@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,251 @@
1
+ /**
2
+ * Copyright 2025 The Artinet Project
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { A2A } from "../types/index.js";
6
+ import { type MessageParams } from "./message-builder.js";
7
+ import { Kindless } from "./base.js";
8
+ export type BaseArtifactParams = Partial<Kindless<A2A.Artifact>>;
9
+ export type ArtifactParams = BaseArtifactParams | string;
10
+ export declare const isArtifactParams: (params: any) => params is ArtifactParams;
11
+ export declare class Artifact {
12
+ private readonly _artifact;
13
+ constructor(artifact_params?: Partial<A2A.Artifact>);
14
+ get artifact(): A2A.Artifact;
15
+ static create(params?: ArtifactParams): A2A.Artifact;
16
+ }
17
+ export declare const artifact: typeof Artifact.create;
18
+ export type StatusParams = Partial<Kindless<A2A.TaskStatus>> | A2A.TaskState | MessageParams;
19
+ export declare const isStatusParams: (params: any) => params is StatusParams;
20
+ export declare class TaskStatus {
21
+ private readonly _status;
22
+ constructor(params?: Partial<A2A.TaskStatus>);
23
+ get status(): A2A.TaskStatus;
24
+ static create(params?: StatusParams): A2A.TaskStatus;
25
+ }
26
+ /**
27
+ * Convenience factory function for creating a task status with default parameters.
28
+ *
29
+ * @returns New {@link A2A.TaskStatus} with default parameters
30
+ * @defaults {
31
+ * state: "working",
32
+ * timestamp: getCurrentTimestamp(),
33
+ * }
34
+ *
35
+ * @example
36
+ * ```typescript
37
+ * const status = status("working");
38
+ * ```
39
+ *
40
+ * @public
41
+ * @since 0.6.0
42
+ */
43
+ export declare const status: typeof TaskStatus.create;
44
+ export type TaskParams = Partial<Kindless<A2A.Task>> | StatusParams;
45
+ export declare class Task {
46
+ private readonly _task;
47
+ constructor(params?: Partial<Kindless<A2A.Task>>);
48
+ get task(): A2A.Task;
49
+ static create(params?: TaskParams): A2A.Task;
50
+ }
51
+ /**
52
+ * Convenience factory function for creating a task with default parameters.
53
+ *
54
+ * @returns New {@link A2A.Task} with default parameters
55
+ * @defaults:
56
+ * - `id`: uuidv4()
57
+ * - `contextId`: id
58
+ * - `status`: { state: "working" }
59
+ * @example
60
+ * ```typescript
61
+ * const task = task({ status: { state: "working" } });
62
+ * ```
63
+ *
64
+ * @public
65
+ * @since 0.6.0
66
+ */
67
+ export declare const task: typeof Task.create;
68
+ export type StatusUpdateParams = (Partial<Kindless<A2A.TaskStatusUpdateEvent>> & {
69
+ status: StatusParams;
70
+ }) | StatusParams;
71
+ export declare class TaskStatusUpdateEvent {
72
+ private readonly _event;
73
+ constructor(params: Partial<Kindless<A2A.TaskStatusUpdateEvent>> & Required<Pick<Kindless<A2A.TaskStatusUpdateEvent>, "status">>);
74
+ get event(): A2A.TaskStatusUpdateEvent;
75
+ static create(params: StatusUpdateParams): A2A.TaskStatusUpdateEvent;
76
+ }
77
+ export type ArtifactUpdateParams = (Partial<Kindless<A2A.TaskArtifactUpdateEvent>> & {
78
+ artifact: ArtifactParams;
79
+ }) | ArtifactParams;
80
+ export declare class TaskArtifactUpdateEvent {
81
+ private readonly _event;
82
+ constructor(params: Partial<Kindless<A2A.TaskArtifactUpdateEvent>> & Required<Pick<Kindless<A2A.TaskArtifactUpdateEvent>, "artifact">>);
83
+ get event(): A2A.TaskArtifactUpdateEvent;
84
+ static create(params: ArtifactUpdateParams): A2A.TaskArtifactUpdateEvent;
85
+ }
86
+ type StrictUpdateParams = Partial<Kindless<A2A.TaskStatusUpdateEvent>> & Required<Pick<Kindless<A2A.TaskStatusUpdateEvent>, "taskId" | "contextId" | "status">>;
87
+ export type BuildStatusParams = Omit<StrictUpdateParams, "status"> & Omit<A2A.TaskStatus, "state">;
88
+ declare function _working(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
89
+ declare function _canceled(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
90
+ declare function _submitted(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
91
+ declare function _failed(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
92
+ declare function _completed(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
93
+ declare function _inputRequired(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
94
+ declare function _rejected(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
95
+ declare function _authRequired(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
96
+ declare function _unknown(params: BuildStatusParams): A2A.TaskStatusUpdateEvent;
97
+ /**
98
+ * Convenience factory function for creating a task status and artifact update events with default parameters.
99
+ *
100
+ * @returns New {@link A2A.TaskStatusUpdateEvent} and {@link A2A.TaskArtifactUpdateEvent} with default parameters
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * const artifactEvent = update.artifact({
105
+ * artifact: "result"
106
+ * });
107
+ * const statusEvent = update.status({
108
+ * status: "working"
109
+ * });
110
+ * ```
111
+ *
112
+ * @public
113
+ * @since 0.6.0
114
+ */
115
+ export declare const update: {
116
+ /**
117
+ * Convenience factory function for creating a task artifact update event.
118
+ * @returns New {@link A2A.TaskArtifactUpdateEvent}
119
+ * @example
120
+ * ```typescript
121
+ * const event = update.artifact({
122
+ * artifact: "result"
123
+ * });
124
+ * ```
125
+ */
126
+ artifact: typeof TaskArtifactUpdateEvent.create;
127
+ /**
128
+ * Convenience factory function for creating a task status update event.
129
+ * @returns New {@link A2A.TaskStatusUpdateEvent}
130
+ * @example
131
+ * ```typescript
132
+ * const event = update.status({
133
+ * message: "Working on the task"
134
+ * });
135
+ * ```
136
+ */
137
+ status: typeof TaskStatusUpdateEvent.create;
138
+ /**
139
+ * Convenience factory function for creating a task status update event with the working state.
140
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.working} state
141
+ * @example
142
+ * ```typescript
143
+ * const event = update.working({
144
+ * message: "Working on the task"
145
+ * });
146
+ * ```
147
+ */
148
+ working: typeof _working;
149
+ /**
150
+ * Convenience factory function for creating a task status update event with the canceled state.
151
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.canceled} state
152
+ * @example
153
+ * ```typescript
154
+ * const event = update.canceled({
155
+ * message: "Task canceled"
156
+ * });
157
+ * ```
158
+ */
159
+ canceled: typeof _canceled;
160
+ /**
161
+ * Convenience factory function for creating a task status update event with the submitted state.
162
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.submitted} state
163
+ * @example
164
+ * ```typescript
165
+ * const event = update.submitted({
166
+ * message: "Task submitted"
167
+ * });
168
+ * ```
169
+ */
170
+ submitted: typeof _submitted;
171
+ /**
172
+ * Convenience factory function for creating a task status update event with the failed state.
173
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.failed} state
174
+ * @example
175
+ * ```typescript
176
+ * const event = update.failed({
177
+ * message: "Task failed"
178
+ * });
179
+ * ```
180
+ */
181
+ failed: typeof _failed;
182
+ /**
183
+ * Convenience factory function for creating a task status update event with the completed state.
184
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.completed} state
185
+ * @example
186
+ * ```typescript
187
+ * const event = update.completed({
188
+ * message: "Task completed"
189
+ * });
190
+ * ```
191
+ */
192
+ completed: typeof _completed;
193
+ /**
194
+ * Convenience factory function for creating a task status update event with the input required state.
195
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState["input-required"]} state
196
+ * @example
197
+ * ```typescript
198
+ * const event = update.inputRequired({
199
+ * message: "Task input required"
200
+ * });
201
+ * ```
202
+ */
203
+ inputRequired: typeof _inputRequired;
204
+ /**
205
+ * Convenience factory function for creating a task status update event with the rejected state.
206
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.rejected} state
207
+ * @example
208
+ * ```typescript
209
+ * const event = update.rejected({
210
+ * message: "Task rejected"
211
+ * });
212
+ * ```
213
+ */
214
+ rejected: typeof _rejected;
215
+ /**
216
+ * Convenience factory function for creating a task status update event with the auth required state.
217
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState["auth-required"]} state
218
+ * @example
219
+ * ```typescript
220
+ * const event = update.authRequired({
221
+ * message: {
222
+ * role: "agent"
223
+ * parts: [
224
+ * {
225
+ * text: "Task auth required"
226
+ * }
227
+ * ]
228
+ * kind: "message"
229
+ * });
230
+ * ```
231
+ */
232
+ authRequired: typeof _authRequired;
233
+ /**
234
+ * Convenience factory function for creating a task status update event with the unknown state.
235
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.unknown} state
236
+ * @example
237
+ * ```typescript
238
+ * const event = update.unknown({
239
+ * message: "Task unknown"
240
+ * });
241
+ * ```
242
+ */
243
+ unknown: typeof _unknown;
244
+ };
245
+ /**
246
+ * @description A temporary compatibility function for updating a task status, purely for migration purposes.
247
+ * @deprecated Use {@link update.status} instead
248
+ * @since 0.6.0
249
+ */
250
+ export declare const update_compat: (taskId: string, contextId: string, state: A2A.TaskState, message?: A2A.Message, timestamp?: string, final?: boolean) => A2A.TaskStatusUpdateEvent;
251
+ export {};
@@ -0,0 +1,379 @@
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
+ constructor(artifact_params = {}) {
17
+ this._artifact = {
18
+ artifactId: uuidv4(),
19
+ parts: [],
20
+ ...artifact_params,
21
+ };
22
+ }
23
+ get artifact() {
24
+ return this._artifact;
25
+ }
26
+ static create(params = {}) {
27
+ return new Artifact(typeof params === "string"
28
+ ? { parts: [{ text: params, kind: "text" }] }
29
+ : params).artifact;
30
+ }
31
+ }
32
+ export const artifact = Artifact.create;
33
+ export const isStatusParams = (params) => {
34
+ return (typeof params === "string" ||
35
+ (typeof params === "object" &&
36
+ params !== null &&
37
+ "state" in params &&
38
+ params.state in A2A.TaskState) ||
39
+ (typeof params === "object" &&
40
+ params !== null &&
41
+ "message" in params &&
42
+ isMessageParams(params.message)));
43
+ };
44
+ export class TaskStatus {
45
+ constructor(params = {}) {
46
+ const timestamp = params.timestamp ?? getCurrentTimestamp();
47
+ this._status = {
48
+ ...params,
49
+ state: params.state ?? A2A.TaskState.working,
50
+ timestamp,
51
+ };
52
+ }
53
+ get status() {
54
+ return this._status;
55
+ }
56
+ static create(params = {}) {
57
+ if (typeof params === "string" && params in A2A.TaskState) {
58
+ return new TaskStatus({ state: params }).status;
59
+ }
60
+ else if (isMessageParams(params)) {
61
+ return new TaskStatus({
62
+ state: A2A.TaskState.working,
63
+ message: Message.create(params),
64
+ }).status;
65
+ }
66
+ return new TaskStatus(params).status;
67
+ }
68
+ }
69
+ /**
70
+ * Convenience factory function for creating a task status with default parameters.
71
+ *
72
+ * @returns New {@link A2A.TaskStatus} with default parameters
73
+ * @defaults {
74
+ * state: "working",
75
+ * timestamp: getCurrentTimestamp(),
76
+ * }
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const status = status("working");
81
+ * ```
82
+ *
83
+ * @public
84
+ * @since 0.6.0
85
+ */
86
+ export const status = TaskStatus.create;
87
+ export class Task {
88
+ constructor(params = {}) {
89
+ const id = params.id ?? uuidv4();
90
+ this._task = {
91
+ ...params,
92
+ id,
93
+ contextId: params.contextId ?? id,
94
+ kind: A2A.Kind.task,
95
+ status: TaskStatus.create(params.status),
96
+ };
97
+ }
98
+ get task() {
99
+ return this._task;
100
+ }
101
+ static create(params = {}) {
102
+ if (isStatusParams(params)) {
103
+ return new Task({ status: TaskStatus.create(params) }).task;
104
+ }
105
+ return new Task(params).task;
106
+ }
107
+ }
108
+ /**
109
+ * Convenience factory function for creating a task with default parameters.
110
+ *
111
+ * @returns New {@link A2A.Task} with default parameters
112
+ * @defaults:
113
+ * - `id`: uuidv4()
114
+ * - `contextId`: id
115
+ * - `status`: { state: "working" }
116
+ * @example
117
+ * ```typescript
118
+ * const task = task({ status: { state: "working" } });
119
+ * ```
120
+ *
121
+ * @public
122
+ * @since 0.6.0
123
+ */
124
+ export const task = Task.create;
125
+ export class TaskStatusUpdateEvent {
126
+ constructor(params) {
127
+ const taskId = params.taskId ?? params.status.message?.taskId ?? uuidv4();
128
+ const contextId = params.contextId ?? params.status.message?.contextId ?? taskId;
129
+ this._event = {
130
+ ...params,
131
+ taskId,
132
+ contextId,
133
+ kind: A2A.Kind["status-update"],
134
+ final: params.final ?? false,
135
+ };
136
+ }
137
+ get event() {
138
+ return this._event;
139
+ }
140
+ static create(params) {
141
+ if (isStatusParams(params)) {
142
+ return new TaskStatusUpdateEvent({
143
+ /*allows for a mixture of Update & Status Params*/
144
+ ...(typeof params === "object" ? params : {}),
145
+ status: TaskStatus.create(params),
146
+ }).event;
147
+ }
148
+ return new TaskStatusUpdateEvent(params).event;
149
+ }
150
+ }
151
+ export class TaskArtifactUpdateEvent {
152
+ constructor(params) {
153
+ const taskId = params.taskId ?? uuidv4();
154
+ this._event = {
155
+ ...params,
156
+ taskId,
157
+ contextId: params.contextId ?? taskId,
158
+ kind: A2A.Kind["artifact-update"],
159
+ };
160
+ }
161
+ get event() {
162
+ return this._event;
163
+ }
164
+ static create(params) {
165
+ if (isArtifactParams(params)) {
166
+ return new TaskArtifactUpdateEvent({
167
+ artifact: Artifact.create(params),
168
+ }).event;
169
+ }
170
+ return new TaskArtifactUpdateEvent({
171
+ ...params,
172
+ artifact: Artifact.create(params.artifact),
173
+ }).event;
174
+ }
175
+ }
176
+ const strict_update = (params) => {
177
+ return TaskStatusUpdateEvent.create(params);
178
+ };
179
+ function _buildUpdate(state, params, final) {
180
+ return strict_update({
181
+ taskId: params.taskId,
182
+ contextId: params.contextId,
183
+ status: {
184
+ state: state,
185
+ message: params.message,
186
+ timestamp: params.timestamp,
187
+ },
188
+ final: final ?? params.final,
189
+ metadata: params.metadata,
190
+ });
191
+ }
192
+ function _working(params) {
193
+ return _buildUpdate(A2A.TaskState.working, params);
194
+ }
195
+ function _canceled(params) {
196
+ return _buildUpdate(A2A.TaskState.canceled, params, true);
197
+ }
198
+ function _submitted(params) {
199
+ return _buildUpdate(A2A.TaskState.submitted, params);
200
+ }
201
+ function _failed(params) {
202
+ return _buildUpdate(A2A.TaskState.failed, params, true);
203
+ }
204
+ function _completed(params) {
205
+ return _buildUpdate(A2A.TaskState.completed, params, true);
206
+ }
207
+ function _inputRequired(params) {
208
+ return _buildUpdate(A2A.TaskState["input-required"], params);
209
+ }
210
+ function _rejected(params) {
211
+ return _buildUpdate(A2A.TaskState.rejected, params);
212
+ }
213
+ function _authRequired(params) {
214
+ return _buildUpdate(A2A.TaskState["auth-required"], params);
215
+ }
216
+ function _unknown(params) {
217
+ return _buildUpdate(A2A.TaskState["unknown"], params);
218
+ }
219
+ /**
220
+ * Convenience factory function for creating a task status and artifact update events with default parameters.
221
+ *
222
+ * @returns New {@link A2A.TaskStatusUpdateEvent} and {@link A2A.TaskArtifactUpdateEvent} with default parameters
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * const artifactEvent = update.artifact({
227
+ * artifact: "result"
228
+ * });
229
+ * const statusEvent = update.status({
230
+ * status: "working"
231
+ * });
232
+ * ```
233
+ *
234
+ * @public
235
+ * @since 0.6.0
236
+ */
237
+ export const update = {
238
+ /**
239
+ * Convenience factory function for creating a task artifact update event.
240
+ * @returns New {@link A2A.TaskArtifactUpdateEvent}
241
+ * @example
242
+ * ```typescript
243
+ * const event = update.artifact({
244
+ * artifact: "result"
245
+ * });
246
+ * ```
247
+ */
248
+ artifact: TaskArtifactUpdateEvent.create,
249
+ /**
250
+ * Convenience factory function for creating a task status update event.
251
+ * @returns New {@link A2A.TaskStatusUpdateEvent}
252
+ * @example
253
+ * ```typescript
254
+ * const event = update.status({
255
+ * message: "Working on the task"
256
+ * });
257
+ * ```
258
+ */
259
+ status: TaskStatusUpdateEvent.create,
260
+ /**
261
+ * Convenience factory function for creating a task status update event with the working state.
262
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.working} state
263
+ * @example
264
+ * ```typescript
265
+ * const event = update.working({
266
+ * message: "Working on the task"
267
+ * });
268
+ * ```
269
+ */
270
+ working: _working,
271
+ /**
272
+ * Convenience factory function for creating a task status update event with the canceled state.
273
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.canceled} state
274
+ * @example
275
+ * ```typescript
276
+ * const event = update.canceled({
277
+ * message: "Task canceled"
278
+ * });
279
+ * ```
280
+ */
281
+ canceled: _canceled,
282
+ /**
283
+ * Convenience factory function for creating a task status update event with the submitted state.
284
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.submitted} state
285
+ * @example
286
+ * ```typescript
287
+ * const event = update.submitted({
288
+ * message: "Task submitted"
289
+ * });
290
+ * ```
291
+ */
292
+ submitted: _submitted,
293
+ /**
294
+ * Convenience factory function for creating a task status update event with the failed state.
295
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.failed} state
296
+ * @example
297
+ * ```typescript
298
+ * const event = update.failed({
299
+ * message: "Task failed"
300
+ * });
301
+ * ```
302
+ */
303
+ failed: _failed,
304
+ /**
305
+ * Convenience factory function for creating a task status update event with the completed state.
306
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.completed} state
307
+ * @example
308
+ * ```typescript
309
+ * const event = update.completed({
310
+ * message: "Task completed"
311
+ * });
312
+ * ```
313
+ */
314
+ completed: _completed,
315
+ /**
316
+ * Convenience factory function for creating a task status update event with the input required state.
317
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState["input-required"]} state
318
+ * @example
319
+ * ```typescript
320
+ * const event = update.inputRequired({
321
+ * message: "Task input required"
322
+ * });
323
+ * ```
324
+ */
325
+ inputRequired: _inputRequired,
326
+ /**
327
+ * Convenience factory function for creating a task status update event with the rejected state.
328
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.rejected} state
329
+ * @example
330
+ * ```typescript
331
+ * const event = update.rejected({
332
+ * message: "Task rejected"
333
+ * });
334
+ * ```
335
+ */
336
+ rejected: _rejected,
337
+ /**
338
+ * Convenience factory function for creating a task status update event with the auth required state.
339
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState["auth-required"]} state
340
+ * @example
341
+ * ```typescript
342
+ * const event = update.authRequired({
343
+ * message: {
344
+ * role: "agent"
345
+ * parts: [
346
+ * {
347
+ * text: "Task auth required"
348
+ * }
349
+ * ]
350
+ * kind: "message"
351
+ * });
352
+ * ```
353
+ */
354
+ authRequired: _authRequired,
355
+ /**
356
+ * Convenience factory function for creating a task status update event with the unknown state.
357
+ * @returns New {@link A2A.TaskStatusUpdateEvent} with the {@link A2A.TaskState.unknown} state
358
+ * @example
359
+ * ```typescript
360
+ * const event = update.unknown({
361
+ * message: "Task unknown"
362
+ * });
363
+ * ```
364
+ */
365
+ unknown: _unknown,
366
+ };
367
+ /**
368
+ * @description A temporary compatibility function for updating a task status, purely for migration purposes.
369
+ * @deprecated Use {@link update.status} instead
370
+ * @since 0.6.0
371
+ */
372
+ export const update_compat = (taskId, contextId, state, message, timestamp, final = false) => {
373
+ return _buildUpdate(state, {
374
+ taskId: taskId,
375
+ contextId: contextId,
376
+ message: message,
377
+ timestamp: timestamp,
378
+ }, final);
379
+ };
@@ -12,4 +12,4 @@ import { MCP } from "../../types/index.js";
12
12
  * @returns The parsed and validated response object
13
13
  * @throws A2AError if the response contains an error or is invalid
14
14
  */
15
- export declare function parseResponse<Res extends MCP.JSONRPCResponse | MCP.JSONRPCError>(data: string): Res;
15
+ export declare function parseResponse<Res extends MCP.JSONRPCResponse | MCP.JSONRPCErrorResponse>(data: string): Res;
@@ -21,7 +21,8 @@ export function parseResponse(data) {
21
21
  try {
22
22
  const parsed = JSON.parse(data); //todo: leverage safe parse
23
23
  if (parsed.error) {
24
- const parsedError = MCP.JSONRPCErrorSchema.safeParse(parsed);
24
+ //MCP Error defs may be a wee bit restrictive
25
+ const parsedError = MCP.JSONRPCErrorResponseSchema.safeParse(parsed);
25
26
  if (!parsedError.success) {
26
27
  throw PARSE_ERROR(parsedError.error);
27
28
  }
@@ -256,10 +256,14 @@ export declare const UpdateSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
256
256
  lastChunk: z.ZodOptional<z.ZodBoolean>;
257
257
  metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
258
258
  }, z.core.$strip>]>;
259
- export type Update = z.infer<typeof UpdateSchema>;
259
+ export type Update = z.output<typeof UpdateSchema>;
260
260
  export type Engine = (context: Context) => AsyncGenerator<Update, void, unknown>;
261
261
  export interface BaseContext extends core.Context<Task> {
262
262
  readonly service: Service;
263
+ /**
264
+ * Considering ommit OnStart & OnComplete from Context consumers.
265
+ * That way the user cannot inadvertently trigger a start/completion out of band.
266
+ */
263
267
  readonly publisher: EventPublisher;
264
268
  }
265
269
  export interface Context extends BaseContext {
@@ -270,9 +274,9 @@ export interface Context extends BaseContext {
270
274
  references?: Task[];
271
275
  getTask: () => Promise<Task>;
272
276
  }
273
- export type ContextParams = Omit<BaseContext, "publisher" | "isCancelled" | "getState" | "abortSignal"> & Omit<Partial<Context>, "userMessage"> & {
277
+ export type ContextParams = Omit<BaseContext, "publisher" | "isCancelled" | "getState" | "abortSignal"> & Omit<Partial<Context>, "userMessage" | "taskId"> & {
274
278
  messenger: MessageConsumerProxy;
275
- task?: Task;
279
+ task: Task;
276
280
  overrides?: Partial<Omit<EventConsumer, "contextId">>;
277
281
  abortSignal?: AbortSignal;
278
282
  };
@@ -1,3 +1,5 @@
1
- export * from "./builder.js";
2
1
  export * as A2A from "./a2a.js";
2
+ /**
3
+ * @deprecated Use {@link A2A.Engine} instead.
4
+ */
3
5
  export type { Engine as AgentEngine } from "./a2a.js";
@@ -1,2 +1 @@
1
- export * from "./builder.js";
2
1
  export * as A2A from "./a2a.js";
@@ -3,9 +3,4 @@
3
3
  * SPDX-License-Identifier: Apache-2.0
4
4
  */
5
5
  import { A2A } from "../../types/index.js";
6
- export declare const STATUS_UPDATE: (taskId: string, contextId: string, status: A2A.TaskState, message?: A2A.Message, timestamp?: string, final?: boolean) => A2A.TaskStatusUpdateEvent;
7
- export declare const WORKING_UPDATE: (taskId: string, contextId: string, message?: A2A.Message, timestamp?: string) => A2A.TaskStatusUpdateEvent;
8
- export declare const CANCEL_UPDATE: (taskId: string, contextId: string, message?: A2A.Message, timestamp?: string) => A2A.TaskStatusUpdateEvent;
9
- export declare const SUBMITTED_UPDATE: (taskId: string, contextId: string, message?: A2A.Message, timestamp?: string) => A2A.TaskStatusUpdateEvent;
10
- export declare const FAILED_UPDATE_EVENT: (taskId: string, contextId: string, message?: A2A.Message, timestamp?: string) => A2A.TaskStatusUpdateEvent;
11
6
  export declare const FINAL_STATES: A2A.TaskState[];