@a2a-js/sdk 0.3.6 → 0.3.8

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.
@@ -0,0 +1,2145 @@
1
+ import {
2
+ A2AError
3
+ } from "./chunk-UHZEIZLS.js";
4
+
5
+ // src/errors.ts
6
+ var A2A_ERROR_CODE = {
7
+ PARSE_ERROR: -32700,
8
+ INVALID_REQUEST: -32600,
9
+ METHOD_NOT_FOUND: -32601,
10
+ INVALID_PARAMS: -32602,
11
+ INTERNAL_ERROR: -32603,
12
+ TASK_NOT_FOUND: -32001,
13
+ TASK_NOT_CANCELABLE: -32002,
14
+ PUSH_NOTIFICATION_NOT_SUPPORTED: -32003,
15
+ UNSUPPORTED_OPERATION: -32004,
16
+ CONTENT_TYPE_NOT_SUPPORTED: -32005,
17
+ INVALID_AGENT_RESPONSE: -32006,
18
+ AUTHENTICATED_EXTENDED_CARD_NOT_CONFIGURED: -32007
19
+ };
20
+ var TaskNotFoundError = class extends Error {
21
+ constructor(message) {
22
+ super(message ?? "Task not found");
23
+ this.name = "TaskNotFoundError";
24
+ }
25
+ };
26
+ var TaskNotCancelableError = class extends Error {
27
+ constructor(message) {
28
+ super(message ?? "Task cannot be canceled");
29
+ this.name = "TaskNotCancelableError";
30
+ }
31
+ };
32
+ var PushNotificationNotSupportedError = class extends Error {
33
+ constructor(message) {
34
+ super(message ?? "Push Notification is not supported");
35
+ this.name = "PushNotificationNotSupportedError";
36
+ }
37
+ };
38
+ var UnsupportedOperationError = class extends Error {
39
+ constructor(message) {
40
+ super(message ?? "This operation is not supported");
41
+ this.name = "UnsupportedOperationError";
42
+ }
43
+ };
44
+ var ContentTypeNotSupportedError = class extends Error {
45
+ constructor(message) {
46
+ super(message ?? "Incompatible content types");
47
+ this.name = "ContentTypeNotSupportedError";
48
+ }
49
+ };
50
+ var InvalidAgentResponseError = class extends Error {
51
+ constructor(message) {
52
+ super(message ?? "Invalid agent response type");
53
+ this.name = "InvalidAgentResponseError";
54
+ }
55
+ };
56
+ var AuthenticatedExtendedCardNotConfiguredError = class extends Error {
57
+ constructor(message) {
58
+ super(message ?? "Authenticated Extended Card not configured");
59
+ this.name = "AuthenticatedExtendedCardNotConfiguredError";
60
+ }
61
+ };
62
+
63
+ // src/sse_utils.ts
64
+ var SSE_HEADERS = {
65
+ "Content-Type": "text/event-stream",
66
+ "Cache-Control": "no-cache",
67
+ Connection: "keep-alive",
68
+ "X-Accel-Buffering": "no"
69
+ // Disable buffering in nginx
70
+ };
71
+ function formatSSEEvent(event) {
72
+ return `data: ${JSON.stringify(event)}
73
+
74
+ `;
75
+ }
76
+ function formatSSEErrorEvent(error) {
77
+ return `event: error
78
+ data: ${JSON.stringify(error)}
79
+
80
+ `;
81
+ }
82
+ async function* parseSseStream(response) {
83
+ if (!response.body) {
84
+ throw new Error("SSE response body is undefined. Cannot read stream.");
85
+ }
86
+ let buffer = "";
87
+ let eventType = "message";
88
+ let eventData = "";
89
+ for await (const value of response.body.pipeThrough(new TextDecoderStream())) {
90
+ buffer += value;
91
+ let lineEndIndex;
92
+ while ((lineEndIndex = buffer.indexOf("\n")) >= 0) {
93
+ const line = buffer.substring(0, lineEndIndex).trim();
94
+ buffer = buffer.substring(lineEndIndex + 1);
95
+ if (line === "") {
96
+ if (eventData) {
97
+ yield { type: eventType, data: eventData };
98
+ eventData = "";
99
+ eventType = "message";
100
+ }
101
+ } else if (line.startsWith("event:")) {
102
+ eventType = line.substring("event:".length).trim();
103
+ } else if (line.startsWith("data:")) {
104
+ eventData = line.substring("data:".length).trim();
105
+ }
106
+ }
107
+ }
108
+ if (eventData) {
109
+ yield { type: eventType, data: eventData };
110
+ }
111
+ }
112
+
113
+ // src/types/pb/google/protobuf/timestamp.ts
114
+ var Timestamp = {
115
+ fromJSON(object) {
116
+ return {
117
+ seconds: isSet(object.seconds) ? globalThis.Number(object.seconds) : 0,
118
+ nanos: isSet(object.nanos) ? globalThis.Number(object.nanos) : 0
119
+ };
120
+ },
121
+ toJSON(message) {
122
+ const obj = {};
123
+ if (message.seconds !== 0) {
124
+ obj.seconds = Math.round(message.seconds);
125
+ }
126
+ if (message.nanos !== 0) {
127
+ obj.nanos = Math.round(message.nanos);
128
+ }
129
+ return obj;
130
+ }
131
+ };
132
+ function isSet(value) {
133
+ return value !== null && value !== void 0;
134
+ }
135
+
136
+ // src/types/pb/a2a.ts
137
+ function taskStateFromJSON(object) {
138
+ switch (object) {
139
+ case 0:
140
+ case "TASK_STATE_UNSPECIFIED":
141
+ return 0 /* TASK_STATE_UNSPECIFIED */;
142
+ case 1:
143
+ case "TASK_STATE_SUBMITTED":
144
+ return 1 /* TASK_STATE_SUBMITTED */;
145
+ case 2:
146
+ case "TASK_STATE_WORKING":
147
+ return 2 /* TASK_STATE_WORKING */;
148
+ case 3:
149
+ case "TASK_STATE_COMPLETED":
150
+ return 3 /* TASK_STATE_COMPLETED */;
151
+ case 4:
152
+ case "TASK_STATE_FAILED":
153
+ return 4 /* TASK_STATE_FAILED */;
154
+ case 5:
155
+ case "TASK_STATE_CANCELLED":
156
+ return 5 /* TASK_STATE_CANCELLED */;
157
+ case 6:
158
+ case "TASK_STATE_INPUT_REQUIRED":
159
+ return 6 /* TASK_STATE_INPUT_REQUIRED */;
160
+ case 7:
161
+ case "TASK_STATE_REJECTED":
162
+ return 7 /* TASK_STATE_REJECTED */;
163
+ case 8:
164
+ case "TASK_STATE_AUTH_REQUIRED":
165
+ return 8 /* TASK_STATE_AUTH_REQUIRED */;
166
+ case -1:
167
+ case "UNRECOGNIZED":
168
+ default:
169
+ return -1 /* UNRECOGNIZED */;
170
+ }
171
+ }
172
+ function taskStateToJSON(object) {
173
+ switch (object) {
174
+ case 0 /* TASK_STATE_UNSPECIFIED */:
175
+ return "TASK_STATE_UNSPECIFIED";
176
+ case 1 /* TASK_STATE_SUBMITTED */:
177
+ return "TASK_STATE_SUBMITTED";
178
+ case 2 /* TASK_STATE_WORKING */:
179
+ return "TASK_STATE_WORKING";
180
+ case 3 /* TASK_STATE_COMPLETED */:
181
+ return "TASK_STATE_COMPLETED";
182
+ case 4 /* TASK_STATE_FAILED */:
183
+ return "TASK_STATE_FAILED";
184
+ case 5 /* TASK_STATE_CANCELLED */:
185
+ return "TASK_STATE_CANCELLED";
186
+ case 6 /* TASK_STATE_INPUT_REQUIRED */:
187
+ return "TASK_STATE_INPUT_REQUIRED";
188
+ case 7 /* TASK_STATE_REJECTED */:
189
+ return "TASK_STATE_REJECTED";
190
+ case 8 /* TASK_STATE_AUTH_REQUIRED */:
191
+ return "TASK_STATE_AUTH_REQUIRED";
192
+ case -1 /* UNRECOGNIZED */:
193
+ default:
194
+ return "UNRECOGNIZED";
195
+ }
196
+ }
197
+ function roleFromJSON(object) {
198
+ switch (object) {
199
+ case 0:
200
+ case "ROLE_UNSPECIFIED":
201
+ return 0 /* ROLE_UNSPECIFIED */;
202
+ case 1:
203
+ case "ROLE_USER":
204
+ return 1 /* ROLE_USER */;
205
+ case 2:
206
+ case "ROLE_AGENT":
207
+ return 2 /* ROLE_AGENT */;
208
+ case -1:
209
+ case "UNRECOGNIZED":
210
+ default:
211
+ return -1 /* UNRECOGNIZED */;
212
+ }
213
+ }
214
+ function roleToJSON(object) {
215
+ switch (object) {
216
+ case 0 /* ROLE_UNSPECIFIED */:
217
+ return "ROLE_UNSPECIFIED";
218
+ case 1 /* ROLE_USER */:
219
+ return "ROLE_USER";
220
+ case 2 /* ROLE_AGENT */:
221
+ return "ROLE_AGENT";
222
+ case -1 /* UNRECOGNIZED */:
223
+ default:
224
+ return "UNRECOGNIZED";
225
+ }
226
+ }
227
+ var SendMessageConfiguration = {
228
+ fromJSON(object) {
229
+ return {
230
+ acceptedOutputModes: globalThis.Array.isArray(object?.acceptedOutputModes) ? object.acceptedOutputModes.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.accepted_output_modes) ? object.accepted_output_modes.map(
231
+ (e) => globalThis.String(e)
232
+ ) : [],
233
+ pushNotification: isSet2(object.pushNotification) ? PushNotificationConfig.fromJSON(object.pushNotification) : isSet2(object.push_notification) ? PushNotificationConfig.fromJSON(object.push_notification) : void 0,
234
+ historyLength: isSet2(object.historyLength) ? globalThis.Number(object.historyLength) : isSet2(object.history_length) ? globalThis.Number(object.history_length) : void 0,
235
+ blocking: isSet2(object.blocking) ? globalThis.Boolean(object.blocking) : void 0
236
+ };
237
+ },
238
+ toJSON(message) {
239
+ const obj = {};
240
+ if (message.acceptedOutputModes?.length) {
241
+ obj.acceptedOutputModes = message.acceptedOutputModes;
242
+ }
243
+ if (message.pushNotification !== void 0) {
244
+ obj.pushNotification = PushNotificationConfig.toJSON(message.pushNotification);
245
+ }
246
+ if (message.historyLength !== void 0) {
247
+ obj.historyLength = Math.round(message.historyLength);
248
+ }
249
+ if (message.blocking !== void 0) {
250
+ obj.blocking = message.blocking;
251
+ }
252
+ return obj;
253
+ }
254
+ };
255
+ var Task = {
256
+ fromJSON(object) {
257
+ return {
258
+ id: isSet2(object.id) ? globalThis.String(object.id) : void 0,
259
+ contextId: isSet2(object.contextId) ? globalThis.String(object.contextId) : isSet2(object.context_id) ? globalThis.String(object.context_id) : void 0,
260
+ status: isSet2(object.status) ? TaskStatus.fromJSON(object.status) : void 0,
261
+ artifacts: globalThis.Array.isArray(object?.artifacts) ? object.artifacts.map((e) => Artifact.fromJSON(e)) : [],
262
+ history: globalThis.Array.isArray(object?.history) ? object.history.map((e) => Message.fromJSON(e)) : [],
263
+ metadata: isObject(object.metadata) ? object.metadata : void 0
264
+ };
265
+ },
266
+ toJSON(message) {
267
+ const obj = {};
268
+ if (message.id !== void 0) {
269
+ obj.id = message.id;
270
+ }
271
+ if (message.contextId !== void 0) {
272
+ obj.contextId = message.contextId;
273
+ }
274
+ if (message.status !== void 0) {
275
+ obj.status = TaskStatus.toJSON(message.status);
276
+ }
277
+ if (message.artifacts?.length) {
278
+ obj.artifacts = message.artifacts.map((e) => Artifact.toJSON(e));
279
+ }
280
+ if (message.history?.length) {
281
+ obj.history = message.history.map((e) => Message.toJSON(e));
282
+ }
283
+ if (message.metadata !== void 0) {
284
+ obj.metadata = message.metadata;
285
+ }
286
+ return obj;
287
+ }
288
+ };
289
+ var TaskStatus = {
290
+ fromJSON(object) {
291
+ return {
292
+ state: isSet2(object.state) ? taskStateFromJSON(object.state) : void 0,
293
+ update: isSet2(object.message) ? Message.fromJSON(object.message) : isSet2(object.update) ? Message.fromJSON(object.update) : void 0,
294
+ timestamp: isSet2(object.timestamp) ? fromJsonTimestamp(object.timestamp) : void 0
295
+ };
296
+ },
297
+ toJSON(message) {
298
+ const obj = {};
299
+ if (message.state !== void 0) {
300
+ obj.state = taskStateToJSON(message.state);
301
+ }
302
+ if (message.update !== void 0) {
303
+ obj.message = Message.toJSON(message.update);
304
+ }
305
+ if (message.timestamp !== void 0) {
306
+ obj.timestamp = message.timestamp.toISOString();
307
+ }
308
+ return obj;
309
+ }
310
+ };
311
+ var Part = {
312
+ fromJSON(object) {
313
+ return {
314
+ part: isSet2(object.text) ? { $case: "text", value: globalThis.String(object.text) } : isSet2(object.file) ? { $case: "file", value: FilePart.fromJSON(object.file) } : isSet2(object.data) ? { $case: "data", value: DataPart.fromJSON(object.data) } : void 0
315
+ };
316
+ },
317
+ toJSON(message) {
318
+ const obj = {};
319
+ if (message.part?.$case === "text") {
320
+ obj.text = message.part.value;
321
+ } else if (message.part?.$case === "file") {
322
+ obj.file = FilePart.toJSON(message.part.value);
323
+ } else if (message.part?.$case === "data") {
324
+ obj.data = DataPart.toJSON(message.part.value);
325
+ }
326
+ return obj;
327
+ }
328
+ };
329
+ var FilePart = {
330
+ fromJSON(object) {
331
+ return {
332
+ file: isSet2(object.fileWithUri) ? { $case: "fileWithUri", value: globalThis.String(object.fileWithUri) } : isSet2(object.file_with_uri) ? { $case: "fileWithUri", value: globalThis.String(object.file_with_uri) } : isSet2(object.fileWithBytes) ? { $case: "fileWithBytes", value: Buffer.from(bytesFromBase64(object.fileWithBytes)) } : isSet2(object.file_with_bytes) ? { $case: "fileWithBytes", value: Buffer.from(bytesFromBase64(object.file_with_bytes)) } : void 0,
333
+ mimeType: isSet2(object.mimeType) ? globalThis.String(object.mimeType) : isSet2(object.mime_type) ? globalThis.String(object.mime_type) : void 0
334
+ };
335
+ },
336
+ toJSON(message) {
337
+ const obj = {};
338
+ if (message.file?.$case === "fileWithUri") {
339
+ obj.fileWithUri = message.file.value;
340
+ } else if (message.file?.$case === "fileWithBytes") {
341
+ obj.fileWithBytes = base64FromBytes(message.file.value);
342
+ }
343
+ if (message.mimeType !== void 0) {
344
+ obj.mimeType = message.mimeType;
345
+ }
346
+ return obj;
347
+ }
348
+ };
349
+ var DataPart = {
350
+ fromJSON(object) {
351
+ return { data: isObject(object.data) ? object.data : void 0 };
352
+ },
353
+ toJSON(message) {
354
+ const obj = {};
355
+ if (message.data !== void 0) {
356
+ obj.data = message.data;
357
+ }
358
+ return obj;
359
+ }
360
+ };
361
+ var Message = {
362
+ fromJSON(object) {
363
+ return {
364
+ messageId: isSet2(object.messageId) ? globalThis.String(object.messageId) : isSet2(object.message_id) ? globalThis.String(object.message_id) : void 0,
365
+ contextId: isSet2(object.contextId) ? globalThis.String(object.contextId) : isSet2(object.context_id) ? globalThis.String(object.context_id) : void 0,
366
+ taskId: isSet2(object.taskId) ? globalThis.String(object.taskId) : isSet2(object.task_id) ? globalThis.String(object.task_id) : void 0,
367
+ role: isSet2(object.role) ? roleFromJSON(object.role) : void 0,
368
+ content: globalThis.Array.isArray(object?.content) ? object.content.map((e) => Part.fromJSON(e)) : [],
369
+ metadata: isObject(object.metadata) ? object.metadata : void 0,
370
+ extensions: globalThis.Array.isArray(object?.extensions) ? object.extensions.map((e) => globalThis.String(e)) : []
371
+ };
372
+ },
373
+ toJSON(message) {
374
+ const obj = {};
375
+ if (message.messageId !== void 0) {
376
+ obj.messageId = message.messageId;
377
+ }
378
+ if (message.contextId !== void 0) {
379
+ obj.contextId = message.contextId;
380
+ }
381
+ if (message.taskId !== void 0) {
382
+ obj.taskId = message.taskId;
383
+ }
384
+ if (message.role !== void 0) {
385
+ obj.role = roleToJSON(message.role);
386
+ }
387
+ if (message.content?.length) {
388
+ obj.content = message.content.map((e) => Part.toJSON(e));
389
+ }
390
+ if (message.metadata !== void 0) {
391
+ obj.metadata = message.metadata;
392
+ }
393
+ if (message.extensions?.length) {
394
+ obj.extensions = message.extensions;
395
+ }
396
+ return obj;
397
+ }
398
+ };
399
+ var Artifact = {
400
+ fromJSON(object) {
401
+ return {
402
+ artifactId: isSet2(object.artifactId) ? globalThis.String(object.artifactId) : isSet2(object.artifact_id) ? globalThis.String(object.artifact_id) : void 0,
403
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0,
404
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
405
+ parts: globalThis.Array.isArray(object?.parts) ? object.parts.map((e) => Part.fromJSON(e)) : [],
406
+ metadata: isObject(object.metadata) ? object.metadata : void 0,
407
+ extensions: globalThis.Array.isArray(object?.extensions) ? object.extensions.map((e) => globalThis.String(e)) : []
408
+ };
409
+ },
410
+ toJSON(message) {
411
+ const obj = {};
412
+ if (message.artifactId !== void 0) {
413
+ obj.artifactId = message.artifactId;
414
+ }
415
+ if (message.name !== void 0) {
416
+ obj.name = message.name;
417
+ }
418
+ if (message.description !== void 0) {
419
+ obj.description = message.description;
420
+ }
421
+ if (message.parts?.length) {
422
+ obj.parts = message.parts.map((e) => Part.toJSON(e));
423
+ }
424
+ if (message.metadata !== void 0) {
425
+ obj.metadata = message.metadata;
426
+ }
427
+ if (message.extensions?.length) {
428
+ obj.extensions = message.extensions;
429
+ }
430
+ return obj;
431
+ }
432
+ };
433
+ var TaskStatusUpdateEvent = {
434
+ fromJSON(object) {
435
+ return {
436
+ taskId: isSet2(object.taskId) ? globalThis.String(object.taskId) : isSet2(object.task_id) ? globalThis.String(object.task_id) : void 0,
437
+ contextId: isSet2(object.contextId) ? globalThis.String(object.contextId) : isSet2(object.context_id) ? globalThis.String(object.context_id) : void 0,
438
+ status: isSet2(object.status) ? TaskStatus.fromJSON(object.status) : void 0,
439
+ final: isSet2(object.final) ? globalThis.Boolean(object.final) : void 0,
440
+ metadata: isObject(object.metadata) ? object.metadata : void 0
441
+ };
442
+ },
443
+ toJSON(message) {
444
+ const obj = {};
445
+ if (message.taskId !== void 0) {
446
+ obj.taskId = message.taskId;
447
+ }
448
+ if (message.contextId !== void 0) {
449
+ obj.contextId = message.contextId;
450
+ }
451
+ if (message.status !== void 0) {
452
+ obj.status = TaskStatus.toJSON(message.status);
453
+ }
454
+ if (message.final !== void 0) {
455
+ obj.final = message.final;
456
+ }
457
+ if (message.metadata !== void 0) {
458
+ obj.metadata = message.metadata;
459
+ }
460
+ return obj;
461
+ }
462
+ };
463
+ var TaskArtifactUpdateEvent = {
464
+ fromJSON(object) {
465
+ return {
466
+ taskId: isSet2(object.taskId) ? globalThis.String(object.taskId) : isSet2(object.task_id) ? globalThis.String(object.task_id) : void 0,
467
+ contextId: isSet2(object.contextId) ? globalThis.String(object.contextId) : isSet2(object.context_id) ? globalThis.String(object.context_id) : void 0,
468
+ artifact: isSet2(object.artifact) ? Artifact.fromJSON(object.artifact) : void 0,
469
+ append: isSet2(object.append) ? globalThis.Boolean(object.append) : void 0,
470
+ lastChunk: isSet2(object.lastChunk) ? globalThis.Boolean(object.lastChunk) : isSet2(object.last_chunk) ? globalThis.Boolean(object.last_chunk) : void 0,
471
+ metadata: isObject(object.metadata) ? object.metadata : void 0
472
+ };
473
+ },
474
+ toJSON(message) {
475
+ const obj = {};
476
+ if (message.taskId !== void 0) {
477
+ obj.taskId = message.taskId;
478
+ }
479
+ if (message.contextId !== void 0) {
480
+ obj.contextId = message.contextId;
481
+ }
482
+ if (message.artifact !== void 0) {
483
+ obj.artifact = Artifact.toJSON(message.artifact);
484
+ }
485
+ if (message.append !== void 0) {
486
+ obj.append = message.append;
487
+ }
488
+ if (message.lastChunk !== void 0) {
489
+ obj.lastChunk = message.lastChunk;
490
+ }
491
+ if (message.metadata !== void 0) {
492
+ obj.metadata = message.metadata;
493
+ }
494
+ return obj;
495
+ }
496
+ };
497
+ var PushNotificationConfig = {
498
+ fromJSON(object) {
499
+ return {
500
+ id: isSet2(object.id) ? globalThis.String(object.id) : void 0,
501
+ url: isSet2(object.url) ? globalThis.String(object.url) : void 0,
502
+ token: isSet2(object.token) ? globalThis.String(object.token) : void 0,
503
+ authentication: isSet2(object.authentication) ? AuthenticationInfo.fromJSON(object.authentication) : void 0
504
+ };
505
+ },
506
+ toJSON(message) {
507
+ const obj = {};
508
+ if (message.id !== void 0) {
509
+ obj.id = message.id;
510
+ }
511
+ if (message.url !== void 0) {
512
+ obj.url = message.url;
513
+ }
514
+ if (message.token !== void 0) {
515
+ obj.token = message.token;
516
+ }
517
+ if (message.authentication !== void 0) {
518
+ obj.authentication = AuthenticationInfo.toJSON(message.authentication);
519
+ }
520
+ return obj;
521
+ }
522
+ };
523
+ var AuthenticationInfo = {
524
+ fromJSON(object) {
525
+ return {
526
+ schemes: globalThis.Array.isArray(object?.schemes) ? object.schemes.map((e) => globalThis.String(e)) : [],
527
+ credentials: isSet2(object.credentials) ? globalThis.String(object.credentials) : void 0
528
+ };
529
+ },
530
+ toJSON(message) {
531
+ const obj = {};
532
+ if (message.schemes?.length) {
533
+ obj.schemes = message.schemes;
534
+ }
535
+ if (message.credentials !== void 0) {
536
+ obj.credentials = message.credentials;
537
+ }
538
+ return obj;
539
+ }
540
+ };
541
+ var AgentInterface = {
542
+ fromJSON(object) {
543
+ return {
544
+ url: isSet2(object.url) ? globalThis.String(object.url) : void 0,
545
+ transport: isSet2(object.transport) ? globalThis.String(object.transport) : void 0
546
+ };
547
+ },
548
+ toJSON(message) {
549
+ const obj = {};
550
+ if (message.url !== void 0) {
551
+ obj.url = message.url;
552
+ }
553
+ if (message.transport !== void 0) {
554
+ obj.transport = message.transport;
555
+ }
556
+ return obj;
557
+ }
558
+ };
559
+ var AgentCard = {
560
+ fromJSON(object) {
561
+ return {
562
+ protocolVersion: isSet2(object.protocolVersion) ? globalThis.String(object.protocolVersion) : isSet2(object.protocol_version) ? globalThis.String(object.protocol_version) : void 0,
563
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0,
564
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
565
+ url: isSet2(object.url) ? globalThis.String(object.url) : void 0,
566
+ preferredTransport: isSet2(object.preferredTransport) ? globalThis.String(object.preferredTransport) : isSet2(object.preferred_transport) ? globalThis.String(object.preferred_transport) : void 0,
567
+ additionalInterfaces: globalThis.Array.isArray(object?.additionalInterfaces) ? object.additionalInterfaces.map((e) => AgentInterface.fromJSON(e)) : globalThis.Array.isArray(object?.additional_interfaces) ? object.additional_interfaces.map((e) => AgentInterface.fromJSON(e)) : [],
568
+ provider: isSet2(object.provider) ? AgentProvider.fromJSON(object.provider) : void 0,
569
+ version: isSet2(object.version) ? globalThis.String(object.version) : void 0,
570
+ documentationUrl: isSet2(object.documentationUrl) ? globalThis.String(object.documentationUrl) : isSet2(object.documentation_url) ? globalThis.String(object.documentation_url) : void 0,
571
+ capabilities: isSet2(object.capabilities) ? AgentCapabilities.fromJSON(object.capabilities) : void 0,
572
+ securitySchemes: isObject(object.securitySchemes) ? globalThis.Object.entries(object.securitySchemes).reduce(
573
+ (acc, [key, value]) => {
574
+ acc[key] = SecurityScheme.fromJSON(value);
575
+ return acc;
576
+ },
577
+ {}
578
+ ) : isObject(object.security_schemes) ? globalThis.Object.entries(object.security_schemes).reduce(
579
+ (acc, [key, value]) => {
580
+ acc[key] = SecurityScheme.fromJSON(value);
581
+ return acc;
582
+ },
583
+ {}
584
+ ) : {},
585
+ security: globalThis.Array.isArray(object?.security) ? object.security.map((e) => Security.fromJSON(e)) : [],
586
+ defaultInputModes: globalThis.Array.isArray(object?.defaultInputModes) ? object.defaultInputModes.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.default_input_modes) ? object.default_input_modes.map((e) => globalThis.String(e)) : [],
587
+ defaultOutputModes: globalThis.Array.isArray(object?.defaultOutputModes) ? object.defaultOutputModes.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.default_output_modes) ? object.default_output_modes.map((e) => globalThis.String(e)) : [],
588
+ skills: globalThis.Array.isArray(object?.skills) ? object.skills.map((e) => AgentSkill.fromJSON(e)) : [],
589
+ supportsAuthenticatedExtendedCard: isSet2(object.supportsAuthenticatedExtendedCard) ? globalThis.Boolean(object.supportsAuthenticatedExtendedCard) : isSet2(object.supports_authenticated_extended_card) ? globalThis.Boolean(object.supports_authenticated_extended_card) : void 0,
590
+ signatures: globalThis.Array.isArray(object?.signatures) ? object.signatures.map((e) => AgentCardSignature.fromJSON(e)) : []
591
+ };
592
+ },
593
+ toJSON(message) {
594
+ const obj = {};
595
+ if (message.protocolVersion !== void 0) {
596
+ obj.protocolVersion = message.protocolVersion;
597
+ }
598
+ if (message.name !== void 0) {
599
+ obj.name = message.name;
600
+ }
601
+ if (message.description !== void 0) {
602
+ obj.description = message.description;
603
+ }
604
+ if (message.url !== void 0) {
605
+ obj.url = message.url;
606
+ }
607
+ if (message.preferredTransport !== void 0) {
608
+ obj.preferredTransport = message.preferredTransport;
609
+ }
610
+ if (message.additionalInterfaces?.length) {
611
+ obj.additionalInterfaces = message.additionalInterfaces.map((e) => AgentInterface.toJSON(e));
612
+ }
613
+ if (message.provider !== void 0) {
614
+ obj.provider = AgentProvider.toJSON(message.provider);
615
+ }
616
+ if (message.version !== void 0) {
617
+ obj.version = message.version;
618
+ }
619
+ if (message.documentationUrl !== void 0) {
620
+ obj.documentationUrl = message.documentationUrl;
621
+ }
622
+ if (message.capabilities !== void 0) {
623
+ obj.capabilities = AgentCapabilities.toJSON(message.capabilities);
624
+ }
625
+ if (message.securitySchemes) {
626
+ const entries = globalThis.Object.entries(message.securitySchemes);
627
+ if (entries.length > 0) {
628
+ obj.securitySchemes = {};
629
+ entries.forEach(([k, v]) => {
630
+ obj.securitySchemes[k] = SecurityScheme.toJSON(v);
631
+ });
632
+ }
633
+ }
634
+ if (message.security?.length) {
635
+ obj.security = message.security.map((e) => Security.toJSON(e));
636
+ }
637
+ if (message.defaultInputModes?.length) {
638
+ obj.defaultInputModes = message.defaultInputModes;
639
+ }
640
+ if (message.defaultOutputModes?.length) {
641
+ obj.defaultOutputModes = message.defaultOutputModes;
642
+ }
643
+ if (message.skills?.length) {
644
+ obj.skills = message.skills.map((e) => AgentSkill.toJSON(e));
645
+ }
646
+ if (message.supportsAuthenticatedExtendedCard !== void 0) {
647
+ obj.supportsAuthenticatedExtendedCard = message.supportsAuthenticatedExtendedCard;
648
+ }
649
+ if (message.signatures?.length) {
650
+ obj.signatures = message.signatures.map((e) => AgentCardSignature.toJSON(e));
651
+ }
652
+ return obj;
653
+ }
654
+ };
655
+ var AgentProvider = {
656
+ fromJSON(object) {
657
+ return {
658
+ url: isSet2(object.url) ? globalThis.String(object.url) : void 0,
659
+ organization: isSet2(object.organization) ? globalThis.String(object.organization) : void 0
660
+ };
661
+ },
662
+ toJSON(message) {
663
+ const obj = {};
664
+ if (message.url !== void 0) {
665
+ obj.url = message.url;
666
+ }
667
+ if (message.organization !== void 0) {
668
+ obj.organization = message.organization;
669
+ }
670
+ return obj;
671
+ }
672
+ };
673
+ var AgentCapabilities = {
674
+ fromJSON(object) {
675
+ return {
676
+ streaming: isSet2(object.streaming) ? globalThis.Boolean(object.streaming) : void 0,
677
+ pushNotifications: isSet2(object.pushNotifications) ? globalThis.Boolean(object.pushNotifications) : isSet2(object.push_notifications) ? globalThis.Boolean(object.push_notifications) : void 0,
678
+ extensions: globalThis.Array.isArray(object?.extensions) ? object.extensions.map((e) => AgentExtension.fromJSON(e)) : []
679
+ };
680
+ },
681
+ toJSON(message) {
682
+ const obj = {};
683
+ if (message.streaming !== void 0) {
684
+ obj.streaming = message.streaming;
685
+ }
686
+ if (message.pushNotifications !== void 0) {
687
+ obj.pushNotifications = message.pushNotifications;
688
+ }
689
+ if (message.extensions?.length) {
690
+ obj.extensions = message.extensions.map((e) => AgentExtension.toJSON(e));
691
+ }
692
+ return obj;
693
+ }
694
+ };
695
+ var AgentExtension = {
696
+ fromJSON(object) {
697
+ return {
698
+ uri: isSet2(object.uri) ? globalThis.String(object.uri) : void 0,
699
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
700
+ required: isSet2(object.required) ? globalThis.Boolean(object.required) : void 0,
701
+ params: isObject(object.params) ? object.params : void 0
702
+ };
703
+ },
704
+ toJSON(message) {
705
+ const obj = {};
706
+ if (message.uri !== void 0) {
707
+ obj.uri = message.uri;
708
+ }
709
+ if (message.description !== void 0) {
710
+ obj.description = message.description;
711
+ }
712
+ if (message.required !== void 0) {
713
+ obj.required = message.required;
714
+ }
715
+ if (message.params !== void 0) {
716
+ obj.params = message.params;
717
+ }
718
+ return obj;
719
+ }
720
+ };
721
+ var AgentSkill = {
722
+ fromJSON(object) {
723
+ return {
724
+ id: isSet2(object.id) ? globalThis.String(object.id) : void 0,
725
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0,
726
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
727
+ tags: globalThis.Array.isArray(object?.tags) ? object.tags.map((e) => globalThis.String(e)) : [],
728
+ examples: globalThis.Array.isArray(object?.examples) ? object.examples.map((e) => globalThis.String(e)) : [],
729
+ inputModes: globalThis.Array.isArray(object?.inputModes) ? object.inputModes.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.input_modes) ? object.input_modes.map((e) => globalThis.String(e)) : [],
730
+ outputModes: globalThis.Array.isArray(object?.outputModes) ? object.outputModes.map((e) => globalThis.String(e)) : globalThis.Array.isArray(object?.output_modes) ? object.output_modes.map((e) => globalThis.String(e)) : [],
731
+ security: globalThis.Array.isArray(object?.security) ? object.security.map((e) => Security.fromJSON(e)) : []
732
+ };
733
+ },
734
+ toJSON(message) {
735
+ const obj = {};
736
+ if (message.id !== void 0) {
737
+ obj.id = message.id;
738
+ }
739
+ if (message.name !== void 0) {
740
+ obj.name = message.name;
741
+ }
742
+ if (message.description !== void 0) {
743
+ obj.description = message.description;
744
+ }
745
+ if (message.tags?.length) {
746
+ obj.tags = message.tags;
747
+ }
748
+ if (message.examples?.length) {
749
+ obj.examples = message.examples;
750
+ }
751
+ if (message.inputModes?.length) {
752
+ obj.inputModes = message.inputModes;
753
+ }
754
+ if (message.outputModes?.length) {
755
+ obj.outputModes = message.outputModes;
756
+ }
757
+ if (message.security?.length) {
758
+ obj.security = message.security.map((e) => Security.toJSON(e));
759
+ }
760
+ return obj;
761
+ }
762
+ };
763
+ var AgentCardSignature = {
764
+ fromJSON(object) {
765
+ return {
766
+ protected: isSet2(object.protected) ? globalThis.String(object.protected) : void 0,
767
+ signature: isSet2(object.signature) ? globalThis.String(object.signature) : void 0,
768
+ header: isObject(object.header) ? object.header : void 0
769
+ };
770
+ },
771
+ toJSON(message) {
772
+ const obj = {};
773
+ if (message.protected !== void 0) {
774
+ obj.protected = message.protected;
775
+ }
776
+ if (message.signature !== void 0) {
777
+ obj.signature = message.signature;
778
+ }
779
+ if (message.header !== void 0) {
780
+ obj.header = message.header;
781
+ }
782
+ return obj;
783
+ }
784
+ };
785
+ var TaskPushNotificationConfig = {
786
+ fromJSON(object) {
787
+ return {
788
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0,
789
+ pushNotificationConfig: isSet2(object.pushNotificationConfig) ? PushNotificationConfig.fromJSON(object.pushNotificationConfig) : isSet2(object.push_notification_config) ? PushNotificationConfig.fromJSON(object.push_notification_config) : void 0
790
+ };
791
+ },
792
+ toJSON(message) {
793
+ const obj = {};
794
+ if (message.name !== void 0) {
795
+ obj.name = message.name;
796
+ }
797
+ if (message.pushNotificationConfig !== void 0) {
798
+ obj.pushNotificationConfig = PushNotificationConfig.toJSON(message.pushNotificationConfig);
799
+ }
800
+ return obj;
801
+ }
802
+ };
803
+ var StringList = {
804
+ fromJSON(object) {
805
+ return { list: globalThis.Array.isArray(object?.list) ? object.list.map((e) => globalThis.String(e)) : [] };
806
+ },
807
+ toJSON(message) {
808
+ const obj = {};
809
+ if (message.list?.length) {
810
+ obj.list = message.list;
811
+ }
812
+ return obj;
813
+ }
814
+ };
815
+ var Security = {
816
+ fromJSON(object) {
817
+ return {
818
+ schemes: isObject(object.schemes) ? globalThis.Object.entries(object.schemes).reduce(
819
+ (acc, [key, value]) => {
820
+ acc[key] = StringList.fromJSON(value);
821
+ return acc;
822
+ },
823
+ {}
824
+ ) : {}
825
+ };
826
+ },
827
+ toJSON(message) {
828
+ const obj = {};
829
+ if (message.schemes) {
830
+ const entries = globalThis.Object.entries(message.schemes);
831
+ if (entries.length > 0) {
832
+ obj.schemes = {};
833
+ entries.forEach(([k, v]) => {
834
+ obj.schemes[k] = StringList.toJSON(v);
835
+ });
836
+ }
837
+ }
838
+ return obj;
839
+ }
840
+ };
841
+ var SecurityScheme = {
842
+ fromJSON(object) {
843
+ return {
844
+ scheme: isSet2(object.apiKeySecurityScheme) ? { $case: "apiKeySecurityScheme", value: APIKeySecurityScheme.fromJSON(object.apiKeySecurityScheme) } : isSet2(object.api_key_security_scheme) ? { $case: "apiKeySecurityScheme", value: APIKeySecurityScheme.fromJSON(object.api_key_security_scheme) } : isSet2(object.httpAuthSecurityScheme) ? { $case: "httpAuthSecurityScheme", value: HTTPAuthSecurityScheme.fromJSON(object.httpAuthSecurityScheme) } : isSet2(object.http_auth_security_scheme) ? { $case: "httpAuthSecurityScheme", value: HTTPAuthSecurityScheme.fromJSON(object.http_auth_security_scheme) } : isSet2(object.oauth2SecurityScheme) ? { $case: "oauth2SecurityScheme", value: OAuth2SecurityScheme.fromJSON(object.oauth2SecurityScheme) } : isSet2(object.oauth2_security_scheme) ? { $case: "oauth2SecurityScheme", value: OAuth2SecurityScheme.fromJSON(object.oauth2_security_scheme) } : isSet2(object.openIdConnectSecurityScheme) ? {
845
+ $case: "openIdConnectSecurityScheme",
846
+ value: OpenIdConnectSecurityScheme.fromJSON(object.openIdConnectSecurityScheme)
847
+ } : isSet2(object.open_id_connect_security_scheme) ? {
848
+ $case: "openIdConnectSecurityScheme",
849
+ value: OpenIdConnectSecurityScheme.fromJSON(object.open_id_connect_security_scheme)
850
+ } : isSet2(object.mtlsSecurityScheme) ? { $case: "mtlsSecurityScheme", value: MutualTlsSecurityScheme.fromJSON(object.mtlsSecurityScheme) } : isSet2(object.mtls_security_scheme) ? { $case: "mtlsSecurityScheme", value: MutualTlsSecurityScheme.fromJSON(object.mtls_security_scheme) } : void 0
851
+ };
852
+ },
853
+ toJSON(message) {
854
+ const obj = {};
855
+ if (message.scheme?.$case === "apiKeySecurityScheme") {
856
+ obj.apiKeySecurityScheme = APIKeySecurityScheme.toJSON(message.scheme.value);
857
+ } else if (message.scheme?.$case === "httpAuthSecurityScheme") {
858
+ obj.httpAuthSecurityScheme = HTTPAuthSecurityScheme.toJSON(message.scheme.value);
859
+ } else if (message.scheme?.$case === "oauth2SecurityScheme") {
860
+ obj.oauth2SecurityScheme = OAuth2SecurityScheme.toJSON(message.scheme.value);
861
+ } else if (message.scheme?.$case === "openIdConnectSecurityScheme") {
862
+ obj.openIdConnectSecurityScheme = OpenIdConnectSecurityScheme.toJSON(message.scheme.value);
863
+ } else if (message.scheme?.$case === "mtlsSecurityScheme") {
864
+ obj.mtlsSecurityScheme = MutualTlsSecurityScheme.toJSON(message.scheme.value);
865
+ }
866
+ return obj;
867
+ }
868
+ };
869
+ var APIKeySecurityScheme = {
870
+ fromJSON(object) {
871
+ return {
872
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
873
+ location: isSet2(object.location) ? globalThis.String(object.location) : void 0,
874
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0
875
+ };
876
+ },
877
+ toJSON(message) {
878
+ const obj = {};
879
+ if (message.description !== void 0) {
880
+ obj.description = message.description;
881
+ }
882
+ if (message.location !== void 0) {
883
+ obj.location = message.location;
884
+ }
885
+ if (message.name !== void 0) {
886
+ obj.name = message.name;
887
+ }
888
+ return obj;
889
+ }
890
+ };
891
+ var HTTPAuthSecurityScheme = {
892
+ fromJSON(object) {
893
+ return {
894
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
895
+ scheme: isSet2(object.scheme) ? globalThis.String(object.scheme) : void 0,
896
+ bearerFormat: isSet2(object.bearerFormat) ? globalThis.String(object.bearerFormat) : isSet2(object.bearer_format) ? globalThis.String(object.bearer_format) : void 0
897
+ };
898
+ },
899
+ toJSON(message) {
900
+ const obj = {};
901
+ if (message.description !== void 0) {
902
+ obj.description = message.description;
903
+ }
904
+ if (message.scheme !== void 0) {
905
+ obj.scheme = message.scheme;
906
+ }
907
+ if (message.bearerFormat !== void 0) {
908
+ obj.bearerFormat = message.bearerFormat;
909
+ }
910
+ return obj;
911
+ }
912
+ };
913
+ var OAuth2SecurityScheme = {
914
+ fromJSON(object) {
915
+ return {
916
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
917
+ flows: isSet2(object.flows) ? OAuthFlows.fromJSON(object.flows) : void 0,
918
+ oauth2MetadataUrl: isSet2(object.oauth2MetadataUrl) ? globalThis.String(object.oauth2MetadataUrl) : isSet2(object.oauth2_metadata_url) ? globalThis.String(object.oauth2_metadata_url) : void 0
919
+ };
920
+ },
921
+ toJSON(message) {
922
+ const obj = {};
923
+ if (message.description !== void 0) {
924
+ obj.description = message.description;
925
+ }
926
+ if (message.flows !== void 0) {
927
+ obj.flows = OAuthFlows.toJSON(message.flows);
928
+ }
929
+ if (message.oauth2MetadataUrl !== void 0) {
930
+ obj.oauth2MetadataUrl = message.oauth2MetadataUrl;
931
+ }
932
+ return obj;
933
+ }
934
+ };
935
+ var OpenIdConnectSecurityScheme = {
936
+ fromJSON(object) {
937
+ return {
938
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
939
+ openIdConnectUrl: isSet2(object.openIdConnectUrl) ? globalThis.String(object.openIdConnectUrl) : isSet2(object.open_id_connect_url) ? globalThis.String(object.open_id_connect_url) : void 0
940
+ };
941
+ },
942
+ toJSON(message) {
943
+ const obj = {};
944
+ if (message.description !== void 0) {
945
+ obj.description = message.description;
946
+ }
947
+ if (message.openIdConnectUrl !== void 0) {
948
+ obj.openIdConnectUrl = message.openIdConnectUrl;
949
+ }
950
+ return obj;
951
+ }
952
+ };
953
+ var MutualTlsSecurityScheme = {
954
+ fromJSON(object) {
955
+ return { description: isSet2(object.description) ? globalThis.String(object.description) : void 0 };
956
+ },
957
+ toJSON(message) {
958
+ const obj = {};
959
+ if (message.description !== void 0) {
960
+ obj.description = message.description;
961
+ }
962
+ return obj;
963
+ }
964
+ };
965
+ var OAuthFlows = {
966
+ fromJSON(object) {
967
+ return {
968
+ flow: isSet2(object.authorizationCode) ? { $case: "authorizationCode", value: AuthorizationCodeOAuthFlow.fromJSON(object.authorizationCode) } : isSet2(object.authorization_code) ? { $case: "authorizationCode", value: AuthorizationCodeOAuthFlow.fromJSON(object.authorization_code) } : isSet2(object.clientCredentials) ? { $case: "clientCredentials", value: ClientCredentialsOAuthFlow.fromJSON(object.clientCredentials) } : isSet2(object.client_credentials) ? { $case: "clientCredentials", value: ClientCredentialsOAuthFlow.fromJSON(object.client_credentials) } : isSet2(object.implicit) ? { $case: "implicit", value: ImplicitOAuthFlow.fromJSON(object.implicit) } : isSet2(object.password) ? { $case: "password", value: PasswordOAuthFlow.fromJSON(object.password) } : void 0
969
+ };
970
+ },
971
+ toJSON(message) {
972
+ const obj = {};
973
+ if (message.flow?.$case === "authorizationCode") {
974
+ obj.authorizationCode = AuthorizationCodeOAuthFlow.toJSON(message.flow.value);
975
+ } else if (message.flow?.$case === "clientCredentials") {
976
+ obj.clientCredentials = ClientCredentialsOAuthFlow.toJSON(message.flow.value);
977
+ } else if (message.flow?.$case === "implicit") {
978
+ obj.implicit = ImplicitOAuthFlow.toJSON(message.flow.value);
979
+ } else if (message.flow?.$case === "password") {
980
+ obj.password = PasswordOAuthFlow.toJSON(message.flow.value);
981
+ }
982
+ return obj;
983
+ }
984
+ };
985
+ var AuthorizationCodeOAuthFlow = {
986
+ fromJSON(object) {
987
+ return {
988
+ authorizationUrl: isSet2(object.authorizationUrl) ? globalThis.String(object.authorizationUrl) : isSet2(object.authorization_url) ? globalThis.String(object.authorization_url) : void 0,
989
+ tokenUrl: isSet2(object.tokenUrl) ? globalThis.String(object.tokenUrl) : isSet2(object.token_url) ? globalThis.String(object.token_url) : void 0,
990
+ refreshUrl: isSet2(object.refreshUrl) ? globalThis.String(object.refreshUrl) : isSet2(object.refresh_url) ? globalThis.String(object.refresh_url) : void 0,
991
+ scopes: isObject(object.scopes) ? globalThis.Object.entries(object.scopes).reduce(
992
+ (acc, [key, value]) => {
993
+ acc[key] = globalThis.String(value);
994
+ return acc;
995
+ },
996
+ {}
997
+ ) : {}
998
+ };
999
+ },
1000
+ toJSON(message) {
1001
+ const obj = {};
1002
+ if (message.authorizationUrl !== void 0) {
1003
+ obj.authorizationUrl = message.authorizationUrl;
1004
+ }
1005
+ if (message.tokenUrl !== void 0) {
1006
+ obj.tokenUrl = message.tokenUrl;
1007
+ }
1008
+ if (message.refreshUrl !== void 0) {
1009
+ obj.refreshUrl = message.refreshUrl;
1010
+ }
1011
+ if (message.scopes) {
1012
+ const entries = globalThis.Object.entries(message.scopes);
1013
+ if (entries.length > 0) {
1014
+ obj.scopes = {};
1015
+ entries.forEach(([k, v]) => {
1016
+ obj.scopes[k] = v;
1017
+ });
1018
+ }
1019
+ }
1020
+ return obj;
1021
+ }
1022
+ };
1023
+ var ClientCredentialsOAuthFlow = {
1024
+ fromJSON(object) {
1025
+ return {
1026
+ tokenUrl: isSet2(object.tokenUrl) ? globalThis.String(object.tokenUrl) : isSet2(object.token_url) ? globalThis.String(object.token_url) : void 0,
1027
+ refreshUrl: isSet2(object.refreshUrl) ? globalThis.String(object.refreshUrl) : isSet2(object.refresh_url) ? globalThis.String(object.refresh_url) : void 0,
1028
+ scopes: isObject(object.scopes) ? globalThis.Object.entries(object.scopes).reduce(
1029
+ (acc, [key, value]) => {
1030
+ acc[key] = globalThis.String(value);
1031
+ return acc;
1032
+ },
1033
+ {}
1034
+ ) : {}
1035
+ };
1036
+ },
1037
+ toJSON(message) {
1038
+ const obj = {};
1039
+ if (message.tokenUrl !== void 0) {
1040
+ obj.tokenUrl = message.tokenUrl;
1041
+ }
1042
+ if (message.refreshUrl !== void 0) {
1043
+ obj.refreshUrl = message.refreshUrl;
1044
+ }
1045
+ if (message.scopes) {
1046
+ const entries = globalThis.Object.entries(message.scopes);
1047
+ if (entries.length > 0) {
1048
+ obj.scopes = {};
1049
+ entries.forEach(([k, v]) => {
1050
+ obj.scopes[k] = v;
1051
+ });
1052
+ }
1053
+ }
1054
+ return obj;
1055
+ }
1056
+ };
1057
+ var ImplicitOAuthFlow = {
1058
+ fromJSON(object) {
1059
+ return {
1060
+ authorizationUrl: isSet2(object.authorizationUrl) ? globalThis.String(object.authorizationUrl) : isSet2(object.authorization_url) ? globalThis.String(object.authorization_url) : void 0,
1061
+ refreshUrl: isSet2(object.refreshUrl) ? globalThis.String(object.refreshUrl) : isSet2(object.refresh_url) ? globalThis.String(object.refresh_url) : void 0,
1062
+ scopes: isObject(object.scopes) ? globalThis.Object.entries(object.scopes).reduce(
1063
+ (acc, [key, value]) => {
1064
+ acc[key] = globalThis.String(value);
1065
+ return acc;
1066
+ },
1067
+ {}
1068
+ ) : {}
1069
+ };
1070
+ },
1071
+ toJSON(message) {
1072
+ const obj = {};
1073
+ if (message.authorizationUrl !== void 0) {
1074
+ obj.authorizationUrl = message.authorizationUrl;
1075
+ }
1076
+ if (message.refreshUrl !== void 0) {
1077
+ obj.refreshUrl = message.refreshUrl;
1078
+ }
1079
+ if (message.scopes) {
1080
+ const entries = globalThis.Object.entries(message.scopes);
1081
+ if (entries.length > 0) {
1082
+ obj.scopes = {};
1083
+ entries.forEach(([k, v]) => {
1084
+ obj.scopes[k] = v;
1085
+ });
1086
+ }
1087
+ }
1088
+ return obj;
1089
+ }
1090
+ };
1091
+ var PasswordOAuthFlow = {
1092
+ fromJSON(object) {
1093
+ return {
1094
+ tokenUrl: isSet2(object.tokenUrl) ? globalThis.String(object.tokenUrl) : isSet2(object.token_url) ? globalThis.String(object.token_url) : void 0,
1095
+ refreshUrl: isSet2(object.refreshUrl) ? globalThis.String(object.refreshUrl) : isSet2(object.refresh_url) ? globalThis.String(object.refresh_url) : void 0,
1096
+ scopes: isObject(object.scopes) ? globalThis.Object.entries(object.scopes).reduce(
1097
+ (acc, [key, value]) => {
1098
+ acc[key] = globalThis.String(value);
1099
+ return acc;
1100
+ },
1101
+ {}
1102
+ ) : {}
1103
+ };
1104
+ },
1105
+ toJSON(message) {
1106
+ const obj = {};
1107
+ if (message.tokenUrl !== void 0) {
1108
+ obj.tokenUrl = message.tokenUrl;
1109
+ }
1110
+ if (message.refreshUrl !== void 0) {
1111
+ obj.refreshUrl = message.refreshUrl;
1112
+ }
1113
+ if (message.scopes) {
1114
+ const entries = globalThis.Object.entries(message.scopes);
1115
+ if (entries.length > 0) {
1116
+ obj.scopes = {};
1117
+ entries.forEach(([k, v]) => {
1118
+ obj.scopes[k] = v;
1119
+ });
1120
+ }
1121
+ }
1122
+ return obj;
1123
+ }
1124
+ };
1125
+ var SendMessageRequest = {
1126
+ fromJSON(object) {
1127
+ return {
1128
+ request: isSet2(object.message) ? Message.fromJSON(object.message) : isSet2(object.request) ? Message.fromJSON(object.request) : void 0,
1129
+ configuration: isSet2(object.configuration) ? SendMessageConfiguration.fromJSON(object.configuration) : void 0,
1130
+ metadata: isObject(object.metadata) ? object.metadata : void 0
1131
+ };
1132
+ },
1133
+ toJSON(message) {
1134
+ const obj = {};
1135
+ if (message.request !== void 0) {
1136
+ obj.message = Message.toJSON(message.request);
1137
+ }
1138
+ if (message.configuration !== void 0) {
1139
+ obj.configuration = SendMessageConfiguration.toJSON(message.configuration);
1140
+ }
1141
+ if (message.metadata !== void 0) {
1142
+ obj.metadata = message.metadata;
1143
+ }
1144
+ return obj;
1145
+ }
1146
+ };
1147
+ var SendMessageResponse = {
1148
+ fromJSON(object) {
1149
+ return {
1150
+ payload: isSet2(object.task) ? { $case: "task", value: Task.fromJSON(object.task) } : isSet2(object.message) ? { $case: "msg", value: Message.fromJSON(object.message) } : isSet2(object.msg) ? { $case: "msg", value: Message.fromJSON(object.msg) } : void 0
1151
+ };
1152
+ },
1153
+ toJSON(message) {
1154
+ const obj = {};
1155
+ if (message.payload?.$case === "task") {
1156
+ obj.task = Task.toJSON(message.payload.value);
1157
+ } else if (message.payload?.$case === "msg") {
1158
+ obj.message = Message.toJSON(message.payload.value);
1159
+ }
1160
+ return obj;
1161
+ }
1162
+ };
1163
+ var StreamResponse = {
1164
+ fromJSON(object) {
1165
+ return {
1166
+ payload: isSet2(object.task) ? { $case: "task", value: Task.fromJSON(object.task) } : isSet2(object.message) ? { $case: "msg", value: Message.fromJSON(object.message) } : isSet2(object.msg) ? { $case: "msg", value: Message.fromJSON(object.msg) } : isSet2(object.statusUpdate) ? { $case: "statusUpdate", value: TaskStatusUpdateEvent.fromJSON(object.statusUpdate) } : isSet2(object.status_update) ? { $case: "statusUpdate", value: TaskStatusUpdateEvent.fromJSON(object.status_update) } : isSet2(object.artifactUpdate) ? { $case: "artifactUpdate", value: TaskArtifactUpdateEvent.fromJSON(object.artifactUpdate) } : isSet2(object.artifact_update) ? { $case: "artifactUpdate", value: TaskArtifactUpdateEvent.fromJSON(object.artifact_update) } : void 0
1167
+ };
1168
+ },
1169
+ toJSON(message) {
1170
+ const obj = {};
1171
+ if (message.payload?.$case === "task") {
1172
+ obj.task = Task.toJSON(message.payload.value);
1173
+ } else if (message.payload?.$case === "msg") {
1174
+ obj.message = Message.toJSON(message.payload.value);
1175
+ } else if (message.payload?.$case === "statusUpdate") {
1176
+ obj.statusUpdate = TaskStatusUpdateEvent.toJSON(message.payload.value);
1177
+ } else if (message.payload?.$case === "artifactUpdate") {
1178
+ obj.artifactUpdate = TaskArtifactUpdateEvent.toJSON(message.payload.value);
1179
+ }
1180
+ return obj;
1181
+ }
1182
+ };
1183
+ var ListTaskPushNotificationConfigResponse = {
1184
+ fromJSON(object) {
1185
+ return {
1186
+ configs: globalThis.Array.isArray(object?.configs) ? object.configs.map((e) => TaskPushNotificationConfig.fromJSON(e)) : [],
1187
+ nextPageToken: isSet2(object.nextPageToken) ? globalThis.String(object.nextPageToken) : isSet2(object.next_page_token) ? globalThis.String(object.next_page_token) : void 0
1188
+ };
1189
+ },
1190
+ toJSON(message) {
1191
+ const obj = {};
1192
+ if (message.configs?.length) {
1193
+ obj.configs = message.configs.map((e) => TaskPushNotificationConfig.toJSON(e));
1194
+ }
1195
+ if (message.nextPageToken !== void 0) {
1196
+ obj.nextPageToken = message.nextPageToken;
1197
+ }
1198
+ return obj;
1199
+ }
1200
+ };
1201
+ function bytesFromBase64(b64) {
1202
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
1203
+ }
1204
+ function base64FromBytes(arr) {
1205
+ return globalThis.Buffer.from(arr).toString("base64");
1206
+ }
1207
+ function fromTimestamp(t) {
1208
+ let millis = (t.seconds || 0) * 1e3;
1209
+ millis += (t.nanos || 0) / 1e6;
1210
+ return new globalThis.Date(millis);
1211
+ }
1212
+ function fromJsonTimestamp(o) {
1213
+ if (o instanceof globalThis.Date) {
1214
+ return o;
1215
+ } else if (typeof o === "string") {
1216
+ return new globalThis.Date(o);
1217
+ } else {
1218
+ return fromTimestamp(Timestamp.fromJSON(o));
1219
+ }
1220
+ }
1221
+ function isObject(value) {
1222
+ return typeof value === "object" && value !== null;
1223
+ }
1224
+ function isSet2(value) {
1225
+ return value !== null && value !== void 0;
1226
+ }
1227
+
1228
+ // src/types/converters/id_decoding.ts
1229
+ var CONFIG_REGEX = /^tasks\/([^/]+)\/pushNotificationConfigs\/([^/]+)$/;
1230
+ var TASK_ONLY_REGEX = /^tasks\/([^/]+)(?:\/|$)/;
1231
+ var extractTaskId = (name) => {
1232
+ const match = name.match(TASK_ONLY_REGEX);
1233
+ if (!match) {
1234
+ throw A2AError.invalidParams(`Invalid or missing task ID in: "${name}"`);
1235
+ }
1236
+ return match[1];
1237
+ };
1238
+ var generateTaskName = (taskId) => {
1239
+ return `tasks/${taskId}`;
1240
+ };
1241
+ var extractTaskAndPushNotificationConfigId = (name) => {
1242
+ const match = name.match(CONFIG_REGEX);
1243
+ if (!match) {
1244
+ throw A2AError.invalidParams(`Invalid or missing config ID in: "${name}"`);
1245
+ }
1246
+ return { taskId: match[1], configId: match[2] };
1247
+ };
1248
+ var generatePushNotificationConfigName = (taskId, configId) => {
1249
+ return `tasks/${taskId}/pushNotificationConfigs/${configId}`;
1250
+ };
1251
+
1252
+ // src/types/converters/to_proto.ts
1253
+ var ToProto = class _ToProto {
1254
+ static agentCard(agentCard) {
1255
+ return {
1256
+ protocolVersion: agentCard.protocolVersion,
1257
+ name: agentCard.name,
1258
+ description: agentCard.description,
1259
+ url: agentCard.url,
1260
+ preferredTransport: agentCard.preferredTransport,
1261
+ additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _ToProto.agentInterface(i)) ?? [],
1262
+ provider: _ToProto.agentProvider(agentCard.provider),
1263
+ version: agentCard.version,
1264
+ documentationUrl: agentCard.documentationUrl,
1265
+ capabilities: _ToProto.agentCapabilities(agentCard.capabilities),
1266
+ securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
1267
+ Object.entries(agentCard.securitySchemes).map(([key, value]) => [
1268
+ key,
1269
+ _ToProto.securityScheme(value)
1270
+ ])
1271
+ ) : {},
1272
+ security: agentCard.security?.map((s) => _ToProto.security(s)) ?? [],
1273
+ defaultInputModes: agentCard.defaultInputModes,
1274
+ defaultOutputModes: agentCard.defaultOutputModes,
1275
+ skills: agentCard.skills.map((s) => _ToProto.agentSkill(s)),
1276
+ supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
1277
+ signatures: agentCard.signatures?.map((s) => _ToProto.agentCardSignature(s)) ?? []
1278
+ };
1279
+ }
1280
+ static agentCardSignature(signatures) {
1281
+ return {
1282
+ protected: signatures.protected,
1283
+ signature: signatures.signature,
1284
+ header: signatures.header
1285
+ };
1286
+ }
1287
+ static agentSkill(skill) {
1288
+ return {
1289
+ id: skill.id,
1290
+ name: skill.name,
1291
+ description: skill.description,
1292
+ tags: skill.tags ?? [],
1293
+ examples: skill.examples ?? [],
1294
+ inputModes: skill.inputModes ?? [],
1295
+ outputModes: skill.outputModes ?? [],
1296
+ security: skill.security ? skill.security.map((s) => _ToProto.security(s)) : []
1297
+ };
1298
+ }
1299
+ static security(security) {
1300
+ return {
1301
+ schemes: Object.fromEntries(
1302
+ Object.entries(security).map(([key, value]) => {
1303
+ return [key, { list: value }];
1304
+ })
1305
+ )
1306
+ };
1307
+ }
1308
+ static securityScheme(scheme) {
1309
+ switch (scheme.type) {
1310
+ case "apiKey":
1311
+ return {
1312
+ scheme: {
1313
+ $case: "apiKeySecurityScheme",
1314
+ value: {
1315
+ name: scheme.name,
1316
+ location: scheme.in,
1317
+ description: scheme.description
1318
+ }
1319
+ }
1320
+ };
1321
+ case "http":
1322
+ return {
1323
+ scheme: {
1324
+ $case: "httpAuthSecurityScheme",
1325
+ value: {
1326
+ description: scheme.description,
1327
+ scheme: scheme.scheme,
1328
+ bearerFormat: scheme.bearerFormat
1329
+ }
1330
+ }
1331
+ };
1332
+ case "mutualTLS":
1333
+ return {
1334
+ scheme: {
1335
+ $case: "mtlsSecurityScheme",
1336
+ value: {
1337
+ description: scheme.description
1338
+ }
1339
+ }
1340
+ };
1341
+ case "oauth2":
1342
+ return {
1343
+ scheme: {
1344
+ $case: "oauth2SecurityScheme",
1345
+ value: {
1346
+ description: scheme.description,
1347
+ flows: _ToProto.oauthFlows(scheme.flows),
1348
+ oauth2MetadataUrl: scheme.oauth2MetadataUrl
1349
+ }
1350
+ }
1351
+ };
1352
+ case "openIdConnect":
1353
+ return {
1354
+ scheme: {
1355
+ $case: "openIdConnectSecurityScheme",
1356
+ value: {
1357
+ description: scheme.description,
1358
+ openIdConnectUrl: scheme.openIdConnectUrl
1359
+ }
1360
+ }
1361
+ };
1362
+ default:
1363
+ throw A2AError.internalError(`Unsupported security scheme type`);
1364
+ }
1365
+ }
1366
+ static oauthFlows(flows) {
1367
+ if (flows.implicit) {
1368
+ return {
1369
+ flow: {
1370
+ $case: "implicit",
1371
+ value: {
1372
+ authorizationUrl: flows.implicit.authorizationUrl,
1373
+ scopes: flows.implicit.scopes,
1374
+ refreshUrl: flows.implicit.refreshUrl
1375
+ }
1376
+ }
1377
+ };
1378
+ } else if (flows.password) {
1379
+ return {
1380
+ flow: {
1381
+ $case: "password",
1382
+ value: {
1383
+ tokenUrl: flows.password.tokenUrl,
1384
+ scopes: flows.password.scopes,
1385
+ refreshUrl: flows.password.refreshUrl
1386
+ }
1387
+ }
1388
+ };
1389
+ } else if (flows.clientCredentials) {
1390
+ return {
1391
+ flow: {
1392
+ $case: "clientCredentials",
1393
+ value: {
1394
+ tokenUrl: flows.clientCredentials.tokenUrl,
1395
+ scopes: flows.clientCredentials.scopes,
1396
+ refreshUrl: flows.clientCredentials.refreshUrl
1397
+ }
1398
+ }
1399
+ };
1400
+ } else if (flows.authorizationCode) {
1401
+ return {
1402
+ flow: {
1403
+ $case: "authorizationCode",
1404
+ value: {
1405
+ authorizationUrl: flows.authorizationCode.authorizationUrl,
1406
+ tokenUrl: flows.authorizationCode.tokenUrl,
1407
+ scopes: flows.authorizationCode.scopes,
1408
+ refreshUrl: flows.authorizationCode.refreshUrl
1409
+ }
1410
+ }
1411
+ };
1412
+ } else {
1413
+ throw A2AError.internalError(`Unsupported OAuth flows`);
1414
+ }
1415
+ }
1416
+ static agentInterface(agentInterface) {
1417
+ return {
1418
+ transport: agentInterface.transport,
1419
+ url: agentInterface.url
1420
+ };
1421
+ }
1422
+ static agentProvider(agentProvider) {
1423
+ if (!agentProvider) {
1424
+ return void 0;
1425
+ }
1426
+ return {
1427
+ url: agentProvider.url,
1428
+ organization: agentProvider.organization
1429
+ };
1430
+ }
1431
+ static agentCapabilities(capabilities) {
1432
+ return {
1433
+ streaming: capabilities.streaming,
1434
+ pushNotifications: capabilities.pushNotifications,
1435
+ extensions: capabilities.extensions ? capabilities.extensions.map((e) => _ToProto.agentExtension(e)) : []
1436
+ };
1437
+ }
1438
+ static agentExtension(extension) {
1439
+ return {
1440
+ uri: extension.uri,
1441
+ description: extension.description,
1442
+ required: extension.required,
1443
+ params: extension.params
1444
+ };
1445
+ }
1446
+ static listTaskPushNotificationConfig(config) {
1447
+ return {
1448
+ configs: config.map((c) => _ToProto.taskPushNotificationConfig(c)),
1449
+ nextPageToken: ""
1450
+ };
1451
+ }
1452
+ static getTaskPushNotificationConfigParams(config) {
1453
+ return {
1454
+ name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
1455
+ };
1456
+ }
1457
+ static listTaskPushNotificationConfigParams(config) {
1458
+ return {
1459
+ parent: generateTaskName(config.id),
1460
+ pageToken: "",
1461
+ pageSize: 0
1462
+ };
1463
+ }
1464
+ static deleteTaskPushNotificationConfigParams(config) {
1465
+ return {
1466
+ name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
1467
+ };
1468
+ }
1469
+ static taskPushNotificationConfig(config) {
1470
+ return {
1471
+ name: generatePushNotificationConfigName(
1472
+ config.taskId,
1473
+ config.pushNotificationConfig.id ?? ""
1474
+ ),
1475
+ pushNotificationConfig: _ToProto.pushNotificationConfig(config.pushNotificationConfig)
1476
+ };
1477
+ }
1478
+ static taskPushNotificationConfigCreate(config) {
1479
+ return {
1480
+ parent: generateTaskName(config.taskId),
1481
+ config: _ToProto.taskPushNotificationConfig(config),
1482
+ configId: config.pushNotificationConfig.id
1483
+ };
1484
+ }
1485
+ static pushNotificationConfig(config) {
1486
+ if (!config) {
1487
+ return void 0;
1488
+ }
1489
+ return {
1490
+ id: config.id,
1491
+ url: config.url,
1492
+ token: config.token,
1493
+ authentication: _ToProto.pushNotificationAuthenticationInfo(config.authentication)
1494
+ };
1495
+ }
1496
+ static pushNotificationAuthenticationInfo(authInfo) {
1497
+ if (!authInfo) {
1498
+ return void 0;
1499
+ }
1500
+ return {
1501
+ schemes: authInfo.schemes,
1502
+ credentials: authInfo.credentials
1503
+ };
1504
+ }
1505
+ static messageStreamResult(event) {
1506
+ if (event.kind === "message") {
1507
+ return {
1508
+ payload: {
1509
+ $case: "msg",
1510
+ value: _ToProto.message(event)
1511
+ }
1512
+ };
1513
+ } else if (event.kind === "task") {
1514
+ return {
1515
+ payload: {
1516
+ $case: "task",
1517
+ value: _ToProto.task(event)
1518
+ }
1519
+ };
1520
+ } else if (event.kind === "status-update") {
1521
+ return {
1522
+ payload: {
1523
+ $case: "statusUpdate",
1524
+ value: _ToProto.taskStatusUpdateEvent(event)
1525
+ }
1526
+ };
1527
+ } else if (event.kind === "artifact-update") {
1528
+ return {
1529
+ payload: {
1530
+ $case: "artifactUpdate",
1531
+ value: _ToProto.taskArtifactUpdateEvent(event)
1532
+ }
1533
+ };
1534
+ } else {
1535
+ throw A2AError.internalError("Invalid event type");
1536
+ }
1537
+ }
1538
+ static taskStatusUpdateEvent(event) {
1539
+ return {
1540
+ taskId: event.taskId,
1541
+ status: _ToProto.taskStatus(event.status),
1542
+ contextId: event.contextId,
1543
+ metadata: event.metadata,
1544
+ final: event.final
1545
+ };
1546
+ }
1547
+ static taskArtifactUpdateEvent(event) {
1548
+ return {
1549
+ taskId: event.taskId,
1550
+ artifact: _ToProto.artifact(event.artifact),
1551
+ contextId: event.contextId,
1552
+ metadata: event.metadata,
1553
+ append: event.append,
1554
+ lastChunk: event.lastChunk
1555
+ };
1556
+ }
1557
+ static messageSendResult(params) {
1558
+ if (params.kind === "message") {
1559
+ return {
1560
+ payload: {
1561
+ $case: "msg",
1562
+ value: _ToProto.message(params)
1563
+ }
1564
+ };
1565
+ } else if (params.kind === "task") {
1566
+ return {
1567
+ payload: {
1568
+ $case: "task",
1569
+ value: _ToProto.task(params)
1570
+ }
1571
+ };
1572
+ }
1573
+ }
1574
+ static message(message) {
1575
+ if (!message) {
1576
+ return void 0;
1577
+ }
1578
+ return {
1579
+ messageId: message.messageId,
1580
+ content: message.parts.map((p) => _ToProto.parts(p)),
1581
+ contextId: message.contextId,
1582
+ taskId: message.taskId,
1583
+ role: _ToProto.role(message.role),
1584
+ metadata: message.metadata,
1585
+ extensions: message.extensions ?? []
1586
+ };
1587
+ }
1588
+ static role(role) {
1589
+ switch (role) {
1590
+ case "agent":
1591
+ return 2 /* ROLE_AGENT */;
1592
+ case "user":
1593
+ return 1 /* ROLE_USER */;
1594
+ default:
1595
+ throw A2AError.internalError(`Invalid role`);
1596
+ }
1597
+ }
1598
+ static task(task) {
1599
+ return {
1600
+ id: task.id,
1601
+ contextId: task.contextId,
1602
+ status: _ToProto.taskStatus(task.status),
1603
+ artifacts: task.artifacts?.map((a) => _ToProto.artifact(a)) ?? [],
1604
+ history: task.history?.map((m) => _ToProto.message(m)) ?? [],
1605
+ metadata: task.metadata
1606
+ };
1607
+ }
1608
+ static taskStatus(status) {
1609
+ return {
1610
+ state: _ToProto.taskState(status.state),
1611
+ update: _ToProto.message(status.message),
1612
+ timestamp: status.timestamp ? new Date(status.timestamp) : void 0
1613
+ };
1614
+ }
1615
+ static artifact(artifact) {
1616
+ return {
1617
+ artifactId: artifact.artifactId,
1618
+ name: artifact.name,
1619
+ description: artifact.description,
1620
+ parts: artifact.parts.map((p) => _ToProto.parts(p)),
1621
+ metadata: artifact.metadata,
1622
+ extensions: artifact.extensions ? artifact.extensions : []
1623
+ };
1624
+ }
1625
+ static taskState(state) {
1626
+ switch (state) {
1627
+ case "submitted":
1628
+ return 1 /* TASK_STATE_SUBMITTED */;
1629
+ case "working":
1630
+ return 2 /* TASK_STATE_WORKING */;
1631
+ case "input-required":
1632
+ return 6 /* TASK_STATE_INPUT_REQUIRED */;
1633
+ case "rejected":
1634
+ return 7 /* TASK_STATE_REJECTED */;
1635
+ case "auth-required":
1636
+ return 8 /* TASK_STATE_AUTH_REQUIRED */;
1637
+ case "completed":
1638
+ return 3 /* TASK_STATE_COMPLETED */;
1639
+ case "failed":
1640
+ return 4 /* TASK_STATE_FAILED */;
1641
+ case "canceled":
1642
+ return 5 /* TASK_STATE_CANCELLED */;
1643
+ case "unknown":
1644
+ return 0 /* TASK_STATE_UNSPECIFIED */;
1645
+ default:
1646
+ return -1 /* UNRECOGNIZED */;
1647
+ }
1648
+ }
1649
+ static parts(part) {
1650
+ if (part.kind === "text") {
1651
+ return {
1652
+ part: { $case: "text", value: part.text }
1653
+ };
1654
+ }
1655
+ if (part.kind === "file") {
1656
+ let filePart;
1657
+ if ("uri" in part.file) {
1658
+ filePart = {
1659
+ file: { $case: "fileWithUri", value: part.file.uri },
1660
+ mimeType: part.file.mimeType
1661
+ };
1662
+ } else if ("bytes" in part.file) {
1663
+ filePart = {
1664
+ file: { $case: "fileWithBytes", value: Buffer.from(part.file.bytes, "base64") },
1665
+ mimeType: part.file.mimeType
1666
+ };
1667
+ } else {
1668
+ throw A2AError.internalError("Invalid file part");
1669
+ }
1670
+ return {
1671
+ part: { $case: "file", value: filePart }
1672
+ };
1673
+ }
1674
+ if (part.kind === "data") {
1675
+ return {
1676
+ part: { $case: "data", value: { data: part.data } }
1677
+ };
1678
+ }
1679
+ throw A2AError.internalError("Invalid part type");
1680
+ }
1681
+ static messageSendParams(params) {
1682
+ return {
1683
+ request: _ToProto.message(params.message),
1684
+ configuration: _ToProto.configuration(params.configuration),
1685
+ metadata: params.metadata
1686
+ };
1687
+ }
1688
+ static configuration(configuration) {
1689
+ if (!configuration) {
1690
+ return void 0;
1691
+ }
1692
+ return {
1693
+ blocking: configuration.blocking,
1694
+ acceptedOutputModes: configuration.acceptedOutputModes ?? [],
1695
+ pushNotification: _ToProto.pushNotificationConfig(configuration.pushNotificationConfig),
1696
+ historyLength: configuration.historyLength ?? 0
1697
+ };
1698
+ }
1699
+ static taskQueryParams(params) {
1700
+ return {
1701
+ name: generateTaskName(params.id),
1702
+ historyLength: params.historyLength ?? 0
1703
+ };
1704
+ }
1705
+ static cancelTaskRequest(params) {
1706
+ return {
1707
+ name: generateTaskName(params.id)
1708
+ };
1709
+ }
1710
+ static taskIdParams(params) {
1711
+ return {
1712
+ name: generateTaskName(params.id)
1713
+ };
1714
+ }
1715
+ };
1716
+
1717
+ // src/types/converters/from_proto.ts
1718
+ var FromProto = class _FromProto {
1719
+ static taskQueryParams(request) {
1720
+ return {
1721
+ id: extractTaskId(request.name),
1722
+ historyLength: request.historyLength
1723
+ };
1724
+ }
1725
+ static taskIdParams(request) {
1726
+ return {
1727
+ id: extractTaskId(request.name)
1728
+ };
1729
+ }
1730
+ static getTaskPushNotificationConfigParams(request) {
1731
+ const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
1732
+ return {
1733
+ id: taskId,
1734
+ pushNotificationConfigId: configId
1735
+ };
1736
+ }
1737
+ static listTaskPushNotificationConfigParams(request) {
1738
+ return {
1739
+ id: extractTaskId(request.parent)
1740
+ };
1741
+ }
1742
+ static createTaskPushNotificationConfig(request) {
1743
+ if (!request.config?.pushNotificationConfig) {
1744
+ throw A2AError.invalidParams(
1745
+ "Request must include a `config` object with a `pushNotificationConfig`"
1746
+ );
1747
+ }
1748
+ return {
1749
+ taskId: extractTaskId(request.parent),
1750
+ pushNotificationConfig: _FromProto.pushNotificationConfig(
1751
+ request.config.pushNotificationConfig
1752
+ )
1753
+ };
1754
+ }
1755
+ static deleteTaskPushNotificationConfigParams(request) {
1756
+ const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
1757
+ return {
1758
+ id: taskId,
1759
+ pushNotificationConfigId: configId
1760
+ };
1761
+ }
1762
+ static message(message) {
1763
+ if (!message) {
1764
+ return void 0;
1765
+ }
1766
+ return {
1767
+ kind: "message",
1768
+ messageId: message.messageId,
1769
+ parts: message.content.map((p) => _FromProto.parts(p)),
1770
+ contextId: message.contextId,
1771
+ taskId: message.taskId,
1772
+ role: _FromProto.role(message.role),
1773
+ metadata: message.metadata,
1774
+ extensions: message.extensions
1775
+ };
1776
+ }
1777
+ static role(role) {
1778
+ switch (role) {
1779
+ case 2 /* ROLE_AGENT */:
1780
+ return "agent";
1781
+ case 1 /* ROLE_USER */:
1782
+ return "user";
1783
+ default:
1784
+ throw A2AError.invalidParams(`Invalid role: ${role}`);
1785
+ }
1786
+ }
1787
+ static messageSendConfiguration(configuration) {
1788
+ if (!configuration) {
1789
+ return void 0;
1790
+ }
1791
+ return {
1792
+ blocking: configuration.blocking,
1793
+ acceptedOutputModes: configuration.acceptedOutputModes,
1794
+ pushNotificationConfig: _FromProto.pushNotificationConfig(configuration.pushNotification)
1795
+ };
1796
+ }
1797
+ static pushNotificationConfig(config) {
1798
+ if (!config) {
1799
+ return void 0;
1800
+ }
1801
+ return {
1802
+ id: config.id,
1803
+ url: config.url,
1804
+ token: config.token,
1805
+ authentication: _FromProto.pushNotificationAuthenticationInfo(config.authentication)
1806
+ };
1807
+ }
1808
+ static pushNotificationAuthenticationInfo(authInfo) {
1809
+ if (!authInfo) {
1810
+ return void 0;
1811
+ }
1812
+ return {
1813
+ schemes: authInfo.schemes,
1814
+ credentials: authInfo.credentials
1815
+ };
1816
+ }
1817
+ static parts(part) {
1818
+ if (part.part?.$case === "text") {
1819
+ return {
1820
+ kind: "text",
1821
+ text: part.part.value
1822
+ };
1823
+ }
1824
+ if (part.part?.$case === "file") {
1825
+ const filePart = part.part.value;
1826
+ if (filePart.file?.$case === "fileWithUri") {
1827
+ return {
1828
+ kind: "file",
1829
+ file: {
1830
+ uri: filePart.file.value,
1831
+ mimeType: filePart.mimeType
1832
+ }
1833
+ };
1834
+ } else if (filePart.file?.$case === "fileWithBytes") {
1835
+ return {
1836
+ kind: "file",
1837
+ file: {
1838
+ bytes: filePart.file.value.toString("base64"),
1839
+ mimeType: filePart.mimeType
1840
+ }
1841
+ };
1842
+ }
1843
+ throw A2AError.invalidParams("Invalid file part type");
1844
+ }
1845
+ if (part.part?.$case === "data") {
1846
+ return {
1847
+ kind: "data",
1848
+ data: part.part.value.data
1849
+ };
1850
+ }
1851
+ throw A2AError.invalidParams("Invalid part type");
1852
+ }
1853
+ static messageSendParams(request) {
1854
+ return {
1855
+ message: _FromProto.message(request.request),
1856
+ configuration: _FromProto.messageSendConfiguration(request.configuration),
1857
+ metadata: request.metadata
1858
+ };
1859
+ }
1860
+ static sendMessageResult(response) {
1861
+ if (response.payload?.$case === "task") {
1862
+ return _FromProto.task(response.payload.value);
1863
+ } else if (response.payload?.$case === "msg") {
1864
+ return _FromProto.message(response.payload.value);
1865
+ }
1866
+ throw A2AError.invalidParams("Invalid SendMessageResponse: missing result");
1867
+ }
1868
+ static task(task) {
1869
+ return {
1870
+ kind: "task",
1871
+ id: task.id,
1872
+ status: _FromProto.taskStatus(task.status),
1873
+ contextId: task.contextId,
1874
+ artifacts: task.artifacts?.map((a) => _FromProto.artifact(a)),
1875
+ history: task.history?.map((h) => _FromProto.message(h)),
1876
+ metadata: task.metadata
1877
+ };
1878
+ }
1879
+ static taskStatus(status) {
1880
+ return {
1881
+ message: _FromProto.message(status.update),
1882
+ state: _FromProto.taskState(status.state),
1883
+ timestamp: status.timestamp?.toISOString()
1884
+ };
1885
+ }
1886
+ static taskState(state) {
1887
+ switch (state) {
1888
+ case 1 /* TASK_STATE_SUBMITTED */:
1889
+ return "submitted";
1890
+ case 2 /* TASK_STATE_WORKING */:
1891
+ return "working";
1892
+ case 6 /* TASK_STATE_INPUT_REQUIRED */:
1893
+ return "input-required";
1894
+ case 3 /* TASK_STATE_COMPLETED */:
1895
+ return "completed";
1896
+ case 5 /* TASK_STATE_CANCELLED */:
1897
+ return "canceled";
1898
+ case 4 /* TASK_STATE_FAILED */:
1899
+ return "failed";
1900
+ case 7 /* TASK_STATE_REJECTED */:
1901
+ return "rejected";
1902
+ case 8 /* TASK_STATE_AUTH_REQUIRED */:
1903
+ return "auth-required";
1904
+ case 0 /* TASK_STATE_UNSPECIFIED */:
1905
+ return "unknown";
1906
+ default:
1907
+ throw A2AError.invalidParams(`Invalid task state: ${state}`);
1908
+ }
1909
+ }
1910
+ static artifact(artifact) {
1911
+ return {
1912
+ artifactId: artifact.artifactId,
1913
+ name: artifact.name,
1914
+ description: artifact.description,
1915
+ parts: artifact.parts.map((p) => _FromProto.parts(p)),
1916
+ metadata: artifact.metadata
1917
+ };
1918
+ }
1919
+ static taskPushNotificationConfig(request) {
1920
+ return {
1921
+ taskId: extractTaskId(request.name),
1922
+ pushNotificationConfig: _FromProto.pushNotificationConfig(request.pushNotificationConfig)
1923
+ };
1924
+ }
1925
+ static listTaskPushNotificationConfig(request) {
1926
+ return request.configs.map((c) => _FromProto.taskPushNotificationConfig(c));
1927
+ }
1928
+ static agentCard(agentCard) {
1929
+ return {
1930
+ additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _FromProto.agentInterface(i)),
1931
+ capabilities: agentCard.capabilities ? _FromProto.agentCapabilities(agentCard.capabilities) : {},
1932
+ defaultInputModes: agentCard.defaultInputModes,
1933
+ defaultOutputModes: agentCard.defaultOutputModes,
1934
+ description: agentCard.description,
1935
+ documentationUrl: agentCard.documentationUrl,
1936
+ name: agentCard.name,
1937
+ preferredTransport: agentCard.preferredTransport,
1938
+ provider: agentCard.provider ? _FromProto.agentProvider(agentCard.provider) : void 0,
1939
+ protocolVersion: agentCard.protocolVersion,
1940
+ security: agentCard.security?.map((s) => _FromProto.security(s)),
1941
+ securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
1942
+ Object.entries(agentCard.securitySchemes).map(([key, value]) => [
1943
+ key,
1944
+ _FromProto.securityScheme(value)
1945
+ ])
1946
+ ) : {},
1947
+ skills: agentCard.skills.map((s) => _FromProto.skills(s)),
1948
+ signatures: agentCard.signatures?.map((s) => _FromProto.agentCardSignature(s)),
1949
+ supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
1950
+ url: agentCard.url,
1951
+ version: agentCard.version
1952
+ };
1953
+ }
1954
+ static agentCapabilities(capabilities) {
1955
+ return {
1956
+ extensions: capabilities.extensions?.map((e) => _FromProto.agentExtension(e)),
1957
+ pushNotifications: capabilities.pushNotifications,
1958
+ streaming: capabilities.streaming
1959
+ };
1960
+ }
1961
+ static agentExtension(extension) {
1962
+ return {
1963
+ uri: extension.uri ?? "",
1964
+ description: extension.description,
1965
+ required: extension.required,
1966
+ params: extension.params
1967
+ };
1968
+ }
1969
+ static agentInterface(intf) {
1970
+ return {
1971
+ transport: intf.transport ?? "",
1972
+ url: intf.url ?? ""
1973
+ };
1974
+ }
1975
+ static agentProvider(provider) {
1976
+ return {
1977
+ organization: provider.organization ?? "",
1978
+ url: provider.url ?? ""
1979
+ };
1980
+ }
1981
+ static security(security) {
1982
+ return Object.fromEntries(
1983
+ Object.entries(security.schemes)?.map(([key, value]) => [key, value.list])
1984
+ );
1985
+ }
1986
+ static securityScheme(securitySchemes) {
1987
+ switch (securitySchemes.scheme?.$case) {
1988
+ case "apiKeySecurityScheme":
1989
+ return {
1990
+ type: "apiKey",
1991
+ name: securitySchemes.scheme.value.name,
1992
+ in: securitySchemes.scheme.value.location,
1993
+ description: securitySchemes.scheme.value.description
1994
+ };
1995
+ case "httpAuthSecurityScheme":
1996
+ return {
1997
+ type: "http",
1998
+ scheme: securitySchemes.scheme.value.scheme,
1999
+ bearerFormat: securitySchemes.scheme.value.bearerFormat,
2000
+ description: securitySchemes.scheme.value.description
2001
+ };
2002
+ case "mtlsSecurityScheme":
2003
+ return {
2004
+ type: "mutualTLS",
2005
+ description: securitySchemes.scheme.value.description
2006
+ };
2007
+ case "oauth2SecurityScheme":
2008
+ return {
2009
+ type: "oauth2",
2010
+ description: securitySchemes.scheme.value.description,
2011
+ flows: _FromProto.oauthFlows(securitySchemes.scheme.value.flows),
2012
+ oauth2MetadataUrl: securitySchemes.scheme.value.oauth2MetadataUrl
2013
+ };
2014
+ case "openIdConnectSecurityScheme":
2015
+ return {
2016
+ type: "openIdConnect",
2017
+ description: securitySchemes.scheme.value.description,
2018
+ openIdConnectUrl: securitySchemes.scheme.value.openIdConnectUrl
2019
+ };
2020
+ default:
2021
+ throw A2AError.internalError(`Unsupported security scheme type`);
2022
+ }
2023
+ }
2024
+ static oauthFlows(flows) {
2025
+ switch (flows.flow?.$case) {
2026
+ case "implicit":
2027
+ return {
2028
+ implicit: {
2029
+ authorizationUrl: flows.flow.value.authorizationUrl,
2030
+ scopes: flows.flow.value.scopes,
2031
+ refreshUrl: flows.flow.value.refreshUrl
2032
+ }
2033
+ };
2034
+ case "password":
2035
+ return {
2036
+ password: {
2037
+ refreshUrl: flows.flow.value.refreshUrl,
2038
+ scopes: flows.flow.value.scopes,
2039
+ tokenUrl: flows.flow.value.tokenUrl
2040
+ }
2041
+ };
2042
+ case "authorizationCode":
2043
+ return {
2044
+ authorizationCode: {
2045
+ refreshUrl: flows.flow.value.refreshUrl,
2046
+ authorizationUrl: flows.flow.value.authorizationUrl,
2047
+ scopes: flows.flow.value.scopes,
2048
+ tokenUrl: flows.flow.value.tokenUrl
2049
+ }
2050
+ };
2051
+ case "clientCredentials":
2052
+ return {
2053
+ clientCredentials: {
2054
+ refreshUrl: flows.flow.value.refreshUrl,
2055
+ scopes: flows.flow.value.scopes,
2056
+ tokenUrl: flows.flow.value.tokenUrl
2057
+ }
2058
+ };
2059
+ default:
2060
+ throw A2AError.internalError(`Unsupported OAuth flows`);
2061
+ }
2062
+ }
2063
+ static skills(skill) {
2064
+ return {
2065
+ id: skill.id,
2066
+ name: skill.name,
2067
+ description: skill.description,
2068
+ tags: skill.tags,
2069
+ examples: skill.examples,
2070
+ inputModes: skill.inputModes,
2071
+ outputModes: skill.outputModes,
2072
+ security: skill.security?.map((s) => _FromProto.security(s))
2073
+ };
2074
+ }
2075
+ static agentCardSignature(signatures) {
2076
+ return {
2077
+ protected: signatures.protected,
2078
+ signature: signatures.signature,
2079
+ header: signatures.header
2080
+ };
2081
+ }
2082
+ static taskStatusUpdateEvent(event) {
2083
+ return {
2084
+ kind: "status-update",
2085
+ taskId: event.taskId,
2086
+ status: _FromProto.taskStatus(event.status),
2087
+ contextId: event.contextId,
2088
+ metadata: event.metadata,
2089
+ final: event.final
2090
+ };
2091
+ }
2092
+ static taskArtifactUpdateEvent(event) {
2093
+ return {
2094
+ kind: "artifact-update",
2095
+ taskId: event.taskId,
2096
+ artifact: _FromProto.artifact(event.artifact),
2097
+ contextId: event.contextId,
2098
+ metadata: event.metadata,
2099
+ lastChunk: event.lastChunk
2100
+ };
2101
+ }
2102
+ static messageStreamResult(event) {
2103
+ switch (event.payload?.$case) {
2104
+ case "msg": {
2105
+ const message = _FromProto.message(event.payload.value);
2106
+ if (!message) {
2107
+ throw A2AError.internalError("Invalid message in StreamResponse");
2108
+ }
2109
+ return message;
2110
+ }
2111
+ case "task":
2112
+ return _FromProto.task(event.payload.value);
2113
+ case "statusUpdate":
2114
+ return _FromProto.taskStatusUpdateEvent(event.payload.value);
2115
+ case "artifactUpdate":
2116
+ return _FromProto.taskArtifactUpdateEvent(event.payload.value);
2117
+ default:
2118
+ throw A2AError.internalError("Invalid event type in StreamResponse");
2119
+ }
2120
+ }
2121
+ };
2122
+
2123
+ export {
2124
+ A2A_ERROR_CODE,
2125
+ TaskNotFoundError,
2126
+ TaskNotCancelableError,
2127
+ PushNotificationNotSupportedError,
2128
+ UnsupportedOperationError,
2129
+ ContentTypeNotSupportedError,
2130
+ InvalidAgentResponseError,
2131
+ AuthenticatedExtendedCardNotConfiguredError,
2132
+ SSE_HEADERS,
2133
+ formatSSEEvent,
2134
+ formatSSEErrorEvent,
2135
+ parseSseStream,
2136
+ Task,
2137
+ AgentCard,
2138
+ TaskPushNotificationConfig,
2139
+ SendMessageRequest,
2140
+ SendMessageResponse,
2141
+ StreamResponse,
2142
+ ListTaskPushNotificationConfigResponse,
2143
+ ToProto,
2144
+ FromProto
2145
+ };