libre-webui 0.21.0 → 0.21.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 (43) hide show
  1. package/backend/dist/index.d.ts.map +1 -1
  2. package/backend/dist/index.js +29 -5
  3. package/backend/dist/index.js.map +1 -1
  4. package/backend/dist/services/webSearchService.d.ts.map +1 -1
  5. package/backend/dist/services/webSearchService.js +8 -1
  6. package/backend/dist/services/webSearchService.js.map +1 -1
  7. package/backend/package.json +1 -1
  8. package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
  9. package/frontend/dist/assets/{index-0wfi-EpC.js → index-BN-WAt2j.js} +2 -40
  10. package/frontend/dist/index.html +9 -9
  11. package/frontend/dist/js/{ArtifactContainer-DPRPcuES.js → ArtifactContainer-BD20LheX.js} +1 -1
  12. package/frontend/dist/js/{ArtifactDemoPage-DzwPlz9J.js → ArtifactDemoPage-DQBTKgzC.js} +1 -1
  13. package/frontend/dist/js/{ArtifactSandboxFrame-CKi4mSTH.js → ArtifactSandboxFrame-CpblpEf4.js} +2 -2
  14. package/frontend/dist/js/{ArtifactSlideOutPanel-BskRCzP0.js → ArtifactSlideOutPanel-BVgr8Cv6.js} +1 -1
  15. package/frontend/dist/js/{ChatPage-DRutCyJ5.js → ChatPage-D2EWlzO4.js} +1 -1
  16. package/frontend/dist/js/{FirstTimeSetup-DU50YWrE.js → FirstTimeSetup-C3ldEPmK.js} +1 -1
  17. package/frontend/dist/js/{GalleryPage-DxXIUesf.js → GalleryPage-DrrOhli8.js} +1 -1
  18. package/frontend/dist/js/{HomePage-Bew9kMKx.js → HomePage-D21Haon_.js} +1 -1
  19. package/frontend/dist/js/{LibreClawPage-Cy9y3YlF.js → LibreClawPage-CEf9ws8z.js} +1 -1
  20. package/frontend/dist/js/{ModelSelector-DXDcDmDR.js → ModelSelector-whWBlN-S.js} +1 -1
  21. package/frontend/dist/js/{ModelsPage-Bj2reiF9.js → ModelsPage-CL2t9qNT.js} +1 -1
  22. package/frontend/dist/js/{NotesPage-CJKEbj3J.js → NotesPage-D10aWpVj.js} +1 -1
  23. package/frontend/dist/js/{PersonasPage-bgWF9S7b.js → PersonasPage-BvCPzwx2.js} +1 -1
  24. package/frontend/dist/js/{PluginUsagePage-CRkD1Tz6.js → PluginUsagePage-B9YgizW8.js} +1 -1
  25. package/frontend/dist/js/{RichMessageContent-DeNjCiyN.js → RichMessageContent-2L-mHp9Q.js} +1 -1
  26. package/frontend/dist/js/{SettingsModal-BUUlkZcv.js → SettingsModal-BK05P_rU.js} +1 -1
  27. package/frontend/dist/js/{SystemPage-DcO51urv.js → SystemPage-CKnhy0Fr.js} +1 -1
  28. package/frontend/dist/js/{UserManagementPage-DLiYw6xG.js → UserManagementPage-B3gA_Zx8.js} +1 -1
  29. package/frontend/dist/js/{WorkPage-MMQ0Y0U5.js → WorkPage-Bj3UVrmb.js} +3 -3
  30. package/frontend/dist/js/{api-CZURQtuc.js → api-DjQINB7B.js} +1 -1
  31. package/frontend/dist/js/{appStore-sGaWMSDr.js → appStore-CIV0DhiE.js} +2 -2
  32. package/frontend/dist/js/{authStore-uaj0hswV.js → authStore-pmXfK_qt.js} +3 -3
  33. package/frontend/dist/js/{chatStore-tRx0Ulq0.js → chatStore-D76rdaV6.js} +2 -2
  34. package/frontend/dist/js/{config-D-jxRG52.js → config-DF-g5uwS.js} +1 -1
  35. package/frontend/dist/js/{estree-CRuerC6a.js → estree-livw6QLA.js} +1 -1
  36. package/frontend/dist/js/{html-BYKlz3Jp.js → html-CWlKlrlk.js} +1 -1
  37. package/frontend/dist/js/{markdown-DFy8bILU.js → markdown-BM75gisb.js} +1 -1
  38. package/frontend/dist/js/{messageCodeStyles-_gGirbe-.js → messageCodeStyles-DxPb6SKm.js} +1 -1
  39. package/frontend/dist/js/{standalone-jOqWoOmp.js → standalone-h0KNQ5yy.js} +1 -1
  40. package/frontend/dist/js/{typescript-TwGXpgeF.js → typescript-CPI0lY4n.js} +1 -1
  41. package/frontend/dist/js/{ui-DSFUl2vT.js → ui-ovAoLjDQ.js} +2 -2
  42. package/frontend/dist/js/{workApi-kClHFVkJ.js → workApi-CCHIEahA.js} +2 -2
  43. package/package.json +1 -1
@@ -34,7 +34,7 @@
34
34
  name="description"
35
35
  content="A modern, minimalist WebUI for interacting with local LLMs through Ollama API"
36
36
  />
37
- <script type="module" crossorigin src="/assets/index-0wfi-EpC.js"></script>
37
+ <script type="module" crossorigin src="/assets/index-BN-WAt2j.js"></script>
38
38
  <link rel="modulepreload" crossorigin href="/js/rolldown-runtime-hePW80VL.js">
39
39
  <link rel="modulepreload" crossorigin href="/js/markdown-core-DHnR5Hw8.js">
40
40
  <link rel="modulepreload" crossorigin href="/js/react-vendor-DPNXrO-8.js">
@@ -45,17 +45,17 @@
45
45
  <link rel="modulepreload" crossorigin href="/js/ui-vendor-xUzKqAXI.js">
46
46
  <link rel="modulepreload" crossorigin href="/js/utils-vendor-1zob7nK9.js">
47
47
  <link rel="modulepreload" crossorigin href="/js/logger-DSXjF4ye.js">
48
- <link rel="modulepreload" crossorigin href="/js/config-D-jxRG52.js">
49
- <link rel="modulepreload" crossorigin href="/js/workApi-kClHFVkJ.js">
50
- <link rel="modulepreload" crossorigin href="/js/api-CZURQtuc.js">
48
+ <link rel="modulepreload" crossorigin href="/js/config-DF-g5uwS.js">
49
+ <link rel="modulepreload" crossorigin href="/js/workApi-CCHIEahA.js">
50
+ <link rel="modulepreload" crossorigin href="/js/api-DjQINB7B.js">
51
51
  <link rel="modulepreload" crossorigin href="/js/utils-BhpNrGnR.js">
52
- <link rel="modulepreload" crossorigin href="/js/chatStore-tRx0Ulq0.js">
53
- <link rel="modulepreload" crossorigin href="/js/appStore-sGaWMSDr.js">
54
- <link rel="modulepreload" crossorigin href="/js/authStore-uaj0hswV.js">
52
+ <link rel="modulepreload" crossorigin href="/js/chatStore-D76rdaV6.js">
53
+ <link rel="modulepreload" crossorigin href="/js/appStore-CIV0DhiE.js">
54
+ <link rel="modulepreload" crossorigin href="/js/authStore-pmXfK_qt.js">
55
55
  <link rel="modulepreload" crossorigin href="/js/welcomePrompts-to5mv_gx.js">
56
- <link rel="modulepreload" crossorigin href="/js/messageCodeStyles-_gGirbe-.js">
56
+ <link rel="modulepreload" crossorigin href="/js/messageCodeStyles-DxPb6SKm.js">
57
57
  <link rel="modulepreload" crossorigin href="/js/Button-X9TT9gTD.js">
58
- <link rel="modulepreload" crossorigin href="/js/ui-DSFUl2vT.js">
58
+ <link rel="modulepreload" crossorigin href="/js/ui-ovAoLjDQ.js">
59
59
  <link rel="stylesheet" crossorigin href="/assets/index-D7m1zWWg.css">
60
60
  </head>
61
61
  <body>
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./useTranslation-CdeLZqSW.js";import{Ft as i,Jt as a,Kt as o,St as s,Ut as c,Vt as l,Yt as u,at as d,f,sn as p,zt as m}from"./ui-vendor-xUzKqAXI.js";import{t as h}from"./logger-DSXjF4ye.js";import{t as g}from"./utils-BhpNrGnR.js";import{t as _}from"./appStore-sGaWMSDr.js";import{t as v}from"./Button-X9TT9gTD.js";import{t as y}from"./OptimizedSyntaxHighlighter-CWYUn9Oe.js";import{a as b,i as x,l as S,n as C,o as w,r as T,t as E}from"./ArtifactSandboxFrame-CKi4mSTH.js";var D=e(n(),1),O=t(),k=h(`components:artifact-renderer`),A=({artifact:e,className:t})=>{let{t:n}=r(),[h,A]=(0,D.useState)(!1),[j,M]=(0,D.useState)(`preview`),{theme:N,openArtifactPanel:P}=_(),F=async e=>{try{await navigator.clipboard.writeText(e),A(!0),setTimeout(()=>A(!1),2e3)}catch(e){k.error(`Failed to copy:`,e)}},I=()=>{let t=e.type===`html`?b(e.content,e.title):e.content,n=new Blob([t],{type:L(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${R(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},L=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},R=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},z=()=>{switch(e.type){case`html`:return(0,O.jsx)(s,{className:`h-4 w-4`});case`react`:return(0,O.jsx)(a,{className:`h-4 w-4`});case`svg`:return(0,O.jsx)(i,{className:`h-4 w-4`});case`code`:return(0,O.jsx)(a,{className:`h-4 w-4`});default:return(0,O.jsx)(i,{className:`h-4 w-4`})}},B=()=>(0,O.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,O.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,O.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,O.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:n(`artifacts.previewUnavailable`)}),(0,O.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,O.jsxs)(v,{variant:`outline`,size:`sm`,onClick:()=>M(`code`),className:`mt-4`,children:[(0,O.jsx)(u,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),V=async()=>{try{let t=await T(C(e.type)??`html`,e.content,e.title,{colorScheme:N.mode===`dark`?`dark`:`light`});S(t,x,e.title)}catch(e){k.error(`Failed to open the artifact preview:`,e)}},H=t=>e.content.trim()?(0,O.jsx)(E,{content:e.content,title:e.title,kind:t,colorScheme:N.mode===`dark`?`dark`:`light`,className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,fallback:B()}):B(),U=()=>(0,O.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:w(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg bg-white`,sandbox:``,title:e.title}),W=()=>(0,O.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,O.jsx)(y,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:N.mode===`dark`,className:`!m-0 !rounded-lg`,children:e.content})}),G=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,O.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,O.jsx)(y,{language:`json`,isDark:N.mode===`dark`,className:`!m-0 !rounded-lg`,children:n})})}catch{return(0,O.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,O.jsxs)(`div`,{className:`text-center`,children:[(0,O.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,O.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidJson`)})]})})}},K=()=>{if(j===`code`)return W();switch(e.type){case`html`:return H(`html`);case`react`:return H(`react`);case`mermaid`:return H(`mermaid`);case`svg`:return U();case`json`:return G();default:return W()}},q=()=>e.type===`html`||e.type===`svg`||e.type===`react`||e.type===`mermaid`;return(0,O.jsxs)(`div`,{className: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,O.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,O.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:z()}),(0,O.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,O.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[q()&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(v,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,O.jsx)(m,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,O.jsx)(u,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>F(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:h?(0,O.jsx)(p,{className:`h-2.5 w-2.5 text-green-500`}):(0,O.jsx)(o,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:I,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,O.jsx)(c,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>P(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,O.jsx)(d,{className:`h-2.5 w-2.5`})})]})]}),(0,O.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,O.jsx)(`div`,{className:`flex-shrink-0`,children:z()}),(0,O.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,O.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[q()&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(v,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,O.jsx)(m,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,O.jsxs)(v,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,O.jsx)(u,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,O.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>F(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:h?(0,O.jsx)(p,{className:`h-4 w-4 text-green-500`}):(0,O.jsx)(o,{className:`h-4 w-4`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:I,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,O.jsx)(c,{className:`h-4 w-4`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>P(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,O.jsx)(d,{className:`h-4 w-4`})})]})]})]}),(0,O.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,O.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,O.jsx)(`div`,{className:`h-full overflow-auto`,children:K()})]}),(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:[(0,O.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]}),C(e.type)&&(0,O.jsxs)(v,{variant:`ghost`,size:`sm`,onClick:()=>V(),className:`text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,children:[(0,O.jsx)(l,{className:`h-3 w-3 mr-1`}),n(`artifacts.openInNewWindow`)]})]})]})},j=({artifacts:e,className:t})=>!e||e.length===0?null:(0,O.jsx)(`div`,{className:g(`space-y-3`,t),children:e.map(e=>(0,O.jsx)(A,{artifact:e},e.id))});export{j as t};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./useTranslation-CdeLZqSW.js";import{Ft as i,Jt as a,Kt as o,St as s,Ut as c,Vt as l,Yt as u,at as d,f,sn as p,zt as m}from"./ui-vendor-xUzKqAXI.js";import{t as h}from"./logger-DSXjF4ye.js";import{t as g}from"./utils-BhpNrGnR.js";import{t as _}from"./appStore-CIV0DhiE.js";import{t as v}from"./Button-X9TT9gTD.js";import{t as y}from"./OptimizedSyntaxHighlighter-CWYUn9Oe.js";import{a as b,i as x,l as S,n as C,o as w,r as T,t as E}from"./ArtifactSandboxFrame-CpblpEf4.js";var D=e(n(),1),O=t(),k=h(`components:artifact-renderer`),A=({artifact:e,className:t})=>{let{t:n}=r(),[h,A]=(0,D.useState)(!1),[j,M]=(0,D.useState)(`preview`),{theme:N,openArtifactPanel:P}=_(),F=async e=>{try{await navigator.clipboard.writeText(e),A(!0),setTimeout(()=>A(!1),2e3)}catch(e){k.error(`Failed to copy:`,e)}},I=()=>{let t=e.type===`html`?b(e.content,e.title):e.content,n=new Blob([t],{type:L(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${R(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},L=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},R=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},z=()=>{switch(e.type){case`html`:return(0,O.jsx)(s,{className:`h-4 w-4`});case`react`:return(0,O.jsx)(a,{className:`h-4 w-4`});case`svg`:return(0,O.jsx)(i,{className:`h-4 w-4`});case`code`:return(0,O.jsx)(a,{className:`h-4 w-4`});default:return(0,O.jsx)(i,{className:`h-4 w-4`})}},B=()=>(0,O.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,O.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,O.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,O.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:n(`artifacts.previewUnavailable`)}),(0,O.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,O.jsxs)(v,{variant:`outline`,size:`sm`,onClick:()=>M(`code`),className:`mt-4`,children:[(0,O.jsx)(u,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),V=async()=>{try{let t=await T(C(e.type)??`html`,e.content,e.title,{colorScheme:N.mode===`dark`?`dark`:`light`});S(t,x,e.title)}catch(e){k.error(`Failed to open the artifact preview:`,e)}},H=t=>e.content.trim()?(0,O.jsx)(E,{content:e.content,title:e.title,kind:t,colorScheme:N.mode===`dark`?`dark`:`light`,className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,fallback:B()}):B(),U=()=>(0,O.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:w(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg bg-white`,sandbox:``,title:e.title}),W=()=>(0,O.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,O.jsx)(y,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:N.mode===`dark`,className:`!m-0 !rounded-lg`,children:e.content})}),G=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,O.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,O.jsx)(y,{language:`json`,isDark:N.mode===`dark`,className:`!m-0 !rounded-lg`,children:n})})}catch{return(0,O.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,O.jsxs)(`div`,{className:`text-center`,children:[(0,O.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,O.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:n(`artifacts.invalidJson`)})]})})}},K=()=>{if(j===`code`)return W();switch(e.type){case`html`:return H(`html`);case`react`:return H(`react`);case`mermaid`:return H(`mermaid`);case`svg`:return U();case`json`:return G();default:return W()}},q=()=>e.type===`html`||e.type===`svg`||e.type===`react`||e.type===`mermaid`;return(0,O.jsxs)(`div`,{className: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,O.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,O.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,O.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:z()}),(0,O.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,O.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[q()&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(v,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,O.jsx)(m,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,O.jsx)(u,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>F(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:h?(0,O.jsx)(p,{className:`h-2.5 w-2.5 text-green-500`}):(0,O.jsx)(o,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:I,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,O.jsx)(c,{className:`h-2.5 w-2.5`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>P(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,O.jsx)(d,{className:`h-2.5 w-2.5`})})]})]}),(0,O.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,O.jsx)(`div`,{className:`flex-shrink-0`,children:z()}),(0,O.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,O.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,O.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[q()&&(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)(v,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,O.jsx)(m,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,O.jsxs)(v,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,O.jsx)(u,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,O.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>F(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:h?(0,O.jsx)(p,{className:`h-4 w-4 text-green-500`}):(0,O.jsx)(o,{className:`h-4 w-4`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:I,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,O.jsx)(c,{className:`h-4 w-4`})}),(0,O.jsx)(v,{variant:`ghost`,size:`sm`,onClick:()=>P(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,O.jsx)(d,{className:`h-4 w-4`})})]})]})]}),(0,O.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,O.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,O.jsx)(`div`,{className:`h-full overflow-auto`,children:K()})]}),(0,O.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:[(0,O.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]}),C(e.type)&&(0,O.jsxs)(v,{variant:`ghost`,size:`sm`,onClick:()=>V(),className:`text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,children:[(0,O.jsx)(l,{className:`h-3 w-3 mr-1`}),n(`artifacts.openInNewWindow`)]})]})]})},j=({artifacts:e,className:t})=>!e||e.length===0?null:(0,O.jsx)(`div`,{className:g(`space-y-3`,t),children:e.map(e=>(0,O.jsx)(A,{artifact:e},e.id))});export{j as t};
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./Button-X9TT9gTD.js";import{n as i}from"./ui-DSFUl2vT.js";import{t as a}from"./ArtifactContainer-DPRPcuES.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-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./Button-X9TT9gTD.js";import{n as i}from"./ui-ovAoLjDQ.js";import{t as a}from"./ArtifactContainer-BD20LheX.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
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./logger-DSXjF4ye.js";import{t as i}from"./config-D-jxRG52.js";var a=e(n(),1),o=`allow-scripts allow-forms allow-modals allow-popups allow-pointer-lock allow-downloads`,s=`clipboard-read; clipboard-write; fullscreen; gamepad`,c=`libre-artifact:render`;function l(e,t){if(!t||e.source!==t.contentWindow)return!1;let n=e.origin,r=typeof window>`u`?void 0:window.location?.origin;if(typeof n==`string`&&n!==``&&n!==`null`&&n!==r)return!1;let i=e.data;return!!i&&i?.type===`libre-artifact:ready`}function u(e,t){e?.contentWindow?.postMessage({type:c,html:t},`*`)}var d=`
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as r}from"./logger-DSXjF4ye.js";import{t as i}from"./config-DF-g5uwS.js";var a=e(n(),1),o=`allow-scripts allow-forms allow-modals allow-popups allow-pointer-lock allow-downloads`,s=`clipboard-read; clipboard-write; fullscreen; gamepad`,c=`libre-artifact:render`;function l(e,t){if(!t||e.source!==t.contentWindow)return!1;let n=e.origin,r=typeof window>`u`?void 0:window.location?.origin;if(typeof n==`string`&&n!==``&&n!==`null`&&n!==r)return!1;let i=e.data;return!!i&&i?.type===`libre-artifact:ready`}function u(e,t){e?.contentWindow?.postMessage({type:c,html:t},`*`)}var d=`
2
2
  body {
3
3
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
4
4
  margin: 0;
@@ -38,7 +38,7 @@ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./m
38
38
  </head>
39
39
  <body>${e}</body>
40
40
  </html>`}function g(e,t,n=`Artifact`){let r=window.open(``,`_blank`);if(!r)return null;r.opener=null;let{document:i}=r;i.title=n,i.documentElement.style.width=`100%`,i.documentElement.style.height=`100%`,i.body.style.width=`100%`,i.body.style.height=`100%`,i.body.style.margin=`0`,i.body.replaceChildren();let a=i.createElement(`iframe`);return a.title=n,a.src=t,a.setAttribute(`sandbox`,o),a.setAttribute(`allow`,s),a.style.width=`100%`,a.style.height=`100%`,a.style.border=`0`,r.addEventListener(`message`,t=>{l(t,a)&&u(a,e)}),i.body.appendChild(a),r}function _(e,t){let n=e;/<head[\s>]/i.test(n)||(n=n.replace(/<html([^>]*)>/i,`<html$1><head></head>`));let r=[];return/<meta\s+charset=/i.test(n)||r.push(`<meta charset="UTF-8">`),/<meta\s+name=["']viewport["']/i.test(n)||r.push(`<meta name="viewport" content="width=device-width, initial-scale=1.0">`),/<base\s/i.test(n)||r.push(`<base target="_blank">`),/<title[\s>]/i.test(n)||r.push(`<title>${S(t)}</title>`),r.length===0?n:v(n,`\n ${r.join(`
41
- `)}`)}function v(e,t){let n=/<head(\s[^>]*)?>/i;return n.test(e)?e.replace(n,e=>`${e}${t}`):`${t}\n${e}`}function y(e,t){return/<\/head>/i.test(e)?e.replace(/<\/head>/i,`${t}</head>`):/<html[^>]*>/i.test(e)?e.replace(/<html([^>]*)>/i,`<html$1><head>${t}</head>`):`${t}${e}`}function b(e,t){return/<\/body>/i.test(e)?e.replace(/<\/body>/i,`${t}</body>`):`${e}${t}`}function x(e){return S(e)}function S(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}var C=`${i.replace(/\/+$/,``)}/artifacts/sandbox`,ee=window.location.protocol===`file:`?new URL(C).origin:window.location.origin,te=`/artifact-runtime`,w=`runtime`,T=`react`,E=`babel`,D=`tailwind`,O=`fonts`,k={react:T,"react-dom":T,"react-dom/client":T,"react/jsx-runtime":T,"react/jsx-dev-runtime":T,recharts:`recharts`,"lucide-react":`lucide-react`,d3:`d3`,three:`three`,papaparse:`papaparse`,lodash:`lodash`,"lodash-es":`lodash`,mermaid:`mermaid`,"chart.js":`chart`,"chart.js/auto":`chart`,tone:`tone`,mathjs:`mathjs`,"plotly.js":`plotly`,"plotly.js-dist-min":`plotly`,"framer-motion":`framer-motion`,"motion/react":`framer-motion`,motion:`framer-motion`,"three/addons/controls/OrbitControls.js":`three`,"three/examples/jsm/controls/OrbitControls.js":`three`},ne=[w,T,E,D],re=[w,`mermaid`],A=[{pattern:/cdn\.tailwindcss\.com/i,bundle:D},{pattern:/(?:^|\/)tailwindcss(?:@[\d.]+)?(?:\/|$)/i,bundle:D},{pattern:/(?:^|\/)chart\.js(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)chart(?:\.min)?\.js(?:$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)d3(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)d3(?:\.min)?\.js(?:$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)three(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`three`},{pattern:/(?:^|\/)three(?:\.min)?\.js(?:$|\?)/i,bundle:`three`},{pattern:/papaparse/i,bundle:`papaparse`},{pattern:/(?:^|\/)lodash(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`lodash`},{pattern:/(?:^|\/)lodash(?:\.min)?\.js(?:$|\?)/i,bundle:`lodash`},{pattern:/fonts\.(?:googleapis|gstatic)\.com/i,bundle:O},{pattern:/mermaid/i,bundle:`mermaid`},{pattern:/(?:^|\/)tone(?:@[\d.]+)?(?:\/|$|\?)|tone(?:\.min)?\.js/i,bundle:`tone`},{pattern:/mathjs|math(?:\.min)?\.js/i,bundle:`mathjs`},{pattern:/plotly/i,bundle:`plotly`},{pattern:/framer-motion|(?:^|\/)motion(?:@[\d.]+)?(?:\/|$)/i,bundle:`framer-motion`},{pattern:/react-dom/i,bundle:T},{pattern:/(?:^|\/)react(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:T},{pattern:/babel(?:-standalone|\/standalone)/i,bundle:E}],j=`__libreArtifactRuntime`;function ie(e){if(k[e])return e;let t=A.find(({pattern:t})=>t.test(e))?.bundle??Object.values(k).find(t=>e.startsWith(`${t}/`));return t?Object.entries(k).find(([,e])=>e===t)?.[0]??null:null}function ae(e){let t=new Set,n=e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g);for(let[,e]of n){let n=ie(e);n&&t.add(k[n])}return[...t]}var M=/\b(?:flex|grid|hidden|absolute|relative|(?:p|m|px|py|mx|my|mt|mb|ml|mr|gap|space)-\d|(?:w|h|max-w|min-h)-(?:\d|full|screen|auto)|text-(?:xs|sm|base|lg|xl|\dxl|center|left|right|white|black|gray-\d)|bg-(?:white|black|transparent|[a-z]+-\d)|rounded(?:-[a-z]+)?|shadow(?:-[a-z]+)?|border(?:-\d)?|items-(?:center|start|end)|justify-(?:center|between|around|end)|font-(?:bold|medium|semibold|light)|hover:[a-z-]+|(?:sm|md|lg|xl):[a-z-]+)\b/g;function N(e){let t=[...e.matchAll(/class\s*=\s*("|')(.*?)\1/gi)].map(e=>e[2]).join(` `);return new Set(t.match(M)??[]).size>=3}function P(e){let t=new Set;for(let[n,r]of Object.entries(k)){let i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:from|import|require)\\s*\\(?\\s*['"\`]${i}['"\`]`).test(e)&&t.add(r)}return[...t]}function F(e){return A.find(({pattern:t})=>t.test(e))?.bundle??null}function I(e){let t=new Set;for(let n of e.matchAll(/\b(?:src|href)\s*=\s*("|')(.*?)\1/gi))t.add(n[2]);for(let n of e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g))t.add(n[1]);return[...t]}function L(e){let t=new Set;for(let n of I(e)){let e=F(n);e&&t.add(e)}return[...t]}var R=`dde8315bbc6a38b3`,z=new Map;function B(e){let t=z.get(e);if(t)return t;let n=fetch(`${ee}${te}/${e}.js?v=${R}`,{credentials:`same-origin`,cache:`no-cache`}).then(t=>{if(!t.ok)throw Error(`The artifact runtime bundle "${e}" is unavailable (HTTP ${t.status}).`);return t.text()});return n.catch(()=>z.delete(e)),z.set(e,n),n}async function V(e){let t=await Promise.all(e.map(B));return Object.fromEntries(e.map((e,n)=>[e,t[n]]))}function H(e){return e===`html`||e===`react`||e===`mermaid`?e:null}var U=`
41
+ `)}`)}function v(e,t){let n=/<head(\s[^>]*)?>/i;return n.test(e)?e.replace(n,e=>`${e}${t}`):`${t}\n${e}`}function y(e,t){return/<\/head>/i.test(e)?e.replace(/<\/head>/i,`${t}</head>`):/<html[^>]*>/i.test(e)?e.replace(/<html([^>]*)>/i,`<html$1><head>${t}</head>`):`${t}${e}`}function b(e,t){return/<\/body>/i.test(e)?e.replace(/<\/body>/i,`${t}</body>`):`${e}${t}`}function x(e){return S(e)}function S(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`)}var C=`${i.replace(/\/+$/,``)}/artifacts/sandbox`,ee=window.location.protocol===`file:`?new URL(C).origin:window.location.origin,te=`/artifact-runtime`,w=`runtime`,T=`react`,E=`babel`,D=`tailwind`,O=`fonts`,k={react:T,"react-dom":T,"react-dom/client":T,"react/jsx-runtime":T,"react/jsx-dev-runtime":T,recharts:`recharts`,"lucide-react":`lucide-react`,d3:`d3`,three:`three`,papaparse:`papaparse`,lodash:`lodash`,"lodash-es":`lodash`,mermaid:`mermaid`,"chart.js":`chart`,"chart.js/auto":`chart`,tone:`tone`,mathjs:`mathjs`,"plotly.js":`plotly`,"plotly.js-dist-min":`plotly`,"framer-motion":`framer-motion`,"motion/react":`framer-motion`,motion:`framer-motion`,"three/addons/controls/OrbitControls.js":`three`,"three/examples/jsm/controls/OrbitControls.js":`three`},ne=[w,T,E,D],re=[w,`mermaid`],A=[{pattern:/cdn\.tailwindcss\.com/i,bundle:D},{pattern:/(?:^|\/)tailwindcss(?:@[\d.]+)?(?:\/|$)/i,bundle:D},{pattern:/(?:^|\/)chart\.js(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)chart(?:\.min)?\.js(?:$|\?)/i,bundle:`chart`},{pattern:/(?:^|\/)d3(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)d3(?:\.min)?\.js(?:$|\?)/i,bundle:`d3`},{pattern:/(?:^|\/)three(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`three`},{pattern:/(?:^|\/)three(?:\.min)?\.js(?:$|\?)/i,bundle:`three`},{pattern:/papaparse/i,bundle:`papaparse`},{pattern:/(?:^|\/)lodash(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:`lodash`},{pattern:/(?:^|\/)lodash(?:\.min)?\.js(?:$|\?)/i,bundle:`lodash`},{pattern:/fonts\.(?:googleapis|gstatic)\.com/i,bundle:O},{pattern:/mermaid/i,bundle:`mermaid`},{pattern:/(?:^|\/)tone(?:@[\d.]+)?(?:\/|$|\?)|tone(?:\.min)?\.js/i,bundle:`tone`},{pattern:/mathjs|math(?:\.min)?\.js/i,bundle:`mathjs`},{pattern:/plotly/i,bundle:`plotly`},{pattern:/framer-motion|(?:^|\/)motion(?:@[\d.]+)?(?:\/|$)/i,bundle:`framer-motion`},{pattern:/react-dom/i,bundle:T},{pattern:/(?:^|\/)react(?:@[\d.]+)?(?:\/|$|\?)/i,bundle:T},{pattern:/babel(?:-standalone|\/standalone)/i,bundle:E}],j=`__libreArtifactRuntime`;function ie(e){if(k[e])return e;let t=A.find(({pattern:t})=>t.test(e))?.bundle??Object.values(k).find(t=>e.startsWith(`${t}/`));return t?Object.entries(k).find(([,e])=>e===t)?.[0]??null:null}function ae(e){let t=new Set,n=e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g);for(let[,e]of n){let n=ie(e);n&&t.add(k[n])}return[...t]}var M=/\b(?:flex|grid|hidden|absolute|relative|(?:p|m|px|py|mx|my|mt|mb|ml|mr|gap|space)-\d|(?:w|h|max-w|min-h)-(?:\d|full|screen|auto)|text-(?:xs|sm|base|lg|xl|\dxl|center|left|right|white|black|gray-\d)|bg-(?:white|black|transparent|[a-z]+-\d)|rounded(?:-[a-z]+)?|shadow(?:-[a-z]+)?|border(?:-\d)?|items-(?:center|start|end)|justify-(?:center|between|around|end)|font-(?:bold|medium|semibold|light)|hover:[a-z-]+|(?:sm|md|lg|xl):[a-z-]+)\b/g;function N(e){let t=[...e.matchAll(/class\s*=\s*("|')(.*?)\1/gi)].map(e=>e[2]).join(` `);return new Set(t.match(M)??[]).size>=3}function P(e){let t=new Set;for(let[n,r]of Object.entries(k)){let i=n.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);RegExp(`(?:from|import|require)\\s*\\(?\\s*['"\`]${i}['"\`]`).test(e)&&t.add(r)}return[...t]}function F(e){return A.find(({pattern:t})=>t.test(e))?.bundle??null}function I(e){let t=new Set;for(let n of e.matchAll(/\b(?:src|href)\s*=\s*("|')(.*?)\1/gi))t.add(n[2]);for(let n of e.matchAll(/(?:from|import|require)\s*\(?\s*['"`]([^'"`]+)['"`]/g))t.add(n[1]);return[...t]}function L(e){let t=new Set;for(let n of I(e)){let e=F(n);e&&t.add(e)}return[...t]}var R=`05e9b37d11baee00`,z=new Map;function B(e){let t=z.get(e);if(t)return t;let n=fetch(`${ee}${te}/${e}.js?v=${R}`,{credentials:`same-origin`,cache:`no-cache`}).then(t=>{if(!t.ok)throw Error(`The artifact runtime bundle "${e}" is unavailable (HTTP ${t.status}).`);return t.text()});return n.catch(()=>z.delete(e)),z.set(e,n),n}async function V(e){let t=await Promise.all(e.map(B));return Object.fromEntries(e.map((e,n)=>[e,t[n]]))}function H(e){return e===`html`||e===`react`||e===`mermaid`?e:null}var U=`
42
42
  html, body { margin: 0; min-height: 100%; }
43
43
  body {
44
44
  background: #ffffff;
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{n as r}from"./react-vendor-DPNXrO-8.js";import{t as i}from"./useTranslation-CdeLZqSW.js";import{i as a}from"./i18n-DJTg6xWw.js";import{Ft as o,Jt as s,Kt as ee,St as te,Ut as ne,Vt as re,Yt as c,an as l,f as u,in as ie,n as d,sn as f,xt as p,zt as m}from"./ui-vendor-xUzKqAXI.js";import{t as h}from"./logger-DSXjF4ye.js";import{t as g}from"./utils-BhpNrGnR.js";import{t as ae}from"./chatStore-tRx0Ulq0.js";import{t as oe}from"./appStore-sGaWMSDr.js";import{t as _}from"./Button-X9TT9gTD.js";import{t as v}from"./OptimizedSyntaxHighlighter-CWYUn9Oe.js";import{a as se,i as ce,l as le,n as y,o as ue,r as de,t as fe}from"./ArtifactSandboxFrame-CKi4mSTH.js";var b=e(n(),1),pe=r(),x=t(),S=h(`components:artifact-slide-out-panel`),C=320,w=.9,me=600,T=()=>{let{t:e,i18n:t}=i(),n=a(t.language),{artifactPanelOpen:r,artifactPanelArtifact:h,openArtifactPanel:T,closeArtifactPanel:E,theme:D}=oe(),O=ae(e=>e.currentSession),k=b.useMemo(()=>{if(!h)return[];let e=h.title.trim().toLowerCase(),t=(O?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===h.id)?t:[...t,h]},[O,h]),A=k.findIndex(e=>e.id===h?.id),[he,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(`preview`),[P,F]=(0,b.useState)(me),[I,L]=(0,b.useState)(!1),R=(0,b.useRef)(null),z=(0,b.useRef)(null),B=(0,b.useRef)(0),V=(0,b.useRef)(0),H=(0,b.useRef)(null),U=(0,b.useRef)(null),W=(0,b.useRef)(P),G=h?.id??null;G!==z.current&&(z.current=G,M!==`preview`&&N(`preview`));let K=(0,b.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,F(W.current)}))},[]),q=(0,b.useCallback)(()=>{H.current=null,L(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,F(W.current))},[]),ge=(0,b.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=P,B.current=e.clientX,W.current=P,e.currentTarget.setPointerCapture(e.pointerId),L(!0)},[P]),J=(0,b.useCallback)(e=>{if(!I||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=window.innerWidth*w,i=Math.min(r,Math.max(C,V.current+t));K(i)},[I,n,K]);if((0,b.useEffect)(()=>{if(!I){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[I,J,q]),(0,b.useEffect)(()=>{let e=()=>{let e=window.innerWidth*w;P>e&&F(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[P]),(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r&&E()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,E]),(0,b.useEffect)(()=>{let e=e=>{I||R.current&&!R.current.contains(e.target)&&r&&E()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,E,I]),!h)return null;let Y=h,_e=async e=>{try{await navigator.clipboard.writeText(e),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){S.error(`Failed to copy:`,e)}},ve=()=>{let e=Y.type===`html`?se(Y.content,Y.title):Y.content,t=new Blob([e],{type:ye(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${be(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ye=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},be=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},xe=()=>{switch(Y.type){case`html`:return(0,x.jsx)(te,{className:`h-5 w-5`});case`react`:return(0,x.jsx)(s,{className:`h-5 w-5`});case`svg`:return(0,x.jsx)(o,{className:`h-5 w-5`});case`code`:return(0,x.jsx)(s,{className:`h-5 w-5`});default:return(0,x.jsx)(o,{className:`h-5 w-5`})}},X=()=>(0,x.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,x.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,x.jsx)(u,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,x.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,x.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,x.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>N(`code`),className:`mt-4`,children:[(0,x.jsx)(c,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Se=async()=>{try{let e=await de(y(Y.type)??`html`,Y.content,Y.title,{colorScheme:D.mode===`dark`?`dark`:`light`});le(e,ce,Y.title)}catch(e){S.error(`Failed to open the artifact preview:`,e)}},Z=e=>Y.content.trim()?(0,x.jsx)(fe,{content:Y.content,title:Y.title,kind:e,colorScheme:D.mode===`dark`?`dark`:`light`,className:g(`w-full h-full border-0 rounded-lg bg-white`,I&&`pointer-events-none`),fallback:X()}):X(),Ce=()=>(0,x.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:ue(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(v,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:Y.content})}),we=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(v,{language:`json`,isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,x.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,x.jsxs)(`div`,{className:`text-center`,children:[(0,x.jsx)(u,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},Te=()=>{if(M===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return Ce();case`json`:return we();default:return Q()}},Ee=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,De=$?`100%`:`${P}px`,Oe=(0,x.jsxs)(x.Fragment,{children:[(0,x.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,x.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,x.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:De},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,x.jsxs)(`div`,{onPointerDown:ge,"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,x.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,x.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,x.jsx)(p,{className:`h-4 w-4`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,x.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:xe()}),(0,x.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:Y.title}),(0,x.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:Y.type.toUpperCase()})]}),(0,x.jsx)(_,{variant:`ghost`,size:`sm`,onClick:E,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,x.jsx)(d,{className:`h-5 w-5`})})]}),(0,x.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,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[k.length>1&&A!==-1&&(0,x.jsxs)(`div`,{className:`me-1 flex items-center gap-0.5`,children:[(0,x.jsx)(_,{variant:`ghost`,size:`sm`,disabled:A===0,onClick:()=>T(k[A-1]),className:`h-8 w-8 p-0`,title:e(`artifacts.previousVersion`),children:(0,x.jsx)(l,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,x.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:A+1,total:k.length})}),(0,x.jsx)(_,{variant:`ghost`,size:`sm`,disabled:A===k.length-1,onClick:()=>T(k[A+1]),className:`h-8 w-8 p-0`,title:e(`artifacts.nextVersion`),children:(0,x.jsx)(ie,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Ee()&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(_,{variant:M===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,x.jsx)(m,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.preview`)]}),(0,x.jsxs)(_,{variant:M===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,x.jsx)(c,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,x.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>_e(Y.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:he?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(f,{className:`h-3.5 w-3.5 me-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ee,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.copyButton`)]})}),(0,x.jsxs)(_,{variant:`ghost`,size:`sm`,onClick:ve,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,x.jsx)(ne,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.download`)]}),y(Y.type)&&(0,x.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.openInNewWindow`),children:[(0,x.jsx)(re,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.open`)]})]})]}),Y.description&&(0,x.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:Y.description})}),(0,x.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:Te()}),(0,x.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,x.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,x.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(Y.createdAt).toLocaleString()]}),!$&&(0,x.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]});return(0,pe.createPortal)(Oe,document.body)};export{T as ArtifactSlideOutPanel};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{n as r}from"./react-vendor-DPNXrO-8.js";import{t as i}from"./useTranslation-CdeLZqSW.js";import{i as a}from"./i18n-DJTg6xWw.js";import{Ft as o,Jt as s,Kt as ee,St as te,Ut as ne,Vt as re,Yt as c,an as l,f as u,in as ie,n as d,sn as f,xt as p,zt as m}from"./ui-vendor-xUzKqAXI.js";import{t as h}from"./logger-DSXjF4ye.js";import{t as g}from"./utils-BhpNrGnR.js";import{t as ae}from"./chatStore-D76rdaV6.js";import{t as oe}from"./appStore-CIV0DhiE.js";import{t as _}from"./Button-X9TT9gTD.js";import{t as v}from"./OptimizedSyntaxHighlighter-CWYUn9Oe.js";import{a as se,i as ce,l as le,n as y,o as ue,r as de,t as fe}from"./ArtifactSandboxFrame-CpblpEf4.js";var b=e(n(),1),pe=r(),x=t(),S=h(`components:artifact-slide-out-panel`),C=320,w=.9,me=600,T=()=>{let{t:e,i18n:t}=i(),n=a(t.language),{artifactPanelOpen:r,artifactPanelArtifact:h,openArtifactPanel:T,closeArtifactPanel:E,theme:D}=oe(),O=ae(e=>e.currentSession),k=b.useMemo(()=>{if(!h)return[];let e=h.title.trim().toLowerCase(),t=(O?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===h.id)?t:[...t,h]},[O,h]),A=k.findIndex(e=>e.id===h?.id),[he,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(`preview`),[P,F]=(0,b.useState)(me),[I,L]=(0,b.useState)(!1),R=(0,b.useRef)(null),z=(0,b.useRef)(null),B=(0,b.useRef)(0),V=(0,b.useRef)(0),H=(0,b.useRef)(null),U=(0,b.useRef)(null),W=(0,b.useRef)(P),G=h?.id??null;G!==z.current&&(z.current=G,M!==`preview`&&N(`preview`));let K=(0,b.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,F(W.current)}))},[]),q=(0,b.useCallback)(()=>{H.current=null,L(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,F(W.current))},[]),ge=(0,b.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=P,B.current=e.clientX,W.current=P,e.currentTarget.setPointerCapture(e.pointerId),L(!0)},[P]),J=(0,b.useCallback)(e=>{if(!I||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=window.innerWidth*w,i=Math.min(r,Math.max(C,V.current+t));K(i)},[I,n,K]);if((0,b.useEffect)(()=>{if(!I){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[I,J,q]),(0,b.useEffect)(()=>{let e=()=>{let e=window.innerWidth*w;P>e&&F(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[P]),(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r&&E()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,E]),(0,b.useEffect)(()=>{let e=e=>{I||R.current&&!R.current.contains(e.target)&&r&&E()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,E,I]),!h)return null;let Y=h,_e=async e=>{try{await navigator.clipboard.writeText(e),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){S.error(`Failed to copy:`,e)}},ve=()=>{let e=Y.type===`html`?se(Y.content,Y.title):Y.content,t=new Blob([e],{type:ye(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${be(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ye=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},be=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},xe=()=>{switch(Y.type){case`html`:return(0,x.jsx)(te,{className:`h-5 w-5`});case`react`:return(0,x.jsx)(s,{className:`h-5 w-5`});case`svg`:return(0,x.jsx)(o,{className:`h-5 w-5`});case`code`:return(0,x.jsx)(s,{className:`h-5 w-5`});default:return(0,x.jsx)(o,{className:`h-5 w-5`})}},X=()=>(0,x.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,x.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,x.jsx)(u,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,x.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,x.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,x.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>N(`code`),className:`mt-4`,children:[(0,x.jsx)(c,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Se=async()=>{try{let e=await de(y(Y.type)??`html`,Y.content,Y.title,{colorScheme:D.mode===`dark`?`dark`:`light`});le(e,ce,Y.title)}catch(e){S.error(`Failed to open the artifact preview:`,e)}},Z=e=>Y.content.trim()?(0,x.jsx)(fe,{content:Y.content,title:Y.title,kind:e,colorScheme:D.mode===`dark`?`dark`:`light`,className:g(`w-full h-full border-0 rounded-lg bg-white`,I&&`pointer-events-none`),fallback:X()}):X(),Ce=()=>(0,x.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:ue(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(v,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:Y.content})}),we=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(v,{language:`json`,isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,x.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,x.jsxs)(`div`,{className:`text-center`,children:[(0,x.jsx)(u,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},Te=()=>{if(M===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return Ce();case`json`:return we();default:return Q()}},Ee=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,De=$?`100%`:`${P}px`,Oe=(0,x.jsxs)(x.Fragment,{children:[(0,x.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,x.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,x.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:De},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,x.jsxs)(`div`,{onPointerDown:ge,"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,x.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,x.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,x.jsx)(p,{className:`h-4 w-4`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,x.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:xe()}),(0,x.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:Y.title}),(0,x.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:Y.type.toUpperCase()})]}),(0,x.jsx)(_,{variant:`ghost`,size:`sm`,onClick:E,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,x.jsx)(d,{className:`h-5 w-5`})})]}),(0,x.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,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[k.length>1&&A!==-1&&(0,x.jsxs)(`div`,{className:`me-1 flex items-center gap-0.5`,children:[(0,x.jsx)(_,{variant:`ghost`,size:`sm`,disabled:A===0,onClick:()=>T(k[A-1]),className:`h-8 w-8 p-0`,title:e(`artifacts.previousVersion`),children:(0,x.jsx)(l,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,x.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:A+1,total:k.length})}),(0,x.jsx)(_,{variant:`ghost`,size:`sm`,disabled:A===k.length-1,onClick:()=>T(k[A+1]),className:`h-8 w-8 p-0`,title:e(`artifacts.nextVersion`),children:(0,x.jsx)(ie,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Ee()&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)(_,{variant:M===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,x.jsx)(m,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.preview`)]}),(0,x.jsxs)(_,{variant:M===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,x.jsx)(c,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,x.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>_e(Y.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:he?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(f,{className:`h-3.5 w-3.5 me-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ee,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.copyButton`)]})}),(0,x.jsxs)(_,{variant:`ghost`,size:`sm`,onClick:ve,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,x.jsx)(ne,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.download`)]}),y(Y.type)&&(0,x.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.openInNewWindow`),children:[(0,x.jsx)(re,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.open`)]})]})]}),Y.description&&(0,x.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:Y.description})}),(0,x.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:Te()}),(0,x.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,x.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,x.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(Y.createdAt).toLocaleString()]}),!$&&(0,x.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]});return(0,pe.createPortal)(Oe,document.body)};export{T as ArtifactSlideOutPanel};
@@ -1,4 +1,4 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{n as r}from"./react-vendor-DPNXrO-8.js";import{d as i,f as a,u as o}from"./router-vendor-Ca9zqOqT.js";import{t as s}from"./useTranslation-CdeLZqSW.js";import{i as c}from"./i18n-DJTg6xWw.js";import{A as l,B as u,D as d,En as f,Et as p,F as m,Ft as h,G as g,Jt as _,Kt as v,N as y,Nt as b,P as x,R as S,St as C,T as w,Tn as T,Tt as E,Wt as D,Yt as O,_n as k,a as ee,bn as A,c as j,d as M,fn as N,g as P,h as te,ht as F,in as ne,j as I,lt as L,mt as R,n as z,nt as re,o as ie,on as ae,pn as oe,q as se,r as ce,rn as le,rt as B,sn as ue,t as V,tt as de,v as fe,x as pe}from"./ui-vendor-xUzKqAXI.js";import{i as me,t as H}from"./logger-DSXjF4ye.js";import{S as U,a as W,b as G,d as K,g as he,i as ge,l as _e,n as ve,p as ye,u as q,v as be}from"./api-CZURQtuc.js";import{a as xe,n as Se,r as Ce,t as J}from"./utils-BhpNrGnR.js";import{a as we,c as Te,i as Ee,l as De,n as Oe,r as ke,t as Y}from"./chatStore-tRx0Ulq0.js";import{n as Ae,r as X}from"./authStore-uaj0hswV.js";import{t as je}from"./appStore-sGaWMSDr.js";import{i as Me,r as Ne,t as Pe}from"./welcomePrompts-to5mv_gx.js";import{l as Fe}from"./messageCodeStyles-_gGirbe-.js";import{t as Z}from"./Button-X9TT9gTD.js";import{d as Ie,f as Le,l as Re}from"./ui-DSFUl2vT.js";import{l as ze}from"../assets/index-0wfi-EpC.js";import{c as Be,s as Ve}from"./ArtifactSandboxFrame-CKi4mSTH.js";import{t as He}from"./ArtifactContainer-DPRPcuES.js";import{t as Ue}from"./ModelSelector-DXDcDmDR.js";var We=r(),Q=e(n(),1),$=t(),Ge=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(R,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,$.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,$.jsx)(ae,{size:12}):(0,$.jsx)(ne,{size:12,className:`rtl:rotate-180`}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},Ke=H(`components:ttsbutton`),qe=null,Je=null,Ye=0,Xe=3e5;async function Ze(e=!1){let t=Date.now();return!e&&qe!==null&&t-Ye<Xe?qe:Je||(Je=(async()=>{try{let e=await W.getModels();return e.success&&e.data&&e.data.length>0?(qe=e.data,Ye=t,e.data):(qe=[],Ye=t,[])}catch{return qe=[],Ye=t,[]}finally{Je=null}})(),Je)}function Qe(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var $e=({text:e,className:t,size:n=`sm`})=>{let{t:r}=s(),{preferences:i}=je(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(!1),v=(0,Q.useRef)([]),y=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await Ze(),n=ve(t,i.ttsSettings?.model,i.ttsSettings?.pluginId);i.ttsSettings?.model&&!n&&(t=await Ze(!0)),e&&(p(t),h(t.length>0))})(),()=>{e=!1}},[i.ttsSettings?.model,i.ttsSettings?.pluginId]);let b=(0,Q.useCallback)(async(e,t,n,i,a,o)=>{let s=await W.generateBase64({model:t,pluginId:n,input:e,voice:i,speed:a,response_format:o});if(!s.success||!s.data?.audio)throw Error(s.message||r(`ttsButton.generateFailed`));let c=`data:${s.data.mimeType};base64,${s.data.audio}`,l=new Audio(c);return g.current=l,new Promise((e,t)=>{l.onended=()=>{g.current=null,e()},l.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},l.play().catch(t)})},[r]),x=(0,Q.useCallback)(async(e,t,n,r,i,a)=>{v.current=e,y.current=0,_.current=!1;let o=null,s=async e=>{try{let o=await W.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){Ke.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){Ke.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Q.useCallback)(()=>{_.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),o(!1),l(!1)},[]),C=async()=>{if(!c){if(a){S();return}l(!0),d(null),_.current=!1;try{let t=i.ttsSettings,n=ge(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=Qe(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));l(!1),o(!0),await x(t,a,s,c,u,p),_.current||o(!1)}else await b(e,a,s,c,u,p),l(!1),o(!0),g.current&&(g.current.onended=()=>{o(!1),g.current=null},g.current.onerror=()=>{d(r(`ttsButton.playbackFailed`)),o(!1),g.current=null})}catch(e){let t=e instanceof Error?e.message:r(`ttsButton.generateFailed`);d(t),Ke.error(`TTS error:`,e),o(!1),l(!1)}}};if((0,Q.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},T={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,$.jsx)(`button`,{onClick:C,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:J(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,u?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,w[n],t),children:c?(0,$.jsx)(L,{className:J(T[n],`animate-spin`)}):a?(0,$.jsx)(pe,{className:T[n]}):u?(0,$.jsx)(ee,{className:T[n]}):(0,$.jsx)(ie,{className:T[n]})})},et=new Map;function tt(e,t,n=``){let r=et.get(e);if(n){if((!r||r.state===`none`)&&(et.set(e,{state:`open`,startedAt:Date.now()}),!t))return;let n=et.get(e);t&&n?.state===`open`&&et.set(e,{state:`done`,durationMs:Date.now()-n.startedAt});return}if(r&&r.state!==`open`||!t)return;let i=xe(t);if(!r){i.thinkingComplete?et.set(e,{state:`none`}):et.set(e,{state:`open`,startedAt:Date.now()});return}i.thinkingComplete&&et.set(e,{state:`done`,durationMs:Date.now()-r.startedAt})}function nt(e){let t=et.get(e);if(t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function rt(e){let t=et.get(e);if(et.delete(e),t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function it(e){let t=e/1e3;if(t<.95)return`${Math.max(.1,Math.round(t*10)/10)}s`;if(t<60)return`${Math.round(t)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return r>0?`${n}m ${r}s`:`${n}m`}var at=/```([^\n`]*)\n([\s\S]*?)\n```/g,ot=/^(?:%%|flowchart|graph|sequenceDiagram|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|mindmap|timeline|gitGraph|quadrantChart|requirementDiagram|sankey-beta|xychart-beta|block-beta|architecture-beta|packet-beta|kanban|radar-beta|treemap-beta|C4Context)\b/i,st=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,ct=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],lt=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:vt(e[1]),title:ut(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=vt(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function ut(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return ft(dt(e))}function dt(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 ft(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 pt(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return ut(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&ut(n[1]).trim()||null}function mt(e){for(let t of[/export\s+default\s+(?:function|class)\s+([A-Z]\w*)/,/export\s+default\s+([A-Z]\w*)\s*(?:;|$)/m,/(?:function|class)\s+([A-Z]\w*)/,/const\s+([A-Z]\w*)\s*[:=]/,/(?:function|const|class)\s+(\w+)/]){let n=e.match(t);if(n)return n[1]}return null}function ht(e){let t=e.match(/^\s*title\s+(.+)$/im);if(t)return t[1].trim();let n=e.trim().match(/^([A-Za-z][\w-]*)/);if(!n)return null;let r=n[1].replace(/-(?:beta|v2)$/i,``).replace(/([a-z])([A-Z])/g,`$1 $2`);return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function gt(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 _t(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 vt(e){let t=e.trim().toLowerCase();return ct.includes(t)?t:`text`}function yt(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function bt(e){let t=[],n=new RegExp(at),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=xt(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 xt(e,t){let n=St(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!st.test(r)&&!r.includes(`=`)?yt(r):void 0)||yt(Tt(n)),fileName:n}}function St(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&st.test(t[1]))return wt(t[1]);let n=e.match(st);return n?wt(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-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{n as r}from"./react-vendor-DPNXrO-8.js";import{d as i,f as a,u as o}from"./router-vendor-Ca9zqOqT.js";import{t as s}from"./useTranslation-CdeLZqSW.js";import{i as c}from"./i18n-DJTg6xWw.js";import{A as l,B as u,D as d,En as f,Et as p,F as m,Ft as h,G as g,Jt as _,Kt as v,N as y,Nt as b,P as x,R as S,St as C,T as w,Tn as T,Tt as E,Wt as D,Yt as O,_n as k,a as ee,bn as A,c as j,d as M,fn as N,g as P,h as te,ht as F,in as ne,j as I,lt as L,mt as R,n as z,nt as re,o as ie,on as ae,pn as oe,q as se,r as ce,rn as le,rt as B,sn as ue,t as V,tt as de,v as fe,x as pe}from"./ui-vendor-xUzKqAXI.js";import{i as me,t as H}from"./logger-DSXjF4ye.js";import{S as U,a as W,b as G,d as K,g as he,i as ge,l as _e,n as ve,p as ye,u as q,v as be}from"./api-DjQINB7B.js";import{a as xe,n as Se,r as Ce,t as J}from"./utils-BhpNrGnR.js";import{a as we,c as Te,i as Ee,l as De,n as Oe,r as ke,t as Y}from"./chatStore-D76rdaV6.js";import{n as Ae,r as X}from"./authStore-pmXfK_qt.js";import{t as je}from"./appStore-CIV0DhiE.js";import{i as Me,r as Ne,t as Pe}from"./welcomePrompts-to5mv_gx.js";import{l as Fe}from"./messageCodeStyles-DxPb6SKm.js";import{t as Z}from"./Button-X9TT9gTD.js";import{d as Ie,f as Le,l as Re}from"./ui-ovAoLjDQ.js";import{l as ze}from"../assets/index-BN-WAt2j.js";import{c as Be,s as Ve}from"./ArtifactSandboxFrame-CpblpEf4.js";import{t as He}from"./ArtifactContainer-BD20LheX.js";import{t as Ue}from"./ModelSelector-whWBlN-S.js";var We=r(),Q=e(n(),1),$=t(),Ge=({statistics:e,className:t=``})=>{let[n,r]=(0,Q.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,$.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(R,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,$.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,$.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,$.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,$.jsx)(ae,{size:12}):(0,$.jsx)(ne,{size:12,className:`rtl:rotate-180`}),(0,$.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,$.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,$.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,$.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,$.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},Ke=H(`components:ttsbutton`),qe=null,Je=null,Ye=0,Xe=3e5;async function Ze(e=!1){let t=Date.now();return!e&&qe!==null&&t-Ye<Xe?qe:Je||(Je=(async()=>{try{let e=await W.getModels();return e.success&&e.data&&e.data.length>0?(qe=e.data,Ye=t,e.data):(qe=[],Ye=t,[])}catch{return qe=[],Ye=t,[]}finally{Je=null}})(),Je)}function Qe(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var $e=({text:e,className:t,size:n=`sm`})=>{let{t:r}=s(),{preferences:i}=je(),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(null),[f,p]=(0,Q.useState)([]),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(null),_=(0,Q.useRef)(!1),v=(0,Q.useRef)([]),y=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await Ze(),n=ve(t,i.ttsSettings?.model,i.ttsSettings?.pluginId);i.ttsSettings?.model&&!n&&(t=await Ze(!0)),e&&(p(t),h(t.length>0))})(),()=>{e=!1}},[i.ttsSettings?.model,i.ttsSettings?.pluginId]);let b=(0,Q.useCallback)(async(e,t,n,i,a,o)=>{let s=await W.generateBase64({model:t,pluginId:n,input:e,voice:i,speed:a,response_format:o});if(!s.success||!s.data?.audio)throw Error(s.message||r(`ttsButton.generateFailed`));let c=`data:${s.data.mimeType};base64,${s.data.audio}`,l=new Audio(c);return g.current=l,new Promise((e,t)=>{l.onended=()=>{g.current=null,e()},l.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},l.play().catch(t)})},[r]),x=(0,Q.useCallback)(async(e,t,n,r,i,a)=>{v.current=e,y.current=0,_.current=!1;let o=null,s=async e=>{try{let o=await W.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){Ke.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){Ke.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Q.useCallback)(()=>{_.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),o(!1),l(!1)},[]),C=async()=>{if(!c){if(a){S();return}l(!0),d(null),_.current=!1;try{let t=i.ttsSettings,n=ge(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=Qe(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));l(!1),o(!0),await x(t,a,s,c,u,p),_.current||o(!1)}else await b(e,a,s,c,u,p),l(!1),o(!0),g.current&&(g.current.onended=()=>{o(!1),g.current=null},g.current.onerror=()=>{d(r(`ttsButton.playbackFailed`)),o(!1),g.current=null})}catch(e){let t=e instanceof Error?e.message:r(`ttsButton.generateFailed`);d(t),Ke.error(`TTS error:`,e),o(!1),l(!1)}}};if((0,Q.useEffect)(()=>()=>{_.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let w={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},T={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,$.jsx)(`button`,{onClick:C,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:J(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,u?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,w[n],t),children:c?(0,$.jsx)(L,{className:J(T[n],`animate-spin`)}):a?(0,$.jsx)(pe,{className:T[n]}):u?(0,$.jsx)(ee,{className:T[n]}):(0,$.jsx)(ie,{className:T[n]})})},et=new Map;function tt(e,t,n=``){let r=et.get(e);if(n){if((!r||r.state===`none`)&&(et.set(e,{state:`open`,startedAt:Date.now()}),!t))return;let n=et.get(e);t&&n?.state===`open`&&et.set(e,{state:`done`,durationMs:Date.now()-n.startedAt});return}if(r&&r.state!==`open`||!t)return;let i=xe(t);if(!r){i.thinkingComplete?et.set(e,{state:`none`}):et.set(e,{state:`open`,startedAt:Date.now()});return}i.thinkingComplete&&et.set(e,{state:`done`,durationMs:Date.now()-r.startedAt})}function nt(e){let t=et.get(e);if(t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function rt(e){let t=et.get(e);if(et.delete(e),t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function it(e){let t=e/1e3;if(t<.95)return`${Math.max(.1,Math.round(t*10)/10)}s`;if(t<60)return`${Math.round(t)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return r>0?`${n}m ${r}s`:`${n}m`}var at=/```([^\n`]*)\n([\s\S]*?)\n```/g,ot=/^(?:%%|flowchart|graph|sequenceDiagram|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|mindmap|timeline|gitGraph|quadrantChart|requirementDiagram|sankey-beta|xychart-beta|block-beta|architecture-beta|packet-beta|kanban|radar-beta|treemap-beta|C4Context)\b/i,st=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,ct=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],lt=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:vt(e[1]),title:ut(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=vt(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function ut(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return ft(dt(e))}function dt(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 ft(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 pt(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return ut(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&ut(n[1]).trim()||null}function mt(e){for(let t of[/export\s+default\s+(?:function|class)\s+([A-Z]\w*)/,/export\s+default\s+([A-Z]\w*)\s*(?:;|$)/m,/(?:function|class)\s+([A-Z]\w*)/,/const\s+([A-Z]\w*)\s*[:=]/,/(?:function|const|class)\s+(\w+)/]){let n=e.match(t);if(n)return n[1]}return null}function ht(e){let t=e.match(/^\s*title\s+(.+)$/im);if(t)return t[1].trim();let n=e.trim().match(/^([A-Za-z][\w-]*)/);if(!n)return null;let r=n[1].replace(/-(?:beta|v2)$/i,``).replace(/([a-z])([A-Z])/g,`$1 $2`);return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function gt(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 _t(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 vt(e){let t=e.trim().toLowerCase();return ct.includes(t)?t:`text`}function yt(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function bt(e){let t=[],n=new RegExp(at),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=xt(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 xt(e,t){let n=St(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!st.test(r)&&!r.includes(`=`)?yt(r):void 0)||yt(Tt(n)),fileName:n}}function St(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&st.test(t[1]))return wt(t[1]);let n=e.match(st);return n?wt(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(st);if(t)return wt(t[0])}}function wt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function Tt(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function Et(e){return e?.split(/[\\/]/).pop()}function Dt(e){let t=Et(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 Ot(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function kt(e){let t=yt(e.language)||yt(Tt(e.fileName));switch(t){case`html`:return{type:`html`,title:pt(e.content)||Dt(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:Dt(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:mt(e.content)||Dt(e.fileName)||`React Component`,language:`jsx`};case`mermaid`:return{type:`mermaid`,title:ht(e.content)||`Diagram`,language:`mermaid`};case`json`:return{type:`json`,title:Dt(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:gt(e.content)||Dt(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:Dt(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:_t(e.content)||Dt(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:Dt(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:Dt(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function At(e){return(yt(e.language)||yt(Tt(e.fileName)))===`html`}function jt(e){return(yt(e.language)||yt(Tt(e.fileName)))===`css`}function Mt(e){return(yt(e.language)||yt(Tt(e.fileName)))===`javascript`}function Nt(e){let t=bt(e),n=t.filter(At);if(n.length===0)return null;let r=t.filter(jt),i=t.filter(Mt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=Pt(a.content,r,i),s=Be(o,r.map(e=>e.content),i.map(e=>e.content));return zt(s,`html`)?{artifact:Ot({type:`html`,title:pt(s)||Dt(a.fileName)||`Interactive HTML App`,description:`Bundled generated HTML, CSS, and JavaScript files into one runnable artifact.`,content:s}),ranges:[a,...r,...i]}:null}function Pt(e,t,n){let r=e;for(let e of t){let t=Et(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${Rt(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=Et(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${Rt(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function Ft(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=bt(e);if(It(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 zt(s,`html`)?{artifact:Ot({type:`html`,title:pt(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function It(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function Lt(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 Rt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function zt(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&&(Ve(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Za-z][^>]*>/.test(e)&&/\b(?:export\s+default|return\s*[(<]|=>\s*[(<]|createRoot|render\s*\()/.test(e);if(t===`mermaid`)return ot.test(e.trim());if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
3
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 Bt(e){let t=[],n=e;for(let e of lt){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);zt(n.content,n.type)&&(t.push(Ot({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=Lt(n,r)}let r=Nt(n);for(;r;)t.push(r.artifact),n=Lt(n,r.ranges),r=Nt(n);let i=Ft(n);i&&(t.push(i.artifact),n=Lt(n,i.ranges));let a=bt(n),o=[];for(let e of a){let n=kt(e);!n||!zt(e.content,n.type)||(t.push(Ot({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=Lt(n,o),{content:n.trim(),artifacts:t}}var Vt=H(`components:chat-message`);function Ht({role:e,user:t,personaAvatar:n}){let[r,i]=(0,Q.useState)(null);if(e===`assistant`){let e=n?.trim()||``,t=e.startsWith(`data:`)&&e!==r?e:``;return(0,$.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-sm dark:border-white/[0.09] dark:bg-dark-200 dark:text-dark-950`,children:t?(0,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>i(e)}):e?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,$.jsx)(ze,{label:null,className:`h-4 w-4`})})}let a=t?.username||`User`,o=t?.avatar?.trim()||``,s=!!o&&o!==r;return(0,$.jsx)(`div`,{role:s?void 0:`img`,"aria-label":s?void 0:a,"data-testid":`chat-user-avatar`,className:J(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,s?`border border-black/[0.07] bg-white dark:border-white/[0.09] dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:a,children:s?(0,$.jsx)(`img`,{src:o,alt:a,className:`h-full w-full object-cover`,onError:()=>i(o)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(j,{"aria-hidden":`true`,className:`h-4 w-4`})})}var Ut=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onEditResend:a})=>{let{t:o,i18n:c}=s(),u=e.role===`user`,d=e.role===`system`,{preferences:f}=je(),{user:p}=Ae(),{setSystemMessage:h,getCurrentPersona:_,currentSession:y,rateMessage:b}=Y(),x=_(),[C,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(e.content),[D,O]=(0,Q.useState)(null),[k,ee]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(!1),[M,F]=(0,Q.useState)(!1),[ne,I]=(0,Q.useState)(!1),[L,R]=(0,Q.useState)(!1),re=(0,Q.useRef)(null),ie=(0,Q.useRef)(t),oe=(0,Q.useRef)(!1),se=async()=>{try{await navigator.clipboard.writeText(e.content),Fe(`success`),R(!0),setTimeout(()=>R(!1),2e3)}catch(e){Vt.error(`Failed to copy message:`,e)}},{thinkingContent:ce,thinkingStreaming:B,parsedContent:V,artifacts:de}=(0,Q.useMemo)(()=>{if(u||d||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:xe(e.content),r=n.content,i=t&&!n.thinkingComplete;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:e.artifacts};if(!t){let e=Bt(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,u,d,t]),fe=B?void 0:e.statistics?.thinking_duration_ms??nt(e.id);(0,Q.useEffect)(()=>{let e=ie.current&&!t;return ie.current=t,e&&!oe.current&&!u&&!d&&V&&f.ttsSettings?.enabled&&f.ttsSettings?.autoPlay&&(oe.current=!0,(async()=>{I(!0);try{let e=await W.getModels(),t=e.success&&e.data?e.data:[],n=f.ttsSettings,r=ge(t,n?.model,n?.pluginId),i=ve(t,n?.model,n?.pluginId),a=await W.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);re.current=t,t.onended=()=>{I(!1),re.current=null},t.onerror=()=>{I(!1),re.current=null},await t.play()}}catch(e){Vt.error(`Auto-play TTS failed:`,e),I(!1)}})()),()=>{re.current&&(re.current.pause(),re.current=null)}},[t,u,d,V,f.ttsSettings]);let pe=()=>d?o(`chatMessage.system`):u?f.showUsername&&p?.username?p.username:o(`chatMessage.you`):x?.name?x.name:e.model||o(`chatMessage.assistant`),me=()=>{w(!0),E(e.content)},H=async()=>{ee(!0);try{h(T),w(!1),Vt.debug(`✅ System message updated:`,T)}catch(e){Vt.error(`Failed to save system message:`,e)}finally{ee(!1)}},U=()=>{w(!1),E(e.content)},G=()=>{let t=T.trim();w(!1),!(!t||t===e.content)&&a?.(e.id,t)},K=t=>{y&&b(y.id,e.id,e.rating===t?void 0:t)},he=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,_e=d&&e.content.length>100;return(0,$.jsxs)(`div`,{className:J(`group flex py-1.5 transition-colors sm:py-2`,u?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:J(`flex min-w-0 gap-2.5 sm:gap-3`,u?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!u&&!d&&(0,$.jsx)(Ht,{role:`assistant`,personaAvatar:x?.avatar}),(0,$.jsxs)(`div`,{className:J(`min-w-0 flex-1`,u?`flex flex-col items-end`:d?`py-1.5`:`py-0.5`),children:[!u&&!d&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:pe()}),e.model&&x?.name&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,$.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:Se(e.timestamp,c.language)})]}),(0,$.jsxs)(`div`,{className:J(!u&&!d&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/[0.06] bg-gray-100 dark:border-white/[0.08] dark:bg-gray-800`,children:(0,$.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>O(e)})},t))}),u?C?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/[0.08] bg-white p-2 shadow-sm dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{dir:`auto`,value:T,onChange:e=>E(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),G()):e.key===`Escape`&&U()},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-none dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(`button`,{onClick:U,className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 transition-colors hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:o(`chatMessage.cancelEditing`)}),(0,$.jsx)(`button`,{onClick:G,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white transition-colors hover:bg-gray-700 dark:bg-dark-300 dark:hover:bg-dark-400`,children:o(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{className:`rounded-2xl rounded-ee-md border border-black/[0.06] bg-gray-900 px-3.5 py-2 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):d?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(l,{className:`h-2.5 w-2.5 opacity-50`}),o(`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:C?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:H,disabled:k,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.saveChanges`),children:(0,$.jsx)(m,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:U,disabled:k,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.cancelEditing`),children:(0,$.jsx)(z,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:me,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:o(`chatMessage.editSystemMessage`),children:(0,$.jsx)(g,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),C?(0,$.jsx)(`textarea`,{dir:`auto`,value:T,onChange:e=>E(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:o(`chatMessage.systemMessagePlaceholder`),disabled:k}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:A?e.content:he(e.content)}),_e&&(0,$.jsx)(`button`,{onClick:()=>j(!A),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:A?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(le,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(ae,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(ce||B)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{onClick:()=>F(!M),className:`flex items-center gap-1.5 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,$.jsx)(N,{className:J(`h-3.5 w-3.5`,B&&`animate-pulse-subtle motion-reduce:animate-none`)}),B?(0,$.jsxs)(`span`,{className:`animate-shimmer bg-gradient-to-r from-gray-400 via-gray-900 to-gray-400 bg-[length:200%_100%] bg-clip-text font-medium text-transparent motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-gray-500 dark:from-dark-500 dark:via-dark-900 dark:to-dark-500 motion-reduce:dark:text-dark-600`,children:[o(`chatMessage.thinking`),`…`]}):(0,$.jsx)(`span`,{className:`font-medium`,children:fe===void 0?o(`chatMessage.thinking`):o(`chatMessage.thoughtFor`,{duration:it(fe)})}),M?(0,$.jsx)(le,{className:`h-3.5 w-3.5`}):(0,$.jsx)(ae,{className:`h-3.5 w-3.5`})]}),M&&ce&&(0,$.jsx)(`div`,{className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 dark:bg-dark-200/60`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[13px] leading-relaxed text-gray-600 dark:text-dark-700`,children:ce})})]}),(0,$.jsx)(Re,{content:V,isStreaming:t})]}),!u&&!d&&de.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(He,{artifacts:de})}),!u&&!d&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,$.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:o(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,$.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,$.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!u&&!d&&e.statistics&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(Ge,{statistics:e.statistics})}),!d&&!t&&(0,$.jsxs)(`div`,{className:J(`flex items-center gap-0.5 text-gray-400 dark:text-dark-500`,`sm:opacity-0 sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,u?`mt-1 justify-end`:`mt-1`),children:[u&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:Se(e.timestamp,c.language),children:[pe(),` ·`,` `,Se(e.timestamp,c.language)]}),!u&&V&&(0,$.jsx)($e,{text:V,size:`sm`,className:J(`transition-colors`,ne&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),u&&a&&!C&&(0,$.jsx)(`button`,{onClick:()=>{E(e.content),w(!0)},className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.edit`),children:(0,$.jsx)(g,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{onClick:se,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(L?`chatMessage.copied`:`chatMessage.copyMessage`),children:L?(0,$.jsx)(ue,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(v,{className:`h-3.5 w-3.5`})}),!u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>K(1),className:J(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===1&&`text-primary-600 dark:text-primary-400`),title:o(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(te,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>K(-1),className:J(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===-1&&`text-red-500 dark:text-red-400`),title:o(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(P,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})})]}),!u&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.regenerateResponse`),children:(0,$.jsx)(S,{className:`h-3.5 w-3.5`})})]})]})]}),u&&(0,$.jsx)(Ht,{role:`user`,user:p??null})]}),D&&(0,We.createPortal)((0,$.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":o(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>O(null),children:[(0,$.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),O(null)},children:(0,$.jsx)(z,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:D,alt:o(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Wt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Gt=220,Kt=e=>{let t=e.slice(0,880).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>Gt?`${t.slice(0,219).trimEnd()}…`:t},qt=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;!r||!i||(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Q.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:Wt()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===h,u=Math.abs(a-m),d=c===t.id?v:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:J(`group flex h-4 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:J(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,$.jsx)(`div`,{id:v,role:`tooltip`,className:J(`pointer-events-none absolute start-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:Kt(_.prompt)}),_.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:Kt(_.response)})]})})]})}),Jt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(Ut,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,$.jsxs)(`div`,{className:J(`relative py-2`,c),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,$.jsx)(E,{className:`h-3 w-3`}),(0,$.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let l=e.isActive!==!1,u=t&&i===e.id,d=u?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:J(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||u?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!u&&`cursor-pointer`),role:!l&&!u?`button`:void 0,tabIndex:!l&&!u?0:void 0,onClick:()=>!l&&!u&&s?.(e.id),onKeyDown:t=>{!l&&!u&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,$.jsxs)(`div`,{className:J(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||u?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,$.jsx)(ue,{className:`h-3 w-3`}),!l&&!u&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,$.jsx)(`div`,{className:J(!l&&!u&&`opacity-75`),children:(0,$.jsx)(Ut,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Yt={web_search:x,web_fetch:C,exec:fe,browser:C,Read:h,Write:h,Edit:h,image:F,memory_search:D,memory_get:D,working:ce,thinking:ce,default:ce},Xt={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`},Zt=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,$.jsx)(`div`,{className:J(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Yt[e.name]||Yt.default,n=Xt[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:J(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(`div`,{className:J(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};H(`components:chat-messages`);var Qt=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],$t=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,en=e=>Math.min(120,e*.28),tn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],className:o,onRegenerate:c,onSelectBranch:l,onEditResend:u,followUpSuggestions:d,onFollowUpSelect:f})=>{let{t:p}=s(),m=(0,Q.useRef)(null),h=(0,Q.useRef)(void 0),g=(0,Q.useRef)(null),_=(0,Q.useRef)(null),v=(0,Q.useRef)(new Map),y=(0,Q.useRef)(null),b=(0,Q.useRef)(0),x=(0,Q.useRef)(!1),S=(0,Q.useRef)(!1),[C,T]=(0,Q.useState)(!1),E=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),D=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<E.length;t++){let n=E[t],r=Qt(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<E.length;e++){let t=Qt(E[e]);if(t.role===`user`)break;if(t.role===`assistant`){i=t.content;break}}e.push({id:n.id,prompt:r.content,response:i})}return e},[E]),O=D.map(e=>e.id).join(``),k=(0,Q.useMemo)(()=>O?O.split(``):[],[O]),ee=(0,Q.useMemo)(()=>new Set(k),[k]),[j,M]=(0,Q.useState)(null),N=(0,Q.useCallback)(()=>{let e=g.current;if(!e||k.length===0){M(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(b.current,k.length-1);if(t<=2)n=k.length-1;else{let t=e.scrollTop+en(e.clientHeight);for(;n<k.length-1;){let e=v.current.get(k[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=v.current.get(k[n]);if(!e||e.offsetTop<=t)break;n--}}b.current=n;let r=k[n];M(e=>e===r?e:r)},[k]),P=(0,Q.useCallback)(()=>{y.current===null&&(y.current=window.requestAnimationFrame(()=>{y.current=null,N()}))},[N]),te=(0,Q.useCallback)(()=>{let t=g.current;if(h.current&&clearTimeout(h.current),x.current=!1,h.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;S.current=!n,T(!n&&e.length>0),P()},[e.length,P]),F=(0,Q.useCallback)(()=>{h.current&&clearTimeout(h.current),h.current=setTimeout(te,180)},[te]),ne=(0,Q.useCallback)((e=!1)=>{S.current&&!e||m.current?.scrollIntoView({behavior:$t()})},[]),I=(0,Q.useCallback)(()=>{let t=g.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(x.current){S.current=!0,T(!o&&e.length>0),P(),F();return}S.current=!o,T(!o&&e.length>0),a<=2&&k.length>0?(b.current=k.length-1,M(k[k.length-1])):P()},[k,e.length,F,P]),L=(0,Q.useCallback)(e=>{let t=g.current,n=v.current.get(e);if(!t||!n)return;let r=$t();x.current=!0,S.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-en(t.clientHeight)),behavior:r}),P(),r===`auto`?te():F()},[te,F,P]),R=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>R.current&&!S.current&&ne(),R.current=e.length},[e.length,ne]),(0,Q.useEffect)(()=>{i&&(t||n)&&!S.current&&requestAnimationFrame(()=>{let e=g.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{P();let e=_.current,t=g.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(P);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,P),()=>{n?.disconnect(),window.removeEventListener(`resize`,P)}},[O,P]),(0,Q.useEffect)(()=>()=>{y.current!==null&&(window.cancelAnimationFrame(y.current),y.current=null)},[]),(0,Q.useEffect)(()=>()=>{h.current&&clearTimeout(h.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:J(`flex-1 flex items-center justify-center p-6 sm:p-10`,o),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-surface/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(w,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:p(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:p(`chatMessage.startConversationDescription`)})]})});let z=-1;for(let e=E.length-1;e>=0;e--)if(E[e].messages.some(e=>e.role===`assistant`)){z=e;break}return(0,$.jsxs)(`div`,{className:J(`relative min-h-0 flex-1`,o),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:g,"data-testid":`chat-scroll-viewport`,onScroll:I,className:J(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,$.jsxs)(`div`,{ref:_,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[E.map((e,a)=>{let o=a===z,s=ee.has(e.id),d=i&&e.messages.some(e=>e.id===r),f;if(e.messages.length===1){let s=e.messages[0],l=i&&s.id===r,d=l?{...s,content:t??s.content,thinking:n||s.thinking}:s;f=(0,$.jsx)(Ut,{message:d,isStreaming:l,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onEditResend:i?void 0:u,className:a===0?`mt-3 sm:mt-4`:``})}else f=(0,$.jsx)(Jt,{messages:e.messages,isStreaming:d,streamingMessage:t,streamingThinking:n,streamingMessageId:r||void 0,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onSelectBranch:l,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{ref:t=>{s&&(t?v.current.set(e.id,t):v.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:f},e.id)}),i&&a.length>0&&(0,$.jsx)(Zt,{tools:a,className:`px-0`}),!i&&d&&d.length>0&&f&&(0,$.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:p(`chat.followUp`)}),(0,$.jsx)(`div`,{className:`flex flex-col`,children:d.map(e=>(0,$.jsx)(`button`,{onClick:()=>f(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-gray-600 transition-colors hover:text-gray-900 dark:border-dark-200 dark:text-dark-600 dark:hover:text-dark-900`,children:e},e))})]}),(0,$.jsx)(`div`,{ref:m,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(qt,{items:D,activeId:j,onSelect:L}),C&&(0,$.jsxs)(`button`,{onClick:()=>{x.current=!1,h.current&&(clearTimeout(h.current),h.current=void 0),S.current=!1,m.current?.scrollIntoView({behavior:$t()}),T(!1)},className:J(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/[0.08]`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:p(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(A,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:p(`chatMessage.newMessages`)})]})]})};function nn(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 rn=Q.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Q.useMemo)(()=>nn(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:J(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:J(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,$.jsx)(O,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});rn.displayName=`CodeAwareTextarea`;var an=H(`components:media-upload`),on=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)([]),v=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await y(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await x(n):f.error(`File type not supported: ${n.name}`)}},y=async r=>{if(n-e.length<=0){f.error(`Maximum ${n} images allowed`);return}if(r.size>10485760){f.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)},x=async e=>{if(e.size>10485760){f.error(`File size must be less than 10MB`);return}m(!0);try{let t=await G.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;_(e=>[...e,n]),i?.(n),f.success(`Document "${e.name}" uploaded`)}else f.error(t.error||`Failed to upload document`)}catch(e){an.error(`Document upload error:`,e),f.error(`Failed to upload document`)}finally{m(!1)}},S=e=>{e.preventDefault(),a||d(!0)},C=e=>{e.preventDefault(),d(!1)},w=e=>{e.preventDefault(),d(!1),a||v(e.dataTransfer.files)},T=n=>{t(e.filter((e,t)=>t!==n))},E=async e=>{try{let t=await G.deleteDocument(e);t.success?(_(t=>t.filter(t=>t.id!==e)),f.success(`Document removed`)):f.error(t.error||`Failed to remove document`)}catch(e){an.error(`Error removing document:`,e),f.error(`Failed to remove document`)}},D=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},O=e.length>0||g.length>0;return(0,$.jsxs)(`div`,{className:J(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:J(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:S,onDragLeave:C,onDrop:w,onClick:()=>!a&&l.current?.click(),children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{v(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[p?(0,$.jsx)(L,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,$.jsx)(M,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),O&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{onClick:e=>{e.stopPropagation(),T(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,$.jsx)(z,{className:`h-3 w-3`})})]},`img-${t}`)),g.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(h,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,$.jsx)(b,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:D(e.size)})]}),(0,$.jsx)(`button`,{onClick:t=>{t.stopPropagation(),E(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(z,{className:`h-3 w-3`})})]},e.id))]})]})},sn=H(`components:document-indicator`),cn=({sessionId:e,className:t=``})=>{let[n,r]=(0,Q.useState)([]);if((0,Q.useEffect)(()=>{if(!e)return;let t=async()=>{try{let t=await G.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){sn.error(`Failed to load documents:`,e)}};t();let n=()=>void t();return window.addEventListener(`libre:documents-updated`,n),()=>window.removeEventListener(`libre:documents-updated`,n)},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{className:`
4
4
  inline-flex items-center space-x-1 px-2 py-1
@@ -1 +1 @@
1
- import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as ee}from"./useTranslation-CdeLZqSW.js";import{Bt as r,Kt as i,O as a,St as o,Tn as s,f as c,l,pt as u,sn as d,t as f,vn as p,zt as m}from"./ui-vendor-xUzKqAXI.js";import{t as h}from"./logger-DSXjF4ye.js";import{C as g}from"./api-CZURQtuc.js";import{n as _}from"./authStore-uaj0hswV.js";import{i as v,l as y,n as b,r as x,u as S}from"../assets/index-0wfi-EpC.js";var C=e(n(),1),w=t(),T=h(`components:first-time-setup`),E=({onComplete:e})=>{let{t}=ee(),[n,h]=(0,C.useState)(`welcome`),[E,D]=(0,C.useState)(``),[O,k]=(0,C.useState)(``),[A,j]=(0,C.useState)(``),[M,N]=(0,C.useState)(!1),[P,F]=(0,C.useState)(!1),[I,L]=(0,C.useState)(!1),[R,z]=(0,C.useState)(null),[B,V]=(0,C.useState)(!1),[H,U]=(0,C.useState)(!1),[W,G]=(0,C.useState)(``),{login:K,systemInfo:q}=_(),J=q?.turnstile?.siteKey,Y=!!(q?.turnstile?.enabled&&J),X=(0,C.useCallback)(e=>{G(e)},[]),Z=(0,C.useMemo)(()=>I||Y&&!W,[I,Y,W]);(0,C.useEffect)(()=>{n===`encryption-key`&&!R&&g.getEncryptionKey().then(e=>{e.success&&e.data&&z(e.data.encryptionKey)})},[n,R]);let Q=async e=>{if(e.preventDefault(),!E.trim()||!O.trim()||!A.trim()){s.error(t(`setup.admin.fillAllFields`));return}if(O!==A){s.error(t(`auth.signup.passwordMismatch`));return}let n=x(O);if(n){s.error(n);return}if(Y&&!W){s.error(t(`auth.signup.tryAgain`));return}L(!0);try{let e=await g.signup({username:E,password:O,email:``,turnstileToken:W});if(e.success&&e.data){if(!(`token`in e.data)){s.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}K(e.data.user,e.data.token,e.data.systemInfo),s.success(t(`setup.admin.success`)),h(`encryption-key`)}else s.error(e.message||t(`setup.admin.failed`))}catch(e){T.error(`Admin creation error:`,e),s.error(t(`setup.admin.failed`))}finally{G(``),L(!1)}},te=async()=>{if(R)try{await navigator.clipboard.writeText(R),V(!0),s.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>V(!1),3e3)}catch{s.error(t(`setup.encryptionKey.copyFailed`))}},ne=()=>{if(!H){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,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(S,{})]})}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,w.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(a,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(f,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,w.jsx)(`button`,{onClick:()=>h(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,w.jsx)(p,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(S,{})]}),(0,w.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,w.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,w.jsx)(u,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,w.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,w.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,w.jsx)(c,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,w.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,w.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,w.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,w.jsxs)(`div`,{className:`mb-6`,children:[(0,w.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:R||t(`setup.encryptionKey.loading`)}),(0,w.jsx)(`button`,{type:`button`,onClick:te,disabled:!R,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:B?(0,w.jsx)(d,{className:`h-5 w-5 text-green-500`}):(0,w.jsx)(i,{className:`h-5 w-5`})})]}),(0,w.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,w.jsx)(`div`,{className:`mb-6`,children:(0,w.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>U(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,w.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,w.jsx)(`button`,{onClick:ne,disabled:!H,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,w.jsx)(p,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(S,{})]}),(0,w.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,w.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,w.jsx)(`input`,{id:`username`,type:`text`,value:E,onChange:e=>D(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:I})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`input`,{id:`password`,type:M?`text`:`password`,value:O,onChange:e=>k(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:I}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:M?(0,w.jsx)(r,{size:20}):(0,w.jsx)(m,{size:20})})]}),(0,w.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:b})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`input`,{id:`confirmPassword`,type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:I}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:P?(0,w.jsx)(r,{size:20}):(0,w.jsx)(m,{size:20})})]})]}),Y&&J&&(0,w.jsx)(v,{siteKey:J,action:`signup`,disabled:I,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:X}),(0,w.jsxs)(`div`,{className:`flex gap-3`,children:[(0,w.jsx)(`button`,{type:`button`,onClick:()=>h(`welcome`),disabled:I,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,w.jsx)(`button`,{type:`submit`,disabled:Z,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:I?(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(l,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,w.jsx)(`div`,{className:`mt-6 text-center`,children:(0,w.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{E as FirstTimeSetup};
1
+ import{r as e}from"./rolldown-runtime-hePW80VL.js";import{d as t,f as n}from"./markdown-core-DHnR5Hw8.js";import{t as ee}from"./useTranslation-CdeLZqSW.js";import{Bt as r,Kt as i,O as a,St as o,Tn as s,f as c,l,pt as u,sn as d,t as f,vn as p,zt as m}from"./ui-vendor-xUzKqAXI.js";import{t as h}from"./logger-DSXjF4ye.js";import{C as g}from"./api-DjQINB7B.js";import{n as _}from"./authStore-pmXfK_qt.js";import{i as v,l as y,n as b,r as x,u as S}from"../assets/index-BN-WAt2j.js";var C=e(n(),1),w=t(),T=h(`components:first-time-setup`),E=({onComplete:e})=>{let{t}=ee(),[n,h]=(0,C.useState)(`welcome`),[E,D]=(0,C.useState)(``),[O,k]=(0,C.useState)(``),[A,j]=(0,C.useState)(``),[M,N]=(0,C.useState)(!1),[P,F]=(0,C.useState)(!1),[I,L]=(0,C.useState)(!1),[R,z]=(0,C.useState)(null),[B,V]=(0,C.useState)(!1),[H,U]=(0,C.useState)(!1),[W,G]=(0,C.useState)(``),{login:K,systemInfo:q}=_(),J=q?.turnstile?.siteKey,Y=!!(q?.turnstile?.enabled&&J),X=(0,C.useCallback)(e=>{G(e)},[]),Z=(0,C.useMemo)(()=>I||Y&&!W,[I,Y,W]);(0,C.useEffect)(()=>{n===`encryption-key`&&!R&&g.getEncryptionKey().then(e=>{e.success&&e.data&&z(e.data.encryptionKey)})},[n,R]);let Q=async e=>{if(e.preventDefault(),!E.trim()||!O.trim()||!A.trim()){s.error(t(`setup.admin.fillAllFields`));return}if(O!==A){s.error(t(`auth.signup.passwordMismatch`));return}let n=x(O);if(n){s.error(n);return}if(Y&&!W){s.error(t(`auth.signup.tryAgain`));return}L(!0);try{let e=await g.signup({username:E,password:O,email:``,turnstileToken:W});if(e.success&&e.data){if(!(`token`in e.data)){s.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}K(e.data.user,e.data.token,e.data.systemInfo),s.success(t(`setup.admin.success`)),h(`encryption-key`)}else s.error(e.message||t(`setup.admin.failed`))}catch(e){T.error(`Admin creation error:`,e),s.error(t(`setup.admin.failed`))}finally{G(``),L(!1)}},te=async()=>{if(R)try{await navigator.clipboard.writeText(R),V(!0),s.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>V(!1),3e3)}catch{s.error(t(`setup.encryptionKey.copyFailed`))}},ne=()=>{if(!H){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,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(S,{})]})}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,w.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(a,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(f,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,w.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,w.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,w.jsx)(`button`,{onClick:()=>h(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,w.jsx)(p,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(S,{})]}),(0,w.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,w.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,w.jsx)(u,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,w.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,w.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,w.jsx)(c,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,w.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,w.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,w.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,w.jsxs)(`div`,{className:`mb-6`,children:[(0,w.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:R||t(`setup.encryptionKey.loading`)}),(0,w.jsx)(`button`,{type:`button`,onClick:te,disabled:!R,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:B?(0,w.jsx)(d,{className:`h-5 w-5 text-green-500`}):(0,w.jsx)(i,{className:`h-5 w-5`})})]}),(0,w.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,w.jsx)(`div`,{className:`mb-6`,children:(0,w.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,w.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>U(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,w.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,w.jsx)(`button`,{onClick:ne,disabled:!H,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,w.jsx)(p,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,w.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,w.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,w.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,w.jsx)(y,{size:`md`,label:null}),(0,w.jsx)(S,{})]}),(0,w.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,w.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,w.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,w.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,w.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,w.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,w.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,w.jsx)(`input`,{id:`username`,type:`text`,value:E,onChange:e=>D(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:I})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`input`,{id:`password`,type:M?`text`:`password`,value:O,onChange:e=>k(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:I}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:M?(0,w.jsx)(r,{size:20}):(0,w.jsx)(m,{size:20})})]}),(0,w.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:b})]}),(0,w.jsxs)(`div`,{children:[(0,w.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(`input`,{id:`confirmPassword`,type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:I}),(0,w.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:P?(0,w.jsx)(r,{size:20}):(0,w.jsx)(m,{size:20})})]})]}),Y&&J&&(0,w.jsx)(v,{siteKey:J,action:`signup`,disabled:I,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:X}),(0,w.jsxs)(`div`,{className:`flex gap-3`,children:[(0,w.jsx)(`button`,{type:`button`,onClick:()=>h(`welcome`),disabled:I,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,w.jsx)(`button`,{type:`submit`,disabled:Z,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:I?(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,w.jsxs)(`div`,{className:`flex items-center`,children:[(0,w.jsx)(l,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,w.jsx)(`div`,{className:`mt-6 text-center`,children:(0,w.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{E as FirstTimeSetup};