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/README.md +104 -2
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.global.js +12 -12
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/session.ts +3 -2
- package/src/types.ts +17 -0
- package/src/ui.ts +2 -2
package/package.json
CHANGED
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
|
}
|