generated from coulomb/repo-seed
Some checks failed
Test / test (push) Has been cancelled
- Schema: AgentRegistration, ModelRoutingPolicy, AgentDelegation, CollectiveProposal, CollectiveProposalContribution, AiGovernancePolicy, AgentPerformanceRecord + ALTER TABLE agent_proposals (migration 1744156800; CHECK constraints on trust_level, status, consensus_status — GAAF compliant) - Bridge: scripts/llm_bridge.py (llm-connect subprocess seam) + Application/Helper/AgentBridge.hs (callBridge, callAgent, checkGovernancePolicy, jsonArrayTexts) - Routing: Application/Helper/ModelRouter.hs (resolveAgent, resolveAllAgents) + ModelRoutingPolicies CRUD - Registry: AgentRegistrations CRUD (Index/Show/New/Edit/Performance), DeactivateAgentAction, ComputeAgentPerformanceAction - Delegation: AgentDelegations controller + views, DelegateSubtaskAction with token budget enforcement at bridge call time - Collective: CollectiveProposals controller + views, CreateCollectiveProposalAction (fan-out → synthesis → consensus detection) - Governance: AiGovernancePolicies CRUD + ToggleAiGovernancePolicyAction; checkGovernancePolicy enforced at all 4 Phase 5 invocation points - Phase 5 wiring: replaced callClaudeApi in Widgets, DecisionRecords, RequirementCandidates with resolveAgent + callAgent + token tracking - llm-connect feature requests: ~/llm-connect/FEATURE_REQUESTS.md (FR-1 HTTP serve, FR-2 RoutingPolicy, FR-3 async, FR-4 BudgetTracker) - GAAF scorecard: 3.61 (up from 3.56); Functional 3.4→3.6, Extensions 3.8→3.9 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
66 lines
2.7 KiB
Haskell
66 lines
2.7 KiB
Haskell
module Web.Controller.AiGovernancePolicies where
|
|
|
|
-- IHF Phase 11 — Advanced AI Federation (IHUB-WP-0012 T08)
|
|
|
|
import Web.Controller.Prelude
|
|
import Web.View.AiGovernancePolicies.Index
|
|
import Web.View.AiGovernancePolicies.New
|
|
import Application.Helper.AgentBridge (jsonArrayTexts)
|
|
|
|
validAllowedActions :: [Text]
|
|
validAllowedActions = ["read", "propose", "delegate", "auto_apply"]
|
|
|
|
validateAllowedActions :: Value -> ValidatorResult
|
|
validateAllowedActions val =
|
|
let actions = jsonArrayTexts val
|
|
invalid = filter (`notElem` validAllowedActions) actions
|
|
in if null invalid
|
|
then Success
|
|
else Failure ("Invalid actions: " <> intercalate ", " invalid)
|
|
|
|
instance Controller AiGovernancePoliciesController where
|
|
|
|
action AiGovernancePoliciesAction = do
|
|
policies <- query @AiGovernancePolicy
|
|
|> orderByAsc #artifactType
|
|
|> fetch
|
|
hubs <- query @Hub |> orderByAsc #name |> fetch
|
|
agents <- query @AgentRegistration |> orderByAsc #name |> fetch
|
|
render IndexView { .. }
|
|
|
|
action NewAiGovernancePolicyAction = do
|
|
let policy = newRecord @AiGovernancePolicy
|
|
|> set #allowedActions (A.toJSON ["read" :: Text])
|
|
hubs <- query @Hub |> orderByAsc #name |> fetch
|
|
agents <- query @AgentRegistration
|
|
|> filterWhere (#isActive, True)
|
|
|> orderByAsc #name
|
|
|> fetch
|
|
render NewView { .. }
|
|
|
|
action CreateAiGovernancePolicyAction = do
|
|
-- Collect allowed_actions from checkbox params
|
|
selectedActions <- paramList @Text "allowedActions"
|
|
let actionsJson = A.toJSON selectedActions
|
|
let policy = newRecord @AiGovernancePolicy
|
|
|> set #allowedActions actionsJson
|
|
policy
|
|
|> fill @'["hubId","agentRegistrationId","artifactType"]
|
|
|> validateField #artifactType nonEmpty
|
|
|> ifValid \case
|
|
Left policy -> do
|
|
hubs <- query @Hub |> orderByAsc #name |> fetch
|
|
agents <- query @AgentRegistration |> filterWhere (#isActive, True) |> fetch
|
|
render NewView { .. }
|
|
Right policy -> do
|
|
createRecord policy
|
|
setSuccessMessage "Governance policy created"
|
|
redirectTo AiGovernancePoliciesAction
|
|
|
|
action ToggleAiGovernancePolicyAction { aiGovernancePolicyId } = do
|
|
policy <- fetch aiGovernancePolicyId
|
|
policy |> set #isActive (not policy.isActive) |> updateRecord
|
|
let msg = if policy.isActive then "Policy deactivated" else "Policy activated"
|
|
setSuccessMessage msg
|
|
redirectTo AiGovernancePoliciesAction
|