@agents24/node 0.5.41 → 0.5.42
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/README.md +17 -1
- package/compatibility.json +5 -5
- package/dist/bff.cjs +269 -8
- package/dist/bff.cjs.map +1 -1
- package/dist/bff.d.cts +6 -2
- package/dist/bff.d.ts +6 -2
- package/dist/bff.js +269 -8
- package/dist/bff.js.map +1 -1
- package/dist/{client-BfSwZnv3.d.cts → client-aKlZQ7rZ.d.cts} +66 -1
- package/dist/{client-BfSwZnv3.d.ts → client-aKlZQ7rZ.d.ts} +66 -1
- package/dist/index.cjs +36 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -1
- package/dist/types/bff-agent-resolution.d.ts +4 -0
- package/dist/types/bff-agent-resolution.d.ts.map +1 -1
- package/dist/types/bff-bootstrap.d.ts.map +1 -1
- package/dist/types/bff-conversation-submission.d.ts.map +1 -1
- package/dist/types/bff-customer-operations.d.ts +51 -0
- package/dist/types/bff-customer-operations.d.ts.map +1 -0
- package/dist/types/bff-multi-agent.d.ts.map +1 -1
- package/dist/types/bff-request.d.ts +1 -1
- package/dist/types/bff-request.d.ts.map +1 -1
- package/dist/types/bff.d.ts +1 -1
- package/dist/types/bff.d.ts.map +1 -1
- package/dist/types/embed-types.d.ts +2 -0
- package/dist/types/embed-types.d.ts.map +1 -1
- package/dist/types/embed.d.ts.map +1 -1
- package/dist/types/generated/embed.d.ts +5 -1
- package/dist/types/generated/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/generated/personal-skills.d.ts +59 -0
- package/dist/types/generated/personal-skills.d.ts.map +1 -1
- package/dist/types/types.d.ts +1 -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-aKlZQ7rZ.cjs';
|
|
2
2
|
import '@agents24/client/protocol';
|
|
3
3
|
import '@agents24/client';
|
|
4
4
|
|
|
@@ -50,6 +50,8 @@ type Agents24BffAgent = Agents24BffAgentVersion & ({
|
|
|
50
50
|
agentAlias: string;
|
|
51
51
|
agentId?: never;
|
|
52
52
|
});
|
|
53
|
+
/** Customer operations a handler may expose; none unless listed. */
|
|
54
|
+
type Agents24BffCapability = "skills.personal" | "connections.personal" | "tools.host" | "relay.connect";
|
|
53
55
|
interface Agents24BffHandlerOptions {
|
|
54
56
|
client: Pick<Agents24, "embed">;
|
|
55
57
|
agents: readonly Agents24BffAgent[];
|
|
@@ -58,6 +60,8 @@ interface Agents24BffHandlerOptions {
|
|
|
58
60
|
integrationId: string;
|
|
59
61
|
integrationName?: string;
|
|
60
62
|
runtimeTarget?: "draft" | "published";
|
|
63
|
+
/** Customer operations this handler exposes and advertises in bootstrap. */
|
|
64
|
+
capabilities?: readonly Agents24BffCapability[];
|
|
61
65
|
basePath?: string;
|
|
62
66
|
resolvePrincipal(request: Request): Promise<AgentBffPrincipalResolution> | AgentBffPrincipalResolution;
|
|
63
67
|
revokePrincipal?(request: Request, principal: AgentBffPrincipal): Promise<HeadersInit | void> | HeadersInit | void;
|
|
@@ -76,4 +80,4 @@ declare class AgentBffResolverError extends Error {
|
|
|
76
80
|
|
|
77
81
|
declare function createAgents24BffHandler(options: Agents24BffHandlerOptions): Agents24BffHandler;
|
|
78
82
|
|
|
79
|
-
export { type AgentBffPrincipal, type AgentBffPrincipalResolution, AgentBffResolverError, type AgentBffResolverErrorKind, type Agents24BffAgent, type Agents24BffDiagnostic, type Agents24BffHandler, type Agents24BffHandlerOptions, createAgents24BffHandler };
|
|
83
|
+
export { type AgentBffPrincipal, type AgentBffPrincipalResolution, AgentBffResolverError, type AgentBffResolverErrorKind, type Agents24BffAgent, type Agents24BffCapability, type Agents24BffDiagnostic, type Agents24BffHandler, type Agents24BffHandlerOptions, createAgents24BffHandler };
|
package/dist/bff.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Agents24 } from './client-
|
|
1
|
+
import { A as Agents24 } from './client-aKlZQ7rZ.js';
|
|
2
2
|
import '@agents24/client/protocol';
|
|
3
3
|
import '@agents24/client';
|
|
4
4
|
|
|
@@ -50,6 +50,8 @@ type Agents24BffAgent = Agents24BffAgentVersion & ({
|
|
|
50
50
|
agentAlias: string;
|
|
51
51
|
agentId?: never;
|
|
52
52
|
});
|
|
53
|
+
/** Customer operations a handler may expose; none unless listed. */
|
|
54
|
+
type Agents24BffCapability = "skills.personal" | "connections.personal" | "tools.host" | "relay.connect";
|
|
53
55
|
interface Agents24BffHandlerOptions {
|
|
54
56
|
client: Pick<Agents24, "embed">;
|
|
55
57
|
agents: readonly Agents24BffAgent[];
|
|
@@ -58,6 +60,8 @@ interface Agents24BffHandlerOptions {
|
|
|
58
60
|
integrationId: string;
|
|
59
61
|
integrationName?: string;
|
|
60
62
|
runtimeTarget?: "draft" | "published";
|
|
63
|
+
/** Customer operations this handler exposes and advertises in bootstrap. */
|
|
64
|
+
capabilities?: readonly Agents24BffCapability[];
|
|
61
65
|
basePath?: string;
|
|
62
66
|
resolvePrincipal(request: Request): Promise<AgentBffPrincipalResolution> | AgentBffPrincipalResolution;
|
|
63
67
|
revokePrincipal?(request: Request, principal: AgentBffPrincipal): Promise<HeadersInit | void> | HeadersInit | void;
|
|
@@ -76,4 +80,4 @@ declare class AgentBffResolverError extends Error {
|
|
|
76
80
|
|
|
77
81
|
declare function createAgents24BffHandler(options: Agents24BffHandlerOptions): Agents24BffHandler;
|
|
78
82
|
|
|
79
|
-
export { type AgentBffPrincipal, type AgentBffPrincipalResolution, AgentBffResolverError, type AgentBffResolverErrorKind, type Agents24BffAgent, type Agents24BffDiagnostic, type Agents24BffHandler, type Agents24BffHandlerOptions, createAgents24BffHandler };
|
|
83
|
+
export { type AgentBffPrincipal, type AgentBffPrincipalResolution, AgentBffResolverError, type AgentBffResolverErrorKind, type Agents24BffAgent, type Agents24BffCapability, type Agents24BffDiagnostic, type Agents24BffHandler, type Agents24BffHandlerOptions, createAgents24BffHandler };
|
package/dist/bff.js
CHANGED
|
@@ -123,9 +123,9 @@ function json(value, headers, status = 200) {
|
|
|
123
123
|
responseHeaders.set("Content-Type", "application/json; charset=utf-8");
|
|
124
124
|
return new Response(JSON.stringify(value), { status, headers: responseHeaders });
|
|
125
125
|
}
|
|
126
|
-
async function requestJson(request) {
|
|
126
|
+
async function requestJson(request, limit = JSON_LIMIT_BYTES) {
|
|
127
127
|
const contentLength = Number(request.headers.get("content-length") || 0);
|
|
128
|
-
if (contentLength >
|
|
128
|
+
if (contentLength > limit) throw new BffInputError(413, "REQUEST_TOO_LARGE", "The request body is too large.");
|
|
129
129
|
const value = await request.json().catch(() => null);
|
|
130
130
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
131
131
|
throw new BffInputError(400, "INVALID_JSON", "A JSON object is required.");
|
|
@@ -283,6 +283,237 @@ async function guardHistoricalRequest(input) {
|
|
|
283
283
|
}
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
// src/bff-customer-operations.ts
|
|
287
|
+
var SKILL_BODY_LIMIT_BYTES = 32 * 1048576;
|
|
288
|
+
var query = (call) => ({
|
|
289
|
+
externalUserId: call.owner.external_user_id,
|
|
290
|
+
integrationId: call.owner.integration_id,
|
|
291
|
+
runtimeTarget: call.owner.runtime_target
|
|
292
|
+
});
|
|
293
|
+
var relayOwner = (call) => {
|
|
294
|
+
if (call.owner.runtime_target !== "published") throw new BffInputError(409, "RELAY_PUBLISHED_ONLY", "Local tools serve published Agents only.");
|
|
295
|
+
return {
|
|
296
|
+
external_user_id: call.owner.external_user_id,
|
|
297
|
+
integration_id: call.owner.integration_id,
|
|
298
|
+
...call.agentVersionId ? { agent_version_id: call.agentVersionId } : {}
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
var integer = (url, name) => {
|
|
302
|
+
const raw = url.searchParams.get(name);
|
|
303
|
+
if (raw === null) return void 0;
|
|
304
|
+
const value = Number(raw);
|
|
305
|
+
if (!Number.isInteger(value) || value < 0) throw new BffInputError(400, "INVALID_PAGINATION", `${name} is invalid.`);
|
|
306
|
+
return value;
|
|
307
|
+
};
|
|
308
|
+
var text = (url, name) => url.searchParams.get(name) ?? void 0;
|
|
309
|
+
var SKILL = /^\/personal-skills\/([^/]+)$/;
|
|
310
|
+
var SESSION = (suffix) => new RegExp(`^/tool-sessions/([^/]+)${suffix}$`);
|
|
311
|
+
var payload = (call, extra = {}) => ({ ...call.body, ...extra, ...call.owner });
|
|
312
|
+
var OPERATIONS = [
|
|
313
|
+
{ method: "GET", pattern: /^\/personal-skills$/, capability: "skills.personal", run: (call) => call.embed.listPersonalSkills(call.agentId, {
|
|
314
|
+
...query(call),
|
|
315
|
+
q: text(call.url, "q"),
|
|
316
|
+
offset: integer(call.url, "offset"),
|
|
317
|
+
limit: integer(call.url, "limit"),
|
|
318
|
+
includeArchived: call.url.searchParams.get("include_archived") === "true"
|
|
319
|
+
}) },
|
|
320
|
+
{
|
|
321
|
+
method: "POST",
|
|
322
|
+
pattern: /^\/personal-skills$/,
|
|
323
|
+
capability: "skills.personal",
|
|
324
|
+
keyed: true,
|
|
325
|
+
bodyLimit: SKILL_BODY_LIMIT_BYTES,
|
|
326
|
+
fields: ["skill_id", "expected_revision", "name", "description", "content", "assets", "asset_changes"],
|
|
327
|
+
run: (call) => call.embed.savePersonalSkill(call.agentId, payload(call), call.options)
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
method: "POST",
|
|
331
|
+
pattern: /^\/personal-skills\/import$/,
|
|
332
|
+
capability: "skills.personal",
|
|
333
|
+
keyed: true,
|
|
334
|
+
bodyLimit: SKILL_BODY_LIMIT_BYTES,
|
|
335
|
+
fields: ["markdown", "assets"],
|
|
336
|
+
run: (call) => call.embed.importPersonalSkill(call.agentId, payload(call), call.options)
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
method: "GET",
|
|
340
|
+
pattern: SKILL,
|
|
341
|
+
capability: "skills.personal",
|
|
342
|
+
run: (call) => call.embed.getPersonalSkill(call.agentId, call.ids[0], query(call))
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
method: "PATCH",
|
|
346
|
+
pattern: SKILL,
|
|
347
|
+
capability: "skills.personal",
|
|
348
|
+
keyed: true,
|
|
349
|
+
fields: ["expected_revision", "enabled", "archived", "agent_enabled"],
|
|
350
|
+
run: (call) => call.embed.setPersonalSkillState(call.agentId, call.ids[0], payload(call), call.options)
|
|
351
|
+
},
|
|
352
|
+
{ method: "GET", pattern: /^\/personal-skills\/([^/]+)\/versions\/([^/]+)\/asset$/, capability: "skills.personal", run: (call) => {
|
|
353
|
+
const path = text(call.url, "path");
|
|
354
|
+
if (!path) throw new BffInputError(400, "INVALID_PATH", "path is required.");
|
|
355
|
+
return call.embed.readPersonalSkillAsset(call.agentId, call.ids[0], call.ids[1], { ...query(call), path });
|
|
356
|
+
} },
|
|
357
|
+
{
|
|
358
|
+
method: "GET",
|
|
359
|
+
pattern: /^\/personal-connections$/,
|
|
360
|
+
capability: "connections.personal",
|
|
361
|
+
run: (call) => call.embed.listPersonalConnections(call.agentId, query(call))
|
|
362
|
+
},
|
|
363
|
+
{ method: "GET", pattern: /^\/personal-connections\/catalog$/, capability: "connections.personal", run: (call) => call.embed.browsePersonalConnections(call.agentId, {
|
|
364
|
+
...query(call),
|
|
365
|
+
q: text(call.url, "q"),
|
|
366
|
+
category: text(call.url, "category"),
|
|
367
|
+
offset: integer(call.url, "offset"),
|
|
368
|
+
limit: integer(call.url, "limit")
|
|
369
|
+
}) },
|
|
370
|
+
{
|
|
371
|
+
method: "POST",
|
|
372
|
+
pattern: /^\/personal-connections$/,
|
|
373
|
+
capability: "connections.personal",
|
|
374
|
+
keyed: true,
|
|
375
|
+
fields: ["action", "toolkit", "server_id", "account_id", "native_callback_uri", "enabled", "selected", "label", "enabled_tool_names"],
|
|
376
|
+
run: (call) => call.embed.managePersonalConnection(call.agentId, payload(call), call.options)
|
|
377
|
+
},
|
|
378
|
+
// Ungated: raising a generation only ever withdraws authority.
|
|
379
|
+
{
|
|
380
|
+
method: "PUT",
|
|
381
|
+
pattern: /^\/caller-authority$/,
|
|
382
|
+
keyed: true,
|
|
383
|
+
fields: ["generation"],
|
|
384
|
+
run: (call) => call.embed.revokeCallerAuthority(call.agentId, payload(call), call.options)
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
method: "POST",
|
|
388
|
+
pattern: /^\/tool-sessions$/,
|
|
389
|
+
capability: "tools.host",
|
|
390
|
+
keyed: true,
|
|
391
|
+
fields: ["submission_id", "restrictions", "max_calls", "max_seconds", "deadline_at", "allow_cloud_computer", "personal_skills", "selected_app_ids"],
|
|
392
|
+
run: (call) => call.embed.openToolSession(call.agentId, payload(call, {
|
|
393
|
+
...call.agentVersionId ? { agent_version_id: call.agentVersionId } : {},
|
|
394
|
+
...call.resolution.knowledgeNamespaces === void 0 ? {} : { knowledge_namespaces: call.resolution.knowledgeNamespaces },
|
|
395
|
+
...call.resolution.knowledgeAccessScopes === void 0 ? {} : { knowledge_access_scopes: call.resolution.knowledgeAccessScopes }
|
|
396
|
+
}), call.options)
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
method: "POST",
|
|
400
|
+
pattern: SESSION("/discover"),
|
|
401
|
+
capability: "tools.host",
|
|
402
|
+
keyed: true,
|
|
403
|
+
fields: [],
|
|
404
|
+
run: (call) => call.embed.discoverHostTools(call.agentId, call.ids[0], call.owner, call.options)
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
method: "POST",
|
|
408
|
+
pattern: SESSION("/invoke"),
|
|
409
|
+
capability: "tools.host",
|
|
410
|
+
keyed: true,
|
|
411
|
+
fields: ["name", "arguments"],
|
|
412
|
+
run: (call) => call.embed.invokeHostTool(call.agentId, call.ids[0], payload(call), call.options)
|
|
413
|
+
},
|
|
414
|
+
{
|
|
415
|
+
method: "GET",
|
|
416
|
+
pattern: SESSION("/receipts/([^/]+)"),
|
|
417
|
+
capability: "tools.host",
|
|
418
|
+
run: (call) => call.embed.inspectHostTool(call.agentId, call.ids[0], call.ids[1], call.owner)
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
method: "POST",
|
|
422
|
+
pattern: SESSION("/receipts/([^/]+)/resume"),
|
|
423
|
+
capability: "tools.host",
|
|
424
|
+
keyed: true,
|
|
425
|
+
fields: ["decision"],
|
|
426
|
+
run: (call) => call.embed.resumeHostTool(call.agentId, call.ids[0], call.ids[1], payload(call), call.options)
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
method: "POST",
|
|
430
|
+
pattern: SESSION("/close"),
|
|
431
|
+
capability: "tools.host",
|
|
432
|
+
fields: [],
|
|
433
|
+
run: (call) => call.embed.closeToolSession(call.agentId, call.ids[0], call.owner, call.options)
|
|
434
|
+
},
|
|
435
|
+
{ method: "GET", pattern: /^\/relay$/, capability: "relay.connect", run: (call) => {
|
|
436
|
+
const owner = relayOwner(call);
|
|
437
|
+
return call.embed.getRelay(call.agentId, {
|
|
438
|
+
externalUserId: owner.external_user_id,
|
|
439
|
+
integrationId: owner.integration_id,
|
|
440
|
+
agentVersionId: call.agentVersionId
|
|
441
|
+
});
|
|
442
|
+
} },
|
|
443
|
+
{
|
|
444
|
+
method: "POST",
|
|
445
|
+
pattern: /^\/relay-clients$/,
|
|
446
|
+
capability: "relay.connect",
|
|
447
|
+
fields: ["id", "name"],
|
|
448
|
+
run: (call) => call.embed.createRelayClient(call.agentId, { ...call.body, ...relayOwner(call) })
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
method: "POST",
|
|
452
|
+
pattern: /^\/relay-clients\/([^/]+)\/tickets$/,
|
|
453
|
+
capability: "relay.connect",
|
|
454
|
+
fields: ["registrations"],
|
|
455
|
+
run: (call) => call.embed.issueRelayTicket(call.agentId, call.ids[0], { ...call.body, ...relayOwner(call) })
|
|
456
|
+
},
|
|
457
|
+
{
|
|
458
|
+
method: "POST",
|
|
459
|
+
pattern: /^\/relay-clients\/([^/]+)\/revoke$/,
|
|
460
|
+
capability: "relay.connect",
|
|
461
|
+
fields: [],
|
|
462
|
+
run: (call) => call.embed.revokeRelayClient(call.agentId, call.ids[0], relayOwner(call))
|
|
463
|
+
}
|
|
464
|
+
];
|
|
465
|
+
function customerOperation(method, path) {
|
|
466
|
+
return OPERATIONS.find((operation) => operation.method === method && operation.pattern.test(path));
|
|
467
|
+
}
|
|
468
|
+
async function dispatchCustomerOperation(operation, input) {
|
|
469
|
+
const { request } = input;
|
|
470
|
+
if (operation.capability && !input.capabilities.includes(operation.capability)) {
|
|
471
|
+
throw new BffInputError(403, "CAPABILITY_NOT_ENABLED", "This operation is not available.");
|
|
472
|
+
}
|
|
473
|
+
const idempotencyKey = stringValue(request.headers.get("idempotency-key"));
|
|
474
|
+
if (operation.keyed && !idempotencyKey) throw new BffInputError(400, "IDEMPOTENCY_REQUIRED", "An Idempotency-Key is required.");
|
|
475
|
+
const body = !operation.fields?.length ? {} : await requestJson(request, operation.bodyLimit);
|
|
476
|
+
if (Object.keys(body).some((field) => !operation.fields?.includes(field))) {
|
|
477
|
+
throw new BffInputError(400, "INVALID_REQUEST", "The request contains an unsupported field.");
|
|
478
|
+
}
|
|
479
|
+
const match = operation.pattern.exec(input.path);
|
|
480
|
+
return json(await operation.run({
|
|
481
|
+
embed: input.embed,
|
|
482
|
+
agentId: input.agent.agentId,
|
|
483
|
+
agentVersionId: input.agent.agentVersionId,
|
|
484
|
+
resolution: input.resolution,
|
|
485
|
+
owner: { external_user_id: input.externalUserId, integration_id: input.integrationId, runtime_target: input.runtimeTarget },
|
|
486
|
+
ids: match.slice(1).map((id) => routeId(`/${id}`, /^\/(.+)$/, "id")),
|
|
487
|
+
url: new URL(request.url),
|
|
488
|
+
body,
|
|
489
|
+
options: { ...idempotencyKey ? { idempotencyKey } : {} }
|
|
490
|
+
}));
|
|
491
|
+
}
|
|
492
|
+
function turnChoices(body) {
|
|
493
|
+
const list = (key, valid) => {
|
|
494
|
+
const value = body[key];
|
|
495
|
+
if (value === void 0 || value === null) return void 0;
|
|
496
|
+
if (!Array.isArray(value) || !value.every(valid)) throw new BffInputError(400, "INVALID_REQUEST", `${key} is invalid.`);
|
|
497
|
+
return value;
|
|
498
|
+
};
|
|
499
|
+
const record = (key) => {
|
|
500
|
+
const value = body[key];
|
|
501
|
+
if (value === void 0 || value === null) return void 0;
|
|
502
|
+
if (typeof value !== "object" || Array.isArray(value)) throw new BffInputError(400, "INVALID_REQUEST", `${key} is invalid.`);
|
|
503
|
+
return objectValue(value);
|
|
504
|
+
};
|
|
505
|
+
const skills = list("personalSkills", (item) => Boolean(stringValue(objectValue(item).skill_id)));
|
|
506
|
+
const apps = list("selectedAppIds", (item) => Boolean(stringValue(item)));
|
|
507
|
+
const restrictions = record("callerRestrictions");
|
|
508
|
+
const limits = record("executionLimits");
|
|
509
|
+
return {
|
|
510
|
+
...skills?.length ? { personal_skills: skills } : {},
|
|
511
|
+
...apps ? { selected_app_ids: apps } : {},
|
|
512
|
+
...restrictions ? { caller_restrictions: restrictions } : {},
|
|
513
|
+
...limits ? { execution_limits: limits } : {}
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
|
|
286
517
|
// src/bff-conversation-submission.ts
|
|
287
518
|
async function submitConversationStream(input) {
|
|
288
519
|
const { request, body, resolution } = input;
|
|
@@ -296,6 +527,8 @@ async function submitConversationStream(input) {
|
|
|
296
527
|
input: value.input,
|
|
297
528
|
attachment_ids: value.attachmentIds,
|
|
298
529
|
client_submission_id: value.clientSubmissionId,
|
|
530
|
+
...turnChoices(body),
|
|
531
|
+
...body.relayClientId === null ? { relay_client_id: null } : stringValue(body.relayClientId) ? { relay_client_id: stringValue(body.relayClientId) } : {},
|
|
299
532
|
...stringValue(body.dictationSessionId) ? { dictation_session_id: stringValue(body.dictationSessionId) } : {},
|
|
300
533
|
...input.requestedAgentId ? { requested_agent_id: input.requestedAgentId } : {},
|
|
301
534
|
...value.requestedModelId ? { requested_model_id: value.requestedModelId } : {},
|
|
@@ -328,9 +561,9 @@ async function dispatchDelegations(request, path, embed, agentId, scope) {
|
|
|
328
561
|
const match = delegationRoute(path);
|
|
329
562
|
const threadId = decodeURIComponent(match[1]);
|
|
330
563
|
const handle = match[2] ? decodeURIComponent(match[2]) : void 0;
|
|
331
|
-
const
|
|
564
|
+
const query2 = new URL(request.url).searchParams;
|
|
332
565
|
const paging = (key, max) => {
|
|
333
|
-
const raw =
|
|
566
|
+
const raw = query2.get(key), rawLimit = query2.get("limit");
|
|
334
567
|
const cursor = raw === null ? void 0 : Number(raw);
|
|
335
568
|
const limit = rawLimit === null ? void 0 : Number(rawLimit);
|
|
336
569
|
if (cursor !== void 0 && (!Number.isInteger(cursor) || cursor < 0) || limit !== void 0 && (!Number.isInteger(limit) || limit < 1 || limit > max)) {
|
|
@@ -510,8 +743,8 @@ function emitDiagnostic(callback, diagnostic) {
|
|
|
510
743
|
}
|
|
511
744
|
function reportFailureResponse(callback, request, operation, response) {
|
|
512
745
|
if (!callback || response.status < 400) return response;
|
|
513
|
-
void response.clone().json().then((
|
|
514
|
-
const row =
|
|
746
|
+
void response.clone().json().then((payload2) => {
|
|
747
|
+
const row = payload2 && typeof payload2 === "object" && !Array.isArray(payload2) ? payload2 : {};
|
|
515
748
|
const clean2 = (value, pattern) => typeof value === "string" && pattern.test(value) ? value : void 0;
|
|
516
749
|
emitDiagnostic(callback, {
|
|
517
750
|
operation,
|
|
@@ -1254,6 +1487,32 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1254
1487
|
});
|
|
1255
1488
|
return (await requestedAgent(detail.runtime_selection?.agent_id)).agentId;
|
|
1256
1489
|
};
|
|
1490
|
+
const operation = customerOperation(request.method, path);
|
|
1491
|
+
if (operation) {
|
|
1492
|
+
const agent = await requestedAgent(url.searchParams.get("agent_id"));
|
|
1493
|
+
assertWritableAgent(agent.agentId, historical);
|
|
1494
|
+
return mergeHeaders(await dispatchCustomerOperation(operation, {
|
|
1495
|
+
request,
|
|
1496
|
+
path,
|
|
1497
|
+
embed: options.client.embed,
|
|
1498
|
+
agent,
|
|
1499
|
+
resolution,
|
|
1500
|
+
externalUserId,
|
|
1501
|
+
integrationId,
|
|
1502
|
+
runtimeTarget,
|
|
1503
|
+
capabilities: options.capabilities ?? []
|
|
1504
|
+
}), resolution.responseHeaders);
|
|
1505
|
+
}
|
|
1506
|
+
if (request.method === "GET" && /^\/runs\/[^/]+$/.test(path)) {
|
|
1507
|
+
const runId = routeId(path, /^\/runs\/([^/]+)$/, "runId");
|
|
1508
|
+
return mergeHeaders(json(await options.client.embed.getAgentRun(await resolveRunAgent(runId), runId, {
|
|
1509
|
+
externalUserId,
|
|
1510
|
+
integrationId,
|
|
1511
|
+
runtimeTarget,
|
|
1512
|
+
externalSessionId: resolution.principal.externalSessionId,
|
|
1513
|
+
chatScope: resolution.chatScope
|
|
1514
|
+
})), resolution.responseHeaders);
|
|
1515
|
+
}
|
|
1257
1516
|
if (request.method === "GET" && /^\/runs\/[^/]+\/outputs(?:\/[^/]+)?$/.test(path)) {
|
|
1258
1517
|
const runId = routeId(path, /^\/runs\/([^/]+)\/outputs/, "runId");
|
|
1259
1518
|
return dispatchToAgent(await resolveRunAgent(runId));
|
|
@@ -1268,7 +1527,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1268
1527
|
const body = await requestJson(request);
|
|
1269
1528
|
const threadId = stringValue(body.threadId);
|
|
1270
1529
|
if (threadId && body.requestedAgentId) assertWritableAgent((await requestedAgent(body.requestedAgentId)).agentId, historical);
|
|
1271
|
-
if (threadId) return submitConversationStream({
|
|
1530
|
+
if (threadId) return await submitConversationStream({
|
|
1272
1531
|
options,
|
|
1273
1532
|
request,
|
|
1274
1533
|
body,
|
|
@@ -1296,6 +1555,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1296
1555
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
1297
1556
|
...input ? { input } : {},
|
|
1298
1557
|
client_submission_id: stringValue(body.clientSubmissionId),
|
|
1558
|
+
...turnChoices(body),
|
|
1299
1559
|
...body.relayClientId === null ? { relay_client_id: null } : stringValue(body.relayClientId) ? { relay_client_id: stringValue(body.relayClientId) } : {},
|
|
1300
1560
|
attachment_ids: attachmentIds,
|
|
1301
1561
|
...stringValue(body.dictationSessionId) ? { dictation_session_id: stringValue(body.dictationSessionId) } : {},
|
|
@@ -1581,7 +1841,8 @@ async function runtimeBootstrap(options, request, identityResolver) {
|
|
|
1581
1841
|
});
|
|
1582
1842
|
identityResolver.remember(resolution.principal, result.customer_principal_ref);
|
|
1583
1843
|
await options.onPrincipalResolved?.(request, resolution, result.customer_principal_ref);
|
|
1584
|
-
|
|
1844
|
+
const bootstrap = options.capabilities?.length ? { ...result.bootstrap, capabilities: [.../* @__PURE__ */ new Set([...result.bootstrap.capabilities ?? [], ...options.capabilities])] } : result.bootstrap;
|
|
1845
|
+
return { response: mergeHeaders(json(bootstrap), resolution.responseHeaders), result };
|
|
1585
1846
|
}
|
|
1586
1847
|
|
|
1587
1848
|
// src/bff.ts
|