module Web.View.AgentRegistrations.Show where import IHP.ViewPrelude import Web.View.AgentRegistrations.Index (trustBadge, statusBadge) import Text.Printf (printf) data ShowView = ShowView { agent :: !AgentRegistration , policies :: ![ModelRoutingPolicy] , recentProposals :: ![AgentProposal] , mPerformance :: !(Maybe AgentPerformanceRecord) } instance View ShowView where html ShowView { .. } = [hsx|

{agent.name}

{agent.slug}

{trustBadge agent.trustLevel} {statusBadge agent.isActive} Edit {when agent.isActive [hsx| Deactivate |]} Compute Performance

Provider

{agent.provider}

Model

{agent.modelName}

Description

{fromMaybe "—" agent.description}

{performancePanel mPerformance}

Routing Policies

{if null policies then noPoliciesMsg else policiesTable}

Recent Proposals (last 10)

{if null recentProposals then noProposalsMsg else proposalsTable}
|] where policiesTable = [hsx|
{forEach policies renderPolicyRow}
Task Type Priority Active
|] proposalsTable = [hsx|
{forEach recentProposals renderProposalRow}
Type Status Tokens In/Out Created
|] renderMeanConfidence :: Maybe Double -> Html renderMeanConfidence Nothing = [hsx|

Mean confidence: —

|] renderMeanConfidence (Just c) = [hsx|

Mean confidence: {printf "%.2f" c :: String}

|] renderPolicyRow :: ModelRoutingPolicy -> Html renderPolicyRow p = [hsx| {p.taskType} {show p.priority} {statusBadge p.isActive} |] noPoliciesMsg :: Html noPoliciesMsg = [hsx|

No routing policies. Add one.

|] noProposalsMsg :: Html noProposalsMsg = [hsx|

No proposals yet.

|] renderProposalRow :: AgentProposal -> Html renderProposalRow p = [hsx| {p.proposalType} {p.status} {maybe "—" show p.tokensIn} / {maybe "—" show p.tokensOut} {timeAgo p.createdAt} |] performancePanel :: Maybe AgentPerformanceRecord -> Html performancePanel Nothing = [hsx|
No performance snapshot available. Click "Compute Performance" to generate one.
|] performancePanel (Just p) = let total = p.proposalsAccepted + p.proposalsRejected acceptPct = if total > 0 then (100 * p.proposalsAccepted) `div` total else 0 in [hsx|

Performance (30-day snapshot)

{show p.proposalsGenerated}

Generated

{show p.proposalsAccepted}

Accepted

{show p.proposalsRejected}

Rejected

{show acceptPct}%

Acceptance rate

{renderMeanConfidence p.meanConfidence}
|]