recoder-a2a-sdk 1.0.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 (59) hide show
  1. package/dist/audit-helpers.d.mts +209 -0
  2. package/dist/audit-helpers.d.ts +209 -0
  3. package/dist/audit-helpers.js +905 -0
  4. package/dist/audit-helpers.js.map +1 -0
  5. package/dist/audit-helpers.mjs +34 -0
  6. package/dist/audit-helpers.mjs.map +1 -0
  7. package/dist/chunk-7GY5FFBI.mjs +117 -0
  8. package/dist/chunk-7GY5FFBI.mjs.map +1 -0
  9. package/dist/chunk-AGD6G5N6.mjs +141 -0
  10. package/dist/chunk-AGD6G5N6.mjs.map +1 -0
  11. package/dist/chunk-BWCRJDUB.mjs +357 -0
  12. package/dist/chunk-BWCRJDUB.mjs.map +1 -0
  13. package/dist/chunk-DPFH2JIC.mjs +141 -0
  14. package/dist/chunk-DPFH2JIC.mjs.map +1 -0
  15. package/dist/chunk-EP2GHC3R.mjs +116 -0
  16. package/dist/chunk-EP2GHC3R.mjs.map +1 -0
  17. package/dist/chunk-JOZQDX7A.mjs +359 -0
  18. package/dist/chunk-JOZQDX7A.mjs.map +1 -0
  19. package/dist/chunk-MAA7JZ2Q.mjs +142 -0
  20. package/dist/chunk-MAA7JZ2Q.mjs.map +1 -0
  21. package/dist/chunk-QVOOBAUA.mjs +140 -0
  22. package/dist/chunk-QVOOBAUA.mjs.map +1 -0
  23. package/dist/chunk-T5GUBIFZ.mjs +358 -0
  24. package/dist/chunk-T5GUBIFZ.mjs.map +1 -0
  25. package/dist/chunk-WLNW7Y2H.mjs +636 -0
  26. package/dist/chunk-WLNW7Y2H.mjs.map +1 -0
  27. package/dist/chunk-XSELW6DU.mjs +356 -0
  28. package/dist/chunk-XSELW6DU.mjs.map +1 -0
  29. package/dist/envelope-builders.d.mts +189 -0
  30. package/dist/envelope-builders.d.ts +189 -0
  31. package/dist/envelope-builders.js +652 -0
  32. package/dist/envelope-builders.js.map +1 -0
  33. package/dist/envelope-builders.mjs +20 -0
  34. package/dist/envelope-builders.mjs.map +1 -0
  35. package/dist/error-mapping.d.mts +132 -0
  36. package/dist/error-mapping.d.ts +132 -0
  37. package/dist/error-mapping.js +642 -0
  38. package/dist/error-mapping.js.map +1 -0
  39. package/dist/error-mapping.mjs +16 -0
  40. package/dist/error-mapping.mjs.map +1 -0
  41. package/dist/index.d.mts +7 -0
  42. package/dist/index.d.ts +7 -0
  43. package/dist/index.js +1798 -0
  44. package/dist/index.js.map +1 -0
  45. package/dist/index.mjs +153 -0
  46. package/dist/index.mjs.map +1 -0
  47. package/dist/state-mapping.d.mts +139 -0
  48. package/dist/state-mapping.d.ts +139 -0
  49. package/dist/state-mapping.js +641 -0
  50. package/dist/state-mapping.js.map +1 -0
  51. package/dist/state-mapping.mjs +28 -0
  52. package/dist/state-mapping.mjs.map +1 -0
  53. package/dist/validation.d.mts +117 -0
  54. package/dist/validation.d.ts +117 -0
  55. package/dist/validation.js +850 -0
  56. package/dist/validation.js.map +1 -0
  57. package/dist/validation.mjs +22 -0
  58. package/dist/validation.mjs.map +1 -0
  59. package/package.json +18 -0
@@ -0,0 +1,850 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/validation.ts
21
+ var validation_exports = {};
22
+ __export(validation_exports, {
23
+ assertAuditEvent: () => assertAuditEvent,
24
+ assertTaskEnvelope: () => assertTaskEnvelope,
25
+ isValidA2AError: () => isValidA2AError,
26
+ isValidAuditEvent: () => isValidAuditEvent,
27
+ isValidTaskEnvelope: () => isValidTaskEnvelope,
28
+ validateA2AError: () => validateA2AError,
29
+ validateAuditEvent: () => validateAuditEvent,
30
+ validateTaskEnvelope: () => validateTaskEnvelope
31
+ });
32
+ module.exports = __toCommonJS(validation_exports);
33
+
34
+ // ../../shared/src/a2a/schemas/task-envelope.ts
35
+ var TASK_ENVELOPE_VERSION = "1.0.0";
36
+ var TaskStateEnum = {
37
+ /** Task has been created and is awaiting execution. */
38
+ Submitted: "submitted",
39
+ /** Task is actively being processed by the assignee agent. */
40
+ Working: "working",
41
+ /** The assignee needs additional input before it can continue. */
42
+ InputRequired: "input-required",
43
+ /** Task finished successfully. */
44
+ Completed: "completed",
45
+ /** Task terminated with an error. */
46
+ Failed: "failed",
47
+ /** Task was explicitly cancelled by a requester or operator. */
48
+ Cancelled: "cancelled"
49
+ };
50
+ var TASK_STATES = [
51
+ TaskStateEnum.Submitted,
52
+ TaskStateEnum.Working,
53
+ TaskStateEnum.InputRequired,
54
+ TaskStateEnum.Completed,
55
+ TaskStateEnum.Failed,
56
+ TaskStateEnum.Cancelled
57
+ ];
58
+ var TERMINAL_TASK_STATES = /* @__PURE__ */ new Set([
59
+ TaskStateEnum.Completed,
60
+ TaskStateEnum.Failed,
61
+ TaskStateEnum.Cancelled
62
+ ]);
63
+ var ALLOWED_STATE_TRANSITIONS = {
64
+ [TaskStateEnum.Submitted]: [TaskStateEnum.Working, TaskStateEnum.Cancelled, TaskStateEnum.Failed],
65
+ [TaskStateEnum.Working]: [
66
+ TaskStateEnum.Completed,
67
+ TaskStateEnum.Failed,
68
+ TaskStateEnum.Cancelled,
69
+ TaskStateEnum.InputRequired
70
+ ],
71
+ [TaskStateEnum.InputRequired]: [TaskStateEnum.Working, TaskStateEnum.Cancelled, TaskStateEnum.Failed],
72
+ [TaskStateEnum.Completed]: [],
73
+ [TaskStateEnum.Failed]: [],
74
+ [TaskStateEnum.Cancelled]: []
75
+ };
76
+
77
+ // ../../shared/src/a2a/schemas/audit-event.ts
78
+ var AUDIT_EVENT_VERSION = "1.0.0";
79
+ var AuditEventTypeEnum = {
80
+ // -- task lifecycle ---------------------------------------------------------
81
+ /** A new task was submitted. */
82
+ TaskSubmitted: "task.submitted",
83
+ /** Task execution started. */
84
+ TaskStarted: "task.started",
85
+ /** Task made progress (intermediate update). */
86
+ TaskProgress: "task.progress",
87
+ /** Assignee agent needs additional input. */
88
+ TaskInputRequired: "task.input_required",
89
+ /** Task completed successfully. */
90
+ TaskCompleted: "task.completed",
91
+ /** Task failed with an error. */
92
+ TaskFailed: "task.failed",
93
+ /** Task was cancelled. */
94
+ TaskCancelled: "task.cancelled",
95
+ // -- policy decisions -------------------------------------------------------
96
+ /** A policy check was performed. */
97
+ PolicyChecked: "policy.checked",
98
+ /** A policy action was approved (auto or prompt). */
99
+ PolicyApproved: "policy.approved",
100
+ /** A policy action was denied. */
101
+ PolicyDenied: "policy.denied",
102
+ // -- connector events -------------------------------------------------------
103
+ /** A connector was attached to an agent. */
104
+ ConnectorAttached: "connector.attached",
105
+ /** A connector was detached from an agent. */
106
+ ConnectorDetached: "connector.detached",
107
+ /** A connector emitted a diagnostic or health event. */
108
+ ConnectorHealth: "connector.health",
109
+ /** A connector encountered an error. */
110
+ ConnectorError: "connector.error",
111
+ // -- agent registry ---------------------------------------------------------
112
+ /** An agent was registered. */
113
+ AgentRegistered: "agent.registered",
114
+ /** An agent was unregistered. */
115
+ AgentUnregistered: "agent.unregistered",
116
+ /** An agent's capabilities were updated. */
117
+ AgentUpdated: "agent.updated",
118
+ // -- collaboration ----------------------------------------------------------
119
+ /** A collaboration channel was created. */
120
+ ChannelCreated: "collaboration.channel_created",
121
+ /** A collaboration thread was created. */
122
+ ThreadCreated: "collaboration.thread_created",
123
+ /** A message was sent in a collaboration thread. */
124
+ MessageSent: "collaboration.message_sent",
125
+ // -- system -----------------------------------------------------------------
126
+ /** A system-level configuration change. */
127
+ SystemConfig: "system.config",
128
+ /** A system-level error or warning. */
129
+ SystemError: "system.error"
130
+ };
131
+ var AUDIT_EVENT_TYPES = Object.values(AuditEventTypeEnum);
132
+
133
+ // ../../shared/src/a2a/schemas/error-taxonomy.ts
134
+ var A2AErrorSeverityEnum = {
135
+ /** Low impact -- informational or gracefully handled. */
136
+ Low: "low",
137
+ /** Medium impact -- degraded functionality but system continues. */
138
+ Medium: "medium",
139
+ /** High impact -- a key operation failed and needs attention. */
140
+ High: "high",
141
+ /** Critical -- system stability at risk, immediate action required. */
142
+ Critical: "critical"
143
+ };
144
+ var A2AErrorCategoryEnum = {
145
+ /** Errors in the envelope or message format (validation, parsing). */
146
+ Envelope: "envelope",
147
+ /** Errors in the connector/adapter layer. */
148
+ Connector: "connector",
149
+ /** Errors in the policy/approval plane. */
150
+ Policy: "policy",
151
+ /** Errors in the task orchestration layer. */
152
+ Task: "task",
153
+ /** Errors in the agent registry. */
154
+ Registry: "registry",
155
+ /** Errors in the collaboration service. */
156
+ Collaboration: "collaboration",
157
+ /** Transport/network-level errors. */
158
+ Transport: "transport",
159
+ /** Authentication and authorization errors. */
160
+ Auth: "auth",
161
+ /** Rate-limiting and quota errors. */
162
+ RateLimit: "rate_limit",
163
+ /** Internal / unexpected errors. */
164
+ Internal: "internal"
165
+ };
166
+ var A2AErrorCodeEnum = {
167
+ // -- envelope ---------------------------------------------------------------
168
+ /** The envelope failed structural validation. */
169
+ InvalidEnvelope: "INVALID_ENVELOPE",
170
+ /** The envelope version is unsupported. */
171
+ UnsupportedEnvelopeVersion: "UNSUPPORTED_ENVELOPE_VERSION",
172
+ /** A required field is missing from the envelope. */
173
+ MissingEnvelopeField: "MISSING_ENVELOPE_FIELD",
174
+ /** The payload kind is unknown or malformed. */
175
+ InvalidPayload: "INVALID_PAYLOAD",
176
+ /** Compatibility alias used by older gateway/workspace routes. */
177
+ InvalidParams: "INVALID_ENVELOPE",
178
+ // -- connector --------------------------------------------------------------
179
+ /** No connector is attached for the target agent. */
180
+ ConnectorNotFound: "CONNECTOR_NOT_FOUND",
181
+ /** The connector timed out during task execution. */
182
+ ConnectorTimeout: "CONNECTOR_TIMEOUT",
183
+ /** The connector returned an unexpected error. */
184
+ ConnectorError: "CONNECTOR_ERROR",
185
+ /** The connector is temporarily unavailable. */
186
+ ConnectorUnavailable: "CONNECTOR_UNAVAILABLE",
187
+ /** Protocol mismatch between connector and remote agent. */
188
+ ProtocolMismatch: "PROTOCOL_MISMATCH",
189
+ // -- policy -----------------------------------------------------------------
190
+ /** The policy plane denied the requested action. */
191
+ PolicyDenied: "POLICY_DENIED",
192
+ /** No prompt handler is configured for the policy rule. */
193
+ PolicyHandlerMissing: "POLICY_HANDLER_MISSING",
194
+ /** The policy evaluation timed out. */
195
+ PolicyTimeout: "POLICY_TIMEOUT",
196
+ // -- task -------------------------------------------------------------------
197
+ /** The task was not found. */
198
+ TaskNotFound: "TASK_NOT_FOUND",
199
+ /** An invalid state transition was attempted. */
200
+ InvalidStateTransition: "INVALID_STATE_TRANSITION",
201
+ /** The task has already reached a terminal state. */
202
+ TaskAlreadyTerminal: "TASK_ALREADY_TERMINAL",
203
+ /** The task failed during execution. */
204
+ TaskExecutionFailed: "TASK_EXECUTION_FAILED",
205
+ /** The task was cancelled. */
206
+ TaskCancelled: "TASK_CANCELLED",
207
+ // -- registry ---------------------------------------------------------------
208
+ /** The agent was not found in the registry. */
209
+ AgentNotFound: "AGENT_NOT_FOUND",
210
+ /** The agent is already registered. */
211
+ AgentAlreadyRegistered: "AGENT_ALREADY_REGISTERED",
212
+ /** The agent does not have the requested capability. */
213
+ CapabilityNotFound: "CAPABILITY_NOT_FOUND",
214
+ // -- collaboration ----------------------------------------------------------
215
+ /** The channel was not found. */
216
+ ChannelNotFound: "CHANNEL_NOT_FOUND",
217
+ /** The thread was not found. */
218
+ ThreadNotFound: "THREAD_NOT_FOUND",
219
+ /** The message was not found. */
220
+ MessageNotFound: "MESSAGE_NOT_FOUND",
221
+ /** The sender is not a member of the target channel. */
222
+ NotChannelMember: "NOT_CHANNEL_MEMBER",
223
+ // -- transport --------------------------------------------------------------
224
+ /** A network request failed. */
225
+ NetworkError: "NETWORK_ERROR",
226
+ /** The remote endpoint returned an unexpected status. */
227
+ UnexpectedStatus: "UNEXPECTED_STATUS",
228
+ /** The request or response body could not be parsed. */
229
+ SerializationError: "SERIALIZATION_ERROR",
230
+ // -- auth -------------------------------------------------------------------
231
+ /** Authentication failed (invalid or missing credentials). */
232
+ AuthenticationFailed: "AUTHENTICATION_FAILED",
233
+ /** The caller is not authorized for the requested operation. */
234
+ AuthorizationDenied: "AUTHORIZATION_DENIED",
235
+ /** The access token has expired. */
236
+ TokenExpired: "TOKEN_EXPIRED",
237
+ // -- rate limit -------------------------------------------------------------
238
+ /** The caller has exceeded the rate limit. */
239
+ RateLimitExceeded: "RATE_LIMIT_EXCEEDED",
240
+ /** The caller has exceeded their usage quota. */
241
+ QuotaExceeded: "QUOTA_EXCEEDED",
242
+ // -- internal ---------------------------------------------------------------
243
+ /** An unexpected internal error occurred. */
244
+ InternalError: "INTERNAL_ERROR",
245
+ /** A configuration error was detected. */
246
+ ConfigurationError: "CONFIGURATION_ERROR"
247
+ };
248
+ var A2A_ERROR_CODE_REGISTRY = {
249
+ // envelope
250
+ [A2AErrorCodeEnum.InvalidEnvelope]: {
251
+ code: A2AErrorCodeEnum.InvalidEnvelope,
252
+ category: A2AErrorCategoryEnum.Envelope,
253
+ severity: A2AErrorSeverityEnum.Medium,
254
+ retryable: false,
255
+ description: "The envelope failed structural validation."
256
+ },
257
+ [A2AErrorCodeEnum.UnsupportedEnvelopeVersion]: {
258
+ code: A2AErrorCodeEnum.UnsupportedEnvelopeVersion,
259
+ category: A2AErrorCategoryEnum.Envelope,
260
+ severity: A2AErrorSeverityEnum.Medium,
261
+ retryable: false,
262
+ description: "The envelope version is not supported by this service."
263
+ },
264
+ [A2AErrorCodeEnum.MissingEnvelopeField]: {
265
+ code: A2AErrorCodeEnum.MissingEnvelopeField,
266
+ category: A2AErrorCategoryEnum.Envelope,
267
+ severity: A2AErrorSeverityEnum.Medium,
268
+ retryable: false,
269
+ description: "A required field is missing from the envelope."
270
+ },
271
+ [A2AErrorCodeEnum.InvalidPayload]: {
272
+ code: A2AErrorCodeEnum.InvalidPayload,
273
+ category: A2AErrorCategoryEnum.Envelope,
274
+ severity: A2AErrorSeverityEnum.Medium,
275
+ retryable: false,
276
+ description: "The payload kind is unknown or malformed."
277
+ },
278
+ // connector
279
+ [A2AErrorCodeEnum.ConnectorNotFound]: {
280
+ code: A2AErrorCodeEnum.ConnectorNotFound,
281
+ category: A2AErrorCategoryEnum.Connector,
282
+ severity: A2AErrorSeverityEnum.High,
283
+ retryable: false,
284
+ description: "No connector is attached for the target agent."
285
+ },
286
+ [A2AErrorCodeEnum.ConnectorTimeout]: {
287
+ code: A2AErrorCodeEnum.ConnectorTimeout,
288
+ category: A2AErrorCategoryEnum.Connector,
289
+ severity: A2AErrorSeverityEnum.High,
290
+ retryable: true,
291
+ description: "The connector timed out during task execution."
292
+ },
293
+ [A2AErrorCodeEnum.ConnectorError]: {
294
+ code: A2AErrorCodeEnum.ConnectorError,
295
+ category: A2AErrorCategoryEnum.Connector,
296
+ severity: A2AErrorSeverityEnum.High,
297
+ retryable: true,
298
+ description: "The connector returned an unexpected error."
299
+ },
300
+ [A2AErrorCodeEnum.ConnectorUnavailable]: {
301
+ code: A2AErrorCodeEnum.ConnectorUnavailable,
302
+ category: A2AErrorCategoryEnum.Connector,
303
+ severity: A2AErrorSeverityEnum.High,
304
+ retryable: true,
305
+ description: "The connector is temporarily unavailable."
306
+ },
307
+ [A2AErrorCodeEnum.ProtocolMismatch]: {
308
+ code: A2AErrorCodeEnum.ProtocolMismatch,
309
+ category: A2AErrorCategoryEnum.Connector,
310
+ severity: A2AErrorSeverityEnum.High,
311
+ retryable: false,
312
+ description: "Protocol mismatch between connector and remote agent."
313
+ },
314
+ // policy
315
+ [A2AErrorCodeEnum.PolicyDenied]: {
316
+ code: A2AErrorCodeEnum.PolicyDenied,
317
+ category: A2AErrorCategoryEnum.Policy,
318
+ severity: A2AErrorSeverityEnum.Medium,
319
+ retryable: false,
320
+ description: "The policy plane denied the requested action."
321
+ },
322
+ [A2AErrorCodeEnum.PolicyHandlerMissing]: {
323
+ code: A2AErrorCodeEnum.PolicyHandlerMissing,
324
+ category: A2AErrorCategoryEnum.Policy,
325
+ severity: A2AErrorSeverityEnum.Medium,
326
+ retryable: false,
327
+ description: "No prompt handler is configured for the policy rule."
328
+ },
329
+ [A2AErrorCodeEnum.PolicyTimeout]: {
330
+ code: A2AErrorCodeEnum.PolicyTimeout,
331
+ category: A2AErrorCategoryEnum.Policy,
332
+ severity: A2AErrorSeverityEnum.High,
333
+ retryable: true,
334
+ description: "The policy evaluation timed out."
335
+ },
336
+ // task
337
+ [A2AErrorCodeEnum.TaskNotFound]: {
338
+ code: A2AErrorCodeEnum.TaskNotFound,
339
+ category: A2AErrorCategoryEnum.Task,
340
+ severity: A2AErrorSeverityEnum.Medium,
341
+ retryable: false,
342
+ description: "The task was not found."
343
+ },
344
+ [A2AErrorCodeEnum.InvalidStateTransition]: {
345
+ code: A2AErrorCodeEnum.InvalidStateTransition,
346
+ category: A2AErrorCategoryEnum.Task,
347
+ severity: A2AErrorSeverityEnum.Medium,
348
+ retryable: false,
349
+ description: "An invalid state transition was attempted."
350
+ },
351
+ [A2AErrorCodeEnum.TaskAlreadyTerminal]: {
352
+ code: A2AErrorCodeEnum.TaskAlreadyTerminal,
353
+ category: A2AErrorCategoryEnum.Task,
354
+ severity: A2AErrorSeverityEnum.Low,
355
+ retryable: false,
356
+ description: "The task has already reached a terminal state."
357
+ },
358
+ [A2AErrorCodeEnum.TaskExecutionFailed]: {
359
+ code: A2AErrorCodeEnum.TaskExecutionFailed,
360
+ category: A2AErrorCategoryEnum.Task,
361
+ severity: A2AErrorSeverityEnum.High,
362
+ retryable: true,
363
+ description: "The task failed during execution."
364
+ },
365
+ [A2AErrorCodeEnum.TaskCancelled]: {
366
+ code: A2AErrorCodeEnum.TaskCancelled,
367
+ category: A2AErrorCategoryEnum.Task,
368
+ severity: A2AErrorSeverityEnum.Low,
369
+ retryable: false,
370
+ description: "The task was cancelled."
371
+ },
372
+ // registry
373
+ [A2AErrorCodeEnum.AgentNotFound]: {
374
+ code: A2AErrorCodeEnum.AgentNotFound,
375
+ category: A2AErrorCategoryEnum.Registry,
376
+ severity: A2AErrorSeverityEnum.Medium,
377
+ retryable: false,
378
+ description: "The agent was not found in the registry."
379
+ },
380
+ [A2AErrorCodeEnum.AgentAlreadyRegistered]: {
381
+ code: A2AErrorCodeEnum.AgentAlreadyRegistered,
382
+ category: A2AErrorCategoryEnum.Registry,
383
+ severity: A2AErrorSeverityEnum.Low,
384
+ retryable: false,
385
+ description: "The agent is already registered."
386
+ },
387
+ [A2AErrorCodeEnum.CapabilityNotFound]: {
388
+ code: A2AErrorCodeEnum.CapabilityNotFound,
389
+ category: A2AErrorCategoryEnum.Registry,
390
+ severity: A2AErrorSeverityEnum.Medium,
391
+ retryable: false,
392
+ description: "The agent does not have the requested capability."
393
+ },
394
+ // collaboration
395
+ [A2AErrorCodeEnum.ChannelNotFound]: {
396
+ code: A2AErrorCodeEnum.ChannelNotFound,
397
+ category: A2AErrorCategoryEnum.Collaboration,
398
+ severity: A2AErrorSeverityEnum.Medium,
399
+ retryable: false,
400
+ description: "The channel was not found."
401
+ },
402
+ [A2AErrorCodeEnum.ThreadNotFound]: {
403
+ code: A2AErrorCodeEnum.ThreadNotFound,
404
+ category: A2AErrorCategoryEnum.Collaboration,
405
+ severity: A2AErrorSeverityEnum.Medium,
406
+ retryable: false,
407
+ description: "The thread was not found."
408
+ },
409
+ [A2AErrorCodeEnum.MessageNotFound]: {
410
+ code: A2AErrorCodeEnum.MessageNotFound,
411
+ category: A2AErrorCategoryEnum.Collaboration,
412
+ severity: A2AErrorSeverityEnum.Medium,
413
+ retryable: false,
414
+ description: "The message was not found."
415
+ },
416
+ [A2AErrorCodeEnum.NotChannelMember]: {
417
+ code: A2AErrorCodeEnum.NotChannelMember,
418
+ category: A2AErrorCategoryEnum.Collaboration,
419
+ severity: A2AErrorSeverityEnum.Medium,
420
+ retryable: false,
421
+ description: "The sender is not a member of the target channel."
422
+ },
423
+ // transport
424
+ [A2AErrorCodeEnum.NetworkError]: {
425
+ code: A2AErrorCodeEnum.NetworkError,
426
+ category: A2AErrorCategoryEnum.Transport,
427
+ severity: A2AErrorSeverityEnum.High,
428
+ retryable: true,
429
+ description: "A network request failed."
430
+ },
431
+ [A2AErrorCodeEnum.UnexpectedStatus]: {
432
+ code: A2AErrorCodeEnum.UnexpectedStatus,
433
+ category: A2AErrorCategoryEnum.Transport,
434
+ severity: A2AErrorSeverityEnum.Medium,
435
+ retryable: true,
436
+ description: "The remote endpoint returned an unexpected status."
437
+ },
438
+ [A2AErrorCodeEnum.SerializationError]: {
439
+ code: A2AErrorCodeEnum.SerializationError,
440
+ category: A2AErrorCategoryEnum.Transport,
441
+ severity: A2AErrorSeverityEnum.Medium,
442
+ retryable: false,
443
+ description: "The request or response body could not be parsed."
444
+ },
445
+ // auth
446
+ [A2AErrorCodeEnum.AuthenticationFailed]: {
447
+ code: A2AErrorCodeEnum.AuthenticationFailed,
448
+ category: A2AErrorCategoryEnum.Auth,
449
+ severity: A2AErrorSeverityEnum.High,
450
+ retryable: false,
451
+ description: "Authentication failed (invalid or missing credentials)."
452
+ },
453
+ [A2AErrorCodeEnum.AuthorizationDenied]: {
454
+ code: A2AErrorCodeEnum.AuthorizationDenied,
455
+ category: A2AErrorCategoryEnum.Auth,
456
+ severity: A2AErrorSeverityEnum.Medium,
457
+ retryable: false,
458
+ description: "The caller is not authorized for the requested operation."
459
+ },
460
+ [A2AErrorCodeEnum.TokenExpired]: {
461
+ code: A2AErrorCodeEnum.TokenExpired,
462
+ category: A2AErrorCategoryEnum.Auth,
463
+ severity: A2AErrorSeverityEnum.Medium,
464
+ retryable: true,
465
+ description: "The access token has expired."
466
+ },
467
+ // rate limit
468
+ [A2AErrorCodeEnum.RateLimitExceeded]: {
469
+ code: A2AErrorCodeEnum.RateLimitExceeded,
470
+ category: A2AErrorCategoryEnum.RateLimit,
471
+ severity: A2AErrorSeverityEnum.Medium,
472
+ retryable: true,
473
+ description: "The caller has exceeded the rate limit."
474
+ },
475
+ [A2AErrorCodeEnum.QuotaExceeded]: {
476
+ code: A2AErrorCodeEnum.QuotaExceeded,
477
+ category: A2AErrorCategoryEnum.RateLimit,
478
+ severity: A2AErrorSeverityEnum.Medium,
479
+ retryable: false,
480
+ description: "The caller has exceeded their usage quota."
481
+ },
482
+ // internal
483
+ [A2AErrorCodeEnum.InternalError]: {
484
+ code: A2AErrorCodeEnum.InternalError,
485
+ category: A2AErrorCategoryEnum.Internal,
486
+ severity: A2AErrorSeverityEnum.Critical,
487
+ retryable: false,
488
+ description: "An unexpected internal error occurred."
489
+ },
490
+ [A2AErrorCodeEnum.ConfigurationError]: {
491
+ code: A2AErrorCodeEnum.ConfigurationError,
492
+ category: A2AErrorCategoryEnum.Internal,
493
+ severity: A2AErrorSeverityEnum.High,
494
+ retryable: false,
495
+ description: "A configuration error was detected."
496
+ }
497
+ };
498
+ function isA2AErrorCode(code) {
499
+ return code in A2A_ERROR_CODE_REGISTRY;
500
+ }
501
+
502
+ // src/validation.ts
503
+ function isRecord(value) {
504
+ return typeof value === "object" && value !== null && !Array.isArray(value);
505
+ }
506
+ function isNonEmptyString(value) {
507
+ return typeof value === "string" && value.trim().length > 0;
508
+ }
509
+ function isValidISODate(value) {
510
+ return typeof value === "string" && !Number.isNaN(Date.parse(value));
511
+ }
512
+ var VALID_PLATFORMS = /* @__PURE__ */ new Set([
513
+ "codex",
514
+ "claude_code",
515
+ "recoder_web",
516
+ "recoder_pm",
517
+ "recoder_agency",
518
+ "recoder_backend",
519
+ "recoder_desktop",
520
+ "custom"
521
+ ]);
522
+ var VALID_PROTOCOLS = /* @__PURE__ */ new Set(["a2a", "mcp", "jsonrpc", "rest", "file_git"]);
523
+ var VALID_TASK_STATES = new Set(TASK_STATES);
524
+ var VALID_AUDIT_EVENT_TYPES = new Set(AUDIT_EVENT_TYPES);
525
+ var VALID_ACTOR_KINDS = /* @__PURE__ */ new Set(["agent", "user", "system", "connector"]);
526
+ var VALID_TARGET_KINDS = /* @__PURE__ */ new Set([
527
+ "task",
528
+ "agent",
529
+ "connector",
530
+ "channel",
531
+ "thread",
532
+ "message",
533
+ "policy",
534
+ "workspace",
535
+ "system"
536
+ ]);
537
+ var VALID_SEVERITIES = /* @__PURE__ */ new Set(["low", "medium", "high", "critical"]);
538
+ var VALID_AUDIT_SEVERITIES = /* @__PURE__ */ new Set(["info", "warning", "error", "critical"]);
539
+ function validateAgentRef(value, path, issues) {
540
+ if (!isRecord(value)) {
541
+ issues.push({ path, message: "must be an object" });
542
+ return;
543
+ }
544
+ if (!isNonEmptyString(value.agent_id)) {
545
+ issues.push({ path: `${path}.agent_id`, message: "must be a non-empty string" });
546
+ }
547
+ if (!isNonEmptyString(value.platform) || !VALID_PLATFORMS.has(value.platform)) {
548
+ issues.push({
549
+ path: `${path}.platform`,
550
+ message: `must be one of: ${[...VALID_PLATFORMS].join(", ")}`
551
+ });
552
+ }
553
+ }
554
+ function validateConnectorInfo(value, path, issues) {
555
+ if (!isRecord(value)) {
556
+ issues.push({ path, message: "must be an object" });
557
+ return;
558
+ }
559
+ if (!isNonEmptyString(value.platform) || !VALID_PLATFORMS.has(value.platform)) {
560
+ issues.push({
561
+ path: `${path}.platform`,
562
+ message: `must be one of: ${[...VALID_PLATFORMS].join(", ")}`
563
+ });
564
+ }
565
+ if (!isNonEmptyString(value.protocol) || !VALID_PROTOCOLS.has(value.protocol)) {
566
+ issues.push({
567
+ path: `${path}.protocol`,
568
+ message: `must be one of: ${[...VALID_PROTOCOLS].join(", ")}`
569
+ });
570
+ }
571
+ if (!isNonEmptyString(value.connector_id)) {
572
+ issues.push({
573
+ path: `${path}.connector_id`,
574
+ message: "must be a non-empty string"
575
+ });
576
+ }
577
+ }
578
+ function validatePayloadItem(value, path, issues) {
579
+ if (!isRecord(value)) {
580
+ issues.push({ path, message: "must be an object" });
581
+ return;
582
+ }
583
+ const validKinds = /* @__PURE__ */ new Set(["text", "json", "command", "artifact"]);
584
+ if (!isNonEmptyString(value.kind) || !validKinds.has(value.kind)) {
585
+ issues.push({
586
+ path: `${path}.kind`,
587
+ message: `must be one of: ${[...validKinds].join(", ")}`
588
+ });
589
+ return;
590
+ }
591
+ switch (value.kind) {
592
+ case "text":
593
+ if (!isNonEmptyString(value.text)) {
594
+ issues.push({ path: `${path}.text`, message: "must be a non-empty string" });
595
+ }
596
+ break;
597
+ case "json":
598
+ if (!isRecord(value.data)) {
599
+ issues.push({ path: `${path}.data`, message: "must be an object" });
600
+ }
601
+ break;
602
+ case "command":
603
+ if (!isNonEmptyString(value.command)) {
604
+ issues.push({ path: `${path}.command`, message: "must be a non-empty string" });
605
+ }
606
+ break;
607
+ case "artifact":
608
+ if (!isNonEmptyString(value.mimeType) && !isNonEmptyString(value.mime_type)) {
609
+ issues.push({ path: `${path}.mimeType`, message: "must be a non-empty string" });
610
+ }
611
+ if (!isNonEmptyString(value.content)) {
612
+ issues.push({ path: `${path}.content`, message: "must be a non-empty string" });
613
+ }
614
+ break;
615
+ }
616
+ }
617
+ function validateTaskEnvelope(value, options) {
618
+ const issues = [];
619
+ if (!isRecord(value)) {
620
+ return { valid: false, issues: [{ path: "$", message: "must be an object" }] };
621
+ }
622
+ if (!isNonEmptyString(value.envelope_version)) {
623
+ issues.push({ path: "envelope_version", message: "must be a non-empty string" });
624
+ } else if (options?.strictVersion && value.envelope_version !== TASK_ENVELOPE_VERSION) {
625
+ issues.push({
626
+ path: "envelope_version",
627
+ message: `must equal "${TASK_ENVELOPE_VERSION}"`
628
+ });
629
+ }
630
+ if (!isNonEmptyString(value.id)) {
631
+ issues.push({ path: "id", message: "must be a non-empty string" });
632
+ }
633
+ if (!isNonEmptyString(value.workspace_id)) {
634
+ issues.push({ path: "workspace_id", message: "must be a non-empty string" });
635
+ }
636
+ if (!isNonEmptyString(value.thread_id)) {
637
+ issues.push({ path: "thread_id", message: "must be a non-empty string" });
638
+ }
639
+ if (!isNonEmptyString(value.trace_id)) {
640
+ issues.push({ path: "trace_id", message: "must be a non-empty string" });
641
+ }
642
+ if (!isNonEmptyString(value.state) || !VALID_TASK_STATES.has(value.state)) {
643
+ issues.push({
644
+ path: "state",
645
+ message: `must be one of: ${[...VALID_TASK_STATES].join(", ")}`
646
+ });
647
+ }
648
+ validateAgentRef(value.requester, "requester", issues);
649
+ validateAgentRef(value.assignee, "assignee", issues);
650
+ validateConnectorInfo(value.connector, "connector", issues);
651
+ if (value.payload === void 0 || value.payload === null) {
652
+ issues.push({ path: "payload", message: "is required" });
653
+ } else if (Array.isArray(value.payload)) {
654
+ value.payload.forEach(
655
+ (item, i) => validatePayloadItem(item, `payload[${i}]`, issues)
656
+ );
657
+ } else {
658
+ validatePayloadItem(value.payload, "payload", issues);
659
+ }
660
+ if (!isValidISODate(value.created_at)) {
661
+ issues.push({ path: "created_at", message: "must be a valid ISO-8601 timestamp" });
662
+ }
663
+ if (!isValidISODate(value.updated_at)) {
664
+ issues.push({ path: "updated_at", message: "must be a valid ISO-8601 timestamp" });
665
+ }
666
+ if (value.error !== void 0) {
667
+ if (!isRecord(value.error)) {
668
+ issues.push({ path: "error", message: "must be an object when present" });
669
+ } else {
670
+ if (!isNonEmptyString(value.error.code)) {
671
+ issues.push({ path: "error.code", message: "must be a non-empty string" });
672
+ }
673
+ if (!isNonEmptyString(value.error.category)) {
674
+ issues.push({ path: "error.category", message: "must be a non-empty string" });
675
+ }
676
+ if (!isNonEmptyString(value.error.message)) {
677
+ issues.push({ path: "error.message", message: "must be a non-empty string" });
678
+ }
679
+ if (!isNonEmptyString(value.error.severity) || !VALID_SEVERITIES.has(value.error.severity)) {
680
+ issues.push({
681
+ path: "error.severity",
682
+ message: `must be one of: ${[...VALID_SEVERITIES].join(", ")}`
683
+ });
684
+ }
685
+ if (typeof value.error.retryable !== "boolean") {
686
+ issues.push({ path: "error.retryable", message: "must be a boolean" });
687
+ }
688
+ }
689
+ }
690
+ return { valid: issues.length === 0, issues };
691
+ }
692
+ function isValidTaskEnvelope(value) {
693
+ return validateTaskEnvelope(value).valid;
694
+ }
695
+ function assertTaskEnvelope(value) {
696
+ const result = validateTaskEnvelope(value);
697
+ if (!result.valid) {
698
+ const summary = result.issues.map((i) => ` ${i.path}: ${i.message}`).join("\n");
699
+ throw new Error(`Invalid TaskEnvelope:
700
+ ${summary}`);
701
+ }
702
+ }
703
+ function validateAuditActor(value, path, issues) {
704
+ if (!isRecord(value)) {
705
+ issues.push({ path, message: "must be an object" });
706
+ return;
707
+ }
708
+ if (!isNonEmptyString(value.kind) || !VALID_ACTOR_KINDS.has(value.kind)) {
709
+ issues.push({
710
+ path: `${path}.kind`,
711
+ message: `must be one of: ${[...VALID_ACTOR_KINDS].join(", ")}`
712
+ });
713
+ }
714
+ if (!isNonEmptyString(value.id)) {
715
+ issues.push({ path: `${path}.id`, message: "must be a non-empty string" });
716
+ }
717
+ }
718
+ function validateAuditTarget(value, path, issues) {
719
+ if (!isRecord(value)) {
720
+ issues.push({ path, message: "must be an object" });
721
+ return;
722
+ }
723
+ if (!isNonEmptyString(value.kind) || !VALID_TARGET_KINDS.has(value.kind)) {
724
+ issues.push({
725
+ path: `${path}.kind`,
726
+ message: `must be one of: ${[...VALID_TARGET_KINDS].join(", ")}`
727
+ });
728
+ }
729
+ if (!isNonEmptyString(value.id)) {
730
+ issues.push({ path: `${path}.id`, message: "must be a non-empty string" });
731
+ }
732
+ }
733
+ function validateAuditEvent(value, options) {
734
+ const issues = [];
735
+ if (!isRecord(value)) {
736
+ return { valid: false, issues: [{ path: "$", message: "must be an object" }] };
737
+ }
738
+ if (!isNonEmptyString(value.schema_version)) {
739
+ issues.push({ path: "schema_version", message: "must be a non-empty string" });
740
+ } else if (options?.strictVersion && value.schema_version !== AUDIT_EVENT_VERSION) {
741
+ issues.push({
742
+ path: "schema_version",
743
+ message: `must equal "${AUDIT_EVENT_VERSION}"`
744
+ });
745
+ }
746
+ if (!isNonEmptyString(value.id)) {
747
+ issues.push({ path: "id", message: "must be a non-empty string" });
748
+ }
749
+ if (!isNonEmptyString(value.event_type) || !VALID_AUDIT_EVENT_TYPES.has(value.event_type)) {
750
+ issues.push({
751
+ path: "event_type",
752
+ message: `must be one of the canonical audit event types`
753
+ });
754
+ }
755
+ if (value.severity !== void 0 && (!isNonEmptyString(value.severity) || !VALID_AUDIT_SEVERITIES.has(value.severity))) {
756
+ issues.push({
757
+ path: "severity",
758
+ message: `must be one of: ${[...VALID_AUDIT_SEVERITIES].join(", ")}`
759
+ });
760
+ }
761
+ validateAuditActor(value.actor, "actor", issues);
762
+ validateAuditTarget(value.target, "target", issues);
763
+ if (!isNonEmptyString(value.trace_id)) {
764
+ issues.push({ path: "trace_id", message: "must be a non-empty string" });
765
+ }
766
+ if (!isNonEmptyString(value.workspace_id)) {
767
+ issues.push({ path: "workspace_id", message: "must be a non-empty string" });
768
+ }
769
+ if (!isValidISODate(value.timestamp)) {
770
+ issues.push({ path: "timestamp", message: "must be a valid ISO-8601 timestamp" });
771
+ }
772
+ if (value.policy !== void 0) {
773
+ if (!isRecord(value.policy)) {
774
+ issues.push({ path: "policy", message: "must be an object when present" });
775
+ } else {
776
+ if (!isNonEmptyString(value.policy.action)) {
777
+ issues.push({ path: "policy.action", message: "must be a non-empty string" });
778
+ }
779
+ if (!isNonEmptyString(value.policy.rule)) {
780
+ issues.push({ path: "policy.rule", message: "must be a non-empty string" });
781
+ }
782
+ if (typeof value.policy.approved !== "boolean") {
783
+ issues.push({ path: "policy.approved", message: "must be a boolean" });
784
+ }
785
+ if (!isNonEmptyString(value.policy.reason)) {
786
+ issues.push({ path: "policy.reason", message: "must be a non-empty string" });
787
+ }
788
+ if (!isNonEmptyString(value.policy.agent_id)) {
789
+ issues.push({ path: "policy.agent_id", message: "must be a non-empty string" });
790
+ }
791
+ }
792
+ }
793
+ return { valid: issues.length === 0, issues };
794
+ }
795
+ function isValidAuditEvent(value) {
796
+ return validateAuditEvent(value).valid;
797
+ }
798
+ function assertAuditEvent(value) {
799
+ const result = validateAuditEvent(value);
800
+ if (!result.valid) {
801
+ const summary = result.issues.map((i) => ` ${i.path}: ${i.message}`).join("\n");
802
+ throw new Error(`Invalid AuditEvent:
803
+ ${summary}`);
804
+ }
805
+ }
806
+ function validateA2AError(value) {
807
+ const issues = [];
808
+ if (!isRecord(value)) {
809
+ return { valid: false, issues: [{ path: "$", message: "must be an object" }] };
810
+ }
811
+ if (!isNonEmptyString(value.code)) {
812
+ issues.push({ path: "code", message: "must be a non-empty string" });
813
+ } else if (!isA2AErrorCode(value.code)) {
814
+ issues.push({
815
+ path: "code",
816
+ message: "must be a recognized A2A error code"
817
+ });
818
+ }
819
+ if (!isNonEmptyString(value.category)) {
820
+ issues.push({ path: "category", message: "must be a non-empty string" });
821
+ }
822
+ if (!isNonEmptyString(value.message)) {
823
+ issues.push({ path: "message", message: "must be a non-empty string" });
824
+ }
825
+ if (!isNonEmptyString(value.severity) || !VALID_SEVERITIES.has(value.severity)) {
826
+ issues.push({
827
+ path: "severity",
828
+ message: `must be one of: ${[...VALID_SEVERITIES].join(", ")}`
829
+ });
830
+ }
831
+ if (typeof value.retryable !== "boolean") {
832
+ issues.push({ path: "retryable", message: "must be a boolean" });
833
+ }
834
+ return { valid: issues.length === 0, issues };
835
+ }
836
+ function isValidA2AError(value) {
837
+ return validateA2AError(value).valid;
838
+ }
839
+ // Annotate the CommonJS export names for ESM import in node:
840
+ 0 && (module.exports = {
841
+ assertAuditEvent,
842
+ assertTaskEnvelope,
843
+ isValidA2AError,
844
+ isValidAuditEvent,
845
+ isValidTaskEnvelope,
846
+ validateA2AError,
847
+ validateAuditEvent,
848
+ validateTaskEnvelope
849
+ });
850
+ //# sourceMappingURL=validation.js.map