import type { Static, TSchema } from "typebox"; import type { AgentHistoryEntry } from "./agent-history.js"; import { type ExecutorRegistry, type ExecutorUsage, type WorkflowExecutor } from "./executor.js"; /** * Dependency-neutral constructor options shared by the portable runner and the * Pi-backed WorkflowAgent it creates on demand. * * Pi-specific values intentionally remain opaque here. Keeping their types out * of this module prevents importing the Pi SDK merely to run Codex or Claude * Code; the values are forwarded unchanged if the caller later selects Pi. */ export interface PortableAgentRunnerOptions { cwd?: string; tools?: readonly unknown[]; excludeTools?: string[]; session?: unknown; instructions?: string; mainModel?: string; modelRegistry?: unknown; executorRegistry?: ExecutorRegistry; persistAgentSessions?: boolean; } /** Run options accepted without loading a host-specific agent SDK. */ export interface PortableAgentRunOptions { label?: string; executor?: WorkflowExecutor; sessionName?: string; schema?: TSchemaDef; tools?: readonly unknown[]; instructions?: string; signal?: AbortSignal; onUsage?: (usage: ExecutorUsage) => void; model?: string; tier?: string; onModelResolved?: (modelId: string) => void; onModelFallback?: (requestedSpec: string) => void; onHistory?: (history: AgentHistoryEntry[]) => void; cwd?: string; toolNames?: string[]; disallowedToolNames?: string[]; maxSchemaRetries?: number; systemTools?: readonly unknown[]; modelRegistry?: unknown; } export type PortableAgentRunResult = TSchemaDef extends TSchema ? Static : string; /** The small structural surface used after the optional Pi module is loaded. */ export interface PortablePiAgent { run(prompt: string, options?: PortableAgentRunOptions): Promise>; } export interface PortablePiAgentModule { WorkflowAgent: new (options?: PortableAgentRunnerOptions) => PortablePiAgent; } /** Injectable only so embedders/tests can control how the optional Pi host loads. */ export interface PortableAgentRunnerDependencies { loadPiAgent?: () => Promise; } /** * Default workflow agent runner for host-neutral runtimes. * * Codex and Claude Code are dispatched directly through ExecutorRegistry. The * Pi implementation and its SDK peers are imported only when a call actually * selects `executor: "pi"` (also the default), then the WorkflowAgent instance * is cached for all subsequent Pi calls. */ export declare class PortableAgentRunner { private readonly cwd; private readonly instructions?; private readonly executorRegistry; private readonly piOptions; private readonly loadPiAgent; private piAgentPromise?; constructor(options?: PortableAgentRunnerOptions, dependencies?: PortableAgentRunnerDependencies); run(prompt: string, options?: PortableAgentRunOptions): Promise>; private getPiAgent; /** Build the same adapter-neutral prompt used by WorkflowAgent's external path. */ private buildExternalPrompt; }