vanilla-agent 1.30.0 → 1.31.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vanilla-agent",
3
- "version": "1.30.0",
3
+ "version": "1.31.0",
4
4
  "description": "Themeable, plugable streaming agent widget for websites, in plain JS with support for voice input and reasoning / tool output.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -94,6 +94,7 @@ export const buildPanel = (config?: AgentWidgetConfig, showClose = true): PanelE
94
94
 
95
95
  // Build header using layout config if available, otherwise use standard builder
96
96
  const headerLayoutConfig = config?.layout?.header;
97
+ const showHeader = config?.layout?.showHeader !== false; // default to true
97
98
  const headerElements: HeaderElements = headerLayoutConfig
98
99
  ? buildHeaderWithLayout(config!, headerLayoutConfig, { showClose })
99
100
  : buildHeader({ config, showClose });
@@ -132,10 +133,26 @@ export const buildPanel = (config?: AgentWidgetConfig, showClose = true): PanelE
132
133
 
133
134
  // Build composer/footer using extracted builder
134
135
  const composerElements: ComposerElements = buildComposer({ config });
136
+ const showFooter = config?.layout?.showFooter !== false; // default to true
135
137
 
136
138
  // Assemble container with header, body, and footer
137
- attachHeaderToContainer(container, headerElements, config);
138
- container.append(body, composerElements.footer);
139
+ if (showHeader) {
140
+ attachHeaderToContainer(container, headerElements, config);
141
+ } else {
142
+ // Hide header completely
143
+ headerElements.header.style.display = 'none';
144
+ attachHeaderToContainer(container, headerElements, config);
145
+ }
146
+
147
+ container.append(body);
148
+
149
+ if (showFooter) {
150
+ container.append(composerElements.footer);
151
+ } else {
152
+ // Hide footer completely
153
+ composerElements.footer.style.display = 'none';
154
+ container.append(composerElements.footer);
155
+ }
139
156
 
140
157
  return {
141
158
  container,
@@ -4,7 +4,34 @@ import { describeReasonStatus } from "../utils/formatting";
4
4
  import { renderLucideIcon } from "../utils/icons";
5
5
 
6
6
  // Expansion state per widget instance
7
- const reasoningExpansionState = new Set<string>();
7
+ export const reasoningExpansionState = new Set<string>();
8
+
9
+ // Helper function to update reasoning bubble UI after expansion state changes
10
+ export const updateReasoningBubbleUI = (messageId: string, bubble: HTMLElement): void => {
11
+ const expanded = reasoningExpansionState.has(messageId);
12
+ const header = bubble.querySelector('button[data-expand-header="true"]') as HTMLElement;
13
+ const content = bubble.querySelector('.tvw-border-t') as HTMLElement;
14
+
15
+ if (!header || !content) return;
16
+
17
+ header.setAttribute("aria-expanded", expanded ? "true" : "false");
18
+
19
+ // Find toggle icon container - it's the direct child div of headerMeta (which has tvw-ml-auto)
20
+ const headerMeta = header.querySelector('.tvw-ml-auto') as HTMLElement;
21
+ const toggleIcon = headerMeta?.querySelector(':scope > .tvw-flex.tvw-items-center') as HTMLElement;
22
+ if (toggleIcon) {
23
+ toggleIcon.innerHTML = "";
24
+ const iconColor = "currentColor";
25
+ const chevronIcon = renderLucideIcon(expanded ? "chevron-up" : "chevron-down", 16, iconColor, 2);
26
+ if (chevronIcon) {
27
+ toggleIcon.appendChild(chevronIcon);
28
+ } else {
29
+ toggleIcon.textContent = expanded ? "Hide" : "Show";
30
+ }
31
+ }
32
+
33
+ content.style.display = expanded ? "" : "none";
34
+ };
8
35
 
9
36
  export const createReasoningBubble = (message: AgentWidgetMessage): HTMLElement => {
10
37
  const reasoning = message.reasoning;
@@ -41,6 +68,8 @@ export const createReasoningBubble = (message: AgentWidgetMessage): HTMLElement
41
68
  ) as HTMLButtonElement;
42
69
  header.type = "button";
43
70
  header.setAttribute("aria-expanded", expanded ? "true" : "false");
71
+ header.setAttribute("data-expand-header", "true");
72
+ header.setAttribute("data-bubble-type", "reasoning");
44
73
 
45
74
  const headerContent = createElement("div", "tvw-flex tvw-flex-col tvw-text-left");
46
75
  const title = createElement("span", "tvw-text-xs tvw-text-cw-primary");
@@ -105,28 +134,6 @@ export const createReasoningBubble = (message: AgentWidgetMessage): HTMLElement
105
134
  content.style.display = expanded ? "" : "none";
106
135
  };
107
136
 
108
- const toggleExpansion = () => {
109
- expanded = !expanded;
110
- if (expanded) {
111
- reasoningExpansionState.add(message.id);
112
- } else {
113
- reasoningExpansionState.delete(message.id);
114
- }
115
- applyExpansionState();
116
- };
117
-
118
- header.addEventListener("pointerdown", (event) => {
119
- event.preventDefault();
120
- toggleExpansion();
121
- });
122
-
123
- header.addEventListener("keydown", (event) => {
124
- if (event.key === "Enter" || event.key === " ") {
125
- event.preventDefault();
126
- toggleExpansion();
127
- }
128
- });
129
-
130
137
  applyExpansionState();
131
138
 
132
139
  bubble.append(header, content);
@@ -4,7 +4,35 @@ import { formatUnknownValue, describeToolTitle } from "../utils/formatting";
4
4
  import { renderLucideIcon } from "../utils/icons";
5
5
 
6
6
  // Expansion state per widget instance
7
- const toolExpansionState = new Set<string>();
7
+ export const toolExpansionState = new Set<string>();
8
+
9
+ // Helper function to update tool bubble UI after expansion state changes
10
+ export const updateToolBubbleUI = (messageId: string, bubble: HTMLElement, config?: AgentWidgetConfig): void => {
11
+ const expanded = toolExpansionState.has(messageId);
12
+ const toolCallConfig = config?.toolCall ?? {};
13
+ const header = bubble.querySelector('button[data-expand-header="true"]') as HTMLElement;
14
+ const content = bubble.querySelector('.tvw-border-t') as HTMLElement;
15
+
16
+ if (!header || !content) return;
17
+
18
+ header.setAttribute("aria-expanded", expanded ? "true" : "false");
19
+
20
+ // Find toggle icon container - it's the direct child div of headerMeta (which has tvw-ml-auto)
21
+ const headerMeta = header.querySelector('.tvw-ml-auto') as HTMLElement;
22
+ const toggleIcon = headerMeta?.querySelector(':scope > .tvw-flex.tvw-items-center') as HTMLElement;
23
+ if (toggleIcon) {
24
+ toggleIcon.innerHTML = "";
25
+ const iconColor = toolCallConfig.toggleTextColor || toolCallConfig.headerTextColor || "currentColor";
26
+ const chevronIcon = renderLucideIcon(expanded ? "chevron-up" : "chevron-down", 16, iconColor, 2);
27
+ if (chevronIcon) {
28
+ toggleIcon.appendChild(chevronIcon);
29
+ } else {
30
+ toggleIcon.textContent = expanded ? "Hide" : "Show";
31
+ }
32
+ }
33
+
34
+ content.style.display = expanded ? "" : "none";
35
+ };
8
36
 
9
37
  export const createToolBubble = (message: AgentWidgetMessage, config?: AgentWidgetConfig): HTMLElement => {
10
38
  const tool = message.toolCall;
@@ -57,6 +85,8 @@ export const createToolBubble = (message: AgentWidgetMessage, config?: AgentWidg
57
85
  ) as HTMLButtonElement;
58
86
  header.type = "button";
59
87
  header.setAttribute("aria-expanded", expanded ? "true" : "false");
88
+ header.setAttribute("data-expand-header", "true");
89
+ header.setAttribute("data-bubble-type", "tool");
60
90
 
61
91
  // Apply header styles
62
92
  if (toolCallConfig.headerBackgroundColor) {
@@ -248,28 +278,6 @@ export const createToolBubble = (message: AgentWidgetMessage, config?: AgentWidg
248
278
  content.style.display = expanded ? "" : "none";
249
279
  };
250
280
 
251
- const toggleToolExpansion = () => {
252
- expanded = !expanded;
253
- if (expanded) {
254
- toolExpansionState.add(message.id);
255
- } else {
256
- toolExpansionState.delete(message.id);
257
- }
258
- applyToolExpansion();
259
- };
260
-
261
- header.addEventListener("pointerdown", (event) => {
262
- event.preventDefault();
263
- toggleToolExpansion();
264
- });
265
-
266
- header.addEventListener("keydown", (event) => {
267
- if (event.key === "Enter" || event.key === " ") {
268
- event.preventDefault();
269
- toggleToolExpansion();
270
- }
271
- });
272
-
273
281
  applyToolExpansion();
274
282
 
275
283
  bubble.append(header, content);
package/src/types.ts CHANGED
@@ -790,6 +790,19 @@ export type AgentWidgetLayoutConfig = {
790
790
  messages?: AgentWidgetMessageLayoutConfig;
791
791
  /** Slot renderers for custom content injection */
792
792
  slots?: Partial<Record<WidgetLayoutSlot, SlotRenderer>>;
793
+ /**
794
+ * Show/hide the header section entirely.
795
+ * When false, the header (including icon, title, buttons) is completely hidden.
796
+ * @default true
797
+ */
798
+ showHeader?: boolean;
799
+ /**
800
+ * Show/hide the footer/composer section entirely.
801
+ * When false, the footer (including input field, send button, suggestions) is completely hidden.
802
+ * Useful for read-only conversation previews.
803
+ * @default true
804
+ */
805
+ showFooter?: boolean;
793
806
  };
794
807
 
795
808
  // ============================================================================
package/src/ui.ts CHANGED
@@ -26,8 +26,8 @@ import { positionMap } from "./utils/positioning";
26
26
  import type { HeaderElements, ComposerElements } from "./components/panel";
27
27
  import { MessageTransform, MessageActionCallbacks } from "./components/message-bubble";
28
28
  import { createStandardBubble, createTypingIndicator } from "./components/message-bubble";
29
- import { createReasoningBubble } from "./components/reasoning-bubble";
30
- import { createToolBubble } from "./components/tool-bubble";
29
+ import { createReasoningBubble, reasoningExpansionState, updateReasoningBubbleUI } from "./components/reasoning-bubble";
30
+ import { createToolBubble, toolExpansionState, updateToolBubbleUI } from "./components/tool-bubble";
31
31
  import { createSuggestions } from "./components/suggestions";
32
32
  import { enhanceWithForms } from "./components/forms";
33
33
  import { pluginRegistry } from "./plugins/registry";
@@ -453,6 +453,60 @@ export const createAgentExperience = (
453
453
  // Render custom slots
454
454
  renderSlots();
455
455
 
456
+ // Add event delegation for reasoning and tool bubble expansion
457
+ // This handles clicks even after idiomorph morphs the DOM
458
+ const handleBubbleExpansion = (event: Event) => {
459
+ const target = event.target as HTMLElement;
460
+
461
+ // Check if the click/keypress is on an expand header button
462
+ const headerButton = target.closest('button[data-expand-header="true"]') as HTMLElement;
463
+ if (!headerButton) return;
464
+
465
+ // Find the parent bubble element
466
+ const bubble = headerButton.closest('.vanilla-reasoning-bubble, .vanilla-tool-bubble') as HTMLElement;
467
+ if (!bubble) return;
468
+
469
+ // Get message ID from bubble
470
+ const messageId = bubble.getAttribute('data-message-id');
471
+ if (!messageId) return;
472
+
473
+ const bubbleType = headerButton.getAttribute('data-bubble-type');
474
+
475
+ // Toggle expansion state
476
+ if (bubbleType === 'reasoning') {
477
+ if (reasoningExpansionState.has(messageId)) {
478
+ reasoningExpansionState.delete(messageId);
479
+ } else {
480
+ reasoningExpansionState.add(messageId);
481
+ }
482
+ updateReasoningBubbleUI(messageId, bubble);
483
+ } else if (bubbleType === 'tool') {
484
+ if (toolExpansionState.has(messageId)) {
485
+ toolExpansionState.delete(messageId);
486
+ } else {
487
+ toolExpansionState.add(messageId);
488
+ }
489
+ updateToolBubbleUI(messageId, bubble, config);
490
+ }
491
+ };
492
+
493
+ // Attach event listeners to messagesWrapper for event delegation
494
+ messagesWrapper.addEventListener('pointerdown', (event) => {
495
+ const target = event.target as HTMLElement;
496
+ if (target.closest('button[data-expand-header="true"]')) {
497
+ event.preventDefault();
498
+ handleBubbleExpansion(event);
499
+ }
500
+ });
501
+
502
+ messagesWrapper.addEventListener('keydown', (event) => {
503
+ const target = event.target as HTMLElement;
504
+ if ((event.key === 'Enter' || event.key === ' ') && target.closest('button[data-expand-header="true"]')) {
505
+ event.preventDefault();
506
+ handleBubbleExpansion(event);
507
+ }
508
+ });
509
+
456
510
  panel.appendChild(container);
457
511
  mount.appendChild(wrapper);
458
512
 
@@ -1975,6 +2029,18 @@ export const createAgentExperience = (
1975
2029
  }
1976
2030
  }
1977
2031
 
2032
+ // Update header visibility based on layout.showHeader
2033
+ const showHeader = config.layout?.showHeader !== false; // default to true
2034
+ if (header) {
2035
+ header.style.display = showHeader ? "" : "none";
2036
+ }
2037
+
2038
+ // Update footer visibility based on layout.showFooter
2039
+ const showFooter = config.layout?.showFooter !== false; // default to true
2040
+ if (footer) {
2041
+ footer.style.display = showFooter ? "" : "none";
2042
+ }
2043
+
1978
2044
  // Only update open state if launcher enabled state changed or autoExpand value changed
1979
2045
  const launcherEnabledChanged = launcherEnabled !== prevLauncherEnabled;
1980
2046
  const autoExpandChanged = autoExpand !== prevAutoExpand;