@genesislcap/ai-assistant 15.81.0 → 15.83.0
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/ai-assistant.api.json +2800 -116
- package/dist/ai-assistant.d.ts +887 -109
- package/dist/chat-driver.cjs +468 -107
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +468 -107
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/custom-elements.json +1108 -61
- package/dist/dts/autopilot/autopilot-driver.d.ts +117 -11
- package/dist/dts/autopilot/autopilot-driver.d.ts.map +1 -1
- package/dist/dts/autopilot/autopilot-session.d.ts +55 -7
- package/dist/dts/autopilot/autopilot-session.d.ts.map +1 -1
- package/dist/dts/autopilot/autopilot-tools.d.ts +3 -2
- package/dist/dts/autopilot/autopilot-tools.d.ts.map +1 -1
- package/dist/dts/autopilot/decision-message.d.ts +35 -3
- package/dist/dts/autopilot/decision-message.d.ts.map +1 -1
- package/dist/dts/autopilot/hand-back/hand-back.controller.d.ts +2 -2
- package/dist/dts/autopilot/hand-back/hand-back.controller.d.ts.map +1 -1
- package/dist/dts/autopilot/hand-back/hand-back.d.ts +2 -2
- package/dist/dts/autopilot/hand-back/hand-back.d.ts.map +1 -1
- package/dist/dts/autopilot/index.d.ts +1 -0
- package/dist/dts/autopilot/index.d.ts.map +1 -1
- package/dist/dts/autopilot/widget-tools.d.ts +95 -0
- package/dist/dts/autopilot/widget-tools.d.ts.map +1 -0
- package/dist/dts/channel/ai-activity-channel.d.ts +10 -0
- package/dist/dts/channel/ai-activity-channel.d.ts.map +1 -1
- package/dist/dts/components/agent-session/agent-session.d.ts +2 -1
- package/dist/dts/components/agent-session/agent-session.d.ts.map +1 -1
- package/dist/dts/components/ai-driver/ai-driver.d.ts +25 -6
- package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
- package/dist/dts/components/ai-driver/base-driver-decorator.d.ts +2 -0
- package/dist/dts/components/ai-driver/base-driver-decorator.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +14 -2
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/interaction-controller.d.ts +61 -17
- package/dist/dts/components/chat-driver/interaction-controller.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +6 -0
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/config/config.d.ts +31 -6
- package/dist/dts/config/config.d.ts.map +1 -1
- package/dist/dts/config/define-stateful-agent.d.ts +5 -1
- package/dist/dts/config/define-stateful-agent.d.ts.map +1 -1
- package/dist/dts/index.d.ts +4 -2
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/main/main.d.ts +33 -16
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/main/main.types.d.ts +15 -0
- package/dist/dts/main/main.types.d.ts.map +1 -1
- package/dist/dts/notifications/agent-notifications.d.ts +6 -2
- package/dist/dts/notifications/agent-notifications.d.ts.map +1 -1
- package/dist/dts/notifications/agent-notifier.d.ts +26 -4
- package/dist/dts/notifications/agent-notifier.d.ts.map +1 -1
- package/dist/dts/state/decision-surface.d.ts +22 -4
- package/dist/dts/state/decision-surface.d.ts.map +1 -1
- package/dist/dts/state/interaction-context.d.ts +23 -4
- package/dist/dts/state/interaction-context.d.ts.map +1 -1
- package/dist/dts/state/interaction-registry.d.ts +55 -6
- package/dist/dts/state/interaction-registry.d.ts.map +1 -1
- package/dist/dts/state/live-interactions.d.ts +28 -0
- package/dist/dts/state/live-interactions.d.ts.map +1 -0
- package/dist/dts/state/persistence/session-persister.d.ts +6 -0
- package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-snapshot.d.ts +16 -5
- package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
- package/dist/dts/state/test-interaction-context.d.ts +93 -0
- package/dist/dts/state/test-interaction-context.d.ts.map +1 -0
- package/dist/dts/types/ai-chat-widget.d.ts +7 -6
- package/dist/dts/types/ai-chat-widget.d.ts.map +1 -1
- package/dist/dts/types/interaction-context.d.ts +128 -17
- package/dist/dts/types/interaction-context.d.ts.map +1 -1
- package/dist/dts/types/interaction-interceptor.d.ts +48 -6
- package/dist/dts/types/interaction-interceptor.d.ts.map +1 -1
- package/dist/dts/types/interaction-surface.d.ts +145 -23
- package/dist/dts/types/interaction-surface.d.ts.map +1 -1
- package/dist/dts/utils/delegated-message.d.ts +7 -0
- package/dist/dts/utils/delegated-message.d.ts.map +1 -1
- package/dist/esm/autopilot/autopilot-driver.js +313 -60
- package/dist/esm/autopilot/autopilot-session.js +219 -40
- package/dist/esm/autopilot/autopilot-tools.js +11 -7
- package/dist/esm/autopilot/decision-message.js +105 -26
- package/dist/esm/autopilot/hand-back/hand-back.controller.js +2 -1
- package/dist/esm/autopilot/index.js +1 -0
- package/dist/esm/autopilot/widget-tools.js +39 -0
- package/dist/esm/components/agent-session/agent-session.js +3 -2
- package/dist/esm/components/ai-driver/base-driver-decorator.js +17 -0
- package/dist/esm/components/chat-driver/chat-driver.js +18 -2
- package/dist/esm/components/chat-driver/interaction-controller.js +232 -71
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +14 -6
- package/dist/esm/components/settings-modal/settings-modal.template.js +2 -2
- package/dist/esm/config/define-stateful-agent.js +22 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/main/main.js +88 -35
- package/dist/esm/main/main.template.js +4 -1
- package/dist/esm/notifications/agent-notifications.js +11 -1
- package/dist/esm/notifications/agent-notifier.js +41 -7
- package/dist/esm/state/debug-event-log.js +6 -6
- package/dist/esm/state/decision-surface.js +137 -54
- package/dist/esm/state/interaction-context.js +41 -8
- package/dist/esm/state/interaction-registry.js +11 -0
- package/dist/esm/state/live-interactions.js +36 -0
- package/dist/esm/state/persistence/session-persister.js +55 -18
- package/dist/esm/state/persistence/session-snapshot.js +2 -2
- package/dist/esm/state/test-interaction-context.js +99 -0
- package/docs/notifications.md +55 -5
- package/docs/styling.md +33 -0
- package/package.json +19 -19
- package/sandbox/README.md +3 -2
- package/sandbox/autopilot.ts +26 -6
- package/sandbox/sandbox.ts +2 -0
- /package/dist/{tsdoc-metadata.json → dts/tsdoc-metadata.json} +0 -0
package/dist/chat-driver.mjs
CHANGED
|
@@ -4034,8 +4034,8 @@ var META_EVENT_IMPORTANCE = {
|
|
|
4034
4034
|
"interaction.outcome-dropped": "high",
|
|
4035
4035
|
// A long action's step starting, finishing, or skipped on resume because it was already done.
|
|
4036
4036
|
"interaction.step": "low",
|
|
4037
|
-
// A cut checkpoint taken over after a reload, refused (by sameWork,
|
|
4038
|
-
// at flow end.
|
|
4037
|
+
// A cut checkpoint taken over after a reload, refused (by sameWork, and kept for a later request;
|
|
4038
|
+
// or as malformed), or dropped at flow end, as is the live one.
|
|
4039
4039
|
"interaction.checkpoint": "normal",
|
|
4040
4040
|
// A claimant handing a pending interaction to the person, or taking it back.
|
|
4041
4041
|
"interaction.held": "normal",
|
|
@@ -4937,9 +4937,10 @@ var AgentSession = class {
|
|
|
4937
4937
|
/**
|
|
4938
4938
|
* The name routing is locked to, flow lock first. A flow in progress outranks the user's
|
|
4939
4939
|
* sticky pick for the duration of the flow; neither being set means automatic routing.
|
|
4940
|
+
* `pin`, when given, stands in for the sticky pick: one message routed its own way.
|
|
4940
4941
|
*/
|
|
4941
|
-
getLockedName() {
|
|
4942
|
-
return this.flowOwner ??
|
|
4942
|
+
getLockedName(pin = this.pinned) {
|
|
4943
|
+
return this.flowOwner ?? pin;
|
|
4943
4944
|
}
|
|
4944
4945
|
/** Set the sticky user pin. `null` returns to automatic routing. */
|
|
4945
4946
|
setPinned(name) {
|
|
@@ -5273,14 +5274,22 @@ var FoldController = class {
|
|
|
5273
5274
|
// src/state/decision-surface.ts
|
|
5274
5275
|
var SELECT_ACTION = "select";
|
|
5275
5276
|
var REPLY_ACTION = "reply";
|
|
5276
|
-
var normalise = (option) => typeof option === "string" ? { id: option, label: option } : { id: option.id ?? option.label, label: option.label,
|
|
5277
|
-
var
|
|
5277
|
+
var normalise = (option) => typeof option === "string" ? { id: option, label: option } : { id: option.id ?? option.label, label: option.label, unavailable: option.unavailable };
|
|
5278
|
+
var GENERIC_UNAVAILABLE = "not available in this state";
|
|
5279
|
+
function unavailableReason(guard, ...args) {
|
|
5280
|
+
if (!guard) return void 0;
|
|
5278
5281
|
try {
|
|
5279
|
-
|
|
5282
|
+
const reason = guard(...args);
|
|
5283
|
+
if (reason === void 0) return void 0;
|
|
5284
|
+
return reason.trim().replace(/\.+$/, "") || GENERIC_UNAVAILABLE;
|
|
5280
5285
|
} catch {
|
|
5281
|
-
return
|
|
5286
|
+
return GENERIC_UNAVAILABLE;
|
|
5282
5287
|
}
|
|
5283
|
-
}
|
|
5288
|
+
}
|
|
5289
|
+
var reasonFor = (option) => unavailableReason(option.unavailable);
|
|
5290
|
+
var isEnabled = (option) => reasonFor(option) === void 0;
|
|
5291
|
+
var describeViews = (views) => Object.fromEntries(Object.entries(views).map(([name, v]) => [name, v.description]));
|
|
5292
|
+
var readView = (views, view) => Object.prototype.hasOwnProperty.call(views, view) ? views[view].read() : void 0;
|
|
5284
5293
|
function buildDecisionSurface(spec) {
|
|
5285
5294
|
const options = spec.options.map(normalise);
|
|
5286
5295
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -5295,12 +5304,16 @@ function buildDecisionSurface(spec) {
|
|
|
5295
5304
|
const actions = () => {
|
|
5296
5305
|
const enabled = options.filter(isEnabled);
|
|
5297
5306
|
return [
|
|
5298
|
-
...options.map((o) =>
|
|
5299
|
-
|
|
5300
|
-
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5307
|
+
...options.map((o) => {
|
|
5308
|
+
const unavailable = reasonFor(o);
|
|
5309
|
+
return {
|
|
5310
|
+
name: o.id,
|
|
5311
|
+
label: o.label,
|
|
5312
|
+
finishes: true,
|
|
5313
|
+
enabled: unavailable === void 0,
|
|
5314
|
+
...unavailable !== void 0 ? { unavailable } : {}
|
|
5315
|
+
};
|
|
5316
|
+
}),
|
|
5304
5317
|
...spec.multi ? [
|
|
5305
5318
|
{
|
|
5306
5319
|
name: SELECT_ACTION,
|
|
@@ -5309,13 +5322,32 @@ function buildDecisionSurface(spec) {
|
|
|
5309
5322
|
args: "options"
|
|
5310
5323
|
}
|
|
5311
5324
|
] : [],
|
|
5312
|
-
...spec.freeText ? [
|
|
5325
|
+
...spec.freeText ? [replyAction()] : []
|
|
5313
5326
|
];
|
|
5314
5327
|
};
|
|
5328
|
+
const replyReason = () => unavailableReason(spec.freeTextUnavailable);
|
|
5329
|
+
const replyAction = () => {
|
|
5330
|
+
const unavailable = replyReason();
|
|
5331
|
+
return {
|
|
5332
|
+
name: REPLY_ACTION,
|
|
5333
|
+
finishes: true,
|
|
5334
|
+
enabled: unavailable === void 0,
|
|
5335
|
+
...unavailable !== void 0 ? { unavailable } : {},
|
|
5336
|
+
args: "text",
|
|
5337
|
+
refines: true
|
|
5338
|
+
};
|
|
5339
|
+
};
|
|
5315
5340
|
const answer = (a) => () => spec.choose(a);
|
|
5341
|
+
const facts = () => spec.facts?.() ?? {};
|
|
5342
|
+
const views = spec.views && Object.keys(spec.views).length ? spec.views : void 0;
|
|
5343
|
+
const readable = views ? {
|
|
5344
|
+
views: describeViews(views),
|
|
5345
|
+
read: (view) => view === void 0 ? facts() : readView(views, view)
|
|
5346
|
+
} : {};
|
|
5316
5347
|
return {
|
|
5317
5348
|
prompt: spec.prompt,
|
|
5318
|
-
facts
|
|
5349
|
+
facts,
|
|
5350
|
+
...readable,
|
|
5319
5351
|
actions,
|
|
5320
5352
|
isReady: () => actions().some((a) => a.finishes && a.enabled),
|
|
5321
5353
|
prepare(name, args) {
|
|
@@ -5336,7 +5368,7 @@ function buildDecisionSurface(spec) {
|
|
|
5336
5368
|
if (disabled.length) {
|
|
5337
5369
|
return {
|
|
5338
5370
|
error: "disabled",
|
|
5339
|
-
message: `Not available right now: ${disabled.map((o) => o.label).join(", ")}.`
|
|
5371
|
+
message: `Not available right now: ${disabled.map((o) => `${o.label} (${reasonFor(o)})`).join(", ")}.`
|
|
5340
5372
|
};
|
|
5341
5373
|
}
|
|
5342
5374
|
const picks = chosen;
|
|
@@ -5347,6 +5379,10 @@ function buildDecisionSurface(spec) {
|
|
|
5347
5379
|
};
|
|
5348
5380
|
}
|
|
5349
5381
|
if (spec.freeText && name === REPLY_ACTION) {
|
|
5382
|
+
const why2 = replyReason();
|
|
5383
|
+
if (why2 !== void 0) {
|
|
5384
|
+
return { error: "disabled", message: `"reply" is not available right now: ${why2}.` };
|
|
5385
|
+
}
|
|
5350
5386
|
const text = args?.text;
|
|
5351
5387
|
if (typeof text !== "string" || !text.trim()) {
|
|
5352
5388
|
return { error: "invalid-args", message: "`reply` takes { text: string }, not empty." };
|
|
@@ -5357,8 +5393,12 @@ function buildDecisionSurface(spec) {
|
|
|
5357
5393
|
if (!option) {
|
|
5358
5394
|
return { error: "unknown-action", message: `No action "${name}" here.` };
|
|
5359
5395
|
}
|
|
5360
|
-
|
|
5361
|
-
|
|
5396
|
+
const why = reasonFor(option);
|
|
5397
|
+
if (why !== void 0) {
|
|
5398
|
+
return {
|
|
5399
|
+
error: "disabled",
|
|
5400
|
+
message: `"${option.label}" is not available right now: ${why}.`
|
|
5401
|
+
};
|
|
5362
5402
|
}
|
|
5363
5403
|
return {
|
|
5364
5404
|
choice: option.label,
|
|
@@ -5398,33 +5438,65 @@ function checkArgs(args, schema) {
|
|
|
5398
5438
|
return wrong.length ? `${wrong.join("; ")}.` : void 0;
|
|
5399
5439
|
}
|
|
5400
5440
|
function buildFullSurface(spec) {
|
|
5401
|
-
const
|
|
5402
|
-
|
|
5403
|
-
|
|
5404
|
-
|
|
5405
|
-
|
|
5441
|
+
for (const [name, action] of Object.entries(spec.actions)) {
|
|
5442
|
+
if (action.text && action.argsSchema) {
|
|
5443
|
+
throw new Error(
|
|
5444
|
+
`exposeSurface: action "${name}" takes \`text\` or \`argsSchema\`, not both.`
|
|
5445
|
+
);
|
|
5406
5446
|
}
|
|
5407
|
-
}
|
|
5408
|
-
const
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
|
|
5414
|
-
|
|
5447
|
+
}
|
|
5448
|
+
const views = spec.views && Object.keys(spec.views).length ? spec.views : void 0;
|
|
5449
|
+
if (spec.preview !== void 0 && !(views && Object.prototype.hasOwnProperty.call(views, spec.preview))) {
|
|
5450
|
+
throw new Error(`exposeSurface: the preview "${spec.preview}" is not one of its views.`);
|
|
5451
|
+
}
|
|
5452
|
+
const actions = () => Object.entries(spec.actions).map(([name, a]) => {
|
|
5453
|
+
const unavailable = unavailableReason(a.unavailable);
|
|
5454
|
+
return {
|
|
5455
|
+
name,
|
|
5456
|
+
finishes: !!a.finishes,
|
|
5457
|
+
enabled: unavailable === void 0,
|
|
5458
|
+
...unavailable !== void 0 ? { unavailable } : {},
|
|
5459
|
+
description: a.description,
|
|
5460
|
+
...a.text ? { args: "text" } : {},
|
|
5461
|
+
...a.argsSchema ? { args: "fields", argsSchema: a.argsSchema } : {},
|
|
5462
|
+
...a.refines ? { refines: true } : {}
|
|
5463
|
+
};
|
|
5464
|
+
});
|
|
5415
5465
|
return {
|
|
5416
5466
|
prompt: spec.prompt,
|
|
5417
5467
|
facts: () => ({}),
|
|
5418
5468
|
describe: () => spec.describe(),
|
|
5419
|
-
views
|
|
5420
|
-
|
|
5469
|
+
...views ? {
|
|
5470
|
+
views: describeViews(views),
|
|
5471
|
+
...spec.preview !== void 0 ? { preview: spec.preview } : {},
|
|
5472
|
+
read: (view) => {
|
|
5473
|
+
const name = view ?? spec.preview;
|
|
5474
|
+
return name === void 0 ? void 0 : readView(views, name);
|
|
5475
|
+
}
|
|
5476
|
+
} : {},
|
|
5421
5477
|
actions,
|
|
5422
5478
|
isReady: () => actions().some((a) => a.enabled),
|
|
5423
5479
|
prepare(name, args) {
|
|
5424
5480
|
const action = Object.prototype.hasOwnProperty.call(spec.actions, name) ? spec.actions[name] : void 0;
|
|
5425
5481
|
if (!action) return { error: "unknown-action", message: `No action "${name}" here.` };
|
|
5426
|
-
|
|
5427
|
-
|
|
5482
|
+
const why = unavailableReason(action.unavailable);
|
|
5483
|
+
if (why !== void 0) {
|
|
5484
|
+
return { error: "disabled", message: `"${name}" is not available right now: ${why}.` };
|
|
5485
|
+
}
|
|
5486
|
+
if (action.text) {
|
|
5487
|
+
const text = args?.text;
|
|
5488
|
+
if (typeof text !== "string" || !text.trim()) {
|
|
5489
|
+
return {
|
|
5490
|
+
error: "invalid-args",
|
|
5491
|
+
message: `"${name}" takes its argument as \`text\`, not empty.`
|
|
5492
|
+
};
|
|
5493
|
+
}
|
|
5494
|
+
const trimmed = text.trim();
|
|
5495
|
+
return {
|
|
5496
|
+
choice: `${name}: ${trimmed}`.slice(0, CHOICE_CHARS),
|
|
5497
|
+
finishes: !!action.finishes,
|
|
5498
|
+
run: () => action.run(trimmed)
|
|
5499
|
+
};
|
|
5428
5500
|
}
|
|
5429
5501
|
const problem = checkArgs(args ?? {}, action.argsSchema);
|
|
5430
5502
|
if (problem) return { error: "invalid-args", message: `"${name}": ${problem}` };
|
|
@@ -5452,15 +5524,21 @@ function createInteractionContext(interactionId, deps = {}) {
|
|
|
5452
5524
|
let surface;
|
|
5453
5525
|
let lastActivityAt = Date.now();
|
|
5454
5526
|
let checkpoint = deps.checkpoint;
|
|
5527
|
+
let working;
|
|
5455
5528
|
let offered = false;
|
|
5456
5529
|
let attention;
|
|
5457
5530
|
let attentionDone = false;
|
|
5531
|
+
let attentionTaker;
|
|
5458
5532
|
const reportAttention = () => {
|
|
5459
5533
|
if (!offered || !attention || attentionDone || disposed || settled) return;
|
|
5460
5534
|
attentionDone = true;
|
|
5461
5535
|
if (heldBy !== "user") return;
|
|
5462
|
-
deps.requestAttention?.(attention.message);
|
|
5536
|
+
(attentionTaker ?? deps.requestAttention)?.(attention.message);
|
|
5463
5537
|
};
|
|
5538
|
+
const reporting = (built) => ({
|
|
5539
|
+
...built,
|
|
5540
|
+
isReady: () => working === false || working !== true && built.isReady()
|
|
5541
|
+
});
|
|
5464
5542
|
const checkReady = () => {
|
|
5465
5543
|
if (disposed || !surface || readyListeners.size === 0 || !surface.isReady()) return;
|
|
5466
5544
|
const waiting = [...readyListeners];
|
|
@@ -5491,6 +5569,14 @@ function createInteractionContext(interactionId, deps = {}) {
|
|
|
5491
5569
|
get checkpoint() {
|
|
5492
5570
|
return checkpoint;
|
|
5493
5571
|
},
|
|
5572
|
+
get working() {
|
|
5573
|
+
return working;
|
|
5574
|
+
},
|
|
5575
|
+
setWorking(next) {
|
|
5576
|
+
if (disposed || next === working) return;
|
|
5577
|
+
working = next;
|
|
5578
|
+
context.notify();
|
|
5579
|
+
},
|
|
5494
5580
|
saveCheckpoint(next) {
|
|
5495
5581
|
if (disposed) return;
|
|
5496
5582
|
checkpoint = next;
|
|
@@ -5533,19 +5619,19 @@ function createInteractionContext(interactionId, deps = {}) {
|
|
|
5533
5619
|
}
|
|
5534
5620
|
disposers.add(fn);
|
|
5535
5621
|
},
|
|
5536
|
-
resolve(result) {
|
|
5622
|
+
resolve(result, options) {
|
|
5537
5623
|
if (settled || disposed) return;
|
|
5538
5624
|
settled = true;
|
|
5539
|
-
deps.resolve?.(result);
|
|
5625
|
+
deps.resolve?.(result, options);
|
|
5540
5626
|
},
|
|
5541
5627
|
exposeDecision(decision) {
|
|
5542
5628
|
if (disposed) return;
|
|
5543
|
-
surface = buildDecisionSurface(decision);
|
|
5629
|
+
surface = reporting(buildDecisionSurface(decision));
|
|
5544
5630
|
context.notify();
|
|
5545
5631
|
},
|
|
5546
5632
|
exposeSurface(spec) {
|
|
5547
5633
|
if (disposed) return;
|
|
5548
|
-
surface = buildFullSurface(spec);
|
|
5634
|
+
surface = reporting(buildFullSurface(spec));
|
|
5549
5635
|
context.notify();
|
|
5550
5636
|
},
|
|
5551
5637
|
onSurfaceReady(fn) {
|
|
@@ -5599,6 +5685,16 @@ function createInteractionContext(interactionId, deps = {}) {
|
|
|
5599
5685
|
offered = true;
|
|
5600
5686
|
reportAttention();
|
|
5601
5687
|
},
|
|
5688
|
+
get attentionMessage() {
|
|
5689
|
+
return attention?.message;
|
|
5690
|
+
},
|
|
5691
|
+
takeAttention(onRequest) {
|
|
5692
|
+
if (attentionDone || disposed || settled || attentionTaker) return void 0;
|
|
5693
|
+
attentionTaker = onRequest;
|
|
5694
|
+
return () => {
|
|
5695
|
+
if (attentionTaker === onRequest) attentionTaker = void 0;
|
|
5696
|
+
};
|
|
5697
|
+
},
|
|
5602
5698
|
get surface() {
|
|
5603
5699
|
return surface;
|
|
5604
5700
|
}
|
|
@@ -5611,6 +5707,15 @@ function getInteractionRegistration(name) {
|
|
|
5611
5707
|
return registry2.get(name);
|
|
5612
5708
|
}
|
|
5613
5709
|
|
|
5710
|
+
// src/state/live-interactions.ts
|
|
5711
|
+
var live = /* @__PURE__ */ new Map();
|
|
5712
|
+
function trackInteractionContext(context) {
|
|
5713
|
+
live.set(context.interactionId, context);
|
|
5714
|
+
return () => {
|
|
5715
|
+
if (live.get(context.interactionId) === context) live.delete(context.interactionId);
|
|
5716
|
+
};
|
|
5717
|
+
}
|
|
5718
|
+
|
|
5614
5719
|
// src/state/run-steps.ts
|
|
5615
5720
|
var recorders = /* @__PURE__ */ new WeakMap();
|
|
5616
5721
|
function bindStepRecorder(ctx, record, refused) {
|
|
@@ -5659,6 +5764,19 @@ function doneOnUsersBehalf(interaction, answeredBy) {
|
|
|
5659
5764
|
}
|
|
5660
5765
|
return {};
|
|
5661
5766
|
}
|
|
5767
|
+
function stampAnsweredBy(result, answeredBy) {
|
|
5768
|
+
if (result === null || typeof result !== "object" || Array.isArray(result)) return result;
|
|
5769
|
+
const copy = { ...result };
|
|
5770
|
+
if (answeredBy) copy.answeredBy = answeredBy;
|
|
5771
|
+
else delete copy.answeredBy;
|
|
5772
|
+
return copy;
|
|
5773
|
+
}
|
|
5774
|
+
function whoAnswered(interaction, result, how) {
|
|
5775
|
+
const unanswered = result?.status === "timeout";
|
|
5776
|
+
const resolvedItself = !unanswered && !interaction.settledBy && (!!interaction.resolvesItself || how?.resolvedItself === true);
|
|
5777
|
+
if (unanswered || resolvedItself) return { resolvedItself };
|
|
5778
|
+
return { answeredBy: interaction.settledBy ?? "user", resolvedItself };
|
|
5779
|
+
}
|
|
5662
5780
|
var STOPPED = {
|
|
5663
5781
|
status: "timeout",
|
|
5664
5782
|
message: "The turn was stopped before this was answered."
|
|
@@ -5681,58 +5799,118 @@ var InteractionController = class {
|
|
|
5681
5799
|
* the root's are ever consulted: a sub-agent's request is opened by the root.
|
|
5682
5800
|
*/
|
|
5683
5801
|
this.interceptors = [];
|
|
5802
|
+
/**
|
|
5803
|
+
* Checkpoints a reload cut, oldest first, each waiting for a request of its own widget type that
|
|
5804
|
+
* `sameWork` agrees is the same work. Held apart from `live`, so neither the work a resumed flow
|
|
5805
|
+
* does first nor a request `sameWork` refuses can lose one: a flow may open other long widgets
|
|
5806
|
+
* before the one a checkpoint belongs to asks for it. Each leaves when it is taken over, and all
|
|
5807
|
+
* of them when the flow ends.
|
|
5808
|
+
*/
|
|
5809
|
+
this.cut = [];
|
|
5684
5810
|
}
|
|
5685
|
-
/**
|
|
5811
|
+
/**
|
|
5812
|
+
* See `ChatDriver.getInteractionCheckpoints`: every checkpoint to save with the session — those a
|
|
5813
|
+
* reload cut that nothing has taken yet, oldest first, then the live interaction's. A reload cuts
|
|
5814
|
+
* them all, so all of them are restored as cut.
|
|
5815
|
+
*/
|
|
5816
|
+
getCheckpoints() {
|
|
5817
|
+
const live2 = this.live;
|
|
5818
|
+
return [
|
|
5819
|
+
...this.cut.map(({ componentName, value }) => ({ componentName, value })),
|
|
5820
|
+
...live2 ? [{ componentName: live2.componentName, value: live2.value }] : []
|
|
5821
|
+
];
|
|
5822
|
+
}
|
|
5823
|
+
/**
|
|
5824
|
+
* See `ChatDriver.getInteractionCheckpoint` (deprecated): one checkpoint, the live interaction's,
|
|
5825
|
+
* else the newest a reload cut.
|
|
5826
|
+
*/
|
|
5686
5827
|
getCheckpoint() {
|
|
5687
|
-
const
|
|
5688
|
-
return
|
|
5828
|
+
const all = this.getCheckpoints();
|
|
5829
|
+
return all[all.length - 1];
|
|
5689
5830
|
}
|
|
5690
|
-
/**
|
|
5831
|
+
/**
|
|
5832
|
+
* See `ChatDriver.restoreInteractionCheckpoints`. Restored means cut: their interactions are gone.
|
|
5833
|
+
* Replaces whatever was held.
|
|
5834
|
+
*/
|
|
5835
|
+
restoreCheckpoints(saved) {
|
|
5836
|
+
this.live = void 0;
|
|
5837
|
+
this.cut = (saved ?? []).map(({ componentName, value }) => ({ componentName, value }));
|
|
5838
|
+
}
|
|
5839
|
+
/** See `ChatDriver.restoreInteractionCheckpoint` (deprecated): one, or none. */
|
|
5691
5840
|
restoreCheckpoint(saved) {
|
|
5692
|
-
this.
|
|
5841
|
+
this.restoreCheckpoints(saved ? [saved] : []);
|
|
5693
5842
|
}
|
|
5694
|
-
/** Drop
|
|
5843
|
+
/** Drop every checkpoint, used or not, cut or live, when its flow ends. */
|
|
5695
5844
|
clearCheckpoint(why) {
|
|
5696
|
-
const
|
|
5697
|
-
|
|
5698
|
-
this.
|
|
5699
|
-
|
|
5700
|
-
|
|
5701
|
-
|
|
5702
|
-
|
|
5703
|
-
|
|
5704
|
-
|
|
5845
|
+
const live2 = this.live;
|
|
5846
|
+
const cut = this.cut;
|
|
5847
|
+
this.live = void 0;
|
|
5848
|
+
this.cut = [];
|
|
5849
|
+
for (const cp of cut) {
|
|
5850
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.checkpoint", {
|
|
5851
|
+
action: "cleared",
|
|
5852
|
+
component: cp.componentName,
|
|
5853
|
+
why,
|
|
5854
|
+
cut: true
|
|
5855
|
+
});
|
|
5856
|
+
}
|
|
5857
|
+
if (live2) {
|
|
5858
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.checkpoint", {
|
|
5859
|
+
action: "cleared",
|
|
5860
|
+
component: live2.componentName,
|
|
5861
|
+
why,
|
|
5862
|
+
interactionId: live2.interactionId
|
|
5863
|
+
});
|
|
5864
|
+
}
|
|
5705
5865
|
}
|
|
5706
5866
|
/**
|
|
5707
|
-
*
|
|
5708
|
-
*
|
|
5709
|
-
*
|
|
5867
|
+
* Offer the checkpoints a reload cut to a new request of their widget type, newest first, and
|
|
5868
|
+
* hand it the first its registration's `sameWork` agrees is the same work (any, without one). A
|
|
5869
|
+
* checkpoint `sameWork` refuses stays where it is, for a later request of the same type: a flow
|
|
5870
|
+
* may ask for other work of that type first. Each refusal is recorded, with the identity kept.
|
|
5710
5871
|
*/
|
|
5711
5872
|
takeOverCheckpoint(componentName, data, interactionId) {
|
|
5712
|
-
const cut = this.checkpoint;
|
|
5713
|
-
if (!cut?.cut || cut.componentName !== componentName) return void 0;
|
|
5714
|
-
this.checkpoint = void 0;
|
|
5715
5873
|
const sameWork = getInteractionRegistration(componentName)?.sameWork;
|
|
5716
|
-
let
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
|
|
5722
|
-
|
|
5874
|
+
for (let i = this.cut.length - 1; i >= 0; i -= 1) {
|
|
5875
|
+
const cut = this.cut[i];
|
|
5876
|
+
if (cut.componentName !== componentName) continue;
|
|
5877
|
+
let agrees = true;
|
|
5878
|
+
if (sameWork) {
|
|
5879
|
+
try {
|
|
5880
|
+
agrees = sameWork(cut.value, data);
|
|
5881
|
+
} catch (e) {
|
|
5882
|
+
logger2.warn(
|
|
5883
|
+
`InteractionController: "${componentName}" sameWork threw; not taking it over:`,
|
|
5884
|
+
e
|
|
5885
|
+
);
|
|
5886
|
+
agrees = false;
|
|
5887
|
+
}
|
|
5723
5888
|
}
|
|
5889
|
+
if (!agrees) {
|
|
5890
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.checkpoint", {
|
|
5891
|
+
action: "refused",
|
|
5892
|
+
component: componentName,
|
|
5893
|
+
interactionId,
|
|
5894
|
+
saved: cut.value,
|
|
5895
|
+
kept: true
|
|
5896
|
+
});
|
|
5897
|
+
continue;
|
|
5898
|
+
}
|
|
5899
|
+
this.cut.splice(i, 1);
|
|
5900
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.checkpoint", {
|
|
5901
|
+
action: "resumed",
|
|
5902
|
+
component: componentName,
|
|
5903
|
+
interactionId
|
|
5904
|
+
});
|
|
5905
|
+
this.live = { componentName, value: cut.value, interactionId };
|
|
5906
|
+
return cut.value;
|
|
5724
5907
|
}
|
|
5725
|
-
|
|
5726
|
-
action: agrees ? "resumed" : "refused",
|
|
5727
|
-
component: componentName,
|
|
5728
|
-
interactionId,
|
|
5729
|
-
...agrees ? {} : { saved: cut.value }
|
|
5730
|
-
});
|
|
5731
|
-
if (!agrees) return void 0;
|
|
5732
|
-
this.checkpoint = { componentName, value: cut.value, interactionId };
|
|
5733
|
-
return cut.value;
|
|
5908
|
+
return void 0;
|
|
5734
5909
|
}
|
|
5735
|
-
/**
|
|
5910
|
+
/**
|
|
5911
|
+
* A controller's `ctx.saveCheckpoint`: kept as JSON, the form it is persisted in. Replaces the
|
|
5912
|
+
* live interaction's only; the checkpoints a reload cut are left waiting for their own widgets.
|
|
5913
|
+
*/
|
|
5736
5914
|
saveCheckpoint(interactionId, componentName, value) {
|
|
5737
5915
|
if (!this.pending.has(interactionId)) return;
|
|
5738
5916
|
let copy;
|
|
@@ -5745,7 +5923,7 @@ var InteractionController = class {
|
|
|
5745
5923
|
);
|
|
5746
5924
|
return;
|
|
5747
5925
|
}
|
|
5748
|
-
this.
|
|
5926
|
+
this.live = { componentName, value: copy, interactionId };
|
|
5749
5927
|
this.deps.emit(new CustomEvent("checkpoint-saved", { detail: { interactionId } }));
|
|
5750
5928
|
}
|
|
5751
5929
|
/** See `ChatDriver.addInteractionInterceptor`. Returns a remover. */
|
|
@@ -5772,11 +5950,34 @@ var InteractionController = class {
|
|
|
5772
5950
|
*
|
|
5773
5951
|
* Runs before the interaction's message is appended, so the widget's first render already knows
|
|
5774
5952
|
* its holder and nothing appears only to disappear.
|
|
5953
|
+
*
|
|
5954
|
+
* **A late claim.** An interceptor that declined may still claim it later, through its hold's
|
|
5955
|
+
* `claim`, once the asking is over and while nobody else has (see {@link InteractionHold.claim}).
|
|
5775
5956
|
*/
|
|
5776
5957
|
offer(handle, opened) {
|
|
5777
5958
|
let claimant;
|
|
5959
|
+
let asking = true;
|
|
5960
|
+
const claimLate = (interceptor) => {
|
|
5961
|
+
if (asking || claimant || opened.userOnly) return false;
|
|
5962
|
+
const pending = this.pending.get(opened.interactionId);
|
|
5963
|
+
if (!pending || !handle.setHeldBy(interceptor.id)) return false;
|
|
5964
|
+
claimant = interceptor;
|
|
5965
|
+
pending.claimant = interceptor;
|
|
5966
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.held", {
|
|
5967
|
+
interactionId: opened.interactionId,
|
|
5968
|
+
heldBy: interceptor.id,
|
|
5969
|
+
claimant: interceptor.id,
|
|
5970
|
+
late: true
|
|
5971
|
+
});
|
|
5972
|
+
return true;
|
|
5973
|
+
};
|
|
5778
5974
|
for (const interceptor of [...this.interceptors].reverse()) {
|
|
5779
|
-
const hold = this.holdFor(
|
|
5975
|
+
const hold = this.holdFor(
|
|
5976
|
+
handle,
|
|
5977
|
+
interceptor,
|
|
5978
|
+
() => claimant === interceptor,
|
|
5979
|
+
() => claimLate(interceptor)
|
|
5980
|
+
);
|
|
5780
5981
|
let answer;
|
|
5781
5982
|
try {
|
|
5782
5983
|
answer = interceptor.onInteractionOpened({ ...opened, ctx: handle.context, hold });
|
|
@@ -5798,11 +5999,39 @@ var InteractionController = class {
|
|
|
5798
5999
|
const pending = this.pending.get(opened.interactionId);
|
|
5799
6000
|
if (pending) pending.claimant = interceptor;
|
|
5800
6001
|
}
|
|
6002
|
+
asking = false;
|
|
5801
6003
|
return handle.context.heldBy;
|
|
5802
6004
|
}
|
|
5803
|
-
/**
|
|
5804
|
-
|
|
6005
|
+
/**
|
|
6006
|
+
* Publish `agent-attention-ended` each time the interaction stops waiting on the person — a
|
|
6007
|
+
* claimant takes it, or it settles — so a notification still showing for it is closed
|
|
6008
|
+
* (GENC-1660). Wired once who holds it is decided, so a claim made as it opens is not one.
|
|
6009
|
+
*/
|
|
6010
|
+
reportAttentionEnds(ctx) {
|
|
6011
|
+
const ended = () => this.deps.activityBus.publish("agent-attention-ended", {
|
|
6012
|
+
sessionKey: this.deps.sessionKey,
|
|
6013
|
+
interactionId: ctx.interactionId
|
|
6014
|
+
});
|
|
6015
|
+
let heldBy = ctx.heldBy;
|
|
6016
|
+
const unsubscribe = ctx.subscribe(() => {
|
|
6017
|
+
if (ctx.heldBy === heldBy) return;
|
|
6018
|
+
heldBy = ctx.heldBy;
|
|
6019
|
+
if (heldBy !== "user") ended();
|
|
6020
|
+
});
|
|
6021
|
+
ctx.onDispose(() => {
|
|
6022
|
+
unsubscribe();
|
|
6023
|
+
ended();
|
|
6024
|
+
});
|
|
6025
|
+
}
|
|
6026
|
+
/**
|
|
6027
|
+
* The {@link InteractionHold} for one interceptor: it applies only while that one is the claimant,
|
|
6028
|
+
* which `claim` can make it after the asking, if nobody else is.
|
|
6029
|
+
*/
|
|
6030
|
+
holdFor(handle, interceptor, isClaimant, claim) {
|
|
5805
6031
|
return {
|
|
6032
|
+
claim,
|
|
6033
|
+
attentionMessage: () => handle.attentionMessage,
|
|
6034
|
+
takeAttention: (onRequest) => handle.takeAttention(onRequest),
|
|
5806
6035
|
set: (holder) => {
|
|
5807
6036
|
if (!isClaimant()) return false;
|
|
5808
6037
|
const next = holder === "user" ? "user" : interceptor.id;
|
|
@@ -5946,6 +6175,9 @@ var InteractionController = class {
|
|
|
5946
6175
|
reject,
|
|
5947
6176
|
onSettled,
|
|
5948
6177
|
overrideId: chatInputDuringExecution ? interactionId : void 0,
|
|
6178
|
+
...getInteractionRegistration(componentName)?.resolvesItself === true && {
|
|
6179
|
+
resolvesItself: true
|
|
6180
|
+
},
|
|
5949
6181
|
// Resolve the interaction with a timeout result if the user does not
|
|
5950
6182
|
// respond in time. `resolve` runs the same teardown a normal resolution
|
|
5951
6183
|
// does (marks the widget read-only, reverts any input override) and
|
|
@@ -5959,7 +6191,7 @@ var InteractionController = class {
|
|
|
5959
6191
|
});
|
|
5960
6192
|
const handle = createInteractionContext(interactionId, {
|
|
5961
6193
|
sessionKey: this.deps.sessionKey,
|
|
5962
|
-
resolve: (result) => this.resolve(interactionId, result),
|
|
6194
|
+
resolve: (result, how) => this.resolve(interactionId, result, how),
|
|
5963
6195
|
checkpoint: this.takeOverCheckpoint(componentName, data, interactionId),
|
|
5964
6196
|
saveCheckpoint: (value) => this.saveCheckpoint(interactionId, componentName, value),
|
|
5965
6197
|
requestAttention: (message) => this.deps.activityBus.publish("agent-attention", {
|
|
@@ -5970,6 +6202,7 @@ var InteractionController = class {
|
|
|
5970
6202
|
})
|
|
5971
6203
|
});
|
|
5972
6204
|
this.contexts.set(interactionId, handle);
|
|
6205
|
+
handle.context.onDispose(trackInteractionContext(handle.context));
|
|
5973
6206
|
bindStepRecorder(
|
|
5974
6207
|
handle.context,
|
|
5975
6208
|
(step, outcome) => recordMetaEvent(this.deps.sessionKey, "interaction.step", {
|
|
@@ -6002,6 +6235,7 @@ var InteractionController = class {
|
|
|
6002
6235
|
userOnly: options?.userOnly === true
|
|
6003
6236
|
});
|
|
6004
6237
|
handle.markOffered();
|
|
6238
|
+
this.reportAttentionEnds(handle.context);
|
|
6005
6239
|
recordMetaEvent(this.deps.sessionKey, "interaction.requested", {
|
|
6006
6240
|
interactionId,
|
|
6007
6241
|
component: componentName,
|
|
@@ -6031,7 +6265,7 @@ var InteractionController = class {
|
|
|
6031
6265
|
const opened = this.pending.get(interactionId);
|
|
6032
6266
|
if (opened) {
|
|
6033
6267
|
opened.appended = true;
|
|
6034
|
-
if (opened.early) this.resolve(interactionId, opened.early.result);
|
|
6268
|
+
if (opened.early) this.resolve(interactionId, opened.early.result, opened.early.options);
|
|
6035
6269
|
}
|
|
6036
6270
|
const signal = options?.signal;
|
|
6037
6271
|
if (signal) {
|
|
@@ -6050,16 +6284,17 @@ var InteractionController = class {
|
|
|
6050
6284
|
}
|
|
6051
6285
|
/**
|
|
6052
6286
|
* See `ChatDriver.resolveInteraction`. Warns and returns when the id is unknown — a widget can
|
|
6053
|
-
* report twice, and the second report has nothing left to settle.
|
|
6287
|
+
* report twice, and the second report has nothing left to settle. `how` is what a controller's
|
|
6288
|
+
* `ctx.resolve` said about the settle (`resolvedItself`); every other route passes none.
|
|
6054
6289
|
*/
|
|
6055
|
-
resolve(interactionId, result) {
|
|
6290
|
+
resolve(interactionId, result, how) {
|
|
6056
6291
|
const interaction = this.pending.get(interactionId);
|
|
6057
6292
|
if (!interaction) {
|
|
6058
6293
|
logger2.warn(`Interaction with ID ${interactionId} not found.`);
|
|
6059
6294
|
return;
|
|
6060
6295
|
}
|
|
6061
6296
|
if (!interaction.appended) {
|
|
6062
|
-
interaction.early ??= { result };
|
|
6297
|
+
interaction.early ??= { result, options: how };
|
|
6063
6298
|
return;
|
|
6064
6299
|
}
|
|
6065
6300
|
if (interaction.timeoutHandle) clearTimeout(interaction.timeoutHandle);
|
|
@@ -6069,8 +6304,7 @@ var InteractionController = class {
|
|
|
6069
6304
|
result?.diagnostics
|
|
6070
6305
|
);
|
|
6071
6306
|
const costUsd = typeof result?.costUsd === "number" && Number.isFinite(result.costUsd) && result.costUsd > 0 ? result.costUsd : void 0;
|
|
6072
|
-
const
|
|
6073
|
-
const answeredBy = unanswered ? void 0 : interaction.settledBy ?? "user";
|
|
6307
|
+
const { answeredBy, resolvedItself } = whoAnswered(interaction, result, how);
|
|
6074
6308
|
const run = answeredBy && answeredBy !== "user" ? interaction.running : void 0;
|
|
6075
6309
|
if (run) {
|
|
6076
6310
|
interaction.settledInRun = run.token;
|
|
@@ -6084,20 +6318,23 @@ var InteractionController = class {
|
|
|
6084
6318
|
...message.interaction,
|
|
6085
6319
|
resolved: result,
|
|
6086
6320
|
...answeredBy ? { answeredBy } : {},
|
|
6321
|
+
...resolvedItself ? { resolvedItself } : {},
|
|
6087
6322
|
...edits ? { edits } : {}
|
|
6088
6323
|
},
|
|
6089
6324
|
...costUsd != null ? { externalCostUsd: (message.externalCostUsd ?? 0) + costUsd } : {}
|
|
6090
6325
|
}));
|
|
6091
6326
|
if (patched) this.deps.notifyHistoryUpdated();
|
|
6092
6327
|
if (typeof result?.userMessage === "string" && result.userMessage.trim()) {
|
|
6093
|
-
|
|
6094
|
-
|
|
6328
|
+
if (!answeredBy || answeredBy === "user") {
|
|
6329
|
+
this.deps.appendToHistory({ role: "synthetic-user", content: result.userMessage });
|
|
6330
|
+
} else if (!run?.note) {
|
|
6331
|
+
this.deps.appendToHistory({
|
|
6095
6332
|
role: "assistant",
|
|
6096
6333
|
content: result.userMessage,
|
|
6097
6334
|
delegate: answeredBy,
|
|
6098
6335
|
excludeFromProvider: true
|
|
6099
|
-
}
|
|
6100
|
-
|
|
6336
|
+
});
|
|
6337
|
+
}
|
|
6101
6338
|
}
|
|
6102
6339
|
if (interaction.overrideId) {
|
|
6103
6340
|
this.deps.emit(new CustomEvent("interaction-stop", { detail: { interactionId } }));
|
|
@@ -6105,22 +6342,32 @@ var InteractionController = class {
|
|
|
6105
6342
|
recordMetaEvent(this.deps.sessionKey, "interaction.resolved", {
|
|
6106
6343
|
interactionId,
|
|
6107
6344
|
...answeredBy ? { answeredBy } : {},
|
|
6345
|
+
...resolvedItself ? { resolvedItself } : {},
|
|
6108
6346
|
...edits ? { edits: edits.length } : {}
|
|
6109
6347
|
});
|
|
6110
6348
|
this.deps.activityBus.publish("interaction-resolved", void 0);
|
|
6111
6349
|
try {
|
|
6112
|
-
interaction.onSettled?.({
|
|
6350
|
+
interaction.onSettled?.({
|
|
6351
|
+
answeredBy,
|
|
6352
|
+
...resolvedItself ? { resolvedItself } : {},
|
|
6353
|
+
decision,
|
|
6354
|
+
...edited ? { edited } : {}
|
|
6355
|
+
});
|
|
6113
6356
|
} catch (e) {
|
|
6114
6357
|
logger2.warn("InteractionController: onSettled threw:", e);
|
|
6115
6358
|
}
|
|
6116
6359
|
this.deps.emit(
|
|
6117
6360
|
new CustomEvent("interaction-settled", {
|
|
6118
|
-
detail: {
|
|
6361
|
+
detail: {
|
|
6362
|
+
interactionId,
|
|
6363
|
+
...answeredBy ? { answeredBy } : {},
|
|
6364
|
+
...resolvedItself ? { resolvedItself } : {}
|
|
6365
|
+
}
|
|
6119
6366
|
})
|
|
6120
6367
|
);
|
|
6121
|
-
interaction.resolve(result);
|
|
6368
|
+
interaction.resolve(stampAnsweredBy(result, answeredBy));
|
|
6122
6369
|
this.pending.delete(interactionId);
|
|
6123
|
-
if (this.
|
|
6370
|
+
if (this.live?.interactionId === interactionId) this.live = void 0;
|
|
6124
6371
|
this.contexts.get(interactionId)?.dispose();
|
|
6125
6372
|
this.contexts.delete(interactionId);
|
|
6126
6373
|
}
|
|
@@ -8048,11 +8295,27 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
8048
8295
|
getInteractionContext(interactionId) {
|
|
8049
8296
|
return this.interactions.context(interactionId);
|
|
8050
8297
|
}
|
|
8051
|
-
/** {@inheritDoc AiDriver.
|
|
8298
|
+
/** {@inheritDoc AiDriver.getInteractionCheckpoints} */
|
|
8299
|
+
getInteractionCheckpoints() {
|
|
8300
|
+
return this.interactions.getCheckpoints();
|
|
8301
|
+
}
|
|
8302
|
+
/** {@inheritDoc AiDriver.restoreInteractionCheckpoints} */
|
|
8303
|
+
restoreInteractionCheckpoints(saved) {
|
|
8304
|
+
this.interactions.restoreCheckpoints(saved);
|
|
8305
|
+
}
|
|
8306
|
+
/**
|
|
8307
|
+
* {@inheritDoc AiDriver.getInteractionCheckpoint}
|
|
8308
|
+
*
|
|
8309
|
+
* @deprecated Use `getInteractionCheckpoints`.
|
|
8310
|
+
*/
|
|
8052
8311
|
getInteractionCheckpoint() {
|
|
8053
8312
|
return this.interactions.getCheckpoint();
|
|
8054
8313
|
}
|
|
8055
|
-
/**
|
|
8314
|
+
/**
|
|
8315
|
+
* {@inheritDoc AiDriver.restoreInteractionCheckpoint}
|
|
8316
|
+
*
|
|
8317
|
+
* @deprecated Use `restoreInteractionCheckpoints`.
|
|
8318
|
+
*/
|
|
8056
8319
|
restoreInteractionCheckpoint(saved) {
|
|
8057
8320
|
this.interactions.restoreCheckpoint(saved);
|
|
8058
8321
|
}
|
|
@@ -9339,6 +9602,18 @@ var BaseDriverDecorator = class _BaseDriverDecorator extends EventTarget {
|
|
|
9339
9602
|
getFlowOwner() {
|
|
9340
9603
|
return this.inner.getFlowOwner?.() ?? null;
|
|
9341
9604
|
}
|
|
9605
|
+
getInteractionCheckpoints() {
|
|
9606
|
+
if (this.inner.getInteractionCheckpoints) return this.inner.getInteractionCheckpoints();
|
|
9607
|
+
const one = this.inner.getInteractionCheckpoint?.();
|
|
9608
|
+
return one ? [one] : [];
|
|
9609
|
+
}
|
|
9610
|
+
restoreInteractionCheckpoints(saved) {
|
|
9611
|
+
if (this.inner.restoreInteractionCheckpoints) {
|
|
9612
|
+
this.inner.restoreInteractionCheckpoints(saved);
|
|
9613
|
+
} else {
|
|
9614
|
+
this.inner.restoreInteractionCheckpoint?.(saved[saved.length - 1]);
|
|
9615
|
+
}
|
|
9616
|
+
}
|
|
9342
9617
|
getInteractionCheckpoint() {
|
|
9343
9618
|
return this.inner.getInteractionCheckpoint?.();
|
|
9344
9619
|
}
|
|
@@ -9615,7 +9890,8 @@ var OrchestratingDriver = class _OrchestratingDriver extends BaseDriverDecorator
|
|
|
9615
9890
|
})
|
|
9616
9891
|
);
|
|
9617
9892
|
const routingInput = delegated.delegate ? frameDelegatedContent(input, delegated.delegateFraming) : input;
|
|
9618
|
-
const
|
|
9893
|
+
const pin = options?.agent;
|
|
9894
|
+
const pinned = this.resolvePinnedAgent(pin);
|
|
9619
9895
|
if (!pinned) this.dispatchEvent(new CustomEvent("orchestrating-start"));
|
|
9620
9896
|
let routed;
|
|
9621
9897
|
if (pinned) {
|
|
@@ -9633,7 +9909,7 @@ var OrchestratingDriver = class _OrchestratingDriver extends BaseDriverDecorator
|
|
|
9633
9909
|
let lastResult;
|
|
9634
9910
|
while (true) {
|
|
9635
9911
|
if (this.cancelled) break;
|
|
9636
|
-
await this.installAgent(currentAgent);
|
|
9912
|
+
await this.installAgent(currentAgent, pin);
|
|
9637
9913
|
if (this.cancelled) break;
|
|
9638
9914
|
let result;
|
|
9639
9915
|
if (isHandoff) {
|
|
@@ -9769,9 +10045,13 @@ var OrchestratingDriver = class _OrchestratingDriver extends BaseDriverDecorator
|
|
|
9769
10045
|
}
|
|
9770
10046
|
return winner ? { ...winner, agentName, basis: "reachable-max" } : void 0;
|
|
9771
10047
|
}
|
|
9772
|
-
|
|
10048
|
+
/**
|
|
10049
|
+
* `pin` stands in for the user-pin when given, as for
|
|
10050
|
+
* {@link OrchestratingDriver.resolvePinnedAgent}.
|
|
10051
|
+
*/
|
|
10052
|
+
async installAgent(agent, pin) {
|
|
9773
10053
|
const { previousAgent } = await this.agentSession.activate(agent);
|
|
9774
|
-
const isTerminal = isFallback(agent) || this.agentSession.getPinned() !== null || this.agentSession.getFlowOwner() !== null || !!(agent.onActivate || agent.onDeactivate);
|
|
10054
|
+
const isTerminal = isFallback(agent) || (pin === void 0 ? this.agentSession.getPinned() : pin) !== null || this.agentSession.getFlowOwner() !== null || !!(agent.onActivate || agent.onDeactivate);
|
|
9775
10055
|
let agentToApply = agent;
|
|
9776
10056
|
if (!isTerminal) {
|
|
9777
10057
|
const declaredTools = agent.toolDefinitions;
|
|
@@ -10012,9 +10292,11 @@ ${recentMessages}` : ""}`;
|
|
|
10012
10292
|
*
|
|
10013
10293
|
* Logs and returns `undefined` if a name no longer matches the agents array
|
|
10014
10294
|
* — protects against stale state after an agents-array reassignment.
|
|
10295
|
+
*
|
|
10296
|
+
* `pin` stands in for the user-pin when given — `SendMessageOptions.agent`.
|
|
10015
10297
|
*/
|
|
10016
|
-
resolvePinnedAgent() {
|
|
10017
|
-
const name = this.agentSession.getLockedName();
|
|
10298
|
+
resolvePinnedAgent(pin) {
|
|
10299
|
+
const name = this.agentSession.getLockedName(pin);
|
|
10018
10300
|
if (name === null) return void 0;
|
|
10019
10301
|
const match = this.agents.find((a) => a.name === name);
|
|
10020
10302
|
if (!match) {
|
|
@@ -10053,6 +10335,68 @@ function defineAgent(config) {
|
|
|
10053
10335
|
return config;
|
|
10054
10336
|
}
|
|
10055
10337
|
|
|
10338
|
+
// src/autopilot/autopilot-tools.ts
|
|
10339
|
+
var WIDGET_READ = "widget_read";
|
|
10340
|
+
var WIDGET_ACT = "widget_act";
|
|
10341
|
+
var HAND_BACK = "hand_back";
|
|
10342
|
+
var AUTOPILOT_TOOL_DEFINITIONS = [
|
|
10343
|
+
{
|
|
10344
|
+
name: WIDGET_READ,
|
|
10345
|
+
description: "Read the current decision as it stands now: its state (one of its views, if it lists views; without one, its facts or the view shown as Now), and its actions with their numbers and whether each is available. Use it when the decision message may be out of date, or to read a view it lists.",
|
|
10346
|
+
parameters: {
|
|
10347
|
+
type: "object",
|
|
10348
|
+
properties: {
|
|
10349
|
+
view: { type: "string", description: "One of the views the decision lists, if any." }
|
|
10350
|
+
}
|
|
10351
|
+
}
|
|
10352
|
+
},
|
|
10353
|
+
{
|
|
10354
|
+
name: WIDGET_ACT,
|
|
10355
|
+
description: 'Act on the current decision, as the user would by clicking. `action` is the number of an option from the decision\'s list (e.g. "1"), or a named action from that list: "select" with `options` to choose several, "reply" with `text` to answer in your own words, any action listed as name({text}) with its argument in `text`, and any listed as name({fields}) with `fields`. If it settles the decision, your turn ends. `note` is shown to the user as the assistant speaking, before the outcome: one short sentence in the first person saying what you chose and why, e.g. "Your brief has no external feeds, so I\'ll skip Data Feeds." Never mention an autopilot or a second agent.',
|
|
10356
|
+
parameters: {
|
|
10357
|
+
type: "object",
|
|
10358
|
+
required: ["action"],
|
|
10359
|
+
properties: {
|
|
10360
|
+
action: {
|
|
10361
|
+
type: "string",
|
|
10362
|
+
description: 'An option number from the list, starting at 1, or a named action ("select", "reply").'
|
|
10363
|
+
},
|
|
10364
|
+
options: {
|
|
10365
|
+
type: "array",
|
|
10366
|
+
items: { type: "string" },
|
|
10367
|
+
description: 'For "select": the options to choose, by number or label.'
|
|
10368
|
+
},
|
|
10369
|
+
text: {
|
|
10370
|
+
type: "string",
|
|
10371
|
+
description: `For "reply" (your answer, in the user's place) and any action listed as name({text}): its one argument, as plain text.`
|
|
10372
|
+
},
|
|
10373
|
+
fields: {
|
|
10374
|
+
type: "string",
|
|
10375
|
+
description: "Only for an action listed as name({fields}): a JSON object, as text, matching the fields schema the decision lists for it."
|
|
10376
|
+
},
|
|
10377
|
+
note: {
|
|
10378
|
+
type: "string",
|
|
10379
|
+
description: "Shown to the user as the assistant speaking. One sentence, first person."
|
|
10380
|
+
}
|
|
10381
|
+
}
|
|
10382
|
+
}
|
|
10383
|
+
},
|
|
10384
|
+
{
|
|
10385
|
+
name: HAND_BACK,
|
|
10386
|
+
description: 'Give this one decision to the user, when it rests on something only they can know and neither their brief nor their own answers settle it, or when nothing on it can be done (every action unavailable). Your turn ends and the user sees the question. `reason` is shown to them as the assistant speaking, after "I need your input on this one:" \u2014 say plainly what you need from them. Never mention an autopilot or a second agent.',
|
|
10387
|
+
parameters: {
|
|
10388
|
+
type: "object",
|
|
10389
|
+
required: ["reason"],
|
|
10390
|
+
properties: {
|
|
10391
|
+
reason: {
|
|
10392
|
+
type: "string",
|
|
10393
|
+
description: "What the user needs to decide, and why it is theirs."
|
|
10394
|
+
}
|
|
10395
|
+
}
|
|
10396
|
+
}
|
|
10397
|
+
}
|
|
10398
|
+
];
|
|
10399
|
+
|
|
10056
10400
|
// src/config/define-stateful-agent.ts
|
|
10057
10401
|
function defaultStatefulDebugSnapshot(state) {
|
|
10058
10402
|
if (!state || typeof state !== "object") return state;
|
|
@@ -10252,6 +10596,23 @@ function defineStatefulAgent(opts) {
|
|
|
10252
10596
|
};
|
|
10253
10597
|
}
|
|
10254
10598
|
function defineAutopilot(config) {
|
|
10599
|
+
const seen = new Set(AUTOPILOT_TOOL_DEFINITIONS.map((d) => d.name));
|
|
10600
|
+
for (const d of config.tools?.definitions ?? []) {
|
|
10601
|
+
if (seen.has(d.name)) {
|
|
10602
|
+
throw new Error(`defineAutopilot: the tool "${d.name}" is named twice.`);
|
|
10603
|
+
}
|
|
10604
|
+
seen.add(d.name);
|
|
10605
|
+
}
|
|
10606
|
+
for (const set of config.widgetTools ?? []) {
|
|
10607
|
+
for (const name of Object.keys(set.tools)) {
|
|
10608
|
+
if (seen.has(name)) {
|
|
10609
|
+
throw new Error(
|
|
10610
|
+
`defineAutopilot: the widget tool "${name}" (for "${set.componentName}") is named twice.`
|
|
10611
|
+
);
|
|
10612
|
+
}
|
|
10613
|
+
seen.add(name);
|
|
10614
|
+
}
|
|
10615
|
+
}
|
|
10255
10616
|
return config;
|
|
10256
10617
|
}
|
|
10257
10618
|
|