@a2a-js/sdk 0.3.9 → 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.
- package/dist/{a2a_request_handler-BuP9LgXH.d.ts → a2a_request_handler-BiphzMH4.d.cts} +2 -2
- package/dist/{a2a_request_handler-B3LxMq3P.d.cts → a2a_request_handler-C9bZITjN.d.ts} +2 -2
- package/dist/{chunk-U3QAVT4H.js → chunk-2TNRJNPO.js} +694 -694
- package/dist/{chunk-TS5RMC7F.js → chunk-WMQQYH7W.js} +16 -1
- package/dist/client/index.cjs +1339 -1284
- package/dist/client/index.d.cts +7 -3
- package/dist/client/index.d.ts +7 -3
- package/dist/client/index.js +80 -40
- package/dist/client/transports/grpc/index.d.cts +2 -2
- package/dist/client/transports/grpc/index.d.ts +2 -2
- package/dist/client/transports/grpc/index.js +1 -1
- package/dist/{core-Ci-lR0jz.d.cts → core-BHroNzI0.d.cts} +2 -2
- package/dist/{core-BAzQJfA2.d.ts → core-NwQicv77.d.ts} +2 -2
- package/dist/{extensions-DvruCIzw.d.cts → extensions-APfrw8gz.d.cts} +1 -1
- package/dist/{extensions-DvruCIzw.d.ts → extensions-APfrw8gz.d.ts} +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/server/express/index.cjs +2 -2
- package/dist/server/express/index.d.cts +2 -2
- package/dist/server/express/index.d.ts +2 -2
- package/dist/server/express/index.js +4 -4
- package/dist/server/grpc/index.d.cts +2 -2
- package/dist/server/grpc/index.d.ts +2 -2
- package/dist/server/grpc/index.js +1 -1
- package/dist/server/index.cjs +0 -1
- package/dist/server/index.d.cts +3 -4
- package/dist/server/index.d.ts +3 -4
- package/dist/server/index.js +0 -1
- package/package.json +6 -4
package/dist/client/index.cjs
CHANGED
|
@@ -114,7 +114,8 @@ async function* parseSseStream(response) {
|
|
|
114
114
|
let buffer = "";
|
|
115
115
|
let eventType = "message";
|
|
116
116
|
let eventData = "";
|
|
117
|
-
|
|
117
|
+
const stream = response.body.pipeThrough(new TextDecoderStream());
|
|
118
|
+
for await (const value of readFrom(stream)) {
|
|
118
119
|
buffer += value;
|
|
119
120
|
let lineEndIndex;
|
|
120
121
|
while ((lineEndIndex = buffer.indexOf("\n")) >= 0) {
|
|
@@ -137,6 +138,20 @@ async function* parseSseStream(response) {
|
|
|
137
138
|
yield { type: eventType, data: eventData };
|
|
138
139
|
}
|
|
139
140
|
}
|
|
141
|
+
async function* readFrom(stream) {
|
|
142
|
+
const reader = stream.getReader();
|
|
143
|
+
try {
|
|
144
|
+
while (true) {
|
|
145
|
+
const { done, value } = await reader.read();
|
|
146
|
+
if (done) {
|
|
147
|
+
break;
|
|
148
|
+
}
|
|
149
|
+
yield value;
|
|
150
|
+
}
|
|
151
|
+
} finally {
|
|
152
|
+
reader.releaseLock();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
140
155
|
|
|
141
156
|
// src/client/transports/json_rpc_transport.ts
|
|
142
157
|
var JsonRpcTransport = class _JsonRpcTransport {
|
|
@@ -249,8 +264,8 @@ var JsonRpcTransport = class _JsonRpcTransport {
|
|
|
249
264
|
}
|
|
250
265
|
const rpcResponse = await httpResponse.json();
|
|
251
266
|
if (rpcResponse.id !== requestId) {
|
|
252
|
-
|
|
253
|
-
`
|
|
267
|
+
throw new Error(
|
|
268
|
+
`JSON-RPC response ID mismatch for method ${method}. Expected ${requestId}, got ${rpcResponse.id}.`
|
|
254
269
|
);
|
|
255
270
|
}
|
|
256
271
|
if ("error" in rpcResponse) {
|
|
@@ -314,37 +329,31 @@ var JsonRpcTransport = class _JsonRpcTransport {
|
|
|
314
329
|
if (!jsonData.trim()) {
|
|
315
330
|
throw new Error("Attempted to process empty SSE event data.");
|
|
316
331
|
}
|
|
332
|
+
let a2aStreamResponse;
|
|
317
333
|
try {
|
|
318
|
-
|
|
319
|
-
const a2aStreamResponse = sseJsonRpcResponse;
|
|
320
|
-
if (a2aStreamResponse.id !== originalRequestId) {
|
|
321
|
-
console.warn(
|
|
322
|
-
`SSE Event's JSON-RPC response ID mismatch. Client request ID: ${originalRequestId}, event response ID: ${a2aStreamResponse.id}.`
|
|
323
|
-
);
|
|
324
|
-
}
|
|
325
|
-
if ("error" in a2aStreamResponse) {
|
|
326
|
-
const err = a2aStreamResponse.error;
|
|
327
|
-
throw new Error(
|
|
328
|
-
`SSE event contained an error: ${err.message} (Code: ${err.code}) Data: ${JSON.stringify(err.data || {})}`
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
if (!("result" in a2aStreamResponse) || typeof a2aStreamResponse.result === "undefined") {
|
|
332
|
-
throw new Error(`SSE event JSON-RPC response is missing 'result' field. Data: ${jsonData}`);
|
|
333
|
-
}
|
|
334
|
-
return a2aStreamResponse.result;
|
|
334
|
+
a2aStreamResponse = JSON.parse(jsonData);
|
|
335
335
|
} catch (e) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
console.error(
|
|
340
|
-
"Failed to parse SSE event data string or unexpected JSON-RPC structure:",
|
|
341
|
-
jsonData,
|
|
342
|
-
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 }
|
|
343
339
|
);
|
|
340
|
+
}
|
|
341
|
+
if (a2aStreamResponse.id !== originalRequestId) {
|
|
344
342
|
throw new Error(
|
|
345
|
-
`
|
|
343
|
+
`JSON-RPC response ID mismatch in SSE event. Expected ${originalRequestId}, got ${a2aStreamResponse.id}.`
|
|
346
344
|
);
|
|
347
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;
|
|
348
357
|
}
|
|
349
358
|
static mapToError(response) {
|
|
350
359
|
switch (response.error.code) {
|
|
@@ -817,574 +826,217 @@ function createAuthenticatingFetchWithRetry(fetchImpl, authHandler) {
|
|
|
817
826
|
return authFetch;
|
|
818
827
|
}
|
|
819
828
|
|
|
820
|
-
// src/
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
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 */;
|
|
845
863
|
}
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
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";
|
|
857
888
|
}
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
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 */;
|
|
871
905
|
}
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
this.transport.sendMessage.bind(this.transport)
|
|
885
|
-
);
|
|
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";
|
|
886
918
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
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
|
|
898
929
|
};
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
agentCard: this.agentCard,
|
|
905
|
-
options: beforeArgs.options
|
|
906
|
-
};
|
|
907
|
-
await this.interceptAfter(afterArgs, beforeResult.executed);
|
|
908
|
-
yield afterArgs.result.value;
|
|
909
|
-
return;
|
|
930
|
+
},
|
|
931
|
+
toJSON(message) {
|
|
932
|
+
const obj = {};
|
|
933
|
+
if (message.acceptedOutputModes?.length) {
|
|
934
|
+
obj.acceptedOutputModes = message.acceptedOutputModes;
|
|
910
935
|
}
|
|
911
|
-
if (
|
|
912
|
-
|
|
913
|
-
const afterArgs = {
|
|
914
|
-
result: { method, value: result },
|
|
915
|
-
agentCard: this.agentCard,
|
|
916
|
-
options: beforeArgs.options
|
|
917
|
-
};
|
|
918
|
-
await this.interceptAfter(afterArgs);
|
|
919
|
-
yield afterArgs.result.value;
|
|
920
|
-
return;
|
|
936
|
+
if (message.pushNotification !== void 0) {
|
|
937
|
+
obj.pushNotification = PushNotificationConfig.toJSON(message.pushNotification);
|
|
921
938
|
}
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
beforeArgs.options
|
|
925
|
-
)) {
|
|
926
|
-
const afterArgs = {
|
|
927
|
-
result: { method, value: event },
|
|
928
|
-
agentCard: this.agentCard,
|
|
929
|
-
options: beforeArgs.options
|
|
930
|
-
};
|
|
931
|
-
await this.interceptAfter(afterArgs);
|
|
932
|
-
yield afterArgs.result.value;
|
|
933
|
-
if (afterArgs.earlyReturn) {
|
|
934
|
-
return;
|
|
935
|
-
}
|
|
939
|
+
if (message.historyLength !== 0) {
|
|
940
|
+
obj.historyLength = Math.round(message.historyLength);
|
|
936
941
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
* Sets or updates the push notification configuration for a specified task.
|
|
940
|
-
* Requires the server to have AgentCard.capabilities.pushNotifications: true.
|
|
941
|
-
*/
|
|
942
|
-
setTaskPushNotificationConfig(params, options) {
|
|
943
|
-
if (!this.agentCard.capabilities.pushNotifications) {
|
|
944
|
-
throw new PushNotificationNotSupportedError();
|
|
942
|
+
if (message.blocking !== false) {
|
|
943
|
+
obj.blocking = message.blocking;
|
|
945
944
|
}
|
|
946
|
-
return
|
|
947
|
-
{ method: "setTaskPushNotificationConfig", value: params },
|
|
948
|
-
options,
|
|
949
|
-
this.transport.setTaskPushNotificationConfig.bind(this.transport)
|
|
950
|
-
);
|
|
945
|
+
return obj;
|
|
951
946
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
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
|
|
957
|
+
};
|
|
958
|
+
},
|
|
959
|
+
toJSON(message) {
|
|
960
|
+
const obj = {};
|
|
961
|
+
if (message.id !== "") {
|
|
962
|
+
obj.id = message.id;
|
|
959
963
|
}
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
options,
|
|
963
|
-
this.transport.getTaskPushNotificationConfig.bind(this.transport)
|
|
964
|
-
);
|
|
965
|
-
}
|
|
966
|
-
/**
|
|
967
|
-
* Retrieves the associated push notification configurations for a specified task.
|
|
968
|
-
* Requires the server to have AgentCard.capabilities.pushNotifications: true.
|
|
969
|
-
*/
|
|
970
|
-
listTaskPushNotificationConfig(params, options) {
|
|
971
|
-
if (!this.agentCard.capabilities.pushNotifications) {
|
|
972
|
-
throw new PushNotificationNotSupportedError();
|
|
964
|
+
if (message.contextId !== "") {
|
|
965
|
+
obj.contextId = message.contextId;
|
|
973
966
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
options,
|
|
977
|
-
this.transport.listTaskPushNotificationConfig.bind(this.transport)
|
|
978
|
-
);
|
|
979
|
-
}
|
|
980
|
-
/**
|
|
981
|
-
* Deletes an associated push notification configuration for a task.
|
|
982
|
-
*/
|
|
983
|
-
deleteTaskPushNotificationConfig(params, options) {
|
|
984
|
-
return this.executeWithInterceptors(
|
|
985
|
-
{ method: "deleteTaskPushNotificationConfig", value: params },
|
|
986
|
-
options,
|
|
987
|
-
this.transport.deleteTaskPushNotificationConfig.bind(this.transport)
|
|
988
|
-
);
|
|
989
|
-
}
|
|
990
|
-
/**
|
|
991
|
-
* Retrieves the current state (including status, artifacts, and optionally history) of a previously initiated task.
|
|
992
|
-
*/
|
|
993
|
-
getTask(params, options) {
|
|
994
|
-
return this.executeWithInterceptors(
|
|
995
|
-
{ method: "getTask", value: params },
|
|
996
|
-
options,
|
|
997
|
-
this.transport.getTask.bind(this.transport)
|
|
998
|
-
);
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Requests the cancellation of an ongoing task. The server will attempt to cancel the task,
|
|
1002
|
-
* 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).
|
|
1003
|
-
*/
|
|
1004
|
-
cancelTask(params, options) {
|
|
1005
|
-
return this.executeWithInterceptors(
|
|
1006
|
-
{ method: "cancelTask", value: params },
|
|
1007
|
-
options,
|
|
1008
|
-
this.transport.cancelTask.bind(this.transport)
|
|
1009
|
-
);
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Allows a client to reconnect to an updates stream for an ongoing task after a previous connection was interrupted.
|
|
1013
|
-
*/
|
|
1014
|
-
async *resubscribeTask(params, options) {
|
|
1015
|
-
const method = "resubscribeTask";
|
|
1016
|
-
const beforeArgs = {
|
|
1017
|
-
input: { method, value: params },
|
|
1018
|
-
agentCard: this.agentCard,
|
|
1019
|
-
options
|
|
1020
|
-
};
|
|
1021
|
-
const beforeResult = await this.interceptBefore(beforeArgs);
|
|
1022
|
-
if (beforeResult) {
|
|
1023
|
-
const earlyReturn = beforeResult.earlyReturn.value;
|
|
1024
|
-
const afterArgs = {
|
|
1025
|
-
result: { method, value: earlyReturn },
|
|
1026
|
-
agentCard: this.agentCard,
|
|
1027
|
-
options: beforeArgs.options
|
|
1028
|
-
};
|
|
1029
|
-
await this.interceptAfter(afterArgs, beforeResult.executed);
|
|
1030
|
-
yield afterArgs.result.value;
|
|
1031
|
-
return;
|
|
967
|
+
if (message.status !== void 0) {
|
|
968
|
+
obj.status = TaskStatus.toJSON(message.status);
|
|
1032
969
|
}
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
beforeArgs.options
|
|
1036
|
-
)) {
|
|
1037
|
-
const afterArgs = {
|
|
1038
|
-
result: { method, value: event },
|
|
1039
|
-
agentCard: this.agentCard,
|
|
1040
|
-
options: beforeArgs.options
|
|
1041
|
-
};
|
|
1042
|
-
await this.interceptAfter(afterArgs);
|
|
1043
|
-
yield afterArgs.result.value;
|
|
1044
|
-
if (afterArgs.earlyReturn) {
|
|
1045
|
-
return;
|
|
1046
|
-
}
|
|
970
|
+
if (message.artifacts?.length) {
|
|
971
|
+
obj.artifacts = message.artifacts.map((e) => Artifact.toJSON(e));
|
|
1047
972
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
params,
|
|
1051
|
-
blocking
|
|
1052
|
-
}) {
|
|
1053
|
-
const result = { ...params, configuration: params.configuration ?? {} };
|
|
1054
|
-
if (!result.configuration.acceptedOutputModes && this.config?.acceptedOutputModes) {
|
|
1055
|
-
result.configuration.acceptedOutputModes = this.config.acceptedOutputModes;
|
|
973
|
+
if (message.history?.length) {
|
|
974
|
+
obj.history = message.history.map((e) => Message.toJSON(e));
|
|
1056
975
|
}
|
|
1057
|
-
if (
|
|
1058
|
-
|
|
976
|
+
if (message.metadata !== void 0) {
|
|
977
|
+
obj.metadata = message.metadata;
|
|
1059
978
|
}
|
|
1060
|
-
|
|
1061
|
-
return result;
|
|
979
|
+
return obj;
|
|
1062
980
|
}
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
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
|
|
1068
988
|
};
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
value: beforeResult.earlyReturn.value
|
|
1075
|
-
},
|
|
1076
|
-
agentCard: this.agentCard,
|
|
1077
|
-
options: beforeArgs.options
|
|
1078
|
-
};
|
|
1079
|
-
await this.interceptAfter(afterArgs2, beforeResult.executed);
|
|
1080
|
-
return afterArgs2.result.value;
|
|
989
|
+
},
|
|
990
|
+
toJSON(message) {
|
|
991
|
+
const obj = {};
|
|
992
|
+
if (message.state !== 0) {
|
|
993
|
+
obj.state = taskStateToJSON(message.state);
|
|
1081
994
|
}
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
result: { method: input.method, value: result },
|
|
1085
|
-
agentCard: this.agentCard,
|
|
1086
|
-
options: beforeArgs.options
|
|
1087
|
-
};
|
|
1088
|
-
await this.interceptAfter(afterArgs);
|
|
1089
|
-
return afterArgs.result.value;
|
|
1090
|
-
}
|
|
1091
|
-
async interceptBefore(args) {
|
|
1092
|
-
if (!this.config?.interceptors || this.config.interceptors.length === 0) {
|
|
1093
|
-
return;
|
|
995
|
+
if (message.update !== void 0) {
|
|
996
|
+
obj.message = Message.toJSON(message.update);
|
|
1094
997
|
}
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
await interceptor.before(args);
|
|
1098
|
-
executed.push(interceptor);
|
|
1099
|
-
if (args.earlyReturn) {
|
|
1100
|
-
return {
|
|
1101
|
-
earlyReturn: args.earlyReturn,
|
|
1102
|
-
executed
|
|
1103
|
-
};
|
|
1104
|
-
}
|
|
998
|
+
if (message.timestamp !== void 0) {
|
|
999
|
+
obj.timestamp = message.timestamp;
|
|
1105
1000
|
}
|
|
1001
|
+
return obj;
|
|
1106
1002
|
}
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
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);
|
|
1114
1018
|
}
|
|
1019
|
+
return obj;
|
|
1115
1020
|
}
|
|
1116
1021
|
};
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
taskId;
|
|
1123
|
-
// Optional task ID context
|
|
1124
|
-
constructor(code, message, data, taskId) {
|
|
1125
|
-
super(message);
|
|
1126
|
-
this.name = "A2AError";
|
|
1127
|
-
this.code = code;
|
|
1128
|
-
this.data = data;
|
|
1129
|
-
this.taskId = taskId;
|
|
1130
|
-
}
|
|
1131
|
-
/**
|
|
1132
|
-
* Formats the error into a standard JSON-RPC error object structure.
|
|
1133
|
-
*/
|
|
1134
|
-
toJSONRPCError() {
|
|
1135
|
-
const errorObject = {
|
|
1136
|
-
code: this.code,
|
|
1137
|
-
message: this.message
|
|
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) : ""
|
|
1138
1027
|
};
|
|
1139
|
-
|
|
1140
|
-
|
|
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);
|
|
1141
1035
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
return new _A2AError(-32700, message, data);
|
|
1147
|
-
}
|
|
1148
|
-
static invalidRequest(message, data) {
|
|
1149
|
-
return new _A2AError(-32600, message, data);
|
|
1150
|
-
}
|
|
1151
|
-
static methodNotFound(method) {
|
|
1152
|
-
return new _A2AError(-32601, `Method not found: ${method}`);
|
|
1153
|
-
}
|
|
1154
|
-
static invalidParams(message, data) {
|
|
1155
|
-
return new _A2AError(-32602, message, data);
|
|
1156
|
-
}
|
|
1157
|
-
static internalError(message, data) {
|
|
1158
|
-
return new _A2AError(-32603, message, data);
|
|
1159
|
-
}
|
|
1160
|
-
static taskNotFound(taskId) {
|
|
1161
|
-
return new _A2AError(-32001, `Task not found: ${taskId}`, void 0, taskId);
|
|
1162
|
-
}
|
|
1163
|
-
static taskNotCancelable(taskId) {
|
|
1164
|
-
return new _A2AError(-32002, `Task not cancelable: ${taskId}`, void 0, taskId);
|
|
1165
|
-
}
|
|
1166
|
-
static pushNotificationNotSupported() {
|
|
1167
|
-
return new _A2AError(-32003, "Push Notification is not supported");
|
|
1168
|
-
}
|
|
1169
|
-
static unsupportedOperation(operation) {
|
|
1170
|
-
return new _A2AError(-32004, `Unsupported operation: ${operation}`);
|
|
1171
|
-
}
|
|
1172
|
-
static authenticatedExtendedCardNotConfigured() {
|
|
1173
|
-
return new _A2AError(-32007, `Extended card not configured.`);
|
|
1174
|
-
}
|
|
1175
|
-
};
|
|
1176
|
-
|
|
1177
|
-
// src/types/pb/a2a_types.ts
|
|
1178
|
-
function taskStateFromJSON(object) {
|
|
1179
|
-
switch (object) {
|
|
1180
|
-
case 0:
|
|
1181
|
-
case "TASK_STATE_UNSPECIFIED":
|
|
1182
|
-
return 0 /* TASK_STATE_UNSPECIFIED */;
|
|
1183
|
-
case 1:
|
|
1184
|
-
case "TASK_STATE_SUBMITTED":
|
|
1185
|
-
return 1 /* TASK_STATE_SUBMITTED */;
|
|
1186
|
-
case 2:
|
|
1187
|
-
case "TASK_STATE_WORKING":
|
|
1188
|
-
return 2 /* TASK_STATE_WORKING */;
|
|
1189
|
-
case 3:
|
|
1190
|
-
case "TASK_STATE_COMPLETED":
|
|
1191
|
-
return 3 /* TASK_STATE_COMPLETED */;
|
|
1192
|
-
case 4:
|
|
1193
|
-
case "TASK_STATE_FAILED":
|
|
1194
|
-
return 4 /* TASK_STATE_FAILED */;
|
|
1195
|
-
case 5:
|
|
1196
|
-
case "TASK_STATE_CANCELLED":
|
|
1197
|
-
return 5 /* TASK_STATE_CANCELLED */;
|
|
1198
|
-
case 6:
|
|
1199
|
-
case "TASK_STATE_INPUT_REQUIRED":
|
|
1200
|
-
return 6 /* TASK_STATE_INPUT_REQUIRED */;
|
|
1201
|
-
case 7:
|
|
1202
|
-
case "TASK_STATE_REJECTED":
|
|
1203
|
-
return 7 /* TASK_STATE_REJECTED */;
|
|
1204
|
-
case 8:
|
|
1205
|
-
case "TASK_STATE_AUTH_REQUIRED":
|
|
1206
|
-
return 8 /* TASK_STATE_AUTH_REQUIRED */;
|
|
1207
|
-
case -1:
|
|
1208
|
-
case "UNRECOGNIZED":
|
|
1209
|
-
default:
|
|
1210
|
-
return -1 /* UNRECOGNIZED */;
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
function taskStateToJSON(object) {
|
|
1214
|
-
switch (object) {
|
|
1215
|
-
case 0 /* TASK_STATE_UNSPECIFIED */:
|
|
1216
|
-
return "TASK_STATE_UNSPECIFIED";
|
|
1217
|
-
case 1 /* TASK_STATE_SUBMITTED */:
|
|
1218
|
-
return "TASK_STATE_SUBMITTED";
|
|
1219
|
-
case 2 /* TASK_STATE_WORKING */:
|
|
1220
|
-
return "TASK_STATE_WORKING";
|
|
1221
|
-
case 3 /* TASK_STATE_COMPLETED */:
|
|
1222
|
-
return "TASK_STATE_COMPLETED";
|
|
1223
|
-
case 4 /* TASK_STATE_FAILED */:
|
|
1224
|
-
return "TASK_STATE_FAILED";
|
|
1225
|
-
case 5 /* TASK_STATE_CANCELLED */:
|
|
1226
|
-
return "TASK_STATE_CANCELLED";
|
|
1227
|
-
case 6 /* TASK_STATE_INPUT_REQUIRED */:
|
|
1228
|
-
return "TASK_STATE_INPUT_REQUIRED";
|
|
1229
|
-
case 7 /* TASK_STATE_REJECTED */:
|
|
1230
|
-
return "TASK_STATE_REJECTED";
|
|
1231
|
-
case 8 /* TASK_STATE_AUTH_REQUIRED */:
|
|
1232
|
-
return "TASK_STATE_AUTH_REQUIRED";
|
|
1233
|
-
case -1 /* UNRECOGNIZED */:
|
|
1234
|
-
default:
|
|
1235
|
-
return "UNRECOGNIZED";
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
function roleFromJSON(object) {
|
|
1239
|
-
switch (object) {
|
|
1240
|
-
case 0:
|
|
1241
|
-
case "ROLE_UNSPECIFIED":
|
|
1242
|
-
return 0 /* ROLE_UNSPECIFIED */;
|
|
1243
|
-
case 1:
|
|
1244
|
-
case "ROLE_USER":
|
|
1245
|
-
return 1 /* ROLE_USER */;
|
|
1246
|
-
case 2:
|
|
1247
|
-
case "ROLE_AGENT":
|
|
1248
|
-
return 2 /* ROLE_AGENT */;
|
|
1249
|
-
case -1:
|
|
1250
|
-
case "UNRECOGNIZED":
|
|
1251
|
-
default:
|
|
1252
|
-
return -1 /* UNRECOGNIZED */;
|
|
1253
|
-
}
|
|
1254
|
-
}
|
|
1255
|
-
function roleToJSON(object) {
|
|
1256
|
-
switch (object) {
|
|
1257
|
-
case 0 /* ROLE_UNSPECIFIED */:
|
|
1258
|
-
return "ROLE_UNSPECIFIED";
|
|
1259
|
-
case 1 /* ROLE_USER */:
|
|
1260
|
-
return "ROLE_USER";
|
|
1261
|
-
case 2 /* ROLE_AGENT */:
|
|
1262
|
-
return "ROLE_AGENT";
|
|
1263
|
-
case -1 /* UNRECOGNIZED */:
|
|
1264
|
-
default:
|
|
1265
|
-
return "UNRECOGNIZED";
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
var SendMessageConfiguration = {
|
|
1269
|
-
fromJSON(object) {
|
|
1270
|
-
return {
|
|
1271
|
-
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(
|
|
1272
|
-
(e) => globalThis.String(e)
|
|
1273
|
-
) : [],
|
|
1274
|
-
pushNotification: isSet(object.pushNotification) ? PushNotificationConfig.fromJSON(object.pushNotification) : isSet(object.push_notification) ? PushNotificationConfig.fromJSON(object.push_notification) : void 0,
|
|
1275
|
-
historyLength: isSet(object.historyLength) ? globalThis.Number(object.historyLength) : isSet(object.history_length) ? globalThis.Number(object.history_length) : 0,
|
|
1276
|
-
blocking: isSet(object.blocking) ? globalThis.Boolean(object.blocking) : false
|
|
1277
|
-
};
|
|
1278
|
-
},
|
|
1279
|
-
toJSON(message) {
|
|
1280
|
-
const obj = {};
|
|
1281
|
-
if (message.acceptedOutputModes?.length) {
|
|
1282
|
-
obj.acceptedOutputModes = message.acceptedOutputModes;
|
|
1283
|
-
}
|
|
1284
|
-
if (message.pushNotification !== void 0) {
|
|
1285
|
-
obj.pushNotification = PushNotificationConfig.toJSON(message.pushNotification);
|
|
1286
|
-
}
|
|
1287
|
-
if (message.historyLength !== 0) {
|
|
1288
|
-
obj.historyLength = Math.round(message.historyLength);
|
|
1289
|
-
}
|
|
1290
|
-
if (message.blocking !== false) {
|
|
1291
|
-
obj.blocking = message.blocking;
|
|
1292
|
-
}
|
|
1293
|
-
return obj;
|
|
1294
|
-
}
|
|
1295
|
-
};
|
|
1296
|
-
var Task = {
|
|
1297
|
-
fromJSON(object) {
|
|
1298
|
-
return {
|
|
1299
|
-
id: isSet(object.id) ? globalThis.String(object.id) : "",
|
|
1300
|
-
contextId: isSet(object.contextId) ? globalThis.String(object.contextId) : isSet(object.context_id) ? globalThis.String(object.context_id) : "",
|
|
1301
|
-
status: isSet(object.status) ? TaskStatus.fromJSON(object.status) : void 0,
|
|
1302
|
-
artifacts: globalThis.Array.isArray(object?.artifacts) ? object.artifacts.map((e) => Artifact.fromJSON(e)) : [],
|
|
1303
|
-
history: globalThis.Array.isArray(object?.history) ? object.history.map((e) => Message.fromJSON(e)) : [],
|
|
1304
|
-
metadata: isObject(object.metadata) ? object.metadata : void 0
|
|
1305
|
-
};
|
|
1306
|
-
},
|
|
1307
|
-
toJSON(message) {
|
|
1308
|
-
const obj = {};
|
|
1309
|
-
if (message.id !== "") {
|
|
1310
|
-
obj.id = message.id;
|
|
1311
|
-
}
|
|
1312
|
-
if (message.contextId !== "") {
|
|
1313
|
-
obj.contextId = message.contextId;
|
|
1314
|
-
}
|
|
1315
|
-
if (message.status !== void 0) {
|
|
1316
|
-
obj.status = TaskStatus.toJSON(message.status);
|
|
1317
|
-
}
|
|
1318
|
-
if (message.artifacts?.length) {
|
|
1319
|
-
obj.artifacts = message.artifacts.map((e) => Artifact.toJSON(e));
|
|
1320
|
-
}
|
|
1321
|
-
if (message.history?.length) {
|
|
1322
|
-
obj.history = message.history.map((e) => Message.toJSON(e));
|
|
1323
|
-
}
|
|
1324
|
-
if (message.metadata !== void 0) {
|
|
1325
|
-
obj.metadata = message.metadata;
|
|
1326
|
-
}
|
|
1327
|
-
return obj;
|
|
1328
|
-
}
|
|
1329
|
-
};
|
|
1330
|
-
var TaskStatus = {
|
|
1331
|
-
fromJSON(object) {
|
|
1332
|
-
return {
|
|
1333
|
-
state: isSet(object.state) ? taskStateFromJSON(object.state) : 0,
|
|
1334
|
-
update: isSet(object.message) ? Message.fromJSON(object.message) : isSet(object.update) ? Message.fromJSON(object.update) : void 0,
|
|
1335
|
-
timestamp: isSet(object.timestamp) ? globalThis.String(object.timestamp) : void 0
|
|
1336
|
-
};
|
|
1337
|
-
},
|
|
1338
|
-
toJSON(message) {
|
|
1339
|
-
const obj = {};
|
|
1340
|
-
if (message.state !== 0) {
|
|
1341
|
-
obj.state = taskStateToJSON(message.state);
|
|
1342
|
-
}
|
|
1343
|
-
if (message.update !== void 0) {
|
|
1344
|
-
obj.message = Message.toJSON(message.update);
|
|
1345
|
-
}
|
|
1346
|
-
if (message.timestamp !== void 0) {
|
|
1347
|
-
obj.timestamp = message.timestamp;
|
|
1348
|
-
}
|
|
1349
|
-
return obj;
|
|
1350
|
-
}
|
|
1351
|
-
};
|
|
1352
|
-
var Part = {
|
|
1353
|
-
fromJSON(object) {
|
|
1354
|
-
return {
|
|
1355
|
-
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
|
|
1356
|
-
};
|
|
1357
|
-
},
|
|
1358
|
-
toJSON(message) {
|
|
1359
|
-
const obj = {};
|
|
1360
|
-
if (message.part?.$case === "text") {
|
|
1361
|
-
obj.text = message.part.value;
|
|
1362
|
-
} else if (message.part?.$case === "file") {
|
|
1363
|
-
obj.file = FilePart.toJSON(message.part.value);
|
|
1364
|
-
} else if (message.part?.$case === "data") {
|
|
1365
|
-
obj.data = DataPart.toJSON(message.part.value);
|
|
1366
|
-
}
|
|
1367
|
-
return obj;
|
|
1368
|
-
}
|
|
1369
|
-
};
|
|
1370
|
-
var FilePart = {
|
|
1371
|
-
fromJSON(object) {
|
|
1372
|
-
return {
|
|
1373
|
-
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,
|
|
1374
|
-
mimeType: isSet(object.mimeType) ? globalThis.String(object.mimeType) : isSet(object.mime_type) ? globalThis.String(object.mime_type) : ""
|
|
1375
|
-
};
|
|
1376
|
-
},
|
|
1377
|
-
toJSON(message) {
|
|
1378
|
-
const obj = {};
|
|
1379
|
-
if (message.file?.$case === "fileWithUri") {
|
|
1380
|
-
obj.fileWithUri = message.file.value;
|
|
1381
|
-
} else if (message.file?.$case === "fileWithBytes") {
|
|
1382
|
-
obj.fileWithBytes = base64FromBytes(message.file.value);
|
|
1383
|
-
}
|
|
1384
|
-
if (message.mimeType !== "") {
|
|
1385
|
-
obj.mimeType = message.mimeType;
|
|
1386
|
-
}
|
|
1387
|
-
return obj;
|
|
1036
|
+
if (message.mimeType !== "") {
|
|
1037
|
+
obj.mimeType = message.mimeType;
|
|
1038
|
+
}
|
|
1039
|
+
return obj;
|
|
1388
1040
|
}
|
|
1389
1041
|
};
|
|
1390
1042
|
var DataPart = {
|
|
@@ -2252,19 +1904,78 @@ function isSet(value) {
|
|
|
2252
1904
|
return value !== null && value !== void 0;
|
|
2253
1905
|
}
|
|
2254
1906
|
|
|
2255
|
-
// src/
|
|
2256
|
-
var
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
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;
|
|
2262
1919
|
}
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
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) => {
|
|
1970
|
+
const match = name.match(TASK_ONLY_REGEX);
|
|
1971
|
+
if (!match) {
|
|
1972
|
+
throw A2AError.invalidParams(`Invalid or missing task ID in: "${name}"`);
|
|
1973
|
+
}
|
|
1974
|
+
return match[1];
|
|
1975
|
+
};
|
|
1976
|
+
var generateTaskName = (taskId) => {
|
|
1977
|
+
return `tasks/${taskId}`;
|
|
1978
|
+
};
|
|
2268
1979
|
var extractTaskAndPushNotificationConfigId = (name) => {
|
|
2269
1980
|
const match = name.match(CONFIG_REGEX);
|
|
2270
1981
|
if (!match) {
|
|
@@ -2276,237 +1987,84 @@ var generatePushNotificationConfigName = (taskId, configId) => {
|
|
|
2276
1987
|
return `tasks/${taskId}/pushNotificationConfigs/${configId}`;
|
|
2277
1988
|
};
|
|
2278
1989
|
|
|
2279
|
-
// src/types/converters/
|
|
2280
|
-
var
|
|
2281
|
-
static
|
|
1990
|
+
// src/types/converters/from_proto.ts
|
|
1991
|
+
var FromProto = class _FromProto {
|
|
1992
|
+
static taskQueryParams(request) {
|
|
2282
1993
|
return {
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
description: agentCard.description,
|
|
2286
|
-
url: agentCard.url,
|
|
2287
|
-
preferredTransport: agentCard.preferredTransport ?? "",
|
|
2288
|
-
additionalInterfaces: agentCard.additionalInterfaces?.map((i) => _ToProto.agentInterface(i)) ?? [],
|
|
2289
|
-
provider: _ToProto.agentProvider(agentCard.provider),
|
|
2290
|
-
version: agentCard.version,
|
|
2291
|
-
documentationUrl: agentCard.documentationUrl ?? "",
|
|
2292
|
-
capabilities: _ToProto.agentCapabilities(agentCard.capabilities),
|
|
2293
|
-
securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
|
|
2294
|
-
Object.entries(agentCard.securitySchemes).map(([key, value]) => [
|
|
2295
|
-
key,
|
|
2296
|
-
_ToProto.securityScheme(value)
|
|
2297
|
-
])
|
|
2298
|
-
) : {},
|
|
2299
|
-
security: agentCard.security?.map((s) => _ToProto.security(s)) ?? [],
|
|
2300
|
-
defaultInputModes: agentCard.defaultInputModes,
|
|
2301
|
-
defaultOutputModes: agentCard.defaultOutputModes,
|
|
2302
|
-
skills: agentCard.skills.map((s) => _ToProto.agentSkill(s)),
|
|
2303
|
-
supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
|
|
2304
|
-
signatures: agentCard.signatures?.map((s) => _ToProto.agentCardSignature(s)) ?? []
|
|
1994
|
+
id: extractTaskId(request.name),
|
|
1995
|
+
historyLength: request.historyLength
|
|
2305
1996
|
};
|
|
2306
1997
|
}
|
|
2307
|
-
static
|
|
1998
|
+
static taskIdParams(request) {
|
|
2308
1999
|
return {
|
|
2309
|
-
|
|
2310
|
-
signature: signatures.signature,
|
|
2311
|
-
header: signatures.header
|
|
2000
|
+
id: extractTaskId(request.name)
|
|
2312
2001
|
};
|
|
2313
2002
|
}
|
|
2314
|
-
static
|
|
2003
|
+
static getTaskPushNotificationConfigParams(request) {
|
|
2004
|
+
const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
|
|
2315
2005
|
return {
|
|
2316
|
-
id:
|
|
2317
|
-
|
|
2318
|
-
description: skill.description,
|
|
2319
|
-
tags: skill.tags ?? [],
|
|
2320
|
-
examples: skill.examples ?? [],
|
|
2321
|
-
inputModes: skill.inputModes ?? [],
|
|
2322
|
-
outputModes: skill.outputModes ?? [],
|
|
2323
|
-
security: skill.security ? skill.security.map((s) => _ToProto.security(s)) : []
|
|
2006
|
+
id: taskId,
|
|
2007
|
+
pushNotificationConfigId: configId
|
|
2324
2008
|
};
|
|
2325
2009
|
}
|
|
2326
|
-
static
|
|
2010
|
+
static listTaskPushNotificationConfigParams(request) {
|
|
2327
2011
|
return {
|
|
2328
|
-
|
|
2329
|
-
Object.entries(security).map(([key, value]) => {
|
|
2330
|
-
return [key, { list: value }];
|
|
2331
|
-
})
|
|
2332
|
-
)
|
|
2012
|
+
id: extractTaskId(request.parent)
|
|
2333
2013
|
};
|
|
2334
2014
|
}
|
|
2335
|
-
static
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
$case: "apiKeySecurityScheme",
|
|
2341
|
-
value: {
|
|
2342
|
-
name: scheme.name,
|
|
2343
|
-
location: scheme.in,
|
|
2344
|
-
description: scheme.description ?? ""
|
|
2345
|
-
}
|
|
2346
|
-
}
|
|
2347
|
-
};
|
|
2348
|
-
case "http":
|
|
2349
|
-
return {
|
|
2350
|
-
scheme: {
|
|
2351
|
-
$case: "httpAuthSecurityScheme",
|
|
2352
|
-
value: {
|
|
2353
|
-
description: scheme.description ?? "",
|
|
2354
|
-
scheme: scheme.scheme,
|
|
2355
|
-
bearerFormat: scheme.bearerFormat ?? ""
|
|
2356
|
-
}
|
|
2357
|
-
}
|
|
2358
|
-
};
|
|
2359
|
-
case "mutualTLS":
|
|
2360
|
-
return {
|
|
2361
|
-
scheme: {
|
|
2362
|
-
$case: "mtlsSecurityScheme",
|
|
2363
|
-
value: {
|
|
2364
|
-
description: scheme.description ?? ""
|
|
2365
|
-
}
|
|
2366
|
-
}
|
|
2367
|
-
};
|
|
2368
|
-
case "oauth2":
|
|
2369
|
-
return {
|
|
2370
|
-
scheme: {
|
|
2371
|
-
$case: "oauth2SecurityScheme",
|
|
2372
|
-
value: {
|
|
2373
|
-
description: scheme.description ?? "",
|
|
2374
|
-
flows: _ToProto.oauthFlows(scheme.flows),
|
|
2375
|
-
oauth2MetadataUrl: scheme.oauth2MetadataUrl ?? ""
|
|
2376
|
-
}
|
|
2377
|
-
}
|
|
2378
|
-
};
|
|
2379
|
-
case "openIdConnect":
|
|
2380
|
-
return {
|
|
2381
|
-
scheme: {
|
|
2382
|
-
$case: "openIdConnectSecurityScheme",
|
|
2383
|
-
value: {
|
|
2384
|
-
description: scheme.description ?? "",
|
|
2385
|
-
openIdConnectUrl: scheme.openIdConnectUrl
|
|
2386
|
-
}
|
|
2387
|
-
}
|
|
2388
|
-
};
|
|
2389
|
-
default:
|
|
2390
|
-
throw A2AError.internalError(`Unsupported security scheme type`);
|
|
2391
|
-
}
|
|
2392
|
-
}
|
|
2393
|
-
static oauthFlows(flows) {
|
|
2394
|
-
if (flows.implicit) {
|
|
2395
|
-
return {
|
|
2396
|
-
flow: {
|
|
2397
|
-
$case: "implicit",
|
|
2398
|
-
value: {
|
|
2399
|
-
authorizationUrl: flows.implicit.authorizationUrl,
|
|
2400
|
-
scopes: flows.implicit.scopes,
|
|
2401
|
-
refreshUrl: flows.implicit.refreshUrl ?? ""
|
|
2402
|
-
}
|
|
2403
|
-
}
|
|
2404
|
-
};
|
|
2405
|
-
} else if (flows.password) {
|
|
2406
|
-
return {
|
|
2407
|
-
flow: {
|
|
2408
|
-
$case: "password",
|
|
2409
|
-
value: {
|
|
2410
|
-
tokenUrl: flows.password.tokenUrl,
|
|
2411
|
-
scopes: flows.password.scopes,
|
|
2412
|
-
refreshUrl: flows.password.refreshUrl ?? ""
|
|
2413
|
-
}
|
|
2414
|
-
}
|
|
2415
|
-
};
|
|
2416
|
-
} else if (flows.clientCredentials) {
|
|
2417
|
-
return {
|
|
2418
|
-
flow: {
|
|
2419
|
-
$case: "clientCredentials",
|
|
2420
|
-
value: {
|
|
2421
|
-
tokenUrl: flows.clientCredentials.tokenUrl,
|
|
2422
|
-
scopes: flows.clientCredentials.scopes,
|
|
2423
|
-
refreshUrl: flows.clientCredentials.refreshUrl ?? ""
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
};
|
|
2427
|
-
} else if (flows.authorizationCode) {
|
|
2428
|
-
return {
|
|
2429
|
-
flow: {
|
|
2430
|
-
$case: "authorizationCode",
|
|
2431
|
-
value: {
|
|
2432
|
-
authorizationUrl: flows.authorizationCode.authorizationUrl,
|
|
2433
|
-
tokenUrl: flows.authorizationCode.tokenUrl,
|
|
2434
|
-
scopes: flows.authorizationCode.scopes,
|
|
2435
|
-
refreshUrl: flows.authorizationCode.refreshUrl ?? ""
|
|
2436
|
-
}
|
|
2437
|
-
}
|
|
2438
|
-
};
|
|
2439
|
-
} else {
|
|
2440
|
-
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
|
+
);
|
|
2441
2020
|
}
|
|
2021
|
+
return {
|
|
2022
|
+
taskId: extractTaskId(request.parent),
|
|
2023
|
+
pushNotificationConfig: _FromProto.pushNotificationConfig(
|
|
2024
|
+
request.config.pushNotificationConfig
|
|
2025
|
+
)
|
|
2026
|
+
};
|
|
2442
2027
|
}
|
|
2443
|
-
static
|
|
2028
|
+
static deleteTaskPushNotificationConfigParams(request) {
|
|
2029
|
+
const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
|
|
2444
2030
|
return {
|
|
2445
|
-
|
|
2446
|
-
|
|
2031
|
+
id: taskId,
|
|
2032
|
+
pushNotificationConfigId: configId
|
|
2447
2033
|
};
|
|
2448
2034
|
}
|
|
2449
|
-
static
|
|
2450
|
-
if (!
|
|
2035
|
+
static message(message) {
|
|
2036
|
+
if (!message) {
|
|
2451
2037
|
return void 0;
|
|
2452
2038
|
}
|
|
2453
2039
|
return {
|
|
2454
|
-
|
|
2455
|
-
|
|
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
|
|
2456
2048
|
};
|
|
2457
2049
|
}
|
|
2458
|
-
static
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2464
|
-
|
|
2465
|
-
|
|
2466
|
-
|
|
2467
|
-
uri: extension.uri,
|
|
2468
|
-
description: extension.description ?? "",
|
|
2469
|
-
required: extension.required ?? false,
|
|
2470
|
-
params: extension.params
|
|
2471
|
-
};
|
|
2472
|
-
}
|
|
2473
|
-
static listTaskPushNotificationConfig(config) {
|
|
2474
|
-
return {
|
|
2475
|
-
configs: config.map((c) => _ToProto.taskPushNotificationConfig(c)),
|
|
2476
|
-
nextPageToken: ""
|
|
2477
|
-
};
|
|
2478
|
-
}
|
|
2479
|
-
static getTaskPushNotificationConfigParams(config) {
|
|
2480
|
-
return {
|
|
2481
|
-
name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
|
|
2482
|
-
};
|
|
2483
|
-
}
|
|
2484
|
-
static listTaskPushNotificationConfigParams(config) {
|
|
2485
|
-
return {
|
|
2486
|
-
parent: generateTaskName(config.id),
|
|
2487
|
-
pageToken: "",
|
|
2488
|
-
pageSize: 0
|
|
2489
|
-
};
|
|
2490
|
-
}
|
|
2491
|
-
static deleteTaskPushNotificationConfigParams(config) {
|
|
2492
|
-
return {
|
|
2493
|
-
name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
|
|
2494
|
-
};
|
|
2495
|
-
}
|
|
2496
|
-
static taskPushNotificationConfig(config) {
|
|
2497
|
-
return {
|
|
2498
|
-
name: generatePushNotificationConfigName(
|
|
2499
|
-
config.taskId,
|
|
2500
|
-
config.pushNotificationConfig.id ?? ""
|
|
2501
|
-
),
|
|
2502
|
-
pushNotificationConfig: _ToProto.pushNotificationConfig(config.pushNotificationConfig)
|
|
2503
|
-
};
|
|
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
|
+
}
|
|
2504
2059
|
}
|
|
2505
|
-
static
|
|
2060
|
+
static messageSendConfiguration(configuration) {
|
|
2061
|
+
if (!configuration) {
|
|
2062
|
+
return void 0;
|
|
2063
|
+
}
|
|
2506
2064
|
return {
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2065
|
+
blocking: configuration.blocking,
|
|
2066
|
+
acceptedOutputModes: configuration.acceptedOutputModes,
|
|
2067
|
+
pushNotificationConfig: _FromProto.pushNotificationConfig(configuration.pushNotification)
|
|
2510
2068
|
};
|
|
2511
2069
|
}
|
|
2512
2070
|
static pushNotificationConfig(config) {
|
|
@@ -2514,10 +2072,10 @@ var ToProto = class _ToProto {
|
|
|
2514
2072
|
return void 0;
|
|
2515
2073
|
}
|
|
2516
2074
|
return {
|
|
2517
|
-
id: config.id
|
|
2075
|
+
id: config.id,
|
|
2518
2076
|
url: config.url,
|
|
2519
|
-
token: config.token
|
|
2520
|
-
authentication:
|
|
2077
|
+
token: config.token || void 0,
|
|
2078
|
+
authentication: _FromProto.pushNotificationAuthenticationInfo(config.authentication)
|
|
2521
2079
|
};
|
|
2522
2080
|
}
|
|
2523
2081
|
static pushNotificationAuthenticationInfo(authInfo) {
|
|
@@ -2526,302 +2084,888 @@ var ToProto = class _ToProto {
|
|
|
2526
2084
|
}
|
|
2527
2085
|
return {
|
|
2528
2086
|
schemes: authInfo.schemes,
|
|
2529
|
-
credentials: authInfo.credentials
|
|
2087
|
+
credentials: authInfo.credentials
|
|
2530
2088
|
};
|
|
2531
2089
|
}
|
|
2532
|
-
static
|
|
2533
|
-
if (
|
|
2534
|
-
return {
|
|
2535
|
-
payload: {
|
|
2536
|
-
$case: "msg",
|
|
2537
|
-
value: _ToProto.message(event)
|
|
2538
|
-
}
|
|
2539
|
-
};
|
|
2540
|
-
} else if (event.kind === "task") {
|
|
2541
|
-
return {
|
|
2542
|
-
payload: {
|
|
2543
|
-
$case: "task",
|
|
2544
|
-
value: _ToProto.task(event)
|
|
2545
|
-
}
|
|
2546
|
-
};
|
|
2547
|
-
} else if (event.kind === "status-update") {
|
|
2090
|
+
static part(part) {
|
|
2091
|
+
if (part.part?.$case === "text") {
|
|
2548
2092
|
return {
|
|
2549
|
-
|
|
2550
|
-
|
|
2551
|
-
value: _ToProto.taskStatusUpdateEvent(event)
|
|
2552
|
-
}
|
|
2093
|
+
kind: "text",
|
|
2094
|
+
text: part.part.value
|
|
2553
2095
|
};
|
|
2554
|
-
}
|
|
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") {
|
|
2555
2119
|
return {
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
value: _ToProto.taskArtifactUpdateEvent(event)
|
|
2559
|
-
}
|
|
2120
|
+
kind: "data",
|
|
2121
|
+
data: part.part.value.data
|
|
2560
2122
|
};
|
|
2561
|
-
} else {
|
|
2562
|
-
throw A2AError.internalError("Invalid event type");
|
|
2563
2123
|
}
|
|
2124
|
+
throw A2AError.invalidParams("Invalid part type");
|
|
2564
2125
|
}
|
|
2565
|
-
static
|
|
2126
|
+
static messageSendParams(request) {
|
|
2566
2127
|
return {
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
metadata: event.metadata,
|
|
2571
|
-
final: event.final
|
|
2128
|
+
message: _FromProto.message(request.request),
|
|
2129
|
+
configuration: _FromProto.messageSendConfiguration(request.configuration),
|
|
2130
|
+
metadata: request.metadata
|
|
2572
2131
|
};
|
|
2573
2132
|
}
|
|
2574
|
-
static
|
|
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) {
|
|
2575
2142
|
return {
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
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
|
|
2582
2150
|
};
|
|
2583
2151
|
}
|
|
2584
|
-
static
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
}
|
|
2591
|
-
};
|
|
2592
|
-
} else if (params.kind === "task") {
|
|
2593
|
-
return {
|
|
2594
|
-
payload: {
|
|
2595
|
-
$case: "task",
|
|
2596
|
-
value: _ToProto.task(params)
|
|
2597
|
-
}
|
|
2598
|
-
};
|
|
2599
|
-
}
|
|
2152
|
+
static taskStatus(status) {
|
|
2153
|
+
return {
|
|
2154
|
+
message: _FromProto.message(status.update),
|
|
2155
|
+
state: _FromProto.taskState(status.state),
|
|
2156
|
+
timestamp: status.timestamp
|
|
2157
|
+
};
|
|
2600
2158
|
}
|
|
2601
|
-
static
|
|
2602
|
-
|
|
2603
|
-
|
|
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}`);
|
|
2604
2181
|
}
|
|
2182
|
+
}
|
|
2183
|
+
static artifact(artifact) {
|
|
2605
2184
|
return {
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
metadata: message.metadata,
|
|
2612
|
-
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
|
|
2613
2190
|
};
|
|
2614
2191
|
}
|
|
2615
|
-
static
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
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
|
+
}
|
|
2623
2734
|
}
|
|
2624
2735
|
}
|
|
2625
|
-
|
|
2736
|
+
};
|
|
2737
|
+
|
|
2738
|
+
// src/types/converters/to_proto.ts
|
|
2739
|
+
var ToProto = class _ToProto {
|
|
2740
|
+
static agentCard(agentCard) {
|
|
2626
2741
|
return {
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
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)) ?? []
|
|
2633
2764
|
};
|
|
2634
2765
|
}
|
|
2635
|
-
static
|
|
2766
|
+
static agentCardSignature(signatures) {
|
|
2636
2767
|
return {
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2768
|
+
protected: signatures.protected,
|
|
2769
|
+
signature: signatures.signature,
|
|
2770
|
+
header: signatures.header
|
|
2640
2771
|
};
|
|
2641
2772
|
}
|
|
2642
|
-
static
|
|
2773
|
+
static agentSkill(skill) {
|
|
2643
2774
|
return {
|
|
2644
|
-
|
|
2645
|
-
name:
|
|
2646
|
-
description:
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
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)) : []
|
|
2650
2783
|
};
|
|
2651
2784
|
}
|
|
2652
|
-
static
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
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
|
+
};
|
|
2672
2848
|
default:
|
|
2673
|
-
|
|
2849
|
+
throw A2AError.internalError(`Unsupported security scheme type`);
|
|
2674
2850
|
}
|
|
2675
2851
|
}
|
|
2676
|
-
static
|
|
2677
|
-
if (
|
|
2852
|
+
static oauthFlows(flows) {
|
|
2853
|
+
if (flows.implicit) {
|
|
2678
2854
|
return {
|
|
2679
|
-
|
|
2855
|
+
flow: {
|
|
2856
|
+
$case: "implicit",
|
|
2857
|
+
value: {
|
|
2858
|
+
authorizationUrl: flows.implicit.authorizationUrl,
|
|
2859
|
+
scopes: flows.implicit.scopes,
|
|
2860
|
+
refreshUrl: flows.implicit.refreshUrl ?? ""
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2680
2863
|
};
|
|
2681
|
-
}
|
|
2682
|
-
if (part.kind === "file") {
|
|
2683
|
-
let filePart;
|
|
2684
|
-
if ("uri" in part.file) {
|
|
2685
|
-
filePart = {
|
|
2686
|
-
file: { $case: "fileWithUri", value: part.file.uri },
|
|
2687
|
-
mimeType: part.file.mimeType
|
|
2688
|
-
};
|
|
2689
|
-
} else if ("bytes" in part.file) {
|
|
2690
|
-
filePart = {
|
|
2691
|
-
file: { $case: "fileWithBytes", value: Buffer.from(part.file.bytes, "base64") },
|
|
2692
|
-
mimeType: part.file.mimeType
|
|
2693
|
-
};
|
|
2694
|
-
} else {
|
|
2695
|
-
throw A2AError.internalError("Invalid file part");
|
|
2696
|
-
}
|
|
2864
|
+
} else if (flows.password) {
|
|
2697
2865
|
return {
|
|
2698
|
-
|
|
2866
|
+
flow: {
|
|
2867
|
+
$case: "password",
|
|
2868
|
+
value: {
|
|
2869
|
+
tokenUrl: flows.password.tokenUrl,
|
|
2870
|
+
scopes: flows.password.scopes,
|
|
2871
|
+
refreshUrl: flows.password.refreshUrl ?? ""
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2699
2874
|
};
|
|
2700
|
-
}
|
|
2701
|
-
if (part.kind === "data") {
|
|
2875
|
+
} else if (flows.clientCredentials) {
|
|
2702
2876
|
return {
|
|
2703
|
-
|
|
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
|
+
}
|
|
2704
2897
|
};
|
|
2898
|
+
} else {
|
|
2899
|
+
throw A2AError.internalError(`Unsupported OAuth flows`);
|
|
2705
2900
|
}
|
|
2706
|
-
throw A2AError.internalError("Invalid part type");
|
|
2707
2901
|
}
|
|
2708
|
-
static
|
|
2902
|
+
static agentInterface(agentInterface) {
|
|
2709
2903
|
return {
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
metadata: params.metadata
|
|
2904
|
+
transport: agentInterface.transport,
|
|
2905
|
+
url: agentInterface.url
|
|
2713
2906
|
};
|
|
2714
2907
|
}
|
|
2715
|
-
static
|
|
2716
|
-
if (!
|
|
2908
|
+
static agentProvider(agentProvider) {
|
|
2909
|
+
if (!agentProvider) {
|
|
2717
2910
|
return void 0;
|
|
2718
2911
|
}
|
|
2719
2912
|
return {
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
pushNotification: _ToProto.pushNotificationConfig(configuration.pushNotificationConfig),
|
|
2723
|
-
historyLength: configuration.historyLength ?? 0
|
|
2724
|
-
};
|
|
2725
|
-
}
|
|
2726
|
-
static taskQueryParams(params) {
|
|
2727
|
-
return {
|
|
2728
|
-
name: generateTaskName(params.id),
|
|
2729
|
-
historyLength: params.historyLength ?? 0
|
|
2730
|
-
};
|
|
2731
|
-
}
|
|
2732
|
-
static cancelTaskRequest(params) {
|
|
2733
|
-
return {
|
|
2734
|
-
name: generateTaskName(params.id)
|
|
2735
|
-
};
|
|
2736
|
-
}
|
|
2737
|
-
static taskIdParams(params) {
|
|
2738
|
-
return {
|
|
2739
|
-
name: generateTaskName(params.id)
|
|
2913
|
+
url: agentProvider.url,
|
|
2914
|
+
organization: agentProvider.organization
|
|
2740
2915
|
};
|
|
2741
2916
|
}
|
|
2742
|
-
static
|
|
2743
|
-
return {};
|
|
2744
|
-
}
|
|
2745
|
-
};
|
|
2746
|
-
|
|
2747
|
-
// src/types/converters/from_proto.ts
|
|
2748
|
-
var FromProto = class _FromProto {
|
|
2749
|
-
static taskQueryParams(request) {
|
|
2917
|
+
static agentCapabilities(capabilities) {
|
|
2750
2918
|
return {
|
|
2751
|
-
|
|
2752
|
-
|
|
2919
|
+
streaming: capabilities.streaming,
|
|
2920
|
+
pushNotifications: capabilities.pushNotifications,
|
|
2921
|
+
extensions: capabilities.extensions ? capabilities.extensions.map((e) => _ToProto.agentExtension(e)) : []
|
|
2753
2922
|
};
|
|
2754
2923
|
}
|
|
2755
|
-
static
|
|
2924
|
+
static agentExtension(extension) {
|
|
2756
2925
|
return {
|
|
2757
|
-
|
|
2926
|
+
uri: extension.uri,
|
|
2927
|
+
description: extension.description ?? "",
|
|
2928
|
+
required: extension.required ?? false,
|
|
2929
|
+
params: extension.params
|
|
2758
2930
|
};
|
|
2759
2931
|
}
|
|
2760
|
-
static
|
|
2761
|
-
const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
|
|
2932
|
+
static listTaskPushNotificationConfig(config) {
|
|
2762
2933
|
return {
|
|
2763
|
-
|
|
2764
|
-
|
|
2934
|
+
configs: config.map((c) => _ToProto.taskPushNotificationConfig(c)),
|
|
2935
|
+
nextPageToken: ""
|
|
2765
2936
|
};
|
|
2766
2937
|
}
|
|
2767
|
-
static
|
|
2938
|
+
static getTaskPushNotificationConfigParams(config) {
|
|
2768
2939
|
return {
|
|
2769
|
-
|
|
2940
|
+
name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
|
|
2770
2941
|
};
|
|
2771
2942
|
}
|
|
2772
|
-
static
|
|
2773
|
-
if (!request.config?.pushNotificationConfig) {
|
|
2774
|
-
throw A2AError.invalidParams(
|
|
2775
|
-
"Request must include a `config` object with a `pushNotificationConfig`"
|
|
2776
|
-
);
|
|
2777
|
-
}
|
|
2943
|
+
static listTaskPushNotificationConfigParams(config) {
|
|
2778
2944
|
return {
|
|
2779
|
-
|
|
2780
|
-
|
|
2781
|
-
|
|
2782
|
-
)
|
|
2945
|
+
parent: generateTaskName(config.id),
|
|
2946
|
+
pageToken: "",
|
|
2947
|
+
pageSize: 0
|
|
2783
2948
|
};
|
|
2784
2949
|
}
|
|
2785
|
-
static deleteTaskPushNotificationConfigParams(
|
|
2786
|
-
const { taskId, configId } = extractTaskAndPushNotificationConfigId(request.name);
|
|
2950
|
+
static deleteTaskPushNotificationConfigParams(config) {
|
|
2787
2951
|
return {
|
|
2788
|
-
|
|
2789
|
-
pushNotificationConfigId: configId
|
|
2952
|
+
name: generatePushNotificationConfigName(config.id, config.pushNotificationConfigId)
|
|
2790
2953
|
};
|
|
2791
2954
|
}
|
|
2792
|
-
static
|
|
2793
|
-
if (!message) {
|
|
2794
|
-
return void 0;
|
|
2795
|
-
}
|
|
2955
|
+
static taskPushNotificationConfig(config) {
|
|
2796
2956
|
return {
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
role: _FromProto.role(message.role),
|
|
2803
|
-
metadata: message.metadata,
|
|
2804
|
-
extensions: message.extensions
|
|
2957
|
+
name: generatePushNotificationConfigName(
|
|
2958
|
+
config.taskId,
|
|
2959
|
+
config.pushNotificationConfig.id ?? ""
|
|
2960
|
+
),
|
|
2961
|
+
pushNotificationConfig: _ToProto.pushNotificationConfig(config.pushNotificationConfig)
|
|
2805
2962
|
};
|
|
2806
2963
|
}
|
|
2807
|
-
static
|
|
2808
|
-
switch (role) {
|
|
2809
|
-
case 2 /* ROLE_AGENT */:
|
|
2810
|
-
return "agent";
|
|
2811
|
-
case 1 /* ROLE_USER */:
|
|
2812
|
-
return "user";
|
|
2813
|
-
default:
|
|
2814
|
-
throw A2AError.invalidParams(`Invalid role: ${role}`);
|
|
2815
|
-
}
|
|
2816
|
-
}
|
|
2817
|
-
static messageSendConfiguration(configuration) {
|
|
2818
|
-
if (!configuration) {
|
|
2819
|
-
return void 0;
|
|
2820
|
-
}
|
|
2964
|
+
static taskPushNotificationConfigCreate(config) {
|
|
2821
2965
|
return {
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2966
|
+
parent: generateTaskName(config.taskId),
|
|
2967
|
+
config: _ToProto.taskPushNotificationConfig(config),
|
|
2968
|
+
configId: config.pushNotificationConfig.id
|
|
2825
2969
|
};
|
|
2826
2970
|
}
|
|
2827
2971
|
static pushNotificationConfig(config) {
|
|
@@ -2829,10 +2973,10 @@ var FromProto = class _FromProto {
|
|
|
2829
2973
|
return void 0;
|
|
2830
2974
|
}
|
|
2831
2975
|
return {
|
|
2832
|
-
id: config.id,
|
|
2976
|
+
id: config.id ?? "",
|
|
2833
2977
|
url: config.url,
|
|
2834
|
-
token: config.token
|
|
2835
|
-
authentication:
|
|
2978
|
+
token: config.token ?? "",
|
|
2979
|
+
authentication: _ToProto.pushNotificationAuthenticationInfo(config.authentication)
|
|
2836
2980
|
};
|
|
2837
2981
|
}
|
|
2838
2982
|
static pushNotificationAuthenticationInfo(authInfo) {
|
|
@@ -2841,307 +2985,221 @@ var FromProto = class _FromProto {
|
|
|
2841
2985
|
}
|
|
2842
2986
|
return {
|
|
2843
2987
|
schemes: authInfo.schemes,
|
|
2844
|
-
credentials: authInfo.credentials
|
|
2988
|
+
credentials: authInfo.credentials ?? ""
|
|
2845
2989
|
};
|
|
2846
2990
|
}
|
|
2847
|
-
static
|
|
2848
|
-
if (
|
|
2991
|
+
static messageStreamResult(event) {
|
|
2992
|
+
if (event.kind === "message") {
|
|
2849
2993
|
return {
|
|
2850
|
-
|
|
2851
|
-
|
|
2994
|
+
payload: {
|
|
2995
|
+
$case: "msg",
|
|
2996
|
+
value: _ToProto.message(event)
|
|
2997
|
+
}
|
|
2852
2998
|
};
|
|
2853
|
-
}
|
|
2854
|
-
if (part.part?.$case === "file") {
|
|
2855
|
-
const filePart = part.part.value;
|
|
2856
|
-
if (filePart.file?.$case === "fileWithUri") {
|
|
2857
|
-
return {
|
|
2858
|
-
kind: "file",
|
|
2859
|
-
file: {
|
|
2860
|
-
uri: filePart.file.value,
|
|
2861
|
-
mimeType: filePart.mimeType
|
|
2862
|
-
}
|
|
2863
|
-
};
|
|
2864
|
-
} else if (filePart.file?.$case === "fileWithBytes") {
|
|
2865
|
-
return {
|
|
2866
|
-
kind: "file",
|
|
2867
|
-
file: {
|
|
2868
|
-
bytes: filePart.file.value.toString("base64"),
|
|
2869
|
-
mimeType: filePart.mimeType
|
|
2870
|
-
}
|
|
2871
|
-
};
|
|
2872
|
-
}
|
|
2873
|
-
throw A2AError.invalidParams("Invalid file part type");
|
|
2874
|
-
}
|
|
2875
|
-
if (part.part?.$case === "data") {
|
|
2999
|
+
} else if (event.kind === "task") {
|
|
2876
3000
|
return {
|
|
2877
|
-
|
|
2878
|
-
|
|
3001
|
+
payload: {
|
|
3002
|
+
$case: "task",
|
|
3003
|
+
value: _ToProto.task(event)
|
|
3004
|
+
}
|
|
2879
3005
|
};
|
|
2880
|
-
}
|
|
2881
|
-
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
throw A2AError.invalidParams("Invalid SendMessageResponse: missing result");
|
|
2897
|
-
}
|
|
2898
|
-
static task(task) {
|
|
2899
|
-
return {
|
|
2900
|
-
kind: "task",
|
|
2901
|
-
id: task.id,
|
|
2902
|
-
status: _FromProto.taskStatus(task.status),
|
|
2903
|
-
contextId: task.contextId,
|
|
2904
|
-
artifacts: task.artifacts?.map((a) => _FromProto.artifact(a)),
|
|
2905
|
-
history: task.history?.map((h) => _FromProto.message(h)),
|
|
2906
|
-
metadata: task.metadata
|
|
2907
|
-
};
|
|
2908
|
-
}
|
|
2909
|
-
static taskStatus(status) {
|
|
2910
|
-
return {
|
|
2911
|
-
message: _FromProto.message(status.update),
|
|
2912
|
-
state: _FromProto.taskState(status.state),
|
|
2913
|
-
timestamp: status.timestamp
|
|
2914
|
-
};
|
|
2915
|
-
}
|
|
2916
|
-
static taskState(state) {
|
|
2917
|
-
switch (state) {
|
|
2918
|
-
case 1 /* TASK_STATE_SUBMITTED */:
|
|
2919
|
-
return "submitted";
|
|
2920
|
-
case 2 /* TASK_STATE_WORKING */:
|
|
2921
|
-
return "working";
|
|
2922
|
-
case 6 /* TASK_STATE_INPUT_REQUIRED */:
|
|
2923
|
-
return "input-required";
|
|
2924
|
-
case 3 /* TASK_STATE_COMPLETED */:
|
|
2925
|
-
return "completed";
|
|
2926
|
-
case 5 /* TASK_STATE_CANCELLED */:
|
|
2927
|
-
return "canceled";
|
|
2928
|
-
case 4 /* TASK_STATE_FAILED */:
|
|
2929
|
-
return "failed";
|
|
2930
|
-
case 7 /* TASK_STATE_REJECTED */:
|
|
2931
|
-
return "rejected";
|
|
2932
|
-
case 8 /* TASK_STATE_AUTH_REQUIRED */:
|
|
2933
|
-
return "auth-required";
|
|
2934
|
-
case 0 /* TASK_STATE_UNSPECIFIED */:
|
|
2935
|
-
return "unknown";
|
|
2936
|
-
default:
|
|
2937
|
-
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");
|
|
2938
3022
|
}
|
|
2939
3023
|
}
|
|
2940
|
-
static
|
|
3024
|
+
static taskStatusUpdateEvent(event) {
|
|
2941
3025
|
return {
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
3026
|
+
taskId: event.taskId,
|
|
3027
|
+
status: _ToProto.taskStatus(event.status),
|
|
3028
|
+
contextId: event.contextId,
|
|
3029
|
+
metadata: event.metadata,
|
|
3030
|
+
final: event.final
|
|
2947
3031
|
};
|
|
2948
3032
|
}
|
|
2949
|
-
static
|
|
3033
|
+
static taskArtifactUpdateEvent(event) {
|
|
2950
3034
|
return {
|
|
2951
|
-
taskId:
|
|
2952
|
-
|
|
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
|
|
2953
3041
|
};
|
|
2954
3042
|
}
|
|
2955
|
-
static
|
|
2956
|
-
|
|
2957
|
-
|
|
2958
|
-
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
|
|
2965
|
-
|
|
2966
|
-
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
2970
|
-
|
|
2971
|
-
securitySchemes: agentCard.securitySchemes ? Object.fromEntries(
|
|
2972
|
-
Object.entries(agentCard.securitySchemes).map(([key, value]) => [
|
|
2973
|
-
key,
|
|
2974
|
-
_FromProto.securityScheme(value)
|
|
2975
|
-
])
|
|
2976
|
-
) : {},
|
|
2977
|
-
skills: agentCard.skills.map((s) => _FromProto.skills(s)),
|
|
2978
|
-
signatures: agentCard.signatures?.map((s) => _FromProto.agentCardSignature(s)),
|
|
2979
|
-
supportsAuthenticatedExtendedCard: agentCard.supportsAuthenticatedExtendedCard,
|
|
2980
|
-
url: agentCard.url,
|
|
2981
|
-
version: agentCard.version
|
|
2982
|
-
};
|
|
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
|
+
}
|
|
2983
3059
|
}
|
|
2984
|
-
static
|
|
3060
|
+
static message(message) {
|
|
3061
|
+
if (!message) {
|
|
3062
|
+
return void 0;
|
|
3063
|
+
}
|
|
2985
3064
|
return {
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
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 ?? []
|
|
2989
3072
|
};
|
|
2990
3073
|
}
|
|
2991
|
-
static
|
|
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) {
|
|
2992
3085
|
return {
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
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
|
|
2997
3092
|
};
|
|
2998
3093
|
}
|
|
2999
|
-
static
|
|
3094
|
+
static taskStatus(status) {
|
|
3000
3095
|
return {
|
|
3001
|
-
|
|
3002
|
-
|
|
3096
|
+
state: _ToProto.taskState(status.state),
|
|
3097
|
+
update: _ToProto.message(status.message),
|
|
3098
|
+
timestamp: status.timestamp
|
|
3003
3099
|
};
|
|
3004
3100
|
}
|
|
3005
|
-
static
|
|
3101
|
+
static artifact(artifact) {
|
|
3006
3102
|
return {
|
|
3007
|
-
|
|
3008
|
-
|
|
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 : []
|
|
3009
3109
|
};
|
|
3010
3110
|
}
|
|
3011
|
-
static
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
case "
|
|
3026
|
-
return
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
};
|
|
3032
|
-
case "mtlsSecurityScheme":
|
|
3033
|
-
return {
|
|
3034
|
-
type: "mutualTLS",
|
|
3035
|
-
description: securitySchemes.scheme.value.description || void 0
|
|
3036
|
-
};
|
|
3037
|
-
case "oauth2SecurityScheme":
|
|
3038
|
-
return {
|
|
3039
|
-
type: "oauth2",
|
|
3040
|
-
description: securitySchemes.scheme.value.description || void 0,
|
|
3041
|
-
flows: _FromProto.oauthFlows(securitySchemes.scheme.value.flows),
|
|
3042
|
-
oauth2MetadataUrl: securitySchemes.scheme.value.oauth2MetadataUrl || void 0
|
|
3043
|
-
};
|
|
3044
|
-
case "openIdConnectSecurityScheme":
|
|
3045
|
-
return {
|
|
3046
|
-
type: "openIdConnect",
|
|
3047
|
-
description: securitySchemes.scheme.value.description || void 0,
|
|
3048
|
-
openIdConnectUrl: securitySchemes.scheme.value.openIdConnectUrl
|
|
3049
|
-
};
|
|
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 */;
|
|
3050
3131
|
default:
|
|
3051
|
-
|
|
3132
|
+
return -1 /* UNRECOGNIZED */;
|
|
3052
3133
|
}
|
|
3053
3134
|
}
|
|
3054
|
-
static
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
password: {
|
|
3067
|
-
refreshUrl: flows.flow.value.refreshUrl || void 0,
|
|
3068
|
-
scopes: flows.flow.value.scopes,
|
|
3069
|
-
tokenUrl: flows.flow.value.tokenUrl
|
|
3070
|
-
}
|
|
3071
|
-
};
|
|
3072
|
-
case "authorizationCode":
|
|
3073
|
-
return {
|
|
3074
|
-
authorizationCode: {
|
|
3075
|
-
refreshUrl: flows.flow.value.refreshUrl || void 0,
|
|
3076
|
-
authorizationUrl: flows.flow.value.authorizationUrl,
|
|
3077
|
-
scopes: flows.flow.value.scopes,
|
|
3078
|
-
tokenUrl: flows.flow.value.tokenUrl
|
|
3079
|
-
}
|
|
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
|
|
3080
3147
|
};
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
scopes: flows.flow.value.scopes,
|
|
3086
|
-
tokenUrl: flows.flow.value.tokenUrl
|
|
3087
|
-
}
|
|
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
|
|
3088
3152
|
};
|
|
3089
|
-
|
|
3090
|
-
throw A2AError.internalError(
|
|
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
|
+
};
|
|
3091
3164
|
}
|
|
3165
|
+
throw A2AError.internalError("Invalid part type");
|
|
3092
3166
|
}
|
|
3093
|
-
static
|
|
3167
|
+
static messageSendParams(params) {
|
|
3094
3168
|
return {
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
tags: skill.tags,
|
|
3099
|
-
examples: skill.examples,
|
|
3100
|
-
inputModes: skill.inputModes,
|
|
3101
|
-
outputModes: skill.outputModes,
|
|
3102
|
-
security: skill.security?.map((s) => _FromProto.security(s))
|
|
3169
|
+
request: _ToProto.message(params.message),
|
|
3170
|
+
configuration: _ToProto.configuration(params.configuration),
|
|
3171
|
+
metadata: params.metadata
|
|
3103
3172
|
};
|
|
3104
3173
|
}
|
|
3105
|
-
static
|
|
3174
|
+
static configuration(configuration) {
|
|
3175
|
+
if (!configuration) {
|
|
3176
|
+
return void 0;
|
|
3177
|
+
}
|
|
3106
3178
|
return {
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3179
|
+
blocking: configuration.blocking,
|
|
3180
|
+
acceptedOutputModes: configuration.acceptedOutputModes ?? [],
|
|
3181
|
+
pushNotification: _ToProto.pushNotificationConfig(configuration.pushNotificationConfig),
|
|
3182
|
+
historyLength: configuration.historyLength ?? 0
|
|
3110
3183
|
};
|
|
3111
3184
|
}
|
|
3112
|
-
static
|
|
3185
|
+
static taskQueryParams(params) {
|
|
3113
3186
|
return {
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
status: _FromProto.taskStatus(event.status),
|
|
3117
|
-
contextId: event.contextId,
|
|
3118
|
-
metadata: event.metadata,
|
|
3119
|
-
final: event.final
|
|
3187
|
+
name: generateTaskName(params.id),
|
|
3188
|
+
historyLength: params.historyLength ?? 0
|
|
3120
3189
|
};
|
|
3121
3190
|
}
|
|
3122
|
-
static
|
|
3191
|
+
static cancelTaskRequest(params) {
|
|
3123
3192
|
return {
|
|
3124
|
-
|
|
3125
|
-
taskId: event.taskId,
|
|
3126
|
-
artifact: _FromProto.artifact(event.artifact),
|
|
3127
|
-
contextId: event.contextId,
|
|
3128
|
-
metadata: event.metadata,
|
|
3129
|
-
lastChunk: event.lastChunk
|
|
3193
|
+
name: generateTaskName(params.id)
|
|
3130
3194
|
};
|
|
3131
3195
|
}
|
|
3132
|
-
static
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
return _FromProto.taskStatusUpdateEvent(event.payload.value);
|
|
3140
|
-
case "artifactUpdate":
|
|
3141
|
-
return _FromProto.taskArtifactUpdateEvent(event.payload.value);
|
|
3142
|
-
default:
|
|
3143
|
-
throw A2AError.internalError("Invalid event type in StreamResponse");
|
|
3144
|
-
}
|
|
3196
|
+
static taskIdParams(params) {
|
|
3197
|
+
return {
|
|
3198
|
+
name: generateTaskName(params.id)
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3201
|
+
static getAgentCardRequest() {
|
|
3202
|
+
return {};
|
|
3145
3203
|
}
|
|
3146
3204
|
};
|
|
3147
3205
|
|
|
@@ -3485,18 +3543,15 @@ var ClientFactory = class {
|
|
|
3485
3543
|
...additionalInterfaces.map((i) => i.transport)
|
|
3486
3544
|
];
|
|
3487
3545
|
for (const transport of transportsByPreference) {
|
|
3488
|
-
|
|
3489
|
-
continue;
|
|
3490
|
-
}
|
|
3546
|
+
const url = urlsPerAgentTransports.get(transport);
|
|
3491
3547
|
const factory = this.transportsByName.get(transport);
|
|
3492
|
-
if (
|
|
3493
|
-
|
|
3548
|
+
if (factory && url) {
|
|
3549
|
+
return new Client(
|
|
3550
|
+
await factory.create(url, agentCard),
|
|
3551
|
+
agentCard,
|
|
3552
|
+
this.options.clientConfig
|
|
3553
|
+
);
|
|
3494
3554
|
}
|
|
3495
|
-
return new Client(
|
|
3496
|
-
await factory.create(urlsPerAgentTransports.get(transport), agentCard),
|
|
3497
|
-
agentCard,
|
|
3498
|
-
this.options.clientConfig
|
|
3499
|
-
);
|
|
3500
3555
|
}
|
|
3501
3556
|
throw new Error(
|
|
3502
3557
|
"No compatible transport found, available transports: " + [...this.transportsByName.keys()].join()
|