import type { JsonValue } from "../state/json.js"; import type { WorkflowMessageKind, WorkflowMessageStatus, WorkflowTurn } from "../state/workflow-messages.js"; export declare const RUN_VIEW_SCHEMA: "pi-workflows.run-view.v1"; export declare const SESSION_VIEW_SCHEMA: "pi-workflows.session-view.v1"; export declare const SESSION_RUN_VIEW_SCHEMA: "pi-workflows.session-run-view.v1"; export declare const SESSION_MESSAGE_SCHEMA: "pi-workflows.session-message.v1"; export declare const BRANCH_REPORT_RECEIPT_SCHEMA: "pi-workflows.branch-report-receipt.v1"; export declare const WORKFLOW_TURN_REPORT_RECEIPT_SCHEMA: "pi-workflows.workflow-turn-report-receipt.v1"; export type WorkflowDisplayStatus = "queued" | "running" | "waiting" | "paused" | "completed" | "failed" | "timed_out" | "cancelled" | "ambiguous"; export declare const WORKFLOW_DISPLAY_CONTROLS: readonly ["pause", "resume", "cancel", "answer", "human-answer", "update", "submit", "review"]; export type WorkflowDisplayControl = (typeof WORKFLOW_DISPLAY_CONTROLS)[number]; export type WorkflowDisplay = { status: WorkflowDisplayStatus; activity: "supervised_runner" | "origin_turn" | null; controls: WorkflowDisplayControl[]; reason: string | null; reasonContent?: JsonValue; }; export type WorkflowRunQueueView = { runId: string; workflowName: string; workflowSourceRef: string; initialized: boolean; definitionDigest: string; status: "queued" | "starting" | "running" | "parked" | "done" | "failed" | "cancelled"; originSessionId: string | null; executionMode: "interactive" | "headless"; parentRunId: string | null; rootRunId: string; lineageKind: "restart" | null; restartNumber: number; parentRunRevision: number | null; errorCode: string | null; createdAt: string; updatedAt: string; startedAt: string | null; finishedAt: string | null; }; export type WorkflowRunView = { schema: typeof RUN_VIEW_SCHEMA; runId: string; /** Presentation cursor for viewer snapshots and deltas. */ revision: number; /** Execution resource revision for exact state-changing commands. */ runRevision: number; display: WorkflowDisplay; manifest: JsonValue; state: JsonValue; workflow: JsonValue; queue: WorkflowRunQueueView; updates: JsonValue[]; graphSteps: JsonValue[]; graphStepStart: number; graphStepTotal: number; takenTransitions: string[]; graphHistory: JsonValue; takenTransitionStart: number; takenTransitionTotal: number; graphCursor: number; stepStart: number; stepTotal: number; tracePage: JsonValue; session: JsonValue; settingsScopes: JsonValue[]; settingsStart: number; settingsTotal: number; followUpQueue: JsonValue; followUpStart: number; followUpTotal: number; updateStart: number; updateTotal: number; workflowMessages: JsonValue[]; workflowMessageStart: number; workflowMessageTotal: number; live: boolean; possiblyInterrupted: boolean; }; export type WorkflowRunListPage = { schema: "pi-workflows.run-list-page.v1"; revision: string; start: number; total: number; items: WorkflowRunSummary[]; }; export type WorkflowRunSummary = { runId: string; workflowName: string; originSessionId: string | null; createdAt: string; updatedAt: string; display: WorkflowDisplay; manifest: JsonValue; live: boolean; possiblyInterrupted: boolean; }; export type ClientInteractiveRequest = { requestId: string; runId: string; attemptId: string; targetSessionId: string; kind: "agent" | "assistant" | "checkpoint" | "decision"; contract: JsonValue; revision: number; status: "pending" | "settled" | "cancelled"; acceptedSubmissionId: string | null; createdAt: string; updatedAt: string; settledAt: string | null; consumedAt: string | null; }; /** * One node row of the Pi widget list. The server sends the semantic facts and * the extension applies terminal colors, glyphs, and layout. */ export type WorkflowSessionNodeRow = { nodeId: string; nodeType: string; /** The node runs an action command rather than a model step. */ actionExecution: "function" | "shell" | null; state: "pending" | "running" | "waiting" | "ok" | "failed"; /** Completed attempts plus the current attempt. */ attempts: number; settingsChangeNumber: number | null; /** Present for the current node. */ statusDetail: string | null; /** Present for the current node. */ startedAt: string | null; /** Duration of the last completed attempt in milliseconds. */ durationMs: number | null; /** Bounded failure text of the last attempt. */ error: string | null; /** Present for a human-decision node. */ humanDecision: { audience: string; summary: string | null; choices: { value: string; label: string; }[]; /** The accepted choice value, when the run recorded one. */ choiceValue: string | null; presentationDigest: string | null; } | null; /** Present for a waiting node without a human decision. */ summary: string | null; assistantResponse: boolean; /** Durable node outcome, when the run recorded one. */ outcome: "ok" | "timed_out" | "failed" | "cancelled" | null; }; /** One latest progress update for the widget progress line. */ export type WorkflowSessionProgressUpdate = { key: string; at: string; data: JsonValue; }; /** * A bounded projection of the current run. Pi uses it for commands, the status * line, and the widget. Complete history stays behind the detailed view. */ export type WorkflowSessionRunView = { schema: typeof SESSION_RUN_VIEW_SCHEMA; runId: string; /** Presentation cursor for the detailed viewer. */ revision: number; /** Execution resource revision for exact state-changing commands. */ runRevision: number; queue: WorkflowRunQueueView; display: WorkflowDisplay; workflowName: string; runTitle: string | null; paused: boolean; currentNode: string | null; waitingOn: string | null; error: string | null; nodes: WorkflowSessionNodeRow[]; nodeStart: number; nodeTotal: number; /** Latest progress update per key, bounded. */ progressUpdates: WorkflowSessionProgressUpdate[]; /** Monitor estimate tracks, when the run publishes them. */ monitorEstimate: JsonValue | null; /** Monitor schedule facts, when the run records one. */ monitorSchedule: { nextCheckAt: string; recordedAt: string; } | null; live: boolean; possiblyInterrupted: boolean; }; /** * The one workflow message Pi must inspect, add, finish, or confirm next. Large * content travels as a content reference that the client verifies on read. */ export type WorkflowSessionMessage = { schema: typeof SESSION_MESSAGE_SCHEMA; workflowMessageId: string; runId: string; targetSessionId: string; kind: WorkflowMessageKind; sourceId: string; order: number; status: WorkflowMessageStatus; piSessionEntryId: string | null; createdAt: string; updatedAt: string; /** Whether adding this message starts a model turn. */ triggerTurn: boolean; customType: string; display: boolean; /** Small content stays inline; large content becomes a content reference. */ content: JsonValue; contentDigest: string; /** The source request was cancelled; delivery can still be sent. */ deliveryCancelled: boolean; }; export type WorkflowSessionView = { schema: typeof SESSION_VIEW_SCHEMA; sessionId: string; /** The current session-owned run, bounded. */ run: WorkflowSessionRunView | null; /** The one interactive request Pi must answer, when one exists. */ interaction: ClientInteractiveRequest | null; /** The one workflow message Pi must handle next, when one exists. */ workflowMessage: WorkflowSessionMessage | null; /** The one open model turn, when one exists. */ openWorkflowTurn: WorkflowTurn | null; coordinatorEpoch: string | null; coordinatorActive: boolean; branchReportRequired: boolean; }; export type WorkflowBranchReport = { targetSessionId: string; coordinatorEpoch: string; /** * The one current workflow message the server asked Pi to confirm, or null * when the session holds no workflow message yet. */ workflowMessageId: string | null; /** The Pi session entry for that message, or null when Pi does not hold it. */ piSessionEntryId: string | null; isIdle: boolean; hasPendingMessages: boolean; }; export type WorkflowBranchReportReceipt = { schema: typeof BRANCH_REPORT_RECEIPT_SCHEMA; /** Whether Pi holds the reported message, and what the server did with it. */ outcome: "present" | "absent"; workflowMessageId: string | null; }; export type WorkflowTurnReportReceipt = { schema: typeof WORKFLOW_TURN_REPORT_RECEIPT_SCHEMA; ownership: "active" | "settled" | "absent"; turn: WorkflowTurn | null; }; export type WorkflowTurnReport = { state: "started"; workflowMessageId: string; workflowTurnId: string; runId: string; targetSessionId: string; coordinatorEpoch: string; } | { state: "ended"; workflowMessageId: string; workflowTurnId: string; runId: string; targetSessionId: string; coordinatorEpoch: string; stopReason: "completed" | "aborted" | "error" | "lost"; responseSessionEntryId: string | null; };