UNPKG

@a2alite/sdk

Version:

A Modular SDK (Server & Client) for Agent to Agent (A2A) protocol, with easy task lifecycle management

1,189 lines (1,188 loc) 36.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isJSONRPCError = exports.JSONRPCErrorSchema = exports.InvalidAgentResponseErrorSchema = exports.ContentTypeNotSupportedErrorSchema = exports.UnsupportedOperationErrorSchema = exports.PushNotificationNotSupportedErrorSchema = exports.TaskNotCancelableErrorSchema = exports.TaskNotFoundErrorSchema = exports.InternalErrorSchema = exports.InvalidParamsErrorSchema = exports.MethodNotFoundErrorSchema = exports.InvalidRequestErrorSchema = exports.JSONParseErrorSchema = exports.ErrorType = exports.MessageSendParamsSchema = exports.MessageSendConfigurationSchema = exports.TaskQueryParamsSchema = exports.TaskIdParamsSchema = exports.TaskArtifactUpdateEventSchema = exports.TaskStatusUpdateEventSchema = exports.TaskSchema = exports.TaskStatusSchema = exports.TaskPushNotificationConfigSchema = exports.PushNotificationConfigSchema = exports.PushNotificationAuthenticationInfoSchema = exports.SecuritySchemeSchema = exports.OpenIdConnectSecuritySchemeSchema = exports.OAuth2SecuritySchemeSchema = exports.OAuthFlowsSchema = exports.PasswordOAuthFlowSchema = exports.ImplicitOAuthFlowSchema = exports.ClientCredentialsOAuthFlowSchema = exports.AuthorizationCodeOAuthFlowSchema = exports.HTTPAuthSecuritySchemeSchema = exports.APIKeySecuritySchemeSchema = exports.AgentCardSchema = exports.AgentSkillSchema = exports.AgentProviderSchema = exports.AgentCapabilitiesSchema = exports.ArtifactSchema = exports.MessageSchema = exports.PartSchema = exports.DataPartSchema = exports.FilePartSchema = exports.FileWithUriSchema = exports.FileWithBytesSchema = exports.TextPartSchema = exports.PartBaseSchema = exports.MessageRoleEnum = exports.TaskStateEnum = void 0; exports.A2ARequestSchema = exports.A2AErrorSchema = exports.GetTaskPushNotificationConfigResponseSchema = exports.GetTaskPushNotificationConfigSuccessResponseSchema = exports.SetTaskPushNotificationConfigResponseSchema = exports.SetTaskPushNotificationConfigSuccessResponseSchema = exports.CancelTaskResponseSchema = exports.CancelTaskSuccessResponseSchema = exports.GetTaskResponseSchema = exports.GetTaskSuccessResponseSchema = exports.SendStreamingMessageResponseSchema = exports.SendStreamingMessageSuccessResponseSchema = exports.SendMessageResponseSchema = exports.SendMessageSuccessResponseSchema = exports.TaskResubscriptionRequestSchema = exports.GetTaskPushNotificationConfigRequestSchema = exports.SetTaskPushNotificationConfigRequestSchema = exports.CancelTaskRequestSchema = exports.GetTaskRequestSchema = exports.SendStreamingMessageRequestSchema = exports.SendMessageRequestSchema = exports.JSONRPCResponseSchema = exports.JSONRPCResultSchema = exports.JSONRPCRequestSchema = exports.JSONRPCMessageSchema = exports.JSONRPCErrorResponseSchema = void 0; const v4_1 = require("zod/v4"); // --- ENUMS --- /** * Represents the possible states of a Task. */ exports.TaskStateEnum = v4_1.z.enum([ "submitted", "working", "input-required", "completed", "canceled", "failed", "rejected", "auth-required", "unknown", ]); /** * Message sender's role: "agent" or "user". */ exports.MessageRoleEnum = v4_1.z.enum(["agent", "user"]); // --- BASES & COMMONS --- /** * Base properties common to all message parts. */ exports.PartBaseSchema = v4_1.z.object({ /** * Optional metadata associated with the part. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), }); // --- PARTS --- /** * Represents a text segment within parts. */ exports.TextPartSchema = v4_1.z.object({ /** * Part type - text for TextParts */ kind: v4_1.z.literal("text"), /** * Text content */ text: v4_1.z.string(), /** * Optional metadata associated with the part. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), }); /** * Define the variant where 'bytes' is present and 'uri' is absent. */ exports.FileWithBytesSchema = v4_1.z.object({ /** * base64 encoded content of the file */ bytes: v4_1.z.string(), /** * Optional mimeType for the file */ mimeType: v4_1.z.string().optional(), /** * Optional name for the file */ name: v4_1.z.string().optional(), }); /** * Define the variant where 'uri' is present and 'bytes' is absent. */ exports.FileWithUriSchema = v4_1.z.object({ /** * URL for the File content */ uri: v4_1.z.string(), /** * Optional mimeType for the file */ mimeType: v4_1.z.string().optional(), /** * Optional name for the file */ name: v4_1.z.string().optional(), }); /** * Represents a File segment within parts. */ exports.FilePartSchema = v4_1.z.object({ /** * Part type - file for FileParts */ kind: v4_1.z.literal("file"), /** * File content either as url or bytes */ file: v4_1.z.union([exports.FileWithBytesSchema, exports.FileWithUriSchema]), /** * Optional metadata associated with the part. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), }); /** * Represents a structured data segment within a message part. */ exports.DataPartSchema = v4_1.z.object({ /** * Part type - data for DataParts */ kind: v4_1.z.literal("data"), /** * Structured data content */ data: v4_1.z.record(v4_1.z.string(), v4_1.z.any()), /** * Optional metadata associated with the part. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), }); /** * Represents a part of a message, which can be text, a file, or structured data. */ exports.PartSchema = v4_1.z.union([ exports.TextPartSchema, exports.FilePartSchema, exports.DataPartSchema, ]); // --- MESSAGE --- /** * Represents a single message exchanged between user and agent. */ exports.MessageSchema = v4_1.z.object({ /** * Event type */ kind: v4_1.z.literal("message"), /** * Identifier created by the message creator */ messageId: v4_1.z.string(), /** * Message content */ parts: v4_1.z.array(exports.PartSchema), /** * Message sender's role */ role: exports.MessageRoleEnum, /** * The context the message is associated with */ contextId: v4_1.z.string().optional(), /** * Extension metadata. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), /** * List of tasks referenced as context by this message. */ referenceTaskIds: v4_1.z.array(v4_1.z.string()).optional(), /** * Identifier of task the message is related to */ taskId: v4_1.z.string().optional(), }); // --- ARTIFACT --- /** * Represents an artifact generated for a task. */ exports.ArtifactSchema = v4_1.z.object({ /** * Unique identifier for the artifact. */ artifactId: v4_1.z.string(), /** * Optional description for the artifact. */ description: v4_1.z.string().optional(), /** * Extension metadata. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), /** * Optional name for the artifact. */ name: v4_1.z.string().optional(), /** * Artifact parts. */ parts: v4_1.z.array(exports.PartSchema), }); // --- AGENT --- /** * Defines optional capabilities supported by an agent. */ exports.AgentCapabilitiesSchema = v4_1.z.object({ /** * true if the agent can notify updates to client. */ pushNotifications: v4_1.z.boolean().optional(), /** * true if the agent exposes status change history for tasks. */ stateTransitionHistory: v4_1.z.boolean().optional(), /** * true if the agent supports SSE. */ streaming: v4_1.z.boolean().optional(), }); /** * Represents the service provider of an agent. */ exports.AgentProviderSchema = v4_1.z.object({ /** * Agent provider's organization name. */ organization: v4_1.z.string(), /** * Agent provider's URL. */ url: v4_1.z.string(), }); /** * Represents a unit of capability that an agent can perform. */ exports.AgentSkillSchema = v4_1.z.object({ /** * Description of the skill - will be used by the client or a human as a hint to understand what the skill does. */ description: v4_1.z.string(), /** * The set of example scenarios that the skill can perform. */ examples: v4_1.z.array(v4_1.z.string()).optional(), /** * Unique identifier for the agent's skill. */ id: v4_1.z.string(), /** * The set of interaction modes that the skill supports (if different than the default). Supported mime types for input. */ inputModes: v4_1.z.array(v4_1.z.string()).optional(), /** * Human readable name of the skill. */ name: v4_1.z.string(), /** * Supported mime types for output. */ outputModes: v4_1.z.array(v4_1.z.string()).optional(), /** * Set of tags describing classes of capabilities for this specific skill. */ tags: v4_1.z.array(v4_1.z.string()), }); /** * An AgentCard conveys key information: * - Overall details (version, name, description, uses) * - Skills: A set of capabilities the agent can perform * - Default modalities/content types supported by the agent. * - Authentication requirements */ exports.AgentCardSchema = v4_1.z.object({ /** * Optional capabilities supported by the agent. */ capabilities: exports.AgentCapabilitiesSchema.optional(), /** * The set of interaction modes that the agent supports across all skills. This can be overridden per-skill. Supported mime types for input. */ defaultInputModes: v4_1.z.array(v4_1.z.string()), /** * Supported mime types for output. */ defaultOutputModes: v4_1.z.array(v4_1.z.string()), /** * A human-readable description of the agent. Used to assist users and other agents in understanding what the agent can do. */ description: v4_1.z.string(), /** * A URL to documentation for the agent. */ documentationUrl: v4_1.z.string().optional(), /** * Human readable name of the agent. */ name: v4_1.z.string(), /** * The service provider of the agent */ provider: exports.AgentProviderSchema.optional(), /** * Security requirements for contacting the agent. */ security: v4_1.z.array(v4_1.z.object({}).catchall(v4_1.z.array(v4_1.z.string()))).optional(), /** * Security scheme details used for authenticating with this agent. */ securitySchemes: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), // SecurityScheme is a union, see below /** * Skills are a unit of capability that an agent can perform. */ skills: v4_1.z.array(exports.AgentSkillSchema), /** * true if the agent supports providing an extended agent card when the user is authenticated. Defaults to false if not specified. */ supportsAuthenticatedExtendedCard: v4_1.z.boolean().optional(), /** * A URL to the address the agent is hosted at. */ url: v4_1.z.string(), /** * The version of the agent - format is up to the provider. */ version: v4_1.z.string(), }); // --- SECURITY SCHEMES --- /** * Defines an API key security scheme. */ exports.APIKeySecuritySchemeSchema = v4_1.z.object({ /** * A description for the security scheme. */ description: v4_1.z.string().optional(), /** * The location of the API key. */ in: v4_1.z.enum(["cookie", "header", "query"]), /** * The name of the header, query, or cookie parameter to be used. */ name: v4_1.z.string(), /** * The type of the security scheme (apiKey). */ type: v4_1.z.literal("apiKey"), }); /** * Defines an HTTP authentication security scheme. */ exports.HTTPAuthSecuritySchemeSchema = v4_1.z.object({ /** * A hint to the client to identify how the bearer token is formatted. */ bearerFormat: v4_1.z.string().optional(), /** * A description for the security scheme. */ description: v4_1.z.string().optional(), /** * The name of the HTTP Authorization scheme to be used in the Authorization header. */ scheme: v4_1.z.string(), /** * The type of the security scheme (http). */ type: v4_1.z.literal("http"), }); /** * Configuration for OAuth2 authorization code flow. */ exports.AuthorizationCodeOAuthFlowSchema = v4_1.z.object({ /** * The authorization URL to be used for this flow. */ authorizationUrl: v4_1.z.string(), /** * The refresh URL to be used for obtaining refresh tokens. */ refreshUrl: v4_1.z.string().optional(), /** * The available scopes for the OAuth2 security scheme. */ scopes: v4_1.z.record(v4_1.z.string(), v4_1.z.string()), /** * The token URL to be used for this flow. */ tokenUrl: v4_1.z.string(), }); /** * Configuration for OAuth2 client credentials flow. */ exports.ClientCredentialsOAuthFlowSchema = v4_1.z.object({ /** * The refresh URL to be used for obtaining refresh tokens. */ refreshUrl: v4_1.z.string().optional(), /** * The available scopes for the OAuth2 security scheme. */ scopes: v4_1.z.record(v4_1.z.string(), v4_1.z.string()), /** * The token URL to be used for this flow. */ tokenUrl: v4_1.z.string(), }); /** * Configuration for OAuth2 implicit flow. */ exports.ImplicitOAuthFlowSchema = v4_1.z.object({ /** * The authorization URL to be used for this flow. */ authorizationUrl: v4_1.z.string(), /** * The refresh URL to be used for obtaining refresh tokens. */ refreshUrl: v4_1.z.string().optional(), /** * The available scopes for the OAuth2 security scheme. */ scopes: v4_1.z.record(v4_1.z.string(), v4_1.z.string()), }); /** * Configuration for OAuth2 password flow. */ exports.PasswordOAuthFlowSchema = v4_1.z.object({ /** * The refresh URL to be used for obtaining refresh tokens. */ refreshUrl: v4_1.z.string().optional(), /** * The available scopes for the OAuth2 security scheme. */ scopes: v4_1.z.record(v4_1.z.string(), v4_1.z.string()), /** * The token URL to be used for this flow. */ tokenUrl: v4_1.z.string(), }); /** * Lists supported OAuth2 flows for a security scheme. */ exports.OAuthFlowsSchema = v4_1.z.object({ /** * Configuration for OAuth2 authorization code flow. */ authorizationCode: exports.AuthorizationCodeOAuthFlowSchema.optional(), /** * Configuration for OAuth2 client credentials flow. */ clientCredentials: exports.ClientCredentialsOAuthFlowSchema.optional(), /** * Configuration for OAuth2 implicit flow. */ implicit: exports.ImplicitOAuthFlowSchema.optional(), /** * Configuration for OAuth2 password flow. */ password: exports.PasswordOAuthFlowSchema.optional(), }); /** * Defines an OAuth2 security scheme. */ exports.OAuth2SecuritySchemeSchema = v4_1.z.object({ /** * A description for the security scheme. */ description: v4_1.z.string().optional(), /** * Lists supported OAuth2 flows. */ flows: exports.OAuthFlowsSchema, /** * The type of the security scheme (oauth2). */ type: v4_1.z.literal("oauth2"), }); /** * Defines an OpenID Connect security scheme. */ exports.OpenIdConnectSecuritySchemeSchema = v4_1.z.object({ /** * A description for the security scheme. */ description: v4_1.z.string().optional(), /** * OpenId Connect URL to discover OAuth2 endpoints. */ openIdConnectUrl: v4_1.z.string(), /** * The type of the security scheme (openIdConnect). */ type: v4_1.z.literal("openIdConnect"), }); /** * Union type for supported security schemes. */ exports.SecuritySchemeSchema = v4_1.z.union([ exports.APIKeySecuritySchemeSchema, exports.HTTPAuthSecuritySchemeSchema, exports.OAuth2SecuritySchemeSchema, exports.OpenIdConnectSecuritySchemeSchema, ]); // --- PUSH NOTIFICATIONS --- /** * Authentication information for push notifications. */ exports.PushNotificationAuthenticationInfoSchema = v4_1.z.object({ /** * Optional credentials for push notification authentication. */ credentials: v4_1.z.string().optional(), /** * Array of supported authentication schemes. */ schemes: v4_1.z.array(v4_1.z.string()), }); /** * Configuration for push notifications for a task. */ exports.PushNotificationConfigSchema = v4_1.z.object({ /** * Optional authentication information for push notifications. */ authentication: exports.PushNotificationAuthenticationInfoSchema.optional(), /** * Optional push notification token. */ token: v4_1.z.string().optional(), /** * URL to send push notifications to. */ url: v4_1.z.string(), }); /** * Associates a push notification config with a task. */ exports.TaskPushNotificationConfigSchema = v4_1.z.object({ /** * Push notification configuration. */ pushNotificationConfig: exports.PushNotificationConfigSchema, /** * ID of the task. */ taskId: v4_1.z.string(), }); // --- TASKS --- /** * Represents the status of a task. */ exports.TaskStatusSchema = v4_1.z.object({ /** * Most recent message for the task. */ message: exports.MessageSchema.optional(), /** * Current state of the task. */ state: exports.TaskStateEnum, /** * ISO 8601 datetime string when the status was recorded. */ timestamp: v4_1.z.string().optional(), }); /** * Represents a task in the system. */ exports.TaskSchema = v4_1.z.object({ /** * Artifacts generated for the task. */ artifacts: v4_1.z.array(exports.ArtifactSchema).optional(), /** * Context ID associated with the task. */ contextId: v4_1.z.string(), /** * History of messages for the task. */ history: v4_1.z.array(exports.MessageSchema).optional(), /** * Unique identifier for the task. */ id: v4_1.z.string(), /** * Type of object (always "task"). */ kind: v4_1.z.literal("task"), /** * Extension metadata. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), /** * Current status of the task. */ status: exports.TaskStatusSchema, }); // --- EVENTS --- /** * Event indicating a status update for a task. */ exports.TaskStatusUpdateEventSchema = v4_1.z.object({ /** * Context ID associated with the event. */ contextId: v4_1.z.string(), /** * Whether this is the final status update for the task. */ final: v4_1.z.boolean(), /** * Event type (always "status-update"). */ kind: v4_1.z.literal("status-update"), /** * Extension metadata. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), /** * Status of the task after the update. */ status: exports.TaskStatusSchema, /** * ID of the task. */ taskId: v4_1.z.string(), }); /** * Event indicating an artifact update for a task. */ exports.TaskArtifactUpdateEventSchema = v4_1.z.object({ /** * If true, the artifact is appended to the task's artifacts array. */ append: v4_1.z.boolean().optional(), /** * The artifact that was updated. */ artifact: exports.ArtifactSchema, /** * Context ID associated with the event. */ contextId: v4_1.z.string(), /** * Event type (always "artifact-update"). */ kind: v4_1.z.literal("artifact-update"), /** * If true, this is the last chunk of the artifact. */ lastChunk: v4_1.z.boolean().optional(), /** * Extension metadata. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), /** * ID of the task. */ taskId: v4_1.z.string(), }); // --- PARAMS --- /** * Parameters for identifying a task by ID. */ exports.TaskIdParamsSchema = v4_1.z.object({ /** * The ID of the task. */ id: v4_1.z.string(), /** * Optional metadata for the operation. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), }); /** * Parameters for querying a task, including optional history length. */ exports.TaskQueryParamsSchema = v4_1.z.object({ /** * Number of messages to include in the returned history. */ historyLength: v4_1.z.number().optional(), /** * The ID of the task. */ id: v4_1.z.string(), /** * Optional metadata for the operation. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), }); // --- MESSAGE SEND --- /** * Configuration options for sending a message. */ exports.MessageSendConfigurationSchema = v4_1.z.object({ /** * List of accepted output modes (MIME types). */ acceptedOutputModes: v4_1.z.array(v4_1.z.string()), /** * If true, the request is blocking. */ blocking: v4_1.z.boolean().optional(), /** * Number of messages to include in the returned history. */ historyLength: v4_1.z.number().optional(), /** * Optional push notification config for the message. */ pushNotificationConfig: exports.PushNotificationConfigSchema.optional(), }); /** * Parameters for sending a message. */ exports.MessageSendParamsSchema = v4_1.z.object({ /** * Optional configuration for sending the message. */ configuration: exports.MessageSendConfigurationSchema.optional(), /** * The message to send. */ message: exports.MessageSchema, /** * Optional metadata for the operation. */ metadata: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), }); // --- ERROR TYPES --- /** * Helper for constructing error schemas with code and default message. */ function errorType(constant, defaultMsg) { return v4_1.z.object({ /** * A Number that indicates the error type that occurred. */ code: v4_1.z.literal(constant), /** * A Primitive or Structured value that contains additional information about the error. * This may be omitted. */ data: v4_1.z.any().optional(), /** * A String providing a short description of the error. */ message: v4_1.z.string().default(defaultMsg), }); } var ErrorType; (function (ErrorType) { ErrorType[ErrorType["JSONParseError"] = -32700] = "JSONParseError"; ErrorType[ErrorType["InvalidRequestError"] = -32600] = "InvalidRequestError"; ErrorType[ErrorType["MethodNotFoundError"] = -32601] = "MethodNotFoundError"; ErrorType[ErrorType["InvalidParamsError"] = -32602] = "InvalidParamsError"; ErrorType[ErrorType["InternalError"] = -32603] = "InternalError"; ErrorType[ErrorType["TaskNotFoundError"] = -32001] = "TaskNotFoundError"; ErrorType[ErrorType["TaskNotCancelableError"] = -32002] = "TaskNotCancelableError"; ErrorType[ErrorType["PushNotificationNotSupportedError"] = -32003] = "PushNotificationNotSupportedError"; ErrorType[ErrorType["UnsupportedOperationError"] = -32004] = "UnsupportedOperationError"; ErrorType[ErrorType["ContentTypeNotSupportedError"] = -32005] = "ContentTypeNotSupportedError"; ErrorType[ErrorType["InvalidAgentResponseError"] = -32006] = "InvalidAgentResponseError"; })(ErrorType || (exports.ErrorType = ErrorType = {})); exports.JSONParseErrorSchema = errorType(ErrorType.JSONParseError, "Invalid JSON payload"); exports.InvalidRequestErrorSchema = errorType(ErrorType.InvalidRequestError, "Request payload validation error"); exports.MethodNotFoundErrorSchema = errorType(ErrorType.MethodNotFoundError, "Method not found"); exports.InvalidParamsErrorSchema = errorType(ErrorType.InvalidParamsError, "Invalid parameters"); exports.InternalErrorSchema = errorType(ErrorType.InternalError, "Internal error"); exports.TaskNotFoundErrorSchema = errorType(ErrorType.TaskNotFoundError, "Task not found"); exports.TaskNotCancelableErrorSchema = errorType(ErrorType.TaskNotCancelableError, "Task cannot be canceled"); exports.PushNotificationNotSupportedErrorSchema = errorType(ErrorType.PushNotificationNotSupportedError, "Push Notification is not supported"); exports.UnsupportedOperationErrorSchema = errorType(ErrorType.UnsupportedOperationError, "This operation is not supported"); exports.ContentTypeNotSupportedErrorSchema = errorType(ErrorType.ContentTypeNotSupportedError, "Incompatible content types"); exports.InvalidAgentResponseErrorSchema = errorType(ErrorType.InvalidAgentResponseError, "Invalid agent response"); // --- JSON-RPC --- /** * Generic JSON-RPC error schema. */ exports.JSONRPCErrorSchema = v4_1.z.object({ /** * Error code. */ code: v4_1.z.number(), /** * Optional error data. */ data: v4_1.z.any().optional(), /** * Error message. */ message: v4_1.z.string(), }); const isJSONRPCError = (value) => exports.JSONRPCErrorSchema.safeParse(value).success; exports.isJSONRPCError = isJSONRPCError; /** * JSON-RPC error response. */ exports.JSONRPCErrorResponseSchema = v4_1.z.object({ /** * The error object. */ error: v4_1.z.union([ exports.JSONRPCErrorSchema, exports.JSONParseErrorSchema, exports.InvalidRequestErrorSchema, exports.MethodNotFoundErrorSchema, exports.InvalidParamsErrorSchema, exports.InternalErrorSchema, exports.TaskNotFoundErrorSchema, exports.TaskNotCancelableErrorSchema, exports.PushNotificationNotSupportedErrorSchema, exports.UnsupportedOperationErrorSchema, exports.ContentTypeNotSupportedErrorSchema, exports.InvalidAgentResponseErrorSchema, ]), /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), }); /** * Base JSON-RPC message schema. */ exports.JSONRPCMessageSchema = v4_1.z.object({ /** * The ID of the request or response. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), }); /** * JSON-RPC request schema. */ exports.JSONRPCRequestSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The method to invoke. */ method: v4_1.z.string(), /** * Optional parameters for the method. */ params: v4_1.z.record(v4_1.z.string(), v4_1.z.any()).optional(), }); /** * JSON-RPC result schema. */ exports.JSONRPCResultSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The result of the request. */ result: v4_1.z.any(), }); /** * JSON-RPC response schema. */ exports.JSONRPCResponseSchema = v4_1.z.union([ exports.JSONRPCResultSchema, exports.JSONRPCErrorResponseSchema, ]); // --- REQUESTS --- /** * JSON-RPC request for sending a message. */ exports.SendMessageRequestSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The method (always "message/send"). */ method: v4_1.z.literal("message/send"), /** * Parameters for sending the message. */ params: exports.MessageSendParamsSchema, }); /** * JSON-RPC request for streaming a message. */ exports.SendStreamingMessageRequestSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The method (always "message/stream"). */ method: v4_1.z.literal("message/stream"), /** * Parameters for streaming the message. */ params: exports.MessageSendParamsSchema, }); /** * JSON-RPC request for retrieving a task. */ exports.GetTaskRequestSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The method (always "tasks/get"). */ method: v4_1.z.literal("tasks/get"), /** * Parameters for querying the task. */ params: exports.TaskQueryParamsSchema, }); /** * JSON-RPC request for canceling a task. */ exports.CancelTaskRequestSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The method (always "tasks/cancel"). */ method: v4_1.z.literal("tasks/cancel"), /** * Parameters for canceling the task. */ params: exports.TaskIdParamsSchema, }); /** * JSON-RPC request for setting push notification config for a task. */ exports.SetTaskPushNotificationConfigRequestSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The method (always "tasks/pushNotificationConfig/set"). */ method: v4_1.z.literal("tasks/pushNotificationConfig/set"), /** * Parameters for setting push notification config. */ params: exports.TaskPushNotificationConfigSchema, }); /** * JSON-RPC request for getting push notification config for a task. */ exports.GetTaskPushNotificationConfigRequestSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The method (always "tasks/pushNotificationConfig/get"). */ method: v4_1.z.literal("tasks/pushNotificationConfig/get"), /** * Parameters for getting push notification config. */ params: exports.TaskIdParamsSchema, }); /** * JSON-RPC request for resubscribing to a task. */ exports.TaskResubscriptionRequestSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The method (always "tasks/resubscribe"). */ method: v4_1.z.literal("tasks/resubscribe"), /** * Parameters for resubscribing to the task. */ params: exports.TaskIdParamsSchema, }); // --- RESPONSES --- /** * JSON-RPC success response for sending a message. */ exports.SendMessageSuccessResponseSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The result (Task or Message). */ result: v4_1.z.union([exports.TaskSchema, exports.MessageSchema]), }); exports.SendMessageResponseSchema = v4_1.z.union([ exports.SendMessageSuccessResponseSchema, exports.JSONRPCErrorResponseSchema, ]); /** * JSON-RPC success response for streaming a message. */ exports.SendStreamingMessageSuccessResponseSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The result (Task, Message, or Event). */ result: v4_1.z.union([ exports.TaskSchema, exports.MessageSchema, exports.TaskStatusUpdateEventSchema, exports.TaskArtifactUpdateEventSchema, ]), }); exports.SendStreamingMessageResponseSchema = v4_1.z.union([ exports.SendStreamingMessageSuccessResponseSchema, exports.JSONRPCErrorResponseSchema, ]); /** * JSON-RPC success response for retrieving a task. */ exports.GetTaskSuccessResponseSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The result (Task). */ result: exports.TaskSchema, }); exports.GetTaskResponseSchema = v4_1.z.union([ exports.GetTaskSuccessResponseSchema, exports.JSONRPCErrorResponseSchema, ]); /** * JSON-RPC success response for canceling a task. */ exports.CancelTaskSuccessResponseSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The result (Task). */ result: exports.TaskSchema, }); exports.CancelTaskResponseSchema = v4_1.z.union([ exports.CancelTaskSuccessResponseSchema, exports.JSONRPCErrorResponseSchema, ]); /** * JSON-RPC success response for setting push notification config. */ exports.SetTaskPushNotificationConfigSuccessResponseSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The result (TaskPushNotificationConfig). */ result: exports.TaskPushNotificationConfigSchema, }); exports.SetTaskPushNotificationConfigResponseSchema = v4_1.z.union([ exports.SetTaskPushNotificationConfigSuccessResponseSchema, exports.JSONRPCErrorResponseSchema, ]); /** * JSON-RPC success response for getting push notification config. */ exports.GetTaskPushNotificationConfigSuccessResponseSchema = v4_1.z.object({ /** * The ID of the request. */ id: v4_1.z.union([v4_1.z.string(), v4_1.z.number()]).optional(), /** * JSON-RPC version (always "2.0"). */ jsonrpc: v4_1.z.literal("2.0"), /** * The result (TaskPushNotificationConfig). */ result: exports.TaskPushNotificationConfigSchema, }); exports.GetTaskPushNotificationConfigResponseSchema = v4_1.z.union([ exports.GetTaskPushNotificationConfigSuccessResponseSchema, exports.JSONRPCErrorResponseSchema, ]); // --- UNION TYPES (A2AError, A2ARequest, etc) --- /** * Union of all error types defined in the A2A protocol. */ exports.A2AErrorSchema = v4_1.z.union([ exports.JSONParseErrorSchema, exports.InvalidRequestErrorSchema, exports.MethodNotFoundErrorSchema, exports.InvalidParamsErrorSchema, exports.InternalErrorSchema, exports.TaskNotFoundErrorSchema, exports.TaskNotCancelableErrorSchema, exports.PushNotificationNotSupportedErrorSchema, exports.UnsupportedOperationErrorSchema, exports.ContentTypeNotSupportedErrorSchema, exports.InvalidAgentResponseErrorSchema, ]); /** * Union of all request types defined in the A2A protocol. */ exports.A2ARequestSchema = v4_1.z.union([ exports.SendMessageRequestSchema, exports.SendStreamingMessageRequestSchema, exports.GetTaskRequestSchema, exports.CancelTaskRequestSchema, exports.SetTaskPushNotificationConfigRequestSchema, exports.GetTaskPushNotificationConfigRequestSchema, exports.TaskResubscriptionRequestSchema, ]); // --- END ---