import type { ChannelSchema, NodeFn } from "../types.js"; import type { BaseSwarmState } from "../swarm/config.js"; import type { AgentCapability, SwarmAgentDef } from "../swarm/types.js"; export type ExternalAgentProvider = "codex" | "claude" | (string & {}); export type ExternalAgentMode = "conductor" | "ide"; export type ExternalAgentStatus = "completed" | "failed" | "cancelled"; export type ExternalAgentMergePolicy = "manual" | "workspace" | "patch" | "ignore"; export interface ExternalAgentCapabilities { /** Driver can pass role-separated messages to the provider. */ structuredMessages: boolean; /** Driver can expose ONI tool schemas to the provider. */ toolSchemas: boolean; /** Driver emits token-level assistant deltas. */ tokenStreaming: boolean; /** Driver exposes readable chain-of-thought or reasoning summaries. */ reasoningText: boolean; /** Driver may receive encrypted reasoning blobs but cannot read them. */ reasoningEncrypted: boolean; /** Driver emits structured tool call/tool result events. */ toolCallEvents: boolean; /** Driver emits structured workspace diff events before completion. */ diffStreaming: boolean; /** Provider is expected to edit the workspace through its native tools. */ workspaceWrites: boolean; } export interface ExternalAgentOwnership { allowedPaths?: string[]; disallowedPaths?: string[]; description?: string; } export interface ExternalAgentConversationMessage { role: "system" | "user" | "assistant" | "tool"; content: string; name?: string; toolCallId?: string; } export interface ExternalAgentRunRequest { agentId: string; provider: ExternalAgentProvider; mode: ExternalAgentMode; prompt: string; role?: string; systemPrompt?: string; messages?: ExternalAgentConversationMessage[]; cwd?: string; env?: Record; inheritProcessEnv?: boolean; redactValues?: string[]; timeoutMs?: number; /** Kill the agent if no stdout/stderr activity occurs for this many ms. */ idleTimeoutMs?: number; ownership?: ExternalAgentOwnership; mergePolicy?: ExternalAgentMergePolicy; sharedContext?: Record; metadata?: Record; } export interface ExternalAgentResumeMetadata { providerSessionId?: string; sessionId?: string; command?: string; cwd?: string; metadata?: Record; } export type ExternalAgentEventType = "external_agent_start" | "external_agent_stdout" | "external_agent_stderr" | "external_agent_text_delta" | "external_agent_thinking" | "external_agent_tool_call" | "external_agent_tool_result" | "external_agent_diff" | "external_agent_artifact" | "external_agent_error" | "external_agent_finish"; export interface ExternalAgentEvent { type: ExternalAgentEventType; agentId: string; provider: ExternalAgentProvider; mode: ExternalAgentMode; timestamp: number; content?: string; toolName?: string; toolCallId?: string; path?: string; data?: Record; } export interface ExternalAgentRunResult { agentId: string; provider: ExternalAgentProvider; mode: ExternalAgentMode; status: ExternalAgentStatus; output: string; startedAt: number; endedAt: number; exitCode?: number | null; signal?: NodeJS.Signals | null; error?: string; events: ExternalAgentEvent[]; artifacts?: Record; metadata?: Record; resume?: ExternalAgentResumeMetadata; } export type ExternalAgentEventSink = (event: ExternalAgentEvent) => void; export interface ExternalAgentDriver { provider: ExternalAgentProvider; name?: string; capabilities: ExternalAgentCapabilities; run(request: ExternalAgentRunRequest, emit: ExternalAgentEventSink, signal?: AbortSignal): Promise; } export interface ExternalAgentHostConfig { drivers: ExternalAgentDriver[]; defaultMode?: ExternalAgentMode; onEvent?: ExternalAgentEventSink; } export interface ExternalAgentRuntimeDefinition { provider: ExternalAgentProvider; name?: string; description?: string; createDriver: (options?: unknown) => ExternalAgentDriver; } export interface ExternalAgentRuntimeSummary { provider: ExternalAgentProvider; name?: string; description?: string; capabilities: ExternalAgentCapabilities; } export interface ExternalAgentRuntimeRegistryHostOptions { providers?: ExternalAgentProvider[]; driverOptions?: Record; defaultMode?: ExternalAgentMode; onEvent?: ExternalAgentEventSink; } export interface ExternalAgentNodeConfig { id: string; provider: ExternalAgentProvider; role?: string; systemPrompt?: string; mode?: ExternalAgentMode; cwd?: string; env?: Record; timeoutMs?: number; ownership?: ExternalAgentOwnership; mergePolicy?: ExternalAgentMergePolicy; sharedContext?: Record; includeMessages?: boolean; recordResult?: "text" | "rich"; taskSelector?: (state: S) => string; contextSelector?: (state: S) => Record; metadata?: Record; } export interface ExternalSwarmAgentConfig extends ExternalAgentNodeConfig { driver: ExternalAgentDriver; description?: string; routingCapabilities?: AgentCapability[]; channels?: Partial>; maxConcurrency?: number; maxRetries?: number; timeout?: number; retryDelayMs?: number; } export interface CliExternalAgentDriverConfig { provider: ExternalAgentProvider; command: string; args?: string[] | ((prompt: string, request: ExternalAgentRunRequest) => string[]); cwd?: string; env?: Record; inheritProcessEnv?: boolean; redactValues?: string[]; stdin?: "prompt" | "none"; output?: "text" | "jsonl"; name?: string; capabilities?: Partial; timeoutMs?: number; /** Kill the agent if no stdout/stderr activity occurs for this many ms. */ idleTimeoutMs?: number; maxEvents?: number; maxOutputChars?: number; maxStderrChars?: number; maxEventContentChars?: number; killProcessTree?: boolean; buildPrompt?: (request: ExternalAgentRunRequest) => string; parseStdoutLine?: (line: string, request: ExternalAgentRunRequest) => ExternalAgentEvent | ExternalAgentEvent[] | null; parseStderrLine?: (line: string, request: ExternalAgentRunRequest) => ExternalAgentEvent | ExternalAgentEvent[] | null; /** * @internal Test-only seam: override the timer functions used for the idle * watchdog and overall timeout. Never set this in production drivers. */ _timers?: { setTimeout: (fn: () => void, ms: number) => NodeJS.Timeout; clearTimeout: (timer: NodeJS.Timeout | undefined) => void; }; } export declare class ExternalAgentPathPolicyError extends Error { constructor(message: string); } export declare class ExternalAgentRuntimeRegistry { private readonly definitions; register(definition: ExternalAgentRuntimeDefinition): this; registerDriver(driver: ExternalAgentDriver): this; has(provider: ExternalAgentProvider): boolean; get(provider: ExternalAgentProvider): ExternalAgentRuntimeDefinition; createDriver(provider: ExternalAgentProvider, options?: unknown): ExternalAgentDriver; list(): ExternalAgentRuntimeSummary[]; createHost(options?: ExternalAgentRuntimeRegistryHostOptions): ExternalAgentHost; } export declare function assertExternalAgentPathAllowed(path: string, ownership: ExternalAgentOwnership | undefined, label?: string, baseDir?: string): string; export declare function buildExternalAgentPrompt(request: ExternalAgentRunRequest): string; export declare class ExternalAgentHost { private readonly drivers; private readonly listeners; private readonly defaultMode; constructor(config: ExternalAgentHostConfig); getDriver(provider: ExternalAgentProvider): ExternalAgentDriver; onEvent(listener: ExternalAgentEventSink): () => void; run(prompt: string, config: Omit & { provider: ExternalAgentProvider; mode?: ExternalAgentMode; }, signal?: AbortSignal): Promise; asNode(config: ExternalAgentNodeConfig, signal?: AbortSignal): NodeFn; asSwarmAgent(config: Omit, "driver">, signal?: AbortSignal): SwarmAgentDef; private emit; } export declare function runExternalAgent(driver: ExternalAgentDriver, request: ExternalAgentRunRequest, onEvent?: ExternalAgentEventSink, signal?: AbortSignal): Promise; export declare function externalAgentAsNode(driver: ExternalAgentDriver, config: ExternalAgentNodeConfig, onEvent?: ExternalAgentEventSink, signal?: AbortSignal): NodeFn; export declare function createExternalSwarmAgent(config: ExternalSwarmAgentConfig, onEvent?: ExternalAgentEventSink, signal?: AbortSignal): SwarmAgentDef; export declare function createCliExternalAgentDriver(config: CliExternalAgentDriverConfig): ExternalAgentDriver; export declare class ExternalAgentOptionPolicyError extends Error { constructor(message: string); } export interface ExternalAgentUnsafeOptionPolicy { /** * Allows raw provider CLI flags. Keep false for governed background agents. */ allowExtraArgs?: boolean; /** * Allows Codex's full approval/sandbox bypass flag. */ allowDangerousSandboxBypass?: boolean; /** * Allows Claude Code's permission bypass mode. */ allowPermissionBypass?: boolean; } export interface CodexExecDriverOptions extends Partial { command?: string; model?: string; profile?: string; sandbox?: "read-only" | "workspace-write" | "danger-full-access"; approvalPolicy?: "untrusted" | "on-failure" | "on-request" | "never"; addDirs?: string[]; skipGitRepoCheck?: boolean; ephemeral?: boolean; ignoreUserConfig?: boolean; ignoreRules?: boolean; outputSchema?: string; dangerouslyBypassApprovalsAndSandbox?: boolean; extraArgs?: string[]; unsafe?: ExternalAgentUnsafeOptionPolicy; } export declare function validateCodexExecDriverOptions(options?: CodexExecDriverOptions): void; export declare function buildCodexExecArgs(prompt: string, request: ExternalAgentRunRequest, options?: CodexExecDriverOptions): string[]; export declare function createCodexExecDriver(options?: CodexExecDriverOptions): ExternalAgentDriver; export interface ClaudeCodeDriverOptions extends Partial { command?: string; model?: string; fallbackModel?: string; permissionMode?: "acceptEdits" | "auto" | "bypassPermissions" | "default" | "dontAsk" | "plan"; allowedTools?: string[]; disallowedTools?: string[]; tools?: string[]; addDirs?: string[]; mcpConfig?: string[]; strictMcpConfig?: boolean; includePartialMessages?: boolean; includeHookEvents?: boolean; maxBudgetUsd?: number; sessionId?: string; sessionName?: string; worktree?: boolean | string; bare?: boolean; extraArgs?: string[]; unsafe?: ExternalAgentUnsafeOptionPolicy; } export declare function validateClaudeCodeDriverOptions(options?: ClaudeCodeDriverOptions): void; export declare function buildClaudeCodeArgs(prompt: string, request: ExternalAgentRunRequest, options?: ClaudeCodeDriverOptions): string[]; export declare function createClaudeCodeDriver(options?: ClaudeCodeDriverOptions): ExternalAgentDriver; export interface DefaultExternalAgentRuntimeRegistryOptions { codex?: CodexExecDriverOptions | false; claude?: ClaudeCodeDriverOptions | false; } export declare function createDefaultExternalAgentRuntimeRegistry(options?: DefaultExternalAgentRuntimeRegistryOptions): ExternalAgentRuntimeRegistry; export declare function parseGenericJsonAgentLine(line: string, request: ExternalAgentRunRequest): ExternalAgentEvent | ExternalAgentEvent[] | null; export declare function parseCodexJsonLine(line: string, request: ExternalAgentRunRequest): ExternalAgentEvent | ExternalAgentEvent[] | null; export declare function parseClaudeJsonLine(line: string, request: ExternalAgentRunRequest): ExternalAgentEvent | ExternalAgentEvent[] | null; //# sourceMappingURL=external-agent.d.ts.map