UNPKG

@artinet/sdk

Version:

A TypeScript SDK for building collaborative AI agents.

77 lines (76 loc) 3.19 kB
/** * Copyright 2025 The Artinet Project * SPDX-License-Identifier: Apache-2.0 */ import { A2A } from "../types/index.js"; import * as describe from "../create/describe.js"; /** * @since 0.6.0 */ export class SystemError extends Error { constructor(message, code, data, taskId) { super(message); // this.name = "RpcError"; this.code = code; this.data = data; this.taskId = taskId; this.message = message; } } /** * @since 0.6.0 */ export const PARSE_ERROR = (data, taskId) => new SystemError("Invalid JSON payload", A2A.ErrorCodeParseError, data, taskId); /** * @since 0.6.0 */ export const INVALID_REQUEST = (data, taskId) => new SystemError("Request payload validation error", A2A.ErrorCodeInvalidRequest, data, taskId); /** * @since 0.6.0 */ export const METHOD_NOT_FOUND = (data, taskId) => new SystemError("Method not found", A2A.ErrorCodeMethodNotFound, data, taskId); export const INVALID_PARAMS = (data, taskId) => new SystemError("Invalid parameters", A2A.ErrorCodeInvalidParams, data, taskId); export const INTERNAL_ERROR = (data, taskId) => new SystemError("Internal error", A2A.ErrorCodeInternalError, data, taskId); export const TASK_NOT_FOUND = (data, taskId) => new SystemError("Task not found", A2A.ErrorCodeTaskNotFound, data, taskId); export const TASK_NOT_CANCELABLE = (data, taskId) => new SystemError("Task cannot be canceled", A2A.ErrorCodeTaskNotCancelable, data, taskId); /** * @deprecated Use errors from the `@a2a-js/sdk` package instead * @since 0.6.0 */ export const PUSH_NOTIFICATION_NOT_SUPPORTED = (data, taskId) => new SystemError("Push Notifications is not supported", A2A.ErrorCodePushNotificationNotSupported, data, taskId); /** * @deprecated Use errors from the `@a2a-js/sdk` package instead * @since 0.6.0 */ export const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED = (data, taskId) => new SystemError("Authenticated Extended Card is not configured", A2A.ErrorCodeAuthenticatedExtendedCardNotConfigured, data, taskId); /** * @deprecated Use errors from the `@a2a-js/sdk` package instead * @since 0.6.0 */ export const UNSUPPORTED_OPERATION = (data, taskId) => new SystemError("This operation is not supported", A2A.ErrorCodeUnsupportedOperation, data, taskId); /** * @deprecated Use errors from the `@a2a-js/sdk` package instead * @since 0.6.0 */ export const CONTENT_TYPE_NOT_SUPPORTED = (data, taskId) => new SystemError("Content type not supported", A2A.ErrorCodeContentTypeNotSupported, data, taskId); /** * @deprecated Use errors from the `@a2a-js/sdk` package instead * @since 0.6.0 */ export const INVALID_AGENT_RESPONSE = (data, taskId) => new SystemError("Invalid agent response", A2A.ErrorCodeInvalidAgentResponse, data, taskId); /** * @deprecated Use {@link describe.update.failed} instead * @since 0.6.0 */ export const FAILED_UPDATE = (taskId, contextId, messageId = "failed-update", errMessage) => { return describe.update.failed({ taskId, contextId, final: true, message: describe.message({ role: "agent", messageId, parts: [{ kind: "text", text: errMessage }], }), }); };