@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.
- package/dist/ai-assistant.api.json +483 -0
- package/dist/ai-assistant.d.ts +213 -0
- package/dist/chat-driver.cjs +221 -4
- package/dist/chat-driver.cjs.map +2 -2
- package/dist/chat-driver.mjs +221 -4
- package/dist/chat-driver.mjs.map +2 -2
- package/dist/custom-elements.json +568 -206
- package/dist/dts/components/ai-driver/ai-driver.d.ts +31 -0
- package/dist/dts/components/ai-driver/ai-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-bubble/chat-bubble.d.ts.map +1 -1
- package/dist/dts/components/chat-bubble/chat-bubble.template.d.ts.map +1 -1
- package/dist/dts/components/chat-driver/chat-driver.d.ts +93 -0
- package/dist/dts/components/chat-driver/chat-driver.d.ts.map +1 -1
- package/dist/dts/components/chat-markdown/chat-markdown.d.ts +29 -0
- package/dist/dts/components/chat-markdown/chat-markdown.d.ts.map +1 -1
- package/dist/dts/components/halo-overlay.d.ts +30 -0
- package/dist/dts/components/halo-overlay.d.ts.map +1 -1
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts +17 -0
- package/dist/dts/components/orchestrating-driver/orchestrating-driver.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts.map +1 -1
- package/dist/dts/state/persistence/index.d.ts +1 -0
- package/dist/dts/state/persistence/index.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-persister.d.ts +12 -0
- package/dist/dts/state/persistence/session-persister.d.ts.map +1 -1
- package/dist/dts/state/persistence/session-snapshot.d.ts +14 -0
- package/dist/dts/state/persistence/session-snapshot.d.ts.map +1 -1
- package/dist/dts/suggestions/chat-suggestions.d.ts +7 -0
- package/dist/dts/suggestions/chat-suggestions.d.ts.map +1 -1
- package/dist/dts/utils/condense-history.d.ts +114 -0
- package/dist/dts/utils/condense-history.d.ts.map +1 -1
- package/dist/esm/components/chat-bubble/chat-bubble.js +8 -0
- package/dist/esm/components/chat-bubble/chat-bubble.template.js +5 -3
- package/dist/esm/components/chat-driver/chat-driver.js +140 -17
- package/dist/esm/components/chat-markdown/chat-markdown.js +132 -1
- package/dist/esm/components/halo-overlay.js +96 -8
- package/dist/esm/components/orchestrating-driver/orchestrating-driver.js +17 -0
- package/dist/esm/main/main.template.js +95 -45
- package/dist/esm/state/persistence/session-persister.js +63 -15
- package/dist/esm/state/persistence/session-snapshot.js +2 -17
- package/dist/esm/suggestions/chat-suggestions.js +11 -3
- package/dist/esm/utils/condense-history.js +123 -0
- package/docs/styling.md +120 -0
- package/package.json +18 -18
|
@@ -17,6 +17,14 @@ const BASELINE_FPS = 60;
|
|
|
17
17
|
* dropped frames.
|
|
18
18
|
*/
|
|
19
19
|
const FRAME_MS = MS_PER_SECOND / BASELINE_FPS;
|
|
20
|
+
/**
|
|
21
|
+
* How long the host takes to fade in/out, in ms.
|
|
22
|
+
*
|
|
23
|
+
* Interpolated into the stylesheet as well as used to time the deferred stop, so the animation
|
|
24
|
+
* cannot outlive the fade or be cut short by it.
|
|
25
|
+
*/
|
|
26
|
+
const HALO_FADE_MS = 400;
|
|
27
|
+
const HALO_FADE_DURATION = `${HALO_FADE_MS}ms`;
|
|
20
28
|
/**
|
|
21
29
|
* Animated halo overlay — rotating conic-gradient border with an inward glow.
|
|
22
30
|
*
|
|
@@ -45,6 +53,8 @@ let AiHaloOverlay = AiHaloOverlay_1 = class AiHaloOverlay extends GenesisElement
|
|
|
45
53
|
/** Transparent stop of the radial glow mask as a percentage (0–100). Higher = less spread. Default: 70. */
|
|
46
54
|
this.glowSpread = HALO_DEFAULT_GLOW_SPREAD;
|
|
47
55
|
this.angle = 0;
|
|
56
|
+
/** Whether the loop should keep rescheduling itself — see {@link AiHaloOverlay.tick}. */
|
|
57
|
+
this.running = false;
|
|
48
58
|
}
|
|
49
59
|
borderSizeChanged() {
|
|
50
60
|
this.style.setProperty('--halo-border-size', `${this.borderSize}px`);
|
|
@@ -55,20 +65,93 @@ let AiHaloOverlay = AiHaloOverlay_1 = class AiHaloOverlay extends GenesisElement
|
|
|
55
65
|
glowSpreadChanged() {
|
|
56
66
|
this.style.setProperty('--halo-glow-spread', `${this.glowSpread}%`);
|
|
57
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Start/stop with `active`, so an idle overlay costs nothing.
|
|
70
|
+
*
|
|
71
|
+
* Guarded on `isConnected` because FAST invokes attribute-changed callbacks during
|
|
72
|
+
* initialisation, before the element is in the document — `connectedCallback` is what decides
|
|
73
|
+
* for an element that mounts already-active.
|
|
74
|
+
*/
|
|
75
|
+
activeChanged() {
|
|
76
|
+
if (!this.isConnected)
|
|
77
|
+
return;
|
|
78
|
+
if (this.active) {
|
|
79
|
+
this.cancelPendingStop();
|
|
80
|
+
this.startAnimation();
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
this.scheduleStop();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
58
86
|
connectedCallback() {
|
|
59
87
|
super.connectedCallback();
|
|
60
|
-
this.
|
|
88
|
+
if (this.active)
|
|
89
|
+
this.startAnimation();
|
|
61
90
|
}
|
|
62
91
|
disconnectedCallback() {
|
|
63
92
|
super.disconnectedCallback();
|
|
93
|
+
this.cancelPendingStop();
|
|
94
|
+
this.stopAnimation();
|
|
95
|
+
}
|
|
96
|
+
startAnimation() {
|
|
97
|
+
// Re-entrant: `activeChanged` can fire for a value that is already applied, and a second
|
|
98
|
+
// scheduled frame would double the rotation speed and leak the first handle.
|
|
99
|
+
if (this.running)
|
|
100
|
+
return;
|
|
101
|
+
this.running = true;
|
|
102
|
+
this.tick();
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Keep spinning until the host has finished fading out.
|
|
106
|
+
*
|
|
107
|
+
* Deactivating only drops the host's opacity — the overlay is still on screen for the length of
|
|
108
|
+
* the transition, so stopping the instant `active` flips would freeze the rotation mid-fade.
|
|
109
|
+
*
|
|
110
|
+
* Timed rather than driven by `transitionend`, which never fires if the host is hidden or an app
|
|
111
|
+
* overrides the transition away, and a stop that never arrives is exactly the idle-tick bug this
|
|
112
|
+
* gating exists to prevent.
|
|
113
|
+
*
|
|
114
|
+
* The timer re-reads `active` rather than trusting that it was cancelled. FAST reflects the
|
|
115
|
+
* property to the attribute on a queued update, so `activeChanged` can run again, out of order,
|
|
116
|
+
* after a rapid toggle — and a stale stop landing on a re-activated overlay would leave it
|
|
117
|
+
* frozen for good, which is worse than the idle ticking this gate removes.
|
|
118
|
+
*/
|
|
119
|
+
scheduleStop() {
|
|
120
|
+
if (this.stopTimer !== undefined || !this.running)
|
|
121
|
+
return;
|
|
122
|
+
this.stopTimer = window.setTimeout(() => {
|
|
123
|
+
this.stopTimer = undefined;
|
|
124
|
+
if (this.active)
|
|
125
|
+
return;
|
|
126
|
+
this.stopAnimation();
|
|
127
|
+
}, HALO_FADE_MS);
|
|
128
|
+
}
|
|
129
|
+
cancelPendingStop() {
|
|
130
|
+
if (this.stopTimer === undefined)
|
|
131
|
+
return;
|
|
132
|
+
clearTimeout(this.stopTimer);
|
|
133
|
+
this.stopTimer = undefined;
|
|
134
|
+
}
|
|
135
|
+
stopAnimation() {
|
|
136
|
+
this.running = false;
|
|
64
137
|
if (this.animFrame !== undefined) {
|
|
65
138
|
cancelAnimationFrame(this.animFrame);
|
|
66
139
|
this.animFrame = undefined;
|
|
67
140
|
}
|
|
68
|
-
// Reset the clock so a later
|
|
141
|
+
// Reset the clock so a later restart doesn't apply one huge time delta. `angle` is
|
|
142
|
+
// deliberately NOT reset: the halo fades out on opacity, so resuming from where it stopped
|
|
143
|
+
// avoids a visible jump when it comes back.
|
|
69
144
|
this.lastTime = undefined;
|
|
70
145
|
}
|
|
71
146
|
tick(now) {
|
|
147
|
+
// Defensive: a frame already dequeued for this tick cannot be cancelled, so without this a
|
|
148
|
+
// stop landing earlier in the same frame would be undone by the reschedule below and the loop
|
|
149
|
+
// would revive with no owner. Keyed on `running` rather than on `active`, which goes false
|
|
150
|
+
// while the fade — and so the rotation — is still meant to be running.
|
|
151
|
+
if (!this.isConnected || !this.running) {
|
|
152
|
+
this.animFrame = undefined;
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
72
155
|
// Advance by elapsed wall-clock time (expressed in 60fps-equivalent frames)
|
|
73
156
|
// rather than a fixed step per callback, so the rotation runs at a constant
|
|
74
157
|
// real-world speed regardless of the display's refresh rate or dropped
|
|
@@ -86,11 +169,16 @@ let AiHaloOverlay = AiHaloOverlay_1 = class AiHaloOverlay extends GenesisElement
|
|
|
86
169
|
this.animFrame = requestAnimationFrame((t) => this.tick(t));
|
|
87
170
|
}
|
|
88
171
|
};
|
|
89
|
-
// TODO: The rAF loop is fine for demos but
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
//
|
|
93
|
-
//
|
|
172
|
+
// TODO: The rAF loop is fine for demos but runs on the main thread, so heavy JS work can cause
|
|
173
|
+
// the animation to stutter. Once @property inside Shadow DOM has solid cross-browser support,
|
|
174
|
+
// consider switching back to a CSS @keyframes approach and removing
|
|
175
|
+
// connectedCallback/disconnectedCallback/tick().
|
|
176
|
+
//
|
|
177
|
+
// The loop is gated on `active` (see startAnimation/stopAnimation): every tick writes
|
|
178
|
+
// `--halo-angle` as an inline style, and hosts mount these permanently while only toggling
|
|
179
|
+
// `active`, so an idle overlay must not tick. Beyond the wasted work, a style attribute
|
|
180
|
+
// rewritten ~60x a second repaints the devtools Elements panel on every mutation, which makes
|
|
181
|
+
// inspecting anywhere in the tree impractical.
|
|
94
182
|
AiHaloOverlay.FULL_ROTATION_DEG = 360;
|
|
95
183
|
__decorate([
|
|
96
184
|
attr({ mode: 'boolean' })
|
|
@@ -125,7 +213,7 @@ AiHaloOverlay = AiHaloOverlay_1 = __decorate([
|
|
|
125
213
|
pointer-events: none;
|
|
126
214
|
z-index: 1000;
|
|
127
215
|
opacity: 0;
|
|
128
|
-
transition: opacity
|
|
216
|
+
transition: opacity ${HALO_FADE_DURATION} ease;
|
|
129
217
|
}
|
|
130
218
|
|
|
131
219
|
:host([active]) {
|
|
@@ -312,6 +312,23 @@ export class OrchestratingDriver extends EventTarget {
|
|
|
312
312
|
getHistoryForPersistence() {
|
|
313
313
|
return this.chatDriver.getHistoryForPersistence();
|
|
314
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* Delegates to the inner {@link ChatDriver}, which owns the condensation registry and clocks
|
|
317
|
+
* (GENC-1632). The forward matters for the same reason as `getHistoryForPersistence` above: the
|
|
318
|
+
* persister reaches it through `?.`, so a missing forward would compile, pass the ChatDriver
|
|
319
|
+
* tests, and do nothing for every orchestrated host — which is every host with an agents array.
|
|
320
|
+
*/
|
|
321
|
+
getCondensePoliciesForPersistence(messages) {
|
|
322
|
+
return this.chatDriver.getCondensePoliciesForPersistence(messages);
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Delegates to the inner {@link ChatDriver} (GENC-1632). The deferred activation stamp it
|
|
326
|
+
* performs is taken by the inner driver's `installAgent`, which this driver's own
|
|
327
|
+
* `installAgent` always reaches, so nothing extra is needed here.
|
|
328
|
+
*/
|
|
329
|
+
restoreCondensePolicies(entries) {
|
|
330
|
+
return this.chatDriver.restoreCondensePolicies(entries);
|
|
331
|
+
}
|
|
315
332
|
/** {@inheritDoc AiDriver.setContextGuard} */
|
|
316
333
|
setContextGuard(policy) {
|
|
317
334
|
this.chatDriver.setContextGuard(policy);
|
|
@@ -16,7 +16,9 @@
|
|
|
16
16
|
*/
|
|
17
17
|
import { isChatToolCallUnknown } from '@genesislcap/foundation-ai';
|
|
18
18
|
import { classNames, html, ref, repeat, when } from '@genesislcap/web-core';
|
|
19
|
+
import { MARKDOWN_EXPORTPARTS } from '../components/chat-markdown/chat-markdown';
|
|
19
20
|
import { SettingsModalTemplate } from '../components/settings-modal';
|
|
21
|
+
import { SUGGESTIONS_EXPORTPARTS } from '../suggestions/chat-suggestions';
|
|
20
22
|
import { formatAbsoluteTimestamp, formatMessageTimestamp, messageTimestampDateTime, } from '../utils/format-message-timestamp';
|
|
21
23
|
import { compactionDividerLabel } from '../utils/history-transform';
|
|
22
24
|
import { LOADING_STYLE_ANIMATIONS } from './main.types';
|
|
@@ -37,35 +39,6 @@ function unknownToolPayload(tc) {
|
|
|
37
39
|
const HALO_SPEED_DEFAULT = 1.5;
|
|
38
40
|
const HALO_SPEED_ORCHESTRATING = 0.4;
|
|
39
41
|
const HALO_BORDER_SIZE_DEFAULT = 3;
|
|
40
|
-
// Avatar markup is owned by the component (`assistantIconSafe` / `userIconSafe`),
|
|
41
|
-
// which holds the sanitized SVG string for the default or any consumer override
|
|
42
|
-
// and is injected via `:innerHTML`. A raster `image-src` / `user-image-src`
|
|
43
|
-
// takes precedence over the inline icon. The exported `*IconSvg` string
|
|
44
|
-
// constants in `./main` let apps opt back into a specific built-in mark.
|
|
45
|
-
const assistantAvatarTemplate = html `
|
|
46
|
-
${(m, c) => {
|
|
47
|
-
const parent = c.parent;
|
|
48
|
-
return parent.imageSrc
|
|
49
|
-
? html `
|
|
50
|
-
<img src="${() => parent.imageSrc}" alt="Assistant" class="avatar-img" />
|
|
51
|
-
`
|
|
52
|
-
: html `
|
|
53
|
-
<span class="avatar-icon" :innerHTML="${() => parent.assistantIconSafe}"></span>
|
|
54
|
-
`;
|
|
55
|
-
}}
|
|
56
|
-
`;
|
|
57
|
-
const userAvatarTemplate = html `
|
|
58
|
-
${(m, c) => {
|
|
59
|
-
const parent = c.parent;
|
|
60
|
-
return parent.userImageSrc
|
|
61
|
-
? html `
|
|
62
|
-
<img src="${() => parent.userImageSrc}" alt="You" class="avatar-img" />
|
|
63
|
-
`
|
|
64
|
-
: html `
|
|
65
|
-
<span class="avatar-icon" :innerHTML="${() => parent.userIconSafe}"></span>
|
|
66
|
-
`;
|
|
67
|
-
}}
|
|
68
|
-
`;
|
|
69
42
|
/**
|
|
70
43
|
* @beta
|
|
71
44
|
*/
|
|
@@ -94,6 +67,62 @@ const messageType = (m) => {
|
|
|
94
67
|
return 'ai';
|
|
95
68
|
}
|
|
96
69
|
};
|
|
70
|
+
// Avatar markup is owned by the component (`assistantIconSafe` / `userIconSafe`),
|
|
71
|
+
// which holds the sanitized SVG string for the default or any consumer override
|
|
72
|
+
// and is injected via `:innerHTML`. A raster `image-src` / `user-image-src`
|
|
73
|
+
// takes precedence over the inline icon. The exported `*IconSvg` string
|
|
74
|
+
// constants in `./main` let apps opt back into a specific built-in mark.
|
|
75
|
+
/**
|
|
76
|
+
* The assistant's own avatar markup.
|
|
77
|
+
*
|
|
78
|
+
* Shared rather than duplicated because the loading-indicator row renders the same avatar from a
|
|
79
|
+
* different binding context (the assistant, not a message) — two copies drifted once already, and
|
|
80
|
+
* the parts below are the kind of thing only one copy tends to get.
|
|
81
|
+
*
|
|
82
|
+
* `type` is the message type the avatar belongs to, so `::part()` can reach the assistant's image
|
|
83
|
+
* without also matching the user's: part names cannot be chained in a selector, so the variant has
|
|
84
|
+
* to be a name of its own.
|
|
85
|
+
*/
|
|
86
|
+
const assistantAvatarMarkup = (parent, type) => parent.imageSrc
|
|
87
|
+
? html `
|
|
88
|
+
<img
|
|
89
|
+
src="${() => parent.imageSrc}"
|
|
90
|
+
alt="Assistant"
|
|
91
|
+
class="avatar-img"
|
|
92
|
+
part="${() => `avatar-img avatar-img-${type}`}"
|
|
93
|
+
/>
|
|
94
|
+
`
|
|
95
|
+
: html `
|
|
96
|
+
<span
|
|
97
|
+
class="avatar-icon"
|
|
98
|
+
part="${() => `avatar-icon avatar-icon-${type}`}"
|
|
99
|
+
:innerHTML="${() => parent.assistantIconSafe}"
|
|
100
|
+
></span>
|
|
101
|
+
`;
|
|
102
|
+
const assistantAvatarTemplate = html `
|
|
103
|
+
${(m, c) => assistantAvatarMarkup(c.parent, messageType(m))}
|
|
104
|
+
`;
|
|
105
|
+
const userAvatarTemplate = html `
|
|
106
|
+
${(m, c) => {
|
|
107
|
+
const parent = c.parent;
|
|
108
|
+
return parent.userImageSrc
|
|
109
|
+
? html `
|
|
110
|
+
<img
|
|
111
|
+
src="${() => parent.userImageSrc}"
|
|
112
|
+
alt="You"
|
|
113
|
+
class="avatar-img"
|
|
114
|
+
part="avatar-img avatar-img-user"
|
|
115
|
+
/>
|
|
116
|
+
`
|
|
117
|
+
: html `
|
|
118
|
+
<span
|
|
119
|
+
class="avatar-icon"
|
|
120
|
+
part="avatar-icon avatar-icon-user"
|
|
121
|
+
:innerHTML="${() => parent.userIconSafe}"
|
|
122
|
+
></span>
|
|
123
|
+
`;
|
|
124
|
+
}}
|
|
125
|
+
`;
|
|
97
126
|
const senderLabel = {
|
|
98
127
|
user: 'You',
|
|
99
128
|
'ai-thinking': 'Thinking',
|
|
@@ -513,7 +542,10 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
513
542
|
<div
|
|
514
543
|
class="message-row ${(m) => messageType(m)} ${(m) => m.interaction ? `present-${interactionPresentation(m)}` : ''}"
|
|
515
544
|
>
|
|
516
|
-
<div
|
|
545
|
+
<div
|
|
546
|
+
class="avatar ${(m) => messageType(m)}"
|
|
547
|
+
part="${(m) => `avatar avatar-${messageType(m)}`}"
|
|
548
|
+
>
|
|
517
549
|
${when(
|
|
518
550
|
// Keyed on messageType (not raw role) so a synthetic-user message,
|
|
519
551
|
// which renders as 'user', gets the user avatar rather than the
|
|
@@ -528,8 +560,8 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
528
560
|
// A 'bare' interaction owns its full presentation — suppress the
|
|
529
561
|
// host sender label. Every other message keeps it.
|
|
530
562
|
(m) => !(m.interaction && interactionPresentation(m) === 'bare'), html `
|
|
531
|
-
<div class="sender">
|
|
532
|
-
<span class="sender-label">
|
|
563
|
+
<div class="sender" part="sender">
|
|
564
|
+
<span class="sender-label" part="sender-label">
|
|
533
565
|
${(m, c) => {
|
|
534
566
|
var _a;
|
|
535
567
|
return messageType(m) === 'ai-function' &&
|
|
@@ -547,9 +579,16 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
547
579
|
c.parent.timestampDisplay !== 'off', messageTimestampTemplate)}
|
|
548
580
|
</div>
|
|
549
581
|
`)}
|
|
550
|
-
<div class="content">
|
|
582
|
+
<div class="content" part="content">
|
|
551
583
|
${when((m) => m.content, html `
|
|
552
|
-
|
|
584
|
+
${
|
|
585
|
+
/* Markdown renders inside THIS shadow root, so its parts need forwarding for
|
|
586
|
+
an app to reach them: ::part() crosses exactly one boundary. Built from the
|
|
587
|
+
component's own vocabulary so the two cannot drift. */ ''}
|
|
588
|
+
<ai-chat-markdown
|
|
589
|
+
exportparts="${MARKDOWN_EXPORTPARTS}"
|
|
590
|
+
:content="${(m) => m.content}"
|
|
591
|
+
></ai-chat-markdown>
|
|
553
592
|
`)}
|
|
554
593
|
${when((m) => m.toolCalls, html `
|
|
555
594
|
${repeat((m) => { var _a; return (_a = m.toolCalls) !== null && _a !== void 0 ? _a : []; }, toolCallItemTemplate)}
|
|
@@ -833,12 +872,30 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
833
872
|
${when((x) => !!x.headerTitle, html `
|
|
834
873
|
<span class="chat-title" part="chat-title">${(x) => x.headerTitle}</span>
|
|
835
874
|
`)}
|
|
875
|
+
${
|
|
876
|
+
/* The two buttons below re-publish the design-system button's inner parts (control,
|
|
877
|
+
content) into THIS component's part namespace via exportparts.
|
|
878
|
+
|
|
879
|
+
Without it they are unreachable by an embedding app: ::part() crosses exactly one
|
|
880
|
+
shadow boundary, and the control sits two away (app -> foundation-ai-assistant ->
|
|
881
|
+
buttonTag -> control). Exposing only the button host leaves an app able to size
|
|
882
|
+
the box but not the padded control inside it, which pushes hosts into sizing the
|
|
883
|
+
host and clipping the overflow to flatten these buttons - a workaround for a
|
|
884
|
+
missing hook rather than a styling choice.
|
|
885
|
+
|
|
886
|
+
The forwarded control/content names come from whichever design system's button is
|
|
887
|
+
registered as `buttonTag`; a button exposing different parts forwards nothing and
|
|
888
|
+
the rules below simply do not match.
|
|
889
|
+
|
|
890
|
+
Named with the owning button as a prefix so the namespace stays legible as more
|
|
891
|
+
parts are exported, and so control does not collide across buttons. */ ''}
|
|
836
892
|
<div class="header-actions" part="header-actions">
|
|
837
893
|
<slot name="header-actions-extra"></slot>
|
|
838
894
|
${when((x) => !!x.popoutMode, html `
|
|
839
895
|
<${buttonTag}
|
|
840
896
|
class="popout-button"
|
|
841
897
|
part="popout-button"
|
|
898
|
+
exportparts="control: popout-button-control, content: popout-button-content"
|
|
842
899
|
appearance="stealth"
|
|
843
900
|
title="${(x) => (x.popoutMode === 'expand' ? 'Expand to panel' : 'Pop back to bubble')}"
|
|
844
901
|
?disabled=${(x) => x.hasActivePendingInteraction}
|
|
@@ -848,6 +905,7 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
848
905
|
<${buttonTag}
|
|
849
906
|
class="settings-button"
|
|
850
907
|
part="settings-button"
|
|
908
|
+
exportparts="control: settings-button-control, content: settings-button-content"
|
|
851
909
|
appearance="stealth"
|
|
852
910
|
title="Settings"
|
|
853
911
|
aria-haspopup="dialog"
|
|
@@ -888,17 +946,8 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
888
946
|
LOADING_STYLE_ANIMATIONS.some((s) => x.enabledAnimations.includes(s)));
|
|
889
947
|
}, html `
|
|
890
948
|
<div class="message-row ai" part="thinking">
|
|
891
|
-
<div class="avatar">
|
|
892
|
-
${(x) => x
|
|
893
|
-
? html `
|
|
894
|
-
<img src="${() => x.imageSrc}" alt="Assistant" class="avatar-img" />
|
|
895
|
-
`
|
|
896
|
-
: html `
|
|
897
|
-
<span
|
|
898
|
-
class="avatar-icon"
|
|
899
|
-
:innerHTML="${() => x.assistantIconSafe}"
|
|
900
|
-
></span>
|
|
901
|
-
`}
|
|
949
|
+
<div class="avatar ai" part="avatar avatar-ai">
|
|
950
|
+
${(x) => assistantAvatarMarkup(x, 'ai')}
|
|
902
951
|
</div>
|
|
903
952
|
${(x) => selectThinkingTemplate(x)}
|
|
904
953
|
</div>
|
|
@@ -936,6 +985,7 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
936
985
|
`)}
|
|
937
986
|
${when((x) => { var _a; return ((_a = x.chatConfig.suggestions) === null || _a === void 0 ? void 0 : _a.behavior) !== 'never' && !x.suggestionsBlocked; }, html `
|
|
938
987
|
<chat-suggestions
|
|
988
|
+
exportparts="${SUGGESTIONS_EXPORTPARTS}"
|
|
939
989
|
:state="${(x) => x.suggestionsState}"
|
|
940
990
|
@suggestion-clicked="${(x, c) => x.handleSuggestionClick(c.event.detail)}"
|
|
941
991
|
></chat-suggestions>
|
|
@@ -263,6 +263,30 @@ export class SessionPersister {
|
|
|
263
263
|
const raw = (_d = (_b = (_a = driver === null || driver === void 0 ? void 0 : driver.getHistoryForPersistence) === null || _a === void 0 ? void 0 : _a.call(driver)) !== null && _b !== void 0 ? _b : (_c = driver === null || driver === void 0 ? void 0 : driver.getRawHistory) === null || _c === void 0 ? void 0 : _c.call(driver)) !== null && _d !== void 0 ? _d : storeMessages;
|
|
264
264
|
return raw.filter((m) => !isSessionNoticeMarker(m));
|
|
265
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* The `condenseWhen` policies still waiting to fire for the calls in `messages` (GENC-1632) —
|
|
268
|
+
* the half of condensation `getHistoryForPersistence` cannot carry, because a payload whose
|
|
269
|
+
* trigger has not fired is stored full and needs its policy to collapse after a reload.
|
|
270
|
+
*
|
|
271
|
+
* `flowDropped` is the frozen (non-resumable) save: its snapshot drops the running flow, so the
|
|
272
|
+
* activation that owned the pending payloads does not resume and they are written as ended.
|
|
273
|
+
*
|
|
274
|
+
* Never throws: a failure here costs a resumed session some context, which is not worth losing
|
|
275
|
+
* the save over.
|
|
276
|
+
*/
|
|
277
|
+
condensePoliciesToPersist(driver, messages, opts = {}) {
|
|
278
|
+
var _a;
|
|
279
|
+
try {
|
|
280
|
+
const pending = (_a = driver === null || driver === void 0 ? void 0 : driver.getCondensePoliciesForPersistence) === null || _a === void 0 ? void 0 : _a.call(driver, messages);
|
|
281
|
+
if (!(pending === null || pending === void 0 ? void 0 : pending.length) || !opts.flowDropped)
|
|
282
|
+
return pending;
|
|
283
|
+
return pending.map((e) => e.elapsed.activations > 0 ? e : Object.assign(Object.assign({}, e), { elapsed: Object.assign(Object.assign({}, e.elapsed), { activations: 1 }) }));
|
|
284
|
+
}
|
|
285
|
+
catch (e) {
|
|
286
|
+
logger.error('Session save: capturing condense policies failed:', e);
|
|
287
|
+
return undefined;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
266
290
|
/**
|
|
267
291
|
* Capture the current session to durable storage (GENC-1351 §5.1). Reads the
|
|
268
292
|
* full transcript from the driver and the restorable scalars from the store, and
|
|
@@ -340,10 +364,11 @@ export class SessionPersister {
|
|
|
340
364
|
// completed exchanges that were already safely stored. Taking the max of the two
|
|
341
365
|
// makes the boundary monotonic: it advances with each new prompt and never rewinds.
|
|
342
366
|
const boundary = Math.max(keepThroughLastUserMessage(messages).length, this._persistedMessages);
|
|
367
|
+
const frozenMessages = messages.slice(0, Math.min(boundary, messages.length));
|
|
343
368
|
const frozen = createPersistedSession({
|
|
344
369
|
sessionKey: key,
|
|
345
370
|
host: window.location.host,
|
|
346
|
-
messages:
|
|
371
|
+
messages: frozenMessages,
|
|
347
372
|
activeAgentName: (_a = s.activeAgent) === null || _a === void 0 ? void 0 : _a.name,
|
|
348
373
|
pinnedAgentName: s.pinnedAgentName,
|
|
349
374
|
flowOwnerAgentName: null,
|
|
@@ -353,6 +378,14 @@ export class SessionPersister {
|
|
|
353
378
|
activeModel: s.activeModel,
|
|
354
379
|
activeProviderName: s.activeProviderName,
|
|
355
380
|
agentSnapshots: {},
|
|
381
|
+
// Pending condense policies are carried here too (GENC-1632), but with the live
|
|
382
|
+
// activation marked as ENDED: this snapshot drops the flow's state, so on return the
|
|
383
|
+
// agent starts afresh rather than resuming, and the activation those payloads belonged to
|
|
384
|
+
// is over. Without the mark, a re-run of the same agent would be taken for a resumption
|
|
385
|
+
// and adopt the dead flow's `agentEnd` / `phaseEnd` payloads for its whole new run.
|
|
386
|
+
condensePolicies: this.condensePoliciesToPersist(driver, frozenMessages, {
|
|
387
|
+
flowDropped: true,
|
|
388
|
+
}),
|
|
356
389
|
});
|
|
357
390
|
// Skip the write when the frozen boundary has not moved — a flow autosaves on every
|
|
358
391
|
// transcript change, and while it runs the last user message (and therefore the
|
|
@@ -420,6 +453,7 @@ export class SessionPersister {
|
|
|
420
453
|
activeModel: s.activeModel,
|
|
421
454
|
activeProviderName: s.activeProviderName,
|
|
422
455
|
agentSnapshots,
|
|
456
|
+
condensePolicies: this.condensePoliciesToPersist(driver, messages),
|
|
423
457
|
});
|
|
424
458
|
// Observability (GENC-1351): record what each autosave captured for stateful
|
|
425
459
|
// agents — `agents: []` here means no machine snapshot was taken (the bug to
|
|
@@ -487,7 +521,7 @@ export class SessionPersister {
|
|
|
487
521
|
*/
|
|
488
522
|
restore() {
|
|
489
523
|
return __awaiter(this, void 0, void 0, function* () {
|
|
490
|
-
var _a, _b, _c, _d;
|
|
524
|
+
var _a, _b, _c, _d, _e;
|
|
491
525
|
const { provider } = this.deps.getPersistence();
|
|
492
526
|
if (!provider)
|
|
493
527
|
return;
|
|
@@ -543,16 +577,6 @@ export class SessionPersister {
|
|
|
543
577
|
// Seed the monotonic freeze floor too (GENC-1511): a flow that goes non-resumable
|
|
544
578
|
// straight after a restore must not freeze BELOW what the restore just brought back.
|
|
545
579
|
this._persistedMessages = trimmed.length;
|
|
546
|
-
// Observability (GENC-1351): record exactly what the restore primed, so a
|
|
547
|
-
// post-reload debug-log export shows whether a stateful agent's snapshot
|
|
548
|
-
// actually came back (meta events reset on reload, so this is the only window
|
|
549
|
-
// onto the saved→loaded handoff).
|
|
550
|
-
this.logMeta('persistence.restored', {
|
|
551
|
-
agents: Object.keys((_a = snapshot.agentSnapshots) !== null && _a !== void 0 ? _a : {}),
|
|
552
|
-
agentSnapshots: snapshot.agentSnapshots,
|
|
553
|
-
pinnedAgentName: snapshot.pinnedAgentName,
|
|
554
|
-
flowOwnerAgentName: snapshot.flowOwnerAgentName,
|
|
555
|
-
});
|
|
556
580
|
// Loudly surface saved agent state that can't be rehydrated because the agent
|
|
557
581
|
// isn't in the current set — otherwise the flow silently fails to resume, a
|
|
558
582
|
// real footgun for hosts with dynamic agent arrays. Non-fatal: the transcript
|
|
@@ -616,7 +640,31 @@ export class SessionPersister {
|
|
|
616
640
|
}
|
|
617
641
|
const messages = [...trimmed, ...trailers];
|
|
618
642
|
ref.actions.aiAssistant.loadSession(toLoadSessionPayload(Object.assign(Object.assign({}, snapshot), { messages })));
|
|
619
|
-
(
|
|
643
|
+
(_a = driver === null || driver === void 0 ? void 0 : driver.loadHistory) === null || _a === void 0 ? void 0 : _a.call(driver, [...messages]);
|
|
644
|
+
// Re-arm the condense policies that had not fired at save time (GENC-1632) — AFTER
|
|
645
|
+
// `loadHistory`, because the driver keeps only entries whose tool call is in the history it
|
|
646
|
+
// now holds, which is how an entry for a call `trimToRestorableBoundary` cut away is dropped
|
|
647
|
+
// rather than resurrected. A snapshot from before the field existed has none, so this is a
|
|
648
|
+
// no-op and the restore is exactly what it was. Timing against the agent's re-activation is
|
|
649
|
+
// the driver's problem, not ours: it defers the activation stamp to the next `installAgent`.
|
|
650
|
+
const condenseRestore = (_b = driver === null || driver === void 0 ? void 0 : driver.restoreCondensePolicies) === null || _b === void 0 ? void 0 : _b.call(driver, snapshot.condensePolicies);
|
|
651
|
+
// Observability (GENC-1351, counts refined for GENC-1632 review): record exactly what the
|
|
652
|
+
// restore primed, so a post-reload debug-log export shows whether a stateful agent's snapshot
|
|
653
|
+
// actually came back (meta events reset on reload, so this is the only window onto the
|
|
654
|
+
// saved→loaded handoff). Logged HERE, after `restoreCondensePolicies` has run, rather than
|
|
655
|
+
// where the snapshot was first read: `stored` alone (the old field) counts what the snapshot
|
|
656
|
+
// OFFERED, not what came back — `restoreCondensePolicies` silently drops a malformed entry, one
|
|
657
|
+
// whose call the restorable-boundary trim removed, and a first-wins duplicate, so a bare
|
|
658
|
+
// `stored: 14` can't tell "all 14 re-armed" from "0 re-armed". `restored`/`awaitingReactivation`
|
|
659
|
+
// are left OFF the object (not zeroed) when there is no driver or it predates this method, so
|
|
660
|
+
// that case can't be misread as "re-armed none" either.
|
|
661
|
+
this.logMeta('persistence.restored', {
|
|
662
|
+
agents: Object.keys((_c = snapshot.agentSnapshots) !== null && _c !== void 0 ? _c : {}),
|
|
663
|
+
condensePolicies: Object.assign({ stored: Array.isArray(snapshot.condensePolicies) ? snapshot.condensePolicies.length : 0 }, condenseRestore),
|
|
664
|
+
agentSnapshots: snapshot.agentSnapshots,
|
|
665
|
+
pinnedAgentName: snapshot.pinnedAgentName,
|
|
666
|
+
flowOwnerAgentName: snapshot.flowOwnerAgentName,
|
|
667
|
+
});
|
|
620
668
|
// Interrupted flow (§5.9): pre-fill the composer with the prompt that started
|
|
621
669
|
// the flow so "send it again" is one keystroke, and record it for observability.
|
|
622
670
|
if (snapshot.interrupted) {
|
|
@@ -639,8 +687,8 @@ export class SessionPersister {
|
|
|
639
687
|
// driver's routing agrees with the restored (picker-locked) store state.
|
|
640
688
|
const orchestrator = asOrchestrator(driver);
|
|
641
689
|
if (orchestrator) {
|
|
642
|
-
orchestrator.setPinnedAgent((
|
|
643
|
-
orchestrator.setFlowOwner((
|
|
690
|
+
orchestrator.setPinnedAgent((_d = snapshot.pinnedAgentName) !== null && _d !== void 0 ? _d : null);
|
|
691
|
+
orchestrator.setFlowOwner((_e = snapshot.flowOwnerAgentName) !== null && _e !== void 0 ? _e : null);
|
|
644
692
|
}
|
|
645
693
|
logger.debug('Session restored', { key, messages: messages.length });
|
|
646
694
|
}
|
|
@@ -13,23 +13,8 @@ export const PERSISTED_SESSION_VERSION = 1;
|
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
15
15
|
export function createPersistedSession(input) {
|
|
16
|
-
var _a;
|
|
17
|
-
return {
|
|
18
|
-
version: PERSISTED_SESSION_VERSION,
|
|
19
|
-
savedAt: new Date().toISOString(),
|
|
20
|
-
host: input.host,
|
|
21
|
-
sessionKey: input.sessionKey,
|
|
22
|
-
messages: input.messages,
|
|
23
|
-
activeAgentName: input.activeAgentName,
|
|
24
|
-
pinnedAgentName: input.pinnedAgentName,
|
|
25
|
-
flowOwnerAgentName: input.flowOwnerAgentName,
|
|
26
|
-
sessionCostUsd: input.sessionCostUsd,
|
|
27
|
-
contextTokens: input.contextTokens,
|
|
28
|
-
contextLimit: input.contextLimit,
|
|
29
|
-
activeModel: input.activeModel,
|
|
30
|
-
activeProviderName: input.activeProviderName,
|
|
31
|
-
agentSnapshots: (_a = input.agentSnapshots) !== null && _a !== void 0 ? _a : {},
|
|
32
|
-
};
|
|
16
|
+
var _a, _b;
|
|
17
|
+
return Object.assign({ version: PERSISTED_SESSION_VERSION, savedAt: new Date().toISOString(), host: input.host, sessionKey: input.sessionKey, messages: input.messages, activeAgentName: input.activeAgentName, pinnedAgentName: input.pinnedAgentName, flowOwnerAgentName: input.flowOwnerAgentName, sessionCostUsd: input.sessionCostUsd, contextTokens: input.contextTokens, contextLimit: input.contextLimit, activeModel: input.activeModel, activeProviderName: input.activeProviderName, agentSnapshots: (_a = input.agentSnapshots) !== null && _a !== void 0 ? _a : {} }, (((_b = input.condensePolicies) === null || _b === void 0 ? void 0 : _b.length) ? { condensePolicies: input.condensePolicies } : {}));
|
|
33
18
|
}
|
|
34
19
|
/**
|
|
35
20
|
* Resolve the notice text + pre-fill prompt for an interrupted (non-resumable) flow
|
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import { __decorate } from "tslib";
|
|
2
2
|
import { attr, customElement, GenesisElement, observable, html, css, repeat, when, } from '@genesislcap/web-core';
|
|
3
3
|
const PILL_ANIMATION_STAGGER_MS = 70;
|
|
4
|
+
/**
|
|
5
|
+
* Every part this component exposes, as an `exportparts` value.
|
|
6
|
+
*
|
|
7
|
+
* `::part()` crosses exactly one shadow boundary, so a host rendering `<chat-suggestions>` in its
|
|
8
|
+
* own shadow root has to forward these for an embedding app to reach them at all.
|
|
9
|
+
*/
|
|
10
|
+
export const SUGGESTIONS_EXPORTPARTS = 'suggestions-container, suggestion-placeholder, suggestion-pill';
|
|
4
11
|
const template = html `
|
|
5
12
|
${when((x) => x.state.status === 'loading', html `
|
|
6
|
-
<div class="suggestions-container">
|
|
13
|
+
<div class="suggestions-container" part="suggestions-container">
|
|
7
14
|
${repeat(() => Array.from({ length: 3 }), html `
|
|
8
|
-
<div class="suggestion-placeholder"></div>
|
|
15
|
+
<div class="suggestion-placeholder" part="suggestion-placeholder"></div>
|
|
9
16
|
`)}
|
|
10
17
|
</div>
|
|
11
18
|
`)}
|
|
12
19
|
${when((x) => x.state.status === 'loaded', html `
|
|
13
|
-
<div class="suggestions-container">
|
|
20
|
+
<div class="suggestions-container" part="suggestions-container">
|
|
14
21
|
${repeat((x) => x.state.suggestions, html `
|
|
15
22
|
<button
|
|
16
23
|
class="suggestion-pill"
|
|
24
|
+
part="suggestion-pill"
|
|
17
25
|
style="animation-delay: ${(_, c) => c.index * PILL_ANIMATION_STAGGER_MS}ms"
|
|
18
26
|
@click="${(suggestion, c) => c.parent.handleSuggestionClick(suggestion)}"
|
|
19
27
|
>
|