@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.
@@ -264,8 +264,8 @@ var JsonRpcTransport = class _JsonRpcTransport {
264
264
  }
265
265
  const rpcResponse = await httpResponse.json();
266
266
  if (rpcResponse.id !== requestId) {
267
- console.error(
268
- `CRITICAL: RPC response ID mismatch for method ${method}. Expected ${requestId}, got ${rpcResponse.id}.`
267
+ throw new Error(
268
+ `JSON-RPC response ID mismatch for method ${method}. Expected ${requestId}, got ${rpcResponse.id}.`
269
269
  );
270
270
  }
271
271
  if ("error" in rpcResponse) {
@@ -329,38 +329,31 @@ var JsonRpcTransport = class _JsonRpcTransport {
329
329
  if (!jsonData.trim()) {
330
330
  throw new Error("Attempted to process empty SSE event data.");
331
331
  }
332
+ let a2aStreamResponse;
332
333
  try {
333
- const sseJsonRpcResponse = JSON.parse(jsonData);
334
- const a2aStreamResponse = sseJsonRpcResponse;
335
- if (a2aStreamResponse.id !== originalRequestId) {
336
- console.warn(
337
- `SSE Event's JSON-RPC response ID mismatch. Client request ID: ${originalRequestId}, event response ID: ${a2aStreamResponse.id}.`
338
- );
339
- }
340
- if ("error" in a2aStreamResponse) {
341
- const err = a2aStreamResponse.error;
342
- throw new Error(
343
- `SSE event contained an error: ${err.message} (Code: ${err.code}) Data: ${JSON.stringify(err.data || {})}`,
344
- { cause: _JsonRpcTransport.mapToError(a2aStreamResponse) }
345
- );
346
- }
347
- if (!("result" in a2aStreamResponse) || typeof a2aStreamResponse.result === "undefined") {
348
- throw new Error(`SSE event JSON-RPC response is missing 'result' field. Data: ${jsonData}`);
349
- }
350
- return a2aStreamResponse.result;
334
+ a2aStreamResponse = JSON.parse(jsonData);
351
335
  } catch (e) {
352
- if (e instanceof Error && (e.message.startsWith("SSE event contained an error") || e.message.startsWith("SSE event JSON-RPC response is missing 'result' field"))) {
353
- throw e;
354
- }
355
- console.error(
356
- "Failed to parse SSE event data string or unexpected JSON-RPC structure:",
357
- jsonData,
358
- e
336
+ throw new Error(
337
+ `Failed to parse SSE event data: "${jsonData.substring(0, 100)}...". Original error: ${e instanceof Error && e.message || "Unknown error"}`,
338
+ { cause: e }
359
339
  );
340
+ }
341
+ if (a2aStreamResponse.id !== originalRequestId) {
360
342
  throw new Error(
361
- `Failed to parse SSE event data: "${jsonData.substring(0, 100)}...". Original error: ${e instanceof Error && e.message || "Unknown error"}`
343
+ `JSON-RPC response ID mismatch in SSE event. Expected ${originalRequestId}, got ${a2aStreamResponse.id}.`
362
344
  );
363
345
  }
346
+ if ("error" in a2aStreamResponse) {
347
+ const err = a2aStreamResponse.error;
348
+ throw new Error(
349
+ `SSE event contained an error: ${err.message} (Code: ${err.code}) Data: ${JSON.stringify(err.data || {})}`,
350
+ { cause: _JsonRpcTransport.mapToError(a2aStreamResponse) }
351
+ );
352
+ }
353
+ if (!("result" in a2aStreamResponse) || typeof a2aStreamResponse.result === "undefined") {
354
+ throw new Error(`SSE event JSON-RPC response is missing 'result' field. Data: ${jsonData}`);
355
+ }
356
+ return a2aStreamResponse.result;
364
357
  }
365
358
  static mapToError(response) {
366
359
  switch (response.error.code) {
@@ -833,586 +826,229 @@ function createAuthenticatingFetchWithRetry(fetchImpl, authHandler) {
833
826
  return authFetch;
834
827
  }
835
828
 
836
- // src/client/card-resolver.ts
837
- var DefaultAgentCardResolver = class {
838
- constructor(options) {
839
- this.options = options;
840
- }
841
- /**
842
- * Fetches the agent card based on provided base URL and path.
843
- * Path is selected in the following order:
844
- * 1) path parameter
845
- * 2) path from options
846
- * 3) .well-known/agent-card.json
847
- */
848
- async resolve(baseUrl, path) {
849
- const agentCardUrl = new URL(path ?? this.options?.path ?? AGENT_CARD_PATH, baseUrl);
850
- const response = await this.fetchImpl(agentCardUrl);
851
- if (!response.ok) {
852
- throw new Error(`Failed to fetch Agent Card from ${agentCardUrl}: ${response.status}`);
853
- }
854
- return await response.json();
855
- }
856
- fetchImpl(...args) {
857
- if (this.options?.fetchImpl) {
858
- return this.options.fetchImpl(...args);
859
- }
860
- return fetch(...args);
829
+ // src/types/pb/a2a_types.ts
830
+ function taskStateFromJSON(object) {
831
+ switch (object) {
832
+ case 0:
833
+ case "TASK_STATE_UNSPECIFIED":
834
+ return 0 /* TASK_STATE_UNSPECIFIED */;
835
+ case 1:
836
+ case "TASK_STATE_SUBMITTED":
837
+ return 1 /* TASK_STATE_SUBMITTED */;
838
+ case 2:
839
+ case "TASK_STATE_WORKING":
840
+ return 2 /* TASK_STATE_WORKING */;
841
+ case 3:
842
+ case "TASK_STATE_COMPLETED":
843
+ return 3 /* TASK_STATE_COMPLETED */;
844
+ case 4:
845
+ case "TASK_STATE_FAILED":
846
+ return 4 /* TASK_STATE_FAILED */;
847
+ case 5:
848
+ case "TASK_STATE_CANCELLED":
849
+ return 5 /* TASK_STATE_CANCELLED */;
850
+ case 6:
851
+ case "TASK_STATE_INPUT_REQUIRED":
852
+ return 6 /* TASK_STATE_INPUT_REQUIRED */;
853
+ case 7:
854
+ case "TASK_STATE_REJECTED":
855
+ return 7 /* TASK_STATE_REJECTED */;
856
+ case 8:
857
+ case "TASK_STATE_AUTH_REQUIRED":
858
+ return 8 /* TASK_STATE_AUTH_REQUIRED */;
859
+ case -1:
860
+ case "UNRECOGNIZED":
861
+ default:
862
+ return -1 /* UNRECOGNIZED */;
861
863
  }
862
- };
863
- var AgentCardResolver = {
864
- default: new DefaultAgentCardResolver()
865
- };
866
-
867
- // src/client/multitransport-client.ts
868
- var Client = class {
869
- constructor(transport, agentCard, config) {
870
- this.transport = transport;
871
- this.agentCard = agentCard;
872
- this.config = config;
864
+ }
865
+ function taskStateToJSON(object) {
866
+ switch (object) {
867
+ case 0 /* TASK_STATE_UNSPECIFIED */:
868
+ return "TASK_STATE_UNSPECIFIED";
869
+ case 1 /* TASK_STATE_SUBMITTED */:
870
+ return "TASK_STATE_SUBMITTED";
871
+ case 2 /* TASK_STATE_WORKING */:
872
+ return "TASK_STATE_WORKING";
873
+ case 3 /* TASK_STATE_COMPLETED */:
874
+ return "TASK_STATE_COMPLETED";
875
+ case 4 /* TASK_STATE_FAILED */:
876
+ return "TASK_STATE_FAILED";
877
+ case 5 /* TASK_STATE_CANCELLED */:
878
+ return "TASK_STATE_CANCELLED";
879
+ case 6 /* TASK_STATE_INPUT_REQUIRED */:
880
+ return "TASK_STATE_INPUT_REQUIRED";
881
+ case 7 /* TASK_STATE_REJECTED */:
882
+ return "TASK_STATE_REJECTED";
883
+ case 8 /* TASK_STATE_AUTH_REQUIRED */:
884
+ return "TASK_STATE_AUTH_REQUIRED";
885
+ case -1 /* UNRECOGNIZED */:
886
+ default:
887
+ return "UNRECOGNIZED";
873
888
  }
874
- /**
875
- * If the current agent card supports the extended feature, it will try to fetch the extended agent card from the server,
876
- * Otherwise it will return the current agent card value.
877
- */
878
- async getAgentCard(options) {
879
- if (this.agentCard.supportsAuthenticatedExtendedCard) {
880
- this.agentCard = await this.executeWithInterceptors(
881
- { method: "getAgentCard" },
882
- options,
883
- (_, options2) => this.transport.getExtendedAgentCard(options2)
884
- );
885
- }
886
- return this.agentCard;
889
+ }
890
+ function roleFromJSON(object) {
891
+ switch (object) {
892
+ case 0:
893
+ case "ROLE_UNSPECIFIED":
894
+ return 0 /* ROLE_UNSPECIFIED */;
895
+ case 1:
896
+ case "ROLE_USER":
897
+ return 1 /* ROLE_USER */;
898
+ case 2:
899
+ case "ROLE_AGENT":
900
+ return 2 /* ROLE_AGENT */;
901
+ case -1:
902
+ case "UNRECOGNIZED":
903
+ default:
904
+ return -1 /* UNRECOGNIZED */;
887
905
  }
888
- /**
889
- * Sends a message to an agent to initiate a new interaction or to continue an existing one.
890
- * Uses blocking mode by default.
891
- */
892
- sendMessage(params, options) {
893
- params = this.applyClientConfig({
894
- params,
895
- blocking: !(this.config?.polling ?? false)
896
- });
897
- return this.executeWithInterceptors(
898
- { method: "sendMessage", value: params },
899
- options,
900
- this.transport.sendMessage.bind(this.transport)
901
- );
906
+ }
907
+ function roleToJSON(object) {
908
+ switch (object) {
909
+ case 0 /* ROLE_UNSPECIFIED */:
910
+ return "ROLE_UNSPECIFIED";
911
+ case 1 /* ROLE_USER */:
912
+ return "ROLE_USER";
913
+ case 2 /* ROLE_AGENT */:
914
+ return "ROLE_AGENT";
915
+ case -1 /* UNRECOGNIZED */:
916
+ default:
917
+ return "UNRECOGNIZED";
902
918
  }
903
- /**
904
- * Sends a message to an agent to initiate/continue a task AND subscribes the client to real-time updates for that task.
905
- * Performs fallback to non-streaming if not supported by the agent.
906
- */
907
- async *sendMessageStream(params, options) {
908
- const method = "sendMessageStream";
909
- params = this.applyClientConfig({ params, blocking: true });
910
- const beforeArgs = {
911
- input: { method, value: params },
912
- agentCard: this.agentCard,
913
- options
919
+ }
920
+ var SendMessageConfiguration = {
921
+ fromJSON(object) {
922
+ return {
923
+ 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(
924
+ (e) => globalThis.String(e)
925
+ ) : [],
926
+ pushNotification: isSet(object.pushNotification) ? PushNotificationConfig.fromJSON(object.pushNotification) : isSet(object.push_notification) ? PushNotificationConfig.fromJSON(object.push_notification) : void 0,
927
+ historyLength: isSet(object.historyLength) ? globalThis.Number(object.historyLength) : isSet(object.history_length) ? globalThis.Number(object.history_length) : 0,
928
+ blocking: isSet(object.blocking) ? globalThis.Boolean(object.blocking) : false
914
929
  };
915
- const beforeResult = await this.interceptBefore(beforeArgs);
916
- if (beforeResult) {
917
- const earlyReturn = beforeResult.earlyReturn.value;
918
- const afterArgs = {
919
- result: { method, value: earlyReturn },
920
- agentCard: this.agentCard,
921
- options: beforeArgs.options
922
- };
923
- await this.interceptAfter(afterArgs, beforeResult.executed);
924
- yield afterArgs.result.value;
925
- return;
930
+ },
931
+ toJSON(message) {
932
+ const obj = {};
933
+ if (message.acceptedOutputModes?.length) {
934
+ obj.acceptedOutputModes = message.acceptedOutputModes;
926
935
  }
927
- if (!this.agentCard.capabilities.streaming) {
928
- const result = await this.transport.sendMessage(beforeArgs.input.value, beforeArgs.options);
929
- const afterArgs = {
930
- result: { method, value: result },
931
- agentCard: this.agentCard,
932
- options: beforeArgs.options
933
- };
934
- await this.interceptAfter(afterArgs);
935
- yield afterArgs.result.value;
936
- return;
936
+ if (message.pushNotification !== void 0) {
937
+ obj.pushNotification = PushNotificationConfig.toJSON(message.pushNotification);
937
938
  }
938
- for await (const event of this.transport.sendMessageStream(
939
- beforeArgs.input.value,
940
- beforeArgs.options
941
- )) {
942
- const afterArgs = {
943
- result: { method, value: event },
944
- agentCard: this.agentCard,
945
- options: beforeArgs.options
946
- };
947
- await this.interceptAfter(afterArgs);
948
- yield afterArgs.result.value;
949
- if (afterArgs.earlyReturn) {
950
- return;
951
- }
939
+ if (message.historyLength !== 0) {
940
+ obj.historyLength = Math.round(message.historyLength);
952
941
  }
953
- }
954
- /**
955
- * Sets or updates the push notification configuration for a specified task.
956
- * Requires the server to have AgentCard.capabilities.pushNotifications: true.
957
- */
958
- setTaskPushNotificationConfig(params, options) {
959
- if (!this.agentCard.capabilities.pushNotifications) {
960
- throw new PushNotificationNotSupportedError();
942
+ if (message.blocking !== false) {
943
+ obj.blocking = message.blocking;
961
944
  }
962
- return this.executeWithInterceptors(
963
- { method: "setTaskPushNotificationConfig", value: params },
964
- options,
965
- this.transport.setTaskPushNotificationConfig.bind(this.transport)
966
- );
945
+ return obj;
967
946
  }
968
- /**
969
- * Retrieves the current push notification configuration for a specified task.
970
- * Requires the server to have AgentCard.capabilities.pushNotifications: true.
971
- */
972
- getTaskPushNotificationConfig(params, options) {
973
- if (!this.agentCard.capabilities.pushNotifications) {
974
- throw new PushNotificationNotSupportedError();
975
- }
976
- return this.executeWithInterceptors(
977
- { method: "getTaskPushNotificationConfig", value: params },
978
- options,
979
- this.transport.getTaskPushNotificationConfig.bind(this.transport)
980
- );
981
- }
982
- /**
983
- * Retrieves the associated push notification configurations for a specified task.
984
- * Requires the server to have AgentCard.capabilities.pushNotifications: true.
985
- */
986
- listTaskPushNotificationConfig(params, options) {
987
- if (!this.agentCard.capabilities.pushNotifications) {
988
- throw new PushNotificationNotSupportedError();
989
- }
990
- return this.executeWithInterceptors(
991
- { method: "listTaskPushNotificationConfig", value: params },
992
- options,
993
- this.transport.listTaskPushNotificationConfig.bind(this.transport)
994
- );
995
- }
996
- /**
997
- * Deletes an associated push notification configuration for a task.
998
- */
999
- deleteTaskPushNotificationConfig(params, options) {
1000
- return this.executeWithInterceptors(
1001
- { method: "deleteTaskPushNotificationConfig", value: params },
1002
- options,
1003
- this.transport.deleteTaskPushNotificationConfig.bind(this.transport)
1004
- );
1005
- }
1006
- /**
1007
- * Retrieves the current state (including status, artifacts, and optionally history) of a previously initiated task.
1008
- */
1009
- getTask(params, options) {
1010
- return this.executeWithInterceptors(
1011
- { method: "getTask", value: params },
1012
- options,
1013
- this.transport.getTask.bind(this.transport)
1014
- );
1015
- }
1016
- /**
1017
- * Requests the cancellation of an ongoing task. The server will attempt to cancel the task,
1018
- * but success is not guaranteed (e.g., the task might have already completed or failed, or cancellation might not be supported at its current stage).
1019
- */
1020
- cancelTask(params, options) {
1021
- return this.executeWithInterceptors(
1022
- { method: "cancelTask", value: params },
1023
- options,
1024
- this.transport.cancelTask.bind(this.transport)
1025
- );
1026
- }
1027
- /**
1028
- * Allows a client to reconnect to an updates stream for an ongoing task after a previous connection was interrupted.
1029
- */
1030
- async *resubscribeTask(params, options) {
1031
- const method = "resubscribeTask";
1032
- const beforeArgs = {
1033
- input: { method, value: params },
1034
- agentCard: this.agentCard,
1035
- options
947
+ };
948
+ var Task = {
949
+ fromJSON(object) {
950
+ return {
951
+ id: isSet(object.id) ? globalThis.String(object.id) : "",
952
+ contextId: isSet(object.contextId) ? globalThis.String(object.contextId) : isSet(object.context_id) ? globalThis.String(object.context_id) : "",
953
+ status: isSet(object.status) ? TaskStatus.fromJSON(object.status) : void 0,
954
+ artifacts: globalThis.Array.isArray(object?.artifacts) ? object.artifacts.map((e) => Artifact.fromJSON(e)) : [],
955
+ history: globalThis.Array.isArray(object?.history) ? object.history.map((e) => Message.fromJSON(e)) : [],
956
+ metadata: isObject(object.metadata) ? object.metadata : void 0
1036
957
  };
1037
- const beforeResult = await this.interceptBefore(beforeArgs);
1038
- if (beforeResult) {
1039
- const earlyReturn = beforeResult.earlyReturn.value;
1040
- const afterArgs = {
1041
- result: { method, value: earlyReturn },
1042
- agentCard: this.agentCard,
1043
- options: beforeArgs.options
1044
- };
1045
- await this.interceptAfter(afterArgs, beforeResult.executed);
1046
- yield afterArgs.result.value;
1047
- return;
958
+ },
959
+ toJSON(message) {
960
+ const obj = {};
961
+ if (message.id !== "") {
962
+ obj.id = message.id;
1048
963
  }
1049
- for await (const event of this.transport.resubscribeTask(
1050
- beforeArgs.input.value,
1051
- beforeArgs.options
1052
- )) {
1053
- const afterArgs = {
1054
- result: { method, value: event },
1055
- agentCard: this.agentCard,
1056
- options: beforeArgs.options
1057
- };
1058
- await this.interceptAfter(afterArgs);
1059
- yield afterArgs.result.value;
1060
- if (afterArgs.earlyReturn) {
1061
- return;
1062
- }
964
+ if (message.contextId !== "") {
965
+ obj.contextId = message.contextId;
1063
966
  }
1064
- }
1065
- applyClientConfig({
1066
- params,
1067
- blocking
1068
- }) {
1069
- const result = { ...params, configuration: params.configuration ?? {} };
1070
- if (!result.configuration.acceptedOutputModes && this.config?.acceptedOutputModes) {
1071
- result.configuration.acceptedOutputModes = this.config.acceptedOutputModes;
967
+ if (message.status !== void 0) {
968
+ obj.status = TaskStatus.toJSON(message.status);
1072
969
  }
1073
- if (!result.configuration.pushNotificationConfig && this.config?.pushNotificationConfig) {
1074
- result.configuration.pushNotificationConfig = this.config.pushNotificationConfig;
970
+ if (message.artifacts?.length) {
971
+ obj.artifacts = message.artifacts.map((e) => Artifact.toJSON(e));
1075
972
  }
1076
- result.configuration.blocking ??= blocking;
1077
- return result;
973
+ if (message.history?.length) {
974
+ obj.history = message.history.map((e) => Message.toJSON(e));
975
+ }
976
+ if (message.metadata !== void 0) {
977
+ obj.metadata = message.metadata;
978
+ }
979
+ return obj;
1078
980
  }
1079
- async executeWithInterceptors(input, options, transportCall) {
1080
- const beforeArgs = {
1081
- input,
1082
- agentCard: this.agentCard,
1083
- options
981
+ };
982
+ var TaskStatus = {
983
+ fromJSON(object) {
984
+ return {
985
+ state: isSet(object.state) ? taskStateFromJSON(object.state) : 0,
986
+ update: isSet(object.message) ? Message.fromJSON(object.message) : isSet(object.update) ? Message.fromJSON(object.update) : void 0,
987
+ timestamp: isSet(object.timestamp) ? globalThis.String(object.timestamp) : void 0
1084
988
  };
1085
- const beforeResult = await this.interceptBefore(beforeArgs);
1086
- if (beforeResult) {
1087
- const afterArgs2 = {
1088
- result: {
1089
- method: input.method,
1090
- value: beforeResult.earlyReturn.value
1091
- },
1092
- agentCard: this.agentCard,
1093
- options: beforeArgs.options
1094
- };
1095
- await this.interceptAfter(afterArgs2, beforeResult.executed);
1096
- return afterArgs2.result.value;
989
+ },
990
+ toJSON(message) {
991
+ const obj = {};
992
+ if (message.state !== 0) {
993
+ obj.state = taskStateToJSON(message.state);
1097
994
  }
1098
- const result = await transportCall(beforeArgs.input.value, beforeArgs.options);
1099
- const afterArgs = {
1100
- result: { method: input.method, value: result },
1101
- agentCard: this.agentCard,
1102
- options: beforeArgs.options
1103
- };
1104
- await this.interceptAfter(afterArgs);
1105
- return afterArgs.result.value;
1106
- }
1107
- async interceptBefore(args) {
1108
- if (!this.config?.interceptors || this.config.interceptors.length === 0) {
1109
- return;
995
+ if (message.update !== void 0) {
996
+ obj.message = Message.toJSON(message.update);
1110
997
  }
1111
- const executed = [];
1112
- for (const interceptor of this.config.interceptors) {
1113
- await interceptor.before(args);
1114
- executed.push(interceptor);
1115
- if (args.earlyReturn) {
1116
- return {
1117
- earlyReturn: args.earlyReturn,
1118
- executed
1119
- };
1120
- }
998
+ if (message.timestamp !== void 0) {
999
+ obj.timestamp = message.timestamp;
1121
1000
  }
1001
+ return obj;
1122
1002
  }
1123
- async interceptAfter(args, interceptors) {
1124
- const reversedInterceptors = [...interceptors ?? this.config?.interceptors ?? []].reverse();
1125
- for (const interceptor of reversedInterceptors) {
1126
- await interceptor.after(args);
1127
- if (args.earlyReturn) {
1128
- return;
1129
- }
1003
+ };
1004
+ var Part = {
1005
+ fromJSON(object) {
1006
+ return {
1007
+ part: isSet(object.text) ? { $case: "text", value: globalThis.String(object.text) } : isSet(object.file) ? { $case: "file", value: FilePart.fromJSON(object.file) } : isSet(object.data) ? { $case: "data", value: DataPart.fromJSON(object.data) } : void 0
1008
+ };
1009
+ },
1010
+ toJSON(message) {
1011
+ const obj = {};
1012
+ if (message.part?.$case === "text") {
1013
+ obj.text = message.part.value;
1014
+ } else if (message.part?.$case === "file") {
1015
+ obj.file = FilePart.toJSON(message.part.value);
1016
+ } else if (message.part?.$case === "data") {
1017
+ obj.data = DataPart.toJSON(message.part.value);
1130
1018
  }
1019
+ return obj;
1131
1020
  }
1132
1021
  };
1133
-
1134
- // src/server/error.ts
1135
- var A2AError = class _A2AError extends Error {
1136
- code;
1137
- data;
1138
- taskId;
1139
- // Optional task ID context
1140
- constructor(code, message, data, taskId) {
1141
- super(message);
1142
- this.name = "A2AError";
1143
- this.code = code;
1144
- this.data = data;
1145
- this.taskId = taskId;
1146
- }
1147
- /**
1148
- * Formats the error into a standard JSON-RPC error object structure.
1149
- */
1150
- toJSONRPCError() {
1151
- const errorObject = {
1152
- code: this.code,
1153
- message: this.message
1022
+ var FilePart = {
1023
+ fromJSON(object) {
1024
+ return {
1025
+ file: isSet(object.fileWithUri) ? { $case: "fileWithUri", value: globalThis.String(object.fileWithUri) } : isSet(object.file_with_uri) ? { $case: "fileWithUri", value: globalThis.String(object.file_with_uri) } : isSet(object.fileWithBytes) ? { $case: "fileWithBytes", value: Buffer.from(bytesFromBase64(object.fileWithBytes)) } : isSet(object.file_with_bytes) ? { $case: "fileWithBytes", value: Buffer.from(bytesFromBase64(object.file_with_bytes)) } : void 0,
1026
+ mimeType: isSet(object.mimeType) ? globalThis.String(object.mimeType) : isSet(object.mime_type) ? globalThis.String(object.mime_type) : ""
1154
1027
  };
1155
- if (this.data !== void 0) {
1156
- errorObject.data = this.data;
1028
+ },
1029
+ toJSON(message) {
1030
+ const obj = {};
1031
+ if (message.file?.$case === "fileWithUri") {
1032
+ obj.fileWithUri = message.file.value;
1033
+ } else if (message.file?.$case === "fileWithBytes") {
1034
+ obj.fileWithBytes = base64FromBytes(message.file.value);
1157
1035
  }
1158
- return errorObject;
1036
+ if (message.mimeType !== "") {
1037
+ obj.mimeType = message.mimeType;
1038
+ }
1039
+ return obj;
1159
1040
  }
1160
- // Static factory methods for common errors
1161
- static parseError(message, data) {
1162
- return new _A2AError(-32700, message, data);
1163
- }
1164
- static invalidRequest(message, data) {
1165
- return new _A2AError(-32600, message, data);
1166
- }
1167
- static methodNotFound(method) {
1168
- return new _A2AError(-32601, `Method not found: ${method}`);
1169
- }
1170
- static invalidParams(message, data) {
1171
- return new _A2AError(-32602, message, data);
1172
- }
1173
- static internalError(message, data) {
1174
- return new _A2AError(-32603, message, data);
1175
- }
1176
- static taskNotFound(taskId) {
1177
- return new _A2AError(-32001, `Task not found: ${taskId}`, void 0, taskId);
1178
- }
1179
- static taskNotCancelable(taskId) {
1180
- return new _A2AError(-32002, `Task not cancelable: ${taskId}`, void 0, taskId);
1181
- }
1182
- static pushNotificationNotSupported() {
1183
- return new _A2AError(-32003, "Push Notification is not supported");
1184
- }
1185
- static unsupportedOperation(operation) {
1186
- return new _A2AError(-32004, `Unsupported operation: ${operation}`);
1187
- }
1188
- static authenticatedExtendedCardNotConfigured() {
1189
- return new _A2AError(-32007, `Extended card not configured.`);
1190
- }
1191
- };
1192
-
1193
- // src/types/pb/a2a_types.ts
1194
- function taskStateFromJSON(object) {
1195
- switch (object) {
1196
- case 0:
1197
- case "TASK_STATE_UNSPECIFIED":
1198
- return 0 /* TASK_STATE_UNSPECIFIED */;
1199
- case 1:
1200
- case "TASK_STATE_SUBMITTED":
1201
- return 1 /* TASK_STATE_SUBMITTED */;
1202
- case 2:
1203
- case "TASK_STATE_WORKING":
1204
- return 2 /* TASK_STATE_WORKING */;
1205
- case 3:
1206
- case "TASK_STATE_COMPLETED":
1207
- return 3 /* TASK_STATE_COMPLETED */;
1208
- case 4:
1209
- case "TASK_STATE_FAILED":
1210
- return 4 /* TASK_STATE_FAILED */;
1211
- case 5:
1212
- case "TASK_STATE_CANCELLED":
1213
- return 5 /* TASK_STATE_CANCELLED */;
1214
- case 6:
1215
- case "TASK_STATE_INPUT_REQUIRED":
1216
- return 6 /* TASK_STATE_INPUT_REQUIRED */;
1217
- case 7:
1218
- case "TASK_STATE_REJECTED":
1219
- return 7 /* TASK_STATE_REJECTED */;
1220
- case 8:
1221
- case "TASK_STATE_AUTH_REQUIRED":
1222
- return 8 /* TASK_STATE_AUTH_REQUIRED */;
1223
- case -1:
1224
- case "UNRECOGNIZED":
1225
- default:
1226
- return -1 /* UNRECOGNIZED */;
1227
- }
1228
- }
1229
- function taskStateToJSON(object) {
1230
- switch (object) {
1231
- case 0 /* TASK_STATE_UNSPECIFIED */:
1232
- return "TASK_STATE_UNSPECIFIED";
1233
- case 1 /* TASK_STATE_SUBMITTED */:
1234
- return "TASK_STATE_SUBMITTED";
1235
- case 2 /* TASK_STATE_WORKING */:
1236
- return "TASK_STATE_WORKING";
1237
- case 3 /* TASK_STATE_COMPLETED */:
1238
- return "TASK_STATE_COMPLETED";
1239
- case 4 /* TASK_STATE_FAILED */:
1240
- return "TASK_STATE_FAILED";
1241
- case 5 /* TASK_STATE_CANCELLED */:
1242
- return "TASK_STATE_CANCELLED";
1243
- case 6 /* TASK_STATE_INPUT_REQUIRED */:
1244
- return "TASK_STATE_INPUT_REQUIRED";
1245
- case 7 /* TASK_STATE_REJECTED */:
1246
- return "TASK_STATE_REJECTED";
1247
- case 8 /* TASK_STATE_AUTH_REQUIRED */:
1248
- return "TASK_STATE_AUTH_REQUIRED";
1249
- case -1 /* UNRECOGNIZED */:
1250
- default:
1251
- return "UNRECOGNIZED";
1252
- }
1253
- }
1254
- function roleFromJSON(object) {
1255
- switch (object) {
1256
- case 0:
1257
- case "ROLE_UNSPECIFIED":
1258
- return 0 /* ROLE_UNSPECIFIED */;
1259
- case 1:
1260
- case "ROLE_USER":
1261
- return 1 /* ROLE_USER */;
1262
- case 2:
1263
- case "ROLE_AGENT":
1264
- return 2 /* ROLE_AGENT */;
1265
- case -1:
1266
- case "UNRECOGNIZED":
1267
- default:
1268
- return -1 /* UNRECOGNIZED */;
1269
- }
1270
- }
1271
- function roleToJSON(object) {
1272
- switch (object) {
1273
- case 0 /* ROLE_UNSPECIFIED */:
1274
- return "ROLE_UNSPECIFIED";
1275
- case 1 /* ROLE_USER */:
1276
- return "ROLE_USER";
1277
- case 2 /* ROLE_AGENT */:
1278
- return "ROLE_AGENT";
1279
- case -1 /* UNRECOGNIZED */:
1280
- default:
1281
- return "UNRECOGNIZED";
1282
- }
1283
- }
1284
- var SendMessageConfiguration = {
1285
- fromJSON(object) {
1286
- return {
1287
- 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(
1288
- (e) => globalThis.String(e)
1289
- ) : [],
1290
- pushNotification: isSet(object.pushNotification) ? PushNotificationConfig.fromJSON(object.pushNotification) : isSet(object.push_notification) ? PushNotificationConfig.fromJSON(object.push_notification) : void 0,
1291
- historyLength: isSet(object.historyLength) ? globalThis.Number(object.historyLength) : isSet(object.history_length) ? globalThis.Number(object.history_length) : 0,
1292
- blocking: isSet(object.blocking) ? globalThis.Boolean(object.blocking) : false
1293
- };
1294
- },
1295
- toJSON(message) {
1296
- const obj = {};
1297
- if (message.acceptedOutputModes?.length) {
1298
- obj.acceptedOutputModes = message.acceptedOutputModes;
1299
- }
1300
- if (message.pushNotification !== void 0) {
1301
- obj.pushNotification = PushNotificationConfig.toJSON(message.pushNotification);
1302
- }
1303
- if (message.historyLength !== 0) {
1304
- obj.historyLength = Math.round(message.historyLength);
1305
- }
1306
- if (message.blocking !== false) {
1307
- obj.blocking = message.blocking;
1308
- }
1309
- return obj;
1310
- }
1311
- };
1312
- var Task = {
1313
- fromJSON(object) {
1314
- return {
1315
- id: isSet(object.id) ? globalThis.String(object.id) : "",
1316
- contextId: isSet(object.contextId) ? globalThis.String(object.contextId) : isSet(object.context_id) ? globalThis.String(object.context_id) : "",
1317
- status: isSet(object.status) ? TaskStatus.fromJSON(object.status) : void 0,
1318
- artifacts: globalThis.Array.isArray(object?.artifacts) ? object.artifacts.map((e) => Artifact.fromJSON(e)) : [],
1319
- history: globalThis.Array.isArray(object?.history) ? object.history.map((e) => Message.fromJSON(e)) : [],
1320
- metadata: isObject(object.metadata) ? object.metadata : void 0
1321
- };
1322
- },
1323
- toJSON(message) {
1324
- const obj = {};
1325
- if (message.id !== "") {
1326
- obj.id = message.id;
1327
- }
1328
- if (message.contextId !== "") {
1329
- obj.contextId = message.contextId;
1330
- }
1331
- if (message.status !== void 0) {
1332
- obj.status = TaskStatus.toJSON(message.status);
1333
- }
1334
- if (message.artifacts?.length) {
1335
- obj.artifacts = message.artifacts.map((e) => Artifact.toJSON(e));
1336
- }
1337
- if (message.history?.length) {
1338
- obj.history = message.history.map((e) => Message.toJSON(e));
1339
- }
1340
- if (message.metadata !== void 0) {
1341
- obj.metadata = message.metadata;
1342
- }
1343
- return obj;
1344
- }
1345
- };
1346
- var TaskStatus = {
1347
- fromJSON(object) {
1348
- return {
1349
- state: isSet(object.state) ? taskStateFromJSON(object.state) : 0,
1350
- update: isSet(object.message) ? Message.fromJSON(object.message) : isSet(object.update) ? Message.fromJSON(object.update) : void 0,
1351
- timestamp: isSet(object.timestamp) ? globalThis.String(object.timestamp) : void 0
1352
- };
1353
- },
1354
- toJSON(message) {
1355
- const obj = {};
1356
- if (message.state !== 0) {
1357
- obj.state = taskStateToJSON(message.state);
1358
- }
1359
- if (message.update !== void 0) {
1360
- obj.message = Message.toJSON(message.update);
1361
- }
1362
- if (message.timestamp !== void 0) {
1363
- obj.timestamp = message.timestamp;
1364
- }
1365
- return obj;
1366
- }
1367
- };
1368
- var Part = {
1369
- fromJSON(object) {
1370
- return {
1371
- part: isSet(object.text) ? { $case: "text", value: globalThis.String(object.text) } : isSet(object.file) ? { $case: "file", value: FilePart.fromJSON(object.file) } : isSet(object.data) ? { $case: "data", value: DataPart.fromJSON(object.data) } : void 0
1372
- };
1373
- },
1374
- toJSON(message) {
1375
- const obj = {};
1376
- if (message.part?.$case === "text") {
1377
- obj.text = message.part.value;
1378
- } else if (message.part?.$case === "file") {
1379
- obj.file = FilePart.toJSON(message.part.value);
1380
- } else if (message.part?.$case === "data") {
1381
- obj.data = DataPart.toJSON(message.part.value);
1382
- }
1383
- return obj;
1384
- }
1385
- };
1386
- var FilePart = {
1387
- fromJSON(object) {
1388
- return {
1389
- file: isSet(object.fileWithUri) ? { $case: "fileWithUri", value: globalThis.String(object.fileWithUri) } : isSet(object.file_with_uri) ? { $case: "fileWithUri", value: globalThis.String(object.file_with_uri) } : isSet(object.fileWithBytes) ? { $case: "fileWithBytes", value: Buffer.from(bytesFromBase64(object.fileWithBytes)) } : isSet(object.file_with_bytes) ? { $case: "fileWithBytes", value: Buffer.from(bytesFromBase64(object.file_with_bytes)) } : void 0,
1390
- mimeType: isSet(object.mimeType) ? globalThis.String(object.mimeType) : isSet(object.mime_type) ? globalThis.String(object.mime_type) : ""
1391
- };
1392
- },
1393
- toJSON(message) {
1394
- const obj = {};
1395
- if (message.file?.$case === "fileWithUri") {
1396
- obj.fileWithUri = message.file.value;
1397
- } else if (message.file?.$case === "fileWithBytes") {
1398
- obj.fileWithBytes = base64FromBytes(message.file.value);
1399
- }
1400
- if (message.mimeType !== "") {
1401
- obj.mimeType = message.mimeType;
1402
- }
1403
- return obj;
1404
- }
1405
- };
1406
- var DataPart = {
1407
- fromJSON(object) {
1408
- return { data: isObject(object.data) ? object.data : void 0 };
1409
- },
1410
- toJSON(message) {
1411
- const obj = {};
1412
- if (message.data !== void 0) {
1413
- obj.data = message.data;
1414
- }
1415
- return obj;
1041
+ };
1042
+ var DataPart = {
1043
+ fromJSON(object) {
1044
+ return { data: isObject(object.data) ? object.data : void 0 };
1045
+ },
1046
+ toJSON(message) {
1047
+ const obj = {};
1048
+ if (message.data !== void 0) {
1049
+ obj.data = message.data;
1050
+ }
1051
+ return obj;
1416
1052
  }
1417
1053
  };
1418
1054
  var Message = {
@@ -2268,10 +1904,69 @@ function isSet(value) {
2268
1904
  return value !== null && value !== void 0;
2269
1905
  }
2270
1906
 
2271
- // src/types/converters/id_decoding.ts
2272
- var CONFIG_REGEX = /^tasks\/([^/]+)\/pushNotificationConfigs\/([^/]+)$/;
2273
- var TASK_ONLY_REGEX = /^tasks\/([^/]+)(?:\/|$)/;
2274
- var extractTaskId = (name) => {
1907
+ // src/server/error.ts
1908
+ var A2AError = class _A2AError extends Error {
1909
+ code;
1910
+ data;
1911
+ taskId;
1912
+ // Optional task ID context
1913
+ constructor(code, message, data, taskId) {
1914
+ super(message);
1915
+ this.name = "A2AError";
1916
+ this.code = code;
1917
+ this.data = data;
1918
+ this.taskId = taskId;
1919
+ }
1920
+ /**
1921
+ * Formats the error into a standard JSON-RPC error object structure.
1922
+ */
1923
+ toJSONRPCError() {
1924
+ const errorObject = {
1925
+ code: this.code,
1926
+ message: this.message
1927
+ };
1928
+ if (this.data !== void 0) {
1929
+ errorObject.data = this.data;
1930
+ }
1931
+ return errorObject;
1932
+ }
1933
+ // Static factory methods for common errors
1934
+ static parseError(message, data) {
1935
+ return new _A2AError(-32700, message, data);
1936
+ }
1937
+ static invalidRequest(message, data) {
1938
+ return new _A2AError(-32600, message, data);
1939
+ }
1940
+ static methodNotFound(method) {
1941
+ return new _A2AError(-32601, `Method not found: ${method}`);
1942
+ }
1943
+ static invalidParams(message, data) {
1944
+ return new _A2AError(-32602, message, data);
1945
+ }
1946
+ static internalError(message, data) {
1947
+ return new _A2AError(-32603, message, data);
1948
+ }
1949
+ static taskNotFound(taskId) {
1950
+ return new _A2AError(-32001, `Task not found: ${taskId}`, void 0, taskId);
1951
+ }
1952
+ static taskNotCancelable(taskId) {
1953
+ return new _A2AError(-32002, `Task not cancelable: ${taskId}`, void 0, taskId);
1954
+ }
1955
+ static pushNotificationNotSupported() {
1956
+ return new _A2AError(-32003, "Push Notification is not supported");
1957
+ }
1958
+ static unsupportedOperation(operation) {
1959
+ return new _A2AError(-32004, `Unsupported operation: ${operation}`);
1960
+ }
1961
+ static authenticatedExtendedCardNotConfigured() {
1962
+ return new _A2AError(-32007, `Extended card not configured.`);
1963
+ }
1964
+ };
1965
+
1966
+ // src/types/converters/id_decoding.ts
1967
+ var CONFIG_REGEX = /^tasks\/([^/]+)\/pushNotificationConfigs\/([^/]+)$/;
1968
+ var TASK_ONLY_REGEX = /^tasks\/([^/]+)(?:\/|$)/;
1969
+ var extractTaskId = (name) => {
2275
1970
  const match = name.match(TASK_ONLY_REGEX);
2276
1971
  if (!match) {
2277
1972
  throw A2AError.invalidParams(`Invalid or missing task ID in: "${name}"`);
@@ -2292,237 +1987,84 @@ var generatePushNotificationConfigName = (taskId, configId) => {
2292
1987
  return `tasks/${taskId}/pushNotificationConfigs/${configId}`;
2293
1988
  };
2294
1989
 
2295
- // src/types/converters/to_proto.ts
2296
- var ToProto = class _ToProto {
2297
- static agentCard(agentCard) {
1990
+ // src/types/converters/from_proto.ts
1991
+ var FromProto = class _FromProto {
1992
+ static taskQueryParams(request) {
2298
1993
  return {
2299
- protocolVersion: agentCard.protocolVersion,
2300
- name: agentCard.name,
2301
- description: agentCard.description,
2302
- url: agentCard.url,
2303
- preferredTransport: agentCard.preferredTransport ?? "",
2304
- additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _ToProto.agentInterface(i)) ?? [],
2305
- provider: _ToProto.agentProvider(agentCard.provider),
2306
- version: agentCard.version,
2307
- documentationUrl: agentCard.documentationUrl ?? "",
2308
- capabilities: _ToProto.agentCapabilities(agentCard.capabilities),
2309
- securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
2310
- Object.entries(agentCard.securitySchemes).map(([key, value]) => [
2311
- key,
2312
- _ToProto.securityScheme(value)
2313
- ])
2314
- ) : {},
2315
- security: agentCard.security?.map((s) => _ToProto.security(s)) ?? [],
2316
- defaultInputModes: agentCard.defaultInputModes,
2317
- defaultOutputModes: agentCard.defaultOutputModes,
2318
- skills: agentCard.skills.map((s) => _ToProto.agentSkill(s)),
2319
- supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
2320
- signatures: agentCard.signatures?.map((s) => _ToProto.agentCardSignature(s)) ?? []
1994
+ id: extractTaskId(request.name),
1995
+ historyLength: request.historyLength
2321
1996
  };
2322
1997
  }
2323
- static agentCardSignature(signatures) {
1998
+ static taskIdParams(request) {
2324
1999
  return {
2325
- protected: signatures.protected,
2326
- signature: signatures.signature,
2327
- header: signatures.header
2000
+ id: extractTaskId(request.name)
2328
2001
  };
2329
2002
  }
2330
- static agentSkill(skill) {
2003
+ static getTaskPushNotificationConfigParams(request) {
2004
+ const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
2331
2005
  return {
2332
- id: skill.id,
2333
- name: skill.name,
2334
- description: skill.description,
2335
- tags: skill.tags ?? [],
2336
- examples: skill.examples ?? [],
2337
- inputModes: skill.inputModes ?? [],
2338
- outputModes: skill.outputModes ?? [],
2339
- security: skill.security ? skill.security.map((s) => _ToProto.security(s)) : []
2006
+ id: taskId,
2007
+ pushNotificationConfigId: configId
2340
2008
  };
2341
2009
  }
2342
- static security(security) {
2010
+ static listTaskPushNotificationConfigParams(request) {
2343
2011
  return {
2344
- schemes: Object.fromEntries(
2345
- Object.entries(security).map(([key, value]) => {
2346
- return [key, { list: value }];
2347
- })
2348
- )
2012
+ id: extractTaskId(request.parent)
2349
2013
  };
2350
2014
  }
2351
- static securityScheme(scheme) {
2352
- switch (scheme.type) {
2353
- case "apiKey":
2354
- return {
2355
- scheme: {
2356
- $case: "apiKeySecurityScheme",
2357
- value: {
2358
- name: scheme.name,
2359
- location: scheme.in,
2360
- description: scheme.description ?? ""
2361
- }
2362
- }
2363
- };
2364
- case "http":
2365
- return {
2366
- scheme: {
2367
- $case: "httpAuthSecurityScheme",
2368
- value: {
2369
- description: scheme.description ?? "",
2370
- scheme: scheme.scheme,
2371
- bearerFormat: scheme.bearerFormat ?? ""
2372
- }
2373
- }
2374
- };
2375
- case "mutualTLS":
2376
- return {
2377
- scheme: {
2378
- $case: "mtlsSecurityScheme",
2379
- value: {
2380
- description: scheme.description ?? ""
2381
- }
2382
- }
2383
- };
2384
- case "oauth2":
2385
- return {
2386
- scheme: {
2387
- $case: "oauth2SecurityScheme",
2388
- value: {
2389
- description: scheme.description ?? "",
2390
- flows: _ToProto.oauthFlows(scheme.flows),
2391
- oauth2MetadataUrl: scheme.oauth2MetadataUrl ?? ""
2392
- }
2393
- }
2394
- };
2395
- case "openIdConnect":
2396
- return {
2397
- scheme: {
2398
- $case: "openIdConnectSecurityScheme",
2399
- value: {
2400
- description: scheme.description ?? "",
2401
- openIdConnectUrl: scheme.openIdConnectUrl
2402
- }
2403
- }
2404
- };
2405
- default:
2406
- throw A2AError.internalError(`Unsupported security scheme type`);
2407
- }
2408
- }
2409
- static oauthFlows(flows) {
2410
- if (flows.implicit) {
2411
- return {
2412
- flow: {
2413
- $case: "implicit",
2414
- value: {
2415
- authorizationUrl: flows.implicit.authorizationUrl,
2416
- scopes: flows.implicit.scopes,
2417
- refreshUrl: flows.implicit.refreshUrl ?? ""
2418
- }
2419
- }
2420
- };
2421
- } else if (flows.password) {
2422
- return {
2423
- flow: {
2424
- $case: "password",
2425
- value: {
2426
- tokenUrl: flows.password.tokenUrl,
2427
- scopes: flows.password.scopes,
2428
- refreshUrl: flows.password.refreshUrl ?? ""
2429
- }
2430
- }
2431
- };
2432
- } else if (flows.clientCredentials) {
2433
- return {
2434
- flow: {
2435
- $case: "clientCredentials",
2436
- value: {
2437
- tokenUrl: flows.clientCredentials.tokenUrl,
2438
- scopes: flows.clientCredentials.scopes,
2439
- refreshUrl: flows.clientCredentials.refreshUrl ?? ""
2440
- }
2441
- }
2442
- };
2443
- } else if (flows.authorizationCode) {
2444
- return {
2445
- flow: {
2446
- $case: "authorizationCode",
2447
- value: {
2448
- authorizationUrl: flows.authorizationCode.authorizationUrl,
2449
- tokenUrl: flows.authorizationCode.tokenUrl,
2450
- scopes: flows.authorizationCode.scopes,
2451
- refreshUrl: flows.authorizationCode.refreshUrl ?? ""
2452
- }
2453
- }
2454
- };
2455
- } else {
2456
- throw A2AError.internalError(`Unsupported OAuth flows`);
2015
+ static createTaskPushNotificationConfig(request) {
2016
+ if (!request.config?.pushNotificationConfig) {
2017
+ throw A2AError.invalidParams(
2018
+ "Request must include a `config` object with a `pushNotificationConfig`"
2019
+ );
2457
2020
  }
2458
- }
2459
- static agentInterface(agentInterface) {
2460
2021
  return {
2461
- transport: agentInterface.transport,
2462
- url: agentInterface.url
2022
+ taskId: extractTaskId(request.parent),
2023
+ pushNotificationConfig: _FromProto.pushNotificationConfig(
2024
+ request.config.pushNotificationConfig
2025
+ )
2463
2026
  };
2464
2027
  }
2465
- static agentProvider(agentProvider) {
2466
- if (!agentProvider) {
2467
- return void 0;
2468
- }
2028
+ static deleteTaskPushNotificationConfigParams(request) {
2029
+ const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
2469
2030
  return {
2470
- url: agentProvider.url,
2471
- organization: agentProvider.organization
2031
+ id: taskId,
2032
+ pushNotificationConfigId: configId
2472
2033
  };
2473
2034
  }
2474
- static agentCapabilities(capabilities) {
2035
+ static message(message) {
2036
+ if (!message) {
2037
+ return void 0;
2038
+ }
2475
2039
  return {
2476
- streaming: capabilities.streaming,
2477
- pushNotifications: capabilities.pushNotifications,
2478
- extensions: capabilities.extensions ? capabilities.extensions.map((e) => _ToProto.agentExtension(e)) : []
2479
- };
2480
- }
2481
- static agentExtension(extension) {
2482
- return {
2483
- uri: extension.uri,
2484
- description: extension.description ?? "",
2485
- required: extension.required ?? false,
2486
- params: extension.params
2487
- };
2488
- }
2489
- static listTaskPushNotificationConfig(config) {
2490
- return {
2491
- configs: config.map((c) => _ToProto.taskPushNotificationConfig(c)),
2492
- nextPageToken: ""
2493
- };
2494
- }
2495
- static getTaskPushNotificationConfigParams(config) {
2496
- return {
2497
- name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
2498
- };
2499
- }
2500
- static listTaskPushNotificationConfigParams(config) {
2501
- return {
2502
- parent: generateTaskName(config.id),
2503
- pageToken: "",
2504
- pageSize: 0
2505
- };
2506
- }
2507
- static deleteTaskPushNotificationConfigParams(config) {
2508
- return {
2509
- name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
2040
+ kind: "message",
2041
+ messageId: message.messageId,
2042
+ parts: message.content.map((p) => _FromProto.part(p)),
2043
+ contextId: message.contextId || void 0,
2044
+ taskId: message.taskId || void 0,
2045
+ role: _FromProto.role(message.role),
2046
+ metadata: message.metadata,
2047
+ extensions: message.extensions
2510
2048
  };
2511
2049
  }
2512
- static taskPushNotificationConfig(config) {
2513
- return {
2514
- name: generatePushNotificationConfigName(
2515
- config.taskId,
2516
- config.pushNotificationConfig.id ?? ""
2517
- ),
2518
- pushNotificationConfig: _ToProto.pushNotificationConfig(config.pushNotificationConfig)
2519
- };
2050
+ static role(role) {
2051
+ switch (role) {
2052
+ case 2 /* ROLE_AGENT */:
2053
+ return "agent";
2054
+ case 1 /* ROLE_USER */:
2055
+ return "user";
2056
+ default:
2057
+ throw A2AError.invalidParams(`Invalid role: ${role}`);
2058
+ }
2520
2059
  }
2521
- static taskPushNotificationConfigCreate(config) {
2060
+ static messageSendConfiguration(configuration) {
2061
+ if (!configuration) {
2062
+ return void 0;
2063
+ }
2522
2064
  return {
2523
- parent: generateTaskName(config.taskId),
2524
- config: _ToProto.taskPushNotificationConfig(config),
2525
- configId: config.pushNotificationConfig.id
2065
+ blocking: configuration.blocking,
2066
+ acceptedOutputModes: configuration.acceptedOutputModes,
2067
+ pushNotificationConfig: _FromProto.pushNotificationConfig(configuration.pushNotification)
2526
2068
  };
2527
2069
  }
2528
2070
  static pushNotificationConfig(config) {
@@ -2530,10 +2072,10 @@ var ToProto = class _ToProto {
2530
2072
  return void 0;
2531
2073
  }
2532
2074
  return {
2533
- id: config.id ?? "",
2075
+ id: config.id,
2534
2076
  url: config.url,
2535
- token: config.token ?? "",
2536
- authentication: _ToProto.pushNotificationAuthenticationInfo(config.authentication)
2077
+ token: config.token || void 0,
2078
+ authentication: _FromProto.pushNotificationAuthenticationInfo(config.authentication)
2537
2079
  };
2538
2080
  }
2539
2081
  static pushNotificationAuthenticationInfo(authInfo) {
@@ -2542,302 +2084,888 @@ var ToProto = class _ToProto {
2542
2084
  }
2543
2085
  return {
2544
2086
  schemes: authInfo.schemes,
2545
- credentials: authInfo.credentials ?? ""
2087
+ credentials: authInfo.credentials
2546
2088
  };
2547
2089
  }
2548
- static messageStreamResult(event) {
2549
- if (event.kind === "message") {
2550
- return {
2551
- payload: {
2552
- $case: "msg",
2553
- value: _ToProto.message(event)
2554
- }
2555
- };
2556
- } else if (event.kind === "task") {
2557
- return {
2558
- payload: {
2559
- $case: "task",
2560
- value: _ToProto.task(event)
2561
- }
2562
- };
2563
- } else if (event.kind === "status-update") {
2090
+ static part(part) {
2091
+ if (part.part?.$case === "text") {
2564
2092
  return {
2565
- payload: {
2566
- $case: "statusUpdate",
2567
- value: _ToProto.taskStatusUpdateEvent(event)
2568
- }
2093
+ kind: "text",
2094
+ text: part.part.value
2569
2095
  };
2570
- } else if (event.kind === "artifact-update") {
2096
+ }
2097
+ if (part.part?.$case === "file") {
2098
+ const filePart = part.part.value;
2099
+ if (filePart.file?.$case === "fileWithUri") {
2100
+ return {
2101
+ kind: "file",
2102
+ file: {
2103
+ uri: filePart.file.value,
2104
+ mimeType: filePart.mimeType
2105
+ }
2106
+ };
2107
+ } else if (filePart.file?.$case === "fileWithBytes") {
2108
+ return {
2109
+ kind: "file",
2110
+ file: {
2111
+ bytes: filePart.file.value.toString("base64"),
2112
+ mimeType: filePart.mimeType
2113
+ }
2114
+ };
2115
+ }
2116
+ throw A2AError.invalidParams("Invalid file part type");
2117
+ }
2118
+ if (part.part?.$case === "data") {
2571
2119
  return {
2572
- payload: {
2573
- $case: "artifactUpdate",
2574
- value: _ToProto.taskArtifactUpdateEvent(event)
2575
- }
2120
+ kind: "data",
2121
+ data: part.part.value.data
2576
2122
  };
2577
- } else {
2578
- throw A2AError.internalError("Invalid event type");
2579
2123
  }
2124
+ throw A2AError.invalidParams("Invalid part type");
2580
2125
  }
2581
- static taskStatusUpdateEvent(event) {
2126
+ static messageSendParams(request) {
2582
2127
  return {
2583
- taskId: event.taskId,
2584
- status: _ToProto.taskStatus(event.status),
2585
- contextId: event.contextId,
2586
- metadata: event.metadata,
2587
- final: event.final
2128
+ message: _FromProto.message(request.request),
2129
+ configuration: _FromProto.messageSendConfiguration(request.configuration),
2130
+ metadata: request.metadata
2588
2131
  };
2589
2132
  }
2590
- static taskArtifactUpdateEvent(event) {
2133
+ static sendMessageResult(response) {
2134
+ if (response.payload?.$case === "task") {
2135
+ return _FromProto.task(response.payload.value);
2136
+ } else if (response.payload?.$case === "msg") {
2137
+ return _FromProto.message(response.payload.value);
2138
+ }
2139
+ throw A2AError.invalidParams("Invalid SendMessageResponse: missing result");
2140
+ }
2141
+ static task(task) {
2591
2142
  return {
2592
- taskId: event.taskId,
2593
- artifact: _ToProto.artifact(event.artifact),
2594
- contextId: event.contextId,
2595
- metadata: event.metadata,
2596
- append: event.append,
2597
- lastChunk: event.lastChunk
2143
+ kind: "task",
2144
+ id: task.id,
2145
+ status: _FromProto.taskStatus(task.status),
2146
+ contextId: task.contextId,
2147
+ artifacts: task.artifacts?.map((a) => _FromProto.artifact(a)),
2148
+ history: task.history?.map((h) => _FromProto.message(h)),
2149
+ metadata: task.metadata
2598
2150
  };
2599
2151
  }
2600
- static messageSendResult(params) {
2601
- if (params.kind === "message") {
2602
- return {
2603
- payload: {
2604
- $case: "msg",
2605
- value: _ToProto.message(params)
2606
- }
2607
- };
2608
- } else if (params.kind === "task") {
2609
- return {
2610
- payload: {
2611
- $case: "task",
2612
- value: _ToProto.task(params)
2613
- }
2614
- };
2615
- }
2152
+ static taskStatus(status) {
2153
+ return {
2154
+ message: _FromProto.message(status.update),
2155
+ state: _FromProto.taskState(status.state),
2156
+ timestamp: status.timestamp
2157
+ };
2616
2158
  }
2617
- static message(message) {
2618
- if (!message) {
2619
- return void 0;
2159
+ static taskState(state) {
2160
+ switch (state) {
2161
+ case 1 /* TASK_STATE_SUBMITTED */:
2162
+ return "submitted";
2163
+ case 2 /* TASK_STATE_WORKING */:
2164
+ return "working";
2165
+ case 6 /* TASK_STATE_INPUT_REQUIRED */:
2166
+ return "input-required";
2167
+ case 3 /* TASK_STATE_COMPLETED */:
2168
+ return "completed";
2169
+ case 5 /* TASK_STATE_CANCELLED */:
2170
+ return "canceled";
2171
+ case 4 /* TASK_STATE_FAILED */:
2172
+ return "failed";
2173
+ case 7 /* TASK_STATE_REJECTED */:
2174
+ return "rejected";
2175
+ case 8 /* TASK_STATE_AUTH_REQUIRED */:
2176
+ return "auth-required";
2177
+ case 0 /* TASK_STATE_UNSPECIFIED */:
2178
+ return "unknown";
2179
+ default:
2180
+ throw A2AError.invalidParams(`Invalid task state: ${state}`);
2620
2181
  }
2182
+ }
2183
+ static artifact(artifact) {
2621
2184
  return {
2622
- messageId: message.messageId,
2623
- content: message.parts.map((p) => _ToProto.part(p)),
2624
- contextId: message.contextId ?? "",
2625
- taskId: message.taskId ?? "",
2626
- role: _ToProto.role(message.role),
2627
- metadata: message.metadata,
2628
- extensions: message.extensions ?? []
2185
+ artifactId: artifact.artifactId,
2186
+ name: artifact.name || void 0,
2187
+ description: artifact.description || void 0,
2188
+ parts: artifact.parts.map((p) => _FromProto.part(p)),
2189
+ metadata: artifact.metadata
2629
2190
  };
2630
2191
  }
2631
- static role(role) {
2632
- switch (role) {
2633
- case "agent":
2634
- return 2 /* ROLE_AGENT */;
2635
- case "user":
2636
- return 1 /* ROLE_USER */;
2637
- default:
2638
- throw A2AError.internalError(`Invalid role`);
2192
+ static taskPushNotificationConfig(request) {
2193
+ return {
2194
+ taskId: extractTaskId(request.name),
2195
+ pushNotificationConfig: _FromProto.pushNotificationConfig(request.pushNotificationConfig)
2196
+ };
2197
+ }
2198
+ static listTaskPushNotificationConfig(request) {
2199
+ return request.configs.map((c) => _FromProto.taskPushNotificationConfig(c));
2200
+ }
2201
+ static agentCard(agentCard) {
2202
+ return {
2203
+ additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _FromProto.agentInterface(i)),
2204
+ capabilities: agentCard.capabilities ? _FromProto.agentCapabilities(agentCard.capabilities) : {},
2205
+ defaultInputModes: agentCard.defaultInputModes,
2206
+ defaultOutputModes: agentCard.defaultOutputModes,
2207
+ description: agentCard.description,
2208
+ documentationUrl: agentCard.documentationUrl || void 0,
2209
+ name: agentCard.name,
2210
+ preferredTransport: agentCard.preferredTransport,
2211
+ provider: agentCard.provider ? _FromProto.agentProvider(agentCard.provider) : void 0,
2212
+ protocolVersion: agentCard.protocolVersion,
2213
+ security: agentCard.security?.map((s) => _FromProto.security(s)),
2214
+ securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
2215
+ Object.entries(agentCard.securitySchemes).map(([key, value]) => [
2216
+ key,
2217
+ _FromProto.securityScheme(value)
2218
+ ])
2219
+ ) : {},
2220
+ skills: agentCard.skills.map((s) => _FromProto.skills(s)),
2221
+ signatures: agentCard.signatures?.map((s) => _FromProto.agentCardSignature(s)),
2222
+ supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
2223
+ url: agentCard.url,
2224
+ version: agentCard.version
2225
+ };
2226
+ }
2227
+ static agentCapabilities(capabilities) {
2228
+ return {
2229
+ extensions: capabilities.extensions?.map((e) => _FromProto.agentExtension(e)),
2230
+ pushNotifications: capabilities.pushNotifications,
2231
+ streaming: capabilities.streaming
2232
+ };
2233
+ }
2234
+ static agentExtension(extension) {
2235
+ return {
2236
+ uri: extension.uri,
2237
+ description: extension.description || void 0,
2238
+ required: extension.required,
2239
+ params: extension.params
2240
+ };
2241
+ }
2242
+ static agentInterface(intf) {
2243
+ return {
2244
+ transport: intf.transport,
2245
+ url: intf.url
2246
+ };
2247
+ }
2248
+ static agentProvider(provider) {
2249
+ return {
2250
+ organization: provider.organization,
2251
+ url: provider.url
2252
+ };
2253
+ }
2254
+ static security(security) {
2255
+ return Object.fromEntries(
2256
+ Object.entries(security.schemes)?.map(([key, value]) => [key, value.list])
2257
+ );
2258
+ }
2259
+ static securityScheme(securitySchemes) {
2260
+ switch (securitySchemes.scheme?.$case) {
2261
+ case "apiKeySecurityScheme":
2262
+ return {
2263
+ type: "apiKey",
2264
+ name: securitySchemes.scheme.value.name,
2265
+ in: securitySchemes.scheme.value.location,
2266
+ description: securitySchemes.scheme.value.description || void 0
2267
+ };
2268
+ case "httpAuthSecurityScheme":
2269
+ return {
2270
+ type: "http",
2271
+ scheme: securitySchemes.scheme.value.scheme,
2272
+ bearerFormat: securitySchemes.scheme.value.bearerFormat || void 0,
2273
+ description: securitySchemes.scheme.value.description || void 0
2274
+ };
2275
+ case "mtlsSecurityScheme":
2276
+ return {
2277
+ type: "mutualTLS",
2278
+ description: securitySchemes.scheme.value.description || void 0
2279
+ };
2280
+ case "oauth2SecurityScheme":
2281
+ return {
2282
+ type: "oauth2",
2283
+ description: securitySchemes.scheme.value.description || void 0,
2284
+ flows: _FromProto.oauthFlows(securitySchemes.scheme.value.flows),
2285
+ oauth2MetadataUrl: securitySchemes.scheme.value.oauth2MetadataUrl || void 0
2286
+ };
2287
+ case "openIdConnectSecurityScheme":
2288
+ return {
2289
+ type: "openIdConnect",
2290
+ description: securitySchemes.scheme.value.description || void 0,
2291
+ openIdConnectUrl: securitySchemes.scheme.value.openIdConnectUrl
2292
+ };
2293
+ default:
2294
+ throw A2AError.internalError(`Unsupported security scheme type`);
2295
+ }
2296
+ }
2297
+ static oauthFlows(flows) {
2298
+ switch (flows.flow?.$case) {
2299
+ case "implicit":
2300
+ return {
2301
+ implicit: {
2302
+ authorizationUrl: flows.flow.value.authorizationUrl,
2303
+ scopes: flows.flow.value.scopes,
2304
+ refreshUrl: flows.flow.value.refreshUrl || void 0
2305
+ }
2306
+ };
2307
+ case "password":
2308
+ return {
2309
+ password: {
2310
+ refreshUrl: flows.flow.value.refreshUrl || void 0,
2311
+ scopes: flows.flow.value.scopes,
2312
+ tokenUrl: flows.flow.value.tokenUrl
2313
+ }
2314
+ };
2315
+ case "authorizationCode":
2316
+ return {
2317
+ authorizationCode: {
2318
+ refreshUrl: flows.flow.value.refreshUrl || void 0,
2319
+ authorizationUrl: flows.flow.value.authorizationUrl,
2320
+ scopes: flows.flow.value.scopes,
2321
+ tokenUrl: flows.flow.value.tokenUrl
2322
+ }
2323
+ };
2324
+ case "clientCredentials":
2325
+ return {
2326
+ clientCredentials: {
2327
+ refreshUrl: flows.flow.value.refreshUrl || void 0,
2328
+ scopes: flows.flow.value.scopes,
2329
+ tokenUrl: flows.flow.value.tokenUrl
2330
+ }
2331
+ };
2332
+ default:
2333
+ throw A2AError.internalError(`Unsupported OAuth flows`);
2334
+ }
2335
+ }
2336
+ static skills(skill) {
2337
+ return {
2338
+ id: skill.id,
2339
+ name: skill.name,
2340
+ description: skill.description,
2341
+ tags: skill.tags,
2342
+ examples: skill.examples,
2343
+ inputModes: skill.inputModes,
2344
+ outputModes: skill.outputModes,
2345
+ security: skill.security?.map((s) => _FromProto.security(s))
2346
+ };
2347
+ }
2348
+ static agentCardSignature(signatures) {
2349
+ return {
2350
+ protected: signatures.protected,
2351
+ signature: signatures.signature,
2352
+ header: signatures.header
2353
+ };
2354
+ }
2355
+ static taskStatusUpdateEvent(event) {
2356
+ return {
2357
+ kind: "status-update",
2358
+ taskId: event.taskId,
2359
+ status: _FromProto.taskStatus(event.status),
2360
+ contextId: event.contextId,
2361
+ metadata: event.metadata,
2362
+ final: event.final
2363
+ };
2364
+ }
2365
+ static taskArtifactUpdateEvent(event) {
2366
+ return {
2367
+ kind: "artifact-update",
2368
+ taskId: event.taskId,
2369
+ artifact: _FromProto.artifact(event.artifact),
2370
+ contextId: event.contextId,
2371
+ metadata: event.metadata,
2372
+ lastChunk: event.lastChunk
2373
+ };
2374
+ }
2375
+ static messageStreamResult(event) {
2376
+ switch (event.payload?.$case) {
2377
+ case "msg":
2378
+ return _FromProto.message(event.payload.value);
2379
+ case "task":
2380
+ return _FromProto.task(event.payload.value);
2381
+ case "statusUpdate":
2382
+ return _FromProto.taskStatusUpdateEvent(event.payload.value);
2383
+ case "artifactUpdate":
2384
+ return _FromProto.taskArtifactUpdateEvent(event.payload.value);
2385
+ default:
2386
+ throw A2AError.internalError("Invalid event type in StreamResponse");
2387
+ }
2388
+ }
2389
+ };
2390
+
2391
+ // src/client/card-resolver.ts
2392
+ var DefaultAgentCardResolver = class {
2393
+ constructor(options) {
2394
+ this.options = options;
2395
+ }
2396
+ /**
2397
+ * Fetches the agent card based on provided base URL and path.
2398
+ * Path is selected in the following order:
2399
+ * 1) path parameter
2400
+ * 2) path from options
2401
+ * 3) .well-known/agent-card.json
2402
+ */
2403
+ async resolve(baseUrl, path) {
2404
+ const agentCardUrl = new URL(path ?? this.options?.path ?? AGENT_CARD_PATH, baseUrl);
2405
+ const response = await this.fetchImpl(agentCardUrl);
2406
+ if (!response.ok) {
2407
+ throw new Error(`Failed to fetch Agent Card from ${agentCardUrl}: ${response.status}`);
2408
+ }
2409
+ const rawCard = await response.json();
2410
+ return this.normalizeAgentCard(rawCard);
2411
+ }
2412
+ fetchImpl(...args) {
2413
+ if (this.options?.fetchImpl) {
2414
+ return this.options.fetchImpl(...args);
2415
+ }
2416
+ return fetch(...args);
2417
+ }
2418
+ /*
2419
+ * In the v0.3.0 specification, there was a structural drift between the JSON Schema data model
2420
+ * and the Protobuf-based data model for AgentCards.
2421
+ * The JSON Schema format uses a `"type"` discriminator (e.g., `{"type": "openIdConnect"}`),
2422
+ * while the Protobuf JSON representation uses the `oneof` field name as the discriminator
2423
+ * (e.g., `{"openIdConnectSecurityScheme": {...}}`).
2424
+ *
2425
+ * The A2A SDK internal logic expects the JSON Schema-based format. This fallback detection
2426
+ * allows us to parse cards served by endpoints returning the Protobuf JSON structure by
2427
+ * identifying the lack of the "type" field in security schemes or the presence of the
2428
+ * "schemes" wrapper in security entries, and normalizing it before use.
2429
+ */
2430
+ normalizeAgentCard(card) {
2431
+ if (this.isProtoAgentCard(card)) {
2432
+ const parsedProto = AgentCard.fromJSON(card);
2433
+ return FromProto.agentCard(parsedProto);
2434
+ }
2435
+ return card;
2436
+ }
2437
+ isProtoAgentCard(card) {
2438
+ if (!card || typeof card !== "object") return false;
2439
+ const c = card;
2440
+ if (this.hasProtoSecurity(c.security)) return true;
2441
+ if (this.hasProtoSecuritySchemes(c.securitySchemes)) return true;
2442
+ if (Array.isArray(c.skills)) {
2443
+ return c.skills.some(
2444
+ (skill) => skill && typeof skill === "object" && this.hasProtoSecurity(skill.security)
2445
+ );
2446
+ }
2447
+ return false;
2448
+ }
2449
+ hasProtoSecurity(securityArray) {
2450
+ if (Array.isArray(securityArray) && securityArray.length > 0) {
2451
+ const first = securityArray[0];
2452
+ return first && typeof first === "object" && "schemes" in first;
2453
+ }
2454
+ return false;
2455
+ }
2456
+ hasProtoSecuritySchemes(securitySchemes) {
2457
+ if (securitySchemes && typeof securitySchemes === "object") {
2458
+ const schemes = Object.values(securitySchemes);
2459
+ if (schemes.length > 0) {
2460
+ const first = schemes[0];
2461
+ return first && typeof first === "object" && !("type" in first);
2462
+ }
2463
+ }
2464
+ return false;
2465
+ }
2466
+ };
2467
+ var AgentCardResolver = {
2468
+ default: new DefaultAgentCardResolver()
2469
+ };
2470
+
2471
+ // src/client/multitransport-client.ts
2472
+ var Client = class {
2473
+ constructor(transport, agentCard, config) {
2474
+ this.transport = transport;
2475
+ this.agentCard = agentCard;
2476
+ this.config = config;
2477
+ }
2478
+ /**
2479
+ * If the current agent card supports the extended feature, it will try to fetch the extended agent card from the server,
2480
+ * Otherwise it will return the current agent card value.
2481
+ */
2482
+ async getAgentCard(options) {
2483
+ if (this.agentCard.supportsAuthenticatedExtendedCard) {
2484
+ this.agentCard = await this.executeWithInterceptors(
2485
+ { method: "getAgentCard" },
2486
+ options,
2487
+ (_, options2) => this.transport.getExtendedAgentCard(options2)
2488
+ );
2489
+ }
2490
+ return this.agentCard;
2491
+ }
2492
+ /**
2493
+ * Sends a message to an agent to initiate a new interaction or to continue an existing one.
2494
+ * Uses blocking mode by default.
2495
+ */
2496
+ sendMessage(params, options) {
2497
+ params = this.applyClientConfig({
2498
+ params,
2499
+ blocking: !(this.config?.polling ?? false)
2500
+ });
2501
+ return this.executeWithInterceptors(
2502
+ { method: "sendMessage", value: params },
2503
+ options,
2504
+ this.transport.sendMessage.bind(this.transport)
2505
+ );
2506
+ }
2507
+ /**
2508
+ * Sends a message to an agent to initiate/continue a task AND subscribes the client to real-time updates for that task.
2509
+ * Performs fallback to non-streaming if not supported by the agent.
2510
+ */
2511
+ async *sendMessageStream(params, options) {
2512
+ const method = "sendMessageStream";
2513
+ params = this.applyClientConfig({ params, blocking: true });
2514
+ const beforeArgs = {
2515
+ input: { method, value: params },
2516
+ agentCard: this.agentCard,
2517
+ options
2518
+ };
2519
+ const beforeResult = await this.interceptBefore(beforeArgs);
2520
+ if (beforeResult) {
2521
+ const earlyReturn = beforeResult.earlyReturn.value;
2522
+ const afterArgs = {
2523
+ result: { method, value: earlyReturn },
2524
+ agentCard: this.agentCard,
2525
+ options: beforeArgs.options
2526
+ };
2527
+ await this.interceptAfter(afterArgs, beforeResult.executed);
2528
+ yield afterArgs.result.value;
2529
+ return;
2530
+ }
2531
+ if (!this.agentCard.capabilities.streaming) {
2532
+ const result = await this.transport.sendMessage(beforeArgs.input.value, beforeArgs.options);
2533
+ const afterArgs = {
2534
+ result: { method, value: result },
2535
+ agentCard: this.agentCard,
2536
+ options: beforeArgs.options
2537
+ };
2538
+ await this.interceptAfter(afterArgs);
2539
+ yield afterArgs.result.value;
2540
+ return;
2541
+ }
2542
+ for await (const event of this.transport.sendMessageStream(
2543
+ beforeArgs.input.value,
2544
+ beforeArgs.options
2545
+ )) {
2546
+ const afterArgs = {
2547
+ result: { method, value: event },
2548
+ agentCard: this.agentCard,
2549
+ options: beforeArgs.options
2550
+ };
2551
+ await this.interceptAfter(afterArgs);
2552
+ yield afterArgs.result.value;
2553
+ if (afterArgs.earlyReturn) {
2554
+ return;
2555
+ }
2556
+ }
2557
+ }
2558
+ /**
2559
+ * Sets or updates the push notification configuration for a specified task.
2560
+ * Requires the server to have AgentCard.capabilities.pushNotifications: true.
2561
+ */
2562
+ setTaskPushNotificationConfig(params, options) {
2563
+ if (!this.agentCard.capabilities.pushNotifications) {
2564
+ throw new PushNotificationNotSupportedError();
2565
+ }
2566
+ return this.executeWithInterceptors(
2567
+ { method: "setTaskPushNotificationConfig", value: params },
2568
+ options,
2569
+ this.transport.setTaskPushNotificationConfig.bind(this.transport)
2570
+ );
2571
+ }
2572
+ /**
2573
+ * Retrieves the current push notification configuration for a specified task.
2574
+ * Requires the server to have AgentCard.capabilities.pushNotifications: true.
2575
+ */
2576
+ getTaskPushNotificationConfig(params, options) {
2577
+ if (!this.agentCard.capabilities.pushNotifications) {
2578
+ throw new PushNotificationNotSupportedError();
2579
+ }
2580
+ return this.executeWithInterceptors(
2581
+ { method: "getTaskPushNotificationConfig", value: params },
2582
+ options,
2583
+ this.transport.getTaskPushNotificationConfig.bind(this.transport)
2584
+ );
2585
+ }
2586
+ /**
2587
+ * Retrieves the associated push notification configurations for a specified task.
2588
+ * Requires the server to have AgentCard.capabilities.pushNotifications: true.
2589
+ */
2590
+ listTaskPushNotificationConfig(params, options) {
2591
+ if (!this.agentCard.capabilities.pushNotifications) {
2592
+ throw new PushNotificationNotSupportedError();
2593
+ }
2594
+ return this.executeWithInterceptors(
2595
+ { method: "listTaskPushNotificationConfig", value: params },
2596
+ options,
2597
+ this.transport.listTaskPushNotificationConfig.bind(this.transport)
2598
+ );
2599
+ }
2600
+ /**
2601
+ * Deletes an associated push notification configuration for a task.
2602
+ */
2603
+ deleteTaskPushNotificationConfig(params, options) {
2604
+ return this.executeWithInterceptors(
2605
+ { method: "deleteTaskPushNotificationConfig", value: params },
2606
+ options,
2607
+ this.transport.deleteTaskPushNotificationConfig.bind(this.transport)
2608
+ );
2609
+ }
2610
+ /**
2611
+ * Retrieves the current state (including status, artifacts, and optionally history) of a previously initiated task.
2612
+ */
2613
+ getTask(params, options) {
2614
+ return this.executeWithInterceptors(
2615
+ { method: "getTask", value: params },
2616
+ options,
2617
+ this.transport.getTask.bind(this.transport)
2618
+ );
2619
+ }
2620
+ /**
2621
+ * Requests the cancellation of an ongoing task. The server will attempt to cancel the task,
2622
+ * but success is not guaranteed (e.g., the task might have already completed or failed, or cancellation might not be supported at its current stage).
2623
+ */
2624
+ cancelTask(params, options) {
2625
+ return this.executeWithInterceptors(
2626
+ { method: "cancelTask", value: params },
2627
+ options,
2628
+ this.transport.cancelTask.bind(this.transport)
2629
+ );
2630
+ }
2631
+ /**
2632
+ * Allows a client to reconnect to an updates stream for an ongoing task after a previous connection was interrupted.
2633
+ */
2634
+ async *resubscribeTask(params, options) {
2635
+ const method = "resubscribeTask";
2636
+ const beforeArgs = {
2637
+ input: { method, value: params },
2638
+ agentCard: this.agentCard,
2639
+ options
2640
+ };
2641
+ const beforeResult = await this.interceptBefore(beforeArgs);
2642
+ if (beforeResult) {
2643
+ const earlyReturn = beforeResult.earlyReturn.value;
2644
+ const afterArgs = {
2645
+ result: { method, value: earlyReturn },
2646
+ agentCard: this.agentCard,
2647
+ options: beforeArgs.options
2648
+ };
2649
+ await this.interceptAfter(afterArgs, beforeResult.executed);
2650
+ yield afterArgs.result.value;
2651
+ return;
2652
+ }
2653
+ for await (const event of this.transport.resubscribeTask(
2654
+ beforeArgs.input.value,
2655
+ beforeArgs.options
2656
+ )) {
2657
+ const afterArgs = {
2658
+ result: { method, value: event },
2659
+ agentCard: this.agentCard,
2660
+ options: beforeArgs.options
2661
+ };
2662
+ await this.interceptAfter(afterArgs);
2663
+ yield afterArgs.result.value;
2664
+ if (afterArgs.earlyReturn) {
2665
+ return;
2666
+ }
2667
+ }
2668
+ }
2669
+ applyClientConfig({
2670
+ params,
2671
+ blocking
2672
+ }) {
2673
+ const result = { ...params, configuration: params.configuration ?? {} };
2674
+ if (!result.configuration.acceptedOutputModes && this.config?.acceptedOutputModes) {
2675
+ result.configuration.acceptedOutputModes = this.config.acceptedOutputModes;
2676
+ }
2677
+ if (!result.configuration.pushNotificationConfig && this.config?.pushNotificationConfig) {
2678
+ result.configuration.pushNotificationConfig = this.config.pushNotificationConfig;
2679
+ }
2680
+ result.configuration.blocking ??= blocking;
2681
+ return result;
2682
+ }
2683
+ async executeWithInterceptors(input, options, transportCall) {
2684
+ const beforeArgs = {
2685
+ input,
2686
+ agentCard: this.agentCard,
2687
+ options
2688
+ };
2689
+ const beforeResult = await this.interceptBefore(beforeArgs);
2690
+ if (beforeResult) {
2691
+ const afterArgs2 = {
2692
+ result: {
2693
+ method: input.method,
2694
+ value: beforeResult.earlyReturn.value
2695
+ },
2696
+ agentCard: this.agentCard,
2697
+ options: beforeArgs.options
2698
+ };
2699
+ await this.interceptAfter(afterArgs2, beforeResult.executed);
2700
+ return afterArgs2.result.value;
2701
+ }
2702
+ const result = await transportCall(beforeArgs.input.value, beforeArgs.options);
2703
+ const afterArgs = {
2704
+ result: { method: input.method, value: result },
2705
+ agentCard: this.agentCard,
2706
+ options: beforeArgs.options
2707
+ };
2708
+ await this.interceptAfter(afterArgs);
2709
+ return afterArgs.result.value;
2710
+ }
2711
+ async interceptBefore(args) {
2712
+ if (!this.config?.interceptors || this.config.interceptors.length === 0) {
2713
+ return;
2714
+ }
2715
+ const executed = [];
2716
+ for (const interceptor of this.config.interceptors) {
2717
+ await interceptor.before(args);
2718
+ executed.push(interceptor);
2719
+ if (args.earlyReturn) {
2720
+ return {
2721
+ earlyReturn: args.earlyReturn,
2722
+ executed
2723
+ };
2724
+ }
2725
+ }
2726
+ }
2727
+ async interceptAfter(args, interceptors) {
2728
+ const reversedInterceptors = [...interceptors ?? this.config?.interceptors ?? []].reverse();
2729
+ for (const interceptor of reversedInterceptors) {
2730
+ await interceptor.after(args);
2731
+ if (args.earlyReturn) {
2732
+ return;
2733
+ }
2639
2734
  }
2640
2735
  }
2641
- static task(task) {
2736
+ };
2737
+
2738
+ // src/types/converters/to_proto.ts
2739
+ var ToProto = class _ToProto {
2740
+ static agentCard(agentCard) {
2642
2741
  return {
2643
- id: task.id,
2644
- contextId: task.contextId,
2645
- status: _ToProto.taskStatus(task.status),
2646
- artifacts: task.artifacts?.map((a) => _ToProto.artifact(a)) ?? [],
2647
- history: task.history?.map((m) => _ToProto.message(m)) ?? [],
2648
- metadata: task.metadata
2742
+ protocolVersion: agentCard.protocolVersion,
2743
+ name: agentCard.name,
2744
+ description: agentCard.description,
2745
+ url: agentCard.url,
2746
+ preferredTransport: agentCard.preferredTransport ?? "",
2747
+ additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _ToProto.agentInterface(i)) ?? [],
2748
+ provider: _ToProto.agentProvider(agentCard.provider),
2749
+ version: agentCard.version,
2750
+ documentationUrl: agentCard.documentationUrl ?? "",
2751
+ capabilities: _ToProto.agentCapabilities(agentCard.capabilities),
2752
+ securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
2753
+ Object.entries(agentCard.securitySchemes).map(([key, value]) => [
2754
+ key,
2755
+ _ToProto.securityScheme(value)
2756
+ ])
2757
+ ) : {},
2758
+ security: agentCard.security?.map((s) => _ToProto.security(s)) ?? [],
2759
+ defaultInputModes: agentCard.defaultInputModes,
2760
+ defaultOutputModes: agentCard.defaultOutputModes,
2761
+ skills: agentCard.skills.map((s) => _ToProto.agentSkill(s)),
2762
+ supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
2763
+ signatures: agentCard.signatures?.map((s) => _ToProto.agentCardSignature(s)) ?? []
2649
2764
  };
2650
2765
  }
2651
- static taskStatus(status) {
2766
+ static agentCardSignature(signatures) {
2652
2767
  return {
2653
- state: _ToProto.taskState(status.state),
2654
- update: _ToProto.message(status.message),
2655
- timestamp: status.timestamp
2768
+ protected: signatures.protected,
2769
+ signature: signatures.signature,
2770
+ header: signatures.header
2656
2771
  };
2657
2772
  }
2658
- static artifact(artifact) {
2773
+ static agentSkill(skill) {
2659
2774
  return {
2660
- artifactId: artifact.artifactId,
2661
- name: artifact.name ?? "",
2662
- description: artifact.description ?? "",
2663
- parts: artifact.parts.map((p) => _ToProto.part(p)),
2664
- metadata: artifact.metadata,
2665
- extensions: artifact.extensions ? artifact.extensions : []
2775
+ id: skill.id,
2776
+ name: skill.name,
2777
+ description: skill.description,
2778
+ tags: skill.tags ?? [],
2779
+ examples: skill.examples ?? [],
2780
+ inputModes: skill.inputModes ?? [],
2781
+ outputModes: skill.outputModes ?? [],
2782
+ security: skill.security ? skill.security.map((s) => _ToProto.security(s)) : []
2666
2783
  };
2667
2784
  }
2668
- static taskState(state) {
2669
- switch (state) {
2670
- case "submitted":
2671
- return 1 /* TASK_STATE_SUBMITTED */;
2672
- case "working":
2673
- return 2 /* TASK_STATE_WORKING */;
2674
- case "input-required":
2675
- return 6 /* TASK_STATE_INPUT_REQUIRED */;
2676
- case "rejected":
2677
- return 7 /* TASK_STATE_REJECTED */;
2678
- case "auth-required":
2679
- return 8 /* TASK_STATE_AUTH_REQUIRED */;
2680
- case "completed":
2681
- return 3 /* TASK_STATE_COMPLETED */;
2682
- case "failed":
2683
- return 4 /* TASK_STATE_FAILED */;
2684
- case "canceled":
2685
- return 5 /* TASK_STATE_CANCELLED */;
2686
- case "unknown":
2687
- return 0 /* TASK_STATE_UNSPECIFIED */;
2785
+ static security(security) {
2786
+ return {
2787
+ schemes: Object.fromEntries(
2788
+ Object.entries(security).map(([key, value]) => {
2789
+ return [key, { list: value }];
2790
+ })
2791
+ )
2792
+ };
2793
+ }
2794
+ static securityScheme(scheme) {
2795
+ switch (scheme.type) {
2796
+ case "apiKey":
2797
+ return {
2798
+ scheme: {
2799
+ $case: "apiKeySecurityScheme",
2800
+ value: {
2801
+ name: scheme.name,
2802
+ location: scheme.in,
2803
+ description: scheme.description ?? ""
2804
+ }
2805
+ }
2806
+ };
2807
+ case "http":
2808
+ return {
2809
+ scheme: {
2810
+ $case: "httpAuthSecurityScheme",
2811
+ value: {
2812
+ description: scheme.description ?? "",
2813
+ scheme: scheme.scheme,
2814
+ bearerFormat: scheme.bearerFormat ?? ""
2815
+ }
2816
+ }
2817
+ };
2818
+ case "mutualTLS":
2819
+ return {
2820
+ scheme: {
2821
+ $case: "mtlsSecurityScheme",
2822
+ value: {
2823
+ description: scheme.description ?? ""
2824
+ }
2825
+ }
2826
+ };
2827
+ case "oauth2":
2828
+ return {
2829
+ scheme: {
2830
+ $case: "oauth2SecurityScheme",
2831
+ value: {
2832
+ description: scheme.description ?? "",
2833
+ flows: _ToProto.oauthFlows(scheme.flows),
2834
+ oauth2MetadataUrl: scheme.oauth2MetadataUrl ?? ""
2835
+ }
2836
+ }
2837
+ };
2838
+ case "openIdConnect":
2839
+ return {
2840
+ scheme: {
2841
+ $case: "openIdConnectSecurityScheme",
2842
+ value: {
2843
+ description: scheme.description ?? "",
2844
+ openIdConnectUrl: scheme.openIdConnectUrl
2845
+ }
2846
+ }
2847
+ };
2688
2848
  default:
2689
- return -1 /* UNRECOGNIZED */;
2849
+ throw A2AError.internalError(`Unsupported security scheme type`);
2690
2850
  }
2691
2851
  }
2692
- static part(part) {
2693
- if (part.kind === "text") {
2852
+ static oauthFlows(flows) {
2853
+ if (flows.implicit) {
2694
2854
  return {
2695
- part: { $case: "text", value: part.text }
2855
+ flow: {
2856
+ $case: "implicit",
2857
+ value: {
2858
+ authorizationUrl: flows.implicit.authorizationUrl,
2859
+ scopes: flows.implicit.scopes,
2860
+ refreshUrl: flows.implicit.refreshUrl ?? ""
2861
+ }
2862
+ }
2696
2863
  };
2697
- }
2698
- if (part.kind === "file") {
2699
- let filePart;
2700
- if ("uri" in part.file) {
2701
- filePart = {
2702
- file: { $case: "fileWithUri", value: part.file.uri },
2703
- mimeType: part.file.mimeType
2704
- };
2705
- } else if ("bytes" in part.file) {
2706
- filePart = {
2707
- file: { $case: "fileWithBytes", value: Buffer.from(part.file.bytes, "base64") },
2708
- mimeType: part.file.mimeType
2709
- };
2710
- } else {
2711
- throw A2AError.internalError("Invalid file part");
2712
- }
2864
+ } else if (flows.password) {
2713
2865
  return {
2714
- part: { $case: "file", value: filePart }
2866
+ flow: {
2867
+ $case: "password",
2868
+ value: {
2869
+ tokenUrl: flows.password.tokenUrl,
2870
+ scopes: flows.password.scopes,
2871
+ refreshUrl: flows.password.refreshUrl ?? ""
2872
+ }
2873
+ }
2715
2874
  };
2716
- }
2717
- if (part.kind === "data") {
2875
+ } else if (flows.clientCredentials) {
2718
2876
  return {
2719
- part: { $case: "data", value: { data: part.data } }
2877
+ flow: {
2878
+ $case: "clientCredentials",
2879
+ value: {
2880
+ tokenUrl: flows.clientCredentials.tokenUrl,
2881
+ scopes: flows.clientCredentials.scopes,
2882
+ refreshUrl: flows.clientCredentials.refreshUrl ?? ""
2883
+ }
2884
+ }
2885
+ };
2886
+ } else if (flows.authorizationCode) {
2887
+ return {
2888
+ flow: {
2889
+ $case: "authorizationCode",
2890
+ value: {
2891
+ authorizationUrl: flows.authorizationCode.authorizationUrl,
2892
+ tokenUrl: flows.authorizationCode.tokenUrl,
2893
+ scopes: flows.authorizationCode.scopes,
2894
+ refreshUrl: flows.authorizationCode.refreshUrl ?? ""
2895
+ }
2896
+ }
2720
2897
  };
2898
+ } else {
2899
+ throw A2AError.internalError(`Unsupported OAuth flows`);
2721
2900
  }
2722
- throw A2AError.internalError("Invalid part type");
2723
2901
  }
2724
- static messageSendParams(params) {
2902
+ static agentInterface(agentInterface) {
2725
2903
  return {
2726
- request: _ToProto.message(params.message),
2727
- configuration: _ToProto.configuration(params.configuration),
2728
- metadata: params.metadata
2904
+ transport: agentInterface.transport,
2905
+ url: agentInterface.url
2729
2906
  };
2730
2907
  }
2731
- static configuration(configuration) {
2732
- if (!configuration) {
2908
+ static agentProvider(agentProvider) {
2909
+ if (!agentProvider) {
2733
2910
  return void 0;
2734
2911
  }
2735
2912
  return {
2736
- blocking: configuration.blocking,
2737
- acceptedOutputModes: configuration.acceptedOutputModes ?? [],
2738
- pushNotification: _ToProto.pushNotificationConfig(configuration.pushNotificationConfig),
2739
- historyLength: configuration.historyLength ?? 0
2740
- };
2741
- }
2742
- static taskQueryParams(params) {
2743
- return {
2744
- name: generateTaskName(params.id),
2745
- historyLength: params.historyLength ?? 0
2746
- };
2747
- }
2748
- static cancelTaskRequest(params) {
2749
- return {
2750
- name: generateTaskName(params.id)
2751
- };
2752
- }
2753
- static taskIdParams(params) {
2754
- return {
2755
- name: generateTaskName(params.id)
2913
+ url: agentProvider.url,
2914
+ organization: agentProvider.organization
2756
2915
  };
2757
2916
  }
2758
- static getAgentCardRequest() {
2759
- return {};
2760
- }
2761
- };
2762
-
2763
- // src/types/converters/from_proto.ts
2764
- var FromProto = class _FromProto {
2765
- static taskQueryParams(request) {
2917
+ static agentCapabilities(capabilities) {
2766
2918
  return {
2767
- id: extractTaskId(request.name),
2768
- historyLength: request.historyLength
2919
+ streaming: capabilities.streaming,
2920
+ pushNotifications: capabilities.pushNotifications,
2921
+ extensions: capabilities.extensions ? capabilities.extensions.map((e) => _ToProto.agentExtension(e)) : []
2769
2922
  };
2770
2923
  }
2771
- static taskIdParams(request) {
2924
+ static agentExtension(extension) {
2772
2925
  return {
2773
- id: extractTaskId(request.name)
2926
+ uri: extension.uri,
2927
+ description: extension.description ?? "",
2928
+ required: extension.required ?? false,
2929
+ params: extension.params
2774
2930
  };
2775
2931
  }
2776
- static getTaskPushNotificationConfigParams(request) {
2777
- const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
2932
+ static listTaskPushNotificationConfig(config) {
2778
2933
  return {
2779
- id: taskId,
2780
- pushNotificationConfigId: configId
2934
+ configs: config.map((c) => _ToProto.taskPushNotificationConfig(c)),
2935
+ nextPageToken: ""
2781
2936
  };
2782
2937
  }
2783
- static listTaskPushNotificationConfigParams(request) {
2938
+ static getTaskPushNotificationConfigParams(config) {
2784
2939
  return {
2785
- id: extractTaskId(request.parent)
2940
+ name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
2786
2941
  };
2787
2942
  }
2788
- static createTaskPushNotificationConfig(request) {
2789
- if (!request.config?.pushNotificationConfig) {
2790
- throw A2AError.invalidParams(
2791
- "Request must include a `config` object with a `pushNotificationConfig`"
2792
- );
2793
- }
2943
+ static listTaskPushNotificationConfigParams(config) {
2794
2944
  return {
2795
- taskId: extractTaskId(request.parent),
2796
- pushNotificationConfig: _FromProto.pushNotificationConfig(
2797
- request.config.pushNotificationConfig
2798
- )
2945
+ parent: generateTaskName(config.id),
2946
+ pageToken: "",
2947
+ pageSize: 0
2799
2948
  };
2800
2949
  }
2801
- static deleteTaskPushNotificationConfigParams(request) {
2802
- const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
2950
+ static deleteTaskPushNotificationConfigParams(config) {
2803
2951
  return {
2804
- id: taskId,
2805
- pushNotificationConfigId: configId
2952
+ name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
2806
2953
  };
2807
2954
  }
2808
- static message(message) {
2809
- if (!message) {
2810
- return void 0;
2811
- }
2955
+ static taskPushNotificationConfig(config) {
2812
2956
  return {
2813
- kind: "message",
2814
- messageId: message.messageId,
2815
- parts: message.content.map((p) => _FromProto.part(p)),
2816
- contextId: message.contextId || void 0,
2817
- taskId: message.taskId || void 0,
2818
- role: _FromProto.role(message.role),
2819
- metadata: message.metadata,
2820
- extensions: message.extensions
2957
+ name: generatePushNotificationConfigName(
2958
+ config.taskId,
2959
+ config.pushNotificationConfig.id ?? ""
2960
+ ),
2961
+ pushNotificationConfig: _ToProto.pushNotificationConfig(config.pushNotificationConfig)
2821
2962
  };
2822
2963
  }
2823
- static role(role) {
2824
- switch (role) {
2825
- case 2 /* ROLE_AGENT */:
2826
- return "agent";
2827
- case 1 /* ROLE_USER */:
2828
- return "user";
2829
- default:
2830
- throw A2AError.invalidParams(`Invalid role: ${role}`);
2831
- }
2832
- }
2833
- static messageSendConfiguration(configuration) {
2834
- if (!configuration) {
2835
- return void 0;
2836
- }
2964
+ static taskPushNotificationConfigCreate(config) {
2837
2965
  return {
2838
- blocking: configuration.blocking,
2839
- acceptedOutputModes: configuration.acceptedOutputModes,
2840
- pushNotificationConfig: _FromProto.pushNotificationConfig(configuration.pushNotification)
2966
+ parent: generateTaskName(config.taskId),
2967
+ config: _ToProto.taskPushNotificationConfig(config),
2968
+ configId: config.pushNotificationConfig.id
2841
2969
  };
2842
2970
  }
2843
2971
  static pushNotificationConfig(config) {
@@ -2845,10 +2973,10 @@ var FromProto = class _FromProto {
2845
2973
  return void 0;
2846
2974
  }
2847
2975
  return {
2848
- id: config.id,
2976
+ id: config.id ?? "",
2849
2977
  url: config.url,
2850
- token: config.token || void 0,
2851
- authentication: _FromProto.pushNotificationAuthenticationInfo(config.authentication)
2978
+ token: config.token ?? "",
2979
+ authentication: _ToProto.pushNotificationAuthenticationInfo(config.authentication)
2852
2980
  };
2853
2981
  }
2854
2982
  static pushNotificationAuthenticationInfo(authInfo) {
@@ -2857,307 +2985,221 @@ var FromProto = class _FromProto {
2857
2985
  }
2858
2986
  return {
2859
2987
  schemes: authInfo.schemes,
2860
- credentials: authInfo.credentials
2988
+ credentials: authInfo.credentials ?? ""
2861
2989
  };
2862
2990
  }
2863
- static part(part) {
2864
- if (part.part?.$case === "text") {
2991
+ static messageStreamResult(event) {
2992
+ if (event.kind === "message") {
2865
2993
  return {
2866
- kind: "text",
2867
- text: part.part.value
2994
+ payload: {
2995
+ $case: "msg",
2996
+ value: _ToProto.message(event)
2997
+ }
2868
2998
  };
2869
- }
2870
- if (part.part?.$case === "file") {
2871
- const filePart = part.part.value;
2872
- if (filePart.file?.$case === "fileWithUri") {
2873
- return {
2874
- kind: "file",
2875
- file: {
2876
- uri: filePart.file.value,
2877
- mimeType: filePart.mimeType
2878
- }
2879
- };
2880
- } else if (filePart.file?.$case === "fileWithBytes") {
2881
- return {
2882
- kind: "file",
2883
- file: {
2884
- bytes: filePart.file.value.toString("base64"),
2885
- mimeType: filePart.mimeType
2886
- }
2887
- };
2888
- }
2889
- throw A2AError.invalidParams("Invalid file part type");
2890
- }
2891
- if (part.part?.$case === "data") {
2999
+ } else if (event.kind === "task") {
2892
3000
  return {
2893
- kind: "data",
2894
- data: part.part.value.data
3001
+ payload: {
3002
+ $case: "task",
3003
+ value: _ToProto.task(event)
3004
+ }
2895
3005
  };
2896
- }
2897
- throw A2AError.invalidParams("Invalid part type");
2898
- }
2899
- static messageSendParams(request) {
2900
- return {
2901
- message: _FromProto.message(request.request),
2902
- configuration: _FromProto.messageSendConfiguration(request.configuration),
2903
- metadata: request.metadata
2904
- };
2905
- }
2906
- static sendMessageResult(response) {
2907
- if (response.payload?.$case === "task") {
2908
- return _FromProto.task(response.payload.value);
2909
- } else if (response.payload?.$case === "msg") {
2910
- return _FromProto.message(response.payload.value);
2911
- }
2912
- throw A2AError.invalidParams("Invalid SendMessageResponse: missing result");
2913
- }
2914
- static task(task) {
2915
- return {
2916
- kind: "task",
2917
- id: task.id,
2918
- status: _FromProto.taskStatus(task.status),
2919
- contextId: task.contextId,
2920
- artifacts: task.artifacts?.map((a) => _FromProto.artifact(a)),
2921
- history: task.history?.map((h) => _FromProto.message(h)),
2922
- metadata: task.metadata
2923
- };
2924
- }
2925
- static taskStatus(status) {
2926
- return {
2927
- message: _FromProto.message(status.update),
2928
- state: _FromProto.taskState(status.state),
2929
- timestamp: status.timestamp
2930
- };
2931
- }
2932
- static taskState(state) {
2933
- switch (state) {
2934
- case 1 /* TASK_STATE_SUBMITTED */:
2935
- return "submitted";
2936
- case 2 /* TASK_STATE_WORKING */:
2937
- return "working";
2938
- case 6 /* TASK_STATE_INPUT_REQUIRED */:
2939
- return "input-required";
2940
- case 3 /* TASK_STATE_COMPLETED */:
2941
- return "completed";
2942
- case 5 /* TASK_STATE_CANCELLED */:
2943
- return "canceled";
2944
- case 4 /* TASK_STATE_FAILED */:
2945
- return "failed";
2946
- case 7 /* TASK_STATE_REJECTED */:
2947
- return "rejected";
2948
- case 8 /* TASK_STATE_AUTH_REQUIRED */:
2949
- return "auth-required";
2950
- case 0 /* TASK_STATE_UNSPECIFIED */:
2951
- return "unknown";
2952
- default:
2953
- throw A2AError.invalidParams(`Invalid task state: ${state}`);
3006
+ } else if (event.kind === "status-update") {
3007
+ return {
3008
+ payload: {
3009
+ $case: "statusUpdate",
3010
+ value: _ToProto.taskStatusUpdateEvent(event)
3011
+ }
3012
+ };
3013
+ } else if (event.kind === "artifact-update") {
3014
+ return {
3015
+ payload: {
3016
+ $case: "artifactUpdate",
3017
+ value: _ToProto.taskArtifactUpdateEvent(event)
3018
+ }
3019
+ };
3020
+ } else {
3021
+ throw A2AError.internalError("Invalid event type");
2954
3022
  }
2955
3023
  }
2956
- static artifact(artifact) {
3024
+ static taskStatusUpdateEvent(event) {
2957
3025
  return {
2958
- artifactId: artifact.artifactId,
2959
- name: artifact.name || void 0,
2960
- description: artifact.description || void 0,
2961
- parts: artifact.parts.map((p) => _FromProto.part(p)),
2962
- metadata: artifact.metadata
3026
+ taskId: event.taskId,
3027
+ status: _ToProto.taskStatus(event.status),
3028
+ contextId: event.contextId,
3029
+ metadata: event.metadata,
3030
+ final: event.final
2963
3031
  };
2964
3032
  }
2965
- static taskPushNotificationConfig(request) {
3033
+ static taskArtifactUpdateEvent(event) {
2966
3034
  return {
2967
- taskId: extractTaskId(request.name),
2968
- pushNotificationConfig: _FromProto.pushNotificationConfig(request.pushNotificationConfig)
3035
+ taskId: event.taskId,
3036
+ artifact: _ToProto.artifact(event.artifact),
3037
+ contextId: event.contextId,
3038
+ metadata: event.metadata,
3039
+ append: event.append,
3040
+ lastChunk: event.lastChunk
2969
3041
  };
2970
3042
  }
2971
- static listTaskPushNotificationConfig(request) {
2972
- return request.configs.map((c) => _FromProto.taskPushNotificationConfig(c));
2973
- }
2974
- static agentCard(agentCard) {
2975
- return {
2976
- additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _FromProto.agentInterface(i)),
2977
- capabilities: agentCard.capabilities ? _FromProto.agentCapabilities(agentCard.capabilities) : {},
2978
- defaultInputModes: agentCard.defaultInputModes,
2979
- defaultOutputModes: agentCard.defaultOutputModes,
2980
- description: agentCard.description,
2981
- documentationUrl: agentCard.documentationUrl || void 0,
2982
- name: agentCard.name,
2983
- preferredTransport: agentCard.preferredTransport,
2984
- provider: agentCard.provider ? _FromProto.agentProvider(agentCard.provider) : void 0,
2985
- protocolVersion: agentCard.protocolVersion,
2986
- security: agentCard.security?.map((s) => _FromProto.security(s)),
2987
- securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
2988
- Object.entries(agentCard.securitySchemes).map(([key, value]) => [
2989
- key,
2990
- _FromProto.securityScheme(value)
2991
- ])
2992
- ) : {},
2993
- skills: agentCard.skills.map((s) => _FromProto.skills(s)),
2994
- signatures: agentCard.signatures?.map((s) => _FromProto.agentCardSignature(s)),
2995
- supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
2996
- url: agentCard.url,
2997
- version: agentCard.version
2998
- };
3043
+ static messageSendResult(params) {
3044
+ if (params.kind === "message") {
3045
+ return {
3046
+ payload: {
3047
+ $case: "msg",
3048
+ value: _ToProto.message(params)
3049
+ }
3050
+ };
3051
+ } else if (params.kind === "task") {
3052
+ return {
3053
+ payload: {
3054
+ $case: "task",
3055
+ value: _ToProto.task(params)
3056
+ }
3057
+ };
3058
+ }
2999
3059
  }
3000
- static agentCapabilities(capabilities) {
3060
+ static message(message) {
3061
+ if (!message) {
3062
+ return void 0;
3063
+ }
3001
3064
  return {
3002
- extensions: capabilities.extensions?.map((e) => _FromProto.agentExtension(e)),
3003
- pushNotifications: capabilities.pushNotifications,
3004
- streaming: capabilities.streaming
3065
+ messageId: message.messageId,
3066
+ content: message.parts.map((p) => _ToProto.part(p)),
3067
+ contextId: message.contextId ?? "",
3068
+ taskId: message.taskId ?? "",
3069
+ role: _ToProto.role(message.role),
3070
+ metadata: message.metadata,
3071
+ extensions: message.extensions ?? []
3005
3072
  };
3006
3073
  }
3007
- static agentExtension(extension) {
3074
+ static role(role) {
3075
+ switch (role) {
3076
+ case "agent":
3077
+ return 2 /* ROLE_AGENT */;
3078
+ case "user":
3079
+ return 1 /* ROLE_USER */;
3080
+ default:
3081
+ throw A2AError.internalError(`Invalid role`);
3082
+ }
3083
+ }
3084
+ static task(task) {
3008
3085
  return {
3009
- uri: extension.uri,
3010
- description: extension.description || void 0,
3011
- required: extension.required,
3012
- params: extension.params
3086
+ id: task.id,
3087
+ contextId: task.contextId,
3088
+ status: _ToProto.taskStatus(task.status),
3089
+ artifacts: task.artifacts?.map((a) => _ToProto.artifact(a)) ?? [],
3090
+ history: task.history?.map((m) => _ToProto.message(m)) ?? [],
3091
+ metadata: task.metadata
3013
3092
  };
3014
3093
  }
3015
- static agentInterface(intf) {
3094
+ static taskStatus(status) {
3016
3095
  return {
3017
- transport: intf.transport,
3018
- url: intf.url
3096
+ state: _ToProto.taskState(status.state),
3097
+ update: _ToProto.message(status.message),
3098
+ timestamp: status.timestamp
3019
3099
  };
3020
3100
  }
3021
- static agentProvider(provider) {
3101
+ static artifact(artifact) {
3022
3102
  return {
3023
- organization: provider.organization,
3024
- url: provider.url
3103
+ artifactId: artifact.artifactId,
3104
+ name: artifact.name ?? "",
3105
+ description: artifact.description ?? "",
3106
+ parts: artifact.parts.map((p) => _ToProto.part(p)),
3107
+ metadata: artifact.metadata,
3108
+ extensions: artifact.extensions ? artifact.extensions : []
3025
3109
  };
3026
3110
  }
3027
- static security(security) {
3028
- return Object.fromEntries(
3029
- Object.entries(security.schemes)?.map(([key, value]) => [key, value.list])
3030
- );
3031
- }
3032
- static securityScheme(securitySchemes) {
3033
- switch (securitySchemes.scheme?.$case) {
3034
- case "apiKeySecurityScheme":
3035
- return {
3036
- type: "apiKey",
3037
- name: securitySchemes.scheme.value.name,
3038
- in: securitySchemes.scheme.value.location,
3039
- description: securitySchemes.scheme.value.description || void 0
3040
- };
3041
- case "httpAuthSecurityScheme":
3042
- return {
3043
- type: "http",
3044
- scheme: securitySchemes.scheme.value.scheme,
3045
- bearerFormat: securitySchemes.scheme.value.bearerFormat || void 0,
3046
- description: securitySchemes.scheme.value.description || void 0
3047
- };
3048
- case "mtlsSecurityScheme":
3049
- return {
3050
- type: "mutualTLS",
3051
- description: securitySchemes.scheme.value.description || void 0
3052
- };
3053
- case "oauth2SecurityScheme":
3054
- return {
3055
- type: "oauth2",
3056
- description: securitySchemes.scheme.value.description || void 0,
3057
- flows: _FromProto.oauthFlows(securitySchemes.scheme.value.flows),
3058
- oauth2MetadataUrl: securitySchemes.scheme.value.oauth2MetadataUrl || void 0
3059
- };
3060
- case "openIdConnectSecurityScheme":
3061
- return {
3062
- type: "openIdConnect",
3063
- description: securitySchemes.scheme.value.description || void 0,
3064
- openIdConnectUrl: securitySchemes.scheme.value.openIdConnectUrl
3065
- };
3111
+ static taskState(state) {
3112
+ switch (state) {
3113
+ case "submitted":
3114
+ return 1 /* TASK_STATE_SUBMITTED */;
3115
+ case "working":
3116
+ return 2 /* TASK_STATE_WORKING */;
3117
+ case "input-required":
3118
+ return 6 /* TASK_STATE_INPUT_REQUIRED */;
3119
+ case "rejected":
3120
+ return 7 /* TASK_STATE_REJECTED */;
3121
+ case "auth-required":
3122
+ return 8 /* TASK_STATE_AUTH_REQUIRED */;
3123
+ case "completed":
3124
+ return 3 /* TASK_STATE_COMPLETED */;
3125
+ case "failed":
3126
+ return 4 /* TASK_STATE_FAILED */;
3127
+ case "canceled":
3128
+ return 5 /* TASK_STATE_CANCELLED */;
3129
+ case "unknown":
3130
+ return 0 /* TASK_STATE_UNSPECIFIED */;
3066
3131
  default:
3067
- throw A2AError.internalError(`Unsupported security scheme type`);
3132
+ return -1 /* UNRECOGNIZED */;
3068
3133
  }
3069
3134
  }
3070
- static oauthFlows(flows) {
3071
- switch (flows.flow?.$case) {
3072
- case "implicit":
3073
- return {
3074
- implicit: {
3075
- authorizationUrl: flows.flow.value.authorizationUrl,
3076
- scopes: flows.flow.value.scopes,
3077
- refreshUrl: flows.flow.value.refreshUrl || void 0
3078
- }
3079
- };
3080
- case "password":
3081
- return {
3082
- password: {
3083
- refreshUrl: flows.flow.value.refreshUrl || void 0,
3084
- scopes: flows.flow.value.scopes,
3085
- tokenUrl: flows.flow.value.tokenUrl
3086
- }
3087
- };
3088
- case "authorizationCode":
3089
- return {
3090
- authorizationCode: {
3091
- refreshUrl: flows.flow.value.refreshUrl || void 0,
3092
- authorizationUrl: flows.flow.value.authorizationUrl,
3093
- scopes: flows.flow.value.scopes,
3094
- tokenUrl: flows.flow.value.tokenUrl
3095
- }
3135
+ static part(part) {
3136
+ if (part.kind === "text") {
3137
+ return {
3138
+ part: { $case: "text", value: part.text }
3139
+ };
3140
+ }
3141
+ if (part.kind === "file") {
3142
+ let filePart;
3143
+ if ("uri" in part.file) {
3144
+ filePart = {
3145
+ file: { $case: "fileWithUri", value: part.file.uri },
3146
+ mimeType: part.file.mimeType
3096
3147
  };
3097
- case "clientCredentials":
3098
- return {
3099
- clientCredentials: {
3100
- refreshUrl: flows.flow.value.refreshUrl || void 0,
3101
- scopes: flows.flow.value.scopes,
3102
- tokenUrl: flows.flow.value.tokenUrl
3103
- }
3148
+ } else if ("bytes" in part.file) {
3149
+ filePart = {
3150
+ file: { $case: "fileWithBytes", value: Buffer.from(part.file.bytes, "base64") },
3151
+ mimeType: part.file.mimeType
3104
3152
  };
3105
- default:
3106
- throw A2AError.internalError(`Unsupported OAuth flows`);
3153
+ } else {
3154
+ throw A2AError.internalError("Invalid file part");
3155
+ }
3156
+ return {
3157
+ part: { $case: "file", value: filePart }
3158
+ };
3159
+ }
3160
+ if (part.kind === "data") {
3161
+ return {
3162
+ part: { $case: "data", value: { data: part.data } }
3163
+ };
3107
3164
  }
3165
+ throw A2AError.internalError("Invalid part type");
3108
3166
  }
3109
- static skills(skill) {
3167
+ static messageSendParams(params) {
3110
3168
  return {
3111
- id: skill.id,
3112
- name: skill.name,
3113
- description: skill.description,
3114
- tags: skill.tags,
3115
- examples: skill.examples,
3116
- inputModes: skill.inputModes,
3117
- outputModes: skill.outputModes,
3118
- security: skill.security?.map((s) => _FromProto.security(s))
3169
+ request: _ToProto.message(params.message),
3170
+ configuration: _ToProto.configuration(params.configuration),
3171
+ metadata: params.metadata
3119
3172
  };
3120
3173
  }
3121
- static agentCardSignature(signatures) {
3174
+ static configuration(configuration) {
3175
+ if (!configuration) {
3176
+ return void 0;
3177
+ }
3122
3178
  return {
3123
- protected: signatures.protected,
3124
- signature: signatures.signature,
3125
- header: signatures.header
3179
+ blocking: configuration.blocking,
3180
+ acceptedOutputModes: configuration.acceptedOutputModes ?? [],
3181
+ pushNotification: _ToProto.pushNotificationConfig(configuration.pushNotificationConfig),
3182
+ historyLength: configuration.historyLength ?? 0
3126
3183
  };
3127
3184
  }
3128
- static taskStatusUpdateEvent(event) {
3185
+ static taskQueryParams(params) {
3129
3186
  return {
3130
- kind: "status-update",
3131
- taskId: event.taskId,
3132
- status: _FromProto.taskStatus(event.status),
3133
- contextId: event.contextId,
3134
- metadata: event.metadata,
3135
- final: event.final
3187
+ name: generateTaskName(params.id),
3188
+ historyLength: params.historyLength ?? 0
3136
3189
  };
3137
3190
  }
3138
- static taskArtifactUpdateEvent(event) {
3191
+ static cancelTaskRequest(params) {
3139
3192
  return {
3140
- kind: "artifact-update",
3141
- taskId: event.taskId,
3142
- artifact: _FromProto.artifact(event.artifact),
3143
- contextId: event.contextId,
3144
- metadata: event.metadata,
3145
- lastChunk: event.lastChunk
3193
+ name: generateTaskName(params.id)
3146
3194
  };
3147
3195
  }
3148
- static messageStreamResult(event) {
3149
- switch (event.payload?.$case) {
3150
- case "msg":
3151
- return _FromProto.message(event.payload.value);
3152
- case "task":
3153
- return _FromProto.task(event.payload.value);
3154
- case "statusUpdate":
3155
- return _FromProto.taskStatusUpdateEvent(event.payload.value);
3156
- case "artifactUpdate":
3157
- return _FromProto.taskArtifactUpdateEvent(event.payload.value);
3158
- default:
3159
- throw A2AError.internalError("Invalid event type in StreamResponse");
3160
- }
3196
+ static taskIdParams(params) {
3197
+ return {
3198
+ name: generateTaskName(params.id)
3199
+ };
3200
+ }
3201
+ static getAgentCardRequest() {
3202
+ return {};
3161
3203
  }
3162
3204
  };
3163
3205
 
@@ -3501,18 +3543,15 @@ var ClientFactory = class {
3501
3543
  ...additionalInterfaces.map((i) => i.transport)
3502
3544
  ];
3503
3545
  for (const transport of transportsByPreference) {
3504
- if (!urlsPerAgentTransports.has(transport)) {
3505
- continue;
3506
- }
3546
+ const url = urlsPerAgentTransports.get(transport);
3507
3547
  const factory = this.transportsByName.get(transport);
3508
- if (!factory) {
3509
- continue;
3548
+ if (factory && url) {
3549
+ return new Client(
3550
+ await factory.create(url, agentCard),
3551
+ agentCard,
3552
+ this.options.clientConfig
3553
+ );
3510
3554
  }
3511
- return new Client(
3512
- await factory.create(urlsPerAgentTransports.get(transport), agentCard),
3513
- agentCard,
3514
- this.options.clientConfig
3515
- );
3516
3555
  }
3517
3556
  throw new Error(
3518
3557
  "No compatible transport found, available transports: " + [...this.transportsByName.keys()].join()