@genesislcap/ai-assistant 15.35.1 → 15.35.4

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.
Files changed (27) hide show
  1. package/dist/ai-assistant.api.json +483 -0
  2. package/dist/ai-assistant.d.ts +192 -0
  3. package/dist/chat-driver.cjs +221 -4
  4. package/dist/chat-driver.cjs.map +2 -2
  5. package/dist/chat-driver.mjs +221 -4
  6. package/dist/chat-driver.mjs.map +2 -2
  7. package/dist/custom-elements.json +267 -1
  8. package/dist/dts/components/ai-driver/ai-driver.d.ts +31 -0
  9. package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
  10. package/dist/dts/components/chat-driver/chat-driver.d.ts +93 -0
  11. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  12. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +17 -0
  13. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
  14. package/dist/dts/state/persistence/index.d.ts +1 -0
  15. package/dist/dts/state/persistence/index.d.ts.map +1 -1
  16. package/dist/dts/state/persistence/session-persister.d.ts +12 -0
  17. package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
  18. package/dist/dts/state/persistence/session-snapshot.d.ts +14 -0
  19. package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
  20. package/dist/dts/utils/condense-history.d.ts +114 -0
  21. package/dist/dts/utils/condense-history.d.ts.map +1 -1
  22. package/dist/esm/components/chat-driver/chat-driver.js +140 -17
  23. package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +17 -0
  24. package/dist/esm/state/persistence/session-persister.js +63 -15
  25. package/dist/esm/state/persistence/session-snapshot.js +2 -17
  26. package/dist/esm/utils/condense-history.js +123 -0
  27. package/package.json +18 -18
@@ -22,6 +22,129 @@ import { APPROX_CHARS_PER_TOKEN } from './context-tokens';
22
22
  export const CONDENSE_MIN_CHARS = 1000;
23
23
  /** Key the collapsed args are stored under — a tool-call's args must stay a Record. */
24
24
  export const CONDENSED_ARGS_KEY = 'condensed';
25
+ /** Whether `t` is a well-formed trigger — the same rule `condenseWhen` enforces on registration. */
26
+ export function isValidCondenseTrigger(t) {
27
+ if ((t === null || t === void 0 ? void 0 : t.kind) === 'superseded')
28
+ return typeof t.by === 'string' && t.by.length > 0;
29
+ if ((t === null || t === void 0 ? void 0 : t.kind) === 'age')
30
+ return typeof t.turns === 'number' && t.turns >= 1;
31
+ return (t === null || t === void 0 ? void 0 : t.kind) === 'turnEnd' || (t === null || t === void 0 ? void 0 : t.kind) === 'agentEnd' || (t === null || t === void 0 ? void 0 : t.kind) === 'phaseEnd';
32
+ }
33
+ /** Whether `r` is a well-formed replacement mode (`pointer` / `drop` / `{ replaceWith }`). */
34
+ function isValidCondenseResult(r) {
35
+ if (r === 'pointer' || r === 'drop')
36
+ return true;
37
+ return (!!r && typeof r === 'object' && typeof r.replaceWith === 'string');
38
+ }
39
+ /**
40
+ * Every tool-call id carried by an assistant message in `history`. Exported so the save side
41
+ * ({@link snapshotCondensePolicies}) and the restore side (`ChatDriver.restoreCondensePolicies`)
42
+ * compute "is this call still present?" from one definition — GENC-1632 review: the two had drifted
43
+ * into separate copies of the same loop.
44
+ */
45
+ export function toolCallIdsIn(history) {
46
+ var _a;
47
+ const ids = new Set();
48
+ for (const msg of history) {
49
+ for (const tc of (_a = msg.toolCalls) !== null && _a !== void 0 ? _a : [])
50
+ ids.add(tc.id);
51
+ }
52
+ return ids;
53
+ }
54
+ /**
55
+ * The entries to PERSIST alongside `history` (GENC-1632): every registered policy that has not
56
+ * fired yet and whose tool call is still in the transcript being saved, re-expressed as elapsed
57
+ * clock counts (see {@link PersistedCondensePolicy}).
58
+ *
59
+ * `history` is the transcript actually being written, not the driver's live one, because the two
60
+ * can differ: a non-resumable save freezes at the last user message, and a compaction may have
61
+ * summarised a call away. An entry whose call is not in the saved transcript has nothing to
62
+ * collapse after a reload, so it is not written.
63
+ *
64
+ * Pure, no writes to the registry — safe on a save path that runs on every autosave.
65
+ */
66
+ export function snapshotCondensePolicies(policies, clocks, history) {
67
+ if (policies.size === 0)
68
+ return [];
69
+ const present = toolCallIdsIn(history);
70
+ const out = [];
71
+ for (const [toolCallId, entry] of policies) {
72
+ if (entry.firedTrigger || !present.has(toolCallId))
73
+ continue;
74
+ out.push(Object.assign(Object.assign({ toolCallId, policy: entry.policy }, (entry.agent !== undefined && { agent: entry.agent })), { elapsed: {
75
+ // `max(0, …)`: every clock is monotonic, so these are never negative on a live driver;
76
+ // the clamp only stops a malformed entry from being written out as "the future".
77
+ modelCalls: Math.max(0, clocks.modelCall - entry.iteration),
78
+ turns: Math.max(0, clocks.turn - entry.turn),
79
+ activations: Math.max(0, clocks.activation - entry.activation),
80
+ phases: Math.max(0, clocks.phaseEpoch - entry.phaseEpoch),
81
+ } }));
82
+ }
83
+ return out;
84
+ }
85
+ /**
86
+ * Validate one persisted entry read back from storage. Returns `undefined` for anything that is not
87
+ * a well-formed {@link PersistedCondensePolicy} — the blob came off a disk or a network, and a
88
+ * policy that cannot be evaluated must be dropped rather than reach `applyCondensation`, which
89
+ * trusts its registry. A missing or malformed `elapsed` count reads as `0` (the boundary had not
90
+ * passed), which errs towards keeping a payload visible rather than eliding it.
91
+ */
92
+ export function parsePersistedCondensePolicy(value) {
93
+ var _a;
94
+ if (!value || typeof value !== 'object')
95
+ return undefined;
96
+ const v = value;
97
+ if (typeof v.toolCallId !== 'string' || !v.toolCallId)
98
+ return undefined;
99
+ const policy = v.policy;
100
+ if (!policy || typeof policy !== 'object')
101
+ return undefined;
102
+ const triggers = Array.isArray(policy.on) ? policy.on : [policy.on];
103
+ if (triggers.length === 0 || !triggers.every(isValidCondenseTrigger))
104
+ return undefined;
105
+ if (policy.args === undefined && policy.response === undefined)
106
+ return undefined;
107
+ if (policy.args !== undefined && !isValidCondenseResult(policy.args))
108
+ return undefined;
109
+ if (policy.response !== undefined && !isValidCondenseResult(policy.response))
110
+ return undefined;
111
+ const count = (n) => typeof n === 'number' && Number.isFinite(n) && n > 0 ? Math.floor(n) : 0;
112
+ const e = ((_a = v.elapsed) !== null && _a !== void 0 ? _a : {});
113
+ return Object.assign(Object.assign({ toolCallId: v.toolCallId, policy }, (typeof v.agent === 'string' && { agent: v.agent })), { elapsed: {
114
+ modelCalls: count(e.modelCalls),
115
+ turns: count(e.turns),
116
+ activations: count(e.activations),
117
+ phases: count(e.phases),
118
+ } });
119
+ }
120
+ /**
121
+ * Re-register a persisted entry against a (typically fresh) driver's clocks (GENC-1632): each
122
+ * stamp is the current clock minus the elapsed count, so every trigger stands exactly as far from
123
+ * firing as it did when the session was saved.
124
+ *
125
+ * Per clock, what that means after a reload:
126
+ * - `age` — exact. The model-call distance is preserved, so a result seen twice of its three
127
+ * allowed looks gets one more. The rebased `iteration` is usually negative (the call predates
128
+ * this driver's first model call), which the trigger arithmetic is indifferent to; it does
129
+ * surface as a negative `turn` on the eventual `context.condensed` event.
130
+ * - `turnEnd` — a call from the turn that was running at save time collapses on the next
131
+ * `sendMessage`. That is the original intent, not an approximation: a reload ends the turn.
132
+ * - `phaseEnd` — collapses at the next `endPhase()`, or at once if the phase had already ended.
133
+ * - `agentEnd` (and `phaseEnd`'s backstop) — an entry whose activation had already ended collapses
134
+ * at once. One owned by the activation live at save time is stamped with the CURRENT
135
+ * activation, which reads as live; but the driver will very likely advance its activation clock
136
+ * when the agent is re-installed after the reload, so this stamp is provisional and the driver
137
+ * must re-stamp it at that point — see `ChatDriver.installAgent`. Leaving it here would collapse
138
+ * the payload the moment the flow resumes, which is the failure this whole mechanism exists to
139
+ * avoid.
140
+ *
141
+ * The `reported*` latches start clear, so the eventual full→stub transition reports once, like any
142
+ * other entry. The stored transcript cannot hold a stub for an unfired entry, so there is no
143
+ * earlier report to duplicate.
144
+ */
145
+ export function rebaseRestoredCondensePolicy(entry, clocks) {
146
+ return Object.assign({ policy: entry.policy, iteration: clocks.modelCall - entry.elapsed.modelCalls, turn: clocks.turn - entry.elapsed.turns, activation: clocks.activation - entry.elapsed.activations, phaseEpoch: clocks.phaseEpoch - entry.elapsed.phases }, (entry.agent !== undefined && { agent: entry.agent }));
147
+ }
25
148
  /** Short human-readable reason for the stub text, per fired trigger. */
26
149
  function triggerReason(trigger) {
27
150
  switch (trigger.kind) {
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.35.1",
4
+ "version": "15.35.4",
5
5
  "license": "SEE LICENSE IN license.txt",
6
6
  "main": "dist/esm/index.js",
7
7
  "types": "dist/ai-assistant.d.ts",
@@ -82,32 +82,32 @@
82
82
  }
83
83
  },
84
84
  "devDependencies": {
85
- "@genesislcap/foundation-comms": "15.35.1",
86
- "@genesislcap/foundation-testing": "15.35.1",
87
- "@genesislcap/genx": "15.35.1",
88
- "@genesislcap/rollup-builder": "15.35.1",
89
- "@genesislcap/ts-builder": "15.35.1",
90
- "@genesislcap/uvu-playwright-builder": "15.35.1",
91
- "@genesislcap/vite-builder": "15.35.1",
92
- "@genesislcap/webpack-builder": "15.35.1",
85
+ "@genesislcap/foundation-comms": "15.35.4",
86
+ "@genesislcap/foundation-testing": "15.35.4",
87
+ "@genesislcap/genx": "15.35.4",
88
+ "@genesislcap/rollup-builder": "15.35.4",
89
+ "@genesislcap/ts-builder": "15.35.4",
90
+ "@genesislcap/uvu-playwright-builder": "15.35.4",
91
+ "@genesislcap/vite-builder": "15.35.4",
92
+ "@genesislcap/webpack-builder": "15.35.4",
93
93
  "@types/dompurify": "^3.0.5",
94
94
  "@types/marked": "^5.0.2",
95
95
  "esbuild": "0.25.12"
96
96
  },
97
97
  "dependencies": {
98
- "@genesislcap/foundation-ai": "15.35.1",
99
- "@genesislcap/foundation-logger": "15.35.1",
100
- "@genesislcap/foundation-notifications": "15.35.1",
101
- "@genesislcap/foundation-redux": "15.35.1",
102
- "@genesislcap/foundation-ui": "15.35.1",
103
- "@genesislcap/foundation-utils": "15.35.1",
104
- "@genesislcap/rapid-design-system": "15.35.1",
105
- "@genesislcap/web-core": "15.35.1",
98
+ "@genesislcap/foundation-ai": "15.35.4",
99
+ "@genesislcap/foundation-logger": "15.35.4",
100
+ "@genesislcap/foundation-notifications": "15.35.4",
101
+ "@genesislcap/foundation-redux": "15.35.4",
102
+ "@genesislcap/foundation-ui": "15.35.4",
103
+ "@genesislcap/foundation-utils": "15.35.4",
104
+ "@genesislcap/rapid-design-system": "15.35.4",
105
+ "@genesislcap/web-core": "15.35.4",
106
106
  "dompurify": "^3.3.1",
107
107
  "marked": "^17.0.3"
108
108
  },
109
109
  "peerDependencies": {
110
- "@genesislcap/foundation-comms": "^15.35.1"
110
+ "@genesislcap/foundation-comms": "^15.35.4"
111
111
  },
112
112
  "peerDependenciesMeta": {
113
113
  "@genesislcap/foundation-comms": {