feat(WP-0012): IHF Phase 11 — Advanced AI Federation
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>
This commit is contained in:
2026-04-01 20:57:17 +00:00
parent 4e4e994659
commit 133dae3d23
32 changed files with 1959 additions and 102 deletions

View File

@@ -0,0 +1,50 @@
module Web.View.AgentDelegations.Index where
import Web.View.Prelude
data IndexView = IndexView
{ delegations :: ![AgentDelegation] }
instance View IndexView where
html IndexView { .. } = [hsx|
<div class="p-6">
<h1 class="text-2xl font-bold text-gray-900 mb-6">Agent Delegations</h1>
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Scope</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Token Budget / Used</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Created</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
{forEach delegations renderRow}
</tbody>
</table>
</div>
</div>
|]
where
renderRow d = [hsx|
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 text-sm text-gray-700">{d.scope}</td>
<td class="px-6 py-4">{statusBadge d.status}</td>
<td class="px-6 py-4 text-sm text-gray-500">
{show d.tokenBudget} / {maybe "" show d.tokensUsed}
</td>
<td class="px-6 py-4 text-sm text-gray-500">{timeAgo d.createdAt}</td>
<td class="px-6 py-4 text-right">
<a href={ShowAgentDelegationAction d.id}
class="text-sm text-blue-600 hover:text-blue-800">View</a>
</td>
</tr>
|]
statusBadge :: Text -> Html
statusBadge "completed" = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-green-100 text-green-800">completed</span>|]
statusBadge "failed" = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-red-100 text-red-800">failed</span>|]
statusBadge "cancelled" = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-gray-100 text-gray-500">cancelled</span>|]
statusBadge _ = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-yellow-100 text-yellow-800">pending</span>|]

View File

@@ -0,0 +1,64 @@
module Web.View.AgentDelegations.Show where
import Web.View.Prelude
import Web.View.AgentDelegations.Index (statusBadge)
data ShowView = ShowView
{ delegation :: !AgentDelegation
, delegatingAgent :: !AgentRegistration
, receivingAgent :: !AgentRegistration
, mParentProposal :: !(Maybe AgentProposal)
}
instance View ShowView where
html ShowView { .. } = [hsx|
<div class="p-6 space-y-6 max-w-3xl">
<div class="flex justify-between items-start">
<h1 class="text-2xl font-bold text-gray-900">Delegation</h1>
{statusBadge delegation.status}
</div>
<div class="bg-gray-50 rounded-lg p-4 grid grid-cols-2 gap-4">
<div>
<p class="text-xs text-gray-500">Delegating Agent</p>
<a href={ShowAgentRegistrationAction delegatingAgent.id}
class="text-sm font-medium text-blue-600 hover:text-blue-800">{delegatingAgent.name}</a>
</div>
<div>
<p class="text-xs text-gray-500">Receiving Agent</p>
<a href={ShowAgentRegistrationAction receivingAgent.id}
class="text-sm font-medium text-blue-600 hover:text-blue-800">{receivingAgent.name}</a>
</div>
<div class="col-span-2">
<p class="text-xs text-gray-500">Scope</p>
<p class="text-sm">{delegation.scope}</p>
</div>
<div>
<p class="text-xs text-gray-500">Token Budget</p>
<p class="text-sm">{show delegation.tokenBudget}</p>
</div>
<div>
<p class="text-xs text-gray-500">Tokens Used</p>
<p class="text-sm">{maybe "" show delegation.tokensUsed}</p>
</div>
</div>
{case mParentProposal of
Nothing -> mempty
Just p -> [hsx|
<div>
<p class="text-xs text-gray-500 mb-1">Parent Proposal</p>
<p class="text-sm font-mono text-gray-600">{p.proposalType} {p.status}</p>
</div>
|]}
{case delegation.result of
Nothing -> mempty
Just r -> [hsx|
<div>
<h2 class="text-lg font-semibold text-gray-800 mb-2">Result</h2>
<pre class="bg-gray-100 rounded p-4 text-sm overflow-auto">{show r}</pre>
</div>
|]}
</div>
|]

View File

@@ -0,0 +1,17 @@
module Web.View.AgentRegistrations.Edit where
import Web.View.Prelude
import Web.View.AgentRegistrations.New (renderForm)
data EditView = EditView
{ agent :: !AgentRegistration
, hubs :: ![Hub]
}
instance View EditView where
html EditView { .. } = [hsx|
<div class="p-6 max-w-2xl">
<h1 class="text-2xl font-bold text-gray-900 mb-6">Edit Agent: {agent.name}</h1>
{renderForm agent hubs}
</div>
|]

View File

@@ -0,0 +1,72 @@
module Web.View.AgentRegistrations.Index where
import Web.View.Prelude
data IndexView = IndexView
{ agents :: ![AgentRegistration]
, hubs :: ![Hub]
}
instance View IndexView where
html IndexView { .. } = [hsx|
<div class="p-6">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-900">Agent Registry</h1>
<a href={NewAgentRegistrationAction}
class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm font-medium">
Register Agent
</a>
</div>
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Name</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Hub</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Provider</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Model</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Trust</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
{forEach agents renderRow}
</tbody>
</table>
</div>
</div>
|]
where
hubName agentHubId =
case find (\h -> h.id == agentHubId) hubs of
Just h -> h.name
Nothing -> "Unknown"
renderRow agent = [hsx|
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 text-sm font-medium text-gray-900">
<a href={ShowAgentRegistrationAction agent.id} class="hover:text-blue-600">{agent.name}</a>
</td>
<td class="px-6 py-4 text-sm text-gray-500">{hubName agent.hubId}</td>
<td class="px-6 py-4 text-sm text-gray-500">
<span class="font-mono bg-gray-100 px-2 py-0.5 rounded text-xs">{agent.provider}</span>
</td>
<td class="px-6 py-4 text-sm text-gray-500 font-mono text-xs">{agent.modelName}</td>
<td class="px-6 py-4">{trustBadge agent.trustLevel}</td>
<td class="px-6 py-4">{statusBadge agent.isActive}</td>
<td class="px-6 py-4 text-right">
<a href={EditAgentRegistrationAction agent.id}
class="text-sm text-blue-600 hover:text-blue-800">Edit</a>
</td>
</tr>
|]
trustBadge :: Text -> Html
trustBadge "autonomous" = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-red-100 text-red-800">autonomous</span>|]
trustBadge "elevated" = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-yellow-100 text-yellow-800">elevated</span>|]
trustBadge _ = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-gray-100 text-gray-700">advisory</span>|]
statusBadge :: Bool -> Html
statusBadge True = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-green-100 text-green-800">active</span>|]
statusBadge False = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-gray-100 text-gray-500">inactive</span>|]

View File

@@ -0,0 +1,56 @@
module Web.View.AgentRegistrations.New where
import Web.View.Prelude
data NewView = NewView
{ agent :: !AgentRegistration
, hubs :: ![Hub]
}
instance View NewView where
html NewView { .. } = [hsx|
<div class="p-6 max-w-2xl">
<h1 class="text-2xl font-bold text-gray-900 mb-6">Register Agent</h1>
{renderForm agent hubs}
</div>
|]
renderForm :: AgentRegistration -> [Hub] -> Html
renderForm agent hubs = formFor agent [hsx|
<div class="space-y-4">
<div>
{(textField #hubId) { label = "Hub", fieldClass = "block w-full border-gray-300 rounded-md shadow-sm" }}
</div>
<div class="grid grid-cols-2 gap-4">
<div>{(textField #name) { label = "Name" }}</div>
<div>{(textField #slug) { label = "Slug (unique identifier)" }}</div>
</div>
<div>{(textareaField #description) { label = "Description" }}</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Provider</label>
<select name="provider" class="block w-full border-gray-300 rounded-md shadow-sm">
<option value="openrouter">openrouter</option>
<option value="gemini">gemini</option>
<option value="openai">openai</option>
<option value="claude-code">claude-code</option>
</select>
</div>
<div>{(textField #modelName) { label = "Model Name" }}</div>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Trust Level</label>
<select name="trustLevel" class="block w-full border-gray-300 rounded-md shadow-sm">
<option value="advisory">advisory (default)</option>
<option value="elevated">elevated</option>
<option value="autonomous">autonomous</option>
</select>
</div>
<div>{(textareaField #systemPrompt) { label = "System Prompt (optional)" }}</div>
<div class="flex gap-3 pt-2">
{submitButton { label = "Register Agent" }}
<a href={AgentRegistrationsAction}
class="px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-md text-sm">Cancel</a>
</div>
</div>
|]

View File

@@ -0,0 +1,7 @@
module Web.View.AgentRegistrations.Performance where
-- Performance view is rendered inline in Show.hs via performancePanel helper.
-- This module re-exports it for use if needed as a standalone view.
import Web.View.Prelude
import Web.View.AgentRegistrations.Show (performancePanel)

View File

@@ -0,0 +1,153 @@
module Web.View.AgentRegistrations.Show where
import Web.View.Prelude
import Web.View.AgentRegistrations.Index (trustBadge, statusBadge)
data ShowView = ShowView
{ agent :: !AgentRegistration
, policies :: ![ModelRoutingPolicy]
, recentProposals :: ![AgentProposal]
, mPerformance :: !(Maybe AgentPerformanceRecord)
}
instance View ShowView where
html ShowView { .. } = [hsx|
<div class="p-6 space-y-6">
<div class="flex justify-between items-start">
<div>
<h1 class="text-2xl font-bold text-gray-900">{agent.name}</h1>
<p class="text-sm text-gray-500 mt-1 font-mono">{agent.slug}</p>
</div>
<div class="flex gap-2">
{trustBadge agent.trustLevel}
{statusBadge agent.isActive}
<a href={EditAgentRegistrationAction agent.id}
class="px-3 py-1 text-sm bg-gray-100 hover:bg-gray-200 rounded">Edit</a>
{when agent.isActive [hsx|
<a href={DeactivateAgentAction agent.id}
class="px-3 py-1 text-sm bg-red-50 text-red-700 hover:bg-red-100 rounded">Deactivate</a>
|]}
<a href={ComputeAgentPerformanceAction agent.id}
class="px-3 py-1 text-sm bg-blue-50 text-blue-700 hover:bg-blue-100 rounded">Compute Performance</a>
</div>
</div>
<div class="grid grid-cols-2 gap-4 bg-gray-50 rounded-lg p-4">
<div>
<p class="text-xs text-gray-500">Provider</p>
<p class="font-mono text-sm">{agent.provider}</p>
</div>
<div>
<p class="text-xs text-gray-500">Model</p>
<p class="font-mono text-sm">{agent.modelName}</p>
</div>
<div class="col-span-2">
<p class="text-xs text-gray-500">Description</p>
<p class="text-sm">{fromMaybe "" agent.description}</p>
</div>
</div>
{performancePanel mPerformance}
<div>
<h2 class="text-lg font-semibold text-gray-800 mb-3">Routing Policies</h2>
{if null policies
then [hsx|<p class="text-sm text-gray-500">No routing policies. <a href={NewModelRoutingPolicyAction} class="text-blue-600">Add one</a>.</p>|]
else policiesTable}
</div>
<div>
<h2 class="text-lg font-semibold text-gray-800 mb-3">Recent Proposals (last 10)</h2>
{if null recentProposals
then [hsx|<p class="text-sm text-gray-500">No proposals yet.</p>|]
else proposalsTable}
</div>
</div>
|]
where
policiesTable = [hsx|
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Task Type</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Priority</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Active</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
{forEach policies \p -> [hsx|
<tr>
<td class="px-4 py-3 text-sm font-mono">{p.taskType}</td>
<td class="px-4 py-3 text-sm">{show p.priority}</td>
<td class="px-4 py-3">{statusBadge p.isActive}</td>
</tr>
|]}
</tbody>
</table>
</div>
|]
proposalsTable = [hsx|
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Type</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Tokens In/Out</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase">Created</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
{forEach recentProposals \p -> [hsx|
<tr>
<td class="px-4 py-3 text-sm font-mono">{p.proposalType}</td>
<td class="px-4 py-3 text-sm">{p.status}</td>
<td class="px-4 py-3 text-sm text-gray-500">
{maybe "" show p.tokensIn} / {maybe "" show p.tokensOut}
</td>
<td class="px-4 py-3 text-sm text-gray-500">{timeAgo p.createdAt}</td>
</tr>
|]}
</tbody>
</table>
</div>
|]
performancePanel :: Maybe AgentPerformanceRecord -> Html
performancePanel Nothing = [hsx|
<div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4 text-sm text-yellow-800">
No performance snapshot available. Click "Compute Performance" to generate one.
</div>
|]
performancePanel (Just p) =
let total = p.proposalsAccepted + p.proposalsRejected
acceptPct = if total > 0 then (100 * p.proposalsAccepted) `div` total else 0
in [hsx|
<div class="bg-white shadow rounded-lg p-4">
<h2 class="text-lg font-semibold text-gray-800 mb-3">Performance (30-day snapshot)</h2>
<div class="grid grid-cols-4 gap-4">
<div class="text-center">
<p class="text-2xl font-bold text-gray-900">{show p.proposalsGenerated}</p>
<p class="text-xs text-gray-500">Generated</p>
</div>
<div class="text-center">
<p class="text-2xl font-bold text-green-600">{show p.proposalsAccepted}</p>
<p class="text-xs text-gray-500">Accepted</p>
</div>
<div class="text-center">
<p class="text-2xl font-bold text-red-500">{show p.proposalsRejected}</p>
<p class="text-xs text-gray-500">Rejected</p>
</div>
<div class="text-center">
<p class="text-2xl font-bold text-blue-600">{show acceptPct}%</p>
<p class="text-xs text-gray-500">Acceptance rate</p>
</div>
</div>
{case p.meanConfidence of
Nothing -> [hsx|<p class="mt-3 text-sm text-gray-400">Mean confidence: </p>|]
Just c -> [hsx|<p class="mt-3 text-sm text-gray-600">Mean confidence: {printf "%.2f" c :: String}</p>|]
}
</div>
|]

View File

@@ -0,0 +1,63 @@
module Web.View.AiGovernancePolicies.Index where
import Web.View.Prelude
data IndexView = IndexView
{ policies :: ![AiGovernancePolicy]
, hubs :: ![Hub]
, agents :: ![AgentRegistration]
}
instance View IndexView where
html IndexView { .. } = [hsx|
<div class="p-6">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-900">AI Governance Policies</h1>
<a href={NewAiGovernancePolicyAction}
class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm font-medium">
Add Policy
</a>
</div>
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Hub</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Agent</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Artifact Type</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Allowed Actions</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Active</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
{forEach policies renderRow}
</tbody>
</table>
</div>
</div>
|]
where
hubName hid = maybe "Unknown" (.name) (find (\h -> h.id == hid) hubs)
agentName aid = maybe "Unknown" (.name) (find (\a -> a.id == aid) agents)
renderRow p = [hsx|
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 text-sm text-gray-700">{hubName p.hubId}</td>
<td class="px-6 py-4 text-sm text-gray-700">{agentName p.agentRegistrationId}</td>
<td class="px-6 py-4 text-sm font-mono">{p.artifactType}</td>
<td class="px-6 py-4 text-sm text-gray-600">{show p.allowedActions}</td>
<td class="px-6 py-4">
{if p.isActive
then [hsx|<span class="text-green-600 text-sm">Active</span>|]
else [hsx|<span class="text-gray-400 text-sm">Inactive</span>|]}
</td>
<td class="px-6 py-4 text-right">
<a href={ToggleAiGovernancePolicyAction p.id}
class="text-sm text-blue-600 hover:text-blue-800"
data-method="POST">
{if p.isActive then "Deactivate" :: Text else "Activate"}
</a>
</td>
</tr>
|]

View File

@@ -0,0 +1,57 @@
module Web.View.AiGovernancePolicies.New where
import Web.View.Prelude
data NewView = NewView
{ policy :: !AiGovernancePolicy
, hubs :: ![Hub]
, agents :: ![AgentRegistration]
}
allowedActionOptions :: [(Text, Text)]
allowedActionOptions =
[ ("read", "read — agent may read artifacts")
, ("propose", "propose — agent may create proposals")
, ("delegate", "delegate — agent may delegate to other agents")
, ("auto_apply", "auto_apply — agent may apply changes without human review")
]
instance View NewView where
html NewView { .. } = [hsx|
<div class="p-6 max-w-xl">
<h1 class="text-2xl font-bold text-gray-900 mb-6">Add AI Governance Policy</h1>
{formFor policy [hsx|
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Hub</label>
<select name="hubId" class="block w-full border-gray-300 rounded-md shadow-sm text-sm">
{forEach hubs \h -> [hsx|<option value={show h.id}>{h.name}</option>|]}
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Agent</label>
<select name="agentRegistrationId" class="block w-full border-gray-300 rounded-md shadow-sm text-sm">
{forEach agents \a -> [hsx|<option value={show a.id}>{a.name}</option>|]}
</select>
</div>
<div>{(textField #artifactType) { label = "Artifact Type", placeholder = "e.g. requirement_candidate, annotation, decision_record" }}</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">Allowed Actions</label>
<div class="space-y-2">
{forEach allowedActionOptions \(val, label) -> [hsx|
<label class="flex items-center gap-2 text-sm">
<input type="checkbox" name="allowedActions" value={val} class="rounded" />
<span>{label}</span>
</label>
|]}
</div>
</div>
<div class="flex gap-3 pt-2">
{submitButton { label = "Create Policy" }}
<a href={AiGovernancePoliciesAction}
class="px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-md text-sm">Cancel</a>
</div>
</div>
|]}
</div>
|]

View File

@@ -0,0 +1,47 @@
module Web.View.CollectiveProposals.Index where
import Web.View.Prelude
data IndexView = IndexView
{ proposals :: ![CollectiveProposal] }
instance View IndexView where
html IndexView { .. } = [hsx|
<div class="p-6">
<h1 class="text-2xl font-bold text-gray-900 mb-6">Collective Proposals</h1>
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Title</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Task Type</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Consensus</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Created</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
{forEach proposals renderRow}
</tbody>
</table>
</div>
</div>
|]
where
renderRow p = [hsx|
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 text-sm font-medium text-gray-900">{p.title}</td>
<td class="px-6 py-4 text-sm font-mono text-gray-500">{p.taskType}</td>
<td class="px-6 py-4">{consensusBadge p.consensusStatus}</td>
<td class="px-6 py-4 text-sm text-gray-500">{timeAgo p.createdAt}</td>
<td class="px-6 py-4 text-right">
<a href={ShowCollectiveProposalAction p.id}
class="text-sm text-blue-600 hover:text-blue-800">View</a>
</td>
</tr>
|]
consensusBadge :: Text -> Html
consensusBadge "consensus" = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-green-100 text-green-800">consensus</span>|]
consensusBadge "divergent" = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-orange-100 text-orange-800">divergent</span>|]
consensusBadge _ = [hsx|<span class="px-2 py-0.5 text-xs rounded-full bg-gray-100 text-gray-500">pending</span>|]

View File

@@ -0,0 +1,58 @@
module Web.View.CollectiveProposals.Show where
import Web.View.Prelude
import Web.View.CollectiveProposals.Index (consensusBadge)
data ShowView = ShowView
{ proposal :: !CollectiveProposal
, agentContributions :: ![(CollectiveProposalContribution, Text)]
-- ^ (contribution, agent name)
}
instance View ShowView where
html ShowView { .. } = [hsx|
<div class="p-6 space-y-6 max-w-4xl">
<div class="flex justify-between items-start">
<div>
<h1 class="text-2xl font-bold text-gray-900">{proposal.title}</h1>
<p class="text-sm font-mono text-gray-500 mt-1">{proposal.taskType}</p>
</div>
{consensusBadge proposal.consensusStatus}
</div>
{case proposal.summary of
Nothing -> mempty
Just s -> [hsx|<p class="text-gray-700">{s}</p>|]}
{case proposal.finalContent of
Nothing -> mempty
Just fc -> [hsx|
<div class="bg-green-50 border border-green-200 rounded-lg p-4">
<h2 class="text-sm font-semibold text-green-800 mb-2">Synthesized Recommendation</h2>
<pre class="text-sm text-green-900 whitespace-pre-wrap">{show fc}</pre>
</div>
|]}
<div>
<h2 class="text-lg font-semibold text-gray-800 mb-3">
Agent Contributions ({show (length agentContributions)})
</h2>
<div class="grid gap-4">
{forEach agentContributions renderContrib}
</div>
</div>
</div>
|]
where
renderContrib (contrib, agentName) = [hsx|
<div class="bg-white shadow rounded-lg p-4">
<div class="flex justify-between items-center mb-2">
<span class="text-sm font-medium text-gray-800">{agentName}</span>
<span class="text-xs text-gray-400">
{maybe "" (\m -> "model: " <> m) contrib.modelUsed}
{maybe "" (\t -> " · " <> show t <> " tokens out") contrib.tokensOut}
</span>
</div>
<pre class="text-sm text-gray-700 whitespace-pre-wrap bg-gray-50 rounded p-3">{show contrib.content}</pre>
</div>
|]

View File

@@ -0,0 +1,65 @@
module Web.View.ModelRoutingPolicies.Index where
import Web.View.Prelude
data IndexView = IndexView
{ policies :: ![ModelRoutingPolicy]
, hubs :: ![Hub]
, agents :: ![AgentRegistration]
}
instance View IndexView where
html IndexView { .. } = [hsx|
<div class="p-6">
<div class="flex justify-between items-center mb-6">
<h1 class="text-2xl font-bold text-gray-900">Model Routing Policies</h1>
<a href={NewModelRoutingPolicyAction}
class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm font-medium">
Add Policy
</a>
</div>
<div class="bg-white shadow rounded-lg overflow-hidden">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Hub</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Task Type</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Agent</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Priority</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Active</th>
<th class="px-6 py-3"></th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200">
{forEach policies renderRow}
</tbody>
</table>
</div>
</div>
|]
where
hubName hid = maybe "Unknown" (.name) (find (\h -> h.id == hid) hubs)
agentName aid = maybe "Unknown" (.name) (find (\a -> a.id == aid) agents)
renderRow p = [hsx|
<tr class="hover:bg-gray-50">
<td class="px-6 py-4 text-sm text-gray-700">{hubName p.hubId}</td>
<td class="px-6 py-4 text-sm font-mono">{p.taskType}</td>
<td class="px-6 py-4 text-sm text-gray-700">
<a href={ShowAgentRegistrationAction p.agentRegistrationId}
class="hover:text-blue-600">{agentName p.agentRegistrationId}</a>
</td>
<td class="px-6 py-4 text-sm text-gray-500">{show p.priority}</td>
<td class="px-6 py-4 text-sm">
{if p.isActive
then [hsx|<span class="text-green-600">Yes</span>|]
else [hsx|<span class="text-gray-400">No</span>|]}
</td>
<td class="px-6 py-4 text-right">
<a href={DeleteModelRoutingPolicyAction p.id}
class="text-sm text-red-600 hover:text-red-800"
data-method="DELETE"
data-confirm="Delete this routing policy?">Delete</a>
</td>
</tr>
|]

View File

@@ -0,0 +1,55 @@
module Web.View.ModelRoutingPolicies.New where
import Web.View.Prelude
data NewView = NewView
{ policy :: !ModelRoutingPolicy
, hubs :: ![Hub]
, agents :: ![AgentRegistration]
}
taskTypeOptions :: [Text]
taskTypeOptions =
[ "requirement_draft"
, "triage"
, "synthesis"
, "policy_check"
, "implementation"
]
instance View NewView where
html NewView { .. } = [hsx|
<div class="p-6 max-w-xl">
<h1 class="text-2xl font-bold text-gray-900 mb-6">Add Routing Policy</h1>
{formFor policy [hsx|
<div class="space-y-4">
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Hub</label>
<select name="hubId" class="block w-full border-gray-300 rounded-md shadow-sm text-sm">
{forEach hubs \h -> [hsx|<option value={show h.id}>{h.name}</option>|]}
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Task Type</label>
<select name="taskType" class="block w-full border-gray-300 rounded-md shadow-sm text-sm">
{forEach taskTypeOptions \t -> [hsx|<option value={t}>{t}</option>|]}
</select>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 mb-1">Agent</label>
<select name="agentRegistrationId" class="block w-full border-gray-300 rounded-md shadow-sm text-sm">
{forEach agents \a -> [hsx|
<option value={show a.id}>{a.name} ({a.provider} / {a.modelName})</option>
|]}
</select>
</div>
<div>{(numberField #priority) { label = "Priority (higher wins)", placeholder = "0" }}</div>
<div class="flex gap-3 pt-2">
{submitButton { label = "Create Policy" }}
<a href={ModelRoutingPoliciesAction}
class="px-4 py-2 bg-gray-100 hover:bg-gray-200 rounded-md text-sm">Cancel</a>
</div>
</div>
|]}
</div>
|]