/** * Experimental TypeScript API for the draft ACP v2 protocol. * * @remarks * ACP v2 is still a draft. Its wire protocol and this API may change * incompatibly in any SDK release. The stable package entry point remains ACP * v1; consumers must opt in through * `@agentclientprotocol/sdk/experimental/v2`. * * Session state updates are aggregate snapshots, not per-prompt completions. * Apply repeated snapshots idempotently; a repeated idle stop reason is not a * new completion, cancellation, or usage report. Every successful * `session/resume` sends a current-state snapshot after replay and before its * response, including when replay was not requested. The response does not * imply idle. Agents may send live traffic after initialization even when no * client request is pending. * * Top-level `_meta` on upsert updates patches stored metadata by key: omission * leaves it unchanged, `null` clears it, null-valued keys are removed, and other * values replace their key whole without nested merging. An empty object does * nothing. Replay uses the same rule. Metadata on chunks, content items, * snapshots, and `plan_update` is not an entity patch. * * Experimental operations follow their advertised capabilities; local schema * selection does not establish peer support. Only send lifecycle * `systemPrompt` instructions when the agent advertises `session.systemPrompt`, * and only use `override` when its `mode.override` capability is advertised. * * @packageDocumentation * @experimental */ import * as schema from "./schema/index.js"; import type { NdJsonStreamOptions } from "../stream.js"; export type * from "./schema/types.gen.js"; export { AuthMethod, AvailableCommandInput, ContentBlock, CreateElicitationRequest, CreateElicitationResponse, DiffChange, ElicitationPropertySchema, IdleStateUpdate, McpServer, MultiSelectItems, PlanUpdateContent, ReplayFrom, RequestPermissionOutcome, RequestPermissionSubject, SessionConfigOption, SessionUpdate, SetSessionConfigOptionRequest, StateUpdate, ToolCallContent, } from "./schema/guards.gen.js"; export { AGENT_METHODS, CLIENT_METHODS, PROTOCOL_METHODS, PROTOCOL_VERSION, } from "./schema/index.js"; /** * Experimental draft ACP v2 transport stream supporting individual and batch * JSON-RPC messages. * * @experimental */ export type WireStream = { /** Outgoing individual or batch JSON-RPC messages. */ writable: WritableStream; /** Incoming individual or batch JSON-RPC messages. */ readable: ReadableStream; }; /** * Consumer-facing alias for the experimental draft ACP v2 wire stream. * * @experimental */ export type Stream = WireStream; /** * Creates an experimental draft ACP v2 stream from newline-delimited JSON. * * Individual and batch JSON-RPC messages are accepted by default. * * @experimental */ export declare function ndJsonStream(output: WritableStream, input: ReadableStream, options?: NdJsonStreamOptions): Stream; export { RequestError } from "../jsonrpc.js"; export { DEFAULT_MAX_MESSAGE_BYTES, MessageTooLargeError, } from "../stream-limits.js"; export type { NdJsonStreamOptions } from "../stream.js"; export { AgentProtocolRouter, agentProtocolRouter, } from "../protocol-router.js"; export type { AgentConnectOptions, AgentConnectionLifecycle, AgentConnector, } from "../connection.js"; export type { AnyBatchCall, AnyBatchMessage, AnyBatchResponse, AnyCall, AnyMessage, AnyNotification, AnyRequest, AnyResponse, AnyWireMessage, BatchEntry, BatchNotification, BatchOutputs, BatchRequest, ErrorResponse, JsonRpcId, MaybePromise, Result, SendRequestOptions, } from "../jsonrpc.js"; import type { AnyWireMessage, BatchEntry, BatchNotification, BatchOutputs, BatchRequest, JsonRpcId, MaybePromise, SendRequestOptions } from "../jsonrpc.js"; /** * ACP v2 extension method name. * * New custom methods should begin with `_` so they cannot collide with present * or future protocol methods. * * @experimental */ export type ExtensionMethod = `_${string}`; /** * A method name that is not part of the current ACP v2 draft. * * This compatibility type permits methods from older or newer unstable ACP * revisions while preventing current built-in method literals from falling * through the untyped overloads. Prefer {@link ExtensionMethod} for new custom * methods. * * @experimental */ export type UnrecognizedMethod = string extends Method ? Method : Method extends AgentRequestMethod | AgentNotificationMethod | ClientRequestMethod | ClientNotificationMethod | typeof schema.PROTOCOL_METHODS.cancel_request ? never : Method; /** * Creates a typed request descriptor for an ACP v2 batch. * * Built-in method literals infer their params and response types. Extension * methods retain the low-level helper's explicit params/response generics. * * @experimental */ export declare function batchRequest(method: Method, params: AgentRequestParamsByMethod[Method], options?: SendRequestOptions): BatchRequest & { readonly method: Method; }; export declare function batchRequest(method: Method, params: AgentRequestParamsByMethod[Method], mapResponse: (response: AgentRequestResponsesByMethod[Method]) => Output, options?: SendRequestOptions): BatchRequest & { readonly method: Method; }; export declare function batchRequest(method: Method, params: ClientRequestParamsByMethod[Method], options?: SendRequestOptions): BatchRequest & { readonly method: Method; }; export declare function batchRequest(method: Method, params: ClientRequestParamsByMethod[Method], mapResponse: (response: ClientRequestResponsesByMethod[Method]) => Output, options?: SendRequestOptions): BatchRequest & { readonly method: Method; }; export declare function batchRequest(method: ExtensionMethod, params?: Params, options?: SendRequestOptions): BatchRequest & { readonly method: ExtensionMethod; }; export declare function batchRequest(method: ExtensionMethod, params: Params | undefined, mapResponse: (response: Response) => Output, options?: SendRequestOptions): BatchRequest & { readonly method: ExtensionMethod; }; export declare function batchRequest(method: UnrecognizedMethod, params?: Params, options?: SendRequestOptions): BatchRequest & { readonly method: Method; }; export declare function batchRequest(method: UnrecognizedMethod, params: Params | undefined, mapResponse: (response: Response) => Output, options?: SendRequestOptions): BatchRequest & { readonly method: Method; }; /** * Creates a typed notification descriptor for an ACP v2 batch. * * @experimental */ export declare function batchNotification(method: Method, params: AgentNotificationParamsByMethod[Method]): BatchNotification & { readonly method: Method; }; export declare function batchNotification(method: Method, params: ClientNotificationParamsByMethod[Method]): BatchNotification & { readonly method: Method; }; export declare function batchNotification(method: typeof schema.PROTOCOL_METHODS.cancel_request, params: schema.CancelRequestNotification): BatchNotification & { readonly method: typeof schema.PROTOCOL_METHODS.cancel_request; }; export declare function batchNotification(method: ExtensionMethod, params?: Params): BatchNotification & { readonly method: ExtensionMethod; }; export declare function batchNotification(method: UnrecognizedMethod, params?: Params): BatchNotification & { readonly method: Method; }; /** * Validated initialize request and response for one ACP v2 connection. * * The snapshot becomes available only after the initialize response has been * validated and sent or received successfully. * * @experimental */ export type InitializationSnapshot = Readonly<{ request: schema.InitializeRequest; response: schema.InitializeResponse; }>; /** * ACP method-name constants for the experimental draft v2 API. * * Use these with `onRequest(...)`, `onNotification(...)`, `request(...)`, and * `notify(...)` when you want literal-string type inference without spelling * protocol strings inline. * * @experimental */ export declare const methods: { readonly agent: { readonly initialize: "initialize"; readonly auth: { readonly login: "auth/login"; readonly logout: "auth/logout"; }; readonly providers: { readonly list: "providers/list"; readonly set: "providers/set"; readonly disable: "providers/disable"; }; readonly session: { readonly new: "session/new"; readonly list: "session/list"; readonly delete: "session/delete"; readonly fork: "session/fork"; readonly resume: "session/resume"; readonly close: "session/close"; readonly setConfigOption: "session/set_config_option"; readonly prompt: "session/prompt"; readonly cancel: "session/cancel"; }; readonly mcp: { readonly message: "mcp/message"; }; }; readonly client: { readonly session: { readonly requestPermission: "session/request_permission"; readonly update: "session/update"; }; readonly mcp: { readonly message: "mcp/message"; }; readonly elicitation: { readonly create: "elicitation/create"; readonly complete: "elicitation/complete"; }; }; readonly protocol: { readonly cancelRequest: "$/cancel_request"; }; }; /** * Experimental draft ACP v2 connection returned by `AgentApp.connect(...)` and * `ClientApp.connect(...)`. * * Use this handle when you need a connection to stay open independently of a * single `connectWith(...)` operation. * * @experimental */ export interface AcpConnection { /** * Resolves with the validated initialize exchange once initialization * succeeds, or rejects if initialization or the connection fails. */ readonly initialized: Promise; /** * AbortSignal that aborts when the connection closes. */ readonly signal: AbortSignal; /** * Promise that resolves when the connection closes. */ readonly closed: Promise; /** * Closes the connection and rejects pending requests. */ close(error?: unknown): void; } /** * Experimental draft ACP v2 agent-side connection returned by * `AgentApp.connect(...)`. * * Use `client` to call client-side ACP methods for the lifetime of the * connection. * * @experimental */ export interface AgentConnection extends AcpConnection { /** * Context for calling client-side ACP methods. */ readonly client: AgentContext; } /** * Experimental draft ACP v2 client-side connection returned by * `ClientApp.connect(...)`. * * Use `agent` to call agent-side ACP methods and session helpers for the * lifetime of the connection. * * @experimental */ export interface ClientConnection extends AcpConnection { /** * Context for calling agent-side ACP methods. */ readonly agent: ClientContext; } /** * One batch entry sent to an ACP v2 agent. * * @experimental */ export type AgentBatchEntry = { [Method in AgentRequestMethod]: BatchRequest & { readonly method: Method; }; }[AgentRequestMethod] | { [Method in AgentNotificationMethod]: BatchNotification & { readonly method: Method; }; }[AgentNotificationMethod] | (BatchNotification & { readonly method: typeof schema.PROTOCOL_METHODS.cancel_request; }) | (BatchRequest & { readonly method: ExtensionMethod | UnrecognizedMethod; }) | (BatchNotification & { readonly method: ExtensionMethod | UnrecognizedMethod; }); /** * One batch entry sent to an ACP v2 client. * * @experimental */ export type ClientBatchEntry = { [Method in ClientRequestMethod]: BatchRequest & { readonly method: Method; }; }[ClientRequestMethod] | { [Method in ClientNotificationMethod]: BatchNotification & { readonly method: Method; }; }[ClientNotificationMethod] | (BatchNotification & { readonly method: typeof schema.PROTOCOL_METHODS.cancel_request; }) | (BatchRequest & { readonly method: ExtensionMethod | UnrecognizedMethod; }) | (BatchNotification & { readonly method: ExtensionMethod | UnrecognizedMethod; }); declare class AcpContext { private readonly cx; private readonly currentRequestId?; /** * Validated initialize exchange, once this connection is initialized. */ get initialized(): Promise; /** * JSON-RPC id of the request currently being handled. * * This is `undefined` for notification handlers and for contexts created * outside an inbound request, such as `connect(...)` and `connectWith(...)`. */ get requestId(): JsonRpcId | undefined; } /** * Experimental draft ACP v2 context passed to agent-side handlers. * * Agents use this context to call client-side ACP methods while handling * requests such as `session/prompt`. * * @experimental */ export declare class AgentContext extends AcpContext { private constructor(); /** * Sends a request to the client by ACP method name. * * Built-in method literals infer their params and response types. Custom * methods can specify their response and params types with generics. */ request(method: Method, params: ClientRequestParamsByMethod[Method], options?: SendRequestOptions): Promise; request(method: ExtensionMethod, params?: Params, options?: SendRequestOptions): Promise; request(method: UnrecognizedMethod, params?: Params, options?: SendRequestOptions): Promise; /** * Sends a notification to the client by ACP method name. * * Built-in method literals infer their params type. Custom notifications can * specify their params type with a generic. */ notify(method: Method, params: ClientNotificationParamsByMethod[Method]): Promise; notify(method: typeof schema.PROTOCOL_METHODS.cancel_request, params: schema.CancelRequestNotification): Promise; notify(method: ExtensionMethod, params?: Params): Promise; notify(method: UnrecognizedMethod, params?: Params): Promise; /** * Sends requests and notifications to the client as one JSON-RPC batch. */ batch(entries: Entries & { readonly 0: BatchEntry; } & { [Index in keyof Entries]: Entries[Index] extends BatchEntry ? string extends Entries[Index]["method"] ? Entries[Index] : Entries[Index]["method"] extends AgentRequestMethod | AgentNotificationMethod | ClientRequestMethod | ClientNotificationMethod | typeof schema.PROTOCOL_METHODS.cancel_request ? Entries[Index] extends ClientBatchEntry ? Entries[Index] : never : Entries[Index] : never; }): Promise>; } /** * Experimental draft ACP v2 context used by clients to call agent-side ACP * methods. * * `connectWith` passes a `ClientContext` to the callback. Client handlers also * receive one as `ctx.agent` when they need to call back into the agent. * * @experimental */ export declare class ClientContext extends AcpContext { private readonly closeOnInitializationFailure?; private constructor(); /** * Creates a builder for starting and observing an ACP session. * * Pass an absolute path for the common case where only `cwd` is needed, or * pass a full `NewSessionRequest` when you need MCP servers, `_meta`, or * additional session fields. */ buildSession(cwd: schema.AbsolutePath): SessionBuilder; buildSession(request: schema.NewSessionRequest): SessionBuilder; /** * Builds active-session helpers around a `session/new` response. */ private attachSession; /** * Sends a request to the agent by ACP method name. * * Built-in method literals infer their params and response types. Custom * methods can specify their response and params types with generics. */ request(method: Method, params: AgentRequestParamsByMethod[Method], options?: SendRequestOptions): Promise; request(method: ExtensionMethod, params?: Params, options?: SendRequestOptions): Promise; request(method: UnrecognizedMethod, params?: Params, options?: SendRequestOptions): Promise; /** * Sends a notification to the agent by ACP method name. * * Built-in method literals infer their params type. Custom notifications can * specify their params type with a generic. */ notify(method: Method, params: AgentNotificationParamsByMethod[Method]): Promise; notify(method: typeof schema.PROTOCOL_METHODS.cancel_request, params: schema.CancelRequestNotification): Promise; notify(method: ExtensionMethod, params?: Params): Promise; notify(method: UnrecognizedMethod, params?: Params): Promise; /** * Sends requests and notifications to the agent as one JSON-RPC batch. */ batch(entries: Entries & { readonly 0: BatchEntry; } & { [Index in keyof Entries]: Entries[Index] extends BatchEntry ? string extends Entries[Index]["method"] ? Entries[Index] : Entries[Index]["method"] extends AgentRequestMethod | AgentNotificationMethod | ClientRequestMethod | ClientNotificationMethod | typeof schema.PROTOCOL_METHODS.cancel_request ? Entries[Index] extends AgentBatchEntry ? Entries[Index] : never : Entries[Index] : never; }): Promise>; } /** * Experimental draft ACP v2 message produced by an `ActiveSession`. * * `session_update` messages expose the typed `session/update` notification and * `stop` messages report an idle `state_update`. Both are session-scoped: * a `stop` message does not acknowledge processing or completion of any prompt. * * @experimental */ export type ActiveSessionMessage = { /** * Indicates that this message came from a `session/update` notification. */ kind: "session_update"; /** * Full notification sent by the agent. */ notification: schema.UpdateSessionNotification; /** * Convenience alias for `notification.update`. */ update: schema.SessionUpdate; } | { /** * Indicates an idle foreground snapshot, not necessarily a new completion. */ kind: "stop"; /** * Full notification containing the idle state update. */ notification: schema.UpdateSessionNotification; /** * Convenience alias for `notification.update`. */ update: schema.SessionUpdate; /** * Stop reason reported by the idle state, when provided. */ stopReason: schema.IdleStateUpdate["stopReason"]; }; /** * Experimental draft ACP v2 builder for creating an `ActiveSession`. * * Start from `ctx.buildSession("/absolute/cwd")` for the common case, or * pass a full `NewSessionRequest` to `ctx.buildSession(...)` when the session * needs MCP servers, `_meta`, or additional request fields. All paths in ACP * payloads should be absolute. * * @experimental */ export declare class SessionBuilder { private cx; private request; private constructor(); /** * Returns the `session/new` request that will be sent. * * The returned object is a defensive copy, so mutating it does not change the * builder. */ toRequest(): schema.NewSessionRequest; /** * Replaces the additional workspace roots for this session. * * `additionalDirectories` expand the session's file-system scope without * changing `cwd`. Each path should be absolute. */ withAdditionalDirectories(additionalDirectories: schema.AbsolutePath[]): this; /** * Adds one MCP server to the `session/new` request. */ withMcpServer(mcpServer: schema.McpServer): this; /** * Starts the session and returns an `ActiveSession` for prompting and reading * updates. * * Call `dispose()` on the returned session when you no longer need update * routing, or use `withSession(...)` to scope disposal automatically. */ start(options?: SendRequestOptions): Promise; /** * Starts the session, runs `op`, and disposes the active-session update * routing when `op` finishes or throws. */ withSession(op: (session: ActiveSession) => MaybePromise): Promise; } /** * Experimental draft ACP v2 convenience wrapper for an active session. * * An active session routes `session/update` notifications for one session ID * into an async queue. Use `prompt(...)` to submit user content and * `nextUpdate()` to observe the session independently of prompt requests. * A `stop` message reports idle foreground work, not per-prompt completion. * * @experimental */ export declare class ActiveSession { private cx; private sessionResponse; private updates; private registrations; private constructor(); /** * Session ID returned by `session/new`. */ get sessionId(): schema.SessionId; /** * Configuration options returned when the session was created, if provided. */ get configOptions(): Array | undefined; /** * Metadata returned when the session was created. */ get meta(): { [key: string]: unknown; } | null | undefined; /** * Full response returned by `session/new`. */ get newSessionResponse(): schema.NewSessionResponse; /** * Sends a prompt to this session. * * Strings are converted to one text content block. A single content block is * wrapped in an array. The returned promise resolves with the inserted user * message's ID once the agent inserts it into the ACP conversation, not when * processing finishes. Session updates remain independent of this request; * an idle `state_update` does not establish that this message was processed. * Rejection is reported only by this promise, not by the session update queue. */ prompt(prompt: string | schema.ContentBlock | Array, options?: SendRequestOptions): Promise; /** * Reads the next update or stop message for this session. * * Idle updates are always returned as `stop` messages, whether or not a prompt * is pending. Queued updates are consumed in arrival order. An abort signal * cancels this read without cancelling session work or discarding updates. */ nextUpdate(signal?: AbortSignal): Promise; /** * Collects agent text from the session queue until the next idle update. * * This consumes the same queue as `nextUpdate()`, including already queued * updates. It does not associate output or idle with any submitted prompt, * skip updates when a prompt is sent, or wait for a prompt to be inserted. * Use one reader at a time to avoid splitting the session's updates. * An abort signal cancels the read without cancelling session work. * * Full `agent_message` updates replace content for their `messageId`, while * `agent_message_chunk` updates append to it. Non-text content and other * update types are ignored; use `nextUpdate()` when you need them. */ readTextUntilIdle(signal?: AbortSignal): Promise; /** * Stops routing updates to this active-session helper. * * This does not close the ACP session on the agent. Use `ClientContext` * session lifecycle methods when the protocol session itself should be closed * or deleted. */ dispose(): void; /** * Supports explicit resource management with `using`. */ [Symbol.dispose](): void; private promptBlocks; } /** * Options used when creating an ACP app. */ export type AppOptions = { /** * Human-readable name used in JSON-RPC handler descriptions and diagnostics. */ name?: string; }; /** * Parser used by custom methods to validate or transform raw JSON-RPC params. * * A Zod schema can be passed directly because schemas expose a compatible * `parse(...)` method. */ export type ParamsParser = { /** * Parses raw JSON-RPC params into the handler's typed params. */ parse: (params: unknown) => Params; } | ((params: unknown) => Params); /** * Common context passed to agent-side handlers. */ export type AgentHandlerContext = { /** * Parsed request or notification params. */ params: Params; /** * AbortSignal for the current request, or the connection signal for * notifications. */ signal: AbortSignal; /** * Typed client context for calling client-side ACP methods. */ client: AgentContext; }; /** * Context passed to agent-side request handlers. */ export type AgentRequestContext = AgentHandlerContext & { /** * JSON-RPC id of the request currently being handled. */ requestId: JsonRpcId; }; /** * Context passed to agent-side notification handlers. * * Notifications do not have JSON-RPC request ids. */ export type AgentNotificationContext = AgentHandlerContext; /** * Common context passed to client-side handlers. */ export type ClientHandlerContext = { /** * Parsed request or notification params. */ params: Params; /** * AbortSignal for the current request, or the connection signal for * notifications. */ signal: AbortSignal; /** * Typed agent context for calling agent-side ACP methods. */ agent: ClientContext; }; /** * Context passed to client-side request handlers. */ export type ClientRequestContext = ClientHandlerContext & { /** * JSON-RPC id of the request currently being handled. */ requestId: JsonRpcId; }; /** * Context passed to client-side notification handlers. * * Notifications do not have JSON-RPC request ids. */ export type ClientNotificationContext = ClientHandlerContext; /** * Request handler registered on an `AgentApp`. */ export type AgentRequestHandler = (context: AgentRequestContext) => MaybePromise; /** * Notification handler registered on an `AgentApp`. */ export type AgentNotificationHandler = (context: AgentNotificationContext) => MaybePromise; /** * Request handler registered on a `ClientApp`. */ export type ClientRequestHandler = (context: ClientRequestContext) => MaybePromise; /** * Notification handler registered on a `ClientApp`. */ export type ClientNotificationHandler = (context: ClientNotificationContext) => MaybePromise; /** * Handler called when an `AgentApp` opens a connection. */ export type AgentConnectHandler = (connection: AgentConnection) => MaybePromise; /** * Handler called when a `ClientApp` opens a connection. */ export type ClientConnectHandler = (connection: ClientConnection) => MaybePromise; /** * Agent request handlers keyed by ACP protocol method name. */ export type AgentRequestHandlersByMethod = { [schema.AGENT_METHODS.initialize]: AgentRequestHandler; [schema.AGENT_METHODS.auth_login]: AgentRequestHandler; [schema.AGENT_METHODS.providers_list]: AgentRequestHandler; [schema.AGENT_METHODS.providers_set]: AgentRequestHandler; [schema.AGENT_METHODS.providers_disable]: AgentRequestHandler; [schema.AGENT_METHODS.session_new]: AgentRequestHandler; [schema.AGENT_METHODS.session_set_config_option]: AgentRequestHandler; [schema.AGENT_METHODS.session_prompt]: AgentRequestHandler; [schema.AGENT_METHODS.session_list]: AgentRequestHandler; [schema.AGENT_METHODS.session_delete]: AgentRequestHandler; [schema.AGENT_METHODS.session_fork]: AgentRequestHandler; [schema.AGENT_METHODS.session_resume]: AgentRequestHandler; [schema.AGENT_METHODS.session_close]: AgentRequestHandler; [schema.AGENT_METHODS.auth_logout]: AgentRequestHandler; }; /** * ACP request methods that can be handled by an `AgentApp`. */ export type AgentRequestMethod = keyof AgentRequestHandlersByMethod & string; /** * Agent notification handlers keyed by ACP protocol method name. */ export type AgentNotificationHandlersByMethod = { [schema.AGENT_METHODS .session_cancel]: AgentNotificationHandler; [schema.AGENT_METHODS .mcp_message]: AgentNotificationHandler; }; /** * ACP notification methods that can be handled by an `AgentApp`. */ export type AgentNotificationMethod = keyof AgentNotificationHandlersByMethod & string; /** * Client request handlers keyed by ACP protocol method name. */ export type ClientRequestHandlersByMethod = { [schema.CLIENT_METHODS.session_request_permission]: ClientRequestHandler; [schema.CLIENT_METHODS.mcp_message]: ClientRequestHandler; [schema.CLIENT_METHODS.elicitation_create]: ClientRequestHandler; }; /** * ACP request methods that can be handled by a `ClientApp`. */ export type ClientRequestMethod = keyof ClientRequestHandlersByMethod & string; /** * Client notification handlers keyed by ACP protocol method name. */ export type ClientNotificationHandlersByMethod = { [schema.CLIENT_METHODS .session_update]: ClientNotificationHandler; [schema.CLIENT_METHODS .elicitation_complete]: ClientNotificationHandler; }; /** * ACP notification methods that can be handled by a `ClientApp`. */ export type ClientNotificationMethod = keyof ClientNotificationHandlersByMethod & string; /** * Agent request params keyed by ACP protocol method name. */ export type AgentRequestParamsByMethod = { [Method in AgentRequestMethod]: AgentRequestHandlersByMethod[Method] extends (context: infer Context) => MaybePromise ? Context extends { params: infer Params; } ? Params : never : never; }; /** * Agent request responses keyed by ACP protocol method name. */ export type AgentRequestResponsesByMethod = { [Method in AgentRequestMethod]: AgentRequestHandlersByMethod[Method] extends (context: infer _Context) => MaybePromise ? Exclude : never; }; /** * Agent notification params keyed by ACP protocol method name. */ export type AgentNotificationParamsByMethod = { [Method in AgentNotificationMethod]: AgentNotificationHandlersByMethod[Method] extends (context: infer Context) => MaybePromise ? Context extends { params: infer Params; } ? Params : never : never; }; /** * Client request params keyed by ACP protocol method name. */ export type ClientRequestParamsByMethod = { [Method in ClientRequestMethod]: ClientRequestHandlersByMethod[Method] extends (context: infer Context) => MaybePromise ? Context extends { params: infer Params; } ? Params : never : never; }; /** * Client request responses keyed by ACP protocol method name. */ export type ClientRequestResponsesByMethod = { [Method in ClientRequestMethod]: ClientRequestHandlersByMethod[Method] extends (context: infer _Context) => MaybePromise ? Exclude : never; }; /** * Client notification params keyed by ACP protocol method name. */ export type ClientNotificationParamsByMethod = { [Method in ClientNotificationMethod]: ClientNotificationHandlersByMethod[Method] extends (context: infer Context) => MaybePromise ? Context extends { params: infer Params; } ? Params : never : never; }; /** * Creates an agent-side app for the experimental draft ACP v2 API. * * Register request and notification handlers by ACP method name, then call * `connect(stream)` to serve an ACP client. * * @experimental */ export declare function agent(options?: AppOptions): AgentApp; /** * Agent-side app builder for the experimental draft ACP v2 API. * * Methods on this class register typed request or notification handlers and * return `this`, so apps can be built with a fluent chain. Handler params are * parsed with the generated ACP schemas before your handler runs, and thrown * errors are converted to JSON-RPC errors by the connection layer. * * @experimental */ export declare class AgentApp { private readonly builder; private readonly connectHandlers; private hasInitializeHandler; constructor(options?: AppOptions); /** * Connects this agent app to a transport stream. */ connect(stream: Stream): AgentConnection; /** * Connects this agent app directly to a client app. * * This is useful for tests and in-process examples that do not need a * transport. */ connect(client: ClientApp): AgentConnection; /** * Connects this agent app to a transport stream for the lifetime of `op`. * * The callback receives an `AgentContext` for calling client-side methods. * When `op` resolves or rejects, the connection is closed. */ connectWith(stream: Stream, op: (context: AgentContext) => MaybePromise): Promise; /** * Connects this agent app directly to a client app for the lifetime of `op`. */ connectWith(client: ClientApp, op: (context: AgentContext) => MaybePromise): Promise; /** * Registers a handler that runs when this agent app opens a connection. * * Use this for connection-scoped work that needs to call client-side ACP * methods outside an inbound request handler, or to set up per-connection * state that the request handlers use. Requests and notifications sent * through `connection.client` wait until `initialize` has completed. * * Handlers are called synchronously in registration order and are not * awaited. A handler that throws or rejects closes the connection. When they * are called depends on who opens the connection: * * - `connect(...)` and `connectWith(...)` call them before the connection * handles its first inbound message, and so does * {@link AgentProtocolRouter.connect} when it routes to this app. Only the * work a handler does before its first `await` is guaranteed to come first. * - The experimental `AcpServer` calls them after the client has completed * `initialize`. Request handlers, including `initialize`, can run before * them. */ onConnect(handler: AgentConnectHandler): this; /** * Registers a request handler by ACP method name. * * Built-in method literals infer their params and response types from * `method`. Pass a parser as the second argument to register custom extension * methods. */ onRequest(method: Method, handler: AgentRequestHandlersByMethod[Method]): this; onRequest(method: ExtensionMethod, params: ParamsParser, handler: AgentRequestHandler): this; onRequest(method: UnrecognizedMethod, params: ParamsParser, handler: AgentRequestHandler): this; /** * Registers a notification handler by ACP method name. * * Built-in method literals infer their params type from `method`. Pass a * parser as the second argument to register custom extension notifications. */ onNotification(method: Method, handler: AgentNotificationHandlersByMethod[Method]): this; onNotification(method: ExtensionMethod, params: ParamsParser, handler: AgentNotificationHandler): this; onNotification(method: UnrecognizedMethod, params: ParamsParser, handler: AgentNotificationHandler): this; private request; private notification; private connectConnection; private openStreamConnection; private assertInitializeHandler; } /** * Creates a client-side app for the experimental draft ACP v2 API. * * Register request and notification handlers by ACP method name, then use * `connectWith(...)` to run the workflow that calls agent-side methods. * * @experimental */ export declare function client(options?: AppOptions): ClientApp; /** * Client-side app builder for the experimental draft ACP v2 API. * * Methods on this class register typed client handlers and return `this`, so * apps can be built with a fluent chain. `connectWith(...)` is the usual entry * point for clients because it provides a `ClientContext` for calling * agent-side requests and session helpers. * * @experimental */ export declare class ClientApp { private readonly builder; private readonly connectHandlers; constructor(options?: AppOptions); /** * Connects this client app to a transport stream. */ connect(stream: Stream): ClientConnection; /** * Connects this client app directly to an agent app. * * This is useful for tests and in-process examples that do not need a * transport. */ connect(agent: AgentApp): ClientConnection; /** * Connects this client app to a transport stream for the lifetime of `op`. * * The callback receives a `ClientContext` for calling agent-side methods. * When `op` resolves or rejects, the connection is closed. */ connectWith(stream: Stream, op: (context: ClientContext) => MaybePromise): Promise; /** * Connects this client app directly to an agent app for the lifetime of `op`. */ connectWith(agent: AgentApp, op: (context: ClientContext) => MaybePromise): Promise; /** * Registers a handler that runs when this client app opens a connection. * * Use this for connection-scoped work that needs to call agent-side ACP * methods outside an inbound request handler. */ onConnect(handler: ClientConnectHandler): this; /** * Registers a client request handler by ACP method name. * * Built-in method literals infer their params and response types from * `method`. Pass a parser as the second argument to register custom extension * methods. */ onRequest(method: Method, handler: ClientRequestHandlersByMethod[Method]): this; onRequest(method: ExtensionMethod, params: ParamsParser, handler: ClientRequestHandler): this; onRequest(method: UnrecognizedMethod, params: ParamsParser, handler: ClientRequestHandler): this; /** * Registers a client notification handler by ACP method name. * * Built-in method literals infer their params type from `method`. Pass a * parser as the second argument to register custom extension notifications. */ onNotification(method: Method, handler: ClientNotificationHandlersByMethod[Method]): this; onNotification(method: ExtensionMethod, params: ParamsParser, handler: ClientNotificationHandler): this; onNotification(method: UnrecognizedMethod, params: ParamsParser, handler: ClientNotificationHandler): this; private request; private notification; private connectConnection; private openStreamConnection; }