/** * Flow execution and telemetry types. */ import type { Message } from "@earendil-works/pi-ai"; import type { SharedContext, CompressionStats } from "../core2/snapshot.js"; /** Aggregated token usage from a flow run. */ export interface UsageStats { input: number; output: number; cacheRead: number; cacheWrite: number; cost: number; contextTokens: number; turns: number; toolCalls: number; smoothedTps?: number; } /** Result of a single flow invocation. */ export interface SingleResult { type: string; agentSource: "user" | "project" | "bundled" | "unknown"; intent: string; aim: string; acceptance?: string; exitCode: number; messages: Message[]; stderr: string; usage: UsageStats; model?: string; stopReason?: string; errorMessage?: string; sawAgentEnd?: boolean; /** Epoch ms when flow execution started; used for live countdown rendering. */ startedAtMs?: number; /** Epoch ms when the flow hard timeout occurs; used for live countdown rendering. */ deadlineAtMs?: number; /** Live in-progress text for status rendering; not part of the final flow report. */ streamingText?: string; /** Max context-window size advertised by the model, if known. */ maxContextTokens?: number; /** Structured JSON output parsed from the flow's final response. */ structuredOutput?: import("./output.js").FlowStructuredOutput; /** Context compression stats if compression was applied during this flow. */ compressionStats?: CompressionStats; /** Lifecycle status for ping-pong flow rendering. Optional — falls back to exitCode inference when absent. */ status?: "pending" | "awaiting" | "running" | "done" | "error" | "skipped"; /** If this result was auto-spawned as an audit, the type of the parent flow it audited. */ auditParentType?: string; /** Explicit group ID assigned by the executor so the renderer can group audit-loop builds with their capstone audit regardless of array contiguity. */ auditLoopGroupId?: number; /** Ping-pong loop metadata — added by executor when auditLoop is used. */ pingPongMeta?: { cycles: number; verdicts: Array<{ cycle: number; verdict: string; feedback?: string; }>; finalVerdict: string; }; } /** Metadata attached to every tool result for rendering. */ export interface FlowDetails { mode: "flow"; flowStyle: "fork"; projectAgentsDir: string | null; results: SingleResult[]; sharedContext?: SharedContext; } /** Metrics emitted after each flow completes. */ export interface FlowMetrics { /** Flow type name. */ type: string; /** Duration in milliseconds. */ durationMs: number; /** Final exit code. */ exitCode: number; /** Whether the flow succeeded. */ success: boolean; /** Model used for this execution. */ model?: string; /** Number of failover attempts. */ failoverCount: number; /** Number of connection-error retries after failover exhaustion. */ connectionRetryCount?: number; /** Token usage. */ usage: UsageStats; /** Flow source. */ source: string; /** Current flow depth. */ depth: number; } /** Public API surface exposed via the pi-agent-flow:ready event. */ export interface PiAgentFlowAPI { /** Discover all available flows for a given working directory. */ discoverFlows: (cwd: string) => { flows: Array<{ name: string; description: string; source: string; }>; projectFlowsDir: string | null; }; /** Determine the model tier for a given flow name. */ getFlowTier: (name: string) => string; /** Get current flow settings. */ getSettings: () => { toolOptimize: boolean; structuredOutput: boolean; maxConcurrency: number; steeringEnabled: boolean; steeringCustomPrompt: string | undefined; animationEnabled: boolean; animationGlitch: boolean; bodyVerbosity: "lite" | "full"; debugMode: boolean; }; } /** Create an empty UsageStats object. */ export declare function emptyFlowUsage(): UsageStats; /** Sum usage across multiple results. */ export declare function aggregateFlowUsage(results: SingleResult[]): UsageStats; /** Whether the child emitted a final assistant text response. */ export declare function hasFlowOutput(r: Pick): boolean; /** Whether the child semantically completed the run. */ export declare function isFlowComplete(r: Pick): boolean; /** Whether a result should be treated as successful by the wrapper/UI. */ export declare function isFlowSuccess(r: SingleResult): boolean; /** Whether a result represents an error. */ export declare function isFlowError(r: SingleResult): boolean; /** Reconcile process exit status with semantic completion observed from Pi's event stream. */ export declare function normalizeFlowResult(result: SingleResult, wasAborted: boolean): SingleResult; /** Extract the last assistant text from a message history. */ export declare function getFlowOutput(messages: Message[]): string; //# sourceMappingURL=flow.d.ts.map