import { type AgentCapabilities, type AuthMethod, type Client, type Implementation, type InitializeResponse, type ListSessionsRequest, type ListSessionsResponse, type McpServer, type SessionNotification } from '@agentclientprotocol/sdk'; import { type RuntimeHost } from './host.js'; import { type AgentProfile } from './agents.js'; import { RuntimeSession, type AcpConnectionLike } from './session.js'; import { type AcpTransportDiagnostics } from './diagnostics.js'; import type { RuntimeInspector } from './inspector.js'; import { type RuntimeApprovalQueue, type RuntimeContext, type RuntimeEventStore, type RuntimeObservabilityOptions } from './enterprise-runtime.js'; import type { AcpConnectionFactory, SpawnProcess } from './transports/node.js'; /** * Connection produced by an {@link AcpTransport}. Extends the per-session * {@link AcpConnectionLike} surface with the connection-level methods used * by the runtime during initialize / new session / load session / auth / * setMode / setModel. */ export interface AcpTransportConnection extends AcpConnectionLike { initialize(params: Record): Promise; newSession(params: Record): Promise<{ sessionId: string; configOptions?: unknown[]; modes?: unknown; models?: unknown; }>; loadSession?(params: Record): Promise<{ configOptions?: unknown[]; modes?: unknown; models?: unknown; } | undefined>; authenticate?(params: { methodId: string; }): Promise; setSessionMode?(params: { sessionId: string; modeId: string; }): Promise; unstable_setSessionModel?(params: { sessionId: string; modelId: string; }): Promise; listSessions?(params: ListSessionsRequest): Promise; unstable_closeSession?(params: { sessionId: string; }): Promise; } export interface AcpTransportSession { connection: AcpTransportConnection; /** Optional diagnostic hook; the runtime calls this when enriching startup errors. */ getDiagnostics?(): AcpTransportDiagnostics; } export interface AcpStartupObserverEvent { phase: string; at?: number; detail?: Record; } export interface AcpStartupObserver { mark(event: AcpStartupObserverEvent): void; once?(event: AcpStartupObserverEvent): void; } /** * Transport abstraction. Owns the underlying transport (child process, IPC, * websocket, etc.) and produces an {@link AcpTransportConnection} ready for * `initialize`. The runtime owns the lifecycle of the returned session via * `connection.dispose()`. */ export interface AcpTransport { connect(params: { agent: AgentProfile; host: RuntimeHost; client: Client; cwd: string | undefined; onSessionUpdate: (notification: SessionNotification) => void; startupObserver?: AcpStartupObserver; }): Promise; } export interface RuntimeOptions { /** * Which agent to launch. Pass one of the built-in constants * ({@link GitHubCopilot}, {@link ClaudeCode}, {@link CodexCli}, * {@link GeminiCli}, {@link QwenCode}, {@link OpenCode}) or a custom * {@link AgentProfile} literal. */ agent: AgentProfile; /** * Optional default working directory for sessions created via `newSession()` without an explicit `cwd`. * If omitted, callers MUST provide `cwd` to every `newSession({ cwd })` call. */ cwd?: string; /** * Host capabilities and policy hooks. Defaults to approving tool permissions once and selecting * the first offered auth method. Production applications should provide an explicit host policy. */ host?: RuntimeHost; /** Correlation context copied onto observations and durable event-store entries. */ context?: RuntimeContext; /** Structured runtime observation sink for tracing, metrics, and audit pipelines. */ observability?: RuntimeObservabilityOptions; /** Durable append-only store for observations and normalized session events. */ eventStore?: RuntimeEventStore; /** Session recording store. Receives the same append-only entries as `eventStore` and is intended for replay/debugging. */ recording?: RuntimeEventStore; /** Optional human approval queue used for ACP permission requests. */ approvals?: RuntimeApprovalQueue; /** Runtime inspector that receives observations and, when enabled, ACP wire frames. */ inspector?: RuntimeInspector; /** Optional observer for startup profiling and startup-phase UI updates. */ startupObserver?: AcpStartupObserver; /** * Pluggable transport. Defaults to the node child-process transport * (`@acp-kit/core/node` → `nodeChildProcessTransport`). Browser/Webview hosts * should provide their own transport that bridges to the underlying IPC. */ transport?: AcpTransport; /** @deprecated Provide a custom `transport` instead. Forwarded to the default node transport when set. */ spawnProcess?: SpawnProcess; /** @deprecated Provide a custom `transport` instead. Forwarded to the default node transport when set. */ connectionFactory?: AcpConnectionFactory; } export interface NewSessionOptions { /** * The working directory for this session. Required unless the runtime was created with a default `cwd`. */ cwd?: string; /** MCP servers to advertise to the agent for this session. */ mcpServers?: McpServer[]; } export interface LoadSessionOptions { /** The ACP session id previously returned by `acp.newSession(...).sessionId`. */ sessionId: string; /** The working directory for the resumed session. Required unless the runtime has a default `cwd`. */ cwd?: string; /** MCP servers to advertise to the agent for this session. */ mcpServers?: McpServer[]; } export declare class AcpRuntime { readonly runtimeId: string; private readonly agent; private readonly cwd; private readonly host; private readonly context; private readonly observability; private readonly eventStore; private readonly recording; private readonly approvals; private readonly inspector; private readonly startupObserver; private readonly explicitTransport; private readonly legacySpawnProcess; private readonly legacyConnectionFactory; private connectPromise; private connectionState; private shutdownStarted; constructor(options: RuntimeOptions); /** Information reported by the agent during `initialize`. `null` until the first session is created. */ get agentInfo(): Implementation | null; /** Authentication methods advertised by the agent. Empty array until the first session is created. */ get authMethods(): readonly AuthMethod[]; /** Capabilities advertised by the agent (e.g. `loadSession`). `null` until the first session is created. */ get agentCapabilities(): AgentCapabilities | null; /** Protocol version negotiated with the agent. `null` until the first session is created. */ get protocolVersion(): number | null; /** True once the transport has connected and `initialize` completed. */ get isReady(): boolean; /** * List sessions known to the agent via ACP `session/list`. Requires the agent * to advertise the `sessionCapabilities.list` capability * (see {@link AcpRuntime.agentCapabilities}); throws otherwise. * * Pagination is cursor-based: pass the previous response's `nextCursor` to * fetch the next page. */ listSessions(params?: ListSessionsRequest): Promise; /** * Connect the transport and complete the ACP `initialize` handshake. Idempotent. * Most users do not need to call this directly; `newSession` / `loadSession` will call it for you. */ ready(): Promise; newSession(options?: NewSessionOptions): Promise; /** * Resume a previously created ACP session by id. Requires the agent to advertise the * `loadSession` capability (see `acp.agentCapabilities`). */ loadSession(options: LoadSessionOptions): Promise; /** * Tear down the current transport session (and any ACP sessions on it) without * shutting the runtime down. The next call to `newSession`/`loadSession` will * reconnect transparently. External references to the runtime stay valid; * external references to prior {@link RuntimeSession} instances do not * (they will be in `disposed` status). */ reconnect(): Promise; /** * Dispose every session created by this runtime, then close the agent process. Idempotent. * After shutdown, `newSession` and `loadSession` throw. */ shutdown(): Promise; /** ES Explicit Resource Management: enables `await using acp = createAcpRuntime(...)`. */ [Symbol.asyncDispose](): Promise; private teardownConnection; private requireCwd; private connect; private doConnect; private markStartup; private resolveTransport; private adoptSession; private recordSessionEvent; private recordObservation; private writeStore; private safeCall; } export declare function createRuntime(options: RuntimeOptions): AcpRuntime; /** * Preferred constructor for the ACP Kit runtime. * Equivalent to `createRuntime` (which is kept as an alias for callers that imported the older name). */ export declare function createAcpRuntime(options: RuntimeOptions): AcpRuntime;