@a2a-js/sdk 0.3.7 → 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.
@@ -1115,6 +1115,2075 @@ var Client = class {
1115
1115
  }
1116
1116
  };
1117
1117
 
1118
+ // src/server/error.ts
1119
+ var A2AError = class _A2AError extends Error {
1120
+ code;
1121
+ data;
1122
+ taskId;
1123
+ // Optional task ID context
1124
+ constructor(code, message, data, taskId) {
1125
+ super(message);
1126
+ this.name = "A2AError";
1127
+ this.code = code;
1128
+ this.data = data;
1129
+ this.taskId = taskId;
1130
+ }
1131
+ /**
1132
+ * Formats the error into a standard JSON-RPC error object structure.
1133
+ */
1134
+ toJSONRPCError() {
1135
+ const errorObject = {
1136
+ code: this.code,
1137
+ message: this.message
1138
+ };
1139
+ if (this.data !== void 0) {
1140
+ errorObject.data = this.data;
1141
+ }
1142
+ return errorObject;
1143
+ }
1144
+ // Static factory methods for common errors
1145
+ static parseError(message, data) {
1146
+ return new _A2AError(-32700, message, data);
1147
+ }
1148
+ static invalidRequest(message, data) {
1149
+ return new _A2AError(-32600, message, data);
1150
+ }
1151
+ static methodNotFound(method) {
1152
+ return new _A2AError(-32601, `Method not found: ${method}`);
1153
+ }
1154
+ static invalidParams(message, data) {
1155
+ return new _A2AError(-32602, message, data);
1156
+ }
1157
+ static internalError(message, data) {
1158
+ return new _A2AError(-32603, message, data);
1159
+ }
1160
+ static taskNotFound(taskId) {
1161
+ return new _A2AError(-32001, `Task not found: ${taskId}`, void 0, taskId);
1162
+ }
1163
+ static taskNotCancelable(taskId) {
1164
+ return new _A2AError(-32002, `Task not cancelable: ${taskId}`, void 0, taskId);
1165
+ }
1166
+ static pushNotificationNotSupported() {
1167
+ return new _A2AError(-32003, "Push Notification is not supported");
1168
+ }
1169
+ static unsupportedOperation(operation) {
1170
+ return new _A2AError(-32004, `Unsupported operation: ${operation}`);
1171
+ }
1172
+ static authenticatedExtendedCardNotConfigured() {
1173
+ return new _A2AError(-32007, `Extended card not configured.`);
1174
+ }
1175
+ };
1176
+
1177
+ // src/types/pb/google/protobuf/timestamp.ts
1178
+ var Timestamp = {
1179
+ fromJSON(object) {
1180
+ return {
1181
+ seconds: isSet(object.seconds) ? globalThis.Number(object.seconds) : 0,
1182
+ nanos: isSet(object.nanos) ? globalThis.Number(object.nanos) : 0
1183
+ };
1184
+ },
1185
+ toJSON(message) {
1186
+ const obj = {};
1187
+ if (message.seconds !== 0) {
1188
+ obj.seconds = Math.round(message.seconds);
1189
+ }
1190
+ if (message.nanos !== 0) {
1191
+ obj.nanos = Math.round(message.nanos);
1192
+ }
1193
+ return obj;
1194
+ }
1195
+ };
1196
+ function isSet(value) {
1197
+ return value !== null && value !== void 0;
1198
+ }
1199
+
1200
+ // src/types/pb/a2a.ts
1201
+ function taskStateFromJSON(object) {
1202
+ switch (object) {
1203
+ case 0:
1204
+ case "TASK_STATE_UNSPECIFIED":
1205
+ return 0 /* TASK_STATE_UNSPECIFIED */;
1206
+ case 1:
1207
+ case "TASK_STATE_SUBMITTED":
1208
+ return 1 /* TASK_STATE_SUBMITTED */;
1209
+ case 2:
1210
+ case "TASK_STATE_WORKING":
1211
+ return 2 /* TASK_STATE_WORKING */;
1212
+ case 3:
1213
+ case "TASK_STATE_COMPLETED":
1214
+ return 3 /* TASK_STATE_COMPLETED */;
1215
+ case 4:
1216
+ case "TASK_STATE_FAILED":
1217
+ return 4 /* TASK_STATE_FAILED */;
1218
+ case 5:
1219
+ case "TASK_STATE_CANCELLED":
1220
+ return 5 /* TASK_STATE_CANCELLED */;
1221
+ case 6:
1222
+ case "TASK_STATE_INPUT_REQUIRED":
1223
+ return 6 /* TASK_STATE_INPUT_REQUIRED */;
1224
+ case 7:
1225
+ case "TASK_STATE_REJECTED":
1226
+ return 7 /* TASK_STATE_REJECTED */;
1227
+ case 8:
1228
+ case "TASK_STATE_AUTH_REQUIRED":
1229
+ return 8 /* TASK_STATE_AUTH_REQUIRED */;
1230
+ case -1:
1231
+ case "UNRECOGNIZED":
1232
+ default:
1233
+ return -1 /* UNRECOGNIZED */;
1234
+ }
1235
+ }
1236
+ function taskStateToJSON(object) {
1237
+ switch (object) {
1238
+ case 0 /* TASK_STATE_UNSPECIFIED */:
1239
+ return "TASK_STATE_UNSPECIFIED";
1240
+ case 1 /* TASK_STATE_SUBMITTED */:
1241
+ return "TASK_STATE_SUBMITTED";
1242
+ case 2 /* TASK_STATE_WORKING */:
1243
+ return "TASK_STATE_WORKING";
1244
+ case 3 /* TASK_STATE_COMPLETED */:
1245
+ return "TASK_STATE_COMPLETED";
1246
+ case 4 /* TASK_STATE_FAILED */:
1247
+ return "TASK_STATE_FAILED";
1248
+ case 5 /* TASK_STATE_CANCELLED */:
1249
+ return "TASK_STATE_CANCELLED";
1250
+ case 6 /* TASK_STATE_INPUT_REQUIRED */:
1251
+ return "TASK_STATE_INPUT_REQUIRED";
1252
+ case 7 /* TASK_STATE_REJECTED */:
1253
+ return "TASK_STATE_REJECTED";
1254
+ case 8 /* TASK_STATE_AUTH_REQUIRED */:
1255
+ return "TASK_STATE_AUTH_REQUIRED";
1256
+ case -1 /* UNRECOGNIZED */:
1257
+ default:
1258
+ return "UNRECOGNIZED";
1259
+ }
1260
+ }
1261
+ function roleFromJSON(object) {
1262
+ switch (object) {
1263
+ case 0:
1264
+ case "ROLE_UNSPECIFIED":
1265
+ return 0 /* ROLE_UNSPECIFIED */;
1266
+ case 1:
1267
+ case "ROLE_USER":
1268
+ return 1 /* ROLE_USER */;
1269
+ case 2:
1270
+ case "ROLE_AGENT":
1271
+ return 2 /* ROLE_AGENT */;
1272
+ case -1:
1273
+ case "UNRECOGNIZED":
1274
+ default:
1275
+ return -1 /* UNRECOGNIZED */;
1276
+ }
1277
+ }
1278
+ function roleToJSON(object) {
1279
+ switch (object) {
1280
+ case 0 /* ROLE_UNSPECIFIED */:
1281
+ return "ROLE_UNSPECIFIED";
1282
+ case 1 /* ROLE_USER */:
1283
+ return "ROLE_USER";
1284
+ case 2 /* ROLE_AGENT */:
1285
+ return "ROLE_AGENT";
1286
+ case -1 /* UNRECOGNIZED */:
1287
+ default:
1288
+ return "UNRECOGNIZED";
1289
+ }
1290
+ }
1291
+ var SendMessageConfiguration = {
1292
+ fromJSON(object) {
1293
+ return {
1294
+ 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(
1295
+ (e) => globalThis.String(e)
1296
+ ) : [],
1297
+ pushNotification: isSet2(object.pushNotification) ? PushNotificationConfig.fromJSON(object.pushNotification) : isSet2(object.push_notification) ? PushNotificationConfig.fromJSON(object.push_notification) : void 0,
1298
+ historyLength: isSet2(object.historyLength) ? globalThis.Number(object.historyLength) : isSet2(object.history_length) ? globalThis.Number(object.history_length) : void 0,
1299
+ blocking: isSet2(object.blocking) ? globalThis.Boolean(object.blocking) : void 0
1300
+ };
1301
+ },
1302
+ toJSON(message) {
1303
+ const obj = {};
1304
+ if (message.acceptedOutputModes?.length) {
1305
+ obj.acceptedOutputModes = message.acceptedOutputModes;
1306
+ }
1307
+ if (message.pushNotification !== void 0) {
1308
+ obj.pushNotification = PushNotificationConfig.toJSON(message.pushNotification);
1309
+ }
1310
+ if (message.historyLength !== void 0) {
1311
+ obj.historyLength = Math.round(message.historyLength);
1312
+ }
1313
+ if (message.blocking !== void 0) {
1314
+ obj.blocking = message.blocking;
1315
+ }
1316
+ return obj;
1317
+ }
1318
+ };
1319
+ var Task = {
1320
+ fromJSON(object) {
1321
+ return {
1322
+ id: isSet2(object.id) ? globalThis.String(object.id) : void 0,
1323
+ contextId: isSet2(object.contextId) ? globalThis.String(object.contextId) : isSet2(object.context_id) ? globalThis.String(object.context_id) : void 0,
1324
+ status: isSet2(object.status) ? TaskStatus.fromJSON(object.status) : void 0,
1325
+ artifacts: globalThis.Array.isArray(object?.artifacts) ? object.artifacts.map((e) => Artifact.fromJSON(e)) : [],
1326
+ history: globalThis.Array.isArray(object?.history) ? object.history.map((e) => Message.fromJSON(e)) : [],
1327
+ metadata: isObject(object.metadata) ? object.metadata : void 0
1328
+ };
1329
+ },
1330
+ toJSON(message) {
1331
+ const obj = {};
1332
+ if (message.id !== void 0) {
1333
+ obj.id = message.id;
1334
+ }
1335
+ if (message.contextId !== void 0) {
1336
+ obj.contextId = message.contextId;
1337
+ }
1338
+ if (message.status !== void 0) {
1339
+ obj.status = TaskStatus.toJSON(message.status);
1340
+ }
1341
+ if (message.artifacts?.length) {
1342
+ obj.artifacts = message.artifacts.map((e) => Artifact.toJSON(e));
1343
+ }
1344
+ if (message.history?.length) {
1345
+ obj.history = message.history.map((e) => Message.toJSON(e));
1346
+ }
1347
+ if (message.metadata !== void 0) {
1348
+ obj.metadata = message.metadata;
1349
+ }
1350
+ return obj;
1351
+ }
1352
+ };
1353
+ var TaskStatus = {
1354
+ fromJSON(object) {
1355
+ return {
1356
+ state: isSet2(object.state) ? taskStateFromJSON(object.state) : void 0,
1357
+ update: isSet2(object.message) ? Message.fromJSON(object.message) : isSet2(object.update) ? Message.fromJSON(object.update) : void 0,
1358
+ timestamp: isSet2(object.timestamp) ? fromJsonTimestamp(object.timestamp) : void 0
1359
+ };
1360
+ },
1361
+ toJSON(message) {
1362
+ const obj = {};
1363
+ if (message.state !== void 0) {
1364
+ obj.state = taskStateToJSON(message.state);
1365
+ }
1366
+ if (message.update !== void 0) {
1367
+ obj.message = Message.toJSON(message.update);
1368
+ }
1369
+ if (message.timestamp !== void 0) {
1370
+ obj.timestamp = message.timestamp.toISOString();
1371
+ }
1372
+ return obj;
1373
+ }
1374
+ };
1375
+ var Part = {
1376
+ fromJSON(object) {
1377
+ return {
1378
+ 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
1379
+ };
1380
+ },
1381
+ toJSON(message) {
1382
+ const obj = {};
1383
+ if (message.part?.$case === "text") {
1384
+ obj.text = message.part.value;
1385
+ } else if (message.part?.$case === "file") {
1386
+ obj.file = FilePart.toJSON(message.part.value);
1387
+ } else if (message.part?.$case === "data") {
1388
+ obj.data = DataPart.toJSON(message.part.value);
1389
+ }
1390
+ return obj;
1391
+ }
1392
+ };
1393
+ var FilePart = {
1394
+ fromJSON(object) {
1395
+ return {
1396
+ 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,
1397
+ mimeType: isSet2(object.mimeType) ? globalThis.String(object.mimeType) : isSet2(object.mime_type) ? globalThis.String(object.mime_type) : void 0
1398
+ };
1399
+ },
1400
+ toJSON(message) {
1401
+ const obj = {};
1402
+ if (message.file?.$case === "fileWithUri") {
1403
+ obj.fileWithUri = message.file.value;
1404
+ } else if (message.file?.$case === "fileWithBytes") {
1405
+ obj.fileWithBytes = base64FromBytes(message.file.value);
1406
+ }
1407
+ if (message.mimeType !== void 0) {
1408
+ obj.mimeType = message.mimeType;
1409
+ }
1410
+ return obj;
1411
+ }
1412
+ };
1413
+ var DataPart = {
1414
+ fromJSON(object) {
1415
+ return { data: isObject(object.data) ? object.data : void 0 };
1416
+ },
1417
+ toJSON(message) {
1418
+ const obj = {};
1419
+ if (message.data !== void 0) {
1420
+ obj.data = message.data;
1421
+ }
1422
+ return obj;
1423
+ }
1424
+ };
1425
+ var Message = {
1426
+ fromJSON(object) {
1427
+ return {
1428
+ messageId: isSet2(object.messageId) ? globalThis.String(object.messageId) : isSet2(object.message_id) ? globalThis.String(object.message_id) : void 0,
1429
+ contextId: isSet2(object.contextId) ? globalThis.String(object.contextId) : isSet2(object.context_id) ? globalThis.String(object.context_id) : void 0,
1430
+ taskId: isSet2(object.taskId) ? globalThis.String(object.taskId) : isSet2(object.task_id) ? globalThis.String(object.task_id) : void 0,
1431
+ role: isSet2(object.role) ? roleFromJSON(object.role) : void 0,
1432
+ content: globalThis.Array.isArray(object?.content) ? object.content.map((e) => Part.fromJSON(e)) : [],
1433
+ metadata: isObject(object.metadata) ? object.metadata : void 0,
1434
+ extensions: globalThis.Array.isArray(object?.extensions) ? object.extensions.map((e) => globalThis.String(e)) : []
1435
+ };
1436
+ },
1437
+ toJSON(message) {
1438
+ const obj = {};
1439
+ if (message.messageId !== void 0) {
1440
+ obj.messageId = message.messageId;
1441
+ }
1442
+ if (message.contextId !== void 0) {
1443
+ obj.contextId = message.contextId;
1444
+ }
1445
+ if (message.taskId !== void 0) {
1446
+ obj.taskId = message.taskId;
1447
+ }
1448
+ if (message.role !== void 0) {
1449
+ obj.role = roleToJSON(message.role);
1450
+ }
1451
+ if (message.content?.length) {
1452
+ obj.content = message.content.map((e) => Part.toJSON(e));
1453
+ }
1454
+ if (message.metadata !== void 0) {
1455
+ obj.metadata = message.metadata;
1456
+ }
1457
+ if (message.extensions?.length) {
1458
+ obj.extensions = message.extensions;
1459
+ }
1460
+ return obj;
1461
+ }
1462
+ };
1463
+ var Artifact = {
1464
+ fromJSON(object) {
1465
+ return {
1466
+ artifactId: isSet2(object.artifactId) ? globalThis.String(object.artifactId) : isSet2(object.artifact_id) ? globalThis.String(object.artifact_id) : void 0,
1467
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0,
1468
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
1469
+ parts: globalThis.Array.isArray(object?.parts) ? object.parts.map((e) => Part.fromJSON(e)) : [],
1470
+ metadata: isObject(object.metadata) ? object.metadata : void 0,
1471
+ extensions: globalThis.Array.isArray(object?.extensions) ? object.extensions.map((e) => globalThis.String(e)) : []
1472
+ };
1473
+ },
1474
+ toJSON(message) {
1475
+ const obj = {};
1476
+ if (message.artifactId !== void 0) {
1477
+ obj.artifactId = message.artifactId;
1478
+ }
1479
+ if (message.name !== void 0) {
1480
+ obj.name = message.name;
1481
+ }
1482
+ if (message.description !== void 0) {
1483
+ obj.description = message.description;
1484
+ }
1485
+ if (message.parts?.length) {
1486
+ obj.parts = message.parts.map((e) => Part.toJSON(e));
1487
+ }
1488
+ if (message.metadata !== void 0) {
1489
+ obj.metadata = message.metadata;
1490
+ }
1491
+ if (message.extensions?.length) {
1492
+ obj.extensions = message.extensions;
1493
+ }
1494
+ return obj;
1495
+ }
1496
+ };
1497
+ var TaskStatusUpdateEvent = {
1498
+ fromJSON(object) {
1499
+ return {
1500
+ taskId: isSet2(object.taskId) ? globalThis.String(object.taskId) : isSet2(object.task_id) ? globalThis.String(object.task_id) : void 0,
1501
+ contextId: isSet2(object.contextId) ? globalThis.String(object.contextId) : isSet2(object.context_id) ? globalThis.String(object.context_id) : void 0,
1502
+ status: isSet2(object.status) ? TaskStatus.fromJSON(object.status) : void 0,
1503
+ final: isSet2(object.final) ? globalThis.Boolean(object.final) : void 0,
1504
+ metadata: isObject(object.metadata) ? object.metadata : void 0
1505
+ };
1506
+ },
1507
+ toJSON(message) {
1508
+ const obj = {};
1509
+ if (message.taskId !== void 0) {
1510
+ obj.taskId = message.taskId;
1511
+ }
1512
+ if (message.contextId !== void 0) {
1513
+ obj.contextId = message.contextId;
1514
+ }
1515
+ if (message.status !== void 0) {
1516
+ obj.status = TaskStatus.toJSON(message.status);
1517
+ }
1518
+ if (message.final !== void 0) {
1519
+ obj.final = message.final;
1520
+ }
1521
+ if (message.metadata !== void 0) {
1522
+ obj.metadata = message.metadata;
1523
+ }
1524
+ return obj;
1525
+ }
1526
+ };
1527
+ var TaskArtifactUpdateEvent = {
1528
+ fromJSON(object) {
1529
+ return {
1530
+ taskId: isSet2(object.taskId) ? globalThis.String(object.taskId) : isSet2(object.task_id) ? globalThis.String(object.task_id) : void 0,
1531
+ contextId: isSet2(object.contextId) ? globalThis.String(object.contextId) : isSet2(object.context_id) ? globalThis.String(object.context_id) : void 0,
1532
+ artifact: isSet2(object.artifact) ? Artifact.fromJSON(object.artifact) : void 0,
1533
+ append: isSet2(object.append) ? globalThis.Boolean(object.append) : void 0,
1534
+ lastChunk: isSet2(object.lastChunk) ? globalThis.Boolean(object.lastChunk) : isSet2(object.last_chunk) ? globalThis.Boolean(object.last_chunk) : void 0,
1535
+ metadata: isObject(object.metadata) ? object.metadata : void 0
1536
+ };
1537
+ },
1538
+ toJSON(message) {
1539
+ const obj = {};
1540
+ if (message.taskId !== void 0) {
1541
+ obj.taskId = message.taskId;
1542
+ }
1543
+ if (message.contextId !== void 0) {
1544
+ obj.contextId = message.contextId;
1545
+ }
1546
+ if (message.artifact !== void 0) {
1547
+ obj.artifact = Artifact.toJSON(message.artifact);
1548
+ }
1549
+ if (message.append !== void 0) {
1550
+ obj.append = message.append;
1551
+ }
1552
+ if (message.lastChunk !== void 0) {
1553
+ obj.lastChunk = message.lastChunk;
1554
+ }
1555
+ if (message.metadata !== void 0) {
1556
+ obj.metadata = message.metadata;
1557
+ }
1558
+ return obj;
1559
+ }
1560
+ };
1561
+ var PushNotificationConfig = {
1562
+ fromJSON(object) {
1563
+ return {
1564
+ id: isSet2(object.id) ? globalThis.String(object.id) : void 0,
1565
+ url: isSet2(object.url) ? globalThis.String(object.url) : void 0,
1566
+ token: isSet2(object.token) ? globalThis.String(object.token) : void 0,
1567
+ authentication: isSet2(object.authentication) ? AuthenticationInfo.fromJSON(object.authentication) : void 0
1568
+ };
1569
+ },
1570
+ toJSON(message) {
1571
+ const obj = {};
1572
+ if (message.id !== void 0) {
1573
+ obj.id = message.id;
1574
+ }
1575
+ if (message.url !== void 0) {
1576
+ obj.url = message.url;
1577
+ }
1578
+ if (message.token !== void 0) {
1579
+ obj.token = message.token;
1580
+ }
1581
+ if (message.authentication !== void 0) {
1582
+ obj.authentication = AuthenticationInfo.toJSON(message.authentication);
1583
+ }
1584
+ return obj;
1585
+ }
1586
+ };
1587
+ var AuthenticationInfo = {
1588
+ fromJSON(object) {
1589
+ return {
1590
+ schemes: globalThis.Array.isArray(object?.schemes) ? object.schemes.map((e) => globalThis.String(e)) : [],
1591
+ credentials: isSet2(object.credentials) ? globalThis.String(object.credentials) : void 0
1592
+ };
1593
+ },
1594
+ toJSON(message) {
1595
+ const obj = {};
1596
+ if (message.schemes?.length) {
1597
+ obj.schemes = message.schemes;
1598
+ }
1599
+ if (message.credentials !== void 0) {
1600
+ obj.credentials = message.credentials;
1601
+ }
1602
+ return obj;
1603
+ }
1604
+ };
1605
+ var AgentInterface = {
1606
+ fromJSON(object) {
1607
+ return {
1608
+ url: isSet2(object.url) ? globalThis.String(object.url) : void 0,
1609
+ transport: isSet2(object.transport) ? globalThis.String(object.transport) : void 0
1610
+ };
1611
+ },
1612
+ toJSON(message) {
1613
+ const obj = {};
1614
+ if (message.url !== void 0) {
1615
+ obj.url = message.url;
1616
+ }
1617
+ if (message.transport !== void 0) {
1618
+ obj.transport = message.transport;
1619
+ }
1620
+ return obj;
1621
+ }
1622
+ };
1623
+ var AgentCard = {
1624
+ fromJSON(object) {
1625
+ return {
1626
+ protocolVersion: isSet2(object.protocolVersion) ? globalThis.String(object.protocolVersion) : isSet2(object.protocol_version) ? globalThis.String(object.protocol_version) : void 0,
1627
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0,
1628
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
1629
+ url: isSet2(object.url) ? globalThis.String(object.url) : void 0,
1630
+ preferredTransport: isSet2(object.preferredTransport) ? globalThis.String(object.preferredTransport) : isSet2(object.preferred_transport) ? globalThis.String(object.preferred_transport) : void 0,
1631
+ 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)) : [],
1632
+ provider: isSet2(object.provider) ? AgentProvider.fromJSON(object.provider) : void 0,
1633
+ version: isSet2(object.version) ? globalThis.String(object.version) : void 0,
1634
+ documentationUrl: isSet2(object.documentationUrl) ? globalThis.String(object.documentationUrl) : isSet2(object.documentation_url) ? globalThis.String(object.documentation_url) : void 0,
1635
+ capabilities: isSet2(object.capabilities) ? AgentCapabilities.fromJSON(object.capabilities) : void 0,
1636
+ securitySchemes: isObject(object.securitySchemes) ? globalThis.Object.entries(object.securitySchemes).reduce(
1637
+ (acc, [key, value]) => {
1638
+ acc[key] = SecurityScheme.fromJSON(value);
1639
+ return acc;
1640
+ },
1641
+ {}
1642
+ ) : isObject(object.security_schemes) ? globalThis.Object.entries(object.security_schemes).reduce(
1643
+ (acc, [key, value]) => {
1644
+ acc[key] = SecurityScheme.fromJSON(value);
1645
+ return acc;
1646
+ },
1647
+ {}
1648
+ ) : {},
1649
+ security: globalThis.Array.isArray(object?.security) ? object.security.map((e) => Security.fromJSON(e)) : [],
1650
+ 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)) : [],
1651
+ 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)) : [],
1652
+ skills: globalThis.Array.isArray(object?.skills) ? object.skills.map((e) => AgentSkill.fromJSON(e)) : [],
1653
+ supportsAuthenticatedExtendedCard: isSet2(object.supportsAuthenticatedExtendedCard) ? globalThis.Boolean(object.supportsAuthenticatedExtendedCard) : isSet2(object.supports_authenticated_extended_card) ? globalThis.Boolean(object.supports_authenticated_extended_card) : void 0,
1654
+ signatures: globalThis.Array.isArray(object?.signatures) ? object.signatures.map((e) => AgentCardSignature.fromJSON(e)) : []
1655
+ };
1656
+ },
1657
+ toJSON(message) {
1658
+ const obj = {};
1659
+ if (message.protocolVersion !== void 0) {
1660
+ obj.protocolVersion = message.protocolVersion;
1661
+ }
1662
+ if (message.name !== void 0) {
1663
+ obj.name = message.name;
1664
+ }
1665
+ if (message.description !== void 0) {
1666
+ obj.description = message.description;
1667
+ }
1668
+ if (message.url !== void 0) {
1669
+ obj.url = message.url;
1670
+ }
1671
+ if (message.preferredTransport !== void 0) {
1672
+ obj.preferredTransport = message.preferredTransport;
1673
+ }
1674
+ if (message.additionalInterfaces?.length) {
1675
+ obj.additionalInterfaces = message.additionalInterfaces.map((e) => AgentInterface.toJSON(e));
1676
+ }
1677
+ if (message.provider !== void 0) {
1678
+ obj.provider = AgentProvider.toJSON(message.provider);
1679
+ }
1680
+ if (message.version !== void 0) {
1681
+ obj.version = message.version;
1682
+ }
1683
+ if (message.documentationUrl !== void 0) {
1684
+ obj.documentationUrl = message.documentationUrl;
1685
+ }
1686
+ if (message.capabilities !== void 0) {
1687
+ obj.capabilities = AgentCapabilities.toJSON(message.capabilities);
1688
+ }
1689
+ if (message.securitySchemes) {
1690
+ const entries = globalThis.Object.entries(message.securitySchemes);
1691
+ if (entries.length > 0) {
1692
+ obj.securitySchemes = {};
1693
+ entries.forEach(([k, v]) => {
1694
+ obj.securitySchemes[k] = SecurityScheme.toJSON(v);
1695
+ });
1696
+ }
1697
+ }
1698
+ if (message.security?.length) {
1699
+ obj.security = message.security.map((e) => Security.toJSON(e));
1700
+ }
1701
+ if (message.defaultInputModes?.length) {
1702
+ obj.defaultInputModes = message.defaultInputModes;
1703
+ }
1704
+ if (message.defaultOutputModes?.length) {
1705
+ obj.defaultOutputModes = message.defaultOutputModes;
1706
+ }
1707
+ if (message.skills?.length) {
1708
+ obj.skills = message.skills.map((e) => AgentSkill.toJSON(e));
1709
+ }
1710
+ if (message.supportsAuthenticatedExtendedCard !== void 0) {
1711
+ obj.supportsAuthenticatedExtendedCard = message.supportsAuthenticatedExtendedCard;
1712
+ }
1713
+ if (message.signatures?.length) {
1714
+ obj.signatures = message.signatures.map((e) => AgentCardSignature.toJSON(e));
1715
+ }
1716
+ return obj;
1717
+ }
1718
+ };
1719
+ var AgentProvider = {
1720
+ fromJSON(object) {
1721
+ return {
1722
+ url: isSet2(object.url) ? globalThis.String(object.url) : void 0,
1723
+ organization: isSet2(object.organization) ? globalThis.String(object.organization) : void 0
1724
+ };
1725
+ },
1726
+ toJSON(message) {
1727
+ const obj = {};
1728
+ if (message.url !== void 0) {
1729
+ obj.url = message.url;
1730
+ }
1731
+ if (message.organization !== void 0) {
1732
+ obj.organization = message.organization;
1733
+ }
1734
+ return obj;
1735
+ }
1736
+ };
1737
+ var AgentCapabilities = {
1738
+ fromJSON(object) {
1739
+ return {
1740
+ streaming: isSet2(object.streaming) ? globalThis.Boolean(object.streaming) : void 0,
1741
+ pushNotifications: isSet2(object.pushNotifications) ? globalThis.Boolean(object.pushNotifications) : isSet2(object.push_notifications) ? globalThis.Boolean(object.push_notifications) : void 0,
1742
+ extensions: globalThis.Array.isArray(object?.extensions) ? object.extensions.map((e) => AgentExtension.fromJSON(e)) : []
1743
+ };
1744
+ },
1745
+ toJSON(message) {
1746
+ const obj = {};
1747
+ if (message.streaming !== void 0) {
1748
+ obj.streaming = message.streaming;
1749
+ }
1750
+ if (message.pushNotifications !== void 0) {
1751
+ obj.pushNotifications = message.pushNotifications;
1752
+ }
1753
+ if (message.extensions?.length) {
1754
+ obj.extensions = message.extensions.map((e) => AgentExtension.toJSON(e));
1755
+ }
1756
+ return obj;
1757
+ }
1758
+ };
1759
+ var AgentExtension = {
1760
+ fromJSON(object) {
1761
+ return {
1762
+ uri: isSet2(object.uri) ? globalThis.String(object.uri) : void 0,
1763
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
1764
+ required: isSet2(object.required) ? globalThis.Boolean(object.required) : void 0,
1765
+ params: isObject(object.params) ? object.params : void 0
1766
+ };
1767
+ },
1768
+ toJSON(message) {
1769
+ const obj = {};
1770
+ if (message.uri !== void 0) {
1771
+ obj.uri = message.uri;
1772
+ }
1773
+ if (message.description !== void 0) {
1774
+ obj.description = message.description;
1775
+ }
1776
+ if (message.required !== void 0) {
1777
+ obj.required = message.required;
1778
+ }
1779
+ if (message.params !== void 0) {
1780
+ obj.params = message.params;
1781
+ }
1782
+ return obj;
1783
+ }
1784
+ };
1785
+ var AgentSkill = {
1786
+ fromJSON(object) {
1787
+ return {
1788
+ id: isSet2(object.id) ? globalThis.String(object.id) : void 0,
1789
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0,
1790
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
1791
+ tags: globalThis.Array.isArray(object?.tags) ? object.tags.map((e) => globalThis.String(e)) : [],
1792
+ examples: globalThis.Array.isArray(object?.examples) ? object.examples.map((e) => globalThis.String(e)) : [],
1793
+ 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)) : [],
1794
+ 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)) : [],
1795
+ security: globalThis.Array.isArray(object?.security) ? object.security.map((e) => Security.fromJSON(e)) : []
1796
+ };
1797
+ },
1798
+ toJSON(message) {
1799
+ const obj = {};
1800
+ if (message.id !== void 0) {
1801
+ obj.id = message.id;
1802
+ }
1803
+ if (message.name !== void 0) {
1804
+ obj.name = message.name;
1805
+ }
1806
+ if (message.description !== void 0) {
1807
+ obj.description = message.description;
1808
+ }
1809
+ if (message.tags?.length) {
1810
+ obj.tags = message.tags;
1811
+ }
1812
+ if (message.examples?.length) {
1813
+ obj.examples = message.examples;
1814
+ }
1815
+ if (message.inputModes?.length) {
1816
+ obj.inputModes = message.inputModes;
1817
+ }
1818
+ if (message.outputModes?.length) {
1819
+ obj.outputModes = message.outputModes;
1820
+ }
1821
+ if (message.security?.length) {
1822
+ obj.security = message.security.map((e) => Security.toJSON(e));
1823
+ }
1824
+ return obj;
1825
+ }
1826
+ };
1827
+ var AgentCardSignature = {
1828
+ fromJSON(object) {
1829
+ return {
1830
+ protected: isSet2(object.protected) ? globalThis.String(object.protected) : void 0,
1831
+ signature: isSet2(object.signature) ? globalThis.String(object.signature) : void 0,
1832
+ header: isObject(object.header) ? object.header : void 0
1833
+ };
1834
+ },
1835
+ toJSON(message) {
1836
+ const obj = {};
1837
+ if (message.protected !== void 0) {
1838
+ obj.protected = message.protected;
1839
+ }
1840
+ if (message.signature !== void 0) {
1841
+ obj.signature = message.signature;
1842
+ }
1843
+ if (message.header !== void 0) {
1844
+ obj.header = message.header;
1845
+ }
1846
+ return obj;
1847
+ }
1848
+ };
1849
+ var TaskPushNotificationConfig = {
1850
+ fromJSON(object) {
1851
+ return {
1852
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0,
1853
+ pushNotificationConfig: isSet2(object.pushNotificationConfig) ? PushNotificationConfig.fromJSON(object.pushNotificationConfig) : isSet2(object.push_notification_config) ? PushNotificationConfig.fromJSON(object.push_notification_config) : void 0
1854
+ };
1855
+ },
1856
+ toJSON(message) {
1857
+ const obj = {};
1858
+ if (message.name !== void 0) {
1859
+ obj.name = message.name;
1860
+ }
1861
+ if (message.pushNotificationConfig !== void 0) {
1862
+ obj.pushNotificationConfig = PushNotificationConfig.toJSON(message.pushNotificationConfig);
1863
+ }
1864
+ return obj;
1865
+ }
1866
+ };
1867
+ var StringList = {
1868
+ fromJSON(object) {
1869
+ return { list: globalThis.Array.isArray(object?.list) ? object.list.map((e) => globalThis.String(e)) : [] };
1870
+ },
1871
+ toJSON(message) {
1872
+ const obj = {};
1873
+ if (message.list?.length) {
1874
+ obj.list = message.list;
1875
+ }
1876
+ return obj;
1877
+ }
1878
+ };
1879
+ var Security = {
1880
+ fromJSON(object) {
1881
+ return {
1882
+ schemes: isObject(object.schemes) ? globalThis.Object.entries(object.schemes).reduce(
1883
+ (acc, [key, value]) => {
1884
+ acc[key] = StringList.fromJSON(value);
1885
+ return acc;
1886
+ },
1887
+ {}
1888
+ ) : {}
1889
+ };
1890
+ },
1891
+ toJSON(message) {
1892
+ const obj = {};
1893
+ if (message.schemes) {
1894
+ const entries = globalThis.Object.entries(message.schemes);
1895
+ if (entries.length > 0) {
1896
+ obj.schemes = {};
1897
+ entries.forEach(([k, v]) => {
1898
+ obj.schemes[k] = StringList.toJSON(v);
1899
+ });
1900
+ }
1901
+ }
1902
+ return obj;
1903
+ }
1904
+ };
1905
+ var SecurityScheme = {
1906
+ fromJSON(object) {
1907
+ return {
1908
+ 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) ? {
1909
+ $case: "openIdConnectSecurityScheme",
1910
+ value: OpenIdConnectSecurityScheme.fromJSON(object.openIdConnectSecurityScheme)
1911
+ } : isSet2(object.open_id_connect_security_scheme) ? {
1912
+ $case: "openIdConnectSecurityScheme",
1913
+ value: OpenIdConnectSecurityScheme.fromJSON(object.open_id_connect_security_scheme)
1914
+ } : 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
1915
+ };
1916
+ },
1917
+ toJSON(message) {
1918
+ const obj = {};
1919
+ if (message.scheme?.$case === "apiKeySecurityScheme") {
1920
+ obj.apiKeySecurityScheme = APIKeySecurityScheme.toJSON(message.scheme.value);
1921
+ } else if (message.scheme?.$case === "httpAuthSecurityScheme") {
1922
+ obj.httpAuthSecurityScheme = HTTPAuthSecurityScheme.toJSON(message.scheme.value);
1923
+ } else if (message.scheme?.$case === "oauth2SecurityScheme") {
1924
+ obj.oauth2SecurityScheme = OAuth2SecurityScheme.toJSON(message.scheme.value);
1925
+ } else if (message.scheme?.$case === "openIdConnectSecurityScheme") {
1926
+ obj.openIdConnectSecurityScheme = OpenIdConnectSecurityScheme.toJSON(message.scheme.value);
1927
+ } else if (message.scheme?.$case === "mtlsSecurityScheme") {
1928
+ obj.mtlsSecurityScheme = MutualTlsSecurityScheme.toJSON(message.scheme.value);
1929
+ }
1930
+ return obj;
1931
+ }
1932
+ };
1933
+ var APIKeySecurityScheme = {
1934
+ fromJSON(object) {
1935
+ return {
1936
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
1937
+ location: isSet2(object.location) ? globalThis.String(object.location) : void 0,
1938
+ name: isSet2(object.name) ? globalThis.String(object.name) : void 0
1939
+ };
1940
+ },
1941
+ toJSON(message) {
1942
+ const obj = {};
1943
+ if (message.description !== void 0) {
1944
+ obj.description = message.description;
1945
+ }
1946
+ if (message.location !== void 0) {
1947
+ obj.location = message.location;
1948
+ }
1949
+ if (message.name !== void 0) {
1950
+ obj.name = message.name;
1951
+ }
1952
+ return obj;
1953
+ }
1954
+ };
1955
+ var HTTPAuthSecurityScheme = {
1956
+ fromJSON(object) {
1957
+ return {
1958
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
1959
+ scheme: isSet2(object.scheme) ? globalThis.String(object.scheme) : void 0,
1960
+ bearerFormat: isSet2(object.bearerFormat) ? globalThis.String(object.bearerFormat) : isSet2(object.bearer_format) ? globalThis.String(object.bearer_format) : void 0
1961
+ };
1962
+ },
1963
+ toJSON(message) {
1964
+ const obj = {};
1965
+ if (message.description !== void 0) {
1966
+ obj.description = message.description;
1967
+ }
1968
+ if (message.scheme !== void 0) {
1969
+ obj.scheme = message.scheme;
1970
+ }
1971
+ if (message.bearerFormat !== void 0) {
1972
+ obj.bearerFormat = message.bearerFormat;
1973
+ }
1974
+ return obj;
1975
+ }
1976
+ };
1977
+ var OAuth2SecurityScheme = {
1978
+ fromJSON(object) {
1979
+ return {
1980
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
1981
+ flows: isSet2(object.flows) ? OAuthFlows.fromJSON(object.flows) : void 0,
1982
+ oauth2MetadataUrl: isSet2(object.oauth2MetadataUrl) ? globalThis.String(object.oauth2MetadataUrl) : isSet2(object.oauth2_metadata_url) ? globalThis.String(object.oauth2_metadata_url) : void 0
1983
+ };
1984
+ },
1985
+ toJSON(message) {
1986
+ const obj = {};
1987
+ if (message.description !== void 0) {
1988
+ obj.description = message.description;
1989
+ }
1990
+ if (message.flows !== void 0) {
1991
+ obj.flows = OAuthFlows.toJSON(message.flows);
1992
+ }
1993
+ if (message.oauth2MetadataUrl !== void 0) {
1994
+ obj.oauth2MetadataUrl = message.oauth2MetadataUrl;
1995
+ }
1996
+ return obj;
1997
+ }
1998
+ };
1999
+ var OpenIdConnectSecurityScheme = {
2000
+ fromJSON(object) {
2001
+ return {
2002
+ description: isSet2(object.description) ? globalThis.String(object.description) : void 0,
2003
+ openIdConnectUrl: isSet2(object.openIdConnectUrl) ? globalThis.String(object.openIdConnectUrl) : isSet2(object.open_id_connect_url) ? globalThis.String(object.open_id_connect_url) : void 0
2004
+ };
2005
+ },
2006
+ toJSON(message) {
2007
+ const obj = {};
2008
+ if (message.description !== void 0) {
2009
+ obj.description = message.description;
2010
+ }
2011
+ if (message.openIdConnectUrl !== void 0) {
2012
+ obj.openIdConnectUrl = message.openIdConnectUrl;
2013
+ }
2014
+ return obj;
2015
+ }
2016
+ };
2017
+ var MutualTlsSecurityScheme = {
2018
+ fromJSON(object) {
2019
+ return { description: isSet2(object.description) ? globalThis.String(object.description) : void 0 };
2020
+ },
2021
+ toJSON(message) {
2022
+ const obj = {};
2023
+ if (message.description !== void 0) {
2024
+ obj.description = message.description;
2025
+ }
2026
+ return obj;
2027
+ }
2028
+ };
2029
+ var OAuthFlows = {
2030
+ fromJSON(object) {
2031
+ return {
2032
+ 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
2033
+ };
2034
+ },
2035
+ toJSON(message) {
2036
+ const obj = {};
2037
+ if (message.flow?.$case === "authorizationCode") {
2038
+ obj.authorizationCode = AuthorizationCodeOAuthFlow.toJSON(message.flow.value);
2039
+ } else if (message.flow?.$case === "clientCredentials") {
2040
+ obj.clientCredentials = ClientCredentialsOAuthFlow.toJSON(message.flow.value);
2041
+ } else if (message.flow?.$case === "implicit") {
2042
+ obj.implicit = ImplicitOAuthFlow.toJSON(message.flow.value);
2043
+ } else if (message.flow?.$case === "password") {
2044
+ obj.password = PasswordOAuthFlow.toJSON(message.flow.value);
2045
+ }
2046
+ return obj;
2047
+ }
2048
+ };
2049
+ var AuthorizationCodeOAuthFlow = {
2050
+ fromJSON(object) {
2051
+ return {
2052
+ authorizationUrl: isSet2(object.authorizationUrl) ? globalThis.String(object.authorizationUrl) : isSet2(object.authorization_url) ? globalThis.String(object.authorization_url) : void 0,
2053
+ tokenUrl: isSet2(object.tokenUrl) ? globalThis.String(object.tokenUrl) : isSet2(object.token_url) ? globalThis.String(object.token_url) : void 0,
2054
+ refreshUrl: isSet2(object.refreshUrl) ? globalThis.String(object.refreshUrl) : isSet2(object.refresh_url) ? globalThis.String(object.refresh_url) : void 0,
2055
+ scopes: isObject(object.scopes) ? globalThis.Object.entries(object.scopes).reduce(
2056
+ (acc, [key, value]) => {
2057
+ acc[key] = globalThis.String(value);
2058
+ return acc;
2059
+ },
2060
+ {}
2061
+ ) : {}
2062
+ };
2063
+ },
2064
+ toJSON(message) {
2065
+ const obj = {};
2066
+ if (message.authorizationUrl !== void 0) {
2067
+ obj.authorizationUrl = message.authorizationUrl;
2068
+ }
2069
+ if (message.tokenUrl !== void 0) {
2070
+ obj.tokenUrl = message.tokenUrl;
2071
+ }
2072
+ if (message.refreshUrl !== void 0) {
2073
+ obj.refreshUrl = message.refreshUrl;
2074
+ }
2075
+ if (message.scopes) {
2076
+ const entries = globalThis.Object.entries(message.scopes);
2077
+ if (entries.length > 0) {
2078
+ obj.scopes = {};
2079
+ entries.forEach(([k, v]) => {
2080
+ obj.scopes[k] = v;
2081
+ });
2082
+ }
2083
+ }
2084
+ return obj;
2085
+ }
2086
+ };
2087
+ var ClientCredentialsOAuthFlow = {
2088
+ fromJSON(object) {
2089
+ return {
2090
+ tokenUrl: isSet2(object.tokenUrl) ? globalThis.String(object.tokenUrl) : isSet2(object.token_url) ? globalThis.String(object.token_url) : void 0,
2091
+ refreshUrl: isSet2(object.refreshUrl) ? globalThis.String(object.refreshUrl) : isSet2(object.refresh_url) ? globalThis.String(object.refresh_url) : void 0,
2092
+ scopes: isObject(object.scopes) ? globalThis.Object.entries(object.scopes).reduce(
2093
+ (acc, [key, value]) => {
2094
+ acc[key] = globalThis.String(value);
2095
+ return acc;
2096
+ },
2097
+ {}
2098
+ ) : {}
2099
+ };
2100
+ },
2101
+ toJSON(message) {
2102
+ const obj = {};
2103
+ if (message.tokenUrl !== void 0) {
2104
+ obj.tokenUrl = message.tokenUrl;
2105
+ }
2106
+ if (message.refreshUrl !== void 0) {
2107
+ obj.refreshUrl = message.refreshUrl;
2108
+ }
2109
+ if (message.scopes) {
2110
+ const entries = globalThis.Object.entries(message.scopes);
2111
+ if (entries.length > 0) {
2112
+ obj.scopes = {};
2113
+ entries.forEach(([k, v]) => {
2114
+ obj.scopes[k] = v;
2115
+ });
2116
+ }
2117
+ }
2118
+ return obj;
2119
+ }
2120
+ };
2121
+ var ImplicitOAuthFlow = {
2122
+ fromJSON(object) {
2123
+ return {
2124
+ authorizationUrl: isSet2(object.authorizationUrl) ? globalThis.String(object.authorizationUrl) : isSet2(object.authorization_url) ? globalThis.String(object.authorization_url) : void 0,
2125
+ refreshUrl: isSet2(object.refreshUrl) ? globalThis.String(object.refreshUrl) : isSet2(object.refresh_url) ? globalThis.String(object.refresh_url) : void 0,
2126
+ scopes: isObject(object.scopes) ? globalThis.Object.entries(object.scopes).reduce(
2127
+ (acc, [key, value]) => {
2128
+ acc[key] = globalThis.String(value);
2129
+ return acc;
2130
+ },
2131
+ {}
2132
+ ) : {}
2133
+ };
2134
+ },
2135
+ toJSON(message) {
2136
+ const obj = {};
2137
+ if (message.authorizationUrl !== void 0) {
2138
+ obj.authorizationUrl = message.authorizationUrl;
2139
+ }
2140
+ if (message.refreshUrl !== void 0) {
2141
+ obj.refreshUrl = message.refreshUrl;
2142
+ }
2143
+ if (message.scopes) {
2144
+ const entries = globalThis.Object.entries(message.scopes);
2145
+ if (entries.length > 0) {
2146
+ obj.scopes = {};
2147
+ entries.forEach(([k, v]) => {
2148
+ obj.scopes[k] = v;
2149
+ });
2150
+ }
2151
+ }
2152
+ return obj;
2153
+ }
2154
+ };
2155
+ var PasswordOAuthFlow = {
2156
+ fromJSON(object) {
2157
+ return {
2158
+ tokenUrl: isSet2(object.tokenUrl) ? globalThis.String(object.tokenUrl) : isSet2(object.token_url) ? globalThis.String(object.token_url) : void 0,
2159
+ refreshUrl: isSet2(object.refreshUrl) ? globalThis.String(object.refreshUrl) : isSet2(object.refresh_url) ? globalThis.String(object.refresh_url) : void 0,
2160
+ scopes: isObject(object.scopes) ? globalThis.Object.entries(object.scopes).reduce(
2161
+ (acc, [key, value]) => {
2162
+ acc[key] = globalThis.String(value);
2163
+ return acc;
2164
+ },
2165
+ {}
2166
+ ) : {}
2167
+ };
2168
+ },
2169
+ toJSON(message) {
2170
+ const obj = {};
2171
+ if (message.tokenUrl !== void 0) {
2172
+ obj.tokenUrl = message.tokenUrl;
2173
+ }
2174
+ if (message.refreshUrl !== void 0) {
2175
+ obj.refreshUrl = message.refreshUrl;
2176
+ }
2177
+ if (message.scopes) {
2178
+ const entries = globalThis.Object.entries(message.scopes);
2179
+ if (entries.length > 0) {
2180
+ obj.scopes = {};
2181
+ entries.forEach(([k, v]) => {
2182
+ obj.scopes[k] = v;
2183
+ });
2184
+ }
2185
+ }
2186
+ return obj;
2187
+ }
2188
+ };
2189
+ var SendMessageRequest = {
2190
+ fromJSON(object) {
2191
+ return {
2192
+ request: isSet2(object.message) ? Message.fromJSON(object.message) : isSet2(object.request) ? Message.fromJSON(object.request) : void 0,
2193
+ configuration: isSet2(object.configuration) ? SendMessageConfiguration.fromJSON(object.configuration) : void 0,
2194
+ metadata: isObject(object.metadata) ? object.metadata : void 0
2195
+ };
2196
+ },
2197
+ toJSON(message) {
2198
+ const obj = {};
2199
+ if (message.request !== void 0) {
2200
+ obj.message = Message.toJSON(message.request);
2201
+ }
2202
+ if (message.configuration !== void 0) {
2203
+ obj.configuration = SendMessageConfiguration.toJSON(message.configuration);
2204
+ }
2205
+ if (message.metadata !== void 0) {
2206
+ obj.metadata = message.metadata;
2207
+ }
2208
+ return obj;
2209
+ }
2210
+ };
2211
+ var SendMessageResponse = {
2212
+ fromJSON(object) {
2213
+ return {
2214
+ 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
2215
+ };
2216
+ },
2217
+ toJSON(message) {
2218
+ const obj = {};
2219
+ if (message.payload?.$case === "task") {
2220
+ obj.task = Task.toJSON(message.payload.value);
2221
+ } else if (message.payload?.$case === "msg") {
2222
+ obj.message = Message.toJSON(message.payload.value);
2223
+ }
2224
+ return obj;
2225
+ }
2226
+ };
2227
+ var StreamResponse = {
2228
+ fromJSON(object) {
2229
+ return {
2230
+ 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
2231
+ };
2232
+ },
2233
+ toJSON(message) {
2234
+ const obj = {};
2235
+ if (message.payload?.$case === "task") {
2236
+ obj.task = Task.toJSON(message.payload.value);
2237
+ } else if (message.payload?.$case === "msg") {
2238
+ obj.message = Message.toJSON(message.payload.value);
2239
+ } else if (message.payload?.$case === "statusUpdate") {
2240
+ obj.statusUpdate = TaskStatusUpdateEvent.toJSON(message.payload.value);
2241
+ } else if (message.payload?.$case === "artifactUpdate") {
2242
+ obj.artifactUpdate = TaskArtifactUpdateEvent.toJSON(message.payload.value);
2243
+ }
2244
+ return obj;
2245
+ }
2246
+ };
2247
+ var ListTaskPushNotificationConfigResponse = {
2248
+ fromJSON(object) {
2249
+ return {
2250
+ configs: globalThis.Array.isArray(object?.configs) ? object.configs.map((e) => TaskPushNotificationConfig.fromJSON(e)) : [],
2251
+ nextPageToken: isSet2(object.nextPageToken) ? globalThis.String(object.nextPageToken) : isSet2(object.next_page_token) ? globalThis.String(object.next_page_token) : void 0
2252
+ };
2253
+ },
2254
+ toJSON(message) {
2255
+ const obj = {};
2256
+ if (message.configs?.length) {
2257
+ obj.configs = message.configs.map((e) => TaskPushNotificationConfig.toJSON(e));
2258
+ }
2259
+ if (message.nextPageToken !== void 0) {
2260
+ obj.nextPageToken = message.nextPageToken;
2261
+ }
2262
+ return obj;
2263
+ }
2264
+ };
2265
+ function bytesFromBase64(b64) {
2266
+ return Uint8Array.from(globalThis.Buffer.from(b64, "base64"));
2267
+ }
2268
+ function base64FromBytes(arr) {
2269
+ return globalThis.Buffer.from(arr).toString("base64");
2270
+ }
2271
+ function fromTimestamp(t) {
2272
+ let millis = (t.seconds || 0) * 1e3;
2273
+ millis += (t.nanos || 0) / 1e6;
2274
+ return new globalThis.Date(millis);
2275
+ }
2276
+ function fromJsonTimestamp(o) {
2277
+ if (o instanceof globalThis.Date) {
2278
+ return o;
2279
+ } else if (typeof o === "string") {
2280
+ return new globalThis.Date(o);
2281
+ } else {
2282
+ return fromTimestamp(Timestamp.fromJSON(o));
2283
+ }
2284
+ }
2285
+ function isObject(value) {
2286
+ return typeof value === "object" && value !== null;
2287
+ }
2288
+ function isSet2(value) {
2289
+ return value !== null && value !== void 0;
2290
+ }
2291
+
2292
+ // src/types/converters/id_decoding.ts
2293
+ var CONFIG_REGEX = /^tasks\/([^/]+)\/pushNotificationConfigs\/([^/]+)$/;
2294
+ var TASK_ONLY_REGEX = /^tasks\/([^/]+)(?:\/|$)/;
2295
+ var extractTaskId = (name) => {
2296
+ const match = name.match(TASK_ONLY_REGEX);
2297
+ if (!match) {
2298
+ throw A2AError.invalidParams(`Invalid or missing task ID in: "${name}"`);
2299
+ }
2300
+ return match[1];
2301
+ };
2302
+ var generateTaskName = (taskId) => {
2303
+ return `tasks/${taskId}`;
2304
+ };
2305
+ var extractTaskAndPushNotificationConfigId = (name) => {
2306
+ const match = name.match(CONFIG_REGEX);
2307
+ if (!match) {
2308
+ throw A2AError.invalidParams(`Invalid or missing config ID in: "${name}"`);
2309
+ }
2310
+ return { taskId: match[1], configId: match[2] };
2311
+ };
2312
+ var generatePushNotificationConfigName = (taskId, configId) => {
2313
+ return `tasks/${taskId}/pushNotificationConfigs/${configId}`;
2314
+ };
2315
+
2316
+ // src/types/converters/to_proto.ts
2317
+ var ToProto = class _ToProto {
2318
+ static agentCard(agentCard) {
2319
+ return {
2320
+ protocolVersion: agentCard.protocolVersion,
2321
+ name: agentCard.name,
2322
+ description: agentCard.description,
2323
+ url: agentCard.url,
2324
+ preferredTransport: agentCard.preferredTransport,
2325
+ additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _ToProto.agentInterface(i)) ?? [],
2326
+ provider: _ToProto.agentProvider(agentCard.provider),
2327
+ version: agentCard.version,
2328
+ documentationUrl: agentCard.documentationUrl,
2329
+ capabilities: _ToProto.agentCapabilities(agentCard.capabilities),
2330
+ securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
2331
+ Object.entries(agentCard.securitySchemes).map(([key, value]) => [
2332
+ key,
2333
+ _ToProto.securityScheme(value)
2334
+ ])
2335
+ ) : {},
2336
+ security: agentCard.security?.map((s) => _ToProto.security(s)) ?? [],
2337
+ defaultInputModes: agentCard.defaultInputModes,
2338
+ defaultOutputModes: agentCard.defaultOutputModes,
2339
+ skills: agentCard.skills.map((s) => _ToProto.agentSkill(s)),
2340
+ supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
2341
+ signatures: agentCard.signatures?.map((s) => _ToProto.agentCardSignature(s)) ?? []
2342
+ };
2343
+ }
2344
+ static agentCardSignature(signatures) {
2345
+ return {
2346
+ protected: signatures.protected,
2347
+ signature: signatures.signature,
2348
+ header: signatures.header
2349
+ };
2350
+ }
2351
+ static agentSkill(skill) {
2352
+ return {
2353
+ id: skill.id,
2354
+ name: skill.name,
2355
+ description: skill.description,
2356
+ tags: skill.tags ?? [],
2357
+ examples: skill.examples ?? [],
2358
+ inputModes: skill.inputModes ?? [],
2359
+ outputModes: skill.outputModes ?? [],
2360
+ security: skill.security ? skill.security.map((s) => _ToProto.security(s)) : []
2361
+ };
2362
+ }
2363
+ static security(security) {
2364
+ return {
2365
+ schemes: Object.fromEntries(
2366
+ Object.entries(security).map(([key, value]) => {
2367
+ return [key, { list: value }];
2368
+ })
2369
+ )
2370
+ };
2371
+ }
2372
+ static securityScheme(scheme) {
2373
+ switch (scheme.type) {
2374
+ case "apiKey":
2375
+ return {
2376
+ scheme: {
2377
+ $case: "apiKeySecurityScheme",
2378
+ value: {
2379
+ name: scheme.name,
2380
+ location: scheme.in,
2381
+ description: scheme.description
2382
+ }
2383
+ }
2384
+ };
2385
+ case "http":
2386
+ return {
2387
+ scheme: {
2388
+ $case: "httpAuthSecurityScheme",
2389
+ value: {
2390
+ description: scheme.description,
2391
+ scheme: scheme.scheme,
2392
+ bearerFormat: scheme.bearerFormat
2393
+ }
2394
+ }
2395
+ };
2396
+ case "mutualTLS":
2397
+ return {
2398
+ scheme: {
2399
+ $case: "mtlsSecurityScheme",
2400
+ value: {
2401
+ description: scheme.description
2402
+ }
2403
+ }
2404
+ };
2405
+ case "oauth2":
2406
+ return {
2407
+ scheme: {
2408
+ $case: "oauth2SecurityScheme",
2409
+ value: {
2410
+ description: scheme.description,
2411
+ flows: _ToProto.oauthFlows(scheme.flows),
2412
+ oauth2MetadataUrl: scheme.oauth2MetadataUrl
2413
+ }
2414
+ }
2415
+ };
2416
+ case "openIdConnect":
2417
+ return {
2418
+ scheme: {
2419
+ $case: "openIdConnectSecurityScheme",
2420
+ value: {
2421
+ description: scheme.description,
2422
+ openIdConnectUrl: scheme.openIdConnectUrl
2423
+ }
2424
+ }
2425
+ };
2426
+ default:
2427
+ throw A2AError.internalError(`Unsupported security scheme type`);
2428
+ }
2429
+ }
2430
+ static oauthFlows(flows) {
2431
+ if (flows.implicit) {
2432
+ return {
2433
+ flow: {
2434
+ $case: "implicit",
2435
+ value: {
2436
+ authorizationUrl: flows.implicit.authorizationUrl,
2437
+ scopes: flows.implicit.scopes,
2438
+ refreshUrl: flows.implicit.refreshUrl
2439
+ }
2440
+ }
2441
+ };
2442
+ } else if (flows.password) {
2443
+ return {
2444
+ flow: {
2445
+ $case: "password",
2446
+ value: {
2447
+ tokenUrl: flows.password.tokenUrl,
2448
+ scopes: flows.password.scopes,
2449
+ refreshUrl: flows.password.refreshUrl
2450
+ }
2451
+ }
2452
+ };
2453
+ } else if (flows.clientCredentials) {
2454
+ return {
2455
+ flow: {
2456
+ $case: "clientCredentials",
2457
+ value: {
2458
+ tokenUrl: flows.clientCredentials.tokenUrl,
2459
+ scopes: flows.clientCredentials.scopes,
2460
+ refreshUrl: flows.clientCredentials.refreshUrl
2461
+ }
2462
+ }
2463
+ };
2464
+ } else if (flows.authorizationCode) {
2465
+ return {
2466
+ flow: {
2467
+ $case: "authorizationCode",
2468
+ value: {
2469
+ authorizationUrl: flows.authorizationCode.authorizationUrl,
2470
+ tokenUrl: flows.authorizationCode.tokenUrl,
2471
+ scopes: flows.authorizationCode.scopes,
2472
+ refreshUrl: flows.authorizationCode.refreshUrl
2473
+ }
2474
+ }
2475
+ };
2476
+ } else {
2477
+ throw A2AError.internalError(`Unsupported OAuth flows`);
2478
+ }
2479
+ }
2480
+ static agentInterface(agentInterface) {
2481
+ return {
2482
+ transport: agentInterface.transport,
2483
+ url: agentInterface.url
2484
+ };
2485
+ }
2486
+ static agentProvider(agentProvider) {
2487
+ if (!agentProvider) {
2488
+ return void 0;
2489
+ }
2490
+ return {
2491
+ url: agentProvider.url,
2492
+ organization: agentProvider.organization
2493
+ };
2494
+ }
2495
+ static agentCapabilities(capabilities) {
2496
+ return {
2497
+ streaming: capabilities.streaming,
2498
+ pushNotifications: capabilities.pushNotifications,
2499
+ extensions: capabilities.extensions ? capabilities.extensions.map((e) => _ToProto.agentExtension(e)) : []
2500
+ };
2501
+ }
2502
+ static agentExtension(extension) {
2503
+ return {
2504
+ uri: extension.uri,
2505
+ description: extension.description,
2506
+ required: extension.required,
2507
+ params: extension.params
2508
+ };
2509
+ }
2510
+ static listTaskPushNotificationConfig(config) {
2511
+ return {
2512
+ configs: config.map((c) => _ToProto.taskPushNotificationConfig(c)),
2513
+ nextPageToken: ""
2514
+ };
2515
+ }
2516
+ static getTaskPushNotificationConfigParams(config) {
2517
+ return {
2518
+ name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
2519
+ };
2520
+ }
2521
+ static listTaskPushNotificationConfigParams(config) {
2522
+ return {
2523
+ parent: generateTaskName(config.id),
2524
+ pageToken: "",
2525
+ pageSize: 0
2526
+ };
2527
+ }
2528
+ static deleteTaskPushNotificationConfigParams(config) {
2529
+ return {
2530
+ name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
2531
+ };
2532
+ }
2533
+ static taskPushNotificationConfig(config) {
2534
+ return {
2535
+ name: generatePushNotificationConfigName(
2536
+ config.taskId,
2537
+ config.pushNotificationConfig.id ?? ""
2538
+ ),
2539
+ pushNotificationConfig: _ToProto.pushNotificationConfig(config.pushNotificationConfig)
2540
+ };
2541
+ }
2542
+ static taskPushNotificationConfigCreate(config) {
2543
+ return {
2544
+ parent: generateTaskName(config.taskId),
2545
+ config: _ToProto.taskPushNotificationConfig(config),
2546
+ configId: config.pushNotificationConfig.id
2547
+ };
2548
+ }
2549
+ static pushNotificationConfig(config) {
2550
+ if (!config) {
2551
+ return void 0;
2552
+ }
2553
+ return {
2554
+ id: config.id,
2555
+ url: config.url,
2556
+ token: config.token,
2557
+ authentication: _ToProto.pushNotificationAuthenticationInfo(config.authentication)
2558
+ };
2559
+ }
2560
+ static pushNotificationAuthenticationInfo(authInfo) {
2561
+ if (!authInfo) {
2562
+ return void 0;
2563
+ }
2564
+ return {
2565
+ schemes: authInfo.schemes,
2566
+ credentials: authInfo.credentials
2567
+ };
2568
+ }
2569
+ static messageStreamResult(event) {
2570
+ if (event.kind === "message") {
2571
+ return {
2572
+ payload: {
2573
+ $case: "msg",
2574
+ value: _ToProto.message(event)
2575
+ }
2576
+ };
2577
+ } else if (event.kind === "task") {
2578
+ return {
2579
+ payload: {
2580
+ $case: "task",
2581
+ value: _ToProto.task(event)
2582
+ }
2583
+ };
2584
+ } else if (event.kind === "status-update") {
2585
+ return {
2586
+ payload: {
2587
+ $case: "statusUpdate",
2588
+ value: _ToProto.taskStatusUpdateEvent(event)
2589
+ }
2590
+ };
2591
+ } else if (event.kind === "artifact-update") {
2592
+ return {
2593
+ payload: {
2594
+ $case: "artifactUpdate",
2595
+ value: _ToProto.taskArtifactUpdateEvent(event)
2596
+ }
2597
+ };
2598
+ } else {
2599
+ throw A2AError.internalError("Invalid event type");
2600
+ }
2601
+ }
2602
+ static taskStatusUpdateEvent(event) {
2603
+ return {
2604
+ taskId: event.taskId,
2605
+ status: _ToProto.taskStatus(event.status),
2606
+ contextId: event.contextId,
2607
+ metadata: event.metadata,
2608
+ final: event.final
2609
+ };
2610
+ }
2611
+ static taskArtifactUpdateEvent(event) {
2612
+ return {
2613
+ taskId: event.taskId,
2614
+ artifact: _ToProto.artifact(event.artifact),
2615
+ contextId: event.contextId,
2616
+ metadata: event.metadata,
2617
+ append: event.append,
2618
+ lastChunk: event.lastChunk
2619
+ };
2620
+ }
2621
+ static messageSendResult(params) {
2622
+ if (params.kind === "message") {
2623
+ return {
2624
+ payload: {
2625
+ $case: "msg",
2626
+ value: _ToProto.message(params)
2627
+ }
2628
+ };
2629
+ } else if (params.kind === "task") {
2630
+ return {
2631
+ payload: {
2632
+ $case: "task",
2633
+ value: _ToProto.task(params)
2634
+ }
2635
+ };
2636
+ }
2637
+ }
2638
+ static message(message) {
2639
+ if (!message) {
2640
+ return void 0;
2641
+ }
2642
+ return {
2643
+ messageId: message.messageId,
2644
+ content: message.parts.map((p) => _ToProto.parts(p)),
2645
+ contextId: message.contextId,
2646
+ taskId: message.taskId,
2647
+ role: _ToProto.role(message.role),
2648
+ metadata: message.metadata,
2649
+ extensions: message.extensions ?? []
2650
+ };
2651
+ }
2652
+ static role(role) {
2653
+ switch (role) {
2654
+ case "agent":
2655
+ return 2 /* ROLE_AGENT */;
2656
+ case "user":
2657
+ return 1 /* ROLE_USER */;
2658
+ default:
2659
+ throw A2AError.internalError(`Invalid role`);
2660
+ }
2661
+ }
2662
+ static task(task) {
2663
+ return {
2664
+ id: task.id,
2665
+ contextId: task.contextId,
2666
+ status: _ToProto.taskStatus(task.status),
2667
+ artifacts: task.artifacts?.map((a) => _ToProto.artifact(a)) ?? [],
2668
+ history: task.history?.map((m) => _ToProto.message(m)) ?? [],
2669
+ metadata: task.metadata
2670
+ };
2671
+ }
2672
+ static taskStatus(status) {
2673
+ return {
2674
+ state: _ToProto.taskState(status.state),
2675
+ update: _ToProto.message(status.message),
2676
+ timestamp: status.timestamp ? new Date(status.timestamp) : void 0
2677
+ };
2678
+ }
2679
+ static artifact(artifact) {
2680
+ return {
2681
+ artifactId: artifact.artifactId,
2682
+ name: artifact.name,
2683
+ description: artifact.description,
2684
+ parts: artifact.parts.map((p) => _ToProto.parts(p)),
2685
+ metadata: artifact.metadata,
2686
+ extensions: artifact.extensions ? artifact.extensions : []
2687
+ };
2688
+ }
2689
+ static taskState(state) {
2690
+ switch (state) {
2691
+ case "submitted":
2692
+ return 1 /* TASK_STATE_SUBMITTED */;
2693
+ case "working":
2694
+ return 2 /* TASK_STATE_WORKING */;
2695
+ case "input-required":
2696
+ return 6 /* TASK_STATE_INPUT_REQUIRED */;
2697
+ case "rejected":
2698
+ return 7 /* TASK_STATE_REJECTED */;
2699
+ case "auth-required":
2700
+ return 8 /* TASK_STATE_AUTH_REQUIRED */;
2701
+ case "completed":
2702
+ return 3 /* TASK_STATE_COMPLETED */;
2703
+ case "failed":
2704
+ return 4 /* TASK_STATE_FAILED */;
2705
+ case "canceled":
2706
+ return 5 /* TASK_STATE_CANCELLED */;
2707
+ case "unknown":
2708
+ return 0 /* TASK_STATE_UNSPECIFIED */;
2709
+ default:
2710
+ return -1 /* UNRECOGNIZED */;
2711
+ }
2712
+ }
2713
+ static parts(part) {
2714
+ if (part.kind === "text") {
2715
+ return {
2716
+ part: { $case: "text", value: part.text }
2717
+ };
2718
+ }
2719
+ if (part.kind === "file") {
2720
+ let filePart;
2721
+ if ("uri" in part.file) {
2722
+ filePart = {
2723
+ file: { $case: "fileWithUri", value: part.file.uri },
2724
+ mimeType: part.file.mimeType
2725
+ };
2726
+ } else if ("bytes" in part.file) {
2727
+ filePart = {
2728
+ file: { $case: "fileWithBytes", value: Buffer.from(part.file.bytes, "base64") },
2729
+ mimeType: part.file.mimeType
2730
+ };
2731
+ } else {
2732
+ throw A2AError.internalError("Invalid file part");
2733
+ }
2734
+ return {
2735
+ part: { $case: "file", value: filePart }
2736
+ };
2737
+ }
2738
+ if (part.kind === "data") {
2739
+ return {
2740
+ part: { $case: "data", value: { data: part.data } }
2741
+ };
2742
+ }
2743
+ throw A2AError.internalError("Invalid part type");
2744
+ }
2745
+ static messageSendParams(params) {
2746
+ return {
2747
+ request: _ToProto.message(params.message),
2748
+ configuration: _ToProto.configuration(params.configuration),
2749
+ metadata: params.metadata
2750
+ };
2751
+ }
2752
+ static configuration(configuration) {
2753
+ if (!configuration) {
2754
+ return void 0;
2755
+ }
2756
+ return {
2757
+ blocking: configuration.blocking,
2758
+ acceptedOutputModes: configuration.acceptedOutputModes ?? [],
2759
+ pushNotification: _ToProto.pushNotificationConfig(configuration.pushNotificationConfig),
2760
+ historyLength: configuration.historyLength ?? 0
2761
+ };
2762
+ }
2763
+ static taskQueryParams(params) {
2764
+ return {
2765
+ name: generateTaskName(params.id),
2766
+ historyLength: params.historyLength ?? 0
2767
+ };
2768
+ }
2769
+ static cancelTaskRequest(params) {
2770
+ return {
2771
+ name: generateTaskName(params.id)
2772
+ };
2773
+ }
2774
+ static taskIdParams(params) {
2775
+ return {
2776
+ name: generateTaskName(params.id)
2777
+ };
2778
+ }
2779
+ };
2780
+
2781
+ // src/types/converters/from_proto.ts
2782
+ var FromProto = class _FromProto {
2783
+ static taskQueryParams(request) {
2784
+ return {
2785
+ id: extractTaskId(request.name),
2786
+ historyLength: request.historyLength
2787
+ };
2788
+ }
2789
+ static taskIdParams(request) {
2790
+ return {
2791
+ id: extractTaskId(request.name)
2792
+ };
2793
+ }
2794
+ static getTaskPushNotificationConfigParams(request) {
2795
+ const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
2796
+ return {
2797
+ id: taskId,
2798
+ pushNotificationConfigId: configId
2799
+ };
2800
+ }
2801
+ static listTaskPushNotificationConfigParams(request) {
2802
+ return {
2803
+ id: extractTaskId(request.parent)
2804
+ };
2805
+ }
2806
+ static createTaskPushNotificationConfig(request) {
2807
+ if (!request.config?.pushNotificationConfig) {
2808
+ throw A2AError.invalidParams(
2809
+ "Request must include a `config` object with a `pushNotificationConfig`"
2810
+ );
2811
+ }
2812
+ return {
2813
+ taskId: extractTaskId(request.parent),
2814
+ pushNotificationConfig: _FromProto.pushNotificationConfig(
2815
+ request.config.pushNotificationConfig
2816
+ )
2817
+ };
2818
+ }
2819
+ static deleteTaskPushNotificationConfigParams(request) {
2820
+ const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
2821
+ return {
2822
+ id: taskId,
2823
+ pushNotificationConfigId: configId
2824
+ };
2825
+ }
2826
+ static message(message) {
2827
+ if (!message) {
2828
+ return void 0;
2829
+ }
2830
+ return {
2831
+ kind: "message",
2832
+ messageId: message.messageId,
2833
+ parts: message.content.map((p) => _FromProto.parts(p)),
2834
+ contextId: message.contextId,
2835
+ taskId: message.taskId,
2836
+ role: _FromProto.role(message.role),
2837
+ metadata: message.metadata,
2838
+ extensions: message.extensions
2839
+ };
2840
+ }
2841
+ static role(role) {
2842
+ switch (role) {
2843
+ case 2 /* ROLE_AGENT */:
2844
+ return "agent";
2845
+ case 1 /* ROLE_USER */:
2846
+ return "user";
2847
+ default:
2848
+ throw A2AError.invalidParams(`Invalid role: ${role}`);
2849
+ }
2850
+ }
2851
+ static messageSendConfiguration(configuration) {
2852
+ if (!configuration) {
2853
+ return void 0;
2854
+ }
2855
+ return {
2856
+ blocking: configuration.blocking,
2857
+ acceptedOutputModes: configuration.acceptedOutputModes,
2858
+ pushNotificationConfig: _FromProto.pushNotificationConfig(configuration.pushNotification)
2859
+ };
2860
+ }
2861
+ static pushNotificationConfig(config) {
2862
+ if (!config) {
2863
+ return void 0;
2864
+ }
2865
+ return {
2866
+ id: config.id,
2867
+ url: config.url,
2868
+ token: config.token,
2869
+ authentication: _FromProto.pushNotificationAuthenticationInfo(config.authentication)
2870
+ };
2871
+ }
2872
+ static pushNotificationAuthenticationInfo(authInfo) {
2873
+ if (!authInfo) {
2874
+ return void 0;
2875
+ }
2876
+ return {
2877
+ schemes: authInfo.schemes,
2878
+ credentials: authInfo.credentials
2879
+ };
2880
+ }
2881
+ static parts(part) {
2882
+ if (part.part?.$case === "text") {
2883
+ return {
2884
+ kind: "text",
2885
+ text: part.part.value
2886
+ };
2887
+ }
2888
+ if (part.part?.$case === "file") {
2889
+ const filePart = part.part.value;
2890
+ if (filePart.file?.$case === "fileWithUri") {
2891
+ return {
2892
+ kind: "file",
2893
+ file: {
2894
+ uri: filePart.file.value,
2895
+ mimeType: filePart.mimeType
2896
+ }
2897
+ };
2898
+ } else if (filePart.file?.$case === "fileWithBytes") {
2899
+ return {
2900
+ kind: "file",
2901
+ file: {
2902
+ bytes: filePart.file.value.toString("base64"),
2903
+ mimeType: filePart.mimeType
2904
+ }
2905
+ };
2906
+ }
2907
+ throw A2AError.invalidParams("Invalid file part type");
2908
+ }
2909
+ if (part.part?.$case === "data") {
2910
+ return {
2911
+ kind: "data",
2912
+ data: part.part.value.data
2913
+ };
2914
+ }
2915
+ throw A2AError.invalidParams("Invalid part type");
2916
+ }
2917
+ static messageSendParams(request) {
2918
+ return {
2919
+ message: _FromProto.message(request.request),
2920
+ configuration: _FromProto.messageSendConfiguration(request.configuration),
2921
+ metadata: request.metadata
2922
+ };
2923
+ }
2924
+ static sendMessageResult(response) {
2925
+ if (response.payload?.$case === "task") {
2926
+ return _FromProto.task(response.payload.value);
2927
+ } else if (response.payload?.$case === "msg") {
2928
+ return _FromProto.message(response.payload.value);
2929
+ }
2930
+ throw A2AError.invalidParams("Invalid SendMessageResponse: missing result");
2931
+ }
2932
+ static task(task) {
2933
+ return {
2934
+ kind: "task",
2935
+ id: task.id,
2936
+ status: _FromProto.taskStatus(task.status),
2937
+ contextId: task.contextId,
2938
+ artifacts: task.artifacts?.map((a) => _FromProto.artifact(a)),
2939
+ history: task.history?.map((h) => _FromProto.message(h)),
2940
+ metadata: task.metadata
2941
+ };
2942
+ }
2943
+ static taskStatus(status) {
2944
+ return {
2945
+ message: _FromProto.message(status.update),
2946
+ state: _FromProto.taskState(status.state),
2947
+ timestamp: status.timestamp?.toISOString()
2948
+ };
2949
+ }
2950
+ static taskState(state) {
2951
+ switch (state) {
2952
+ case 1 /* TASK_STATE_SUBMITTED */:
2953
+ return "submitted";
2954
+ case 2 /* TASK_STATE_WORKING */:
2955
+ return "working";
2956
+ case 6 /* TASK_STATE_INPUT_REQUIRED */:
2957
+ return "input-required";
2958
+ case 3 /* TASK_STATE_COMPLETED */:
2959
+ return "completed";
2960
+ case 5 /* TASK_STATE_CANCELLED */:
2961
+ return "canceled";
2962
+ case 4 /* TASK_STATE_FAILED */:
2963
+ return "failed";
2964
+ case 7 /* TASK_STATE_REJECTED */:
2965
+ return "rejected";
2966
+ case 8 /* TASK_STATE_AUTH_REQUIRED */:
2967
+ return "auth-required";
2968
+ case 0 /* TASK_STATE_UNSPECIFIED */:
2969
+ return "unknown";
2970
+ default:
2971
+ throw A2AError.invalidParams(`Invalid task state: ${state}`);
2972
+ }
2973
+ }
2974
+ static artifact(artifact) {
2975
+ return {
2976
+ artifactId: artifact.artifactId,
2977
+ name: artifact.name,
2978
+ description: artifact.description,
2979
+ parts: artifact.parts.map((p) => _FromProto.parts(p)),
2980
+ metadata: artifact.metadata
2981
+ };
2982
+ }
2983
+ static taskPushNotificationConfig(request) {
2984
+ return {
2985
+ taskId: extractTaskId(request.name),
2986
+ pushNotificationConfig: _FromProto.pushNotificationConfig(request.pushNotificationConfig)
2987
+ };
2988
+ }
2989
+ static listTaskPushNotificationConfig(request) {
2990
+ return request.configs.map((c) => _FromProto.taskPushNotificationConfig(c));
2991
+ }
2992
+ static agentCard(agentCard) {
2993
+ return {
2994
+ additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _FromProto.agentInterface(i)),
2995
+ capabilities: agentCard.capabilities ? _FromProto.agentCapabilities(agentCard.capabilities) : {},
2996
+ defaultInputModes: agentCard.defaultInputModes,
2997
+ defaultOutputModes: agentCard.defaultOutputModes,
2998
+ description: agentCard.description,
2999
+ documentationUrl: agentCard.documentationUrl,
3000
+ name: agentCard.name,
3001
+ preferredTransport: agentCard.preferredTransport,
3002
+ provider: agentCard.provider ? _FromProto.agentProvider(agentCard.provider) : void 0,
3003
+ protocolVersion: agentCard.protocolVersion,
3004
+ security: agentCard.security?.map((s) => _FromProto.security(s)),
3005
+ securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
3006
+ Object.entries(agentCard.securitySchemes).map(([key, value]) => [
3007
+ key,
3008
+ _FromProto.securityScheme(value)
3009
+ ])
3010
+ ) : {},
3011
+ skills: agentCard.skills.map((s) => _FromProto.skills(s)),
3012
+ signatures: agentCard.signatures?.map((s) => _FromProto.agentCardSignature(s)),
3013
+ supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
3014
+ url: agentCard.url,
3015
+ version: agentCard.version
3016
+ };
3017
+ }
3018
+ static agentCapabilities(capabilities) {
3019
+ return {
3020
+ extensions: capabilities.extensions?.map((e) => _FromProto.agentExtension(e)),
3021
+ pushNotifications: capabilities.pushNotifications,
3022
+ streaming: capabilities.streaming
3023
+ };
3024
+ }
3025
+ static agentExtension(extension) {
3026
+ return {
3027
+ uri: extension.uri ?? "",
3028
+ description: extension.description,
3029
+ required: extension.required,
3030
+ params: extension.params
3031
+ };
3032
+ }
3033
+ static agentInterface(intf) {
3034
+ return {
3035
+ transport: intf.transport ?? "",
3036
+ url: intf.url ?? ""
3037
+ };
3038
+ }
3039
+ static agentProvider(provider) {
3040
+ return {
3041
+ organization: provider.organization ?? "",
3042
+ url: provider.url ?? ""
3043
+ };
3044
+ }
3045
+ static security(security) {
3046
+ return Object.fromEntries(
3047
+ Object.entries(security.schemes)?.map(([key, value]) => [key, value.list])
3048
+ );
3049
+ }
3050
+ static securityScheme(securitySchemes) {
3051
+ switch (securitySchemes.scheme?.$case) {
3052
+ case "apiKeySecurityScheme":
3053
+ return {
3054
+ type: "apiKey",
3055
+ name: securitySchemes.scheme.value.name,
3056
+ in: securitySchemes.scheme.value.location,
3057
+ description: securitySchemes.scheme.value.description
3058
+ };
3059
+ case "httpAuthSecurityScheme":
3060
+ return {
3061
+ type: "http",
3062
+ scheme: securitySchemes.scheme.value.scheme,
3063
+ bearerFormat: securitySchemes.scheme.value.bearerFormat,
3064
+ description: securitySchemes.scheme.value.description
3065
+ };
3066
+ case "mtlsSecurityScheme":
3067
+ return {
3068
+ type: "mutualTLS",
3069
+ description: securitySchemes.scheme.value.description
3070
+ };
3071
+ case "oauth2SecurityScheme":
3072
+ return {
3073
+ type: "oauth2",
3074
+ description: securitySchemes.scheme.value.description,
3075
+ flows: _FromProto.oauthFlows(securitySchemes.scheme.value.flows),
3076
+ oauth2MetadataUrl: securitySchemes.scheme.value.oauth2MetadataUrl
3077
+ };
3078
+ case "openIdConnectSecurityScheme":
3079
+ return {
3080
+ type: "openIdConnect",
3081
+ description: securitySchemes.scheme.value.description,
3082
+ openIdConnectUrl: securitySchemes.scheme.value.openIdConnectUrl
3083
+ };
3084
+ default:
3085
+ throw A2AError.internalError(`Unsupported security scheme type`);
3086
+ }
3087
+ }
3088
+ static oauthFlows(flows) {
3089
+ switch (flows.flow?.$case) {
3090
+ case "implicit":
3091
+ return {
3092
+ implicit: {
3093
+ authorizationUrl: flows.flow.value.authorizationUrl,
3094
+ scopes: flows.flow.value.scopes,
3095
+ refreshUrl: flows.flow.value.refreshUrl
3096
+ }
3097
+ };
3098
+ case "password":
3099
+ return {
3100
+ password: {
3101
+ refreshUrl: flows.flow.value.refreshUrl,
3102
+ scopes: flows.flow.value.scopes,
3103
+ tokenUrl: flows.flow.value.tokenUrl
3104
+ }
3105
+ };
3106
+ case "authorizationCode":
3107
+ return {
3108
+ authorizationCode: {
3109
+ refreshUrl: flows.flow.value.refreshUrl,
3110
+ authorizationUrl: flows.flow.value.authorizationUrl,
3111
+ scopes: flows.flow.value.scopes,
3112
+ tokenUrl: flows.flow.value.tokenUrl
3113
+ }
3114
+ };
3115
+ case "clientCredentials":
3116
+ return {
3117
+ clientCredentials: {
3118
+ refreshUrl: flows.flow.value.refreshUrl,
3119
+ scopes: flows.flow.value.scopes,
3120
+ tokenUrl: flows.flow.value.tokenUrl
3121
+ }
3122
+ };
3123
+ default:
3124
+ throw A2AError.internalError(`Unsupported OAuth flows`);
3125
+ }
3126
+ }
3127
+ static skills(skill) {
3128
+ return {
3129
+ id: skill.id,
3130
+ name: skill.name,
3131
+ description: skill.description,
3132
+ tags: skill.tags,
3133
+ examples: skill.examples,
3134
+ inputModes: skill.inputModes,
3135
+ outputModes: skill.outputModes,
3136
+ security: skill.security?.map((s) => _FromProto.security(s))
3137
+ };
3138
+ }
3139
+ static agentCardSignature(signatures) {
3140
+ return {
3141
+ protected: signatures.protected,
3142
+ signature: signatures.signature,
3143
+ header: signatures.header
3144
+ };
3145
+ }
3146
+ static taskStatusUpdateEvent(event) {
3147
+ return {
3148
+ kind: "status-update",
3149
+ taskId: event.taskId,
3150
+ status: _FromProto.taskStatus(event.status),
3151
+ contextId: event.contextId,
3152
+ metadata: event.metadata,
3153
+ final: event.final
3154
+ };
3155
+ }
3156
+ static taskArtifactUpdateEvent(event) {
3157
+ return {
3158
+ kind: "artifact-update",
3159
+ taskId: event.taskId,
3160
+ artifact: _FromProto.artifact(event.artifact),
3161
+ contextId: event.contextId,
3162
+ metadata: event.metadata,
3163
+ lastChunk: event.lastChunk
3164
+ };
3165
+ }
3166
+ static messageStreamResult(event) {
3167
+ switch (event.payload?.$case) {
3168
+ case "msg": {
3169
+ const message = _FromProto.message(event.payload.value);
3170
+ if (!message) {
3171
+ throw A2AError.internalError("Invalid message in StreamResponse");
3172
+ }
3173
+ return message;
3174
+ }
3175
+ case "task":
3176
+ return _FromProto.task(event.payload.value);
3177
+ case "statusUpdate":
3178
+ return _FromProto.taskStatusUpdateEvent(event.payload.value);
3179
+ case "artifactUpdate":
3180
+ return _FromProto.taskArtifactUpdateEvent(event.payload.value);
3181
+ default:
3182
+ throw A2AError.internalError("Invalid event type in StreamResponse");
3183
+ }
3184
+ }
3185
+ };
3186
+
1118
3187
  // src/client/transports/rest_transport.ts
1119
3188
  var RestTransport = class _RestTransport {
1120
3189
  customFetchImpl;
@@ -1124,23 +3193,44 @@ var RestTransport = class _RestTransport {
1124
3193
  this.customFetchImpl = options.fetchImpl;
1125
3194
  }
1126
3195
  async getExtendedAgentCard(options) {
1127
- return this._sendRequest("GET", "/v1/card", void 0, options);
3196
+ const response = await this._sendRequest(
3197
+ "GET",
3198
+ "/v1/card",
3199
+ void 0,
3200
+ options,
3201
+ void 0,
3202
+ AgentCard
3203
+ );
3204
+ return FromProto.agentCard(response);
1128
3205
  }
1129
3206
  async sendMessage(params, options) {
1130
- return this._sendRequest("POST", "/v1/message:send", params, options);
3207
+ const requestBody = ToProto.messageSendParams(params);
3208
+ const response = await this._sendRequest(
3209
+ "POST",
3210
+ "/v1/message:send",
3211
+ requestBody,
3212
+ options,
3213
+ SendMessageRequest,
3214
+ SendMessageResponse
3215
+ );
3216
+ return FromProto.sendMessageResult(response);
1131
3217
  }
1132
3218
  async *sendMessageStream(params, options) {
1133
- yield* this._sendStreamingRequest("/v1/message:stream", params, options);
3219
+ const protoParams = ToProto.messageSendParams(params);
3220
+ const requestBody = SendMessageRequest.toJSON(protoParams);
3221
+ yield* this._sendStreamingRequest("/v1/message:stream", requestBody, options);
1134
3222
  }
1135
3223
  async setTaskPushNotificationConfig(params, options) {
1136
- return this._sendRequest(
3224
+ const requestBody = ToProto.taskPushNotificationConfig(params);
3225
+ const response = await this._sendRequest(
1137
3226
  "POST",
1138
3227
  `/v1/tasks/${encodeURIComponent(params.taskId)}/pushNotificationConfigs`,
1139
- {
1140
- pushNotificationConfig: params.pushNotificationConfig
1141
- },
1142
- options
3228
+ requestBody,
3229
+ options,
3230
+ TaskPushNotificationConfig,
3231
+ TaskPushNotificationConfig
1143
3232
  );
3233
+ return FromProto.taskPushNotificationConfig(response);
1144
3234
  }
1145
3235
  async getTaskPushNotificationConfig(params, options) {
1146
3236
  const { pushNotificationConfigId } = params;
@@ -1149,27 +3239,35 @@ var RestTransport = class _RestTransport {
1149
3239
  "pushNotificationConfigId is required for getTaskPushNotificationConfig with REST transport."
1150
3240
  );
1151
3241
  }
1152
- return this._sendRequest(
3242
+ const response = await this._sendRequest(
1153
3243
  "GET",
1154
3244
  `/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs/${encodeURIComponent(pushNotificationConfigId)}`,
1155
3245
  void 0,
1156
- options
3246
+ options,
3247
+ void 0,
3248
+ TaskPushNotificationConfig
1157
3249
  );
3250
+ return FromProto.taskPushNotificationConfig(response);
1158
3251
  }
1159
3252
  async listTaskPushNotificationConfig(params, options) {
1160
- return this._sendRequest(
3253
+ const response = await this._sendRequest(
1161
3254
  "GET",
1162
3255
  `/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs`,
1163
3256
  void 0,
1164
- options
3257
+ options,
3258
+ void 0,
3259
+ ListTaskPushNotificationConfigResponse
1165
3260
  );
3261
+ return FromProto.listTaskPushNotificationConfig(response);
1166
3262
  }
1167
3263
  async deleteTaskPushNotificationConfig(params, options) {
1168
3264
  await this._sendRequest(
1169
3265
  "DELETE",
1170
3266
  `/v1/tasks/${encodeURIComponent(params.id)}/pushNotificationConfigs/${encodeURIComponent(params.pushNotificationConfigId)}`,
1171
3267
  void 0,
1172
- options
3268
+ options,
3269
+ void 0,
3270
+ void 0
1173
3271
  );
1174
3272
  }
1175
3273
  async getTask(params, options) {
@@ -1179,15 +3277,26 @@ var RestTransport = class _RestTransport {
1179
3277
  }
1180
3278
  const queryString = queryParams.toString();
1181
3279
  const path = `/v1/tasks/${encodeURIComponent(params.id)}${queryString ? `?${queryString}` : ""}`;
1182
- return this._sendRequest("GET", path, void 0, options);
3280
+ const response = await this._sendRequest(
3281
+ "GET",
3282
+ path,
3283
+ void 0,
3284
+ options,
3285
+ void 0,
3286
+ Task
3287
+ );
3288
+ return FromProto.task(response);
1183
3289
  }
1184
3290
  async cancelTask(params, options) {
1185
- return this._sendRequest(
3291
+ const response = await this._sendRequest(
1186
3292
  "POST",
1187
3293
  `/v1/tasks/${encodeURIComponent(params.id)}:cancel`,
1188
3294
  void 0,
1189
- options
3295
+ options,
3296
+ void 0,
3297
+ Task
1190
3298
  );
3299
+ return FromProto.task(response);
1191
3300
  }
1192
3301
  async *resubscribeTask(params, options) {
1193
3302
  yield* this._sendStreamingRequest(
@@ -1214,7 +3323,7 @@ var RestTransport = class _RestTransport {
1214
3323
  Accept: acceptHeader
1215
3324
  };
1216
3325
  }
1217
- async _sendRequest(method, path, body, options) {
3326
+ async _sendRequest(method, path, body, options, requestType, responseType) {
1218
3327
  const url = `${this.endpoint}${path}`;
1219
3328
  const requestInit = {
1220
3329
  method,
@@ -1222,17 +3331,22 @@ var RestTransport = class _RestTransport {
1222
3331
  signal: options?.signal
1223
3332
  };
1224
3333
  if (body !== void 0 && method !== "GET") {
1225
- requestInit.body = JSON.stringify(body);
3334
+ if (!requestType) {
3335
+ throw new Error(
3336
+ `Bug: Request body provided for ${method} ${path} but no toJson serializer provided.`
3337
+ );
3338
+ }
3339
+ requestInit.body = JSON.stringify(requestType.toJSON(body));
1226
3340
  }
1227
3341
  const response = await this._fetch(url, requestInit);
1228
3342
  if (!response.ok) {
1229
3343
  await this._handleErrorResponse(response, path);
1230
3344
  }
1231
- if (response.status === 204) {
3345
+ if (response.status === 204 || !responseType) {
1232
3346
  return void 0;
1233
3347
  }
1234
3348
  const result = await response.json();
1235
- return result;
3349
+ return responseType.fromJSON(result);
1236
3350
  }
1237
3351
  async _handleErrorResponse(response, path) {
1238
3352
  let errorBodyText = "(empty or non-JSON response)";
@@ -1288,8 +3402,9 @@ var RestTransport = class _RestTransport {
1288
3402
  throw new Error("Attempted to process empty SSE event data.");
1289
3403
  }
1290
3404
  try {
1291
- const data = JSON.parse(jsonData);
1292
- return data;
3405
+ const response = JSON.parse(jsonData);
3406
+ const protoResponse = StreamResponse.fromJSON(response);
3407
+ return FromProto.messageStreamResult(protoResponse);
1293
3408
  } catch (e) {
1294
3409
  console.error("Failed to parse SSE event data:", jsonData, e);
1295
3410
  throw new Error(
@@ -1383,8 +3498,7 @@ var ClientFactory = class {
1383
3498
  }
1384
3499
  this.transportsByName = transportsByName(options.transports);
1385
3500
  for (const transport of options.preferredTransports ?? []) {
1386
- const factory = this.options.transports.find((t) => t.protocolName === transport);
1387
- if (!factory) {
3501
+ if (!this.transportsByName.has(transport)) {
1388
3502
  throw new Error(
1389
3503
  `Unknown preferred transport: ${transport}, available transports: ${[...this.transportsByName.keys()].join()}`
1390
3504
  );
@@ -1400,7 +3514,7 @@ var ClientFactory = class {
1400
3514
  async createFromAgentCard(agentCard) {
1401
3515
  const agentCardPreferred = agentCard.preferredTransport ?? JsonRpcTransportFactory.name;
1402
3516
  const additionalInterfaces = agentCard.additionalInterfaces ?? [];
1403
- const urlsPerAgentTransports = new Map([
3517
+ const urlsPerAgentTransports = new CaseInsensitiveMap([
1404
3518
  [agentCardPreferred, agentCard.url],
1405
3519
  ...additionalInterfaces.map((i) => [i.transport, i.url])
1406
3520
  ]);
@@ -1456,7 +3570,7 @@ function mergeTransports(original, overrides) {
1456
3570
  return Array.from(result.values());
1457
3571
  }
1458
3572
  function transportsByName(transports) {
1459
- const result = /* @__PURE__ */ new Map();
3573
+ const result = new CaseInsensitiveMap();
1460
3574
  if (!transports) {
1461
3575
  return result;
1462
3576
  }
@@ -1474,6 +3588,23 @@ function mergeArrays(a1, a2) {
1474
3588
  }
1475
3589
  return [...a1 ?? [], ...a2 ?? []];
1476
3590
  }
3591
+ var CaseInsensitiveMap = class extends Map {
3592
+ normalizeKey(key) {
3593
+ return key.toUpperCase();
3594
+ }
3595
+ set(key, value) {
3596
+ return super.set(this.normalizeKey(key), value);
3597
+ }
3598
+ get(key) {
3599
+ return super.get(this.normalizeKey(key));
3600
+ }
3601
+ has(key) {
3602
+ return super.has(this.normalizeKey(key));
3603
+ }
3604
+ delete(key) {
3605
+ return super.delete(this.normalizeKey(key));
3606
+ }
3607
+ };
1477
3608
 
1478
3609
  // src/extensions.ts
1479
3610
  var Extensions = {