vpschatbotwidget 1.0.0 → 1.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.
Files changed (75) hide show
  1. package/README.md +385 -47
  2. package/dist-lib/types/App.d.ts +2 -0
  3. package/dist-lib/types/chatbot/api/chatbot-api.d.ts +25 -0
  4. package/dist-lib/types/chatbot/api/chatbot-types.d.ts +125 -0
  5. package/dist-lib/types/chatbot/chatbot.test.d.ts +1 -0
  6. package/dist-lib/types/chatbot/config/colors.d.ts +165 -0
  7. package/dist-lib/types/chatbot/config/suggestions.d.ts +3 -0
  8. package/dist-lib/types/chatbot/core/ChatContext.d.ts +28 -0
  9. package/dist-lib/types/chatbot/core/ChatEmptyState.d.ts +2 -0
  10. package/dist-lib/types/chatbot/core/ChatError.d.ts +7 -0
  11. package/dist-lib/types/chatbot/core/ChatHeader.d.ts +22 -0
  12. package/dist-lib/types/chatbot/core/ChatInput.d.ts +8 -0
  13. package/dist-lib/types/chatbot/core/ChatMarkdown.d.ts +4 -0
  14. package/dist-lib/types/chatbot/core/ChatMessage.d.ts +7 -0
  15. package/dist-lib/types/chatbot/core/ChatMessageList.d.ts +2 -0
  16. package/dist-lib/types/chatbot/core/ChatPanel.d.ts +14 -0
  17. package/dist-lib/types/chatbot/core/ChatProvider.d.ts +19 -0
  18. package/dist-lib/types/chatbot/core/ChatSuggestions.d.ts +11 -0
  19. package/dist-lib/types/chatbot/core/ChatTicketConfirmation.d.ts +2 -0
  20. package/dist-lib/types/chatbot/core/ChatTypingIndicator.d.ts +4 -0
  21. package/dist-lib/types/chatbot/core/ticket-intent.d.ts +2 -0
  22. package/dist-lib/types/chatbot/embedded/EmbeddedChatbot.d.ts +27 -0
  23. package/dist-lib/types/chatbot/embedded/EmbeddedChatbotPanel.d.ts +12 -0
  24. package/dist-lib/types/chatbot/embedded/EmbeddedChatbotTrigger.d.ts +6 -0
  25. package/dist-lib/types/chatbot/hooks/useChatbot.d.ts +1 -0
  26. package/dist-lib/types/chatbot/index.d.ts +10 -0
  27. package/dist-lib/types/chatbot/widget/ChatbotWidget.d.ts +26 -0
  28. package/dist-lib/types/chatbot/widget/ChatbotWidgetPanel.d.ts +10 -0
  29. package/dist-lib/types/chatbot/widget/ChatbotWidgetTrigger.d.ts +7 -0
  30. package/dist-lib/types/components/AgentSummaryCard.d.ts +8 -0
  31. package/dist-lib/types/components/ChatHeader.d.ts +20 -0
  32. package/dist-lib/types/components/ChatInput.d.ts +9 -0
  33. package/dist-lib/types/components/ChatWidget.d.ts +14 -0
  34. package/dist-lib/types/components/ConnectingStatus.d.ts +6 -0
  35. package/dist-lib/types/components/EnvBadge.d.ts +31 -0
  36. package/dist-lib/types/components/FeedbackRatingCard.d.ts +7 -0
  37. package/dist-lib/types/components/MessageItem.d.ts +12 -0
  38. package/dist-lib/types/components/MessageList.d.ts +21 -0
  39. package/dist-lib/types/components/OrderTrackingCard.d.ts +13 -0
  40. package/dist-lib/types/components/QuickPrompts.d.ts +11 -0
  41. package/dist-lib/types/components/ResponseIconMapper.d.ts +26 -0
  42. package/dist-lib/types/components/SourceCitations.d.ts +7 -0
  43. package/dist-lib/types/components/ToolCallBadge.d.ts +7 -0
  44. package/dist-lib/types/components/TypingProgressBar.d.ts +21 -0
  45. package/dist-lib/types/components/ui/message-scroller.d.ts +9 -0
  46. package/dist-lib/types/lib/cn.d.ts +1 -0
  47. package/dist-lib/types/lib/gibberishDetector.d.ts +26 -0
  48. package/dist-lib/types/lib/textHighlighter.d.ts +15 -0
  49. package/dist-lib/types/main.d.ts +1 -0
  50. package/dist-lib/types/services/api.d.ts +12 -0
  51. package/dist-lib/types/test/message-scroller-stub.d.ts +36 -0
  52. package/dist-lib/types/test/setup.d.ts +1 -0
  53. package/dist-lib/types/types/chat.d.ts +59 -0
  54. package/dist-lib/vps-chatbot.cjs +101 -0
  55. package/dist-lib/vps-chatbot.js +2179 -0
  56. package/package.json +30 -3
  57. package/src/chatbot/chatbot.test.tsx +87 -0
  58. package/src/chatbot/core/ChatContext.tsx +6 -0
  59. package/src/chatbot/core/ChatProvider.tsx +29 -7
  60. package/src/chatbot/embedded/EmbeddedChatbot.tsx +63 -2
  61. package/src/chatbot/index.ts +25 -5
  62. package/src/chatbot/widget/ChatbotWidget.tsx +64 -2
  63. package/Chatbot.svg +0 -1
  64. package/dist/assets/index-C0fUDi2s.css +0 -1
  65. package/dist/assets/index-foGq5_Av.js +0 -159
  66. package/dist/index.html +0 -17
  67. package/index.html +0 -16
  68. package/src/App.tsx +0 -85
  69. package/src/main.tsx +0 -10
  70. package/src/services/api.ts +0 -74
  71. package/src/test/message-scroller-stub.tsx +0 -60
  72. package/src/test/setup.ts +0 -8
  73. package/src/vite-env.d.ts +0 -14
  74. package/tsconfig.json +0 -21
  75. package/vite.config.ts +0 -28
package/README.md CHANGED
@@ -1,86 +1,424 @@
1
- # VPS React Chatbot UI
1
+ # VPS Customer Chatbot UI (`vpschatbotwidget`)
2
2
 
3
- Reusable React + TypeScript assistant for the VPS Customer Portal. Widget and slide-out modes share one conversation engine and call the existing Python API.
3
+ [![VpsChatbot-widget](https://github.com/dhineshkumar-natobotics/VPS-Chatbot-Widget/actions/workflows/npm-publish.yml/badge.svg)](https://github.com/dhineshkumar-natobotics/VPS-Chatbot-Widget/actions/workflows/npm-publish.yml)
4
4
 
5
- ## Widget
5
+ A modular, highly customizable React + TypeScript assistant widget and slide-out panel for customer portals. Built with Tailwind CSS, Lucide icons, and full TypeScript typings.
6
+
7
+ Supports both **standalone mode** (drop-in with zero setup) and **shared conversation mode** (floating widget + slide-out panel syncing the same session).
8
+
9
+ ---
10
+
11
+ ## Table of Contents
12
+
13
+ - [Installation](#installation)
14
+ - [Quick Start](#quick-start)
15
+ - [1. Standalone Widget](#1-standalone-widget-no-provider-required)
16
+ - [2. Standalone Slide-out Panel](#2-standalone-slide-out-panel)
17
+ - [3. Shared Conversation Mode](#3-shared-conversation-mode-multiple-views)
18
+ - [API & Proxy URL Configuration](#api--proxy-url-configuration)
19
+ - [URL Normalization Behavior](#url-normalization-behavior)
20
+ - [Component Props Reference](#component-props-reference)
21
+ - [`ChatbotWidget`](#chatbotwidget)
22
+ - [`EmbeddedChatbot`](#embeddedchatbot)
23
+ - [`ChatProvider`](#chatprovider)
24
+ - [`ChatPanel`](#chatpanel)
25
+ - [Data Types & Interfaces](#data-types--interfaces)
26
+ - [`ChatUserContext`](#chatusercontext)
27
+ - [`Suggestion`](#suggestion)
28
+ - [`EnvStage`](#envstage)
29
+ - [`ChatMessage`](#chatmessage)
30
+ - [Hooks & API Utilities](#hooks--api-utilities)
31
+ - [`useChatbot()`](#usechatbot)
32
+ - [`createChatApi()`](#createchatapi)
33
+ - [Building & Distributing](#building--distributing)
34
+
35
+ ---
36
+
37
+ ## Installation
38
+
39
+ ### From GitHub Repository
40
+
41
+ ```bash
42
+ # Using npm
43
+ npm install git+https://github.com/dhineshkumar-natobotics/VPS-Chatbot-Widget.git
44
+
45
+ # Or if importing from a monorepo branch subdirectory
46
+ npm install github:dhineshkumar-natobotics/VPS-AI-Chatbot#main:frontend
47
+ ```
48
+
49
+ ### From npm Registry
50
+
51
+ ```bash
52
+ npm install vpschatbotwidget
53
+ ```
54
+
55
+ ### Import Styles
56
+
57
+ Import the CSS in your main application entry point (e.g. `main.tsx`, `index.tsx`, or `_app.tsx`):
6
58
 
7
59
  ```tsx
8
- import { ChatProvider, ChatbotWidget } from "./chatbot";
60
+ import "vpschatbotwidget/css";
61
+ ```
9
62
 
10
- <ChatProvider userContext={{ customerId: "CUST-1001" }}>
11
- <ChatbotWidget />
12
- </ChatProvider>
63
+ ---
64
+
65
+ ## Quick Start
66
+
67
+ ### 1. Standalone Widget (No Provider Required)
68
+
69
+ Drop the widget directly into any React tree. It automatically creates and manages its own internal chat session:
70
+
71
+ ```tsx
72
+ import { ChatbotWidget } from "vpschatbotwidget";
73
+
74
+ export function App() {
75
+ return (
76
+ <ChatbotWidget
77
+ apiBaseUrl="https://yourapiurl.com"
78
+ envStage="alpha"
79
+ envPulse
80
+ userContext={{
81
+ customerId: "CUST-1001",
82
+ email: "alex@company.com",
83
+ name: "Alex",
84
+ page: "dashboard",
85
+ }}
86
+ />
87
+ );
88
+ }
13
89
  ```
14
90
 
15
- `ChatbotWidget` accepts `open` / `onOpenChange` for host-controlled visibility, or `defaultOpen` for an uncontrolled trigger.
91
+ ### 2. Standalone Slide-out Panel
16
92
 
17
- ## Embedded slide-out
93
+ A draggable tab on the right edge that slides out into a responsive side panel:
18
94
 
19
95
  ```tsx
20
- import { ChatProvider, EmbeddedChatbot } from "./chatbot";
96
+ import { EmbeddedChatbot } from "vpschatbotwidget";
21
97
 
22
- <ChatProvider userContext={{ email: "ops@company.com", page: "reports" }}>
23
- <EmbeddedChatbot />
24
- </ChatProvider>
98
+ export function App() {
99
+ return (
100
+ <EmbeddedChatbot
101
+ apiBaseUrl="https://yourapiurl.com"
102
+ envStage="alpha"
103
+ showTrigger={true}
104
+ />
105
+ );
106
+ }
25
107
  ```
26
108
 
27
- On desktop the panel is about 440px and slides in from the right. On small screens it uses the full width with a light overlay.
109
+ ### 3. Shared Conversation Mode (Multiple Views)
28
110
 
29
- ## API base URL
111
+ Wrap both components in `<ChatProvider>` so messages, session state, and ticket flows stay synchronized between views:
30
112
 
31
- The Vite dev server proxies `/api` and `/health` to `http://127.0.0.1:8000`. Production builds are served by FastAPI from `frontend/dist`, so the browser calls same-origin `/api/v1/...`.
113
+ ```tsx
114
+ import { useState } from "react";
115
+ import { ChatProvider, ChatbotWidget, EmbeddedChatbot } from "vpschatbotwidget";
116
+
117
+ export function App() {
118
+ const [widgetOpen, setWidgetOpen] = useState(false);
119
+ const [embeddedOpen, setEmbeddedOpen] = useState(false);
120
+
121
+ return (
122
+ <ChatProvider
123
+ apiBaseUrl="https://yourapiurl.com"
124
+ userContext={{ customerId: "CUST-1001", email: "user@company.com" }}
125
+ >
126
+ <ChatbotWidget
127
+ open={widgetOpen}
128
+ onOpenChange={setWidgetOpen}
129
+ envStage="alpha"
130
+ />
131
+ <EmbeddedChatbot
132
+ open={embeddedOpen}
133
+ onOpenChange={setEmbeddedOpen}
134
+ envStage="alpha"
135
+ />
136
+ </ChatProvider>
137
+ );
138
+ }
139
+ ```
140
+
141
+ ---
142
+
143
+ ## API & Proxy URL Configuration
32
144
 
33
- There is no public model key in the frontend. Change the proxy target in `vite.config.ts` if the API is elsewhere during development.
145
+ You can configure the backend target using any of the following 4 methods:
34
146
 
35
- ## Authentication
147
+ ### 1. Component Prop
36
148
 
37
- Chat sessions are created with `POST /api/v1/sessions`. The current Python API does not require a browser JWT. Do not put NVIDIA, OpenAI, database, or signing secrets in React env vars.
149
+ Pass `apiBaseUrl` (or aliases `apiUrl` / `proxyUrl`) directly:
38
150
 
39
- ## User / customer context
151
+ ```tsx
152
+ <ChatbotWidget apiBaseUrl="https://yourapi.com" />
153
+ ```
154
+
155
+ ### 2. ChatProvider Prop
40
156
 
41
- Pass portal identity through `ChatProvider`:
157
+ Pass to `<ChatProvider>` to supply all child components:
42
158
 
43
159
  ```tsx
44
- <ChatProvider
45
- userContext={{
46
- customerId: "CUST-1001",
47
- email: "user@company.com",
48
- name: "Alex",
49
- role: "customer",
50
- page: "sample-status",
51
- }}
52
- >
160
+ <ChatProvider apiBaseUrl="https://yourapiurl.com">
161
+ <ChatbotWidget />
162
+ </ChatProvider>
163
+ ```
164
+
165
+ ### 3. Vite / Next.js Reverse Proxy
166
+
167
+ If your development server has a proxy rule:
168
+
169
+ ```ts
170
+ // vite.config.ts
171
+ export default defineConfig({
172
+ server: {
173
+ proxy: {
174
+ "/api": {
175
+ target: "https://yourapiurl.com",
176
+ changeOrigin: true,
177
+ },
178
+ "/health": {
179
+ target: "https://yourapiurl.com",
180
+ changeOrigin: true,
181
+ },
182
+ },
183
+ },
184
+ });
185
+ ```
186
+
187
+ You can pass `apiBaseUrl="/api"` or leave `apiBaseUrl` empty (`""`) to use relative same-origin paths.
188
+
189
+ ### 4. Environment Variables
190
+
191
+ Create a `.env` file in your project root:
192
+
193
+ ```env
194
+ VITE_API_BASE=https://yourapiurl.com
195
+ # or
196
+ VITE_API_BASE_URL=https://yourapiurl.com
197
+ # or
198
+ VITE_API_URL=https://yourapiurl.com
199
+ ```
200
+
201
+ When no prop is provided, the components automatically read `VITE_API_BASE`.
202
+
203
+ ### URL Normalization Behavior
204
+
205
+ The library includes automatic path normalization so you don't have to worry about trailing slashes or double `/api/api` paths:
206
+
207
+ | Value passed to `apiBaseUrl` | Call for `/api/v1/sessions` | Call for `/health` | Notes |
208
+ | :--- | :--- | :--- | :--- |
209
+ | `"https://yourapiurl.com"` | `https://yourapiurl.com/api/v1/sessions` | `https://yourapiurl.com/health` | Standard backend URL |
210
+ | `"https://yourapiurl.com/"` | `https://yourapiurl.com/api/v1/sessions` | `https://yourapiurl.com/health` | Trailing slash stripped cleanly |
211
+ | `"https://yourapiurl.com/api"` | `https://yourapiurl.com/api/v1/sessions` | `https://yourapiurl.com/health` | Does not duplicate `/api/api` |
212
+ | `"/api"` | `/api/v1/sessions` | `/health` | Works with local dev server proxies |
213
+ | `""` *(default)* | `/api/v1/sessions` | `/health` | Same-origin relative paths |
214
+
215
+ ---
216
+
217
+ ## Component Props Reference
218
+
219
+ ### `ChatbotWidget`
220
+
221
+ Floating round launcher button in the bottom-right corner with an animated pop-up chat panel.
222
+
223
+ | Prop | Type | Default | Description |
224
+ | :--- | :--- | :--- | :--- |
225
+ | `open` | `boolean` | `undefined` | Controlled visibility state. When provided, component behaves as controlled. |
226
+ | `onOpenChange` | `(open: boolean) => void` | `undefined` | Callback fired when the user opens or closes the widget. |
227
+ | `defaultOpen` | `boolean` | `false` | Initial open state when used in uncontrolled mode. |
228
+ | `apiBaseUrl` | `string` | `""` (or `VITE_API_BASE`) | Backend base URL or proxy URL (e.g. `"https://yourapiurl.com"` or `"/api"`). |
229
+ | `apiUrl` | `string` | `undefined` | Alias for `apiBaseUrl`. |
230
+ | `proxyUrl` | `string` | `undefined` | Alias for `apiBaseUrl`. |
231
+ | `envStage` | `EnvStage` | `undefined` | Environment badge shown in header (`"dev"`, `"stage"`, `"alpha"`, `"beta"`, `"prod"`). Omit for production. |
232
+ | `envPulse` | `boolean` | `true` | Whether the environment badge shows an animated pulsing green/amber dot. |
233
+ | `userContext` | [`ChatUserContext`](#chatusercontext) | `{}` | Authenticated customer identity (`customerId`, `email`, `name`, `role`, `page`). |
234
+ | `suggestions` | [`Suggestion[]`](#suggestion) | `DEFAULT_SUGGESTIONS` | Custom quick prompt suggestions rendered above the input. |
235
+ | `disableSuggestions` | `boolean` | `false` | When `true`, hides the suggestion badges entirely. |
236
+ | `initialMessage` | `string` | `undefined` | Starter message sent automatically to the assistant upon session creation. |
237
+
238
+ ---
239
+
240
+ ### `EmbeddedChatbot`
241
+
242
+ A draggable side tab on the right edge of the screen that slides out into a full chat panel.
243
+
244
+ | Prop | Type | Default | Description |
245
+ | :--- | :--- | :--- | :--- |
246
+ | `open` | `boolean` | `undefined` | Controlled open/close state of the slide-out panel. |
247
+ | `onOpenChange` | `(open: boolean) => void` | `undefined` | Callback fired when the slide-out panel opens or closes. |
248
+ | `defaultOpen` | `boolean` | `false` | Initial open state for uncontrolled mode. |
249
+ | `showTrigger` | `boolean` | `true` | Whether to display the vertical draggable "Assistant" tab on the right edge. |
250
+ | `apiBaseUrl` | `string` | `""` (or `VITE_API_BASE`) | Backend base URL or proxy path. |
251
+ | `apiUrl` | `string` | `undefined` | Alias for `apiBaseUrl`. |
252
+ | `proxyUrl` | `string` | `undefined` | Alias for `apiBaseUrl`. |
253
+ | `envStage` | `EnvStage` | `undefined` | Environment badge stage shown in header. |
254
+ | `envPulse` | `boolean` | `true` | Animated pulse dot on the environment badge. |
255
+ | `userContext` | [`ChatUserContext`](#chatusercontext) | `{}` | Authenticated customer identity information. |
256
+ | `suggestions` | [`Suggestion[]`](#suggestion) | `DEFAULT_SUGGESTIONS` | Quick prompt suggestions. |
257
+ | `disableSuggestions` | `boolean` | `false` | Hide suggestion pills. |
258
+ | `initialMessage` | `string` | `undefined` | Starter message automatically sent on mount. |
259
+
260
+ ---
261
+
262
+ ### `ChatProvider`
263
+
264
+ React context provider that coordinates conversation state, API communication, message history, and customer context.
265
+
266
+ | Prop | Type | Default | Description |
267
+ | :--- | :--- | :--- | :--- |
268
+ | `children` | `React.ReactNode` | **Required** | Nested components that consume chat state. |
269
+ | `apiBaseUrl` | `string` | `""` (or `VITE_API_BASE`) | Backend base URL used by all child components. |
270
+ | `apiUrl` | `string` | `undefined` | Alias for `apiBaseUrl`. |
271
+ | `proxyUrl` | `string` | `undefined` | Alias for `apiBaseUrl`. |
272
+ | `userContext` | [`ChatUserContext`](#chatusercontext) | `{}` | Shared customer identity for ticket creation and contextual flows. |
273
+ | `suggestions` | [`Suggestion[]`](#suggestion) | `DEFAULT_SUGGESTIONS` | Shared suggestion prompts. |
274
+ | `disableSuggestions` | `boolean` | `false` | Disable suggestion badges across all views. |
275
+ | `initialMessage` | `string` | `undefined` | Message triggered upon provider initialization. |
276
+ | `api` | `ChatApiClient` | `undefined` | Optional pre-configured API client instance from `createChatApi(baseUrl)`. |
277
+
278
+ ---
279
+
280
+ ### `ChatPanel`
281
+
282
+ The inner chat interface including header, message stream, suggestions, and input row. Can be embedded directly into custom containers or modal drawers.
283
+
284
+ | Prop | Type | Default | Description |
285
+ | :--- | :--- | :--- | :--- |
286
+ | `className` | `string` | `undefined` | Custom CSS classes applied to the outer `<section>` container. |
287
+ | `onClose` | `() => void` | `undefined` | Callback invoked when close/minimize is clicked. |
288
+ | `showMinimize` | `boolean` | `false` | Whether to display the minimize icon in the header. |
289
+ | `title` | `string` | `"VPS AI Assistant"` | Primary header title text. |
290
+ | `subtitle` | `string` | `undefined` | Secondary header subtitle text. |
291
+ | `envStage` | `EnvStage` | `undefined` | Environment badge stage. |
292
+ | `envPulse` | `boolean` | `true` | Pulse animation on environment badge. |
293
+
294
+ ---
295
+
296
+ ## Data Types & Interfaces
297
+
298
+ ### `ChatUserContext`
299
+
300
+ Passed via `userContext` prop to supply portal identity:
301
+
302
+ ```ts
303
+ export interface ChatUserContext {
304
+ /** Customer unique identifier in portal (e.g. "CUST-1001") */
305
+ customerId?: string;
306
+ /** Customer verified email address */
307
+ email?: string;
308
+ /** Display name of the user */
309
+ name?: string;
310
+ /** User role (e.g. "admin", "customer", "operator") */
311
+ role?: string;
312
+ /** Current page/route context (e.g. "reports", "sample-status") */
313
+ page?: string;
314
+ }
53
315
  ```
54
316
 
55
- Context is used for ticket creation. It is not stored in `localStorage` and is not sent as extra chat fields (the chat endpoint only accepts `{ "message": "..." }`).
317
+ ### `Suggestion`
56
318
 
57
- ## Ticket confirmation
319
+ Quick prompt suggestions:
58
320
 
59
- Messages that ask to create or open a support ticket are intercepted. The UI asks for explicit confirmation, then calls `POST /api/v1/tickets`. If customer ID/email is missing, the confirmation card asks for it.
321
+ ```ts
322
+ export interface Suggestion {
323
+ /** Text displayed inside the chip badge */
324
+ label: string;
325
+ /** Prompt text inserted into input box when clicked */
326
+ query: string;
327
+ }
328
+ ```
60
329
 
61
- The LLM can still create a ticket via the backend `create_ticket` tool on a normal chat turn. That server-side path is unchanged.
330
+ ### `EnvStage`
62
331
 
63
- ## Transport
332
+ Environment stage indicator:
64
333
 
65
- `POST /api/v1/sessions/{id}/messages` returns a full JSON `ChatResponse`. There is no SSE or WebSocket stream. The UI shows a typing row while the request is in flight, then replaces it with the complete answer. `MessageScroller` `autoScroll` follows the live edge unless the reader has scrolled away.
334
+ ```ts
335
+ export type EnvStage = "dev" | "stage" | "alpha" | "beta" | "prod";
336
+ ```
66
337
 
67
- ## Styling
338
+ ### `ChatMessage`
68
339
 
69
- The VPS `ColorPalette` lives in `src/chatbot/config/colors.ts`. Semantic CSS tokens (`--primary`, `--bg-app`, `--text-main`, fonts) are in `src/index.css` and map onto that palette. Tailwind utilities such as `bg-primary` and `text-foreground` compose those tokens. Override with `className` on `ChatPanel` if the host portal needs a tighter match.
340
+ Message structure in history:
70
341
 
71
- ## Suggestions
342
+ ```ts
343
+ export interface ChatMessage {
344
+ id: string;
345
+ role: "user" | "assistant" | "system";
346
+ content: string;
347
+ createdAt: string;
348
+ status?: "pending" | "complete" | "error";
349
+ sources?: Source[];
350
+ toolCalls?: ToolCall[];
351
+ usage?: TokenUsage;
352
+ }
353
+ ```
354
+
355
+ ---
356
+
357
+ ## Hooks & API Utilities
358
+
359
+ ### `useChatbot()`
360
+
361
+ Access conversation state and methods from any child component within `<ChatProvider>`:
362
+
363
+ ```tsx
364
+ import { useChatbot } from "vpschatbotwidget";
365
+
366
+ function CustomStatus() {
367
+ const {
368
+ messages, // ChatMessage[]
369
+ status, // "idle" | "connecting" | "awaiting" | "error"
370
+ error, // string | null
371
+ sessionId, // string | null
372
+ apiBaseUrl, // string
373
+ sendMessage, // (text: string) => Promise<void>
374
+ retryLast, // () => Promise<void>
375
+ resetConversation, // () => Promise<void>
376
+ } = useChatbot();
377
+
378
+ return <div>Active Session: {sessionId} (Status: {status})</div>;
379
+ }
380
+ ```
381
+
382
+ ### `createChatApi()`
72
383
 
73
- Default prompt badges sit above the text box (`src/chatbot/config/suggestions.ts`). Typing filters them by suggestion text; choosing a badge fills the box so you can edit before sending. Disable them:
384
+ Factory function to instantiate an isolated API client:
74
385
 
75
386
  ```tsx
76
- <ChatProvider disableSuggestions>
387
+ import { createChatApi } from "vpschatbotwidget";
388
+
389
+ const client = createChatApi("https://yourapiurl.com");
390
+ const session = await client.createSession();
391
+ const reply = await client.sendMessage(session.sessionId, "Hello");
392
+ ```
393
+
394
+ ---
395
+
396
+ ## Building & Distributing
397
+
398
+ ### Build Standalone Library
399
+
400
+ Compiles the package into `dist-lib/` with ES Modules, CommonJS, and TypeScript types:
401
+
402
+ ```bash
403
+ npm run build:lib
404
+ ```
405
+
406
+ ### Run Tests
407
+
408
+ ```bash
409
+ npm test
410
+ ```
411
+
412
+ ### Run TypeScript Verification
413
+
414
+ ```bash
415
+ npm run typecheck
77
416
  ```
78
417
 
79
- Or replace them with `suggestions={[{ label, query }]}`.
418
+ ### Package Exports Overview
80
419
 
81
- ## Portal integration
420
+ When imported as a library, `package.json` maps:
82
421
 
83
- 1. Wrap the host tree (or a layout region) with a single `ChatProvider`.
84
- 2. Mount `ChatbotWidget` for a floating launcher, `EmbeddedChatbot` for a side panel, or both — they share messages.
85
- 3. Pass authenticated customer id/email from the portal session, never from a public config file.
86
- 4. Keep FastAPI as the only AI backend the browser talks to.
422
+ - `.` &rarr; TypeScript source / `dist-lib/vps-chatbot.js` / CommonJS
423
+ - `./css` &rarr; `dist-lib/style.css` (or `src/index.css`)
424
+ - Types &rarr; `dist-lib/types/chatbot/index.d.ts`
@@ -0,0 +1,2 @@
1
+ import React from "react";
2
+ export declare const App: React.FC;
@@ -0,0 +1,25 @@
1
+ import type { ChatMessage, ChatMessageDto, SessionCreated, Source, SourceDto, Ticket, ToolCall, ToolCallDto, TokenUsage, TokenUsageDto } from "./chatbot-types";
2
+ export declare function resolveApiBaseUrl(customUrl?: string): string;
3
+ export declare function buildApiUrl(baseUrl: string | undefined, path: string): string;
4
+ export declare function normalizeSource(dto: SourceDto): Source;
5
+ export declare function normalizeToolCall(dto: ToolCallDto): ToolCall;
6
+ export declare function normalizeUsage(dto: TokenUsageDto): TokenUsage;
7
+ export declare function normalizeChatMessage(dto: ChatMessageDto): ChatMessage;
8
+ export interface ChatApiClient {
9
+ apiBaseUrl: string;
10
+ createSession(): Promise<SessionCreated>;
11
+ sendMessage(sessionId: string, message: string): Promise<{
12
+ requestId: string;
13
+ sessionId: string;
14
+ answer: string;
15
+ sources: Source[];
16
+ toolCalls: ToolCall[];
17
+ usage: TokenUsage;
18
+ }>;
19
+ getHistory(sessionId: string): Promise<ChatMessage[]>;
20
+ closeSession(sessionId: string): Promise<void>;
21
+ createTicket(): Promise<Ticket>;
22
+ checkHealth(): Promise<boolean>;
23
+ }
24
+ export declare function createChatApi(initialBaseUrl?: string): ChatApiClient;
25
+ export declare const chatApi: ChatApiClient;
@@ -0,0 +1,125 @@
1
+ export type ChatRole = "user" | "assistant" | "system";
2
+ export type MessageStatus = "pending" | "complete" | "error";
3
+ export interface Source {
4
+ chunkId: string;
5
+ source: string;
6
+ score: number;
7
+ }
8
+ export interface ToolCall {
9
+ toolName: string;
10
+ arguments: Record<string, unknown>;
11
+ result: Record<string, unknown>;
12
+ }
13
+ export interface TokenUsage {
14
+ model: string;
15
+ promptTokens: number;
16
+ completionTokens: number;
17
+ totalTokens: number;
18
+ }
19
+ export interface ChatMessage {
20
+ id: string;
21
+ role: ChatRole;
22
+ content: string;
23
+ createdAt: string;
24
+ status?: MessageStatus;
25
+ sources?: Source[];
26
+ toolCalls?: ToolCall[];
27
+ usage?: TokenUsage;
28
+ }
29
+ export interface ChatUserContext {
30
+ customerId?: string;
31
+ email?: string;
32
+ name?: string;
33
+ role?: string;
34
+ page?: string;
35
+ }
36
+ export interface Ticket {
37
+ ticketId: string;
38
+ customerId: string;
39
+ customerEmail: string;
40
+ subject: string;
41
+ description: string;
42
+ priority: string;
43
+ status: string;
44
+ createdAt: string;
45
+ updatedAt: string;
46
+ }
47
+ export interface CreateTicketInput {
48
+ customerIdOrEmail: string;
49
+ subject: string;
50
+ description: string;
51
+ priority?: "low" | "medium" | "high" | "urgent";
52
+ }
53
+ export interface SessionCreated {
54
+ sessionId: string;
55
+ createdAt: string;
56
+ }
57
+ export interface ChatApiError {
58
+ code?: string;
59
+ message: string;
60
+ requestId?: string;
61
+ }
62
+ export interface Suggestion {
63
+ label: string;
64
+ query: string;
65
+ }
66
+ export interface SourceDto {
67
+ chunk_id: string;
68
+ source: string;
69
+ score: number;
70
+ }
71
+ export interface ToolCallDto {
72
+ tool_name: string;
73
+ arguments?: Record<string, unknown>;
74
+ result?: Record<string, unknown>;
75
+ }
76
+ export interface TokenUsageDto {
77
+ model: string;
78
+ prompt_tokens: number;
79
+ completion_tokens: number;
80
+ total_tokens: number;
81
+ }
82
+ export interface ChatMessageDto {
83
+ id: string;
84
+ role: string;
85
+ content: string;
86
+ model?: string | null;
87
+ prompt_tokens?: number;
88
+ completion_tokens?: number;
89
+ created_at?: string | null;
90
+ }
91
+ export interface SessionResponseDto {
92
+ session_id: string;
93
+ created_at: string;
94
+ }
95
+ export interface SessionMessagesResponseDto {
96
+ session_id: string;
97
+ messages: ChatMessageDto[];
98
+ }
99
+ export interface ChatResponseDto {
100
+ request_id: string;
101
+ session_id: string;
102
+ answer: string;
103
+ sources: SourceDto[];
104
+ tool_calls?: ToolCallDto[];
105
+ usage: TokenUsageDto;
106
+ }
107
+ export interface TicketDto {
108
+ ticket_id: string;
109
+ customer_id: string;
110
+ customer_email: string;
111
+ subject: string;
112
+ description: string;
113
+ priority: string;
114
+ status: string;
115
+ created_at: string;
116
+ updated_at: string;
117
+ }
118
+ export interface ApiErrorDto {
119
+ success?: boolean;
120
+ error?: {
121
+ code?: string;
122
+ message?: string;
123
+ request_id?: string;
124
+ };
125
+ }
@@ -0,0 +1 @@
1
+ export {};