@agents24/node 0.5.32 → 0.5.34
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/compatibility.json +8 -8
- package/dist/bff.cjs +123 -14
- package/dist/bff.cjs.map +1 -1
- package/dist/bff.d.cts +3 -1
- package/dist/bff.d.ts +3 -1
- package/dist/bff.js +123 -14
- package/dist/bff.js.map +1 -1
- package/dist/{client-BhE-CjMz.d.cts → client-CY0o68YO.d.cts} +26 -0
- package/dist/{client-BhE-CjMz.d.ts → client-CY0o68YO.d.ts} +26 -0
- package/dist/index.cjs +37 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +37 -7
- package/dist/index.js.map +1 -1
- package/dist/types/agents.d.ts +1 -0
- package/dist/types/agents.d.ts.map +1 -1
- package/dist/types/bff-agent-resolution.d.ts +2 -0
- package/dist/types/bff-agent-resolution.d.ts.map +1 -1
- package/dist/types/bff-conversation-submission.d.ts.map +1 -1
- package/dist/types/bff-history.d.ts +17 -0
- package/dist/types/bff-history.d.ts.map +1 -0
- package/dist/types/bff-multi-agent.d.ts +1 -0
- package/dist/types/bff-multi-agent.d.ts.map +1 -1
- package/dist/types/bff-request.d.ts +2 -0
- package/dist/types/bff-request.d.ts.map +1 -1
- package/dist/types/bff-single-agent.d.ts.map +1 -1
- package/dist/types/bff-sse.d.ts +3 -0
- package/dist/types/bff-sse.d.ts.map +1 -1
- package/dist/types/bff.d.ts.map +1 -1
- package/dist/types/embed-types.d.ts +4 -0
- package/dist/types/embed-types.d.ts.map +1 -1
- package/dist/types/embed.d.ts +5 -0
- package/dist/types/embed.d.ts.map +1 -1
- package/dist/types/generated/manifest.d.ts +1 -1
- package/dist/types/generated/manifest.d.ts.map +1 -1
- package/dist/types/runs.d.ts +11 -0
- package/dist/types/runs.d.ts.map +1 -1
- package/dist/types/types.d.ts +6 -0
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +2 -2
package/compatibility.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"contractHash": "
|
|
2
|
+
"contractHash": "b9b9a3f464ed29f9df64462c3104802c5e9a4e7d3ed6f4ecfc078295e4458ed5",
|
|
3
3
|
"contractVersion": "0.3.0",
|
|
4
4
|
"corpus": "conformance/v1/corpus.json",
|
|
5
5
|
"generatedBy": "@agents24/sdk-contract",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"reactDom": ">=19 <20"
|
|
16
16
|
},
|
|
17
17
|
"@agents24/client": {
|
|
18
|
-
"contract": "
|
|
18
|
+
"contract": "9d624998b7ba0eb7055eaf4720ee4756ae579be0733ed3485d577086f9bf847c",
|
|
19
19
|
"runtime": "run-stream.v3"
|
|
20
20
|
},
|
|
21
21
|
"@agents24/node": {
|
|
22
|
-
"contract": "
|
|
22
|
+
"contract": "b9b9a3f464ed29f9df64462c3104802c5e9a4e7d3ed6f4ecfc078295e4458ed5",
|
|
23
23
|
"node": "^22.0.0 || ^24.0.0"
|
|
24
24
|
},
|
|
25
25
|
"@agents24/react": {
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"react": ">=19 <20"
|
|
28
28
|
},
|
|
29
29
|
"@talmudpedia/runtime-sdk": {
|
|
30
|
-
"contract": "
|
|
30
|
+
"contract": "9d624998b7ba0eb7055eaf4720ee4756ae579be0733ed3485d577086f9bf847c",
|
|
31
31
|
"protocolOwner": "@agents24/client"
|
|
32
32
|
},
|
|
33
33
|
"agents24": {
|
|
34
|
-
"contract": "
|
|
34
|
+
"contract": "b9b9a3f464ed29f9df64462c3104802c5e9a4e7d3ed6f4ecfc078295e4458ed5",
|
|
35
35
|
"python": ">=3.10"
|
|
36
36
|
}
|
|
37
37
|
},
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
},
|
|
48
48
|
"schemaVersion": "agents24.compatibility.v1",
|
|
49
49
|
"targetOperationCounts": {
|
|
50
|
-
"client":
|
|
51
|
-
"node":
|
|
52
|
-
"python":
|
|
50
|
+
"client": 38,
|
|
51
|
+
"node": 202,
|
|
52
|
+
"python": 196
|
|
53
53
|
}
|
|
54
54
|
}
|
package/dist/bff.cjs
CHANGED
|
@@ -189,6 +189,13 @@ function routeId(path, pattern, field) {
|
|
|
189
189
|
throw new BffInputError(400, "INVALID_PATH", `${field} is invalid.`);
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
|
+
function requestedOutputNames(value) {
|
|
193
|
+
if (value === void 0) return void 0;
|
|
194
|
+
if (!Array.isArray(value) || !value.every((name) => typeof name === "string")) {
|
|
195
|
+
throw new BffInputError(400, "INVALID_REQUESTED_OUTPUTS", "requestedOutputs must be a string array.");
|
|
196
|
+
}
|
|
197
|
+
return value;
|
|
198
|
+
}
|
|
192
199
|
function messageBody(body) {
|
|
193
200
|
const mode = body.mode === "steer" ? "steer" : body.mode === "queue" ? "queue" : null;
|
|
194
201
|
if (!mode) throw new BffInputError(400, "INVALID_MODE", "Message mode must be queue or steer.");
|
|
@@ -205,6 +212,7 @@ function messageBody(body) {
|
|
|
205
212
|
input,
|
|
206
213
|
attachmentIds,
|
|
207
214
|
...requestedModelId ? { requestedModelId } : {},
|
|
215
|
+
...body.requestedOutputs === void 0 ? {} : { requestedOutputs: requestedOutputNames(body.requestedOutputs) },
|
|
208
216
|
toolInputs: objectValue(body.toolInputs),
|
|
209
217
|
...body.metadata === void 0 ? {} : { metadata: objectValue(body.metadata) }
|
|
210
218
|
};
|
|
@@ -235,6 +243,48 @@ function computerFileQuery(url, requirePath) {
|
|
|
235
243
|
};
|
|
236
244
|
}
|
|
237
245
|
|
|
246
|
+
// src/bff-history.ts
|
|
247
|
+
function historyProjection(value, historical) {
|
|
248
|
+
const row = objectValue(value);
|
|
249
|
+
if (Array.isArray(row.items)) return { ...row, items: row.items.map((item) => historyProjection(item, historical)) };
|
|
250
|
+
if (row.thread) return { ...row, thread: historyProjection(row.thread, historical) };
|
|
251
|
+
if (row.runtime_selection) return { ...row, read_only: historical.has(String(objectValue(row.runtime_selection).agent_id)) };
|
|
252
|
+
return value;
|
|
253
|
+
}
|
|
254
|
+
function assertWritableAgent(agent, historical) {
|
|
255
|
+
if (historical.has(agent)) throw new BffInputError(409, "THREAD_READ_ONLY", "This conversation is read-only. Start a new chat.");
|
|
256
|
+
}
|
|
257
|
+
async function guardHistoricalRequest(input) {
|
|
258
|
+
const { request, path, historical } = input;
|
|
259
|
+
if (!historical.size || request.method === "GET" || request.method === "HEAD" || request.method === "DELETE" && /^\/threads\/[^/]+$/.test(path) || request.method === "POST" && (/^\/attachments\/[^/]+\/content-access$/.test(path) || /^\/runs\/[^/]+\/attach$/.test(path) || /^\/threads\/[^/]+\/computer\/content-access$/.test(path))) return;
|
|
260
|
+
let threadId = path.match(/^\/threads\/([^/]+)/)?.[1];
|
|
261
|
+
if (path === "/chat/stream") threadId = stringValue((await requestJson(request.clone())).threadId);
|
|
262
|
+
if (path === "/attachments/upload") threadId = stringValue((await requestMultipart(request.clone())).get("thread_id"));
|
|
263
|
+
const scope = {
|
|
264
|
+
externalUserId: input.externalUserId,
|
|
265
|
+
integrationId: input.integrationId,
|
|
266
|
+
externalSessionId: input.resolution.principal.externalSessionId,
|
|
267
|
+
chatScope: input.resolution.chatScope,
|
|
268
|
+
runtimeTarget: input.runtimeTarget
|
|
269
|
+
};
|
|
270
|
+
if (threadId) {
|
|
271
|
+
const thread = await input.embed.getConversationThread(decodeURIComponent(threadId), { ...scope, agentIds: input.agentIds });
|
|
272
|
+
assertWritableAgent(String(thread.runtime_selection.agent_id), historical);
|
|
273
|
+
}
|
|
274
|
+
const runId = path.match(/^\/runs\/([^/]+)/)?.[1];
|
|
275
|
+
if (runId) {
|
|
276
|
+
const run = await input.embed.resolveConversationRun(decodeURIComponent(runId), {
|
|
277
|
+
agent_ids: input.agentIds,
|
|
278
|
+
external_user_id: scope.externalUserId,
|
|
279
|
+
integration_id: scope.integrationId,
|
|
280
|
+
external_session_id: scope.externalSessionId,
|
|
281
|
+
chat_scope: scope.chatScope,
|
|
282
|
+
runtime_target: scope.runtimeTarget
|
|
283
|
+
});
|
|
284
|
+
assertWritableAgent(run.agent_id, historical);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
238
288
|
// src/bff-conversation-submission.ts
|
|
239
289
|
async function submitConversationStream(input) {
|
|
240
290
|
const { request, body, resolution } = input;
|
|
@@ -254,6 +304,7 @@ async function submitConversationStream(input) {
|
|
|
254
304
|
...resolution.customerTenant === void 0 ? {} : { customer_tenant: resolution.customerTenant },
|
|
255
305
|
...resolution.trustedContext === void 0 ? {} : { trusted_context: resolution.trustedContext },
|
|
256
306
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledge_namespaces: resolution.knowledgeNamespaces },
|
|
307
|
+
...value.requestedOutputs === void 0 ? {} : { requested_outputs: value.requestedOutputs },
|
|
257
308
|
tool_inputs: value.toolInputs,
|
|
258
309
|
metadata: objectValue(body.metadata)
|
|
259
310
|
}, {
|
|
@@ -552,6 +603,10 @@ function sseResponse(execute, headers, failurePayload, onFailure, requestSignal,
|
|
|
552
603
|
});
|
|
553
604
|
return new Response(stream, { headers: sseHeaders(headers) });
|
|
554
605
|
}
|
|
606
|
+
function runtimeEventEnabled(request, event) {
|
|
607
|
+
const feature = event.event === "assistant.completed" ? "assistant-completion-v1" : event.event.startsWith("workflow.output.") ? "workflow-outputs-v1" : null;
|
|
608
|
+
return feature === null || Boolean(new URL(request.url).searchParams.get("stream_features")?.split(",").includes(feature));
|
|
609
|
+
}
|
|
555
610
|
|
|
556
611
|
// src/bff-resolver.ts
|
|
557
612
|
var AgentBffResolverError = class extends Error {
|
|
@@ -641,6 +696,21 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
641
696
|
{ ...threadIdentity, integrationId }
|
|
642
697
|
), resolution.responseHeaders);
|
|
643
698
|
let response;
|
|
699
|
+
if (request.method === "GET" && /^\/runs\/[^/]+\/outputs(?:\/[^/]+)?$/.test(path)) {
|
|
700
|
+
const parts = path.split("/");
|
|
701
|
+
const scope = {
|
|
702
|
+
...threadIdentity,
|
|
703
|
+
integrationId,
|
|
704
|
+
runtimeTarget,
|
|
705
|
+
...resolution.chatScope === void 0 ? {} : { chatScope: resolution.chatScope }
|
|
706
|
+
};
|
|
707
|
+
const result = parts[4] ? await embed.getAgentRunOutput(agentId, decodeURIComponent(parts[2]), decodeURIComponent(parts[4]), scope) : await embed.listAgentRunOutputs(agentId, decodeURIComponent(parts[2]), {
|
|
708
|
+
...scope,
|
|
709
|
+
after: Number(url.searchParams.get("after") || 0),
|
|
710
|
+
limit: Number(url.searchParams.get("limit") || 50)
|
|
711
|
+
});
|
|
712
|
+
return mergeHeaders(json(result), resolution.responseHeaders);
|
|
713
|
+
}
|
|
644
714
|
if (request.method === "GET" && path === "/bootstrap") {
|
|
645
715
|
const raw = await embed.getRuntimeBootstrap(agentId, agentVersionId, runtimeTarget);
|
|
646
716
|
response = json(bootstrapDocument(raw, agentVersionId));
|
|
@@ -677,12 +747,15 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
677
747
|
input,
|
|
678
748
|
attachmentIds,
|
|
679
749
|
...resolution.customerTenant === void 0 ? {} : { customerTenant: resolution.customerTenant },
|
|
750
|
+
...resolution.trustedContext === void 0 ? {} : { trustedContext: resolution.trustedContext },
|
|
680
751
|
...stringValue(body.requestedModelId) ? { requestedModelId: stringValue(body.requestedModelId) } : {},
|
|
681
752
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledgeNamespaces: resolution.knowledgeNamespaces },
|
|
753
|
+
...body.requestedOutputs === void 0 ? {} : { requestedOutputs: requestedOutputNames(body.requestedOutputs) },
|
|
682
754
|
toolInputs: objectValue(body.toolInputs),
|
|
683
755
|
...body.metadata === void 0 ? {} : { metadata: objectValue(body.metadata) }
|
|
684
756
|
}, { idempotencyKey }) : await embed.startAgentRun(agentId, {
|
|
685
757
|
...resolution.customerTenant === void 0 ? {} : { customer_tenant: resolution.customerTenant },
|
|
758
|
+
...resolution.trustedContext === void 0 ? {} : { trusted_context: resolution.trustedContext },
|
|
686
759
|
...identity,
|
|
687
760
|
integration_id: integrationId,
|
|
688
761
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
@@ -694,6 +767,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
694
767
|
attachment_ids: attachmentIds,
|
|
695
768
|
...stringValue(body.requestedModelId) ? { requested_model_id: stringValue(body.requestedModelId) } : {},
|
|
696
769
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledge_namespaces: resolution.knowledgeNamespaces },
|
|
770
|
+
...body.requestedOutputs === void 0 ? {} : { requested_outputs: requestedOutputNames(body.requestedOutputs) },
|
|
697
771
|
tool_inputs: objectValue(body.toolInputs),
|
|
698
772
|
...body.metadata === void 0 ? {} : { metadata: objectValue(body.metadata) },
|
|
699
773
|
client: objectValue(body.client)
|
|
@@ -712,7 +786,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
712
786
|
client: objectValue(body.client),
|
|
713
787
|
cursor: 0
|
|
714
788
|
}, (event) => {
|
|
715
|
-
if (
|
|
789
|
+
if (runtimeEventEnabled(request, event)) return write(event);
|
|
716
790
|
}, { signal, onControl: control, leaseSeconds: 60, streamFeatures: url.searchParams.get("stream_features") || "", onPreview: (frame) => write(frame) });
|
|
717
791
|
}, {
|
|
718
792
|
"X-Run-ID": admittedRunId,
|
|
@@ -735,12 +809,13 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
735
809
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
736
810
|
...cursor === void 0 ? {} : { cursor: Number(cursor) }
|
|
737
811
|
}, (event) => {
|
|
738
|
-
if (
|
|
812
|
+
if (runtimeEventEnabled(request, event)) return write(event);
|
|
739
813
|
}, {
|
|
740
814
|
idempotencyKey,
|
|
741
815
|
signal,
|
|
742
816
|
onControl: control,
|
|
743
817
|
leaseSeconds: 60,
|
|
818
|
+
streamFeatures: url.searchParams.get("stream_features") || "",
|
|
744
819
|
...url.searchParams.get("thread_id") ? { threadId: url.searchParams.get("thread_id") } : {}
|
|
745
820
|
});
|
|
746
821
|
}, void 0, void 0, streamFailure(request, "run.attach"), request.signal);
|
|
@@ -827,7 +902,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
827
902
|
response = json(await embed.submitAgentThreadMessage(
|
|
828
903
|
agentId,
|
|
829
904
|
threadId,
|
|
830
|
-
{ ...threadIdentity, integrationId, ...messageBody(body), ...resolution.knowledgeNamespaces === void 0 ? {} : { knowledgeNamespaces: resolution.knowledgeNamespaces }, agentVersionId: agentVersionId ?? null },
|
|
905
|
+
{ ...threadIdentity, integrationId, ...messageBody(body), ...resolution.trustedContext === void 0 ? {} : { trustedContext: resolution.trustedContext }, ...resolution.customerTenant === void 0 ? {} : { customerTenant: resolution.customerTenant }, ...resolution.knowledgeNamespaces === void 0 ? {} : { knowledgeNamespaces: resolution.knowledgeNamespaces }, agentVersionId: agentVersionId ?? null },
|
|
831
906
|
{ idempotencyKey }
|
|
832
907
|
));
|
|
833
908
|
} else if (/^\/threads\/[^/]+\/messages\/[^/]+$/.test(path) && request.method === "PATCH") {
|
|
@@ -1008,6 +1083,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
1008
1083
|
|
|
1009
1084
|
// src/bff-multi-agent.ts
|
|
1010
1085
|
function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
1086
|
+
const historical = new Set(options.readOnlyAgentIds || []);
|
|
1011
1087
|
const runtimeTarget = options.runtimeTarget || "published";
|
|
1012
1088
|
const basePath = normalizeBasePath(options.basePath);
|
|
1013
1089
|
const integrationId = normalized(options.integrationId, "integrationId");
|
|
@@ -1065,6 +1141,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1065
1141
|
}
|
|
1066
1142
|
try {
|
|
1067
1143
|
const externalUserId = await resolveCustomerIdentity(resolution.principal);
|
|
1144
|
+
await guardHistoricalRequest({ request, path, historical, agentIds: agents.map((row) => row.agentId), embed: options.client.embed, resolution, externalUserId, integrationId, runtimeTarget });
|
|
1068
1145
|
await options.onPrincipalResolved?.(request, resolution, externalUserId);
|
|
1069
1146
|
const identity = {
|
|
1070
1147
|
external_user_id: externalUserId,
|
|
@@ -1118,21 +1195,27 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1118
1195
|
});
|
|
1119
1196
|
return (await requestedAgent(detail.runtime_selection?.agent_id)).agentId;
|
|
1120
1197
|
};
|
|
1198
|
+
if (request.method === "GET" && /^\/runs\/[^/]+\/outputs(?:\/[^/]+)?$/.test(path)) {
|
|
1199
|
+
const runId = routeId(path, /^\/runs\/([^/]+)\/outputs/, "runId");
|
|
1200
|
+
return dispatchToAgent(await resolveRunAgent(runId));
|
|
1201
|
+
}
|
|
1121
1202
|
if (request.method === "POST" && path === "/chat/stream") {
|
|
1122
1203
|
const body = await requestJson(request);
|
|
1123
1204
|
const threadId = stringValue(body.threadId);
|
|
1205
|
+
if (threadId && body.requestedAgentId) assertWritableAgent((await requestedAgent(body.requestedAgentId)).agentId, historical);
|
|
1124
1206
|
if (threadId) return submitConversationStream({
|
|
1125
1207
|
options,
|
|
1126
1208
|
request,
|
|
1127
1209
|
body,
|
|
1128
1210
|
resolution,
|
|
1129
|
-
agents,
|
|
1211
|
+
agents: agents.filter((agent) => !historical.has(agent.agentId)),
|
|
1130
1212
|
identity,
|
|
1131
1213
|
integrationId,
|
|
1132
1214
|
runtimeTarget,
|
|
1133
1215
|
requestedAgentId: body.requestedAgentId ? (await requestedAgent(body.requestedAgentId)).agentId : void 0
|
|
1134
1216
|
});
|
|
1135
1217
|
const selected = await requestedAgent(body.requestedAgentId);
|
|
1218
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1136
1219
|
const input = stringValue(body.input);
|
|
1137
1220
|
const attachmentIds = stringList(body.attachmentIds);
|
|
1138
1221
|
if (!input && attachmentIds.length === 0) throw new BffInputError(400, "INPUT_REQUIRED", "A message or attachment is required.");
|
|
@@ -1150,6 +1233,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1150
1233
|
client_submission_id: stringValue(body.clientSubmissionId),
|
|
1151
1234
|
...body.relayClientId === null ? { relay_client_id: null } : stringValue(body.relayClientId) ? { relay_client_id: stringValue(body.relayClientId) } : {},
|
|
1152
1235
|
attachment_ids: attachmentIds,
|
|
1236
|
+
...body.requestedOutputs === void 0 ? {} : { requested_outputs: requestedOutputNames(body.requestedOutputs) },
|
|
1153
1237
|
...stringValue(body.requestedModelId) ? { requested_model_id: stringValue(body.requestedModelId) } : {},
|
|
1154
1238
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledge_namespaces: resolution.knowledgeNamespaces },
|
|
1155
1239
|
tool_inputs: objectValue(body.toolInputs),
|
|
@@ -1168,7 +1252,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1168
1252
|
client: objectValue(body.client),
|
|
1169
1253
|
cursor: 0
|
|
1170
1254
|
}, (event) => {
|
|
1171
|
-
if (
|
|
1255
|
+
if (runtimeEventEnabled(request, event)) return write(event);
|
|
1172
1256
|
}, { signal, onControl: control, leaseSeconds: 60, streamFeatures: url.searchParams.get("stream_features") || "", onPreview: (frame) => write(frame) });
|
|
1173
1257
|
}, {
|
|
1174
1258
|
"X-Run-ID": admittedRunId,
|
|
@@ -1181,7 +1265,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1181
1265
|
if (!Number.isInteger(skip) || skip < 0 || !Number.isInteger(limit) || limit < 1 || limit > 100) {
|
|
1182
1266
|
throw new BffInputError(400, "INVALID_PAGINATION", "skip must be non-negative and limit must be between 1 and 100.");
|
|
1183
1267
|
}
|
|
1184
|
-
return mergeHeaders(json(await options.client.embed.listAgentThreadsMulti({
|
|
1268
|
+
return mergeHeaders(json(historyProjection(await options.client.embed.listAgentThreadsMulti({
|
|
1185
1269
|
agent_ids: agents.map((agent) => agent.agentId),
|
|
1186
1270
|
external_user_id: externalUserId,
|
|
1187
1271
|
...resolution.principal.externalSessionId ? { external_session_id: resolution.principal.externalSessionId } : {},
|
|
@@ -1190,7 +1274,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1190
1274
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
1191
1275
|
skip,
|
|
1192
1276
|
limit
|
|
1193
|
-
})), resolution.responseHeaders);
|
|
1277
|
+
}), historical)), resolution.responseHeaders);
|
|
1194
1278
|
}
|
|
1195
1279
|
if (request.method === "GET" && path === "/threads/events") {
|
|
1196
1280
|
const rawCursor = url.searchParams.get("cursor");
|
|
@@ -1211,7 +1295,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1211
1295
|
onControl: control,
|
|
1212
1296
|
leaseSeconds: 60,
|
|
1213
1297
|
...url.searchParams.get("thread_id") ? { threadId: url.searchParams.get("thread_id") } : {}
|
|
1214
|
-
}, (event) => write(event));
|
|
1298
|
+
}, (event) => write(historyProjection(event, historical)));
|
|
1215
1299
|
}, void 0, () => ({
|
|
1216
1300
|
schema_version: "agents24.thread_summary_event.v1",
|
|
1217
1301
|
event: "snapshot_required",
|
|
@@ -1229,8 +1313,11 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1229
1313
|
if (/^\/threads\/[^/]+\/(?:messages(?:\/[^/]+)?|queue\/resume)$/.test(path) && ["GET", "POST", "PATCH", "DELETE"].includes(request.method)) {
|
|
1230
1314
|
const threadId = routeId(path, /^\/threads\/([^/]+)\//, "threadId");
|
|
1231
1315
|
const storedAgent = await resolveThreadAgent(threadId);
|
|
1316
|
+
if (request.method !== "GET") assertWritableAgent(storedAgent, historical);
|
|
1232
1317
|
const message = request.method === "PATCH" || request.method === "POST" && path.endsWith("/messages") ? await request.clone().json() : void 0;
|
|
1233
|
-
|
|
1318
|
+
const selected = (await requestedAgent(message?.requestedAgentId || storedAgent)).agentId;
|
|
1319
|
+
if (request.method !== "GET") assertWritableAgent(selected, historical);
|
|
1320
|
+
return dispatchToAgent(selected, message);
|
|
1234
1321
|
}
|
|
1235
1322
|
if (/^\/threads\/[^/]+\/computer(?:\/files|\/file|\/content-access)?$/.test(path) && (request.method === "GET" || request.method === "POST" && path.endsWith("/content-access"))) {
|
|
1236
1323
|
const threadId = routeId(path, /^\/threads\/([^/]+)\/computer/, "threadId");
|
|
@@ -1275,7 +1362,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1275
1362
|
if (detailLimit !== void 0 && (!Number.isInteger(detailLimit) || detailLimit < 1 || detailLimit > 100)) {
|
|
1276
1363
|
throw new BffInputError(400, "INVALID_PAGINATION", "limit must be between 1 and 100.");
|
|
1277
1364
|
}
|
|
1278
|
-
return mergeHeaders(json(await options.client.embed.getConversationThread(threadId, {
|
|
1365
|
+
return mergeHeaders(json(historyProjection(await options.client.embed.getConversationThread(threadId, {
|
|
1279
1366
|
agentIds: agents.map((agent) => agent.agentId),
|
|
1280
1367
|
externalUserId,
|
|
1281
1368
|
...resolution.principal.externalSessionId ? { externalSessionId: resolution.principal.externalSessionId } : {},
|
|
@@ -1284,12 +1371,13 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1284
1371
|
runtimeTarget,
|
|
1285
1372
|
beforeTurnIndex,
|
|
1286
1373
|
limit: detailLimit
|
|
1287
|
-
})), resolution.responseHeaders);
|
|
1374
|
+
}), historical)), resolution.responseHeaders);
|
|
1288
1375
|
}
|
|
1289
1376
|
if (/^\/threads\/[^/]+\/runtime-selection$/.test(path) && request.method === "PATCH") {
|
|
1290
1377
|
const threadId = routeId(path, /^\/threads\/([^/]+)\//, "threadId");
|
|
1291
1378
|
const body = await requestJson(request);
|
|
1292
1379
|
const selected = await requestedAgent(body.preferredAgentId);
|
|
1380
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1293
1381
|
return mergeHeaders(json(await options.client.embed.setConversationRuntimeSelection(threadId, {
|
|
1294
1382
|
agent_ids: agents.map((agent) => agent.agentId),
|
|
1295
1383
|
preferred_agent_id: selected.agentId,
|
|
@@ -1314,6 +1402,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1314
1402
|
if (request.method === "POST" && path === "/attachments/upload") {
|
|
1315
1403
|
const form = await requestMultipart(request.clone());
|
|
1316
1404
|
const selected = await requestedAgent(form.get("requested_agent_id"));
|
|
1405
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1317
1406
|
const policy = await options.client.embed.getResourcePolicy(selected.agentId, {
|
|
1318
1407
|
external_user_id: externalUserId,
|
|
1319
1408
|
integration_id: integrationId,
|
|
@@ -1324,7 +1413,22 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1324
1413
|
return dispatchToAgent(selected.agentId);
|
|
1325
1414
|
}
|
|
1326
1415
|
if (request.method === "POST" && /^\/attachments\/[^/]+\/content-access$/.test(path)) {
|
|
1327
|
-
|
|
1416
|
+
const body = await requestJson(request);
|
|
1417
|
+
if (body.disposition !== "inline" && body.disposition !== "attachment") throw new BffInputError(400, "INVALID_DISPOSITION", "Attachment disposition is invalid.");
|
|
1418
|
+
for (const [index, agent] of agents.entries()) {
|
|
1419
|
+
try {
|
|
1420
|
+
return mergeHeaders(json(await options.client.embed.createAttachmentContentAccess(agent.agentId, routeId(path, /^\/attachments\/([^/]+)\/content-access$/, "attachmentId"), {
|
|
1421
|
+
...identity,
|
|
1422
|
+
integration_id: integrationId,
|
|
1423
|
+
runtime_target: runtimeTarget,
|
|
1424
|
+
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
1425
|
+
disposition: body.disposition
|
|
1426
|
+
})), resolution.responseHeaders);
|
|
1427
|
+
} catch (error) {
|
|
1428
|
+
if (error.status !== 404 || index === agents.length - 1) throw error;
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
throw new BffInputError(404, "NOT_FOUND", "Attachment not found.");
|
|
1328
1432
|
}
|
|
1329
1433
|
if (/^\/runs\/[^/]+\/(?:attach|cancel|feedback)$/.test(path) || /^\/runs\/[^/]+\/hitl\/[^/]+\/resume$/.test(path) || /^\/runs\/[^/]+\/mcp\/servers\/[^/]+\/auth\/start$/.test(path)) {
|
|
1330
1434
|
const runId = routeId(path, /^\/runs\/([^/]+)\//, "runId");
|
|
@@ -1416,6 +1520,11 @@ async function runtimeBootstrap(options, request, identityResolver) {
|
|
|
1416
1520
|
// src/bff.ts
|
|
1417
1521
|
function createAgents24BffHandler(options) {
|
|
1418
1522
|
const resolveAgents = prepareAgents24BffAgentResolution(options);
|
|
1523
|
+
const resolveHistory = options.readOnlyAgents?.length ? prepareAgents24BffAgentResolution({ ...options, agents: options.readOnlyAgents }) : async () => [];
|
|
1524
|
+
const withHistory = async (agents) => {
|
|
1525
|
+
const history = await resolveHistory();
|
|
1526
|
+
return createResolvedAgents24BffHandler({ ...options, agents: [...agents, ...history], readOnlyAgentIds: history.map((row) => row.agentId) }, identity);
|
|
1527
|
+
};
|
|
1419
1528
|
const identity = createCustomerIdentityResolver(options.client.embed, options.integrationId, options.integrationName);
|
|
1420
1529
|
const basePath = normalizeBasePath(options.basePath);
|
|
1421
1530
|
let resolvedHandler;
|
|
@@ -1425,10 +1534,10 @@ function createAgents24BffHandler(options) {
|
|
|
1425
1534
|
if (request.method === "GET" && new URL(request.url).pathname === `${basePath}/bootstrap`) {
|
|
1426
1535
|
const { response, result } = await runtimeBootstrap(options, request, identity);
|
|
1427
1536
|
const agents = result.resolved_agents.map((row) => ({ agentId: row.agent_id, agentAlias: row.agent_alias, agentVersionId: row.agent_version_id || void 0 }));
|
|
1428
|
-
resolvedHandler = Promise.resolve(
|
|
1537
|
+
resolvedHandler = Promise.resolve(await withHistory(agents));
|
|
1429
1538
|
return response;
|
|
1430
1539
|
}
|
|
1431
|
-
resolvedHandler ||= resolveAgents().then(
|
|
1540
|
+
resolvedHandler ||= resolveAgents().then(withHistory);
|
|
1432
1541
|
return await (await resolvedHandler)(request);
|
|
1433
1542
|
} catch (error) {
|
|
1434
1543
|
resolvedHandler = void 0;
|