@genesislcap/ai-assistant 15.98.3 → 15.99.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 +112 -7
- package/dist/ai-assistant.d.ts +42 -10
- package/dist/chat-driver.cjs +389 -68
- package/dist/chat-driver.cjs.map +3 -3
- package/dist/chat-driver.mjs +387 -68
- package/dist/chat-driver.mjs.map +3 -3
- package/dist/custom-elements.json +129 -1
- package/dist/dts/chat-driver-node.d.ts +1 -1
- package/dist/dts/chat-driver-node.d.ts.map +1 -1
- package/dist/dts/components/ai-driver/ai-driver.d.ts +15 -5
- package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
- package/dist/dts/components/ai-driver/base-driver-decorator.d.ts +1 -0
- package/dist/dts/components/ai-driver/base-driver-decorator.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.constants.d.ts +25 -0
- package/dist/dts/components/chat-driver/chat-driver.constants.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/hand-off.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +2 -0
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/config/config.d.ts +24 -5
- package/dist/dts/config/config.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-persister.d.ts +22 -0
- package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
- package/dist/esm/chat-driver-node.js +1 -1
- package/dist/esm/components/ai-driver/base-driver-decorator.js +4 -0
- package/dist/esm/components/chat-driver/chat-driver.constants.js +31 -0
- package/dist/esm/components/chat-driver/chat-driver.js +81 -5
- package/dist/esm/components/orchestrating-driver/hand-off.js +2 -0
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +20 -2
- package/dist/esm/state/debug-event-log.js +2 -2
- package/dist/esm/state/persistence/session-persister.js +106 -11
- package/package.json +17 -17
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
|
+
import { parseHandOffFrames } from '../../components/orchestrating-driver/hand-off';
|
|
2
3
|
import { withoutAttachmentNote } from '../../utils/attachment-note';
|
|
3
4
|
import { flattenSubAgentMessages } from '../../utils/flatten-sub-agent-messages';
|
|
4
5
|
import { logger } from '../../utils/logger';
|
|
@@ -37,6 +38,12 @@ function handOffsOf(driver) {
|
|
|
37
38
|
handOffData: (_f = (_e = driver === null || driver === void 0 ? void 0 : driver.getHandOffData) === null || _e === void 0 ? void 0 : _e.call(driver)) !== null && _f !== void 0 ? _f : {},
|
|
38
39
|
};
|
|
39
40
|
}
|
|
41
|
+
/** The saved hand-off data of the callers on the saved stack alone. */
|
|
42
|
+
function callersData(snapshot) {
|
|
43
|
+
var _a;
|
|
44
|
+
const callers = new Set(parseHandOffFrames(snapshot.handoffStack).map((f) => f.caller));
|
|
45
|
+
return Object.fromEntries(Object.entries((_a = snapshot.handOffData) !== null && _a !== void 0 ? _a : {}).filter(([name]) => callers.has(name)));
|
|
46
|
+
}
|
|
40
47
|
/**
|
|
41
48
|
* Restore the saved hand-offs (GENC-1737), and settle what the restore re-activates and locks:
|
|
42
49
|
* - the top frame's target had finished, or has gone: its caller resumes, and the target's lock
|
|
@@ -47,8 +54,11 @@ function handOffsOf(driver) {
|
|
|
47
54
|
*/
|
|
48
55
|
function restoreHandOffs(driver, snapshot, restored) {
|
|
49
56
|
var _a, _b, _c, _d, _e, _f;
|
|
50
|
-
// The data first: the stack drops it for a caller that cannot resume.
|
|
51
|
-
|
|
57
|
+
// The data first: the stack drops it for a caller that cannot resume. A frozen save keeps only
|
|
58
|
+
// the waiting callers' data, which is for the callers that resume, so that is restored. A save
|
|
59
|
+
// frozen by an earlier release holds the running target's too, which has nothing to resume, so
|
|
60
|
+
// a frozen session is cut to the callers on its stack.
|
|
61
|
+
(_a = driver === null || driver === void 0 ? void 0 : driver.restoreHandOffData) === null || _a === void 0 ? void 0 : _a.call(driver, snapshot.interrupted ? callersData(snapshot) : snapshot.handOffData, false);
|
|
52
62
|
const { resume, droppedLocks } = (_d = (_b = driver === null || driver === void 0 ? void 0 : driver.restoreHandOffStack) === null || _b === void 0 ? void 0 : _b.call(driver, snapshot.handoffStack, (_c = snapshot.agentSnapshots) !== null && _c !== void 0 ? _c : {}, !!snapshot.interrupted)) !== null && _d !== void 0 ? _d : {};
|
|
53
63
|
if (resume) {
|
|
54
64
|
const note = ((_e = driver === null || driver === void 0 ? void 0 : driver.canResumeRestoredFlow) === null || _e === void 0 ? void 0 : _e.call(driver, resume.agent)) ? resume.note : undefined;
|
|
@@ -98,6 +108,8 @@ const DEFAULT_DIAGNOSTICS_DEBOUNCE_MS = 4000;
|
|
|
98
108
|
*/
|
|
99
109
|
const SAVE_FAILURES_BEFORE_BROKEN = 2;
|
|
100
110
|
const DEFAULT_NOT_RESUMABLE_MESSAGE = "Sorry, I didn't manage to finish the task from your previous message. Send it again if you'd like me to try it again";
|
|
111
|
+
/** The notice a restore shows when a waiting caller resumes after its target was cut short. */
|
|
112
|
+
const HAND_BACK_INTERRUPTED_MESSAGE = 'The reload cut that work short, so some of it was lost. Picking up from here.';
|
|
101
113
|
/**
|
|
102
114
|
* Owns **restore-core** persistence for one session (GENC-1351 §5.10) — the
|
|
103
115
|
* save/restore/freeze of the {@link PersistedSession} snapshot plus the
|
|
@@ -325,6 +337,71 @@ export class SessionPersister {
|
|
|
325
337
|
}
|
|
326
338
|
});
|
|
327
339
|
}
|
|
340
|
+
/**
|
|
341
|
+
* What a frozen save keeps of the hand-off stack (GENC-1640). The stack is a chain of agents that
|
|
342
|
+
* hand back to each other. The running agent cannot persist, and neither may the callers just
|
|
343
|
+
* below it, so the session goes back to the TOPMOST waiting caller that can: the frames above it
|
|
344
|
+
* are dropped, with their agents' state and data, and it resumes told `target-interrupted`.
|
|
345
|
+
*
|
|
346
|
+
* Every frame at or below the cut is kept, so a caller there that says it cannot resume still
|
|
347
|
+
* has its frame; it just has no saved state or data, so the restore unwinds that frame as
|
|
348
|
+
* `state-lost` and the frame below it waits on the caller's target instead. The answer for a
|
|
349
|
+
* caller is therefore its own, not its neighbours'. With none able to resume, the whole stack is
|
|
350
|
+
* kept for the restore to unwind as `state-lost`, and no caller's state or data is saved.
|
|
351
|
+
*/
|
|
352
|
+
frozenHandOffs(driver, handoffStack, agentSnapshots, handOffData, key, messages) {
|
|
353
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
354
|
+
var _a, _b;
|
|
355
|
+
const agents = (_b = (_a = driver === null || driver === void 0 ? void 0 : driver.getWaitingCallers) === null || _a === void 0 ? void 0 : _a.call(driver)) !== null && _b !== void 0 ? _b : [];
|
|
356
|
+
const ask = (name) => this.callerCanResume(name, agents, agentSnapshots, key, messages);
|
|
357
|
+
let cut = -1;
|
|
358
|
+
for (let i = handoffStack.length - 1; i >= 0 && cut < 0; i -= 1) {
|
|
359
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
360
|
+
if (yield ask(handoffStack[i].caller))
|
|
361
|
+
cut = i;
|
|
362
|
+
}
|
|
363
|
+
const keptFrames = cut < 0 ? handoffStack : handoffStack.slice(0, cut + 1);
|
|
364
|
+
const callers = [];
|
|
365
|
+
for (let i = 0; i <= cut; i += 1) {
|
|
366
|
+
const name = keptFrames[i].caller;
|
|
367
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
368
|
+
if (i === cut || (yield ask(name)))
|
|
369
|
+
callers.push(name);
|
|
370
|
+
}
|
|
371
|
+
const only = (all) => Object.fromEntries(Object.entries(all).filter(([name]) => callers.includes(name)));
|
|
372
|
+
return {
|
|
373
|
+
keptFrames,
|
|
374
|
+
callers,
|
|
375
|
+
callerSnapshots: only(agentSnapshots),
|
|
376
|
+
callerData: only(handOffData),
|
|
377
|
+
};
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Whether the waiting caller `name` can resume (GENC-1640): asked as the active agent is, with
|
|
382
|
+
* its own saved state. A caller with no `resumable` can; one that throws is taken to (fail-safe,
|
|
383
|
+
* as for the active agent).
|
|
384
|
+
*/
|
|
385
|
+
callerCanResume(name, callers, agentSnapshots, key, messages) {
|
|
386
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
387
|
+
const agent = callers.find((a) => a.name === name);
|
|
388
|
+
if (!(agent === null || agent === void 0 ? void 0 : agent.resumable))
|
|
389
|
+
return true;
|
|
390
|
+
try {
|
|
391
|
+
return yield agent.resumable({
|
|
392
|
+
agentName: name,
|
|
393
|
+
sessionKey: key,
|
|
394
|
+
state: agentSnapshots[name],
|
|
395
|
+
messages,
|
|
396
|
+
isFlowOwner: false,
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
catch (e) {
|
|
400
|
+
logger.error('Session save: resumable() threw on a waiting caller — resuming it:', e);
|
|
401
|
+
return true;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
}
|
|
328
405
|
/**
|
|
329
406
|
* The transcript to STORE, for both save paths (the resumable autosave and the non-resumable
|
|
330
407
|
* freeze, which slices this same array).
|
|
@@ -354,6 +431,9 @@ export class SessionPersister {
|
|
|
354
431
|
*
|
|
355
432
|
* `flowDropped` is the frozen (non-resumable) save: its snapshot drops the running flow, so the
|
|
356
433
|
* activation that owned the pending payloads does not resume and they are written as ended.
|
|
434
|
+
* `keepAgents` are the callers waiting in a hand-off, whose activations do resume (GENC-1640):
|
|
435
|
+
* their payloads stay as they are, so a caller that reads a document before handing off still
|
|
436
|
+
* has it in full after the reload.
|
|
357
437
|
*
|
|
358
438
|
* Never throws: a failure here costs a resumed session some context, which is not worth losing
|
|
359
439
|
* the save over.
|
|
@@ -364,7 +444,12 @@ export class SessionPersister {
|
|
|
364
444
|
const pending = (_a = driver === null || driver === void 0 ? void 0 : driver.getCondensePoliciesForPersistence) === null || _a === void 0 ? void 0 : _a.call(driver, messages);
|
|
365
445
|
if (!(pending === null || pending === void 0 ? void 0 : pending.length) || !opts.flowDropped)
|
|
366
446
|
return pending;
|
|
367
|
-
return pending.map((e) =>
|
|
447
|
+
return pending.map((e) => {
|
|
448
|
+
var _a;
|
|
449
|
+
return e.elapsed.activations > 0 || (e.agent !== undefined && ((_a = opts.keepAgents) === null || _a === void 0 ? void 0 : _a.includes(e.agent)))
|
|
450
|
+
? e
|
|
451
|
+
: Object.assign(Object.assign({}, e), { elapsed: Object.assign(Object.assign({}, e.elapsed), { activations: 1 }) });
|
|
452
|
+
});
|
|
368
453
|
}
|
|
369
454
|
catch (e) {
|
|
370
455
|
logger.error('Session save: capturing condense policies failed:', e);
|
|
@@ -422,6 +507,8 @@ export class SessionPersister {
|
|
|
422
507
|
// that is failing.
|
|
423
508
|
this.maybeReportBroken(resumable, messages.length);
|
|
424
509
|
if (!resumable) {
|
|
510
|
+
// What a frozen save keeps of the hand-off stack (GENC-1640): see `frozenHandOffs`.
|
|
511
|
+
const { keptFrames, callers, callerSnapshots, callerData } = yield this.frozenHandOffs(driver, handoffStack, agentSnapshots, handOffData, key, messages);
|
|
425
512
|
// FREEZE THE FLOW STATE, NOT THE TRANSCRIPT (GENC-1511).
|
|
426
513
|
//
|
|
427
514
|
// The intent of §5.9 is the one stated on `PersistedSession.interrupted`: the
|
|
@@ -463,18 +550,21 @@ export class SessionPersister {
|
|
|
463
550
|
contextLimit: s.contextLimit,
|
|
464
551
|
activeModel: s.activeModel,
|
|
465
552
|
activeProviderName: s.activeProviderName,
|
|
466
|
-
agentSnapshots:
|
|
553
|
+
agentSnapshots: callerSnapshots,
|
|
467
554
|
// Pending condense policies are carried here too (GENC-1632), but with the live
|
|
468
555
|
// activation marked as ENDED: this snapshot drops the flow's state, so on return the
|
|
469
556
|
// agent starts afresh rather than resuming, and the activation those payloads belonged to
|
|
470
557
|
// is over. Without the mark, a re-run of the same agent would be taken for a resumption
|
|
471
|
-
// and adopt the dead flow's `agentEnd` / `phaseEnd` payloads for its whole new run.
|
|
558
|
+
// and adopt the dead flow's `agentEnd` / `phaseEnd` payloads for its whole new run. The
|
|
559
|
+
// waiting callers do resume (GENC-1640), so their payloads are left as they are.
|
|
472
560
|
condensePolicies: this.condensePoliciesToPersist(driver, frozenMessages, {
|
|
473
561
|
flowDropped: true,
|
|
562
|
+
keepAgents: callers,
|
|
474
563
|
}),
|
|
475
|
-
//
|
|
476
|
-
//
|
|
477
|
-
handoffStack,
|
|
564
|
+
// The frames up to the resume point, whose target is the one cut short: a restore hands back
|
|
565
|
+
// to its caller, `target-interrupted` (GENC-1640).
|
|
566
|
+
handoffStack: keptFrames,
|
|
567
|
+
handOffData: callerData,
|
|
478
568
|
});
|
|
479
569
|
// Skip the write when the frozen boundary has not moved — a flow autosaves on every
|
|
480
570
|
// transcript change, and while it runs the last user message (and therefore the
|
|
@@ -737,15 +827,20 @@ export class SessionPersister {
|
|
|
737
827
|
// lacks it — re-appending otherwise duplicates the bubble (GENC-1351 §5.9).
|
|
738
828
|
const lastUser = trimmed[lastUserMessageIndex(trimmed)];
|
|
739
829
|
const promptAlreadyPresent = (lastUser === null || lastUser === void 0 ? void 0 : lastUser.content) === prompt;
|
|
740
|
-
|
|
830
|
+
// Not when a waiting caller resumes (GENC-1640): the request it handed on is what was lost,
|
|
831
|
+
// and the caller's own hand-back turn decides what happens next, so a user bubble, or a
|
|
832
|
+
// composer holding the request to send again, would invite a second run of the same work.
|
|
833
|
+
if (prompt && !promptAlreadyPresent && !handBack) {
|
|
741
834
|
trailers.push(Object.assign(Object.assign({ role: 'user', content: prompt }, (files ? { attachments: files } : {})), { timestamp: trailerTs }));
|
|
742
835
|
}
|
|
743
836
|
// The files stay on the transcript message and aren't put back in the composer, so it
|
|
744
837
|
// gets only what was typed.
|
|
745
|
-
prefill = prompt ? withoutAttachmentNote(prompt, files) :
|
|
838
|
+
prefill = prompt && !handBack ? withoutAttachmentNote(prompt, files) : undefined;
|
|
746
839
|
trailers.push({
|
|
747
840
|
role: 'assistant',
|
|
748
|
-
|
|
841
|
+
// A resuming caller is already acting on the lost request, so the target's own notice,
|
|
842
|
+
// which invites the user to send it again, is replaced (GENC-1640).
|
|
843
|
+
content: handBack ? HAND_BACK_INTERRUPTED_MESSAGE : snapshot.interrupted.message,
|
|
749
844
|
timestamp: trailerTs,
|
|
750
845
|
});
|
|
751
846
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@genesislcap/ai-assistant",
|
|
3
3
|
"description": "Genesis AI Assistant micro-frontend",
|
|
4
|
-
"version": "15.
|
|
4
|
+
"version": "15.99.0",
|
|
5
5
|
"license": "SEE LICENSE IN license.txt",
|
|
6
6
|
"main": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/dts/index.d.ts",
|
|
@@ -102,31 +102,31 @@
|
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
104
|
"devDependencies": {
|
|
105
|
-
"@genesislcap/foundation-comms": "15.
|
|
106
|
-
"@genesislcap/foundation-testing": "15.
|
|
107
|
-
"@genesislcap/genx": "15.
|
|
108
|
-
"@genesislcap/ts-builder": "15.
|
|
109
|
-
"@genesislcap/uvu-playwright-builder": "15.
|
|
110
|
-
"@genesislcap/vite-builder": "15.
|
|
111
|
-
"@genesislcap/webpack-builder": "15.
|
|
105
|
+
"@genesislcap/foundation-comms": "15.99.0",
|
|
106
|
+
"@genesislcap/foundation-testing": "15.99.0",
|
|
107
|
+
"@genesislcap/genx": "15.99.0",
|
|
108
|
+
"@genesislcap/ts-builder": "15.99.0",
|
|
109
|
+
"@genesislcap/uvu-playwright-builder": "15.99.0",
|
|
110
|
+
"@genesislcap/vite-builder": "15.99.0",
|
|
111
|
+
"@genesislcap/webpack-builder": "15.99.0",
|
|
112
112
|
"@types/dompurify": "^3.0.5",
|
|
113
113
|
"@types/marked": "^5.0.2",
|
|
114
114
|
"esbuild": "0.25.12"
|
|
115
115
|
},
|
|
116
116
|
"dependencies": {
|
|
117
|
-
"@genesislcap/foundation-ai": "15.
|
|
118
|
-
"@genesislcap/foundation-logger": "15.
|
|
119
|
-
"@genesislcap/foundation-notifications": "15.
|
|
120
|
-
"@genesislcap/foundation-redux": "15.
|
|
121
|
-
"@genesislcap/foundation-ui": "15.
|
|
122
|
-
"@genesislcap/foundation-utils": "15.
|
|
123
|
-
"@genesislcap/rapid-design-system": "15.
|
|
124
|
-
"@genesislcap/web-core": "15.
|
|
117
|
+
"@genesislcap/foundation-ai": "15.99.0",
|
|
118
|
+
"@genesislcap/foundation-logger": "15.99.0",
|
|
119
|
+
"@genesislcap/foundation-notifications": "15.99.0",
|
|
120
|
+
"@genesislcap/foundation-redux": "15.99.0",
|
|
121
|
+
"@genesislcap/foundation-ui": "15.99.0",
|
|
122
|
+
"@genesislcap/foundation-utils": "15.99.0",
|
|
123
|
+
"@genesislcap/rapid-design-system": "15.99.0",
|
|
124
|
+
"@genesislcap/web-core": "15.99.0",
|
|
125
125
|
"dompurify": "^3.3.1",
|
|
126
126
|
"marked": "^17.0.3"
|
|
127
127
|
},
|
|
128
128
|
"peerDependencies": {
|
|
129
|
-
"@genesislcap/foundation-comms": "15.
|
|
129
|
+
"@genesislcap/foundation-comms": "15.99.0"
|
|
130
130
|
},
|
|
131
131
|
"peerDependenciesMeta": {
|
|
132
132
|
"@genesislcap/foundation-comms": {
|