vanilla-agent 0.2.0 → 1.1.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 +73 -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 +43 -4
- 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 +73 -0
- package/src/types.ts +56 -31
- package/src/ui.ts +338 -53
- 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/src/plugins/registry.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentWidgetPlugin } from "./types";
|
|
2
2
|
|
|
3
3
|
class PluginRegistry {
|
|
4
|
-
private plugins: Map<string,
|
|
4
|
+
private plugins: Map<string, AgentWidgetPlugin> = new Map();
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Register a plugin
|
|
8
8
|
*/
|
|
9
|
-
register(plugin:
|
|
9
|
+
register(plugin: AgentWidgetPlugin): void {
|
|
10
10
|
if (this.plugins.has(plugin.id)) {
|
|
11
11
|
console.warn(`Plugin "${plugin.id}" is already registered. Overwriting.`);
|
|
12
12
|
}
|
|
@@ -29,7 +29,7 @@ class PluginRegistry {
|
|
|
29
29
|
/**
|
|
30
30
|
* Get all plugins sorted by priority
|
|
31
31
|
*/
|
|
32
|
-
getAll():
|
|
32
|
+
getAll(): AgentWidgetPlugin[] {
|
|
33
33
|
return Array.from(this.plugins.values()).sort(
|
|
34
34
|
(a, b) => (b.priority ?? 0) - (a.priority ?? 0)
|
|
35
35
|
);
|
|
@@ -39,7 +39,7 @@ class PluginRegistry {
|
|
|
39
39
|
* Get plugins for a specific instance (from config)
|
|
40
40
|
* Merges instance plugins with globally registered plugins
|
|
41
41
|
*/
|
|
42
|
-
getForInstance(instancePlugins?:
|
|
42
|
+
getForInstance(instancePlugins?: AgentWidgetPlugin[]): AgentWidgetPlugin[] {
|
|
43
43
|
const allPlugins = this.getAll();
|
|
44
44
|
|
|
45
45
|
if (!instancePlugins || instancePlugins.length === 0) {
|
|
@@ -70,3 +70,5 @@ export const pluginRegistry = new PluginRegistry();
|
|
|
70
70
|
|
|
71
71
|
|
|
72
72
|
|
|
73
|
+
|
|
74
|
+
|
package/src/plugins/types.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentWidgetMessage, AgentWidgetConfig } from "../types";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Plugin interface for customizing widget components
|
|
5
5
|
*/
|
|
6
|
-
export interface
|
|
6
|
+
export interface AgentWidgetPlugin {
|
|
7
7
|
/**
|
|
8
8
|
* Unique identifier for the plugin
|
|
9
9
|
*/
|
|
@@ -19,9 +19,9 @@ export interface ChatWidgetPlugin {
|
|
|
19
19
|
* Return null to use default renderer
|
|
20
20
|
*/
|
|
21
21
|
renderMessage?: (context: {
|
|
22
|
-
message:
|
|
22
|
+
message: AgentWidgetMessage;
|
|
23
23
|
defaultRenderer: () => HTMLElement;
|
|
24
|
-
config:
|
|
24
|
+
config: AgentWidgetConfig;
|
|
25
25
|
}) => HTMLElement | null;
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -29,7 +29,7 @@ export interface ChatWidgetPlugin {
|
|
|
29
29
|
* Return null to use default renderer
|
|
30
30
|
*/
|
|
31
31
|
renderLauncher?: (context: {
|
|
32
|
-
config:
|
|
32
|
+
config: AgentWidgetConfig;
|
|
33
33
|
defaultRenderer: () => HTMLElement;
|
|
34
34
|
onToggle: () => void;
|
|
35
35
|
}) => HTMLElement | null;
|
|
@@ -39,7 +39,7 @@ export interface ChatWidgetPlugin {
|
|
|
39
39
|
* Return null to use default renderer
|
|
40
40
|
*/
|
|
41
41
|
renderHeader?: (context: {
|
|
42
|
-
config:
|
|
42
|
+
config: AgentWidgetConfig;
|
|
43
43
|
defaultRenderer: () => HTMLElement;
|
|
44
44
|
onClose?: () => void;
|
|
45
45
|
}) => HTMLElement | null;
|
|
@@ -49,7 +49,7 @@ export interface ChatWidgetPlugin {
|
|
|
49
49
|
* Return null to use default renderer
|
|
50
50
|
*/
|
|
51
51
|
renderComposer?: (context: {
|
|
52
|
-
config:
|
|
52
|
+
config: AgentWidgetConfig;
|
|
53
53
|
defaultRenderer: () => HTMLElement;
|
|
54
54
|
onSubmit: (text: string) => void;
|
|
55
55
|
disabled: boolean;
|
|
@@ -60,9 +60,9 @@ export interface ChatWidgetPlugin {
|
|
|
60
60
|
* Return null to use default renderer
|
|
61
61
|
*/
|
|
62
62
|
renderReasoning?: (context: {
|
|
63
|
-
message:
|
|
63
|
+
message: AgentWidgetMessage;
|
|
64
64
|
defaultRenderer: () => HTMLElement;
|
|
65
|
-
config:
|
|
65
|
+
config: AgentWidgetConfig;
|
|
66
66
|
}) => HTMLElement | null;
|
|
67
67
|
|
|
68
68
|
/**
|
|
@@ -70,9 +70,9 @@ export interface ChatWidgetPlugin {
|
|
|
70
70
|
* Return null to use default renderer
|
|
71
71
|
*/
|
|
72
72
|
renderToolCall?: (context: {
|
|
73
|
-
message:
|
|
73
|
+
message: AgentWidgetMessage;
|
|
74
74
|
defaultRenderer: () => HTMLElement;
|
|
75
|
-
config:
|
|
75
|
+
config: AgentWidgetConfig;
|
|
76
76
|
}) => HTMLElement | null;
|
|
77
77
|
|
|
78
78
|
/**
|
|
@@ -88,3 +88,5 @@ export interface ChatWidgetPlugin {
|
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
|
|
91
|
+
|
|
92
|
+
|
package/src/runtime/init.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createAgentExperience, AgentWidgetController } from "../ui";
|
|
2
|
+
import { AgentWidgetConfig, AgentWidgetInitOptions } from "../types";
|
|
3
3
|
|
|
4
4
|
const ensureTarget = (target: string | HTMLElement): HTMLElement => {
|
|
5
5
|
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
@@ -84,11 +84,11 @@ const mountStyles = (root: ShadowRoot | HTMLElement) => {
|
|
|
84
84
|
}
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
export type
|
|
87
|
+
export type AgentWidgetInitHandle = AgentWidgetController & { host: HTMLElement };
|
|
88
88
|
|
|
89
|
-
export const
|
|
90
|
-
options:
|
|
91
|
-
):
|
|
89
|
+
export const initAgentWidget = (
|
|
90
|
+
options: AgentWidgetInitOptions
|
|
91
|
+
): AgentWidgetInitHandle => {
|
|
92
92
|
const target = ensureTarget(options.target);
|
|
93
93
|
const host = document.createElement("div");
|
|
94
94
|
host.className = "vanilla-agent-host";
|
|
@@ -113,12 +113,12 @@ export const initChatWidget = (
|
|
|
113
113
|
mountStyles(host);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
let controller =
|
|
116
|
+
let controller = createAgentExperience(mount, options.config);
|
|
117
117
|
options.onReady?.();
|
|
118
118
|
|
|
119
119
|
return {
|
|
120
120
|
host,
|
|
121
|
-
update(nextConfig:
|
|
121
|
+
update(nextConfig: AgentWidgetConfig) {
|
|
122
122
|
controller.update(nextConfig);
|
|
123
123
|
},
|
|
124
124
|
open() {
|
|
@@ -130,6 +130,9 @@ export const initChatWidget = (
|
|
|
130
130
|
toggle() {
|
|
131
131
|
controller.toggle();
|
|
132
132
|
},
|
|
133
|
+
clearChat() {
|
|
134
|
+
controller.clearChat();
|
|
135
|
+
},
|
|
133
136
|
destroy() {
|
|
134
137
|
controller.destroy();
|
|
135
138
|
host.remove();
|
package/src/session.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentWidgetClient } from "./client";
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
AgentWidgetConfig,
|
|
4
|
+
AgentWidgetEvent,
|
|
5
|
+
AgentWidgetMessage
|
|
6
6
|
} from "./types";
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type AgentWidgetSessionStatus =
|
|
9
9
|
| "idle"
|
|
10
10
|
| "connecting"
|
|
11
11
|
| "connected"
|
|
12
12
|
| "error";
|
|
13
13
|
|
|
14
14
|
type SessionCallbacks = {
|
|
15
|
-
onMessagesChanged: (messages:
|
|
16
|
-
onStatusChanged: (status:
|
|
15
|
+
onMessagesChanged: (messages: AgentWidgetMessage[]) => void;
|
|
16
|
+
onStatusChanged: (status: AgentWidgetSessionStatus) => void;
|
|
17
17
|
onStreamingChanged: (streaming: boolean) => void;
|
|
18
18
|
onError?: (error: Error) => void;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export class
|
|
22
|
-
private client:
|
|
23
|
-
private messages:
|
|
24
|
-
private status:
|
|
21
|
+
export class AgentWidgetSession {
|
|
22
|
+
private client: AgentWidgetClient;
|
|
23
|
+
private messages: AgentWidgetMessage[];
|
|
24
|
+
private status: AgentWidgetSessionStatus = "idle";
|
|
25
25
|
private streaming = false;
|
|
26
26
|
private abortController: AbortController | null = null;
|
|
27
27
|
private sequenceCounter = Date.now();
|
|
28
28
|
|
|
29
29
|
constructor(
|
|
30
|
-
private config:
|
|
30
|
+
private config: AgentWidgetConfig = {},
|
|
31
31
|
private callbacks: SessionCallbacks
|
|
32
32
|
) {
|
|
33
33
|
this.messages = [...(config.initialMessages ?? [])].map((message) => ({
|
|
@@ -35,7 +35,7 @@ export class ChatWidgetSession {
|
|
|
35
35
|
sequence: message.sequence ?? this.nextSequence()
|
|
36
36
|
}));
|
|
37
37
|
this.messages = this.sortMessages(this.messages);
|
|
38
|
-
this.client = new
|
|
38
|
+
this.client = new AgentWidgetClient(config);
|
|
39
39
|
|
|
40
40
|
if (this.messages.length) {
|
|
41
41
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
@@ -43,9 +43,9 @@ export class ChatWidgetSession {
|
|
|
43
43
|
this.callbacks.onStatusChanged(this.status);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
public updateConfig(next:
|
|
46
|
+
public updateConfig(next: AgentWidgetConfig) {
|
|
47
47
|
this.config = { ...this.config, ...next };
|
|
48
|
-
this.client = new
|
|
48
|
+
this.client = new AgentWidgetClient(this.config);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
public getMessages() {
|
|
@@ -66,7 +66,7 @@ export class ChatWidgetSession {
|
|
|
66
66
|
|
|
67
67
|
this.abortController?.abort();
|
|
68
68
|
|
|
69
|
-
const userMessage:
|
|
69
|
+
const userMessage: AgentWidgetMessage = {
|
|
70
70
|
id: `user-${Date.now()}`,
|
|
71
71
|
role: "user",
|
|
72
72
|
content: input,
|
|
@@ -91,7 +91,7 @@ export class ChatWidgetSession {
|
|
|
91
91
|
this.handleEvent
|
|
92
92
|
);
|
|
93
93
|
} catch (error) {
|
|
94
|
-
const fallback:
|
|
94
|
+
const fallback: AgentWidgetMessage = {
|
|
95
95
|
id: `assistant-${Date.now()}`,
|
|
96
96
|
role: "assistant",
|
|
97
97
|
createdAt: new Date().toISOString(),
|
|
@@ -119,7 +119,16 @@ export class ChatWidgetSession {
|
|
|
119
119
|
this.setStatus("idle");
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
|
|
122
|
+
public clearMessages() {
|
|
123
|
+
this.abortController?.abort();
|
|
124
|
+
this.abortController = null;
|
|
125
|
+
this.messages = [];
|
|
126
|
+
this.setStreaming(false);
|
|
127
|
+
this.setStatus("idle");
|
|
128
|
+
this.callbacks.onMessagesChanged([...this.messages]);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private handleEvent = (event: AgentWidgetEvent) => {
|
|
123
132
|
if (event.type === "message") {
|
|
124
133
|
this.upsertMessage(event.message);
|
|
125
134
|
} else if (event.type === "status") {
|
|
@@ -138,7 +147,7 @@ export class ChatWidgetSession {
|
|
|
138
147
|
}
|
|
139
148
|
};
|
|
140
149
|
|
|
141
|
-
private setStatus(status:
|
|
150
|
+
private setStatus(status: AgentWidgetSessionStatus) {
|
|
142
151
|
if (this.status === status) return;
|
|
143
152
|
this.status = status;
|
|
144
153
|
this.callbacks.onStatusChanged(status);
|
|
@@ -150,13 +159,13 @@ export class ChatWidgetSession {
|
|
|
150
159
|
this.callbacks.onStreamingChanged(streaming);
|
|
151
160
|
}
|
|
152
161
|
|
|
153
|
-
private appendMessage(message:
|
|
162
|
+
private appendMessage(message: AgentWidgetMessage) {
|
|
154
163
|
const withSequence = this.ensureSequence(message);
|
|
155
164
|
this.messages = this.sortMessages([...this.messages, withSequence]);
|
|
156
165
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
157
166
|
}
|
|
158
167
|
|
|
159
|
-
private upsertMessage(message:
|
|
168
|
+
private upsertMessage(message: AgentWidgetMessage) {
|
|
160
169
|
const withSequence = this.ensureSequence(message);
|
|
161
170
|
const index = this.messages.findIndex((m) => m.id === withSequence.id);
|
|
162
171
|
if (index === -1) {
|
|
@@ -171,7 +180,7 @@ export class ChatWidgetSession {
|
|
|
171
180
|
this.callbacks.onMessagesChanged([...this.messages]);
|
|
172
181
|
}
|
|
173
182
|
|
|
174
|
-
private ensureSequence(message:
|
|
183
|
+
private ensureSequence(message: AgentWidgetMessage): AgentWidgetMessage {
|
|
175
184
|
if (message.sequence !== undefined) {
|
|
176
185
|
return { ...message };
|
|
177
186
|
}
|
|
@@ -185,7 +194,7 @@ export class ChatWidgetSession {
|
|
|
185
194
|
return this.sequenceCounter++;
|
|
186
195
|
}
|
|
187
196
|
|
|
188
|
-
private sortMessages(messages:
|
|
197
|
+
private sortMessages(messages: AgentWidgetMessage[]) {
|
|
189
198
|
return [...messages].sort((a, b) => {
|
|
190
199
|
// Sort by createdAt timestamp first (chronological order)
|
|
191
200
|
const timeA = new Date(a.createdAt).getTime();
|
package/src/styles/widget.css
CHANGED
|
@@ -572,6 +572,10 @@
|
|
|
572
572
|
width: 360px;
|
|
573
573
|
}
|
|
574
574
|
|
|
575
|
+
.tvw-w-\[400px\] {
|
|
576
|
+
width: 400px;
|
|
577
|
+
}
|
|
578
|
+
|
|
575
579
|
.tvw-h-\[640px\] {
|
|
576
580
|
height: 640px;
|
|
577
581
|
}
|
|
@@ -687,6 +691,35 @@ form:focus-within textarea {
|
|
|
687
691
|
opacity: 1;
|
|
688
692
|
}
|
|
689
693
|
|
|
694
|
+
/* Clear chat button tooltip */
|
|
695
|
+
.tvw-clear-chat-button-wrapper {
|
|
696
|
+
position: relative;
|
|
697
|
+
display: inline-flex;
|
|
698
|
+
align-items: center;
|
|
699
|
+
justify-content: center;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
.tvw-clear-chat-tooltip {
|
|
703
|
+
background-color: #111827;
|
|
704
|
+
color: #ffffff;
|
|
705
|
+
padding: 6px 12px;
|
|
706
|
+
border-radius: 0.5rem;
|
|
707
|
+
font-size: 12px;
|
|
708
|
+
white-space: nowrap;
|
|
709
|
+
pointer-events: none;
|
|
710
|
+
z-index: 10000;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
.tvw-clear-chat-tooltip-arrow {
|
|
714
|
+
content: "";
|
|
715
|
+
position: absolute;
|
|
716
|
+
top: 100%;
|
|
717
|
+
left: 50%;
|
|
718
|
+
transform: translateX(-50%);
|
|
719
|
+
border: 4px solid transparent;
|
|
720
|
+
border-top-color: #111827;
|
|
721
|
+
}
|
|
722
|
+
|
|
690
723
|
/* Typing indicator animation */
|
|
691
724
|
@keyframes typing {
|
|
692
725
|
0%, 100% {
|
|
@@ -750,3 +783,43 @@ form:focus-within textarea {
|
|
|
750
783
|
.tvw-voice-recording svg {
|
|
751
784
|
animation: voice-recording-pulse 1.5s ease-in-out infinite;
|
|
752
785
|
}
|
|
786
|
+
|
|
787
|
+
/* Markdown content overflow handling */
|
|
788
|
+
#vanilla-agent-root pre {
|
|
789
|
+
overflow-x: auto;
|
|
790
|
+
max-width: 100%;
|
|
791
|
+
word-wrap: break-word;
|
|
792
|
+
word-break: break-word;
|
|
793
|
+
white-space: pre-wrap;
|
|
794
|
+
background-color: #f3f4f6;
|
|
795
|
+
padding: 0.75rem;
|
|
796
|
+
border-radius: 0.375rem;
|
|
797
|
+
margin: 0.5rem 0;
|
|
798
|
+
font-size: 0.875rem;
|
|
799
|
+
line-height: 1.5;
|
|
800
|
+
border: 1px solid #e5e7eb;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
#vanilla-agent-root code {
|
|
804
|
+
word-break: break-word;
|
|
805
|
+
word-wrap: break-word;
|
|
806
|
+
white-space: pre-wrap;
|
|
807
|
+
overflow-wrap: break-word;
|
|
808
|
+
font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, "Liberation Mono", Menlo, monospace;
|
|
809
|
+
font-size: 0.875em;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
#vanilla-agent-root pre code {
|
|
813
|
+
font-size: inherit;
|
|
814
|
+
background-color: transparent;
|
|
815
|
+
padding: 0;
|
|
816
|
+
border-radius: 0;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
#vanilla-agent-root img {
|
|
820
|
+
max-width: 100%;
|
|
821
|
+
height: auto;
|
|
822
|
+
display: block;
|
|
823
|
+
margin: 0.5rem 0;
|
|
824
|
+
border-radius: 0.375rem;
|
|
825
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentWidgetPlugin } from "./plugins/types";
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type AgentWidgetFeatureFlags = {
|
|
4
4
|
showReasoning?: boolean;
|
|
5
5
|
showToolCalls?: boolean;
|
|
6
6
|
};
|
|
7
7
|
|
|
8
|
-
export type
|
|
8
|
+
export type AgentWidgetTheme = {
|
|
9
9
|
primary?: string;
|
|
10
10
|
secondary?: string;
|
|
11
11
|
surface?: string;
|
|
@@ -24,6 +24,9 @@ export type ChatWidgetTheme = {
|
|
|
24
24
|
closeButtonColor?: string;
|
|
25
25
|
closeButtonBackgroundColor?: string;
|
|
26
26
|
closeButtonBorderColor?: string;
|
|
27
|
+
clearChatIconColor?: string;
|
|
28
|
+
clearChatBackgroundColor?: string;
|
|
29
|
+
clearChatBorderColor?: string;
|
|
27
30
|
micIconColor?: string;
|
|
28
31
|
micBackgroundColor?: string;
|
|
29
32
|
micBorderColor?: string;
|
|
@@ -39,7 +42,7 @@ export type ChatWidgetTheme = {
|
|
|
39
42
|
buttonRadius?: string;
|
|
40
43
|
};
|
|
41
44
|
|
|
42
|
-
export type
|
|
45
|
+
export type AgentWidgetLauncherConfig = {
|
|
43
46
|
enabled?: boolean;
|
|
44
47
|
title?: string;
|
|
45
48
|
subtitle?: string;
|
|
@@ -68,10 +71,17 @@ export type ChatWidgetLauncherConfig = {
|
|
|
68
71
|
closeButtonBorderWidth?: string;
|
|
69
72
|
closeButtonBorderColor?: string;
|
|
70
73
|
closeButtonBorderRadius?: string;
|
|
74
|
+
closeButtonPaddingX?: string;
|
|
75
|
+
closeButtonPaddingY?: string;
|
|
71
76
|
closeButtonPlacement?: "inline" | "top-right";
|
|
77
|
+
closeButtonIconName?: string;
|
|
78
|
+
closeButtonIconText?: string;
|
|
79
|
+
closeButtonTooltipText?: string;
|
|
80
|
+
closeButtonShowTooltip?: boolean;
|
|
81
|
+
clearChat?: AgentWidgetClearChatConfig;
|
|
72
82
|
};
|
|
73
83
|
|
|
74
|
-
export type
|
|
84
|
+
export type AgentWidgetSendButtonConfig = {
|
|
75
85
|
borderWidth?: string;
|
|
76
86
|
borderColor?: string;
|
|
77
87
|
paddingX?: string;
|
|
@@ -86,7 +96,22 @@ export type ChatWidgetSendButtonConfig = {
|
|
|
86
96
|
size?: string;
|
|
87
97
|
};
|
|
88
98
|
|
|
89
|
-
export type
|
|
99
|
+
export type AgentWidgetClearChatConfig = {
|
|
100
|
+
enabled?: boolean;
|
|
101
|
+
iconName?: string;
|
|
102
|
+
iconColor?: string;
|
|
103
|
+
backgroundColor?: string;
|
|
104
|
+
borderWidth?: string;
|
|
105
|
+
borderColor?: string;
|
|
106
|
+
borderRadius?: string;
|
|
107
|
+
size?: string;
|
|
108
|
+
paddingX?: string;
|
|
109
|
+
paddingY?: string;
|
|
110
|
+
tooltipText?: string;
|
|
111
|
+
showTooltip?: boolean;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export type AgentWidgetStatusIndicatorConfig = {
|
|
90
115
|
visible?: boolean;
|
|
91
116
|
idleText?: string;
|
|
92
117
|
connectingText?: string;
|
|
@@ -94,7 +119,7 @@ export type ChatWidgetStatusIndicatorConfig = {
|
|
|
94
119
|
errorText?: string;
|
|
95
120
|
};
|
|
96
121
|
|
|
97
|
-
export type
|
|
122
|
+
export type AgentWidgetVoiceRecognitionConfig = {
|
|
98
123
|
enabled?: boolean;
|
|
99
124
|
pauseDuration?: number;
|
|
100
125
|
iconName?: string;
|
|
@@ -113,7 +138,7 @@ export type ChatWidgetVoiceRecognitionConfig = {
|
|
|
113
138
|
showRecordingIndicator?: boolean;
|
|
114
139
|
};
|
|
115
140
|
|
|
116
|
-
export type
|
|
141
|
+
export type AgentWidgetConfig = {
|
|
117
142
|
apiUrl?: string;
|
|
118
143
|
flowId?: string;
|
|
119
144
|
headers?: Record<string, string>;
|
|
@@ -123,28 +148,28 @@ export type ChatWidgetConfig = {
|
|
|
123
148
|
inputPlaceholder?: string;
|
|
124
149
|
sendButtonLabel?: string;
|
|
125
150
|
};
|
|
126
|
-
theme?:
|
|
127
|
-
features?:
|
|
128
|
-
launcher?:
|
|
129
|
-
initialMessages?:
|
|
151
|
+
theme?: AgentWidgetTheme;
|
|
152
|
+
features?: AgentWidgetFeatureFlags;
|
|
153
|
+
launcher?: AgentWidgetLauncherConfig;
|
|
154
|
+
initialMessages?: AgentWidgetMessage[];
|
|
130
155
|
suggestionChips?: string[];
|
|
131
156
|
debug?: boolean;
|
|
132
157
|
formEndpoint?: string;
|
|
133
158
|
launcherWidth?: string;
|
|
134
|
-
sendButton?:
|
|
135
|
-
statusIndicator?:
|
|
136
|
-
voiceRecognition?:
|
|
159
|
+
sendButton?: AgentWidgetSendButtonConfig;
|
|
160
|
+
statusIndicator?: AgentWidgetStatusIndicatorConfig;
|
|
161
|
+
voiceRecognition?: AgentWidgetVoiceRecognitionConfig;
|
|
137
162
|
postprocessMessage?: (context: {
|
|
138
163
|
text: string;
|
|
139
|
-
message:
|
|
164
|
+
message: AgentWidgetMessage;
|
|
140
165
|
streaming: boolean;
|
|
141
166
|
}) => string;
|
|
142
|
-
plugins?:
|
|
167
|
+
plugins?: AgentWidgetPlugin[];
|
|
143
168
|
};
|
|
144
169
|
|
|
145
|
-
export type
|
|
170
|
+
export type AgentWidgetMessageRole = "user" | "assistant" | "system";
|
|
146
171
|
|
|
147
|
-
export type
|
|
172
|
+
export type AgentWidgetReasoning = {
|
|
148
173
|
id: string;
|
|
149
174
|
status: "pending" | "streaming" | "complete";
|
|
150
175
|
chunks: string[];
|
|
@@ -153,7 +178,7 @@ export type ChatWidgetReasoning = {
|
|
|
153
178
|
durationMs?: number;
|
|
154
179
|
};
|
|
155
180
|
|
|
156
|
-
export type
|
|
181
|
+
export type AgentWidgetToolCall = {
|
|
157
182
|
id: string;
|
|
158
183
|
name?: string;
|
|
159
184
|
status: "pending" | "running" | "complete";
|
|
@@ -166,29 +191,29 @@ export type ChatWidgetToolCall = {
|
|
|
166
191
|
durationMs?: number;
|
|
167
192
|
};
|
|
168
193
|
|
|
169
|
-
export type
|
|
194
|
+
export type AgentWidgetMessageVariant = "assistant" | "reasoning" | "tool";
|
|
170
195
|
|
|
171
|
-
export type
|
|
196
|
+
export type AgentWidgetMessage = {
|
|
172
197
|
id: string;
|
|
173
|
-
role:
|
|
198
|
+
role: AgentWidgetMessageRole;
|
|
174
199
|
content: string;
|
|
175
200
|
createdAt: string;
|
|
176
201
|
streaming?: boolean;
|
|
177
|
-
variant?:
|
|
202
|
+
variant?: AgentWidgetMessageVariant;
|
|
178
203
|
sequence?: number;
|
|
179
|
-
reasoning?:
|
|
180
|
-
toolCall?:
|
|
181
|
-
tools?:
|
|
204
|
+
reasoning?: AgentWidgetReasoning;
|
|
205
|
+
toolCall?: AgentWidgetToolCall;
|
|
206
|
+
tools?: AgentWidgetToolCall[];
|
|
182
207
|
};
|
|
183
208
|
|
|
184
|
-
export type
|
|
185
|
-
| { type: "message"; message:
|
|
209
|
+
export type AgentWidgetEvent =
|
|
210
|
+
| { type: "message"; message: AgentWidgetMessage }
|
|
186
211
|
| { type: "status"; status: "connecting" | "connected" | "error" | "idle" }
|
|
187
212
|
| { type: "error"; error: Error };
|
|
188
213
|
|
|
189
|
-
export type
|
|
214
|
+
export type AgentWidgetInitOptions = {
|
|
190
215
|
target: string | HTMLElement;
|
|
191
|
-
config?:
|
|
216
|
+
config?: AgentWidgetConfig;
|
|
192
217
|
useShadowDom?: boolean;
|
|
193
218
|
onReady?: () => void;
|
|
194
219
|
};
|