import { type PersistedRun, type RunStore } from "./persistence.js"; import { WorkflowError, type JsonValue, type WorkflowFailureDiagnostics, type WorkflowMetadata } from "./types.js"; import { SerialLane } from "./utils.js"; export type ForegroundDetachResult = { runId: string; state: "running"; detached: true; run: PersistedRun; }; export type ForegroundDelivery = { store: RunStore; inline: boolean; detached: boolean; detach: () => Promise; timer?: ReturnType; }; export type PendingFailureDiagnostic = { diagnostic: WorkflowFailureDiagnostics; store: RunStore; }; type ForegroundDeliveryControllerOptions = { runs: ReadonlyMap; deliver?: (content: string) => void; }; export declare class ForegroundDeliveryController { private readonly options; readonly foregroundDeliveries: Map; readonly pendingFailureDiagnostics: Map; readonly foregroundResumeClaims: WeakSet; readonly terminalDeliveryLanes: WeakMap; constructor(options: ForegroundDeliveryControllerOptions); deliverTerminal: (store: RunStore, content: string | (() => string | Promise), failure?: boolean) => Promise; scheduleForegroundDelivery: (toolCallId: string, send: () => Promise) => void; foregroundDeliveryCandidates: (runId: string) => Array<[string, ForegroundDelivery]>; moveForegroundToBackground: (runId: string) => Promise; isForegroundAttached: (runId: string) => boolean; queueForegroundDelivery: (toolCallId: string, content: string | (() => string | Promise), foregroundResultReady: Promise, failure?: boolean) => Promise; } export declare function markWorkflowFailureDiagnostics(error: WorkflowError, diagnostic: WorkflowFailureDiagnostics): void; export declare function formatWorkflowFailure(error: unknown): string; export declare function workflowFailedAt(error: unknown): string | undefined; export declare const DELIVERY_LIMIT_BYTES: number; export declare const WORKFLOW_LOG_ENTRY = "workflow-log"; export interface WorkflowLogEntry { workflowName: string; message: string; } export interface CompletionContextUsage { tokens: number | null; contextWindow: number; } export interface CompletionDeliveryModel { contextWindow?: number; maxTokens?: number; } export interface CompletionDeliveryContext { getContextUsage?: () => CompletionContextUsage | undefined; getModel?: () => CompletionDeliveryModel | undefined; model?: CompletionDeliveryModel; } export interface CompletionDeliveryOptions { mode: "foreground" | "background"; name: string; runId: string; value: JsonValue; resultPath: string; resultBytes: number; worktrees: readonly { branch: string; path: string; }[]; context?: CompletionDeliveryContext; } export interface CompletionDeliveryStoreOptions extends Omit { store: Pick; } export interface CompletionDeliveryResult { content: string; inlined: boolean; } export declare function completionDelivery(options: CompletionDeliveryOptions): CompletionDeliveryResult; export declare function completionDeliveryFromStore(options: CompletionDeliveryStoreOptions): Promise; export declare function utf8Prefix(value: string, maxBytes: number): string; export declare function failureDiagnosticsFrom(error: unknown): WorkflowFailureDiagnostics | undefined; export declare function incompleteRetryPaths(paths: readonly string[], completedPaths: readonly string[]): string[]; export declare function createWorkflowFailureDiagnostics(store: RunStore, metadata: WorkflowMetadata, error: unknown, run: PersistedRun): Promise; export declare function formatWorkflowFailureDiagnostics(diagnostic: WorkflowFailureDiagnostics): string; export declare function formatWorkflowFailureDelivery(diagnostic: WorkflowFailureDiagnostics): string; export declare function formatWorkflowFailureDeliveryFallback(workflowName: string, runId: string, runDirectory: string, error: unknown): string; export declare function serializeWorkflowFailureDiagnostics(diagnostic: WorkflowFailureDiagnostics): string; export declare function isWorkflowFailureDiagnostics(value: unknown): value is WorkflowFailureDiagnostics; export {};