libre-webui 0.13.0 → 0.13.2

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 (89) hide show
  1. package/backend/dist/index.js +1 -1
  2. package/backend/dist/index.js.map +1 -1
  3. package/backend/dist/routes/plugins.d.ts.map +1 -1
  4. package/backend/dist/routes/plugins.js +8 -7
  5. package/backend/dist/routes/plugins.js.map +1 -1
  6. package/backend/dist/routes/tts.d.ts.map +1 -1
  7. package/backend/dist/routes/tts.js +28 -7
  8. package/backend/dist/routes/tts.js.map +1 -1
  9. package/backend/dist/services/pluginCapabilityRegistryService.d.ts +1 -1
  10. package/backend/dist/services/pluginCapabilityRegistryService.d.ts.map +1 -1
  11. package/backend/dist/services/pluginCapabilityRegistryService.js +10 -5
  12. package/backend/dist/services/pluginCapabilityRegistryService.js.map +1 -1
  13. package/backend/dist/services/pluginService.d.ts +8 -3
  14. package/backend/dist/services/pluginService.d.ts.map +1 -1
  15. package/backend/dist/services/pluginService.js +74 -54
  16. package/backend/dist/services/pluginService.js.map +1 -1
  17. package/backend/dist/services/pluginTTSService.d.ts +4 -2
  18. package/backend/dist/services/pluginTTSService.d.ts.map +1 -1
  19. package/backend/dist/services/pluginTTSService.js +25 -31
  20. package/backend/dist/services/pluginTTSService.js.map +1 -1
  21. package/backend/dist/services/preferencesService.d.ts.map +1 -1
  22. package/backend/dist/services/preferencesService.js +6 -1
  23. package/backend/dist/services/preferencesService.js.map +1 -1
  24. package/backend/dist/types/index.d.ts +2 -0
  25. package/backend/dist/types/index.d.ts.map +1 -1
  26. package/backend/dist/types/index.js.map +1 -1
  27. package/backend/dist/utils/packagePaths.d.ts +1 -0
  28. package/backend/dist/utils/packagePaths.d.ts.map +1 -1
  29. package/backend/dist/utils/packagePaths.js +22 -0
  30. package/backend/dist/utils/packagePaths.js.map +1 -1
  31. package/backend/package.json +1 -1
  32. package/frontend/dist/assets/index-BJsjOpGD.css +1 -0
  33. package/frontend/dist/assets/index-DgL4shIj.js +5 -0
  34. package/frontend/dist/index.html +5 -5
  35. package/frontend/dist/js/{ArtifactContainer-DYmgznWk.js → ArtifactContainer-urMJnZ_h.js} +1 -1
  36. package/frontend/dist/js/{ArtifactDemoPage-D9cUJCUT.js → ArtifactDemoPage-CVxPfyus.js} +1 -1
  37. package/frontend/dist/js/ArtifactSlideOutPanel-MP4ap9If.js +1 -0
  38. package/frontend/dist/js/{Button-Cgmt_2gR.js → Button-BZBnLKRn.js} +1 -1
  39. package/frontend/dist/js/ChatPage-D35quAJJ.js +16 -0
  40. package/frontend/dist/js/{FirstTimeSetup-BO1IPnfI.js → FirstTimeSetup-B9NVXnGv.js} +1 -1
  41. package/frontend/dist/js/{GalleryPage-B2hhzIun.js → GalleryPage-BNdUukNh.js} +1 -1
  42. package/frontend/dist/js/LibreClawPage-D_N9GBg7.js +1 -0
  43. package/frontend/dist/js/{ModelManagerModals-CSGR9o2J.js → ModelManagerModals-C7wlZoV2.js} +1 -1
  44. package/frontend/dist/js/{ModelsPage-CpVM6Qhl.js → ModelsPage-1ykVyEI4.js} +2 -2
  45. package/frontend/dist/js/{OptimizedSyntaxHighlighter-CNjLqj1Z.js → OptimizedSyntaxHighlighter-Fr-hsdRj.js} +1 -1
  46. package/frontend/dist/js/{PersonasPage-CwqOhNVH.js → PersonasPage-Dg1AQ0e8.js} +2 -2
  47. package/frontend/dist/js/RichMessageContent-tAv_35Ur.js +3 -0
  48. package/frontend/dist/js/SettingsModal-BRQcVyKI.js +1 -0
  49. package/frontend/dist/js/{UserManagementPage-C0bC1w1D.js → UserManagementPage-CA15W6yb.js} +1 -1
  50. package/frontend/dist/js/{api-D9FuobIF.js → api-BsUaU_IW.js} +3 -3
  51. package/frontend/dist/js/{ar-CQheG5xK.js → ar-CxLY7ABG.js} +1 -1
  52. package/frontend/dist/js/{bn-BVXljlpH.js → bn-DREExDzT.js} +1 -1
  53. package/frontend/dist/js/{cs-BgyyXudt.js → cs-LDpGwqlb.js} +1 -1
  54. package/frontend/dist/js/{da-Dk83-zzY.js → da-Csupo97j.js} +1 -1
  55. package/frontend/dist/js/{de-B9SDOxyQ.js → de-EOghQcPX.js} +1 -1
  56. package/frontend/dist/js/{es-DMlNf0tc.js → es-CiX_CYKt.js} +1 -1
  57. package/frontend/dist/js/{fr-DtOoKP26.js → fr-1IIacQYp.js} +1 -1
  58. package/frontend/dist/js/{hi-wuG6Draz.js → hi-DGT4fx6S.js} +1 -1
  59. package/frontend/dist/js/{id-CT2rnPXt.js → id-0UGudeEI.js} +1 -1
  60. package/frontend/dist/js/{is-Cfy2VWp5.js → is-BQzgz0LG.js} +1 -1
  61. package/frontend/dist/js/{it-vgQmoI8w.js → it-3PfovgDw.js} +1 -1
  62. package/frontend/dist/js/{ja-B8pVsr1R.js → ja-BaXdHNz8.js} +1 -1
  63. package/frontend/dist/js/{ko-CTERnuAH.js → ko-DNqxLzw3.js} +1 -1
  64. package/frontend/dist/js/{ms-BGmwAKcP.js → ms-D_X86VRO.js} +1 -1
  65. package/frontend/dist/js/{nl-CKLRry0w.js → nl-B832wh-7.js} +1 -1
  66. package/frontend/dist/js/{pl-DRWZS4lz.js → pl-BDMgy2lk.js} +1 -1
  67. package/frontend/dist/js/{pt-Dua6AStw.js → pt-CbhjHMrx.js} +1 -1
  68. package/frontend/dist/js/{ru-B6MEHobb.js → ru-CEe0KRO9.js} +1 -1
  69. package/frontend/dist/js/{sv-Bg1rkqPN.js → sv-BWwpkP0M.js} +1 -1
  70. package/frontend/dist/js/{th-Nz5BELCH.js → th-Dm5aEMnB.js} +1 -1
  71. package/frontend/dist/js/{tr-7Nyg2UmX.js → tr-DMaVgSRT.js} +1 -1
  72. package/frontend/dist/js/{uk-DUAnc6NJ.js → uk-Cu1mMWfT.js} +1 -1
  73. package/frontend/dist/js/useBaseQuery-DDZrESRv.js +1 -0
  74. package/frontend/dist/js/useQuery-BFOeNWc6.js +1 -0
  75. package/frontend/dist/js/utils-D0l9J3P-.js +1 -0
  76. package/frontend/dist/js/{vi-BOpghAsX.js → vi-B_DGmAUD.js} +1 -1
  77. package/frontend/dist/js/{zh-lCo3TiLV.js → zh-DIKyA5Kk.js} +1 -1
  78. package/package.json +5 -4
  79. package/scripts/postinstall.js +54 -0
  80. package/frontend/dist/assets/index-j-Q57B_D.css +0 -1
  81. package/frontend/dist/assets/index-pmlsmnQ4.js +0 -5
  82. package/frontend/dist/js/ArtifactSlideOutPanel-DlS_laML.js +0 -1
  83. package/frontend/dist/js/ChatPage-CQ0V4ote.js +0 -16
  84. package/frontend/dist/js/LibreClawPage-Bs8vK_yo.js +0 -1
  85. package/frontend/dist/js/RichMessageContent-DH5WM9fX.js +0 -3
  86. package/frontend/dist/js/SettingsModal-DzkKC4ks.js +0 -1
  87. package/frontend/dist/js/useBaseQuery-D0MMQYNQ.js +0 -1
  88. package/frontend/dist/js/useQuery-B2OUd39C.js +0 -1
  89. package/frontend/dist/js/utils-BaPYjs_z.js +0 -1
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{n as r}from"./react-vendor-Co1u1rWb.js";import{t as i}from"./logger-BmpKNkls.js";import{J as a,Ot as o,Rt as s,Y as c,at as ee,dt as l,n as u,ot as d,st as f,tt as p,ut as m,vt as te}from"./ui-vendor-njo77ljx.js";import{t as h}from"./utils-BaPYjs_z.js";import{t as g}from"./Button-Cgmt_2gR.js";import{P as _,w as v}from"../assets/index-pmlsmnQ4.js";import{t as y}from"./OptimizedSyntaxHighlighter-CNjLqj1Z.js";import{n as b,r as x,t as ne}from"./artifactHtml-B7Oy2e__.js";var S=e(n(),1),C=r(),w=t(),T=i(`components:artifact-slide-out-panel`),E=320,D=.9,O=600,k=()=>{let{t:e}=_(),{artifactPanelOpen:t,artifactPanelArtifact:n,closeArtifactPanel:r,theme:i}=v(),[k,A]=(0,S.useState)(!1),[j,M]=(0,S.useState)(`preview`),[N,P]=(0,S.useState)(O),[F,I]=(0,S.useState)(!1),L=(0,S.useRef)(null),R=(0,S.useRef)(null),z=(0,S.useRef)(null),B=(0,S.useRef)(0),V=(0,S.useRef)(0),H=(0,S.useRef)(null),U=(0,S.useRef)(null),W=(0,S.useRef)(N),G=n?.id??null;G!==z.current&&(z.current=G,j!==`preview`&&M(`preview`));let K=(0,S.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,P(W.current)}))},[]),q=(0,S.useCallback)(()=>{H.current=null,I(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,P(W.current))},[]),J=(0,S.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=N,B.current=e.clientX,W.current=N,e.currentTarget.setPointerCapture(e.pointerId),I(!0)},[N]),Y=(0,S.useCallback)(e=>{if(!F||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=B.current-e.clientX,n=window.innerWidth*D;K(Math.min(n,Math.max(E,V.current+t)))},[F,K]);if((0,S.useEffect)(()=>{if(!F){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,Y,{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`,Y),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[F,Y,q]),(0,S.useEffect)(()=>{let e=()=>{let e=window.innerWidth*D;N>e&&P(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[N]),(0,S.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t&&r()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[t,r]),(0,S.useEffect)(()=>{let e=e=>{F||R.current&&!R.current.contains(e.target)&&t&&r()},n=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(n),window.removeEventListener(`mousedown`,e)}},[t,r,F]),!n)return null;let X=n,re=async e=>{try{await navigator.clipboard.writeText(e),A(!0),setTimeout(()=>A(!1),2e3)}catch(e){T.error(`Failed to copy:`,e)}},ie=()=>{let e=X.type===`html`?x(X.content,X.title):X.content,t=new Blob([e],{type:ae(X.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${X.title}.${oe(X.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ae=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`}},oe=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`}},se=()=>{switch(X.type){case`html`:return(0,w.jsx)(c,{className:`h-5 w-5`});case`react`:return(0,w.jsx)(l,{className:`h-5 w-5`});case`svg`:return(0,w.jsx)(p,{className:`h-5 w-5`});case`code`:return(0,w.jsx)(l,{className:`h-5 w-5`});default:return(0,w.jsx)(p,{className:`h-5 w-5`})}},ce=()=>(0,w.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,w.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,w.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,w.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,w.jsxs)(g,{variant:`outline`,size:`sm`,onClick:()=>M(`code`),className:`mt-4`,children:[(0,w.jsx)(s,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.code`)]})]})}),Z=()=>X.content.trim()?(0,w.jsx)(`iframe`,{ref:L,"data-testid":`artifact-html-preview`,srcDoc:x(X.content,X.title),className:h(`w-full h-full border-0 rounded-lg bg-white`,F&&`pointer-events-none`),sandbox:b,allow:ne,allowFullScreen:!0,title:X.title}):ce(),le=()=>{try{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-auto p-4`,dangerouslySetInnerHTML:{__html:X.content}})}catch{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidSvg`)})]})})}},Q=()=>(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,w.jsx)(y,{language:(()=>{if(X.language)return X.language;switch(X.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:i.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:X.content})}),ue=()=>{try{let e=JSON.parse(X.content),t=JSON.stringify(e,null,2);return(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,w.jsx)(y,{language:`json`,isDark:i.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,w.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(o,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},de=()=>{if(j===`code`)return Q();switch(X.type){case`html`:return Z();case`svg`:return le();case`json`:return ue();default:return Q()}},fe=()=>X.type===`html`||X.type===`svg`||X.type===`react`,$=typeof window<`u`&&window.innerWidth<640,pe=$?`100%`:`${N}px`;return(0,C.createPortal)((0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(`div`,{className:h(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,t?`opacity-100`:`opacity-0 pointer-events-none`)}),F&&(0,w.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,w.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:pe},className:h(`fixed top-0 right-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-l border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,t?`translate-x-0`:`translate-x-full`),children:[!$&&(0,w.jsxs)(`div`,{onPointerDown:J,"data-testid":`artifact-resize-handle`,className:h(`absolute left-0 top-0 bottom-0 w-4 -ml-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,w.jsx)(`div`,{className:h(`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`,F&&`bg-primary-500 h-24`)}),(0,w.jsx)(`div`,{className:h(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,F&&`opacity-100`),children:(0,w.jsx)(a,{className:`h-4 w-4`})})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,w.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:se()}),(0,w.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:X.title}),(0,w.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:X.type.toUpperCase()})]}),(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:r,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,w.jsx)(u,{className:`h-5 w-5`})})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:[(0,w.jsx)(`div`,{className:`flex items-center gap-1`,children:fe()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(g,{variant:j===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,w.jsx)(ee,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.preview`)]}),(0,w.jsxs)(g,{variant:j===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>M(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,w.jsx)(s,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.code`)]})]})}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,w.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>re(X.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:k?(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(te,{className:`h-3.5 w-3.5 mr-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(m,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.copyButton`)]})}),(0,w.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:ie,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,w.jsx)(f,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.download`)]}),(X.type===`html`||X.type===`react`)&&(0,w.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:()=>{let e=window.open(``,`_blank`);e&&(e.document.write(x(X.content,X.title)),e.document.close())},className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.openInNewWindow`),children:[(0,w.jsx)(d,{className:`h-3.5 w-3.5 mr-1.5`}),e(`artifacts.open`)]})]})]}),X.description&&(0,w.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:X.description})}),(0,w.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:de()}),(0,w.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:(0,w.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,w.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(X.createdAt).toLocaleString()]}),!$&&(0,w.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]}),document.body)};export{k as ArtifactSlideOutPanel};
@@ -1,16 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{n as r}from"./react-vendor-Co1u1rWb.js";import{t as i}from"./useQuery-B2OUd39C.js";import{t as a}from"./logger-BmpKNkls.js";import{A as o,At as s,Bt as c,C as l,Ct as u,D as d,G as f,H as p,Mt as m,N as h,Nt as g,P as _,Q as v,Rt as y,S as b,St as x,T as S,Tt as C,U as w,Vt as T,Y as E,Z as D,_t as O,a as k,c as A,ct as ee,d as j,dt as M,et as N,ft as P,h as te,ht as ne,i as F,lt as I,mt as re,n as L,o as ie,ot as ae,q as oe,r as se,st as ce,t as R,tt as z,ut as le,v as B,vt as ue,x as V,xt as de,y as fe,z as H}from"./ui-vendor-njo77ljx.js";import{n as pe}from"./demoMode-BhEpMVh5.js";import{a as me,c as he,d as ge,f as U,m as _e,n as ve,o as ye,s as be,u as xe}from"./api-D9FuobIF.js";import{i as Se,n as Ce,r as we,t as W}from"./utils-BaPYjs_z.js";import{t as G}from"./Button-Cgmt_2gR.js";import{A as K,G as Te,K as Ee,P as q,S as J,W as De,_ as Oe,f as ke,h as Ae,m as je,v as Me,w as Ne,x as Pe,y as Fe}from"../assets/index-pmlsmnQ4.js";import{a as Ie,i as Le}from"./artifactHtml-B7Oy2e__.js";import{t as Re}from"./ArtifactContainer-DYmgznWk.js";var ze=r(),Y=e(n(),1),X=t(),Be=({statistics:e,className:t=``})=>{let[n,r]=(0,Y.useState)(!1),{t:i}=q(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,s=e.prompt_eval_count||0,c=e.eval_count||0,l=s+c,u=a(e.total_duration),d=o(e.tokens_per_second);return(0,X.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(p,{size:12,className:`text-primary-500`}),c,` tokens`]}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:u}),e.model&&(0,X.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,X.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,X.jsx)(O,{size:12}):(0,X.jsx)(ne,{size:12}),(0,X.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,X.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,s]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,c]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,l]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,d]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,u]})]}),e.created_at&&(0,X.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},Ve=a(`components:ttsbutton`),He=null,Ue=null,We=0,Ge=300*1e3;async function Ke(){let e=Date.now();return He!==null&&e-We<Ge?He:Ue||(Ue=(async()=>{try{let t=await ve.getModels();return t.success&&t.data&&t.data.length>0?(He=t.data,We=e,t.data):(He=[],We=e,[])}catch{return He=[],We=e,[]}finally{Ue=null}})(),Ue)}function qe(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Je=({text:e,className:t,size:n=`sm`})=>{let{t:r}=q(),{preferences:i}=Ne(),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(!1),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)([]),[p,m]=(0,Y.useState)(null),h=(0,Y.useRef)(null),_=(0,Y.useRef)(!1),v=(0,Y.useRef)([]),y=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=!0;return Ke().then(t=>{e&&(f(t),m(t.length>0))}),()=>{e=!1}},[]);let b=(0,Y.useCallback)(async(e,t,n,i)=>{let a=await ve.generateBase64({model:t,input:e,voice:n,speed:i,response_format:`mp3`});if(!a.success||!a.data?.audio)throw Error(a.message||r(`ttsButton.generateFailed`));let o=`data:${a.data.mimeType};base64,${a.data.audio}`,s=new Audio(o);return h.current=s,new Promise((e,t)=>{s.onended=()=>{h.current=null,e()},s.onerror=()=>{h.current=null,t(Error(r(`ttsButton.playbackFailed`)))},s.play().catch(t)})},[r]),x=(0,Y.useCallback)(async(e,t,n,r)=>{v.current=e,y.current=0,_.current=!1;let i=null,a=async e=>{try{let i=await ve.generateBase64({model:t,input:e,voice:n,speed:r,response_format:`mp3`});return!i.success||!i.data?.audio?null:{audioUrl:`data:${i.data.mimeType};base64,${i.data.audio}`,mimeType:i.data.mimeType}}catch{return null}};e.length>0&&(i=a(e[0]));for(let t=0;t<e.length&&!_.current;t++){y.current=t;try{let n=await i;if(_.current)break;if(i=t+1<e.length?a(e[t+1]):null,!n){Ve.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);h.current=r,await new Promise((e,t)=>{r.onended=()=>{h.current=null,e()},r.onerror=()=>{h.current=null,e()},r.play().catch(()=>{e()})})}catch(e){Ve.error(`Error playing sentence ${t+1}:`,e)}}},[]),S=(0,Y.useCallback)(()=>{_.current=!0,h.current&&(h.current.pause(),h.current.currentTime=0,h.current=null),o(!1),c(!1)},[]),C=async()=>{if(!s){if(a){S();return}c(!0),u(null),_.current=!1;try{let t=i.ttsSettings,n=t?.model||d[0]?.model||`tts-1`,a=t?.voice||d[0]?.config?.default_voice||`alloy`,s=t?.speed||1;if(t?.streamSentences){let t=qe(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));c(!1),o(!0),await x(t,n,a,s),_.current||o(!1)}else await b(e,n,a,s),c(!1),o(!0),h.current&&(h.current.onended=()=>{o(!1),h.current=null},h.current.onerror=()=>{u(r(`ttsButton.playbackFailed`)),o(!1),h.current=null})}catch(e){u(e instanceof Error?e.message:r(`ttsButton.generateFailed`)),Ve.error(`TTS error:`,e),o(!1),c(!1)}}};if((0,Y.useEffect)(()=>()=>{_.current=!0,h.current&&(h.current.pause(),h.current=null)},[]),p===!1||p===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,X.jsx)(`button`,{onClick:C,disabled:s||!e,title:l||r(a?`ttsButton.stopSpeaking`:s?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:W(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,l?`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:s?(0,X.jsx)(g,{className:W(T[n],`animate-spin`)}):a?(0,X.jsx)(te,{className:T[n]}):l?(0,X.jsx)(F,{className:T[n]}):(0,X.jsx)(k,{className:T[n]})})},Ye=/```([^\n`]*)\n([\s\S]*?)\n```/g,Xe=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,Ze=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],Qe=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:ot(e[1]),title:$e(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=ot(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function $e(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return tt(et(e))}function et(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 tt(e){let t=``,n=!1,r=null;for(let i=0;i<e.length;i+=1){let a=e[i];if(n){if(r){a===r&&(r=null);continue}if(a===`"`||a===`'`){r=a;continue}a===`>`&&(n=!1);continue}if(a===`<`){let t=e[i+1];if(t&&/[!/A-Za-z?]/.test(t)){n=!0;continue}}t+=a}return t}function nt(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return $e(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&$e(n[1]).trim()||null}function rt(e){let t=e.match(/(?:function|const)\s+(\w+)/);if(t)return t[1];let n=e.match(/class\s+(\w+)/);return n?n[1]:null}function it(e){if(e.includes(`def main(`))return`Python Script`;let t=e.match(/class\s+(\w+)/);if(t)return`${t[1]} Class`;let n=e.match(/def\s+(\w+)/);return n&&n[1]!==`__init__`?`${n[1]} Function`:null}function at(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 ot(e){let t=e.trim().toLowerCase();return Ze.includes(t)?t:`text`}function Z(e){if(!e)return;let t=e.trim().toLowerCase().replace(/^\./,``).replace(/[,:;]+$/,``);switch(t){case`htm`:case`html`:return`html`;case`js`:case`mjs`:case`javascript`:return`javascript`;case`jsx`:case`tsx`:case`react`:return`react`;case`ts`:case`typescript`:return`typescript`;case`py`:case`python`:return`python`;case`css`:case`svg`:case`json`:return t;default:return t||void 0}}function st(e){let t=[],n=new RegExp(Ye),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=ct(n,ut(e,r.index));t.push({raw:r[0],info:n,content:r[2].trim(),start:r.index,end:r.index+r[0].length,language:i.language,fileName:i.fileName})}return t}function ct(e,t){let n=lt(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!Xe.test(r)&&!r.includes(`=`)?Z(r):void 0)||Z(ft(n)),fileName:n}}function lt(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&Xe.test(t[1]))return dt(t[1]);let n=e.match(Xe);return n?dt(n[0]):void 0}function ut(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
2
- `).slice(-3).reverse();for(let e of n){let t=e.trim().replace(/^#{1,6}\s*/,``).replace(/^[-*]\s*/,``).replace(/[::]\s*$/,``).match(Xe);if(t)return dt(t[0])}}function dt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function ft(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function pt(e){return e?.split(/[\\/]/).pop()}function Q(e){let t=pt(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 mt(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function ht(e){let t=Z(e.language)||Z(ft(e.fileName));switch(t){case`html`:return{type:`html`,title:nt(e.content)||Q(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:Q(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:rt(e.content)||Q(e.fileName)||`React Component`,language:`jsx`};case`json`:return{type:`json`,title:Q(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:it(e.content)||Q(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:Q(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:at(e.content)||Q(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:Q(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:Q(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function gt(e){return(Z(e.language)||Z(ft(e.fileName)))===`html`}function _t(e){return(Z(e.language)||Z(ft(e.fileName)))===`css`}function vt(e){return(Z(e.language)||Z(ft(e.fileName)))===`javascript`}function yt(e){let t=st(e),n=t.filter(gt);if(n.length===0)return null;let r=t.filter(_t),i=t.filter(vt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=Ie(bt(a.content,r,i),r.map(e=>e.content),i.map(e=>e.content));return Tt(o,`html`)?{artifact:mt({type:`html`,title:nt(o)||Q(a.fileName)||`Interactive HTML App`,description:`Bundled generated HTML, CSS, and JavaScript files into one runnable artifact.`,content:o}),ranges:[a,...r,...i]}:null}function bt(e,t,n){let r=e;for(let e of t){let t=pt(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${wt(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=pt(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${wt(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function xt(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=st(e);if(St(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 Tt(s,`html`)?{artifact:mt({type:`html`,title:nt(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function St(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function Ct(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 wt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Tt(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&&(Le(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Z][^>]*>/.test(e)||/return\s*\(/.test(e);if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
3
- `).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return e.trim().length>200}function Et(e){let t=[],n=e;for(let e of Qe){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);Tt(n.content,n.type)&&(t.push(mt({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=Ct(n,r)}let r=yt(n);for(;r;)t.push(r.artifact),n=Ct(n,r.ranges),r=yt(n);let i=xt(n);i&&(t.push(i.artifact),n=Ct(n,i.ranges));let a=st(n),o=[];for(let e of a){let n=ht(e);!n||!Tt(e.content,n.type)||(t.push(mt({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=Ct(n,o),{content:n.trim(),artifacts:t}}var Dt=a(`components:chat-message`),Ot=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i})=>{let{t:a}=q(),o=e.role===`user`,s=e.role===`system`,{preferences:c}=Ne(),{user:u}=Pe(),{setSystemMessage:d,getCurrentPersona:f}=K(),p=f(),[h,g]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(e.content),[y,b]=(0,Y.useState)(null),[x,C]=(0,Y.useState)(!1),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(!1),[k,A]=(0,Y.useState)(!1),[ee,j]=(0,Y.useState)(!1),M=(0,Y.useRef)(null),N=(0,Y.useRef)(t),P=(0,Y.useRef)(!1),te=async()=>{try{await navigator.clipboard.writeText(e.content),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){Dt.error(`Failed to copy message:`,e)}},{thinkingContent:ne,parsedContent:F,artifacts:I}=(0,Y.useMemo)(()=>{if(o||s||!e.content)return{thinkingContent:null,parsedContent:e.content,artifacts:e.artifacts||[]};let n=Se(e.content),r=n.content;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,parsedContent:r,artifacts:e.artifacts};if(!t){let e=Et(r);return{thinkingContent:n.thinking,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,parsedContent:r,artifacts:[]}},[e.content,e.artifacts,o,s,t]);(0,Y.useEffect)(()=>{let e=N.current&&!t;return N.current=t,e&&!P.current&&!o&&!s&&F&&c.ttsSettings?.enabled&&c.ttsSettings?.autoPlay&&(P.current=!0,(async()=>{A(!0);try{let e=await ve.generateBase64({model:c.ttsSettings?.model||`tts-1`,input:F,voice:c.ttsSettings?.voice||`alloy`,speed:c.ttsSettings?.speed||1,response_format:`mp3`});if(e.success&&e.data?.audio){let t=`data:${e.data.mimeType};base64,${e.data.audio}`,n=new Audio(t);M.current=n,n.onended=()=>{A(!1),M.current=null},n.onerror=()=>{A(!1),M.current=null},await n.play()}}catch(e){Dt.error(`Auto-play TTS failed:`,e),A(!1)}})()),()=>{M.current&&(M.current.pause(),M.current=null)}},[t,o,s,F,c.ttsSettings]);let ie=()=>s?a(`chatMessage.system`):o?c.showUsername&&u?.username?u.username:a(`chatMessage.you`):p?.name?p.name:e.model||a(`chatMessage.assistant`),ae=()=>{g(!0),v(e.content)},oe=async()=>{C(!0);try{d(_),g(!1),Dt.debug(`✅ System message updated:`,_)}catch(e){Dt.error(`Failed to save system message:`,e)}finally{C(!1)}},se=()=>{g(!1),v(e.content)},ce=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,R=s&&e.content.length>100;return(0,X.jsxs)(`div`,{className:W(`group flex py-3 transition-colors sm:py-4`,o?`justify-end`:`justify-start`,n),children:[(0,X.jsx)(`div`,{className:W(`flex min-w-0`,o?`max-w-[88%] sm:max-w-[72%]`:`w-full`),children:(0,X.jsxs)(`div`,{className:W(`min-w-0 flex-1`,o?`rounded-[1.35rem] rounded-br-md border border-black/[0.06] bg-gray-900 px-4 py-3 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`:s?`bg-transparent py-2`:`bg-transparent py-1`),children:[!s&&(0,X.jsxs)(`div`,{className:W(`mb-2 flex items-center gap-2.5`,o&&`justify-end`),children:[(0,X.jsx)(`span`,{className:W(`text-[11px] font-semibold uppercase tracking-[0.1em]`,o?`text-white/70`:`text-gray-700 dark:text-dark-700`),children:ie()}),e.model&&!o&&p?.name&&(0,X.jsx)(`span`,{className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,X.jsx)(`span`,{className:W(`text-[10px] tabular-nums`,o?`text-white/45`:`text-gray-400 dark:text-dark-500`),children:Ce(e.timestamp)})]}),(0,X.jsxs)(`div`,{className:W(o?`text-[15px] text-white`:`text-[15px] leading-7 text-gray-800 dark:text-dark-800 sm:text-base`),children:[e.images&&e.images.length>0&&(0,X.jsx)(`div`,{className:`mb-3 grid max-w-lg grid-cols-2 gap-2 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,X.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-white/10 bg-gray-100 dark:bg-gray-800`,children:(0,X.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>b(e)})},t))}),o?(0,X.jsx)(`p`,{className:`whitespace-pre-wrap leading-relaxed`,children:e.content}):s?(0,X.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,X.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(B,{className:`h-2.5 w-2.5 opacity-50`}),a(`chatMessage.system`)]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:h?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:oe,disabled:x,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:a(`chatMessage.saveChanges`),children:(0,X.jsx)(l,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,X.jsx)(`button`,{onClick:se,disabled:x,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:a(`chatMessage.cancelEditing`),children:(0,X.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,X.jsx)(`button`,{onClick:ae,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:a(`chatMessage.editSystemMessage`),children:(0,X.jsx)(m,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),h?(0,X.jsx)(`textarea`,{value:_,onChange:e=>v(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:a(`chatMessage.systemMessagePlaceholder`),disabled:x}):(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:w?e.content:ce(e.content)}),R&&(0,X.jsx)(`button`,{onClick:()=>T(!w),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:w?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(re,{className:`h-3 w-3`}),a(`chatMessage.showLess`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(O,{className:`h-3 w-3`}),a(`chatMessage.showMore`)]})})]})]}):(0,X.jsxs)(`div`,{className:`relative`,children:[ne&&(0,X.jsxs)(`div`,{className:`mb-4 border-l border-gray-200 pl-3 dark:border-dark-300`,children:[(0,X.jsxs)(`button`,{onClick:()=>D(!E),className:`flex items-center gap-2 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,X.jsx)(de,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`font-medium`,children:a(`chatMessage.thinking`)}),E?(0,X.jsx)(re,{className:`h-4 w-4`}):(0,X.jsx)(O,{className:`h-4 w-4`})]}),E&&(0,X.jsx)(`div`,{className:`mt-3 rounded-xl bg-gray-100/60 p-3 dark:bg-dark-200/60`,children:(0,X.jsx)(`p`,{className:`whitespace-pre-wrap text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:ne})})]}),(0,X.jsx)(ke,{content:F,isStreaming:t}),t&&!F.includes("```")&&(0,X.jsx)(`div`,{className:`ml-1 inline-block h-5 w-1 animate-pulse rounded-full bg-primary-500`})]}),!o&&!s&&I.length>0&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Re,{artifacts:I})}),!o&&!s&&e.statistics&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Be,{statistics:e.statistics})}),!s&&!t&&(0,X.jsxs)(`div`,{className:W(`mt-3 flex items-center gap-1`,o?`justify-end border-t border-white/10 pt-2 text-white/65`:`text-gray-400 dark:text-dark-500`),children:[!o&&F&&(0,X.jsx)(Je,{text:F,size:`sm`,className:W(`transition-colors`,k&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),(0,X.jsx)(`button`,{onClick:te,className:W(`flex h-8 w-8 items-center justify-center rounded-full transition-colors`,o?`hover:bg-white/10 hover:text-white`:`hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`),title:a(ee?`chatMessage.copied`:`chatMessage.copyMessage`),children:ee?(0,X.jsx)(ue,{className:`h-3.5 w-3.5 text-green-400`}):(0,X.jsx)(le,{className:`h-3.5 w-3.5`})}),!o&&r&&i&&(0,X.jsx)(`button`,{onClick:i,className:`flex h-8 w-8 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:a(`chatMessage.regenerateResponse`),children:(0,X.jsx)(S,{className:`h-3.5 w-3.5`})})]})]})]})}),y&&(0,ze.createPortal)((0,X.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":a(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>b(null),children:[(0,X.jsx)(`button`,{className:`absolute right-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(),b(null)},children:(0,X.jsx)(L,{className:`h-7 w-7`})}),(0,X.jsx)(`img`,{src:y,alt:a(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},kt=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingMessageId:r,isLastAssistantMessage:i=!1,onRegenerate:a,onSelectBranch:o,className:s})=>{if(e.length===1){let o=e[0],c=t&&r===o.id;return(0,X.jsx)(Ot,{message:c&&n?{...o,content:n}:o,isStreaming:c,isLastAssistantMessage:i,onRegenerate:a,className:s})}return(0,X.jsxs)(`div`,{className:W(`relative py-2`,s),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500`,children:[(0,X.jsx)(D,{className:`h-3 w-3`}),(0,X.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let c=e.isActive!==!1,l=t&&r===e.id,u=l&&n?{...e,content:n}:e;return(0,X.jsxs)(`div`,{className:W(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,c||l?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!c&&!l&&`cursor-pointer`),role:!c&&!l?`button`:void 0,tabIndex:!c&&!l?0:void 0,onClick:()=>!c&&!l&&o?.(e.id),onKeyDown:t=>{!c&&!l&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),o?.(e.id))},children:[(0,X.jsxs)(`div`,{className:W(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,c||l?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`font-medium`,children:s+1}),l&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),c&&!l&&(0,X.jsx)(ue,{className:`h-3 w-3`}),!c&&!l&&(0,X.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,X.jsx)(`div`,{className:W(!c&&!l&&`opacity-75`),children:(0,X.jsx)(Ot,{message:u,isStreaming:l,isLastAssistantMessage:i&&(c||l),onRegenerate:c&&!t?a:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},At={web_search:b,web_fetch:E,exec:j,browser:E,Read:z,Write:z,Edit:z,image:w,memory_search:ee,memory_get:ee,working:se,thinking:se,default:se},jt={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`},Mt=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,X.jsx)(`div`,{className:W(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=At[e.name]||At.default,n=jt[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,X.jsxs)(`div`,{className:W(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,X.jsx)(`div`,{className:W(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,X.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,X.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,X.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};a(`components:chat-messages`);var Nt=({messages:e,streamingMessage:t,streamingMessageId:n,isStreaming:r=!1,toolActivities:i=[],className:a,onRegenerate:o,onSelectBranch:c})=>{let{t:l}=q(),u=(0,Y.useRef)(null),d=(0,Y.useRef)(),f=(0,Y.useRef)(null),p=(0,Y.useRef)(!1),[m,h]=(0,Y.useState)(!1),g=(0,Y.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),_=(0,Y.useCallback)((e=!1)=>{p.current&&!e||u.current?.scrollIntoView({behavior:`smooth`})},[]),v=(0,Y.useCallback)(()=>{let t=f.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i<100;p.current=!a,h(!a&&e.length>0)},[e.length]),y=(0,Y.useRef)(e.length);if((0,Y.useEffect)(()=>{e.length>y.current&&!p.current&&_(),y.current=e.length},[e.length,_]),(0,Y.useEffect)(()=>{r&&t&&!p.current&&requestAnimationFrame(()=>{let e=f.current;e&&(e.scrollTop=e.scrollHeight)})},[r,t]),(0,Y.useEffect)(()=>{let e=d.current;return()=>{e&&clearTimeout(e)}},[]),e.length===0&&!r)return(0,X.jsx)(`div`,{className:W(`flex-1 flex items-center justify-center p-6 sm:p-10`,a),children:(0,X.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,X.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-white/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,X.jsx)(s,{className:`h-4 w-4`})}),(0,X.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:l(`chatMessage.startConversation`)}),(0,X.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:l(`chatMessage.startConversationDescription`)})]})});let b=-1;for(let e=g.length-1;e>=0;e--)if(g[e].messages.some(e=>e.role===`assistant`)){b=e;break}return(0,X.jsxs)(`div`,{ref:f,onScroll:v,className:W(`relative flex-1 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]`,a),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`,WebkitAppRegion:`no-drag`},children:[(0,X.jsxs)(`div`,{className:`mx-auto w-full min-w-0 max-w-4xl px-4 sm:px-6 md:px-8`,children:[g.map((e,i)=>{let a=i===b,s=r&&e.messages.some(e=>e.id===n);if(e.messages.length===1){let s=e.messages[0],c=r&&s.id===n;return(0,X.jsx)(Ot,{message:c&&t?{...s,content:t}:s,isStreaming:c,isLastAssistantMessage:a,onRegenerate:a?o:void 0,className:i===0?`mt-5 sm:mt-7`:``},s.id)}return(0,X.jsx)(kt,{messages:e.messages,isStreaming:s,streamingMessage:t,streamingMessageId:n||void 0,isLastAssistantMessage:a,onRegenerate:a?o:void 0,onSelectBranch:c,className:i===0?`mt-5 sm:mt-7`:``},e.id)}),r&&i.length>0&&(0,X.jsx)(Mt,{tools:i,className:`px-0`}),(0,X.jsx)(`div`,{ref:u,className:`h-4 sm:h-6`})]}),m&&(0,X.jsxs)(`button`,{onClick:()=>{p.current=!1,u.current?.scrollIntoView({behavior:`smooth`}),h(!1)},className:W(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-white/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-white dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:l(`chatMessage.scrollToBottom`),children:[(0,X.jsx)(C,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:l(`chatMessage.newMessages`)})]})]})};function Pt(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 Ft=Y.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,...o},s)=>{let{hasCodeBlocks:c,isInCodeBlock:l,language:u}=(0,Y.useMemo)(()=>Pt(e),[e]);return(0,X.jsxs)(`div`,{className:`relative w-full`,children:[(0,X.jsx)(`textarea`,{ref:s,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,className:W(`w-full resize-none transition-all duration-200`,l&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...o}),c&&(0,X.jsx)(`div`,{className:`absolute right-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,X.jsxs)(`div`,{className:W(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,l&&`animate-pulse`),children:[(0,X.jsx)(y,{className:`h-3 w-3`}),u&&(0,X.jsx)(`span`,{children:u}),!u&&l&&(0,X.jsx)(`span`,{children:`code`})]})})]})});Ft.displayName=`CodeAwareTextarea`;var It=a(`components:media-upload`),Lt=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:s}=q(),c=(0,Y.useRef)(null),[l,u]=(0,Y.useState)(!1),[d,f]=(0,Y.useState)(!1),[p,m]=(0,Y.useState)([]),h=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await _(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await v(n):T.error(`File type not supported: ${n.name}`)}},_=async r=>{if(n-e.length<=0){T.error(`Maximum ${n} images allowed`);return}if(r.size>10*1024*1024){T.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},v=async e=>{if(e.size>10*1024*1024){T.error(`File size must be less than 10MB`);return}f(!0);try{let t=await U.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;m(e=>[...e,n]),i?.(n),T.success(`Document "${e.name}" uploaded`)}else T.error(t.error||`Failed to upload document`)}catch(e){It.error(`Document upload error:`,e),T.error(`Failed to upload document`)}finally{f(!1)}},y=e=>{e.preventDefault(),a||u(!0)},b=e=>{e.preventDefault(),u(!1)},x=e=>{e.preventDefault(),u(!1),a||h(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},C=async e=>{try{let t=await U.deleteDocument(e);t.success?(m(t=>t.filter(t=>t.id!==e)),T.success(`Document removed`)):T.error(t.error||`Failed to remove document`)}catch(e){It.error(`Error removing document:`,e),T.error(`Failed to remove document`)}},w=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},E=e.length>0||p.length>0;return(0,X.jsxs)(`div`,{className:W(`space-y-3`,o),children:[(0,X.jsxs)(`div`,{className:W(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,l&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:y,onDragLeave:b,onDrop:x,onClick:()=>!a&&c.current?.click(),children:[(0,X.jsx)(`input`,{ref:c,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{h(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[d?(0,X.jsx)(g,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,X.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[s(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:s(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:s(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,X.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),S(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,X.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),p.map(e=>(0,X.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,X.jsx)(z,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,X.jsx)(N,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,X.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:w(e.size)})]}),(0,X.jsx)(`button`,{onClick:t=>{t.stopPropagation(),C(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,X.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},Rt=a(`components:document-indicator`),zt=({sessionId:e,className:t=``})=>{let[n,r]=(0,Y.useState)([]);if((0,Y.useEffect)(()=>{e&&(async()=>{try{let t=await U.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){Rt.error(`Failed to load documents:`,e)}})()},[e]),!e||n.length===0)return null;let i=n.reduce((e,t)=>e+t.size,0);return(0,X.jsxs)(`div`,{className:`
4
- inline-flex items-center space-x-1 px-2 py-1
5
- bg-blue-50 dark:bg-blue-900/20
6
- border border-blue-200 dark:border-blue-800
7
- rounded-md text-xs
8
- ${t}
9
- `,title:`${n.length} document(s) available for context - Total: ${(e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]})(i)}`,children:[(0,X.jsx)(u,{className:`w-3 h-3 text-blue-600 dark:text-blue-400`}),(0,X.jsxs)(`span`,{className:`text-blue-700 dark:text-blue-300 font-medium`,children:[n.length,` doc`,n.length===1?``:`s`]})]})},Bt=a(`components:structured-output`),Vt=[{key:`none`,value:null},{key:`json`,value:`json`},{key:`list`,value:{type:`object`,properties:{items:{type:`array`,items:{type:`string`}}},required:[`items`]}},{key:`summary`,value:{type:`object`,properties:{title:{type:`string`},summary:{type:`string`},key_points:{type:`array`,items:{type:`string`}}},required:[`title`,`summary`,`key_points`]}},{key:`analysis`,value:{type:`object`,properties:{analysis:{type:`string`},pros:{type:`array`,items:{type:`string`}},cons:{type:`array`,items:{type:`string`}},recommendation:{type:`string`}},required:[`analysis`,`pros`,`cons`,`recommendation`]}},{key:`custom`,value:`custom`}],Ht=({format:e,onFormatChange:t,className:n})=>{let{t:r}=q(),[i,a]=(0,Y.useState)(!1),[o,s]=(0,Y.useState)(``),c=()=>Vt.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),l=()=>{let t=c();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},u=e=>{let n=c().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,X.jsxs)(`div`,{className:W(`space-y-3`,n),children:[(0,X.jsx)(`div`,{className:`flex items-center justify-between`,children:(0,X.jsxs)(`div`,{className:`flex items-center`,children:[(0,X.jsx)(B,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.title`)})]})}),(0,X.jsx)(je,{value:l().label,onChange:e=>u(e.target.value),options:c().map(e=>({value:e.label,label:e.label}))}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l().description}),i&&(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(Ae,{value:o,onChange:e=>s(e.target.value),placeholder:`{
10
- "type": "object",
11
- "properties": {
12
- "field1": { "type": "string" },
13
- "field2": { "type": "number" }
14
- },
15
- "required": ["field1"]
16
- }`,rows:8,className:`font-mono text-sm`}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(G,{onClick:()=>{try{t(JSON.parse(o)),a(!1)}catch(e){Bt.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!o.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,X.jsx)(G,{onClick:()=>{a(!1),s(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=l();return!e.value||e.value===`json`?null:(0,X.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,X.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,X.jsx)(M,{className:`h-4 w-4 text-gray-500 mr-2`}),(0,X.jsx)(`span`,{className:`text-sm font-medium text-gray-700 dark:text-gray-300`,children:r(`chat.structuredOutput.schemaPreview`)})]}),(0,X.jsx)(`pre`,{className:`text-xs text-gray-700 dark:text-gray-300 overflow-x-auto`,children:JSON.stringify(e.value,null,2)})]})})(),e&&(0,X.jsxs)(`div`,{className:`flex items-center text-xs text-green-600 dark:text-green-400`,children:[(0,X.jsx)(z,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})};function Ut(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function Wt({hfTask:e,hfSort:t,canInstallModels:n,loadingHf:r,hfModels:i,expandedHfModel:a,hfGgufFiles:o,loadingGguf:s,pullingModel:c,pullProgress:l,setHfTask:u,setHfSort:d,onToggleHfModel:p,onPullHfGguf:m,onCancelPull:h,onRefreshHfModels:g}){let{t:_}=q();return(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0 space-y-2`,children:(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsxs)(`select`,{value:e,onChange:e=>u(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`flex-1 px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,children:[(0,X.jsx)(`option`,{value:`text-generation`,children:_(`modelManager.huggingface.taskTextGeneration`)}),(0,X.jsx)(`option`,{value:`text-to-speech`,children:_(`modelManager.huggingface.taskTextToSpeech`)}),(0,X.jsx)(`option`,{value:`text-to-image`,children:_(`modelManager.huggingface.taskTextToImage`)}),(0,X.jsx)(`option`,{value:`automatic-speech-recognition`,children:_(`modelManager.huggingface.taskSpeechRecognition`)})]}),(0,X.jsxs)(`select`,{value:t,onChange:e=>d(e.target.value),onMouseDown:e=>e.stopPropagation(),className:`px-2 py-1.5 rounded-lg border text-xs bg-gray-50 dark:bg-dark-50 border-gray-200 dark:border-dark-300 text-gray-900 dark:text-gray-100`,children:[(0,X.jsx)(`option`,{value:`downloads`,children:_(`modelManager.huggingface.sortDownloads`)}),(0,X.jsx)(`option`,{value:`likes`,children:_(`modelManager.huggingface.sortLikes`)}),(0,X.jsx)(`option`,{value:`lastModified`,children:_(`modelManager.huggingface.sortRecent`)})]})]})}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[!n&&(0,X.jsx)(`div`,{className:`mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300`,children:_(`modelSelector.pullRestricted`)}),r?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,X.jsx)(H,{className:`h-6 w-6 animate-spin text-gray-400`})}):i.length===0?(0,X.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,X.jsx)(R,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,X.jsx)(`p`,{className:`text-sm`,children:_(`modelManager.huggingface.noModelsFound`)})]}):(0,X.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:i.map(e=>{let t=a===e.id,r=o[e.id]||[],i=s===e.id;return(0,X.jsxs)(`div`,{className:`bg-white dark:bg-dark-100`,children:[(0,X.jsx)(`div`,{className:`px-3 py-3 cursor-pointer hover:bg-gray-50 dark:hover:bg-dark-200`,onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),p(e.id)},children:(0,X.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`p-2 rounded-lg bg-yellow-100 dark:bg-yellow-900/30 flex-shrink-0`,children:(0,X.jsx)(R,{className:`h-4 w-4 text-yellow-600 dark:text-yellow-400`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.id}),e.gated&&(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-400`,children:`Gated`})]}),(0,X.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-0.5`,children:[`by `,e.author]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-3 mt-1.5 text-xs text-gray-400 dark:text-gray-500`,children:[(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(ce,{className:`h-3 w-3`}),Ut(e.downloads)]}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(f,{className:`h-3 w-3`}),Ut(e.likes)]}),e.pipeline_tag&&(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-gray-100 dark:bg-dark-200`,children:e.pipeline_tag})]})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 flex-shrink-0`,children:[(0,X.jsx)(`a`,{href:`https://huggingface.co/${e.id}`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,X.jsx)(ae,{className:`h-4 w-4 text-gray-400`})}),(0,X.jsx)(O,{className:W(`h-4 w-4 text-gray-400 transition-transform`,t&&`rotate-180`)})]})]})}),t&&(0,X.jsx)(`div`,{className:`px-3 pb-3 pt-1 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-200`,children:i?(0,X.jsxs)(`div`,{className:`flex items-center justify-center py-4`,children:[(0,X.jsx)(H,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,X.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:_(`modelManager.huggingface.checkingGguf`)})]}):r.length===0?(0,X.jsx)(`div`,{className:`py-4 text-center text-xs text-gray-500 dark:text-gray-400`,children:_(`modelManager.huggingface.noGgufAvailable`)}):(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-gray-600 dark:text-gray-300 mb-2`,children:_(`modelManager.huggingface.ggufFilesCount`,{count:r.length})}),r.map(e=>{let t=c===e.ollamaCommand;return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 p-2 rounded-lg bg-white dark:bg-dark-100 border border-gray-200 dark:border-dark-300`,children:[(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-xs font-medium text-gray-800 dark:text-gray-200 truncate`,children:e.filename}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5 text-xs text-gray-500 dark:text-gray-400`,children:[(0,X.jsx)(`span`,{children:e.sizeFormatted}),e.quantization&&(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-400`,children:e.quantization})]})]}),t?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:l?.percent===void 0?`...`:`${l.percent}%`}),(0,X.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),h()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,X.jsx)(L,{className:`h-4 w-4`})})]}):n?(0,X.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),m(e.ollamaCommand,e.filename)},disabled:!!c,className:W(`px-3 py-1.5 rounded-lg text-xs font-medium`,`bg-primary-100 dark:bg-primary-900/30`,`text-primary-700 dark:text-primary-400`,`hover:bg-primary-200 dark:hover:bg-primary-900/50`,`disabled:opacity-50 disabled:cursor-not-allowed`),children:[(0,X.jsx)(ce,{className:`h-3 w-3 inline mr-1`}),_(`models.pull`)]}):(0,X.jsx)(`span`,{className:`px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`,children:_(`modelSelector.adminOnlyPull`)})]},e.filename)}),c?.startsWith(`hf.co/`)&&c.includes(e.id)&&l?.percent!==void 0&&(0,X.jsx)(`div`,{className:`w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden mt-2`,children:(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${l.percent}%`}})})]})})]},e.id)})})]}),(0,X.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 flex items-center justify-between flex-shrink-0`,children:[(0,X.jsxs)(`a`,{href:`https://huggingface.co/models`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 hover:underline flex items-center gap-1`,children:[(0,X.jsx)(ae,{className:`h-3 w-3`}),_(`modelManager.huggingface.browseAllLink`)]}),(0,X.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),g()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,X.jsx)(S,{className:W(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}function Gt({filteredGroups:e,selectedModel:t,showImageGen:n,getModelIcon:r,getModelLabel:i,getModelSubLabel:a,onModelSelect:o,onOpenGallery:s}){let{t:c}=q();return(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400`,children:[e.length>0?e.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-dark-300 border-b border-gray-200 dark:border-dark-400 sticky top-0`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e.icon,e.label,` (`,e.models.length,`)`]})}),e.models.map(e=>(0,X.jsx)(`div`,{onMouseDown:t=>{t.preventDefault(),o(e.name)},className:W(`px-3 py-3 cursor-pointer border-b border-gray-100 dark:border-dark-200 last:border-b-0`,`hover:bg-gray-50 dark:hover:bg-dark-200`,`bg-white dark:bg-dark-100 transition-colors`,t===e.name&&`bg-primary-50 dark:bg-primary-900/30`),children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[r(e),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:i(e)}),a(e)&&(0,X.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:a(e)})]}),t===e.name&&(0,X.jsx)(ue,{className:`h-4 w-4 text-primary-600 dark:text-primary-400 flex-shrink-0`})]})},e.name))]},e.type)):(0,X.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,X.jsx)(I,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,X.jsx)(`p`,{className:`text-sm`,children:c(`models.noModelsFound`)})]}),n&&(0,X.jsxs)(`div`,{className:`border-t border-gray-200 dark:border-dark-300`,children:[(0,X.jsx)(`div`,{className:`px-3 py-2 text-xs font-semibold text-gray-500 dark:text-gray-400 bg-gray-100 dark:bg-dark-300`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(d,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),c(`modelSelector.actions`)]})}),(0,X.jsx)(`div`,{onMouseDown:e=>{e.preventDefault(),s()},className:`px-3 py-3 cursor-pointer hover:bg-blue-50 dark:hover:bg-blue-900/20 bg-white dark:bg-dark-100`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(w,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),(0,X.jsxs)(`div`,{className:`flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:c(`gallery.generate`)}),(0,X.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:c(`gallery.generateDescription`)})]})]})})]})]})}function Kt({libraryCategories:e,libraryCategory:t,canInstallModels:n,loadingLibrary:r,filteredLibraryModels:i,pullingModel:a,pullProgress:o,setLibraryCategory:s,isModelInstalled:c,onModelSelect:l,onPullModel:u,onCancelPull:d,onRefreshLibrary:f}){let{t:p}=q();return(0,X.jsxs)(`div`,{className:`flex-1 flex flex-col overflow-hidden`,children:[(0,X.jsx)(`div`,{className:`px-3 py-2 border-b border-gray-200 dark:border-dark-300 flex-shrink-0`,children:(0,X.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map(e=>(0,X.jsx)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),s(e)},className:W(`px-2.5 py-1 rounded-full text-xs font-medium transition-colors`,t===e?`bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400`:`bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400 hover:bg-gray-200 dark:hover:bg-dark-300`),children:e.charAt(0).toUpperCase()+e.slice(1)},e))})}),(0,X.jsxs)(`div`,{className:`flex-1 overflow-y-auto`,children:[!n&&(0,X.jsx)(`div`,{className:`mx-3 mt-3 mb-1 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-800 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-300`,children:p(`modelSelector.pullRestricted`)}),r?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,X.jsx)(H,{className:`h-6 w-6 animate-spin text-gray-400`})}):i.length===0?(0,X.jsxs)(`div`,{className:`px-4 py-8 text-center text-gray-500 dark:text-gray-400`,children:[(0,X.jsx)(P,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,X.jsx)(`p`,{className:`text-sm`,children:p(`models.noModelsFound`)})]}):(0,X.jsx)(`div`,{className:`divide-y divide-gray-100 dark:divide-dark-200`,children:i.slice(0,50).map(e=>{let t=c(e.name),r=a===e.name;return(0,X.jsxs)(`div`,{className:W(`px-3 py-3 bg-white dark:bg-dark-100`,t&&`bg-green-50/50 dark:bg-green-900/10`),children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,X.jsx)(`div`,{className:`p-2 rounded-lg bg-blue-100 dark:bg-blue-900/30 flex-shrink-0`,children:(0,X.jsx)(P,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`})}),(0,X.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`h4`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:e.name}),t&&(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400`,children:p(`modelSelector.installed`)}),(e.category===`cloud`||e.tags?.includes(`cloud`))&&(0,X.jsxs)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-400 flex items-center gap-1`,children:[(0,X.jsx)(P,{className:`h-3 w-3`}),`Cloud`]})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 line-clamp-1 mt-0.5`,children:e.description}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2 mt-1.5`,children:[e.sizes.slice(0,3).map(e=>(0,X.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-xs bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:e},e)),e.pulls&&(0,X.jsxs)(`span`,{className:`text-xs text-gray-400 dark:text-gray-500 flex items-center gap-1`,children:[(0,X.jsx)(ce,{className:`h-3 w-3`}),e.pulls]})]})]}),(0,X.jsx)(`div`,{className:`flex-shrink-0`,children:r?(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`div`,{className:`text-xs text-gray-500 w-12 text-right`,children:o?.percent===void 0?`...`:`${o.percent}%`}),(0,X.jsx)(`button`,{onClick:d,className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,X.jsx)(L,{className:`h-4 w-4`})})]}):t?(0,X.jsx)(`button`,{onClick:()=>l(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-400 hover:bg-green-200 dark:hover:bg-green-900/50`,children:p(`modelSelector.use`)}):n?(0,X.jsxs)(`button`,{onClick:()=>u(e.name),className:`px-3 py-1.5 rounded-lg text-xs font-medium bg-primary-100 dark:bg-primary-900/30 text-primary-700 dark:text-primary-400 hover:bg-primary-200 dark:hover:bg-primary-900/50`,children:[(0,X.jsx)(ce,{className:`h-3 w-3 inline mr-1`}),p(`modelSelector.pull`)]}):(0,X.jsx)(`span`,{className:`px-2 py-1 rounded text-[11px] font-medium bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`,children:p(`modelSelector.adminOnlyPull`)})})]}),r&&o?.percent!==void 0&&(0,X.jsx)(`div`,{className:`mt-2 w-full bg-gray-200 dark:bg-dark-300 rounded-full h-1.5 overflow-hidden`,children:(0,X.jsx)(`div`,{className:`h-1.5 rounded-full bg-primary-500 transition-all duration-300`,style:{width:`${o.percent}%`}})})]},e.name)})})]}),(0,X.jsxs)(`div`,{className:`px-3 py-2 border-t border-gray-200 dark:border-dark-300 flex items-center justify-between flex-shrink-0`,children:[(0,X.jsxs)(`a`,{href:`https://ollama.com/library`,target:`_blank`,rel:`noopener noreferrer`,onMouseDown:e=>e.stopPropagation(),className:`text-xs text-primary-600 dark:text-primary-400 hover:underline flex items-center gap-1`,children:[(0,X.jsx)(ae,{className:`h-3 w-3`}),p(`modelManager.huggingface.browseAllLink`)]}),(0,X.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),f()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,X.jsx)(S,{className:W(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}var qt=a(`components:model-selector`),Jt=({models:e,selectedModel:t,onModelChange:n,currentPersona:r,className:a,disabled:o=!1,compact:c=!1,showImageGen:l=!1,onModelsRefresh:u})=>{let{t:d}=q(),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)(``),[g,_]=(0,Y.useState)(`installed`),v=(0,Y.useRef)(null),y=(0,Y.useRef)(null),S=Te(),{user:C,systemInfo:w}=Pe(),E=C?.role===`admin`||(w?.allowUserModelPull??!0),[D,k]=(0,Y.useState)(`all`),[A,ee]=(0,Y.useState)(``),[j,M]=(0,Y.useState)(`text-generation`),[N,te]=(0,Y.useState)(`downloads`),[ne,F]=(0,Y.useState)(``),[I,re]=(0,Y.useState)(null),[ae,se]=(0,Y.useState)({}),[ce,z]=(0,Y.useState)(null),[le,B]=(0,Y.useState)(null),[ue,V]=(0,Y.useState)(null),[fe,H]=(0,Y.useState)(null),pe=[`all`,`popular`,`chat`,`code`,`vision`,`embedding`,`cloud`],me=[{type:`personas`,label:d(`modelSelector.personas`),icon:(0,X.jsx)(ie,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPersona),color:`purple`},{type:`ollama`,label:d(`modelSelector.ollamaModels`),icon:(0,X.jsx)(x,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>!e.isPersona&&!e.isPlugin&&!e.name.includes(`embed`)),color:`green`},{type:`plugins`,label:d(`modelSelector.pluginModels`),icon:(0,X.jsx)(R,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPlugin),color:`green`}].filter(e=>e.models.length>0).map(e=>({...e,models:e.models.filter(e=>e.name.toLowerCase().includes(m.toLowerCase())||e.personaName&&e.personaName.toLowerCase().includes(m.toLowerCase())||e.pluginName&&e.pluginName.toLowerCase().includes(m.toLowerCase()))})).filter(e=>e.models.length>0),U=e.find(e=>e.name===t||t.startsWith(`persona:`)&&e.name===t),{data:_e=[],isLoading:ve,refetch:ye}=i({queryKey:[`ollama-library-selector`,A,D],queryFn:async()=>{let e=await he.getLibraryModels({search:A||void 0,sort:`popular`,category:D===`cloud`?`cloud`:void 0});return e.success&&e.data?e.data:[]},enabled:f&&g===`ollama`}),{data:be=[],isLoading:xe,refetch:Se}=i({queryKey:[`hf-models-selector`,j,ne,N],queryFn:async()=>{let e=await ge.getModels({task:j,search:ne||void 0,sort:N,limit:30});return e.success&&e.data?e.data:[]},enabled:f&&g===`huggingface`}),Ce=_e.filter(e=>{let t=!m||e.name.toLowerCase().includes(m.toLowerCase())||e.description.toLowerCase().includes(m.toLowerCase()),n=D===`all`||e.category===D;return t&&n}),we=(0,Y.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){z(e);try{let r=await ge.getGgufFiles(t,n);r.success&&r.data&&se(t=>({...t,[e]:r.data}))}catch(e){qt.error(`Failed to load GGUF files:`,e)}finally{z(null)}}},[]),G=(0,Y.useCallback)(e=>{I===e?re(null):(re(e),ae[e]||we(e))},[I,ae,we]),K=(0,Y.useCallback)((e,t)=>{if(!E){T.error(d(`modelSelector.pullRestricted`));return}if(!le){B(e),V({status:`starting`});try{let n=he.pullModelStream(e,e=>{V(e)},()=>{V(null),B(null),H(null),T.success(`Downloaded ${t}`),u?.()},e=>{V(null),B(null),H(null),T.error(`Failed to download: ${e}`)});H(()=>n)}catch{V(null),B(null),T.error(`Failed to start download`)}}},[E,u,le,d]);(0,Y.useEffect)(()=>{let e=setTimeout(()=>{g===`huggingface`?F(m):g===`ollama`&&ee(m)},300);return()=>clearTimeout(e)},[m,g]),(0,Y.useEffect)(()=>{if(!f)return;let e=e=>{e.key===`Escape`&&(p(!1),h(``))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[f]),(0,Y.useEffect)(()=>{f&&y.current&&y.current.focus()},[f]);let Ee=async e=>{p(!1),h(``);try{let t=await he.listRunningModels();if(t.success&&t.data){let n=t.data;n.length>0&&(n.some(t=>t.name===e||e.startsWith(`persona:`))||await he.unloadAllModels())}}catch(e){qt.warn(`Failed to unload models before switch:`,e)}n({target:{value:e}})},J=async e=>{if(!E){T.error(d(`modelSelector.pullRestricted`));return}if(!le){B(e),V({status:`starting`});try{let t=he.pullModelStream(e,e=>{V(e)},()=>{V(null),B(null),H(null),T.success(`Downloaded ${e}`),u?.()},e=>{V(null),B(null),H(null),T.error(`Failed to download: ${e}`)});H(()=>t)}catch{V(null),B(null),T.error(`Failed to start download`)}}},De=()=>{fe&&(fe(),H(null),B(null),V(null),T.success(`Download cancelled`))},Oe=t=>e.some(e=>e.name===t||e.name.startsWith(t+`:`)),ke=e=>e.isPersona?(0,X.jsx)(ie,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):e.isPlugin?(0,X.jsx)(R,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):(0,X.jsx)(x,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),Ae=e=>e.isPersona?e.personaName||e.name:e.isPlugin?`${e.name}`:e.name,je=e=>e.isPersona?`via ${e.model}`:e.isPlugin?`via ${e.pluginName}`:null;return(0,X.jsxs)(`div`,{className:W(`relative`,a),ref:v,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>!o&&p(!f),disabled:o,"aria-haspopup":`dialog`,"aria-expanded":f,className:W(c?`h-9 sm:h-10 px-2.5 flex items-center justify-between text-left w-full`:`w-full flex items-center justify-between gap-2 px-3 py-2.5 text-left`,`border border-black/[0.06] bg-gray-100/70 dark:border-white/[0.06] dark:bg-dark-300/70`,`rounded-xl text-sm hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500/40`,o?`opacity-50 cursor-not-allowed`:`cursor-pointer`),title:c?U?Ae(U):d(`modelSelector.selectModel`):void 0,children:[(()=>{if(!U)return c?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,X.jsx)(x,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-xs font-medium text-gray-400 dark:text-gray-500 truncate`,children:d(`modelSelector.selectModel`)})]}):d(`modelSelector.selectModel`);if(c){let e=Ae(U);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[ke(U),(0,X.jsx)(`span`,{className:`text-xs font-medium text-gray-700 dark:text-gray-200 truncate`,children:e})]})}let e=Ae(U),t=je(U);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[ke(U),(0,X.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium truncate`,children:e}),t&&(0,X.jsx)(`span`,{className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:t})]}),U.isPersona&&r&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 ml-auto`,children:[(0,X.jsx)(de,{className:`h-3 w-3 text-gray-500 dark:text-dark-600`}),r.embedding_model&&(0,X.jsx)(s,{className:`h-3 w-3 text-gray-400 dark:text-dark-500`})]})]})})(),(0,X.jsx)(O,{className:W(c?`h-3 w-3`:`h-4 w-4`,`text-gray-400 flex-shrink-0 transition-transform duration-150`,f&&`rotate-180`)})]}),f&&(0,ze.createPortal)((0,X.jsxs)(`div`,{className:`fixed inset-0 z-[999999] flex items-center justify-center p-3 sm:p-6`,children:[(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gray-950/55 backdrop-blur-md`,onClick:()=>{p(!1),h(``)}}),(0,X.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":d(`modelSelector.selectModel`),className:W(`relative flex w-full max-w-xl flex-col overflow-hidden bg-white/[0.98] dark:bg-dark-25/[0.98]`,`h-[min(620px,88vh)] rounded-[1.5rem] border border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_30px_100px_rgba(0,0,0,0.28)] backdrop-blur-xl animate-scale-in`),onClick:e=>e.stopPropagation(),children:[(0,X.jsxs)(`div`,{className:`flex-shrink-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between px-4 pb-2 pt-4 sm:px-5 sm:pt-5`,children:[(0,X.jsx)(`h2`,{className:`text-lg font-medium tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:d(`modelSelector.selectModel`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{p(!1),h(``)},className:`flex h-9 w-9 items-center justify-center rounded-full text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-950 dark:text-dark-500 dark:hover:bg-dark-200 dark:hover:text-dark-950`,title:d(`common.close`),children:(0,X.jsx)(L,{className:`h-4 w-4`})})]}),(0,X.jsx)(`div`,{className:`px-4 pb-3 sm:px-5`,children:(0,X.jsxs)(`div`,{className:`relative`,children:[(0,X.jsx)(b,{className:`absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{ref:y,type:`text`,placeholder:d(g===`installed`?`modelSelector.searchInstalled`:g===`ollama`?`modelSelector.searchOllama`:`modelSelector.searchHuggingFace`),value:m,onChange:e=>h(e.target.value),className:W(`w-full rounded-xl border border-black/[0.07] bg-gray-100/70 py-2.5 pl-10 pr-4 text-sm dark:border-white/[0.07] dark:bg-dark-200/70`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`text-gray-900 dark:text-dark-900 placeholder:text-gray-400 dark:placeholder:text-dark-500`)})]})}),(0,X.jsxs)(`div`,{className:`mx-4 mb-3 flex rounded-xl bg-gray-100/70 p-1 dark:bg-dark-200/70 sm:mx-5`,children:[(0,X.jsxs)(`button`,{onClick:()=>{_(`installed`)},className:W(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,g===`installed`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":g===`installed`,children:[(0,X.jsx)(oe,{className:`h-4 w-4 inline mr-1.5`}),d(`modelSelector.installed`)]}),(0,X.jsxs)(`button`,{onClick:()=>{_(`ollama`)},className:W(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,g===`ollama`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":g===`ollama`,children:[(0,X.jsx)(P,{className:`h-4 w-4 inline mr-1.5`}),`Ollama`]}),(0,X.jsxs)(`button`,{onClick:()=>{_(`huggingface`)},className:W(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,g===`huggingface`?`bg-white text-gray-950 shadow-sm dark:bg-dark-300 dark:text-dark-950`:`text-gray-500 hover:text-gray-800 dark:text-dark-500 dark:hover:text-dark-800`),"aria-pressed":g===`huggingface`,children:[(0,X.jsx)(R,{className:`h-4 w-4 inline mr-1.5`}),`HuggingFace`]})]})]}),g===`installed`&&(0,X.jsx)(Gt,{filteredGroups:me,selectedModel:t,showImageGen:l,getModelIcon:ke,getModelLabel:Ae,getModelSubLabel:je,onModelSelect:Ee,onOpenGallery:()=>{p(!1),S(`/gallery`)}}),g===`ollama`&&(0,X.jsx)(Kt,{libraryCategories:pe,libraryCategory:D,canInstallModels:E,loadingLibrary:ve,filteredLibraryModels:Ce,pullingModel:le,pullProgress:ue,setLibraryCategory:k,isModelInstalled:Oe,onModelSelect:Ee,onPullModel:J,onCancelPull:De,onRefreshLibrary:()=>{ye()}}),g===`huggingface`&&(0,X.jsx)(Wt,{hfTask:j,hfSort:N,canInstallModels:E,loadingHf:xe,hfModels:be,expandedHfModel:I,hfGgufFiles:ae,loadingGguf:ce,pullingModel:le,pullProgress:ue,setHfTask:M,setHfSort:te,onToggleHfModel:G,onPullHfGguf:K,onCancelPull:De,onRefreshHfModels:()=>{Se()}})]})]}),document.body),(0,X.jsx)(`select`,{value:t,onChange:n,className:`sr-only`,tabIndex:-1,children:e.map(e=>(0,X.jsx)(`option`,{value:e.name,children:Ae(e)},e.name))})]})},Yt=a(`components:chat-input`),Xt=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r}=q(),[i,a]=(0,Y.useState)(``),[s,l]=(0,Y.useState)([]),[u,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(!1),{isGenerating:b,setBackgroundImage:x}=Ne(),{currentSession:S,models:C}=K(),w=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{(async()=>{try{let e=await xe.getPlugins();y(!!(e.success&&e.data&&e.data.length>0))}catch{y(!1)}})()},[]);let T=t=>{t.preventDefault(),!(!i.trim()||b)&&(e(i.trim(),s.length>0?s:void 0,u||void 0),a(``),l([]))},E=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),T(e))},D=()=>{t()};(0,Y.useEffect)(()=>{let e=w.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[i]),(0,Y.useEffect)(()=>{(async()=>{if(S?.personaId)try{let e=await me.getPersona(S.personaId);if(e.success&&e.data)_(e.data);else{Yt.warn(`Persona ${S.personaId} not found, clearing reference`),_(null);let{setCurrentSession:e}=K.getState();e({...S,personaId:void 0})}}catch(e){if(Yt.error(`Failed to load current persona:`,e),_(null),S){let{setCurrentSession:e}=K.getState();e({...S,personaId:void 0})}}else _(null)})()},[S?.personaId]);let O=async e=>{let t=e.target.value;if(S)try{if(t.startsWith(`persona:`)){let e=t.replace(`persona:`,``),n=await me.getPersona(e);if(!n.success||!n.data){c.error(`Failed to load persona details`);return}let i=n.data,a=await _e.updateSession(S.id,{personaId:e,model:t});if(a.success&&a.data){let{sessions:e}=K.getState(),t=e.map(e=>e.id===S.id?a.data:e);K.setState({sessions:t,currentSession:a.data}),i.background&&x(i.background),c.success(r(`chat.persona.applied`))}}else{let e=await _e.updateSession(S.id,{model:t,personaId:void 0});if(e.success&&e.data){let{sessions:t}=K.getState(),n=t.map(t=>t.id===S.id?e.data:t);K.setState({sessions:n,currentSession:e.data}),x(null),c.success(r(`chat.model.updated`))}}}catch(e){Yt.error(`Failed to update session:`,e),c.error(`Failed to update session`)}},k=s.length>0||u!==null;return(0,X.jsx)(`div`,{className:`pointer-events-none`,children:(0,X.jsxs)(`div`,{className:`pointer-events-auto mx-auto w-full max-w-4xl px-4 sm:px-6 md:px-8`,children:[p&&(0,X.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-white/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/90`,children:[(0,X.jsx)(Lt,{images:s,onImagesChange:l,maxImages:5,sessionId:S?.id,disabled:n}),(0,X.jsx)(Ht,{format:u,onFormatChange:f})]}),(0,X.jsxs)(`div`,{className:`pb-3 pt-2 sm:pb-4`,children:[(0,X.jsx)(`form`,{onSubmit:T,children:(0,X.jsxs)(`div`,{className:W(`flex items-end gap-2 rounded-[1.55rem] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200 sm:p-3`,`bg-white/[0.92] dark:bg-dark-200/[0.92] backdrop-blur-xl`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_14px_42px_rgba(15,23,42,0.08)]`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_52px_rgba(15,23,42,0.11)]`),children:[(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>m(!p),className:W(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,k&&`text-primary-600 dark:text-primary-400`,p&&`bg-gray-100 dark:bg-dark-300`),title:r(`chat.input.attachments`),children:k?(0,X.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,X.jsx)(o,{className:`h-4 w-4`}),(0,X.jsx)(`div`,{className:`absolute -top-0.5 -right-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):p?(0,X.jsx)(h,{className:`h-4 w-4`}):(0,X.jsx)(d,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,X.jsx)(Ft,{ref:w,value:i,onChange:e=>a(e.target.value),onKeyDown:E,placeholder:r(`chat.input.placeholder`),disabled:n,className:`!m-0 min-h-[40px] max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !p-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-base leading-relaxed touch-manipulation`,rows:1})}),(0,X.jsxs)(`div`,{className:`flex flex-shrink-0 items-center gap-1 sm:gap-2`,children:[S&&C.length>0&&(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)(Jt,{models:C,selectedModel:S.personaId?`persona:${S.personaId}`:S.model,onModelChange:O,currentPersona:g,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:v})}),b?(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:D,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-red-50 dark:bg-red-900/20`,`text-red-500 dark:text-red-400`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`transition-colors duration-150 touch-manipulation`),title:r(`chat.input.stopGeneration`),children:(0,X.jsx)(te,{className:`h-4 w-4`})}):(0,X.jsx)(G,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!i.trim()||n,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-100 text-gray-400 dark:bg-dark-300 dark:text-dark-500`,`disabled:cursor-not-allowed disabled:opacity-70`,`transition-colors duration-150 touch-manipulation`,i.trim()&&!n&&[`bg-gray-950 text-white hover:bg-gray-800`,`dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`shadow-sm`]),title:r(`chat.input.sendMessage`),children:(0,X.jsx)(V,{className:`h-4 w-4`})})]})]})}),S&&C.length>0&&(0,X.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,X.jsx)(Jt,{models:C,selectedModel:S.personaId?`persona:${S.personaId}`:S.model,onModelChange:O,currentPersona:g,className:`w-full`,compact:!0,showImageGen:v})}),(0,X.jsxs)(`div`,{className:`mt-2 flex min-h-4 items-center justify-center gap-2 text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,X.jsx)(zt,{sessionId:S?.id}),(0,X.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,X.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),k&&(0,X.jsxs)(`span`,{className:`ml-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,s.length>0&&r(`chat.footer.images`,{count:s.length}),s.length>0&&u&&` • `,u&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},Zt=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(null),[o,c]=(0,Y.useState)({top:0,left:0});(0,Y.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect();c({top:e.bottom+8,left:e.left})}},[r]);let l=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),u=()=>ye(e,64),d=t=>{be(t.currentTarget,e.name,64)};return(0,X.jsxs)(`div`,{className:W(`relative`,n),children:[(0,X.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:W(`flex items-center gap-2 px-3 py-1.5 rounded-full transition-all duration-200`,`bg-primary-50 dark:bg-primary-900/30`,`border border-primary-200 dark:border-primary-700/50`,`hover:bg-primary-100 dark:hover:bg-primary-900/40`,`text-primary-700 dark:text-primary-300`),children:[(0,X.jsx)(`img`,{src:u(),alt:e.name,className:`w-5 h-5 rounded-full object-cover`,onError:d}),(0,X.jsx)(`span`,{className:`text-sm font-medium max-w-[120px] truncate`,children:e.name}),l&&(0,X.jsx)(s,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,X.jsx)(O,{className:W(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,ze.createPortal)((0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`fixed inset-0 z-[9998]`,onClick:()=>i(!1)}),(0,X.jsx)(`div`,{className:`fixed w-72 z-[9999]`,style:{top:o.top,left:o.left},children:(0,X.jsxs)(`div`,{className:W(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,X.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,X.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,X.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 right-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,X.jsx)(L,{className:`h-3.5 w-3.5 text-white`})}),l&&(0,X.jsxs)(`div`,{className:`absolute top-2 left-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,X.jsx)(de,{className:`h-3 w-3`}),`Enhanced`]})]}),(0,X.jsx)(`div`,{className:`relative px-4 -mt-6`,children:(0,X.jsx)(`img`,{src:u(),alt:e.name,className:`w-12 h-12 rounded-lg object-cover ring-3 ring-white dark:ring-dark-100 shadow-md`,onError:d})}),(0,X.jsxs)(`div`,{className:`px-4 pt-2 pb-4`,children:[(0,X.jsx)(`h4`,{className:`text-base font-semibold text-gray-900 dark:text-gray-100`,children:e.name}),(0,X.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 flex items-center gap-1 mt-0.5`,children:[(0,X.jsx)(fe,{className:`h-3 w-3`}),e.model]}),e.description&&(0,X.jsx)(`p`,{className:`text-xs text-gray-600 dark:text-gray-400 mt-2 line-clamp-2`,children:e.description}),e.parameters.system_prompt&&(0,X.jsxs)(`div`,{className:`mt-3 p-2 rounded-lg bg-gray-50 dark:bg-dark-50 border border-gray-100 dark:border-dark-200`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1 mb-1`,children:[(0,X.jsx)(_,{className:`h-2.5 w-2.5 text-gray-400`}),(0,X.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-medium text-gray-400`,children:`System`})]}),(0,X.jsxs)(`p`,{className:`text-[11px] text-gray-600 dark:text-gray-400 line-clamp-2 italic`,children:[`“`,e.parameters.system_prompt,`”`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-1 mt-3`,children:[(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[(0,X.jsx)(R,{className:`h-2.5 w-2.5`}),e.parameters.temperature?.toFixed(1)||`0.7`]}),(0,X.jsxs)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-gray-100 dark:bg-dark-200 text-gray-600 dark:text-gray-400`,children:[`Top-P `,e.parameters.top_p?.toFixed(1)||`0.9`]}),e.memory_settings?.enabled&&(0,X.jsxs)(`span`,{className:`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-[10px] font-medium bg-purple-100 dark:bg-purple-900/30 text-purple-700 dark:text-purple-300`,children:[(0,X.jsx)(de,{className:`h-2.5 w-2.5`}),`Memory`]})]})]})]})})]}),document.body)]})},Qt=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=q(),a=(0,Y.useRef)(null),[o,s]=(0,Y.useState)(!1),c=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){T.error(`File ${o.name} is not an image`);continue}if(o.size>10*1024*1024){T.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&T.error(`Only ${a} more images can be added`)},l=e=>{e.preventDefault(),s(!0)},u=e=>{e.preventDefault(),s(!1)},d=e=>{e.preventDefault(),s(!1),c(e.dataTransfer.files)},f=n=>{t(e.filter((e,t)=>t!==n))},p=e.length<n;return(0,X.jsxs)(`div`,{className:W(`space-y-3`,r),children:[p&&(0,X.jsxs)(`div`,{className:W(`border-2 border-dashed border-gray-300 dark:border-gray-600 rounded-lg p-4 transition-colors`,`hover:border-primary-400 dark:hover:border-primary-500`,o&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:l,onDragLeave:u,onDrop:d,children:[(0,X.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>c(e.target.files),className:`hidden`}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,X.jsx)(A,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,X.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,X.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>f(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,X.jsx)(L,{className:`h-4 w-4`})})})]},t))}),p&&e.length>0&&(0,X.jsxs)(G,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,X.jsx)(w,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},$=a(`use-chat`),$t=new Set([`New Chat`,`New Demo Session`]),en=e=>!e||$t.has(e),tn=e=>{let[t,n]=(0,Y.useState)(``),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)([]),{addMessage:l,updateMessage:u,updateMessageWithStatistics:d,updateSessionTitle:f,setGeneratingTitleForSession:p}=K(),{setIsGenerating:m,preferences:h}=Ne(),g=(0,Y.useRef)(null),_=(0,Y.useRef)(null),v=(0,Y.useRef)(!1),y=(0,Y.useRef)(null),b=(0,Y.useRef)(``),x=(0,Y.useRef)(0),S=(0,Y.useRef)(),C=(0,Y.useRef)(null),w=(0,Y.useRef)(``),E=(0,Y.useCallback)(()=>{C.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(C.current),C.current=null},[]),D=(0,Y.useCallback)((e,t=!1)=>{if(w.current=e,t||typeof window>`u`){E(),n(e);return}C.current===null&&(C.current=window.requestAnimationFrame(()=>{C.current=null,n(w.current)}))},[E]),O=(0,Y.useCallback)(()=>{E(),w.current=``,n(``)},[E]),k=(0,Y.useCallback)(()=>{_.current=null,v.current=!1,y.current=null},[]),A=(0,Y.useCallback)(e=>{let t=Ne.getState().preferences.titleSettings,n=_.current,r=v.current&&y.current===e;$.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),n&&r&&t?.autoTitle&&t?.taskModel&&($.debug(`Triggering auto-title generation...`),p(e),_e.generateTitle(e,t.taskModel,n).then(t=>{$.debug(`Title generation response:`,t),t.success&&t.data?.title&&f(e,t.data.title)}).catch(e=>{$.error(`Failed to generate title:`,e)}).finally(()=>{p(null)})),k()},[k,p,f]);return(0,Y.useEffect)(()=>()=>{J.offMessage(`user_message`),J.offMessage(`assistant_chunk`),J.offMessage(`assistant_complete`),J.offMessage(`tool_status`),J.offMessage(`error`)},[e]),(0,Y.useEffect)(()=>{if(!e){J.offMessage(`user_message`),J.offMessage(`assistant_chunk`),J.offMessage(`assistant_complete`),J.offMessage(`tool_status`),J.offMessage(`error`);return}return J.onMessage(`user_message`,()=>{}),J.onMessage(`assistant_chunk`,t=>{let n=t,r=n.messageId||g.current;r&&(b.current=n.total,D(n.total,n.done),S.current&&clearTimeout(S.current),S.current=setTimeout(()=>{u(e,r,b.current),x.current=Date.now()},n.done?0:200))}),J.onMessage(`tool_status`,e=>{let t=e;c(e=>e.find(e=>e.toolCallId===t.toolCallId)?e.map(e=>e.toolCallId===t.toolCallId?{...e,phase:t.phase}:e):[...e,{toolCallId:t.toolCallId,name:t.name,phase:t.phase,startedAt:Date.now()}])}),J.onMessage(`assistant_complete`,t=>{let n=t;$.debug(`Hook: Received assistant_complete for session:`,e,`messageId:`,n.messageId,`with statistics:`,!!n.statistics),o(!1),O(),m(!1),c([]);let r=n.messageId||g.current;n&&r&&d(e,r,b.current||n.content,n.statistics),A(e),g.current=null,b.current=``,S.current&&clearTimeout(S.current),x.current=0}),J.onMessage(`error`,e=>{let t=e;if(o(!1),O(),m(!1),g.current=null,t.code===`SESSION_NOT_FOUND`){$.warn(`Session not found, redirecting to create new session...`),T.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}T.error(t.error),k()}),o(!1),O(),g.current=null,()=>{S.current&&clearTimeout(S.current),E()}},[e,u,d,m,D,O,E,A,k]),{sendMessage:(0,Y.useCallback)(async(t,n,r)=>{if(!(!e||!t.trim()&&(!n||n.length===0)))try{m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let a=K.getState().currentSession,s=a?.isPrivate===!0,c=a?.messages?.some(e=>e.role===`user`);!s&&!c&&en(a?.title)?(_.current=t.trim(),v.current=!0,y.current=e):(_.current=null,v.current=!1,y.current=null),l(e,{role:`user`,content:t.trim(),images:n});let d=we();if(g.current=d,i(d),l(e,{role:`assistant`,content:``,id:d}),pe()){let n=`Demo response for: ${t.trim()}`;window.setTimeout(()=>{u(e,d,n),o(!1),O(),i(null),m(!1),A(e),g.current=null,b.current=``},500);return}J.isConnected||await J.connect();let f=s?a?.messages?.filter(e=>e.role!==`system`&&e.id!==d).map(e=>({role:e.role,content:e.content,images:e.images})):void 0;J.send({type:`chat_stream`,data:{sessionId:e,content:t.trim(),images:n,format:r,options:h.generationOptions,assistantMessageId:d,isPrivate:s,model:s?a?.model:void 0,messageHistory:f}})}catch(e){$.error(`Failed to send message:`,e),o(!1),O(),i(null),m(!1),g.current=null,T.error(`Failed to send message`)}},[e,l,u,m,O,A,h.generationOptions]),stopGeneration:(0,Y.useCallback)(()=>{o(!1),O(),i(null),m(!1),g.current=null},[m,O]),regenerateLastMessage:(0,Y.useCallback)(async()=>{let t=K.getState().currentSession;if(!t||!e)return;let n=t.messages,r=-1,a=-1;for(let e=n.length-1;e>=0;e--)if(n[e].role===`assistant`){a=e;break}if(a>0){for(let e=a-1;e>=0;e--)if(n[e].role===`user`){r=e;break}}if(r===-1||a===-1){T.error(`No message to regenerate`);return}let s=n[r],c=n[a];try{m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let t=we();g.current=t,i(t),l(e,{role:`assistant`,content:``,id:t,parentId:c.parentId||c.id,branchIndex:c.siblingCount||1,isActive:!0}),J.isConnected||await J.connect(),J.send({type:`chat_stream`,data:{sessionId:e,content:s.content,images:s.images,options:h.generationOptions,assistantMessageId:t,regenerate:!0,originalMessageId:c.id}})}catch(e){$.error(`Failed to regenerate message:`,e),o(!1),O(),i(null),m(!1),g.current=null,T.error(`Failed to regenerate message`)}},[e,m,O,l,h.generationOptions]),selectBranch:(0,Y.useCallback)(async t=>{let n=K.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){T.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await _e.switchMessageBranch(e,t,a);if(r.success&&r.data){let r=n.messages.map(e=>e.id===i||e.parentId===i?{...e,isActive:e.id===t}:e),o={...n,messages:r,updatedAt:Date.now()};K.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),T.success(`Switched to variant ${a+1}`)}else T.error(r.error||`Failed to select branch`)}catch(e){$.error(`Failed to select branch:`,e),T.error(`Failed to select branch`)}},[e]),isStreaming:a,streamingMessage:t,streamingMessageId:r,toolActivities:s}},nn=a(`pages:chat-page`),rn=(e,t)=>{let n=new Date().getHours(),r=e?`, ${e}`:``;return n>=5&&n<12?{id:`time`,title:`${t?t(`chat.greeting.morning`):`Good morning`}${r}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:n>=12&&n<17?{id:`time`,title:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${r}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:n>=17&&n<21?{id:`time`,title:`${t?t(`chat.greeting.evening`):`Good evening`}${r}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}:{id:`time`,title:`${t?t(`chat.greeting.night`):`Good night`}${r}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}},an=(e,t,n)=>{let r=Me(e);return r===`time`?rn(t,n):{id:r,title:n?n(`chat.welcome.variety.${r}.title`):`What should we make?`,subtitle:n?n(`chat.welcome.variety.${r}.subtitle`):`Start with a thought, a sketch, or a stubborn problem.`}},on=()=>{let{t:e}=q(),{sessionId:t}=Ee(),n=Te(),r=De(),{currentSession:i,sessions:a,models:s,selectedModel:c,setSelectedModel:l,createSession:u,setCurrentSession:f,loadSessions:p,getCurrentPersona:m}=K(),{user:g}=Pe(),{sendMessage:_,stopGeneration:y,regenerateLastMessage:b,selectBranch:x,isStreaming:S,streamingMessage:C,streamingMessageId:w,toolActivities:T}=tn(i?.id||``),E=m(),[D,O]=(0,Y.useState)(Fe),k=(0,Y.useMemo)(()=>an(D,g?.username,e),[e,g?.username,D]),[A,ee]=(0,Y.useState)(``),[j,M]=(0,Y.useState)([]),[N,P]=(0,Y.useState)(!1),te=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=()=>{O(Fe())};return window.addEventListener(Oe,e),()=>window.removeEventListener(Oe,e)},[]);let[ne,F]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{a.length===0&&p()},[p,a.length]),(0,Y.useEffect)(()=>{(async()=>{try{let e=await xe.getPlugins();F(!!(e.success&&e.data&&e.data.length>0))}catch{F(!1)}})()},[]),(0,Y.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!i?.isPrivate&&a.length!==0)if(t){let e=a.find(e=>e.id===t);e&&e.id!==i?.id?f(e):e||(nn.warn(`Session ${t} not found for current user, redirecting...`),a.length>0?n(`/c/${a[0].id}`,{replace:!0}):n(`/`,{replace:!0}))}else!t&&a.length>0&&r.pathname===`/`&&n(`/c/${a[0].id}`,{replace:!0})})()},[t,a,f,n,i?.id,i?.isPrivate,r.pathname]),(0,Y.useEffect)(()=>{if(i?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{_(t.content,t.images)},100)}catch(e){nn.error(`Failed to parse pending message:`,e)}}}},[i?.id,_]),(0,Y.useEffect)(()=>{let e=te.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[A]);let I=async e=>{if(e.preventDefault(),!A.trim()||!c)return;let t={content:A.trim(),images:j.length>0?j:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(t)),ee(``),M([]);let r=await u(c);r&&n(`/c/${r.id}`,{replace:!0})},re=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),I(e))},L=async e=>{let t=e.target.value;l(t)},ie=(e,t,n)=>{i&&_(e,t,n)};if(!i){let t=j.length>0;return(0,X.jsxs)(`div`,{className:`relative h-full flex-1 overflow-y-auto overflow-x-hidden px-4 py-20 sm:px-8 sm:py-24`,children:[(0,X.jsxs)(`div`,{"aria-hidden":`true`,className:`pointer-events-none absolute inset-0`,children:[(0,X.jsx)(`div`,{className:`absolute left-[12%] top-[18%] h-56 w-56 rounded-full bg-primary-500/[0.035] blur-3xl dark:bg-primary-400/[0.04]`}),(0,X.jsx)(`div`,{className:`absolute bottom-[16%] right-[10%] h-72 w-72 rounded-full bg-gray-900/[0.025] blur-3xl dark:bg-white/[0.025]`}),(0,X.jsx)(`div`,{className:`absolute left-1/2 top-0 h-16 w-px bg-gray-300/60 dark:bg-white/10`})]}),(0,X.jsxs)(`button`,{onClick:()=>{if(!c&&s.length===0)return;let t=Date.now();f({id:`private-${t}`,title:e(`chat.session.private`),model:c||s[0]?.name||``,messages:[],createdAt:t,updatedAt:t,isPrivate:!0})},disabled:!c&&s.length===0,className:`absolute right-4 top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-white/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-white hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:right-6 sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,X.jsx)(v,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:e(`chat.session.private`)})]}),(0,X.jsxs)(`div`,{className:`relative z-[1] mx-auto flex min-h-full w-full max-w-3xl flex-col items-center justify-center`,children:[(0,X.jsxs)(`div`,{className:`mb-10 flex flex-col items-center text-center animate-fade-in sm:mb-12`,"aria-live":`polite`,children:[(0,X.jsx)(`h1`,{className:`mb-4 max-w-3xl text-balance text-[clamp(2.65rem,7vw,5.25rem)] font-light leading-[0.98] tracking-[-0.055em] text-gray-950 dark:text-dark-950`,children:k.title}),(0,X.jsx)(`p`,{className:`max-w-xl text-balance text-base leading-relaxed text-gray-500 dark:text-dark-600 sm:text-lg`,children:k.subtitle})]},k.id),s.length>0?(0,X.jsxs)(`div`,{className:`w-full`,children:[N&&(0,X.jsx)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-white/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:(0,X.jsx)(Qt,{images:j,onImagesChange:M,maxImages:5})}),(0,X.jsx)(`form`,{onSubmit:I,children:(0,X.jsxs)(`div`,{className:W(`flex items-end gap-2 rounded-[1.6rem] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200 sm:p-3`,`border-black/[0.08] bg-white/90 dark:border-white/[0.09] dark:bg-dark-200/90`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_50px_rgba(15,23,42,0.08)] backdrop-blur-xl`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_22px_65px_rgba(15,23,42,0.12)]`),children:[(0,X.jsx)(G,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>P(!N),className:W(`h-9 w-9 sm:h-10 sm:w-10 !p-0 rounded-full flex-shrink-0`,`text-gray-500 dark:text-dark-600 hover:bg-gray-100 dark:hover:bg-dark-300 transition-colors touch-manipulation`,t&&`text-primary-600 dark:text-primary-400`,N&&`bg-gray-100 dark:bg-dark-300`),title:e(`chat.input.attachImages`),children:t?(0,X.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,X.jsx)(o,{className:`h-4 w-4`}),(0,X.jsx)(`div`,{className:`absolute -top-0.5 -right-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):N?(0,X.jsx)(h,{className:`h-4 w-4`}):(0,X.jsx)(d,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,X.jsx)(Ft,{ref:te,value:A,onChange:e=>ee(e.target.value),onKeyDown:re,placeholder:e(`chat.input.messagePlaceholder`),className:`!m-0 min-h-[40px] max-h-[160px] resize-none !rounded-none !border-0 !bg-transparent !p-2 !shadow-none scrollbar-thin scrollbar-thumb-gray-300 placeholder:text-gray-400 focus:!border-0 focus:!bg-transparent focus:!shadow-none focus:!ring-0 dark:scrollbar-thumb-dark-400 dark:placeholder:text-dark-500 text-base leading-relaxed touch-manipulation`,rows:1})}),(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)(Jt,{models:s,selectedModel:c,onModelChange:L,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:ne})}),(0,X.jsx)(G,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!A.trim()||!c,className:W(`h-9 w-9 sm:h-10 sm:w-10 p-0 rounded-full flex-shrink-0 flex items-center justify-center`,`bg-gray-950 text-white hover:bg-gray-800 dark:bg-white dark:text-gray-950 dark:hover:bg-gray-100`,`disabled:bg-gray-100 disabled:text-gray-400 dark:disabled:bg-dark-300 dark:disabled:text-dark-500 disabled:hover:bg-gray-100 dark:disabled:hover:bg-dark-300`,`transition-colors duration-150 touch-manipulation`,A.trim()&&c&&`shadow-sm`),title:e(`chat.input.sendMessage`),children:(0,X.jsx)(V,{className:`h-4 w-4`})})]})}),(0,X.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,X.jsx)(Jt,{models:s,selectedModel:c,onModelChange:L,className:`w-full`,compact:!0,showImageGen:ne})}),(0,X.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,X.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,X.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.07] bg-white/70 p-6 backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/70`,children:[(0,X.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,X.jsx)(`code`,{className:`block rounded-xl bg-gray-100 p-3 font-mono text-xs text-gray-800 dark:bg-dark-300 dark:text-dark-700`,children:e(`chat.model.pullCommand`)})]})})]})]})}return(0,X.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:E?.background?{backgroundImage:`url(${E.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[E?.background&&(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gray-50/[0.88] backdrop-blur-sm dark:bg-dark-100/[0.88]`}),(0,X.jsxs)(`div`,{className:`relative z-10 flex h-full flex-col`,children:[i?.isPrivate&&(0,X.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-white/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,X.jsx)(v,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:e(`chat.session.privateMode`)}),(0,X.jsxs)(`span`,{className:`hidden text-[11px] text-gray-400 dark:text-dark-500 sm:inline`,children:[`— `,e(`chat.session.privateDescription`)]})]})}),E&&!i?.isPrivate&&(0,X.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-white/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,X.jsx)(Zt,{persona:E,onClear:()=>{if(i){let{sessions:e}=K.getState(),t={...i,model:E.model,personaId:void 0},n=e.map(e=>e.id===i.id?t:e);K.setState({sessions:n,currentSession:t})}}})}),(0,X.jsx)(Nt,{messages:i.messages,streamingMessage:C,streamingMessageId:w,isStreaming:S,toolActivities:T,onRegenerate:b,onSelectBranch:x,className:`flex-1`}),(0,X.jsx)(Xt,{onSendMessage:ie,onStopGeneration:y,disabled:!i})]})]})};export{on as ChatPage,on as default};
@@ -1 +0,0 @@
1
- import{r as e,t}from"./rolldown-runtime-QTnfLwEv.js";import{d as n,f as r}from"./markdown-core-fkbHPd-g.js";import{t as i}from"./logger-BmpKNkls.js";import{Dt as a,Nt as o,O as s,St as c,T as l,Vt as u,Z as d,_ as f,bt as p,d as m,h,k as g,n as _,ot as v,pt as y,u as b,vt as x}from"./ui-vendor-njo77ljx.js";import{l as S}from"./api-D9FuobIF.js";import{t as C}from"./utils-BaPYjs_z.js";import{t as w}from"./Button-Cgmt_2gR.js";import{B as T,F as E,H as D,I as ee,L as te,P as ne,R as O,U as re,V as k,a as ie,i as A,z as j}from"../assets/index-pmlsmnQ4.js";var M=e(t(((e,t)=>{t.exports={area:!0,base:!0,br:!0,col:!0,embed:!0,hr:!0,img:!0,input:!0,link:!0,meta:!0,param:!0,source:!0,track:!0,wbr:!0}}))()),N=/\s([^'"/\s><]+?)[\s/>]|([^\s=]+)=\s?(".*?"|'.*?')/g;function P(e){var t={type:`tag`,name:``,voidElement:!1,attrs:{},children:[]},n=e.match(/<\/?([^\s]+?)[/\s>]/);if(n&&(t.name=n[1],(M.default[n[1]]||e.charAt(e.length-2)===`/`)&&(t.voidElement=!0),t.name.startsWith(`!--`))){var r=e.indexOf(`-->`);return{type:`comment`,comment:r===-1?``:e.slice(4,r)}}for(var i=new RegExp(N),a=null;(a=i.exec(e))!==null;)if(a[0].trim())if(a[1]){var o=a[1].trim(),s=[o,``];o.indexOf(`=`)>-1&&(s=o.split(`=`)),t.attrs[s[0]]=s[1],i.lastIndex--}else a[2]&&(t.attrs[a[2]]=a[3].trim().substring(1,a[3].length-1));return t}var F=/<[a-zA-Z0-9\-\!\/](?:"[^"]*"|'[^']*'|[^'">])*>/g,ae=/^\s*$/,oe=Object.create(null);function I(e,t){switch(t.type){case`text`:return e+t.content;case`tag`:return e+=`<`+t.name+(t.attrs?function(e){var t=[];for(var n in e)t.push(n+`="`+e[n]+`"`);return t.length?` `+t.join(` `):``}(t.attrs):``)+(t.voidElement?`/>`:`>`),t.voidElement?e:e+t.children.reduce(I,``)+`</`+t.name+`>`;case`comment`:return e+`<!--`+t.comment+`-->`}}var se={parse:function(e,t){t||(t={}),t.components||(t.components=oe);var n,r=[],i=[],a=-1,o=!1;if(e.indexOf(`<`)!==0){var s=e.indexOf(`<`);r.push({type:`text`,content:s===-1?e:e.substring(0,s)})}return e.replace(F,function(s,c){if(o){if(s!==`</`+n.name+`>`)return;o=!1}var l,u=s.charAt(1)!==`/`,d=s.startsWith(`<!--`),f=c+s.length,p=e.charAt(f);if(d){var m=P(s);return a<0?(r.push(m),r):((l=i[a]).children.push(m),r)}if(u&&(a++,(n=P(s)).type===`tag`&&t.components[n.name]&&(n.type=`component`,o=!0),n.voidElement||o||!p||p===`<`||n.children.push({type:`text`,content:e.slice(f,e.indexOf(`<`,f))}),a===0&&r.push(n),(l=i[a-1])&&l.children.push(n),i[a]=n),(!u||n.voidElement)&&(a>-1&&(n.voidElement||n.name===s.slice(2,-1))&&(a--,n=a===-1?r:i[a]),!o&&p!==`<`&&p)){l=a===-1?r:i[a].children;var h=e.indexOf(`<`,f),g=e.slice(f,h===-1?void 0:h);ae.test(g)&&(g=` `),(h>-1&&a+l.length>=0||g!==` `)&&l.push({type:`text`,content:g})}}),r},stringify:function(e){return e.reduce(function(e,t){return e+I(``,t)},``)}},L=e(r()),R=(e,t)=>{if(!e)return!1;let n=e.props?.children??e.children;return t?n.length>0:!!n},z=e=>{if(!e)return[];let t=e.props?.children??e.children;return e.props?.i18nIsDynamicList?B(t):t},ce=e=>Array.isArray(e)&&e.every(L.isValidElement),B=e=>Array.isArray(e)?e:[e],le=(e,t)=>{let n={...t};return n.props={...t.props,...e.props},n},V=e=>{let t={};if(!e)return t;let n=e=>{B(e).forEach(e=>{T(e)||(R(e)?n(z(e)):j(e)&&!(0,L.isValidElement)(e)&&Object.assign(t,e))})};return n(e),t},H=(e,t,n,r)=>{if(!e)return``;let i=``,a=B(e),o=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach((e,a)=>{if(T(e)){i+=`${e}`;return}if((0,L.isValidElement)(e)){let{props:s,type:c}=e,l=Object.keys(s).length,u=o.indexOf(c)>-1,d=s.children;if(!d&&u&&!l){i+=`<${c}/>`;return}if(!d&&(!u||l)||s.i18nIsDynamicList){i+=`<${a}></${a}>`;return}if(u&&l<=1){let e=T(d)?d:H(d,t,n,r);i+=`<${c}>${e}</${c}>`;return}let f=H(d,t,n,r);i+=`<${a}>${f}</${a}>`;return}if(e===null){k(n,`TRANS_NULL_VALUE`,`Passed in a null value as child`,{i18nKey:r});return}if(j(e)){let{format:t,...a}=e,o=Object.keys(a);if(o.length===1){let e=t?`${o[0]}, ${t}`:o[0];i+=`{{${e}}}`;return}k(n,`TRANS_INVALID_OBJ`,`Invalid child - Object should only have keys {{ value, format }} (format is optional).`,{i18nKey:r,child:e});return}k(n,`TRANS_INVALID_VAR`,`Passed in a variable like {number} - pass variables for interpolation as full objects like {{number}}.`,{i18nKey:r,child:e})}),i},ue=(e,t=[],n={})=>{if(!e)return e;let r=Object.keys(n),i=[...t,...r],a=``,o=0;for(;o<e.length;)if(e[o]===`<`){let t=!1,n=e.slice(o).match(/^<\/(\d+|[a-zA-Z][a-zA-Z0-9_-]*)>/);if(n){let e=n[1];(/^\d+$/.test(e)||i.includes(e))&&(t=!0,a+=n[0],o+=n[0].length)}if(!t){let n=e.slice(o).match(/^<(\d+|[a-zA-Z][a-zA-Z0-9_-]*)(\s+[\w-]+(?:=(?:"[^"]*"|'[^']*'|[^\s>]+))?)*\s*(\/)?>/);if(n){let e=n[1];(/^\d+$/.test(e)||i.includes(e))&&(t=!0,a+=n[0],o+=n[0].length)}}t||(a+=`&lt;`,o+=1)}else a+=e[o],o+=1;return a},de=(e,t,n,r,i,a,o)=>{if(n===``)return[];let s=i.transKeepBasicHtmlNodesFor||[],c=n&&new RegExp(s.map(e=>`<${e}`).join(`|`)).test(n);if(!e&&!t&&!c&&!o)return[n];let l=t??{},u=e=>{B(e).forEach(e=>{T(e)||(R(e)?u(z(e)):j(e)&&!(0,L.isValidElement)(e)&&Object.assign(l,e))})};u(e);let d=ue(n,s,l),f=se.parse(`<0>${d}</0>`),p={...l,...a},m=(e,t,n)=>{let r=z(e),i=g(r,t.children,n);return ce(r)&&i.length===0||e.props?.i18nIsDynamicList?r:i},h=(e,t,n,r,i)=>{e.dummy?(e.children=t,n.push((0,L.cloneElement)(e,{key:r},i?void 0:t))):n.push(...L.Children.map([e],e=>{if(e.type===L.Fragment||e.props?.i18nIsDynamicList!==void 0){let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t===`children`||t===`i18nIsDynamicList`||(n[t]=e.props[t])}),(0,L.createElement)(e.type,n,i?null:t)}let n={key:r};return e&&e.props&&Object.keys(e.props).forEach(t=>{t===`ref`||t===`children`||(n[t]=e.props[t])}),(0,L.cloneElement)(e,n,i?null:t)}))},g=(e,n,a)=>{let l=B(e),u=B(n),d={};return u.reduce((e,n,u)=>{let f=n.children?.[0]?.content&&r.services.interpolator.interpolate(n.children[0].content,p,r.language);if(n.type===`tag`){let _=l[parseInt(n.name,10)];!_&&t&&(_=t[n.name]),a.length===1&&!_&&(_=a[0][n.name]),_||(_={});let v={...n.attrs};o&&Object.keys(v).forEach(e=>{let t=v[e];T(t)&&(v[e]=O(t))});let y=Object.keys(v).length===0?_:le({props:v},_),b=(0,L.isValidElement)(y),x=b&&R(n,!0)&&!n.voidElement,S=c&&j(y)&&y.dummy&&!b,C=j(t)&&Object.hasOwnProperty.call(t,n.name);if(T(y)){let t=r.services.interpolator.interpolate(y,p,r.language);e.push(t)}else if(R(y)||x)h(y,m(y,n,a),e,u);else if(S)h(y,g(l,n.children,a),e,u);else if(Number.isNaN(parseFloat(n.name)))if(C)h(y,m(y,n,a),e,u,n.voidElement);else if(i.transSupportBasicHtmlNodes&&s.indexOf(n.name)>-1)if(n.voidElement)e.push((0,L.createElement)(n.name,{key:`${n.name}-${u}`}));else{let t=d[n.name]||0;d[n.name]=t+1;let r,i=0;for(let e=0;e<l.length;e+=1){let a=l[e];if((0,L.isValidElement)(a)&&a.type===n.name){if(i===t){r=a;break}i+=1}}let o=g(r?B(z(r)):l,n.children,a);e.push((0,L.createElement)(n.name,{key:`${n.name}-${u}`},o))}else if(n.voidElement)e.push(`<${n.name} />`);else{let t=g(l,n.children,a);e.push(`<${n.name}>${t}</${n.name}>`)}else if(j(y)&&!b){let t=n.children[0]?f:null;t&&e.push(t)}else h(y,f,e,u,n.children.length!==1||!f)}else if(n.type===`text`){let t=i.transWrapTextNodes,a=typeof i.unescape==`function`?i.unescape:te().unescape,s=o?a(r.services.interpolator.interpolate(n.content,p,r.language)):r.services.interpolator.interpolate(n.content,p,r.language);t?e.push((0,L.createElement)(t,{key:`${n.name}-${u}`},s)):e.push(s)}return e},[])};return z(g([{dummy:!0,children:e||[]}],f,B(e||[]))[0])},U=(e,t,n)=>{let r=e.key||t,i=(0,L.cloneElement)(e,{key:r});if(!i.props||!i.props.children||n.indexOf(`${t}/>`)<0&&n.indexOf(`${t} />`)<0)return i;function a(){return(0,L.createElement)(L.Fragment,null,i)}return(0,L.createElement)(a,{key:r})},fe=(e,t)=>e.map((e,n)=>U(e,n,t)),pe=(e,t)=>{let n={};return Object.keys(e).forEach(r=>{Object.assign(n,{[r]:U(e[r],r,t)})}),n},me=(e,t,n,r)=>e?Array.isArray(e)?fe(e,t):j(e)?pe(e,t):(D(n,`TRANS_INVALID_COMPONENTS`,`<Trans /> "components" prop expects an object or array`,{i18nKey:r}),null):null,W=e=>!j(e)||Array.isArray(e)?!1:Object.keys(e).reduce((e,t)=>e&&Number.isNaN(Number.parseFloat(t)),!0);function he({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:o,defaults:s,components:c,ns:l,i18n:u,t:d,shouldUnescape:f,...p}){let m=u||ee();if(!m)return D(m,`NO_I18NEXT_INSTANCE`,`Trans: You need to pass in an i18next instance using i18nextReactModule`,{i18nKey:r}),e;let h=d||m.t.bind(m)||(e=>e),g={...te(),...m.options?.react},_=l||h.ns||m.options?.defaultNS;_=T(_)?[_]:_||[`translation`];let{transDefaultProps:v}=g,y=v?.tOptions?{...v.tOptions,...a}:a,b=f??v?.shouldUnescape,x=v?.values?{...v.values,...o}:o,S=v?.components?{...v.components,...c}:c,C=H(e,g,m,r),w=s||y?.defaultValue||C||g.transEmptyNodeValue||(typeof r==`function`?re(r):r),{hashTransKey:E}=g,ne=r||(E?E(C||w):C||w);o=m.options?.interpolation?.defaultVariables?x&&Object.keys(x).length>0?{...x,...m.options.interpolation.defaultVariables}:{...m.options.interpolation.defaultVariables}:x;let O=V(e);O&&typeof O.count==`number`&&t===void 0&&(t=O.count);let k=o||t!==void 0&&!m.options?.interpolation?.alwaysFormat||!e?y.interpolation:{interpolation:{...y.interpolation,prefix:`#$?`,suffix:`?$#`}},ie={...y,context:i||y.context,count:t,...o,...k,defaultValue:w,ns:_},A=ne?h(ne,ie):w;A===ne&&w&&(A=w);let j=me(S,A,m,r),M=j||e,N=null;W(j)&&(N=j,M=e);let P=de(M,N,A,m,g,ie,b),F=n??g.defaultTransParent;return F?(0,L.createElement)(F,p,P):P}function ge({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:o,defaults:s,components:c,ns:l,i18n:u,t:d,shouldUnescape:f,...p}){let{i18n:m,defaultNS:h}=(0,L.useContext)(E)||{},g=u||m||ee(),_=d||g?.t.bind(g);return he({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a,values:o,defaults:s,components:c,ns:l||_?.ns||h||g?.options?.defaultNS,i18n:g,t:d,shouldUnescape:f,...p})}var G=n(),K=i(`pages:libre-claw`),q={queued:`bg-gray-100 text-gray-700 dark:bg-dark-200 dark:text-dark-700`,running:`bg-primary-100 text-primary-700 dark:bg-primary-900/25 dark:text-primary-300`,blocked:`bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`,done:`bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300`,failed:`bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-300`,cancelled:`bg-slate-100 text-slate-700 dark:bg-slate-800 dark:text-slate-300`},_e={assistant_message:`text-primary-600 dark:text-primary-300`,assistant_delta:`text-primary-600 dark:text-primary-300`,user_message:`text-gray-700 dark:text-dark-700`,permission_request:`text-amber-600 dark:text-amber-300`,permission_response:`text-gray-600 dark:text-dark-600`,tool_call:`text-gray-600 dark:text-dark-600`,tool_result:`text-gray-600 dark:text-dark-600`,usage:`text-gray-600 dark:text-dark-600`,error:`text-red-600 dark:text-red-300`,run_finished:`text-emerald-600 dark:text-emerald-300`},ve=[[`lobster`,`Lobster`],[`lobster-light`,`Lobster Light`],[`github-dark`,`GitHub Dark`],[`github-light`,`GitHub Light`],[`monokai-pro`,`Monokai Pro`],[`night-owl`,`Night Owl`],[`tokyo-night`,`Tokyo Night`],[`ayu`,`Ayu`],[`dracula`,`Dracula`],[`catppuccin-mocha`,`Catppuccin Mocha`],[`catppuccin-latte`,`Catppuccin Latte`],[`gruvbox-dark`,`Gruvbox Dark`],[`nord`,`Nord`],[`solarized-dark`,`Solarized Dark`],[`solarized-light`,`Solarized Light`],[`one-dark-pro`,`One Dark Pro`],[`rose-pine`,`Rose Pine`],[`kanagawa`,`Kanagawa`],[`matrix`,`Matrix`]],ye=()=>{let{t:e}=ne(),[t,n]=(0,L.useState)(null),[r,i]=(0,L.useState)([]),[T,E]=(0,L.useState)([]),[D,ee]=(0,L.useState)([]),[te,O]=(0,L.useState)(null),[re,k]=(0,L.useState)(null),[j,M]=(0,L.useState)(``),[N,P]=(0,L.useState)(null),[F,ae]=(0,L.useState)(!0),[oe,I]=(0,L.useState)(!1),[se,R]=(0,L.useState)(!1),[z,ce]=(0,L.useState)(!1),[B,le]=(0,L.useState)(!1),[V,H]=(0,L.useState)(``),[ue,de]=(0,L.useState)(`chat`),[U,fe]=(0,L.useState)(``),[pe,me]=(0,L.useState)(``),[W,he]=(0,L.useState)(``),[q,_e]=(0,L.useState)(``),[ye,we]=(0,L.useState)(!1),[Te,Ee]=(0,L.useState)(`lobster`),[Y,De]=(0,L.useState)(!0),[je,Me]=(0,L.useState)(``),[Ne,X]=(0,L.useState)(``),[Z,Pe]=(0,L.useState)(``),[Fe,Ie]=(0,L.useState)(`report`),Q=(0,L.useMemo)(()=>r.find(e=>e.run_id===N)||null,[r,N]),Le=(0,L.useMemo)(()=>{let e=new Set(T.filter(e=>e.type===`permission_response`).map(e=>String(e.data.tool_call_id||``)));return T.filter(t=>{if(t.type!==`permission_request`)return!1;let n=String(t.data.tool_call_id||``);return n&&!e.has(n)})},[T]),Re=(0,L.useMemo)(()=>Ae(T,e),[T,e]),$=(0,L.useCallback)(async()=>{try{let[e,t,r,a,o,s]=await Promise.all([S.status(),S.listRuns(30),S.currentModel(),S.currentFallback(),S.usage(``,100),S.listAutomations(50)]);e.success&&e.data&&n(e.data),t.success&&t.data&&(i(t.data.runs),P(e=>e||t.data?.runs[0]?.run_id||null)),r.success&&r.data&&(O(r.data),he(String(r.data.provider||``)),_e(String(r.data.model||``))),a.success&&a.data&&k(a.data),o.success&&o.data&&M(String(o.data.text||``)),s.success&&s.data&&ee(s.data.automations)}catch(t){K.error(`Failed to load Libre Claw overview:`,t),u.error(e(`libreClaw.toasts.loadStatusFailed`))}finally{ae(!1)}},[e]),ze=(0,L.useCallback)(async(e,t=!1)=>{let n=t?0:T.length>0&&T[T.length-1]?.event_id||0;try{let r=await S.getEvents(e,n);r.success&&r.data&&E(e=>t?r.data?.events||[]:[...e,...r.data?.events||[]])}catch(e){K.error(`Failed to load Libre Claw events:`,e)}},[T]);(0,L.useEffect)(()=>{let e=window.setTimeout(()=>{$()},0);return()=>window.clearTimeout(e)},[$]),(0,L.useEffect)(()=>{if(!N){let e=window.setTimeout(()=>{E([])},0);return()=>window.clearTimeout(e)}let e=N;S.getEvents(e,0).then(e=>{e.success&&e.data&&E(e.data.events)}).catch(e=>{K.error(`Failed to load Libre Claw events:`,e)})},[N]),(0,L.useEffect)(()=>{if(!N||!Q||![`queued`,`running`,`blocked`].includes(Q.state))return;let e=window.setInterval(()=>{ze(N),S.listRuns(30).then(e=>{e.success&&e.data&&i(e.data.runs)})},1500);return()=>window.clearInterval(e)},[ze,Q,N]);let Be=async()=>{if(!V.trim()){u.error(e(`libreClaw.toasts.enterTask`));return}I(!0);try{let t=await S.startRun({message:V,kind:ue,provider:U||void 0,model:pe||void 0});if(t.success&&t.data){let n=t.data.run;i(e=>[n,...e.filter(e=>e.run_id!==n.run_id)]),P(n.run_id),H(``),u.success(e(`libreClaw.toasts.runStarted`))}else u.error(t.error||e(`libreClaw.toasts.startRunFailed`))}catch(t){K.error(`Failed to start Libre Claw run:`,t),u.error(e(`libreClaw.toasts.startRunFailed`))}finally{I(!1)}},Ve=async t=>{try{await S.cancelRun(t),await $(),u.success(e(`libreClaw.toasts.runCancelled`))}catch(t){K.error(`Failed to cancel Libre Claw run:`,t),u.error(e(`libreClaw.toasts.cancelRunFailed`))}},He=async(t,n)=>{if(!N)return;let r=String(t.data.tool_call_id||``);if(r)try{await S.resolvePermission(N,r,n),await ze(N,!0),u.success(e(n===`deny`?`libreClaw.toasts.denied`:`libreClaw.toasts.approved`))}catch(t){K.error(`Failed to resolve Libre Claw permission:`,t),u.error(e(`libreClaw.toasts.resolvePermissionFailed`))}},Ue=async()=>{if(!W.trim()||!q.trim()){u.error(e(`libreClaw.toasts.providerModelRequired`));return}R(!0);try{let t=await S.updateModel(W,q,ye);t.success&&t.data?(O(t.data),u.success(e(`libreClaw.toasts.modelUpdated`))):u.error(t.error||e(`libreClaw.toasts.updateModelFailed`))}catch(t){K.error(`Failed to update Libre Claw model:`,t),u.error(e(`libreClaw.toasts.updateModelFailed`))}finally{R(!1)}},We=async()=>{ce(!0);try{let t=await S.updateTheme(Te,Y);t.success?u.success(e(`libreClaw.toasts.themeUpdated`)):u.error(t.error||e(`libreClaw.toasts.updateThemeFailed`))}catch(t){K.error(`Failed to update Libre Claw theme:`,t),u.error(e(`libreClaw.toasts.updateThemeFailed`))}finally{ce(!1)}},Ge=async()=>{if(!je.trim()||!Ne.trim()||!Z.trim()){u.error(e(`libreClaw.toasts.automationRequired`));return}le(!0);try{let t=await S.createAutomation({name:je,schedule:Ne,prompt:Z,route:Fe});t.success?(Me(``),X(``),Pe(``),await $(),u.success(e(`libreClaw.toasts.automationCreated`))):u.error(t.error||e(`libreClaw.toasts.createAutomationFailed`))}catch(t){K.error(`Failed to create Libre Claw automation:`,t),u.error(e(`libreClaw.toasts.createAutomationFailed`))}finally{le(!1)}},Ke=async(t,n)=>{try{n===`pause`&&await S.pauseAutomation(t),n===`resume`&&await S.resumeAutomation(t),n===`run`&&await S.runAutomationNow(t),n===`delete`&&await S.deleteAutomation(t),await $(),u.success(e(`libreClaw.toasts.automationUpdated`))}catch(t){K.error(`Failed to update Libre Claw automation:`,t),u.error(e(`libreClaw.toasts.updateAutomationFailed`))}};return(0,G.jsxs)(ie,{width:`wide`,contentClassName:`space-y-6`,children:[(0,G.jsx)(A,{className:`mb-0`,title:e(`libreClaw.title`),description:e(`libreClaw.subtitle`),actions:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(be,{status:t,t:e}),(0,G.jsxs)(w,{variant:`secondary`,size:`sm`,onClick:$,children:[(0,G.jsx)(l,{className:`h-4 w-4`}),e(`common.refresh`)]}),(0,G.jsxs)(`a`,{href:t?.dashboardUrl||`http://127.0.0.1:8766/dashboard`,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex min-h-9 items-center gap-1.5 rounded-xl border border-gray-200/80 bg-white/70 px-3 py-1.5 text-sm font-medium text-gray-700 transition-colors hover:bg-white dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-700 dark:hover:bg-white/[0.08]`,children:[(0,G.jsx)(v,{className:`h-4 w-4`}),e(`libreClaw.dashboard`)]})]})}),!t?.connected&&!F&&(0,G.jsx)(`section`,{className:`rounded-xl border border-amber-200 bg-amber-50 p-4 text-amber-900 dark:border-amber-800 dark:bg-amber-900/20 dark:text-amber-200`,children:(0,G.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,G.jsx)(m,{className:`mt-0.5 h-5 w-5 shrink-0`}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h2`,{className:`font-semibold`,children:e(`libreClaw.connection.disconnectedTitle`)}),(0,G.jsx)(`p`,{className:`mt-1 text-sm opacity-90`,children:(0,G.jsx)(ge,{i18nKey:`libreClaw.connection.disconnectedDescription`,components:{command:(0,G.jsx)(`code`,{}),env:(0,G.jsx)(`code`,{})}})}),t?.error&&(0,G.jsx)(`p`,{className:`mt-2 text-xs opacity-80`,children:t.error})]})]})}),(0,G.jsxs)(`section`,{className:`grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,G.jsx)(J,{title:e(`libreClaw.startRun.title`),icon:(0,G.jsx)(s,{className:`h-4 w-4`}),children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsx)(`textarea`,{value:V,onChange:e=>H(e.target.value),placeholder:e(`libreClaw.startRun.placeholder`),className:`min-h-32 w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 outline-none transition focus:border-primary-400 focus:ring-2 focus:ring-primary-100 dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800 dark:focus:border-primary-500 dark:focus:ring-primary-900/30`}),(0,G.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-4`,children:[(0,G.jsxs)(`select`,{value:ue,onChange:e=>de(e.target.value),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,G.jsx)(`option`,{value:`chat`,children:e(`libreClaw.startRun.chatRun`)}),(0,G.jsx)(`option`,{value:`goal`,children:e(`libreClaw.startRun.goalMode`)})]}),(0,G.jsx)(`input`,{value:U,onChange:e=>fe(e.target.value),placeholder:e(`libreClaw.startRun.providerOverride`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,G.jsx)(`input`,{value:pe,onChange:e=>me(e.target.value),placeholder:e(`libreClaw.startRun.modelOverride`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,G.jsxs)(w,{onClick:Be,loading:oe,children:[(0,G.jsx)(c,{className:`h-4 w-4`}),e(`libreClaw.startRun.run`)]})]})]})}),(0,G.jsx)(J,{title:e(`libreClaw.modelRoute.title`),icon:(0,G.jsx)(d,{className:`h-4 w-4`}),children:(0,G.jsxs)(`div`,{className:`space-y-3`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2 lg:grid-cols-1`,children:[(0,G.jsx)(`input`,{value:W,onChange:e=>he(e.target.value),placeholder:e(`libreClaw.modelRoute.providerPlaceholder`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,G.jsx)(`input`,{value:q,onChange:e=>_e(e.target.value),placeholder:e(`libreClaw.modelRoute.modelPlaceholder`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`})]}),(0,G.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-gray-600 dark:text-dark-600`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:ye,onChange:e=>we(e.target.checked),className:`h-4 w-4 rounded border-gray-300 text-primary-600 focus:ring-primary-500`}),e(`libreClaw.modelRoute.persistGlobal`)]}),(0,G.jsx)(w,{variant:`secondary`,onClick:Ue,loading:se,children:e(`libreClaw.modelRoute.saveModel`)}),(0,G.jsxs)(`div`,{className:`border-t border-gray-100 pt-3 dark:border-dark-200`,children:[(0,G.jsx)(`label`,{className:`mb-1 block text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-500`,children:e(`libreClaw.modelRoute.theme`)}),(0,G.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-[minmax(0,1fr)_auto] lg:grid-cols-1`,children:[(0,G.jsx)(`select`,{value:Te,onChange:e=>Ee(e.target.value),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:ve.map(([e,t])=>(0,G.jsx)(`option`,{value:e,children:t},e))}),(0,G.jsx)(w,{variant:`secondary`,onClick:We,loading:z,children:e(`libreClaw.modelRoute.saveTheme`)})]}),(0,G.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-sm text-gray-600 dark:text-dark-600`,children:[(0,G.jsx)(`input`,{type:`checkbox`,checked:Y,onChange:e=>De(e.target.checked),className:`h-4 w-4 rounded border-gray-300 text-primary-600 focus:ring-primary-500`}),e(`libreClaw.modelRoute.persistGlobal`)]})]}),te&&(0,G.jsx)(`pre`,{className:`max-h-32 overflow-auto rounded-lg bg-gray-100 p-2 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:JSON.stringify(te,null,2)})]})})]}),(0,G.jsxs)(`section`,{className:`grid gap-4 xl:grid-cols-[360px_minmax(0,1fr)]`,children:[(0,G.jsx)(J,{title:e(`libreClaw.runs.title`),icon:(0,G.jsx)(a,{className:`h-4 w-4`}),children:(0,G.jsxs)(`div`,{className:`space-y-2`,children:[r.length===0&&(0,G.jsx)(Oe,{text:e(`libreClaw.runs.empty`)}),r.map(t=>(0,G.jsxs)(`button`,{onClick:()=>P(t.run_id),className:C(`w-full rounded-xl border p-3 text-start transition`,N===t.run_id?`border-primary-300 bg-primary-50 dark:border-primary-700 dark:bg-primary-900/20`:`border-gray-200 bg-white hover:bg-gray-50 dark:border-dark-300 dark:bg-dark-50 dark:hover:bg-dark-100`),children:[(0,G.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,G.jsx)(`span`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,children:t.title}),(0,G.jsx)(xe,{state:t.state,t:e})]}),(0,G.jsxs)(`div`,{className:`mt-1 truncate text-xs text-gray-500 dark:text-dark-500`,children:[t.provider,`:`,t.model]}),(0,G.jsx)(`div`,{className:`mt-1 text-xs text-gray-400 dark:text-dark-500`,children:ke(t.updated_at)})]},t.run_id))]})}),(0,G.jsxs)(J,{title:Q?Q.title:e(`libreClaw.timeline.title`),icon:(0,G.jsx)(y,{className:`h-4 w-4`}),actions:Q&&[`queued`,`running`,`blocked`].includes(Q.state)?(0,G.jsxs)(w,{variant:`danger`,size:`sm`,onClick:()=>Ve(Q.run_id),children:[(0,G.jsx)(h,{className:`h-4 w-4`}),e(`common.cancel`)]}):null,children:[Le.length>0&&(0,G.jsxs)(`div`,{className:`mb-4 space-y-2 rounded-xl border border-amber-200 bg-amber-50 p-3 dark:border-amber-800 dark:bg-amber-900/20`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-amber-800 dark:text-amber-200`,children:[(0,G.jsx)(f,{className:`h-4 w-4`}),e(`libreClaw.approvals.needed`)]}),Le.map(t=>(0,G.jsxs)(`div`,{className:`rounded-lg bg-white/70 p-3 dark:bg-dark-50/70`,children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:String(t.data.name||e(`libreClaw.fallbacks.tool`))}),(0,G.jsx)(`pre`,{className:`mt-2 max-h-36 overflow-auto rounded bg-gray-100 p-2 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:JSON.stringify(t.data.arguments||{},null,2)}),(0,G.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,G.jsxs)(w,{size:`sm`,onClick:()=>He(t,`allow_once`),children:[(0,G.jsx)(x,{className:`h-4 w-4`}),e(`libreClaw.approvals.allowOnce`)]}),(0,G.jsx)(w,{size:`sm`,variant:`secondary`,onClick:()=>He(t,`always_allow_tool`),children:e(`libreClaw.approvals.alwaysAllowTool`)}),(0,G.jsxs)(w,{size:`sm`,variant:`danger`,onClick:()=>He(t,`deny`),children:[(0,G.jsx)(_,{className:`h-4 w-4`}),e(`libreClaw.approvals.deny`)]})]})]},t.event_id))]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[T.length===0&&(0,G.jsx)(Oe,{text:e(`libreClaw.timeline.empty`)}),Re.map(t=>(0,G.jsx)(Ce,{item:t,t:e},t.key))]})]})]}),(0,G.jsxs)(`section`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,G.jsx)(J,{title:e(`libreClaw.automations.title`),icon:(0,G.jsx)(p,{className:`h-4 w-4`}),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:[(0,G.jsx)(`input`,{value:je,onChange:e=>Me(e.target.value),placeholder:e(`libreClaw.automations.namePlaceholder`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,G.jsx)(`input`,{value:Ne,onChange:e=>X(e.target.value),placeholder:e(`libreClaw.automations.schedulePlaceholder`),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,G.jsxs)(`select`,{value:Fe,onChange:e=>Ie(e.target.value),className:`rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`,children:[(0,G.jsx)(`option`,{value:`report`,children:e(`libreClaw.automations.routes.report`)}),(0,G.jsx)(`option`,{value:`telegram`,children:e(`libreClaw.automations.routes.telegram`)})]}),(0,G.jsx)(w,{onClick:Ge,loading:B,children:e(`libreClaw.automations.create`)})]}),(0,G.jsx)(`textarea`,{value:Z,onChange:e=>Pe(e.target.value),placeholder:e(`libreClaw.automations.promptPlaceholder`),className:`min-h-24 w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm dark:border-dark-300 dark:bg-dark-50 dark:text-dark-800`}),(0,G.jsxs)(`div`,{className:`space-y-2`,children:[D.length===0&&(0,G.jsx)(Oe,{text:e(`libreClaw.automations.empty`)}),D.map(t=>(0,G.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-white p-3 dark:border-dark-300 dark:bg-dark-50`,children:(0,G.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsx)(`div`,{className:`truncate text-sm font-medium text-gray-900 dark:text-dark-900`,children:t.name}),(0,G.jsxs)(`div`,{className:`mt-1 text-xs text-gray-500 dark:text-dark-500`,children:[t.schedule,` ·`,` `,e(`libreClaw.automations.routes.${t.route}`,{defaultValue:t.route}),` `,`·`,` `,e(`libreClaw.automations.status.${t.status}`,{defaultValue:t.status})]})]}),(0,G.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,G.jsx)(Se,{title:e(`libreClaw.automations.runNow`),onClick:()=>Ke(t.automation_id,`run`),children:(0,G.jsx)(s,{className:`h-4 w-4`})}),(0,G.jsx)(Se,{title:t.status===`paused`?e(`libreClaw.automations.resume`):e(`libreClaw.automations.pause`),onClick:()=>Ke(t.automation_id,t.status===`paused`?`resume`:`pause`),children:t.status===`paused`?(0,G.jsx)(s,{className:`h-4 w-4`}):(0,G.jsx)(g,{className:`h-4 w-4`})}),(0,G.jsx)(Se,{title:e(`common.delete`),danger:!0,onClick:()=>Ke(t.automation_id,`delete`),children:(0,G.jsx)(b,{className:`h-4 w-4`})})]})]})},t.automation_id))]})]})}),(0,G.jsx)(J,{title:e(`libreClaw.usageFallback.title`),icon:(0,G.jsx)(a,{className:`h-4 w-4`}),children:(0,G.jsxs)(`div`,{className:`space-y-4`,children:[(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`mb-2 text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`libreClaw.usageFallback.usage`)}),(0,G.jsx)(`pre`,{className:`max-h-52 overflow-auto rounded-xl bg-gray-100 p-3 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:j||e(`libreClaw.usageFallback.noUsage`)})]}),(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`h3`,{className:`mb-2 text-sm font-semibold text-gray-900 dark:text-dark-900`,children:e(`libreClaw.usageFallback.fallbackRoute`)}),(0,G.jsx)(`pre`,{className:`max-h-52 overflow-auto rounded-xl bg-gray-100 p-3 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:JSON.stringify(re||{},null,2)})]})]})})]}),F&&(0,G.jsx)(`div`,{className:`fixed inset-0 z-40 flex items-center justify-center bg-white/60 backdrop-blur-sm dark:bg-dark-50/60`,children:(0,G.jsx)(o,{className:`h-7 w-7 animate-spin text-primary-600`})})]})},be=({status:e,t})=>{let n=!!e?.connected;return(0,G.jsxs)(`span`,{className:C(`inline-flex items-center gap-2 rounded-full px-3 py-1.5 text-sm font-medium`,n?`bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300`:`bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-300`),children:[(0,G.jsx)(`span`,{className:C(`h-2 w-2 rounded-full`,n?`bg-emerald-500`:`bg-amber-500`)}),t(n?`libreClaw.status.connected`:`libreClaw.status.disconnected`),e?.health?.active_runs!==void 0&&(0,G.jsxs)(`span`,{className:`opacity-70`,children:[`·`,` `,t(`libreClaw.status.activeRuns`,{count:e.health.active_runs})]})]})},xe=({state:e,t})=>(0,G.jsx)(`span`,{className:C(`rounded-full px-2 py-0.5 text-[11px] font-semibold uppercase tracking-wide`,q[e]||q.queued),children:t(`libreClaw.states.${e}`,{defaultValue:e})}),J=({title:e,icon:t,actions:n,children:r})=>(0,G.jsxs)(`section`,{className:`rounded-2xl border border-gray-200/80 bg-white/60 dark:border-white/10 dark:bg-white/[0.03]`,children:[(0,G.jsxs)(`header`,{className:`flex items-center justify-between gap-3 border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08]`,children:[(0,G.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-gray-900 dark:text-dark-900`,children:[(0,G.jsx)(`span`,{className:`text-primary-600 dark:text-primary-300`,children:t}),e]}),n]}),(0,G.jsx)(`div`,{className:`p-5`,children:r})]}),Se=({title:e,danger:t,onClick:n,children:r})=>(0,G.jsx)(`button`,{type:`button`,title:e,onClick:n,className:C(`inline-flex h-8 w-8 items-center justify-center rounded-lg transition-colors`,t?`text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`:`text-gray-500 hover:bg-gray-100 dark:text-dark-500 dark:hover:bg-dark-200`),children:r}),Ce=({item:e,t})=>(0,G.jsxs)(`article`,{className:C(`rounded-xl border p-3 transition-colors`,e.eventType===`assistant_message`?`border-primary-200 bg-primary-50/60 dark:border-primary-900/60 dark:bg-primary-900/10`:(e.eventType,`border-gray-200/80 bg-white/50 dark:border-white/[0.08] dark:bg-white/[0.025]`)),children:[(0,G.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,G.jsx)(`span`,{className:C(`text-xs font-semibold uppercase tracking-wide`,_e[e.eventType]||`text-gray-500 dark:text-dark-500`),children:e.label}),(0,G.jsxs)(`span`,{className:`shrink-0 text-xs text-gray-400 dark:text-dark-500`,children:[Ne(e),` · `,ke(e.timestamp)]})]}),(0,G.jsx)(we,{item:e,t})]}),we=({item:e,t})=>{if(e.kind===`assistant_message`)return(0,G.jsx)(`p`,{className:`whitespace-pre-wrap text-sm leading-6 text-gray-900 dark:text-dark-900`,children:je(e.events)||t(`libreClaw.timeline.streaming`)});let n=e.events[0];return n?n.type===`assistant_delta`?(0,G.jsx)(`p`,{className:`whitespace-pre-wrap text-sm text-gray-800 dark:text-dark-800`,children:String(n.data.text||``)}):n.type===`user_message`?(0,G.jsx)(`p`,{className:`whitespace-pre-wrap text-sm text-gray-800 dark:text-dark-800`,children:String(n.data.content||``)}):n.type===`tool_call`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:String(n.data.name||t(`libreClaw.fallbacks.tool`))}),(0,G.jsx)(De,{value:n.data.arguments||{}})]}):n.type===`tool_result`?(0,G.jsxs)(`div`,{children:[(0,G.jsxs)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:[String(n.data.name||t(`libreClaw.fallbacks.tool`)),` ·`,` `,n.data.is_error?t(`libreClaw.timeline.resultError`):t(`libreClaw.timeline.resultOk`)]}),(0,G.jsx)(`pre`,{className:`mt-2 max-h-56 overflow-auto whitespace-pre-wrap rounded-lg bg-gray-100 p-2 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:String(n.data.content||``)})]}):n.type===`permission_request`?(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:String(n.data.name||t(`libreClaw.approvals.toolApprovalRequested`))}),(0,G.jsx)(De,{value:n.data.arguments||{}})]}):n.type===`permission_response`?(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,G.jsx)(Y,{label:t(`libreClaw.metrics.tool`),value:String(n.data.name||n.data.tool_call_id||t(`libreClaw.fallbacks.tool`))}),(0,G.jsx)(Y,{label:t(`libreClaw.metrics.resolution`),value:String(n.data.resolution||t(`libreClaw.fallbacks.resolved`))})]}):n.type===`usage`?(0,G.jsx)(Te,{data:n.data,t}):n.type===`run_finished`?(0,G.jsx)(Ee,{data:n.data,t}):n.type===`error`?(0,G.jsx)(`p`,{className:`text-sm text-red-700 dark:text-red-300`,children:String(n.data.message||t(`libreClaw.fallbacks.unknownError`))}):(0,G.jsx)(De,{value:n.data}):null},Te=({data:e,t})=>(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,G.jsx)(Y,{label:t(`libreClaw.metrics.provider`),value:String(e.provider||t(`libreClaw.fallbacks.unknown`))}),(0,G.jsx)(Y,{label:t(`libreClaw.metrics.model`),value:String(e.model||t(`libreClaw.fallbacks.unknown`))}),(0,G.jsx)(Y,{label:t(`libreClaw.metrics.input`),value:t(`libreClaw.metrics.tokens`,{count:X(e.input_tokens),formatted:Z(e.input_tokens)})}),(0,G.jsx)(Y,{label:t(`libreClaw.metrics.output`),value:t(`libreClaw.metrics.tokens`,{count:X(e.output_tokens),formatted:Z(e.output_tokens)})}),X(e.cached_tokens)>0&&(0,G.jsx)(Y,{label:t(`libreClaw.metrics.cached`),value:t(`libreClaw.metrics.tokens`,{count:X(e.cached_tokens),formatted:Z(e.cached_tokens)})}),X(e.reasoning_tokens)>0&&(0,G.jsx)(Y,{label:t(`libreClaw.metrics.reasoning`),value:t(`libreClaw.metrics.tokens`,{count:X(e.reasoning_tokens),formatted:Z(e.reasoning_tokens)})}),(0,G.jsx)(Y,{label:t(`libreClaw.metrics.cost`),value:Pe(e.cost)})]}),Ee=({data:e,t})=>(0,G.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,G.jsx)(Y,{label:t(`libreClaw.metrics.state`),value:t(`libreClaw.states.${String(e.state||`done`)}`,{defaultValue:String(e.state||`done`)})}),e.stop_reason!==void 0&&(0,G.jsx)(Y,{label:t(`libreClaw.metrics.stopReason`),value:String(e.stop_reason)})]}),Y=({label:e,value:t})=>(0,G.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded-full border border-gray-200/80 bg-white/50 px-2.5 py-1 text-xs text-gray-700 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-700`,children:[(0,G.jsx)(`span`,{className:`font-semibold text-gray-500 dark:text-dark-500`,children:e}),(0,G.jsx)(`span`,{children:t})]}),De=({value:e})=>(0,G.jsx)(`pre`,{className:`mt-2 max-h-56 overflow-auto rounded-lg bg-gray-100 p-2 text-xs text-gray-700 dark:bg-dark-200 dark:text-dark-700`,children:JSON.stringify(e,null,2)}),Oe=({text:e})=>(0,G.jsx)(`div`,{className:`rounded-xl border border-dashed border-gray-300 bg-white/30 px-4 py-8 text-center text-sm text-gray-500 dark:border-white/15 dark:bg-white/[0.02] dark:text-dark-500`,children:e}),ke=e=>{if(!e)return``;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()},Ae=(e,t)=>{let n=[],r=0;for(;r<e.length;){let i=e[r];if(!i)break;if(i.type===`assistant_delta`){let i=[];for(;e[r]?.type===`assistant_delta`;){let t=e[r];t&&i.push(t),r+=1}let a=i[0],o=i[i.length-1]||a;a&&o&&n.push({key:`assistant-${a.event_id}-${o.event_id}`,kind:`assistant_message`,eventType:`assistant_message`,label:t(`libreClaw.timeline.assistantResponse`),firstEventId:a.event_id,lastEventId:o.event_id,timestamp:a.timestamp,events:i});continue}n.push({key:`${i.type}-${i.event_id}`,kind:`event`,eventType:i.type,label:Me(i.type,t),firstEventId:i.event_id,lastEventId:i.event_id,timestamp:i.timestamp,events:[i]}),r+=1}return n},je=e=>e.map(e=>String(e.data.text||``)).join(``),Me=(e,t)=>({user_message:t(`libreClaw.timeline.labels.userMessage`),tool_call:t(`libreClaw.timeline.labels.toolCall`),tool_result:t(`libreClaw.timeline.labels.toolResult`),permission_request:t(`libreClaw.timeline.labels.approvalRequest`),permission_response:t(`libreClaw.timeline.labels.approvalResponse`),run_started:t(`libreClaw.timeline.labels.runStarted`),run_finished:t(`libreClaw.timeline.labels.runFinished`),usage:t(`libreClaw.timeline.labels.usage`),error:t(`libreClaw.timeline.labels.error`)})[e]||e.replace(/_/g,` `),Ne=e=>e.firstEventId===e.lastEventId?`#${e.firstEventId}`:`#${e.firstEventId}-#${e.lastEventId}`,X=e=>{let t=Number(e);return Number.isFinite(t)?t:0},Z=e=>new Intl.NumberFormat().format(X(e)),Pe=e=>{let t=X(e);return t<=0?`$0.00`:t<.01?`$${t.toFixed(6)}`:`$${t.toFixed(4)}`};export{ye as default};
@@ -1,3 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["js/OptimizedSyntaxHighlighter-CNjLqj1Z.js","js/rolldown-runtime-QTnfLwEv.js","js/markdown-core-fkbHPd-g.js","js/syntax-highlight-D5wpTVgr.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n,r}from"./markdown-core-fkbHPd-g.js";import{r as i,t as a}from"./logger-BmpKNkls.js";import{ut as o,vt as s}from"./ui-vendor-njo77ljx.js";import{t as c}from"./utils-BaPYjs_z.js";import{p as l,w as u}from"../assets/index-pmlsmnQ4.js";import{n as d,t as f}from"./markdown-math-Ci4QOsf-.js";var p=e(n(),1),m=t(),h=a(`components:ui:rich-message-content`),g=p.lazy(()=>i(()=>import(`./OptimizedSyntaxHighlighter-CNjLqj1Z.js`).then(e=>e.n),__vite__mapDeps([0,1,2,3])));function _({children:e,className:t}){return(0,m.jsx)(`pre`,{className:c(`bg-gray-100 dark:bg-dark-200 p-3 rounded-lg overflow-x-auto text-sm font-mono`,t),children:(0,m.jsx)(`code`,{children:e})})}var v=({content:e,className:t})=>{let{theme:n}=u(),[i,a]=p.useState(null),v=p.useMemo(()=>l(e),[e]),y=async e=>{try{await navigator.clipboard.writeText(e),a(e),setTimeout(()=>a(null),2e3)}catch(e){h.error(`Failed to copy text:`,e)}};return(0,m.jsx)(`div`,{className:c(`prose prose-sm max-w-none dark:prose-invert prose-gray`,`[&_.katex-display]:overflow-x-auto [&_.katex-display]:overflow-y-hidden [&_.katex-display]:py-2`,`[&_.katex]:text-inherit`,t),children:(0,m.jsx)(r,{remarkPlugins:[d],rehypePlugins:[f],components:{code({className:e,children:t,node:r,...a}){let l=/language-([^\s]+)/.exec(e||``),u=String(t),d=u.replace(/\n$/,``),f=l?l[1]:null;return f||u.includes(`
3
- `)?(0,m.jsxs)(`div`,{className:`relative group my-4 overflow-hidden rounded-xl border border-gray-200 dark:border-dark-300 shadow-sm`,children:[(0,m.jsxs)(`div`,{className:`flex items-center justify-between bg-gray-50 dark:bg-dark-100 px-4 py-3 border-b border-gray-200 dark:border-dark-300`,children:[(0,m.jsx)(`span`,{className:`text-xs font-semibold text-gray-700 dark:text-dark-700 uppercase tracking-wide`,children:f||`text`}),(0,m.jsx)(`button`,{onClick:()=>y(d),className:`opacity-0 group-hover:opacity-100 transition-all duration-200 p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-300 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,title:`Copy code`,children:i===d?(0,m.jsx)(s,{className:`h-4 w-4 text-success-600 dark:text-success-400`}):(0,m.jsx)(o,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`})})]}),(0,m.jsx)(`div`,{className:`overflow-x-auto`,children:(0,m.jsx)(p.Suspense,{fallback:(0,m.jsx)(_,{className:`!m-0 !rounded-none !border-none`,children:d}),children:(0,m.jsx)(g,{language:f||`text`,isDark:n.mode===`dark`,className:`!m-0 !rounded-none !border-none`,children:d})})})]}):(0,m.jsx)(`code`,{className:c(`px-2 py-1 rounded-md bg-gray-100 dark:bg-dark-200 text-gray-800 dark:text-dark-800`,`font-mono text-sm border border-gray-200 dark:border-dark-300`,e),...a,children:t})},pre({children:e,node:t,...n}){return(0,m.jsx)(`pre`,{...n,children:e})},p({children:e,...t}){return(0,m.jsx)(`div`,{className:`mb-4 last:mb-0 leading-relaxed`,...t,children:e})},ul({children:e,...t}){return(0,m.jsx)(`ul`,{className:`list-disc list-inside mb-4 space-y-2 pl-4`,...t,children:e})},ol({children:e,...t}){return(0,m.jsx)(`ol`,{className:`list-decimal list-inside mb-4 space-y-2 pl-4`,...t,children:e})},li({children:e,...t}){return(0,m.jsx)(`li`,{className:`text-gray-700 dark:text-dark-700 leading-relaxed`,...t,children:e})},blockquote({children:e,...t}){return(0,m.jsx)(`blockquote`,{className:`border-l-4 border-primary-400 dark:border-primary-500 bg-primary-25 dark:bg-primary-950/30 pl-4 py-3 my-4 rounded-r-lg italic text-gray-700 dark:text-dark-700`,...t,children:e})},h1({children:e,...t}){return(0,m.jsx)(`h1`,{className:`text-2xl font-bold mb-4 mt-6 first:mt-0 text-gray-900 dark:text-dark-800 border-b border-gray-200 dark:border-dark-300 pb-2`,...t,children:e})},h2({children:e,...t}){return(0,m.jsx)(`h2`,{className:`text-xl font-semibold mb-3 mt-6 first:mt-0 text-gray-900 dark:text-dark-800`,...t,children:e})},h3({children:e,...t}){return(0,m.jsx)(`h3`,{className:`text-lg font-medium mb-3 mt-4 first:mt-0 text-gray-900 dark:text-dark-800`,...t,children:e})}},children:v})})};export{v as RichMessageContent,v as default};