@filigran/chatbot 3.5.1 → 3.6.0
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 +108 -1
- package/dist/index.d.ts +39 -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
|
@@ -5,6 +5,8 @@ Filigran chat panel — a standalone React + Tailwind chatbot component with SSE
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- 🔄 **SSE Message Streaming** — Real-time response streaming with status indicators
|
|
8
|
+
- ⚡ **Mid-Run Steering** — Send messages while the agent is generating; they are injected into the running agentic loop instead of waiting for the turn to finish
|
|
9
|
+
- 🗂️ **Conversation History** — Switch between (and delete) past conversations from a history menu in the header
|
|
8
10
|
- 🤖 **Multi-Agent Support** — Switch between different AI agents
|
|
9
11
|
- 📎 **File Attachments** — Upload and paste files (PDF, TXT, images)
|
|
10
12
|
- 📥 **Agent-Generated Files** — Renders downloadable file cards from agent output and strips the `[[FILE:id]]` markers from the prose
|
|
@@ -192,6 +194,37 @@ even though streaming downloads work:
|
|
|
192
194
|
}
|
|
193
195
|
```
|
|
194
196
|
|
|
197
|
+
### `GET {apiBaseUrl}/chat/sessions`
|
|
198
|
+
|
|
199
|
+
Lists the user's past conversations for the history menu in the chat header.
|
|
200
|
+
|
|
201
|
+
**Response** (a bare array or `{ "conversations": [...] }`):
|
|
202
|
+
|
|
203
|
+
```json
|
|
204
|
+
[
|
|
205
|
+
{
|
|
206
|
+
"conversation_id": "uuid-here",
|
|
207
|
+
"title": "What is the weather?",
|
|
208
|
+
"updated_at": "2026-06-10T08:30:00Z",
|
|
209
|
+
"message_count": 12
|
|
210
|
+
}
|
|
211
|
+
]
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
Selecting a conversation restores it through the existing
|
|
215
|
+
`POST /chat/sessions` contract above. The endpoint is fetched lazily when the
|
|
216
|
+
history menu opens; a backend that doesn't implement it yet (404/405) simply
|
|
217
|
+
yields an empty list, so the menu shows its empty state instead of breaking
|
|
218
|
+
the chat. Set `apiEndpoints.history` to `null` to hide the history menu
|
|
219
|
+
entirely, or point it at a dedicated path if your proxy can't route `GET` on
|
|
220
|
+
the sessions path.
|
|
221
|
+
|
|
222
|
+
### `DELETE {apiBaseUrl}/chat/sessions/{conversation_id}`
|
|
223
|
+
|
|
224
|
+
Deletes a conversation from the history menu. Any 2xx response counts as
|
|
225
|
+
success; deleting the active conversation resets the panel to a fresh chat so
|
|
226
|
+
the next message never targets a dead conversation id.
|
|
227
|
+
|
|
195
228
|
### `POST {apiBaseUrl}/chat/messages`
|
|
196
229
|
|
|
197
230
|
Sends a message and streams the response via SSE.
|
|
@@ -223,9 +256,24 @@ data: {"type": "status", "status": "analyzing"}
|
|
|
223
256
|
data: {"type": "status", "status": "streaming"}
|
|
224
257
|
data: {"type": "stream", "content": "The weather "}
|
|
225
258
|
data: {"type": "stream", "content": "today is sunny."}
|
|
226
|
-
data: {"type": "done", "content": "The weather today is sunny.", "conversation_id": "new-uuid", "tool_names": ["search_web"], "tool_call_count": 1, "iterations": 1}
|
|
259
|
+
data: {"type": "done", "content": "The weather today is sunny.", "conversation_id": "new-uuid", "tool_names": ["search_web"], "tool_call_count": 1, "iterations": 1, "reasoning": "Let me check the weather data first."}
|
|
227
260
|
```
|
|
228
261
|
|
|
262
|
+
The optional `reasoning` field on `done` (and on restored session messages)
|
|
263
|
+
carries the accumulated model reasoning / pre-tool preamble prose for the
|
|
264
|
+
turn. When present it is surfaced in the per-message reasoning-details panel
|
|
265
|
+
(the "i" button), mirroring the XTM One web chat.
|
|
266
|
+
|
|
267
|
+
#### Internal links
|
|
268
|
+
|
|
269
|
+
Assistant markdown links are routed through `onRelativeLinkClick` when they
|
|
270
|
+
are **internal to the host application**: relative hrefs (`/dashboard/...`)
|
|
271
|
+
and absolute http(s) hrefs on the **same origin** as the embedding page
|
|
272
|
+
(backends emit absolute links so they work from any chat surface — when the
|
|
273
|
+
chatbot is embedded in that very platform, e.g. the OpenCTI link inside
|
|
274
|
+
OpenCTI, the link is reduced to `pathname + search + hash` and navigates
|
|
275
|
+
in-app instead of opening a new tab). All other links open in a new tab.
|
|
276
|
+
|
|
229
277
|
#### Agent-generated file attachments
|
|
230
278
|
|
|
231
279
|
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:
|
|
@@ -257,9 +305,11 @@ Download failures (403/404/5xx/network) are reported through the optional `onDow
|
|
|
257
305
|
|
|
258
306
|
- `thinking` — Agent is processing
|
|
259
307
|
- `tool_start` — Agent is using tools (with `tools` array)
|
|
308
|
+
- `tool_heartbeat` — Liveness signal during a long tool execution (with `tools` and `elapsed_s`). The widget keeps the current status label and renders a live elapsed-time indicator next to it once the execution exceeds ~15 s, so long operations (background tasks, agent consults) never look stuck
|
|
260
309
|
- `analyzing` — Agent is analyzing tool results
|
|
261
310
|
- `composing` — Agent is composing the response
|
|
262
311
|
- `streaming` — Content is being streamed
|
|
312
|
+
- `steering` — A mid-run steering message is being incorporated (see below)
|
|
263
313
|
|
|
264
314
|
**Error event:**
|
|
265
315
|
|
|
@@ -267,6 +317,51 @@ Download failures (403/404/5xx/network) are reported through the optional `onDow
|
|
|
267
317
|
data: {"type": "error", "content": "Something went wrong"}
|
|
268
318
|
```
|
|
269
319
|
|
|
320
|
+
### `POST {apiBaseUrl}/chat/messages/steer`
|
|
321
|
+
|
|
322
|
+
Steers the agent mid-run: while a response is still streaming, Enter / the
|
|
323
|
+
accent Send button dispatches the typed text immediately instead of blocking
|
|
324
|
+
until the turn finishes. The widget POSTs:
|
|
325
|
+
|
|
326
|
+
```json
|
|
327
|
+
{
|
|
328
|
+
"conversation_id": "uuid-here",
|
|
329
|
+
"content": "Actually, filter by subregion instead",
|
|
330
|
+
"agent_slug": "general"
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
A 2xx response means the message was persisted and will be injected into the
|
|
335
|
+
running agentic loop at the next iteration boundary. On a non-2xx response or
|
|
336
|
+
a network error the optimistic user bubble is rolled back and the text is
|
|
337
|
+
restored into the composer (prepended on its own line if the user already
|
|
338
|
+
typed something new) — so a backend without steering support degrades
|
|
339
|
+
gracefully and the message is never silently lost. Set `apiEndpoints.steer`
|
|
340
|
+
to `null` to disable the steering affordances entirely.
|
|
341
|
+
|
|
342
|
+
Steering only applies to text-only sends on the `rest` backend with a known
|
|
343
|
+
`conversation_id` (the first turn of a fresh conversation only receives its id
|
|
344
|
+
on `done`). Sends with attachments keep the legacy wait behavior. Esc stops
|
|
345
|
+
generating.
|
|
346
|
+
|
|
347
|
+
#### Multi-segment responses
|
|
348
|
+
|
|
349
|
+
A steered turn can produce **multiple response segments** on one SSE stream:
|
|
350
|
+
when the steering message arrives too late to be folded into the current
|
|
351
|
+
pass, the backend completes the current segment (an intermediate `done`
|
|
352
|
+
event) and then runs a follow-up pass for the steering message (a fresh
|
|
353
|
+
`thinking` status followed by more `stream` events and a final `done`). The
|
|
354
|
+
widget renders each segment as its own assistant message:
|
|
355
|
+
|
|
356
|
+
```
|
|
357
|
+
data: {"type": "status", "status": "steering"}
|
|
358
|
+
data: {"type": "stream", "content": "...current answer keeps streaming..."}
|
|
359
|
+
data: {"type": "done", "content": "First segment answer", "conversation_id": "uuid"}
|
|
360
|
+
data: {"type": "status", "status": "thinking"}
|
|
361
|
+
data: {"type": "stream", "content": "Follow-up answer to the steering message"}
|
|
362
|
+
data: {"type": "done", "content": "Follow-up answer to the steering message", "conversation_id": "uuid"}
|
|
363
|
+
```
|
|
364
|
+
|
|
270
365
|
## Customization
|
|
271
366
|
|
|
272
367
|
### Custom Logo
|
|
@@ -321,15 +416,27 @@ function App() {
|
|
|
321
416
|
- `'Using tools…'`
|
|
322
417
|
- `'Analyzing results…'`
|
|
323
418
|
- `'Composing answer…'`
|
|
419
|
+
- `'Incorporating your message…'`
|
|
324
420
|
- `'Ask a question...'`
|
|
325
421
|
- `'Stop generating'`
|
|
422
|
+
- `'Send now'`
|
|
423
|
+
- `'Enter to send now · Esc to stop'`
|
|
424
|
+
- `'Attachments wait for the current response'`
|
|
326
425
|
- `'New chat'`
|
|
426
|
+
- `'Conversation history'`
|
|
427
|
+
- `'No conversations yet'`
|
|
428
|
+
- `'Untitled conversation'`
|
|
429
|
+
- `'New conversation'`
|
|
430
|
+
- `'Delete conversation'`
|
|
431
|
+
- `'just now'` / `'m ago'` / `'h ago'` / `'d ago'`
|
|
327
432
|
- `'Switch view'`
|
|
328
433
|
- `'Close'`
|
|
329
434
|
- `'Switch to another agent'`
|
|
330
435
|
- `'Browse agents'`
|
|
331
436
|
- `'Create agent'`
|
|
332
437
|
- `'Reasoning details'`
|
|
438
|
+
- `'Model reasoning'`
|
|
439
|
+
- `'iterations'`
|
|
333
440
|
- `'Download'`
|
|
334
441
|
- `'tool call'` / `'tool calls'`
|
|
335
442
|
- `'Uses AI. Verify results.'`
|
package/dist/index.d.ts
CHANGED
|
@@ -12,10 +12,29 @@ interface ApiEndpoints {
|
|
|
12
12
|
singleEndpoint?: boolean;
|
|
13
13
|
/** Path for sending messages. Default: '/chat/messages' */
|
|
14
14
|
messages?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Path for steering the agent mid-run (sending a message while a response
|
|
17
|
+
* is still streaming). Default: '/chat/messages/steer'. The widget POSTs
|
|
18
|
+
* `{ conversation_id, content, agent_slug }`; a 2xx response means the
|
|
19
|
+
* message was persisted and will be injected into the running agentic loop
|
|
20
|
+
* at the next iteration boundary. On a non-2xx response the optimistic
|
|
21
|
+
* bubble is rolled back and the text is restored into the composer, so a
|
|
22
|
+
* backend without steering support degrades gracefully. Set to null to
|
|
23
|
+
* disable mid-run steering entirely.
|
|
24
|
+
*/
|
|
25
|
+
steer?: string | null;
|
|
15
26
|
/** Path for fetching agents. Default: '/chat/agents'. Set to null to disable. */
|
|
16
27
|
agents?: string | null;
|
|
17
28
|
/** Path for fetching session history. Default: '/chat/sessions'. Set to null to disable. */
|
|
18
29
|
sessions?: string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Path for the multi-conversation history menu. Defaults to the sessions
|
|
32
|
+
* path: the widget lists past conversations via `GET {history}` and deletes
|
|
33
|
+
* one via `DELETE {history}/{conversation_id}`. Set to null to hide the
|
|
34
|
+
* history menu (e.g. when the backend only implements the session-restore
|
|
35
|
+
* POST contract).
|
|
36
|
+
*/
|
|
37
|
+
history?: string | null;
|
|
19
38
|
/** Path for uploading files. Default: '/chat/upload'. Set to null to disable file uploads. */
|
|
20
39
|
upload?: string | null;
|
|
21
40
|
/**
|
|
@@ -128,6 +147,12 @@ interface ChatMessage {
|
|
|
128
147
|
toolNames?: string[];
|
|
129
148
|
toolCallCount?: number;
|
|
130
149
|
iterations?: number;
|
|
150
|
+
/**
|
|
151
|
+
* Accumulated model reasoning / pre-tool preamble prose for the turn
|
|
152
|
+
* (from `thinking_text` events), surfaced in the reasoning-details panel
|
|
153
|
+
* after the answer completes — mirroring the XTM One web chat.
|
|
154
|
+
*/
|
|
155
|
+
reasoning?: string;
|
|
131
156
|
}
|
|
132
157
|
/**
|
|
133
158
|
* An agent-generated file produced during a chat turn (via the backend
|
|
@@ -162,6 +187,19 @@ interface ChatFile {
|
|
|
162
187
|
/** Upload status: 'pending' while uploading, 'done' when uploaded, 'error' on failure. */
|
|
163
188
|
uploadStatus?: 'pending' | 'done' | 'error';
|
|
164
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* A past conversation surfaced in the history menu (REST backend only).
|
|
192
|
+
* Listed via `GET {apiBaseUrl}{apiEndpoints.history ?? apiEndpoints.sessions ?? '/chat/sessions'}`
|
|
193
|
+
* — the optional `apiEndpoints.history` override takes precedence when the
|
|
194
|
+
* proxy cannot route GET/DELETE on the sessions path.
|
|
195
|
+
*/
|
|
196
|
+
interface ChatConversationSummary {
|
|
197
|
+
conversationId: string;
|
|
198
|
+
title: string;
|
|
199
|
+
/** ISO timestamp of the last activity, used for the relative-time label. */
|
|
200
|
+
updatedAt?: string;
|
|
201
|
+
messageCount?: number;
|
|
202
|
+
}
|
|
165
203
|
interface XtmAgent {
|
|
166
204
|
id: string;
|
|
167
205
|
name: string;
|
|
@@ -180,4 +218,4 @@ interface TransferredAgent {
|
|
|
180
218
|
}
|
|
181
219
|
|
|
182
220
|
export { ChatPanel, ChatToggleButton };
|
|
183
|
-
export type { ApiEndpoints, BackendType, ChatAttachment, ChatFile, ChatMessage, ChatMode, ChatPanelProps, ChatToggleButtonProps, TransferredAgent, XtmAgent };
|
|
221
|
+
export type { ApiEndpoints, BackendType, ChatAttachment, ChatConversationSummary, 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,useCallback as o,useEffect 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")}`}function h(e){if(!e)return e;const t=e.split("\n"),n=/^(\s*)(`{3,})(.*)$/,r=/^(markdown|md|mdx|markup)\b/i;let a=-1;for(let e=0;e<t.length;e++){const o=t[e].match(n);if(o&&3===o[2].length&&r.test(o[3].trim())){a=e;break}}if(-1===a)return e;let o=3,s=0,i=-1;for(let e=a+1;e<t.length;e++){const r=t[e].match(n);r&&(s++,o=Math.max(o,r[2].length),""===r[3].trim()&&(i=e))}if(0===s)return e;const l="`".repeat(Math.max(o+1,4)),c=t[a].match(n);if(t[a]=`${c[1]}${l}${c[3]}`,i>a){const e=t[i].match(n);t[i]=`${e[1]}${l}`}return t.join("\n")}const u=e=>e,g=/\[\[FILE(?::[^\]]*)?\]?$/;function m(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 p(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:m(e.attachments)}:{action:"noop"}}function f(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 w(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"}}if("REASONING_START"===n||"REASONING_MESSAGE_START"===n)return{action:"status",status:"thinking"};if("REASONING_MESSAGE_CONTENT"===n||"REASONING_MESSAGE_CHUNK"===n){const t=e.delta;return t?{action:"status",status:"thinking_text",thinkingContent:t}:{action:"status",status:"thinking"}}return{action:"noop"}}const x="filigranChatConversationId",b="filigranChatLegacyChatId",k=52428800;function v({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",agentSlug:s,requestHeaders:i,pageContext:l,t:c,maxFileCount:d=10,maxTotalSize:h=52428800}){const u="legacy"===n,[g,m]=r([]),[v,y]=r(""),[N,C]=r(!1),[S,_]=r(null),[I,L]=r(()=>"undefined"==typeof window?null:localStorage.getItem(x)),[z,M]=r([]),[A,T]=r(null),[E,$]=r(()=>"undefined"==typeof window?null:localStorage.getItem(b)),R=a(!1),j=a(null),D=a(!1),U=a(I),O=a(l);O.current=l;const W=a(null),B=a(new AbortController),F=Number.isFinite(d)&&d>0?Math.floor(d):10,H=Number.isFinite(h)&&h>0?h:k,P=()=>u||t?.singleEndpoint||null===t?.upload?null:`${e}${t?.upload??"/chat/upload"}`,G=o(e=>{U.current=e,L(e),e?localStorage.setItem(x,e):localStorage.removeItem(x)},[]),V=async n=>{if(U.current)return U.current;if(W.current)return W.current;const r=u||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",...i??{}},body:JSON.stringify({agent_slug:n})});if(!e.ok)return null;const t=await e.json(),a=t?.conversation_id??null;return a&&G(a),a}catch{return null}finally{W.current=null}})();return W.current=a,a},q=async(e,t,n)=>{const r=P(),a=new FormData;a.append("conversation_id",t),a.append("file",e,e.name);const o=i?Object.fromEntries(Object.entries(i).filter(([e])=>"content-type"!==e.toLowerCase())):void 0,s=await fetch(r,{method:"POST",headers:o,body:a,signal:n});if(!s.ok)throw new Error(`File upload failed: ${s.status}`);const l=(await s.json()).file_ids??[];if(0===l.length)throw new Error("No file_id returned");return l[0]},K=e=>{if(!e||0===e.length||!P())return;const t=Array.from(e).map(e=>({file:e,tempId:crypto.randomUUID()}));let n=[];M(e=>{const r=e.length,a=e.reduce((e,t)=>e+t.size,0),o=F-r;if(o<=0)return e;let s=H-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=B.current.signal;for(const{file:t,tempId:r}of n)(async()=>{try{const n=await V(s);if(!n)return void M(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e));const a=await q(t,n,e);M(e=>e.map(e=>e.fileId===r?{...e,fileId:a,uploadStatus:"done"}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;M(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e))}})()},0)};return{messages:g,inputValue:v,setInputValue:y,isLoading:N,agentStatus:S,attachedFiles:z,conversationId:I,transferredAgent:A,historyLoadedRef:R,conversationIdRef:U,handleFileAdd:K,handlePaste:e=>{const{files:t}=e.clipboardData;t.length>0&&(e.preventDefault(),K(t))},handleSendMessage:async()=>{if(!v.trim()&&0===z.length||N)return;const r=v.trim(),a={id:crypto.randomUUID(),role:"user",content:r,timestamp:new Date,files:z.length>0?[...z]:void 0};m(e=>[...e,a]),y(""),M([]),C(!0),_({status:"thinking"}),D.current=!1;const o=crypto.randomUUID();m(e=>[...e,{id:o,role:"assistant",content:"",timestamp:new Date}]);try{const l=new AbortController;j.current=l;const d=(a.files??[]).filter(e=>"done"===e.uploadStatus&&e.fileId).map(e=>e.fileId),h=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:{const e={content:t,conversation_id:n.conversationId,agent_slug:n.agentSlug};if(n.pageContext&&Object.keys(n.pageContext).length>0)try{const t=JSON.stringify(n.pageContext);t&&"{}"!==t&&(e.context=n.pageContext)}catch{}return e}}}(n,r,{legacyChatId:E,conversationId:U.current,agentSlug:s,pageContext:O.current});d.length>0&&(h.file_ids=d),_({status:"thinking"});const g=await fetch(u||t?.singleEndpoint?e:`${e}${t?.messages??"/chat/messages"}`,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify(h),signal:l.signal});if(!g.ok||!g.body)return void m(e=>e.map(e=>e.id===o?{...e,content:c("Unable to connect. Please check the configuration.")}:e));const x=function(e){switch(e){case"legacy":return f;case"ag-ui":return w;default:return p}}(n),k={hasUsedTools:!1,activeNodeId:""},v=g.body.getReader(),y=new TextDecoder;let N="",C="",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=x(JSON.parse(n),k);switch(k.hasUsedTools=k.hasUsedTools||D.current,e.action){case"status":"tool_start"===e.status&&(D.current=!0),"stream_retract"===e.status?(C="",m(e=>e.map(e=>e.id===o?{...e,content:""}:e)),_(e=>({status:"analyzing",thinkingContent:e?.thinkingContent}))):"thinking_text"===e.status?_(t=>({...t,status:t?.status??"thinking",thinkingContent:(t?.thinkingContent??"")+(e.thinkingContent??"")})):_(t=>({status:e.status,tools:e.tools,thinkingContent:t?.thinkingContent}));break;case"stream":C+=e.content,_(e=>({status:"streaming",thinkingContent:e?.thinkingContent})),m(e=>e.map(e=>e.id===o?{...e,content:C}:e));break;case"done":S=!0,e.conversationId&&G(e.conversationId),e.transferAgentId&&e.transferAgentName&&T({id:e.transferAgentId,name:e.transferAgentName}),m(t=>t.map(t=>t.id===o?{...t,content:e.content||C,toolNames:e.toolNames,toolCallCount:e.toolCallCount,iterations:e.iterations,attachments:e.attachments}:t));break;case"error":return void m(t=>t.map(t=>t.id===o?{...t,content:e.content||c("Unable to connect. Please check the configuration.")}:t));case"set_chat_id":$(e.chatId),localStorage.setItem(b,e.chatId)}D.current=k.hasUsedTools}catch{}}}C&&!S&&m(e=>e.map(e=>e.id===o?{...e,content:C||"No response."}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;m(e=>e.map(e=>e.id===o?{...e,content:c("Sorry, an error occurred. Please try again.")}:e))}finally{j.current=null,C(!1),_(null),D.current=!1}},handleNewChat:()=>{j.current?.abort(),j.current=null,B.current.abort(),B.current=new AbortController,W.current=null,m([]),y(""),M([]),C(!1),_(null),T(null),D.current=!1,R.current=!1,u?($(null),localStorage.removeItem(b)):G(null)},handleStopGenerating:()=>{j.current?.abort(),j.current=null,C(!1),_(null),D.current=!1,m(e=>e.filter(e=>!("assistant"===e.role&&!e.content)))},setAttachedFiles:M,setMessages:m,updateConversationId:G}}const y="filigranChatAgentSlug";const N=400,C="filigranChatSidebarWidth";const 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:"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"})}),_=({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"})]}),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:"M20 6 9 17l-5-5"})}),L=({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"})}),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("path",{d:"M18 6 6 18"}),e("path",{d:"m6 6 12 12"})]}),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("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"})]}),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("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"})]}),T=({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"})}),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:"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"})]}),$=({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"})]}),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 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"})]}),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:"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"})]}),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 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"})]}),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:"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"})]}),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("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 16v-4"}),e("path",{d:"M12 8h.01"})]}),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("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"})]}),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("circle",{cx:"11",cy:"11",r:"8"}),e("path",{d:"m21 21-4.3-4.3"})]}),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("path",{d:"m22 2-7 20-4-9-9-4Z"}),e("path",{d:"m22 2-11 11"})]}),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("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),e("path",{d:"M15 3v18"})]}),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:"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"})}),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("circle",{cx:"12",cy:"12",r:"10"}),e("rect",{width:"6",height:"6",x:"9",y:"9"})]}),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("polyline",{points:"4 17 10 11 4 5"}),e("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]}),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("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"})]}),J=({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){s(()=>{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,o(()=>n(),[n]),t),s(()=>{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)},Q=({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 Y(e){let t=e;for(;t;){if(t.classList.contains("filigran-chatbot"))return t;t=t.parentElement}return document.body}const ee=({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}),Y(s.current))]})},te=[{mode:"floating",label:"Floating",getIcon:t=>e(D,{...t})},{mode:"sidebar",label:"Sidebar",getIcon:t=>e(G,{...t})},{mode:"fullscreen",label:"Full screen",getIcon:t=>e(O,{...t})}],ne=({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?G:"fullscreen"===n?U: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(L,{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(Q,{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(R,{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(Z,{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(ee,{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($,{size:18})})}),e(ee,{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:te.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(ee,{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(z,{size:18})})})]})},re=({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(j,{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(S,{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(ee,{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?q:P,{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 ae({content:t}){const n=a(null),[o,i]=r(!1),l=a(!0),c=t.replace(/```[\s\S]*?```/g," ").replace(/`([^`]+)`/g,"$1").replace(/\*\*(.+?)\*\*/g,"$1").replace(/__(.+?)__/g,"$1").replace(/#{1,6}\s+/g,"").replace(/^[ \t]*[-*>]+[ \t]*/gm,"").replace(/[ \t]+/g," ").replace(/\n{3,}/g,"\n\n").trim();return s(()=>{const e=n.current;e&&(l.current&&(e.scrollTop=e.scrollHeight),i(e.scrollHeight>e.clientHeight+1))},[c]),c.length<3?null:e("div",{className:"ml-11 mt-2.5 max-w-[75%] rounded-md border-l-2 bg-[var(--chat-accent)]/[0.03] py-2 pl-3 pr-3",style:{animation:"reasoningGlow 3s ease-in-out infinite, chat-fade-in 0.5s ease-out"},children:e("div",{ref:n,onScroll:()=>{const e=n.current;e&&(l.current=e.scrollHeight-e.scrollTop-e.clientHeight<24)},className:"max-h-40 overflow-y-auto overscroll-contain [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"+(o?" [mask-image:linear-gradient(to_bottom,transparent_0,rgb(0_0_0/0.25)_1.5rem,rgb(0_0_0/0.7)_3rem,black_4.5rem)]":""),children:e("p",{className:"m-0 whitespace-pre-wrap break-words text-xs leading-5 text-gray-500 dark:text-white/45",children:c})})})}const oe=({agentStatus:r,logoIcon:a,t:o})=>{const{label:s,StatusIcon:i,showDots:l}=function(e,t){if(!e)return{label:t("Thinking..."),StatusIcon:_,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:Z,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:V,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:V,showDots:!1}}let a,o=J;if(r.some(e=>e.includes("search")||e.includes("list"))?o=H:r.some(e=>e.includes("read")||e.includes("get")||e.includes("query"))?o=A:r.some(e=>e.includes("send")||e.includes("create")||e.includes("draft")||e.includes("reply")||e.includes("flag"))?o=F:r.some(e=>e.includes("code")||e.includes("execute"))?o=K: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:V,showDots:!1};case"composing":return{label:t("Composing answer…"),StatusIcon:_,showDots:!0};case"consulting":{const n=e.tools?.[0]??"agent";return{label:`${t("Consulting")} ${n}…`,StatusIcon:Z,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:Z,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:V,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:V,showDots:!1}}case"transferring":{const n=e.tools?.[0]??"agent";return{label:`${t("Transferring to")} ${n}…`,StatusIcon:R,showDots:!1}}default:return{label:t("Thinking..."),StatusIcon:_,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(ae,{content:c})]})},se=e=>{if(!e)return!1;if(e.startsWith("//"))return!1;return!/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(e)},ie=({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(I,{size:14,className:"text-green-500"}):e(M,{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=!se(t);return e("a",{href:t,onClick:e=>{t&&se(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:h(n)})};function le(e){const t=e.lastIndexOf(".");if(t<=0||t===e.length-1)return;const n=e.slice(t+1);return n.length<=8?n.toUpperCase():void 0}const ce=({messages:o,isLoading:i,agentStatus:l,agentName:c,logoIcon:d,onRelativeLinkClick:h,onDownloadFile:u,t:m})=>{const p=a(null),[f,w]=r(null);s(()=>{p.current?.scrollIntoView({behavior:"smooth"})},[o]);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:()=>u?.(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(j,{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(E,{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(g,"");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(ie,{content:t.value,onRelativeLinkClick:h})},`t-${n}`));else if(u){const e=a.get(t.fileId);e&&(o.add(t.fileId),s.push(x(e,`f-${t.fileId}-${n}`)))}}),u&&(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},k=(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(j,{size:14}),n]},r),v=e=>{const t=[],n=new Set;return(e.files??[]).forEach((e,r)=>{!(!u||!e.fileId||"done"!==e.uploadStatus)&&e.fileId?(n.add(e.fileId),t.push(x({fileId:e.fileId,filename:e.name,type:le(e.name),size:e.size,contentType:e.type},`file-${e.fileId}-${r}`))):t.push(k(e.name,`file-${r}`))}),(e.attachments??[]).forEach((e,r)=>{n.has(e.fileId)||(n.add(e.fileId),t.push(u?x(e,`att-${e.fileId}-${r}`):k(e.filename,`att-${r}`)))}),t};return t("div",{className:"flex-1 overflow-y-auto px-4 py-3 flex flex-col gap-4 filigran-chat-scrollable",children:[o.map((r,a)=>{const s="assistant"===r.role,h=!r.content,u=i&&a===o.length-1;return s&&h&&u?e("div",{children:e(oe,{agentStatus:l,logoIcon:d,t:m})},r.id):t("div",{className:"flex flex-col "+(s?"items-start":"items-end"),children:[s&&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})]}),!s&&((r.files?.length??0)>0||(r.attachments?.length??0)>0)&&e("div",{className:"flex gap-1.5 flex-wrap mb-1.5 justify-end",children:v(r)}),s?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}),s&&!h&&!u&&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(B,{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})]})},de=({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))]})]}),he=["Help me create a new simulation scenario","What are the latest attack patterns?","How do I configure detection rules?","Summarize my recent findings"],ue=({mode:n,onClose:i,onModeChange:l,topOffset:c=0,apiBaseUrl:h,apiEndpoints:g,agentDashboardUrl:p,user:f,t:w=u,accentColor:x="#7b5cff",logoIcon:b,promptSuggestions:k=he,draftBorderColor:S,resizable:_=!1,onWidthChange:I,onResizeStart:L,onResizeEnd:z,disableFileManagement:M=!1,onRelativeLinkClick:A,onDownloadError:E,maxFileCount:$,maxTotalSize:R,requestHeaders:j,pageContext:D,pushContentSelector:U,backendType:O="rest"})=>{const[W,B]=r(!1),{agents:F,selectedAgent:H,agentMenuOpen:P,setAgentMenuOpen:G,handleSwitchAgent:V}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[o,i]=r([]),[l,c]=r(null),[d,h]=r(!1);return s(()=>{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(y),n=t?e.find(e=>e.slug===t):null;c(n||e[0])}}).catch(()=>{})},[e,t,n,a]),{agents:o,selectedAgent:l,setSelectedAgent:c,agentMenuOpen:d,setAgentMenuOpen:h,handleSwitchAgent:(e,t)=>{e.id!==l?.id?(c(e),e.slug&&localStorage.setItem(y,e.slug),h(!1),t?.()):h(!1)}}}({apiBaseUrl:h,apiEndpoints:g,backendType:O,requestHeaders:j}),{messages:q,inputValue:K,setInputValue:Z,isLoading:J,agentStatus:X,attachedFiles:Q,conversationId:Y,transferredAgent:ee,historyLoadedRef:te,conversationIdRef:ae,handleFileAdd:oe,handlePaste:se,handleSendMessage:ie,handleNewChat:le,handleStopGenerating:ue,setAttachedFiles:ge,setMessages:me,updateConversationId:pe}=v({apiBaseUrl:h,apiEndpoints:g,backendType:O,agentSlug:H?.slug,requestHeaders:j,pageContext:D,t:w,maxFileCount:$,maxTotalSize:R}),{sidebarWidth:fe,handleResizeStart:we,defaultWidth:xe,isResizing:be}=function({mode:e,resizable:t,onWidthChange:n,onResizeStart:o,onResizeEnd:i}){const[l,c]=r(()=>{if("undefined"==typeof window)return N;const e=localStorage.getItem(C);if(e){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=N)return t}return N}),[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,s(()=>{"sidebar"===e&&t&&m.current?.(g.current)},[e,t]),s(()=>{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,N),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(C,String(g.current)),p.current?.())},a=()=>{const e=.4*window.innerWidth;if(g.current>e){const t=Math.max(e,N);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",o?.()},defaultWidth:N,isResizing:d}}({mode:n,resizable:_,onWidthChange:I,onResizeStart:L,onResizeEnd:z});s(()=>{const e="sidebar"===n?_?fe:xe:0,t=e>0?e+6:0;if(document.documentElement.style.setProperty("--chatbot-sidebar-width",`${t}px`),document.documentElement.style.setProperty("--chatbot-transition",be?"none":"all 225ms cubic-bezier(0.4, 0, 0.2, 1)"),U){const e=document.querySelector(U);if(e){const n=e.style.paddingRight,r=e.style.transition;return e.style.paddingRight=t>0?`${t}px`:"",e.style.transition=be?"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")}},[U,n,fe,xe,_,be]);const ke=b??e(T,{size:24}),ve=f.firstName,ye=ee?.name||H?.name||"Assistant",Ne=null!=g?.download,Ce="rest"===O&&null!==g?.download&&(!g?.singleEndpoint||Ne),Se=o(async e=>{const t=`${h}${g?.download??"/chat/files"}/${encodeURIComponent(e.fileId)}/download`;try{const n=await fetch(t,{method:"GET",credentials:"include",headers:{...j??{}}});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)}},[h,g,j,E]),_e={"--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},Ie=a(!0);s(()=>(Ie.current=!0,()=>{Ie.current=!1}),[]),s(()=>{if(null===g?.sessions||g?.singleEndpoint||"legacy"===O||"ag-ui"===O)return;if(!Y||te.current||!H)return;te.current=!0;const e=Y,t=()=>!Ie.current||ae.current!==e;fetch(`${h}${g?.sessions??"/chat/sessions"}`,{method:"POST",headers:{"Content-Type":"application/json",...j??{}},body:JSON.stringify({conversation_id:Y,agent_slug:H.slug})}).then(e=>t()?null:e.ok?e.json():(pe(null),null)).then(n=>{if(!n||t())return;if("string"==typeof n.conversation_id&&n.conversation_id&&n.conversation_id!==e&&pe(n.conversation_id),!n.messages?.length)return;const r=n.messages.map((e,t)=>({id:`restored-${t}`,role:e.role,content:e.content,timestamp:new Date,attachments:m(e.attachments)}));me(r)}).catch(()=>{t()||pe(null)})},[Y,H,h,g,O,te,ae,Ie,j,me,pe]);const Le=(()=>{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}})(),ze={..._e,..."sidebar"===n?{top:c,width:_?fe:xe}:"floating"===n?{width:380,height:560}:{top:c}};return t("div",{className:Le,style:ze,children:["sidebar"===n&&_&&e("div",{onMouseDown:we,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(ne,{mode:n,agentName:ye,agents:F,selectedAgent:H,transferredFrom:ee?H?.name:void 0,agentMenuOpen:P,onAgentMenuToggle:()=>G(e=>!e),onAgentMenuClose:()=>G(!1),onSwitchAgent:e=>{e&&V(e,()=>{le()})},modeMenuOpen:W,onModeMenuToggle:()=>B(e=>!e),onModeMenuClose:()=>B(!1),onModeChange:l,onNewChat:le,onClose:i,logoIcon:ke,agentDashboardUrl:p,t:w}),0===q.length?e(de,{firstName:ve,logoIcon:ke,promptSuggestions:k,onPromptClick:Z,t:w}):e(ce,{messages:q,isLoading:J,agentStatus:X,agentName:ye,logoIcon:ke,onRelativeLinkClick:A,onDownloadFile:Ce?Se:void 0,t:w}),e(re,{inputValue:K,onInputChange:Z,onSend:ie,onStop:ue,isLoading:J,attachedFiles:M?[]:Q,onFileAdd:M?void 0:oe,onFileRemove:M?void 0:e=>ge(t=>t.filter((t,n)=>n!==e)),onPaste:M?void 0:se,t:w,mode:n,separatorColor:S})]})},ge=({isOpen:n,onToggle:r,label:a="Ask Assistant",accentColor:o="#7b5cff",icon:s})=>{const i=s??e(T,{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{ue as ChatPanel,ge as ChatToggleButton};
|
|
1
|
+
import{jsx as e,jsxs as t,Fragment as n}from"react/jsx-runtime";import{useState as r,useRef as a,useCallback as o,useEffect 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")}`}function h(e){if(!e)return e;const t=e.split("\n"),n=/^(\s*)(`{3,})(.*)$/,r=/^(markdown|md|mdx|markup)\b/i;let a=-1;for(let e=0;e<t.length;e++){const o=t[e].match(n);if(o&&3===o[2].length&&r.test(o[3].trim())){a=e;break}}if(-1===a)return e;let o=3,s=0,i=-1;for(let e=a+1;e<t.length;e++){const r=t[e].match(n);r&&(s++,o=Math.max(o,r[2].length),""===r[3].trim()&&(i=e))}if(0===s)return e;const l="`".repeat(Math.max(o+1,4)),c=t[a].match(n);if(t[a]=`${c[1]}${l}${c[3]}`,i>a){const e=t[i].match(n);t[i]=`${e[1]}${l}`}return t.join("\n")}const u=e=>e;const g=/\[\[FILE(?::[^\]]*)?\]?$/;function m(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 p(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}):"tool_heartbeat"===n?{action:"status",status:"tool_heartbeat",tools:e.tools,elapsedS:"number"==typeof e.elapsed_s?e.elapsed_s:void 0}:"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:m(e.attachments),reasoning:"string"==typeof e.reasoning?e.reasoning:void 0}:{action:"noop"}}function f(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 w(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"}}if("REASONING_START"===n||"REASONING_MESSAGE_START"===n)return{action:"status",status:"thinking"};if("REASONING_MESSAGE_CONTENT"===n||"REASONING_MESSAGE_CHUNK"===n){const t=e.delta;return t?{action:"status",status:"thinking_text",thinkingContent:t}:{action:"status",status:"thinking"}}return{action:"noop"}}const x="filigranChatConversationId",v="filigranChatLegacyChatId",b=52428800;function y({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",agentSlug:s,requestHeaders:i,pageContext:l,t:c,maxFileCount:d=10,maxTotalSize:h=52428800}){const u="legacy"===n,[g,m]=r([]),[y,k]=r(""),[N,C]=r(!1),[_,S]=r(null),[I,L]=r(()=>"undefined"==typeof window?null:localStorage.getItem(x)),[M,z]=r([]),[$,E]=r(null),[A,T]=r(()=>"undefined"==typeof window?null:localStorage.getItem(v)),D=a(!1),j=a(null),R=a(!1),U=a(I),O=a(l);O.current=l;const B=a(null),W=a(new AbortController),F=Number.isFinite(d)&&d>0?Math.floor(d):10,H=Number.isFinite(h)&&h>0?h:b,P=()=>u||"ag-ui"===n||t?.singleEndpoint||null===t?.steer?null:`${e}${t?.steer??"/chat/messages/steer"}`,G=()=>u||t?.singleEndpoint||null===t?.upload?null:`${e}${t?.upload??"/chat/upload"}`,V=o(e=>{U.current=e,L(e),e?localStorage.setItem(x,e):localStorage.removeItem(x)},[]),q=async n=>{if(U.current)return U.current;if(B.current)return B.current;const r=u||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",...i??{}},body:JSON.stringify({agent_slug:n})});if(!e.ok)return null;const t=await e.json(),a=t?.conversation_id??null;return a&&V(a),a}catch{return null}finally{B.current=null}})();return B.current=a,a},J=async(e,t,n)=>{const r=G(),a=new FormData;a.append("conversation_id",t),a.append("file",e,e.name);const o=i?Object.fromEntries(Object.entries(i).filter(([e])=>"content-type"!==e.toLowerCase())):void 0,s=await fetch(r,{method:"POST",headers:o,body:a,signal:n});if(!s.ok)throw new Error(`File upload failed: ${s.status}`);const l=(await s.json()).file_ids??[];if(0===l.length)throw new Error("No file_id returned");return l[0]},K=e=>{if(!e||0===e.length||!G())return;const t=Array.from(e).map(e=>({file:e,tempId:crypto.randomUUID()}));let n=[];z(e=>{const r=e.length,a=e.reduce((e,t)=>e+t.size,0),o=F-r;if(o<=0)return e;let s=H-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=W.current.signal;for(const{file:t,tempId:r}of n)(async()=>{try{const n=await q(s);if(!n)return void z(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e));const a=await J(t,n,e);z(e=>e.map(e=>e.fileId===r?{...e,fileId:a,uploadStatus:"done"}:e))}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;z(e=>e.map(e=>e.fileId===r?{...e,uploadStatus:"error"}:e))}})()},0)},Z=()=>{j.current?.abort(),j.current=null,W.current.abort(),W.current=new AbortController,B.current=null,m([]),k(""),z([]),C(!1),S(null),E(null),R.current=!1,D.current=!1,u?(T(null),localStorage.removeItem(v)):V(null)},X=N&&null!==P()&&null!==I;return{messages:g,inputValue:y,setInputValue:k,isLoading:N,agentStatus:_,attachedFiles:M,conversationId:I,transferredAgent:$,canSteer:X,historyLoadedRef:D,conversationIdRef:U,handleFileAdd:K,handlePaste:e=>{const{files:t}=e.clipboardData;t.length>0&&(e.preventDefault(),K(t))},handleSendMessage:async()=>{const r=y.trim();if(N)return void(r&&0===M.length&&P()&&U.current&&(k(""),await(async e=>{const t=P(),n=U.current;if(!t||!n)return;const r={id:crypto.randomUUID(),role:"user",content:e,timestamp:new Date};m(e=>[...e,r]);try{const r=await fetch(t,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify({conversation_id:n,content:e,agent_slug:s})});if(!r.ok)throw new Error(`Steer failed: ${r.status}`)}catch{m(e=>e.filter(e=>e.id!==r.id)),k(t=>t?`${e}\n${t}`:e)}})(r)));if(!y.trim()&&0===M.length)return;const a=y.trim(),o={id:crypto.randomUUID(),role:"user",content:a,timestamp:new Date,files:M.length>0?[...M]:void 0};m(e=>[...e,o]),k(""),z([]),C(!0),S({status:"thinking"}),R.current=!1;const l=crypto.randomUUID();m(e=>[...e,{id:l,role:"assistant",content:"",timestamp:new Date}]);let d=l;try{const r=new AbortController;j.current=r;const h=(o.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:{const e={content:t,conversation_id:n.conversationId,agent_slug:n.agentSlug};if(n.pageContext&&Object.keys(n.pageContext).length>0)try{const t=JSON.stringify(n.pageContext);t&&"{}"!==t&&(e.context=n.pageContext)}catch{}return e}}}(n,a,{legacyChatId:A,conversationId:U.current,agentSlug:s,pageContext:O.current});h.length>0&&(g.file_ids=h),S({status:"thinking"});const x=await fetch(u||t?.singleEndpoint?e:`${e}${t?.messages??"/chat/messages"}`,{method:"POST",headers:{"Content-Type":"application/json",...i??{}},body:JSON.stringify(g),signal:r.signal});if(!x.ok||!x.body)return void m(e=>e.map(e=>e.id===l?{...e,content:c("Unable to connect. Please check the configuration.")}:e));const b=function(e){switch(e){case"legacy":return f;case"ag-ui":return w;default:return p}}(n),y={hasUsedTools:!1,activeNodeId:""},k=x.body.getReader(),N=new TextDecoder;let C="",_="",I=!1;const L=()=>{if(!I)return;I=!1,_="",d=crypto.randomUUID();const e=d;m(t=>[...t,{id:e,role:"assistant",content:"",timestamp:new Date}]),S({status:"thinking"})};for(;;){const{done:e,value:t}=await k.read();if(e)break;C+=N.decode(t,{stream:!0});const n=C.split("\n");C=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),y);switch(y.hasUsedTools=y.hasUsedTools||R.current,e.action){case"status":{L();const t=d;"tool_start"===e.status&&(R.current=!0),"stream_retract"===e.status?(_="",m(e=>e.map(e=>e.id===t?{...e,content:""}:e)),S(e=>({status:"analyzing",thinkingContent:e?.thinkingContent}))):"thinking_text"===e.status?S(t=>({...t,status:t?.status??"thinking",thinkingContent:(t?.thinkingContent??"")+(e.thinkingContent??"")})):"tool_heartbeat"===e.status?S(t=>t?{...t,elapsedS:e.elapsedS}:{status:"tool_start",tools:e.tools,elapsedS:e.elapsedS}):S(t=>({status:e.status,tools:e.tools,thinkingContent:t?.thinkingContent}));break}case"stream":{L(),_+=e.content;const t=d,n=_;S(e=>({status:"streaming",thinkingContent:e?.thinkingContent})),m(e=>e.map(e=>e.id===t?{...e,content:n}:e));break}case"done":{I=!0,e.conversationId&&V(e.conversationId),e.transferAgentId&&e.transferAgentName&&E({id:e.transferAgentId,name:e.transferAgentName});const t=d,n=e.content||_;m(r=>r.map(r=>r.id===t?{...r,content:n,toolNames:e.toolNames,toolCallCount:e.toolCallCount,iterations:e.iterations,attachments:e.attachments,reasoning:e.reasoning}:r));break}case"error":{L();const t=d;return void m(n=>n.map(n=>n.id===t?{...n,content:e.content||c("Unable to connect. Please check the configuration.")}:n))}case"set_chat_id":T(e.chatId),localStorage.setItem(v,e.chatId)}R.current=y.hasUsedTools}catch{}}}if(_&&!I){const e=d,t=_;m(n=>n.map(n=>n.id===e?{...n,content:t||"No response."}:n))}}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return;const t=d;m(e=>e.map(e=>e.id===t?{...e,content:c("Sorry, an error occurred. Please try again.")}:e))}finally{j.current=null,C(!1),S(null),R.current=!1}},handleNewChat:Z,handleStopGenerating:()=>{j.current?.abort(),j.current=null,C(!1),S(null),R.current=!1,m(e=>e.filter(e=>!("assistant"===e.role&&!e.content)))},setAttachedFiles:z,setMessages:m,updateConversationId:V,handleSwitchConversation:e=>{(u||e!==U.current)&&(Z(),u||V(e))}}}const k="filigranChatAgentSlug";function N(e){if(!e||"object"!=typeof e)return null;const t=e,n=t.conversation_id??t.id;if("string"!=typeof n||!n)return null;return{conversationId:n,title:"string"==typeof t.title?t.title.trim():"",updatedAt:"string"==typeof t.updated_at?t.updated_at:"string"==typeof t.created_at?t.created_at:void 0,messageCount:"number"==typeof t.message_count?t.message_count:void 0}}const C=400,_="filigranChatSidebarWidth";const 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:"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"})}),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("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"})]}),L=({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"})}),M=({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"})}),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("path",{d:"M18 6 6 18"}),e("path",{d:"m6 6 12 12"})]}),$=({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"})]}),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("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"})]}),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:"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"})]}),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:"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"})]}),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:"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"})]}),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:"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"})]}),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("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"})]}),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("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),e("path",{d:"M3 3v5h5"}),e("path",{d:"M12 7v5l4 2"})]}),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("circle",{cx:"12",cy:"12",r:"10"}),e("path",{d:"M12 16v-4"}),e("path",{d:"M12 8h.01"})]}),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:"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"})]}),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("circle",{cx:"11",cy:"11",r:"8"}),e("path",{d:"m21 21-4.3-4.3"})]}),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("path",{d:"m22 2-7 20-4-9-9-4Z"}),e("path",{d:"m22 2-11 11"})]}),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("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2"}),e("path",{d:"M15 3v18"})]}),J=({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"})}),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("circle",{cx:"12",cy:"12",r:"10"}),e("rect",{width:"6",height:"6",x:"9",y:"9"})]}),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("polyline",{points:"4 17 10 11 4 5"}),e("line",{x1:"12",x2:"20",y1:"19",y2:"19"})]}),X=({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:"M3 6h18"}),e("path",{d:"M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"}),e("path",{d:"M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"}),e("line",{x1:"10",x2:"10",y1:"11",y2:"17"}),e("line",{x1:"14",x2:"14",y1:"11",y2:"17"})]}),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("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"})]}),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:"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 ee=({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){s(()=>{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,o(()=>n(),[n]),t),s(()=>{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)},te=({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 ne(e){let t=e;for(;t;){if(t.classList.contains("filigran-chatbot"))return t;t=t.parentElement}return document.body}const re=({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}),ne(s.current))]})},ae=[{mode:"floating",label:"Floating",getIcon:t=>e(U,{...t})},{mode:"sidebar",label:"Sidebar",getIcon:t=>e(q,{...t})},{mode:"fullscreen",label:"Full screen",getIcon:t=>e(B,{...t})}],oe=({mode:r,agentName:o,agents:s,selectedAgent:i,transferredFrom:l,agentMenuOpen:c,onAgentMenuToggle:d,onAgentMenuClose:h,onSwitchAgent:u,modeMenuOpen:g,onModeMenuToggle:m,onModeMenuClose:p,onModeChange:f,onNewChat:w,onClose:x,logoIcon:v,agentDashboardUrl:b,historyEnabled:y=!1,historyMenuOpen:k=!1,onHistoryMenuToggle:N,onHistoryMenuClose:C,conversations:_=[],conversationsLoading:S=!1,activeConversationId:I=null,onSelectConversation:L,onDeleteConversation:$,t:E})=>{const A=a(null),T=a(null),R=a(null),B="sidebar"===r?q:"fullscreen"===r?O:U;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"===r?"rounded-t-xl":""),children:[t("div",{className:"min-w-0",children:[t("button",{ref:A,type:"button",onClick:d,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:v}),e("span",{children:o}),e(M,{size:16,className:"text-gray-400 dark:text-white/30"})]}),l&&t("div",{className:"pl-10 pr-2 text-[0.6rem] font-normal text-gray-400 dark:text-white/30",children:[E("Transferred from")," ",l]})]}),t(ee,{open:c,onClose:h,anchorRef:A,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:E("Switch to another agent")}),0===s.length&&e("div",{className:"px-4 py-2",children:e(te,{size:16})}),e("div",{children:s.map(n=>t("button",{type:"button",onClick:()=>u(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===i?.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:v})}),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:()=>{h(),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(j,{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:E("Browse agents")})]}),b&&t("button",{type:"button",onClick:()=>{h(),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(Q,{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:E("Create agent")})]})]})]}),e("div",{className:"flex-1"}),y&&t(n,{children:[e(re,{title:E("Conversation history"),children:e("button",{ref:R,type:"button",onClick:N,"aria-label":E("Conversation history"),"aria-haspopup":"menu","aria-expanded":k,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(F,{size:18})})}),t(ee,{open:k,onClose:()=>C?.(),anchorRef:R,placement:"bottom-end",width:300,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:E("Conversation history")}),t("div",{className:"max-h-72 overflow-y-auto filigran-chat-scrollable",children:[S&&0===_.length&&e("div",{className:"px-4 py-2",children:e(te,{size:16})}),!S&&0===_.length&&e("div",{className:"px-4 py-3 text-[0.75rem] text-gray-400 dark:text-white/40",children:E("No conversations yet")}),_.map(n=>{const r=n.conversationId===I,a=function(e,t){if(!e)return"";const n=new Date(e).getTime();if(Number.isNaN(n))return"";const r=Date.now()-n,a=Math.floor(r/6e4);if(a<1)return t("just now");if(a<60)return`${a}${t("m ago")}`;const o=Math.floor(a/60);if(o<24)return`${o}${t("h ago")}`;const s=Math.floor(o/24);return s<7?`${s}${t("d ago")}`:new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}(n.updatedAt,E);return t("div",{className:"group flex items-center gap-2 px-4 py-1.5 hover:bg-gray-100 dark:hover:bg-white/10 transition-colors "+(r?"bg-[var(--chat-accent)]/10":""),children:[t("button",{type:"button",onClick:()=>L?.(n.conversationId),className:"flex-1 min-w-0 text-left",children:[e("div",{className:"text-[0.8125rem] font-medium text-gray-900 dark:text-white truncate",children:n.title||E("Untitled conversation")}),a&&e("div",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 truncate",children:a})]}),$&&e("button",{type:"button",onClick:()=>$(n.conversationId),title:E("Delete conversation"),"aria-label":E("Delete conversation"),className:"shrink-0 p-1 rounded-md text-gray-400 dark:text-white/30 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:text-red-500 dark:hover:text-red-400 transition-all",children:e(X,{size:14})})]},n.conversationId)})]}),e("div",{className:"h-px bg-gray-200 dark:bg-white/10 mx-2"}),t("button",{type:"button",onClick:()=>{C?.(),w()},className:"w-full flex items-center gap-2 px-4 py-2 text-left hover:bg-gray-100 dark:hover:bg-white/10 transition-colors",children:[e(D,{size:16,className:"text-gray-400 dark:text-white/40 shrink-0"}),e("span",{className:"text-[0.8125rem] text-gray-700 dark:text-white/70",children:E("New conversation")})]})]})]}),e(re,{title:E("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(D,{size:18})})}),e(re,{title:E("Switch view"),children:e("button",{ref:T,type:"button",onClick:m,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(B,{size:18})})}),t(ee,{open:g,onClose:p,anchorRef:T,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:E("Switch to")}),e("div",{className:"pb-1",children:ae.map(n=>t("button",{type:"button",onClick:()=>{f(n.mode),p()},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 "+(r===n.mode?"bg-[var(--chat-accent)]/10":""),children:[n.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:E(n.label)})]},n.mode))})]}),e(re,{title:E("Close"),children:e("button",{type:"button",onClick:x,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(z,{size:18})})})]})},se=({inputValue:r,onInputChange:o,onSend:s,onStop:i,isLoading:l,canSteer:c=!1,attachedFiles:d=[],onFileAdd:h,onFileRemove:u,onPaste:g,t:m,mode:p,separatorColor:f})=>{const w=a(null),x=a(null),v=Boolean(h&&u&&g),b=r.trim()||v&&d.length>0,y=v&&d.some(e=>"pending"===e.uploadStatus),k=b&&!y,N=v&&d.length>0,C=l&&c&&Boolean(r.trim())&&!N,_=m(l&&c&&!N?"Enter to send now · Esc to stop":l&&N?"Attachments wait for the current response":"Uses AI. Verify results.");return t("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-white/10 "+("floating"===p?"rounded-b-xl":""),style:f?{borderTopColor:f,borderTopWidth:1}:void 0,children:[v&&d.length>0&&e("div",{className:"flex gap-1.5 flex-wrap mb-2",children:d.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:()=>u?.(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:[v&&t(n,{children:[e("input",{ref:w,type:"file",multiple:!0,hidden:!0,onChange:e=>{h?.(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(S,{size:18})})]}),e("textarea",{ref:x,placeholder:m("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()),"Escape"===e.key&&l&&(e.preventDefault(),i())},onPaste:g,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}}),C&&e(re,{title:m("Send now"),children:e("button",{type:"button",onClick:s,"aria-label":m("Send now"),className:"p-1.5 rounded-lg w-8 h-8 flex items-center justify-center transition-all duration-150 text-[var(--chat-accent)] bg-[var(--chat-accent)]/10 hover:bg-[var(--chat-accent)]/20",children:e(V,{size:18})})}),e(re,{title:l?m("Stop generating"):y?m("Files uploading..."):"",children:e("button",{type:"button",onClick:l?i:s,disabled:!l&&!k,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 ml-0.5":k?"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?K:V,{size:18})})})]}),e("p",{className:"text-center text-[0.65rem] text-gray-400 dark:text-white/30 mt-1.5 opacity-70",children:_})]})};function ie(e){return e.replace(/```[\s\S]*?```/g," ").replace(/`([^`]+)`/g,"$1").replace(/\*\*(.+?)\*\*/g,"$1").replace(/__(.+?)__/g,"$1").replace(/#{1,6}\s+/g,"").replace(/^[ \t]*[-*>]+[ \t]*/gm,"").replace(/[ \t]+/g," ").replace(/\n{3,}/g,"\n\n").trim()}function le({content:t}){const n=a(null),[o,i]=r(!1),l=ie(t);return s(()=>{const e=n.current;e&&(e.scrollTop=e.scrollHeight,i(e.scrollHeight>e.clientHeight+1))},[l]),l.length<3?null:e("div",{className:"ml-11 mt-2.5 max-w-[75%] rounded-md border-l-2 bg-[var(--chat-accent)]/[0.03] py-2 pl-3 pr-3",style:{animation:"reasoningGlow 3s ease-in-out infinite, chat-fade-in 0.5s ease-out"},children:e("div",{ref:n,className:"max-h-40 overflow-hidden"+(o?" [-webkit-mask-image:linear-gradient(to_bottom,transparent_0,rgb(0_0_0/0.25)_1.5rem,rgb(0_0_0/0.7)_3rem,black_4.5rem)] [mask-image:linear-gradient(to_bottom,transparent_0,rgb(0_0_0/0.25)_1.5rem,rgb(0_0_0/0.7)_3rem,black_4.5rem)]":""),children:e("p",{className:"m-0 whitespace-pre-wrap break-words text-xs leading-5 text-gray-500 dark:text-white/45",children:l})})})}function ce(e){const t=Math.floor(e);if(t<60)return`${t}s`;const n=Math.floor(t/60),r=t%60;return r>0?`${n}m ${r}s`:`${n}m`}const de=({agentStatus:r,logoIcon:a,t:o})=>{const{label:s,StatusIcon:i,showDots:l}=function(e,t){if(!e)return{label:t("Thinking..."),StatusIcon:I,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:Q,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:J,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:J,showDots:!1}}let a,o=Y;if(r.some(e=>e.includes("search")||e.includes("list"))?o=G:r.some(e=>e.includes("read")||e.includes("get")||e.includes("query"))?o=E:r.some(e=>e.includes("send")||e.includes("create")||e.includes("draft")||e.includes("reply")||e.includes("flag"))?o=P:r.some(e=>e.includes("code")||e.includes("execute"))?o=Z: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:J,showDots:!1};case"steering":return{label:t("Incorporating your message…"),StatusIcon:J,showDots:!0};case"composing":return{label:t("Composing answer…"),StatusIcon:I,showDots:!0};case"consulting":{const n=e.tools?.[0]??"agent";return{label:`${t("Consulting")} ${n}…`,StatusIcon:Q,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:Q,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:J,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:J,showDots:!1}}case"transferring":{const n=e.tools?.[0]??"agent";return{label:`${t("Transferring to")} ${n}…`,StatusIcon:j,showDots:!1}}default:return{label:t("Thinking..."),StatusIcon:I,showDots:!1}}}(r,o),c=r?.thinkingContent,d=r?.elapsedS,h="number"==typeof d&&d>=15;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}),h&&e("span",{className:"text-xs text-gray-400 dark:text-white/30 tabular-nums shrink-0",children:ce(d)})]})]})]}),c&&e(le,{content:c})]})},he=e=>{if(!e)return!1;if(e.startsWith("//"))return!1;return!/^[a-zA-Z][a-zA-Z\d+.-]*:/.test(e)},ue=({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(L,{size:14,className:"text-green-500"}):e($,{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=(e=>{if(!e)return null;if(he(e))return e;if("undefined"==typeof window)return null;try{const t=new URL(e,window.location.href);if(("http:"===t.protocol||"https:"===t.protocol)&&t.origin===window.location.origin)return`${t.pathname}${t.search}${t.hash}`||"/"}catch{}return null})(t),o=null!==r&&!!a,s=!o&&!he(t);return e("a",{href:t,onClick:e=>{o&&(e.preventDefault(),a(r))},target:s?"_blank":void 0,rel:s?"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:h(n)})};function ge(e){const t=e.lastIndexOf(".");if(t<=0||t===e.length-1)return;const n=e.slice(t+1);return n.length<=8?n.toUpperCase():void 0}const me=({messages:o,isLoading:i,agentStatus:l,agentName:c,logoIcon:d,onRelativeLinkClick:h,onDownloadFile:u,t:m})=>{const p=a(null),[f,w]=r(null);s(()=>{p.current?.scrollIntoView({behavior:"smooth"})},[o]);const x=l?.thinkingContent?.length??0;s(()=>{x&&p.current?.scrollIntoView({behavior:"instant"})},[x]);const v=(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:()=>u?.(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(g,"");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(ue,{content:t.value,onRelativeLinkClick:h})},`t-${n}`));else if(u){const e=a.get(t.fileId);e&&(o.add(t.fileId),s.push(v(e,`f-${t.fileId}-${n}`)))}}),u&&(t.attachments??[]).forEach(e=>{o.has(e.fileId)||s.push(v(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},y=(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]},r),k=e=>{const t=[],n=new Set;return(e.files??[]).forEach((e,r)=>{!(!u||!e.fileId||"done"!==e.uploadStatus)&&e.fileId?(n.add(e.fileId),t.push(v({fileId:e.fileId,filename:e.name,type:ge(e.name),size:e.size,contentType:e.type},`file-${e.fileId}-${r}`))):t.push(y(e.name,`file-${r}`))}),(e.attachments??[]).forEach((e,r)=>{n.has(e.fileId)||(n.add(e.fileId),t.push(u?v(e,`att-${e.fileId}-${r}`):y(e.filename,`att-${r}`)))}),t};let N=-1;for(let e=o.length-1;e>=0;e--)if("assistant"===o[e].role){N=e;break}return t("div",{className:"flex-1 overflow-y-auto px-4 py-3 flex flex-col gap-4 filigran-chat-scrollable",children:[o.map((r,a)=>{const o="assistant"===r.role,s=!r.content,h=i&&a===N;return o&&s&&h?e("div",{children:e(de,{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&&((r.files?.length??0)>0||(r.attachments?.length??0)>0)&&e("div",{className:"flex gap-1.5 flex-wrap mb-1.5 justify-end",children:k(r)}),o?t("div",{className:"flex flex-col gap-1.5 w-full items-start",children:[b(r,h),!s&&h&&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&&!s&&!h&&(r.toolNames&&r.toolNames.length>0||(r.reasoning??"").trim())&&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(H,{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 max-w-[90%]",children:[t("div",{className:"flex items-center gap-1.5 mb-1",children:[e(Y,{size:13,className:"text-[var(--chat-accent)]"}),e("span",{className:"text-[0.75rem] font-semibold text-gray-900 dark:text-white",children:m("Reasoning details")})]}),t("p",{className:"text-[0.7rem] text-gray-500 dark:text-white/40 mb-1.5",children:[r.iterations&&r.iterations>1?`${r.iterations} ${m("iterations")} · `:"",r.toolCallCount??r.toolNames?.length??0," ",1===(r.toolCallCount??r.toolNames?.length??0)?m("tool call"):m("tool calls")]}),(r.reasoning??"").trim()&&t("div",{className:"mb-2",children:[t("div",{className:"flex items-center gap-1.5 mb-1",children:[e(I,{size:13,className:"text-[var(--chat-accent)]/70"}),e("span",{className:"text-[0.7rem] font-medium text-gray-500 dark:text-white/50",children:m("Model reasoning")})]}),e("div",{className:"rounded-md border border-gray-200 dark:border-white/[0.06] bg-white dark:bg-white/[0.01] px-2.5 py-2 max-h-44 overflow-y-auto",children:e("p",{className:"m-0 whitespace-pre-wrap break-words text-[0.7rem] leading-5 text-gray-500 dark:text-white/45",children:ie(r.reasoning)})})]}),r.toolNames&&r.toolNames.length>0&&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})]})},pe=({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))]})]}),fe=["Help me create a new simulation scenario","What are the latest attack patterns?","How do I configure detection rules?","Summarize my recent findings"],we=({mode:n,onClose:i,onModeChange:l,topOffset:c=0,apiBaseUrl:h,apiEndpoints:g,agentDashboardUrl:p,user:f,t:w=u,accentColor:x="#7b5cff",logoIcon:v,promptSuggestions:b=fe,draftBorderColor:S,resizable:I=!1,onWidthChange:L,onResizeStart:M,onResizeEnd:z,disableFileManagement:$=!1,onRelativeLinkClick:E,onDownloadError:T,maxFileCount:D,maxTotalSize:j,requestHeaders:R,pageContext:U,pushContentSelector:O,backendType:B="rest"})=>{const[W,F]=r(!1),{agents:H,selectedAgent:P,agentMenuOpen:G,setAgentMenuOpen:V,handleSwitchAgent:q}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[o,i]=r([]),[l,c]=r(null),[d,h]=r(!1);return s(()=>{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(k),n=t?e.find(e=>e.slug===t):null;c(n||e[0])}}).catch(()=>{})},[e,t,n,a]),{agents:o,selectedAgent:l,setSelectedAgent:c,agentMenuOpen:d,setAgentMenuOpen:h,handleSwitchAgent:(e,t)=>{e.id!==l?.id?(c(e),e.slug&&localStorage.setItem(k,e.slug),h(!1),t?.()):h(!1)}}}({apiBaseUrl:h,apiEndpoints:g,backendType:B,requestHeaders:R}),{messages:J,inputValue:K,setInputValue:Z,isLoading:X,agentStatus:Q,attachedFiles:Y,conversationId:ee,transferredAgent:te,canSteer:ne,historyLoadedRef:re,conversationIdRef:ae,handleFileAdd:ie,handlePaste:le,handleSendMessage:ce,handleNewChat:de,handleStopGenerating:he,setAttachedFiles:ue,setMessages:ge,updateConversationId:we,handleSwitchConversation:xe}=y({apiBaseUrl:h,apiEndpoints:g,backendType:B,agentSlug:P?.slug,requestHeaders:R,pageContext:U,t:w,maxFileCount:D,maxTotalSize:j}),{historyEnabled:ve,conversations:be,conversationsLoading:ye,refreshConversations:ke,deleteConversation:Ne}=function({apiBaseUrl:e,apiEndpoints:t,backendType:n="rest",requestHeaders:a}){const[s,i]=r([]),[l,c]=r(!1),d="rest"===n&&!t?.singleEndpoint&&null!==t?.sessions&&null!==t?.history,h=`${e}${t?.history??t?.sessions??"/chat/sessions"}`,u=o(async()=>{if(d){c(!0);try{const e=await fetch(h,{method:"GET",headers:{...a??{}}});if(!e.ok)return void i([]);const t=await e.json(),n=Array.isArray(t)?t:Array.isArray(t?.conversations)?t.conversations:[];i(n.map(N).filter(e=>null!==e))}catch{i([])}finally{c(!1)}}},[d,h,a]),g=o(async e=>{if(!d)return!1;try{return!!(await fetch(`${h}/${encodeURIComponent(e)}`,{method:"DELETE",headers:{...a??{}}})).ok&&(i(t=>t.filter(t=>t.conversationId!==e)),!0)}catch{return!1}},[d,h,a]);return{historyEnabled:d,conversations:s,conversationsLoading:l,refreshConversations:u,deleteConversation:g}}({apiBaseUrl:h,apiEndpoints:g,backendType:B,requestHeaders:R}),[Ce,_e]=r(!1),{sidebarWidth:Se,handleResizeStart:Ie,defaultWidth:Le,isResizing:Me}=function({mode:e,resizable:t,onWidthChange:n,onResizeStart:o,onResizeEnd:i}){const[l,c]=r(()=>{if("undefined"==typeof window)return C;const e=localStorage.getItem(_);if(e){const t=parseInt(e,10);if(!Number.isNaN(t)&&t>=C)return t}return C}),[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,s(()=>{"sidebar"===e&&t&&m.current?.(g.current)},[e,t]),s(()=>{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,C),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(_,String(g.current)),p.current?.())},a=()=>{const e=.4*window.innerWidth;if(g.current>e){const t=Math.max(e,C);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",o?.()},defaultWidth:C,isResizing:d}}({mode:n,resizable:I,onWidthChange:L,onResizeStart:M,onResizeEnd:z});s(()=>{const e="sidebar"===n?I?Se:Le: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)"),O){const e=document.querySelector(O);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")}},[O,n,Se,Le,I,Me]);const ze=v??e(A,{size:24}),$e=f.firstName,Ee=te?.name||P?.name||"Assistant",Ae=null!=g?.download,Te="rest"===B&&null!==g?.download&&(!g?.singleEndpoint||Ae),De=o(async e=>{const t=`${h}${g?.download??"/chat/files"}/${encodeURIComponent(e.fileId)}/download`;try{const n=await fetch(t,{method:"GET",credentials:"include",headers:{...R??{}}});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){T?.(t,e)}},[h,g,R,T]),je={"--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},Re=a(!0);s(()=>(Re.current=!0,()=>{Re.current=!1}),[]),s(()=>{if(null===g?.sessions||g?.singleEndpoint||"legacy"===B||"ag-ui"===B)return;if(!ee||re.current||!P)return;re.current=!0;const e=ee,t=()=>!Re.current||ae.current!==e;fetch(`${h}${g?.sessions??"/chat/sessions"}`,{method:"POST",headers:{"Content-Type":"application/json",...R??{}},body:JSON.stringify({conversation_id:ee,agent_slug:P.slug})}).then(e=>t()?null:e.ok?e.json():(we(null),null)).then(n=>{if(!n||t())return;if("string"==typeof n.conversation_id&&n.conversation_id&&n.conversation_id!==e&&we(n.conversation_id),!n.messages?.length)return;const r=n.messages.map((e,t)=>({id:`restored-${t}`,role:e.role,content:e.content,timestamp:new Date,attachments:m(e.attachments),toolNames:Array.isArray(e.tool_names)?e.tool_names:void 0,toolCallCount:"number"==typeof e.tool_call_count?e.tool_call_count:void 0,iterations:"number"==typeof e.iterations?e.iterations:void 0,reasoning:"string"==typeof e.reasoning?e.reasoning:void 0}));ge(r)}).catch(()=>{t()||we(null)})},[ee,P,h,g,B,re,ae,Re,R,ge,we]);const Ue=(()=>{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}})(),Oe={...je,..."sidebar"===n?{top:c,width:I?Se:Le}:"floating"===n?{width:380,height:560}:{top:c}};return t("div",{className:Ue,style:Oe,children:["sidebar"===n&&I&&e("div",{onMouseDown:Ie,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(oe,{mode:n,agentName:Ee,agents:H,selectedAgent:P,transferredFrom:te?P?.name:void 0,agentMenuOpen:G,onAgentMenuToggle:()=>V(e=>!e),onAgentMenuClose:()=>V(!1),onSwitchAgent:e=>{e&&q(e,()=>{de()})},modeMenuOpen:W,onModeMenuToggle:()=>F(e=>!e),onModeMenuClose:()=>F(!1),onModeChange:l,onNewChat:de,onClose:i,logoIcon:ze,agentDashboardUrl:p,historyEnabled:ve,historyMenuOpen:Ce,onHistoryMenuToggle:()=>{const e=!Ce;e&&ke(),_e(e)},onHistoryMenuClose:()=>_e(!1),conversations:be,conversationsLoading:ye,activeConversationId:ee,onSelectConversation:e=>{_e(!1),xe(e)},onDeleteConversation:e=>{(async e=>{await Ne(e)&&e===ae.current&&de()})(e)},t:w}),0===J.length?e(pe,{firstName:$e,logoIcon:ze,promptSuggestions:b,onPromptClick:Z,t:w}):e(me,{messages:J,isLoading:X,agentStatus:Q,agentName:Ee,logoIcon:ze,onRelativeLinkClick:E,onDownloadFile:Te?De:void 0,t:w}),e(se,{inputValue:K,onInputChange:Z,onSend:ce,onStop:he,isLoading:X,canSteer:ne,attachedFiles:$?[]:Y,onFileAdd:$?void 0:ie,onFileRemove:$?void 0:e=>ue(t=>t.filter((t,n)=>n!==e)),onPaste:$?void 0:le,t:w,mode:n,separatorColor:S})]})},xe=({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{we as ChatPanel,xe as ChatToggleButton};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|