libre-webui 0.19.6 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -22
- package/backend/dist/db.d.ts.map +1 -1
- package/backend/dist/db.js +31 -0
- package/backend/dist/db.js.map +1 -1
- package/backend/dist/index.d.ts.map +1 -1
- package/backend/dist/index.js +14 -10
- package/backend/dist/index.js.map +1 -1
- package/backend/dist/routes/chat.d.ts.map +1 -1
- package/backend/dist/routes/chat.js +97 -10
- package/backend/dist/routes/chat.js.map +1 -1
- package/backend/dist/routes/libreClaw.d.ts.map +1 -1
- package/backend/dist/routes/libreClaw.js +41 -0
- package/backend/dist/routes/libreClaw.js.map +1 -1
- package/backend/dist/routes/ollama.d.ts.map +1 -1
- package/backend/dist/routes/ollama.js +52 -2
- package/backend/dist/routes/ollama.js.map +1 -1
- package/backend/dist/routes/search.d.ts +3 -0
- package/backend/dist/routes/search.d.ts.map +1 -0
- package/backend/dist/routes/search.js +143 -0
- package/backend/dist/routes/search.js.map +1 -0
- package/backend/dist/routes/work.d.ts.map +1 -1
- package/backend/dist/routes/work.js +138 -4
- package/backend/dist/routes/work.js.map +1 -1
- package/backend/dist/services/agentAccessService.d.ts +6 -0
- package/backend/dist/services/agentAccessService.d.ts.map +1 -0
- package/backend/dist/services/agentAccessService.js +58 -0
- package/backend/dist/services/agentAccessService.js.map +1 -0
- package/backend/dist/services/agentCliService.d.ts.map +1 -1
- package/backend/dist/services/agentCliService.js +2 -1
- package/backend/dist/services/agentCliService.js.map +1 -1
- package/backend/dist/services/authService.d.ts +1 -0
- package/backend/dist/services/authService.d.ts.map +1 -1
- package/backend/dist/services/authService.js +2 -0
- package/backend/dist/services/authService.js.map +1 -1
- package/backend/dist/services/documentService.d.ts +2 -0
- package/backend/dist/services/documentService.d.ts.map +1 -1
- package/backend/dist/services/documentService.js +51 -23
- package/backend/dist/services/documentService.js.map +1 -1
- package/backend/dist/services/modelAccessService.d.ts +12 -0
- package/backend/dist/services/modelAccessService.d.ts.map +1 -0
- package/backend/dist/services/modelAccessService.js +66 -0
- package/backend/dist/services/modelAccessService.js.map +1 -0
- package/backend/dist/services/systemDiagnosticsService.d.ts +4 -3
- package/backend/dist/services/systemDiagnosticsService.d.ts.map +1 -1
- package/backend/dist/services/systemDiagnosticsService.js +35 -34
- package/backend/dist/services/systemDiagnosticsService.js.map +1 -1
- package/backend/dist/services/webSearchService.d.ts +64 -0
- package/backend/dist/services/webSearchService.d.ts.map +1 -0
- package/backend/dist/services/webSearchService.js +230 -0
- package/backend/dist/services/webSearchService.js.map +1 -0
- package/backend/dist/services/workAccessService.d.ts +15 -0
- package/backend/dist/services/workAccessService.d.ts.map +1 -0
- package/backend/dist/services/workAccessService.js +67 -0
- package/backend/dist/services/workAccessService.js.map +1 -0
- package/backend/dist/services/workAdminService.d.ts +67 -0
- package/backend/dist/services/workAdminService.d.ts.map +1 -0
- package/backend/dist/services/workAdminService.js +92 -0
- package/backend/dist/services/workAdminService.js.map +1 -0
- package/backend/dist/services/workAgentGuidance.d.ts +1 -0
- package/backend/dist/services/workAgentGuidance.d.ts.map +1 -1
- package/backend/dist/services/workAgentGuidance.js +3 -0
- package/backend/dist/services/workAgentGuidance.js.map +1 -1
- package/backend/dist/services/workAgentService.d.ts +6 -0
- package/backend/dist/services/workAgentService.d.ts.map +1 -1
- package/backend/dist/services/workAgentService.js +199 -11
- package/backend/dist/services/workAgentService.js.map +1 -1
- package/backend/dist/services/workKubernetesDriver.d.ts +74 -0
- package/backend/dist/services/workKubernetesDriver.d.ts.map +1 -0
- package/backend/dist/services/workKubernetesDriver.js +659 -0
- package/backend/dist/services/workKubernetesDriver.js.map +1 -0
- package/backend/dist/services/workPolicyService.d.ts +58 -0
- package/backend/dist/services/workPolicyService.d.ts.map +1 -0
- package/backend/dist/services/workPolicyService.js +299 -0
- package/backend/dist/services/workPolicyService.js.map +1 -0
- package/backend/dist/services/workPreviewProxyService.d.ts +7 -1
- package/backend/dist/services/workPreviewProxyService.d.ts.map +1 -1
- package/backend/dist/services/workPreviewProxyService.js +36 -8
- package/backend/dist/services/workPreviewProxyService.js.map +1 -1
- package/backend/dist/services/workRuntimeDriver.d.ts +166 -0
- package/backend/dist/services/workRuntimeDriver.d.ts.map +1 -0
- package/backend/dist/services/workRuntimeDriver.js +737 -0
- package/backend/dist/services/workRuntimeDriver.js.map +1 -0
- package/backend/dist/services/workRuntimeService.d.ts +60 -51
- package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
- package/backend/dist/services/workRuntimeService.js +310 -658
- package/backend/dist/services/workRuntimeService.js.map +1 -1
- package/backend/dist/services/workRuntimeShared.d.ts +83 -0
- package/backend/dist/services/workRuntimeShared.d.ts.map +1 -0
- package/backend/dist/services/workRuntimeShared.js +136 -0
- package/backend/dist/services/workRuntimeShared.js.map +1 -0
- package/backend/dist/services/workTaskService.d.ts +6 -1
- package/backend/dist/services/workTaskService.d.ts.map +1 -1
- package/backend/dist/services/workTaskService.js +18 -3
- package/backend/dist/services/workTaskService.js.map +1 -1
- package/backend/dist/services/workTerminalService.d.ts +2 -22
- package/backend/dist/services/workTerminalService.d.ts.map +1 -1
- package/backend/dist/services/workTerminalService.js +10 -127
- package/backend/dist/services/workTerminalService.js.map +1 -1
- package/backend/dist/storage.d.ts.map +1 -1
- package/backend/dist/storage.js +3 -3
- package/backend/dist/storage.js.map +1 -1
- package/backend/dist/storageMappers.d.ts +1 -0
- package/backend/dist/storageMappers.d.ts.map +1 -1
- package/backend/dist/storageMappers.js +1 -0
- package/backend/dist/storageMappers.js.map +1 -1
- package/backend/dist/types/index.d.ts +1 -0
- package/backend/dist/types/index.d.ts.map +1 -1
- package/backend/dist/types/index.js.map +1 -1
- package/backend/dist/types/work.d.ts +4 -0
- package/backend/dist/types/work.d.ts.map +1 -1
- package/backend/dist/utils/chatDocumentContext.d.ts +7 -0
- package/backend/dist/utils/chatDocumentContext.d.ts.map +1 -1
- package/backend/dist/utils/chatDocumentContext.js +38 -30
- package/backend/dist/utils/chatDocumentContext.js.map +1 -1
- package/backend/dist/utils/dockerEndpoint.d.ts +37 -0
- package/backend/dist/utils/dockerEndpoint.d.ts.map +1 -0
- package/backend/dist/utils/dockerEndpoint.js +72 -0
- package/backend/dist/utils/dockerEndpoint.js.map +1 -0
- package/backend/dist/websocketServer.d.ts.map +1 -1
- package/backend/dist/websocketServer.js +79 -15
- package/backend/dist/websocketServer.js.map +1 -1
- package/backend/dist/workTerminalServer.d.ts.map +1 -1
- package/backend/dist/workTerminalServer.js +6 -5
- package/backend/dist/workTerminalServer.js.map +1 -1
- package/backend/package.json +2 -1
- package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
- package/frontend/dist/assets/index-0wfi-EpC.js +40 -0
- package/frontend/dist/assets/index-D7m1zWWg.css +1 -0
- package/frontend/dist/index.html +12 -11
- package/frontend/dist/js/ArtifactContainer-DPRPcuES.js +1 -0
- package/frontend/dist/js/{ArtifactDemoPage-Big00RwH.js → ArtifactDemoPage-DzwPlz9J.js} +1 -1
- package/frontend/dist/js/{ArtifactSandboxFrame-C_S4j076.js → ArtifactSandboxFrame-CKi4mSTH.js} +2 -2
- package/frontend/dist/js/{ArtifactSlideOutPanel-B4-D3HkB.js → ArtifactSlideOutPanel-BskRCzP0.js} +1 -1
- package/frontend/dist/js/ChatPage-DRutCyJ5.js +16 -0
- package/frontend/dist/js/FirstTimeSetup-DU50YWrE.js +1 -0
- package/frontend/dist/js/GalleryPage-DxXIUesf.js +1 -0
- package/frontend/dist/js/HomePage-Bew9kMKx.js +1 -0
- package/frontend/dist/js/{LibreClawPage-B14Go5Mn.js → LibreClawPage-Cy9y3YlF.js} +1 -1
- package/frontend/dist/js/{ModelManagerModals-D9j9RECi.js → ModelManagerModals-D-NxeVvV.js} +1 -1
- package/frontend/dist/js/ModelSelector-DXDcDmDR.js +1 -0
- package/frontend/dist/js/ModelsPage-Bj2reiF9.js +2 -0
- package/frontend/dist/js/{NotesPage-BwEMW-Z3.js → NotesPage-CJKEbj3J.js} +1 -1
- package/frontend/dist/js/{PersonasPage-e-CbTxP3.js → PersonasPage-bgWF9S7b.js} +2 -2
- package/frontend/dist/js/{PluginUsagePage-CvZMJJwv.js → PluginUsagePage-CRkD1Tz6.js} +1 -1
- package/frontend/dist/js/{RichMessageContent-DNl3_CIw.js → RichMessageContent-DeNjCiyN.js} +1 -1
- package/frontend/dist/js/SettingsModal-BUUlkZcv.js +1 -0
- package/frontend/dist/js/SettingsToggle-bZ5W4CCf.js +1 -0
- package/frontend/dist/js/SystemPage-DcO51urv.js +1 -0
- package/frontend/dist/js/UserManagementPage-DLiYw6xG.js +1 -0
- package/frontend/dist/js/WorkPage-MMQ0Y0U5.js +5 -0
- package/frontend/dist/js/api-CZURQtuc.js +14 -0
- package/frontend/dist/js/{appStore-BpoXhleX.js → appStore-sGaWMSDr.js} +2 -2
- package/frontend/dist/js/ar-Bm27TCMQ.js +2 -0
- package/frontend/dist/js/authStore-uaj0hswV.js +4 -0
- package/frontend/dist/js/bn-C7CHC42H.js +2 -0
- package/frontend/dist/js/{chatStore-CWqfsOjc.js → chatStore-tRx0Ulq0.js} +2 -2
- package/frontend/dist/js/{config-CuXlcWP1.js → config-D-jxRG52.js} +1 -1
- package/frontend/dist/js/cs-zGEtwQn_.js +2 -0
- package/frontend/dist/js/da-B-0sHNTu.js +2 -0
- package/frontend/dist/js/de-UZNE6t2h.js +2 -0
- package/frontend/dist/js/es-CPLnFYIw.js +2 -0
- package/frontend/dist/js/{estree-BuWOCMW0.js → estree-CRuerC6a.js} +1 -1
- package/frontend/dist/js/fr-Br1o0WVz.js +2 -0
- package/frontend/dist/js/hi-BcEvNEpb.js +2 -0
- package/frontend/dist/js/{html-D7tW7UvW.js → html-BYKlz3Jp.js} +1 -1
- package/frontend/dist/js/i18n-DJTg6xWw.js +2 -0
- package/frontend/dist/js/id-C30L2DoT.js +2 -0
- package/frontend/dist/js/is-BAEhfi5Z.js +2 -0
- package/frontend/dist/js/it-HWnfQXZY.js +2 -0
- package/frontend/dist/js/ja-Dvux1mon.js +2 -0
- package/frontend/dist/js/ko-agDQ__KP.js +2 -0
- package/frontend/dist/js/{markdown-CBSxWEtK.js → markdown-DFy8bILU.js} +1 -1
- package/frontend/dist/js/{messageCodeStyles-BlTi46wI.js → messageCodeStyles-_gGirbe-.js} +2 -2
- package/frontend/dist/js/ms-aNRa2QX7.js +2 -0
- package/frontend/dist/js/nl-BtkiDUn-.js +2 -0
- package/frontend/dist/js/pl-SEO0lBnX.js +2 -0
- package/frontend/dist/js/pt-BYtjmvq1.js +2 -0
- package/frontend/dist/js/ru-B-ynj2hU.js +2 -0
- package/frontend/dist/js/{standalone-CaXys7q3.js → standalone-jOqWoOmp.js} +1 -1
- package/frontend/dist/js/sv-CliKR15U.js +2 -0
- package/frontend/dist/js/th-DJQyDr9J.js +2 -0
- package/frontend/dist/js/tr-BBGKZ1la.js +2 -0
- package/frontend/dist/js/{typescript-DQ5zi5zo.js → typescript-TwGXpgeF.js} +1 -1
- package/frontend/dist/js/{ui-DFQiHo_k.js → ui-DSFUl2vT.js} +2 -2
- package/frontend/dist/js/{ui-vendor-D_pYT79f.js → ui-vendor-xUzKqAXI.js} +1 -1
- package/frontend/dist/js/uk-C1GcFWxE.js +2 -0
- package/frontend/dist/js/vi-CIxgICOQ.js +2 -0
- package/frontend/dist/js/workApi-kClHFVkJ.js +6 -0
- package/frontend/dist/js/zh-Cm7vsQ9s.js +2 -0
- package/package.json +4 -3
- package/frontend/dist/assets/index-Cd0_AoYV.js +0 -23
- package/frontend/dist/assets/index-DtkGuqvC.css +0 -1
- package/frontend/dist/js/ArtifactContainer-Dy_1KKWg.js +0 -1
- package/frontend/dist/js/ChatPage-BkFd1iac.js +0 -16
- package/frontend/dist/js/FirstTimeSetup-C6YxrwR7.js +0 -1
- package/frontend/dist/js/GalleryPage-BtcPs7SO.js +0 -1
- package/frontend/dist/js/HomePage-5PhpAt14.js +0 -1
- package/frontend/dist/js/ModelSelector-C1wN91tl.js +0 -1
- package/frontend/dist/js/ModelsPage-Cc3L0ur8.js +0 -2
- package/frontend/dist/js/SettingsModal-C8KJJEud.js +0 -1
- package/frontend/dist/js/SystemPage-8kEAS71H.js +0 -1
- package/frontend/dist/js/UserManagementPage-BSrZ0ucu.js +0 -1
- package/frontend/dist/js/WorkPage-spf92PVN.js +0 -5
- package/frontend/dist/js/api-MySpmAK8.js +0 -19
- package/frontend/dist/js/ar-ClMsdoTH.js +0 -2
- package/frontend/dist/js/authStore-DmrydYuS.js +0 -3
- package/frontend/dist/js/bn-LyPol_AY.js +0 -2
- package/frontend/dist/js/cs-D98fZaKF.js +0 -2
- package/frontend/dist/js/da-M7ND0GQR.js +0 -2
- package/frontend/dist/js/de-BV0q1kzb.js +0 -2
- package/frontend/dist/js/es-C7FvsVoN.js +0 -2
- package/frontend/dist/js/fr-5SloN0ok.js +0 -2
- package/frontend/dist/js/hi-C6VeRgeR.js +0 -2
- package/frontend/dist/js/i18n-CLd1FZPx.js +0 -2
- package/frontend/dist/js/id-CkVp7Z1Z.js +0 -2
- package/frontend/dist/js/is-DqxnBX4W.js +0 -2
- package/frontend/dist/js/it-CiW4_O5V.js +0 -2
- package/frontend/dist/js/ja-BZ3Sdund.js +0 -2
- package/frontend/dist/js/ko-CS7LAhfJ.js +0 -2
- package/frontend/dist/js/ms-URvcYqgz.js +0 -2
- package/frontend/dist/js/nl-CQJpW7wK.js +0 -2
- package/frontend/dist/js/pl-DDMgPMAz.js +0 -2
- package/frontend/dist/js/pt-JCqqmGn_.js +0 -2
- package/frontend/dist/js/ru-C_dwMbiK.js +0 -2
- package/frontend/dist/js/sv-CW3c9NGx.js +0 -2
- package/frontend/dist/js/th-9ARgClBr.js +0 -2
- package/frontend/dist/js/tr-DNY5_DAg.js +0 -2
- package/frontend/dist/js/uk-XDh4_7IL.js +0 -2
- package/frontend/dist/js/vi-BaoJBXnt.js +0 -2
- package/frontend/dist/js/zh-B202vYJt.js +0 -2
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{n as r}from"./react-vendor-DPNXrO-8.js";import{d as i,f as a,u as o}from"./router-vendor-Ca9zqOqT.js";import{t as s}from"./useTranslation-CdeLZqSW.js";import{i as c}from"./i18n-CLd1FZPx.js";import{$ as l,A as u,B as d,Ct as f,D as p,F as m,G as h,Gt as g,Jt as _,Mt as v,N as y,P as b,Pt as x,R as S,T as C,Tn as w,U as T,Ut as E,a as D,an as O,bt as k,d as A,dn as j,et as M,fn as N,ft as P,g as F,gn as I,h as ee,j as te,n as L,nn as R,o as z,on as ne,pt as re,qt as ie,r as ae,rn as B,st as oe,t as se,tt as ce,v as le,wn as V,wt as H,x as ue,yn as de}from"./ui-vendor-D_pYT79f.js";import{i as U,t as W}from"./logger-DSXjF4ye.js";import{S as G,_ as fe,a as K,b as pe,d as q,f as me,i as he,m as ge,n as _e,u as ve}from"./api-MySpmAK8.js";import{a as ye,n as be,r as xe,t as J}from"./utils-BhpNrGnR.js";import{a as Se,c as Ce,i as we,l as Te,n as Ee,r as De,t as Y}from"./chatStore-CWqfsOjc.js";import{n as Oe,r as X}from"./authStore-DmrydYuS.js";import{t as ke}from"./appStore-BpoXhleX.js";import{i as Ae,r as je,t as Me}from"./welcomePrompts-to5mv_gx.js";import{l as Ne}from"./messageCodeStyles-BlTi46wI.js";import{t as Z}from"./Button-X9TT9gTD.js";import{d as Pe,f as Fe,l as Ie}from"./ui-DFQiHo_k.js";import{c as Le,s as Re}from"./ArtifactSandboxFrame-C_S4j076.js";import{t as ze}from"./ArtifactContainer-Dy_1KKWg.js";import{t as Be}from"./ModelSelector-C1wN91tl.js";var Ve=r(),Q=e(n(),1),$=t(),He=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.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,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(P,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,$.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,$.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,$.jsx)(O,{size:12}):(0,$.jsx)(B,{size:12,className:`rtl:rotate-180`}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.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,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},Ue=W(`components:ttsbutton`),We=null,Ge=null,Ke=0,qe=3e5;async function Je(e=!1){let t=Date.now();return!e&&We!==null&&t-Ke<qe?We:Ge||(Ge=(async()=>{try{let e=await K.getModels();return e.success&&e.data&&e.data.length>0?(We=e.data,Ke=t,e.data):(We=[],Ke=t,[])}catch{return We=[],Ke=t,[]}finally{Ge=null}})(),Ge)}function Ye(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Xe=({text:e,className:t,size:n=`sm`})=>{let{t:r}=s(),{preferences:i}=ke(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(!1),v=(0,Q.useRef)([]),y=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await Je(),n=_e(t,i.ttsSettings?.model,i.ttsSettings?.pluginId);i.ttsSettings?.model&&!n&&(t=await Je(!0)),e&&(p(t),h(t.length>0))})(),()=>{e=!1}},[i.ttsSettings?.model,i.ttsSettings?.pluginId]);let b=(0,Q.useCallback)(async(e,t,n,i,a,o)=>{let s=await K.generateBase64({model:t,pluginId:n,input:e,voice:i,speed:a,response_format:o});if(!s.success||!s.data?.audio)throw Error(s.message||r(`ttsButton.generateFailed`));let c=`data:${s.data.mimeType};base64,${s.data.audio}`,l=new Audio(c);return g.current=l,new Promise((e,t)=>{l.onended=()=>{g.current=null,e()},l.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},l.play().catch(t)})},[r]),x=(0,Q.useCallback)(async(e,t,n,r,i,a)=>{v.current=e,y.current=0,_.current=!1;let o=null,s=async e=>{try{let o=await K.generateBase64({model:t,pluginId:n,input:e,voice:r,speed:i,response_format:a});return!o.success||!o.data?.audio?null:{audioUrl:`data:${o.data.mimeType};base64,${o.data.audio}`,mimeType:o.data.mimeType}}catch{return null}};e.length>0&&(o=s(e[0]));for(let t=0;t<e.length&&!_.current;t++){y.current=t;try{let n=await o;if(_.current)break;if(o=t+1<e.length?s(e[t+1]):null,!n){Ue.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);g.current=r,await new Promise((e,t)=>{r.onended=()=>{g.current=null,e()},r.onerror=()=>{g.current=null,e()},r.play().catch(()=>{e()})})}catch(e){Ue.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Q.useCallback)(()=>{_.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),o(!1),l(!1)},[]),C=async()=>{if(!c){if(a){S();return}l(!0),d(null),_.current=!1;try{let t=i.ttsSettings,n=he(f,t?.model,t?.pluginId),a=n?.model||t?.model||`tts-1`,s=n?.plugin||t?.pluginId,c=n?.model===t?.model&&(!t?.pluginId||n?.plugin===t.pluginId)?t?.voice||n?.config?.default_voice||`alloy`:n?.config?.default_voice||`alloy`,u=t?.speed||1,p=n?.config?.default_format;if(t?.streamSentences){let t=Ye(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));l(!1),o(!0),await x(t,a,s,c,u,p),_.current||o(!1)}else await b(e,a,s,c,u,p),l(!1),o(!0),g.current&&(g.current.onended=()=>{o(!1),g.current=null},g.current.onerror=()=>{d(r(`ttsButton.playbackFailed`)),o(!1),g.current=null})}catch(e){let t=e instanceof Error?e.message:r(`ttsButton.generateFailed`);d(t),Ue.error(`TTS error:`,e),o(!1),l(!1)}}};if((0,Q.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},T={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,$.jsx)(`button`,{onClick:C,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:J(`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`,u?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,w[n],t),children:c?(0,$.jsx)(oe,{className:J(T[n],`animate-spin`)}):a?(0,$.jsx)(ue,{className:T[n]}):u?(0,$.jsx)(D,{className:T[n]}):(0,$.jsx)(z,{className:T[n]})})},Ze=new Map;function Qe(e,t,n=``){let r=Ze.get(e);if(n){if((!r||r.state===`none`)&&(Ze.set(e,{state:`open`,startedAt:Date.now()}),!t))return;let n=Ze.get(e);t&&n?.state===`open`&&Ze.set(e,{state:`done`,durationMs:Date.now()-n.startedAt});return}if(r&&r.state!==`open`||!t)return;let i=ye(t);if(!r){i.thinkingComplete?Ze.set(e,{state:`none`}):Ze.set(e,{state:`open`,startedAt:Date.now()});return}i.thinkingComplete&&Ze.set(e,{state:`done`,durationMs:Date.now()-r.startedAt})}function $e(e){let t=Ze.get(e);if(t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function et(e){let t=Ze.get(e);if(Ze.delete(e),t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function tt(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 nt=/```([^\n`]*)\n([\s\S]*?)\n```/g,rt=/^(?:%%|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,it=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,at=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],ot=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:ht(e[1]),title:st(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=ht(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function st(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return lt(ct(e))}function ct(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 lt(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 ut(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return st(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&st(n[1]).trim()||null}function dt(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 pt(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 mt(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 ht(e){let t=e.trim().toLowerCase();return at.includes(t)?t:`text`}function gt(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 _t(e){let t=[],n=new RegExp(nt),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=vt(n,bt(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=yt(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!it.test(r)&&!r.includes(`=`)?gt(r):void 0)||gt(St(n)),fileName:n}}function yt(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&it.test(t[1]))return xt(t[1]);let n=e.match(it);return n?xt(n[0]):void 0}function bt(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(it);if(t)return xt(t[0])}}function xt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function St(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function Ct(e){return e?.split(/[\\/]/).pop()}function wt(e){let t=Ct(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 Tt(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function Et(e){let t=gt(e.language)||gt(St(e.fileName));switch(t){case`html`:return{type:`html`,title:ut(e.content)||wt(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:wt(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:dt(e.content)||wt(e.fileName)||`React Component`,language:`jsx`};case`mermaid`:return{type:`mermaid`,title:ft(e.content)||`Diagram`,language:`mermaid`};case`json`:return{type:`json`,title:wt(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:pt(e.content)||wt(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:wt(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:mt(e.content)||wt(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:wt(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:wt(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function Dt(e){return(gt(e.language)||gt(St(e.fileName)))===`html`}function Ot(e){return(gt(e.language)||gt(St(e.fileName)))===`css`}function kt(e){return(gt(e.language)||gt(St(e.fileName)))===`javascript`}function At(e){let t=_t(e),n=t.filter(Dt);if(n.length===0)return null;let r=t.filter(Ot),i=t.filter(kt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=jt(a.content,r,i),s=Le(o,r.map(e=>e.content),i.map(e=>e.content));return It(s,`html`)?{artifact:Tt({type:`html`,title:ut(s)||wt(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 jt(e,t,n){let r=e;for(let e of t){let t=Ct(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${Ft(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=Ct(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${Ft(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function Mt(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=_t(e);if(Nt(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 It(s,`html`)?{artifact:Tt({type:`html`,title:ut(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function Nt(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function Pt(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 Ft(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function It(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&&(Re(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 rt.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 Lt(e){let t=[],n=e;for(let e of ot){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);It(n.content,n.type)&&(t.push(Tt({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=Pt(n,r)}let r=At(n);for(;r;)t.push(r.artifact),n=Pt(n,r.ranges),r=At(n);let i=Mt(n);i&&(t.push(i.artifact),n=Pt(n,i.ranges));let a=_t(n),o=[];for(let e of a){let n=Et(e);!n||!It(e.content,n.type)||(t.push(Tt({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=Pt(n,o),{content:n.trim(),artifacts:t}}var Rt=W(`components:chat-message`),zt=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onEditResend:a})=>{let{t:o,i18n:c}=s(),l=e.role===`user`,d=e.role===`system`,{preferences:f}=ke(),{user:p}=Oe(),{setSystemMessage:h,getCurrentPersona:_,currentSession:v,rateMessage:y}=Y(),b=_(),[x,C]=(0,Q.useState)(!1),[w,E]=(0,Q.useState)(e.content),[D,k]=(0,Q.useState)(null),[A,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(!1),[I,te]=(0,Q.useState)(!1),[z,re]=(0,Q.useState)(!1),[ie,ae]=(0,Q.useState)(!1),B=(0,Q.useRef)(null),oe=(0,Q.useRef)(t),se=(0,Q.useRef)(!1),ce=async()=>{try{await navigator.clipboard.writeText(e.content),Ne(`success`),ae(!0),setTimeout(()=>ae(!1),2e3)}catch(e){Rt.error(`Failed to copy message:`,e)}},{thinkingContent:le,thinkingStreaming:V,parsedContent:H,artifacts:ue}=(0,Q.useMemo)(()=>{if(l||d||!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}:ye(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=Lt(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,d,t]),de=V?void 0:e.statistics?.thinking_duration_ms??$e(e.id);(0,Q.useEffect)(()=>{let e=oe.current&&!t;return oe.current=t,e&&!se.current&&!l&&!d&&H&&f.ttsSettings?.enabled&&f.ttsSettings?.autoPlay&&(se.current=!0,(async()=>{re(!0);try{let e=await K.getModels(),t=e.success&&e.data?e.data:[],n=f.ttsSettings,r=he(t,n?.model,n?.pluginId),i=_e(t,n?.model,n?.pluginId),a=await K.generateBase64({model:r?.model||n?.model||`tts-1`,pluginId:r?.plugin||n?.pluginId,input:H,voice:i?n?.voice||r?.config?.default_voice||`alloy`:r?.config?.default_voice||`alloy`,speed:n?.speed||1,response_format:r?.config?.default_format});if(a.success&&a.data?.audio){let e=`data:${a.data.mimeType};base64,${a.data.audio}`,t=new Audio(e);B.current=t,t.onended=()=>{re(!1),B.current=null},t.onerror=()=>{re(!1),B.current=null},await t.play()}}catch(e){Rt.error(`Auto-play TTS failed:`,e),re(!1)}})()),()=>{B.current&&(B.current.pause(),B.current=null)}},[t,l,d,H,f.ttsSettings]);let U=()=>d?o(`chatMessage.system`):l?f.showUsername&&p?.username?p.username:o(`chatMessage.you`):b?.name?b.name:e.model||o(`chatMessage.assistant`),W=()=>{C(!0),E(e.content)},G=async()=>{M(!0);try{h(w),C(!1),Rt.debug(`✅ System message updated:`,w)}catch(e){Rt.error(`Failed to save system message:`,e)}finally{M(!1)}},fe=()=>{C(!1),E(e.content)},pe=()=>{let t=w.trim();C(!1),!(!t||t===e.content)&&a?.(e.id,t)},q=t=>{v&&y(v.id,e.id,e.rating===t?void 0:t)},me=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ge=d&&e.content.length>100;return(0,$.jsxs)(`div`,{className:J(`group flex py-1.5 transition-colors sm:py-2`,l?`justify-end`:`justify-start`,n),children:[(0,$.jsx)(`div`,{className:J(`flex min-w-0`,l?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:(0,$.jsxs)(`div`,{className:J(`min-w-0 flex-1`,l?`flex flex-col items-end`:d?`py-1.5`:`py-0.5`),children:[!l&&!d&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:U()}),e.model&&b?.name&&(0,$.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,$.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:be(e.timestamp,c.language)})]}),(0,$.jsxs)(`div`,{className:J(!l&&!d&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,$.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,$.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,$.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>k(e)})},t))}),l?x?(0,$.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,$.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),pe()):e.key===`Escape`&&fe()},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,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(`button`,{onClick:fe,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,$.jsx)(`button`,{onClick:pe,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,$.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,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):d?(0,$.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,$.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,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(u,{className:`h-2.5 w-2.5 opacity-50`}),o(`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:x?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:G,disabled:A,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,$.jsx)(m,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:fe,disabled:A,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,$.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:W,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:o(`chatMessage.editSystemMessage`),children:(0,$.jsx)(T,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),x?(0,$.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>E(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:A}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:N?e.content:me(e.content)}),ge&&(0,$.jsx)(`button`,{onClick:()=>P(!N),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:N?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(R,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(O,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(le||V)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{onClick:()=>te(!I),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,$.jsx)(j,{className:J(`h-3.5 w-3.5`,V&&`animate-pulse-subtle motion-reduce:animate-none`)}),V?(0,$.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,$.jsx)(`span`,{className:`font-medium`,children:de===void 0?o(`chatMessage.thinking`):o(`chatMessage.thoughtFor`,{duration:tt(de)})}),I?(0,$.jsx)(R,{className:`h-3.5 w-3.5`}):(0,$.jsx)(O,{className:`h-3.5 w-3.5`})]}),I&&le&&(0,$.jsx)(`div`,{className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 dark:bg-dark-200/60`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[13px] leading-relaxed text-gray-600 dark:text-dark-700`,children:le})})]}),(0,$.jsx)(Ie,{content:H,isStreaming:t})]}),!l&&!d&&ue.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(ze,{artifacts:ue})}),!l&&!d&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(He,{statistics:e.statistics})}),!d&&!t&&(0,$.jsxs)(`div`,{className:J(`flex items-center gap-0.5 text-gray-400 dark:text-dark-500`,`sm:opacity-0 sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,l?`mt-1 justify-end`:`mt-1`),children:[l&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:be(e.timestamp,c.language),children:[U(),` ·`,` `,be(e.timestamp,c.language)]}),!l&&H&&(0,$.jsx)(Xe,{text:H,size:`sm`,className:J(`transition-colors`,z&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),l&&a&&!x&&(0,$.jsx)(`button`,{onClick:()=>{E(e.content),C(!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,$.jsx)(T,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:ce,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(ie?`chatMessage.copied`:`chatMessage.copyMessage`),children:ie?(0,$.jsx)(ne,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(g,{className:`h-3.5 w-3.5`})}),!l&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>q(1),className:J(`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,$.jsx)(ee,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>q(-1),className:J(`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,$.jsx)(F,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})})]}),!l&&r&&i&&(0,$.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,$.jsx)(S,{className:`h-3.5 w-3.5`})})]})]})]})}),D&&(0,Ve.createPortal)((0,$.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:()=>k(null),children:[(0,$.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(),k(null)},children:(0,$.jsx)(L,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:D,alt:o(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Bt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Vt=220,Ht=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>Vt?`${t.slice(0,219).trimEnd()}…`:t},Ut=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),f=(0,Q.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)},[]),p=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;!r||!i||(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Q.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:Bt()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,$.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,$.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===h,u=Math.abs(a-m),d=c===t.id?v:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.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===m?0:-1,className:J(`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=>f(t.id,e.currentTarget),onFocus:e=>f(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(),p(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:J(`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)})}),_&&(0,$.jsx)(`div`,{id:v,role:`tooltip`,className:J(`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,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:Ht(_.prompt)}),_.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:Ht(_.response)})]})})]})}),Wt=({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,$.jsx)(zt,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,$.jsxs)(`div`,{className:J(`relative py-2`,c),children:[(0,$.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,$.jsx)(f,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,$.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,$.jsxs)(`div`,{className:J(`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,$.jsxs)(`div`,{className:J(`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,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,$.jsx)(ne,{className:`h-3 w-3`}),!l&&!u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,$.jsx)(`div`,{className:J(!l&&!u&&`opacity-75`),children:(0,$.jsx)(zt,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Gt={web_search:b,web_fetch:k,exec:le,browser:k,Read:x,Write:x,Edit:x,image:re,memory_search:E,memory_get:E,working:ae,thinking:ae,default:ae},Kt={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`},qt=({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,$.jsx)(`div`,{className:J(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Gt[e.name]||Gt.default,n=Kt[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:J(`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,$.jsx)(`div`,{className:J(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};W(`components:chat-messages`);var Jt=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],Yt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,Xt=e=>Math.min(120,e*.28),Zt=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],className:o,onRegenerate:c,onSelectBranch:l,onEditResend:u,followUpSuggestions:d,onFollowUpSelect:f})=>{let{t:p}=s(),m=(0,Q.useRef)(null),h=(0,Q.useRef)(void 0),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(new Map),y=(0,Q.useRef)(null),b=(0,Q.useRef)(0),x=(0,Q.useRef)(!1),S=(0,Q.useRef)(!1),[w,T]=(0,Q.useState)(!1),E=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?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 n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),D=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<E.length;t++){let n=E[t],r=Jt(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<E.length;e++){let t=Jt(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,Q.useMemo)(()=>O?O.split(``):[],[O]),A=(0,Q.useMemo)(()=>new Set(k),[k]),[j,M]=(0,Q.useState)(null),N=(0,Q.useCallback)(()=>{let e=g.current;if(!e||k.length===0){M(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(b.current,k.length-1);if(t<=2)n=k.length-1;else{let t=e.scrollTop+Xt(e.clientHeight);for(;n<k.length-1;){let e=v.current.get(k[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=v.current.get(k[n]);if(!e||e.offsetTop<=t)break;n--}}b.current=n;let r=k[n];M(e=>e===r?e:r)},[k]),P=(0,Q.useCallback)(()=>{y.current===null&&(y.current=window.requestAnimationFrame(()=>{y.current=null,N()}))},[N]),F=(0,Q.useCallback)(()=>{let t=g.current;if(h.current&&clearTimeout(h.current),x.current=!1,h.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;S.current=!n,T(!n&&e.length>0),P()},[e.length,P]),I=(0,Q.useCallback)(()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(F,180)},[F]),ee=(0,Q.useCallback)((e=!1)=>{S.current&&!e||m.current?.scrollIntoView({behavior:Yt()})},[]),te=(0,Q.useCallback)(()=>{let t=g.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(x.current){S.current=!0,T(!o&&e.length>0),P(),I();return}S.current=!o,T(!o&&e.length>0),a<=2&&k.length>0?(b.current=k.length-1,M(k[k.length-1])):P()},[k,e.length,I,P]),L=(0,Q.useCallback)(e=>{let t=g.current,n=v.current.get(e);if(!t||!n)return;let r=Yt();x.current=!0,S.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-Xt(t.clientHeight)),behavior:r}),P(),r===`auto`?F():I()},[F,I,P]),R=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>R.current&&!S.current&&ee(),R.current=e.length},[e.length,ee]),(0,Q.useEffect)(()=>{i&&(t||n)&&!S.current&&requestAnimationFrame(()=>{let e=g.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{P();let e=_.current,t=g.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(P);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,P),()=>{n?.disconnect(),window.removeEventListener(`resize`,P)}},[O,P]),(0,Q.useEffect)(()=>()=>{y.current!==null&&(window.cancelAnimationFrame(y.current),y.current=null)},[]),(0,Q.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:J(`flex-1 flex items-center justify-center p-6 sm:p-10`,o),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,$.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,$.jsx)(C,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:p(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:p(`chatMessage.startConversationDescription`)})]})});let z=-1;for(let e=E.length-1;e>=0;e--)if(E[e].messages.some(e=>e.role===`assistant`)){z=e;break}return(0,$.jsxs)(`div`,{className:J(`relative min-h-0 flex-1`,o),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:g,"data-testid":`chat-scroll-viewport`,onScroll:te,className:J(`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,$.jsxs)(`div`,{ref:_,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===z,s=A.has(e.id),d=i&&e.messages.some(e=>e.id===r),f;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,$.jsx)(zt,{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,$.jsx)(Wt,{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,$.jsx)(`div`,{ref:t=>{s&&(t?v.current.set(e.id,t):v.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,$.jsx)(qt,{tools:a,className:`px-0`}),!i&&d&&d.length>0&&f&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:p(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:d.map(e=>(0,$.jsx)(`button`,{onClick:()=>f(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,$.jsx)(`div`,{ref:m,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(Ut,{items:D,activeId:j,onSelect:L}),w&&(0,$.jsxs)(`button`,{onClick:()=>{x.current=!1,h.current&&(clearTimeout(h.current),h.current=void 0),S.current=!1,m.current?.scrollIntoView({behavior:Yt()}),T(!1)},className:J(`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:p(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(de,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:p(`chatMessage.newMessages`)})]})]})};function Qt(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 $t=Q.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,Q.useMemo)(()=>Qt(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:J(`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,$.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:J(`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,$.jsx)(_,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});$t.displayName=`CodeAwareTextarea`;var en=W(`components:media-upload`),tn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)([]),g=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):w.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){w.error(`Maximum ${n} images allowed`);return}if(r.size>10485760){w.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){w.error(`File size must be less than 10MB`);return}p(!0);try{let t=await pe.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),w.success(`Document "${e.name}" uploaded`)}else w.error(t.error||`Failed to upload document`)}catch(e){en.error(`Document upload error:`,e),w.error(`Failed to upload document`)}finally{p(!1)}},b=e=>{e.preventDefault(),a||d(!0)},S=e=>{e.preventDefault(),d(!1)},C=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},T=n=>{t(e.filter((e,t)=>t!==n))},E=async e=>{try{let t=await pe.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),w.success(`Document removed`)):w.error(t.error||`Failed to remove document`)}catch(e){en.error(`Error removing document:`,e),w.error(`Failed to remove document`)}},D=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]},O=e.length>0||m.length>0;return(0,$.jsxs)(`div`,{className:J(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:J(`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:S,onDrop:C,onClick:()=>!a&&l.current?.click(),children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(oe,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,$.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),O&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.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,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),T(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,$.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,$.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,$.jsx)(x,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,$.jsx)(v,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:D(e.size)})]}),(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),E(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,$.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},nn=W(`components:document-indicator`),rn=({sessionId:e,className:t=``})=>{let[n,r]=(0,Q.useState)([]);if((0,Q.useEffect)(()=>{if(!e)return;let t=async()=>{try{let t=await pe.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){nn.error(`Failed to load documents:`,e)}};t();let n=()=>void t();return window.addEventListener(`libre:documents-updated`,n),()=>window.removeEventListener(`libre:documents-updated`,n)},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{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
|
-
${t}
|
|
9
|
-
`,title:`${n.length} document(s) available for context - Total: ${(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]})(i)}`,children:[(0,$.jsx)(I,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,$.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},an=W(`components:structured-output`),on=[{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`}],sn=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),[o,c]=(0,Q.useState)(``),l=()=>on.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),d=()=>{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]},f=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,$.jsxs)(`div`,{className:J(`space-y-3`,n),children:[(0,$.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,$.jsxs)(`div`,{className:`flex items-center`,children:[(0,$.jsx)(u,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,$.jsx)(Pe,{value:d().label,onChange:e=>f(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(Fe,{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,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(Z,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){an.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(Z,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=d();return!e.value||e.value===`json`?null:(0,$.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,$.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,$.jsx)(ie,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,$.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,$.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,$.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,$.jsx)(x,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},cn=W(`components:chat-input`),ln=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},un=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r,i18n:i}=s(),[a,o]=(0,Q.useState)(``),[c,u]=(0,Q.useState)(!1),f=(0,Q.useRef)(null),p=(0,Q.useRef)(``),m=(0,Q.useMemo)(()=>!!ln(),[]),[g,_]=(0,Q.useState)([]),[v,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(!1),[E,D]=(0,Q.useState)(null),[O,A]=(0,Q.useState)(!1),[j,P]=(0,Q.useState)([]),[F,ee]=(0,Q.useState)(!1),[te,L]=(0,Q.useState)(!1),[R,z]=(0,Q.useState)(null),[ie,ae]=(0,Q.useState)(!1),B=(0,Q.useRef)(null),se=(0,Q.useRef)(null),{isGenerating:ce,setBackgroundImage:le}=ke(),H=ke(e=>e.preferences.imageGenSettings?.enabled===!0),de=H&&ie,{currentSession:U,models:W}=Y(),K=(0,Q.useRef)(null),q=(0,Q.useMemo)(()=>({model:U?.personaId?`persona:${U.personaId}`:U?.model||``,providerType:U?.providerType,providerId:U?.providerId}),[U?.model,U?.personaId,U?.providerId,U?.providerType]),me=(0,Q.useMemo)(()=>Te(W,q),[W,q]),he=q.model?Se(me,q):``,ge=Ce(W,q);(0,Q.useEffect)(()=>{let e=!1;return H&&(async()=>{try{let t=await fe.getPlugins();if(e)return;ae(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ae(!1)}})(),()=>{e=!0}},[H]),(0,Q.useEffect)(()=>{if(!w)return;let e=e=>{B.current&&!B.current.contains(e.target)&&(T(!1),D(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[w]);let _e=()=>{T(!1),D(null),A(!1)};(0,Q.useEffect)(()=>{if(!O)return;let e=!1;return pe.getCollections().then(t=>{!e&&t.success&&t.data&&P(t.data)}).catch(()=>{}),()=>{e=!0}},[O]);let ye=U?.settings?.knowledgeCollectionIds??[],be=async e=>{if(!U)return;let t=ye.includes(e)?ye.filter(t=>t!==e):[...ye,e],n={...U.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(Y.setState(e=>({currentSession:e.currentSession?.id===U.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===U.id?{...e,settings:n}:e)})),!U.isPrivate)try{await G.updateSession(U.id,{settings:n})}catch(e){cn.error(`Failed to update knowledge collections:`,e),V.error(r(`chat.input.menu.attachFailed`))}};(0,Q.useEffect)(()=>()=>{f.current?.stop()},[]);let xe=()=>{if(c){f.current?.stop();return}let e=ln();if(!e)return;let t=new e;t.lang=i.language,t.continuous=!0,t.interimResults=!0,p.current=a,t.onresult=e=>{let t=``;for(let n=0;n<e.results.length;n++)t+=e.results[n][0]?.transcript??``;let n=p.current;o(n?`${n} ${t.trim()}`:t.trim())},t.onend=()=>{f.current=null,u(!1)},t.onerror=()=>{f.current=null,u(!1)},f.current=t;try{t.start(),u(!0)}catch(e){cn.error(`Failed to start dictation:`,e),f.current=null}},we=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){_e(),L(!0);try{let e=await pe.uploadDocument(t,U?.id);e.success?(V.success(r(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):V.error(e.error||r(`chat.input.menu.attachFailed`))}catch(e){cn.error(`Document upload failed:`,e),V.error(r(`chat.input.menu.attachFailed`))}finally{L(!1)}}},Oe=async()=>{let e=E?.trim();if(!(!e||F)){ee(!0);try{let t=await pe.fetchWebpage(e,U?.id);t.success?(V.success(r(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),_e()):V.error(t.error||r(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||r(`chat.input.menu.attachFailed`);cn.error(`Webpage attach failed:`,e),V.error(t)}finally{ee(!1)}}},X=t=>{if(t.preventDefault(),!(!a.trim()||ce)){if(!ge){V.error(`Select an available model before sending`);return}e(a.trim(),g.length>0?g:void 0,v||void 0),o(``),_([])}},Ae=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),X(e))},je=()=>{t()};(0,Q.useEffect)(()=>{let e=K.current;e&&(e.style.height=`auto`,e.style.height=a?`${Math.min(e.scrollHeight,200)}px`:``)},[a]),(0,Q.useEffect)(()=>{(async()=>{if(U?.personaId)try{let e=await ve.getPersona(U.personaId);if(e.success&&e.data)z(e.data);else{cn.warn(`Persona ${U.personaId} not found, clearing reference`),z(null);let{setCurrentSession:e}=Y.getState();e({...U,personaId:void 0})}}catch(e){if(cn.error(`Failed to load current persona:`,e),z(null),U){let{setCurrentSession:e}=Y.getState();e({...U,personaId:void 0})}}else z(null)})()},[U?.personaId]);let Me=async e=>{let t=De(me,e.target.value);if(t&&U)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await ve.getPersona(e);if(!n.success||!n.data){V.error(`Failed to load persona details`);return}let i=n.data,a=await G.updateSession(U.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(a.success&&a.data){let{sessions:e}=Y.getState(),t=e.map(e=>e.id===U.id?a.data:e);Y.setState({sessions:t,currentSession:a.data}),i.background&&le(i.background),V.success(r(`chat.persona.applied`))}}else{let e=await G.updateSession(U.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}=Y.getState(),n=t.map(t=>t.id===U.id?e.data:t);Y.setState({sessions:n,currentSession:e.data}),le(null),V.success(r(`chat.model.updated`))}}}catch(e){cn.error(`Failed to update session:`,e),V.error(`Failed to update session`)}},Ne=g.length>0||v!==null;return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[S&&(0,$.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,$.jsx)(tn,{images:g,onImagesChange:_,maxImages:5,sessionId:U?.id,disabled:n}),(0,$.jsx)(sn,{format:v,onFormatChange:b})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[(0,$.jsx)(`form`,{onSubmit:X,children:(0,$.jsxs)(`div`,{className:J(`flex items-end gap-2 rounded-[1.35rem] border p-2 transition-[border-color,box-shadow,background-color] duration-200`,`bg-surface/[0.92] dark:bg-dark-200/[0.92] backdrop-blur-xl`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_14px_42px_rgba(15,23,42,0.08)]`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_52px_rgba(15,23,42,0.11)]`),children:[(0,$.jsxs)(`div`,{ref:B,className:`relative flex-shrink-0`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(S){C(!1);return}T(e=>!e),D(null)},className:J(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,Ne&&`text-primary-600 dark:text-primary-400`,(S||w)&&`bg-gray-100 dark:bg-dark-300`),title:r(`chat.input.attachments`),children:te||F?(0,$.jsx)(oe,{className:`h-4 w-4 animate-spin`}):Ne?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(h,{className:`h-4 w-4`}),(0,$.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`})]}):S?(0,$.jsx)(l,{className:`h-4 w-4`}):(0,$.jsx)(d,{className:`h-4 w-4`})}),w&&(0,$.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:O?(0,$.jsxs)(`div`,{className:`p-1`,children:[(0,$.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`)}),j.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-gray-400 dark:text-dark-500`,children:r(`chat.input.menu.noCollections`)}):j.map(e=>{let t=ye.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void be(e.id),className:J(`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,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(I,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(ne,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>A(!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`)})]}):E===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{C(!0),_e()},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,$.jsx)(re,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.uploadImages`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>se.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,$.jsx)(x,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>D(``),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,$.jsx)(k,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>A(!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,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(I,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.attachKnowledge`)]}),ye.length>0&&(0,$.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:ye.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{C(!0),_e()},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,$.jsx)(N,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),r(`chat.input.menu.structuredOutput`)]})]}):(0,$.jsxs)(`div`,{className:`p-1.5`,children:[(0,$.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,$.jsx)(`input`,{type:`url`,value:E,onChange:e=>D(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),Oe()):e.key===`Escape`&&D(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,$.jsxs)(`div`,{className:`mt-2 flex justify-end gap-1.5`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>D(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,$.jsx)(`button`,{type:`button`,onClick:()=>void Oe(),disabled:!E.trim()||F,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:F?(0,$.jsx)(oe,{className:`h-3.5 w-3.5 animate-spin`}):r(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:se,type:`file`,accept:`.pdf,.txt,application/pdf,text/plain`,className:`hidden`,onChange:e=>void we(e)})]}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)($t,{ref:K,value:a,onChange:e=>o(e.target.value),onKeyDown:Ae,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!m-0 block min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-1.5 !py-1.5 sm:!min-h-10 sm:!py-2 max-[768px]:!min-h-11 max-[768px]:!py-[10.5px] !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1})}),(0,$.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1 sm:gap-2`,children:[U&&me.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Be,{models:me,selectedModel:he,onModelChange:Me,getModelValue:Ee,currentPersona:R,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:de})}),m&&(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:xe,className:J(`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&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:r(c?`chat.input.voiceStop`:`chat.input.voiceInput`),"aria-pressed":c,children:(0,$.jsx)(M,{className:`h-4 w-4`})}),ce?(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:je,className:J(`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,$.jsx)(ue,{className:`h-4 w-4`})}):(0,$.jsx)(Z,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!a.trim()||n||!ge,className:J(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-100 text-gray-400 dark:bg-dark-300 dark:text-dark-500`,`disabled:cursor-not-allowed disabled:opacity-70`,`transition-colors duration-150 touch-manipulation`,a.trim()&&!n&&ge&&[`bg-gray-950 text-white hover:bg-gray-800`,`dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`shadow-sm`]),title:r(`chat.input.sendMessage`),children:(0,$.jsx)(y,{className:`h-4 w-4`})})]})]})}),U&&me.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(Be,{models:me,selectedModel:he,onModelChange:Me,getModelValue:Ee,currentPersona:R,className:`w-full`,compact:!0,showImageGen:de})}),(0,$.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,$.jsx)(rn,{sessionId:U?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),Ne&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,g.length>0&&r(`chat.footer.images`,{count:g.length}),g.length>0&&v&&` • `,v&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},dn=W(`components:chat-controls-panel`),fn=[{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`}],pn=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i}=s(),a=Y(e=>e.draftSessionSettings),o=Y(e=>e.setDraftSessionSettings),c=e?.model??t??``,l=ke(e=>e.preferences.generationOptions),u=ke(e=>e.preferences.modelGenerationOptions?.[c]),[d,f]=(0,Q.useState)({options:{},contextCapped:!1});(0,Q.useEffect)(()=>{if(!n||!c)return;let e=!1;return ge.getModelDefaults(c).then(t=>{e||!t.success||!t.data||f({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,c]);let p=(0,Q.useMemo)(()=>({...l??{},...d.options,...u??{}}),[l,d.options,u]),m=(0,Q.useMemo)(()=>e?.messages.find(e=>e.role===`system`),[e?.messages]),[h,g]=(0,Q.useState)(m?.content??a.systemPrompt??``),[_,v]=(0,Q.useState)(e?.settings?.generationOptions??a.generationOptions??{}),[y,b]=(0,Q.useState)(!1),[x,S]=(0,Q.useState)(e?.id??`draft`),C=e?.id??`draft`;x!==C&&(S(C),g(m?.content??a.systemPrompt??``),v(e?.settings?.generationOptions??a.generationOptions??{}));let T=(e,t)=>{v(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},E=async()=>{b(!0);try{let t=h.trim(),n=m?.content??``,a=Object.fromEntries(Object.entries(_).filter(([,e])=>e!==void 0)),s=Object.keys(a).length>0?{generationOptions:a}:void 0;if(!e){o({systemPrompt:t||void 0,generationOptions:s?.generationOptions}),w.success(i(`chat.controls.saved`)),r();return}let c=e.messages;if(t!==n.trim()&&(m?c=t?e.messages.map(e=>e.id===m.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==m.id):t&&(c=[{id:xe(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)Y.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:c,settings:s}:t.currentSession}));else{let t=await G.updateSession(e.id,{messages:c,settings:s});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;Y.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}w.success(i(`chat.controls.saved`)),r()}catch(e){dn.error(`Failed to save chat controls:`,e),w.error(i(`chat.controls.saveFailed`))}finally{b(!1)}};return n?(0,$.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,$.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4`,children:[(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:i(`chat.controls.title`)}),(0,$.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,$.jsx)(L,{className:`h-4 w-4`})})]}),(0,$.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 overflow-y-auto px-4 py-2 scrollbar-thin`,children:[(0,$.jsxs)(`div`,{children:[(0,$.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,$.jsx)(`textarea`,{dir:`auto`,value:h,onChange:e=>g(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,$.jsxs)(`div`,{children:[(0,$.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,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.advancedParamsDescription`)}),d.contextCapped&&d.trainedContextLength&&(0,$.jsx)(`p`,{className:`mb-2.5 text-[11px] leading-snug text-gray-500 dark:text-dark-600`,children:i(`chat.controls.contextCapped`,{context:p.num_ctx?.toLocaleString(),trained:d.trainedContextLength.toLocaleString()})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:fn.map(e=>{let t=_[e.key],n=p[e.key],r=d.options[e.key]!==void 0&&u?.[e.key]===void 0;return(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.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,$.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,$.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=>T(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,$.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,$.jsx)(`button`,{onClick:()=>{v({}),g(m?.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,$.jsx)(Z,{onClick:()=>void E(),size:`sm`,disabled:y,children:i(y?`common.saving`:`common.save`)})]})]}):null},mn=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Q.useState)(!1),a=(0,Q.useRef)(null),[o,s]=(0,Q.useState)({top:0,left:0});(0,Q.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=()=>q(e,64),u=t=>{me(t.currentTarget,e.name,64)};return(0,$.jsxs)(`div`,{className:J(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:J(`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,$.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:u}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,$.jsx)(C,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(O,{className:J(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Ve.createPortal)((0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,$.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,$.jsxs)(`div`,{className:J(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,$.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,$.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,$.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,$.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,$.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,$.jsx)(L,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,$.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,$.jsx)(j,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,$.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,$.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,$.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,$.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,$.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,$.jsx)(te,{className:`h-3 w-3`}),e.model]}),e.description&&(0,$.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,$.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,$.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,$.jsx)(ce,{className:`h-2.5 w-2.5 text-gray-400`}),(0,$.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,$.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,$.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,$.jsx)(se,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,$.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,$.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,$.jsx)(j,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},hn=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Q.useRef)(null),[o,c]=(0,Q.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/`)){w.error(`File ${o.name} is not an image`);continue}if(o.size>10485760){w.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&&w.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),c(!0)},d=e=>{e.preventDefault(),c(!1)},f=e=>{e.preventDefault(),c(!1),l(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},m=e.length<n;return(0,$.jsxs)(`div`,{className:J(`space-y-3`,r),children:[m&&(0,$.jsxs)(`div`,{className:J(`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:f,children:[(0,$.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,$.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,$.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,$.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,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.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,$.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:()=>p(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,$.jsx)(L,{className:`h-4 w-4`})})})]},t))}),m&&e.length>0&&(0,$.jsxs)(Z,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(re,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},gn=W(`use-chat`),_n=new Set([`New Chat`,`New Demo Session`]),vn=e=>!e||_n.has(e),yn=e=>{let[t,n]=(0,Q.useState)(``),[r,i]=(0,Q.useState)(``),[a,o]=(0,Q.useState)(null),[s,c]=(0,Q.useState)(!1),[l,u]=(0,Q.useState)([]),{addMessage:d,updateMessage:f,updateMessageWithStatistics:p,applySessionTitle:m,setGeneratingTitleForSession:h}=Y(),{setIsGenerating:g}=ke(),_=(0,Q.useRef)(null),v=(0,Q.useRef)(null),y=(0,Q.useRef)(!1),b=(0,Q.useRef)(null),x=(0,Q.useRef)(``),S=(0,Q.useRef)(``),C=(0,Q.useRef)(0),T=(0,Q.useRef)(void 0),E=(0,Q.useRef)(null),D=(0,Q.useRef)(``),O=(0,Q.useRef)(``),k=(0,Q.useCallback)(()=>{E.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(E.current),E.current=null},[]),A=(0,Q.useCallback)((e,t=!1,r=``)=>{if(D.current=e,O.current=r,t||typeof window>`u`){k(),n(e),i(r);return}E.current===null&&(E.current=window.requestAnimationFrame(()=>{E.current=null,n(D.current),i(O.current)}))},[k]),j=(0,Q.useCallback)(()=>{k(),D.current=``,O.current=``,n(``),i(``)},[k]),M=(0,Q.useCallback)(()=>{v.current=null,y.current=!1,b.current=null},[]),N=(0,Q.useCallback)(async e=>{let t=ke.getState().preferences.titleSettings,n=v.current,r=y.current&&b.current===e;if(gn.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),!n||!r||!t?.autoTitle||!t?.taskModel){M();return}M(),gn.debug(`Triggering auto-title generation...`),h(e);try{let r=await G.generateTitle(e,t.taskModel,n,t.taskProviderType,t.taskProviderId);if(gn.debug(`Title generation response:`,r),!r.success||!r.data?.title)throw Error(r.error||`Title generation returned no title`);m(e,r.data.title,r.data.updatedAt),r.data.source===`fallback`?w.error(`Could not generate a title; using the message preview`):w.success(`Chat title generated`)}catch(e){gn.error(`Failed to generate title:`,e),w.error(`Failed to generate chat title`)}finally{h(null)}},[m,M,h]);(0,Q.useEffect)(()=>()=>{X.offMessage(`user_message`),X.offMessage(`assistant_chunk`),X.offMessage(`assistant_complete`),X.offMessage(`tool_status`),X.offMessage(`error`)},[e]),(0,Q.useEffect)(()=>{if(!e){X.offMessage(`user_message`),X.offMessage(`assistant_chunk`),X.offMessage(`assistant_complete`),X.offMessage(`tool_status`),X.offMessage(`error`);return}return X.onMessage(`user_message`,()=>{}),X.onMessage(`assistant_chunk`,t=>{let n=t,r=n.messageId||_.current;r&&(x.current=n.total,typeof n.thinkingTotal==`string`&&(S.current=n.thinkingTotal),Qe(r,n.total,S.current),A(n.total,n.done,S.current),T.current&&clearTimeout(T.current),T.current=setTimeout(()=>{f(e,r,x.current),C.current=Date.now()},n.done?0:200))}),X.onMessage(`tool_status`,e=>{let t=e;u(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()}])}),X.onMessage(`assistant_complete`,t=>{let n=t;gn.debug(`Hook: Received assistant_complete for session:`,e,`messageId:`,n.messageId,`with statistics:`,!!n.statistics),c(!1),j(),g(!1),u([]);let r=n.messageId||_.current;if(n&&r){let t=x.current||n.content,i=S.current||n.thinking,a=et(r),o=n.statistics?.thinking_duration_ms===void 0&&a!==void 0?{...n.statistics,thinking_duration_ms:a}:n.statistics;p(e,r,t,o,n.providerMetadata,i)}N(e),_.current=null,x.current=``,S.current=``,T.current&&clearTimeout(T.current),C.current=0}),X.onMessage(`error`,e=>{let t=e;if(c(!1),j(),g(!1),_.current=null,S.current=``,t.code===`SESSION_NOT_FOUND`){gn.warn(`Session not found, redirecting to create new session...`),w.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}w.error(t.error),M()}),c(!1),j(),_.current=null,S.current=``,()=>{T.current&&clearTimeout(T.current),k()}},[e,f,p,g,A,j,k,N,M]);let P=(0,Q.useCallback)(async(t,n,r)=>{if(!(!e||!t.trim()&&(!n||n.length===0)))try{let i=Y.getState(),a=i.currentSession,s={model:a?.personaId?`persona:${a.personaId}`:a?.model||``,providerType:a?.providerType,providerId:a?.providerId};if(!Ce(i.models,s)){w.error(`Select an available model before sending`);return}g(!0),c(!0),j(),T.current&&clearTimeout(T.current),C.current=Date.now();let l=a?.isPrivate===!0,u=a?.messages?.some(e=>e.role===`user`);!l&&!u&&vn(a?.title)?(v.current=t.trim(),y.current=!0,b.current=e):(v.current=null,y.current=!1,b.current=null),d(e,{role:`user`,content:t.trim(),images:n});let p=xe();if(_.current=p,S.current=``,o(p),d(e,{role:`assistant`,content:``,id:p}),U()){let n=`Demo response for: ${t.trim()}`;window.setTimeout(()=>{f(e,p,n),c(!1),j(),o(null),g(!1),N(e),_.current=null,x.current=``,S.current=``},500);return}X.isConnected||await X.connect();let m=l?a?.messages?.filter(e=>e.role!==`system`&&e.id!==p).map(e=>({role:e.role,content:e.content,thinking:e.thinking,images:e.images,providerMetadata:e.providerMetadata})):void 0;X.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:n,format:r,options:a?.settings?.generationOptions??{},assistantMessageId:p,isPrivate:l,...l?{model:a?.model,providerType:a?.providerType,providerId:a?.providerId,messageHistory:m}:{}}})}catch(e){gn.error(`Failed to send message:`,e),c(!1),j(),o(null),g(!1),_.current=null,S.current=``,w.error(`Failed to send message`)}},[e,d,f,g,j,N]),F=(0,Q.useCallback)(()=>{c(!1),j(),o(null),g(!1),_.current=null,S.current=``},[g,j]),I=(0,Q.useCallback)(async()=>{let t=Y.getState(),n=t.currentSession;if(!n||!e)return;if(!Ce(t.models,{model:n.personaId?`persona:${n.personaId}`:n.model,providerType:n.providerType,providerId:n.providerId})){w.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){w.error(`No message to regenerate`);return}let s=r[i],l=r[a];try{g(!0),c(!0),j(),T.current&&clearTimeout(T.current),C.current=Date.now();let t=xe();_.current=t,S.current=``,o(t),d(e,{role:`assistant`,content:``,id:t,parentId:l.parentId||l.id,branchIndex:l.siblingCount||1,isActive:!0}),X.isConnected||await X.connect();let i=n.isPrivate===!0,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;X.send({type:`chat_stream`,data:{sessionId:e,content:s.content,images:s.images,options:n.settings?.generationOptions??{},assistantMessageId:t,regenerate:!0,originalMessageId:l.id,isPrivate:i,...i?{model:n.model,providerType:n.providerType,providerId:n.providerId,messageHistory:a}:{}}})}catch(e){gn.error(`Failed to regenerate message:`,e),c(!1),j(),o(null),g(!1),_.current=null,S.current=``,w.error(`Failed to regenerate message`)}},[e,g,j,d]),ee=(0,Q.useCallback)(async t=>{let n=Y.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){w.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await G.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()};Y.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),w.success(`Switched to variant ${a+1}`)}else w.error(r.error||`Failed to select branch`)}catch(e){gn.error(`Failed to select branch:`,e),w.error(`Failed to select branch`)}},[e]);return{sendMessage:P,stopGeneration:F,regenerateLastMessage:I,editAndResendMessage:(0,Q.useCallback)(async(t,n)=>{if(!e||!n.trim())return;let r=Y.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 G.updateSession(e,{messages:s}),r.truncateMessagesFrom(e,t),await P(n,o.images)}catch(e){gn.error(`Failed to edit message:`,e),w.error(`Failed to edit message`)}},[e,P]),selectBranch:ee,isStreaming:s,streamingMessage:t,streamingThinking:r,streamingMessageId:a,toolActivities:l}},bn=W(`pages:chat-page`),xn=(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?`}},Sn=(e,t,n,r=!1)=>{let i=je(e);return i===`time`?xn(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.`}},Cn=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),u=o(),{currentSession:f,sessions:m,models:g,selectedModel:_,selectedProviderType:v,selectedProviderId:b,setSelectedModel:x,createSession:S,setCurrentSession:C,loadSessions:T,getCurrentPersona:E}=Y(),{user:D}=Oe(),O=ke(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:k,stopGeneration:A,regenerateLastMessage:j,editAndResendMessage:M,selectBranch:N,isStreaming:P,streamingMessage:F,streamingThinking:I,streamingMessageId:ee,toolActivities:te}=yn(f?.id||``),L=E(),R=(0,Q.useMemo)(()=>({model:_,providerType:v,providerId:b}),[_,b,v]),z=(0,Q.useMemo)(()=>Te(g,R),[g,R]),ne=_?Se(z,R):``,re=Ce(g,R),ie=new URLSearchParams(u.search).get(`incognito`)===`1`,[ae,B]=(0,Q.useState)(Ae),[oe,se]=(0,Q.useState)(null),[ce,le]=(0,Q.useState)(!1),V=ke(e=>e.preferences.showFollowUpSuggestions!==!1),ue=(0,Q.useRef)(null),de=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=f?.id,t=de.current&&!P;if(de.current=P,!e||P||!V||f?.isPrivate||!t)return;let n=f.messages[f.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||ue.current===n.id)return;ue.current=n.id;let r=!1;return G.generateFollowUps(e).then(t=>{r||!t.success||Y.getState().currentSession?.id===e&&se({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[P,f,V]);let U=oe&&oe.sessionId===f?.id?oe.suggestions:[],W=(0,Q.useMemo)(()=>Sn(ae,D?.username,e,c(t.language)),[t.language,e,D?.username,ae]),[K,pe]=(0,Q.useState)(``),[q,me]=(0,Q.useState)([]),[he,ge]=(0,Q.useState)(!1),_e=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{B(Ae())};return window.addEventListener(Me,e),()=>window.removeEventListener(Me,e)},[]);let[ve,ye]=(0,Q.useState)(!1),be=O&&ve,X=(0,Q.useCallback)((t=!0)=>{let n=_?R:g[0]?we(g[0]):null;if(!n||!Ce(g,n))return t&&w.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return C({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},[g,_,R,C,e]);(0,Q.useEffect)(()=>{m.length===0&&T()},[T,m.length]),(0,Q.useEffect)(()=>{!ie||f?.isPrivate||X(!1)},[f?.isPrivate,ie,X]),(0,Q.useEffect)(()=>{let e=!1;return O&&(async()=>{try{let t=await fe.getPlugins();if(e)return;ye(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ye(!1)}})(),()=>{e=!0}},[O]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!(f?.isPrivate&&!n)&&m.length!==0)if(n){let e=m.find(e=>e.id===n);e&&e.id!==f?.id?C(e):e||(bn.warn(`Session ${n} not found for current user, redirecting...`),m.length>0?r(`/c/${m[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&m.length>0&&u.pathname===`/`&&r(`/c/${m[0].id}`,{replace:!0})})()},[n,m,C,r,f?.id,f?.isPrivate,u.pathname]),(0,Q.useEffect)(()=>{if(f?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{k(t.content,t.images)},100)}catch(e){bn.error(`Failed to parse pending message:`,e)}}}},[f?.id,k]),(0,Q.useEffect)(()=>{let e=_e.current;e&&(e.style.height=`auto`,e.style.height=K?`${Math.min(e.scrollHeight,200)}px`:``)},[K]);let je=async t=>{if(t.preventDefault(),!K.trim()||!_)return;if(!re){w.error(e(`chat.model.selectBeforeSending`));return}Ne(`impact`);let n={content:K.trim(),images:q.length>0?q:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),pe(``),me([]);let i=await S(_,void 0,_.startsWith(`persona:`)?_.slice(8):void 0,v,b);i&&(await Pe(i),r(`/c/${i.id}`,{replace:!0}))},Pe=(0,Q.useCallback)(async e=>{let t=Y.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions;if(!n&&!r)return;let i=n?[{id:xe(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await G.updateSession(e.id,{messages:i,settings:r?{generationOptions:r}:void 0});if(t.success&&t.data){let e=t.data;Y.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){bn.error(`Failed to apply chat settings to the new session`,e)}finally{Y.getState().setDraftSessionSettings({})}},[]),Fe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),je(e))},Ie=async e=>{let t=De(z,e.target.value);t&&x(t.model,t.providerType,t.providerId)},Le=(e,t,n)=>{f&&(Ne(`impact`),se(null),k(e,t,n))};if(!f){let t=q.length>0;return(0,$.jsxs)(`div`,{className:`flex h-full min-h-0 flex-1`,children:[(0,$.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,$.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,$.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,$.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,$.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,$.jsx)(`button`,{onClick:()=>le(e=>!e),className:J(`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`,ce&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ce,children:(0,$.jsx)(p,{className:`h-4 w-4`})}),(0,$.jsxs)(`button`,{onClick:()=>X(),disabled:!_&&g.length===0||!!_&&!re,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,$.jsx)(H,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{children:e(`chat.session.incognito`,`Incognito Chat`)})]}),(0,$.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,$.jsxs)(`div`,{className:`mb-10 flex flex-col items-center text-center animate-fade-in sm:mb-12`,"aria-live":`polite`,children:[(0,$.jsx)(`h1`,{className:`mb-4 max-w-3xl text-balance text-[clamp(2.65rem,7vw,5.25rem)] font-light leading-[0.98] tracking-[-0.055em] text-gray-950 dark:text-dark-950 rtl:leading-[1.12] rtl:tracking-normal`,children:W.title}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-base leading-relaxed text-gray-500 dark:text-dark-600 sm:text-lg`,children:W.subtitle})]},W.id),z.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[he&&(0,$.jsx)(`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,$.jsx)(hn,{images:q,onImagesChange:me,maxImages:5})}),(0,$.jsx)(`form`,{onSubmit:je,children:(0,$.jsxs)(`div`,{className:J(`flex items-end gap-2 rounded-[1.35rem] border p-2 transition-[border-color,box-shadow,background-color] duration-200`,`border-black/[0.08] bg-surface/90 dark:border-white/[0.09] dark:bg-dark-200/90`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_50px_rgba(15,23,42,0.08)] backdrop-blur-xl`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_22px_65px_rgba(15,23,42,0.12)]`),children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>ge(!he),className:J(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300 transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,he&&`bg-gray-100 dark:bg-dark-300`),title:e(`chat.input.attachImages`),children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(h,{className:`h-4 w-4`}),(0,$.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):he?(0,$.jsx)(l,{className:`h-4 w-4`}):(0,$.jsx)(d,{className:`h-4 w-4`})}),(0,$.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,$.jsx)($t,{ref:_e,value:K,onChange:e=>pe(e.target.value),onKeyDown:Fe,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 block min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-1.5 !py-1.5 sm:!min-h-10 sm:!py-2 max-[768px]:!min-h-11 max-[768px]:!py-[10.5px] !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1})}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Be,{models:z,selectedModel:ne,onModelChange:Ie,getModelValue:Ee,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:be})}),(0,$.jsx)(Z,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!K.trim()||!_||!re,className:J(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-950 text-white hover:bg-gray-800 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`disabled:bg-gray-100 disabled:text-gray-400 dark:disabled:bg-dark-300 dark:disabled:text-dark-500 disabled:hover:bg-gray-100 dark:disabled:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,K.trim()&&_&&`shadow-sm`),title:e(`chat.input.sendMessage`),children:(0,$.jsx)(y,{className:`h-4 w-4`})})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(Be,{models:z,selectedModel:ne,onModelChange:Ie,getModelValue:Ee,className:`w-full`,compact:!0,showImageGen:be})}),(0,$.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,$.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,$.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,$.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,$.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,$.jsx)(pn,{draftModel:_,open:ce,onClose:()=>le(!1)})]})}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:L?.background?{backgroundImage:`url(${L.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[L?.background&&(0,$.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,$.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[f?.isPrivate&&(0,$.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,$.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(H,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,$.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),L&&!f?.isPrivate&&(0,$.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,$.jsx)(mn,{persona:L,onClear:()=>{f&&G.updateSession(f.id,{model:L.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);Y.setState(t=>({sessions:t.sessions.map(t=>t.id===f.id?e.data:t),currentSession:e.data}))}).catch(t=>{bn.error(`Failed to remove persona:`,t),w.error(e(`chat.persona.removeFailed`))})}})}),(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`relative flex min-w-0 flex-1 flex-col`,children:[(0,$.jsx)(`button`,{onClick:()=>le(e=>!e),className:J(`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`,ce&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ce,children:(0,$.jsx)(p,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(Zt,{messages:f.messages,streamingMessage:F,streamingThinking:I,streamingMessageId:ee,isStreaming:P,toolActivities:te,onRegenerate:j,onSelectBranch:N,onEditResend:M,followUpSuggestions:U,onFollowUpSelect:e=>Le(e),className:`flex-1`}),(0,$.jsx)(un,{onSendMessage:Le,onStopGeneration:A,disabled:!f})]}),(0,$.jsx)(pn,{session:f,open:ce,onClose:()=>le(!1)})]})]})]})};export{Cn as ChatPage,Cn as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./useTranslation-CdeLZqSW.js";import{Gt as i,O as a,Rt as o,_n as s,bt as ee,dt as c,f as l,l as u,on as d,t as f,wn as p,zt as m}from"./ui-vendor-D_pYT79f.js";import{t as h}from"./logger-DSXjF4ye.js";import{C as g}from"./api-MySpmAK8.js";import{n as _}from"./authStore-DmrydYuS.js";import{i as v,l as y,n as b,r as x,u as S}from"../assets/index-Cd0_AoYV.js";var C=e(n(),1),w=t(),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()){p.error(t(`setup.admin.fillAllFields`));return}if(O!==A){p.error(t(`auth.signup.passwordMismatch`));return}let n=x(O);if(n){p.error(n);return}if(Y&&!W){p.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)){p.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),p.success(t(`setup.admin.success`)),h(`encryption-key`)}else p.error(e.message||t(`setup.admin.failed`))}catch(e){T.error(`Admin creation error:`,e),p.error(t(`setup.admin.failed`))}finally{G(``),L(!1)}},te=async()=>{if(R)try{await navigator.clipboard.writeText(R),V(!0),p.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>V(!1),3e3)}catch{p.error(t(`setup.encryptionKey.copyFailed`))}},ne=()=>{if(!H){p.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)(S,{})]})}),(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)(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.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)(f,{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)(ee,{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)(s,{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)(S,{})]}),(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)(l,{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)(d,{className:`h-5 w-5 text-green-500`}):(0,w.jsx)(i,{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)(s,{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)(S,{})]}),(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)(m,{size:20}):(0,w.jsx)(o,{size:20})})]}),(0,w.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:b})]}),(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)(m,{size:20}):(0,w.jsx)(o,{size:20})})]})]}),Y&&J&&(0,w.jsx)(v,{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)(u,{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};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{n as r}from"./react-vendor-DPNXrO-8.js";import{t as i}from"./useTranslation-CdeLZqSW.js";import{Ht as a,T as o,Wt as s,Xt as c,jt as l,m as u,mt as d,n as f,o as p,pt as m,rt as h,st as g,wn as _}from"./ui-vendor-D_pYT79f.js";import{t as v}from"./logger-DSXjF4ye.js";import{_ as y,h as b}from"./api-MySpmAK8.js";import{i as x,n as ee,r as S,s as C}from"./imageGenModels-Dx_QMLJQ.js";import{t as w}from"./utils-BhpNrGnR.js";import{t as T}from"./appStore-BpoXhleX.js";import{t as E}from"./Button-X9TT9gTD.js";import{n as D,t as O}from"./ui-DFQiHo_k.js";import{_ as k,f as A,h as j,m as M,p as N,v as P}from"../assets/index-Cd0_AoYV.js";var F=class extends j{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,f=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:k(t,n.data),hasPreviousPage:P(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function I(e,t){return N(e,F,t)}var L=e(n(),1),R=r(),z=t(),B=v(`components:image-generation-panel`);function V(e,t={}){let n=e.config?.sizes&&e.config.sizes.length>0?e.config.sizes:[t.size||e.config?.default_size||`1024x1024`],r=e.config?.qualities&&e.config.qualities.length>0?e.config.qualities:e.config?.omit_quality_when_empty?[]:[t.quality||e.config?.default_quality||`standard`],i=e.config?.styles&&e.config.styles.length>0?e.config.styles:[];return{pluginId:e.id,model:C(e.models,t.model,void 0,``),size:C(n,t.size,e.config?.default_size,`1024x1024`),quality:r.length>0?C(r,t.quality,e.config?.default_quality,`standard`):``,style:i.length>0?C(i,t.style,e.config?.default_style,i[0]):``,sizes:n,qualities:r,styles:i,maxPromptLength:e.config?.max_prompt_length??null,sizeLabel:e.config?.size_label||``}}var H=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=i(),s=T(e=>e.preferences.imageGenSettings),c=s?.enabled===!0,[l,u]=(0,L.useState)([]),[d,p]=(0,L.useState)(``),[h,v]=(0,L.useState)(``),[b,C]=(0,L.useState)(``),[D,O]=(0,L.useState)(`1024x1024`),[k,A]=(0,L.useState)(`standard`),[j,M]=(0,L.useState)(``),[N,P]=(0,L.useState)(!1),[F,I]=(0,L.useState)(null),[H,U]=(0,L.useState)([`512x512`,`768x768`,`1024x1024`]),[W,G]=(0,L.useState)([`standard`,`high`]),[K,q]=(0,L.useState)([]),[J,Y]=(0,L.useState)(null),[te,ne]=(0,L.useState)(``),X=L.useId(),Z=(0,L.useCallback)((e,t)=>{let n=V(e,t);p(n.pluginId),v(n.model),O(n.size),A(n.quality),M(n.style),U(n.sizes),G(n.qualities),q(n.styles),Y(n.maxPromptLength),ne(n.sizeLabel)},[]);(0,L.useEffect)(()=>{let t=!1;return e&&c&&(async()=>{try{let e=await y.getPlugins();if(t)return;let n=e.success&&e.data?e.data.filter(e=>e.models.length>0):[];u(n);let r=ee(n,s);r?Z(r,s):(p(``),v(``))}catch(e){if(t)return;u([]),p(``),v(``),B.error(`Failed to load image generation plugins:`,e)}})(),()=>{t=!0}},[Z,c,e,s]),(0,L.useEffect)(()=>{if(!e)return;let n=document.body.style.overflow,r=e=>{e.key===`Escape`&&t()};return document.body.style.overflow=`hidden`,document.addEventListener(`keydown`,r),()=>{document.body.style.overflow=n,document.removeEventListener(`keydown`,r)}},[e,t]);let Q=e=>{let t=l.find(t=>t.id===e);t&&Z(t,{model:h,size:D,quality:k,style:j})},re=async()=>{if(!c||!d||!h||!b.trim()){_.error(r(`imageGeneration.enterPrompt`));return}if(J&&b.length>J){_.error(r(`imageGeneration.promptTooLong`,{max:J.toLocaleString()}));return}P(!0),I(null);try{let e=await y.generate({model:h,pluginId:d,prompt:b.trim(),size:D,quality:k,...j?{style:j}:{}});if(e.success&&e.data?.images&&e.data.images.length>0){let i=x(e.data.images[0]);i&&(_.success(r(`imageGeneration.success`)),n?(n(i,b.trim(),h),C(``),I(null),t()):I(i))}else _.error(r(`imageGeneration.failed`))}catch(e){B.error(`Image generation failed:`,e);let t=e instanceof Error?e.message:r(`imageGeneration.failed`);_.error(t)}finally{P(!1)}},ie=()=>{if(!F)return;let e=document.createElement(`a`);e.href=F,e.download=`generated-image-${Date.now()}.${S(F)}`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e||!c)return null;let $=l.find(e=>e.id===d);return(0,R.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":X,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:t}),(0,z.jsxs)(`div`,{className:w(`relative bg-white/95 dark:bg-dark-25/95`,`border border-gray-200/80 dark:border-white/10`,`rounded-3xl shadow-2xl backdrop-blur-xl`,`flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden`),onClick:e=>e.stopPropagation(),children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:[(0,z.jsx)(`div`,{children:(0,z.jsx)(`h2`,{id:X,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,z.jsx)(`button`,{onClick:t,className:`rounded-xl p-2 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-500 dark:hover:bg-white/[0.06] dark:hover:text-dark-900`,title:r(`common.close`,{defaultValue:`Close`}),children:(0,z.jsx)(f,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,z.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 p-5 scrollbar-thin sm:p-6`,children:$?(0,z.jsxs)(z.Fragment,{children:[(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,z.jsx)(`select`,{value:d,onChange:e=>Q(e.target.value),className:w(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:l.map(e=>(0,z.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,z.jsx)(`select`,{value:h,onChange:e=>v(e.target.value),className:w(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:$?.models.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),K.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.style`)}),(0,z.jsx)(`select`,{value:j,onChange:e=>M(e.target.value),className:w(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:K.map(e=>(0,z.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,z.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:te||r(`imageGeneration.size`)}),(0,z.jsx)(`select`,{value:D,onChange:e=>O(e.target.value),className:w(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:H.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))})]}),W.length>0&&(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,z.jsx)(`select`,{value:k,onChange:e=>A(e.target.value),className:w(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:W.map(e=>(0,z.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,z.jsx)(`textarea`,{value:b,onChange:e=>C(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:w(`w-full resize-none rounded-2xl px-4 py-3 text-sm leading-6`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,J&&b.length>J&&`border-red-500 dark:border-red-500`)}),J&&(0,z.jsxs)(`div`,{className:w(`mt-1 text-end text-xs`,b.length>J?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[b.length.toLocaleString(),` /`,` `,J.toLocaleString()]})]}),F&&(0,z.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,z.jsx)(`img`,{src:F,alt:`Generated`,className:`w-full h-auto`}),(0,z.jsx)(`button`,{onClick:ie,className:w(`absolute bottom-3 end-3 rounded-lg p-2`,`bg-white/90 dark:bg-dark-100/90`,`hover:bg-white dark:hover:bg-dark-100`,`border border-gray-200 dark:border-dark-300`,`transition-colors`),title:r(`imageGallery.download`),children:(0,z.jsx)(a,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]}):(0,z.jsxs)(`div`,{className:`text-center py-8`,children:[(0,z.jsx)(m,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,z.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,z.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]})}),$&&(0,z.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,z.jsx)(E,{onClick:re,disabled:N||!c||!b.trim()||!d||!h,className:w(`w-full py-2.5 rounded-xl font-medium`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white`,`disabled:opacity-50 disabled:cursor-not-allowed`,`transition-colors`),children:N?(0,z.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,z.jsx)(g,{className:`h-4 w-4 animate-spin`}),r(`imageGeneration.generating`)]}):(0,z.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,z.jsx)(o,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},U={video:[],audio:[]};function W({isOpen:e,initialKind:t,onClose:n,onGenerated:r}){let{t:a}=i(),[s,c]=(0,L.useState)(t),[u,d]=(0,L.useState)(U),[m,h]=(0,L.useState)(``),[v,y]=(0,L.useState)(``),[x,ee]=(0,L.useState)(`alloy`),[S,C]=(0,L.useState)(``),[T,D]=(0,L.useState)(``),[O,k]=(0,L.useState)(``),[A,j]=(0,L.useState)(!0),[M,N]=(0,L.useState)(!0),[P,F]=(0,L.useState)(!1),I=L.useId();(0,L.useEffect)(()=>{if(!e)return;let t=!1;return b.getModels().then(e=>{t||!e.success||!e.data||d(e.data)}).catch(()=>{t||_.error(a(`mediaGeneration.loadFailed`))}).finally(()=>{t||N(!1)}),()=>{t=!0}},[e,a]);let B=s===`video`?u.video:u.audio,V=B.some(e=>K(e)===m)?m:B[0]?K(B[0]):``,H=(0,L.useMemo)(()=>B.find(e=>K(e)===V),[V,B]),W=s===`video`?H?.config:void 0,Y=s===`audio`?H:void 0;return e?(0,R.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,children:[(0,z.jsx)(`button`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:n,"aria-label":a(`common.close`)}),(0,z.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":I,className:`relative flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-gray-200/80 bg-white/95 shadow-2xl backdrop-blur-xl dark:border-white/10 dark:bg-dark-25/95`,children:[(0,z.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.08] sm:px-5`,children:[(0,z.jsxs)(`div`,{children:[(0,z.jsx)(`h2`,{id:I,className:`text-xl text-gray-950 dark:text-dark-950`,children:a(`mediaGeneration.title`)}),(0,z.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-dark-500`,children:a(`mediaGeneration.description`)})]}),(0,z.jsx)(`button`,{onClick:n,className:`rounded-xl p-2`,children:(0,z.jsx)(f,{className:`h-5 w-5`})})]}),(0,z.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-4 p-4 sm:p-5`,children:[(0,z.jsx)(`div`,{className:`grid grid-cols-2 gap-2 rounded-xl bg-gray-100 p-1 dark:bg-white/[0.05]`,children:[`video`,`audio`].map(e=>(0,z.jsxs)(`button`,{type:`button`,onClick:()=>c(e),className:w(`flex items-center justify-center gap-2 rounded-xl px-3 py-2 text-sm transition-colors`,e===s?`bg-white text-gray-950 shadow-sm dark:bg-white/10 dark:text-white`:`text-gray-500 dark:text-dark-500`),children:[e===`video`?(0,z.jsx)(l,{className:`h-4 w-4`}):(0,z.jsx)(p,{className:`h-4 w-4`}),a(`mediaGeneration.${e}`)]},e))}),M?(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(g,{className:`h-7 w-7 animate-spin`})}):B.length===0?(0,z.jsx)(`div`,{className:`rounded-xl border border-amber-500/25 bg-amber-500/10 p-4 text-sm text-amber-800 dark:text-amber-200`,children:a(`mediaGeneration.noModels`,{kind:a(`mediaGeneration.${s}`)})}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(G,{label:a(`mediaGeneration.model`),children:(0,z.jsx)(`select`,{value:V,onChange:e=>{h(e.target.value),C(``),D(``),k(``),j(!0)},className:J,children:B.map(e=>(0,z.jsxs)(`option`,{value:K(e),children:[e.model,` (`,e.plugin,`mode`in e?` · ${a(`mediaGeneration.${e.mode}`)}`:``,`)`]},K(e)))})}),s===`audio`?(0,z.jsx)(G,{label:a(`mediaGeneration.voice`),children:(0,z.jsx)(`input`,{value:x,onChange:e=>ee(e.target.value),className:J,placeholder:`alloy`})}):(0,z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[(0,z.jsx)(G,{label:a(`mediaGeneration.resolution`),children:(0,z.jsxs)(`select`,{value:S,onChange:e=>C(e.target.value),className:J,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),W?.resolutions?.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})}),(0,z.jsx)(G,{label:a(`mediaGeneration.aspectRatio`),children:(0,z.jsxs)(`select`,{value:T,onChange:e=>D(e.target.value),className:J,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),W?.aspect_ratios?.map(e=>(0,z.jsx)(`option`,{value:e,children:e},e))]})}),(0,z.jsx)(G,{label:a(`mediaGeneration.duration`),children:(0,z.jsxs)(`select`,{value:O,onChange:e=>k(e.target.value),className:J,children:[(0,z.jsx)(`option`,{value:``,children:a(`mediaGeneration.providerDefault`)}),W?.durations?.map(e=>(0,z.jsxs)(`option`,{value:e,children:[e,`s`]},e))]})})]}),s===`video`&&W?.supports_audio&&(0,z.jsxs)(`label`,{className:`flex items-center gap-3 text-sm`,children:[(0,z.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>j(e.target.checked)}),a(`mediaGeneration.generateAudio`)]}),(0,z.jsx)(G,{label:s===`video`||Y?.mode===`sound`?a(`mediaGeneration.prompt`):a(`mediaGeneration.text`),children:(0,z.jsx)(`textarea`,{value:v,onChange:e=>y(e.target.value),rows:6,className:w(J,`resize-none`),placeholder:a(s===`audio`&&Y?.mode===`sound`?`mediaGeneration.soundPlaceholder`:`mediaGeneration.${s}Placeholder`)})})]})]}),B.length>0&&(0,z.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-5`,children:(0,z.jsxs)(E,{onClick:async()=>{if(!(!H||!v.trim())){F(!0);try{if(s===`audio`){let e=Y?.mode===`sound`?await b.generateSound({model:H.model,pluginId:H.plugin,prompt:v.trim(),voice:x.trim()||void 0,format:`wav`}):await b.generateAudio({model:H.model,pluginId:H.plugin,input:v.trim(),voice:x.trim()||void 0,response_format:`mp3`});if(!e.success)throw Error(e.message)}else{let e=await b.generateVideo({model:H.model,pluginId:H.plugin,prompt:v.trim(),...O?{duration:Number(O)}:{},...S?{resolution:S}:{},...T?{aspect_ratio:T}:{},...W?.supports_audio?{generate_audio:A}:{}});if(!e.success||!e.data)throw Error(e.message||a(`mediaGeneration.failed`));let t=e.data,n=0;for(;t.status===`pending`||t.status===`in_progress`;){await q(3e4);try{let e=await b.getVideoJob(t.id);if(!e.success||!e.data)throw Error(e.message||a(`mediaGeneration.failed`));t=e.data,n=0}catch(e){if(n+=1,n>=5)throw e}}if(t.status===`failed`)throw Error(t.error||a(`mediaGeneration.failed`))}_.success(a(`mediaGeneration.success`)),y(``),r(),n()}catch(e){_.error(e instanceof Error?e.message:a(`mediaGeneration.failed`))}finally{F(!1)}}},disabled:P||!H||!v.trim(),className:`w-full gap-2`,children:[P?(0,z.jsx)(g,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(o,{className:`h-4 w-4`}),a(P?`mediaGeneration.generating`:`mediaGeneration.generate`)]})})]})]}),document.body):null}function G({label:e,children:t}){return(0,z.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-gray-700 dark:text-gray-300`,children:[(0,z.jsx)(`span`,{children:e}),t]})}function K(e){return`${e.mode||`default`}::${e.plugin}::${e.model}`}function q(e){return new Promise(t=>window.setTimeout(t,e))}var J=`w-full rounded-xl border border-gray-200/80 bg-white/70 px-3 py-2.5 text-sm text-gray-900 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.035] dark:text-gray-100`,Y=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:o}=i();return(0,L.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[t]),(0,R.createPortal)((0,z.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,z.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,z.jsxs)(`div`,{className:`relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4`,onClick:e=>e.stopPropagation(),children:[(0,z.jsx)(`button`,{onClick:t,className:w(`absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10`,`p-2 rounded-full`,`bg-white/10 hover:bg-white/20`,`transition-colors`),children:(0,z.jsx)(f,{className:`h-6 w-6 text-white`})}),(0,z.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,z.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,z.jsxs)(`div`,{className:w(`w-full lg:w-80 flex-shrink-0`,`bg-white dark:bg-dark-100`,`rounded-xl p-4 lg:p-5`,`overflow-y-auto max-h-[25vh] lg:max-h-[90vh]`),children:[(0,z.jsxs)(`div`,{className:`mb-4`,children:[(0,z.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:o(`gallery.prompt`)}),(0,z.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,z.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(s,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.model`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(h,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.size`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 text-xs font-bold`,children:`Q`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.quality`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,z.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,z.jsx)(c,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,z.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.created`),`:`]}),(0,z.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:(e=>new Date(e).toLocaleString(void 0,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}))(e.createdAt)})]})]}),(0,z.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,z.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.${S(e.imageData)}`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:w(`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white font-medium text-sm`,`transition-colors`),children:[(0,z.jsx)(a,{className:`h-4 w-4`}),o(`gallery.download`)]}),n&&(0,z.jsx)(`button`,{onClick:()=>n(e.id),className:w(`p-2.5 rounded-lg`,`bg-gray-100 dark:bg-dark-200`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`text-gray-600 dark:text-gray-300`,`hover:text-red-600 dark:hover:text-red-400`,`transition-colors`),title:`Delete image`,children:(0,z.jsx)(u,{className:`h-4 w-4`})})]})]})]})]}),document.body)};function te({kind:e,refreshKey:t,onCountChange:n}){let{t:r}=i(),o=M(),[s,c]=(0,L.useState)(null),[l,f]=(0,L.useState)(null),p=I({queryKey:[`media-gallery`,e||`all`,t||0],queryFn:async({pageParam:t})=>{let n=await b.getGallery({limit:20,offset:t,...e?{kind:e}:{}});if(!n.success||!n.data)throw Error(n.message||r(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.media.length,0);return n<e.total?n:void 0}}),m=(0,L.useMemo)(()=>p.data?.pages.flatMap(e=>e.media)||[],[p.data]),h=p.data?.pages[0]?.total||0;(0,L.useEffect)(()=>n?.(h),[n,h]);let v=async e=>{if(!l){f(e.id);try{let t=await b.deleteGalleryItem(e.id);if(!t.success)throw Error(t.message);c(null),await o.invalidateQueries({queryKey:[`media-gallery`]}),_.success(r(`imageGallery.deleteSuccess`))}catch{_.error(r(`imageGallery.deleteFailed`))}finally{f(null)}}},y=async e=>{let t=await b.getGalleryContent(e.id),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`generated-${e.id}.${Z(e.mimeType)}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)};return p.isLoading?(0,z.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,z.jsx)(g,{className:`h-8 w-8 animate-spin text-gray-400`})}):m.length===0?(0,z.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-12 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,z.jsx)(d,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,z.jsx)(`h3`,{className:`text-lg font-medium`,children:r(`mediaGallery.empty`)}),(0,z.jsx)(`p`,{className:`mt-2 max-w-sm text-gray-500 dark:text-gray-400`,children:r(`mediaGallery.emptyHint`)})]}):(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:m.map(e=>(0,z.jsxs)(`article`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/70 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,z.jsx)(ne,{item:e,onOpenImage:t=>c(X(e,t))}),(0,z.jsxs)(`div`,{className:`space-y-3 p-3`,children:[(0,z.jsx)(`p`,{className:`line-clamp-2 text-sm text-gray-800 dark:text-gray-200`,children:e.prompt}),(0,z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,z.jsx)(`span`,{className:`min-w-0 truncate text-xs text-gray-500`,children:e.model}),(0,z.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,z.jsx)(`button`,{onClick:()=>void y(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:r(`imageGallery.download`),children:(0,z.jsx)(a,{className:`h-4 w-4`})}),(0,z.jsx)(`button`,{onClick:()=>void v(e),disabled:l===e.id,className:`rounded-lg p-1.5 hover:bg-red-500/15 hover:text-red-500`,title:r(`imageGallery.delete`),children:l===e.id?(0,z.jsx)(g,{className:`h-4 w-4 animate-spin`}):(0,z.jsx)(u,{className:`h-4 w-4`})})]})]})]})]},e.id))}),p.hasNextPage&&(0,z.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,z.jsx)(E,{variant:`outline`,disabled:p.isFetchingNextPage,onClick:()=>void p.fetchNextPage(),children:p.isFetchingNextPage?r(`common.loading`):r(`imageGallery.loadMore`,{current:m.length,total:h})})}),s&&(0,z.jsx)(Y,{image:s,onClose:()=>c(null),onDelete:e=>{let t=m.find(t=>t.id===e);t&&v(t)},onDownload:e=>{let t=m.find(t=>t.id===e.id);t&&y(t)}})]})}function ne({item:e,onOpenImage:t}){let{data:n,isLoading:r}=A({queryKey:[`media-gallery-content`,e.id],queryFn:()=>b.getGalleryContent(e.id),staleTime:3e5}),i=(0,L.useMemo)(()=>n?URL.createObjectURL(n):``,[n]);return(0,L.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),r||!i?(0,z.jsx)(`div`,{className:`flex aspect-video items-center justify-center bg-gray-100 dark:bg-white/[0.03]`,children:(0,z.jsx)(g,{className:`h-6 w-6 animate-spin text-gray-400`})}):e.kind===`image`?(0,z.jsx)(`button`,{className:`block aspect-square w-full overflow-hidden`,onClick:()=>t(i),children:(0,z.jsx)(`img`,{src:i,alt:e.prompt,className:`h-full w-full object-cover`,loading:`lazy`})}):e.kind===`video`?(0,z.jsx)(`div`,{className:`aspect-video bg-black`,children:(0,z.jsx)(`video`,{src:i,controls:!0,preload:`metadata`,className:`h-full w-full object-contain`})}):(0,z.jsxs)(`div`,{className:`flex min-h-40 flex-col items-center justify-center gap-3 bg-gradient-to-br from-primary-500/10 to-cyan-500/10 p-4`,children:[(0,z.jsx)(p,{className:`h-9 w-9 text-primary-500`}),(0,z.jsx)(`audio`,{src:i,controls:!0,preload:`metadata`,className:`w-full`})]})}function X(e,t){return{id:e.id,userId:e.userId,prompt:e.prompt,model:e.model,imageData:t,size:e.size,quality:e.quality,createdAt:e.createdAt}}function Z(e){let t=e.split(`/`)[1]?.split(`;`)[0];return t===`mpeg`?e.startsWith(`audio/`)?`mp3`:`mpeg`:t===`svg+xml`?`svg`:t||`bin`}var Q=()=>{let{t:e}=i(),[t,n]=(0,L.useState)(null),[r,a]=(0,L.useState)(!1),[o,s]=(0,L.useState)(null),[c,u]=(0,L.useState)(`all`),[d,f]=(0,L.useState)(0),h=T(e=>e.preferences.imageGenSettings?.enabled===!0),g=(0,L.useCallback)(()=>{f(e=>e+1)},[]);return(0,z.jsxs)(D,{width:`wide`,children:[(0,z.jsx)(O,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,z.jsx)(`span`,{className:`inline-flex rounded-full border border-gray-200/80 bg-white/60 px-2.5 py-1 text-xs text-gray-500 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-500`,children:e(`mediaGallery.itemCount`,{count:t})}):null,actions:(0,z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,z.jsxs)(E,{onClick:()=>{h&&a(!0)},disabled:!h,className:`gap-2 px-4`,children:[(0,z.jsx)(m,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]}),(0,z.jsxs)(E,{variant:`outline`,onClick:()=>s(`video`),className:`gap-2 px-4`,children:[(0,z.jsx)(l,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.video`)]}),(0,z.jsxs)(E,{variant:`outline`,onClick:()=>s(`audio`),className:`gap-2 px-4`,children:[(0,z.jsx)(p,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.audio`)]})]})}),(0,z.jsx)(`div`,{className:`mb-5 flex flex-wrap gap-2`,children:[`all`,`image`,`video`,`audio`].map(t=>(0,z.jsx)(`button`,{type:`button`,onClick:()=>u(t),className:w(`rounded-full border px-3 py-1.5 text-sm transition-colors`,c===t?`border-gray-950 bg-gray-950 text-white dark:border-white dark:bg-white dark:text-gray-950`:`border-gray-200 text-gray-600 hover:border-gray-400 dark:border-white/10 dark:text-dark-600`),children:e(`mediaGallery.filters.${t}`)},t))}),(0,z.jsx)(te,{kind:c===`all`?void 0:c,refreshKey:d,onCountChange:n}),(0,z.jsx)(H,{isOpen:r&&h,onClose:()=>a(!1),onImageGenerated:g}),(0,z.jsx)(W,{isOpen:o!==null,initialKind:o||`video`,onClose:()=>s(null),onGenerated:g},o||`closed`)]})};export{Q as GalleryPage,Q as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{d as r}from"./router-vendor-Ca9zqOqT.js";import{t as i}from"./useTranslation-CdeLZqSW.js";import{T as a,Ut as o,Y as s,c,hn as l,tt as u,un as d,wt as f}from"./ui-vendor-D_pYT79f.js";import{i as p,n as m,t as h}from"./utils-BhpNrGnR.js";import{t as g}from"./chatStore-CWqfsOjc.js";import{l as _,n as v}from"./authStore-DmrydYuS.js";import{a as y,c as b,o as x,s as S,t as C}from"../assets/index-Cd0_AoYV.js";import{t as w}from"./work-DVgm81bJ.js";var T=e(n(),1),E=t(),D=e=>e<5?[`home.greeting.night`,`Up late`]:e<12?[`home.greeting.morning`,`Morning`]:e<18?[`home.greeting.afternoon`,`Afternoon`]:[`home.greeting.evening`,`Evening`],O=`mb-2 text-xs font-medium text-gray-500 dark:text-dark-500`,k=`group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-start text-sm text-gray-700 transition-colors hover:bg-white hover:text-gray-950 dark:text-dark-700 dark:hover:bg-dark-200 dark:hover:text-dark-950 outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`,A=()=>{let{t:e,i18n:t}=i(),n=r(),{user:A,systemInfo:j,isAdmin:M}=v(),N=g(e=>e.sessions),P=_(e=>e.tasks),F=_(e=>e.capabilities),I=_(e=>e.loadTasks),L=_(e=>e.loadCapabilities),R=j?.requiresAuth===!1||M(),z=R;(0,T.useEffect)(()=>{R&&(I(!0).catch(()=>{}),L().catch(()=>{}))},[R,I,L]);let[B,V]=D(new Date().getHours()),H=e(B,V),U=A?.username,W=[...N].sort((e,t)=>t.updatedAt-e.updatedAt).slice(0,4),G=[...P].sort((e,t)=>new Date(t.updatedAt).getTime()-new Date(e.updatedAt).getTime()).slice(0,3),K=F?.activeRuntimes?.user??0,q=p()?`⌘`:`Ctrl`,J=W.length>0||G.length>0,Y=C(j?.version);return(0,E.jsx)(`div`,{"data-testid":`home-page`,className:`h-full overflow-y-auto scrollbar-thin`,children:(0,E.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-xl flex-col justify-center px-6 py-12`,children:[(0,E.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-gray-950 dark:text-dark-950`,children:U?`${H}, ${U}.`:`${H}.`}),(0,E.jsxs)(`p`,{"data-testid":`app-version`,className:`mt-1 font-mono text-xs text-gray-400 dark:text-dark-500`,children:[window.location.host||`Libre WebUI`,Y?` · v${Y}`:``]}),(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsx)(`p`,{className:O,children:e(`home.start`,`Start`)}),(0,E.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-new-chat`,className:k,onClick:()=>x(n),children:[(0,E.jsx)(u,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,E.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newChat`,`New Chat`)}),(0,E.jsxs)(`span`,{className:`font-mono text-[10px] tracking-wide text-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,children:[q,`⇧O`]})]}),(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-incognito-chat`,className:k,onClick:()=>y(n),children:[(0,E.jsx)(f,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,E.jsx)(`span`,{className:`flex-1`,children:e(`chat.session.incognito`,`Incognito Chat`)})]}),R&&(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-new-work`,className:k,onClick:()=>S(n),children:[(0,E.jsx)(d,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,E.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newWork`,`New Work`)}),(0,E.jsxs)(`span`,{className:`font-mono text-[10px] tracking-wide text-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,children:[q,`⇧U`]})]})]})]}),J&&(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsxs)(`div`,{className:`mb-2 flex items-baseline justify-between`,children:[(0,E.jsx)(`p`,{className:h(O,`mb-0`),children:e(`home.continue`,`Continue`)}),R&&K>0&&(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,E.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse-subtle rounded-full bg-[rgb(48,121,255)]`}),K,` `,e(`home.active`,`active`)]})]}),(0,E.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[G.map(r=>{let i=b[r.status];return(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-work`,className:k,onClick:()=>n(`/work/${r.id}`),children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:h(`h-2 w-2 shrink-0 rounded-full ring-1 ring-black/[0.06] dark:ring-white/[0.1]`,i.animated&&`animate-pulse-subtle`),style:{backgroundColor:i.color}}),(0,E.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`work.tasks.untitled`,`Untitled task`)}),r.hostPath&&(0,E.jsx)(`span`,{className:`hidden max-w-[14rem] shrink-0 truncate font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,title:r.hostPath,children:r.hostPath}),(0,E.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:w(r)?e(i.labelKey,i.label):m(new Date(r.updatedAt).getTime(),t.language)})]},r.id)}),W.map(r=>(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-chat`,className:k,onClick:()=>n(`/c/${r.id}`),children:[(0,E.jsx)(u,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,E.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`tabs.chat`,`Chat`)}),(0,E.jsx)(`span`,{className:`hidden shrink-0 font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,children:r.model}),(0,E.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:m(r.updatedAt,t.language)})]},r.id))]})]}),(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsx)(`p`,{className:O,children:e(`home.explore`,`Explore`)}),(0,E.jsx)(`div`,{className:`-mx-2.5 flex flex-col`,children:[[`/notes`,s,e(`sidebar.navigation.notes`,`Notes`)],[`/models`,o,e(`sidebar.navigation.models`,`Models`)],[`/personas`,c,e(`sidebar.navigation.personas`,`Personas`)],[`/gallery`,a,e(`sidebar.navigation.imagine`,`Imagine`)],...z?[[`/agents`,l,e(`sidebar.navigation.agents`,`Agents`)]]:[]].map(([e,t,r])=>(0,E.jsxs)(`button`,{type:`button`,className:k,onClick:()=>n(e),children:[(0,E.jsx)(t,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,E.jsx)(`span`,{className:`flex-1`,children:r})]},e))})]})]})})};export{A as HomePage,A as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{n as r}from"./react-vendor-DPNXrO-8.js";import{d as i}from"./router-vendor-Ca9zqOqT.js";import{t as a}from"./useTranslation-CdeLZqSW.js";import{B as o,Bt as s,Ht as c,P as l,R as u,T as d,Tn as f,Wt as p,Yt as m,an as h,c as g,dn as _,gt as v,hn as y,n as b,on as x,ot as S,pt as C,t as w,v as T,vt as ee}from"./ui-vendor-D_pYT79f.js";import{t as te}from"./logger-DSXjF4ye.js";import{m as E,v as ne}from"./api-MySpmAK8.js";import{t as D}from"./utils-BhpNrGnR.js";import{s as re}from"./chatStore-CWqfsOjc.js";import{n as ie}from"./authStore-DmrydYuS.js";import{f as ae}from"../assets/index-Cd0_AoYV.js";var O=e(n(),1),oe=r(),k=t();function A(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function se({hfTask:e,hfSort:t,canInstallModels:n,loadingHf:r,hfModels:i,expandedHfModel:o,hfGgufFiles:l,loadingGguf:d,pullingModel:f,pullProgress:p,setHfTask:m,setHfSort:g,onToggleHfModel:_,onPullHfGguf:y,onCancelPull:x,onRefreshHfModels:C}){let{t:T}=a();return(0,k.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,k.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0 space-y-2`,children:(0,k.jsxs)(`div`,{className:`flex gap-2`,children:[(0,k.jsxs)(`select`,{value:e,onChange:e=>m(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`flex-1 px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,children:[(0,k.jsx)(`option`,{value:`text-generation`,children:T(`modelManager.huggingface.taskTextGeneration`)}),(0,k.jsx)(`option`,{value:`text-to-speech`,children:T(`modelManager.huggingface.taskTextToSpeech`)}),(0,k.jsx)(`option`,{value:`text-to-image`,children:T(`modelManager.huggingface.taskTextToImage`)}),(0,k.jsx)(`option`,{value:`automatic-speech-recognition`,children:T(`modelManager.huggingface.taskSpeechRecognition`)})]}),(0,k.jsxs)(`select`,{value:t,onChange:e=>g(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,children:[(0,k.jsx)(`option`,{value:`downloads`,children:T(`modelManager.huggingface.sortDownloads`)}),(0,k.jsx)(`option`,{value:`likes`,children:T(`modelManager.huggingface.sortLikes`)}),(0,k.jsx)(`option`,{value:`lastModified`,children:T(`modelManager.huggingface.sortRecent`)})]})]})}),(0,k.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin`,children:[!n&&(0,k.jsx)(`div`,{className:`mx-3 mb-1 mt-3 rounded-lg border border-amber-200 bg-amber-500/10 px-3 py-2 text-xs text-ink dark:border-amber-800 dark:bg-amber-900/20`,children:T(`modelSelector.pullRestricted`)}),r?(0,k.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,k.jsx)(S,{className:`h-6 w-6 animate-spin text-gray-400`})}):i.length===0?(0,k.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,k.jsx)(w,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,k.jsx)(`p`,{className:`text-sm`,children:T(`modelManager.huggingface.noModelsFound`)})]}):(0,k.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:i.map(e=>{let t=o===e.id,r=l[e.id]||[],i=d===e.id;return(0,k.jsxs)(`div`,{className:`bg-white dark:bg-dark-100`,children:[(0,k.jsx)(`div`,{className:`px-3 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-200`,onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),_(e.id)},children:(0,k.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,k.jsx)(`div`,{className:`flex-shrink-0 rounded-lg bg-yellow-500/20 p-2 dark:bg-yellow-900/30`,children:(0,k.jsx)(w,{className:`h-4 w-4 text-yellow-600 dark:text-yellow-400`})}),(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`h4`,{dir:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.id}),e.gated&&(0,k.jsx)(`span`,{className:`rounded bg-yellow-500/20 px-1.5 py-0.5 text-xs text-ink dark:bg-yellow-900/30`,children:`Gated`})]}),(0,k.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-0.5`,children:[`by `,e.author]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 text-xs text-gray-400 dark:text-gray-500`,children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,k.jsx)(c,{className:`h-3 w-3`}),A(e.downloads)]}),(0,k.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,k.jsx)(v,{className:`h-3 w-3`}),A(e.likes)]}),e.pipeline_tag&&(0,k.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200`,children:e.pipeline_tag})]})]}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,k.jsx)(`a`,{href:`https://huggingface.co/${e.id}`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,k.jsx)(s,{className:`h-4 w-4 text-gray-400`})}),(0,k.jsx)(h,{className:D(`h-4 w-4 text-gray-400 transition-transform`,t&&`rotate-180`)})]})]})}),t&&(0,k.jsx)(`div`,{className:`px-3 pb-3 pt-1 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-200`,children:i?(0,k.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,k.jsx)(S,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,k.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:T(`modelManager.huggingface.checkingGguf`)})]}):r.length===0?(0,k.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:T(`modelManager.huggingface.noGgufAvailable`)}):(0,k.jsxs)(`div`,{className:`space-y-2`,children:[(0,k.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 mb-2`,children:T(`modelManager.huggingface.ggufFilesCount`,{count:r.length})}),r.map(e=>{let t=f===e.ollamaCommand;return(0,k.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-white dark:bg-dark-100 border border-gray-200 dark:border-dark-300`,children:[(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 truncate`,children:e.filename}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,k.jsx)(`span`,{children:e.sizeFormatted}),e.quantization&&(0,k.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-400`,children:e.quantization})]})]}),t?(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:p?.percent===void 0?`...`:`${p.percent}%`}),(0,k.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),x()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,k.jsx)(b,{className:`h-4 w-4`})})]}):n?(0,k.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),y(e.ollamaCommand,e.filename)},disabled:!!f,className:D(`px-3 py-1.5 rounded-lg text-xs font-medium`,`bg-primary-100 dark:bg-primary-900/30`,`text-primary-700 dark:text-primary-400`,`hover:bg-primary-200 dark:hover:bg-primary-900/50`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,k.jsx)(c,{className:`h-3 w-3 inline mr-1`}),T(`models.pull`)]}):(0,k.jsx)(`span`,{className:`rounded bg-amber-500/20 px-2 py-1 text-[11px] font-medium text-ink dark:bg-amber-900/30`,children:T(`modelSelector.adminOnlyPull`)})]},e.filename)}),f?.startsWith(`hf.co/`)&&f.includes(e.id)&&p?.percent!==void 0&&(0,k.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,k.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${p.percent}%`}})})]})})]},e.id)})})]}),(0,k.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 flex items-center justify-between flex-shrink-0`,children:[(0,k.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 hover:underline flex items-center gap-1`,children:[(0,k.jsx)(s,{className:`h-3 w-3`}),T(`modelManager.huggingface.browseAllLink`)]}),(0,k.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),C()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,k.jsx)(u,{className:D(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}function ce({filteredGroups:e,selectedModel:t,showImageGen:n,getModelValue:r,getModelIcon:i,getModelLabel:s,getModelSubLabel:c,onModelSelect:l,onOpenGallery:u}){let{t:d}=a();return(0,k.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400`,children:[e.length>0?e.map(e=>(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-dark-300 border-b border-gray-200 dark:border-dark-400 sticky top-0`,children:(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon,e.label,` (`,e.models.length,`)`]})}),e.models.map(e=>{let n=r(e);return(0,k.jsx)(`button`,{type:`button`,"data-testid":`model-selector-option`,"data-model-value":n,"aria-pressed":t===n,onClick:()=>l(n),className:D(`block w-full cursor-pointer border-b border-gray-100 px-3 py-3 text-start last:border-b-0 dark:border-dark-200`,`hover:bg-gray-50 dark:hover:bg-dark-200`,`bg-white dark:bg-dark-100 transition-colors`,`focus-visible:relative focus-visible:z-10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500/50`,t===n&&`bg-primary-50 dark:bg-primary-900/30`),children:(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[i(e),(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsx)(`div`,{dir:e.isPersona?`auto`:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:s(e)}),c(e)&&(0,k.jsx)(`div`,{dir:`auto`,className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:c(e)})]}),t===n&&(0,k.jsx)(x,{className:`h-4 w-4 text-primary-600 dark:text-primary-400 flex-shrink-0`})]})},n)})]},e.type)):(0,k.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,k.jsx)(p,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,k.jsx)(`p`,{className:`text-sm`,children:d(`models.noModelsFound`)})]}),n&&(0,k.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-dark-300`,children:[(0,k.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-dark-300`,children:(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(o,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),d(`modelSelector.actions`)]})}),(0,k.jsx)(`div`,{onMouseDown:e=>{e.preventDefault(),u()},className:`px-3 py-3 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-900/20 bg-white dark:bg-dark-100`,children:(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,k.jsx)(C,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),(0,k.jsxs)(`div`,{className:`flex-1`,children:[(0,k.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:d(`gallery.generate`)}),(0,k.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:d(`gallery.generateDescription`)})]})]})})]})]})}function le({libraryCategories:e,libraryCategory:t,canInstallModels:n,loadingLibrary:r,filteredLibraryModels:i,pullingModel:o,pullProgress:l,setLibraryCategory:d,isModelInstalled:f,onModelSelect:p,onPullModel:h,onCancelPull:g,onRefreshLibrary:_}){let{t:v}=a();return(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden`,children:[(0,k.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0`,children:(0,k.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,k.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),d(e)},className:D(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,t===e?`bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-dark-300`),children:e.charAt(0).toUpperCase()+e.slice(1)},e))})}),(0,k.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin`,children:[!n&&(0,k.jsx)(`div`,{className:`mx-3 mb-1 mt-3 rounded-lg border border-amber-200 bg-amber-500/10 px-3 py-2 text-xs text-ink dark:border-amber-800 dark:bg-amber-900/20`,children:v(`modelSelector.pullRestricted`)}),r?(0,k.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,k.jsx)(S,{className:`h-6 w-6 animate-spin text-gray-400`})}):i.length===0?(0,k.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,k.jsx)(m,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,k.jsx)(`p`,{className:`text-sm`,children:v(`models.noModelsFound`)})]}):(0,k.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:i.map(e=>{let t=f(e.name),r=o===e.name;return(0,k.jsxs)(`div`,{className:D(`px-3 py-3 bg-white dark:bg-dark-100`,t&&`bg-green-50/50 dark:bg-green-900/10`),children:[(0,k.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,k.jsx)(`div`,{className:`p-2 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex-shrink-0`,children:(0,k.jsx)(m,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`})}),(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`h4`,{dir:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.name}),t&&(0,k.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`,children:v(`modelSelector.installed`)}),(e.category===`cloud`||e.tags?.includes(`cloud`))&&(0,k.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400 flex items-center gap-1`,children:[(0,k.jsx)(m,{className:`h-3 w-3`}),`Cloud`]})]}),(0,k.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 line-clamp-1 mt-0.5`,children:e.description}),(0,k.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[e.sizes.slice(0,3).map(e=>(0,k.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:e},e)),e.pulls&&(0,k.jsxs)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1`,children:[(0,k.jsx)(c,{className:`h-3 w-3`}),e.pulls]})]})]}),(0,k.jsx)(`div`,{className:`flex-shrink-0`,children:r?(0,k.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,k.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:l?.percent===void 0?`...`:`${l.percent}%`}),(0,k.jsx)(`button`,{onClick:g,className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,k.jsx)(b,{className:`h-4 w-4`})})]}):t?(0,k.jsx)(`button`,{onClick:()=>p(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-900/50`,children:v(`modelSelector.use`)}):n?(0,k.jsxs)(`button`,{onClick:()=>h(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50`,children:[(0,k.jsx)(c,{className:`h-3 w-3 inline mr-1`}),v(`modelSelector.pull`)]}):(0,k.jsx)(`span`,{className:`rounded bg-amber-500/20 px-2 py-1 text-[11px] font-medium text-ink dark:bg-amber-900/30`,children:v(`modelSelector.adminOnlyPull`)})})]}),r&&l?.percent!==void 0&&(0,k.jsx)(`div`,{className:`mt-2 w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden`,children:(0,k.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${l.percent}%`}})})]},e.name)})})]}),(0,k.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 flex items-center justify-between flex-shrink-0`,children:[(0,k.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 hover:underline flex items-center gap-1`,children:[(0,k.jsx)(s,{className:`h-3 w-3`}),v(`modelManager.huggingface.browseAllLink`)]}),(0,k.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),_()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,k.jsx)(u,{className:D(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}var ue=te(`components:model-selector`),j=({models:e,selectedModel:t,onModelChange:n,currentPersona:r,className:o,disabled:s=!1,compact:c=!1,showImageGen:u=!1,onModelsRefresh:p,getModelValue:v,getModelLabel:x,getModelTitle:S,triggerRef:C,triggerTestId:te,selectTestId:A,ariaLabel:j})=>{let{t:M}=a(),[N,de]=(0,O.useState)(!1),[P,fe]=(0,O.useState)(``),[F,I]=(0,O.useState)(`installed`),pe=(0,O.useRef)(null),L=(0,O.useRef)(null),R=(0,O.useRef)(null),z=(0,O.useRef)(null),me=i(),{user:he,systemInfo:ge}=ie(),B=he?.role===`admin`||ge?.requiresAuth===!1,[V,_e]=(0,O.useState)(`all`),[ve,ye]=(0,O.useState)(``),[H,be]=(0,O.useState)(`text-generation`),[U,xe]=(0,O.useState)(`downloads`),[Se,Ce]=(0,O.useState)(``),[W,we]=(0,O.useState)(null),[G,Te]=(0,O.useState)({}),[Ee,De]=(0,O.useState)(null),[K,q]=(0,O.useState)(null),[Oe,J]=(0,O.useState)(null),[ke,Y]=(0,O.useState)(null),Ae=[`all`,`general`,`coding`,`reasoning`,`vision`,`embedding`,`cloud`],je=[{type:`legacy`,label:M(`modelSelector.providerNotRecorded`,`Provider not recorded`),icon:(0,k.jsx)(_,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isLegacySelection),color:`gray`},{type:`unavailable`,label:M(`modelSelector.unavailableSelections`,`Unavailable selections`),icon:(0,k.jsx)(b,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isUnavailable&&!e.isLegacySelection),color:`gray`},{type:`personas`,label:M(`modelSelector.personas`),icon:(0,k.jsx)(g,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPersona&&!e.isUnavailable),color:`purple`},{type:`agents`,label:M(`modelSelector.agentModels`,`Agents`),icon:(0,k.jsx)(T,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isAgent&&!e.isUnavailable),color:`green`},{type:`ollama`,label:M(`modelSelector.ollamaModels`),icon:(0,k.jsx)(y,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>re(e)&&!e.name.includes(`embed`)),color:`green`},{type:`plugins`,label:M(`modelSelector.pluginModels`),icon:(0,k.jsx)(w,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPlugin&&!e.isUnavailable),color:`green`}].filter(e=>e.models.length>0).map(e=>({...e,models:e.models.filter(e=>e.name.toLowerCase().includes(P.toLowerCase())||e.personaName&&e.personaName.toLowerCase().includes(P.toLowerCase())||e.pluginName&&e.pluginName.toLowerCase().includes(P.toLowerCase()))})).filter(e=>e.models.length>0),X=e=>v?.(e)??e.name,Z=e.find(e=>X(e)===t);(0,O.useImperativeHandle)(C,()=>R.current);let Q=(0,O.useCallback)((e=!0)=>{de(!1),fe(``),e&&window.requestAnimationFrame(()=>R.current?.focus())},[]),{data:Me=[],isLoading:Ne,refetch:Pe}=ae({queryKey:[`ollama-library-selector`,ve,V===`cloud`?`cloud`:`all`],queryFn:async()=>{let e=await E.getLibraryModels({search:ve||void 0,sort:`popular`,category:V===`cloud`?`cloud`:void 0});return e.success&&e.data?e.data:[]},enabled:N&&F===`ollama`}),{data:Fe=[],isLoading:Ie,refetch:Le}=ae({queryKey:[`hf-models-selector`,H,Se,U],queryFn:async()=>{let e=await ne.getModels({task:H,search:Se||void 0,sort:U,limit:30});return e.success&&e.data?e.data:[]},enabled:N&&F===`huggingface`}),Re=Me.filter(e=>{let t=!P||e.name.toLowerCase().includes(P.toLowerCase())||e.description.toLowerCase().includes(P.toLowerCase()),n=V===`all`||e.category===V;return t&&n}),ze=(0,O.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){De(e);try{let r=await ne.getGgufFiles(t,n);r.success&&r.data&&Te(t=>({...t,[e]:r.data}))}catch(e){ue.error(`Failed to load GGUF files:`,e)}finally{De(null)}}},[]),Be=(0,O.useCallback)(e=>{W===e?we(null):(we(e),G[e]||ze(e))},[W,G,ze]),Ve=(0,O.useCallback)((e,t)=>{if(!B){f.error(M(`modelSelector.pullRestricted`));return}if(!K){q(e),J({status:`starting`});try{let n=E.pullModelStream(e,e=>{J(e)},()=>{J(null),q(null),Y(null),f.success(`Downloaded ${t}`),p?.()},e=>{J(null),q(null),Y(null),f.error(`Failed to download: ${e}`)});Y(()=>n)}catch{J(null),q(null),f.error(`Failed to start download`)}}},[B,p,K,M]);(0,O.useEffect)(()=>{let e=setTimeout(()=>{F===`huggingface`?Ce(P):F===`ollama`&&ye(P)},300);return()=>clearTimeout(e)},[P,F]),(0,O.useEffect)(()=>{if(!N)return;let e=e=>{if(e.key===`Escape`){e.preventDefault(),Q();return}if(e.key===`Tab`&&L.current){let t=Array.from(L.current.querySelectorAll(`button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex="-1"])`)).filter(e=>e.offsetParent!==null),n=t[0],r=t[t.length-1];if(!n||!r)return;e.shiftKey&&document.activeElement===n?(e.preventDefault(),r.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n.focus())}};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[Q,N]),(0,O.useEffect)(()=>{N&&z.current&&z.current.focus()},[N]);let He=async t=>{let r=e.find(e=>X(e)===t)??e.find(e=>!e.isPlugin&&!e.isPersona&&e.name===t),i=r?X(r):t,a=r?.name??t;Q();try{let e=await E.listRunningModels();if(e.success&&e.data){let t=e.data;t.length>0&&(r?.isPlugin!==!0&&t.some(e=>e.name===a||a.startsWith(`persona:`))||await E.unloadAllModels())}}catch(e){ue.warn(`Failed to unload models before switch:`,e)}n({target:{value:i}})},Ue=async e=>{if(!B){f.error(M(`modelSelector.pullRestricted`));return}if(!K){q(e),J({status:`starting`});try{let t=E.pullModelStream(e,e=>{J(e)},()=>{J(null),q(null),Y(null),f.success(`Downloaded ${e}`),p?.()},e=>{J(null),q(null),Y(null),f.error(`Failed to download: ${e}`)});Y(()=>t)}catch{J(null),q(null),f.error(`Failed to start download`)}}},We=()=>{ke&&(ke(),Y(null),q(null),J(null),f.success(`Download cancelled`))},Ge=t=>e.some(e=>re(e)&&(e.name===t||e.name.startsWith(t+`:`))),Ke=e=>e.isLegacySelection?(0,k.jsx)(_,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):e.isPersona?(0,k.jsx)(g,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):e.isPlugin?(0,k.jsx)(w,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):(0,k.jsx)(y,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),$=e=>x?x(e):e.isLegacySelection?`${e.name} (${M(`modelSelector.legacyProvider`,`provider not recorded`)})`:e.isPersona?e.personaName||e.name:e.isAgent?e.isUnavailable?`${e.agentName||e.name} (${M(`modelSelector.unavailable`,`unavailable`)})`:e.agentName||e.name:(e.isPlugin,e.isUnavailable?`${e.name} (${M(`modelSelector.unavailable`,`unavailable`)})`:e.name),qe=e=>e.isLegacySelection?e.isUnavailable?M(`modelSelector.providerUnavailable`,`provider unavailable`):M(`modelSelector.reselectProvider`,`reselect a provider to pin this model`):e.isPersona?`via ${e.model}`:e.isPlugin?e.isUnavailable?`via ${e.pluginName||e.pluginId} · ${M(`modelSelector.providerUnavailable`,`provider unavailable`)}`:`via ${e.pluginName}`:e.isUnavailable?M(`modelSelector.providerUnavailable`,`provider unavailable`):null;return(0,k.jsxs)(`div`,{className:D(`relative`,o),ref:pe,children:[(0,k.jsxs)(`button`,{ref:R,"data-testid":te,type:`button`,onClick:()=>!s&&de(!N),disabled:s,"aria-haspopup":`dialog`,"aria-expanded":N,"aria-label":j&&Z?`${j}: ${$(Z)}`:j,className:D(c?`h-9 sm:h-10 px-2.5 flex items-center justify-between text-start w-full`:`w-full flex items-center justify-between gap-2 px-3 py-2.5 text-start`,`border border-black/[0.06] bg-gray-100/70 dark:border-white/[0.06] dark:bg-dark-300/70`,`rounded-xl text-sm hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500/40`,s?`opacity-50 cursor-not-allowed`:`cursor-pointer`),title:c?Z?S?.(Z)??$(Z):M(`modelSelector.selectModel`):void 0,children:[(()=>{if(!Z)return c?(0,k.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,k.jsx)(y,{className:`h-4 w-4`}),(0,k.jsx)(`span`,{className:`text-xs font-medium text-gray-400 dark:text-gray-500 truncate`,children:M(`modelSelector.selectModel`)})]}):M(`modelSelector.selectModel`);if(c){let e=$(Z);return(0,k.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[Ke(Z),(0,k.jsx)(`span`,{dir:Z.isPersona?`auto`:`ltr`,className:`text-xs font-medium text-gray-700 dark:text-gray-200 truncate`,children:e})]})}let e=$(Z),t=qe(Z);return(0,k.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[Ke(Z),(0,k.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,k.jsx)(`span`,{dir:Z.isPersona?`auto`:`ltr`,className:`text-sm font-medium truncate`,children:e}),t&&(0,k.jsx)(`span`,{dir:`auto`,className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:t})]}),Z.isPersona&&r&&(0,k.jsxs)(`div`,{className:`flex items-center gap-1 ms-auto`,children:[(0,k.jsx)(_,{className:`h-3 w-3 text-gray-500 dark:text-dark-600`}),r.embedding_model&&(0,k.jsx)(d,{className:`h-3 w-3 text-gray-400 dark:text-dark-500`})]})]})})(),(0,k.jsx)(h,{className:D(c?`h-3 w-3`:`h-4 w-4`,`text-gray-400 flex-shrink-0 transition-transform duration-150`,N&&`rotate-180`)})]}),N&&(0,oe.createPortal)((0,k.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-3 sm:p-6`,children:[(0,k.jsx)(`div`,{className:`absolute inset-0 bg-gray-950/55 backdrop-blur-md`,onClick:()=>Q()}),(0,k.jsxs)(`div`,{ref:L,role:`dialog`,"aria-modal":`true`,"aria-label":M(`modelSelector.selectModel`),className:D(`relative flex w-full max-w-xl flex-col overflow-hidden bg-white/[0.98] dark:bg-dark-25/[0.98]`,`h-[min(620px,88vh)] rounded-[1.5rem] border border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_30px_100px_rgba(0,0,0,0.28)] backdrop-blur-xl animate-scale-in`),onClick:e=>e.stopPropagation(),children:[(0,k.jsxs)(`div`,{className:`flex-shrink-0`,children:[(0,k.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4 sm:px-5 sm:pt-5`,children:[(0,k.jsx)(`h2`,{className:`text-lg font-medium tracking-[-0.025em] text-gray-950 dark:text-dark-950 rtl:tracking-normal`,children:M(`modelSelector.selectModel`)}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>Q(),className:`flex h-9 w-9 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-950 dark:text-dark-500 dark:hover:bg-dark-200 dark:hover:text-dark-950`,title:M(`common.close`),children:(0,k.jsx)(b,{className:`h-4 w-4`})})]}),(0,k.jsx)(`div`,{className:`px-4 pb-3 sm:px-5`,children:(0,k.jsxs)(`div`,{className:`relative`,children:[(0,k.jsx)(l,{className:`absolute start-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400`}),(0,k.jsx)(`input`,{ref:z,type:`text`,placeholder:M(F===`installed`?`modelSelector.searchInstalled`:F===`ollama`?`modelSelector.searchOllama`:`modelSelector.searchHuggingFace`),value:P,onChange:e=>fe(e.target.value),className:D(`w-full rounded-xl border border-black/[0.07] bg-gray-100/70 py-2.5 ps-10 pe-4 text-sm dark:border-white/[0.07] dark:bg-dark-200/70`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`text-gray-900 dark:text-dark-900 placeholder:text-gray-400 dark:placeholder:text-dark-500`)})]})}),(0,k.jsxs)(`div`,{className:`mx-4 mb-3 flex rounded-xl bg-gray-100/70 p-1 dark:bg-dark-200/70 sm:mx-5`,children:[(0,k.jsxs)(`button`,{onClick:()=>{I(`installed`)},className:D(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,F===`installed`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":F===`installed`,children:[(0,k.jsx)(ee,{className:`h-4 w-4 inline me-1.5`}),M(`modelSelector.installed`)]}),(0,k.jsxs)(`button`,{onClick:()=>{I(`ollama`)},className:D(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,F===`ollama`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":F===`ollama`,children:[(0,k.jsx)(m,{className:`h-4 w-4 inline me-1.5`}),`Ollama`]}),(0,k.jsxs)(`button`,{onClick:()=>{I(`huggingface`)},className:D(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,F===`huggingface`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":F===`huggingface`,children:[(0,k.jsx)(w,{className:`h-4 w-4 inline me-1.5`}),`HuggingFace`]})]})]}),F===`installed`&&(0,k.jsx)(ce,{filteredGroups:je,selectedModel:t,showImageGen:u,getModelValue:X,getModelIcon:Ke,getModelLabel:$,getModelSubLabel:qe,onModelSelect:He,onOpenGallery:()=>{Q(!1),me(`/gallery`)}}),F===`ollama`&&(0,k.jsx)(le,{libraryCategories:Ae,libraryCategory:V,canInstallModels:B,loadingLibrary:Ne,filteredLibraryModels:Re,pullingModel:K,pullProgress:Oe,setLibraryCategory:_e,isModelInstalled:Ge,onModelSelect:He,onPullModel:Ue,onCancelPull:We,onRefreshLibrary:()=>{Pe()}}),F===`huggingface`&&(0,k.jsx)(se,{hfTask:H,hfSort:U,canInstallModels:B,loadingHf:Ie,hfModels:Fe,expandedHfModel:W,hfGgufFiles:G,loadingGguf:Ee,pullingModel:K,pullProgress:Oe,setHfTask:be,setHfSort:xe,onToggleHfModel:Be,onPullHfGguf:Ve,onCancelPull:We,onRefreshHfModels:()=>{Le()}})]})]}),document.body),(0,k.jsx)(`select`,{"data-testid":A,"aria-label":j,"aria-hidden":`true`,dir:`ltr`,value:t,onChange:n,className:`hidden`,tabIndex:-1,children:e.map(e=>(0,k.jsx)(`option`,{value:X(e),children:$(e)},`${e.isLegacySelection?`legacy`:e.isPersona?`persona`:e.isPlugin?`plugin`:`ollama`}:${e.pluginId||``}:${X(e)}`))})]})};export{j as t};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/ModelManagerModals-D9j9RECi.js","js/rolldown-runtime-hePW80VL.js","js/markdown-core-DHnR5Hw8.js","js/react-vendor-DPNXrO-8.js","js/useTranslation-CdeLZqSW.js","js/ui-vendor-D_pYT79f.js","js/utils-BhpNrGnR.js","js/utils-vendor-1zob7nK9.js","js/Button-X9TT9gTD.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{i as r}from"./router-vendor-Ca9zqOqT.js";import{t as i}from"./useTranslation-CdeLZqSW.js";import{A as a,Bt as o,Et as s,Gt as c,Ht as l,Lt as u,M as d,P as f,R as p,Sn as m,Tn as h,Tt as ee,Wt as g,Xt as _,Yt as v,_ as te,_t as y,an as b,ft as x,gt as S,lt as C,m as w,n as T,nn as E,nt as ne,on as D,ot as re,t as ie,vt as O}from"./ui-vendor-D_pYT79f.js";import{t as ae}from"./logger-DSXjF4ye.js";import{m as k,v as oe}from"./api-MySpmAK8.js";import{t as A}from"./utils-BhpNrGnR.js";import{n as se}from"./authStore-DmrydYuS.js";import{t as j}from"./Button-X9TT9gTD.js";import{n as ce,t as le}from"./ui-DFQiHo_k.js";import{f as M,m as ue}from"../assets/index-Cd0_AoYV.js";var N=e(n(),1),P=t();function de({expanded:e,models:t,search:n,task:r,sort:a,loadingModels:s,canInstallModels:c,expandedModelId:l,loadingGgufModelId:u,ggufFiles:d,pullingModel:m,pullProgress:h,setSearch:ee,setTask:g,setSort:_,onToggle:v,onToggleModel:te,onPullGguf:y,onCancelPull:x,onRefresh:S}){let{t:C}=i();return(0,P.jsxs)(`div`,{className:A(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/[0.03]`,`border-gray-200/80 dark:border-white/10`),children:[(0,P.jsxs)(`button`,{onClick:v,"aria-expanded":e,className:A(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(ie,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,P.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:C(`modelManager.sections.huggingface`,`HuggingFace Hub`)}),t.length>0&&(0,P.jsxs)(`span`,{className:A(`px-2 py-0.5 rounded-full text-xs font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-600 dark:text-gray-400`),children:[t.length,` `,C(`modelManager.library.available`,`available`)]})]}),e?(0,P.jsx)(E,{className:`h-5 w-5 text-gray-500`}):(0,P.jsx)(b,{className:`h-5 w-5 text-gray-500`})]}),e&&(0,P.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,P.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,P.jsxs)(`div`,{className:`relative flex-1`,children:[(0,P.jsx)(f,{className:`absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400 dark:text-gray-500`}),(0,P.jsx)(`input`,{type:`text`,value:n,onChange:e=>ee(e.target.value),placeholder:C(`modelManager.huggingface.search`,`Search HuggingFace models...`),className:A(`w-full rounded-xl border py-2 pe-4 ps-10 text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`)})]}),(0,P.jsxs)(`select`,{value:r,onChange:e=>g(e.target.value),className:A(`px-3 py-2 rounded-lg border text-sm min-w-[160px]`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:[(0,P.jsx)(`option`,{value:`text-generation`,children:C(`modelManager.huggingface.tasks.textGen`,`Text Generation`)}),(0,P.jsx)(`option`,{value:`text-to-speech`,children:C(`modelManager.huggingface.tasks.tts`,`Text to Speech`)}),(0,P.jsx)(`option`,{value:`text-to-image`,children:C(`modelManager.huggingface.tasks.image`,`Text to Image`)}),(0,P.jsx)(`option`,{value:`automatic-speech-recognition`,children:C(`modelManager.huggingface.tasks.stt`,`Speech Recognition`)})]}),(0,P.jsxs)(`select`,{value:a,onChange:e=>_(e.target.value),className:A(`px-3 py-2 rounded-lg border text-sm min-w-[140px]`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:[(0,P.jsx)(`option`,{value:`downloads`,children:C(`modelManager.huggingface.sort.downloads`,`Most Downloads`)}),(0,P.jsx)(`option`,{value:`likes`,children:C(`modelManager.huggingface.sort.likes`,`Most Liked`)}),(0,P.jsx)(`option`,{value:`lastModified`,children:C(`modelManager.huggingface.sort.recent`,`Recently Updated`)})]})]}),!c&&(0,P.jsx)(`p`,{className:`text-xs text-ink`,children:C(`modelManager.pull.restricted`)}),s?(0,P.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,P.jsx)(re,{className:`h-5 w-5 animate-spin text-gray-400`})}):t.length===0?(0,P.jsx)(`div`,{className:`text-center py-8 text-gray-500`,children:C(`modelManager.huggingface.noResults`,`No models found. Try adjusting your search or filters.`)}):(0,P.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:t.map(e=>(0,P.jsx)(fe,{model:e,expanded:l===e.id,loadingGguf:u===e.id,ggufFiles:d[e.id]||[],pullingModel:m,pullProgress:h,canInstallModels:c,onToggle:()=>te(e.id),onPullGguf:y,onCancelPull:x},e.id))}),(0,P.jsxs)(`div`,{className:`flex items-center justify-between pt-2`,children:[(0,P.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,className:A(`inline-flex items-center gap-1.5 text-xs`,`text-primary-600 dark:text-primary-400`,`hover:underline`),children:[(0,P.jsx)(o,{className:`h-3 w-3`}),C(`modelManager.huggingface.browseAll`,`Browse all on HuggingFace`)]}),(0,P.jsxs)(j,{onClick:S,variant:`outline`,size:`sm`,disabled:s,className:A(`gap-1.5`,``,``),children:[(0,P.jsx)(p,{className:A(`h-3.5 w-3.5`,s&&`animate-spin`)}),C(`modelManager.library.refresh`,`Refresh`)]})]})]})]})}function fe({model:e,expanded:t,loadingGguf:n,ggufFiles:r,pullingModel:a,pullProgress:s,canInstallModels:c,onToggle:u,onPullGguf:d,onCancelPull:f}){let{t:p}=i();return(0,P.jsxs)(`div`,{className:A(`rounded-lg border transition-all overflow-hidden`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`hover:shadow-md hover:border-gray-300 dark:hover:border-dark-400`),children:[(0,P.jsxs)(`div`,{className:`p-4 cursor-pointer`,onClick:u,children:[(0,P.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-2`,children:[(0,P.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800 truncate`,children:e.id}),e.gated&&(0,P.jsx)(`span`,{className:A(`px-1.5 py-0.5 rounded text-xs`,`bg-yellow-500/20 dark:bg-yellow-900/30`,`text-ink`),children:p(`modelManager.huggingface.gated`,`Gated`)})]}),(0,P.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-dark-600 mt-0.5`,children:[p(`modelManager.huggingface.by`,`by`),` `,e.author]})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,P.jsx)(`a`,{href:`https://huggingface.co/${e.id}`,target:`_blank`,rel:`noopener noreferrer`,onClick:e=>e.stopPropagation(),className:`p-1.5 rounded-lg hover:bg-gray-200 dark:hover:bg-dark-300 transition-colors`,title:p(`modelManager.huggingface.viewOnHF`,`View on HuggingFace`),children:(0,P.jsx)(o,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`})}),(0,P.jsx)(b,{className:A(`h-4 w-4 text-gray-400 transition-transform`,t&&`rotate-180`)})]})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-500 dark:text-dark-600`,children:[(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(l,{className:`h-3.5 w-3.5`}),F(e.downloads)]}),(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(S,{className:`h-3.5 w-3.5`}),F(e.likes)]}),e.pipeline_tag&&(0,P.jsx)(`span`,{className:A(`px-1.5 py-0.5 rounded`,`bg-gray-200 dark:bg-dark-300`),children:e.pipeline_tag})]})]}),t&&(0,P.jsx)(pe,{modelId:e.id,loading:n,files:r,pullingModel:a,pullProgress:s,canInstallModels:c,onPullGguf:d,onCancelPull:f})]})}function pe({modelId:e,loading:t,files:n,pullingModel:r,pullProgress:a,canInstallModels:o,onPullGguf:s,onCancelPull:c}){let{t:l}=i();return(0,P.jsx)(`div`,{className:`px-4 pb-4 pt-1 border-t border-gray-200 dark:border-dark-300 bg-white dark:bg-dark-100`,children:t?(0,P.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,P.jsx)(re,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,P.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:l(`modelManager.huggingface.checkingGguf`)})]}):n.length===0?(0,P.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:l(`modelManager.huggingface.noGgufAvailable`)}):(0,P.jsxs)(`div`,{className:`space-y-2`,children:[(0,P.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 mb-2`,children:l(`modelManager.huggingface.ggufFilesCount`,{count:n.length})}),n.map(e=>(0,P.jsx)(me,{file:e,pulling:r===e.ollamaCommand,pullProgress:a,canInstallModels:o,disabled:!!r||!o,onPullGguf:s,onCancelPull:c},e.filename)),r?.startsWith(`hf.co/`)&&r.includes(e)&&a?.percent!==void 0&&(0,P.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,P.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${a.percent}%`}})})]})})}function me({file:e,pulling:t,disabled:n,pullProgress:r,onPullGguf:a,onCancelPull:o}){let{t:s}=i();return(0,P.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-200 dark:border-dark-300`,children:[(0,P.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,P.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 truncate`,children:e.filename}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,P.jsx)(`span`,{children:e.sizeFormatted}),e.quantization&&(0,P.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-400`,children:e.quantization})]})]}),t?(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:r?.percent===void 0?`...`:`${r.percent}%`}),(0,P.jsx)(`button`,{onClick:e=>{e.stopPropagation(),o()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,P.jsx)(T,{className:`h-4 w-4`})})]}):(0,P.jsxs)(`button`,{onClick:t=>{t.stopPropagation(),a(e.ollamaCommand,e.filename)},disabled:n,className:A(`px-3 py-1.5 rounded-lg text-xs font-medium`,`bg-primary-100 dark:bg-primary-900/30`,`text-primary-700 dark:text-primary-400`,`hover:bg-primary-200 dark:hover:bg-primary-900/50`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,P.jsx)(l,{className:`h-3 w-3 inline mr-1`}),s(`models.pull`)]})]})}function F(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e}function he({expanded:e,models:t,onToggle:n,isModelRunning:r,formatSize:a,onShowModel:o,onCopyModel:s,onDeleteModel:c}){let{t:l}=i();return(0,P.jsxs)(`div`,{className:A(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/[0.03]`,`border-gray-200/80 dark:border-white/10`),children:[(0,P.jsxs)(`button`,{onClick:n,"aria-expanded":e,className:A(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(O,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,P.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:l(`modelManager.sections.local`)}),(0,P.jsxs)(`span`,{className:A(`px-2 py-0.5 rounded-full text-xs font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-600 dark:text-gray-400`),children:[t.length,` `,l(`modelManager.local.installed`)]})]}),e?(0,P.jsx)(E,{className:`h-5 w-5 text-gray-500`}):(0,P.jsx)(b,{className:`h-5 w-5 text-gray-500`})]}),e&&(0,P.jsx)(`div`,{className:`p-4 pt-0`,children:t.length===0?(0,P.jsxs)(`div`,{className:A(`text-center py-12 rounded-lg border-2 border-dashed`,`border-gray-200 dark:border-dark-300`),children:[(0,P.jsx)(O,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,P.jsx)(`p`,{className:`text-gray-600 dark:text-dark-600 mb-2`,children:l(`modelManager.local.noModels`)}),(0,P.jsx)(`p`,{className:`text-sm text-gray-500 dark:text-gray-500`,children:l(`modelManager.local.pullToStart`)})]}):(0,P.jsx)(`div`,{className:`space-y-3`,children:t.map(e=>(0,P.jsx)(ge,{model:e,running:r(e.name),formatSize:a,onShowModel:o,onCopyModel:s,onDeleteModel:c},e.name))})})]})}function ge({model:e,running:t,formatSize:n,onShowModel:r,onCopyModel:a,onDeleteModel:o}){let{t:s}=i();return(0,P.jsx)(`div`,{className:A(`p-4 rounded-lg border transition-colors`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`hover:bg-gray-100 dark:hover:bg-dark-200`),children:(0,P.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,P.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,P.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),t&&(0,P.jsxs)(`span`,{className:A(`inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium`,`bg-green-100 dark:bg-green-900/30`,`text-green-700 dark:text-green-400`),children:[(0,P.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-green-500 animate-pulse`}),s(`modelManager.local.running`)]})]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1 text-sm text-gray-600 dark:text-dark-600 mt-2`,children:[(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(O,{className:`h-3.5 w-3.5`}),n(e.size)]}),e.details?.parameter_size&&(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(g,{className:`h-3.5 w-3.5`}),e.details.parameter_size]}),e.details?.quantization_level&&(0,P.jsx)(`span`,{className:A(`px-1.5 py-0.5 rounded text-xs`,`bg-gray-200 dark:bg-dark-300`,`text-gray-600 dark:text-gray-400`),children:e.details.quantization_level}),e.details?.family&&(0,P.jsx)(`span`,{className:`text-gray-500 dark:text-gray-500`,children:e.details.family})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-3 text-xs text-gray-400 dark:text-dark-500 mt-2`,children:[(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(_,{className:`h-3 w-3`}),new Date(e.modified_at).toLocaleDateString()]}),(0,P.jsxs)(`span`,{className:`flex items-center gap-1 font-mono truncate max-w-[200px]`,title:e.digest,children:[(0,P.jsx)(y,{className:`h-3 w-3`}),e.digest.slice(0,12),`...`]})]})]}),(0,P.jsxs)(`div`,{className:`flex gap-2 flex-shrink-0`,children:[(0,P.jsxs)(j,{onClick:()=>r(e.name),variant:`outline`,size:`sm`,className:A(`gap-1.5`,``,``),children:[(0,P.jsx)(x,{className:`h-3.5 w-3.5`}),s(`modelManager.local.info`)]}),(0,P.jsxs)(j,{onClick:()=>a(e.name),variant:`outline`,size:`sm`,className:A(`gap-1.5`,``,``),children:[(0,P.jsx)(c,{className:`h-3.5 w-3.5`}),s(`modelManager.local.copy`)]}),(0,P.jsxs)(j,{onClick:()=>o(e.name),variant:`outline`,size:`sm`,className:A(`gap-1.5`,`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,``,``),children:[(0,P.jsx)(w,{className:`h-3.5 w-3.5`}),s(`modelManager.local.delete`)]})]})]})})}function _e({expanded:e,models:t,totalAvailable:n,categories:r,filter:a,search:o,loading:c,pulling:l,canInstallModels:u,pullSectionExpanded:d,setFilter:m,setSearch:h,isModelInstalled:ee,normalizeCloudPullName:g,onToggle:_,onTogglePullSection:te,onPullModel:y,onRefresh:x}){let{t:S}=i();return(0,P.jsxs)(`div`,{className:A(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/[0.03]`,`border-gray-200/80 dark:border-white/10`),children:[(0,P.jsxs)(`button`,{onClick:_,"aria-expanded":e,className:A(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(v,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,P.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:S(`modelManager.sections.library`)}),(0,P.jsxs)(`span`,{className:A(`px-2 py-0.5 rounded-full text-xs font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-600 dark:text-gray-400`),children:[n,` `,S(`modelManager.library.available`)]})]}),e?(0,P.jsx)(E,{className:`h-5 w-5 text-gray-500`}):(0,P.jsx)(b,{className:`h-5 w-5 text-gray-500`})]}),e&&(0,P.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,P.jsxs)(`div`,{className:`flex flex-col sm:flex-row gap-3`,children:[(0,P.jsxs)(`div`,{className:`relative flex-1`,children:[(0,P.jsx)(f,{className:`absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400 dark:text-gray-500`}),(0,P.jsx)(`input`,{type:`text`,value:o,onChange:e=>h(e.target.value),placeholder:S(`modelManager.library.search`),className:A(`w-full rounded-xl border py-2 pe-4 ps-10 text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`)})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(s,{className:`h-4 w-4 text-gray-400`}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:r.map(e=>(0,P.jsx)(`button`,{onClick:()=>m(e),className:A(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,a===e?`bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-dark-300`),children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),c?(0,P.jsx)(`div`,{className:`flex items-center justify-center py-8`,children:(0,P.jsx)(p,{className:`h-5 w-5 animate-spin text-gray-400`})}):t.length===0?(0,P.jsx)(`div`,{className:`text-center py-8 text-gray-500`,children:S(`modelManager.library.noResults`)}):(0,P.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-3`,children:t.map(e=>{let t=e.category===`cloud`?g(e.name):e.name,n=ee(e.name)||ee(t);return(0,P.jsx)(I,{model:e,installed:n,pulling:l,canInstallModels:u,pullSectionExpanded:d,onTogglePullSection:te,onPullModel:y},e.name)})}),(0,P.jsx)(`div`,{className:`flex justify-center`,children:(0,P.jsxs)(j,{onClick:x,variant:`outline`,size:`sm`,disabled:c,className:A(`gap-1.5`,``,``),children:[(0,P.jsx)(p,{className:A(`h-3.5 w-3.5`,c&&`animate-spin`)}),S(`modelManager.library.refresh`)]})})]})]})}function I({model:e,installed:t,pulling:n,canInstallModels:r,pullSectionExpanded:a,onTogglePullSection:o,onPullModel:s}){let{t:c}=i();return(0,P.jsxs)(`div`,{"data-testid":`library-model-card-${e.name}`,className:A(`p-4 rounded-lg border transition-all`,`bg-gray-50 dark:bg-dark-50`,t?`border-green-200 dark:border-green-800/50`:`border-gray-200 dark:border-dark-300`,`hover:shadow-md hover:border-gray-300 dark:hover:border-dark-400`),children:[(0,P.jsxs)(`div`,{className:`flex items-start justify-between gap-2 mb-2`,children:[(0,P.jsx)(`h4`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:e.name}),t&&(0,P.jsxs)(`span`,{className:A(`flex items-center gap-1 px-1.5 py-0.5 rounded text-xs`,`bg-green-100 dark:bg-green-900/30`,`text-green-700 dark:text-green-400`),children:[(0,P.jsx)(D,{className:`h-3 w-3`}),c(`modelManager.library.installed`)]})]}),(0,P.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-dark-600 mb-3 line-clamp-2`,children:e.description}),(0,P.jsxs)(`div`,{className:`flex flex-wrap gap-1.5 mb-3`,children:[e.sizes.slice(0,4).map(e=>(0,P.jsx)(`span`,{className:A(`px-1.5 py-0.5 rounded text-xs`,`bg-gray-200 dark:bg-dark-300`,`text-gray-600 dark:text-gray-400`),children:e},e)),e.sizes.length>4&&(0,P.jsx)(`span`,{className:`text-xs text-gray-400`,children:c(`modelManager.library.more`,{count:e.sizes.length-4})})]}),(0,P.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-gray-500`,children:[e.pulls&&(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(l,{className:`h-3 w-3`}),e.pulls]}),(0,P.jsx)(`span`,{className:A(`px-1.5 py-0.5 rounded capitalize`,e.category===`cloud`?`bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400`:`bg-gray-100 dark:bg-dark-200`),children:e.category})]}),(0,P.jsxs)(j,{"data-testid":`library-model-install-${e.name}`,onClick:()=>{a||o(),s(e.name,e.category)},variant:`outline`,size:`sm`,disabled:n||!r,className:A(`gap-1 text-xs`,``,``),children:[(0,P.jsx)(l,{className:`h-3 w-3`}),c(`modelManager.pull.button`)]})]})]})}function ve({expanded:e,modelName:t,setModelName:n,pulling:r,progress:a,canInstallModels:s,popularModels:c,onToggle:u,onPull:d,onCancelPull:p,formatSize:m}){let{t:h}=i();return(0,P.jsxs)(`div`,{className:A(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/[0.03]`,`border-gray-200/80 dark:border-white/10`),children:[(0,P.jsxs)(`button`,{onClick:u,"aria-expanded":e,className:A(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(l,{className:`h-4 w-4 text-primary-600 dark:text-primary-400`}),(0,P.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:h(`modelManager.sections.pull`)})]}),e?(0,P.jsx)(E,{className:`h-5 w-5 text-gray-500`}):(0,P.jsx)(b,{className:`h-5 w-5 text-gray-500`})]}),e&&(0,P.jsxs)(`div`,{className:`p-4 pt-0 space-y-4`,children:[(0,P.jsxs)(`div`,{className:`flex gap-2`,children:[(0,P.jsxs)(`div`,{className:`relative flex-1`,children:[(0,P.jsx)(f,{className:`absolute start-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400 dark:text-gray-500`}),(0,P.jsx)(`input`,{type:`text`,value:t,onChange:e=>n(e.target.value),placeholder:h(`modelManager.pull.placeholder`),className:A(`w-full rounded-xl border py-2.5 pe-4 ps-10 text-sm`,`bg-gray-50 dark:bg-dark-50`,`border-gray-200 dark:border-dark-300`,`text-gray-900 dark:text-dark-700`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`focus:border-primary-500`),disabled:r||!s,onKeyDown:e=>{e.key===`Enter`&&!r&&s&&d()}})]}),r?(0,P.jsxs)(j,{onClick:p,variant:`outline`,className:A(`px-4 py-2.5 gap-2`,`text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,``,``),children:[(0,P.jsx)(T,{className:`h-4 w-4`}),h(`modelManager.pull.cancel`)]}):(0,P.jsxs)(j,{onClick:d,disabled:!t.trim()||!s,className:A(`px-4 py-2.5 gap-2`,``),children:[(0,P.jsx)(l,{className:`h-4 w-4`}),h(`modelManager.pull.button`)]})]}),r&&a&&(0,P.jsx)(L,{progress:a,formatSize:m}),!s&&(0,P.jsx)(`p`,{className:`text-xs text-ink-muted`,children:h(`modelManager.pull.restricted`)}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`p`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400 mb-2`,children:h(`modelManager.pull.popular`)}),(0,P.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:c.map(e=>(0,P.jsxs)(`button`,{onClick:()=>n(e.name),disabled:r||!s,className:A(`px-3 py-1.5 rounded-full text-xs font-medium transition-colors`,`bg-gray-100 dark:bg-dark-200`,`text-gray-700 dark:text-gray-300`,`hover:bg-gray-200 dark:hover:bg-dark-300`,`border border-gray-200 dark:border-dark-300`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[e.name,(0,P.jsx)(`span`,{className:`ml-1 text-gray-400 dark:text-gray-500`,children:e.size})]},e.name))})]}),(0,P.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,className:A(`inline-flex items-center gap-1.5 text-xs`,`text-primary-600 dark:text-primary-400`,`hover:underline`),children:[(0,P.jsx)(o,{className:`h-3 w-3`}),h(`modelManager.pull.browseAll`)]})]})]})}function L({progress:e,formatSize:t}){let{t:n}=i(),r=e.status===`starting`?n(`modelManager.progress.starting`):e.status.startsWith(`pulling`)?`${n(`modelManager.progress.pullingLayer`)} ${e.status.replace(`pulling `,``)}`:e.status.startsWith(`verifying sha256`)?n(`modelManager.progress.verifyingDigest`):e.status===`writing manifest`?n(`modelManager.progress.writing`):e.status===`removing any unused layers`?n(`modelManager.progress.cleaning`):e.status;return(0,P.jsxs)(`div`,{className:A(`p-4 rounded-lg border`,`bg-gray-50 dark:bg-dark-200`,`border-gray-200 dark:border-dark-300`),children:[(0,P.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,P.jsx)(`span`,{className:`text-sm font-medium text-gray-800 dark:text-dark-700`,children:r}),e.percent!==void 0&&(0,P.jsxs)(`span`,{className:`text-sm font-mono text-gray-600 dark:text-dark-600`,children:[e.percent,`%`]})]}),e.percent!==void 0&&(0,P.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-400 rounded-full h-2 overflow-hidden`,children:(0,P.jsx)(`div`,{className:A(`h-2 rounded-full transition-all duration-300`,`bg-primary-500 dark:bg-primary-400`),style:{width:`${e.percent}%`}})}),e.total&&e.completed&&(0,P.jsxs)(`div`,{className:`mt-2 text-xs text-gray-600 dark:text-dark-600`,children:[t(e.completed),` / `,t(e.total)]})]})}var ye=ae(`components:model-manager`),be=N.lazy(()=>r(()=>import(`./ModelManagerModals-D9j9RECi.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8]))),R=e=>{let t=e.split(`:`).pop()?.toLowerCase();return t===`cloud`||t?.endsWith(`-cloud`)===!0},xe=e=>{let t=e.trim();if(!t||R(t))return t;let n=t.lastIndexOf(`:`);return n===-1?`${t}:cloud`:`${t.slice(0,n)}:${t.slice(n+1)}-cloud`},z=()=>{let{t:e}=i(),{user:t,systemInfo:n}=se(),r=t?.role===`admin`||n?.requiresAuth===!1,o=ue(),[s,l]=(0,N.useState)(`all`),[f,g]=(0,N.useState)(``),[_,v]=(0,N.useState)(``),[y,x]=(0,N.useState)(!1),[S,w]=(0,N.useState)(null),[T,D]=(0,N.useState)(null),[re,ae]=(0,N.useState)(null),[ce,le]=(0,N.useState)(``),[fe,pe]=(0,N.useState)(!1),[me,F]=(0,N.useState)(!1),[ge,I]=(0,N.useState)(!1),[L,R]=(0,N.useState)(``),[z,B]=(0,N.useState)(``),[Se,Ce]=(0,N.useState)(!1),[we,Te]=(0,N.useState)(!1),[V,Ee]=(0,N.useState)(``),[De,Oe]=(0,N.useState)(``),[ke,Ae]=(0,N.useState)(!1),[je,Me]=(0,N.useState)(!1),[Ne,Pe]=(0,N.useState)(``),[Fe,Ie]=(0,N.useState)(``),[Le,Re]=(0,N.useState)(null),[ze,Be]=(0,N.useState)(!1),[Ve,He]=(0,N.useState)(``),[Ue,We]=(0,N.useState)(``),[H,Ge]=(0,N.useState)(`text-generation`),[U,Ke]=(0,N.useState)(`downloads`),[qe,Je]=(0,N.useState)(null),[Ye,Xe]=(0,N.useState)({}),[Ze,Qe]=(0,N.useState)(null),[$e,W]=(0,N.useState)(null),[et,G]=(0,N.useState)(null),[tt,K]=(0,N.useState)(null),[q,nt]=(0,N.useState)(new Set([`pull`,`local`])),J=e=>{nt(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},{data:rt,isLoading:it,refetch:at}=M({queryKey:[`ollama-state`],queryFn:async()=>{let[e,t,n,r]=await Promise.all([k.getModels(),k.listRunningModels(),k.getVersion(),k.checkHealth()]);return{models:e.success&&e.data||[],runningModels:t.success&&Array.isArray(t.data)?t.data:[],ollamaVersion:n.success&&n.data?n.data.version:null,isHealthy:r.success}}}),Y=rt?.models??[],X=rt?.runningModels??[],ot=rt?.ollamaVersion??null,st=rt?.isHealthy??null,Z=(0,N.useCallback)(async()=>{await at()},[at]),{data:Q=[],isLoading:ct}=M({queryKey:[`ollama-library`],queryFn:async()=>{let e=await k.getLibraryModels();return e.success&&e.data?e.data:[]}}),{data:lt=[],isLoading:ut}=M({queryKey:[`ollama-library`,`cloud`],queryFn:async()=>{let e=await k.getLibraryModels({category:`cloud`});return e.success&&e.data?e.data:[]},enabled:s===`cloud`}),dt=()=>o.invalidateQueries({queryKey:[`ollama-library`]});(0,N.useEffect)(()=>{let e=setTimeout(()=>{We(Ve)},300);return()=>clearTimeout(e)},[Ve]);let ft=q.has(`huggingface`),{data:pt=[],isLoading:mt}=M({queryKey:[`hf-models`,H,Ue,U],queryFn:async()=>{let e=await oe.getModels({task:H,search:Ue||void 0,sort:U,limit:30});return e.success&&e.data?e.data:[]},enabled:ft}),ht=()=>o.invalidateQueries({queryKey:[`hf-models`,H,Ue,U]}),gt=(0,N.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){Qe(e);try{let r=await oe.getGgufFiles(t,n);r.success&&r.data&&Xe(t=>({...t,[e]:r.data}))}catch(e){ye.error(`Failed to load GGUF files:`,e)}finally{Qe(null)}}},[]),_t=(0,N.useCallback)(e=>{qe===e?Je(null):(Je(e),Ye[e]||gt(e))},[qe,Ye,gt]),vt=(0,N.useCallback)((t,n)=>{if(!r){h.error(e(`modelManager.pull.restricted`));return}if(!$e){W(t),G({status:`starting`});try{let e=k.pullModelStream(t,e=>{G(e)},()=>{G(null),W(null),K(null),h.success(`Downloaded ${n}`),Z()},e=>{G(null),W(null),K(null),h.error(`Failed to download: ${e}`)});K(()=>e)}catch{G(null),W(null),h.error(`Failed to start download`)}}},[r,$e,Z,e]),yt=(0,N.useCallback)(()=>{tt&&(tt(),K(null),W(null),G(null))},[tt]),bt=async(t,n)=>{if(!r){h.error(e(`modelManager.pull.restricted`));return}let i=t||_.trim(),a=n===`cloud`||!t&&s===`cloud`?xe(i):i;if(!a){h.error(e(`modelManager.pull.enterName`));return}t&&v(a),x(!0),w({status:`starting`});try{let t=k.pullModelStream(a,e=>{w(e)},()=>{w(null),x(!1),D(null),h.success(e(`modelManager.pull.success`,{name:a})),v(``),Z()},t=>{w(null),x(!1),D(null),h.error(e(`modelManager.pull.failed`)+`: `+t)});D(()=>t)}catch(t){let n=t instanceof Error?t.message:String(t);h.error(e(`modelManager.pull.failed`)+`: `+n),w(null),x(!1),D(null)}},xt=()=>{T&&(T(),D(null),x(!1),w(null),h.success(e(`modelManager.pull.cancelled`)))},St=async t=>{if(confirm(e(`modelManager.local.deleteConfirm`,{name:t})))try{await k.deleteModel(t),h.success(e(`modelManager.local.deleteSuccess`,{name:t})),await Z()}catch(t){let n=t instanceof Error?t.message:String(t);h.error(e(`modelManager.local.deleteFailed`)+`: `+n)}},Ct=async t=>{F(!0),le(t),pe(!0);try{let n=await k.showModel(t,!0);n.success&&n.data?ae(n.data):h.error(e(`modelManager.modals.details.noDetails`))}catch(t){let n=t instanceof Error?t.message:String(t);h.error(e(`modelManager.modals.details.noDetails`)+`: `+n)}finally{F(!1)}},wt=async()=>{if(!L.trim()||!z.trim()){h.error(e(`modelManager.modals.copy.enterBoth`));return}Ce(!0);try{await k.copyModel(L.trim(),z.trim()),h.success(e(`modelManager.modals.copy.success`,{name:z})),I(!1),R(``),B(``),await Z()}catch(t){let n=t instanceof Error?t.message:String(t);h.error(e(`modelManager.modals.copy.failed`)+`: `+n)}finally{Ce(!1)}},Tt=async()=>{if(!V.trim()||!De.trim()){h.error(e(`modelManager.modals.create.enterBoth`));return}Ae(!0);try{await k.createModel({model:V.trim(),modelfile:De.trim()}),h.success(e(`modelManager.modals.create.success`,{name:V})),Te(!1),Ee(``),Oe(``),await Z()}catch(t){let n=t instanceof Error?t.message:String(t);h.error(e(`modelManager.modals.create.failed`)+`: `+n)}finally{Ae(!1)}},Et=async()=>{if(!Ne.trim()||!Fe.trim()){h.error(e(`modelManager.modals.embeddings.enterBoth`));return}Be(!0),Re(null);try{let t=await k.generateEmbeddings({model:Ne.trim(),input:Fe.trim()});if(t.success&&t.data){let n=t.data.embeddings?.[0]||[];Re(n),h.success(e(`modelManager.modals.embeddings.success`,{count:n.length}))}}catch(t){let n=t instanceof Error?t.message:String(t);h.error(e(`modelManager.modals.embeddings.failed`)+`: `+n)}finally{Be(!1)}},$=e=>{let t=e/1073741824;return t>=1?`${t.toFixed(2)} GB`:`${(e/1048576).toFixed(1)} MB`},Dt=e=>Array.isArray(X)&&X.some(t=>t.name===e),Ot=()=>Y.reduce((e,t)=>e+t.size,0),kt=()=>X.reduce((e,t)=>e+(t.size_vram||0),0),At=e=>Y.some(t=>t.name===e||t.name.startsWith(e+`:`)),jt=(s===`cloud`?lt:Q).filter(e=>{let t=s===`all`||s===`cloud`||e.category===s,n=!f||e.name.toLowerCase().includes(f.toLowerCase())||e.description.toLowerCase().includes(f.toLowerCase());return t&&n}),Mt=[`all`,...new Set([...Q.map(e=>e.category),`cloud`])],Nt=(0,N.useMemo)(()=>Q.length>0?Q.slice(0,10).map(e=>({name:e.name,category:e.category,size:e.sizes?.[0]||``})):[{name:`deepseek-r1`,category:`reasoning`,size:`7B`},{name:`llama3.2`,category:`general`,size:`3B`},{name:`gemma3`,category:`general`,size:`4B`},{name:`qwen2.5`,category:`general`,size:`7B`},{name:`mistral`,category:`general`,size:`7B`},{name:`codellama`,category:`coding`,size:`7B`},{name:`nomic-embed-text`,category:`embedding`,size:`137M`},{name:`llava`,category:`vision`,size:`7B`},{name:`phi3`,category:`general`,size:`3.8B`},{name:`gemma2`,category:`general`,size:`9B`}],[Q]),Pt=fe||ge||we||je;return it?(0,P.jsx)(`div`,{className:`flex items-center justify-center p-8`,children:(0,P.jsxs)(`div`,{className:`flex items-center gap-3 text-gray-600 dark:text-dark-600`,children:[(0,P.jsx)(p,{className:`h-5 w-5 animate-spin`}),e(`modelManager.loading`)]})}):(0,P.jsxs)(`div`,{className:`space-y-4`,children:[(0,P.jsx)(`div`,{className:A(`rounded-2xl border px-4 py-3`,`bg-white/60 dark:bg-white/[0.03]`,`border-gray-200/80 dark:border-white/10`),children:(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-4`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,P.jsx)(`div`,{className:A(`w-2.5 h-2.5 rounded-full`,st?`bg-green-500`:`bg-red-500`)}),(0,P.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:e(st?`modelManager.systemStatus.online`:`modelManager.systemStatus.offline`)})]}),ot&&(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,P.jsx)(d,{className:`h-4 w-4`}),(0,P.jsxs)(`span`,{children:[`v`,ot]})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,P.jsx)(O,{className:`h-4 w-4`}),(0,P.jsxs)(`span`,{children:[Y.length,` `,Y.length===1?e(`modelManager.systemStatus.models`):e(`modelManager.systemStatus.models_plural`)]})]}),(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400`,children:[(0,P.jsx)(C,{className:`h-4 w-4`}),(0,P.jsx)(`span`,{children:$(Ot())})]}),X.length>0&&(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-green-600 dark:text-green-400`,children:[(0,P.jsx)(m,{className:`h-4 w-4`}),(0,P.jsxs)(`span`,{children:[X.length,` `,e(`modelManager.systemStatus.running`),` (`,$(kt()),` `,e(`modelManager.systemStatus.vram`),`)`]})]})]}),(0,P.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,P.jsxs)(j,{onClick:Z,variant:`outline`,size:`sm`,className:A(`gap-1.5`,``,``),children:[(0,P.jsx)(p,{className:`h-3.5 w-3.5`}),e(`common.refresh`)]})})]})}),(0,P.jsx)(ve,{expanded:q.has(`pull`),modelName:_,setModelName:v,pulling:y,progress:S,canInstallModels:r,popularModels:Nt,onToggle:()=>J(`pull`),onPull:()=>bt(),onCancelPull:xt,formatSize:$}),(0,P.jsx)(_e,{expanded:q.has(`library`),models:jt,totalAvailable:Q.length,categories:Mt,filter:s,search:f,loading:ct||ut,pulling:y,canInstallModels:r,pullSectionExpanded:q.has(`pull`),setFilter:l,setSearch:g,isModelInstalled:At,normalizeCloudPullName:xe,onToggle:()=>J(`library`),onTogglePullSection:()=>J(`pull`),onPullModel:bt,onRefresh:dt}),(0,P.jsx)(de,{expanded:q.has(`huggingface`),models:pt,search:Ve,task:H,sort:U,loadingModels:mt,canInstallModels:r,expandedModelId:qe,loadingGgufModelId:Ze,ggufFiles:Ye,pullingModel:$e,pullProgress:et,setSearch:He,setTask:Ge,setSort:Ke,onToggle:()=>J(`huggingface`),onToggleModel:_t,onPullGguf:vt,onCancelPull:yt,onRefresh:ht}),Array.isArray(X)&&X.length>0&&(0,P.jsxs)(`div`,{className:A(`rounded-2xl border p-4`,`bg-white/60 dark:bg-white/[0.03]`,`border-gray-200/80 dark:border-white/10`),children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-3 mb-4`,children:[(0,P.jsx)(m,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,P.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`modelManager.sections.running`)}),(0,P.jsxs)(`span`,{className:A(`ms-auto rounded-full px-2 py-0.5 text-xs font-medium`,`border border-gray-200 bg-gray-50 dark:border-white/10 dark:bg-white/[0.04]`,`text-gray-600 dark:text-dark-600`),children:[X.length,` `,e(`modelManager.systemStatus.running`)]})]}),(0,P.jsx)(`div`,{className:`space-y-2`,children:X.map(t=>(0,P.jsxs)(`div`,{className:A(`flex items-center justify-between p-4 rounded-lg border`,`bg-white/50 dark:bg-white/[0.025]`,`border-gray-200/80 dark:border-white/[0.08]`),children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(`div`,{className:A(`w-2 h-2 rounded-full animate-pulse`,`bg-green-500`)}),(0,P.jsxs)(`div`,{children:[(0,P.jsx)(`div`,{className:`font-medium text-gray-900 dark:text-dark-800`,children:t.name}),(0,P.jsxs)(`div`,{className:`flex items-center gap-3 text-sm text-gray-500 dark:text-dark-500`,children:[(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(ne,{className:`h-3 w-3`}),e(`modelManager.systemStatus.vram`),`:`,` `,$(t.size_vram||0)]}),t.size&&(0,P.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,P.jsx)(O,{className:`h-3 w-3`}),e(`models.size`),`: `,$(t.size)]})]})]})]}),(0,P.jsxs)(`div`,{className:A(`flex items-center gap-1.5 px-2 py-1 rounded-full text-xs font-medium`,`border border-gray-200 bg-gray-50 dark:border-white/10 dark:bg-white/[0.04]`,`text-gray-600 dark:text-dark-600`),children:[(0,P.jsx)(ie,{className:`h-3 w-3`}),e(`modelManager.local.running`)]})]},t.name))})]}),(0,P.jsx)(he,{expanded:q.has(`local`),models:Y,onToggle:()=>J(`local`),isModelRunning:Dt,formatSize:$,onShowModel:Ct,onCopyModel:e=>{R(e),I(!0)},onDeleteModel:St}),(0,P.jsxs)(`div`,{className:A(`overflow-hidden rounded-2xl border`,`bg-white/60 dark:bg-white/[0.03]`,`border-gray-200/80 dark:border-white/10`),children:[(0,P.jsxs)(`button`,{onClick:()=>J(`advanced`),"aria-expanded":q.has(`advanced`),className:A(`w-full flex items-center justify-between p-4`,`hover:bg-gray-50 dark:hover:bg-dark-50`,`transition-colors`),children:[(0,P.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,P.jsx)(a,{className:`h-4 w-4 text-gray-500 dark:text-dark-500`}),(0,P.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-800`,children:e(`modelManager.sections.advanced`)})]}),q.has(`advanced`)?(0,P.jsx)(E,{className:`h-5 w-5 text-gray-500`}):(0,P.jsx)(b,{className:`h-5 w-5 text-gray-500`})]}),q.has(`advanced`)&&(0,P.jsx)(`div`,{className:`p-4 pt-0`,children:(0,P.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3`,children:[(0,P.jsxs)(j,{onClick:()=>Te(!0),variant:`outline`,className:A(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,P.jsx)(u,{className:`h-5 w-5 text-gray-500 dark:text-dark-500`}),(0,P.jsxs)(`div`,{className:`text-start`,children:[(0,P.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.createModel`)}),(0,P.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.fromModelfile`)})]})]}),(0,P.jsxs)(j,{onClick:()=>I(!0),variant:`outline`,className:A(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,P.jsx)(c,{className:`h-5 w-5 text-gray-500 dark:text-dark-500`}),(0,P.jsxs)(`div`,{className:`text-start`,children:[(0,P.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.copyModel`)}),(0,P.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.duplicateExisting`)})]})]}),(0,P.jsxs)(j,{onClick:()=>Me(!0),variant:`outline`,className:A(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,P.jsx)(te,{className:`h-5 w-5 text-gray-500 dark:text-dark-500`}),(0,P.jsxs)(`div`,{className:`text-start`,children:[(0,P.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.testEmbeddings`)}),(0,P.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.generateVectors`)})]})]}),(0,P.jsxs)(j,{onClick:async()=>{try{(await k.checkHealth()).success&&(await at(),h.success(e(`modelManager.advanced.healthy`)))}catch{await at(),h.error(e(`modelManager.systemStatus.offline`))}},variant:`outline`,className:A(`w-full gap-2 justify-start h-auto py-3 px-4`,``,``),children:[(0,P.jsx)(ee,{className:`h-5 w-5 text-gray-500 dark:text-dark-500`}),(0,P.jsxs)(`div`,{className:`text-start`,children:[(0,P.jsx)(`div`,{className:`font-medium`,children:e(`modelManager.advanced.healthCheck`)}),(0,P.jsx)(`div`,{className:`text-xs opacity-70`,children:e(`modelManager.advanced.testConnection`)})]})]})]})})]}),Pt&&(0,P.jsx)(N.Suspense,{fallback:null,children:(0,P.jsx)(be,{models:Y,showDetailsModal:fe,setShowDetailsModal:pe,selectedModelName:ce,selectedModelDetails:re,loadingDetails:me,showCopyModal:ge,setShowCopyModal:I,copySource:L,setCopySource:R,copyDestination:z,setCopyDestination:B,copying:Se,handleCopyModel:wt,showCreateModal:we,setShowCreateModal:Te,createModelName:V,setCreateModelName:Ee,createModelfile:De,setCreateModelfile:Oe,creating:ke,handleCreateModel:Tt,showEmbeddingsModal:je,setShowEmbeddingsModal:Me,embeddingsModel:Ne,setEmbeddingsModel:Pe,embeddingsInput:Fe,setEmbeddingsInput:Ie,embeddingsResult:Le,generatingEmbeddings:ze,handleGenerateEmbeddings:Et})})]})},B=()=>{let{t:e}=i();return(0,P.jsxs)(ce,{children:[(0,P.jsx)(le,{title:e(`models.title`),description:e(`models.subtitle`)}),(0,P.jsx)(z,{})]})};export{B as ModelsPage,B as default};
|