@artinet/sdk 0.6.0-preview.1 → 0.6.0-preview.2

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 (113) hide show
  1. package/README.md +1 -1
  2. package/dist/browser/client/a2a-client.js +4 -4
  3. package/dist/browser/config/index.d.ts +1 -1
  4. package/dist/browser/config/index.js +1 -1
  5. package/dist/browser/create/agentcard-builder.d.ts +47 -0
  6. package/dist/browser/create/agentcard-builder.js +65 -0
  7. package/dist/browser/create/base.d.ts +4 -0
  8. package/dist/browser/create/base.js +1 -0
  9. package/dist/browser/create/describe.d.ts +8 -0
  10. package/dist/browser/create/describe.js +8 -0
  11. package/dist/browser/create/message-builder.d.ts +78 -0
  12. package/dist/browser/create/message-builder.js +108 -0
  13. package/dist/browser/create/part-builder.d.ts +60 -0
  14. package/dist/browser/create/part-builder.js +81 -0
  15. package/dist/browser/create/task-builder.d.ts +251 -0
  16. package/dist/browser/create/task-builder.js +379 -0
  17. package/dist/browser/transport/rpc/parser.d.ts +1 -1
  18. package/dist/browser/transport/rpc/parser.js +2 -1
  19. package/dist/browser/types/a2a/a2a.d.ts +7 -3
  20. package/dist/browser/types/a2a/index.d.ts +3 -1
  21. package/dist/browser/types/a2a/index.js +0 -1
  22. package/dist/browser/utils/common/constants.d.ts +0 -5
  23. package/dist/browser/utils/common/constants.js +0 -27
  24. package/dist/browser/utils/common/errors.d.ts +57 -1
  25. package/dist/browser/utils/common/errors.js +68 -15
  26. package/dist/client/a2a-client.js +4 -4
  27. package/dist/config/default.d.ts +1 -1
  28. package/dist/config/default.js +1 -1
  29. package/dist/config/index.d.ts +1 -1
  30. package/dist/config/index.js +1 -1
  31. package/dist/create/agent-builder.d.ts +77 -0
  32. package/dist/create/agent-builder.js +20 -0
  33. package/dist/create/agentcard-builder.d.ts +47 -0
  34. package/dist/create/agentcard-builder.js +66 -0
  35. package/dist/create/base.d.ts +4 -0
  36. package/dist/create/base.js +1 -0
  37. package/dist/create/create.d.ts +762 -0
  38. package/dist/create/create.js +556 -0
  39. package/dist/create/describe.d.ts +8 -0
  40. package/dist/create/describe.js +8 -0
  41. package/dist/create/index.d.ts +4 -0
  42. package/dist/create/index.js +4 -0
  43. package/dist/create/message-builder.d.ts +78 -0
  44. package/dist/create/message-builder.js +110 -0
  45. package/dist/create/part-builder.d.ts +60 -0
  46. package/dist/create/part-builder.js +84 -0
  47. package/dist/create/status-builder.d.ts +26 -0
  48. package/dist/create/status-builder.js +46 -0
  49. package/dist/create/task-builder.d.ts +251 -0
  50. package/dist/create/task-builder.js +384 -0
  51. package/dist/create/transform.d.ts +16 -0
  52. package/dist/create/transform.js +106 -0
  53. package/dist/index.d.ts +2 -0
  54. package/dist/index.js +2 -0
  55. package/dist/server/express/errors.js +4 -8
  56. package/dist/server/express/middeware.js +17 -38
  57. package/dist/server/express/server.d.ts +6 -1
  58. package/dist/server/express/server.js +30 -12
  59. package/dist/services/a2a/execute.d.ts +5 -0
  60. package/dist/services/a2a/execute.js +7 -0
  61. package/dist/services/a2a/factory/context.d.ts +1 -1
  62. package/dist/services/a2a/factory/context.js +2 -3
  63. package/dist/services/a2a/factory/handler.js +3 -3
  64. package/dist/services/a2a/factory/index.d.ts +0 -1
  65. package/dist/services/a2a/factory/index.js +0 -1
  66. package/dist/services/a2a/factory/service.d.ts +2 -2
  67. package/dist/services/a2a/factory/service.js +2 -2
  68. package/dist/services/a2a/factory/state-machine.d.ts +1 -1
  69. package/dist/services/a2a/factory/state-machine.js +30 -8
  70. package/dist/services/a2a/handlers/artifact.d.ts +2 -5
  71. package/dist/services/a2a/handlers/artifact.js +21 -32
  72. package/dist/services/a2a/handlers/cancel-task.js +7 -5
  73. package/dist/services/a2a/handlers/resubscribe-task.d.ts +10 -2
  74. package/dist/services/a2a/handlers/resubscribe-task.js +21 -18
  75. package/dist/services/a2a/handlers/send-message.js +6 -10
  76. package/dist/services/a2a/handlers/stream-message.d.ts +10 -2
  77. package/dist/services/a2a/handlers/stream-message.js +5 -1
  78. package/dist/services/a2a/handlers/update.js +11 -6
  79. package/dist/services/a2a/helpers/content.d.ts +5 -1
  80. package/dist/services/a2a/helpers/content.js +5 -1
  81. package/dist/services/a2a/helpers/index.d.ts +2 -2
  82. package/dist/services/a2a/helpers/index.js +2 -2
  83. package/dist/services/a2a/index.d.ts +1 -1
  84. package/dist/services/a2a/index.js +1 -1
  85. package/dist/services/a2a/managers.js +7 -1
  86. package/dist/services/a2a/service.d.ts +6 -2
  87. package/dist/services/a2a/service.js +52 -59
  88. package/dist/services/a2a/state-machine.d.ts +3 -3
  89. package/dist/services/a2a/state-machine.js +2 -0
  90. package/dist/transport/rpc/parser.d.ts +1 -1
  91. package/dist/transport/rpc/parser.js +2 -1
  92. package/dist/types/a2a/a2a.d.ts +7 -3
  93. package/dist/types/a2a/index.d.ts +3 -1
  94. package/dist/types/a2a/index.js +0 -1
  95. package/dist/utils/common/constants.d.ts +0 -5
  96. package/dist/utils/common/constants.js +0 -27
  97. package/dist/utils/common/errors.d.ts +57 -1
  98. package/dist/utils/common/errors.js +68 -15
  99. package/dist/utils/common/parse.d.ts +1 -1
  100. package/dist/utils/common/schema-validation.d.ts +1 -1
  101. package/package.json +7 -4
  102. package/dist/browser/services/a2a/helpers/message-builder.d.ts +0 -17
  103. package/dist/browser/services/a2a/helpers/message-builder.js +0 -66
  104. package/dist/browser/types/a2a/builder.d.ts +0 -43
  105. package/dist/browser/types/a2a/builder.js +0 -5
  106. package/dist/services/a2a/factory/builder.d.ts +0 -292
  107. package/dist/services/a2a/factory/builder.js +0 -370
  108. package/dist/services/a2a/helpers/agentcard-builder.d.ts +0 -11
  109. package/dist/services/a2a/helpers/agentcard-builder.js +0 -27
  110. package/dist/services/a2a/helpers/message-builder.d.ts +0 -17
  111. package/dist/services/a2a/helpers/message-builder.js +0 -66
  112. package/dist/types/a2a/builder.d.ts +0 -43
  113. package/dist/types/a2a/builder.js +0 -5
@@ -0,0 +1,384 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { A2A } from "../types/index.js";
6
+ import { v4 as uuidv4 } from "uuid";
7
+ import { getCurrentTimestamp } from "../utils/common/utils.js";
8
+ import { isMessageParams, Message,
9
+ // type BuilderMessageParams,
10
+ } from "./message-builder.js";
11
+ export const isArtifactParams = (params) => {
12
+ return (typeof params === "string" ||
13
+ (typeof params === "object" && params !== null && "parts" in params));
14
+ };
15
+ export class Artifact {
16
+ _artifact;
17
+ constructor(artifact_params = {}) {
18
+ this._artifact = {
19
+ artifactId: uuidv4(),
20
+ parts: [],
21
+ ...artifact_params,
22
+ };
23
+ }
24
+ get artifact() {
25
+ return this._artifact;
26
+ }
27
+ static create(params = {}) {
28
+ return new Artifact(typeof params === "string"
29
+ ? { parts: [{ text: params, kind: "text" }] }
30
+ : params).artifact;
31
+ }
32
+ }
33
+ export const artifact = Artifact.create;
34
+ export const isStatusParams = (params) => {
35
+ return (typeof params === "string" ||
36
+ (typeof params === "object" &&
37
+ params !== null &&
38
+ "state" in params &&
39
+ params.state in A2A.TaskState) ||
40
+ (typeof params === "object" &&
41
+ params !== null &&
42
+ "message" in params &&
43
+ isMessageParams(params.message)));
44
+ };
45
+ export class TaskStatus {
46
+ _status;
47
+ constructor(params = {}) {
48
+ const timestamp = params.timestamp ?? getCurrentTimestamp();
49
+ this._status = {
50
+ ...params,
51
+ state: params.state ?? A2A.TaskState.working,
52
+ timestamp,
53
+ };
54
+ }
55
+ get status() {
56
+ return this._status;
57
+ }
58
+ static create(params = {}) {
59
+ if (typeof params === "string" && params in A2A.TaskState) {
60
+ return new TaskStatus({ state: params }).status;
61
+ }
62
+ else if (isMessageParams(params)) {
63
+ return new TaskStatus({
64
+ state: A2A.TaskState.working,
65
+ message: Message.create(params),
66
+ }).status;
67
+ }
68
+ return new TaskStatus(params).status;
69
+ }
70
+ }
71
+ /**
72
+ * Convenience factory function for creating a task status with default parameters.
73
+ *
74
+ * @returns New {@link A2A.TaskStatus} with default parameters
75
+ * @defaults {
76
+ * state: "working",
77
+ * timestamp: getCurrentTimestamp(),
78
+ * }
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const status = status("working");
83
+ * ```
84
+ *
85
+ * @public
86
+ * @since 0.6.0
87
+ */
88
+ export const status = TaskStatus.create;
89
+ export class Task {
90
+ _task;
91
+ constructor(params = {}) {
92
+ const id = params.id ?? uuidv4();
93
+ this._task = {
94
+ ...params,
95
+ id,
96
+ contextId: params.contextId ?? id,
97
+ kind: A2A.Kind.task,
98
+ status: TaskStatus.create(params.status),
99
+ };
100
+ }
101
+ get task() {
102
+ return this._task;
103
+ }
104
+ static create(params = {}) {
105
+ if (isStatusParams(params)) {
106
+ return new Task({ status: TaskStatus.create(params) }).task;
107
+ }
108
+ return new Task(params).task;
109
+ }
110
+ }
111
+ /**
112
+ * Convenience factory function for creating a task with default parameters.
113
+ *
114
+ * @returns New {@link A2A.Task} with default parameters
115
+ * @defaults:
116
+ * - `id`: uuidv4()
117
+ * - `contextId`: id
118
+ * - `status`: { state: "working" }
119
+ * @example
120
+ * ```typescript
121
+ * const task = task({ status: { state: "working" } });
122
+ * ```
123
+ *
124
+ * @public
125
+ * @since 0.6.0
126
+ */
127
+ export const task = Task.create;
128
+ export class TaskStatusUpdateEvent {
129
+ _event;
130
+ constructor(params) {
131
+ const taskId = params.taskId ?? params.status.message?.taskId ?? uuidv4();
132
+ const contextId = params.contextId ?? params.status.message?.contextId ?? taskId;
133
+ this._event = {
134
+ ...params,
135
+ taskId,
136
+ contextId,
137
+ kind: A2A.Kind["status-update"],
138
+ final: params.final ?? false,
139
+ };
140
+ }
141
+ get event() {
142
+ return this._event;
143
+ }
144
+ static create(params) {
145
+ if (isStatusParams(params)) {
146
+ return new TaskStatusUpdateEvent({
147
+ /*allows for a mixture of Update & Status Params*/
148
+ ...(typeof params === "object" ? params : {}),
149
+ status: TaskStatus.create(params),
150
+ }).event;
151
+ }
152
+ return new TaskStatusUpdateEvent(params).event;
153
+ }
154
+ }
155
+ export class TaskArtifactUpdateEvent {
156
+ _event;
157
+ constructor(params) {
158
+ const taskId = params.taskId ?? uuidv4();
159
+ this._event = {
160
+ ...params,
161
+ taskId,
162
+ contextId: params.contextId ?? taskId,
163
+ kind: A2A.Kind["artifact-update"],
164
+ };
165
+ }
166
+ get event() {
167
+ return this._event;
168
+ }
169
+ static create(params) {
170
+ if (isArtifactParams(params)) {
171
+ return new TaskArtifactUpdateEvent({
172
+ artifact: Artifact.create(params),
173
+ }).event;
174
+ }
175
+ return new TaskArtifactUpdateEvent({
176
+ ...params,
177
+ artifact: Artifact.create(params.artifact),
178
+ }).event;
179
+ }
180
+ }
181
+ const strict_update = (params) => {
182
+ return TaskStatusUpdateEvent.create(params);
183
+ };
184
+ function _buildUpdate(state, params, final) {
185
+ return strict_update({
186
+ taskId: params.taskId,
187
+ contextId: params.contextId,
188
+ status: {
189
+ state: state,
190
+ message: params.message,
191
+ timestamp: params.timestamp,
192
+ },
193
+ final: final ?? params.final,
194
+ metadata: params.metadata,
195
+ });
196
+ }
197
+ function _working(params) {
198
+ return _buildUpdate(A2A.TaskState.working, params);
199
+ }
200
+ function _canceled(params) {
201
+ return _buildUpdate(A2A.TaskState.canceled, params, true);
202
+ }
203
+ function _submitted(params) {
204
+ return _buildUpdate(A2A.TaskState.submitted, params);
205
+ }
206
+ function _failed(params) {
207
+ return _buildUpdate(A2A.TaskState.failed, params, true);
208
+ }
209
+ function _completed(params) {
210
+ return _buildUpdate(A2A.TaskState.completed, params, true);
211
+ }
212
+ function _inputRequired(params) {
213
+ return _buildUpdate(A2A.TaskState["input-required"], params);
214
+ }
215
+ function _rejected(params) {
216
+ return _buildUpdate(A2A.TaskState.rejected, params);
217
+ }
218
+ function _authRequired(params) {
219
+ return _buildUpdate(A2A.TaskState["auth-required"], params);
220
+ }
221
+ function _unknown(params) {
222
+ return _buildUpdate(A2A.TaskState["unknown"], params);
223
+ }
224
+ /**
225
+ * Convenience factory function for creating a task status and artifact update events with default parameters.
226
+ *
227
+ * @returns New {@link A2A.TaskStatusUpdateEvent} and {@link A2A.TaskArtifactUpdateEvent} with default parameters
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const artifactEvent = update.artifact({
232
+ * artifact: "result"
233
+ * });
234
+ * const statusEvent = update.status({
235
+ * status: "working"
236
+ * });
237
+ * ```
238
+ *
239
+ * @public
240
+ * @since 0.6.0
241
+ */
242
+ export const update = {
243
+ /**
244
+ * Convenience factory function for creating a task artifact update event.
245
+ * @returns New {@link A2A.TaskArtifactUpdateEvent}
246
+ * @example
247
+ * ```typescript
248
+ * const event = update.artifact({
249
+ * artifact: "result"
250
+ * });
251
+ * ```
252
+ */
253
+ artifact: TaskArtifactUpdateEvent.create,
254
+ /**
255
+ * Convenience factory function for creating a task status update event.
256
+ * @returns New {@link A2A.TaskStatusUpdateEvent}
257
+ * @example
258
+ * ```typescript
259
+ * const event = update.status({
260
+ * message: "Working on the task"
261
+ * });
262
+ * ```
263
+ */
264
+ status: TaskStatusUpdateEvent.create,
265
+ /**
266
+ * Convenience factory function for creating a task status update event with the working state.
267
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.working} state
268
+ * @example
269
+ * ```typescript
270
+ * const event = update.working({
271
+ * message: "Working on the task"
272
+ * });
273
+ * ```
274
+ */
275
+ working: _working,
276
+ /**
277
+ * Convenience factory function for creating a task status update event with the canceled state.
278
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.canceled} state
279
+ * @example
280
+ * ```typescript
281
+ * const event = update.canceled({
282
+ * message: "Task canceled"
283
+ * });
284
+ * ```
285
+ */
286
+ canceled: _canceled,
287
+ /**
288
+ * Convenience factory function for creating a task status update event with the submitted state.
289
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.submitted} state
290
+ * @example
291
+ * ```typescript
292
+ * const event = update.submitted({
293
+ * message: "Task submitted"
294
+ * });
295
+ * ```
296
+ */
297
+ submitted: _submitted,
298
+ /**
299
+ * Convenience factory function for creating a task status update event with the failed state.
300
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.failed} state
301
+ * @example
302
+ * ```typescript
303
+ * const event = update.failed({
304
+ * message: "Task failed"
305
+ * });
306
+ * ```
307
+ */
308
+ failed: _failed,
309
+ /**
310
+ * Convenience factory function for creating a task status update event with the completed state.
311
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.completed} state
312
+ * @example
313
+ * ```typescript
314
+ * const event = update.completed({
315
+ * message: "Task completed"
316
+ * });
317
+ * ```
318
+ */
319
+ completed: _completed,
320
+ /**
321
+ * Convenience factory function for creating a task status update event with the input required state.
322
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState["input-required"]} state
323
+ * @example
324
+ * ```typescript
325
+ * const event = update.inputRequired({
326
+ * message: "Task input required"
327
+ * });
328
+ * ```
329
+ */
330
+ inputRequired: _inputRequired,
331
+ /**
332
+ * Convenience factory function for creating a task status update event with the rejected state.
333
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.rejected} state
334
+ * @example
335
+ * ```typescript
336
+ * const event = update.rejected({
337
+ * message: "Task rejected"
338
+ * });
339
+ * ```
340
+ */
341
+ rejected: _rejected,
342
+ /**
343
+ * Convenience factory function for creating a task status update event with the auth required state.
344
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState["auth-required"]} state
345
+ * @example
346
+ * ```typescript
347
+ * const event = update.authRequired({
348
+ * message: {
349
+ * role: "agent"
350
+ * parts: [
351
+ * {
352
+ * text: "Task auth required"
353
+ * }
354
+ * ]
355
+ * kind: "message"
356
+ * });
357
+ * ```
358
+ */
359
+ authRequired: _authRequired,
360
+ /**
361
+ * Convenience factory function for creating a task status update event with the unknown state.
362
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.unknown} state
363
+ * @example
364
+ * ```typescript
365
+ * const event = update.unknown({
366
+ * message: "Task unknown"
367
+ * });
368
+ * ```
369
+ */
370
+ unknown: _unknown,
371
+ };
372
+ /**
373
+ * @description A temporary compatibility function for updating a task status, purely for migration purposes.
374
+ * @deprecated Use {@link update.status} instead
375
+ * @since 0.6.0
376
+ */
377
+ export const update_compat = (taskId, contextId, state, message, timestamp, final = false) => {
378
+ return _buildUpdate(state, {
379
+ taskId: taskId,
380
+ contextId: contextId,
381
+ message: message,
382
+ timestamp: timestamp,
383
+ }, final);
384
+ };
@@ -0,0 +1,16 @@
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 Builder from "./agent-builder.js";
7
+ import { MessageParams } from "./message-builder.js";
8
+ import { StatusUpdateParams, ArtifactUpdateParams, TaskParams } from "./task-builder.js";
9
+ export declare function hasCarry<Ret extends Builder.AcceptedReturnValues, Carried extends Builder.BaseArgs>(ret: Builder.Reply<Ret, Carried>): ret is Builder.ReturnAndCarry<Ret, Carried>;
10
+ export declare function hasReply<Ret extends Builder.AcceptedReturnValues, Carried extends Builder.BaseArgs>(ret: Builder.Reply<Ret, Carried>): ret is Builder.ReturnValue<Ret>;
11
+ export declare function Parts(kind: "text" | "file" | "data"): Builder.Transform<Builder.AcceptedParts>;
12
+ export declare function Message(): Builder.Transform<Builder.Stateless<MessageParams>>;
13
+ export declare function Artifact(): Builder.Transform<Builder.Stateless<ArtifactUpdateParams>>;
14
+ export declare function Status(): Builder.Transform<Builder.Stateless<StatusUpdateParams>>;
15
+ export declare function Task(): Builder.Transform<Builder.Stateless<TaskParams>>;
16
+ export declare function Reply<Ret extends Builder.AcceptedReturnValues, Carried extends Builder.BaseArgs>(ret: Builder.Reply<Ret, Carried>, context: A2A.Context, transform: Builder.Transform<Ret>): AsyncGenerator<A2A.Update, Carried | undefined, unknown>;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { describe } from "./index.js";
6
+ import { TaskStatus, } from "./task-builder.js";
7
+ export function hasCarry(ret) {
8
+ return (ret !== null && typeof ret === "object" && "reply" in ret && "args" in ret);
9
+ }
10
+ export function hasReply(ret) {
11
+ return ret !== null && typeof ret === "object" && "reply" in ret;
12
+ }
13
+ function messagePart(params) {
14
+ switch (params.kind) {
15
+ case "text": {
16
+ return describe.part.text(params.part);
17
+ }
18
+ case "file": {
19
+ return describe.part.file(params.part);
20
+ }
21
+ case "data": {
22
+ return describe.part.data(params.part);
23
+ }
24
+ default:
25
+ throw new Error("Invalid part detected", { cause: params });
26
+ }
27
+ }
28
+ export function Parts(kind) {
29
+ return async function* (payload, { taskId, contextId }) {
30
+ const parts = (Array.isArray(payload) ? payload : [payload]).map((part) => messagePart({ kind, part }));
31
+ yield describe.update.working({
32
+ taskId,
33
+ contextId,
34
+ message: describe.message({ role: "agent", parts }),
35
+ });
36
+ return;
37
+ };
38
+ }
39
+ export function Message() {
40
+ return async function* (payload, { taskId, contextId }) {
41
+ if (Array.isArray(payload)) {
42
+ throw new Error("Array of messages is not supported");
43
+ }
44
+ const message = typeof payload === "string" ? describe.message(payload) : payload;
45
+ yield describe.message({
46
+ ...message,
47
+ taskId,
48
+ contextId,
49
+ });
50
+ return;
51
+ };
52
+ }
53
+ export function Artifact() {
54
+ return async function* (payload, { taskId, contextId }) {
55
+ const updates = Array.isArray(payload) ? payload : [payload];
56
+ for (const update of updates) {
57
+ const artifact = typeof update === "string" ? describe.artifact(update) : update;
58
+ yield describe.update.artifact({
59
+ ...artifact,
60
+ taskId,
61
+ contextId,
62
+ });
63
+ }
64
+ return;
65
+ };
66
+ }
67
+ export function Status() {
68
+ return async function* (payload, { taskId, contextId }) {
69
+ const updates = Array.isArray(payload) ? payload : [payload];
70
+ for (const update of updates) {
71
+ const status = typeof update === "string" ? TaskStatus.create(update) : update;
72
+ yield describe.update.status({
73
+ ...status,
74
+ taskId,
75
+ contextId,
76
+ });
77
+ }
78
+ return;
79
+ };
80
+ }
81
+ export function Task() {
82
+ return async function* (payload, { taskId, contextId }) {
83
+ if (Array.isArray(payload)) {
84
+ throw new Error("Array of tasks is not supported");
85
+ }
86
+ const task = typeof payload === "string" ? describe.task(payload) : payload;
87
+ yield describe.task({ ...task, taskId, contextId });
88
+ return;
89
+ };
90
+ }
91
+ export async function* Reply(ret, context, transform) {
92
+ if (Array.isArray(ret)) {
93
+ yield* transform(ret, context);
94
+ }
95
+ else if (hasCarry(ret)) {
96
+ yield* transform(ret.reply, context);
97
+ return ret.args;
98
+ }
99
+ else if (hasReply(ret)) {
100
+ yield* transform(ret.reply, context);
101
+ }
102
+ else {
103
+ yield* transform(ret, context);
104
+ }
105
+ return;
106
+ }
package/dist/index.d.ts CHANGED
@@ -6,3 +6,5 @@ export * from "./transport/index.js";
6
6
  export * from "./utils/index.js";
7
7
  export * from "./config/index.js";
8
8
  export * from "./config/default.js";
9
+ export * from "./create/create.js";
10
+ export * from "./create/index.js";
package/dist/index.js CHANGED
@@ -6,3 +6,5 @@ export * from "./transport/index.js";
6
6
  export * from "./utils/index.js";
7
7
  export * from "./config/index.js";
8
8
  export * from "./config/default.js";
9
+ export * from "./create/create.js";
10
+ export * from "./create/index.js";
@@ -2,9 +2,10 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { SystemError, INTERNAL_ERROR } from "../../utils/index.js";
5
+ import { SystemError } from "../../utils/index.js";
6
6
  import { logger } from "../../config/index.js";
7
7
  import escapeHtml from "escape-html";
8
+ import { A2AError } from "@a2a-js/sdk/server";
8
9
  /**
9
10
  * Express error handler middleware.
10
11
  */
@@ -24,16 +25,11 @@ export const errorHandler = (err, req, res, _) => {
24
25
  logger.error("errorHandler: Error extracting request ID", e);
25
26
  }
26
27
  let jsonRpcError;
27
- if (err instanceof SystemError) {
28
+ if (err instanceof A2AError || err instanceof SystemError) {
28
29
  jsonRpcError = { code: err.code, message: err.message, data: err.data };
29
30
  }
30
31
  else {
31
- const internalError = INTERNAL_ERROR(err.stack);
32
- jsonRpcError = {
33
- code: internalError.code,
34
- message: internalError.message,
35
- data: internalError.data,
36
- };
32
+ jsonRpcError = A2AError.internalError(err.message, err.data).toJSONRPCError();
37
33
  }
38
34
  const errorResponse = {
39
35
  jsonrpc: "2.0",
@@ -2,9 +2,9 @@
2
2
  * Copyright 2025 The Artinet Project
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
- import { A2A } from "../../types/index.js";
6
- import { PUSH_NOTIFICATION_NOT_SUPPORTED, INVALID_REQUEST, INVALID_PARAMS, METHOD_NOT_FOUND, AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED, } from "../../utils/index.js";
7
5
  import { logger } from "../../config/index.js";
6
+ import { formatJson } from "../../utils/common/utils.js";
7
+ import { A2AError } from "@a2a-js/sdk/server";
8
8
  const isValidMethod = (method) => {
9
9
  return (method &&
10
10
  method !== "" &&
@@ -14,41 +14,35 @@ const isValidMethod = (method) => {
14
14
  };
15
15
  const checkParams = (params, method) => {
16
16
  if (!params || (typeof params !== "object" && !Array.isArray(params))) {
17
- throw INVALID_PARAMS({
18
- data: {
19
- message: "Invalid params",
20
- method,
21
- },
17
+ throw A2AError.invalidParams("Invalid Parameters", {
18
+ params,
19
+ method,
22
20
  });
23
21
  }
24
22
  else if (typeof params === "object" && Object.keys(params).length === 0) {
25
- throw INVALID_PARAMS({
26
- data: {
27
- message: "No params provided",
28
- method,
29
- },
23
+ throw A2AError.invalidParams("Params Required", {
24
+ params,
25
+ method,
30
26
  });
31
27
  }
32
28
  };
33
29
  export async function jsonRPCMiddleware(service, req, res, next, extendedAgentCard) {
34
30
  const { method, params, id, jsonrpc } = req.body;
35
31
  if (jsonrpc !== "2.0" ||
36
- (id && typeof id !== "string" && typeof id !== "number" && id !== null)) {
32
+ (typeof id !== "string" &&
33
+ typeof id === "number" &&
34
+ !Number.isInteger(id) &&
35
+ id !== null)) {
37
36
  res.json({
38
37
  jsonrpc: "2.0",
39
38
  id: id || null,
40
- error: { code: A2A.ErrorCodeInvalidRequest, message: "Invalid Request" },
39
+ error: A2AError.invalidRequest(`Invalid JSONRPC info: ${formatJson({ method, params, id, jsonrpc })}`).toJSONRPCError(),
41
40
  });
42
41
  return;
43
42
  }
44
43
  try {
45
44
  if (!isValidMethod(method)) {
46
- throw INVALID_REQUEST({
47
- data: {
48
- message: "No method provided",
49
- method,
50
- },
51
- });
45
+ throw A2AError.invalidRequest("No method provided");
52
46
  }
53
47
  let result;
54
48
  switch (method) {
@@ -101,34 +95,19 @@ export async function jsonRPCMiddleware(service, req, res, next, extendedAgentCa
101
95
  case "tasks/pushNotificationConfig/get":
102
96
  case "tasks/pushNotificationConfig/delete":
103
97
  case "task/pushNotificationConfig/list": {
104
- throw PUSH_NOTIFICATION_NOT_SUPPORTED({
105
- data: {
106
- message: "Push notifications not supported",
107
- method,
108
- },
109
- });
98
+ throw A2AError.pushNotificationNotSupported();
110
99
  }
111
100
  case "agent/getAuthenticatedExtendedCard": {
112
101
  if (!extendedAgentCard ||
113
102
  (await service.getAgentCard()).supportsAuthenticatedExtendedCard !==
114
103
  true) {
115
- throw AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED({
116
- data: {
117
- message: "Authenticated Extended Card is not configured",
118
- method,
119
- },
120
- });
104
+ throw A2AError.authenticatedExtendedCardNotConfigured();
121
105
  }
122
106
  result = extendedAgentCard;
123
107
  break;
124
108
  }
125
109
  default:
126
- throw METHOD_NOT_FOUND({
127
- data: {
128
- message: "Method not found",
129
- method,
130
- },
131
- });
110
+ throw A2AError.methodNotFound(method);
132
111
  }
133
112
  res.json({ jsonrpc: "2.0", id, result });
134
113
  }
@@ -11,14 +11,19 @@ export interface ServerParams {
11
11
  app?: express.Express;
12
12
  corsOptions?: CorsOptions;
13
13
  basePath?: string;
14
+ port?: number;
15
+ /**
16
+ * Your agentCard must have supportsAuthenticatedExtendedCard set to true
17
+ */
14
18
  extendedAgentCard?: A2A.AgentCard;
15
19
  agent: Agent | CreateAgentParams;
16
20
  agentCardPath?: string;
17
21
  register?: boolean;
18
22
  }
19
23
  export declare function rpcParser(req: express.Request, res: express.Response, next: express.NextFunction): void;
20
- export declare function createAgentServer({ app, basePath, agentCardPath, agent, corsOptions, extendedAgentCard, }: ServerParams): {
24
+ export declare function createAgentServer({ app, basePath, agentCardPath, agent, corsOptions, extendedAgentCard, register, port, }: ServerParams): {
21
25
  app: express.Express;
22
26
  agent: Agent;
27
+ start: (_port?: number) => import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse>;
23
28
  };
24
29
  export type ExpressAgentServer = ReturnType<typeof createAgentServer>;