@botzki/react 0.1.2 → 0.1.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # @botzki/react
2
2
 
3
- Official React SDK for [Botzki](https://botzki.com) autonomous AI agents, floating widgets, and headless streaming chat interfaces.
3
+ Official React SDK for [Botzki](https://botzki.com) autonomous AI agents, floating widgets, live human handoff, zero-install Ghost Co-Browsing, 2-step autonomous actions, and headless streaming chat interfaces.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/@botzki/react.svg)](https://www.npmjs.com/package/@botzki/react)
6
6
  [![license](https://img.shields.io/npm/l/@botzki/react.svg)](https://github.com/botzki/botzki-react/blob/main/LICENSE)
@@ -10,11 +10,15 @@ Official React SDK for [Botzki](https://botzki.com) autonomous AI agents, floati
10
10
  ## Features
11
11
 
12
12
  - ⚛️ **Idiomatic React 18 & 19**: Full support for React Strict Mode, Server Components (`"use client"`), and SSR frameworks (Next.js App Router, Remix, Vite).
13
- - 🚀 **1-Line Floating Widget**: Drop-in `<BotzkiWidget />` with full reactivity to theme and primary color changes.
14
- - 💬 **Embedded Chat Component**: Turnkey `<BotzkiChat />` ready to plug into sidebars, dashboards, or support pages without external CSS.
15
- - 🪝 **Headless `useChat()` Hook**: Full control over UI rendering with real-time SSE token streaming, optimistic updates, session persistence in `localStorage`, and regenerate (`reload()`) capabilities.
16
- - 🛠️ **Full Specialized Hooks**: `useBotInfo()`, `useFeedback()`, `useLeadCapture()`, `useVoiceTranscription()`.
17
- - 🛡️ **TypeScript First**: Complete typings for all components, hooks, options, and returns.
13
+ - 🚀 **1-Line Floating Widget (`<BotzkiWidget />`)**: Drop-in floating launcher and modal with portal rendering, proactive triggers, unread badges, and full imperative `ref` control.
14
+ - 💬 **Embedded Chat Container (`<BotzkiChat />`)**: Turnkey embedded chat ready for sidebars, dashboards, or dedicated support pages with zero external CSS required.
15
+ - 🪝 **Headless `useChat()` Hook**: Complete control over UI rendering with real-time SSE token streaming, optimistic updates, `localStorage` session persistence, human handoff, and autonomous action execution.
16
+ - 🎧 **Live Human Handoff & Visitor 360**: Seamless escalation to human operators in the Botzki Shared Inbox with real-time typing previews, custom CRM attributes (`visitorData`), conversation tags (`tags`), and post-resolution 5-star CSAT ratings.
17
+ - 🖥️ **Zero-Install Ghost Co-Browsing (`useCoBrowse`)**: Built-in live screen assistance with interactive SVG laser pointer (`<CoBrowseLaserPointer />`), remote viewport scroll guidance, explicit visitor consent, and strict `.botzki-mask` PII input masking.
18
+ - ⚡ **Autonomous 2-Step Action Cards**: Cryptographically signed (`HMAC-SHA256`) action proposals allowing visitors to confirm or cancel webhooks and client events right inside the chat stream.
19
+ - 🎙️ **Crisp/WhatsApp-Style Voice Messages**: Live voice note recording with animated equalizers and interactive `<BotzkiAudioPlayer />` waveform scrubber with speed controls (`1x`, `1.5x`, `2x`).
20
+ - 🔔 **Synthesized Web Audio Chimes & Tab-Title Alerts**: Native Web Audio API harmonic chime (zero external audio files) and background tab title flashing when new support messages arrive.
21
+ - 🛠️ **7 Specialized Hooks**: `useChat()`, `useBotInfo()`, `useFeedback()`, `useLeadCapture()`, `useVoiceTranscription()`, `useCoBrowse()`, and `useEmpathyEngine()`.
18
22
 
19
23
  ---
20
24
 
@@ -46,7 +50,12 @@ export function Providers({ children }: { children: React.ReactNode }) {
46
50
  return (
47
51
  <BotzkiProvider
48
52
  botId="YOUR_BOT_ID"
49
- publishableKey="YOUR_PUBLISHABLE_KEY"
53
+ publishableKey="botz_pk_live_..."
54
+ user={{
55
+ id: "usr_123",
56
+ name: "Sarah Jenkins",
57
+ email: "sarah@example.com",
58
+ }}
50
59
  >
51
60
  {children}
52
61
  </BotzkiProvider>
@@ -54,7 +63,7 @@ export function Providers({ children }: { children: React.ReactNode }) {
54
63
  }
55
64
  ```
56
65
 
57
- ### 2. Drop in the Floating Widget
66
+ ### 2. Drop in `<BotzkiWidget />` with Full Customization
58
67
 
59
68
  ```tsx
60
69
  import { BotzkiWidget } from "@botzki/react";
@@ -67,7 +76,38 @@ export function App() {
67
76
  theme="auto"
68
77
  primaryColor="#0ea5e9"
69
78
  widgetTitle="Support AI"
79
+ widgetSubtitle="Typically replies in seconds"
70
80
  greeting="Hi there! How can I help you today?"
81
+ starterPrompts={[
82
+ "How do I upgrade my plan?",
83
+ "Can I get a copy of my invoice?",
84
+ "Talk to a support specialist",
85
+ ]}
86
+ // Visitor 360 CRM Metadata & Segments
87
+ visitorData={{ plan: "Enterprise", mrr: "$499" }}
88
+ tags={["vip", "dashboard"]}
89
+ // Feature Toggles (All enabled by default, customizable per page)
90
+ enableImageUpload={true}
91
+ enableVoiceInput={true}
92
+ enableVoiceOutput={true}
93
+ enableVoiceNotes={true}
94
+ enableHumanHandoff={true}
95
+ enableCoBrowse={true}
96
+ enableActionEngine={true}
97
+ enableTriggers={true}
98
+ enableSoundAlert={true}
99
+ enableTabTitleNotification={true}
100
+ enableHotkey={true}
101
+ enableEmpathyEngine={true}
102
+ showAvatars={true}
103
+ showFeedback={true}
104
+ showCitations={true}
105
+ showCopyButton={true}
106
+ showExportButton={true}
107
+ showNewChatButton={true}
108
+ showHistoryButton={true}
109
+ showBranding={true}
110
+ allowExpand={true}
71
111
  />
72
112
  </div>
73
113
  );
@@ -76,114 +116,133 @@ export function App() {
76
116
 
77
117
  ---
78
118
 
79
- ## Headless Streaming with `useChat()`
119
+ ## Complete Feature Toggles Reference (`<BotzkiWidget />` & `<BotzkiChat />`)
120
+
121
+ Every capability can be individually enabled or disabled via boolean props:
122
+
123
+ | Prop | Type | Default | Description |
124
+ | :--- | :--- | :---: | :--- |
125
+ | `defaultOpen` | `boolean` | `false` | Opens the floating chat window automatically on mount. |
126
+ | `defaultExpanded` | `boolean` | `false` | Starts the floating chat window in maximized mode. |
127
+ | `allowExpand` | `boolean` | `true` | Shows the expand/collapse window maximize toggle in the header. |
128
+ | `enableImageUpload` | `boolean` | `true` | Enables image, screenshot, PDF, and document attachments in the composer. |
129
+ | `enableVoiceInput` | `boolean` | `true` | Enables microphone speech-to-text dictation. |
130
+ | `enableVoiceNotes` | `boolean` | `true` | Enables Crisp/WhatsApp-style audio voice note recording. |
131
+ | `enableVoiceOutput` | `boolean` | `true` | Enables text-to-speech read-aloud button on assistant messages. |
132
+ | `enableHumanHandoff` | `boolean` | `true` | Shows the "Talk to Support" human escalation button in the header. |
133
+ | `enableCoBrowse` | `boolean` | `true` | Enables Zero-Install Ghost Co-Browsing screen assistance during live chat. |
134
+ | `enableActionEngine` | `boolean` | `true` | Renders 2-step confirmation cards for autonomous AI actions. |
135
+ | `enableTriggers` | `boolean` | `true` | Evaluates proactive triggers (time-on-page, scroll depth, exit-intent). |
136
+ | `enableSoundAlert` | `boolean` | `true` | Plays a subtle synthesized Web Audio chime on incoming messages. |
137
+ | `enableTabTitleNotification` | `boolean` | `true` | Flashes the browser tab title when new messages arrive while backgrounded. |
138
+ | `enableHotkey` | `boolean` | `true` | Enables `Cmd+K` / `Ctrl+K` to toggle widget and `Escape` to close. |
139
+ | `enableEmpathyEngine` | `boolean` | `true` | Dynamically syncs avatar expressions and micro-motions with visitor sentiment. |
140
+ | `showAvatars` | `boolean` | `true` | Renders bot, operator, and user avatars beside message bubbles. |
141
+ | `showFeedback` | `boolean` | `true` | Shows thumbs-up / thumbs-down feedback buttons on assistant answers. |
142
+ | `showCitations` | `boolean` | `true` | Displays grounded document citation pills beneath answers. |
143
+ | `showCopyButton` | `boolean` | `true` | Displays 1-click copy button on assistant answers. |
144
+ | `showExportButton` | `boolean` | `true` | Displays 1-click Download Chat Transcript button in the header. |
145
+ | `showNewChatButton` | `boolean` | `true` | Displays the `+ New` session button in the header. |
146
+ | `showHistoryButton` | `boolean` | `true` | Displays the multi-session chat history drawer button in the header. |
147
+ | `showClearButton` | `boolean` | `false` | Displays a Clear button in the header. |
148
+ | `showCloseButton` | `boolean` | `true` | Displays the close (`✕`) button in the widget header. |
149
+ | `showBranding` | `boolean` | `true` | Displays "Powered by Botzki" in the footer. |
150
+ | `persistSession` | `boolean` | `false` | Persists chat messages and session history in `localStorage`. |
80
151
 
81
- Build custom, completely unstyled AI chat interfaces with real-time streaming:
152
+ ---
82
153
 
83
- ```tsx
84
- "use client";
154
+ ## Lifecycle & Event Callbacks Reference
85
155
 
86
- import { useChat } from "@botzki/react";
87
-
88
- export function CustomChat() {
89
- const {
90
- messages,
91
- input,
92
- handleInputChange,
93
- handleSubmit,
94
- isLoading,
95
- isStreaming,
96
- stop,
97
- reload,
98
- clearMessages,
99
- } = useChat();
156
+ Subscribe to every user interaction, AI generation, human escalation, and autonomous action event:
100
157
 
101
- return (
102
- <div className="chat-container">
103
- <div className="messages">
104
- {messages.map((m) => (
105
- <div key={m.id} className={`message ${m.role}`}>
106
- <strong>{m.role === "user" ? "You" : "AI"}:</strong> {m.content}
107
- {m.citations && (
108
- <div className="citations">
109
- {m.citations.map((c, i) => (
110
- <span key={i}>[{c.source}]</span>
111
- ))}
112
- </div>
113
- )}
114
- </div>
115
- ))}
116
- {isLoading && !isStreaming && <p>Thinking...</p>}
117
- </div>
118
-
119
- <form onSubmit={handleSubmit}>
120
- <input
121
- value={input}
122
- onChange={handleInputChange}
123
- placeholder="Ask a question..."
124
- />
125
- <button type="submit" disabled={isLoading}>Send</button>
126
- {isStreaming && <button type="button" onClick={stop}>Stop</button>}
127
- </form>
128
- </div>
129
- );
130
- }
158
+ ```tsx
159
+ <BotzkiWidget
160
+ onOpen={() => console.log("Widget opened")}
161
+ onClose={() => console.log("Widget closed")}
162
+ onExpandChange={(isExpanded) => console.log("Expanded:", isExpanded)}
163
+ onNewChat={() => console.log("Started new chat session")}
164
+ onUnreadCountChange={(count) => console.log("Unread messages:", count)}
165
+ onSendMessage={(msg) => console.log("Visitor sent:", msg.content)}
166
+ onResponse={(res) => console.log("Received response metadata:", res)}
167
+ onFinish={(msg) => console.log("Streaming completed:", msg)}
168
+ onError={(err) => console.error("Chat error:", err)}
169
+ onEscalationRequest={(details) => console.log("Escalated to human:", details)}
170
+ onOperatorJoined={(operator) => console.log("Operator joined:", operator.name)}
171
+ onTicketResolved={(ticketId) => console.log("Ticket resolved:", ticketId)}
172
+ onCsatSubmit={(rating, feedback) => console.log("CSAT submitted:", rating, feedback)}
173
+ onActionProposed={(action) => console.log("Action proposed:", action.actionName)}
174
+ onActionExecuted={(action, result) => console.log("Action executed:", action.actionName, result)}
175
+ onActionCancelled={(action, reason) => console.log("Action cancelled:", reason)}
176
+ onCoBrowseStart={(operatorName) => console.log("Co-browsing started with:", operatorName)}
177
+ onCoBrowseEnd={() => console.log("Co-browsing ended")}
178
+ onFeedbackSubmit={(messageId, rating) => console.log("Message rated:", messageId, rating)}
179
+ onTriggerActivated={(trigger) => console.log("Proactive trigger fired:", trigger.name)}
180
+ />
131
181
  ```
132
182
 
133
183
  ---
134
184
 
135
- ## Embedded Chat Container (`<BotzkiChat />`)
185
+ ## Imperative Control via `ref` (`BotzkiWidgetRef`)
186
+
187
+ Control `<BotzkiWidget ref={widgetRef} />` programmatically from anywhere in your application:
188
+
189
+ | Method | Signature | Description |
190
+ | :--- | :--- | :--- |
191
+ | `open()` | `() => void` | Opens the floating chat window and marks messages as read. |
192
+ | `close()` | `() => void` | Closes the floating chat window. |
193
+ | `toggle()` | `() => void` | Toggles open/close state. |
194
+ | `isOpen()` | `() => boolean` | Returns `true` if the chat window is currently open. |
195
+ | `show()` | `() => void` | Shows the floating launcher button. |
196
+ | `hide()` | `() => void` | Hides the floating launcher button and closes the modal. |
197
+ | `expand()` | `() => void` | Maximizes the widget window. |
198
+ | `collapse()` | `() => void` | Restores the widget window to compact dimensions. |
199
+ | `isExpanded()` | `() => boolean` | Returns `true` if currently maximized. |
200
+ | `sendMessage(msg, img?)` | `(msg: string, img?: string) => Promise<void>` | Opens the widget and sends a message programmatically. |
201
+ | `clearMessages()` | `() => void` | Clears the current conversation messages. |
202
+ | `newChat()` | `() => void` | Resets conversation and generates a fresh session ID. |
203
+ | `openHistory()` | `() => void` | Opens the widget and displays the multi-session history drawer. |
204
+ | `closeHistory()` | `() => void` | Closes the multi-session history drawer. |
205
+ | `exportChat(format?)` | `(format?: "markdown" \| "json") => string` | Returns the formatted conversation transcript. |
206
+ | `requestHumanHandoff(...)` | `(reason?, name?, email?) => Promise<void>` | Programmatically escalates the conversation to a human agent. |
207
+ | `cancelHumanHandoff()` | `() => Promise<void>` | Cancels human escalation and returns to AI mode. |
208
+ | `getMessages()` | `() => BotzkiMessage[]` | Returns the current array of conversation messages. |
209
+ | `getSessionId()` | `() => string` | Returns the active session ID. |
210
+ | `setSessionId(id)` | `(id: string) => void` | Sets a custom session ID. |
211
+ | `stopStreaming()` | `() => void` | Aborts active token streaming immediately. |
212
+ | `reloadLastMessage()` | `() => Promise<void>` | Regenerates the last assistant response. |
213
+ | `setTheme(theme)` | `(theme: "light" \| "dark" \| "auto") => void` | Dynamically switches widget theme. |
214
+ | `setPrimaryColor(color)` | `(color: string) => void` | Dynamically updates the primary brand accent color. |
215
+ | `setUser(user)` | `(user: BotzkiUser) => void` | Updates the identified visitor profile. |
216
+ | `getUnreadCount()` | `() => number` | Returns the current unread message count. |
217
+ | `markAsRead()` | `() => void` | Clears unread badge and stops tab title alerts. |
136
218
 
137
- Embed a complete AI chat window directly into your page layout:
219
+ ---
138
220
 
139
- ```tsx
140
- import { BotzkiChat } from "@botzki/react";
221
+ ## Headless Hooks & Utilities
141
222
 
142
- export function SupportPage() {
143
- return (
144
- <div style={{ height: "600px", maxWidth: "480px" }}>
145
- <BotzkiChat
146
- title="Knowledge Assistant"
147
- theme="dark"
148
- primaryColor="#6366f1"
149
- starterQuestions={[
150
- "How do I reset my password?",
151
- "Where can I find my invoices?",
152
- "How do I invite team members?",
153
- ]}
154
- />
155
- </div>
156
- );
157
- }
158
- ```
223
+ ### 1. `useChat(options?)`
224
+ Full headless state machine for custom chat UIs, including streaming, voice notes, human handoff, Ghost Co-Browsing (`coBrowse`), and 2-step action confirmation (`executeProposedAction`, `cancelProposedAction`).
159
225
 
160
- ---
226
+ ### 2. `useBotInfo()`
227
+ Fetches public bot configuration, branding colors, starter prompts, live chat operating hours, and active proactive triggers.
161
228
 
162
- ## Specialized Hooks
229
+ ### 3. `useFeedback()`
230
+ Submits thumbs-up (`1`) or thumbs-down (`-1`) ratings and comments for specific messages.
163
231
 
164
- ### `useBotInfo`
165
- Fetches bot metadata, name, avatar, and starter questions:
166
- ```tsx
167
- const { data, isLoading } = useBotInfo();
168
- ```
232
+ ### 4. `useLeadCapture()`
233
+ Captures visitor contact leads (`email`, `name`, `phoneNumber`, `company`, `teamSize`, `notes`) directly into the Botzki Leads CRM.
169
234
 
170
- ### `useFeedback`
171
- Submits thumbs-up or star ratings on responses:
172
- ```tsx
173
- const { submitFeedback, isSubmitting } = useFeedback();
174
- await submitFeedback({ rating: 1, comment: "Very helpful!" });
175
- ```
235
+ ### 5. `useVoiceTranscription()`
236
+ Transcribes audio `Blob` or `File` recordings into text via Botzki's speech-to-text endpoint.
176
237
 
177
- ### `useLeadCapture`
178
- Captures visitor contact info inside custom forms:
179
- ```tsx
180
- const { captureLead } = useLeadCapture();
181
- await captureLead({ email: "user@example.com", name: "Alex" });
182
- ```
238
+ ### 6. `useCoBrowse(options)` & `<CoBrowseLaserPointer />`
239
+ Powers Zero-Install Ghost Co-Browsing in custom headless chat interfaces with sanitized DOM snapshots (`captureDomSnapshot`) and real-time operator laser pointer rendering.
240
+
241
+ ### 7. `useEmpathyEngine(options)` & `analyzeVisitorSentiment(text)`
242
+ Analyzes visitor sentiment in real time (`frustrated`, `delighted`, `confused`, `urgent`, `neutral`) and drives procedural `<BotziAvatar />` emotions and physics.
183
243
 
184
244
  ---
185
245
 
186
246
  ## License
187
247
 
188
248
  MIT © Botzki
189
-