48 lines
1.8 KiB
Haskell
48 lines
1.8 KiB
Haskell
|
|
module Web.Controller.ModelRoutingPolicies where
|
||
|
|
|
||
|
|
-- IHF Phase 11 — Advanced AI Federation (IHUB-WP-0012 T04)
|
||
|
|
|
||
|
|
import Web.Controller.Prelude
|
||
|
|
import Web.View.ModelRoutingPolicies.Index
|
||
|
|
import Web.View.ModelRoutingPolicies.New
|
||
|
|
|
||
|
|
instance Controller ModelRoutingPoliciesController where
|
||
|
|
|
||
|
|
action ModelRoutingPoliciesAction = do
|
||
|
|
policies <- query @ModelRoutingPolicy
|
||
|
|
|> orderByAsc #taskType
|
||
|
|
|> fetch
|
||
|
|
hubs <- query @Hub |> orderByAsc #name |> fetch
|
||
|
|
agents <- query @AgentRegistration |> orderByAsc #name |> fetch
|
||
|
|
render IndexView { .. }
|
||
|
|
|
||
|
|
action NewModelRoutingPolicyAction = do
|
||
|
|
let policy = newRecord @ModelRoutingPolicy
|
||
|
|
hubs <- query @Hub |> orderByAsc #name |> fetch
|
||
|
|
agents <- query @AgentRegistration
|
||
|
|
|> filterWhere (#isActive, True)
|
||
|
|
|> orderByAsc #name
|
||
|
|
|> fetch
|
||
|
|
render NewView { .. }
|
||
|
|
|
||
|
|
action CreateModelRoutingPolicyAction = do
|
||
|
|
let policy = newRecord @ModelRoutingPolicy
|
||
|
|
policy
|
||
|
|
|> fill @'["hubId","taskType","agentRegistrationId","priority"]
|
||
|
|
|> validateField #taskType 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 "Routing policy created"
|
||
|
|
redirectTo ModelRoutingPoliciesAction
|
||
|
|
|
||
|
|
action DeleteModelRoutingPolicyAction { modelRoutingPolicyId } = do
|
||
|
|
policy <- fetch modelRoutingPolicyId
|
||
|
|
deleteRecord policy
|
||
|
|
setSuccessMessage "Routing policy deleted"
|
||
|
|
redirectTo ModelRoutingPoliciesAction
|