@bangdb/web-sdk 1.0.5 → 1.0.7

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 ADDED
@@ -0,0 +1,199 @@
1
+ # @bangdb/web-sdk
2
+
3
+ A self-contained AI chat widget that mounts itself into any web page. Works as a plain `<script>` tag, an npm package, or inside a React, Angular app.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @bangdb/web-sdk
11
+ # or
12
+ pnpm add @bangdb/web-sdk
13
+ ```
14
+
15
+ ---
16
+
17
+ ## Quick Start
18
+
19
+ ### Script tag
20
+
21
+ ```html
22
+ <script src="https://cdn.jsdelivr.net/@bangdb/web-sdk/dist/index.global.js"></script>
23
+ <script>
24
+ window.BangdbChatWidget.init({
25
+ config: {
26
+ apikey: "your-api-key",
27
+ baseURL: "your-bangdb-instance.com:18080",
28
+ userid: "user-123",
29
+ indexName: "my-index",
30
+ },
31
+ });
32
+ </script>
33
+ ```
34
+
35
+ ### ES Module
36
+
37
+ ```ts
38
+ import { init } from "@bangdb/web-sdk";
39
+
40
+ init({
41
+ config: {
42
+ apikey: "your-api-key",
43
+ baseURL: "your-bangdb-instance.com:18080",
44
+ userid: "user-123",
45
+ indexName: "my-index",
46
+ },
47
+ });
48
+ ```
49
+
50
+ ### React
51
+
52
+ ```tsx
53
+ // components/Chat.tsx
54
+ "use client"; // Next.js App Router only
55
+
56
+ import { useEffect, useRef } from "react";
57
+ import { type ChatWidgetOptions, ChatWidget } from "@bangdb/web-sdk";
58
+
59
+ export default function Chat(props: ChatWidgetOptions) {
60
+ const mountedRef = useRef(false);
61
+
62
+ useEffect(() => {
63
+ if (mountedRef.current) return;
64
+ mountedRef.current = true;
65
+
66
+ new ChatWidget(props);
67
+
68
+ return () => {
69
+ document.getElementById("ai-chat-widget-root")?.remove();
70
+ mountedRef.current = false;
71
+ };
72
+ }, []);
73
+
74
+ return null; // widget mounts itself into document.body
75
+ }
76
+ ```
77
+
78
+ ```tsx
79
+ // app/layout.tsx
80
+ import Chat from "@/components/Chat";
81
+
82
+ export default function Layout({ children }) {
83
+ return (
84
+ <>
85
+ {children}
86
+ <Chat
87
+ config={{
88
+ apikey: process.env.NEXT_PUBLIC_BANGDB_API_KEY!,
89
+ baseURL: process.env.NEXT_PUBLIC_BANGDB_BASE_URL!,
90
+ userid: "user-123",
91
+ indexName: "my-index",
92
+ }}
93
+ />
94
+ </>
95
+ );
96
+ }
97
+ ```
98
+
99
+ ---
100
+
101
+ ## Configuration
102
+
103
+ ### `ChatWidgetOptions`
104
+
105
+ | Option | Type | Required | Description |
106
+ |---------------|---|---|-------------------------------|
107
+ | `config` | `ApiConfig` | ✅ | API connection settings |
108
+ | `colorTokens` | `ColorTokens` | ❌ | Override default theme colors |
109
+ | `title` | `string` | ❌ | Custom chat header title |
110
+
111
+ ### `ApiConfig`
112
+
113
+ | Option | Type | Required | Description |
114
+ |-------------------------|---|---|--------------------------------------------------|
115
+ | `apikey` | `string` | ✅ | BangDB API key |
116
+ | `backendURL` | `string` | ✅ | BangDB instance URL with PORT |
117
+ | `userid` | `string` | ✅ | BangDB userid |
118
+ | `indexName` | `string` | ✅ | Vector index to query against |
119
+ | `resourceURL` | `string` | ❌ | Resource service URL with PORT for images/tables |
120
+
121
+ ---
122
+
123
+ If you use KaTeX for math rendering, import its CSS in your app:
124
+
125
+ ```ts
126
+ import "katex/dist/katex.min.css";
127
+ ```
128
+
129
+ ---
130
+
131
+ ## Theming
132
+
133
+ Override any part of the default dark theme by passing `colorTokens`:
134
+
135
+ ```ts
136
+ init({
137
+ config: { ... },
138
+ colorTokens: {
139
+ background: "oklch(0.2223 0.0060 271.1393)",
140
+ foreground: "oklch(0.9551 0 0)",
141
+ card: "oklch(0.2568 0.0076 274.6528)",
142
+ cardForeground: "oklch(0.9551 0 0)",
143
+ primary: "oklch(0.611 0.1217 157.75)",
144
+ primaryForeground: "oklch(0.9491 0 0)",
145
+ secondary: "oklch(0.2940 0.0130 272.9312)",
146
+ secondaryForeground: "oklch(0.9551 0 0)",
147
+ muted: "oklch(0.2940 0.0130 272.9312)",
148
+ mutedForeground: "oklch(0.7058 0 0)",
149
+ accent: "oklch(0.2795 0.0368 260.0310)",
150
+ accentForeground: "oklch(0.7857 0.1153 246.6596)",
151
+ border: "oklch(0.3289 0.0092 268.3843)",
152
+ input: "oklch(0.3289 0.0092 268.3843)",
153
+ ring: "oklch(0.611 0.1217 157.75)",
154
+ radius: "0.5rem",
155
+ shadowPanel:
156
+ "0 32px 80px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.06)",
157
+ shadowBubble:
158
+ "0 8px 32px color-mix(in oklab, oklch(0.611 0.1217 157.75) 40%, transparent)",
159
+ shadowInput:
160
+ "0 0 0 2px color-mix(in oklab, oklch(0.611 0.1217 157.75) 50%, transparent)",
161
+ },
162
+ });
163
+ ```
164
+
165
+ ## TypeScript Support
166
+
167
+ All types are exported from the package root:
168
+
169
+ ```ts
170
+ import type {
171
+ ChatWidgetOptions,
172
+ ApiConfig,
173
+ ColorTokens,
174
+ } from "@bangdb/web-sdk";
175
+ ```
176
+
177
+ ---
178
+
179
+ ## Browser Support
180
+
181
+ The widget uses Shadow DOM (`mode: "open"`) for style isolation. It requires a modern browser that supports:
182
+
183
+ - Shadow DOM v1
184
+ - Custom Elements
185
+ - `requestAnimationFrame`
186
+ - ES2020+
187
+
188
+ ---
189
+
190
+ ## Peer Dependencies
191
+
192
+ The following are **not** bundled and must be provided by the consumer if used:
193
+
194
+ | Package | When needed |
195
+ |---|---|
196
+ | `katex` | Math rendering in markdown |
197
+ | `katex/dist/katex.min.css` | KaTeX styles (import in your app) |
198
+
199
+ ---
package/dist/index.d.mts CHANGED
@@ -31,9 +31,15 @@ interface ChatWidgetOptions {
31
31
  title?: string;
32
32
  config: ApiConfig;
33
33
  logo?: string;
34
+ tools?: {
35
+ id: string;
36
+ name: string;
37
+ }[];
34
38
  }
35
39
  declare class ChatWidget {
36
40
  private font;
41
+ private static DEFAULT_TOOLS;
42
+ private tools;
37
43
  private injectThemeVars;
38
44
  private injectGlobalFonts;
39
45
  private TOKENS;
@@ -52,6 +58,8 @@ declare class ChatWidget {
52
58
  init(): Promise<void>;
53
59
  private handleChatDataChange;
54
60
  private handleModeChange;
61
+ /** Repositions the chat panel above/below/left/right based on where the bubble is on screen */
62
+ private updatePanelPosition;
55
63
  createChatBubble(): HTMLElement;
56
64
  createChatUI(): HTMLElement;
57
65
  chatArea(): HTMLElement;
package/dist/index.d.ts CHANGED
@@ -31,9 +31,15 @@ interface ChatWidgetOptions {
31
31
  title?: string;
32
32
  config: ApiConfig;
33
33
  logo?: string;
34
+ tools?: {
35
+ id: string;
36
+ name: string;
37
+ }[];
34
38
  }
35
39
  declare class ChatWidget {
36
40
  private font;
41
+ private static DEFAULT_TOOLS;
42
+ private tools;
37
43
  private injectThemeVars;
38
44
  private injectGlobalFonts;
39
45
  private TOKENS;
@@ -52,6 +58,8 @@ declare class ChatWidget {
52
58
  init(): Promise<void>;
53
59
  private handleChatDataChange;
54
60
  private handleModeChange;
61
+ /** Repositions the chat panel above/below/left/right based on where the bubble is on screen */
62
+ private updatePanelPosition;
55
63
  createChatBubble(): HTMLElement;
56
64
  createChatUI(): HTMLElement;
57
65
  chatArea(): HTMLElement;