generated from coulomb/repo-seed
Convert all remaining `<- paramOrNothing / param / paramOrDefault /
currentUserOrNothing` monadic binds to `let` — these functions are pure
(ImplicitParams-based) in IHP v1.5, so `<-` is a type error in an IO
do-block.
Controllers fixed:
AgentDelegations, AiGovernancePolicies, Annotations, ApiConsumers,
CollectiveProposals, DecisionRecords, DeploymentRecords,
HubCapabilityManifests, HubRoutingRules, InstitutionalKnowledge,
OutcomeCorrelations, RequirementCandidates, TypeRegistries,
WebhookSubscriptions, Widgets,
Api/V2/{Annotations,InteractionEvents,Token}
WebhookSubscriptions: remove orphaned `Right () ->` case arm that was
left inside a bare `unless` block (structural parse error).
Also carries forward all in-progress fixes from the working tree:
helpers (AgentBridge, ApiRateLimit, BottleneckDetector,
CrossHubPropagation, FrictionScore),
views (CanSelect instances, HSX lambda extraction, formFor wrappers),
env/build (envrc GHCi perms, flake.nix Tailwind + GHC resource limits,
static/app.css additional Tailwind output).
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
|
|
let 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
|