@botzki/react 0.0.0-stage → 0.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 +188 -2
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +409 -0
- package/dist/index.d.ts +409 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +67 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default from 'react';
|
|
3
|
+
import { Citation, ChatResponse, Botzki, BotzkiUser, WidgetOptions } from '@botzki/js';
|
|
4
|
+
export { BotzkiConfig, BotzkiUser, ChatOptions, ChatResponse, Citation, WidgetOptions } from '@botzki/js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Message representation inside React chat interfaces.
|
|
8
|
+
*/
|
|
9
|
+
interface BotzkiMessage {
|
|
10
|
+
id: string;
|
|
11
|
+
role: "user" | "assistant" | "system";
|
|
12
|
+
content: string;
|
|
13
|
+
createdAt: Date;
|
|
14
|
+
citations?: Citation[];
|
|
15
|
+
isStreaming?: boolean;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Configuration options for the `useChat` hook.
|
|
20
|
+
*/
|
|
21
|
+
interface UseChatOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Target bot identifier. Inherited from `<BotzkiProvider>` if omitted.
|
|
24
|
+
*/
|
|
25
|
+
botId?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Publishable API key. Inherited from `<BotzkiProvider>` if omitted.
|
|
28
|
+
*/
|
|
29
|
+
publishableKey?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Custom backend API base URL (e.g. for local development or custom proxy).
|
|
32
|
+
*/
|
|
33
|
+
baseUrl?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Alias for `baseUrl`.
|
|
36
|
+
*/
|
|
37
|
+
apiHost?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Unique session identifier. Auto-generated and persisted if omitted.
|
|
40
|
+
*/
|
|
41
|
+
sessionId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Initial messages to preload into the conversation.
|
|
44
|
+
*/
|
|
45
|
+
initialMessages?: BotzkiMessage[];
|
|
46
|
+
/**
|
|
47
|
+
* Whether to persist the conversation and session in browser localStorage.
|
|
48
|
+
* @default true
|
|
49
|
+
*/
|
|
50
|
+
persistSession?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Custom localStorage key prefix for session and message caching.
|
|
53
|
+
*/
|
|
54
|
+
storageKey?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Preferred ISO 639-1 language code (e.g. 'en', 'es', 'de').
|
|
57
|
+
*/
|
|
58
|
+
language?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Whether to stream answers in real-time token-by-token.
|
|
61
|
+
* @default true
|
|
62
|
+
*/
|
|
63
|
+
stream?: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* Callback fired whenever a full response is received from the bot.
|
|
66
|
+
*/
|
|
67
|
+
onResponse?: (response: ChatResponse) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Callback fired when a message turn finishes (streaming completed).
|
|
70
|
+
*/
|
|
71
|
+
onFinish?: (message: BotzkiMessage) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Callback fired when an error occurs during message transmission.
|
|
74
|
+
*/
|
|
75
|
+
onError?: (error: Error) => void;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Return type and state of the `useChat` hook.
|
|
79
|
+
*/
|
|
80
|
+
interface UseChatReturn {
|
|
81
|
+
/**
|
|
82
|
+
* Array of conversation messages in chronological order.
|
|
83
|
+
*/
|
|
84
|
+
messages: BotzkiMessage[];
|
|
85
|
+
/**
|
|
86
|
+
* Current text in the input box.
|
|
87
|
+
*/
|
|
88
|
+
input: string;
|
|
89
|
+
/**
|
|
90
|
+
* Sets input box value manually.
|
|
91
|
+
*/
|
|
92
|
+
setInput: (value: string) => void;
|
|
93
|
+
/**
|
|
94
|
+
* Standard React onChange handler for input and textarea elements.
|
|
95
|
+
*/
|
|
96
|
+
handleInputChange: (e: React__default.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
97
|
+
/**
|
|
98
|
+
* Form submission handler. Submits current `input` and clears the input box.
|
|
99
|
+
*/
|
|
100
|
+
handleSubmit: (e?: React__default.FormEvent, options?: {
|
|
101
|
+
imageBase64?: string;
|
|
102
|
+
imageMimeType?: string;
|
|
103
|
+
}) => Promise<void>;
|
|
104
|
+
/**
|
|
105
|
+
* Programmatically sends a message with optional image attachment.
|
|
106
|
+
*/
|
|
107
|
+
sendMessage: (content: string, options?: {
|
|
108
|
+
imageBase64?: string;
|
|
109
|
+
imageMimeType?: string;
|
|
110
|
+
}) => Promise<void>;
|
|
111
|
+
/**
|
|
112
|
+
* Appends a message to the conversation history without triggering an API call.
|
|
113
|
+
*/
|
|
114
|
+
append: (message: Partial<BotzkiMessage> & {
|
|
115
|
+
content: string;
|
|
116
|
+
}) => void;
|
|
117
|
+
/**
|
|
118
|
+
* Re-sends the last user message to regenerate the assistant response.
|
|
119
|
+
*/
|
|
120
|
+
reload: () => Promise<void>;
|
|
121
|
+
/**
|
|
122
|
+
* Aborts the active streaming generation immediately.
|
|
123
|
+
*/
|
|
124
|
+
stop: () => void;
|
|
125
|
+
/**
|
|
126
|
+
* Clears the current conversation history.
|
|
127
|
+
*/
|
|
128
|
+
clearMessages: () => void;
|
|
129
|
+
/**
|
|
130
|
+
* Direct state setter for messages array.
|
|
131
|
+
*/
|
|
132
|
+
setMessages: React__default.Dispatch<React__default.SetStateAction<BotzkiMessage[]>>;
|
|
133
|
+
/**
|
|
134
|
+
* True if waiting for a response or streaming tokens.
|
|
135
|
+
*/
|
|
136
|
+
isLoading: boolean;
|
|
137
|
+
/**
|
|
138
|
+
* True specifically when tokens are actively streaming in.
|
|
139
|
+
*/
|
|
140
|
+
isStreaming: boolean;
|
|
141
|
+
/**
|
|
142
|
+
* Error object if the last operation failed, or null.
|
|
143
|
+
*/
|
|
144
|
+
error: Error | null;
|
|
145
|
+
/**
|
|
146
|
+
* Active conversation session identifier.
|
|
147
|
+
*/
|
|
148
|
+
sessionId: string;
|
|
149
|
+
/**
|
|
150
|
+
* Sets or updates active conversation session identifier.
|
|
151
|
+
*/
|
|
152
|
+
setSessionId: (id: string) => void;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Properties for `<BotzkiProvider>`.
|
|
156
|
+
*/
|
|
157
|
+
interface BotzkiProviderProps {
|
|
158
|
+
/**
|
|
159
|
+
* Target bot identifier.
|
|
160
|
+
*/
|
|
161
|
+
botId: string;
|
|
162
|
+
/**
|
|
163
|
+
* Publishable API key (`botz_pk_live_...`). Safe to expose in frontend bundles.
|
|
164
|
+
*/
|
|
165
|
+
publishableKey: string;
|
|
166
|
+
/**
|
|
167
|
+
* Optional custom backend API base URL (defaults to https://api.botzki.com).
|
|
168
|
+
*/
|
|
169
|
+
baseUrl?: string;
|
|
170
|
+
/**
|
|
171
|
+
* Alias for `baseUrl`.
|
|
172
|
+
*/
|
|
173
|
+
apiHost?: string;
|
|
174
|
+
/**
|
|
175
|
+
* Optional visitor user details to identify customer sessions.
|
|
176
|
+
*/
|
|
177
|
+
user?: BotzkiUser;
|
|
178
|
+
/**
|
|
179
|
+
* Optional persistent session ID. Auto-generated if omitted.
|
|
180
|
+
*/
|
|
181
|
+
defaultSessionId?: string;
|
|
182
|
+
/**
|
|
183
|
+
* Optional pre-instantiated Botzki client instance.
|
|
184
|
+
*/
|
|
185
|
+
client?: Botzki;
|
|
186
|
+
/**
|
|
187
|
+
* React tree to wrap with Botzki context.
|
|
188
|
+
*/
|
|
189
|
+
children: React__default.ReactNode;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Value exposed by the Botzki React Context.
|
|
193
|
+
*/
|
|
194
|
+
interface BotzkiContextValue {
|
|
195
|
+
client: Botzki;
|
|
196
|
+
botId: string;
|
|
197
|
+
publishableKey: string;
|
|
198
|
+
baseUrl: string;
|
|
199
|
+
apiHost: string;
|
|
200
|
+
user?: BotzkiUser;
|
|
201
|
+
sessionId: string;
|
|
202
|
+
setSessionId: (id: string) => void;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Imperative handle exposed via React ref for `<BotzkiWidget />`.
|
|
206
|
+
*/
|
|
207
|
+
interface BotzkiWidgetRef {
|
|
208
|
+
/** Opens the floating chat popup */
|
|
209
|
+
open: () => void;
|
|
210
|
+
/** Closes the floating chat popup */
|
|
211
|
+
close: () => void;
|
|
212
|
+
/** Toggles open / close state */
|
|
213
|
+
toggle: () => void;
|
|
214
|
+
/** Returns true if the chat popup is currently open */
|
|
215
|
+
isOpen: () => boolean;
|
|
216
|
+
/** Shows the floating launcher bubble */
|
|
217
|
+
show: () => void;
|
|
218
|
+
/** Hides the floating launcher bubble */
|
|
219
|
+
hide: () => void;
|
|
220
|
+
/** Sends a message programmatically through the widget */
|
|
221
|
+
sendMessage: (message: string, imageBase64?: string) => Promise<void>;
|
|
222
|
+
/** Clears widget chat history */
|
|
223
|
+
clearMessages: () => void;
|
|
224
|
+
/** Dynamically updates widget theme */
|
|
225
|
+
setTheme: (theme: "light" | "dark" | "auto") => void;
|
|
226
|
+
/** Dynamically updates widget primary accent color */
|
|
227
|
+
setPrimaryColor: (color: string) => void;
|
|
228
|
+
/** Updates identified visitor details */
|
|
229
|
+
setUser: (user: BotzkiUser) => void;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Props for `<BotzkiWidget />`.
|
|
233
|
+
*/
|
|
234
|
+
interface BotzkiWidgetProps extends WidgetOptions {
|
|
235
|
+
/**
|
|
236
|
+
* Optional bot ID. If omitted, uses value from `<BotzkiProvider>`.
|
|
237
|
+
*/
|
|
238
|
+
botId?: string;
|
|
239
|
+
/**
|
|
240
|
+
* Optional publishable key. If omitted, uses value from `<BotzkiProvider>`.
|
|
241
|
+
*/
|
|
242
|
+
publishableKey?: string;
|
|
243
|
+
/**
|
|
244
|
+
* Optional custom base URL.
|
|
245
|
+
*/
|
|
246
|
+
baseUrl?: string;
|
|
247
|
+
/**
|
|
248
|
+
* Optional visitor details.
|
|
249
|
+
*/
|
|
250
|
+
user?: BotzkiUser;
|
|
251
|
+
/**
|
|
252
|
+
* Callback fired when the widget chat window opens.
|
|
253
|
+
*/
|
|
254
|
+
onOpen?: () => void;
|
|
255
|
+
/**
|
|
256
|
+
* Callback fired when the widget chat window closes.
|
|
257
|
+
*/
|
|
258
|
+
onClose?: () => void;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Root context provider for Botzki AI. Wraps your React component tree and shares
|
|
263
|
+
* client instances and configuration with all child hooks and components.
|
|
264
|
+
*/
|
|
265
|
+
declare function BotzkiProvider({ botId, publishableKey, baseUrl, apiHost, user, defaultSessionId, client: customClient, children, }: BotzkiProviderProps): React.JSX.Element;
|
|
266
|
+
/**
|
|
267
|
+
* Hook to access the current Botzki context value (client instance, botId, sessionId).
|
|
268
|
+
* Throws a helpful error if used outside a `<BotzkiProvider>`.
|
|
269
|
+
*/
|
|
270
|
+
declare function useBotzki(): BotzkiContextValue;
|
|
271
|
+
/**
|
|
272
|
+
* Optional hook to access the Botzki context, returning null instead of throwing
|
|
273
|
+
* if called outside `<BotzkiProvider>`. Useful for components that can be used standalone.
|
|
274
|
+
*/
|
|
275
|
+
declare function useOptionalBotzki(): BotzkiContextValue | null;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Drop-in floating chat widget component for React.
|
|
279
|
+
* Handles automatic lifecycle management, React StrictMode safety, dynamic theme/color updates,
|
|
280
|
+
* and imperative control via forwarded ref.
|
|
281
|
+
*/
|
|
282
|
+
declare const BotzkiWidget: React.ForwardRefExoticComponent<BotzkiWidgetProps & React.RefAttributes<BotzkiWidgetRef>>;
|
|
283
|
+
|
|
284
|
+
interface BotzkiChatProps extends UseChatOptions {
|
|
285
|
+
/**
|
|
286
|
+
* Title shown in the chat window header. Defaults to bot name or "AI Assistant".
|
|
287
|
+
*/
|
|
288
|
+
title?: string;
|
|
289
|
+
/**
|
|
290
|
+
* Subtitle shown in the chat window header. Defaults to "Online".
|
|
291
|
+
*/
|
|
292
|
+
subtitle?: string;
|
|
293
|
+
/**
|
|
294
|
+
* Welcome greeting when conversation starts.
|
|
295
|
+
*/
|
|
296
|
+
greeting?: string;
|
|
297
|
+
/**
|
|
298
|
+
* List of clickable starter prompt questions.
|
|
299
|
+
*/
|
|
300
|
+
starterQuestions?: string[];
|
|
301
|
+
/**
|
|
302
|
+
* Visual theme ("light" | "dark" | "auto"). Defaults to "auto".
|
|
303
|
+
*/
|
|
304
|
+
theme?: "light" | "dark" | "auto";
|
|
305
|
+
/**
|
|
306
|
+
* Primary accent color (hex or rgb). Defaults to "#0ea5e9".
|
|
307
|
+
*/
|
|
308
|
+
primaryColor?: string;
|
|
309
|
+
/**
|
|
310
|
+
* Custom CSS class name for the outer container.
|
|
311
|
+
*/
|
|
312
|
+
className?: string;
|
|
313
|
+
/**
|
|
314
|
+
* Custom style object for the outer container.
|
|
315
|
+
*/
|
|
316
|
+
style?: React__default.CSSProperties;
|
|
317
|
+
/**
|
|
318
|
+
* Placeholder text for the message input.
|
|
319
|
+
*/
|
|
320
|
+
placeholder?: string;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Embedded, full-featured AI chat container for dashboards, sidebars, and dedicated support pages.
|
|
324
|
+
* Fully responsive and self-contained with no external CSS dependencies.
|
|
325
|
+
*/
|
|
326
|
+
declare function BotzkiChat({ title, subtitle, greeting, starterQuestions, theme, primaryColor, className, style, placeholder, ...chatOptions }: BotzkiChatProps): React__default.JSX.Element;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Headless React hook for building rich, interactive AI chat interfaces with real-time streaming,
|
|
330
|
+
* session persistence, optimistic UI updates, error recovery, and multimodal support.
|
|
331
|
+
*/
|
|
332
|
+
declare function useChat(options?: UseChatOptions): UseChatReturn;
|
|
333
|
+
|
|
334
|
+
interface BotInfoData {
|
|
335
|
+
id?: string;
|
|
336
|
+
name?: string;
|
|
337
|
+
description?: string;
|
|
338
|
+
primaryColor?: string;
|
|
339
|
+
theme?: string;
|
|
340
|
+
avatarUrl?: string;
|
|
341
|
+
greeting?: string;
|
|
342
|
+
starterQuestions?: string[];
|
|
343
|
+
capabilities?: string[];
|
|
344
|
+
[key: string]: unknown;
|
|
345
|
+
}
|
|
346
|
+
interface UseBotInfoReturn {
|
|
347
|
+
data: BotInfoData | null;
|
|
348
|
+
isLoading: boolean;
|
|
349
|
+
error: Error | null;
|
|
350
|
+
refetch: () => Promise<void>;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Hook to retrieve public bot configuration, branding, avatar, and starter questions.
|
|
354
|
+
*/
|
|
355
|
+
declare function useBotInfo(): UseBotInfoReturn;
|
|
356
|
+
|
|
357
|
+
interface FeedbackPayload {
|
|
358
|
+
messageId?: string;
|
|
359
|
+
query?: string;
|
|
360
|
+
rating: number;
|
|
361
|
+
comment?: string;
|
|
362
|
+
category?: string;
|
|
363
|
+
}
|
|
364
|
+
interface UseFeedbackReturn {
|
|
365
|
+
submitFeedback: (payload: FeedbackPayload) => Promise<boolean>;
|
|
366
|
+
isSubmitting: boolean;
|
|
367
|
+
isSuccess: boolean;
|
|
368
|
+
error: Error | null;
|
|
369
|
+
reset: () => void;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Hook to submit visitor ratings and feedback on bot answers.
|
|
373
|
+
*/
|
|
374
|
+
declare function useFeedback(): UseFeedbackReturn;
|
|
375
|
+
|
|
376
|
+
interface LeadCapturePayload {
|
|
377
|
+
email: string;
|
|
378
|
+
name?: string;
|
|
379
|
+
phone?: string;
|
|
380
|
+
company?: string;
|
|
381
|
+
notes?: string;
|
|
382
|
+
metadata?: Record<string, unknown>;
|
|
383
|
+
customData?: Record<string, unknown>;
|
|
384
|
+
}
|
|
385
|
+
interface UseLeadCaptureReturn {
|
|
386
|
+
captureLead: (payload: LeadCapturePayload) => Promise<boolean>;
|
|
387
|
+
isSubmitting: boolean;
|
|
388
|
+
isSuccess: boolean;
|
|
389
|
+
error: Error | null;
|
|
390
|
+
reset: () => void;
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Hook to capture customer lead contact details directly from custom React forms or chat widgets.
|
|
394
|
+
*/
|
|
395
|
+
declare function useLeadCapture(): UseLeadCaptureReturn;
|
|
396
|
+
|
|
397
|
+
interface UseVoiceTranscriptionReturn {
|
|
398
|
+
transcribe: (audio: Blob | File) => Promise<string | null>;
|
|
399
|
+
isTranscribing: boolean;
|
|
400
|
+
transcript: string | null;
|
|
401
|
+
error: Error | null;
|
|
402
|
+
reset: () => void;
|
|
403
|
+
}
|
|
404
|
+
/**
|
|
405
|
+
* Hook to transcribe audio recordings directly to text using the Botzki AI audio transcription endpoint.
|
|
406
|
+
*/
|
|
407
|
+
declare function useVoiceTranscription(): UseVoiceTranscriptionReturn;
|
|
408
|
+
|
|
409
|
+
export { type BotInfoData, BotzkiChat, type BotzkiChatProps, type BotzkiContextValue, type BotzkiMessage, BotzkiProvider, type BotzkiProviderProps, BotzkiWidget, type BotzkiWidgetProps, type BotzkiWidgetRef, type FeedbackPayload, type LeadCapturePayload, type UseBotInfoReturn, type UseChatOptions, type UseChatReturn, type UseFeedbackReturn, type UseLeadCaptureReturn, type UseVoiceTranscriptionReturn, useBotInfo, useBotzki, useChat, useFeedback, useLeadCapture, useOptionalBotzki, useVoiceTranscription };
|