// The agent module's page, mounted by the web shell under `////agent`. // // /agent the run list, the approval queue and the start form // /agent/ one run: the plan with per-step progress, the budget, the recovery controls // // Every read is a procedure through the same caller the API uses. Progress is rendered from the // durable step log, so a refresh after a restart tells the truth; the progress bar is a real // element, keyboard-operable controls only. import type { Container, TransportCaller } from "@conusai-kit/core" import type { I18n } from "@conusai-kit/i18n" import type { ProjectPage } from "@conusai-kit/ui" import type { ReactElement } from "react" import { type ApprovalView, approvalList, type RunView, runList, runStatus } from "../contract/index.js" import { ApprovalQueue } from "./approval-queue.js" import { RunControls } from "./run-controls.js" import { StartForm } from "./start-form.js" export type AgentPage = ProjectPage export const runStatusKey: Record = { queued: "runs.statusQueued", running: "runs.statusRunning", awaiting_approval: "runs.statusAwaitingApproval", completed: "runs.statusCompleted", failed: "runs.statusFailed", cancelled: "runs.statusCancelled", uncertain: "runs.statusUncertain", } const stepStatusKey: Record = { pending: "runs.stepPending", committed: "runs.stepCommitted", failed: "runs.stepFailed", cancelled: "runs.stepCancelled", uncertain: "runs.stepUncertain", } export const agentPage: AgentPage = async ({ slugs, segments, caller, i18n }): Promise => { const t = (key: string, values?: Record) => i18n.message(`agent.${key}`, values) const failed = i18n.message("app.failed") const [runs, approvals] = await Promise.all([caller.call(runList, slugs), caller.call(approvalList, slugs)]) const startLabels = { heading: t("start.heading"), goalLabel: t("start.goalLabel"), goalHint: t("start.goalHint"), planLabel: t("start.planLabel"), planHint: t("start.planHint"), submit: t("start.submit"), starting: t("start.starting"), failed, } const approvalLabels = { heading: t("approvals.heading"), empty: t("approvals.empty"), proposed: t("approvals.proposed"), review: t("approvals.review"), approve: t("approvals.approve"), reject: t("approvals.reject"), decided: t("approvals.decided"), disclosure: t("approvals.disclosure"), failed, } const controlsLabels = { cancel: t("runs.cancel"), cancelling: t("runs.cancelling"), refresh: t("runs.refresh"), failedHint: t("recovery.failedHint"), cancelledHint: t("recovery.cancelledHint"), uncertainHint: t("recovery.uncertainHint"), budgetExhausted: t("recovery.budgetExhausted"), approvalUnavailable: t("recovery.approvalUnavailable"), toolError: t("recovery.toolError"), planRefused: t("recovery.planRefused"), internal: t("recovery.internal"), } if (segments.length === 0) { return ( <>

{t("title")}

{t("intro")}

{t("runs.heading")}

{runs.runs.length === 0 ?

{t("runs.empty")}

: null} {runs.runs.map((run) => ( ))}
{t("runs.heading")}
{t("runs.goal")} {t("runs.status")} {t("runs.progress")} {t("runs.startedBy")}
{run.goal} {t(runStatusKey[run.status])} {Math.round(run.percent * 100)}% {run.actorId}
) } const [runId, ...rest] = segments if (runId === undefined || rest.length > 0) throw notFoundPage() const run = await caller.call(runStatus, { ...slugs, runId }) return ( <>

{t("runs.back")}

{run.goal}

{t("runs.status")}
{t(runStatusKey[run.status])}
{t("runs.startedBy")}
{run.actorId}
{t("runs.usage")}
{t("runs.usage", { steps: run.usageSteps, cost: run.usageCostMicrocents })}
{Math.round(run.percent * 100)}%

{t("runs.plan")}

{run.plan.map((step) => ( ))}
{t("runs.plan")}
{t("runs.step")} {t("runs.tool")} {t("runs.status")}
{step.label} {step.tool} {t(stepStatusKey[step.status])} {step.attempts > 1 ? ` (${t("runs.attempts", { count: step.attempts })})` : ""} {step.error !== null ? `: ${step.error}` : ""}
) } const notFoundPage = () => { // A segment that is not a run id is a page that does not exist. return Object.assign(new Error("no such page"), { status: 404 }) }