@miiflow/assistant-ui 0.1.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.
Files changed (75) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +563 -0
  3. package/dist/WelcomeScreen-CsFaFNcu.d.mts +246 -0
  4. package/dist/WelcomeScreen-TrcbOYob.d.ts +246 -0
  5. package/dist/avatar-D5eHcfjf.d.mts +109 -0
  6. package/dist/avatar-DftdWqSs.d.ts +109 -0
  7. package/dist/branding-SzYU4ncD.d.mts +18 -0
  8. package/dist/branding-SzYU4ncD.d.ts +18 -0
  9. package/dist/chunk-3E2HG62U.mjs +2 -0
  10. package/dist/chunk-3E2HG62U.mjs.map +1 -0
  11. package/dist/chunk-3ERHTQXR.js +2 -0
  12. package/dist/chunk-3ERHTQXR.js.map +1 -0
  13. package/dist/chunk-3GQNGDXX.mjs +22 -0
  14. package/dist/chunk-3GQNGDXX.mjs.map +1 -0
  15. package/dist/chunk-3KB4JYSQ.js +2 -0
  16. package/dist/chunk-3KB4JYSQ.js.map +1 -0
  17. package/dist/chunk-BA3VCHRC.js +22 -0
  18. package/dist/chunk-BA3VCHRC.js.map +1 -0
  19. package/dist/chunk-CRNBTU42.mjs +2 -0
  20. package/dist/chunk-CRNBTU42.mjs.map +1 -0
  21. package/dist/chunk-KPGHBLGY.mjs +2 -0
  22. package/dist/chunk-KPGHBLGY.mjs.map +1 -0
  23. package/dist/chunk-LJQHWCUK.js +2 -0
  24. package/dist/chunk-LJQHWCUK.js.map +1 -0
  25. package/dist/chunk-MFCWFFJV.mjs +2 -0
  26. package/dist/chunk-MFCWFFJV.mjs.map +1 -0
  27. package/dist/chunk-NSTK5EUQ.js +2 -0
  28. package/dist/chunk-NSTK5EUQ.js.map +1 -0
  29. package/dist/chunk-OCKHJ4WO.js +2 -0
  30. package/dist/chunk-OCKHJ4WO.js.map +1 -0
  31. package/dist/chunk-RTT6LULU.mjs +2 -0
  32. package/dist/chunk-RTT6LULU.mjs.map +1 -0
  33. package/dist/client/index.d.mts +249 -0
  34. package/dist/client/index.d.ts +249 -0
  35. package/dist/client/index.js +9 -0
  36. package/dist/client/index.js.map +1 -0
  37. package/dist/client/index.mjs +9 -0
  38. package/dist/client/index.mjs.map +1 -0
  39. package/dist/context/index.d.mts +43 -0
  40. package/dist/context/index.d.ts +43 -0
  41. package/dist/context/index.js +2 -0
  42. package/dist/context/index.js.map +1 -0
  43. package/dist/context/index.mjs +2 -0
  44. package/dist/context/index.mjs.map +1 -0
  45. package/dist/hooks/index.d.mts +109 -0
  46. package/dist/hooks/index.d.ts +109 -0
  47. package/dist/hooks/index.js +2 -0
  48. package/dist/hooks/index.js.map +1 -0
  49. package/dist/hooks/index.mjs +2 -0
  50. package/dist/hooks/index.mjs.map +1 -0
  51. package/dist/index.d.mts +157 -0
  52. package/dist/index.d.ts +157 -0
  53. package/dist/index.js +2 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/index.mjs +2 -0
  56. package/dist/index.mjs.map +1 -0
  57. package/dist/message-B21_kqE2.d.ts +78 -0
  58. package/dist/message-ufYsvKXP.d.mts +78 -0
  59. package/dist/primitives/index.d.mts +86 -0
  60. package/dist/primitives/index.d.ts +86 -0
  61. package/dist/primitives/index.js +2 -0
  62. package/dist/primitives/index.js.map +1 -0
  63. package/dist/primitives/index.mjs +2 -0
  64. package/dist/primitives/index.mjs.map +1 -0
  65. package/dist/streaming-CF63E6iS.d.mts +426 -0
  66. package/dist/streaming-CF63E6iS.d.ts +426 -0
  67. package/dist/styled/index.d.mts +477 -0
  68. package/dist/styled/index.d.ts +477 -0
  69. package/dist/styled/index.js +2 -0
  70. package/dist/styled/index.js.map +1 -0
  71. package/dist/styled/index.mjs +2 -0
  72. package/dist/styled/index.mjs.map +1 -0
  73. package/dist/styles-no-preflight.css +1 -0
  74. package/dist/styles.css +1 -0
  75. package/package.json +100 -0
@@ -0,0 +1,109 @@
1
+ import * as react from 'react';
2
+ import { HTMLAttributes, ReactNode, TextareaHTMLAttributes, ButtonHTMLAttributes } from 'react';
3
+ import { M as MessageData, P as ParticipantRole } from './message-B21_kqE2.js';
4
+
5
+ interface MessageContextValue {
6
+ message: MessageData;
7
+ isViewer: boolean;
8
+ isStreaming: boolean;
9
+ }
10
+ declare const MessageContext: react.Context<MessageContextValue | null>;
11
+ /**
12
+ * Hook to access the current message context.
13
+ * Must be used within a Message component.
14
+ */
15
+ declare function useMessage(): MessageContextValue;
16
+ interface MessageProps extends HTMLAttributes<HTMLDivElement> {
17
+ /** The message data */
18
+ message: MessageData;
19
+ /** The viewer's role (used to determine alignment) */
20
+ viewerRole?: ParticipantRole;
21
+ /** Children to render inside the message */
22
+ children: ReactNode;
23
+ }
24
+ /**
25
+ * Headless Message primitive.
26
+ * Provides message context to children and data attributes for styling.
27
+ */
28
+ declare const Message: react.ForwardRefExoticComponent<MessageProps & react.RefAttributes<HTMLDivElement>>;
29
+ interface MessageContentProps extends HTMLAttributes<HTMLDivElement> {
30
+ /** Custom content to render instead of message text */
31
+ children?: ReactNode;
32
+ }
33
+ /**
34
+ * Renders the message content.
35
+ * By default renders the message's textContent.
36
+ */
37
+ declare const MessageContent: react.ForwardRefExoticComponent<MessageContentProps & react.RefAttributes<HTMLDivElement>>;
38
+ interface MessageTimestampProps extends HTMLAttributes<HTMLSpanElement> {
39
+ /** Custom date formatter */
40
+ format?: (date: Date) => string;
41
+ }
42
+ /**
43
+ * Renders the message timestamp.
44
+ */
45
+ declare const MessageTimestamp: react.ForwardRefExoticComponent<MessageTimestampProps & react.RefAttributes<HTMLSpanElement>>;
46
+
47
+ interface ComposerContextValue {
48
+ content: string;
49
+ isSubmitting: boolean;
50
+ canSubmit: boolean;
51
+ error: string | null;
52
+ handleContentChange: (value: string) => void;
53
+ handleSubmit: () => Promise<void>;
54
+ handleKeyDown: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void;
55
+ inputRef: React.RefObject<HTMLTextAreaElement | null>;
56
+ }
57
+ declare const ComposerContext: react.Context<ComposerContextValue | null>;
58
+ /**
59
+ * Hook to access the composer context.
60
+ * Must be used within a MessageComposer component.
61
+ */
62
+ declare function useComposer(): ComposerContextValue;
63
+ interface MessageComposerProps {
64
+ /** Callback when message is submitted */
65
+ onSubmit: (content: string, attachments?: File[]) => Promise<void>;
66
+ /** Whether the composer is disabled */
67
+ disabled?: boolean;
68
+ /** Children to render inside the composer */
69
+ children: ReactNode;
70
+ /** Additional CSS classes */
71
+ className?: string;
72
+ }
73
+ /**
74
+ * Headless MessageComposer primitive.
75
+ * Provides composer state and behavior to children.
76
+ */
77
+ declare const MessageComposer: react.ForwardRefExoticComponent<MessageComposerProps & react.RefAttributes<HTMLFormElement>>;
78
+ interface ComposerInputProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, "onChange" | "value"> {
79
+ }
80
+ /**
81
+ * Text input for the message composer.
82
+ */
83
+ declare const ComposerInput: react.ForwardRefExoticComponent<ComposerInputProps & react.RefAttributes<HTMLTextAreaElement>>;
84
+ interface ComposerSubmitProps extends ButtonHTMLAttributes<HTMLButtonElement> {
85
+ }
86
+ /**
87
+ * Submit button for the message composer.
88
+ */
89
+ declare const ComposerSubmit: react.ForwardRefExoticComponent<ComposerSubmitProps & react.RefAttributes<HTMLButtonElement>>;
90
+
91
+ interface AvatarProps extends HTMLAttributes<HTMLDivElement> {
92
+ /** Name for fallback initials */
93
+ name?: string;
94
+ /** Image URL */
95
+ src?: string;
96
+ /** Alt text for image */
97
+ alt?: string;
98
+ /** Participant role for styling */
99
+ role?: ParticipantRole;
100
+ /** Fallback content when no image or name */
101
+ fallback?: React.ReactNode;
102
+ }
103
+ /**
104
+ * Headless Avatar primitive.
105
+ * Renders an image or fallback initials.
106
+ */
107
+ declare const Avatar: react.ForwardRefExoticComponent<AvatarProps & react.RefAttributes<HTMLDivElement>>;
108
+
109
+ export { Avatar as A, ComposerContext as C, MessageComposer as M, ComposerInput as a, ComposerSubmit as b, MessageContent as c, MessageContext as d, Message as e, MessageTimestamp as f, useMessage as g, type AvatarProps as h, type ComposerInputProps as i, type ComposerSubmitProps as j, type MessageComposerProps as k, type MessageContentProps as l, type MessageProps as m, type MessageTimestampProps as n, useComposer as u };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Branding types for theming chat UI components.
3
+ */
4
+ interface BrandingData {
5
+ customName?: string;
6
+ messageFontSize?: number;
7
+ welcomeMessage?: string;
8
+ chatboxPlaceholder?: string;
9
+ backgroundBubbleColor?: string;
10
+ headerBackgroundColor?: string;
11
+ showHeader?: boolean;
12
+ rotatingPlaceholders?: string[];
13
+ presetQuestions?: string[];
14
+ chatbotLogo?: string;
15
+ assistantAvatar?: string;
16
+ }
17
+
18
+ export type { BrandingData as B };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Branding types for theming chat UI components.
3
+ */
4
+ interface BrandingData {
5
+ customName?: string;
6
+ messageFontSize?: number;
7
+ welcomeMessage?: string;
8
+ chatboxPlaceholder?: string;
9
+ backgroundBubbleColor?: string;
10
+ headerBackgroundColor?: string;
11
+ showHeader?: boolean;
12
+ rotatingPlaceholders?: string[];
13
+ presetQuestions?: string[];
14
+ chatbotLogo?: string;
15
+ assistantAvatar?: string;
16
+ }
17
+
18
+ export type { BrandingData as B };
@@ -0,0 +1,2 @@
1
+ import {useState,useRef,useCallback}from'react';function A(r={}){let[c,i]=useState({isStreaming:false,streamingMessageId:null,streamedContent:""}),n=useRef(null),m=useCallback(e=>{i({isStreaming:true,streamingMessageId:e,streamedContent:""}),n.current=new AbortController;},[]),d=useCallback(e=>{e.type==="content"&&e.content&&i(u=>({...u,streamedContent:u.streamedContent+e.content})),r.onChunk?.(e);},[r]),p=useCallback(()=>{n.current?.abort();let e=c.streamedContent;i({isStreaming:false,streamingMessageId:null,streamedContent:""}),r.onComplete?.(e);},[c.streamedContent,r]),f=useCallback(e=>{n.current?.abort(),i({isStreaming:false,streamingMessageId:null,streamedContent:""}),r.onError?.(e);},[r]);return {...c,startStreaming:m,appendContent:d,stopStreaming:p,handleError:f,abortSignal:n.current?.signal}}function x({maxCount:r=5,maxFileSize:c=10*1024*1024,allowedTypes:i}={}){let[n,m]=useState([]),d=useCallback(t=>{if(n.length>=r)return {success:false,error:`Maximum ${r} attachments allowed`};if(t.size>c)return {success:false,error:`File size exceeds ${Math.round(c/1024/1024)}MB limit`};if(i&&!i.includes(t.type))return {success:false,error:`File type ${t.type} not allowed`};let o=`${Date.now()}-${Math.random().toString(36).slice(2)}`;return m(a=>[...a,{file:t,id:o,progress:0,status:"pending"}]),{success:true}},[n.length,r,c,i]),p=useCallback(t=>{m(o=>o.filter(a=>a.id!==t));},[]),f=useCallback((t,o)=>{m(a=>a.map(s=>s.id===t?{...s,progress:o,status:o<100?"uploading":"complete"}:s));},[]),e=useCallback((t,o)=>{m(a=>a.map(s=>s.id===t?{...s,status:"error",error:o}:s));},[]),u=useCallback((t,o)=>{m(a=>a.map(s=>s.id===t?{...s,url:o,status:"complete",progress:100}:s));},[]),S=useCallback(()=>{m([]);},[]),C=useCallback(()=>n.map(t=>t.file),[n]);return {attachments:n,addAttachment:d,removeAttachment:p,updateProgress:f,setError:e,setUrl:u,clear:S,getFiles:C,canAddMore:n.length<r}}export{A as a,x as b};//# sourceMappingURL=chunk-3E2HG62U.mjs.map
2
+ //# sourceMappingURL=chunk-3E2HG62U.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-streaming.ts","../src/hooks/use-attachments.ts"],"names":["useStreaming","options","state","setState","useState","abortControllerRef","useRef","startStreaming","useCallback","messageId","appendContent","chunk","prev","stopStreaming","finalContent","handleError","error","useAttachments","maxCount","maxFileSize","allowedTypes","attachments","setAttachments","addAttachment","file","id","removeAttachment","updateProgress","progress","a","setError","setUrl","url","clear","getFiles"],"mappings":"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","file":"chunk-3E2HG62U.mjs","sourcesContent":["import { useState, useCallback, useRef } from \"react\";\nimport type { StreamingState, StreamChunk, StreamingOptions } from \"../types\";\n\n/**\n * Hook to manage streaming message state.\n */\nexport function useStreaming(options: StreamingOptions = {}) {\n const [state, setState] = useState<StreamingState>({\n isStreaming: false,\n streamingMessageId: null,\n streamedContent: \"\",\n });\n\n const abortControllerRef = useRef<AbortController | null>(null);\n\n const startStreaming = useCallback((messageId: string) => {\n setState({\n isStreaming: true,\n streamingMessageId: messageId,\n streamedContent: \"\",\n });\n abortControllerRef.current = new AbortController();\n }, []);\n\n const appendContent = useCallback(\n (chunk: StreamChunk) => {\n if (chunk.type === \"content\" && chunk.content) {\n setState((prev) => ({\n ...prev,\n streamedContent: prev.streamedContent + chunk.content,\n }));\n }\n options.onChunk?.(chunk);\n },\n [options]\n );\n\n const stopStreaming = useCallback(() => {\n abortControllerRef.current?.abort();\n const finalContent = state.streamedContent;\n\n setState({\n isStreaming: false,\n streamingMessageId: null,\n streamedContent: \"\",\n });\n\n options.onComplete?.(finalContent);\n }, [state.streamedContent, options]);\n\n const handleError = useCallback(\n (error: Error) => {\n abortControllerRef.current?.abort();\n setState({\n isStreaming: false,\n streamingMessageId: null,\n streamedContent: \"\",\n });\n options.onError?.(error);\n },\n [options]\n );\n\n return {\n ...state,\n startStreaming,\n appendContent,\n stopStreaming,\n handleError,\n abortSignal: abortControllerRef.current?.signal,\n };\n}\n","import { useState, useCallback } from \"react\";\n\ninterface AttachmentState {\n file: File;\n id: string;\n progress: number;\n status: \"pending\" | \"uploading\" | \"complete\" | \"error\";\n error?: string;\n url?: string;\n}\n\ninterface UseAttachmentsOptions {\n /** Maximum number of attachments */\n maxCount?: number;\n /** Maximum file size in bytes */\n maxFileSize?: number;\n /** Allowed MIME types */\n allowedTypes?: string[];\n}\n\n/**\n * Hook to manage file attachments with upload progress.\n */\nexport function useAttachments({\n maxCount = 5,\n maxFileSize = 10 * 1024 * 1024,\n allowedTypes,\n}: UseAttachmentsOptions = {}) {\n const [attachments, setAttachments] = useState<AttachmentState[]>([]);\n\n const addAttachment = useCallback(\n (file: File): { success: boolean; error?: string } => {\n // Check count\n if (attachments.length >= maxCount) {\n return { success: false, error: `Maximum ${maxCount} attachments allowed` };\n }\n\n // Check size\n if (file.size > maxFileSize) {\n return {\n success: false,\n error: `File size exceeds ${Math.round(maxFileSize / 1024 / 1024)}MB limit`,\n };\n }\n\n // Check type\n if (allowedTypes && !allowedTypes.includes(file.type)) {\n return { success: false, error: `File type ${file.type} not allowed` };\n }\n\n const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`;\n\n setAttachments((prev) => [\n ...prev,\n {\n file,\n id,\n progress: 0,\n status: \"pending\",\n },\n ]);\n\n return { success: true };\n },\n [attachments.length, maxCount, maxFileSize, allowedTypes]\n );\n\n const removeAttachment = useCallback((id: string) => {\n setAttachments((prev) => prev.filter((a) => a.id !== id));\n }, []);\n\n const updateProgress = useCallback((id: string, progress: number) => {\n setAttachments((prev) =>\n prev.map((a) =>\n a.id === id\n ? { ...a, progress, status: progress < 100 ? \"uploading\" : \"complete\" }\n : a\n )\n );\n }, []);\n\n const setError = useCallback((id: string, error: string) => {\n setAttachments((prev) =>\n prev.map((a) => (a.id === id ? { ...a, status: \"error\", error } : a))\n );\n }, []);\n\n const setUrl = useCallback((id: string, url: string) => {\n setAttachments((prev) =>\n prev.map((a) => (a.id === id ? { ...a, url, status: \"complete\", progress: 100 } : a))\n );\n }, []);\n\n const clear = useCallback(() => {\n setAttachments([]);\n }, []);\n\n const getFiles = useCallback(() => {\n return attachments.map((a) => a.file);\n }, [attachments]);\n\n return {\n attachments,\n addAttachment,\n removeAttachment,\n updateProgress,\n setError,\n setUrl,\n clear,\n getFiles,\n canAddMore: attachments.length < maxCount,\n };\n}\n"]}
@@ -0,0 +1,2 @@
1
+ 'use strict';var react=require('react');function A(r={}){let[c,i]=react.useState({isStreaming:false,streamingMessageId:null,streamedContent:""}),n=react.useRef(null),m=react.useCallback(e=>{i({isStreaming:true,streamingMessageId:e,streamedContent:""}),n.current=new AbortController;},[]),d=react.useCallback(e=>{e.type==="content"&&e.content&&i(u=>({...u,streamedContent:u.streamedContent+e.content})),r.onChunk?.(e);},[r]),p=react.useCallback(()=>{n.current?.abort();let e=c.streamedContent;i({isStreaming:false,streamingMessageId:null,streamedContent:""}),r.onComplete?.(e);},[c.streamedContent,r]),f=react.useCallback(e=>{n.current?.abort(),i({isStreaming:false,streamingMessageId:null,streamedContent:""}),r.onError?.(e);},[r]);return {...c,startStreaming:m,appendContent:d,stopStreaming:p,handleError:f,abortSignal:n.current?.signal}}function x({maxCount:r=5,maxFileSize:c=10*1024*1024,allowedTypes:i}={}){let[n,m]=react.useState([]),d=react.useCallback(t=>{if(n.length>=r)return {success:false,error:`Maximum ${r} attachments allowed`};if(t.size>c)return {success:false,error:`File size exceeds ${Math.round(c/1024/1024)}MB limit`};if(i&&!i.includes(t.type))return {success:false,error:`File type ${t.type} not allowed`};let o=`${Date.now()}-${Math.random().toString(36).slice(2)}`;return m(a=>[...a,{file:t,id:o,progress:0,status:"pending"}]),{success:true}},[n.length,r,c,i]),p=react.useCallback(t=>{m(o=>o.filter(a=>a.id!==t));},[]),f=react.useCallback((t,o)=>{m(a=>a.map(s=>s.id===t?{...s,progress:o,status:o<100?"uploading":"complete"}:s));},[]),e=react.useCallback((t,o)=>{m(a=>a.map(s=>s.id===t?{...s,status:"error",error:o}:s));},[]),u=react.useCallback((t,o)=>{m(a=>a.map(s=>s.id===t?{...s,url:o,status:"complete",progress:100}:s));},[]),S=react.useCallback(()=>{m([]);},[]),C=react.useCallback(()=>n.map(t=>t.file),[n]);return {attachments:n,addAttachment:d,removeAttachment:p,updateProgress:f,setError:e,setUrl:u,clear:S,getFiles:C,canAddMore:n.length<r}}exports.a=A;exports.b=x;//# sourceMappingURL=chunk-3ERHTQXR.js.map
2
+ //# sourceMappingURL=chunk-3ERHTQXR.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-streaming.ts","../src/hooks/use-attachments.ts"],"names":["useStreaming","options","state","setState","useState","abortControllerRef","useRef","startStreaming","useCallback","messageId","appendContent","chunk","prev","stopStreaming","finalContent","handleError","error","useAttachments","maxCount","maxFileSize","allowedTypes","attachments","setAttachments","addAttachment","file","id","removeAttachment","updateProgress","progress","a","setError","setUrl","url","clear","getFiles"],"mappings":"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","file":"chunk-3ERHTQXR.js","sourcesContent":["import { useState, useCallback, useRef } from \"react\";\nimport type { StreamingState, StreamChunk, StreamingOptions } from \"../types\";\n\n/**\n * Hook to manage streaming message state.\n */\nexport function useStreaming(options: StreamingOptions = {}) {\n const [state, setState] = useState<StreamingState>({\n isStreaming: false,\n streamingMessageId: null,\n streamedContent: \"\",\n });\n\n const abortControllerRef = useRef<AbortController | null>(null);\n\n const startStreaming = useCallback((messageId: string) => {\n setState({\n isStreaming: true,\n streamingMessageId: messageId,\n streamedContent: \"\",\n });\n abortControllerRef.current = new AbortController();\n }, []);\n\n const appendContent = useCallback(\n (chunk: StreamChunk) => {\n if (chunk.type === \"content\" && chunk.content) {\n setState((prev) => ({\n ...prev,\n streamedContent: prev.streamedContent + chunk.content,\n }));\n }\n options.onChunk?.(chunk);\n },\n [options]\n );\n\n const stopStreaming = useCallback(() => {\n abortControllerRef.current?.abort();\n const finalContent = state.streamedContent;\n\n setState({\n isStreaming: false,\n streamingMessageId: null,\n streamedContent: \"\",\n });\n\n options.onComplete?.(finalContent);\n }, [state.streamedContent, options]);\n\n const handleError = useCallback(\n (error: Error) => {\n abortControllerRef.current?.abort();\n setState({\n isStreaming: false,\n streamingMessageId: null,\n streamedContent: \"\",\n });\n options.onError?.(error);\n },\n [options]\n );\n\n return {\n ...state,\n startStreaming,\n appendContent,\n stopStreaming,\n handleError,\n abortSignal: abortControllerRef.current?.signal,\n };\n}\n","import { useState, useCallback } from \"react\";\n\ninterface AttachmentState {\n file: File;\n id: string;\n progress: number;\n status: \"pending\" | \"uploading\" | \"complete\" | \"error\";\n error?: string;\n url?: string;\n}\n\ninterface UseAttachmentsOptions {\n /** Maximum number of attachments */\n maxCount?: number;\n /** Maximum file size in bytes */\n maxFileSize?: number;\n /** Allowed MIME types */\n allowedTypes?: string[];\n}\n\n/**\n * Hook to manage file attachments with upload progress.\n */\nexport function useAttachments({\n maxCount = 5,\n maxFileSize = 10 * 1024 * 1024,\n allowedTypes,\n}: UseAttachmentsOptions = {}) {\n const [attachments, setAttachments] = useState<AttachmentState[]>([]);\n\n const addAttachment = useCallback(\n (file: File): { success: boolean; error?: string } => {\n // Check count\n if (attachments.length >= maxCount) {\n return { success: false, error: `Maximum ${maxCount} attachments allowed` };\n }\n\n // Check size\n if (file.size > maxFileSize) {\n return {\n success: false,\n error: `File size exceeds ${Math.round(maxFileSize / 1024 / 1024)}MB limit`,\n };\n }\n\n // Check type\n if (allowedTypes && !allowedTypes.includes(file.type)) {\n return { success: false, error: `File type ${file.type} not allowed` };\n }\n\n const id = `${Date.now()}-${Math.random().toString(36).slice(2)}`;\n\n setAttachments((prev) => [\n ...prev,\n {\n file,\n id,\n progress: 0,\n status: \"pending\",\n },\n ]);\n\n return { success: true };\n },\n [attachments.length, maxCount, maxFileSize, allowedTypes]\n );\n\n const removeAttachment = useCallback((id: string) => {\n setAttachments((prev) => prev.filter((a) => a.id !== id));\n }, []);\n\n const updateProgress = useCallback((id: string, progress: number) => {\n setAttachments((prev) =>\n prev.map((a) =>\n a.id === id\n ? { ...a, progress, status: progress < 100 ? \"uploading\" : \"complete\" }\n : a\n )\n );\n }, []);\n\n const setError = useCallback((id: string, error: string) => {\n setAttachments((prev) =>\n prev.map((a) => (a.id === id ? { ...a, status: \"error\", error } : a))\n );\n }, []);\n\n const setUrl = useCallback((id: string, url: string) => {\n setAttachments((prev) =>\n prev.map((a) => (a.id === id ? { ...a, url, status: \"complete\", progress: 100 } : a))\n );\n }, []);\n\n const clear = useCallback(() => {\n setAttachments([]);\n }, []);\n\n const getFiles = useCallback(() => {\n return attachments.map((a) => a.file);\n }, [attachments]);\n\n return {\n attachments,\n addAttachment,\n removeAttachment,\n updateProgress,\n setError,\n setUrl,\n clear,\n getFiles,\n canAddMore: attachments.length < maxCount,\n };\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import {l,m,c,d,f,r}from'./chunk-MFCWFFJV.mjs';import {a}from'./chunk-RTT6LULU.mjs';import {forwardRef,useState,useContext,useMemo,useRef,useCallback,useEffect}from'react';import {X,Zap,ExternalLink,Search,Mail,Copy,Navigation,Send,Loader2,Paperclip,ArrowUp,Image,FileText,File,User,Bot,Link,ArrowRight,Sparkle,MessageCircle,AlertCircle,MessageCircleQuestion,Check,Users,GitBranch,Terminal,Globe,Wrench,ListTodo,Download,CheckCircle2,XCircle,ChevronDown,ChevronRight,Eye,Save,Pencil,Clock,FileSearch,FolderSearch,ChevronUp,Video,FileIcon,CircleDashed,CircleCheck,CircleX,MoreVertical,Circle}from'lucide-react';import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {jsxs,jsx,Fragment}from'react/jsx-runtime';import yr from'react-markdown';import hr from'remark-gfm';import {Prism}from'react-syntax-highlighter';import {oneLight,oneDark}from'react-syntax-highlighter/dist/esm/styles/prism';import {AnimatePresence,motion}from'framer-motion';import {ResponsiveContainer,ScatterChart,CartesianGrid,XAxis,YAxis,Tooltip,Legend,Scatter,PieChart,Pie,Cell,AreaChart,Area,BarChart,Bar,LineChart,Line}from'recharts';import {z}from'zod';import {AutoLinkNode}from'@lexical/link';import {ListItemNode,ListNode}from'@lexical/list';import {$convertToMarkdownString,BOLD_STAR,ITALIC_UNDERSCORE,QUOTE,ORDERED_LIST,UNORDERED_LIST,$convertFromMarkdownString}from'@lexical/markdown';import {LexicalComposer}from'@lexical/react/LexicalComposer';import {ContentEditable}from'@lexical/react/LexicalContentEditable';import {LexicalErrorBoundary}from'@lexical/react/LexicalErrorBoundary';import {HistoryPlugin}from'@lexical/react/LexicalHistoryPlugin';import {ListPlugin}from'@lexical/react/LexicalListPlugin';import {RichTextPlugin}from'@lexical/react/LexicalRichTextPlugin';import {OnChangePlugin}from'@lexical/react/LexicalOnChangePlugin';import {AutoFocusPlugin}from'@lexical/react/LexicalAutoFocusPlugin';import {QuoteNode}from'@lexical/rich-text';import {useLexicalComposerContext}from'@lexical/react/LexicalComposerContext';import {KEY_ENTER_COMMAND,COMMAND_PRIORITY_HIGH,$getRoot,$createParagraphNode}from'lexical';function i(...e){return twMerge(clsx(e))}function nr(e){return e.startsWith("image/")?Image:e==="application/pdf"||e.startsWith("text/")?FileText:File}function or(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}var pa=forwardRef(({attachment:e,onRemove:a,removable:r=true,className:t},n)=>{let s=nr(e.mimeType),o=e.mimeType.startsWith("image/");return jsxs("div",{ref:n,className:i("relative group","flex items-center gap-2","p-2 rounded-lg","border border-chat-border","bg-chat-panel-bg",t),children:[jsx("div",{className:i("w-10 h-10 rounded","flex items-center justify-center","bg-gray-100 dark:bg-gray-800","overflow-hidden flex-shrink-0"),children:o&&e.previewUrl?jsx("img",{src:e.previewUrl,alt:e.filename,className:"w-full h-full object-cover"}):jsx(s,{className:"w-5 h-5 text-chat-subtle"})}),jsxs("div",{className:"flex-1 min-w-0",children:[jsx("p",{className:"text-sm font-medium truncate text-chat-text",children:e.filename}),jsx("p",{className:"text-xs text-chat-subtle",children:or(e.size)})]}),r&&a&&jsx("button",{type:"button",onClick:a,className:i("absolute -top-1.5 -right-1.5","w-5 h-5 rounded-full","flex items-center justify-center","bg-gray-500 text-white","opacity-0 group-hover:opacity-100","hover:bg-gray-600","transition-opacity duration-200"),"aria-label":`Remove ${e.filename}`,children:jsx(X,{className:"w-3 h-3"})})]})});pa.displayName="AttachmentPreview";var lr={sm:"w-6 h-6 text-xs",md:"w-8 h-8 text-sm",lg:"w-10 h-10 text-base"},cr={sm:14,md:16,lg:20};function pr(e,a){let r=cr[a];switch(e){case "assistant":return jsx(Bot,{size:r});case "user":return jsx(User,{size:r});default:return jsx(User,{size:r})}}var Ie=forwardRef(({name:e,src:a,alt:r,role:t,size:n="md",className:s,...o},l$1)=>jsx(l,{ref:l$1,name:e,src:a,alt:r,role:t,className:i("rounded-full overflow-hidden flex-shrink-0","flex items-center justify-center","font-medium",t==="assistant"?"bg-primary/10 text-primary":"bg-gray-200 dark:bg-gray-700 text-gray-600 dark:text-gray-300",lr[n],s),fallback:pr(t,n),...o}));Ie.displayName="Avatar";var ma=forwardRef(({children:e,className:a,...r},t)=>jsx("div",{ref:t,className:i("flex flex-col h-full","bg-white dark:bg-gray-900","font-sans text-chat-text",a),...r,children:e}));ma.displayName="ChatContainer";var ur={small:"w-1.5 h-1.5",medium:"w-2 h-2",large:"w-2.5 h-2.5"},gr={small:"gap-1",medium:"gap-1.5",large:"gap-2"};function We({size:e="medium",className:a}){let r=ur[e];return jsxs("div",{className:i("flex items-center",gr[e],a),children:[jsx("div",{className:i(r,"rounded-full bg-[var(--chat-text-subtle)]","animate-loading-dot animate-loading-dot-1")}),jsx("div",{className:i(r,"rounded-full bg-[var(--chat-text-subtle)]","animate-loading-dot animate-loading-dot-2")}),jsx("div",{className:i(r,"rounded-full bg-[var(--chat-text-subtle)]","animate-loading-dot animate-loading-dot-3")})]})}var Sr={js:"javascript",ts:"typescript",jsx:"jsx",tsx:"tsx",py:"python",rb:"ruby",rs:"rust",go:"go",java:"java",cpp:"cpp",c:"c",cs:"csharp",swift:"swift",kt:"kotlin",php:"php",sql:"sql",sh:"bash",bash:"bash",zsh:"bash",shell:"bash",html:"html",css:"css",scss:"scss",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",md:"markdown",graphql:"graphql",dockerfile:"docker",toml:"toml"};function zr(e){return Sr[e.toLowerCase()]||e.toLowerCase()}function Tt(e){return e.toLowerCase().replace(/[^\w\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim()}function Pr({text:e}){let[a,r]=useState(false),t=useCallback(async()=>{try{await navigator.clipboard.writeText(e),r(!0),setTimeout(()=>r(!1),2e3);}catch{}},[e]);return jsxs("button",{onClick:t,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-white/10 transition-colors text-gray-400 hover:text-gray-200","aria-label":a?"Copied":"Copy code",children:[a?jsx(Check,{size:14}):jsx(Copy,{size:14}),a?"Copied":"Copy"]})}function re({children:e,className:a,baselineFontSize:r=1,darkCodeTheme:t}){let n=t??(typeof window<"u"&&window.matchMedia?.("(prefers-color-scheme: dark)").matches),s=r!==1?{fontSize:`${r}rem`}:void 0;return jsx(yr,{className:i("chat-prose",a),remarkPlugins:[hr],components:{h1:({children:o})=>{let l=String(o),p=Tt(l);return jsxs("h1",{id:p,className:"group text-xl font-semibold mt-4 mb-2 first:mt-0",style:s,children:[o,jsx("a",{href:`#${p}`,className:"ml-2 opacity-0 group-hover:opacity-50 transition-opacity","aria-label":"Link to heading",children:jsx(Link,{size:16,className:"inline"})})]})},h2:({children:o})=>{let l=String(o),p=Tt(l);return jsxs("h2",{id:p,className:"group text-lg font-semibold mt-3 mb-2 first:mt-0",style:s,children:[o,jsx("a",{href:`#${p}`,className:"ml-2 opacity-0 group-hover:opacity-50 transition-opacity","aria-label":"Link to heading",children:jsx(Link,{size:14,className:"inline"})})]})},h3:({children:o})=>{let l=String(o),p=Tt(l);return jsxs("h3",{id:p,className:"group text-base font-medium mt-2 mb-1 first:mt-0",style:s,children:[o,jsx("a",{href:`#${p}`,className:"ml-2 opacity-0 group-hover:opacity-50 transition-opacity","aria-label":"Link to heading",children:jsx(Link,{size:12,className:"inline"})})]})},h4:({children:o})=>jsx("h4",{className:"text-base font-medium mt-2 mb-1 first:mt-0",style:s,children:o}),p:({children:o})=>jsx("p",{className:"mb-2 last:mb-0 leading-relaxed",style:s,children:o}),a:({href:o,children:l})=>jsx("a",{href:o,target:"_blank",rel:"noopener noreferrer",className:"text-primary underline hover:opacity-80 transition-opacity",style:s,children:l}),ul:({children:o})=>jsx("ul",{className:"list-disc pl-4 mb-2 space-y-1",children:o}),ol:({children:o})=>jsx("ol",{className:"list-decimal pl-4 mb-2 space-y-1",children:o}),li:({children:o})=>jsx("li",{className:"leading-relaxed",style:s,children:o}),blockquote:({children:o})=>jsx("blockquote",{className:"border-l-2 border-gray-300 dark:border-gray-600 pl-3 my-2 italic text-chat-subtle",style:s,children:o}),code:({className:o,children:l})=>{let p=/language-(\w+)/.exec(o||""),d=String(l).replace(/\n$/,"");if(!p&&!d.includes(`
2
+ `))return jsx("code",{className:"bg-gray-100 dark:bg-gray-800 px-1.5 py-0.5 rounded text-sm font-mono",style:s,children:l});let x=p?zr(p[1]):"text";return jsxs("div",{className:"relative group my-2 rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700",children:[jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-gray-800 dark:bg-gray-900 border-b border-gray-700",children:[jsx("span",{className:"text-xs font-mono text-gray-400",children:x}),jsx(Pr,{text:d})]}),jsx(Prism,{language:x,style:n===false?oneLight:oneDark,customStyle:{margin:0,borderRadius:0,fontSize:"0.8125rem",lineHeight:"1.6"},codeTagProps:{style:{fontFamily:"'Fira Code', 'JetBrains Mono', monospace"}},children:d})]})},pre:({children:o})=>jsx(Fragment,{children:o}),table:({children:o})=>jsx("div",{className:"overflow-x-auto my-2 rounded-lg border border-gray-200 dark:border-gray-700",children:jsx("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:o})}),thead:({children:o})=>jsx("thead",{className:"bg-gray-50 dark:bg-gray-800",children:o}),th:({children:o})=>jsx("th",{className:"px-3 py-2 text-left text-sm font-medium text-gray-700 dark:text-gray-300",style:s,children:o}),td:({children:o})=>jsx("td",{className:"px-3 py-2 text-sm text-gray-600 dark:text-gray-400 border-t border-gray-100 dark:border-gray-700",style:s,children:o}),hr:()=>jsx("hr",{className:"my-4 border-gray-200 dark:border-gray-700"}),strong:({children:o})=>jsx("strong",{className:"font-semibold",children:o}),em:({children:o})=>jsx("em",{className:"italic",children:o}),img:({src:o,alt:l})=>jsx("img",{src:o,alt:l??"",className:"max-w-full h-auto rounded-lg my-2",loading:"lazy"})},children:e})}function ga(e){switch(e){case "knowledge_base":return {label:"Knowledge Base",color:"#4caf50"};case "api":return {label:"API",color:"#2196f3"};case "system_tool":return {label:"Tool",color:"#ff9800"};case "mcp_tool":return {label:"MCP",color:"#9c27b0"};case "workflow":return {label:"Workflow",color:"#00bcd4"};default:return {label:"Source",color:"#757575"}}}function Rt({sources:e,className:a}){let[r,t]=useState(null);return !e||e.length===0?null:jsxs(Fragment,{children:[jsx("div",{className:i("flex flex-wrap gap-1.5 mt-2",a),children:e.map(n=>{let s=ga(n.source_type);return jsxs("button",{onClick:()=>t(n),className:"inline-flex items-center h-6 px-2 text-[0.75rem] font-medium rounded-full border cursor-pointer transition-colors max-w-[280px] truncate",style:{backgroundColor:s.color+"1a",color:s.color,borderColor:s.color+"40"},children:["[",n.index,"] ",n.title]},n.index)})}),jsx(fa,{source:r,onClose:()=>t(null)})]})}function fa({source:e,onClose:a}){if(useEffect(()=>{if(!e)return;let t=n=>{n.key==="Escape"&&a();};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[e,a]),!e)return null;let r=ga(e.source_type);return jsx(AnimatePresence,{children:e&&jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center p-4",children:[jsx(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-black/50",onClick:a}),jsxs(motion.div,{initial:{opacity:0,scale:.95,y:10},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:10},transition:{duration:.15},className:"relative bg-white dark:bg-gray-900 rounded-xl shadow-xl border border-gray-200 dark:border-gray-700 w-full max-w-2xl max-h-[80vh] flex flex-col overflow-hidden",children:[jsxs("div",{className:"flex items-center justify-between p-4 border-b border-gray-200 dark:border-gray-700",children:[jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[jsx("h3",{className:"text-lg font-semibold truncate",children:e.title}),jsx("span",{className:"text-[0.7rem] px-1.5 py-0.5 rounded font-medium shrink-0",style:{backgroundColor:r.color+"1a",color:r.color},children:r.label})]}),jsx("button",{onClick:a,className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 ml-2",children:jsx(X,{size:16})})]}),jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[jsxs("div",{className:"flex flex-wrap gap-1.5 mb-4",children:[jsx("span",{className:"text-[0.7rem] px-1.5 py-0.5 rounded border border-gray-200 dark:border-gray-700",children:e.tool_name.replace(/_/g," ")}),e.query&&jsxs("span",{className:"text-[0.7rem] px-1.5 py-0.5 rounded border border-gray-200 dark:border-gray-700 max-w-[200px] truncate",title:e.query,children:["Query: ",e.query.slice(0,40),e.query.length>40?"...":""]})]}),e.url&&jsx("div",{className:"mb-4",children:jsxs("a",{href:e.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm text-blue-500 hover:underline inline-flex items-center gap-1",children:[e.url.length>80?`${e.url.slice(0,80)}...`:e.url,jsx(ExternalLink,{size:12})]})}),e.description&&jsx("p",{className:"text-sm text-gray-500 mb-4",children:e.description}),e.full_content?jsx("div",{className:"whitespace-pre-wrap font-mono text-sm leading-relaxed p-4 rounded-lg bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700 max-h-[400px] overflow-auto",children:e.full_content}):e.snippet?jsx("div",{className:"whitespace-pre-wrap font-mono text-sm leading-relaxed p-4 rounded-lg bg-gray-50 dark:bg-gray-800/50 border border-gray-200 dark:border-gray-700",children:e.snippet}):jsx("p",{className:"text-sm text-gray-400 italic",children:"No content available for this source."})]}),jsx("div",{className:"flex justify-end p-3 border-t border-gray-200 dark:border-gray-700",children:jsx("button",{onClick:a,className:"px-3 py-1.5 text-sm rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors",children:"Close"})})]})]})})}function _r({index:e,source:a}){return jsx("span",{className:i("inline-flex items-center justify-center min-w-[16px] h-4 rounded-full","bg-blue-500 text-white text-[0.6rem] font-semibold","px-0.5 mx-0.5 align-super",a?.url?"cursor-pointer hover:opacity-85":"cursor-default"),title:a?`${a.title}${a.description?": "+a.description:""}`:void 0,onClick:r=>{a?.url&&(r.stopPropagation(),window.open(a.url,"_blank","noopener,noreferrer"));},children:e})}function Mt({clarification:e,onSubmit:a,onOptionSelect:r,disabled:t=false,loading:n=false,className:s}){let[o,l]=useState(""),p=useCallback(v=>{v.trim()&&(l(""),a(v.trim()));},[a]),d=v=>{let g=v.target.value;r?.(g),p(g);},f=v=>{v.key==="Enter"&&!v.shiftKey&&o.trim()&&(v.preventDefault(),p(o));},x=e.options&&e.options.length>0,h=e.allowFreeText!==false;return jsxs("div",{className:i("mx-4 mb-3 px-4 py-3","bg-orange-50/60 dark:bg-orange-950/20","border-l-[3px] border-orange-400","rounded-r-lg",s),children:[jsxs("div",{className:i("flex items-start gap-2",(x||h)&&"mb-2"),children:[jsx("span",{className:"text-orange-600 mt-0.5",children:jsx(MessageCircle,{size:14})}),jsx("p",{className:"text-sm font-medium",children:e.question})]}),x&&jsx("div",{className:i("ml-5 space-y-1",h&&"mb-2"),children:e.options.map((v,g)=>jsxs("label",{className:"flex items-center gap-2 py-0.5 cursor-pointer text-sm hover:bg-orange-100/50 dark:hover:bg-orange-900/20 rounded px-1 -mx-1",children:[jsx("input",{type:"radio",name:"clarification-option",value:v,onChange:d,disabled:t||n,className:"accent-orange-500 w-3.5 h-3.5"}),v]},g))}),h&&jsxs("div",{className:"flex items-center ml-5 bg-white dark:bg-gray-900 rounded border border-orange-200 dark:border-orange-800 px-3 py-1",children:[jsx("input",{type:"text",value:o,onChange:v=>l(v.target.value),onKeyDown:f,placeholder:x?"Or type your response...":"Type your response...",disabled:t||n,className:"flex-1 text-sm bg-transparent outline-none placeholder:text-gray-400 disabled:opacity-50"}),jsx("button",{onClick:()=>p(o),disabled:!o.trim()||t||n,className:i("p-1 rounded transition-colors",o.trim()?"text-orange-600 hover:text-orange-700":"text-gray-300"),children:jsx(Send,{size:16})})]})]})}function _t({attachments:e,onDownload:a,onPreview:r,className:t}){let[n,s]=useState(null);if(!e||e.length===0)return null;let o=p=>{if(a){a(p);return}if(p.url){let d=document.createElement("a");d.href=p.url,d.download=p.filename,d.target="_blank",document.body.appendChild(d),d.click(),document.body.removeChild(d);}},l=p=>{if(r){r(p);return}p.isImage&&p.url&&s(p.url);};return jsxs("div",{className:i("flex flex-wrap gap-1.5",t),children:[e.map(p=>jsx(qr,{attachment:p,onDownload:()=>o(p),onPreview:()=>l(p)},p.id)),n&&jsxs("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:()=>s(null),children:[jsx("button",{className:"absolute top-4 right-4 p-2 text-white hover:bg-white/20 rounded-full transition-colors",onClick:()=>s(null),"aria-label":"Close",children:jsx(X,{size:24})}),jsx("img",{src:n,alt:"Preview",className:"max-w-[90vw] max-h-[90vh] object-contain",onClick:p=>p.stopPropagation()})]})]})}function qr({attachment:e,onDownload:a,onPreview:r}){let t=e.humanReadableSize||Xr(e.size);return jsxs("div",{className:i("inline-flex items-center gap-2 px-2.5 py-1.5 rounded-lg max-w-full","border border-[var(--chat-border)] bg-[var(--chat-panel-bg)]",e.isImage&&e.url&&"cursor-pointer hover:bg-[var(--chat-border)]/30"),onClick:e.isImage&&e.url?r:void 0,children:[jsx(Gr,{mimeType:e.mimeType,size:14}),jsx("span",{className:"text-xs text-[var(--chat-text)] truncate min-w-0",children:e.filename}),t&&t!=="0 Bytes"&&jsx("span",{className:"text-[10px] text-[var(--chat-text-subtle)] flex-shrink-0",children:t}),e.url&&jsx("button",{onClick:n=>{n.stopPropagation(),a();},className:"p-0.5 hover:bg-[var(--chat-border)] rounded transition-colors flex-shrink-0","aria-label":"Download",children:jsx(Download,{size:12,className:"text-[var(--chat-text-subtle)]"})})]})}function Gr({mimeType:e,size:a=14}){return e.startsWith("image/")?jsx(Image,{size:a,className:"text-[var(--chat-primary)] flex-shrink-0"}):e.startsWith("video/")?jsx(Video,{size:a,className:"text-[var(--chat-primary)] flex-shrink-0"}):e==="application/pdf"?jsx(FileText,{size:a,className:"text-red-500 flex-shrink-0"}):jsx(FileIcon,{size:a,className:"text-gray-500 flex-shrink-0"})}function Xr(e){if(e===0)return "0 Bytes";let a=1024,r=["Bytes","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(a));return parseFloat((e/Math.pow(a,t)).toFixed(2))+" "+r[t]}var ba="miiflow-beamer-keyframes";function Pe(e){if(typeof document>"u")return;let a=e?.getRootNode?.(),r=a instanceof ShadowRoot?a:document.head;if(r.querySelector(`#${ba}`))return;let t=document.createElement("style");t.id=ba,t.textContent="@keyframes beamer{0%{left:-30%}100%{left:100%}}",r.appendChild(t);}var Ee={position:"absolute",top:0,left:"-30%",width:"30%",height:"100%",background:"linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.7) 50%, transparent 100%)",animation:"beamer 2s linear infinite",zIndex:1,pointerEvents:"none"};function Qe({status:e,size:a=16,className:r}){let t=Math.max(a-4,10);return jsxs("div",{className:i("relative flex-shrink-0 flex items-center justify-center",r),style:{width:a,height:a},children:[e==="pending"&&jsx(CircleDashed,{size:a,strokeWidth:2,className:"text-[var(--chat-text-subtle)] opacity-40"}),e==="running"&&jsxs("div",{className:"relative flex items-center justify-center",style:{width:a,height:a},children:[jsx("div",{className:"absolute inset-0 rounded-full bg-indigo-500/20 animate-ping",style:{animationDuration:"1.5s"}}),jsx("div",{className:"relative rounded-full bg-gradient-to-br from-indigo-500 to-purple-500 p-[2px] animate-pulse-glow",children:jsx("div",{className:"rounded-full bg-white dark:bg-gray-900 flex items-center justify-center",style:{width:t,height:t},children:jsx(Loader2,{size:t-2,strokeWidth:2.5,className:"text-indigo-500 animate-spin"})})})]}),e==="completed"&&jsx("div",{className:"animate-complete-pop",children:jsx("div",{className:"rounded-full animate-success-flash",children:jsx(CircleCheck,{size:a,strokeWidth:2,className:"text-green-500"})})}),e==="failed"&&jsx(CircleX,{size:a,strokeWidth:2,className:"text-red-500"})]})}function De({items:e,badgeSize:a=20,className:r}){let t=useRef(null);return useEffect(()=>{Pe(t.current);},[]),e.length===0?null:jsx("div",{ref:t,className:i("max-w-full",r),children:jsx("div",{className:"flex flex-col",children:e.map((n,s)=>{let o=s===e.length-1,p=(o?null:e[s+1])?.status==="pending",d=n.status==="running"&&!o;return jsxs("div",{className:"animate-fade-in",style:{display:"grid",gridTemplateColumns:`${a}px 1fr`,gap:"0.5rem",paddingBottom:o?0:"0.5rem",position:"relative"},children:[jsxs("div",{className:"relative flex flex-col items-center flex-shrink-0",style:{paddingTop:"4px"},children:[jsx(Qe,{status:n.status,size:a}),!o&&(d?jsx("div",{className:"absolute left-1/2 -translate-x-1/2 w-[2px] animate-flow-down",style:{top:a+6,height:`calc(100% - ${a}px + 4px)`,background:`repeating-linear-gradient(
3
+ 180deg,
4
+ rgb(99, 102, 241) 0px,
5
+ rgb(99, 102, 241) 4px,
6
+ transparent 4px,
7
+ transparent 8px
8
+ )`,zIndex:1}}):jsx("div",{className:"absolute left-1/2 -translate-x-1/2",style:{top:a+6,height:`calc(100% - ${a}px + 4px)`,width:0,borderLeft:"2px",borderStyle:p?"dashed":"solid",borderColor:"var(--chat-border)",zIndex:1}}))]}),jsxs("div",{style:{minWidth:0,flex:1,display:"flex",alignItems:"center",position:"relative",overflow:"hidden",borderRadius:4,...n.status==="running"&&{backgroundColor:"rgba(0, 0, 0, 0.02)",padding:"2px 4px"}},children:[n.status==="running"&&jsx("div",{style:Ee}),n.content]})]},n.id)})})})}function en({status:e,isLast:a=false,badgeSize:r=16,children:t,className:n}){let s=useRef(null);useEffect(()=>{Pe(s.current);},[]);let o=e==="running"&&!a;return jsxs("div",{ref:s,className:i("relative flex items-start gap-3 animate-fade-in",!a&&"pb-3",n),children:[jsxs("div",{className:"relative flex-shrink-0 pt-0.5",children:[jsx(Qe,{status:e,size:r}),!a&&(o?jsx("div",{className:"absolute w-[2px] animate-flow-down",style:{left:r/2-1,top:r+4,height:"calc(100% + 12px)",background:`repeating-linear-gradient(
9
+ 180deg,
10
+ rgb(99, 102, 241) 0px,
11
+ rgb(99, 102, 241) 4px,
12
+ transparent 4px,
13
+ transparent 8px
14
+ )`,zIndex:1}}):jsx("div",{className:"absolute bg-[var(--chat-border)] opacity-30",style:{left:r/2-.5,top:r+4,height:"calc(100% + 12px)",width:1,zIndex:1}}))]}),jsxs("div",{style:{minWidth:0,flex:1,position:"relative",overflow:"hidden",borderRadius:4,...e==="running"&&{backgroundColor:"rgba(0, 0, 0, 0.02)",padding:"2px 4px"}},children:[e==="running"&&jsx("div",{style:Ee}),t]})]})}function Lt({event:e,className:a,isRunning:r}){let t=useRef(null);if(useEffect(()=>{Pe(t.current);},[]),e.type==="thinking")return jsx("div",{ref:t,className:i("p-1 rounded transition-colors","bg-black/[0.01] hover:bg-black/[0.02]",a),children:jsx("div",{className:"text-[var(--chat-text-subtle)] leading-relaxed",children:jsx(re,{className:"text-[14px]",children:e.content})})});if(e.type==="planning")return jsx("div",{ref:t,className:i("p-1 rounded transition-colors","bg-black/[0.01] hover:bg-black/[0.02]",a),children:jsx("div",{className:"text-[var(--chat-text-subtle)] leading-relaxed",children:jsx(re,{className:"text-[14px]",children:e.content})})});if(e.type==="tool")return jsxs("div",{ref:t,className:i("inline-flex items-center gap-1.5",a),style:{position:"relative",overflow:"hidden",borderRadius:4,...r&&{backgroundColor:"rgba(0, 0, 0, 0.02)",padding:"2px 4px"}},children:[r&&jsx("div",{style:Ee}),jsx(Wrench,{size:14,className:"text-black/50 relative z-10 shrink-0"}),jsx("span",{className:"text-[14px] text-black/65 relative z-10",children:e.toolDescription||e.toolName})]});if(e.type==="observation"){let n=e.success!==false;return jsxs("div",{ref:t,className:i("px-3 py-1.5 rounded max-w-full overflow-auto",n?"bg-green-50 border-l-[3px] border-green-400":"bg-yellow-50 border-l-[3px] border-yellow-400",a),children:[jsxs("span",{className:i("text-xs font-semibold uppercase tracking-wide block mb-1",n?"text-green-700":"text-yellow-700"),children:[e.toolName," Result"]}),jsx("div",{className:i(n?"text-green-900":"text-yellow-900"),children:jsx(re,{className:"text-[14px]",children:e.content})})]})}return null}var nn=["create_plan","unknown"];function wa(e){return e?nn.includes(e.toLowerCase().trim()):false}function et(e,a){if(e.toolName&&wa(e.toolName))return null;if(e.type==="thinking")return !e.content||e.content.trim().length===0?null:{id:`thinking-${a}`,type:"thinking",status:"completed",content:e.content};if(e.type==="planning"){if(!e.content||e.content.trim().length===0)return null;let r=e.planData!==void 0||e.content.includes("\u2713 Created plan");return {id:`planning-${a}`,type:"planning",status:r?"completed":"running",content:e.content,isComplete:r}}if(e.type==="tool"){let r=e.status==="executing"?"running":e.status==="completed"?"completed":"pending";return {id:`tool-${a}`,type:"tool",status:r,toolName:e.toolName||"Unknown Tool",toolDescription:e.toolDescription}}return null}function on(e){let a=[];return e.forEach((r,t)=>{if(r.type==="thought"){let n=r.thought;if(!n||n.trim().length===0)return;a.push({id:`thought-${t}`,type:"thinking",status:"completed",content:n});}else if(r.type==="tool"){let n=r.tool||"Unknown Tool";if(wa(n))return;a.push({id:`tool-${t}`,type:"tool",status:"completed",toolName:n,toolDescription:r.tool_description});}}),a}function we({events:e,className:a}){if(e.length===0)return null;let r=e.map(t=>({id:t.id,status:t.status,content:jsx(Lt,{event:t,isRunning:t.status==="running"})}));return jsx(De,{items:r,badgeSize:20,className:a})}function pn(e){let a=[];return e.forEach((r,t)=>{if(r.type==="thinking"){if(!r.content||r.content.trim().length===0)return;a.push({id:`thinking-${t}`,type:"thinking",status:"completed",content:r.content});}else if(r.type==="tool"){let n=r.status==="executing"?"running":r.status==="completed"?"completed":"pending";a.push({id:`tool-${t}`,type:"tool",status:n,toolName:r.toolName||"Unknown Tool",toolDescription:r.toolDescription});}}),a}function dn({subtask:e,executionChunks:a=[]}){let[r,t]=useState(e.status==="running"),n=e.status==="running",s=e.status==="failed",o=e.status==="completed";n&&!r&&t(true);let l=a.length>0,p=pn(a);return jsxs("div",{className:"flex-1 min-w-0",children:[jsxs("div",{onClick:()=>l&&t(!r),className:i("flex items-center gap-2 min-w-0",l&&"cursor-pointer"),children:[jsx("span",{className:i("text-sm font-medium truncate",s?"text-red-500":"text-black/85"),children:e.description}),s&&e.error&&jsx("span",{className:"text-sm text-red-500 truncate flex-1",children:e.error}),o&&e.execution_time!=null&&e.execution_time>0&&jsxs("span",{className:"text-xs text-black/40 shrink-0 tabular-nums",children:[e.execution_time.toFixed(1),"s"]}),l&&jsx("span",{className:"text-black/40 shrink-0 flex items-center",children:r?jsx(ChevronUp,{size:14}):jsx(ChevronDown,{size:14})})]}),l&&r&&jsx("div",{className:"mt-2 pl-2",children:jsx(we,{events:p})})]})}function at({plan:e,streamingChunks:a=[],className:r}){let t=e.subtasks.map(n=>{let s=a.filter(l=>l.subtaskId===n.id),o=n.status==="running"?"running":n.status==="completed"?"completed":n.status==="failed"?"failed":"pending";return {id:String(n.id),status:o,content:jsx(dn,{subtask:n,executionChunks:s})}});return jsxs("div",{className:i("space-y-2",r),children:[jsx("span",{className:"text-sm text-black/50",children:"Plan:"}),jsx(De,{items:t,badgeSize:20})]})}function rt({chunk:e}){let[a,r]=useState(false),t=e.claudeToolData;if(!t)return null;let n=t.status==="pending",s=t.status==="error",o=t.status==="completed",l=()=>n?jsx(Loader2,{size:14,className:"animate-spin text-gray-400"}):s?jsx(XCircle,{size:14,className:"text-red-500"}):jsx(CheckCircle2,{size:14,className:"text-green-500"});return jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden",children:[jsxs("div",{onClick:()=>r(!a),className:"flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800",children:[jsx(Wrench,{size:16,className:"text-gray-400 shrink-0"}),jsxs("span",{className:"flex-1 text-sm truncate",children:[jsx("span",{className:"font-medium",children:(()=>{let d=t.toolName;if(d.startsWith("mcp__")){let f=d.split("__");if(f.length>=3)return `${f[1]}/${f[2]}`}return d})()}),t.toolDescription&&jsx("span",{className:"text-gray-400 ml-2",children:t.toolDescription})]}),l(),o&&t.durationMs!=null&&jsxs("span",{className:"text-[0.7rem] px-1.5 py-0.5 bg-black/5 dark:bg-white/5 rounded",children:[Math.round(t.durationMs),"ms"]}),jsx("span",{className:"p-0.5",children:a?jsx(ChevronDown,{size:14}):jsx(ChevronRight,{size:14})})]}),a&&jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700 p-3",children:[t.toolInput&&Object.keys(t.toolInput).length>0&&jsxs("div",{className:"mb-3",children:[jsx("div",{className:"text-[0.75rem] text-gray-400 uppercase tracking-wider mb-1",children:"Input"}),jsx("pre",{className:"text-[0.75rem] font-mono bg-gray-100 dark:bg-gray-900 rounded p-2 overflow-auto max-h-[150px] m-0",children:JSON.stringify(t.toolInput,null,2)})]}),s&&jsx("p",{className:"text-sm text-red-500 font-mono",children:t.content||"Tool execution failed"}),n&&jsx("p",{className:"text-sm text-gray-400 italic",children:"Executing tool..."}),o&&t.content&&!t.isError&&jsxs("div",{children:[jsx("div",{className:"text-[0.75rem] text-gray-400 uppercase tracking-wider mb-1",children:"Result"}),jsx("pre",{className:"text-[0.75rem] font-mono bg-gray-100 dark:bg-gray-900 rounded p-2 overflow-auto max-h-[200px] whitespace-pre-wrap break-words m-0",children:t.content.length>1500?`${t.content.slice(0,1500)}
15
+ ... (truncated)`:t.content})]})]})]})}function nt({chunk:e}){let[a,r]=useState(true),t=e.terminalData;if(!t)return null;let n=()=>{switch(t.status){case "running":return jsx(Loader2,{size:14,className:"animate-spin text-blue-500"});case "completed":return jsx(CheckCircle2,{size:14,className:"text-green-500"});case "failed":return jsx(XCircle,{size:14,className:"text-red-500"});default:return null}},s=t.status==="running"?"border-blue-500/30":t.status==="failed"?"border-red-500/30":t.exitCode===0?"border-green-500/30":"border-yellow-500/30",o=t.status==="running"?"bg-blue-500/10":t.status==="failed"?"bg-red-500/10":"bg-green-500/10",l=t.status==="running"?"text-blue-500":t.status==="failed"?"text-red-500":"text-green-500",p=d=>d?d<1e3?d+"ms":(d/1e3).toFixed(1)+"s":null;return jsxs("div",{className:i("my-1 bg-[#1a1a1a] rounded border",s,"overflow-hidden"),children:[jsxs("div",{onClick:()=>r(!a),className:i("flex items-center gap-2 px-3 py-1.5 cursor-pointer",o,"hover:brightness-110"),children:[jsx("span",{className:"p-0.5 text-gray-500",children:a?jsx(ChevronDown,{size:16}):jsx(ChevronRight,{size:16})}),jsx(Terminal,{size:16,className:l}),jsxs("span",{className:"flex-1 font-mono text-[0.75rem] text-gray-300 truncate",children:[jsx("span",{className:"text-gray-500",children:"$ "}),t.command]}),t.durationMs!=null&&jsx("span",{className:"text-[0.7rem] text-gray-600",children:p(t.durationMs)}),n(),t.status!=="running"&&t.exitCode!==void 0&&jsxs("span",{className:i("text-[0.7rem] font-mono",t.exitCode===0?"text-green-500":"text-red-500"),children:["[",t.exitCode,"]"]})]}),a&&jsxs("div",{className:"p-3",children:[t.description&&jsx("p",{className:"text-gray-500 text-[0.75rem] italic mb-2",children:t.description}),t.stdout&&jsx("pre",{className:i("m-0 p-2 text-[0.7rem] font-mono bg-[#0d0d0d] rounded overflow-auto max-h-[300px]","text-green-400 whitespace-pre-wrap break-words",t.stderr&&"mb-2"),children:t.stdout}),t.stderr&&jsx("pre",{className:"m-0 p-2 text-[0.7rem] font-mono bg-red-500/10 rounded border border-red-500/30 overflow-auto max-h-[200px] text-red-400 whitespace-pre-wrap break-words",children:t.stderr}),t.status==="running"&&!t.stdout&&!t.stderr&&jsx("p",{className:"text-gray-500 text-[0.75rem] italic",children:"Running..."}),t.status==="completed"&&!t.stdout&&!t.stderr&&t.exitCode===0&&jsx("p",{className:"text-gray-600 text-[0.75rem] italic",children:"Command completed with no output"})]})]})}function ot({chunk:e}){let[a,r]=useState(false),t=e.fileOperationData;if(!t)return null;let n=t.operation==="read"?jsx(Eye,{size:16}):t.operation==="write"?jsx(Save,{size:16}):t.operation==="edit"?jsx(Pencil,{size:16}):jsx(FileText,{size:16}),s=t.operation==="read"?"text-blue-500 border-blue-500":t.operation==="write"?"text-green-500 border-green-500":t.operation==="edit"?"text-yellow-500 border-yellow-500":"text-gray-500 border-gray-500",o=t.operation==="read"?"bg-blue-500/5 hover:bg-blue-500/8":t.operation==="write"?"bg-green-500/5 hover:bg-green-500/8":t.operation==="edit"?"bg-yellow-500/5 hover:bg-yellow-500/8":"bg-gray-500/5",l=t.status==="pending"?jsx(Clock,{size:14,className:"text-gray-400"}):t.status==="completed"?jsx(CheckCircle2,{size:14,className:"text-green-500"}):jsx(XCircle,{size:14,className:"text-red-500"}),p=t.operation==="read"?"Read":t.operation==="write"?"Write":t.operation==="edit"?"Edit":"File",d=f=>{let x=f.split("/");return x.length<=3?f:".../"+x.slice(-3).join("/")};return jsxs("div",{className:i("my-1 border rounded overflow-hidden",s.split(" ")[1]+"/30"),children:[jsxs("div",{onClick:()=>r(!a),className:i("flex items-center gap-2 px-3 py-1.5 cursor-pointer",o),children:[jsx("span",{className:"p-0.5",children:a?jsx(ChevronDown,{size:16}):jsx(ChevronRight,{size:16})}),jsx("span",{className:s.split(" ")[0],children:n}),jsx("span",{className:i("font-medium text-[0.75rem]",s.split(" ")[0]),children:p}),jsx("span",{className:"flex-1 font-mono text-[0.75rem] text-gray-500 truncate",children:d(t.filePath)}),t.totalLines!=null&&jsxs("span",{className:"text-[0.7rem] text-gray-400",children:[t.totalLines," lines"]}),l]}),a&&jsxs("div",{className:"p-3 bg-gray-50 dark:bg-[#1e1e1e]",children:[t.operation==="read"&&t.content&&jsx(Vn,{content:t.content}),t.operation==="edit"&&jsx(Fn,{oldString:t.oldString,newString:t.newString}),t.operation==="write"&&t.status==="completed"&&jsx("p",{className:"text-green-500 text-sm",children:"File written successfully"}),t.error&&jsxs("p",{className:"text-red-500 text-sm",children:["Error: ",t.error]})]})]})}function Vn({content:e}){let a=useMemo(()=>e.split(`
16
+ `).slice(0,50),[e]),r=e.split(`
17
+ `).length,t=r>50;return jsxs("div",{children:[jsx("pre",{className:"m-0 p-2 text-[0.75rem] font-mono bg-gray-100 dark:bg-[#1a1a1a] rounded overflow-auto max-h-[300px]",children:a.map((n,s)=>jsxs("div",{className:"flex",children:[jsx("span",{className:"inline-block w-10 text-right pr-3 mr-3 border-r border-gray-200 dark:border-gray-700 text-gray-400 select-none",children:s+1}),jsx("span",{children:n||" "})]},s))}),t&&jsxs("p",{className:"text-[0.75rem] text-gray-400 mt-1",children:["... and ",r-50," more lines"]})]})}function Fn({oldString:e,newString:a}){return !e&&!a?jsx("p",{className:"text-gray-500 text-sm",children:"No changes to display"}):jsxs("div",{className:"flex gap-4",children:[jsxs("div",{className:"flex-1",children:[jsx("span",{className:"text-[0.75rem] font-medium text-red-500 block mb-1",children:"- Removed"}),jsx("pre",{className:"m-0 p-2 text-[0.7rem] font-mono bg-red-500/10 rounded border border-red-500/30 overflow-auto max-h-[200px] whitespace-pre-wrap break-words",children:e||"(empty)"})]}),jsxs("div",{className:"flex-1",children:[jsx("span",{className:"text-[0.75rem] font-medium text-green-500 block mb-1",children:"+ Added"}),jsx("pre",{className:"m-0 p-2 text-[0.7rem] font-mono bg-green-500/10 rounded border border-green-500/30 overflow-auto max-h-[200px] whitespace-pre-wrap break-words",children:a||"(empty)"})]})]})}function st({chunk:e}){let[a,r]=useState(true),t=e.searchResultsData;if(!t)return null;let n=t.tool==="grep",s=n?"text-purple-500":"text-blue-500",o=n?"border-purple-500/30":"border-blue-500/30",l=n?"bg-purple-500/5 hover:bg-purple-500/8":"bg-blue-500/5 hover:bg-blue-500/8",p=n?"bg-purple-500/10 text-purple-500":"bg-blue-500/10 text-blue-500";return jsxs("div",{className:i("my-1 border rounded overflow-hidden",o),children:[jsxs("div",{onClick:()=>r(!a),className:i("flex items-center gap-2 px-3 py-1.5 cursor-pointer",l),children:[jsx("span",{className:"p-0.5",children:a?jsx(ChevronDown,{size:16}):jsx(ChevronRight,{size:16})}),jsx("span",{className:s,children:n?jsx(FileSearch,{size:16}):jsx(FolderSearch,{size:16})}),jsx("span",{className:i("text-[0.7rem] px-1.5 py-0.5 rounded font-medium",p),children:n?"Grep":"Glob"}),jsx("span",{className:"flex-1 font-mono text-[0.75rem] text-gray-500 truncate",children:t.pattern}),jsxs("span",{className:i("text-[0.7rem] px-1.5 py-0.5 rounded",t.totalCount>0?"bg-green-500/10 text-green-500":"bg-gray-500/10 text-gray-500"),children:[t.totalCount," results"]})]}),a&&jsxs("div",{className:"max-h-[300px] overflow-auto",children:[t.results.length>0?jsxs("div",{children:[t.results.slice(0,50).map((d,f)=>jsx(jn,{result:d,isGrep:n},f)),t.results.length>50&&jsx("div",{className:"py-1 px-3",children:jsxs("span",{className:"text-[0.75rem] text-gray-400",children:["... and ",t.results.length-50," more results"]})})]}):jsx("div",{className:"p-3",children:jsx("p",{className:"text-gray-500 text-sm",children:"No results found"})}),t.error&&jsx("div",{className:"p-3",children:jsxs("p",{className:"text-red-500 text-sm",children:["Error: ",t.error]})})]})]})}function jn({result:e,isGrep:a}){return jsxs("div",{className:"flex items-start gap-2 py-1 px-3 border-b border-gray-100 dark:border-gray-800 last:border-b-0 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:[jsx(File,{size:14,className:"text-gray-400 mt-0.5 shrink-0"}),jsxs("div",{className:"min-w-0 flex-1",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx("span",{className:"font-mono text-[0.75rem] truncate",children:(t=>{let n=t.split("/");return n.length<=4?t:".../"+n.slice(-4).join("/")})(e.filePath)}),a&&e.lineNumber!=null&&jsxs("span",{className:"font-mono text-[0.7rem] text-blue-500",children:[":",e.lineNumber]})]}),e.snippet&&jsx("p",{className:"font-mono text-[0.7rem] text-gray-500 truncate max-w-[400px]",children:e.snippet})]})]})}function it({chunk:e}){let[a,r]=useState(false),t=e.webOperationData;if(!t)return null;let n=t.operation==="search",s=t.status==="pending",o=t.status==="error",l=t.status==="completed",p=()=>s?jsx(Loader2,{size:14,className:"animate-spin text-gray-400"}):o?jsx(XCircle,{size:14,className:"text-red-500"}):jsx(CheckCircle2,{size:14,className:"text-green-500"}),f=n?(()=>{if(!t.results||typeof t.results!="string")return [];let x=/\[([^\]]+)\]\(([^)]+)\)/g,h=[],v;for(;(v=x.exec(t.results))!==null;)h.push({title:v[1],url:v[2]});return h})():[];return jsxs("div",{className:"bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700 overflow-hidden",children:[jsxs("div",{onClick:()=>r(!a),className:"flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800",children:[n?jsx(Search,{size:16,className:"text-gray-400 shrink-0"}):jsx(Globe,{size:16,className:"text-gray-400 shrink-0"}),jsx("span",{className:"flex-1 text-sm truncate",children:n?jsxs(Fragment,{children:["Searching: ",jsx("span",{className:"font-medium",children:t.query})]}):jsxs(Fragment,{children:["Fetching: ",jsx("span",{className:"font-medium",children:t.url})]})}),p(),l&&t.durationMs!=null&&jsxs("span",{className:"text-[0.7rem] px-1.5 py-0.5 bg-black/5 dark:bg-white/5 rounded",children:[Math.round(t.durationMs),"ms"]}),jsx("span",{className:"p-0.5",children:a?jsx(ChevronDown,{size:14}):jsx(ChevronRight,{size:14})})]}),a&&jsxs("div",{className:"border-t border-gray-200 dark:border-gray-700 p-3",children:[o&&t.error&&jsx("p",{className:"text-sm text-red-500 font-mono",children:t.error}),s&&jsx("p",{className:"text-sm text-gray-400 italic",children:n?"Searching the web...":"Fetching content..."}),n&&l&&f.length>0&&jsxs("div",{className:"space-y-2",children:[jsxs("div",{className:"text-[0.75rem] text-gray-400 uppercase tracking-wider",children:[f.length," Results"]}),f.slice(0,5).map((x,h)=>jsxs("div",{className:i("flex items-center gap-2 py-1",h<Math.min(f.length,5)-1&&"border-b border-gray-200 dark:border-gray-700"),children:[jsx(ExternalLink,{size:12,className:"text-gray-400 shrink-0"}),jsx("a",{href:x.url,target:"_blank",rel:"noopener noreferrer",className:"text-sm truncate hover:underline",children:x.title})]},h)),f.length>5&&jsxs("p",{className:"text-[0.75rem] text-gray-400 italic",children:["+",f.length-5," more results"]})]}),n&&l&&f.length===0&&t.results&&jsxs("p",{className:"text-sm whitespace-pre-wrap max-h-[200px] overflow-auto",children:[typeof t.results=="string"?t.results.slice(0,1e3):JSON.stringify(t.results,null,2).slice(0,1e3),t.results.length>1e3&&"..."]}),!n&&l&&t.content&&jsx("div",{className:"max-h-[300px] overflow-auto bg-gray-100 dark:bg-gray-900 rounded p-2",children:jsxs("pre",{className:"text-[0.75rem] font-mono whitespace-pre-wrap break-words m-0",children:[t.content.slice(0,2e3),t.content.length>2e3&&`
18
+ ... (truncated)`]})})]})]})}var lo={code_reviewer:"Code Review",researcher:"Research",data_analyst:"Data Analysis",Explore:"Explore",Plan:"Planning",Bash:"Command Execution"};function lt({chunk:e}){let[a,r]=useState(true),t=e.subagentData;if(!t)return null;let n=t.status==="running"?jsx(Loader2,{size:16,className:"animate-spin text-blue-500"}):t.status==="completed"?jsx(CheckCircle2,{size:16,className:"text-green-500"}):t.status==="failed"?jsx(XCircle,{size:16,className:"text-red-500"}):null,s=t.status==="running"?"border-blue-500":t.status==="completed"?"border-green-500":t.status==="failed"?"border-red-500":"border-gray-500",o=t.status==="running"?"bg-blue-500/3":t.status==="completed"?"bg-green-500/3":t.status==="failed"?"bg-red-500/3":"bg-gray-500/3",l=t.status==="running"?"bg-blue-500/10 text-blue-500":t.status==="completed"?"bg-green-500/10 text-green-500":t.status==="failed"?"bg-red-500/10 text-red-500":"bg-gray-500/10 text-gray-500",p=f=>f?f<1e3?f+"ms":(f/1e3).toFixed(1)+"s":null,d=lo[t.subagentType]||t.subagentType;return jsxs("div",{className:i("border border-dashed rounded ml-4 my-2 overflow-hidden",s+"/50",o),children:[jsxs("div",{onClick:()=>r(!a),className:i("flex items-center gap-2 px-3 py-1.5 cursor-pointer hover:brightness-95"),children:[jsx("span",{className:"p-0.5",children:a?jsx(ChevronDown,{size:18}):jsx(ChevronRight,{size:18})}),jsx(GitBranch,{size:16,className:s.replace("border-","text-")}),jsx("span",{className:i("text-[0.75rem] px-2 py-0.5 rounded font-medium",l),children:d}),jsx("span",{className:"flex-1 text-sm text-gray-500 truncate",children:t.description}),n,t.durationMs!=null&&jsx("span",{className:"text-[0.7rem] text-gray-400",children:p(t.durationMs)})]}),a&&jsxs("div",{className:"px-4 pb-3",children:[t.nestedChunks&&t.nestedChunks.length>0&&jsx("div",{className:"mt-2 space-y-1",children:t.nestedChunks.map((f,x)=>jsx(co,{chunk:f},x))}),t.status==="completed"&&t.result&&jsxs("div",{className:"mt-2 p-2 rounded bg-green-500/5 border border-green-500/20",children:[jsx("span",{className:"text-[0.75rem] font-medium text-green-500",children:"Result"}),jsx("p",{className:"mt-1 text-sm text-gray-500 whitespace-pre-wrap",children:t.result.length>500?t.result.slice(0,500)+"...":t.result})]})]})]})}function co({chunk:e}){return e.type==="tool"||e.type==="observation"?jsxs("div",{className:"py-1 px-2 my-1 rounded bg-blue-500/5 text-[0.75rem]",children:[jsxs("span",{className:"font-medium text-blue-500",children:[e.toolName||"Tool",":"]})," ",jsxs("span",{className:"text-gray-500",children:[e.content?.slice(0,200)||e.toolDescription||"Executing...",e.content&&e.content.length>200&&"..."]})]}):e.type==="thinking"||e.type==="claude_thinking"?jsxs("p",{className:"py-1 text-[0.75rem] text-gray-400 italic",children:[e.content?.slice(0,150),e.content&&e.content.length>150&&"..."]}):null}function vo(e){let a=useRef(null),[r,t]=useState(0),n=useRef(0);return useEffect(()=>{if(e){a.current===null&&(a.current=Date.now());let s=setInterval(()=>{if(a.current!==null){let o=Math.floor((Date.now()-a.current)/1e3);t(o),n.current=o;}},1e3);return ()=>clearInterval(s)}else a.current!==null&&(n.current=Math.floor((Date.now()-a.current)/1e3),t(n.current),a.current=null);},[e]),{display:`${r}`,finalSeconds:n.current}}function wo(e){return e.some(a=>a.orchestrator==="claude_agent_sdk"||a.type==="subagent"||a.type==="file_operation"||a.type==="terminal"||a.type==="search_results"||a.type==="web_operation"||a.type==="claude_text"||a.type==="claude_thinking")}function No(e){return e.some(a=>a.type==="wave_start"||a.type==="wave_complete"||a.type==="parallel_subtask_start"||a.type==="parallel_subtask_complete"||a.isParallel)}function ko(e){let a=e.filter(p=>p.type==="wave_start"&&p.waveData);if(a.length===0)return null;let r=a[a.length-1],t=r.waveData?.waveNumber??0,n=r.waveData?.totalWaves??1,s=r.waveData?.parallelCount??0,o=[],l=[];return e.forEach(p=>{if(p.type==="parallel_subtask_start"&&p.waveNumber===t&&p.subtaskId!==void 0&&(l.includes(p.subtaskId)||o.push(p.subtaskId)),p.type==="parallel_subtask_complete"&&p.waveNumber===t&&p.subtaskId!==void 0){l.push(p.subtaskId);let d=o.indexOf(p.subtaskId);d>=0&&o.splice(d,1);}}),{currentWave:t,totalWaves:n,parallelCount:s,activeSubtasks:o,completedSubtasks:l}}function Co(e){return e.some(a=>a.type==="multi_agent_planning"||a.type==="multi_agent_planning_complete"||a.type==="subagent_start"||a.type==="subagent_complete"||a.type==="subagent_failed"||a.type==="synthesis"||a.isMultiAgent)}function Pa(e){return e.find(r=>(r.type==="multi_agent_planning"||r.type==="multi_agent_planning_complete")&&r.subagentAllocations)?.subagentAllocations||[]}function Ea(e){let a=new Map,r=false;Pa(e).forEach(s=>{a.set(s.name,{name:s.name,task:s.query||s.focus,status:"pending"});});let t={pending:0,running:1,completed:2,failed:2};e.forEach(s=>{if(s.subagentInfo?.name){let o=s.subagentInfo.id||s.subagentInfo.name,l=a.get(o);(!l||(t[s.subagentInfo.status]??0)>=(t[l.status]??0))&&a.set(o,s.subagentInfo);}s.type==="synthesis"&&(r=true);});let n=[...a.values()];return {subagents:a,running:n.filter(s=>s.status==="running").length,completed:n.filter(s=>s.status==="completed").length,failed:n.filter(s=>s.status==="failed").length,pending:n.filter(s=>s.status==="pending").length,isSynthesizing:r}}function So(e){let a=[];return e.forEach(r=>{r.type==="thought"&&r.thought?a.push({type:"thinking",content:r.thought,subtaskId:r.subtask_id}):r.type==="tool"&&(a.push({type:"tool",content:"",toolName:r.tool||"Unknown Tool",toolDescription:r.tool_description,status:"completed",subtaskId:r.subtask_id}),r.observation&&a.push({type:"observation",content:r.observation,toolName:r.tool||"Unknown Tool",success:true,subtaskId:r.subtask_id}));}),a}function zo({chunks:e}){let a=Ea(e),r=[...a.subagents.values()];if(r.length===0){let n=e.some(o=>o.type==="multi_agent_planning"),s=Pa(e);return s.length>0?jsxs("div",{className:"flex items-center gap-2",children:[jsx(Loader2,{size:14,className:"animate-spin text-gray-400"}),jsxs("span",{className:"text-sm text-gray-500",children:["Allocating agents: ",s.map(o=>o.name).join(", ")]})]}):n?jsxs("div",{className:"flex items-center gap-2",children:[jsx(Loader2,{size:14,className:"animate-spin text-gray-400"}),jsx("span",{className:"text-sm text-gray-500",children:"Planning agent allocation..."})]}):null}let t=r.map((n,s)=>({id:n.id||`agent-${s}`,status:n.status==="running"?"running":n.status==="completed"?"completed":n.status==="failed"?"failed":"pending",content:jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[jsx("span",{className:"text-sm font-medium",children:n.name}),jsx("span",{className:i("text-sm flex-1 truncate",n.status==="failed"?"text-red-500":"text-gray-500"),children:n.status==="failed"&&n.error?n.error:n.task}),n.status==="completed"&&n.executionTime!=null&&jsxs("span",{className:"text-xs text-gray-400 shrink-0",children:[n.executionTime.toFixed(1),"s"]})]})}));return jsxs("div",{className:"space-y-2",children:[jsx("span",{className:"text-sm text-gray-500",children:a.running===0?"Agents:":"Running agents:"}),jsx(De,{items:t,badgeSize:16}),a.isSynthesizing&&jsxs("div",{className:"flex items-center gap-2",children:[jsx(Sparkle,{size:14,className:"text-gray-500"}),jsx("span",{className:"text-sm text-gray-500",children:"Synthesizing results..."})]})]})}function Po({chunks:e}){return jsx("div",{className:"space-y-2",children:e.map((a,r)=>a.type==="subagent"&&a.subagentData?jsx(lt,{chunk:a},`subagent-${a.subagentData.subagentId}-${r}`):a.type==="file_operation"&&a.fileOperationData?jsx(ot,{chunk:a},`file-op-${a.fileOperationData.toolUseId}-${r}`):a.type==="terminal"&&a.terminalData?jsx(nt,{chunk:a},`terminal-${a.terminalData.toolUseId}-${r}`):a.type==="search_results"&&a.searchResultsData?jsx(st,{chunk:a},`search-${a.searchResultsData.toolUseId}-${r}`):a.type==="web_operation"&&a.webOperationData?jsx(it,{chunk:a},`web-op-${a.webOperationData.toolUseId}-${r}`):a.claudeToolData?jsx(rt,{chunk:a},`claude-tool-${a.claudeToolData.toolUseId}-${r}`):null)})}function Ca(e){return e<1?`${Math.round(e*1e3)}ms`:`${e.toFixed(1)}s`}function Ft({isStreaming:e=false,chunks:a=[],plan:r,executionTimeline:t=[],userMessageTimestamp:n,executionTime:s,defaultExpanded:o=false,expanded:l,onExpandedChange:p,className:d}){let[f,x]=useState(o),{display:h,finalSeconds:v}=vo(e),g=useRef(null);useEffect(()=>{Pe(g.current);},[]);let C=l??f,E=N=>{x(N),p?.(N);},I=useMemo(()=>e?a.map((N,b)=>et(N,b)).filter(N=>N!==null):[],[e,a]),L=useMemo(()=>!e&&(t.length>0||a.length>0)?a.map((N,b)=>et(N,b)).filter(N=>N!==null):[],[e,t,a]),ee=useMemo(()=>!e&&t.length>0?So(t):[],[e,t]),P=useMemo(()=>{if(!e)return null;let N=a.find(z=>z.planData!==void 0);if(!N?.planData)return null;let b={...N.planData},D=[...b.subtasks||[]],T=0,y=0;return a.forEach(z=>{if(z.type==="parallel_subtask_start"&&z.subtaskId!==void 0){let F=D.findIndex(B=>String(B.id)===String(z.subtaskId));F!==-1&&(D[F]={...D[F],status:"running"});}else if(z.type==="parallel_subtask_complete"&&z.subtaskId!==void 0){let F=D.findIndex(B=>String(B.id)===String(z.subtaskId));if(F!==-1){let B={...D[F]};z.parallelSubtaskData?.success===false||z.success===false?(B.status="failed",B.error=z.parallelSubtaskData?.error,y++):(B.status="completed",B.result=z.parallelSubtaskData?.result,B.execution_time=z.parallelSubtaskData?.executionTime,T++),D[F]=B;}}else if(z.type==="subtask"&&z.subtaskId!==void 0){let F=D.findIndex(B=>String(B.id)===String(z.subtaskId));if(F!==-1){let B={...D[F]};if(z.content.includes("\u2713 Completed"))B.status="completed",z.subtaskData?.execution_time&&(B.execution_time=z.subtaskData.execution_time),T++;else if(z.content.includes("\u2717 Failed")){B.status="failed";let ta=z.content.match(/✗ Failed: (.*)/);ta&&(B.error=ta[1]),y++;}else z.content.includes("\u2192 **Subtask")&&(B.status="running");D[F]=B;}}}),b.subtasks=D,b.completed_subtasks=T,b.failed_subtasks=y,b.progress_percentage=T/b.total_subtasks*100,b},[e,a]),u=useMemo(()=>{if(!e){if(r?.subtasks)return r.subtasks.reduce((N,b)=>N+(b.execution_time||0),0);if(t.length>0){let N=t[t.length-1];if(n&&N.timestamp)return N.timestamp-n;if(t.length>1){let b=t[0];if(b.timestamp&&N.timestamp)return N.timestamp-b.timestamp}}}return s||0},[e,r,t,n,s]);if(!e){let N=r||t.length>0||a.length>0;if(!N||N&&L.length===0&&!r&&t.length===0)return null}let c=a.length>0?a[a.length-1]:null,k=c?.type==="tool"||!!c?.toolName,O=c?.type==="planning",w=No(a),q=w?ko(a):null,Y=wo(a),fe=Co(a),he=fe?Ea(a):null,Ae=()=>{if(!e)return u>0?`Thought for ${Ca(u)}`:v>0?`Thought for ${Ca(v)}`:(a.length>0,"Thought for a few seconds");if(fe&&he){let{running:N,completed:b,failed:D,isSynthesizing:T}=he;if(T)return "Synthesizing results...";if(c?.type==="multi_agent_planning")return "Planning subagent allocation...";if(c?.type==="subagent_start"&&c?.subagentInfo)return `${c.subagentInfo.name}: ${c.subagentInfo.task?.slice(0,30)||"working"}...`;if(c?.type==="subagent_complete"&&c?.subagentInfo)return `${c.subagentInfo.name} complete`;if(c?.type==="subagent_failed"&&c?.subagentInfo)return `${c.subagentInfo.name} failed`;let y=N+b+D;if(N>0)return `${N} subagent${N>1?"s":""} running (${b}/${y} done)`;if(y>0)return `Multi-agent execution (${b}/${y} complete)`}if(Y){if(c?.type==="subagent"&&c?.subagentData)return `${c.subagentData.subagentType}: ${c.subagentData.description}`;if(c?.type==="file_operation"&&c?.fileOperationData){let N=c.fileOperationData.operation,b=c.fileOperationData.filePath.split("/").pop();return `${N==="read"?"Reading":N==="edit"?"Editing":"Writing"} ${b}`}if(c?.type==="terminal"&&c?.terminalData){let N=c.terminalData.command;return N.length>40?`$ ${N.slice(0,37)}...`:`$ ${N}`}if(c?.type==="search_results"&&c?.searchResultsData)return `${c.searchResultsData.tool}: ${c.searchResultsData.pattern}`;if(c?.type==="web_operation"&&c?.webOperationData)return c.webOperationData.operation==="search"?`Searching: ${c.webOperationData.query}`:`Fetching: ${c.webOperationData.url?.slice(0,40)}...`}if(w&&q){let{currentWave:N,totalWaves:b,parallelCount:D,activeSubtasks:T,completedSubtasks:y}=q;if(c?.type==="wave_start")return `Wave ${N+1}/${b}: ${D} parallel subtasks`;if(c?.type==="wave_complete")return `Wave ${N+1} complete (${y.length} done)`;if(c?.type==="parallel_subtask_start"&&c?.parallelSubtaskData?.description){let z=c.parallelSubtaskData.description;return z.length>40?`${z.slice(0,37)}...`:z}return T.length>0?`Wave ${N+1}/${b}: ${T.length} running...`:`Parallel execution (Wave ${N+1}/${b})`}if(c?.toolDescription)return c.toolDescription;if(c?.toolName)return c.toolName;switch(c?.type){case "planning":return "Planning...";case "thinking":return "Thinking...";case "tool":return c.toolName||"Using tool...";case "subtask":return `Executing subtask ${c.subtaskId||""}...`;case "observation":return "Analyzing results...";case "progress":return "Working...";case "wave_start":return "Starting parallel execution...";case "wave_complete":return "Parallel wave complete";case "parallel_subtask_start":return "Running parallel subtask...";case "parallel_subtask_complete":return "Parallel subtask complete";default:return "Thinking..."}},Se=()=>fe?jsx(Users,{size:14}):Y?c?.type==="subagent"?jsx(GitBranch,{size:14}):c?.type==="file_operation"?jsx(FileText,{size:14}):c?.type==="terminal"?jsx(Terminal,{size:14}):c?.type==="search_results"?jsx(Search,{size:14}):c?.type==="web_operation"?jsx(Globe,{size:14}):jsx(Sparkle,{size:14}):w?jsx(Zap,{size:14}):k?jsx(Wrench,{size:14}):O?jsx(ListTodo,{size:14}):jsx(Sparkle,{size:14}),Be=N=>N?.subtasks&&N.subtasks.length>=2,ce=e?P:r,_e=Be(ce);return jsxs("div",{ref:g,className:i("max-w-full",d),children:[jsxs("div",{onClick:()=>E(!C),style:{position:"relative",display:"inline-flex",alignItems:"center",gap:6,padding:"4px 6px",overflow:"hidden",borderRadius:8,cursor:"pointer",transition:"opacity 0.2s",...!e&&{opacity:.6}},children:[e&&jsx("div",{style:Ee}),jsx("span",{className:i("flex items-center text-gray-500"),children:e?Se():jsx(Sparkle,{size:14})}),jsx("span",{className:i("text-sm font-medium",e?"text-[var(--chat-text)]":"text-[var(--chat-text-subtle)]"),children:Ae()}),e&&parseInt(h)>0&&jsxs("span",{className:"text-gray-500 font-medium tabular-nums text-sm",children:[h,"s"]})]}),C&&jsx("div",{className:"mt-3 animate-fade-in",children:e?fe?jsx(zo,{chunks:a}):Y?jsx(Po,{chunks:a}):_e&&ce?jsx(at,{plan:ce,streamingChunks:a}):P?.subtasks?.length===1?jsx(we,{events:I}):P?.subtasks?.length===0?null:jsx(we,{events:I}):r?r.subtasks?.length===0?null:r.subtasks?.length===1?jsx(we,{events:L}):jsx(at,{plan:r,streamingChunks:ee}):jsx(we,{events:L})})]})}var je=forwardRef(({content:e,isStreaming:a=false,renderMarkdown:r=true,className:t,baselineFontSize:n,markdownProps:s},o)=>jsx(m,{ref:o,content:e,isStreaming:a,showCursor:false,className:i("relative",t),children:r?jsx(re,{baselineFontSize:n,...s,children:e}):jsx("span",{className:"whitespace-pre-wrap",children:e})}));je.displayName="StreamingText";var Bo={send_message:jsx(Send,{size:14}),navigate:jsx(Navigation,{size:14}),copy_text:jsx(Copy,{size:14}),compose_email:jsx(Mail,{size:14}),search_emails:jsx(Search,{size:14}),open_modal:jsx(ExternalLink,{size:14}),api_call:jsx(Zap,{size:14})};function Wo(e){return e?Bo[e]||jsx(ArrowRight,{size:14}):jsx(ArrowRight,{size:14})}var pt=forwardRef(({actions:e,onSelect:a,className:r,showIcons:t=true,disabled:n=false},s)=>{let[o,l]=useState(null);if(e.length===0)return null;let p=async(d,f)=>{if(!(!a||o!==null)){l(f);try{await a(d);}finally{l(null);}}};return jsx("div",{ref:s,role:"group","aria-label":"Suggested actions",className:i("flex flex-wrap gap-2",r),children:jsx(AnimatePresence,{children:e.map((d,f)=>{let x=o===f,h=n||o!==null;return jsxs(motion.button,{type:"button",initial:{opacity:0,y:4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.2,delay:f*.05},disabled:h,onClick:()=>p(d,f),className:i("inline-flex items-center gap-1.5","px-3 py-1.5 rounded-lg","text-sm font-medium","border border-gray-200 dark:border-gray-700","bg-white dark:bg-gray-800","text-gray-700 dark:text-gray-300","opacity-80 hover:opacity-100","hover:border-gray-300 dark:hover:border-gray-600","hover:bg-gray-50 dark:hover:bg-gray-750","hover:-translate-y-px","active:translate-y-0","transition-all duration-200","focus:outline-none focus:ring-2 focus:ring-blue-500/20","disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:translate-y-0"),children:[x?jsx(Loader2,{size:14,className:"animate-spin"}):t&&jsx("span",{className:"text-gray-400 dark:text-gray-500",children:Wo(d.type)}),d.label]},d.id)})})})});pt.displayName="SuggestedActions";var as=["#3B82F6","#10B981","#F59E0B","#EF4444","#8B5CF6","#EC4899","#06B6D4","#F97316"];function gt({data:e,config:a,isStreaming:r=false}){let{chartType:t,series:n,xAxis:s,yAxis:o}=e,l=a?.colors||as,p=a?.height||300,d=a?.legend!==false,f=a?.grid!==false,x=a?.tooltip!==false,h=a?.animate!==false&&!r,v=a?.stacked||false,C=(()=>{if(t==="pie")return (n[0]?.data||[]).map((c,k)=>({name:c.name||c.x||`Item ${k+1}`,value:c.value??c.y??0}));let P=new Map;return n.forEach(u=>{u.data.forEach(c=>{let k=c.x??c.name;P.has(k)||P.set(k,{x:k}),P.get(k)[u.name]=c.y??c.value??0;});}),Array.from(P.values())})(),E={data:C,margin:{top:10,right:30,left:0,bottom:0}},I={fontSize:12},L={backgroundColor:"#fff",border:"1px solid #e5e7eb",borderRadius:8};return jsx("div",{className:"w-full",style:{height:p},children:jsx(ResponsiveContainer,{width:"100%",height:"100%",children:(()=>{switch(t){case "line":return jsxs(LineChart,{...E,children:[f&&jsx(CartesianGrid,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),jsx(XAxis,{dataKey:"x",...I,tickLine:false,padding:{left:10,right:10}}),jsx(YAxis,{...I,tickLine:false,width:40}),x&&jsx(Tooltip,{contentStyle:L}),d&&jsx(Legend,{}),n.map((P,u)=>jsx(Line,{type:"monotone",dataKey:P.name,stroke:P.color||l[u%l.length],strokeWidth:2,dot:false,activeDot:{r:4},isAnimationActive:h},P.name))]});case "bar":return jsxs(BarChart,{...E,children:[f&&jsx(CartesianGrid,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),jsx(XAxis,{dataKey:"x",...I,tickLine:false,padding:{left:10,right:10}}),jsx(YAxis,{...I,tickLine:false,width:40}),x&&jsx(Tooltip,{contentStyle:L}),d&&jsx(Legend,{}),n.map((P,u)=>jsx(Bar,{dataKey:P.name,fill:P.color||l[u%l.length],stackId:v?"stack":void 0,isAnimationActive:h,radius:[4,4,0,0]},P.name))]});case "area":return jsxs(AreaChart,{...E,children:[f&&jsx(CartesianGrid,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),jsx(XAxis,{dataKey:"x",...I,tickLine:false,padding:{left:10,right:10}}),jsx(YAxis,{...I,tickLine:false,width:40}),x&&jsx(Tooltip,{contentStyle:L}),d&&jsx(Legend,{}),n.map((P,u)=>jsx(Area,{type:"monotone",dataKey:P.name,stroke:P.color||l[u%l.length],fill:P.color||l[u%l.length],fillOpacity:.3,stackId:v?"stack":void 0,isAnimationActive:h},P.name))]});case "pie":return jsxs(PieChart,{children:[x&&jsx(Tooltip,{contentStyle:L}),d&&jsx(Legend,{}),jsx(Pie,{data:C,dataKey:"value",nameKey:"name",cx:"50%",cy:"50%",outerRadius:Math.min(p,300)/3,isAnimationActive:h,label:({name:P,percent:u})=>`${P}: ${((u??0)*100).toFixed(0)}%`,labelLine:false,children:C.map((P,u)=>jsx(Cell,{fill:l[u%l.length]},`cell-${u}`))})]});case "scatter":return jsxs(ScatterChart,{...E,children:[f&&jsx(CartesianGrid,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),jsx(XAxis,{dataKey:"x",type:"number",...I,tickLine:false,name:s?.label,padding:{left:10,right:10}}),jsx(YAxis,{...I,tickLine:false,name:o?.label,width:40}),x&&jsx(Tooltip,{contentStyle:L}),d&&jsx(Legend,{}),n.map((P,u)=>jsx(Scatter,{name:P.name,data:P.data.map(c=>({x:c.x,y:c.y})),fill:P.color||l[u%l.length],isAnimationActive:h},P.name))]});default:return null}})()||jsx(Fragment,{})})})}var cs={active:"bg-green-100 text-green-700",completed:"bg-green-100 text-green-700",success:"bg-green-100 text-green-700",enabled:"bg-green-100 text-green-700",pending:"bg-yellow-100 text-yellow-700",processing:"bg-yellow-100 text-yellow-700",in_progress:"bg-yellow-100 text-yellow-700",failed:"bg-red-100 text-red-700",error:"bg-red-100 text-red-700",disabled:"bg-red-100 text-red-700",inactive:"bg-gray-100 text-gray-700",draft:"bg-gray-100 text-gray-700"};function ps(e,a){if(e==null)return jsx("span",{className:"text-gray-400",children:"-"});switch(a.type||"string"){case "number":return typeof e=="number"?e.toLocaleString():String(e);case "currency":return typeof e=="number"?new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(e):String(e);case "date":try{return new Date(e).toLocaleDateString()}catch{return String(e)}case "badge":{let t=String(e).toLowerCase().replace(/\s+/g,"_"),n=cs[t]||"bg-gray-100 text-gray-700";return jsx("span",{className:i("inline-block px-2 py-0.5 rounded-full text-xs font-medium",n),children:String(e)})}case "link":return jsx("a",{href:String(e),target:"_blank",rel:"noopener noreferrer",className:"text-blue-500 hover:underline",children:String(e)});case "boolean":return e?jsx(Check,{size:18,className:"text-green-500"}):jsx(X,{size:18,className:"text-gray-400"});case "progress":{let t=typeof e=="number"?e:parseFloat(String(e));return jsxs("div",{className:"flex items-center gap-2",children:[jsx("div",{className:"flex-1 h-2 bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden",children:jsx("div",{className:"h-full bg-blue-500 rounded-full",style:{width:`${Math.min(100,Math.max(0,t))}%`}})}),jsxs("span",{className:"text-xs text-gray-500",children:[t.toFixed(0),"%"]})]})}default:return String(e)}}function Ta(e,a,r){let t=e[r],n=a[r];return t==null?1:n==null?-1:typeof t=="number"&&typeof n=="number"?n-t:String(n).localeCompare(String(t))}function ft({data:e,config:a}){let{columns:r,rows:t}=e,n=a?.sortable!==false,s=a?.paginated||false,o=a?.pageSize||10,[l,p]=useState("asc"),[d,f]=useState(r[0]?.key||""),[x,h]=useState(0),v=E=>{p(d===E&&l==="asc"?"desc":"asc"),f(E);},g=useMemo(()=>{let E=[...t];return n&&d&&E.sort((I,L)=>l==="desc"?Ta(I,L,d):-Ta(I,L,d)),s&&(E=E.slice(x*o,(x+1)*o)),E},[t,l,d,x,o,n,s]),C=Math.ceil(t.length/o);return jsxs("div",{className:"w-full overflow-x-auto",children:[jsxs("table",{className:"min-w-full text-sm",children:[jsx("thead",{children:jsx("tr",{children:r.map(E=>jsx("th",{className:i("px-3 py-2 font-semibold bg-gray-50 dark:bg-gray-800 whitespace-nowrap text-left",n&&"cursor-pointer select-none hover:bg-gray-100 dark:hover:bg-gray-700"),style:{width:E.width,textAlign:E.align||"left"},onClick:()=>n&&v(E.key),children:jsxs("span",{className:"inline-flex items-center gap-1",children:[E.label,n&&d===E.key&&(l==="asc"?jsx(ChevronUp,{size:14}):jsx(ChevronDown,{size:14}))]})},E.key))})}),jsxs("tbody",{children:[g.map((E,I)=>jsx("tr",{className:"border-t border-gray-100 dark:border-gray-800 hover:bg-gray-50 dark:hover:bg-gray-800/50",children:r.map(L=>jsx("td",{className:"px-3 py-2 whitespace-nowrap max-w-[300px] overflow-hidden text-ellipsis",style:{textAlign:L.align||"left"},children:ps(E[L.key],L)},L.key))},I)),g.length===0&&jsx("tr",{children:jsx("td",{colSpan:r.length,className:"px-3 py-8 text-center text-gray-400",children:"No data available"})})]})]}),s&&t.length>o&&jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-t border-gray-200 dark:border-gray-700 text-sm",children:[jsxs("span",{className:"text-gray-500",children:[x*o+1,"-",Math.min((x+1)*o,t.length)," of ",t.length]}),jsxs("div",{className:"flex gap-1",children:[jsx("button",{onClick:()=>h(Math.max(0,x-1)),disabled:x===0,className:"px-2 py-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-30",children:"Prev"}),jsx("button",{onClick:()=>h(Math.min(C-1,x+1)),disabled:x>=C-1,className:"px-2 py-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-30",children:"Next"})]})]})]})}function bt({data:e,config:a,onAction:r}){let{subtitle:t,imageUrl:n,sections:s,actions:o}=e,l=a?.collapsible||false,p=a?.initiallyCollapsed||false,[d,f]=useState(!p),x=g=>{g.startsWith("http://")||g.startsWith("https://")||g.startsWith("/")?window.open(g,"_blank","noopener,noreferrer"):r?r({type:"card_action",action:g}):window.dispatchEvent(new CustomEvent("visualization-action",{detail:{action:g}}));},h=(g,C)=>jsxs("div",{className:i(C<s.length-1&&"mb-4"),children:[g.title&&jsx("h4",{className:"font-semibold text-sm mb-2",children:g.title}),g.items&&g.items.length>0&&jsx("div",{className:"space-y-1",children:g.items.map((E,I)=>jsxs("div",{className:"flex justify-between items-start gap-4",children:[jsx("span",{className:"text-sm text-gray-500 shrink-0",children:E.label}),jsx("span",{className:"text-sm font-medium text-right",children:E.value})]},I))}),g.content&&jsx(re,{children:g.content})]},C),v=jsxs(Fragment,{children:[n&&jsx("img",{src:n,alt:"",className:"w-full h-[140px] object-cover border-b border-gray-200 dark:border-gray-700"}),t&&jsx("p",{className:"text-sm text-gray-500 italic mb-4",children:t}),s.map((g,C)=>jsxs("div",{children:[h(g,C),C<s.length-1&&jsx("hr",{className:"my-4 border-gray-200 dark:border-gray-700"})]},C))]});return jsxs("div",{className:"w-full",children:[l&&jsxs("div",{className:"flex items-center justify-between mb-2 cursor-pointer",onClick:()=>f(!d),children:[jsx("span",{className:"text-sm text-gray-500",children:d?"Click to collapse":"Click to expand"}),jsx("button",{className:"p-1",children:d?jsx(ChevronUp,{size:18}):jsx(ChevronDown,{size:18})})]}),(!l||d)&&v,o&&o.length>0&&jsx("div",{className:"flex gap-2 mt-4 pt-4 border-t border-gray-200 dark:border-gray-700",children:o.map((g,C)=>jsxs("button",{onClick:()=>x(g.action),className:i("px-3 py-1.5 text-sm rounded-lg transition-colors",g.variant==="primary"?"bg-blue-500 text-white hover:bg-blue-600":g.variant==="text"?"text-blue-500 hover:bg-blue-50":"border border-gray-300 hover:bg-gray-50"),children:[g.label,g.action.startsWith("http")&&jsx(ExternalLink,{size:14,className:"inline ml-1"})]},C))})]})}var Ns=["#3B82F6","#10B981","#F59E0B","#8B5CF6"];function ks({metric:e,color:a,animate:r}){let t=e.trend==="up"?jsx(ArrowUp,{size:16,className:"text-green-500"}):e.trend==="down"?jsx(ChevronDown,{size:16,className:"text-red-500"}):e.trend==="neutral"?jsx(Circle,{size:14,className:"text-gray-400"}):null,n=e.trend==="up"?"text-green-500":e.trend==="down"?"text-red-500":"text-gray-500",s=e.sparkline?.map((o,l)=>({value:o,idx:l}));return jsxs("div",{className:"p-4 rounded-lg border border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 relative overflow-hidden",children:[s&&s.length>0&&jsx("div",{className:"absolute bottom-0 left-0 right-0 h-10 opacity-30",children:jsx(ResponsiveContainer,{width:"100%",height:"100%",children:jsx(AreaChart,{data:s,margin:{top:0,right:0,left:0,bottom:0},children:jsx(Area,{type:"monotone",dataKey:"value",stroke:e.color||a,fill:e.color||a,strokeWidth:1,isAnimationActive:r})})})}),jsxs("div",{className:"relative z-10",children:[jsx("span",{className:"text-xs text-gray-500 font-medium uppercase tracking-wider",children:e.label}),jsxs("div",{className:"flex items-baseline gap-1 mt-1",children:[jsx("span",{className:"text-2xl font-bold",children:e.value}),e.unit&&jsx("span",{className:"text-sm text-gray-500",children:e.unit})]}),(e.trend||e.change)&&jsxs("div",{className:"flex items-center gap-1 mt-2",children:[t,e.change&&jsx("span",{className:i("text-sm font-medium",n),children:e.change}),e.changeLabel&&jsx("span",{className:"text-xs text-gray-500",children:e.changeLabel})]})]})]})}function yt({data:e,config:a,isStreaming:r=false}){let{metrics:t,layout:n="row"}=e,s=a?.colors||Ns,o=a?.animate!==false&&!r,l=n==="grid";return jsx("div",{className:i("w-full",l?"grid grid-cols-1 sm:grid-cols-2 gap-4":"flex gap-4 flex-wrap"),children:t.map((p,d)=>jsx("div",{className:i(!l&&"flex-1 min-w-[200px]"),children:jsx(ks,{metric:p,color:p.color||s[d%s.length],animate:o})},d))})}var Rs={js:"javascript",ts:"typescript",jsx:"jsx",tsx:"tsx",py:"python",rb:"ruby",rs:"rust",go:"go",java:"java",cpp:"cpp",c:"c",cs:"csharp",sh:"bash",bash:"bash",sql:"sql",html:"html",css:"css",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",md:"markdown",graphql:"graphql"};function ht({data:e}){let{code:a,language:r,lineNumbers:t=true,highlightLines:n=[],startLine:s=1}=e,[o,l]=useState(false),p=Rs[r.toLowerCase()]||r.toLowerCase(),d=async()=>{try{await navigator.clipboard.writeText(a),l(!0);}catch{}};return useEffect(()=>{if(o){let x=setTimeout(()=>l(false),2e3);return ()=>clearTimeout(x)}},[o]),jsxs("div",{className:"relative rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700",children:[jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-gray-800 dark:bg-gray-900 border-b border-gray-700",children:[jsxs("div",{className:"flex items-center gap-2",children:[jsx(FileText,{size:16,className:"text-gray-400"}),jsx("span",{className:"text-xs font-mono text-gray-400 lowercase",children:p})]}),jsx("button",{onClick:d,className:"flex items-center gap-1 px-2 py-1 text-xs rounded hover:bg-white/10 transition-colors text-gray-400 hover:text-gray-200",title:o?"Copied!":"Copy code",children:o?jsx(Check,{size:14,className:"text-green-400"}):jsx(Copy,{size:14})})]}),jsx(Prism,{language:p,style:oneDark,showLineNumbers:t,startingLineNumber:s,wrapLines:true,lineProps:x=>{let h={};return n.includes(x)&&(h.backgroundColor="rgba(59, 130, 246, 0.1)",h.display="block",h.borderLeft="3px solid #3B82F6",h.paddingLeft="8px",h.marginLeft="-11px"),{style:h}},customStyle:{margin:0,borderRadius:0,fontSize:"0.8125rem",lineHeight:"1.6",background:"#1e1e1e"},codeTagProps:{style:{fontFamily:"'Fira Code', 'JetBrains Mono', monospace"}},children:a.trim()})]})}function vt({data:e,config:a,isStreaming:r=false,onAction:t}){let{fields:n,submitAction:s}=e,o=a?.submitButtonText||"Submit",l=a?.cancelButtonText||"Cancel",[p,d]=useState(()=>{let u={};return n.forEach(c=>{c.defaultValue!==void 0?u[c.name]=c.defaultValue:c.type==="multiselect"?u[c.name]=[]:c.type==="checkbox"?u[c.name]=false:u[c.name]="";}),u}),[f,x]=useState({}),[h,v]=useState(false),g=(u,c)=>{d(k=>({...k,[u]:c})),f[u]&&x(k=>{let O={...k};return delete O[u],O});},C=()=>{let u={};return n.forEach(c=>{let k=p[c.name];if(c.required&&(k==null||k===""||Array.isArray(k)&&k.length===0)){u[c.name]=`${c.label} is required`;return}if(!(!k&&!c.required)){if(c.validation){let{min:O,max:w,pattern:q,message:Y}=c.validation;O!==void 0&&typeof k=="number"&&k<O&&(u[c.name]=Y||`Minimum value is ${O}`),w!==void 0&&typeof k=="number"&&k>w&&(u[c.name]=Y||`Maximum value is ${w}`),q&&typeof k=="string"&&!new RegExp(q).test(k)&&(u[c.name]=Y||"Invalid format");}c.type==="email"&&typeof k=="string"&&k&&!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(k)&&(u[c.name]="Invalid email address");}}),x(u),Object.keys(u).length===0},E=u=>{u.preventDefault(),C()&&(t?t({type:"form_submit",action:s||"",data:p}):window.dispatchEvent(new CustomEvent("visualization-form-submit",{detail:{action:s,data:p}})),v(true));},I=()=>{t?t({type:"form_cancel",action:s||""}):window.dispatchEvent(new CustomEvent("visualization-form-cancel",{detail:{action:s}}));};if(h)return jsxs("div",{className:"text-center py-8",children:[jsx("p",{className:"text-lg font-semibold text-green-500 mb-1",children:"Form Submitted"}),jsx("p",{className:"text-sm text-gray-500",children:"Your response has been recorded."})]});let L="w-full px-3 py-2 text-sm rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-900 focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none transition-colors",ee="border-red-500 focus:ring-red-500/20 focus:border-red-500",P=u=>{let c=p[u.name],O=!!f[u.name];switch(u.type){case "text":case "email":case "number":return jsx("input",{type:u.type,placeholder:u.placeholder,required:u.required,value:String(c||""),onChange:w=>g(u.name,u.type==="number"?parseFloat(w.target.value)||"":w.target.value),className:i(L,O&&ee),min:u.validation?.min,max:u.validation?.max});case "textarea":return jsx("textarea",{placeholder:u.placeholder,required:u.required,value:String(c||""),onChange:w=>g(u.name,w.target.value),className:i(L,"min-h-[100px] resize-y",O&&ee),rows:4});case "select":return jsxs("select",{value:String(c||""),onChange:w=>g(u.name,w.target.value),className:i(L,O&&ee),children:[jsx("option",{value:"",disabled:true,children:u.placeholder||"Select an option"}),u.options?.map(w=>jsx("option",{value:w.value,children:w.label},w.value))]});case "multiselect":return jsx("select",{multiple:true,value:c||[],onChange:w=>g(u.name,Array.from(w.target.selectedOptions,q=>q.value)),className:i(L,"min-h-[80px]",O&&ee),children:u.options?.map(w=>jsx("option",{value:w.value,children:w.label},w.value))});case "checkbox":return jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[jsx("input",{type:"checkbox",checked:!!c,onChange:w=>g(u.name,w.target.checked),className:"w-4 h-4 accent-blue-500 rounded"}),jsx("span",{className:"text-sm",children:u.label})]});case "radio":return jsx("div",{className:"space-y-1",children:u.options?.map(w=>jsxs("label",{className:"flex items-center gap-2 cursor-pointer text-sm",children:[jsx("input",{type:"radio",name:u.name,value:w.value,checked:c===w.value,onChange:q=>g(u.name,q.target.value),className:"w-3.5 h-3.5 accent-blue-500"}),w.label]},w.value))});case "date":return jsx("input",{type:"date",value:String(c||""),onChange:w=>g(u.name,w.target.value),className:i(L,O&&ee)});case "datetime":return jsx("input",{type:"datetime-local",value:String(c||""),onChange:w=>g(u.name,w.target.value),className:i(L,O&&ee)});default:return null}};return jsxs("form",{onSubmit:E,className:"space-y-4",children:[n.map(u=>jsxs("div",{children:[u.type!=="checkbox"&&jsxs("label",{className:"block text-sm font-medium mb-1",children:[u.label,u.required&&jsx("span",{className:"text-red-500 ml-0.5",children:"*"})]}),P(u),f[u.name]&&jsx("p",{className:"text-xs text-red-500 mt-1",children:f[u.name]})]},u.name)),jsxs("div",{className:"flex gap-2 pt-2",children:[jsx("button",{type:"submit",disabled:r,className:"px-4 py-2 text-sm rounded-lg bg-blue-500 text-white hover:bg-blue-600 disabled:opacity-50 transition-colors",children:o}),jsx("button",{type:"button",onClick:I,className:"px-4 py-2 text-sm rounded-lg border border-gray-300 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors",children:l})]})]})}var wt=new Map;function Ce(e,a){wt.set(e,a);}function Nt(e){return wt.get(e)}function Ra(){return Array.from(wt.keys())}Ce("chart",{component:gt});Ce("table",{component:ft});Ce("card",{component:bt});Ce("kpi",{component:yt});Ce("code_preview",{component:ht});Ce("form",{component:vt});function Ma(e){for(let[a,r]of Object.entries(e)){let t=wt.get(a);t&&(t.schema=r);}}var Ms=z.object({name:z.string(),data:z.array(z.union([z.object({x:z.union([z.string(),z.number()]),y:z.number()}),z.object({name:z.string(),value:z.number()})])),color:z.string().optional()}),Aa=z.object({label:z.string().optional(),type:z.enum(["category","number","time"]).optional(),min:z.number().optional(),max:z.number().optional()}),Ut=z.object({chartType:z.enum(["line","bar","pie","area","scatter","composed"]),series:z.array(Ms),xAxis:Aa.optional(),yAxis:Aa.optional()}),As=z.object({key:z.string(),label:z.string(),type:z.enum(["string","number","currency","date","badge","link","boolean","progress"]).optional(),align:z.enum(["left","center","right"]).optional(),width:z.string().optional()}),Ht=z.object({columns:z.array(As),rows:z.array(z.record(z.string(),z.unknown()))}),_s=z.object({title:z.string().optional(),items:z.array(z.object({label:z.string(),value:z.union([z.string(),z.number()])})).optional(),content:z.string().optional()}),Is=z.object({label:z.string(),action:z.string(),variant:z.enum(["primary","secondary","text"]).optional()}),jt=z.object({subtitle:z.string().optional(),imageUrl:z.string().optional(),sections:z.array(_s),actions:z.array(Is).optional()}),Ls=z.object({label:z.string(),value:z.union([z.string(),z.number()]),unit:z.string().optional(),trend:z.enum(["up","down","neutral"]).optional(),change:z.string().optional(),changeLabel:z.string().optional(),sparkline:z.array(z.number()).optional(),color:z.string().optional()}),Kt=z.object({metrics:z.array(Ls),layout:z.enum(["row","grid"]).optional()}),qt=z.object({code:z.string(),language:z.string(),lineNumbers:z.boolean().optional(),highlightLines:z.array(z.number()).optional(),startLine:z.number().optional()}),Vs=z.object({name:z.string(),type:z.enum(["text","number","email","select","multiselect","checkbox","radio","textarea","date","datetime"]),label:z.string(),required:z.boolean().optional(),placeholder:z.string().optional(),options:z.array(z.object({value:z.string(),label:z.string()})).optional(),defaultValue:z.unknown().optional(),validation:z.object({min:z.number().optional(),max:z.number().optional(),pattern:z.string().optional(),message:z.string().optional()}).optional()}),Gt=z.object({fields:z.array(Vs),submitAction:z.string().optional()});Ma({chart:Ut,table:Ht,card:jt,kpi:Kt,code_preview:qt,form:Gt});function kt({data:e,isStreaming:a=false,onAction:r}){let{type:t,title:n,description:s,data:o,config:l}=e;return jsxs("div",{className:"my-3 overflow-hidden",children:[(n||s)&&jsxs("div",{className:"mb-2",children:[n&&jsx("p",{className:"text-sm font-semibold",children:n}),s&&jsx("p",{className:"text-xs text-gray-500 mt-0.5",children:s})]}),jsx("div",{children:(()=>{let d=Nt(t);if(!d)return jsxs("div",{className:"flex items-center gap-2 p-4 text-yellow-500",children:[jsx(AlertCircle,{size:20}),jsxs("span",{className:"text-sm",children:["Unknown visualization type: ",t]})]});if(d.schema){let x=d.schema.safeParse(o);if(!x.success){let h=x.error.issues.slice(0,3);return jsxs("div",{className:"p-4 rounded-lg border border-red-200 dark:border-red-800 bg-red-50 dark:bg-red-950/30",children:[jsxs("div",{className:"flex items-center gap-2 text-red-600 dark:text-red-400 mb-2",children:[jsx(AlertCircle,{size:18}),jsxs("span",{className:"text-sm font-medium",children:["Invalid ",t," visualization data"]})]}),jsxs("ul",{className:"text-xs text-red-500 dark:text-red-400 space-y-1 list-disc list-inside",children:[h.map((v,g)=>jsxs("li",{children:[v.path.join("."),": ",v.message]},g)),x.error.issues.length>3&&jsxs("li",{children:["...and ",x.error.issues.length-3," more"]})]})]})}}let f=d.component;return jsx(f,{data:o,config:l,isStreaming:a,onAction:r})})()})]})}var La=/\[VIZ:([a-f0-9-]+)\]/gi;function Ws(e){let a=[],r=0,t;for(La.lastIndex=0;(t=La.exec(e))!==null;){if(t.index>r){let n=e.slice(r,t.index);n.trim()&&a.push({type:"text",content:n});}a.push({type:"viz",id:t[1]}),r=t.index+t[0].length;}if(r<e.length){let n=e.slice(r);n.trim()&&a.push({type:"text",content:n});}return a}var Va=forwardRef(({message:e,viewerRole:a$1="user",className:r,showAvatar:t=true,showTimestamp:n=true,renderMarkdown:s=true,reasoning:o,executionPlan:l,executionTimeline:p,suggestedActions:d$1,onSuggestedAction:f,reasoningExpanded:x,onReasoningExpandedChange:h,citations:v,visualizations:g,baselineFontSize:C,pendingClarification:E,onClarificationSubmit:I},L)=>{let P=useContext(a)?.onVisualizationAction,u=(e.participant?.role||"").toLowerCase(),c$1=(a$1||"").toLowerCase(),k=u===c$1,O=u==="assistant",w=e.isStreaming,q=o?.filter(y=>y.type==="thinking"||y.type==="tool"||y.type==="observation"||y.type==="planning"||y.type==="subtask"||y.type==="wave_start"||y.type==="wave_complete"||y.type==="parallel_subtask_start"||y.type==="parallel_subtask_complete"||y.type==="multi_agent_planning"||y.type==="subagent_start"||y.type==="subagent_complete"||y.type==="subagent_failed"||y.type==="synthesis"||y.type==="claude_thinking"||y.type==="subagent"||y.type==="file_operation"||y.type==="terminal"||y.type==="search_results"||y.type==="web_operation"||y.claudeToolData!=null),Y=q&&q.length>0,fe=!w&&(l||p&&p.length>0),he=Y||fe,Ae=w&&!e.textContent&&!he,Se=e.attachments,Be=Se&&Se.length>0,ce=useMemo(()=>{if(!g||g.length===0)return null;let y=new Map;return g.forEach(z=>y.set(z.id,z)),y},[g]),_e=ce&&ce.size>0,N=useMemo(()=>!_e||!e.textContent?null:Ws(e.textContent),[_e,e.textContent]),b=()=>e.textContent?N&&N.length>0&&ce?jsx(Fragment,{children:N.map((y,z)=>{if(y.type==="text")return w?jsx(je,{content:y.content,isStreaming:true,baselineFontSize:C},z):jsx(re,{baselineFontSize:C,className:k?"prose-invert":"",children:y.content},z);let F=ce.get(y.id);return F?jsx(kt,{data:F,isStreaming:w,onAction:P},`viz-${y.id}`):null})}):w&&s?jsx(je,{content:e.textContent,isStreaming:true,baselineFontSize:C,className:k?"prose-invert":""}):s?jsx(re,{baselineFontSize:C,className:k?"prose-invert":"",children:e.textContent}):jsx("p",{className:"whitespace-pre-wrap",children:e.textContent}):null,D=useRef(w);w&&(D.current=true);let T=!w&&!D.current;return jsx(c,{ref:L,message:e,viewerRole:a$1,className:i("w-full",T&&"animate-fade-in",r),children:jsxs("div",{className:i("flex flex-col gap-1 w-full"),"data-is-viewer":k,children:[Ae&&jsxs("div",{className:i("flex items-start gap-2 w-full"),children:[t&&!k&&jsx("div",{className:"flex-shrink-0",children:jsx(Ie,{name:e.participant?.name,src:e.participant?.avatarUrl,role:e.participant?.role,className:"w-10 h-10 flex-shrink-0"})}),jsx("div",{className:"px-4 py-3",children:jsx(We,{size:"small"})})]}),he&&O&&jsx("div",{className:"w-full max-w-[80%]",children:jsx(Ft,{isStreaming:w,chunks:q,plan:l,executionTimeline:p,userMessageTimestamp:e.createdAt?new Date((typeof e.createdAt=="string",e.createdAt)).getTime()/1e3:void 0,expanded:x,onExpandedChange:h})}),e.textContent&&jsxs("div",{className:i("flex items-start gap-2 w-full",k?"flex-row-reverse":"flex-row"),children:[t&&!k&&jsx("div",{className:"flex-shrink-0",children:jsx(Ie,{name:e.participant?.name,src:e.participant?.avatarUrl,role:e.participant?.role,className:"w-10 h-10 flex-shrink-0"})}),jsxs("div",{className:i("max-w-[85%]","flex flex-col"),"data-message-role":k?"viewer":"other",children:[jsxs("div",{className:i("rounded-2xl",k||t?"px-4 py-3":""),style:{backgroundColor:k?"var(--chat-user-message-bg)":"transparent",color:k?"var(--chat-user-message-text, #ffffff)":"var(--chat-text)"},children:[jsx(d,{children:b()}),v&&v.length>0&&jsx("div",{className:"mt-2 pt-2 border-t border-[var(--chat-border)]",children:jsx(Rt,{sources:v})})]}),Be&&jsx("div",{className:"mt-2",children:jsx(_t,{attachments:Se})}),n&&!w&&e.createdAt&&jsx(Us,{createdAt:typeof e.createdAt=="string"?e.createdAt:e.createdAt.toISOString(),isViewer:k})]})]}),!e.textContent&&t&&!k&&he&&!Ae&&jsx("div",{className:"flex items-start gap-2 w-full",children:jsx("div",{className:"flex-shrink-0",children:jsx(Ie,{name:e.participant?.name,src:e.participant?.avatarUrl,role:e.participant?.role,className:"w-10 h-10 flex-shrink-0"})})}),E&&!w&&I&&jsx("div",{className:"w-full max-w-[80%]",children:jsx(Mt,{clarification:E,onSubmit:I})}),d$1&&d$1.length>0&&!w&&jsx("div",{className:"w-full max-w-[80%]",children:jsx(pt,{actions:d$1,onSelect:f})})]})})});Va.displayName="Message";function Us({createdAt:e,isViewer:a}){let r=t=>{try{return new Date(t).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}catch{return ""}};return jsx("span",{className:i("text-xs mt-1 block text-[var(--chat-text-subtle)]",a&&"text-right"),children:r(e)})}var Fa=[BOLD_STAR,ITALIC_UNDERSCORE,QUOTE,ORDERED_LIST,UNORDERED_LIST],Ni={ltr:"ltr",rtl:"rtl",placeholder:"editor-placeholder",paragraph:"editor-paragraph",quote:"editor-quote",text:{}},ki=100*1024*1024,Ci=["image/jpeg","image/jpg","image/png","image/gif","image/webp","image/svg+xml","image/bmp"],Si=["application/pdf","text/plain","text/csv","text/markdown","application/json","text/json","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"],zi=["video/mp4","video/webm","video/ogg","video/avi","video/mov","video/wmv","video/flv","video/mkv"],Pi=[...Ci,...Si,...zi];function $a(e){if(e===0)return "0 Bytes";let a=1024,r=["Bytes","KB","MB","GB"],t=Math.floor(Math.log(e)/Math.log(a));return parseFloat((e/Math.pow(a,t)).toFixed(2))+" "+r[t]}function Ei(e,a,r){return e.size>r?`File size (${$a(e.size)}) exceeds max (${$a(r)})`:a.includes(e.type)?null:`File type ${e.type||"unknown"} is not allowed`}function Di({attachments:e,onRemove:a,disabled:r}){return e.length===0?null:jsx("div",{className:"flex flex-wrap gap-2 px-3 pt-3 pb-0",children:e.map(t=>{let n=t.file.type.startsWith("image/"),s=t.status==="error",o=t.status==="uploading";return jsxs("div",{className:i("relative flex items-center gap-1.5 px-2 py-1.5 rounded-lg text-xs max-w-[200px]",s?"bg-red-50 dark:bg-red-900/30 text-red-600 dark:text-red-400":"bg-gray-100 dark:bg-zinc-700 text-gray-600 dark:text-zinc-300"),children:[o?jsx(Loader2,{size:14,className:"flex-shrink-0 animate-spin"}):s?jsx(AlertCircle,{size:14,className:"flex-shrink-0"}):n&&t.previewUrl?jsx("img",{src:t.previewUrl,alt:t.file.name,className:"w-5 h-5 rounded object-cover"}):n?jsx(Image,{size:14,className:"flex-shrink-0"}):jsx(FileText,{size:14,className:"flex-shrink-0"}),jsx("span",{className:"truncate",title:s?t.error:t.file.name,children:s?t.error:t.file.name}),!r&&jsx("button",{type:"button",onClick:()=>a(t.id),className:"flex-shrink-0 ml-0.5 p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-zinc-600 transition-colors",children:jsx(X,{size:12})})]},t.id)})})}function Ti({onSubmit:e,disabled:a}){let[r]=useLexicalComposerContext();return useEffect(()=>r.registerCommand(KEY_ENTER_COMMAND,t=>!t||t.shiftKey?false:(t.preventDefault(),a||e(),true),COMMAND_PRIORITY_HIGH),[r,e,a]),null}function Ri({clearRef:e}){let[a]=useLexicalComposerContext();return useEffect(()=>{e.current=()=>{a.update(()=>{let r=$getRoot();r.clear(),r.append($createParagraphNode());});};},[a,e]),null}var Wa=forwardRef(({onSubmit:e,onAttach:a,onUploadFile:r,onRemoveUploadedAttachment:t,disabled:n=false,supportsAttachments:s=true,allowedFileTypes:o=Pi,maxFileSize:l=ki,placeholder:p="Type a message...",className:d,isSubmitting:f=false},x)=>{let[h,v]=useState(""),[g,C]=useState([]),[E,I]=useState(false),L=useRef(null),ee=useRef(null),P=useRef(0),u=n||f,c=g.some(b=>b.status==="uploading"),k=g.filter(b=>b.status==="uploaded"&&b.attachmentId).map(b=>b.attachmentId),O=k.length>0||g.some(b=>b.status==="pending"),w=h.trim().length>0||O,q=useCallback(b=>{b.read(()=>{let T=$convertToMarkdownString(Fa).replace(/\n\s*\n\s*\n+/g,`
19
+
20
+ `).replace(/(?<!\n)\n(?!\n)/g,`
21
+ `);v(T);});},[]),Y=useCallback(async b=>{let D=b.map(T=>{let y=Ei(T,o,l),z={id:`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,file:T,status:y?"error":r?"uploading":"pending",error:y||void 0};return !y&&T.type.startsWith("image/")&&(z.previewUrl=URL.createObjectURL(T)),z});if(C(T=>[...T,...D]),a?.(b),r){for(let T of D)if(T.status==="uploading")try{let y=await r(T.file);C(z=>z.map(F=>F.id===T.id?{...F,status:"uploaded",attachmentId:y}:F));}catch(y){C(z=>z.map(F=>F.id===T.id?{...F,status:"error",error:y instanceof Error?y.message:"Upload failed"}:F));}}},[o,l,r,a]),fe=useCallback(async()=>{if(!w||u||c)return;let b=h,D=g.filter(y=>y.status!=="error").map(y=>y.file),T=g;ee.current?.(),v(""),C([]);try{r&&k.length>0?await e(b,void 0,k):await e(b,D.length>0?D:void 0);}catch{v(b),C(T);}},[h,g,w,u,c,e,r,k]),he=useCallback(b=>{let D=b.target.files;!D||D.length===0||(Y(Array.from(D)),b.target.value="");},[Y]),Ae=useCallback(b=>{C(D=>{let T=D.find(y=>y.id===b);return T?.previewUrl&&URL.revokeObjectURL(T.previewUrl),T?.attachmentId&&t&&t(T.attachmentId),D.filter(y=>y.id!==b)});},[t]),Se=useCallback(b=>{b.preventDefault(),b.stopPropagation(),!(!s||f)&&(P.current++,b.dataTransfer.types.includes("Files")&&I(true));},[s,f]),Be=useCallback(b=>{b.preventDefault(),b.stopPropagation(),P.current--,P.current===0&&I(false);},[]),ce=useCallback(b=>{b.preventDefault(),b.stopPropagation();},[]),_e=useCallback(b=>{if(b.preventDefault(),b.stopPropagation(),P.current=0,I(false),!s||f)return;let D=Array.from(b.dataTransfer.files);D.length>0&&Y(D);},[s,f,Y]);useEffect(()=>()=>{g.forEach(b=>{b.previewUrl&&URL.revokeObjectURL(b.previewUrl);});},[]);let N={namespace:"ChatComposer",theme:Ni,onError(b){console.error("[ChatComposer]",b);},editorState(){return $convertFromMarkdownString("",Fa)},nodes:[ListItemNode,ListNode,AutoLinkNode,QuoteNode],editable:!f};return jsx("div",{ref:x,className:i("flex-shrink-0 px-3 pt-2 pb-3","border-t border-gray-200 dark:border-zinc-700","bg-white/95 dark:bg-zinc-900/95 backdrop-blur-sm",d),onDragEnter:Se,onDragLeave:Be,onDragOver:ce,onDrop:_e,children:jsxs("div",{className:i("mx-auto max-w-[900px]","rounded-xl","bg-white dark:bg-zinc-800","border border-gray-200 dark:border-zinc-700","shadow-sm","transition-all duration-200","focus-within:shadow-md focus-within:border-gray-300 dark:focus-within:border-zinc-600",E&&"ring-2 ring-blue-400 border-blue-400"),children:[E&&jsx("div",{className:"px-3 pt-3 pb-0",children:jsx("div",{className:"flex items-center justify-center py-4 rounded-lg border-2 border-dashed border-blue-300 bg-blue-50 dark:bg-blue-900/20 text-blue-500 text-sm",children:"Drop files here"})}),jsx(Di,{attachments:g,onRemove:Ae,disabled:f}),jsxs("div",{className:i("flex items-center gap-2 p-3",g.length>0&&"pt-1.5"),children:[s&&jsx("button",{type:"button",onClick:()=>L.current?.click(),disabled:f,className:i("flex-shrink-0","w-8 h-8 rounded-lg","flex items-center justify-center","border border-gray-200 dark:border-zinc-600","text-gray-500 dark:text-zinc-400","hover:bg-gray-50 dark:hover:bg-zinc-700","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors"),children:jsx(Paperclip,{size:16})}),jsx("div",{className:"flex-1 min-w-0",children:jsx(LexicalComposer,{initialConfig:N,children:jsxs("div",{className:"relative px-1 text-sm",children:[jsx(RichTextPlugin,{contentEditable:jsx(ContentEditable,{className:i("outline-none resize-none","min-h-[24px] max-h-[200px] overflow-y-auto","text-gray-900 dark:text-zinc-100","[&_.editor-paragraph]:my-0","[&_.editor-quote]:ml-0 [&_.editor-quote]:pl-3 [&_.editor-quote]:border-l-4 [&_.editor-quote]:border-gray-300","[&_ul]:pl-4 [&_ol]:pl-4")}),placeholder:jsx("span",{className:"absolute top-0 left-1 text-gray-400 dark:text-zinc-500 pointer-events-none select-none",children:p}),ErrorBoundary:LexicalErrorBoundary}),jsx(OnChangePlugin,{onChange:q}),jsx(ListPlugin,{}),jsx(HistoryPlugin,{}),jsx(AutoFocusPlugin,{defaultSelection:"rootStart"}),jsx(Ti,{onSubmit:fe,disabled:u||c}),jsx(Ri,{clearRef:ee})]})})}),jsx("button",{type:"button",onClick:fe,disabled:!w||u||c,className:i("flex-shrink-0","w-9 h-9 rounded-lg","flex items-center justify-center","bg-blue-500 text-white","shadow-sm","hover:bg-blue-600 hover:shadow-md hover:-translate-y-px","active:translate-y-0 active:shadow-sm","disabled:bg-gray-300 dark:disabled:bg-zinc-600 disabled:shadow-none disabled:translate-y-0 disabled:cursor-not-allowed","transition-all duration-200"),children:f||c?jsx(Loader2,{size:16,className:"animate-spin"}):jsx(ArrowUp,{size:16})})]}),s&&jsx("input",{ref:L,type:"file",multiple:true,accept:o.join(","),onChange:he,className:"hidden"})]})})});Wa.displayName="MessageComposer";var Ua=forwardRef(({children:e,autoScroll:a=true,className:r},t)=>jsx(f,{ref:t,autoScroll:a,className:i("flex-1 overflow-y-auto","flex flex-col gap-4 p-4","chat-scrollbar",r),children:e}));Ua.displayName="MessageList";function _i({label:e,className:a}){return jsxs("div",{className:`flex items-center gap-3 py-6 select-none ${a??""}`,role:"separator",children:[jsx("div",{className:"flex-1 h-px bg-[var(--chat-border)]"}),jsx("span",{className:"text-xs font-medium text-[var(--chat-text-subtle)] whitespace-nowrap",children:e}),jsx("div",{className:"flex-1 h-px bg-[var(--chat-border)]"})]})}var ja=forwardRef(({className:e},a)=>jsx(r,{ref:a,className:i("inline-flex items-center gap-1","px-4 py-3",e),children:jsx(We,{size:"small"})}));ja.displayName="TypingIndicator";function Bi({title:e,subtitle:a,logo:r,actions:t,showClose:n,onClose:s,loading:o,className:l,style:p}){let[d,f]=useState(false),x=useRef(null),h=useRef(null);return useEffect(()=>{let v=g=>{let C=g.composedPath();x.current&&!C.includes(x.current)&&h.current&&!C.includes(h.current)&&f(false);};if(d)return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[d]),jsxs("header",{className:i("flex items-center justify-between gap-3","px-4 py-3","border-b border-[var(--chat-border)]","bg-[var(--chat-header-bg,#ffffff)]",l),style:p,children:[jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[r&&jsx("div",{className:"flex-shrink-0",children:typeof r=="string"?jsx("img",{src:r,alt:"",className:"w-10 h-10 rounded-lg object-contain"}):r}),jsxs("div",{className:"flex flex-col min-w-0",children:[o?jsx("div",{className:"h-5 w-24 bg-gray-200 rounded animate-pulse"}):jsx("h1",{className:"text-lg font-semibold text-[var(--chat-text)] truncate",children:e}),a&&jsx("p",{className:"text-sm text-[var(--chat-text-subtle)] truncate",children:a})]})]}),jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[t&&t.length>0&&jsxs("div",{className:"relative",children:[jsx("button",{ref:h,onClick:()=>f(!d),className:i("p-2 rounded-lg","text-[var(--chat-text-subtle)]","hover:bg-[var(--chat-panel-bg)] hover:text-[var(--chat-text)]","transition-colors duration-200"),"aria-label":"Menu","aria-expanded":d,children:jsx(MoreVertical,{size:18})}),d&&jsx("div",{ref:x,className:i("absolute right-0 top-full mt-1 z-50","min-w-[180px]","bg-white rounded-lg shadow-lg","border border-[var(--chat-border)]","py-1","animate-fade-in"),children:t.map(v=>jsxs("button",{onClick:()=>{v.onClick(),f(false);},disabled:v.disabled,className:i("w-full flex items-center gap-2 px-3 py-2","text-sm text-left","text-[var(--chat-text)]","hover:bg-[var(--chat-panel-bg)]","disabled:opacity-50 disabled:cursor-not-allowed","transition-colors duration-150"),children:[v.icon&&jsx("span",{className:"flex-shrink-0 text-[var(--chat-text-subtle)]",children:v.icon}),v.label]},v.id))})]}),n&&s&&jsx("button",{onClick:s,className:i("p-2 rounded-lg","text-[var(--chat-text-subtle)]","hover:bg-[var(--chat-panel-bg)] hover:text-[var(--chat-text)]","transition-colors duration-200"),"aria-label":"Close",children:jsx(X,{size:18})})]})]})}var Ga=forwardRef(({isEmpty:e,header:a,welcomeScreen:r,messageList:t,composer:n,footer:s,className:o},l)=>jsx("div",{ref:l,className:i("relative h-full overflow-hidden flex flex-col min-h-0",o),children:jsx(AnimatePresence,{mode:"wait",children:e&&r?jsxs(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.3},className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[a,r]},"welcome"):jsxs(motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.4},className:"flex-1 flex flex-col overflow-hidden min-h-0",children:[a,jsx(motion.div,{initial:{opacity:0,y:-20},animate:{opacity:1,y:0},transition:{duration:.4,delay:.1},className:"flex-1 overflow-hidden flex flex-col min-h-0",children:t}),s,jsx(motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.4,delay:.2},children:n})]},"active")})}));Ga.displayName="ChatLayout";function Gi(e,a=3e3){let[r,t]=useState(0),n=useRef(null);return useEffect(()=>{if(e.length<=1)return;let s=()=>{n.current=setInterval(()=>{t(l=>(l+1)%e.length);},a);},o=()=>{document.visibilityState!=="visible"?n.current&&(clearInterval(n.current),n.current=null):s();};return s(),document.addEventListener("visibilitychange",o),()=>{n.current&&clearInterval(n.current),document.removeEventListener("visibilitychange",o);}},[e,a]),e[r]??""}function Xi({placeholder:e,onSubmit:a,disabled:r,supportsAttachments:t}){let[n,s]=useState(""),[o,l]=useState([]),p=useRef(null),d=useRef(null);useEffect(()=>{p.current&&(p.current.style.height="auto",p.current.style.height=p.current.scrollHeight+"px");},[n]);let f=g=>{g.key==="Enter"&&!g.shiftKey&&(g.preventDefault(),x());},x=()=>{!n.trim()&&o.length===0||r||(a(n.trim(),o.length>0?o:void 0),s(""),l([]));},h=g=>{g.target.files&&l(C=>[...C,...Array.from(g.target.files)]),g.target.value="";},v=g=>{l(C=>C.filter((E,I)=>I!==g));};return jsxs("form",{className:i("w-full relative mx-auto","bg-white dark:bg-zinc-800","rounded-2xl overflow-hidden","shadow-[0_8px_30px_rgba(0,0,0,0.08)]","border border-gray-100 dark:border-zinc-700/50","transition duration-200","focus-within:shadow-[0_8px_30px_rgba(0,0,0,0.12)] focus-within:border-gray-200 dark:focus-within:border-zinc-600"),onSubmit:g=>{g.preventDefault(),x();},children:[o.length>0&&jsx("div",{className:"flex flex-wrap gap-2 px-4 pt-3",children:o.map((g,C)=>jsxs("div",{className:i("flex items-center gap-1.5 px-2.5 py-1 rounded-lg text-xs","bg-gray-100 dark:bg-zinc-700 text-gray-600 dark:text-zinc-300"),children:[jsx("span",{className:"max-w-[120px] truncate",children:g.name}),jsx("button",{type:"button",onClick:()=>v(C),className:"flex-shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-zinc-200",children:jsx(X,{size:12})})]},`${g.name}-${C}`))}),jsxs("div",{className:"flex items-center gap-2",children:[t&&jsx("button",{type:"button",onClick:()=>d.current?.click(),disabled:r,className:i("ml-3 flex-shrink-0","w-8 h-8 rounded-lg","flex items-center justify-center","text-gray-400 dark:text-zinc-500","hover:bg-gray-100 dark:hover:bg-zinc-700","hover:text-gray-600 dark:hover:text-zinc-300","disabled:opacity-40 disabled:cursor-not-allowed","transition-colors"),children:jsx(Paperclip,{size:16})}),jsx("textarea",{ref:p,value:n,onChange:g=>s(g.target.value),onKeyDown:f,disabled:r,rows:1,placeholder:e,className:i("flex-1 text-sm sm:text-base","border-none bg-transparent","text-gray-900 dark:text-white","focus:outline-none focus:ring-0 resize-none","py-4 sm:py-5",t?"pl-1":"pl-4 sm:pl-6","placeholder:text-gray-400 dark:placeholder:text-zinc-500","disabled:opacity-50 disabled:cursor-not-allowed","max-h-[200px] overflow-y-auto")}),jsx("button",{type:"submit",disabled:!n.trim()&&o.length===0||!!r,className:i("mr-3 flex-shrink-0","w-9 h-9 rounded-lg","flex items-center justify-center","bg-gray-900 dark:bg-zinc-600 text-white dark:text-zinc-100","shadow-sm","hover:bg-gray-700 dark:hover:bg-zinc-500","hover:shadow-md hover:-translate-y-px","active:translate-y-0 active:shadow-sm","disabled:bg-gray-300 dark:disabled:bg-zinc-700","disabled:text-gray-500 dark:disabled:text-zinc-400","disabled:shadow-none disabled:translate-y-0 disabled:cursor-not-allowed","transition-all duration-200"),children:jsx("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:"M12 19V5M5 12l7-7 7 7"})})})]}),t&&jsx("input",{ref:d,type:"file",multiple:true,onChange:h,className:"hidden"})]})}function Yi({text:e,onClick:a,index:r}){let t=useRef(null),n=useRef(typeof window<"u"?window.matchMedia("(prefers-reduced-motion: reduce)").matches:false),[s,o]=useState(null),l=useCallback(d=>{if(n.current)return;let f=d.currentTarget.getBoundingClientRect();o({x:d.clientX-f.left,y:d.clientY-f.top});},[]),p=useCallback(()=>{o(null);},[]);return jsx(motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.2+r*.1,duration:.4},children:jsxs("button",{ref:t,type:"button",onClick:a,onMouseMove:l,onMouseLeave:p,className:i("relative overflow-hidden","w-full text-left","p-3","cursor-pointer","border border-gray-200 dark:border-zinc-700","rounded-lg","transition-all duration-200 ease-out","bg-white dark:bg-zinc-800","hover:border-gray-300 dark:hover:border-zinc-600","hover:bg-gray-50 dark:hover:bg-zinc-750","hover:shadow-sm","active:bg-gray-100 dark:active:bg-zinc-700"),children:[s&&jsx("div",{className:"pointer-events-none absolute inset-0 z-0",style:{background:`radial-gradient(120px circle at ${s.x}px ${s.y}px, var(--chat-halo-primary, rgba(16,105,151,0.06)), transparent)`}}),jsxs("div",{className:"relative z-10 flex items-start gap-2.5",children:[jsx(MessageCircleQuestion,{size:16,strokeWidth:2,className:"mt-0.5 text-gray-400 dark:text-zinc-500 flex-shrink-0"}),jsx("span",{className:"text-sm text-gray-600 dark:text-zinc-300 leading-relaxed flex-1",children:e})]})]})})}var Ya=forwardRef(({placeholders:e=[],suggestions:a=[],onSubmit:r,onSuggestionClick:t,welcomeText:n="How can I help you today?",supportsAttachments:s,composerSlot:o,className:l},p)=>{let d=Gi(e),f=useCallback(x=>{t?.(x);},[t]);return jsxs("div",{ref:p,className:i("relative overflow-hidden","flex-1 flex items-center justify-center","px-4 sm:px-6",l),children:[jsx("div",{className:"pointer-events-none absolute inset-0 animate-welcome-halo",style:{background:"radial-gradient(ellipse 60% 50% at 50% 45%, var(--chat-halo-primary, rgba(16,105,151,0.06)), var(--chat-halo-secondary, rgba(86,193,138,0.03)) 60%, transparent 100%)"}}),jsxs(motion.div,{layout:true,initial:{scale:.95,y:20,opacity:0},animate:{scale:1,y:0,opacity:1},transition:{type:"spring",stiffness:200,damping:25},className:"relative w-full max-w-[800px] flex flex-col items-center gap-8",children:[n&&jsx(motion.h2,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},transition:{delay:.1,duration:.4},className:"text-2xl font-semibold text-gray-800 dark:text-gray-300 text-center",children:n}),jsx("div",{className:i("w-full rounded-2xl","transition-shadow duration-500","shadow-[0_0_15px_rgba(16,105,151,0.08)]","focus-within:shadow-[0_0_20px_rgba(16,105,151,0.15),0_0_40px_rgba(86,193,138,0.08)]","dark:shadow-[0_0_15px_rgba(255,255,255,0.04)]","dark:focus-within:shadow-[0_0_20px_rgba(255,255,255,0.08),0_0_40px_rgba(255,255,255,0.03)]"),children:o??jsx(Xi,{placeholder:d,onSubmit:(x,h)=>r?.(x,h),supportsAttachments:s})}),a.length>0&&jsx("div",{className:i("grid gap-3 w-full max-w-[900px]","grid-cols-1 sm:grid-cols-[repeat(auto-fit,minmax(250px,1fr))]"),children:a.map((x,h)=>jsx(Yi,{text:x,onClick:()=>f(x),index:h},h))})]})]})});Ya.displayName="WelcomeScreen";export{je as A,pt as B,gt as C,ft as D,bt as E,yt as F,ht as G,vt as H,Ce as I,Nt as J,Ra as K,Ut as L,Ht as M,jt as N,Kt as O,qt as P,Gt as Q,kt as R,Va as S,Wa as T,Ua as U,_i as V,ja as W,Bi as X,Ga as Y,Ya as Z,i as a,pa as b,Ie as c,ma as d,We as e,re as f,Rt as g,fa as h,_r as i,Mt as j,_t as k,Qe as l,De as m,en as n,Lt as o,et as p,on as q,we as r,at as s,rt as t,nt as u,ot as v,st as w,it as x,lt as y,Ft as z};//# sourceMappingURL=chunk-3GQNGDXX.mjs.map
22
+ //# sourceMappingURL=chunk-3GQNGDXX.mjs.map