@runtypelabs/persona 3.5.2 → 3.6.0
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/index.cjs +30 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.global.js +41 -41
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +29 -29
- package/dist/index.js.map +1 -1
- package/dist/theme-editor.cjs +17728 -0
- package/dist/theme-editor.d.cts +3857 -0
- package/dist/theme-editor.d.ts +3857 -0
- package/dist/theme-editor.js +17623 -0
- package/dist/theme-reference.cjs +1 -1
- package/dist/theme-reference.d.cts +14 -0
- package/dist/theme-reference.d.ts +14 -0
- package/dist/theme-reference.js +1 -1
- package/dist/widget.css +29 -25
- package/package.json +9 -7
- package/src/components/artifact-card.ts +1 -1
- package/src/components/composer-builder.ts +16 -29
- package/src/components/demo-carousel.ts +4 -4
- package/src/components/event-stream-view.ts +1 -1
- package/src/components/header-builder.ts +2 -2
- package/src/components/launcher.ts +9 -0
- package/src/components/message-bubble.ts +9 -3
- package/src/components/suggestions.ts +1 -1
- package/src/defaults.ts +9 -9
- package/src/styles/widget.css +29 -25
- package/src/theme-editor/color-utils.ts +252 -0
- package/src/theme-editor/index.ts +130 -0
- package/src/theme-editor/presets.ts +144 -0
- package/src/theme-editor/preview-utils.ts +265 -0
- package/src/theme-editor/preview.ts +445 -0
- package/src/theme-editor/role-mappings.ts +331 -0
- package/src/theme-editor/sections.ts +952 -0
- package/src/theme-editor/state.ts +298 -0
- package/src/theme-editor/types.ts +177 -0
- package/src/theme-editor.ts +2 -0
- package/src/types/theme.ts +1 -0
- package/src/ui.ts +53 -58
- package/src/utils/plugins.ts +1 -1
- package/src/utils/theme.test.ts +10 -8
- package/src/utils/theme.ts +11 -11
- package/src/utils/tokens.ts +88 -41
- package/widget.css +0 -1
|
@@ -0,0 +1,3857 @@
|
|
|
1
|
+
type TokenType = 'color' | 'spacing' | 'typography' | 'shadow' | 'border' | 'radius';
|
|
2
|
+
type TokenReference<_T extends TokenType = TokenType> = string;
|
|
3
|
+
interface ColorShade {
|
|
4
|
+
50?: string;
|
|
5
|
+
100?: string;
|
|
6
|
+
200?: string;
|
|
7
|
+
300?: string;
|
|
8
|
+
400?: string;
|
|
9
|
+
500?: string;
|
|
10
|
+
600?: string;
|
|
11
|
+
700?: string;
|
|
12
|
+
800?: string;
|
|
13
|
+
900?: string;
|
|
14
|
+
950?: string;
|
|
15
|
+
[key: string]: string | undefined;
|
|
16
|
+
}
|
|
17
|
+
interface ColorPalette {
|
|
18
|
+
gray: ColorShade;
|
|
19
|
+
primary: ColorShade;
|
|
20
|
+
secondary: ColorShade;
|
|
21
|
+
accent: ColorShade;
|
|
22
|
+
success: ColorShade;
|
|
23
|
+
warning: ColorShade;
|
|
24
|
+
error: ColorShade;
|
|
25
|
+
info: ColorShade;
|
|
26
|
+
[key: string]: ColorShade;
|
|
27
|
+
}
|
|
28
|
+
interface SpacingScale {
|
|
29
|
+
0: string;
|
|
30
|
+
1: string;
|
|
31
|
+
2: string;
|
|
32
|
+
3: string;
|
|
33
|
+
4: string;
|
|
34
|
+
5: string;
|
|
35
|
+
6: string;
|
|
36
|
+
8: string;
|
|
37
|
+
10: string;
|
|
38
|
+
12: string;
|
|
39
|
+
16: string;
|
|
40
|
+
20: string;
|
|
41
|
+
24: string;
|
|
42
|
+
32: string;
|
|
43
|
+
40: string;
|
|
44
|
+
48: string;
|
|
45
|
+
56: string;
|
|
46
|
+
64: string;
|
|
47
|
+
[key: string]: string;
|
|
48
|
+
}
|
|
49
|
+
interface ShadowScale {
|
|
50
|
+
none: string;
|
|
51
|
+
sm: string;
|
|
52
|
+
md: string;
|
|
53
|
+
lg: string;
|
|
54
|
+
xl: string;
|
|
55
|
+
'2xl': string;
|
|
56
|
+
[key: string]: string;
|
|
57
|
+
}
|
|
58
|
+
interface BorderScale {
|
|
59
|
+
none: string;
|
|
60
|
+
sm: string;
|
|
61
|
+
md: string;
|
|
62
|
+
lg: string;
|
|
63
|
+
[key: string]: string;
|
|
64
|
+
}
|
|
65
|
+
interface RadiusScale {
|
|
66
|
+
none: string;
|
|
67
|
+
sm: string;
|
|
68
|
+
md: string;
|
|
69
|
+
lg: string;
|
|
70
|
+
xl: string;
|
|
71
|
+
full: string;
|
|
72
|
+
[key: string]: string;
|
|
73
|
+
}
|
|
74
|
+
interface TypographyScale {
|
|
75
|
+
fontFamily: {
|
|
76
|
+
sans: string;
|
|
77
|
+
serif: string;
|
|
78
|
+
mono: string;
|
|
79
|
+
};
|
|
80
|
+
fontSize: {
|
|
81
|
+
xs: string;
|
|
82
|
+
sm: string;
|
|
83
|
+
base: string;
|
|
84
|
+
lg: string;
|
|
85
|
+
xl: string;
|
|
86
|
+
'2xl': string;
|
|
87
|
+
'3xl': string;
|
|
88
|
+
'4xl': string;
|
|
89
|
+
};
|
|
90
|
+
fontWeight: {
|
|
91
|
+
normal: string;
|
|
92
|
+
medium: string;
|
|
93
|
+
semibold: string;
|
|
94
|
+
bold: string;
|
|
95
|
+
};
|
|
96
|
+
lineHeight: {
|
|
97
|
+
tight: string;
|
|
98
|
+
normal: string;
|
|
99
|
+
relaxed: string;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
interface SemanticColors {
|
|
103
|
+
primary: TokenReference<'color'>;
|
|
104
|
+
secondary: TokenReference<'color'>;
|
|
105
|
+
accent: TokenReference<'color'>;
|
|
106
|
+
surface: TokenReference<'color'>;
|
|
107
|
+
background: TokenReference<'color'>;
|
|
108
|
+
container: TokenReference<'color'>;
|
|
109
|
+
text: TokenReference<'color'>;
|
|
110
|
+
textMuted: TokenReference<'color'>;
|
|
111
|
+
textInverse: TokenReference<'color'>;
|
|
112
|
+
border: TokenReference<'color'>;
|
|
113
|
+
divider: TokenReference<'color'>;
|
|
114
|
+
interactive: {
|
|
115
|
+
default: TokenReference<'color'>;
|
|
116
|
+
hover: TokenReference<'color'>;
|
|
117
|
+
focus: TokenReference<'color'>;
|
|
118
|
+
active: TokenReference<'color'>;
|
|
119
|
+
disabled: TokenReference<'color'>;
|
|
120
|
+
};
|
|
121
|
+
feedback: {
|
|
122
|
+
success: TokenReference<'color'>;
|
|
123
|
+
warning: TokenReference<'color'>;
|
|
124
|
+
error: TokenReference<'color'>;
|
|
125
|
+
info: TokenReference<'color'>;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
interface SemanticSpacing {
|
|
129
|
+
xs: TokenReference<'spacing'>;
|
|
130
|
+
sm: TokenReference<'spacing'>;
|
|
131
|
+
md: TokenReference<'spacing'>;
|
|
132
|
+
lg: TokenReference<'spacing'>;
|
|
133
|
+
xl: TokenReference<'spacing'>;
|
|
134
|
+
'2xl': TokenReference<'spacing'>;
|
|
135
|
+
}
|
|
136
|
+
interface SemanticTypography {
|
|
137
|
+
fontFamily: TokenReference<'typography'>;
|
|
138
|
+
fontSize: TokenReference<'typography'>;
|
|
139
|
+
fontWeight: TokenReference<'typography'>;
|
|
140
|
+
lineHeight: TokenReference<'typography'>;
|
|
141
|
+
}
|
|
142
|
+
interface SemanticTokens {
|
|
143
|
+
colors: SemanticColors;
|
|
144
|
+
spacing: SemanticSpacing;
|
|
145
|
+
typography: SemanticTypography;
|
|
146
|
+
}
|
|
147
|
+
interface ComponentTokenSet {
|
|
148
|
+
background?: TokenReference<'color'>;
|
|
149
|
+
foreground?: TokenReference<'color'>;
|
|
150
|
+
border?: TokenReference<'color'>;
|
|
151
|
+
borderRadius?: TokenReference<'radius'>;
|
|
152
|
+
padding?: TokenReference<'spacing'>;
|
|
153
|
+
margin?: TokenReference<'spacing'>;
|
|
154
|
+
shadow?: TokenReference<'shadow'>;
|
|
155
|
+
opacity?: number;
|
|
156
|
+
}
|
|
157
|
+
interface ButtonTokens extends ComponentTokenSet {
|
|
158
|
+
primary: ComponentTokenSet;
|
|
159
|
+
secondary: ComponentTokenSet;
|
|
160
|
+
ghost: ComponentTokenSet;
|
|
161
|
+
}
|
|
162
|
+
interface InputTokens extends ComponentTokenSet {
|
|
163
|
+
background: TokenReference<'color'>;
|
|
164
|
+
placeholder: TokenReference<'color'>;
|
|
165
|
+
focus: {
|
|
166
|
+
border: TokenReference<'color'>;
|
|
167
|
+
ring: TokenReference<'color'>;
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
interface LauncherTokens extends ComponentTokenSet {
|
|
171
|
+
size: string;
|
|
172
|
+
iconSize: string;
|
|
173
|
+
shadow: TokenReference<'shadow'>;
|
|
174
|
+
}
|
|
175
|
+
interface PanelTokens extends ComponentTokenSet {
|
|
176
|
+
width: string;
|
|
177
|
+
maxWidth: string;
|
|
178
|
+
height: string;
|
|
179
|
+
maxHeight: string;
|
|
180
|
+
}
|
|
181
|
+
interface HeaderTokens extends ComponentTokenSet {
|
|
182
|
+
background: TokenReference<'color'>;
|
|
183
|
+
border: TokenReference<'color'>;
|
|
184
|
+
borderRadius: TokenReference<'radius'>;
|
|
185
|
+
/** Background of the rounded avatar tile next to the title (Lucide / emoji / image). */
|
|
186
|
+
iconBackground: TokenReference<'color'>;
|
|
187
|
+
/** Foreground (glyph stroke or emoji text) on the header avatar tile. */
|
|
188
|
+
iconForeground: TokenReference<'color'>;
|
|
189
|
+
/** Header title line (next to the icon, or minimal layout title). */
|
|
190
|
+
titleForeground: TokenReference<'color'>;
|
|
191
|
+
/** Header subtitle line under the title. */
|
|
192
|
+
subtitleForeground: TokenReference<'color'>;
|
|
193
|
+
/** Default color for clear / close icon buttons when launcher overrides are unset. */
|
|
194
|
+
actionIconForeground: TokenReference<'color'>;
|
|
195
|
+
/** Box-shadow on the header (e.g., a fade shadow to replace the default border). */
|
|
196
|
+
shadow?: string;
|
|
197
|
+
/** Override the header bottom border (e.g., `none`). */
|
|
198
|
+
borderBottom?: string;
|
|
199
|
+
}
|
|
200
|
+
interface MessageTokens {
|
|
201
|
+
user: {
|
|
202
|
+
background: TokenReference<'color'>;
|
|
203
|
+
text: TokenReference<'color'>;
|
|
204
|
+
borderRadius: TokenReference<'radius'>;
|
|
205
|
+
/** User bubble box-shadow (token ref or raw CSS, e.g. `none`). */
|
|
206
|
+
shadow?: string;
|
|
207
|
+
};
|
|
208
|
+
assistant: {
|
|
209
|
+
background: TokenReference<'color'>;
|
|
210
|
+
text: TokenReference<'color'>;
|
|
211
|
+
borderRadius: TokenReference<'radius'>;
|
|
212
|
+
/** Assistant bubble border color (CSS color). */
|
|
213
|
+
border?: TokenReference<'color'>;
|
|
214
|
+
/** Assistant bubble box-shadow (token ref or raw CSS, e.g. `none`). */
|
|
215
|
+
shadow?: string;
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
interface MarkdownTokens {
|
|
219
|
+
inlineCode: {
|
|
220
|
+
background: TokenReference<'color'>;
|
|
221
|
+
foreground: TokenReference<'color'>;
|
|
222
|
+
};
|
|
223
|
+
/** Foreground for `<a>` in rendered markdown (assistant bubbles + artifact pane). */
|
|
224
|
+
link?: {
|
|
225
|
+
foreground: TokenReference<'color'>;
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* Body font for rendered markdown blocks (artifact pane + markdown bubbles).
|
|
229
|
+
* Use a raw CSS `font-family` value, e.g. `Georgia, serif`.
|
|
230
|
+
*/
|
|
231
|
+
prose?: {
|
|
232
|
+
fontFamily?: string;
|
|
233
|
+
};
|
|
234
|
+
/** Optional heading scale overrides (raw CSS or resolvable token paths). */
|
|
235
|
+
heading?: {
|
|
236
|
+
h1?: {
|
|
237
|
+
fontSize?: string;
|
|
238
|
+
fontWeight?: string;
|
|
239
|
+
};
|
|
240
|
+
h2?: {
|
|
241
|
+
fontSize?: string;
|
|
242
|
+
fontWeight?: string;
|
|
243
|
+
};
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
interface VoiceTokens {
|
|
247
|
+
recording: {
|
|
248
|
+
indicator: TokenReference<'color'>;
|
|
249
|
+
background: TokenReference<'color'>;
|
|
250
|
+
border: TokenReference<'color'>;
|
|
251
|
+
};
|
|
252
|
+
processing: {
|
|
253
|
+
icon: TokenReference<'color'>;
|
|
254
|
+
background: TokenReference<'color'>;
|
|
255
|
+
};
|
|
256
|
+
speaking: {
|
|
257
|
+
icon: TokenReference<'color'>;
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
interface ApprovalTokens {
|
|
261
|
+
requested: {
|
|
262
|
+
background: TokenReference<'color'>;
|
|
263
|
+
border: TokenReference<'color'>;
|
|
264
|
+
text: TokenReference<'color'>;
|
|
265
|
+
};
|
|
266
|
+
approve: ComponentTokenSet;
|
|
267
|
+
deny: ComponentTokenSet;
|
|
268
|
+
}
|
|
269
|
+
interface AttachmentTokens {
|
|
270
|
+
image: {
|
|
271
|
+
background: TokenReference<'color'>;
|
|
272
|
+
border: TokenReference<'color'>;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
/** Tool-call row chrome (collapsible tool bubbles). */
|
|
276
|
+
interface ToolBubbleTokens {
|
|
277
|
+
/** Box-shadow for tool bubbles (token ref or raw CSS, e.g. `none`). */
|
|
278
|
+
shadow: string;
|
|
279
|
+
}
|
|
280
|
+
/** Reasoning / “thinking” row chrome. */
|
|
281
|
+
interface ReasoningBubbleTokens {
|
|
282
|
+
shadow: string;
|
|
283
|
+
}
|
|
284
|
+
/** Composer (message input) chrome. */
|
|
285
|
+
interface ComposerChromeTokens {
|
|
286
|
+
/** Box-shadow on the composer form (raw CSS, e.g. `none`). */
|
|
287
|
+
shadow: string;
|
|
288
|
+
}
|
|
289
|
+
/** Artifact toolbar chrome. */
|
|
290
|
+
interface ArtifactToolbarTokens {
|
|
291
|
+
iconHoverColor?: string;
|
|
292
|
+
iconHoverBackground?: string;
|
|
293
|
+
iconPadding?: string;
|
|
294
|
+
iconBorderRadius?: string;
|
|
295
|
+
iconBorder?: string;
|
|
296
|
+
toggleGroupGap?: string;
|
|
297
|
+
toggleBorderRadius?: string;
|
|
298
|
+
copyBackground?: string;
|
|
299
|
+
copyBorder?: string;
|
|
300
|
+
copyColor?: string;
|
|
301
|
+
copyBorderRadius?: string;
|
|
302
|
+
copyPadding?: string;
|
|
303
|
+
copyMenuBackground?: string;
|
|
304
|
+
copyMenuBorder?: string;
|
|
305
|
+
copyMenuShadow?: string;
|
|
306
|
+
copyMenuBorderRadius?: string;
|
|
307
|
+
copyMenuItemHoverBackground?: string;
|
|
308
|
+
/** Base background of icon buttons (defaults to --persona-surface). */
|
|
309
|
+
iconBackground?: string;
|
|
310
|
+
/** Border on the toolbar (e.g., `none` to remove the bottom border). */
|
|
311
|
+
toolbarBorder?: string;
|
|
312
|
+
}
|
|
313
|
+
/** Artifact tab strip chrome. */
|
|
314
|
+
interface ArtifactTabTokens {
|
|
315
|
+
background?: string;
|
|
316
|
+
activeBackground?: string;
|
|
317
|
+
activeBorder?: string;
|
|
318
|
+
borderRadius?: string;
|
|
319
|
+
textColor?: string;
|
|
320
|
+
/** Hover background for inactive tabs. */
|
|
321
|
+
hoverBackground?: string;
|
|
322
|
+
/** Tab list container background. */
|
|
323
|
+
listBackground?: string;
|
|
324
|
+
/** Tab list container border color. */
|
|
325
|
+
listBorderColor?: string;
|
|
326
|
+
/** Tab list container padding (CSS shorthand). */
|
|
327
|
+
listPadding?: string;
|
|
328
|
+
}
|
|
329
|
+
/** Artifact pane chrome. */
|
|
330
|
+
interface ArtifactPaneTokens {
|
|
331
|
+
/**
|
|
332
|
+
* Background for the artifact column (toolbar + content), resolved from the theme.
|
|
333
|
+
* Defaults to `semantic.colors.container` so the pane matches assistant message surfaces.
|
|
334
|
+
* `features.artifacts.layout.paneBackground` still wins when set (layout escape hatch).
|
|
335
|
+
*/
|
|
336
|
+
background?: string;
|
|
337
|
+
toolbarBackground?: string;
|
|
338
|
+
}
|
|
339
|
+
/** Icon button chrome (used by createIconButton). */
|
|
340
|
+
interface IconButtonTokens {
|
|
341
|
+
background?: string;
|
|
342
|
+
border?: string;
|
|
343
|
+
color?: string;
|
|
344
|
+
padding?: string;
|
|
345
|
+
borderRadius?: string;
|
|
346
|
+
hoverBackground?: string;
|
|
347
|
+
hoverColor?: string;
|
|
348
|
+
/** Background when aria-pressed="true". */
|
|
349
|
+
activeBackground?: string;
|
|
350
|
+
/** Border color when aria-pressed="true". */
|
|
351
|
+
activeBorder?: string;
|
|
352
|
+
}
|
|
353
|
+
/** Label button chrome (used by createLabelButton). */
|
|
354
|
+
interface LabelButtonTokens {
|
|
355
|
+
background?: string;
|
|
356
|
+
border?: string;
|
|
357
|
+
color?: string;
|
|
358
|
+
padding?: string;
|
|
359
|
+
borderRadius?: string;
|
|
360
|
+
hoverBackground?: string;
|
|
361
|
+
fontSize?: string;
|
|
362
|
+
gap?: string;
|
|
363
|
+
}
|
|
364
|
+
/** Toggle group chrome (used by createToggleGroup). */
|
|
365
|
+
interface ToggleGroupTokens {
|
|
366
|
+
/** Gap between toggle buttons. Default: 0 (connected). */
|
|
367
|
+
gap?: string;
|
|
368
|
+
/** Border radius for first/last buttons. */
|
|
369
|
+
borderRadius?: string;
|
|
370
|
+
}
|
|
371
|
+
interface ComponentTokens {
|
|
372
|
+
button: ButtonTokens;
|
|
373
|
+
input: InputTokens;
|
|
374
|
+
launcher: LauncherTokens;
|
|
375
|
+
panel: PanelTokens;
|
|
376
|
+
header: HeaderTokens;
|
|
377
|
+
message: MessageTokens;
|
|
378
|
+
/** Markdown surfaces (chat + artifact pane). */
|
|
379
|
+
markdown?: MarkdownTokens;
|
|
380
|
+
voice: VoiceTokens;
|
|
381
|
+
approval: ApprovalTokens;
|
|
382
|
+
attachment: AttachmentTokens;
|
|
383
|
+
toolBubble: ToolBubbleTokens;
|
|
384
|
+
reasoningBubble: ReasoningBubbleTokens;
|
|
385
|
+
composer: ComposerChromeTokens;
|
|
386
|
+
/** Icon button styling tokens. */
|
|
387
|
+
iconButton?: IconButtonTokens;
|
|
388
|
+
/** Label button styling tokens. */
|
|
389
|
+
labelButton?: LabelButtonTokens;
|
|
390
|
+
/** Toggle group styling tokens. */
|
|
391
|
+
toggleGroup?: ToggleGroupTokens;
|
|
392
|
+
/** Artifact toolbar, tab strip, and pane chrome. */
|
|
393
|
+
artifact?: {
|
|
394
|
+
toolbar?: ArtifactToolbarTokens;
|
|
395
|
+
tab?: ArtifactTabTokens;
|
|
396
|
+
pane?: ArtifactPaneTokens;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
interface PaletteExtras {
|
|
400
|
+
transitions?: Record<string, string>;
|
|
401
|
+
easings?: Record<string, string>;
|
|
402
|
+
}
|
|
403
|
+
interface PersonaThemeBase {
|
|
404
|
+
palette: {
|
|
405
|
+
colors: ColorPalette;
|
|
406
|
+
spacing: SpacingScale;
|
|
407
|
+
typography: TypographyScale;
|
|
408
|
+
shadows: ShadowScale;
|
|
409
|
+
borders: BorderScale;
|
|
410
|
+
radius: RadiusScale;
|
|
411
|
+
} & PaletteExtras;
|
|
412
|
+
}
|
|
413
|
+
interface PersonaThemeSemantic {
|
|
414
|
+
semantic: SemanticTokens;
|
|
415
|
+
}
|
|
416
|
+
interface PersonaThemeComponents {
|
|
417
|
+
components: ComponentTokens;
|
|
418
|
+
}
|
|
419
|
+
type PersonaTheme = PersonaThemeBase & PersonaThemeSemantic & PersonaThemeComponents;
|
|
420
|
+
/** Recursive partial for `config.theme` / `config.darkTheme` overrides. */
|
|
421
|
+
type DeepPartial<T> = T extends object ? {
|
|
422
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
423
|
+
} : T;
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* Plugin interface for customizing widget components
|
|
427
|
+
*/
|
|
428
|
+
interface AgentWidgetPlugin {
|
|
429
|
+
/**
|
|
430
|
+
* Unique identifier for the plugin
|
|
431
|
+
*/
|
|
432
|
+
id: string;
|
|
433
|
+
/**
|
|
434
|
+
* Optional priority (higher = runs first). Default: 0
|
|
435
|
+
*/
|
|
436
|
+
priority?: number;
|
|
437
|
+
/**
|
|
438
|
+
* Custom renderer for message bubbles
|
|
439
|
+
* Return null to use default renderer
|
|
440
|
+
*/
|
|
441
|
+
renderMessage?: (context: {
|
|
442
|
+
message: AgentWidgetMessage;
|
|
443
|
+
defaultRenderer: () => HTMLElement;
|
|
444
|
+
config: AgentWidgetConfig;
|
|
445
|
+
}) => HTMLElement | null;
|
|
446
|
+
/**
|
|
447
|
+
* Custom renderer for launcher button
|
|
448
|
+
* Return null to use default renderer
|
|
449
|
+
*/
|
|
450
|
+
renderLauncher?: (context: {
|
|
451
|
+
config: AgentWidgetConfig;
|
|
452
|
+
defaultRenderer: () => HTMLElement;
|
|
453
|
+
onToggle: () => void;
|
|
454
|
+
}) => HTMLElement | null;
|
|
455
|
+
/**
|
|
456
|
+
* Custom renderer for panel header
|
|
457
|
+
* Return null to use default renderer
|
|
458
|
+
*/
|
|
459
|
+
renderHeader?: (context: {
|
|
460
|
+
config: AgentWidgetConfig;
|
|
461
|
+
defaultRenderer: () => HTMLElement;
|
|
462
|
+
onClose?: () => void;
|
|
463
|
+
}) => HTMLElement | null;
|
|
464
|
+
/**
|
|
465
|
+
* Custom renderer for composer/input area
|
|
466
|
+
* Return null to use default renderer
|
|
467
|
+
*/
|
|
468
|
+
renderComposer?: (context: {
|
|
469
|
+
config: AgentWidgetConfig;
|
|
470
|
+
defaultRenderer: () => HTMLElement;
|
|
471
|
+
onSubmit: (text: string) => void;
|
|
472
|
+
/**
|
|
473
|
+
* When true, the assistant stream is active — same moment `session.isStreaming()` becomes true.
|
|
474
|
+
* Prefer wiring controls to `data-persona-composer-disable-when-streaming` plus `setComposerDisabled`
|
|
475
|
+
* in the host, or react to `footer.dataset.personaComposerStreaming === "true"`.
|
|
476
|
+
*/
|
|
477
|
+
streaming: boolean;
|
|
478
|
+
/**
|
|
479
|
+
* Legacy alias: host disables the primary submit control while `streaming` is true.
|
|
480
|
+
* @deprecated Use `streaming` for new plugins.
|
|
481
|
+
*/
|
|
482
|
+
disabled: boolean;
|
|
483
|
+
/** Opens the hidden file input when `config.attachments.enabled` is true (no-op otherwise). */
|
|
484
|
+
openAttachmentPicker: () => void;
|
|
485
|
+
/** From `config.composer.models` */
|
|
486
|
+
models?: Array<{
|
|
487
|
+
id: string;
|
|
488
|
+
label: string;
|
|
489
|
+
}>;
|
|
490
|
+
/** From `config.composer.selectedModelId` */
|
|
491
|
+
selectedModelId?: string;
|
|
492
|
+
/** Updates `config.composer.selectedModelId` for the running widget instance. */
|
|
493
|
+
onModelChange?: (modelId: string) => void;
|
|
494
|
+
/**
|
|
495
|
+
* Same behavior as the built-in mic when voice is enabled.
|
|
496
|
+
* Omitted when `config.voiceRecognition.enabled` is not true.
|
|
497
|
+
*/
|
|
498
|
+
onVoiceToggle?: () => void;
|
|
499
|
+
}) => HTMLElement | null;
|
|
500
|
+
/**
|
|
501
|
+
* Custom renderer for reasoning bubbles
|
|
502
|
+
* Return null to use default renderer
|
|
503
|
+
*/
|
|
504
|
+
renderReasoning?: (context: {
|
|
505
|
+
message: AgentWidgetMessage;
|
|
506
|
+
defaultRenderer: () => HTMLElement;
|
|
507
|
+
config: AgentWidgetConfig;
|
|
508
|
+
}) => HTMLElement | null;
|
|
509
|
+
/**
|
|
510
|
+
* Custom renderer for tool call bubbles
|
|
511
|
+
* Return null to use default renderer
|
|
512
|
+
*/
|
|
513
|
+
renderToolCall?: (context: {
|
|
514
|
+
message: AgentWidgetMessage;
|
|
515
|
+
defaultRenderer: () => HTMLElement;
|
|
516
|
+
config: AgentWidgetConfig;
|
|
517
|
+
}) => HTMLElement | null;
|
|
518
|
+
/**
|
|
519
|
+
* Custom renderer for approval bubbles
|
|
520
|
+
* Return null to use default renderer
|
|
521
|
+
*/
|
|
522
|
+
renderApproval?: (context: {
|
|
523
|
+
message: AgentWidgetMessage;
|
|
524
|
+
defaultRenderer: () => HTMLElement;
|
|
525
|
+
config: AgentWidgetConfig;
|
|
526
|
+
}) => HTMLElement | null;
|
|
527
|
+
/**
|
|
528
|
+
* Custom renderer for loading indicator
|
|
529
|
+
* Return null to use default renderer (or config-based renderer)
|
|
530
|
+
*
|
|
531
|
+
* @example
|
|
532
|
+
* ```typescript
|
|
533
|
+
* renderLoadingIndicator: ({ location, defaultRenderer }) => {
|
|
534
|
+
* if (location === 'standalone') {
|
|
535
|
+
* const el = document.createElement('div');
|
|
536
|
+
* el.textContent = 'Thinking...';
|
|
537
|
+
* return el;
|
|
538
|
+
* }
|
|
539
|
+
* return defaultRenderer();
|
|
540
|
+
* }
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
renderLoadingIndicator?: (context: LoadingIndicatorRenderContext) => HTMLElement | null;
|
|
544
|
+
/**
|
|
545
|
+
* Custom renderer for idle state indicator.
|
|
546
|
+
* Called when the widget is idle (not streaming) and has at least one message.
|
|
547
|
+
* Return an HTMLElement to display, or null to hide (default).
|
|
548
|
+
*
|
|
549
|
+
* @example
|
|
550
|
+
* ```typescript
|
|
551
|
+
* renderIdleIndicator: ({ lastMessage, messageCount }) => {
|
|
552
|
+
* if (messageCount === 0) return null;
|
|
553
|
+
* if (lastMessage?.role !== 'assistant') return null;
|
|
554
|
+
* const el = document.createElement('div');
|
|
555
|
+
* el.className = 'idle-pulse';
|
|
556
|
+
* el.setAttribute('data-preserve-animation', 'true');
|
|
557
|
+
* return el;
|
|
558
|
+
* }
|
|
559
|
+
* ```
|
|
560
|
+
*/
|
|
561
|
+
renderIdleIndicator?: (context: IdleIndicatorRenderContext) => HTMLElement | null;
|
|
562
|
+
/**
|
|
563
|
+
* Custom renderer for the entire event stream view.
|
|
564
|
+
* Return null to use default renderer.
|
|
565
|
+
*/
|
|
566
|
+
renderEventStreamView?: (context: EventStreamViewRenderContext) => HTMLElement | null;
|
|
567
|
+
/**
|
|
568
|
+
* Custom renderer for individual event stream rows.
|
|
569
|
+
* Return null to use default renderer.
|
|
570
|
+
*/
|
|
571
|
+
renderEventStreamRow?: (context: EventStreamRowRenderContext) => HTMLElement | null;
|
|
572
|
+
/**
|
|
573
|
+
* Custom renderer for the event stream toolbar/header bar.
|
|
574
|
+
* Return null to use default renderer.
|
|
575
|
+
*/
|
|
576
|
+
renderEventStreamToolbar?: (context: EventStreamToolbarRenderContext) => HTMLElement | null;
|
|
577
|
+
/**
|
|
578
|
+
* Custom renderer for the expanded event payload display.
|
|
579
|
+
* Return null to use default renderer.
|
|
580
|
+
*/
|
|
581
|
+
renderEventStreamPayload?: (context: EventStreamPayloadRenderContext) => HTMLElement | null;
|
|
582
|
+
/**
|
|
583
|
+
* Called when plugin is registered
|
|
584
|
+
*/
|
|
585
|
+
onRegister?: () => void;
|
|
586
|
+
/**
|
|
587
|
+
* Called when plugin is unregistered
|
|
588
|
+
*/
|
|
589
|
+
onUnregister?: () => void;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Text content part for multi-modal messages
|
|
594
|
+
*/
|
|
595
|
+
type TextContentPart = {
|
|
596
|
+
type: 'text';
|
|
597
|
+
text: string;
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* Image content part for multi-modal messages
|
|
601
|
+
* Supports base64 data URIs or URLs
|
|
602
|
+
*/
|
|
603
|
+
type ImageContentPart = {
|
|
604
|
+
type: 'image';
|
|
605
|
+
image: string;
|
|
606
|
+
mimeType?: string;
|
|
607
|
+
alt?: string;
|
|
608
|
+
};
|
|
609
|
+
/**
|
|
610
|
+
* File content part for multi-modal messages
|
|
611
|
+
* Supports PDF, TXT, DOCX, and other document types
|
|
612
|
+
*/
|
|
613
|
+
type FileContentPart = {
|
|
614
|
+
type: 'file';
|
|
615
|
+
data: string;
|
|
616
|
+
mimeType: string;
|
|
617
|
+
filename: string;
|
|
618
|
+
};
|
|
619
|
+
/**
|
|
620
|
+
* Union type for all content part types
|
|
621
|
+
*/
|
|
622
|
+
type ContentPart = TextContentPart | ImageContentPart | FileContentPart;
|
|
623
|
+
/**
|
|
624
|
+
* Message content can be a simple string or an array of content parts
|
|
625
|
+
*/
|
|
626
|
+
type MessageContent = string | ContentPart[];
|
|
627
|
+
type AgentWidgetContextProviderContext = {
|
|
628
|
+
messages: AgentWidgetMessage[];
|
|
629
|
+
config: AgentWidgetConfig;
|
|
630
|
+
};
|
|
631
|
+
type AgentWidgetContextProvider = (context: AgentWidgetContextProviderContext) => Record<string, unknown> | void | Promise<Record<string, unknown> | void>;
|
|
632
|
+
type AgentWidgetRequestPayloadMessage = {
|
|
633
|
+
role: AgentWidgetMessageRole;
|
|
634
|
+
content: MessageContent;
|
|
635
|
+
createdAt: string;
|
|
636
|
+
};
|
|
637
|
+
type AgentWidgetRequestPayload = {
|
|
638
|
+
messages: AgentWidgetRequestPayloadMessage[];
|
|
639
|
+
flowId?: string;
|
|
640
|
+
context?: Record<string, unknown>;
|
|
641
|
+
metadata?: Record<string, unknown>;
|
|
642
|
+
/** Per-turn template variables for /v1/client/chat (merged as root-level {{var}} in Runtype). */
|
|
643
|
+
inputs?: Record<string, unknown>;
|
|
644
|
+
};
|
|
645
|
+
/**
|
|
646
|
+
* Configuration for agent loop behavior.
|
|
647
|
+
*/
|
|
648
|
+
type AgentLoopConfig = {
|
|
649
|
+
/** Maximum number of agent turns (1-100). The loop continues while the model calls tools. */
|
|
650
|
+
maxTurns: number;
|
|
651
|
+
/** Maximum cost budget in USD. Agent stops when exceeded. */
|
|
652
|
+
maxCost?: number;
|
|
653
|
+
/** Enable periodic reflection during execution */
|
|
654
|
+
enableReflection?: boolean;
|
|
655
|
+
/** Number of iterations between reflections (1-50) */
|
|
656
|
+
reflectionInterval?: number;
|
|
657
|
+
};
|
|
658
|
+
/**
|
|
659
|
+
* Configuration for agent tools (search, code execution, MCP servers, etc.)
|
|
660
|
+
*/
|
|
661
|
+
type AgentToolsConfig = {
|
|
662
|
+
/** Tool IDs to enable (e.g., "builtin:exa", "builtin:dalle", "builtin:openai_web_search") */
|
|
663
|
+
toolIds?: string[];
|
|
664
|
+
/** Per-tool configuration overrides keyed by tool ID */
|
|
665
|
+
toolConfigs?: Record<string, Record<string, unknown>>;
|
|
666
|
+
/** Inline tool definitions for runtime-defined tools */
|
|
667
|
+
runtimeTools?: Array<Record<string, unknown>>;
|
|
668
|
+
/** Custom MCP server connections */
|
|
669
|
+
mcpServers?: Array<Record<string, unknown>>;
|
|
670
|
+
/** Maximum number of tool invocations per execution */
|
|
671
|
+
maxToolCalls?: number;
|
|
672
|
+
/** Tool approval configuration for human-in-the-loop workflows */
|
|
673
|
+
approval?: {
|
|
674
|
+
/** Tool names/patterns to require approval for, or true for all tools */
|
|
675
|
+
require: string[] | boolean;
|
|
676
|
+
/** Approval timeout in milliseconds (default: 300000 / 5 minutes) */
|
|
677
|
+
timeout?: number;
|
|
678
|
+
};
|
|
679
|
+
};
|
|
680
|
+
/** Artifact kinds for the Persona sidebar and dispatch payload */
|
|
681
|
+
type PersonaArtifactKind = "markdown" | "component";
|
|
682
|
+
/**
|
|
683
|
+
* Agent configuration for agent execution mode.
|
|
684
|
+
* When provided in the widget config, enables agent loop execution instead of flow dispatch.
|
|
685
|
+
*/
|
|
686
|
+
type ArtifactConfigPayload = {
|
|
687
|
+
enabled: true;
|
|
688
|
+
types: PersonaArtifactKind[];
|
|
689
|
+
};
|
|
690
|
+
type AgentConfig = {
|
|
691
|
+
/** Agent display name */
|
|
692
|
+
name: string;
|
|
693
|
+
/** Model identifier (e.g., 'openai:gpt-4o-mini', 'qwen/qwen3-8b') */
|
|
694
|
+
model: string;
|
|
695
|
+
/** System prompt for the agent */
|
|
696
|
+
systemPrompt: string;
|
|
697
|
+
/** Temperature for model responses */
|
|
698
|
+
temperature?: number;
|
|
699
|
+
/** Tool configuration for the agent */
|
|
700
|
+
tools?: AgentToolsConfig;
|
|
701
|
+
/** Persona artifacts — sibling of tools (virtual agent / API parity) */
|
|
702
|
+
artifacts?: ArtifactConfigPayload;
|
|
703
|
+
/** Loop configuration for multi-turn execution */
|
|
704
|
+
loopConfig?: AgentLoopConfig;
|
|
705
|
+
};
|
|
706
|
+
/**
|
|
707
|
+
* Options for agent execution requests.
|
|
708
|
+
*/
|
|
709
|
+
type AgentRequestOptions = {
|
|
710
|
+
/** Whether to stream the response (should be true for widget usage) */
|
|
711
|
+
streamResponse?: boolean;
|
|
712
|
+
/** Record mode: 'virtual' for no persistence, 'existing'/'create' for database records */
|
|
713
|
+
recordMode?: 'virtual' | 'existing' | 'create';
|
|
714
|
+
/** Whether to store results server-side */
|
|
715
|
+
storeResults?: boolean;
|
|
716
|
+
/** Enable debug mode for additional event data */
|
|
717
|
+
debugMode?: boolean;
|
|
718
|
+
};
|
|
719
|
+
/**
|
|
720
|
+
* Metadata attached to messages created during agent execution.
|
|
721
|
+
*/
|
|
722
|
+
type AgentMessageMetadata = {
|
|
723
|
+
executionId?: string;
|
|
724
|
+
iteration?: number;
|
|
725
|
+
turnId?: string;
|
|
726
|
+
agentName?: string;
|
|
727
|
+
};
|
|
728
|
+
type AgentWidgetRequestMiddlewareContext = {
|
|
729
|
+
payload: AgentWidgetRequestPayload;
|
|
730
|
+
config: AgentWidgetConfig;
|
|
731
|
+
};
|
|
732
|
+
type AgentWidgetRequestMiddleware = (context: AgentWidgetRequestMiddlewareContext) => AgentWidgetRequestPayload | void | Promise<AgentWidgetRequestPayload | void>;
|
|
733
|
+
type AgentWidgetParsedAction = {
|
|
734
|
+
type: string;
|
|
735
|
+
payload: Record<string, unknown>;
|
|
736
|
+
raw?: unknown;
|
|
737
|
+
};
|
|
738
|
+
type AgentWidgetActionParserInput = {
|
|
739
|
+
text: string;
|
|
740
|
+
message: AgentWidgetMessage;
|
|
741
|
+
};
|
|
742
|
+
type AgentWidgetActionParser = (input: AgentWidgetActionParserInput) => AgentWidgetParsedAction | null | undefined;
|
|
743
|
+
type AgentWidgetActionHandlerResult = {
|
|
744
|
+
handled?: boolean;
|
|
745
|
+
displayText?: string;
|
|
746
|
+
persistMessage?: boolean;
|
|
747
|
+
resubmit?: boolean;
|
|
748
|
+
};
|
|
749
|
+
type AgentWidgetActionContext = {
|
|
750
|
+
message: AgentWidgetMessage;
|
|
751
|
+
metadata: Record<string, unknown>;
|
|
752
|
+
updateMetadata: (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
|
|
753
|
+
document: Document | null;
|
|
754
|
+
/**
|
|
755
|
+
* Trigger automatic model continuation.
|
|
756
|
+
* Call this AFTER completing async operations (e.g., injecting search results)
|
|
757
|
+
* to have the model analyze the injected data.
|
|
758
|
+
*
|
|
759
|
+
* Use this instead of returning `resubmit: true` for handlers that do async work,
|
|
760
|
+
* as it ensures the continuation happens after the data is available in context.
|
|
761
|
+
*
|
|
762
|
+
* @example
|
|
763
|
+
* // In an action handler
|
|
764
|
+
* const results = await fetchProducts(query);
|
|
765
|
+
* session.injectAssistantMessage({ content: formatResults(results) });
|
|
766
|
+
* context.triggerResubmit();
|
|
767
|
+
*/
|
|
768
|
+
triggerResubmit: () => void;
|
|
769
|
+
};
|
|
770
|
+
type AgentWidgetActionHandler = (action: AgentWidgetParsedAction, context: AgentWidgetActionContext) => AgentWidgetActionHandlerResult | void;
|
|
771
|
+
type AgentWidgetStoredState = {
|
|
772
|
+
messages?: AgentWidgetMessage[];
|
|
773
|
+
metadata?: Record<string, unknown>;
|
|
774
|
+
};
|
|
775
|
+
interface AgentWidgetStorageAdapter {
|
|
776
|
+
load?: () => AgentWidgetStoredState | null | Promise<AgentWidgetStoredState | null>;
|
|
777
|
+
save?: (state: AgentWidgetStoredState) => void | Promise<void>;
|
|
778
|
+
clear?: () => void | Promise<void>;
|
|
779
|
+
}
|
|
780
|
+
type AgentWidgetVoiceStateEvent = {
|
|
781
|
+
active: boolean;
|
|
782
|
+
source: "user" | "auto" | "restore" | "system";
|
|
783
|
+
timestamp: number;
|
|
784
|
+
};
|
|
785
|
+
type AgentWidgetActionEventPayload = {
|
|
786
|
+
action: AgentWidgetParsedAction;
|
|
787
|
+
message: AgentWidgetMessage;
|
|
788
|
+
};
|
|
789
|
+
/**
|
|
790
|
+
* Feedback event payload for upvote/downvote actions on messages
|
|
791
|
+
*/
|
|
792
|
+
type AgentWidgetMessageFeedback = {
|
|
793
|
+
type: "upvote" | "downvote";
|
|
794
|
+
messageId: string;
|
|
795
|
+
message: AgentWidgetMessage;
|
|
796
|
+
};
|
|
797
|
+
/**
|
|
798
|
+
* Configuration for message action buttons (copy, upvote, downvote)
|
|
799
|
+
*
|
|
800
|
+
* **Client Token Mode**: When using `clientToken`, feedback is automatically
|
|
801
|
+
* sent to your Runtype backend. Just enable the buttons and you're done!
|
|
802
|
+
* The `onFeedback` and `onCopy` callbacks are optional for additional local handling.
|
|
803
|
+
*
|
|
804
|
+
* @example
|
|
805
|
+
* ```typescript
|
|
806
|
+
* // With clientToken - feedback is automatic!
|
|
807
|
+
* config: {
|
|
808
|
+
* clientToken: 'ct_live_...',
|
|
809
|
+
* messageActions: {
|
|
810
|
+
* showUpvote: true,
|
|
811
|
+
* showDownvote: true,
|
|
812
|
+
* // No onFeedback needed - sent to backend automatically
|
|
813
|
+
* }
|
|
814
|
+
* }
|
|
815
|
+
* ```
|
|
816
|
+
*/
|
|
817
|
+
type AgentWidgetMessageActionsConfig = {
|
|
818
|
+
/**
|
|
819
|
+
* Enable/disable message actions entirely
|
|
820
|
+
* @default true
|
|
821
|
+
*/
|
|
822
|
+
enabled?: boolean;
|
|
823
|
+
/**
|
|
824
|
+
* Show copy button
|
|
825
|
+
* @default true
|
|
826
|
+
*/
|
|
827
|
+
showCopy?: boolean;
|
|
828
|
+
/**
|
|
829
|
+
* Show upvote button.
|
|
830
|
+
* When using `clientToken`, feedback is sent to the backend automatically.
|
|
831
|
+
* @default false
|
|
832
|
+
*/
|
|
833
|
+
showUpvote?: boolean;
|
|
834
|
+
/**
|
|
835
|
+
* Show downvote button.
|
|
836
|
+
* When using `clientToken`, feedback is sent to the backend automatically.
|
|
837
|
+
* @default false
|
|
838
|
+
*/
|
|
839
|
+
showDownvote?: boolean;
|
|
840
|
+
/**
|
|
841
|
+
* Visibility mode: 'always' shows buttons always, 'hover' shows on hover only
|
|
842
|
+
* @default 'hover'
|
|
843
|
+
*/
|
|
844
|
+
visibility?: "always" | "hover";
|
|
845
|
+
/**
|
|
846
|
+
* Horizontal alignment of action buttons
|
|
847
|
+
* @default 'right'
|
|
848
|
+
*/
|
|
849
|
+
align?: "left" | "center" | "right";
|
|
850
|
+
/**
|
|
851
|
+
* Layout style for action buttons
|
|
852
|
+
* - 'pill-inside': Compact floating pill around just the buttons (default for hover)
|
|
853
|
+
* - 'row-inside': Full-width row at the bottom of the message
|
|
854
|
+
* @default 'pill-inside'
|
|
855
|
+
*/
|
|
856
|
+
layout?: "pill-inside" | "row-inside";
|
|
857
|
+
/**
|
|
858
|
+
* Callback when user submits feedback (upvote/downvote).
|
|
859
|
+
*
|
|
860
|
+
* **Note**: When using `clientToken`, feedback is AUTOMATICALLY sent to your
|
|
861
|
+
* backend via `/v1/client/feedback`. This callback is called IN ADDITION to
|
|
862
|
+
* the automatic submission, useful for updating local UI or analytics.
|
|
863
|
+
*/
|
|
864
|
+
onFeedback?: (feedback: AgentWidgetMessageFeedback) => void;
|
|
865
|
+
/**
|
|
866
|
+
* Callback when user copies a message.
|
|
867
|
+
*
|
|
868
|
+
* **Note**: When using `clientToken`, copy events are AUTOMATICALLY tracked
|
|
869
|
+
* via `/v1/client/feedback`. This callback is called IN ADDITION to the
|
|
870
|
+
* automatic tracking.
|
|
871
|
+
*/
|
|
872
|
+
onCopy?: (message: AgentWidgetMessage) => void;
|
|
873
|
+
};
|
|
874
|
+
type AgentWidgetStateEvent = {
|
|
875
|
+
open: boolean;
|
|
876
|
+
source: "user" | "auto" | "api" | "system";
|
|
877
|
+
timestamp: number;
|
|
878
|
+
};
|
|
879
|
+
type AgentWidgetStateSnapshot = {
|
|
880
|
+
open: boolean;
|
|
881
|
+
launcherEnabled: boolean;
|
|
882
|
+
voiceActive: boolean;
|
|
883
|
+
streaming: boolean;
|
|
884
|
+
};
|
|
885
|
+
type AgentWidgetControllerEventMap = {
|
|
886
|
+
"user:message": AgentWidgetMessage;
|
|
887
|
+
"assistant:message": AgentWidgetMessage;
|
|
888
|
+
"assistant:complete": AgentWidgetMessage;
|
|
889
|
+
"voice:state": AgentWidgetVoiceStateEvent;
|
|
890
|
+
"action:detected": AgentWidgetActionEventPayload;
|
|
891
|
+
"action:resubmit": AgentWidgetActionEventPayload;
|
|
892
|
+
"widget:opened": AgentWidgetStateEvent;
|
|
893
|
+
"widget:closed": AgentWidgetStateEvent;
|
|
894
|
+
"widget:state": AgentWidgetStateSnapshot;
|
|
895
|
+
"message:feedback": AgentWidgetMessageFeedback;
|
|
896
|
+
"message:copy": AgentWidgetMessage;
|
|
897
|
+
"eventStream:opened": {
|
|
898
|
+
timestamp: number;
|
|
899
|
+
};
|
|
900
|
+
"eventStream:closed": {
|
|
901
|
+
timestamp: number;
|
|
902
|
+
};
|
|
903
|
+
"approval:requested": {
|
|
904
|
+
approval: AgentWidgetApproval;
|
|
905
|
+
message: AgentWidgetMessage;
|
|
906
|
+
};
|
|
907
|
+
"approval:resolved": {
|
|
908
|
+
approval: AgentWidgetApproval;
|
|
909
|
+
decision: string;
|
|
910
|
+
};
|
|
911
|
+
};
|
|
912
|
+
/**
|
|
913
|
+
* Layout for the artifact split / drawer (CSS lengths unless noted).
|
|
914
|
+
*
|
|
915
|
+
* **Close behavior:** In desktop split mode, the artifact chrome `Close` control uses the same
|
|
916
|
+
* dismiss path as the mobile drawer (`onDismiss` on the artifact pane): the pane is hidden until
|
|
917
|
+
* new artifact content arrives or the host calls `showArtifacts()` on the widget handle.
|
|
918
|
+
*/
|
|
919
|
+
type AgentWidgetArtifactsLayoutConfig = {
|
|
920
|
+
/** Flex gap between chat column and artifact pane. @default 0.5rem */
|
|
921
|
+
splitGap?: string;
|
|
922
|
+
/** Artifact column width in split mode. @default 40% */
|
|
923
|
+
paneWidth?: string;
|
|
924
|
+
/** Max width of artifact column. @default 28rem */
|
|
925
|
+
paneMaxWidth?: string;
|
|
926
|
+
/** Min width of artifact column (optional). */
|
|
927
|
+
paneMinWidth?: string;
|
|
928
|
+
/**
|
|
929
|
+
* When the floating panel is at most this wide (px), use in-panel drawer for artifacts
|
|
930
|
+
* instead of a side-by-side split (viewport can still be wide).
|
|
931
|
+
* @default 520
|
|
932
|
+
*/
|
|
933
|
+
narrowHostMaxWidth?: number;
|
|
934
|
+
/**
|
|
935
|
+
* When true (default), widen the launcher panel while artifacts are visible and not user-dismissed.
|
|
936
|
+
* No-op for inline embed (`launcher.enabled === false`).
|
|
937
|
+
*/
|
|
938
|
+
expandLauncherPanelWhenOpen?: boolean;
|
|
939
|
+
/** Panel width when expanded (launcher + artifacts visible). @default min(720px, calc(100vw - 24px)) */
|
|
940
|
+
expandedPanelWidth?: string;
|
|
941
|
+
/**
|
|
942
|
+
* When true, shows a drag handle between chat and artifact columns in desktop split mode only
|
|
943
|
+
* (hidden in narrow-host drawer and viewport ≤640px). Width is not persisted across reloads.
|
|
944
|
+
*/
|
|
945
|
+
resizable?: boolean;
|
|
946
|
+
/** Min artifact column width while resizing. Only `px` strings are supported. @default 200px */
|
|
947
|
+
resizableMinWidth?: string;
|
|
948
|
+
/** Optional max artifact width cap while resizing (`px` only). Layout still bounds by chat min width. */
|
|
949
|
+
resizableMaxWidth?: string;
|
|
950
|
+
/**
|
|
951
|
+
* Visual treatment for the artifact column in split mode.
|
|
952
|
+
* - `'panel'` — bordered sidebar with left border, gap, and shadow (default).
|
|
953
|
+
* - `'seamless'` — flush with chat: no border or shadow, container background, zero gap.
|
|
954
|
+
* @default 'panel'
|
|
955
|
+
*/
|
|
956
|
+
paneAppearance?: "panel" | "seamless";
|
|
957
|
+
/** Border radius on the artifact pane (CSS length). Works with any `paneAppearance`. */
|
|
958
|
+
paneBorderRadius?: string;
|
|
959
|
+
/** CSS `box-shadow` on the artifact pane. Set `"none"` to suppress the default shadow. */
|
|
960
|
+
paneShadow?: string;
|
|
961
|
+
/**
|
|
962
|
+
* Full `border` shorthand for the artifact `<aside>` (all sides). Overrides default pane borders.
|
|
963
|
+
* Example: `"1px solid #cccccc"`.
|
|
964
|
+
*/
|
|
965
|
+
paneBorder?: string;
|
|
966
|
+
/**
|
|
967
|
+
* `border-left` shorthand only — typical for split view next to chat (with or without resizer).
|
|
968
|
+
* Ignored if `paneBorder` is set. Example: `"1px solid #cccccc"`.
|
|
969
|
+
*/
|
|
970
|
+
paneBorderLeft?: string;
|
|
971
|
+
/**
|
|
972
|
+
* Desktop split only (not narrow-host drawer / not ≤640px): square the **main chat card’s**
|
|
973
|
+
* top-right and bottom-right radii, and round the **artifact pane’s** top-right and bottom-right
|
|
974
|
+
* to match `persona-rounded-2xl` (`--persona-radius-lg`) so the two columns read as one shell.
|
|
975
|
+
*/
|
|
976
|
+
unifiedSplitChrome?: boolean;
|
|
977
|
+
/**
|
|
978
|
+
* When `unifiedSplitChrome` is true, outer-right corner radius on the artifact column (CSS length).
|
|
979
|
+
* @default matches theme large radius (`--persona-radius-lg`)
|
|
980
|
+
*/
|
|
981
|
+
unifiedSplitOuterRadius?: string;
|
|
982
|
+
/**
|
|
983
|
+
* Strongest override: solid background for the artifact column (CSS color). Sets `--persona-artifact-pane-bg`
|
|
984
|
+
* on the widget root. Leave unset to use theme `components.artifact.pane.background` (defaults to semantic
|
|
985
|
+
* container) so light/dark stays consistent.
|
|
986
|
+
*/
|
|
987
|
+
paneBackground?: string;
|
|
988
|
+
/**
|
|
989
|
+
* Horizontal padding for artifact toolbar and content (CSS length), e.g. `24px`.
|
|
990
|
+
*/
|
|
991
|
+
panePadding?: string;
|
|
992
|
+
/**
|
|
993
|
+
* Toolbar layout preset.
|
|
994
|
+
* - `default` — "Artifacts" title, horizontal tabs, text close.
|
|
995
|
+
* - `document` — view/source toggle, document title, copy / refresh / close; tab strip hidden when only one artifact.
|
|
996
|
+
* @default 'default'
|
|
997
|
+
*/
|
|
998
|
+
toolbarPreset?: "default" | "document";
|
|
999
|
+
/**
|
|
1000
|
+
* When `toolbarPreset` is `document`, show a visible "Copy" label next to the copy icon.
|
|
1001
|
+
*/
|
|
1002
|
+
documentToolbarShowCopyLabel?: boolean;
|
|
1003
|
+
/**
|
|
1004
|
+
* When `toolbarPreset` is `document`, show a small chevron after the copy control (e.g. menu affordance).
|
|
1005
|
+
*/
|
|
1006
|
+
documentToolbarShowCopyChevron?: boolean;
|
|
1007
|
+
/** Document toolbar icon buttons (view, code, copy, refresh, close) — CSS color. Sets `--persona-artifact-doc-toolbar-icon-color` on the widget root. */
|
|
1008
|
+
documentToolbarIconColor?: string;
|
|
1009
|
+
/** Active view/source toggle background. Sets `--persona-artifact-doc-toggle-active-bg`. */
|
|
1010
|
+
documentToolbarToggleActiveBackground?: string;
|
|
1011
|
+
/** Active view/source toggle border color. Sets `--persona-artifact-doc-toggle-active-border`. */
|
|
1012
|
+
documentToolbarToggleActiveBorderColor?: string;
|
|
1013
|
+
/**
|
|
1014
|
+
* Invoked when the document toolbar Refresh control is used (before the pane re-renders).
|
|
1015
|
+
* Use to replay `connectStream`, refetch, etc.
|
|
1016
|
+
*/
|
|
1017
|
+
onDocumentToolbarRefresh?: () => void | Promise<void>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Optional copy dropdown entries (shown when `documentToolbarShowCopyChevron` is true and this array is non-empty).
|
|
1020
|
+
* The main Copy control still performs default copy unless `onDocumentToolbarCopyMenuSelect` handles everything.
|
|
1021
|
+
*/
|
|
1022
|
+
documentToolbarCopyMenuItems?: Array<{
|
|
1023
|
+
id: string;
|
|
1024
|
+
label: string;
|
|
1025
|
+
}>;
|
|
1026
|
+
/**
|
|
1027
|
+
* When set, invoked for the chevron menu (and can override default copy per `actionId`).
|
|
1028
|
+
*/
|
|
1029
|
+
onDocumentToolbarCopyMenuSelect?: (payload: {
|
|
1030
|
+
actionId: string;
|
|
1031
|
+
artifactId: string | null;
|
|
1032
|
+
markdown: string;
|
|
1033
|
+
jsonPayload: string;
|
|
1034
|
+
}) => void | Promise<void>;
|
|
1035
|
+
};
|
|
1036
|
+
type AgentWidgetArtifactsFeature = {
|
|
1037
|
+
/** When true, Persona shows the artifact pane and handles artifact_* SSE events */
|
|
1038
|
+
enabled?: boolean;
|
|
1039
|
+
/** If set, artifact events for other types are ignored */
|
|
1040
|
+
allowedTypes?: PersonaArtifactKind[];
|
|
1041
|
+
/** Split / drawer dimensions and launcher widen behavior */
|
|
1042
|
+
layout?: AgentWidgetArtifactsLayoutConfig;
|
|
1043
|
+
/**
|
|
1044
|
+
* Called when an artifact card action is triggered (open, download).
|
|
1045
|
+
* Return `true` to prevent the default behavior.
|
|
1046
|
+
*/
|
|
1047
|
+
onArtifactAction?: (action: {
|
|
1048
|
+
type: 'open' | 'download';
|
|
1049
|
+
artifactId: string;
|
|
1050
|
+
}) => boolean | void;
|
|
1051
|
+
/**
|
|
1052
|
+
* Custom renderer for artifact reference cards shown in the message thread.
|
|
1053
|
+
* Return an HTMLElement to replace the default card, or `null` to use the default.
|
|
1054
|
+
*/
|
|
1055
|
+
renderCard?: (context: {
|
|
1056
|
+
artifact: {
|
|
1057
|
+
artifactId: string;
|
|
1058
|
+
title: string;
|
|
1059
|
+
artifactType: string;
|
|
1060
|
+
status: string;
|
|
1061
|
+
};
|
|
1062
|
+
config: AgentWidgetConfig;
|
|
1063
|
+
defaultRenderer: () => HTMLElement;
|
|
1064
|
+
}) => HTMLElement | null;
|
|
1065
|
+
};
|
|
1066
|
+
type AgentWidgetFeatureFlags = {
|
|
1067
|
+
showReasoning?: boolean;
|
|
1068
|
+
showToolCalls?: boolean;
|
|
1069
|
+
showEventStreamToggle?: boolean;
|
|
1070
|
+
/** Configuration for the Event Stream inspector view */
|
|
1071
|
+
eventStream?: EventStreamConfig;
|
|
1072
|
+
/** Optional artifact sidebar (split pane / mobile drawer) */
|
|
1073
|
+
artifacts?: AgentWidgetArtifactsFeature;
|
|
1074
|
+
};
|
|
1075
|
+
type SSEEventRecord = {
|
|
1076
|
+
id: string;
|
|
1077
|
+
type: string;
|
|
1078
|
+
timestamp: number;
|
|
1079
|
+
payload: string;
|
|
1080
|
+
};
|
|
1081
|
+
/**
|
|
1082
|
+
* Badge color configuration for event stream event types.
|
|
1083
|
+
*/
|
|
1084
|
+
type EventStreamBadgeColor = {
|
|
1085
|
+
/** Background color (CSS value) */
|
|
1086
|
+
bg: string;
|
|
1087
|
+
/** Text color (CSS value) */
|
|
1088
|
+
text: string;
|
|
1089
|
+
};
|
|
1090
|
+
/**
|
|
1091
|
+
* Configuration for the Event Stream inspector view.
|
|
1092
|
+
*/
|
|
1093
|
+
type EventStreamConfig = {
|
|
1094
|
+
/**
|
|
1095
|
+
* Custom badge color mappings by event type prefix or exact type.
|
|
1096
|
+
* Keys are matched as exact match first, then prefix match (keys ending with "_").
|
|
1097
|
+
* @example { "flow_": { bg: "#dcfce7", text: "#166534" }, "error": { bg: "#fecaca", text: "#991b1b" } }
|
|
1098
|
+
*/
|
|
1099
|
+
badgeColors?: Record<string, EventStreamBadgeColor>;
|
|
1100
|
+
/**
|
|
1101
|
+
* Timestamp display format.
|
|
1102
|
+
* - "relative": Shows time offset from first event (+0.000s, +0.361s)
|
|
1103
|
+
* - "absolute": Shows wall-clock time (HH:MM:SS.mmm)
|
|
1104
|
+
* @default "relative"
|
|
1105
|
+
*/
|
|
1106
|
+
timestampFormat?: "absolute" | "relative";
|
|
1107
|
+
/**
|
|
1108
|
+
* Whether to show sequential event numbers (1, 2, 3...).
|
|
1109
|
+
* @default true
|
|
1110
|
+
*/
|
|
1111
|
+
showSequenceNumbers?: boolean;
|
|
1112
|
+
/**
|
|
1113
|
+
* Maximum events to keep in the ring buffer.
|
|
1114
|
+
* @default 500
|
|
1115
|
+
*/
|
|
1116
|
+
maxEvents?: number;
|
|
1117
|
+
/**
|
|
1118
|
+
* Fields to extract from event payloads for description text.
|
|
1119
|
+
* The first matching field value is displayed after the badge.
|
|
1120
|
+
* @default ["flowName", "stepName", "name", "tool", "toolName"]
|
|
1121
|
+
*/
|
|
1122
|
+
descriptionFields?: string[];
|
|
1123
|
+
/**
|
|
1124
|
+
* Custom CSS class names to append to event stream UI elements.
|
|
1125
|
+
* Each value is a space-separated class string appended to the element's default classes.
|
|
1126
|
+
*/
|
|
1127
|
+
classNames?: {
|
|
1128
|
+
/** The toggle button in the widget header (activity icon). */
|
|
1129
|
+
toggleButton?: string;
|
|
1130
|
+
/** Additional classes applied to the toggle button when the event stream is open. */
|
|
1131
|
+
toggleButtonActive?: string;
|
|
1132
|
+
/** The outer event stream panel/container. */
|
|
1133
|
+
panel?: string;
|
|
1134
|
+
/** The toolbar header bar (title, filter, copy all). */
|
|
1135
|
+
headerBar?: string;
|
|
1136
|
+
/** The search bar wrapper. */
|
|
1137
|
+
searchBar?: string;
|
|
1138
|
+
/** The search text input. */
|
|
1139
|
+
searchInput?: string;
|
|
1140
|
+
/** Each event row wrapper. */
|
|
1141
|
+
eventRow?: string;
|
|
1142
|
+
/** The "new events" scroll indicator pill. */
|
|
1143
|
+
scrollIndicator?: string;
|
|
1144
|
+
};
|
|
1145
|
+
};
|
|
1146
|
+
/**
|
|
1147
|
+
* Context for the renderEventStreamView plugin hook.
|
|
1148
|
+
*/
|
|
1149
|
+
type EventStreamViewRenderContext = {
|
|
1150
|
+
config: AgentWidgetConfig;
|
|
1151
|
+
events: SSEEventRecord[];
|
|
1152
|
+
defaultRenderer: () => HTMLElement;
|
|
1153
|
+
onClose?: () => void;
|
|
1154
|
+
};
|
|
1155
|
+
/**
|
|
1156
|
+
* Context for the renderEventStreamRow plugin hook.
|
|
1157
|
+
*/
|
|
1158
|
+
type EventStreamRowRenderContext = {
|
|
1159
|
+
event: SSEEventRecord;
|
|
1160
|
+
index: number;
|
|
1161
|
+
config: AgentWidgetConfig;
|
|
1162
|
+
defaultRenderer: () => HTMLElement;
|
|
1163
|
+
isExpanded: boolean;
|
|
1164
|
+
onToggleExpand: () => void;
|
|
1165
|
+
};
|
|
1166
|
+
/**
|
|
1167
|
+
* Context for the renderEventStreamToolbar plugin hook.
|
|
1168
|
+
*/
|
|
1169
|
+
type EventStreamToolbarRenderContext = {
|
|
1170
|
+
config: AgentWidgetConfig;
|
|
1171
|
+
defaultRenderer: () => HTMLElement;
|
|
1172
|
+
eventCount: number;
|
|
1173
|
+
filteredCount: number;
|
|
1174
|
+
onFilterChange: (type: string) => void;
|
|
1175
|
+
onSearchChange: (term: string) => void;
|
|
1176
|
+
};
|
|
1177
|
+
/**
|
|
1178
|
+
* Context for the renderEventStreamPayload plugin hook.
|
|
1179
|
+
*/
|
|
1180
|
+
type EventStreamPayloadRenderContext = {
|
|
1181
|
+
event: SSEEventRecord;
|
|
1182
|
+
config: AgentWidgetConfig;
|
|
1183
|
+
defaultRenderer: () => HTMLElement;
|
|
1184
|
+
parsedPayload: unknown;
|
|
1185
|
+
};
|
|
1186
|
+
type AgentWidgetDockConfig = {
|
|
1187
|
+
/**
|
|
1188
|
+
* Side of the wrapped container where the docked panel should render.
|
|
1189
|
+
* @default "right"
|
|
1190
|
+
*/
|
|
1191
|
+
side?: "left" | "right";
|
|
1192
|
+
/**
|
|
1193
|
+
* Expanded width of the docked panel.
|
|
1194
|
+
* @default "420px"
|
|
1195
|
+
*/
|
|
1196
|
+
width?: string;
|
|
1197
|
+
/**
|
|
1198
|
+
* When false, the dock column snaps between `0` and `width` with no CSS transition so main
|
|
1199
|
+
* content does not reflow during the open/close animation.
|
|
1200
|
+
* @default true
|
|
1201
|
+
*/
|
|
1202
|
+
animate?: boolean;
|
|
1203
|
+
/**
|
|
1204
|
+
* How the dock panel is shown.
|
|
1205
|
+
* - `"resize"` (default): a flex column grows/shrinks between `0` and `width` (main content reflows).
|
|
1206
|
+
* - `"overlay"`: panel is absolutely positioned and translates in/out **over** full-width content.
|
|
1207
|
+
* - `"push"`: a wide inner track `[content at shell width][panel]` translates horizontally so the panel
|
|
1208
|
+
* appears to push the workspace aside **without** animating the content column width (Shopify-style).
|
|
1209
|
+
* - `"emerge"`: like `"resize"`, the flex column animates so **page content reflows**; the chat
|
|
1210
|
+
* panel keeps a **fixed** `dock.width` (not squeezed while the column grows), clipped by the slot so
|
|
1211
|
+
* it appears to emerge at full width like a floating widget.
|
|
1212
|
+
*/
|
|
1213
|
+
reveal?: "resize" | "overlay" | "push" | "emerge";
|
|
1214
|
+
};
|
|
1215
|
+
type AgentWidgetLauncherConfig = {
|
|
1216
|
+
enabled?: boolean;
|
|
1217
|
+
title?: string;
|
|
1218
|
+
subtitle?: string;
|
|
1219
|
+
textHidden?: boolean;
|
|
1220
|
+
iconUrl?: string;
|
|
1221
|
+
agentIconText?: string;
|
|
1222
|
+
agentIconName?: string;
|
|
1223
|
+
agentIconHidden?: boolean;
|
|
1224
|
+
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
1225
|
+
/**
|
|
1226
|
+
* Controls how the launcher panel is mounted relative to the host page.
|
|
1227
|
+
* - "floating": default floating launcher / panel behavior
|
|
1228
|
+
* - "docked": wraps the target container and renders as a sibling dock
|
|
1229
|
+
*
|
|
1230
|
+
* @default "floating"
|
|
1231
|
+
*/
|
|
1232
|
+
mountMode?: "floating" | "docked";
|
|
1233
|
+
/**
|
|
1234
|
+
* Layout configuration for docked mode.
|
|
1235
|
+
*/
|
|
1236
|
+
dock?: AgentWidgetDockConfig;
|
|
1237
|
+
autoExpand?: boolean;
|
|
1238
|
+
width?: string;
|
|
1239
|
+
/**
|
|
1240
|
+
* When true, the widget panel will fill the full height of its container.
|
|
1241
|
+
* Useful for sidebar layouts where the chat should take up the entire viewport height.
|
|
1242
|
+
* The widget will use flex layout to ensure header stays at top, messages scroll in middle,
|
|
1243
|
+
* and composer stays fixed at bottom.
|
|
1244
|
+
*
|
|
1245
|
+
* @default false
|
|
1246
|
+
*/
|
|
1247
|
+
fullHeight?: boolean;
|
|
1248
|
+
/**
|
|
1249
|
+
* When true, the widget panel will be positioned as a sidebar flush with the viewport edges.
|
|
1250
|
+
* The panel will have:
|
|
1251
|
+
* - No border-radius (square corners)
|
|
1252
|
+
* - No margins (flush with top, left/right, and bottom edges)
|
|
1253
|
+
* - Full viewport height
|
|
1254
|
+
* - Subtle shadow on the edge facing the content
|
|
1255
|
+
* - No border between footer and messages
|
|
1256
|
+
*
|
|
1257
|
+
* Use with `position` to control which side ('bottom-left' for left sidebar, 'bottom-right' for right sidebar).
|
|
1258
|
+
* Automatically enables fullHeight when true.
|
|
1259
|
+
*
|
|
1260
|
+
* @default false
|
|
1261
|
+
*/
|
|
1262
|
+
sidebarMode?: boolean;
|
|
1263
|
+
/**
|
|
1264
|
+
* Width of the sidebar panel when sidebarMode is true.
|
|
1265
|
+
* @default "420px"
|
|
1266
|
+
*/
|
|
1267
|
+
sidebarWidth?: string;
|
|
1268
|
+
/**
|
|
1269
|
+
* Offset (in pixels) to subtract from the calculated panel height.
|
|
1270
|
+
* Useful for adjusting the panel height when there are other fixed elements on the page.
|
|
1271
|
+
* Only applies when not in fullHeight or sidebarMode.
|
|
1272
|
+
*
|
|
1273
|
+
* @default 0
|
|
1274
|
+
*/
|
|
1275
|
+
heightOffset?: number;
|
|
1276
|
+
/**
|
|
1277
|
+
* When true, the widget panel expands to fill the full viewport on mobile devices.
|
|
1278
|
+
* Removes border-radius, margins, and shadows for a native app-like experience.
|
|
1279
|
+
* Applies when viewport width is at or below `mobileBreakpoint`.
|
|
1280
|
+
*
|
|
1281
|
+
* @default true
|
|
1282
|
+
*/
|
|
1283
|
+
mobileFullscreen?: boolean;
|
|
1284
|
+
/**
|
|
1285
|
+
* Viewport width (in pixels) at or below which the widget enters mobile fullscreen mode.
|
|
1286
|
+
* Only applies when `mobileFullscreen` is true.
|
|
1287
|
+
*
|
|
1288
|
+
* @default 640
|
|
1289
|
+
*/
|
|
1290
|
+
mobileBreakpoint?: number;
|
|
1291
|
+
/**
|
|
1292
|
+
* CSS z-index applied to the widget wrapper when it is in a positioned mode
|
|
1293
|
+
* (floating panel, mobile fullscreen, or sidebar). Increase this value if
|
|
1294
|
+
* other elements on the host page appear on top of the widget.
|
|
1295
|
+
*
|
|
1296
|
+
* @default 9999 in overlay modes (mobile fullscreen / sidebar); 50 for the regular floating panel
|
|
1297
|
+
*/
|
|
1298
|
+
zIndex?: number;
|
|
1299
|
+
callToActionIconText?: string;
|
|
1300
|
+
callToActionIconName?: string;
|
|
1301
|
+
callToActionIconColor?: string;
|
|
1302
|
+
callToActionIconBackgroundColor?: string;
|
|
1303
|
+
callToActionIconHidden?: boolean;
|
|
1304
|
+
callToActionIconPadding?: string;
|
|
1305
|
+
agentIconSize?: string;
|
|
1306
|
+
callToActionIconSize?: string;
|
|
1307
|
+
headerIconSize?: string;
|
|
1308
|
+
headerIconName?: string;
|
|
1309
|
+
headerIconHidden?: boolean;
|
|
1310
|
+
closeButtonSize?: string;
|
|
1311
|
+
closeButtonColor?: string;
|
|
1312
|
+
closeButtonBackgroundColor?: string;
|
|
1313
|
+
closeButtonBorderWidth?: string;
|
|
1314
|
+
closeButtonBorderColor?: string;
|
|
1315
|
+
closeButtonBorderRadius?: string;
|
|
1316
|
+
closeButtonPaddingX?: string;
|
|
1317
|
+
closeButtonPaddingY?: string;
|
|
1318
|
+
closeButtonPlacement?: "inline" | "top-right";
|
|
1319
|
+
closeButtonIconName?: string;
|
|
1320
|
+
closeButtonIconText?: string;
|
|
1321
|
+
closeButtonTooltipText?: string;
|
|
1322
|
+
closeButtonShowTooltip?: boolean;
|
|
1323
|
+
clearChat?: AgentWidgetClearChatConfig;
|
|
1324
|
+
/**
|
|
1325
|
+
* Border style for the launcher button.
|
|
1326
|
+
* @example "1px solid #e5e7eb" | "2px solid #3b82f6" | "none"
|
|
1327
|
+
* @default "1px solid #e5e7eb"
|
|
1328
|
+
*/
|
|
1329
|
+
border?: string;
|
|
1330
|
+
/**
|
|
1331
|
+
* Box shadow for the launcher button.
|
|
1332
|
+
* @example "0 10px 15px -3px rgba(0,0,0,0.1)" | "none"
|
|
1333
|
+
* @default "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)"
|
|
1334
|
+
*/
|
|
1335
|
+
shadow?: string;
|
|
1336
|
+
/**
|
|
1337
|
+
* CSS `max-width` for the floating launcher button when the panel is closed.
|
|
1338
|
+
* Title and subtitle each truncate with an ellipsis when space is tight; full strings are available via the native `title` tooltip. Does not affect the open chat panel (`width` / `launcherWidth`).
|
|
1339
|
+
*
|
|
1340
|
+
* @example "min(380px, calc(100vw - 48px))"
|
|
1341
|
+
*/
|
|
1342
|
+
collapsedMaxWidth?: string;
|
|
1343
|
+
};
|
|
1344
|
+
type AgentWidgetSendButtonConfig = {
|
|
1345
|
+
borderWidth?: string;
|
|
1346
|
+
borderColor?: string;
|
|
1347
|
+
paddingX?: string;
|
|
1348
|
+
paddingY?: string;
|
|
1349
|
+
iconText?: string;
|
|
1350
|
+
iconName?: string;
|
|
1351
|
+
useIcon?: boolean;
|
|
1352
|
+
tooltipText?: string;
|
|
1353
|
+
showTooltip?: boolean;
|
|
1354
|
+
backgroundColor?: string;
|
|
1355
|
+
textColor?: string;
|
|
1356
|
+
size?: string;
|
|
1357
|
+
};
|
|
1358
|
+
/** Optional composer UI state for custom `renderComposer` implementations. */
|
|
1359
|
+
type AgentWidgetComposerConfig = {
|
|
1360
|
+
models?: Array<{
|
|
1361
|
+
id: string;
|
|
1362
|
+
label: string;
|
|
1363
|
+
}>;
|
|
1364
|
+
/** Current selection; host or plugin may update this at runtime. */
|
|
1365
|
+
selectedModelId?: string;
|
|
1366
|
+
};
|
|
1367
|
+
type AgentWidgetClearChatConfig = {
|
|
1368
|
+
enabled?: boolean;
|
|
1369
|
+
placement?: "inline" | "top-right";
|
|
1370
|
+
iconName?: string;
|
|
1371
|
+
iconColor?: string;
|
|
1372
|
+
backgroundColor?: string;
|
|
1373
|
+
borderWidth?: string;
|
|
1374
|
+
borderColor?: string;
|
|
1375
|
+
borderRadius?: string;
|
|
1376
|
+
size?: string;
|
|
1377
|
+
paddingX?: string;
|
|
1378
|
+
paddingY?: string;
|
|
1379
|
+
tooltipText?: string;
|
|
1380
|
+
showTooltip?: boolean;
|
|
1381
|
+
};
|
|
1382
|
+
type AgentWidgetStatusIndicatorConfig = {
|
|
1383
|
+
visible?: boolean;
|
|
1384
|
+
/** Text alignment. Default: 'right'. */
|
|
1385
|
+
align?: 'left' | 'center' | 'right';
|
|
1386
|
+
idleText?: string;
|
|
1387
|
+
/** URL to open in a new tab when the idle text is clicked. */
|
|
1388
|
+
idleLink?: string;
|
|
1389
|
+
connectingText?: string;
|
|
1390
|
+
connectedText?: string;
|
|
1391
|
+
errorText?: string;
|
|
1392
|
+
};
|
|
1393
|
+
type AgentWidgetVoiceRecognitionConfig = {
|
|
1394
|
+
enabled?: boolean;
|
|
1395
|
+
pauseDuration?: number;
|
|
1396
|
+
/** Text shown in the user message placeholder while voice is being processed. Default: "🎤 Processing voice..." */
|
|
1397
|
+
processingText?: string;
|
|
1398
|
+
/** Text shown in the assistant message if voice processing fails. Default: "Voice processing failed. Please try again." */
|
|
1399
|
+
processingErrorText?: string;
|
|
1400
|
+
iconName?: string;
|
|
1401
|
+
iconSize?: string;
|
|
1402
|
+
iconColor?: string;
|
|
1403
|
+
backgroundColor?: string;
|
|
1404
|
+
borderColor?: string;
|
|
1405
|
+
borderWidth?: string;
|
|
1406
|
+
paddingX?: string;
|
|
1407
|
+
paddingY?: string;
|
|
1408
|
+
tooltipText?: string;
|
|
1409
|
+
showTooltip?: boolean;
|
|
1410
|
+
recordingIconColor?: string;
|
|
1411
|
+
recordingBackgroundColor?: string;
|
|
1412
|
+
recordingBorderColor?: string;
|
|
1413
|
+
showRecordingIndicator?: boolean;
|
|
1414
|
+
/** Icon name shown while processing voice input. Default: "loader" */
|
|
1415
|
+
processingIconName?: string;
|
|
1416
|
+
/** Icon color during processing. Inherits idle iconColor if not set */
|
|
1417
|
+
processingIconColor?: string;
|
|
1418
|
+
/** Button background color during processing. Inherits idle backgroundColor if not set */
|
|
1419
|
+
processingBackgroundColor?: string;
|
|
1420
|
+
/** Button border color during processing. Inherits idle borderColor if not set */
|
|
1421
|
+
processingBorderColor?: string;
|
|
1422
|
+
/** Icon name shown while agent is speaking. Default: "volume-2" (or "square" in cancel mode) */
|
|
1423
|
+
speakingIconName?: string;
|
|
1424
|
+
/** Icon color while speaking. Inherits idle iconColor if not set */
|
|
1425
|
+
speakingIconColor?: string;
|
|
1426
|
+
/** Button background color while speaking. Inherits idle backgroundColor if not set */
|
|
1427
|
+
speakingBackgroundColor?: string;
|
|
1428
|
+
/** Button border color while speaking. Inherits idle borderColor if not set */
|
|
1429
|
+
speakingBorderColor?: string;
|
|
1430
|
+
autoResume?: boolean | "assistant";
|
|
1431
|
+
provider?: {
|
|
1432
|
+
type: 'browser' | 'runtype' | 'custom';
|
|
1433
|
+
browser?: {
|
|
1434
|
+
language?: string;
|
|
1435
|
+
continuous?: boolean;
|
|
1436
|
+
};
|
|
1437
|
+
runtype?: {
|
|
1438
|
+
agentId: string;
|
|
1439
|
+
clientToken: string;
|
|
1440
|
+
host?: string;
|
|
1441
|
+
voiceId?: string;
|
|
1442
|
+
/** Duration of silence (ms) before auto-stopping recording. Default: 2000 */
|
|
1443
|
+
pauseDuration?: number;
|
|
1444
|
+
/** RMS volume threshold below which counts as silence. Default: 0.01 */
|
|
1445
|
+
silenceThreshold?: number;
|
|
1446
|
+
};
|
|
1447
|
+
custom?: any;
|
|
1448
|
+
};
|
|
1449
|
+
};
|
|
1450
|
+
/**
|
|
1451
|
+
* Text-to-speech configuration for reading assistant messages aloud.
|
|
1452
|
+
* Currently supports the Web Speech API (`speechSynthesis`).
|
|
1453
|
+
*
|
|
1454
|
+
* @example
|
|
1455
|
+
* ```typescript
|
|
1456
|
+
* textToSpeech: {
|
|
1457
|
+
* enabled: true,
|
|
1458
|
+
* provider: 'browser',
|
|
1459
|
+
* voice: 'Google US English',
|
|
1460
|
+
* rate: 1.2,
|
|
1461
|
+
* pitch: 1.0
|
|
1462
|
+
* }
|
|
1463
|
+
* ```
|
|
1464
|
+
*/
|
|
1465
|
+
type TextToSpeechConfig = {
|
|
1466
|
+
/** Enable text-to-speech for assistant messages */
|
|
1467
|
+
enabled: boolean;
|
|
1468
|
+
/**
|
|
1469
|
+
* TTS provider.
|
|
1470
|
+
* - `'browser'` — Use the Web Speech API for all assistant messages (default).
|
|
1471
|
+
* - `'runtype'` — Server handles TTS for voice interactions.
|
|
1472
|
+
* Set `browserFallback: true` to also speak text-typed responses via the browser.
|
|
1473
|
+
*/
|
|
1474
|
+
provider?: 'browser' | 'runtype';
|
|
1475
|
+
/**
|
|
1476
|
+
* When `provider` is `'runtype'`, fall back to browser TTS for assistant
|
|
1477
|
+
* messages that the server didn't already speak (e.g. text-typed messages).
|
|
1478
|
+
* Has no effect when provider is `'browser'` (browser TTS is always used).
|
|
1479
|
+
* @default false
|
|
1480
|
+
*/
|
|
1481
|
+
browserFallback?: boolean;
|
|
1482
|
+
/** Voice name to use for browser TTS (e.g., 'Google US English'). If not found, uses auto-detect. */
|
|
1483
|
+
voice?: string;
|
|
1484
|
+
/**
|
|
1485
|
+
* Custom voice picker called when `voice` is not set.
|
|
1486
|
+
* Receives the full list of available `SpeechSynthesisVoice` objects and
|
|
1487
|
+
* should return the one to use. If not provided, the SDK auto-detects the
|
|
1488
|
+
* best English voice.
|
|
1489
|
+
*
|
|
1490
|
+
* @example
|
|
1491
|
+
* ```typescript
|
|
1492
|
+
* pickVoice: (voices) => voices.find(v => v.lang === 'fr-FR') ?? voices[0]
|
|
1493
|
+
* ```
|
|
1494
|
+
*/
|
|
1495
|
+
pickVoice?: (voices: SpeechSynthesisVoice[]) => SpeechSynthesisVoice;
|
|
1496
|
+
/** Speech rate (0.1 - 10). Default: 1 */
|
|
1497
|
+
rate?: number;
|
|
1498
|
+
/** Speech pitch (0 - 2). Default: 1 */
|
|
1499
|
+
pitch?: number;
|
|
1500
|
+
};
|
|
1501
|
+
/**
|
|
1502
|
+
* Configuration for tool approval bubbles.
|
|
1503
|
+
* Controls styling, labels, and behavior of the approval UI.
|
|
1504
|
+
*/
|
|
1505
|
+
type AgentWidgetApprovalConfig = {
|
|
1506
|
+
/** Background color of the approval bubble */
|
|
1507
|
+
backgroundColor?: string;
|
|
1508
|
+
/** Border color of the approval bubble */
|
|
1509
|
+
borderColor?: string;
|
|
1510
|
+
/** Color for the title text */
|
|
1511
|
+
titleColor?: string;
|
|
1512
|
+
/** Color for the description text */
|
|
1513
|
+
descriptionColor?: string;
|
|
1514
|
+
/** Background color for the approve button */
|
|
1515
|
+
approveButtonColor?: string;
|
|
1516
|
+
/** Text color for the approve button */
|
|
1517
|
+
approveButtonTextColor?: string;
|
|
1518
|
+
/** Background color for the deny button */
|
|
1519
|
+
denyButtonColor?: string;
|
|
1520
|
+
/** Text color for the deny button */
|
|
1521
|
+
denyButtonTextColor?: string;
|
|
1522
|
+
/** Background color for the parameters block */
|
|
1523
|
+
parameterBackgroundColor?: string;
|
|
1524
|
+
/** Text color for the parameters block */
|
|
1525
|
+
parameterTextColor?: string;
|
|
1526
|
+
/** Title text displayed above the description */
|
|
1527
|
+
title?: string;
|
|
1528
|
+
/** Label for the approve button */
|
|
1529
|
+
approveLabel?: string;
|
|
1530
|
+
/** Label for the deny button */
|
|
1531
|
+
denyLabel?: string;
|
|
1532
|
+
/**
|
|
1533
|
+
* Custom handler for approval decisions.
|
|
1534
|
+
* Return void to let the SDK auto-resolve via the API,
|
|
1535
|
+
* or return a Response/ReadableStream for custom handling.
|
|
1536
|
+
*/
|
|
1537
|
+
onDecision?: (data: {
|
|
1538
|
+
approvalId: string;
|
|
1539
|
+
executionId: string;
|
|
1540
|
+
agentId: string;
|
|
1541
|
+
toolName: string;
|
|
1542
|
+
}, decision: 'approved' | 'denied') => Promise<Response | ReadableStream<Uint8Array> | void>;
|
|
1543
|
+
};
|
|
1544
|
+
type AgentWidgetToolCallConfig$1 = {
|
|
1545
|
+
/** Box-shadow for tool-call bubbles; overrides `theme.toolBubbleShadow` when set. */
|
|
1546
|
+
shadow?: string;
|
|
1547
|
+
backgroundColor?: string;
|
|
1548
|
+
borderColor?: string;
|
|
1549
|
+
borderWidth?: string;
|
|
1550
|
+
borderRadius?: string;
|
|
1551
|
+
headerBackgroundColor?: string;
|
|
1552
|
+
headerTextColor?: string;
|
|
1553
|
+
headerPaddingX?: string;
|
|
1554
|
+
headerPaddingY?: string;
|
|
1555
|
+
contentBackgroundColor?: string;
|
|
1556
|
+
contentTextColor?: string;
|
|
1557
|
+
contentPaddingX?: string;
|
|
1558
|
+
contentPaddingY?: string;
|
|
1559
|
+
codeBlockBackgroundColor?: string;
|
|
1560
|
+
codeBlockBorderColor?: string;
|
|
1561
|
+
codeBlockTextColor?: string;
|
|
1562
|
+
toggleTextColor?: string;
|
|
1563
|
+
labelTextColor?: string;
|
|
1564
|
+
};
|
|
1565
|
+
type AgentWidgetSuggestionChipsConfig = {
|
|
1566
|
+
fontFamily?: "sans-serif" | "serif" | "mono";
|
|
1567
|
+
fontWeight?: string;
|
|
1568
|
+
paddingX?: string;
|
|
1569
|
+
paddingY?: string;
|
|
1570
|
+
};
|
|
1571
|
+
/**
|
|
1572
|
+
* Interface for pluggable stream parsers that extract text from streaming responses.
|
|
1573
|
+
* Parsers handle incremental parsing to extract text values from structured formats (JSON, XML, etc.).
|
|
1574
|
+
*
|
|
1575
|
+
* @example
|
|
1576
|
+
* ```typescript
|
|
1577
|
+
* const jsonParser: AgentWidgetStreamParser = {
|
|
1578
|
+
* processChunk: async (content) => {
|
|
1579
|
+
* // Extract text from JSON - return null if not JSON or text not available yet
|
|
1580
|
+
* if (!content.trim().startsWith('{')) return null;
|
|
1581
|
+
* const match = content.match(/"text"\s*:\s*"([^"]*)"/);
|
|
1582
|
+
* return match ? match[1] : null;
|
|
1583
|
+
* },
|
|
1584
|
+
* getExtractedText: () => extractedText
|
|
1585
|
+
* };
|
|
1586
|
+
* ```
|
|
1587
|
+
*/
|
|
1588
|
+
interface AgentWidgetStreamParserResult {
|
|
1589
|
+
/**
|
|
1590
|
+
* The extracted text to display (may be partial during streaming)
|
|
1591
|
+
*/
|
|
1592
|
+
text: string | null;
|
|
1593
|
+
/**
|
|
1594
|
+
* The raw accumulated content. Built-in parsers always populate this so
|
|
1595
|
+
* downstream middleware (action handlers, logging, etc.) can
|
|
1596
|
+
* inspect/parse the original structured payload.
|
|
1597
|
+
*/
|
|
1598
|
+
raw?: string;
|
|
1599
|
+
}
|
|
1600
|
+
interface AgentWidgetStreamParser {
|
|
1601
|
+
/**
|
|
1602
|
+
* Process a chunk of content and return the extracted text (if available).
|
|
1603
|
+
* This method is called for each chunk as it arrives during streaming.
|
|
1604
|
+
* Return null if the content doesn't match this parser's format or if text is not yet available.
|
|
1605
|
+
*
|
|
1606
|
+
* @param accumulatedContent - The full accumulated content so far (including new chunk)
|
|
1607
|
+
* @returns The extracted text value and optionally raw content, or null if not yet available or format doesn't match
|
|
1608
|
+
*/
|
|
1609
|
+
processChunk(accumulatedContent: string): Promise<AgentWidgetStreamParserResult | string | null> | AgentWidgetStreamParserResult | string | null;
|
|
1610
|
+
/**
|
|
1611
|
+
* Get the currently extracted text value (may be partial).
|
|
1612
|
+
* This is called synchronously to get the latest extracted text without processing.
|
|
1613
|
+
*
|
|
1614
|
+
* @returns The currently extracted text value, or null if not yet available
|
|
1615
|
+
*/
|
|
1616
|
+
getExtractedText(): string | null;
|
|
1617
|
+
/**
|
|
1618
|
+
* Clean up any resources when parsing is complete.
|
|
1619
|
+
*/
|
|
1620
|
+
close?(): Promise<void> | void;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Component renderer function signature for custom components
|
|
1624
|
+
*/
|
|
1625
|
+
type AgentWidgetComponentRenderer = (props: Record<string, unknown>, context: {
|
|
1626
|
+
message: AgentWidgetMessage;
|
|
1627
|
+
config: AgentWidgetConfig;
|
|
1628
|
+
updateProps: (newProps: Record<string, unknown>) => void;
|
|
1629
|
+
}) => HTMLElement;
|
|
1630
|
+
/**
|
|
1631
|
+
* Result from custom SSE event parser
|
|
1632
|
+
*/
|
|
1633
|
+
type AgentWidgetSSEEventResult = {
|
|
1634
|
+
/** Text content to display */
|
|
1635
|
+
text?: string;
|
|
1636
|
+
/** Whether the stream is complete */
|
|
1637
|
+
done?: boolean;
|
|
1638
|
+
/** Error message if an error occurred */
|
|
1639
|
+
error?: string;
|
|
1640
|
+
/** Text segment identity — when this changes, a new assistant message bubble is created */
|
|
1641
|
+
partId?: string;
|
|
1642
|
+
} | null;
|
|
1643
|
+
/**
|
|
1644
|
+
* Custom SSE event parser function
|
|
1645
|
+
* Allows transforming non-standard SSE event formats to persona's expected format
|
|
1646
|
+
*/
|
|
1647
|
+
type AgentWidgetSSEEventParser = (eventData: unknown) => AgentWidgetSSEEventResult | Promise<AgentWidgetSSEEventResult>;
|
|
1648
|
+
/**
|
|
1649
|
+
* Custom fetch function for full control over API requests
|
|
1650
|
+
* Use this for custom authentication, request transformation, etc.
|
|
1651
|
+
*/
|
|
1652
|
+
type AgentWidgetCustomFetch = (url: string, init: RequestInit, payload: AgentWidgetRequestPayload) => Promise<Response>;
|
|
1653
|
+
/**
|
|
1654
|
+
* Dynamic headers function - called before each request
|
|
1655
|
+
*/
|
|
1656
|
+
type AgentWidgetHeadersFunction = () => Record<string, string> | Promise<Record<string, string>>;
|
|
1657
|
+
/**
|
|
1658
|
+
* Session information returned after client token initialization.
|
|
1659
|
+
* Contains session ID, expiry time, flow info, and config from the server.
|
|
1660
|
+
*/
|
|
1661
|
+
type ClientSession = {
|
|
1662
|
+
/** Unique session identifier */
|
|
1663
|
+
sessionId: string;
|
|
1664
|
+
/** When the session expires */
|
|
1665
|
+
expiresAt: Date;
|
|
1666
|
+
/** Flow information */
|
|
1667
|
+
flow: {
|
|
1668
|
+
id: string;
|
|
1669
|
+
name: string;
|
|
1670
|
+
description: string | null;
|
|
1671
|
+
};
|
|
1672
|
+
/** Configuration from the server */
|
|
1673
|
+
config: {
|
|
1674
|
+
welcomeMessage: string | null;
|
|
1675
|
+
placeholder: string;
|
|
1676
|
+
theme: Record<string, unknown> | null;
|
|
1677
|
+
};
|
|
1678
|
+
};
|
|
1679
|
+
/** Icon button in the header title row (minimal layout). */
|
|
1680
|
+
type AgentWidgetHeaderTrailingAction = {
|
|
1681
|
+
id: string;
|
|
1682
|
+
/** Lucide icon name, e.g. `chevron-down` */
|
|
1683
|
+
icon?: string;
|
|
1684
|
+
label?: string;
|
|
1685
|
+
ariaLabel?: string;
|
|
1686
|
+
/**
|
|
1687
|
+
* When set, clicking this action opens a dropdown menu.
|
|
1688
|
+
* Menu item selections fire `onAction(menuItemId)`.
|
|
1689
|
+
*/
|
|
1690
|
+
menuItems?: Array<{
|
|
1691
|
+
id: string;
|
|
1692
|
+
label: string;
|
|
1693
|
+
icon?: string;
|
|
1694
|
+
destructive?: boolean;
|
|
1695
|
+
dividerBefore?: boolean;
|
|
1696
|
+
}>;
|
|
1697
|
+
};
|
|
1698
|
+
/**
|
|
1699
|
+
* Context provided to header render functions
|
|
1700
|
+
*/
|
|
1701
|
+
type HeaderRenderContext = {
|
|
1702
|
+
config: AgentWidgetConfig;
|
|
1703
|
+
onClose?: () => void;
|
|
1704
|
+
onClearChat?: () => void;
|
|
1705
|
+
/** Built from `layout.header.trailingActions` for custom `render` implementations. */
|
|
1706
|
+
trailingActions?: AgentWidgetHeaderTrailingAction[];
|
|
1707
|
+
/** Fired when a built-in trailing action is activated (same as `layout.header.onAction`). */
|
|
1708
|
+
onAction?: (actionId: string) => void;
|
|
1709
|
+
};
|
|
1710
|
+
/**
|
|
1711
|
+
* Context provided to message render functions
|
|
1712
|
+
*/
|
|
1713
|
+
type MessageRenderContext = {
|
|
1714
|
+
message: AgentWidgetMessage;
|
|
1715
|
+
config: AgentWidgetConfig;
|
|
1716
|
+
streaming: boolean;
|
|
1717
|
+
};
|
|
1718
|
+
/**
|
|
1719
|
+
* Context provided to slot render functions
|
|
1720
|
+
*/
|
|
1721
|
+
type SlotRenderContext = {
|
|
1722
|
+
config: AgentWidgetConfig;
|
|
1723
|
+
defaultContent: () => HTMLElement | null;
|
|
1724
|
+
};
|
|
1725
|
+
/**
|
|
1726
|
+
* Header layout configuration
|
|
1727
|
+
* Allows customization of the header section appearance and behavior
|
|
1728
|
+
*/
|
|
1729
|
+
type AgentWidgetHeaderLayoutConfig = {
|
|
1730
|
+
/**
|
|
1731
|
+
* Layout preset: "default" | "minimal"
|
|
1732
|
+
* - default: Standard layout with icon, title, subtitle, and buttons
|
|
1733
|
+
* - minimal: Simplified layout with just title and close button
|
|
1734
|
+
*/
|
|
1735
|
+
layout?: "default" | "minimal";
|
|
1736
|
+
/** Show/hide the header icon */
|
|
1737
|
+
showIcon?: boolean;
|
|
1738
|
+
/** Show/hide the title */
|
|
1739
|
+
showTitle?: boolean;
|
|
1740
|
+
/** Show/hide the subtitle */
|
|
1741
|
+
showSubtitle?: boolean;
|
|
1742
|
+
/** Show/hide the close button */
|
|
1743
|
+
showCloseButton?: boolean;
|
|
1744
|
+
/** Show/hide the clear chat button */
|
|
1745
|
+
showClearChat?: boolean;
|
|
1746
|
+
/**
|
|
1747
|
+
* Custom renderer for complete header override
|
|
1748
|
+
* When provided, replaces the entire header with custom content
|
|
1749
|
+
*/
|
|
1750
|
+
render?: (context: HeaderRenderContext) => HTMLElement;
|
|
1751
|
+
/**
|
|
1752
|
+
* Shown after the title in `minimal` header layout (e.g. chevron menu affordance).
|
|
1753
|
+
*/
|
|
1754
|
+
trailingActions?: AgentWidgetHeaderTrailingAction[];
|
|
1755
|
+
/** Called when a `trailingActions` button is clicked. */
|
|
1756
|
+
onAction?: (actionId: string) => void;
|
|
1757
|
+
/**
|
|
1758
|
+
* Called when the header title row is clicked.
|
|
1759
|
+
* Useful for dropdown menus or navigation triggered from the header.
|
|
1760
|
+
* When set, the title row becomes visually interactive (cursor: pointer).
|
|
1761
|
+
*/
|
|
1762
|
+
onTitleClick?: () => void;
|
|
1763
|
+
/** Style config for the title row hover effect (minimal layout). */
|
|
1764
|
+
titleRowHover?: {
|
|
1765
|
+
/** Hover background color. */
|
|
1766
|
+
background?: string;
|
|
1767
|
+
/** Hover border color. */
|
|
1768
|
+
border?: string;
|
|
1769
|
+
/** Border radius for the pill shape. */
|
|
1770
|
+
borderRadius?: string;
|
|
1771
|
+
/** Padding inside the pill. */
|
|
1772
|
+
padding?: string;
|
|
1773
|
+
};
|
|
1774
|
+
/**
|
|
1775
|
+
* Replaces the title with a combo button (label + chevron + dropdown menu).
|
|
1776
|
+
* When set, `trailingActions`, `onTitleClick`, and `titleRowHover` are ignored
|
|
1777
|
+
* since the combo button handles all of these internally.
|
|
1778
|
+
*/
|
|
1779
|
+
titleMenu?: {
|
|
1780
|
+
/** Dropdown menu items. */
|
|
1781
|
+
menuItems: Array<{
|
|
1782
|
+
id: string;
|
|
1783
|
+
label: string;
|
|
1784
|
+
icon?: string;
|
|
1785
|
+
destructive?: boolean;
|
|
1786
|
+
dividerBefore?: boolean;
|
|
1787
|
+
}>;
|
|
1788
|
+
/** Called when a menu item is selected. */
|
|
1789
|
+
onSelect: (id: string) => void;
|
|
1790
|
+
/** Hover pill style. */
|
|
1791
|
+
hover?: {
|
|
1792
|
+
background?: string;
|
|
1793
|
+
border?: string;
|
|
1794
|
+
borderRadius?: string;
|
|
1795
|
+
padding?: string;
|
|
1796
|
+
};
|
|
1797
|
+
};
|
|
1798
|
+
};
|
|
1799
|
+
/**
|
|
1800
|
+
* Avatar configuration for message bubbles
|
|
1801
|
+
*/
|
|
1802
|
+
type AgentWidgetAvatarConfig = {
|
|
1803
|
+
/** Whether to show avatars */
|
|
1804
|
+
show?: boolean;
|
|
1805
|
+
/** Position of avatar relative to message bubble */
|
|
1806
|
+
position?: "left" | "right";
|
|
1807
|
+
/** URL or emoji for user avatar */
|
|
1808
|
+
userAvatar?: string;
|
|
1809
|
+
/** URL or emoji for assistant avatar */
|
|
1810
|
+
assistantAvatar?: string;
|
|
1811
|
+
};
|
|
1812
|
+
/**
|
|
1813
|
+
* Timestamp configuration for message bubbles
|
|
1814
|
+
*/
|
|
1815
|
+
type AgentWidgetTimestampConfig = {
|
|
1816
|
+
/** Whether to show timestamps */
|
|
1817
|
+
show?: boolean;
|
|
1818
|
+
/** Position of timestamp relative to message */
|
|
1819
|
+
position?: "inline" | "below";
|
|
1820
|
+
/** Custom formatter for timestamp display */
|
|
1821
|
+
format?: (date: Date) => string;
|
|
1822
|
+
};
|
|
1823
|
+
/**
|
|
1824
|
+
* Message layout configuration
|
|
1825
|
+
* Allows customization of how chat messages are displayed
|
|
1826
|
+
*/
|
|
1827
|
+
type AgentWidgetMessageLayoutConfig = {
|
|
1828
|
+
/**
|
|
1829
|
+
* Layout preset: "bubble" | "flat" | "minimal"
|
|
1830
|
+
* - bubble: Standard chat bubble appearance (default)
|
|
1831
|
+
* - flat: Flat messages without bubble styling
|
|
1832
|
+
* - minimal: Minimal styling with reduced padding/borders
|
|
1833
|
+
*/
|
|
1834
|
+
layout?: "bubble" | "flat" | "minimal";
|
|
1835
|
+
/** Avatar configuration */
|
|
1836
|
+
avatar?: AgentWidgetAvatarConfig;
|
|
1837
|
+
/** Timestamp configuration */
|
|
1838
|
+
timestamp?: AgentWidgetTimestampConfig;
|
|
1839
|
+
/** Group consecutive messages from the same role */
|
|
1840
|
+
groupConsecutive?: boolean;
|
|
1841
|
+
/**
|
|
1842
|
+
* Custom renderer for user messages
|
|
1843
|
+
* When provided, replaces the default user message rendering
|
|
1844
|
+
*/
|
|
1845
|
+
renderUserMessage?: (context: MessageRenderContext) => HTMLElement;
|
|
1846
|
+
/**
|
|
1847
|
+
* Custom renderer for assistant messages
|
|
1848
|
+
* When provided, replaces the default assistant message rendering
|
|
1849
|
+
*/
|
|
1850
|
+
renderAssistantMessage?: (context: MessageRenderContext) => HTMLElement;
|
|
1851
|
+
};
|
|
1852
|
+
/**
|
|
1853
|
+
* Available layout slots for content injection
|
|
1854
|
+
*/
|
|
1855
|
+
type WidgetLayoutSlot = "header-left" | "header-center" | "header-right" | "body-top" | "messages" | "body-bottom" | "footer-top" | "composer" | "footer-bottom";
|
|
1856
|
+
/**
|
|
1857
|
+
* Slot renderer function signature
|
|
1858
|
+
* Returns HTMLElement to render in the slot, or null to use default content
|
|
1859
|
+
*/
|
|
1860
|
+
type SlotRenderer = (context: SlotRenderContext) => HTMLElement | null;
|
|
1861
|
+
/**
|
|
1862
|
+
* Main layout configuration
|
|
1863
|
+
* Provides comprehensive control over widget layout and appearance
|
|
1864
|
+
*
|
|
1865
|
+
* @example
|
|
1866
|
+
* ```typescript
|
|
1867
|
+
* config: {
|
|
1868
|
+
* layout: {
|
|
1869
|
+
* header: { layout: "minimal" },
|
|
1870
|
+
* messages: {
|
|
1871
|
+
* avatar: { show: true, assistantAvatar: "/bot.png" },
|
|
1872
|
+
* timestamp: { show: true, position: "below" }
|
|
1873
|
+
* },
|
|
1874
|
+
* slots: {
|
|
1875
|
+
* "footer-top": () => {
|
|
1876
|
+
* const el = document.createElement("div");
|
|
1877
|
+
* el.textContent = "Powered by AI";
|
|
1878
|
+
* return el;
|
|
1879
|
+
* }
|
|
1880
|
+
* }
|
|
1881
|
+
* }
|
|
1882
|
+
* }
|
|
1883
|
+
* ```
|
|
1884
|
+
*/
|
|
1885
|
+
type AgentWidgetLayoutConfig = {
|
|
1886
|
+
/** Header layout configuration */
|
|
1887
|
+
header?: AgentWidgetHeaderLayoutConfig;
|
|
1888
|
+
/** Message layout configuration */
|
|
1889
|
+
messages?: AgentWidgetMessageLayoutConfig;
|
|
1890
|
+
/** Slot renderers for custom content injection */
|
|
1891
|
+
slots?: Partial<Record<WidgetLayoutSlot, SlotRenderer>>;
|
|
1892
|
+
/**
|
|
1893
|
+
* Show/hide the header section entirely.
|
|
1894
|
+
* When false, the header (including icon, title, buttons) is completely hidden.
|
|
1895
|
+
* @default true
|
|
1896
|
+
*/
|
|
1897
|
+
showHeader?: boolean;
|
|
1898
|
+
/**
|
|
1899
|
+
* Show/hide the footer/composer section entirely.
|
|
1900
|
+
* When false, the footer (including input field, send button, suggestions) is completely hidden.
|
|
1901
|
+
* Useful for read-only conversation previews.
|
|
1902
|
+
* @default true
|
|
1903
|
+
*/
|
|
1904
|
+
showFooter?: boolean;
|
|
1905
|
+
/**
|
|
1906
|
+
* Max width for the content area (messages + composer).
|
|
1907
|
+
* Applied with `margin: 0 auto` for centering.
|
|
1908
|
+
* Accepts any CSS width value (e.g. "90ch", "720px", "80%").
|
|
1909
|
+
*/
|
|
1910
|
+
contentMaxWidth?: string;
|
|
1911
|
+
};
|
|
1912
|
+
/**
|
|
1913
|
+
* Token types for marked renderer methods
|
|
1914
|
+
*/
|
|
1915
|
+
type AgentWidgetMarkdownHeadingToken = {
|
|
1916
|
+
type: "heading";
|
|
1917
|
+
raw: string;
|
|
1918
|
+
depth: 1 | 2 | 3 | 4 | 5 | 6;
|
|
1919
|
+
text: string;
|
|
1920
|
+
tokens: unknown[];
|
|
1921
|
+
};
|
|
1922
|
+
type AgentWidgetMarkdownCodeToken = {
|
|
1923
|
+
type: "code";
|
|
1924
|
+
raw: string;
|
|
1925
|
+
text: string;
|
|
1926
|
+
lang?: string;
|
|
1927
|
+
escaped?: boolean;
|
|
1928
|
+
};
|
|
1929
|
+
type AgentWidgetMarkdownBlockquoteToken = {
|
|
1930
|
+
type: "blockquote";
|
|
1931
|
+
raw: string;
|
|
1932
|
+
text: string;
|
|
1933
|
+
tokens: unknown[];
|
|
1934
|
+
};
|
|
1935
|
+
type AgentWidgetMarkdownTableToken = {
|
|
1936
|
+
type: "table";
|
|
1937
|
+
raw: string;
|
|
1938
|
+
header: Array<{
|
|
1939
|
+
text: string;
|
|
1940
|
+
tokens: unknown[];
|
|
1941
|
+
}>;
|
|
1942
|
+
rows: Array<Array<{
|
|
1943
|
+
text: string;
|
|
1944
|
+
tokens: unknown[];
|
|
1945
|
+
}>>;
|
|
1946
|
+
align: Array<"left" | "center" | "right" | null>;
|
|
1947
|
+
};
|
|
1948
|
+
type AgentWidgetMarkdownLinkToken = {
|
|
1949
|
+
type: "link";
|
|
1950
|
+
raw: string;
|
|
1951
|
+
href: string;
|
|
1952
|
+
title: string | null;
|
|
1953
|
+
text: string;
|
|
1954
|
+
tokens: unknown[];
|
|
1955
|
+
};
|
|
1956
|
+
type AgentWidgetMarkdownImageToken = {
|
|
1957
|
+
type: "image";
|
|
1958
|
+
raw: string;
|
|
1959
|
+
href: string;
|
|
1960
|
+
title: string | null;
|
|
1961
|
+
text: string;
|
|
1962
|
+
};
|
|
1963
|
+
type AgentWidgetMarkdownListToken = {
|
|
1964
|
+
type: "list";
|
|
1965
|
+
raw: string;
|
|
1966
|
+
ordered: boolean;
|
|
1967
|
+
start: number | "";
|
|
1968
|
+
loose: boolean;
|
|
1969
|
+
items: unknown[];
|
|
1970
|
+
};
|
|
1971
|
+
type AgentWidgetMarkdownListItemToken = {
|
|
1972
|
+
type: "list_item";
|
|
1973
|
+
raw: string;
|
|
1974
|
+
task: boolean;
|
|
1975
|
+
checked?: boolean;
|
|
1976
|
+
loose: boolean;
|
|
1977
|
+
text: string;
|
|
1978
|
+
tokens: unknown[];
|
|
1979
|
+
};
|
|
1980
|
+
type AgentWidgetMarkdownParagraphToken = {
|
|
1981
|
+
type: "paragraph";
|
|
1982
|
+
raw: string;
|
|
1983
|
+
text: string;
|
|
1984
|
+
tokens: unknown[];
|
|
1985
|
+
};
|
|
1986
|
+
type AgentWidgetMarkdownCodespanToken = {
|
|
1987
|
+
type: "codespan";
|
|
1988
|
+
raw: string;
|
|
1989
|
+
text: string;
|
|
1990
|
+
};
|
|
1991
|
+
type AgentWidgetMarkdownStrongToken = {
|
|
1992
|
+
type: "strong";
|
|
1993
|
+
raw: string;
|
|
1994
|
+
text: string;
|
|
1995
|
+
tokens: unknown[];
|
|
1996
|
+
};
|
|
1997
|
+
type AgentWidgetMarkdownEmToken = {
|
|
1998
|
+
type: "em";
|
|
1999
|
+
raw: string;
|
|
2000
|
+
text: string;
|
|
2001
|
+
tokens: unknown[];
|
|
2002
|
+
};
|
|
2003
|
+
/**
|
|
2004
|
+
* Custom renderer overrides for markdown elements.
|
|
2005
|
+
* Each method receives the token and should return an HTML string.
|
|
2006
|
+
* Return `false` to use the default renderer.
|
|
2007
|
+
*
|
|
2008
|
+
* @example
|
|
2009
|
+
* ```typescript
|
|
2010
|
+
* renderer: {
|
|
2011
|
+
* heading(token) {
|
|
2012
|
+
* return `<h${token.depth} class="custom-heading">${token.text}</h${token.depth}>`;
|
|
2013
|
+
* },
|
|
2014
|
+
* link(token) {
|
|
2015
|
+
* return `<a href="${token.href}" target="_blank" rel="noopener">${token.text}</a>`;
|
|
2016
|
+
* }
|
|
2017
|
+
* }
|
|
2018
|
+
* ```
|
|
2019
|
+
*/
|
|
2020
|
+
type AgentWidgetMarkdownRendererOverrides = {
|
|
2021
|
+
/** Override heading rendering (h1-h6) */
|
|
2022
|
+
heading?: (token: AgentWidgetMarkdownHeadingToken) => string | false;
|
|
2023
|
+
/** Override code block rendering */
|
|
2024
|
+
code?: (token: AgentWidgetMarkdownCodeToken) => string | false;
|
|
2025
|
+
/** Override blockquote rendering */
|
|
2026
|
+
blockquote?: (token: AgentWidgetMarkdownBlockquoteToken) => string | false;
|
|
2027
|
+
/** Override table rendering */
|
|
2028
|
+
table?: (token: AgentWidgetMarkdownTableToken) => string | false;
|
|
2029
|
+
/** Override link rendering */
|
|
2030
|
+
link?: (token: AgentWidgetMarkdownLinkToken) => string | false;
|
|
2031
|
+
/** Override image rendering */
|
|
2032
|
+
image?: (token: AgentWidgetMarkdownImageToken) => string | false;
|
|
2033
|
+
/** Override list rendering (ul/ol) */
|
|
2034
|
+
list?: (token: AgentWidgetMarkdownListToken) => string | false;
|
|
2035
|
+
/** Override list item rendering */
|
|
2036
|
+
listitem?: (token: AgentWidgetMarkdownListItemToken) => string | false;
|
|
2037
|
+
/** Override paragraph rendering */
|
|
2038
|
+
paragraph?: (token: AgentWidgetMarkdownParagraphToken) => string | false;
|
|
2039
|
+
/** Override inline code rendering */
|
|
2040
|
+
codespan?: (token: AgentWidgetMarkdownCodespanToken) => string | false;
|
|
2041
|
+
/** Override strong/bold rendering */
|
|
2042
|
+
strong?: (token: AgentWidgetMarkdownStrongToken) => string | false;
|
|
2043
|
+
/** Override emphasis/italic rendering */
|
|
2044
|
+
em?: (token: AgentWidgetMarkdownEmToken) => string | false;
|
|
2045
|
+
/** Override horizontal rule rendering */
|
|
2046
|
+
hr?: () => string | false;
|
|
2047
|
+
/** Override line break rendering */
|
|
2048
|
+
br?: () => string | false;
|
|
2049
|
+
/** Override deleted/strikethrough rendering */
|
|
2050
|
+
del?: (token: {
|
|
2051
|
+
type: "del";
|
|
2052
|
+
raw: string;
|
|
2053
|
+
text: string;
|
|
2054
|
+
tokens: unknown[];
|
|
2055
|
+
}) => string | false;
|
|
2056
|
+
/** Override checkbox rendering (in task lists) */
|
|
2057
|
+
checkbox?: (token: {
|
|
2058
|
+
checked: boolean;
|
|
2059
|
+
}) => string | false;
|
|
2060
|
+
/** Override HTML passthrough */
|
|
2061
|
+
html?: (token: {
|
|
2062
|
+
type: "html";
|
|
2063
|
+
raw: string;
|
|
2064
|
+
text: string;
|
|
2065
|
+
}) => string | false;
|
|
2066
|
+
/** Override text rendering */
|
|
2067
|
+
text?: (token: {
|
|
2068
|
+
type: "text";
|
|
2069
|
+
raw: string;
|
|
2070
|
+
text: string;
|
|
2071
|
+
}) => string | false;
|
|
2072
|
+
};
|
|
2073
|
+
/**
|
|
2074
|
+
* Markdown parsing options (subset of marked options)
|
|
2075
|
+
*/
|
|
2076
|
+
type AgentWidgetMarkdownOptions = {
|
|
2077
|
+
/**
|
|
2078
|
+
* Enable GitHub Flavored Markdown (tables, strikethrough, autolinks).
|
|
2079
|
+
* @default true
|
|
2080
|
+
*/
|
|
2081
|
+
gfm?: boolean;
|
|
2082
|
+
/**
|
|
2083
|
+
* Convert \n in paragraphs into <br>.
|
|
2084
|
+
* @default true
|
|
2085
|
+
*/
|
|
2086
|
+
breaks?: boolean;
|
|
2087
|
+
/**
|
|
2088
|
+
* Conform to original markdown.pl as much as possible.
|
|
2089
|
+
* @default false
|
|
2090
|
+
*/
|
|
2091
|
+
pedantic?: boolean;
|
|
2092
|
+
/**
|
|
2093
|
+
* Add id attributes to headings.
|
|
2094
|
+
* @default false
|
|
2095
|
+
*/
|
|
2096
|
+
headerIds?: boolean;
|
|
2097
|
+
/**
|
|
2098
|
+
* Prefix for heading id attributes.
|
|
2099
|
+
* @default ""
|
|
2100
|
+
*/
|
|
2101
|
+
headerPrefix?: string;
|
|
2102
|
+
/**
|
|
2103
|
+
* Mangle email addresses for spam protection.
|
|
2104
|
+
* @default true
|
|
2105
|
+
*/
|
|
2106
|
+
mangle?: boolean;
|
|
2107
|
+
/**
|
|
2108
|
+
* Silent mode - don't throw on parse errors.
|
|
2109
|
+
* @default false
|
|
2110
|
+
*/
|
|
2111
|
+
silent?: boolean;
|
|
2112
|
+
};
|
|
2113
|
+
/**
|
|
2114
|
+
* Markdown configuration for customizing how markdown is rendered in chat messages.
|
|
2115
|
+
* Provides three levels of control:
|
|
2116
|
+
*
|
|
2117
|
+
* 1. **CSS Variables** - Override styles via `--cw-md-*` CSS custom properties
|
|
2118
|
+
* 2. **Parsing Options** - Configure marked behavior via `options`
|
|
2119
|
+
* 3. **Custom Renderers** - Full control via `renderer` overrides
|
|
2120
|
+
*
|
|
2121
|
+
* @example
|
|
2122
|
+
* ```typescript
|
|
2123
|
+
* // Level 2: Configure parsing options
|
|
2124
|
+
* config: {
|
|
2125
|
+
* markdown: {
|
|
2126
|
+
* options: {
|
|
2127
|
+
* gfm: true,
|
|
2128
|
+
* breaks: true,
|
|
2129
|
+
* headerIds: true
|
|
2130
|
+
* }
|
|
2131
|
+
* }
|
|
2132
|
+
* }
|
|
2133
|
+
* ```
|
|
2134
|
+
*
|
|
2135
|
+
* @example
|
|
2136
|
+
* ```typescript
|
|
2137
|
+
* // Level 3: Custom renderers
|
|
2138
|
+
* config: {
|
|
2139
|
+
* markdown: {
|
|
2140
|
+
* renderer: {
|
|
2141
|
+
* heading(token) {
|
|
2142
|
+
* return `<h${token.depth} class="custom-h${token.depth}">${token.text}</h${token.depth}>`;
|
|
2143
|
+
* },
|
|
2144
|
+
* link(token) {
|
|
2145
|
+
* return `<a href="${token.href}" target="_blank">${token.text}</a>`;
|
|
2146
|
+
* },
|
|
2147
|
+
* table(token) {
|
|
2148
|
+
* // Wrap tables in a scrollable container
|
|
2149
|
+
* return `<div class="table-scroll">${this.parser.parse(token.tokens)}</div>`;
|
|
2150
|
+
* }
|
|
2151
|
+
* }
|
|
2152
|
+
* }
|
|
2153
|
+
* }
|
|
2154
|
+
* ```
|
|
2155
|
+
*/
|
|
2156
|
+
type AgentWidgetMarkdownConfig = {
|
|
2157
|
+
/**
|
|
2158
|
+
* Markdown parsing options.
|
|
2159
|
+
* These are passed directly to the marked parser.
|
|
2160
|
+
*/
|
|
2161
|
+
options?: AgentWidgetMarkdownOptions;
|
|
2162
|
+
/**
|
|
2163
|
+
* Custom renderer overrides for specific markdown elements.
|
|
2164
|
+
* Each method receives a token object and should return an HTML string.
|
|
2165
|
+
* Return `false` to fall back to the default renderer.
|
|
2166
|
+
*/
|
|
2167
|
+
renderer?: AgentWidgetMarkdownRendererOverrides;
|
|
2168
|
+
/**
|
|
2169
|
+
* Disable default markdown CSS styles.
|
|
2170
|
+
* When true, the widget won't apply any default styles to markdown elements,
|
|
2171
|
+
* allowing you to provide your own CSS.
|
|
2172
|
+
*
|
|
2173
|
+
* @default false
|
|
2174
|
+
*/
|
|
2175
|
+
disableDefaultStyles?: boolean;
|
|
2176
|
+
};
|
|
2177
|
+
/**
|
|
2178
|
+
* Configuration for file attachments in the composer.
|
|
2179
|
+
* Enables users to attach images to their messages.
|
|
2180
|
+
*
|
|
2181
|
+
* @example
|
|
2182
|
+
* ```typescript
|
|
2183
|
+
* config: {
|
|
2184
|
+
* attachments: {
|
|
2185
|
+
* enabled: true,
|
|
2186
|
+
* allowedTypes: ['image/png', 'image/jpeg', 'image/gif', 'image/webp'],
|
|
2187
|
+
* maxFileSize: 5 * 1024 * 1024, // 5MB
|
|
2188
|
+
* maxFiles: 4
|
|
2189
|
+
* }
|
|
2190
|
+
* }
|
|
2191
|
+
* ```
|
|
2192
|
+
*/
|
|
2193
|
+
type AgentWidgetAttachmentsConfig = {
|
|
2194
|
+
/**
|
|
2195
|
+
* Enable/disable file attachments.
|
|
2196
|
+
* @default false
|
|
2197
|
+
*/
|
|
2198
|
+
enabled?: boolean;
|
|
2199
|
+
/**
|
|
2200
|
+
* Allowed MIME types for attachments.
|
|
2201
|
+
* @default ['image/png', 'image/jpeg', 'image/gif', 'image/webp']
|
|
2202
|
+
*/
|
|
2203
|
+
allowedTypes?: string[];
|
|
2204
|
+
/**
|
|
2205
|
+
* Maximum file size in bytes.
|
|
2206
|
+
* @default 10485760 (10MB)
|
|
2207
|
+
*/
|
|
2208
|
+
maxFileSize?: number;
|
|
2209
|
+
/**
|
|
2210
|
+
* Maximum number of files per message.
|
|
2211
|
+
* @default 4
|
|
2212
|
+
*/
|
|
2213
|
+
maxFiles?: number;
|
|
2214
|
+
/**
|
|
2215
|
+
* Button icon name (from Lucide icons).
|
|
2216
|
+
* @default 'image-plus'
|
|
2217
|
+
*/
|
|
2218
|
+
buttonIconName?: string;
|
|
2219
|
+
/**
|
|
2220
|
+
* Tooltip text for the attachment button.
|
|
2221
|
+
* @default 'Attach image'
|
|
2222
|
+
*/
|
|
2223
|
+
buttonTooltipText?: string;
|
|
2224
|
+
/**
|
|
2225
|
+
* Callback when a file is rejected (wrong type or too large).
|
|
2226
|
+
*/
|
|
2227
|
+
onFileRejected?: (file: File, reason: 'type' | 'size' | 'count') => void;
|
|
2228
|
+
};
|
|
2229
|
+
/**
|
|
2230
|
+
* Configuration for persisting widget state across page navigations.
|
|
2231
|
+
* Stores open/closed state, voice recognition state, and voice mode in browser storage.
|
|
2232
|
+
*
|
|
2233
|
+
* @example
|
|
2234
|
+
* ```typescript
|
|
2235
|
+
* config: {
|
|
2236
|
+
* persistState: true // Use defaults: sessionStorage, persist open state
|
|
2237
|
+
* }
|
|
2238
|
+
* ```
|
|
2239
|
+
*
|
|
2240
|
+
* @example
|
|
2241
|
+
* ```typescript
|
|
2242
|
+
* config: {
|
|
2243
|
+
* persistState: {
|
|
2244
|
+
* storage: 'local', // Use localStorage instead of sessionStorage
|
|
2245
|
+
* keyPrefix: 'myapp-', // Custom prefix for storage keys
|
|
2246
|
+
* persist: {
|
|
2247
|
+
* openState: true,
|
|
2248
|
+
* voiceState: true,
|
|
2249
|
+
* focusInput: true
|
|
2250
|
+
* },
|
|
2251
|
+
* clearOnChatClear: true
|
|
2252
|
+
* }
|
|
2253
|
+
* }
|
|
2254
|
+
* ```
|
|
2255
|
+
*/
|
|
2256
|
+
type AgentWidgetPersistStateConfig = {
|
|
2257
|
+
/**
|
|
2258
|
+
* Storage type to use.
|
|
2259
|
+
* @default 'session'
|
|
2260
|
+
*/
|
|
2261
|
+
storage?: 'local' | 'session';
|
|
2262
|
+
/**
|
|
2263
|
+
* Prefix for storage keys.
|
|
2264
|
+
* @default 'persona-'
|
|
2265
|
+
*/
|
|
2266
|
+
keyPrefix?: string;
|
|
2267
|
+
/**
|
|
2268
|
+
* What state to persist.
|
|
2269
|
+
*/
|
|
2270
|
+
persist?: {
|
|
2271
|
+
/**
|
|
2272
|
+
* Persist widget open/closed state.
|
|
2273
|
+
* @default true
|
|
2274
|
+
*/
|
|
2275
|
+
openState?: boolean;
|
|
2276
|
+
/**
|
|
2277
|
+
* Persist voice recognition state.
|
|
2278
|
+
* @default true
|
|
2279
|
+
*/
|
|
2280
|
+
voiceState?: boolean;
|
|
2281
|
+
/**
|
|
2282
|
+
* Focus input when restoring open state.
|
|
2283
|
+
* @default true
|
|
2284
|
+
*/
|
|
2285
|
+
focusInput?: boolean;
|
|
2286
|
+
};
|
|
2287
|
+
/**
|
|
2288
|
+
* Clear persisted state when chat is cleared.
|
|
2289
|
+
* @default true
|
|
2290
|
+
*/
|
|
2291
|
+
clearOnChatClear?: boolean;
|
|
2292
|
+
};
|
|
2293
|
+
/**
|
|
2294
|
+
* Context provided to loading indicator render functions.
|
|
2295
|
+
* Used for customizing the loading indicator appearance.
|
|
2296
|
+
*/
|
|
2297
|
+
type LoadingIndicatorRenderContext = {
|
|
2298
|
+
/**
|
|
2299
|
+
* Full widget configuration for accessing theme, etc.
|
|
2300
|
+
*/
|
|
2301
|
+
config: AgentWidgetConfig;
|
|
2302
|
+
/**
|
|
2303
|
+
* Current streaming state (always true when indicator is shown)
|
|
2304
|
+
*/
|
|
2305
|
+
streaming: boolean;
|
|
2306
|
+
/**
|
|
2307
|
+
* Location where the indicator is rendered:
|
|
2308
|
+
* - 'inline': Inside a streaming assistant message bubble (when content is empty)
|
|
2309
|
+
* - 'standalone': Separate bubble while waiting for stream to start
|
|
2310
|
+
*/
|
|
2311
|
+
location: 'inline' | 'standalone';
|
|
2312
|
+
/**
|
|
2313
|
+
* Function to render the default 3-dot bouncing indicator.
|
|
2314
|
+
* Call this if you want to use the default for certain cases.
|
|
2315
|
+
*/
|
|
2316
|
+
defaultRenderer: () => HTMLElement;
|
|
2317
|
+
};
|
|
2318
|
+
/**
|
|
2319
|
+
* Context provided to idle indicator render functions.
|
|
2320
|
+
* Used for customizing the idle state indicator appearance.
|
|
2321
|
+
*/
|
|
2322
|
+
type IdleIndicatorRenderContext = {
|
|
2323
|
+
/**
|
|
2324
|
+
* Full widget configuration for accessing theme, etc.
|
|
2325
|
+
*/
|
|
2326
|
+
config: AgentWidgetConfig;
|
|
2327
|
+
/**
|
|
2328
|
+
* The last message in the conversation (if any).
|
|
2329
|
+
* Useful for conditional rendering based on who spoke last.
|
|
2330
|
+
*/
|
|
2331
|
+
lastMessage: AgentWidgetMessage | undefined;
|
|
2332
|
+
/**
|
|
2333
|
+
* Total number of messages in the conversation.
|
|
2334
|
+
*/
|
|
2335
|
+
messageCount: number;
|
|
2336
|
+
};
|
|
2337
|
+
/**
|
|
2338
|
+
* Configuration for customizing the loading indicator.
|
|
2339
|
+
* The loading indicator is shown while waiting for a response or
|
|
2340
|
+
* when an assistant message is streaming but has no content yet.
|
|
2341
|
+
*
|
|
2342
|
+
* @example
|
|
2343
|
+
* ```typescript
|
|
2344
|
+
* // Custom animated spinner
|
|
2345
|
+
* config: {
|
|
2346
|
+
* loadingIndicator: {
|
|
2347
|
+
* render: ({ location }) => {
|
|
2348
|
+
* const el = document.createElement('div');
|
|
2349
|
+
* el.innerHTML = '<svg class="spinner">...</svg>';
|
|
2350
|
+
* el.setAttribute('data-preserve-animation', 'true');
|
|
2351
|
+
* return el;
|
|
2352
|
+
* }
|
|
2353
|
+
* }
|
|
2354
|
+
* }
|
|
2355
|
+
* ```
|
|
2356
|
+
*
|
|
2357
|
+
* @example
|
|
2358
|
+
* ```typescript
|
|
2359
|
+
* // Different indicators by location
|
|
2360
|
+
* config: {
|
|
2361
|
+
* loadingIndicator: {
|
|
2362
|
+
* render: ({ location, defaultRenderer }) => {
|
|
2363
|
+
* if (location === 'inline') {
|
|
2364
|
+
* return defaultRenderer(); // Use default for inline
|
|
2365
|
+
* }
|
|
2366
|
+
* // Custom for standalone
|
|
2367
|
+
* const el = document.createElement('div');
|
|
2368
|
+
* el.textContent = 'Thinking...';
|
|
2369
|
+
* return el;
|
|
2370
|
+
* }
|
|
2371
|
+
* }
|
|
2372
|
+
* }
|
|
2373
|
+
* ```
|
|
2374
|
+
*
|
|
2375
|
+
* @example
|
|
2376
|
+
* ```typescript
|
|
2377
|
+
* // Hide loading indicator entirely
|
|
2378
|
+
* config: {
|
|
2379
|
+
* loadingIndicator: {
|
|
2380
|
+
* render: () => null
|
|
2381
|
+
* }
|
|
2382
|
+
* }
|
|
2383
|
+
* ```
|
|
2384
|
+
*/
|
|
2385
|
+
type AgentWidgetLoadingIndicatorConfig = {
|
|
2386
|
+
/**
|
|
2387
|
+
* Whether to show the bubble background and border around the standalone loading indicator.
|
|
2388
|
+
* Set to false to render the loading indicator without any bubble styling.
|
|
2389
|
+
* @default true
|
|
2390
|
+
*/
|
|
2391
|
+
showBubble?: boolean;
|
|
2392
|
+
/**
|
|
2393
|
+
* Custom render function for the loading indicator.
|
|
2394
|
+
* Return an HTMLElement to display, or null to hide the indicator.
|
|
2395
|
+
*
|
|
2396
|
+
* For custom animations, add `data-preserve-animation="true"` attribute
|
|
2397
|
+
* to prevent the DOM morpher from interrupting the animation.
|
|
2398
|
+
*/
|
|
2399
|
+
render?: (context: LoadingIndicatorRenderContext) => HTMLElement | null;
|
|
2400
|
+
/**
|
|
2401
|
+
* Render function for the idle state indicator.
|
|
2402
|
+
* Called when the widget is idle (not streaming) and has at least one message.
|
|
2403
|
+
* Return an HTMLElement to display, or null to hide (default).
|
|
2404
|
+
*
|
|
2405
|
+
* For animations, add `data-preserve-animation="true"` attribute
|
|
2406
|
+
* to prevent the DOM morpher from interrupting the animation.
|
|
2407
|
+
*
|
|
2408
|
+
* @example
|
|
2409
|
+
* ```typescript
|
|
2410
|
+
* loadingIndicator: {
|
|
2411
|
+
* renderIdle: ({ lastMessage }) => {
|
|
2412
|
+
* // Only show idle indicator after assistant messages
|
|
2413
|
+
* if (lastMessage?.role !== 'assistant') return null;
|
|
2414
|
+
* const el = document.createElement('div');
|
|
2415
|
+
* el.className = 'pulse-dot';
|
|
2416
|
+
* el.setAttribute('data-preserve-animation', 'true');
|
|
2417
|
+
* return el;
|
|
2418
|
+
* }
|
|
2419
|
+
* }
|
|
2420
|
+
* ```
|
|
2421
|
+
*/
|
|
2422
|
+
renderIdle?: (context: IdleIndicatorRenderContext) => HTMLElement | null;
|
|
2423
|
+
};
|
|
2424
|
+
type AgentWidgetConfig = {
|
|
2425
|
+
apiUrl?: string;
|
|
2426
|
+
flowId?: string;
|
|
2427
|
+
/**
|
|
2428
|
+
* Agent configuration for agent execution mode.
|
|
2429
|
+
* When provided, the widget uses agent loop execution instead of flow dispatch.
|
|
2430
|
+
* Mutually exclusive with `flowId`.
|
|
2431
|
+
*
|
|
2432
|
+
* @example
|
|
2433
|
+
* ```typescript
|
|
2434
|
+
* config: {
|
|
2435
|
+
* agent: {
|
|
2436
|
+
* name: 'Assistant',
|
|
2437
|
+
* model: 'openai:gpt-4o-mini',
|
|
2438
|
+
* systemPrompt: 'You are a helpful assistant.',
|
|
2439
|
+
* loopConfig: { maxTurns: 5 }
|
|
2440
|
+
* }
|
|
2441
|
+
* }
|
|
2442
|
+
* ```
|
|
2443
|
+
*/
|
|
2444
|
+
agent?: AgentConfig;
|
|
2445
|
+
/**
|
|
2446
|
+
* Options for agent execution requests.
|
|
2447
|
+
* Only used when `agent` is configured.
|
|
2448
|
+
*
|
|
2449
|
+
* @default { streamResponse: true, recordMode: 'virtual' }
|
|
2450
|
+
*/
|
|
2451
|
+
agentOptions?: AgentRequestOptions;
|
|
2452
|
+
/**
|
|
2453
|
+
* Controls how multiple agent iterations are displayed in the chat UI.
|
|
2454
|
+
* Only used when `agent` is configured.
|
|
2455
|
+
*
|
|
2456
|
+
* - `'separate'`: Each iteration creates a new assistant message bubble
|
|
2457
|
+
* - `'merged'`: All iterations stream into a single assistant message
|
|
2458
|
+
*
|
|
2459
|
+
* @default 'separate'
|
|
2460
|
+
*/
|
|
2461
|
+
iterationDisplay?: 'separate' | 'merged';
|
|
2462
|
+
/**
|
|
2463
|
+
* Client token for direct browser-to-API communication.
|
|
2464
|
+
* When set, the widget uses /v1/client/* endpoints instead of /v1/dispatch.
|
|
2465
|
+
* Mutually exclusive with apiKey/headers authentication.
|
|
2466
|
+
*
|
|
2467
|
+
* @example
|
|
2468
|
+
* ```typescript
|
|
2469
|
+
* config: {
|
|
2470
|
+
* clientToken: 'ct_live_flow01k7_a8b9c0d1e2f3g4h5i6j7k8l9'
|
|
2471
|
+
* }
|
|
2472
|
+
* ```
|
|
2473
|
+
*/
|
|
2474
|
+
clientToken?: string;
|
|
2475
|
+
/**
|
|
2476
|
+
* Callback when session is initialized (client token mode only).
|
|
2477
|
+
* Receives session info including expiry time.
|
|
2478
|
+
*
|
|
2479
|
+
* @example
|
|
2480
|
+
* ```typescript
|
|
2481
|
+
* config: {
|
|
2482
|
+
* onSessionInit: (session) => {
|
|
2483
|
+
* console.log('Session started:', session.sessionId);
|
|
2484
|
+
* }
|
|
2485
|
+
* }
|
|
2486
|
+
* ```
|
|
2487
|
+
*/
|
|
2488
|
+
onSessionInit?: (session: ClientSession) => void;
|
|
2489
|
+
/**
|
|
2490
|
+
* Callback when session expires or errors (client token mode only).
|
|
2491
|
+
* Widget should prompt user to refresh.
|
|
2492
|
+
*
|
|
2493
|
+
* @example
|
|
2494
|
+
* ```typescript
|
|
2495
|
+
* config: {
|
|
2496
|
+
* onSessionExpired: () => {
|
|
2497
|
+
* alert('Your session has expired. Please refresh the page.');
|
|
2498
|
+
* }
|
|
2499
|
+
* }
|
|
2500
|
+
* ```
|
|
2501
|
+
*/
|
|
2502
|
+
onSessionExpired?: () => void;
|
|
2503
|
+
/**
|
|
2504
|
+
* Get stored session ID for session resumption (client token mode only).
|
|
2505
|
+
* Called when initializing a new session to check if there's a previous session_id
|
|
2506
|
+
* that should be passed to /client/init to resume the same conversation record.
|
|
2507
|
+
*
|
|
2508
|
+
* @example
|
|
2509
|
+
* ```typescript
|
|
2510
|
+
* config: {
|
|
2511
|
+
* getStoredSessionId: () => {
|
|
2512
|
+
* const stored = localStorage.getItem('session_id');
|
|
2513
|
+
* return stored || null;
|
|
2514
|
+
* }
|
|
2515
|
+
* }
|
|
2516
|
+
* ```
|
|
2517
|
+
*/
|
|
2518
|
+
getStoredSessionId?: () => string | null;
|
|
2519
|
+
/**
|
|
2520
|
+
* Store session ID for session resumption (client token mode only).
|
|
2521
|
+
* Called when a new session is initialized to persist the session_id
|
|
2522
|
+
* so it can be used to resume the conversation later.
|
|
2523
|
+
*
|
|
2524
|
+
* @example
|
|
2525
|
+
* ```typescript
|
|
2526
|
+
* config: {
|
|
2527
|
+
* setStoredSessionId: (sessionId) => {
|
|
2528
|
+
* localStorage.setItem('session_id', sessionId);
|
|
2529
|
+
* }
|
|
2530
|
+
* }
|
|
2531
|
+
* ```
|
|
2532
|
+
*/
|
|
2533
|
+
setStoredSessionId?: (sessionId: string) => void;
|
|
2534
|
+
/**
|
|
2535
|
+
* Static headers to include with each request.
|
|
2536
|
+
* For dynamic headers (e.g., auth tokens), use `getHeaders` instead.
|
|
2537
|
+
*/
|
|
2538
|
+
headers?: Record<string, string>;
|
|
2539
|
+
/**
|
|
2540
|
+
* Dynamic headers function - called before each request.
|
|
2541
|
+
* Useful for adding auth tokens that may change.
|
|
2542
|
+
* @example
|
|
2543
|
+
* ```typescript
|
|
2544
|
+
* getHeaders: async () => ({
|
|
2545
|
+
* 'Authorization': `Bearer ${await getAuthToken()}`
|
|
2546
|
+
* })
|
|
2547
|
+
* ```
|
|
2548
|
+
*/
|
|
2549
|
+
getHeaders?: AgentWidgetHeadersFunction;
|
|
2550
|
+
copy?: {
|
|
2551
|
+
welcomeTitle?: string;
|
|
2552
|
+
welcomeSubtitle?: string;
|
|
2553
|
+
inputPlaceholder?: string;
|
|
2554
|
+
sendButtonLabel?: string;
|
|
2555
|
+
/**
|
|
2556
|
+
* When false, the welcome / intro card is not shown above the message list.
|
|
2557
|
+
* @default true
|
|
2558
|
+
*/
|
|
2559
|
+
showWelcomeCard?: boolean;
|
|
2560
|
+
};
|
|
2561
|
+
/**
|
|
2562
|
+
* Semantic design tokens (`palette`, `semantic`, `components`).
|
|
2563
|
+
* Omit for library defaults.
|
|
2564
|
+
*/
|
|
2565
|
+
theme?: DeepPartial<PersonaTheme>;
|
|
2566
|
+
/**
|
|
2567
|
+
* Dark-mode token overrides. Merged over `theme` when the active scheme is dark.
|
|
2568
|
+
*/
|
|
2569
|
+
darkTheme?: DeepPartial<PersonaTheme>;
|
|
2570
|
+
/**
|
|
2571
|
+
* Color scheme mode for the widget.
|
|
2572
|
+
* - 'light': Always use light theme (default)
|
|
2573
|
+
* - 'dark': Always use dark theme
|
|
2574
|
+
* - 'auto': Automatically detect from page (HTML class or prefers-color-scheme)
|
|
2575
|
+
*
|
|
2576
|
+
* When 'auto', detection order:
|
|
2577
|
+
* 1. Check if `<html>` has 'dark' class
|
|
2578
|
+
* 2. Fall back to `prefers-color-scheme: dark` media query
|
|
2579
|
+
*
|
|
2580
|
+
* @default 'light'
|
|
2581
|
+
*/
|
|
2582
|
+
colorScheme?: 'auto' | 'light' | 'dark';
|
|
2583
|
+
features?: AgentWidgetFeatureFlags;
|
|
2584
|
+
/**
|
|
2585
|
+
* When true, focus the chat input after the panel opens and the open animation completes.
|
|
2586
|
+
* Applies to launcher mode (user click, controller.open(), autoExpand) and inline mode (on init).
|
|
2587
|
+
* Skip when voice is active to avoid stealing focus from voice UI.
|
|
2588
|
+
* @default false
|
|
2589
|
+
*/
|
|
2590
|
+
autoFocusInput?: boolean;
|
|
2591
|
+
launcher?: AgentWidgetLauncherConfig;
|
|
2592
|
+
initialMessages?: AgentWidgetMessage[];
|
|
2593
|
+
suggestionChips?: string[];
|
|
2594
|
+
suggestionChipsConfig?: AgentWidgetSuggestionChipsConfig;
|
|
2595
|
+
debug?: boolean;
|
|
2596
|
+
formEndpoint?: string;
|
|
2597
|
+
launcherWidth?: string;
|
|
2598
|
+
sendButton?: AgentWidgetSendButtonConfig;
|
|
2599
|
+
statusIndicator?: AgentWidgetStatusIndicatorConfig;
|
|
2600
|
+
voiceRecognition?: AgentWidgetVoiceRecognitionConfig;
|
|
2601
|
+
/**
|
|
2602
|
+
* Text-to-speech configuration for reading assistant messages aloud.
|
|
2603
|
+
* Uses the browser's Web Speech API (`speechSynthesis`).
|
|
2604
|
+
*
|
|
2605
|
+
* @example
|
|
2606
|
+
* ```typescript
|
|
2607
|
+
* config: {
|
|
2608
|
+
* textToSpeech: {
|
|
2609
|
+
* enabled: true,
|
|
2610
|
+
* voice: 'Google US English',
|
|
2611
|
+
* rate: 1.0,
|
|
2612
|
+
* pitch: 1.0
|
|
2613
|
+
* }
|
|
2614
|
+
* }
|
|
2615
|
+
* ```
|
|
2616
|
+
*/
|
|
2617
|
+
textToSpeech?: TextToSpeechConfig;
|
|
2618
|
+
toolCall?: AgentWidgetToolCallConfig$1;
|
|
2619
|
+
/**
|
|
2620
|
+
* Configuration for tool approval bubbles.
|
|
2621
|
+
* Set to `false` to disable built-in approval handling entirely.
|
|
2622
|
+
*
|
|
2623
|
+
* @example
|
|
2624
|
+
* ```typescript
|
|
2625
|
+
* config: {
|
|
2626
|
+
* approval: {
|
|
2627
|
+
* title: "Permission Required",
|
|
2628
|
+
* approveLabel: "Allow",
|
|
2629
|
+
* denyLabel: "Block",
|
|
2630
|
+
* approveButtonColor: "#16a34a"
|
|
2631
|
+
* }
|
|
2632
|
+
* }
|
|
2633
|
+
* ```
|
|
2634
|
+
*/
|
|
2635
|
+
approval?: AgentWidgetApprovalConfig | false;
|
|
2636
|
+
postprocessMessage?: (context: {
|
|
2637
|
+
text: string;
|
|
2638
|
+
message: AgentWidgetMessage;
|
|
2639
|
+
streaming: boolean;
|
|
2640
|
+
raw?: string;
|
|
2641
|
+
}) => string;
|
|
2642
|
+
plugins?: AgentWidgetPlugin[];
|
|
2643
|
+
contextProviders?: AgentWidgetContextProvider[];
|
|
2644
|
+
requestMiddleware?: AgentWidgetRequestMiddleware;
|
|
2645
|
+
actionParsers?: AgentWidgetActionParser[];
|
|
2646
|
+
actionHandlers?: AgentWidgetActionHandler[];
|
|
2647
|
+
storageAdapter?: AgentWidgetStorageAdapter;
|
|
2648
|
+
/**
|
|
2649
|
+
* Called after state is loaded from the storage adapter, but before the widget
|
|
2650
|
+
* initializes with that state. Use this to transform or inject messages based
|
|
2651
|
+
* on external state (e.g., navigation flags, checkout returns).
|
|
2652
|
+
*
|
|
2653
|
+
* This hook runs synchronously and must return the (potentially modified) state.
|
|
2654
|
+
*
|
|
2655
|
+
* Returning `{ state, open: true }` also signals that the widget panel should
|
|
2656
|
+
* open after initialization — useful when injecting a post-navigation message
|
|
2657
|
+
* that the user should immediately see.
|
|
2658
|
+
*
|
|
2659
|
+
* @example
|
|
2660
|
+
* ```typescript
|
|
2661
|
+
* // Plain state transform (existing form, still supported)
|
|
2662
|
+
* config: {
|
|
2663
|
+
* onStateLoaded: (state) => {
|
|
2664
|
+
* const navMessage = consumeNavigationFlag();
|
|
2665
|
+
* if (navMessage) {
|
|
2666
|
+
* return {
|
|
2667
|
+
* ...state,
|
|
2668
|
+
* messages: [...(state.messages || []), {
|
|
2669
|
+
* id: `nav-${Date.now()}`,
|
|
2670
|
+
* role: 'assistant',
|
|
2671
|
+
* content: navMessage,
|
|
2672
|
+
* createdAt: new Date().toISOString()
|
|
2673
|
+
* }]
|
|
2674
|
+
* };
|
|
2675
|
+
* }
|
|
2676
|
+
* return state;
|
|
2677
|
+
* }
|
|
2678
|
+
* }
|
|
2679
|
+
* ```
|
|
2680
|
+
*
|
|
2681
|
+
* @example
|
|
2682
|
+
* ```typescript
|
|
2683
|
+
* // Return { state, open: true } to also open the panel
|
|
2684
|
+
* config: {
|
|
2685
|
+
* onStateLoaded: (state) => {
|
|
2686
|
+
* const navMessage = consumeNavigationFlag();
|
|
2687
|
+
* if (navMessage) {
|
|
2688
|
+
* return {
|
|
2689
|
+
* state: {
|
|
2690
|
+
* ...state,
|
|
2691
|
+
* messages: [...(state.messages || []), {
|
|
2692
|
+
* id: `nav-${Date.now()}`,
|
|
2693
|
+
* role: 'assistant',
|
|
2694
|
+
* content: navMessage,
|
|
2695
|
+
* createdAt: new Date().toISOString()
|
|
2696
|
+
* }]
|
|
2697
|
+
* },
|
|
2698
|
+
* open: true
|
|
2699
|
+
* };
|
|
2700
|
+
* }
|
|
2701
|
+
* return state;
|
|
2702
|
+
* }
|
|
2703
|
+
* }
|
|
2704
|
+
* ```
|
|
2705
|
+
*/
|
|
2706
|
+
onStateLoaded?: (state: AgentWidgetStoredState) => AgentWidgetStoredState | {
|
|
2707
|
+
state: AgentWidgetStoredState;
|
|
2708
|
+
open?: boolean;
|
|
2709
|
+
};
|
|
2710
|
+
/**
|
|
2711
|
+
* Registry of custom components that can be rendered from JSON directives.
|
|
2712
|
+
* Components are registered by name and can be invoked via JSON responses
|
|
2713
|
+
* with the format: `{"component": "ComponentName", "props": {...}}`
|
|
2714
|
+
*
|
|
2715
|
+
* @example
|
|
2716
|
+
* ```typescript
|
|
2717
|
+
* config: {
|
|
2718
|
+
* components: {
|
|
2719
|
+
* ProductCard: (props, context) => {
|
|
2720
|
+
* const card = document.createElement("div");
|
|
2721
|
+
* card.innerHTML = `<h3>${props.title}</h3><p>$${props.price}</p>`;
|
|
2722
|
+
* return card;
|
|
2723
|
+
* }
|
|
2724
|
+
* }
|
|
2725
|
+
* }
|
|
2726
|
+
* ```
|
|
2727
|
+
*/
|
|
2728
|
+
components?: Record<string, AgentWidgetComponentRenderer>;
|
|
2729
|
+
/**
|
|
2730
|
+
* Enable component streaming. When true, component props will be updated
|
|
2731
|
+
* incrementally as they stream in from the JSON response.
|
|
2732
|
+
*
|
|
2733
|
+
* @default true
|
|
2734
|
+
*/
|
|
2735
|
+
enableComponentStreaming?: boolean;
|
|
2736
|
+
/**
|
|
2737
|
+
* When false, JSON component directives render without the default bubble chrome
|
|
2738
|
+
* (surface background, border, extra padding). Use for wide custom cards in the transcript.
|
|
2739
|
+
* @default true
|
|
2740
|
+
*/
|
|
2741
|
+
wrapComponentDirectiveInBubble?: boolean;
|
|
2742
|
+
/**
|
|
2743
|
+
* Custom stream parser for extracting text from streaming structured responses.
|
|
2744
|
+
* Handles incremental parsing of JSON, XML, or other formats.
|
|
2745
|
+
* If not provided, uses the default JSON parser.
|
|
2746
|
+
*
|
|
2747
|
+
* @example
|
|
2748
|
+
* ```typescript
|
|
2749
|
+
* streamParser: () => ({
|
|
2750
|
+
* processChunk: async (content) => {
|
|
2751
|
+
* // Return null if not your format, or extracted text if available
|
|
2752
|
+
* if (!content.trim().startsWith('{')) return null;
|
|
2753
|
+
* return extractText(content);
|
|
2754
|
+
* },
|
|
2755
|
+
* getExtractedText: () => extractedText
|
|
2756
|
+
* })
|
|
2757
|
+
* ```
|
|
2758
|
+
*/
|
|
2759
|
+
streamParser?: () => AgentWidgetStreamParser;
|
|
2760
|
+
/**
|
|
2761
|
+
* Additional localStorage key to clear when the clear chat button is clicked.
|
|
2762
|
+
* The widget automatically clears `"persona-chat-history"` by default.
|
|
2763
|
+
* Use this option to clear additional keys (e.g., if you're using a custom storage key).
|
|
2764
|
+
*
|
|
2765
|
+
* @example
|
|
2766
|
+
* ```typescript
|
|
2767
|
+
* config: {
|
|
2768
|
+
* clearChatHistoryStorageKey: "my-custom-chat-history"
|
|
2769
|
+
* }
|
|
2770
|
+
* ```
|
|
2771
|
+
*/
|
|
2772
|
+
clearChatHistoryStorageKey?: string;
|
|
2773
|
+
/**
|
|
2774
|
+
* Built-in parser type selector. Provides an easy way to choose a parser without importing functions.
|
|
2775
|
+
* If both `parserType` and `streamParser` are provided, `streamParser` takes precedence.
|
|
2776
|
+
*
|
|
2777
|
+
* - `"plain"` - Plain text parser (default). Passes through text as-is.
|
|
2778
|
+
* - `"json"` - JSON parser using partial-json. Extracts `text` field from JSON objects incrementally.
|
|
2779
|
+
* - `"regex-json"` - Regex-based JSON parser. Less robust but faster fallback for simple JSON.
|
|
2780
|
+
* - `"xml"` - XML parser. Extracts text content from XML tags.
|
|
2781
|
+
*
|
|
2782
|
+
* @example
|
|
2783
|
+
* ```typescript
|
|
2784
|
+
* config: {
|
|
2785
|
+
* parserType: "json" // Use built-in JSON parser
|
|
2786
|
+
* }
|
|
2787
|
+
* ```
|
|
2788
|
+
*
|
|
2789
|
+
* @example
|
|
2790
|
+
* ```typescript
|
|
2791
|
+
* config: {
|
|
2792
|
+
* parserType: "json",
|
|
2793
|
+
* streamParser: () => customParser() // Custom parser overrides parserType
|
|
2794
|
+
* }
|
|
2795
|
+
* ```
|
|
2796
|
+
*/
|
|
2797
|
+
parserType?: "plain" | "json" | "regex-json" | "xml";
|
|
2798
|
+
/**
|
|
2799
|
+
* Custom fetch function for full control over API requests.
|
|
2800
|
+
* Use this for custom authentication, request/response transformation, etc.
|
|
2801
|
+
*
|
|
2802
|
+
* When provided, this function is called instead of the default fetch.
|
|
2803
|
+
* You receive the URL, RequestInit, and the payload that would be sent.
|
|
2804
|
+
*
|
|
2805
|
+
* @example
|
|
2806
|
+
* ```typescript
|
|
2807
|
+
* config: {
|
|
2808
|
+
* customFetch: async (url, init, payload) => {
|
|
2809
|
+
* // Transform request for your API format
|
|
2810
|
+
* const myPayload = {
|
|
2811
|
+
* flow: { id: 'my-flow-id' },
|
|
2812
|
+
* messages: payload.messages,
|
|
2813
|
+
* options: { stream_response: true }
|
|
2814
|
+
* };
|
|
2815
|
+
*
|
|
2816
|
+
* // Add auth header
|
|
2817
|
+
* const token = await getAuthToken();
|
|
2818
|
+
*
|
|
2819
|
+
* return fetch('/my-api/dispatch', {
|
|
2820
|
+
* method: 'POST',
|
|
2821
|
+
* headers: {
|
|
2822
|
+
* 'Content-Type': 'application/json',
|
|
2823
|
+
* 'Authorization': `Bearer ${token}`
|
|
2824
|
+
* },
|
|
2825
|
+
* body: JSON.stringify(myPayload),
|
|
2826
|
+
* signal: init.signal
|
|
2827
|
+
* });
|
|
2828
|
+
* }
|
|
2829
|
+
* }
|
|
2830
|
+
* ```
|
|
2831
|
+
*/
|
|
2832
|
+
customFetch?: AgentWidgetCustomFetch;
|
|
2833
|
+
/**
|
|
2834
|
+
* Custom SSE event parser for non-standard streaming response formats.
|
|
2835
|
+
*
|
|
2836
|
+
* Use this when your API returns SSE events in a different format than expected.
|
|
2837
|
+
* Return `{ text }` for text chunks, `{ done: true }` for completion,
|
|
2838
|
+
* `{ error }` for errors, or `null` to ignore the event.
|
|
2839
|
+
*
|
|
2840
|
+
* @example
|
|
2841
|
+
* ```typescript
|
|
2842
|
+
* // For Runtype API format
|
|
2843
|
+
* config: {
|
|
2844
|
+
* parseSSEEvent: (data) => {
|
|
2845
|
+
* if ((data.type === 'step_delta' || data.type === 'step_chunk') && (data.delta || data.chunk)) {
|
|
2846
|
+
* return { text: data.delta ?? data.chunk };
|
|
2847
|
+
* }
|
|
2848
|
+
* if (data.type === 'flow_complete') {
|
|
2849
|
+
* return { done: true };
|
|
2850
|
+
* }
|
|
2851
|
+
* if (data.type === 'step_error') {
|
|
2852
|
+
* return { error: data.error };
|
|
2853
|
+
* }
|
|
2854
|
+
* return null; // Ignore other events
|
|
2855
|
+
* }
|
|
2856
|
+
* }
|
|
2857
|
+
* ```
|
|
2858
|
+
*/
|
|
2859
|
+
parseSSEEvent?: AgentWidgetSSEEventParser;
|
|
2860
|
+
/**
|
|
2861
|
+
* Layout configuration for customizing widget appearance and structure.
|
|
2862
|
+
* Provides control over header, messages, and content slots.
|
|
2863
|
+
*
|
|
2864
|
+
* @example
|
|
2865
|
+
* ```typescript
|
|
2866
|
+
* config: {
|
|
2867
|
+
* layout: {
|
|
2868
|
+
* header: { layout: "minimal" },
|
|
2869
|
+
* messages: { avatar: { show: true } }
|
|
2870
|
+
* }
|
|
2871
|
+
* }
|
|
2872
|
+
* ```
|
|
2873
|
+
*/
|
|
2874
|
+
layout?: AgentWidgetLayoutConfig;
|
|
2875
|
+
/**
|
|
2876
|
+
* Markdown rendering configuration.
|
|
2877
|
+
* Customize how markdown is parsed and rendered in chat messages.
|
|
2878
|
+
*
|
|
2879
|
+
* Override methods:
|
|
2880
|
+
* 1. **CSS Variables** - Override `--cw-md-*` variables in your stylesheet
|
|
2881
|
+
* 2. **Options** - Configure marked parser behavior
|
|
2882
|
+
* 3. **Renderers** - Custom rendering functions for specific elements
|
|
2883
|
+
* 4. **postprocessMessage** - Complete control over message transformation
|
|
2884
|
+
*
|
|
2885
|
+
* @example
|
|
2886
|
+
* ```typescript
|
|
2887
|
+
* config: {
|
|
2888
|
+
* markdown: {
|
|
2889
|
+
* options: { breaks: true, gfm: true },
|
|
2890
|
+
* renderer: {
|
|
2891
|
+
* link(token) {
|
|
2892
|
+
* return `<a href="${token.href}" target="_blank">${token.text}</a>`;
|
|
2893
|
+
* }
|
|
2894
|
+
* }
|
|
2895
|
+
* }
|
|
2896
|
+
* }
|
|
2897
|
+
* ```
|
|
2898
|
+
*/
|
|
2899
|
+
markdown?: AgentWidgetMarkdownConfig;
|
|
2900
|
+
/**
|
|
2901
|
+
* HTML sanitization for rendered message content.
|
|
2902
|
+
*
|
|
2903
|
+
* The widget renders AI-generated markdown as HTML. By default, all HTML
|
|
2904
|
+
* output is sanitized using DOMPurify to prevent XSS attacks.
|
|
2905
|
+
*
|
|
2906
|
+
* - `true` (default): sanitize using built-in DOMPurify
|
|
2907
|
+
* - `false`: disable sanitization (only use with fully trusted content sources)
|
|
2908
|
+
* - `(html: string) => string`: custom sanitizer function
|
|
2909
|
+
*
|
|
2910
|
+
* @default true
|
|
2911
|
+
*/
|
|
2912
|
+
sanitize?: boolean | ((html: string) => string);
|
|
2913
|
+
/**
|
|
2914
|
+
* Configuration for message action buttons (copy, upvote, downvote).
|
|
2915
|
+
* Shows action buttons on assistant messages for user feedback.
|
|
2916
|
+
*
|
|
2917
|
+
* @example
|
|
2918
|
+
* ```typescript
|
|
2919
|
+
* config: {
|
|
2920
|
+
* messageActions: {
|
|
2921
|
+
* enabled: true,
|
|
2922
|
+
* showCopy: true,
|
|
2923
|
+
* showUpvote: true,
|
|
2924
|
+
* showDownvote: true,
|
|
2925
|
+
* visibility: 'hover',
|
|
2926
|
+
* onFeedback: (feedback) => {
|
|
2927
|
+
* console.log('Feedback:', feedback.type, feedback.messageId);
|
|
2928
|
+
* },
|
|
2929
|
+
* onCopy: (message) => {
|
|
2930
|
+
* console.log('Copied message:', message.id);
|
|
2931
|
+
* }
|
|
2932
|
+
* }
|
|
2933
|
+
* }
|
|
2934
|
+
* ```
|
|
2935
|
+
*/
|
|
2936
|
+
messageActions?: AgentWidgetMessageActionsConfig;
|
|
2937
|
+
/**
|
|
2938
|
+
* Configuration for file attachments in the composer.
|
|
2939
|
+
* When enabled, users can attach images to their messages.
|
|
2940
|
+
*
|
|
2941
|
+
* @example
|
|
2942
|
+
* ```typescript
|
|
2943
|
+
* config: {
|
|
2944
|
+
* attachments: {
|
|
2945
|
+
* enabled: true,
|
|
2946
|
+
* maxFileSize: 5 * 1024 * 1024, // 5MB
|
|
2947
|
+
* maxFiles: 4
|
|
2948
|
+
* }
|
|
2949
|
+
* }
|
|
2950
|
+
* ```
|
|
2951
|
+
*/
|
|
2952
|
+
attachments?: AgentWidgetAttachmentsConfig;
|
|
2953
|
+
/**
|
|
2954
|
+
* Composer extras for custom `renderComposer` plugins (model picker, etc.).
|
|
2955
|
+
* `selectedModelId` may be updated at runtime by the host.
|
|
2956
|
+
*/
|
|
2957
|
+
composer?: AgentWidgetComposerConfig;
|
|
2958
|
+
/**
|
|
2959
|
+
* Persist widget state (open/closed, voice mode) across page navigations.
|
|
2960
|
+
* When `true`, uses default settings with sessionStorage.
|
|
2961
|
+
* When an object, allows customizing storage type, key prefix, and what to persist.
|
|
2962
|
+
*
|
|
2963
|
+
* @example
|
|
2964
|
+
* ```typescript
|
|
2965
|
+
* // Simple usage - persist open state in sessionStorage
|
|
2966
|
+
* config: {
|
|
2967
|
+
* persistState: true
|
|
2968
|
+
* }
|
|
2969
|
+
* ```
|
|
2970
|
+
*
|
|
2971
|
+
* @example
|
|
2972
|
+
* ```typescript
|
|
2973
|
+
* // Advanced usage
|
|
2974
|
+
* config: {
|
|
2975
|
+
* persistState: {
|
|
2976
|
+
* storage: 'local', // Use localStorage
|
|
2977
|
+
* persist: {
|
|
2978
|
+
* openState: true,
|
|
2979
|
+
* voiceState: true,
|
|
2980
|
+
* focusInput: true
|
|
2981
|
+
* }
|
|
2982
|
+
* }
|
|
2983
|
+
* }
|
|
2984
|
+
* ```
|
|
2985
|
+
*/
|
|
2986
|
+
persistState?: boolean | AgentWidgetPersistStateConfig;
|
|
2987
|
+
/**
|
|
2988
|
+
* Configuration for customizing the loading indicator.
|
|
2989
|
+
* The loading indicator is shown while waiting for a response or
|
|
2990
|
+
* when an assistant message is streaming but has no content yet.
|
|
2991
|
+
*
|
|
2992
|
+
* @example
|
|
2993
|
+
* ```typescript
|
|
2994
|
+
* config: {
|
|
2995
|
+
* loadingIndicator: {
|
|
2996
|
+
* render: ({ location, defaultRenderer }) => {
|
|
2997
|
+
* if (location === 'standalone') {
|
|
2998
|
+
* const el = document.createElement('div');
|
|
2999
|
+
* el.textContent = 'Thinking...';
|
|
3000
|
+
* return el;
|
|
3001
|
+
* }
|
|
3002
|
+
* return defaultRenderer();
|
|
3003
|
+
* }
|
|
3004
|
+
* }
|
|
3005
|
+
* }
|
|
3006
|
+
* ```
|
|
3007
|
+
*/
|
|
3008
|
+
loadingIndicator?: AgentWidgetLoadingIndicatorConfig;
|
|
3009
|
+
};
|
|
3010
|
+
type AgentWidgetMessageRole = "user" | "assistant" | "system";
|
|
3011
|
+
type AgentWidgetReasoning = {
|
|
3012
|
+
id: string;
|
|
3013
|
+
status: "pending" | "streaming" | "complete";
|
|
3014
|
+
chunks: string[];
|
|
3015
|
+
startedAt?: number;
|
|
3016
|
+
completedAt?: number;
|
|
3017
|
+
durationMs?: number;
|
|
3018
|
+
};
|
|
3019
|
+
type AgentWidgetToolCall = {
|
|
3020
|
+
id: string;
|
|
3021
|
+
name?: string;
|
|
3022
|
+
status: "pending" | "running" | "complete";
|
|
3023
|
+
args?: unknown;
|
|
3024
|
+
chunks?: string[];
|
|
3025
|
+
result?: unknown;
|
|
3026
|
+
duration?: number;
|
|
3027
|
+
startedAt?: number;
|
|
3028
|
+
completedAt?: number;
|
|
3029
|
+
durationMs?: number;
|
|
3030
|
+
};
|
|
3031
|
+
/**
|
|
3032
|
+
* Represents a tool approval request in the chat conversation.
|
|
3033
|
+
* Created when the agent requires human approval before executing a tool.
|
|
3034
|
+
*/
|
|
3035
|
+
type AgentWidgetApproval = {
|
|
3036
|
+
id: string;
|
|
3037
|
+
status: "pending" | "approved" | "denied" | "timeout";
|
|
3038
|
+
agentId: string;
|
|
3039
|
+
executionId: string;
|
|
3040
|
+
toolName: string;
|
|
3041
|
+
toolType?: string;
|
|
3042
|
+
description: string;
|
|
3043
|
+
parameters?: unknown;
|
|
3044
|
+
resolvedAt?: number;
|
|
3045
|
+
};
|
|
3046
|
+
type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool" | "approval";
|
|
3047
|
+
/**
|
|
3048
|
+
* Represents a message in the chat conversation.
|
|
3049
|
+
*
|
|
3050
|
+
* @property id - Unique message identifier
|
|
3051
|
+
* @property role - Message role: "user", "assistant", or "system"
|
|
3052
|
+
* @property content - Message text content (for display)
|
|
3053
|
+
* @property contentParts - Original multi-modal content parts (for API requests)
|
|
3054
|
+
* @property createdAt - ISO timestamp when message was created
|
|
3055
|
+
* @property streaming - Whether message is still streaming (for assistant messages)
|
|
3056
|
+
* @property variant - Message variant for assistant messages: "assistant", "reasoning", or "tool"
|
|
3057
|
+
* @property sequence - Message ordering number
|
|
3058
|
+
* @property reasoning - Reasoning data for assistant reasoning messages
|
|
3059
|
+
* @property toolCall - Tool call data for assistant tool messages
|
|
3060
|
+
* @property tools - Array of tool calls
|
|
3061
|
+
* @property viaVoice - Set to `true` when a user message is sent via voice recognition.
|
|
3062
|
+
* Useful for implementing voice-specific behaviors like auto-reactivation.
|
|
3063
|
+
*/
|
|
3064
|
+
type AgentWidgetMessage = {
|
|
3065
|
+
id: string;
|
|
3066
|
+
role: AgentWidgetMessageRole;
|
|
3067
|
+
content: string;
|
|
3068
|
+
createdAt: string;
|
|
3069
|
+
/**
|
|
3070
|
+
* Original multi-modal content parts for this message.
|
|
3071
|
+
* When present, this is sent to the API instead of `content`.
|
|
3072
|
+
* The `content` field contains the text-only representation for display.
|
|
3073
|
+
*/
|
|
3074
|
+
contentParts?: ContentPart[];
|
|
3075
|
+
streaming?: boolean;
|
|
3076
|
+
variant?: AgentWidgetMessageVariant;
|
|
3077
|
+
sequence?: number;
|
|
3078
|
+
reasoning?: AgentWidgetReasoning;
|
|
3079
|
+
toolCall?: AgentWidgetToolCall;
|
|
3080
|
+
tools?: AgentWidgetToolCall[];
|
|
3081
|
+
/** Approval data for messages with variant "approval" */
|
|
3082
|
+
approval?: AgentWidgetApproval;
|
|
3083
|
+
viaVoice?: boolean;
|
|
3084
|
+
/**
|
|
3085
|
+
* Set to `true` on placeholder messages injected during Runtype voice processing.
|
|
3086
|
+
* Use this in `messageTransform` to detect and customize voice processing placeholders.
|
|
3087
|
+
*
|
|
3088
|
+
* @example
|
|
3089
|
+
* messageTransform: ({ text, message }) => {
|
|
3090
|
+
* if (message.voiceProcessing && message.role === 'user') {
|
|
3091
|
+
* return '<div class="my-voice-spinner">Transcribing...</div>';
|
|
3092
|
+
* }
|
|
3093
|
+
* return text;
|
|
3094
|
+
* }
|
|
3095
|
+
*/
|
|
3096
|
+
voiceProcessing?: boolean;
|
|
3097
|
+
/**
|
|
3098
|
+
* Raw structured payload for this message (e.g., JSON action response).
|
|
3099
|
+
* Populated automatically when structured parsers run.
|
|
3100
|
+
*/
|
|
3101
|
+
rawContent?: string;
|
|
3102
|
+
/**
|
|
3103
|
+
* LLM-specific content for API requests.
|
|
3104
|
+
* When present, this is sent to the LLM instead of `content`.
|
|
3105
|
+
*
|
|
3106
|
+
* Priority for API payload:
|
|
3107
|
+
* 1. `contentParts` (if present, used as-is for multi-modal)
|
|
3108
|
+
* 2. `llmContent` (if present, sent as string)
|
|
3109
|
+
* 3. `rawContent` (backward compatibility with structured parsers)
|
|
3110
|
+
* 4. `content` (fallback - display content)
|
|
3111
|
+
*
|
|
3112
|
+
* The `content` field is always used for UI display.
|
|
3113
|
+
*
|
|
3114
|
+
* @example
|
|
3115
|
+
* // Show full details to user, send summary to LLM
|
|
3116
|
+
* {
|
|
3117
|
+
* content: "**Product:** iPhone 15 Pro\n**Price:** $1,199\n**SKU:** IP15P-256",
|
|
3118
|
+
* llmContent: "[Product search: iPhone 15 Pro, $1199]"
|
|
3119
|
+
* }
|
|
3120
|
+
*/
|
|
3121
|
+
llmContent?: string;
|
|
3122
|
+
/**
|
|
3123
|
+
* Text segment identity for chronological ordering.
|
|
3124
|
+
* When present, identifies which text segment this message represents
|
|
3125
|
+
* (e.g., "text_0", "text_1") for messages split at tool boundaries.
|
|
3126
|
+
*/
|
|
3127
|
+
partId?: string;
|
|
3128
|
+
/**
|
|
3129
|
+
* Metadata for messages created during agent loop execution.
|
|
3130
|
+
* Contains execution context like iteration number and turn ID.
|
|
3131
|
+
*/
|
|
3132
|
+
agentMetadata?: AgentMessageMetadata;
|
|
3133
|
+
};
|
|
3134
|
+
/**
|
|
3135
|
+
* Options for injecting a message into the conversation.
|
|
3136
|
+
* Supports dual-content where UI display differs from LLM context.
|
|
3137
|
+
*
|
|
3138
|
+
* @example
|
|
3139
|
+
* // Same content for user and LLM
|
|
3140
|
+
* {
|
|
3141
|
+
* role: 'assistant',
|
|
3142
|
+
* content: 'Here are your search results...'
|
|
3143
|
+
* }
|
|
3144
|
+
*
|
|
3145
|
+
* @example
|
|
3146
|
+
* // Different content: user sees full details, LLM sees summary
|
|
3147
|
+
* {
|
|
3148
|
+
* role: 'assistant',
|
|
3149
|
+
* content: '**Found 3 products:**\n- iPhone 15 Pro ($1,199)\n- iPhone 15 ($999)',
|
|
3150
|
+
* llmContent: '[Search results: 3 iPhones, $999-$1199]'
|
|
3151
|
+
* }
|
|
3152
|
+
*/
|
|
3153
|
+
type InjectMessageOptions = {
|
|
3154
|
+
/**
|
|
3155
|
+
* Message role: "assistant", "user", or "system"
|
|
3156
|
+
*/
|
|
3157
|
+
role: AgentWidgetMessageRole;
|
|
3158
|
+
/**
|
|
3159
|
+
* Content displayed to the user in the chat UI.
|
|
3160
|
+
* This is what appears in the message bubble.
|
|
3161
|
+
*/
|
|
3162
|
+
content: string;
|
|
3163
|
+
/**
|
|
3164
|
+
* Content sent to the LLM in API requests.
|
|
3165
|
+
* When omitted, `content` is used for both display and LLM.
|
|
3166
|
+
*
|
|
3167
|
+
* Use cases:
|
|
3168
|
+
* - Redacted content: Show full product details to user, send summary to LLM
|
|
3169
|
+
* - Structured data: Show formatted markdown to user, send JSON to LLM
|
|
3170
|
+
* - Token optimization: Show verbose content to user, send concise version to LLM
|
|
3171
|
+
*/
|
|
3172
|
+
llmContent?: string;
|
|
3173
|
+
/**
|
|
3174
|
+
* Multi-modal content parts for the LLM (images, files).
|
|
3175
|
+
* Takes precedence over `llmContent` when present.
|
|
3176
|
+
* The `content` field is still used for UI display.
|
|
3177
|
+
*/
|
|
3178
|
+
contentParts?: ContentPart[];
|
|
3179
|
+
/**
|
|
3180
|
+
* Optional message ID. If omitted, auto-generated based on role.
|
|
3181
|
+
*/
|
|
3182
|
+
id?: string;
|
|
3183
|
+
/**
|
|
3184
|
+
* Optional creation timestamp (ISO string). If omitted, uses current time.
|
|
3185
|
+
*/
|
|
3186
|
+
createdAt?: string;
|
|
3187
|
+
/**
|
|
3188
|
+
* Optional sequence number for ordering.
|
|
3189
|
+
*/
|
|
3190
|
+
sequence?: number;
|
|
3191
|
+
/**
|
|
3192
|
+
* Whether the message is still streaming (for incremental updates).
|
|
3193
|
+
* @default false
|
|
3194
|
+
*/
|
|
3195
|
+
streaming?: boolean;
|
|
3196
|
+
/**
|
|
3197
|
+
* Mark this message as a voice processing placeholder.
|
|
3198
|
+
* Consumers can detect this in `messageTransform` to render custom UI.
|
|
3199
|
+
*/
|
|
3200
|
+
voiceProcessing?: boolean;
|
|
3201
|
+
};
|
|
3202
|
+
/**
|
|
3203
|
+
* Options for injecting assistant messages (most common case).
|
|
3204
|
+
* Role defaults to 'assistant'.
|
|
3205
|
+
*/
|
|
3206
|
+
type InjectAssistantMessageOptions = Omit<InjectMessageOptions, "role">;
|
|
3207
|
+
/**
|
|
3208
|
+
* Options for injecting user messages.
|
|
3209
|
+
* Role defaults to 'user'.
|
|
3210
|
+
*/
|
|
3211
|
+
type InjectUserMessageOptions = Omit<InjectMessageOptions, "role">;
|
|
3212
|
+
/**
|
|
3213
|
+
* Options for injecting system messages.
|
|
3214
|
+
* Role defaults to 'system'.
|
|
3215
|
+
*/
|
|
3216
|
+
type InjectSystemMessageOptions = Omit<InjectMessageOptions, "role">;
|
|
3217
|
+
type PersonaArtifactRecord = {
|
|
3218
|
+
id: string;
|
|
3219
|
+
artifactType: PersonaArtifactKind;
|
|
3220
|
+
title?: string;
|
|
3221
|
+
status: "streaming" | "complete";
|
|
3222
|
+
markdown?: string;
|
|
3223
|
+
component?: string;
|
|
3224
|
+
props?: Record<string, unknown>;
|
|
3225
|
+
};
|
|
3226
|
+
/** Programmatic artifact upsert (controller / window API) */
|
|
3227
|
+
type PersonaArtifactManualUpsert = {
|
|
3228
|
+
id?: string;
|
|
3229
|
+
artifactType: "markdown";
|
|
3230
|
+
title?: string;
|
|
3231
|
+
content: string;
|
|
3232
|
+
} | {
|
|
3233
|
+
id?: string;
|
|
3234
|
+
artifactType: "component";
|
|
3235
|
+
title?: string;
|
|
3236
|
+
component: string;
|
|
3237
|
+
props?: Record<string, unknown>;
|
|
3238
|
+
};
|
|
3239
|
+
type AgentWidgetEvent = {
|
|
3240
|
+
type: "message";
|
|
3241
|
+
message: AgentWidgetMessage;
|
|
3242
|
+
} | {
|
|
3243
|
+
type: "status";
|
|
3244
|
+
status: "connecting" | "connected" | "error" | "idle";
|
|
3245
|
+
} | {
|
|
3246
|
+
type: "error";
|
|
3247
|
+
error: Error;
|
|
3248
|
+
} | {
|
|
3249
|
+
type: "artifact_start";
|
|
3250
|
+
id: string;
|
|
3251
|
+
artifactType: PersonaArtifactKind;
|
|
3252
|
+
title?: string;
|
|
3253
|
+
component?: string;
|
|
3254
|
+
} | {
|
|
3255
|
+
type: "artifact_delta";
|
|
3256
|
+
id: string;
|
|
3257
|
+
artDelta: string;
|
|
3258
|
+
} | {
|
|
3259
|
+
type: "artifact_update";
|
|
3260
|
+
id: string;
|
|
3261
|
+
props: Record<string, unknown>;
|
|
3262
|
+
component?: string;
|
|
3263
|
+
} | {
|
|
3264
|
+
type: "artifact_complete";
|
|
3265
|
+
id: string;
|
|
3266
|
+
};
|
|
3267
|
+
|
|
3268
|
+
/** Field definition types for the declarative configurator system (headless — no DOM) */
|
|
3269
|
+
|
|
3270
|
+
type FieldType = 'color' | 'slider' | 'toggle' | 'select' | 'text' | 'chip-list' | 'color-scale' | 'token-ref' | 'role-assignment';
|
|
3271
|
+
interface SliderOptions {
|
|
3272
|
+
min: number;
|
|
3273
|
+
max: number;
|
|
3274
|
+
step: number;
|
|
3275
|
+
unit?: 'px' | 'rem' | 'none';
|
|
3276
|
+
/** Treat max value as 9999px (border-radius: full) */
|
|
3277
|
+
isRadiusFull?: boolean;
|
|
3278
|
+
}
|
|
3279
|
+
interface SelectOption {
|
|
3280
|
+
value: string;
|
|
3281
|
+
label: string;
|
|
3282
|
+
}
|
|
3283
|
+
interface ColorScaleOptions {
|
|
3284
|
+
/** Which palette color family (e.g., 'primary', 'gray') */
|
|
3285
|
+
colorFamily: string;
|
|
3286
|
+
}
|
|
3287
|
+
interface TokenRefOptions {
|
|
3288
|
+
/** Token type to filter available references */
|
|
3289
|
+
tokenType: 'color' | 'spacing' | 'radius' | 'shadow' | 'typography';
|
|
3290
|
+
/** Available palette families to reference */
|
|
3291
|
+
families?: string[];
|
|
3292
|
+
}
|
|
3293
|
+
/** Which kind of value a role target expects */
|
|
3294
|
+
type RoleTargetKind = 'background' | 'foreground' | 'border' | 'accent';
|
|
3295
|
+
/** A single token path that a role assignment writes to */
|
|
3296
|
+
interface RoleTarget {
|
|
3297
|
+
/** Theme token path (e.g., 'components.message.user.background') */
|
|
3298
|
+
path: string;
|
|
3299
|
+
/** What kind of value this target expects */
|
|
3300
|
+
kind: RoleTargetKind;
|
|
3301
|
+
}
|
|
3302
|
+
/** An intensity preset (e.g., Solid uses .500 shades, Soft uses .100 shades) */
|
|
3303
|
+
interface RoleIntensity {
|
|
3304
|
+
id: string;
|
|
3305
|
+
label: string;
|
|
3306
|
+
}
|
|
3307
|
+
/** Options for a role-assignment field */
|
|
3308
|
+
interface RoleAssignmentOptions {
|
|
3309
|
+
/** Unique role identifier */
|
|
3310
|
+
roleId: string;
|
|
3311
|
+
/** Helper text shown below the role name */
|
|
3312
|
+
helper: string;
|
|
3313
|
+
/** Token paths this role writes to */
|
|
3314
|
+
targets: RoleTarget[];
|
|
3315
|
+
/** Available intensity presets */
|
|
3316
|
+
intensities: RoleIntensity[];
|
|
3317
|
+
/** Which data-persona-theme-zone this role corresponds to (for preview highlighting) */
|
|
3318
|
+
previewZone?: string;
|
|
3319
|
+
}
|
|
3320
|
+
interface FieldDef {
|
|
3321
|
+
id: string;
|
|
3322
|
+
label: string;
|
|
3323
|
+
description?: string;
|
|
3324
|
+
type: FieldType;
|
|
3325
|
+
/** Dot-path into the config/theme object */
|
|
3326
|
+
path: string;
|
|
3327
|
+
defaultValue?: unknown;
|
|
3328
|
+
/** Slider-specific options */
|
|
3329
|
+
slider?: SliderOptions;
|
|
3330
|
+
/** Select-specific options */
|
|
3331
|
+
options?: SelectOption[];
|
|
3332
|
+
/** Color-scale-specific options */
|
|
3333
|
+
colorScale?: ColorScaleOptions;
|
|
3334
|
+
/** Token-ref-specific options */
|
|
3335
|
+
tokenRef?: TokenRefOptions;
|
|
3336
|
+
/** Role-assignment-specific options */
|
|
3337
|
+
roleAssignment?: RoleAssignmentOptions;
|
|
3338
|
+
/** CSS property hint for value formatting */
|
|
3339
|
+
cssProperty?: string;
|
|
3340
|
+
/** Whether this is a theme path (vs config path) */
|
|
3341
|
+
isThemePath?: boolean;
|
|
3342
|
+
/** Convert stored value into a control-friendly value */
|
|
3343
|
+
formatValue?: (value: unknown) => unknown;
|
|
3344
|
+
/** Convert control input back into the stored value shape */
|
|
3345
|
+
parseValue?: (value: unknown) => unknown;
|
|
3346
|
+
}
|
|
3347
|
+
interface SectionDef {
|
|
3348
|
+
id: string;
|
|
3349
|
+
title: string;
|
|
3350
|
+
description?: string;
|
|
3351
|
+
fields: FieldDef[];
|
|
3352
|
+
/** Whether the section starts collapsed */
|
|
3353
|
+
collapsed?: boolean;
|
|
3354
|
+
/** Preset buttons for this section */
|
|
3355
|
+
presets?: SectionPreset[];
|
|
3356
|
+
}
|
|
3357
|
+
interface SectionPreset {
|
|
3358
|
+
id: string;
|
|
3359
|
+
label: string;
|
|
3360
|
+
values: Record<string, unknown>;
|
|
3361
|
+
}
|
|
3362
|
+
interface TabDef {
|
|
3363
|
+
id: string;
|
|
3364
|
+
label: string;
|
|
3365
|
+
icon?: string;
|
|
3366
|
+
sections: SectionDef[];
|
|
3367
|
+
}
|
|
3368
|
+
interface SubGroupDef {
|
|
3369
|
+
label: string;
|
|
3370
|
+
sections: SectionDef[];
|
|
3371
|
+
/** When true, the sub-group starts collapsed and must be explicitly expanded */
|
|
3372
|
+
collapsedByDefault?: boolean;
|
|
3373
|
+
}
|
|
3374
|
+
/** Extract the toolCall config type from AgentWidgetConfig */
|
|
3375
|
+
type AgentWidgetToolCallConfig = NonNullable<AgentWidgetConfig['toolCall']>;
|
|
3376
|
+
interface ThemeEditorPreset {
|
|
3377
|
+
id: string;
|
|
3378
|
+
name: string;
|
|
3379
|
+
description: string;
|
|
3380
|
+
theme: DeepPartial<PersonaTheme>;
|
|
3381
|
+
darkTheme?: DeepPartial<PersonaTheme>;
|
|
3382
|
+
/** Tool call styling for light mode */
|
|
3383
|
+
toolCall?: AgentWidgetToolCallConfig;
|
|
3384
|
+
/** Tool call styling for dark mode (falls back to toolCall if not set) */
|
|
3385
|
+
darkToolCall?: AgentWidgetToolCallConfig;
|
|
3386
|
+
preview: {
|
|
3387
|
+
primary: string;
|
|
3388
|
+
surface: string;
|
|
3389
|
+
accent: string;
|
|
3390
|
+
};
|
|
3391
|
+
darkPreview?: {
|
|
3392
|
+
primary: string;
|
|
3393
|
+
surface: string;
|
|
3394
|
+
accent: string;
|
|
3395
|
+
};
|
|
3396
|
+
/** Tags for filtering/categorization */
|
|
3397
|
+
tags?: string[];
|
|
3398
|
+
}
|
|
3399
|
+
interface ConfiguratorSnapshot {
|
|
3400
|
+
version: 2;
|
|
3401
|
+
config: Record<string, unknown>;
|
|
3402
|
+
theme: PersonaTheme;
|
|
3403
|
+
}
|
|
3404
|
+
type ConfigChangeListener = (config: AgentWidgetConfig, theme: PersonaTheme) => void;
|
|
3405
|
+
/** Callback for when a control value changes */
|
|
3406
|
+
type OnChangeCallback = (path: string, value: unknown) => void;
|
|
3407
|
+
|
|
3408
|
+
/** Headless state management for the theme editor (no DOM, no localStorage, no side effects) */
|
|
3409
|
+
|
|
3410
|
+
declare class ThemeEditorState {
|
|
3411
|
+
private config;
|
|
3412
|
+
private theme;
|
|
3413
|
+
private listeners;
|
|
3414
|
+
private history;
|
|
3415
|
+
private historyIndex;
|
|
3416
|
+
private suppressHistory;
|
|
3417
|
+
constructor(initialTheme?: Partial<PersonaTheme>, initialConfig?: Partial<AgentWidgetConfig>, options?: {
|
|
3418
|
+
mergeDefaults?: boolean;
|
|
3419
|
+
});
|
|
3420
|
+
/**
|
|
3421
|
+
* Get a value using a dot-path.
|
|
3422
|
+
* - `theme.*` → reads from the PersonaTheme
|
|
3423
|
+
* - `darkTheme.*` → reads from config.darkTheme
|
|
3424
|
+
* - everything else → reads from the AgentWidgetConfig
|
|
3425
|
+
*/
|
|
3426
|
+
get(path: string): unknown;
|
|
3427
|
+
getTheme(): PersonaTheme;
|
|
3428
|
+
getConfig(): AgentWidgetConfig;
|
|
3429
|
+
/**
|
|
3430
|
+
* Set a value using a dot-path.
|
|
3431
|
+
* - `theme.*` → writes into the PersonaTheme
|
|
3432
|
+
* - `darkTheme.*` → writes into config.darkTheme
|
|
3433
|
+
* - everything else → writes into AgentWidgetConfig
|
|
3434
|
+
*/
|
|
3435
|
+
set(path: string, value: unknown): void;
|
|
3436
|
+
/** Batch-set multiple paths at once */
|
|
3437
|
+
setBatch(updates: Record<string, unknown>): void;
|
|
3438
|
+
/** Replace the entire theme */
|
|
3439
|
+
setTheme(theme: PersonaTheme): void;
|
|
3440
|
+
/** Replace the entire config (for preset loading) */
|
|
3441
|
+
setFullConfig(config: AgentWidgetConfig, theme?: PersonaTheme): void;
|
|
3442
|
+
/** Import a snapshot (v2 or raw theme) */
|
|
3443
|
+
importSnapshot(snapshot: unknown): void;
|
|
3444
|
+
/** Reset to defaults */
|
|
3445
|
+
resetToDefaults(): void;
|
|
3446
|
+
canUndo(): boolean;
|
|
3447
|
+
canRedo(): boolean;
|
|
3448
|
+
getHistoryLength(): number;
|
|
3449
|
+
getHistoryIndex(): number;
|
|
3450
|
+
undo(): void;
|
|
3451
|
+
redo(): void;
|
|
3452
|
+
exportSnapshot(): ConfiguratorSnapshot;
|
|
3453
|
+
onChange(listener: ConfigChangeListener): () => void;
|
|
3454
|
+
private syncThemeIntoConfig;
|
|
3455
|
+
private notifyListeners;
|
|
3456
|
+
private recordHistory;
|
|
3457
|
+
private pushHistorySnapshot;
|
|
3458
|
+
private restoreSnapshot;
|
|
3459
|
+
}
|
|
3460
|
+
|
|
3461
|
+
/** Declarative section/field definitions for the theme editor (pure data — no DOM, no render logic) */
|
|
3462
|
+
|
|
3463
|
+
declare const STYLE_SECTIONS: SectionDef[];
|
|
3464
|
+
declare const PALETTE_SECTION: SectionDef;
|
|
3465
|
+
declare const SEMANTIC_COLORS_SECTION: SectionDef;
|
|
3466
|
+
declare const COLORS_SECTIONS: SectionDef[];
|
|
3467
|
+
/** Shared shape sections (not scoped to light/dark) */
|
|
3468
|
+
declare const COMPONENT_SHAPE_SECTIONS: SectionDef[];
|
|
3469
|
+
/** Component color sections (can be scoped for light/dark) */
|
|
3470
|
+
declare const COMPONENT_COLOR_SECTIONS: SectionDef[];
|
|
3471
|
+
declare const COMPONENTS_SECTIONS: SectionDef[];
|
|
3472
|
+
declare const CONFIGURE_SUB_GROUPS: SubGroupDef[];
|
|
3473
|
+
declare const CONFIGURE_SECTIONS: SectionDef[];
|
|
3474
|
+
/** Section 1: Theme — color mode selection */
|
|
3475
|
+
declare const THEME_SECTION: SectionDef;
|
|
3476
|
+
/** Section 2: Brand Palette — primary colors + collapsed status colors */
|
|
3477
|
+
declare const BRAND_PALETTE_SECTION: SectionDef;
|
|
3478
|
+
/** Section 2b: Status palette — collapsed under Brand Palette */
|
|
3479
|
+
declare const STATUS_PALETTE_SECTION: SectionDef;
|
|
3480
|
+
/** Section 3: Interface Roles — the main theming surface */
|
|
3481
|
+
declare const INTERFACE_ROLES_SECTION: SectionDef;
|
|
3482
|
+
/** Section 4: Status Colors — feedback semantic tokens */
|
|
3483
|
+
declare const STATUS_COLORS_SECTION: SectionDef;
|
|
3484
|
+
/** Section 5: Advanced Tokens — entry point for drill-downs (no fields) */
|
|
3485
|
+
declare const ADVANCED_TOKENS_SECTION: SectionDef;
|
|
3486
|
+
/** V2 Style tab sections — outcome-oriented editor */
|
|
3487
|
+
declare const STYLE_SECTIONS_V2: SectionDef[];
|
|
3488
|
+
declare const ALL_TABS: TabDef[];
|
|
3489
|
+
type ThemeScope = 'theme' | 'darkTheme';
|
|
3490
|
+
type ThemeVariant = 'light' | 'dark';
|
|
3491
|
+
/** Look up a section by ID from an array of sections */
|
|
3492
|
+
declare function findSection(sections: SectionDef[], id: string): SectionDef;
|
|
3493
|
+
/** Create a light/dark scoped copy of a section */
|
|
3494
|
+
declare function scopeSection(section: SectionDef, scope: ThemeScope, variant: ThemeVariant, collapsed?: boolean | undefined): SectionDef;
|
|
3495
|
+
|
|
3496
|
+
/** Theme editor presets — unified collection of built-in presets */
|
|
3497
|
+
|
|
3498
|
+
declare const BUILT_IN_PRESETS: ThemeEditorPreset[];
|
|
3499
|
+
/** All built-in presets */
|
|
3500
|
+
declare const THEME_EDITOR_PRESETS: ThemeEditorPreset[];
|
|
3501
|
+
/** Look up a preset by ID */
|
|
3502
|
+
declare function getThemeEditorPreset(id: string): ThemeEditorPreset | undefined;
|
|
3503
|
+
|
|
3504
|
+
type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error";
|
|
3505
|
+
|
|
3506
|
+
/**
|
|
3507
|
+
* Feedback UI components for CSAT and NPS collection
|
|
3508
|
+
*/
|
|
3509
|
+
type CSATFeedbackOptions = {
|
|
3510
|
+
/** Callback when user submits CSAT feedback */
|
|
3511
|
+
onSubmit: (rating: number, comment?: string) => void | Promise<void>;
|
|
3512
|
+
/** Callback when user dismisses the feedback form */
|
|
3513
|
+
onDismiss?: () => void;
|
|
3514
|
+
/** Title text */
|
|
3515
|
+
title?: string;
|
|
3516
|
+
/** Subtitle/question text */
|
|
3517
|
+
subtitle?: string;
|
|
3518
|
+
/** Placeholder for optional comment field */
|
|
3519
|
+
commentPlaceholder?: string;
|
|
3520
|
+
/** Submit button text */
|
|
3521
|
+
submitText?: string;
|
|
3522
|
+
/** Skip button text */
|
|
3523
|
+
skipText?: string;
|
|
3524
|
+
/** Show comment field */
|
|
3525
|
+
showComment?: boolean;
|
|
3526
|
+
/** Rating labels (5 items for ratings 1-5) */
|
|
3527
|
+
ratingLabels?: [string, string, string, string, string];
|
|
3528
|
+
};
|
|
3529
|
+
type NPSFeedbackOptions = {
|
|
3530
|
+
/** Callback when user submits NPS feedback */
|
|
3531
|
+
onSubmit: (rating: number, comment?: string) => void | Promise<void>;
|
|
3532
|
+
/** Callback when user dismisses the feedback form */
|
|
3533
|
+
onDismiss?: () => void;
|
|
3534
|
+
/** Title text */
|
|
3535
|
+
title?: string;
|
|
3536
|
+
/** Subtitle/question text */
|
|
3537
|
+
subtitle?: string;
|
|
3538
|
+
/** Placeholder for optional comment field */
|
|
3539
|
+
commentPlaceholder?: string;
|
|
3540
|
+
/** Submit button text */
|
|
3541
|
+
submitText?: string;
|
|
3542
|
+
/** Skip button text */
|
|
3543
|
+
skipText?: string;
|
|
3544
|
+
/** Show comment field */
|
|
3545
|
+
showComment?: boolean;
|
|
3546
|
+
/** Low label (left side) */
|
|
3547
|
+
lowLabel?: string;
|
|
3548
|
+
/** High label (right side) */
|
|
3549
|
+
highLabel?: string;
|
|
3550
|
+
};
|
|
3551
|
+
|
|
3552
|
+
type Controller = {
|
|
3553
|
+
update: (config: AgentWidgetConfig) => void;
|
|
3554
|
+
destroy: () => void;
|
|
3555
|
+
open: () => void;
|
|
3556
|
+
close: () => void;
|
|
3557
|
+
toggle: () => void;
|
|
3558
|
+
clearChat: () => void;
|
|
3559
|
+
setMessage: (message: string) => boolean;
|
|
3560
|
+
submitMessage: (message?: string) => boolean;
|
|
3561
|
+
startVoiceRecognition: () => boolean;
|
|
3562
|
+
stopVoiceRecognition: () => boolean;
|
|
3563
|
+
/**
|
|
3564
|
+
* Inject a message into the conversation with dual-content support.
|
|
3565
|
+
* Auto-opens the widget if closed and launcher is enabled.
|
|
3566
|
+
*/
|
|
3567
|
+
injectMessage: (options: InjectMessageOptions) => AgentWidgetMessage;
|
|
3568
|
+
/**
|
|
3569
|
+
* Convenience method for injecting assistant messages.
|
|
3570
|
+
*/
|
|
3571
|
+
injectAssistantMessage: (options: InjectAssistantMessageOptions) => AgentWidgetMessage;
|
|
3572
|
+
/**
|
|
3573
|
+
* Convenience method for injecting user messages.
|
|
3574
|
+
*/
|
|
3575
|
+
injectUserMessage: (options: InjectUserMessageOptions) => AgentWidgetMessage;
|
|
3576
|
+
/**
|
|
3577
|
+
* Convenience method for injecting system messages.
|
|
3578
|
+
*/
|
|
3579
|
+
injectSystemMessage: (options: InjectSystemMessageOptions) => AgentWidgetMessage;
|
|
3580
|
+
/**
|
|
3581
|
+
* Inject multiple messages in a single batch with one sort and one render pass.
|
|
3582
|
+
*/
|
|
3583
|
+
injectMessageBatch: (optionsList: InjectMessageOptions[]) => AgentWidgetMessage[];
|
|
3584
|
+
/**
|
|
3585
|
+
* @deprecated Use injectMessage() instead.
|
|
3586
|
+
*/
|
|
3587
|
+
injectTestMessage: (event: AgentWidgetEvent) => void;
|
|
3588
|
+
getMessages: () => AgentWidgetMessage[];
|
|
3589
|
+
getStatus: () => AgentWidgetSessionStatus;
|
|
3590
|
+
getPersistentMetadata: () => Record<string, unknown>;
|
|
3591
|
+
updatePersistentMetadata: (updater: (prev: Record<string, unknown>) => Record<string, unknown>) => void;
|
|
3592
|
+
on: <K extends keyof AgentWidgetControllerEventMap>(event: K, handler: (payload: AgentWidgetControllerEventMap[K]) => void) => () => void;
|
|
3593
|
+
off: <K extends keyof AgentWidgetControllerEventMap>(event: K, handler: (payload: AgentWidgetControllerEventMap[K]) => void) => void;
|
|
3594
|
+
isOpen: () => boolean;
|
|
3595
|
+
isVoiceActive: () => boolean;
|
|
3596
|
+
getState: () => AgentWidgetStateSnapshot;
|
|
3597
|
+
showCSATFeedback: (options?: Partial<CSATFeedbackOptions>) => void;
|
|
3598
|
+
showNPSFeedback: (options?: Partial<NPSFeedbackOptions>) => void;
|
|
3599
|
+
submitCSATFeedback: (rating: number, comment?: string) => Promise<void>;
|
|
3600
|
+
submitNPSFeedback: (rating: number, comment?: string) => Promise<void>;
|
|
3601
|
+
/**
|
|
3602
|
+
* Connect an external SSE stream and process it through the SDK's
|
|
3603
|
+
* native event pipeline (tools, reasoning, streaming text, etc.).
|
|
3604
|
+
*/
|
|
3605
|
+
connectStream: (stream: ReadableStream<Uint8Array>, options?: {
|
|
3606
|
+
assistantMessageId?: string;
|
|
3607
|
+
}) => Promise<void>;
|
|
3608
|
+
/** Push a raw event into the event stream buffer (for testing/debugging) */
|
|
3609
|
+
__pushEventStreamEvent: (event: {
|
|
3610
|
+
type: string;
|
|
3611
|
+
payload: unknown;
|
|
3612
|
+
}) => void;
|
|
3613
|
+
/** Opens the event stream panel */
|
|
3614
|
+
showEventStream: () => void;
|
|
3615
|
+
/** Closes the event stream panel */
|
|
3616
|
+
hideEventStream: () => void;
|
|
3617
|
+
/** Returns current visibility state of the event stream panel */
|
|
3618
|
+
isEventStreamVisible: () => boolean;
|
|
3619
|
+
/** Show artifact sidebar (no-op if features.artifacts.enabled is false) */
|
|
3620
|
+
showArtifacts: () => void;
|
|
3621
|
+
/** Hide artifact sidebar */
|
|
3622
|
+
hideArtifacts: () => void;
|
|
3623
|
+
/** Upsert an artifact programmatically */
|
|
3624
|
+
upsertArtifact: (manual: PersonaArtifactManualUpsert) => PersonaArtifactRecord | null;
|
|
3625
|
+
selectArtifact: (id: string) => void;
|
|
3626
|
+
clearArtifacts: () => void;
|
|
3627
|
+
/**
|
|
3628
|
+
* Focus the chat input. Returns true if focus succeeded, false if panel is closed
|
|
3629
|
+
* (launcher mode) or textarea is unavailable.
|
|
3630
|
+
*/
|
|
3631
|
+
focusInput: () => boolean;
|
|
3632
|
+
/**
|
|
3633
|
+
* Programmatically resolve a pending approval.
|
|
3634
|
+
* @param approvalId - The approval ID to resolve
|
|
3635
|
+
* @param decision - "approved" or "denied"
|
|
3636
|
+
*/
|
|
3637
|
+
resolveApproval: (approvalId: string, decision: 'approved' | 'denied') => Promise<void>;
|
|
3638
|
+
};
|
|
3639
|
+
type AgentWidgetController = Controller;
|
|
3640
|
+
|
|
3641
|
+
/**
|
|
3642
|
+
* Shared preview building blocks for theme editor preview renderers.
|
|
3643
|
+
* Used by both `createThemePreview()` (simple API) and the configurator's
|
|
3644
|
+
* advanced preview system. Separate file for code-splitting.
|
|
3645
|
+
*/
|
|
3646
|
+
|
|
3647
|
+
declare const DEVICE_DIMENSIONS: Record<string, {
|
|
3648
|
+
w: number;
|
|
3649
|
+
h: number;
|
|
3650
|
+
}>;
|
|
3651
|
+
declare const ZOOM_MIN = 0.15;
|
|
3652
|
+
declare const ZOOM_MAX = 1.5;
|
|
3653
|
+
declare const SHELL_STYLE_ID = "persona-preview-shell-theme";
|
|
3654
|
+
declare const PREVIEW_STORAGE_ADAPTER: {
|
|
3655
|
+
load: () => null;
|
|
3656
|
+
save: () => void;
|
|
3657
|
+
clear: () => void;
|
|
3658
|
+
};
|
|
3659
|
+
declare const HOME_SUGGESTION_CHIPS: string[];
|
|
3660
|
+
declare function escapeHtml(str: string): string;
|
|
3661
|
+
type PreviewShellPalette = {
|
|
3662
|
+
pageBg: string;
|
|
3663
|
+
chromeBg: string;
|
|
3664
|
+
chromeBorder: string;
|
|
3665
|
+
dot: string;
|
|
3666
|
+
skeleton: string;
|
|
3667
|
+
cardBg: string;
|
|
3668
|
+
cardBorder: string;
|
|
3669
|
+
};
|
|
3670
|
+
declare function getShellPalette(shellMode: 'light' | 'dark'): PreviewShellPalette;
|
|
3671
|
+
declare function buildShellCss(shellMode: 'light' | 'dark'): string;
|
|
3672
|
+
declare function applyShellTheme(iframe: HTMLIFrameElement, shellMode: 'light' | 'dark'): void;
|
|
3673
|
+
/** Browser chrome mock with skeleton content cards */
|
|
3674
|
+
declare const MOCK_BROWSER_CONTENT = "\n <div class=\"preview-iframe-mock\" aria-hidden=\"true\">\n <div class=\"preview-iframe-chrome\">\n <span class=\"preview-iframe-dot\"></span>\n <span class=\"preview-iframe-dot\"></span>\n <span class=\"preview-iframe-dot\"></span>\n </div>\n <div class=\"preview-iframe-copy\">\n <div class=\"preview-iframe-line hero\"></div>\n <div class=\"preview-iframe-line body\"></div>\n <div class=\"preview-iframe-line body\"></div>\n <div class=\"preview-iframe-grid\">\n <div class=\"preview-iframe-card\"></div>\n <div class=\"preview-iframe-card\"></div>\n <div class=\"preview-iframe-card\"></div>\n </div>\n <div class=\"preview-iframe-line body\"></div>\n <div class=\"preview-iframe-line body\"></div>\n </div>\n </div>";
|
|
3675
|
+
/** Docked workspace skeleton (cards + rows inside content area) */
|
|
3676
|
+
declare const MOCK_WORKSPACE_CONTENT = "\n <div class=\"preview-workspace-content-shell\" aria-hidden=\"true\">\n <div class=\"preview-iframe-line hero\"></div>\n <div class=\"preview-iframe-line body\"></div>\n <div class=\"preview-workspace-row\">\n <div class=\"preview-workspace-card\"></div>\n <div class=\"preview-workspace-card\"></div>\n </div>\n <div class=\"preview-workspace-row\">\n <div class=\"preview-workspace-card short\"></div>\n <div class=\"preview-workspace-card short\"></div>\n <div class=\"preview-workspace-card short\"></div>\n </div>\n </div>";
|
|
3677
|
+
/**
|
|
3678
|
+
* Build a basic iframe srcdoc with mock page chrome and widget mount point.
|
|
3679
|
+
* For advanced use cases (background URLs, embed detection), build custom srcdoc
|
|
3680
|
+
* using the exported templates and shell CSS utilities.
|
|
3681
|
+
*/
|
|
3682
|
+
declare function buildSrcdoc(mountId: string, shellMode: 'light' | 'dark', docked: boolean, widgetCssPath: string): string;
|
|
3683
|
+
type PreviewScene = 'home' | 'conversation' | 'minimized' | 'artifact';
|
|
3684
|
+
declare function createPreviewMessages(scene: PreviewScene): AgentWidgetMessage[];
|
|
3685
|
+
declare function applySceneConfig(base: AgentWidgetConfig, scene: PreviewScene): AgentWidgetConfig;
|
|
3686
|
+
|
|
3687
|
+
interface PreviewConfigOptions {
|
|
3688
|
+
config?: Partial<AgentWidgetConfig>;
|
|
3689
|
+
theme?: DeepPartial<PersonaTheme>;
|
|
3690
|
+
darkTheme?: DeepPartial<PersonaTheme>;
|
|
3691
|
+
scene?: PreviewScene;
|
|
3692
|
+
}
|
|
3693
|
+
declare function buildPreviewConfig(options: PreviewConfigOptions, shellModeOverride?: 'light' | 'dark'): AgentWidgetConfig;
|
|
3694
|
+
|
|
3695
|
+
/**
|
|
3696
|
+
* Imperative preview renderer for the theme editor.
|
|
3697
|
+
* Manages iframe-based widget previews with device frames, zoom, scenes, and compare mode.
|
|
3698
|
+
* No external DOM dependencies — only needs a container element to mount into.
|
|
3699
|
+
*
|
|
3700
|
+
* For advanced preview needs (background URLs, inline editing, contrast checking),
|
|
3701
|
+
* use the lifecycle hooks in `ThemePreviewOptions` and import shared building blocks
|
|
3702
|
+
* from `./preview-utils` directly.
|
|
3703
|
+
*/
|
|
3704
|
+
|
|
3705
|
+
type PreviewDevice = 'desktop' | 'mobile';
|
|
3706
|
+
|
|
3707
|
+
type PreviewShellMode = 'light' | 'dark';
|
|
3708
|
+
type CompareMode = 'off' | 'baseline' | 'themes';
|
|
3709
|
+
/** Context passed to lifecycle hooks after mounting or updating */
|
|
3710
|
+
interface PreviewLifecycleContext {
|
|
3711
|
+
iframes: HTMLIFrameElement[];
|
|
3712
|
+
controllers: AgentWidgetController[];
|
|
3713
|
+
}
|
|
3714
|
+
interface ThemePreviewOptions {
|
|
3715
|
+
/** Device frame dimensions */
|
|
3716
|
+
device?: PreviewDevice;
|
|
3717
|
+
/** Widget state */
|
|
3718
|
+
scene?: PreviewScene;
|
|
3719
|
+
/** Browser chrome appearance */
|
|
3720
|
+
shellMode?: PreviewShellMode;
|
|
3721
|
+
/** Side-by-side comparison */
|
|
3722
|
+
compareMode?: CompareMode;
|
|
3723
|
+
/** Widget config */
|
|
3724
|
+
config?: Partial<AgentWidgetConfig>;
|
|
3725
|
+
/** Light mode theme */
|
|
3726
|
+
theme?: DeepPartial<PersonaTheme>;
|
|
3727
|
+
/** Dark mode theme */
|
|
3728
|
+
darkTheme?: DeepPartial<PersonaTheme>;
|
|
3729
|
+
/** Zoom level (0.15–1.5), or undefined for auto-fit */
|
|
3730
|
+
zoom?: number;
|
|
3731
|
+
/** Path to widget.css (defaults to looking for /widget-dist/widget.css) */
|
|
3732
|
+
widgetCssPath?: string;
|
|
3733
|
+
/** Config for the baseline side of a baseline comparison */
|
|
3734
|
+
baselineConfig?: Partial<AgentWidgetConfig>;
|
|
3735
|
+
/** Theme for the baseline side of a baseline comparison */
|
|
3736
|
+
baselineTheme?: DeepPartial<PersonaTheme>;
|
|
3737
|
+
/** Dark theme for the baseline side of a baseline comparison */
|
|
3738
|
+
baselineDarkTheme?: DeepPartial<PersonaTheme>;
|
|
3739
|
+
/** Called after all iframes load and widgets mount */
|
|
3740
|
+
onAfterMount?: (ctx: PreviewLifecycleContext) => void;
|
|
3741
|
+
/** Called after fast-path controller updates */
|
|
3742
|
+
onAfterUpdate?: (ctx: PreviewLifecycleContext) => void;
|
|
3743
|
+
/** Called before controllers are destroyed */
|
|
3744
|
+
onBeforeDestroy?: () => void;
|
|
3745
|
+
/** Called whenever the preview scale changes */
|
|
3746
|
+
onScaleChange?: (scale: number) => void;
|
|
3747
|
+
/** Override iframe srcdoc generation (for background URLs, etc.) */
|
|
3748
|
+
buildSrcdoc?: (mountId: string, shellMode: PreviewShellMode, docked: boolean, cssPath: string) => string;
|
|
3749
|
+
/** Override container HTML injection (for Idiomorph, etc.) */
|
|
3750
|
+
morphContainer?: (container: HTMLElement, html: string) => void;
|
|
3751
|
+
}
|
|
3752
|
+
interface ThemePreviewHandle {
|
|
3753
|
+
/** Update the preview (fast path when possible, full remount when needed) */
|
|
3754
|
+
update(options: Partial<ThemePreviewOptions>): void;
|
|
3755
|
+
/** Destroy preview and clean up */
|
|
3756
|
+
destroy(): void;
|
|
3757
|
+
/** Get live widget controllers */
|
|
3758
|
+
getControllers(): AgentWidgetController[];
|
|
3759
|
+
/** Recalculate auto-fit zoom */
|
|
3760
|
+
fitToContainer(): void;
|
|
3761
|
+
/** Get all preview iframes */
|
|
3762
|
+
getIframes(): HTMLIFrameElement[];
|
|
3763
|
+
/** Get current computed scale */
|
|
3764
|
+
getScale(): number;
|
|
3765
|
+
/** Set explicit zoom (or undefined to auto-fit) */
|
|
3766
|
+
setZoom(zoom: number | undefined): void;
|
|
3767
|
+
}
|
|
3768
|
+
declare function createThemePreview(container: HTMLElement, initialOptions: ThemePreviewOptions): ThemePreviewHandle;
|
|
3769
|
+
|
|
3770
|
+
/**
|
|
3771
|
+
* Interface Role → Token mapping layer.
|
|
3772
|
+
*
|
|
3773
|
+
* Maps high-level editor choices (family + intensity) to concrete palette
|
|
3774
|
+
* token references across multiple component/semantic paths. This is the
|
|
3775
|
+
* core of the "Interface Roles" editor section — one picker writes to
|
|
3776
|
+
* many tokens atomically.
|
|
3777
|
+
*
|
|
3778
|
+
* All functions are pure and headless (no DOM).
|
|
3779
|
+
*/
|
|
3780
|
+
|
|
3781
|
+
declare const ROLE_INTENSITIES: RoleIntensity[];
|
|
3782
|
+
declare const ROLE_FAMILIES: readonly ["primary", "secondary", "accent", "gray"];
|
|
3783
|
+
type RoleFamily = (typeof ROLE_FAMILIES)[number];
|
|
3784
|
+
/** Display labels for palette families in the editor */
|
|
3785
|
+
declare const ROLE_FAMILY_LABELS: Record<RoleFamily, string>;
|
|
3786
|
+
declare const ROLE_SURFACES: RoleAssignmentOptions;
|
|
3787
|
+
declare const ROLE_HEADER: RoleAssignmentOptions;
|
|
3788
|
+
declare const ROLE_USER_MESSAGES: RoleAssignmentOptions;
|
|
3789
|
+
declare const ROLE_ASSISTANT_MESSAGES: RoleAssignmentOptions;
|
|
3790
|
+
declare const ROLE_PRIMARY_ACTIONS: RoleAssignmentOptions;
|
|
3791
|
+
declare const ROLE_INPUT: RoleAssignmentOptions;
|
|
3792
|
+
declare const ROLE_LINKS_FOCUS: RoleAssignmentOptions;
|
|
3793
|
+
declare const ROLE_BORDERS: RoleAssignmentOptions;
|
|
3794
|
+
/** All interface role definitions in display order */
|
|
3795
|
+
declare const ALL_ROLES: RoleAssignmentOptions[];
|
|
3796
|
+
/**
|
|
3797
|
+
* Resolve a role assignment (family + intensity) into concrete token writes.
|
|
3798
|
+
*
|
|
3799
|
+
* Returns a map of `{ "theme.{path}": "palette.colors.{family}.{shade}" }`.
|
|
3800
|
+
* The `theme.` prefix is added so callers can pass the result directly to
|
|
3801
|
+
* `state.setBatch()`.
|
|
3802
|
+
*/
|
|
3803
|
+
declare function resolveRoleAssignment(family: string, intensity: string, role: RoleAssignmentOptions): Record<string, string>;
|
|
3804
|
+
/** Result of detecting a role assignment from current state */
|
|
3805
|
+
interface DetectedRoleAssignment {
|
|
3806
|
+
family: RoleFamily;
|
|
3807
|
+
intensity: string;
|
|
3808
|
+
}
|
|
3809
|
+
/**
|
|
3810
|
+
* Detect the current role assignment by reading token values and matching
|
|
3811
|
+
* against known palette reference patterns.
|
|
3812
|
+
*
|
|
3813
|
+
* @param getValue - Function to read a theme token value (e.g., `(p) => state.get('theme.' + p)`)
|
|
3814
|
+
* @param role - The role definition to detect against
|
|
3815
|
+
* @returns Detected assignment or null if tokens don't match a known pattern
|
|
3816
|
+
*/
|
|
3817
|
+
declare function detectRoleAssignment(getValue: (path: string) => unknown, role: RoleAssignmentOptions): DetectedRoleAssignment | null;
|
|
3818
|
+
|
|
3819
|
+
/** Color parsing, normalization, and scale generation utilities (pure functions — no DOM) */
|
|
3820
|
+
|
|
3821
|
+
interface ParsedCssValue {
|
|
3822
|
+
value: number;
|
|
3823
|
+
unit: 'px' | 'rem';
|
|
3824
|
+
}
|
|
3825
|
+
declare function parseCssValue(cssValue: string): ParsedCssValue;
|
|
3826
|
+
declare function formatCssValue(value: number, unit: 'px' | 'rem'): string;
|
|
3827
|
+
declare function convertToPx(value: number, unit: 'px' | 'rem'): number;
|
|
3828
|
+
declare function convertFromPx(pxValue: number, unit: 'px' | 'rem'): number;
|
|
3829
|
+
declare function normalizeColorValue(value: string): string;
|
|
3830
|
+
declare function isValidHex(value: string): boolean;
|
|
3831
|
+
/**
|
|
3832
|
+
* Compute WCAG 2.x contrast ratio between two hex colors.
|
|
3833
|
+
* Returns a number ≥ 1 (e.g. 4.5 for AA normal text).
|
|
3834
|
+
*/
|
|
3835
|
+
declare function wcagContrastRatio(hex1: string, hex2: string): number;
|
|
3836
|
+
declare function hexToHsl(hex: string): {
|
|
3837
|
+
h: number;
|
|
3838
|
+
s: number;
|
|
3839
|
+
l: number;
|
|
3840
|
+
};
|
|
3841
|
+
declare function hslToHex(h: number, s: number, l: number): string;
|
|
3842
|
+
/**
|
|
3843
|
+
* Generate a full color scale (50-950) from a base color (shade 500).
|
|
3844
|
+
* Uses HSL-based lightness interpolation for natural-looking scales.
|
|
3845
|
+
*/
|
|
3846
|
+
declare function generateColorScale(baseHex: string): ColorShade;
|
|
3847
|
+
declare const SHADE_KEYS: readonly ["50", "100", "200", "300", "400", "500", "600", "700", "800", "900", "950"];
|
|
3848
|
+
declare const COLOR_FAMILIES: readonly ["primary", "secondary", "accent", "gray", "success", "warning", "error", "info"];
|
|
3849
|
+
declare function paletteColorPath(family: string, shade: string): string;
|
|
3850
|
+
/**
|
|
3851
|
+
* Resolve a theme dot-path to a concrete CSS color string.
|
|
3852
|
+
* Follows token references recursively (palette.*, semantic.*, components.*).
|
|
3853
|
+
*/
|
|
3854
|
+
declare function resolveThemeColorPath(get: (path: string) => unknown, path: string, depth?: number): string;
|
|
3855
|
+
declare function tokenRefDisplayName(path: string): string;
|
|
3856
|
+
|
|
3857
|
+
export { ADVANCED_TOKENS_SECTION, ALL_ROLES, ALL_TABS, BRAND_PALETTE_SECTION, BUILT_IN_PRESETS, COLORS_SECTIONS, COLOR_FAMILIES, COMPONENTS_SECTIONS, COMPONENT_COLOR_SECTIONS, COMPONENT_SHAPE_SECTIONS, CONFIGURE_SECTIONS, CONFIGURE_SUB_GROUPS, type ColorScaleOptions, type CompareMode, type ConfigChangeListener, type ConfiguratorSnapshot, DEVICE_DIMENSIONS, type DetectedRoleAssignment, type FieldDef, type FieldType, HOME_SUGGESTION_CHIPS, INTERFACE_ROLES_SECTION, MOCK_BROWSER_CONTENT, MOCK_WORKSPACE_CONTENT, type OnChangeCallback, PALETTE_SECTION, PREVIEW_STORAGE_ADAPTER, type PreviewConfigOptions, type PreviewDevice, type PreviewLifecycleContext, type PreviewScene, type PreviewShellMode, type PreviewShellPalette, ROLE_ASSISTANT_MESSAGES, ROLE_BORDERS, ROLE_FAMILIES, ROLE_FAMILY_LABELS, ROLE_HEADER, ROLE_INPUT, ROLE_INTENSITIES, ROLE_LINKS_FOCUS, ROLE_PRIMARY_ACTIONS, ROLE_SURFACES, ROLE_USER_MESSAGES, type RoleAssignmentOptions, type RoleFamily, type RoleIntensity, type RoleTarget, type RoleTargetKind, SEMANTIC_COLORS_SECTION, SHADE_KEYS, SHELL_STYLE_ID, STATUS_COLORS_SECTION, STATUS_PALETTE_SECTION, STYLE_SECTIONS, STYLE_SECTIONS_V2, type SectionDef, type SectionPreset, type SelectOption, type SliderOptions, type SubGroupDef, THEME_EDITOR_PRESETS, THEME_SECTION, type TabDef, type ThemeEditorPreset, ThemeEditorState, type ThemePreviewHandle, type ThemePreviewOptions, type TokenRefOptions, ZOOM_MAX, ZOOM_MIN, applySceneConfig, applyShellTheme, buildPreviewConfig, buildShellCss, buildSrcdoc, convertFromPx, convertToPx, createPreviewMessages, createThemePreview, detectRoleAssignment, escapeHtml, findSection, formatCssValue, generateColorScale, getShellPalette, getThemeEditorPreset, hexToHsl, hslToHex, isValidHex, normalizeColorValue, paletteColorPath, parseCssValue, resolveRoleAssignment, resolveThemeColorPath, scopeSection, tokenRefDisplayName, wcagContrastRatio };
|