@agents24/node 0.5.32 → 0.5.33
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/bff.cjs +84 -11
- 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 +84 -11
- package/dist/bff.js.map +1 -1
- package/dist/{client-BhE-CjMz.d.cts → client-IX8nsoyr.d.cts} +1 -0
- package/dist/{client-BhE-CjMz.d.ts → client-IX8nsoyr.d.ts} +1 -0
- package/dist/index.cjs +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -0
- package/dist/index.js.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-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-single-agent.d.ts.map +1 -1
- package/dist/types/bff.d.ts.map +1 -1
- package/dist/types/embed-types.d.ts +1 -0
- package/dist/types/embed-types.d.ts.map +1 -1
- package/dist/types/embed.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-IX8nsoyr.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-IX8nsoyr.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
|
@@ -233,6 +233,48 @@ function computerFileQuery(url, requirePath) {
|
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
235
|
|
|
236
|
+
// src/bff-history.ts
|
|
237
|
+
function historyProjection(value, historical) {
|
|
238
|
+
const row = objectValue(value);
|
|
239
|
+
if (Array.isArray(row.items)) return { ...row, items: row.items.map((item) => historyProjection(item, historical)) };
|
|
240
|
+
if (row.thread) return { ...row, thread: historyProjection(row.thread, historical) };
|
|
241
|
+
if (row.runtime_selection) return { ...row, read_only: historical.has(String(objectValue(row.runtime_selection).agent_id)) };
|
|
242
|
+
return value;
|
|
243
|
+
}
|
|
244
|
+
function assertWritableAgent(agent, historical) {
|
|
245
|
+
if (historical.has(agent)) throw new BffInputError(409, "THREAD_READ_ONLY", "This conversation is read-only. Start a new chat.");
|
|
246
|
+
}
|
|
247
|
+
async function guardHistoricalRequest(input) {
|
|
248
|
+
const { request, path, historical } = input;
|
|
249
|
+
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;
|
|
250
|
+
let threadId = path.match(/^\/threads\/([^/]+)/)?.[1];
|
|
251
|
+
if (path === "/chat/stream") threadId = stringValue((await requestJson(request.clone())).threadId);
|
|
252
|
+
if (path === "/attachments/upload") threadId = stringValue((await requestMultipart(request.clone())).get("thread_id"));
|
|
253
|
+
const scope = {
|
|
254
|
+
externalUserId: input.externalUserId,
|
|
255
|
+
integrationId: input.integrationId,
|
|
256
|
+
externalSessionId: input.resolution.principal.externalSessionId,
|
|
257
|
+
chatScope: input.resolution.chatScope,
|
|
258
|
+
runtimeTarget: input.runtimeTarget
|
|
259
|
+
};
|
|
260
|
+
if (threadId) {
|
|
261
|
+
const thread = await input.embed.getConversationThread(decodeURIComponent(threadId), { ...scope, agentIds: input.agentIds });
|
|
262
|
+
assertWritableAgent(String(thread.runtime_selection.agent_id), historical);
|
|
263
|
+
}
|
|
264
|
+
const runId = path.match(/^\/runs\/([^/]+)/)?.[1];
|
|
265
|
+
if (runId) {
|
|
266
|
+
const run = await input.embed.resolveConversationRun(decodeURIComponent(runId), {
|
|
267
|
+
agent_ids: input.agentIds,
|
|
268
|
+
external_user_id: scope.externalUserId,
|
|
269
|
+
integration_id: scope.integrationId,
|
|
270
|
+
external_session_id: scope.externalSessionId,
|
|
271
|
+
chat_scope: scope.chatScope,
|
|
272
|
+
runtime_target: scope.runtimeTarget
|
|
273
|
+
});
|
|
274
|
+
assertWritableAgent(run.agent_id, historical);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
236
278
|
// src/bff-conversation-submission.ts
|
|
237
279
|
async function submitConversationStream(input) {
|
|
238
280
|
const { request, body, resolution } = input;
|
|
@@ -675,12 +717,14 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
675
717
|
input,
|
|
676
718
|
attachmentIds,
|
|
677
719
|
...resolution.customerTenant === void 0 ? {} : { customerTenant: resolution.customerTenant },
|
|
720
|
+
...resolution.trustedContext === void 0 ? {} : { trustedContext: resolution.trustedContext },
|
|
678
721
|
...stringValue(body.requestedModelId) ? { requestedModelId: stringValue(body.requestedModelId) } : {},
|
|
679
722
|
...resolution.knowledgeNamespaces === void 0 ? {} : { knowledgeNamespaces: resolution.knowledgeNamespaces },
|
|
680
723
|
toolInputs: objectValue(body.toolInputs),
|
|
681
724
|
...body.metadata === void 0 ? {} : { metadata: objectValue(body.metadata) }
|
|
682
725
|
}, { idempotencyKey }) : await embed.startAgentRun(agentId, {
|
|
683
726
|
...resolution.customerTenant === void 0 ? {} : { customer_tenant: resolution.customerTenant },
|
|
727
|
+
...resolution.trustedContext === void 0 ? {} : { trusted_context: resolution.trustedContext },
|
|
684
728
|
...identity,
|
|
685
729
|
integration_id: integrationId,
|
|
686
730
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
@@ -825,7 +869,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
825
869
|
response = json(await embed.submitAgentThreadMessage(
|
|
826
870
|
agentId,
|
|
827
871
|
threadId,
|
|
828
|
-
{ ...threadIdentity, integrationId, ...messageBody(body), ...resolution.knowledgeNamespaces === void 0 ? {} : { knowledgeNamespaces: resolution.knowledgeNamespaces }, agentVersionId: agentVersionId ?? null },
|
|
872
|
+
{ ...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
873
|
{ idempotencyKey }
|
|
830
874
|
));
|
|
831
875
|
} else if (/^\/threads\/[^/]+\/messages\/[^/]+$/.test(path) && request.method === "PATCH") {
|
|
@@ -1006,6 +1050,7 @@ function createAgents24BffHandlerWithResolver(options, resolveCustomerIdentity)
|
|
|
1006
1050
|
|
|
1007
1051
|
// src/bff-multi-agent.ts
|
|
1008
1052
|
function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
1053
|
+
const historical = new Set(options.readOnlyAgentIds || []);
|
|
1009
1054
|
const runtimeTarget = options.runtimeTarget || "published";
|
|
1010
1055
|
const basePath = normalizeBasePath(options.basePath);
|
|
1011
1056
|
const integrationId = normalized(options.integrationId, "integrationId");
|
|
@@ -1063,6 +1108,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1063
1108
|
}
|
|
1064
1109
|
try {
|
|
1065
1110
|
const externalUserId = await resolveCustomerIdentity(resolution.principal);
|
|
1111
|
+
await guardHistoricalRequest({ request, path, historical, agentIds: agents.map((row) => row.agentId), embed: options.client.embed, resolution, externalUserId, integrationId, runtimeTarget });
|
|
1066
1112
|
await options.onPrincipalResolved?.(request, resolution, externalUserId);
|
|
1067
1113
|
const identity = {
|
|
1068
1114
|
external_user_id: externalUserId,
|
|
@@ -1119,18 +1165,20 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1119
1165
|
if (request.method === "POST" && path === "/chat/stream") {
|
|
1120
1166
|
const body = await requestJson(request);
|
|
1121
1167
|
const threadId = stringValue(body.threadId);
|
|
1168
|
+
if (threadId && body.requestedAgentId) assertWritableAgent((await requestedAgent(body.requestedAgentId)).agentId, historical);
|
|
1122
1169
|
if (threadId) return submitConversationStream({
|
|
1123
1170
|
options,
|
|
1124
1171
|
request,
|
|
1125
1172
|
body,
|
|
1126
1173
|
resolution,
|
|
1127
|
-
agents,
|
|
1174
|
+
agents: agents.filter((agent) => !historical.has(agent.agentId)),
|
|
1128
1175
|
identity,
|
|
1129
1176
|
integrationId,
|
|
1130
1177
|
runtimeTarget,
|
|
1131
1178
|
requestedAgentId: body.requestedAgentId ? (await requestedAgent(body.requestedAgentId)).agentId : void 0
|
|
1132
1179
|
});
|
|
1133
1180
|
const selected = await requestedAgent(body.requestedAgentId);
|
|
1181
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1134
1182
|
const input = stringValue(body.input);
|
|
1135
1183
|
const attachmentIds = stringList(body.attachmentIds);
|
|
1136
1184
|
if (!input && attachmentIds.length === 0) throw new BffInputError(400, "INPUT_REQUIRED", "A message or attachment is required.");
|
|
@@ -1179,7 +1227,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1179
1227
|
if (!Number.isInteger(skip) || skip < 0 || !Number.isInteger(limit) || limit < 1 || limit > 100) {
|
|
1180
1228
|
throw new BffInputError(400, "INVALID_PAGINATION", "skip must be non-negative and limit must be between 1 and 100.");
|
|
1181
1229
|
}
|
|
1182
|
-
return mergeHeaders(json(await options.client.embed.listAgentThreadsMulti({
|
|
1230
|
+
return mergeHeaders(json(historyProjection(await options.client.embed.listAgentThreadsMulti({
|
|
1183
1231
|
agent_ids: agents.map((agent) => agent.agentId),
|
|
1184
1232
|
external_user_id: externalUserId,
|
|
1185
1233
|
...resolution.principal.externalSessionId ? { external_session_id: resolution.principal.externalSessionId } : {},
|
|
@@ -1188,7 +1236,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1188
1236
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
1189
1237
|
skip,
|
|
1190
1238
|
limit
|
|
1191
|
-
})), resolution.responseHeaders);
|
|
1239
|
+
}), historical)), resolution.responseHeaders);
|
|
1192
1240
|
}
|
|
1193
1241
|
if (request.method === "GET" && path === "/threads/events") {
|
|
1194
1242
|
const rawCursor = url.searchParams.get("cursor");
|
|
@@ -1209,7 +1257,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1209
1257
|
onControl: control,
|
|
1210
1258
|
leaseSeconds: 60,
|
|
1211
1259
|
...url.searchParams.get("thread_id") ? { threadId: url.searchParams.get("thread_id") } : {}
|
|
1212
|
-
}, (event) => write(event));
|
|
1260
|
+
}, (event) => write(historyProjection(event, historical)));
|
|
1213
1261
|
}, void 0, () => ({
|
|
1214
1262
|
schema_version: "agents24.thread_summary_event.v1",
|
|
1215
1263
|
event: "snapshot_required",
|
|
@@ -1227,8 +1275,11 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1227
1275
|
if (/^\/threads\/[^/]+\/(?:messages(?:\/[^/]+)?|queue\/resume)$/.test(path) && ["GET", "POST", "PATCH", "DELETE"].includes(request.method)) {
|
|
1228
1276
|
const threadId = routeId(path, /^\/threads\/([^/]+)\//, "threadId");
|
|
1229
1277
|
const storedAgent = await resolveThreadAgent(threadId);
|
|
1278
|
+
if (request.method !== "GET") assertWritableAgent(storedAgent, historical);
|
|
1230
1279
|
const message = request.method === "PATCH" || request.method === "POST" && path.endsWith("/messages") ? await request.clone().json() : void 0;
|
|
1231
|
-
|
|
1280
|
+
const selected = (await requestedAgent(message?.requestedAgentId || storedAgent)).agentId;
|
|
1281
|
+
if (request.method !== "GET") assertWritableAgent(selected, historical);
|
|
1282
|
+
return dispatchToAgent(selected, message);
|
|
1232
1283
|
}
|
|
1233
1284
|
if (/^\/threads\/[^/]+\/computer(?:\/files|\/file|\/content-access)?$/.test(path) && (request.method === "GET" || request.method === "POST" && path.endsWith("/content-access"))) {
|
|
1234
1285
|
const threadId = routeId(path, /^\/threads\/([^/]+)\/computer/, "threadId");
|
|
@@ -1273,7 +1324,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1273
1324
|
if (detailLimit !== void 0 && (!Number.isInteger(detailLimit) || detailLimit < 1 || detailLimit > 100)) {
|
|
1274
1325
|
throw new BffInputError(400, "INVALID_PAGINATION", "limit must be between 1 and 100.");
|
|
1275
1326
|
}
|
|
1276
|
-
return mergeHeaders(json(await options.client.embed.getConversationThread(threadId, {
|
|
1327
|
+
return mergeHeaders(json(historyProjection(await options.client.embed.getConversationThread(threadId, {
|
|
1277
1328
|
agentIds: agents.map((agent) => agent.agentId),
|
|
1278
1329
|
externalUserId,
|
|
1279
1330
|
...resolution.principal.externalSessionId ? { externalSessionId: resolution.principal.externalSessionId } : {},
|
|
@@ -1282,12 +1333,13 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1282
1333
|
runtimeTarget,
|
|
1283
1334
|
beforeTurnIndex,
|
|
1284
1335
|
limit: detailLimit
|
|
1285
|
-
})), resolution.responseHeaders);
|
|
1336
|
+
}), historical)), resolution.responseHeaders);
|
|
1286
1337
|
}
|
|
1287
1338
|
if (/^\/threads\/[^/]+\/runtime-selection$/.test(path) && request.method === "PATCH") {
|
|
1288
1339
|
const threadId = routeId(path, /^\/threads\/([^/]+)\//, "threadId");
|
|
1289
1340
|
const body = await requestJson(request);
|
|
1290
1341
|
const selected = await requestedAgent(body.preferredAgentId);
|
|
1342
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1291
1343
|
return mergeHeaders(json(await options.client.embed.setConversationRuntimeSelection(threadId, {
|
|
1292
1344
|
agent_ids: agents.map((agent) => agent.agentId),
|
|
1293
1345
|
preferred_agent_id: selected.agentId,
|
|
@@ -1312,6 +1364,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1312
1364
|
if (request.method === "POST" && path === "/attachments/upload") {
|
|
1313
1365
|
const form = await requestMultipart(request.clone());
|
|
1314
1366
|
const selected = await requestedAgent(form.get("requested_agent_id"));
|
|
1367
|
+
assertWritableAgent(selected.agentId, historical);
|
|
1315
1368
|
const policy = await options.client.embed.getResourcePolicy(selected.agentId, {
|
|
1316
1369
|
external_user_id: externalUserId,
|
|
1317
1370
|
integration_id: integrationId,
|
|
@@ -1322,7 +1375,22 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1322
1375
|
return dispatchToAgent(selected.agentId);
|
|
1323
1376
|
}
|
|
1324
1377
|
if (request.method === "POST" && /^\/attachments\/[^/]+\/content-access$/.test(path)) {
|
|
1325
|
-
|
|
1378
|
+
const body = await requestJson(request);
|
|
1379
|
+
if (body.disposition !== "inline" && body.disposition !== "attachment") throw new BffInputError(400, "INVALID_DISPOSITION", "Attachment disposition is invalid.");
|
|
1380
|
+
for (const [index, agent] of agents.entries()) {
|
|
1381
|
+
try {
|
|
1382
|
+
return mergeHeaders(json(await options.client.embed.createAttachmentContentAccess(agent.agentId, routeId(path, /^\/attachments\/([^/]+)\/content-access$/, "attachmentId"), {
|
|
1383
|
+
...identity,
|
|
1384
|
+
integration_id: integrationId,
|
|
1385
|
+
runtime_target: runtimeTarget,
|
|
1386
|
+
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
1387
|
+
disposition: body.disposition
|
|
1388
|
+
})), resolution.responseHeaders);
|
|
1389
|
+
} catch (error) {
|
|
1390
|
+
if (error.status !== 404 || index === agents.length - 1) throw error;
|
|
1391
|
+
}
|
|
1392
|
+
}
|
|
1393
|
+
throw new BffInputError(404, "NOT_FOUND", "Attachment not found.");
|
|
1326
1394
|
}
|
|
1327
1395
|
if (/^\/runs\/[^/]+\/(?:attach|cancel|feedback)$/.test(path) || /^\/runs\/[^/]+\/hitl\/[^/]+\/resume$/.test(path) || /^\/runs\/[^/]+\/mcp\/servers\/[^/]+\/auth\/start$/.test(path)) {
|
|
1328
1396
|
const runId = routeId(path, /^\/runs\/([^/]+)\//, "runId");
|
|
@@ -1414,6 +1482,11 @@ async function runtimeBootstrap(options, request, identityResolver) {
|
|
|
1414
1482
|
// src/bff.ts
|
|
1415
1483
|
function createAgents24BffHandler(options) {
|
|
1416
1484
|
const resolveAgents = prepareAgents24BffAgentResolution(options);
|
|
1485
|
+
const resolveHistory = options.readOnlyAgents?.length ? prepareAgents24BffAgentResolution({ ...options, agents: options.readOnlyAgents }) : async () => [];
|
|
1486
|
+
const withHistory = async (agents) => {
|
|
1487
|
+
const history = await resolveHistory();
|
|
1488
|
+
return createResolvedAgents24BffHandler({ ...options, agents: [...agents, ...history], readOnlyAgentIds: history.map((row) => row.agentId) }, identity);
|
|
1489
|
+
};
|
|
1417
1490
|
const identity = createCustomerIdentityResolver(options.client.embed, options.integrationId, options.integrationName);
|
|
1418
1491
|
const basePath = normalizeBasePath(options.basePath);
|
|
1419
1492
|
let resolvedHandler;
|
|
@@ -1423,10 +1496,10 @@ function createAgents24BffHandler(options) {
|
|
|
1423
1496
|
if (request.method === "GET" && new URL(request.url).pathname === `${basePath}/bootstrap`) {
|
|
1424
1497
|
const { response, result } = await runtimeBootstrap(options, request, identity);
|
|
1425
1498
|
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(
|
|
1499
|
+
resolvedHandler = Promise.resolve(await withHistory(agents));
|
|
1427
1500
|
return response;
|
|
1428
1501
|
}
|
|
1429
|
-
resolvedHandler ||= resolveAgents().then(
|
|
1502
|
+
resolvedHandler ||= resolveAgents().then(withHistory);
|
|
1430
1503
|
return await (await resolvedHandler)(request);
|
|
1431
1504
|
} catch (error) {
|
|
1432
1505
|
resolvedHandler = void 0;
|