vanilla-agent 1.1.0 → 1.2.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.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.global.js +15 -15
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/runtime/init.ts +24 -1
- package/src/types.ts +1 -0
- package/src/ui.ts +53 -0
package/package.json
CHANGED
package/src/runtime/init.ts
CHANGED
|
@@ -116,7 +116,7 @@ export const initAgentWidget = (
|
|
|
116
116
|
let controller = createAgentExperience(mount, options.config);
|
|
117
117
|
options.onReady?.();
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
const handle: AgentWidgetInitHandle = {
|
|
120
120
|
host,
|
|
121
121
|
update(nextConfig: AgentWidgetConfig) {
|
|
122
122
|
controller.update(nextConfig);
|
|
@@ -133,9 +133,32 @@ export const initAgentWidget = (
|
|
|
133
133
|
clearChat() {
|
|
134
134
|
controller.clearChat();
|
|
135
135
|
},
|
|
136
|
+
setMessage(message: string) {
|
|
137
|
+
return controller.setMessage(message);
|
|
138
|
+
},
|
|
139
|
+
submitMessage(message?: string) {
|
|
140
|
+
return controller.submitMessage(message);
|
|
141
|
+
},
|
|
142
|
+
startVoiceRecognition() {
|
|
143
|
+
return controller.startVoiceRecognition();
|
|
144
|
+
},
|
|
145
|
+
stopVoiceRecognition() {
|
|
146
|
+
return controller.stopVoiceRecognition();
|
|
147
|
+
},
|
|
136
148
|
destroy() {
|
|
137
149
|
controller.destroy();
|
|
138
150
|
host.remove();
|
|
151
|
+
// Clean up window reference if it was set
|
|
152
|
+
if (options.windowKey && typeof window !== 'undefined') {
|
|
153
|
+
delete (window as any)[options.windowKey];
|
|
154
|
+
}
|
|
139
155
|
}
|
|
140
156
|
};
|
|
157
|
+
|
|
158
|
+
// Store on window if windowKey is provided
|
|
159
|
+
if (options.windowKey && typeof window !== 'undefined') {
|
|
160
|
+
(window as any)[options.windowKey] = handle;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return handle;
|
|
141
164
|
};
|
package/src/types.ts
CHANGED
package/src/ui.ts
CHANGED
|
@@ -23,6 +23,10 @@ type Controller = {
|
|
|
23
23
|
close: () => void;
|
|
24
24
|
toggle: () => void;
|
|
25
25
|
clearChat: () => void;
|
|
26
|
+
setMessage: (message: string) => boolean;
|
|
27
|
+
submitMessage: (message?: string) => boolean;
|
|
28
|
+
startVoiceRecognition: () => boolean;
|
|
29
|
+
stopVoiceRecognition: () => boolean;
|
|
26
30
|
};
|
|
27
31
|
|
|
28
32
|
const buildPostprocessor = (cfg?: AgentWidgetConfig): MessageTransform => {
|
|
@@ -1596,6 +1600,55 @@ export const createAgentExperience = (
|
|
|
1596
1600
|
});
|
|
1597
1601
|
window.dispatchEvent(clearEvent);
|
|
1598
1602
|
},
|
|
1603
|
+
setMessage(message: string): boolean {
|
|
1604
|
+
if (!textarea) return false;
|
|
1605
|
+
if (session.isStreaming()) return false;
|
|
1606
|
+
|
|
1607
|
+
// Auto-open widget if closed and launcher is enabled
|
|
1608
|
+
if (!open && launcherEnabled) {
|
|
1609
|
+
setOpenState(true);
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
textarea.value = message;
|
|
1613
|
+
// Trigger input event for any listeners
|
|
1614
|
+
textarea.dispatchEvent(new Event('input', { bubbles: true }));
|
|
1615
|
+
return true;
|
|
1616
|
+
},
|
|
1617
|
+
submitMessage(message?: string): boolean {
|
|
1618
|
+
if (session.isStreaming()) return false;
|
|
1619
|
+
|
|
1620
|
+
const valueToSubmit = message?.trim() || textarea.value.trim();
|
|
1621
|
+
if (!valueToSubmit) return false;
|
|
1622
|
+
|
|
1623
|
+
// Auto-open widget if closed and launcher is enabled
|
|
1624
|
+
if (!open && launcherEnabled) {
|
|
1625
|
+
setOpenState(true);
|
|
1626
|
+
}
|
|
1627
|
+
|
|
1628
|
+
textarea.value = "";
|
|
1629
|
+
session.sendMessage(valueToSubmit);
|
|
1630
|
+
return true;
|
|
1631
|
+
},
|
|
1632
|
+
startVoiceRecognition(): boolean {
|
|
1633
|
+
if (isRecording || session.isStreaming()) return false;
|
|
1634
|
+
|
|
1635
|
+
const SpeechRecognitionClass = getSpeechRecognitionClass();
|
|
1636
|
+
if (!SpeechRecognitionClass) return false;
|
|
1637
|
+
|
|
1638
|
+
// Auto-open widget if closed and launcher is enabled
|
|
1639
|
+
if (!open && launcherEnabled) {
|
|
1640
|
+
setOpenState(true);
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
startVoiceRecognition();
|
|
1644
|
+
return true;
|
|
1645
|
+
},
|
|
1646
|
+
stopVoiceRecognition(): boolean {
|
|
1647
|
+
if (!isRecording) return false;
|
|
1648
|
+
|
|
1649
|
+
stopVoiceRecognition();
|
|
1650
|
+
return true;
|
|
1651
|
+
},
|
|
1599
1652
|
destroy() {
|
|
1600
1653
|
destroyCallbacks.forEach((cb) => cb());
|
|
1601
1654
|
wrapper.remove();
|