@filigran/chatbot 3.2.2 β 3.3.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 +84 -44
- package/dist/index.d.ts +45 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,6 +7,7 @@ Filigran chat panel β a standalone React + Tailwind chatbot component with SSE
|
|
|
7
7
|
- π **SSE Message Streaming** β Real-time response streaming with status indicators
|
|
8
8
|
- π€ **Multi-Agent Support** β Switch between different AI agents
|
|
9
9
|
- π **File Attachments** β Upload and paste files (PDF, TXT, images)
|
|
10
|
+
- π₯ **Agent-Generated Files** β Renders downloadable file cards from agent output and strips the `[[FILE:id]]` markers from the prose
|
|
10
11
|
- π **Full Markdown** β Tables, code blocks with copy button, lists, blockquotes
|
|
11
12
|
- π¨ **Customizable Theme** β Accent color and logo customization
|
|
12
13
|
- π± **3 Display Modes** β Floating, sidebar (resizable), and fullscreen
|
|
@@ -32,20 +33,9 @@ function App() {
|
|
|
32
33
|
|
|
33
34
|
return (
|
|
34
35
|
<>
|
|
35
|
-
<ChatToggleButton
|
|
36
|
-
isOpen={isOpen}
|
|
37
|
-
onToggle={() => setIsOpen(!isOpen)}
|
|
38
|
-
label="Ask Assistant"
|
|
39
|
-
accentColor="#7b5cff"
|
|
40
|
-
/>
|
|
36
|
+
<ChatToggleButton isOpen={isOpen} onToggle={() => setIsOpen(!isOpen)} label="Ask Assistant" accentColor="#7b5cff" />
|
|
41
37
|
{isOpen && (
|
|
42
|
-
<ChatPanel
|
|
43
|
-
mode={mode}
|
|
44
|
-
onClose={() => setIsOpen(false)}
|
|
45
|
-
onModeChange={setMode}
|
|
46
|
-
apiBaseUrl="/api/assistant"
|
|
47
|
-
user={{ firstName: 'John' }}
|
|
48
|
-
/>
|
|
38
|
+
<ChatPanel mode={mode} onClose={() => setIsOpen(false)} onModeChange={setMode} apiBaseUrl="/api/assistant" user={{ firstName: 'John' }} />
|
|
49
39
|
)}
|
|
50
40
|
</>
|
|
51
41
|
);
|
|
@@ -64,23 +54,23 @@ import { ChatPanel } from '@filigran/chatbot';
|
|
|
64
54
|
|
|
65
55
|
#### Props
|
|
66
56
|
|
|
67
|
-
| Prop
|
|
68
|
-
|
|
69
|
-
| `mode`
|
|
70
|
-
| `onClose`
|
|
71
|
-
| `onModeChange`
|
|
72
|
-
| `apiBaseUrl`
|
|
73
|
-
| `user`
|
|
74
|
-
| `topOffset`
|
|
75
|
-
| `agentDashboardUrl` | `string`
|
|
76
|
-
| `t`
|
|
77
|
-
| `accentColor`
|
|
78
|
-
| `logoIcon`
|
|
79
|
-
| `promptSuggestions` | `string[]`
|
|
80
|
-
| `resizable`
|
|
81
|
-
| `onWidthChange`
|
|
82
|
-
| `onResizeStart`
|
|
83
|
-
| `onResizeEnd`
|
|
57
|
+
| Prop | Type | Default | Description |
|
|
58
|
+
| ------------------- | ----------------------------------------- | ------------ | ---------------------------------------------------------------- |
|
|
59
|
+
| `mode` | `'floating' \| 'sidebar' \| 'fullscreen'` | **required** | Display mode |
|
|
60
|
+
| `onClose` | `() => void` | **required** | Called when close button is clicked |
|
|
61
|
+
| `onModeChange` | `(mode: ChatMode) => void` | **required** | Called when user switches display mode |
|
|
62
|
+
| `apiBaseUrl` | `string` | **required** | Base URL for chat API endpoints |
|
|
63
|
+
| `user` | `{ firstName: string }` | **required** | Current user info |
|
|
64
|
+
| `topOffset` | `number` | `0` | Top offset in pixels (for sidebar/fullscreen with fixed headers) |
|
|
65
|
+
| `agentDashboardUrl` | `string` | β | URL for "Browse agents" / "Create agent" links |
|
|
66
|
+
| `t` | `(key: string) => string` | identity | Translation function for i18n |
|
|
67
|
+
| `accentColor` | `string` | `'#7b5cff'` | Primary accent color (hex) |
|
|
68
|
+
| `logoIcon` | `React.ReactNode` | default icon | Custom logo/icon for the assistant |
|
|
69
|
+
| `promptSuggestions` | `string[]` | default list | Prompt suggestions shown on welcome screen |
|
|
70
|
+
| `resizable` | `boolean` | `false` | Enable drag-to-resize for sidebar mode |
|
|
71
|
+
| `onWidthChange` | `(width: number) => void` | β | Called when sidebar width changes during resize |
|
|
72
|
+
| `onResizeStart` | `() => void` | β | Called when resize drag starts |
|
|
73
|
+
| `onResizeEnd` | `() => void` | β | Called when resize drag ends |
|
|
84
74
|
|
|
85
75
|
#### Resizable Sidebar Example
|
|
86
76
|
|
|
@@ -117,13 +107,13 @@ import { ChatToggleButton } from '@filigran/chatbot';
|
|
|
117
107
|
|
|
118
108
|
#### Props
|
|
119
109
|
|
|
120
|
-
| Prop
|
|
121
|
-
|
|
122
|
-
| `isOpen`
|
|
123
|
-
| `onToggle`
|
|
124
|
-
| `label`
|
|
125
|
-
| `accentColor` | `string`
|
|
126
|
-
| `icon`
|
|
110
|
+
| Prop | Type | Default | Description |
|
|
111
|
+
| ------------- | ----------------- | ------------ | ------------------------------ |
|
|
112
|
+
| `isOpen` | `boolean` | **required** | Whether the chat panel is open |
|
|
113
|
+
| `onToggle` | `() => void` | **required** | Called when button is clicked |
|
|
114
|
+
| `label` | `string` | `'Chat'` | Tooltip/aria label |
|
|
115
|
+
| `accentColor` | `string` | `'#7b5cff'` | Button background color |
|
|
116
|
+
| `icon` | `React.ReactNode` | default icon | Custom icon |
|
|
127
117
|
|
|
128
118
|
## API Contract
|
|
129
119
|
|
|
@@ -150,6 +140,7 @@ Returns available AI agents.
|
|
|
150
140
|
Restores conversation history.
|
|
151
141
|
|
|
152
142
|
**Request:**
|
|
143
|
+
|
|
153
144
|
```json
|
|
154
145
|
{
|
|
155
146
|
"conversation_id": "uuid-here",
|
|
@@ -158,6 +149,7 @@ Restores conversation history.
|
|
|
158
149
|
```
|
|
159
150
|
|
|
160
151
|
**Response:**
|
|
152
|
+
|
|
161
153
|
```json
|
|
162
154
|
{
|
|
163
155
|
"messages": [
|
|
@@ -167,11 +159,32 @@ Restores conversation history.
|
|
|
167
159
|
}
|
|
168
160
|
```
|
|
169
161
|
|
|
162
|
+
Assistant history messages **should echo the same `attachments[]` array** that
|
|
163
|
+
was sent on the original `done` event (see [Agent-generated file attachments](#agent-generated-file-attachments)),
|
|
164
|
+
keyed by `file_id`. The component re-surfaces the download cards on restore,
|
|
165
|
+
so omitting them means download cards silently disappear after a page reload
|
|
166
|
+
even though streaming downloads work:
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"messages": [
|
|
171
|
+
{
|
|
172
|
+
"role": "assistant",
|
|
173
|
+
"content": "Here is your export. [[FILE:0f3a...]]",
|
|
174
|
+
"attachments": [
|
|
175
|
+
{ "file_id": "0f3a...", "filename": "iocs.csv", "type": "csv", "size": 2048, "content_type": "text/csv", "file_tag": "download_file" }
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
170
182
|
### `POST {apiBaseUrl}/chat/messages`
|
|
171
183
|
|
|
172
184
|
Sends a message and streams the response via SSE.
|
|
173
185
|
|
|
174
186
|
**Request:**
|
|
187
|
+
|
|
175
188
|
```json
|
|
176
189
|
{
|
|
177
190
|
"content": "What is the weather?",
|
|
@@ -192,7 +205,35 @@ data: {"type": "stream", "content": "today is sunny."}
|
|
|
192
205
|
data: {"type": "done", "content": "The weather today is sunny.", "conversation_id": "new-uuid", "tool_names": ["search_web"], "tool_call_count": 1, "iterations": 1}
|
|
193
206
|
```
|
|
194
207
|
|
|
208
|
+
#### Agent-generated file attachments
|
|
209
|
+
|
|
210
|
+
When an agent produces a downloadable file, the `done` event carries an `attachments` array and the streamed prose embeds `[[FILE:<file_id>]]` markers. The component strips those markers and renders a download card per attachment:
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
{
|
|
214
|
+
"type": "done",
|
|
215
|
+
"content": "Here is your export. [[FILE:0f3a...]]",
|
|
216
|
+
"conversation_id": "uuid",
|
|
217
|
+
"attachments": [
|
|
218
|
+
{ "file_id": "0f3a...", "filename": "iocs.csv", "type": "csv", "size": 2048, "content_type": "text/csv", "file_tag": "download_file" }
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Each attachment carries only `file_id` + display metadata β **never an absolute download URL**. Clicking a card issues:
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
GET {apiBaseUrl}{apiEndpoints.download ?? '/chat/files'}/{file_id}/download
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
with `credentials: 'include'` and your `requestHeaders`. Point `apiEndpoints.download` at your **own backend proxy** so the download is authenticated by your platform (the proxy mints any upstream token server-side) β the user never authenticates to the upstream chat service directly. Set `apiEndpoints.download` to `null` to disable download cards.
|
|
230
|
+
|
|
231
|
+
The `/chat/files` default applies to REST-style endpoints. In `singleEndpoint` mode there is no per-path routing, so the default is **not** applied β download cards stay disabled unless you set `apiEndpoints.download` explicitly to a proxy route.
|
|
232
|
+
|
|
233
|
+
Download failures (403/404/5xx/network) are reported through the optional `onDownloadError(error, attachment)` callback so the host can surface them via its own notification system (the chatbot has no toast surface of its own).
|
|
234
|
+
|
|
195
235
|
**Status values:**
|
|
236
|
+
|
|
196
237
|
- `thinking` β Agent is processing
|
|
197
238
|
- `tool_start` β Agent is using tools (with `tools` array)
|
|
198
239
|
- `analyzing` β Agent is analyzing tool results
|
|
@@ -200,6 +241,7 @@ data: {"type": "done", "content": "The weather today is sunny.", "conversation_i
|
|
|
200
241
|
- `streaming` β Content is being streamed
|
|
201
242
|
|
|
202
243
|
**Error event:**
|
|
244
|
+
|
|
203
245
|
```
|
|
204
246
|
data: {"type": "error", "content": "Something went wrong"}
|
|
205
247
|
```
|
|
@@ -214,7 +256,7 @@ import { MyLogo } from './icons';
|
|
|
214
256
|
<ChatPanel
|
|
215
257
|
logoIcon={<MyLogo size={24} />}
|
|
216
258
|
// ...
|
|
217
|
-
|
|
259
|
+
/>;
|
|
218
260
|
```
|
|
219
261
|
|
|
220
262
|
### Custom Accent Color
|
|
@@ -230,11 +272,7 @@ import { MyLogo } from './icons';
|
|
|
230
272
|
|
|
231
273
|
```tsx
|
|
232
274
|
<ChatPanel
|
|
233
|
-
promptSuggestions={[
|
|
234
|
-
'Help me write a report',
|
|
235
|
-
'Analyze this data',
|
|
236
|
-
'Summarize recent activity',
|
|
237
|
-
]}
|
|
275
|
+
promptSuggestions={['Help me write a report', 'Analyze this data', 'Summarize recent activity']}
|
|
238
276
|
// ...
|
|
239
277
|
/>
|
|
240
278
|
```
|
|
@@ -246,7 +284,7 @@ import { useTranslation } from 'react-i18next';
|
|
|
246
284
|
|
|
247
285
|
function App() {
|
|
248
286
|
const { t } = useTranslation();
|
|
249
|
-
|
|
287
|
+
|
|
250
288
|
return (
|
|
251
289
|
<ChatPanel
|
|
252
290
|
t={t}
|
|
@@ -257,6 +295,7 @@ function App() {
|
|
|
257
295
|
```
|
|
258
296
|
|
|
259
297
|
**Translation keys used:**
|
|
298
|
+
|
|
260
299
|
- `'Thinking...'`
|
|
261
300
|
- `'Using toolsβ¦'`
|
|
262
301
|
- `'Analyzing resultsβ¦'`
|
|
@@ -270,6 +309,7 @@ function App() {
|
|
|
270
309
|
- `'Browse agents'`
|
|
271
310
|
- `'Create agent'`
|
|
272
311
|
- `'Reasoning details'`
|
|
312
|
+
- `'Download'`
|
|
273
313
|
- `'tool call'` / `'tool calls'`
|
|
274
314
|
- `'Uses AI. Verify results.'`
|
|
275
315
|
- `'How can I help you, '`
|
package/dist/index.d.ts
CHANGED
|
@@ -18,6 +18,20 @@ interface ApiEndpoints {
|
|
|
18
18
|
sessions?: string | null;
|
|
19
19
|
/** Path for uploading files. Default: '/chat/upload'. Set to null to disable file uploads. */
|
|
20
20
|
upload?: string | null;
|
|
21
|
+
/**
|
|
22
|
+
* Base path for downloading agent-generated files. Default: '/chat/files'.
|
|
23
|
+
* The download URL is built as
|
|
24
|
+
* `${apiBaseUrl}${download}/${fileId}/download`, resolved against the
|
|
25
|
+
* host app's own backend proxy. This keeps the download authenticated by
|
|
26
|
+
* the host platform (e.g. OpenCTI / OpenAEV session) β the proxy mints
|
|
27
|
+
* any upstream token server-side, so the user never authenticates to the
|
|
28
|
+
* upstream chat service directly. Set to null to disable download chips.
|
|
29
|
+
*
|
|
30
|
+
* Exception: in `singleEndpoint` mode the `/chat/files` default is NOT
|
|
31
|
+
* applied (there is no per-path routing), so download cards stay disabled
|
|
32
|
+
* unless this path is set explicitly to a proxy route.
|
|
33
|
+
*/
|
|
34
|
+
download?: string | null;
|
|
21
35
|
}
|
|
22
36
|
interface ChatPanelProps {
|
|
23
37
|
mode: ChatMode;
|
|
@@ -51,6 +65,12 @@ interface ChatPanelProps {
|
|
|
51
65
|
disableFileManagement?: boolean;
|
|
52
66
|
/** Called when a relative markdown link is clicked in assistant messages. */
|
|
53
67
|
onRelativeLinkClick?: (href: string) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Called when an agent-generated file download fails (non-2xx response or
|
|
70
|
+
* network error). Lets the host surface the failure through its own
|
|
71
|
+
* notification system (the chatbot has no toast surface of its own).
|
|
72
|
+
*/
|
|
73
|
+
onDownloadError?: (error: unknown, attachment: ChatAttachment) => void;
|
|
54
74
|
/** Maximum number of files attachable in one chat context. Default: 10. */
|
|
55
75
|
maxFileCount?: number;
|
|
56
76
|
/** Maximum total size in bytes for attached files. Default: 50 * 1024 * 1024 (50 MB). */
|
|
@@ -84,10 +104,34 @@ interface ChatMessage {
|
|
|
84
104
|
content: string;
|
|
85
105
|
timestamp: Date;
|
|
86
106
|
files?: ChatFile[];
|
|
107
|
+
/** Agent-generated downloadable files attached to an assistant message. */
|
|
108
|
+
attachments?: ChatAttachment[];
|
|
87
109
|
toolNames?: string[];
|
|
88
110
|
toolCallCount?: number;
|
|
89
111
|
iterations?: number;
|
|
90
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* An agent-generated file produced during a chat turn (via the backend
|
|
115
|
+
* `generate_file` tool / custom-tool `$output_files`). Rendered as a
|
|
116
|
+
* download card in assistant messages.
|
|
117
|
+
*
|
|
118
|
+
* Intentionally carries no absolute URL: the download is resolved against
|
|
119
|
+
* the host app's backend proxy from `fileId` (see `ApiEndpoints.download`)
|
|
120
|
+
* so the user stays authenticated to the host platform only.
|
|
121
|
+
*/
|
|
122
|
+
interface ChatAttachment {
|
|
123
|
+
fileId: string;
|
|
124
|
+
filename: string;
|
|
125
|
+
/** Short extension-style label surfaced under the filename (e.g. "PDF"). */
|
|
126
|
+
type?: string;
|
|
127
|
+
size?: number;
|
|
128
|
+
contentType?: string;
|
|
129
|
+
/**
|
|
130
|
+
* `download_file` β prominent download card (user deliverable).
|
|
131
|
+
* `working_file` β de-emphasized scratch/working artifact chip.
|
|
132
|
+
*/
|
|
133
|
+
fileTag?: 'download_file' | 'working_file';
|
|
134
|
+
}
|
|
91
135
|
interface ChatFile {
|
|
92
136
|
name: string;
|
|
93
137
|
type: string;
|
|
@@ -117,4 +161,4 @@ interface TransferredAgent {
|
|
|
117
161
|
}
|
|
118
162
|
|
|
119
163
|
export { ChatPanel, ChatToggleButton };
|
|
120
|
-
export type { ApiEndpoints, BackendType, ChatFile, ChatMessage, ChatMode, ChatPanelProps, ChatToggleButtonProps, TransferredAgent, XtmAgent };
|
|
164
|
+
export type { ApiEndpoints, BackendType, ChatAttachment, ChatFile, ChatMessage, ChatMode, ChatPanelProps, ChatToggleButtonProps, TransferredAgent, XtmAgent };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{useState as r,useRef as a,useEffect as o,useCallback as s}from"react";import{createPortal as i}from"react-dom";import l from"react-markdown";import c from"remark-gfm";function d(e,t){return`${e}${Math.round(255*t).toString(16).padStart(2,"0")}`}const h=e=>e;function u(e,t){const n=e.event;if("nextAgentFlow"===n){const n=e.data,r=n?.nodeId;return"INPROGRESS"===n?.status&&r&&(t.activeNodeId=r),{action:"noop"}}if("start"===n)return{action:"noop"};if("token"===n){return{action:"stream",content:(e.data??"").replace(/<br\s*\/?>/g,"\n")}}if("agentReasoning"===n){const n=e.data,r=n?.usedTools;return r?.length?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:r.map(e=>e.tool)}):t.hasUsedTools?{action:"status",status:"analyzing"}:{action:"status",status:"thinking"}}if("usedTools"===n){t.hasUsedTools=!0;const n=e.data;return{action:"status",status:"tool_start",tools:Array.isArray(n)?n.map(e=>e.tool):[]}}if("metadata"===n){const t=e.data,n=t?.chatId;return n?{action:"set_chat_id",chatId:n}:{action:"noop"}}return"error"===n?{action:"error",content:e.data||""}:"end"===n?{action:"done",content:""}:{action:"noop"}}function g(e,t){const n=e.type;if("error"===n)return{action:"error",content:e.content||""};if("status"===n){const n=e.status;return"tool_done"===n||"wind_down"===n?{action:"noop"}:"streaming"===n?{action:"status",status:"streaming"}:"thinking_text"===n?{action:"status",status:"thinking_text",thinkingContent:e.content}:"tool_start"===n?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:e.tools}):"thinking"===n&&t.hasUsedTools?{action:"status",status:"analyzing"}:{action:"status",status:n,tools:e.tools}}return"stream"===n?{action:"stream",content:e.content}:"done"===n?{action:"done",content:e.content,conversationId:e.conversation_id,toolNames:e.tool_names,toolCallCount:e.tool_call_count,iterations:e.iterations,transferAgentId:e.transfer_agent_id,transferAgentName:e.transfer_agent_name}:{action:"noop"}}function m(e,t){const n=e.type;if("RUN_STARTED"===n)return{action:"status",status:"thinking"};if("RUN_FINISHED"===n)return{action:"done",content:""};if("RUN_ERROR"===n)return{action:"error",content:e.message||"Unknown error"};if("STEP_STARTED"===n){return{action:"status",status:e.stepName||"thinking"}}if("STEP_FINISHED"===n)return{action:"noop"};if("TEXT_MESSAGE_START"===n)return{action:"status",status:"streaming"};if("TEXT_MESSAGE_CONTENT"===n){const t=e.delta;return t?{action:"stream",content:t}:{action:"noop"}}if("TEXT_MESSAGE_END"===n)return{action:"noop"};if("TEXT_MESSAGE_CHUNK"===n){const t=e.delta;return t?{action:"stream",content:t}:{action:"noop"}}if("TOOL_CALL_START"===n){t.hasUsedTools=!0;const n=e.toolCallName;return{action:"status",status:"tool_start",tools:n?[n]:[]}}if("TOOL_CALL_ARGS"===n)return{action:"noop"};if("TOOL_CALL_END"===n)return{action:"status",status:"analyzing"};if("TOOL_CALL_RESULT"===n)return{action:"noop"};if("TOOL_CALL_CHUNK"===n){const n=e.toolCallName;return n?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:[n]}):{action:"noop"}}return"REASONING_START"===n||"REASONING_MESSAGE_START"===n||"REASONING_MESSAGE_CONTENT"===n||"REASONING_MESSAGE_CHUNK"===n?{action:"status",status:"thinking"}:{action:"noop"}}const p="filigranChatConversationId",w="filigranChatLegacyChatId",f=52428800;function x({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",agentSlug:o,requestHeaders:s,t:i,maxFileCount:l=10,maxTotalSize:c=52428800}){const d="legacy"===n,[h,x]=r([]),[b,k]=r(""),[v,y]=r(!1),[N,C]=r(null),[S,_]=r(()=>"undefined"==typeof window?null:localStorage.getItem(p)),[L,I]=r([]),[z,M]=r(null),[A,T]=r(()=>"undefined"==typeof window?null:localStorage.getItem(w)),E=a(!1),$=a(null),R=a(!1),D=a(S),j=a(null),U=a(new AbortController),W=Number.isFinite(l)&&l>0?Math.floor(l):10,O=Number.isFinite(c)&&c>0?c:f,B=()=>d||t?.singleEndpoint||null===t?.upload?null:`${e}${t?.upload??"/chat/upload"}`,F=e=>{D.current=e,_(e),e?localStorage.setItem(p,e):localStorage.removeItem(p)},P=async n=>{if(D.current)return D.current;if(j.current)return j.current;const r=d||t?.singleEndpoint||null===t?.sessions?null:`${e}${t?.sessions??"/chat/sessions"}`;if(!r)return null;const a=(async()=>{try{const e=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",...s??{}},body:JSON.stringify({agent_slug:n})});if(!e.ok)return null;const t=await e.json(),a=t?.conversation_id??null;return a&&F(a),a}catch{return null}finally{j.current=null}})();return j.current=a,a},H=async(e,t,n)=>{const r=B(),a=new FormData;a.append("conversation_id",t),a.append("file",e,e.name);const o=s?Object.fromEntries(Object.entries(s).filter(([e])=>"content-type"!==e.toLowerCase())):void 0,i=await fetch(r,{method:"POST",headers:o,body:a,signal:n});if(!i.ok)throw new Error(`File upload failed: ${i.status}`);const l=(await i.json()).file_ids??[];if(0===l.length)throw new Error("No file_id returned");return l[0]},G=e=>{if(!e||0===e.length||!B())return;const t=Array.from(e).map(e=>({file:e,tempId:crypto.randomUUID()}));let n=[];I(e=>{const r=e.length,a=e.reduce((e,t)=>e+t.size,0),o=W-r;if(o<=0)return e;let s=O-a;const i=[];for(const e of t.slice(0,o))e.file.size<=s&&(i.push(e),s-=e.file.size);if(0===i.length)return e;n=i;const l=i.map(({file:e,tempId:t})=>({name:e.name,type:e.type,size:e.size,rawFile:e,uploadStatus:"pending",fileId:t}));return[...e,...l]}),setTimeout(()=>{const e=U.current.signal;for(const{file:t,tempId:r}of n)(async()=>{try{const n=await P(o);if(!n)return void I(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e));const a=await H(t,n,e);I(e=>e.map(e=>e.fileId===r?{...e,fileId:a,uploadStatus:"done"}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;I(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e))}})()},0)};return{messages:h,inputValue:b,setInputValue:k,isLoading:v,agentStatus:N,attachedFiles:L,conversationId:S,transferredAgent:z,historyLoadedRef:E,handleFileAdd:G,handlePaste:e=>{const{files:t}=e.clipboardData;t.length>0&&(e.preventDefault(),G(t))},handleSendMessage:async()=>{if(!b.trim()&&0===L.length||v)return;const r=b.trim(),a={id:crypto.randomUUID(),role:"user",content:r,timestamp:new Date,files:L.length>0?[...L]:void 0};x(e=>[...e,a]),k(""),I([]),y(!0),C({status:"thinking"}),R.current=!1;const l=crypto.randomUUID();x(e=>[...e,{id:l,role:"assistant",content:"",timestamp:new Date}]);try{const c=new AbortController;$.current=c;const h=(a.files??[]).filter(e=>"done"===e.uploadStatus&&e.fileId).map(e=>e.fileId),p=function(e,t,n){switch(e){case"legacy":return{question:t,chatId:n.legacyChatId??void 0,streaming:!0};case"ag-ui":return{threadId:n.conversationId??crypto.randomUUID(),runId:crypto.randomUUID(),messages:[{id:crypto.randomUUID(),role:"user",content:t}],tools:[],context:[],state:{},forwardedProps:n.agentSlug?{agentSlug:n.agentSlug}:{}};default:return{content:t,conversation_id:n.conversationId,agent_slug:n.agentSlug}}}(n,r,{legacyChatId:A,conversationId:D.current,agentSlug:o});h.length>0&&(p.file_ids=h),C({status:"thinking"});const f=await fetch(d||t?.singleEndpoint?e:`${e}${t?.messages??"/chat/messages"}`,{method:"POST",headers:{"Content-Type":"application/json",...s??{}},body:JSON.stringify(p),signal:c.signal});if(!f.ok||!f.body)return void x(e=>e.map(e=>e.id===l?{...e,content:i("Unable to connect. Please check the configuration.")}:e));const b=function(e){switch(e){case"legacy":return u;case"ag-ui":return m;default:return g}}(n),k={hasUsedTools:!1,activeNodeId:""},v=f.body.getReader(),y=new TextDecoder;let N="",S="",_=!1;for(;;){const{done:e,value:t}=await v.read();if(e)break;N+=y.decode(t,{stream:!0});const n=N.split("\n");N=n.pop()||"";for(const e of n){const t=e.replace(/\r$/,"");if(!t.startsWith("data:"))continue;const n=t.startsWith("data: ")?t.slice(6):t.slice(5);try{const e=b(JSON.parse(n),k);switch(k.hasUsedTools=k.hasUsedTools||R.current,e.action){case"status":"tool_start"===e.status&&(R.current=!0),"thinking_text"===e.status?C(t=>({...t,status:t?.status??"thinking",thinkingContent:(t?.thinkingContent??"")+(e.thinkingContent??"")})):C(t=>({status:e.status,tools:e.tools,thinkingContent:t?.thinkingContent}));break;case"stream":S+=e.content,C(e=>({status:"streaming",thinkingContent:e?.thinkingContent})),x(e=>e.map(e=>e.id===l?{...e,content:S}:e));break;case"done":_=!0,e.conversationId&&F(e.conversationId),e.transferAgentId&&e.transferAgentName&&M({id:e.transferAgentId,name:e.transferAgentName}),x(t=>t.map(t=>t.id===l?{...t,content:e.content||S,toolNames:e.toolNames,toolCallCount:e.toolCallCount,iterations:e.iterations}:t));break;case"error":return void x(t=>t.map(t=>t.id===l?{...t,content:e.content||i("Unable to connect. Please check the configuration.")}:t));case"set_chat_id":T(e.chatId),localStorage.setItem(w,e.chatId)}R.current=k.hasUsedTools}catch{}}}S&&!_&&x(e=>e.map(e=>e.id===l?{...e,content:S||"No response."}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;x(e=>e.map(e=>e.id===l?{...e,content:i("Sorry, an error occurred. Please try again.")}:e))}finally{$.current=null,y(!1),C(null),R.current=!1}},handleNewChat:()=>{$.current?.abort(),$.current=null,U.current.abort(),U.current=new AbortController,j.current=null,x([]),k(""),I([]),y(!1),C(null),M(null),R.current=!1,E.current=!1,d?(T(null),localStorage.removeItem(w)):F(null)},handleStopGenerating:()=>{$.current?.abort(),$.current=null,y(!1),C(null),R.current=!1,x(e=>e.filter(e=>!("assistant"===e.role&&!e.content)))},setAttachedFiles:I,setMessages:x,setConversationId:_}}const b="filigranChatAgentSlug";const k=400,v="filigranChatSidebarWidth";const y=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),N=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"}),e("path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"}),e("path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4"}),e("path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375"}),e("path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5"}),e("path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396"}),e("path",{d:"M19.938 10.5a4 4 0 0 1 .585.396"}),e("path",{d:"M6 18a4 4 0 0 1-1.967-.516"}),e("path",{d:"M19.967 17.484A4 4 0 0 1 18 18"})]}),C=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"M20 6 9 17l-5-5"})}),S=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"m6 9 6 6 6-6"})}),_=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M18 6 6 18"}),e("path",{d:"m6 6 12 12"})]}),L=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}),e("path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"})]}),I=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),e("path",{d:"M3 12A9 3 0 0 0 21 12"})]}),z=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",className:t,children:e("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"})}),M=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M12 20h9"}),e("path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z"})]}),A=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M15 3h6v6"}),e("path",{d:"M10 14 21 3"}),e("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]}),T=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),E=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M11 13H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h7"}),e("rect",{width:"12",height:"12",x:"10",y:"10",rx:"2"})]}),$=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),e("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),e("path",{d:"M3 16h3a2 2 0 0 0 2 2v3"}),e("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]}),R=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),e("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),e("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),e("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]}),D=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),e("path",{d:"M2 12h20"})]}),j=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 16v-4"}),e("path",{d:"M12 8h.01"})]}),U=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),e("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),W=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("circle",{cx:"11",cy:"11",r:"8"}),e("path",{d:"m21 21-4.3-4.3"})]}),O=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"m22 2-7 20-4-9-9-4Z"}),e("path",{d:"m22 2-11 11"})]}),B=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),e("path",{d:"M15 3v18"})]}),F=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"})}),P=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("rect",{width:"6",height:"6",x:"9",y:"9"})]}),H=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("polyline",{points:"4 17 10 11 4 5"}),e("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]}),G=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e("circle",{cx:"9",cy:"7",r:"4"}),e("line",{x1:"19",x2:"19",y1:"8",y2:"14"}),e("line",{x1:"22",x2:"16",y1:"11",y2:"11"})]}),V=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})});const q=({open:t,onClose:n,anchorRef:l,placement:c="bottom-start",width:d=280,children:h})=>{const u=a(null),[g,m]=r({top:0,left:0});if(function(e,t,n=!0){o(()=>{if(!n)return;const r=n=>{e.current&&!e.current.contains(n.target)&&t()};return document.addEventListener("mousedown",r),document.addEventListener("touchstart",r),()=>{document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r)}},[e,t,n])}(u,s(()=>n(),[n]),t),o(()=>{if(!t||!l.current)return;const e=l.current.getBoundingClientRect(),n="bottom-end"===c?e.right-d:e.left;m({top:e.bottom+4,left:n})},[t,l,c,d]),!t)return null;const p=function(e){let t=e;for(;t;){if(t.classList.contains("filigran-chatbot"))return t;t=t.parentElement}return document.body}(l.current);return i(e("div",{ref:u,className:"fixed z-[10000] rounded-[10px] overflow-hidden border border-gray-200 dark:border-white/10 bg-white dark:bg-[#2a2a3e] shadow-xl",style:{top:g.top,left:g.left,width:d},children:h}),p)},Z=({size:t=16,className:n=""})=>e("div",{className:`animate-spin rounded-full border-2 border-current/20 border-t-[var(--chat-accent)] ${n}`,style:{width:t,height:t}});function K(e){let t=e;for(;t;){if(t.classList.contains("filigran-chatbot"))return t;t=t.parentElement}return document.body}const X=({title:n,children:o})=>{const s=a(null),[l,c]=r(!1),[d,h]=r({top:0,left:0});if(!n)return o;return t("span",{ref:s,className:"inline-flex",onMouseEnter:()=>{if(!s.current)return;const e=s.current.getBoundingClientRect();h({top:e.top-4,left:e.left+e.width/2}),c(!0)},onMouseLeave:()=>c(!1),children:[o,l&&i(e("span",{className:"pointer-events-none fixed z-[10001] -translate-x-1/2 -translate-y-full whitespace-nowrap rounded-md bg-gray-900 dark:bg-gray-100 px-2 py-1 text-xs text-white dark:text-gray-900 shadow-lg",style:{top:d.top,left:d.left},role:"tooltip",children:n}),K(s.current))]})},J=[{mode:"floating",label:"Floating",getIcon:t=>e(E,{...t})},{mode:"sidebar",label:"Sidebar",getIcon:t=>e(B,{...t})},{mode:"fullscreen",label:"Full screen",getIcon:t=>e(R,{...t})}],Q=({mode:n,agentName:r,agents:o,selectedAgent:s,transferredFrom:i,agentMenuOpen:l,onAgentMenuToggle:c,onAgentMenuClose:d,onSwitchAgent:h,modeMenuOpen:u,onModeMenuToggle:g,onModeMenuClose:m,onModeChange:p,onNewChat:w,onClose:f,logoIcon:x,agentDashboardUrl:b,t:k})=>{const v=a(null),y=a(null),N="sidebar"===n?B:"fullscreen"===n?$:E;return t("div",{className:"flex items-center px-3 py-2 min-h-[48px] border-b border-gray-200 dark:border-white/10 bg-gradient-to-br from-[var(--chat-accent-dark)]/[0.13] to-[var(--chat-accent)]/[0.07] "+("floating"===n?"rounded-t-xl":""),children:[t("div",{className:"min-w-0",children:[t("button",{ref:v,type:"button",onClick:c,className:"flex items-center gap-1.5 text-sm font-semibold text-gray-900 dark:text-white px-2 py-1 rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e("span",{className:"flex items-center text-[var(--chat-accent)] [&>svg]:w-[18px] [&>svg]:h-[18px]",children:x}),e("span",{children:r}),e(S,{size:16,className:"text-gray-400 dark:text-white/30"})]}),i&&t("div",{className:"pl-10 pr-2 text-[0.6rem] font-normal text-gray-400 dark:text-white/30",children:[k("Transferred from")," ",i]})]}),t(q,{open:l,onClose:d,anchorRef:v,width:280,children:[e("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:k("Switch to another agent")}),0===o.length&&e("div",{className:"px-4 py-2",children:e(Z,{size:16})}),e("div",{children:o.map(n=>t("button",{type:"button",onClick:()=>h(n),className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(n.id===s?.id?"bg-[var(--chat-accent)]/10":""),children:[e("div",{className:"w-7 h-7 rounded-full flex items-center justify-center shrink-0 bg-gradient-to-br from-[var(--chat-accent)]/20 to-[var(--chat-accent)]/5",children:e("span",{className:"text-[var(--chat-accent)] [&>svg]:w-4 [&>svg]:h-4",children:x})}),t("div",{className:"min-w-0",children:[e("div",{className:"text-[0.8125rem] font-medium text-gray-900 dark:text-white truncate",children:n.name}),n.description&&e("div",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 truncate",children:n.description})]})]},n.id))}),e("div",{className:"h-px bg-gray-200 dark:bg-white/10 mx-2"}),t("div",{children:[b&&t("button",{type:"button",onClick:()=>{d(),window.open(`${b}/agents`,"_blank")},className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e(A,{size:18,className:"text-gray-400 dark:text-white/40 shrink-0"}),e("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:k("Browse agents")})]}),b&&t("button",{type:"button",onClick:()=>{d(),window.open(`${b}/agents/new`,"_blank")},className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e(G,{size:18,className:"text-gray-400 dark:text-white/40 shrink-0"}),e("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:k("Create agent")})]})]})]}),e("div",{className:"flex-1"}),e(X,{title:k("New chat"),children:e("button",{type:"button",onClick:w,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:e(M,{size:18})})}),e(X,{title:k("Switch view"),children:e("button",{ref:y,type:"button",onClick:g,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:e(N,{size:18})})}),t(q,{open:u,onClose:m,anchorRef:y,placement:"bottom-end",width:180,children:[e("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:k("Switch to")}),e("div",{className:"pb-1",children:J.map(r=>t("button",{type:"button",onClick:()=>{p(r.mode),m()},className:"w-full flex items-center gap-3 px-4 py-1 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(n===r.mode?"bg-[var(--chat-accent)]/10":""),children:[r.getIcon({size:18,className:"text-gray-400 dark:text-white/40"}),e("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:k(r.label)})]},r.mode))})]}),e(X,{title:k("Close"),children:e("button",{type:"button",onClick:f,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:e(_,{size:18})})})]})},Y=({inputValue:r,onInputChange:o,onSend:s,onStop:i,isLoading:l,attachedFiles:c=[],onFileAdd:d,onFileRemove:h,onPaste:u,t:g,mode:m,separatorColor:p})=>{const w=a(null),f=a(null),x=Boolean(d&&h&&u),b=r.trim()||x&&c.length>0,k=x&&c.some(e=>"pending"===e.uploadStatus),v=b&&!k;return t("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-white/10 "+("floating"===m?"rounded-b-xl":""),style:p?{borderTopColor:p,borderTopWidth:1}:void 0,children:[x&&c.length>0&&e("div",{className:"flex gap-1.5 flex-wrap mb-2",children:c.map((n,r)=>t("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border text-[0.7rem] "+("error"===n.uploadStatus?"border-red-300 dark:border-red-500/30 text-red-500 dark:text-red-400":"pending"===n.uploadStatus?"border-gray-200 dark:border-white/10 text-gray-400 dark:text-white/40":"border-gray-200 dark:border-white/10 text-gray-600 dark:text-white/60"),children:["pending"===n.uploadStatus?e("span",{className:"w-3.5 h-3.5 border border-current/30 border-t-current rounded-full animate-spin"}):e(T,{size:14}),n.name,"error"===n.uploadStatus&&e("span",{className:"text-red-400 text-[0.6rem]",children:"β"}),e("button",{type:"button",onClick:()=>h?.(r),className:"ml-0.5 text-gray-400 dark:text-white/30 hover:text-gray-600 dark:hover:text-white/60",children:"Γ"})]},r))}),t("div",{className:"flex items-center border border-gray-200 dark:border-white/10 rounded-xl px-2 py-1 transition-colors focus-within:border-[var(--chat-accent)]",children:[x&&t(n,{children:[e("input",{ref:w,type:"file",multiple:!0,hidden:!0,onChange:e=>{d?.(e.target.files),e.target.value=""}}),e("button",{type:"button",onClick:()=>w.current?.click(),className:"w-8 h-8 flex items-center justify-center shrink-0 rounded-lg text-gray-400 dark:text-white/30 hover:bg-gray-100 dark:hover:bg-white/10 mr-0.5 transition-colors",children:e(y,{size:18})})]}),e("textarea",{ref:f,placeholder:g("Ask a question..."),value:r,onChange:e=>{o(e.target.value);const t=e.target;t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,120)}px`},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),s())},onPaste:u,rows:1,className:"flex-1 bg-transparent border-none outline-hidden resize-none text-[0.8125rem] py-1.5 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-white/30 filigran-chat-scrollable",style:{maxHeight:120}}),e(X,{title:l?g("Stop generating"):k?g("Files uploading..."):"",children:e("button",{type:"button",onClick:l?i:s,disabled:!l&&!v,className:"p-1.5 rounded-lg w-8 h-8 flex items-center justify-center transition-all duration-150 "+(l?"text-red-500 bg-red-500/10 hover:bg-red-500/20":v?"text-[var(--chat-accent)] bg-[var(--chat-accent)]/10 hover:bg-[var(--chat-accent)]/20":"text-gray-300 dark:text-white/20 cursor-not-allowed"),children:e(l?P:O,{size:18})})})]}),e("p",{className:"text-center text-[0.65rem] text-gray-400 dark:text-white/30 mt-1.5 opacity-70",children:g("Uses AI. Verify results.")})]})};function ee({content:n}){const r=a(null),s=n.replace(/```[\s\S]*?```/g," ").replace(/`([^`]+)`/g,"$1").replace(/\*\*(.+?)\*\*/g,"$1").replace(/__(.+?)__/g,"$1").replace(/\*(.+?)\*/g,"$1").replace(/_(.+?)_/g,"$1").replace(/#{1,6}\s+/g,"").replace(/[*\->]+/g," ").replace(/\s+/g," ").trim();return o(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},[s]),s.length<3?null:t("div",{ref:r,className:"ml-11 max-w-[70%] max-h-20 overflow-hidden relative rounded-md border-l-2 bg-[var(--chat-accent)]/[0.03] pl-3 pr-3 py-2",style:{animation:"reasoningGlow 3s ease-in-out infinite, chat-fade-in 0.5s ease-out"},children:[e("p",{className:"text-[13px] leading-[1.35rem] text-gray-400 dark:text-white/40 break-words m-0",children:s}),e("div",{className:"absolute inset-x-0 bottom-0 h-5 bg-gradient-to-t from-white/90 dark:from-[#1e1e2e]/90 to-transparent pointer-events-none"})]})}const te=({agentStatus:r,logoIcon:a,t:o})=>{const{label:s,StatusIcon:i,showDots:l}=function(e,t){if(!e)return{label:t("Thinking..."),StatusIcon:N,showDots:!1};switch(e.status){case"tool_start":{const n=e.tools??[],r=n.map(e=>e.toLowerCase());if(r.some(e=>"spawn_background_task"===e)){const e=n.filter(e=>"spawn_background_task"===e).length;return{label:e>1?`${t("Delegating")} ${e} ${t("tasks")}β¦`:`${t("Delegating task")}β¦`,StatusIcon:G,showDots:!1}}if(r.some(e=>"check_task_status"===e)){const e=n.filter(e=>"check_task_status"===e).length,r=e>1?`${e} ${t("background tasks")}`:t("background task");return{label:`${t("Waiting for")} ${r}β¦`,StatusIcon:F,showDots:!1}}if(r.some(e=>"get_task_result"===e)){const e=n.filter(e=>"get_task_result"===e).length,r=e>1?`${e} ${t("tasks")}`:t("task");return{label:`${t("Collecting results from")} ${r}β¦`,StatusIcon:F,showDots:!1}}let a,o=V;if(r.some(e=>e.includes("search")||e.includes("list"))?o=W:r.some(e=>e.includes("read")||e.includes("get")||e.includes("query"))?o=I:r.some(e=>e.includes("send")||e.includes("create")||e.includes("draft")||e.includes("reply")||e.includes("flag"))?o=U:r.some(e=>e.includes("code")||e.includes("execute"))?o=H:r.some(e=>e.includes("web")||e.includes("browse"))&&(o=D),n.length>0){const e=n.map(e=>e.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())),t=Array.from(new Set(e));a=1===t.length?`${t[0]}β¦`:`${t[0]} (+${t.length-1} more)β¦`}else a=t("Using toolsβ¦");return{label:a,StatusIcon:o,showDots:!1}}case"analyzing":return{label:t("Analyzing resultsβ¦"),StatusIcon:F,showDots:!1};case"composing":return{label:t("Composing answerβ¦"),StatusIcon:N,showDots:!0};case"consulting":{const n=e.tools?.[0]??"agent";return{label:`${t("Consulting")} ${n}β¦`,StatusIcon:G,showDots:!1}}case"delegating":{const n=e.tools?.filter(e=>"spawn_background_task"===e).length??0;return{label:n>1?`${t("Delegating")} ${n} ${t("tasks")}β¦`:`${t("Delegating task")}β¦`,StatusIcon:G,showDots:!1}}case"polling":{const n=e.tools?.filter(e=>"check_task_status"===e).length??0,r=n>1?`${n} ${t("background tasks")}`:t("background task");return{label:`${t("Waiting for")} ${r}β¦`,StatusIcon:F,showDots:!1}}case"collecting":{const n=e.tools?.filter(e=>"get_task_result"===e).length??0,r=n>1?`${n} ${t("tasks")}`:t("task");return{label:`${t("Collecting results from")} ${r}β¦`,StatusIcon:F,showDots:!1}}case"transferring":{const n=e.tools?.[0]??"agent";return{label:`${t("Transferring to")} ${n}β¦`,StatusIcon:A,showDots:!1}}default:return{label:t("Thinking..."),StatusIcon:N,showDots:!1}}}(r,o),c=r?.thinkingContent;return t(n,{children:[t("div",{className:"flex gap-3 items-center justify-start",children:[e("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-[var(--chat-accent)]/15 to-[var(--chat-accent)]/5",children:e("span",{className:"text-[var(--chat-accent)] [&>svg]:w-4 [&>svg]:h-4",children:a})}),t("div",{className:"rounded-lg bg-gray-50 dark:bg-white/[0.03] px-4 py-3 relative overflow-hidden",children:[e("div",{className:"absolute inset-0 bg-gradient-to-r from-[var(--chat-accent)]/[0.03] via-transparent to-[var(--chat-accent)]/[0.03] animate-pulse pointer-events-none"}),t("div",{className:"relative flex items-center gap-2.5",children:[l?e("div",{className:"flex gap-[3px] items-center h-3.5 w-3.5 justify-center",children:[0,.15,.3].map((t,n)=>e("span",{className:"h-[5px] w-[5px] rounded-full bg-[var(--chat-accent)]/50",style:{animation:`chat-dot 1s ease-in-out infinite ${t}s`}},n))}):e(i,{size:14,className:"text-[var(--chat-accent)] animate-pulse transition-all duration-300"}),e("span",{className:"text-sm text-gray-500 dark:text-white/50 transition-all duration-300",children:s})]})]})]}),c&&e(ee,{content:c})]})},ne=e=>{if(!e)return!1;if(e.startsWith("//"))return!1;return!/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(e)},re=({content:n,onRelativeLinkClick:a})=>{const[o,s]=r(null);return e(l,{remarkPlugins:[c],components:{p:({children:t})=>e("p",{className:"mb-3 last:mb-0 leading-7 break-words text-[0.8125rem] text-gray-900 dark:text-white/90",children:t}),code:({className:n,children:r})=>{const a=/language-(\w+)/.exec(n||""),i=String(r).replace(/\n$/,"");return a?t("div",{className:"my-3 rounded-lg border border-gray-200 dark:border-white/10 overflow-hidden bg-gray-50 dark:bg-white/[0.03]",children:[t("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-gray-200 dark:border-white/10 bg-gray-100 dark:bg-white/[0.03]",children:[e("span",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 font-mono",children:a[1]}),e("button",{type:"button",onClick:()=>{return e=i,navigator.clipboard.writeText(e),s(e),void setTimeout(()=>s(null),2e3);var e},className:"p-0.5 rounded-sm hover:bg-gray-200 dark:hover:bg-white/10 transition-colors",children:o===i?e(C,{size:14,className:"text-green-500"}):e(L,{size:14,className:"text-gray-400 dark:text-white/40"})})]}),e("pre",{className:"m-0 px-3 py-2 overflow-x-auto",children:e("code",{className:"font-mono text-xs leading-[1.7] text-gray-800 dark:text-white/90 whitespace-pre",children:i})})]}):e("code",{className:"bg-gray-100 dark:bg-white/[0.08] px-1.5 py-0.5 rounded-sm font-mono text-xs text-[var(--chat-accent)]",children:r})},ul:({children:t})=>e("ul",{className:"pl-5 mb-3 text-[0.8125rem] text-gray-900 dark:text-white/90 [&_li]:mb-1 marker:text-[var(--chat-accent)]/50",children:t}),ol:({children:t})=>e("ol",{className:"pl-5 mb-3 text-[0.8125rem] text-gray-900 dark:text-white/90 [&_li]:mb-1 marker:text-[var(--chat-accent)]/50",children:t}),blockquote:({children:t})=>e("blockquote",{className:"my-3 border-l-2 border-[var(--chat-accent)]/30 bg-[var(--chat-accent)]/[0.03] pl-4 pr-3 py-2 rounded-r-md italic text-gray-500 dark:text-white/60",children:t}),a:({href:t,children:n})=>{const r=!ne(t);return e("a",{href:t,onClick:e=>{t&&ne(t)&&a&&(e.preventDefault(),a(t))},target:r?"_blank":void 0,rel:r?"noopener noreferrer":void 0,className:"text-[var(--chat-accent)] underline underline-offset-2 hover:brightness-125",children:n})},h1:({children:t})=>e("h1",{className:"mt-4 first:mt-0 mb-2 font-bold text-base text-gray-900 dark:text-white",children:t}),h2:({children:t})=>e("h2",{className:"mt-3 first:mt-0 mb-2 font-bold text-[0.9rem] text-gray-900 dark:text-white",children:t}),h3:({children:t})=>e("h3",{className:"mt-3 first:mt-0 mb-1.5 font-semibold text-[0.85rem] text-gray-900 dark:text-white",children:t}),table:({children:t})=>e("div",{className:"my-3 overflow-x-auto rounded-lg border border-gray-200 dark:border-white/10",children:e("table",{className:"w-full border-collapse text-xs",children:t})}),th:({children:t})=>e("th",{className:"px-3 py-2 text-left font-semibold bg-gray-50 dark:bg-white/[0.04] border-b border-gray-200 dark:border-white/10 text-gray-900 dark:text-white",children:t}),td:({children:t})=>e("td",{className:"px-3 py-2 border-b border-gray-200 dark:border-white/10 text-gray-700 dark:text-white/80",children:t})},children:n})},ae=({messages:s,isLoading:i,agentStatus:l,agentName:c,logoIcon:d,onRelativeLinkClick:h,t:u})=>{const g=a(null),[m,p]=r(null);return o(()=>{g.current?.scrollIntoView({behavior:"smooth"})},[s]),t("div",{className:"flex-1 overflow-y-auto px-4 py-3 flex flex-col gap-4 filigran-chat-scrollable",children:[s.map(r=>{const a="assistant"===r.role,o=!r.content;return a&&o&&i?e("div",{children:e(te,{agentStatus:l,logoIcon:d,t:u})},r.id):t("div",{className:"flex flex-col "+(a?"items-start":"items-end"),children:[a&&t("div",{className:"flex items-center gap-1.5 mb-1",children:[e("div",{className:"w-6 h-6 rounded-lg flex items-center justify-center bg-gradient-to-br from-[var(--chat-accent)]/20 to-[var(--chat-accent)]/5",children:e("span",{className:"text-[var(--chat-accent)] [&>svg]:w-3 [&>svg]:h-3",children:d})}),e("span",{className:"font-semibold text-xs text-gray-900 dark:text-white",children:c})]}),a&&!o&&i&&l?.thinkingContent&&e(ee,{content:l.thinkingContent}),r.files&&r.files.length>0&&e("div",{className:"flex gap-1.5 flex-wrap mb-1.5",children:r.files.map((n,r)=>t("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border border-gray-200 dark:border-white/10 text-[0.7rem] text-gray-600 dark:text-white/60",children:[e(T,{size:14}),n.name]},r))}),t("div",{className:"max-w-[90%] "+(a?"pl-1 py-1 text-[0.8125rem] leading-7":"px-3.5 py-2 rounded-[14px_14px_4px_14px] bg-[var(--chat-accent-dark)] text-white text-[0.8125rem] leading-6"),children:[a?e(re,{content:r.content,onRelativeLinkClick:h}):r.content,a&&o&&!i&&e("span",{className:"text-[0.8125rem] text-gray-400 dark:text-white/40 italic",children:"..."}),a&&!o&&i&&e("span",{className:"inline-block w-1.5 h-4 bg-[var(--chat-accent)]/70 rounded-xs ml-0.5 animate-pulse align-text-bottom"})]}),a&&!o&&!i&&r.toolNames&&r.toolNames.length>0&&t(n,{children:[e("button",{type:"button",onClick:()=>p(m===r.id?null:r.id),className:"mt-0.5 p-1 rounded-lg opacity-50 hover:opacity-100 hover:text-[var(--chat-accent)] transition-opacity",title:u("Reasoning details"),children:e(j,{size:14})}),m===r.id&&t("div",{className:"mt-1.5 p-3 rounded-lg bg-gray-50 dark:bg-white/[0.04] border border-gray-200 dark:border-white/10",children:[t("p",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 mb-1.5",children:[r.iterations&&r.iterations>1?`${r.iterations} iterations Β· `:"",r.toolCallCount??r.toolNames.length," ",1===(r.toolCallCount??r.toolNames.length)?u("tool call"):u("tool calls")]}),e("div",{className:"flex flex-wrap gap-1",children:Array.from(new Set(r.toolNames)).map(t=>e("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full border border-gray-200 dark:border-white/10 text-[0.68rem] font-mono text-gray-500 dark:text-white/40",children:t.replace(/_/g," ")},t))})]})]})]},r.id)}),e("div",{ref:g})]})},oe=({firstName:n,logoIcon:r,promptSuggestions:a,onPromptClick:o,t:s})=>t("div",{className:"flex-1 flex flex-col items-center justify-center px-6 pb-8",children:[e("span",{className:"text-[var(--chat-accent)] mb-4 [&>svg]:w-12 [&>svg]:h-12 drop-shadow-[0_0_12px_var(--chat-accent-40)]",children:r}),t("h2",{className:"text-xl font-medium mb-6 text-center text-gray-900 dark:text-white",style:{fontFamily:'"Geologica", sans-serif'},children:[s("How can I help you, "),n,"?"]}),t("div",{className:"w-full max-w-[320px]",children:[e("span",{className:"block text-center mb-2 text-[0.65rem] tracking-[1.5px] uppercase text-[var(--chat-accent)] font-semibold",children:s("Suggestions")}),a.map(t=>e("button",{type:"button",onClick:()=>o(t),className:"w-full text-left text-[0.8125rem] text-gray-800 dark:text-white py-1.5 px-3 mb-1 rounded-lg border border-gray-200 dark:border-white/10 bg-transparent transition-colors hover:bg-[var(--chat-accent-10)] hover:border-[var(--chat-accent-50)]",children:s(t)},t))]})]}),se=["Help me create a new simulation scenario","What are the latest attack patterns?","How do I configure detection rules?","Summarize my recent findings"],ie=({mode:n,onClose:s,onModeChange:i,topOffset:l=0,apiBaseUrl:c,apiEndpoints:u,agentDashboardUrl:g,user:m,t:p=h,accentColor:w="#7b5cff",logoIcon:f,promptSuggestions:y=se,draftBorderColor:N,resizable:C=!1,onWidthChange:S,onResizeStart:_,onResizeEnd:L,disableFileManagement:I=!1,onRelativeLinkClick:M,maxFileCount:A,maxTotalSize:T,requestHeaders:E,pushContentSelector:$,backendType:R="rest"})=>{const[D,j]=r(!1),{agents:U,selectedAgent:W,agentMenuOpen:O,setAgentMenuOpen:B,handleSwitchAgent:F}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[s,i]=r([]),[l,c]=r(null),[d,h]=r(!1);return o(()=>{null===t?.agents||t?.singleEndpoint||"legacy"===n||fetch(`${e}${t?.agents??"/chat/agents"}`,{headers:a}).then(e=>e.ok?e.json():[]).then(e=>{if(i(e),e.length>0&&!l){const t=localStorage.getItem(b),n=t?e.find(e=>e.slug===t):null;c(n||e[0])}}).catch(()=>{})},[e,t,n,a]),{agents:s,selectedAgent:l,setSelectedAgent:c,agentMenuOpen:d,setAgentMenuOpen:h,handleSwitchAgent:(e,t)=>{e.id!==l?.id?(c(e),e.slug&&localStorage.setItem(b,e.slug),h(!1),t?.()):h(!1)}}}({apiBaseUrl:c,apiEndpoints:u,backendType:R,requestHeaders:E}),{messages:P,inputValue:H,setInputValue:G,isLoading:V,agentStatus:q,attachedFiles:Z,conversationId:K,transferredAgent:X,historyLoadedRef:J,handleFileAdd:ee,handlePaste:te,handleSendMessage:ne,handleNewChat:re,handleStopGenerating:ie,setAttachedFiles:le,setMessages:ce,setConversationId:de}=x({apiBaseUrl:c,apiEndpoints:u,backendType:R,agentSlug:W?.slug,requestHeaders:E,t:p,maxFileCount:A,maxTotalSize:T}),{sidebarWidth:he,handleResizeStart:ue,defaultWidth:ge,isResizing:me}=function({mode:e,resizable:t,onWidthChange:n,onResizeStart:s,onResizeEnd:i}){const[l,c]=r(()=>{if("undefined"==typeof window)return k;const e=localStorage.getItem(v);if(e){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=k)return t}return k}),[d,h]=r(!1),u=a(!1),g=a(l);g.current=l;const m=a(n);m.current=n;const p=a(i);return p.current=i,o(()=>{"sidebar"===e&&t&&m.current?.(g.current)},[e,t]),o(()=>{if("sidebar"!==e||!t)return;const n=e=>{if(!u.current)return;e.preventDefault();const t=window.innerWidth-e.clientX,n=.4*window.innerWidth,r=Math.min(Math.max(t,k),n);c(r),g.current=r,m.current?.(r)},r=()=>{u.current&&(u.current=!1,h(!1),document.body.style.cursor="",document.body.style.userSelect="",localStorage.setItem(v,String(g.current)),p.current?.())},a=()=>{const e=.4*window.innerWidth;if(g.current>e){const t=Math.max(e,k);c(t),g.current=t,m.current?.(t)}};return document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),window.addEventListener("resize",a),()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),window.removeEventListener("resize",a)}},[e,t]),{sidebarWidth:l,handleResizeStart:e=>{e.preventDefault(),u.current=!0,h(!0),document.body.style.cursor="col-resize",document.body.style.userSelect="none",s?.()},defaultWidth:k,isResizing:d}}({mode:n,resizable:C,onWidthChange:S,onResizeStart:_,onResizeEnd:L});o(()=>{const e="sidebar"===n?C?he:ge:0,t=e>0?e+6:0;if(document.documentElement.style.setProperty("--chatbot-sidebar-width",`${t}px`),document.documentElement.style.setProperty("--chatbot-transition",me?"none":"all 225ms cubic-bezier(0.4, 0, 0.2, 1)"),$){const e=document.querySelector($);if(e){const n=e.style.paddingRight,r=e.style.transition;return e.style.paddingRight=t>0?`${t}px`:"",e.style.transition=me?"none":"padding-right 225ms cubic-bezier(0.4, 0, 0.2, 1)",()=>{e.style.paddingRight=n,e.style.transition=r,document.documentElement.style.setProperty("--chatbot-sidebar-width","0px")}}}return()=>{document.documentElement.style.setProperty("--chatbot-sidebar-width","0px")}},[$,n,he,ge,C,me]);const pe=f??e(z,{size:24}),we=m.firstName,fe=X?.name||W?.name||"Assistant",xe={"--chat-accent":w,"--chat-accent-10":d(w,.1),"--chat-accent-40":d(w,.25),"--chat-accent-50":d(w,.5),"--chat-accent-dark":w};o(()=>{if(null===u?.sessions||u?.singleEndpoint||"legacy"===R||"ag-ui"===R)return;if(!K||J.current||!W)return;J.current=!0;const e=()=>{de(null),localStorage.removeItem("filigranChatConversationId")};fetch(`${c}${u?.sessions??"/chat/sessions"}`,{method:"POST",headers:{"Content-Type":"application/json",...E??{}},body:JSON.stringify({conversation_id:K,agent_slug:W.slug})}).then(t=>t.ok?t.json():(e(),null)).then(e=>{if(!e?.messages?.length)return;const t=e.messages.map((e,t)=>({id:`restored-${t}`,role:e.role,content:e.content,timestamp:new Date}));ce(t)}).catch(()=>{e()})},[K,W,c,u,J,E,ce,de]);const be=(()=>{const e="filigran-chatbot";switch(n){case"sidebar":return`${e} fixed right-0 bottom-0 flex flex-col bg-white dark:bg-[#1e1e2e] border-l border-gray-200 dark:border-white/10 z-[1200]`;case"floating":return`${e} fixed bottom-5 right-5 flex flex-col bg-white dark:bg-[#1e1e2e] rounded-xl shadow-[0_8px_32px_rgba(0,0,0,0.15)] dark:shadow-[0_8px_32px_rgba(0,0,0,0.4)] z-[1300] border border-gray-200 dark:border-white/10`;case"fullscreen":return`${e} fixed right-0 bottom-0 left-0 flex flex-col bg-gray-50 dark:bg-[#161622] z-[1400]`;default:return e}})(),ke={...xe,..."sidebar"===n?{top:l,width:C?he:ge}:"floating"===n?{width:380,height:560}:{top:l}};return t("div",{className:be,style:ke,children:["sidebar"===n&&C&&e("div",{onMouseDown:ue,className:"absolute top-0 -left-1 bottom-0 w-2 cursor-col-resize z-10 group",children:e("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 bottom-0 w-0.5 rounded-sm bg-[var(--chat-accent)] opacity-0 transition-opacity group-hover:opacity-100 group-active:opacity-100"})}),e(Q,{mode:n,agentName:fe,agents:U,selectedAgent:W,transferredFrom:X?W?.name:void 0,agentMenuOpen:O,onAgentMenuToggle:()=>B(e=>!e),onAgentMenuClose:()=>B(!1),onSwitchAgent:e=>{e&&F(e,()=>{re()})},modeMenuOpen:D,onModeMenuToggle:()=>j(e=>!e),onModeMenuClose:()=>j(!1),onModeChange:i,onNewChat:re,onClose:s,logoIcon:pe,agentDashboardUrl:g,t:p}),0===P.length?e(oe,{firstName:we,logoIcon:pe,promptSuggestions:y,onPromptClick:G,t:p}):e(ae,{messages:P,isLoading:V,agentStatus:q,agentName:fe,logoIcon:pe,onRelativeLinkClick:M,t:p}),e(Y,{inputValue:H,onInputChange:G,onSend:ne,onStop:ie,isLoading:V,attachedFiles:I?[]:Z,onFileAdd:I?void 0:ee,onFileRemove:I?void 0:e=>le(t=>t.filter((t,n)=>n!==e)),onPaste:I?void 0:te,t:p,mode:n,separatorColor:N})]})},le=({isOpen:n,onToggle:r,label:a="Ask Assistant",accentColor:o="#7b5cff",icon:s})=>{const i=s??e(z,{size:16});return t("button",{type:"button",onClick:r,className:"filigran-chatbot inline-flex items-center gap-1.5 px-3 py-[3px] text-[0.8125rem] font-medium whitespace-nowrap rounded-md border transition-colors",style:{borderColor:n?o:d(o,.5),color:o,backgroundColor:n?d(o,.1):"transparent"},onMouseEnter:e=>{e.currentTarget.style.borderColor=o,e.currentTarget.style.backgroundColor=d(o,.1)},onMouseLeave:e=>{e.currentTarget.style.borderColor=n?o:d(o,.5),e.currentTarget.style.backgroundColor=n?d(o,.1):"transparent"},children:[e("span",{className:"[&>svg]:w-4 [&>svg]:h-4",children:i}),a]})};export{ie as ChatPanel,le as ChatToggleButton};
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{useState as r,useRef as a,useEffect as o,useCallback as s}from"react";import{createPortal as i}from"react-dom";import l from"react-markdown";import c from"remark-gfm";function d(e,t){return`${e}${Math.round(255*t).toString(16).padStart(2,"0")}`}const h=e=>e,u=/\[\[FILE(?::[^\]]*)?\]?$/;function g(e){if(!Array.isArray(e))return;const t=[];for(const n of e){if(!n||"object"!=typeof n)continue;const e=n,r=e.file_id;"string"==typeof r&&r&&t.push({fileId:r,filename:"string"==typeof e.filename?e.filename:"file",type:"string"==typeof e.type?e.type:void 0,size:"number"==typeof e.size?e.size:void 0,contentType:"string"==typeof e.content_type?e.content_type:void 0,fileTag:"working_file"===e.file_tag?"working_file":"download_file"})}return t.length>0?t:void 0}function m(e,t){const n=e.type;if("error"===n)return{action:"error",content:e.content||""};if("status"===n){const n=e.status;return"tool_done"===n||"wind_down"===n?{action:"noop"}:"streaming"===n?{action:"status",status:"streaming"}:"thinking_text"===n?{action:"status",status:"thinking_text",thinkingContent:e.content}:"tool_start"===n?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:e.tools}):"thinking"===n&&t.hasUsedTools?{action:"status",status:"analyzing"}:{action:"status",status:n,tools:e.tools}}return"stream"===n?{action:"stream",content:e.content}:"done"===n?{action:"done",content:e.content,conversationId:e.conversation_id,toolNames:e.tool_names,toolCallCount:e.tool_call_count,iterations:e.iterations,transferAgentId:e.transfer_agent_id,transferAgentName:e.transfer_agent_name,attachments:g(e.attachments)}:{action:"noop"}}function p(e,t){const n=e.event;if("nextAgentFlow"===n){const n=e.data,r=n?.nodeId;return"INPROGRESS"===n?.status&&r&&(t.activeNodeId=r),{action:"noop"}}if("start"===n)return{action:"noop"};if("token"===n){return{action:"stream",content:(e.data??"").replace(/<br\s*\/?>/g,"\n")}}if("agentReasoning"===n){const n=e.data,r=n?.usedTools;return r?.length?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:r.map(e=>e.tool)}):t.hasUsedTools?{action:"status",status:"analyzing"}:{action:"status",status:"thinking"}}if("usedTools"===n){t.hasUsedTools=!0;const n=e.data;return{action:"status",status:"tool_start",tools:Array.isArray(n)?n.map(e=>e.tool):[]}}if("metadata"===n){const t=e.data,n=t?.chatId;return n?{action:"set_chat_id",chatId:n}:{action:"noop"}}return"error"===n?{action:"error",content:e.data||""}:"end"===n?{action:"done",content:""}:{action:"noop"}}function f(e,t){const n=e.type;if("RUN_STARTED"===n)return{action:"status",status:"thinking"};if("RUN_FINISHED"===n)return{action:"done",content:""};if("RUN_ERROR"===n)return{action:"error",content:e.message||"Unknown error"};if("STEP_STARTED"===n){return{action:"status",status:e.stepName||"thinking"}}if("STEP_FINISHED"===n)return{action:"noop"};if("TEXT_MESSAGE_START"===n)return{action:"status",status:"streaming"};if("TEXT_MESSAGE_CONTENT"===n){const t=e.delta;return t?{action:"stream",content:t}:{action:"noop"}}if("TEXT_MESSAGE_END"===n)return{action:"noop"};if("TEXT_MESSAGE_CHUNK"===n){const t=e.delta;return t?{action:"stream",content:t}:{action:"noop"}}if("TOOL_CALL_START"===n){t.hasUsedTools=!0;const n=e.toolCallName;return{action:"status",status:"tool_start",tools:n?[n]:[]}}if("TOOL_CALL_ARGS"===n)return{action:"noop"};if("TOOL_CALL_END"===n)return{action:"status",status:"analyzing"};if("TOOL_CALL_RESULT"===n)return{action:"noop"};if("TOOL_CALL_CHUNK"===n){const n=e.toolCallName;return n?(t.hasUsedTools=!0,{action:"status",status:"tool_start",tools:[n]}):{action:"noop"}}return"REASONING_START"===n||"REASONING_MESSAGE_START"===n||"REASONING_MESSAGE_CONTENT"===n||"REASONING_MESSAGE_CHUNK"===n?{action:"status",status:"thinking"}:{action:"noop"}}const w="filigranChatConversationId",x="filigranChatLegacyChatId",b=52428800;function k({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",agentSlug:o,requestHeaders:s,t:i,maxFileCount:l=10,maxTotalSize:c=52428800}){const d="legacy"===n,[h,u]=r([]),[g,k]=r(""),[v,y]=r(!1),[N,C]=r(null),[S,_]=r(()=>"undefined"==typeof window?null:localStorage.getItem(w)),[I,L]=r([]),[z,M]=r(null),[A,T]=r(()=>"undefined"==typeof window?null:localStorage.getItem(x)),E=a(!1),$=a(null),R=a(!1),D=a(S),j=a(null),U=a(new AbortController),W=Number.isFinite(l)&&l>0?Math.floor(l):10,O=Number.isFinite(c)&&c>0?c:b,B=()=>d||t?.singleEndpoint||null===t?.upload?null:`${e}${t?.upload??"/chat/upload"}`,F=e=>{D.current=e,_(e),e?localStorage.setItem(w,e):localStorage.removeItem(w)},H=async n=>{if(D.current)return D.current;if(j.current)return j.current;const r=d||t?.singleEndpoint||null===t?.sessions?null:`${e}${t?.sessions??"/chat/sessions"}`;if(!r)return null;const a=(async()=>{try{const e=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json",...s??{}},body:JSON.stringify({agent_slug:n})});if(!e.ok)return null;const t=await e.json(),a=t?.conversation_id??null;return a&&F(a),a}catch{return null}finally{j.current=null}})();return j.current=a,a},P=async(e,t,n)=>{const r=B(),a=new FormData;a.append("conversation_id",t),a.append("file",e,e.name);const o=s?Object.fromEntries(Object.entries(s).filter(([e])=>"content-type"!==e.toLowerCase())):void 0,i=await fetch(r,{method:"POST",headers:o,body:a,signal:n});if(!i.ok)throw new Error(`File upload failed: ${i.status}`);const l=(await i.json()).file_ids??[];if(0===l.length)throw new Error("No file_id returned");return l[0]},G=e=>{if(!e||0===e.length||!B())return;const t=Array.from(e).map(e=>({file:e,tempId:crypto.randomUUID()}));let n=[];L(e=>{const r=e.length,a=e.reduce((e,t)=>e+t.size,0),o=W-r;if(o<=0)return e;let s=O-a;const i=[];for(const e of t.slice(0,o))e.file.size<=s&&(i.push(e),s-=e.file.size);if(0===i.length)return e;n=i;const l=i.map(({file:e,tempId:t})=>({name:e.name,type:e.type,size:e.size,rawFile:e,uploadStatus:"pending",fileId:t}));return[...e,...l]}),setTimeout(()=>{const e=U.current.signal;for(const{file:t,tempId:r}of n)(async()=>{try{const n=await H(o);if(!n)return void L(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e));const a=await P(t,n,e);L(e=>e.map(e=>e.fileId===r?{...e,fileId:a,uploadStatus:"done"}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;L(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e))}})()},0)};return{messages:h,inputValue:g,setInputValue:k,isLoading:v,agentStatus:N,attachedFiles:I,conversationId:S,transferredAgent:z,historyLoadedRef:E,handleFileAdd:G,handlePaste:e=>{const{files:t}=e.clipboardData;t.length>0&&(e.preventDefault(),G(t))},handleSendMessage:async()=>{if(!g.trim()&&0===I.length||v)return;const r=g.trim(),a={id:crypto.randomUUID(),role:"user",content:r,timestamp:new Date,files:I.length>0?[...I]:void 0};u(e=>[...e,a]),k(""),L([]),y(!0),C({status:"thinking"}),R.current=!1;const l=crypto.randomUUID();u(e=>[...e,{id:l,role:"assistant",content:"",timestamp:new Date}]);try{const c=new AbortController;$.current=c;const h=(a.files??[]).filter(e=>"done"===e.uploadStatus&&e.fileId).map(e=>e.fileId),g=function(e,t,n){switch(e){case"legacy":return{question:t,chatId:n.legacyChatId??void 0,streaming:!0};case"ag-ui":return{threadId:n.conversationId??crypto.randomUUID(),runId:crypto.randomUUID(),messages:[{id:crypto.randomUUID(),role:"user",content:t}],tools:[],context:[],state:{},forwardedProps:n.agentSlug?{agentSlug:n.agentSlug}:{}};default:return{content:t,conversation_id:n.conversationId,agent_slug:n.agentSlug}}}(n,r,{legacyChatId:A,conversationId:D.current,agentSlug:o});h.length>0&&(g.file_ids=h),C({status:"thinking"});const w=await fetch(d||t?.singleEndpoint?e:`${e}${t?.messages??"/chat/messages"}`,{method:"POST",headers:{"Content-Type":"application/json",...s??{}},body:JSON.stringify(g),signal:c.signal});if(!w.ok||!w.body)return void u(e=>e.map(e=>e.id===l?{...e,content:i("Unable to connect. Please check the configuration.")}:e));const b=function(e){switch(e){case"legacy":return p;case"ag-ui":return f;default:return m}}(n),k={hasUsedTools:!1,activeNodeId:""},v=w.body.getReader(),y=new TextDecoder;let N="",S="",_=!1;for(;;){const{done:e,value:t}=await v.read();if(e)break;N+=y.decode(t,{stream:!0});const n=N.split("\n");N=n.pop()||"";for(const e of n){const t=e.replace(/\r$/,"");if(!t.startsWith("data:"))continue;const n=t.startsWith("data: ")?t.slice(6):t.slice(5);try{const e=b(JSON.parse(n),k);switch(k.hasUsedTools=k.hasUsedTools||R.current,e.action){case"status":"tool_start"===e.status&&(R.current=!0),"thinking_text"===e.status?C(t=>({...t,status:t?.status??"thinking",thinkingContent:(t?.thinkingContent??"")+(e.thinkingContent??"")})):C(t=>({status:e.status,tools:e.tools,thinkingContent:t?.thinkingContent}));break;case"stream":S+=e.content,C(e=>({status:"streaming",thinkingContent:e?.thinkingContent})),u(e=>e.map(e=>e.id===l?{...e,content:S}:e));break;case"done":_=!0,e.conversationId&&F(e.conversationId),e.transferAgentId&&e.transferAgentName&&M({id:e.transferAgentId,name:e.transferAgentName}),u(t=>t.map(t=>t.id===l?{...t,content:e.content||S,toolNames:e.toolNames,toolCallCount:e.toolCallCount,iterations:e.iterations,attachments:e.attachments}:t));break;case"error":return void u(t=>t.map(t=>t.id===l?{...t,content:e.content||i("Unable to connect. Please check the configuration.")}:t));case"set_chat_id":T(e.chatId),localStorage.setItem(x,e.chatId)}R.current=k.hasUsedTools}catch{}}}S&&!_&&u(e=>e.map(e=>e.id===l?{...e,content:S||"No response."}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;u(e=>e.map(e=>e.id===l?{...e,content:i("Sorry, an error occurred. Please try again.")}:e))}finally{$.current=null,y(!1),C(null),R.current=!1}},handleNewChat:()=>{$.current?.abort(),$.current=null,U.current.abort(),U.current=new AbortController,j.current=null,u([]),k(""),L([]),y(!1),C(null),M(null),R.current=!1,E.current=!1,d?(T(null),localStorage.removeItem(x)):F(null)},handleStopGenerating:()=>{$.current?.abort(),$.current=null,y(!1),C(null),R.current=!1,u(e=>e.filter(e=>!("assistant"===e.role&&!e.content)))},setAttachedFiles:L,setMessages:u,setConversationId:_}}const v="filigranChatAgentSlug";const y=400,N="filigranChatSidebarWidth";const C=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"m21.44 11.05-9.19 9.19a6 6 0 0 1-8.49-8.49l8.57-8.57A4 4 0 1 1 18 8.84l-8.59 8.57a2 2 0 0 1-2.83-2.83l8.49-8.48"})}),S=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M12 5a3 3 0 1 0-5.997.125 4 4 0 0 0-2.526 5.77 4 4 0 0 0 .556 6.588A4 4 0 1 0 12 18Z"}),e("path",{d:"M12 5a3 3 0 1 1 5.997.125 4 4 0 0 1 2.526 5.77 4 4 0 0 1-.556 6.588A4 4 0 1 1 12 18Z"}),e("path",{d:"M15 13a4.5 4.5 0 0 1-3-4 4.5 4.5 0 0 1-3 4"}),e("path",{d:"M17.599 6.5a3 3 0 0 0 .399-1.375"}),e("path",{d:"M6.003 5.125A3 3 0 0 0 6.401 6.5"}),e("path",{d:"M3.477 10.896a4 4 0 0 1 .585-.396"}),e("path",{d:"M19.938 10.5a4 4 0 0 1 .585.396"}),e("path",{d:"M6 18a4 4 0 0 1-1.967-.516"}),e("path",{d:"M19.967 17.484A4 4 0 0 1 18 18"})]}),_=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"M20 6 9 17l-5-5"})}),I=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"m6 9 6 6 6-6"})}),L=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M18 6 6 18"}),e("path",{d:"m6 6 12 12"})]}),z=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2"}),e("path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"})]}),M=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("ellipse",{cx:"12",cy:"5",rx:"9",ry:"3"}),e("path",{d:"M3 5V19A9 3 0 0 0 21 19V5"}),e("path",{d:"M3 12A9 3 0 0 0 21 12"})]}),A=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"currentColor",stroke:"none",className:t,children:e("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"})}),T=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e("polyline",{points:"7 10 12 15 17 10"}),e("line",{x1:"12",x2:"12",y1:"15",y2:"3"})]}),E=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M12 20h9"}),e("path",{d:"M16.376 3.622a1 1 0 0 1 3.002 3.002L7.368 18.635a2 2 0 0 1-.855.506l-2.872.838a.5.5 0 0 1-.62-.62l.838-2.872a2 2 0 0 1 .506-.854z"})]}),$=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M15 3h6v6"}),e("path",{d:"M10 14 21 3"}),e("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"})]}),R=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]}),D=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M11 13H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h7"}),e("rect",{width:"12",height:"12",x:"10",y:"10",rx:"2"})]}),j=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),e("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),e("path",{d:"M3 16h3a2 2 0 0 0 2 2v3"}),e("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]}),U=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M8 3H5a2 2 0 0 0-2 2v3"}),e("path",{d:"M21 8V5a2 2 0 0 0-2-2h-3"}),e("path",{d:"M3 16v3a2 2 0 0 0 2 2h3"}),e("path",{d:"M16 21h3a2 2 0 0 0 2-2v-3"})]}),W=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20"}),e("path",{d:"M2 12h20"})]}),O=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 16v-4"}),e("path",{d:"M12 8h.01"})]}),B=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("rect",{width:"20",height:"16",x:"2",y:"4",rx:"2"}),e("path",{d:"m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"})]}),F=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("circle",{cx:"11",cy:"11",r:"8"}),e("path",{d:"m21 21-4.3-4.3"})]}),H=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"m22 2-7 20-4-9-9-4Z"}),e("path",{d:"m22 2-11 11"})]}),P=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),e("path",{d:"M15 3v18"})]}),G=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"})}),V=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("circle",{cx:"12",cy:"12",r:"10"}),e("rect",{width:"6",height:"6",x:"9",y:"9"})]}),q=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("polyline",{points:"4 17 10 11 4 5"}),e("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]}),K=({className:n,size:r=24})=>t("svg",{xmlns:"http://www.w3.org/2000/svg",width:r,height:r,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:n,children:[e("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),e("circle",{cx:"9",cy:"7",r:"4"}),e("line",{x1:"19",x2:"19",y1:"8",y2:"14"}),e("line",{x1:"22",x2:"16",y1:"11",y2:"11"})]}),Z=({className:t,size:n=24})=>e("svg",{xmlns:"http://www.w3.org/2000/svg",width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",className:t,children:e("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})});const X=({open:t,onClose:n,anchorRef:l,placement:c="bottom-start",width:d=280,children:h})=>{const u=a(null),[g,m]=r({top:0,left:0});if(function(e,t,n=!0){o(()=>{if(!n)return;const r=n=>{e.current&&!e.current.contains(n.target)&&t()};return document.addEventListener("mousedown",r),document.addEventListener("touchstart",r),()=>{document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r)}},[e,t,n])}(u,s(()=>n(),[n]),t),o(()=>{if(!t||!l.current)return;const e=l.current.getBoundingClientRect(),n="bottom-end"===c?e.right-d:e.left;m({top:e.bottom+4,left:n})},[t,l,c,d]),!t)return null;const p=function(e){let t=e;for(;t;){if(t.classList.contains("filigran-chatbot"))return t;t=t.parentElement}return document.body}(l.current);return i(e("div",{ref:u,className:"fixed z-[10000] rounded-[10px] overflow-hidden border border-gray-200 dark:border-white/10 bg-white dark:bg-[#2a2a3e] shadow-xl",style:{top:g.top,left:g.left,width:d},children:h}),p)},J=({size:t=16,className:n=""})=>e("div",{className:`animate-spin rounded-full border-2 border-current/20 border-t-[var(--chat-accent)] ${n}`,style:{width:t,height:t}});function Q(e){let t=e;for(;t;){if(t.classList.contains("filigran-chatbot"))return t;t=t.parentElement}return document.body}const Y=({title:n,children:o})=>{const s=a(null),[l,c]=r(!1),[d,h]=r({top:0,left:0});if(!n)return o;return t("span",{ref:s,className:"inline-flex",onMouseEnter:()=>{if(!s.current)return;const e=s.current.getBoundingClientRect();h({top:e.top-4,left:e.left+e.width/2}),c(!0)},onMouseLeave:()=>c(!1),children:[o,l&&i(e("span",{className:"pointer-events-none fixed z-[10001] -translate-x-1/2 -translate-y-full whitespace-nowrap rounded-md bg-gray-900 dark:bg-gray-100 px-2 py-1 text-xs text-white dark:text-gray-900 shadow-lg",style:{top:d.top,left:d.left},role:"tooltip",children:n}),Q(s.current))]})},ee=[{mode:"floating",label:"Floating",getIcon:t=>e(D,{...t})},{mode:"sidebar",label:"Sidebar",getIcon:t=>e(P,{...t})},{mode:"fullscreen",label:"Full screen",getIcon:t=>e(U,{...t})}],te=({mode:n,agentName:r,agents:o,selectedAgent:s,transferredFrom:i,agentMenuOpen:l,onAgentMenuToggle:c,onAgentMenuClose:d,onSwitchAgent:h,modeMenuOpen:u,onModeMenuToggle:g,onModeMenuClose:m,onModeChange:p,onNewChat:f,onClose:w,logoIcon:x,agentDashboardUrl:b,t:k})=>{const v=a(null),y=a(null),N="sidebar"===n?P:"fullscreen"===n?j:D;return t("div",{className:"flex items-center px-3 py-2 min-h-[48px] border-b border-gray-200 dark:border-white/10 bg-gradient-to-br from-[var(--chat-accent-dark)]/[0.13] to-[var(--chat-accent)]/[0.07] "+("floating"===n?"rounded-t-xl":""),children:[t("div",{className:"min-w-0",children:[t("button",{ref:v,type:"button",onClick:c,className:"flex items-center gap-1.5 text-sm font-semibold text-gray-900 dark:text-white px-2 py-1 rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e("span",{className:"flex items-center text-[var(--chat-accent)] [&>svg]:w-[18px] [&>svg]:h-[18px]",children:x}),e("span",{children:r}),e(I,{size:16,className:"text-gray-400 dark:text-white/30"})]}),i&&t("div",{className:"pl-10 pr-2 text-[0.6rem] font-normal text-gray-400 dark:text-white/30",children:[k("Transferred from")," ",i]})]}),t(X,{open:l,onClose:d,anchorRef:v,width:280,children:[e("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:k("Switch to another agent")}),0===o.length&&e("div",{className:"px-4 py-2",children:e(J,{size:16})}),e("div",{children:o.map(n=>t("button",{type:"button",onClick:()=>h(n),className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(n.id===s?.id?"bg-[var(--chat-accent)]/10":""),children:[e("div",{className:"w-7 h-7 rounded-full flex items-center justify-center shrink-0 bg-gradient-to-br from-[var(--chat-accent)]/20 to-[var(--chat-accent)]/5",children:e("span",{className:"text-[var(--chat-accent)] [&>svg]:w-4 [&>svg]:h-4",children:x})}),t("div",{className:"min-w-0",children:[e("div",{className:"text-[0.8125rem] font-medium text-gray-900 dark:text-white truncate",children:n.name}),n.description&&e("div",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 truncate",children:n.description})]})]},n.id))}),e("div",{className:"h-px bg-gray-200 dark:bg-white/10 mx-2"}),t("div",{children:[b&&t("button",{type:"button",onClick:()=>{d(),window.open(`${b}/agents`,"_blank")},className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e($,{size:18,className:"text-gray-400 dark:text-white/40 shrink-0"}),e("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:k("Browse agents")})]}),b&&t("button",{type:"button",onClick:()=>{d(),window.open(`${b}/agents/new`,"_blank")},className:"w-full flex items-center gap-2 px-4 py-1.5 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e(K,{size:18,className:"text-gray-400 dark:text-white/40 shrink-0"}),e("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:k("Create agent")})]})]})]}),e("div",{className:"flex-1"}),e(Y,{title:k("New chat"),children:e("button",{type:"button",onClick:f,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:e(E,{size:18})})}),e(Y,{title:k("Switch view"),children:e("button",{ref:y,type:"button",onClick:g,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:e(N,{size:18})})}),t(X,{open:u,onClose:m,anchorRef:y,placement:"bottom-end",width:180,children:[e("span",{className:"block px-4 pt-3 pb-1 text-[0.68rem] tracking-[1px] uppercase text-gray-400 dark:text-white/40",children:k("Switch to")}),e("div",{className:"pb-1",children:ee.map(r=>t("button",{type:"button",onClick:()=>{p(r.mode),m()},className:"w-full flex items-center gap-3 px-4 py-1 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(n===r.mode?"bg-[var(--chat-accent)]/10":""),children:[r.getIcon({size:18,className:"text-gray-400 dark:text-white/40"}),e("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:k(r.label)})]},r.mode))})]}),e(Y,{title:k("Close"),children:e("button",{type:"button",onClick:w,className:"w-8 h-8 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-500 dark:text-white/40 hover:text-gray-700 dark:hover:text-white/70 transition-colors",children:e(L,{size:18})})})]})},ne=({inputValue:r,onInputChange:o,onSend:s,onStop:i,isLoading:l,attachedFiles:c=[],onFileAdd:d,onFileRemove:h,onPaste:u,t:g,mode:m,separatorColor:p})=>{const f=a(null),w=a(null),x=Boolean(d&&h&&u),b=r.trim()||x&&c.length>0,k=x&&c.some(e=>"pending"===e.uploadStatus),v=b&&!k;return t("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-white/10 "+("floating"===m?"rounded-b-xl":""),style:p?{borderTopColor:p,borderTopWidth:1}:void 0,children:[x&&c.length>0&&e("div",{className:"flex gap-1.5 flex-wrap mb-2",children:c.map((n,r)=>t("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border text-[0.7rem] "+("error"===n.uploadStatus?"border-red-300 dark:border-red-500/30 text-red-500 dark:text-red-400":"pending"===n.uploadStatus?"border-gray-200 dark:border-white/10 text-gray-400 dark:text-white/40":"border-gray-200 dark:border-white/10 text-gray-600 dark:text-white/60"),children:["pending"===n.uploadStatus?e("span",{className:"w-3.5 h-3.5 border border-current/30 border-t-current rounded-full animate-spin"}):e(R,{size:14}),n.name,"error"===n.uploadStatus&&e("span",{className:"text-red-400 text-[0.6rem]",children:"β"}),e("button",{type:"button",onClick:()=>h?.(r),className:"ml-0.5 text-gray-400 dark:text-white/30 hover:text-gray-600 dark:hover:text-white/60",children:"Γ"})]},r))}),t("div",{className:"flex items-center border border-gray-200 dark:border-white/10 rounded-xl px-2 py-1 transition-colors focus-within:border-[var(--chat-accent)]",children:[x&&t(n,{children:[e("input",{ref:f,type:"file",multiple:!0,hidden:!0,onChange:e=>{d?.(e.target.files),e.target.value=""}}),e("button",{type:"button",onClick:()=>f.current?.click(),className:"w-8 h-8 flex items-center justify-center shrink-0 rounded-lg text-gray-400 dark:text-white/30 hover:bg-gray-100 dark:hover:bg-white/10 mr-0.5 transition-colors",children:e(C,{size:18})})]}),e("textarea",{ref:w,placeholder:g("Ask a question..."),value:r,onChange:e=>{o(e.target.value);const t=e.target;t.style.height="auto",t.style.height=`${Math.min(t.scrollHeight,120)}px`},onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),s())},onPaste:u,rows:1,className:"flex-1 bg-transparent border-none outline-hidden resize-none text-[0.8125rem] py-1.5 text-gray-900 dark:text-white placeholder:text-gray-400 dark:placeholder:text-white/30 filigran-chat-scrollable",style:{maxHeight:120}}),e(Y,{title:l?g("Stop generating"):k?g("Files uploading..."):"",children:e("button",{type:"button",onClick:l?i:s,disabled:!l&&!v,className:"p-1.5 rounded-lg w-8 h-8 flex items-center justify-center transition-all duration-150 "+(l?"text-red-500 bg-red-500/10 hover:bg-red-500/20":v?"text-[var(--chat-accent)] bg-[var(--chat-accent)]/10 hover:bg-[var(--chat-accent)]/20":"text-gray-300 dark:text-white/20 cursor-not-allowed"),children:e(l?V:H,{size:18})})})]}),e("p",{className:"text-center text-[0.65rem] text-gray-400 dark:text-white/30 mt-1.5 opacity-70",children:g("Uses AI. Verify results.")})]})};function re({content:n}){const r=a(null),s=n.replace(/```[\s\S]*?```/g," ").replace(/`([^`]+)`/g,"$1").replace(/\*\*(.+?)\*\*/g,"$1").replace(/__(.+?)__/g,"$1").replace(/\*(.+?)\*/g,"$1").replace(/_(.+?)_/g,"$1").replace(/#{1,6}\s+/g,"").replace(/[*\->]+/g," ").replace(/\s+/g," ").trim();return o(()=>{r.current&&(r.current.scrollTop=r.current.scrollHeight)},[s]),s.length<3?null:t("div",{ref:r,className:"ml-11 max-w-[70%] max-h-20 overflow-hidden relative rounded-md border-l-2 bg-[var(--chat-accent)]/[0.03] pl-3 pr-3 py-2",style:{animation:"reasoningGlow 3s ease-in-out infinite, chat-fade-in 0.5s ease-out"},children:[e("p",{className:"text-[13px] leading-[1.35rem] text-gray-400 dark:text-white/40 break-words m-0",children:s}),e("div",{className:"absolute inset-x-0 bottom-0 h-5 bg-gradient-to-t from-white/90 dark:from-[#1e1e2e]/90 to-transparent pointer-events-none"})]})}const ae=({agentStatus:r,logoIcon:a,t:o})=>{const{label:s,StatusIcon:i,showDots:l}=function(e,t){if(!e)return{label:t("Thinking..."),StatusIcon:S,showDots:!1};switch(e.status){case"tool_start":{const n=e.tools??[],r=n.map(e=>e.toLowerCase());if(r.some(e=>"spawn_background_task"===e)){const e=n.filter(e=>"spawn_background_task"===e).length;return{label:e>1?`${t("Delegating")} ${e} ${t("tasks")}β¦`:`${t("Delegating task")}β¦`,StatusIcon:K,showDots:!1}}if(r.some(e=>"check_task_status"===e)){const e=n.filter(e=>"check_task_status"===e).length,r=e>1?`${e} ${t("background tasks")}`:t("background task");return{label:`${t("Waiting for")} ${r}β¦`,StatusIcon:G,showDots:!1}}if(r.some(e=>"get_task_result"===e)){const e=n.filter(e=>"get_task_result"===e).length,r=e>1?`${e} ${t("tasks")}`:t("task");return{label:`${t("Collecting results from")} ${r}β¦`,StatusIcon:G,showDots:!1}}let a,o=Z;if(r.some(e=>e.includes("search")||e.includes("list"))?o=F:r.some(e=>e.includes("read")||e.includes("get")||e.includes("query"))?o=M:r.some(e=>e.includes("send")||e.includes("create")||e.includes("draft")||e.includes("reply")||e.includes("flag"))?o=B:r.some(e=>e.includes("code")||e.includes("execute"))?o=q:r.some(e=>e.includes("web")||e.includes("browse"))&&(o=W),n.length>0){const e=n.map(e=>e.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase())),t=Array.from(new Set(e));a=1===t.length?`${t[0]}β¦`:`${t[0]} (+${t.length-1} more)β¦`}else a=t("Using toolsβ¦");return{label:a,StatusIcon:o,showDots:!1}}case"analyzing":return{label:t("Analyzing resultsβ¦"),StatusIcon:G,showDots:!1};case"composing":return{label:t("Composing answerβ¦"),StatusIcon:S,showDots:!0};case"consulting":{const n=e.tools?.[0]??"agent";return{label:`${t("Consulting")} ${n}β¦`,StatusIcon:K,showDots:!1}}case"delegating":{const n=e.tools?.filter(e=>"spawn_background_task"===e).length??0;return{label:n>1?`${t("Delegating")} ${n} ${t("tasks")}β¦`:`${t("Delegating task")}β¦`,StatusIcon:K,showDots:!1}}case"polling":{const n=e.tools?.filter(e=>"check_task_status"===e).length??0,r=n>1?`${n} ${t("background tasks")}`:t("background task");return{label:`${t("Waiting for")} ${r}β¦`,StatusIcon:G,showDots:!1}}case"collecting":{const n=e.tools?.filter(e=>"get_task_result"===e).length??0,r=n>1?`${n} ${t("tasks")}`:t("task");return{label:`${t("Collecting results from")} ${r}β¦`,StatusIcon:G,showDots:!1}}case"transferring":{const n=e.tools?.[0]??"agent";return{label:`${t("Transferring to")} ${n}β¦`,StatusIcon:$,showDots:!1}}default:return{label:t("Thinking..."),StatusIcon:S,showDots:!1}}}(r,o),c=r?.thinkingContent;return t(n,{children:[t("div",{className:"flex gap-3 items-center justify-start",children:[e("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-gradient-to-br from-[var(--chat-accent)]/15 to-[var(--chat-accent)]/5",children:e("span",{className:"text-[var(--chat-accent)] [&>svg]:w-4 [&>svg]:h-4",children:a})}),t("div",{className:"rounded-lg bg-gray-50 dark:bg-white/[0.03] px-4 py-3 relative overflow-hidden",children:[e("div",{className:"absolute inset-0 bg-gradient-to-r from-[var(--chat-accent)]/[0.03] via-transparent to-[var(--chat-accent)]/[0.03] animate-pulse pointer-events-none"}),t("div",{className:"relative flex items-center gap-2.5",children:[l?e("div",{className:"flex gap-[3px] items-center h-3.5 w-3.5 justify-center",children:[0,.15,.3].map((t,n)=>e("span",{className:"h-[5px] w-[5px] rounded-full bg-[var(--chat-accent)]/50",style:{animation:`chat-dot 1s ease-in-out infinite ${t}s`}},n))}):e(i,{size:14,className:"text-[var(--chat-accent)] animate-pulse transition-all duration-300"}),e("span",{className:"text-sm text-gray-500 dark:text-white/50 transition-all duration-300",children:s})]})]})]}),c&&e(re,{content:c})]})},oe=e=>{if(!e)return!1;if(e.startsWith("//"))return!1;return!/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(e)},se=({content:n,onRelativeLinkClick:a})=>{const[o,s]=r(null);return e(l,{remarkPlugins:[c],components:{p:({children:t})=>e("p",{className:"mb-3 last:mb-0 leading-7 break-words text-[0.8125rem] text-gray-900 dark:text-white/90",children:t}),code:({className:n,children:r})=>{const a=/language-(\w+)/.exec(n||""),i=String(r).replace(/\n$/,"");return a?t("div",{className:"my-3 rounded-lg border border-gray-200 dark:border-white/10 overflow-hidden bg-gray-50 dark:bg-white/[0.03]",children:[t("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-gray-200 dark:border-white/10 bg-gray-100 dark:bg-white/[0.03]",children:[e("span",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 font-mono",children:a[1]}),e("button",{type:"button",onClick:()=>{return e=i,navigator.clipboard.writeText(e),s(e),void setTimeout(()=>s(null),2e3);var e},className:"p-0.5 rounded-sm hover:bg-gray-200 dark:hover:bg-white/10 transition-colors",children:o===i?e(_,{size:14,className:"text-green-500"}):e(z,{size:14,className:"text-gray-400 dark:text-white/40"})})]}),e("pre",{className:"m-0 px-3 py-2 overflow-x-auto",children:e("code",{className:"font-mono text-xs leading-[1.7] text-gray-800 dark:text-white/90 whitespace-pre",children:i})})]}):e("code",{className:"bg-gray-100 dark:bg-white/[0.08] px-1.5 py-0.5 rounded-sm font-mono text-xs text-[var(--chat-accent)]",children:r})},ul:({children:t})=>e("ul",{className:"pl-5 mb-3 text-[0.8125rem] text-gray-900 dark:text-white/90 [&_li]:mb-1 marker:text-[var(--chat-accent)]/50",children:t}),ol:({children:t})=>e("ol",{className:"pl-5 mb-3 text-[0.8125rem] text-gray-900 dark:text-white/90 [&_li]:mb-1 marker:text-[var(--chat-accent)]/50",children:t}),blockquote:({children:t})=>e("blockquote",{className:"my-3 border-l-2 border-[var(--chat-accent)]/30 bg-[var(--chat-accent)]/[0.03] pl-4 pr-3 py-2 rounded-r-md italic text-gray-500 dark:text-white/60",children:t}),a:({href:t,children:n})=>{const r=!oe(t);return e("a",{href:t,onClick:e=>{t&&oe(t)&&a&&(e.preventDefault(),a(t))},target:r?"_blank":void 0,rel:r?"noopener noreferrer":void 0,className:"text-[var(--chat-accent)] underline underline-offset-2 hover:brightness-125",children:n})},h1:({children:t})=>e("h1",{className:"mt-4 first:mt-0 mb-2 font-bold text-base text-gray-900 dark:text-white",children:t}),h2:({children:t})=>e("h2",{className:"mt-3 first:mt-0 mb-2 font-bold text-[0.9rem] text-gray-900 dark:text-white",children:t}),h3:({children:t})=>e("h3",{className:"mt-3 first:mt-0 mb-1.5 font-semibold text-[0.85rem] text-gray-900 dark:text-white",children:t}),table:({children:t})=>e("div",{className:"my-3 overflow-x-auto rounded-lg border border-gray-200 dark:border-white/10",children:e("table",{className:"w-full border-collapse text-xs",children:t})}),th:({children:t})=>e("th",{className:"px-3 py-2 text-left font-semibold bg-gray-50 dark:bg-white/[0.04] border-b border-gray-200 dark:border-white/10 text-gray-900 dark:text-white",children:t}),td:({children:t})=>e("td",{className:"px-3 py-2 border-b border-gray-200 dark:border-white/10 text-gray-700 dark:text-white/80",children:t})},children:n})};const ie=({messages:s,isLoading:i,agentStatus:l,agentName:c,logoIcon:d,onRelativeLinkClick:h,onDownloadFile:g,t:m})=>{const p=a(null),[f,w]=r(null);o(()=>{p.current?.scrollIntoView({behavior:"smooth"})},[s]);const x=(n,r)=>{const a="working_file"===n.fileTag,o=!(s=n.size)||s<=0?"":s<1024?`${s} B`:s<1048576?`${(s/1024).toFixed(0)} KB`:`${(s/1048576).toFixed(1)} MB`;var s;return t("button",{type:"button",onClick:()=>g?.(n),title:m("Download"),className:"group flex items-center gap-2 text-left rounded-lg border px-2.5 py-1.5 transition-colors cursor-pointer max-w-[90%] "+(a?"border-gray-200 dark:border-white/10 bg-transparent":"border-gray-200 dark:border-white/10 bg-gray-50 dark:bg-white/[0.04] hover:border-[var(--chat-accent)] hover:bg-[var(--chat-accent)]/5"),children:[e("span",{className:"shrink-0 "+(a?"text-gray-400 dark:text-white/40":"text-[var(--chat-accent)]"),children:e(R,{size:16})}),t("span",{className:"flex flex-col min-w-0 flex-1",children:[e("span",{className:"truncate text-[0.75rem] text-gray-900 dark:text-white",children:n.filename}),(n.type||o)&&e("span",{className:"text-[0.65rem] text-gray-400 dark:text-white/40 uppercase",children:[n.type,o].filter(Boolean).join(" Β· ")})]}),e("span",{className:"shrink-0 text-gray-400 dark:text-white/30 group-hover:text-[var(--chat-accent)]",children:e(T,{size:15})})]},r)},b=(t,n)=>{const r=function(e){if(!e)return[];const t=[],n=/\[\[FILE:([^\]]+)\]\]/g;let r=0,a=n.exec(e);for(;null!==a;)a.index>r&&t.push({type:"text",value:e.slice(r,a.index)}),t.push({type:"file",fileId:a[1]}),r=n.lastIndex,a=n.exec(e);const o=e.slice(r).replace(u,"");return o&&t.push({type:"text",value:o}),t}(t.content),a=new Map((t.attachments??[]).map(e=>[e.fileId,e])),o=new Set,s=[];return r.forEach((t,n)=>{if("text"===t.type)t.value.trim()&&s.push(e("div",{className:"max-w-[90%] pl-1 py-1 text-[0.8125rem] leading-7",children:e(se,{content:t.value,onRelativeLinkClick:h})},`t-${n}`));else if(g){const e=a.get(t.fileId);e&&(o.add(t.fileId),s.push(x(e,`f-${t.fileId}-${n}`)))}}),g&&(t.attachments??[]).forEach(e=>{o.has(e.fileId)||s.push(x(e,`orphan-${e.fileId}`))}),0!==s.length||n||s.push(e("span",{className:"pl-1 text-[0.8125rem] text-gray-400 dark:text-white/40 italic",children:"..."},"empty")),s};return t("div",{className:"flex-1 overflow-y-auto px-4 py-3 flex flex-col gap-4 filigran-chat-scrollable",children:[s.map((r,a)=>{const o="assistant"===r.role,h=!r.content,u=i&&a===s.length-1;return o&&h&&u?e("div",{children:e(ae,{agentStatus:l,logoIcon:d,t:m})},r.id):t("div",{className:"flex flex-col "+(o?"items-start":"items-end"),children:[o&&t("div",{className:"flex items-center gap-1.5 mb-1",children:[e("div",{className:"w-6 h-6 rounded-lg flex items-center justify-center bg-gradient-to-br from-[var(--chat-accent)]/20 to-[var(--chat-accent)]/5",children:e("span",{className:"text-[var(--chat-accent)] [&>svg]:w-3 [&>svg]:h-3",children:d})}),e("span",{className:"font-semibold text-xs text-gray-900 dark:text-white",children:c})]}),o&&!h&&u&&l?.thinkingContent&&e(re,{content:l.thinkingContent}),r.files&&r.files.length>0&&e("div",{className:"flex gap-1.5 flex-wrap mb-1.5",children:r.files.map((n,r)=>t("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full border border-gray-200 dark:border-white/10 text-[0.7rem] text-gray-600 dark:text-white/60",children:[e(R,{size:14}),n.name]},r))}),o?t("div",{className:"flex flex-col gap-1.5 w-full items-start",children:[b(r,u),!h&&u&&e("span",{className:"inline-block w-1.5 h-4 bg-[var(--chat-accent)]/70 rounded-xs ml-1 animate-pulse"})]}):e("div",{className:"max-w-[90%] px-3.5 py-2 rounded-[14px_14px_4px_14px] bg-[var(--chat-accent-dark)] text-white text-[0.8125rem] leading-6",children:r.content}),o&&!h&&!i&&r.toolNames&&r.toolNames.length>0&&t(n,{children:[e("button",{type:"button",onClick:()=>w(f===r.id?null:r.id),className:"mt-0.5 p-1 rounded-lg opacity-50 hover:opacity-100 hover:text-[var(--chat-accent)] transition-opacity",title:m("Reasoning details"),children:e(O,{size:14})}),f===r.id&&t("div",{className:"mt-1.5 p-3 rounded-lg bg-gray-50 dark:bg-white/[0.04] border border-gray-200 dark:border-white/10",children:[t("p",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 mb-1.5",children:[r.iterations&&r.iterations>1?`${r.iterations} iterations Β· `:"",r.toolCallCount??r.toolNames.length," ",1===(r.toolCallCount??r.toolNames.length)?m("tool call"):m("tool calls")]}),e("div",{className:"flex flex-wrap gap-1",children:Array.from(new Set(r.toolNames)).map(t=>e("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full border border-gray-200 dark:border-white/10 text-[0.68rem] font-mono text-gray-500 dark:text-white/40",children:t.replace(/_/g," ")},t))})]})]})]},r.id)}),e("div",{ref:p})]})},le=({firstName:n,logoIcon:r,promptSuggestions:a,onPromptClick:o,t:s})=>t("div",{className:"flex-1 flex flex-col items-center justify-center px-6 pb-8",children:[e("span",{className:"text-[var(--chat-accent)] mb-4 [&>svg]:w-12 [&>svg]:h-12 drop-shadow-[0_0_12px_var(--chat-accent-40)]",children:r}),t("h2",{className:"text-xl font-medium mb-6 text-center text-gray-900 dark:text-white",style:{fontFamily:'"Geologica", sans-serif'},children:[s("How can I help you, "),n,"?"]}),t("div",{className:"w-full max-w-[320px]",children:[e("span",{className:"block text-center mb-2 text-[0.65rem] tracking-[1.5px] uppercase text-[var(--chat-accent)] font-semibold",children:s("Suggestions")}),a.map(t=>e("button",{type:"button",onClick:()=>o(t),className:"w-full text-left text-[0.8125rem] text-gray-800 dark:text-white py-1.5 px-3 mb-1 rounded-lg border border-gray-200 dark:border-white/10 bg-transparent transition-colors hover:bg-[var(--chat-accent-10)] hover:border-[var(--chat-accent-50)]",children:s(t)},t))]})]}),ce=["Help me create a new simulation scenario","What are the latest attack patterns?","How do I configure detection rules?","Summarize my recent findings"],de=({mode:n,onClose:i,onModeChange:l,topOffset:c=0,apiBaseUrl:u,apiEndpoints:m,agentDashboardUrl:p,user:f,t:w=h,accentColor:x="#7b5cff",logoIcon:b,promptSuggestions:C=ce,draftBorderColor:S,resizable:_=!1,onWidthChange:I,onResizeStart:L,onResizeEnd:z,disableFileManagement:M=!1,onRelativeLinkClick:T,onDownloadError:E,maxFileCount:$,maxTotalSize:R,requestHeaders:D,pushContentSelector:j,backendType:U="rest"})=>{const[W,O]=r(!1),{agents:B,selectedAgent:F,agentMenuOpen:H,setAgentMenuOpen:P,handleSwitchAgent:G}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[s,i]=r([]),[l,c]=r(null),[d,h]=r(!1);return o(()=>{null===t?.agents||t?.singleEndpoint||"legacy"===n||fetch(`${e}${t?.agents??"/chat/agents"}`,{headers:a}).then(e=>e.ok?e.json():[]).then(e=>{if(i(e),e.length>0&&!l){const t=localStorage.getItem(v),n=t?e.find(e=>e.slug===t):null;c(n||e[0])}}).catch(()=>{})},[e,t,n,a]),{agents:s,selectedAgent:l,setSelectedAgent:c,agentMenuOpen:d,setAgentMenuOpen:h,handleSwitchAgent:(e,t)=>{e.id!==l?.id?(c(e),e.slug&&localStorage.setItem(v,e.slug),h(!1),t?.()):h(!1)}}}({apiBaseUrl:u,apiEndpoints:m,backendType:U,requestHeaders:D}),{messages:V,inputValue:q,setInputValue:K,isLoading:Z,agentStatus:X,attachedFiles:J,conversationId:Q,transferredAgent:Y,historyLoadedRef:ee,handleFileAdd:re,handlePaste:ae,handleSendMessage:oe,handleNewChat:se,handleStopGenerating:de,setAttachedFiles:he,setMessages:ue,setConversationId:ge}=k({apiBaseUrl:u,apiEndpoints:m,backendType:U,agentSlug:F?.slug,requestHeaders:D,t:w,maxFileCount:$,maxTotalSize:R}),{sidebarWidth:me,handleResizeStart:pe,defaultWidth:fe,isResizing:we}=function({mode:e,resizable:t,onWidthChange:n,onResizeStart:s,onResizeEnd:i}){const[l,c]=r(()=>{if("undefined"==typeof window)return y;const e=localStorage.getItem(N);if(e){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=y)return t}return y}),[d,h]=r(!1),u=a(!1),g=a(l);g.current=l;const m=a(n);m.current=n;const p=a(i);return p.current=i,o(()=>{"sidebar"===e&&t&&m.current?.(g.current)},[e,t]),o(()=>{if("sidebar"!==e||!t)return;const n=e=>{if(!u.current)return;e.preventDefault();const t=window.innerWidth-e.clientX,n=.4*window.innerWidth,r=Math.min(Math.max(t,y),n);c(r),g.current=r,m.current?.(r)},r=()=>{u.current&&(u.current=!1,h(!1),document.body.style.cursor="",document.body.style.userSelect="",localStorage.setItem(N,String(g.current)),p.current?.())},a=()=>{const e=.4*window.innerWidth;if(g.current>e){const t=Math.max(e,y);c(t),g.current=t,m.current?.(t)}};return document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),window.addEventListener("resize",a),()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),window.removeEventListener("resize",a)}},[e,t]),{sidebarWidth:l,handleResizeStart:e=>{e.preventDefault(),u.current=!0,h(!0),document.body.style.cursor="col-resize",document.body.style.userSelect="none",s?.()},defaultWidth:y,isResizing:d}}({mode:n,resizable:_,onWidthChange:I,onResizeStart:L,onResizeEnd:z});o(()=>{const e="sidebar"===n?_?me:fe:0,t=e>0?e+6:0;if(document.documentElement.style.setProperty("--chatbot-sidebar-width",`${t}px`),document.documentElement.style.setProperty("--chatbot-transition",we?"none":"all 225ms cubic-bezier(0.4, 0, 0.2, 1)"),j){const e=document.querySelector(j);if(e){const n=e.style.paddingRight,r=e.style.transition;return e.style.paddingRight=t>0?`${t}px`:"",e.style.transition=we?"none":"padding-right 225ms cubic-bezier(0.4, 0, 0.2, 1)",()=>{e.style.paddingRight=n,e.style.transition=r,document.documentElement.style.setProperty("--chatbot-sidebar-width","0px")}}}return()=>{document.documentElement.style.setProperty("--chatbot-sidebar-width","0px")}},[j,n,me,fe,_,we]);const xe=b??e(A,{size:24}),be=f.firstName,ke=Y?.name||F?.name||"Assistant",ve=null!=m?.download,ye="rest"===U&&null!==m?.download&&(!m?.singleEndpoint||ve),Ne=s(async e=>{const t=`${u}${m?.download??"/chat/files"}/${encodeURIComponent(e.fileId)}/download`;try{const n=await fetch(t,{method:"GET",credentials:"include",headers:{...D??{}}});if(!n.ok)throw new Error(`Download failed: ${n.status}`);const r=await n.blob(),a=URL.createObjectURL(r),o=document.createElement("a");o.href=a,o.download=e.filename||"download",document.body.appendChild(o),o.click(),o.remove(),URL.revokeObjectURL(a)}catch(t){E?.(t,e)}},[u,m,D,E]),Ce={"--chat-accent":x,"--chat-accent-10":d(x,.1),"--chat-accent-40":d(x,.25),"--chat-accent-50":d(x,.5),"--chat-accent-dark":x};o(()=>{if(null===m?.sessions||m?.singleEndpoint||"legacy"===U||"ag-ui"===U)return;if(!Q||ee.current||!F)return;ee.current=!0;const e=()=>{ge(null),localStorage.removeItem("filigranChatConversationId")};fetch(`${u}${m?.sessions??"/chat/sessions"}`,{method:"POST",headers:{"Content-Type":"application/json",...D??{}},body:JSON.stringify({conversation_id:Q,agent_slug:F.slug})}).then(t=>t.ok?t.json():(e(),null)).then(e=>{if(!e?.messages?.length)return;const t=e.messages.map((e,t)=>({id:`restored-${t}`,role:e.role,content:e.content,timestamp:new Date,attachments:"assistant"===e.role?g(e.attachments):void 0}));ue(t)}).catch(()=>{e()})},[Q,F,u,m,ee,D,ue,ge]);const Se=(()=>{const e="filigran-chatbot";switch(n){case"sidebar":return`${e} fixed right-0 bottom-0 flex flex-col bg-white dark:bg-[#1e1e2e] border-l border-gray-200 dark:border-white/10 z-[1200]`;case"floating":return`${e} fixed bottom-5 right-5 flex flex-col bg-white dark:bg-[#1e1e2e] rounded-xl shadow-[0_8px_32px_rgba(0,0,0,0.15)] dark:shadow-[0_8px_32px_rgba(0,0,0,0.4)] z-[1300] border border-gray-200 dark:border-white/10`;case"fullscreen":return`${e} fixed right-0 bottom-0 left-0 flex flex-col bg-gray-50 dark:bg-[#161622] z-[1400]`;default:return e}})(),_e={...Ce,..."sidebar"===n?{top:c,width:_?me:fe}:"floating"===n?{width:380,height:560}:{top:c}};return t("div",{className:Se,style:_e,children:["sidebar"===n&&_&&e("div",{onMouseDown:pe,className:"absolute top-0 -left-1 bottom-0 w-2 cursor-col-resize z-10 group",children:e("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 bottom-0 w-0.5 rounded-sm bg-[var(--chat-accent)] opacity-0 transition-opacity group-hover:opacity-100 group-active:opacity-100"})}),e(te,{mode:n,agentName:ke,agents:B,selectedAgent:F,transferredFrom:Y?F?.name:void 0,agentMenuOpen:H,onAgentMenuToggle:()=>P(e=>!e),onAgentMenuClose:()=>P(!1),onSwitchAgent:e=>{e&&G(e,()=>{se()})},modeMenuOpen:W,onModeMenuToggle:()=>O(e=>!e),onModeMenuClose:()=>O(!1),onModeChange:l,onNewChat:se,onClose:i,logoIcon:xe,agentDashboardUrl:p,t:w}),0===V.length?e(le,{firstName:be,logoIcon:xe,promptSuggestions:C,onPromptClick:K,t:w}):e(ie,{messages:V,isLoading:Z,agentStatus:X,agentName:ke,logoIcon:xe,onRelativeLinkClick:T,onDownloadFile:ye?Ne:void 0,t:w}),e(ne,{inputValue:q,onInputChange:K,onSend:oe,onStop:de,isLoading:Z,attachedFiles:M?[]:J,onFileAdd:M?void 0:re,onFileRemove:M?void 0:e=>he(t=>t.filter((t,n)=>n!==e)),onPaste:M?void 0:ae,t:w,mode:n,separatorColor:S})]})},he=({isOpen:n,onToggle:r,label:a="Ask Assistant",accentColor:o="#7b5cff",icon:s})=>{const i=s??e(A,{size:16});return t("button",{type:"button",onClick:r,className:"filigran-chatbot inline-flex items-center gap-1.5 px-3 py-[3px] text-[0.8125rem] font-medium whitespace-nowrap rounded-md border transition-colors",style:{borderColor:n?o:d(o,.5),color:o,backgroundColor:n?d(o,.1):"transparent"},onMouseEnter:e=>{e.currentTarget.style.borderColor=o,e.currentTarget.style.backgroundColor=d(o,.1)},onMouseLeave:e=>{e.currentTarget.style.borderColor=n?o:d(o,.5),e.currentTarget.style.backgroundColor=n?d(o,.1):"transparent"},children:[e("span",{className:"[&>svg]:w-4 [&>svg]:h-4",children:i}),a]})};export{de as ChatPanel,he as ChatToggleButton};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|