@axiom-lattice/gateway 7.0.0 → 8.0.1
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/{WechatChannelAdapter-7WHE5UGY.mjs → WechatChannelAdapter-QLPJJD6S.mjs} +55 -4
- package/dist/WechatChannelAdapter-QLPJJD6S.mjs.map +1 -0
- package/dist/{a2a-standard-DP53K7RC.mjs → a2a-standard-VL5I7B4W.mjs} +831 -59
- package/dist/a2a-standard-VL5I7B4W.mjs.map +1 -0
- package/dist/{chunk-FGSFOXIX.mjs → chunk-L6MBEEII.mjs} +2 -2
- package/dist/{chunk-J6B2VFJ7.mjs → chunk-W3YH4S6G.mjs} +2 -1
- package/dist/{chunk-MWWLJMYN.mjs → chunk-XUWD4VKY.mjs} +4 -2
- package/dist/chunk-XUWD4VKY.mjs.map +1 -0
- package/dist/embed/embed-page-AgentDetailSideApp-23TCREK6.js +1 -0
- package/dist/embed/embed-page-AgentGovernanceWorkbench-N3F65F3W.js +1 -0
- package/dist/embed/embed-page-LangfuseDashboard-WBE7GJPU.js +1 -0
- package/dist/embed/embed-page-MessageGraph-T3EFAXTX.js +6 -0
- package/dist/embed/embed-page-ReactChart-FJFQU4IV.js +1 -0
- package/dist/embed/embed-page-SkillFlow-2BUXCLAL.js +1 -0
- package/dist/embed/{embed-page-TasksSideApp-D7FFG2OC.js → embed-page-TasksSideApp-VFKEYFGR.js} +1 -1
- package/dist/embed/embed-page-ThreadMaintenancePanel-EPBJ4J3L.js +1 -0
- package/dist/embed/{embed-page-TopologyRuntimeView-IS6HEO4F.js → embed-page-TopologyRuntimeView-OWESU7IK.js} +1 -1
- package/dist/embed/{embed-page-WorkflowAutomationView-IDVSQTJB.js → embed-page-WorkflowAutomationView-5J2RQTZ7.js} +1 -1
- package/dist/embed/{embed-page-chunk-XFV3N2LD.js → embed-page-chunk-2ZBEWYJQ.js} +1 -1
- package/dist/embed/{embed-page-chunk-SRMYHWL3.js → embed-page-chunk-34RWKVD7.js} +1 -1
- package/dist/embed/{embed-page-chunk-JFMBLJXY.js → embed-page-chunk-6QLLZJVH.js} +1 -1
- package/dist/embed/embed-page-chunk-B2KNZ3EW.js +59 -0
- package/dist/embed/{embed-page-chunk-BOEX26H7.js → embed-page-chunk-BFVNPGSW.js} +8 -8
- package/dist/embed/embed-page-chunk-CKUSXUKW.js +6746 -0
- package/dist/embed/embed-page-chunk-CQLDPGEG.js +1 -0
- package/dist/embed/embed-page-chunk-D7YTSCUO.js +1 -0
- package/dist/embed/{embed-page-chunk-S2KVN3RB.js → embed-page-chunk-DJKD2PHO.js} +1 -1
- package/dist/embed/{embed-page-chunk-EYYKNTX7.js → embed-page-chunk-EU32IF7M.js} +1 -1
- package/dist/embed/embed-page-chunk-F7TA3LRH.js +459 -0
- package/dist/embed/embed-page-chunk-F7ZUYG42.js +121 -0
- package/dist/embed/{embed-page-chunk-NFMLKSPM.js → embed-page-chunk-GSUSX54K.js} +1 -1
- package/dist/embed/embed-page-chunk-JMTQCORF.js +211 -0
- package/dist/embed/embed-page-chunk-L7TDL27M.js +15 -0
- package/dist/embed/{embed-page-chunk-TVVAPR7I.js → embed-page-chunk-PTKGTA4B.js} +1 -1
- package/dist/embed/embed-page-chunk-R7TLHZR3.js +7 -0
- package/dist/embed/{embed-page-chunk-FEMHLB6I.js → embed-page-chunk-WKQHSEZ4.js} +1 -1
- package/dist/embed/embed-page-code-highlighter-72YW5HXH.js +1 -0
- package/dist/embed/{embed-page-en-ETUCVCSC.js → embed-page-en-E35GE7TA.js} +1 -1
- package/dist/embed/embed-page-en-EKHHBS6L.js +1 -0
- package/dist/embed/embed-page-en-G5J7KW6V.js +1 -0
- package/dist/embed/embed-page-en-HDSVQ4O6.js +1 -0
- package/dist/embed/embed-page-en-KAXIJJ4X.js +1 -0
- package/dist/embed/embed-page-en-OIICQSPX.js +3 -0
- package/dist/embed/embed-page-en-TMGUHZ6Y.js +1 -0
- package/dist/embed/embed-page-en-TSCGSJAI.js +1 -0
- package/dist/embed/embed-page-en-XJYWUJEL.js +1 -0
- package/dist/embed/{embed-page-en-2SWQHPAC.js → embed-page-en-ZCNNAMUD.js} +1 -1
- package/dist/embed/{embed-page-mermaid-KEBBKHQH.js → embed-page-mermaid-4PZJJXQU.js} +1 -1
- package/dist/embed/embed-page-zh-2UVQB4RP.js +3 -0
- package/dist/embed/embed-page-zh-6EBUEFKP.js +1 -0
- package/dist/embed/embed-page-zh-72QSTYRF.js +1 -0
- package/dist/embed/embed-page-zh-B3WBWQAV.js +1 -0
- package/dist/embed/embed-page-zh-IR652A6J.js +1 -0
- package/dist/embed/embed-page-zh-KEMYJJLT.js +1 -0
- package/dist/embed/embed-page-zh-Q22DIOB3.js +1 -0
- package/dist/embed/{embed-page-zh-PRMID3YQ.js → embed-page-zh-Z3URTIHW.js} +1 -1
- package/dist/embed/{embed-page-zh-D3IC6BGA.js → embed-page-zh-ZLK3GLM3.js} +1 -1
- package/dist/embed/embed-page.js +1 -1
- package/dist/index.d.mts +137 -14
- package/dist/index.d.ts +137 -14
- package/dist/index.js +3942 -1479
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2272 -635
- package/dist/index.mjs.map +1 -1
- package/dist/{open-NTH7AGD3.mjs → open-7ED27I5B.mjs} +3 -3
- package/dist/{open-exposure-AGNG4MC3.mjs → open-exposure-I3DN2X4E.mjs} +6 -4
- package/dist/{open-exposure-AGNG4MC3.mjs.map → open-exposure-I3DN2X4E.mjs.map} +1 -1
- package/package.json +13 -7
- package/dist/WechatChannelAdapter-7WHE5UGY.mjs.map +0 -1
- package/dist/a2a-standard-DP53K7RC.mjs.map +0 -1
- package/dist/chunk-MWWLJMYN.mjs.map +0 -1
- package/dist/embed/embed-page-AgentDetailSideApp-KNVDO3FZ.js +0 -1
- package/dist/embed/embed-page-AgentGovernanceWorkbench-QSKWVADP.js +0 -1
- package/dist/embed/embed-page-MessageGraph-VGXX4OWU.js +0 -6
- package/dist/embed/embed-page-ReactChart-PIISVBLU.js +0 -1
- package/dist/embed/embed-page-SkillFlow-JLI5MEZE.js +0 -1
- package/dist/embed/embed-page-ThreadMaintenancePanel-FSQVVIIG.js +0 -1
- package/dist/embed/embed-page-chunk-37LGEEJU.js +0 -21
- package/dist/embed/embed-page-chunk-436REIWY.js +0 -1
- package/dist/embed/embed-page-chunk-4W34QOXT.js +0 -517
- package/dist/embed/embed-page-chunk-BANVRQT7.js +0 -322
- package/dist/embed/embed-page-chunk-N66H4DNH.js +0 -6657
- package/dist/embed/embed-page-code-highlighter-66CSPTFK.js +0 -1
- package/dist/embed/embed-page-en-27OIE2UA.js +0 -1
- package/dist/embed/embed-page-en-7IHJFS63.js +0 -1
- package/dist/embed/embed-page-en-7NF4GCC2.js +0 -1
- package/dist/embed/embed-page-en-FP6DWSG3.js +0 -1
- package/dist/embed/embed-page-en-GHTROC4H.js +0 -1
- package/dist/embed/embed-page-en-WUFULCUS.js +0 -1
- package/dist/embed/embed-page-en-X6B6RVNL.js +0 -1
- package/dist/embed/embed-page-en-XUMHP5CL.js +0 -1
- package/dist/embed/embed-page-zh-EQ5X2M32.js +0 -1
- package/dist/embed/embed-page-zh-FXQGY5HD.js +0 -1
- package/dist/embed/embed-page-zh-G75LDQU4.js +0 -1
- package/dist/embed/embed-page-zh-KJXKOUIY.js +0 -1
- package/dist/embed/embed-page-zh-RMSS6PXD.js +0 -1
- package/dist/embed/embed-page-zh-VH6J7XZO.js +0 -1
- package/dist/embed/embed-page-zh-Y5X5Y2DF.js +0 -1
- /package/dist/{chunk-FGSFOXIX.mjs.map → chunk-L6MBEEII.mjs.map} +0 -0
- /package/dist/{chunk-J6B2VFJ7.mjs.map → chunk-W3YH4S6G.mjs.map} +0 -0
- /package/dist/{open-NTH7AGD3.mjs.map → open-7ED27I5B.mjs.map} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
buildAgentCardForAssistant
|
|
3
|
-
|
|
2
|
+
buildAgentCardForAssistant,
|
|
3
|
+
deriveAgentSkills
|
|
4
|
+
} from "./chunk-W3YH4S6G.mjs";
|
|
4
5
|
import {
|
|
5
6
|
formatFileRefsSection,
|
|
6
7
|
getRunCancelRouter,
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
JsonRpcTransportHandler,
|
|
23
24
|
RequestContext
|
|
24
25
|
} from "@a2a-js/sdk/server";
|
|
26
|
+
import { AgentCard as AgentCardV1 } from "@a2a-js/sdk-v1";
|
|
25
27
|
import {
|
|
26
28
|
agentInstanceManager as agentInstanceManager2,
|
|
27
29
|
ChunkCursorExpiredError,
|
|
@@ -32,6 +34,488 @@ import {
|
|
|
32
34
|
} from "@axiom-lattice/core";
|
|
33
35
|
import { MessageChunkTypes as MessageChunkTypes3 } from "@axiom-lattice/protocols";
|
|
34
36
|
|
|
37
|
+
// src/services/a2a/A2AAgentCardBuilderV1.ts
|
|
38
|
+
function buildAgentCardForAssistantV1(params) {
|
|
39
|
+
const { assistant, baseUrl } = params;
|
|
40
|
+
const v1Url = `${baseUrl}/a2a/v1/${assistant.id}`;
|
|
41
|
+
const v03Url = `${baseUrl}/a2a/${assistant.id}`;
|
|
42
|
+
const skills = deriveAgentSkills(assistant).map((skill) => ({
|
|
43
|
+
...skill,
|
|
44
|
+
tags: skill.tags ?? [],
|
|
45
|
+
examples: skill.examples ?? [],
|
|
46
|
+
inputModes: [],
|
|
47
|
+
outputModes: [],
|
|
48
|
+
securityRequirements: []
|
|
49
|
+
}));
|
|
50
|
+
return {
|
|
51
|
+
name: assistant.name,
|
|
52
|
+
description: assistant.description ?? "",
|
|
53
|
+
supportedInterfaces: [
|
|
54
|
+
{
|
|
55
|
+
url: v1Url,
|
|
56
|
+
protocolBinding: "JSONRPC",
|
|
57
|
+
tenant: "",
|
|
58
|
+
protocolVersion: "1.0"
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
url: v03Url,
|
|
62
|
+
protocolBinding: "JSONRPC",
|
|
63
|
+
tenant: "",
|
|
64
|
+
protocolVersion: "0.3"
|
|
65
|
+
}
|
|
66
|
+
],
|
|
67
|
+
provider: void 0,
|
|
68
|
+
version: "1.0.0",
|
|
69
|
+
capabilities: {
|
|
70
|
+
streaming: true,
|
|
71
|
+
pushNotifications: params.pushNotifications ?? true,
|
|
72
|
+
extensions: [
|
|
73
|
+
{
|
|
74
|
+
uri: "https://axiom-lattice.dev/a2a/extensions/push-notifications-experimental",
|
|
75
|
+
description: "Push notifications are experimental and best-effort. Delivery is at-most-once; clients should poll tasks/get or use SubscribeToTask for reliability.",
|
|
76
|
+
required: false,
|
|
77
|
+
params: {
|
|
78
|
+
experimental: true,
|
|
79
|
+
reliable: false,
|
|
80
|
+
delivery: "at-most-once"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
extendedAgentCard: true
|
|
85
|
+
},
|
|
86
|
+
securitySchemes: {
|
|
87
|
+
bearer: {
|
|
88
|
+
scheme: {
|
|
89
|
+
$case: "httpAuthSecurityScheme",
|
|
90
|
+
value: {
|
|
91
|
+
scheme: "Bearer",
|
|
92
|
+
description: "API key sent as an Authorization Bearer token",
|
|
93
|
+
bearerFormat: ""
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
apiKeyHeader: {
|
|
98
|
+
scheme: {
|
|
99
|
+
$case: "apiKeySecurityScheme",
|
|
100
|
+
value: {
|
|
101
|
+
location: "header",
|
|
102
|
+
name: "x-api-key",
|
|
103
|
+
description: "API key sent via the x-api-key header"
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
securityRequirements: [
|
|
109
|
+
{ schemes: { bearer: { list: [] } } },
|
|
110
|
+
{ schemes: { apiKeyHeader: { list: [] } } }
|
|
111
|
+
],
|
|
112
|
+
defaultInputModes: ["text"],
|
|
113
|
+
defaultOutputModes: ["text"],
|
|
114
|
+
skills,
|
|
115
|
+
signatures: []
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// src/services/a2a/a2aV1Wire.ts
|
|
120
|
+
var V1_TO_V03_METHOD = {
|
|
121
|
+
SendMessage: "message/send",
|
|
122
|
+
SendStreamingMessage: "message/stream",
|
|
123
|
+
GetTask: "tasks/get",
|
|
124
|
+
ListTasks: "tasks/list",
|
|
125
|
+
CancelTask: "tasks/cancel",
|
|
126
|
+
SubscribeToTask: "tasks/resubscribe",
|
|
127
|
+
CreateTaskPushNotificationConfig: "tasks/pushNotificationConfig/set",
|
|
128
|
+
GetTaskPushNotificationConfig: "tasks/pushNotificationConfig/get",
|
|
129
|
+
ListTaskPushNotificationConfigs: "tasks/pushNotificationConfig/list",
|
|
130
|
+
DeleteTaskPushNotificationConfig: "tasks/pushNotificationConfig/delete",
|
|
131
|
+
GetExtendedAgentCard: "agent/getAuthenticatedExtendedCard"
|
|
132
|
+
};
|
|
133
|
+
var V1_TO_V03_STATE = {
|
|
134
|
+
TASK_STATE_SUBMITTED: "submitted",
|
|
135
|
+
TASK_STATE_WORKING: "working",
|
|
136
|
+
TASK_STATE_COMPLETED: "completed",
|
|
137
|
+
TASK_STATE_FAILED: "failed",
|
|
138
|
+
TASK_STATE_CANCELED: "canceled",
|
|
139
|
+
TASK_STATE_INPUT_REQUIRED: "input-required",
|
|
140
|
+
TASK_STATE_REJECTED: "rejected",
|
|
141
|
+
TASK_STATE_AUTH_REQUIRED: "auth-required",
|
|
142
|
+
TASK_STATE_UNSPECIFIED: "unknown"
|
|
143
|
+
};
|
|
144
|
+
var V03_TO_V1_STATE = {
|
|
145
|
+
submitted: "TASK_STATE_SUBMITTED",
|
|
146
|
+
working: "TASK_STATE_WORKING",
|
|
147
|
+
completed: "TASK_STATE_COMPLETED",
|
|
148
|
+
failed: "TASK_STATE_FAILED",
|
|
149
|
+
canceled: "TASK_STATE_CANCELED",
|
|
150
|
+
"input-required": "TASK_STATE_INPUT_REQUIRED",
|
|
151
|
+
rejected: "TASK_STATE_REJECTED",
|
|
152
|
+
"auth-required": "TASK_STATE_AUTH_REQUIRED",
|
|
153
|
+
unknown: "TASK_STATE_UNSPECIFIED"
|
|
154
|
+
};
|
|
155
|
+
function asRecord(value) {
|
|
156
|
+
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
157
|
+
}
|
|
158
|
+
function asString(value) {
|
|
159
|
+
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
160
|
+
}
|
|
161
|
+
function asArray(value) {
|
|
162
|
+
return Array.isArray(value) ? value : void 0;
|
|
163
|
+
}
|
|
164
|
+
function withMetadata(value, metadata) {
|
|
165
|
+
return typeof metadata === "object" && metadata !== null && !Array.isArray(metadata) ? { ...value, metadata } : value;
|
|
166
|
+
}
|
|
167
|
+
function v1TaskStateTo03(value) {
|
|
168
|
+
if (typeof value !== "string") return "unknown";
|
|
169
|
+
return V1_TO_V03_STATE[value] ?? value;
|
|
170
|
+
}
|
|
171
|
+
function v03TaskStateToV1(value) {
|
|
172
|
+
if (typeof value !== "string") return "TASK_STATE_UNSPECIFIED";
|
|
173
|
+
return V03_TO_V1_STATE[value] ?? "TASK_STATE_UNSPECIFIED";
|
|
174
|
+
}
|
|
175
|
+
function toV03Part(part) {
|
|
176
|
+
const record = asRecord(part);
|
|
177
|
+
if (!record) return void 0;
|
|
178
|
+
if (typeof record.text === "string") {
|
|
179
|
+
return withMetadata({ kind: "text", text: record.text }, record.metadata);
|
|
180
|
+
}
|
|
181
|
+
if (typeof record.raw === "string") {
|
|
182
|
+
return withMetadata({
|
|
183
|
+
kind: "file",
|
|
184
|
+
file: {
|
|
185
|
+
bytes: record.raw,
|
|
186
|
+
...typeof record.mediaType === "string" ? { mimeType: record.mediaType } : {},
|
|
187
|
+
...typeof record.filename === "string" ? { name: record.filename } : {}
|
|
188
|
+
}
|
|
189
|
+
}, record.metadata);
|
|
190
|
+
}
|
|
191
|
+
if (typeof record.url === "string") {
|
|
192
|
+
return withMetadata({
|
|
193
|
+
kind: "file",
|
|
194
|
+
file: {
|
|
195
|
+
uri: record.url,
|
|
196
|
+
...typeof record.mediaType === "string" ? { mimeType: record.mediaType } : {},
|
|
197
|
+
...typeof record.filename === "string" ? { name: record.filename } : {}
|
|
198
|
+
}
|
|
199
|
+
}, record.metadata);
|
|
200
|
+
}
|
|
201
|
+
if ("data" in record) {
|
|
202
|
+
return withMetadata({ kind: "data", data: record.data }, record.metadata);
|
|
203
|
+
}
|
|
204
|
+
if (record.kind === "text" && typeof record.text === "string") {
|
|
205
|
+
return withMetadata({ kind: "text", text: record.text }, record.metadata);
|
|
206
|
+
}
|
|
207
|
+
if (record.kind === "file") {
|
|
208
|
+
const file = asRecord(record.file);
|
|
209
|
+
if (!file) return void 0;
|
|
210
|
+
return withMetadata({ kind: "file", file }, record.metadata);
|
|
211
|
+
}
|
|
212
|
+
if (record.kind === "data") {
|
|
213
|
+
return withMetadata({ kind: "data", data: record.data }, record.metadata);
|
|
214
|
+
}
|
|
215
|
+
return void 0;
|
|
216
|
+
}
|
|
217
|
+
function toV1Part(part) {
|
|
218
|
+
if (part.kind === "text") {
|
|
219
|
+
return withMetadata({ text: part.text }, part.metadata);
|
|
220
|
+
}
|
|
221
|
+
if (part.kind === "data") {
|
|
222
|
+
return withMetadata({ data: part.data }, part.metadata);
|
|
223
|
+
}
|
|
224
|
+
const file = part.file;
|
|
225
|
+
const base = "uri" in file ? {
|
|
226
|
+
url: file.uri,
|
|
227
|
+
...file.mimeType ? { mediaType: file.mimeType } : {},
|
|
228
|
+
...file.name ? { filename: file.name } : {}
|
|
229
|
+
} : {
|
|
230
|
+
raw: file.bytes,
|
|
231
|
+
...file.mimeType ? { mediaType: file.mimeType } : {},
|
|
232
|
+
...file.name ? { filename: file.name } : {}
|
|
233
|
+
};
|
|
234
|
+
return withMetadata(base, part.metadata);
|
|
235
|
+
}
|
|
236
|
+
function v1RoleTo03(value) {
|
|
237
|
+
if (value === "ROLE_USER" || value === "user" || value === 1) return "user";
|
|
238
|
+
return "agent";
|
|
239
|
+
}
|
|
240
|
+
function v03RoleToV1(value) {
|
|
241
|
+
return value === "user" ? "ROLE_USER" : "ROLE_AGENT";
|
|
242
|
+
}
|
|
243
|
+
function toV03Message(value) {
|
|
244
|
+
const record = asRecord(value);
|
|
245
|
+
if (!record) return void 0;
|
|
246
|
+
const parts = (asArray(record.parts) ?? []).map(toV03Part).filter((part) => part !== void 0);
|
|
247
|
+
return {
|
|
248
|
+
kind: "message",
|
|
249
|
+
messageId: asString(record.messageId) ?? "",
|
|
250
|
+
role: v1RoleTo03(record.role),
|
|
251
|
+
parts,
|
|
252
|
+
...asString(record.contextId) ? { contextId: asString(record.contextId) } : {},
|
|
253
|
+
...asString(record.taskId) ? { taskId: asString(record.taskId) } : {},
|
|
254
|
+
...typeof record.metadata === "object" && record.metadata !== null ? { metadata: record.metadata } : {},
|
|
255
|
+
...asArray(record.extensions) ? { extensions: record.extensions } : {},
|
|
256
|
+
...asArray(record.referenceTaskIds) ? { referenceTaskIds: record.referenceTaskIds } : {}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function toV1Message(message) {
|
|
260
|
+
return {
|
|
261
|
+
messageId: message.messageId,
|
|
262
|
+
...message.contextId ? { contextId: message.contextId } : {},
|
|
263
|
+
...message.taskId ? { taskId: message.taskId } : {},
|
|
264
|
+
role: v03RoleToV1(message.role),
|
|
265
|
+
parts: message.parts.map(toV1Part),
|
|
266
|
+
...message.metadata ? { metadata: message.metadata } : {},
|
|
267
|
+
...message.extensions?.length ? { extensions: message.extensions } : {},
|
|
268
|
+
...message.referenceTaskIds?.length ? { referenceTaskIds: message.referenceTaskIds } : {}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function toV03Status(value) {
|
|
272
|
+
const record = asRecord(value);
|
|
273
|
+
if (!record) return void 0;
|
|
274
|
+
return {
|
|
275
|
+
state: v1TaskStateTo03(record.state),
|
|
276
|
+
...asRecord(record.message) ? { message: toV03Message(record.message) } : {},
|
|
277
|
+
...asString(record.timestamp) ? { timestamp: asString(record.timestamp) } : {}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
function toV1Status(status) {
|
|
281
|
+
return {
|
|
282
|
+
state: v03TaskStateToV1(status.state),
|
|
283
|
+
...status.message ? { message: toV1Message(status.message) } : {},
|
|
284
|
+
...status.timestamp ? { timestamp: status.timestamp } : {}
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function toV03Artifact(value) {
|
|
288
|
+
const record = asRecord(value);
|
|
289
|
+
if (!record) return void 0;
|
|
290
|
+
const parts = (asArray(record.parts) ?? []).map(toV03Part).filter((part) => part !== void 0);
|
|
291
|
+
return {
|
|
292
|
+
artifactId: asString(record.artifactId) ?? "",
|
|
293
|
+
...asString(record.name) ? { name: asString(record.name) } : {},
|
|
294
|
+
...asString(record.description) ? { description: asString(record.description) } : {},
|
|
295
|
+
parts,
|
|
296
|
+
...typeof record.metadata === "object" && record.metadata !== null ? { metadata: record.metadata } : {}
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
function toV1Artifact(artifact) {
|
|
300
|
+
return {
|
|
301
|
+
artifactId: artifact.artifactId,
|
|
302
|
+
...artifact.name ? { name: artifact.name } : {},
|
|
303
|
+
...artifact.description ? { description: artifact.description } : {},
|
|
304
|
+
parts: artifact.parts.map(toV1Part),
|
|
305
|
+
...artifact.metadata ? { metadata: artifact.metadata } : {}
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
function toV03Task(value) {
|
|
309
|
+
const record = asRecord(value);
|
|
310
|
+
if (!record) return void 0;
|
|
311
|
+
const status = toV03Status(record.status);
|
|
312
|
+
if (!status) return void 0;
|
|
313
|
+
const rawArtifacts = asArray(record.artifacts);
|
|
314
|
+
const rawHistory = asArray(record.history);
|
|
315
|
+
return {
|
|
316
|
+
kind: "task",
|
|
317
|
+
id: asString(record.id) ?? "",
|
|
318
|
+
contextId: asString(record.contextId) ?? "",
|
|
319
|
+
status,
|
|
320
|
+
...rawArtifacts ? {
|
|
321
|
+
artifacts: rawArtifacts.map(toV03Artifact).filter((artifact) => artifact !== void 0)
|
|
322
|
+
} : {},
|
|
323
|
+
...rawHistory ? {
|
|
324
|
+
history: rawHistory.map(toV03Message).filter((message) => message !== void 0)
|
|
325
|
+
} : {},
|
|
326
|
+
...typeof record.metadata === "object" && record.metadata !== null ? { metadata: record.metadata } : {}
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
function toV1Task(task) {
|
|
330
|
+
return {
|
|
331
|
+
id: task.id,
|
|
332
|
+
contextId: task.contextId,
|
|
333
|
+
status: toV1Status(task.status),
|
|
334
|
+
...task.artifacts?.length ? { artifacts: task.artifacts.map(toV1Artifact) } : {},
|
|
335
|
+
...task.history?.length ? { history: task.history.map(toV1Message) } : {},
|
|
336
|
+
...task.metadata ? { metadata: task.metadata } : {}
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
function toV03PushConfig(value) {
|
|
340
|
+
const record = asRecord(value);
|
|
341
|
+
if (!record) return void 0;
|
|
342
|
+
const authentication = asRecord(record.authentication);
|
|
343
|
+
return {
|
|
344
|
+
...asString(record.id) ? { id: asString(record.id) } : {},
|
|
345
|
+
url: asString(record.url) ?? "",
|
|
346
|
+
...asString(record.token) ? { token: asString(record.token) } : {},
|
|
347
|
+
...authentication ? {
|
|
348
|
+
authentication: {
|
|
349
|
+
...asString(authentication.scheme) ? { schemes: [authentication.scheme] } : {},
|
|
350
|
+
...asString(authentication.credentials) ? { credentials: authentication.credentials } : {}
|
|
351
|
+
}
|
|
352
|
+
} : {}
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
function toV1PushConfig(value) {
|
|
356
|
+
const record = asRecord(value);
|
|
357
|
+
if (!record) return void 0;
|
|
358
|
+
const config = asRecord(record.pushNotificationConfig) ?? record;
|
|
359
|
+
const authentication = asRecord(config.authentication);
|
|
360
|
+
const schemes = asArray(authentication?.schemes);
|
|
361
|
+
return {
|
|
362
|
+
...asString(record.taskId) ? { taskId: asString(record.taskId) } : {},
|
|
363
|
+
...asString(config.id) ? { id: asString(config.id) } : {},
|
|
364
|
+
...asString(config.url) ? { url: asString(config.url) } : {},
|
|
365
|
+
...asString(config.token) ? { token: asString(config.token) } : {},
|
|
366
|
+
...schemes?.[0] || asString(authentication?.credentials) ? {
|
|
367
|
+
authentication: {
|
|
368
|
+
...typeof schemes?.[0] === "string" ? { scheme: schemes[0] } : {},
|
|
369
|
+
...asString(authentication?.credentials) ? { credentials: asString(authentication?.credentials) } : {}
|
|
370
|
+
}
|
|
371
|
+
} : {}
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
function convertParams(method, params) {
|
|
375
|
+
const record = asRecord(params);
|
|
376
|
+
if (!record) return params;
|
|
377
|
+
if (method === "SendMessage" || method === "SendStreamingMessage") {
|
|
378
|
+
const configuration = asRecord(record.configuration);
|
|
379
|
+
const push = asRecord(configuration?.taskPushNotificationConfig);
|
|
380
|
+
return {
|
|
381
|
+
...asRecord(record.message) ? { message: toV03Message(record.message) } : {},
|
|
382
|
+
...configuration ? {
|
|
383
|
+
configuration: {
|
|
384
|
+
...asArray(configuration.acceptedOutputModes) ? { acceptedOutputModes: configuration.acceptedOutputModes } : {},
|
|
385
|
+
blocking: configuration.returnImmediately !== true,
|
|
386
|
+
...typeof configuration.historyLength === "number" ? { historyLength: configuration.historyLength } : {},
|
|
387
|
+
...push ? { pushNotificationConfig: toV03PushConfig(push) } : {}
|
|
388
|
+
}
|
|
389
|
+
} : {},
|
|
390
|
+
...typeof record.metadata === "object" && record.metadata !== null ? { metadata: record.metadata } : {}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
if (method === "ListTasks") {
|
|
394
|
+
return {
|
|
395
|
+
...asString(record.contextId) ? { contextId: asString(record.contextId) } : {},
|
|
396
|
+
...record.status !== void 0 ? { status: v1TaskStateTo03(record.status) } : {},
|
|
397
|
+
...typeof record.pageSize === "number" ? { pageSize: record.pageSize } : {},
|
|
398
|
+
...asString(record.pageToken) ? { pageToken: asString(record.pageToken) } : {},
|
|
399
|
+
...typeof record.historyLength === "number" ? { historyLength: record.historyLength } : {},
|
|
400
|
+
...asString(record.statusTimestampAfter) ? { statusTimestampAfter: asString(record.statusTimestampAfter) } : {},
|
|
401
|
+
...typeof record.includeArtifacts === "boolean" ? { includeArtifacts: record.includeArtifacts } : {}
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
if (method === "CreateTaskPushNotificationConfig") {
|
|
405
|
+
const config = toV03PushConfig(record);
|
|
406
|
+
return {
|
|
407
|
+
taskId: asString(record.taskId) ?? "",
|
|
408
|
+
...config ? { pushNotificationConfig: config } : {}
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
if (method === "GetTaskPushNotificationConfig") {
|
|
412
|
+
return {
|
|
413
|
+
id: asString(record.taskId) ?? "",
|
|
414
|
+
...asString(record.id) ? { pushNotificationConfigId: asString(record.id) } : {}
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
if (method === "ListTaskPushNotificationConfigs" || method === "DeleteTaskPushNotificationConfig") {
|
|
418
|
+
return {
|
|
419
|
+
id: asString(record.taskId) ?? "",
|
|
420
|
+
...asString(record.id) ? { pushNotificationConfigId: asString(record.id) } : {}
|
|
421
|
+
};
|
|
422
|
+
}
|
|
423
|
+
return record;
|
|
424
|
+
}
|
|
425
|
+
function toA2A03JsonRpcRequest(body) {
|
|
426
|
+
const record = asRecord(body);
|
|
427
|
+
const method = asString(record?.method);
|
|
428
|
+
if (!record || !method) return body;
|
|
429
|
+
const mapped = V1_TO_V03_METHOD[method];
|
|
430
|
+
if (!mapped) return body;
|
|
431
|
+
return {
|
|
432
|
+
...record,
|
|
433
|
+
method: mapped,
|
|
434
|
+
params: convertParams(method, record.params)
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
function toA2A11Result(value, method) {
|
|
438
|
+
const record = asRecord(value);
|
|
439
|
+
if (!record) return value;
|
|
440
|
+
if (record.kind === "task") {
|
|
441
|
+
const task = toV03Task(record);
|
|
442
|
+
return task ? toV1Task(task) : value;
|
|
443
|
+
}
|
|
444
|
+
if (record.kind === "message") {
|
|
445
|
+
const message = toV03Message(record);
|
|
446
|
+
return message ? toV1Message(message) : value;
|
|
447
|
+
}
|
|
448
|
+
if (method === "CreateTaskPushNotificationConfig" || method === "GetTaskPushNotificationConfig") {
|
|
449
|
+
return toV1PushConfig(record);
|
|
450
|
+
}
|
|
451
|
+
return value;
|
|
452
|
+
}
|
|
453
|
+
function toA2A11StreamResult(event) {
|
|
454
|
+
const record = asRecord(event);
|
|
455
|
+
if (!record) return event;
|
|
456
|
+
if (record.kind === "task") {
|
|
457
|
+
const task = toV03Task(record);
|
|
458
|
+
return task ? { task: toV1Task(task) } : event;
|
|
459
|
+
}
|
|
460
|
+
if (record.kind === "message") {
|
|
461
|
+
const message = toV03Message(record);
|
|
462
|
+
return message ? { message: toV1Message(message) } : event;
|
|
463
|
+
}
|
|
464
|
+
if (record.kind === "status-update") {
|
|
465
|
+
const status = toV03Status(record.status);
|
|
466
|
+
return {
|
|
467
|
+
statusUpdate: {
|
|
468
|
+
taskId: asString(record.taskId) ?? "",
|
|
469
|
+
contextId: asString(record.contextId) ?? "",
|
|
470
|
+
...status ? { status: toV1Status(status) } : {},
|
|
471
|
+
...typeof record.metadata === "object" && record.metadata !== null ? { metadata: record.metadata } : {}
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
if (record.kind === "artifact-update") {
|
|
476
|
+
const artifact = toV03Artifact(record.artifact);
|
|
477
|
+
return {
|
|
478
|
+
artifactUpdate: {
|
|
479
|
+
taskId: asString(record.taskId) ?? "",
|
|
480
|
+
contextId: asString(record.contextId) ?? "",
|
|
481
|
+
...artifact ? { artifact: toV1Artifact(artifact) } : {},
|
|
482
|
+
...record.append === true ? { append: true } : {},
|
|
483
|
+
...record.lastChunk === true ? { lastChunk: true } : {},
|
|
484
|
+
...typeof record.metadata === "object" && record.metadata !== null ? { metadata: record.metadata } : {}
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
return event;
|
|
489
|
+
}
|
|
490
|
+
function toA2A11ListResult(value, options = {}) {
|
|
491
|
+
const record = asRecord(value);
|
|
492
|
+
const tasks = asArray(record?.tasks) ?? [];
|
|
493
|
+
return {
|
|
494
|
+
tasks: tasks.map(toV03Task).filter((task) => task !== void 0).map((task) => {
|
|
495
|
+
const converted = toV1Task(task);
|
|
496
|
+
if (options.includeArtifacts !== true) delete converted.artifacts;
|
|
497
|
+
return converted;
|
|
498
|
+
}),
|
|
499
|
+
...asString(record?.nextPageToken) ? { nextPageToken: asString(record?.nextPageToken) } : {}
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
function toA2A11PushListResult(value) {
|
|
503
|
+
const configs = asArray(value) ?? [];
|
|
504
|
+
return {
|
|
505
|
+
configs: configs.map(toV1PushConfig).filter((config) => config !== void 0)
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
function versionNotSupportedError(id, version) {
|
|
509
|
+
return {
|
|
510
|
+
jsonrpc: "2.0",
|
|
511
|
+
id: id ?? null,
|
|
512
|
+
error: {
|
|
513
|
+
code: -32009,
|
|
514
|
+
message: `The requested A2A protocol version '${version}' is not supported. Supported versions: 1.0`
|
|
515
|
+
}
|
|
516
|
+
};
|
|
517
|
+
}
|
|
518
|
+
|
|
35
519
|
// src/services/a2a/A2APushNotificationStore.ts
|
|
36
520
|
import { decrypt, encrypt } from "@axiom-lattice/core";
|
|
37
521
|
|
|
@@ -451,10 +935,10 @@ var A2ATaskScopeConflictError = class extends Error {
|
|
|
451
935
|
function mapTaskStatusToA2AState(status) {
|
|
452
936
|
return TASK_STATUS_TO_A2A_STATE[status];
|
|
453
937
|
}
|
|
454
|
-
function
|
|
938
|
+
function asString2(value) {
|
|
455
939
|
return typeof value === "string" ? value : void 0;
|
|
456
940
|
}
|
|
457
|
-
function
|
|
941
|
+
function asRecord2(value) {
|
|
458
942
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
459
943
|
}
|
|
460
944
|
function asStringArray(value) {
|
|
@@ -588,11 +1072,11 @@ var A2ATaskStoreAdapter = class {
|
|
|
588
1072
|
const files = extractFiles(task);
|
|
589
1073
|
const result = task.status.state === "completed" ? extractArtifactText(task.artifacts) || extractFinalTurnAgentText(task.history) : void 0;
|
|
590
1074
|
const failureReason = extractFailureReason(task);
|
|
591
|
-
const a2aRunId =
|
|
1075
|
+
const a2aRunId = asString2(task.metadata?.a2aRunId) ?? asString2(task.metadata?.runId);
|
|
592
1076
|
const context = {
|
|
593
1077
|
a2aContextId: task.contextId,
|
|
594
1078
|
...a2aRunId ? { a2aRunId } : {},
|
|
595
|
-
threadId:
|
|
1079
|
+
threadId: asString2(task.metadata?.threadId),
|
|
596
1080
|
a2aTask: task
|
|
597
1081
|
};
|
|
598
1082
|
let existing = await this.taskStore.getById(tenantId, task.id);
|
|
@@ -626,7 +1110,7 @@ var A2ATaskStoreAdapter = class {
|
|
|
626
1110
|
await this.recordSnapshot(task, existing);
|
|
627
1111
|
}
|
|
628
1112
|
const actor = `a2a:${this.scope.assistantId}`;
|
|
629
|
-
const threadId =
|
|
1113
|
+
const threadId = asString2(task.metadata?.threadId);
|
|
630
1114
|
if (task.status.state === "working") {
|
|
631
1115
|
existing = await this.refresh(existing);
|
|
632
1116
|
const resumesInterruption = existing.status === "interrupted" && task.metadata?.a2aResume === true;
|
|
@@ -700,7 +1184,7 @@ var A2ATaskStoreAdapter = class {
|
|
|
700
1184
|
async completeRun(task, result) {
|
|
701
1185
|
const { tenantId } = this.scope;
|
|
702
1186
|
const actor = `a2a:${this.scope.assistantId}`;
|
|
703
|
-
const threadId =
|
|
1187
|
+
const threadId = asString2(task.metadata?.threadId);
|
|
704
1188
|
let item = await this.taskStore.getById(tenantId, task.id);
|
|
705
1189
|
if (!item) {
|
|
706
1190
|
throw new Error(`A2A completed run cannot reconcile missing task ${task.id}`);
|
|
@@ -781,7 +1265,7 @@ var A2ATaskStoreAdapter = class {
|
|
|
781
1265
|
summary: "A2A task snapshot",
|
|
782
1266
|
detail: { type: "a2a_task_snapshot", snapshotSequence: sequence, eventKey, task: sequencedTask },
|
|
783
1267
|
eventKey,
|
|
784
|
-
...
|
|
1268
|
+
...asString2(task.metadata?.threadId) ? { threadId: asString2(task.metadata?.threadId) } : {},
|
|
785
1269
|
...workspaceId ? { workspaceId } : {}
|
|
786
1270
|
});
|
|
787
1271
|
}
|
|
@@ -802,14 +1286,14 @@ var A2ATaskStoreAdapter = class {
|
|
|
802
1286
|
...task.status.message ? { message: extractText(task.status.message.parts) } : {}
|
|
803
1287
|
},
|
|
804
1288
|
eventKey: observationEventKey(task, result, failureReason),
|
|
805
|
-
...
|
|
1289
|
+
...asString2(task.metadata?.threadId) ? { threadId: asString2(task.metadata?.threadId) } : {},
|
|
806
1290
|
...workspaceId ? { workspaceId } : {}
|
|
807
1291
|
});
|
|
808
1292
|
}
|
|
809
1293
|
async applyObservation(task, item, result, failureReason) {
|
|
810
1294
|
const actor = `a2a:${this.scope.assistantId}`;
|
|
811
1295
|
item = await this.refresh(item);
|
|
812
|
-
const threadId =
|
|
1296
|
+
const threadId = asString2(task.metadata?.threadId);
|
|
813
1297
|
if (task.status.state === "canceled") {
|
|
814
1298
|
await this.requireLifecycleSuccess("cancel", task.id, await this.runBridge.settleRun({
|
|
815
1299
|
tenantId: this.scope.tenantId,
|
|
@@ -835,10 +1319,10 @@ var A2ATaskStoreAdapter = class {
|
|
|
835
1319
|
return;
|
|
836
1320
|
}
|
|
837
1321
|
if (task.status.state === "input-required") {
|
|
838
|
-
const observed =
|
|
839
|
-
const observedType =
|
|
1322
|
+
const observed = asRecord2(task.metadata?.interruption);
|
|
1323
|
+
const observedType = asString2(observed?.type);
|
|
840
1324
|
const interruptionType = observedType === "review_required" || observedType === "user_decision" ? "user_decision" : "missing_input";
|
|
841
|
-
const summary =
|
|
1325
|
+
const summary = asString2(observed?.summary) || (task.status.message ? extractText(task.status.message.parts).trim() : "") || "A2A requires input";
|
|
842
1326
|
await this.requireLifecycleSuccess("interrupt", task.id, await this.lifecycle.interruptTask({
|
|
843
1327
|
tenantId: this.scope.tenantId,
|
|
844
1328
|
taskId: task.id,
|
|
@@ -869,7 +1353,7 @@ var A2ATaskStoreAdapter = class {
|
|
|
869
1353
|
const item = await this.taskStore.getById(this.scope.tenantId, taskId);
|
|
870
1354
|
if (!item) return;
|
|
871
1355
|
const context = item.context ?? {};
|
|
872
|
-
const current =
|
|
1356
|
+
const current = asRecord2(context.interruption) ?? {};
|
|
873
1357
|
await this.taskStore.update(this.scope.tenantId, taskId, {
|
|
874
1358
|
context: {
|
|
875
1359
|
...context,
|
|
@@ -919,7 +1403,7 @@ var A2ATaskStoreAdapter = class {
|
|
|
919
1403
|
const candidate = {
|
|
920
1404
|
task: activity.detail.task,
|
|
921
1405
|
sequence,
|
|
922
|
-
eventKey:
|
|
1406
|
+
eventKey: asString2(activity.detail.eventKey) ?? activity.eventKey ?? snapshotEventKey(activity.detail.task),
|
|
923
1407
|
statusTimestamp: Date.parse(activity.detail.task.status.timestamp ?? ""),
|
|
924
1408
|
createdAt: activity.createdAt,
|
|
925
1409
|
id: activity.id
|
|
@@ -936,8 +1420,8 @@ var A2ATaskStoreAdapter = class {
|
|
|
936
1420
|
}
|
|
937
1421
|
const state = mapTaskStatusToA2AState(item.status);
|
|
938
1422
|
const interruption = item.context?.interruption;
|
|
939
|
-
const contextRunId =
|
|
940
|
-
const contextThreadId =
|
|
1423
|
+
const contextRunId = asString2(item.context?.a2aRunId);
|
|
1424
|
+
const contextThreadId = asString2(item.context?.threadId);
|
|
941
1425
|
const metadata = {
|
|
942
1426
|
...snapshot.metadata ?? {},
|
|
943
1427
|
...contextRunId === void 0 ? {} : { a2aRunId: contextRunId },
|
|
@@ -1349,10 +1833,10 @@ var TERMINAL_A2A_STATES = /* @__PURE__ */ new Set([
|
|
|
1349
1833
|
function isoNow() {
|
|
1350
1834
|
return (/* @__PURE__ */ new Date()).toISOString();
|
|
1351
1835
|
}
|
|
1352
|
-
function
|
|
1836
|
+
function asString3(value) {
|
|
1353
1837
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
1354
1838
|
}
|
|
1355
|
-
function
|
|
1839
|
+
function asRecord3(value) {
|
|
1356
1840
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
1357
1841
|
}
|
|
1358
1842
|
function extractText2(parts) {
|
|
@@ -1364,7 +1848,7 @@ function dataParts(parts) {
|
|
|
1364
1848
|
);
|
|
1365
1849
|
}
|
|
1366
1850
|
function soleOfficialInterruptId(task) {
|
|
1367
|
-
const ids = (task?.artifacts ?? []).filter((artifact) => artifact.name === "interrupt").flatMap((artifact) => artifact.parts).filter((part) => part.kind === "data").map((part) =>
|
|
1851
|
+
const ids = (task?.artifacts ?? []).filter((artifact) => artifact.name === "interrupt").flatMap((artifact) => artifact.parts).filter((part) => part.kind === "data").map((part) => asString3(part.data.id)).filter((id) => id !== void 0 && isOfficialInterruptId(id));
|
|
1368
1852
|
return ids.length === 1 ? ids[0] : void 0;
|
|
1369
1853
|
}
|
|
1370
1854
|
function agentMessage(text) {
|
|
@@ -1397,7 +1881,7 @@ var AxiomAgentExecutor = class {
|
|
|
1397
1881
|
/** Execute one A2A request through the durable run service. */
|
|
1398
1882
|
async execute(ctx, bus) {
|
|
1399
1883
|
const existing = ctx.task;
|
|
1400
|
-
const threadId =
|
|
1884
|
+
const threadId = asString3(existing?.metadata?.threadId) ?? ctx.contextId;
|
|
1401
1885
|
const dependencies = ctx.referenceTasks?.map((task) => task.id) ?? [];
|
|
1402
1886
|
const resume = this.isResume(existing);
|
|
1403
1887
|
const text = extractText2(ctx.userMessage.parts);
|
|
@@ -1422,7 +1906,7 @@ var AxiomAgentExecutor = class {
|
|
|
1422
1906
|
`Task ${existing.id} is terminal (${existing.status.state}) and cannot be modified`
|
|
1423
1907
|
);
|
|
1424
1908
|
}
|
|
1425
|
-
const interruption =
|
|
1909
|
+
const interruption = asRecord3(existing?.metadata?.interruption);
|
|
1426
1910
|
const reviewInterruption = interruption?.type === "review_required";
|
|
1427
1911
|
const command = resume ? this.resumeCommand(
|
|
1428
1912
|
ctx.userMessage.parts,
|
|
@@ -1589,7 +2073,7 @@ var AxiomAgentExecutor = class {
|
|
|
1589
2073
|
threadId,
|
|
1590
2074
|
this.scope.assistantId
|
|
1591
2075
|
).catch(() => void 0);
|
|
1592
|
-
const runRecord =
|
|
2076
|
+
const runRecord = asRecord3(run);
|
|
1593
2077
|
const abortStream = runRecord?.cancelRequested === true || terminal.status === "timeout";
|
|
1594
2078
|
if (abortStream) {
|
|
1595
2079
|
dropChunks = true;
|
|
@@ -1610,7 +2094,7 @@ var AxiomAgentExecutor = class {
|
|
|
1610
2094
|
case "error": {
|
|
1611
2095
|
const canonical = this.taskStore ? await this.taskStore.load(ctx.taskId) : void 0;
|
|
1612
2096
|
const canonicalMessage = canonical?.status.state === "failed" && canonical.status.message ? extractText2(canonical.status.message.parts).trim() : "";
|
|
1613
|
-
const message = canonicalMessage ||
|
|
2097
|
+
const message = canonicalMessage || asString3(runRecord?.error) || (streamError instanceof Error ? streamError.message : void 0) || "A2A run failed";
|
|
1614
2098
|
await this.failTask(
|
|
1615
2099
|
ctx,
|
|
1616
2100
|
bus,
|
|
@@ -1718,8 +2202,8 @@ var AxiomAgentExecutor = class {
|
|
|
1718
2202
|
artifactId: `${ctx.taskId}:interrupt`,
|
|
1719
2203
|
name: "interrupt",
|
|
1720
2204
|
parts: interrupts.map((interrupt) => {
|
|
1721
|
-
const payload =
|
|
1722
|
-
const schema =
|
|
2205
|
+
const payload = asRecord3(interrupt.payload);
|
|
2206
|
+
const schema = asRecord3(payload?.response_schema) ?? payload?.response_schema;
|
|
1723
2207
|
return {
|
|
1724
2208
|
kind: "data",
|
|
1725
2209
|
data: {
|
|
@@ -1861,7 +2345,7 @@ ${formatFileRefsSection(inputFiles)}` : text;
|
|
|
1861
2345
|
const data = dataParts(parts);
|
|
1862
2346
|
if (data.length > 0) {
|
|
1863
2347
|
const officialIds = data.map((part) => {
|
|
1864
|
-
const id =
|
|
2348
|
+
const id = asString3(part.data.id);
|
|
1865
2349
|
return id !== void 0 && isOfficialInterruptId(id) ? id : void 0;
|
|
1866
2350
|
});
|
|
1867
2351
|
if (data.length > 1 && officialIds.every((id) => id !== void 0)) {
|
|
@@ -1917,8 +2401,8 @@ ${formatFileRefsSection(inputFiles)}` : text;
|
|
|
1917
2401
|
*/
|
|
1918
2402
|
async cancelTask(taskId, bus) {
|
|
1919
2403
|
const task = this.taskStore ? await this.taskStore.load(taskId) : void 0;
|
|
1920
|
-
const threadId =
|
|
1921
|
-
const runId =
|
|
2404
|
+
const threadId = asString3(task?.metadata?.threadId);
|
|
2405
|
+
const runId = asString3(task?.metadata?.a2aRunId) ?? asString3(task?.metadata?.runId);
|
|
1922
2406
|
if (threadId && runId) {
|
|
1923
2407
|
try {
|
|
1924
2408
|
await this.runService.cancel(
|
|
@@ -2321,14 +2805,14 @@ function normalizeCheckpointMessages(messages) {
|
|
|
2321
2805
|
messages.forEach((message, index) => {
|
|
2322
2806
|
if (typeof message !== "object" || message === null) return;
|
|
2323
2807
|
const record = message;
|
|
2324
|
-
const type = typeof record.getType === "function" ? record.getType() :
|
|
2808
|
+
const type = typeof record.getType === "function" ? record.getType() : asString4(record.type) ?? asString4(record.role);
|
|
2325
2809
|
const role = type === "human" || type === "user" ? "user" : type === "ai" || type === "assistant" ? "agent" : void 0;
|
|
2326
2810
|
if (!role) return;
|
|
2327
2811
|
const text = messageText(record.content);
|
|
2328
2812
|
if (!text) return;
|
|
2329
2813
|
normalized.push({
|
|
2330
2814
|
kind: "message",
|
|
2331
|
-
messageId:
|
|
2815
|
+
messageId: asString4(record.id) ?? `a2a-checkpoint:${index}`,
|
|
2332
2816
|
role,
|
|
2333
2817
|
parts: [{ kind: "text", text }]
|
|
2334
2818
|
});
|
|
@@ -2374,11 +2858,11 @@ var TERMINAL_RUN_STATUSES = /* @__PURE__ */ new Set([
|
|
|
2374
2858
|
"timeout"
|
|
2375
2859
|
]);
|
|
2376
2860
|
var RESUBSCRIBE_SETTLE_TIMEOUT_MS = 1e4;
|
|
2377
|
-
function
|
|
2861
|
+
function asString4(value) {
|
|
2378
2862
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
2379
2863
|
}
|
|
2380
2864
|
function requestMethod(body) {
|
|
2381
|
-
return typeof body === "object" && body !== null ?
|
|
2865
|
+
return typeof body === "object" && body !== null ? asString4(body.method) : void 0;
|
|
2382
2866
|
}
|
|
2383
2867
|
function requestTaskId(body) {
|
|
2384
2868
|
if (typeof body !== "object" || body === null) return void 0;
|
|
@@ -2386,11 +2870,11 @@ function requestTaskId(body) {
|
|
|
2386
2870
|
const params = typeof record.params === "object" && record.params !== null ? record.params : void 0;
|
|
2387
2871
|
if (!params) return void 0;
|
|
2388
2872
|
if (record.method === "tasks/get" || record.method === "tasks/cancel" || record.method === "tasks/resubscribe") {
|
|
2389
|
-
return
|
|
2873
|
+
return asString4(params.id);
|
|
2390
2874
|
}
|
|
2391
2875
|
if (record.method === "message/send" || record.method === "message/stream") {
|
|
2392
2876
|
const message = typeof params.message === "object" && params.message !== null ? params.message : void 0;
|
|
2393
|
-
return
|
|
2877
|
+
return asString4(message?.taskId);
|
|
2394
2878
|
}
|
|
2395
2879
|
return void 0;
|
|
2396
2880
|
}
|
|
@@ -2418,7 +2902,7 @@ function projectRunState(run) {
|
|
|
2418
2902
|
case "timeout":
|
|
2419
2903
|
return {
|
|
2420
2904
|
state: "failed",
|
|
2421
|
-
...
|
|
2905
|
+
...asString4(run.error) ? { message: agentMessage2(asString4(run.error)) } : {}
|
|
2422
2906
|
};
|
|
2423
2907
|
default:
|
|
2424
2908
|
return void 0;
|
|
@@ -2497,9 +2981,9 @@ async function reconcileTaskFromRun(taskStore, runService, stateResolver, scope,
|
|
|
2497
2981
|
if (isTerminalA2AState(task.status.state)) {
|
|
2498
2982
|
if (task.status.state !== "completed") return task;
|
|
2499
2983
|
}
|
|
2500
|
-
const runId =
|
|
2984
|
+
const runId = asString4(task.metadata?.a2aRunId);
|
|
2501
2985
|
if (!runId) return task;
|
|
2502
|
-
const threadId =
|
|
2986
|
+
const threadId = asString4(task.metadata?.threadId) ?? task.contextId;
|
|
2503
2987
|
const run = await runService.getRun(
|
|
2504
2988
|
scope.tenantId,
|
|
2505
2989
|
runId,
|
|
@@ -2591,9 +3075,9 @@ async function cancelTaskFromRun(taskStore, runService, scope, body) {
|
|
|
2591
3075
|
if (!taskId) return void 0;
|
|
2592
3076
|
const task = await taskStore.load(taskId);
|
|
2593
3077
|
if (!task || isTerminalA2AState(task.status.state)) return void 0;
|
|
2594
|
-
const runId =
|
|
3078
|
+
const runId = asString4(task.metadata?.a2aRunId);
|
|
2595
3079
|
if (!runId) return void 0;
|
|
2596
|
-
const threadId =
|
|
3080
|
+
const threadId = asString4(task.metadata?.threadId) ?? task.contextId;
|
|
2597
3081
|
const before = await runService.getRun(
|
|
2598
3082
|
scope.tenantId,
|
|
2599
3083
|
runId,
|
|
@@ -2697,7 +3181,7 @@ var TASKS_LIST_STATUSES = {
|
|
|
2697
3181
|
interrupted: ["interrupted"],
|
|
2698
3182
|
cancelled: ["cancelled"]
|
|
2699
3183
|
};
|
|
2700
|
-
function
|
|
3184
|
+
function asRecord4(value) {
|
|
2701
3185
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
2702
3186
|
}
|
|
2703
3187
|
function encodePageToken(offset) {
|
|
@@ -2711,12 +3195,12 @@ function decodePageToken(token) {
|
|
|
2711
3195
|
return Number.isSafeInteger(offset) && offset >= 0 ? offset : void 0;
|
|
2712
3196
|
}
|
|
2713
3197
|
function parseTasksListQuery(body) {
|
|
2714
|
-
const record =
|
|
3198
|
+
const record = asRecord4(body);
|
|
2715
3199
|
const rawParams = record?.params;
|
|
2716
|
-
if (rawParams !== void 0 && rawParams !== null &&
|
|
3200
|
+
if (rawParams !== void 0 && rawParams !== null && asRecord4(rawParams) === void 0) {
|
|
2717
3201
|
return { ok: false, message: "params must be an object" };
|
|
2718
3202
|
}
|
|
2719
|
-
const params =
|
|
3203
|
+
const params = asRecord4(rawParams) ?? {};
|
|
2720
3204
|
let pageSize = DEFAULT_A2A_TASKS_PAGE_SIZE;
|
|
2721
3205
|
if (params.pageSize !== void 0) {
|
|
2722
3206
|
const value = params.pageSize;
|
|
@@ -2737,6 +3221,20 @@ function parseTasksListQuery(body) {
|
|
|
2737
3221
|
}
|
|
2738
3222
|
offset = decoded;
|
|
2739
3223
|
}
|
|
3224
|
+
let contextId;
|
|
3225
|
+
if (params.contextId !== void 0) {
|
|
3226
|
+
if (typeof params.contextId !== "string") {
|
|
3227
|
+
return { ok: false, message: "contextId must be a string" };
|
|
3228
|
+
}
|
|
3229
|
+
contextId = params.contextId;
|
|
3230
|
+
}
|
|
3231
|
+
let statusTimestampAfter;
|
|
3232
|
+
if (params.statusTimestampAfter !== void 0) {
|
|
3233
|
+
if (typeof params.statusTimestampAfter !== "string") {
|
|
3234
|
+
return { ok: false, message: "statusTimestampAfter must be a string" };
|
|
3235
|
+
}
|
|
3236
|
+
statusTimestampAfter = params.statusTimestampAfter;
|
|
3237
|
+
}
|
|
2740
3238
|
let statuses;
|
|
2741
3239
|
if (params.status !== void 0) {
|
|
2742
3240
|
const value = params.status;
|
|
@@ -2747,7 +3245,13 @@ function parseTasksListQuery(body) {
|
|
|
2747
3245
|
}
|
|
2748
3246
|
return {
|
|
2749
3247
|
ok: true,
|
|
2750
|
-
query: {
|
|
3248
|
+
query: {
|
|
3249
|
+
pageSize,
|
|
3250
|
+
offset,
|
|
3251
|
+
...statuses ? { statuses } : {},
|
|
3252
|
+
...contextId ? { contextId } : {},
|
|
3253
|
+
...statusTimestampAfter ? { statusTimestampAfter } : {}
|
|
3254
|
+
}
|
|
2751
3255
|
};
|
|
2752
3256
|
}
|
|
2753
3257
|
function isA2ATaskSnapshot2(value, id) {
|
|
@@ -2782,6 +3286,8 @@ async function listCanonicalA2ATasks(internalTasks, taskStore, scope, query) {
|
|
|
2782
3286
|
if (statuses && !statuses.includes(item.status)) continue;
|
|
2783
3287
|
const restored = await taskStore.load(item.id).catch(() => void 0);
|
|
2784
3288
|
if (!restored || !isA2ATaskSnapshot2(restored, item.id)) continue;
|
|
3289
|
+
if (query.contextId && restored.contextId !== query.contextId) continue;
|
|
3290
|
+
if (query.statusTimestampAfter && (!restored.status.timestamp || restored.status.timestamp <= query.statusTimestampAfter)) continue;
|
|
2785
3291
|
if (seen.has(restored.id)) continue;
|
|
2786
3292
|
if (tasks.length < query.pageSize) {
|
|
2787
3293
|
seen.add(restored.id);
|
|
@@ -2880,11 +3386,12 @@ function registerA2AStandardRoutes(app, deps) {
|
|
|
2880
3386
|
app.addHook("onClose", async () => {
|
|
2881
3387
|
runtimeRegistry.close();
|
|
2882
3388
|
});
|
|
2883
|
-
const handleTaskResubscribe = async (request, reply, requestId, scope, taskStore) => {
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
const
|
|
2887
|
-
const
|
|
3389
|
+
const handleTaskResubscribe = async (request, reply, requestId, scope, taskStore, options = {}) => {
|
|
3390
|
+
const version = options.version ?? "0.3";
|
|
3391
|
+
reply.header("A2A-Version", version);
|
|
3392
|
+
const body = asRecord4(options.body ?? request.body);
|
|
3393
|
+
const params = asRecord4(body?.params);
|
|
3394
|
+
const taskId = asString4(params?.id);
|
|
2888
3395
|
if (!taskId) {
|
|
2889
3396
|
reply.send(jsonRpcError(requestId, -32602, "Invalid params: id is required"));
|
|
2890
3397
|
return;
|
|
@@ -2917,7 +3424,7 @@ function registerA2AStandardRoutes(app, deps) {
|
|
|
2917
3424
|
throw err;
|
|
2918
3425
|
}
|
|
2919
3426
|
reply.hijack();
|
|
2920
|
-
reply.raw.writeHead(200, SSE_HEADERS);
|
|
3427
|
+
reply.raw.writeHead(200, { ...SSE_HEADERS, "A2A-Version": version });
|
|
2921
3428
|
const writeFrame = async (frame, event) => {
|
|
2922
3429
|
if (reply.raw.writableEnded || reply.raw.destroyed) return;
|
|
2923
3430
|
const data = `${event ? `event: ${event}
|
|
@@ -2938,7 +3445,7 @@ function registerA2AStandardRoutes(app, deps) {
|
|
|
2938
3445
|
const resultFrame = (result) => ({
|
|
2939
3446
|
jsonrpc: "2.0",
|
|
2940
3447
|
id: requestId,
|
|
2941
|
-
result
|
|
3448
|
+
result: version === "1.0" ? toA2A11StreamResult(result) : result
|
|
2942
3449
|
});
|
|
2943
3450
|
let disconnected = false;
|
|
2944
3451
|
let iterator;
|
|
@@ -2959,11 +3466,11 @@ function registerA2AStandardRoutes(app, deps) {
|
|
|
2959
3466
|
try {
|
|
2960
3467
|
await writeFrame(resultFrame(task));
|
|
2961
3468
|
if (disconnected || isTerminalA2AState(task.status.state)) return;
|
|
2962
|
-
const runId =
|
|
3469
|
+
const runId = asString4(task.metadata?.a2aRunId);
|
|
2963
3470
|
if (!runId) return;
|
|
2964
|
-
const threadId =
|
|
2965
|
-
const messageId =
|
|
2966
|
-
const cursor =
|
|
3471
|
+
const threadId = asString4(task.metadata?.threadId) ?? task.contextId;
|
|
3472
|
+
const messageId = asString4(task.metadata?.a2aMessageId);
|
|
3473
|
+
const cursor = asString4(task.metadata?.a2aStreamCursor);
|
|
2967
3474
|
const runService = runServiceFor(scope);
|
|
2968
3475
|
const reconcileCanonicalTask = async () => {
|
|
2969
3476
|
const reconciled = await reconcileTaskFromRun(
|
|
@@ -2971,7 +3478,7 @@ function registerA2AStandardRoutes(app, deps) {
|
|
|
2971
3478
|
runService,
|
|
2972
3479
|
stateResolver,
|
|
2973
3480
|
scope,
|
|
2974
|
-
request.body
|
|
3481
|
+
options.body ?? request.body
|
|
2975
3482
|
).catch(() => void 0);
|
|
2976
3483
|
return reconciled ?? taskStore.load(taskId).catch(() => void 0);
|
|
2977
3484
|
};
|
|
@@ -3409,8 +3916,273 @@ data: ${JSON.stringify(data)}
|
|
|
3409
3916
|
}
|
|
3410
3917
|
}
|
|
3411
3918
|
);
|
|
3919
|
+
const v1CardFor = (request, assistant, pushNotifications) => buildAgentCardForAssistantV1({
|
|
3920
|
+
assistant,
|
|
3921
|
+
baseUrl: buildBaseUrl(request),
|
|
3922
|
+
pushNotifications
|
|
3923
|
+
});
|
|
3924
|
+
const authenticateV1 = async (request) => {
|
|
3925
|
+
const auth = await authService.authenticate(
|
|
3926
|
+
getHeader(request.headers.authorization) ?? getHeader(request.headers["x-api-key"])
|
|
3927
|
+
);
|
|
3928
|
+
if (!auth.authenticated) {
|
|
3929
|
+
return { ok: false, status: 401, message: "Unauthorized" };
|
|
3930
|
+
}
|
|
3931
|
+
try {
|
|
3932
|
+
const assistant = await authService.assertAgentAccess(
|
|
3933
|
+
auth,
|
|
3934
|
+
request.params.assistantId
|
|
3935
|
+
);
|
|
3936
|
+
return { ok: true, assistant, auth };
|
|
3937
|
+
} catch (err) {
|
|
3938
|
+
if (err instanceof A2AAuthError) {
|
|
3939
|
+
return { ok: false, status: err.statusCode, message: err.message };
|
|
3940
|
+
}
|
|
3941
|
+
throw err;
|
|
3942
|
+
}
|
|
3943
|
+
};
|
|
3944
|
+
app.get(
|
|
3945
|
+
"/a2a/v1/:assistantId/.well-known/agent-card.json",
|
|
3946
|
+
async (request, reply) => {
|
|
3947
|
+
const auth = await authenticateV1(request);
|
|
3948
|
+
if (!auth.ok) {
|
|
3949
|
+
reply.status(auth.status).send({ error: auth.message });
|
|
3950
|
+
return;
|
|
3951
|
+
}
|
|
3952
|
+
reply.header("A2A-Version", "1.0");
|
|
3953
|
+
reply.status(200).send(
|
|
3954
|
+
AgentCardV1.toJSON(
|
|
3955
|
+
v1CardFor(request, auth.assistant, hasPushStore())
|
|
3956
|
+
)
|
|
3957
|
+
);
|
|
3958
|
+
}
|
|
3959
|
+
);
|
|
3960
|
+
app.post(
|
|
3961
|
+
"/a2a/v1/:assistantId",
|
|
3962
|
+
async (request, reply) => {
|
|
3963
|
+
const requestBody = asRecord4(request.body) ?? {};
|
|
3964
|
+
const requestId = extractRequestId(requestBody);
|
|
3965
|
+
reply.header("A2A-Version", "1.0");
|
|
3966
|
+
const requestedVersion = getHeader(request.headers["a2a-version"]);
|
|
3967
|
+
if (requestedVersion !== void 0 && !requestedVersion.startsWith("1.0")) {
|
|
3968
|
+
reply.header("A2A-Version", "1.0").send(versionNotSupportedError(requestId, requestedVersion));
|
|
3969
|
+
return;
|
|
3970
|
+
}
|
|
3971
|
+
const auth = await authenticateV1(request);
|
|
3972
|
+
if (!auth.ok) {
|
|
3973
|
+
reply.status(auth.status).send(jsonRpcError(requestId, authErrorToRpcCode(auth.status), auth.message));
|
|
3974
|
+
return;
|
|
3975
|
+
}
|
|
3976
|
+
const rawMethod = asString4(requestBody.method);
|
|
3977
|
+
const tenantId = auth.auth.tenantId ?? "default";
|
|
3978
|
+
const scope = {
|
|
3979
|
+
tenantId,
|
|
3980
|
+
projectId: auth.auth.projectId ?? "",
|
|
3981
|
+
workspaceId: await resolveWorkspaceId(getProjectStore, tenantId, auth.auth.projectId),
|
|
3982
|
+
assistantId: auth.assistant.id
|
|
3983
|
+
};
|
|
3984
|
+
const internalTasks = resolveTasks();
|
|
3985
|
+
const workItems = resolveTaskWorkItems();
|
|
3986
|
+
const taskStore = taskStoreFor(scope, internalTasks, workItems);
|
|
3987
|
+
if (rawMethod === "ListTasks") {
|
|
3988
|
+
const v03Body2 = toA2A03JsonRpcRequest(requestBody);
|
|
3989
|
+
const parsed = parseTasksListQuery(v03Body2);
|
|
3990
|
+
if (!parsed.ok) {
|
|
3991
|
+
reply.send(jsonRpcError(requestId, -32602, parsed.message));
|
|
3992
|
+
return;
|
|
3993
|
+
}
|
|
3994
|
+
try {
|
|
3995
|
+
const result2 = await listCanonicalA2ATasks(
|
|
3996
|
+
internalTasks,
|
|
3997
|
+
taskStore,
|
|
3998
|
+
scope,
|
|
3999
|
+
parsed.query
|
|
4000
|
+
);
|
|
4001
|
+
const listParams = asRecord4(requestBody.params);
|
|
4002
|
+
reply.send({
|
|
4003
|
+
jsonrpc: "2.0",
|
|
4004
|
+
id: requestId,
|
|
4005
|
+
result: toA2A11ListResult(result2, {
|
|
4006
|
+
includeArtifacts: listParams?.includeArtifacts === true
|
|
4007
|
+
})
|
|
4008
|
+
});
|
|
4009
|
+
} catch (err) {
|
|
4010
|
+
request.log.error({ err }, "a2a:v1:list");
|
|
4011
|
+
reply.send(jsonRpcError(requestId, -32603, "Internal error"));
|
|
4012
|
+
}
|
|
4013
|
+
return;
|
|
4014
|
+
}
|
|
4015
|
+
if (rawMethod === "GetExtendedAgentCard") {
|
|
4016
|
+
reply.send({
|
|
4017
|
+
jsonrpc: "2.0",
|
|
4018
|
+
id: requestId,
|
|
4019
|
+
result: AgentCardV1.toJSON(
|
|
4020
|
+
v1CardFor(request, auth.assistant, hasPushStore())
|
|
4021
|
+
)
|
|
4022
|
+
});
|
|
4023
|
+
return;
|
|
4024
|
+
}
|
|
4025
|
+
const v03Body = toA2A03JsonRpcRequest(requestBody);
|
|
4026
|
+
if (rawMethod === "SubscribeToTask") {
|
|
4027
|
+
await handleTaskResubscribe(
|
|
4028
|
+
request,
|
|
4029
|
+
reply,
|
|
4030
|
+
requestId,
|
|
4031
|
+
scope,
|
|
4032
|
+
taskStore,
|
|
4033
|
+
{ version: "1.0", body: v03Body }
|
|
4034
|
+
);
|
|
4035
|
+
return;
|
|
4036
|
+
}
|
|
4037
|
+
const ingestor = makeFileIngestor(scope.tenantId, deps.maxFileBytes);
|
|
4038
|
+
const runService = runServiceFor(scope);
|
|
4039
|
+
const executor = new AxiomAgentExecutor({
|
|
4040
|
+
scope,
|
|
4041
|
+
assistant: auth.assistant,
|
|
4042
|
+
taskStore,
|
|
4043
|
+
ingestor,
|
|
4044
|
+
runService,
|
|
4045
|
+
blocking: blockingFor(v03Body),
|
|
4046
|
+
getInterrupts: (threadId) => stateResolver.getInterrupts(threadId, auth.assistant.id, scope)
|
|
4047
|
+
});
|
|
4048
|
+
try {
|
|
4049
|
+
await reconcileTaskFromRun(
|
|
4050
|
+
taskStore,
|
|
4051
|
+
runService,
|
|
4052
|
+
stateResolver,
|
|
4053
|
+
scope,
|
|
4054
|
+
v03Body
|
|
4055
|
+
);
|
|
4056
|
+
const canceled = await cancelTaskFromRun(
|
|
4057
|
+
taskStore,
|
|
4058
|
+
runService,
|
|
4059
|
+
scope,
|
|
4060
|
+
v03Body
|
|
4061
|
+
);
|
|
4062
|
+
if (canceled) {
|
|
4063
|
+
reply.send({
|
|
4064
|
+
jsonrpc: "2.0",
|
|
4065
|
+
id: requestId,
|
|
4066
|
+
result: toA2A11Result(canceled, rawMethod)
|
|
4067
|
+
});
|
|
4068
|
+
return;
|
|
4069
|
+
}
|
|
4070
|
+
} catch (err) {
|
|
4071
|
+
if (err instanceof A2AError3) {
|
|
4072
|
+
reply.send(jsonRpcError(requestId, err.code, err.message));
|
|
4073
|
+
return;
|
|
4074
|
+
}
|
|
4075
|
+
request.log.error({ err }, "a2a:v1:reconcile");
|
|
4076
|
+
reply.send(jsonRpcError(requestId, -32603, "Internal error"));
|
|
4077
|
+
return;
|
|
4078
|
+
}
|
|
4079
|
+
const resumeError = await resumeValidationError(taskStore, v03Body).catch(() => void 0);
|
|
4080
|
+
if (resumeError !== void 0) {
|
|
4081
|
+
reply.send(jsonRpcError(requestId, -32602, resumeError));
|
|
4082
|
+
return;
|
|
4083
|
+
}
|
|
4084
|
+
let pushStore;
|
|
4085
|
+
try {
|
|
4086
|
+
pushStore = createPushStore(scope);
|
|
4087
|
+
} catch (err) {
|
|
4088
|
+
request.log.warn({ err }, "a2a:v1:push-store-unavailable");
|
|
4089
|
+
}
|
|
4090
|
+
const card = buildAgentCardForAssistant({
|
|
4091
|
+
assistant: auth.assistant,
|
|
4092
|
+
baseUrl: buildBaseUrl(request),
|
|
4093
|
+
pushNotifications: pushStore !== void 0,
|
|
4094
|
+
jsonRpcPath: `/a2a/v1/${auth.assistant.id}`
|
|
4095
|
+
});
|
|
4096
|
+
let runtimeLease;
|
|
4097
|
+
try {
|
|
4098
|
+
runtimeLease = runtimeRegistry.acquire(scope);
|
|
4099
|
+
} catch (err) {
|
|
4100
|
+
if (err instanceof A2ARuntimeCapacityError) {
|
|
4101
|
+
request.log.error({ err, scope }, "a2a:v1:runtime_capacity");
|
|
4102
|
+
reply.status(503).send(jsonRpcError(requestId, -32603, "A2A runtime capacity exhausted"));
|
|
4103
|
+
return;
|
|
4104
|
+
}
|
|
4105
|
+
throw err;
|
|
4106
|
+
}
|
|
4107
|
+
let result;
|
|
4108
|
+
try {
|
|
4109
|
+
const pushSender = pushStore ? deps.getPushNotificationSender?.(pushStore) ?? new A2APushNotificationSender({
|
|
4110
|
+
store: pushStore,
|
|
4111
|
+
...deps.resolvePushHost ? { resolveHost: deps.resolvePushHost } : {}
|
|
4112
|
+
}) : void 0;
|
|
4113
|
+
const handler = new DefaultRequestHandler(
|
|
4114
|
+
card,
|
|
4115
|
+
taskStore,
|
|
4116
|
+
executor,
|
|
4117
|
+
runtimeLease.manager,
|
|
4118
|
+
pushStore,
|
|
4119
|
+
pushSender
|
|
4120
|
+
);
|
|
4121
|
+
const transport = new JsonRpcTransportHandler(handler);
|
|
4122
|
+
result = await transport.handle(v03Body);
|
|
4123
|
+
} catch (err) {
|
|
4124
|
+
runtimeLease.release();
|
|
4125
|
+
if (err instanceof A2AError3) {
|
|
4126
|
+
reply.send(jsonRpcError(requestId, err.code, err.message));
|
|
4127
|
+
return;
|
|
4128
|
+
}
|
|
4129
|
+
request.log.error({ err }, "a2a:v1:handler");
|
|
4130
|
+
reply.send(jsonRpcError(requestId, -32603, "Internal error"));
|
|
4131
|
+
return;
|
|
4132
|
+
}
|
|
4133
|
+
const convertResult = (value) => {
|
|
4134
|
+
if (rawMethod === "ListTaskPushNotificationConfigs") {
|
|
4135
|
+
return toA2A11PushListResult(value);
|
|
4136
|
+
}
|
|
4137
|
+
const converted = toA2A11Result(value, rawMethod);
|
|
4138
|
+
if (rawMethod === "SendMessage") {
|
|
4139
|
+
if (value && typeof value === "object" && value.kind === "task") {
|
|
4140
|
+
return { task: converted };
|
|
4141
|
+
}
|
|
4142
|
+
if (value && typeof value === "object" && value.kind === "message") {
|
|
4143
|
+
return { message: converted };
|
|
4144
|
+
}
|
|
4145
|
+
}
|
|
4146
|
+
return converted;
|
|
4147
|
+
};
|
|
4148
|
+
if (isAsyncGenerator(result)) {
|
|
4149
|
+
reply.hijack();
|
|
4150
|
+
reply.raw.writeHead(200, SSE_HEADERS);
|
|
4151
|
+
try {
|
|
4152
|
+
for await (const frame of result) {
|
|
4153
|
+
const converted = {
|
|
4154
|
+
...frame,
|
|
4155
|
+
..."result" in frame ? { result: toA2A11StreamResult(frame.result) } : {}
|
|
4156
|
+
};
|
|
4157
|
+
reply.raw.write(`data: ${JSON.stringify(converted)}
|
|
4158
|
+
|
|
4159
|
+
`);
|
|
4160
|
+
}
|
|
4161
|
+
} catch (err) {
|
|
4162
|
+
request.log.error({ err }, "a2a:v1:stream");
|
|
4163
|
+
const errorResponse = jsonRpcError(
|
|
4164
|
+
requestId,
|
|
4165
|
+
-32603,
|
|
4166
|
+
err instanceof Error ? err.message : "Streaming error."
|
|
4167
|
+
);
|
|
4168
|
+
reply.raw.write(`event: error
|
|
4169
|
+
data: ${JSON.stringify(errorResponse)}
|
|
4170
|
+
|
|
4171
|
+
`);
|
|
4172
|
+
} finally {
|
|
4173
|
+
runtimeLease.release();
|
|
4174
|
+
reply.raw.end();
|
|
4175
|
+
}
|
|
4176
|
+
return;
|
|
4177
|
+
}
|
|
4178
|
+
runtimeLease.release();
|
|
4179
|
+
reply.send(
|
|
4180
|
+
"result" in result ? { ...result, result: convertResult(result.result) } : result
|
|
4181
|
+
);
|
|
4182
|
+
}
|
|
4183
|
+
);
|
|
3412
4184
|
}
|
|
3413
4185
|
export {
|
|
3414
4186
|
registerA2AStandardRoutes
|
|
3415
4187
|
};
|
|
3416
|
-
//# sourceMappingURL=a2a-standard-
|
|
4188
|
+
//# sourceMappingURL=a2a-standard-VL5I7B4W.mjs.map
|