@botdojo/chat-sdk 0.0.2
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/LICENSE +27 -0
- package/README.md +536 -0
- package/lib/index.d.ts +384 -0
- package/lib/index.js +9206 -0
- package/lib/index.js.map +1 -0
- package/package.json +62 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import React$1 from 'react';
|
|
2
|
+
import { ModelContext, BotDojoConnector as BotDojoConnector$1 } from '@botdojo/sdk-canvas';
|
|
3
|
+
export { BotDojoConnector } from '@botdojo/sdk-canvas';
|
|
4
|
+
import { ModelContext as ModelContext$1 } from '@botdojo/sdk-types';
|
|
5
|
+
export { ModelContext, ModelContextMessage, ModelContextPrompt, ModelContextResource, ResourceContent, ResourceProvider, ResourceTemplate, ToolDefinition, ToolExecutionContext, ToolResponse, ToolResponseAction, actions, toolResponse } from '@botdojo/sdk-types';
|
|
6
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Display modes for BotDojo chat
|
|
10
|
+
*/
|
|
11
|
+
type BotDojoChatDisplayMode = 'chat-popup' | 'side-panel' | 'side-push' | 'inline';
|
|
12
|
+
/**
|
|
13
|
+
* Popup configuration options
|
|
14
|
+
*/
|
|
15
|
+
interface PopupOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Width of the popup
|
|
18
|
+
* @default '400px'
|
|
19
|
+
*/
|
|
20
|
+
width?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Height of the popup
|
|
23
|
+
* @default '600px'
|
|
24
|
+
*/
|
|
25
|
+
height?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the popup can be resized by the user
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
resizable?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Minimum width when resizing
|
|
33
|
+
* @default '300px'
|
|
34
|
+
*/
|
|
35
|
+
minWidth?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Maximum width when resizing
|
|
38
|
+
* @default 'auto'
|
|
39
|
+
*/
|
|
40
|
+
maxWidth?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Minimum height when resizing
|
|
43
|
+
* @default '400px'
|
|
44
|
+
*/
|
|
45
|
+
minHeight?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Maximum height when resizing
|
|
48
|
+
* @default 'auto'
|
|
49
|
+
*/
|
|
50
|
+
maxHeight?: string;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Side panel configuration options
|
|
54
|
+
*/
|
|
55
|
+
interface SidePanelOptions {
|
|
56
|
+
/**
|
|
57
|
+
* Direction the panel slides in from
|
|
58
|
+
* @default 'right'
|
|
59
|
+
*/
|
|
60
|
+
direction?: 'left' | 'right';
|
|
61
|
+
/**
|
|
62
|
+
* Default width of the panel
|
|
63
|
+
* @default '400px'
|
|
64
|
+
*/
|
|
65
|
+
defaultWidth?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Whether the panel can be resized by the user
|
|
68
|
+
* @default false
|
|
69
|
+
*/
|
|
70
|
+
resizable?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Maximum width when resizing
|
|
73
|
+
* @default '800px'
|
|
74
|
+
*/
|
|
75
|
+
maxWidth?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Minimum width when resizing
|
|
78
|
+
* @default '300px'
|
|
79
|
+
*/
|
|
80
|
+
minWidth?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Control interface for programmatically controlling the BotDojoChat widget
|
|
84
|
+
*/
|
|
85
|
+
interface BotDojoChatControl {
|
|
86
|
+
/**
|
|
87
|
+
* Open the chat widget
|
|
88
|
+
*/
|
|
89
|
+
openChat: () => void;
|
|
90
|
+
/**
|
|
91
|
+
* Close the chat widget
|
|
92
|
+
*/
|
|
93
|
+
closeChat: () => void;
|
|
94
|
+
/**
|
|
95
|
+
* Send a flow request programmatically
|
|
96
|
+
* - Automatically opens the chat if not already open
|
|
97
|
+
* - Waits for connector to initialize
|
|
98
|
+
* - Sends the request via connector.run()
|
|
99
|
+
* @param body - Request body (string or object)
|
|
100
|
+
* @returns Promise resolving to the flow response
|
|
101
|
+
*/
|
|
102
|
+
sendFlowRequest: (body: any) => Promise<any>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Props for BotDojoChat component
|
|
106
|
+
*/
|
|
107
|
+
interface BotDojoChatProps {
|
|
108
|
+
/**
|
|
109
|
+
* BotDojo API key (contains flow ID and configuration)
|
|
110
|
+
*/
|
|
111
|
+
apiKey: string;
|
|
112
|
+
/**
|
|
113
|
+
* How the chat should be displayed:
|
|
114
|
+
* - 'chat-popup': Floating button + popup chat (default)
|
|
115
|
+
* - 'side-panel': Slides in from right side (overlays content)
|
|
116
|
+
* - 'side-push': Slides in from right side (pushes content left)
|
|
117
|
+
* - 'inline': Direct iframe embed at current location
|
|
118
|
+
* @default 'chat-popup'
|
|
119
|
+
*/
|
|
120
|
+
mode?: BotDojoChatDisplayMode;
|
|
121
|
+
/**
|
|
122
|
+
* Configuration options for chat-popup mode
|
|
123
|
+
*/
|
|
124
|
+
popupOptions?: PopupOptions;
|
|
125
|
+
/**
|
|
126
|
+
* Configuration options for side-panel and side-push modes
|
|
127
|
+
*/
|
|
128
|
+
sidePanelOptions?: SidePanelOptions;
|
|
129
|
+
/**
|
|
130
|
+
* Width of the chat container
|
|
131
|
+
* @default '400px'
|
|
132
|
+
*/
|
|
133
|
+
width?: string;
|
|
134
|
+
/**
|
|
135
|
+
* Height of the chat container
|
|
136
|
+
* @default '600px'
|
|
137
|
+
*/
|
|
138
|
+
height?: string;
|
|
139
|
+
/**
|
|
140
|
+
* Primary accent color
|
|
141
|
+
* @default '#4a3ed4'
|
|
142
|
+
*/
|
|
143
|
+
accentColor?: string;
|
|
144
|
+
/**
|
|
145
|
+
* Background color
|
|
146
|
+
* @default '#ffffff'
|
|
147
|
+
*/
|
|
148
|
+
backgroundColor?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Theme mode: 'light' or 'dark'
|
|
151
|
+
*/
|
|
152
|
+
theme?: 'light' | 'dark';
|
|
153
|
+
/**
|
|
154
|
+
* Font size for chat text
|
|
155
|
+
*/
|
|
156
|
+
fontSize?: string;
|
|
157
|
+
/**
|
|
158
|
+
* Flow version to use
|
|
159
|
+
* @default 'default'
|
|
160
|
+
*/
|
|
161
|
+
flowVersion?: string;
|
|
162
|
+
/**
|
|
163
|
+
* Headers to pass to the flow
|
|
164
|
+
*/
|
|
165
|
+
flowHeaders?: Record<string, any>;
|
|
166
|
+
/**
|
|
167
|
+
* URL for user chat icon/image
|
|
168
|
+
*/
|
|
169
|
+
userImage?: string;
|
|
170
|
+
/**
|
|
171
|
+
* URL for widget icon (chat button)
|
|
172
|
+
*/
|
|
173
|
+
widgetImage?: string;
|
|
174
|
+
/**
|
|
175
|
+
* URL for bot/agent icon/image
|
|
176
|
+
*/
|
|
177
|
+
botImage?: string;
|
|
178
|
+
/**
|
|
179
|
+
* URL for voice icon
|
|
180
|
+
*/
|
|
181
|
+
voiceIcon?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Start a new session instead of resuming
|
|
184
|
+
* @default false
|
|
185
|
+
*/
|
|
186
|
+
newSession?: boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Specific session ID to use
|
|
189
|
+
*/
|
|
190
|
+
sessionId?: string;
|
|
191
|
+
/**
|
|
192
|
+
* Allow microphone access in iframe
|
|
193
|
+
* @default false
|
|
194
|
+
*/
|
|
195
|
+
allowMicrophone?: boolean;
|
|
196
|
+
/**
|
|
197
|
+
* Base URL for the chat embed iframe
|
|
198
|
+
* @default 'https://embed.botdojo.com'
|
|
199
|
+
*/
|
|
200
|
+
baseUrl?: string;
|
|
201
|
+
/**
|
|
202
|
+
* Model context definition(s) with tools and resources
|
|
203
|
+
* Can be a single ModelContext or an array of ModelContext objects
|
|
204
|
+
* Tools should include `execute` functions directly in their definitions
|
|
205
|
+
*/
|
|
206
|
+
modelContext?: ModelContext | ModelContext[];
|
|
207
|
+
/**
|
|
208
|
+
* Called when chat iframe loads
|
|
209
|
+
*/
|
|
210
|
+
onLoad?: () => void;
|
|
211
|
+
/**
|
|
212
|
+
* Called when chat is opened (for popup/side-panel modes)
|
|
213
|
+
*/
|
|
214
|
+
onOpen?: () => void;
|
|
215
|
+
/**
|
|
216
|
+
* Called when chat is closed (for popup/side-panel modes)
|
|
217
|
+
*/
|
|
218
|
+
onClose?: () => void;
|
|
219
|
+
/**
|
|
220
|
+
* Called when connector initializes successfully (if using model context)
|
|
221
|
+
*/
|
|
222
|
+
onConnectorInit?: (connector: BotDojoConnector$1) => void;
|
|
223
|
+
/**
|
|
224
|
+
* Called when connector encounters an error (if using model context)
|
|
225
|
+
*/
|
|
226
|
+
onConnectorError?: (error: Error) => void;
|
|
227
|
+
/**
|
|
228
|
+
* Called with control methods for programmatically controlling the chat widget
|
|
229
|
+
* - openChat(): Opens the chat
|
|
230
|
+
* - closeChat(): Closes the chat
|
|
231
|
+
* - sendFlowRequest(body): Sends a flow request programmatically
|
|
232
|
+
*/
|
|
233
|
+
onBotDojoChatControl?: (control: BotDojoChatControl) => void;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* BotDojoChat - Single unified React component for embedding BotDojo chat
|
|
237
|
+
*
|
|
238
|
+
* This component provides a complete solution for embedding BotDojo chat with:
|
|
239
|
+
* - Multiple display modes (popup, side panel, inline)
|
|
240
|
+
* - Optional model context integration for tools and resources
|
|
241
|
+
* - Automatic connector lifecycle management
|
|
242
|
+
* - PostMessage-based communication (no WebSocket needed)
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* Basic usage (no tools):
|
|
246
|
+
* ```tsx
|
|
247
|
+
* <BotDojoChat
|
|
248
|
+
* apiKey="YOUR_API_KEY"
|
|
249
|
+
* mode="chat-popup"
|
|
250
|
+
* accentColor="#4a3ed4"
|
|
251
|
+
* />
|
|
252
|
+
* ```
|
|
253
|
+
*
|
|
254
|
+
* @example
|
|
255
|
+
* With model context and tools:
|
|
256
|
+
* ```tsx
|
|
257
|
+
* <BotDojoChat
|
|
258
|
+
* apiKey="YOUR_API_KEY"
|
|
259
|
+
* mode="chat-popup"
|
|
260
|
+
* modelContext={{
|
|
261
|
+
* name: 'myapp',
|
|
262
|
+
* description: 'My application',
|
|
263
|
+
* tools: {
|
|
264
|
+
* get_data: {
|
|
265
|
+
* description: 'Get data',
|
|
266
|
+
* parameters: { type: 'object', properties: {} },
|
|
267
|
+
* execute: async () => ({ data: 'Hello!' })
|
|
268
|
+
* }
|
|
269
|
+
* }
|
|
270
|
+
* }}
|
|
271
|
+
* />
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
declare const BotDojoChat: React$1.FC<BotDojoChatProps>;
|
|
275
|
+
|
|
276
|
+
interface BotDojoChatConfig {
|
|
277
|
+
apiKey: string;
|
|
278
|
+
mode: BotDojoChatDisplayMode;
|
|
279
|
+
popupOptions?: PopupOptions;
|
|
280
|
+
sidePanelOptions?: SidePanelOptions;
|
|
281
|
+
width?: string;
|
|
282
|
+
height?: string;
|
|
283
|
+
accentColor: string;
|
|
284
|
+
backgroundColor: string;
|
|
285
|
+
theme?: 'light' | 'dark';
|
|
286
|
+
fontSize?: string;
|
|
287
|
+
flowVersion: string;
|
|
288
|
+
flowHeaders?: Record<string, any>;
|
|
289
|
+
userImage?: string;
|
|
290
|
+
widgetImage?: string;
|
|
291
|
+
botImage?: string;
|
|
292
|
+
voiceIcon?: string;
|
|
293
|
+
newSession: boolean;
|
|
294
|
+
sessionId?: string;
|
|
295
|
+
allowMicrophone: boolean;
|
|
296
|
+
baseUrl?: string;
|
|
297
|
+
}
|
|
298
|
+
interface BotDojoChatConfiguratorProps {
|
|
299
|
+
initialConfig?: Partial<BotDojoChatConfig>;
|
|
300
|
+
onClose?: () => void;
|
|
301
|
+
onApply?: (config: BotDojoChatConfig) => void;
|
|
302
|
+
}
|
|
303
|
+
declare const BotDojoChatConfigurator: React$1.FC<BotDojoChatConfiguratorProps>;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Canvas types for inline canvas cards in chat widgets
|
|
307
|
+
*/
|
|
308
|
+
|
|
309
|
+
interface BotDojoConnector {
|
|
310
|
+
executeToolCall: (toolName: string, args: any) => Promise<any>;
|
|
311
|
+
run: (params: any) => Promise<any>;
|
|
312
|
+
init: () => Promise<void>;
|
|
313
|
+
close: () => void;
|
|
314
|
+
updateCanvasData: (canvasData: any) => Promise<any>;
|
|
315
|
+
[key: string]: any;
|
|
316
|
+
}
|
|
317
|
+
type CanvasEvent = 'canvas:ready' | 'canvas:update' | 'message' | 'token' | 'complete' | 'error' | 'tool:args_streaming' | 'tool:executing' | 'tool:complete' | 'tool:error';
|
|
318
|
+
interface UseBotDojoCanvasReturn {
|
|
319
|
+
/** Whether the canvas is ready */
|
|
320
|
+
isReady: boolean;
|
|
321
|
+
/** Error if any */
|
|
322
|
+
error: Error | null;
|
|
323
|
+
/** Canvas data for this card */
|
|
324
|
+
canvasData: any | null;
|
|
325
|
+
/** Tool execution info (for tool canvas templates) */
|
|
326
|
+
toolName?: string;
|
|
327
|
+
toolDisplayName?: string;
|
|
328
|
+
toolPhase?: "streaming_args" | "executing" | "complete" | "error";
|
|
329
|
+
toolStatus?: "processing" | "complete" | "error";
|
|
330
|
+
/** Argument streaming (pre-execution, only during streaming_args phase) */
|
|
331
|
+
partialArguments?: string;
|
|
332
|
+
parsedArguments?: any;
|
|
333
|
+
toolError?: string;
|
|
334
|
+
/** Send message in the chat (triggers flow) */
|
|
335
|
+
sendMessage: (text: string, params?: any) => Promise<any>;
|
|
336
|
+
/** Access to chat connector */
|
|
337
|
+
connector: BotDojoConnector | null;
|
|
338
|
+
/** Listen to events */
|
|
339
|
+
on: (event: CanvasEvent, handler: (data: any) => void) => () => void;
|
|
340
|
+
/** Whether in mock mode */
|
|
341
|
+
isMockMode: boolean;
|
|
342
|
+
}
|
|
343
|
+
interface BotDojoCanvasProviderProps {
|
|
344
|
+
children: React.ReactNode;
|
|
345
|
+
/** Canvas data for this card */
|
|
346
|
+
canvasData?: any;
|
|
347
|
+
/** Connector from parent chat widget */
|
|
348
|
+
connector?: BotDojoConnector;
|
|
349
|
+
/** Optional canvas tools (agent can call these) */
|
|
350
|
+
modelContext?: ModelContext$1 | ModelContext$1[];
|
|
351
|
+
/** Debug mode */
|
|
352
|
+
debug?: boolean;
|
|
353
|
+
}
|
|
354
|
+
interface MockCanvasProviderProps {
|
|
355
|
+
children: React.ReactNode;
|
|
356
|
+
/** Mock canvas data */
|
|
357
|
+
mockCanvasData?: any;
|
|
358
|
+
/** Mock message handler */
|
|
359
|
+
onSendMessage?: (text: string, params?: any) => Promise<any>;
|
|
360
|
+
/** Debug mode */
|
|
361
|
+
debug?: boolean;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Canvas provider for inline canvas cards in chat widgets
|
|
366
|
+
* Automatically handles postMessage communication when in iframe
|
|
367
|
+
*/
|
|
368
|
+
declare function BotDojoCanvasProvider({ children, canvasData: initialCanvasData, connector: externalConnector, modelContext, debug }: BotDojoCanvasProviderProps): react_jsx_runtime.JSX.Element;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Mock canvas provider for testing canvas cards standalone
|
|
372
|
+
* - No connector needed
|
|
373
|
+
* - Simulates runtime with callbacks
|
|
374
|
+
* - Perfect for development and testing
|
|
375
|
+
*/
|
|
376
|
+
declare function MockCanvasProvider({ children, mockCanvasData, onSendMessage, debug }: MockCanvasProviderProps): react_jsx_runtime.JSX.Element;
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Hook to access canvas runtime
|
|
380
|
+
* Works with both BotDojoCanvasProvider and MockCanvasProvider
|
|
381
|
+
*/
|
|
382
|
+
declare function useBotDojoCanvas(): UseBotDojoCanvasReturn;
|
|
383
|
+
|
|
384
|
+
export { BotDojoCanvasProvider, type BotDojoCanvasProviderProps, BotDojoChat, type BotDojoChatConfig, BotDojoChatConfigurator, type BotDojoChatConfiguratorProps, type BotDojoChatControl, type BotDojoChatDisplayMode, type BotDojoChatProps, type CanvasEvent, MockCanvasProvider, type MockCanvasProviderProps, type PopupOptions, type SidePanelOptions, type UseBotDojoCanvasReturn, useBotDojoCanvas };
|