vanilla-agent 1.19.0 → 1.21.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.d.cts CHANGED
@@ -254,6 +254,14 @@ type AgentWidgetLauncherConfig = {
254
254
  * @default "420px"
255
255
  */
256
256
  sidebarWidth?: string;
257
+ /**
258
+ * Offset (in pixels) to subtract from the calculated panel height.
259
+ * Useful for adjusting the panel height when there are other fixed elements on the page.
260
+ * Only applies when not in fullHeight or sidebarMode.
261
+ *
262
+ * @default 0
263
+ */
264
+ heightOffset?: number;
257
265
  callToActionIconText?: string;
258
266
  callToActionIconName?: string;
259
267
  callToActionIconColor?: string;
@@ -279,6 +287,18 @@ type AgentWidgetLauncherConfig = {
279
287
  closeButtonTooltipText?: string;
280
288
  closeButtonShowTooltip?: boolean;
281
289
  clearChat?: AgentWidgetClearChatConfig;
290
+ /**
291
+ * Border style for the launcher button.
292
+ * @example "1px solid #e5e7eb" | "2px solid #3b82f6" | "none"
293
+ * @default "1px solid #e5e7eb"
294
+ */
295
+ border?: string;
296
+ /**
297
+ * Box shadow for the launcher button.
298
+ * @example "0 10px 15px -3px rgba(0,0,0,0.1)" | "none"
299
+ * @default "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)"
300
+ */
301
+ shadow?: string;
282
302
  };
283
303
  type AgentWidgetSendButtonConfig = {
284
304
  borderWidth?: string;
@@ -589,6 +609,271 @@ type AgentWidgetLayoutConfig = {
589
609
  /** Slot renderers for custom content injection */
590
610
  slots?: Partial<Record<WidgetLayoutSlot, SlotRenderer>>;
591
611
  };
612
+ /**
613
+ * Token types for marked renderer methods
614
+ */
615
+ type AgentWidgetMarkdownHeadingToken = {
616
+ type: "heading";
617
+ raw: string;
618
+ depth: 1 | 2 | 3 | 4 | 5 | 6;
619
+ text: string;
620
+ tokens: unknown[];
621
+ };
622
+ type AgentWidgetMarkdownCodeToken = {
623
+ type: "code";
624
+ raw: string;
625
+ text: string;
626
+ lang?: string;
627
+ escaped?: boolean;
628
+ };
629
+ type AgentWidgetMarkdownBlockquoteToken = {
630
+ type: "blockquote";
631
+ raw: string;
632
+ text: string;
633
+ tokens: unknown[];
634
+ };
635
+ type AgentWidgetMarkdownTableToken = {
636
+ type: "table";
637
+ raw: string;
638
+ header: Array<{
639
+ text: string;
640
+ tokens: unknown[];
641
+ }>;
642
+ rows: Array<Array<{
643
+ text: string;
644
+ tokens: unknown[];
645
+ }>>;
646
+ align: Array<"left" | "center" | "right" | null>;
647
+ };
648
+ type AgentWidgetMarkdownLinkToken = {
649
+ type: "link";
650
+ raw: string;
651
+ href: string;
652
+ title: string | null;
653
+ text: string;
654
+ tokens: unknown[];
655
+ };
656
+ type AgentWidgetMarkdownImageToken = {
657
+ type: "image";
658
+ raw: string;
659
+ href: string;
660
+ title: string | null;
661
+ text: string;
662
+ };
663
+ type AgentWidgetMarkdownListToken = {
664
+ type: "list";
665
+ raw: string;
666
+ ordered: boolean;
667
+ start: number | "";
668
+ loose: boolean;
669
+ items: unknown[];
670
+ };
671
+ type AgentWidgetMarkdownListItemToken = {
672
+ type: "list_item";
673
+ raw: string;
674
+ task: boolean;
675
+ checked?: boolean;
676
+ loose: boolean;
677
+ text: string;
678
+ tokens: unknown[];
679
+ };
680
+ type AgentWidgetMarkdownParagraphToken = {
681
+ type: "paragraph";
682
+ raw: string;
683
+ text: string;
684
+ tokens: unknown[];
685
+ };
686
+ type AgentWidgetMarkdownCodespanToken = {
687
+ type: "codespan";
688
+ raw: string;
689
+ text: string;
690
+ };
691
+ type AgentWidgetMarkdownStrongToken = {
692
+ type: "strong";
693
+ raw: string;
694
+ text: string;
695
+ tokens: unknown[];
696
+ };
697
+ type AgentWidgetMarkdownEmToken = {
698
+ type: "em";
699
+ raw: string;
700
+ text: string;
701
+ tokens: unknown[];
702
+ };
703
+ /**
704
+ * Custom renderer overrides for markdown elements.
705
+ * Each method receives the token and should return an HTML string.
706
+ * Return `false` to use the default renderer.
707
+ *
708
+ * @example
709
+ * ```typescript
710
+ * renderer: {
711
+ * heading(token) {
712
+ * return `<h${token.depth} class="custom-heading">${token.text}</h${token.depth}>`;
713
+ * },
714
+ * link(token) {
715
+ * return `<a href="${token.href}" target="_blank" rel="noopener">${token.text}</a>`;
716
+ * }
717
+ * }
718
+ * ```
719
+ */
720
+ type AgentWidgetMarkdownRendererOverrides = {
721
+ /** Override heading rendering (h1-h6) */
722
+ heading?: (token: AgentWidgetMarkdownHeadingToken) => string | false;
723
+ /** Override code block rendering */
724
+ code?: (token: AgentWidgetMarkdownCodeToken) => string | false;
725
+ /** Override blockquote rendering */
726
+ blockquote?: (token: AgentWidgetMarkdownBlockquoteToken) => string | false;
727
+ /** Override table rendering */
728
+ table?: (token: AgentWidgetMarkdownTableToken) => string | false;
729
+ /** Override link rendering */
730
+ link?: (token: AgentWidgetMarkdownLinkToken) => string | false;
731
+ /** Override image rendering */
732
+ image?: (token: AgentWidgetMarkdownImageToken) => string | false;
733
+ /** Override list rendering (ul/ol) */
734
+ list?: (token: AgentWidgetMarkdownListToken) => string | false;
735
+ /** Override list item rendering */
736
+ listitem?: (token: AgentWidgetMarkdownListItemToken) => string | false;
737
+ /** Override paragraph rendering */
738
+ paragraph?: (token: AgentWidgetMarkdownParagraphToken) => string | false;
739
+ /** Override inline code rendering */
740
+ codespan?: (token: AgentWidgetMarkdownCodespanToken) => string | false;
741
+ /** Override strong/bold rendering */
742
+ strong?: (token: AgentWidgetMarkdownStrongToken) => string | false;
743
+ /** Override emphasis/italic rendering */
744
+ em?: (token: AgentWidgetMarkdownEmToken) => string | false;
745
+ /** Override horizontal rule rendering */
746
+ hr?: () => string | false;
747
+ /** Override line break rendering */
748
+ br?: () => string | false;
749
+ /** Override deleted/strikethrough rendering */
750
+ del?: (token: {
751
+ type: "del";
752
+ raw: string;
753
+ text: string;
754
+ tokens: unknown[];
755
+ }) => string | false;
756
+ /** Override checkbox rendering (in task lists) */
757
+ checkbox?: (token: {
758
+ checked: boolean;
759
+ }) => string | false;
760
+ /** Override HTML passthrough */
761
+ html?: (token: {
762
+ type: "html";
763
+ raw: string;
764
+ text: string;
765
+ }) => string | false;
766
+ /** Override text rendering */
767
+ text?: (token: {
768
+ type: "text";
769
+ raw: string;
770
+ text: string;
771
+ }) => string | false;
772
+ };
773
+ /**
774
+ * Markdown parsing options (subset of marked options)
775
+ */
776
+ type AgentWidgetMarkdownOptions = {
777
+ /**
778
+ * Enable GitHub Flavored Markdown (tables, strikethrough, autolinks).
779
+ * @default true
780
+ */
781
+ gfm?: boolean;
782
+ /**
783
+ * Convert \n in paragraphs into <br>.
784
+ * @default true
785
+ */
786
+ breaks?: boolean;
787
+ /**
788
+ * Conform to original markdown.pl as much as possible.
789
+ * @default false
790
+ */
791
+ pedantic?: boolean;
792
+ /**
793
+ * Add id attributes to headings.
794
+ * @default false
795
+ */
796
+ headerIds?: boolean;
797
+ /**
798
+ * Prefix for heading id attributes.
799
+ * @default ""
800
+ */
801
+ headerPrefix?: string;
802
+ /**
803
+ * Mangle email addresses for spam protection.
804
+ * @default true
805
+ */
806
+ mangle?: boolean;
807
+ /**
808
+ * Silent mode - don't throw on parse errors.
809
+ * @default false
810
+ */
811
+ silent?: boolean;
812
+ };
813
+ /**
814
+ * Markdown configuration for customizing how markdown is rendered in chat messages.
815
+ * Provides three levels of control:
816
+ *
817
+ * 1. **CSS Variables** - Override styles via `--cw-md-*` CSS custom properties
818
+ * 2. **Parsing Options** - Configure marked behavior via `options`
819
+ * 3. **Custom Renderers** - Full control via `renderer` overrides
820
+ *
821
+ * @example
822
+ * ```typescript
823
+ * // Level 2: Configure parsing options
824
+ * config: {
825
+ * markdown: {
826
+ * options: {
827
+ * gfm: true,
828
+ * breaks: true,
829
+ * headerIds: true
830
+ * }
831
+ * }
832
+ * }
833
+ * ```
834
+ *
835
+ * @example
836
+ * ```typescript
837
+ * // Level 3: Custom renderers
838
+ * config: {
839
+ * markdown: {
840
+ * renderer: {
841
+ * heading(token) {
842
+ * return `<h${token.depth} class="custom-h${token.depth}">${token.text}</h${token.depth}>`;
843
+ * },
844
+ * link(token) {
845
+ * return `<a href="${token.href}" target="_blank">${token.text}</a>`;
846
+ * },
847
+ * table(token) {
848
+ * // Wrap tables in a scrollable container
849
+ * return `<div class="table-scroll">${this.parser.parse(token.tokens)}</div>`;
850
+ * }
851
+ * }
852
+ * }
853
+ * }
854
+ * ```
855
+ */
856
+ type AgentWidgetMarkdownConfig = {
857
+ /**
858
+ * Markdown parsing options.
859
+ * These are passed directly to the marked parser.
860
+ */
861
+ options?: AgentWidgetMarkdownOptions;
862
+ /**
863
+ * Custom renderer overrides for specific markdown elements.
864
+ * Each method receives a token object and should return an HTML string.
865
+ * Return `false` to fall back to the default renderer.
866
+ */
867
+ renderer?: AgentWidgetMarkdownRendererOverrides;
868
+ /**
869
+ * Disable default markdown CSS styles.
870
+ * When true, the widget won't apply any default styles to markdown elements,
871
+ * allowing you to provide your own CSS.
872
+ *
873
+ * @default false
874
+ */
875
+ disableDefaultStyles?: boolean;
876
+ };
592
877
  type AgentWidgetConfig = {
593
878
  apiUrl?: string;
594
879
  flowId?: string;
@@ -798,6 +1083,31 @@ type AgentWidgetConfig = {
798
1083
  * ```
799
1084
  */
800
1085
  layout?: AgentWidgetLayoutConfig;
1086
+ /**
1087
+ * Markdown rendering configuration.
1088
+ * Customize how markdown is parsed and rendered in chat messages.
1089
+ *
1090
+ * Override methods:
1091
+ * 1. **CSS Variables** - Override `--cw-md-*` variables in your stylesheet
1092
+ * 2. **Options** - Configure marked parser behavior
1093
+ * 3. **Renderers** - Custom rendering functions for specific elements
1094
+ * 4. **postprocessMessage** - Complete control over message transformation
1095
+ *
1096
+ * @example
1097
+ * ```typescript
1098
+ * config: {
1099
+ * markdown: {
1100
+ * options: { breaks: true, gfm: true },
1101
+ * renderer: {
1102
+ * link(token) {
1103
+ * return `<a href="${token.href}" target="_blank">${token.text}</a>`;
1104
+ * }
1105
+ * }
1106
+ * }
1107
+ * }
1108
+ * ```
1109
+ */
1110
+ markdown?: AgentWidgetMarkdownConfig;
801
1111
  };
802
1112
  type AgentWidgetMessageRole = "user" | "assistant" | "system";
803
1113
  type AgentWidgetReasoning = {
@@ -998,8 +1308,51 @@ declare const createActionManager: (options: ActionManagerOptions) => {
998
1308
  };
999
1309
 
1000
1310
  /**
1001
- * Basic markdown renderer. Remember to sanitize the returned HTML if you render
1002
- * untrusted content in your host page.
1311
+ * Options for creating a markdown processor
1312
+ */
1313
+ type MarkdownProcessorOptions = {
1314
+ /** Marked parsing options */
1315
+ markedOptions?: AgentWidgetMarkdownOptions;
1316
+ /** Custom renderer overrides */
1317
+ renderer?: AgentWidgetMarkdownRendererOverrides;
1318
+ };
1319
+ /**
1320
+ * Creates a configured markdown processor with custom options and renderers.
1321
+ *
1322
+ * @param options - Configuration options for the markdown processor
1323
+ * @returns A function that converts markdown text to HTML
1324
+ *
1325
+ * @example
1326
+ * ```typescript
1327
+ * // Basic usage with defaults
1328
+ * const processor = createMarkdownProcessor();
1329
+ * const html = processor("# Hello World");
1330
+ *
1331
+ * // With custom options
1332
+ * const processor = createMarkdownProcessor({
1333
+ * markedOptions: { gfm: true, breaks: true },
1334
+ * renderer: {
1335
+ * link(token) {
1336
+ * return `<a href="${token.href}" target="_blank">${token.text}</a>`;
1337
+ * }
1338
+ * }
1339
+ * });
1340
+ * ```
1341
+ */
1342
+ declare const createMarkdownProcessor: (options?: MarkdownProcessorOptions) => (text: string) => string;
1343
+ /**
1344
+ * Creates a markdown processor from AgentWidgetMarkdownConfig.
1345
+ * This is a convenience function that maps the widget config to processor options.
1346
+ *
1347
+ * @param config - The markdown configuration from widget config
1348
+ * @returns A function that converts markdown text to HTML
1349
+ */
1350
+ declare const createMarkdownProcessorFromConfig: (config?: AgentWidgetMarkdownConfig) => (text: string) => string;
1351
+ /**
1352
+ * Basic markdown renderer using default settings.
1353
+ * Remember to sanitize the returned HTML if you render untrusted content in your host page.
1354
+ *
1355
+ * For custom configuration, use `createMarkdownProcessor()` or `createMarkdownProcessorFromConfig()`.
1003
1356
  */
1004
1357
  declare const markdownPostprocessor: (text: string) => string;
1005
1358
  /**
@@ -1007,10 +1360,23 @@ declare const markdownPostprocessor: (text: string) => string;
1007
1360
  */
1008
1361
  declare const escapeHtml: (text: string) => string;
1009
1362
  /**
1363
+ * Creates a directive postprocessor with custom markdown configuration.
1010
1364
  * Converts special directives (either `<Form type="init" />` or
1011
1365
  * `<Directive>{"component":"form","type":"init"}</Directive>`) into placeholder
1012
1366
  * elements that the widget upgrades after render. Remaining text is rendered as
1013
- * Markdown.
1367
+ * Markdown with the provided configuration.
1368
+ *
1369
+ * @param markdownConfig - Optional markdown configuration
1370
+ * @returns A function that processes text with directives and markdown
1371
+ */
1372
+ declare const createDirectivePostprocessor: (markdownConfig?: AgentWidgetMarkdownConfig) => (text: string) => string;
1373
+ /**
1374
+ * Converts special directives (either `<Form type="init" />` or
1375
+ * `<Directive>{"component":"form","type":"init"}</Directive>`) into placeholder
1376
+ * elements that the widget upgrades after render. Remaining text is rendered as
1377
+ * Markdown using default settings.
1378
+ *
1379
+ * For custom markdown configuration, use `createDirectivePostprocessor()`.
1014
1380
  */
1015
1381
  declare const directivePostprocessor: (text: string) => string;
1016
1382
 
@@ -1318,4 +1684,4 @@ declare const getHeaderLayout: (layoutName: string) => HeaderLayoutRenderer;
1318
1684
  */
1319
1685
  declare const buildHeaderWithLayout: (config: AgentWidgetConfig, layoutConfig?: AgentWidgetHeaderLayoutConfig, context?: Partial<HeaderLayoutContext>) => HeaderElements;
1320
1686
 
1321
- 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 CodeFormat, 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, generateCodeSnippet, getHeaderLayout, hasComponentDirective, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, pluginRegistry, renderComponentDirective };
1687
+ 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 AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTheme, type AgentWidgetTimestampConfig, type CodeFormat, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComposerBuildContext, type ComposerElements, DEFAULT_WIDGET_CONFIG, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type MarkdownProcessorOptions, type MessageRenderContext, type MessageTransform, type SlotRenderContext, type SlotRenderer, type WidgetLayoutSlot, attachHeaderToContainer, buildComposer, buildDefaultHeader, buildExpandedHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, componentRegistry, createActionManager, createAgentExperience, createBubbleWithLayout, createComponentMiddleware, createComponentStreamParser, createDirectivePostprocessor, createFlexibleJsonStreamParser, createJsonStreamParser, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createPlainTextParser, createRegexJsonParser, createStandardBubble, createTypingIndicator, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, directivePostprocessor, escapeHtml, extractComponentDirectiveFromMessage, generateCodeSnippet, getHeaderLayout, hasComponentDirective, headerLayouts, initAgentWidget, isComponentDirectiveType, markdownPostprocessor, mergeWithDefaults, pluginRegistry, renderComponentDirective };