@filigran/chatbot 1.1.2 β†’ 3.0.1

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,215 +1,325 @@
1
- <!-- markdownlint-disable MD030 -->
1
+ # @filigran/chatbot
2
2
 
3
- # Filigran Chatbot
3
+ Filigran chat panel β€” a standalone React + Tailwind chatbot component with SSE streaming, multi-agent support, and full markdown rendering.
4
4
 
5
- > πŸͺ§ Most of the code from this repository is taken from [FlowiseEmbedChat](https://github.com/FlowiseAI/FlowiseChatEmbed).
6
- >
7
- > The chatbot interface and logic is kept, but we remove ties to flowise in favor of an agnostic approach, to be able to connect custom agentic server.
5
+ ## Features
8
6
 
9
- ![Flowise](https://github.com/FlowiseAI/FlowiseChatEmbed/blob/main/images/ChatEmbed.gif?raw=true)
7
+ - πŸ”„ **SSE Message Streaming** β€” Real-time response streaming with status indicators
8
+ - πŸ€– **Multi-Agent Support** β€” Switch between different AI agents
9
+ - πŸ“Ž **File Attachments** β€” Upload and paste files (PDF, TXT, images)
10
+ - πŸ“ **Full Markdown** β€” Tables, code blocks with copy button, lists, blockquotes
11
+ - 🎨 **Customizable Theme** β€” Accent color and logo customization
12
+ - πŸ“± **3 Display Modes** β€” Floating, sidebar (resizable), and fullscreen
13
+ - πŸ’Ύ **Persistence** β€” Conversation and sidebar width saved to localStorage
14
+ - πŸ› οΈ **Tool Tracking** β€” Visual indicators for AI tool usage
10
15
 
11
- Install:
16
+ ## Installation
12
17
 
13
18
  ```bash
14
- yarn install
19
+ yarn add @filigran/chatbot
15
20
  ```
16
21
 
17
- Dev:
22
+ ## Quick Start
18
23
 
19
- ```bash
20
- yarn dev
24
+ ```tsx
25
+ import { useState } from 'react';
26
+ import { ChatPanel, ChatToggleButton } from '@filigran/chatbot';
27
+ import '@filigran/chatbot/styles.css';
28
+
29
+ function App() {
30
+ const [isOpen, setIsOpen] = useState(false);
31
+ const [mode, setMode] = useState<'floating' | 'sidebar' | 'fullscreen'>('floating');
32
+
33
+ return (
34
+ <>
35
+ <ChatToggleButton
36
+ isOpen={isOpen}
37
+ onToggle={() => setIsOpen(!isOpen)}
38
+ label="Ask Assistant"
39
+ accentColor="#7b5cff"
40
+ />
41
+ {isOpen && (
42
+ <ChatPanel
43
+ mode={mode}
44
+ onClose={() => setIsOpen(false)}
45
+ onModeChange={setMode}
46
+ apiBaseUrl="/api/assistant"
47
+ user={{ firstName: 'John' }}
48
+ />
49
+ )}
50
+ </>
51
+ );
52
+ }
21
53
  ```
22
54
 
23
- A development server will be running on http://localhost:5678 automatically. Update `public/index.html` to connect to your server:
55
+ ## Components
56
+
57
+ ### `ChatPanel`
24
58
 
25
- ```html
26
- <!-- public/index.html -->
27
- <script type="module">
28
- import Chatbot from 'https://localhost:5678/web.js'; // Switch between './web.js' or 'https://localhost:5678/web.js'
29
- Chatbot.init({
30
- agenticUrl: 'https://your-agentic-service-url/endpoint', // Add your endpoint
31
- });
32
- </script>
59
+ The main chat interface component.
60
+
61
+ ```tsx
62
+ import { ChatPanel } from '@filigran/chatbot';
33
63
  ```
34
64
 
35
- Build:
65
+ #### Props
36
66
 
37
- ```bash
38
- yarn build
67
+ | Prop | Type | Default | Description |
68
+ |------|------|---------|-------------|
69
+ | `mode` | `'floating' \| 'sidebar' \| 'fullscreen'` | **required** | Display mode |
70
+ | `onClose` | `() => void` | **required** | Called when close button is clicked |
71
+ | `onModeChange` | `(mode: ChatMode) => void` | **required** | Called when user switches display mode |
72
+ | `apiBaseUrl` | `string` | **required** | Base URL for chat API endpoints |
73
+ | `user` | `{ firstName: string }` | **required** | Current user info |
74
+ | `topOffset` | `number` | `0` | Top offset in pixels (for sidebar/fullscreen with fixed headers) |
75
+ | `agentDashboardUrl` | `string` | β€” | URL for "Browse agents" / "Create agent" links |
76
+ | `t` | `(key: string) => string` | identity | Translation function for i18n |
77
+ | `accentColor` | `string` | `'#7b5cff'` | Primary accent color (hex) |
78
+ | `logoIcon` | `React.ReactNode` | default icon | Custom logo/icon for the assistant |
79
+ | `promptSuggestions` | `string[]` | default list | Prompt suggestions shown on welcome screen |
80
+ | `resizable` | `boolean` | `false` | Enable drag-to-resize for sidebar mode |
81
+ | `onWidthChange` | `(width: number) => void` | β€” | Called when sidebar width changes during resize |
82
+ | `onResizeStart` | `() => void` | β€” | Called when resize drag starts |
83
+ | `onResizeEnd` | `() => void` | β€” | Called when resize drag ends |
84
+
85
+ #### Resizable Sidebar Example
86
+
87
+ ```tsx
88
+ function App() {
89
+ const [sidebarWidth, setSidebarWidth] = useState(400);
90
+ const [isResizing, setIsResizing] = useState(false);
91
+
92
+ return (
93
+ <div style={{ marginRight: sidebarWidth }}>
94
+ <MainContent />
95
+ <ChatPanel
96
+ mode="sidebar"
97
+ resizable={true}
98
+ onWidthChange={setSidebarWidth}
99
+ onResizeStart={() => setIsResizing(true)}
100
+ onResizeEnd={() => setIsResizing(false)}
101
+ // ... other props
102
+ />
103
+ </div>
104
+ );
105
+ }
39
106
  ```
40
107
 
41
- ## Configuration
42
-
43
- You can also customize chatbot with different configuration
44
-
45
- ```html
46
- <script type="module">
47
- import Chatbot from 'https://localhost:5678/web.js'; // Switch between './web.js' or 'https://localhost:5678/web.js'
48
- Chatbot.init({
49
- agenticUrl: 'https://your-agentic-service-url/endpoint', // Add your endpoint
50
- chatflowConfig: {
51
- some: "variable" // this will be send in request header
52
- },
53
- observersConfig: {
54
- // (optional) Allows you to execute code in parent based upon signal observations within the chatbot.
55
- // The userinput field submitted to bot ("" when reset by bot)
56
- observeUserInput: (userInput) => {
57
- console.log({ userInput });
58
- },
59
- // The bot message stack has changed
60
- observeMessages: (messages) => {
61
- console.log({ messages });
62
- },
63
- // The bot loading signal changed
64
- observeLoading: (loading) => {
65
- console.log({ loading });
66
- },
67
- },
68
- theme: {
69
- button: {
70
- backgroundColor: '#3B81F6',
71
- right: 20,
72
- bottom: 20,
73
- size: 48, // small | medium | large | number
74
- dragAndDrop: true,
75
- iconColor: 'white',
76
- customIconSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
77
- autoWindowOpen: {
78
- autoOpen: true, //parameter to control automatic window opening
79
- openDelay: 2, // Optional parameter for delay time in seconds
80
- autoOpenOnMobile: false, //parameter to control automatic window opening in mobile
81
- },
82
- },
83
- tooltip: {
84
- showTooltip: true,
85
- tooltipMessage: 'Hi There πŸ‘‹!',
86
- tooltipBackgroundColor: 'black',
87
- tooltipTextColor: 'white',
88
- tooltipFontSize: 16,
89
- },
90
- disclaimer: {
91
- title: 'Disclaimer',
92
- message: 'By using this chatbot, you agree to the <a target="_blank" href="https://your-url/terms">Terms & Condition</a>',
93
- textColor: 'black',
94
- buttonColor: '#3b82f6',
95
- buttonText: 'Start Chatting',
96
- buttonTextColor: 'white',
97
- blurredBackgroundColor: 'rgba(0, 0, 0, 0.4)', //The color of the blurred background that overlays the chat interface
98
- backgroundColor: 'white',
99
- denyButtonText: 'Cancel',
100
- denyButtonBgColor: '#ef4444',
101
- },
102
- form: {
103
- backgroundColor: 'white',
104
- textColor: 'black',
105
- }
106
- customCSS: ``, // Add custom CSS styles. Use !important to override default styles
107
- chatWindow: {
108
- showTitle: true,
109
- showAgentMessages: true,
110
- title: 'Chat Bot',
111
- titleAvatarSrc: 'https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/svg/google-messages.svg',
112
- titleBackgroundColor: '#3B81F6',
113
- titleTextColor: '#ffffff',
114
- welcomeMessage: 'Hello! This is custom welcome message',
115
- errorMessage: 'This is a custom error message',
116
- backgroundColor: '#ffffff',
117
- backgroundImage: 'enter image path or link', // If set, this will overlap the background color of the chat window.
118
- height: 700,
119
- width: 400,
120
- fontSize: 16,
121
- starterPrompts: ['What is a bot?', 'Who are you?'], // It overrides the starter prompts set by the chat flow passed
122
- starterPromptFontSize: 15,
123
- clearChatOnReload: false, // If set to true, the chat will be cleared when the page reloads
124
- sourceDocsTitle: 'Sources:',
125
- renderHTML: true,
126
- botMessage: {
127
- backgroundColor: '#f7f8ff',
128
- textColor: '#303235',
129
- showAvatar: true,
130
- avatarSrc: 'https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/parroticon.png',
131
- },
132
- userMessage: {
133
- backgroundColor: '#3B81F6',
134
- textColor: '#ffffff',
135
- showAvatar: true,
136
- avatarSrc: 'https://raw.githubusercontent.com/zahidkhawaja/langchain-chat-nextjs/main/public/usericon.png',
137
- },
138
- textInput: {
139
- placeholder: 'Type your question',
140
- backgroundColor: '#ffffff',
141
- textColor: '#303235',
142
- sendButtonColor: '#3B81F6',
143
- maxChars: 50,
144
- maxCharsWarningMessage: 'You exceeded the characters limit. Please input less than 50 characters.',
145
- autoFocus: true, // If not used, autofocus is disabled on mobile and enabled on desktop. true enables it on both, false disables it on both.
146
- sendMessageSound: true,
147
- // sendSoundLocation: "send_message.mp3", // If this is not used, the default sound effect will be played if sendSoundMessage is true.
148
- receiveMessageSound: true,
149
- // receiveSoundLocation: "receive_message.mp3", // If this is not used, the default sound effect will be played if receiveSoundMessage is true.
150
- },
151
- feedback: {
152
- color: '#303235',
153
- },
154
- dateTimeToggle: {
155
- date: true,
156
- time: true,
157
- },
158
- footer: {
159
- textColor: '#303235',
160
- text: 'Powered by',
161
- company: 'Filigran',
162
- companyLink: 'https://filigran.io',
163
- },
164
- },
165
- },
166
- });
167
- </script>
168
- ```
169
-
170
- ## Development Mode (For Local Testing)
171
-
172
- 1. Configure your environment variables (see above)
173
-
174
- 2. Start the proxy server:
108
+ The sidebar width is persisted to `localStorage` under the key `filigranChatSidebarWidth`.
175
109
 
176
- ```bash
177
- yarn start
178
- # Server will be available at:
179
- # - Local: http://localhost:3001
110
+ ### `ChatToggleButton`
111
+
112
+ A floating action button to toggle the chat panel.
113
+
114
+ ```tsx
115
+ import { ChatToggleButton } from '@filigran/chatbot';
180
116
  ```
181
117
 
182
- 3. Update the test page configuration:
118
+ #### Props
119
+
120
+ | Prop | Type | Default | Description |
121
+ |------|------|---------|-------------|
122
+ | `isOpen` | `boolean` | **required** | Whether the chat panel is open |
123
+ | `onToggle` | `() => void` | **required** | Called when button is clicked |
124
+ | `label` | `string` | `'Chat'` | Tooltip/aria label |
125
+ | `accentColor` | `string` | `'#7b5cff'` | Button background color |
126
+ | `icon` | `React.ReactNode` | default icon | Custom icon |
127
+
128
+ ## API Contract
129
+
130
+ The component expects your backend to implement these endpoints:
131
+
132
+ ### `GET {apiBaseUrl}/chat/agents`
183
133
 
184
- - Open `public/index.html` in your code editor
185
- - Modify the `agenticUrl`:
134
+ Returns available AI agents.
186
135
 
187
- ```html
188
- <!-- public/index.html -->
189
- <script type="module">
190
- import Chatbot from './web.js';
191
- Chatbot.init({
192
- agenticUrl: 'https://your-agentic-service-url/endpoint', // Add your endpoint
193
- });
194
- </script>
136
+ ```json
137
+ [
138
+ {
139
+ "id": "agent-1",
140
+ "name": "General Assistant",
141
+ "slug": "general",
142
+ "icon": null,
143
+ "description": "A helpful general-purpose assistant"
144
+ }
145
+ ]
195
146
  ```
196
147
 
197
- 4. Open a new terminal and start the development server:
148
+ ### `POST {apiBaseUrl}/chat/sessions`
149
+
150
+ Restores conversation history.
151
+
152
+ **Request:**
153
+ ```json
154
+ {
155
+ "conversation_id": "uuid-here",
156
+ "agent_slug": "general"
157
+ }
158
+ ```
159
+
160
+ **Response:**
161
+ ```json
162
+ {
163
+ "messages": [
164
+ { "role": "user", "content": "Hello" },
165
+ { "role": "assistant", "content": "Hi! How can I help?" }
166
+ ]
167
+ }
168
+ ```
169
+
170
+ ### `POST {apiBaseUrl}/chat/messages`
171
+
172
+ Sends a message and streams the response via SSE.
173
+
174
+ **Request:**
175
+ ```json
176
+ {
177
+ "content": "What is the weather?",
178
+ "conversation_id": "uuid-or-null",
179
+ "agent_slug": "general"
180
+ }
181
+ ```
182
+
183
+ **Response:** Server-Sent Events stream with these event types:
184
+
185
+ ```
186
+ data: {"type": "status", "status": "thinking"}
187
+ data: {"type": "status", "status": "tool_start", "tools": ["search_web"]}
188
+ data: {"type": "status", "status": "analyzing"}
189
+ data: {"type": "status", "status": "streaming"}
190
+ data: {"type": "stream", "content": "The weather "}
191
+ data: {"type": "stream", "content": "today is sunny."}
192
+ data: {"type": "done", "content": "The weather today is sunny.", "conversation_id": "new-uuid", "tool_names": ["search_web"], "tool_call_count": 1, "iterations": 1}
193
+ ```
194
+
195
+ **Status values:**
196
+ - `thinking` β€” Agent is processing
197
+ - `tool_start` β€” Agent is using tools (with `tools` array)
198
+ - `analyzing` β€” Agent is analyzing tool results
199
+ - `composing` β€” Agent is composing the response
200
+ - `streaming` β€” Content is being streamed
201
+
202
+ **Error event:**
203
+ ```
204
+ data: {"type": "error", "content": "Something went wrong"}
205
+ ```
206
+
207
+ ## Customization
208
+
209
+ ### Custom Logo
210
+
211
+ ```tsx
212
+ import { MyLogo } from './icons';
213
+
214
+ <ChatPanel
215
+ logoIcon={<MyLogo size={24} />}
216
+ // ...
217
+ />
218
+ ```
219
+
220
+ ### Custom Accent Color
221
+
222
+ ```tsx
223
+ <ChatPanel
224
+ accentColor="#00bcd4"
225
+ // ...
226
+ />
227
+ ```
228
+
229
+ ### Custom Prompt Suggestions
230
+
231
+ ```tsx
232
+ <ChatPanel
233
+ promptSuggestions={[
234
+ 'Help me write a report',
235
+ 'Analyze this data',
236
+ 'Summarize recent activity',
237
+ ]}
238
+ // ...
239
+ />
240
+ ```
241
+
242
+ ### Internationalization
243
+
244
+ ```tsx
245
+ import { useTranslation } from 'react-i18next';
246
+
247
+ function App() {
248
+ const { t } = useTranslation();
249
+
250
+ return (
251
+ <ChatPanel
252
+ t={t}
253
+ // ...
254
+ />
255
+ );
256
+ }
257
+ ```
258
+
259
+ **Translation keys used:**
260
+ - `'Thinking...'`
261
+ - `'Using tools…'`
262
+ - `'Analyzing results…'`
263
+ - `'Composing answer…'`
264
+ - `'Ask a question...'`
265
+ - `'Stop generating'`
266
+ - `'New chat'`
267
+ - `'Switch view'`
268
+ - `'Close'`
269
+ - `'Switch to another agent'`
270
+ - `'Browse agents'`
271
+ - `'Create agent'`
272
+ - `'Reasoning details'`
273
+ - `'tool call'` / `'tool calls'`
274
+ - `'Uses AI. Verify results.'`
275
+ - `'How can I help you, '`
276
+ - `'Suggestions'`
277
+ - `'Floating'`
278
+ - `'Sidebar'`
279
+ - `'Full screen'`
280
+
281
+ ## Styling
282
+
283
+ Import the CSS file to apply default styles:
284
+
285
+ ```tsx
286
+ import '@filigran/chatbot/styles.css';
287
+ ```
288
+
289
+ The component uses Tailwind CSS classes and CSS custom properties for theming. The accent color is applied via `--chat-accent` CSS variable.
290
+
291
+ ## Peer Dependencies
292
+
293
+ - `react` >= 18
294
+ - `react-dom` >= 18
295
+ - `react-markdown` >= 10
296
+ - `remark-gfm` >= 4
297
+
298
+ ---
299
+
300
+ ## Development
301
+
302
+ To develop locally:
198
303
 
199
304
  ```bash
305
+ cd packages/filigran-chatbot
200
306
  yarn dev
201
- # This will serve the test page on http://localhost:5678 automatically
202
307
  ```
203
308
 
204
- 5. Test the chatbot:
309
+ To build:
205
310
 
206
- - Navigate to http://localhost:5678
207
- - The chatbot should now be visible and functional
311
+ ```bash
312
+ yarn build
313
+ ```
314
+
315
+ To publish:
208
316
 
209
- **Note:** The development URL (http://localhost:5678) is automatically added to allowed domains in development mode. You don't need to add it manually.
317
+ ```bash
318
+ yarn publish --access public
319
+ ```
210
320
 
211
- ## License
321
+ Or from the monorepo root:
212
322
 
213
- This project is a fork of [FlowiseEmbedChat](https://github.com/FlowiseAI/FlowiseChatEmbed), originally licensed under the [MIT License](https://github.com/FlowiseAI/Flowise/blob/master/LICENSE.md).
214
- Original code remains under the MIT License.
215
- Modifications and additional code are licensed under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
323
+ ```bash
324
+ yarn publish:filigran-chatbot
325
+ ```
package/base.json CHANGED
@@ -1,21 +1,21 @@
1
1
  {
2
- "$schema": "https://json.schemastore.org/tsconfig",
3
- "display": "Default",
4
- "compilerOptions": {
5
- "composite": false,
6
- "declaration": true,
7
- "declarationMap": true,
8
- "esModuleInterop": true,
9
- "forceConsistentCasingInFileNames": true,
10
- "inlineSources": false,
11
- "isolatedModules": true,
12
- "moduleResolution": "bundler",
13
- "noUnusedLocals": false,
14
- "noUnusedParameters": false,
15
- "preserveWatchOutput": true,
16
- "skipLibCheck": true,
17
- "strict": true,
18
- "downlevelIteration": true
19
- },
20
- "exclude": ["node_modules"]
2
+ "$schema": "https://json.schemastore.org/tsconfig",
3
+ "display": "Default",
4
+ "compilerOptions": {
5
+ "composite": false,
6
+ "declaration": true,
7
+ "declarationMap": true,
8
+ "esModuleInterop": true,
9
+ "forceConsistentCasingInFileNames": true,
10
+ "inlineSources": false,
11
+ "isolatedModules": true,
12
+ "moduleResolution": "bundler",
13
+ "noUnusedLocals": false,
14
+ "noUnusedParameters": false,
15
+ "preserveWatchOutput": true,
16
+ "skipLibCheck": true,
17
+ "strict": true,
18
+ "downlevelIteration": true
19
+ },
20
+ "exclude": ["node_modules"]
21
21
  }