libre-webui 0.16.0 → 0.16.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/README.md +18 -8
  2. package/backend/dist/routes/plugins.d.ts.map +1 -1
  3. package/backend/dist/routes/plugins.js +10 -3
  4. package/backend/dist/routes/plugins.js.map +1 -1
  5. package/backend/dist/routes/work.d.ts.map +1 -1
  6. package/backend/dist/routes/work.js +2 -1
  7. package/backend/dist/routes/work.js.map +1 -1
  8. package/backend/dist/services/pluginService.d.ts +42 -1
  9. package/backend/dist/services/pluginService.d.ts.map +1 -1
  10. package/backend/dist/services/pluginService.js +143 -12
  11. package/backend/dist/services/pluginService.js.map +1 -1
  12. package/backend/dist/services/workRuntimeService.d.ts +18 -1
  13. package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
  14. package/backend/dist/services/workRuntimeService.js +62 -11
  15. package/backend/dist/services/workRuntimeService.js.map +1 -1
  16. package/backend/package.json +1 -1
  17. package/frontend/dist/assets/{index-CKV9Lnj8.js → index-BVgyQN3z.js} +4 -4
  18. package/frontend/dist/index.html +2 -2
  19. package/frontend/dist/js/{ArtifactContainer-B0uVR8Z9.js → ArtifactContainer-CbMAYwvr.js} +1 -1
  20. package/frontend/dist/js/{ArtifactDemoPage-DBVPHFxk.js → ArtifactDemoPage-CWDhGWrz.js} +1 -1
  21. package/frontend/dist/js/ArtifactSlideOutPanel-CzUpDM59.js +1 -0
  22. package/frontend/dist/js/{ChatPage-CPHlIZqU.js → ChatPage-D0fdzy7a.js} +4 -4
  23. package/frontend/dist/js/{FirstTimeSetup-DksL5arK.js → FirstTimeSetup-CfnOmy9w.js} +1 -1
  24. package/frontend/dist/js/{GalleryPage-1mdUGo_N.js → GalleryPage-CMkCur9v.js} +1 -1
  25. package/frontend/dist/js/{LibreClawPage-qGr1Jy8p.js → LibreClawPage-CHEfny1k.js} +1 -1
  26. package/frontend/dist/js/{ModelSelector-CUnwRmNU.js → ModelSelector-COnlNsVM.js} +1 -1
  27. package/frontend/dist/js/{ModelsPage-DMYVg3LT.js → ModelsPage-nxheiYJp.js} +1 -1
  28. package/frontend/dist/js/{PersonasPage-Ct-KKW-j.js → PersonasPage-C2pqDsWA.js} +1 -1
  29. package/frontend/dist/js/{RichMessageContent-CGBAcUES.js → RichMessageContent-Cz9y-bgl.js} +1 -1
  30. package/frontend/dist/js/SettingsModal-B6Se68Hd.js +1 -0
  31. package/frontend/dist/js/{UserManagementPage-D3tLGtTu.js → UserManagementPage-DQeL-Twp.js} +1 -1
  32. package/frontend/dist/js/WorkPage-AcZMp8OB.js +2 -0
  33. package/frontend/dist/js/{api-YWoSobKv.js → api-Fi-lJlfu.js} +3 -3
  34. package/frontend/dist/js/{estree-PDLT672k.js → estree-BRklD62a.js} +1 -1
  35. package/frontend/dist/js/{html-CkhF9wDQ.js → html-BgGIAGmn.js} +1 -1
  36. package/frontend/dist/js/{markdown-B1iNUbse.js → markdown-CM2nBJJi.js} +1 -1
  37. package/frontend/dist/js/{standalone-CCd6rkf-.js → standalone-CUBo-NGt.js} +1 -1
  38. package/frontend/dist/js/{typescript-DKJ1uM5L.js → typescript-Dcy9qxSB.js} +1 -1
  39. package/frontend/dist/js/{useBaseQuery-MuQj7vA5.js → useBaseQuery-CFTidwqz.js} +1 -1
  40. package/frontend/dist/js/useQuery-UsSBfWzs.js +1 -0
  41. package/package.json +2 -2
  42. package/frontend/dist/js/ArtifactSlideOutPanel-Cg5kAwv9.js +0 -1
  43. package/frontend/dist/js/SettingsModal-BVj3gFCS.js +0 -1
  44. package/frontend/dist/js/WorkPage-DhTjy-kf.js +0 -2
  45. package/frontend/dist/js/useQuery-CYGPkxWR.js +0 -1
@@ -10,7 +10,7 @@
10
10
  name="description"
11
11
  content="A modern, minimalist WebUI for interacting with local LLMs through Ollama API"
12
12
  />
13
- <script type="module" crossorigin src="/assets/index-CKV9Lnj8.js"></script>
13
+ <script type="module" crossorigin src="/assets/index-BVgyQN3z.js"></script>
14
14
  <link rel="modulepreload" crossorigin href="/js/rolldown-runtime-QTnfLwEv.js">
15
15
  <link rel="modulepreload" crossorigin href="/js/markdown-core-GI9BPwrB.js">
16
16
  <link rel="modulepreload" crossorigin href="/js/react-vendor-DyG_ODzn.js">
@@ -20,7 +20,7 @@
20
20
  <link rel="modulepreload" crossorigin href="/js/utils-vendor-Cbaj0BC5.js">
21
21
  <link rel="modulepreload" crossorigin href="/js/demoMode-BhEpMVh5.js">
22
22
  <link rel="modulepreload" crossorigin href="/js/logger-DbNs3-DK.js">
23
- <link rel="modulepreload" crossorigin href="/js/api-YWoSobKv.js">
23
+ <link rel="modulepreload" crossorigin href="/js/api-Fi-lJlfu.js">
24
24
  <link rel="modulepreload" crossorigin href="/js/utils-pTFqSV8c.js">
25
25
  <link rel="modulepreload" crossorigin href="/js/Button-DBk-AREB.js">
26
26
  <link rel="stylesheet" crossorigin href="/assets/index-Dme2Ozol.css">
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{t as r}from"./useTranslation-Cs6iTP4m.js";import{Ft as i,Kt as a,L as o,X as s,ct as c,it as l,lt as u,mt as d,pt as f,ut as p,xt as m}from"./ui-vendor-CAFEDSaO.js";import{t as h}from"./logger-DbNs3-DK.js";import{t as g}from"./utils-pTFqSV8c.js";import{t as _}from"./Button-DBk-AREB.js";import{F as v}from"../assets/index-CKV9Lnj8.js";import{t as y}from"./OptimizedSyntaxHighlighter-Ci9sRc78.js";import{n as b,r as x,t as S}from"./artifactHtml-B7Oy2e__.js";var C=e(n(),1),w=t(),T=h(`components:artifact-renderer`),E=({artifact:e,className:t})=>{let{t:n}=r(),[h,E]=(0,C.useState)(!1),[D,O]=(0,C.useState)(`preview`),k=(0,C.useRef)(null),{theme:A,openArtifactPanel:j}=v(),M=async e=>{try{await navigator.clipboard.writeText(e),E(!0),setTimeout(()=>E(!1),2e3)}catch(e){T.error(`Failed to copy:`,e)}},N=()=>{let t=e.type===`html`?x(e.content,e.title):e.content,n=new Blob([t],{type:P(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${F(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},P=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},F=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},I=()=>{switch(e.type){case`html`:return(0,w.jsx)(s,{className:`h-4 w-4`});case`react`:return(0,w.jsx)(d,{className:`h-4 w-4`});case`svg`:return(0,w.jsx)(l,{className:`h-4 w-4`});case`code`:return(0,w.jsx)(d,{className:`h-4 w-4`});default:return(0,w.jsx)(l,{className:`h-4 w-4`})}},L=()=>(0,w.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,w.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,w.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:n(`artifacts.previewUnavailable`)}),(0,w.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,w.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>O(`code`),className:`mt-4`,children:[(0,w.jsx)(a,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),R=()=>e.content.trim()?(0,w.jsx)(`iframe`,{ref:k,"data-testid":`artifact-html-preview`,srcDoc:x(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,sandbox:b,allow:S,allowFullScreen:!0,title:e.title}):L(),z=()=>{try{return(0,w.jsx)(`div`,{className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-hidden border border-gray-200 dark:border-dark-200`,dangerouslySetInnerHTML:{__html:e.content}})}catch{return(0,w.jsx)(`div`,{className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidSvg`)})]})})}},B=()=>(0,w.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,w.jsx)(y,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:A.mode===`dark`,className:`!m-0 !rounded-lg`,children:e.content})}),V=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,w.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,w.jsx)(y,{language:`json`,isDark:A.mode===`dark`,className:`!m-0 !rounded-lg`,children:n})})}catch{return(0,w.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidJson`)})]})})}},H=()=>{if(D===`code`)return B();switch(e.type){case`html`:return R();case`svg`:return z();case`json`:return V();default:return B()}},U=()=>e.type===`html`||e.type===`svg`||e.type===`react`;return(0,w.jsxs)(`div`,{className:g(`border border-gray-200 dark:border-dark-200 rounded-xl bg-white dark:bg-dark-25 shadow-lg transition-all duration-300 hover:shadow-xl`,`w-full max-w-full overflow-hidden animate-fade-in`,`max-h-[400px] flex flex-col`,t),children:[(0,w.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:I()}),(0,w.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[U()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(_,{variant:D===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,w.jsx)(c,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:D===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,w.jsx)(a,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:h?(0,w.jsx)(m,{className:`h-2.5 w-2.5 text-green-500`}):(0,w.jsx)(f,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,w.jsx)(p,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>j(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,w.jsx)(o,{className:`h-2.5 w-2.5`})})]})]}),(0,w.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0`,children:I()}),(0,w.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,w.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[U()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(_,{variant:D===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,w.jsx)(c,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,w.jsxs)(_,{variant:D===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,w.jsx)(a,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,w.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:h?(0,w.jsx)(m,{className:`h-4 w-4 text-green-500`}):(0,w.jsx)(f,{className:`h-4 w-4`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,w.jsx)(p,{className:`h-4 w-4`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>j(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,w.jsx)(o,{className:`h-4 w-4`})})]})]})]}),(0,w.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:H()})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:[(0,w.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]}),(e.type===`html`||e.type===`react`)&&(0,w.jsxs)(_,{variant:`ghost`,size:`sm`,onClick:()=>{let t=window.open(``,`_blank`);t&&(t.document.write(x(e.content,e.title)),t.document.close())},className:`text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,children:[(0,w.jsx)(u,{className:`h-3 w-3 mr-1`}),n(`artifacts.openInNewWindow`)]})]})]})},D=({artifacts:e,className:t})=>!e||e.length===0?null:(0,w.jsx)(`div`,{className:g(`space-y-3`,t),children:e.map(e=>(0,w.jsx)(E,{artifact:e},e.id))});export{D as t};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{t as r}from"./useTranslation-Cs6iTP4m.js";import{Ft as i,Kt as a,L as o,X as s,ct as c,it as l,lt as u,mt as d,pt as f,ut as p,xt as m}from"./ui-vendor-CAFEDSaO.js";import{t as h}from"./logger-DbNs3-DK.js";import{t as g}from"./utils-pTFqSV8c.js";import{t as _}from"./Button-DBk-AREB.js";import{F as v}from"../assets/index-BVgyQN3z.js";import{t as y}from"./OptimizedSyntaxHighlighter-Ci9sRc78.js";import{n as b,r as x,t as S}from"./artifactHtml-B7Oy2e__.js";var C=e(n(),1),w=t(),T=h(`components:artifact-renderer`),E=({artifact:e,className:t})=>{let{t:n}=r(),[h,E]=(0,C.useState)(!1),[D,O]=(0,C.useState)(`preview`),k=(0,C.useRef)(null),{theme:A,openArtifactPanel:j}=v(),M=async e=>{try{await navigator.clipboard.writeText(e),E(!0),setTimeout(()=>E(!1),2e3)}catch(e){T.error(`Failed to copy:`,e)}},N=()=>{let t=e.type===`html`?x(e.content,e.title):e.content,n=new Blob([t],{type:P(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${F(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},P=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},F=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},I=()=>{switch(e.type){case`html`:return(0,w.jsx)(s,{className:`h-4 w-4`});case`react`:return(0,w.jsx)(d,{className:`h-4 w-4`});case`svg`:return(0,w.jsx)(l,{className:`h-4 w-4`});case`code`:return(0,w.jsx)(d,{className:`h-4 w-4`});default:return(0,w.jsx)(l,{className:`h-4 w-4`})}},L=()=>(0,w.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,w.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,w.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:n(`artifacts.previewUnavailable`)}),(0,w.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,w.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>O(`code`),className:`mt-4`,children:[(0,w.jsx)(a,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),R=()=>e.content.trim()?(0,w.jsx)(`iframe`,{ref:k,"data-testid":`artifact-html-preview`,srcDoc:x(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,sandbox:b,allow:S,allowFullScreen:!0,title:e.title}):L(),z=()=>{try{return(0,w.jsx)(`div`,{className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-hidden border border-gray-200 dark:border-dark-200`,dangerouslySetInnerHTML:{__html:e.content}})}catch{return(0,w.jsx)(`div`,{className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidSvg`)})]})})}},B=()=>(0,w.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,w.jsx)(y,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:A.mode===`dark`,className:`!m-0 !rounded-lg`,children:e.content})}),V=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,w.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,w.jsx)(y,{language:`json`,isDark:A.mode===`dark`,className:`!m-0 !rounded-lg`,children:n})})}catch{return(0,w.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidJson`)})]})})}},H=()=>{if(D===`code`)return B();switch(e.type){case`html`:return R();case`svg`:return z();case`json`:return V();default:return B()}},U=()=>e.type===`html`||e.type===`svg`||e.type===`react`;return(0,w.jsxs)(`div`,{className:g(`border border-gray-200 dark:border-dark-200 rounded-xl bg-white dark:bg-dark-25 shadow-lg transition-all duration-300 hover:shadow-xl`,`w-full max-w-full overflow-hidden animate-fade-in`,`max-h-[400px] flex flex-col`,t),children:[(0,w.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:I()}),(0,w.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[U()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(_,{variant:D===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,w.jsx)(c,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:D===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,w.jsx)(a,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:h?(0,w.jsx)(m,{className:`h-2.5 w-2.5 text-green-500`}):(0,w.jsx)(f,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,w.jsx)(p,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>j(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,w.jsx)(o,{className:`h-2.5 w-2.5`})})]})]}),(0,w.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0`,children:I()}),(0,w.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,w.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[U()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(_,{variant:D===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,w.jsx)(c,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,w.jsxs)(_,{variant:D===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,w.jsx)(a,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,w.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:h?(0,w.jsx)(m,{className:`h-4 w-4 text-green-500`}):(0,w.jsx)(f,{className:`h-4 w-4`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,w.jsx)(p,{className:`h-4 w-4`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>j(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,w.jsx)(o,{className:`h-4 w-4`})})]})]})]}),(0,w.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:H()})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:[(0,w.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]}),(e.type===`html`||e.type===`react`)&&(0,w.jsxs)(_,{variant:`ghost`,size:`sm`,onClick:()=>{let t=window.open(``,`_blank`);t&&(t.document.write(x(e.content,e.title)),t.document.close())},className:`text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,children:[(0,w.jsx)(u,{className:`h-3 w-3 mr-1`}),n(`artifacts.openInNewWindow`)]})]})]})},D=({artifacts:e,className:t})=>!e||e.length===0?null:(0,w.jsx)(`div`,{className:g(`space-y-3`,t),children:e.map(e=>(0,w.jsx)(E,{artifact:e},e.id))});export{D as t};
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{t as r}from"./Button-DBk-AREB.js";import{o as i}from"../assets/index-CKV9Lnj8.js";import{t as a}from"./ArtifactContainer-B0uVR8Z9.js";var o=e(n(),1),s=t(),c=[{id:`demo-html-1`,type:`html`,title:`Interactive Button Demo`,description:`A simple HTML page with interactive elements`,content:`<div style="text-align: center; padding: 20px;">
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{t as r}from"./Button-DBk-AREB.js";import{o as i}from"../assets/index-BVgyQN3z.js";import{t as a}from"./ArtifactContainer-CbMAYwvr.js";var o=e(n(),1),s=t(),c=[{id:`demo-html-1`,type:`html`,title:`Interactive Button Demo`,description:`A simple HTML page with interactive elements`,content:`<div style="text-align: center; padding: 20px;">
2
2
  <h1 style="color: #333; font-family: Arial, sans-serif;">Welcome to Libre WebUI!</h1>
3
3
  <p style="color: #666; font-size: 16px;">This is an interactive HTML artifact.</p>
4
4
  <button
@@ -0,0 +1 @@
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{n as r}from"./react-vendor-DyG_ODzn.js";import{t as ee}from"./useTranslation-Cs6iTP4m.js";import{Ft as i,Kt as a,X as o,Y as s,ct as te,it as c,lt as l,mt as u,n as d,pt as f,ut as p,xt as m}from"./ui-vendor-CAFEDSaO.js";import{t as h}from"./logger-DbNs3-DK.js";import{t as g}from"./utils-pTFqSV8c.js";import{t as _}from"./Button-DBk-AREB.js";import{F as ne,nt as re}from"../assets/index-BVgyQN3z.js";import{t as v}from"./OptimizedSyntaxHighlighter-Ci9sRc78.js";import{n as y,r as b,t as x}from"./artifactHtml-B7Oy2e__.js";var S=e(n(),1),C=r(),w=t(),T=h(`components:artifact-slide-out-panel`),E=320,D=.9,O=600,k=()=>{let{t:e,i18n:t}=ee(),n=re(t.language),{artifactPanelOpen:r,artifactPanelArtifact:h,closeArtifactPanel:k,theme:A}=ne(),[ie,j]=(0,S.useState)(!1),[M,N]=(0,S.useState)(`preview`),[P,F]=(0,S.useState)(O),[I,L]=(0,S.useState)(!1),R=(0,S.useRef)(null),z=(0,S.useRef)(null),B=(0,S.useRef)(null),V=(0,S.useRef)(0),H=(0,S.useRef)(0),U=(0,S.useRef)(null),W=(0,S.useRef)(null),G=(0,S.useRef)(P),K=h?.id??null;K!==B.current&&(B.current=K,M!==`preview`&&N(`preview`));let q=(0,S.useCallback)(e=>{G.current=e,W.current===null&&(W.current=window.requestAnimationFrame(()=>{W.current=null,F(G.current)}))},[]),J=(0,S.useCallback)(()=>{U.current=null,L(!1),W.current!==null&&(window.cancelAnimationFrame(W.current),W.current=null,F(G.current))},[]),ae=(0,S.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),U.current=e.pointerId,H.current=P,V.current=e.clientX,G.current=P,e.currentTarget.setPointerCapture(e.pointerId),L(!0)},[P]),Y=(0,S.useCallback)(e=>{if(!I||U.current!==null&&e.pointerId!==U.current)return;e.preventDefault();let t=(V.current-e.clientX)*(n?-1:1),r=window.innerWidth*D;q(Math.min(r,Math.max(E,H.current+t)))},[I,n,q]);if((0,S.useEffect)(()=>{if(!I){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(U.current===null||e.pointerId===U.current)&&J()};return window.addEventListener(`pointermove`,Y,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,J),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,Y),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,J),document.body.style.userSelect=``,document.body.style.cursor=``}},[I,Y,J]),(0,S.useEffect)(()=>{let e=()=>{let e=window.innerWidth*D;P>e&&F(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[P]),(0,S.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r&&k()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,k]),(0,S.useEffect)(()=>{let e=e=>{I||z.current&&!z.current.contains(e.target)&&r&&k()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,k,I]),!h)return null;let X=h,oe=async e=>{try{await navigator.clipboard.writeText(e),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){T.error(`Failed to copy:`,e)}},se=()=>{let e=X.type===`html`?b(X.content,X.title):X.content,t=new Blob([e],{type:ce(X.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${X.title}.${le(X.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ce=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},le=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},ue=()=>{switch(X.type){case`html`:return(0,w.jsx)(o,{className:`h-5 w-5`});case`react`:return(0,w.jsx)(u,{className:`h-5 w-5`});case`svg`:return(0,w.jsx)(c,{className:`h-5 w-5`});case`code`:return(0,w.jsx)(u,{className:`h-5 w-5`});default:return(0,w.jsx)(c,{className:`h-5 w-5`})}},de=()=>(0,w.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,w.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,w.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,w.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,w.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>N(`code`),className:`mt-4`,children:[(0,w.jsx)(a,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Z=()=>X.content.trim()?(0,w.jsx)(`iframe`,{ref:R,"data-testid":`artifact-html-preview`,srcDoc:b(X.content,X.title),className:g(`w-full h-full border-0 rounded-lg bg-white`,I&&`pointer-events-none`),sandbox:y,allow:x,allowFullScreen:!0,title:X.title}):de(),fe=()=>{try{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-auto p-4`,dangerouslySetInnerHTML:{__html:X.content}})}catch{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidSvg`)})]})})}},Q=()=>(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,w.jsx)(v,{language:(()=>{if(X.language)return X.language;switch(X.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:A.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:X.content})}),pe=()=>{try{let e=JSON.parse(X.content),t=JSON.stringify(e,null,2);return(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,w.jsx)(v,{language:`json`,isDark:A.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(i,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},me=()=>{if(M===`code`)return Q();switch(X.type){case`html`:return Z();case`svg`:return fe();case`json`:return pe();default:return Q()}},he=()=>X.type===`html`||X.type===`svg`||X.type===`react`,$=typeof window<`u`&&window.innerWidth<640,ge=$?`100%`:`${P}px`;return(0,C.createPortal)((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:g(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),I&&(0,w.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,w.jsxs)(`div`,{ref:z,"data-testid":`artifact-slide-out-panel`,style:{width:ge},className:g(`fixed top-0 end-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,w.jsxs)(`div`,{onPointerDown:ae,"data-testid":`artifact-resize-handle`,className:g(`absolute start-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,w.jsx)(`div`,{className:g(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,I&&`bg-primary-500 h-24`)}),(0,w.jsx)(`div`,{className:g(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,I&&`opacity-100`),children:(0,w.jsx)(s,{className:`h-4 w-4`})})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,w.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:ue()}),(0,w.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:X.title}),(0,w.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:X.type.toUpperCase()})]}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:k,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,w.jsx)(d,{className:`h-5 w-5`})})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:[(0,w.jsx)(`div`,{className:`flex items-center gap-1`,children:he()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(_,{variant:M===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,w.jsx)(te,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.preview`)]}),(0,w.jsxs)(_,{variant:M===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,w.jsx)(a,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>oe(X.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:ie?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(m,{className:`h-3.5 w-3.5 me-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(f,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.copyButton`)]})}),(0,w.jsxs)(_,{variant:`ghost`,size:`sm`,onClick:se,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,w.jsx)(p,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.download`)]}),(X.type===`html`||X.type===`react`)&&(0,w.jsxs)(_,{variant:`ghost`,size:`sm`,onClick:()=>{let e=window.open(``,`_blank`);e&&(e.document.write(b(X.content,X.title)),e.document.close())},className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.openInNewWindow`),children:[(0,w.jsx)(l,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.open`)]})]})]}),X.description&&(0,w.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:X.description})}),(0,w.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:me()}),(0,w.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:(0,w.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,w.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(X.createdAt).toLocaleString()]}),!$&&(0,w.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]}),document.body)};export{k as ArtifactSlideOutPanel};
@@ -1,16 +1,16 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{n as r}from"./react-vendor-DyG_ODzn.js";import{d as i,f as a,u as o}from"./router-vendor-BjDI9mRe.js";import{t as s}from"./useTranslation-Cs6iTP4m.js";import{$ as c,A as l,Bt as u,C as d,D as f,F as p,Kt as m,Ot as h,P as g,Q as _,Rt as v,S as y,T as b,Tt as x,U as S,Vt as C,W as w,X as T,Xt as E,Yt as D,_t as O,a as k,bt as A,c as j,d as M,dt as N,h as P,i as F,it as I,jt as L,mt as R,n as z,pt as ee,r as te,rt as ne,t as B,v as re,vt as V,x as ie,xt as ae,y as oe}from"./ui-vendor-CAFEDSaO.js";import{n as se}from"./demoMode-BhEpMVh5.js";import{t as H}from"./logger-DbNs3-DK.js";import{C as ce,T as le,a as U,d as ue,i as de,l as fe,m as pe,n as me,u as he}from"./api-YWoSobKv.js";import{i as ge,n as _e,r as ve,t as W}from"./utils-pTFqSV8c.js";import{t as G}from"./Button-DBk-AREB.js";import{$ as ye,E as be,F as K,G as xe,H as q,K as Se,O as Ce,S as we,T as Te,U as Ee,W as De,X as Oe,Y as ke,k as J,p as Ae,w as je,x as Me}from"../assets/index-CKV9Lnj8.js";import{a as Ne,i as Pe}from"./artifactHtml-B7Oy2e__.js";import{t as Fe}from"./ArtifactContainer-B0uVR8Z9.js";import{t as Ie}from"./ModelSelector-CUnwRmNU.js";var Le=r(),Y=e(n(),1),X=t(),Re=({statistics:e,className:t=``})=>{let[n,r]=(0,Y.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,X.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(S,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,X.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,X.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,X.jsx)(A,{size:12}):(0,X.jsx)(V,{size:12,className:`rtl:rotate-180`}),(0,X.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,X.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,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,X.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},ze=H(`components:ttsbutton`),Be=null,Ve=null,He=0,Ue=300*1e3;async function We(e=!1){let t=Date.now();return!e&&Be!==null&&t-He<Ue?Be:Ve||(Ve=(async()=>{try{let e=await U.getModels();return e.success&&e.data&&e.data.length>0?(Be=e.data,He=t,e.data):(Be=[],He=t,[])}catch{return Be=[],He=t,[]}finally{Ve=null}})(),Ve)}function Ge(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Ke=({text:e,className:t,size:n=`sm`})=>{let{t:r}=s(),{preferences:i}=K(),[a,o]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)([]),[m,h]=(0,Y.useState)(null),g=(0,Y.useRef)(null),_=(0,Y.useRef)(!1),v=(0,Y.useRef)([]),y=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=!0;return(async()=>{let t=await We(),n=me(t,i.ttsSettings?.model,i.ttsSettings?.pluginId);i.ttsSettings?.model&&!n&&(t=await We(!0)),e&&(p(t),h(t.length>0))})(),()=>{e=!1}},[i.ttsSettings?.model,i.ttsSettings?.pluginId]);let b=(0,Y.useCallback)(async(e,t,n,i,a,o)=>{let s=await U.generateBase64({model:t,pluginId:n,input:e,voice:i,speed:a,response_format:o});if(!s.success||!s.data?.audio)throw Error(s.message||r(`ttsButton.generateFailed`));let c=`data:${s.data.mimeType};base64,${s.data.audio}`,l=new Audio(c);return g.current=l,new Promise((e,t)=>{l.onended=()=>{g.current=null,e()},l.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},l.play().catch(t)})},[r]),x=(0,Y.useCallback)(async(e,t,n,r,i,a)=>{v.current=e,y.current=0,_.current=!1;let o=null,s=async e=>{try{let o=await U.generateBase64({model:t,pluginId:n,input:e,voice:r,speed:i,response_format:a});return!o.success||!o.data?.audio?null:{audioUrl:`data:${o.data.mimeType};base64,${o.data.audio}`,mimeType:o.data.mimeType}}catch{return null}};e.length>0&&(o=s(e[0]));for(let t=0;t<e.length&&!_.current;t++){y.current=t;try{let n=await o;if(_.current)break;if(o=t+1<e.length?s(e[t+1]):null,!n){ze.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);g.current=r,await new Promise((e,t)=>{r.onended=()=>{g.current=null,e()},r.onerror=()=>{g.current=null,e()},r.play().catch(()=>{e()})})}catch(e){ze.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Y.useCallback)(()=>{_.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),o(!1),l(!1)},[]),w=async()=>{if(!c){if(a){S();return}l(!0),d(null),_.current=!1;try{let t=i.ttsSettings,n=de(f,t?.model,t?.pluginId),a=n?.model||t?.model||`tts-1`,s=n?.plugin||t?.pluginId,c=n?.model===t?.model&&(!t?.pluginId||n?.plugin===t.pluginId)?t?.voice||n?.config?.default_voice||`alloy`:n?.config?.default_voice||`alloy`,u=t?.speed||1,p=n?.config?.default_format;if(t?.streamSentences){let t=Ge(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));l(!1),o(!0),await x(t,a,s,c,u,p),_.current||o(!1)}else await b(e,a,s,c,u,p),l(!1),o(!0),g.current&&(g.current.onended=()=>{o(!1),g.current=null},g.current.onerror=()=>{d(r(`ttsButton.playbackFailed`)),o(!1),g.current=null})}catch(e){d(e instanceof Error?e.message:r(`ttsButton.generateFailed`)),ze.error(`TTS error:`,e),o(!1),l(!1)}}};if((0,Y.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let T={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},E={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,X.jsx)(`button`,{onClick:w,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:W(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,u?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,T[n],t),children:c?(0,X.jsx)(C,{className:W(E[n],`animate-spin`)}):a?(0,X.jsx)(P,{className:E[n]}):u?(0,X.jsx)(F,{className:E[n]}):(0,X.jsx)(k,{className:E[n]})})},qe=/```([^\n`]*)\n([\s\S]*?)\n```/g,Je=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,Ye=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],Xe=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:it(e[1]),title:Ze(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=it(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function Ze(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return $e(Qe(e))}function Qe(e){return e.replace(/&(lt|gt|quot|apos|#39);/gi,(e,t)=>{switch(t.toLowerCase()){case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:case`#39`:return`'`;default:return``}}).replace(/&amp;/gi,`&`)}function $e(e){let t=``,n=!1,r=null;for(let i=0;i<e.length;i+=1){let a=e[i];if(n){if(r){a===r&&(r=null);continue}if(a===`"`||a===`'`){r=a;continue}a===`>`&&(n=!1);continue}if(a===`<`){let t=e[i+1];if(t&&/[!/A-Za-z?]/.test(t)){n=!0;continue}}t+=a}return t}function et(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return Ze(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&Ze(n[1]).trim()||null}function tt(e){let t=e.match(/(?:function|const)\s+(\w+)/);if(t)return t[1];let n=e.match(/class\s+(\w+)/);return n?n[1]:null}function nt(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function rt(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function it(e){let t=e.trim().toLowerCase();return Ye.includes(t)?t:`text`}function Z(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function at(e){let t=[],n=new RegExp(qe),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=ot(n,ct(e,r.index));t.push({raw:r[0],info:n,content:r[2].trim(),start:r.index,end:r.index+r[0].length,language:i.language,fileName:i.fileName})}return t}function ot(e,t){let n=st(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!Je.test(r)&&!r.includes(`=`)?Z(r):void 0)||Z(ut(n)),fileName:n}}function st(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&Je.test(t[1]))return lt(t[1]);let n=e.match(Je);return n?lt(n[0]):void 0}function ct(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{n as r}from"./react-vendor-DyG_ODzn.js";import{d as i,f as a,u as o}from"./router-vendor-BjDI9mRe.js";import{t as s}from"./useTranslation-Cs6iTP4m.js";import{$ as c,A as l,Bt as u,C as d,D as f,F as p,Kt as m,Ot as h,P as g,Q as _,Rt as v,S as y,T as b,Tt as x,U as S,Vt as C,W as w,X as T,Xt as E,Yt as D,_t as O,a as k,bt as A,c as j,d as M,dt as N,h as P,i as F,it as I,jt as L,mt as R,n as z,pt as ee,r as te,rt as ne,t as B,v as re,vt as V,x as ie,xt as ae,y as oe}from"./ui-vendor-CAFEDSaO.js";import{n as se}from"./demoMode-BhEpMVh5.js";import{t as H}from"./logger-DbNs3-DK.js";import{C as ce,T as le,a as U,d as ue,i as de,l as fe,m as pe,n as me,u as he}from"./api-Fi-lJlfu.js";import{i as ge,n as _e,r as ve,t as W}from"./utils-pTFqSV8c.js";import{t as G}from"./Button-DBk-AREB.js";import{E as ye,F as K,G as be,H as q,K as xe,O as Se,S as Ce,T as we,U as Te,W as Ee,X as De,Y as Oe,k as J,nt as ke,p as Ae,w as je,x as Me}from"../assets/index-BVgyQN3z.js";import{a as Ne,i as Pe}from"./artifactHtml-B7Oy2e__.js";import{t as Fe}from"./ArtifactContainer-CbMAYwvr.js";import{t as Ie}from"./ModelSelector-COnlNsVM.js";var Le=r(),Y=e(n(),1),X=t(),Re=({statistics:e,className:t=``})=>{let[n,r]=(0,Y.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,X.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(S,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,X.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,X.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,X.jsx)(A,{size:12}):(0,X.jsx)(V,{size:12,className:`rtl:rotate-180`}),(0,X.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,X.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,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,X.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},ze=H(`components:ttsbutton`),Be=null,Ve=null,He=0,Ue=300*1e3;async function We(e=!1){let t=Date.now();return!e&&Be!==null&&t-He<Ue?Be:Ve||(Ve=(async()=>{try{let e=await U.getModels();return e.success&&e.data&&e.data.length>0?(Be=e.data,He=t,e.data):(Be=[],He=t,[])}catch{return Be=[],He=t,[]}finally{Ve=null}})(),Ve)}function Ge(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Ke=({text:e,className:t,size:n=`sm`})=>{let{t:r}=s(),{preferences:i}=K(),[a,o]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)([]),[m,h]=(0,Y.useState)(null),g=(0,Y.useRef)(null),_=(0,Y.useRef)(!1),v=(0,Y.useRef)([]),y=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=!0;return(async()=>{let t=await We(),n=me(t,i.ttsSettings?.model,i.ttsSettings?.pluginId);i.ttsSettings?.model&&!n&&(t=await We(!0)),e&&(p(t),h(t.length>0))})(),()=>{e=!1}},[i.ttsSettings?.model,i.ttsSettings?.pluginId]);let b=(0,Y.useCallback)(async(e,t,n,i,a,o)=>{let s=await U.generateBase64({model:t,pluginId:n,input:e,voice:i,speed:a,response_format:o});if(!s.success||!s.data?.audio)throw Error(s.message||r(`ttsButton.generateFailed`));let c=`data:${s.data.mimeType};base64,${s.data.audio}`,l=new Audio(c);return g.current=l,new Promise((e,t)=>{l.onended=()=>{g.current=null,e()},l.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},l.play().catch(t)})},[r]),x=(0,Y.useCallback)(async(e,t,n,r,i,a)=>{v.current=e,y.current=0,_.current=!1;let o=null,s=async e=>{try{let o=await U.generateBase64({model:t,pluginId:n,input:e,voice:r,speed:i,response_format:a});return!o.success||!o.data?.audio?null:{audioUrl:`data:${o.data.mimeType};base64,${o.data.audio}`,mimeType:o.data.mimeType}}catch{return null}};e.length>0&&(o=s(e[0]));for(let t=0;t<e.length&&!_.current;t++){y.current=t;try{let n=await o;if(_.current)break;if(o=t+1<e.length?s(e[t+1]):null,!n){ze.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);g.current=r,await new Promise((e,t)=>{r.onended=()=>{g.current=null,e()},r.onerror=()=>{g.current=null,e()},r.play().catch(()=>{e()})})}catch(e){ze.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Y.useCallback)(()=>{_.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),o(!1),l(!1)},[]),w=async()=>{if(!c){if(a){S();return}l(!0),d(null),_.current=!1;try{let t=i.ttsSettings,n=de(f,t?.model,t?.pluginId),a=n?.model||t?.model||`tts-1`,s=n?.plugin||t?.pluginId,c=n?.model===t?.model&&(!t?.pluginId||n?.plugin===t.pluginId)?t?.voice||n?.config?.default_voice||`alloy`:n?.config?.default_voice||`alloy`,u=t?.speed||1,p=n?.config?.default_format;if(t?.streamSentences){let t=Ge(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));l(!1),o(!0),await x(t,a,s,c,u,p),_.current||o(!1)}else await b(e,a,s,c,u,p),l(!1),o(!0),g.current&&(g.current.onended=()=>{o(!1),g.current=null},g.current.onerror=()=>{d(r(`ttsButton.playbackFailed`)),o(!1),g.current=null})}catch(e){d(e instanceof Error?e.message:r(`ttsButton.generateFailed`)),ze.error(`TTS error:`,e),o(!1),l(!1)}}};if((0,Y.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let T={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},E={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,X.jsx)(`button`,{onClick:w,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:W(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,u?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,T[n],t),children:c?(0,X.jsx)(C,{className:W(E[n],`animate-spin`)}):a?(0,X.jsx)(P,{className:E[n]}):u?(0,X.jsx)(F,{className:E[n]}):(0,X.jsx)(k,{className:E[n]})})},qe=/```([^\n`]*)\n([\s\S]*?)\n```/g,Je=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,Ye=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],Xe=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:it(e[1]),title:Ze(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=it(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function Ze(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return $e(Qe(e))}function Qe(e){return e.replace(/&(lt|gt|quot|apos|#39);/gi,(e,t)=>{switch(t.toLowerCase()){case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:case`#39`:return`'`;default:return``}}).replace(/&amp;/gi,`&`)}function $e(e){let t=``,n=!1,r=null;for(let i=0;i<e.length;i+=1){let a=e[i];if(n){if(r){a===r&&(r=null);continue}if(a===`"`||a===`'`){r=a;continue}a===`>`&&(n=!1);continue}if(a===`<`){let t=e[i+1];if(t&&/[!/A-Za-z?]/.test(t)){n=!0;continue}}t+=a}return t}function et(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return Ze(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&Ze(n[1]).trim()||null}function tt(e){let t=e.match(/(?:function|const)\s+(\w+)/);if(t)return t[1];let n=e.match(/class\s+(\w+)/);return n?n[1]:null}function nt(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function rt(e){let t=e.match(/function\s+(\w+)/);if(t)return`${t[1]} Function`;let n=e.match(/(?:const|let)\s+(\w+)\s*=/);return n?n[1]:null}function it(e){let t=e.trim().toLowerCase();return Ye.includes(t)?t:`text`}function Z(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function at(e){let t=[],n=new RegExp(qe),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=ot(n,ct(e,r.index));t.push({raw:r[0],info:n,content:r[2].trim(),start:r.index,end:r.index+r[0].length,language:i.language,fileName:i.fileName})}return t}function ot(e,t){let n=st(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!Je.test(r)&&!r.includes(`=`)?Z(r):void 0)||Z(ut(n)),fileName:n}}function st(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&Je.test(t[1]))return lt(t[1]);let n=e.match(Je);return n?lt(n[0]):void 0}function ct(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
2
2
  `).slice(-3).reverse();for(let e of n){let t=e.trim().replace(/^#{1,6}\s*/,``).replace(/^[-*]\s*/,``).replace(/[::]\s*$/,``).match(Je);if(t)return lt(t[0])}}function lt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function ut(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function dt(e){return e?.split(/[\\/]/).pop()}function Q(e){let t=dt(e);if(!t)return null;let n=t.replace(/\.[^.]+$/,``);return/^(index|main|app)$/i.test(n)?null:n.replace(/[-_]+/g,` `).replace(/\b\w/g,e=>e.toUpperCase())}function ft(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function pt(e){let t=Z(e.language)||Z(ut(e.fileName));switch(t){case`html`:return{type:`html`,title:et(e.content)||Q(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:Q(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:tt(e.content)||Q(e.fileName)||`React Component`,language:`jsx`};case`json`:return{type:`json`,title:Q(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:nt(e.content)||Q(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:Q(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:rt(e.content)||Q(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:Q(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:Q(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function mt(e){return(Z(e.language)||Z(ut(e.fileName)))===`html`}function ht(e){return(Z(e.language)||Z(ut(e.fileName)))===`css`}function gt(e){return(Z(e.language)||Z(ut(e.fileName)))===`javascript`}function _t(e){let t=at(e),n=t.filter(mt);if(n.length===0)return null;let r=t.filter(ht),i=t.filter(gt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=Ne(vt(a.content,r,i),r.map(e=>e.content),i.map(e=>e.content));return Ct(o,`html`)?{artifact:ft({type:`html`,title:et(o)||Q(a.fileName)||`Interactive HTML App`,description:`Bundled generated HTML, CSS, and JavaScript files into one runnable artifact.`,content:o}),ranges:[a,...r,...i]}:null}function vt(e,t,n){let r=e;for(let e of t){let t=dt(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${St(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=dt(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${St(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function yt(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=at(e);if(bt(t.index,n))return null;let r=t.index,i=/<\/html>/gi;i.lastIndex=r;let a=i.exec(e),o=a?a.index+a[0].length:e.length,s=e.slice(r,o).trim();return Ct(s,`html`)?{artifact:ft({type:`html`,title:et(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function bt(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function xt(e,t){return[...t].sort((e,t)=>t.start-e.start).reduce((e,t)=>`${e.slice(0,t.start)}${e.slice(t.end)}`,e)}function St(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ct(e,t){if(t===`html`){let t=e.trim(),n=/<[^>]+>/.test(t),r=/<(canvas|script|style|button|form|input|select|textarea|video|audio)\b/i.test(t)||/\bon(?:click|input|submit|keydown|keyup|mousemove)=/i.test(t);return n&&(Pe(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Z][^>]*>/.test(e)||/return\s*\(/.test(e);if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
3
- `).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return e.trim().length>200}function wt(e){let t=[],n=e;for(let e of Xe){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);Ct(n.content,n.type)&&(t.push(ft({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=xt(n,r)}let r=_t(n);for(;r;)t.push(r.artifact),n=xt(n,r.ranges),r=_t(n);let i=yt(n);i&&(t.push(i.artifact),n=xt(n,i.ranges));let a=at(n),o=[];for(let e of a){let n=pt(e);!n||!Ct(e.content,n.type)||(t.push(ft({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=xt(n,o),{content:n.trim(),artifacts:t}}var Tt=H(`components:chat-message`),Et=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i})=>{let{t:a,i18n:o}=s(),c=e.role===`user`,l=e.role===`system`,{preferences:f}=K(),{user:p}=Ce(),{setSystemMessage:m,getCurrentPersona:h}=q(),g=h(),[_,v]=(0,Y.useState)(!1),[y,S]=(0,Y.useState)(e.content),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),[D,k]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(!1),[N,P]=(0,Y.useState)(!1),[F,I]=(0,Y.useState)(!1),L=(0,Y.useRef)(null),R=(0,Y.useRef)(t),te=(0,Y.useRef)(!1),ne=async()=>{try{await navigator.clipboard.writeText(e.content),I(!0),setTimeout(()=>I(!1),2e3)}catch(e){Tt.error(`Failed to copy message:`,e)}},{thinkingContent:B,parsedContent:V,artifacts:ie}=(0,Y.useMemo)(()=>{if(c||l||!e.content)return{thinkingContent:null,parsedContent:e.content,artifacts:e.artifacts||[]};let n=ge(e.content),r=n.content;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,parsedContent:r,artifacts:e.artifacts};if(!t){let e=wt(r);return{thinkingContent:n.thinking,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,parsedContent:r,artifacts:[]}},[e.content,e.artifacts,c,l,t]);(0,Y.useEffect)(()=>{let e=R.current&&!t;return R.current=t,e&&!te.current&&!c&&!l&&V&&f.ttsSettings?.enabled&&f.ttsSettings?.autoPlay&&(te.current=!0,(async()=>{P(!0);try{let e=await U.getModels(),t=e.success&&e.data?e.data:[],n=f.ttsSettings,r=de(t,n?.model,n?.pluginId),i=me(t,n?.model,n?.pluginId),a=await U.generateBase64({model:r?.model||n?.model||`tts-1`,pluginId:r?.plugin||n?.pluginId,input:V,voice:i?n?.voice||r?.config?.default_voice||`alloy`:r?.config?.default_voice||`alloy`,speed:n?.speed||1,response_format:r?.config?.default_format});if(a.success&&a.data?.audio){let e=`data:${a.data.mimeType};base64,${a.data.audio}`,t=new Audio(e);L.current=t,t.onended=()=>{P(!1),L.current=null},t.onerror=()=>{P(!1),L.current=null},await t.play()}}catch(e){Tt.error(`Auto-play TTS failed:`,e),P(!1)}})()),()=>{L.current&&(L.current.pause(),L.current=null)}},[t,c,l,V,f.ttsSettings]);let oe=()=>l?a(`chatMessage.system`):c?f.showUsername&&p?.username?p.username:a(`chatMessage.you`):g?.name?g.name:e.model||a(`chatMessage.assistant`),se=()=>{v(!0),S(e.content)},H=async()=>{E(!0);try{m(y),v(!1),Tt.debug(`✅ System message updated:`,y)}catch(e){Tt.error(`Failed to save system message:`,e)}finally{E(!1)}},ce=()=>{v(!1),S(e.content)},le=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ue=l&&e.content.length>100;return(0,X.jsxs)(`div`,{className:W(`group flex py-3 transition-colors sm:py-4`,c?`justify-end`:`justify-start`,n),children:[(0,X.jsx)(`div`,{className:W(`flex min-w-0`,c?`max-w-[88%] sm:max-w-[72%]`:`w-full`),children:(0,X.jsxs)(`div`,{className:W(`min-w-0 flex-1`,c?`rounded-[1.35rem] rounded-ee-md border border-black/[0.06] bg-gray-900 px-4 py-3 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`:l?`bg-transparent py-2`:`bg-transparent py-1`),children:[!l&&(0,X.jsxs)(`div`,{className:W(`mb-2 flex items-center gap-2.5`,c&&`justify-end`),children:[(0,X.jsx)(`span`,{dir:`auto`,className:W(`text-[11px] font-semibold uppercase tracking-[0.1em] rtl:tracking-normal`,c?`text-white/70`:`text-gray-700 dark:text-dark-700`),children:oe()}),e.model&&!c&&g?.name&&(0,X.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,X.jsx)(`span`,{dir:`auto`,className:W(`text-[10px] tabular-nums`,c?`text-white/45`:`text-gray-400 dark:text-dark-500`),children:_e(e.timestamp,o.language)})]}),(0,X.jsxs)(`div`,{className:W(c?`text-[15px] text-white`:`text-[15px] leading-7 text-gray-800 dark:text-dark-800 sm:text-base`),children:[e.images&&e.images.length>0&&(0,X.jsx)(`div`,{className:`mb-3 grid max-w-lg grid-cols-2 gap-2 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,X.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-white/10 bg-gray-100 dark:bg-gray-800`,children:(0,X.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>w(e)})},t))}),c?(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap leading-relaxed`,children:e.content}):l?(0,X.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,X.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,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(re,{className:`h-2.5 w-2.5 opacity-50`}),a(`chatMessage.system`)]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:H,disabled:T,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:a(`chatMessage.saveChanges`),children:(0,X.jsx)(d,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,X.jsx)(`button`,{onClick:ce,disabled:T,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:a(`chatMessage.cancelEditing`),children:(0,X.jsx)(z,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,X.jsx)(`button`,{onClick:se,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:a(`chatMessage.editSystemMessage`),children:(0,X.jsx)(u,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),_?(0,X.jsx)(`textarea`,{dir:`auto`,value:y,onChange:e=>S(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:a(`chatMessage.systemMessagePlaceholder`),disabled:T}):(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:D?e.content:le(e.content)}),ue&&(0,X.jsx)(`button`,{onClick:()=>k(!D),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:D?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O,{className:`h-3 w-3`}),a(`chatMessage.showLess`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{className:`h-3 w-3`}),a(`chatMessage.showMore`)]})})]})]}):(0,X.jsxs)(`div`,{className:`relative`,children:[B&&(0,X.jsxs)(`div`,{className:`mb-4 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,X.jsxs)(`button`,{onClick:()=>M(!j),className:`flex items-center gap-2 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,X.jsx)(x,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium`,children:a(`chatMessage.thinking`)}),j?(0,X.jsx)(O,{className:`h-4 w-4`}):(0,X.jsx)(A,{className:`h-4 w-4`})]}),j&&(0,X.jsx)(`div`,{className:`mt-3 rounded-xl bg-gray-100/60 p-3 dark:bg-dark-200/60`,children:(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:B})})]}),(0,X.jsx)(Ae,{content:V,isStreaming:t})]}),!c&&!l&&ie.length>0&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Fe,{artifacts:ie})}),!c&&!l&&e.statistics&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Re,{statistics:e.statistics})}),!l&&!t&&(0,X.jsxs)(`div`,{className:W(`mt-3 flex items-center gap-1`,c?`justify-end border-t border-white/10 pt-2 text-white/65`:`text-gray-400 dark:text-dark-500`),children:[!c&&V&&(0,X.jsx)(Ke,{text:V,size:`sm`,className:W(`transition-colors`,N&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),(0,X.jsx)(`button`,{onClick:ne,className:W(`flex h-8 w-8 items-center justify-center rounded-full transition-colors`,c?`hover:bg-white/10 hover:text-white`:`hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`),title:a(F?`chatMessage.copied`:`chatMessage.copyMessage`),children:F?(0,X.jsx)(ae,{className:`h-3.5 w-3.5 text-green-400`}):(0,X.jsx)(ee,{className:`h-3.5 w-3.5`})}),!c&&r&&i&&(0,X.jsx)(`button`,{onClick:i,className:`flex h-8 w-8 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:a(`chatMessage.regenerateResponse`),children:(0,X.jsx)(b,{className:`h-3.5 w-3.5`})})]})]})]})}),C&&(0,Le.createPortal)((0,X.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":a(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>w(null),children:[(0,X.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(),w(null)},children:(0,X.jsx)(z,{className:`h-7 w-7`})}),(0,X.jsx)(`img`,{src:C,alt:a(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Dt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Ot=220,kt=e=>{let t=e.slice(0,Ot*4).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>Ot?`${t.slice(0,Ot-1).trimEnd()}…`:t},At=Y.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Y.useRef)(null),a=(0,Y.useRef)(null),o=(0,Y.useRef)(new Map),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(0),f=(0,Y.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Y.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,Y.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:Dt()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,X.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% - 30rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,X.jsx)(`ol`,{ref:a,className:`pointer-events-auto grid h-full min-h-0 overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,style:{gridTemplateRows:`repeat(${e.length}, minmax(1.5rem, 1fr))`},children:e.map((t,a)=>{let s=t.id===h,u=c===t.id?v:void 0;return(0,X.jsx)(`li`,{className:`flex min-h-6 items-center`,children:(0,X.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":u,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:W(`group flex h-6 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,X.jsx)(`span`,{"aria-hidden":`true`,className:W(`block rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`h-0.5 w-6 bg-ink opacity-90 xl:w-7`:`h-px w-3 bg-line-strong opacity-75 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,X.jsxs)(`div`,{id:v,role:`tooltip`,className:W(`pointer-events-none absolute start-full ms-3 w-72 -translate-y-1/2`,`rounded-2xl border border-line bg-surface-overlay/95 p-4 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(6.5rem, ${u}px, calc(100% - 6.5rem))`},children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,X.jsxs)(`span`,{dir:`ltr`,className:`text-[10px] font-semibold uppercase tracking-[0.14em] text-ink-subtle`,children:[String(g+1).padStart(2,`0`),` /`,` `,String(e.length).padStart(2,`0`)]}),(0,X.jsx)(`span`,{className:`h-px flex-1 bg-line`,"aria-hidden":`true`})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`mb-1 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-subtle`,children:r(`chatMessage.you`)}),(0,X.jsx)(`p`,{dir:`auto`,className:`line-clamp-2 text-sm font-medium leading-5 text-ink`,children:kt(_.prompt)})]}),_.response&&(0,X.jsxs)(`div`,{className:`border-t border-line pt-3`,children:[(0,X.jsx)(`p`,{className:`mb-1 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-subtle`,children:r(`chatMessage.assistant`)}),(0,X.jsx)(`p`,{dir:`auto`,className:`line-clamp-2 text-xs leading-5 text-ink-muted`,children:kt(_.response)})]})]})]})]})}),jt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingMessageId:r,isLastAssistantMessage:i=!1,onRegenerate:a,onSelectBranch:o,className:s})=>{if(e.length===1){let o=e[0],c=t&&r===o.id;return(0,X.jsx)(Et,{message:c&&n?{...o,content:n}:o,isStreaming:c,isLastAssistantMessage:i,onRegenerate:a,className:s})}return(0,X.jsxs)(`div`,{className:W(`relative py-2`,s),children:[(0,X.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,X.jsx)(_,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let c=e.isActive!==!1,l=t&&r===e.id,u=l&&n?{...e,content:n}:e;return(0,X.jsxs)(`div`,{className:W(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,c||l?`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`,!c&&!l&&`cursor-pointer`),role:!c&&!l?`button`:void 0,tabIndex:!c&&!l?0:void 0,onClick:()=>!c&&!l&&o?.(e.id),onKeyDown:t=>{!c&&!l&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),o?.(e.id))},children:[(0,X.jsxs)(`div`,{className:W(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,c||l?`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,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:s+1}),l&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),c&&!l&&(0,X.jsx)(ae,{className:`h-3 w-3`}),!c&&!l&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,X.jsx)(`div`,{className:W(!c&&!l&&`opacity-75`),children:(0,X.jsx)(Et,{message:u,isStreaming:l,isLastAssistantMessage:i&&(c||l),onRegenerate:c&&!t?a:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Mt={web_search:y,web_fetch:T,exec:M,browser:T,Read:I,Write:I,Edit:I,image:w,memory_search:N,memory_get:N,working:te,thinking:te,default:te},Nt={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`},Pt=({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,X.jsx)(`div`,{className:W(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Mt[e.name]||Mt.default,n=Nt[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,X.jsxs)(`div`,{className:W(`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,X.jsx)(`div`,{className:W(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,X.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,X.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};H(`components:chat-messages`);var Ft=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],It=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,Lt=e=>Math.min(120,e*.28),Rt=({messages:e,streamingMessage:t,streamingMessageId:n,isStreaming:r=!1,toolActivities:i=[],className:a,onRegenerate:o,onSelectBranch:c})=>{let{t:l}=s(),u=(0,Y.useRef)(null),d=(0,Y.useRef)(void 0),f=(0,Y.useRef)(null),p=(0,Y.useRef)(null),m=(0,Y.useRef)(new Map),h=(0,Y.useRef)(null),g=(0,Y.useRef)(0),_=(0,Y.useRef)(!1),y=(0,Y.useRef)(!1),[b,x]=(0,Y.useState)(!1),S=(0,Y.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),C=(0,Y.useMemo)(()=>{let e=[];for(let t=0;t<S.length;t++){let n=S[t],r=Ft(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<S.length;e++){let t=Ft(S[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},[S]),w=C.map(e=>e.id).join(``),T=(0,Y.useMemo)(()=>w?w.split(``):[],[w]),E=(0,Y.useMemo)(()=>new Set(T),[T]),[D,O]=(0,Y.useState)(null),k=(0,Y.useCallback)(()=>{let e=f.current;if(!e||T.length===0){O(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(g.current,T.length-1);if(t<=2)n=T.length-1;else{let t=e.scrollTop+Lt(e.clientHeight);for(;n<T.length-1;){let e=m.current.get(T[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=m.current.get(T[n]);if(!e||e.offsetTop<=t)break;n--}}g.current=n;let r=T[n];O(e=>e===r?e:r)},[T]),A=(0,Y.useCallback)(()=>{h.current===null&&(h.current=window.requestAnimationFrame(()=>{h.current=null,k()}))},[k]),j=(0,Y.useCallback)(()=>{let t=f.current;if(d.current&&clearTimeout(d.current),_.current=!1,d.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;y.current=!n,x(!n&&e.length>0),A()},[e.length,A]),M=(0,Y.useCallback)(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(j,180)},[j]),N=(0,Y.useCallback)((e=!1)=>{y.current&&!e||u.current?.scrollIntoView({behavior:It()})},[]),P=(0,Y.useCallback)(()=>{let t=f.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(_.current){y.current=!0,x(!o&&e.length>0),A(),M();return}y.current=!o,x(!o&&e.length>0),a<=2&&T.length>0?(g.current=T.length-1,O(T[T.length-1])):A()},[T,e.length,M,A]),F=(0,Y.useCallback)(e=>{let t=f.current,n=m.current.get(e);if(!t||!n)return;let r=It();_.current=!0,y.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-Lt(t.clientHeight)),behavior:r}),A(),r===`auto`?j():M()},[j,M,A]),I=(0,Y.useRef)(e.length);if((0,Y.useEffect)(()=>{e.length>I.current&&!y.current&&N(),I.current=e.length},[e.length,N]),(0,Y.useEffect)(()=>{r&&t&&!y.current&&requestAnimationFrame(()=>{let e=f.current;e&&(e.scrollTop=e.scrollHeight)})},[r,t]),(0,Y.useEffect)(()=>{A();let e=p.current,t=f.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(A);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,A),()=>{n?.disconnect(),window.removeEventListener(`resize`,A)}},[w,A]),(0,Y.useEffect)(()=>()=>{h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null)},[]),(0,Y.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]),e.length===0&&!r)return(0,X.jsx)(`div`,{className:W(`flex-1 flex items-center justify-center p-6 sm:p-10`,a),children:(0,X.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,X.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,X.jsx)(v,{className:`h-4 w-4`})}),(0,X.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:l(`chatMessage.startConversation`)}),(0,X.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:l(`chatMessage.startConversationDescription`)})]})});let R=-1;for(let e=S.length-1;e>=0;e--)if(S[e].messages.some(e=>e.role===`assistant`)){R=e;break}return(0,X.jsxs)(`div`,{className:W(`relative min-h-0 flex-1`,a),style:{WebkitAppRegion:`no-drag`},children:[(0,X.jsx)(`div`,{ref:f,"data-testid":`chat-scroll-viewport`,onScroll:P,className:W(`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,X.jsxs)(`div`,{ref:p,className:`mx-auto w-full min-w-0 max-w-4xl px-4 sm:px-6 md:px-8`,children:[S.map((e,i)=>{let a=i===R,s=E.has(e.id),l=r&&e.messages.some(e=>e.id===n),u;if(e.messages.length===1){let s=e.messages[0],c=r&&s.id===n;u=(0,X.jsx)(Et,{message:c&&t?{...s,content:t}:s,isStreaming:c,isLastAssistantMessage:a,onRegenerate:a?o:void 0,className:i===0?`mt-5 sm:mt-7`:``})}else u=(0,X.jsx)(jt,{messages:e.messages,isStreaming:l,streamingMessage:t,streamingMessageId:n||void 0,isLastAssistantMessage:a,onRegenerate:a?o:void 0,onSelectBranch:c,className:i===0?`mt-5 sm:mt-7`:``});return(0,X.jsx)(`div`,{ref:t=>{s&&(t?m.current.set(e.id,t):m.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:u},e.id)}),r&&i.length>0&&(0,X.jsx)(Pt,{tools:i,className:`px-0`}),(0,X.jsx)(`div`,{ref:u,className:`h-4 sm:h-6`})]})}),(0,X.jsx)(At,{items:C,activeId:D,onSelect:F}),b&&(0,X.jsxs)(`button`,{onClick:()=>{_.current=!1,d.current&&(clearTimeout(d.current),d.current=void 0),y.current=!1,u.current?.scrollIntoView({behavior:It()}),x(!1)},className:W(`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:l(`chatMessage.scrollToBottom`),children:[(0,X.jsx)(L,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:l(`chatMessage.newMessages`)})]})]})};function zt(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 Bt=Y.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,Y.useMemo)(()=>zt(e),[e]);return(0,X.jsxs)(`div`,{className:`relative w-full`,children:[(0,X.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:W(`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,X.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,X.jsxs)(`div`,{className:W(`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,X.jsx)(m,{className:`h-3 w-3`}),d&&(0,X.jsx)(`span`,{children:d}),!d&&u&&(0,X.jsx)(`span`,{children:`code`})]})})]})});Bt.displayName=`CodeAwareTextarea`;var Vt=H(`components:media-upload`),Ht=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)([]),g=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await v(n):E.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){E.error(`Maximum ${n} images allowed`);return}if(r.size>10*1024*1024){E.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},v=async e=>{if(e.size>10*1024*1024){E.error(`File size must be less than 10MB`);return}p(!0);try{let t=await ce.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),E.success(`Document "${e.name}" uploaded`)}else E.error(t.error||`Failed to upload document`)}catch(e){Vt.error(`Document upload error:`,e),E.error(`Failed to upload document`)}finally{p(!1)}},y=e=>{e.preventDefault(),a||d(!0)},b=e=>{e.preventDefault(),d(!1)},x=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},w=async e=>{try{let t=await ce.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),E.success(`Document removed`)):E.error(t.error||`Failed to remove document`)}catch(e){Vt.error(`Error removing document:`,e),E.error(`Failed to remove document`)}},T=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},D=e.length>0||m.length>0;return(0,X.jsxs)(`div`,{className:W(`space-y-3`,o),children:[(0,X.jsxs)(`div`,{className:W(`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:y,onDragLeave:b,onDrop:x,onClick:()=>!a&&l.current?.click(),children:[(0,X.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,X.jsx)(C,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,X.jsx)(j,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),D&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,X.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,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),S(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,X.jsx)(z,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,X.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,X.jsx)(I,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,X.jsx)(ne,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,X.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:T(e.size)})]}),(0,X.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,X.jsx)(z,{className:`h-3 w-3`})})]},e.id))]})]})},Ut=H(`components:document-indicator`),Wt=({sessionId:e,className:t=``})=>{let[n,r]=(0,Y.useState)([]);if((0,Y.useEffect)(()=>{e&&(async()=>{try{let t=await ce.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){Ut.error(`Failed to load documents:`,e)}})()},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,X.jsxs)(`div`,{className:`
3
+ `).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return e.trim().length>200}function wt(e){let t=[],n=e;for(let e of Xe){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);Ct(n.content,n.type)&&(t.push(ft({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=xt(n,r)}let r=_t(n);for(;r;)t.push(r.artifact),n=xt(n,r.ranges),r=_t(n);let i=yt(n);i&&(t.push(i.artifact),n=xt(n,i.ranges));let a=at(n),o=[];for(let e of a){let n=pt(e);!n||!Ct(e.content,n.type)||(t.push(ft({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=xt(n,o),{content:n.trim(),artifacts:t}}var Tt=H(`components:chat-message`),Et=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i})=>{let{t:a,i18n:o}=s(),c=e.role===`user`,l=e.role===`system`,{preferences:f}=K(),{user:p}=Se(),{setSystemMessage:m,getCurrentPersona:h}=q(),g=h(),[_,v]=(0,Y.useState)(!1),[y,S]=(0,Y.useState)(e.content),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),[D,k]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(!1),[N,P]=(0,Y.useState)(!1),[F,I]=(0,Y.useState)(!1),L=(0,Y.useRef)(null),R=(0,Y.useRef)(t),te=(0,Y.useRef)(!1),ne=async()=>{try{await navigator.clipboard.writeText(e.content),I(!0),setTimeout(()=>I(!1),2e3)}catch(e){Tt.error(`Failed to copy message:`,e)}},{thinkingContent:B,parsedContent:V,artifacts:ie}=(0,Y.useMemo)(()=>{if(c||l||!e.content)return{thinkingContent:null,parsedContent:e.content,artifacts:e.artifacts||[]};let n=ge(e.content),r=n.content;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,parsedContent:r,artifacts:e.artifacts};if(!t){let e=wt(r);return{thinkingContent:n.thinking,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,parsedContent:r,artifacts:[]}},[e.content,e.artifacts,c,l,t]);(0,Y.useEffect)(()=>{let e=R.current&&!t;return R.current=t,e&&!te.current&&!c&&!l&&V&&f.ttsSettings?.enabled&&f.ttsSettings?.autoPlay&&(te.current=!0,(async()=>{P(!0);try{let e=await U.getModels(),t=e.success&&e.data?e.data:[],n=f.ttsSettings,r=de(t,n?.model,n?.pluginId),i=me(t,n?.model,n?.pluginId),a=await U.generateBase64({model:r?.model||n?.model||`tts-1`,pluginId:r?.plugin||n?.pluginId,input:V,voice:i?n?.voice||r?.config?.default_voice||`alloy`:r?.config?.default_voice||`alloy`,speed:n?.speed||1,response_format:r?.config?.default_format});if(a.success&&a.data?.audio){let e=`data:${a.data.mimeType};base64,${a.data.audio}`,t=new Audio(e);L.current=t,t.onended=()=>{P(!1),L.current=null},t.onerror=()=>{P(!1),L.current=null},await t.play()}}catch(e){Tt.error(`Auto-play TTS failed:`,e),P(!1)}})()),()=>{L.current&&(L.current.pause(),L.current=null)}},[t,c,l,V,f.ttsSettings]);let oe=()=>l?a(`chatMessage.system`):c?f.showUsername&&p?.username?p.username:a(`chatMessage.you`):g?.name?g.name:e.model||a(`chatMessage.assistant`),se=()=>{v(!0),S(e.content)},H=async()=>{E(!0);try{m(y),v(!1),Tt.debug(`✅ System message updated:`,y)}catch(e){Tt.error(`Failed to save system message:`,e)}finally{E(!1)}},ce=()=>{v(!1),S(e.content)},le=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ue=l&&e.content.length>100;return(0,X.jsxs)(`div`,{className:W(`group flex py-3 transition-colors sm:py-4`,c?`justify-end`:`justify-start`,n),children:[(0,X.jsx)(`div`,{className:W(`flex min-w-0`,c?`max-w-[88%] sm:max-w-[72%]`:`w-full`),children:(0,X.jsxs)(`div`,{className:W(`min-w-0 flex-1`,c?`rounded-[1.35rem] rounded-ee-md border border-black/[0.06] bg-gray-900 px-4 py-3 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`:l?`bg-transparent py-2`:`bg-transparent py-1`),children:[!l&&(0,X.jsxs)(`div`,{className:W(`mb-2 flex items-center gap-2.5`,c&&`justify-end`),children:[(0,X.jsx)(`span`,{dir:`auto`,className:W(`text-[11px] font-semibold uppercase tracking-[0.1em] rtl:tracking-normal`,c?`text-white/70`:`text-gray-700 dark:text-dark-700`),children:oe()}),e.model&&!c&&g?.name&&(0,X.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,X.jsx)(`span`,{dir:`auto`,className:W(`text-[10px] tabular-nums`,c?`text-white/45`:`text-gray-400 dark:text-dark-500`),children:_e(e.timestamp,o.language)})]}),(0,X.jsxs)(`div`,{className:W(c?`text-[15px] text-white`:`text-[15px] leading-7 text-gray-800 dark:text-dark-800 sm:text-base`),children:[e.images&&e.images.length>0&&(0,X.jsx)(`div`,{className:`mb-3 grid max-w-lg grid-cols-2 gap-2 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,X.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-white/10 bg-gray-100 dark:bg-gray-800`,children:(0,X.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>w(e)})},t))}),c?(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap leading-relaxed`,children:e.content}):l?(0,X.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,X.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,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(re,{className:`h-2.5 w-2.5 opacity-50`}),a(`chatMessage.system`)]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:H,disabled:T,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:a(`chatMessage.saveChanges`),children:(0,X.jsx)(d,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,X.jsx)(`button`,{onClick:ce,disabled:T,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:a(`chatMessage.cancelEditing`),children:(0,X.jsx)(z,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,X.jsx)(`button`,{onClick:se,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:a(`chatMessage.editSystemMessage`),children:(0,X.jsx)(u,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),_?(0,X.jsx)(`textarea`,{dir:`auto`,value:y,onChange:e=>S(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:a(`chatMessage.systemMessagePlaceholder`),disabled:T}):(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:D?e.content:le(e.content)}),ue&&(0,X.jsx)(`button`,{onClick:()=>k(!D),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:D?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O,{className:`h-3 w-3`}),a(`chatMessage.showLess`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(A,{className:`h-3 w-3`}),a(`chatMessage.showMore`)]})})]})]}):(0,X.jsxs)(`div`,{className:`relative`,children:[B&&(0,X.jsxs)(`div`,{className:`mb-4 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,X.jsxs)(`button`,{onClick:()=>M(!j),className:`flex items-center gap-2 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,X.jsx)(x,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium`,children:a(`chatMessage.thinking`)}),j?(0,X.jsx)(O,{className:`h-4 w-4`}):(0,X.jsx)(A,{className:`h-4 w-4`})]}),j&&(0,X.jsx)(`div`,{className:`mt-3 rounded-xl bg-gray-100/60 p-3 dark:bg-dark-200/60`,children:(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:B})})]}),(0,X.jsx)(Ae,{content:V,isStreaming:t})]}),!c&&!l&&ie.length>0&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Fe,{artifacts:ie})}),!c&&!l&&e.statistics&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Re,{statistics:e.statistics})}),!l&&!t&&(0,X.jsxs)(`div`,{className:W(`mt-3 flex items-center gap-1`,c?`justify-end border-t border-white/10 pt-2 text-white/65`:`text-gray-400 dark:text-dark-500`),children:[!c&&V&&(0,X.jsx)(Ke,{text:V,size:`sm`,className:W(`transition-colors`,N&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),(0,X.jsx)(`button`,{onClick:ne,className:W(`flex h-8 w-8 items-center justify-center rounded-full transition-colors`,c?`hover:bg-white/10 hover:text-white`:`hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`),title:a(F?`chatMessage.copied`:`chatMessage.copyMessage`),children:F?(0,X.jsx)(ae,{className:`h-3.5 w-3.5 text-green-400`}):(0,X.jsx)(ee,{className:`h-3.5 w-3.5`})}),!c&&r&&i&&(0,X.jsx)(`button`,{onClick:i,className:`flex h-8 w-8 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:a(`chatMessage.regenerateResponse`),children:(0,X.jsx)(b,{className:`h-3.5 w-3.5`})})]})]})]})}),C&&(0,Le.createPortal)((0,X.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":a(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>w(null),children:[(0,X.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(),w(null)},children:(0,X.jsx)(z,{className:`h-7 w-7`})}),(0,X.jsx)(`img`,{src:C,alt:a(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Dt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Ot=220,kt=e=>{let t=e.slice(0,Ot*4).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>Ot?`${t.slice(0,Ot-1).trimEnd()}…`:t},At=Y.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Y.useRef)(null),a=(0,Y.useRef)(null),o=(0,Y.useRef)(new Map),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(0),f=(0,Y.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Y.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,Y.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:Dt()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,X.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% - 30rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,X.jsx)(`ol`,{ref:a,className:`pointer-events-auto grid h-full min-h-0 overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,style:{gridTemplateRows:`repeat(${e.length}, minmax(1.5rem, 1fr))`},children:e.map((t,a)=>{let s=t.id===h,u=c===t.id?v:void 0;return(0,X.jsx)(`li`,{className:`flex min-h-6 items-center`,children:(0,X.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":u,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:W(`group flex h-6 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,X.jsx)(`span`,{"aria-hidden":`true`,className:W(`block rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`h-0.5 w-6 bg-ink opacity-90 xl:w-7`:`h-px w-3 bg-line-strong opacity-75 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,X.jsxs)(`div`,{id:v,role:`tooltip`,className:W(`pointer-events-none absolute start-full ms-3 w-72 -translate-y-1/2`,`rounded-2xl border border-line bg-surface-overlay/95 p-4 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(6.5rem, ${u}px, calc(100% - 6.5rem))`},children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,X.jsxs)(`span`,{dir:`ltr`,className:`text-[10px] font-semibold uppercase tracking-[0.14em] text-ink-subtle`,children:[String(g+1).padStart(2,`0`),` /`,` `,String(e.length).padStart(2,`0`)]}),(0,X.jsx)(`span`,{className:`h-px flex-1 bg-line`,"aria-hidden":`true`})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`mb-1 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-subtle`,children:r(`chatMessage.you`)}),(0,X.jsx)(`p`,{dir:`auto`,className:`line-clamp-2 text-sm font-medium leading-5 text-ink`,children:kt(_.prompt)})]}),_.response&&(0,X.jsxs)(`div`,{className:`border-t border-line pt-3`,children:[(0,X.jsx)(`p`,{className:`mb-1 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-subtle`,children:r(`chatMessage.assistant`)}),(0,X.jsx)(`p`,{dir:`auto`,className:`line-clamp-2 text-xs leading-5 text-ink-muted`,children:kt(_.response)})]})]})]})]})}),jt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingMessageId:r,isLastAssistantMessage:i=!1,onRegenerate:a,onSelectBranch:o,className:s})=>{if(e.length===1){let o=e[0],c=t&&r===o.id;return(0,X.jsx)(Et,{message:c&&n?{...o,content:n}:o,isStreaming:c,isLastAssistantMessage:i,onRegenerate:a,className:s})}return(0,X.jsxs)(`div`,{className:W(`relative py-2`,s),children:[(0,X.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,X.jsx)(_,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let c=e.isActive!==!1,l=t&&r===e.id,u=l&&n?{...e,content:n}:e;return(0,X.jsxs)(`div`,{className:W(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,c||l?`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`,!c&&!l&&`cursor-pointer`),role:!c&&!l?`button`:void 0,tabIndex:!c&&!l?0:void 0,onClick:()=>!c&&!l&&o?.(e.id),onKeyDown:t=>{!c&&!l&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),o?.(e.id))},children:[(0,X.jsxs)(`div`,{className:W(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,c||l?`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,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:s+1}),l&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),c&&!l&&(0,X.jsx)(ae,{className:`h-3 w-3`}),!c&&!l&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,X.jsx)(`div`,{className:W(!c&&!l&&`opacity-75`),children:(0,X.jsx)(Et,{message:u,isStreaming:l,isLastAssistantMessage:i&&(c||l),onRegenerate:c&&!t?a:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Mt={web_search:y,web_fetch:T,exec:M,browser:T,Read:I,Write:I,Edit:I,image:w,memory_search:N,memory_get:N,working:te,thinking:te,default:te},Nt={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`},Pt=({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,X.jsx)(`div`,{className:W(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Mt[e.name]||Mt.default,n=Nt[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,X.jsxs)(`div`,{className:W(`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,X.jsx)(`div`,{className:W(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,X.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,X.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};H(`components:chat-messages`);var Ft=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],It=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,Lt=e=>Math.min(120,e*.28),Rt=({messages:e,streamingMessage:t,streamingMessageId:n,isStreaming:r=!1,toolActivities:i=[],className:a,onRegenerate:o,onSelectBranch:c})=>{let{t:l}=s(),u=(0,Y.useRef)(null),d=(0,Y.useRef)(void 0),f=(0,Y.useRef)(null),p=(0,Y.useRef)(null),m=(0,Y.useRef)(new Map),h=(0,Y.useRef)(null),g=(0,Y.useRef)(0),_=(0,Y.useRef)(!1),y=(0,Y.useRef)(!1),[b,x]=(0,Y.useState)(!1),S=(0,Y.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),C=(0,Y.useMemo)(()=>{let e=[];for(let t=0;t<S.length;t++){let n=S[t],r=Ft(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<S.length;e++){let t=Ft(S[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},[S]),w=C.map(e=>e.id).join(``),T=(0,Y.useMemo)(()=>w?w.split(``):[],[w]),E=(0,Y.useMemo)(()=>new Set(T),[T]),[D,O]=(0,Y.useState)(null),k=(0,Y.useCallback)(()=>{let e=f.current;if(!e||T.length===0){O(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(g.current,T.length-1);if(t<=2)n=T.length-1;else{let t=e.scrollTop+Lt(e.clientHeight);for(;n<T.length-1;){let e=m.current.get(T[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=m.current.get(T[n]);if(!e||e.offsetTop<=t)break;n--}}g.current=n;let r=T[n];O(e=>e===r?e:r)},[T]),A=(0,Y.useCallback)(()=>{h.current===null&&(h.current=window.requestAnimationFrame(()=>{h.current=null,k()}))},[k]),j=(0,Y.useCallback)(()=>{let t=f.current;if(d.current&&clearTimeout(d.current),_.current=!1,d.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;y.current=!n,x(!n&&e.length>0),A()},[e.length,A]),M=(0,Y.useCallback)(()=>{d.current&&clearTimeout(d.current),d.current=setTimeout(j,180)},[j]),N=(0,Y.useCallback)((e=!1)=>{y.current&&!e||u.current?.scrollIntoView({behavior:It()})},[]),P=(0,Y.useCallback)(()=>{let t=f.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(_.current){y.current=!0,x(!o&&e.length>0),A(),M();return}y.current=!o,x(!o&&e.length>0),a<=2&&T.length>0?(g.current=T.length-1,O(T[T.length-1])):A()},[T,e.length,M,A]),F=(0,Y.useCallback)(e=>{let t=f.current,n=m.current.get(e);if(!t||!n)return;let r=It();_.current=!0,y.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-Lt(t.clientHeight)),behavior:r}),A(),r===`auto`?j():M()},[j,M,A]),I=(0,Y.useRef)(e.length);if((0,Y.useEffect)(()=>{e.length>I.current&&!y.current&&N(),I.current=e.length},[e.length,N]),(0,Y.useEffect)(()=>{r&&t&&!y.current&&requestAnimationFrame(()=>{let e=f.current;e&&(e.scrollTop=e.scrollHeight)})},[r,t]),(0,Y.useEffect)(()=>{A();let e=p.current,t=f.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(A);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,A),()=>{n?.disconnect(),window.removeEventListener(`resize`,A)}},[w,A]),(0,Y.useEffect)(()=>()=>{h.current!==null&&(window.cancelAnimationFrame(h.current),h.current=null)},[]),(0,Y.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]),e.length===0&&!r)return(0,X.jsx)(`div`,{className:W(`flex-1 flex items-center justify-center p-6 sm:p-10`,a),children:(0,X.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,X.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,X.jsx)(v,{className:`h-4 w-4`})}),(0,X.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:l(`chatMessage.startConversation`)}),(0,X.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:l(`chatMessage.startConversationDescription`)})]})});let R=-1;for(let e=S.length-1;e>=0;e--)if(S[e].messages.some(e=>e.role===`assistant`)){R=e;break}return(0,X.jsxs)(`div`,{className:W(`relative min-h-0 flex-1`,a),style:{WebkitAppRegion:`no-drag`},children:[(0,X.jsx)(`div`,{ref:f,"data-testid":`chat-scroll-viewport`,onScroll:P,className:W(`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,X.jsxs)(`div`,{ref:p,className:`mx-auto w-full min-w-0 max-w-4xl px-4 sm:px-6 md:px-8`,children:[S.map((e,i)=>{let a=i===R,s=E.has(e.id),l=r&&e.messages.some(e=>e.id===n),u;if(e.messages.length===1){let s=e.messages[0],c=r&&s.id===n;u=(0,X.jsx)(Et,{message:c&&t?{...s,content:t}:s,isStreaming:c,isLastAssistantMessage:a,onRegenerate:a?o:void 0,className:i===0?`mt-5 sm:mt-7`:``})}else u=(0,X.jsx)(jt,{messages:e.messages,isStreaming:l,streamingMessage:t,streamingMessageId:n||void 0,isLastAssistantMessage:a,onRegenerate:a?o:void 0,onSelectBranch:c,className:i===0?`mt-5 sm:mt-7`:``});return(0,X.jsx)(`div`,{ref:t=>{s&&(t?m.current.set(e.id,t):m.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:u},e.id)}),r&&i.length>0&&(0,X.jsx)(Pt,{tools:i,className:`px-0`}),(0,X.jsx)(`div`,{ref:u,className:`h-4 sm:h-6`})]})}),(0,X.jsx)(At,{items:C,activeId:D,onSelect:F}),b&&(0,X.jsxs)(`button`,{onClick:()=>{_.current=!1,d.current&&(clearTimeout(d.current),d.current=void 0),y.current=!1,u.current?.scrollIntoView({behavior:It()}),x(!1)},className:W(`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:l(`chatMessage.scrollToBottom`),children:[(0,X.jsx)(L,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:l(`chatMessage.newMessages`)})]})]})};function zt(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 Bt=Y.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,Y.useMemo)(()=>zt(e),[e]);return(0,X.jsxs)(`div`,{className:`relative w-full`,children:[(0,X.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:W(`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,X.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,X.jsxs)(`div`,{className:W(`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,X.jsx)(m,{className:`h-3 w-3`}),d&&(0,X.jsx)(`span`,{children:d}),!d&&u&&(0,X.jsx)(`span`,{children:`code`})]})})]})});Bt.displayName=`CodeAwareTextarea`;var Vt=H(`components:media-upload`),Ht=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)([]),g=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await v(n):E.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){E.error(`Maximum ${n} images allowed`);return}if(r.size>10*1024*1024){E.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},v=async e=>{if(e.size>10*1024*1024){E.error(`File size must be less than 10MB`);return}p(!0);try{let t=await ce.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),E.success(`Document "${e.name}" uploaded`)}else E.error(t.error||`Failed to upload document`)}catch(e){Vt.error(`Document upload error:`,e),E.error(`Failed to upload document`)}finally{p(!1)}},y=e=>{e.preventDefault(),a||d(!0)},b=e=>{e.preventDefault(),d(!1)},x=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},w=async e=>{try{let t=await ce.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),E.success(`Document removed`)):E.error(t.error||`Failed to remove document`)}catch(e){Vt.error(`Error removing document:`,e),E.error(`Failed to remove document`)}},T=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},D=e.length>0||m.length>0;return(0,X.jsxs)(`div`,{className:W(`space-y-3`,o),children:[(0,X.jsxs)(`div`,{className:W(`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:y,onDragLeave:b,onDrop:x,onClick:()=>!a&&l.current?.click(),children:[(0,X.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,X.jsx)(C,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,X.jsx)(j,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),D&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,X.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,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),S(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,X.jsx)(z,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,X.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,X.jsx)(I,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,X.jsx)(ne,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,X.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:T(e.size)})]}),(0,X.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,X.jsx)(z,{className:`h-3 w-3`})})]},e.id))]})]})},Ut=H(`components:document-indicator`),Wt=({sessionId:e,className:t=``})=>{let[n,r]=(0,Y.useState)([]);if((0,Y.useEffect)(()=>{e&&(async()=>{try{let t=await ce.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){Ut.error(`Failed to load documents:`,e)}})()},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,X.jsxs)(`div`,{className:`
4
4
  inline-flex items-center space-x-1 px-2 py-1
5
5
  bg-blue-50 dark:bg-blue-900/20
6
6
  border border-blue-200 dark:border-blue-800
7
7
  rounded-md text-xs
8
8
  ${t}
9
- `,title:`${n.length} document(s) available for context - Total: ${(e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]})(i)}`,children:[(0,X.jsx)(h,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,X.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},Gt=H(`components:structured-output`),Kt=[{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`}],qt=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(``),l=()=>Kt.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,X.jsxs)(`div`,{className:W(`space-y-3`,n),children:[(0,X.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,X.jsxs)(`div`,{className:`flex items-center`,children:[(0,X.jsx)(re,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,X.jsx)(Me,{value:u().label,onChange:e=>d(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u().description}),i&&(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(we,{value:o,onChange:e=>c(e.target.value),placeholder:`{
9
+ `,title:`${n.length} document(s) available for context - Total: ${(e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]})(i)}`,children:[(0,X.jsx)(h,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,X.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},Gt=H(`components:structured-output`),Kt=[{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`}],qt=({format:e,onFormatChange:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Y.useState)(!1),[o,c]=(0,Y.useState)(``),l=()=>Kt.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,X.jsxs)(`div`,{className:W(`space-y-3`,n),children:[(0,X.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,X.jsxs)(`div`,{className:`flex items-center`,children:[(0,X.jsx)(re,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,X.jsx)(Me,{value:u().label,onChange:e=>d(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u().description}),i&&(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(Ce,{value:o,onChange:e=>c(e.target.value),placeholder:`{
10
10
  "type": "object",
11
11
  "properties": {
12
12
  "field1": { "type": "string" },
13
13
  "field2": { "type": "number" }
14
14
  },
15
15
  "required": ["field1"]
16
- }`,rows:8,className:`font-mono text-sm`}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(G,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){Gt.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,X.jsx)(G,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=u();return!e.value||e.value===`json`?null:(0,X.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,X.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,X.jsx)(R,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,X.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,X.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,X.jsx)(I,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},Jt=H(`components:chat-input`),Yt=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r}=s(),[i,a]=(0,Y.useState)(``),[o,c]=(0,Y.useState)([]),[u,d]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(!1),[h,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(!1),{isGenerating:b,setBackgroundImage:x}=K(),S=K(e=>e.preferences.imageGenSettings?.enabled===!0),C=S&&v,{currentSession:w,models:T}=q(),E=(0,Y.useRef)(null),O=(0,Y.useMemo)(()=>({model:w?.personaId?`persona:${w.personaId}`:w?.model||``,providerType:w?.providerType,providerId:w?.providerId}),[w?.model,w?.personaId,w?.providerId,w?.providerType]),k=(0,Y.useMemo)(()=>Oe(T,O),[T,O]),A=O.model?Se(k,O):``,j=ke(T,O);(0,Y.useEffect)(()=>{let e=!1;return S&&(async()=>{try{let t=await pe.getPlugins();if(e)return;y(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;y(!1)}})(),()=>{e=!0}},[S]);let M=t=>{if(t.preventDefault(),!(!i.trim()||b)){if(!j){D.error(`Select an available model before sending`);return}e(i.trim(),o.length>0?o:void 0,u||void 0),a(``),c([])}},N=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),M(e))},F=()=>{t()};(0,Y.useEffect)(()=>{let e=E.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[i]),(0,Y.useEffect)(()=>{(async()=>{if(w?.personaId)try{let e=await fe.getPersona(w.personaId);if(e.success&&e.data)_(e.data);else{Jt.warn(`Persona ${w.personaId} not found, clearing reference`),_(null);let{setCurrentSession:e}=q.getState();e({...w,personaId:void 0})}}catch(e){if(Jt.error(`Failed to load current persona:`,e),_(null),w){let{setCurrentSession:e}=q.getState();e({...w,personaId:void 0})}}else _(null)})()},[w?.personaId]);let I=async e=>{let t=De(k,e.target.value);if(t&&w)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await fe.getPersona(e);if(!n.success||!n.data){D.error(`Failed to load persona details`);return}let i=n.data,a=await le.updateSession(w.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(a.success&&a.data){let{sessions:e}=q.getState(),t=e.map(e=>e.id===w.id?a.data:e);q.setState({sessions:t,currentSession:a.data}),i.background&&x(i.background),D.success(r(`chat.persona.applied`))}}else{let e=await le.updateSession(w.id,{model:t.model,providerType:t.providerType,providerId:t.providerType===`plugin`&&t.providerId||null,personaId:null});if(e.success&&e.data){let{sessions:t}=q.getState(),n=t.map(t=>t.id===w.id?e.data:t);q.setState({sessions:n,currentSession:e.data}),x(null),D.success(r(`chat.model.updated`))}}}catch(e){Jt.error(`Failed to update session:`,e),D.error(`Failed to update session`)}},L=o.length>0||u!==null;return(0,X.jsx)(`div`,{className:`pointer-events-none`,children:(0,X.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-4xl px-4 sm:px-6 md:px-8`,children:[p&&(0,X.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,X.jsx)(Ht,{images:o,onImagesChange:c,maxImages:5,sessionId:w?.id,disabled:n}),(0,X.jsx)(qt,{format:u,onFormatChange:d})]}),(0,X.jsxs)(`div`,{className:`pb-3 pt-2 sm:pb-4`,children:[(0,X.jsx)(`form`,{onSubmit:M,children:(0,X.jsxs)(`div`,{className:W(`flex items-end gap-2 rounded-[1.55rem] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200 sm:p-3`,`bg-surface/[0.92] dark:bg-dark-200/[0.92] backdrop-blur-xl`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_14px_42px_rgba(15,23,42,0.08)]`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_52px_rgba(15,23,42,0.11)]`),children:[(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(!p),className:W(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,L&&`text-primary-600 dark:text-primary-400`,p&&`bg-gray-100 dark:bg-dark-300`),title:r(`chat.input.attachments`),children:L?(0,X.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,X.jsx)(l,{className:`h-4 w-4`}),(0,X.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`})]}):p?(0,X.jsx)(g,{className:`h-4 w-4`}):(0,X.jsx)(f,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,X.jsx)(Bt,{ref:E,value:i,onChange:e=>a(e.target.value),onKeyDown:N,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!m-0 min-h-[40px] max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !p-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-base leading-relaxed touch-manipulation`,rows:1})}),(0,X.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1 sm:gap-2`,children:[w&&k.length>0&&(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)(Ie,{models:k,selectedModel:A,onModelChange:I,getModelValue:Ee,currentPersona:h,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:C})}),b?(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:F,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.stopGeneration`),children:(0,X.jsx)(P,{className:`h-4 w-4`})}):(0,X.jsx)(G,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!i.trim()||n||!j,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-100 text-gray-400 dark:bg-dark-300 dark:text-dark-500`,`disabled:cursor-not-allowed disabled:opacity-70`,`transition-colors duration-150 touch-manipulation`,i.trim()&&!n&&j&&[`bg-gray-950 text-white hover:bg-gray-800`,`dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`shadow-sm`]),title:r(`chat.input.sendMessage`),children:(0,X.jsx)(ie,{className:`h-4 w-4`})})]})]})}),w&&k.length>0&&(0,X.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,X.jsx)(Ie,{models:k,selectedModel:A,onModelChange:I,getModelValue:Ee,currentPersona:h,className:`w-full`,compact:!0,showImageGen:C})}),(0,X.jsxs)(`div`,{className:`mt-2 flex min-h-4 items-center justify-center gap-2 text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,X.jsx)(Wt,{sessionId:w?.id}),(0,X.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,X.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),L&&(0,X.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,o.length>0&&r(`chat.footer.images`,{count:o.length}),o.length>0&&u&&` • `,u&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},Xt=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(null),[o,s]=(0,Y.useState)({top:0,left:0});(0,Y.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=()=>he(e,64),u=t=>{ue(t.currentTarget,e.name,64)};return(0,X.jsxs)(`div`,{className:W(`relative`,n),children:[(0,X.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:W(`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,X.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:u}),(0,X.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,X.jsx)(v,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,X.jsx)(A,{className:W(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Le.createPortal)((0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,X.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,X.jsxs)(`div`,{className:W(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,X.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,X.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,X.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,X.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,X.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,X.jsx)(z,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,X.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,X.jsx)(x,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,X.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,X.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,X.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,X.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,X.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,X.jsx)(oe,{className:`h-3 w-3`}),e.model]}),e.description&&(0,X.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,X.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,X.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,X.jsx)(p,{className:`h-2.5 w-2.5 text-gray-400`}),(0,X.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,X.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,X.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,X.jsx)(B,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,X.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,X.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,X.jsx)(x,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},Zt=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Y.useRef)(null),[o,c]=(0,Y.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/`)){E.error(`File ${o.name} is not an image`);continue}if(o.size>10*1024*1024){E.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&&E.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),c(!0)},d=e=>{e.preventDefault(),c(!1)},f=e=>{e.preventDefault(),c(!1),l(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},m=e.length<n;return(0,X.jsxs)(`div`,{className:W(`space-y-3`,r),children:[m&&(0,X.jsxs)(`div`,{className:W(`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,X.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,X.jsx)(j,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,X.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,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.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,X.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,X.jsx)(z,{className:`h-4 w-4`})})})]},t))}),m&&e.length>0&&(0,X.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,X.jsx)(w,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},$=H(`use-chat`),Qt=new Set([`New Chat`,`New Demo Session`]),$t=e=>!e||Qt.has(e),en=e=>{let[t,n]=(0,Y.useState)(``),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)([]),{addMessage:l,updateMessage:u,updateMessageWithStatistics:d,applySessionTitle:f,setGeneratingTitleForSession:p}=q(),{setIsGenerating:m,preferences:h}=K(),g=(0,Y.useRef)(null),_=(0,Y.useRef)(null),v=(0,Y.useRef)(!1),y=(0,Y.useRef)(null),b=(0,Y.useRef)(``),x=(0,Y.useRef)(0),S=(0,Y.useRef)(void 0),C=(0,Y.useRef)(null),w=(0,Y.useRef)(``),T=(0,Y.useCallback)(()=>{C.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(C.current),C.current=null},[]),D=(0,Y.useCallback)((e,t=!1)=>{if(w.current=e,t||typeof window>`u`){T(),n(e);return}C.current===null&&(C.current=window.requestAnimationFrame(()=>{C.current=null,n(w.current)}))},[T]),O=(0,Y.useCallback)(()=>{T(),w.current=``,n(``)},[T]),k=(0,Y.useCallback)(()=>{_.current=null,v.current=!1,y.current=null},[]),A=(0,Y.useCallback)(async e=>{let t=K.getState().preferences.titleSettings,n=_.current,r=v.current&&y.current===e;if($.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),!n||!r||!t?.autoTitle||!t?.taskModel){k();return}k(),$.debug(`Triggering auto-title generation...`),p(e);try{let r=await le.generateTitle(e,t.taskModel,n,t.taskProviderType,t.taskProviderId);if($.debug(`Title generation response:`,r),!r.success||!r.data?.title)throw Error(r.error||`Title generation returned no title`);f(e,r.data.title,r.data.updatedAt),r.data.source===`fallback`?E.error(`Could not generate a title; using the message preview`):E.success(`Chat title generated`)}catch(e){$.error(`Failed to generate title:`,e),E.error(`Failed to generate chat title`)}finally{p(null)}},[f,k,p]);return(0,Y.useEffect)(()=>()=>{J.offMessage(`user_message`),J.offMessage(`assistant_chunk`),J.offMessage(`assistant_complete`),J.offMessage(`tool_status`),J.offMessage(`error`)},[e]),(0,Y.useEffect)(()=>{if(!e){J.offMessage(`user_message`),J.offMessage(`assistant_chunk`),J.offMessage(`assistant_complete`),J.offMessage(`tool_status`),J.offMessage(`error`);return}return J.onMessage(`user_message`,()=>{}),J.onMessage(`assistant_chunk`,t=>{let n=t,r=n.messageId||g.current;r&&(b.current=n.total,D(n.total,n.done),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{u(e,r,b.current),x.current=Date.now()},n.done?0:200))}),J.onMessage(`tool_status`,e=>{let t=e;c(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),J.onMessage(`assistant_complete`,t=>{let n=t;$.debug(`Hook: Received assistant_complete for session:`,e,`messageId:`,n.messageId,`with statistics:`,!!n.statistics),o(!1),O(),m(!1),c([]);let r=n.messageId||g.current;n&&r&&d(e,r,b.current||n.content,n.statistics,n.providerMetadata),A(e),g.current=null,b.current=``,S.current&&clearTimeout(S.current),x.current=0}),J.onMessage(`error`,e=>{let t=e;if(o(!1),O(),m(!1),g.current=null,t.code===`SESSION_NOT_FOUND`){$.warn(`Session not found, redirecting to create new session...`),E.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}E.error(t.error),k()}),o(!1),O(),g.current=null,()=>{S.current&&clearTimeout(S.current),T()}},[e,u,d,m,D,O,T,A,k]),{sendMessage:(0,Y.useCallback)(async(t,n,r)=>{if(!(!e||!t.trim()&&(!n||n.length===0)))try{let a=q.getState(),s=a.currentSession,c={model:s?.personaId?`persona:${s.personaId}`:s?.model||``,providerType:s?.providerType,providerId:s?.providerId};if(!ke(a.models,c)){E.error(`Select an available model before sending`);return}m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let d=s?.isPrivate===!0,f=s?.messages?.some(e=>e.role===`user`);!d&&!f&&$t(s?.title)?(_.current=t.trim(),v.current=!0,y.current=e):(_.current=null,v.current=!1,y.current=null),l(e,{role:`user`,content:t.trim(),images:n});let p=ve();if(g.current=p,i(p),l(e,{role:`assistant`,content:``,id:p}),se()){let n=`Demo response for: ${t.trim()}`;window.setTimeout(()=>{u(e,p,n),o(!1),O(),i(null),m(!1),A(e),g.current=null,b.current=``},500);return}J.isConnected||await J.connect();let C=d?s?.messages?.filter(e=>e.role!==`system`&&e.id!==p).map(e=>({role:e.role,content:e.content,images:e.images,providerMetadata:e.providerMetadata})):void 0;J.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:n,format:r,options:h.generationOptions,assistantMessageId:p,isPrivate:d,...d?{model:s?.model,providerType:s?.providerType,providerId:s?.providerId,messageHistory:C}:{}}})}catch(e){$.error(`Failed to send message:`,e),o(!1),O(),i(null),m(!1),g.current=null,E.error(`Failed to send message`)}},[e,l,u,m,O,A,h.generationOptions]),stopGeneration:(0,Y.useCallback)(()=>{o(!1),O(),i(null),m(!1),g.current=null},[m,O]),regenerateLastMessage:(0,Y.useCallback)(async()=>{let t=q.getState(),n=t.currentSession;if(!n||!e)return;if(!ke(t.models,{model:n.personaId?`persona:${n.personaId}`:n.model,providerType:n.providerType,providerId:n.providerId})){E.error(`Select an available model before regenerating`);return}let r=n.messages,a=-1,s=-1;for(let e=r.length-1;e>=0;e--)if(r[e].role===`assistant`){s=e;break}if(s>0){for(let e=s-1;e>=0;e--)if(r[e].role===`user`){a=e;break}}if(a===-1||s===-1){E.error(`No message to regenerate`);return}let c=r[a],u=r[s];try{m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let t=ve();g.current=t,i(t),l(e,{role:`assistant`,content:``,id:t,parentId:u.parentId||u.id,branchIndex:u.siblingCount||1,isActive:!0}),J.isConnected||await J.connect();let a=n.isPrivate===!0,s=a?r.filter(e=>e.role!==`system`).map(e=>({role:e.role,content:e.content,images:e.images,providerMetadata:e.providerMetadata})):void 0;J.send({type:`chat_stream`,data:{sessionId:e,content:c.content,images:c.images,options:h.generationOptions,assistantMessageId:t,regenerate:!0,originalMessageId:u.id,isPrivate:a,...a?{model:n.model,providerType:n.providerType,providerId:n.providerId,messageHistory:s}:{}}})}catch(e){$.error(`Failed to regenerate message:`,e),o(!1),O(),i(null),m(!1),g.current=null,E.error(`Failed to regenerate message`)}},[e,m,O,l,h.generationOptions]),selectBranch:(0,Y.useCallback)(async t=>{let n=q.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){E.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await le.switchMessageBranch(e,t,a);if(r.success&&r.data){let r=n.messages.map(e=>e.id===i||e.parentId===i?{...e,isActive:e.id===t}:e),o={...n,messages:r,updatedAt:Date.now()};q.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),E.success(`Switched to variant ${a+1}`)}else E.error(r.error||`Failed to select branch`)}catch(e){$.error(`Failed to select branch:`,e),E.error(`Failed to select branch`)}},[e]),isStreaming:a,streamingMessage:t,streamingMessageId:r,toolActivities:s}},tn=H(`pages:chat-page`),nn=(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?`}},rn=(e,t,n,r=!1)=>{let i=Te(e);return i===`time`?nn(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.`}},an=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),u=o(),{currentSession:d,sessions:p,models:m,selectedModel:h,selectedProviderType:_,selectedProviderId:v,setSelectedModel:y,createSession:b,setCurrentSession:x,loadSessions:S,getCurrentPersona:C}=q(),{user:w}=Ce(),T=K(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:D,stopGeneration:O,regenerateLastMessage:k,selectBranch:A,isStreaming:j,streamingMessage:M,streamingMessageId:N,toolActivities:P}=en(d?.id||``),F=C(),I=(0,Y.useMemo)(()=>({model:h,providerType:_,providerId:v}),[h,v,_]),L=(0,Y.useMemo)(()=>Oe(m,I),[m,I]),R=h?Se(L,I):``,z=ke(m,I),[ee,te]=(0,Y.useState)(be),ne=(0,Y.useMemo)(()=>rn(ee,w?.username,e,ye(t.language)),[t.language,e,w?.username,ee]),[B,re]=(0,Y.useState)(``),[V,ae]=(0,Y.useState)([]),[oe,se]=(0,Y.useState)(!1),H=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=()=>{te(be())};return window.addEventListener(je,e),()=>window.removeEventListener(je,e)},[]);let[ce,U]=(0,Y.useState)(!1),ue=T&&ce;(0,Y.useEffect)(()=>{p.length===0&&S()},[S,p.length]),(0,Y.useEffect)(()=>{let e=!1;return T&&(async()=>{try{let t=await pe.getPlugins();if(e)return;U(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;U(!1)}})(),()=>{e=!0}},[T]),(0,Y.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!d?.isPrivate&&p.length!==0)if(n){let e=p.find(e=>e.id===n);e&&e.id!==d?.id?x(e):e||(tn.warn(`Session ${n} not found for current user, redirecting...`),p.length>0?r(`/c/${p[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&p.length>0&&u.pathname===`/`&&r(`/c/${p[0].id}`,{replace:!0})})()},[n,p,x,r,d?.id,d?.isPrivate,u.pathname]),(0,Y.useEffect)(()=>{if(d?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{D(t.content,t.images)},100)}catch(e){tn.error(`Failed to parse pending message:`,e)}}}},[d?.id,D]),(0,Y.useEffect)(()=>{let e=H.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[B]);let de=async e=>{if(e.preventDefault(),!B.trim()||!h)return;if(!z){E.error(`Select an available model before sending`);return}let t={content:B.trim(),images:V.length>0?V:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(t)),re(``),ae([]);let n=await b(h,void 0,h.startsWith(`persona:`)?h.slice(8):void 0,_,v);n&&r(`/c/${n.id}`,{replace:!0})},fe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),de(e))},me=async e=>{let t=De(L,e.target.value);t&&y(t.model,t.providerType,t.providerId)},he=(e,t,n)=>{d&&D(e,t,n)};if(!d){let t=V.length>0;return(0,X.jsxs)(`div`,{className:`relative h-full flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,X.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,X.jsx)(`div`,{className:`absolute left-[12%] top-[18%] h-56 w-56 rounded-full bg-primary-500/[0.035] blur-3xl dark:bg-primary-400/[0.04]`}),(0,X.jsx)(`div`,{className:`absolute bottom-[16%] right-[10%] h-72 w-72 rounded-full bg-gray-900/[0.025] blur-3xl dark:bg-white/[0.025]`}),(0,X.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,X.jsxs)(`button`,{onClick:()=>{if(!h&&m.length===0)return;let t=Date.now(),n=h?I:m[0]?xe(m[0]):null;if(!n||!ke(m,n)){E.error(`Select an available model before starting private chat`);return}x({id:`private-${t}`,title:e(`chat.session.private`),model:n.model,providerType:n.providerType,providerId:n.providerId,messages:[],createdAt:t,updatedAt:t,isPrivate:!0})},disabled:!h&&m.length===0||!!h&&!z,className:`absolute end-4 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-6 sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,X.jsx)(c,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:e(`chat.session.private`)})]}),(0,X.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,X.jsxs)(`div`,{className:`mb-10 flex flex-col items-center text-center animate-fade-in sm:mb-12`,"aria-live":`polite`,children:[(0,X.jsx)(`h1`,{className:`mb-4 max-w-3xl text-balance text-[clamp(2.65rem,7vw,5.25rem)] font-light leading-[0.98] tracking-[-0.055em] text-gray-950 dark:text-dark-950 rtl:leading-[1.12] rtl:tracking-normal`,children:ne.title}),(0,X.jsx)(`p`,{className:`max-w-xl text-balance text-base leading-relaxed text-gray-500 dark:text-dark-600 sm:text-lg`,children:ne.subtitle})]},ne.id),L.length>0?(0,X.jsxs)(`div`,{className:`w-full`,children:[oe&&(0,X.jsx)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:(0,X.jsx)(Zt,{images:V,onImagesChange:ae,maxImages:5})}),(0,X.jsx)(`form`,{onSubmit:de,children:(0,X.jsxs)(`div`,{className:W(`flex items-end gap-2 rounded-[1.6rem] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200 sm:p-3`,`border-black/[0.08] bg-surface/90 dark:border-white/[0.09] dark:bg-dark-200/90`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_50px_rgba(15,23,42,0.08)] backdrop-blur-xl`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_22px_65px_rgba(15,23,42,0.12)]`),children:[(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>se(!oe),className:W(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300 transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,oe&&`bg-gray-100 dark:bg-dark-300`),title:e(`chat.input.attachImages`),children:t?(0,X.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,X.jsx)(l,{className:`h-4 w-4`}),(0,X.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):oe?(0,X.jsx)(g,{className:`h-4 w-4`}):(0,X.jsx)(f,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,X.jsx)(Bt,{ref:H,value:B,onChange:e=>re(e.target.value),onKeyDown:fe,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 min-h-[40px] max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !p-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-base leading-relaxed touch-manipulation`,rows:1})}),(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)(Ie,{models:L,selectedModel:R,onModelChange:me,getModelValue:Ee,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:ue})}),(0,X.jsx)(G,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!B.trim()||!h||!z,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-950 text-white hover:bg-gray-800 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`disabled:bg-gray-100 disabled:text-gray-400 dark:disabled:bg-dark-300 dark:disabled:text-dark-500 disabled:hover:bg-gray-100 dark:disabled:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,B.trim()&&h&&`shadow-sm`),title:e(`chat.input.sendMessage`),children:(0,X.jsx)(ie,{className:`h-4 w-4`})})]})}),(0,X.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,X.jsx)(Ie,{models:L,selectedModel:R,onModelChange:me,getModelValue:Ee,className:`w-full`,compact:!0,showImageGen:ue})}),(0,X.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,X.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,X.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.07] bg-surface/70 p-6 backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/70`,children:[(0,X.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,X.jsx)(`code`,{className:`block rounded-xl bg-gray-100 p-3 font-mono text-xs text-gray-800 dark:bg-dark-300 dark:text-dark-700`,children:e(`chat.model.pullCommand`)})]})})]})]})}return(0,X.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:F?.background?{backgroundImage:`url(${F.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[F?.background&&(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,X.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[d?.isPrivate&&(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,X.jsx)(c,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,X.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),F&&!d?.isPrivate&&(0,X.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,X.jsx)(Xt,{persona:F,onClear:()=>{d&&le.updateSession(d.id,{model:F.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);q.setState(t=>({sessions:t.sessions.map(t=>t.id===d.id?e.data:t),currentSession:e.data}))}).catch(e=>{tn.error(`Failed to remove persona:`,e),E.error(`Failed to remove persona`)})}})}),(0,X.jsx)(Rt,{messages:d.messages,streamingMessage:M,streamingMessageId:N,isStreaming:j,toolActivities:P,onRegenerate:k,onSelectBranch:A,className:`flex-1`}),(0,X.jsx)(Yt,{onSendMessage:he,onStopGeneration:O,disabled:!d})]})]})};export{an as ChatPage,an as default};
16
+ }`,rows:8,className:`font-mono text-sm`}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(G,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){Gt.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,X.jsx)(G,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=u();return!e.value||e.value===`json`?null:(0,X.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,X.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,X.jsx)(R,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,X.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,X.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,X.jsx)(I,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})},Jt=H(`components:chat-input`),Yt=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r}=s(),[i,a]=(0,Y.useState)(``),[o,c]=(0,Y.useState)([]),[u,d]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(!1),[h,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(!1),{isGenerating:b,setBackgroundImage:x}=K(),S=K(e=>e.preferences.imageGenSettings?.enabled===!0),C=S&&v,{currentSession:w,models:T}=q(),E=(0,Y.useRef)(null),O=(0,Y.useMemo)(()=>({model:w?.personaId?`persona:${w.personaId}`:w?.model||``,providerType:w?.providerType,providerId:w?.providerId}),[w?.model,w?.personaId,w?.providerId,w?.providerType]),k=(0,Y.useMemo)(()=>De(T,O),[T,O]),A=O.model?xe(k,O):``,j=Oe(T,O);(0,Y.useEffect)(()=>{let e=!1;return S&&(async()=>{try{let t=await pe.getPlugins();if(e)return;y(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;y(!1)}})(),()=>{e=!0}},[S]);let M=t=>{if(t.preventDefault(),!(!i.trim()||b)){if(!j){D.error(`Select an available model before sending`);return}e(i.trim(),o.length>0?o:void 0,u||void 0),a(``),c([])}},N=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),M(e))},F=()=>{t()};(0,Y.useEffect)(()=>{let e=E.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[i]),(0,Y.useEffect)(()=>{(async()=>{if(w?.personaId)try{let e=await fe.getPersona(w.personaId);if(e.success&&e.data)_(e.data);else{Jt.warn(`Persona ${w.personaId} not found, clearing reference`),_(null);let{setCurrentSession:e}=q.getState();e({...w,personaId:void 0})}}catch(e){if(Jt.error(`Failed to load current persona:`,e),_(null),w){let{setCurrentSession:e}=q.getState();e({...w,personaId:void 0})}}else _(null)})()},[w?.personaId]);let I=async e=>{let t=Ee(k,e.target.value);if(t&&w)try{if(t.model.startsWith(`persona:`)){let e=t.model.slice(8),n=await fe.getPersona(e);if(!n.success||!n.data){D.error(`Failed to load persona details`);return}let i=n.data,a=await le.updateSession(w.id,{personaId:e,model:t.model,providerType:`ollama`,providerId:null});if(a.success&&a.data){let{sessions:e}=q.getState(),t=e.map(e=>e.id===w.id?a.data:e);q.setState({sessions:t,currentSession:a.data}),i.background&&x(i.background),D.success(r(`chat.persona.applied`))}}else{let e=await le.updateSession(w.id,{model:t.model,providerType:t.providerType,providerId:t.providerType===`plugin`&&t.providerId||null,personaId:null});if(e.success&&e.data){let{sessions:t}=q.getState(),n=t.map(t=>t.id===w.id?e.data:t);q.setState({sessions:n,currentSession:e.data}),x(null),D.success(r(`chat.model.updated`))}}}catch(e){Jt.error(`Failed to update session:`,e),D.error(`Failed to update session`)}},L=o.length>0||u!==null;return(0,X.jsx)(`div`,{className:`pointer-events-none`,children:(0,X.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-4xl px-4 sm:px-6 md:px-8`,children:[p&&(0,X.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,X.jsx)(Ht,{images:o,onImagesChange:c,maxImages:5,sessionId:w?.id,disabled:n}),(0,X.jsx)(qt,{format:u,onFormatChange:d})]}),(0,X.jsxs)(`div`,{className:`pb-3 pt-2 sm:pb-4`,children:[(0,X.jsx)(`form`,{onSubmit:M,children:(0,X.jsxs)(`div`,{className:W(`flex items-end gap-2 rounded-[1.55rem] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200 sm:p-3`,`bg-surface/[0.92] dark:bg-dark-200/[0.92] backdrop-blur-xl`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_14px_42px_rgba(15,23,42,0.08)]`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_52px_rgba(15,23,42,0.11)]`),children:[(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(!p),className:W(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,L&&`text-primary-600 dark:text-primary-400`,p&&`bg-gray-100 dark:bg-dark-300`),title:r(`chat.input.attachments`),children:L?(0,X.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,X.jsx)(l,{className:`h-4 w-4`}),(0,X.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`})]}):p?(0,X.jsx)(g,{className:`h-4 w-4`}):(0,X.jsx)(f,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,X.jsx)(Bt,{ref:E,value:i,onChange:e=>a(e.target.value),onKeyDown:N,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!m-0 min-h-[40px] max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !p-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-base leading-relaxed touch-manipulation`,rows:1})}),(0,X.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1 sm:gap-2`,children:[w&&k.length>0&&(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)(Ie,{models:k,selectedModel:A,onModelChange:I,getModelValue:Te,currentPersona:h,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:C})}),b?(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:F,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.stopGeneration`),children:(0,X.jsx)(P,{className:`h-4 w-4`})}):(0,X.jsx)(G,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!i.trim()||n||!j,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-100 text-gray-400 dark:bg-dark-300 dark:text-dark-500`,`disabled:cursor-not-allowed disabled:opacity-70`,`transition-colors duration-150 touch-manipulation`,i.trim()&&!n&&j&&[`bg-gray-950 text-white hover:bg-gray-800`,`dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`shadow-sm`]),title:r(`chat.input.sendMessage`),children:(0,X.jsx)(ie,{className:`h-4 w-4`})})]})]})}),w&&k.length>0&&(0,X.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,X.jsx)(Ie,{models:k,selectedModel:A,onModelChange:I,getModelValue:Te,currentPersona:h,className:`w-full`,compact:!0,showImageGen:C})}),(0,X.jsxs)(`div`,{className:`mt-2 flex min-h-4 items-center justify-center gap-2 text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,X.jsx)(Wt,{sessionId:w?.id}),(0,X.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,X.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),L&&(0,X.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,o.length>0&&r(`chat.footer.images`,{count:o.length}),o.length>0&&u&&` • `,u&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},Xt=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(null),[o,s]=(0,Y.useState)({top:0,left:0});(0,Y.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=()=>he(e,64),u=t=>{ue(t.currentTarget,e.name,64)};return(0,X.jsxs)(`div`,{className:W(`relative`,n),children:[(0,X.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:W(`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,X.jsx)(`img`,{src:l(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:u}),(0,X.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),c&&(0,X.jsx)(v,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,X.jsx)(A,{className:W(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,Le.createPortal)((0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,X.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,X.jsxs)(`div`,{className:W(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,X.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,X.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,X.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,X.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,X.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,X.jsx)(z,{className:`h-3.5 w-3.5 text-white`})}),c&&(0,X.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,X.jsx)(x,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,X.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,X.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,X.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,X.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,X.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,X.jsx)(oe,{className:`h-3 w-3`}),e.model]}),e.description&&(0,X.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,X.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,X.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,X.jsx)(p,{className:`h-2.5 w-2.5 text-gray-400`}),(0,X.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,X.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,X.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,X.jsx)(B,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,X.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,X.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,X.jsx)(x,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},Zt=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=s(),a=(0,Y.useRef)(null),[o,c]=(0,Y.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/`)){E.error(`File ${o.name} is not an image`);continue}if(o.size>10*1024*1024){E.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&&E.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),c(!0)},d=e=>{e.preventDefault(),c(!1)},f=e=>{e.preventDefault(),c(!1),l(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},m=e.length<n;return(0,X.jsxs)(`div`,{className:W(`space-y-3`,r),children:[m&&(0,X.jsxs)(`div`,{className:W(`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,X.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,X.jsx)(j,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,X.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,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.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,X.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,X.jsx)(z,{className:`h-4 w-4`})})})]},t))}),m&&e.length>0&&(0,X.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,X.jsx)(w,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},$=H(`use-chat`),Qt=new Set([`New Chat`,`New Demo Session`]),$t=e=>!e||Qt.has(e),en=e=>{let[t,n]=(0,Y.useState)(``),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)([]),{addMessage:l,updateMessage:u,updateMessageWithStatistics:d,applySessionTitle:f,setGeneratingTitleForSession:p}=q(),{setIsGenerating:m,preferences:h}=K(),g=(0,Y.useRef)(null),_=(0,Y.useRef)(null),v=(0,Y.useRef)(!1),y=(0,Y.useRef)(null),b=(0,Y.useRef)(``),x=(0,Y.useRef)(0),S=(0,Y.useRef)(void 0),C=(0,Y.useRef)(null),w=(0,Y.useRef)(``),T=(0,Y.useCallback)(()=>{C.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(C.current),C.current=null},[]),D=(0,Y.useCallback)((e,t=!1)=>{if(w.current=e,t||typeof window>`u`){T(),n(e);return}C.current===null&&(C.current=window.requestAnimationFrame(()=>{C.current=null,n(w.current)}))},[T]),O=(0,Y.useCallback)(()=>{T(),w.current=``,n(``)},[T]),k=(0,Y.useCallback)(()=>{_.current=null,v.current=!1,y.current=null},[]),A=(0,Y.useCallback)(async e=>{let t=K.getState().preferences.titleSettings,n=_.current,r=v.current&&y.current===e;if($.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),!n||!r||!t?.autoTitle||!t?.taskModel){k();return}k(),$.debug(`Triggering auto-title generation...`),p(e);try{let r=await le.generateTitle(e,t.taskModel,n,t.taskProviderType,t.taskProviderId);if($.debug(`Title generation response:`,r),!r.success||!r.data?.title)throw Error(r.error||`Title generation returned no title`);f(e,r.data.title,r.data.updatedAt),r.data.source===`fallback`?E.error(`Could not generate a title; using the message preview`):E.success(`Chat title generated`)}catch(e){$.error(`Failed to generate title:`,e),E.error(`Failed to generate chat title`)}finally{p(null)}},[f,k,p]);return(0,Y.useEffect)(()=>()=>{J.offMessage(`user_message`),J.offMessage(`assistant_chunk`),J.offMessage(`assistant_complete`),J.offMessage(`tool_status`),J.offMessage(`error`)},[e]),(0,Y.useEffect)(()=>{if(!e){J.offMessage(`user_message`),J.offMessage(`assistant_chunk`),J.offMessage(`assistant_complete`),J.offMessage(`tool_status`),J.offMessage(`error`);return}return J.onMessage(`user_message`,()=>{}),J.onMessage(`assistant_chunk`,t=>{let n=t,r=n.messageId||g.current;r&&(b.current=n.total,D(n.total,n.done),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{u(e,r,b.current),x.current=Date.now()},n.done?0:200))}),J.onMessage(`tool_status`,e=>{let t=e;c(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),J.onMessage(`assistant_complete`,t=>{let n=t;$.debug(`Hook: Received assistant_complete for session:`,e,`messageId:`,n.messageId,`with statistics:`,!!n.statistics),o(!1),O(),m(!1),c([]);let r=n.messageId||g.current;n&&r&&d(e,r,b.current||n.content,n.statistics,n.providerMetadata),A(e),g.current=null,b.current=``,S.current&&clearTimeout(S.current),x.current=0}),J.onMessage(`error`,e=>{let t=e;if(o(!1),O(),m(!1),g.current=null,t.code===`SESSION_NOT_FOUND`){$.warn(`Session not found, redirecting to create new session...`),E.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}E.error(t.error),k()}),o(!1),O(),g.current=null,()=>{S.current&&clearTimeout(S.current),T()}},[e,u,d,m,D,O,T,A,k]),{sendMessage:(0,Y.useCallback)(async(t,n,r)=>{if(!(!e||!t.trim()&&(!n||n.length===0)))try{let a=q.getState(),s=a.currentSession,c={model:s?.personaId?`persona:${s.personaId}`:s?.model||``,providerType:s?.providerType,providerId:s?.providerId};if(!Oe(a.models,c)){E.error(`Select an available model before sending`);return}m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let d=s?.isPrivate===!0,f=s?.messages?.some(e=>e.role===`user`);!d&&!f&&$t(s?.title)?(_.current=t.trim(),v.current=!0,y.current=e):(_.current=null,v.current=!1,y.current=null),l(e,{role:`user`,content:t.trim(),images:n});let p=ve();if(g.current=p,i(p),l(e,{role:`assistant`,content:``,id:p}),se()){let n=`Demo response for: ${t.trim()}`;window.setTimeout(()=>{u(e,p,n),o(!1),O(),i(null),m(!1),A(e),g.current=null,b.current=``},500);return}J.isConnected||await J.connect();let C=d?s?.messages?.filter(e=>e.role!==`system`&&e.id!==p).map(e=>({role:e.role,content:e.content,images:e.images,providerMetadata:e.providerMetadata})):void 0;J.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:n,format:r,options:h.generationOptions,assistantMessageId:p,isPrivate:d,...d?{model:s?.model,providerType:s?.providerType,providerId:s?.providerId,messageHistory:C}:{}}})}catch(e){$.error(`Failed to send message:`,e),o(!1),O(),i(null),m(!1),g.current=null,E.error(`Failed to send message`)}},[e,l,u,m,O,A,h.generationOptions]),stopGeneration:(0,Y.useCallback)(()=>{o(!1),O(),i(null),m(!1),g.current=null},[m,O]),regenerateLastMessage:(0,Y.useCallback)(async()=>{let t=q.getState(),n=t.currentSession;if(!n||!e)return;if(!Oe(t.models,{model:n.personaId?`persona:${n.personaId}`:n.model,providerType:n.providerType,providerId:n.providerId})){E.error(`Select an available model before regenerating`);return}let r=n.messages,a=-1,s=-1;for(let e=r.length-1;e>=0;e--)if(r[e].role===`assistant`){s=e;break}if(s>0){for(let e=s-1;e>=0;e--)if(r[e].role===`user`){a=e;break}}if(a===-1||s===-1){E.error(`No message to regenerate`);return}let c=r[a],u=r[s];try{m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let t=ve();g.current=t,i(t),l(e,{role:`assistant`,content:``,id:t,parentId:u.parentId||u.id,branchIndex:u.siblingCount||1,isActive:!0}),J.isConnected||await J.connect();let a=n.isPrivate===!0,s=a?r.filter(e=>e.role!==`system`).map(e=>({role:e.role,content:e.content,images:e.images,providerMetadata:e.providerMetadata})):void 0;J.send({type:`chat_stream`,data:{sessionId:e,content:c.content,images:c.images,options:h.generationOptions,assistantMessageId:t,regenerate:!0,originalMessageId:u.id,isPrivate:a,...a?{model:n.model,providerType:n.providerType,providerId:n.providerId,messageHistory:s}:{}}})}catch(e){$.error(`Failed to regenerate message:`,e),o(!1),O(),i(null),m(!1),g.current=null,E.error(`Failed to regenerate message`)}},[e,m,O,l,h.generationOptions]),selectBranch:(0,Y.useCallback)(async t=>{let n=q.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){E.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await le.switchMessageBranch(e,t,a);if(r.success&&r.data){let r=n.messages.map(e=>e.id===i||e.parentId===i?{...e,isActive:e.id===t}:e),o={...n,messages:r,updatedAt:Date.now()};q.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),E.success(`Switched to variant ${a+1}`)}else E.error(r.error||`Failed to select branch`)}catch(e){$.error(`Failed to select branch:`,e),E.error(`Failed to select branch`)}},[e]),isStreaming:a,streamingMessage:t,streamingMessageId:r,toolActivities:s}},tn=H(`pages:chat-page`),nn=(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?`}},rn=(e,t,n,r=!1)=>{let i=we(e);return i===`time`?nn(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.`}},an=()=>{let{t:e,i18n:t}=s(),{sessionId:n}=a(),r=i(),u=o(),{currentSession:d,sessions:p,models:m,selectedModel:h,selectedProviderType:_,selectedProviderId:v,setSelectedModel:y,createSession:b,setCurrentSession:x,loadSessions:S,getCurrentPersona:C}=q(),{user:w}=Se(),T=K(e=>e.preferences.imageGenSettings?.enabled===!0),{sendMessage:D,stopGeneration:O,regenerateLastMessage:k,selectBranch:A,isStreaming:j,streamingMessage:M,streamingMessageId:N,toolActivities:P}=en(d?.id||``),F=C(),I=(0,Y.useMemo)(()=>({model:h,providerType:_,providerId:v}),[h,v,_]),L=(0,Y.useMemo)(()=>De(m,I),[m,I]),R=h?xe(L,I):``,z=Oe(m,I),[ee,te]=(0,Y.useState)(ye),ne=(0,Y.useMemo)(()=>rn(ee,w?.username,e,ke(t.language)),[t.language,e,w?.username,ee]),[B,re]=(0,Y.useState)(``),[V,ae]=(0,Y.useState)([]),[oe,se]=(0,Y.useState)(!1),H=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=()=>{te(ye())};return window.addEventListener(je,e),()=>window.removeEventListener(je,e)},[]);let[ce,U]=(0,Y.useState)(!1),ue=T&&ce;(0,Y.useEffect)(()=>{p.length===0&&S()},[S,p.length]),(0,Y.useEffect)(()=>{let e=!1;return T&&(async()=>{try{let t=await pe.getPlugins();if(e)return;U(!!(t.success&&t.data&&t.data.length>0))}catch{if(e)return;U(!1)}})(),()=>{e=!0}},[T]),(0,Y.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!d?.isPrivate&&p.length!==0)if(n){let e=p.find(e=>e.id===n);e&&e.id!==d?.id?x(e):e||(tn.warn(`Session ${n} not found for current user, redirecting...`),p.length>0?r(`/c/${p[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&p.length>0&&u.pathname===`/`&&r(`/c/${p[0].id}`,{replace:!0})})()},[n,p,x,r,d?.id,d?.isPrivate,u.pathname]),(0,Y.useEffect)(()=>{if(d?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{D(t.content,t.images)},100)}catch(e){tn.error(`Failed to parse pending message:`,e)}}}},[d?.id,D]),(0,Y.useEffect)(()=>{let e=H.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[B]);let de=async e=>{if(e.preventDefault(),!B.trim()||!h)return;if(!z){E.error(`Select an available model before sending`);return}let t={content:B.trim(),images:V.length>0?V:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(t)),re(``),ae([]);let n=await b(h,void 0,h.startsWith(`persona:`)?h.slice(8):void 0,_,v);n&&r(`/c/${n.id}`,{replace:!0})},fe=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),de(e))},me=async e=>{let t=Ee(L,e.target.value);t&&y(t.model,t.providerType,t.providerId)},he=(e,t,n)=>{d&&D(e,t,n)};if(!d){let t=V.length>0;return(0,X.jsxs)(`div`,{className:`relative h-full flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,X.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,X.jsx)(`div`,{className:`absolute left-[12%] top-[18%] h-56 w-56 rounded-full bg-primary-500/[0.035] blur-3xl dark:bg-primary-400/[0.04]`}),(0,X.jsx)(`div`,{className:`absolute bottom-[16%] right-[10%] h-72 w-72 rounded-full bg-gray-900/[0.025] blur-3xl dark:bg-white/[0.025]`}),(0,X.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,X.jsxs)(`button`,{onClick:()=>{if(!h&&m.length===0)return;let t=Date.now(),n=h?I:m[0]?be(m[0]):null;if(!n||!Oe(m,n)){E.error(`Select an available model before starting private chat`);return}x({id:`private-${t}`,title:e(`chat.session.private`),model:n.model,providerType:n.providerType,providerId:n.providerId,messages:[],createdAt:t,updatedAt:t,isPrivate:!0})},disabled:!h&&m.length===0||!!h&&!z,className:`absolute end-4 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-6 sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,X.jsx)(c,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:e(`chat.session.private`)})]}),(0,X.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,X.jsxs)(`div`,{className:`mb-10 flex flex-col items-center text-center animate-fade-in sm:mb-12`,"aria-live":`polite`,children:[(0,X.jsx)(`h1`,{className:`mb-4 max-w-3xl text-balance text-[clamp(2.65rem,7vw,5.25rem)] font-light leading-[0.98] tracking-[-0.055em] text-gray-950 dark:text-dark-950 rtl:leading-[1.12] rtl:tracking-normal`,children:ne.title}),(0,X.jsx)(`p`,{className:`max-w-xl text-balance text-base leading-relaxed text-gray-500 dark:text-dark-600 sm:text-lg`,children:ne.subtitle})]},ne.id),L.length>0?(0,X.jsxs)(`div`,{className:`w-full`,children:[oe&&(0,X.jsx)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:(0,X.jsx)(Zt,{images:V,onImagesChange:ae,maxImages:5})}),(0,X.jsx)(`form`,{onSubmit:de,children:(0,X.jsxs)(`div`,{className:W(`flex items-end gap-2 rounded-[1.6rem] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200 sm:p-3`,`border-black/[0.08] bg-surface/90 dark:border-white/[0.09] dark:bg-dark-200/90`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_50px_rgba(15,23,42,0.08)] backdrop-blur-xl`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_22px_65px_rgba(15,23,42,0.12)]`),children:[(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>se(!oe),className:W(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300 transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,oe&&`bg-gray-100 dark:bg-dark-300`),title:e(`chat.input.attachImages`),children:t?(0,X.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,X.jsx)(l,{className:`h-4 w-4`}),(0,X.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):oe?(0,X.jsx)(g,{className:`h-4 w-4`}):(0,X.jsx)(f,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,X.jsx)(Bt,{ref:H,value:B,onChange:e=>re(e.target.value),onKeyDown:fe,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 min-h-[40px] max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !p-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-base leading-relaxed touch-manipulation`,rows:1})}),(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)(Ie,{models:L,selectedModel:R,onModelChange:me,getModelValue:Te,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:ue})}),(0,X.jsx)(G,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!B.trim()||!h||!z,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-950 text-white hover:bg-gray-800 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`disabled:bg-gray-100 disabled:text-gray-400 dark:disabled:bg-dark-300 dark:disabled:text-dark-500 disabled:hover:bg-gray-100 dark:disabled:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,B.trim()&&h&&`shadow-sm`),title:e(`chat.input.sendMessage`),children:(0,X.jsx)(ie,{className:`h-4 w-4`})})]})}),(0,X.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,X.jsx)(Ie,{models:L,selectedModel:R,onModelChange:me,getModelValue:Te,className:`w-full`,compact:!0,showImageGen:ue})}),(0,X.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,X.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,X.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.07] bg-surface/70 p-6 backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/70`,children:[(0,X.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,X.jsx)(`code`,{className:`block rounded-xl bg-gray-100 p-3 font-mono text-xs text-gray-800 dark:bg-dark-300 dark:text-dark-700`,children:e(`chat.model.pullCommand`)})]})})]})]})}return(0,X.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:F?.background?{backgroundImage:`url(${F.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[F?.background&&(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,X.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[d?.isPrivate&&(0,X.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,X.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,X.jsx)(c,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,X.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),F&&!d?.isPrivate&&(0,X.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,X.jsx)(Xt,{persona:F,onClear:()=>{d&&le.updateSession(d.id,{model:F.model,providerType:`ollama`,providerId:null,personaId:null}).then(e=>{if(!e.success||!e.data)throw Error(e.error||`Failed to remove persona`);q.setState(t=>({sessions:t.sessions.map(t=>t.id===d.id?e.data:t),currentSession:e.data}))}).catch(e=>{tn.error(`Failed to remove persona:`,e),E.error(`Failed to remove persona`)})}})}),(0,X.jsx)(Rt,{messages:d.messages,streamingMessage:M,streamingMessageId:N,isStreaming:j,toolActivities:P,onRegenerate:k,onSelectBranch:A,className:`flex-1`}),(0,X.jsx)(Yt,{onSendMessage:he,onStopGeneration:O,disabled:!d})]})]})};export{an as ChatPage,an as default};
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{t as r}from"./useTranslation-Cs6iTP4m.js";import{Ft as i,H as a,X as o,Yt as s,ct as c,g as l,kt as u,pt as d,s as f,st as p,t as m,xt as h}from"./ui-vendor-CAFEDSaO.js";import{t as g}from"./logger-DbNs3-DK.js";import{E as _}from"./api-YWoSobKv.js";import{O as v,r as y,t as b}from"../assets/index-CKV9Lnj8.js";var x=e(n(),1),S=t(),C=g(`components:first-time-setup`),w=({onComplete:e})=>{let{t}=r(),[n,g]=(0,x.useState)(`welcome`),[w,T]=(0,x.useState)(``),[E,D]=(0,x.useState)(``),[O,k]=(0,x.useState)(``),[A,j]=(0,x.useState)(!1),[M,N]=(0,x.useState)(!1),[P,F]=(0,x.useState)(!1),[I,L]=(0,x.useState)(null),[R,z]=(0,x.useState)(!1),[B,V]=(0,x.useState)(!1),[H,U]=(0,x.useState)(``),{login:W,systemInfo:G}=v(),K=G?.turnstile?.siteKey,q=!!(G?.turnstile?.enabled&&K),J=(0,x.useCallback)(e=>{U(e)},[]),Y=(0,x.useMemo)(()=>P||q&&!H,[P,q,H]);(0,x.useEffect)(()=>{n===`encryption-key`&&!I&&_.getEncryptionKey().then(e=>{e.success&&e.data&&L(e.data.encryptionKey)})},[n,I]);let X=async e=>{if(e.preventDefault(),!w.trim()||!E.trim()||!O.trim()){s.error(t(`setup.admin.fillAllFields`));return}if(E!==O){s.error(t(`auth.signup.passwordMismatch`));return}if(E.length<6){s.error(t(`auth.signup.passwordTooShort`));return}if(q&&!H){s.error(t(`auth.signup.tryAgain`));return}F(!0);try{let e=await _.signup({username:w,password:E,email:``,turnstileToken:H});e.success&&e.data?(W(e.data.user,e.data.token,e.data.systemInfo),s.success(t(`setup.admin.success`)),g(`encryption-key`)):s.error(e.message||t(`setup.admin.failed`))}catch(e){C.error(`Admin creation error:`,e),s.error(t(`setup.admin.failed`))}finally{U(``),F(!1)}},Z=async()=>{if(I)try{await navigator.clipboard.writeText(I),z(!0),s.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>z(!1),3e3)}catch{s.error(t(`setup.encryptionKey.copyFailed`))}},Q=()=>{if(!B){s.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})})}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,S.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(l,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(m,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,S.jsx)(`button`,{onClick:()=>g(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,S.jsx)(u,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,S.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,S.jsx)(a,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,S.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,S.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,S.jsx)(i,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,S.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,S.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,S.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,S.jsxs)(`div`,{className:`mb-6`,children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:I||t(`setup.encryptionKey.loading`)}),(0,S.jsx)(`button`,{type:`button`,onClick:Z,disabled:!I,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:R?(0,S.jsx)(h,{className:`h-5 w-5 text-green-500`}):(0,S.jsx)(d,{className:`h-5 w-5`})})]}),(0,S.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,S.jsx)(`div`,{className:`mb-6`,children:(0,S.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:B,onChange:e=>V(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,S.jsx)(`button`,{onClick:Q,disabled:!B,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,S.jsx)(u,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,S.jsxs)(`form`,{onSubmit:X,className:`space-y-4`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,S.jsx)(`input`,{id:`username`,type:`text`,value:w,onChange:e=>T(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:P})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`password`,type:A?`text`:`password`,value:E,onChange:e=>D(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>j(!A),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:A?(0,S.jsx)(p,{size:20}):(0,S.jsx)(c,{size:20})})]})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`confirmPassword`,type:M?`text`:`password`,value:O,onChange:e=>k(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:M?(0,S.jsx)(p,{size:20}):(0,S.jsx)(c,{size:20})})]})]}),q&&K&&(0,S.jsx)(b,{siteKey:K,disabled:P,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:J}),(0,S.jsxs)(`div`,{className:`flex gap-3`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>g(`welcome`),disabled:P,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,S.jsx)(`button`,{type:`submit`,disabled:Y,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:P?(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(f,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,S.jsx)(`div`,{className:`mt-6 text-center`,children:(0,S.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{w as FirstTimeSetup};
1
+ import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-GI9BPwrB.js";import{t as r}from"./useTranslation-Cs6iTP4m.js";import{Ft as i,H as a,X as o,Yt as s,ct as c,g as l,kt as u,pt as d,s as f,st as p,t as m,xt as h}from"./ui-vendor-CAFEDSaO.js";import{t as g}from"./logger-DbNs3-DK.js";import{E as _}from"./api-Fi-lJlfu.js";import{O as v,r as y,t as b}from"../assets/index-BVgyQN3z.js";var x=e(n(),1),S=t(),C=g(`components:first-time-setup`),w=({onComplete:e})=>{let{t}=r(),[n,g]=(0,x.useState)(`welcome`),[w,T]=(0,x.useState)(``),[E,D]=(0,x.useState)(``),[O,k]=(0,x.useState)(``),[A,j]=(0,x.useState)(!1),[M,N]=(0,x.useState)(!1),[P,F]=(0,x.useState)(!1),[I,L]=(0,x.useState)(null),[R,z]=(0,x.useState)(!1),[B,V]=(0,x.useState)(!1),[H,U]=(0,x.useState)(``),{login:W,systemInfo:G}=v(),K=G?.turnstile?.siteKey,q=!!(G?.turnstile?.enabled&&K),J=(0,x.useCallback)(e=>{U(e)},[]),Y=(0,x.useMemo)(()=>P||q&&!H,[P,q,H]);(0,x.useEffect)(()=>{n===`encryption-key`&&!I&&_.getEncryptionKey().then(e=>{e.success&&e.data&&L(e.data.encryptionKey)})},[n,I]);let X=async e=>{if(e.preventDefault(),!w.trim()||!E.trim()||!O.trim()){s.error(t(`setup.admin.fillAllFields`));return}if(E!==O){s.error(t(`auth.signup.passwordMismatch`));return}if(E.length<6){s.error(t(`auth.signup.passwordTooShort`));return}if(q&&!H){s.error(t(`auth.signup.tryAgain`));return}F(!0);try{let e=await _.signup({username:w,password:E,email:``,turnstileToken:H});e.success&&e.data?(W(e.data.user,e.data.token,e.data.systemInfo),s.success(t(`setup.admin.success`)),g(`encryption-key`)):s.error(e.message||t(`setup.admin.failed`))}catch(e){C.error(`Admin creation error:`,e),s.error(t(`setup.admin.failed`))}finally{U(``),F(!1)}},Z=async()=>{if(I)try{await navigator.clipboard.writeText(I),z(!0),s.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>z(!1),3e3)}catch{s.error(t(`setup.encryptionKey.copyFailed`))}},Q=()=>{if(!B){s.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})})}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,S.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(l,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(m,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,S.jsx)(`button`,{onClick:()=>g(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,S.jsx)(u,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,S.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,S.jsx)(a,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,S.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,S.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,S.jsx)(i,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,S.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,S.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,S.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,S.jsxs)(`div`,{className:`mb-6`,children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:I||t(`setup.encryptionKey.loading`)}),(0,S.jsx)(`button`,{type:`button`,onClick:Z,disabled:!I,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:R?(0,S.jsx)(h,{className:`h-5 w-5 text-green-500`}):(0,S.jsx)(d,{className:`h-5 w-5`})})]}),(0,S.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,S.jsx)(`div`,{className:`mb-6`,children:(0,S.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:B,onChange:e=>V(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,S.jsx)(`button`,{onClick:Q,disabled:!B,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,S.jsx)(u,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,S.jsxs)(`form`,{onSubmit:X,className:`space-y-4`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,S.jsx)(`input`,{id:`username`,type:`text`,value:w,onChange:e=>T(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:P})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`password`,type:A?`text`:`password`,value:E,onChange:e=>D(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>j(!A),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:A?(0,S.jsx)(p,{size:20}):(0,S.jsx)(c,{size:20})})]})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`confirmPassword`,type:M?`text`:`password`,value:O,onChange:e=>k(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:M?(0,S.jsx)(p,{size:20}):(0,S.jsx)(c,{size:20})})]})]}),q&&K&&(0,S.jsx)(b,{siteKey:K,disabled:P,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:J}),(0,S.jsxs)(`div`,{className:`flex gap-3`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>g(`welcome`),disabled:P,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,S.jsx)(`button`,{type:`submit`,disabled:Y,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:P?(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(f,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,S.jsx)(`div`,{className:`mt-6 text-center`,children:(0,S.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{w as FirstTimeSetup};