@genesislcap/ai-assistant 15.6.2 → 15.7.1
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 +422 -6
- package/dist/ai-assistant.d.ts +654 -19
- package/dist/chat-driver.cjs +285 -26
- package/dist/chat-driver.cjs.map +3 -3
- package/dist/chat-driver.mjs +285 -26
- package/dist/chat-driver.mjs.map +3 -3
- package/dist/custom-elements.json +289 -32
- package/dist/dts/channel/ai-activity-channel.d.ts +51 -1
- package/dist/dts/channel/ai-activity-channel.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +99 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.test.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.budget.test.d.ts +2 -0
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.budget.test.d.ts.map +1 -0
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +14 -0
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/components/settings-modal/settings-modal.styles.d.ts.map +1 -1
- package/dist/dts/components/settings-modal/settings-modal.template.d.ts.map +1 -1
- package/dist/dts/main/blocked-state.test.d.ts +2 -0
- package/dist/dts/main/blocked-state.test.d.ts.map +1 -0
- package/dist/dts/main/main.d.ts +435 -19
- package/dist/dts/main/main.d.ts.map +1 -1
- package/dist/dts/main/main.styles.d.ts.map +1 -1
- package/dist/dts/main/main.styles.test.d.ts +2 -0
- package/dist/dts/main/main.styles.test.d.ts.map +1 -0
- package/dist/dts/main/main.template.d.ts +53 -0
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/state/ai-assistant-slice.d.ts +162 -6
- package/dist/dts/state/ai-assistant-slice.d.ts.map +1 -1
- package/dist/dts/state/debug-event-log.d.ts +6 -1
- package/dist/dts/state/debug-event-log.d.ts.map +1 -1
- package/dist/dts/state/session-store.d.ts +11 -0
- package/dist/dts/state/session-store.d.ts.map +1 -1
- package/dist/dts/utils/banked-usage-baselines.d.ts +51 -0
- package/dist/dts/utils/banked-usage-baselines.d.ts.map +1 -0
- package/dist/esm/components/chat-driver/chat-driver.js +263 -21
- package/dist/esm/components/chat-driver/chat-driver.test.js +464 -1
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.budget.test.js +312 -0
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +89 -4
- package/dist/esm/components/settings-modal/settings-modal.styles.js +63 -18
- package/dist/esm/components/settings-modal/settings-modal.template.js +36 -7
- package/dist/esm/main/blocked-state.test.js +969 -0
- package/dist/esm/main/cost-session-banking.test.js +238 -8
- package/dist/esm/main/main.js +826 -48
- package/dist/esm/main/main.styles.js +72 -0
- package/dist/esm/main/main.styles.test.js +99 -0
- package/dist/esm/main/main.template.js +121 -4
- package/dist/esm/state/ai-assistant-slice.js +145 -7
- package/dist/esm/state/ai-assistant-slice.test.js +138 -1
- package/dist/esm/state/debug-event-log.js +7 -2
- package/dist/esm/state/debug-event-log.test.js +49 -1
- package/dist/esm/state/persistence/session-snapshot.test.js +18 -0
- package/dist/esm/utils/banked-usage-baselines.js +84 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/docs/migration-GENC-1464.md +562 -0
- package/docs/sub_agent.md +20 -3
- package/package.json +17 -17
- package/src/channel/ai-activity-channel.ts +56 -2
- package/src/components/chat-driver/chat-driver.test.ts +549 -0
- package/src/components/chat-driver/chat-driver.ts +324 -14
- package/src/components/orchestrating-driver/orchestrating-driver.budget.test.ts +438 -0
- package/src/components/orchestrating-driver/orchestrating-driver.ts +101 -6
- package/src/components/settings-modal/settings-modal.styles.ts +63 -18
- package/src/components/settings-modal/settings-modal.template.ts +38 -7
- package/src/main/blocked-state.test.ts +1316 -0
- package/src/main/cost-session-banking.test.ts +283 -11
- package/src/main/main.styles.test.ts +130 -0
- package/src/main/main.styles.ts +72 -0
- package/src/main/main.template.ts +131 -4
- package/src/main/main.ts +827 -42
- package/src/state/ai-assistant-slice.test.ts +215 -0
- package/src/state/ai-assistant-slice.ts +218 -8
- package/src/state/debug-event-log.test.ts +63 -0
- package/src/state/debug-event-log.ts +7 -2
- package/src/state/persistence/session-snapshot.test.ts +22 -0
- package/src/utils/banked-usage-baselines.ts +90 -0
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { AggregateUsage } from '@genesislcap/foundation-ai';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Per-session banked baselines for the cost ledger (GENC-1475) — the spend a project had
|
|
5
|
+
* accrued *before* the transcript currently in memory. Module-level and keyed by the session
|
|
6
|
+
* `stateKey`, exactly like the diagnostics cursors and the meta-event buffer.
|
|
7
|
+
*
|
|
8
|
+
* The lifetime is the point of this module. A baseline is only meaningful paired with the
|
|
9
|
+
* transcript it complements: `row.usage = baseline + whatever that transcript proves`. The
|
|
10
|
+
* transcript lives in the per-key session store, so the baseline must live and die with that
|
|
11
|
+
* store — which means module state keyed the same way, NOT element state.
|
|
12
|
+
*
|
|
13
|
+
* Held on the element it silently double-counted. Element instances are created and destroyed
|
|
14
|
+
* many times inside one session (the assistant is remounted as the host re-renders its layout,
|
|
15
|
+
* and a popped-out bubble and a docked panel can be wired to the same session at once), and each
|
|
16
|
+
* new instance re-derived the baseline from the ledger rows. By then those rows contain the
|
|
17
|
+
* instance-before-last's own upserts, whose `usage` already includes the live transcript — so
|
|
18
|
+
* where the transcript is NOT restored on load (`resolveBankedUsage`'s "bank the whole prior
|
|
19
|
+
* total" branch, i.e. persistence off) the live session was banked as its own baseline. Lifetime
|
|
20
|
+
* then jumped by the whole session-to-date on every remount while the live figure kept climbing
|
|
21
|
+
* normally, which is the "the two totals went up by different amounts" report.
|
|
22
|
+
*
|
|
23
|
+
* Module state dies with the JS realm, so a real page reload starts clean — exactly right, since
|
|
24
|
+
* that is also when the transcript starts over.
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
const baselinesByKey = new Map<string, AggregateUsage>();
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The baseline resolved for `key`, or `undefined` when this session has not resolved one yet.
|
|
32
|
+
*
|
|
33
|
+
* `undefined` rather than an empty usage: "nothing banked" is a legitimate resolved value (a
|
|
34
|
+
* project's first ever session), and it must not be mistaken for "not resolved", or every write
|
|
35
|
+
* would re-derive and hit the double-count above.
|
|
36
|
+
*
|
|
37
|
+
* Returns a copy — see `setBankedBaseline` for why both ends of this map are cloned.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export function getBankedBaseline(key: string): AggregateUsage | undefined {
|
|
42
|
+
const usage = baselinesByKey.get(key);
|
|
43
|
+
return usage ? { ...usage } : undefined;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Record the baseline for `key`, replacing any previous one.
|
|
48
|
+
*
|
|
49
|
+
* Stores a copy, and `getBankedBaseline` hands back a copy, so nothing outside this module can
|
|
50
|
+
* reach the object the map holds. Both ends have to clone, because a baseline is aliased at both:
|
|
51
|
+
* `resolveBankedUsage` returns a *reference into a ledger row* (`row.banked` or `row.usage`),
|
|
52
|
+
* which is what gets stored here, and the caller then assigns what it reads back onto the NEXT
|
|
53
|
+
* row's `banked` field. Uncloned, one object is reachable from page-global state, two rows, and —
|
|
54
|
+
* since the row list is public and gets handed to a host's `saveCostHistory` — from host code.
|
|
55
|
+
* Whoever mutated it would silently rewrite this project's baseline for the rest of the page.
|
|
56
|
+
*
|
|
57
|
+
* A shallow spread is a complete copy: `AggregateUsage` is five flat numbers, no nested state.
|
|
58
|
+
*
|
|
59
|
+
* @internal
|
|
60
|
+
*/
|
|
61
|
+
export function setBankedBaseline(key: string, usage: AggregateUsage): void {
|
|
62
|
+
baselinesByKey.set(key, { ...usage });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Drop the baseline for `key`, so the next write re-derives it from the ledger rows.
|
|
67
|
+
*
|
|
68
|
+
* For when the pairing is broken deliberately at the *row* end — the row this baseline came from
|
|
69
|
+
* has been deleted, or the whole ledger cleared — and for a session teardown, where the store
|
|
70
|
+
* (and with it the transcript) is disposed and a later return re-restores from scratch.
|
|
71
|
+
*
|
|
72
|
+
* NOT for a mid-session reload of the rows: those rows already include this session's own
|
|
73
|
+
* upserts, so re-deriving from them folds the live transcript into its own baseline.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export function deleteBankedBaseline(key: string): void {
|
|
78
|
+
baselinesByKey.delete(key);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Forget every baseline — the page-load boundary, which production gets for free from module
|
|
83
|
+
* state dying with the realm. Exists so tests can model separate page loads (and so one test's
|
|
84
|
+
* session key cannot leak a baseline into the next).
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
export function resetBankedBaselines(): void {
|
|
89
|
+
baselinesByKey.clear();
|
|
90
|
+
}
|