@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/dist/bff.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Agents24 } from './client-
|
|
1
|
+
import { A as Agents24 } from './client-CY0o68YO.cjs';
|
|
2
2
|
import '@agents24/client/protocol';
|
|
3
3
|
import '@agents24/client';
|
|
4
4
|
|
|
@@ -44,6 +44,8 @@ type Agents24BffAgent = Agents24BffAgentVersion & ({
|
|
|
44
44
|
interface Agents24BffHandlerOptions {
|
|
45
45
|
client: Pick<Agents24, "embed">;
|
|
46
46
|
agents: readonly Agents24BffAgent[];
|
|
47
|
+
/** Historical Agents are readable/deletable but never selectable for execution. */
|
|
48
|
+
readOnlyAgents?: readonly Agents24BffAgent[];
|
|
47
49
|
integrationId: string;
|
|
48
50
|
integrationName?: string;
|
|
49
51
|
runtimeTarget?: "draft" | "published";
|
package/dist/bff.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Agents24 } from './client-
|
|
1
|
+
import { A as Agents24 } from './client-CY0o68YO.js';
|
|
2
2
|
import '@agents24/client/protocol';
|
|
3
3
|
import '@agents24/client';
|
|
4
4
|
|
|
@@ -44,6 +44,8 @@ type Agents24BffAgent = Agents24BffAgentVersion & ({
|
|
|
44
44
|
interface Agents24BffHandlerOptions {
|
|
45
45
|
client: Pick<Agents24, "embed">;
|
|
46
46
|
agents: readonly Agents24BffAgent[];
|
|
47
|
+
/** Historical Agents are readable/deletable but never selectable for execution. */
|
|
48
|
+
readOnlyAgents?: readonly Agents24BffAgent[];
|
|
47
49
|
integrationId: string;
|
|
48
50
|
integrationName?: string;
|
|
49
51
|
runtimeTarget?: "draft" | "published";
|
package/dist/bff.js
CHANGED
|
@@ -187,6 +187,13 @@ function routeId(path, pattern, field) {
|
|
|
187
187
|
throw new BffInputError(400, "INVALID_PATH", `${field} is invalid.`);
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
|
+
function requestedOutputNames(value) {
|
|
191
|
+
if (value === void 0) return void 0;
|
|
192
|
+
if (!Array.isArray(value) || !value.every((name) => typeof name === "string")) {
|
|
193
|
+
throw new BffInputError(400, "INVALID_REQUESTED_OUTPUTS", "requestedOutputs must be a string array.");
|
|
194
|
+
}
|
|
195
|
+
return value;
|
|
196
|
+
}
|
|
190
197
|
function messageBody(body) {
|
|
191
198
|
const mode = body.mode === "steer" ? "steer" : body.mode === "queue" ? "queue" : null;
|
|
192
199
|
if (!mode) throw new BffInputError(400, "INVALID_MODE", "Message mode must be queue or steer.");
|
|
@@ -203,6 +210,7 @@ function messageBody(body) {
|
|
|
203
210
|
input,
|
|
204
211
|
attachmentIds,
|
|
205
212
|
...requestedModelId ? { requestedModelId } : {},
|
|
213
|
+
...body.requestedOutputs === void 0 ? {} : { requestedOutputs: requestedOutputNames(body.requestedOutputs) },
|
|
206
214
|
toolInputs: objectValue(body.toolInputs),
|
|
207
215
|
...body.metadata === void 0 ? {} : { metadata: objectValue(body.metadata) }
|
|
208
216
|
};
|
|
@@ -233,6 +241,48 @@ function computerFileQuery(url, requirePath) {
|
|
|
233
241
|
};
|
|
234
242
|
}
|
|
235
243
|
|
|
244
|
+
// src/bff-history.ts
|
|
245
|
+
function historyProjection(value, historical) {
|
|
246
|
+
const row = objectValue(value);
|
|
247
|
+
if (Array.isArray(row.items)) return { ...row, items: row.items.map((item) => historyProjection(item, historical)) };
|
|
248
|
+
if (row.thread) return { ...row, thread: historyProjection(row.thread, historical) };
|
|
249
|
+
if (row.runtime_selection) return { ...row, read_only: historical.has(String(objectValue(row.runtime_selection).agent_id)) };
|
|
250
|
+
return value;
|
|
251
|
+
}
|
|
252
|
+
function assertWritableAgent(agent, historical) {
|
|
253
|
+
if (historical.has(agent)) throw new BffInputError(409, "THREAD_READ_ONLY", "This conversation is read-only. Start a new chat.");
|
|
254
|
+
}
|
|
255
|
+
async function guardHistoricalRequest(input) {
|
|
256
|
+
const { request, path, historical } = input;
|
|
257
|
+
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;
|
|
258
|
+
let threadId = path.match(/^\/threads\/([^/]+)/)?.[1];
|
|
259
|
+
if (path === "/chat/stream") threadId = stringValue((await requestJson(request.clone())).threadId);
|
|
260
|
+
if (path === "/attachments/upload") threadId = stringValue((await requestMultipart(request.clone())).get("thread_id"));
|
|
261
|
+
const scope = {
|
|
262
|
+
externalUserId: input.externalUserId,
|
|
263
|
+
integrationId: input.integrationId,
|
|
264
|
+
externalSessionId: input.resolution.principal.externalSessionId,
|
|
265
|
+
chatScope: input.resolution.chatScope,
|
|
266
|
+
runtimeTarget: input.runtimeTarget
|
|
267
|
+
};
|
|
268
|
+
if (threadId) {
|
|
269
|
+
const thread = await input.embed.getConversationThread(decodeURIComponent(threadId), { ...scope, agentIds: input.agentIds });
|
|
270
|
+
assertWritableAgent(String(thread.runtime_selection.agent_id), historical);
|
|
271
|
+
}
|
|
272
|
+
const runId = path.match(/^\/runs\/([^/]+)/)?.[1];
|
|
273
|
+
if (runId) {
|
|
274
|
+
const run = await input.embed.resolveConversationRun(decodeURIComponent(runId), {
|
|
275
|
+
agent_ids: input.agentIds,
|
|
276
|
+
external_user_id: scope.externalUserId,
|
|
277
|
+
integration_id: scope.integrationId,
|
|
278
|
+
external_session_id: scope.externalSessionId,
|
|
279
|
+
chat_scope: scope.chatScope,
|
|
280
|
+
runtime_target: scope.runtimeTarget
|
|
281
|
+
});
|
|
282
|
+
assertWritableAgent(run.agent_id, historical);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
236
286
|
// src/bff-conversation-submission.ts
|
|
237
287
|
async function submitConversationStream(input) {
|
|
238
288
|
const { request, body, resolution } = input;
|
|
@@ -252,6 +302,7 @@ async function submitConversationStream(input) {
|
|
|
252
302
|
...resolution.customerTenant === void 0 ? {} : { customer_tenant: resolution.customerTenant },
|
|
253
303
|
...resolution.trustedContext === void 0 ? {} : { trusted_context: resolution.trustedContext },
|
|
254
304
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledge_namespaces: resolution.knowledgeNamespaces },
|
|
305
|
+
...value.requestedOutputs === void 0 ? {} : { requested_outputs: value.requestedOutputs },
|
|
255
306
|
tool_inputs: value.toolInputs,
|
|
256
307
|
metadata: objectValue(body.metadata)
|
|
257
308
|
}, {
|
|
@@ -550,6 +601,10 @@ function sseResponse(execute, headers, failurePayload, onFailure, requestSignal,
|
|
|
550
601
|
});
|
|
551
602
|
return new Response(stream, { headers: sseHeaders(headers) });
|
|
552
603
|
}
|
|
604
|
+
function runtimeEventEnabled(request, event) {
|
|
605
|
+
const feature = event.event === "assistant.completed" ? "assistant-completion-v1" : event.event.startsWith("workflow.output.") ? "workflow-outputs-v1" : null;
|
|
606
|
+
return feature === null || Boolean(new URL(request.url).searchParams.get("stream_features")?.split(",").includes(feature));
|
|
607
|
+
}
|
|
553
608
|
|
|
554
609
|
// src/bff-resolver.ts
|
|
555
610
|
var AgentBffResolverError = class extends Error {
|
|
@@ -639,6 +694,21 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
639
694
|
{ ...threadIdentity, integrationId }
|
|
640
695
|
), resolution.responseHeaders);
|
|
641
696
|
let response;
|
|
697
|
+
if (request.method === "GET" && /^\/runs\/[^/]+\/outputs(?:\/[^/]+)?$/.test(path)) {
|
|
698
|
+
const parts = path.split("/");
|
|
699
|
+
const scope = {
|
|
700
|
+
...threadIdentity,
|
|
701
|
+
integrationId,
|
|
702
|
+
runtimeTarget,
|
|
703
|
+
...resolution.chatScope === void 0 ? {} : { chatScope: resolution.chatScope }
|
|
704
|
+
};
|
|
705
|
+
const result = parts[4] ? await embed.getAgentRunOutput(agentId, decodeURIComponent(parts[2]), decodeURIComponent(parts[4]), scope) : await embed.listAgentRunOutputs(agentId, decodeURIComponent(parts[2]), {
|
|
706
|
+
...scope,
|
|
707
|
+
after: Number(url.searchParams.get("after") || 0),
|
|
708
|
+
limit: Number(url.searchParams.get("limit") || 50)
|
|
709
|
+
});
|
|
710
|
+
return mergeHeaders(json(result), resolution.responseHeaders);
|
|
711
|
+
}
|
|
642
712
|
if (request.method === "GET" && path === "/bootstrap") {
|
|
643
713
|
const raw = await embed.getRuntimeBootstrap(agentId, agentVersionId, runtimeTarget);
|
|
644
714
|
response = json(bootstrapDocument(raw, agentVersionId));
|
|
@@ -675,12 +745,15 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
675
745
|
input,
|
|
676
746
|
attachmentIds,
|
|
677
747
|
...resolution.customerTenant === void 0 ? {} : { customerTenant: resolution.customerTenant },
|
|
748
|
+
...resolution.trustedContext === void 0 ? {} : { trustedContext: resolution.trustedContext },
|
|
678
749
|
...stringValue(body.requestedModelId) ? { requestedModelId: stringValue(body.requestedModelId) } : {},
|
|
679
750
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledgeNamespaces: resolution.knowledgeNamespaces },
|
|
751
|
+
...body.requestedOutputs === void 0 ? {} : { requestedOutputs: requestedOutputNames(body.requestedOutputs) },
|
|
680
752
|
toolInputs: objectValue(body.toolInputs),
|
|
681
753
|
...body.metadata === void 0 ? {} : { metadata: objectValue(body.metadata) }
|
|
682
754
|
}, { idempotencyKey }) : await embed.startAgentRun(agentId, {
|
|
683
755
|
...resolution.customerTenant === void 0 ? {} : { customer_tenant: resolution.customerTenant },
|
|
756
|
+
...resolution.trustedContext === void 0 ? {} : { trusted_context: resolution.trustedContext },
|
|
684
757
|
...identity,
|
|
685
758
|
integration_id: integrationId,
|
|
686
759
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
@@ -692,6 +765,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
692
765
|
attachment_ids: attachmentIds,
|
|
693
766
|
...stringValue(body.requestedModelId) ? { requested_model_id: stringValue(body.requestedModelId) } : {},
|
|
694
767
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledge_namespaces: resolution.knowledgeNamespaces },
|
|
768
|
+
...body.requestedOutputs === void 0 ? {} : { requested_outputs: requestedOutputNames(body.requestedOutputs) },
|
|
695
769
|
tool_inputs: objectValue(body.toolInputs),
|
|
696
770
|
...body.metadata === void 0 ? {} : { metadata: objectValue(body.metadata) },
|
|
697
771
|
client: objectValue(body.client)
|
|
@@ -710,7 +784,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
710
784
|
client: objectValue(body.client),
|
|
711
785
|
cursor: 0
|
|
712
786
|
}, (event) => {
|
|
713
|
-
if (
|
|
787
|
+
if (runtimeEventEnabled(request, event)) return write(event);
|
|
714
788
|
}, { signal, onControl: control, leaseSeconds: 60, streamFeatures: url.searchParams.get("stream_features") || "", onPreview: (frame) => write(frame) });
|
|
715
789
|
}, {
|
|
716
790
|
"X-Run-ID": admittedRunId,
|
|
@@ -733,12 +807,13 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
733
807
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
734
808
|
...cursor === void 0 ? {} : { cursor: Number(cursor) }
|
|
735
809
|
}, (event) => {
|
|
736
|
-
if (
|
|
810
|
+
if (runtimeEventEnabled(request, event)) return write(event);
|
|
737
811
|
}, {
|
|
738
812
|
idempotencyKey,
|
|
739
813
|
signal,
|
|
740
814
|
onControl: control,
|
|
741
815
|
leaseSeconds: 60,
|
|
816
|
+
streamFeatures: url.searchParams.get("stream_features") || "",
|
|
742
817
|
...url.searchParams.get("thread_id") ? { threadId: url.searchParams.get("thread_id") } : {}
|
|
743
818
|
});
|
|
744
819
|
}, void 0, void 0, streamFailure(request, "run.attach"), request.signal);
|
|
@@ -825,7 +900,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
825
900
|
response = json(await embed.submitAgentThreadMessage(
|
|
826
901
|
agentId,
|
|
827
902
|
threadId,
|
|
828
|
-
{ ...threadIdentity, integrationId, ...messageBody(body), ...resolution.knowledgeNamespaces === void 0 ? {} : { knowledgeNamespaces: resolution.knowledgeNamespaces }, agentVersionId: agentVersionId ?? null },
|
|
903
|
+
{ ...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 },
|
|
829
904
|
{ idempotencyKey }
|
|
830
905
|
));
|
|
831
906
|
} else if (/^\/threads\/[^/]+\/messages\/[^/]+$/.test(path) && request.method === "PATCH") {
|
|
@@ -1006,6 +1081,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
1006
1081
|
|
|
1007
1082
|
// src/bff-multi-agent.ts
|
|
1008
1083
|
function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
1084
|
+
const historical = new Set(options.readOnlyAgentIds || []);
|
|
1009
1085
|
const runtimeTarget = options.runtimeTarget || "published";
|
|
1010
1086
|
const basePath = normalizeBasePath(options.basePath);
|
|
1011
1087
|
const integrationId = normalized(options.integrationId, "integrationId");
|
|
@@ -1063,6 +1139,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1063
1139
|
}
|
|
1064
1140
|
try {
|
|
1065
1141
|
const externalUserId = await resolveCustomerIdentity(resolution.principal);
|
|
1142
|
+
await guardHistoricalRequest({ request, path, historical, agentIds: agents.map((row) => row.agentId), embed: options.client.embed, resolution, externalUserId, integrationId, runtimeTarget });
|
|
1066
1143
|
await options.onPrincipalResolved?.(request, resolution, externalUserId);
|
|
1067
1144
|
const identity = {
|
|
1068
1145
|
external_user_id: externalUserId,
|
|
@@ -1116,21 +1193,27 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1116
1193
|
});
|
|
1117
1194
|
return (await requestedAgent(detail.runtime_selection?.agent_id)).agentId;
|
|
1118
1195
|
};
|
|
1196
|
+
if (request.method === "GET" && /^\/runs\/[^/]+\/outputs(?:\/[^/]+)?$/.test(path)) {
|
|
1197
|
+
const runId = routeId(path, /^\/runs\/([^/]+)\/outputs/, "runId");
|
|
1198
|
+
return dispatchToAgent(await resolveRunAgent(runId));
|
|
1199
|
+
}
|
|
1119
1200
|
if (request.method === "POST" && path === "/chat/stream") {
|
|
1120
1201
|
const body = await requestJson(request);
|
|
1121
1202
|
const threadId = stringValue(body.threadId);
|
|
1203
|
+
if (threadId && body.requestedAgentId) assertWritableAgent((await requestedAgent(body.requestedAgentId)).agentId, historical);
|
|
1122
1204
|
if (threadId) return submitConversationStream({
|
|
1123
1205
|
options,
|
|
1124
1206
|
request,
|
|
1125
1207
|
body,
|
|
1126
1208
|
resolution,
|
|
1127
|
-
agents,
|
|
1209
|
+
agents: agents.filter((agent) => !historical.has(agent.agentId)),
|
|
1128
1210
|
identity,
|
|
1129
1211
|
integrationId,
|
|
1130
1212
|
runtimeTarget,
|
|
1131
1213
|
requestedAgentId: body.requestedAgentId ? (await requestedAgent(body.requestedAgentId)).agentId : void 0
|
|
1132
1214
|
});
|
|
1133
1215
|
const selected = await requestedAgent(body.requestedAgentId);
|
|
1216
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1134
1217
|
const input = stringValue(body.input);
|
|
1135
1218
|
const attachmentIds = stringList(body.attachmentIds);
|
|
1136
1219
|
if (!input && attachmentIds.length === 0) throw new BffInputError(400, "INPUT_REQUIRED", "A message or attachment is required.");
|
|
@@ -1148,6 +1231,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1148
1231
|
client_submission_id: stringValue(body.clientSubmissionId),
|
|
1149
1232
|
...body.relayClientId === null ? { relay_client_id: null } : stringValue(body.relayClientId) ? { relay_client_id: stringValue(body.relayClientId) } : {},
|
|
1150
1233
|
attachment_ids: attachmentIds,
|
|
1234
|
+
...body.requestedOutputs === void 0 ? {} : { requested_outputs: requestedOutputNames(body.requestedOutputs) },
|
|
1151
1235
|
...stringValue(body.requestedModelId) ? { requested_model_id: stringValue(body.requestedModelId) } : {},
|
|
1152
1236
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledge_namespaces: resolution.knowledgeNamespaces },
|
|
1153
1237
|
tool_inputs: objectValue(body.toolInputs),
|
|
@@ -1166,7 +1250,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1166
1250
|
client: objectValue(body.client),
|
|
1167
1251
|
cursor: 0
|
|
1168
1252
|
}, (event) => {
|
|
1169
|
-
if (
|
|
1253
|
+
if (runtimeEventEnabled(request, event)) return write(event);
|
|
1170
1254
|
}, { signal, onControl: control, leaseSeconds: 60, streamFeatures: url.searchParams.get("stream_features") || "", onPreview: (frame) => write(frame) });
|
|
1171
1255
|
}, {
|
|
1172
1256
|
"X-Run-ID": admittedRunId,
|
|
@@ -1179,7 +1263,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1179
1263
|
if (!Number.isInteger(skip) || skip < 0 || !Number.isInteger(limit) || limit < 1 || limit > 100) {
|
|
1180
1264
|
throw new BffInputError(400, "INVALID_PAGINATION", "skip must be non-negative and limit must be between 1 and 100.");
|
|
1181
1265
|
}
|
|
1182
|
-
return mergeHeaders(json(await options.client.embed.listAgentThreadsMulti({
|
|
1266
|
+
return mergeHeaders(json(historyProjection(await options.client.embed.listAgentThreadsMulti({
|
|
1183
1267
|
agent_ids: agents.map((agent) => agent.agentId),
|
|
1184
1268
|
external_user_id: externalUserId,
|
|
1185
1269
|
...resolution.principal.externalSessionId ? { external_session_id: resolution.principal.externalSessionId } : {},
|
|
@@ -1188,7 +1272,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1188
1272
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
1189
1273
|
skip,
|
|
1190
1274
|
limit
|
|
1191
|
-
})), resolution.responseHeaders);
|
|
1275
|
+
}), historical)), resolution.responseHeaders);
|
|
1192
1276
|
}
|
|
1193
1277
|
if (request.method === "GET" && path === "/threads/events") {
|
|
1194
1278
|
const rawCursor = url.searchParams.get("cursor");
|
|
@@ -1209,7 +1293,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1209
1293
|
onControl: control,
|
|
1210
1294
|
leaseSeconds: 60,
|
|
1211
1295
|
...url.searchParams.get("thread_id") ? { threadId: url.searchParams.get("thread_id") } : {}
|
|
1212
|
-
}, (event) => write(event));
|
|
1296
|
+
}, (event) => write(historyProjection(event, historical)));
|
|
1213
1297
|
}, void 0, () => ({
|
|
1214
1298
|
schema_version: "agents24.thread_summary_event.v1",
|
|
1215
1299
|
event: "snapshot_required",
|
|
@@ -1227,8 +1311,11 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1227
1311
|
if (/^\/threads\/[^/]+\/(?:messages(?:\/[^/]+)?|queue\/resume)$/.test(path) && ["GET", "POST", "PATCH", "DELETE"].includes(request.method)) {
|
|
1228
1312
|
const threadId = routeId(path, /^\/threads\/([^/]+)\//, "threadId");
|
|
1229
1313
|
const storedAgent = await resolveThreadAgent(threadId);
|
|
1314
|
+
if (request.method !== "GET") assertWritableAgent(storedAgent, historical);
|
|
1230
1315
|
const message = request.method === "PATCH" || request.method === "POST" && path.endsWith("/messages") ? await request.clone().json() : void 0;
|
|
1231
|
-
|
|
1316
|
+
const selected = (await requestedAgent(message?.requestedAgentId || storedAgent)).agentId;
|
|
1317
|
+
if (request.method !== "GET") assertWritableAgent(selected, historical);
|
|
1318
|
+
return dispatchToAgent(selected, message);
|
|
1232
1319
|
}
|
|
1233
1320
|
if (/^\/threads\/[^/]+\/computer(?:\/files|\/file|\/content-access)?$/.test(path) && (request.method === "GET" || request.method === "POST" && path.endsWith("/content-access"))) {
|
|
1234
1321
|
const threadId = routeId(path, /^\/threads\/([^/]+)\/computer/, "threadId");
|
|
@@ -1273,7 +1360,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1273
1360
|
if (detailLimit !== void 0 && (!Number.isInteger(detailLimit) || detailLimit < 1 || detailLimit > 100)) {
|
|
1274
1361
|
throw new BffInputError(400, "INVALID_PAGINATION", "limit must be between 1 and 100.");
|
|
1275
1362
|
}
|
|
1276
|
-
return mergeHeaders(json(await options.client.embed.getConversationThread(threadId, {
|
|
1363
|
+
return mergeHeaders(json(historyProjection(await options.client.embed.getConversationThread(threadId, {
|
|
1277
1364
|
agentIds: agents.map((agent) => agent.agentId),
|
|
1278
1365
|
externalUserId,
|
|
1279
1366
|
...resolution.principal.externalSessionId ? { externalSessionId: resolution.principal.externalSessionId } : {},
|
|
@@ -1282,12 +1369,13 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1282
1369
|
runtimeTarget,
|
|
1283
1370
|
beforeTurnIndex,
|
|
1284
1371
|
limit: detailLimit
|
|
1285
|
-
})), resolution.responseHeaders);
|
|
1372
|
+
}), historical)), resolution.responseHeaders);
|
|
1286
1373
|
}
|
|
1287
1374
|
if (/^\/threads\/[^/]+\/runtime-selection$/.test(path) && request.method === "PATCH") {
|
|
1288
1375
|
const threadId = routeId(path, /^\/threads\/([^/]+)\//, "threadId");
|
|
1289
1376
|
const body = await requestJson(request);
|
|
1290
1377
|
const selected = await requestedAgent(body.preferredAgentId);
|
|
1378
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1291
1379
|
return mergeHeaders(json(await options.client.embed.setConversationRuntimeSelection(threadId, {
|
|
1292
1380
|
agent_ids: agents.map((agent) => agent.agentId),
|
|
1293
1381
|
preferred_agent_id: selected.agentId,
|
|
@@ -1312,6 +1400,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1312
1400
|
if (request.method === "POST" && path === "/attachments/upload") {
|
|
1313
1401
|
const form = await requestMultipart(request.clone());
|
|
1314
1402
|
const selected = await requestedAgent(form.get("requested_agent_id"));
|
|
1403
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1315
1404
|
const policy = await options.client.embed.getResourcePolicy(selected.agentId, {
|
|
1316
1405
|
external_user_id: externalUserId,
|
|
1317
1406
|
integration_id: integrationId,
|
|
@@ -1322,7 +1411,22 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1322
1411
|
return dispatchToAgent(selected.agentId);
|
|
1323
1412
|
}
|
|
1324
1413
|
if (request.method === "POST" && /^\/attachments\/[^/]+\/content-access$/.test(path)) {
|
|
1325
|
-
|
|
1414
|
+
const body = await requestJson(request);
|
|
1415
|
+
if (body.disposition !== "inline" && body.disposition !== "attachment") throw new BffInputError(400, "INVALID_DISPOSITION", "Attachment disposition is invalid.");
|
|
1416
|
+
for (const [index, agent] of agents.entries()) {
|
|
1417
|
+
try {
|
|
1418
|
+
return mergeHeaders(json(await options.client.embed.createAttachmentContentAccess(agent.agentId, routeId(path, /^\/attachments\/([^/]+)\/content-access$/, "attachmentId"), {
|
|
1419
|
+
...identity,
|
|
1420
|
+
integration_id: integrationId,
|
|
1421
|
+
runtime_target: runtimeTarget,
|
|
1422
|
+
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
1423
|
+
disposition: body.disposition
|
|
1424
|
+
})), resolution.responseHeaders);
|
|
1425
|
+
} catch (error) {
|
|
1426
|
+
if (error.status !== 404 || index === agents.length - 1) throw error;
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
throw new BffInputError(404, "NOT_FOUND", "Attachment not found.");
|
|
1326
1430
|
}
|
|
1327
1431
|
if (/^\/runs\/[^/]+\/(?:attach|cancel|feedback)$/.test(path) || /^\/runs\/[^/]+\/hitl\/[^/]+\/resume$/.test(path) || /^\/runs\/[^/]+\/mcp\/servers\/[^/]+\/auth\/start$/.test(path)) {
|
|
1328
1432
|
const runId = routeId(path, /^\/runs\/([^/]+)\//, "runId");
|
|
@@ -1414,6 +1518,11 @@ async function runtimeBootstrap(options, request, identityResolver) {
|
|
|
1414
1518
|
// src/bff.ts
|
|
1415
1519
|
function createAgents24BffHandler(options) {
|
|
1416
1520
|
const resolveAgents = prepareAgents24BffAgentResolution(options);
|
|
1521
|
+
const resolveHistory = options.readOnlyAgents?.length ? prepareAgents24BffAgentResolution({ ...options, agents: options.readOnlyAgents }) : async () => [];
|
|
1522
|
+
const withHistory = async (agents) => {
|
|
1523
|
+
const history = await resolveHistory();
|
|
1524
|
+
return createResolvedAgents24BffHandler({ ...options, agents: [...agents, ...history], readOnlyAgentIds: history.map((row) => row.agentId) }, identity);
|
|
1525
|
+
};
|
|
1417
1526
|
const identity = createCustomerIdentityResolver(options.client.embed, options.integrationId, options.integrationName);
|
|
1418
1527
|
const basePath = normalizeBasePath(options.basePath);
|
|
1419
1528
|
let resolvedHandler;
|
|
@@ -1423,10 +1532,10 @@ function createAgents24BffHandler(options) {
|
|
|
1423
1532
|
if (request.method === "GET" && new URL(request.url).pathname === `${basePath}/bootstrap`) {
|
|
1424
1533
|
const { response, result } = await runtimeBootstrap(options, request, identity);
|
|
1425
1534
|
const agents = result.resolved_agents.map((row) => ({ agentId: row.agent_id, agentAlias: row.agent_alias, agentVersionId: row.agent_version_id || void 0 }));
|
|
1426
|
-
resolvedHandler = Promise.resolve(
|
|
1535
|
+
resolvedHandler = Promise.resolve(await withHistory(agents));
|
|
1427
1536
|
return response;
|
|
1428
1537
|
}
|
|
1429
|
-
resolvedHandler ||= resolveAgents().then(
|
|
1538
|
+
resolvedHandler ||= resolveAgents().then(withHistory);
|
|
1430
1539
|
return await (await resolvedHandler)(request);
|
|
1431
1540
|
} catch (error) {
|
|
1432
1541
|
resolvedHandler = void 0;
|