import type { TaskCancelReason, UnstampedMessageStreamEvent } from "#protocol/message.js"; import type { ChannelAudience } from "#shared/channel-audience.js"; import type { JsonObject } from "#shared/json.js"; /** How one of the turn's calls stands. */ export type TaskCardStatus = "working" | "completed" | "failed" | "cancelled"; /** What a blocked task waits on: a person's approval, answer, or sign-in. */ export interface TaskCardBlocker { readonly kind: "approval" | "authorization" | "input"; /** * The request's prompt or the connection's name. Only in a private * conversation, since a request can be sent to one person alone. */ readonly label?: string; } /** One task call in a turn's task card. */ export interface TaskCardTask { /** The call's id; a resumable task called twice in a turn has two rows. */ readonly id: string; readonly taskId: string; readonly kind: "agent" | "tool"; /** The tool or agent name. */ readonly name: string; /** * The tool's start label, or the name's display title. An agent's is * `Researcher: brief`, or the brief alone for a call to the agent's own copy. */ readonly title: string; /** `blocked` while the task waits on a person; see {@link TaskCardTask.blockedOn}. */ readonly status: TaskCardStatus | "blocked"; readonly blockedOn?: TaskCardBlocker; /** * The first sentence of the result once settled. A failure's line appears * only in a private conversation, since error text can carry internals. */ readonly summary?: string; /** * Why a cancelled task stopped: `task_cancel` when the model no longer * needed it. Absent when the task's run stopped on its own. */ readonly cancelReason?: TaskCancelReason; readonly startedAt: string; readonly settledAt?: string; } /** * One of the turn's own tool calls that doesn't run as a task, such as a call * to an app's `plan` tool whose input a renderer shows as rows. */ export interface TaskCardAction { /** The call's id. */ readonly id: string; /** The tool name. */ readonly name: string; /** The tool's start label, or the name's display title. */ readonly title: string; readonly status: TaskCardStatus; /** The call's input, when its JSON is at most 4,096 characters. */ readonly input?: Readonly>; readonly startedAt: string; readonly settledAt?: string; } /** * One turn's own tool calls: the tasks it started, and its other actions, * each in call order. `blocked` while any task waits on a person, `working` * while the turn or any other task works, then `finished`. */ export interface TaskCardView { readonly turnId: string; readonly state: "working" | "blocked" | "finished"; readonly tasks: readonly TaskCardTask[]; readonly actions: readonly TaskCardAction[]; } /** One call as a channel tracks it: plain JSON, kept in the channel's state. */ interface TrackedCall { readonly callId: string; readonly name: string; readonly title: string; readonly status: TaskCardStatus; readonly startedAt: string; readonly input?: JsonObject; readonly settledAt?: string; readonly task?: { readonly id: string; readonly kind: "agent" | "tool"; readonly summary?: string; readonly cancelReason?: TaskCancelReason; /** Open requests and sign-ins the task waits on, oldest first. */ readonly blockers?: readonly (TaskCardBlocker & { readonly id: string; })[]; }; } /** One turn's calls as a channel tracks them from its session's own events. */ export interface TaskCardTurn { readonly calls: readonly TrackedCall[]; readonly ended: boolean; } type TurnChanges = Readonly>; /** * Folds one of the session's events into the turns' tracked calls, including * the requests a task's run relays through the session. Returns each turn it * changed, by turn id; none when the event changes no card. */ export declare function trackTaskCardEvent(turns: Readonly>, event: UnstampedMessageStreamEvent, at: string): TurnChanges; /** * Splits a turn's card when the turn starts a task after every task on the * card settled, which happens when the turn's caller keeps talking to an open * turn. The settled calls end as their own finished card; the calls still * working, including the one starting, open a new card. Returns nothing while * any of the card's tasks works. */ export declare function closeSettledTasks(turn: TaskCardTurn, callId: string): { readonly closed: TaskCardTurn; readonly open: TaskCardTurn; } | undefined; /** The view a renderer draws one turn's card from. */ export declare function taskCardView(turnId: string, turn: TaskCardTurn, options: { readonly audience: ChannelAudience; }): TaskCardView; /** The names of a turn's working tasks, for a status such as `Waiting on researcher...`. */ export declare function workingTaskNames(turn: TaskCardTurn | undefined): readonly string[]; export {};