vanilla-agent 1.10.0 → 1.11.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/README.md +57 -8
- package/dist/index.cjs +46 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +305 -1
- package/dist/index.d.ts +305 -1
- package/dist/index.global.js +69 -30
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +46 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/composer-builder.ts +366 -0
- package/src/components/header-builder.ts +454 -0
- package/src/components/header-layouts.ts +303 -0
- package/src/components/message-bubble.ts +251 -34
- package/src/components/panel.ts +46 -684
- package/src/defaults.ts +49 -1
- package/src/index.ts +43 -1
- package/src/runtime/init.ts +26 -0
- package/src/types.ts +231 -0
- package/src/ui.ts +452 -34
package/dist/index.d.cts
CHANGED
|
@@ -194,6 +194,24 @@ type AgentWidgetTheme = {
|
|
|
194
194
|
radiusLg?: string;
|
|
195
195
|
launcherRadius?: string;
|
|
196
196
|
buttonRadius?: string;
|
|
197
|
+
/**
|
|
198
|
+
* Border style for the chat panel container.
|
|
199
|
+
* @example "1px solid #e5e7eb" | "none"
|
|
200
|
+
* @default "1px solid var(--tvw-cw-border)"
|
|
201
|
+
*/
|
|
202
|
+
panelBorder?: string;
|
|
203
|
+
/**
|
|
204
|
+
* Box shadow for the chat panel container.
|
|
205
|
+
* @example "0 25px 50px -12px rgba(0,0,0,0.25)" | "none"
|
|
206
|
+
* @default "0 25px 50px -12px rgba(0,0,0,0.25)"
|
|
207
|
+
*/
|
|
208
|
+
panelShadow?: string;
|
|
209
|
+
/**
|
|
210
|
+
* Border radius for the chat panel container.
|
|
211
|
+
* @example "16px" | "0"
|
|
212
|
+
* @default "16px"
|
|
213
|
+
*/
|
|
214
|
+
panelBorderRadius?: string;
|
|
197
215
|
};
|
|
198
216
|
type AgentWidgetLauncherConfig = {
|
|
199
217
|
enabled?: boolean;
|
|
@@ -207,6 +225,35 @@ type AgentWidgetLauncherConfig = {
|
|
|
207
225
|
position?: "bottom-right" | "bottom-left" | "top-right" | "top-left";
|
|
208
226
|
autoExpand?: boolean;
|
|
209
227
|
width?: string;
|
|
228
|
+
/**
|
|
229
|
+
* When true, the widget panel will fill the full height of its container.
|
|
230
|
+
* Useful for sidebar layouts where the chat should take up the entire viewport height.
|
|
231
|
+
* The widget will use flex layout to ensure header stays at top, messages scroll in middle,
|
|
232
|
+
* and composer stays fixed at bottom.
|
|
233
|
+
*
|
|
234
|
+
* @default false
|
|
235
|
+
*/
|
|
236
|
+
fullHeight?: boolean;
|
|
237
|
+
/**
|
|
238
|
+
* When true, the widget panel will be positioned as a sidebar flush with the viewport edges.
|
|
239
|
+
* The panel will have:
|
|
240
|
+
* - No border-radius (square corners)
|
|
241
|
+
* - No margins (flush with top, left/right, and bottom edges)
|
|
242
|
+
* - Full viewport height
|
|
243
|
+
* - Subtle shadow on the edge facing the content
|
|
244
|
+
* - No border between footer and messages
|
|
245
|
+
*
|
|
246
|
+
* Use with `position` to control which side ('bottom-left' for left sidebar, 'bottom-right' for right sidebar).
|
|
247
|
+
* Automatically enables fullHeight when true.
|
|
248
|
+
*
|
|
249
|
+
* @default false
|
|
250
|
+
*/
|
|
251
|
+
sidebarMode?: boolean;
|
|
252
|
+
/**
|
|
253
|
+
* Width of the sidebar panel when sidebarMode is true.
|
|
254
|
+
* @default "420px"
|
|
255
|
+
*/
|
|
256
|
+
sidebarWidth?: string;
|
|
210
257
|
callToActionIconText?: string;
|
|
211
258
|
callToActionIconName?: string;
|
|
212
259
|
callToActionIconColor?: string;
|
|
@@ -249,6 +296,7 @@ type AgentWidgetSendButtonConfig = {
|
|
|
249
296
|
};
|
|
250
297
|
type AgentWidgetClearChatConfig = {
|
|
251
298
|
enabled?: boolean;
|
|
299
|
+
placement?: "inline" | "top-right";
|
|
252
300
|
iconName?: string;
|
|
253
301
|
iconColor?: string;
|
|
254
302
|
backgroundColor?: string;
|
|
@@ -396,6 +444,151 @@ type AgentWidgetCustomFetch = (url: string, init: RequestInit, payload: AgentWid
|
|
|
396
444
|
* Dynamic headers function - called before each request
|
|
397
445
|
*/
|
|
398
446
|
type AgentWidgetHeadersFunction = () => Record<string, string> | Promise<Record<string, string>>;
|
|
447
|
+
/**
|
|
448
|
+
* Context provided to header render functions
|
|
449
|
+
*/
|
|
450
|
+
type HeaderRenderContext = {
|
|
451
|
+
config: AgentWidgetConfig;
|
|
452
|
+
onClose?: () => void;
|
|
453
|
+
onClearChat?: () => void;
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Context provided to message render functions
|
|
457
|
+
*/
|
|
458
|
+
type MessageRenderContext = {
|
|
459
|
+
message: AgentWidgetMessage;
|
|
460
|
+
config: AgentWidgetConfig;
|
|
461
|
+
streaming: boolean;
|
|
462
|
+
};
|
|
463
|
+
/**
|
|
464
|
+
* Context provided to slot render functions
|
|
465
|
+
*/
|
|
466
|
+
type SlotRenderContext = {
|
|
467
|
+
config: AgentWidgetConfig;
|
|
468
|
+
defaultContent: () => HTMLElement | null;
|
|
469
|
+
};
|
|
470
|
+
/**
|
|
471
|
+
* Header layout configuration
|
|
472
|
+
* Allows customization of the header section appearance and behavior
|
|
473
|
+
*/
|
|
474
|
+
type AgentWidgetHeaderLayoutConfig = {
|
|
475
|
+
/**
|
|
476
|
+
* Layout preset: "default" | "minimal" | "expanded"
|
|
477
|
+
* - default: Standard layout with icon, title, subtitle, and buttons
|
|
478
|
+
* - minimal: Simplified layout with just title and close button
|
|
479
|
+
* - expanded: Full branding area with additional content space
|
|
480
|
+
*/
|
|
481
|
+
layout?: "default" | "minimal" | "expanded";
|
|
482
|
+
/** Show/hide the header icon */
|
|
483
|
+
showIcon?: boolean;
|
|
484
|
+
/** Show/hide the title */
|
|
485
|
+
showTitle?: boolean;
|
|
486
|
+
/** Show/hide the subtitle */
|
|
487
|
+
showSubtitle?: boolean;
|
|
488
|
+
/** Show/hide the close button */
|
|
489
|
+
showCloseButton?: boolean;
|
|
490
|
+
/** Show/hide the clear chat button */
|
|
491
|
+
showClearChat?: boolean;
|
|
492
|
+
/**
|
|
493
|
+
* Custom renderer for complete header override
|
|
494
|
+
* When provided, replaces the entire header with custom content
|
|
495
|
+
*/
|
|
496
|
+
render?: (context: HeaderRenderContext) => HTMLElement;
|
|
497
|
+
};
|
|
498
|
+
/**
|
|
499
|
+
* Avatar configuration for message bubbles
|
|
500
|
+
*/
|
|
501
|
+
type AgentWidgetAvatarConfig = {
|
|
502
|
+
/** Whether to show avatars */
|
|
503
|
+
show?: boolean;
|
|
504
|
+
/** Position of avatar relative to message bubble */
|
|
505
|
+
position?: "left" | "right";
|
|
506
|
+
/** URL or emoji for user avatar */
|
|
507
|
+
userAvatar?: string;
|
|
508
|
+
/** URL or emoji for assistant avatar */
|
|
509
|
+
assistantAvatar?: string;
|
|
510
|
+
};
|
|
511
|
+
/**
|
|
512
|
+
* Timestamp configuration for message bubbles
|
|
513
|
+
*/
|
|
514
|
+
type AgentWidgetTimestampConfig = {
|
|
515
|
+
/** Whether to show timestamps */
|
|
516
|
+
show?: boolean;
|
|
517
|
+
/** Position of timestamp relative to message */
|
|
518
|
+
position?: "inline" | "below";
|
|
519
|
+
/** Custom formatter for timestamp display */
|
|
520
|
+
format?: (date: Date) => string;
|
|
521
|
+
};
|
|
522
|
+
/**
|
|
523
|
+
* Message layout configuration
|
|
524
|
+
* Allows customization of how chat messages are displayed
|
|
525
|
+
*/
|
|
526
|
+
type AgentWidgetMessageLayoutConfig = {
|
|
527
|
+
/**
|
|
528
|
+
* Layout preset: "bubble" | "flat" | "minimal"
|
|
529
|
+
* - bubble: Standard chat bubble appearance (default)
|
|
530
|
+
* - flat: Flat messages without bubble styling
|
|
531
|
+
* - minimal: Minimal styling with reduced padding/borders
|
|
532
|
+
*/
|
|
533
|
+
layout?: "bubble" | "flat" | "minimal";
|
|
534
|
+
/** Avatar configuration */
|
|
535
|
+
avatar?: AgentWidgetAvatarConfig;
|
|
536
|
+
/** Timestamp configuration */
|
|
537
|
+
timestamp?: AgentWidgetTimestampConfig;
|
|
538
|
+
/** Group consecutive messages from the same role */
|
|
539
|
+
groupConsecutive?: boolean;
|
|
540
|
+
/**
|
|
541
|
+
* Custom renderer for user messages
|
|
542
|
+
* When provided, replaces the default user message rendering
|
|
543
|
+
*/
|
|
544
|
+
renderUserMessage?: (context: MessageRenderContext) => HTMLElement;
|
|
545
|
+
/**
|
|
546
|
+
* Custom renderer for assistant messages
|
|
547
|
+
* When provided, replaces the default assistant message rendering
|
|
548
|
+
*/
|
|
549
|
+
renderAssistantMessage?: (context: MessageRenderContext) => HTMLElement;
|
|
550
|
+
};
|
|
551
|
+
/**
|
|
552
|
+
* Available layout slots for content injection
|
|
553
|
+
*/
|
|
554
|
+
type WidgetLayoutSlot = "header-left" | "header-center" | "header-right" | "body-top" | "messages" | "body-bottom" | "footer-top" | "composer" | "footer-bottom";
|
|
555
|
+
/**
|
|
556
|
+
* Slot renderer function signature
|
|
557
|
+
* Returns HTMLElement to render in the slot, or null to use default content
|
|
558
|
+
*/
|
|
559
|
+
type SlotRenderer = (context: SlotRenderContext) => HTMLElement | null;
|
|
560
|
+
/**
|
|
561
|
+
* Main layout configuration
|
|
562
|
+
* Provides comprehensive control over widget layout and appearance
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```typescript
|
|
566
|
+
* config: {
|
|
567
|
+
* layout: {
|
|
568
|
+
* header: { layout: "minimal" },
|
|
569
|
+
* messages: {
|
|
570
|
+
* avatar: { show: true, assistantAvatar: "/bot.png" },
|
|
571
|
+
* timestamp: { show: true, position: "below" }
|
|
572
|
+
* },
|
|
573
|
+
* slots: {
|
|
574
|
+
* "footer-top": () => {
|
|
575
|
+
* const el = document.createElement("div");
|
|
576
|
+
* el.textContent = "Powered by AI";
|
|
577
|
+
* return el;
|
|
578
|
+
* }
|
|
579
|
+
* }
|
|
580
|
+
* }
|
|
581
|
+
* }
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
584
|
+
type AgentWidgetLayoutConfig = {
|
|
585
|
+
/** Header layout configuration */
|
|
586
|
+
header?: AgentWidgetHeaderLayoutConfig;
|
|
587
|
+
/** Message layout configuration */
|
|
588
|
+
messages?: AgentWidgetMessageLayoutConfig;
|
|
589
|
+
/** Slot renderers for custom content injection */
|
|
590
|
+
slots?: Partial<Record<WidgetLayoutSlot, SlotRenderer>>;
|
|
591
|
+
};
|
|
399
592
|
type AgentWidgetConfig = {
|
|
400
593
|
apiUrl?: string;
|
|
401
594
|
flowId?: string;
|
|
@@ -590,6 +783,21 @@ type AgentWidgetConfig = {
|
|
|
590
783
|
* ```
|
|
591
784
|
*/
|
|
592
785
|
parseSSEEvent?: AgentWidgetSSEEventParser;
|
|
786
|
+
/**
|
|
787
|
+
* Layout configuration for customizing widget appearance and structure.
|
|
788
|
+
* Provides control over header, messages, and content slots.
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* ```typescript
|
|
792
|
+
* config: {
|
|
793
|
+
* layout: {
|
|
794
|
+
* header: { layout: "minimal" },
|
|
795
|
+
* messages: { avatar: { show: true } }
|
|
796
|
+
* }
|
|
797
|
+
* }
|
|
798
|
+
* ```
|
|
799
|
+
*/
|
|
800
|
+
layout?: AgentWidgetLayoutConfig;
|
|
593
801
|
};
|
|
594
802
|
type AgentWidgetMessageRole = "user" | "assistant" | "system";
|
|
595
803
|
type AgentWidgetReasoning = {
|
|
@@ -960,6 +1168,17 @@ type MessageTransform = (context: {
|
|
|
960
1168
|
streaming: boolean;
|
|
961
1169
|
raw?: string;
|
|
962
1170
|
}) => string;
|
|
1171
|
+
declare const createTypingIndicator: () => HTMLElement;
|
|
1172
|
+
/**
|
|
1173
|
+
* Create standard message bubble
|
|
1174
|
+
* Supports layout configuration for avatars, timestamps, and visual presets
|
|
1175
|
+
*/
|
|
1176
|
+
declare const createStandardBubble: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig) => HTMLElement;
|
|
1177
|
+
/**
|
|
1178
|
+
* Create bubble with custom renderer support
|
|
1179
|
+
* Uses custom renderer if provided in layout config, otherwise falls back to standard bubble
|
|
1180
|
+
*/
|
|
1181
|
+
declare const createBubbleWithLayout: (message: AgentWidgetMessage, transform: MessageTransform, layoutConfig?: AgentWidgetMessageLayoutConfig) => HTMLElement;
|
|
963
1182
|
|
|
964
1183
|
/**
|
|
965
1184
|
* Options for component middleware
|
|
@@ -1011,4 +1230,89 @@ declare const DEFAULT_WIDGET_CONFIG: Partial<AgentWidgetConfig>;
|
|
|
1011
1230
|
*/
|
|
1012
1231
|
declare function mergeWithDefaults(config?: Partial<AgentWidgetConfig>): Partial<AgentWidgetConfig>;
|
|
1013
1232
|
|
|
1014
|
-
|
|
1233
|
+
interface HeaderElements {
|
|
1234
|
+
header: HTMLElement;
|
|
1235
|
+
iconHolder: HTMLElement;
|
|
1236
|
+
headerTitle: HTMLElement;
|
|
1237
|
+
headerSubtitle: HTMLElement;
|
|
1238
|
+
closeButton: HTMLButtonElement;
|
|
1239
|
+
closeButtonWrapper: HTMLElement;
|
|
1240
|
+
clearChatButton: HTMLButtonElement | null;
|
|
1241
|
+
clearChatButtonWrapper: HTMLElement | null;
|
|
1242
|
+
}
|
|
1243
|
+
interface HeaderBuildContext {
|
|
1244
|
+
config?: AgentWidgetConfig;
|
|
1245
|
+
showClose?: boolean;
|
|
1246
|
+
onClose?: () => void;
|
|
1247
|
+
onClearChat?: () => void;
|
|
1248
|
+
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Build the header section of the panel.
|
|
1251
|
+
* Extracted for reuse and plugin override support.
|
|
1252
|
+
*/
|
|
1253
|
+
declare const buildHeader: (context: HeaderBuildContext) => HeaderElements;
|
|
1254
|
+
/**
|
|
1255
|
+
* Attach header elements to the container, handling placement modes.
|
|
1256
|
+
*/
|
|
1257
|
+
declare const attachHeaderToContainer: (container: HTMLElement, headerElements: HeaderElements, config?: AgentWidgetConfig) => void;
|
|
1258
|
+
|
|
1259
|
+
interface ComposerElements {
|
|
1260
|
+
footer: HTMLElement;
|
|
1261
|
+
suggestions: HTMLElement;
|
|
1262
|
+
composerForm: HTMLFormElement;
|
|
1263
|
+
textarea: HTMLTextAreaElement;
|
|
1264
|
+
sendButton: HTMLButtonElement;
|
|
1265
|
+
sendButtonWrapper: HTMLElement;
|
|
1266
|
+
micButton: HTMLButtonElement | null;
|
|
1267
|
+
micButtonWrapper: HTMLElement | null;
|
|
1268
|
+
statusText: HTMLElement;
|
|
1269
|
+
}
|
|
1270
|
+
interface ComposerBuildContext {
|
|
1271
|
+
config?: AgentWidgetConfig;
|
|
1272
|
+
onSubmit?: (text: string) => void;
|
|
1273
|
+
disabled?: boolean;
|
|
1274
|
+
}
|
|
1275
|
+
/**
|
|
1276
|
+
* Build the composer/footer section of the panel.
|
|
1277
|
+
* Extracted for reuse and plugin override support.
|
|
1278
|
+
*/
|
|
1279
|
+
declare const buildComposer: (context: ComposerBuildContext) => ComposerElements;
|
|
1280
|
+
|
|
1281
|
+
interface HeaderLayoutContext {
|
|
1282
|
+
config: AgentWidgetConfig;
|
|
1283
|
+
showClose?: boolean;
|
|
1284
|
+
onClose?: () => void;
|
|
1285
|
+
onClearChat?: () => void;
|
|
1286
|
+
}
|
|
1287
|
+
type HeaderLayoutRenderer = (context: HeaderLayoutContext) => HeaderElements;
|
|
1288
|
+
/**
|
|
1289
|
+
* Build default header layout
|
|
1290
|
+
* Full header with icon, title, subtitle, clear chat, and close button
|
|
1291
|
+
*/
|
|
1292
|
+
declare const buildDefaultHeader: HeaderLayoutRenderer;
|
|
1293
|
+
/**
|
|
1294
|
+
* Build minimal header layout
|
|
1295
|
+
* Simplified layout with just title and close button
|
|
1296
|
+
*/
|
|
1297
|
+
declare const buildMinimalHeader: HeaderLayoutRenderer;
|
|
1298
|
+
/**
|
|
1299
|
+
* Build expanded header layout
|
|
1300
|
+
* Full branding area with additional space for custom content
|
|
1301
|
+
*/
|
|
1302
|
+
declare const buildExpandedHeader: HeaderLayoutRenderer;
|
|
1303
|
+
/**
|
|
1304
|
+
* Header layout registry
|
|
1305
|
+
* Maps layout names to their renderer functions
|
|
1306
|
+
*/
|
|
1307
|
+
declare const headerLayouts: Record<string, HeaderLayoutRenderer>;
|
|
1308
|
+
/**
|
|
1309
|
+
* Get header layout renderer by name
|
|
1310
|
+
*/
|
|
1311
|
+
declare const getHeaderLayout: (layoutName: string) => HeaderLayoutRenderer;
|
|
1312
|
+
/**
|
|
1313
|
+
* Build header based on layout configuration
|
|
1314
|
+
* Applies layout config settings to determine which layout to use
|
|
1315
|
+
*/
|
|
1316
|
+
declare const buildHeaderWithLayout: (config: AgentWidgetConfig, layoutConfig?: AgentWidgetHeaderLayoutConfig, context?: Partial<HeaderLayoutContext>) => HeaderElements;
|
|
1317
|
+
|
|
1318
|
+
export { type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetCustomFetch, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetMessage, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, type AgentWidgetTimestampConfig, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, DEFAULT_WIDGET_CONFIG, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type MessageRenderContext, type MessageTransform, type SlotRenderContext, type SlotRenderer, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createComponentMiddleware, createComponentStreamParser, createFlexibleJsonStreamParser, createJsonStreamParser, createLocalStorageAdapter, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, getHeaderLayout, hasComponentDirective, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, pluginRegistry, renderComponentDirective };
|