@genesislcap/ai-assistant 15.35.4 → 15.36.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 +23 -0
- package/dist/ai-assistant.d.ts +46 -0
- package/dist/custom-elements.json +104 -0
- package/dist/dts/components/chat-bubble/chat-bubble.d.ts +18 -0
- 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-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/index.d.ts +1 -1
- package/dist/dts/index.d.ts.map +1 -1
- package/dist/dts/main/main.template.d.ts +15 -0
- package/dist/dts/main/main.template.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/esm/components/chat-bubble/chat-bubble.js +27 -0
- package/dist/esm/components/chat-bubble/chat-bubble.template.js +5 -3
- package/dist/esm/components/chat-markdown/chat-markdown.js +132 -1
- package/dist/esm/components/halo-overlay.js +96 -8
- package/dist/esm/index.js +3 -1
- package/dist/esm/main/main.template.js +110 -45
- package/dist/esm/suggestions/chat-suggestions.js +11 -3
- package/docs/styling.md +153 -0
- package/package.json +18 -18
|
@@ -68,6 +68,92 @@ const styles = css `
|
|
|
68
68
|
font-weight: 600;
|
|
69
69
|
}
|
|
70
70
|
`;
|
|
71
|
+
/**
|
|
72
|
+
* Element tag -> the shadow part it is exposed as.
|
|
73
|
+
*
|
|
74
|
+
* Markdown is rendered from a string at runtime, so there is no template on which to author
|
|
75
|
+
* `part=` attributes - which is why this component previously exposed nothing at all and an
|
|
76
|
+
* embedding app could only reach it through whichever global design tokens the rules below happen
|
|
77
|
+
* to use. Annotating the generated DOM gives an app ordinary CSS over each element type
|
|
78
|
+
* (`ai-chat-markdown::part(md-li) { ... }`) instead of a per-property token API that would have to
|
|
79
|
+
* grow every time someone wants to style something new.
|
|
80
|
+
*
|
|
81
|
+
* The vocabulary is deliberately a fixed list of element kinds rather than anything derived from
|
|
82
|
+
* the content: it is a public API surface, so it should change only when this map does. That also
|
|
83
|
+
* makes it enumerable, which {@link MARKDOWN_EXPORTPARTS} relies on.
|
|
84
|
+
*/
|
|
85
|
+
const MARKDOWN_PARTS = {
|
|
86
|
+
P: 'md-p',
|
|
87
|
+
UL: 'md-ul',
|
|
88
|
+
OL: 'md-ol',
|
|
89
|
+
LI: 'md-li',
|
|
90
|
+
PRE: 'md-pre',
|
|
91
|
+
CODE: 'md-code',
|
|
92
|
+
A: 'md-link',
|
|
93
|
+
BLOCKQUOTE: 'md-quote',
|
|
94
|
+
TABLE: 'md-table',
|
|
95
|
+
THEAD: 'md-thead',
|
|
96
|
+
TBODY: 'md-tbody',
|
|
97
|
+
TR: 'md-tr',
|
|
98
|
+
TH: 'md-th',
|
|
99
|
+
TD: 'md-td',
|
|
100
|
+
HR: 'md-hr',
|
|
101
|
+
IMG: 'md-img',
|
|
102
|
+
STRONG: 'md-strong',
|
|
103
|
+
EM: 'md-em',
|
|
104
|
+
H1: 'md-h1',
|
|
105
|
+
H2: 'md-h2',
|
|
106
|
+
H3: 'md-h3',
|
|
107
|
+
H4: 'md-h4',
|
|
108
|
+
H5: 'md-h5',
|
|
109
|
+
H6: 'md-h6',
|
|
110
|
+
};
|
|
111
|
+
/** Tags whose part is also emitted with a nesting level (see {@link AiChatMarkdown.annotateParts}). */
|
|
112
|
+
const DEPTH_TAGGED = ['UL', 'OL', 'LI'];
|
|
113
|
+
const DEPTH_TAGGED_SET = new Set(DEPTH_TAGGED);
|
|
114
|
+
/**
|
|
115
|
+
* Deepest list level with a part of its own; anything deeper is tagged as this level.
|
|
116
|
+
*
|
|
117
|
+
* `exportparts` has no wildcard, so every level a host forwards has to be named. An uncapped
|
|
118
|
+
* scheme would therefore have a forwarding list that can never be complete, and any list deeper
|
|
119
|
+
* than it happened to enumerate would be silently unstyleable. Capping keeps the exported
|
|
120
|
+
* vocabulary finite and makes the deepest level mean "this deep or deeper", which is a contract
|
|
121
|
+
* that can actually be honoured.
|
|
122
|
+
*/
|
|
123
|
+
const MAX_LIST_LEVEL = 3;
|
|
124
|
+
/**
|
|
125
|
+
* The two `code` flavours, emitted alongside `md-code`.
|
|
126
|
+
*
|
|
127
|
+
* `::part()` takes no descendant combinators, so `md-code` alone cannot distinguish inline code
|
|
128
|
+
* from the `code` inside a `pre`: an app giving it a background for inline spans would paint every
|
|
129
|
+
* code block too, and the `pre code` reset in this component's own styles loses to an outer
|
|
130
|
+
* `::part` rule in the cascade, so there would be nothing to undo it with.
|
|
131
|
+
*/
|
|
132
|
+
const CODE_BLOCK_PART = 'md-code-block';
|
|
133
|
+
const CODE_INLINE_PART = 'md-code-inline';
|
|
134
|
+
/**
|
|
135
|
+
* Every part this component exposes, as an `exportparts` value.
|
|
136
|
+
*
|
|
137
|
+
* `::part()` crosses exactly one shadow boundary, so a host that renders `<ai-chat-markdown>` in
|
|
138
|
+
* its own shadow root has to forward these for an app to reach them at all. Built from the map
|
|
139
|
+
* above rather than written out, so the forwarded list cannot drift from what is emitted.
|
|
140
|
+
*/
|
|
141
|
+
export const MARKDOWN_EXPORTPARTS = [
|
|
142
|
+
...Object.values(MARKDOWN_PARTS),
|
|
143
|
+
CODE_BLOCK_PART,
|
|
144
|
+
CODE_INLINE_PART,
|
|
145
|
+
...DEPTH_TAGGED.flatMap((tag) => Array.from({ length: MAX_LIST_LEVEL }, (_, i) => `${MARKDOWN_PARTS[tag]}-level-${i + 1}`)),
|
|
146
|
+
].join(', ');
|
|
147
|
+
/** The part attribute for one generated element, given the list depth it sits at. */
|
|
148
|
+
function partFor(el, base, listDepth) {
|
|
149
|
+
var _a;
|
|
150
|
+
if (DEPTH_TAGGED_SET.has(el.tagName))
|
|
151
|
+
return `${base} ${base}-level-${listDepth}`;
|
|
152
|
+
if (el.tagName === 'CODE') {
|
|
153
|
+
return `${base} ${((_a = el.parentElement) === null || _a === void 0 ? void 0 : _a.tagName) === 'PRE' ? CODE_BLOCK_PART : CODE_INLINE_PART}`;
|
|
154
|
+
}
|
|
155
|
+
return base;
|
|
156
|
+
}
|
|
71
157
|
let AiChatMarkdown = class AiChatMarkdown extends GenesisElement {
|
|
72
158
|
constructor() {
|
|
73
159
|
super(...arguments);
|
|
@@ -79,7 +165,52 @@ let AiChatMarkdown = class AiChatMarkdown extends GenesisElement {
|
|
|
79
165
|
if (!this.content)
|
|
80
166
|
return '';
|
|
81
167
|
const rawHtml = marked.parse(this.content);
|
|
82
|
-
|
|
168
|
+
// `part`/`exportparts` are on DOMPurify's default allow-list, so a model emitting
|
|
169
|
+
// `<span part="md-link">` would otherwise land a name in this component's part namespace that
|
|
170
|
+
// MARKDOWN_PARTS never granted. Forbidding them keeps the vocabulary exactly what this file
|
|
171
|
+
// says it is, whatever the content claims.
|
|
172
|
+
return this.annotateParts(DOMPurify.sanitize(rawHtml, {
|
|
173
|
+
FORBID_ATTR: ['part', 'exportparts'],
|
|
174
|
+
RETURN_DOM_FRAGMENT: true,
|
|
175
|
+
}));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Tag the generated elements with shadow parts so an embedding app can style them.
|
|
179
|
+
*
|
|
180
|
+
* Takes the tree DOMPurify built rather than re-parsing its serialised output: `content` changes
|
|
181
|
+
* on every streamed chunk, so a second parse/serialise round trip would run per chunk over the
|
|
182
|
+
* whole message, and the string the browser finally parses is then serialised straight from the
|
|
183
|
+
* tree DOMPurify checked. Parse/serialise mismatches are where mXSS bypasses have historically
|
|
184
|
+
* lived, and this walk has no need to introduce one.
|
|
185
|
+
*
|
|
186
|
+
* Only ever *adds* attributes, to DOM that has already been cleared - so it is not itself
|
|
187
|
+
* sanitiser surface.
|
|
188
|
+
*
|
|
189
|
+
* Lists additionally carry a level: a top-level list is `md-ul md-ul-level-1`, a list nested
|
|
190
|
+
* inside it is `md-ul-level-2`, and an `li` takes the level of the list holding it. Levels are
|
|
191
|
+
* clamped at `MAX_LIST_LEVEL`, so a list deeper than that answers to the deepest level
|
|
192
|
+
* rather than to a name no host forwards. Chat markdown rarely nests, so this is a safety valve
|
|
193
|
+
* rather than a feature - without it, every list at every depth would answer to one selector and
|
|
194
|
+
* there would be no way to tell them apart afterwards. Depth comes from walking the tree rather
|
|
195
|
+
* than from marked's renderers, which are invoked innermost-first and so cannot count downwards.
|
|
196
|
+
*/
|
|
197
|
+
annotateParts(fragment) {
|
|
198
|
+
const walk = (parent, listDepth) => {
|
|
199
|
+
for (const el of Array.from(parent.children)) {
|
|
200
|
+
const base = MARKDOWN_PARTS[el.tagName];
|
|
201
|
+
// A list opens the next level; everything else sits at its parent list's level.
|
|
202
|
+
const depth = el.tagName === 'UL' || el.tagName === 'OL'
|
|
203
|
+
? Math.min(listDepth + 1, MAX_LIST_LEVEL)
|
|
204
|
+
: listDepth;
|
|
205
|
+
if (base)
|
|
206
|
+
el.setAttribute('part', partFor(el, base, depth));
|
|
207
|
+
walk(el, depth);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
walk(fragment, 0);
|
|
211
|
+
const container = document.createElement('div');
|
|
212
|
+
container.append(fragment);
|
|
213
|
+
return container.innerHTML;
|
|
83
214
|
}
|
|
84
215
|
};
|
|
85
216
|
__decorate([
|
|
@@ -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]) {
|
package/dist/esm/index.js
CHANGED
|
@@ -18,4 +18,6 @@ export * from './provider/tiered-provider-switcher';
|
|
|
18
18
|
export * from './provider/assistant-app-settings';
|
|
19
19
|
export * from './utils/tool-fold';
|
|
20
20
|
export { assistantSettingsSectionTitleStyles } from './styles/settings-section';
|
|
21
|
-
|
|
21
|
+
// MARKDOWN_EXPORTPARTS travels with the component: a host rendering `<ai-chat-markdown>` in its
|
|
22
|
+
// own shadow root has to forward its parts, and hand-copying the list is how it drifts.
|
|
23
|
+
export { AiChatMarkdown, MARKDOWN_EXPORTPARTS } from './components/chat-markdown/chat-markdown';
|
|
@@ -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,77 @@ const messageType = (m) => {
|
|
|
94
67
|
return 'ai';
|
|
95
68
|
}
|
|
96
69
|
};
|
|
70
|
+
/**
|
|
71
|
+
* Part names for one avatar element: the bare name, a role-level name, and — on the assistant
|
|
72
|
+
* side, whose rows vary — the message type.
|
|
73
|
+
*
|
|
74
|
+
* The role-level name is the one an app usually wants. `messageType` splits the assistant across
|
|
75
|
+
* `ai`, `ai-thinking`, `ai-function` and `interaction`, so without it "style the assistant's
|
|
76
|
+
* avatar, not the user's" takes four selectors and silently misses any type added later.
|
|
77
|
+
* `::part()` names cannot be chained, so each has to be a name of its own rather than a
|
|
78
|
+
* combination. The user side needs no extra name — its role and its type are both `user`.
|
|
79
|
+
*
|
|
80
|
+
* Exported for the unit test that pins the vocabulary; not part of the element API.
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
export const avatarPartsFor = (base, type) => type === 'user' ? `${base} ${base}-user` : `${base} ${base}-assistant ${base}-${type}`;
|
|
85
|
+
// Avatar markup is owned by the component (`assistantIconSafe` / `userIconSafe`),
|
|
86
|
+
// which holds the sanitized SVG string for the default or any consumer override
|
|
87
|
+
// and is injected via `:innerHTML`. A raster `image-src` / `user-image-src`
|
|
88
|
+
// takes precedence over the inline icon. The exported `*IconSvg` string
|
|
89
|
+
// constants in `./main` let apps opt back into a specific built-in mark.
|
|
90
|
+
/**
|
|
91
|
+
* The assistant's own avatar markup.
|
|
92
|
+
*
|
|
93
|
+
* Shared rather than duplicated because the loading-indicator row renders the same avatar from a
|
|
94
|
+
* different binding context (the assistant, not a message) — two copies drifted once already, and
|
|
95
|
+
* the parts below are the kind of thing only one copy tends to get.
|
|
96
|
+
*
|
|
97
|
+
* `type` is the message type the avatar belongs to, so `::part()` can reach the assistant's image
|
|
98
|
+
* without also matching the user's: part names cannot be chained in a selector, so the variant has
|
|
99
|
+
* to be a name of its own.
|
|
100
|
+
*/
|
|
101
|
+
const assistantAvatarMarkup = (parent, type) => parent.imageSrc
|
|
102
|
+
? html `
|
|
103
|
+
<img
|
|
104
|
+
src="${() => parent.imageSrc}"
|
|
105
|
+
alt="Assistant"
|
|
106
|
+
class="avatar-img"
|
|
107
|
+
part="${() => avatarPartsFor('avatar-img', type)}"
|
|
108
|
+
/>
|
|
109
|
+
`
|
|
110
|
+
: html `
|
|
111
|
+
<span
|
|
112
|
+
class="avatar-icon"
|
|
113
|
+
part="${() => avatarPartsFor('avatar-icon', type)}"
|
|
114
|
+
:innerHTML="${() => parent.assistantIconSafe}"
|
|
115
|
+
></span>
|
|
116
|
+
`;
|
|
117
|
+
const assistantAvatarTemplate = html `
|
|
118
|
+
${(m, c) => assistantAvatarMarkup(c.parent, messageType(m))}
|
|
119
|
+
`;
|
|
120
|
+
const userAvatarTemplate = html `
|
|
121
|
+
${(m, c) => {
|
|
122
|
+
const parent = c.parent;
|
|
123
|
+
return parent.userImageSrc
|
|
124
|
+
? html `
|
|
125
|
+
<img
|
|
126
|
+
src="${() => parent.userImageSrc}"
|
|
127
|
+
alt="You"
|
|
128
|
+
class="avatar-img"
|
|
129
|
+
part="${() => avatarPartsFor('avatar-img', 'user')}"
|
|
130
|
+
/>
|
|
131
|
+
`
|
|
132
|
+
: html `
|
|
133
|
+
<span
|
|
134
|
+
class="avatar-icon"
|
|
135
|
+
part="${() => avatarPartsFor('avatar-icon', 'user')}"
|
|
136
|
+
:innerHTML="${() => parent.userIconSafe}"
|
|
137
|
+
></span>
|
|
138
|
+
`;
|
|
139
|
+
}}
|
|
140
|
+
`;
|
|
97
141
|
const senderLabel = {
|
|
98
142
|
user: 'You',
|
|
99
143
|
'ai-thinking': 'Thinking',
|
|
@@ -513,7 +557,10 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
513
557
|
<div
|
|
514
558
|
class="message-row ${(m) => messageType(m)} ${(m) => m.interaction ? `present-${interactionPresentation(m)}` : ''}"
|
|
515
559
|
>
|
|
516
|
-
<div
|
|
560
|
+
<div
|
|
561
|
+
class="avatar ${(m) => messageType(m)}"
|
|
562
|
+
part="${(m) => avatarPartsFor('avatar', messageType(m))}"
|
|
563
|
+
>
|
|
517
564
|
${when(
|
|
518
565
|
// Keyed on messageType (not raw role) so a synthetic-user message,
|
|
519
566
|
// which renders as 'user', gets the user avatar rather than the
|
|
@@ -528,8 +575,8 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
528
575
|
// A 'bare' interaction owns its full presentation — suppress the
|
|
529
576
|
// host sender label. Every other message keeps it.
|
|
530
577
|
(m) => !(m.interaction && interactionPresentation(m) === 'bare'), html `
|
|
531
|
-
<div class="sender">
|
|
532
|
-
<span class="sender-label">
|
|
578
|
+
<div class="sender" part="sender">
|
|
579
|
+
<span class="sender-label" part="sender-label">
|
|
533
580
|
${(m, c) => {
|
|
534
581
|
var _a;
|
|
535
582
|
return messageType(m) === 'ai-function' &&
|
|
@@ -547,9 +594,16 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
547
594
|
c.parent.timestampDisplay !== 'off', messageTimestampTemplate)}
|
|
548
595
|
</div>
|
|
549
596
|
`)}
|
|
550
|
-
<div class="content">
|
|
597
|
+
<div class="content" part="content">
|
|
551
598
|
${when((m) => m.content, html `
|
|
552
|
-
|
|
599
|
+
${
|
|
600
|
+
/* Markdown renders inside THIS shadow root, so its parts need forwarding for
|
|
601
|
+
an app to reach them: ::part() crosses exactly one boundary. Built from the
|
|
602
|
+
component's own vocabulary so the two cannot drift. */ ''}
|
|
603
|
+
<ai-chat-markdown
|
|
604
|
+
exportparts="${MARKDOWN_EXPORTPARTS}"
|
|
605
|
+
:content="${(m) => m.content}"
|
|
606
|
+
></ai-chat-markdown>
|
|
553
607
|
`)}
|
|
554
608
|
${when((m) => m.toolCalls, html `
|
|
555
609
|
${repeat((m) => { var _a; return (_a = m.toolCalls) !== null && _a !== void 0 ? _a : []; }, toolCallItemTemplate)}
|
|
@@ -833,12 +887,30 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
833
887
|
${when((x) => !!x.headerTitle, html `
|
|
834
888
|
<span class="chat-title" part="chat-title">${(x) => x.headerTitle}</span>
|
|
835
889
|
`)}
|
|
890
|
+
${
|
|
891
|
+
/* The two buttons below re-publish the design-system button's inner parts (control,
|
|
892
|
+
content) into THIS component's part namespace via exportparts.
|
|
893
|
+
|
|
894
|
+
Without it they are unreachable by an embedding app: ::part() crosses exactly one
|
|
895
|
+
shadow boundary, and the control sits two away (app -> foundation-ai-assistant ->
|
|
896
|
+
buttonTag -> control). Exposing only the button host leaves an app able to size
|
|
897
|
+
the box but not the padded control inside it, which pushes hosts into sizing the
|
|
898
|
+
host and clipping the overflow to flatten these buttons - a workaround for a
|
|
899
|
+
missing hook rather than a styling choice.
|
|
900
|
+
|
|
901
|
+
The forwarded control/content names come from whichever design system's button is
|
|
902
|
+
registered as `buttonTag`; a button exposing different parts forwards nothing and
|
|
903
|
+
the rules below simply do not match.
|
|
904
|
+
|
|
905
|
+
Named with the owning button as a prefix so the namespace stays legible as more
|
|
906
|
+
parts are exported, and so control does not collide across buttons. */ ''}
|
|
836
907
|
<div class="header-actions" part="header-actions">
|
|
837
908
|
<slot name="header-actions-extra"></slot>
|
|
838
909
|
${when((x) => !!x.popoutMode, html `
|
|
839
910
|
<${buttonTag}
|
|
840
911
|
class="popout-button"
|
|
841
912
|
part="popout-button"
|
|
913
|
+
exportparts="control: popout-button-control, content: popout-button-content"
|
|
842
914
|
appearance="stealth"
|
|
843
915
|
title="${(x) => (x.popoutMode === 'expand' ? 'Expand to panel' : 'Pop back to bubble')}"
|
|
844
916
|
?disabled=${(x) => x.hasActivePendingInteraction}
|
|
@@ -848,6 +920,7 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
848
920
|
<${buttonTag}
|
|
849
921
|
class="settings-button"
|
|
850
922
|
part="settings-button"
|
|
923
|
+
exportparts="control: settings-button-control, content: settings-button-content"
|
|
851
924
|
appearance="stealth"
|
|
852
925
|
title="Settings"
|
|
853
926
|
aria-haspopup="dialog"
|
|
@@ -888,17 +961,8 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
888
961
|
LOADING_STYLE_ANIMATIONS.some((s) => x.enabledAnimations.includes(s)));
|
|
889
962
|
}, html `
|
|
890
963
|
<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
|
-
`}
|
|
964
|
+
<div class="avatar ai" part="${avatarPartsFor('avatar', 'ai')}">
|
|
965
|
+
${(x) => assistantAvatarMarkup(x, 'ai')}
|
|
902
966
|
</div>
|
|
903
967
|
${(x) => selectThinkingTemplate(x)}
|
|
904
968
|
</div>
|
|
@@ -936,6 +1000,7 @@ ${(tc) => { var _a; return (((_a = tc.foldPath) === null || _a === void 0 ? void
|
|
|
936
1000
|
`)}
|
|
937
1001
|
${when((x) => { var _a; return ((_a = x.chatConfig.suggestions) === null || _a === void 0 ? void 0 : _a.behavior) !== 'never' && !x.suggestionsBlocked; }, html `
|
|
938
1002
|
<chat-suggestions
|
|
1003
|
+
exportparts="${SUGGESTIONS_EXPORTPARTS}"
|
|
939
1004
|
:state="${(x) => x.suggestionsState}"
|
|
940
1005
|
@suggestion-clicked="${(x, c) => x.handleSuggestionClick(c.event.detail)}"
|
|
941
1006
|
></chat-suggestions>
|
|
@@ -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
|
>
|