@agents24/node 0.5.41 → 0.5.43
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 +6 -6
- package/dist/bff.cjs +296 -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 +296 -8
- package/dist/bff.js.map +1 -1
- package/dist/{client-BfSwZnv3.d.cts → client-9eTRFxs2.d.cts} +276 -6
- package/dist/{client-BfSwZnv3.d.ts → client-9eTRFxs2.d.ts} +276 -6
- package/dist/index.cjs +193 -4
- 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 +193 -4
- 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/client.d.ts +4 -0
- package/dist/types/client.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/clientGovernance.d.ts +8 -0
- package/dist/types/generated/clientGovernance.d.ts.map +1 -0
- package/dist/types/generated/clientServiceKeys.d.ts +10 -0
- package/dist/types/generated/clientServiceKeys.d.ts.map +1 -0
- package/dist/types/generated/embed.d.ts +10 -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 +120 -0
- package/dist/types/generated/personal-skills.d.ts.map +1 -1
- package/dist/types/generated/resourcePolicies.d.ts +5 -1
- package/dist/types/generated/resourcePolicies.d.ts.map +1 -1
- package/dist/types/generated/runs.d.ts +8 -0
- package/dist/types/generated/runs.d.ts.map +1 -0
- package/dist/types/runs.d.ts +2 -2
- package/dist/types/runs.d.ts.map +1 -1
- package/dist/types/submission-and-service-key-types.d.ts +39 -0
- package/dist/types/submission-and-service-key-types.d.ts.map +1 -0
- package/dist/types/types.d.ts +81 -3
- 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-9eTRFxs2.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-9eTRFxs2.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,264 @@ 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
|
+
{
|
|
379
|
+
method: "GET",
|
|
380
|
+
pattern: /^\/connector-triggers$/,
|
|
381
|
+
capability: "connections.personal",
|
|
382
|
+
run: (call) => call.embed.listConnectorTriggers(call.agentId, query(call))
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
method: "POST",
|
|
386
|
+
pattern: /^\/connector-triggers$/,
|
|
387
|
+
capability: "connections.personal",
|
|
388
|
+
keyed: true,
|
|
389
|
+
fields: ["account_id", "trigger_slug", "trigger_config"],
|
|
390
|
+
run: (call) => call.embed.subscribeConnectorTrigger(call.agentId, payload(call), call.options)
|
|
391
|
+
},
|
|
392
|
+
// Removing a subscription twice finds nothing the second time, so no key is required.
|
|
393
|
+
{
|
|
394
|
+
method: "DELETE",
|
|
395
|
+
pattern: /^\/connector-triggers\/([^/]+)$/,
|
|
396
|
+
capability: "connections.personal",
|
|
397
|
+
run: (call) => call.embed.unsubscribeConnectorTrigger(call.agentId, call.ids[0], query(call))
|
|
398
|
+
},
|
|
399
|
+
{ method: "GET", pattern: /^\/connector-events$/, capability: "connections.personal", run: (call) => call.embed.readConnectorEvents(call.agentId, {
|
|
400
|
+
...query(call),
|
|
401
|
+
after: integer(call.url, "after"),
|
|
402
|
+
limit: integer(call.url, "limit"),
|
|
403
|
+
waitSeconds: integer(call.url, "wait_seconds")
|
|
404
|
+
}) },
|
|
405
|
+
// Ungated: raising a generation only ever withdraws authority.
|
|
406
|
+
{
|
|
407
|
+
method: "PUT",
|
|
408
|
+
pattern: /^\/caller-authority$/,
|
|
409
|
+
keyed: true,
|
|
410
|
+
fields: ["generation"],
|
|
411
|
+
run: (call) => call.embed.revokeCallerAuthority(call.agentId, payload(call), call.options)
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
method: "POST",
|
|
415
|
+
pattern: /^\/tool-sessions$/,
|
|
416
|
+
capability: "tools.host",
|
|
417
|
+
keyed: true,
|
|
418
|
+
fields: ["submission_id", "restrictions", "max_calls", "max_seconds", "deadline_at", "allow_cloud_computer", "personal_skills", "selected_app_ids"],
|
|
419
|
+
run: (call) => call.embed.openToolSession(call.agentId, payload(call, {
|
|
420
|
+
...call.agentVersionId ? { agent_version_id: call.agentVersionId } : {},
|
|
421
|
+
...call.resolution.knowledgeNamespaces === void 0 ? {} : { knowledge_namespaces: call.resolution.knowledgeNamespaces },
|
|
422
|
+
...call.resolution.knowledgeAccessScopes === void 0 ? {} : { knowledge_access_scopes: call.resolution.knowledgeAccessScopes }
|
|
423
|
+
}), call.options)
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
method: "POST",
|
|
427
|
+
pattern: SESSION("/discover"),
|
|
428
|
+
capability: "tools.host",
|
|
429
|
+
keyed: true,
|
|
430
|
+
fields: [],
|
|
431
|
+
run: (call) => call.embed.discoverHostTools(call.agentId, call.ids[0], call.owner, call.options)
|
|
432
|
+
},
|
|
433
|
+
{
|
|
434
|
+
method: "POST",
|
|
435
|
+
pattern: SESSION("/invoke"),
|
|
436
|
+
capability: "tools.host",
|
|
437
|
+
keyed: true,
|
|
438
|
+
fields: ["name", "arguments"],
|
|
439
|
+
run: (call) => call.embed.invokeHostTool(call.agentId, call.ids[0], payload(call), call.options)
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
method: "GET",
|
|
443
|
+
pattern: SESSION("/receipts/([^/]+)"),
|
|
444
|
+
capability: "tools.host",
|
|
445
|
+
run: (call) => call.embed.inspectHostTool(call.agentId, call.ids[0], call.ids[1], call.owner)
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
method: "POST",
|
|
449
|
+
pattern: SESSION("/receipts/([^/]+)/resume"),
|
|
450
|
+
capability: "tools.host",
|
|
451
|
+
keyed: true,
|
|
452
|
+
fields: ["decision"],
|
|
453
|
+
run: (call) => call.embed.resumeHostTool(call.agentId, call.ids[0], call.ids[1], payload(call), call.options)
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
method: "POST",
|
|
457
|
+
pattern: SESSION("/close"),
|
|
458
|
+
capability: "tools.host",
|
|
459
|
+
fields: [],
|
|
460
|
+
run: (call) => call.embed.closeToolSession(call.agentId, call.ids[0], call.owner, call.options)
|
|
461
|
+
},
|
|
462
|
+
{ method: "GET", pattern: /^\/relay$/, capability: "relay.connect", run: (call) => {
|
|
463
|
+
const owner = relayOwner(call);
|
|
464
|
+
return call.embed.getRelay(call.agentId, {
|
|
465
|
+
externalUserId: owner.external_user_id,
|
|
466
|
+
integrationId: owner.integration_id,
|
|
467
|
+
agentVersionId: call.agentVersionId
|
|
468
|
+
});
|
|
469
|
+
} },
|
|
470
|
+
{
|
|
471
|
+
method: "POST",
|
|
472
|
+
pattern: /^\/relay-clients$/,
|
|
473
|
+
capability: "relay.connect",
|
|
474
|
+
fields: ["id", "name"],
|
|
475
|
+
run: (call) => call.embed.createRelayClient(call.agentId, { ...call.body, ...relayOwner(call) })
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
method: "POST",
|
|
479
|
+
pattern: /^\/relay-clients\/([^/]+)\/tickets$/,
|
|
480
|
+
capability: "relay.connect",
|
|
481
|
+
fields: ["registrations"],
|
|
482
|
+
run: (call) => call.embed.issueRelayTicket(call.agentId, call.ids[0], { ...call.body, ...relayOwner(call) })
|
|
483
|
+
},
|
|
484
|
+
{
|
|
485
|
+
method: "POST",
|
|
486
|
+
pattern: /^\/relay-clients\/([^/]+)\/revoke$/,
|
|
487
|
+
capability: "relay.connect",
|
|
488
|
+
fields: [],
|
|
489
|
+
run: (call) => call.embed.revokeRelayClient(call.agentId, call.ids[0], relayOwner(call))
|
|
490
|
+
}
|
|
491
|
+
];
|
|
492
|
+
function customerOperation(method, path) {
|
|
493
|
+
return OPERATIONS.find((operation) => operation.method === method && operation.pattern.test(path));
|
|
494
|
+
}
|
|
495
|
+
async function dispatchCustomerOperation(operation, input) {
|
|
496
|
+
const { request } = input;
|
|
497
|
+
if (operation.capability && !input.capabilities.includes(operation.capability)) {
|
|
498
|
+
throw new BffInputError(403, "CAPABILITY_NOT_ENABLED", "This operation is not available.");
|
|
499
|
+
}
|
|
500
|
+
const idempotencyKey = stringValue(request.headers.get("idempotency-key"));
|
|
501
|
+
if (operation.keyed && !idempotencyKey) throw new BffInputError(400, "IDEMPOTENCY_REQUIRED", "An Idempotency-Key is required.");
|
|
502
|
+
const body = !operation.fields?.length ? {} : await requestJson(request, operation.bodyLimit);
|
|
503
|
+
if (Object.keys(body).some((field) => !operation.fields?.includes(field))) {
|
|
504
|
+
throw new BffInputError(400, "INVALID_REQUEST", "The request contains an unsupported field.");
|
|
505
|
+
}
|
|
506
|
+
const match = operation.pattern.exec(input.path);
|
|
507
|
+
return json(await operation.run({
|
|
508
|
+
embed: input.embed,
|
|
509
|
+
agentId: input.agent.agentId,
|
|
510
|
+
agentVersionId: input.agent.agentVersionId,
|
|
511
|
+
resolution: input.resolution,
|
|
512
|
+
owner: { external_user_id: input.externalUserId, integration_id: input.integrationId, runtime_target: input.runtimeTarget },
|
|
513
|
+
ids: match.slice(1).map((id) => routeId(`/${id}`, /^\/(.+)$/, "id")),
|
|
514
|
+
url: new URL(request.url),
|
|
515
|
+
body,
|
|
516
|
+
options: { ...idempotencyKey ? { idempotencyKey } : {} }
|
|
517
|
+
}));
|
|
518
|
+
}
|
|
519
|
+
function turnChoices(body) {
|
|
520
|
+
const list = (key, valid) => {
|
|
521
|
+
const value = body[key];
|
|
522
|
+
if (value === void 0 || value === null) return void 0;
|
|
523
|
+
if (!Array.isArray(value) || !value.every(valid)) throw new BffInputError(400, "INVALID_REQUEST", `${key} is invalid.`);
|
|
524
|
+
return value;
|
|
525
|
+
};
|
|
526
|
+
const record = (key) => {
|
|
527
|
+
const value = body[key];
|
|
528
|
+
if (value === void 0 || value === null) return void 0;
|
|
529
|
+
if (typeof value !== "object" || Array.isArray(value)) throw new BffInputError(400, "INVALID_REQUEST", `${key} is invalid.`);
|
|
530
|
+
return objectValue(value);
|
|
531
|
+
};
|
|
532
|
+
const skills = list("personalSkills", (item) => Boolean(stringValue(objectValue(item).skill_id)));
|
|
533
|
+
const apps = list("selectedAppIds", (item) => Boolean(stringValue(item)));
|
|
534
|
+
const restrictions = record("callerRestrictions");
|
|
535
|
+
const limits = record("executionLimits");
|
|
536
|
+
return {
|
|
537
|
+
...skills?.length ? { personal_skills: skills } : {},
|
|
538
|
+
...apps ? { selected_app_ids: apps } : {},
|
|
539
|
+
...restrictions ? { caller_restrictions: restrictions } : {},
|
|
540
|
+
...limits ? { execution_limits: limits } : {}
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
|
|
286
544
|
// src/bff-conversation-submission.ts
|
|
287
545
|
async function submitConversationStream(input) {
|
|
288
546
|
const { request, body, resolution } = input;
|
|
@@ -296,6 +554,8 @@ async function submitConversationStream(input) {
|
|
|
296
554
|
input: value.input,
|
|
297
555
|
attachment_ids: value.attachmentIds,
|
|
298
556
|
client_submission_id: value.clientSubmissionId,
|
|
557
|
+
...turnChoices(body),
|
|
558
|
+
...body.relayClientId === null ? { relay_client_id: null } : stringValue(body.relayClientId) ? { relay_client_id: stringValue(body.relayClientId) } : {},
|
|
299
559
|
...stringValue(body.dictationSessionId) ? { dictation_session_id: stringValue(body.dictationSessionId) } : {},
|
|
300
560
|
...input.requestedAgentId ? { requested_agent_id: input.requestedAgentId } : {},
|
|
301
561
|
...value.requestedModelId ? { requested_model_id: value.requestedModelId } : {},
|
|
@@ -328,9 +588,9 @@ async function dispatchDelegations(request, path, embed, agentId, scope) {
|
|
|
328
588
|
const match = delegationRoute(path);
|
|
329
589
|
const threadId = decodeURIComponent(match[1]);
|
|
330
590
|
const handle = match[2] ? decodeURIComponent(match[2]) : void 0;
|
|
331
|
-
const
|
|
591
|
+
const query2 = new URL(request.url).searchParams;
|
|
332
592
|
const paging = (key, max) => {
|
|
333
|
-
const raw =
|
|
593
|
+
const raw = query2.get(key), rawLimit = query2.get("limit");
|
|
334
594
|
const cursor = raw === null ? void 0 : Number(raw);
|
|
335
595
|
const limit = rawLimit === null ? void 0 : Number(rawLimit);
|
|
336
596
|
if (cursor !== void 0 && (!Number.isInteger(cursor) || cursor < 0) || limit !== void 0 && (!Number.isInteger(limit) || limit < 1 || limit > max)) {
|
|
@@ -510,8 +770,8 @@ function emitDiagnostic(callback, diagnostic) {
|
|
|
510
770
|
}
|
|
511
771
|
function reportFailureResponse(callback, request, operation, response) {
|
|
512
772
|
if (!callback || response.status < 400) return response;
|
|
513
|
-
void response.clone().json().then((
|
|
514
|
-
const row =
|
|
773
|
+
void response.clone().json().then((payload2) => {
|
|
774
|
+
const row = payload2 && typeof payload2 === "object" && !Array.isArray(payload2) ? payload2 : {};
|
|
515
775
|
const clean2 = (value, pattern) => typeof value === "string" && pattern.test(value) ? value : void 0;
|
|
516
776
|
emitDiagnostic(callback, {
|
|
517
777
|
operation,
|
|
@@ -1254,6 +1514,32 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1254
1514
|
});
|
|
1255
1515
|
return (await requestedAgent(detail.runtime_selection?.agent_id)).agentId;
|
|
1256
1516
|
};
|
|
1517
|
+
const operation = customerOperation(request.method, path);
|
|
1518
|
+
if (operation) {
|
|
1519
|
+
const agent = await requestedAgent(url.searchParams.get("agent_id"));
|
|
1520
|
+
assertWritableAgent(agent.agentId, historical);
|
|
1521
|
+
return mergeHeaders(await dispatchCustomerOperation(operation, {
|
|
1522
|
+
request,
|
|
1523
|
+
path,
|
|
1524
|
+
embed: options.client.embed,
|
|
1525
|
+
agent,
|
|
1526
|
+
resolution,
|
|
1527
|
+
externalUserId,
|
|
1528
|
+
integrationId,
|
|
1529
|
+
runtimeTarget,
|
|
1530
|
+
capabilities: options.capabilities ?? []
|
|
1531
|
+
}), resolution.responseHeaders);
|
|
1532
|
+
}
|
|
1533
|
+
if (request.method === "GET" && /^\/runs\/[^/]+$/.test(path)) {
|
|
1534
|
+
const runId = routeId(path, /^\/runs\/([^/]+)$/, "runId");
|
|
1535
|
+
return mergeHeaders(json(await options.client.embed.getAgentRun(await resolveRunAgent(runId), runId, {
|
|
1536
|
+
externalUserId,
|
|
1537
|
+
integrationId,
|
|
1538
|
+
runtimeTarget,
|
|
1539
|
+
externalSessionId: resolution.principal.externalSessionId,
|
|
1540
|
+
chatScope: resolution.chatScope
|
|
1541
|
+
})), resolution.responseHeaders);
|
|
1542
|
+
}
|
|
1257
1543
|
if (request.method === "GET" && /^\/runs\/[^/]+\/outputs(?:\/[^/]+)?$/.test(path)) {
|
|
1258
1544
|
const runId = routeId(path, /^\/runs\/([^/]+)\/outputs/, "runId");
|
|
1259
1545
|
return dispatchToAgent(await resolveRunAgent(runId));
|
|
@@ -1268,7 +1554,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1268
1554
|
const body = await requestJson(request);
|
|
1269
1555
|
const threadId = stringValue(body.threadId);
|
|
1270
1556
|
if (threadId && body.requestedAgentId) assertWritableAgent((await requestedAgent(body.requestedAgentId)).agentId, historical);
|
|
1271
|
-
if (threadId) return submitConversationStream({
|
|
1557
|
+
if (threadId) return await submitConversationStream({
|
|
1272
1558
|
options,
|
|
1273
1559
|
request,
|
|
1274
1560
|
body,
|
|
@@ -1296,6 +1582,7 @@ function createResolvedAgents24BffHandler(options, sharedIdentity) {
|
|
|
1296
1582
|
...resolution.chatScope === void 0 ? {} : { chat_scope: resolution.chatScope },
|
|
1297
1583
|
...input ? { input } : {},
|
|
1298
1584
|
client_submission_id: stringValue(body.clientSubmissionId),
|
|
1585
|
+
...turnChoices(body),
|
|
1299
1586
|
...body.relayClientId === null ? { relay_client_id: null } : stringValue(body.relayClientId) ? { relay_client_id: stringValue(body.relayClientId) } : {},
|
|
1300
1587
|
attachment_ids: attachmentIds,
|
|
1301
1588
|
...stringValue(body.dictationSessionId) ? { dictation_session_id: stringValue(body.dictationSessionId) } : {},
|
|
@@ -1581,7 +1868,8 @@ async function runtimeBootstrap(options, request, identityResolver) {
|
|
|
1581
1868
|
});
|
|
1582
1869
|
identityResolver.remember(resolution.principal, result.customer_principal_ref);
|
|
1583
1870
|
await options.onPrincipalResolved?.(request, resolution, result.customer_principal_ref);
|
|
1584
|
-
|
|
1871
|
+
const bootstrap = options.capabilities?.length ? { ...result.bootstrap, capabilities: [.../* @__PURE__ */ new Set([...result.bootstrap.capabilities ?? [], ...options.capabilities])] } : result.bootstrap;
|
|
1872
|
+
return { response: mergeHeaders(json(bootstrap), resolution.responseHeaders), result };
|
|
1585
1873
|
}
|
|
1586
1874
|
|
|
1587
1875
|
// src/bff.ts
|