@genesislcap/ai-assistant 15.35.1 → 15.35.4-FUI-0.9

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 (43) hide show
  1. package/dist/ai-assistant.api.json +483 -0
  2. package/dist/ai-assistant.d.ts +213 -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 +568 -206
  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-bubble/chat-bubble.d.ts.map +1 -1
  11. package/dist/dts/components/chat-bubble/chat-bubble.template.d.ts.map +1 -1
  12. package/dist/dts/components/chat-driver/chat-driver.d.ts +93 -0
  13. package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
  14. package/dist/dts/components/chat-markdown/chat-markdown.d.ts +29 -0
  15. package/dist/dts/components/chat-markdown/chat-markdown.d.ts.map +1 -1
  16. package/dist/dts/components/halo-overlay.d.ts +30 -0
  17. package/dist/dts/components/halo-overlay.d.ts.map +1 -1
  18. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +17 -0
  19. package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
  20. package/dist/dts/main/main.template.d.ts.map +1 -1
  21. package/dist/dts/state/persistence/index.d.ts +1 -0
  22. package/dist/dts/state/persistence/index.d.ts.map +1 -1
  23. package/dist/dts/state/persistence/session-persister.d.ts +12 -0
  24. package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
  25. package/dist/dts/state/persistence/session-snapshot.d.ts +14 -0
  26. package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
  27. package/dist/dts/suggestions/chat-suggestions.d.ts +7 -0
  28. package/dist/dts/suggestions/chat-suggestions.d.ts.map +1 -1
  29. package/dist/dts/utils/condense-history.d.ts +114 -0
  30. package/dist/dts/utils/condense-history.d.ts.map +1 -1
  31. package/dist/esm/components/chat-bubble/chat-bubble.js +8 -0
  32. package/dist/esm/components/chat-bubble/chat-bubble.template.js +5 -3
  33. package/dist/esm/components/chat-driver/chat-driver.js +140 -17
  34. package/dist/esm/components/chat-markdown/chat-markdown.js +132 -1
  35. package/dist/esm/components/halo-overlay.js +96 -8
  36. package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +17 -0
  37. package/dist/esm/main/main.template.js +95 -45
  38. package/dist/esm/state/persistence/session-persister.js +63 -15
  39. package/dist/esm/state/persistence/session-snapshot.js +2 -17
  40. package/dist/esm/suggestions/chat-suggestions.js +11 -3
  41. package/dist/esm/utils/condense-history.js +123 -0
  42. package/docs/styling.md +120 -0
  43. 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/docs/styling.md CHANGED
@@ -60,6 +60,18 @@ Parts on the conversation area (the outer frame exposes many more — e.g.
60
60
  | `message-<type>` | A bubble of one kind: `message-user`, `message-ai`, `message-ai-thinking`, `message-ai-function`, `message-interaction` |
61
61
  | `message-interaction-<presentation>` | An interaction bubble in one presentation: `message-interaction-label`, `message-interaction-bare`, `message-interaction-bubble` |
62
62
  | `thinking` | The loading-indicator row |
63
+ | `avatar` | The avatar box beside a message (and beside the loading indicator) |
64
+ | `avatar-<type>` | That box for one kind of row: `avatar-user`, `avatar-ai`, `avatar-ai-thinking`, `avatar-ai-function` |
65
+ | `avatar-img` / `avatar-img-<type>` | The avatar image, when `image-src` / `user-image-src` is set |
66
+ | `avatar-icon` / `avatar-icon-<type>` | The inline SVG mark, when no image is set |
67
+ | `sender` | The name + timestamp row at the top of a bubble |
68
+ | `sender-label` | Just the name |
69
+ | `content` | The bubble's body (markdown, tool calls, interaction widgets) |
70
+
71
+ `avatar-img` and `avatar-icon` carry the row type as a separate name because
72
+ `::part()` names cannot be chained — `::part(avatar-ai) ::part(avatar-img)` does
73
+ not exist, so styling the assistant's mark without touching the user's means
74
+ targeting `avatar-icon-ai` directly.
63
75
 
64
76
  Target them from an app stylesheet with `::part()`:
65
77
 
@@ -188,6 +200,114 @@ foundation-ai-assistant::part(messages-content) { max-width: none; }
188
200
  foundation-ai-assistant::part(messages-content) { display: contents; }
189
201
  ```
190
202
 
203
+ ### The header buttons
204
+
205
+ The header's popout and settings buttons are design-system buttons, so their
206
+ padded inner `control` sits two shadow boundaries from the app. `::part()` crosses
207
+ exactly one, so the assistant re-publishes them under its own namespace:
208
+
209
+ | Part | Element |
210
+ | --- | --- |
211
+ | `popout-button` / `settings-button` | The button hosts |
212
+ | `popout-button-control` / `settings-button-control` | The button's inner control — where padding and sizing actually live |
213
+ | `popout-button-content` / `settings-button-content` | The content slot wrapper inside the control |
214
+
215
+ Size the control, not the host: shrinking the host and clipping the overflow
216
+ flattens the glyph, which is the workaround these parts exist to remove.
217
+
218
+ ```css
219
+ foundation-ai-assistant::part(settings-button-control) {
220
+ padding: 2px;
221
+ min-width: 24px;
222
+ }
223
+ ```
224
+
225
+ The `-control` / `-content` names come from the registered design-system button.
226
+ A button exposing different parts forwards nothing and these rules simply do not
227
+ match.
228
+
229
+ ### Rendered markdown
230
+
231
+ Assistant replies are markdown rendered at runtime, so there is no template to
232
+ author parts on — the generated DOM is annotated after sanitising instead. Every
233
+ element kind gets a part, forwarded through the assistant's own shadow root:
234
+
235
+ | Part | Element |
236
+ | --- | --- |
237
+ | `md-p` | `<p>` |
238
+ | `md-ul` / `md-ol` / `md-li` | Lists and list items |
239
+ | `md-ul-level-<n>` / `md-ol-level-<n>` / `md-li-level-<n>` | The same, at nesting level `n` (1-based) |
240
+ | `md-pre` | Code block wrapper |
241
+ | `md-code` | Any `<code>` |
242
+ | `md-code-block` / `md-code-inline` | A `<code>` inside a `<pre>`, or standing alone |
243
+ | `md-link` | `<a>` |
244
+ | `md-quote` | `<blockquote>` |
245
+ | `md-table` / `md-thead` / `md-tbody` / `md-tr` / `md-th` / `md-td` | Table structure |
246
+ | `md-hr` | `<hr>` |
247
+ | `md-img` | `<img>` |
248
+ | `md-strong` / `md-em` | Bold and italic |
249
+ | `md-h1` … `md-h6` | Headings |
250
+
251
+ ```css
252
+ /* Inline code only — code blocks keep their own treatment */
253
+ foundation-ai-assistant::part(md-code-inline) {
254
+ background: var(--neutral-fill-secondary-rest);
255
+ }
256
+
257
+ /* Tighten nested lists */
258
+ foundation-ai-assistant::part(md-ul-level-2) {
259
+ margin-block: 0;
260
+ }
261
+ ```
262
+
263
+ Two caveats. **List levels stop at 3**: `exportparts` has no wildcard, so the
264
+ forwarded vocabulary has to be finite — a list nested four deep is tagged
265
+ `md-ul-level-3`, i.e. the deepest level means "this deep or deeper". And the part
266
+ vocabulary is exactly the table above whatever the model writes: `part` and
267
+ `exportparts` are stripped from the markdown during sanitising, so inline HTML in
268
+ a reply cannot mint a name of its own.
269
+
270
+ ### Suggestions
271
+
272
+ | Part | Element |
273
+ | --- | --- |
274
+ | `suggestions-container` | The row of suggestion pills |
275
+ | `suggestion-placeholder` | A skeleton pill, while suggestions load |
276
+ | `suggestion-pill` | One suggestion button |
277
+
278
+ ### The floating bubble
279
+
280
+ When the assistant runs as a floating bubble (`ai-chat-bubble`):
281
+
282
+ | Part | Element |
283
+ | --- | --- |
284
+ | `bubble` | The collapsed floating bubble |
285
+ | `pulse-ring` | The ring animating around it |
286
+ | `tooltip` | Its hover tooltip |
287
+ | `dialog` | The expanded dialog |
288
+ | `dialog-content` | The dialog's content area |
289
+
290
+ These three are positioned and sized by the component, and an outer `::part()`
291
+ rule beats both the component's own styles *and* its inline `style` attribute —
292
+ the tree-context comparison comes before the style-attribute one in the cascade.
293
+ So the component owns, and you should not set:
294
+
295
+ | Part | Properties the component owns |
296
+ | --- | --- |
297
+ | `bubble` | `translate` (its drag position) |
298
+ | `dialog` | `translate`, `width`, `height` (drag position and resize state) |
299
+ | `tooltip` | Its placement (set inline as the bubble moves) |
300
+
301
+ Overriding `width` / `height` on `dialog` does not resize the dialog so much as
302
+ desynchronise it: the resize handle keeps writing sizes that no longer apply.
303
+ Everything else — colours, borders, radius, shadow, typography — is yours.
304
+
305
+ One more on `dialog`: the exit animation is a real dependency, not decoration.
306
+ Removing it (`animation: none`) is handled — the dialog closes immediately
307
+ instead of waiting for an `animationend` that would never fire — but replacing it
308
+ with a non-terminating animation will leave the dialog open, since the close
309
+ waits for that animation to end.
310
+
191
311
  ---
192
312
 
193
313
  ## Responsive sizing
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-FUI-0.9",
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-FUI-0.9",
86
+ "@genesislcap/foundation-testing": "15.35.4-FUI-0.9",
87
+ "@genesislcap/genx": "15.35.4-FUI-0.9",
88
+ "@genesislcap/rollup-builder": "15.35.4-FUI-0.9",
89
+ "@genesislcap/ts-builder": "15.35.4-FUI-0.9",
90
+ "@genesislcap/uvu-playwright-builder": "15.35.4-FUI-0.9",
91
+ "@genesislcap/vite-builder": "15.35.4-FUI-0.9",
92
+ "@genesislcap/webpack-builder": "15.35.4-FUI-0.9",
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-FUI-0.9",
99
+ "@genesislcap/foundation-logger": "15.35.4-FUI-0.9",
100
+ "@genesislcap/foundation-notifications": "15.35.4-FUI-0.9",
101
+ "@genesislcap/foundation-redux": "15.35.4-FUI-0.9",
102
+ "@genesislcap/foundation-ui": "15.35.4-FUI-0.9",
103
+ "@genesislcap/foundation-utils": "15.35.4-FUI-0.9",
104
+ "@genesislcap/rapid-design-system": "15.35.4-FUI-0.9",
105
+ "@genesislcap/web-core": "15.35.4-FUI-0.9",
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-FUI-0.9"
111
111
  },
112
112
  "peerDependenciesMeta": {
113
113
  "@genesislcap/foundation-comms": {