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AEA,OAAO,cAAA,CAAe,OAAA,EAAiB,IAAA,EAAgC;AACrE,IAAA,OAAO,IAAI,eAAA,CAAe,uBAAA,EAAyB,OAAA,EAAS,IAAI,CAAA;AAAA,EAClE;AAAA,EAEA,OAAO,eAAe,MAAA,EAAgC;AACpD,IAAA,OAAO,IAAI,eAAA,CAAe,uBAAA,EAAyB,CAAA,kBAAA,EAAqB,MAAM,CAAA,CAAE,CAAA;AAAA,EAClF;AAAA,EAEA,OAAO,aAAA,CAAc,OAAA,EAAiB,IAAA,EAAgC;AACpE,IAAA,OAAO,IAAI,eAAA,CAAe,sBAAA,EAAwB,OAAA,EAAS,IAAI,CAAA;AAAA,EACjE;AAAA,EAEA,OAAO,aAAA,CAAc,OAAA,EAAiB,IAAA,EAAgC;AACpE,IAAA,OAAO,IAAI,eAAA,CAAe,sBAAA,EAAwB,OAAA,EAAS,IAAI,CAAA;AAAA,EACjE;AAAA,EAEA,OAAO,aAAa,MAAA,EAAgC;AAClD,IAAA,OAAO,IAAI,eAAA,CAAe,qBAAA,EAAuB,mBAAmB,MAAM,CAAA,CAAA,EAAI,QAAW,MAAM,CAAA;AAAA,EACjG;AAAA,EAEA,OAAO,kBAAkB,MAAA,EAAgC;AACvD,IAAA,OAAO,IAAI,eAAA,CAAe,0BAAA,EAA4B,wBAAwB,MAAM,CAAA,CAAA,EAAI,QAAW,MAAM,CAAA;AAAA,EAC3G;AAAA,EAEA,OAAO,4BAAA,GAA+C;AACpD,IAAA,OAAO,IAAI,eAAA,CAAe,qCAAA,EAAuC,oCAAoC,CAAA;AAAA,EACvG;AAAA,EAEA,OAAO,qBAAqB,SAAA,EAAmC;AAC7D,IAAA,OAAO,IAAI,eAAA,CAAe,6BAAA,EAA+B,CAAA,uBAAA,EAA0B,SAAS,CAAA,CAAE,CAAA;AAAA,EAChG;AACF","file":"index.cjs","sourcesContent":["import type { JSONRPCMessage, Message, Task } from '@a2a-js/sdk';\n\n/**\n * Represents a JSON-RPC error object.\n */\nexport interface JSONRPCError<Data = unknown | null, Code = number> {\n  /**\n   * A number indicating the error type that occurred.\n   */\n  code: Code;\n\n  /**\n   * A string providing a short description of the error.\n   */\n  message: string;\n\n  /**\n   * Optional additional data about the error.\n   * @default null\n   */\n  data?: Data;\n}\n\n/**\n * Represents a JSON-RPC response object.\n */\nexport interface JSONRPCResponse<R = unknown | null, E = unknown | null> extends JSONRPCMessage {\n  /**\n   * The result of the method invocation. Required on success.\n   * Should be null or omitted if an error occurred.\n   * @default null\n   */\n  result?: R;\n\n  /**\n   * An error object if an error occurred during the request. Required on failure.\n   * Should be null or omitted if the request was successful.\n   * @default null\n   */\n  error?: JSONRPCError<E> | null;\n}\n\nexport interface TaskContext {\n  /**\n   * The current state of the task when the handler is invoked or resumed.\n   * Note: This is a snapshot. For the absolute latest state during async operations,\n   * the handler might need to reload the task via the store.\n   */\n  task: Task;\n\n  /**\n   * The specific user message that triggered this handler invocation or resumption.\n   */\n  userMessage: Message;\n\n  /**\n   * Function to check if cancellation has been requested for this task.\n   * Handlers should ideally check this periodically during long-running operations.\n   * @returns {boolean} True if cancellation has been requested, false otherwise.\n   */\n  isCancelled(): boolean;\n\n  /**\n   * The message history associated with the task up to the point the handler is invoked.\n   * Optional, as history might not always be available or relevant.\n   */\n  history?: Message[];\n\n  // taskStore is removed as the server now handles loading/saving directly.\n  // If a handler specifically needs history, it would need to be passed differently\n  // or the handler pattern might need adjustment based on use case.\n\n  // Potential future additions:\n  // - logger instance\n  // - AbortSignal linked to cancellation\n}\n\n// === Error Types (Standard and A2A)\n\n/** Error code for JSON Parse Error (-32700). Invalid JSON was received by the server. */\nexport const ErrorCodeParseError = -32700;\nexport type ErrorCodeParseError = typeof ErrorCodeParseError;\n/** Error code for Invalid Request (-32600). The JSON sent is not a valid Request object. */\nexport const ErrorCodeInvalidRequest = -32600;\nexport type ErrorCodeInvalidRequest = typeof ErrorCodeInvalidRequest;\n/** Error code for Method Not Found (-32601). The method does not exist / is not available. */\nexport const ErrorCodeMethodNotFound = -32601;\nexport type ErrorCodeMethodNotFound = typeof ErrorCodeMethodNotFound;\n/** Error code for Invalid Params (-32602). Invalid method parameter(s). */\nexport const ErrorCodeInvalidParams = -32602;\nexport type ErrorCodeInvalidParams = typeof ErrorCodeInvalidParams;\n/** Error code for Internal Error (-32603). Internal JSON-RPC error. */\nexport const ErrorCodeInternalError = -32603;\nexport type ErrorCodeInternalError = typeof ErrorCodeInternalError;\n\n/** Error code for Task Not Found (-32001). The specified task was not found. */\nexport const ErrorCodeTaskNotFound = -32001;\nexport type ErrorCodeTaskNotFound = typeof ErrorCodeTaskNotFound;\n/** Error code for Task Not Cancelable (-32002). The specified task cannot be canceled. */\nexport const ErrorCodeTaskNotCancelable = -32002;\nexport type ErrorCodeTaskNotCancelable = typeof ErrorCodeTaskNotCancelable;\n/** Error code for Push Notification Not Supported (-32003). Push Notifications are not supported for this operation or agent. */\nexport const ErrorCodePushNotificationNotSupported = -32003;\nexport type ErrorCodePushNotificationNotSupported = typeof ErrorCodePushNotificationNotSupported;\n/** Error code for Unsupported Operation (-32004). The requested operation is not supported by the agent. */\nexport const ErrorCodeUnsupportedOperation = -32004;\nexport type ErrorCodeUnsupportedOperation = typeof ErrorCodeUnsupportedOperation;\n\n/**\n * Union of all well-known A2A and standard JSON-RPC error codes defined in this schema.\n * Use this type for checking against specific error codes. A server might theoretically\n * use other codes within the valid JSON-RPC ranges.\n */\nexport type KnownErrorCode =\n  | typeof ErrorCodeParseError\n  | typeof ErrorCodeInvalidRequest\n  | typeof ErrorCodeMethodNotFound\n  | typeof ErrorCodeInvalidParams\n  | typeof ErrorCodeInternalError\n  | typeof ErrorCodeTaskNotFound\n  | typeof ErrorCodeTaskNotCancelable\n  | typeof ErrorCodePushNotificationNotSupported\n  | typeof ErrorCodeUnsupportedOperation;\n","import {\n  ErrorCodeParseError,\n  ErrorCodeInvalidRequest,\n  ErrorCodeMethodNotFound,\n  ErrorCodePushNotificationNotSupported,\n  ErrorCodeTaskNotCancelable,\n  ErrorCodeTaskNotFound,\n  ErrorCodeUnsupportedOperation,\n  ErrorCodeInvalidParams,\n  ErrorCodeInternalError,\n} from './types';\nimport type { JSONRPCError, KnownErrorCode } from './types';\n\n/**\n * Custom error class for A2A server operations, incorporating JSON-RPC error codes.\n */\nexport class MastraA2AError extends Error {\n  public code: KnownErrorCode | number;\n  public data?: unknown;\n  public taskId?: string; // Optional task ID context\n\n  constructor(code: KnownErrorCode | number, message: string, data?: unknown, taskId?: string) {\n    super(message);\n    this.name = 'MastraA2AError';\n    this.code = code;\n    this.data = data;\n    this.taskId = taskId; // Store associated task ID if provided\n  }\n\n  /**\n   * Formats the error into a standard JSON-RPC error object structure.\n   */\n  toJSONRPCError(): JSONRPCError<unknown> {\n    const errorObject: JSONRPCError<unknown> = {\n      code: this.code,\n      message: this.message,\n    };\n    if (this.data !== undefined) {\n      errorObject.data = this.data;\n    }\n    return errorObject;\n  }\n\n  // Static factory methods for common errors\n\n  static parseError(message: string, data?: unknown): MastraA2AError {\n    return new MastraA2AError(ErrorCodeParseError, message, data);\n  }\n\n  static invalidRequest(message: string, data?: unknown): MastraA2AError {\n    return new MastraA2AError(ErrorCodeInvalidRequest, message, data);\n  }\n\n  static methodNotFound(method: string): MastraA2AError {\n    return new MastraA2AError(ErrorCodeMethodNotFound, `Method not found: ${method}`);\n  }\n\n  static invalidParams(message: string, data?: unknown): MastraA2AError {\n    return new MastraA2AError(ErrorCodeInvalidParams, message, data);\n  }\n\n  static internalError(message: string, data?: unknown): MastraA2AError {\n    return new MastraA2AError(ErrorCodeInternalError, message, data);\n  }\n\n  static taskNotFound(taskId: string): MastraA2AError {\n    return new MastraA2AError(ErrorCodeTaskNotFound, `Task not found: ${taskId}`, undefined, taskId);\n  }\n\n  static taskNotCancelable(taskId: string): MastraA2AError {\n    return new MastraA2AError(ErrorCodeTaskNotCancelable, `Task not cancelable: ${taskId}`, undefined, taskId);\n  }\n\n  static pushNotificationNotSupported(): MastraA2AError {\n    return new MastraA2AError(ErrorCodePushNotificationNotSupported, 'Push Notification is not supported');\n  }\n\n  static unsupportedOperation(operation: string): MastraA2AError {\n    return new MastraA2AError(ErrorCodeUnsupportedOperation, `Unsupported operation: ${operation}`);\n  }\n}\n"]}