@artinet/sdk 0.6.0-preview.3 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -50
- package/dist/browser/browser.d.ts +2 -7
- package/dist/browser/browser.js +2 -7
- package/dist/browser/config/observability.d.ts +1 -1
- package/dist/browser/create/message-builder.d.ts +1 -1
- package/dist/browser/create/message-builder.js +19 -7
- package/dist/browser/create/task-builder.js +5 -1
- package/dist/browser/messenger/index.d.ts +1 -0
- package/dist/browser/messenger/index.js +1 -0
- package/dist/browser/messenger/messenger.d.ts +119 -0
- package/dist/browser/messenger/messenger.js +280 -0
- package/dist/browser/types/a2a/a2a.d.ts +38 -20
- package/dist/browser/types/a2a/a2a.js +0 -1
- package/dist/browser/types/core/core.d.ts +4 -2
- package/dist/browser/types/index.d.ts +0 -1
- package/dist/browser/types/index.js +0 -1
- package/dist/browser/types/storage.d.ts +2 -14
- package/dist/browser/types/storage.js +0 -4
- package/dist/browser/utils/{common/constants.d.ts → constants.d.ts} +1 -1
- package/dist/{utils/common → browser/utils}/constants.js +1 -1
- package/dist/browser/utils/{common/errors.d.ts → errors.d.ts} +17 -36
- package/dist/browser/utils/errors.js +76 -0
- package/dist/browser/utils/index.d.ts +6 -0
- package/dist/browser/utils/index.js +6 -0
- package/dist/{utils/common → browser/utils}/parse.js +4 -1
- package/dist/{utils/common → browser/utils}/schema-validation.js +2 -2
- package/dist/config/index.d.ts +1 -1
- package/dist/config/observability.d.ts +1 -1
- package/dist/create/agent-builder.d.ts +1 -1
- package/dist/create/create.d.ts +19 -20
- package/dist/create/create.js +33 -101
- package/dist/create/message-builder.d.ts +1 -1
- package/dist/create/message-builder.js +19 -7
- package/dist/create/task-builder.js +5 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/messenger/index.d.ts +1 -0
- package/dist/messenger/index.js +1 -0
- package/dist/messenger/messenger.d.ts +119 -0
- package/dist/messenger/messenger.js +288 -0
- package/dist/server/adapters/a2a_request_handler.d.ts +889 -0
- package/dist/server/adapters/a2a_request_handler.js +241 -0
- package/dist/server/adapters/loadable.d.ts +7 -0
- package/dist/server/adapters/loadable.js +73 -0
- package/dist/server/adapters/notifications.d.ts +26 -0
- package/dist/server/adapters/notifications.js +77 -0
- package/dist/server/express/server.d.ts +11 -19
- package/dist/server/express/server.js +29 -64
- package/dist/server/express/utils.d.ts +14 -0
- package/dist/server/express/{errors.js → utils.js} +22 -0
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.js +4 -1
- package/dist/server/params.d.ts +115 -0
- package/dist/server/params.js +21 -0
- package/dist/services/a2a/factory/context.d.ts +2 -1
- package/dist/services/a2a/factory/context.js +4 -3
- package/dist/services/a2a/factory/handler.d.ts +1 -1
- package/dist/services/a2a/factory/handler.js +7 -6
- package/dist/services/a2a/factory/service.d.ts +1 -1
- package/dist/services/a2a/factory/service.js +2 -2
- package/dist/services/a2a/factory/state-machine.js +9 -6
- package/dist/services/a2a/handlers/cancel-task.d.ts +1 -1
- package/dist/services/a2a/handlers/get-task.d.ts +1 -1
- package/dist/services/a2a/handlers/resubscribe-task.d.ts +2 -2
- package/dist/services/a2a/handlers/send-message.d.ts +1 -1
- package/dist/services/a2a/handlers/stream-message.d.ts +2 -2
- package/dist/services/a2a/handlers/update.js +2 -2
- package/dist/services/a2a/index.d.ts +0 -1
- package/dist/services/a2a/index.js +0 -1
- package/dist/services/a2a/managers.js +2 -1
- package/dist/services/a2a/messenger.d.ts +1 -1
- package/dist/services/a2a/messenger.js +1 -1
- package/dist/services/a2a/service.d.ts +26 -21
- package/dist/services/a2a/service.js +163 -95
- package/dist/services/a2a/state-machine.d.ts +1 -1
- package/dist/services/a2a/state-machine.js +2 -1
- package/dist/services/a2a/streams.js +1 -1
- package/dist/services/core/manager.d.ts +5 -0
- package/dist/services/core/manager.js +6 -0
- package/dist/services/mcp/service.js +1 -1
- package/dist/{utils/storage → storage}/file.d.ts +4 -2
- package/dist/{utils/storage → storage}/file.js +5 -4
- package/dist/storage/index.d.ts +1 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/sqlite.d.ts +353 -0
- package/dist/storage/sqlite.js +85 -0
- package/dist/transport/trpc/a2a/factory/router.d.ts +16 -16
- package/dist/transport/trpc/a2a/routes/info.d.ts +2 -2
- package/dist/transport/trpc/a2a/routes/message/route.d.ts +3 -3
- package/dist/transport/trpc/a2a/routes/message/route.js +2 -2
- package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +4 -4
- package/dist/transport/trpc/a2a/routes/tasks/route.js +3 -3
- package/dist/types/a2a/a2a.d.ts +38 -20
- package/dist/types/a2a/a2a.js +0 -1
- package/dist/types/core/core.d.ts +4 -2
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/storage.d.ts +2 -14
- package/dist/types/storage.js +0 -4
- package/dist/utils/{common/constants.d.ts → constants.d.ts} +1 -1
- package/dist/{browser/utils/common → utils}/constants.js +1 -1
- package/dist/utils/{common/errors.d.ts → errors.d.ts} +17 -36
- package/dist/utils/errors.js +80 -0
- package/dist/utils/index.d.ts +6 -10
- package/dist/utils/index.js +6 -10
- package/dist/utils/parse.d.ts +7 -0
- package/dist/utils/parse.js +17 -0
- package/dist/utils/schema-validation.d.ts +2 -0
- package/dist/utils/schema-validation.js +12 -0
- package/package.json +35 -22
- package/dist/browser/client/a2a-client.d.ts +0 -127
- package/dist/browser/client/a2a-client.js +0 -233
- package/dist/browser/client/index.d.ts +0 -1
- package/dist/browser/client/index.js +0 -1
- package/dist/browser/transport/rpc/parser.d.ts +0 -15
- package/dist/browser/transport/rpc/parser.js +0 -49
- package/dist/browser/transport/rpc/rpc-client.d.ts +0 -80
- package/dist/browser/transport/rpc/rpc-client.js +0 -189
- package/dist/browser/transport/streaming/event-stream.d.ts +0 -25
- package/dist/browser/transport/streaming/event-stream.js +0 -100
- package/dist/browser/types/client.d.ts +0 -133
- package/dist/browser/types/client.js +0 -5
- package/dist/browser/utils/common/errors.js +0 -95
- package/dist/client/a2a-client.d.ts +0 -127
- package/dist/client/a2a-client.js +0 -237
- package/dist/client/index.d.ts +0 -1
- package/dist/client/index.js +0 -1
- package/dist/server/express/errors.d.ts +0 -9
- package/dist/server/express/index.d.ts +0 -3
- package/dist/server/express/index.js +0 -3
- package/dist/server/express/middeware.d.ts +0 -7
- package/dist/server/express/middeware.js +0 -121
- package/dist/transport/index.d.ts +0 -3
- package/dist/transport/index.js +0 -4
- package/dist/transport/rpc/parser.d.ts +0 -15
- package/dist/transport/rpc/parser.js +0 -49
- package/dist/transport/rpc/rpc-client.d.ts +0 -80
- package/dist/transport/rpc/rpc-client.js +0 -189
- package/dist/transport/streaming/event-stream.d.ts +0 -25
- package/dist/transport/streaming/event-stream.js +0 -100
- package/dist/types/client.d.ts +0 -133
- package/dist/types/client.js +0 -5
- package/dist/utils/common/errors.js +0 -98
- /package/dist/{utils/common → browser/utils}/parse.d.ts +0 -0
- /package/dist/{utils/common → browser/utils}/schema-validation.d.ts +0 -0
- /package/dist/browser/utils/{common/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/browser/utils/{common/utils.js → utils.js} +0 -0
- /package/dist/utils/{common/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/utils/{common/utils.js → utils.js} +0 -0
- /package/dist/utils/{common/zAsyncIterable-v3.d.ts → zAsyncIterable-v3.d.ts} +0 -0
- /package/dist/utils/{common/zAsyncIterable-v3.js → zAsyncIterable-v3.js} +0 -0
- /package/dist/utils/{common/zAsyncIterable.d.ts → zAsyncIterable.d.ts} +0 -0
- /package/dist/utils/{common/zAsyncIterable.js → zAsyncIterable.js} +0 -0
|
@@ -49,7 +49,7 @@ export declare const taskRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
49
49
|
id: string;
|
|
50
50
|
contextId: string;
|
|
51
51
|
status: {
|
|
52
|
-
state: "
|
|
52
|
+
state: "unknown" | "submitted" | "working" | "input-required" | "completed" | "canceled" | "failed" | "rejected" | "auth-required";
|
|
53
53
|
message?: {
|
|
54
54
|
role: "user" | "agent";
|
|
55
55
|
parts: ({
|
|
@@ -155,7 +155,7 @@ export declare const taskRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
155
155
|
contextId: string;
|
|
156
156
|
kind: "status-update";
|
|
157
157
|
status: {
|
|
158
|
-
state: "
|
|
158
|
+
state: "unknown" | "submitted" | "working" | "input-required" | "completed" | "canceled" | "failed" | "rejected" | "auth-required";
|
|
159
159
|
message?: {
|
|
160
160
|
role: "user" | "agent";
|
|
161
161
|
parts: ({
|
|
@@ -242,7 +242,7 @@ export declare const taskRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
242
242
|
id: string;
|
|
243
243
|
contextId: string;
|
|
244
244
|
status: {
|
|
245
|
-
state: "
|
|
245
|
+
state: "unknown" | "submitted" | "working" | "input-required" | "completed" | "canceled" | "failed" | "rejected" | "auth-required";
|
|
246
246
|
message?: {
|
|
247
247
|
role: "user" | "agent";
|
|
248
248
|
parts: ({
|
|
@@ -355,7 +355,7 @@ export declare const taskRouter: import("@trpc/server").TRPCBuiltRouter<{
|
|
|
355
355
|
id: string;
|
|
356
356
|
contextId: string;
|
|
357
357
|
status: {
|
|
358
|
-
state: "
|
|
358
|
+
state: "unknown" | "submitted" | "working" | "input-required" | "completed" | "canceled" | "failed" | "rejected" | "auth-required";
|
|
359
359
|
message?: {
|
|
360
360
|
role: "user" | "agent";
|
|
361
361
|
parts: ({
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
import { z } from "zod/v4";
|
|
6
6
|
import { router, A2AProcedure } from "../../trpc.js";
|
|
7
7
|
import { A2A } from "../../../../../types/index.js";
|
|
8
|
-
import { INVALID_REQUEST, PUSH_NOTIFICATION_NOT_SUPPORTED, } from "../../../../../utils/
|
|
9
|
-
import { zAsyncIterable } from "../../../../../utils/
|
|
8
|
+
import { INVALID_REQUEST, PUSH_NOTIFICATION_NOT_SUPPORTED, } from "../../../../../utils/errors.js";
|
|
9
|
+
import { zAsyncIterable } from "../../../../../utils/zAsyncIterable.js";
|
|
10
10
|
const pushNotificationConfigRouter = router({
|
|
11
11
|
set: A2AProcedure.input(A2A.TaskPushNotificationConfigSchema)
|
|
12
12
|
.output(A2A.TaskPushNotificationConfigSchema)
|
|
@@ -20,7 +20,7 @@ const pushNotificationConfigRouter = router({
|
|
|
20
20
|
console.warn("task/pushNotificationConfig/get", input);
|
|
21
21
|
throw PUSH_NOTIFICATION_NOT_SUPPORTED("Push notifications not supported");
|
|
22
22
|
}),
|
|
23
|
-
list: A2AProcedure.input(A2A.
|
|
23
|
+
list: A2AProcedure.input(A2A.ListTaskPushNotificationConfigParamsSchema)
|
|
24
24
|
.output(A2A.ListTaskPushNotificationConfigResultSchema)
|
|
25
25
|
.query(async ({ input }) => {
|
|
26
26
|
console.warn("task/pushNotificationConfig/list", input);
|
package/dist/types/a2a/a2a.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { AgentCard, Message, Task, AgentExtension, TaskQueryParams, TaskIdParams, MessageSendParams, SendMessageSuccessResult } from "@artinet/types/a2a";
|
|
5
|
+
import { AgentCard, Message, Task, AgentExtension, TaskQueryParams, TaskIdParams, MessageSendParams, SendMessageSuccessResult, PushNotificationConfig } from "@artinet/types/a2a";
|
|
6
6
|
import { core } from "../core/index.js";
|
|
7
7
|
import { z } from "zod/v4";
|
|
8
8
|
export type AgentCardParams = (Partial<AgentCard> & Required<Pick<AgentCard, "name">>) | string;
|
|
@@ -46,14 +46,14 @@ export declare const UpdateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
46
46
|
contextId: z.ZodString;
|
|
47
47
|
status: z.ZodObject<{
|
|
48
48
|
state: z.ZodEnum<{
|
|
49
|
-
failed: "failed";
|
|
50
49
|
unknown: "unknown";
|
|
50
|
+
submitted: "submitted";
|
|
51
|
+
working: "working";
|
|
52
|
+
"input-required": "input-required";
|
|
51
53
|
completed: "completed";
|
|
52
54
|
canceled: "canceled";
|
|
55
|
+
failed: "failed";
|
|
53
56
|
rejected: "rejected";
|
|
54
|
-
working: "working";
|
|
55
|
-
submitted: "submitted";
|
|
56
|
-
"input-required": "input-required";
|
|
57
57
|
"auth-required": "auth-required";
|
|
58
58
|
}>;
|
|
59
59
|
message: z.ZodOptional<z.ZodObject<{
|
|
@@ -168,14 +168,14 @@ export declare const UpdateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
168
168
|
kind: z.ZodLiteral<"status-update">;
|
|
169
169
|
status: z.ZodObject<{
|
|
170
170
|
state: z.ZodEnum<{
|
|
171
|
-
failed: "failed";
|
|
172
171
|
unknown: "unknown";
|
|
172
|
+
submitted: "submitted";
|
|
173
|
+
working: "working";
|
|
174
|
+
"input-required": "input-required";
|
|
173
175
|
completed: "completed";
|
|
174
176
|
canceled: "canceled";
|
|
177
|
+
failed: "failed";
|
|
175
178
|
rejected: "rejected";
|
|
176
|
-
working: "working";
|
|
177
|
-
submitted: "submitted";
|
|
178
|
-
"input-required": "input-required";
|
|
179
179
|
"auth-required": "auth-required";
|
|
180
180
|
}>;
|
|
181
181
|
message: z.ZodOptional<z.ZodObject<{
|
|
@@ -272,13 +272,13 @@ export interface Context extends BaseContext {
|
|
|
272
272
|
readonly messages: MessageConsumerProxy;
|
|
273
273
|
extensions?: AgentExtension[];
|
|
274
274
|
references?: Task[];
|
|
275
|
+
userId?: string;
|
|
275
276
|
getTask: () => Promise<Task>;
|
|
276
277
|
}
|
|
277
278
|
export type ContextParams = Omit<BaseContext, "publisher" | "isCancelled" | "getState" | "abortSignal"> & Omit<Partial<Context>, "userMessage" | "taskId"> & {
|
|
278
279
|
messenger: MessageConsumerProxy;
|
|
279
280
|
task: Task;
|
|
280
281
|
overrides?: Partial<Omit<EventConsumer, "contextId">>;
|
|
281
|
-
abortSignal?: AbortSignal;
|
|
282
282
|
};
|
|
283
283
|
export interface Contexts extends core.Contexts<Context> {
|
|
284
284
|
create: (params: ContextParams) => Promise<Context>;
|
|
@@ -294,20 +294,38 @@ export interface Cancellations extends Omit<core.Manager<void>, "get"> {
|
|
|
294
294
|
}
|
|
295
295
|
export interface Connections extends Omit<core.Manager<void>, "get"> {
|
|
296
296
|
}
|
|
297
|
-
export interface
|
|
298
|
-
|
|
297
|
+
export interface Notifier {
|
|
298
|
+
notify: (task: Task, update: Update, context?: Context) => Promise<void>;
|
|
299
|
+
register: (taskId: string, config: PushNotificationConfig) => Promise<void>;
|
|
300
|
+
}
|
|
301
|
+
export type ServiceOptions = Pick<ContextParams, "userId" | "extensions"> & {
|
|
302
|
+
task?: Task;
|
|
303
|
+
signal?: AbortSignal;
|
|
304
|
+
notifier?: Notifier;
|
|
305
|
+
};
|
|
306
|
+
export interface Handles {
|
|
307
|
+
getTask: (input: TaskQueryParams, context: Context) => Promise<Task>;
|
|
308
|
+
cancelTask: (input: TaskIdParams, context: Context) => Promise<Task>;
|
|
309
|
+
sendMessage: (message: MessageSendParams, context: Context) => Promise<SendMessageSuccessResult>;
|
|
310
|
+
/**
|
|
311
|
+
* @deprecated Use sendMessageStream instead
|
|
312
|
+
*/
|
|
313
|
+
streamMessage: (message: MessageSendParams, context: Context) => AsyncGenerator<Update>;
|
|
314
|
+
sendMessageStream: (message: MessageSendParams, context: Context) => AsyncGenerator<Update>;
|
|
315
|
+
resubscribe: (input: TaskIdParams, context: Context) => AsyncGenerator<Update>;
|
|
299
316
|
}
|
|
300
317
|
export interface RequestHandler {
|
|
301
|
-
getTask: (input: TaskQueryParams,
|
|
302
|
-
cancelTask: (input: TaskIdParams,
|
|
303
|
-
sendMessage: (message: MessageSendParams,
|
|
304
|
-
|
|
305
|
-
|
|
318
|
+
getTask: (input: TaskQueryParams, options?: ServiceOptions) => Promise<Task>;
|
|
319
|
+
cancelTask: (input: TaskIdParams, options?: ServiceOptions) => Promise<Task>;
|
|
320
|
+
sendMessage: (message: MessageSendParams, options?: ServiceOptions) => Promise<SendMessageSuccessResult>;
|
|
321
|
+
/**
|
|
322
|
+
* @deprecated Use sendMessageStream instead
|
|
323
|
+
*/
|
|
324
|
+
streamMessage: (message: MessageSendParams, options?: ServiceOptions) => AsyncGenerator<Update>;
|
|
325
|
+
sendMessageStream: (message: MessageSendParams, options?: ServiceOptions) => AsyncGenerator<Update>;
|
|
326
|
+
resubscribe: (input: TaskIdParams, options?: ServiceOptions) => AsyncGenerator<Update>;
|
|
306
327
|
getAgentCard: () => Promise<AgentCard>;
|
|
307
328
|
}
|
|
308
|
-
export interface ExtendedHandler extends RequestHandler {
|
|
309
|
-
getAuthenticatedExtendedCard: () => Promise<AgentCard>;
|
|
310
|
-
}
|
|
311
329
|
export interface Stream {
|
|
312
330
|
readonly contextId: string;
|
|
313
331
|
isAlive: boolean;
|
package/dist/types/a2a/a2a.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
//lets stay really granular with the imports
|
|
6
5
|
import { TaskArtifactUpdateEventSchema, MessageSchema, TaskSchema, TaskStatusUpdateEventSchema, } from "@artinet/types/a2a";
|
|
7
6
|
import { z } from "zod/v4";
|
|
8
7
|
export const UpdateSchema = z.discriminatedUnion("kind", [
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { EventEmitter } from "
|
|
1
|
+
import { EventEmitter } from "eventemitter3";
|
|
2
|
+
import { IStore } from "../storage.js";
|
|
2
3
|
export interface Service<Params extends object = object, Result extends unknown = void> {
|
|
3
4
|
execute: (params: Params) => Promise<Result>;
|
|
4
5
|
stop: () => Promise<void>;
|
|
@@ -11,9 +12,10 @@ export interface Context<State extends object = object> {
|
|
|
11
12
|
readonly publisher?: Publisher;
|
|
12
13
|
readonly getState: (args?: string) => Promise<State | undefined>;
|
|
13
14
|
metadata?: Record<string, unknown>;
|
|
15
|
+
/**hooks allow consumers to modify context on the fly*/
|
|
14
16
|
readonly hooks?: Record<string, (...args: unknown[]) => Promise<unknown>>;
|
|
15
17
|
}
|
|
16
|
-
export interface Manager<T = object> {
|
|
18
|
+
export interface Manager<T = object> extends IStore<T> {
|
|
17
19
|
get: (id: string) => Promise<T | undefined>;
|
|
18
20
|
set: (id: string, data?: T) => Promise<void>;
|
|
19
21
|
delete: (id: string) => Promise<void>;
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/index.js
CHANGED
package/dist/types/storage.d.ts
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Interface for a store of data.
|
|
7
|
-
* @deprecated Use IStore instead
|
|
8
|
-
* @template T - The type of data to store
|
|
9
|
-
*/
|
|
10
|
-
export interface Store<T> {
|
|
11
|
-
set(data: T, id?: string): Promise<void>;
|
|
12
|
-
get(id: string): Promise<T | undefined>;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Interface for a store of data.
|
|
2
|
+
* @note prefer implementing `Manager` instead of `IStore` as it provides a more robust interface.
|
|
3
|
+
* Interface for a store of data.
|
|
16
4
|
* @template T - The type of data to store
|
|
17
5
|
*/
|
|
18
6
|
export interface IStore<T> {
|
package/dist/types/storage.js
CHANGED
|
@@ -2,77 +2,58 @@
|
|
|
2
2
|
* Copyright 2025 The Artinet Project
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { A2A, MCP } from "
|
|
5
|
+
import { A2A, MCP } from "../types/index.js";
|
|
6
6
|
/**
|
|
7
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
8
7
|
* @since 0.6.0
|
|
9
8
|
*/
|
|
10
9
|
export declare class SystemError<T extends MCP.JSONRPCErrorResponse> extends Error {
|
|
11
|
-
message: string;
|
|
12
10
|
code: T["error"]["code"];
|
|
13
|
-
data
|
|
14
|
-
|
|
11
|
+
data?: T["error"]["data"];
|
|
12
|
+
taskId?: string;
|
|
13
|
+
message: string;
|
|
14
|
+
constructor(message: string, code: T["error"]["code"], data?: T["error"]["data"], taskId?: string);
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
18
|
-
* @since 0.6.0
|
|
19
|
-
*/
|
|
20
|
-
export declare const PARSE_ERROR: <T extends A2A.JSONParseError>(data: T["error"]["data"]) => SystemError<T>;
|
|
21
|
-
/**
|
|
22
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
23
|
-
* @since 0.6.0
|
|
24
|
-
*/
|
|
25
|
-
export declare const INVALID_REQUEST: <T extends A2A.InvalidRequestError>(data: T["error"]["data"]) => SystemError<T>;
|
|
26
|
-
/**
|
|
27
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
28
|
-
* @since 0.6.0
|
|
29
|
-
*/
|
|
30
|
-
export declare const METHOD_NOT_FOUND: <T extends A2A.MethodNotFoundError>(data: T["error"]["data"]) => SystemError<T>;
|
|
31
|
-
/**
|
|
32
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
33
17
|
* @since 0.6.0
|
|
34
18
|
*/
|
|
35
|
-
export declare const
|
|
19
|
+
export declare const PARSE_ERROR: <T extends A2A.JSONParseError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
36
20
|
/**
|
|
37
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
38
21
|
* @since 0.6.0
|
|
39
22
|
*/
|
|
40
|
-
export declare const
|
|
23
|
+
export declare const INVALID_REQUEST: <T extends A2A.InvalidRequestError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
41
24
|
/**
|
|
42
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
43
|
-
* @since 0.6.0
|
|
44
|
-
*/
|
|
45
|
-
export declare const TASK_NOT_FOUND: <T extends A2A.TaskNotFoundError>(data: T["error"]["data"]) => SystemError<T>;
|
|
46
|
-
/**
|
|
47
|
-
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
48
25
|
* @since 0.6.0
|
|
49
26
|
*/
|
|
50
|
-
export declare const
|
|
27
|
+
export declare const METHOD_NOT_FOUND: <T extends A2A.MethodNotFoundError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
28
|
+
export declare const INVALID_PARAMS: <T extends A2A.InvalidParamsError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
29
|
+
export declare const INTERNAL_ERROR: <T extends A2A.InternalError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
30
|
+
export declare const TASK_NOT_FOUND: <T extends A2A.TaskNotFoundError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
31
|
+
export declare const TASK_NOT_CANCELABLE: <T extends A2A.TaskNotCancelableError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
51
32
|
/**
|
|
52
33
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
53
34
|
* @since 0.6.0
|
|
54
35
|
*/
|
|
55
|
-
export declare const PUSH_NOTIFICATION_NOT_SUPPORTED: <T extends A2A.
|
|
36
|
+
export declare const PUSH_NOTIFICATION_NOT_SUPPORTED: <T extends A2A.PushNotificationNotSupportedError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
56
37
|
/**
|
|
57
38
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
58
39
|
* @since 0.6.0
|
|
59
40
|
*/
|
|
60
|
-
export declare const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED: <T extends A2A.AuthenticatedExtendedCardNotConfiguredError>(data: T["error"]["data"]) => SystemError<T>;
|
|
41
|
+
export declare const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED: <T extends A2A.AuthenticatedExtendedCardNotConfiguredError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
61
42
|
/**
|
|
62
43
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
63
44
|
* @since 0.6.0
|
|
64
45
|
*/
|
|
65
|
-
export declare const UNSUPPORTED_OPERATION: <T extends A2A.A2AError>(data: T["error"]["data"]) => SystemError<T>;
|
|
46
|
+
export declare const UNSUPPORTED_OPERATION: <T extends A2A.A2AError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
66
47
|
/**
|
|
67
48
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
68
49
|
* @since 0.6.0
|
|
69
50
|
*/
|
|
70
|
-
export declare const CONTENT_TYPE_NOT_SUPPORTED: <T extends A2A.ContentTypeNotSupportedError>(data: T["error"]["data"]) => SystemError<T>;
|
|
51
|
+
export declare const CONTENT_TYPE_NOT_SUPPORTED: <T extends A2A.ContentTypeNotSupportedError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
71
52
|
/**
|
|
72
53
|
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
73
54
|
* @since 0.6.0
|
|
74
55
|
*/
|
|
75
|
-
export declare const INVALID_AGENT_RESPONSE: <T extends A2A.InvalidAgentResponseError>(data: T["error"]["data"]) => SystemError<T>;
|
|
56
|
+
export declare const INVALID_AGENT_RESPONSE: <T extends A2A.InvalidAgentResponseError>(data: T["error"]["data"], taskId?: string) => SystemError<T>;
|
|
76
57
|
/**
|
|
77
58
|
* @deprecated Use {@link describe.update.failed} instead
|
|
78
59
|
* @since 0.6.0
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { A2A } from "../types/index.js";
|
|
6
|
+
import * as describe from "../create/describe.js";
|
|
7
|
+
/**
|
|
8
|
+
* @since 0.6.0
|
|
9
|
+
*/
|
|
10
|
+
export class SystemError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
data;
|
|
13
|
+
taskId;
|
|
14
|
+
message;
|
|
15
|
+
constructor(message, code, data, taskId) {
|
|
16
|
+
super(message);
|
|
17
|
+
// this.name = "RpcError";
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.data = data;
|
|
20
|
+
this.taskId = taskId;
|
|
21
|
+
this.message = message;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @since 0.6.0
|
|
26
|
+
*/
|
|
27
|
+
export const PARSE_ERROR = (data, taskId) => new SystemError("Invalid JSON payload", A2A.ErrorCodeParseError, data, taskId);
|
|
28
|
+
/**
|
|
29
|
+
* @since 0.6.0
|
|
30
|
+
*/
|
|
31
|
+
export const INVALID_REQUEST = (data, taskId) => new SystemError("Request payload validation error", A2A.ErrorCodeInvalidRequest, data, taskId);
|
|
32
|
+
/**
|
|
33
|
+
* @since 0.6.0
|
|
34
|
+
*/
|
|
35
|
+
export const METHOD_NOT_FOUND = (data, taskId) => new SystemError("Method not found", A2A.ErrorCodeMethodNotFound, data, taskId);
|
|
36
|
+
export const INVALID_PARAMS = (data, taskId) => new SystemError("Invalid parameters", A2A.ErrorCodeInvalidParams, data, taskId);
|
|
37
|
+
export const INTERNAL_ERROR = (data, taskId) => new SystemError("Internal error", A2A.ErrorCodeInternalError, data, taskId);
|
|
38
|
+
export const TASK_NOT_FOUND = (data, taskId) => new SystemError("Task not found", A2A.ErrorCodeTaskNotFound, data, taskId);
|
|
39
|
+
export const TASK_NOT_CANCELABLE = (data, taskId) => new SystemError("Task cannot be canceled", A2A.ErrorCodeTaskNotCancelable, data, taskId);
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
42
|
+
* @since 0.6.0
|
|
43
|
+
*/
|
|
44
|
+
export const PUSH_NOTIFICATION_NOT_SUPPORTED = (data, taskId) => new SystemError("Push Notifications is not supported", A2A.ErrorCodePushNotificationNotSupported, data, taskId);
|
|
45
|
+
/**
|
|
46
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
47
|
+
* @since 0.6.0
|
|
48
|
+
*/
|
|
49
|
+
export const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED = (data, taskId) => new SystemError("Authenticated Extended Card is not configured", A2A.ErrorCodeAuthenticatedExtendedCardNotConfigured, data, taskId);
|
|
50
|
+
/**
|
|
51
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
52
|
+
* @since 0.6.0
|
|
53
|
+
*/
|
|
54
|
+
export const UNSUPPORTED_OPERATION = (data, taskId) => new SystemError("This operation is not supported", A2A.ErrorCodeUnsupportedOperation, data, taskId);
|
|
55
|
+
/**
|
|
56
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
57
|
+
* @since 0.6.0
|
|
58
|
+
*/
|
|
59
|
+
export const CONTENT_TYPE_NOT_SUPPORTED = (data, taskId) => new SystemError("Content type not supported", A2A.ErrorCodeContentTypeNotSupported, data, taskId);
|
|
60
|
+
/**
|
|
61
|
+
* @deprecated Use errors from the `@a2a-js/sdk` package instead
|
|
62
|
+
* @since 0.6.0
|
|
63
|
+
*/
|
|
64
|
+
export const INVALID_AGENT_RESPONSE = (data, taskId) => new SystemError("Invalid agent response", A2A.ErrorCodeInvalidAgentResponse, data, taskId);
|
|
65
|
+
/**
|
|
66
|
+
* @deprecated Use {@link describe.update.failed} instead
|
|
67
|
+
* @since 0.6.0
|
|
68
|
+
*/
|
|
69
|
+
export const FAILED_UPDATE = (taskId, contextId, messageId = "failed-update", errMessage) => {
|
|
70
|
+
return describe.update.failed({
|
|
71
|
+
taskId,
|
|
72
|
+
contextId,
|
|
73
|
+
final: true,
|
|
74
|
+
message: describe.message({
|
|
75
|
+
role: "agent",
|
|
76
|
+
messageId,
|
|
77
|
+
parts: [{ kind: "text", text: errMessage }],
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
};
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./common/schema-validation.js";
|
|
8
|
-
export * from "./common/utils.js";
|
|
9
|
-
export * from "./common/parse.js";
|
|
10
|
-
export * from "./storage/file.js";
|
|
1
|
+
/**Only export browser compatible utils */
|
|
2
|
+
export * from "./constants.js";
|
|
3
|
+
export * from "./errors.js";
|
|
4
|
+
export * from "./parse.js";
|
|
5
|
+
export * from "./schema-validation.js";
|
|
6
|
+
export * from "./utils.js";
|
package/dist/utils/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
|
|
5
|
-
export * from "./
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./common/schema-validation.js";
|
|
8
|
-
export * from "./common/utils.js";
|
|
9
|
-
export * from "./common/parse.js";
|
|
10
|
-
export * from "./storage/file.js";
|
|
1
|
+
/**Only export browser compatible utils */
|
|
2
|
+
export * from "./constants.js";
|
|
3
|
+
export * from "./errors.js";
|
|
4
|
+
export * from "./parse.js";
|
|
5
|
+
export * from "./schema-validation.js";
|
|
6
|
+
export * from "./utils.js";
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { z } from "zod/v4";
|
|
6
|
+
export declare function safeParse<T = any>(json: string): T;
|
|
7
|
+
export declare function safeParseSchema<T extends z.ZodSchema>(json: string, schema: T): Promise<z.output<T>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { validateSchema } from "./schema-validation.js";
|
|
2
|
+
import { logger } from "../config/index.js";
|
|
3
|
+
export function safeParse(json) {
|
|
4
|
+
if (!json || json === "{}" || json === "[]" || json === "") {
|
|
5
|
+
return {};
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
return JSON.parse(json);
|
|
9
|
+
}
|
|
10
|
+
catch (error) {
|
|
11
|
+
logger.warn("safeParse error:", error, json);
|
|
12
|
+
return {};
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export async function safeParseSchema(json, schema) {
|
|
16
|
+
return await validateSchema(schema, safeParse(json));
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2025 The Artinet Project
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { INVALID_PARAMS } from "./errors.js";
|
|
6
|
+
import { logger } from "../config/index.js";
|
|
7
|
+
export async function validateSchema(schema, data) {
|
|
8
|
+
return await schema.parseAsync(data).catch((error) => {
|
|
9
|
+
logger.error("Schema validation failed", error);
|
|
10
|
+
throw INVALID_PARAMS(error);
|
|
11
|
+
});
|
|
12
|
+
}
|