@artinet/sdk 0.6.0-preview.2 → 0.6.0

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.
Files changed (160) hide show
  1. package/README.md +100 -59
  2. package/dist/browser/browser.d.ts +2 -7
  3. package/dist/browser/browser.js +2 -7
  4. package/dist/browser/config/observability.d.ts +1 -1
  5. package/dist/browser/create/message-builder.d.ts +1 -1
  6. package/dist/browser/create/message-builder.js +19 -7
  7. package/dist/browser/create/task-builder.js +1 -1
  8. package/dist/browser/messenger/index.d.ts +1 -0
  9. package/dist/browser/messenger/index.js +1 -0
  10. package/dist/browser/messenger/messenger.d.ts +119 -0
  11. package/dist/browser/messenger/messenger.js +245 -0
  12. package/dist/browser/types/a2a/a2a.d.ts +38 -20
  13. package/dist/browser/types/a2a/a2a.js +0 -1
  14. package/dist/browser/types/core/core.d.ts +4 -2
  15. package/dist/browser/types/index.d.ts +0 -1
  16. package/dist/browser/types/index.js +0 -1
  17. package/dist/browser/types/storage.d.ts +2 -14
  18. package/dist/browser/types/storage.js +0 -4
  19. package/dist/browser/utils/{common/constants.d.ts → constants.d.ts} +1 -1
  20. package/dist/{utils/common → browser/utils}/constants.js +1 -1
  21. package/dist/browser/utils/{common/errors.d.ts → errors.d.ts} +17 -36
  22. package/dist/browser/utils/errors.js +76 -0
  23. package/dist/browser/utils/index.d.ts +6 -0
  24. package/dist/browser/utils/index.js +6 -0
  25. package/dist/{utils/common → browser/utils}/parse.js +1 -1
  26. package/dist/{utils/common → browser/utils}/schema-validation.js +2 -2
  27. package/dist/config/index.d.ts +1 -1
  28. package/dist/config/observability.d.ts +1 -1
  29. package/dist/create/agent-builder.d.ts +1 -1
  30. package/dist/create/create.d.ts +19 -20
  31. package/dist/create/create.js +33 -101
  32. package/dist/create/message-builder.d.ts +1 -1
  33. package/dist/create/message-builder.js +19 -7
  34. package/dist/create/status-builder.d.ts +4 -0
  35. package/dist/create/task-builder.js +1 -1
  36. package/dist/extensions/otel.d.ts +3 -0
  37. package/dist/extensions/otel.js +3 -0
  38. package/dist/extensions/pino.d.ts +3 -0
  39. package/dist/extensions/pino.js +3 -0
  40. package/dist/extensions/winston.d.ts +3 -0
  41. package/dist/extensions/winston.js +3 -0
  42. package/dist/index.d.ts +3 -3
  43. package/dist/index.js +3 -3
  44. package/dist/messenger/index.d.ts +1 -0
  45. package/dist/messenger/index.js +1 -0
  46. package/dist/messenger/messenger.d.ts +119 -0
  47. package/dist/messenger/messenger.js +251 -0
  48. package/dist/server/adapters/a2a_request_handler.d.ts +889 -0
  49. package/dist/server/adapters/a2a_request_handler.js +241 -0
  50. package/dist/server/adapters/loadable.d.ts +7 -0
  51. package/dist/server/adapters/loadable.js +73 -0
  52. package/dist/server/adapters/notifications.d.ts +26 -0
  53. package/dist/server/adapters/notifications.js +77 -0
  54. package/dist/server/express/server.d.ts +24 -18
  55. package/dist/server/express/server.js +41 -62
  56. package/dist/server/express/utils.d.ts +14 -0
  57. package/dist/server/express/{errors.js → utils.js} +22 -0
  58. package/dist/server/index.d.ts +4 -1
  59. package/dist/server/index.js +4 -1
  60. package/dist/server/params.d.ts +115 -0
  61. package/dist/server/params.js +21 -0
  62. package/dist/services/a2a/factory/context.d.ts +2 -1
  63. package/dist/services/a2a/factory/context.js +4 -3
  64. package/dist/services/a2a/factory/handler.d.ts +1 -1
  65. package/dist/services/a2a/factory/handler.js +7 -6
  66. package/dist/services/a2a/factory/service.d.ts +1 -1
  67. package/dist/services/a2a/factory/service.js +2 -2
  68. package/dist/services/a2a/factory/state-machine.js +9 -6
  69. package/dist/services/a2a/handlers/cancel-task.d.ts +1 -1
  70. package/dist/services/a2a/handlers/get-task.d.ts +1 -1
  71. package/dist/services/a2a/handlers/resubscribe-task.d.ts +2 -2
  72. package/dist/services/a2a/handlers/send-message.d.ts +1 -1
  73. package/dist/services/a2a/handlers/stream-message.d.ts +2 -2
  74. package/dist/services/a2a/handlers/update.js +7 -9
  75. package/dist/services/a2a/index.d.ts +0 -1
  76. package/dist/services/a2a/index.js +0 -1
  77. package/dist/services/a2a/managers.js +2 -1
  78. package/dist/services/a2a/messenger.d.ts +1 -1
  79. package/dist/services/a2a/messenger.js +1 -1
  80. package/dist/services/a2a/service.d.ts +26 -21
  81. package/dist/services/a2a/service.js +161 -93
  82. package/dist/services/a2a/state-machine.d.ts +1 -1
  83. package/dist/services/a2a/state-machine.js +2 -1
  84. package/dist/services/a2a/streams.js +1 -1
  85. package/dist/services/core/manager.d.ts +5 -0
  86. package/dist/services/core/manager.js +6 -0
  87. package/dist/services/mcp/service.js +1 -1
  88. package/dist/{utils/storage → storage}/file.d.ts +4 -2
  89. package/dist/{utils/storage → storage}/file.js +5 -4
  90. package/dist/storage/index.d.ts +1 -0
  91. package/dist/storage/index.js +2 -0
  92. package/dist/storage/sqlite.d.ts +353 -0
  93. package/dist/storage/sqlite.js +85 -0
  94. package/dist/transport/trpc/a2a/factory/router.d.ts +16 -16
  95. package/dist/transport/trpc/a2a/routes/info.d.ts +2 -2
  96. package/dist/transport/trpc/a2a/routes/message/route.d.ts +3 -3
  97. package/dist/transport/trpc/a2a/routes/message/route.js +2 -1
  98. package/dist/transport/trpc/a2a/routes/tasks/route.d.ts +4 -4
  99. package/dist/transport/trpc/a2a/routes/tasks/route.js +3 -2
  100. package/dist/types/a2a/a2a.d.ts +38 -20
  101. package/dist/types/a2a/a2a.js +0 -1
  102. package/dist/types/core/core.d.ts +4 -2
  103. package/dist/types/index.d.ts +0 -1
  104. package/dist/types/index.js +0 -1
  105. package/dist/types/storage.d.ts +2 -14
  106. package/dist/types/storage.js +0 -4
  107. package/dist/utils/{common/constants.d.ts → constants.d.ts} +1 -1
  108. package/dist/{browser/utils/common → utils}/constants.js +1 -1
  109. package/dist/utils/{common/errors.d.ts → errors.d.ts} +17 -36
  110. package/dist/utils/errors.js +80 -0
  111. package/dist/utils/index.d.ts +6 -11
  112. package/dist/utils/index.js +6 -11
  113. package/dist/utils/parse.d.ts +7 -0
  114. package/dist/utils/parse.js +14 -0
  115. package/dist/utils/schema-validation.d.ts +2 -0
  116. package/dist/utils/schema-validation.js +12 -0
  117. package/package.json +35 -22
  118. package/dist/browser/client/a2a-client.d.ts +0 -127
  119. package/dist/browser/client/a2a-client.js +0 -233
  120. package/dist/browser/client/index.d.ts +0 -1
  121. package/dist/browser/client/index.js +0 -1
  122. package/dist/browser/transport/rpc/parser.d.ts +0 -15
  123. package/dist/browser/transport/rpc/parser.js +0 -49
  124. package/dist/browser/transport/rpc/rpc-client.d.ts +0 -80
  125. package/dist/browser/transport/rpc/rpc-client.js +0 -189
  126. package/dist/browser/transport/streaming/event-stream.d.ts +0 -25
  127. package/dist/browser/transport/streaming/event-stream.js +0 -100
  128. package/dist/browser/types/client.d.ts +0 -133
  129. package/dist/browser/types/client.js +0 -5
  130. package/dist/browser/utils/common/errors.js +0 -95
  131. package/dist/client/a2a-client.d.ts +0 -127
  132. package/dist/client/a2a-client.js +0 -237
  133. package/dist/client/index.d.ts +0 -1
  134. package/dist/client/index.js +0 -1
  135. package/dist/server/express/errors.d.ts +0 -9
  136. package/dist/server/express/index.d.ts +0 -3
  137. package/dist/server/express/index.js +0 -3
  138. package/dist/server/express/middeware.d.ts +0 -7
  139. package/dist/server/express/middeware.js +0 -121
  140. package/dist/transport/index.d.ts +0 -3
  141. package/dist/transport/index.js +0 -4
  142. package/dist/transport/rpc/parser.d.ts +0 -15
  143. package/dist/transport/rpc/parser.js +0 -49
  144. package/dist/transport/rpc/rpc-client.d.ts +0 -80
  145. package/dist/transport/rpc/rpc-client.js +0 -189
  146. package/dist/transport/streaming/event-stream.d.ts +0 -25
  147. package/dist/transport/streaming/event-stream.js +0 -100
  148. package/dist/types/client.d.ts +0 -133
  149. package/dist/types/client.js +0 -5
  150. package/dist/utils/common/errors.js +0 -98
  151. /package/dist/{utils/common → browser/utils}/parse.d.ts +0 -0
  152. /package/dist/{utils/common → browser/utils}/schema-validation.d.ts +0 -0
  153. /package/dist/browser/utils/{common/utils.d.ts → utils.d.ts} +0 -0
  154. /package/dist/browser/utils/{common/utils.js → utils.js} +0 -0
  155. /package/dist/utils/{common/utils.d.ts → utils.d.ts} +0 -0
  156. /package/dist/utils/{common/utils.js → utils.js} +0 -0
  157. /package/dist/utils/{common/zAsyncIterable-v3.d.ts → zAsyncIterable-v3.d.ts} +0 -0
  158. /package/dist/utils/{common/zAsyncIterable-v3.js → zAsyncIterable-v3.js} +0 -0
  159. /package/dist/utils/{common/zAsyncIterable.d.ts → zAsyncIterable.d.ts} +0 -0
  160. /package/dist/utils/{common/zAsyncIterable.js → zAsyncIterable.js} +0 -0
@@ -0,0 +1,245 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { A2A } from "../types/index.js";
6
+ import { validateSchema } from "../utils/schema-validation.js";
7
+ import { logger } from "../config/index.js";
8
+ import * as describe from "../create/describe.js";
9
+ import { ClientFactory, ClientFactoryOptions, } from "@a2a-js/sdk/client";
10
+ class HeaderInterceptor {
11
+ constructor(_getCustomHeaders) {
12
+ this._getCustomHeaders = _getCustomHeaders;
13
+ }
14
+ before(args) {
15
+ const options = args.options ?? { serviceParameters: {} };
16
+ const serviceParameters = options.serviceParameters;
17
+ options.serviceParameters = {
18
+ ...serviceParameters,
19
+ ...this._getCustomHeaders(),
20
+ };
21
+ args.options = options;
22
+ return Promise.resolve();
23
+ }
24
+ after() {
25
+ return Promise.resolve();
26
+ }
27
+ }
28
+ /**
29
+ * Messenger is the main communication client for interacting with remote A2A-compatible services.
30
+ * It provides methods for sending messages, retrieving tasks, canceling operations, and handling streaming responses.
31
+ */
32
+ class Messenger {
33
+ constructor(baseUrl, _headers = {}, _fallbackPath, factory = ClientFactoryOptions.default, config) {
34
+ this._headers = _headers;
35
+ this._fallbackPath = _fallbackPath;
36
+ this._baseUrl = typeof baseUrl === "string" ? baseUrl : baseUrl.toString();
37
+ this._fallbackPath = _fallbackPath ?? "/agent.json";
38
+ this._factory = new ClientFactory(ClientFactoryOptions.createFrom(factory, {
39
+ clientConfig: {
40
+ ...config,
41
+ interceptors: [
42
+ ...(config?.interceptors ?? []),
43
+ new HeaderInterceptor(() => this.headers),
44
+ ],
45
+ },
46
+ }));
47
+ this.clientPromise = this.reset(this._baseUrl, this._fallbackPath);
48
+ }
49
+ async reset(baseUrl = this._baseUrl, fallbackPath = this._fallbackPath) {
50
+ this._baseUrl = typeof baseUrl === "string" ? baseUrl : baseUrl.toString();
51
+ this._fallbackPath = fallbackPath ?? "/agent.json";
52
+ this.clientPromise = this._factory
53
+ .createFromUrl(this._baseUrl)
54
+ .catch(async (error) => {
55
+ if (!this._fallbackPath) {
56
+ logger.error("Messenger: Failed to create client, no fallback path provided", { error });
57
+ throw error;
58
+ }
59
+ logger.warn("Messenger: Failed to create client, falling back to fallback path: ", { error, fallbackPath: this._fallbackPath });
60
+ return await this._factory
61
+ .createFromUrl(this._baseUrl, this._fallbackPath)
62
+ .catch(async (error) => {
63
+ logger.error("Messenger: Failed to create client, at fallback path: ", { error, fallbackPath: this._fallbackPath });
64
+ throw error;
65
+ });
66
+ });
67
+ return this.clientPromise;
68
+ }
69
+ get baseUrl() {
70
+ return this._baseUrl;
71
+ }
72
+ get headers() {
73
+ return this._headers;
74
+ }
75
+ set headers(headers) {
76
+ this._headers = headers;
77
+ }
78
+ get _client() {
79
+ return this.clientPromise;
80
+ }
81
+ /**
82
+ * Retrieves the AgentCard from the A2A server.
83
+ * @returns A promise resolving to the AgentCard.
84
+ */
85
+ async getAgentCard(requestOptions) {
86
+ const client = await this._client;
87
+ return await client.getAgentCard(requestOptions);
88
+ }
89
+ /**
90
+ * Sends a Message to an agent server.
91
+ * @param params The {@link A2A.MessageSendParams} for the message/send method.
92
+ * @param options The {@link RequestOptions} for the request.
93
+ * @returns A promise resolving to {@link A2A.SendMessageSuccessResult} from the agent server.
94
+ */
95
+ async sendMessage(params, options) {
96
+ const client = await this._client;
97
+ return await validateSchema(A2A.SendMessageSuccessResultSchema, await client.sendMessage(describe.messageSendParams(params), options));
98
+ }
99
+ /**
100
+ * Sends a Message and returns a stream of status and artifact updates.
101
+ * @param params Task parameters for the request
102
+ * @returns An AsyncIterable that yields TaskStatusUpdateEvent/TaskArtifactUpdateEvent/Task/Message payloads.
103
+ */
104
+ async *sendMessageStream(params, options) {
105
+ try {
106
+ const client = await this._client;
107
+ yield* client.sendMessageStream(describe.messageSendParams(params), options);
108
+ }
109
+ catch (error) {
110
+ logger.error("Messenger: Failed to send message stream", { error });
111
+ throw error;
112
+ }
113
+ }
114
+ /**
115
+ * Retrieves the current state of a task.
116
+ * @param params The parameters for the tasks/get method.
117
+ * @returns A promise resolving to the Task object or null.
118
+ */
119
+ async getTask(params, options) {
120
+ const client = await this._client;
121
+ return await validateSchema(A2A.TaskSchema, await client.getTask(params, options));
122
+ }
123
+ /**
124
+ * Cancels a currently running task.
125
+ * @param params The parameters for the tasks/cancel method.
126
+ * @returns A promise resolving to the updated Task object (usually canceled state) or null.
127
+ */
128
+ async cancelTask(params, options) {
129
+ const client = await this._client;
130
+ return await validateSchema(A2A.TaskSchema, await client.cancelTask(params, options));
131
+ }
132
+ /**
133
+ * Sets or updates the push notification config for a task.
134
+ * @param params The parameters for the tasks/pushNotificationConfig/set method (which is TaskPushNotificationConfig).
135
+ * @returns A promise resolving to the confirmed TaskPushNotificationConfig or null.
136
+ */
137
+ async setTaskPushNotificationConfig(params, options) {
138
+ const client = await this._client;
139
+ return await validateSchema(A2A.TaskPushNotificationConfigSchema, await client.setTaskPushNotificationConfig(params, options));
140
+ }
141
+ /**
142
+ * Retrieves the currently configured push notification config for a task.
143
+ * @param params The parameters for the tasks/pushNotificationConfig/get method.
144
+ * @returns A promise resolving to the TaskPushNotificationConfig or null.
145
+ */
146
+ async getTaskPushNotificationConfig(params, options) {
147
+ const client = await this._client;
148
+ return await validateSchema(A2A.TaskPushNotificationConfigSchema, await client.getTaskPushNotificationConfig(params, options));
149
+ }
150
+ async listTaskPushNotificationConfig(params, options) {
151
+ const client = await this._client;
152
+ return await validateSchema(A2A.ListTaskPushNotificationConfigResultSchema, await client.listTaskPushNotificationConfig(params, options));
153
+ }
154
+ async deleteTaskPushNotificationConfig(params, options) {
155
+ const client = await this._client;
156
+ return client.deleteTaskPushNotificationConfig(params, options);
157
+ }
158
+ /**
159
+ * Resubscribes to an existing task's update stream.
160
+ * @param params Parameters identifying the task to resubscribe to
161
+ * @returns An AsyncIterable that yields TaskStatusUpdateEvent or TaskArtifactUpdateEvent payloads.
162
+ */
163
+ async *resubscribeTask(params, options) {
164
+ try {
165
+ const client = await this._client;
166
+ yield* client.resubscribeTask(params, options);
167
+ }
168
+ catch (error) {
169
+ logger.error("Messenger: Failed to resubscribe task", { error });
170
+ throw error;
171
+ }
172
+ }
173
+ /**
174
+ * Checks if the server supports a specific capability based on the agent card.
175
+ * @param capability The capability to check (e.g., 'streaming', 'pushNotifications').
176
+ * @returns A promise resolving to true if the capability is supported.
177
+ */
178
+ async supports(capability) {
179
+ const card = await this.getAgentCard();
180
+ if (!card.capabilities) {
181
+ return false;
182
+ }
183
+ switch (capability) {
184
+ case "streaming":
185
+ return !!card.capabilities.streaming;
186
+ case "pushNotifications":
187
+ return !!card.capabilities.pushNotifications;
188
+ case "stateTransitionHistory":
189
+ return !!card.capabilities.stateTransitionHistory;
190
+ case "extentions":
191
+ return !!card.capabilities.extensions;
192
+ default:
193
+ return false;
194
+ }
195
+ }
196
+ /**
197
+ * Adds a single header to be included in all requests.
198
+ * @param name The header name.
199
+ * @param value The header value.
200
+ */
201
+ addHeader(name, value) {
202
+ this.headers[name] = value;
203
+ }
204
+ /**
205
+ * Removes a header.
206
+ * @param name The header name to remove.
207
+ */
208
+ removeHeader(name) {
209
+ delete this.headers[name];
210
+ }
211
+ static async create({ baseUrl, headers, fallbackPath, factory, config, }) {
212
+ const messenger = new Messenger(baseUrl, headers, fallbackPath, factory, config);
213
+ const card = await messenger.getAgentCard();
214
+ /**Validate the agent card to ensure the target conforms to the A2A specification */
215
+ await validateSchema(A2A.AgentCardSchema, card).catch((error) => {
216
+ logger.warn("Messenger: Invalid agent card detected", { error });
217
+ });
218
+ return messenger;
219
+ }
220
+ }
221
+ /**
222
+ * Creates a new Messenger instance.
223
+ * @param baseUrl The base URL for the A2A server.
224
+ * @param headers Optional custom headers to include in all requests.
225
+ * @param fallbackPath Optional fallback path to use if the agent card is not found at the base URL.
226
+ * @example
227
+ * const messenger = createMessenger({
228
+ * baseUrl: "http://localhost:4000/a2a",
229
+ * });
230
+ * const card = await messenger.getAgentCard();
231
+ * console.log(card);
232
+ * @example
233
+ * const messenger = createMessenger({
234
+ * baseUrl: "http://localhost:4000/a2a",
235
+ * fallbackPath: "/agent-card",
236
+ * });
237
+ * const card = await messenger.getAgentCard();
238
+ * console.log(card);
239
+ */
240
+ export const createMessenger = Messenger.create;
241
+ export const AgentMessenger = Messenger;
242
+ /**
243
+ * @deprecated Use {@link createMessenger} instead.
244
+ */
245
+ export const A2AClient = Messenger;
@@ -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 ServiceOptions {
298
- abortSignal?: AbortSignal;
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, context?: Context, options?: ServiceOptions) => Promise<Task>;
302
- cancelTask: (input: TaskIdParams, context?: Context, options?: ServiceOptions) => Promise<Task>;
303
- sendMessage: (message: MessageSendParams, context?: Context, options?: ServiceOptions) => Promise<SendMessageSuccessResult>;
304
- streamMessage: (message: MessageSendParams, context?: Context, options?: ServiceOptions) => AsyncGenerator<Update>;
305
- resubscribe: (input: TaskIdParams, context?: Context, options?: ServiceOptions) => AsyncGenerator<Update>;
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;
@@ -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 "events";
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>;
@@ -1,7 +1,6 @@
1
1
  export * from "./a2a/index.js";
2
2
  export * from "./core/index.js";
3
3
  export * from "./mcp/index.js";
4
- export * from "./client.js";
5
4
  export * from "./protocol.js";
6
5
  export * from "./storage.js";
7
6
  export * from "./utils/index.js";
@@ -1,7 +1,6 @@
1
1
  export * from "./a2a/index.js";
2
2
  export * from "./core/index.js";
3
3
  export * from "./mcp/index.js";
4
- export * from "./client.js";
5
4
  export * from "./protocol.js";
6
5
  export * from "./storage.js";
7
6
  export * from "./utils/index.js";
@@ -1,18 +1,6 @@
1
1
  /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
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> {
@@ -1,5 +1 @@
1
- /**
2
- * Copyright 2025 The Artinet Project
3
- * SPDX-License-Identifier: Apache-2.0
4
- */
5
1
  export {};
@@ -2,5 +2,5 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { A2A } from "../../types/index.js";
5
+ import { A2A } from "../types/index.js";
6
6
  export declare const FINAL_STATES: A2A.TaskState[];
@@ -2,7 +2,7 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { A2A } from "../../types/index.js";
5
+ import { A2A } from "../types/index.js";
6
6
  export const FINAL_STATES = [
7
7
  A2A.TaskState.completed,
8
8
  A2A.TaskState.failed,
@@ -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 "../../types/index.js";
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: T["error"]["data"];
14
- constructor(message: string, code: T["error"]["code"], data: T["error"]["data"]);
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 INVALID_PARAMS: <T extends A2A.InvalidParamsError>(data: T["error"]["data"]) => SystemError<T>;
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 INTERNAL_ERROR: <T extends A2A.InternalError>(data: T["error"]["data"]) => SystemError<T>;
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 TASK_NOT_CANCELABLE: <T extends A2A.TaskNotCancelableError>(data: T["error"]["data"]) => SystemError<T>;
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.A2AError>(data: T["error"]["data"]) => SystemError<T>;
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,76 @@
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
+ constructor(message, code, data, taskId) {
12
+ super(message);
13
+ // this.name = "RpcError";
14
+ this.code = code;
15
+ this.data = data;
16
+ this.taskId = taskId;
17
+ this.message = message;
18
+ }
19
+ }
20
+ /**
21
+ * @since 0.6.0
22
+ */
23
+ export const PARSE_ERROR = (data, taskId) => new SystemError("Invalid JSON payload", A2A.ErrorCodeParseError, data, taskId);
24
+ /**
25
+ * @since 0.6.0
26
+ */
27
+ export const INVALID_REQUEST = (data, taskId) => new SystemError("Request payload validation error", A2A.ErrorCodeInvalidRequest, data, taskId);
28
+ /**
29
+ * @since 0.6.0
30
+ */
31
+ export const METHOD_NOT_FOUND = (data, taskId) => new SystemError("Method not found", A2A.ErrorCodeMethodNotFound, data, taskId);
32
+ export const INVALID_PARAMS = (data, taskId) => new SystemError("Invalid parameters", A2A.ErrorCodeInvalidParams, data, taskId);
33
+ export const INTERNAL_ERROR = (data, taskId) => new SystemError("Internal error", A2A.ErrorCodeInternalError, data, taskId);
34
+ export const TASK_NOT_FOUND = (data, taskId) => new SystemError("Task not found", A2A.ErrorCodeTaskNotFound, data, taskId);
35
+ export const TASK_NOT_CANCELABLE = (data, taskId) => new SystemError("Task cannot be canceled", A2A.ErrorCodeTaskNotCancelable, data, taskId);
36
+ /**
37
+ * @deprecated Use errors from the `@a2a-js/sdk` package instead
38
+ * @since 0.6.0
39
+ */
40
+ export const PUSH_NOTIFICATION_NOT_SUPPORTED = (data, taskId) => new SystemError("Push Notifications is not supported", A2A.ErrorCodePushNotificationNotSupported, data, taskId);
41
+ /**
42
+ * @deprecated Use errors from the `@a2a-js/sdk` package instead
43
+ * @since 0.6.0
44
+ */
45
+ export const AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED = (data, taskId) => new SystemError("Authenticated Extended Card is not configured", A2A.ErrorCodeAuthenticatedExtendedCardNotConfigured, data, taskId);
46
+ /**
47
+ * @deprecated Use errors from the `@a2a-js/sdk` package instead
48
+ * @since 0.6.0
49
+ */
50
+ export const UNSUPPORTED_OPERATION = (data, taskId) => new SystemError("This operation is not supported", A2A.ErrorCodeUnsupportedOperation, data, taskId);
51
+ /**
52
+ * @deprecated Use errors from the `@a2a-js/sdk` package instead
53
+ * @since 0.6.0
54
+ */
55
+ export const CONTENT_TYPE_NOT_SUPPORTED = (data, taskId) => new SystemError("Content type not supported", A2A.ErrorCodeContentTypeNotSupported, data, taskId);
56
+ /**
57
+ * @deprecated Use errors from the `@a2a-js/sdk` package instead
58
+ * @since 0.6.0
59
+ */
60
+ export const INVALID_AGENT_RESPONSE = (data, taskId) => new SystemError("Invalid agent response", A2A.ErrorCodeInvalidAgentResponse, data, taskId);
61
+ /**
62
+ * @deprecated Use {@link describe.update.failed} instead
63
+ * @since 0.6.0
64
+ */
65
+ export const FAILED_UPDATE = (taskId, contextId, messageId = "failed-update", errMessage) => {
66
+ return describe.update.failed({
67
+ taskId,
68
+ contextId,
69
+ final: true,
70
+ message: describe.message({
71
+ role: "agent",
72
+ messageId,
73
+ parts: [{ kind: "text", text: errMessage }],
74
+ }),
75
+ });
76
+ };
@@ -0,0 +1,6 @@
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,6 @@
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";
@@ -1,5 +1,5 @@
1
1
  import { validateSchema } from "./schema-validation.js";
2
- import { logger } from "../../config/index.js";
2
+ import { logger } from "../config/index.js";
3
3
  export function safeParse(json) {
4
4
  try {
5
5
  return JSON.parse(json);
@@ -2,8 +2,8 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { INVALID_PARAMS } from "../index.js";
6
- import { logger } from "../../config/index.js";
5
+ import { INVALID_PARAMS } from "./errors.js";
6
+ import { logger } from "../config/index.js";
7
7
  export async function validateSchema(schema, data) {
8
8
  return await schema.parseAsync(data).catch((error) => {
9
9
  logger.error("Schema validation failed", error);