libre-webui 0.34.2 → 0.35.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/backend/dist/persistence/extensionTypes.d.ts +2 -0
- package/backend/dist/persistence/extensionTypes.d.ts.map +1 -1
- package/backend/dist/persistence/extensionTypes.js.map +1 -1
- package/backend/dist/persistence/postgresExtensionRepositories.d.ts.map +1 -1
- package/backend/dist/persistence/postgresExtensionRepositories.js +26 -0
- package/backend/dist/persistence/postgresExtensionRepositories.js.map +1 -1
- package/backend/dist/persistence/sqliteExtensionRepositories.d.ts.map +1 -1
- package/backend/dist/persistence/sqliteExtensionRepositories.js +28 -0
- package/backend/dist/persistence/sqliteExtensionRepositories.js.map +1 -1
- package/backend/dist/platform/jobs/durableJobRuntime.d.ts.map +1 -1
- package/backend/dist/platform/jobs/durableJobRuntime.js +3 -1
- package/backend/dist/platform/jobs/durableJobRuntime.js.map +1 -1
- package/backend/dist/platform/storage/s3EncryptedBlobStore.js +1 -1
- package/backend/dist/platform/storage/s3EncryptedBlobStore.js.map +1 -1
- package/backend/dist/routes/chat.d.ts.map +1 -1
- package/backend/dist/routes/chat.js +49 -0
- package/backend/dist/routes/chat.js.map +1 -1
- package/backend/dist/routes/plugins.d.ts.map +1 -1
- package/backend/dist/routes/plugins.js +29 -2
- package/backend/dist/routes/plugins.js.map +1 -1
- package/backend/dist/services/calendarService.js +1 -1
- package/backend/dist/services/calendarService.js.map +1 -1
- package/backend/dist/services/chatService.d.ts.map +1 -1
- package/backend/dist/services/chatService.js +5 -2
- package/backend/dist/services/chatService.js.map +1 -1
- package/backend/dist/services/documentService.d.ts.map +1 -1
- package/backend/dist/services/documentService.js +4 -5
- package/backend/dist/services/documentService.js.map +1 -1
- package/backend/dist/services/followUpService.js +1 -1
- package/backend/dist/services/followUpService.js.map +1 -1
- package/backend/dist/services/galleryService.d.ts.map +1 -1
- package/backend/dist/services/galleryService.js +5 -2
- package/backend/dist/services/galleryService.js.map +1 -1
- package/backend/dist/services/legacyCiphertextIntegrity.js +2 -2
- package/backend/dist/services/legacyCiphertextIntegrity.js.map +1 -1
- package/backend/dist/services/pluginCacheInvalidation.d.ts.map +1 -1
- package/backend/dist/services/pluginCacheInvalidation.js +3 -2
- package/backend/dist/services/pluginCacheInvalidation.js.map +1 -1
- package/backend/dist/services/pluginUsageService.d.ts +5 -1
- package/backend/dist/services/pluginUsageService.d.ts.map +1 -1
- package/backend/dist/services/pluginUsageService.js +37 -14
- package/backend/dist/services/pluginUsageService.js.map +1 -1
- package/backend/dist/services/thinkingSummaryService.d.ts +48 -0
- package/backend/dist/services/thinkingSummaryService.d.ts.map +1 -0
- package/backend/dist/services/thinkingSummaryService.js +170 -0
- package/backend/dist/services/thinkingSummaryService.js.map +1 -0
- package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
- package/backend/dist/services/workRuntimeService.js +5 -2
- package/backend/dist/services/workRuntimeService.js.map +1 -1
- package/backend/dist/services/workTaskService.d.ts.map +1 -1
- package/backend/dist/services/workTaskService.js +5 -2
- package/backend/dist/services/workTaskService.js.map +1 -1
- package/backend/dist/utils/pluginStreamAdapter.d.ts.map +1 -1
- package/backend/dist/utils/pluginStreamAdapter.js +2 -7
- package/backend/dist/utils/pluginStreamAdapter.js.map +1 -1
- package/backend/package.json +1 -1
- package/bin/cli.js +0 -1
- package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
- package/frontend/dist/assets/index-B8CRGFpq.css +1 -0
- package/frontend/dist/assets/index-D34e2tgI.js +92 -0
- package/frontend/dist/index.html +17 -17
- package/frontend/dist/js/{ArtifactContainer-CQjqR9G1.js → ArtifactContainer-DxNTcOvH.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-DbbqglMU.js → ArtifactDemoPage-Bzb07rM8.js} +1 -1
- package/frontend/dist/js/{ArtifactSandboxFrame-DI2b9BW5.js → ArtifactSandboxFrame-DP_4rZwQ.js} +1 -1
- package/frontend/dist/js/{ArtifactSlideOutPanel-B_UX92CK.js → ArtifactSlideOutPanel-DkuFYmTf.js} +1 -1
- package/frontend/dist/js/{AutomationModal-CNiy1Dxm.js → AutomationModal-Dh_l3_KV.js} +1 -1
- package/frontend/dist/js/{AutomationsPage-CeAsldk_.js → AutomationsPage-BZqRE_iS.js} +1 -1
- package/frontend/dist/js/{AvatarUpload-xCWQm3_w.js → AvatarUpload-CM537pyV.js} +1 -1
- package/frontend/dist/js/{CalendarPage-Cwk0X00z.js → CalendarPage-CNovVIyJ.js} +1 -1
- package/frontend/dist/js/{ChannelsPage-BG3n4ElV.js → ChannelsPage-B24ElGbY.js} +1 -1
- package/frontend/dist/js/ChatPage-YD9iS6Kh.js +14 -0
- package/frontend/dist/js/{ConnectModels-D7ZTGihA.js → ConnectModels-Dwih31mg.js} +1 -1
- package/frontend/dist/js/{EvaluationsPage-C795TI_6.js → EvaluationsPage-fd4Bzfet.js} +1 -1
- package/frontend/dist/js/{FirstTimeSetup-C4C5GLjW.js → FirstTimeSetup-Bf6VF-W2.js} +1 -1
- package/frontend/dist/js/{GalleryPage-DVWl3LaC.js → GalleryPage-BiHsiQXa.js} +1 -1
- package/frontend/dist/js/HomePage-QmyVNWCW.js +1 -0
- package/frontend/dist/js/LanguageSwitcher-DjCF4n-n.js +1 -0
- package/frontend/dist/js/{LibreClawPage-OD6iZtiy.js → LibreClawPage-BgWhUlqz.js} +1 -1
- package/frontend/dist/js/{NotesPage-rqL0zS8z.js → NotesPage-Di2Bg-aA.js} +1 -1
- package/frontend/dist/js/{PersonasPage-Babix8IA.js → PersonasPage-BdJO364O.js} +1 -1
- package/frontend/dist/js/PluginUsagePage-Cg8eqMsE.js +1 -0
- package/frontend/dist/js/RichMessageContent-C8qt0Aa7.js +1 -0
- package/frontend/dist/js/{RichMessageContent-CcKn_kcQ.js → RichMessageContent-CUbm43PQ.js} +1 -1
- package/frontend/dist/js/{SettingsModal-CXU60RIf.js → SettingsModal-BxEuHSvE.js} +3 -3
- package/frontend/dist/js/{ShareDialog-CnU4ptx7.js → ShareDialog-DTGlwdvx.js} +1 -1
- package/frontend/dist/js/{SystemPage-BzpTjdQY.js → SystemPage-wOjktp6W.js} +1 -1
- package/frontend/dist/js/UserManagementPanel-KLgquEZv.js +1 -0
- package/frontend/dist/js/{WhatsNewModal-TuDrBWKj.js → WhatsNewModal-B-8T7RFf.js} +1 -1
- package/frontend/dist/js/{WorkPage-DCeqm0BN.js → WorkPage-5YiyDil1.js} +2 -2
- package/frontend/dist/js/api-C4tAvZc2.js +14 -0
- package/frontend/dist/js/api-vKAlaBw8.js +1 -0
- package/frontend/dist/js/{appNavigation-DySHcEGS.js → appNavigation-DXgSn83Q.js} +1 -1
- package/frontend/dist/js/{appStore-DrTsJPfh.js → appStore-CmY86Gzn.js} +2 -2
- package/frontend/dist/js/appVersion-Nzg0IWED.js +1 -0
- package/frontend/dist/js/ar-DtoEKcvZ.js +2 -0
- package/frontend/dist/js/authStore-Cq6ASMHJ.js +1 -0
- package/frontend/dist/js/{authStore-CieFdk4S.js → authStore-DzKajX63.js} +3 -3
- package/frontend/dist/js/bn-DP2AKHj6.js +2 -0
- package/frontend/dist/js/chatStore-Bp-tan20.js +3 -0
- package/frontend/dist/js/{composerStyles-BjJm_BgC.js → composerStyles-nggBKICR.js} +1 -1
- package/frontend/dist/js/{config-D7WLbWrW.js → config-Cg4OZeHO.js} +1 -1
- package/frontend/dist/js/cs-BYiysC42.js +2 -0
- package/frontend/dist/js/da-CjvZwl21.js +2 -0
- package/frontend/dist/js/de-BKI2vbyb.js +2 -0
- package/frontend/dist/js/es-Bd_rGARS.js +2 -0
- package/frontend/dist/js/{evaluationsApi-Dn-WNzzH.js → evaluationsApi-BKkwm4WQ.js} +1 -1
- package/frontend/dist/js/fr-MJPX-cfk.js +2 -0
- package/frontend/dist/js/hi-i1pFIKuq.js +2 -0
- package/frontend/dist/js/id-Cx2UmvDs.js +2 -0
- package/frontend/dist/js/is-BhoLtzfO.js +2 -0
- package/frontend/dist/js/it-DBSOFUQF.js +2 -0
- package/frontend/dist/js/ja-tt90GfPo.js +2 -0
- package/frontend/dist/js/ko-CuQjGSbu.js +2 -0
- package/frontend/dist/js/{messageCodeStyles-C0pbLr0L.js → messageCodeStyles-CNMdqZf-.js} +1 -1
- package/frontend/dist/js/ms-B1IgAOxc.js +2 -0
- package/frontend/dist/js/nl-KC1T6ODd.js +2 -0
- package/frontend/dist/js/pl-BELaieBr.js +2 -0
- package/frontend/dist/js/pt-BcNdTKuY.js +2 -0
- package/frontend/dist/js/ru-BY36Y8EF.js +2 -0
- package/frontend/dist/js/sv-Df0qJdhZ.js +2 -0
- package/frontend/dist/js/{teamEventStream-CI_GSbae.js → teamEventStream-CjWlYJh3.js} +1 -1
- package/frontend/dist/js/th-BQogE70C.js +2 -0
- package/frontend/dist/js/tr-CE2ShLd6.js +2 -0
- package/frontend/dist/js/ui-DzVF9vZ5.js +2 -0
- package/frontend/dist/js/uk-DuVduqlS.js +2 -0
- package/frontend/dist/js/useChat-DubO9MWm.js +10 -0
- package/frontend/dist/js/vi-DABvOoXL.js +2 -0
- package/frontend/dist/js/workApi-mPLHmuyT.js +1 -0
- package/frontend/dist/js/{workApi-C-WfyZSs.js → workApi-oO8srJWT.js} +3 -3
- package/frontend/dist/js/zh-D2B1N9vW.js +2 -0
- package/package.json +2 -2
- package/frontend/dist/assets/index-C59a0tht.css +0 -1
- package/frontend/dist/assets/index-Cyi10ekV.js +0 -43
- package/frontend/dist/js/ChatPage-wSRfAOeh.js +0 -14
- package/frontend/dist/js/HomePage-BljB9ZMN.js +0 -1
- package/frontend/dist/js/LanguageSwitcher-BuS3i6u5.js +0 -1
- package/frontend/dist/js/PluginUsagePage-CudDkMxy.js +0 -1
- package/frontend/dist/js/RichMessageContent-B-U0EcyW.js +0 -1
- package/frontend/dist/js/UserManagementPanel-pbtLqF8X.js +0 -1
- package/frontend/dist/js/api-BIVGtaZy.js +0 -1
- package/frontend/dist/js/api-CgnEj5Jc.js +0 -14
- package/frontend/dist/js/appVersion-CAidQlBP.js +0 -1
- package/frontend/dist/js/ar-DNI77Stn.js +0 -2
- package/frontend/dist/js/authStore-GaOHAAsM.js +0 -1
- package/frontend/dist/js/bn-u6oyZr4U.js +0 -2
- package/frontend/dist/js/chatStore-BvZkd8Un.js +0 -3
- package/frontend/dist/js/cs-BIkJ6jwb.js +0 -2
- package/frontend/dist/js/da-DV3V6XJ_.js +0 -2
- package/frontend/dist/js/de-DdcTQ-vn.js +0 -2
- package/frontend/dist/js/es-Cw-ozFaX.js +0 -2
- package/frontend/dist/js/fr-Y2NfnlYR.js +0 -2
- package/frontend/dist/js/hi-BKU62_1Y.js +0 -2
- package/frontend/dist/js/id-q6wo4InR.js +0 -2
- package/frontend/dist/js/is-_B6QblCu.js +0 -2
- package/frontend/dist/js/it-NUupXhzK.js +0 -2
- package/frontend/dist/js/ja-BUvl9RXq.js +0 -2
- package/frontend/dist/js/ko-df4leR83.js +0 -2
- package/frontend/dist/js/ms-CN-7Q9S2.js +0 -2
- package/frontend/dist/js/nl-OEm4uNIo.js +0 -2
- package/frontend/dist/js/pl-B9pHpjg7.js +0 -2
- package/frontend/dist/js/pt-D3uaEKud.js +0 -2
- package/frontend/dist/js/ru-z9H07lhi.js +0 -2
- package/frontend/dist/js/sv-GkQDA4wx.js +0 -2
- package/frontend/dist/js/th-0hzCkDzt.js +0 -2
- package/frontend/dist/js/tr-CZDobfHQ.js +0 -2
- package/frontend/dist/js/ui-CgokQU6I.js +0 -2
- package/frontend/dist/js/uk-BwspIPCI.js +0 -2
- package/frontend/dist/js/useChat-DIGuMg5j.js +0 -10
- package/frontend/dist/js/vi-Dipdv5ta.js +0 -2
- package/frontend/dist/js/workApi-CApikuye.js +0 -1
- package/frontend/dist/js/zh-CgdWmtP_.js +0 -2
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,r as n,t as r}from"./react-vendor-D0Ec-185.js";import{d as i,f as a,u as o}from"./router-vendor-Epc3_KZ_.js";import{t as s}from"./logger-DnuT4jgB.js";import{t as c}from"./useTranslation-rdLmo6zV.js";import{i as l,n as u,o as d,r as f,t as p}from"./utils-CKWltgs8.js";import{T as m,_ as h,a as g,d as _,f as v,g as y,h as b,i as x,l as S,n as C,o as w,p as T,r as E,t as D,u as O}from"./chatStore-BvZkd8Un.js";import{Ct as k,En as A,Et as j,F as M,Ft as N,G as ee,Gn as te,H as ne,Ht as re,In as P,Jn as F,Kn as ie,L as I,M as ae,Mn as oe,Nn as se,O as ce,On as le,P as L,Qt as ue,S as R,St as de,Ut as fe,V as pe,Y as me,Yn as he,Z as ge,a as _e,b as ve,br as z,c as ye,cr as be,dr as B,en as xe,fr as V,g as Se,hr as Ce,in as we,jn as Te,lt as Ee,m as De,mn as H,n as U,nr as Oe,o as ke,ot as Ae,p as W,pn as G,q as je,r as K,rn as Me,rr as Ne,sr as Pe,st as Fe,t as Ie,tt as Le,wt as Re,xr as q,y as ze}from"./ui-vendor-Dt9hfsGD.js";import{N as J,S as Be,_ as Ve,a as Y,d as He,f as Ue,g as We,i as Ge,j as Ke,m as qe,n as Je,p as Ye,t as Xe,w as Ze,y as Qe}from"./api-CgnEj5Jc.js";import{t as $e}from"./authStore-CieFdk4S.js";import{t as et}from"./appStore-DrTsJPfh.js";import{i as tt,r as nt,t as rt}from"./welcomePrompts-to5mv_gx.js";import{l as it}from"./messageCodeStyles-C0pbLr0L.js";import{t as X}from"./Button-BxwbQ5xw.js";import{_ as at,g as ot,m as Z}from"./ui-CgokQU6I.js";import{t as st}from"./LogoMark-BDqTSfCe.js";import{a as ct,i as lt,n as ut,o as dt,r as ft}from"./useChat-DIGuMg5j.js";import{a as pt,i as mt,o as ht,r as gt,s as _t,t as vt}from"./ttsBatching-kFVEE3Ip.js";import{t as yt}from"./ConnectModels-D7ZTGihA.js";import{i as bt,n as xt,r as St,t as Ct}from"./thinking-DwlkTfPX.js";import{t as wt}from"./ArtifactContainer-CQjqR9G1.js";import{t as Tt}from"./evaluationsApi-Dn-WNzzH.js";import{i as Et,n as Dt,r as Ot,t as kt}from"./composerStyles-BjJm_BgC.js";var At=n(),Q=e(t(),1),$=r(),jt=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},Mt=({status:e})=>e===`running`||e===`awaiting_approval`?(0,$.jsx)(N,{className:`h-3.5 w-3.5 animate-spin`}):e===`succeeded`?(0,$.jsx)(he,{className:`h-3.5 w-3.5 text-green-600 dark:text-green-400`}):e===`denied`?(0,$.jsx)(U,{className:`h-3.5 w-3.5 text-amber-600 dark:text-amber-400`}):(0,$.jsx)(Se,{className:`h-3.5 w-3.5 text-red-500 dark:text-red-400`}),Nt=({call:e})=>{let{t}=c(),[n,r]=(0,Q.useState)(!1),i=t(`tools.callStatus.${e.status}`);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-200 bg-gray-50 dark:bg-dark-50 text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-left`,"aria-expanded":n,children:[n?(0,$.jsx)(F,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(ie,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,$.jsx)(K,{className:`h-3.5 w-3.5 shrink-0 text-gray-500 dark:text-gray-400`}),(0,$.jsx)(`span`,{className:`truncate font-medium text-gray-700 dark:text-gray-200`,dir:`ltr`,children:e.name}),e.serverName&&(0,$.jsx)(`span`,{className:`truncate text-xs text-gray-500 dark:text-gray-400`,children:e.serverName}),(0,$.jsxs)(`span`,{className:p(`ml-auto flex shrink-0 items-center gap-1 text-xs`,e.status===`succeeded`?`text-green-600 dark:text-green-400`:e.status===`failed`?`text-red-500 dark:text-red-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(Mt,{status:e.status}),i]})]}),n&&(0,$.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 dark:border-dark-200`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.arguments`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:jt(e.arguments)}),e.resultPreview!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-2 text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.result`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:e.resultPreview})]})]})]})},Pt=({calls:e,className:t})=>e.length===0?null:(0,$.jsx)(`div`,{className:p(`flex flex-col gap-1.5`,t),children:e.map(e=>(0,$.jsx)(Nt,{call:e},e.id))}),Ft=({approval:e,onDecide:t,className:n})=>{let{t:r}=c(),[i,a]=(0,Q.useState)(!1),o=(n,r)=>{a(!0),t(e.approvalId,n,r)};return(0,$.jsxs)(`div`,{role:`alertdialog`,"aria-label":r(`tools.approval.title`),className:p(`rounded-lg border border-primary-300/70 bg-primary-50 p-3 text-sm dark:border-primary-700/60 dark:bg-primary-900/20`,n),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 font-medium text-primary-800 dark:text-primary-200`,children:[(0,$.jsx)(I,{className:`h-4 w-4 shrink-0`}),r(`tools.approval.title`)]}),(0,$.jsx)(`p`,{className:`mt-1 text-primary-800/90 dark:text-primary-100/80`,children:r(`tools.approval.description`,{tool:e.toolCall.name,server:e.toolCall.serverName??r(`tools.approval.builtinSource`)})}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded bg-white/70 p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:jt(e.toolCall.arguments)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(X,{size:`sm`,disabled:i,onClick:()=>o(!0,`once`),children:r(`tools.approval.allowOnce`)}),(0,$.jsx)(X,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>o(!0,`session`),children:r(`tools.approval.allowSession`)}),(0,$.jsx)(X,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>o(!0,`always`),children:r(`tools.approval.allowAlways`)}),(0,$.jsx)(X,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>o(!1,`once`),children:r(`tools.approval.deny`)})]})]})},It=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i}=c(),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`,s=e.prompt_eval_count||0,l=e.eval_count||0,u=s+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)(re,{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)(F,{size:12}):(0,$.jsx)(ie,{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`)}),` `,s]}),(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()]})]})]})},Lt=s(`components:ttsbutton`),Rt=null,zt=null,Bt=0,Vt=3e5;async function Ht(e=!1){let t=Date.now();return!e&&Rt!==null&&t-Bt<Vt?Rt:zt||(zt=(async()=>{try{let e=await Y.getModels();return e.success&&e.data&&e.data.length>0?(Rt=e.data,Bt=t,e.data):(Rt=[],Bt=t,[])}catch{return Rt=[],Bt=t,[]}finally{zt=null}})(),zt)}var Ut=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:s}=c(),{preferences:l}=et(),[u,d]=(0,Q.useState)(`idle`),[f,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)([]),[_,v]=(0,Q.useState)(null),y=(0,Q.useRef)(null),b=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await Ht(),n=Je(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await Ht(!0)),e&&(g(t),v(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let x=()=>{b.current+=1,y.current?.cancel(),y.current=null,d(`idle`)},S=async()=>{if(r===`blocked`||r===`error`){a?.();return}if(r===`loading`||r===`generating`||r===`buffering`||r===`playing`){i?.();return}if(u===`loading`||u===`generating`||u===`buffering`||u===`playing`){x();return}if(y.current){x();return}let t=_t();d(`loading`),m(null);let n=b.current+1;b.current=n;try{let r=await t;if(b.current!==n)return;if(r===`blocked`){d(`blocked`);return}let i=l.ttsSettings,a=Ge(h,i?.model,i?.pluginId),c=a?.model||i?.model||`tts-1`,u=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),p=f&&i?.voice||a?.config?.default_voice,m=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,v=Math.max(1,a?.config?.max_characters||600),x=Math.min(v,600),S=i?.streamSentences!==!1||e.length>x?gt(e,{locale:s.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=mt({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>Y.generate({model:c,pluginId:u,input:e,voice:m?void 0:p||void 0,voiceProfileId:m,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});y.current=C;let w=vt(C);try{await C.play(S)}finally{w(),y.current===C&&(y.current=null)}}catch(e){if(b.current!==n)return;if(pt(e)){d(`idle`);return}if(ht(e)){d(`blocked`);return}let t=e instanceof Error?e.message:o(`ttsButton.generateFailed`);m(t),Lt.error(`TTS error:`,e),d(`error`)}};if((0,Q.useEffect)(()=>()=>{b.current+=1,y.current?.cancel(),y.current=null},[]),_===!1||_===null)return null;let C={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},w={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`},T=r&&![`idle`,`ended`,`cancelled`].includes(r)?r:u,E=T===`loading`||T===`generating`||T===`buffering`,D=T===`playing`,O=T===`blocked`,k=!!f||T===`error`,A=f||o(k?`ttsButton.playbackFailed`:O?`ttsButton.enableAudio`:D||E?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,$.jsxs)(`button`,{onClick:S,disabled:!e,title:A,"aria-label":A,"aria-busy":E||void 0,className:p(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,k?`text-red-500 dark:text-red-400`:O?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:D?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!O&&C[n],O&&n===`sm`&&`h-7`,O&&n===`md`&&`h-8`,O&&n===`lg`&&`h-10`,t),children:[E?(0,$.jsx)(N,{className:p(w[n],`animate-spin`)}):D?(0,$.jsx)(ce,{className:w[n]}):k||O?(0,$.jsx)(_e,{className:w[n]}):(0,$.jsx)(ke,{className:w[n]}),O&&(0,$.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},Wt=[`accuracy`,`style`,`incomplete`,`harmful`,`formatting`],Gt=s(`components:chat-message`);function Kt({role:e,user:t,persona:n,modelAvatar:r}){let[i,a]=(0,Q.useState)(null);if(e===`assistant`){if(n)return(0,$.jsx)(`img`,{src:We(n,64),alt:n.name,"data-testid":`chat-assistant-avatar`,onError:e=>Ve(e.currentTarget,n.name,64),className:`mt-0.5 h-8 w-8 shrink-0 rounded-lg object-cover`});let e=r?.trim()??``,t=e.startsWith(`data:`)&&e!==i?e:``;return(0,$.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-sm dark:border-white/[0.09] dark:bg-dark-200 dark:text-dark-950`,children:t?(0,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>a(e)}):e?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,$.jsx)(st,{label:null,className:`h-4 w-4`})})}let o=t?.username||`User`,s=t?.avatar?.trim()||``,c=!!s&&s!==i;return(0,$.jsx)(`div`,{role:c?void 0:`img`,"aria-label":c?void 0:o,"data-testid":`chat-user-avatar`,className:p(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,c?`border border-black/[0.07] bg-white dark:border-white/[0.09] dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:o,children:c?(0,$.jsx)(`img`,{src:s,alt:o,className:`h-full w-full object-cover`,onError:()=>a(s)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(ye,{"aria-hidden":`true`,className:`h-4 w-4`})})}var qt=Q.memo(({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onFork:a,onEditResend:o})=>{let{t:s,i18n:l}=c(),u=e.role===`user`,m=e.role===`system`,h=m&&g(e.content),_=h?e.content.slice(C.length):e.content,v=et(e=>e.preferences),y=$e(e=>e.user),b=D(e=>e.setSystemMessage),x=D(e=>e.rateMessage),S=D(e=>e.modelMetadata),w=D(e=>e.currentSession?.id),T=D(e=>e.currentSession?.model),E=D(e=>e.currentSession?.isPrivate===!0),O=D(e=>e.getCurrentPersona()),k=e.model||T||``,A=k?S[k]??Object.entries(S).find(([e])=>e.slice(e.indexOf(`/`)+1)===k)?.[1]:void 0,[j,M]=(0,Q.useState)(!1),[N,ee]=(0,Q.useState)(e.content),[ne,re]=(0,Q.useState)(null),[P,ie]=(0,Q.useState)(!1),[I,ae]=(0,Q.useState)(!1),[oe,se]=(0,Q.useState)(!1),[ce,L]=(0,Q.useState)(`idle`),[ue,R]=(0,Q.useState)(null),[de,fe]=(0,Q.useState)([]),[_e,z]=(0,Q.useState)(``),[ye,be]=(0,Q.useState)(!1),B=(0,Q.useRef)(null),V=(0,Q.useRef)(0),Se=(0,Q.useRef)(t),Ce=(0,Q.useRef)(!1),we=async()=>{try{await navigator.clipboard.writeText(e.content),it(`success`),be(!0),setTimeout(()=>be(!1),2e3)}catch(e){Gt.error(`Failed to copy message:`,e)}},{thinkingContent:Te,thinkingStreaming:Ee,parsedContent:H,artifacts:ke}=(0,Q.useMemo)(()=>{if(u||m||!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}:d(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=dt(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,u,m,t]),Ae=Ee?void 0:e.statistics?.thinking_duration_ms??ct(e.id),W=(0,Q.useCallback)(async e=>{let t=V.current+1;V.current=t,B.current?.cancel(),B.current=null,L(`loading`);try{if(e){let n=await e;if(V.current!==t)return;if(n===`blocked`){L(`blocked`);return}}let n=await Y.getModels();if(V.current!==t)return;let r=n.success&&n.data?n.data:[],i=v.ttsSettings,a=Ge(r,i?.model,i?.pluginId),o=Je(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,c=a?.plugin||i?.pluginId,u=o&&i?.voice||a?.config?.default_voice,d=o&&i?.voiceProfileId||void 0,f=Math.max(1,a?.config?.max_characters||600),p=Math.min(f,600),m=i?.streamSentences!==!1||H.length>p?gt(H,{locale:l.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[H.trim()];if(m.length===0){L(`idle`);return}let h=mt({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>Y.generate({model:s,pluginId:c,input:e,voice:d?void 0:u||void 0,voiceProfileId:d,speed:i?.speed||1,response_format:a?.config?.default_format},{signal:t}),onStateChange:e=>{V.current===t&&L(e)}});if(V.current!==t){h.cancel();return}B.current=h;let g=vt(h);try{await h.play(m)}finally{g(),B.current===h&&(B.current=null),V.current===t&&(h.state===`ended`||h.state===`cancelled`)&&L(`idle`)}}catch(e){if(V.current!==t)return;pt(e)?L(`idle`):ht(e)?L(`blocked`):(Gt.error(`Auto-play TTS failed:`,e),L(`error`))}},[l.language,H,v.ttsSettings]);(0,Q.useEffect)(()=>{let e=Se.current&&!t;Se.current=t,e&&!Ce.current&&!u&&!m&&H&&v.ttsSettings?.enabled&&v.ttsSettings.autoPlay&&(Ce.current=!0,W())},[t,u,m,H,v.ttsSettings?.autoPlay,v.ttsSettings?.enabled,W]),(0,Q.useEffect)(()=>()=>{V.current+=1,B.current?.cancel(),B.current=null},[]);let G=()=>{let e=_t();W(e)},K=()=>{V.current+=1,B.current?.cancel(),B.current=null,L(`idle`)},Me=()=>h?s(`chatMessage.conversationSummary`):m?s(`chatMessage.system`):u?v.showUsername&&y?.username?y.username:s(`chatMessage.you`):O?.name?O.name:A?.label||k||s(`chatMessage.assistant`),Ne=()=>{M(!0),ee(e.content)},[Pe,Ie]=(0,Q.useState)(!1),Le=async()=>{if(!(!w||Pe)){Ie(!0);try{let t=await J.restoreCompaction(w,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;D.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){Gt.error(`Failed to restore compacted messages:`,e),q.error(s(`chatMessage.restoreFailed`))}finally{Ie(!1)}}},Re=async()=>{ie(!0);try{b(N),M(!1),Gt.debug(`✅ System message updated:`,N)}catch(e){Gt.error(`Failed to save system message:`,e)}finally{ie(!1)}},Be=()=>{M(!1),ee(e.content)},Ve=()=>{let t=N.trim();M(!1),t&&o?.(e.id,t)},He=t=>{if(!w)return;let n=e.rating===t;if(x(w,e.id,n?void 0:t),!E){if(n){R(null),Tt.deleteFeedback(e.id).catch(()=>void 0);return}fe([]),z(``),R(t===1?1:-1),Tt.upsertFeedback({sessionId:w,messageId:e.id,rating:t===1?1:-1}).catch(()=>void 0)}},Ue=()=>{!w||ue===null||(Tt.upsertFeedback({sessionId:w,messageId:e.id,rating:ue,tags:de,..._e.trim()?{comment:_e.trim()}:{}}).catch(()=>void 0),R(null))},We=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,Ke=m&&_.length>100;return(0,$.jsxs)(`div`,{className:p(`group flex py-1.5 transition-colors sm:py-2`,u?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:p(`flex min-w-0 gap-2.5 sm:gap-3`,u?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!u&&!m&&(0,$.jsx)(Kt,{role:`assistant`,persona:O,modelAvatar:A?.avatar}),(0,$.jsxs)(`div`,{className:p(`min-w-0 flex-1`,u?`flex flex-col items-end`:m?`py-1.5`:`py-0.5`),children:[!u&&!m&&(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-ink-muted rtl:tracking-normal`,children:Me()}),e.model&&O?.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-ink-subtle`,children:f(e.timestamp,l.language)})]}),(0,$.jsxs)(`div`,{className:p(!u&&!m&&`text-[0.9375rem] leading-[1.65] text-ink`),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:()=>re(e)})},t))}),u?j?(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:N,onChange:e=>ee(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||(e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),Ve()):e.key===`Escape`&&Be())},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:Be,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:s(`chatMessage.cancelEditing`)}),(0,$.jsx)(`button`,{onClick:Ve,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:s(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{"data-user-bubble":``,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})}):m?(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:[h?(0,$.jsx)(me,{className:`h-2.5 w-2.5 opacity-50`}):(0,$.jsx)(pe,{className:`h-2.5 w-2.5 opacity-50`}),s(h?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:h?(0,$.jsx)(`button`,{onClick:()=>void Le(),disabled:Pe,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.restoreCompacted`),children:(0,$.jsx)(De,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):j?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:Re,disabled:P,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.saveChanges`),children:(0,$.jsx)(je,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:Be,disabled:P,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:s(`chatMessage.cancelEditing`),children:(0,$.jsx)(U,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:Ne,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:s(`chatMessage.editSystemMessage`),children:(0,$.jsx)(Fe,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),j?(0,$.jsx)(`textarea`,{dir:`auto`,value:N,onChange:e=>ee(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:s(`chatMessage.systemMessagePlaceholder`),disabled:P}):(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:I?_:We(_)}),Ke&&(0,$.jsx)(`button`,{onClick:()=>ae(!I),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:I?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(te,{className:`h-3 w-3`}),s(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(F,{className:`h-3 w-3`}),s(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(Te||Ee)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{onClick:()=>se(!oe),className:`flex items-center gap-1.5 text-xs text-ink-muted transition-colors hover:text-ink`,children:[(0,$.jsx)(Oe,{className:p(`h-3.5 w-3.5`,Ee&&`animate-pulse-subtle motion-reduce:animate-none`)}),Ee?(0,$.jsxs)(`span`,{className:`animate-shimmer bg-gradient-to-r from-ink-subtle via-ink to-ink-subtle bg-[length:200%_100%] bg-clip-text font-medium text-transparent motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-ink-muted`,children:[s(`chatMessage.thinking`),`…`]}):(0,$.jsx)(`span`,{className:`font-medium`,children:Ae===void 0?s(`chatMessage.thinking`):s(`chatMessage.thoughtFor`,{duration:lt(Ae)})}),oe?(0,$.jsx)(te,{className:`h-3.5 w-3.5`}):(0,$.jsx)(F,{className:`h-3.5 w-3.5`})]}),oe&&Te&&(0,$.jsx)(`div`,{dir:`auto`,className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 text-[13px] leading-relaxed text-gray-600 dark:bg-dark-200/60 dark:text-dark-700`,children:(0,$.jsx)(Z,{content:Te,isStreaming:Ee,className:`text-[13px] text-ink-muted`})})]}),(0,$.jsx)(Z,{content:H,isStreaming:t})]}),!u&&!m&&ke.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(wt,{artifacts:ke})}),!u&&!m&&Array.isArray(e.providerMetadata?.toolCalls)&&e.providerMetadata.toolCalls.length>0&&(0,$.jsx)(Pt,{calls:e.providerMetadata.toolCalls,className:`mt-2.5`}),!u&&!m&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,$.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-ink-subtle rtl:tracking-normal`,children:s(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,$.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,$.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!u&&!m&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(It,{statistics:e.statistics})}),!m&&!t&&(0,$.jsxs)(`div`,{className:p(`flex items-center gap-0.5 text-ink-subtle`,`sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,!u&&[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(ce)?`sm:opacity-100`:`sm:opacity-0`,u?`mt-1 justify-end`:`mt-1`),children:[u&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:f(e.timestamp,l.language),children:[Me(),` ·`,` `,f(e.timestamp,l.language)]}),!u&&H&&(0,$.jsx)(Ut,{text:H,size:`sm`,externalPlaybackState:ce,onStopExternal:K,onRetryExternal:G,className:p(`transition-colors`,ce===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),u&&o&&!j&&(0,$.jsx)(`button`,{onClick:()=>{ee(e.content),M(!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:s(`chatMessage.edit`),children:(0,$.jsx)(Fe,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:we,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:s(ye?`chatMessage.copied`:`chatMessage.copyMessage`),children:ye?(0,$.jsx)(he,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(le,{className:`h-3.5 w-3.5`})}),!u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>He(1),className:p(`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:s(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(ze,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>He(-1),className:p(`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:s(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(ve,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})}),ue!==null&&(0,$.jsxs)(`div`,{className:`ml-1 flex flex-wrap items-center gap-1 rounded-lg border border-gray-200 bg-white px-2 py-1 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`feedback-details`,children:[Wt.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>fe(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:p(`rounded-full border px-2 py-0.5 text-[10px]`,de.includes(e)?`border-primary-500 bg-primary-50 text-primary-700 dark:bg-primary-950/40 dark:text-primary-300`:`border-gray-300 text-gray-500 dark:border-dark-300`),"aria-pressed":de.includes(e),children:s(`chatMessage.feedbackTags.${e}`)},e)),(0,$.jsx)(`input`,{value:_e,onChange:e=>z(e.target.value),placeholder:s(`chatMessage.feedbackComment`),className:`w-32 rounded border border-gray-300 px-1.5 py-0.5 text-[10px] dark:border-dark-300 dark:bg-dark-50`,maxLength:2e3}),(0,$.jsx)(`button`,{type:`button`,onClick:Ue,className:`rounded bg-gray-900 px-2 py-0.5 text-[10px] text-white dark:bg-white dark:text-gray-900`,children:s(`common.save`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>R(null),"aria-label":s(`common.close`),className:`rounded p-0.5 text-gray-400 hover:text-gray-600`,children:(0,$.jsx)(U,{className:`h-3 w-3`})})]})]}),!u&&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:s(`chatMessage.regenerateResponse`),children:(0,$.jsx)(ge,{className:`h-3.5 w-3.5`})}),a&&(0,$.jsx)(`button`,{onClick:()=>a(e.id),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:s(`chat.fork.action`),"data-testid":`fork-from-message`,children:(0,$.jsx)(xe,{className:`h-3.5 w-3.5`})})]})]})]}),u&&(0,$.jsx)(Kt,{role:`user`,user:y??null})]}),ne&&(0,At.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":s(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>re(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(),re(null)},children:(0,$.jsx)(U,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:ne,alt:s(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})});qt.displayName=`ChatMessage`;var Jt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Yt=220,Xt=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>Yt?`${t.slice(0,219).trimEnd()}…`:t},Zt=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=c(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[s,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)},[]),m=(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:Jt()?`auto`:`smooth`})},[t]),e.length<3)return null;let h=Math.max(0,e.findIndex(e=>e.id===t)),g=e[h]?.id,_=e.findIndex(e=>e.id===s),v=_>=0?e[_]:null,y=_>=0?`conversation-history-preview-${_}`: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 c=t.id===g,u=Math.abs(a-h),d=s===t.id?y: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":c?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===h?0:-1,className:p(`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(),m(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:p(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,c?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),v&&(0,$.jsx)(`div`,{id:y,role:`tooltip`,className:p(`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:Xt(v.prompt)}),v.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:Xt(v.response)})]})})]})}),Qt=Q.memo(({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)(qt,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,$.jsxs)(`div`,{className:p(`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)(Me,{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:p(`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:p(`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)(he,{className:`h-3 w-3`}),!l&&!u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,$.jsx)(`div`,{className:p(!l&&!u&&`opacity-75`),children:(0,$.jsx)(qt,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})});Qt.displayName=`MessageBranch`;var $t={web_search:ee,web_fetch:ue,exec:R,browser:ue,Read:H,Write:H,Edit:H,image:fe,memory_search:A,memory_get:A,working:K,thinking:K,default:K},en={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`},tn=({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:p(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=$t[e.name]||$t.default,n=en[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:p(`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:p(`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)})})};s(`components:chat-messages`);var nn=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],rn=e=>e.messages.every(e=>e.isActive===!1),an=e=>e.role===`system`&&!g(e.content),on=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,sn=e=>Math.min(120,e*.28),cn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],activeToolCalls:o,pendingToolApproval:s,onDecideToolApproval:l,className:u,onRegenerate:d,onSelectBranch:f,onEditResend:m,onFork:h,followUpSuggestions:g,onFollowUpSelect:_})=>{let{t:v}=c(),y=(0,Q.useRef)(null),b=(0,Q.useRef)(void 0),x=(0,Q.useRef)(null),S=(0,Q.useRef)(null),[C]=(0,Q.useState)(()=>new Map),w=(0,Q.useRef)(null),T=(0,Q.useRef)(0),E=(0,Q.useRef)(!1),D=(0,Q.useRef)(!1),[O,k]=(0,Q.useState)(!1),A=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>an(e)&&!an(t)?-1:an(t)&&!an(e)?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return an(n)&&!an(r)?-1:an(r)&&!an(n)?1:n.timestamp-r.timestamp})},[e]),j=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<A.length;t++){let n=A[t],r=nn(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<A.length;e++){let t=nn(A[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},[A]),M=j.map(e=>e.id).join(``),N=(0,Q.useMemo)(()=>M?M.split(``):[],[M]),ee=(0,Q.useMemo)(()=>new Set(N),[N]),te=(0,Q.useMemo)(()=>{let e=new Map;for(let t of N)e.set(t,e=>{e?C.set(t,e):C.delete(t)});return e},[C,N]),[ne,re]=(0,Q.useState)(null),P=(0,Q.useCallback)(()=>{let e=x.current;if(!e||N.length===0){re(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(T.current,N.length-1);if(t<=2)n=N.length-1;else{let t=e.scrollTop+sn(e.clientHeight);for(;n<N.length-1;){let e=C.get(N[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=C.get(N[n]);if(!e||e.offsetTop<=t)break;n--}}T.current=n;let r=N[n];re(e=>e===r?e:r)},[C,N]),F=(0,Q.useCallback)(()=>{w.current===null&&(w.current=window.requestAnimationFrame(()=>{w.current=null,P()}))},[P]),ie=(0,Q.useCallback)(()=>{let t=x.current;if(b.current&&clearTimeout(b.current),E.current=!1,b.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;D.current=!n,k(!n&&e.length>0),F()},[e.length,F]),I=(0,Q.useCallback)(()=>{b.current&&clearTimeout(b.current),b.current=setTimeout(ie,180)},[ie]),oe=(0,Q.useCallback)((e=!1)=>{D.current&&!e||y.current?.scrollIntoView({behavior:on()})},[]),se=(0,Q.useCallback)(()=>{let t=x.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(E.current){D.current=!0,k(!o&&e.length>0),F(),I();return}D.current=!o,k(!o&&e.length>0),a<=2&&N.length>0?(T.current=N.length-1,re(N[N.length-1])):F()},[N,e.length,I,F]),ce=(0,Q.useCallback)(e=>{let t=x.current,n=C.get(e);if(!t||!n)return;let r=on();E.current=!0,D.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-sn(t.clientHeight)),behavior:r}),F(),r===`auto`?ie():I()},[ie,C,I,F]),le=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>le.current&&!D.current&&oe(),le.current=e.length},[e.length,oe]),(0,Q.useEffect)(()=>{i&&(t||n)&&!D.current&&requestAnimationFrame(()=>{let e=x.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{F();let e=S.current,t=x.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(F);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,F),()=>{n?.disconnect(),window.removeEventListener(`resize`,F)}},[M,F]),(0,Q.useEffect)(()=>()=>{w.current!==null&&(window.cancelAnimationFrame(w.current),w.current=null)},[]),(0,Q.useEffect)(()=>()=>{b.current&&clearTimeout(b.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:p(`flex-1 flex items-center justify-center p-6 sm:p-10`,u),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-ink-muted`,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)(ae,{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:v(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:v(`chatMessage.startConversationDescription`)})]})});let L=-1;for(let e=A.length-1;e>=0;e--)if(A[e].messages.some(e=>e.role===`assistant`)){L=e;break}return(0,$.jsxs)(`div`,{className:p(`relative min-h-0 flex-1`,u),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:x,"data-testid":`chat-scroll-viewport`,"data-scroll-fade-top":`40`,"data-scroll-fade-bottom":`72`,onScroll:se,className:p(`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:S,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[A.map((e,a)=>{let o=a===L,s=ee.has(e.id),c=i&&e.messages.some(e=>e.id===r),l;if(rn(e))l=(0,$.jsx)(`div`,{className:`opacity-55`,children:(0,$.jsx)(qt,{message:nn(e),isStreaming:!1,isLastAssistantMessage:!1,className:a===0?`mt-3 sm:mt-4`:``})});else if(e.messages.length===1){let s=e.messages[0],c=i&&s.id===r,u=c?{...s,content:t??s.content,thinking:n||s.thinking}:s;l=(0,$.jsx)(qt,{message:u,isStreaming:c,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onEditResend:i?void 0:m,onFork:i?void 0:h,className:a===0?`mt-3 sm:mt-4`:``})}else l=(0,$.jsx)(Qt,{messages:e.messages,isStreaming:c,streamingMessage:c?t:void 0,streamingThinking:c?n:void 0,streamingMessageId:c&&r||void 0,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onSelectBranch:f,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{className:`[content-visibility:auto] [contain-intrinsic-size:auto_160px]`,ref:te.get(e.id),"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:l},e.id)}),i&&(o?.length??0)>0&&(0,$.jsx)(Pt,{calls:o??[],className:`pb-2`}),s&&l&&(0,$.jsx)(Ft,{approval:s,onDecide:l,className:`mb-2`}),i&&a.length>0&&(0,$.jsx)(tn,{tools:a,className:`px-0`}),!i&&g&&g.length>0&&_&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-subtle`,children:v(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:g.map(e=>(0,$.jsx)(`button`,{onClick:()=>_(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-ink-muted transition-colors hover:text-ink dark:border-dark-200`,children:e},e))})]}),(0,$.jsx)(`div`,{ref:y,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(Zt,{items:j,activeId:ne,onSelect:ce}),O&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-new-messages`,onClick:()=>{E.current=!1,b.current&&=(clearTimeout(b.current),void 0),D.current=!1,y.current?.scrollIntoView({behavior:on()}),k(!1)},className:p(`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:v(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(Ce,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:v(`chatMessage.newMessages`)})]})]})};function ln(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 un=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)(()=>ln(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:p(`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:p(`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)(oe,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});un.displayName=`CodeAwareTextarea`;var dn=s(`components:media-upload`),fn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:s}=c(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,m]=(0,Q.useState)(!1),[h,g]=(0,Q.useState)([]),_=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await v(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):q.error(s(`chat.mediaUpload.unsupportedFileType`,{name:n.name}))}},v=async r=>{if(n-e.length<=0){q.error(s(`chat.mediaUpload.maxImagesAllowed`,{count:n}));return}if(r.size>10485760){q.error(s(`chat.mediaUpload.imageTooLarge`,{name:r.name}));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){q.error(s(`documents.fileSizeTooLarge`));return}m(!0);try{let t=await Ke.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;g(e=>[...e,n]),i?.(n),q.success(s(`documents.uploadSuccessWithName`,{name:e.name}))}else q.error(t.error||s(`documents.uploadFailed`))}catch(e){dn.error(`Document upload error:`,e),q.error(s(`documents.uploadFailed`))}finally{m(!1)}},b=e=>{e.preventDefault(),a||d(!0)},x=e=>{e.preventDefault(),d(!1)},S=e=>{e.preventDefault(),d(!1),a||_(e.dataTransfer.files)},C=n=>{t(e.filter((e,t)=>t!==n))},w=async e=>{try{let t=await Ke.deleteDocument(e);t.success?(g(t=>t.filter(t=>t.id!==e)),q.success(s(`documents.removeSuccess`))):q.error(t.error||s(`documents.removeFailed`))}catch(e){dn.error(`Error removing document:`,e),q.error(s(`documents.removeFailed`))}},T=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},E=e.length>0||h.length>0;return(0,$.jsxs)(`div`,{className:p(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:p(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>!a&&l.current?.click(),children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{_(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(N,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,$.jsx)(W,{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:[s(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:s(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:s(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(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(),C(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(U,{className:`h-3 w-3`})})]},`img-${t}`)),h.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)(H,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,$.jsx)(G,{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:T(e.size)})]}),(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(U,{className:`h-3 w-3`})})]},e.id))]})]})},pn=s(`components:document-indicator`),mn=({sessionId:e,className:t=``})=>{let{t:n}=c(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(null),d=(0,Q.useRef)(null),f=(0,Q.useCallback)(async()=>{try{let t=await Ke.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){pn.error(`Failed to load documents:`,e)}},[e]);if((0,Q.useEffect)(()=>{let e=setTimeout(()=>void f(),0),t=()=>void f();return window.addEventListener(`libre:documents-updated`,t),()=>{clearTimeout(e),window.removeEventListener(`libre:documents-updated`,t)}},[f]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{d.current?.contains(e.target)||(o(!1),l(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let p=async e=>{l(null);try{let t=await Ke.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){pn.error(`Failed to delete document:`,e),z.error(n(`settings.documents.library.deleteFailed`))}},m=r.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{ref:d,className:`relative inline-block ${t}`,children:[a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full left-0 z-50 mb-2 w-80 max-w-[85vw] rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-xs font-medium text-gray-500 dark:text-dark-600`,children:n(`chat.documents.title`)}),(0,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,$.jsx)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-gray-50 dark:hover:bg-dark-200`,children:s===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-red-700 dark:text-red-300`,children:n(`settings.documents.library.deleteConfirm`,{name:e.filename})}),(0,$.jsx)(`button`,{onClick:()=>void p(e.id),className:`shrink-0 text-xs font-medium text-red-600 underline underline-offset-2 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:n(`common.delete`)}),(0,$.jsx)(`button`,{onClick:()=>l(null),className:`shrink-0 text-xs text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,children:n(`common.cancel`)})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(H,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-xs text-gray-900 dark:text-dark-900`,children:e.filename}),(0,$.jsxs)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:[u(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,$.jsx)(`button`,{onClick:()=>l(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,$.jsx)(U,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),l(null)},className:`
|
|
2
|
-
inline-flex items-center space-x-1 px-2 py-1
|
|
3
|
-
bg-blue-50 dark:bg-blue-900/20
|
|
4
|
-
border border-blue-200 dark:border-blue-800
|
|
5
|
-
rounded-md text-xs
|
|
6
|
-
transition-colors hover:bg-blue-100 dark:hover:bg-blue-900/40
|
|
7
|
-
`,title:`${n(`chat.documents.title`)} - ${u(m)}`,children:[(0,$.jsx)(be,{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:[r.length,` doc`,r.length===1?``:`s`]})]})]})},hn=s(`components:structured-output`),gn=[{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`}],_n=({format:e,onFormatChange:t,className:n})=>{let{t:r}=c(),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(``),l=()=>gn.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),u=()=>{let t=l();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},d=e=>{let n=l().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,$.jsxs)(`div`,{className:p(`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)(pe,{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)(ot,{value:u().label,onChange:e=>d(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:u().description}),i&&(0,$.jsxs)(`div`,{className:`space-y-3`,children:[(0,$.jsx)(at,{value:o,onChange:e=>s(e.target.value),placeholder:`{
|
|
8
|
-
"type": "object",
|
|
9
|
-
"properties": {
|
|
10
|
-
"field1": { "type": "string" },
|
|
11
|
-
"field2": { "type": "number" }
|
|
12
|
-
},
|
|
13
|
-
"required": ["field1"]
|
|
14
|
-
}`,rows:8,className:`font-mono text-sm`}),(0,$.jsxs)(`div`,{className:`flex gap-2`,children:[(0,$.jsx)(X,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){hn.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,$.jsx)(X,{onClick:()=>{a(!1),s(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=u();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)(se,{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)(H,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},vn=({value:e,inheritedValue:t,onChange:n})=>{let{t:r}=c(),[i,a]=(0,Q.useState)(!1),o=(0,Q.useRef)(null),s=e??t,l=xt(s),u=St(s),d=St(e),f=t==null?void 0:St(t);return(0,Q.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return window.addEventListener(`mousedown`,e),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`mousedown`,e),window.removeEventListener(`keydown`,t)}},[i]),(0,$.jsxs)(`div`,{ref:o,className:`relative flex-shrink-0`,children:[(0,$.jsxs)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>a(e=>!e),className:p(`h-9 rounded-full p-0 flex items-center justify-center gap-1 touch-manipulation transition-colors duration-150`,l?`w-auto px-2.5`:`w-9`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,l&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:l?r(`chat.input.thinkingOn`,{level:r(`settings.generation.thinkingLevels.${u}`)}):r(`chat.input.thinkingOff`),"aria-haspopup":`menu`,"aria-expanded":i,"aria-pressed":l,children:[(0,$.jsx)(Oe,{className:`h-4 w-4`}),l&&(0,$.jsx)(`span`,{className:`text-[11px] font-medium`,children:r(`settings.generation.thinkingLevels.${u}`)})]}),i&&(0,$.jsxs)(`div`,{role:`menu`,className:`absolute bottom-full end-0 z-30 mb-2 w-48 rounded-2xl border border-black/[0.08] bg-surface/95 p-1.5 shadow-[0_16px_48px_rgba(15,23,42,0.16)] backdrop-blur-xl animate-scale-in dark:border-white/[0.09] dark:bg-dark-100/95`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-2 pt-1 text-[11px] font-medium text-gray-500 dark:text-dark-600`,children:r(`chat.controls.thinking`)}),Ct.map(e=>{let t=e===d;return(0,$.jsxs)(`button`,{type:`button`,role:`menuitemradio`,"aria-checked":t,onClick:()=>{n(bt(e)),a(!1)},className:p(`flex w-full items-center justify-between gap-2 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,t&&`text-primary-600 dark:text-primary-400`),children:[(0,$.jsx)(`span`,{className:`truncate`,children:e==="default"&&f!==void 0?r(`settings.generation.thinkingLevels.defaultWith`,{level:r(`settings.generation.thinkingLevels.${f}`)}):r(`settings.generation.thinkingLevels.${e}`)}),t&&(0,$.jsx)(he,{className:`h-3.5 w-3.5 shrink-0`})]},e)})]})]})},yn=7,bn=2*Math.PI*yn,xn=e=>`${e}`,Sn=({usage:e,trainedBudget:t})=>{let{t:n,i18n:r}=c(),[i,a]=(0,Q.useState)(!1),o=typeof e.budget==`number`&&e.budget>0,s=e.ratio??0,l=Math.round(s*100),u=e.measured?``:`~`,d=r.language,f=`${u}${x(e.used,d)}`,m=o?n(`chat.context.tokensUsed`,{used:xn(f),budget:xn(x(e.budget,d))}):n(`chat.context.tokensUsedNoBudget`,{used:xn(f)}),h=t===void 0?void 0:n(`chat.context.capped`,{trained:xn(x(t,d))}),g=[n(`chat.context.title`),o?n(`chat.context.full`,{percent:l}):void 0,m,h].filter(Boolean).join(` `),_=Math.min(s,1);return(0,$.jsxs)(`div`,{className:`relative flex-shrink-0`,onMouseEnter:()=>a(!0),onMouseLeave:()=>a(!1),onFocus:()=>a(!0),onBlur:()=>a(!1),onKeyDown:e=>{e.key===`Escape`&&a(!1)},children:[(0,$.jsx)(`span`,{role:o?`meter`:`img`,tabIndex:0,"aria-label":g,...o?{"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.min(l,100),"aria-valuetext":g}:{},className:p(`touch-target flex h-9 w-9 items-center justify-center rounded-full text-ink-muted outline-none`,`transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/40`,s>=.8&&s<1&&`text-amber-600 dark:text-amber-400`,s>=1&&`text-red-600 dark:text-red-400`),children:(0,$.jsxs)(`svg`,{viewBox:`0 0 18 18`,className:`h-4 w-4 -rotate-90`,children:[(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:yn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`opacity-30`,...o?{}:{strokeDasharray:`2 2`}}),o&&_>0&&(0,$.jsx)(`circle`,{cx:`9`,cy:`9`,r:yn,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeDasharray:bn,strokeDashoffset:bn*(1-_)})]})}),i&&(0,$.jsxs)(`div`,{role:`tooltip`,className:p(`pointer-events-none absolute bottom-full left-1/2 z-30 mb-2 -translate-x-1/2`,`whitespace-nowrap rounded-2xl bg-surface/95 px-4 py-3 text-center shadow-lv3 backdrop-blur-xl`,`border border-black/[0.06] dark:border-white/[0.08] dark:bg-dark-100/95`,`animate-scale-in`),children:[(0,$.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.title`)}),o&&(0,$.jsx)(`p`,{className:`text-[13px] text-gray-500 dark:text-dark-600`,children:n(`chat.context.full`,{percent:l})}),(0,$.jsx)(`p`,{className:`text-[13px] tabular-nums text-gray-900 dark:text-dark-900`,children:m}),h&&(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-gray-400 dark:text-dark-500`,children:h})]})]})},Cn=s(`components:prompt-queue`),wn=({sessionId:e,queue:t})=>{let{t:n}=c(),[r,i]=(0,Q.useState)(null),[a,o]=(0,Q.useState)(``),s=t=>ft(e,t),l=async t=>{try{let n=await J.claimQueuedPrompt(e,t);n.success&&n.data&&s(n.data.queue)}catch(e){Cn.error(`Failed to remove queued prompt:`,e)}},u=async(n,r)=>{let i=t.findIndex(e=>e.id===n),a=i+r;if(i===-1||a<0||a>=t.length)return;let o=t.map(e=>e.id);[o[i],o[a]]=[o[a],o[i]];try{let t=await J.reorderPromptQueue(e,o);t.success&&t.data&&s(t.data.queue)}catch(e){Cn.error(`Failed to reorder the prompt queue:`,e)}},d=async t=>{let r=a.trim();if(r)try{let a=await J.updateQueuedPrompt(e,t,r);a.success&&a.data?(s(a.data.queue),i(null)):q.error(a.error||n(`chat.queue.updateFailed`))}catch(e){Cn.error(`Failed to update the queued prompt:`,e),q.error(n(`chat.queue.updateFailed`))}};return t.length===0?null:(0,$.jsxs)(`div`,{className:`mx-auto mb-1.5 w-full max-w-3xl px-1`,"data-testid":`prompt-queue`,children:[(0,$.jsxs)(`p`,{className:`mb-1 flex items-center gap-1.5 px-1 text-[11px] font-medium text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(P,{className:`h-3 w-3`}),n(`chat.queue.title`,{total:t.length})]}),(0,$.jsx)(`ul`,{className:`space-y-1`,children:t.map((e,s)=>(0,$.jsx)(`li`,{className:`flex items-center gap-1.5 rounded-lg border border-black/[0.06] bg-surface/70 px-2 py-1 dark:border-white/[0.08] dark:bg-dark-200/70`,"data-testid":`prompt-queue-entry`,children:r===e.id?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`input`,{autoFocus:!0,value:a,onChange:e=>o(e.target.value),onKeyDown:t=>{t.key===`Enter`&&d(e.id),t.key===`Escape`&&i(null)},className:`min-w-0 flex-1 bg-transparent text-[13px] text-gray-900 focus:outline-none dark:text-dark-900`,"data-testid":`prompt-queue-edit-input`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void d(e.id),className:`rounded-md p-1 text-green-600 hover:bg-green-50 dark:hover:bg-green-900/20`,"aria-label":n(`common.save`),children:(0,$.jsx)(he,{className:`h-3.5 w-3.5`})})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-700 dark:text-dark-800`,children:e.content}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void u(e.id,-1),disabled:s===0,className:`rounded-md p-1 text-gray-400 hover:text-gray-700 disabled:opacity-30 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`chat.queue.moveUp`),children:(0,$.jsx)(V,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void u(e.id,1),disabled:s===t.length-1,className:`rounded-md p-1 text-gray-400 hover:text-gray-700 disabled:opacity-30 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`chat.queue.moveDown`),children:(0,$.jsx)(Ce,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>{i(e.id),o(e.content)},className:`rounded-md p-1 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":n(`common.edit`),children:(0,$.jsx)(Ae,{className:`h-3 w-3`})}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void l(e.id),className:`rounded-md p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,"aria-label":n(`common.delete`),children:(0,$.jsx)(U,{className:`h-3 w-3`})})]})},e.id))})]})},Tn=(e,t)=>{let n=[];for(let r of t){let t=O(e,r);t&&n.push({model:t.model,providerType:t.providerType??null,providerId:t.providerId??null})}return n},En=({models:e,currentModelKey:t,selectedKeys:n,onChange:r,disabled:i=!1})=>{let{t:a}=c(),[o,s]=(0,Q.useState)(!1),l=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{if(!o)return;let e=e=>{l.current?.contains(e.target)||s(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[o]);let u=e.filter(b).map(e=>({model:e,key:S(e)})).filter(e=>e.key!==t);if(u.length===0)return null;let d=e=>{n.includes(e)?r(n.filter(t=>t!==e)):n.length<3&&r([...n,e])};return(0,$.jsxs)(`div`,{className:`relative`,ref:l,children:[(0,$.jsxs)(X,{type:`button`,variant:`ghost`,size:`sm`,disabled:i,onClick:()=>s(e=>!e),className:p(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,n.length>0&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:a(`chat.compare.title`),"aria-pressed":n.length>0,"aria-expanded":o,"data-testid":`composer-compare-toggle`,children:[(0,$.jsx)(Te,{className:`h-4 w-4`}),n.length>0&&(0,$.jsxs)(`span`,{className:`absolute -end-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white`,children:[`+`,n.length]})]}),o&&(0,$.jsxs)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 max-h-72 w-72 overflow-y-auto rounded-xl border border-gray-200 bg-white p-2 shadow-lg scrollbar-thin dark:border-dark-200 dark:bg-dark-50`,role:`menu`,"data-testid":`composer-compare-menu`,children:[(0,$.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-[11px] font-medium text-gray-400 dark:text-dark-500`,children:a(`chat.compare.hint`,{max:3})}),u.map(({model:e,key:t})=>{let r=n.includes(t),i=!r&&n.length>=3;return(0,$.jsxs)(`label`,{className:p(`flex cursor-pointer items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-800 hover:bg-gray-50 dark:text-dark-800 dark:hover:bg-dark-100`,i&&`cursor-not-allowed opacity-40`),children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:r,disabled:i,onChange:()=>d(t),className:`h-3.5 w-3.5 rounded border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate`,children:e.name})]},t)})]})]})},Dn=`pdf.txt.text.log.md.markdown.mdx.html.htm.xhtml.docx.pptx.xlsx.csv.tsv.ts.tsx.js.jsx.mjs.cjs.py.rb.go.rs.java.kt.swift.c.h.cc.cpp.hpp.cs.php.sh.bash.zsh.sql.r.scala.lua.pl.json.yaml.yml.toml.ini.css.scss.less.xml.graphql.proto.tf.dockerfile.png.jpg.jpeg.webp.gif.wav.webm`.split(`.`).map(e=>`.${e}`).join(`,`),On=/^\/([a-z0-9-]*)$/,kn=/(?:^|\s)\$([a-z0-9-]*)$/,An=8,jn=(e,t,n)=>e.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_]*)\s*\}\}/g,(e,r)=>{let i=t.find(e=>e.name===r);if(!i)return e;let a=n[r];return a!==void 0&&a!==``?a:i.default??``}),Mn=({prompt:e,onCancel:t,onInsert:n})=>{let{t:r}=c(),[i,a]=(0,Q.useState)(()=>Object.fromEntries(e.variables.map(e=>[e.name,e.default??(e.type===`boolean`?`false`:``)]))),o=e.variables.filter(e=>e.required===!0&&(i[e.name]===void 0||i[e.name]===``));return(0,$.jsxs)(`div`,{className:`p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-gray-700 dark:text-gray-200`,children:r(`composer.variables.title`,{title:e.title})}),(0,$.jsx)(`div`,{className:`mt-2 flex max-h-56 flex-col gap-2 overflow-y-auto`,children:e.variables.map(e=>(0,$.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,dir:`ltr`,children:[e.label||e.name,e.required?` *`:``]}),e.type===`select`?(0,$.jsxs)(`select`,{value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`option`,{value:``,children:`—`}),(e.options??[]).map(e=>(0,$.jsx)(`option`,{value:e,children:e},e))]}):e.type===`boolean`?(0,$.jsxs)(`select`,{value:i[e.name]??`false`,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`,children:[(0,$.jsx)(`option`,{value:`true`,children:r(`common.yes`)}),(0,$.jsx)(`option`,{value:`false`,children:r(`common.no`)})]}):(0,$.jsx)(`input`,{type:e.type===`number`?`number`:`text`,value:i[e.name]??``,onChange:t=>a(n=>({...n,[e.name]:t.target.value})),className:`rounded-md border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-100`})]},e.name))}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-end gap-2`,children:[(0,$.jsx)(X,{size:`sm`,variant:`ghost`,onClick:t,children:r(`composer.variables.cancel`)}),(0,$.jsx)(X,{size:`sm`,disabled:o.length>0,title:o.length>0?r(`composer.variables.required`,{name:o[0]?.name??``}):void 0,onClick:()=>n(jn(e.content,e.variables,i)),children:r(`composer.variables.insert`)})]})]})},Nn=(0,Q.forwardRef)(({message:e,disabled:t=!1,onApply:n},r)=>{let{t:i}=c(),[a,o]=(0,Q.useState)(null),[s,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),[f,m]=(0,Q.useState)(null),h=(0,Q.useRef)({prompts:!1,skills:!1}),g=t?null:On.exec(e),_=t||g?null:kn.exec(e),v=g!==null,y=_!==null;(0,Q.useEffect)(()=>{!v||h.current.prompts||(h.current.prompts=!0,Ye.list().then(e=>{o(t=>e.success&&e.data?e.data:t??[])}).catch(()=>o(e=>e??[])).finally(()=>{h.current.prompts=!1}))},[v]),(0,Q.useEffect)(()=>{!y||h.current.skills||(h.current.skills=!0,Ue.list().then(e=>{l(t=>e.success&&e.data?e.data:t??[])}).catch(()=>l(e=>e??[])).finally(()=>{h.current.skills=!1}))},[y]);let b=(0,Q.useMemo)(()=>{if(g){let e=g[1];return(a??[]).filter(t=>t.slug.startsWith(e)).slice(0,An).map(e=>({kind:`prompt`,key:e.id,slug:e.slug,label:e.title,detail:e.description,prompt:e}))}if(_){let e=_[1];return(s??[]).filter(t=>t.enabled&&t.slug.startsWith(e)).slice(0,An).map(e=>({kind:`skill`,key:e.id,slug:e.slug,label:e.name,detail:e.description,skill:e}))}return[]},[g,_,a,s]),[x,S]=(0,Q.useState)(e);e!==x&&(S(e),d(0),!g&&f&&m(null));let C=t=>{let r=b[t];if(r){if(r.kind===`prompt`){if(r.prompt.variables.length>0){m(r.prompt);return}n(r.prompt.content);return}if(_){let t=e.length-(_[1].length+1);n(`${e.slice(0,t)}$${r.slug} `)}}};if((0,Q.useImperativeHandle)(r,()=>({handleKeyDown(t){return f?t.key===`Escape`?(t.preventDefault(),m(null),!0):t.key===`Enter`:b.length===0?!1:t.key===`ArrowDown`?(t.preventDefault(),d(e=>(e+1)%b.length),!0):t.key===`ArrowUp`?(t.preventDefault(),d(e=>(e-1+b.length)%b.length),!0):t.key===`Enter`||t.key===`Tab`?(t.preventDefault(),C(u),!0):t.key===`Escape`&&(t.preventDefault(),n(e),!0)}})),f)return(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-variable-form`,children:(0,$.jsx)(Mn,{prompt:f,onCancel:()=>m(null),onInsert:e=>{m(null),n(e)}})});let w=g?`prompt`:_?`skill`:null,T=g?a!==null:s!==null,E=g?g[1]===``:_?_[1]===``:!1;return b.length===0?w&&T&&E?(0,$.jsx)(`div`,{className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md rounded-xl border border-gray-200 bg-white px-3 py-2 text-xs text-gray-500 shadow-lg dark:border-dark-200 dark:bg-dark-50 dark:text-gray-400`,"data-testid":`composer-suggestions-empty`,children:i(w===`prompt`?`composer.promptMenu.empty`:`composer.skillMenu.empty`)}):null:(0,$.jsx)(`div`,{role:`listbox`,"aria-label":i(g?`composer.promptMenu.label`:`composer.skillMenu.label`),className:`absolute bottom-full left-0 z-30 mb-2 w-full max-w-md overflow-hidden rounded-xl border border-gray-200 bg-white shadow-lg dark:border-dark-200 dark:bg-dark-50`,"data-testid":`composer-suggestions`,children:b.map((e,t)=>(0,$.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===u,onMouseEnter:()=>d(t),onMouseDown:e=>{e.preventDefault(),C(t)},className:p(`flex w-full items-center gap-2 px-3 py-2 text-left text-sm`,t===u?`bg-gray-100 dark:bg-dark-200`:`bg-transparent`),children:[e.kind===`prompt`?(0,$.jsx)(Pe,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(ae,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,$.jsxs)(`span`,{className:`font-mono text-xs text-gray-500`,dir:`ltr`,children:[e.kind===`prompt`?`/`:`$`,e.slug]}),(0,$.jsx)(`span`,{className:`truncate text-gray-700 dark:text-gray-200`,children:e.label}),e.detail&&(0,$.jsx)(`span`,{className:`ml-auto hidden max-w-[40%] truncate text-xs text-gray-400 sm:block`,children:e.detail})]},e.key))})});Nn.displayName=`ComposerSuggestions`;var Pn=(e,t,n)=>{let r=new Set(e??t);r.has(n)?r.delete(n):r.add(n);let i=t.filter(e=>r.has(e));return i.length===t.length?null:i},Fn=({value:e,onChange:t,disabled:n=!1,buttonClassName:r})=>{let{t:i}=c(),[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(!1),f=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=!1;return He.getCatalog().then(t=>{e||!t.success||!t.data||(d(t.data.available&&t.data.tools.length>0),l(t.data.tools))}).catch(()=>{}),()=>{e=!0}},[a]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{f.current?.contains(e.target)||o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]);let[m,h]=(0,Q.useState)(void 0);if((0,Q.useLayoutEffect)(()=>{if(!a)return;let e=()=>{let e=f.current;if(!e)return;let t=e.getBoundingClientRect().top,n=0;for(let t=e.parentElement;t&&t!==document.body;t=t.parentElement){let{overflowY:e,overflowX:r}=getComputedStyle(t);(e!==`visible`||r!==`visible`)&&(n=Math.max(n,t.getBoundingClientRect().top))}h(Math.max(160,Math.floor(t-n-24)))};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[a]),!u||!s)return null;let g=s.filter(e=>e.source===`builtin`),_=new Map;for(let e of s)e.serverId&&_.set(e.serverId,e.serverName??e.serverId);let v=[..._.entries()],y=g.map(e=>e.name),b=v.map(([e])=>e),x=new Set(e.builtinTools??y),S=new Set(e.serverIds??b),C=(n,r,i,a,o)=>(0,$.jsxs)(`label`,{className:p(`flex cursor-pointer items-start gap-2 rounded-lg px-2 py-1.5 text-sm hover:bg-gray-50 dark:hover:bg-dark-100`,!e.enabled&&`opacity-50`),onClickCapture:e.enabled?void 0:n=>{n.preventDefault(),n.stopPropagation(),t({...e,enabled:!0})},children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:a,disabled:!e.enabled,onChange:o,"data-testid":`composer-tool-option`,className:`mt-0.5 h-3.5 w-3.5 accent-primary-600`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-gray-800 dark:text-gray-200`,dir:`ltr`,children:r}),i&&(0,$.jsx)(`span`,{className:`block truncate text-xs text-gray-500 dark:text-gray-400`,children:i})]})]},n);return(0,$.jsxs)(`div`,{ref:f,className:`relative flex-shrink-0`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,disabled:n,onClick:()=>o(e=>!e),className:p(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,e.enabled&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`,r),title:e.enabled?i(`chat.input.toolsOn`):i(`chat.input.toolsOff`),"aria-pressed":e.enabled,"aria-expanded":a,"data-testid":`composer-tools-button`,children:(0,$.jsx)(K,{className:`h-4 w-4`})}),a&&(0,$.jsxs)(`div`,{className:`absolute bottom-full start-0 z-30 mb-2 flex w-72 flex-col rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-200 dark:bg-dark-50`,style:{maxHeight:m},"data-testid":`composer-tools-menu`,children:[(0,$.jsxs)(`label`,{className:`flex flex-shrink-0 cursor-pointer items-center justify-between gap-2 rounded-lg px-2 py-1.5 text-sm font-medium text-gray-800 dark:text-gray-200`,children:[i(`composer.toolsMenu.enable`),(0,$.jsx)(`input`,{type:`checkbox`,checked:e.enabled,onChange:()=>t({...e,enabled:!e.enabled}),"data-testid":`composer-tools-enable`,className:`h-3.5 w-3.5 accent-primary-600`})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,"data-testid":`composer-tools-options`,children:[g.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.builtin`)}),g.map(n=>C(n.name,n.name,void 0,x.has(n.name),()=>t({...e,enabled:!0,builtinTools:Pn(e.builtinTools,y,n.name)})))]}),v.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`p`,{className:`mt-1 px-2 text-[11px] font-medium uppercase tracking-wide text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:i(`composer.toolsMenu.servers`)}),v.map(([n,r])=>C(n,r,void 0,S.has(n),()=>t({...e,enabled:!0,serverIds:Pn(e.serverIds,b,n)})))]})]}),(0,$.jsx)(`p`,{className:`mt-1 flex-shrink-0 border-t border-gray-100 px-2 pb-0.5 pt-1.5 text-[11px] leading-4 text-gray-400 dark:border-dark-200 dark:text-dark-500`,children:i(`composer.toolsMenu.hint`)})]})]})},In={enabled:!1,builtinTools:null,serverIds:null},Ln=e=>{if(!e.enabled)return{};let t={...e.builtinTools===null?{}:{builtinTools:e.builtinTools},...e.serverIds===null?{}:{serverIds:e.serverIds}};return{tools:!0,...Object.keys(t).length>0?{toolSelection:t}:{}}},Rn=s(`components:chat-input`),zn=560,Bn=({onSendMessage:e,onStopGeneration:t,onCancelComparison:n,onOpenVoiceMode:r,disabled:i=!1})=>{let{t:a}=c(),[o,s]=(0,Q.useState)(``),l=(0,Q.useRef)(``),[u,d]=(0,Q.useState)([]),[f,m]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(!1),[C,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(!1),[ee,te]=(0,Q.useState)([]),ne=D(e=>e.pendingComparisons),[re,P]=(0,Q.useState)(In),F=D(e=>e.currentSession?.isPrivate===!0);(0,Q.useEffect)(()=>{let e=!1;return Ze.getConfig().then(t=>{!e&&t.success&&t.data&&A(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[ie,I]=(0,Q.useState)(null),[ae,oe]=(0,Q.useState)(!1),[se,le]=(0,Q.useState)([]),[L,R]=(0,Q.useState)(!1),[pe,me]=(0,Q.useState)(!1),[ge,_e]=(0,Q.useState)(null),[ve,ye]=(0,Q.useState)(!1),xe=(0,Q.useRef)(null),Se=(0,Q.useRef)(null),Ce=(0,Q.useRef)(null),[we,Te]=(0,Q.useState)(!1);(0,Q.useEffect)(()=>{let e=Ce.current;if(!e)return;let t=new ResizeObserver(t=>{let n=t[0]?.contentRect.width??e.clientWidth;Te(n<zn)});return t.observe(e),()=>t.disconnect()},[]);let{isGenerating:De}=et(),Oe=et(e=>e.preferences.generationOptions),ke=et(e=>e.preferences.imageGenSettings?.enabled===!0),Ae=ke&&ve,{currentSession:W,models:G}=D(),je=et(e=>W?.model?e.preferences.modelGenerationOptions?.[W.model]:void 0),K=W?.id,[Me,Pe]=(0,Q.useState)(K);Me!==K&&(Pe(K),te([]));let Fe=(0,Q.useRef)(null),Ie=(0,Q.useRef)(null),Re=(0,Q.useMemo)(()=>({model:W?.personaId?`persona:${W.personaId}`:W?.model||``,providerType:W?.providerType,providerId:W?.providerId}),[W?.model,W?.personaId,W?.providerId,W?.providerType]),q=(0,Q.useMemo)(()=>h(G,Re),[G,Re]),ze=Re.model?T(q,Re):``,Ve=y(G,Re);(0,Q.useEffect)(()=>{let e=!1;return ke&&(async()=>{try{let t=await Be.getPlugins();if(e)return;ye(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ye(!1)}})(),()=>{e=!0}},[ke]),(0,Q.useEffect)(()=>{if(!b)return;let e=e=>{xe.current&&!xe.current.contains(e.target)&&(x(!1),I(null))};return window.addEventListener(`mousedown`,e),()=>window.removeEventListener(`mousedown`,e)},[b]);let Y=()=>{x(!1),I(null),oe(!1)};(0,Q.useEffect)(()=>{if(!ae)return;let e=!1;return Ke.getCollections().then(t=>{!e&&t.success&&t.data&&le(t.data)}).catch(()=>{}),()=>{e=!0}},[ae]);let He=W?.settings?.generationOptions?.think,Ue=je?.think??Oe?.think??null,We=(0,Q.useMemo)(()=>G.find(e=>e.name===W?.model),[G,W?.model]),[Ge,Je]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=W?.model;if(!e||G.length===0||!We||We.isPlugin||We.isAgent)return;let t=!1;return Qe.getModelDefaults(e).then(n=>{t||!n.success||!n.data||Je({model:e,supportsThinking:n.data.supportsThinking,options:n.data.options??{},trainedContextLength:n.data.trainedContextLength,contextCapped:n.data.contextCapped})}).catch(()=>{}),()=>{t=!0}},[We,W?.model,G.length]);let Ye=Ge?.model===W?.model?Ge:null,Xe=Ye?.supportsThinking,$e=!!(W&&!We?.isAgent&&(We?.isPlugin?We.reasoningSupport!==!1:Xe!==!1)),tt=w({model:We,sessionOptions:W?.settings?.generationOptions,pinnedOptions:je,modelDefaults:Ye?.options,globalOptions:Oe}),nt=D(e=>e.contextWindowMessages),rt=(0,Q.useMemo)(()=>E({messages:W?.messages??[],budget:tt,systemPrompt:ge?.parameters?.system_prompt,windowMessages:nt}),[tt,nt,ge,W?.messages]),it=async e=>{if(!W)return;let t={...W.settings?.generationOptions??{}};e===null?delete t.think:t.think=e;let n={...W.settings,generationOptions:t};if(D.setState(e=>({currentSession:e.currentSession?.id===W.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===W.id?{...e,settings:n}:e)})),!W.isPrivate)try{await J.updateSession(W.id,{settings:n})}catch(e){Rn.error(`Failed to update the thinking setting:`,e)}},at=W?.settings?.knowledgeCollectionIds??[],ot=async e=>{if(!W)return;let t=at.includes(e)?at.filter(t=>t!==e):[...at,e],n={...W.settings,knowledgeCollectionIds:t.length>0?t:void 0};if(D.setState(e=>({currentSession:e.currentSession?.id===W.id?{...e.currentSession,settings:n}:e.currentSession,sessions:e.sessions.map(e=>e.id===W.id?{...e,settings:n}:e)})),!W.isPrivate)try{await J.updateSession(W.id,{settings:n})}catch(e){Rn.error(`Failed to update knowledge collections:`,e),z.error(a(`chat.input.menu.attachFailed`))}},Z=Ot({onStart:()=>{l.current=o},onText:e=>{let t=l.current;s(t?`${t} ${e}`:e)},ownerKey:K}),st=Z.phase===`starting`,ct=Z.phase===`recording`,lt=Z.phase===`transcribing`,ut=Z.supported,dt=Z.providerModel,pt=Z.sources.filter(e=>e.kind===`provider`),mt=async e=>{let t=e.target.files?.[0];if(e.target.value=``,t){Y(),me(!0);try{let e=await Ke.uploadDocument(t,W?.id);e.success?(z.success(a(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):z.error(e.error||a(`chat.input.menu.attachFailed`))}catch(e){Rn.error(`Document upload failed:`,e),z.error(a(`chat.input.menu.attachFailed`))}finally{me(!1)}}},ht=async()=>{let e=ie?.trim();if(!(!e||L)){R(!0);try{let t=await Ke.fetchWebpage(e,W?.id);t.success?(z.success(a(`chat.input.menu.webpageAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`)),Y()):z.error(t.error||a(`chat.input.menu.attachFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.input.menu.attachFailed`);Rn.error(`Webpage attach failed:`,e),z.error(t)}finally{R(!1)}}},gt=async e=>{if(!(!K||F))try{let t=await J.enqueuePrompt(K,e);t.success&&t.data?(ft(K,t.data.queue),s(``)):z.error(t.error||a(`chat.queue.enqueueFailed`))}catch(e){let t=e?.response?.data?.error||a(`chat.queue.enqueueFailed`);Rn.error(`Failed to queue the prompt:`,e),z.error(t)}},vt=t=>{if(t.preventDefault(),!o.trim())return;if(De){u.length===0&&!F&&K&>(o.trim());return}if(!Ve){z.error(a(`chat.model.selectBeforeSending`));return}let n=F?{}:Ln(re),r=F?[]:Tn(G,ee);e(o.trim(),u.length>0?u:void 0,f||void 0,C&&j?!0:void 0,n.tools,n.toolSelection,r.length>0?r:void 0),s(``),d([])},yt=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||Ie.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),vt(e))},bt=()=>{t()};(0,Q.useEffect)(()=>{let e=Fe.current;e&&(e.style.height=`auto`,e.style.height=o?`${Math.min(e.scrollHeight,200)}px`:``)},[o]),(0,Q.useEffect)(()=>{(async()=>{if(W?.personaId)try{let e=await qe.getPersona(W.personaId);if(e.success&&e.data)_e(e.data);else{Rn.warn(`Persona ${W.personaId} not found, clearing reference`),_e(null);let{setCurrentSession:e}=D.getState();e({...W,personaId:void 0})}}catch(e){if(Rn.error(`Failed to load current persona:`,e),_e(null),W){let{setCurrentSession:e}=D.getState();e({...W,personaId:void 0})}}else _e(null)})()},[W?.personaId]);let xt=async e=>{let t=O(q,e.target.value);if(t&&W)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await qe.getPersona(e);if(!n.success||!n.data){z.error(a(`chat.persona.loadFailed`));return}let r=await J.updateSession(W.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(r.success&&r.data){let{sessions:e}=D.getState(),t=e.map(e=>e.id===W.id?r.data:e);D.setState({sessions:t,currentSession:r.data}),z.success(a(`chat.persona.applied`))}}else{let e=await J.updateSession(W.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}=D.getState(),n=t.map(t=>t.id===W.id?e.data:t);D.setState({sessions:n,currentSession:e.data}),z.success(a(`chat.model.updated`))}}}catch(e){Rn.error(`Failed to update session:`,e),z.error(a(`chat.toasts.updateFailed`))}},St=u.length>0||f!==null;return(0,$.jsx)(`div`,{className:`pointer-events-none`,children:(0,$.jsxs)(`div`,{ref:Ce,className:`pointer-events-auto mx-auto w-full max-w-3xl px-4 sm:px-6 md:px-8`,children:[g&&(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)(fn,{images:u,onImagesChange:d,maxImages:5,sessionId:W?.id,disabled:i}),(0,$.jsx)(_n,{format:f,onFormatChange:m})]}),(0,$.jsxs)(`div`,{className:`pb-2.5 pt-1.5 sm:pb-3`,children:[K&&!F&&(W?.settings?.promptQueue?.length??0)>0&&(0,$.jsx)(wn,{sessionId:K,queue:W.settings.promptQueue}),K&&ne.some(e=>e.sessionId===K)&&(0,$.jsx)(`div`,{className:`mx-auto mb-1.5 flex w-full max-w-3xl flex-wrap gap-1.5 px-1`,"data-testid":`pending-comparisons`,children:ne.filter(e=>e.sessionId===K).map(e=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-2.5 py-1 text-[12px] text-gray-600 dark:border-white/[0.08] dark:bg-dark-200/70 dark:text-dark-700`,"data-testid":`pending-comparison`,children:[(0,$.jsx)(N,{className:`h-3 w-3 animate-spin`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-[160px] truncate`,children:e.model}),n&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(e.assistantMessageId),className:`rounded-full p-0.5 text-gray-400 hover:text-red-500`,"aria-label":a(`common.cancel`),children:(0,$.jsx)(U,{className:`h-3 w-3`})})]},e.assistantMessageId))}),(0,$.jsx)(`form`,{onSubmit:vt,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:Dt,children:[(0,$.jsx)(Nn,{ref:Ie,message:o,disabled:i,onApply:e=>{s(e),Fe.current?.focus()}}),(0,$.jsx)(un,{ref:Fe,value:o,onChange:e=>s(e.target.value),onKeyDown:yt,placeholder:a(`chat.input.placeholder`),disabled:i,className:`!m-0 block w-full min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-2 !pt-1.5 !pb-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(`div`,{ref:xe,className:`relative flex-shrink-0`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{if(g){_(!1);return}x(e=>!e),I(null)},className:p(`h-9 w-9 !p-0 rounded-full flex-shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay`,`transition-colors duration-150 touch-manipulation`,St&&`text-primary-600 dark:text-primary-400`,(g||b)&&`bg-hover-solid text-ink`),title:a(`chat.input.attachments`),children:pe||L?(0,$.jsx)(N,{className:`h-4 w-4 animate-spin`}):St?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Ee,{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`})]}):g?(0,$.jsx)(de,{className:`h-4 w-4`}):(0,$.jsx)(Le,{className:`h-4 w-4`})}),b&&(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:ae?(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:a(`chat.input.menu.attachKnowledge`)}),se.length===0?(0,$.jsx)(`p`,{className:`px-1.5 pb-1 text-[12px] text-ink-subtle`,children:a(`chat.input.menu.noCollections`)}):se.map(e=>{let t=at.includes(e.id);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void ot(e.id),className:p(`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)(be,{className:`h-4 w-4 shrink-0`}),(0,$.jsx)(`span`,{className:`truncate`,children:e.name})]}),t&&(0,$.jsx)(he,{className:`h-3.5 w-3.5 shrink-0`})]},e.id)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>oe(!1),className:`mt-1 w-full rounded-lg border-t border-gray-100 px-2.5 py-1.5 text-start text-xs text-gray-500 hover:bg-gray-100 dark:border-dark-300 dark:text-dark-600 dark:hover:bg-dark-200`,children:a(`common.back`)})]}):ie===null?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{_(!0),Y()},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)(fe,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`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)(H,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachDocument`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>I(``),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)(ue,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachWebpage`)]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>oe(!0),className:`flex w-full items-center justify-between gap-2.5 rounded-xl px-2.5 py-2 text-start text-[13px] text-gray-700 hover:bg-gray-100 dark:text-dark-800 dark:hover:bg-dark-200`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(be,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.attachKnowledge`)]}),at.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:at.length})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{_(!0),Y()},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)(Ne,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`chat.input.menu.structuredOutput`)]}),we&&C&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{M(e=>!e),Y()},className:p(`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`,j&&`text-primary-600 dark:text-primary-400`),"aria-pressed":j,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(ue,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(j?`chat.input.webSearchOn`:`chat.input.webSearchOff`)]}),j&&(0,$.jsx)(he,{className:`h-3.5 w-3.5 shrink-0`})]}),we&&ut&&r&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{_t(),r(),Y()},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)(B,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),a(`voiceMode.open`)]})]}):(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:a(`chat.input.menu.attachWebpage`)}),(0,$.jsx)(`input`,{type:`url`,value:ie,onChange:e=>I(e.target.value),onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),ht()):e.key===`Escape`&&I(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:()=>I(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:a(`common.cancel`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void ht(),disabled:!ie.trim()||L,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:L?(0,$.jsx)(N,{className:`h-3.5 w-3.5 animate-spin`}):a(`chat.input.menu.attach`)})]})]})}),(0,$.jsx)(`input`,{ref:Se,type:`file`,accept:Dn,className:`hidden`,onChange:e=>void mt(e)})]}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center gap-1 sm:gap-1.5`,children:[$e&&(0,$.jsx)(vn,{value:He,inheritedValue:Ue,onChange:e=>void it(e)}),C&&!we&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>M(e=>!e),className:p(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,j&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:a(j?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":j,children:(0,$.jsx)(ue,{className:`h-4 w-4`})}),!F&&(0,$.jsx)(Fn,{value:re,onChange:P}),!F&&W&&!we&&(0,$.jsx)(En,{models:G,currentModelKey:v({model:W.personaId?`persona:${W.personaId}`:W.model,providerType:W.providerType??null,providerId:W.providerId??null}),selectedKeys:ee,onChange:te,disabled:i}),pt.length>0&&!we&&(0,$.jsx)(`select`,{value:Z.activeSourceKey,onChange:e=>Z.setSourceKey(e.target.value),disabled:st||ct||lt,"aria-label":a(`chat.input.transcriptionSource`),title:dt?a(`chat.input.providerTranscriptionDisclosure`,{provider:dt.plugin}):a(`chat.input.transcriptionSource`),className:`h-8 max-w-32 rounded-lg border border-black/[0.08] bg-transparent px-1.5 text-[11px] text-gray-500 outline-none focus:border-primary-500/40 dark:border-white/[0.09] dark:text-dark-600`,children:Z.sources.map(e=>e.kind===`browser`?(0,$.jsx)(`option`,{value:e.key,children:a(`chat.input.browserSpeech`)},e.key):(0,$.jsxs)(`option`,{value:e.key,children:[e.model?.plugin,` · `,e.model?.model]},e.key))}),ut&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void Z.toggle(),className:p(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,(st||ct||lt)&&`bg-red-50 text-red-500 animate-pulse dark:bg-red-900/20 dark:text-red-400`),title:lt||st?a(`common.cancel`):ct?a(`chat.input.voiceStop`):dt?a(`chat.input.providerTranscriptionDisclosure`,{provider:dt.plugin}):a(`chat.input.voiceInput`),"aria-pressed":st||ct||lt,children:st?(0,$.jsx)(N,{className:`h-4 w-4 animate-spin`}):lt?(0,$.jsx)(ce,{className:`h-4 w-4`}):(0,$.jsx)(k,{className:`h-4 w-4`})}),ut&&r&&!we&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>{_t(),r()},className:p(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`),title:a(`voiceMode.open`),"aria-label":a(`voiceMode.open`),"data-testid":`voice-mode-open`,children:(0,$.jsx)(B,{className:`h-4 w-4`})}),W&&(0,$.jsx)(Sn,{usage:rt,trainedBudget:Ye?.contextCapped?Ye.trainedContextLength:void 0}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),W&&q.length>0&&(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Et,{models:q,selectedModel:ze,onModelChange:xt,getModelValue:S,currentPersona:ge,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:Ae})}),De?(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:bt,className:p(`h-9 w-9 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:a(`chat.input.stopGeneration`),children:(0,$.jsx)(ce,{className:`h-4 w-4`})}):(0,$.jsx)(X,{type:`submit`,variant:`primary`,size:`sm`,disabled:!o.trim()||i||!Ve,className:kt,title:a(`chat.input.sendMessage`),children:(0,$.jsx)(V,{className:`h-4 w-4`})})]})]})]})}),dt&&(0,$.jsx)(`p`,{role:`note`,className:`mt-1.5 text-center text-[10px] leading-relaxed text-amber-700 dark:text-amber-300`,children:a(`chat.input.providerTranscriptionDisclosure`,{provider:dt.plugin})}),W&&q.length>0&&(0,$.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,$.jsx)(Et,{models:q,selectedModel:ze,onModelChange:xt,getModelValue:S,currentPersona:ge,className:`w-full`,compact:!0,showImageGen:Ae})}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex min-h-4 items-center justify-center gap-2 text-[10px] text-ink-subtle`,children:[(0,$.jsx)(mn,{sessionId:W?.id}),(0,$.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,$.jsx)(`span`,{children:a(`chat.footer.disclaimer`)}),St&&(0,$.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,u.length>0&&a(`chat.footer.images`,{count:u.length}),u.length>0&&f&&` • `,f&&a(`chat.footer.structuredOutput`)]})]})]})]})]})})},Vn={phase:`idle`,muted:!1,turn:0,error:null},Hn=e=>({...e,phase:`listening`,turn:e.turn+1});function Un(e,t){switch(t.type){case`start`:return e.phase===`idle`?{phase:`listening`,muted:!1,turn:e.turn+1,error:null}:e;case`stop`:return{...e,phase:`idle`,error:null};case`mute`:return{...e,muted:!0};case`unmute`:return{...e,muted:!1};case`captured`:return e.phase===`listening`&&!e.muted?{...e,phase:`transcribing`,error:null}:e;case`transcript`:return e.phase===`transcribing`?t.text.trim()?{...e,phase:`generating`}:Hn(e):e;case`reply`:return e.phase===`generating`?t.speak?{...e,phase:`speaking`}:Hn(e):e;case`spoken`:case`barge-in`:return e.phase===`speaking`?Hn(e):e;case`fail`:return e.phase===`idle`?e:{...Hn(e),error:t.message}}}var Wn=s(`utils:voice-mode-controller`),Gn=.015,Kn=200,qn=1500,Jn=6e4,Yn=300,Xn=18e4,Zn=()=>{if(typeof window>`u`)return;let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition},Qn=e=>{if(typeof MediaRecorder>`u`)return;let t=new Set((e.config?.formats||[]).map(e=>e.toLowerCase())),n=`audio/webm;codecs=opus`;if(!(t.size>0&&!t.has(`webm`))&&!(typeof MediaRecorder.isTypeSupported==`function`&&!MediaRecorder.isTypeSupported(n)))return n},$n=class{options;state=Vn;closed=!1;useBrowserRecognition=!1;sttModel=null;ttsModels=[];stream=null;recorder=null;chunks=[];audioContext=null;analyser=null;monitorTimer=null;pollTimer=null;recognition=null;ttsSession=null;abortController=null;constructor(e){this.options=e}async start(){try{let[e,t]=await Promise.all([Xe.getModels().catch(()=>({success:!1,data:[]})),Y.getModels().catch(()=>({success:!1,data:[]}))]);if(this.closed)return;let n=e.success&&e.data||[];this.ttsModels=t.success&&t.data||[];let r=n.find(e=>!!Qn(e)),i=!!r&&typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia,a=!!Zn();if(i&&r)this.sttModel=r,this.useBrowserRecognition=!1;else if(a)this.useBrowserRecognition=!0;else{this.options.onSupport(!1);return}if(this.options.onSupport(!0),!this.useBrowserRecognition&&(await this.ensureStream(),this.closed))return;let o=this.send({type:`start`});this.beginTurn(o.turn)}catch(e){Wn.warn(`Voice mode failed to start:`,e),this.closed||this.options.onSupport(!1)}}close(){this.closed=!0,this.clearMonitor(),this.clearPoll(),this.stopRecorder(),this.stopRecognition(),this.abortController?.abort(),this.ttsSession?.cancel(),this.ttsSession=null,this.stream?.getTracks().forEach(e=>e.stop()),this.stream=null,this.audioContext&&=(this.audioContext.close().catch(()=>void 0),null)}toggleMute(){if(this.state.muted){let e=this.send({type:`unmute`});e.phase===`listening`&&(this.stopRecorder(),this.stopRecognition(),this.beginTurn(e.turn))}else this.send({type:`mute`})}finishTurn(){this.state.phase!==`listening`||this.state.muted||(this.useBrowserRecognition?this.recognition?.stop():this.finishProviderCapture(this.state.turn))}skipSpeech(){if(this.state.phase!==`speaking`)return;this.ttsSession?.cancel(),this.clearMonitor();let e=this.send({type:`spoken`});e.phase===`listening`&&this.beginTurn(e.turn)}send(e){return this.state=Un(this.state,e),this.options.onState(this.state),this.state}staleTurn(e){return this.closed||this.state.turn!==e}clearMonitor(){this.monitorTimer!==null&&(window.clearInterval(this.monitorTimer),this.monitorTimer=null)}clearPoll(){this.pollTimer!==null&&(window.clearInterval(this.pollTimer),this.pollTimer=null)}stopRecorder(){let e=this.recorder;if(this.recorder=null,e&&e.state!==`inactive`)try{e.stop()}catch{}}stopRecognition(){let e=this.recognition;if(this.recognition=null,e){e.onresult=null,e.onend=null,e.onerror=null;try{e.stop()}catch{}}}rmsLevel(){if(!this.analyser)return 0;let e=new Float32Array(this.analyser.fftSize);this.analyser.getFloatTimeDomainData(e);let t=0;for(let n=0;n<e.length;n+=1)t+=e[n]*e[n];return Math.sqrt(t/e.length)}async ensureStream(){if(this.stream)return this.stream;let e=await navigator.mediaDevices.getUserMedia({audio:!0});this.stream=e;try{let t=window.AudioContext||window.webkitAudioContext;if(t){let n=new t;n.resume().catch(()=>void 0);let r=n.createMediaStreamSource(e),i=n.createAnalyser();i.fftSize=1024,r.connect(i),this.audioContext=n,this.analyser=i}}catch(e){Wn.warn(`Voice mode analyser unavailable:`,e)}return e}fail(e,t){if(this.staleTurn(e))return;this.clearMonitor(),this.clearPoll();let n=this.send({type:`fail`,message:t});n.phase===`listening`&&this.beginTurn(n.turn)}beginTurn(e){this.closed||this.state.turn!==e||this.state.phase===`listening`&&(this.stopRecognition(),this.useBrowserRecognition?this.startBrowserCapture(e):this.startProviderCapture(e))}startBrowserCapture(e){let t=Zn();if(!t)return;let n=new t;n.lang=this.options.locale,n.continuous=!1,n.interimResults=!1;let r=``;n.onresult=e=>{r=Array.from({length:e.results.length},(t,n)=>e.results[n]?.[0]?.transcript??``).join(` `).trim()},n.onend=()=>{this.staleTurn(e)||this.state.muted||this.send({type:`captured`}).phase===`transcribing`&&this.handleTranscript(e,r)},n.onerror=()=>{this.staleTurn(e)||this.fail(e,this.options.messages.microphoneFailed)},this.recognition=n;try{n.start()}catch{this.fail(e,this.options.messages.microphoneFailed)}}async startProviderCapture(e){let t=this.sttModel;if(!t)return;let n=Qn(t);if(!n){this.fail(e,this.options.messages.microphoneFailed);return}try{let t=await this.ensureStream();if(this.staleTurn(e))return;this.chunks=[];let r=new MediaRecorder(t,{mimeType:n});this.recorder=r,r.ondataavailable=e=>{e.data.size>0&&this.chunks.push(e.data)},r.onstop=()=>{if(this.staleTurn(e)&&this.state.phase!==`transcribing`)return;let t=new Blob(this.chunks,{type:n});if(this.chunks=[],t.size===0){this.handleTranscript(e,``);return}this.transcribeRecording(e,t)},r.start();let i=0,a=0,o=!1,s=Date.now();this.clearMonitor(),this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearMonitor();return}if(this.state.muted){i=0,a=0;return}this.analyser&&(this.rmsLevel()>Gn?(i+=50,a=0,i>=Kn&&(o=!0)):(i=0,o&&(a+=50))),(o&&a>=qn||Date.now()-s>=Jn)&&this.finishProviderCapture(e)},50)}catch(t){Wn.warn(`Voice mode microphone failed:`,t),this.fail(e,this.options.messages.microphoneFailed)}}finishProviderCapture(e){this.staleTurn(e)||(this.clearMonitor(),this.send({type:`captured`}).phase===`transcribing`&&this.stopRecorder())}transcribeRecording(e,t){let n=this.sttModel;if(!n){this.fail(e,this.options.messages.transcriptionFailed);return}let r=new AbortController;this.abortController=r,Xe.transcribe(t,n,{language:this.options.locale?.split(`-`)[0],signal:r.signal}).then(t=>this.handleTranscript(e,t.text??``)).catch(t=>{r.signal.aborted||(Wn.warn(`Voice mode transcription failed:`,t),this.fail(e,this.options.messages.transcriptionFailed))})}handleTranscript(e,t){if(this.staleTurn(e))return;let n=this.send({type:`transcript`,text:t});n.phase===`generating`?this.startGeneration(n.turn,t.trim()):n.phase===`listening`&&this.beginTurn(n.turn)}startGeneration(e,t){this.options.onTranscript(t);let n=this.options.snapshot().lastAssistantMessage?.id??null,r=!1,i=Date.now();this.options.sendMessage(t),this.clearPoll(),this.pollTimer=window.setInterval(()=>{if(this.staleTurn(e)){this.clearPoll();return}let t=this.options.snapshot(),a=t.lastAssistantMessage,o=a!==null&&a.id!==n;if((t.isStreaming||o)&&(r=!0),r&&!t.isStreaming&&o){this.clearPoll();let t=this.ttsModels.length>0&&a.content.trim()!==``,n=this.send({type:`reply`,speak:t});n.phase===`speaking`?this.speakReply(e,a.content):n.phase===`listening`&&this.beginTurn(n.turn);return}Date.now()-i>Xn&&(this.clearPoll(),this.fail(e,this.options.messages.replyTimeout))},250)}speakReply(e,t){let n=this.options.snapshot().ttsSettings,r=Ge(this.ttsModels,n?.model,n?.pluginId);if(!r){this.finishSpeaking(e);return}let i=r.model===n?.model&&(!n?.pluginId||r.plugin===n.pluginId),a=i&&n?.voice||r.config?.default_voice,o=i&&n?.voiceProfileId||void 0,s=Math.max(1,r.config?.max_characters||600),c=Math.min(s,600),l=gt(t,{locale:this.options.locale,maxChars:c,targetChars:Math.min(c,420),minChars:Math.min(c,80)});if(l.length===0){this.finishSpeaking(e);return}let u=mt({concurrency:3,initialBufferSize:Math.min(2,l.length),generate:(e,{signal:t})=>Y.generate({model:r.model,pluginId:r.plugin,input:e,voice:o?void 0:a||void 0,voiceProfileId:o,speed:n?.speed||1,response_format:r.config?.default_format},{signal:t}),onStateChange:()=>void 0});this.ttsSession=u;let d=vt(u);this.startBargeInMonitor(e,u),u.play(l).then(()=>{this.staleTurn(e)||this.finishSpeaking(e)}).catch(t=>{this.staleTurn(e)||pt(t)||(Wn.warn(`Voice mode speech failed:`,t),this.finishSpeaking(e))}).finally(()=>{d(),this.ttsSession===u&&(this.ttsSession=null)})}startBargeInMonitor(e,t){if(!this.analyser)return;this.clearMonitor();let n=0;this.monitorTimer=window.setInterval(()=>{if(this.staleTurn(e)||this.state.muted){n=0;return}if(this.rmsLevel()>Gn){if(n+=50,n>=Yn){this.clearMonitor(),t.cancel();let e=this.send({type:`barge-in`});e.phase===`listening`&&this.beginTurn(e.turn)}}else n=0},50)}finishSpeaking(e){if(this.staleTurn(e))return;this.clearMonitor();let t=this.send({type:`spoken`});t.phase===`listening`&&this.beginTurn(t.turn)}},er=({onClose:e,onSendMessage:t,isStreaming:n,lastAssistantMessage:r})=>{let{t:i,i18n:a}=c(),{preferences:o}=et(),[s,l]=(0,Q.useState)(Vn),[u,d]=(0,Q.useState)(``),[f,m]=(0,Q.useState)(null),h=(0,Q.useRef)(null),g=(0,Q.useRef)({isStreaming:!1,lastAssistantMessage:null,ttsSettings:void 0});(0,Q.useEffect)(()=>{g.current={isStreaming:n,lastAssistantMessage:r,ttsSettings:o.ttsSettings}},[n,r,o.ttsSettings]),(0,Q.useEffect)(()=>{let e=new $n({locale:a.language,sendMessage:e=>t(e),snapshot:()=>g.current,onState:e=>l(e),onTranscript:e=>d(e),onSupport:e=>m(e),messages:{microphoneFailed:i(`voiceMode.microphoneFailed`),transcriptionFailed:i(`voiceMode.transcriptionFailed`),replyTimeout:i(`voiceMode.replyTimeout`)}});return h.current=e,e.start(),()=>{h.current=null,e.close()}},[]);let _=s.phase,v=f===!1?`voiceMode.unsupported`:_===`listening`?s.muted?`voiceMode.muted`:`voiceMode.listening`:_===`transcribing`?`voiceMode.transcribing`:_===`generating`?`voiceMode.generating`:_===`speaking`?`voiceMode.speaking`:`voiceMode.starting`;return(0,At.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":i(`voiceMode.title`),className:`fixed inset-0 z-[70] flex flex-col items-center justify-center gap-6 bg-white/95 p-6 backdrop-blur dark:bg-dark-25/95`,"data-testid":`voice-mode-overlay`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:e,"aria-label":i(`voiceMode.close`),className:`absolute right-4 top-4 rounded-full p-2 text-gray-500 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:bg-dark-100`,children:(0,$.jsx)(U,{className:`h-5 w-5`})}),(0,$.jsx)(`div`,{className:p(`flex h-28 w-28 items-center justify-center rounded-full border-4 transition-colors`,_===`listening`&&!s.muted?`border-primary-500 text-primary-500`:_===`speaking`?`border-emerald-500 text-emerald-500`:_===`generating`||_===`transcribing`?`border-amber-500 text-amber-500`:`border-gray-300 text-gray-400 dark:border-dark-300`),children:_===`transcribing`||_===`generating`?(0,$.jsx)(N,{className:`h-10 w-10 animate-spin`}):s.muted?(0,$.jsx)(Re,{className:`h-10 w-10`}):_===`speaking`?(0,$.jsx)(B,{className:`h-10 w-10`}):(0,$.jsx)(k,{className:`h-10 w-10`})}),(0,$.jsxs)(`div`,{className:`text-center`,children:[(0,$.jsx)(`p`,{className:`text-base font-medium text-gray-900 dark:text-gray-100`,"data-testid":`voice-mode-status`,children:i(v)}),s.error&&(0,$.jsx)(`p`,{className:`mt-1 text-sm text-red-600 dark:text-red-400`,children:s.error}),u&&(0,$.jsxs)(`p`,{className:`mt-3 max-w-md text-sm text-gray-600 dark:text-gray-300`,children:[`“`,u,`”`]})]}),f!==!1&&(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.toggleMute(),"aria-label":s.muted?i(`voiceMode.unmute`):i(`voiceMode.mute`),"aria-pressed":s.muted,className:`rounded-full border border-gray-300 p-3 text-gray-700 hover:bg-gray-100 dark:border-dark-300 dark:text-gray-300 dark:hover:bg-dark-100`,children:s.muted?(0,$.jsx)(Re,{className:`h-5 w-5`}):(0,$.jsx)(k,{className:`h-5 w-5`})}),_===`listening`&&!s.muted&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.finishTurn(),"aria-label":i(`voiceMode.finishTurn`),className:`rounded-full border border-primary-500 p-3 text-primary-600 hover:bg-primary-50 dark:hover:bg-primary-950/30`,children:(0,$.jsx)(he,{className:`h-5 w-5`})}),_===`speaking`&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>h.current?.skipSpeech(),"aria-label":i(`voiceMode.skipReply`),className:`rounded-full border border-emerald-500 p-3 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-950/30`,children:(0,$.jsx)(M,{className:`h-5 w-5`})})]}),f===!1&&(0,$.jsx)(`p`,{className:`max-w-md text-center text-sm text-gray-600 dark:text-gray-300`,children:i(`voiceMode.unsupportedHint`)})]}),document.body)},tr=s(`components:chat-controls-panel`),nr=[{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`}],rr=({session:e,draftModel:t,open:n,onClose:r})=>{let{t:i}=c(),a=D(e=>e.draftSessionSettings),o=D(e=>e.setDraftSessionSettings),s=e?.model??t??``,u=et(e=>e.preferences.generationOptions),d=et(e=>e.preferences.modelGenerationOptions?.[s]),[f,p]=(0,Q.useState)({options:{},contextCapped:!1});(0,Q.useEffect)(()=>{if(!n||!s)return;let e=!1;return Qe.getModelDefaults(s).then(t=>{e||!t.success||!t.data||p({options:t.data.options??{},trainedContextLength:t.data.trainedContextLength,contextCapped:!!t.data.contextCapped})}).catch(()=>{}),()=>{e=!0}},[n,s]);let m=(0,Q.useMemo)(()=>({...u??{},...f.options,...d??{}}),[u,f.options,d]),h=(0,Q.useMemo)(()=>e?.messages.find(e=>e.role===`system`&&!g(e.content)),[e?.messages]),[_,v]=(0,Q.useState)(h?.content??a.systemPrompt??``),[y,b]=(0,Q.useState)(e?.settings?.generationOptions??a.generationOptions??{}),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(e?.settings?.compaction!==!1),[T,E]=(0,Q.useState)(e?.id??`draft`),O=e?.id??`draft`;T!==O&&(E(O),v(h?.content??a.systemPrompt??``),b(e?.settings?.generationOptions??a.generationOptions??{}),w(e?.settings?.compaction!==!1));let k=e=>{b(t=>{let n={...t},r=bt(e);return r===null?delete n.think:n.think=r,n})},A=(e,t)=>{b(n=>{let r={...n};if(t===``)delete r[e];else{let n=Number(t);Number.isNaN(n)||(r[e]=n)}return r})},j=async()=>{S(!0);try{let t=_.trim(),n=h?.content??``,a=Object.fromEntries(Object.entries(y).filter(([,e])=>e!==void 0)),s=e?{...e.settings,generationOptions:a}:Object.keys(a).length>0?{generationOptions:a}:void 0;if(s&&e&&(C?delete s.compaction:s.compaction=!1),!e){o({systemPrompt:t||void 0,generationOptions:s?.generationOptions}),q.success(i(`chat.controls.saved`)),r();return}let c=e.messages;if(t!==n.trim()&&(h?c=t?e.messages.map(e=>e.id===h.id?{...e,content:t}:e):e.messages.filter(e=>e.id!==h.id):t&&(c=[{id:l(),role:`system`,content:t,timestamp:Date.now()},...e.messages])),e.isPrivate)D.setState(t=>({currentSession:t.currentSession?.id===e.id?{...t.currentSession,messages:c,settings:s}:t.currentSession}));else{let t=await J.updateSession(e.id,{messages:c,settings:s});if(!t.success||!t.data)throw Error(t.error||`Update failed`);let n=t.data;D.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?n:t),currentSession:t.currentSession?.id===e.id?n:t.currentSession}))}q.success(i(`chat.controls.saved`)),r()}catch(e){tr.error(`Failed to save chat controls:`,e),q.error(i(`chat.controls.saveFailed`))}finally{S(!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)(U,{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:_,onChange:e=>v(e.target.value),placeholder:i(`chat.controls.systemPromptPlaceholder`),className:`min-h-[110px] w-full resize-y rounded-xl border border-black/[0.08] bg-white p-2.5 text-[13px] leading-relaxed text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]}),(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-think`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.thinking`)}),(0,$.jsx)(`select`,{id:`chat-control-think`,value:St(y.think),onChange:e=>k(e.target.value),className:`w-full rounded-xl border border-black/[0.08] bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`,children:Ct.map(e=>(0,$.jsx)(`option`,{value:e,children:e==="default"&&m.think!==void 0&&m.think!==null?i(`settings.generation.thinkingLevels.defaultWith`,{level:i(`settings.generation.thinkingLevels.${St(m.think)}`)}):i(`settings.generation.thinkingLevels.${e}`)},e))}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.thinkingDescription`)})]}),e&&(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`label`,{htmlFor:`chat-control-compaction`,className:`mb-1.5 block text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:i(`chat.controls.compaction`)}),(0,$.jsxs)(`select`,{id:`chat-control-compaction`,value:C?`default`:`off`,onChange:e=>w(e.target.value!==`off`),className:`w-full rounded-xl border border-black/[0.08] bg-white px-2.5 py-2 text-[13px] text-gray-900 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900`,children:[(0,$.jsx)(`option`,{value:`default`,children:i(`chat.controls.compactionDefault`)}),(0,$.jsx)(`option`,{value:`off`,children:i(`chat.controls.compactionOff`)})]}),(0,$.jsx)(`p`,{className:`mt-1.5 text-[11px] leading-snug text-gray-400 dark:text-dark-500`,children:i(`chat.controls.compactionDescription`)})]}),(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`)}),f.contextCapped&&f.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:m.num_ctx?.toLocaleString(),trained:f.trainedContextLength.toLocaleString()})}),(0,$.jsx)(`div`,{className:`space-y-1.5`,children:nr.map(e=>{let t=y[e.key],n=m[e.key],r=f.options[e.key]!==void 0&&d?.[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=>A(e.key,t.target.value),className:`w-24 rounded-lg border border-black/[0.08] bg-white px-2 py-1 text-end text-[12px] tabular-nums text-gray-900 placeholder:text-gray-400 focus:border-primary-500/40 focus:outline-none dark:border-white/[0.08] dark:bg-dark-50 dark:text-dark-900 dark:placeholder:text-dark-500`})]},e.key)})})]})]}),(0,$.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:()=>{b({}),v(h?.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)(X,{onClick:()=>void j(),size:`sm`,disabled:x,children:i(x?`common.saving`:`common.save`)})]})]}):null},ir=s(`components:chat-sources-panel`),ar=6,or=[],sr=e=>{try{return new URL(e).hostname.replace(/^www\./,``)}catch{return e}},cr=({session:e})=>{let{t}=c(),[n,r]=(0,Q.useState)({sessionId:``,docs:or}),i=!e.isPrivate&&n.sessionId===e.id?n.docs:or,[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),{webSources:f,ragSources:p,fullContextSkipped:m}=(0,Q.useMemo)(()=>{let t=new Map,n=new Map,r;for(let i of e.messages){let e=i.providerMetadata;if(Array.isArray(e?.webSearchSources))for(let n of e.webSearchSources){let e=n;e&&typeof e.url==`string`&&e.url&&t.set(e.url,{url:e.url,title:typeof e.title==`string`&&e.title?e.title:e.url})}if(Array.isArray(e?.ragSources))for(let t of e.ragSources){let e=t;e&&typeof e.id==`string`&&e.id&&n.set(e.id,{id:e.id,filename:typeof e.filename==`string`&&e.filename?e.filename:e.id,...Array.isArray(e.citations)?{citations:e.citations.filter(e=>!!e&&typeof e==`object`&&typeof e.chunkIndex==`number`)}:{},...e.full===!0?{full:!0}:{}})}let a=e?.ragFullContextSkipped;a&&typeof a.estimatedTokens==`number`&&typeof a.maxTokens==`number`?r={estimatedTokens:a.estimatedTokens,maxTokens:a.maxTokens}:e?.ragSources&&(r=void 0)}return{webSources:Array.from(t.values()),ragSources:Array.from(n.values()),fullContextSkipped:r}},[e.messages]);(0,Q.useEffect)(()=>{if(e.isPrivate)return;let t=!1,n=()=>{Ke.getDocuments(e.id).then(n=>{t||!n.success||!Array.isArray(n.data)||r({sessionId:e.id,docs:n.data.map(e=>({id:e.id,filename:e.filename,contentChars:e.contentChars}))})}).catch(()=>{})};return n(),window.addEventListener(`libre:documents-updated`,n),()=>{t=!0,window.removeEventListener(`libre:documents-updated`,n)}},[e.id,e.isPrivate]);let h=(0,Q.useMemo)(()=>{let e=new Map;for(let t of i)e.set(t.id,{...t,used:!1});for(let t of p)e.set(t.id,{...e.get(t.id)??{},id:t.id,filename:t.filename,used:!0,...t.citations?.length?{citations:t.citations}:{},...t.full?{full:!0}:{}});return Array.from(e.values())},[i,p]),g=e.settings?.fullDocumentContext===!0,_=(0,Q.useMemo)(()=>i.reduce((e,t)=>e+Math.ceil((t.contentChars??0)/4),0),[i]),v=async()=>{let t={...e.settings,fullDocumentContext:!g||void 0};if(D.setState(n=>({currentSession:n.currentSession?.id===e.id?{...n.currentSession,settings:t}:n.currentSession,sessions:n.sessions.map(n=>n.id===e.id?{...n,settings:t}:n)})),!e.isPrivate)try{await J.updateSession(e.id,{settings:t})}catch(e){ir.error(`Failed to update the full-document setting:`,e)}},y=e=>{let t=[];for(let n of e){let e=n.location??`#${n.chunkIndex+1}`;if(t.includes(e)||t.push(e),t.length>=4)break}return t.join(` · `)};if(f.length===0&&h.length===0)return null;let b=a?f:f.slice(0,ar),x=s?h:h.slice(0,ar),S=(e,n,r)=>(e>0||n)&&(0,$.jsx)(`button`,{type:`button`,onClick:r,className:`mt-1 flex items-center gap-1 px-1 text-[12px] text-gray-400 transition-colors hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,children:n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(te,{className:`h-3 w-3`}),t(`chatMessage.showLess`,`Show less`)]}):`${t(`chatMessage.showMore`)} (${e})`}),C=(0,$.jsxs)($.Fragment,{children:[f.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:b.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`group -mx-1 flex items-center gap-2.5 rounded-lg px-1 py-1.5 transition-colors hover:bg-black/[0.04] dark:hover:bg-white/[0.05]`,title:e.url,children:[(0,$.jsx)(ue,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-700 dark:text-dark-500 dark:group-hover:text-dark-800`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.title}),(0,$.jsx)(`span`,{dir:`ltr`,className:`block truncate text-[11px] text-gray-400 dark:text-dark-500`,children:sr(e.url)})]})]})},e.url))}),S(f.length-b.length,a,()=>o(e=>!e))]}),h.length>0&&(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-[13px] font-medium text-gray-500 dark:text-dark-500`,children:t(`settings.tabs.documents`,`Documents`)}),(0,$.jsx)(`ul`,{className:`space-y-0.5`,children:x.map(e=>(0,$.jsxs)(`li`,{className:`-mx-1 rounded-lg px-1 py-1.5`,title:e.filename,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2.5`,children:[(0,$.jsx)(H,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsx)(`span`,{dir:`ltr`,className:`min-w-0 flex-1 truncate text-[13px] leading-snug text-gray-800 dark:text-dark-800`,children:e.filename}),e.used&&(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`h-1.5 w-1.5 shrink-0 rounded-full bg-primary-500`})]}),e.full?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-gray-400 dark:text-dark-500`,"data-testid":`chat-source-citation`,children:t(`documents.fullDocument`,`Full document`)}):e.citations?.length?(0,$.jsx)(`span`,{className:`ms-[26px] block truncate text-[11px] text-gray-400 dark:text-dark-500`,"data-testid":`chat-source-citation`,children:y(e.citations)}):null]},e.id))}),S(h.length-x.length,s,()=>l(e=>!e)),(0,$.jsxs)(`label`,{className:`mt-3 flex cursor-pointer items-center gap-2 px-1 text-[12px] text-gray-500 dark:text-dark-500`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:g,onChange:v,"data-testid":`full-document-context-toggle`,className:`h-3.5 w-3.5 rounded border-gray-300 text-primary-600 focus:ring-primary-500 dark:border-dark-400`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[t(`documents.fullContextToggle`,`Send full documents`),g&&_>0&&(0,$.jsx)(`span`,{className:`ms-1 text-gray-400 dark:text-dark-500`,children:t(`documents.fullContextEstimate`,{tokens:_.toLocaleString()})})]})]}),g&&m&&(0,$.jsx)(`p`,{className:`mt-1 px-1 text-[11px] text-amber-600 dark:text-amber-400`,"data-testid":`full-document-context-warning`,children:t(`documents.fullContextTooLarge`)})]})]});return(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`aside`,{"data-testid":`chat-sources-panel`,className:`hidden w-72 shrink-0 flex-col gap-7 overflow-y-auto border-s border-black/[0.05] px-5 py-6 scrollbar-thin dark:border-white/[0.06] xl:flex`,children:C}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>d(!0),"data-testid":`chat-sources-trigger`,className:`absolute end-3 top-[4.25rem] z-20 flex h-8 w-8 items-center justify-center rounded-full border border-black/[0.07] bg-surface/65 text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 xl:hidden`,title:t(`chat.message.sources`,`Sources`),"aria-haspopup":`dialog`,"aria-expanded":u,children:[(0,$.jsx)(be,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`absolute -end-0.5 -top-0.5 flex h-4 min-w-4 items-center justify-center rounded-md bg-primary-500 px-1 text-[9px] font-semibold tabular-nums text-white shadow-sm`,children:f.length+h.length})]}),u&&(0,At.createPortal)((0,$.jsxs)(`div`,{className:`fixed inset-0 z-[80] xl:hidden`,children:[(0,$.jsx)(`button`,{type:`button`,className:`absolute inset-0 bg-black/35 backdrop-blur-[2px]`,onClick:()=>d(!1),"aria-label":t(`common.close`)}),(0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":t(`chat.message.sources`,`Sources`),className:`absolute inset-x-3 bottom-3 max-h-[75vh] overflow-y-auto rounded-2xl border border-black/[0.08] bg-surface p-5 shadow-[0_20px_70px_rgba(0,0,0,0.3)] scrollbar-thin dark:border-white/[0.09] dark:bg-dark-100`,"data-testid":`chat-sources-sheet`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold text-gray-900 dark:text-dark-900`,children:t(`chat.message.sources`,`Sources`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>d(!1),className:`rounded-md p-1.5 text-gray-400 hover:text-gray-700 dark:text-dark-500 dark:hover:text-dark-800`,"aria-label":t(`common.close`),children:(0,$.jsx)(U,{className:`h-4 w-4`})})]}),(0,$.jsx)(`div`,{className:`flex flex-col gap-6`,children:C})]})]}),document.body)]})},lr=({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=()=>We(e,64),u=t=>{Ve(t.currentTarget,e.name,64)};return(0,$.jsxs)(`div`,{className:p(`relative`,n),children:[(0,$.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:p(`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-md object-cover`,onError:u}),(0,$.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,$.jsx)(ae,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,$.jsx)(F,{className:p(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,At.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:p(`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)(U,{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)(Oe,{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)(ne,{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)(j,{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)(Ie,{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)(Oe,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},ur=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=c(),a=(0,Q.useRef)(null),[o,s]=(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/`)){q.error(`File ${o.name} is not an image`);continue}if(o.size>10485760){q.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&&q.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),s(!0)},d=e=>{e.preventDefault(),s(!1)},f=e=>{e.preventDefault(),s(!1),l(e.dataTransfer.files)},m=n=>{t(e.filter((e,t)=>t!==n))},h=e.length<n;return(0,$.jsxs)(`div`,{className:p(`space-y-3`,r),children:[h&&(0,$.jsxs)(`div`,{className:p(`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)(W,{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)(X,{variant:`ghost`,size:`sm`,onClick:()=>m(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,$.jsx)(U,{className:`h-4 w-4`})})})]},t))}),h&&e.length>0&&(0,$.jsxs)(X,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,$.jsx)(fe,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},dr=s(`pages:chat-page`),fr=(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?`}},pr=(e,t,n,r=!1)=>{let i=nt(e);return i===`time`?fr(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.`}},mr=e=>{if(!e)return null;for(let t=e.length-1;t>=0;--t){let n=e[t];if(n.role===`assistant`)return{id:n.id,content:n.content}}return null},hr=()=>{let{t:e,i18n:t}=c(),{sessionId:n}=a(),r=i(),s=o(),{currentSession:u,sessions:d,models:f,selectedModel:g,selectedProviderType:v,selectedProviderId:b,setSelectedModel:x,createSession:C,setCurrentSession:w,loadSessions:E,getCurrentPersona:k}=D(),{user:A}=$e(),j=et(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:M,stopGeneration:N,cancelComparison:ee,regenerateLastMessage:te,editAndResendMessage:ne,selectBranch:re,isStreaming:P,streamingMessage:F,streamingThinking:ie,streamingMessageId:I,toolActivities:ae,activeToolCalls:oe,pendingToolApproval:se,decideToolApproval:ce}=ut(u?.id||``),le=k(),R=(0,Q.useMemo)(()=>({model:g,providerType:v,providerId:b}),[g,b,v]),fe=(0,Q.useMemo)(()=>h(f,R),[f,R]),pe=g?T(fe,R):``,me=y(f,R),he=new URLSearchParams(s.search).get(`incognito`)===`1`,[ge,_e]=(0,Q.useState)(tt),[ve,z]=(0,Q.useState)(null),[ye,be]=(0,Q.useState)(!1),B=et(e=>e.preferences.showFollowUpSuggestions!==!1),Se=(0,Q.useRef)(null),Ce=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{let e=u?.id,t=Ce.current&&!P;if(Ce.current=P,!e||P||!B||u?.isPrivate||!t)return;let n=u.messages[u.messages.length-1];if(!n||n.role!==`assistant`||!n.content.trim()||Se.current===n.id)return;Se.current=n.id;let r=!1;return J.generateFollowUps(e).then(t=>{r||!t.success||D.getState().currentSession?.id===e&&z({sessionId:e,suggestions:t.data?.suggestions??[]})}).catch(()=>{}),()=>{r=!0}},[P,u,B]);let Te=ve&&ve.sessionId===u?.id?ve.suggestions:[],De=(0,Q.useMemo)(()=>pr(ge,A?.username,e,m(t.language)),[t.language,e,A?.username,ge]),[H,U]=(0,Q.useState)(``),[Oe,ke]=(0,Q.useState)([]),[Ae,W]=(0,Q.useState)(!1),[G,je]=(0,Q.useState)(!1),[K,Me]=(0,Q.useState)(In),[Ne,Pe]=(0,Q.useState)(!1),Fe=(0,Q.useRef)(null),Ie=D(e=>e.draftSessionSettings),Re=D(e=>e.setDraftSessionSettings),ze=Ie.generationOptions?.think,Ve=et(e=>(g?e.preferences.modelGenerationOptions?.[g]?.think:void 0)??e.preferences.generationOptions?.think??null),Y=(0,Q.useMemo)(()=>f.find(e=>e.name===g),[f,g]),[He,Ue]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{if(!g||f.length===0||!Y||Y.isPlugin||Y.isAgent)return;let e=!1;return Qe.getModelDefaults(g).then(t=>{e||!t.success||!t.data||Ue({model:g,supported:t.data.supportsThinking})}).catch(()=>{}),()=>{e=!0}},[g,Y,f.length]);let We=!!(g&&!Y?.isAgent&&(Y?.isPlugin?Y.reasoningSupport!==!1:He?.model!==g||He.supported!==!1)),Ge=e=>{let t=D.getState().draftSessionSettings,n={...t.generationOptions};e===null?delete n.think:n.think=e,Re({...t,generationOptions:Object.keys(n).length?n:void 0})},qe=async t=>{let n=t.target.files?.[0];if(t.target.value=``,n){Pe(!0);try{let t=await Ke.uploadDocument(n);t.success?(q.success(e(`chat.input.menu.documentAttached`)),window.dispatchEvent(new Event(`libre:documents-updated`))):q.error(t.error||e(`chat.input.menu.attachFailed`))}catch(t){dr.error(`Document upload failed:`,t),q.error(e(`chat.input.menu.attachFailed`))}finally{Pe(!1)}}};(0,Q.useEffect)(()=>{let e=!1;return Ze.getConfig().then(t=>{!e&&t.success&&t.data&&W(t.data.allowed)}).catch(()=>{}),()=>{e=!0}},[]);let[Je,Ye]=(0,Q.useState)(!1),Xe=(0,Q.useRef)(null),nt=(0,Q.useRef)(null);(0,Q.useEffect)(()=>{let e=()=>{_e(tt())};return window.addEventListener(rt,e),()=>window.removeEventListener(rt,e)},[]);let[at,ot]=(0,Q.useState)(!1),[Z,ct]=(0,Q.useState)(!1),lt=mr(u?.messages),dt=j&&at,ft=(0,Q.useCallback)((t=!0)=>{let n=g?R:f[0]?_(f[0]):null;if(!n||!y(f,n))return t&&q.error(e(`chat.model.selectBeforePrivateChat`)),!1;let r=Date.now();return w({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},[f,g,R,w,e]);(0,Q.useEffect)(()=>{d.length===0&&E()},[E,d.length]),(0,Q.useEffect)(()=>{!he||u?.isPrivate||ft(!1)},[u?.isPrivate,he,ft]),(0,Q.useEffect)(()=>{let e=!1;return j&&(async()=>{try{let t=await Be.getPlugins();if(e)return;ot(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;ot(!1)}})(),()=>{e=!0}},[j]),(0,Q.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!(u?.isPrivate&&!n)&&d.length!==0){if(n){let e=d.find(e=>e.id===n);e&&e.id!==u?.id?w(e):e||(dr.warn(`Session ${n} not found for current user, redirecting...`),d.length>0?r(`/c/${d[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&d.length>0&&s.pathname===`/`&&r(`/c/${d[0].id}`,{replace:!0})}})()},[n,d,w,r,u?.id,u?.isPrivate,s.pathname]),(0,Q.useEffect)(()=>{if(u?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{M(t.content,t.images,void 0,t.webSearch===!0,t.tools===!0,t.toolSelection)},100)}catch(e){dr.error(`Failed to parse pending message:`,e)}}}},[u?.id,M]),(0,Q.useEffect)(()=>{let e=Xe.current;e&&(e.style.height=`auto`,e.style.height=H?`${Math.min(e.scrollHeight,200)}px`:``)},[H]);let pt=async t=>{if(t.preventDefault(),!H.trim()||!g)return;if(!me){q.error(e(`chat.model.selectBeforeSending`));return}it(`impact`);let n={content:H.trim(),images:Oe.length>0?Oe:void 0,webSearch:Ae&&G?!0:void 0,...Ln(K)};sessionStorage.setItem(`pendingMessage`,JSON.stringify(n)),U(``),ke([]),je(!1),Me(In);let i=await C(g,void 0,g.startsWith(`persona:`)?g.slice(8):void 0,v,b);i&&(await mt(i),r(`/c/${i.id}`,{replace:!0}))},mt=(0,Q.useCallback)(async e=>{let t=D.getState().draftSessionSettings,n=t.systemPrompt?.trim(),r=t.generationOptions;if(!n&&!r)return;let i=n?[{id:l(),role:`system`,content:n,timestamp:Date.now()},...e.messages.filter(e=>e.role!==`system`)]:e.messages;try{let t=await J.updateSession(e.id,{messages:i,settings:r?{generationOptions:r}:void 0});if(t.success&&t.data){let e=t.data;D.setState(t=>({sessions:t.sessions.map(t=>t.id===e.id?e:t),currentSession:t.currentSession?.id===e.id?e:t.currentSession}))}}catch(e){dr.error(`Failed to apply chat settings to the new session`,e)}finally{D.getState().setDraftSessionSettings({})}},[]),ht=e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||nt.current?.handleKeyDown(e)||e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),pt(e))},gt=async e=>{let t=O(fe,e.target.value);t&&x(t.model,t.providerType,t.providerId)},_t=(e,t,n,r,i,a,o)=>{u&&(it(`impact`),z(null),M(e,t,n,r,i,a,o))},vt=u?.id,bt=(0,Q.useCallback)(async t=>{if(vt)try{let n=await J.forkSession(vt,{messageId:t});if(n.success&&n.data){let t=n.data;D.setState(e=>({sessions:[t,...e.sessions]})),q.success(e(`chat.fork.created`)),r(`/c/${t.id}`)}else q.error(n.error||e(`chat.fork.failed`))}catch(t){dr.error(`Failed to fork the chat:`,t),q.error(e(`chat.fork.failed`))}},[vt,r,e]);if(!u){let t=Oe.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,$.jsx)(`button`,{onClick:()=>be(e=>!e),className:p(`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`,ye&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ye,children:(0,$.jsx)(L,{className:`h-4 w-4`})}),(0,$.jsxs)(`button`,{onClick:()=>ft(),disabled:!g&&f.length===0||!!g&&!me,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)(we,{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-8 flex flex-col items-center text-center animate-fade-in sm:mb-10`,"aria-live":`polite`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-center justify-center gap-3`,children:[(0,$.jsx)(st,{size:`sm`,label:null,className:`h-9 w-9 shrink-0 p-0 text-ink`}),(0,$.jsx)(`h1`,{className:`max-w-3xl text-balance text-[clamp(1.75rem,3.5vw,2.35rem)] font-medium leading-tight tracking-[-0.02em] text-ink rtl:tracking-normal`,children:De.title})]}),(0,$.jsx)(`p`,{className:`max-w-xl text-balance text-[15px] leading-relaxed text-ink-subtle`,children:De.subtitle})]},De.id),fe.length>0?(0,$.jsxs)(`div`,{className:`w-full`,children:[Je&&(0,$.jsxs)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:[(0,$.jsx)(ur,{images:Oe,onImagesChange:ke,maxImages:5}),(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-3 border-t border-black/[0.06] pt-3 dark:border-white/[0.07]`,children:[(0,$.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:e(`chat.input.menu.attachDocument`)}),(0,$.jsxs)(X,{type:`button`,size:`sm`,variant:`outline`,disabled:Ne,onClick:()=>Fe.current?.click(),className:`shrink-0 whitespace-nowrap`,children:[(0,$.jsx)(Ee,{className:`h-3.5 w-3.5`}),(0,$.jsx)(`span`,{className:`ms-1.5`,children:e(Ne?`documents.uploading`:`chat.input.menu.attach`)})]}),(0,$.jsx)(`input`,{ref:Fe,type:`file`,accept:Dn,className:`hidden`,onChange:e=>void qe(e)})]})]}),(0,$.jsx)(`form`,{onSubmit:pt,children:(0,$.jsxs)(`div`,{"data-composer-box":``,className:Dt,children:[(0,$.jsx)(Nn,{ref:nt,message:H,onApply:e=>{U(e),Xe.current?.focus()}}),(0,$.jsx)(un,{ref:Xe,value:H,onChange:e=>U(e.target.value),onKeyDown:ht,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 block w-full min-h-9 max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !px-2 !pt-1.5 !pb-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-ink-subtle focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 text-[0.9375rem] leading-relaxed touch-manipulation`,rows:1}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>Ye(!Je),className:p(`h-9 w-9 !p-0 rounded-full flex-shrink-0`,`bg-surface-subtle text-ink-muted hover:bg-hover-solid hover:text-ink dark:bg-surface-raised dark:hover:bg-surface-overlay transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,Je&&`bg-hover-solid text-ink`),title:e(`chat.input.attachImages`),children:t?(0,$.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,$.jsx)(Ee,{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`})]}):Je?(0,$.jsx)(de,{className:`h-4 w-4`}):(0,$.jsx)(Le,{className:`h-4 w-4`})}),We&&(0,$.jsx)(vn,{value:ze,inheritedValue:Ve,onChange:Ge}),Ae&&(0,$.jsx)(X,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>je(e=>!e),className:p(`h-9 w-9 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`text-ink-muted hover:bg-interactive-hover hover:text-ink`,`transition-colors duration-150 touch-manipulation`,G&&`bg-primary-50 text-primary-600 dark:bg-primary-900/25 dark:text-primary-400`),title:e(G?`chat.input.webSearchOn`:`chat.input.webSearchOff`),"aria-pressed":G,children:(0,$.jsx)(ue,{className:`h-4 w-4`})}),(0,$.jsx)(Fn,{value:K,onChange:Me,buttonClassName:`h-9 w-9`}),(0,$.jsx)(`div`,{className:`min-w-0 flex-1`}),(0,$.jsx)(`div`,{className:`hidden sm:block`,children:(0,$.jsx)(Et,{models:fe,selectedModel:pe,onModelChange:gt,getModelValue:S,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:dt})}),(0,$.jsx)(X,{type:`submit`,variant:`primary`,size:`sm`,disabled:!H.trim()||!g||!me,className:kt,title:e(`chat.input.sendMessage`),children:(0,$.jsx)(V,{className:`h-4 w-4`})})]})]})}),(0,$.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,$.jsx)(Et,{models:fe,selectedModel:pe,onModelChange:gt,getModelValue:S,className:`w-full`,compact:!0,showImageGen:dt})}),(0,$.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-ink-subtle`,children:e(`chat.footer.disclaimer`)})]}):(0,$.jsxs)(`div`,{className:`flex w-full max-w-lg flex-col items-center gap-4`,children:[(0,$.jsx)(`p`,{className:`text-center text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.connectDescription`)}),(0,$.jsx)(yt,{variant:`inline`})]})]})]}),(0,$.jsx)(rr,{draftModel:g,open:ye,onClose:()=>be(!1)})]})}return(0,$.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:le?.background?{backgroundImage:`url(${le.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[le?.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:[u?.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)(we,{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-ink-subtle sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),le&&!u?.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)(lr,{persona:le,onClear:()=>{u&&J.updateSession(u.id,{model:le.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);D.setState(t=>({sessions:t.sessions.map(t=>t.id===u.id?e.data:t),currentSession:e.data}))}).catch(t=>{dr.error(`Failed to remove persona:`,t),q.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:()=>be(e=>!e),className:p(`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`,ye&&`text-primary-600 dark:text-primary-400`),title:e(`chat.controls.title`),"aria-expanded":ye,children:(0,$.jsx)(L,{className:`h-3.5 w-3.5`})}),u.settings?.forkedFrom&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(`/c/${u.settings.forkedFrom.sessionId}`),className:`mx-auto mt-2 flex items-center gap-1.5 rounded-full border border-black/[0.07] bg-surface/70 px-3 py-1 text-[11px] text-gray-500 transition-colors hover:text-gray-800 dark:border-white/[0.08] dark:bg-dark-200/70 dark:text-dark-600 dark:hover:text-dark-900`,"data-testid":`forked-from-banner`,children:[(0,$.jsx)(xe,{className:`h-3 w-3`}),e(`chat.fork.origin`,{title:u.settings.forkedFrom.title||e(`chat.fork.originUnknown`)})]}),(0,$.jsx)(cn,{messages:u.messages,streamingMessage:F,streamingThinking:ie,streamingMessageId:I,isStreaming:P,toolActivities:ae,activeToolCalls:oe,pendingToolApproval:se,onDecideToolApproval:ce,onRegenerate:te,onSelectBranch:re,onEditResend:ne,onFork:bt,followUpSuggestions:Te,onFollowUpSelect:e=>_t(e),className:`flex-1`}),u?.shared?(0,$.jsx)(`div`,{className:`mx-auto mb-4 w-full max-w-3xl rounded-xl border border-black/[0.06] bg-black/[0.02] px-4 py-3 text-center text-[13px] text-gray-500 dark:border-white/[0.08] dark:bg-white/[0.03] dark:text-dark-600`,"data-testid":`chat-shared-readonly`,children:e(`chat.sharedReadOnly`,{owner:u.shared.ownerUserId})}):(0,$.jsx)(Bn,{onSendMessage:_t,onStopGeneration:N,onCancelComparison:ee,onOpenVoiceMode:()=>ct(!0),disabled:!u})]}),Z&&u&&(0,$.jsx)(er,{onClose:()=>ct(!1),onSendMessage:e=>_t(e),isStreaming:P,lastAssistantMessage:lt}),u&&(0,$.jsx)(cr,{session:u}),(0,$.jsx)(rr,{session:u,open:ye,onClose:()=>be(!1)})]})]})]})};export{hr as ChatPage,hr as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{d as r}from"./router-vendor-Epc3_KZ_.js";import{t as i}from"./useTranslation-rdLmo6zV.js";import{a,r as o,t as s}from"./utils-CKWltgs8.js";import{t as c}from"./chatStore-BvZkd8Un.js";import{$n as l,Et as u,M as d,c as f,in as p,mt as m,or as h,t as g,tr as _}from"./ui-vendor-Dt9hfsGD.js";import{d as v,t as y}from"./authStore-CieFdk4S.js";import{t as b}from"./workStatus-CcO9Fg41.js";import{n as x,r as S,t as C}from"./appNavigation-DySHcEGS.js";import{t as w}from"./appVersion-CAidQlBP.js";import{t as T}from"./work-DVgm81bJ.js";var E=e(t(),1),D=n(),O=e=>e<5?`chat.greeting.night`:e<12?`chat.greeting.morning`:e<18?`chat.greeting.afternoon`:`chat.greeting.evening`,k=`mb-2 text-xs font-medium text-gray-500 dark:text-dark-500`,A=`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`,j=()=>{let{t:e,i18n:t}=i(),n=r(),{user:j,systemInfo:M,canUseWork:N,canUseAgents:P}=y(),F=c(e=>e.sessions),I=c(e=>e.models),L=v(e=>e.tasks),R=v(e=>e.capabilities),z=v(e=>e.loadTasks),B=v(e=>e.loadCapabilities),V=N(),H=P();(0,E.useEffect)(()=>{V&&(z(!0).catch(()=>{}),B().catch(()=>{}))},[V,z,B]);let U=e(O(new Date().getHours())),W=j?.username,G=[...F].sort((e,t)=>t.updatedAt-e.updatedAt).slice(0,4),K=[...L].sort((e,t)=>new Date(t.updatedAt).getTime()-new Date(e.updatedAt).getTime()).slice(0,3),q=R?.activeRuntimes?.user??0,J=a()?`⌘`:`Ctrl`,Y=G.length>0||K.length>0,X=w(M?.version);return(0,D.jsx)(`div`,{"data-testid":`home-page`,className:`h-full overflow-y-auto scrollbar-thin`,children:(0,D.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-xl flex-col justify-center px-6 py-12`,children:[(0,D.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-gray-950 dark:text-dark-950`,children:W?`${U}, ${W}.`:`${U}.`}),(0,D.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`,X?` · v${X}`:``]}),(0,D.jsxs)(`div`,{className:`mt-8`,children:[(0,D.jsx)(`p`,{className:k,children:e(`home.start`,`Start`)}),(0,D.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-new-chat`,className:A,onClick:()=>x(n),children:[(0,D.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,D.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newChat`,`New Chat`)}),(0,D.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:[J,`⇧O`]})]}),(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-incognito-chat`,className:A,onClick:()=>C(n),children:[(0,D.jsx)(p,{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,D.jsx)(`span`,{className:`flex-1`,children:e(`chat.session.incognito`,`Incognito Chat`)})]}),V&&(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-new-work`,className:A,onClick:()=>S(n),children:[(0,D.jsx)(_,{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,D.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newWork`,`New Work`)}),(0,D.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:[J,`⇧U`]})]})]})]}),Y&&(0,D.jsxs)(`div`,{className:`mt-8`,children:[(0,D.jsxs)(`div`,{className:`mb-2 flex items-baseline justify-between`,children:[(0,D.jsx)(`p`,{className:s(k,`mb-0`),children:e(`home.continue`,`Continue`)}),V&&q>0&&(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,D.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse-subtle rounded-full bg-[rgb(48,121,255)]`}),q,` `,e(`home.active`,`active`)]})]}),(0,D.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[K.map(r=>{let i=b[r.status];return(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-work`,className:A,onClick:()=>n(`/work/${r.id}`),children:[(0,D.jsx)(`span`,{"aria-hidden":`true`,className:s(`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,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`work.tasks.untitled`,`Untitled task`)}),r.hostPath&&(0,D.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,D.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:T(r)?e(i.labelKey,i.label):o(new Date(r.updatedAt).getTime(),t.language)})]},r.id)}),G.map(r=>(0,D.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-chat`,className:A,onClick:()=>n(`/c/${r.id}`),children:[(0,D.jsx)(u,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,D.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`tabs.chat`,`Chat`)}),(0,D.jsx)(`span`,{className:`hidden shrink-0 font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,children:r.model.startsWith(`persona:`)?I.find(e=>e.isPersona&&e.name===r.model)?.personaName||e(`chat.persona.label`,`Persona`):r.model}),(0,D.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:o(r.updatedAt,t.language)})]},r.id))]})]}),(0,D.jsxs)(`div`,{className:`mt-8`,children:[(0,D.jsx)(`p`,{className:k,children:e(`home.explore`,`Explore`)}),(0,D.jsx)(`div`,{className:`-mx-2.5 flex flex-col`,children:[[`/notes`,m,e(`sidebar.navigation.notes`,`Notes`)],[`/calendar`,l,e(`sidebar.navigation.calendar`,`Calendar`)],[`/automations`,g,e(`sidebar.navigation.automations`,`Automations`)],[`/personas`,f,e(`sidebar.navigation.personas`,`Personas`)],[`/gallery`,d,e(`sidebar.navigation.imagine`,`Imagine`)],...H?[[`/agents`,h,e(`sidebar.navigation.agents`,`Agents`)]]:[]].map(([e,t,r])=>(0,D.jsxs)(`button`,{type:`button`,className:A,onClick:()=>n(e),children:[(0,D.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,D.jsx)(`span`,{className:`flex-1`,children:r})]},e))})]})]})})};export{j as HomePage,j as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./useTranslation-rdLmo6zV.js";import{t as i}from"./utils-CKWltgs8.js";import{C as a,D as o,E as s}from"./chatStore-BvZkd8Un.js";import{E as c,In as l,J as u,Jn as d,T as f,_t as p,ct as m,w as h}from"./ui-vendor-Dt9hfsGD.js";import{t as g}from"./authStore-CieFdk4S.js";import{f as _,l as v,n as y,p as b,t as x,u as S}from"./appStore-DrTsJPfh.js";var C=e(t(),1),w=e=>/^\/(?:chat\/?|c\/[^/]+\/?|work(?:\/[^/]+)?\/?)$/.test(e),T=524288,E=1024;function D(e,t,n=2){if(!Number.isFinite(e)||!Number.isFinite(t)||e<=0||t<=0)return{width:0,height:0};let r=Math.min(1/Math.max(1,n),E/Math.max(e,t),Math.sqrt(T/(e*t)));return{width:Math.max(1,Math.floor(e*r)),height:Math.max(1,Math.floor(t*r))}}function O(e,t,n,r){let i=Math.max(n/e,r/t),a=n/i,o=r/i;return{x:(e-a)/2,y:(t-o)/2,width:a,height:o}}var k=[0,48,12,60,3,51,15,63,32,16,44,28,35,19,47,31,8,56,4,52,11,59,7,55,40,24,36,20,43,27,39,23,2,50,14,62,1,49,13,61,34,18,46,30,33,17,45,29,10,58,6,54,9,57,5,53,42,26,38,22,41,25,37,21];function A(e){let t=new Float32Array(e);for(let n=0;n<t.length;n+=4){let r=Math.max(e[n],e[n+1],e[n+2]);if(r===0)continue;let i=M[e[n]]*.2126+M[e[n+1]]*.7152+M[e[n+2]]*.0722,a=N[Math.round(i*4096)],o=(a<=64?a:64+(a-64)*48/191)/r;for(let r=0;r<3;r+=1)t[n+r]=e[n+r]*o}return t}function j(e,t,n){if(!Number.isSafeInteger(t)||!Number.isSafeInteger(n)||t<0||n<0||t*n*4!==e.length)throw RangeError(`Wallpaper pixel dimensions do not match the buffer`);let r=new Uint8ClampedArray(e);for(let i=0;i<n;i+=1)for(let n=0;n<t;n+=1){let a=(i*t+n)*4,o=(k[i%8*8+n%8]+.5)/64-.5,s=Math.max(e[a],e[a+1],e[a+2]);if(s===0)continue;let c=Math.round(s/255*1+o),l=Math.max(0,Math.min(1,c))*255/1/s;for(let t=0;t<3;t+=1)r[a+t]=e[a+t]*l}return r}var M=Array.from({length:256},(e,t)=>{let n=t/255;return n<=.04045?n/12.92:((n+.055)/1.055)**2.4}),N=Uint8ClampedArray.from({length:4097},(e,t)=>{let n=t/4096;return 255*(n<=.0031308?n*12.92:1.055*n**(1/2.4)-.055)});function P(e){let t=new Uint8ClampedArray(e);for(let e=0;e<t.length;e+=4){let n=M[t[e]],r=M[t[e+1]],i=M[t[e+2]],a=n*.2126+r*.7152+i*.0722;if(a<=.16)continue;let o=.16/a;t[e]=N[Math.round(n*o*4096)],t[e+1]=N[Math.round(r*o*4096)],t[e+2]=N[Math.round(i*o*4096)]}return t}function F(e,t,n){let r=P(j(A(e),t,n));for(let e=0;e<r.length;e+=4)r[e]===0&&r[e+1]===0&&r[e+2]===0&&(r[e+3]=0);return r}var I=n();function L({settings:e,testId:t=`wallpaper-layer`}){return!e.enabled||!e.imageUrl||e.opacity===0?null:(0,I.jsx)(R,{settings:e,testId:t})}function R({settings:e,testId:t}){let n=(0,C.useRef)(null),r=(0,C.useRef)(null),[i,a]=(0,C.useState)(null),{imageUrl:o,effect:s}=e,c=x(e=>e.theme.mode),l=S(e=>e.palette?.isDark),u=c===`dark`||c===`amoled`||c===`celestial`&&l===!0,d=i?.source===o&&i.effect===s&&i.dark===u?i.state:`loading`;return(0,C.useEffect)(()=>{let e=n.current;if(!e)return;let t=!1,i,c=new Image;c.decoding=`async`,c.referrerPolicy=`no-referrer`,(s===`dither`||u)&&(c.crossOrigin=`anonymous`);let l=e=>{t||a({source:o,effect:s,state:e,dark:u})},d=()=>{if(t||!c.naturalWidth||!c.naturalHeight)return;let n=r.current,{width:i,height:a}=e.getBoundingClientRect(),o=D(i,a,s===`dither`?3:1);if(!(!n||!o.width||!o.height))try{n.width=o.width,n.height=o.height;let e=n.getContext(`2d`,{willReadFrequently:!0});if(!e)throw Error(`Canvas unavailable`);let t=O(c.naturalWidth,c.naturalHeight,o.width,o.height);if(e.drawImage(c,t.x,t.y,t.width,t.height,0,0,o.width,o.height),s===`dither`||u){let t=e.getImageData(0,0,o.width,o.height),n=s===`dither`?F(t.data,o.width,o.height):P(t.data);t.data.set(n),e.putImageData(t,0,0)}l(`ready`)}catch{l(`fallback`)}},f=new ResizeObserver(()=>{i&&clearTimeout(i),i=setTimeout(d,100)});return f.observe(e),c.onload=d,c.onerror=()=>l(`fallback`),c.src=o,()=>{t=!0,f.disconnect(),i&&clearTimeout(i),c.onload=null,c.onerror=null,c.removeAttribute(`src`)}},[o,s,u]),(0,I.jsxs)(`div`,{ref:n,"data-testid":t,"data-effect":s,"data-state":d,"data-tone":i?.dark?`dark`:`light`,className:`account-wallpaper`,"aria-hidden":`true`,style:{"--wallpaper-intensity":e.opacity,"--wallpaper-blur":`${e.blurAmount}px`},children:[(0,I.jsxs)(`div`,{className:`account-wallpaper__art`,children:[(0,I.jsx)(`canvas`,{ref:r,"data-testid":`wallpaper-canvas`,className:`account-wallpaper__canvas`}),d===`fallback`&&(0,I.jsx)(`img`,{src:o,alt:``,draggable:!1,referrerPolicy:`no-referrer`,className:`account-wallpaper__photo`})]}),(0,I.jsx)(`div`,{className:`account-wallpaper__veil`})]})}function z({active:e=!0}){let t=x(e=>e.preferences.backgroundSettings),n=x(e=>e.backgroundImage),r=g(e=>e.user?.id),i=g(e=>e.systemInfo?.requiresAuth),a=y(t);return a.imageUrl=n??a.imageUrl,!e||i!==!1&&!r||!a.enabled||!a.imageUrl?null:(0,I.jsx)(L,{settings:a,testId:`app-background`},r??`solo`)}var B=e=>(Math.round(e)%1440+1440)%1440,V=()=>{let{t:e}=r(),t=S(e=>e.palette),n=S(e=>e.previewMinutes),a=S(e=>e.location),o=S(e=>e.weather),s=S(e=>e.weatherEnabled),d=new Date().setHours(0,0,0,0),g=s&&a?o:null,y=(0,C.useMemo)(()=>{let e=new Date(d);return`linear-gradient(to right, ${Array.from({length:17},(t,n)=>{let r=Math.min(n*1440/16,1439);return`${b(e,r,{location:a,weather:g}).sky.mid} ${n*100/16}%`}).join(`, `)})`},[d,a,g]);if(!t)return null;let x=B(n??t.solar.minutes),w=_(x),T=n!==null,E=t.solar.isDay?c:p,D=T?m:l,O=[{key:`sunrise`,minutes:t.solar.sunrise,Icon:f},{key:`sunset`,minutes:t.solar.sunset,Icon:h}];return(0,I.jsxs)(`div`,{className:`celestial-day-preview flex min-w-0 flex-col gap-3`,style:{"--celestial-day-gradient":y,"--celestial-preview-sky":`linear-gradient(${t.sky.top}, ${t.sky.mid} 65%, ${t.sky.horizon})`,"--celestial-preview-glow":t.glow},children:[(0,I.jsxs)(`div`,{className:`celestial-day-preview__header flex min-w-0 items-start justify-between gap-3`,children:[(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`h4`,{className:`text-sm font-medium text-ink`,children:e(`settings.appearance.celestial.title`)}),(0,I.jsxs)(`span`,{role:`status`,"data-testid":`celestial-preview-status`,className:`mt-1.5 inline-flex items-center gap-1.5 rounded-full border border-line bg-surface-subtle px-2 py-0.5 text-[11px] font-medium text-ink-muted`,children:[(0,I.jsx)(D,{className:`h-3 w-3`,"aria-hidden":`true`}),e(T?`settings.appearance.celestial.preview`:`settings.appearance.celestial.live`)]})]}),(0,I.jsx)(`span`,{dir:`ltr`,className:`shrink-0 text-xl font-medium tabular-nums tracking-tight text-ink`,"data-testid":`celestial-preview-clock`,children:w})]}),(0,I.jsx)(`p`,{className:`text-xs leading-5 text-ink-muted`,children:e(`settings.appearance.celestial.description`)}),(0,I.jsxs)(`div`,{className:`celestial-day-preview__scene`,"aria-hidden":`true`,dir:`ltr`,children:[(0,I.jsx)(`div`,{className:`celestial-day-preview__horizon`}),(0,I.jsx)(`div`,{className:`celestial-day-preview__orb`,"data-day":t.solar.isDay,style:{left:`clamp(22px, ${x/1439*100}%, calc(100% - 22px))`,bottom:`${20+Math.abs(t.solar.altitude)*45}%`},children:(0,I.jsx)(E,{className:`h-5 w-5`,strokeWidth:1.5})})]}),(0,I.jsxs)(`div`,{dir:`ltr`,children:[(0,I.jsx)(`input`,{type:`range`,min:0,max:1439,step:1,value:x,onChange:e=>v(Number(e.target.value)),"aria-label":e(`settings.appearance.celestial.title`),"aria-valuetext":w,"data-testid":`celestial-scrubber`,className:`celestial-day-preview__range w-full rounded-full outline-none focus-visible:ring-2 focus-visible:ring-primary-500/60 focus-visible:ring-offset-2 focus-visible:ring-offset-surface`,dir:`ltr`}),(0,I.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`celestial-time-anchors`,className:`flex justify-between gap-2 text-[11px] tabular-nums text-ink-muted`,children:[0,720,1439].map(e=>(0,I.jsx)(`span`,{children:_(e)},e))})]}),(0,I.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:O.map(({key:t,minutes:n,Icon:r})=>(0,I.jsxs)(`button`,{type:`button`,onClick:()=>v(B(n)),"data-testid":`celestial-preview-${t}`,className:`flex min-w-0 items-center gap-2 rounded-xl border border-line px-3 py-2 text-start text-ink hover:bg-interactive-hover outline-none focus-visible:ring-2 focus-visible:ring-primary-500/60`,children:[(0,I.jsx)(r,{className:`h-4 w-4 shrink-0`,"aria-hidden":`true`}),(0,I.jsxs)(`span`,{className:`min-w-0`,children:[(0,I.jsx)(`span`,{className:`block truncate text-[11px] text-ink-muted`,children:e(`settings.appearance.celestial.${t}`)}),(0,I.jsx)(`span`,{dir:`ltr`,className:`block text-xs tabular-nums`,children:_(n)})]})]},t))}),(0,I.jsxs)(`button`,{type:`button`,onClick:()=>v(null),disabled:!T,"data-testid":`celestial-follow-clock`,className:i(`flex items-center justify-center gap-2 rounded-xl border px-3 py-2 text-xs font-medium outline-none transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-primary-500/60 motion-reduce:transition-none`,T?`border-transparent bg-ink text-ink-inverse hover:opacity-90`:`border-line text-ink-muted disabled:cursor-default`),children:[T?(0,I.jsx)(u,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}):(0,I.jsx)(l,{className:`h-3.5 w-3.5`,"aria-hidden":`true`}),e(`settings.appearance.celestial.followClock`)]})]})},H=()=>typeof window<`u`&&window.PublicKeyCredential!==void 0&&typeof navigator.credentials?.create==`function`,U=e=>{let t=e.replace(/-/g,`+`).replace(/_/g,`/`),n=t+`=`.repeat((4-t.length%4)%4),r=atob(n),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i.buffer},W=e=>{let t=new Uint8Array(e),n=``;for(let e of t)n+=String.fromCharCode(e);return btoa(n).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)},G=async e=>{let t=e.user,n={...e,challenge:U(e.challenge),user:{...t,id:U(t.id)},excludeCredentials:(e.excludeCredentials??[]).map(e=>({type:`public-key`,id:U(e.id)}))},r=await navigator.credentials.create({publicKey:n});if(!r)throw Error(`Passkey creation was cancelled`);let i=r.response;return{rawId:W(r.rawId),response:{clientDataJSON:W(i.clientDataJSON),attestationObject:W(i.attestationObject),transports:typeof i.getTransports==`function`?i.getTransports():[]}}},K=async e=>{let t={...e,challenge:U(e.challenge)},n=await navigator.credentials.get({publicKey:t});if(!n)throw Error(`Passkey sign-in was cancelled`);let r=n.response;return{rawId:W(n.rawId),response:{clientDataJSON:W(r.clientDataJSON),authenticatorData:W(r.authenticatorData),signature:W(r.signature),userHandle:r.userHandle?W(r.userHandle):null}}},q=({compact:e=!1})=>{let{t,i18n:n}=r();return(0,I.jsxs)(`div`,{className:i(`flex items-center gap-4`,!e&&`py-4`),children:[(0,I.jsxs)(`div`,{className:i(`min-w-0 flex-1`,e&&`sr-only`),children:[(0,I.jsx)(`h4`,{className:`text-sm leading-[22px] text-ink`,children:t(`settings.appearance.language.title`)}),(0,I.jsx)(`p`,{className:`mt-0.5 text-xs text-ink-subtle`,children:t(`settings.appearance.language.description`)})]}),(0,I.jsxs)(`div`,{className:`relative shrink-0`,children:[(0,I.jsx)(`select`,{"data-testid":`language-switcher-select`,"aria-label":t(`settings.appearance.language.title`),value:s(n.language),onChange:e=>{let t=e.target.value;a(t)},className:i(e?`max-w-[140px]`:`max-w-[220px]`,`h-9 cursor-pointer appearance-none rounded-full bg-surface-subtle pe-9 ps-3.5 text-sm text-ink transition-colors hover:bg-hover-solid focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`),children:o.map(t=>(0,I.jsx)(`option`,{value:t.code,children:e?t.nativeName:`${t.nativeName} (${t.name})`},t.code))}),(0,I.jsx)(d,{className:`pointer-events-none absolute end-3 top-1/2 h-4 w-4 -translate-y-1/2 text-ink-muted`})]})]})};export{V as a,w as c,H as i,G as n,z as o,K as r,L as s,q as t};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{i as t,t as n}from"./react-vendor-D0Ec-185.js";import{t as r}from"./useQuery-BKulzCS7.js";import{t as i}from"./useTranslation-rdLmo6zV.js";import{t as a}from"./utils-CKWltgs8.js";import{Bn as o,Ft as s,In as c,Tn as l,Z as u,an as d,br as f,g as p,or as m,s as h,tt as g,v as _,vr as v}from"./ui-vendor-Dt9hfsGD.js";import{n as y}from"./workApi-C-WfyZSs.js";import{u as b}from"./api-CgnEj5Jc.js";import{t as x}from"./Button-BxwbQ5xw.js";import{a as S,o as C}from"./ui-CgokQU6I.js";var w=e(t(),1),T={getAnalytics:e=>y.get(`/costs/analytics`,{params:{days:e}}).then(e=>e.data),listTariffs:()=>y.get(`/costs/tariffs`).then(e=>e.data),createTariff:e=>y.post(`/costs/tariffs`,e).then(e=>e.data),deleteTariff:e=>y.delete(`/costs/tariffs/${encodeURIComponent(e)}`).then(()=>void 0),listBudgets:()=>y.get(`/costs/budgets`).then(e=>e.data),createBudget:e=>y.post(`/costs/budgets`,e).then(e=>e.data),deleteBudget:e=>y.delete(`/costs/budgets/${encodeURIComponent(e)}`).then(()=>void 0),exportUrl:e=>`/api/costs/export?days=${e}`,exportCsv:e=>y.get(`/costs/export`,{params:{days:e},responseType:`blob`}).then(e=>e.data)},E=n(),D=e=>new Intl.NumberFormat(void 0,{style:`currency`,currency:`USD`,maximumFractionDigits:e<1?4:2}).format(e),O=`w-full rounded-lg border border-gray-300 bg-white px-2 py-1.5 text-sm dark:border-dark-300 dark:bg-dark-50`,k=({days:e})=>{let{t}=i(),[n,r]=(0,w.useState)(null),[a,o]=(0,w.useState)([]),[c,u]=(0,w.useState)([]),[d,p]=(0,w.useState)(!0),[m,h]=(0,w.useState)(0),[v,y]=(0,w.useState)({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),[b,S]=(0,w.useState)({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`});(0,w.useEffect)(()=>{let n=!1;return Promise.all([T.getAnalytics(e),T.listTariffs(),T.listBudgets()]).then(([e,t,i])=>{n||(e.success&&e.data&&r(e.data),t.success&&t.data&&o(t.data),i.success&&i.data&&u(i.data))}).catch(()=>f.error(t(`costs.loadFailed`))).finally(()=>{n||p(!1)}),()=>{n=!0}},[e,m,t]);let C=e=>{if(!e.trim())return;let t=Number(e);return Number.isFinite(t)?t:void 0},k=async()=>{try{let e=await T.createTariff({pluginId:v.pluginId.trim(),model:v.model.trim()||void 0,inputPerMillion:C(v.inputPerMillion),outputPerMillion:C(v.outputPerMillion),unitPrice:C(v.unitPrice)});if(!e.success)throw Error(e.message);f.success(t(`costs.tariffSaved`)),y({pluginId:``,model:``,inputPerMillion:``,outputPerMillion:``,unitPrice:``}),h(e=>e+1)}catch(e){f.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},A=async()=>{try{let e=await T.createBudget({name:b.name.trim(),principalType:b.principalType,principalId:b.principalType===`instance`?void 0:b.principalId.trim(),period:b.period,amountUsd:Number(b.amountUsd),mode:b.mode});if(!e.success)throw Error(e.message);f.success(t(`costs.budgetSaved`)),S({name:``,principalType:`instance`,principalId:``,period:`monthly`,amountUsd:``,mode:`soft`}),h(e=>e+1)}catch(e){f.error(e instanceof Error?e.message:t(`costs.saveFailed`))}},j=async()=>{try{let t=await T.exportCsv(e),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`libre-webui-costs.csv`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}catch{f.error(t(`costs.exportFailed`))}};return d&&!n?(0,E.jsx)(`div`,{className:`flex justify-center rounded-lg border border-gray-200 bg-white p-6 dark:border-dark-300 dark:bg-dark-100`,children:(0,E.jsx)(s,{className:`h-5 w-5 animate-spin text-gray-400`})}):(0,E.jsxs)(`div`,{className:`space-y-4 rounded-lg border border-gray-200 bg-white p-4 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`cost-governance-panel`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h3`,{className:`text-sm font-semibold text-gray-900 dark:text-gray-100`,children:t(`costs.title`)}),(0,E.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:t(`costs.description`)})]}),(0,E.jsxs)(x,{size:`sm`,variant:`outline`,onClick:()=>void j(),children:[(0,E.jsx)(l,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.exportCsv`)]})]}),n&&(0,E.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-4`,children:[(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.totalSpend`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:D(n.totalUsd)})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.meteredEvents`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:n.meteredEvents})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.unmeteredEvents`)}),(0,E.jsx)(`p`,{className:`text-lg font-semibold`,children:n.unmeteredEvents})]}),(0,E.jsxs)(`div`,{className:`rounded-lg bg-gray-50 p-3 dark:bg-dark-50`,children:[(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.topModel`)}),(0,E.jsx)(`p`,{className:`truncate text-sm font-medium`,children:n.byModel[0]?`${n.byModel[0].model} (${D(n.byModel[0].usd)})`:`—`})]})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.budgets`)}),(0,E.jsxs)(`div`,{className:`space-y-2`,children:[n?.budgets.map(e=>{let n=Math.min(1,e.spentUsd/e.amountUsd);return(0,E.jsxs)(`div`,{className:`rounded-lg border border-gray-200 p-2 dark:border-dark-300`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-sm`,children:[(0,E.jsxs)(`span`,{className:`min-w-0 truncate font-medium`,children:[e.name,(0,E.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-gray-500`,children:[t(`costs.mode.${e.mode}`),` ·`,` `,t(`costs.period.${e.period}`),` ·`,` `,e.principalType===`instance`?t(`costs.scope.instance`):`${t(`costs.scope.${e.principalType}`)}: ${e.principalId}`]})]}),(0,E.jsxs)(`span`,{className:`shrink-0 text-xs text-gray-600 dark:text-gray-300`,children:[D(e.spentUsd),` / `,D(e.amountUsd)]}),(0,E.jsx)(`button`,{onClick:()=>{T.deleteBudget(e.id).then(()=>h(e=>e+1)).catch(()=>f.error(t(`costs.saveFailed`)))},className:`shrink-0 rounded p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteBudget`),children:(0,E.jsx)(_,{className:`h-3.5 w-3.5`})})]}),(0,E.jsx)(`div`,{className:`mt-1 h-1.5 overflow-hidden rounded bg-gray-200 dark:bg-dark-300`,children:(0,E.jsx)(`div`,{className:n>=1?`h-full bg-red-500`:n>=.8?`h-full bg-amber-500`:`h-full bg-emerald-500`,style:{width:`${Math.round(n*100)}%`}})})]},e.id)}),c.length===0&&(0,E.jsx)(`p`,{className:`text-xs text-gray-500`,children:t(`costs.noBudgets`)})]}),(0,E.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.budgetName`),value:b.name,onChange:e=>S({...b,name:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.principalType,onChange:e=>S({...b,principalType:e.target.value}),children:[(0,E.jsx)(`option`,{value:`instance`,children:t(`costs.scope.instance`)}),(0,E.jsx)(`option`,{value:`user`,children:t(`costs.scope.user`)}),(0,E.jsx)(`option`,{value:`group`,children:t(`costs.scope.group`)})]}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.principalId`),value:b.principalId,disabled:b.principalType===`instance`,onChange:e=>S({...b,principalId:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.period,onChange:e=>S({...b,period:e.target.value}),children:[(0,E.jsx)(`option`,{value:`daily`,children:t(`costs.period.daily`)}),(0,E.jsx)(`option`,{value:`weekly`,children:t(`costs.period.weekly`)}),(0,E.jsx)(`option`,{value:`monthly`,children:t(`costs.period.monthly`)})]}),(0,E.jsxs)(`div`,{className:`flex gap-2`,children:[(0,E.jsx)(`input`,{className:O,placeholder:`USD`,inputMode:`decimal`,value:b.amountUsd,onChange:e=>S({...b,amountUsd:e.target.value})}),(0,E.jsxs)(`select`,{className:O,value:b.mode,onChange:e=>S({...b,mode:e.target.value}),children:[(0,E.jsx)(`option`,{value:`observe`,children:t(`costs.mode.observe`)}),(0,E.jsx)(`option`,{value:`soft`,children:t(`costs.mode.soft`)}),(0,E.jsx)(`option`,{value:`hard`,children:t(`costs.mode.hard`)})]})]}),(0,E.jsxs)(x,{size:`sm`,onClick:()=>void A(),children:[(0,E.jsx)(g,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addBudget`)]})]})]}),(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-gray-500`,children:t(`costs.tariffs`)}),(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`table`,{className:`w-full text-left text-xs`,children:[(0,E.jsx)(`thead`,{className:`text-gray-500`,children:(0,E.jsxs)(`tr`,{children:[(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.plugin`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.model`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.inputPerMillion`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.outputPerMillion`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.unitPrice`)}),(0,E.jsx)(`th`,{className:`py-1 pr-2`,children:t(`costs.effectiveFrom`)}),(0,E.jsx)(`th`,{})]})}),(0,E.jsxs)(`tbody`,{children:[a.map(e=>(0,E.jsxs)(`tr`,{className:`border-t border-gray-100 dark:border-dark-300`,children:[(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.plugin_id}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.model??t(`costs.allModels`)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.input_per_million===null?`—`:D(e.input_per_million)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.output_per_million===null?`—`:D(e.output_per_million)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:e.unit_price===null?`—`:D(e.unit_price)}),(0,E.jsx)(`td`,{className:`py-1 pr-2`,children:new Intl.DateTimeFormat(void 0,{dateStyle:`medium`}).format(e.effective_from)}),(0,E.jsx)(`td`,{className:`py-1`,children:(0,E.jsx)(`button`,{onClick:()=>{T.deleteTariff(e.id).then(()=>h(e=>e+1)).catch(()=>f.error(t(`costs.saveFailed`)))},className:`rounded p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-950/30`,"aria-label":t(`costs.deleteTariff`),children:(0,E.jsx)(_,{className:`h-3.5 w-3.5`})})})]},e.id)),a.length===0&&(0,E.jsx)(`tr`,{children:(0,E.jsx)(`td`,{colSpan:7,className:`py-2 text-gray-500`,children:t(`costs.noTariffs`)})})]})]})}),(0,E.jsxs)(`div`,{className:`mt-2 grid grid-cols-2 gap-2 sm:grid-cols-6`,children:[(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.plugin`),value:v.pluginId,onChange:e=>y({...v,pluginId:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.modelOptional`),value:v.model,onChange:e=>y({...v,model:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.inputPerMillion`),inputMode:`decimal`,value:v.inputPerMillion,onChange:e=>y({...v,inputPerMillion:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.outputPerMillion`),inputMode:`decimal`,value:v.outputPerMillion,onChange:e=>y({...v,outputPerMillion:e.target.value})}),(0,E.jsx)(`input`,{className:O,placeholder:t(`costs.unitPrice`),inputMode:`decimal`,value:v.unitPrice,onChange:e=>y({...v,unitPrice:e.target.value})}),(0,E.jsxs)(x,{size:`sm`,onClick:()=>void k(),children:[(0,E.jsx)(g,{className:`mr-1 h-3.5 w-3.5`}),t(`costs.addTariff`)]})]})]})]})},A=new Intl.NumberFormat(void 0,{maximumFractionDigits:0}),j=new Intl.NumberFormat(void 0,{notation:`compact`,maximumFractionDigits:1}),M=e=>e>=1e4?j.format(e):A.format(e),N=e=>e?e<1e3?`${A.format(e)} ms`:`${(e/1e3).toFixed(+(e<1e4))} s`:`—`,P=(e,t)=>e===0?0:(e-t)/e*100,F=({analytics:e,metric:t,onMetricChange:n})=>{let{t:r}=i(),o={top:22,right:18,bottom:42,left:52},s=e.series.map(e=>e[t]),c=Math.max(1,...s),l=960-o.left-o.right,u=280-o.top-o.bottom,d=t=>o.left+(e.series.length<=1?l/2:t/(e.series.length-1)*l),f=e=>o.top+u-e/c*u,p=e.series.map((e,n)=>({x:d(n),y:f(e[t]),point:e})),m=p.map(({x:e,y:t},n)=>`${n===0?`M`:`L`} ${e} ${t}`).join(` `),h=p.length?`${m} L ${p[p.length-1].x} ${o.top+u} L ${p[0].x} ${o.top+u} Z`:``,g=new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,timeZone:`UTC`}),_=Array.from(new Set([0,Math.floor((e.series.length-1)/2),e.series.length-1])).filter(e=>e>=0);return(0,E.jsxs)(`div`,{"data-testid":`plugin-usage-chart`,className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`flex flex-col gap-3 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:r(`usageAnalytics.activity.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:r(t===`calls`?`usageAnalytics.activity.callsDescription`:`usageAnalytics.activity.tokensDescription`)})]}),(0,E.jsx)(`div`,{className:`inline-flex w-fit rounded-xl bg-gray-100 p-1 dark:bg-dark-200/80`,children:[`calls`,`tokens`].map(e=>(0,E.jsx)(`button`,{type:`button`,"aria-pressed":t===e,className:a(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,t===e?`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`),onClick:()=>n(e),children:r(`usageAnalytics.metrics.${e}`)},e))})]}),(0,E.jsx)(`div`,{className:`px-2 pb-3 pt-4 sm:px-5 sm:pt-6`,children:(0,E.jsxs)(`svg`,{viewBox:`0 0 960 280`,className:`h-auto w-full overflow-visible`,role:`img`,"aria-label":r(`usageAnalytics.activity.chartLabel`,{metric:r(`usageAnalytics.metrics.${t}`)}),children:[(0,E.jsx)(`defs`,{children:(0,E.jsxs)(`linearGradient`,{id:`plugin-usage-area`,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,E.jsx)(`stop`,{offset:`0%`,stopColor:`rgb(var(--color-primary-500))`,stopOpacity:`0.28`}),(0,E.jsx)(`stop`,{offset:`100%`,stopColor:`rgb(var(--color-primary-500))`,stopOpacity:`0.015`})]})}),[0,.25,.5,.75,1].map(e=>{let t=o.top+u*e,n=Math.round(c*(1-e));return(0,E.jsxs)(`g`,{children:[(0,E.jsx)(`line`,{x1:o.left,x2:960-o.right,y1:t,y2:t,className:`stroke-gray-200 dark:stroke-white/[0.07]`,strokeDasharray:e===1?void 0:`4 8`}),(0,E.jsx)(`text`,{x:o.left-12,y:t+4,textAnchor:`end`,className:`fill-gray-400 text-[11px] dark:fill-dark-500`,children:M(n)})]},e)}),h&&(0,E.jsx)(`path`,{d:h,fill:`url(#plugin-usage-area)`}),m&&(0,E.jsx)(`path`,{d:m,fill:`none`,className:`stroke-primary-500 dark:stroke-primary-400`,strokeWidth:`3`,strokeLinecap:`round`,strokeLinejoin:`round`}),(e.series.length<=31?p:[]).map(({x:e,y:n,point:i})=>(0,E.jsx)(`circle`,{cx:e,cy:n,r:`4`,className:`fill-white stroke-primary-500 dark:fill-dark-100 dark:stroke-primary-400`,strokeWidth:`2.5`,children:(0,E.jsx)(`title`,{children:`${g.format(i.timestamp)}: ${M(i[t])} ${r(`usageAnalytics.metrics.${t}`).toLocaleLowerCase()}`})},i.timestamp)),_.map(t=>{let n=e.series[t];if(!n)return null;let r=t===0?`start`:t===e.series.length-1?`end`:`middle`;return(0,E.jsx)(`text`,{x:d(t),y:270,textAnchor:r,className:`fill-gray-500 text-[12px] dark:fill-dark-500`,children:g.format(n.timestamp)},n.timestamp)})]})})]})},I=864e5,L=10,R=12,z=30,B=16,V=[`fill-blue-500`,`fill-emerald-500 dark:fill-emerald-600`,`fill-amber-500 dark:fill-amber-600`,`fill-violet-500`,`fill-rose-500`],H=[`bg-blue-500`,`bg-emerald-500 dark:bg-emerald-600`,`bg-amber-500 dark:bg-amber-600`,`bg-violet-500`,`bg-rose-500`],U=`fill-gray-400 dark:fill-gray-500`,W=`bg-gray-400 dark:bg-gray-500`,G=`fill-gray-950/[0.06] dark:fill-white/[0.07]`,K=[0,.35,.55,.75,1],q=({heatmap:e})=>{let{t,i18n:n}=i(),[r,o]=(0,w.useState)(null),{weeks:s,firstColStart:c,cellsByDay:l,maxCalls:u,modelRank:d,totalCalls:f}=(0,w.useMemo)(()=>{let t=new Map(e.cells.map(e=>[e.timestamp,e])),n=e.from,r=e.from+(e.days-1)*I,i=n-new Date(n).getUTCDay()*I;return{weeks:Math.ceil((r-i+I)/(7*I)),firstColStart:i,cellsByDay:t,maxCalls:Math.max(1,...e.cells.map(e=>e.calls)),modelRank:new Map(e.models.map((e,t)=>[e,t])),totalCalls:e.cells.reduce((e,t)=>e+t.calls,0)}},[e]),p=new Intl.DateTimeFormat(n.language,{month:`short`,timeZone:`UTC`}),m=new Intl.DateTimeFormat(n.language,{weekday:`short`,timeZone:`UTC`}),h=new Intl.DateTimeFormat(n.language,{dateStyle:`medium`,timeZone:`UTC`}),g=e.from,_=e.from+(e.days-1)*I,v=z+s*R,y=[],b=-1;for(let e=0;e<s;e++){let t=c+e*7*I,n=Math.max(t,g),r=new Date(n).getUTCMonth();r!==b&&t>=g-6*I&&((b!==-1||t>=g)&&y.push({x:z+e*R,label:p.format(n)}),b=r)}let x=e=>e<=0?0:Math.min(4,Math.max(1,Math.ceil(e/u*4))),S=e=>{let t=e.models[0]?.model,n=t===void 0?void 0:d.get(t);return n===void 0?U:V[n]},C=(e,t,n)=>{let r=e.currentTarget.closest(`[data-heatmap-wrapper]`);if(!r)return;let i=r.getBoundingClientRect(),a=e.currentTarget.getBoundingClientRect(),s=a.left-i.left+a.width/2;o({x:Math.min(Math.max(s,96),Math.max(i.width-96,96)),y:a.top-i.top,timestamp:t,calls:n.calls,models:n.models})};return(0,E.jsxs)(`section`,{"data-testid":`usage-heatmap`,className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`flex flex-col gap-1 border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:flex-row sm:items-center sm:justify-between sm:px-5`,children:[(0,E.jsxs)(`div`,{children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:t(`usageAnalytics.heatmap.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.heatmap.description`)})]}),(0,E.jsx)(`span`,{className:`shrink-0 text-xs tabular-nums text-gray-500 dark:text-dark-500`,children:t(`usageAnalytics.heatmap.yearTotal`,{count:f,formatted:M(f)})})]}),(0,E.jsxs)(`div`,{className:`relative p-4 sm:px-5`,"data-heatmap-wrapper":!0,children:[(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`svg`,{viewBox:`0 0 ${v} 100`,className:`h-auto w-full min-w-[640px]`,role:`img`,"aria-label":t(`usageAnalytics.heatmap.title`),onMouseLeave:()=>o(null),children:[y.map(({x:e,label:t})=>(0,E.jsx)(`text`,{x:e,y:10,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:t},`${e}-${t}`)),[1,3,5].map(e=>(0,E.jsx)(`text`,{x:0,y:B+e*R+L-2,className:`fill-gray-400 text-[8px] dark:fill-dark-500`,children:m.format(new Date(Date.UTC(2023,0,1+e)))},e)),Array.from({length:s},(e,t)=>Array.from({length:7},(e,n)=>{let i=c+(t*7+n)*I;if(i<g||i>_)return null;let o=l.get(i),s=o?.calls??0,u=x(s);return(0,E.jsx)(`rect`,{x:z+t*R,y:B+n*R,width:L,height:L,rx:2,fillOpacity:u===0?1:K[u],strokeWidth:+(r?.timestamp===i),className:a(`transition-opacity`,u===0||!o?G:S(o),r?.timestamp===i?`stroke-gray-500 dark:stroke-white/60`:`stroke-transparent`),onMouseEnter:e=>C(e,i,{calls:s,models:o?.models??[]}),children:(0,E.jsx)(`title`,{children:`${h.format(i)} — ${M(s)}`})},i)}))]})}),r&&(0,E.jsxs)(`div`,{className:`pointer-events-none absolute z-10 min-w-[10rem] -translate-x-1/2 -translate-y-full rounded-lg border border-gray-200/80 bg-white/95 px-3 py-2 shadow-card backdrop-blur-md dark:border-white/[0.1] dark:bg-dark-100/95`,style:{left:r.x,top:r.y-6},children:[(0,E.jsx)(`div`,{className:`text-[11px] font-medium text-gray-900 dark:text-dark-900`,children:h.format(r.timestamp)}),(0,E.jsx)(`div`,{className:`mt-0.5 text-[11px] text-gray-500 dark:text-dark-500`,children:r.calls===0?t(`usageAnalytics.heatmap.noCalls`):`${M(r.calls)} ${t(`usageAnalytics.heatmap.calls`)}`}),r.models.slice(0,3).map(e=>(0,E.jsxs)(`div`,{className:`mt-1 flex items-center justify-between gap-3 text-[11px]`,children:[(0,E.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,E.jsx)(`span`,{className:a(`h-2 w-2 shrink-0 rounded-[3px]`,d.has(e.model)?H[d.get(e.model)]:W)}),(0,E.jsx)(`span`,{className:`truncate font-mono text-gray-700 dark:text-dark-700`,dir:`ltr`,children:e.model})]}),(0,E.jsx)(`span`,{className:`tabular-nums text-gray-500 dark:text-dark-500`,children:M(e.calls)})]},e.model))]}),(0,E.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center justify-between gap-3`,children:[(0,E.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1.5`,children:[e.models.map((e,t)=>(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,E.jsx)(`span`,{className:a(`h-2.5 w-2.5 rounded-[3px]`,H[t])}),(0,E.jsx)(`span`,{className:`font-mono`,dir:`ltr`,children:e})]},e)),(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] text-gray-600 dark:text-dark-600`,children:[(0,E.jsx)(`span`,{className:a(`h-2.5 w-2.5 rounded-[3px]`,W)}),t(`usageAnalytics.heatmap.other`)]})]}),(0,E.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] text-gray-500 dark:text-dark-500`,children:[t(`usageAnalytics.heatmap.less`),(0,E.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-gray-950/[0.06] dark:bg-white/[0.07]`}),K.slice(1).map(e=>(0,E.jsx)(`span`,{className:`h-2.5 w-2.5 rounded-[3px] bg-primary-500`,style:{opacity:e}},e)),t(`usageAnalytics.heatmap.more`)]})]})]})]})},J=()=>{let{t:e}=i(),[t,n]=(0,w.useState)(30),[l,f]=(0,w.useState)(`calls`),{data:g,error:_,isLoading:y,isFetching:T,refetch:D}=r({queryKey:[`plugin-usage`,t],queryFn:async()=>{let n=await b.getUsage(t);if(!n.success||!n.data)throw Error(n.error||e(`usageAnalytics.loadFailed`));return n.data}}),O=_?_ instanceof Error?_.message:e(`usageAnalytics.loadFailed`):null,A=g?.totals,j=(0,w.useMemo)(()=>[{label:e(`usageAnalytics.cards.calls`),value:M(A?.calls??0),detail:e(`usageAnalytics.cards.callsDetail`,{count:A?.uniqueUsers??0}),icon:v},{label:e(`usageAnalytics.cards.tokens`),value:M(A?.reportedTokens??0),detail:e(`usageAnalytics.cards.tokensDetail`,{count:A?.meteredCalls??0}),icon:d},{label:e(`usageAnalytics.cards.success`),value:`${P(A?.calls??0,(A?.failedCalls??0)+(A?.cancelledCalls??0)).toFixed(1)}%`,detail:e(`usageAnalytics.cards.successDetail`,{count:A?.failedCalls??0}),icon:o},{label:e(`usageAnalytics.cards.latency`),value:N(A?.averageLatencyMs??0),detail:e(`usageAnalytics.cards.latencyDetail`),icon:c}],[e,A]);return y&&!g?(0,E.jsx)(C,{width:`wide`,children:(0,E.jsx)(`div`,{className:`flex min-h-[50vh] items-center justify-center`,children:(0,E.jsx)(s,{className:`h-7 w-7 animate-spin text-primary-500`})})}):(0,E.jsxs)(C,{width:`wide`,children:[(0,E.jsx)(S,{eyebrow:e(`usageAnalytics.eyebrow`),title:e(`usageAnalytics.title`),description:e(`usageAnalytics.description`),actions:(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(`div`,{className:`inline-flex rounded-xl border border-gray-200 bg-white/70 p-1 dark:border-white/[0.08] dark:bg-dark-100/70`,children:[7,30,90].map(r=>(0,E.jsx)(`button`,{type:`button`,className:a(`rounded-lg px-3 py-1.5 text-xs font-medium transition-colors`,t===r?`bg-gray-950 text-white dark:bg-white dark:text-gray-950`:`text-gray-500 hover:text-gray-900 dark:text-dark-500 dark:hover:text-dark-900`),onClick:()=>n(r),children:e(`usageAnalytics.days`,{count:r})},r))}),(0,E.jsxs)(x,{variant:`outline`,size:`sm`,onClick:()=>void D(),disabled:T,children:[(0,E.jsx)(u,{className:a(`h-4 w-4`,T&&`animate-spin`)}),(0,E.jsx)(`span`,{className:`sr-only`,children:e(`usageAnalytics.refresh`)})]})]})}),O&&(0,E.jsxs)(`div`,{className:`mb-6 flex items-center gap-3 rounded-2xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700 dark:border-red-900/40 dark:bg-red-950/30 dark:text-red-300`,children:[(0,E.jsx)(p,{className:`h-4 w-4 shrink-0`}),(0,E.jsx)(`span`,{children:O})]}),(0,E.jsx)(`div`,{className:`mb-6`,children:(0,E.jsx)(k,{days:t})}),g&&(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-4`,children:j.map(e=>{let t=e.icon;return(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/75 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/70`,children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,E.jsx)(`span`,{className:`text-xs font-medium uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:e.label}),(0,E.jsx)(t,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`})]}),(0,E.jsx)(`div`,{className:`mt-2 text-2xl font-normal tracking-[-0.04em] text-gray-950 dark:text-dark-950`,children:e.value}),(0,E.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:e.detail})]},e.label)})}),g.heatmap&&g.heatmap.cells.length>0&&(0,E.jsx)(q,{heatmap:g.heatmap}),(0,E.jsx)(F,{analytics:g,metric:l,onMetricChange:f}),g.totals.calls===0?(0,E.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-gray-300 px-6 py-10 text-center dark:border-white/[0.12]`,children:[(0,E.jsx)(m,{className:`mx-auto h-8 w-8 text-gray-400 dark:text-dark-500`}),(0,E.jsx)(`h2`,{className:`mt-4 text-base font-medium text-gray-900 dark:text-dark-900`,children:e(`usageAnalytics.empty.title`)}),(0,E.jsx)(`p`,{className:`mx-auto mt-2 max-w-md text-sm leading-6 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.empty.description`)})]}):(0,E.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-[1.15fr_0.85fr]`,children:[(0,E.jsxs)(`section`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/80 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75`,children:[(0,E.jsxs)(`div`,{className:`border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.07] sm:px-5`,children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.models.title`)}),(0,E.jsx)(`p`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.models.description`)})]}),(0,E.jsx)(`div`,{className:`overflow-x-auto`,children:(0,E.jsxs)(`table`,{className:`w-full min-w-[620px] text-start text-sm`,children:[(0,E.jsx)(`thead`,{className:`text-[11px] uppercase tracking-[0.1em] text-gray-400 dark:text-dark-500`,children:(0,E.jsxs)(`tr`,{children:[(0,E.jsx)(`th`,{className:`px-5 py-2 text-start font-medium`,children:e(`usageAnalytics.models.model`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.calls`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.metrics.tokens`)}),(0,E.jsx)(`th`,{className:`px-4 py-2 text-end font-medium`,children:e(`usageAnalytics.models.success`)}),(0,E.jsx)(`th`,{className:`px-5 py-2 text-end font-medium`,children:e(`usageAnalytics.models.latency`)})]})}),(0,E.jsx)(`tbody`,{className:`divide-y divide-gray-100 dark:divide-white/[0.06]`,children:g.models.slice(0,12).map(e=>(0,E.jsxs)(`tr`,{children:[(0,E.jsxs)(`td`,{className:`px-5 py-2.5`,children:[(0,E.jsx)(`div`,{className:`max-w-[260px] truncate font-medium text-gray-900 dark:text-dark-900`,title:e.model,children:e.model}),(0,E.jsx)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:e.pluginName})]}),(0,E.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:M(e.calls)}),(0,E.jsx)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:e.tokens?M(e.tokens):`—`}),(0,E.jsxs)(`td`,{className:`px-4 py-2.5 text-end tabular-nums text-gray-700 dark:text-dark-700`,children:[P(e.calls,e.errors).toFixed(1),`%`]}),(0,E.jsx)(`td`,{className:`px-5 py-2.5 text-end tabular-nums text-gray-500 dark:text-dark-500`,children:N(e.averageLatencyMs)})]},`${e.pluginId}:${e.model}`))})]})})]}),(0,E.jsxs)(`div`,{className:`space-y-4`,children:[(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75 sm:p-5`,children:[(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.providers.title`)}),(0,E.jsx)(`div`,{className:`mt-5 space-y-4`,children:g.plugins.slice(0,8).map(t=>{let n=g.totals.calls?t.calls/g.totals.calls*100:0;return(0,E.jsxs)(`div`,{children:[(0,E.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-sm`,children:[(0,E.jsxs)(`div`,{className:`min-w-0`,children:[(0,E.jsx)(`div`,{className:`truncate font-medium text-gray-900 dark:text-dark-900`,children:t.pluginName}),(0,E.jsxs)(`div`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:[M(t.tokens),` `,e(`usageAnalytics.metrics.tokens`).toLocaleLowerCase()]})]}),(0,E.jsx)(`span`,{className:`shrink-0 tabular-nums text-gray-600 dark:text-dark-600`,children:M(t.calls)})]}),(0,E.jsx)(`div`,{className:`mt-2 h-1.5 overflow-hidden rounded-full bg-gray-100 dark:bg-dark-300`,children:(0,E.jsx)(`div`,{className:`h-full rounded-full bg-primary-500 dark:bg-primary-400`,style:{width:`${Math.max(2,n)}%`}})})]},t.pluginId)})})]}),(0,E.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/80 p-4 shadow-subtle backdrop-blur-md dark:border-white/[0.08] dark:bg-dark-100/75 sm:p-5`,children:[(0,E.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,E.jsx)(h,{className:`h-4 w-4 text-primary-500 dark:text-primary-400`}),(0,E.jsx)(`h2`,{className:`text-sm font-medium text-gray-950 dark:text-dark-950`,children:e(`usageAnalytics.capabilities.title`)})]}),(0,E.jsx)(`div`,{className:`mt-5 grid grid-cols-2 gap-3`,children:g.capabilities.map(t=>(0,E.jsxs)(`div`,{className:`rounded-xl bg-gray-50 px-3 py-2.5 dark:bg-dark-200/70`,children:[(0,E.jsx)(`div`,{className:`text-xs font-medium capitalize text-gray-500 dark:text-dark-500`,children:t.capability}),(0,E.jsx)(`div`,{className:`mt-1 text-xl text-gray-950 dark:text-dark-950`,children:M(t.calls)}),(0,E.jsx)(`div`,{className:`mt-1 text-[11px] text-gray-500 dark:text-dark-500`,children:t.capability===`tts`?e(`usageAnalytics.capabilities.characters`,{count:M(t.inputUnits)}):t.capability===`stt`?e(`usageAnalytics.capabilities.bytes`,{count:M(t.inputUnits)}):t.capability===`image`?e(`usageAnalytics.capabilities.images`,{count:M(t.outputUnits)}):t.capability===`video`?e(`usageAnalytics.capabilities.jobs`,{count:M(t.calls)}):t.capability===`embedding`?e(`usageAnalytics.capabilities.inputs`,{count:M(t.inputUnits)}):e(`usageAnalytics.capabilities.reportedTokens`,{count:M(t.tokens)})})]},t.capability))})]})]})]}),(0,E.jsx)(`p`,{className:`px-1 text-xs leading-5 text-gray-500 dark:text-dark-500`,children:e(`usageAnalytics.privacyNote`)})]})]})};export{J as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{t as e}from"./RichMessageContent-CcKn_kcQ.js";export{e as RichMessageContent,e as default};
|