// This file is auto-generated by @hey-api/openapi-ts import { defaultOnError, excludeKnownTags, preserveCustomPayload, requiredDefaultOnError, vecSkipError, } from "../schema-deserialize.js"; import * as z from "zod/v4"; /** * JSON RPC Request Id * * An identifier established by the Client that MUST contain a String, Number, or NULL value if included. If it is not included it is assumed to be a notification. The value SHOULD normally not be Null \[1\] and Numbers SHOULD NOT contain fractional parts \[2\] * * The Server MUST reply with the same value in the Response object if included. This member is used to correlate the context between the two objects. * * \[1\] The use of Null as a value for the id member in a Request object is discouraged, because this specification uses a value of Null for Responses with an unknown id. Also, because JSON-RPC 1.0 uses an id value of Null for Notifications this could cause confusion in handling. * * \[2\] Fractional parts may be problematic, since many decimal fractions cannot be represented exactly as binary fractions. */ export const zRequestId = z.union([z.number(), z.string()]).nullable(); /** * A unique identifier for a conversation session between a client and agent. * * Sessions maintain their own context, conversation history, and state, * allowing multiple independent interactions with the same agent. * * See protocol docs: [Session ID](https://agentclientprotocol.com/protocol/session-setup#session-id) */ export const zSessionId = z.string(); /** * Request to write content to a text file. * * Only available if the client supports the `fs.writeTextFile` capability. */ export const zWriteTextFileRequest = z.object({ sessionId: zSessionId, path: z.string(), content: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request to read content from a text file. * * Only available if the client supports the `fs.readTextFile` capability. */ export const zReadTextFileRequest = z.object({ sessionId: zSessionId, path: z.string(), line: defaultOnError( z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), () => undefined, ), limit: defaultOnError( z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Unique identifier for a tool call within a session. */ export const zToolCallId = z.string(); /** * Categories of tools that can be invoked. * * Tool kinds help clients choose appropriate icons and optimize how they * display tool execution progress. * * See protocol docs: [Creating](https://agentclientprotocol.com/protocol/tool-calls#creating) */ export const zToolKind = z.union([ z.literal("read"), z.literal("edit"), z.literal("delete"), z.literal("move"), z.literal("search"), z.literal("execute"), z.literal("think"), z.literal("fetch"), z.literal("switch_mode"), z.literal("other"), ]); /** * Execution status of a tool call. * * Tool calls progress through different statuses during their lifecycle. * * See protocol docs: [Status](https://agentclientprotocol.com/protocol/tool-calls#status) */ export const zToolCallStatus = z.union([ z.literal("pending"), z.literal("in_progress"), z.literal("completed"), z.literal("failed"), ]); /** * The sender or recipient of messages and data in a conversation. */ export const zRole = z.union([z.literal("assistant"), z.literal("user")]); /** * Optional annotations for the client. The client can use annotations to inform how objects are used or displayed */ export const zAnnotations = z.object({ audience: defaultOnError(vecSkipError(zRole).nullish(), () => undefined), lastModified: defaultOnError(z.string().nullish(), () => undefined), priority: defaultOnError(z.number().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Text provided to or from an LLM. */ export const zTextContent = z.object({ annotations: defaultOnError(zAnnotations.nullish(), () => undefined), text: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * An image provided to or from an LLM. */ export const zImageContent = z.object({ annotations: defaultOnError(zAnnotations.nullish(), () => undefined), data: z.string(), mimeType: z.string(), uri: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Audio provided to or from an LLM. */ export const zAudioContent = z.object({ annotations: defaultOnError(zAnnotations.nullish(), () => undefined), data: z.string(), mimeType: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A resource that the server is capable of reading, included in a prompt or tool call result. */ export const zResourceLink = z.object({ annotations: defaultOnError(zAnnotations.nullish(), () => undefined), description: defaultOnError(z.string().nullish(), () => undefined), mimeType: defaultOnError(z.string().nullish(), () => undefined), name: z.string(), size: defaultOnError(z.number().nullish(), () => undefined), title: defaultOnError(z.string().nullish(), () => undefined), uri: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Text-based resource contents. */ export const zTextResourceContents = z.object({ mimeType: defaultOnError(z.string().nullish(), () => undefined), text: z.string(), uri: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Binary resource contents. */ export const zBlobResourceContents = z.object({ blob: z.string(), mimeType: defaultOnError(z.string().nullish(), () => undefined), uri: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Resource content that can be embedded in a message. */ export const zEmbeddedResourceResource = z.union([ zTextResourceContents, zBlobResourceContents, ]); /** * The contents of a resource, embedded into a prompt or tool call result. */ export const zEmbeddedResource = z.object({ annotations: defaultOnError(zAnnotations.nullish(), () => undefined), resource: zEmbeddedResourceResource, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Content blocks represent displayable information in the Agent Client Protocol. * * They provide a structured way to handle various types of user-facing content—whether * it's text from language models, images for analysis, or embedded resources for context. * * Content blocks appear in: * - User prompts sent via `session/prompt` * - Language model output streamed through `session/update` notifications * - Progress updates and results from tool calls * * This structure is compatible with the Model Context Protocol (MCP), enabling * agents to seamlessly forward content from MCP tool outputs without transformation. * * See protocol docs: [Content](https://agentclientprotocol.com/protocol/content) */ export const zContentBlock = z.union([ zTextContent.and( z.object({ type: z.literal("text"), }), ), zImageContent.and( z.object({ type: z.literal("image"), }), ), zAudioContent.and( z.object({ type: z.literal("audio"), }), ), zResourceLink.and( z.object({ type: z.literal("resource_link"), }), ), zEmbeddedResource.and( z.object({ type: z.literal("resource"), }), ), ]); /** * Standard content block (text, images, resources). */ export const zContent = z.object({ content: zContentBlock, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A diff representing file modifications. * * Shows changes to files in a format suitable for display in the client UI. * * See protocol docs: [Content](https://agentclientprotocol.com/protocol/tool-calls#content) */ export const zDiff = z.object({ path: z.string(), oldText: defaultOnError(z.string().nullish(), () => undefined), newText: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Typed identifier used for terminal values on the wire. */ export const zTerminalId = z.string(); /** * Embed a terminal created with `terminal/create` by its id. * * The terminal must be added before calling `terminal/release`. * * See protocol docs: [Terminal](https://agentclientprotocol.com/protocol/terminals) */ export const zTerminal = z.object({ terminalId: zTerminalId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Content produced by a tool call. * * Tool calls can produce different types of content including * standard content blocks (text, images) or file diffs. * * See protocol docs: [Content](https://agentclientprotocol.com/protocol/tool-calls#content) */ export const zToolCallContent = z.union([ zContent.and( z.object({ type: z.literal("content"), }), ), zDiff.and( z.object({ type: z.literal("diff"), }), ), zTerminal.and( z.object({ type: z.literal("terminal"), }), ), ]); /** * A file location being accessed or modified by a tool. * * Enables clients to implement "follow-along" features that track * which files the agent is working with in real-time. * * See protocol docs: [Following the Agent](https://agentclientprotocol.com/protocol/tool-calls#following-the-agent) */ export const zToolCallLocation = z.object({ path: z.string(), line: defaultOnError( z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * An update to an existing tool call. * * Used to report progress and results as tools execute. All fields except * the tool call ID are optional - only changed fields need to be included. * * See protocol docs: [Updating](https://agentclientprotocol.com/protocol/tool-calls#updating) */ export const zToolCallUpdate = z.object({ toolCallId: zToolCallId, kind: defaultOnError(zToolKind.nullish(), () => undefined), status: defaultOnError(zToolCallStatus.nullish(), () => undefined), title: defaultOnError(z.string().nullish(), () => undefined), name: defaultOnError(z.string().nullish(), () => undefined), content: defaultOnError( vecSkipError(zToolCallContent).nullish(), () => undefined, ), locations: defaultOnError( vecSkipError(zToolCallLocation).nullish(), () => undefined, ), rawInput: defaultOnError(z.unknown().optional(), () => undefined), rawOutput: defaultOnError(z.unknown().optional(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Unique identifier for a permission option. */ export const zPermissionOptionId = z.string(); /** * The type of permission option being presented to the user. * * Helps clients choose appropriate icons and UI treatment. */ export const zPermissionOptionKind = z.union([ z.literal("allow_once"), z.literal("allow_always"), z.literal("reject_once"), z.literal("reject_always"), ]); /** * An option presented to the user when requesting permission. */ export const zPermissionOption = z.object({ optionId: zPermissionOptionId, name: z.string(), kind: zPermissionOptionKind, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request for user permission to execute a tool call. * * Sent when the agent needs authorization before performing a sensitive operation. * * See protocol docs: [Requesting Permission](https://agentclientprotocol.com/protocol/tool-calls#requesting-permission) */ export const zRequestPermissionRequest = z.object({ sessionId: zSessionId, toolCall: zToolCallUpdate, options: z.array(zPermissionOption), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * An environment variable to set when launching an MCP server. */ export const zEnvVariable = z.object({ name: z.string(), value: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request to create a new terminal and execute a command. */ export const zCreateTerminalRequest = z.object({ sessionId: zSessionId, command: z.string(), args: defaultOnError(vecSkipError(z.string()).optional(), () => []), env: defaultOnError(vecSkipError(zEnvVariable).optional(), () => []), cwd: defaultOnError(z.string().nullish(), () => undefined), outputByteLimit: defaultOnError(z.number().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request to get the current output and status of a terminal. */ export const zTerminalOutputRequest = z.object({ sessionId: zSessionId, terminalId: zTerminalId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request to release a terminal and free its resources. */ export const zReleaseTerminalRequest = z.object({ sessionId: zSessionId, terminalId: zTerminalId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request to wait for a terminal command to exit. */ export const zWaitForTerminalExitRequest = z.object({ sessionId: zSessionId, terminalId: zTerminalId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request to kill a terminal without releasing it. */ export const zKillTerminalRequest = z.object({ sessionId: zSessionId, terminalId: zTerminalId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Session-scoped elicitation, optionally tied to a specific tool call. * * When `tool_call_id` is set, the elicitation is tied to a specific tool call. * This is useful when an agent receives an elicitation from an MCP server * during a tool call and needs to redirect it to the user. * * @experimental */ export const zElicitationSessionScope = z.object({ sessionId: zSessionId, toolCallId: defaultOnError(zToolCallId.nullish(), () => undefined), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request-scoped elicitation, tied to a specific JSON-RPC request outside of a session * (e.g., during auth/configuration phases before any session is started). * * @experimental */ export const zElicitationRequestScope = z.object({ requestId: zRequestId, }); /** * Object schema type. */ export const zElicitationSchemaType = z.literal("object"); /** * String format types for string properties in elicitation schemas. */ export const zStringFormat = z.union([ z.literal("email"), z.literal("uri"), z.literal("date"), z.literal("date-time"), ]); /** * A titled enum option with a const value, human-readable title, and optional description. */ export const zEnumOption = z.object({ const: z.string(), title: z.string(), description: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Schema for string properties in an elicitation form. * * When `enum` or `oneOf` is set, this represents a single-select enum * with `"type": "string"`. */ export const zStringPropertySchema = z.object({ title: defaultOnError(z.string().nullish(), () => undefined), description: defaultOnError(z.string().nullish(), () => undefined), minLength: z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), maxLength: z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), pattern: z.string().nullish(), format: zStringFormat.nullish(), default: defaultOnError(z.string().nullish(), () => undefined), enum: z.array(z.string()).nullish(), oneOf: z.array(zEnumOption).nullish(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Schema for number (floating-point) properties in an elicitation form. */ export const zNumberPropertySchema = z.object({ title: defaultOnError(z.string().nullish(), () => undefined), description: defaultOnError(z.string().nullish(), () => undefined), minimum: z.number().nullish(), maximum: z.number().nullish(), default: defaultOnError(z.number().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Schema for integer properties in an elicitation form. */ export const zIntegerPropertySchema = z.object({ title: defaultOnError(z.string().nullish(), () => undefined), description: defaultOnError(z.string().nullish(), () => undefined), minimum: z.number().nullish(), maximum: z.number().nullish(), default: defaultOnError(z.number().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Schema for boolean properties in an elicitation form. */ export const zBooleanPropertySchema = z.object({ title: defaultOnError(z.string().nullish(), () => undefined), description: defaultOnError(z.string().nullish(), () => undefined), default: defaultOnError(z.boolean().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * String item schema for multi-select enum properties. */ export const zStringMultiSelectItems = z.object({ enum: z.array(z.string()), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Items definition for titled multi-select enum properties. */ export const zTitledMultiSelectItems = z.object({ anyOf: z.array(zEnumOption), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Items for a multi-select (array) property schema. * * Custom variants (unknown `type` values) keep their extra * properties exactly as received; unlike known variants, those keys * bypass lenient-field salvage and arrive unvalidated. */ export const zMultiSelectItems = preserveCustomPayload( z.union([ zStringMultiSelectItems.and( z.object({ type: z.literal("string"), }), ), excludeKnownTags( z.object({ type: z.string(), }), "type", ["string"], ), zTitledMultiSelectItems, ]), "type", ["string"], ); /** * Schema for multi-select (array) properties in an elicitation form. */ export const zMultiSelectPropertySchema = z.object({ title: defaultOnError(z.string().nullish(), () => undefined), description: defaultOnError(z.string().nullish(), () => undefined), minItems: z.number().nullish(), maxItems: z.number().nullish(), items: zMultiSelectItems, default: defaultOnError(vecSkipError(z.string()).nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Property schema for elicitation form fields. * * Each variant corresponds to a JSON Schema `"type"` value. * Single-select enums use the `String` variant with `enum` or `oneOf` set. * Multi-select enums use the `Array` variant. * * Custom variants (unknown `type` values) keep their extra * properties exactly as received; unlike known variants, those keys * bypass lenient-field salvage and arrive unvalidated. */ export const zElicitationPropertySchema = preserveCustomPayload( z.union([ zStringPropertySchema.and( z.object({ type: z.literal("string"), }), ), zNumberPropertySchema.and( z.object({ type: z.literal("number"), }), ), zIntegerPropertySchema.and( z.object({ type: z.literal("integer"), }), ), zBooleanPropertySchema.and( z.object({ type: z.literal("boolean"), }), ), zMultiSelectPropertySchema.and( z.object({ type: z.literal("array"), }), ), excludeKnownTags( z.object({ type: z.string(), }), "type", ["array", "boolean", "integer", "number", "string"], ), ]), "type", ["array", "boolean", "integer", "number", "string"], ); /** * Type-safe elicitation schema for requesting structured user input. * * This represents a JSON Schema object with primitive-typed properties, * as required by the elicitation specification. */ export const zElicitationSchema = z.object({ type: defaultOnError( zElicitationSchemaType.optional().default("object"), () => "object" as const, ), title: defaultOnError(z.string().nullish(), () => undefined), properties: z .record(z.string(), zElicitationPropertySchema) .optional() .default({}), required: z.array(z.string()).nullish(), description: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Form-based elicitation mode where the client renders a form from the provided schema. * * @experimental */ export const zElicitationFormMode = z.intersection( z.union([zElicitationSessionScope, zElicitationRequestScope]), z.object({ requestedSchema: zElicitationSchema, }), ); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Unique identifier for an elicitation. * * @experimental */ export const zElicitationId = z.string(); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * URL-based elicitation mode where the client directs the user to a URL. * * @experimental */ export const zElicitationUrlMode = z.intersection( z.union([zElicitationSessionScope, zElicitationRequestScope]), z.object({ elicitationId: zElicitationId, url: z.url(), }), ); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request from the agent to elicit structured user input. * * The agent sends this to the client to request information from the user, * either via a form or by directing them to a URL. * Elicitations are tied to a session (optionally a tool call) or a request. * * @experimental * * Custom variants (unknown `mode` values) keep their extra * properties exactly as received; unlike known variants, those keys * bypass lenient-field salvage and arrive unvalidated. */ export const zCreateElicitationRequest = preserveCustomPayload( z.intersection( z.union([ zElicitationFormMode.and( z.object({ mode: z.literal("form"), }), ), zElicitationUrlMode.and( z.object({ mode: z.literal("url"), }), ), excludeKnownTags( z.intersection( z.union([zElicitationSessionScope, zElicitationRequestScope]), z.object({ mode: z.string(), }), ), "mode", ["form", "url"], ), ]), z.object({ message: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }), ), "mode", ["form", "url"], ); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Unique identifier for an MCP server using the ACP transport. * * The value is opaque and generated by the ACP component providing the MCP server. It is * used by `mcp/connect` to route connection requests back to the component that declared the * server. * * @experimental */ export const zMcpServerAcpId = z.string(); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request parameters for `mcp/connect`. * * @experimental */ export const zConnectMcpRequest = z.object({ serverId: zMcpServerAcpId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * A unique identifier for an active MCP-over-ACP connection. * * @experimental */ export const zMcpConnectionId = z.string(); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request parameters for `mcp/message`. * * @experimental */ export const zMessageMcpRequest = z.object({ connectionId: zMcpConnectionId, method: z.string(), params: z.record(z.string(), z.unknown()).nullish(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request parameters for `mcp/disconnect`. * * @experimental */ export const zDisconnectMcpRequest = z.object({ connectionId: zMcpConnectionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Allows for sending an arbitrary request that is not part of the ACP spec. * Extension methods provide a way to add custom functionality while maintaining * protocol compatibility. * * See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility) */ export const zExtRequest = z.unknown(); /** * A JSON-RPC request object. */ export const zAgentRequest = z.object({ id: zRequestId, method: z.string(), params: z .union([ zWriteTextFileRequest, zReadTextFileRequest, zRequestPermissionRequest, zCreateTerminalRequest, zTerminalOutputRequest, zReleaseTerminalRequest, zWaitForTerminalExitRequest, zKillTerminalRequest, zCreateElicitationRequest, zConnectMcpRequest, zMessageMcpRequest, zDisconnectMcpRequest, zExtRequest, ]) .nullish(), }); /** * Protocol version identifier. * * This version is only bumped for breaking changes. * Non-breaking changes should be introduced via capabilities. */ export const zProtocolVersion = z.int().gte(0).lte(65535); /** * Prompt capabilities supported by the agent in `session/prompt` requests. * * Baseline agent functionality requires support for [`ContentBlock::Text`] * and [`ContentBlock::ResourceLink`] in prompt requests. * * Other variants must be explicitly opted in to. * Capabilities for different types of content in prompt requests. * * Indicates which content types beyond the baseline (text and resource links) * the agent can process. * * See protocol docs: [Prompt Capabilities](https://agentclientprotocol.com/protocol/initialization#prompt-capabilities) */ export const zPromptCapabilities = z.object({ image: defaultOnError( z.boolean().optional().default(false), () => false as const, ), audio: defaultOnError( z.boolean().optional().default(false), () => false as const, ), embeddedContext: defaultOnError( z.boolean().optional().default(false), () => false as const, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * MCP capabilities supported by the agent */ export const zMcpCapabilities = z.object({ http: defaultOnError( z.boolean().optional().default(false), () => false as const, ), sse: defaultOnError( z.boolean().optional().default(false), () => false as const, ), acp: defaultOnError( z.boolean().optional().default(false), () => false as const, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for the `session/list` method. * * Supplying `{}` means the agent supports listing sessions. */ export const zSessionListCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for the `session/delete` method. * * Supplying `{}` means the agent supports deleting sessions from `session/list`. */ export const zSessionDeleteCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for additional session directories support. * * Supplying `{}` means the agent supports the `additionalDirectories` field on * supported session lifecycle requests. Agents that also support * `session/list` may return `SessionInfo.additionalDirectories` to report the * complete ordered additional-root list associated with a listed session. */ export const zSessionAdditionalDirectoriesCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Capabilities for the `session/fork` method. * * Supplying `{}` means the agent supports forking sessions. * * @experimental */ export const zSessionForkCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for the `session/resume` method. * * Supplying `{}` means the agent supports resuming sessions. */ export const zSessionResumeCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for the `session/close` method. * * Supplying `{}` means the agent supports closing sessions. */ export const zSessionCloseCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Session capabilities supported by the agent. * * As a baseline, all Agents **MUST** support `session/new`, `session/prompt`, `session/cancel`, and `session/update`. * * Optionally, they **MAY** support other session methods and notifications by specifying additional capabilities. * * Note: `session/load` is still handled by the top-level `load_session` capability. This will be unified in future versions of the protocol. * * See protocol docs: [Session Capabilities](https://agentclientprotocol.com/protocol/initialization#session-capabilities) */ export const zSessionCapabilities = z.object({ list: defaultOnError(zSessionListCapabilities.nullish(), () => undefined), delete: defaultOnError(zSessionDeleteCapabilities.nullish(), () => undefined), additionalDirectories: defaultOnError( zSessionAdditionalDirectoriesCapabilities.nullish(), () => undefined, ), fork: defaultOnError(zSessionForkCapabilities.nullish(), () => undefined), resume: defaultOnError(zSessionResumeCapabilities.nullish(), () => undefined), close: defaultOnError(zSessionCloseCapabilities.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Logout capabilities supported by the agent. * * Supplying `{}` means the agent supports the logout method. */ export const zLogoutCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Authentication-related capabilities supported by the agent. */ export const zAgentAuthCapabilities = z.object({ logout: defaultOnError(zLogoutCapabilities.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Provider configuration capabilities supported by the agent. * * Supplying `{}` means the agent supports provider configuration methods. * * @experimental */ export const zProvidersCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Marker for `document/didOpen` capability support. */ export const zNesDocumentDidOpenCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * How the agent wants document changes delivered. */ export const zTextDocumentSyncKind = z.union([ z.literal("full"), z.literal("incremental"), ]); /** * Capabilities for `document/didChange` events. */ export const zNesDocumentDidChangeCapabilities = z.object({ syncKind: zTextDocumentSyncKind, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Marker for `document/didClose` capability support. */ export const zNesDocumentDidCloseCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Marker for `document/didSave` capability support. */ export const zNesDocumentDidSaveCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Marker for `document/didFocus` capability support. */ export const zNesDocumentDidFocusCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Document event capabilities the agent wants to receive. */ export const zNesDocumentEventCapabilities = z.object({ didOpen: defaultOnError( zNesDocumentDidOpenCapabilities.nullish(), () => undefined, ), didChange: defaultOnError( zNesDocumentDidChangeCapabilities.nullish(), () => undefined, ), didClose: defaultOnError( zNesDocumentDidCloseCapabilities.nullish(), () => undefined, ), didSave: defaultOnError( zNesDocumentDidSaveCapabilities.nullish(), () => undefined, ), didFocus: defaultOnError( zNesDocumentDidFocusCapabilities.nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Event capabilities the agent can consume. */ export const zNesEventCapabilities = z.object({ document: defaultOnError( zNesDocumentEventCapabilities.nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for recent files context. */ export const zNesRecentFilesCapabilities = z.object({ maxCount: defaultOnError( z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for related snippets context. */ export const zNesRelatedSnippetsCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for edit history context. */ export const zNesEditHistoryCapabilities = z.object({ maxCount: defaultOnError( z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for user actions context. */ export const zNesUserActionsCapabilities = z.object({ maxCount: defaultOnError( z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for open files context. */ export const zNesOpenFilesCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for diagnostics context. */ export const zNesDiagnosticsCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Context capabilities the agent wants attached to each suggestion request. */ export const zNesContextCapabilities = z.object({ recentFiles: defaultOnError( zNesRecentFilesCapabilities.nullish(), () => undefined, ), relatedSnippets: defaultOnError( zNesRelatedSnippetsCapabilities.nullish(), () => undefined, ), editHistory: defaultOnError( zNesEditHistoryCapabilities.nullish(), () => undefined, ), userActions: defaultOnError( zNesUserActionsCapabilities.nullish(), () => undefined, ), openFiles: defaultOnError( zNesOpenFilesCapabilities.nullish(), () => undefined, ), diagnostics: defaultOnError( zNesDiagnosticsCapabilities.nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * NES capabilities advertised by the agent during initialization. */ export const zNesCapabilities = z.object({ events: defaultOnError(zNesEventCapabilities.nullish(), () => undefined), context: defaultOnError(zNesContextCapabilities.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * The encoding used for character offsets in positions. * * Follows the same conventions as LSP 3.17. The default is UTF-16. */ export const zPositionEncodingKind = z.union([ z.literal("utf-16"), z.literal("utf-32"), z.literal("utf-8"), ]); /** * Capabilities supported by the agent. * * Advertised during initialization to inform the client about * available features and content types. * * See protocol docs: [Agent Capabilities](https://agentclientprotocol.com/protocol/initialization#agent-capabilities) */ export const zAgentCapabilities = z.object({ loadSession: defaultOnError( z.boolean().optional().default(false), () => false as const, ), promptCapabilities: defaultOnError( zPromptCapabilities.optional().default({ image: false, audio: false, embeddedContext: false, }), () => ({ image: false, audio: false, embeddedContext: false, }), ), mcpCapabilities: defaultOnError( zMcpCapabilities.optional().default({ http: false, sse: false, acp: false, }), () => ({ http: false, sse: false, acp: false, }), ), sessionCapabilities: defaultOnError( zSessionCapabilities.optional().default({}), () => ({}), ), auth: defaultOnError( zAgentAuthCapabilities.optional().default({}), () => ({}), ), providers: defaultOnError(zProvidersCapabilities.nullish(), () => undefined), nes: defaultOnError(zNesCapabilities.nullish(), () => undefined), positionEncoding: defaultOnError( zPositionEncodingKind.nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Typed identifier used for auth method values on the wire. */ export const zAuthMethodId = z.string(); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Describes a single environment variable for an [`AuthMethodEnvVar`] authentication method. * * @experimental */ export const zAuthEnvVar = z.object({ name: z.string(), label: defaultOnError(z.string().nullish(), () => undefined), secret: defaultOnError( z.boolean().optional().default(true), () => true as const, ), optional: defaultOnError( z.boolean().optional().default(false), () => false as const, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Environment variable authentication method. * * The user provides credentials that the client passes to the agent as environment variables. * * @experimental */ export const zAuthMethodEnvVar = z.object({ id: zAuthMethodId, name: z.string(), description: defaultOnError(z.string().nullish(), () => undefined), vars: requiredDefaultOnError(vecSkipError(zAuthEnvVar), () => []), link: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Terminal-based authentication method. * * The client runs an interactive terminal for the user to authenticate via a TUI. * * @experimental */ export const zAuthMethodTerminal = z.object({ id: zAuthMethodId, name: z.string(), description: defaultOnError(z.string().nullish(), () => undefined), args: defaultOnError(vecSkipError(z.string()).optional(), () => []), env: defaultOnError( z.record(z.string(), z.string()).optional(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Agent handles authentication itself. * * This is the default authentication method type. */ export const zAuthMethodAgent = z.object({ id: zAuthMethodId, name: z.string(), description: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Describes an available authentication method. * * The `type` field acts as the discriminator in the serialized JSON form. * When no `type` is present, the method is treated as `agent`. */ export const zAuthMethod = z.union([ zAuthMethodEnvVar.and( z.object({ type: z.literal("env_var"), }), ), zAuthMethodTerminal.and( z.object({ type: z.literal("terminal"), }), ), zAuthMethodAgent, ]); /** * Metadata about the implementation of the client or agent. * Describes the name and version of an ACP implementation, with an optional * title for UI representation. */ export const zImplementation = z.object({ name: z.string(), title: defaultOnError(z.string().nullish(), () => undefined), version: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response to the `initialize` method. * * Contains the negotiated protocol version and agent capabilities. * * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization) */ export const zInitializeResponse = z.object({ protocolVersion: zProtocolVersion, agentCapabilities: defaultOnError( zAgentCapabilities.optional().default({ loadSession: false, promptCapabilities: { image: false, audio: false, embeddedContext: false, }, mcpCapabilities: { http: false, sse: false, acp: false, }, sessionCapabilities: {}, auth: {}, }), () => ({ loadSession: false, promptCapabilities: { image: false, audio: false, embeddedContext: false, }, mcpCapabilities: { http: false, sse: false, acp: false, }, sessionCapabilities: {}, auth: {}, }), ), authMethods: defaultOnError( vecSkipError(zAuthMethod).optional().default([]), () => [], ), agentInfo: defaultOnError(zImplementation.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response to the `authenticate` method. */ export const zAuthenticateResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Unique identifier for a configurable LLM provider. * * @experimental */ export const zProviderId = z.string(); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Well-known API protocol identifiers for LLM providers. * * Agents and clients MUST handle unknown protocol identifiers gracefully. * * Protocol names beginning with `_` are free for custom use, like other ACP extension methods. * Protocol names that do not begin with `_` are reserved for the ACP spec. * * @experimental */ export const zLlmProtocol = z.union([ z.literal("anthropic"), z.literal("openai"), z.literal("azure"), z.literal("vertex"), z.literal("bedrock"), z.string(), ]); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Current effective non-secret routing configuration for a provider. * * @experimental */ export const zProviderCurrentConfig = z.object({ apiType: zLlmProtocol, baseUrl: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Information about a configurable LLM provider. * * @experimental */ export const zProviderInfo = z.object({ providerId: zProviderId, supported: requiredDefaultOnError(vecSkipError(zLlmProtocol), () => []), required: z.boolean(), current: zProviderCurrentConfig.nullish(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Response to `providers/list`. * * @experimental */ export const zListProvidersResponse = z.object({ providers: z.array(zProviderInfo), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Response to `providers/set`. * * @experimental */ export const zSetProviderResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Response to `providers/disable`. * * @experimental */ export const zDisableProviderResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response to the `logout` method. */ export const zLogoutResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Unique identifier for a Session Mode. */ export const zSessionModeId = z.string(); /** * A mode the agent can operate in. * * See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes) */ export const zSessionMode = z.object({ id: zSessionModeId, name: z.string(), description: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * The set of modes and the one currently active. */ export const zSessionModeState = z.object({ currentModeId: zSessionModeId, availableModes: requiredDefaultOnError(vecSkipError(zSessionMode), () => []), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Unique identifier for a session configuration option. */ export const zSessionConfigId = z.string(); /** * Semantic category for a session configuration option. * * This is intended to help Clients distinguish broadly common selectors (e.g. model selector vs * session mode selector vs thought/reasoning level) for UX purposes (keyboard shortcuts, icons, * placement). It MUST NOT be required for correctness. Clients MUST handle missing or unknown * categories gracefully. * * Category names beginning with `_` are free for custom use, like other ACP extension methods. * Category names that do not begin with `_` are reserved for the ACP spec. */ export const zSessionConfigOptionCategory = z.union([ z.literal("mode"), z.literal("model"), z.literal("model_config"), z.literal("thought_level"), z.string(), ]); /** * Unique identifier for a session configuration option value. */ export const zSessionConfigValueId = z.string(); /** * A possible value for a session configuration option. */ export const zSessionConfigSelectOption = z.object({ value: zSessionConfigValueId, name: z.string(), description: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Unique identifier for a session configuration option value group. */ export const zSessionConfigGroupId = z.string(); /** * A group of possible values for a session configuration option. */ export const zSessionConfigSelectGroup = z.object({ group: zSessionConfigGroupId, name: z.string(), options: requiredDefaultOnError( vecSkipError(zSessionConfigSelectOption), () => [], ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Possible values for a session configuration option. */ export const zSessionConfigSelectOptions = z.union([ z.array(zSessionConfigSelectOption), z.array(zSessionConfigSelectGroup), ]); /** * A single-value selector (dropdown) session configuration option payload. */ export const zSessionConfigSelect = z.object({ currentValue: zSessionConfigValueId, options: zSessionConfigSelectOptions, }); /** * A boolean on/off toggle session configuration option payload. */ export const zSessionConfigBoolean = z.object({ currentValue: z.boolean(), }); /** * A session configuration option selector and its current state. */ export const zSessionConfigOption = z.intersection( z.union([ zSessionConfigSelect.and( z.object({ type: z.literal("select"), }), ), zSessionConfigBoolean.and( z.object({ type: z.literal("boolean"), }), ), ]), z.object({ id: zSessionConfigId, name: z.string(), description: defaultOnError(z.string().nullish(), () => undefined), category: defaultOnError( zSessionConfigOptionCategory.nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }), ); /** * Response from creating a new session. * * See protocol docs: [Creating a Session](https://agentclientprotocol.com/protocol/session-setup#creating-a-session) */ export const zNewSessionResponse = z.object({ sessionId: zSessionId, modes: defaultOnError(zSessionModeState.nullish(), () => undefined), configOptions: defaultOnError( vecSkipError(zSessionConfigOption).nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response from loading an existing session. */ export const zLoadSessionResponse = z.object({ modes: defaultOnError(zSessionModeState.nullish(), () => undefined), configOptions: defaultOnError( vecSkipError(zSessionConfigOption).nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Information about a session returned by session/list */ export const zSessionInfo = z.object({ sessionId: zSessionId, cwd: z.string(), additionalDirectories: defaultOnError( vecSkipError(z.string()).optional(), () => [], ), title: defaultOnError(z.string().nullish(), () => undefined), updatedAt: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response from listing sessions. */ export const zListSessionsResponse = z.object({ sessions: requiredDefaultOnError(vecSkipError(zSessionInfo), () => []), nextCursor: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response from deleting a session. */ export const zDeleteSessionResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Response from forking an existing session. * * @experimental */ export const zForkSessionResponse = z.object({ sessionId: zSessionId, modes: defaultOnError(zSessionModeState.nullish(), () => undefined), configOptions: defaultOnError( vecSkipError(zSessionConfigOption).nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response from resuming an existing session. */ export const zResumeSessionResponse = z.object({ modes: defaultOnError(zSessionModeState.nullish(), () => undefined), configOptions: defaultOnError( vecSkipError(zSessionConfigOption).nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response from closing a session. */ export const zCloseSessionResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response to `session/set_mode` method. */ export const zSetSessionModeResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response to `session/set_config_option` method. */ export const zSetSessionConfigOptionResponse = z.object({ configOptions: requiredDefaultOnError( vecSkipError(zSessionConfigOption), () => [], ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Reasons why an agent stops processing a prompt turn. * * See protocol docs: [Stop Reasons](https://agentclientprotocol.com/protocol/prompt-turn#stop-reasons) */ export const zStopReason = z.union([ z.literal("end_turn"), z.literal("max_tokens"), z.literal("max_turn_requests"), z.literal("refusal"), z.literal("cancelled"), ]); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Token usage information for a prompt turn. * * @experimental */ export const zUsage = z.object({ totalTokens: z.number(), inputTokens: z.number(), outputTokens: z.number(), thoughtTokens: defaultOnError(z.number().nullish(), () => undefined), cachedReadTokens: defaultOnError(z.number().nullish(), () => undefined), cachedWriteTokens: defaultOnError(z.number().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response from processing a user prompt. * * See protocol docs: [Check for Completion](https://agentclientprotocol.com/protocol/prompt-turn#4-check-for-completion) */ export const zPromptResponse = z.object({ stopReason: zStopReason, usage: defaultOnError(zUsage.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response to `nes/start`. */ export const zStartNesResponse = z.object({ sessionId: zSessionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Unique identifier for a next edit suggestion. */ export const zNesSuggestionId = z.string(); /** * A zero-based position in a text document. * * The meaning of `character` depends on the negotiated position encoding. */ export const zPosition = z.object({ line: z.int().gte(0).max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }), character: z.int().gte(0).max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A range in a text document, expressed as start and end positions. */ export const zRange = z.object({ start: zPosition, end: zPosition, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A text edit within a suggestion. */ export const zNesTextEdit = z.object({ range: zRange, newText: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A text edit suggestion. */ export const zNesEditSuggestion = z.object({ id: zNesSuggestionId, uri: z.string(), edits: z.array(zNesTextEdit), cursorPosition: defaultOnError(zPosition.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A jump-to-location suggestion. */ export const zNesJumpSuggestion = z.object({ id: zNesSuggestionId, uri: z.string(), position: zPosition, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A rename symbol suggestion. */ export const zNesRenameSuggestion = z.object({ id: zNesSuggestionId, uri: z.string(), position: zPosition, newName: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A search-and-replace suggestion. */ export const zNesSearchAndReplaceSuggestion = z.object({ id: zNesSuggestionId, uri: z.string(), search: z.string(), replace: z.string(), isRegex: z.boolean().nullish(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A suggestion returned by the agent. */ export const zNesSuggestion = z.union([ zNesEditSuggestion.and( z.object({ kind: z.literal("edit"), }), ), zNesJumpSuggestion.and( z.object({ kind: z.literal("jump"), }), ), zNesRenameSuggestion.and( z.object({ kind: z.literal("rename"), }), ), zNesSearchAndReplaceSuggestion.and( z.object({ kind: z.literal("searchAndReplace"), }), ), ]); /** * Response to `nes/suggest`. */ export const zSuggestNesResponse = z.object({ suggestions: z.array(zNesSuggestion), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response from closing an NES session. */ export const zCloseNesResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Allows for sending an arbitrary response to an [`ExtRequest`] that is not part of the ACP spec. * Extension methods provide a way to add custom functionality while maintaining * protocol compatibility. * * See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility) */ export const zExtResponse = z.unknown(); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Response to `mcp/message`. * * This is the inner MCP response result payload. Any JSON value is valid. * * @experimental */ export const zMessageMcpResponse = z.unknown(); /** * Predefined error codes for common JSON-RPC and ACP-specific errors. * * These codes follow the JSON-RPC 2.0 specification for standard errors * and use the reserved range (-32000 to -32099) for protocol-specific errors. */ export const zErrorCode = z.union([ z.literal(-32700), z.literal(-32600), z.literal(-32601), z.literal(-32602), z.literal(-32603), z.literal(-32800), z.literal(-32000), z.literal(-32002), z .int() .min(-2147483648, { error: "Invalid value: Expected int32 to be >= -2147483648", }) .max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647", }), ]); /** * JSON-RPC error object. * * Represents an error that occurred during method execution, following the * JSON-RPC 2.0 error object specification with optional additional data. * * See protocol docs: [JSON-RPC Error Object](https://www.jsonrpc.org/specification#error_object) */ export const zError = z.object({ code: zErrorCode, message: z.string(), data: defaultOnError(z.unknown().optional(), () => undefined), }); /** * A JSON-RPC response object. */ export const zAgentResponse = z.union([ z.object({ id: zRequestId, result: z.union([ zInitializeResponse, zAuthenticateResponse, zListProvidersResponse, zSetProviderResponse, zDisableProviderResponse, zLogoutResponse, zNewSessionResponse, zLoadSessionResponse, zListSessionsResponse, zDeleteSessionResponse, zForkSessionResponse, zResumeSessionResponse, zCloseSessionResponse, zSetSessionModeResponse, zSetSessionConfigOptionResponse, zPromptResponse, zStartNesResponse, zSuggestNesResponse, zCloseNesResponse, zExtResponse, zMessageMcpResponse, ]), }), z.object({ id: zRequestId, error: zError, }), ]); /** * Unique identifier for a message within a session. */ export const zMessageId = z.string(); /** * A streamed item of content */ export const zContentChunk = z.object({ content: zContentBlock, messageId: defaultOnError(zMessageId.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Represents a tool call that the language model has requested. * * Tool calls are actions that the agent executes on behalf of the language model, * such as reading files, executing code, or fetching data from external sources. * * See protocol docs: [Tool Calls](https://agentclientprotocol.com/protocol/tool-calls) */ export const zToolCall = z.object({ toolCallId: zToolCallId, title: z.string(), name: defaultOnError(z.string().nullish(), () => undefined), kind: defaultOnError(zToolKind.optional(), () => undefined), status: defaultOnError(zToolCallStatus.optional(), () => undefined), content: defaultOnError(vecSkipError(zToolCallContent).optional(), () => []), locations: defaultOnError( vecSkipError(zToolCallLocation).optional(), () => [], ), rawInput: defaultOnError(z.unknown().optional(), () => undefined), rawOutput: defaultOnError(z.unknown().optional(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Priority levels for plan entries. * * Used to indicate the relative importance or urgency of different * tasks in the execution plan. * See protocol docs: [Plan Entries](https://agentclientprotocol.com/protocol/agent-plan#plan-entries) */ export const zPlanEntryPriority = z.union([ z.literal("high"), z.literal("medium"), z.literal("low"), ]); /** * Status of a plan entry in the execution flow. * * Tracks the lifecycle of each task from planning through completion. * See protocol docs: [Plan Entries](https://agentclientprotocol.com/protocol/agent-plan#plan-entries) */ export const zPlanEntryStatus = z.union([ z.literal("pending"), z.literal("in_progress"), z.literal("completed"), ]); /** * A single entry in the execution plan. * * Represents a task or goal that the assistant intends to accomplish * as part of fulfilling the user's request. * See protocol docs: [Plan Entries](https://agentclientprotocol.com/protocol/agent-plan#plan-entries) */ export const zPlanEntry = z.object({ content: z.string(), priority: zPlanEntryPriority, status: zPlanEntryStatus, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * An execution plan for accomplishing complex tasks. * * Plans consist of multiple entries representing individual tasks or goals. * Agents report plans to clients to provide visibility into their execution strategy. * Plans can evolve during execution as the agent discovers new requirements or completes tasks. * * See protocol docs: [Agent Plan](https://agentclientprotocol.com/protocol/agent-plan) */ export const zPlan = z.object({ entries: requiredDefaultOnError(vecSkipError(zPlanEntry), () => []), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Unique identifier for a plan within a session. * * @experimental */ export const zPlanId = z.string(); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * A plan represented as structured entries. * * @experimental */ export const zPlanItems = z.object({ planId: zPlanId, entries: requiredDefaultOnError(vecSkipError(zPlanEntry), () => []), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * A plan represented by a file URI. * * @experimental */ export const zPlanFile = z.object({ planId: zPlanId, uri: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * A plan represented as raw markdown content. * * @experimental */ export const zPlanMarkdown = z.object({ planId: zPlanId, content: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Updated content for a plan. * * @experimental */ export const zPlanUpdateContent = z.union([ zPlanItems.and( z.object({ type: z.literal("items"), }), ), zPlanFile.and( z.object({ type: z.literal("file"), }), ), zPlanMarkdown.and( z.object({ type: z.literal("markdown"), }), ), ]); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * A content update for a plan identified by ID. * * @experimental */ export const zPlanUpdate = z.object({ plan: zPlanUpdateContent, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Removal notice for a plan identified by ID. * * @experimental */ export const zPlanRemoved = z.object({ planId: zPlanId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * All text that was typed after the command name is provided as input. */ export const zUnstructuredCommandInput = z.object({ hint: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * unstructured * * All text that was typed after the command name is provided as input. */ export const zAvailableCommandInput = zUnstructuredCommandInput; /** * Information about a command. */ export const zAvailableCommand = z.object({ name: z.string(), description: z.string(), input: defaultOnError(zAvailableCommandInput.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Available commands are ready or have changed */ export const zAvailableCommandsUpdate = z.object({ availableCommands: requiredDefaultOnError( vecSkipError(zAvailableCommand), () => [], ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * The current mode of the session has changed * * See protocol docs: [Session Modes](https://agentclientprotocol.com/protocol/session-modes) */ export const zCurrentModeUpdate = z.object({ currentModeId: zSessionModeId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Session configuration options have been updated. */ export const zConfigOptionUpdate = z.object({ configOptions: requiredDefaultOnError( vecSkipError(zSessionConfigOption), () => [], ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Update to session metadata. All fields are optional to support partial updates. * * Agents send this notification to update session information like title or custom metadata. * This allows clients to display dynamic session names and track session state changes. */ export const zSessionInfoUpdate = z.object({ title: defaultOnError(z.string().nullish(), () => undefined), updatedAt: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Cost information for a session. */ export const zCost = z.object({ amount: z.number(), currency: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Context window and cost update for a session. */ export const zUsageUpdate = z.object({ used: z.number(), size: z.number(), cost: defaultOnError(zCost.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Different types of updates that can be sent during session processing. * * These updates provide real-time feedback about the agent's progress. * * See protocol docs: [Agent Reports Output](https://agentclientprotocol.com/protocol/prompt-turn#3-agent-reports-output) */ export const zSessionUpdate = z.union([ zContentChunk.and( z.object({ sessionUpdate: z.literal("user_message_chunk"), }), ), zContentChunk.and( z.object({ sessionUpdate: z.literal("agent_message_chunk"), }), ), zContentChunk.and( z.object({ sessionUpdate: z.literal("agent_thought_chunk"), }), ), zToolCall.and( z.object({ sessionUpdate: z.literal("tool_call"), }), ), zToolCallUpdate.and( z.object({ sessionUpdate: z.literal("tool_call_update"), }), ), zPlan.and( z.object({ sessionUpdate: z.literal("plan"), }), ), zPlanUpdate.and( z.object({ sessionUpdate: z.literal("plan_update"), }), ), zPlanRemoved.and( z.object({ sessionUpdate: z.literal("plan_removed"), }), ), zAvailableCommandsUpdate.and( z.object({ sessionUpdate: z.literal("available_commands_update"), }), ), zCurrentModeUpdate.and( z.object({ sessionUpdate: z.literal("current_mode_update"), }), ), zConfigOptionUpdate.and( z.object({ sessionUpdate: z.literal("config_option_update"), }), ), zSessionInfoUpdate.and( z.object({ sessionUpdate: z.literal("session_info_update"), }), ), zUsageUpdate.and( z.object({ sessionUpdate: z.literal("usage_update"), }), ), ]); /** * Notification containing a session update from the agent. * * Used to stream real-time progress and results during prompt processing. * * See protocol docs: [Agent Reports Output](https://agentclientprotocol.com/protocol/prompt-turn#3-agent-reports-output) */ export const zSessionNotification = z.object({ sessionId: zSessionId, update: zSessionUpdate, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Notification sent by the agent when a URL-based elicitation is complete. * * @experimental */ export const zCompleteElicitationNotification = z.object({ elicitationId: zElicitationId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Notification parameters for `mcp/message`. * * This is used when the wrapped MCP message is a notification and the outer JSON-RPC * envelope has no `id`. * * @experimental */ export const zMessageMcpNotification = z.object({ connectionId: zMcpConnectionId, method: z.string(), params: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Allows the Agent to send an arbitrary notification that is not part of the ACP spec. * Extension notifications provide a way to send one-way messages for custom functionality * while maintaining protocol compatibility. * * See protocol docs: [Extensibility](https://agentclientprotocol.com/protocol/extensibility) */ export const zExtNotification = z.unknown(); /** * A JSON-RPC notification object. */ export const zAgentNotification = z.object({ method: z.string(), params: z .union([ zSessionNotification, zCompleteElicitationNotification, zMessageMcpNotification, zExtNotification, ]) .nullish(), }); /** * File system capabilities that a client may support. * * See protocol docs: [FileSystem](https://agentclientprotocol.com/protocol/initialization#filesystem) */ export const zFileSystemCapabilities = z.object({ readTextFile: defaultOnError( z.boolean().optional().default(false), () => false as const, ), writeTextFile: defaultOnError( z.boolean().optional().default(false), () => false as const, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities for boolean session configuration options. * * Supplying `{}` means the client supports boolean session configuration options. */ export const zBooleanConfigOptionCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Session configuration option capabilities supported by the client. */ export const zSessionConfigOptionsCapabilities = z.object({ boolean: defaultOnError( zBooleanConfigOptionCapabilities.nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Session-related capabilities supported by the client. */ export const zClientSessionCapabilities = z.object({ configOptions: defaultOnError( zSessionConfigOptionsCapabilities.nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Capabilities for receiving `plan_update` and `plan_removed` session updates. * * @experimental */ export const zPlanCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Authentication capabilities supported by the client. * * Advertised during initialization to inform the agent which authentication * method types the client can handle. This governs opt-in types that require * additional client-side support. * * @experimental */ export const zAuthCapabilities = z.object({ terminal: defaultOnError( z.boolean().optional().default(false), () => false as const, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Form-based elicitation capabilities. * * Supplying `{}` means the client supports form-based elicitation. * * @experimental */ export const zElicitationFormCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * URL-based elicitation capabilities. * * Supplying `{}` means the client supports URL-based elicitation. * * @experimental */ export const zElicitationUrlCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Elicitation capabilities supported by the client. * * @experimental */ export const zElicitationCapabilities = z.object({ form: defaultOnError(zElicitationFormCapabilities.nullish(), () => undefined), url: defaultOnError(zElicitationUrlCapabilities.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Marker for jump suggestion support. */ export const zNesJumpCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Marker for rename suggestion support. */ export const zNesRenameCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Marker for search and replace suggestion support. */ export const zNesSearchAndReplaceCapabilities = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * NES capabilities advertised by the client during initialization. */ export const zClientNesCapabilities = z.object({ jump: defaultOnError(zNesJumpCapabilities.nullish(), () => undefined), rename: defaultOnError(zNesRenameCapabilities.nullish(), () => undefined), searchAndReplace: defaultOnError( zNesSearchAndReplaceCapabilities.nullish(), () => undefined, ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Capabilities supported by the client. * * Advertised during initialization to inform the agent about * available features and methods. * * See protocol docs: [Client Capabilities](https://agentclientprotocol.com/protocol/initialization#client-capabilities) */ export const zClientCapabilities = z.object({ fs: defaultOnError( zFileSystemCapabilities .optional() .default({ readTextFile: false, writeTextFile: false }), () => ({ readTextFile: false, writeTextFile: false }), ), terminal: defaultOnError( z.boolean().optional().default(false), () => false as const, ), session: defaultOnError( zClientSessionCapabilities.nullish(), () => undefined, ), plan: defaultOnError(zPlanCapabilities.nullish(), () => undefined), auth: defaultOnError( zAuthCapabilities.optional().default({ terminal: false }), () => ({ terminal: false }), ), elicitation: defaultOnError( zElicitationCapabilities.nullish(), () => undefined, ), nes: defaultOnError(zClientNesCapabilities.nullish(), () => undefined), positionEncodings: defaultOnError( vecSkipError(zPositionEncodingKind).optional(), () => [], ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for the initialize method. * * Sent by the client to establish connection and negotiate capabilities. * * See protocol docs: [Initialization](https://agentclientprotocol.com/protocol/initialization) */ export const zInitializeRequest = z.object({ protocolVersion: zProtocolVersion, clientCapabilities: defaultOnError( zClientCapabilities.optional().default({ fs: { readTextFile: false, writeTextFile: false }, terminal: false, auth: { terminal: false }, }), () => ({ fs: { readTextFile: false, writeTextFile: false }, terminal: false, auth: { terminal: false }, }), ), clientInfo: defaultOnError(zImplementation.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for the authenticate method. * * Specifies which authentication method to use. */ export const zAuthenticateRequest = z.object({ methodId: zAuthMethodId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request parameters for `providers/list`. * * @experimental */ export const zListProvidersRequest = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request parameters for `providers/set`. * * Replaces the full configuration for one provider ID. * * @experimental */ export const zSetProviderRequest = z.object({ providerId: zProviderId, apiType: zLlmProtocol, baseUrl: z.string(), headers: z.record(z.string(), z.string()).optional(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request parameters for `providers/disable`. * * @experimental */ export const zDisableProviderRequest = z.object({ providerId: zProviderId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for the logout method. * * Terminates the current authenticated session. */ export const zLogoutRequest = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * An HTTP header to set when making requests to the MCP server. */ export const zHttpHeader = z.object({ name: z.string(), value: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * HTTP transport configuration for MCP. */ export const zMcpServerHttp = z.object({ name: z.string(), url: z.string(), headers: z.array(zHttpHeader), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * SSE transport configuration for MCP. */ export const zMcpServerSse = z.object({ name: z.string(), url: z.string(), headers: z.array(zHttpHeader), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * ACP transport configuration for MCP. * * The MCP server is provided by an ACP component and communicates over the ACP channel * using `mcp/connect`, `mcp/message`, and `mcp/disconnect`. * * @experimental */ export const zMcpServerAcp = z.object({ name: z.string(), serverId: zMcpServerAcpId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Stdio transport configuration for MCP. */ export const zMcpServerStdio = z.object({ name: z.string(), command: z.string(), args: z.array(z.string()), env: z.array(zEnvVariable), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Configuration for connecting to an MCP (Model Context Protocol) server. * * MCP servers provide tools and context that the agent can use when * processing prompts. * * See protocol docs: [MCP Servers](https://agentclientprotocol.com/protocol/session-setup#mcp-servers) */ export const zMcpServer = z.union([ zMcpServerHttp.and( z.object({ type: z.literal("http"), }), ), zMcpServerSse.and( z.object({ type: z.literal("sse"), }), ), zMcpServerAcp.and( z.object({ type: z.literal("acp"), }), ), zMcpServerStdio, ]); /** * Request parameters for creating a new session. * * See protocol docs: [Creating a Session](https://agentclientprotocol.com/protocol/session-setup#creating-a-session) */ export const zNewSessionRequest = z.object({ cwd: z.string(), additionalDirectories: defaultOnError( vecSkipError(z.string()).optional(), () => [], ), mcpServers: requiredDefaultOnError(vecSkipError(zMcpServer), () => []), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for loading an existing session. * * Only available if the Agent supports the `loadSession` capability. * * See protocol docs: [Loading Sessions](https://agentclientprotocol.com/protocol/session-setup#loading-sessions) */ export const zLoadSessionRequest = z.object({ mcpServers: requiredDefaultOnError(vecSkipError(zMcpServer), () => []), cwd: z.string(), additionalDirectories: defaultOnError( vecSkipError(z.string()).optional(), () => [], ), sessionId: zSessionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for listing existing sessions. * * Only available if the Agent supports the `sessionCapabilities.list` capability. */ export const zListSessionsRequest = z.object({ cwd: z.string().nullish(), cursor: z.string().nullish(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for deleting an existing session from `session/list`. * * Only available if the Agent supports the `sessionCapabilities.delete` capability. */ export const zDeleteSessionRequest = z.object({ sessionId: zSessionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Request parameters for forking an existing session. * * Creates a new session based on the context of an existing one, allowing * operations like generating summaries without affecting the original session's history. * * Only available if the Agent supports the `session.fork` capability. * * @experimental */ export const zForkSessionRequest = z.object({ sessionId: zSessionId, cwd: z.string(), additionalDirectories: defaultOnError( vecSkipError(z.string()).optional(), () => [], ), mcpServers: defaultOnError(vecSkipError(zMcpServer).optional(), () => []), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for resuming an existing session. * * Resumes an existing session without returning previous messages (unlike `session/load`). * This is useful for agents that can resume sessions but don't implement full session loading. * * Only available if the Agent supports the `sessionCapabilities.resume` capability. */ export const zResumeSessionRequest = z.object({ sessionId: zSessionId, cwd: z.string(), additionalDirectories: defaultOnError( vecSkipError(z.string()).optional(), () => [], ), mcpServers: defaultOnError(vecSkipError(zMcpServer).optional(), () => []), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for closing an active session. * * If supported, the agent **must** cancel any ongoing work related to the session * (treat it as if `session/cancel` was called) and then free up any resources * associated with the session. * * Only available if the Agent supports the `sessionCapabilities.close` capability. */ export const zCloseSessionRequest = z.object({ sessionId: zSessionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for setting a session mode. */ export const zSetSessionModeRequest = z.object({ sessionId: zSessionId, modeId: zSessionModeId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request parameters for setting a session configuration option. */ export const zSetSessionConfigOptionRequest = z.intersection( z.union([ z.object({ value: z.boolean(), type: z.literal("boolean"), }), z.object({ value: zSessionConfigValueId, }), ]), z.object({ sessionId: zSessionId, configId: zSessionConfigId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }), ); /** * Request parameters for sending a user prompt to the agent. * * Contains the user's message and any additional context. * * See protocol docs: [User Message](https://agentclientprotocol.com/protocol/prompt-turn#1-user-message) */ export const zPromptRequest = z.object({ sessionId: zSessionId, prompt: z.array(zContentBlock), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A workspace folder. */ export const zWorkspaceFolder = z.object({ uri: z.string(), name: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Repository metadata for an NES session. */ export const zNesRepository = z.object({ name: z.string(), owner: z.string(), remoteUrl: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request to start an NES session. */ export const zStartNesRequest = z.object({ workspaceUri: defaultOnError(z.string().nullish(), () => undefined), workspaceFolders: z.array(zWorkspaceFolder).nullish(), repository: defaultOnError(zNesRepository.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * What triggered the suggestion request. */ export const zNesTriggerKind = z.union([ z.literal("automatic"), z.literal("diagnostic"), z.literal("manual"), ]); /** * A recently accessed file. */ export const zNesRecentFile = z.object({ uri: z.string(), languageId: z.string(), text: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A code excerpt from a file. */ export const zNesExcerpt = z.object({ startLine: z.int().gte(0).max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }), endLine: z.int().gte(0).max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }), text: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A related code snippet from a file. */ export const zNesRelatedSnippet = z.object({ uri: z.string(), excerpts: z.array(zNesExcerpt), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * An entry in the edit history. */ export const zNesEditHistoryEntry = z.object({ uri: z.string(), diff: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A user action (typing, cursor movement, etc.). */ export const zNesUserAction = z.object({ action: z.string(), uri: z.string(), position: zPosition, timestampMs: z.number(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * An open file in the editor. */ export const zNesOpenFile = z.object({ uri: z.string(), languageId: z.string(), visibleRange: defaultOnError(zRange.nullish(), () => undefined), lastFocusedMs: defaultOnError(z.number().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Severity of a diagnostic. */ export const zNesDiagnosticSeverity = z.union([ z.literal("error"), z.literal("warning"), z.literal("information"), z.literal("hint"), ]); /** * A diagnostic (error, warning, etc.). */ export const zNesDiagnostic = z.object({ uri: z.string(), range: zRange, severity: zNesDiagnosticSeverity, message: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Context attached to a suggestion request. */ export const zNesSuggestContext = z.object({ recentFiles: z.array(zNesRecentFile).nullish(), relatedSnippets: z.array(zNesRelatedSnippet).nullish(), editHistory: z.array(zNesEditHistoryEntry).nullish(), userActions: z.array(zNesUserAction).nullish(), openFiles: z.array(zNesOpenFile).nullish(), diagnostics: z.array(zNesDiagnostic).nullish(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request for a code suggestion. */ export const zSuggestNesRequest = z.object({ sessionId: zSessionId, uri: z.string(), version: z.number(), position: zPosition, selection: zRange.nullish(), triggerKind: zNesTriggerKind, context: zNesSuggestContext.nullish(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Request to close an NES session. * * The agent **must** cancel any ongoing work related to the NES session * and then free up any resources associated with the session. */ export const zCloseNesRequest = z.object({ sessionId: zSessionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A JSON-RPC request object. */ export const zClientRequest = z.object({ id: zRequestId, method: z.string(), params: z .union([ zInitializeRequest, zAuthenticateRequest, zListProvidersRequest, zSetProviderRequest, zDisableProviderRequest, zLogoutRequest, zNewSessionRequest, zLoadSessionRequest, zListSessionsRequest, zDeleteSessionRequest, zForkSessionRequest, zResumeSessionRequest, zCloseSessionRequest, zSetSessionModeRequest, zSetSessionConfigOptionRequest, zPromptRequest, zStartNesRequest, zSuggestNesRequest, zCloseNesRequest, zMessageMcpRequest, zExtRequest, ]) .nullish(), }); /** * Response to `fs/write_text_file` */ export const zWriteTextFileResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response containing the contents of a text file. */ export const zReadTextFileResponse = z.object({ content: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * The user selected one of the provided options. */ export const zSelectedPermissionOutcome = z.object({ optionId: zPermissionOptionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * The outcome of a permission request. */ export const zRequestPermissionOutcome = z.union([ z.object({ outcome: z.literal("cancelled"), }), zSelectedPermissionOutcome.and( z.object({ outcome: z.literal("selected"), }), ), ]); /** * Response to a permission request. */ export const zRequestPermissionResponse = z.object({ outcome: zRequestPermissionOutcome, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response containing the ID of the created terminal. */ export const zCreateTerminalResponse = z.object({ terminalId: zTerminalId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Exit status of a terminal command. */ export const zTerminalExitStatus = z.object({ exitCode: defaultOnError( z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), () => undefined, ), signal: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response containing the terminal output and exit status. */ export const zTerminalOutputResponse = z.object({ output: z.string(), truncated: z.boolean(), exitStatus: defaultOnError(zTerminalExitStatus.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response to terminal/release method */ export const zReleaseTerminalResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response containing the exit status of a terminal command. */ export const zWaitForTerminalExitResponse = z.object({ exitCode: defaultOnError( z .int() .gte(0) .max(4294967295, { error: "Invalid value: Expected uint32 to be <= 4294967295", }) .nullish(), () => undefined, ), signal: defaultOnError(z.string().nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Response to `terminal/kill` method */ export const zKillTerminalResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Allowed wire representations for [`ElicitationContentValue`]. */ export const zElicitationContentValue = z.union([ z.string(), z.number(), z.number(), z.boolean(), z.array(z.string()), ]); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * The user accepted the elicitation and provided content. * * @experimental */ export const zElicitationAcceptAction = z.object({ content: z.record(z.string(), zElicitationContentValue).nullish(), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Response from the client to an elicitation request. * * @experimental * * Custom variants (unknown `action` values) keep their extra * properties exactly as received; unlike known variants, those keys * bypass lenient-field salvage and arrive unvalidated. */ export const zCreateElicitationResponse = preserveCustomPayload( z.intersection( z.union([ zElicitationAcceptAction.and( z.object({ action: z.literal("accept"), }), ), z.object({ action: z.literal("decline"), }), z.object({ action: z.literal("cancel"), }), excludeKnownTags( z.object({ action: z.string(), }), "action", ["accept", "cancel", "decline"], ), ]), z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }), ), "action", ["accept", "cancel", "decline"], ); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Response to `mcp/connect`. * * @experimental */ export const zConnectMcpResponse = z.object({ connectionId: zMcpConnectionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * **UNSTABLE** * * This capability is not part of the spec yet, and may be removed or changed at any point. * * Response to `mcp/disconnect`. * * @experimental */ export const zDisconnectMcpResponse = z.object({ _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A JSON-RPC response object. */ export const zClientResponse = z.union([ z.object({ id: zRequestId, result: z.union([ zWriteTextFileResponse, zReadTextFileResponse, zRequestPermissionResponse, zCreateTerminalResponse, zTerminalOutputResponse, zReleaseTerminalResponse, zWaitForTerminalExitResponse, zKillTerminalResponse, zCreateElicitationResponse, zConnectMcpResponse, zDisconnectMcpResponse, zMessageMcpResponse, zExtResponse, ]), }), z.object({ id: zRequestId, error: zError, }), ]); /** * Notification to cancel ongoing operations for a session. * * See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/prompt-turn#cancellation) */ export const zCancelNotification = z.object({ sessionId: zSessionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Notification sent when a file is opened in the editor. */ export const zDidOpenDocumentNotification = z.object({ sessionId: zSessionId, uri: z.string(), languageId: z.string(), version: z.number(), text: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A content change event for a document. * * When `range` is `None`, `text` is the full content of the document. * When `range` is `Some`, `text` replaces the given range. */ export const zTextDocumentContentChangeEvent = z.object({ range: zRange.nullish(), text: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Notification sent when a file is edited. */ export const zDidChangeDocumentNotification = z.object({ sessionId: zSessionId, uri: z.string(), version: z.number(), contentChanges: requiredDefaultOnError( vecSkipError(zTextDocumentContentChangeEvent), () => [], ), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Notification sent when a file is closed. */ export const zDidCloseDocumentNotification = z.object({ sessionId: zSessionId, uri: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Notification sent when a file is saved. */ export const zDidSaveDocumentNotification = z.object({ sessionId: zSessionId, uri: z.string(), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Notification sent when a file becomes the active editor tab. */ export const zDidFocusDocumentNotification = z.object({ sessionId: zSessionId, uri: z.string(), version: z.number(), position: zPosition, visibleRange: zRange, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * Notification sent when a suggestion is accepted. */ export const zAcceptNesNotification = z.object({ sessionId: zSessionId, id: zNesSuggestionId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * The reason a suggestion was rejected. */ export const zNesRejectReason = z.union([ z.literal("rejected"), z.literal("ignored"), z.literal("replaced"), z.literal("cancelled"), ]); /** * Notification sent when a suggestion is rejected. */ export const zRejectNesNotification = z.object({ sessionId: zSessionId, id: zNesSuggestionId, reason: defaultOnError(zNesRejectReason.nullish(), () => undefined), _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), }); /** * A JSON-RPC notification object. */ export const zClientNotification = z.object({ method: z.string(), params: z .union([ zCancelNotification, zDidOpenDocumentNotification, zDidChangeDocumentNotification, zDidCloseDocumentNotification, zDidSaveDocumentNotification, zDidFocusDocumentNotification, zAcceptNesNotification, zRejectNesNotification, zMessageMcpNotification, zExtNotification, ]) .nullish(), }); /** * Notification to cancel an ongoing request. * * See protocol docs: [Cancellation](https://agentclientprotocol.com/protocol/cancellation) */ export const zCancelRequestNotification = z.object({ requestId: zRequestId, _meta: defaultOnError( z.record(z.string(), z.unknown()).nullish(), () => undefined, ), });