vanilla-agent 0.2.0 → 1.0.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 +53 -21
- package/dist/index.cjs +5 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -61
- package/dist/index.d.ts +98 -61
- package/dist/index.global.js +36 -30
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/install.global.js +1 -1
- package/dist/install.global.js.map +1 -1
- package/dist/widget.css +33 -0
- package/package.json +2 -2
- package/src/client.ts +14 -14
- package/src/components/forms.ts +7 -5
- package/src/components/launcher.ts +4 -4
- package/src/components/message-bubble.ts +3 -3
- package/src/components/messages.ts +4 -2
- package/src/components/panel.ts +254 -13
- package/src/components/reasoning-bubble.ts +2 -2
- package/src/components/suggestions.ts +4 -4
- package/src/components/tool-bubble.ts +2 -2
- package/src/defaults.ts +180 -0
- package/src/index.ts +21 -18
- package/src/install.ts +8 -8
- package/src/plugins/registry.ts +7 -5
- package/src/plugins/types.ts +13 -11
- package/src/runtime/init.ts +11 -8
- package/src/session.ts +32 -23
- package/src/styles/widget.css +33 -0
- package/src/types.ts +56 -31
- package/src/ui.ts +330 -22
- package/src/utils/constants.ts +4 -2
- package/src/utils/dom.ts +2 -0
- package/src/utils/formatting.ts +8 -6
- package/src/utils/icons.ts +1 -1
- package/src/utils/positioning.ts +2 -0
- package/src/utils/theme.ts +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Plugin interface for customizing widget components
|
|
3
3
|
*/
|
|
4
|
-
interface
|
|
4
|
+
interface AgentWidgetPlugin {
|
|
5
5
|
/**
|
|
6
6
|
* Unique identifier for the plugin
|
|
7
7
|
*/
|
|
@@ -15,16 +15,16 @@ interface ChatWidgetPlugin {
|
|
|
15
15
|
* Return null to use default renderer
|
|
16
16
|
*/
|
|
17
17
|
renderMessage?: (context: {
|
|
18
|
-
message:
|
|
18
|
+
message: AgentWidgetMessage;
|
|
19
19
|
defaultRenderer: () => HTMLElement;
|
|
20
|
-
config:
|
|
20
|
+
config: AgentWidgetConfig;
|
|
21
21
|
}) => HTMLElement | null;
|
|
22
22
|
/**
|
|
23
23
|
* Custom renderer for launcher button
|
|
24
24
|
* Return null to use default renderer
|
|
25
25
|
*/
|
|
26
26
|
renderLauncher?: (context: {
|
|
27
|
-
config:
|
|
27
|
+
config: AgentWidgetConfig;
|
|
28
28
|
defaultRenderer: () => HTMLElement;
|
|
29
29
|
onToggle: () => void;
|
|
30
30
|
}) => HTMLElement | null;
|
|
@@ -33,7 +33,7 @@ interface ChatWidgetPlugin {
|
|
|
33
33
|
* Return null to use default renderer
|
|
34
34
|
*/
|
|
35
35
|
renderHeader?: (context: {
|
|
36
|
-
config:
|
|
36
|
+
config: AgentWidgetConfig;
|
|
37
37
|
defaultRenderer: () => HTMLElement;
|
|
38
38
|
onClose?: () => void;
|
|
39
39
|
}) => HTMLElement | null;
|
|
@@ -42,7 +42,7 @@ interface ChatWidgetPlugin {
|
|
|
42
42
|
* Return null to use default renderer
|
|
43
43
|
*/
|
|
44
44
|
renderComposer?: (context: {
|
|
45
|
-
config:
|
|
45
|
+
config: AgentWidgetConfig;
|
|
46
46
|
defaultRenderer: () => HTMLElement;
|
|
47
47
|
onSubmit: (text: string) => void;
|
|
48
48
|
disabled: boolean;
|
|
@@ -52,18 +52,18 @@ interface ChatWidgetPlugin {
|
|
|
52
52
|
* Return null to use default renderer
|
|
53
53
|
*/
|
|
54
54
|
renderReasoning?: (context: {
|
|
55
|
-
message:
|
|
55
|
+
message: AgentWidgetMessage;
|
|
56
56
|
defaultRenderer: () => HTMLElement;
|
|
57
|
-
config:
|
|
57
|
+
config: AgentWidgetConfig;
|
|
58
58
|
}) => HTMLElement | null;
|
|
59
59
|
/**
|
|
60
60
|
* Custom renderer for tool call bubbles
|
|
61
61
|
* Return null to use default renderer
|
|
62
62
|
*/
|
|
63
63
|
renderToolCall?: (context: {
|
|
64
|
-
message:
|
|
64
|
+
message: AgentWidgetMessage;
|
|
65
65
|
defaultRenderer: () => HTMLElement;
|
|
66
|
-
config:
|
|
66
|
+
config: AgentWidgetConfig;
|
|
67
67
|
}) => HTMLElement | null;
|
|
68
68
|
/**
|
|
69
69
|
* Called when plugin is registered
|
|
@@ -75,11 +75,11 @@ interface ChatWidgetPlugin {
|
|
|
75
75
|
onUnregister?: () => void;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
type
|
|
78
|
+
type AgentWidgetFeatureFlags = {
|
|
79
79
|
showReasoning?: boolean;
|
|
80
80
|
showToolCalls?: boolean;
|
|
81
81
|
};
|
|
82
|
-
type
|
|
82
|
+
type AgentWidgetTheme = {
|
|
83
83
|
primary?: string;
|
|
84
84
|
secondary?: string;
|
|
85
85
|
surface?: string;
|
|
@@ -98,6 +98,9 @@ type ChatWidgetTheme = {
|
|
|
98
98
|
closeButtonColor?: string;
|
|
99
99
|
closeButtonBackgroundColor?: string;
|
|
100
100
|
closeButtonBorderColor?: string;
|
|
101
|
+
clearChatIconColor?: string;
|
|
102
|
+
clearChatBackgroundColor?: string;
|
|
103
|
+
clearChatBorderColor?: string;
|
|
101
104
|
micIconColor?: string;
|
|
102
105
|
micBackgroundColor?: string;
|
|
103
106
|
micBorderColor?: string;
|
|
@@ -112,7 +115,7 @@ type ChatWidgetTheme = {
|
|
|
112
115
|
launcherRadius?: string;
|
|
113
116
|
buttonRadius?: string;
|
|
114
117
|
};
|
|
115
|
-
type
|
|
118
|
+
type AgentWidgetLauncherConfig = {
|
|
116
119
|
enabled?: boolean;
|
|
117
120
|
title?: string;
|
|
118
121
|
subtitle?: string;
|
|
@@ -141,9 +144,16 @@ type ChatWidgetLauncherConfig = {
|
|
|
141
144
|
closeButtonBorderWidth?: string;
|
|
142
145
|
closeButtonBorderColor?: string;
|
|
143
146
|
closeButtonBorderRadius?: string;
|
|
147
|
+
closeButtonPaddingX?: string;
|
|
148
|
+
closeButtonPaddingY?: string;
|
|
144
149
|
closeButtonPlacement?: "inline" | "top-right";
|
|
150
|
+
closeButtonIconName?: string;
|
|
151
|
+
closeButtonIconText?: string;
|
|
152
|
+
closeButtonTooltipText?: string;
|
|
153
|
+
closeButtonShowTooltip?: boolean;
|
|
154
|
+
clearChat?: AgentWidgetClearChatConfig;
|
|
145
155
|
};
|
|
146
|
-
type
|
|
156
|
+
type AgentWidgetSendButtonConfig = {
|
|
147
157
|
borderWidth?: string;
|
|
148
158
|
borderColor?: string;
|
|
149
159
|
paddingX?: string;
|
|
@@ -157,14 +167,28 @@ type ChatWidgetSendButtonConfig = {
|
|
|
157
167
|
textColor?: string;
|
|
158
168
|
size?: string;
|
|
159
169
|
};
|
|
160
|
-
type
|
|
170
|
+
type AgentWidgetClearChatConfig = {
|
|
171
|
+
enabled?: boolean;
|
|
172
|
+
iconName?: string;
|
|
173
|
+
iconColor?: string;
|
|
174
|
+
backgroundColor?: string;
|
|
175
|
+
borderWidth?: string;
|
|
176
|
+
borderColor?: string;
|
|
177
|
+
borderRadius?: string;
|
|
178
|
+
size?: string;
|
|
179
|
+
paddingX?: string;
|
|
180
|
+
paddingY?: string;
|
|
181
|
+
tooltipText?: string;
|
|
182
|
+
showTooltip?: boolean;
|
|
183
|
+
};
|
|
184
|
+
type AgentWidgetStatusIndicatorConfig = {
|
|
161
185
|
visible?: boolean;
|
|
162
186
|
idleText?: string;
|
|
163
187
|
connectingText?: string;
|
|
164
188
|
connectedText?: string;
|
|
165
189
|
errorText?: string;
|
|
166
190
|
};
|
|
167
|
-
type
|
|
191
|
+
type AgentWidgetVoiceRecognitionConfig = {
|
|
168
192
|
enabled?: boolean;
|
|
169
193
|
pauseDuration?: number;
|
|
170
194
|
iconName?: string;
|
|
@@ -182,7 +206,7 @@ type ChatWidgetVoiceRecognitionConfig = {
|
|
|
182
206
|
recordingBorderColor?: string;
|
|
183
207
|
showRecordingIndicator?: boolean;
|
|
184
208
|
};
|
|
185
|
-
type
|
|
209
|
+
type AgentWidgetConfig = {
|
|
186
210
|
apiUrl?: string;
|
|
187
211
|
flowId?: string;
|
|
188
212
|
headers?: Record<string, string>;
|
|
@@ -192,26 +216,26 @@ type ChatWidgetConfig = {
|
|
|
192
216
|
inputPlaceholder?: string;
|
|
193
217
|
sendButtonLabel?: string;
|
|
194
218
|
};
|
|
195
|
-
theme?:
|
|
196
|
-
features?:
|
|
197
|
-
launcher?:
|
|
198
|
-
initialMessages?:
|
|
219
|
+
theme?: AgentWidgetTheme;
|
|
220
|
+
features?: AgentWidgetFeatureFlags;
|
|
221
|
+
launcher?: AgentWidgetLauncherConfig;
|
|
222
|
+
initialMessages?: AgentWidgetMessage[];
|
|
199
223
|
suggestionChips?: string[];
|
|
200
224
|
debug?: boolean;
|
|
201
225
|
formEndpoint?: string;
|
|
202
226
|
launcherWidth?: string;
|
|
203
|
-
sendButton?:
|
|
204
|
-
statusIndicator?:
|
|
205
|
-
voiceRecognition?:
|
|
227
|
+
sendButton?: AgentWidgetSendButtonConfig;
|
|
228
|
+
statusIndicator?: AgentWidgetStatusIndicatorConfig;
|
|
229
|
+
voiceRecognition?: AgentWidgetVoiceRecognitionConfig;
|
|
206
230
|
postprocessMessage?: (context: {
|
|
207
231
|
text: string;
|
|
208
|
-
message:
|
|
232
|
+
message: AgentWidgetMessage;
|
|
209
233
|
streaming: boolean;
|
|
210
234
|
}) => string;
|
|
211
|
-
plugins?:
|
|
235
|
+
plugins?: AgentWidgetPlugin[];
|
|
212
236
|
};
|
|
213
|
-
type
|
|
214
|
-
type
|
|
237
|
+
type AgentWidgetMessageRole = "user" | "assistant" | "system";
|
|
238
|
+
type AgentWidgetReasoning = {
|
|
215
239
|
id: string;
|
|
216
240
|
status: "pending" | "streaming" | "complete";
|
|
217
241
|
chunks: string[];
|
|
@@ -219,7 +243,7 @@ type ChatWidgetReasoning = {
|
|
|
219
243
|
completedAt?: number;
|
|
220
244
|
durationMs?: number;
|
|
221
245
|
};
|
|
222
|
-
type
|
|
246
|
+
type AgentWidgetToolCall = {
|
|
223
247
|
id: string;
|
|
224
248
|
name?: string;
|
|
225
249
|
status: "pending" | "running" | "complete";
|
|
@@ -231,22 +255,22 @@ type ChatWidgetToolCall = {
|
|
|
231
255
|
completedAt?: number;
|
|
232
256
|
durationMs?: number;
|
|
233
257
|
};
|
|
234
|
-
type
|
|
235
|
-
type
|
|
258
|
+
type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool";
|
|
259
|
+
type AgentWidgetMessage = {
|
|
236
260
|
id: string;
|
|
237
|
-
role:
|
|
261
|
+
role: AgentWidgetMessageRole;
|
|
238
262
|
content: string;
|
|
239
263
|
createdAt: string;
|
|
240
264
|
streaming?: boolean;
|
|
241
|
-
variant?:
|
|
265
|
+
variant?: AgentWidgetMessageVariant;
|
|
242
266
|
sequence?: number;
|
|
243
|
-
reasoning?:
|
|
244
|
-
toolCall?:
|
|
245
|
-
tools?:
|
|
267
|
+
reasoning?: AgentWidgetReasoning;
|
|
268
|
+
toolCall?: AgentWidgetToolCall;
|
|
269
|
+
tools?: AgentWidgetToolCall[];
|
|
246
270
|
};
|
|
247
|
-
type
|
|
271
|
+
type AgentWidgetEvent = {
|
|
248
272
|
type: "message";
|
|
249
|
-
message:
|
|
273
|
+
message: AgentWidgetMessage;
|
|
250
274
|
} | {
|
|
251
275
|
type: "status";
|
|
252
276
|
status: "connecting" | "connected" | "error" | "idle";
|
|
@@ -254,36 +278,37 @@ type ChatWidgetEvent = {
|
|
|
254
278
|
type: "error";
|
|
255
279
|
error: Error;
|
|
256
280
|
};
|
|
257
|
-
type
|
|
281
|
+
type AgentWidgetInitOptions = {
|
|
258
282
|
target: string | HTMLElement;
|
|
259
|
-
config?:
|
|
283
|
+
config?: AgentWidgetConfig;
|
|
260
284
|
useShadowDom?: boolean;
|
|
261
285
|
onReady?: () => void;
|
|
262
286
|
};
|
|
263
287
|
|
|
264
288
|
type Controller = {
|
|
265
|
-
update: (config:
|
|
289
|
+
update: (config: AgentWidgetConfig) => void;
|
|
266
290
|
destroy: () => void;
|
|
267
291
|
open: () => void;
|
|
268
292
|
close: () => void;
|
|
269
293
|
toggle: () => void;
|
|
294
|
+
clearChat: () => void;
|
|
270
295
|
};
|
|
271
|
-
declare const
|
|
272
|
-
type
|
|
296
|
+
declare const createAgentExperience: (mount: HTMLElement, initialConfig?: AgentWidgetConfig) => Controller;
|
|
297
|
+
type AgentWidgetController = Controller;
|
|
273
298
|
|
|
274
|
-
type
|
|
299
|
+
type AgentWidgetInitHandle = AgentWidgetController & {
|
|
275
300
|
host: HTMLElement;
|
|
276
301
|
};
|
|
277
|
-
declare const
|
|
302
|
+
declare const initAgentWidget: (options: AgentWidgetInitOptions) => AgentWidgetInitHandle;
|
|
278
303
|
|
|
279
|
-
type
|
|
304
|
+
type AgentWidgetSessionStatus = "idle" | "connecting" | "connected" | "error";
|
|
280
305
|
type SessionCallbacks = {
|
|
281
|
-
onMessagesChanged: (messages:
|
|
282
|
-
onStatusChanged: (status:
|
|
306
|
+
onMessagesChanged: (messages: AgentWidgetMessage[]) => void;
|
|
307
|
+
onStatusChanged: (status: AgentWidgetSessionStatus) => void;
|
|
283
308
|
onStreamingChanged: (streaming: boolean) => void;
|
|
284
309
|
onError?: (error: Error) => void;
|
|
285
310
|
};
|
|
286
|
-
declare class
|
|
311
|
+
declare class AgentWidgetSession {
|
|
287
312
|
private config;
|
|
288
313
|
private callbacks;
|
|
289
314
|
private client;
|
|
@@ -292,13 +317,14 @@ declare class ChatWidgetSession {
|
|
|
292
317
|
private streaming;
|
|
293
318
|
private abortController;
|
|
294
319
|
private sequenceCounter;
|
|
295
|
-
constructor(config:
|
|
296
|
-
updateConfig(next:
|
|
297
|
-
getMessages():
|
|
298
|
-
getStatus():
|
|
320
|
+
constructor(config: AgentWidgetConfig | undefined, callbacks: SessionCallbacks);
|
|
321
|
+
updateConfig(next: AgentWidgetConfig): void;
|
|
322
|
+
getMessages(): AgentWidgetMessage[];
|
|
323
|
+
getStatus(): AgentWidgetSessionStatus;
|
|
299
324
|
isStreaming(): boolean;
|
|
300
325
|
sendMessage(rawInput: string): Promise<void>;
|
|
301
326
|
cancel(): void;
|
|
327
|
+
clearMessages(): void;
|
|
302
328
|
private handleEvent;
|
|
303
329
|
private setStatus;
|
|
304
330
|
private setStreaming;
|
|
@@ -310,16 +336,16 @@ declare class ChatWidgetSession {
|
|
|
310
336
|
}
|
|
311
337
|
|
|
312
338
|
type DispatchOptions = {
|
|
313
|
-
messages:
|
|
339
|
+
messages: AgentWidgetMessage[];
|
|
314
340
|
signal?: AbortSignal;
|
|
315
341
|
};
|
|
316
|
-
type SSEHandler = (event:
|
|
317
|
-
declare class
|
|
342
|
+
type SSEHandler = (event: AgentWidgetEvent) => void;
|
|
343
|
+
declare class AgentWidgetClient {
|
|
318
344
|
private config;
|
|
319
345
|
private readonly apiUrl;
|
|
320
346
|
private readonly headers;
|
|
321
347
|
private readonly debug;
|
|
322
|
-
constructor(config?:
|
|
348
|
+
constructor(config?: AgentWidgetConfig);
|
|
323
349
|
dispatch(options: DispatchOptions, onEvent: SSEHandler): Promise<void>;
|
|
324
350
|
private streamResponse;
|
|
325
351
|
}
|
|
@@ -346,7 +372,7 @@ declare class PluginRegistry {
|
|
|
346
372
|
/**
|
|
347
373
|
* Register a plugin
|
|
348
374
|
*/
|
|
349
|
-
register(plugin:
|
|
375
|
+
register(plugin: AgentWidgetPlugin): void;
|
|
350
376
|
/**
|
|
351
377
|
* Unregister a plugin
|
|
352
378
|
*/
|
|
@@ -354,12 +380,12 @@ declare class PluginRegistry {
|
|
|
354
380
|
/**
|
|
355
381
|
* Get all plugins sorted by priority
|
|
356
382
|
*/
|
|
357
|
-
getAll():
|
|
383
|
+
getAll(): AgentWidgetPlugin[];
|
|
358
384
|
/**
|
|
359
385
|
* Get plugins for a specific instance (from config)
|
|
360
386
|
* Merges instance plugins with globally registered plugins
|
|
361
387
|
*/
|
|
362
|
-
getForInstance(instancePlugins?:
|
|
388
|
+
getForInstance(instancePlugins?: AgentWidgetPlugin[]): AgentWidgetPlugin[];
|
|
363
389
|
/**
|
|
364
390
|
* Clear all plugins
|
|
365
391
|
*/
|
|
@@ -367,4 +393,15 @@ declare class PluginRegistry {
|
|
|
367
393
|
}
|
|
368
394
|
declare const pluginRegistry: PluginRegistry;
|
|
369
395
|
|
|
370
|
-
|
|
396
|
+
/**
|
|
397
|
+
* Default widget configuration
|
|
398
|
+
* Single source of truth for all default values
|
|
399
|
+
*/
|
|
400
|
+
declare const DEFAULT_WIDGET_CONFIG: Partial<AgentWidgetConfig>;
|
|
401
|
+
/**
|
|
402
|
+
* Helper to deep merge user config with defaults
|
|
403
|
+
* This ensures all default values are present while allowing selective overrides
|
|
404
|
+
*/
|
|
405
|
+
declare function mergeWithDefaults(config?: Partial<AgentWidgetConfig>): Partial<AgentWidgetConfig>;
|
|
406
|
+
|
|
407
|
+
export { AgentWidgetClient, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetMessage, type AgentWidgetPlugin, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetTheme, DEFAULT_WIDGET_CONFIG, createAgentExperience, initAgentWidget as default, directivePostprocessor, escapeHtml, initAgentWidget, markdownPostprocessor, mergeWithDefaults, pluginRegistry };
|