@a2a-js/sdk 0.3.10 → 0.3.11

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.
@@ -1104,552 +1104,638 @@ var generatePushNotificationConfigName = (taskId, configId) => {
1104
1104
  return `tasks/${taskId}/pushNotificationConfigs/${configId}`;
1105
1105
  };
1106
1106
 
1107
- // src/types/converters/to_proto.ts
1108
- var ToProto = class _ToProto {
1109
- static agentCard(agentCard) {
1110
- return {
1111
- protocolVersion: agentCard.protocolVersion,
1112
- name: agentCard.name,
1113
- description: agentCard.description,
1114
- url: agentCard.url,
1115
- preferredTransport: agentCard.preferredTransport ?? "",
1116
- additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _ToProto.agentInterface(i)) ?? [],
1117
- provider: _ToProto.agentProvider(agentCard.provider),
1118
- version: agentCard.version,
1119
- documentationUrl: agentCard.documentationUrl ?? "",
1120
- capabilities: _ToProto.agentCapabilities(agentCard.capabilities),
1121
- securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
1122
- Object.entries(agentCard.securitySchemes).map(([key, value]) => [
1123
- key,
1124
- _ToProto.securityScheme(value)
1125
- ])
1126
- ) : {},
1127
- security: agentCard.security?.map((s) => _ToProto.security(s)) ?? [],
1128
- defaultInputModes: agentCard.defaultInputModes,
1129
- defaultOutputModes: agentCard.defaultOutputModes,
1130
- skills: agentCard.skills.map((s) => _ToProto.agentSkill(s)),
1131
- supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
1132
- signatures: agentCard.signatures?.map((s) => _ToProto.agentCardSignature(s)) ?? []
1133
- };
1134
- }
1135
- static agentCardSignature(signatures) {
1107
+ // src/types/converters/from_proto.ts
1108
+ var FromProto = class _FromProto {
1109
+ static taskQueryParams(request) {
1136
1110
  return {
1137
- protected: signatures.protected,
1138
- signature: signatures.signature,
1139
- header: signatures.header
1111
+ id: extractTaskId(request.name),
1112
+ historyLength: request.historyLength
1140
1113
  };
1141
1114
  }
1142
- static agentSkill(skill) {
1115
+ static taskIdParams(request) {
1143
1116
  return {
1144
- id: skill.id,
1145
- name: skill.name,
1146
- description: skill.description,
1147
- tags: skill.tags ?? [],
1148
- examples: skill.examples ?? [],
1149
- inputModes: skill.inputModes ?? [],
1150
- outputModes: skill.outputModes ?? [],
1151
- security: skill.security ? skill.security.map((s) => _ToProto.security(s)) : []
1117
+ id: extractTaskId(request.name)
1152
1118
  };
1153
1119
  }
1154
- static security(security) {
1120
+ static getTaskPushNotificationConfigParams(request) {
1121
+ const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
1155
1122
  return {
1156
- schemes: Object.fromEntries(
1157
- Object.entries(security).map(([key, value]) => {
1158
- return [key, { list: value }];
1159
- })
1160
- )
1123
+ id: taskId,
1124
+ pushNotificationConfigId: configId
1161
1125
  };
1162
1126
  }
1163
- static securityScheme(scheme) {
1164
- switch (scheme.type) {
1165
- case "apiKey":
1166
- return {
1167
- scheme: {
1168
- $case: "apiKeySecurityScheme",
1169
- value: {
1170
- name: scheme.name,
1171
- location: scheme.in,
1172
- description: scheme.description ?? ""
1173
- }
1174
- }
1175
- };
1176
- case "http":
1177
- return {
1178
- scheme: {
1179
- $case: "httpAuthSecurityScheme",
1180
- value: {
1181
- description: scheme.description ?? "",
1182
- scheme: scheme.scheme,
1183
- bearerFormat: scheme.bearerFormat ?? ""
1184
- }
1185
- }
1186
- };
1187
- case "mutualTLS":
1188
- return {
1189
- scheme: {
1190
- $case: "mtlsSecurityScheme",
1191
- value: {
1192
- description: scheme.description ?? ""
1193
- }
1194
- }
1195
- };
1196
- case "oauth2":
1197
- return {
1198
- scheme: {
1199
- $case: "oauth2SecurityScheme",
1200
- value: {
1201
- description: scheme.description ?? "",
1202
- flows: _ToProto.oauthFlows(scheme.flows),
1203
- oauth2MetadataUrl: scheme.oauth2MetadataUrl ?? ""
1204
- }
1205
- }
1206
- };
1207
- case "openIdConnect":
1208
- return {
1209
- scheme: {
1210
- $case: "openIdConnectSecurityScheme",
1211
- value: {
1212
- description: scheme.description ?? "",
1213
- openIdConnectUrl: scheme.openIdConnectUrl
1214
- }
1215
- }
1216
- };
1217
- default:
1218
- throw A2AError.internalError(`Unsupported security scheme type`);
1219
- }
1220
- }
1221
- static oauthFlows(flows) {
1222
- if (flows.implicit) {
1223
- return {
1224
- flow: {
1225
- $case: "implicit",
1226
- value: {
1227
- authorizationUrl: flows.implicit.authorizationUrl,
1228
- scopes: flows.implicit.scopes,
1229
- refreshUrl: flows.implicit.refreshUrl ?? ""
1230
- }
1231
- }
1232
- };
1233
- } else if (flows.password) {
1234
- return {
1235
- flow: {
1236
- $case: "password",
1237
- value: {
1238
- tokenUrl: flows.password.tokenUrl,
1239
- scopes: flows.password.scopes,
1240
- refreshUrl: flows.password.refreshUrl ?? ""
1241
- }
1242
- }
1243
- };
1244
- } else if (flows.clientCredentials) {
1245
- return {
1246
- flow: {
1247
- $case: "clientCredentials",
1248
- value: {
1249
- tokenUrl: flows.clientCredentials.tokenUrl,
1250
- scopes: flows.clientCredentials.scopes,
1251
- refreshUrl: flows.clientCredentials.refreshUrl ?? ""
1252
- }
1253
- }
1254
- };
1255
- } else if (flows.authorizationCode) {
1256
- return {
1257
- flow: {
1258
- $case: "authorizationCode",
1259
- value: {
1260
- authorizationUrl: flows.authorizationCode.authorizationUrl,
1261
- tokenUrl: flows.authorizationCode.tokenUrl,
1262
- scopes: flows.authorizationCode.scopes,
1263
- refreshUrl: flows.authorizationCode.refreshUrl ?? ""
1264
- }
1265
- }
1266
- };
1267
- } else {
1268
- throw A2AError.internalError(`Unsupported OAuth flows`);
1269
- }
1270
- }
1271
- static agentInterface(agentInterface) {
1127
+ static listTaskPushNotificationConfigParams(request) {
1272
1128
  return {
1273
- transport: agentInterface.transport,
1274
- url: agentInterface.url
1129
+ id: extractTaskId(request.parent)
1275
1130
  };
1276
1131
  }
1277
- static agentProvider(agentProvider) {
1278
- if (!agentProvider) {
1279
- return void 0;
1132
+ static createTaskPushNotificationConfig(request) {
1133
+ if (!request.config?.pushNotificationConfig) {
1134
+ throw A2AError.invalidParams(
1135
+ "Request must include a `config` object with a `pushNotificationConfig`"
1136
+ );
1280
1137
  }
1281
1138
  return {
1282
- url: agentProvider.url,
1283
- organization: agentProvider.organization
1139
+ taskId: extractTaskId(request.parent),
1140
+ pushNotificationConfig: _FromProto.pushNotificationConfig(
1141
+ request.config.pushNotificationConfig
1142
+ )
1284
1143
  };
1285
1144
  }
1286
- static agentCapabilities(capabilities) {
1145
+ static deleteTaskPushNotificationConfigParams(request) {
1146
+ const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
1287
1147
  return {
1288
- streaming: capabilities.streaming,
1289
- pushNotifications: capabilities.pushNotifications,
1290
- extensions: capabilities.extensions ? capabilities.extensions.map((e) => _ToProto.agentExtension(e)) : []
1148
+ id: taskId,
1149
+ pushNotificationConfigId: configId
1291
1150
  };
1292
1151
  }
1293
- static agentExtension(extension) {
1152
+ static message(message) {
1153
+ if (!message) {
1154
+ return void 0;
1155
+ }
1294
1156
  return {
1295
- uri: extension.uri,
1296
- description: extension.description ?? "",
1297
- required: extension.required ?? false,
1298
- params: extension.params
1157
+ kind: "message",
1158
+ messageId: message.messageId,
1159
+ parts: message.content.map((p) => _FromProto.part(p)),
1160
+ contextId: message.contextId || void 0,
1161
+ taskId: message.taskId || void 0,
1162
+ role: _FromProto.role(message.role),
1163
+ metadata: message.metadata,
1164
+ extensions: message.extensions
1299
1165
  };
1300
1166
  }
1301
- static listTaskPushNotificationConfig(config) {
1302
- return {
1303
- configs: config.map((c) => _ToProto.taskPushNotificationConfig(c)),
1304
- nextPageToken: ""
1305
- };
1167
+ static role(role) {
1168
+ switch (role) {
1169
+ case 2 /* ROLE_AGENT */:
1170
+ return "agent";
1171
+ case 1 /* ROLE_USER */:
1172
+ return "user";
1173
+ default:
1174
+ throw A2AError.invalidParams(`Invalid role: ${role}`);
1175
+ }
1306
1176
  }
1307
- static getTaskPushNotificationConfigParams(config) {
1177
+ static messageSendConfiguration(configuration) {
1178
+ if (!configuration) {
1179
+ return void 0;
1180
+ }
1308
1181
  return {
1309
- name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
1182
+ blocking: configuration.blocking,
1183
+ acceptedOutputModes: configuration.acceptedOutputModes,
1184
+ pushNotificationConfig: _FromProto.pushNotificationConfig(configuration.pushNotification)
1310
1185
  };
1311
1186
  }
1312
- static listTaskPushNotificationConfigParams(config) {
1187
+ static pushNotificationConfig(config) {
1188
+ if (!config) {
1189
+ return void 0;
1190
+ }
1313
1191
  return {
1314
- parent: generateTaskName(config.id),
1315
- pageToken: "",
1316
- pageSize: 0
1192
+ id: config.id,
1193
+ url: config.url,
1194
+ token: config.token || void 0,
1195
+ authentication: _FromProto.pushNotificationAuthenticationInfo(config.authentication)
1317
1196
  };
1318
1197
  }
1319
- static deleteTaskPushNotificationConfigParams(config) {
1198
+ static pushNotificationAuthenticationInfo(authInfo) {
1199
+ if (!authInfo) {
1200
+ return void 0;
1201
+ }
1320
1202
  return {
1321
- name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
1203
+ schemes: authInfo.schemes,
1204
+ credentials: authInfo.credentials
1322
1205
  };
1323
1206
  }
1324
- static taskPushNotificationConfig(config) {
1325
- return {
1326
- name: generatePushNotificationConfigName(
1327
- config.taskId,
1328
- config.pushNotificationConfig.id ?? ""
1329
- ),
1330
- pushNotificationConfig: _ToProto.pushNotificationConfig(config.pushNotificationConfig)
1331
- };
1207
+ static part(part) {
1208
+ if (part.part?.$case === "text") {
1209
+ return {
1210
+ kind: "text",
1211
+ text: part.part.value
1212
+ };
1213
+ }
1214
+ if (part.part?.$case === "file") {
1215
+ const filePart = part.part.value;
1216
+ if (filePart.file?.$case === "fileWithUri") {
1217
+ return {
1218
+ kind: "file",
1219
+ file: {
1220
+ uri: filePart.file.value,
1221
+ mimeType: filePart.mimeType
1222
+ }
1223
+ };
1224
+ } else if (filePart.file?.$case === "fileWithBytes") {
1225
+ return {
1226
+ kind: "file",
1227
+ file: {
1228
+ bytes: filePart.file.value.toString("base64"),
1229
+ mimeType: filePart.mimeType
1230
+ }
1231
+ };
1232
+ }
1233
+ throw A2AError.invalidParams("Invalid file part type");
1234
+ }
1235
+ if (part.part?.$case === "data") {
1236
+ return {
1237
+ kind: "data",
1238
+ data: part.part.value.data
1239
+ };
1240
+ }
1241
+ throw A2AError.invalidParams("Invalid part type");
1332
1242
  }
1333
- static taskPushNotificationConfigCreate(config) {
1243
+ static messageSendParams(request) {
1334
1244
  return {
1335
- parent: generateTaskName(config.taskId),
1336
- config: _ToProto.taskPushNotificationConfig(config),
1337
- configId: config.pushNotificationConfig.id
1245
+ message: _FromProto.message(request.request),
1246
+ configuration: _FromProto.messageSendConfiguration(request.configuration),
1247
+ metadata: request.metadata
1338
1248
  };
1339
1249
  }
1340
- static pushNotificationConfig(config) {
1341
- if (!config) {
1342
- return void 0;
1250
+ static sendMessageResult(response) {
1251
+ if (response.payload?.$case === "task") {
1252
+ return _FromProto.task(response.payload.value);
1253
+ } else if (response.payload?.$case === "msg") {
1254
+ return _FromProto.message(response.payload.value);
1343
1255
  }
1256
+ throw A2AError.invalidParams("Invalid SendMessageResponse: missing result");
1257
+ }
1258
+ static task(task) {
1344
1259
  return {
1345
- id: config.id ?? "",
1346
- url: config.url,
1347
- token: config.token ?? "",
1348
- authentication: _ToProto.pushNotificationAuthenticationInfo(config.authentication)
1260
+ kind: "task",
1261
+ id: task.id,
1262
+ status: _FromProto.taskStatus(task.status),
1263
+ contextId: task.contextId,
1264
+ artifacts: task.artifacts?.map((a) => _FromProto.artifact(a)),
1265
+ history: task.history?.map((h) => _FromProto.message(h)),
1266
+ metadata: task.metadata
1349
1267
  };
1350
1268
  }
1351
- static pushNotificationAuthenticationInfo(authInfo) {
1352
- if (!authInfo) {
1353
- return void 0;
1354
- }
1269
+ static taskStatus(status) {
1355
1270
  return {
1356
- schemes: authInfo.schemes,
1357
- credentials: authInfo.credentials ?? ""
1271
+ message: _FromProto.message(status.update),
1272
+ state: _FromProto.taskState(status.state),
1273
+ timestamp: status.timestamp
1358
1274
  };
1359
1275
  }
1360
- static messageStreamResult(event) {
1361
- if (event.kind === "message") {
1362
- return {
1363
- payload: {
1364
- $case: "msg",
1365
- value: _ToProto.message(event)
1366
- }
1367
- };
1368
- } else if (event.kind === "task") {
1369
- return {
1370
- payload: {
1371
- $case: "task",
1372
- value: _ToProto.task(event)
1373
- }
1374
- };
1375
- } else if (event.kind === "status-update") {
1376
- return {
1377
- payload: {
1378
- $case: "statusUpdate",
1379
- value: _ToProto.taskStatusUpdateEvent(event)
1380
- }
1381
- };
1382
- } else if (event.kind === "artifact-update") {
1383
- return {
1384
- payload: {
1385
- $case: "artifactUpdate",
1386
- value: _ToProto.taskArtifactUpdateEvent(event)
1387
- }
1388
- };
1389
- } else {
1390
- throw A2AError.internalError("Invalid event type");
1276
+ static taskState(state) {
1277
+ switch (state) {
1278
+ case 1 /* TASK_STATE_SUBMITTED */:
1279
+ return "submitted";
1280
+ case 2 /* TASK_STATE_WORKING */:
1281
+ return "working";
1282
+ case 6 /* TASK_STATE_INPUT_REQUIRED */:
1283
+ return "input-required";
1284
+ case 3 /* TASK_STATE_COMPLETED */:
1285
+ return "completed";
1286
+ case 5 /* TASK_STATE_CANCELLED */:
1287
+ return "canceled";
1288
+ case 4 /* TASK_STATE_FAILED */:
1289
+ return "failed";
1290
+ case 7 /* TASK_STATE_REJECTED */:
1291
+ return "rejected";
1292
+ case 8 /* TASK_STATE_AUTH_REQUIRED */:
1293
+ return "auth-required";
1294
+ case 0 /* TASK_STATE_UNSPECIFIED */:
1295
+ return "unknown";
1296
+ default:
1297
+ throw A2AError.invalidParams(`Invalid task state: ${state}`);
1391
1298
  }
1392
1299
  }
1393
- static taskStatusUpdateEvent(event) {
1300
+ static artifact(artifact) {
1394
1301
  return {
1395
- taskId: event.taskId,
1396
- status: _ToProto.taskStatus(event.status),
1397
- contextId: event.contextId,
1398
- metadata: event.metadata,
1399
- final: event.final
1302
+ artifactId: artifact.artifactId,
1303
+ name: artifact.name || void 0,
1304
+ description: artifact.description || void 0,
1305
+ parts: artifact.parts.map((p) => _FromProto.part(p)),
1306
+ metadata: artifact.metadata
1400
1307
  };
1401
1308
  }
1402
- static taskArtifactUpdateEvent(event) {
1309
+ static taskPushNotificationConfig(request) {
1403
1310
  return {
1404
- taskId: event.taskId,
1405
- artifact: _ToProto.artifact(event.artifact),
1406
- contextId: event.contextId,
1407
- metadata: event.metadata,
1408
- append: event.append,
1409
- lastChunk: event.lastChunk
1311
+ taskId: extractTaskId(request.name),
1312
+ pushNotificationConfig: _FromProto.pushNotificationConfig(request.pushNotificationConfig)
1410
1313
  };
1411
1314
  }
1412
- static messageSendResult(params) {
1413
- if (params.kind === "message") {
1414
- return {
1415
- payload: {
1416
- $case: "msg",
1417
- value: _ToProto.message(params)
1418
- }
1419
- };
1420
- } else if (params.kind === "task") {
1421
- return {
1422
- payload: {
1423
- $case: "task",
1424
- value: _ToProto.task(params)
1425
- }
1426
- };
1427
- }
1315
+ static listTaskPushNotificationConfig(request) {
1316
+ return request.configs.map((c) => _FromProto.taskPushNotificationConfig(c));
1428
1317
  }
1429
- static message(message) {
1430
- if (!message) {
1431
- return void 0;
1432
- }
1318
+ static agentCard(agentCard) {
1433
1319
  return {
1434
- messageId: message.messageId,
1435
- content: message.parts.map((p) => _ToProto.part(p)),
1436
- contextId: message.contextId ?? "",
1437
- taskId: message.taskId ?? "",
1438
- role: _ToProto.role(message.role),
1439
- metadata: message.metadata,
1440
- extensions: message.extensions ?? []
1320
+ additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _FromProto.agentInterface(i)),
1321
+ capabilities: agentCard.capabilities ? _FromProto.agentCapabilities(agentCard.capabilities) : {},
1322
+ defaultInputModes: agentCard.defaultInputModes,
1323
+ defaultOutputModes: agentCard.defaultOutputModes,
1324
+ description: agentCard.description,
1325
+ documentationUrl: agentCard.documentationUrl || void 0,
1326
+ name: agentCard.name,
1327
+ preferredTransport: agentCard.preferredTransport,
1328
+ provider: agentCard.provider ? _FromProto.agentProvider(agentCard.provider) : void 0,
1329
+ protocolVersion: agentCard.protocolVersion,
1330
+ security: agentCard.security?.map((s) => _FromProto.security(s)),
1331
+ securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
1332
+ Object.entries(agentCard.securitySchemes).map(([key, value]) => [
1333
+ key,
1334
+ _FromProto.securityScheme(value)
1335
+ ])
1336
+ ) : {},
1337
+ skills: agentCard.skills.map((s) => _FromProto.skills(s)),
1338
+ signatures: agentCard.signatures?.map((s) => _FromProto.agentCardSignature(s)),
1339
+ supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
1340
+ url: agentCard.url,
1341
+ version: agentCard.version
1441
1342
  };
1442
1343
  }
1443
- static role(role) {
1444
- switch (role) {
1445
- case "agent":
1446
- return 2 /* ROLE_AGENT */;
1447
- case "user":
1448
- return 1 /* ROLE_USER */;
1449
- default:
1450
- throw A2AError.internalError(`Invalid role`);
1451
- }
1344
+ static agentCapabilities(capabilities) {
1345
+ return {
1346
+ extensions: capabilities.extensions?.map((e) => _FromProto.agentExtension(e)),
1347
+ pushNotifications: capabilities.pushNotifications,
1348
+ streaming: capabilities.streaming
1349
+ };
1452
1350
  }
1453
- static task(task) {
1351
+ static agentExtension(extension) {
1454
1352
  return {
1455
- id: task.id,
1456
- contextId: task.contextId,
1457
- status: _ToProto.taskStatus(task.status),
1458
- artifacts: task.artifacts?.map((a) => _ToProto.artifact(a)) ?? [],
1459
- history: task.history?.map((m) => _ToProto.message(m)) ?? [],
1460
- metadata: task.metadata
1353
+ uri: extension.uri,
1354
+ description: extension.description || void 0,
1355
+ required: extension.required,
1356
+ params: extension.params
1461
1357
  };
1462
1358
  }
1463
- static taskStatus(status) {
1359
+ static agentInterface(intf) {
1464
1360
  return {
1465
- state: _ToProto.taskState(status.state),
1466
- update: _ToProto.message(status.message),
1467
- timestamp: status.timestamp
1361
+ transport: intf.transport,
1362
+ url: intf.url
1468
1363
  };
1469
1364
  }
1470
- static artifact(artifact) {
1365
+ static agentProvider(provider) {
1471
1366
  return {
1472
- artifactId: artifact.artifactId,
1473
- name: artifact.name ?? "",
1474
- description: artifact.description ?? "",
1475
- parts: artifact.parts.map((p) => _ToProto.part(p)),
1476
- metadata: artifact.metadata,
1477
- extensions: artifact.extensions ? artifact.extensions : []
1367
+ organization: provider.organization,
1368
+ url: provider.url
1478
1369
  };
1479
1370
  }
1480
- static taskState(state) {
1481
- switch (state) {
1482
- case "submitted":
1483
- return 1 /* TASK_STATE_SUBMITTED */;
1484
- case "working":
1485
- return 2 /* TASK_STATE_WORKING */;
1486
- case "input-required":
1487
- return 6 /* TASK_STATE_INPUT_REQUIRED */;
1488
- case "rejected":
1489
- return 7 /* TASK_STATE_REJECTED */;
1490
- case "auth-required":
1491
- return 8 /* TASK_STATE_AUTH_REQUIRED */;
1492
- case "completed":
1493
- return 3 /* TASK_STATE_COMPLETED */;
1494
- case "failed":
1495
- return 4 /* TASK_STATE_FAILED */;
1496
- case "canceled":
1497
- return 5 /* TASK_STATE_CANCELLED */;
1498
- case "unknown":
1499
- return 0 /* TASK_STATE_UNSPECIFIED */;
1371
+ static security(security) {
1372
+ return Object.fromEntries(
1373
+ Object.entries(security.schemes)?.map(([key, value]) => [key, value.list])
1374
+ );
1375
+ }
1376
+ static securityScheme(securitySchemes) {
1377
+ switch (securitySchemes.scheme?.$case) {
1378
+ case "apiKeySecurityScheme":
1379
+ return {
1380
+ type: "apiKey",
1381
+ name: securitySchemes.scheme.value.name,
1382
+ in: securitySchemes.scheme.value.location,
1383
+ description: securitySchemes.scheme.value.description || void 0
1384
+ };
1385
+ case "httpAuthSecurityScheme":
1386
+ return {
1387
+ type: "http",
1388
+ scheme: securitySchemes.scheme.value.scheme,
1389
+ bearerFormat: securitySchemes.scheme.value.bearerFormat || void 0,
1390
+ description: securitySchemes.scheme.value.description || void 0
1391
+ };
1392
+ case "mtlsSecurityScheme":
1393
+ return {
1394
+ type: "mutualTLS",
1395
+ description: securitySchemes.scheme.value.description || void 0
1396
+ };
1397
+ case "oauth2SecurityScheme":
1398
+ return {
1399
+ type: "oauth2",
1400
+ description: securitySchemes.scheme.value.description || void 0,
1401
+ flows: _FromProto.oauthFlows(securitySchemes.scheme.value.flows),
1402
+ oauth2MetadataUrl: securitySchemes.scheme.value.oauth2MetadataUrl || void 0
1403
+ };
1404
+ case "openIdConnectSecurityScheme":
1405
+ return {
1406
+ type: "openIdConnect",
1407
+ description: securitySchemes.scheme.value.description || void 0,
1408
+ openIdConnectUrl: securitySchemes.scheme.value.openIdConnectUrl
1409
+ };
1500
1410
  default:
1501
- return -1 /* UNRECOGNIZED */;
1411
+ throw A2AError.internalError(`Unsupported security scheme type`);
1502
1412
  }
1503
1413
  }
1504
- static part(part) {
1505
- if (part.kind === "text") {
1506
- return {
1507
- part: { $case: "text", value: part.text }
1508
- };
1509
- }
1510
- if (part.kind === "file") {
1511
- let filePart;
1512
- if ("uri" in part.file) {
1513
- filePart = {
1514
- file: { $case: "fileWithUri", value: part.file.uri },
1515
- mimeType: part.file.mimeType
1414
+ static oauthFlows(flows) {
1415
+ switch (flows.flow?.$case) {
1416
+ case "implicit":
1417
+ return {
1418
+ implicit: {
1419
+ authorizationUrl: flows.flow.value.authorizationUrl,
1420
+ scopes: flows.flow.value.scopes,
1421
+ refreshUrl: flows.flow.value.refreshUrl || void 0
1422
+ }
1516
1423
  };
1517
- } else if ("bytes" in part.file) {
1518
- filePart = {
1519
- file: { $case: "fileWithBytes", value: Buffer.from(part.file.bytes, "base64") },
1520
- mimeType: part.file.mimeType
1424
+ case "password":
1425
+ return {
1426
+ password: {
1427
+ refreshUrl: flows.flow.value.refreshUrl || void 0,
1428
+ scopes: flows.flow.value.scopes,
1429
+ tokenUrl: flows.flow.value.tokenUrl
1430
+ }
1521
1431
  };
1522
- } else {
1523
- throw A2AError.internalError("Invalid file part");
1524
- }
1525
- return {
1526
- part: { $case: "file", value: filePart }
1527
- };
1528
- }
1529
- if (part.kind === "data") {
1530
- return {
1531
- part: { $case: "data", value: { data: part.data } }
1532
- };
1432
+ case "authorizationCode":
1433
+ return {
1434
+ authorizationCode: {
1435
+ refreshUrl: flows.flow.value.refreshUrl || void 0,
1436
+ authorizationUrl: flows.flow.value.authorizationUrl,
1437
+ scopes: flows.flow.value.scopes,
1438
+ tokenUrl: flows.flow.value.tokenUrl
1439
+ }
1440
+ };
1441
+ case "clientCredentials":
1442
+ return {
1443
+ clientCredentials: {
1444
+ refreshUrl: flows.flow.value.refreshUrl || void 0,
1445
+ scopes: flows.flow.value.scopes,
1446
+ tokenUrl: flows.flow.value.tokenUrl
1447
+ }
1448
+ };
1449
+ default:
1450
+ throw A2AError.internalError(`Unsupported OAuth flows`);
1533
1451
  }
1534
- throw A2AError.internalError("Invalid part type");
1535
1452
  }
1536
- static messageSendParams(params) {
1453
+ static skills(skill) {
1537
1454
  return {
1538
- request: _ToProto.message(params.message),
1539
- configuration: _ToProto.configuration(params.configuration),
1540
- metadata: params.metadata
1455
+ id: skill.id,
1456
+ name: skill.name,
1457
+ description: skill.description,
1458
+ tags: skill.tags,
1459
+ examples: skill.examples,
1460
+ inputModes: skill.inputModes,
1461
+ outputModes: skill.outputModes,
1462
+ security: skill.security?.map((s) => _FromProto.security(s))
1541
1463
  };
1542
1464
  }
1543
- static configuration(configuration) {
1544
- if (!configuration) {
1545
- return void 0;
1465
+ static agentCardSignature(signatures) {
1466
+ return {
1467
+ protected: signatures.protected,
1468
+ signature: signatures.signature,
1469
+ header: signatures.header
1470
+ };
1471
+ }
1472
+ static taskStatusUpdateEvent(event) {
1473
+ return {
1474
+ kind: "status-update",
1475
+ taskId: event.taskId,
1476
+ status: _FromProto.taskStatus(event.status),
1477
+ contextId: event.contextId,
1478
+ metadata: event.metadata,
1479
+ final: event.final
1480
+ };
1481
+ }
1482
+ static taskArtifactUpdateEvent(event) {
1483
+ return {
1484
+ kind: "artifact-update",
1485
+ taskId: event.taskId,
1486
+ artifact: _FromProto.artifact(event.artifact),
1487
+ contextId: event.contextId,
1488
+ metadata: event.metadata,
1489
+ lastChunk: event.lastChunk
1490
+ };
1491
+ }
1492
+ static messageStreamResult(event) {
1493
+ switch (event.payload?.$case) {
1494
+ case "msg":
1495
+ return _FromProto.message(event.payload.value);
1496
+ case "task":
1497
+ return _FromProto.task(event.payload.value);
1498
+ case "statusUpdate":
1499
+ return _FromProto.taskStatusUpdateEvent(event.payload.value);
1500
+ case "artifactUpdate":
1501
+ return _FromProto.taskArtifactUpdateEvent(event.payload.value);
1502
+ default:
1503
+ throw A2AError.internalError("Invalid event type in StreamResponse");
1546
1504
  }
1505
+ }
1506
+ };
1507
+
1508
+ // src/types/converters/to_proto.ts
1509
+ var ToProto = class _ToProto {
1510
+ static agentCard(agentCard) {
1547
1511
  return {
1548
- blocking: configuration.blocking,
1549
- acceptedOutputModes: configuration.acceptedOutputModes ?? [],
1550
- pushNotification: _ToProto.pushNotificationConfig(configuration.pushNotificationConfig),
1551
- historyLength: configuration.historyLength ?? 0
1512
+ protocolVersion: agentCard.protocolVersion,
1513
+ name: agentCard.name,
1514
+ description: agentCard.description,
1515
+ url: agentCard.url,
1516
+ preferredTransport: agentCard.preferredTransport ?? "",
1517
+ additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _ToProto.agentInterface(i)) ?? [],
1518
+ provider: _ToProto.agentProvider(agentCard.provider),
1519
+ version: agentCard.version,
1520
+ documentationUrl: agentCard.documentationUrl ?? "",
1521
+ capabilities: _ToProto.agentCapabilities(agentCard.capabilities),
1522
+ securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
1523
+ Object.entries(agentCard.securitySchemes).map(([key, value]) => [
1524
+ key,
1525
+ _ToProto.securityScheme(value)
1526
+ ])
1527
+ ) : {},
1528
+ security: agentCard.security?.map((s) => _ToProto.security(s)) ?? [],
1529
+ defaultInputModes: agentCard.defaultInputModes,
1530
+ defaultOutputModes: agentCard.defaultOutputModes,
1531
+ skills: agentCard.skills.map((s) => _ToProto.agentSkill(s)),
1532
+ supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
1533
+ signatures: agentCard.signatures?.map((s) => _ToProto.agentCardSignature(s)) ?? []
1552
1534
  };
1553
1535
  }
1554
- static taskQueryParams(params) {
1536
+ static agentCardSignature(signatures) {
1555
1537
  return {
1556
- name: generateTaskName(params.id),
1557
- historyLength: params.historyLength ?? 0
1538
+ protected: signatures.protected,
1539
+ signature: signatures.signature,
1540
+ header: signatures.header
1558
1541
  };
1559
1542
  }
1560
- static cancelTaskRequest(params) {
1543
+ static agentSkill(skill) {
1561
1544
  return {
1562
- name: generateTaskName(params.id)
1545
+ id: skill.id,
1546
+ name: skill.name,
1547
+ description: skill.description,
1548
+ tags: skill.tags ?? [],
1549
+ examples: skill.examples ?? [],
1550
+ inputModes: skill.inputModes ?? [],
1551
+ outputModes: skill.outputModes ?? [],
1552
+ security: skill.security ? skill.security.map((s) => _ToProto.security(s)) : []
1563
1553
  };
1564
1554
  }
1565
- static taskIdParams(params) {
1555
+ static security(security) {
1566
1556
  return {
1567
- name: generateTaskName(params.id)
1557
+ schemes: Object.fromEntries(
1558
+ Object.entries(security).map(([key, value]) => {
1559
+ return [key, { list: value }];
1560
+ })
1561
+ )
1568
1562
  };
1569
1563
  }
1570
- static getAgentCardRequest() {
1571
- return {};
1564
+ static securityScheme(scheme) {
1565
+ switch (scheme.type) {
1566
+ case "apiKey":
1567
+ return {
1568
+ scheme: {
1569
+ $case: "apiKeySecurityScheme",
1570
+ value: {
1571
+ name: scheme.name,
1572
+ location: scheme.in,
1573
+ description: scheme.description ?? ""
1574
+ }
1575
+ }
1576
+ };
1577
+ case "http":
1578
+ return {
1579
+ scheme: {
1580
+ $case: "httpAuthSecurityScheme",
1581
+ value: {
1582
+ description: scheme.description ?? "",
1583
+ scheme: scheme.scheme,
1584
+ bearerFormat: scheme.bearerFormat ?? ""
1585
+ }
1586
+ }
1587
+ };
1588
+ case "mutualTLS":
1589
+ return {
1590
+ scheme: {
1591
+ $case: "mtlsSecurityScheme",
1592
+ value: {
1593
+ description: scheme.description ?? ""
1594
+ }
1595
+ }
1596
+ };
1597
+ case "oauth2":
1598
+ return {
1599
+ scheme: {
1600
+ $case: "oauth2SecurityScheme",
1601
+ value: {
1602
+ description: scheme.description ?? "",
1603
+ flows: _ToProto.oauthFlows(scheme.flows),
1604
+ oauth2MetadataUrl: scheme.oauth2MetadataUrl ?? ""
1605
+ }
1606
+ }
1607
+ };
1608
+ case "openIdConnect":
1609
+ return {
1610
+ scheme: {
1611
+ $case: "openIdConnectSecurityScheme",
1612
+ value: {
1613
+ description: scheme.description ?? "",
1614
+ openIdConnectUrl: scheme.openIdConnectUrl
1615
+ }
1616
+ }
1617
+ };
1618
+ default:
1619
+ throw A2AError.internalError(`Unsupported security scheme type`);
1620
+ }
1572
1621
  }
1573
- };
1574
-
1575
- // src/types/converters/from_proto.ts
1576
- var FromProto = class _FromProto {
1577
- static taskQueryParams(request) {
1622
+ static oauthFlows(flows) {
1623
+ if (flows.implicit) {
1624
+ return {
1625
+ flow: {
1626
+ $case: "implicit",
1627
+ value: {
1628
+ authorizationUrl: flows.implicit.authorizationUrl,
1629
+ scopes: flows.implicit.scopes,
1630
+ refreshUrl: flows.implicit.refreshUrl ?? ""
1631
+ }
1632
+ }
1633
+ };
1634
+ } else if (flows.password) {
1635
+ return {
1636
+ flow: {
1637
+ $case: "password",
1638
+ value: {
1639
+ tokenUrl: flows.password.tokenUrl,
1640
+ scopes: flows.password.scopes,
1641
+ refreshUrl: flows.password.refreshUrl ?? ""
1642
+ }
1643
+ }
1644
+ };
1645
+ } else if (flows.clientCredentials) {
1646
+ return {
1647
+ flow: {
1648
+ $case: "clientCredentials",
1649
+ value: {
1650
+ tokenUrl: flows.clientCredentials.tokenUrl,
1651
+ scopes: flows.clientCredentials.scopes,
1652
+ refreshUrl: flows.clientCredentials.refreshUrl ?? ""
1653
+ }
1654
+ }
1655
+ };
1656
+ } else if (flows.authorizationCode) {
1657
+ return {
1658
+ flow: {
1659
+ $case: "authorizationCode",
1660
+ value: {
1661
+ authorizationUrl: flows.authorizationCode.authorizationUrl,
1662
+ tokenUrl: flows.authorizationCode.tokenUrl,
1663
+ scopes: flows.authorizationCode.scopes,
1664
+ refreshUrl: flows.authorizationCode.refreshUrl ?? ""
1665
+ }
1666
+ }
1667
+ };
1668
+ } else {
1669
+ throw A2AError.internalError(`Unsupported OAuth flows`);
1670
+ }
1671
+ }
1672
+ static agentInterface(agentInterface) {
1578
1673
  return {
1579
- id: extractTaskId(request.name),
1580
- historyLength: request.historyLength
1674
+ transport: agentInterface.transport,
1675
+ url: agentInterface.url
1676
+ };
1677
+ }
1678
+ static agentProvider(agentProvider) {
1679
+ if (!agentProvider) {
1680
+ return void 0;
1681
+ }
1682
+ return {
1683
+ url: agentProvider.url,
1684
+ organization: agentProvider.organization
1581
1685
  };
1582
1686
  }
1583
- static taskIdParams(request) {
1687
+ static agentCapabilities(capabilities) {
1584
1688
  return {
1585
- id: extractTaskId(request.name)
1689
+ streaming: capabilities.streaming,
1690
+ pushNotifications: capabilities.pushNotifications,
1691
+ extensions: capabilities.extensions ? capabilities.extensions.map((e) => _ToProto.agentExtension(e)) : []
1586
1692
  };
1587
1693
  }
1588
- static getTaskPushNotificationConfigParams(request) {
1589
- const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
1694
+ static agentExtension(extension) {
1590
1695
  return {
1591
- id: taskId,
1592
- pushNotificationConfigId: configId
1696
+ uri: extension.uri,
1697
+ description: extension.description ?? "",
1698
+ required: extension.required ?? false,
1699
+ params: extension.params
1593
1700
  };
1594
1701
  }
1595
- static listTaskPushNotificationConfigParams(request) {
1702
+ static listTaskPushNotificationConfig(config) {
1596
1703
  return {
1597
- id: extractTaskId(request.parent)
1704
+ configs: config.map((c) => _ToProto.taskPushNotificationConfig(c)),
1705
+ nextPageToken: ""
1598
1706
  };
1599
1707
  }
1600
- static createTaskPushNotificationConfig(request) {
1601
- if (!request.config?.pushNotificationConfig) {
1602
- throw A2AError.invalidParams(
1603
- "Request must include a `config` object with a `pushNotificationConfig`"
1604
- );
1605
- }
1708
+ static getTaskPushNotificationConfigParams(config) {
1606
1709
  return {
1607
- taskId: extractTaskId(request.parent),
1608
- pushNotificationConfig: _FromProto.pushNotificationConfig(
1609
- request.config.pushNotificationConfig
1610
- )
1710
+ name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
1611
1711
  };
1612
1712
  }
1613
- static deleteTaskPushNotificationConfigParams(request) {
1614
- const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
1713
+ static listTaskPushNotificationConfigParams(config) {
1615
1714
  return {
1616
- id: taskId,
1617
- pushNotificationConfigId: configId
1715
+ parent: generateTaskName(config.id),
1716
+ pageToken: "",
1717
+ pageSize: 0
1618
1718
  };
1619
1719
  }
1620
- static message(message) {
1621
- if (!message) {
1622
- return void 0;
1623
- }
1720
+ static deleteTaskPushNotificationConfigParams(config) {
1624
1721
  return {
1625
- kind: "message",
1626
- messageId: message.messageId,
1627
- parts: message.content.map((p) => _FromProto.part(p)),
1628
- contextId: message.contextId || void 0,
1629
- taskId: message.taskId || void 0,
1630
- role: _FromProto.role(message.role),
1631
- metadata: message.metadata,
1632
- extensions: message.extensions
1722
+ name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
1633
1723
  };
1634
1724
  }
1635
- static role(role) {
1636
- switch (role) {
1637
- case 2 /* ROLE_AGENT */:
1638
- return "agent";
1639
- case 1 /* ROLE_USER */:
1640
- return "user";
1641
- default:
1642
- throw A2AError.invalidParams(`Invalid role: ${role}`);
1643
- }
1725
+ static taskPushNotificationConfig(config) {
1726
+ return {
1727
+ name: generatePushNotificationConfigName(
1728
+ config.taskId,
1729
+ config.pushNotificationConfig.id ?? ""
1730
+ ),
1731
+ pushNotificationConfig: _ToProto.pushNotificationConfig(config.pushNotificationConfig)
1732
+ };
1644
1733
  }
1645
- static messageSendConfiguration(configuration) {
1646
- if (!configuration) {
1647
- return void 0;
1648
- }
1734
+ static taskPushNotificationConfigCreate(config) {
1649
1735
  return {
1650
- blocking: configuration.blocking,
1651
- acceptedOutputModes: configuration.acceptedOutputModes,
1652
- pushNotificationConfig: _FromProto.pushNotificationConfig(configuration.pushNotification)
1736
+ parent: generateTaskName(config.taskId),
1737
+ config: _ToProto.taskPushNotificationConfig(config),
1738
+ configId: config.pushNotificationConfig.id
1653
1739
  };
1654
1740
  }
1655
1741
  static pushNotificationConfig(config) {
@@ -1657,10 +1743,10 @@ var FromProto = class _FromProto {
1657
1743
  return void 0;
1658
1744
  }
1659
1745
  return {
1660
- id: config.id,
1746
+ id: config.id ?? "",
1661
1747
  url: config.url,
1662
- token: config.token || void 0,
1663
- authentication: _FromProto.pushNotificationAuthenticationInfo(config.authentication)
1748
+ token: config.token ?? "",
1749
+ authentication: _ToProto.pushNotificationAuthenticationInfo(config.authentication)
1664
1750
  };
1665
1751
  }
1666
1752
  static pushNotificationAuthenticationInfo(authInfo) {
@@ -1669,307 +1755,221 @@ var FromProto = class _FromProto {
1669
1755
  }
1670
1756
  return {
1671
1757
  schemes: authInfo.schemes,
1672
- credentials: authInfo.credentials
1758
+ credentials: authInfo.credentials ?? ""
1673
1759
  };
1674
1760
  }
1675
- static part(part) {
1676
- if (part.part?.$case === "text") {
1761
+ static messageStreamResult(event) {
1762
+ if (event.kind === "message") {
1677
1763
  return {
1678
- kind: "text",
1679
- text: part.part.value
1764
+ payload: {
1765
+ $case: "msg",
1766
+ value: _ToProto.message(event)
1767
+ }
1680
1768
  };
1681
- }
1682
- if (part.part?.$case === "file") {
1683
- const filePart = part.part.value;
1684
- if (filePart.file?.$case === "fileWithUri") {
1685
- return {
1686
- kind: "file",
1687
- file: {
1688
- uri: filePart.file.value,
1689
- mimeType: filePart.mimeType
1690
- }
1691
- };
1692
- } else if (filePart.file?.$case === "fileWithBytes") {
1693
- return {
1694
- kind: "file",
1695
- file: {
1696
- bytes: filePart.file.value.toString("base64"),
1697
- mimeType: filePart.mimeType
1698
- }
1699
- };
1700
- }
1701
- throw A2AError.invalidParams("Invalid file part type");
1702
- }
1703
- if (part.part?.$case === "data") {
1769
+ } else if (event.kind === "task") {
1704
1770
  return {
1705
- kind: "data",
1706
- data: part.part.value.data
1771
+ payload: {
1772
+ $case: "task",
1773
+ value: _ToProto.task(event)
1774
+ }
1707
1775
  };
1708
- }
1709
- throw A2AError.invalidParams("Invalid part type");
1710
- }
1711
- static messageSendParams(request) {
1712
- return {
1713
- message: _FromProto.message(request.request),
1714
- configuration: _FromProto.messageSendConfiguration(request.configuration),
1715
- metadata: request.metadata
1716
- };
1717
- }
1718
- static sendMessageResult(response) {
1719
- if (response.payload?.$case === "task") {
1720
- return _FromProto.task(response.payload.value);
1721
- } else if (response.payload?.$case === "msg") {
1722
- return _FromProto.message(response.payload.value);
1723
- }
1724
- throw A2AError.invalidParams("Invalid SendMessageResponse: missing result");
1725
- }
1726
- static task(task) {
1727
- return {
1728
- kind: "task",
1729
- id: task.id,
1730
- status: _FromProto.taskStatus(task.status),
1731
- contextId: task.contextId,
1732
- artifacts: task.artifacts?.map((a) => _FromProto.artifact(a)),
1733
- history: task.history?.map((h) => _FromProto.message(h)),
1734
- metadata: task.metadata
1735
- };
1736
- }
1737
- static taskStatus(status) {
1738
- return {
1739
- message: _FromProto.message(status.update),
1740
- state: _FromProto.taskState(status.state),
1741
- timestamp: status.timestamp
1742
- };
1743
- }
1744
- static taskState(state) {
1745
- switch (state) {
1746
- case 1 /* TASK_STATE_SUBMITTED */:
1747
- return "submitted";
1748
- case 2 /* TASK_STATE_WORKING */:
1749
- return "working";
1750
- case 6 /* TASK_STATE_INPUT_REQUIRED */:
1751
- return "input-required";
1752
- case 3 /* TASK_STATE_COMPLETED */:
1753
- return "completed";
1754
- case 5 /* TASK_STATE_CANCELLED */:
1755
- return "canceled";
1756
- case 4 /* TASK_STATE_FAILED */:
1757
- return "failed";
1758
- case 7 /* TASK_STATE_REJECTED */:
1759
- return "rejected";
1760
- case 8 /* TASK_STATE_AUTH_REQUIRED */:
1761
- return "auth-required";
1762
- case 0 /* TASK_STATE_UNSPECIFIED */:
1763
- return "unknown";
1764
- default:
1765
- throw A2AError.invalidParams(`Invalid task state: ${state}`);
1776
+ } else if (event.kind === "status-update") {
1777
+ return {
1778
+ payload: {
1779
+ $case: "statusUpdate",
1780
+ value: _ToProto.taskStatusUpdateEvent(event)
1781
+ }
1782
+ };
1783
+ } else if (event.kind === "artifact-update") {
1784
+ return {
1785
+ payload: {
1786
+ $case: "artifactUpdate",
1787
+ value: _ToProto.taskArtifactUpdateEvent(event)
1788
+ }
1789
+ };
1790
+ } else {
1791
+ throw A2AError.internalError("Invalid event type");
1766
1792
  }
1767
1793
  }
1768
- static artifact(artifact) {
1794
+ static taskStatusUpdateEvent(event) {
1769
1795
  return {
1770
- artifactId: artifact.artifactId,
1771
- name: artifact.name || void 0,
1772
- description: artifact.description || void 0,
1773
- parts: artifact.parts.map((p) => _FromProto.part(p)),
1774
- metadata: artifact.metadata
1796
+ taskId: event.taskId,
1797
+ status: _ToProto.taskStatus(event.status),
1798
+ contextId: event.contextId,
1799
+ metadata: event.metadata,
1800
+ final: event.final
1775
1801
  };
1776
1802
  }
1777
- static taskPushNotificationConfig(request) {
1803
+ static taskArtifactUpdateEvent(event) {
1778
1804
  return {
1779
- taskId: extractTaskId(request.name),
1780
- pushNotificationConfig: _FromProto.pushNotificationConfig(request.pushNotificationConfig)
1805
+ taskId: event.taskId,
1806
+ artifact: _ToProto.artifact(event.artifact),
1807
+ contextId: event.contextId,
1808
+ metadata: event.metadata,
1809
+ append: event.append,
1810
+ lastChunk: event.lastChunk
1781
1811
  };
1782
1812
  }
1783
- static listTaskPushNotificationConfig(request) {
1784
- return request.configs.map((c) => _FromProto.taskPushNotificationConfig(c));
1785
- }
1786
- static agentCard(agentCard) {
1787
- return {
1788
- additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _FromProto.agentInterface(i)),
1789
- capabilities: agentCard.capabilities ? _FromProto.agentCapabilities(agentCard.capabilities) : {},
1790
- defaultInputModes: agentCard.defaultInputModes,
1791
- defaultOutputModes: agentCard.defaultOutputModes,
1792
- description: agentCard.description,
1793
- documentationUrl: agentCard.documentationUrl || void 0,
1794
- name: agentCard.name,
1795
- preferredTransport: agentCard.preferredTransport,
1796
- provider: agentCard.provider ? _FromProto.agentProvider(agentCard.provider) : void 0,
1797
- protocolVersion: agentCard.protocolVersion,
1798
- security: agentCard.security?.map((s) => _FromProto.security(s)),
1799
- securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
1800
- Object.entries(agentCard.securitySchemes).map(([key, value]) => [
1801
- key,
1802
- _FromProto.securityScheme(value)
1803
- ])
1804
- ) : {},
1805
- skills: agentCard.skills.map((s) => _FromProto.skills(s)),
1806
- signatures: agentCard.signatures?.map((s) => _FromProto.agentCardSignature(s)),
1807
- supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
1808
- url: agentCard.url,
1809
- version: agentCard.version
1810
- };
1813
+ static messageSendResult(params) {
1814
+ if (params.kind === "message") {
1815
+ return {
1816
+ payload: {
1817
+ $case: "msg",
1818
+ value: _ToProto.message(params)
1819
+ }
1820
+ };
1821
+ } else if (params.kind === "task") {
1822
+ return {
1823
+ payload: {
1824
+ $case: "task",
1825
+ value: _ToProto.task(params)
1826
+ }
1827
+ };
1828
+ }
1811
1829
  }
1812
- static agentCapabilities(capabilities) {
1830
+ static message(message) {
1831
+ if (!message) {
1832
+ return void 0;
1833
+ }
1813
1834
  return {
1814
- extensions: capabilities.extensions?.map((e) => _FromProto.agentExtension(e)),
1815
- pushNotifications: capabilities.pushNotifications,
1816
- streaming: capabilities.streaming
1835
+ messageId: message.messageId,
1836
+ content: message.parts.map((p) => _ToProto.part(p)),
1837
+ contextId: message.contextId ?? "",
1838
+ taskId: message.taskId ?? "",
1839
+ role: _ToProto.role(message.role),
1840
+ metadata: message.metadata,
1841
+ extensions: message.extensions ?? []
1817
1842
  };
1818
1843
  }
1819
- static agentExtension(extension) {
1844
+ static role(role) {
1845
+ switch (role) {
1846
+ case "agent":
1847
+ return 2 /* ROLE_AGENT */;
1848
+ case "user":
1849
+ return 1 /* ROLE_USER */;
1850
+ default:
1851
+ throw A2AError.internalError(`Invalid role`);
1852
+ }
1853
+ }
1854
+ static task(task) {
1820
1855
  return {
1821
- uri: extension.uri,
1822
- description: extension.description || void 0,
1823
- required: extension.required,
1824
- params: extension.params
1856
+ id: task.id,
1857
+ contextId: task.contextId,
1858
+ status: _ToProto.taskStatus(task.status),
1859
+ artifacts: task.artifacts?.map((a) => _ToProto.artifact(a)) ?? [],
1860
+ history: task.history?.map((m) => _ToProto.message(m)) ?? [],
1861
+ metadata: task.metadata
1825
1862
  };
1826
1863
  }
1827
- static agentInterface(intf) {
1864
+ static taskStatus(status) {
1828
1865
  return {
1829
- transport: intf.transport,
1830
- url: intf.url
1866
+ state: _ToProto.taskState(status.state),
1867
+ update: _ToProto.message(status.message),
1868
+ timestamp: status.timestamp
1831
1869
  };
1832
1870
  }
1833
- static agentProvider(provider) {
1871
+ static artifact(artifact) {
1834
1872
  return {
1835
- organization: provider.organization,
1836
- url: provider.url
1873
+ artifactId: artifact.artifactId,
1874
+ name: artifact.name ?? "",
1875
+ description: artifact.description ?? "",
1876
+ parts: artifact.parts.map((p) => _ToProto.part(p)),
1877
+ metadata: artifact.metadata,
1878
+ extensions: artifact.extensions ? artifact.extensions : []
1837
1879
  };
1838
1880
  }
1839
- static security(security) {
1840
- return Object.fromEntries(
1841
- Object.entries(security.schemes)?.map(([key, value]) => [key, value.list])
1842
- );
1843
- }
1844
- static securityScheme(securitySchemes) {
1845
- switch (securitySchemes.scheme?.$case) {
1846
- case "apiKeySecurityScheme":
1847
- return {
1848
- type: "apiKey",
1849
- name: securitySchemes.scheme.value.name,
1850
- in: securitySchemes.scheme.value.location,
1851
- description: securitySchemes.scheme.value.description || void 0
1852
- };
1853
- case "httpAuthSecurityScheme":
1854
- return {
1855
- type: "http",
1856
- scheme: securitySchemes.scheme.value.scheme,
1857
- bearerFormat: securitySchemes.scheme.value.bearerFormat || void 0,
1858
- description: securitySchemes.scheme.value.description || void 0
1859
- };
1860
- case "mtlsSecurityScheme":
1861
- return {
1862
- type: "mutualTLS",
1863
- description: securitySchemes.scheme.value.description || void 0
1864
- };
1865
- case "oauth2SecurityScheme":
1866
- return {
1867
- type: "oauth2",
1868
- description: securitySchemes.scheme.value.description || void 0,
1869
- flows: _FromProto.oauthFlows(securitySchemes.scheme.value.flows),
1870
- oauth2MetadataUrl: securitySchemes.scheme.value.oauth2MetadataUrl || void 0
1871
- };
1872
- case "openIdConnectSecurityScheme":
1873
- return {
1874
- type: "openIdConnect",
1875
- description: securitySchemes.scheme.value.description || void 0,
1876
- openIdConnectUrl: securitySchemes.scheme.value.openIdConnectUrl
1877
- };
1881
+ static taskState(state) {
1882
+ switch (state) {
1883
+ case "submitted":
1884
+ return 1 /* TASK_STATE_SUBMITTED */;
1885
+ case "working":
1886
+ return 2 /* TASK_STATE_WORKING */;
1887
+ case "input-required":
1888
+ return 6 /* TASK_STATE_INPUT_REQUIRED */;
1889
+ case "rejected":
1890
+ return 7 /* TASK_STATE_REJECTED */;
1891
+ case "auth-required":
1892
+ return 8 /* TASK_STATE_AUTH_REQUIRED */;
1893
+ case "completed":
1894
+ return 3 /* TASK_STATE_COMPLETED */;
1895
+ case "failed":
1896
+ return 4 /* TASK_STATE_FAILED */;
1897
+ case "canceled":
1898
+ return 5 /* TASK_STATE_CANCELLED */;
1899
+ case "unknown":
1900
+ return 0 /* TASK_STATE_UNSPECIFIED */;
1878
1901
  default:
1879
- throw A2AError.internalError(`Unsupported security scheme type`);
1902
+ return -1 /* UNRECOGNIZED */;
1880
1903
  }
1881
1904
  }
1882
- static oauthFlows(flows) {
1883
- switch (flows.flow?.$case) {
1884
- case "implicit":
1885
- return {
1886
- implicit: {
1887
- authorizationUrl: flows.flow.value.authorizationUrl,
1888
- scopes: flows.flow.value.scopes,
1889
- refreshUrl: flows.flow.value.refreshUrl || void 0
1890
- }
1891
- };
1892
- case "password":
1893
- return {
1894
- password: {
1895
- refreshUrl: flows.flow.value.refreshUrl || void 0,
1896
- scopes: flows.flow.value.scopes,
1897
- tokenUrl: flows.flow.value.tokenUrl
1898
- }
1899
- };
1900
- case "authorizationCode":
1901
- return {
1902
- authorizationCode: {
1903
- refreshUrl: flows.flow.value.refreshUrl || void 0,
1904
- authorizationUrl: flows.flow.value.authorizationUrl,
1905
- scopes: flows.flow.value.scopes,
1906
- tokenUrl: flows.flow.value.tokenUrl
1907
- }
1905
+ static part(part) {
1906
+ if (part.kind === "text") {
1907
+ return {
1908
+ part: { $case: "text", value: part.text }
1909
+ };
1910
+ }
1911
+ if (part.kind === "file") {
1912
+ let filePart;
1913
+ if ("uri" in part.file) {
1914
+ filePart = {
1915
+ file: { $case: "fileWithUri", value: part.file.uri },
1916
+ mimeType: part.file.mimeType
1908
1917
  };
1909
- case "clientCredentials":
1910
- return {
1911
- clientCredentials: {
1912
- refreshUrl: flows.flow.value.refreshUrl || void 0,
1913
- scopes: flows.flow.value.scopes,
1914
- tokenUrl: flows.flow.value.tokenUrl
1915
- }
1918
+ } else if ("bytes" in part.file) {
1919
+ filePart = {
1920
+ file: { $case: "fileWithBytes", value: Buffer.from(part.file.bytes, "base64") },
1921
+ mimeType: part.file.mimeType
1916
1922
  };
1917
- default:
1918
- throw A2AError.internalError(`Unsupported OAuth flows`);
1923
+ } else {
1924
+ throw A2AError.internalError("Invalid file part");
1925
+ }
1926
+ return {
1927
+ part: { $case: "file", value: filePart }
1928
+ };
1929
+ }
1930
+ if (part.kind === "data") {
1931
+ return {
1932
+ part: { $case: "data", value: { data: part.data } }
1933
+ };
1919
1934
  }
1935
+ throw A2AError.internalError("Invalid part type");
1920
1936
  }
1921
- static skills(skill) {
1937
+ static messageSendParams(params) {
1922
1938
  return {
1923
- id: skill.id,
1924
- name: skill.name,
1925
- description: skill.description,
1926
- tags: skill.tags,
1927
- examples: skill.examples,
1928
- inputModes: skill.inputModes,
1929
- outputModes: skill.outputModes,
1930
- security: skill.security?.map((s) => _FromProto.security(s))
1939
+ request: _ToProto.message(params.message),
1940
+ configuration: _ToProto.configuration(params.configuration),
1941
+ metadata: params.metadata
1931
1942
  };
1932
1943
  }
1933
- static agentCardSignature(signatures) {
1944
+ static configuration(configuration) {
1945
+ if (!configuration) {
1946
+ return void 0;
1947
+ }
1934
1948
  return {
1935
- protected: signatures.protected,
1936
- signature: signatures.signature,
1937
- header: signatures.header
1949
+ blocking: configuration.blocking,
1950
+ acceptedOutputModes: configuration.acceptedOutputModes ?? [],
1951
+ pushNotification: _ToProto.pushNotificationConfig(configuration.pushNotificationConfig),
1952
+ historyLength: configuration.historyLength ?? 0
1938
1953
  };
1939
1954
  }
1940
- static taskStatusUpdateEvent(event) {
1955
+ static taskQueryParams(params) {
1941
1956
  return {
1942
- kind: "status-update",
1943
- taskId: event.taskId,
1944
- status: _FromProto.taskStatus(event.status),
1945
- contextId: event.contextId,
1946
- metadata: event.metadata,
1947
- final: event.final
1957
+ name: generateTaskName(params.id),
1958
+ historyLength: params.historyLength ?? 0
1948
1959
  };
1949
1960
  }
1950
- static taskArtifactUpdateEvent(event) {
1961
+ static cancelTaskRequest(params) {
1951
1962
  return {
1952
- kind: "artifact-update",
1953
- taskId: event.taskId,
1954
- artifact: _FromProto.artifact(event.artifact),
1955
- contextId: event.contextId,
1956
- metadata: event.metadata,
1957
- lastChunk: event.lastChunk
1963
+ name: generateTaskName(params.id)
1958
1964
  };
1959
1965
  }
1960
- static messageStreamResult(event) {
1961
- switch (event.payload?.$case) {
1962
- case "msg":
1963
- return _FromProto.message(event.payload.value);
1964
- case "task":
1965
- return _FromProto.task(event.payload.value);
1966
- case "statusUpdate":
1967
- return _FromProto.taskStatusUpdateEvent(event.payload.value);
1968
- case "artifactUpdate":
1969
- return _FromProto.taskArtifactUpdateEvent(event.payload.value);
1970
- default:
1971
- throw A2AError.internalError("Invalid event type in StreamResponse");
1972
- }
1966
+ static taskIdParams(params) {
1967
+ return {
1968
+ name: generateTaskName(params.id)
1969
+ };
1970
+ }
1971
+ static getAgentCardRequest() {
1972
+ return {};
1973
1973
  }
1974
1974
  };
1975
1975
 
@@ -1981,6 +1981,6 @@ export {
1981
1981
  SendMessageResponse,
1982
1982
  StreamResponse,
1983
1983
  ListTaskPushNotificationConfigResponse,
1984
- ToProto,
1985
- FromProto
1984
+ FromProto,
1985
+ ToProto
1986
1986
  };