vanilla-agent 1.2.0 → 1.3.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.2.0",
3
+ "version": "1.3.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",
package/src/session.ts CHANGED
@@ -60,7 +60,7 @@ export class AgentWidgetSession {
60
60
  return this.streaming;
61
61
  }
62
62
 
63
- public async sendMessage(rawInput: string) {
63
+ public async sendMessage(rawInput: string, options?: { viaVoice?: boolean }) {
64
64
  const input = rawInput.trim();
65
65
  if (!input) return;
66
66
 
@@ -71,7 +71,8 @@ export class AgentWidgetSession {
71
71
  role: "user",
72
72
  content: input,
73
73
  createdAt: new Date().toISOString(),
74
- sequence: this.nextSequence()
74
+ sequence: this.nextSequence(),
75
+ viaVoice: options?.viaVoice || false
75
76
  };
76
77
 
77
78
  this.appendMessage(userMessage);
package/src/types.ts CHANGED
@@ -193,6 +193,22 @@ export type AgentWidgetToolCall = {
193
193
 
194
194
  export type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool";
195
195
 
196
+ /**
197
+ * Represents a message in the chat conversation.
198
+ *
199
+ * @property id - Unique message identifier
200
+ * @property role - Message role: "user", "assistant", or "system"
201
+ * @property content - Message text content
202
+ * @property createdAt - ISO timestamp when message was created
203
+ * @property streaming - Whether message is still streaming (for assistant messages)
204
+ * @property variant - Message variant for assistant messages: "assistant", "reasoning", or "tool"
205
+ * @property sequence - Message ordering number
206
+ * @property reasoning - Reasoning data for assistant reasoning messages
207
+ * @property toolCall - Tool call data for assistant tool messages
208
+ * @property tools - Array of tool calls
209
+ * @property viaVoice - Set to `true` when a user message is sent via voice recognition.
210
+ * Useful for implementing voice-specific behaviors like auto-reactivation.
211
+ */
196
212
  export type AgentWidgetMessage = {
197
213
  id: string;
198
214
  role: AgentWidgetMessageRole;
@@ -204,6 +220,7 @@ export type AgentWidgetMessage = {
204
220
  reasoning?: AgentWidgetReasoning;
205
221
  toolCall?: AgentWidgetToolCall;
206
222
  tools?: AgentWidgetToolCall[];
223
+ viaVoice?: boolean;
207
224
  };
208
225
 
209
226
  export type AgentWidgetEvent =
package/src/ui.ts CHANGED
@@ -469,7 +469,7 @@ export const createAgentExperience = (
469
469
  if (finalValue && speechRecognition && isRecording) {
470
470
  stopVoiceRecognition();
471
471
  textarea.value = "";
472
- session.sendMessage(finalValue);
472
+ session.sendMessage(finalValue, { viaVoice: true });
473
473
  }
474
474
  }, pauseDuration);
475
475
  }
@@ -488,7 +488,7 @@ export const createAgentExperience = (
488
488
  const finalValue = textarea.value.trim();
489
489
  if (finalValue && finalValue !== initialText.trim()) {
490
490
  textarea.value = "";
491
- session.sendMessage(finalValue);
491
+ session.sendMessage(finalValue, { viaVoice: true });
492
492
  }
493
493
  stopVoiceRecognition();
494
494
  }