UNPKG

nestjs-a2a

Version:

NestJS module for creating Google Agent to Agent Server

59 lines (58 loc) 2.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.A2AException = void 0; const a2a_types_1 = require("./a2a.types"); /** * Custom error class for A2A server operations, incorporating JSON-RPC error codes. */ class A2AException extends Error { constructor(code, message, data, taskId) { super(message); this.name = 'A2AError'; this.code = code; this.data = data; this.taskId = taskId; // Store associated task ID if provided } /** * Formats the error into a standard JSON-RPC error object structure. */ toJSONRPCError() { const errorObject = { code: this.code, message: this.message, }; if (this.data !== undefined) { errorObject.data = this.data; } return errorObject; } // Static factory methods for common errors static parseError(message, data) { return new A2AException(a2a_types_1.ErrorCodeParseError, message, data); } static invalidRequest(message, data) { return new A2AException(a2a_types_1.ErrorCodeInvalidRequest, message, data); } static methodNotFound(method) { return new A2AException(a2a_types_1.ErrorCodeMethodNotFound, `Method not found: ${method}`); } static invalidParams(message, data) { return new A2AException(a2a_types_1.ErrorCodeInvalidParams, message, data); } static internalError(message, data) { return new A2AException(a2a_types_1.ErrorCodeInternalError, message, data); } static taskNotFound(taskId) { return new A2AException(a2a_types_1.ErrorCodeTaskNotFound, `Task not found: ${taskId}`, undefined, taskId); } static taskNotCancelable(taskId) { return new A2AException(a2a_types_1.ErrorCodeTaskNotCancelable, `Task not cancelable: ${taskId}`, undefined, taskId); } static pushNotificationNotSupported() { return new A2AException(a2a_types_1.ErrorCodePushNotificationNotSupported, 'Push Notification is not supported'); } static unsupportedOperation(operation) { return new A2AException(a2a_types_1.ErrorCodeUnsupportedOperation, `Unsupported operation: ${operation}`); } } exports.A2AException = A2AException;