@genesislcap/ai-assistant 15.82.0 → 15.84.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 +2811 -233
- package/dist/ai-assistant.d.ts +835 -93
- package/dist/chat-driver.cjs +452 -99
- package/dist/chat-driver.cjs.map +4 -4
- package/dist/chat-driver.mjs +452 -99
- package/dist/chat-driver.mjs.map +4 -4
- package/dist/custom-elements.json +1903 -907
- 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/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/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/genesis/write-outcome.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 +11 -0
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/main/main.template.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.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/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/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/settings-modal/settings-modal.template.js +2 -2
- package/dist/esm/config/define-stateful-agent.js +22 -1
- package/dist/esm/genesis/write-outcome.js +8 -4
- package/dist/esm/index.js +2 -0
- package/dist/esm/main/main.js +39 -3
- 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 +5 -5
- 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 +44 -17
- 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.cjs
CHANGED
|
@@ -4117,8 +4117,8 @@ var META_EVENT_IMPORTANCE = {
|
|
|
4117
4117
|
"interaction.outcome-dropped": "high",
|
|
4118
4118
|
// A long action's step starting, finishing, or skipped on resume because it was already done.
|
|
4119
4119
|
"interaction.step": "low",
|
|
4120
|
-
// A cut checkpoint taken over after a reload, refused (by sameWork,
|
|
4121
|
-
// at flow end.
|
|
4120
|
+
// A cut checkpoint taken over after a reload, refused (by sameWork, and kept for a later request;
|
|
4121
|
+
// or as malformed), or dropped at flow end, as is the live one.
|
|
4122
4122
|
"interaction.checkpoint": "normal",
|
|
4123
4123
|
// A claimant handing a pending interaction to the person, or taking it back.
|
|
4124
4124
|
"interaction.held": "normal",
|
|
@@ -5357,14 +5357,22 @@ var FoldController = class {
|
|
|
5357
5357
|
// src/state/decision-surface.ts
|
|
5358
5358
|
var SELECT_ACTION = "select";
|
|
5359
5359
|
var REPLY_ACTION = "reply";
|
|
5360
|
-
var normalise = (option) => typeof option === "string" ? { id: option, label: option } : { id: option.id ?? option.label, label: option.label,
|
|
5361
|
-
var
|
|
5360
|
+
var normalise = (option) => typeof option === "string" ? { id: option, label: option } : { id: option.id ?? option.label, label: option.label, unavailable: option.unavailable };
|
|
5361
|
+
var GENERIC_UNAVAILABLE = "not available in this state";
|
|
5362
|
+
function unavailableReason(guard, ...args) {
|
|
5363
|
+
if (!guard) return void 0;
|
|
5362
5364
|
try {
|
|
5363
|
-
|
|
5365
|
+
const reason = guard(...args);
|
|
5366
|
+
if (reason === void 0) return void 0;
|
|
5367
|
+
return reason.trim().replace(/\.+$/, "") || GENERIC_UNAVAILABLE;
|
|
5364
5368
|
} catch {
|
|
5365
|
-
return
|
|
5369
|
+
return GENERIC_UNAVAILABLE;
|
|
5366
5370
|
}
|
|
5367
|
-
}
|
|
5371
|
+
}
|
|
5372
|
+
var reasonFor = (option) => unavailableReason(option.unavailable);
|
|
5373
|
+
var isEnabled = (option) => reasonFor(option) === void 0;
|
|
5374
|
+
var describeViews = (views) => Object.fromEntries(Object.entries(views).map(([name, v]) => [name, v.description]));
|
|
5375
|
+
var readView = (views, view) => Object.prototype.hasOwnProperty.call(views, view) ? views[view].read() : void 0;
|
|
5368
5376
|
function buildDecisionSurface(spec) {
|
|
5369
5377
|
const options = spec.options.map(normalise);
|
|
5370
5378
|
const ids = /* @__PURE__ */ new Set();
|
|
@@ -5379,12 +5387,16 @@ function buildDecisionSurface(spec) {
|
|
|
5379
5387
|
const actions = () => {
|
|
5380
5388
|
const enabled = options.filter(isEnabled);
|
|
5381
5389
|
return [
|
|
5382
|
-
...options.map((o) =>
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
|
|
5386
|
-
|
|
5387
|
-
|
|
5390
|
+
...options.map((o) => {
|
|
5391
|
+
const unavailable = reasonFor(o);
|
|
5392
|
+
return {
|
|
5393
|
+
name: o.id,
|
|
5394
|
+
label: o.label,
|
|
5395
|
+
finishes: true,
|
|
5396
|
+
enabled: unavailable === void 0,
|
|
5397
|
+
...unavailable !== void 0 ? { unavailable } : {}
|
|
5398
|
+
};
|
|
5399
|
+
}),
|
|
5388
5400
|
...spec.multi ? [
|
|
5389
5401
|
{
|
|
5390
5402
|
name: SELECT_ACTION,
|
|
@@ -5393,13 +5405,32 @@ function buildDecisionSurface(spec) {
|
|
|
5393
5405
|
args: "options"
|
|
5394
5406
|
}
|
|
5395
5407
|
] : [],
|
|
5396
|
-
...spec.freeText ? [
|
|
5408
|
+
...spec.freeText ? [replyAction()] : []
|
|
5397
5409
|
];
|
|
5398
5410
|
};
|
|
5411
|
+
const replyReason = () => unavailableReason(spec.freeTextUnavailable);
|
|
5412
|
+
const replyAction = () => {
|
|
5413
|
+
const unavailable = replyReason();
|
|
5414
|
+
return {
|
|
5415
|
+
name: REPLY_ACTION,
|
|
5416
|
+
finishes: true,
|
|
5417
|
+
enabled: unavailable === void 0,
|
|
5418
|
+
...unavailable !== void 0 ? { unavailable } : {},
|
|
5419
|
+
args: "text",
|
|
5420
|
+
refines: true
|
|
5421
|
+
};
|
|
5422
|
+
};
|
|
5399
5423
|
const answer = (a) => () => spec.choose(a);
|
|
5424
|
+
const facts = () => spec.facts?.() ?? {};
|
|
5425
|
+
const views = spec.views && Object.keys(spec.views).length ? spec.views : void 0;
|
|
5426
|
+
const readable = views ? {
|
|
5427
|
+
views: describeViews(views),
|
|
5428
|
+
read: (view) => view === void 0 ? facts() : readView(views, view)
|
|
5429
|
+
} : {};
|
|
5400
5430
|
return {
|
|
5401
5431
|
prompt: spec.prompt,
|
|
5402
|
-
facts
|
|
5432
|
+
facts,
|
|
5433
|
+
...readable,
|
|
5403
5434
|
actions,
|
|
5404
5435
|
isReady: () => actions().some((a) => a.finishes && a.enabled),
|
|
5405
5436
|
prepare(name, args) {
|
|
@@ -5420,7 +5451,7 @@ function buildDecisionSurface(spec) {
|
|
|
5420
5451
|
if (disabled.length) {
|
|
5421
5452
|
return {
|
|
5422
5453
|
error: "disabled",
|
|
5423
|
-
message: `Not available right now: ${disabled.map((o) => o.label).join(", ")}.`
|
|
5454
|
+
message: `Not available right now: ${disabled.map((o) => `${o.label} (${reasonFor(o)})`).join(", ")}.`
|
|
5424
5455
|
};
|
|
5425
5456
|
}
|
|
5426
5457
|
const picks = chosen;
|
|
@@ -5431,6 +5462,10 @@ function buildDecisionSurface(spec) {
|
|
|
5431
5462
|
};
|
|
5432
5463
|
}
|
|
5433
5464
|
if (spec.freeText && name === REPLY_ACTION) {
|
|
5465
|
+
const why2 = replyReason();
|
|
5466
|
+
if (why2 !== void 0) {
|
|
5467
|
+
return { error: "disabled", message: `"reply" is not available right now: ${why2}.` };
|
|
5468
|
+
}
|
|
5434
5469
|
const text = args?.text;
|
|
5435
5470
|
if (typeof text !== "string" || !text.trim()) {
|
|
5436
5471
|
return { error: "invalid-args", message: "`reply` takes { text: string }, not empty." };
|
|
@@ -5441,8 +5476,12 @@ function buildDecisionSurface(spec) {
|
|
|
5441
5476
|
if (!option) {
|
|
5442
5477
|
return { error: "unknown-action", message: `No action "${name}" here.` };
|
|
5443
5478
|
}
|
|
5444
|
-
|
|
5445
|
-
|
|
5479
|
+
const why = reasonFor(option);
|
|
5480
|
+
if (why !== void 0) {
|
|
5481
|
+
return {
|
|
5482
|
+
error: "disabled",
|
|
5483
|
+
message: `"${option.label}" is not available right now: ${why}.`
|
|
5484
|
+
};
|
|
5446
5485
|
}
|
|
5447
5486
|
return {
|
|
5448
5487
|
choice: option.label,
|
|
@@ -5482,33 +5521,65 @@ function checkArgs(args, schema) {
|
|
|
5482
5521
|
return wrong.length ? `${wrong.join("; ")}.` : void 0;
|
|
5483
5522
|
}
|
|
5484
5523
|
function buildFullSurface(spec) {
|
|
5485
|
-
const
|
|
5486
|
-
|
|
5487
|
-
|
|
5488
|
-
|
|
5489
|
-
|
|
5524
|
+
for (const [name, action] of Object.entries(spec.actions)) {
|
|
5525
|
+
if (action.text && action.argsSchema) {
|
|
5526
|
+
throw new Error(
|
|
5527
|
+
`exposeSurface: action "${name}" takes \`text\` or \`argsSchema\`, not both.`
|
|
5528
|
+
);
|
|
5490
5529
|
}
|
|
5491
|
-
}
|
|
5492
|
-
const
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5530
|
+
}
|
|
5531
|
+
const views = spec.views && Object.keys(spec.views).length ? spec.views : void 0;
|
|
5532
|
+
if (spec.preview !== void 0 && !(views && Object.prototype.hasOwnProperty.call(views, spec.preview))) {
|
|
5533
|
+
throw new Error(`exposeSurface: the preview "${spec.preview}" is not one of its views.`);
|
|
5534
|
+
}
|
|
5535
|
+
const actions = () => Object.entries(spec.actions).map(([name, a]) => {
|
|
5536
|
+
const unavailable = unavailableReason(a.unavailable);
|
|
5537
|
+
return {
|
|
5538
|
+
name,
|
|
5539
|
+
finishes: !!a.finishes,
|
|
5540
|
+
enabled: unavailable === void 0,
|
|
5541
|
+
...unavailable !== void 0 ? { unavailable } : {},
|
|
5542
|
+
description: a.description,
|
|
5543
|
+
...a.text ? { args: "text" } : {},
|
|
5544
|
+
...a.argsSchema ? { args: "fields", argsSchema: a.argsSchema } : {},
|
|
5545
|
+
...a.refines ? { refines: true } : {}
|
|
5546
|
+
};
|
|
5547
|
+
});
|
|
5499
5548
|
return {
|
|
5500
5549
|
prompt: spec.prompt,
|
|
5501
5550
|
facts: () => ({}),
|
|
5502
5551
|
describe: () => spec.describe(),
|
|
5503
|
-
views
|
|
5504
|
-
|
|
5552
|
+
...views ? {
|
|
5553
|
+
views: describeViews(views),
|
|
5554
|
+
...spec.preview !== void 0 ? { preview: spec.preview } : {},
|
|
5555
|
+
read: (view) => {
|
|
5556
|
+
const name = view ?? spec.preview;
|
|
5557
|
+
return name === void 0 ? void 0 : readView(views, name);
|
|
5558
|
+
}
|
|
5559
|
+
} : {},
|
|
5505
5560
|
actions,
|
|
5506
5561
|
isReady: () => actions().some((a) => a.enabled),
|
|
5507
5562
|
prepare(name, args) {
|
|
5508
5563
|
const action = Object.prototype.hasOwnProperty.call(spec.actions, name) ? spec.actions[name] : void 0;
|
|
5509
5564
|
if (!action) return { error: "unknown-action", message: `No action "${name}" here.` };
|
|
5510
|
-
|
|
5511
|
-
|
|
5565
|
+
const why = unavailableReason(action.unavailable);
|
|
5566
|
+
if (why !== void 0) {
|
|
5567
|
+
return { error: "disabled", message: `"${name}" is not available right now: ${why}.` };
|
|
5568
|
+
}
|
|
5569
|
+
if (action.text) {
|
|
5570
|
+
const text = args?.text;
|
|
5571
|
+
if (typeof text !== "string" || !text.trim()) {
|
|
5572
|
+
return {
|
|
5573
|
+
error: "invalid-args",
|
|
5574
|
+
message: `"${name}" takes its argument as \`text\`, not empty.`
|
|
5575
|
+
};
|
|
5576
|
+
}
|
|
5577
|
+
const trimmed = text.trim();
|
|
5578
|
+
return {
|
|
5579
|
+
choice: `${name}: ${trimmed}`.slice(0, CHOICE_CHARS),
|
|
5580
|
+
finishes: !!action.finishes,
|
|
5581
|
+
run: () => action.run(trimmed)
|
|
5582
|
+
};
|
|
5512
5583
|
}
|
|
5513
5584
|
const problem = checkArgs(args ?? {}, action.argsSchema);
|
|
5514
5585
|
if (problem) return { error: "invalid-args", message: `"${name}": ${problem}` };
|
|
@@ -5536,15 +5607,21 @@ function createInteractionContext(interactionId, deps = {}) {
|
|
|
5536
5607
|
let surface;
|
|
5537
5608
|
let lastActivityAt = Date.now();
|
|
5538
5609
|
let checkpoint = deps.checkpoint;
|
|
5610
|
+
let working;
|
|
5539
5611
|
let offered = false;
|
|
5540
5612
|
let attention;
|
|
5541
5613
|
let attentionDone = false;
|
|
5614
|
+
let attentionTaker;
|
|
5542
5615
|
const reportAttention = () => {
|
|
5543
5616
|
if (!offered || !attention || attentionDone || disposed || settled) return;
|
|
5544
5617
|
attentionDone = true;
|
|
5545
5618
|
if (heldBy !== "user") return;
|
|
5546
|
-
deps.requestAttention?.(attention.message);
|
|
5619
|
+
(attentionTaker ?? deps.requestAttention)?.(attention.message);
|
|
5547
5620
|
};
|
|
5621
|
+
const reporting = (built) => ({
|
|
5622
|
+
...built,
|
|
5623
|
+
isReady: () => working === false || working !== true && built.isReady()
|
|
5624
|
+
});
|
|
5548
5625
|
const checkReady = () => {
|
|
5549
5626
|
if (disposed || !surface || readyListeners.size === 0 || !surface.isReady()) return;
|
|
5550
5627
|
const waiting = [...readyListeners];
|
|
@@ -5575,6 +5652,14 @@ function createInteractionContext(interactionId, deps = {}) {
|
|
|
5575
5652
|
get checkpoint() {
|
|
5576
5653
|
return checkpoint;
|
|
5577
5654
|
},
|
|
5655
|
+
get working() {
|
|
5656
|
+
return working;
|
|
5657
|
+
},
|
|
5658
|
+
setWorking(next) {
|
|
5659
|
+
if (disposed || next === working) return;
|
|
5660
|
+
working = next;
|
|
5661
|
+
context.notify();
|
|
5662
|
+
},
|
|
5578
5663
|
saveCheckpoint(next) {
|
|
5579
5664
|
if (disposed) return;
|
|
5580
5665
|
checkpoint = next;
|
|
@@ -5617,19 +5702,19 @@ function createInteractionContext(interactionId, deps = {}) {
|
|
|
5617
5702
|
}
|
|
5618
5703
|
disposers.add(fn);
|
|
5619
5704
|
},
|
|
5620
|
-
resolve(result) {
|
|
5705
|
+
resolve(result, options) {
|
|
5621
5706
|
if (settled || disposed) return;
|
|
5622
5707
|
settled = true;
|
|
5623
|
-
deps.resolve?.(result);
|
|
5708
|
+
deps.resolve?.(result, options);
|
|
5624
5709
|
},
|
|
5625
5710
|
exposeDecision(decision) {
|
|
5626
5711
|
if (disposed) return;
|
|
5627
|
-
surface = buildDecisionSurface(decision);
|
|
5712
|
+
surface = reporting(buildDecisionSurface(decision));
|
|
5628
5713
|
context.notify();
|
|
5629
5714
|
},
|
|
5630
5715
|
exposeSurface(spec) {
|
|
5631
5716
|
if (disposed) return;
|
|
5632
|
-
surface = buildFullSurface(spec);
|
|
5717
|
+
surface = reporting(buildFullSurface(spec));
|
|
5633
5718
|
context.notify();
|
|
5634
5719
|
},
|
|
5635
5720
|
onSurfaceReady(fn) {
|
|
@@ -5683,6 +5768,16 @@ function createInteractionContext(interactionId, deps = {}) {
|
|
|
5683
5768
|
offered = true;
|
|
5684
5769
|
reportAttention();
|
|
5685
5770
|
},
|
|
5771
|
+
get attentionMessage() {
|
|
5772
|
+
return attention?.message;
|
|
5773
|
+
},
|
|
5774
|
+
takeAttention(onRequest) {
|
|
5775
|
+
if (attentionDone || disposed || settled || attentionTaker) return void 0;
|
|
5776
|
+
attentionTaker = onRequest;
|
|
5777
|
+
return () => {
|
|
5778
|
+
if (attentionTaker === onRequest) attentionTaker = void 0;
|
|
5779
|
+
};
|
|
5780
|
+
},
|
|
5686
5781
|
get surface() {
|
|
5687
5782
|
return surface;
|
|
5688
5783
|
}
|
|
@@ -5695,6 +5790,15 @@ function getInteractionRegistration(name) {
|
|
|
5695
5790
|
return registry2.get(name);
|
|
5696
5791
|
}
|
|
5697
5792
|
|
|
5793
|
+
// src/state/live-interactions.ts
|
|
5794
|
+
var live = /* @__PURE__ */ new Map();
|
|
5795
|
+
function trackInteractionContext(context) {
|
|
5796
|
+
live.set(context.interactionId, context);
|
|
5797
|
+
return () => {
|
|
5798
|
+
if (live.get(context.interactionId) === context) live.delete(context.interactionId);
|
|
5799
|
+
};
|
|
5800
|
+
}
|
|
5801
|
+
|
|
5698
5802
|
// src/state/run-steps.ts
|
|
5699
5803
|
var recorders = /* @__PURE__ */ new WeakMap();
|
|
5700
5804
|
function bindStepRecorder(ctx, record, refused) {
|
|
@@ -5743,6 +5847,19 @@ function doneOnUsersBehalf(interaction, answeredBy) {
|
|
|
5743
5847
|
}
|
|
5744
5848
|
return {};
|
|
5745
5849
|
}
|
|
5850
|
+
function stampAnsweredBy(result, answeredBy) {
|
|
5851
|
+
if (result === null || typeof result !== "object" || Array.isArray(result)) return result;
|
|
5852
|
+
const copy = { ...result };
|
|
5853
|
+
if (answeredBy) copy.answeredBy = answeredBy;
|
|
5854
|
+
else delete copy.answeredBy;
|
|
5855
|
+
return copy;
|
|
5856
|
+
}
|
|
5857
|
+
function whoAnswered(interaction, result, how) {
|
|
5858
|
+
const unanswered = result?.status === "timeout";
|
|
5859
|
+
const resolvedItself = !unanswered && !interaction.settledBy && (!!interaction.resolvesItself || how?.resolvedItself === true);
|
|
5860
|
+
if (unanswered || resolvedItself) return { resolvedItself };
|
|
5861
|
+
return { answeredBy: interaction.settledBy ?? "user", resolvedItself };
|
|
5862
|
+
}
|
|
5746
5863
|
var STOPPED = {
|
|
5747
5864
|
status: "timeout",
|
|
5748
5865
|
message: "The turn was stopped before this was answered."
|
|
@@ -5765,58 +5882,118 @@ var InteractionController = class {
|
|
|
5765
5882
|
* the root's are ever consulted: a sub-agent's request is opened by the root.
|
|
5766
5883
|
*/
|
|
5767
5884
|
this.interceptors = [];
|
|
5885
|
+
/**
|
|
5886
|
+
* Checkpoints a reload cut, oldest first, each waiting for a request of its own widget type that
|
|
5887
|
+
* `sameWork` agrees is the same work. Held apart from `live`, so neither the work a resumed flow
|
|
5888
|
+
* does first nor a request `sameWork` refuses can lose one: a flow may open other long widgets
|
|
5889
|
+
* before the one a checkpoint belongs to asks for it. Each leaves when it is taken over, and all
|
|
5890
|
+
* of them when the flow ends.
|
|
5891
|
+
*/
|
|
5892
|
+
this.cut = [];
|
|
5768
5893
|
}
|
|
5769
|
-
/**
|
|
5894
|
+
/**
|
|
5895
|
+
* See `ChatDriver.getInteractionCheckpoints`: every checkpoint to save with the session — those a
|
|
5896
|
+
* reload cut that nothing has taken yet, oldest first, then the live interaction's. A reload cuts
|
|
5897
|
+
* them all, so all of them are restored as cut.
|
|
5898
|
+
*/
|
|
5899
|
+
getCheckpoints() {
|
|
5900
|
+
const live2 = this.live;
|
|
5901
|
+
return [
|
|
5902
|
+
...this.cut.map(({ componentName, value }) => ({ componentName, value })),
|
|
5903
|
+
...live2 ? [{ componentName: live2.componentName, value: live2.value }] : []
|
|
5904
|
+
];
|
|
5905
|
+
}
|
|
5906
|
+
/**
|
|
5907
|
+
* See `ChatDriver.getInteractionCheckpoint` (deprecated): one checkpoint, the live interaction's,
|
|
5908
|
+
* else the newest a reload cut.
|
|
5909
|
+
*/
|
|
5770
5910
|
getCheckpoint() {
|
|
5771
|
-
const
|
|
5772
|
-
return
|
|
5911
|
+
const all = this.getCheckpoints();
|
|
5912
|
+
return all[all.length - 1];
|
|
5773
5913
|
}
|
|
5774
|
-
/**
|
|
5914
|
+
/**
|
|
5915
|
+
* See `ChatDriver.restoreInteractionCheckpoints`. Restored means cut: their interactions are gone.
|
|
5916
|
+
* Replaces whatever was held.
|
|
5917
|
+
*/
|
|
5918
|
+
restoreCheckpoints(saved) {
|
|
5919
|
+
this.live = void 0;
|
|
5920
|
+
this.cut = (saved ?? []).map(({ componentName, value }) => ({ componentName, value }));
|
|
5921
|
+
}
|
|
5922
|
+
/** See `ChatDriver.restoreInteractionCheckpoint` (deprecated): one, or none. */
|
|
5775
5923
|
restoreCheckpoint(saved) {
|
|
5776
|
-
this.
|
|
5924
|
+
this.restoreCheckpoints(saved ? [saved] : []);
|
|
5777
5925
|
}
|
|
5778
|
-
/** Drop
|
|
5926
|
+
/** Drop every checkpoint, used or not, cut or live, when its flow ends. */
|
|
5779
5927
|
clearCheckpoint(why) {
|
|
5780
|
-
const
|
|
5781
|
-
|
|
5782
|
-
this.
|
|
5783
|
-
|
|
5784
|
-
|
|
5785
|
-
|
|
5786
|
-
|
|
5787
|
-
|
|
5788
|
-
|
|
5928
|
+
const live2 = this.live;
|
|
5929
|
+
const cut = this.cut;
|
|
5930
|
+
this.live = void 0;
|
|
5931
|
+
this.cut = [];
|
|
5932
|
+
for (const cp of cut) {
|
|
5933
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.checkpoint", {
|
|
5934
|
+
action: "cleared",
|
|
5935
|
+
component: cp.componentName,
|
|
5936
|
+
why,
|
|
5937
|
+
cut: true
|
|
5938
|
+
});
|
|
5939
|
+
}
|
|
5940
|
+
if (live2) {
|
|
5941
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.checkpoint", {
|
|
5942
|
+
action: "cleared",
|
|
5943
|
+
component: live2.componentName,
|
|
5944
|
+
why,
|
|
5945
|
+
interactionId: live2.interactionId
|
|
5946
|
+
});
|
|
5947
|
+
}
|
|
5789
5948
|
}
|
|
5790
5949
|
/**
|
|
5791
|
-
*
|
|
5792
|
-
*
|
|
5793
|
-
*
|
|
5950
|
+
* Offer the checkpoints a reload cut to a new request of their widget type, newest first, and
|
|
5951
|
+
* hand it the first its registration's `sameWork` agrees is the same work (any, without one). A
|
|
5952
|
+
* checkpoint `sameWork` refuses stays where it is, for a later request of the same type: a flow
|
|
5953
|
+
* may ask for other work of that type first. Each refusal is recorded, with the identity kept.
|
|
5794
5954
|
*/
|
|
5795
5955
|
takeOverCheckpoint(componentName, data, interactionId) {
|
|
5796
|
-
const cut = this.checkpoint;
|
|
5797
|
-
if (!cut?.cut || cut.componentName !== componentName) return void 0;
|
|
5798
|
-
this.checkpoint = void 0;
|
|
5799
5956
|
const sameWork = getInteractionRegistration(componentName)?.sameWork;
|
|
5800
|
-
let
|
|
5801
|
-
|
|
5802
|
-
|
|
5803
|
-
|
|
5804
|
-
|
|
5805
|
-
|
|
5806
|
-
|
|
5957
|
+
for (let i = this.cut.length - 1; i >= 0; i -= 1) {
|
|
5958
|
+
const cut = this.cut[i];
|
|
5959
|
+
if (cut.componentName !== componentName) continue;
|
|
5960
|
+
let agrees = true;
|
|
5961
|
+
if (sameWork) {
|
|
5962
|
+
try {
|
|
5963
|
+
agrees = sameWork(cut.value, data);
|
|
5964
|
+
} catch (e) {
|
|
5965
|
+
logger2.warn(
|
|
5966
|
+
`InteractionController: "${componentName}" sameWork threw; not taking it over:`,
|
|
5967
|
+
e
|
|
5968
|
+
);
|
|
5969
|
+
agrees = false;
|
|
5970
|
+
}
|
|
5807
5971
|
}
|
|
5972
|
+
if (!agrees) {
|
|
5973
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.checkpoint", {
|
|
5974
|
+
action: "refused",
|
|
5975
|
+
component: componentName,
|
|
5976
|
+
interactionId,
|
|
5977
|
+
saved: cut.value,
|
|
5978
|
+
kept: true
|
|
5979
|
+
});
|
|
5980
|
+
continue;
|
|
5981
|
+
}
|
|
5982
|
+
this.cut.splice(i, 1);
|
|
5983
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.checkpoint", {
|
|
5984
|
+
action: "resumed",
|
|
5985
|
+
component: componentName,
|
|
5986
|
+
interactionId
|
|
5987
|
+
});
|
|
5988
|
+
this.live = { componentName, value: cut.value, interactionId };
|
|
5989
|
+
return cut.value;
|
|
5808
5990
|
}
|
|
5809
|
-
|
|
5810
|
-
action: agrees ? "resumed" : "refused",
|
|
5811
|
-
component: componentName,
|
|
5812
|
-
interactionId,
|
|
5813
|
-
...agrees ? {} : { saved: cut.value }
|
|
5814
|
-
});
|
|
5815
|
-
if (!agrees) return void 0;
|
|
5816
|
-
this.checkpoint = { componentName, value: cut.value, interactionId };
|
|
5817
|
-
return cut.value;
|
|
5991
|
+
return void 0;
|
|
5818
5992
|
}
|
|
5819
|
-
/**
|
|
5993
|
+
/**
|
|
5994
|
+
* A controller's `ctx.saveCheckpoint`: kept as JSON, the form it is persisted in. Replaces the
|
|
5995
|
+
* live interaction's only; the checkpoints a reload cut are left waiting for their own widgets.
|
|
5996
|
+
*/
|
|
5820
5997
|
saveCheckpoint(interactionId, componentName, value) {
|
|
5821
5998
|
if (!this.pending.has(interactionId)) return;
|
|
5822
5999
|
let copy;
|
|
@@ -5829,7 +6006,7 @@ var InteractionController = class {
|
|
|
5829
6006
|
);
|
|
5830
6007
|
return;
|
|
5831
6008
|
}
|
|
5832
|
-
this.
|
|
6009
|
+
this.live = { componentName, value: copy, interactionId };
|
|
5833
6010
|
this.deps.emit(new CustomEvent("checkpoint-saved", { detail: { interactionId } }));
|
|
5834
6011
|
}
|
|
5835
6012
|
/** See `ChatDriver.addInteractionInterceptor`. Returns a remover. */
|
|
@@ -5856,11 +6033,34 @@ var InteractionController = class {
|
|
|
5856
6033
|
*
|
|
5857
6034
|
* Runs before the interaction's message is appended, so the widget's first render already knows
|
|
5858
6035
|
* its holder and nothing appears only to disappear.
|
|
6036
|
+
*
|
|
6037
|
+
* **A late claim.** An interceptor that declined may still claim it later, through its hold's
|
|
6038
|
+
* `claim`, once the asking is over and while nobody else has (see {@link InteractionHold.claim}).
|
|
5859
6039
|
*/
|
|
5860
6040
|
offer(handle, opened) {
|
|
5861
6041
|
let claimant;
|
|
6042
|
+
let asking = true;
|
|
6043
|
+
const claimLate = (interceptor) => {
|
|
6044
|
+
if (asking || claimant || opened.userOnly) return false;
|
|
6045
|
+
const pending = this.pending.get(opened.interactionId);
|
|
6046
|
+
if (!pending || !handle.setHeldBy(interceptor.id)) return false;
|
|
6047
|
+
claimant = interceptor;
|
|
6048
|
+
pending.claimant = interceptor;
|
|
6049
|
+
recordMetaEvent(this.deps.sessionKey, "interaction.held", {
|
|
6050
|
+
interactionId: opened.interactionId,
|
|
6051
|
+
heldBy: interceptor.id,
|
|
6052
|
+
claimant: interceptor.id,
|
|
6053
|
+
late: true
|
|
6054
|
+
});
|
|
6055
|
+
return true;
|
|
6056
|
+
};
|
|
5862
6057
|
for (const interceptor of [...this.interceptors].reverse()) {
|
|
5863
|
-
const hold = this.holdFor(
|
|
6058
|
+
const hold = this.holdFor(
|
|
6059
|
+
handle,
|
|
6060
|
+
interceptor,
|
|
6061
|
+
() => claimant === interceptor,
|
|
6062
|
+
() => claimLate(interceptor)
|
|
6063
|
+
);
|
|
5864
6064
|
let answer;
|
|
5865
6065
|
try {
|
|
5866
6066
|
answer = interceptor.onInteractionOpened({ ...opened, ctx: handle.context, hold });
|
|
@@ -5882,11 +6082,39 @@ var InteractionController = class {
|
|
|
5882
6082
|
const pending = this.pending.get(opened.interactionId);
|
|
5883
6083
|
if (pending) pending.claimant = interceptor;
|
|
5884
6084
|
}
|
|
6085
|
+
asking = false;
|
|
5885
6086
|
return handle.context.heldBy;
|
|
5886
6087
|
}
|
|
5887
|
-
/**
|
|
5888
|
-
|
|
6088
|
+
/**
|
|
6089
|
+
* Publish `agent-attention-ended` each time the interaction stops waiting on the person — a
|
|
6090
|
+
* claimant takes it, or it settles — so a notification still showing for it is closed
|
|
6091
|
+
* (GENC-1660). Wired once who holds it is decided, so a claim made as it opens is not one.
|
|
6092
|
+
*/
|
|
6093
|
+
reportAttentionEnds(ctx) {
|
|
6094
|
+
const ended = () => this.deps.activityBus.publish("agent-attention-ended", {
|
|
6095
|
+
sessionKey: this.deps.sessionKey,
|
|
6096
|
+
interactionId: ctx.interactionId
|
|
6097
|
+
});
|
|
6098
|
+
let heldBy = ctx.heldBy;
|
|
6099
|
+
const unsubscribe = ctx.subscribe(() => {
|
|
6100
|
+
if (ctx.heldBy === heldBy) return;
|
|
6101
|
+
heldBy = ctx.heldBy;
|
|
6102
|
+
if (heldBy !== "user") ended();
|
|
6103
|
+
});
|
|
6104
|
+
ctx.onDispose(() => {
|
|
6105
|
+
unsubscribe();
|
|
6106
|
+
ended();
|
|
6107
|
+
});
|
|
6108
|
+
}
|
|
6109
|
+
/**
|
|
6110
|
+
* The {@link InteractionHold} for one interceptor: it applies only while that one is the claimant,
|
|
6111
|
+
* which `claim` can make it after the asking, if nobody else is.
|
|
6112
|
+
*/
|
|
6113
|
+
holdFor(handle, interceptor, isClaimant, claim) {
|
|
5889
6114
|
return {
|
|
6115
|
+
claim,
|
|
6116
|
+
attentionMessage: () => handle.attentionMessage,
|
|
6117
|
+
takeAttention: (onRequest) => handle.takeAttention(onRequest),
|
|
5890
6118
|
set: (holder) => {
|
|
5891
6119
|
if (!isClaimant()) return false;
|
|
5892
6120
|
const next = holder === "user" ? "user" : interceptor.id;
|
|
@@ -6030,6 +6258,9 @@ var InteractionController = class {
|
|
|
6030
6258
|
reject,
|
|
6031
6259
|
onSettled,
|
|
6032
6260
|
overrideId: chatInputDuringExecution ? interactionId : void 0,
|
|
6261
|
+
...getInteractionRegistration(componentName)?.resolvesItself === true && {
|
|
6262
|
+
resolvesItself: true
|
|
6263
|
+
},
|
|
6033
6264
|
// Resolve the interaction with a timeout result if the user does not
|
|
6034
6265
|
// respond in time. `resolve` runs the same teardown a normal resolution
|
|
6035
6266
|
// does (marks the widget read-only, reverts any input override) and
|
|
@@ -6043,7 +6274,7 @@ var InteractionController = class {
|
|
|
6043
6274
|
});
|
|
6044
6275
|
const handle = createInteractionContext(interactionId, {
|
|
6045
6276
|
sessionKey: this.deps.sessionKey,
|
|
6046
|
-
resolve: (result) => this.resolve(interactionId, result),
|
|
6277
|
+
resolve: (result, how) => this.resolve(interactionId, result, how),
|
|
6047
6278
|
checkpoint: this.takeOverCheckpoint(componentName, data, interactionId),
|
|
6048
6279
|
saveCheckpoint: (value) => this.saveCheckpoint(interactionId, componentName, value),
|
|
6049
6280
|
requestAttention: (message) => this.deps.activityBus.publish("agent-attention", {
|
|
@@ -6054,6 +6285,7 @@ var InteractionController = class {
|
|
|
6054
6285
|
})
|
|
6055
6286
|
});
|
|
6056
6287
|
this.contexts.set(interactionId, handle);
|
|
6288
|
+
handle.context.onDispose(trackInteractionContext(handle.context));
|
|
6057
6289
|
bindStepRecorder(
|
|
6058
6290
|
handle.context,
|
|
6059
6291
|
(step, outcome) => recordMetaEvent(this.deps.sessionKey, "interaction.step", {
|
|
@@ -6086,6 +6318,7 @@ var InteractionController = class {
|
|
|
6086
6318
|
userOnly: options?.userOnly === true
|
|
6087
6319
|
});
|
|
6088
6320
|
handle.markOffered();
|
|
6321
|
+
this.reportAttentionEnds(handle.context);
|
|
6089
6322
|
recordMetaEvent(this.deps.sessionKey, "interaction.requested", {
|
|
6090
6323
|
interactionId,
|
|
6091
6324
|
component: componentName,
|
|
@@ -6115,7 +6348,7 @@ var InteractionController = class {
|
|
|
6115
6348
|
const opened = this.pending.get(interactionId);
|
|
6116
6349
|
if (opened) {
|
|
6117
6350
|
opened.appended = true;
|
|
6118
|
-
if (opened.early) this.resolve(interactionId, opened.early.result);
|
|
6351
|
+
if (opened.early) this.resolve(interactionId, opened.early.result, opened.early.options);
|
|
6119
6352
|
}
|
|
6120
6353
|
const signal = options?.signal;
|
|
6121
6354
|
if (signal) {
|
|
@@ -6134,16 +6367,17 @@ var InteractionController = class {
|
|
|
6134
6367
|
}
|
|
6135
6368
|
/**
|
|
6136
6369
|
* See `ChatDriver.resolveInteraction`. Warns and returns when the id is unknown — a widget can
|
|
6137
|
-
* report twice, and the second report has nothing left to settle.
|
|
6370
|
+
* report twice, and the second report has nothing left to settle. `how` is what a controller's
|
|
6371
|
+
* `ctx.resolve` said about the settle (`resolvedItself`); every other route passes none.
|
|
6138
6372
|
*/
|
|
6139
|
-
resolve(interactionId, result) {
|
|
6373
|
+
resolve(interactionId, result, how) {
|
|
6140
6374
|
const interaction = this.pending.get(interactionId);
|
|
6141
6375
|
if (!interaction) {
|
|
6142
6376
|
logger2.warn(`Interaction with ID ${interactionId} not found.`);
|
|
6143
6377
|
return;
|
|
6144
6378
|
}
|
|
6145
6379
|
if (!interaction.appended) {
|
|
6146
|
-
interaction.early ??= { result };
|
|
6380
|
+
interaction.early ??= { result, options: how };
|
|
6147
6381
|
return;
|
|
6148
6382
|
}
|
|
6149
6383
|
if (interaction.timeoutHandle) clearTimeout(interaction.timeoutHandle);
|
|
@@ -6153,8 +6387,7 @@ var InteractionController = class {
|
|
|
6153
6387
|
result?.diagnostics
|
|
6154
6388
|
);
|
|
6155
6389
|
const costUsd = typeof result?.costUsd === "number" && Number.isFinite(result.costUsd) && result.costUsd > 0 ? result.costUsd : void 0;
|
|
6156
|
-
const
|
|
6157
|
-
const answeredBy = unanswered ? void 0 : interaction.settledBy ?? "user";
|
|
6390
|
+
const { answeredBy, resolvedItself } = whoAnswered(interaction, result, how);
|
|
6158
6391
|
const run = answeredBy && answeredBy !== "user" ? interaction.running : void 0;
|
|
6159
6392
|
if (run) {
|
|
6160
6393
|
interaction.settledInRun = run.token;
|
|
@@ -6168,20 +6401,23 @@ var InteractionController = class {
|
|
|
6168
6401
|
...message.interaction,
|
|
6169
6402
|
resolved: result,
|
|
6170
6403
|
...answeredBy ? { answeredBy } : {},
|
|
6404
|
+
...resolvedItself ? { resolvedItself } : {},
|
|
6171
6405
|
...edits ? { edits } : {}
|
|
6172
6406
|
},
|
|
6173
6407
|
...costUsd != null ? { externalCostUsd: (message.externalCostUsd ?? 0) + costUsd } : {}
|
|
6174
6408
|
}));
|
|
6175
6409
|
if (patched) this.deps.notifyHistoryUpdated();
|
|
6176
6410
|
if (typeof result?.userMessage === "string" && result.userMessage.trim()) {
|
|
6177
|
-
|
|
6178
|
-
|
|
6411
|
+
if (!answeredBy || answeredBy === "user") {
|
|
6412
|
+
this.deps.appendToHistory({ role: "synthetic-user", content: result.userMessage });
|
|
6413
|
+
} else if (!run?.note) {
|
|
6414
|
+
this.deps.appendToHistory({
|
|
6179
6415
|
role: "assistant",
|
|
6180
6416
|
content: result.userMessage,
|
|
6181
6417
|
delegate: answeredBy,
|
|
6182
6418
|
excludeFromProvider: true
|
|
6183
|
-
}
|
|
6184
|
-
|
|
6419
|
+
});
|
|
6420
|
+
}
|
|
6185
6421
|
}
|
|
6186
6422
|
if (interaction.overrideId) {
|
|
6187
6423
|
this.deps.emit(new CustomEvent("interaction-stop", { detail: { interactionId } }));
|
|
@@ -6189,22 +6425,32 @@ var InteractionController = class {
|
|
|
6189
6425
|
recordMetaEvent(this.deps.sessionKey, "interaction.resolved", {
|
|
6190
6426
|
interactionId,
|
|
6191
6427
|
...answeredBy ? { answeredBy } : {},
|
|
6428
|
+
...resolvedItself ? { resolvedItself } : {},
|
|
6192
6429
|
...edits ? { edits: edits.length } : {}
|
|
6193
6430
|
});
|
|
6194
6431
|
this.deps.activityBus.publish("interaction-resolved", void 0);
|
|
6195
6432
|
try {
|
|
6196
|
-
interaction.onSettled?.({
|
|
6433
|
+
interaction.onSettled?.({
|
|
6434
|
+
answeredBy,
|
|
6435
|
+
...resolvedItself ? { resolvedItself } : {},
|
|
6436
|
+
decision,
|
|
6437
|
+
...edited ? { edited } : {}
|
|
6438
|
+
});
|
|
6197
6439
|
} catch (e) {
|
|
6198
6440
|
logger2.warn("InteractionController: onSettled threw:", e);
|
|
6199
6441
|
}
|
|
6200
6442
|
this.deps.emit(
|
|
6201
6443
|
new CustomEvent("interaction-settled", {
|
|
6202
|
-
detail: {
|
|
6444
|
+
detail: {
|
|
6445
|
+
interactionId,
|
|
6446
|
+
...answeredBy ? { answeredBy } : {},
|
|
6447
|
+
...resolvedItself ? { resolvedItself } : {}
|
|
6448
|
+
}
|
|
6203
6449
|
})
|
|
6204
6450
|
);
|
|
6205
|
-
interaction.resolve(result);
|
|
6451
|
+
interaction.resolve(stampAnsweredBy(result, answeredBy));
|
|
6206
6452
|
this.pending.delete(interactionId);
|
|
6207
|
-
if (this.
|
|
6453
|
+
if (this.live?.interactionId === interactionId) this.live = void 0;
|
|
6208
6454
|
this.contexts.get(interactionId)?.dispose();
|
|
6209
6455
|
this.contexts.delete(interactionId);
|
|
6210
6456
|
}
|
|
@@ -8132,11 +8378,27 @@ var ChatDriver = class _ChatDriver extends EventTarget {
|
|
|
8132
8378
|
getInteractionContext(interactionId) {
|
|
8133
8379
|
return this.interactions.context(interactionId);
|
|
8134
8380
|
}
|
|
8135
|
-
/** {@inheritDoc AiDriver.
|
|
8381
|
+
/** {@inheritDoc AiDriver.getInteractionCheckpoints} */
|
|
8382
|
+
getInteractionCheckpoints() {
|
|
8383
|
+
return this.interactions.getCheckpoints();
|
|
8384
|
+
}
|
|
8385
|
+
/** {@inheritDoc AiDriver.restoreInteractionCheckpoints} */
|
|
8386
|
+
restoreInteractionCheckpoints(saved) {
|
|
8387
|
+
this.interactions.restoreCheckpoints(saved);
|
|
8388
|
+
}
|
|
8389
|
+
/**
|
|
8390
|
+
* {@inheritDoc AiDriver.getInteractionCheckpoint}
|
|
8391
|
+
*
|
|
8392
|
+
* @deprecated Use `getInteractionCheckpoints`.
|
|
8393
|
+
*/
|
|
8136
8394
|
getInteractionCheckpoint() {
|
|
8137
8395
|
return this.interactions.getCheckpoint();
|
|
8138
8396
|
}
|
|
8139
|
-
/**
|
|
8397
|
+
/**
|
|
8398
|
+
* {@inheritDoc AiDriver.restoreInteractionCheckpoint}
|
|
8399
|
+
*
|
|
8400
|
+
* @deprecated Use `restoreInteractionCheckpoints`.
|
|
8401
|
+
*/
|
|
8140
8402
|
restoreInteractionCheckpoint(saved) {
|
|
8141
8403
|
this.interactions.restoreCheckpoint(saved);
|
|
8142
8404
|
}
|
|
@@ -9423,6 +9685,18 @@ var BaseDriverDecorator = class _BaseDriverDecorator extends EventTarget {
|
|
|
9423
9685
|
getFlowOwner() {
|
|
9424
9686
|
return this.inner.getFlowOwner?.() ?? null;
|
|
9425
9687
|
}
|
|
9688
|
+
getInteractionCheckpoints() {
|
|
9689
|
+
if (this.inner.getInteractionCheckpoints) return this.inner.getInteractionCheckpoints();
|
|
9690
|
+
const one = this.inner.getInteractionCheckpoint?.();
|
|
9691
|
+
return one ? [one] : [];
|
|
9692
|
+
}
|
|
9693
|
+
restoreInteractionCheckpoints(saved) {
|
|
9694
|
+
if (this.inner.restoreInteractionCheckpoints) {
|
|
9695
|
+
this.inner.restoreInteractionCheckpoints(saved);
|
|
9696
|
+
} else {
|
|
9697
|
+
this.inner.restoreInteractionCheckpoint?.(saved[saved.length - 1]);
|
|
9698
|
+
}
|
|
9699
|
+
}
|
|
9426
9700
|
getInteractionCheckpoint() {
|
|
9427
9701
|
return this.inner.getInteractionCheckpoint?.();
|
|
9428
9702
|
}
|
|
@@ -10144,6 +10418,68 @@ function defineAgent(config) {
|
|
|
10144
10418
|
return config;
|
|
10145
10419
|
}
|
|
10146
10420
|
|
|
10421
|
+
// src/autopilot/autopilot-tools.ts
|
|
10422
|
+
var WIDGET_READ = "widget_read";
|
|
10423
|
+
var WIDGET_ACT = "widget_act";
|
|
10424
|
+
var HAND_BACK = "hand_back";
|
|
10425
|
+
var AUTOPILOT_TOOL_DEFINITIONS = [
|
|
10426
|
+
{
|
|
10427
|
+
name: WIDGET_READ,
|
|
10428
|
+
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.",
|
|
10429
|
+
parameters: {
|
|
10430
|
+
type: "object",
|
|
10431
|
+
properties: {
|
|
10432
|
+
view: { type: "string", description: "One of the views the decision lists, if any." }
|
|
10433
|
+
}
|
|
10434
|
+
}
|
|
10435
|
+
},
|
|
10436
|
+
{
|
|
10437
|
+
name: WIDGET_ACT,
|
|
10438
|
+
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.',
|
|
10439
|
+
parameters: {
|
|
10440
|
+
type: "object",
|
|
10441
|
+
required: ["action"],
|
|
10442
|
+
properties: {
|
|
10443
|
+
action: {
|
|
10444
|
+
type: "string",
|
|
10445
|
+
description: 'An option number from the list, starting at 1, or a named action ("select", "reply").'
|
|
10446
|
+
},
|
|
10447
|
+
options: {
|
|
10448
|
+
type: "array",
|
|
10449
|
+
items: { type: "string" },
|
|
10450
|
+
description: 'For "select": the options to choose, by number or label.'
|
|
10451
|
+
},
|
|
10452
|
+
text: {
|
|
10453
|
+
type: "string",
|
|
10454
|
+
description: `For "reply" (your answer, in the user's place) and any action listed as name({text}): its one argument, as plain text.`
|
|
10455
|
+
},
|
|
10456
|
+
fields: {
|
|
10457
|
+
type: "string",
|
|
10458
|
+
description: "Only for an action listed as name({fields}): a JSON object, as text, matching the fields schema the decision lists for it."
|
|
10459
|
+
},
|
|
10460
|
+
note: {
|
|
10461
|
+
type: "string",
|
|
10462
|
+
description: "Shown to the user as the assistant speaking. One sentence, first person."
|
|
10463
|
+
}
|
|
10464
|
+
}
|
|
10465
|
+
}
|
|
10466
|
+
},
|
|
10467
|
+
{
|
|
10468
|
+
name: HAND_BACK,
|
|
10469
|
+
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.',
|
|
10470
|
+
parameters: {
|
|
10471
|
+
type: "object",
|
|
10472
|
+
required: ["reason"],
|
|
10473
|
+
properties: {
|
|
10474
|
+
reason: {
|
|
10475
|
+
type: "string",
|
|
10476
|
+
description: "What the user needs to decide, and why it is theirs."
|
|
10477
|
+
}
|
|
10478
|
+
}
|
|
10479
|
+
}
|
|
10480
|
+
}
|
|
10481
|
+
];
|
|
10482
|
+
|
|
10147
10483
|
// src/config/define-stateful-agent.ts
|
|
10148
10484
|
function defaultStatefulDebugSnapshot(state) {
|
|
10149
10485
|
if (!state || typeof state !== "object") return state;
|
|
@@ -10343,6 +10679,23 @@ function defineStatefulAgent(opts) {
|
|
|
10343
10679
|
};
|
|
10344
10680
|
}
|
|
10345
10681
|
function defineAutopilot(config) {
|
|
10682
|
+
const seen = new Set(AUTOPILOT_TOOL_DEFINITIONS.map((d) => d.name));
|
|
10683
|
+
for (const d of config.tools?.definitions ?? []) {
|
|
10684
|
+
if (seen.has(d.name)) {
|
|
10685
|
+
throw new Error(`defineAutopilot: the tool "${d.name}" is named twice.`);
|
|
10686
|
+
}
|
|
10687
|
+
seen.add(d.name);
|
|
10688
|
+
}
|
|
10689
|
+
for (const set of config.widgetTools ?? []) {
|
|
10690
|
+
for (const name of Object.keys(set.tools)) {
|
|
10691
|
+
if (seen.has(name)) {
|
|
10692
|
+
throw new Error(
|
|
10693
|
+
`defineAutopilot: the widget tool "${name}" (for "${set.componentName}") is named twice.`
|
|
10694
|
+
);
|
|
10695
|
+
}
|
|
10696
|
+
seen.add(name);
|
|
10697
|
+
}
|
|
10698
|
+
}
|
|
10346
10699
|
return config;
|
|
10347
10700
|
}
|
|
10348
10701
|
|