libre-webui 0.23.1 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/dist/index.d.ts.map +1 -1
- package/backend/dist/index.js +2 -0
- package/backend/dist/index.js.map +1 -1
- package/backend/dist/routes/chat.d.ts.map +1 -1
- package/backend/dist/routes/chat.js +148 -3
- package/backend/dist/routes/chat.js.map +1 -1
- package/backend/dist/routes/ollama.d.ts.map +1 -1
- package/backend/dist/routes/ollama.js +48 -1
- package/backend/dist/routes/ollama.js.map +1 -1
- package/backend/dist/services/apiTokenService.d.ts.map +1 -1
- package/backend/dist/services/apiTokenService.js +1 -0
- package/backend/dist/services/apiTokenService.js.map +1 -1
- package/backend/dist/services/chatGenerationService.d.ts +11 -1
- package/backend/dist/services/chatGenerationService.d.ts.map +1 -1
- package/backend/dist/services/chatGenerationService.js +22 -2
- package/backend/dist/services/chatGenerationService.js.map +1 -1
- package/backend/dist/services/chatService.d.ts +14 -1
- package/backend/dist/services/chatService.d.ts.map +1 -1
- package/backend/dist/services/chatService.js +109 -5
- package/backend/dist/services/chatService.js.map +1 -1
- package/backend/dist/services/contextCompactionService.d.ts +36 -0
- package/backend/dist/services/contextCompactionService.d.ts.map +1 -0
- package/backend/dist/services/contextCompactionService.js +285 -0
- package/backend/dist/services/contextCompactionService.js.map +1 -0
- package/backend/dist/services/durableChatGenerationService.d.ts.map +1 -1
- package/backend/dist/services/durableChatGenerationService.js +121 -11
- package/backend/dist/services/durableChatGenerationService.js.map +1 -1
- package/backend/dist/services/followUpService.d.ts.map +1 -1
- package/backend/dist/services/followUpService.js +8 -2
- package/backend/dist/services/followUpService.js.map +1 -1
- package/backend/dist/services/modelVisibilityService.d.ts +45 -0
- package/backend/dist/services/modelVisibilityService.d.ts.map +1 -0
- package/backend/dist/services/modelVisibilityService.js +215 -0
- package/backend/dist/services/modelVisibilityService.js.map +1 -0
- package/backend/dist/services/ollamaService.d.ts +16 -1
- package/backend/dist/services/ollamaService.d.ts.map +1 -1
- package/backend/dist/services/ollamaService.js +52 -13
- package/backend/dist/services/ollamaService.js.map +1 -1
- package/backend/dist/services/pluginService.d.ts +14 -0
- package/backend/dist/services/pluginService.d.ts.map +1 -1
- package/backend/dist/services/pluginService.js +111 -13
- package/backend/dist/services/pluginService.js.map +1 -1
- package/backend/dist/services/preferencesService.d.ts.map +1 -1
- package/backend/dist/services/preferencesService.js +3 -0
- package/backend/dist/services/preferencesService.js.map +1 -1
- package/backend/dist/services/titleGenerationService.d.ts.map +1 -1
- package/backend/dist/services/titleGenerationService.js +20 -2
- package/backend/dist/services/titleGenerationService.js.map +1 -1
- package/backend/dist/services/workAgentService.d.ts.map +1 -1
- package/backend/dist/services/workAgentService.js +22 -0
- package/backend/dist/services/workAgentService.js.map +1 -1
- package/backend/dist/types/index.d.ts +23 -2
- package/backend/dist/types/index.d.ts.map +1 -1
- package/backend/dist/types/index.js.map +1 -1
- package/backend/dist/utils/chatContext.d.ts +7 -0
- package/backend/dist/utils/chatContext.d.ts.map +1 -1
- package/backend/dist/utils/chatContext.js +13 -2
- package/backend/dist/utils/chatContext.js.map +1 -1
- package/backend/dist/utils/ollamaModelDefaults.d.ts +10 -0
- package/backend/dist/utils/ollamaModelDefaults.d.ts.map +1 -1
- package/backend/dist/utils/ollamaModelDefaults.js +19 -1
- package/backend/dist/utils/ollamaModelDefaults.js.map +1 -1
- package/backend/dist/utils/openAIResponsesAdapter.d.ts +2 -0
- package/backend/dist/utils/openAIResponsesAdapter.d.ts.map +1 -1
- package/backend/dist/utils/openAIResponsesAdapter.js +5 -0
- package/backend/dist/utils/openAIResponsesAdapter.js.map +1 -1
- package/backend/dist/utils/pluginChatAdapter.d.ts +1 -0
- package/backend/dist/utils/pluginChatAdapter.d.ts.map +1 -1
- package/backend/dist/utils/pluginChatAdapter.js +101 -11
- package/backend/dist/utils/pluginChatAdapter.js.map +1 -1
- package/backend/dist/utils/pluginModelCatalog.d.ts +50 -0
- package/backend/dist/utils/pluginModelCatalog.d.ts.map +1 -0
- package/backend/dist/utils/pluginModelCatalog.js +221 -0
- package/backend/dist/utils/pluginModelCatalog.js.map +1 -0
- package/backend/dist/utils/pluginStreamAdapter.d.ts +12 -1
- package/backend/dist/utils/pluginStreamAdapter.d.ts.map +1 -1
- package/backend/dist/utils/pluginStreamAdapter.js +32 -2
- package/backend/dist/utils/pluginStreamAdapter.js.map +1 -1
- package/backend/dist/utils/pluginStreaming.d.ts +10 -0
- package/backend/dist/utils/pluginStreaming.d.ts.map +1 -1
- package/backend/dist/utils/pluginStreaming.js.map +1 -1
- package/backend/dist/utils/thinkingOptions.d.ts +68 -0
- package/backend/dist/utils/thinkingOptions.d.ts.map +1 -0
- package/backend/dist/utils/thinkingOptions.js +130 -0
- package/backend/dist/utils/thinkingOptions.js.map +1 -0
- package/backend/dist/websocketServer.d.ts.map +1 -1
- package/backend/dist/websocketServer.js +1 -1
- package/backend/dist/websocketServer.js.map +1 -1
- package/backend/package.json +3 -3
- package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
- package/frontend/dist/artifact-runtime/framer-motion.js +3 -3
- package/frontend/dist/artifact-runtime/papaparse.js +5 -5
- package/frontend/dist/assets/index-CDQ12KBq.js +34 -0
- package/frontend/dist/assets/index-DkFWzmFD.css +1 -0
- package/frontend/dist/assets/{markdown-math-ClTedVi7.css → markdown-math-Ddr6Z9Sf.css} +1 -1
- package/frontend/dist/index.html +15 -15
- package/frontend/dist/js/ArtifactContainer-B-hs0F5K.js +1 -0
- package/frontend/dist/js/{ArtifactDemoPage-QRve-734.js → ArtifactDemoPage-QFtJw-u4.js} +1 -1
- package/frontend/dist/js/{ArtifactSandboxFrame-DhvA-t-7.js → ArtifactSandboxFrame-S9g_q47-.js} +2 -2
- package/frontend/dist/js/ArtifactSlideOutPanel-D0UOo8RW.js +1 -0
- package/frontend/dist/js/{Button-BV44cTnj.js → Button-BPf_pOxH.js} +1 -1
- package/frontend/dist/js/ChatPage-fdd8500b.js +23 -0
- package/frontend/dist/js/FirstTimeSetup-BTjafGOq.js +1 -0
- package/frontend/dist/js/GalleryPage-hR9AJ6b-.js +1 -0
- package/frontend/dist/js/HomePage-JvTzq-Pp.js +1 -0
- package/frontend/dist/js/LibreClawPage-CLJvtXft.js +1 -0
- package/frontend/dist/js/{ModelManagerModals-CZAWUxjI.js → ModelManagerModals-DBmm_slu.js} +1 -1
- package/frontend/dist/js/ModelSelector-A-viVFEc.js +1 -0
- package/frontend/dist/js/ModelsPage-C4Rm-TZF.js +2 -0
- package/frontend/dist/js/NotesPage-C7bPU_KF.js +1 -0
- package/frontend/dist/js/{OptimizedSyntaxHighlighter-XwqZEoTf.js → OptimizedSyntaxHighlighter-Dz7D1LPB.js} +1 -1
- package/frontend/dist/js/{PersonasPage-DpN8DQkY.js → PersonasPage-DpvxbFzv.js} +2 -2
- package/frontend/dist/js/{PluginUsagePage-5PXXZXle.js → PluginUsagePage-laF-M2X9.js} +1 -1
- package/frontend/dist/js/RichMessageContent-D0mK9vRA.js +3 -0
- package/frontend/dist/js/SettingsModal-DNEQ5sTt.js +1 -0
- package/frontend/dist/js/{SettingsToggle-WTa0rgvY.js → SettingsToggle-woG_WebF.js} +1 -1
- package/frontend/dist/js/{SystemPage-FUnoW7Er.js → SystemPage-Xr7XJv8c.js} +1 -1
- package/frontend/dist/js/UserManagementPage-DGmbGTC2.js +1 -0
- package/frontend/dist/js/WorkPage-DNKFD9gS.js +6 -0
- package/frontend/dist/js/{api-Dw_IuHaz.js → api-DGVZHSkS.js} +2 -2
- package/frontend/dist/js/{appStore-DAT2R-5p.js → appStore-DXlmTjIC.js} +2 -2
- package/frontend/dist/js/ar-DW79oSyN.js +2 -0
- package/frontend/dist/js/authStore-B97lJ5Ee.js +4 -0
- package/frontend/dist/js/bn-BEAmE7VH.js +2 -0
- package/frontend/dist/js/chatStore-zilBUd1p.js +3 -0
- package/frontend/dist/js/{config-0eBxRk6E.js → config-CmEh9o8U.js} +1 -1
- package/frontend/dist/js/cs-irpRMzRo.js +2 -0
- package/frontend/dist/js/da-cgilTVxc.js +2 -0
- package/frontend/dist/js/de-BU-eH3gU.js +2 -0
- package/frontend/dist/js/es-B2LRpZ0p.js +2 -0
- package/frontend/dist/js/{estree-Db_NKIE7.js → estree-CZO8RS52.js} +1 -1
- package/frontend/dist/js/fr-Cd5JM-oQ.js +2 -0
- package/frontend/dist/js/hi-CvOhdtiK.js +2 -0
- package/frontend/dist/js/{html-INl_p8N8.js → html-C31pxhBG.js} +1 -1
- package/frontend/dist/js/id-BtRK5nR_.js +2 -0
- package/frontend/dist/js/is-CnEqwgRF.js +2 -0
- package/frontend/dist/js/it-CI6WjId6.js +2 -0
- package/frontend/dist/js/ja-B6gFOHi6.js +2 -0
- package/frontend/dist/js/ko-DuAhnmMf.js +2 -0
- package/frontend/dist/js/{markdown-DQbfLH11.js → markdown-C1CEqXpL.js} +1 -1
- package/frontend/dist/js/{messageCodeStyles-D7zXzjgH.js → messageCodeStyles-BqQ6kOSU.js} +2 -2
- package/frontend/dist/js/ms-C8BIP7MZ.js +2 -0
- package/frontend/dist/js/nl-DnEdspER.js +2 -0
- package/frontend/dist/js/pl-Ddyyvbse.js +2 -0
- package/frontend/dist/js/pt-BYuzm70F.js +2 -0
- package/frontend/dist/js/ru-CmSPFxPX.js +2 -0
- package/frontend/dist/js/{standalone-CFSd7xCM.js → standalone-Dz0pkxn0.js} +1 -1
- package/frontend/dist/js/sv-Dd6SQ9f1.js +2 -0
- package/frontend/dist/js/th-CpH8745B.js +2 -0
- package/frontend/dist/js/thinking-DwlkTfPX.js +1 -0
- package/frontend/dist/js/tr-DuVD75iJ.js +2 -0
- package/frontend/dist/js/{typescript-BIFKSiW0.js → typescript-DeXPhp90.js} +1 -1
- package/frontend/dist/js/ui-CO0DPqrI.js +2 -0
- package/frontend/dist/js/{ui-vendor-54SgntkX.js → ui-vendor-mqjSfAaS.js} +1 -1
- package/frontend/dist/js/uk-B0MU-M8k.js +2 -0
- package/frontend/dist/js/{useTranslation-C3ei3mJq.js → useTranslation-Bho4HCyg.js} +1 -1
- package/frontend/dist/js/{utils-CuC1beTY.js → utils-D9W1Lnkn.js} +1 -1
- package/frontend/dist/js/{utils-vendor-BBa8OxtB.js → utils-vendor-DWh39_3x.js} +1 -1
- package/frontend/dist/js/vi-BLmFNp_z.js +2 -0
- package/frontend/dist/js/{workApi-DlmJ72dN.js → workApi-C4QtuhcE.js} +2 -2
- package/frontend/dist/js/zh-BQu0TLhw.js +2 -0
- package/package.json +3 -3
- package/frontend/dist/assets/index-BXMQqOXF.js +0 -11
- package/frontend/dist/assets/index-DBaj1DRj.css +0 -1
- package/frontend/dist/js/ArtifactContainer-BUjOZ5M5.js +0 -1
- package/frontend/dist/js/ArtifactSlideOutPanel-B8w1Orr1.js +0 -1
- package/frontend/dist/js/ChatPage-DKVwaYxn.js +0 -23
- package/frontend/dist/js/FirstTimeSetup-DaQveC0v.js +0 -1
- package/frontend/dist/js/GalleryPage-Cz-VvarV.js +0 -1
- package/frontend/dist/js/HomePage-DF9pZ5V5.js +0 -1
- package/frontend/dist/js/LibreClawPage-Dw8YQyFj.js +0 -1
- package/frontend/dist/js/ModelSelector-Cc91MEm4.js +0 -1
- package/frontend/dist/js/ModelsPage-BgaQuCry.js +0 -2
- package/frontend/dist/js/NotesPage-CRAo-TFI.js +0 -1
- package/frontend/dist/js/RichMessageContent-C67tFlr1.js +0 -3
- package/frontend/dist/js/SettingsModal-BEzMSDlp.js +0 -1
- package/frontend/dist/js/UserManagementPage-SBsRbt0H.js +0 -1
- package/frontend/dist/js/WorkPage-D3ChSFo-.js +0 -6
- package/frontend/dist/js/ar-D0z0P4rC.js +0 -2
- package/frontend/dist/js/authStore-CwSMGkEM.js +0 -4
- package/frontend/dist/js/bn-BYYU41A7.js +0 -2
- package/frontend/dist/js/chatStore-BK6YcouV.js +0 -3
- package/frontend/dist/js/cs-BFx6KNZe.js +0 -2
- package/frontend/dist/js/da-DSDuY5Du.js +0 -2
- package/frontend/dist/js/de-YqhP0FmX.js +0 -2
- package/frontend/dist/js/es-Dpr_y1cN.js +0 -2
- package/frontend/dist/js/fr-nVg_iAEC.js +0 -2
- package/frontend/dist/js/hi-gHKYCgkP.js +0 -2
- package/frontend/dist/js/id-C_yID1Zk.js +0 -2
- package/frontend/dist/js/is-MoRPLbOM.js +0 -2
- package/frontend/dist/js/it-BZTscLxR.js +0 -2
- package/frontend/dist/js/ja-DpIbtmZq.js +0 -2
- package/frontend/dist/js/ko-LkWggmjU.js +0 -2
- package/frontend/dist/js/ms-p3XiQSAo.js +0 -2
- package/frontend/dist/js/nl-sEHHO2Kb.js +0 -2
- package/frontend/dist/js/pl-D2GD6PDW.js +0 -2
- package/frontend/dist/js/pt-DPkn3GUn.js +0 -2
- package/frontend/dist/js/ru-C42iHrEd.js +0 -2
- package/frontend/dist/js/sv-CGvHo4os.js +0 -2
- package/frontend/dist/js/th-BaDNpCdY.js +0 -2
- package/frontend/dist/js/tr-BHQvi1cN.js +0 -2
- package/frontend/dist/js/ui-CS8EAgvS.js +0 -2
- package/frontend/dist/js/uk-7pNGS1b2.js +0 -2
- package/frontend/dist/js/vi-DgAfh6mo.js +0 -2
- package/frontend/dist/js/zh-FRTz6ZqA.js +0 -2
- /package/frontend/dist/js/{markdown-math-mH7AZ_mb.js → markdown-math-DK846gXU.js} +0 -0
package/frontend/dist/index.html
CHANGED
|
@@ -60,28 +60,28 @@
|
|
|
60
60
|
name="twitter:image:alt"
|
|
61
61
|
content="Libre WebUI icon over a retro-futuristic cityscape"
|
|
62
62
|
/>
|
|
63
|
-
<script type="module" crossorigin src="/assets/index-
|
|
63
|
+
<script type="module" crossorigin src="/assets/index-CDQ12KBq.js"></script>
|
|
64
64
|
<link rel="modulepreload" crossorigin href="/js/rolldown-runtime-hePW80VL.js">
|
|
65
65
|
<link rel="modulepreload" crossorigin href="/js/markdown-core-BmPPZiuD.js">
|
|
66
66
|
<link rel="modulepreload" crossorigin href="/js/react-vendor-C5yShNlM.js">
|
|
67
67
|
<link rel="modulepreload" crossorigin href="/js/router-vendor-CbPDks39.js">
|
|
68
|
-
<link rel="modulepreload" crossorigin href="/js/utils-vendor-
|
|
69
|
-
<link rel="modulepreload" crossorigin href="/js/utils-
|
|
70
|
-
<link rel="modulepreload" crossorigin href="/js/useTranslation-
|
|
68
|
+
<link rel="modulepreload" crossorigin href="/js/utils-vendor-DWh39_3x.js">
|
|
69
|
+
<link rel="modulepreload" crossorigin href="/js/utils-D9W1Lnkn.js">
|
|
70
|
+
<link rel="modulepreload" crossorigin href="/js/useTranslation-Bho4HCyg.js">
|
|
71
71
|
<link rel="modulepreload" crossorigin href="/js/i18next-DgmgtwsV.js">
|
|
72
|
-
<link rel="modulepreload" crossorigin href="/js/ui-vendor-
|
|
72
|
+
<link rel="modulepreload" crossorigin href="/js/ui-vendor-mqjSfAaS.js">
|
|
73
73
|
<link rel="modulepreload" crossorigin href="/js/logger-DSXjF4ye.js">
|
|
74
|
-
<link rel="modulepreload" crossorigin href="/js/config-
|
|
75
|
-
<link rel="modulepreload" crossorigin href="/js/workApi-
|
|
76
|
-
<link rel="modulepreload" crossorigin href="/js/api-
|
|
77
|
-
<link rel="modulepreload" crossorigin href="/js/chatStore-
|
|
78
|
-
<link rel="modulepreload" crossorigin href="/js/appStore-
|
|
79
|
-
<link rel="modulepreload" crossorigin href="/js/authStore-
|
|
74
|
+
<link rel="modulepreload" crossorigin href="/js/config-CmEh9o8U.js">
|
|
75
|
+
<link rel="modulepreload" crossorigin href="/js/workApi-C4QtuhcE.js">
|
|
76
|
+
<link rel="modulepreload" crossorigin href="/js/api-DGVZHSkS.js">
|
|
77
|
+
<link rel="modulepreload" crossorigin href="/js/chatStore-zilBUd1p.js">
|
|
78
|
+
<link rel="modulepreload" crossorigin href="/js/appStore-DXlmTjIC.js">
|
|
79
|
+
<link rel="modulepreload" crossorigin href="/js/authStore-B97lJ5Ee.js">
|
|
80
80
|
<link rel="modulepreload" crossorigin href="/js/welcomePrompts-to5mv_gx.js">
|
|
81
|
-
<link rel="modulepreload" crossorigin href="/js/messageCodeStyles-
|
|
82
|
-
<link rel="modulepreload" crossorigin href="/js/Button-
|
|
83
|
-
<link rel="modulepreload" crossorigin href="/js/ui-
|
|
84
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
81
|
+
<link rel="modulepreload" crossorigin href="/js/messageCodeStyles-BqQ6kOSU.js">
|
|
82
|
+
<link rel="modulepreload" crossorigin href="/js/Button-BPf_pOxH.js">
|
|
83
|
+
<link rel="modulepreload" crossorigin href="/js/ui-CO0DPqrI.js">
|
|
84
|
+
<link rel="stylesheet" crossorigin href="/assets/index-DkFWzmFD.css">
|
|
85
85
|
</head>
|
|
86
86
|
<body>
|
|
87
87
|
<div id="root"></div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./useTranslation-Bho4HCyg.js";import{t as i}from"./utils-D9W1Lnkn.js";import{$t as a,Bt as o,Dt as s,Jt as c,Kt as l,Wt as u,Zt as d,en as f,fn as p,lt as m,m as h}from"./ui-vendor-mqjSfAaS.js";import{t as g}from"./logger-DSXjF4ye.js";import{t as _}from"./appStore-DXlmTjIC.js";import{t as v}from"./Button-BPf_pOxH.js";import{t as y}from"./OptimizedSyntaxHighlighter-Dz7D1LPB.js";import{a as b,i as x,l as S,n as C,o as w,r as T,t as E}from"./ArtifactSandboxFrame-S9g_q47-.js";var D=e(t(),1),O=n(),k=g(`components:artifact-renderer`),A=({artifact:e,className:t})=>{let{t:n}=r(),[g,A]=(0,D.useState)(!1),[j,M]=(0,D.useState)(`preview`),{theme:N,openArtifactPanel:P}=_(),F=async e=>{try{await navigator.clipboard.writeText(e),A(!0),setTimeout(()=>A(!1),2e3)}catch(e){k.error(`Failed to copy:`,e)}},I=()=>{let t=e.type===`html`?b(e.content,e.title):e.content,n=new Blob([t],{type:L(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${R(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},L=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},R=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},z=()=>{switch(e.type){case`html`:return(0,O.jsx)(s,{className:`h-4 w-4`});case`react`:return(0,O.jsx)(a,{className:`h-4 w-4`});case`svg`:return(0,O.jsx)(o,{className:`h-4 w-4`});case`code`:return(0,O.jsx)(a,{className:`h-4 w-4`});default:return(0,O.jsx)(o,{className:`h-4 w-4`})}},B=()=>(0,O.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,O.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,O.jsx)(h,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,O.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:n(`artifacts.previewUnavailable`)}),(0,O.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,O.jsxs)(v,{variant:`outline`,size:`sm`,onClick:()=>M(`code`),className:`mt-4`,children:[(0,O.jsx)(f,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),V=async()=>{try{let t=await T(C(e.type)??`html`,e.content,e.title,{colorScheme:N.mode===`dark`?`dark`:`light`});S(t,x,e.title)}catch(e){k.error(`Failed to open the artifact preview:`,e)}},H=t=>e.content.trim()?(0,O.jsx)(E,{content:e.content,title:e.title,kind:t,colorScheme:N.mode===`dark`?`dark`:`light`,className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,fallback:B()}):B(),U=()=>(0,O.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:w(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg bg-white`,sandbox:``,title:e.title}),W=()=>(0,O.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,O.jsx)(y,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:N.mode===`dark`,className:`!m-0 !rounded-lg`,children:e.content})}),G=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,O.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,O.jsx)(y,{language:`json`,isDark:N.mode===`dark`,className:`!m-0 !rounded-lg`,children:n})})}catch{return(0,O.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,O.jsxs)(`div`,{className:`text-center`,children:[(0,O.jsx)(h,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,O.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidJson`)})]})})}},K=()=>{if(j===`code`)return W();switch(e.type){case`html`:return H(`html`);case`react`:return H(`react`);case`mermaid`:return H(`mermaid`);case`svg`:return U();case`json`:return G();default:return W()}},q=()=>e.type===`html`||e.type===`svg`||e.type===`react`||e.type===`mermaid`;return(0,O.jsxs)(`div`,{className:i(`border border-gray-200 dark:border-dark-200 rounded-xl bg-white dark:bg-dark-25 shadow-lg transition-all duration-300 hover:shadow-xl`,`w-full max-w-full overflow-hidden animate-fade-in`,`max-h-[400px] flex flex-col`,t),children:[(0,O.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,O.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:z()}),(0,O.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,O.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[q()&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(v,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,O.jsx)(u,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,O.jsx)(f,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>F(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:g?(0,O.jsx)(p,{className:`h-2.5 w-2.5 text-green-500`}):(0,O.jsx)(d,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:I,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,O.jsx)(c,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>P(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,O.jsx)(m,{className:`h-2.5 w-2.5`})})]})]}),(0,O.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,O.jsx)(`div`,{className:`flex-shrink-0`,children:z()}),(0,O.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,O.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[q()&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(v,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,O.jsx)(u,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,O.jsxs)(v,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,O.jsx)(f,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,O.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>F(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:g?(0,O.jsx)(p,{className:`h-4 w-4 text-green-500`}):(0,O.jsx)(d,{className:`h-4 w-4`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:I,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,O.jsx)(c,{className:`h-4 w-4`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>P(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,O.jsx)(m,{className:`h-4 w-4`})})]})]})]}),(0,O.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,O.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,O.jsx)(`div`,{className:`h-full overflow-auto`,children:K()})]}),(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:[(0,O.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]}),C(e.type)&&(0,O.jsxs)(v,{variant:`ghost`,size:`sm`,onClick:()=>V(),className:`text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,children:[(0,O.jsx)(l,{className:`h-3 w-3 mr-1`}),n(`artifacts.openInNewWindow`)]})]})]})},j=({artifacts:e,className:t})=>!e||e.length===0?null:(0,O.jsx)(`div`,{className:i(`space-y-3`,t),children:e.map(e=>(0,O.jsx)(A,{artifact:e},e.id))});export{j as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./Button-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./Button-BPf_pOxH.js";import{n as i}from"./ui-CO0DPqrI.js";import{t as a}from"./ArtifactContainer-B-hs0F5K.js";var o=e(t(),1),s=n(),c=[{id:`demo-html-1`,type:`html`,title:`Interactive Button Demo`,description:`A simple HTML page with interactive elements`,content:`<div style="text-align: center; padding: 20px;">
|
|
2
2
|
<h1 style="color: #333; font-family: Arial, sans-serif;">Welcome to Libre WebUI!</h1>
|
|
3
3
|
<p style="color: #666; font-size: 16px;">This is an interactive HTML artifact.</p>
|
|
4
4
|
<button
|
package/frontend/dist/js/{ArtifactSandboxFrame-DhvA-t-7.js → ArtifactSandboxFrame-S9g_q47-.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./logger-DSXjF4ye.js";import{t as i}from"./config-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./logger-DSXjF4ye.js";import{t as i}from"./config-CmEh9o8U.js";var a=e(t(),1),o=`allow-scripts allow-forms allow-modals allow-popups allow-pointer-lock allow-downloads`,s=`clipboard-read; clipboard-write; fullscreen; gamepad`,c=`libre-artifact:render`;function l(e,t){if(!t||e.source!==t.contentWindow)return!1;let n=e.origin,r=typeof window>`u`?void 0:window.location?.origin;if(typeof n==`string`&&n!==``&&n!==`null`&&n!==r)return!1;let i=e.data;return!!i&&i?.type===`libre-artifact:ready`}function u(e,t){e?.contentWindow?.postMessage({type:c,html:t},`*`)}var d=`
|
|
2
2
|
body {
|
|
3
3
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
4
4
|
margin: 0;
|
|
@@ -38,7 +38,7 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./m
|
|
|
38
38
|
</head>
|
|
39
39
|
<body>${e}</body>
|
|
40
40
|
</html>`}function g(e,t,n=`Artifact`){let r=window.open(``,`_blank`);if(!r)return null;r.opener=null;let{document:i}=r;i.title=n,i.documentElement.style.width=`100%`,i.documentElement.style.height=`100%`,i.body.style.width=`100%`,i.body.style.height=`100%`,i.body.style.margin=`0`,i.body.replaceChildren();let a=i.createElement(`iframe`);return a.title=n,a.src=t,a.setAttribute(`sandbox`,o),a.setAttribute(`allow`,s),a.style.width=`100%`,a.style.height=`100%`,a.style.border=`0`,r.addEventListener(`message`,t=>{l(t,a)&&u(a,e)}),i.body.appendChild(a),r}function _(e,t){let n=e;/<head[\s>]/i.test(n)||(n=n.replace(/<html([^>]*)>/i,`<html$1><head></head>`));let r=[];return/<meta\s+charset=/i.test(n)||r.push(`<meta charset="UTF-8">`),/<meta\s+name=["']viewport["']/i.test(n)||r.push(`<meta name="viewport" content="width=device-width, initial-scale=1.0">`),/<base\s/i.test(n)||r.push(`<base target="_blank">`),/<title[\s>]/i.test(n)||r.push(`<title>${S(t)}</title>`),r.length===0?n:v(n,`\n ${r.join(`
|
|
41
|
-
`)}`)}function v(e,t){let n=/<head(\s[^>]*)?>/i;return n.test(e)?e.replace(n,e=>`${e}${t}`):`${t}\n${e}`}function y(e,t){return/<\/head>/i.test(e)?e.replace(/<\/head>/i,`${t}</head>`):/<html[^>]*>/i.test(e)?e.replace(/<html([^>]*)>/i,`<html$1><head>${t}</head>`):`${t}${e}`}function b(e,t){return/<\/body>/i.test(e)?e.replace(/<\/body>/i,`${t}</body>`):`${e}${t}`}function x(e){return S(e)}function S(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}var C=`${i.replace(/\/+$/,``)}/artifacts/sandbox`,ee=window.location.protocol===`file:`?new URL(C).origin:window.location.origin,te=`/artifact-runtime`,w=`runtime`,T=`react`,E=`babel`,D=`tailwind`,O=`fonts`,k={react:T,"react-dom":T,"react-dom/client":T,"react/jsx-runtime":T,"react/jsx-dev-runtime":T,recharts:`recharts`,"lucide-react":`lucide-react`,d3:`d3`,three:`three`,papaparse:`papaparse`,lodash:`lodash`,"lodash-es":`lodash`,mermaid:`mermaid`,"chart.js":`chart`,"chart.js/auto":`chart`,tone:`tone`,mathjs:`mathjs`,"plotly.js":`plotly`,"plotly.js-dist-min":`plotly`,"framer-motion":`framer-motion`,"motion/react":`framer-motion`,motion:`framer-motion`,"three/addons/controls/OrbitControls.js":`three`,"three/examples/jsm/controls/OrbitControls.js":`three`},ne=[w,T,E,D],re=[w,`mermaid`],A=[{pattern:/cdn\.tailwindcss\.com/i,bundle:D},{pattern:/(?:^|\/)tailwindcss(?:@[\d.]+)?(?:\/|$)/i,bundle:D},{pattern:/(?:^|\/)chart\.js(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)chart(?:\.min)?\.js(?:$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)d3(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)d3(?:\.min)?\.js(?:$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)three(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`three`},{pattern:/(?:^|\/)three(?:\.min)?\.js(?:$|\?)/i,bundle:`three`},{pattern:/papaparse/i,bundle:`papaparse`},{pattern:/(?:^|\/)lodash(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`lodash`},{pattern:/(?:^|\/)lodash(?:\.min)?\.js(?:$|\?)/i,bundle:`lodash`},{pattern:/fonts\.(?:googleapis|gstatic)\.com/i,bundle:O},{pattern:/mermaid/i,bundle:`mermaid`},{pattern:/(?:^|\/)tone(?:@[\d.]+)?(?:\/|$|\?)|tone(?:\.min)?\.js/i,bundle:`tone`},{pattern:/mathjs|math(?:\.min)?\.js/i,bundle:`mathjs`},{pattern:/plotly/i,bundle:`plotly`},{pattern:/framer-motion|(?:^|\/)motion(?:@[\d.]+)?(?:\/|$)/i,bundle:`framer-motion`},{pattern:/react-dom/i,bundle:T},{pattern:/(?:^|\/)react(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:T},{pattern:/babel(?:-standalone|\/standalone)/i,bundle:E}],j=`__libreArtifactRuntime`;function ie(e){if(k[e])return e;let t=A.find(({pattern:t})=>t.test(e))?.bundle??Object.values(k).find(t=>e.startsWith(`${t}/`));return t?Object.entries(k).find(([,e])=>e===t)?.[0]??null:null}function ae(e){let t=new Set,n=e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g);for(let[,e]of n){let n=ie(e);n&&t.add(k[n])}return[...t]}var M=/\b(?:flex|grid|hidden|absolute|relative|(?:p|m|px|py|mx|my|mt|mb|ml|mr|gap|space)-\d|(?:w|h|max-w|min-h)-(?:\d|full|screen|auto)|text-(?:xs|sm|base|lg|xl|\dxl|center|left|right|white|black|gray-\d)|bg-(?:white|black|transparent|[a-z]+-\d)|rounded(?:-[a-z]+)?|shadow(?:-[a-z]+)?|border(?:-\d)?|items-(?:center|start|end)|justify-(?:center|between|around|end)|font-(?:bold|medium|semibold|light)|hover:[a-z-]+|(?:sm|md|lg|xl):[a-z-]+)\b/g;function N(e){let t=[...e.matchAll(/class\s*=\s*("|')(.*?)\1/gi)].map(e=>e[2]).join(` `);return new Set(t.match(M)??[]).size>=3}function P(e){let t=new Set;for(let[n,r]of Object.entries(k)){let i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:from|import|require)\\s*\\(?\\s*['"\`]${i}['"\`]`).test(e)&&t.add(r)}return[...t]}function F(e){return A.find(({pattern:t})=>t.test(e))?.bundle??null}function I(e){let t=new Set;for(let n of e.matchAll(/\b(?:src|href)\s*=\s*("|')(.*?)\1/gi))t.add(n[2]);for(let n of e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g))t.add(n[1]);return[...t]}function L(e){let t=new Set;for(let n of I(e)){let e=F(n);e&&t.add(e)}return[...t]}var R=`
|
|
41
|
+
`)}`)}function v(e,t){let n=/<head(\s[^>]*)?>/i;return n.test(e)?e.replace(n,e=>`${e}${t}`):`${t}\n${e}`}function y(e,t){return/<\/head>/i.test(e)?e.replace(/<\/head>/i,`${t}</head>`):/<html[^>]*>/i.test(e)?e.replace(/<html([^>]*)>/i,`<html$1><head>${t}</head>`):`${t}${e}`}function b(e,t){return/<\/body>/i.test(e)?e.replace(/<\/body>/i,`${t}</body>`):`${e}${t}`}function x(e){return S(e)}function S(e){return e.replace(/&/g,`&`).replace(/</g,`<`).replace(/>/g,`>`).replace(/"/g,`"`).replace(/'/g,`'`)}var C=`${i.replace(/\/+$/,``)}/artifacts/sandbox`,ee=window.location.protocol===`file:`?new URL(C).origin:window.location.origin,te=`/artifact-runtime`,w=`runtime`,T=`react`,E=`babel`,D=`tailwind`,O=`fonts`,k={react:T,"react-dom":T,"react-dom/client":T,"react/jsx-runtime":T,"react/jsx-dev-runtime":T,recharts:`recharts`,"lucide-react":`lucide-react`,d3:`d3`,three:`three`,papaparse:`papaparse`,lodash:`lodash`,"lodash-es":`lodash`,mermaid:`mermaid`,"chart.js":`chart`,"chart.js/auto":`chart`,tone:`tone`,mathjs:`mathjs`,"plotly.js":`plotly`,"plotly.js-dist-min":`plotly`,"framer-motion":`framer-motion`,"motion/react":`framer-motion`,motion:`framer-motion`,"three/addons/controls/OrbitControls.js":`three`,"three/examples/jsm/controls/OrbitControls.js":`three`},ne=[w,T,E,D],re=[w,`mermaid`],A=[{pattern:/cdn\.tailwindcss\.com/i,bundle:D},{pattern:/(?:^|\/)tailwindcss(?:@[\d.]+)?(?:\/|$)/i,bundle:D},{pattern:/(?:^|\/)chart\.js(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)chart(?:\.min)?\.js(?:$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)d3(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)d3(?:\.min)?\.js(?:$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)three(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`three`},{pattern:/(?:^|\/)three(?:\.min)?\.js(?:$|\?)/i,bundle:`three`},{pattern:/papaparse/i,bundle:`papaparse`},{pattern:/(?:^|\/)lodash(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`lodash`},{pattern:/(?:^|\/)lodash(?:\.min)?\.js(?:$|\?)/i,bundle:`lodash`},{pattern:/fonts\.(?:googleapis|gstatic)\.com/i,bundle:O},{pattern:/mermaid/i,bundle:`mermaid`},{pattern:/(?:^|\/)tone(?:@[\d.]+)?(?:\/|$|\?)|tone(?:\.min)?\.js/i,bundle:`tone`},{pattern:/mathjs|math(?:\.min)?\.js/i,bundle:`mathjs`},{pattern:/plotly/i,bundle:`plotly`},{pattern:/framer-motion|(?:^|\/)motion(?:@[\d.]+)?(?:\/|$)/i,bundle:`framer-motion`},{pattern:/react-dom/i,bundle:T},{pattern:/(?:^|\/)react(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:T},{pattern:/babel(?:-standalone|\/standalone)/i,bundle:E}],j=`__libreArtifactRuntime`;function ie(e){if(k[e])return e;let t=A.find(({pattern:t})=>t.test(e))?.bundle??Object.values(k).find(t=>e.startsWith(`${t}/`));return t?Object.entries(k).find(([,e])=>e===t)?.[0]??null:null}function ae(e){let t=new Set,n=e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g);for(let[,e]of n){let n=ie(e);n&&t.add(k[n])}return[...t]}var M=/\b(?:flex|grid|hidden|absolute|relative|(?:p|m|px|py|mx|my|mt|mb|ml|mr|gap|space)-\d|(?:w|h|max-w|min-h)-(?:\d|full|screen|auto)|text-(?:xs|sm|base|lg|xl|\dxl|center|left|right|white|black|gray-\d)|bg-(?:white|black|transparent|[a-z]+-\d)|rounded(?:-[a-z]+)?|shadow(?:-[a-z]+)?|border(?:-\d)?|items-(?:center|start|end)|justify-(?:center|between|around|end)|font-(?:bold|medium|semibold|light)|hover:[a-z-]+|(?:sm|md|lg|xl):[a-z-]+)\b/g;function N(e){let t=[...e.matchAll(/class\s*=\s*("|')(.*?)\1/gi)].map(e=>e[2]).join(` `);return new Set(t.match(M)??[]).size>=3}function P(e){let t=new Set;for(let[n,r]of Object.entries(k)){let i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:from|import|require)\\s*\\(?\\s*['"\`]${i}['"\`]`).test(e)&&t.add(r)}return[...t]}function F(e){return A.find(({pattern:t})=>t.test(e))?.bundle??null}function I(e){let t=new Set;for(let n of e.matchAll(/\b(?:src|href)\s*=\s*("|')(.*?)\1/gi))t.add(n[2]);for(let n of e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g))t.add(n[1]);return[...t]}function L(e){let t=new Set;for(let n of I(e)){let e=F(n);e&&t.add(e)}return[...t]}var R=`3eb7ae6f90cd77fe`,z=new Map;function B(e){let t=z.get(e);if(t)return t;let n=fetch(`${ee}${te}/${e}.js?v=${R}`,{credentials:`same-origin`,cache:`no-cache`}).then(t=>{if(!t.ok)throw Error(`The artifact runtime bundle "${e}" is unavailable (HTTP ${t.status}).`);return t.text()});return n.catch(()=>z.delete(e)),z.set(e,n),n}async function V(e){let t=await Promise.all(e.map(B));return Object.fromEntries(e.map((e,n)=>[e,t[n]]))}function H(e){return e===`html`||e===`react`||e===`mermaid`?e:null}var U=`
|
|
42
42
|
html, body { margin: 0; min-height: 100%; }
|
|
43
43
|
body {
|
|
44
44
|
background: #ffffff;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{t as i}from"./useTranslation-Bho4HCyg.js";import{t as a}from"./utils-D9W1Lnkn.js";import{C as ee,t as o}from"./chatStore-zilBUd1p.js";import{$t as s,Bt as c,Dt as te,Et as ne,Jt as re,Kt as ie,Wt as ae,Zt as oe,en as l,fn as u,ln as d,m as f,n as p,un as se}from"./ui-vendor-mqjSfAaS.js";import{t as m}from"./logger-DSXjF4ye.js";import{t as ce}from"./appStore-DXlmTjIC.js";import{t as h}from"./Button-BPf_pOxH.js";import{t as g}from"./OptimizedSyntaxHighlighter-Dz7D1LPB.js";import{a as le,i as ue,l as de,n as _,o as fe,r as pe,t as me}from"./ArtifactSandboxFrame-S9g_q47-.js";var v=e(t(),1),y=r(),b=n(),x=m(`components:artifact-slide-out-panel`),S=320,C=.9,w=600,T=()=>{let{t:e,i18n:t}=i(),n=ee(t.language),{artifactPanelOpen:r,artifactPanelArtifact:m,openArtifactPanel:T,closeArtifactPanel:E,theme:D}=ce(),O=o(e=>e.currentSession),k=v.useMemo(()=>{if(!m)return[];let e=m.title.trim().toLowerCase(),t=(O?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===m.id)?t:[...t,m]},[O,m]),A=k.findIndex(e=>e.id===m?.id),[he,j]=(0,v.useState)(!1),[M,N]=(0,v.useState)(`preview`),[P,F]=(0,v.useState)(w),[I,L]=(0,v.useState)(!1),R=(0,v.useRef)(null),z=(0,v.useRef)(null),B=(0,v.useRef)(0),V=(0,v.useRef)(0),H=(0,v.useRef)(null),U=(0,v.useRef)(null),W=(0,v.useRef)(P),G=m?.id??null;G!==z.current&&(z.current=G,M!==`preview`&&N(`preview`));let K=(0,v.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,F(W.current)}))},[]),q=(0,v.useCallback)(()=>{H.current=null,L(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,F(W.current))},[]),ge=(0,v.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=P,B.current=e.clientX,W.current=P,e.currentTarget.setPointerCapture(e.pointerId),L(!0)},[P]),J=(0,v.useCallback)(e=>{if(!I||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=window.innerWidth*C,i=Math.min(r,Math.max(S,V.current+t));K(i)},[I,n,K]);if((0,v.useEffect)(()=>{if(!I){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[I,J,q]),(0,v.useEffect)(()=>{let e=()=>{let e=window.innerWidth*C;P>e&&F(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[P]),(0,v.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r&&E()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,E]),(0,v.useEffect)(()=>{let e=e=>{I||R.current&&!R.current.contains(e.target)&&r&&E()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,E,I]),!m)return null;let Y=m,_e=async e=>{try{await navigator.clipboard.writeText(e),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){x.error(`Failed to copy:`,e)}},ve=()=>{let e=Y.type===`html`?le(Y.content,Y.title):Y.content,t=new Blob([e],{type:ye(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${be(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ye=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},be=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},xe=()=>{switch(Y.type){case`html`:return(0,b.jsx)(te,{className:`h-5 w-5`});case`react`:return(0,b.jsx)(s,{className:`h-5 w-5`});case`svg`:return(0,b.jsx)(c,{className:`h-5 w-5`});case`code`:return(0,b.jsx)(s,{className:`h-5 w-5`});default:return(0,b.jsx)(c,{className:`h-5 w-5`})}},X=()=>(0,b.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,b.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,b.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,b.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,b.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>N(`code`),className:`mt-4`,children:[(0,b.jsx)(l,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Se=async()=>{try{let e=await pe(_(Y.type)??`html`,Y.content,Y.title,{colorScheme:D.mode===`dark`?`dark`:`light`});de(e,ue,Y.title)}catch(e){x.error(`Failed to open the artifact preview:`,e)}},Z=e=>Y.content.trim()?(0,b.jsx)(me,{content:Y.content,title:Y.title,kind:e,colorScheme:D.mode===`dark`?`dark`:`light`,className:a(`w-full h-full border-0 rounded-lg bg-white`,I&&`pointer-events-none`),fallback:X()}):X(),Ce=()=>(0,b.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:fe(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,b.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,b.jsx)(g,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:Y.content})}),we=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,b.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,b.jsx)(g,{language:`json`,isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,b.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,b.jsxs)(`div`,{className:`text-center`,children:[(0,b.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,b.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},Te=()=>{if(M===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return Ce();case`json`:return we();default:return Q()}},Ee=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,De=$?`100%`:`${P}px`,Oe=(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:a(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),I&&(0,b.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,b.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:De},className:a(`fixed top-0 end-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,b.jsxs)(`div`,{onPointerDown:ge,"data-testid":`artifact-resize-handle`,className:a(`absolute start-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,b.jsx)(`div`,{className:a(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,I&&`bg-primary-500 h-24`)}),(0,b.jsx)(`div`,{className:a(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,I&&`opacity-100`),children:(0,b.jsx)(ne,{className:`h-4 w-4`})})]}),(0,b.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,b.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:xe()}),(0,b.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:Y.title}),(0,b.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:Y.type.toUpperCase()})]}),(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:E,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,b.jsx)(p,{className:`h-5 w-5`})})]}),(0,b.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,children:[k.length>1&&A!==-1&&(0,b.jsxs)(`div`,{className:`me-1 flex items-center gap-0.5`,children:[(0,b.jsx)(h,{variant:`ghost`,size:`sm`,disabled:A===0,onClick:()=>T(k[A-1]),className:`h-8 w-8 p-0`,title:e(`artifacts.previousVersion`),children:(0,b.jsx)(se,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,b.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:A+1,total:k.length})}),(0,b.jsx)(h,{variant:`ghost`,size:`sm`,disabled:A===k.length-1,onClick:()=>T(k[A+1]),className:`h-8 w-8 p-0`,title:e(`artifacts.nextVersion`),children:(0,b.jsx)(d,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Ee()&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(h,{variant:M===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,b.jsx)(ae,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.preview`)]}),(0,b.jsxs)(h,{variant:M===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,b.jsx)(l,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>_e(Y.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:he?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(u,{className:`h-3.5 w-3.5 me-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(oe,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.copyButton`)]})}),(0,b.jsxs)(h,{variant:`ghost`,size:`sm`,onClick:ve,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,b.jsx)(re,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.download`)]}),_(Y.type)&&(0,b.jsxs)(h,{variant:`ghost`,size:`sm`,onClick:()=>Se(),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.openInNewWindow`),children:[(0,b.jsx)(ie,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.open`)]})]})]}),Y.description&&(0,b.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,b.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:Y.description})}),(0,b.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:Te()}),(0,b.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:(0,b.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,b.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(Y.createdAt).toLocaleString()]}),!$&&(0,b.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]});return(0,y.createPortal)(Oe,document.body)};export{T as ArtifactSlideOutPanel};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./rolldown-runtime-hePW80VL.js";import{m as e,p as t}from"./markdown-core-BmPPZiuD.js";import{t as n}from"./utils-
|
|
1
|
+
import"./rolldown-runtime-hePW80VL.js";import{m as e,p as t}from"./markdown-core-BmPPZiuD.js";import{t as n}from"./utils-D9W1Lnkn.js";e();var r=t(),i=({variant:e=`primary`,size:t=`md`,loading:i=!1,disabled:a,children:o,className:s,...c})=>(0,r.jsxs)(`button`,{className:n(`group relative inline-flex select-none items-center justify-center rounded-xl border font-medium tracking-[-0.01em] transition-[background-color,border-color,color,box-shadow,opacity] duration-150 ease-out focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary-500 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas dark:focus-visible:ring-primary-400 disabled:cursor-not-allowed disabled:opacity-40 motion-reduce:transition-none`,{primary:`border-transparent bg-ink text-ink-inverse shadow-subtle hover:opacity-90`,secondary:`border-line bg-surface-raised text-ink shadow-subtle hover:border-line-strong hover:bg-surface-subtle`,outline:`border-line bg-transparent text-ink hover:border-line-strong hover:bg-surface-subtle`,ghost:`border-transparent bg-transparent text-ink-muted shadow-none hover:bg-surface-subtle hover:text-ink`,danger:`border-transparent bg-error-600 text-white shadow-subtle hover:bg-error-700 dark:bg-error-500 dark:text-ink-inverse dark:hover:bg-error-400`}[e],{sm:`h-8 px-3 text-sm gap-1.5`,md:`h-10 px-4 text-sm gap-2`,lg:`h-11 px-5 text-base gap-2.5`}[t],s),disabled:a||i,"aria-busy":i||void 0,...c,children:[i&&(0,r.jsxs)(`svg`,{className:`mr-2 h-4 w-4 animate-spin`,"aria-hidden":`true`,fill:`none`,viewBox:`0 0 24 24`,children:[(0,r.jsx)(`circle`,{className:`opacity-25`,cx:`12`,cy:`12`,r:`10`,stroke:`currentColor`,strokeWidth:`4`}),(0,r.jsx)(`path`,{className:`opacity-75`,fill:`currentColor`,d:`M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z`})]}),o]});export{i as t};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{d as i,f as a,u as o}from"./router-vendor-CbPDks39.js";import{t as s}from"./useTranslation-Bho4HCyg.js";import{i as c,n as l,o as u,r as d,t as f}from"./utils-D9W1Lnkn.js";import{C as p,a as m,c as h,d as g,h as _,i as v,l as y,m as b,n as x,o as S,r as C,t as w,u as T}from"./chatStore-zilBUd1p.js";import{$t as E,At as D,B as O,Bt as k,C as A,Cn as j,D as M,Dt as N,En as ee,F as P,H as F,L as I,M as te,Mn as L,P as R,Sn as z,Y as ne,Yt as B,Zt as re,_ as ie,_n as ae,a as oe,at as se,b as V,bt as ce,c as le,cn as ue,dn as de,en as fe,f as H,fn as pe,jn as U,jt as me,k as he,ln as ge,n as W,o as _e,ot as ve,p as ye,pt as be,q as xe,r as Se,st as Ce,t as we,v as Te,vn as Ee,yt as De,z as Oe,zt as ke}from"./ui-vendor-mqjSfAaS.js";import{i as Ae,t as G}from"./logger-DSXjF4ye.js";import{t as je}from"./config-CmEh9o8U.js";import{S as Me,a as Ne,b as Pe,d as Fe,f as Ie,h as Le,n as Re,o as K,p as ze,r as Be,v as Ve,w as He}from"./api-DGVZHSkS.js";import{n as Ue,r as q}from"./authStore-B97lJ5Ee.js";import{t as We}from"./appStore-DXlmTjIC.js";import{i as Ge,r as Ke,t as qe}from"./welcomePrompts-to5mv_gx.js";import{l as Je}from"./messageCodeStyles-BqQ6kOSU.js";import{t as J}from"./Button-BPf_pOxH.js";import{d as Ye,f as Xe,l as Y}from"./ui-CO0DPqrI.js";import{a as Ze,c as Qe,h as $e,l as et,o as tt,s as nt,u as rt}from"../assets/index-CDQ12KBq.js";import{c as it,s as at}from"./ArtifactSandboxFrame-S9g_q47-.js";import{i as ot,n as st,r as ct,t as lt}from"./thinking-DwlkTfPX.js";import{t as ut}from"./ArtifactContainer-B-hs0F5K.js";import{t as dt}from"./ModelSelector-A-viVFEc.js";var ft=r(),X=e(t(),1),Z=n(),pt=({statistics:e,className:t=``})=>{let[n,r]=(0,X.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,Z.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,Z.jsx)(De,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,Z.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,Z.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,Z.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,Z.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,Z.jsx)(de,{size:12}):(0,Z.jsx)(ge,{size:12,className:`rtl:rotate-180`}),(0,Z.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,Z.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,Z.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},mt=G(`components:ttsbutton`),ht=null,gt=null,_t=0,vt=3e5;async function yt(e=!1){let t=Date.now();return!e&&ht!==null&&t-_t<vt?ht:gt||(gt=(async()=>{try{let e=await K.getModels();return e.success&&e.data&&e.data.length>0?(ht=e.data,_t=t,e.data):(ht=[],_t=t,[])}catch{return ht=[],_t=t,[]}finally{gt=null}})(),gt)}var bt=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:c}=s(),{preferences:l}=We(),[u,d]=(0,X.useState)(`idle`),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)([]),[_,v]=(0,X.useState)(null),y=(0,X.useRef)(null),b=(0,X.useRef)(0);(0,X.useEffect)(()=>{let e=!0;return(async()=>{let t=await yt(),n=Be(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await yt(!0)),e&&(g(t),v(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let x=()=>{b.current+=1,y.current?.cancel(),y.current=null,d(`idle`)},S=async()=>{if(r===`blocked`||r===`error`){a?.();return}if(r===`loading`||r===`generating`||r===`buffering`||r===`playing`){i?.();return}if(u===`loading`||u===`generating`||u===`buffering`||u===`playing`){x();return}if(y.current){x();return}let t=rt();d(`loading`),m(null);let n=b.current+1;b.current=n;try{let r=await t;if(b.current!==n)return;if(r===`blocked`){d(`blocked`);return}let i=l.ttsSettings,a=Ne(h,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,u=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),p=f&&i?.voice||a?.config?.default_voice,m=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,v=Math.max(1,a?.config?.max_characters||600),x=Math.min(v,600),S=i?.streamSentences!==!1||e.length>x?tt(e,{locale:c.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=nt({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>K.generate({model:s,pluginId:u,input:e,voice:m?void 0:p||void 0,voiceProfileId:m,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});y.current=C;let w=Ze(C);try{await C.play(S)}finally{w(),y.current===C&&(y.current=null)}}catch(e){if(b.current!==n)return;if(Qe(e)){d(`idle`);return}if(et(e)){d(`blocked`);return}let t=e instanceof Error?e.message:o(`ttsButton.generateFailed`);m(t),mt.error(`TTS error:`,e),d(`error`)}};if((0,X.useEffect)(()=>()=>{b.current+=1,y.current?.cancel(),y.current=null},[]),_===!1||_===null)return null;let C={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},w={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`},T=r&&![`idle`,`ended`,`cancelled`].includes(r)?r:u,E=T===`loading`||T===`generating`||T===`buffering`,D=T===`playing`,O=T===`blocked`,k=!!p||T===`error`,j=p||o(k?`ttsButton.playbackFailed`:O?`ttsButton.enableAudio`:D||E?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,Z.jsxs)(`button`,{onClick:S,disabled:!e,title:j,"aria-label":j,"aria-busy":E||void 0,className:f(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,k?`text-red-500 dark:text-red-400`:O?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:D?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!O&&C[n],O&&n===`sm`&&`h-7`,O&&n===`md`&&`h-8`,O&&n===`lg`&&`h-10`,t),children:[E?(0,Z.jsx)(be,{className:f(w[n],`animate-spin`)}):D?(0,Z.jsx)(A,{className:w[n]}):k||O?(0,Z.jsx)(oe,{className:w[n]}):(0,Z.jsx)(_e,{className:w[n]}),O&&(0,Z.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},Q=new Map;function xt(e,t,n=``){let r=Q.get(e);if(n){if((!r||r.state===`none`)&&(Q.set(e,{state:`open`,startedAt:Date.now()}),!t))return;let n=Q.get(e);t&&n?.state===`open`&&Q.set(e,{state:`done`,durationMs:Date.now()-n.startedAt});return}if(r&&r.state!==`open`||!t)return;let i=u(t);if(!r){i.thinkingComplete?Q.set(e,{state:`none`}):Q.set(e,{state:`open`,startedAt:Date.now()});return}i.thinkingComplete&&Q.set(e,{state:`done`,durationMs:Date.now()-r.startedAt})}function St(e){let t=Q.get(e);if(t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function Ct(e){let t=Q.get(e);if(Q.delete(e),t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function wt(e){let t=e/1e3;if(t<.95)return`${Math.max(.1,Math.round(t*10)/10)}s`;if(t<60)return`${Math.round(t)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return r>0?`${n}m ${r}s`:`${n}m`}var Tt=/```([^\n`]*)\n([\s\S]*?)\n```/g,Et=/^(?:%%|flowchart|graph|sequenceDiagram|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|mindmap|timeline|gitGraph|quadrantChart|requirementDiagram|sankey-beta|xychart-beta|block-beta|architecture-beta|packet-beta|kanban|radar-beta|treemap-beta|C4Context)\b/i,Dt=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,Ot=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],kt=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:Rt(e[1]),title:At(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=Rt(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function At(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return Mt(jt(e))}function jt(e){return e.replace(/&(lt|gt|quot|apos|#39);/gi,(e,t)=>{switch(t.toLowerCase()){case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:case`#39`:return`'`;default:return``}}).replace(/&/gi,`&`)}function Mt(e){let t=``,n=!1,r=null;for(let i=0;i<e.length;i+=1){let a=e[i];if(n){if(r){a===r&&(r=null);continue}if(a===`"`||a===`'`){r=a;continue}a===`>`&&(n=!1);continue}if(a===`<`){let t=e[i+1];if(t&&/[!/A-Za-z?]/.test(t)){n=!0;continue}}t+=a}return t}function Nt(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return At(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&At(n[1]).trim()||null}function Pt(e){for(let t of[/export\s+default\s+(?:function|class)\s+([A-Z]\w*)/,/export\s+default\s+([A-Z]\w*)\s*(?:;|$)/m,/(?:function|class)\s+([A-Z]\w*)/,/const\s+([A-Z]\w*)\s*[:=]/,/(?:function|const|class)\s+(\w+)/]){let n=e.match(t);if(n)return n[1]}return null}function Ft(e){let t=e.match(/^\s*title\s+(.+)$/im);if(t)return t[1].trim();let n=e.trim().match(/^([A-Za-z][\w-]*)/);if(!n)return null;let r=n[1].replace(/-(?:beta|v2)$/i,``).replace(/([a-z])([A-Z])/g,`$1 $2`);return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function It(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function Lt(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function Rt(e){let t=e.trim().toLowerCase();return Ot.includes(t)?t:`text`}function zt(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function Bt(e){let t=[],n=new RegExp(Tt),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=Vt(n,Ut(e,r.index));t.push({raw:r[0],info:n,content:r[2].trim(),start:r.index,end:r.index+r[0].length,language:i.language,fileName:i.fileName})}return t}function Vt(e,t){let n=Ht(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!Dt.test(r)&&!r.includes(`=`)?zt(r):void 0)||zt(Gt(n)),fileName:n}}function Ht(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&Dt.test(t[1]))return Wt(t[1]);let n=e.match(Dt);return n?Wt(n[0]):void 0}function Ut(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
|
|
2
|
+
`).slice(-3).reverse();for(let e of n){let t=e.trim().replace(/^#{1,6}\s*/,``).replace(/^[-*]\s*/,``).replace(/[::]\s*$/,``).match(Dt);if(t)return Wt(t[0])}}function Wt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function Gt(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function Kt(e){return e?.split(/[\\/]/).pop()}function qt(e){let t=Kt(e);if(!t)return null;let n=t.replace(/\.[^.]+$/,``);return/^(index|main|app)$/i.test(n)?null:n.replace(/[-_]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function Jt(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function Yt(e){let t=zt(e.language)||zt(Gt(e.fileName));switch(t){case`html`:return{type:`html`,title:Nt(e.content)||qt(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:qt(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:Pt(e.content)||qt(e.fileName)||`React Component`,language:`jsx`};case`mermaid`:return{type:`mermaid`,title:Ft(e.content)||`Diagram`,language:`mermaid`};case`json`:return{type:`json`,title:qt(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:It(e.content)||qt(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:qt(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:Lt(e.content)||qt(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:qt(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:qt(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function Xt(e){return(zt(e.language)||zt(Gt(e.fileName)))===`html`}function Zt(e){return(zt(e.language)||zt(Gt(e.fileName)))===`css`}function Qt(e){return(zt(e.language)||zt(Gt(e.fileName)))===`javascript`}function $t(e){let t=Bt(e),n=t.filter(Xt);if(n.length===0)return null;let r=t.filter(Zt),i=t.filter(Qt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=en(a.content,r,i),s=it(o,r.map(e=>e.content),i.map(e=>e.content));return on(s,`html`)?{artifact:Jt({type:`html`,title:Nt(s)||qt(a.fileName)||`Interactive HTML App`,description:`Bundled generated HTML, CSS, and JavaScript files into one runnable artifact.`,content:s}),ranges:[a,...r,...i]}:null}function en(e,t,n){let r=e;for(let e of t){let t=Kt(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${an(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=Kt(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${an(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function tn(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=Bt(e);if(nn(t.index,n))return null;let r=t.index,i=/<\/html>/gi;i.lastIndex=r;let a=i.exec(e),o=a?a.index+a[0].length:e.length,s=e.slice(r,o).trim();return on(s,`html`)?{artifact:Jt({type:`html`,title:Nt(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function nn(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function rn(e,t){return[...t].sort((e,t)=>t.start-e.start).reduce((e,t)=>`${e.slice(0,t.start)}${e.slice(t.end)}`,e)}function an(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function on(e,t){if(t===`html`){let t=e.trim(),n=/<[^>]+>/.test(t),r=/<(canvas|script|style|button|form|input|select|textarea|video|audio)\b/i.test(t)||/\bon(?:click|input|submit|keydown|keyup|mousemove)=/i.test(t);return n&&(at(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Za-z][^>]*>/.test(e)&&/\b(?:export\s+default|return\s*[(<]|=>\s*[(<]|createRoot|render\s*\()/.test(e);if(t===`mermaid`)return Et.test(e.trim());if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
|
|
3
|
+
`).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return e.trim().length>200}function sn(e){let t=[],n=e;for(let e of kt){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);on(n.content,n.type)&&(t.push(Jt({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=rn(n,r)}let r=$t(n);for(;r;)t.push(r.artifact),n=rn(n,r.ranges),r=$t(n);let i=tn(n);i&&(t.push(i.artifact),n=rn(n,i.ranges));let a=Bt(n),o=[];for(let e of a){let n=Yt(e);!n||!on(e.content,n.type)||(t.push(Jt({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=rn(n,o),{content:n.trim(),artifacts:t}}var cn=G(`components:chat-message`);function ln({role:e,user:t,personaAvatar:n,modelAvatar:r}){let[i,a]=(0,X.useState)(null);if(e===`assistant`){let e=(n?.trim()||r?.trim())??``,t=e.startsWith(`data:`)&&e!==i?e:``;return(0,Z.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-sm dark:border-white/[0.09] dark:bg-dark-200 dark:text-dark-950`,children:t?(0,Z.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>a(e)}):e?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,Z.jsx)($e,{label:null,className:`h-4 w-4`})})}let o=t?.username||`User`,s=t?.avatar?.trim()||``,c=!!s&&s!==i;return(0,Z.jsx)(`div`,{role:c?void 0:`img`,"aria-label":c?void 0:o,"data-testid":`chat-user-avatar`,className:f(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,c?`border border-black/[0.07] bg-white dark:border-white/[0.09] dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:o,children:c?(0,Z.jsx)(`img`,{src:s,alt:o,className:`h-full w-full object-cover`,onError:()=>a(s)}):t?.username?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,Z.jsx)(le,{"aria-hidden":`true`,className:`h-4 w-4`})})}var un=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onEditResend:a})=>{let{t:o,i18n:c}=s(),l=e.role===`user`,p=e.role===`system`,h=p&&m(e.content),g=h?e.content.slice(x.length):e.content,{preferences:_}=We(),{user:v}=Ue(),{setSystemMessage:y,getCurrentPersona:b,currentSession:S,rateMessage:C,modelMetadata:T}=w(),E=b(),D=e.model||S?.model||``,k=D?T[D]??Object.entries(T).find(([e])=>e.slice(e.indexOf(`/`)+1)===D)?.[1]:void 0,[A,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(e.content),[ee,P]=(0,X.useState)(null),[F,R]=(0,X.useState)(!1),[z,ne]=(0,X.useState)(!1),[B,oe]=(0,X.useState)(!1),[se,V]=(0,X.useState)(`idle`),[ce,le]=(0,X.useState)(!1),fe=(0,X.useRef)(null),H=(0,X.useRef)(0),U=(0,X.useRef)(t),me=(0,X.useRef)(!1),he=async()=>{try{await navigator.clipboard.writeText(e.content),Je(`success`),le(!0),setTimeout(()=>le(!1),2e3)}catch(e){cn.error(`Failed to copy message:`,e)}},{thinkingContent:ge,thinkingStreaming:_e,parsedContent:ve,artifacts:be}=(0,X.useMemo)(()=>{if(l||p||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:u(e.content),r=n.content,i=t&&!n.thinkingComplete;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:e.artifacts};if(!t){let e=sn(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,l,p,t]),Se=_e?void 0:e.statistics?.thinking_duration_ms??St(e.id),Ce=(0,X.useCallback)(async e=>{let t=H.current+1;H.current=t,fe.current?.cancel(),fe.current=null,V(`loading`);try{if(e){let n=await e;if(H.current!==t)return;if(n===`blocked`){V(`blocked`);return}}let n=await K.getModels();if(H.current!==t)return;let r=n.success&&n.data?n.data:[],i=_.ttsSettings,a=Ne(r,i?.model,i?.pluginId),o=Be(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,l=a?.plugin||i?.pluginId,u=o&&i?.voice||a?.config?.default_voice,d=o&&i?.voiceProfileId||void 0,f=Math.max(1,a?.config?.max_characters||600),p=Math.min(f,600),m=i?.streamSentences!==!1||ve.length>p?tt(ve,{locale:c.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[ve.trim()];if(m.length===0){V(`idle`);return}let h=nt({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>K.generate({model:s,pluginId:l,input:e,voice:d?void 0:u||void 0,voiceProfileId:d,speed:i?.speed||1,response_format:a?.config?.default_format},{signal:t}),onStateChange:e=>{H.current===t&&V(e)}});if(H.current!==t){h.cancel();return}fe.current=h;let g=Ze(h);try{await h.play(m)}finally{g(),fe.current===h&&(fe.current=null),H.current===t&&(h.state===`ended`||h.state===`cancelled`)&&V(`idle`)}}catch(e){if(H.current!==t)return;Qe(e)?V(`idle`):et(e)?V(`blocked`):(cn.error(`Auto-play TTS failed:`,e),V(`error`))}},[c.language,ve,_.ttsSettings]);(0,X.useEffect)(()=>{let e=U.current&&!t;U.current=t,e&&!me.current&&!l&&!p&&ve&&_.ttsSettings?.enabled&&_.ttsSettings.autoPlay&&(me.current=!0,Ce())},[t,l,p,ve,_.ttsSettings?.autoPlay,_.ttsSettings?.enabled,Ce]),(0,X.useEffect)(()=>()=>{H.current+=1,fe.current?.cancel(),fe.current=null},[]);let we=()=>{let e=rt();Ce(e)},Ee=()=>{H.current+=1,fe.current?.cancel(),fe.current=null,V(`idle`)},De=()=>h?o(`chatMessage.conversationSummary`):p?o(`chatMessage.system`):l?_.showUsername&&v?.username?v.username:o(`chatMessage.you`):E?.name?E.name:k?.label||D||o(`chatMessage.assistant`),ke=()=>{j(!0),N(e.content)},[Ae,G]=(0,X.useState)(!1),je=async()=>{if(!(!S||Ae)){G(!0);try{let t=await He.restoreCompaction(S.id,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;w.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){cn.error(`Failed to restore compacted messages:`,e),L.error(o(`chatMessage.restoreFailed`))}finally{G(!1)}}},Me=async()=>{R(!0);try{y(M),j(!1),cn.debug(`✅ System message updated:`,M)}catch(e){cn.error(`Failed to save system message:`,e)}finally{R(!1)}},Pe=()=>{j(!1),N(e.content)},Fe=()=>{let t=M.trim();j(!1),!(!t||t===e.content)&&a?.(e.id,t)},Ie=t=>{S&&C(S.id,e.id,e.rating===t?void 0:t)},Le=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,Re=p&&g.length>100;return(0,Z.jsxs)(`div`,{className:f(`group flex py-1.5 transition-colors sm:py-2`,l?`justify-end`:`justify-start`,n),children:[(0,Z.jsxs)(`div`,{className:f(`flex min-w-0 gap-2.5 sm:gap-3`,l?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!l&&!p&&(0,Z.jsx)(ln,{role:`assistant`,personaAvatar:E?.avatar,modelAvatar:k?.avatar}),(0,Z.jsxs)(`div`,{className:f(`min-w-0 flex-1`,l?`flex flex-col items-end`:p?`py-1.5`:`py-0.5`),children:[!l&&!p&&(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:De()}),e.model&&E?.name&&(0,Z.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,Z.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:d(e.timestamp,c.language)})]}),(0,Z.jsxs)(`div`,{className:f(!l&&!p&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,Z.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,Z.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/[0.06] bg-gray-100 dark:border-white/[0.08] dark:bg-gray-800`,children:(0,Z.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>P(e)})},t))}),l?A?(0,Z.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/[0.08] bg-white p-2 shadow-sm dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,Z.jsx)(`textarea`,{dir:`auto`,value:M,onChange:e=>N(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),Fe()):e.key===`Escape`&&Pe()},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-none dark:text-dark-900`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,Z.jsx)(`button`,{onClick:Pe,className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 transition-colors hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:o(`chatMessage.cancelEditing`)}),(0,Z.jsx)(`button`,{onClick:Fe,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white transition-colors hover:bg-gray-700 dark:bg-dark-300 dark:hover:bg-dark-400`,children:o(`chatMessage.saveAndSubmit`)})]})]}):(0,Z.jsx)(`div`,{className:`rounded-2xl rounded-ee-md border border-black/[0.06] bg-gray-900 px-3.5 py-2 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`,children:(0,Z.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):p?(0,Z.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[h?(0,Z.jsx)(Oe,{className:`h-2.5 w-2.5 opacity-50`}):(0,Z.jsx)(te,{className:`h-2.5 w-2.5 opacity-50`}),o(h?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:h?(0,Z.jsx)(`button`,{onClick:()=>void je(),disabled:Ae,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.restoreCompacted`),children:(0,Z.jsx)(ye,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):A?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{onClick:Me,disabled:F,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.saveChanges`),children:(0,Z.jsx)(I,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,Z.jsx)(`button`,{onClick:Pe,disabled:F,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.cancelEditing`),children:(0,Z.jsx)(W,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,Z.jsx)(`button`,{onClick:ke,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:o(`chatMessage.editSystemMessage`),children:(0,Z.jsx)(xe,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),A?(0,Z.jsx)(`textarea`,{dir:`auto`,value:M,onChange:e=>N(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:o(`chatMessage.systemMessagePlaceholder`),disabled:F}):(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:z?g:Le(g)}),Re&&(0,Z.jsx)(`button`,{onClick:()=>ne(!z),className:`mt-2 flex items-center gap-1 text-xs text-gray-400 transition-colors hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`,children:z?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ue,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(de,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,Z.jsxs)(`div`,{className:`relative`,children:[(ge||_e)&&(0,Z.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,Z.jsxs)(`button`,{onClick:()=>oe(!B),className:`flex items-center gap-1.5 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,Z.jsx)(ae,{className:f(`h-3.5 w-3.5`,_e&&`animate-pulse-subtle motion-reduce:animate-none`)}),_e?(0,Z.jsxs)(`span`,{className:`animate-shimmer bg-gradient-to-r from-gray-400 via-gray-900 to-gray-400 bg-[length:200%_100%] bg-clip-text font-medium text-transparent motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-gray-500 dark:from-dark-500 dark:via-dark-900 dark:to-dark-500 motion-reduce:dark:text-dark-600`,children:[o(`chatMessage.thinking`),`…`]}):(0,Z.jsx)(`span`,{className:`font-medium`,children:Se===void 0?o(`chatMessage.thinking`):o(`chatMessage.thoughtFor`,{duration:wt(Se)})}),B?(0,Z.jsx)(ue,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(de,{className:`h-3.5 w-3.5`})]}),B&&ge&&(0,Z.jsx)(`div`,{className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 dark:bg-dark-200/60`,children:(0,Z.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[13px] leading-relaxed text-gray-600 dark:text-dark-700`,children:ge})})]}),(0,Z.jsx)(Y,{content:ve,isStreaming:t})]}),!l&&!p&&be.length>0&&(0,Z.jsx)(`div`,{className:`mt-3`,children:(0,Z.jsx)(ut,{artifacts:be})}),!l&&!p&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,Z.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:o(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,Z.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,Z.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,Z.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!l&&!p&&e.statistics&&(0,Z.jsx)(`div`,{className:`mt-2`,children:(0,Z.jsx)(pt,{statistics:e.statistics})}),!p&&!t&&(0,Z.jsxs)(`div`,{className:f(`flex items-center gap-0.5 text-gray-400 dark:text-dark-500`,`sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,!l&&[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(se)?`sm:opacity-100`:`sm:opacity-0`,l?`mt-1 justify-end`:`mt-1`),children:[l&&(0,Z.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:d(e.timestamp,c.language),children:[De(),` ·`,` `,d(e.timestamp,c.language)]}),!l&&ve&&(0,Z.jsx)(bt,{text:ve,size:`sm`,externalPlaybackState:se,onStopExternal:Ee,onRetryExternal:we,className:f(`transition-colors`,se===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),l&&a&&!A&&(0,Z.jsx)(`button`,{onClick:()=>{N(e.content),j(!0)},className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.edit`),children:(0,Z.jsx)(xe,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{onClick:he,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(ce?`chatMessage.copied`:`chatMessage.copyMessage`),children:ce?(0,Z.jsx)(pe,{className:`h-3.5 w-3.5 text-green-500`}):(0,Z.jsx)(re,{className:`h-3.5 w-3.5`})}),!l&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{onClick:()=>Ie(1),className:f(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===1&&`text-primary-600 dark:text-primary-400`),title:o(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,Z.jsx)(ie,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,Z.jsx)(`button`,{onClick:()=>Ie(-1),className:f(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===-1&&`text-red-500 dark:text-red-400`),title:o(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,Z.jsx)(Te,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})})]}),!l&&r&&i&&(0,Z.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.regenerateResponse`),children:(0,Z.jsx)(O,{className:`h-3.5 w-3.5`})})]})]})]}),l&&(0,Z.jsx)(ln,{role:`user`,user:v??null})]}),ee&&(0,ft.createPortal)((0,Z.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":o(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>P(null),children:[(0,Z.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),P(null)},children:(0,Z.jsx)(W,{className:`h-7 w-7`})}),(0,Z.jsx)(`img`,{src:ee,alt:o(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},dn=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,fn=220,pn=e=>{let t=e.slice(0,880).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>fn?`${t.slice(0,219).trimEnd()}…`:t},mn=X.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,X.useRef)(null),a=(0,X.useRef)(null),o=(0,X.useRef)(new Map),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(0),p=(0,X.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),m=(0,X.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;!r||!i||(i.focus(),p(r.id,i),n(r.id))},[e,n,p]);if((0,X.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:dn()?`auto`:`smooth`})},[t]),e.length<3)return null;let h=Math.max(0,e.findIndex(e=>e.id===t)),g=e[h]?.id,_=e.findIndex(e=>e.id===c),v=_>=0?e[_]:null,y=_>=0?`conversation-history-preview-${_}`:void 0;return(0,Z.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,Z.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===g,u=Math.abs(a-h),d=c===t.id?y:void 0;return(0,Z.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,Z.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===h?0:-1,className:f(`group flex h-4 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>p(t.id,e.currentTarget),onFocus:e=>p(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),m(n))},children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:f(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),v&&(0,Z.jsx)(`div`,{id:y,role:`tooltip`,className:f(`pointer-events-none absolute start-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,Z.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,Z.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:pn(v.prompt)}),v.response&&(0,Z.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:pn(v.response)})]})})]})}),hn=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,Z.jsx)(un,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,Z.jsxs)(`div`,{className:f(`relative py-2`,c),children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,Z.jsx)(D,{className:`h-3 w-3`}),(0,Z.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let l=e.isActive!==!1,u=t&&i===e.id,d=u?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,Z.jsxs)(`div`,{className:f(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||u?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!u&&`cursor-pointer`),role:!l&&!u?`button`:void 0,tabIndex:!l&&!u?0:void 0,onClick:()=>!l&&!u&&s?.(e.id),onKeyDown:t=>{!l&&!u&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,Z.jsxs)(`div`,{className:f(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||u?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,Z.jsx)(pe,{className:`h-3 w-3`}),!l&&!u&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,Z.jsx)(`div`,{className:f(!l&&!u&&`opacity-75`),children:(0,Z.jsx)(un,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},gn={web_search:P,web_fetch:N,exec:V,browser:N,Read:k,Write:k,Edit:k,image:ce,memory_search:B,memory_get:B,working:Se,thinking:Se,default:Se},_n={web_search:`Searching the web`,web_fetch:`Fetching page`,exec:`Running command`,browser:`Using browser`,Read:`Reading file`,Write:`Writing file`,Edit:`Editing file`,image:`Analyzing image`,memory_search:`Searching memory`,memory_get:`Reading memory`,cron:`Managing schedule`,message:`Sending message`,tts:`Generating speech`,nodes:`Checking devices`,sessions_spawn:`Spawning agent`,canvas:`Rendering canvas`,process:`Managing process`,working:`Using tools`,thinking:`Thinking`},vn=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,Z.jsx)(`div`,{className:f(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=gn[e.name]||gn.default,n=_n[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,Z.jsxs)(`div`,{className:f(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,Z.jsx)(`div`,{className:f(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,Z.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,Z.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,Z.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,Z.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,Z.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};G(`components:chat-messages`);var yn=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],bn=e=>e.messages.every(e=>e.isActive===!1),xn=e=>e.role===`system`&&!m(e.content),Sn=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,Cn=e=>Math.min(120,e*.28),wn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],className:o,onRegenerate:c,onSelectBranch:l,onEditResend:u,followUpSuggestions:d,onFollowUpSelect:p})=>{let{t:m}=s(),h=(0,X.useRef)(null),g=(0,X.useRef)(void 0),_=(0,X.useRef)(null),v=(0,X.useRef)(null),y=(0,X.useRef)(new Map),b=(0,X.useRef)(null),x=(0,X.useRef)(0),S=(0,X.useRef)(!1),C=(0,X.useRef)(!1),[w,T]=(0,X.useState)(!1),E=(0,X.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>xn(e)&&!xn(t)?-1:xn(t)&&!xn(e)?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return xn(n)&&!xn(r)?-1:xn(r)&&!xn(n)?1:n.timestamp-r.timestamp})},[e]),D=(0,X.useMemo)(()=>{let e=[];for(let t=0;t<E.length;t++){let n=E[t],r=yn(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<E.length;e++){let t=yn(E[e]);if(t.role===`user`)break;if(t.role===`assistant`){i=t.content;break}}e.push({id:n.id,prompt:r.content,response:i})}return e},[E]),O=D.map(e=>e.id).join(``),k=(0,X.useMemo)(()=>O?O.split(``):[],[O]),A=(0,X.useMemo)(()=>new Set(k),[k]),[j,N]=(0,X.useState)(null),P=(0,X.useCallback)(()=>{let e=_.current;if(!e||k.length===0){N(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(x.current,k.length-1);if(t<=2)n=k.length-1;else{let t=e.scrollTop+Cn(e.clientHeight);for(;n<k.length-1;){let e=y.current.get(k[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=y.current.get(k[n]);if(!e||e.offsetTop<=t)break;n--}}x.current=n;let r=k[n];N(e=>e===r?e:r)},[k]),F=(0,X.useCallback)(()=>{b.current===null&&(b.current=window.requestAnimationFrame(()=>{b.current=null,P()}))},[P]),I=(0,X.useCallback)(()=>{let t=_.current;if(g.current&&clearTimeout(g.current),S.current=!1,g.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;C.current=!n,T(!n&&e.length>0),F()},[e.length,F]),te=(0,X.useCallback)(()=>{g.current&&clearTimeout(g.current),g.current=setTimeout(I,180)},[I]),L=(0,X.useCallback)((e=!1)=>{C.current&&!e||h.current?.scrollIntoView({behavior:Sn()})},[]),R=(0,X.useCallback)(()=>{let t=_.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(S.current){C.current=!0,T(!o&&e.length>0),F(),te();return}C.current=!o,T(!o&&e.length>0),a<=2&&k.length>0?(x.current=k.length-1,N(k[k.length-1])):F()},[k,e.length,te,F]),z=(0,X.useCallback)(e=>{let t=_.current,n=y.current.get(e);if(!t||!n)return;let r=Sn();S.current=!0,C.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-Cn(t.clientHeight)),behavior:r}),F(),r===`auto`?I():te()},[I,te,F]),ne=(0,X.useRef)(e.length);if((0,X.useEffect)(()=>{e.length>ne.current&&!C.current&&L(),ne.current=e.length},[e.length,L]),(0,X.useEffect)(()=>{i&&(t||n)&&!C.current&&requestAnimationFrame(()=>{let e=_.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,X.useEffect)(()=>{F();let e=v.current,t=_.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(F);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,F),()=>{n?.disconnect(),window.removeEventListener(`resize`,F)}},[O,F]),(0,X.useEffect)(()=>()=>{b.current!==null&&(window.cancelAnimationFrame(b.current),b.current=null)},[]),(0,X.useEffect)(()=>()=>{g.current&&clearTimeout(g.current)},[]),e.length===0&&!i)return(0,Z.jsx)(`div`,{className:f(`flex-1 flex items-center justify-center p-6 sm:p-10`,o),children:(0,Z.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,Z.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-surface/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,Z.jsx)(M,{className:`h-4 w-4`})}),(0,Z.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:m(`chatMessage.startConversation`)}),(0,Z.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:m(`chatMessage.startConversationDescription`)})]})});let B=-1;for(let e=E.length-1;e>=0;e--)if(E[e].messages.some(e=>e.role===`assistant`)){B=e;break}return(0,Z.jsxs)(`div`,{className:f(`relative min-h-0 flex-1`,o),style:{WebkitAppRegion:`no-drag`},children:[(0,Z.jsx)(`div`,{ref:_,"data-testid":`chat-scroll-viewport`,onScroll:R,className:f(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,Z.jsxs)(`div`,{ref:v,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[E.map((e,a)=>{let o=a===B,s=A.has(e.id),d=i&&e.messages.some(e=>e.id===r),f;if(bn(e))f=(0,Z.jsx)(`div`,{className:`opacity-55`,children:(0,Z.jsx)(un,{message:yn(e),isStreaming:!1,isLastAssistantMessage:!1,className:a===0?`mt-3 sm:mt-4`:``})});else if(e.messages.length===1){let s=e.messages[0],l=i&&s.id===r,d=l?{...s,content:t??s.content,thinking:n||s.thinking}:s;f=(0,Z.jsx)(un,{message:d,isStreaming:l,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onEditResend:i?void 0:u,className:a===0?`mt-3 sm:mt-4`:``})}else f=(0,Z.jsx)(hn,{messages:e.messages,isStreaming:d,streamingMessage:t,streamingThinking:n,streamingMessageId:r||void 0,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onSelectBranch:l,className:a===0?`mt-3 sm:mt-4`:``});return(0,Z.jsx)(`div`,{ref:t=>{s&&(t?y.current.set(e.id,t):y.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:f},e.id)}),i&&a.length>0&&(0,Z.jsx)(vn,{tools:a,className:`px-0`}),!i&&d&&d.length>0&&p&&(0,Z.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,Z.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:m(`chat.followUp`)}),(0,Z.jsx)(`div`,{className:`flex flex-col`,children:d.map(e=>(0,Z.jsx)(`button`,{onClick:()=>p(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-gray-600 transition-colors hover:text-gray-900 dark:border-dark-200 dark:text-dark-600 dark:hover:text-dark-900`,children:e},e))})]}),(0,Z.jsx)(`div`,{ref:h,className:`h-4 sm:h-6`})]})}),(0,Z.jsx)(mn,{items:D,activeId:j,onSelect:z}),w&&(0,Z.jsxs)(`button`,{onClick:()=>{S.current=!1,g.current&&(clearTimeout(g.current),g.current=void 0),C.current=!1,h.current?.scrollIntoView({behavior:Sn()}),T(!1)},className:f(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/[0.08]`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:m(`chatMessage.scrollToBottom`),children:[(0,Z.jsx)(ee,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:m(`chatMessage.newMessages`)})]})]})};function Tn(e){let t=(e.match(/```/g)||[]).length,n=t%2==1,r=null;if(n){let t=e.lastIndexOf("```");if(t!==-1){let n=e.slice(t+3).match(/^(\w+)/);n&&(r=n[1])}}return{hasCodeBlocks:t>0,isInCodeBlock:n,language:r}}var En=X.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,X.useMemo)(()=>Tn(e),[e]);return(0,Z.jsxs)(`div`,{className:`relative w-full`,children:[(0,Z.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:f(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,Z.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,Z.jsxs)(`div`,{className:f(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,Z.jsx)(fe,{className:`h-3 w-3`}),d&&(0,Z.jsx)(`span`,{children:d}),!d&&u&&(0,Z.jsx)(`span`,{children:`code`})]})})]})});En.displayName=`CodeAwareTextarea`;var Dn=G(`components:media-upload`),On=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,X.useRef)(null),[u,d]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)([]),_=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await v(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):L.error(`File type not supported: ${n.name}`)}},v=async r=>{if(n-e.length<=0){L.error(`Maximum ${n} images allowed`);return}if(r.size>10485760){L.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},y=async e=>{if(e.size>10485760){L.error(`File size must be less than 10MB`);return}m(!0);try{let t=await Me.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;g(e=>[...e,n]),i?.(n),L.success(`Document "${e.name}" uploaded`)}else L.error(t.error||`Failed to upload document`)}catch(e){Dn.error(`Document upload error:`,e),L.error(`Failed to upload document`)}finally{m(!1)}},b=e=>{e.preventDefault(),a||d(!0)},x=e=>{e.preventDefault(),d(!1)},S=e=>{e.preventDefault(),d(!1),a||_(e.dataTransfer.files)},C=n=>{t(e.filter((e,t)=>t!==n))},w=async e=>{try{let t=await Me.deleteDocument(e);t.success?(g(t=>t.filter(t=>t.id!==e)),L.success(`Document removed`)):L.error(t.error||`Failed to remove document`)}catch(e){Dn.error(`Error removing document:`,e),L.error(`Failed to remove document`)}},T=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},E=e.length>0||h.length>0;return(0,Z.jsxs)(`div`,{className:f(`space-y-3`,o),children:[(0,Z.jsxs)(`div`,{className:f(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>!a&&l.current?.click(),children:[(0,Z.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{_(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,Z.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[p?(0,Z.jsx)(be,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,Z.jsx)(H,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,Z.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,Z.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,Z.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),C(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,Z.jsx)(W,{className:`h-3 w-3`})})]},`img-${t}`)),h.map(e=>(0,Z.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,Z.jsx)(k,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,Z.jsx)(ke,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,Z.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:T(e.size)})]}),(0,Z.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,Z.jsx)(W,{className:`h-3 w-3`})})]},e.id))]})]})},kn=G(`components:document-indicator`),An=({sessionId:e,className:t=``})=>{let{t:n}=s(),[r,i]=(0,X.useState)([]),[a,o]=(0,X.useState)(!1),[c,u]=(0,X.useState)(null),d=(0,X.useRef)(null),f=(0,X.useCallback)(async()=>{try{let t=await Me.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){kn.error(`Failed to load documents:`,e)}},[e]);if((0,X.useEffect)(()=>{let e=setTimeout(()=>void f(),0),t=()=>void f();return window.addEventListener(`libre:documents-updated`,t),()=>{clearTimeout(e),window.removeEventListener(`libre:documents-updated`,t)}},[f]),(0,X.useEffect)(()=>{if(!a)return;let e=e=>{d.current?.contains(e.target)||(o(!1),u(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let p=async e=>{u(null);try{let t=await Me.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){kn.error(`Failed to delete document:`,e),U.error(n(`settings.documents.library.deleteFailed`))}},m=r.reduce((e,t)=>e+t.size,0);return(0,Z.jsxs)(`div`,{ref:d,className:`relative inline-block ${t}`,children:[a&&(0,Z.jsxs)(`div`,{className:`absolute bottom-full left-0 z-50 mb-2 w-80 max-w-[85vw] rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-300 dark:bg-dark-100`,children:[(0,Z.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-xs font-medium text-gray-500 dark:text-dark-600`,children:n(`chat.documents.title`)}),(0,Z.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,Z.jsx)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-gray-50 dark:hover:bg-dark-200`,children:c===e.id?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-red-700 dark:text-red-300`,children:n(`settings.documents.library.deleteConfirm`,{name:e.filename})}),(0,Z.jsx)(`button`,{onClick:()=>void p(e.id),className:`shrink-0 text-xs font-medium text-red-600 underline underline-offset-2 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:n(`common.delete`)}),(0,Z.jsx)(`button`,{onClick:()=>u(null),className:`shrink-0 text-xs text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,children:n(`common.cancel`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(k,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`truncate text-xs text-gray-900 dark:text-dark-900`,children:e.filename}),(0,Z.jsxs)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:[l(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,Z.jsx)(`button`,{onClick:()=>u(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,Z.jsx)(W,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),u(null)},className:`
|
|
4
|
+
inline-flex items-center space-x-1 px-2 py-1
|
|
5
|
+
bg-blue-50 dark:bg-blue-900/20
|
|
6
|
+
border border-blue-200 dark:border-blue-800
|
|
7
|
+
rounded-md text-xs
|
|
8
|
+
transition-colors hover:bg-blue-100 dark:hover:bg-blue-900/40
|
|
9
|
+
`,title:`${n(`chat.documents.title`)} - ${l(m)}`,children:[(0,Z.jsx)(z,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,Z.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[r.length,` doc`,r.length===1?``:`s`]})]})]})},jn=G(`components:structured-output`),Mn=[{key:`none`,value:null},{key:`json`,value:`json`},{key:`list`,value:{type:`object`,properties:{items:{type:`array`,items:{type:`string`}}},required:[`items`]}},{key:`summary`,value:{type:`object`,properties:{title:{type:`string`},summary:{type:`string`},key_points:{type:`array`,items:{type:`string`}}},required:[`title`,`summary`,`key_points`]}},{key:`analysis`,value:{type:`object`,properties:{analysis:{type:`string`},pros:{type:`array`,items:{type:`string`}},cons:{type:`array`,items:{type:`string`}},recommendation:{type:`string`}},required:[`analysis`,`pros`,`cons`,`recommendation`]}},{key:`custom`,value:`custom`}],Nn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,X.useState)(!1),[o,c]=(0,X.useState)(``),l=()=>Mn.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),u=()=>{let t=l();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},d=e=>{let n=l().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,Z.jsxs)(`div`,{className:f(`space-y-3`,n),children:[(0,Z.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,Z.jsxs)(`div`,{className:`flex items-center`,children:[(0,Z.jsx)(te,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,Z.jsx)(Ye,{value:u().label,onChange:e=>d(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u().description}),i&&(0,Z.jsxs)(`div`,{className:`space-y-3`,children:[(0,Z.jsx)(Xe,{value:o,onChange:e=>c(e.target.value),placeholder:`{
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"field1": { "type": "string" },
|
|
13
|
+
"field2": { "type": "number" }
|
|
14
|
+
},
|
|
15
|
+
"required": ["field1"]
|
|
16
|
+
}`,rows:8,className:`font-mono text-sm`}),(0,Z.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Z.jsx)(J,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){jn.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,Z.jsx)(J,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=u();return!e.value||e.value===`json`?null:(0,Z.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,Z.jsx)(E,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,Z.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,Z.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,Z.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,Z.jsx)(k,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},Pn=({value:e,inheritedValue:t,onChange:n})=>{let{t:r}=s(),[i,a]=(0,X.useState)(!1),o=(0,X.useRef)(null),c=e??t,l=st(c),u=ct(c),d=ct(e),p=t==null?void 0:ct(t);return(0,X.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return window.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[i]),(0,Z.jsxs)(`div`,{ref:o,className:`relative flex-shrink-0`,children:[(0,Z.jsxs)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>a(e=>!e),className:f(`h-9 rounded-full p-0 flex items-center justify-center gap-1 touch-manipulation transition-colors duration-150`,l?`w-auto px-2.5`:`w-9 sm:h-10 sm:w-10`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,l&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:l?r(`chat.input.thinkingOn`,{level:r(`settings.generation.thinkingLevels.${u}`)}):r(`chat.input.thinkingOff`),"aria-haspopup":`menu`,"aria-expanded":i,"aria-pressed":l,children:[(0,Z.jsx)(ae,{className:`h-4 w-4`}),l&&(0,Z.jsx)(`span`,{className:`text-[11px] font-medium`,children:r(`settings.generation.thinkingLevels.${u}`)})]}),i&&(0,Z.jsxs)(`div`,{role:`menu`,className:`absolute bottom-full end-0 z-30 mb-2 w-48 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:[(0,Z.jsx)(`p`,{className:`mb-1 px-2 pt-1 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.controls.thinking`)}),lt.map(e=>{let t=e===d;return(0,Z.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":t,onClick:()=>{n(ot(e)),a(!1)},className:f(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),children:[(0,Z.jsx)(`span`,{className:`truncate`,children:e==="default"&&p!==void 0?r(`settings.generation.thinkingLevels.defaultWith`,{level:r(`settings.generation.thinkingLevels.${p}`)}):r(`settings.generation.thinkingLevels.${e}`)}),t&&(0,Z.jsx)(pe,{className:`h-3.5 w-3.5 shrink-0`})]},e)})]})]})},Fn=7,In=2*Math.PI*Fn,Ln=e=>`${e}`,Rn=({usage:e,trainedBudget:t})=>{let{t:n,i18n:r}=s(),[i,a]=(0,X.useState)(!1),o=typeof e.budget==`number`&&e.budget>0,c=e.ratio??0,l=Math.round(c*100),u=e.measured?``:`~`,d=r.language,p=`${u}${v(e.used,d)}`,m=o?n(`chat.context.tokensUsed`,{used:Ln(p),budget:Ln(v(e.budget,d))}):n(`chat.context.tokensUsedNoBudget`,{used:Ln(p)}),h=t===void 0?void 0:n(`chat.context.capped`,{trained:Ln(v(t,d))}),g=[n(`chat.context.title`),o?n(`chat.context.full`,{percent:l}):void 0,m,h].filter(Boolean).join(` `),_=Math.min(c,1);return(0,Z.jsxs)(`div`,{className:`relative flex-shrink-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onFocus:()=>a(!0),onBlur:()=>a(!1),onKeyDown:e=>{e.key===`Escape`&&a(!1)},children:[(0,Z.jsx)(`span`,{role:o?`meter`:`img`,tabIndex:0,"aria-label":g,...o?{"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(l,100),"aria-valuetext":g}:{},className:f(`flex h-9 w-9 items-center justify-center rounded-full text-gray-400 outline-none sm:h-10 sm:w-10`,`transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/40`,`dark:text-dark-500`,c>=.8&&c<1&&`text-amber-600 dark:text-amber-400`,c>=1&&`text-red-600 dark:text-red-400`),children:(0,Z.jsxs)(`svg`,{viewBox:`0 0 18 18`,className:`h-4 w-4 -rotate-90`,children:[(0,Z.jsx)(`circle`,{cx:`9`,cy:`9`,r:Fn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`opacity-30`,...o?{}:{strokeDasharray:`2 2`}}),o&&_>0&&(0,Z.jsx)(`circle`,{cx:`9`,cy:`9`,r:Fn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:In,strokeDashoffset:In*(1-_)})]})}),i&&(0,Z.jsxs)(`div`,{role:`tooltip`,className:f(`pointer-events-none absolute bottom-full left-1/2 z-30 mb-2 -translate-x-1/2`,`whitespace-nowrap rounded-2xl bg-surface/95 px-4 py-3 text-center shadow-lv3 backdrop-blur-xl`,`border border-black/[0.06] dark:border-white/[0.08] dark:bg-dark-100/95`,`animate-scale-in`),children:[(0,Z.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.title`)}),o&&(0,Z.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.full`,{percent:l})}),(0,Z.jsx)(`p`,{className:`text-[13px] tabular-nums text-gray-900 dark:text-dark-900`,children:m}),h&&(0,Z.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:h})]})]})},zn=G(`components:chat-input`),Bn=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},Vn=[{mimeType:`audio/webm;codecs=opus`,format:`webm`}],Hn=300,Un=.25,Wn=e=>`${encodeURIComponent(e.plugin)}:${encodeURIComponent(e.model)}`;function Gn(e){if(typeof MediaRecorder>`u`)return;let t=new Set((e.config?.formats||[]).map(e=>e.toLowerCase()));return Vn.find(e=>(t.size===0||t.has(e.format))&&(typeof MediaRecorder.isTypeSupported!=`function`||MediaRecorder.isTypeSupported(e.mimeType)))?.mimeType}var Kn=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r,i18n:i}=s(),[a,o]=(0,X.useState)(``),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[v,x]=(0,X.useState)([]),[T,E]=(0,X.useState)(()=>typeof window<`u`&&window.isSecureContext&&typeof navigator<`u`&&navigator.mediaDevices&&Bn()?`browser`:``),D=(0,X.useRef)(null),O=(0,X.useRef)(null),M=(0,X.useRef)(null),ee=(0,X.useRef)(null),P=(0,X.useRef)(null),I=(0,X.useRef)(0),te=(0,X.useRef)(`idle`),L=(0,X.useRef)(void 0),R=(0,X.useRef)(``),B=(0,X.useMemo)(()=>typeof window<`u`&&window.isSecureContext&&typeof navigator<`u`&&!!navigator.mediaDevices&&!!Bn(),[]),re=(0,X.useMemo)(()=>v.filter(e=>!!Gn(e)),[v]),ie=typeof window<`u`&&window.isSecureContext&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia,ae=(0,X.useMemo)(()=>ie?re:[],[re,ie]),oe=(0,X.useMemo)(()=>T===`browser`&&B||ae.some(e=>Wn(e)===T)?T:B?`browser`:ae[0]?Wn(ae[0]):``,[B,ae,T]),V=(0,X.useMemo)(()=>ae.find(e=>Wn(e)===oe),[oe,ae]),le=!!V,ue=B||le,[de,fe]=(0,X.useState)([]),[H,me]=(0,X.useState)(null),[he,ge]=(0,X.useState)(!1),[W,_e]=(0,X.useState)(!1),[ye,xe]=(0,X.useState)(!1),[Se,Ce]=(0,X.useState)(!1);(0,X.useEffect)(()=>{let e=!1;return Pe.getConfig().then(t=>{!e&&t.success&&t.data&&xe(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]),(0,X.useEffect)(()=>{let e=!1;return Re.getModels().then(t=>{!e&&t.success&&t.data&&x(t.data)}).catch(()=>{e||x([])}),()=>{e=!0}},[]);let[we,Te]=(0,X.useState)(null),[De,Oe]=(0,X.useState)(!1),[ke,Ae]=(0,X.useState)([]),[G,je]=(0,X.useState)(!1),[Ne,Ie]=(0,X.useState)(!1),[K,ze]=(0,X.useState)(null),[Be,Ue]=(0,X.useState)(!1),q=(0,X.useRef)(null),Ge=(0,X.useRef)(null),{isGenerating:Ke,setBackgroundImage:qe}=We(),Je=We(e=>e.preferences.generationOptions),Ye=We(e=>e.preferences.imageGenSettings?.enabled===!0),Xe=Ye&&Be,{currentSession:Y,models:Ze}=w(),Qe=We(e=>Y?.model?e.preferences.modelGenerationOptions?.[Y.model]:void 0),$e=Y?.id,et=(0,X.useRef)(null),tt=(0,X.useMemo)(()=>({model:Y?.personaId?`persona:${Y.personaId}`:Y?.model||``,providerType:Y?.providerType,providerId:Y?.providerId}),[Y?.model,Y?.personaId,Y?.providerId,Y?.providerType]),nt=(0,X.useMemo)(()=>_(Ze,tt),[Ze,tt]),rt=tt.model?g(nt,tt):``,it=b(Ze,tt);(0,X.useEffect)(()=>{let e=!1;return Ye&&(async()=>{try{let t=await Ve.getPlugins();if(e)return;Ue(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;Ue(!1)}})(),()=>{e=!0}},[Ye]),(0,X.useEffect)(()=>{if(!W)return;let e=e=>{q.current&&!q.current.contains(e.target)&&(_e(!1),Te(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[W]);let at=()=>{_e(!1),Te(null),Oe(!1)};(0,X.useEffect)(()=>{if(!De)return;let e=!1;return Me.getCollections().then(t=>{!e&&t.success&&t.data&&Ae(t.data)}).catch(()=>{}),()=>{e=!0}},[De]);let ot=Y?.settings?.generationOptions?.think,st=Qe?.think??Je?.think??null,ct=(0,X.useMemo)(()=>Ze.find(e=>e.name===Y?.model),[Ze,Y?.model]),[lt,ut]=(0,X.useState)(null);(0,X.useEffect)(()=>{let e=Y?.model;if(!e||Ze.length===0||!ct||ct.isPlugin||ct.isAgent)return;let t=!1;return Le.getModelDefaults(e).then(n=>{t||!n.success||!n.data||ut({model:e,supportsThinking:n.data.supportsThinking,options:n.data.options??{},trainedContextLength:n.data.trainedContextLength,contextCapped:n.data.contextCapped})}).catch(()=>{}),()=>{t=!0}},[ct,Y?.model,Ze.length]);let ft=lt?.model===Y?.model?lt:null,pt=ft?.supportsThinking,mt=!!(Y&&!ct?.isAgent&&(ct?.isPlugin?ct.reasoningSupport!==!1:pt!==!1)),ht=S({model:ct,sessionOptions:Y?.settings?.generationOptions,pinnedOptions:Qe,modelDefaults:ft?.options,globalOptions:Je}),gt=w(e=>e.contextWindowMessages),_t=(0,X.useMemo)(()=>C({messages:Y?.messages??[],budget:ht,systemPrompt:K?.parameters?.system_prompt,windowMessages:gt}),[ht,gt,K,Y?.messages]),vt=async e=>{if(!Y)return;let t={...Y.settings?.generationOptions??{}};e===null?delete t.think:t.think=e;let n={...Y.settings,generationOptions:t};if(w.setState(e=>({currentSession:e.currentSession?.id===Y.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===Y.id?{...e,settings:n}:e)})),!Y.isPrivate)try{await He.updateSession(Y.id,{settings:n})}catch(e){zn.error(`Failed to update the thinking setting:`,e)}},yt=Y?.settings?.knowledgeCollectionIds??[],bt=async e=>{if(!Y)return;let t=yt.includes(e)?yt.filter(t=>t!==e):[...yt,e],n={...Y.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(w.setState(e=>({currentSession:e.currentSession?.id===Y.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===Y.id?{...e,settings:n}:e)})),!Y.isPrivate)try{await He.updateSession(Y.id,{settings:n})}catch(e){zn.error(`Failed to update knowledge collections:`,e),U.error(r(`chat.input.menu.attachFailed`))}},Q=(0,X.useCallback)(()=>{P.current!==null&&(window.clearTimeout(P.current),P.current=null)},[]),xt=(0,X.useCallback)(e=>{te.current=e,l(e===`starting`),d(e===`recording`),m(e===`transcribing`)},[]),St=(0,X.useCallback)(()=>{I.current+=1,Q(),D.current?.stop(),D.current=null,ee.current?.abort(),ee.current=null;let e=O.current;O.current=null,e&&(e.ondataavailable=null,e.onerror=null,e.onstop=null,e.state===`recording`&&e.stop()),M.current?.getTracks().forEach(e=>e.stop()),M.current=null,xt(`idle`)},[Q,xt]);(0,X.useEffect)(()=>(L.current=$e,St),[St,$e]);let Ct=async()=>{let e=te.current;if(e===`starting`||e===`transcribing`){St();return}if(e===`recording`){O.current?.state===`recording`?(xt(`transcribing`),O.current.stop()):St();return}let t=V;if(t&&le){let e=I.current+1;I.current=e;let n=Y?.id;R.current=a,xt(`starting`);try{let a=await navigator.mediaDevices.getUserMedia({audio:!0});if(I.current!==e||L.current!==n){a.getTracks().forEach(e=>e.stop());return}M.current=a;let s=Gn(t),c=s?new MediaRecorder(a,{mimeType:s}):new MediaRecorder(a),l=[];c.ondataavailable=e=>{e.data.size>0&&l.push(e.data)},c.onerror=()=>{a.getTracks().forEach(e=>e.stop()),Q(),I.current===e&&(O.current=null,M.current=null,xt(`idle`),U.error(r(`chat.input.menu.attachFailed`)))},c.onstop=()=>{if(a.getTracks().forEach(e=>e.stop()),Q(),I.current!==e||L.current!==n)return;if(O.current=null,M.current=null,l.length===0){xt(`idle`);return}let s=new Blob(l,{type:c.mimeType||l[0].type||`audio/webm`}),u=new AbortController;ee.current=u,xt(`transcribing`),Re.transcribe(s,t,{language:i.language,signal:u.signal}).then(t=>{if(I.current!==e||L.current!==n||u.signal.aborted)return;let r=R.current;o(r?`${r} ${t.text.trim()}`:t.text.trim())}).catch(e=>{u.signal.aborted||(zn.error(`Provider transcription failed:`,e),U.error(e instanceof Error?e.message:r(`chat.input.menu.attachFailed`)))}).finally(()=>{ee.current===u&&I.current===e&&(ee.current=null,xt(`idle`))})},O.current=c,c.start(250);let u=t.config?.max_duration_seconds,d=typeof u==`number`&&u>0?Math.min(u,Hn):Hn;P.current=window.setTimeout(()=>{I.current===e&&c.state===`recording`&&c.stop()},Math.max(.1,d-Un)*1e3),xt(`recording`);return}catch(t){if(I.current!==e)return;zn.error(`Failed to start provider dictation:`,t),Q(),M.current?.getTracks().forEach(e=>e.stop()),M.current=null,O.current=null,xt(`idle`),U.error(r(`chat.input.menu.attachFailed`));return}}let n=Bn();if(!n)return;let s=I.current+1;I.current=s;let c=Y?.id,l=new n;l.lang=i.language,l.continuous=!0,l.interimResults=!0,R.current=a,l.onresult=e=>{if(I.current!==s||L.current!==c||D.current!==l)return;let t=``;for(let n=0;n<e.results.length;n++)t+=e.results[n][0]?.transcript??``;let n=R.current;o(n?`${n} ${t.trim()}`:t.trim())},l.onend=()=>{I.current===s&&(D.current=null,xt(`idle`))},l.onerror=()=>{I.current===s&&(D.current=null,xt(`idle`))},D.current=l,xt(`recording`);try{l.start()}catch(e){zn.error(`Failed to start dictation:`,e),D.current=null,xt(`idle`)}},wt=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){at(),Ie(!0);try{let e=await Me.uploadDocument(t,Y?.id);e.success?(U.success(r(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):U.error(e.error||r(`chat.input.menu.attachFailed`))}catch(e){zn.error(`Document upload failed:`,e),U.error(r(`chat.input.menu.attachFailed`))}finally{Ie(!1)}}},Tt=async()=>{let e=we?.trim();if(!(!e||G)){je(!0);try{let t=await Me.fetchWebpage(e,Y?.id);t.success?(U.success(r(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),at()):U.error(t.error||r(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||r(`chat.input.menu.attachFailed`);zn.error(`Webpage attach failed:`,e),U.error(t)}finally{je(!1)}}},Et=t=>{if(t.preventDefault(),!(!a.trim()||Ke)){if(!it){U.error(r(`chat.model.selectBeforeSending`));return}e(a.trim(),de.length>0?de:void 0,H||void 0,ye&&Se?!0:void 0),o(``),fe([])}},Dt=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),Et(e))},Ot=()=>{t()};(0,X.useEffect)(()=>{let e=et.current;e&&(e.style.height=`auto`,e.style.height=a?`${Math.min(e.scrollHeight,200)}px`:``)},[a]),(0,X.useEffect)(()=>{(async()=>{if(Y?.personaId)try{let e=await Fe.getPersona(Y.personaId);if(e.success&&e.data)ze(e.data);else{zn.warn(`Persona ${Y.personaId} not found, clearing reference`),ze(null);let{setCurrentSession:e}=w.getState();e({...Y,personaId:void 0})}}catch(e){if(zn.error(`Failed to load current persona:`,e),ze(null),Y){let{setCurrentSession:e}=w.getState();e({...Y,personaId:void 0})}}else ze(null)})()},[Y?.personaId]);let kt=async e=>{let t=y(nt,e.target.value);if(t&&Y)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await Fe.getPersona(e);if(!n.success||!n.data){U.error(r(`chat.persona.loadFailed`));return}let i=n.data,a=await He.updateSession(Y.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(a.success&&a.data){let{sessions:e}=w.getState(),t=e.map(e=>e.id===Y.id?a.data:e);w.setState({sessions:t,currentSession:a.data}),i.background&&qe(i.background),U.success(r(`chat.persona.applied`))}}else{let e=await He.updateSession(Y.id,{model:t.model,providerType:t.providerType,providerId:(t.providerType===`plugin`||t.providerType===`agent`)&&t.providerId||null,personaId:null});if(e.success&&e.data){let{sessions:t}=w.getState(),n=t.map(t=>t.id===Y.id?e.data:t);w.setState({sessions:n,currentSession:e.data}),qe(null),U.success(r(`chat.model.updated`))}}}catch(e){zn.error(`Failed to update session:`,e),U.error(r(`chat.toasts.updateFailed`))}},At=de.length>0||H!==null;return(0,Z.jsx)(`div`,{className:`pointer-events-none`,children:(0,Z.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[he&&(0,Z.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/90`,children:[(0,Z.jsx)(On,{images:de,onImagesChange:fe,maxImages:5,sessionId:Y?.id,disabled:n}),(0,Z.jsx)(Nn,{format:H,onFormatChange:me})]}),(0,Z.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[(0,Z.jsx)(`form`,{onSubmit:Et,children:(0,Z.jsxs)(`div`,{className:f(`rounded-[24px] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200`,`bg-surface dark:bg-surface-subtle`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-lv2 focus-within:shadow-lv3`),children:[(0,Z.jsx)(En,{ref:et,value:a,onChange:e=>o(e.target.value),onKeyDown:Dt,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!m-0 block w-full min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-2 !pt-1.5 !pb-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsxs)(`div`,{ref:q,className:`relative flex-shrink-0`,children:[(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(he){ge(!1);return}_e(e=>!e),Te(null)},className:f(`h-9 w-9 !p-0 rounded-full flex-shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay`,`transition-colors duration-150 touch-manipulation`,At&&`text-primary-600 dark:text-primary-400`,(he||W)&&`bg-hover-solid text-ink`),title:r(`chat.input.attachments`),children:Ne||G?(0,Z.jsx)(be,{className:`h-4 w-4 animate-spin`}):At?(0,Z.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,Z.jsx)(ne,{className:`h-4 w-4`}),(0,Z.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):he?(0,Z.jsx)(se,{className:`h-4 w-4`}):(0,Z.jsx)(F,{className:`h-4 w-4`})}),W&&(0,Z.jsx)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 w-64 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:De?(0,Z.jsxs)(`div`,{className:`p-1`,children:[(0,Z.jsx)(`p`,{className:`mb-1 px-1.5 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.input.menu.attachKnowledge`)}),ke.length===0?(0,Z.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-gray-400 dark:text-dark-500`,children:r(`chat.input.menu.noCollections`)}):ke.map(e=>{let t=yt.includes(e.id);return(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>void bt(e.id),className:f(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),"aria-pressed":t,children:[(0,Z.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,Z.jsx)(z,{className:`h-4 w-4 shrink-0`}),(0,Z.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,Z.jsx)(pe,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Oe(!1),className:`mt-1 w-full rounded-lg border-t border-gray-100 px-2.5 py-1.5 text-start text-xs text-gray-500 hover:bg-gray-100 dark:border-dark-300 dark:text-dark-600 dark:hover:bg-dark-200`,children:r(`common.back`)})]}):we===null?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{ge(!0),at()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Z.jsx)(ce,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.uploadImages`)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Ge.current?.click(),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Z.jsx)(k,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachDocument`)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Te(``),className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Z.jsx)(N,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachWebpage`)]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>Oe(!0),className:`flex w-full items-center justify-between gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,Z.jsx)(z,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachKnowledge`)]}),yt.length>0&&(0,Z.jsx)(`span`,{className:`rounded-full bg-primary-50 px-1.5 text-[10px] font-medium tabular-nums text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`,children:yt.length})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{ge(!0),at()},className:`flex w-full items-center gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,Z.jsx)(Ee,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.structuredOutput`)]})]}):(0,Z.jsxs)(`div`,{className:`p-1.5`,children:[(0,Z.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.input.menu.attachWebpage`)}),(0,Z.jsx)(`input`,{type:`url`,value:we,onChange:e=>Te(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),Tt()):e.key===`Escape`&&Te(null)},placeholder:`https://…`,autoFocus:!0,dir:`ltr`,className:`w-full rounded-lg border border-black/[0.08] bg-white px-2.5 py-1.5 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`}),(0,Z.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,Z.jsx)(`button`,{type:`button`,onClick:()=>Te(null),className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:r(`common.cancel`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>void Tt(),disabled:!we.trim()||G,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white hover:bg-gray-700 disabled:opacity-50 dark:bg-dark-300 dark:hover:bg-dark-400`,children:G?(0,Z.jsx)(be,{className:`h-3.5 w-3.5 animate-spin`}):r(`chat.input.menu.attach`)})]})]})}),(0,Z.jsx)(`input`,{ref:Ge,type:`file`,accept:`.pdf,.txt,application/pdf,text/plain`,className:`hidden`,onChange:e=>void wt(e)})]}),(0,Z.jsxs)(`div`,{className:`ms-auto flex flex-shrink-0 items-center gap-1 sm:gap-1.5`,children:[mt&&(0,Z.jsx)(Pn,{value:ot,inheritedValue:st,onChange:e=>void vt(e)}),ye&&(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Ce(e=>!e),className:f(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,Se&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:r(Se?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":Se,children:(0,Z.jsx)(N,{className:`h-4 w-4`})}),ae.length>0&&(0,Z.jsxs)(`select`,{value:oe,onChange:e=>E(e.target.value),disabled:c||u||p,"aria-label":r(`chat.input.transcriptionSource`),title:V?r(`chat.input.providerTranscriptionDisclosure`,{provider:V.plugin}):r(`chat.input.transcriptionSource`),className:`h-8 max-w-32 rounded-lg border border-black/[0.08] bg-transparent px-1.5 text-[11px] text-gray-500 outline-none focus:border-primary-500/40 dark:border-white/[0.09] dark:text-dark-600`,children:[B&&(0,Z.jsx)(`option`,{value:`browser`,children:r(`chat.input.browserSpeech`)}),ae.map(e=>(0,Z.jsxs)(`option`,{value:Wn(e),children:[e.plugin,` · `,e.model]},Wn(e)))]}),ue&&(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void Ct(),className:f(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,(c||u||p)&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:p||c?r(`common.cancel`):u?r(`chat.input.voiceStop`):V?r(`chat.input.providerTranscriptionDisclosure`,{provider:V.plugin}):r(`chat.input.voiceInput`),"aria-pressed":c||u||p,children:c?(0,Z.jsx)(be,{className:`h-4 w-4 animate-spin`}):p?(0,Z.jsx)(A,{className:`h-4 w-4`}):(0,Z.jsx)(ve,{className:`h-4 w-4`})}),Y&&(0,Z.jsx)(Rn,{usage:_t,trainedBudget:ft?.contextCapped?ft.trainedContextLength:void 0}),Y&&nt.length>0&&(0,Z.jsx)(`div`,{className:`hidden sm:block`,children:(0,Z.jsx)(dt,{models:nt,selectedModel:rt,onModelChange:kt,getModelValue:h,currentPersona:K,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:Xe})}),Ke?(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:Ot,className:f(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.stopGeneration`),children:(0,Z.jsx)(A,{className:`h-4 w-4`})}):(0,Z.jsx)(J,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!a.trim()||n||!it,className:f(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-primary-500 text-white hover:bg-primary-400`,`disabled:cursor-not-allowed disabled:bg-primary-300/50 disabled:text-white/80 dark:disabled:bg-primary-800/60 dark:disabled:text-white/40 disabled:hover:bg-primary-300/50 dark:disabled:hover:bg-primary-800/60`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.sendMessage`),children:(0,Z.jsx)(j,{className:`h-4 w-4`})})]})]})]})}),V&&le&&(0,Z.jsx)(`p`,{role:`note`,className:`mt-1.5 text-center text-[10px] leading-relaxed text-amber-700 dark:text-amber-300`,children:r(`chat.input.providerTranscriptionDisclosure`,{provider:V.plugin})}),Y&&nt.length>0&&(0,Z.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,Z.jsx)(dt,{models:nt,selectedModel:rt,onModelChange:kt,getModelValue:h,currentPersona:K,className:`w-full`,compact:!0,showImageGen:Xe})}),(0,Z.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,Z.jsx)(An,{sessionId:Y?.id}),(0,Z.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,Z.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),At&&(0,Z.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,de.length>0&&r(`chat.footer.images`,{count:de.length}),de.length>0&&H&&` • `,H&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},qn=G(`components:chat-controls-panel`),Jn=[{key:`temperature`,labelKey:`temperature`,step:`0.1`,min:0,max:2},{key:`top_p`,labelKey:`topP`,step:`0.05`,min:0,max:1},{key:`top_k`,labelKey:`topK`,step:`1`,min:1},{key:`min_p`,labelKey:`minP`,step:`0.05`,min:0,max:1},{key:`num_predict`,labelKey:`maxTokens`,step:`1`},{key:`repeat_penalty`,labelKey:`repeatPenalty`,step:`0.05`,min:0},{key:`seed`,labelKey:`seed`,step:`1`},{key:`num_ctx`,labelKey:`contextLength`,step:`1`}],Yn=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i}=s(),a=w(e=>e.draftSessionSettings),o=w(e=>e.setDraftSessionSettings),l=e?.model??t??``,u=We(e=>e.preferences.generationOptions),d=We(e=>e.preferences.modelGenerationOptions?.[l]),[f,p]=(0,X.useState)({options:{},contextCapped:!1});(0,X.useEffect)(()=>{if(!n||!l)return;let e=!1;return Le.getModelDefaults(l).then(t=>{e||!t.success||!t.data||p({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,l]);let h=(0,X.useMemo)(()=>({...u??{},...f.options,...d??{}}),[u,f.options,d]),g=(0,X.useMemo)(()=>e?.messages.find(e=>e.role===`system`&&!m(e.content)),[e?.messages]),[_,v]=(0,X.useState)(g?.content??a.systemPrompt??``),[y,b]=(0,X.useState)(e?.settings?.generationOptions??a.generationOptions??{}),[x,S]=(0,X.useState)(!1),[C,T]=(0,X.useState)(e?.settings?.compaction!==!1),[E,D]=(0,X.useState)(e?.id??`draft`),O=e?.id??`draft`;E!==O&&(D(O),v(g?.content??a.systemPrompt??``),b(e?.settings?.generationOptions??a.generationOptions??{}),T(e?.settings?.compaction!==!1));let k=e=>{b(t=>{let n={...t},r=ot(e);return r===null?delete n.think:n.think=r,n})},A=(e,t)=>{b(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},j=async()=>{S(!0);try{let t=_.trim(),n=g?.content??``,a=Object.fromEntries(Object.entries(y).filter(([,e])=>e!==void 0)),s=e?{...e.settings,generationOptions:a}:Object.keys(a).length>0?{generationOptions:a}:void 0;if(s&&e&&(C?delete s.compaction:s.compaction=!1),!e){o({systemPrompt:t||void 0,generationOptions:s?.generationOptions}),L.success(i(`chat.controls.saved`)),r();return}let l=e.messages;if(t!==n.trim()&&(g?l=t?e.messages.map(e=>e.id===g.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==g.id):t&&(l=[{id:c(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)w.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:l,settings:s}:t.currentSession}));else{let t=await He.updateSession(e.id,{messages:l,settings:s});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;w.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}L.success(i(`chat.controls.saved`)),r()}catch(e){qn.error(`Failed to save chat controls:`,e),L.error(i(`chat.controls.saveFailed`))}finally{S(!1)}};return n?(0,Z.jsxs)(`div`,{"data-testid":`chat-controls-panel`,className:`flex h-full w-[21rem] shrink-0 flex-col border-s border-black/[0.06] bg-surface/70 backdrop-blur-xl dark:border-white/[0.07] dark:bg-dark-100/70`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,Z.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:i(`chat.controls.title`)}),(0,Z.jsx)(`button`,{onClick:r,className:`rounded-full p-1.5 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-900`,title:i(`common.close`),children:(0,Z.jsx)(W,{className:`h-4 w-4`})})]}),(0,Z.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.systemPrompt`)}),(0,Z.jsx)(`textarea`,{dir:`auto`,value:_,onChange:e=>v(e.target.value),placeholder:i(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/[0.08] bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{htmlFor:`chat-control-think`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.thinking`)}),(0,Z.jsx)(`select`,{id:`chat-control-think`,value:ct(y.think),onChange:e=>k(e.target.value),className:`w-full rounded-xl border border-black/[0.08] bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`,children:lt.map(e=>(0,Z.jsx)(`option`,{value:e,children:e==="default"&&h.think!==void 0&&h.think!==null?i(`settings.generation.thinkingLevels.defaultWith`,{level:i(`settings.generation.thinkingLevels.${ct(h.think)}`)}):i(`settings.generation.thinkingLevels.${e}`)},e))}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.thinkingDescription`)})]}),e&&(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`label`,{htmlFor:`chat-control-compaction`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.compaction`)}),(0,Z.jsxs)(`select`,{id:`chat-control-compaction`,value:C?`default`:`off`,onChange:e=>T(e.target.value!==`off`),className:`w-full rounded-xl border border-black/[0.08] bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`,children:[(0,Z.jsx)(`option`,{value:`default`,children:i(`chat.controls.compactionDefault`)}),(0,Z.jsx)(`option`,{value:`off`,children:i(`chat.controls.compactionOff`)})]}),(0,Z.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.compactionDescription`)})]}),(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{className:`mb-1.5 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.advancedParams`)}),(0,Z.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.advancedParamsDescription`)}),f.contextCapped&&f.trainedContextLength&&(0,Z.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-500 dark:text-dark-600`,children:i(`chat.controls.contextCapped`,{context:h.num_ctx?.toLocaleString(),trained:f.trainedContextLength.toLocaleString()})}),(0,Z.jsx)(`div`,{className:`space-y-1.5`,children:Jn.map(e=>{let t=y[e.key],n=h[e.key],r=f.options[e.key]!==void 0&&d?.[e.key]===void 0;return(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsxs)(`label`,{htmlFor:`chat-control-${e.key}`,className:`text-[13px] text-gray-700 dark:text-dark-700`,children:[i(`chat.controls.params.${e.labelKey}`),r&&(0,Z.jsx)(`span`,{title:i(`chat.controls.fromModelHint`),className:`ms-1.5 text-[10px] uppercase tracking-wide text-gray-400 dark:text-dark-500`,children:i(`chat.controls.fromModel`)})]}),(0,Z.jsx)(`input`,{id:`chat-control-${e.key}`,type:`number`,inputMode:`decimal`,step:e.step,min:e.min,max:e.max,value:typeof t==`number`?t:``,placeholder:typeof n==`number`?String(n):i(`common.default`),onChange:t=>A(e.key,t.target.value),className:`w-24 rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-t border-black/[0.06] px-4 py-3 dark:border-white/[0.07] lg:pb-16`,children:[(0,Z.jsx)(`button`,{onClick:()=>{b({}),v(g?.content??``)},className:`text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:i(`common.reset`)}),(0,Z.jsx)(J,{onClick:()=>void j(),size:`sm`,disabled:x,children:i(x?`common.saving`:`common.save`)})]})]}):null},Xn=6,Zn=[],Qn=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}},$n=({session:e})=>{let{t}=s(),[n,r]=(0,X.useState)({sessionId:``,docs:Zn}),i=!e.isPrivate&&n.sessionId===e.id?n.docs:Zn,[a,o]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)(!1),{webSources:f,ragSources:p}=(0,X.useMemo)(()=>{let t=new Map,n=new Map;for(let r of e.messages){let e=r.providerMetadata;if(Array.isArray(e?.webSearchSources))for(let n of e.webSearchSources){let e=n;e&&typeof e.url==`string`&&e.url&&t.set(e.url,{url:e.url,title:typeof e.title==`string`&&e.title?e.title:e.url})}if(Array.isArray(e?.ragSources))for(let t of e.ragSources){let e=t;e&&typeof e.id==`string`&&e.id&&n.set(e.id,{id:e.id,filename:typeof e.filename==`string`&&e.filename?e.filename:e.id})}}return{webSources:Array.from(t.values()),ragSources:Array.from(n.values())}},[e.messages]);(0,X.useEffect)(()=>{if(e.isPrivate)return;let t=!1,n=()=>{Me.getDocuments(e.id).then(n=>{t||!n.success||!Array.isArray(n.data)||r({sessionId:e.id,docs:n.data.map(e=>({id:e.id,filename:e.filename}))})}).catch(()=>{})};return n(),window.addEventListener(`libre:documents-updated`,n),()=>{t=!0,window.removeEventListener(`libre:documents-updated`,n)}},[e.id,e.isPrivate]);let m=(0,X.useMemo)(()=>{let e=new Map;for(let t of i)e.set(t.id,{...t,used:!1});for(let t of p)e.set(t.id,{id:t.id,filename:t.filename,used:!0});return Array.from(e.values())},[i,p]);if(f.length===0&&m.length===0)return null;let h=a?f:f.slice(0,Xn),g=c?m:m.slice(0,Xn),_=(e,n,r)=>(e>0||n)&&(0,Z.jsx)(`button`,{type:`button`,onClick:r,className:`mt-1 flex items-center gap-1 px-1 text-[12px] text-gray-400 transition-colors hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,children:n?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ue,{className:`h-3 w-3`}),t(`chatMessage.showLess`,`Show less`)]}):`${t(`chatMessage.showMore`)} (${e})`}),v=(0,Z.jsxs)(Z.Fragment,{children:[f.length>0&&(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`chat.message.sources`,`Sources`)}),(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:h.map(e=>(0,Z.jsx)(`li`,{children:(0,Z.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`group -mx-1 flex items-center gap-2.5 rounded-lg px-1 py-1.5 transition-colors hover:bg-black/[0.04] dark:hover:bg-white/[0.05]`,title:e.url,children:[(0,Z.jsx)(N,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-700 dark:text-dark-500 dark:group-hover:text-dark-800`}),(0,Z.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`span`,{className:`block truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.title}),(0,Z.jsx)(`span`,{dir:`ltr`,className:`block truncate text-[11px] text-gray-400 dark:text-dark-500`,children:Qn(e.url)})]})]})},e.url))}),_(f.length-h.length,a,()=>o(e=>!e))]}),m.length>0&&(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`settings.tabs.documents`,`Documents`)}),(0,Z.jsx)(`ul`,{className:`space-y-0.5`,children:g.map(e=>(0,Z.jsxs)(`li`,{className:`-mx-1 flex items-center gap-2.5 rounded-lg px-1 py-1.5`,title:e.filename,children:[(0,Z.jsx)(k,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,Z.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.filename}),e.used&&(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-primary-500`})]},e.id))}),_(m.length-g.length,c,()=>l(e=>!e))]})]});return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`aside`,{"data-testid":`chat-sources-panel`,className:`hidden w-72 shrink-0 flex-col gap-7 overflow-y-auto border-s border-black/[0.05] px-5 py-6 scrollbar-thin dark:border-white/[0.06] xl:flex`,children:v}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),"data-testid":`chat-sources-trigger`,className:`absolute end-3 top-[4.25rem] z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 xl:hidden`,title:t(`chat.message.sources`,`Sources`),"aria-haspopup":`dialog`,"aria-expanded":u,children:[(0,Z.jsx)(z,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`absolute -end-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white shadow-sm`,children:f.length+m.length})]}),u&&(0,ft.createPortal)((0,Z.jsxs)(`div`,{className:`fixed inset-0 z-[80] xl:hidden`,children:[(0,Z.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/35 backdrop-blur-[2px]`,onClick:()=>d(!1),"aria-label":t(`common.close`)}),(0,Z.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":t(`chat.message.sources`,`Sources`),className:`absolute inset-x-3 bottom-3 max-h-[75vh] overflow-y-auto rounded-2xl border border-black/[0.08] bg-surface p-5 shadow-[0_20px_70px_rgba(0,0,0,0.3)] scrollbar-thin dark:border-white/[0.09] dark:bg-dark-100`,"data-testid":`chat-sources-sheet`,children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,Z.jsx)(`p`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:t(`chat.message.sources`,`Sources`)}),(0,Z.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`rounded-md p-1.5 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":t(`common.close`),children:(0,Z.jsx)(W,{className:`h-4 w-4`})})]}),(0,Z.jsx)(`div`,{className:`flex flex-col gap-6`,children:v})]})]}),document.body)]})},er=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,X.useState)(!1),a=(0,X.useRef)(null),[o,s]=(0,X.useState)({top:0,left:0});(0,X.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect(),t=document.documentElement.dir===`rtl`?e.right-288:e.left;s({top:e.bottom+8,left:Math.min(window.innerWidth-288-8,Math.max(8,t))})}},[r]);let c=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),l=()=>Ie(e,64),u=t=>{ze(t.currentTarget,e.name,64)};return(0,Z.jsxs)(`div`,{className:f(`relative`,n),children:[(0,Z.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:f(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,Z.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:u}),(0,Z.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,Z.jsx)(M,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,Z.jsx)(de,{className:f(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,ft.createPortal)((0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,Z.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,Z.jsxs)(`div`,{className:f(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,Z.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,Z.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 end-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,Z.jsx)(W,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,Z.jsxs)(`div`,{className:`absolute top-2 start-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,Z.jsx)(ae,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,Z.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,Z.jsx)(`img`,{src:l(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:u})}),(0,Z.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,Z.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,Z.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,Z.jsx)(R,{className:`h-3 w-3`}),e.model]}),e.description&&(0,Z.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,Z.jsxs)(`div`,{className:`mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,Z.jsx)(Ce,{className:`h-2.5 w-2.5 text-gray-400`}),(0,Z.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,Z.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,Z.jsx)(we,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,Z.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,Z.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,Z.jsx)(ae,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},tr=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,X.useRef)(null),[o,c]=(0,X.useState)(!1),l=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){L.error(`File ${o.name} is not an image`);continue}if(o.size>10485760){L.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&L.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),c(!0)},d=e=>{e.preventDefault(),c(!1)},p=e=>{e.preventDefault(),c(!1),l(e.dataTransfer.files)},m=n=>{t(e.filter((e,t)=>t!==n))},h=e.length<n;return(0,Z.jsxs)(`div`,{className:f(`space-y-3`,r),children:[h&&(0,Z.jsxs)(`div`,{className:f(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:u,onDragLeave:d,onDrop:p,children:[(0,Z.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,Z.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,Z.jsx)(H,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,Z.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,Z.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,Z.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,Z.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,Z.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,Z.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>m(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,Z.jsx)(W,{className:`h-4 w-4`})})})]},t))}),h&&e.length>0&&(0,Z.jsxs)(J,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,Z.jsx)(ce,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},nr=(e,t)=>{t?.add(e.assistantMessageId),e.cancelRequested=!0,e.jobId&&e.abort.abort()},rr=async e=>{if(!e.cancelledMessageIds.has(e.assistantMessageId))return!1;try{let t=await(e.cancelByIdentity??pr)(e.sessionId,e.assistantMessageId);await e.settle(t)}catch(t){e.onError?.(t)}return!0},ir=e=>{e.retainForContinuation||e.cancelledMessageIds.delete(e.assistantMessageId)},ar=async(e,t,n={})=>{if(e.jobId=t.jobId,!e.cancelRequested)return`stream`;e.abort.abort();let[,r]=await Promise.allSettled([(n.byJob??fr)(t.jobId),(n.byIdentity??pr)(e.sessionId,e.assistantMessageId)]);if(r.status===`rejected`)throw r.reason;return r.value.completed?`completed`:`cancelled`},or=async e=>{let t=await e.loadSession(e.sessionId);if(t.id!==e.sessionId)throw Error(`Reloaded chat session does not match the completed turn.`);if(!t.messages.find(t=>t.id===e.assistantMessageId&&t.role===`assistant`))throw Error(`Completed assistant message is absent from chat storage.`);return e.applySession(t),t},sr=async e=>{try{let t=await e.json(),n=typeof t.error==`string`?t.error:typeof t.message==`string`?t.message:void 0;if(n)return Error(n)}catch{}return Error(`Chat event request failed with status ${e.status}.`)},cr=()=>{let e=localStorage.getItem(`auth-token`);return e?{Authorization:`Bearer ${e}`}:{}},lr=async e=>{let t=await fetch(`${je}/chat/sessions/${encodeURIComponent(e.sessionId)}/generations`,{method:`POST`,headers:{"Content-Type":`application/json`,...cr()},credentials:`same-origin`,signal:e.signal,body:JSON.stringify({message:e.message,images:e.images,userMessageId:e.userMessageId,assistantMessageId:e.assistantMessageId,options:e.options,webSearch:e.webSearch,regenerate:e.regenerate===!0,originalMessageId:e.originalMessageId})});if(!t.ok)throw await sr(t);let n=await t.json();if(!n.data?.jobId)throw Error(`Chat generation response did not include a durable job.`);return n.data},ur=async(e,t)=>{if(!e.body)throw Error(`Chat event stream has no response body.`);let n=e.body.getReader(),r=new TextDecoder,i=``,a=0,o=!1,s=e=>{let n,r=[];for(let t of e.split(`
|
|
17
|
+
`))t.startsWith(`id:`)&&(n=Number(t.slice(3).trim())),t.startsWith(`data:`)&&r.push(t.slice(5).trimStart());if(!Number.isSafeInteger(n)||!r.length)return;let i=JSON.parse(r.join(`
|
|
18
|
+
`)),s=n,c=i.type===`done`||i.type===`error`;t(s,i),a=s,o=c};try{for(;;){let{done:e,value:t}=await n.read();i+=r.decode(t,{stream:!e}).replace(/\r\n/g,`
|
|
19
|
+
`);let a=i.indexOf(`
|
|
20
|
+
|
|
21
|
+
`);for(;a>=0;)s(i.slice(0,a)),i=i.slice(a+2),a=i.indexOf(`
|
|
22
|
+
|
|
23
|
+
`);if(e||o)break}}finally{await n.cancel().catch(()=>void 0),n.releaseLock()}return{cursor:a,terminal:o}},dr=async e=>{let t=0,n=0;for(;!e.signal.aborted;){let r=new URL(`${je}/chat/sessions/${encodeURIComponent(e.sessionId)}/events`,window.location.origin);r.searchParams.set(`after`,String(t)),r.searchParams.set(`generation`,e.assistantMessageId);try{let i=await fetch(r,{headers:{Accept:`text/event-stream`,...cr()},credentials:`same-origin`,cache:`no-store`,signal:e.signal});if(!i.ok)throw await sr(i);if((await ur(i,(n,r)=>{e.onEvent(r),t=n})).terminal)return;n=0}catch(t){if(e.signal.aborted||(n+=1,n>8))throw t}await new Promise((t,r)=>{let i=window.setTimeout(()=>{e.signal.removeEventListener(`abort`,a),t()},Math.min(5e3,n*500+250)),a=()=>{window.clearTimeout(i),e.signal.removeEventListener(`abort`,a),r(e.signal.reason??Error(`Chat stream cancelled`))};e.signal.addEventListener(`abort`,a,{once:!0})})}},fr=async e=>{let t=await fetch(`${je}/jobs/${encodeURIComponent(e)}/cancel`,{method:`POST`,headers:cr(),credentials:`same-origin`});if(!t.ok)throw await sr(t)},pr=async(e,t)=>{let n=await fetch(`${je}/chat/sessions/${encodeURIComponent(e)}/generations/${encodeURIComponent(t)}/cancel`,{method:`POST`,headers:cr(),credentials:`same-origin`});if(!n.ok)throw await sr(n);let r=(await n.json()).data;if(!r)throw Error(`Chat cancellation response did not include a decision.`);let i=typeof r.jobId==`string`?r.jobId:void 0;if(r.completed!==!0&&r.pending!==!0&&!i)throw Error(`Chat cancellation response did not include a decision.`);return{completed:r.completed===!0,pending:r.pending===!0,...i?{jobId:i}:{},...typeof r.state==`string`?{state:r.state}:{}}},$=G(`use-chat`),mr=new Set([`New Chat`,`New Demo Session`]),hr=e=>!e||mr.has(e),gr=e=>{let[t,n]=(0,X.useState)(``),[r,i]=(0,X.useState)(``),[a,o]=(0,X.useState)(null),[s,l]=(0,X.useState)(!1),[u,d]=(0,X.useState)([]),{addMessage:f,updateMessage:p,updateMessageWithStatistics:m,applySessionTitle:h,setGeneratingTitleForSession:g,removeMessage:_}=w(),{setIsGenerating:v}=We(),y=(0,X.useRef)(null),x=(0,X.useRef)(new Set),S=(0,X.useRef)(null),C=(0,X.useRef)(null),T=(0,X.useRef)(null),E=(0,X.useRef)(!1),D=(0,X.useRef)(null),O=(0,X.useRef)(``),k=(0,X.useRef)(``),A=(0,X.useRef)(0),j=(0,X.useRef)(void 0),M=(0,X.useRef)(null),N=(0,X.useRef)(``),ee=(0,X.useRef)(``),P=(0,X.useCallback)(()=>{M.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(M.current),M.current=null},[]),F=(0,X.useCallback)((e,t=!1,r=``)=>{if(N.current=e,ee.current=r,t||typeof window>`u`){P(),n(e),i(r);return}M.current===null&&(M.current=window.requestAnimationFrame(()=>{M.current=null,n(N.current),i(ee.current)}))},[P]),I=(0,X.useCallback)(()=>{P(),N.current=``,ee.current=``,n(``),i(``)},[P]),te=(0,X.useCallback)(async(e,t)=>{await or({sessionId:e,assistantMessageId:t,loadSession:async e=>{let t=await He.getSession(e);if(!t.success||!t.data)throw Error(t.error||`Completed chat session could not be reloaded.`);return t.data},applySession:e=>{w.setState(t=>({sessions:t.sessions.some(t=>t.id===e.id)?t.sessions.map(t=>t.id===e.id?e:t):[e,...t.sessions],currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}})},[]),R=(0,X.useCallback)(async(e,t,n,r={})=>{n.completed?await te(e,t):_(e,t),ir({assistantMessageId:t,cancelledMessageIds:x.current,decision:n,retainForContinuation:r.retainForContinuation})},[te,_]),z=(0,X.useCallback)(()=>{T.current=null,E.current=!1,D.current=null},[]),ne=(0,X.useCallback)(async e=>{let t=We.getState().preferences.titleSettings,n=T.current,r=E.current&&D.current===e;if($.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),!n||!r||!t?.autoTitle||!t?.taskModel){z();return}z(),$.debug(`Triggering auto-title generation...`),g(e);try{let r=await He.generateTitle(e,t.taskModel,n,t.taskProviderType,t.taskProviderId);if($.debug(`Title generation response:`,r),!r.success||!r.data?.title)throw Error(r.error||`Title generation returned no title`);h(e,r.data.title,r.data.updatedAt),r.data.source===`fallback`?L.error(`Could not generate a title; using the message preview`):L.success(`Chat title generated`)}catch(e){$.error(`Failed to generate title:`,e),L.error(`Failed to generate chat title`)}finally{g(null)}},[h,z,g]);(0,X.useEffect)(()=>{let t=x.current;return()=>{let n=y.current,r=C.current;if(r){let e=!r.jobId;nr(r,t),pr(r.sessionId,r.assistantMessageId).then(t=>R(r.sessionId,r.assistantMessageId,t,{retainForContinuation:e})).catch(e=>$.error(`Failed to cancel durable chat generation:`,e)),r.jobId&&fr(r.jobId).catch(e=>$.error(`Failed to cancel durable chat generation:`,e)),C.current=null}n&&e&&!r&&q.send({type:`chat_cancel`,data:{sessionId:e,assistantMessageId:n}}),q.offMessage(`user_message`),q.offMessage(`assistant_chunk`),q.offMessage(`assistant_complete`),q.offMessage(`assistant_cancelled`),q.offMessage(`tool_status`),q.offMessage(`error`)}},[e,R]),(0,X.useEffect)(()=>{if(!e){q.offMessage(`user_message`),q.offMessage(`assistant_chunk`),q.offMessage(`assistant_complete`),q.offMessage(`assistant_cancelled`),q.offMessage(`tool_status`),q.offMessage(`error`);return}return q.onMessage(`user_message`,()=>{}),q.onMessage(`assistant_chunk`,t=>{let n=t,r=n.messageId||y.current;r&&x.current.has(r)||r&&y.current&&r!==y.current||r&&(typeof n.total==`string`?O.current=n.total:typeof n.content==`string`&&(O.current+=n.content),typeof n.thinkingTotal==`string`?k.current=n.thinkingTotal:typeof n.thinking==`string`&&(k.current+=n.thinking),xt(r,O.current,k.current),F(O.current,n.done,k.current),j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{p(e,r,O.current),A.current=Date.now()},n.done?0:200))}),q.onMessage(`tool_status`,e=>{let t=e;d(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),q.onMessage(`assistant_complete`,t=>{let n=t;$.debug(`Hook: Received assistant_complete for session:`,e,`messageId:`,n.messageId,`with statistics:`,!!n.statistics);let r=n.messageId||y.current,i=!r||r===y.current;if(r&&x.current.delete(r),!i){if(n.truncated&&r){te(e,r);return}r&&m(e,r,n.content,n.statistics,n.providerMetadata,n.thinking);return}if(l(!1),I(),v(!1),d([]),n&&r){let t=O.current||n.content,i=k.current||n.thinking,a=Ct(r),o=n.statistics?.thinking_duration_ms===void 0&&a!==void 0?{...n.statistics,thinking_duration_ms:a}:n.statistics;m(e,r,t,o,n.providerMetadata,i)}ne(e),y.current=null,O.current=``,k.current=``,j.current&&clearTimeout(j.current),A.current=0}),q.onMessage(`assistant_cancelled`,t=>{let n=t,r=n.assistantMessageId;!r||n.sessionId!==e||x.current.has(r)&&(x.current.delete(r),_(e,r),y.current===r&&(l(!1),I(),o(null),v(!1),d([]),y.current=null,O.current=``,k.current=``))}),q.onMessage(`error`,e=>{let t=e;if(l(!1),I(),v(!1),y.current=null,k.current=``,t.code===`SESSION_NOT_FOUND`){$.warn(`Session not found, redirecting to create new session...`),L.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}L.error(t.error),z()}),l(!1),I(),y.current=null,k.current=``,()=>{j.current&&clearTimeout(j.current),P()}},[e,p,m,v,F,I,P,ne,z,_,te]);let B=(0,X.useCallback)(async(t,n,r,i)=>{if(!e||!t.trim()&&(!n||n.length===0))return;let a;try{let s=w.getState(),u=s.currentSession,d={model:u?.personaId?`persona:${u.personaId}`:u?.model||``,providerType:u?.providerType,providerId:u?.providerId};if(!b(s.models,d)){L.error(`Select an available model before sending`);return}v(!0),l(!0),I(),O.current=``,k.current=``,j.current&&clearTimeout(j.current),A.current=Date.now();let m=u?.isPrivate===!0,h=u?.messages?.some(e=>e.role===`user`);!m&&!h&&hr(u?.title)?(T.current=t.trim(),E.current=!0,D.current=e):(T.current=null,E.current=!1,D.current=null);let g=c();f(e,{id:g,role:`user`,content:t.trim(),images:n});let _=c();if(a=_,y.current=_,k.current=``,o(_),f(e,{role:`assistant`,content:``,id:_}),Ae()){let n=`Demo response for: ${t.trim()}`;S.current=window.setTimeout(()=>{S.current=null,!x.current.has(_)&&(p(e,_,n),l(!1),I(),o(null),v(!1),ne(e),y.current=null,O.current=``,k.current=``)},500);return}if(!m){let a=new AbortController,o={sessionId:e,assistantMessageId:_,abort:a};C.current=o;let s=await ar(o,await lr({sessionId:e,message:t.trim(),images:n,userMessageId:g,assistantMessageId:_,options:{...u?.settings?.generationOptions??{},...r===void 0?{}:{format:r}},webSearch:i===!0,signal:a.signal}));if(s!==`stream`){await R(e,_,{completed:s===`completed`,pending:!1,state:s===`completed`?`succeeded`:`cancelled`}),C.current===o&&(C.current=null);return}await dr({sessionId:e,assistantMessageId:_,signal:a.signal,onEvent:t=>{t.type===`chunk`?q.dispatchMessage(`assistant_chunk`,t):t.type===`done`?q.dispatchMessage(`assistant_complete`,t):t.type===`error`&&q.dispatchMessage(`error`,{...t,sessionId:e})}}),C.current?.assistantMessageId===_&&(C.current=null);return}q.isConnected||await q.connect();let M=m?u?.messages?.filter(e=>e.role!==`system`&&e.id!==_).map(e=>({role:e.role,content:e.content,thinking:e.thinking,images:e.images,providerMetadata:e.providerMetadata})):void 0;q.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:n,format:r,options:u?.settings?.generationOptions??{},assistantMessageId:_,isPrivate:m,...i===!0?{webSearch:!0}:{},...m?{model:u?.model,providerType:u?.providerType,providerId:u?.providerId,messageHistory:M}:{}}})}catch(t){let n=a;if(n&&await rr({sessionId:e,assistantMessageId:n,cancelledMessageIds:x.current,settle:t=>R(e,n,t),onError:e=>$.error(`Failed to resolve cancelled durable chat generation:`,e)})){C.current?.assistantMessageId===n&&(C.current=null);return}if(t instanceof DOMException&&t.name===`AbortError`)return;$.error(`Failed to send message:`,t),l(!1),I(),o(null),v(!1),y.current=null,k.current=``,L.error(`Failed to send message`)}},[e,f,p,v,I,ne,R]),re=(0,X.useCallback)(()=>{let t=y.current;if(t)if(x.current.add(t),S.current!==null)window.clearTimeout(S.current),S.current=null,_(e,t),x.current.delete(t);else if(C.current?.assistantMessageId===t){let n=C.current,r=!n.jobId;nr(n),pr(e,t).then(async i=>{await R(e,t,i,{retainForContinuation:r}),C.current===n&&(C.current=null)}).catch(e=>$.error(`Failed to cancel durable chat generation:`,e)),n.jobId&&fr(n.jobId).catch(e=>$.error(`Failed to cancel durable chat generation:`,e))}else q.send({type:`chat_cancel`,data:{sessionId:e,assistantMessageId:t}})||(_(e,t),x.current.delete(t));j.current&&(clearTimeout(j.current),j.current=void 0),l(!1),I(),o(null),v(!1),y.current=null,O.current=``,k.current=``,z()},[v,I,_,e,z,R]),ie=(0,X.useCallback)(async()=>{let t=w.getState(),n=t.currentSession;if(!n||!e)return;if(!b(t.models,{model:n.personaId?`persona:${n.personaId}`:n.model,providerType:n.providerType,providerId:n.providerId})){L.error(`Select an available model before regenerating`);return}let r=n.messages,i=-1,a=-1;for(let e=r.length-1;e>=0;e--)if(r[e].role===`assistant`){a=e;break}if(a>0){for(let e=a-1;e>=0;e--)if(r[e].role===`user`){i=e;break}}if(i===-1||a===-1){L.error(`No message to regenerate`);return}let s=r[i],u=r[a],d;try{v(!0),l(!0),I(),O.current=``,k.current=``,j.current&&clearTimeout(j.current),A.current=Date.now();let t=c();d=t,y.current=t,k.current=``,o(t),f(e,{role:`assistant`,content:``,id:t,parentId:u.parentId||u.id,branchIndex:u.siblingCount||1,isActive:!0});let i=n.isPrivate===!0;if(!i){let r=new AbortController,i={sessionId:e,assistantMessageId:t,abort:r};C.current=i;let a=await ar(i,await lr({sessionId:e,message:s.content,images:s.images,userMessageId:s.id,assistantMessageId:t,options:n.settings?.generationOptions??{},webSearch:!1,regenerate:!0,originalMessageId:u.id,signal:r.signal}));if(a!==`stream`){await R(e,t,{completed:a===`completed`,pending:!1,state:a===`completed`?`succeeded`:`cancelled`}),C.current===i&&(C.current=null);return}await dr({sessionId:e,assistantMessageId:t,signal:r.signal,onEvent:t=>{t.type===`chunk`?q.dispatchMessage(`assistant_chunk`,t):t.type===`done`?q.dispatchMessage(`assistant_complete`,t):t.type===`error`&&q.dispatchMessage(`error`,{...t,sessionId:e})}}),C.current?.assistantMessageId===t&&(C.current=null);return}q.isConnected||await q.connect();let a=i?r.filter(e=>e.role!==`system`).map(e=>({role:e.role,content:e.content,thinking:e.thinking,images:e.images,providerMetadata:e.providerMetadata})):void 0;q.send({type:`chat_stream`,data:{sessionId:e,content:s.content,images:s.images,options:n.settings?.generationOptions??{},assistantMessageId:t,regenerate:!0,originalMessageId:u.id,isPrivate:i,...i?{model:n.model,providerType:n.providerType,providerId:n.providerId,messageHistory:a}:{}}})}catch(t){let n=d;if(n&&await rr({sessionId:e,assistantMessageId:n,cancelledMessageIds:x.current,settle:t=>R(e,n,t),onError:e=>$.error(`Failed to resolve cancelled durable chat regeneration:`,e)})){C.current?.assistantMessageId===n&&(C.current=null);return}$.error(`Failed to regenerate message:`,t),l(!1),I(),o(null),v(!1),y.current=null,k.current=``,L.error(`Failed to regenerate message`)}},[e,v,I,f,R]),ae=(0,X.useCallback)(async t=>{let n=w.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){L.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await He.switchMessageBranch(e,t,a);if(r.success&&r.data){let r=n.messages.map(e=>e.id===i||e.parentId===i?{...e,isActive:e.id===t}:e),o={...n,messages:r,updatedAt:Date.now()};w.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),L.success(`Switched to variant ${a+1}`)}else L.error(r.error||`Failed to select branch`)}catch(e){$.error(`Failed to select branch:`,e),L.error(`Failed to select branch`)}},[e]);return{sendMessage:B,stopGeneration:re,regenerateLastMessage:ie,editAndResendMessage:(0,X.useCallback)(async(t,n)=>{if(!e||!n.trim())return;let r=w.getState(),i=r.currentSession;if(!i||i.id!==e)return;let a=i.messages.findIndex(e=>e.id===t);if(a===-1||i.messages[a].role!==`user`)return;let o=i.messages[a],s=i.messages.slice(0,a);try{i.isPrivate||await He.updateSession(e,{messages:s}),r.truncateMessagesFrom(e,t),await B(n,o.images)}catch(e){$.error(`Failed to edit message:`,e),L.error(`Failed to edit message`)}},[e,B]),selectBranch:ae,isStreaming:s,streamingMessage:t,streamingThinking:r,streamingMessageId:a,toolActivities:u}},_r=G(`pages:chat-page`),vr=(e,t,n=!1)=>{let r=new Date().getHours(),i=e?`${n?`،`:`,`} \u2068${e}\u2069`:``;return r>=5&&r<12?{id:`time`,title:`${t?t(`chat.greeting.morning`):`Good morning`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=12&&r<17?{id:`time`,title:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=17&&r<21?{id:`time`,title:`${t?t(`chat.greeting.evening`):`Good evening`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}:{id:`time`,title:`${t?t(`chat.greeting.night`):`Good night`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}},yr=(e,t,n,r=!1)=>{let i=Ke(e);return i===`time`?vr(t,n,r):{id:i,title:n?n(`chat.welcome.variety.${i}.title`):`What should we make?`,subtitle:n?n(`chat.welcome.variety.${i}.subtitle`):`Start with a thought, a sketch, or a stubborn problem.`}},br=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),l=o(),{currentSession:u,sessions:d,models:m,selectedModel:v,selectedProviderType:x,selectedProviderId:S,setSelectedModel:C,createSession:E,setCurrentSession:D,loadSessions:O,getCurrentPersona:k}=w(),{user:A}=Ue(),M=We(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:ee,stopGeneration:P,regenerateLastMessage:I,editAndResendMessage:te,selectBranch:R,isStreaming:z,streamingMessage:B,streamingThinking:re,streamingMessageId:ie,toolActivities:ae}=gr(u?.id||``),oe=k(),V=(0,X.useMemo)(()=>({model:v,providerType:x,providerId:S}),[v,S,x]),ce=(0,X.useMemo)(()=>_(m,V),[m,V]),le=v?g(ce,V):``,ue=b(m,V),de=new URLSearchParams(l.search).get(`incognito`)===`1`,[fe,H]=(0,X.useState)(Ge),[pe,U]=(0,X.useState)(null),[ge,W]=(0,X.useState)(!1),_e=We(e=>e.preferences.showFollowUpSuggestions!==!1),ve=(0,X.useRef)(null),ye=(0,X.useRef)(!1);(0,X.useEffect)(()=>{let e=u?.id,t=ye.current&&!z;if(ye.current=z,!e||z||!_e||u?.isPrivate||!t)return;let n=u.messages[u.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||ve.current===n.id)return;ve.current=n.id;let r=!1;return He.generateFollowUps(e).then(t=>{r||!t.success||w.getState().currentSession?.id===e&&U({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[z,u,_e]);let be=pe&&pe.sessionId===u?.id?pe.suggestions:[],xe=(0,X.useMemo)(()=>yr(fe,A?.username,e,p(t.language)),[t.language,e,A?.username,fe]),[Se,Ce]=(0,X.useState)(``),[we,Te]=(0,X.useState)([]),[Ee,De]=(0,X.useState)(!1),[Oe,ke]=(0,X.useState)(!1),[Ae,G]=(0,X.useState)(!1),je=(0,X.useRef)(null),Ne=w(e=>e.draftSessionSettings),Fe=w(e=>e.setDraftSessionSettings),Ie=Ne.generationOptions?.think,Re=We(e=>(v?e.preferences.modelGenerationOptions?.[v]?.think:void 0)??e.preferences.generationOptions?.think??null),K=(0,X.useMemo)(()=>m.find(e=>e.name===v),[m,v]),[ze,Be]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!v||m.length===0||!K||K.isPlugin||K.isAgent)return;let e=!1;return Le.getModelDefaults(v).then(t=>{e||!t.success||!t.data||Be({model:v,supported:t.data.supportsThinking})}).catch(()=>{}),()=>{e=!0}},[v,K,m.length]);let q=!!(v&&!K?.isAgent&&(K?.isPlugin?K.reasoningSupport!==!1:ze?.model!==v||ze.supported!==!1)),Ke=e=>{let t=w.getState().draftSessionSettings,n={...t.generationOptions};e===null?delete n.think:n.think=e,Fe({...t,generationOptions:Object.keys(n).length?n:void 0})},Ye=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){G(!0);try{let t=await Me.uploadDocument(n);t.success?(L.success(e(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):L.error(t.error||e(`chat.input.menu.attachFailed`))}catch(t){_r.error(`Document upload failed:`,t),L.error(e(`chat.input.menu.attachFailed`))}finally{G(!1)}}};(0,X.useEffect)(()=>{let e=!1;return Pe.getConfig().then(t=>{!e&&t.success&&t.data&&De(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[Xe,Y]=(0,X.useState)(!1),Ze=(0,X.useRef)(null);(0,X.useEffect)(()=>{let e=()=>{H(Ge())};return window.addEventListener(qe,e),()=>window.removeEventListener(qe,e)},[]);let[Qe,et]=(0,X.useState)(!1),tt=M&&Qe,nt=(0,X.useCallback)((t=!0)=>{let n=v?V:m[0]?T(m[0]):null;if(!n||!b(m,n))return t&&L.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return D({id:`private-${r}`,title:e(`chat.session.incognito`,`Incognito Chat`),model:n.model,providerType:n.providerType,providerId:n.providerId,messages:[],createdAt:r,updatedAt:r,isPrivate:!0}),!0},[m,v,V,D,e]);(0,X.useEffect)(()=>{d.length===0&&O()},[O,d.length]),(0,X.useEffect)(()=>{!de||u?.isPrivate||nt(!1)},[u?.isPrivate,de,nt]),(0,X.useEffect)(()=>{let e=!1;return M&&(async()=>{try{let t=await Ve.getPlugins();if(e)return;et(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;et(!1)}})(),()=>{e=!0}},[M]),(0,X.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!(u?.isPrivate&&!n)&&d.length!==0)if(n){let e=d.find(e=>e.id===n);e&&e.id!==u?.id?D(e):e||(_r.warn(`Session ${n} not found for current user, redirecting...`),d.length>0?r(`/c/${d[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&d.length>0&&l.pathname===`/`&&r(`/c/${d[0].id}`,{replace:!0})})()},[n,d,D,r,u?.id,u?.isPrivate,l.pathname]),(0,X.useEffect)(()=>{if(u?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{ee(t.content,t.images,void 0,t.webSearch===!0)},100)}catch(e){_r.error(`Failed to parse pending message:`,e)}}}},[u?.id,ee]),(0,X.useEffect)(()=>{let e=Ze.current;e&&(e.style.height=`auto`,e.style.height=Se?`${Math.min(e.scrollHeight,200)}px`:``)},[Se]);let rt=async t=>{if(t.preventDefault(),!Se.trim()||!v)return;if(!ue){L.error(e(`chat.model.selectBeforeSending`));return}Je(`impact`);let n={content:Se.trim(),images:we.length>0?we:void 0,webSearch:Ee&&Oe?!0:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),Ce(``),Te([]),ke(!1);let i=await E(v,void 0,v.startsWith(`persona:`)?v.slice(8):void 0,x,S);i&&(await it(i),r(`/c/${i.id}`,{replace:!0}))},it=(0,X.useCallback)(async e=>{let t=w.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions;if(!n&&!r)return;let i=n?[{id:c(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await He.updateSession(e.id,{messages:i,settings:r?{generationOptions:r}:void 0});if(t.success&&t.data){let e=t.data;w.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){_r.error(`Failed to apply chat settings to the new session`,e)}finally{w.getState().setDraftSessionSettings({})}},[]),at=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),rt(e))},ot=async e=>{let t=y(ce,e.target.value);t&&C(t.model,t.providerType,t.providerId)},st=(e,t,n,r)=>{u&&(Je(`impact`),U(null),ee(e,t,n,r))};if(!u){let t=we.length>0;return(0,Z.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`relative h-full min-w-0 flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,Z.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,Z.jsx)(`div`,{className:`absolute left-[12%] top-[18%] h-56 w-56 rounded-full bg-primary-500/[0.035] blur-3xl dark:bg-primary-400/[0.04]`}),(0,Z.jsx)(`div`,{className:`absolute bottom-[16%] right-[10%] h-72 w-72 rounded-full bg-gray-900/[0.025] blur-3xl dark:bg-white/[0.025]`}),(0,Z.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,Z.jsx)(`button`,{onClick:()=>W(e=>!e),className:f(`absolute end-4 top-4 z-10 flex h-9 w-9 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-6 sm:top-6`,ge&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ge,children:(0,Z.jsx)(he,{className:`h-4 w-4`})}),(0,Z.jsxs)(`button`,{onClick:()=>nt(),disabled:!v&&m.length===0||!!v&&!ue,className:`absolute end-[3.75rem] top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-surface/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-[4.25rem] sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,Z.jsx)(me,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{children:e(`chat.session.incognito`,`Incognito Chat`)})]}),(0,Z.jsxs)(`div`,{className:`relative z-[1] mx-auto flex min-h-full w-full max-w-3xl flex-col items-center justify-center`,children:[(0,Z.jsxs)(`div`,{className:`mb-8 flex flex-col items-center text-center animate-fade-in sm:mb-10`,"aria-live":`polite`,children:[(0,Z.jsxs)(`div`,{className:`mb-3 flex items-center justify-center gap-3`,children:[(0,Z.jsx)($e,{size:`sm`,label:null,className:`h-9 w-9 shrink-0 p-0 text-ink`}),(0,Z.jsx)(`h1`,{className:`max-w-3xl text-balance text-[clamp(1.75rem,3.5vw,2.35rem)] font-medium leading-tight tracking-[-0.02em] text-ink rtl:tracking-normal`,children:xe.title})]}),(0,Z.jsx)(`p`,{className:`max-w-xl text-balance text-[15px] leading-relaxed text-ink-subtle`,children:xe.subtitle})]},xe.id),ce.length>0?(0,Z.jsxs)(`div`,{className:`w-full`,children:[Xe&&(0,Z.jsxs)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:[(0,Z.jsx)(tr,{images:we,onImagesChange:Te,maxImages:5}),(0,Z.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 border-t border-black/[0.06] pt-3 dark:border-white/[0.07]`,children:[(0,Z.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:e(`chat.input.menu.attachDocument`)}),(0,Z.jsxs)(J,{type:`button`,size:`sm`,variant:`outline`,disabled:Ae,onClick:()=>je.current?.click(),className:`shrink-0 whitespace-nowrap`,children:[(0,Z.jsx)(ne,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`ms-1.5`,children:e(Ae?`documents.uploading`:`chat.input.menu.attach`)})]}),(0,Z.jsx)(`input`,{ref:je,type:`file`,accept:`.pdf,.txt`,className:`hidden`,onChange:e=>void Ye(e)})]})]}),(0,Z.jsx)(`form`,{onSubmit:rt,children:(0,Z.jsxs)(`div`,{className:f(`rounded-[24px] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200`,`border-black/[0.08] bg-surface dark:border-white/[0.09] dark:bg-surface-subtle`,`shadow-lv2 focus-within:shadow-lv3`),children:[(0,Z.jsx)(En,{ref:Ze,value:Se,onChange:e=>Ce(e.target.value),onKeyDown:at,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 block w-full min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-2 !pt-1.5 !pb-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Y(!Xe),className:f(`h-9 w-9 !p-0 rounded-full flex-shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,Xe&&`bg-hover-solid text-ink`),title:e(`chat.input.attachImages`),children:t?(0,Z.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,Z.jsx)(ne,{className:`h-4 w-4`}),(0,Z.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):Xe?(0,Z.jsx)(se,{className:`h-4 w-4`}):(0,Z.jsx)(F,{className:`h-4 w-4`})}),q&&(0,Z.jsx)(Pn,{value:Ie,inheritedValue:Re,onChange:Ke}),Ee&&(0,Z.jsx)(J,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ke(e=>!e),className:f(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,Oe&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:e(Oe?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":Oe,children:(0,Z.jsx)(N,{className:`h-4 w-4`})}),(0,Z.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,Z.jsx)(`div`,{className:`hidden sm:block`,children:(0,Z.jsx)(dt,{models:ce,selectedModel:le,onModelChange:ot,getModelValue:h,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:tt})}),(0,Z.jsx)(J,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!Se.trim()||!v||!ue,className:f(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-primary-500 text-white hover:bg-primary-400`,`disabled:bg-primary-300/50 disabled:text-white/80 dark:disabled:bg-primary-800/60 dark:disabled:text-white/40 disabled:hover:bg-primary-300/50 dark:disabled:hover:bg-primary-800/60`,`transition-colors duration-150 touch-manipulation`),title:e(`chat.input.sendMessage`),children:(0,Z.jsx)(j,{className:`h-4 w-4`})})]})]})}),(0,Z.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,Z.jsx)(dt,{models:ce,selectedModel:le,onModelChange:ot,getModelValue:h,className:`w-full`,compact:!0,showImageGen:tt})}),(0,Z.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,Z.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,Z.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.07] bg-surface/70 p-6 backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/70`,children:[(0,Z.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,Z.jsx)(`code`,{className:`block rounded-xl bg-gray-100 p-3 font-mono text-xs text-gray-800 dark:bg-dark-300 dark:text-dark-700`,children:e(`chat.model.pullCommand`)})]})})]})]}),(0,Z.jsx)(Yn,{draftModel:v,open:ge,onClose:()=>W(!1)})]})}return(0,Z.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:oe?.background?{backgroundImage:`url(${oe.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[oe?.background&&(0,Z.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,Z.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[u?.isPrivate&&(0,Z.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,Z.jsx)(me,{className:`h-3.5 w-3.5`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,Z.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),oe&&!u?.isPrivate&&(0,Z.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,Z.jsx)(er,{persona:oe,onClear:()=>{u&&He.updateSession(u.id,{model:oe.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);w.setState(t=>({sessions:t.sessions.map(t=>t.id===u.id?e.data:t),currentSession:e.data}))}).catch(t=>{_r.error(`Failed to remove persona:`,t),L.error(e(`chat.persona.removeFailed`))})}})}),(0,Z.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,Z.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,Z.jsx)(`button`,{onClick:()=>W(e=>!e),className:f(`absolute end-3 top-3 z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950`,ge&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ge,children:(0,Z.jsx)(he,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(wn,{messages:u.messages,streamingMessage:B,streamingThinking:re,streamingMessageId:ie,isStreaming:z,toolActivities:ae,onRegenerate:I,onSelectBranch:R,onEditResend:te,followUpSuggestions:be,onFollowUpSelect:e=>st(e),className:`flex-1`}),(0,Z.jsx)(Kn,{onSendMessage:st,onStopGeneration:P,disabled:!u})]}),u&&(0,Z.jsx)($n,{session:u}),(0,Z.jsx)(Yn,{session:u,open:ge,onClose:()=>W(!1)})]})]})]})};export{br as ChatPage,br as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./useTranslation-Bho4HCyg.js";import{A as i,Dt as a,Gt as o,Wt as s,Zt as ee,_t as c,fn as l,jn as u,l as d,m as f,t as p,wn as m}from"./ui-vendor-mqjSfAaS.js";import{t as h}from"./logger-DSXjF4ye.js";import{D as g}from"./api-DGVZHSkS.js";import{n as _}from"./authStore-B97lJ5Ee.js";import{g as v,h as y,i as b,n as x,r as S}from"../assets/index-CDQ12KBq.js";var C=e(t(),1),w=n(),T=h(`components:first-time-setup`),E=({onComplete:e})=>{let{t}=r(),[n,h]=(0,C.useState)(`welcome`),[E,D]=(0,C.useState)(``),[O,k]=(0,C.useState)(``),[A,j]=(0,C.useState)(``),[M,N]=(0,C.useState)(!1),[P,F]=(0,C.useState)(!1),[I,L]=(0,C.useState)(!1),[R,z]=(0,C.useState)(null),[B,V]=(0,C.useState)(!1),[H,U]=(0,C.useState)(!1),[W,G]=(0,C.useState)(``),{login:K,systemInfo:q}=_(),J=q?.turnstile?.siteKey,Y=!!(q?.turnstile?.enabled&&J),X=(0,C.useCallback)(e=>{G(e)},[]),Z=(0,C.useMemo)(()=>I||Y&&!W,[I,Y,W]);(0,C.useEffect)(()=>{n===`encryption-key`&&!R&&g.getEncryptionKey().then(e=>{e.success&&e.data&&z(e.data.encryptionKey)})},[n,R]);let Q=async e=>{if(e.preventDefault(),!E.trim()||!O.trim()||!A.trim()){u.error(t(`setup.admin.fillAllFields`));return}if(O!==A){u.error(t(`auth.signup.passwordMismatch`));return}let n=S(O);if(n){u.error(n);return}if(Y&&!W){u.error(t(`auth.signup.tryAgain`));return}L(!0);try{let e=await g.signup({username:E,password:O,email:``,turnstileToken:W});if(e.success&&e.data){if(!(`token`in e.data)){u.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}K(e.data.user,e.data.token,e.data.systemInfo),u.success(t(`setup.admin.success`)),h(`encryption-key`)}else u.error(e.message||t(`setup.admin.failed`))}catch(e){T.error(`Admin creation error:`,e),u.error(t(`setup.admin.failed`))}finally{G(``),L(!1)}},te=async()=>{if(R)try{await navigator.clipboard.writeText(R),V(!0),u.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>V(!1),3e3)}catch{u.error(t(`setup.encryptionKey.copyFailed`))}},ne=()=>{if(!H){u.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(v,{})]})}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,w.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(i,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(p,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(a,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,w.jsx)(`button`,{onClick:()=>h(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,w.jsx)(m,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(v,{})]}),(0,w.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,w.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,w.jsx)(c,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,w.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,w.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,w.jsx)(f,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,w.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,w.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,w.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,w.jsxs)(`div`,{className:`mb-6`,children:[(0,w.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:R||t(`setup.encryptionKey.loading`)}),(0,w.jsx)(`button`,{type:`button`,onClick:te,disabled:!R,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:B?(0,w.jsx)(l,{className:`h-5 w-5 text-green-500`}):(0,w.jsx)(ee,{className:`h-5 w-5`})})]}),(0,w.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,w.jsx)(`div`,{className:`mb-6`,children:(0,w.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>U(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,w.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,w.jsx)(`button`,{onClick:ne,disabled:!H,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,w.jsx)(m,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(v,{})]}),(0,w.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,w.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,w.jsx)(`input`,{id:`username`,type:`text`,value:E,onChange:e=>D(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:I})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`input`,{id:`password`,type:M?`text`:`password`,value:O,onChange:e=>k(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:I}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:M?(0,w.jsx)(o,{size:20}):(0,w.jsx)(s,{size:20})})]}),(0,w.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:x})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`input`,{id:`confirmPassword`,type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:I}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:P?(0,w.jsx)(o,{size:20}):(0,w.jsx)(s,{size:20})})]})]}),Y&&J&&(0,w.jsx)(b,{siteKey:J,action:`signup`,disabled:I,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:X}),(0,w.jsxs)(`div`,{className:`flex gap-3`,children:[(0,w.jsx)(`button`,{type:`button`,onClick:()=>h(`welcome`),disabled:I,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,w.jsx)(`button`,{type:`submit`,disabled:Z,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:I?(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(d,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,w.jsx)(`div`,{className:`mt-6 text-center`,children:(0,w.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{E as FirstTimeSetup};
|