"use client" // Starting a run: the goal and the plan as JSON. The plan is what the run will do, shown to the // person before they start it, and admitted by the server against the hard ceilings. import { type ProjectSlugs, useTransport } from "@conusai-kit/ui" import { type FormEvent, type ReactElement, useId, useState } from "react" export interface StartFormLabels { readonly heading: string readonly goalLabel: string readonly goalHint: string readonly planLabel: string readonly planHint: string readonly submit: string readonly starting: string readonly failed: string } type State = { kind: "idle" } | { kind: "busy" } | { kind: "failed"; detail: string } const EXAMPLE = JSON.stringify([ { key: "read", label: "Read the document", tool: "documents.read", args: { fileId: "…" } }, ]) export function StartForm({ slugs, labels }: { slugs: ProjectSlugs; labels: StartFormLabels }): ReactElement { const { call, describe } = useTransport() const goalId = useId() const planId = useId() const [state, setState] = useState({ kind: "idle" }) const start = async (event: FormEvent): Promise => { event.preventDefault() const form = new FormData(event.currentTarget) const goal = String(form.get("goal") ?? "").trim() let plan: unknown try { plan = JSON.parse(String(form.get("plan") ?? "")) } catch { setState({ kind: "failed", detail: "invalid JSON" }) return } setState({ kind: "busy" }) try { await call("agent.run.start", { ...slugs, goal, plan }) window.location.reload() } catch (error) { setState({ kind: "failed", detail: describe(error) }) } } return (

{labels.heading}

void start(event)}>

{labels.goalHint}