libre-webui 0.13.3 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/backend/dist/index.d.ts.map +1 -1
- package/backend/dist/index.js +14 -1
- package/backend/dist/index.js.map +1 -1
- package/backend/dist/services/titleGenerationService.d.ts.map +1 -1
- package/backend/dist/services/titleGenerationService.js +1 -0
- package/backend/dist/services/titleGenerationService.js.map +1 -1
- package/backend/dist/types/index.d.ts +1 -0
- package/backend/dist/types/index.d.ts.map +1 -1
- package/backend/dist/types/index.js.map +1 -1
- package/backend/package.json +1 -1
- package/frontend/dist/assets/index-BPvF-fpc.css +1 -0
- package/frontend/dist/assets/index-Cp8PdlFo.js +5 -0
- package/frontend/dist/index.html +4 -3
- package/frontend/dist/js/ArtifactContainer-Blx2e3aj.js +1 -0
- package/frontend/dist/js/{ArtifactDemoPage-DlROHIWC.js → ArtifactDemoPage-ChIM17kG.js} +2 -2
- package/frontend/dist/js/ArtifactSlideOutPanel-BypEW58A.js +1 -0
- package/frontend/dist/js/ChatPage-gNqQdhRe.js +16 -0
- package/frontend/dist/js/FirstTimeSetup-DS5-kf4m.js +1 -0
- package/frontend/dist/js/GalleryPage-vdXO-QSc.js +1 -0
- package/frontend/dist/js/LibreClawPage-CA7LgGj7.js +1 -0
- package/frontend/dist/js/ModelManagerModals-D1_k_AKo.js +1 -0
- package/frontend/dist/js/ModelsPage-Bxig1vZN.js +2 -0
- package/frontend/dist/js/OptimizedSyntaxHighlighter-BR97Z7hi.js +1 -0
- package/frontend/dist/js/PersonasPage-BMm3MuVw.js +13 -0
- package/frontend/dist/js/RichMessageContent-COEmecOd.js +3 -0
- package/frontend/dist/js/SettingsModal-DvFcpdVU.js +1 -0
- package/frontend/dist/js/UserManagementPage-C6ZvMO_V.js +1 -0
- package/frontend/dist/js/{api-CdKv5S1E.js → api-BNnUZaFX.js} +2 -2
- package/frontend/dist/js/{ar-CxLY7ABG.js → ar-UnnZB1Qy.js} +1 -1
- package/frontend/dist/js/{bn-DREExDzT.js → bn-uZXaDyeV.js} +1 -1
- package/frontend/dist/js/{cs-LDpGwqlb.js → cs-CCXlnUEB.js} +1 -1
- package/frontend/dist/js/{da-Csupo97j.js → da--BpVVGPp.js} +1 -1
- package/frontend/dist/js/{de-EOghQcPX.js → de-DZd9lsBc.js} +1 -1
- package/frontend/dist/js/{es-CiX_CYKt.js → es-Bm968oUX.js} +1 -1
- package/frontend/dist/js/{fr-1IIacQYp.js → fr-RlC0rD8I.js} +1 -1
- package/frontend/dist/js/{hi-DGT4fx6S.js → hi-C6kwkL7d.js} +1 -1
- package/frontend/dist/js/{id-0UGudeEI.js → id-CDfqnnXS.js} +1 -1
- package/frontend/dist/js/{is-BQzgz0LG.js → is-Dnd_7Jqv.js} +1 -1
- package/frontend/dist/js/{it-3PfovgDw.js → it-BM0j6_Sz.js} +1 -1
- package/frontend/dist/js/{ja-BaXdHNz8.js → ja-xGblKDDf.js} +1 -1
- package/frontend/dist/js/{ko-DNqxLzw3.js → ko-CQ2d_Oj0.js} +1 -1
- package/frontend/dist/js/{ms-D_X86VRO.js → ms-CFpRuv_a.js} +1 -1
- package/frontend/dist/js/{nl-B832wh-7.js → nl-D6oTztmP.js} +1 -1
- package/frontend/dist/js/{pl-BDMgy2lk.js → pl-ByuvABul.js} +1 -1
- package/frontend/dist/js/{pt-CbhjHMrx.js → pt-CNFV21T7.js} +1 -1
- package/frontend/dist/js/{ru-CEe0KRO9.js → ru-CRsSOntz.js} +1 -1
- package/frontend/dist/js/{sv-BWwpkP0M.js → sv-BRkwjyS5.js} +1 -1
- package/frontend/dist/js/syntax-highlight-B8OiKBhG.js +8 -0
- package/frontend/dist/js/{th-Dm5aEMnB.js → th-DigqsQEB.js} +1 -1
- package/frontend/dist/js/{tr-DMaVgSRT.js → tr-B5aMUMJE.js} +1 -1
- package/frontend/dist/js/{uk-Cu1mMWfT.js → uk-BUYi3llT.js} +1 -1
- package/frontend/dist/js/useBaseQuery-EKJwyGqK.js +1 -0
- package/frontend/dist/js/useQuery-CCuhLVjf.js +1 -0
- package/frontend/dist/js/useTranslation-CP6Cg-EI.js +1 -0
- package/frontend/dist/js/{vi-B_DGmAUD.js → vi-hQIcXi3m.js} +1 -1
- package/frontend/dist/js/{zh-DIKyA5Kk.js → zh-CUDZ3JDv.js} +1 -1
- package/package.json +8 -4
- package/frontend/dist/assets/index-CXKTQEWS.js +0 -5
- package/frontend/dist/assets/index-ClnPpnM5.css +0 -1
- package/frontend/dist/js/ArtifactContainer-DiRnahHG.js +0 -1
- package/frontend/dist/js/ArtifactSlideOutPanel-Bsj35Ixs.js +0 -1
- package/frontend/dist/js/ChatPage-CjrNWkGe.js +0 -16
- package/frontend/dist/js/FirstTimeSetup-DHqRxGnu.js +0 -1
- package/frontend/dist/js/GalleryPage-D6JI9-bu.js +0 -1
- package/frontend/dist/js/LibreClawPage-C5UCG3UO.js +0 -1
- package/frontend/dist/js/ModelManagerModals-ibSD3Sfs.js +0 -1
- package/frontend/dist/js/ModelsPage-4isgqfxd.js +0 -2
- package/frontend/dist/js/OptimizedSyntaxHighlighter-Fr-hsdRj.js +0 -1
- package/frontend/dist/js/PersonasPage-CQPSBBkb.js +0 -13
- package/frontend/dist/js/RichMessageContent-DmV_QHWo.js +0 -3
- package/frontend/dist/js/SettingsModal-CMgPDKKF.js +0 -1
- package/frontend/dist/js/UserManagementPage-KmYKTbzm.js +0 -1
- package/frontend/dist/js/syntax-highlight-D5wpTVgr.js +0 -8
- package/frontend/dist/js/useBaseQuery-4Pd5VVAl.js +0 -1
- package/frontend/dist/js/useQuery-BgOybVfP.js +0 -1
package/frontend/dist/index.html
CHANGED
|
@@ -10,18 +10,19 @@
|
|
|
10
10
|
name="description"
|
|
11
11
|
content="A modern, minimalist WebUI for interacting with local LLMs through Ollama API"
|
|
12
12
|
/>
|
|
13
|
-
<script type="module" crossorigin src="/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/assets/index-Cp8PdlFo.js"></script>
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/js/rolldown-runtime-QTnfLwEv.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/js/markdown-core-fkbHPd-g.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/js/react-vendor-Co1u1rWb.js">
|
|
17
17
|
<link rel="modulepreload" crossorigin href="/js/demoMode-BhEpMVh5.js">
|
|
18
18
|
<link rel="modulepreload" crossorigin href="/js/logger-BmpKNkls.js">
|
|
19
|
+
<link rel="modulepreload" crossorigin href="/js/useTranslation-CP6Cg-EI.js">
|
|
19
20
|
<link rel="modulepreload" crossorigin href="/js/ui-vendor-njo77ljx.js">
|
|
20
21
|
<link rel="modulepreload" crossorigin href="/js/utils-vendor-BX3ZwoIK.js">
|
|
21
|
-
<link rel="modulepreload" crossorigin href="/js/api-
|
|
22
|
+
<link rel="modulepreload" crossorigin href="/js/api-BNnUZaFX.js">
|
|
22
23
|
<link rel="modulepreload" crossorigin href="/js/utils-D0l9J3P-.js">
|
|
23
24
|
<link rel="modulepreload" crossorigin href="/js/Button-BZBnLKRn.js">
|
|
24
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
25
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BPvF-fpc.css">
|
|
25
26
|
</head>
|
|
26
27
|
<body>
|
|
27
28
|
<div id="root"></div>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./logger-BmpKNkls.js";import{t as i}from"./useTranslation-CP6Cg-EI.js";import{I as a,Ot as o,Rt as s,Y as c,at as l,dt as u,ot as d,st as f,tt as p,ut as m,vt as h}from"./ui-vendor-njo77ljx.js";import{t as g}from"./utils-D0l9J3P-.js";import{t as _}from"./Button-BZBnLKRn.js";import{O as v}from"../assets/index-Cp8PdlFo.js";import{t as y}from"./OptimizedSyntaxHighlighter-BR97Z7hi.js";import{n as b,r as x,t as S}from"./artifactHtml-B7Oy2e__.js";var C=e(n(),1),w=t(),T=r(`components:artifact-renderer`),E=({artifact:e,className:t})=>{let{t:n}=i(),[r,E]=(0,C.useState)(!1),[D,O]=(0,C.useState)(`preview`),k=(0,C.useRef)(null),{theme:A,openArtifactPanel:j}=v(),M=async e=>{try{await navigator.clipboard.writeText(e),E(!0),setTimeout(()=>E(!1),2e3)}catch(e){T.error(`Failed to copy:`,e)}},N=()=>{let t=e.type===`html`?x(e.content,e.title):e.content,n=new Blob([t],{type:P(e.type)}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.title}.${F(e.type)}`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)},P=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},F=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},I=()=>{switch(e.type){case`html`:return(0,w.jsx)(c,{className:`h-4 w-4`});case`react`:return(0,w.jsx)(u,{className:`h-4 w-4`});case`svg`:return(0,w.jsx)(p,{className:`h-4 w-4`});case`code`:return(0,w.jsx)(u,{className:`h-4 w-4`});default:return(0,w.jsx)(p,{className:`h-4 w-4`})}},L=()=>(0,w.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,w.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,w.jsx)(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:n(`artifacts.previewUnavailable`)}),(0,w.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:n(`artifacts.previewUnavailableDescription`)}),(0,w.jsxs)(_,{variant:`outline`,size:`sm`,onClick:()=>O(`code`),className:`mt-4`,children:[(0,w.jsx)(s,{className:`h-3.5 w-3.5 mr-1.5`}),n(`artifacts.code`)]})]})}),R=()=>e.content.trim()?(0,w.jsx)(`iframe`,{ref:k,"data-testid":`artifact-html-preview`,srcDoc:x(e.content,e.title),className:`w-full h-64 sm:h-80 lg:h-96 border-0 rounded-lg`,sandbox:b,allow:S,allowFullScreen:!0,title:e.title}):L(),z=()=>{try{return(0,w.jsx)(`div`,{className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg overflow-hidden border border-gray-200 dark:border-dark-200`,dangerouslySetInnerHTML:{__html:e.content}})}catch{return(0,w.jsx)(`div`,{className:`w-full h-64 sm:h-80 lg:h-96 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(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:n(`artifacts.invalidSvg`)})]})})}},B=()=>(0,w.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,w.jsx)(y,{language:(()=>{if(e.language)return e.language;switch(e.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:A.mode===`dark`,className:`!m-0 !rounded-lg`,children:e.content})}),V=()=>{try{let t=JSON.parse(e.content),n=JSON.stringify(t,null,2);return(0,w.jsx)(`div`,{className:`relative max-h-64 sm:max-h-80 lg:max-h-96 overflow-auto`,children:(0,w.jsx)(y,{language:`json`,isDark:A.mode===`dark`,className:`!m-0 !rounded-lg`,children:n})})}catch{return(0,w.jsx)(`div`,{className:`w-full h-32 flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200`,children:(0,w.jsxs)(`div`,{className:`text-center`,children:[(0,w.jsx)(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:n(`artifacts.invalidJson`)})]})})}},H=()=>{if(D===`code`)return B();switch(e.type){case`html`:return R();case`svg`:return z();case`json`:return V();default:return B()}},U=()=>e.type===`html`||e.type===`svg`||e.type===`react`;return(0,w.jsxs)(`div`,{className:g(`border border-gray-200 dark:border-dark-200 rounded-xl bg-white dark:bg-dark-25 shadow-lg transition-all duration-300 hover:shadow-xl`,`w-full max-w-full overflow-hidden animate-fade-in`,`max-h-[400px] flex flex-col`,t),children:[(0,w.jsxs)(`div`,{className:`px-1.5 py-1.5 sm:p-4 border-b border-gray-100 dark:border-dark-200 flex-shrink-0`,children:[(0,w.jsxs)(`div`,{className:`flex flex-col gap-2 sm:hidden`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,w.jsx)(`div`,{className:`h-4 w-4 flex-shrink-0 flex items-center justify-center`,children:I()}),(0,w.jsx)(`h3`,{className:`font-medium text-gray-900 dark:text-gray-100 truncate text-sm leading-tight flex-1`,children:e.title})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-end gap-0.5`,children:[U()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsx)(_,{variant:D===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`preview`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.previewMode`),children:(0,w.jsx)(l,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:D===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`code`),className:`h-5 px-0.5 text-xs`,title:n(`artifacts.codeMode`),children:(0,w.jsx)(s,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(`div`,{className:`w-px h-2 bg-gray-300 dark:bg-gray-600 mx-0.5`})]}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.copyContent`),children:r?(0,w.jsx)(h,{className:`h-2.5 w-2.5 text-green-500`}):(0,w.jsx)(m,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation`,title:n(`artifacts.download`),children:(0,w.jsx)(f,{className:`h-2.5 w-2.5`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>j(e),className:`h-5 w-5 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 touch-manipulation border border-gray-200 dark:border-dark-300 hover:border-gray-300 dark:hover:border-dark-400`,title:n(`artifacts.openInPanel`),children:(0,w.jsx)(a,{className:`h-2.5 w-2.5`})})]})]}),(0,w.jsxs)(`div`,{className:`hidden sm:flex items-center justify-between gap-2`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-1`,children:[(0,w.jsx)(`div`,{className:`flex-shrink-0`,children:I()}),(0,w.jsx)(`h3`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:e.title})]}),(0,w.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:e.type.toUpperCase()})]}),(0,w.jsxs)(`div`,{className:`flex items-center gap-1 flex-shrink-0`,children:[U()&&(0,w.jsxs)(w.Fragment,{children:[(0,w.jsxs)(_,{variant:D===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`preview`),className:`h-8 px-3 text-xs`,title:n(`artifacts.previewMode`),children:[(0,w.jsx)(l,{className:`h-3 w-3 mr-1`}),n(`artifacts.preview`)]}),(0,w.jsxs)(_,{variant:D===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>O(`code`),className:`h-8 px-3 text-xs`,title:n(`artifacts.codeMode`),children:[(0,w.jsx)(s,{className:`h-3 w-3 mr-1`}),n(`artifacts.code`)]}),(0,w.jsx)(`div`,{className:`w-px h-4 bg-gray-300 dark:bg-gray-600 mx-1`})]}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>M(e.content),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.copyContent`),children:r?(0,w.jsx)(h,{className:`h-4 w-4 text-green-500`}):(0,w.jsx)(m,{className:`h-4 w-4`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:N,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.download`),children:(0,w.jsx)(f,{className:`h-4 w-4`})}),(0,w.jsx)(_,{variant:`ghost`,size:`sm`,onClick:()=>j(e),className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200`,title:n(`artifacts.openInPanel`),children:(0,w.jsx)(a,{className:`h-4 w-4`})})]})]})]}),(0,w.jsxs)(`div`,{className:`p-4 flex-1 overflow-hidden min-h-0`,children:[e.description&&(0,w.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400 mb-4`,children:e.description}),(0,w.jsx)(`div`,{className:`h-full overflow-auto`,children:H()})]}),(0,w.jsxs)(`div`,{className:`flex items-center justify-between p-3 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50 flex-shrink-0`,children:[(0,w.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[n(`artifacts.created`),`:`,` `,new Date(e.createdAt).toLocaleString()]}),(e.type===`html`||e.type===`react`)&&(0,w.jsxs)(_,{variant:`ghost`,size:`sm`,onClick:()=>{let t=window.open(``,`_blank`);t&&(t.document.write(x(e.content,e.title)),t.document.close())},className:`text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,children:[(0,w.jsx)(d,{className:`h-3 w-3 mr-1`}),n(`artifacts.openInNewWindow`)]})]})]})},D=({artifacts:e,className:t})=>!e||e.length===0?null:(0,w.jsx)(`div`,{className:g(`space-y-3`,t),children:e.map(e=>(0,w.jsx)(E,{artifact:e},e.id))});export{D as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./Button-BZBnLKRn.js";import{
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./Button-BZBnLKRn.js";import{a as i}from"../assets/index-Cp8PdlFo.js";import{t as a}from"./ArtifactContainer-Blx2e3aj.js";var o=e(n(),1),s=t(),c=[{id:`demo-html-1`,type:`html`,title:`Interactive Button Demo`,description:`A simple HTML page with interactive elements`,content:`<div style="text-align: center; padding: 20px;">
|
|
2
2
|
<h1 style="color: #333; font-family: Arial, sans-serif;">Welcome to Libre WebUI!</h1>
|
|
3
3
|
<p style="color: #666; font-size: 16px;">This is an interactive HTML artifact.</p>
|
|
4
4
|
<button
|
|
@@ -197,4 +197,4 @@ def process_data(filename):
|
|
|
197
197
|
if __name__ == "__main__":
|
|
198
198
|
result = process_data('data.csv')
|
|
199
199
|
print("Data processing results:")
|
|
200
|
-
print(result)`,createdAt:Date.now(),updatedAt:Date.now()}],
|
|
200
|
+
print(result)`,createdAt:Date.now(),updatedAt:Date.now()}],l=()=>{let[e,t]=(0,o.useState)([c[0]]),n=n=>{e.find(e=>e.id===n.id)||t([...e,n])},i=n=>{t(e.filter(e=>e.id!==n))};return(0,s.jsxs)(`div`,{className:`text-gray-900 dark:text-dark-800`,children:[(0,s.jsxs)(`div`,{className:`mb-8`,children:[(0,s.jsx)(`h1`,{className:`text-3xl font-bold text-gray-900 dark:text-gray-100 mb-4`,children:`Artifacts Demo`}),(0,s.jsx)(`p`,{className:`text-gray-600 dark:text-gray-400 text-lg`,children:`This demonstrates the Artifacts feature - interactive content that can be rendered alongside chat messages. Try the different artifact types below.`})]}),(0,s.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-4 gap-6`,children:[(0,s.jsxs)(`div`,{className:`lg:col-span-1`,children:[(0,s.jsx)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:`Available Artifacts`}),(0,s.jsx)(`div`,{className:`space-y-2`,children:c.map(t=>(0,s.jsxs)(`div`,{className:`flex items-center justify-between p-3 bg-white dark:bg-dark-200 border border-gray-200 dark:border-dark-300 rounded-lg`,children:[(0,s.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,s.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:t.title}),(0,s.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 uppercase`,children:t.type})]}),(0,s.jsx)(r,{size:`sm`,variant:e.find(e=>e.id===t.id)?`outline`:`primary`,onClick:()=>{e.find(e=>e.id===t.id)?i(t.id):n(t)},children:e.find(e=>e.id===t.id)?`Remove`:`Add`})]},t.id))})]}),(0,s.jsxs)(`div`,{className:`lg:col-span-3`,children:[(0,s.jsxs)(`h2`,{className:`text-xl font-semibold text-gray-900 dark:text-gray-100 mb-4`,children:[`Selected Artifacts (`,e.length,`)`]}),e.length>0?(0,s.jsx)(a,{artifacts:e}):(0,s.jsx)(`div`,{className:`text-center py-12 text-gray-500 dark:text-gray-400`,children:(0,s.jsx)(`p`,{children:`No artifacts selected. Choose some from the left panel to see them in action.`})})]})]}),(0,s.jsxs)(`div`,{className:`mt-12 bg-white dark:bg-dark-25 border border-gray-200 dark:border-dark-300 rounded-lg p-6`,children:[(0,s.jsx)(`h3`,{className:`text-lg font-semibold text-gray-900 dark:text-dark-900 mb-3`,children:`How Artifacts Work`}),(0,s.jsxs)(`div`,{className:`text-sm text-gray-700 dark:text-dark-700 space-y-2`,children:[(0,s.jsxs)(`p`,{children:[(0,s.jsx)(`strong`,{children:`Automatic Detection:`}),` When an AI model returns code blocks with specific languages (HTML, SVG, Python, etc.), they are automatically converted into interactive artifacts.`]}),(0,s.jsxs)(`p`,{children:[(0,s.jsx)(`strong`,{children:`Supported Types:`}),` HTML pages, SVG graphics, JSON data, code snippets, React components, and more.`]}),(0,s.jsxs)(`p`,{children:[(0,s.jsx)(`strong`,{children:`Interactive Features:`}),` View in fullscreen, copy content, download files, and open in new windows.`]}),(0,s.jsxs)(`p`,{children:[(0,s.jsx)(`strong`,{children:`Safe Rendering:`}),` All artifacts are rendered in sandboxed environments for security.`]})]})]})]})},u=()=>(0,s.jsx)(i,{width:`wide`,children:(0,s.jsx)(l,{})});export{u as default};
|
|
@@ -0,0 +1 @@
|
|
|
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{t as a}from"./useTranslation-CP6Cg-EI.js";import{J as o,Ot as s,Rt as c,Y as ee,at as te,dt as l,n as u,ot as d,st as f,tt as p,ut as ne,vt as m}from"./ui-vendor-njo77ljx.js";import{t as h}from"./utils-D0l9J3P-.js";import{t as g}from"./Button-BZBnLKRn.js";import{I as _,O as v}from"../assets/index-Cp8PdlFo.js";import{t as y}from"./OptimizedSyntaxHighlighter-BR97Z7hi.js";import{n as re,r as b,t as ie}from"./artifactHtml-B7Oy2e__.js";var x=e(n(),1),S=r(),C=t(),w=i(`components:artifact-slide-out-panel`),T=320,E=.9,D=600,O=()=>{let{t:e,i18n:t}=a(),n=_(t.language),{artifactPanelOpen:r,artifactPanelArtifact:i,closeArtifactPanel:O,theme:k}=v(),[A,j]=(0,x.useState)(!1),[M,N]=(0,x.useState)(`preview`),[P,F]=(0,x.useState)(D),[I,L]=(0,x.useState)(!1),R=(0,x.useRef)(null),z=(0,x.useRef)(null),B=(0,x.useRef)(null),V=(0,x.useRef)(0),H=(0,x.useRef)(0),U=(0,x.useRef)(null),W=(0,x.useRef)(null),G=(0,x.useRef)(P),K=i?.id??null;K!==B.current&&(B.current=K,M!==`preview`&&N(`preview`));let q=(0,x.useCallback)(e=>{G.current=e,W.current===null&&(W.current=window.requestAnimationFrame(()=>{W.current=null,F(G.current)}))},[]),J=(0,x.useCallback)(()=>{U.current=null,L(!1),W.current!==null&&(window.cancelAnimationFrame(W.current),W.current=null,F(G.current))},[]),ae=(0,x.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),U.current=e.pointerId,H.current=P,V.current=e.clientX,G.current=P,e.currentTarget.setPointerCapture(e.pointerId),L(!0)},[P]),Y=(0,x.useCallback)(e=>{if(!I||U.current!==null&&e.pointerId!==U.current)return;e.preventDefault();let t=(V.current-e.clientX)*(n?-1:1),r=window.innerWidth*E;q(Math.min(r,Math.max(T,H.current+t)))},[I,n,q]);if((0,x.useEffect)(()=>{if(!I){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(U.current===null||e.pointerId===U.current)&&J()};return window.addEventListener(`pointermove`,Y,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,J),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,Y),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,J),document.body.style.userSelect=``,document.body.style.cursor=``}},[I,Y,J]),(0,x.useEffect)(()=>{let e=()=>{let e=window.innerWidth*E;P>e&&F(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[P]),(0,x.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r&&O()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,O]),(0,x.useEffect)(()=>{let e=e=>{I||z.current&&!z.current.contains(e.target)&&r&&O()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,O,I]),!i)return null;let X=i,oe=async e=>{try{await navigator.clipboard.writeText(e),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){w.error(`Failed to copy:`,e)}},se=()=>{let e=X.type===`html`?b(X.content,X.title):X.content,t=new Blob([e],{type:ce(X.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${X.title}.${le(X.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ce=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},le=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},Z=()=>{switch(X.type){case`html`:return(0,C.jsx)(ee,{className:`h-5 w-5`});case`react`:return(0,C.jsx)(l,{className:`h-5 w-5`});case`svg`:return(0,C.jsx)(p,{className:`h-5 w-5`});case`code`:return(0,C.jsx)(l,{className:`h-5 w-5`});default:return(0,C.jsx)(p,{className:`h-5 w-5`})}},ue=()=>(0,C.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,C.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,C.jsx)(s,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,C.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,C.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,C.jsxs)(g,{variant:`outline`,size:`sm`,onClick:()=>N(`code`),className:`mt-4`,children:[(0,C.jsx)(c,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),de=()=>X.content.trim()?(0,C.jsx)(`iframe`,{ref:R,"data-testid":`artifact-html-preview`,srcDoc:b(X.content,X.title),className:h(`w-full h-full border-0 rounded-lg bg-white`,I&&`pointer-events-none`),sandbox:re,allow:ie,allowFullScreen:!0,title:X.title}):ue(),fe=()=>{try{return(0,C.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,C.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,C.jsxs)(`div`,{className:`text-center`,children:[(0,C.jsx)(s,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidSvg`)})]})})}},Q=()=>(0,C.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,C.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:k.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:X.content})}),pe=()=>{try{let e=JSON.parse(X.content),t=JSON.stringify(e,null,2);return(0,C.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,C.jsx)(y,{language:`json`,isDark:k.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,C.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,C.jsxs)(`div`,{className:`text-center`,children:[(0,C.jsx)(s,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},me=()=>{if(M===`code`)return Q();switch(X.type){case`html`:return de();case`svg`:return fe();case`json`:return pe();default:return Q()}},he=()=>X.type===`html`||X.type===`svg`||X.type===`react`,$=typeof window<`u`&&window.innerWidth<640,ge=$?`100%`:`${P}px`;return(0,S.createPortal)((0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(`div`,{className:h(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),I&&(0,C.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,C.jsxs)(`div`,{ref:z,"data-testid":`artifact-slide-out-panel`,style:{width:ge},className:h(`fixed top-0 end-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,C.jsxs)(`div`,{onPointerDown:ae,"data-testid":`artifact-resize-handle`,className:h(`absolute start-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,C.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`,I&&`bg-primary-500 h-24`)}),(0,C.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`,I&&`opacity-100`),children:(0,C.jsx)(o,{className:`h-4 w-4`})})]}),(0,C.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,C.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,C.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:Z()}),(0,C.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:X.title}),(0,C.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,C.jsx)(g,{variant:`ghost`,size:`sm`,onClick:O,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,C.jsx)(u,{className:`h-5 w-5`})})]}),(0,C.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,C.jsx)(`div`,{className:`flex items-center gap-1`,children:he()&&(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)(g,{variant:M===`preview`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`preview`),className:`h-8 px-3 text-xs`,title:e(`artifacts.previewMode`),children:[(0,C.jsx)(te,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.preview`)]}),(0,C.jsxs)(g,{variant:M===`code`?`primary`:`ghost`,size:`sm`,onClick:()=>N(`code`),className:`h-8 px-3 text-xs`,title:e(`artifacts.codeMode`),children:[(0,C.jsx)(c,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),(0,C.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,C.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>oe(X.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:A?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(m,{className:`h-3.5 w-3.5 me-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)(ne,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.copyButton`)]})}),(0,C.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:se,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,C.jsx)(f,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.download`)]}),(X.type===`html`||X.type===`react`)&&(0,C.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:()=>{let e=window.open(``,`_blank`);e&&(e.document.write(b(X.content,X.title)),e.document.close())},className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.openInNewWindow`),children:[(0,C.jsx)(d,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.open`)]})]})]}),X.description&&(0,C.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,C.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:X.description})}),(0,C.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:me()}),(0,C.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,C.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,C.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(X.createdAt).toLocaleString()]}),!$&&(0,C.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]}),document.body)};export{O as ArtifactSlideOutPanel};
|
|
@@ -0,0 +1,16 @@
|
|
|
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-CCuhLVjf.js";import{t as a}from"./logger-BmpKNkls.js";import{t as o}from"./useTranslation-CP6Cg-EI.js";import{A as s,At as c,Bt as l,C as u,Ct as d,D as f,G as p,H as m,Mt as h,N as g,Nt as _,P as v,Q as y,Rt as b,S as x,St as S,T as C,Tt as w,U as T,Vt as E,Y as D,Z as O,_t as k,a as A,c as j,ct as M,d as N,dt as P,et as F,ft as I,h as L,ht as R,i as ee,lt as z,mt as te,n as B,o as ne,ot as re,q as ie,r as ae,st as oe,t as se,tt as ce,ut as le,v as V,vt as ue,x as H,xt as de,y as fe,z as U}from"./ui-vendor-njo77ljx.js";import{n as pe}from"./demoMode-BhEpMVh5.js";import{_ as me,a as W,c as he,d as ge,h as _e,i as ve,l as ye,m as be,n as xe,p as Se,u as Ce}from"./api-BNnUZaFX.js";import{i as we,n as Te,r as Ee,t as G}from"./utils-D0l9J3P-.js";import{t as K}from"./Button-BZBnLKRn.js";import{B as De,C as Oe,E as q,H as ke,I as Ae,O as je,P as J,S as Me,T as Ne,V as Pe,f as Fe,v as Ie,x as Le,y as Re}from"../assets/index-Cp8PdlFo.js";import{a as ze,i as Be}from"./artifactHtml-B7Oy2e__.js";import{t as Ve}from"./ArtifactContainer-Blx2e3aj.js";var He=r(),Y=e(n(),1),X=t(),Ue=({statistics:e,className:t=``})=>{let[n,r]=(0,Y.useState)(!1),{t:i}=o(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},s=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=s(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)(m,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,X.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,X.jsx)(`span`,{className:`text-gray-400 dark:text-dark-400 bg-gray-100 dark:bg-dark-200 px-2 py-0.5 rounded-full truncate max-w-32 sm:max-w-48`,title:e.model,children:e.model})]}),(0,X.jsxs)(`button`,{onClick:()=>r(!n),className:`flex items-center gap-1 text-gray-400 dark:text-dark-400 hover:text-gray-600 dark:hover:text-dark-600 transition-colors`,children:[n?(0,X.jsx)(k,{size:12}):(0,X.jsx)(R,{size:12,className:`rtl:rotate-180`}),(0,X.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,X.jsxs)(`div`,{className:`mt-2 p-3 bg-gray-50 dark:bg-dark-100 border border-gray-200 dark:border-dark-300 rounded-lg text-xs space-y-2`,children:[(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,X.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,X.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,X.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},We=a(`components:ttsbutton`),Ge=null,Ke=null,qe=0,Je=300*1e3;async function Ye(e=!1){let t=Date.now();return!e&&Ge!==null&&t-qe<Je?Ge:Ke||(Ke=(async()=>{try{let e=await W.getModels();return e.success&&e.data&&e.data.length>0?(Ge=e.data,qe=t,e.data):(Ge=[],qe=t,[])}catch{return Ge=[],qe=t,[]}finally{Ke=null}})(),Ke)}function Xe(e){return e.split(/(?<=[.!?]["']?\s)|(?<=[.!?]["']?$)/).map(e=>e.trim()).filter(e=>e.length>0)}var Ze=({text:e,className:t,size:n=`sm`})=>{let{t:r}=o(),{preferences:i}=je(),[a,s]=(0,Y.useState)(!1),[c,l]=(0,Y.useState)(!1),[u,d]=(0,Y.useState)(null),[f,p]=(0,Y.useState)([]),[m,h]=(0,Y.useState)(null),g=(0,Y.useRef)(null),v=(0,Y.useRef)(!1),y=(0,Y.useRef)([]),b=(0,Y.useRef)(0);(0,Y.useEffect)(()=>{let e=!0;return(async()=>{let t=await Ye(),n=xe(t,i.ttsSettings?.model,i.ttsSettings?.pluginId);i.ttsSettings?.model&&!n&&(t=await Ye(!0)),e&&(p(t),h(t.length>0))})(),()=>{e=!1}},[i.ttsSettings?.model,i.ttsSettings?.pluginId]);let x=(0,Y.useCallback)(async(e,t,n,i,a,o)=>{let s=await W.generateBase64({model:t,pluginId:n,input:e,voice:i,speed:a,response_format:o});if(!s.success||!s.data?.audio)throw Error(s.message||r(`ttsButton.generateFailed`));let c=`data:${s.data.mimeType};base64,${s.data.audio}`,l=new Audio(c);return g.current=l,new Promise((e,t)=>{l.onended=()=>{g.current=null,e()},l.onerror=()=>{g.current=null,t(Error(r(`ttsButton.playbackFailed`)))},l.play().catch(t)})},[r]),S=(0,Y.useCallback)(async(e,t,n,r,i,a)=>{y.current=e,b.current=0,v.current=!1;let o=null,s=async e=>{try{let o=await W.generateBase64({model:t,pluginId:n,input:e,voice:r,speed:i,response_format:a});return!o.success||!o.data?.audio?null:{audioUrl:`data:${o.data.mimeType};base64,${o.data.audio}`,mimeType:o.data.mimeType}}catch{return null}};e.length>0&&(o=s(e[0]));for(let t=0;t<e.length&&!v.current;t++){b.current=t;try{let n=await o;if(v.current)break;if(o=t+1<e.length?s(e[t+1]):null,!n){We.warn(`Failed to generate audio for sentence ${t+1}, skipping`);continue}let r=new Audio(n.audioUrl);g.current=r,await new Promise((e,t)=>{r.onended=()=>{g.current=null,e()},r.onerror=()=>{g.current=null,e()},r.play().catch(()=>{e()})})}catch(e){We.error(`Error playing sentence ${t+1}:`,e)}}},[]),C=(0,Y.useCallback)(()=>{v.current=!0,g.current&&(g.current.pause(),g.current.currentTime=0,g.current=null),s(!1),l(!1)},[]),w=async()=>{if(!c){if(a){C();return}l(!0),d(null),v.current=!1;try{let t=i.ttsSettings,n=ve(f,t?.model,t?.pluginId),a=n?.model||t?.model||`tts-1`,o=n?.plugin||t?.pluginId,c=n?.model===t?.model&&(!t?.pluginId||n?.plugin===t.pluginId)?t?.voice||n?.config?.default_voice||`alloy`:n?.config?.default_voice||`alloy`,u=t?.speed||1,p=n?.config?.default_format;if(t?.streamSentences){let t=Xe(e);if(t.length===0)throw Error(r(`ttsButton.generateFailed`));l(!1),s(!0),await S(t,a,o,c,u,p),v.current||s(!1)}else await x(e,a,o,c,u,p),l(!1),s(!0),g.current&&(g.current.onended=()=>{s(!1),g.current=null},g.current.onerror=()=>{d(r(`ttsButton.playbackFailed`)),s(!1),g.current=null})}catch(e){d(e instanceof Error?e.message:r(`ttsButton.generateFailed`)),We.error(`TTS error:`,e),s(!1),l(!1)}}};if((0,Y.useEffect)(()=>()=>{v.current=!0,g.current&&(g.current.pause(),g.current=null)},[]),m===!1||m===null)return null;let T={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},E={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`};return(0,X.jsx)(`button`,{onClick:w,disabled:c||!e,title:u||r(a?`ttsButton.stopSpeaking`:c?`ttsButton.generatingSpeech`:`ttsButton.readAloud`),className:G(`rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,u?`text-red-500 dark:text-red-400`:a?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,T[n],t),children:c?(0,X.jsx)(_,{className:G(E[n],`animate-spin`)}):a?(0,X.jsx)(L,{className:E[n]}):u?(0,X.jsx)(ee,{className:E[n]}):(0,X.jsx)(A,{className:E[n]})})},Qe=/```([^\n`]*)\n([\s\S]*?)\n```/g,$e=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,et=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],tt=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:lt(e[1]),title:nt(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=lt(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function nt(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return it(rt(e))}function rt(e){return e.replace(/&(lt|gt|quot|apos|#39);/gi,(e,t)=>{switch(t.toLowerCase()){case`lt`:return`<`;case`gt`:return`>`;case`quot`:return`"`;case`apos`:case`#39`:return`'`;default:return``}}).replace(/&/gi,`&`)}function it(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 at(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return nt(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&nt(n[1]).trim()||null}function ot(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 st(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 ct(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 lt(e){let t=e.trim().toLowerCase();return et.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 ut(e){let t=[],n=new RegExp(Qe),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=dt(n,pt(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 dt(e,t){let n=ft(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!$e.test(r)&&!r.includes(`=`)?Z(r):void 0)||Z(ht(n)),fileName:n}}function ft(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&&$e.test(t[1]))return mt(t[1]);let n=e.match($e);return n?mt(n[0]):void 0}function pt(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($e);if(t)return mt(t[0])}}function mt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function ht(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function gt(e){return e?.split(/[\\/]/).pop()}function Q(e){let t=gt(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 _t(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function vt(e){let t=Z(e.language)||Z(ht(e.fileName));switch(t){case`html`:return{type:`html`,title:at(e.content)||Q(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:Q(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:ot(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:st(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:ct(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 yt(e){return(Z(e.language)||Z(ht(e.fileName)))===`html`}function bt(e){return(Z(e.language)||Z(ht(e.fileName)))===`css`}function xt(e){return(Z(e.language)||Z(ht(e.fileName)))===`javascript`}function St(e){let t=ut(e),n=t.filter(yt);if(n.length===0)return null;let r=t.filter(bt),i=t.filter(xt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=ze(Ct(a.content,r,i),r.map(e=>e.content),i.map(e=>e.content));return Ot(o,`html`)?{artifact:_t({type:`html`,title:at(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 Ct(e,t,n){let r=e;for(let e of t){let t=gt(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${Dt(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=gt(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${Dt(t)}["'][^>]*>\\s*<\\/script>`,`gi`),``))}return r}function wt(e){let t=/<!doctype\s+html|<html[\s>]/i.exec(e);if(!t||t.index===void 0)return null;let n=ut(e);if(Tt(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 Ot(s,`html`)?{artifact:_t({type:`html`,title:at(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function Tt(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function Et(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 Dt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ot(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&&(Be(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 kt(e){let t=[],n=e;for(let e of tt){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);Ot(n.content,n.type)&&(t.push(_t({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=Et(n,r)}let r=St(n);for(;r;)t.push(r.artifact),n=Et(n,r.ranges),r=St(n);let i=wt(n);i&&(t.push(i.artifact),n=Et(n,i.ranges));let a=ut(n),o=[];for(let e of a){let n=vt(e);!n||!Ot(e.content,n.type)||(t.push(_t({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=Et(n,o),{content:n.trim(),artifacts:t}}var At=a(`components:chat-message`),jt=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i})=>{let{t:a,i18n:s}=o(),c=e.role===`user`,l=e.role===`system`,{preferences:d}=je(),{user:f}=Ne(),{setSystemMessage:p,getCurrentPersona:m}=J(),g=m(),[_,v]=(0,Y.useState)(!1),[y,b]=(0,Y.useState)(e.content),[x,S]=(0,Y.useState)(null),[w,T]=(0,Y.useState)(!1),[E,D]=(0,Y.useState)(!1),[O,A]=(0,Y.useState)(!1),[j,M]=(0,Y.useState)(!1),[N,P]=(0,Y.useState)(!1),F=(0,Y.useRef)(null),I=(0,Y.useRef)(t),L=(0,Y.useRef)(!1),R=async()=>{try{await navigator.clipboard.writeText(e.content),P(!0),setTimeout(()=>P(!1),2e3)}catch(e){At.error(`Failed to copy message:`,e)}},{thinkingContent:ee,parsedContent:z,artifacts:ne}=(0,Y.useMemo)(()=>{if(c||l||!e.content)return{thinkingContent:null,parsedContent:e.content,artifacts:e.artifacts||[]};let n=we(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=kt(r);return{thinkingContent:n.thinking,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,parsedContent:r,artifacts:[]}},[e.content,e.artifacts,c,l,t]);(0,Y.useEffect)(()=>{let e=I.current&&!t;return I.current=t,e&&!L.current&&!c&&!l&&z&&d.ttsSettings?.enabled&&d.ttsSettings?.autoPlay&&(L.current=!0,(async()=>{M(!0);try{let e=await W.getModels(),t=e.success&&e.data?e.data:[],n=d.ttsSettings,r=ve(t,n?.model,n?.pluginId),i=xe(t,n?.model,n?.pluginId),a=await W.generateBase64({model:r?.model||n?.model||`tts-1`,pluginId:r?.plugin||n?.pluginId,input:z,voice:i?n?.voice||r?.config?.default_voice||`alloy`:r?.config?.default_voice||`alloy`,speed:n?.speed||1,response_format:r?.config?.default_format});if(a.success&&a.data?.audio){let e=`data:${a.data.mimeType};base64,${a.data.audio}`,t=new Audio(e);F.current=t,t.onended=()=>{M(!1),F.current=null},t.onerror=()=>{M(!1),F.current=null},await t.play()}}catch(e){At.error(`Auto-play TTS failed:`,e),M(!1)}})()),()=>{F.current&&(F.current.pause(),F.current=null)}},[t,c,l,z,d.ttsSettings]);let re=()=>l?a(`chatMessage.system`):c?d.showUsername&&f?.username?f.username:a(`chatMessage.you`):g?.name?g.name:e.model||a(`chatMessage.assistant`),ie=()=>{v(!0),b(e.content)},ae=async()=>{T(!0);try{p(y),v(!1),At.debug(`✅ System message updated:`,y)}catch(e){At.error(`Failed to save system message:`,e)}finally{T(!1)}},oe=()=>{v(!1),b(e.content)},se=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,ce=l&&e.content.length>100;return(0,X.jsxs)(`div`,{className:G(`group flex py-3 transition-colors sm:py-4`,c?`justify-end`:`justify-start`,n),children:[(0,X.jsx)(`div`,{className:G(`flex min-w-0`,c?`max-w-[88%] sm:max-w-[72%]`:`w-full`),children:(0,X.jsxs)(`div`,{className:G(`min-w-0 flex-1`,c?`rounded-[1.35rem] rounded-ee-md border border-black/[0.06] bg-gray-900 px-4 py-3 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`:l?`bg-transparent py-2`:`bg-transparent py-1`),children:[!l&&(0,X.jsxs)(`div`,{className:G(`mb-2 flex items-center gap-2.5`,c&&`justify-end`),children:[(0,X.jsx)(`span`,{dir:`auto`,className:G(`text-[11px] font-semibold uppercase tracking-[0.1em] rtl:tracking-normal`,c?`text-white/70`:`text-gray-700 dark:text-dark-700`),children:re()}),e.model&&!c&&g?.name&&(0,X.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,X.jsx)(`span`,{dir:`auto`,className:G(`text-[10px] tabular-nums`,c?`text-white/45`:`text-gray-400 dark:text-dark-500`),children:Te(e.timestamp,s.language)})]}),(0,X.jsxs)(`div`,{className:G(c?`text-[15px] text-white`:`text-[15px] leading-7 text-gray-800 dark:text-dark-800 sm:text-base`),children:[e.images&&e.images.length>0&&(0,X.jsx)(`div`,{className:`mb-3 grid max-w-lg grid-cols-2 gap-2 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,X.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-white/10 bg-gray-100 dark:bg-gray-800`,children:(0,X.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>S(e)})},t))}),c?(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap leading-relaxed`,children:e.content}):l?(0,X.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/[0.06] bg-white/55 p-3 dark:border-white/[0.06] dark:bg-dark-200/45`,children:[(0,X.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(V,{className:`h-2.5 w-2.5 opacity-50`}),a(`chatMessage.system`)]}),(0,X.jsx)(`div`,{className:`flex items-center gap-1`,children:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`button`,{onClick:ae,disabled:w,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)(u,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,X.jsx)(`button`,{onClick:oe,disabled:w,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)(B,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,X.jsx)(`button`,{onClick:ie,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)(h,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),_?(0,X.jsx)(`textarea`,{dir:`auto`,value:y,onChange:e=>b(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:w}):(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:E?e.content:se(e.content)}),ce&&(0,X.jsx)(`button`,{onClick:()=>D(!E),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:E?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(te,{className:`h-3 w-3`}),a(`chatMessage.showLess`)]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(k,{className:`h-3 w-3`}),a(`chatMessage.showMore`)]})})]})]}):(0,X.jsxs)(`div`,{className:`relative`,children:[ee&&(0,X.jsxs)(`div`,{className:`mb-4 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,X.jsxs)(`button`,{onClick:()=>A(!O),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`)}),O?(0,X.jsx)(te,{className:`h-4 w-4`}):(0,X.jsx)(k,{className:`h-4 w-4`})]}),O&&(0,X.jsx)(`div`,{className:`mt-3 rounded-xl bg-gray-100/60 p-3 dark:bg-dark-200/60`,children:(0,X.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:ee})})]}),(0,X.jsx)(Fe,{content:z,isStreaming:t})]}),!c&&!l&&ne.length>0&&(0,X.jsx)(`div`,{className:`mt-4`,children:(0,X.jsx)(Ve,{artifacts:ne})}),!c&&!l&&e.statistics&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Ue,{statistics:e.statistics})}),!l&&!t&&(0,X.jsxs)(`div`,{className:G(`mt-3 flex items-center gap-1`,c?`justify-end border-t border-white/10 pt-2 text-white/65`:`text-gray-400 dark:text-dark-500`),children:[!c&&z&&(0,X.jsx)(Ze,{text:z,size:`sm`,className:G(`transition-colors`,j&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),(0,X.jsx)(`button`,{onClick:R,className:G(`flex h-8 w-8 items-center justify-center rounded-full transition-colors`,c?`hover:bg-white/10 hover:text-white`:`hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`),title:a(N?`chatMessage.copied`:`chatMessage.copyMessage`),children:N?(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`})}),!c&&r&&i&&(0,X.jsx)(`button`,{onClick:i,className:`flex h-8 w-8 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:a(`chatMessage.regenerateResponse`),children:(0,X.jsx)(C,{className:`h-3.5 w-3.5`})})]})]})]})}),x&&(0,He.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:()=>S(null),children:[(0,X.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),S(null)},children:(0,X.jsx)(B,{className:`h-7 w-7`})}),(0,X.jsx)(`img`,{src:x,alt:a(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},Mt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,Nt=220,Pt=e=>{let t=e.slice(0,Nt*4).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>Nt?`${t.slice(0,Nt-1).trimEnd()}…`:t},Ft=Y.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=o(),i=(0,Y.useRef)(null),a=(0,Y.useRef)(null),s=(0,Y.useRef)(new Map),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(0),f=(0,Y.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Y.useCallback)(t=>{let r=e[t],i=r?s.current.get(r.id):void 0;!r||!i||(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Y.useEffect)(()=>{if(!t)return;let e=a.current,n=s.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),o=null;i.top<r.top?o=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(o=e.scrollTop+(i.bottom-r.bottom)+8),o!==null&&e.scrollTo({top:o,behavior:Mt()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,X.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 30rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,X.jsx)(`ol`,{ref:a,className:`pointer-events-auto grid h-full min-h-0 overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden`,style:{gridTemplateRows:`repeat(${e.length}, minmax(1.5rem, 1fr))`},children:e.map((t,a)=>{let o=t.id===h,u=c===t.id?v:void 0;return(0,X.jsx)(`li`,{className:`flex min-h-6 items-center`,children:(0,X.jsx)(`button`,{ref:e=>{e?s.current.set(t.id,e):s.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":o?`location`:void 0,"aria-describedby":u,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:G(`group flex h-6 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,X.jsx)(`span`,{"aria-hidden":`true`,className:G(`block rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,o?`h-0.5 w-6 bg-ink opacity-90 xl:w-7`:`h-px w-3 bg-line-strong opacity-75 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,X.jsxs)(`div`,{id:v,role:`tooltip`,className:G(`pointer-events-none absolute start-full ms-3 w-72 -translate-y-1/2`,`rounded-2xl border border-line bg-surface-overlay/95 p-4 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(6.5rem, ${u}px, calc(100% - 6.5rem))`},children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-center justify-between gap-3`,children:[(0,X.jsxs)(`span`,{dir:`ltr`,className:`text-[10px] font-semibold uppercase tracking-[0.14em] text-ink-subtle`,children:[String(g+1).padStart(2,`0`),` /`,` `,String(e.length).padStart(2,`0`)]}),(0,X.jsx)(`span`,{className:`h-px flex-1 bg-line`,"aria-hidden":`true`})]}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`mb-1 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-subtle`,children:r(`chatMessage.you`)}),(0,X.jsx)(`p`,{dir:`auto`,className:`line-clamp-2 text-sm font-medium leading-5 text-ink`,children:Pt(_.prompt)})]}),_.response&&(0,X.jsxs)(`div`,{className:`border-t border-line pt-3`,children:[(0,X.jsx)(`p`,{className:`mb-1 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-subtle`,children:r(`chatMessage.assistant`)}),(0,X.jsx)(`p`,{dir:`auto`,className:`line-clamp-2 text-xs leading-5 text-ink-muted`,children:Pt(_.response)})]})]})]})]})}),It=({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)(jt,{message:c&&n?{...o,content:n}:o,isStreaming:c,isLastAssistantMessage:i,onRegenerate:a,className:s})}return(0,X.jsxs)(`div`,{className:G(`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)(O,{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:G(`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:G(`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:G(!c&&!l&&`opacity-75`),children:(0,X.jsx)(jt,{message:u,isStreaming:l,isLastAssistantMessage:i&&(c||l),onRegenerate:c&&!t?a:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},Lt={web_search:x,web_fetch:D,exec:N,browser:D,Read:ce,Write:ce,Edit:ce,image:T,memory_search:M,memory_get:M,working:ae,thinking:ae,default:ae},Rt={web_search:`Searching the web`,web_fetch:`Fetching page`,exec:`Running command`,browser:`Using browser`,Read:`Reading file`,Write:`Writing file`,Edit:`Editing file`,image:`Analyzing image`,memory_search:`Searching memory`,memory_get:`Reading memory`,cron:`Managing schedule`,message:`Sending message`,tts:`Generating speech`,nodes:`Checking devices`,sessions_spawn:`Spawning agent`,canvas:`Rendering canvas`,process:`Managing process`,working:`Using tools`,thinking:`Thinking`},zt=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,X.jsx)(`div`,{className:G(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Lt[e.name]||Lt.default,n=Rt[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,X.jsxs)(`div`,{className:G(`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:G(`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 Bt=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],Vt=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,Ht=e=>Math.min(120,e*.28),Ut=({messages:e,streamingMessage:t,streamingMessageId:n,isStreaming:r=!1,toolActivities:i=[],className:a,onRegenerate:s,onSelectBranch:l})=>{let{t:u}=o(),d=(0,Y.useRef)(null),f=(0,Y.useRef)(),p=(0,Y.useRef)(null),m=(0,Y.useRef)(null),h=(0,Y.useRef)(new Map),g=(0,Y.useRef)(null),_=(0,Y.useRef)(0),v=(0,Y.useRef)(!1),y=(0,Y.useRef)(!1),[b,x]=(0,Y.useState)(!1),S=(0,Y.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>e.role===`system`&&t.role!==`system`?-1:t.role===`system`&&e.role!==`system`?1:e.parentId===t.parentId?(e.branchIndex||0)-(t.branchIndex||0):e.timestamp-t.timestamp);for(let i of r){if(n.has(i.id))continue;let r=i.parentId;if(r){let a=t.findIndex(e=>e.id===r);if(a>=0)t[a].messages.push(i);else{let a=e.find(e=>e.id===r);a&&!n.has(r)?(t.push({id:r,messages:[a,i],messageIndex:t.length}),n.add(r)):t.push({id:i.id,messages:[i],messageIndex:t.length})}n.add(i.id)}else{let r=e.filter(e=>e.parentId===i.id);r.length>0?(t.push({id:i.id,messages:[i,...r],messageIndex:t.length}),n.add(i.id),r.forEach(e=>n.add(e.id))):(t.push({id:i.id,messages:[i],messageIndex:t.length}),n.add(i.id))}}return t.sort((e,t)=>{let n=e.messages[0],r=t.messages[0];return n.role===`system`&&r.role!==`system`?-1:r.role===`system`&&n.role!==`system`?1:n.timestamp-r.timestamp})},[e]),C=(0,Y.useMemo)(()=>{let e=[];for(let t=0;t<S.length;t++){let n=S[t],r=Bt(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<S.length;e++){let t=Bt(S[e]);if(t.role===`user`)break;if(t.role===`assistant`){i=t.content;break}}e.push({id:n.id,prompt:r.content,response:i})}return e},[S]),T=C.map(e=>e.id).join(``),E=(0,Y.useMemo)(()=>T?T.split(``):[],[T]),D=(0,Y.useMemo)(()=>new Set(E),[E]),[O,k]=(0,Y.useState)(null),A=(0,Y.useCallback)(()=>{let e=p.current;if(!e||E.length===0){k(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(_.current,E.length-1);if(t<=2)n=E.length-1;else{let t=e.scrollTop+Ht(e.clientHeight);for(;n<E.length-1;){let e=h.current.get(E[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=h.current.get(E[n]);if(!e||e.offsetTop<=t)break;n--}}_.current=n;let r=E[n];k(e=>e===r?e:r)},[E]),j=(0,Y.useCallback)(()=>{g.current===null&&(g.current=window.requestAnimationFrame(()=>{g.current=null,A()}))},[A]),M=(0,Y.useCallback)(()=>{let t=p.current;if(f.current&&clearTimeout(f.current),v.current=!1,f.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;y.current=!n,x(!n&&e.length>0),j()},[e.length,j]),N=(0,Y.useCallback)(()=>{f.current&&clearTimeout(f.current),f.current=setTimeout(M,180)},[M]),P=(0,Y.useCallback)((e=!1)=>{y.current&&!e||d.current?.scrollIntoView({behavior:Vt()})},[]),F=(0,Y.useCallback)(()=>{let t=p.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(v.current){y.current=!0,x(!o&&e.length>0),j(),N();return}y.current=!o,x(!o&&e.length>0),a<=2&&E.length>0?(_.current=E.length-1,k(E[E.length-1])):j()},[E,e.length,N,j]),I=(0,Y.useCallback)(e=>{let t=p.current,n=h.current.get(e);if(!t||!n)return;let r=Vt();v.current=!0,y.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-Ht(t.clientHeight)),behavior:r}),j(),r===`auto`?M():N()},[M,N,j]),L=(0,Y.useRef)(e.length);if((0,Y.useEffect)(()=>{e.length>L.current&&!y.current&&P(),L.current=e.length},[e.length,P]),(0,Y.useEffect)(()=>{r&&t&&!y.current&&requestAnimationFrame(()=>{let e=p.current;e&&(e.scrollTop=e.scrollHeight)})},[r,t]),(0,Y.useEffect)(()=>{j();let e=m.current,t=p.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(j);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,j),()=>{n?.disconnect(),window.removeEventListener(`resize`,j)}},[T,j]),(0,Y.useEffect)(()=>()=>{g.current!==null&&(window.cancelAnimationFrame(g.current),g.current=null)},[]),(0,Y.useEffect)(()=>()=>{f.current&&clearTimeout(f.current)},[]),e.length===0&&!r)return(0,X.jsx)(`div`,{className:G(`flex-1 flex items-center justify-center p-6 sm:p-10`,a),children:(0,X.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,X.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/[0.06] bg-surface/70 text-gray-500 shadow-sm dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,X.jsx)(c,{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:u(`chatMessage.startConversation`)}),(0,X.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:u(`chatMessage.startConversationDescription`)})]})});let R=-1;for(let e=S.length-1;e>=0;e--)if(S[e].messages.some(e=>e.role===`assistant`)){R=e;break}return(0,X.jsxs)(`div`,{className:G(`relative min-h-0 flex-1`,a),style:{WebkitAppRegion:`no-drag`},children:[(0,X.jsx)(`div`,{ref:p,"data-testid":`chat-scroll-viewport`,onScroll:F,className:G(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,X.jsxs)(`div`,{ref:m,className:`mx-auto w-full min-w-0 max-w-4xl px-4 sm:px-6 md:px-8`,children:[S.map((e,i)=>{let a=i===R,o=D.has(e.id),c=r&&e.messages.some(e=>e.id===n),u;if(e.messages.length===1){let o=e.messages[0],c=r&&o.id===n;u=(0,X.jsx)(jt,{message:c&&t?{...o,content:t}:o,isStreaming:c,isLastAssistantMessage:a,onRegenerate:a?s:void 0,className:i===0?`mt-5 sm:mt-7`:``})}else u=(0,X.jsx)(It,{messages:e.messages,isStreaming:c,streamingMessage:t,streamingMessageId:n||void 0,isLastAssistantMessage:a,onRegenerate:a?s:void 0,onSelectBranch:l,className:i===0?`mt-5 sm:mt-7`:``});return(0,X.jsx)(`div`,{ref:t=>{o&&(t?h.current.set(e.id,t):h.current.delete(e.id))},"data-testid":o?`conversation-turn-anchor`:void 0,"data-history-id":o?e.id:void 0,children:u},e.id)}),r&&i.length>0&&(0,X.jsx)(zt,{tools:i,className:`px-0`}),(0,X.jsx)(`div`,{ref:d,className:`h-4 sm:h-6`})]})}),(0,X.jsx)(Ft,{items:C,activeId:O,onSelect:I}),b&&(0,X.jsxs)(`button`,{onClick:()=>{v.current=!1,f.current&&(clearTimeout(f.current),f.current=void 0),y.current=!1,d.current?.scrollIntoView({behavior:Vt()}),x(!1)},className:G(`absolute bottom-4 left-1/2 -translate-x-1/2 z-10`,`flex items-center justify-center gap-1.5`,`px-3.5 py-2 rounded-full`,`bg-surface/90 dark:bg-dark-200/90`,`border border-black/[0.07] dark:border-white/[0.08]`,`shadow-[0_8px_28px_rgba(15,23,42,0.12)] backdrop-blur-xl`,`text-gray-600 dark:text-dark-600`,`hover:bg-surface-raised dark:hover:bg-dark-200`,`hover:text-gray-900 dark:hover:text-dark-800`,`transition-colors duration-150`),title:u(`chatMessage.scrollToBottom`),children:[(0,X.jsx)(w,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:u(`chatMessage.newMessages`)})]})]})};function Wt(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 Gt=Y.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Y.useMemo)(()=>Wt(e),[e]);return(0,X.jsxs)(`div`,{className:`relative w-full`,children:[(0,X.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:G(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,X.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,X.jsxs)(`div`,{className:G(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,X.jsx)(b,{className:`h-3 w-3`}),d&&(0,X.jsx)(`span`,{children:d}),!d&&u&&(0,X.jsx)(`span`,{children:`code`})]})})]})});Gt.displayName=`CodeAwareTextarea`;var Kt=a(`components:media-upload`),qt=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:s})=>{let{t:c}=o(),l=(0,Y.useRef)(null),[u,d]=(0,Y.useState)(!1),[f,p]=(0,Y.useState)(!1),[m,h]=(0,Y.useState)([]),g=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await v(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):E.error(`File type not supported: ${n.name}`)}},v=async r=>{if(n-e.length<=0){E.error(`Maximum ${n} images allowed`);return}if(r.size>10*1024*1024){E.error(`Image ${r.name} is too large (max 10MB)`);return}let i=new FileReader;i.onload=n=>{n.target?.result&&t([...e,n.target.result])},i.readAsDataURL(r)},y=async e=>{if(e.size>10*1024*1024){E.error(`File size must be less than 10MB`);return}p(!0);try{let t=await _e.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),E.success(`Document "${e.name}" uploaded`)}else E.error(t.error||`Failed to upload document`)}catch(e){Kt.error(`Document upload error:`,e),E.error(`Failed to upload document`)}finally{p(!1)}},b=e=>{e.preventDefault(),a||d(!0)},x=e=>{e.preventDefault(),d(!1)},S=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},C=n=>{t(e.filter((e,t)=>t!==n))},w=async e=>{try{let t=await _e.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),E.success(`Document removed`)):E.error(t.error||`Failed to remove document`)}catch(e){Kt.error(`Error removing document:`,e),E.error(`Failed to remove document`)}},T=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},D=e.length>0||m.length>0;return(0,X.jsxs)(`div`,{className:G(`space-y-3`,s),children:[(0,X.jsxs)(`div`,{className:G(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:b,onDragLeave:x,onDrop:S,onClick:()=>!a&&l.current?.click(),children:[(0,X.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,X.jsx)(_,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,X.jsx)(j,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),D&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,X.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),C(t)},className:`absolute top-0.5 right-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 transition-opacity`,children:(0,X.jsx)(B,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,X.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,X.jsx)(ce,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,X.jsx)(F,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,X.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:T(e.size)})]}),(0,X.jsx)(`button`,{onClick:t=>{t.stopPropagation(),w(e.id)},className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,X.jsx)(B,{className:`h-3 w-3`})})]},e.id))]})]})},Jt=a(`components:document-indicator`),Yt=({sessionId:e,className:t=``})=>{let[n,r]=(0,Y.useState)([]);if((0,Y.useEffect)(()=>{e&&(async()=>{try{let t=await _e.getDocuments(e);t.success&&t.data&&r(t.data)}catch(e){Jt.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)(d,{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`]})]})},Xt=a(`components:structured-output`),Zt=[{key:`none`,value:null},{key:`json`,value:`json`},{key:`list`,value:{type:`object`,properties:{items:{type:`array`,items:{type:`string`}}},required:[`items`]}},{key:`summary`,value:{type:`object`,properties:{title:{type:`string`},summary:{type:`string`},key_points:{type:`array`,items:{type:`string`}}},required:[`title`,`summary`,`key_points`]}},{key:`analysis`,value:{type:`object`,properties:{analysis:{type:`string`},pros:{type:`array`,items:{type:`string`}},cons:{type:`array`,items:{type:`string`}},recommendation:{type:`string`}},required:[`analysis`,`pros`,`cons`,`recommendation`]}},{key:`custom`,value:`custom`}],Qt=({format:e,onFormatChange:t,className:n})=>{let{t:r}=o(),[i,a]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)(``),l=()=>Zt.map(e=>({key:e.key,label:r(`chat.structuredOutput.${e.key}`),value:e.value,description:r(`chat.structuredOutput.${e.key}Description`)})),u=()=>{let t=l();return e===null?t[0]:e===`json`?t[1]:typeof e==`object`?t.find(t=>typeof t.value==`object`&&JSON.stringify(t.value)===JSON.stringify(e))||{key:`customSchema`,label:r(`chat.structuredOutput.custom`),value:e,description:r(`chat.structuredOutput.customSchema`)}:t[0]},d=e=>{let n=l().find(t=>t.label===e);if(n){if(n.value===`custom`){a(!0);return}a(!1),t(n.value)}};return(0,X.jsxs)(`div`,{className:G(`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)(V,{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)(Ie,{value:u().label,onChange:e=>d(e.target.value),options:l().map(e=>({value:e.label,label:e.label}))}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:u().description}),i&&(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(Re,{value:s,onChange:e=>c(e.target.value),placeholder:`{
|
|
10
|
+
"type": "object",
|
|
11
|
+
"properties": {
|
|
12
|
+
"field1": { "type": "string" },
|
|
13
|
+
"field2": { "type": "number" }
|
|
14
|
+
},
|
|
15
|
+
"required": ["field1"]
|
|
16
|
+
}`,rows:8,className:`font-mono text-sm`}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(K,{onClick:()=>{try{t(JSON.parse(s)),a(!1)}catch(e){Xt.error(`Invalid JSON schema:`,e)}},size:`sm`,disabled:!s.trim(),children:r(`chat.structuredOutput.applySchema`)}),(0,X.jsx)(K,{onClick:()=>{a(!1),c(``)},variant:`outline`,size:`sm`,children:r(`chat.structuredOutput.cancel`)})]})]}),(()=>{let e=u();return!e.value||e.value===`json`?null:(0,X.jsxs)(`div`,{className:`mt-3 p-3 bg-gray-50 dark:bg-gray-800 rounded-md`,children:[(0,X.jsxs)(`div`,{className:`flex items-center mb-2`,children:[(0,X.jsx)(P,{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)(ce,{className:`h-3 w-3 mr-1`}),r(`chat.structuredOutput.enabled`)]})]})};function $t(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toString()}function en({hfTask:e,hfSort:t,canInstallModels:n,loadingHf:r,hfModels:i,expandedHfModel:a,hfGgufFiles:s,loadingGguf:c,pullingModel:l,pullProgress:u,setHfTask:d,setHfSort:f,onToggleHfModel:m,onPullHfGguf:h,onCancelPull:g,onRefreshHfModels:_}){let{t:v}=o();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=>d(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:v(`modelManager.huggingface.taskTextGeneration`)}),(0,X.jsx)(`option`,{value:`text-to-speech`,children:v(`modelManager.huggingface.taskTextToSpeech`)}),(0,X.jsx)(`option`,{value:`text-to-image`,children:v(`modelManager.huggingface.taskTextToImage`)}),(0,X.jsx)(`option`,{value:`automatic-speech-recognition`,children:v(`modelManager.huggingface.taskSpeechRecognition`)})]}),(0,X.jsxs)(`select`,{value:t,onChange:e=>f(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:v(`modelManager.huggingface.sortDownloads`)}),(0,X.jsx)(`option`,{value:`likes`,children:v(`modelManager.huggingface.sortLikes`)}),(0,X.jsx)(`option`,{value:`lastModified`,children:v(`modelManager.huggingface.sortRecent`)})]})]})}),(0,X.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin`,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:v(`modelSelector.pullRestricted`)}),r?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,X.jsx)(U,{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)(se,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,X.jsx)(`p`,{className:`text-sm`,children:v(`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=s[e.id]||[],i=c===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(),m(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)(se,{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`,{dir:`ltr`,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)(oe,{className:`h-3 w-3`}),$t(e.downloads)]}),(0,X.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(p,{className:`h-3 w-3`}),$t(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)(re,{className:`h-4 w-4 text-gray-400`})}),(0,X.jsx)(k,{className:G(`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)(U,{className:`h-4 w-4 animate-spin text-gray-400`}),(0,X.jsx)(`span`,{className:`ml-2 text-xs text-gray-500`,children:v(`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:v(`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:v(`modelManager.huggingface.ggufFilesCount`,{count:r.length})}),r.map(e=>{let t=l===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:u?.percent===void 0?`...`:`${u.percent}%`}),(0,X.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),g()},className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,X.jsx)(B,{className:`h-4 w-4`})})]}):n?(0,X.jsxs)(`button`,{onMouseDown:t=>{t.preventDefault(),t.stopPropagation(),h(e.ollamaCommand,e.filename)},disabled:!!l,className:G(`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)(oe,{className:`h-3 w-3 inline mr-1`}),v(`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:v(`modelSelector.adminOnlyPull`)})]},e.filename)}),l?.startsWith(`hf.co/`)&&l.includes(e.id)&&u?.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:`${u.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)(re,{className:`h-3 w-3`}),v(`modelManager.huggingface.browseAllLink`)]}),(0,X.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),_()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,X.jsx)(C,{className:G(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}function tn({filteredGroups:e,selectedModel:t,showImageGen:n,getModelIcon:r,getModelLabel:i,getModelSubLabel:a,onModelSelect:s,onOpenGallery:c}){let{t:l}=o();return(0,X.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-dark-400`,children:[e.length>0?e.map(e=>(0,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(),s(e.name)},className:G(`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`,{dir:e.isPersona?`auto`:`ltr`,className:`text-sm font-medium text-gray-900 dark:text-gray-100 truncate`,children:i(e)}),a(e)&&(0,X.jsx)(`div`,{dir:`auto`,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)(z,{className:`h-8 w-8 mx-auto mb-2 text-gray-300 dark:text-gray-600`}),(0,X.jsx)(`p`,{className:`text-sm`,children:l(`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)(f,{className:`h-4 w-4 text-blue-600 dark:text-blue-400`}),l(`modelSelector.actions`)]})}),(0,X.jsx)(`div`,{onMouseDown:e=>{e.preventDefault(),c()},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)(T,{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:l(`gallery.generate`)}),(0,X.jsx)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:l(`gallery.generateDescription`)})]})]})})]})]})}function nn({libraryCategories:e,libraryCategory:t,canInstallModels:n,loadingLibrary:r,filteredLibraryModels:i,pullingModel:a,pullProgress:s,setLibraryCategory:c,isModelInstalled:l,onModelSelect:u,onPullModel:d,onCancelPull:f,onRefreshLibrary:p}){let{t:m}=o();return(0,X.jsxs)(`div`,{className:`flex min-h-0 flex-1 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(),c(e)},className:G(`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:`scroll-region min-h-0 flex-1 scrollbar-thin`,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:m(`modelSelector.pullRestricted`)}),r?(0,X.jsx)(`div`,{className:`flex items-center justify-center py-12`,children:(0,X.jsx)(U,{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)(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:m(`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=l(e.name),r=a===e.name;return(0,X.jsxs)(`div`,{className:G(`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)(I,{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`,{dir:`ltr`,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:m(`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)(I,{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)(oe,{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:s?.percent===void 0?`...`:`${s.percent}%`}),(0,X.jsx)(`button`,{onClick:f,className:`p-1.5 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,children:(0,X.jsx)(B,{className:`h-4 w-4`})})]}):t?(0,X.jsx)(`button`,{onClick:()=>u(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:m(`modelSelector.use`)}):n?(0,X.jsxs)(`button`,{onClick:()=>d(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)(oe,{className:`h-3 w-3 inline mr-1`}),m(`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:m(`modelSelector.adminOnlyPull`)})})]}),r&&s?.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:`${s.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)(re,{className:`h-3 w-3`}),m(`modelManager.huggingface.browseAllLink`)]}),(0,X.jsx)(`button`,{onMouseDown:e=>{e.preventDefault(),e.stopPropagation(),p()},className:`p-1.5 rounded-lg hover:bg-gray-100 dark:hover:bg-dark-200`,children:(0,X.jsx)(C,{className:G(`h-3.5 w-3.5 text-gray-400`,r&&`animate-spin`)})})]})]})}var rn=a(`components:model-selector`),an=({models:e,selectedModel:t,onModelChange:n,currentPersona:r,className:a,disabled:s=!1,compact:l=!1,showImageGen:u=!1,onModelsRefresh:d})=>{let{t:f}=o(),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(``),[_,v]=(0,Y.useState)(`installed`),y=(0,Y.useRef)(null),b=(0,Y.useRef)(null),C=Pe(),{user:w,systemInfo:T}=Ne(),D=w?.role===`admin`||(T?.allowUserModelPull??!0),[O,A]=(0,Y.useState)(`all`),[j,M]=(0,Y.useState)(``),[N,P]=(0,Y.useState)(`text-generation`),[F,L]=(0,Y.useState)(`downloads`),[R,ee]=(0,Y.useState)(``),[z,te]=(0,Y.useState)(null),[re,ae]=(0,Y.useState)({}),[oe,ce]=(0,Y.useState)(null),[le,V]=(0,Y.useState)(null),[ue,H]=(0,Y.useState)(null),[fe,U]=(0,Y.useState)(null),pe=[`all`,`popular`,`chat`,`code`,`vision`,`embedding`,`cloud`],me=[{type:`personas`,label:f(`modelSelector.personas`),icon:(0,X.jsx)(ne,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}),models:e.filter(e=>e.isPersona),color:`purple`},{type:`ollama`,label:f(`modelSelector.ollamaModels`),icon:(0,X.jsx)(S,{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:f(`modelSelector.pluginModels`),icon:(0,X.jsx)(se,{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(h.toLowerCase())||e.personaName&&e.personaName.toLowerCase().includes(h.toLowerCase())||e.pluginName&&e.pluginName.toLowerCase().includes(h.toLowerCase()))})).filter(e=>e.models.length>0),W=e.find(e=>e.name===t||t.startsWith(`persona:`)&&e.name===t),{data:he=[],isLoading:_e,refetch:ve}=i({queryKey:[`ollama-library-selector`,j,O],queryFn:async()=>{let e=await ge.getLibraryModels({search:j||void 0,sort:`popular`,category:O===`cloud`?`cloud`:void 0});return e.success&&e.data?e.data:[]},enabled:p&&_===`ollama`}),{data:ye=[],isLoading:xe,refetch:Se}=i({queryKey:[`hf-models-selector`,N,R,F],queryFn:async()=>{let e=await be.getModels({task:N,search:R||void 0,sort:F,limit:30});return e.success&&e.data?e.data:[]},enabled:p&&_===`huggingface`}),Ce=he.filter(e=>{let t=!h||e.name.toLowerCase().includes(h.toLowerCase())||e.description.toLowerCase().includes(h.toLowerCase()),n=O===`all`||e.category===O;return t&&n}),we=(0,Y.useCallback)(async e=>{let[t,n]=e.split(`/`);if(!(!t||!n)){ce(e);try{let r=await be.getGgufFiles(t,n);r.success&&r.data&&ae(t=>({...t,[e]:r.data}))}catch(e){rn.error(`Failed to load GGUF files:`,e)}finally{ce(null)}}},[]),Te=(0,Y.useCallback)(e=>{z===e?te(null):(te(e),re[e]||we(e))},[z,re,we]),Ee=(0,Y.useCallback)((e,t)=>{if(!D){E.error(f(`modelSelector.pullRestricted`));return}if(!le){V(e),H({status:`starting`});try{let n=ge.pullModelStream(e,e=>{H(e)},()=>{H(null),V(null),U(null),E.success(`Downloaded ${t}`),d?.()},e=>{H(null),V(null),U(null),E.error(`Failed to download: ${e}`)});U(()=>n)}catch{H(null),V(null),E.error(`Failed to start download`)}}},[D,d,le,f]);(0,Y.useEffect)(()=>{let e=setTimeout(()=>{_===`huggingface`?ee(h):_===`ollama`&&M(h)},300);return()=>clearTimeout(e)},[h,_]),(0,Y.useEffect)(()=>{if(!p)return;let e=e=>{e.key===`Escape`&&(m(!1),g(``))};return document.addEventListener(`keydown`,e),()=>document.removeEventListener(`keydown`,e)},[p]),(0,Y.useEffect)(()=>{p&&b.current&&b.current.focus()},[p]);let K=async e=>{m(!1),g(``);try{let t=await ge.listRunningModels();if(t.success&&t.data){let n=t.data;n.length>0&&(n.some(t=>t.name===e||e.startsWith(`persona:`))||await ge.unloadAllModels())}}catch(e){rn.warn(`Failed to unload models before switch:`,e)}n({target:{value:e}})},De=async e=>{if(!D){E.error(f(`modelSelector.pullRestricted`));return}if(!le){V(e),H({status:`starting`});try{let t=ge.pullModelStream(e,e=>{H(e)},()=>{H(null),V(null),U(null),E.success(`Downloaded ${e}`),d?.()},e=>{H(null),V(null),U(null),E.error(`Failed to download: ${e}`)});U(()=>t)}catch{H(null),V(null),E.error(`Failed to start download`)}}},Oe=()=>{fe&&(fe(),U(null),V(null),H(null),E.success(`Download cancelled`))},q=t=>e.some(e=>e.name===t||e.name.startsWith(t+`:`)),ke=e=>e.isPersona?(0,X.jsx)(ne,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):e.isPlugin?(0,X.jsx)(se,{className:`h-4 w-4 text-gray-500 dark:text-dark-600`}):(0,X.jsx)(S,{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:G(`relative`,a),ref:y,children:[(0,X.jsxs)(`button`,{type:`button`,onClick:()=>!s&&m(!p),disabled:s,"aria-haspopup":`dialog`,"aria-expanded":p,className:G(l?`h-9 sm:h-10 px-2.5 flex items-center justify-between text-start w-full`:`w-full flex items-center justify-between gap-2 px-3 py-2.5 text-start`,`border border-black/[0.06] bg-gray-100/70 dark:border-white/[0.06] dark:bg-dark-300/70`,`rounded-xl text-sm hover:bg-gray-100 dark:hover:bg-dark-300`,`transition-colors duration-150 focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:border-primary-500/40`,s?`opacity-50 cursor-not-allowed`:`cursor-pointer`),title:l?W?Ae(W):f(`modelSelector.selectModel`):void 0,children:[(()=>{if(!W)return l?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,X.jsx)(S,{className:`h-4 w-4`}),(0,X.jsx)(`span`,{className:`text-xs font-medium text-gray-400 dark:text-gray-500 truncate`,children:f(`modelSelector.selectModel`)})]}):f(`modelSelector.selectModel`);if(l){let e=Ae(W);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[ke(W),(0,X.jsx)(`span`,{dir:W.isPersona?`auto`:`ltr`,className:`text-xs font-medium text-gray-700 dark:text-gray-200 truncate`,children:e})]})}let e=Ae(W),t=je(W);return(0,X.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[ke(W),(0,X.jsxs)(`div`,{className:`flex flex-col min-w-0`,children:[(0,X.jsx)(`span`,{dir:W.isPersona?`auto`:`ltr`,className:`text-sm font-medium truncate`,children:e}),t&&(0,X.jsx)(`span`,{dir:`auto`,className:`text-xs text-gray-500 dark:text-gray-400 truncate`,children:t})]}),W.isPersona&&r&&(0,X.jsxs)(`div`,{className:`flex items-center gap-1 ms-auto`,children:[(0,X.jsx)(de,{className:`h-3 w-3 text-gray-500 dark:text-dark-600`}),r.embedding_model&&(0,X.jsx)(c,{className:`h-3 w-3 text-gray-400 dark:text-dark-500`})]})]})})(),(0,X.jsx)(k,{className:G(l?`h-3 w-3`:`h-4 w-4`,`text-gray-400 flex-shrink-0 transition-transform duration-150`,p&&`rotate-180`)})]}),p&&(0,He.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:()=>{m(!1),g(``)}}),(0,X.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":f(`modelSelector.selectModel`),className:G(`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 rtl:tracking-normal`,children:f(`modelSelector.selectModel`)}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{m(!1),g(``)},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:f(`common.close`),children:(0,X.jsx)(B,{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)(x,{className:`absolute start-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400`}),(0,X.jsx)(`input`,{ref:b,type:`text`,placeholder:f(_===`installed`?`modelSelector.searchInstalled`:_===`ollama`?`modelSelector.searchOllama`:`modelSelector.searchHuggingFace`),value:h,onChange:e=>g(e.target.value),className:G(`w-full rounded-xl border border-black/[0.07] bg-gray-100/70 py-2.5 ps-10 pe-4 text-sm dark:border-white/[0.07] dark:bg-dark-200/70`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,`text-gray-900 dark:text-dark-900 placeholder:text-gray-400 dark:placeholder:text-dark-500`)})]})}),(0,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:()=>{v(`installed`)},className:G(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,_===`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":_===`installed`,children:[(0,X.jsx)(ie,{className:`h-4 w-4 inline me-1.5`}),f(`modelSelector.installed`)]}),(0,X.jsxs)(`button`,{onClick:()=>{v(`ollama`)},className:G(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,_===`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":_===`ollama`,children:[(0,X.jsx)(I,{className:`h-4 w-4 inline me-1.5`}),`Ollama`]}),(0,X.jsxs)(`button`,{onClick:()=>{v(`huggingface`)},className:G(`flex-1 rounded-lg px-2 py-2 text-xs font-medium transition-colors sm:px-4`,_===`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":_===`huggingface`,children:[(0,X.jsx)(se,{className:`h-4 w-4 inline me-1.5`}),`HuggingFace`]})]})]}),_===`installed`&&(0,X.jsx)(tn,{filteredGroups:me,selectedModel:t,showImageGen:u,getModelIcon:ke,getModelLabel:Ae,getModelSubLabel:je,onModelSelect:K,onOpenGallery:()=>{m(!1),C(`/gallery`)}}),_===`ollama`&&(0,X.jsx)(nn,{libraryCategories:pe,libraryCategory:O,canInstallModels:D,loadingLibrary:_e,filteredLibraryModels:Ce,pullingModel:le,pullProgress:ue,setLibraryCategory:A,isModelInstalled:q,onModelSelect:K,onPullModel:De,onCancelPull:Oe,onRefreshLibrary:()=>{ve()}}),_===`huggingface`&&(0,X.jsx)(en,{hfTask:N,hfSort:F,canInstallModels:D,loadingHf:xe,hfModels:ye,expandedHfModel:z,hfGgufFiles:re,loadingGguf:oe,pullingModel:le,pullProgress:ue,setHfTask:P,setHfSort:L,onToggleHfModel:Te,onPullHfGguf:Ee,onCancelPull:Oe,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))})]})},on=a(`components:chat-input`),sn=({onSendMessage:e,onStopGeneration:t,disabled:n=!1})=>{let{t:r}=o(),[i,a]=(0,Y.useState)(``),[c,u]=(0,Y.useState)([]),[d,p]=(0,Y.useState)(null),[m,h]=(0,Y.useState)(!1),[_,v]=(0,Y.useState)(null),[y,b]=(0,Y.useState)(!1),{isGenerating:x,setBackgroundImage:S}=je(),{currentSession:C,models:w}=J(),T=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{(async()=>{try{let e=await Se.getPlugins();b(!!(e.success&&e.data&&e.data.length>0))}catch{b(!1)}})()},[]);let E=t=>{t.preventDefault(),!(!i.trim()||x)&&(e(i.trim(),c.length>0?c:void 0,d||void 0),a(``),u([]))},D=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),E(e))},O=()=>{t()};(0,Y.useEffect)(()=>{let e=T.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[i]),(0,Y.useEffect)(()=>{(async()=>{if(C?.personaId)try{let e=await he.getPersona(C.personaId);if(e.success&&e.data)v(e.data);else{on.warn(`Persona ${C.personaId} not found, clearing reference`),v(null);let{setCurrentSession:e}=J.getState();e({...C,personaId:void 0})}}catch(e){if(on.error(`Failed to load current persona:`,e),v(null),C){let{setCurrentSession:e}=J.getState();e({...C,personaId:void 0})}}else v(null)})()},[C?.personaId]);let k=async e=>{let t=e.target.value;if(C)try{if(t.startsWith(`persona:`)){let e=t.replace(`persona:`,``),n=await he.getPersona(e);if(!n.success||!n.data){l.error(`Failed to load persona details`);return}let i=n.data,a=await me.updateSession(C.id,{personaId:e,model:t});if(a.success&&a.data){let{sessions:e}=J.getState(),t=e.map(e=>e.id===C.id?a.data:e);J.setState({sessions:t,currentSession:a.data}),i.background&&S(i.background),l.success(r(`chat.persona.applied`))}}else{let e=await me.updateSession(C.id,{model:t,personaId:void 0});if(e.success&&e.data){let{sessions:t}=J.getState(),n=t.map(t=>t.id===C.id?e.data:t);J.setState({sessions:n,currentSession:e.data}),S(null),l.success(r(`chat.model.updated`))}}}catch(e){on.error(`Failed to update session:`,e),l.error(`Failed to update session`)}},A=c.length>0||d!==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:[m&&(0,X.jsxs)(`div`,{className:`mb-2 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/90 p-4 shadow-[0_12px_40px_rgba(15,23,42,0.08)] backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/90`,children:[(0,X.jsx)(qt,{images:c,onImagesChange:u,maxImages:5,sessionId:C?.id,disabled:n}),(0,X.jsx)(Qt,{format:d,onFormatChange:p})]}),(0,X.jsxs)(`div`,{className:`pb-3 pt-2 sm:pb-4`,children:[(0,X.jsx)(`form`,{onSubmit:E,children:(0,X.jsxs)(`div`,{className:G(`flex items-end gap-2 rounded-[1.55rem] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200 sm:p-3`,`bg-surface/[0.92] dark:bg-dark-200/[0.92] backdrop-blur-xl`,`border-black/[0.08] dark:border-white/[0.09]`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_14px_42px_rgba(15,23,42,0.08)]`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_52px_rgba(15,23,42,0.11)]`),children:[(0,X.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>h(!m),className:G(`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`,A&&`text-primary-600 dark:text-primary-400`,m&&`bg-gray-100 dark:bg-dark-300`),title:r(`chat.input.attachments`),children:A?(0,X.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,X.jsx)(s,{className:`h-4 w-4`}),(0,X.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-2 w-2 bg-primary-500 dark:bg-primary-400 rounded-full ring-2 ring-white dark:ring-dark-50`})]}):m?(0,X.jsx)(g,{className:`h-4 w-4`}):(0,X.jsx)(f,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,X.jsx)(Gt,{ref:T,value:i,onChange:e=>a(e.target.value),onKeyDown:D,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:[C&&w.length>0&&(0,X.jsx)(`div`,{className:`hidden sm:block`,children:(0,X.jsx)(an,{models:w,selectedModel:C.personaId?`persona:${C.personaId}`:C.model,onModelChange:k,currentPersona:_,className:`min-w-[150px] max-w-[230px]`,compact:!0,showImageGen:y})}),x?(0,X.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:O,className:G(`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)(L,{className:`h-4 w-4`})}):(0,X.jsx)(K,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!i.trim()||n,className:G(`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)(H,{className:`h-4 w-4`})})]})]})}),C&&w.length>0&&(0,X.jsx)(`div`,{className:`mt-3 sm:hidden`,children:(0,X.jsx)(an,{models:w,selectedModel:C.personaId?`persona:${C.personaId}`:C.model,onModelChange:k,currentPersona:_,className:`w-full`,compact:!0,showImageGen:y})}),(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)(Yt,{sessionId:C?.id}),(0,X.jsxs)(`div`,{className:`text-center leading-relaxed`,children:[(0,X.jsx)(`span`,{children:r(`chat.footer.disclaimer`)}),A&&(0,X.jsxs)(`span`,{className:`ms-2 text-primary-600 dark:text-primary-400`,children:[`•`,` `,c.length>0&&r(`chat.footer.images`,{count:c.length}),c.length>0&&d&&` • `,d&&r(`chat.footer.structuredOutput`)]})]})]})]})]})})},cn=({persona:e,onClear:t,className:n})=>{let[r,i]=(0,Y.useState)(!1),a=(0,Y.useRef)(null),[o,s]=(0,Y.useState)({top:0,left:0});(0,Y.useEffect)(()=>{if(r&&a.current){let e=a.current.getBoundingClientRect(),t=document.documentElement.dir===`rtl`?e.right-288:e.left;s({top:e.bottom+8,left:Math.min(window.innerWidth-288-8,Math.max(8,t))})}},[r]);let l=!!(e.memory_settings?.enabled||e.mutation_settings?.enabled),u=()=>ye(e,64),d=t=>{Ce(t.currentTarget,e.name,64)};return(0,X.jsxs)(`div`,{className:G(`relative`,n),children:[(0,X.jsxs)(`button`,{ref:a,onClick:()=>i(!r),className:G(`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)(c,{className:`h-3 w-3 text-purple-500 dark:text-purple-400`}),(0,X.jsx)(k,{className:G(`h-3.5 w-3.5 transition-transform duration-200`,r&&`rotate-180`)})]}),r&&(0,He.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:G(`rounded-xl overflow-hidden shadow-xl`,`bg-white dark:bg-dark-100`,`border border-gray-200 dark:border-dark-300`),children:[(0,X.jsxs)(`div`,{className:`relative h-16`,children:[e.background?(0,X.jsx)(`div`,{className:`absolute inset-0 bg-cover bg-center`,style:{backgroundImage:`url(${e.background})`}}):(0,X.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-br from-primary-400 via-primary-500 to-purple-600 dark:from-primary-600 dark:via-primary-700 dark:to-purple-800`}),(0,X.jsx)(`div`,{className:`absolute inset-0 bg-black/10`}),t&&(0,X.jsx)(`button`,{onClick:e=>{e.stopPropagation(),t(),i(!1)},className:`absolute top-2 end-2 p-1 rounded-full bg-white/20 hover:bg-white/30 backdrop-blur-sm transition-colors`,title:`Remove persona`,children:(0,X.jsx)(B,{className:`h-3.5 w-3.5 text-white`})}),l&&(0,X.jsxs)(`div`,{className:`absolute top-2 start-2 flex items-center gap-1 px-2 py-0.5 rounded-full bg-white/20 backdrop-blur-sm text-white text-[10px] font-medium`,children:[(0,X.jsx)(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)(v,{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)(se,{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)]})},ln=({images:e,onImagesChange:t,maxImages:n=5,className:r})=>{let{t:i}=o(),a=(0,Y.useRef)(null),[s,c]=(0,Y.useState)(!1),l=r=>{if(!r)return;let i=[],a=n-e.length;for(let n=0;n<Math.min(r.length,a);n++){let o=r[n];if(!o.type.startsWith(`image/`)){E.error(`File ${o.name} is not an image`);continue}if(o.size>10*1024*1024){E.error(`Image ${o.name} is too large (max 10MB)`);continue}let s=new FileReader;s.onload=n=>{n.target?.result&&(i.push(n.target.result),i.length===Math.min(r.length,a)&&t([...e,...i]))},s.readAsDataURL(o)}r.length>a&&E.error(`Only ${a} more images can be added`)},u=e=>{e.preventDefault(),c(!0)},d=e=>{e.preventDefault(),c(!1)},f=e=>{e.preventDefault(),c(!1),l(e.dataTransfer.files)},p=n=>{t(e.filter((e,t)=>t!==n))},m=e.length<n;return(0,X.jsxs)(`div`,{className:G(`space-y-3`,r),children:[m&&(0,X.jsxs)(`div`,{className:G(`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`,s&&`border-primary-500 bg-primary-50 dark:bg-primary-900/20`),onDragOver:u,onDragLeave:d,onDrop:f,children:[(0,X.jsx)(`input`,{ref:a,type:`file`,multiple:!0,accept:`image/*`,onChange:e=>l(e.target.files),className:`hidden`}),(0,X.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[(0,X.jsx)(j,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,X.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300 mb-2`,children:[i(`chat.mediaUpload.dropImagesHere`),` `,(0,X.jsx)(`button`,{onClick:()=>a.current?.click(),className:`text-primary-600 dark:text-primary-400 hover:underline font-medium`,children:i(`chat.mediaUpload.browse`)})]}),(0,X.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:i(`chat.mediaUpload.supportedFormats`)})]})]}),e.length>0&&(0,X.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 gap-3`,children:e.map((e,t)=>(0,X.jsxs)(`div`,{className:`relative group aspect-square rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,X.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,X.jsx)(`div`,{className:`absolute inset-0 bg-black bg-opacity-0 group-hover:bg-opacity-50 transition-all duration-200 flex items-center justify-center`,children:(0,X.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>p(t),className:`opacity-0 group-hover:opacity-100 transition-opacity bg-white dark:bg-gray-800 text-gray-900 dark:text-gray-100 hover:bg-red-100 dark:hover:bg-red-900/20 hover:text-red-600 dark:hover:text-red-400 p-1 rounded-full`,children:(0,X.jsx)(B,{className:`h-4 w-4`})})})]},t))}),m&&e.length>0&&(0,X.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>a.current?.click(),className:`w-full sm:w-auto`,children:[(0,X.jsx)(T,{className:`h-4 w-4 mr-2`}),`Add More Images (`,e.length,`/`,n,`)`]})]})},$=a(`use-chat`),un=new Set([`New Chat`,`New Demo Session`]),dn=e=>!e||un.has(e),fn=e=>{let[t,n]=(0,Y.useState)(``),[r,i]=(0,Y.useState)(null),[a,o]=(0,Y.useState)(!1),[s,c]=(0,Y.useState)([]),{addMessage:l,updateMessage:u,updateMessageWithStatistics:d,applySessionTitle:f,setGeneratingTitleForSession:p}=J(),{setIsGenerating:m,preferences:h}=je(),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)(``),T=(0,Y.useCallback)(()=>{C.current!==null&&typeof window<`u`&&window.cancelAnimationFrame(C.current),C.current=null},[]),D=(0,Y.useCallback)((e,t=!1)=>{if(w.current=e,t||typeof window>`u`){T(),n(e);return}C.current===null&&(C.current=window.requestAnimationFrame(()=>{C.current=null,n(w.current)}))},[T]),O=(0,Y.useCallback)(()=>{T(),w.current=``,n(``)},[T]),k=(0,Y.useCallback)(()=>{_.current=null,v.current=!1,y.current=null},[]),A=(0,Y.useCallback)(async e=>{let t=je.getState().preferences.titleSettings,n=_.current,r=v.current&&y.current===e;if($.debug(`Auto-title check:`,{firstMessage:n,autoTitle:t?.autoTitle,taskModel:t?.taskModel,shouldGenerateTitle:r}),!n||!r||!t?.autoTitle||!t?.taskModel){k();return}k(),$.debug(`Triggering auto-title generation...`),p(e);try{let r=await me.generateTitle(e,t.taskModel,n);if($.debug(`Title generation response:`,r),!r.success||!r.data?.title)throw Error(r.error||`Title generation returned no title`);f(e,r.data.title,r.data.updatedAt),r.data.source===`fallback`?E.error(`Could not generate a title; using the message preview`):E.success(`Chat title generated`)}catch(e){$.error(`Failed to generate title:`,e),E.error(`Failed to generate chat title`)}finally{p(null)}},[f,k,p]);return(0,Y.useEffect)(()=>()=>{q.offMessage(`user_message`),q.offMessage(`assistant_chunk`),q.offMessage(`assistant_complete`),q.offMessage(`tool_status`),q.offMessage(`error`)},[e]),(0,Y.useEffect)(()=>{if(!e){q.offMessage(`user_message`),q.offMessage(`assistant_chunk`),q.offMessage(`assistant_complete`),q.offMessage(`tool_status`),q.offMessage(`error`);return}return q.onMessage(`user_message`,()=>{}),q.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))}),q.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()}])}),q.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}),q.onMessage(`error`,e=>{let t=e;if(o(!1),O(),m(!1),g.current=null,t.code===`SESSION_NOT_FOUND`){$.warn(`Session not found, redirecting to create new session...`),E.error(`Session not found. Creating a new session...`),window.location.href=`/`;return}E.error(t.error),k()}),o(!1),O(),g.current=null,()=>{S.current&&clearTimeout(S.current),T()}},[e,u,d,m,D,O,T,A,k]),{sendMessage:(0,Y.useCallback)(async(t,n,r)=>{if(!(!e||!t.trim()&&(!n||n.length===0)))try{m(!0),o(!0),O(),S.current&&clearTimeout(S.current),x.current=Date.now();let a=J.getState().currentSession,s=a?.isPrivate===!0,c=a?.messages?.some(e=>e.role===`user`);!s&&!c&&dn(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=Ee();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}q.isConnected||await q.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;q.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,E.error(`Failed to send message`)}},[e,l,u,m,O,A,h.generationOptions]),stopGeneration:(0,Y.useCallback)(()=>{o(!1),O(),i(null),m(!1),g.current=null},[m,O]),regenerateLastMessage:(0,Y.useCallback)(async()=>{let t=J.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){E.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=Ee();g.current=t,i(t),l(e,{role:`assistant`,content:``,id:t,parentId:c.parentId||c.id,branchIndex:c.siblingCount||1,isActive:!0}),q.isConnected||await q.connect(),q.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,E.error(`Failed to regenerate message`)}},[e,m,O,l,h.generationOptions]),selectBranch:(0,Y.useCallback)(async t=>{let n=J.getState().currentSession;if(!n||!e)return;let r=n.messages.find(e=>e.id===t);if(!r){E.error(`Message not found`);return}if(r.isActive!==!1)return;let i=r.parentId||r.id,a=r.branchIndex||0;try{let r=await me.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()};J.setState(t=>({sessions:t.sessions.map(t=>t.id===e?o:t),currentSession:o})),E.success(`Switched to variant ${a+1}`)}else E.error(r.error||`Failed to select branch`)}catch(e){$.error(`Failed to select branch:`,e),E.error(`Failed to select branch`)}},[e]),isStreaming:a,streamingMessage:t,streamingMessageId:r,toolActivities:s}},pn=a(`pages:chat-page`),mn=(e,t,n=!1)=>{let r=new Date().getHours(),i=e?`${n?`،`:`,`} \u2068${e}\u2069`:``;return r>=5&&r<12?{id:`time`,title:`${t?t(`chat.greeting.morning`):`Good morning`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=12&&r<17?{id:`time`,title:`${t?t(`chat.greeting.afternoon`):`Good afternoon`}${i}`,subtitle:t?t(`chat.welcome.helpToday`):`What can I help with today?`}:r>=17&&r<21?{id:`time`,title:`${t?t(`chat.greeting.evening`):`Good evening`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}:{id:`time`,title:`${t?t(`chat.greeting.night`):`Good night`}${i}`,subtitle:t?t(`chat.welcome.helpTonight`):`What can I help with tonight?`}},hn=(e,t,n,r=!1)=>{let i=Me(e);return i===`time`?mn(t,n,r):{id:i,title:n?n(`chat.welcome.variety.${i}.title`):`What should we make?`,subtitle:n?n(`chat.welcome.variety.${i}.subtitle`):`Start with a thought, a sketch, or a stubborn problem.`}},gn=()=>{let{t:e,i18n:t}=o(),{sessionId:n}=ke(),r=Pe(),i=De(),{currentSession:a,sessions:c,models:l,selectedModel:u,setSelectedModel:d,createSession:p,setCurrentSession:m,loadSessions:h,getCurrentPersona:_}=J(),{user:v}=Ne(),{sendMessage:b,stopGeneration:x,regenerateLastMessage:S,selectBranch:C,isStreaming:w,streamingMessage:T,streamingMessageId:E,toolActivities:D}=fn(a?.id||``),O=_(),[k,A]=(0,Y.useState)(Oe),j=(0,Y.useMemo)(()=>hn(k,v?.username,e,Ae(t.language)),[t.language,e,v?.username,k]),[M,N]=(0,Y.useState)(``),[P,F]=(0,Y.useState)([]),[I,L]=(0,Y.useState)(!1),R=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=()=>{A(Oe())};return window.addEventListener(Le,e),()=>window.removeEventListener(Le,e)},[]);let[ee,z]=(0,Y.useState)(!1);(0,Y.useEffect)(()=>{c.length===0&&h()},[h,c.length]),(0,Y.useEffect)(()=>{(async()=>{try{let e=await Se.getPlugins();z(!!(e.success&&e.data&&e.data.length>0))}catch{z(!1)}})()},[]),(0,Y.useEffect)(()=>{(()=>{if(sessionStorage.getItem(`forceWelcomeScreen`)){sessionStorage.removeItem(`forceWelcomeScreen`);return}if(!a?.isPrivate&&c.length!==0)if(n){let e=c.find(e=>e.id===n);e&&e.id!==a?.id?m(e):e||(pn.warn(`Session ${n} not found for current user, redirecting...`),c.length>0?r(`/c/${c[0].id}`,{replace:!0}):r(`/`,{replace:!0}))}else!n&&c.length>0&&i.pathname===`/`&&r(`/c/${c[0].id}`,{replace:!0})})()},[n,c,m,r,a?.id,a?.isPrivate,i.pathname]),(0,Y.useEffect)(()=>{if(a?.id){let e=sessionStorage.getItem(`pendingMessage`);if(e){sessionStorage.removeItem(`pendingMessage`);try{let t=JSON.parse(e);setTimeout(()=>{b(t.content,t.images)},100)}catch(e){pn.error(`Failed to parse pending message:`,e)}}}},[a?.id,b]),(0,Y.useEffect)(()=>{let e=R.current;e&&(e.style.height=`auto`,e.style.height=Math.min(e.scrollHeight,200)+`px`)},[M]);let te=async e=>{if(e.preventDefault(),!M.trim()||!u)return;let t={content:M.trim(),images:P.length>0?P:void 0};sessionStorage.setItem(`pendingMessage`,JSON.stringify(t)),N(``),F([]);let n=await p(u);n&&r(`/c/${n.id}`,{replace:!0})},B=e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),te(e))},ne=async e=>{let t=e.target.value;d(t)},re=(e,t,n)=>{a&&b(e,t,n)};if(!a){let t=P.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(!u&&l.length===0)return;let t=Date.now();m({id:`private-${t}`,title:e(`chat.session.private`),model:u||l[0]?.name||``,messages:[],createdAt:t,updatedAt:t,isPrivate:!0})},disabled:!u&&l.length===0,className:`absolute end-4 top-4 z-10 flex items-center gap-2 rounded-full border border-black/[0.07] bg-surface/65 px-3 py-2 text-xs font-medium text-gray-500 backdrop-blur-md transition-colors duration-150 hover:bg-surface-raised hover:text-gray-950 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/[0.08] dark:bg-dark-200/65 dark:text-dark-600 dark:hover:bg-dark-200 dark:hover:text-dark-950 sm:end-6 sm:top-6`,title:e(`chat.session.privateTooltip`),children:[(0,X.jsx)(y,{className:`h-3.5 w-3.5`}),(0,X.jsx)(`span`,{children:e(`chat.session.private`)})]}),(0,X.jsxs)(`div`,{className:`relative z-[1] mx-auto flex min-h-full w-full max-w-3xl flex-col items-center justify-center`,children:[(0,X.jsxs)(`div`,{className:`mb-10 flex flex-col items-center text-center animate-fade-in sm:mb-12`,"aria-live":`polite`,children:[(0,X.jsx)(`h1`,{className:`mb-4 max-w-3xl text-balance text-[clamp(2.65rem,7vw,5.25rem)] font-light leading-[0.98] tracking-[-0.055em] text-gray-950 dark:text-dark-950 rtl:leading-[1.12] rtl:tracking-normal`,children:j.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:j.subtitle})]},j.id),l.length>0?(0,X.jsxs)(`div`,{className:`w-full`,children:[I&&(0,X.jsx)(`div`,{className:`mb-3 animate-slide-up rounded-2xl border border-black/[0.07] bg-surface/80 p-4 shadow-sm backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/80`,children:(0,X.jsx)(ln,{images:P,onImagesChange:F,maxImages:5})}),(0,X.jsx)(`form`,{onSubmit:te,children:(0,X.jsxs)(`div`,{className:G(`flex items-end gap-2 rounded-[1.6rem] border p-2.5 transition-[border-color,box-shadow,background-color] duration-200 sm:p-3`,`border-black/[0.08] bg-surface/90 dark:border-white/[0.09] dark:bg-dark-200/90`,`shadow-[0_1px_2px_rgba(0,0,0,0.03),0_18px_50px_rgba(15,23,42,0.08)] backdrop-blur-xl`,`focus-within:border-primary-500/35 focus-within:shadow-[0_1px_2px_rgba(0,0,0,0.03),0_22px_65px_rgba(15,23,42,0.12)]`),children:[(0,X.jsx)(K,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>L(!I),className:G(`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`,I&&`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)(s,{className:`h-4 w-4`}),(0,X.jsx)(`div`,{className:`absolute -top-0.5 -end-0.5 h-1.5 w-1.5 bg-primary-500 rounded-full`})]}):I?(0,X.jsx)(g,{className:`h-4 w-4`}):(0,X.jsx)(f,{className:`h-4 w-4`})}),(0,X.jsx)(`div`,{className:`flex-1 min-w-0`,children:(0,X.jsx)(Gt,{ref:R,value:M,onChange:e=>N(e.target.value),onKeyDown:B,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)(an,{models:l,selectedModel:u,onModelChange:ne,className:`min-w-[140px] max-w-[210px]`,compact:!0,showImageGen:ee})}),(0,X.jsx)(K,{type:`submit`,variant:`ghost`,size:`sm`,disabled:!M.trim()||!u,className:G(`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`,M.trim()&&u&&`shadow-sm`),title:e(`chat.input.sendMessage`),children:(0,X.jsx)(H,{className:`h-4 w-4`})})]})}),(0,X.jsx)(`div`,{className:`sm:hidden mt-4`,children:(0,X.jsx)(an,{models:l,selectedModel:u,onModelChange:ne,className:`w-full`,compact:!0,showImageGen:ee})}),(0,X.jsx)(`p`,{className:`mt-4 text-center text-[10px] leading-relaxed text-gray-400 dark:text-dark-500`,children:e(`chat.footer.disclaimer`)})]}):(0,X.jsx)(`div`,{className:`w-full max-w-lg`,children:(0,X.jsxs)(`div`,{className:`rounded-2xl border border-black/[0.07] bg-surface/70 p-6 backdrop-blur-xl dark:border-white/[0.08] dark:bg-dark-200/70`,children:[(0,X.jsx)(`p`,{className:`mb-4 text-sm leading-relaxed text-gray-600 dark:text-dark-700`,children:e(`chat.model.noModelsDescription`)}),(0,X.jsx)(`code`,{className:`block rounded-xl bg-gray-100 p-3 font-mono text-xs text-gray-800 dark:bg-dark-300 dark:text-dark-700`,children:e(`chat.model.pullCommand`)})]})})]})]})}return(0,X.jsxs)(`div`,{className:`relative flex h-full flex-col`,style:O?.background?{backgroundImage:`url(${O.background})`,backgroundSize:`cover`,backgroundPosition:`center`,backgroundRepeat:`no-repeat`}:void 0,children:[O?.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:[a?.isPrivate&&(0,X.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,X.jsxs)(`div`,{className:`flex items-center justify-center gap-2 text-gray-500 dark:text-dark-600`,children:[(0,X.jsx)(y,{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`)]})]})}),O&&!a?.isPrivate&&(0,X.jsx)(`div`,{className:`flex-shrink-0 border-b border-black/[0.05] bg-surface/55 px-4 py-2 backdrop-blur-xl dark:border-white/[0.06] dark:bg-dark-100/55`,children:(0,X.jsx)(cn,{persona:O,onClear:()=>{if(a){let{sessions:e}=J.getState(),t={...a,model:O.model,personaId:void 0},n=e.map(e=>e.id===a.id?t:e);J.setState({sessions:n,currentSession:t})}}})}),(0,X.jsx)(Ut,{messages:a.messages,streamingMessage:T,streamingMessageId:E,isStreaming:w,toolActivities:D,onRegenerate:S,onSelectBranch:C,className:`flex-1`}),(0,X.jsx)(sn,{onSendMessage:re,onStopGeneration:x,disabled:!a})]})]})};export{gn as ChatPage,gn as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{d as t,f as n}from"./markdown-core-fkbHPd-g.js";import{t as r}from"./logger-BmpKNkls.js";import{t as i}from"./useTranslation-CP6Cg-EI.js";import{Bt as a,Ot as o,V as s,Y as c,at as l,g as u,it as d,s as f,t as p,ut as m,vt as h,wt as g}from"./ui-vendor-njo77ljx.js";import{v as _}from"./api-BNnUZaFX.js";import{T as v,n as y,t as b}from"../assets/index-Cp8PdlFo.js";var x=e(n(),1),S=t(),C=r(`components:first-time-setup`),w=({onComplete:e})=>{let{t}=i(),[n,r]=(0,x.useState)(`welcome`),[w,T]=(0,x.useState)(``),[E,D]=(0,x.useState)(``),[O,k]=(0,x.useState)(``),[A,j]=(0,x.useState)(!1),[M,N]=(0,x.useState)(!1),[P,F]=(0,x.useState)(!1),[I,L]=(0,x.useState)(null),[R,z]=(0,x.useState)(!1),[B,V]=(0,x.useState)(!1),[H,U]=(0,x.useState)(``),{login:W,systemInfo:G}=v(),K=G?.turnstile?.siteKey,q=!!(G?.turnstile?.enabled&&K),J=(0,x.useCallback)(e=>{U(e)},[]),Y=(0,x.useMemo)(()=>P||q&&!H,[P,q,H]);(0,x.useEffect)(()=>{n===`encryption-key`&&!I&&_.getEncryptionKey().then(e=>{e.success&&e.data&&L(e.data.encryptionKey)})},[n,I]);let X=async e=>{if(e.preventDefault(),!w.trim()||!E.trim()||!O.trim()){a.error(t(`setup.admin.fillAllFields`));return}if(E!==O){a.error(t(`auth.signup.passwordMismatch`));return}if(E.length<6){a.error(t(`auth.signup.passwordTooShort`));return}if(q&&!H){a.error(t(`auth.signup.tryAgain`));return}F(!0);try{let e=await _.signup({username:w,password:E,email:``,turnstileToken:H});e.success&&e.data?(W(e.data.user,e.data.token,e.data.systemInfo),a.success(t(`setup.admin.success`)),r(`encryption-key`)):a.error(e.message||t(`setup.admin.failed`))}catch(e){C.error(`Admin creation error:`,e),a.error(t(`setup.admin.failed`))}finally{U(``),F(!1)}},Z=async()=>{if(I)try{await navigator.clipboard.writeText(I),z(!0),a.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>z(!1),3e3)}catch{a.error(t(`setup.encryptionKey.copyFailed`))}},Q=()=>{if(!B){a.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})})}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.welcome.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,S.jsxs)(`div`,{className:`mb-7 divide-y divide-gray-200/70 border-y border-gray-200/70 dark:divide-white/[0.08] dark:border-white/[0.08]`,children:[(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(u,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(p,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,S.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,S.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,S.jsx)(c,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,S.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,S.jsx)(`button`,{onClick:()=>r(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,S.jsx)(g,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-lg rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,S.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-50 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,S.jsx)(s,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.encryptionKey.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,S.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-50/70 p-4 dark:border-amber-800/60 dark:bg-amber-900/15`,children:(0,S.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,S.jsx)(o,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,S.jsxs)(`div`,{className:`text-sm text-amber-800 dark:text-amber-200`,children:[(0,S.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,S.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,S.jsxs)(`div`,{className:`mb-6`,children:[(0,S.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:I||t(`setup.encryptionKey.loading`)}),(0,S.jsx)(`button`,{type:`button`,onClick:Z,disabled:!I,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:R?(0,S.jsx)(h,{className:`h-5 w-5 text-green-500`}):(0,S.jsx)(m,{className:`h-5 w-5`})})]}),(0,S.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,S.jsx)(`div`,{className:`mb-6`,children:(0,S.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,S.jsx)(`input`,{type:`checkbox`,checked:B,onChange:e=>V(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,S.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,S.jsx)(`button`,{onClick:Q,disabled:!B,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,S.jsx)(g,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,S.jsxs)(`div`,{className:`min-h-screen bg-gray-50 px-4 py-16 dark:bg-dark-50 sm:px-6 lg:flex lg:flex-col lg:justify-center lg:py-20`,children:[(0,S.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,S.jsx)(`div`,{className:`flex flex-col items-center`,children:(0,S.jsx)(y,{className:`text-gray-900 dark:text-gray-100`})}),(0,S.jsx)(`h2`,{className:`mt-8 text-center text-3xl font-light tracking-[-0.035em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.title`)})]}),(0,S.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,S.jsxs)(`div`,{className:`mx-auto w-full max-w-md rounded-2xl border border-gray-200/80 bg-white/80 p-6 shadow-sm backdrop-blur-xl dark:border-white/10 dark:bg-white/[0.04] sm:p-8`,children:[(0,S.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,S.jsx)(`h1`,{className:`mb-2 text-2xl font-normal tracking-[-0.03em] text-gray-950 dark:text-dark-950`,children:t(`setup.admin.subtitle`)}),(0,S.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,S.jsxs)(`form`,{onSubmit:X,className:`space-y-4`,children:[(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`username`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.username`)}),(0,S.jsx)(`input`,{id:`username`,type:`text`,value:w,onChange:e=>T(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:P})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`password`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.login.password`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`password`,type:A?`text`:`password`,value:E,onChange:e=>D(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>j(!A),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:A?(0,S.jsx)(d,{size:20}):(0,S.jsx)(l,{size:20})})]})]}),(0,S.jsxs)(`div`,{children:[(0,S.jsx)(`label`,{htmlFor:`confirmPassword`,className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`auth.signup.confirmPassword`)}),(0,S.jsxs)(`div`,{className:`relative`,children:[(0,S.jsx)(`input`,{id:`confirmPassword`,type:M?`text`:`password`,value:O,onChange:e=>k(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:P}),(0,S.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:P,children:M?(0,S.jsx)(d,{size:20}):(0,S.jsx)(l,{size:20})})]})]}),q&&K&&(0,S.jsx)(b,{siteKey:K,disabled:P,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:J}),(0,S.jsxs)(`div`,{className:`flex gap-3`,children:[(0,S.jsx)(`button`,{type:`button`,onClick:()=>r(`welcome`),disabled:P,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,S.jsx)(`button`,{type:`submit`,disabled:Y,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:P?(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,S.jsxs)(`div`,{className:`flex items-center`,children:[(0,S.jsx)(f,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,S.jsx)(`div`,{className:`mt-6 text-center`,children:(0,S.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{w as FirstTimeSetup};
|
|
@@ -0,0 +1 @@
|
|
|
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{n as i,t as a}from"./useBaseQuery-EKJwyGqK.js";import{t as o}from"./logger-BmpKNkls.js";import{t as s}from"./useTranslation-CP6Cg-EI.js";import{At as c,Bt as l,D as u,I as d,Nt as f,U as p,W as m,lt as h,n as g,pt as _,st as v,u as y}from"./ui-vendor-njo77ljx.js";import{p as b}from"./api-BNnUZaFX.js";import{t as x}from"./utils-D0l9J3P-.js";import{t as S}from"./Button-BZBnLKRn.js";import{K as C,U as w,a as T,i as E,q as D}from"../assets/index-Cp8PdlFo.js";var O=class extends i{constructor(e,t){super(e,t)}bindMethods(){super.bindMethods(),this.fetchNextPage=this.fetchNextPage.bind(this),this.fetchPreviousPage=this.fetchPreviousPage.bind(this)}setOptions(e){e._type=`infinite`,super.setOptions(e)}getOptimisticResult(e){return e._type=`infinite`,super.getOptimisticResult(e)}fetchNextPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`forward`}}})}fetchPreviousPage(e){return this.fetch({...e,meta:{fetchMore:{direction:`backward`}}})}createResult(e,t){let{state:n}=e,r=super.createResult(e,t),{isFetching:i,isRefetching:a,isError:o,isRefetchError:s}=r,c=n.fetchMeta?.fetchMore?.direction,l=o&&c===`forward`,u=i&&c===`forward`,d=o&&c===`backward`,f=i&&c===`backward`;return{...r,fetchNextPage:this.fetchNextPage,fetchPreviousPage:this.fetchPreviousPage,hasNextPage:C(t,n.data),hasPreviousPage:D(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function k(e,t){return a(e,O,t)}var A=e(n(),1),j=r(),M=t(),N=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:i}=s();return(0,A.useEffect)(()=>{let e=e=>{e.key===`Escape`&&t()};return document.addEventListener(`keydown`,e),document.body.style.overflow=`hidden`,()=>{document.removeEventListener(`keydown`,e),document.body.style.overflow=``}},[t]),(0,j.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,M.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,M.jsxs)(`div`,{className:`relative flex flex-col lg:flex-row max-w-7xl max-h-[95vh] w-full mx-4 gap-4`,onClick:e=>e.stopPropagation(),children:[(0,M.jsx)(`button`,{onClick:t,className:x(`absolute -top-12 right-0 lg:top-0 lg:-right-12 z-10`,`p-2 rounded-full`,`bg-white/10 hover:bg-white/20`,`transition-colors`),children:(0,M.jsx)(g,{className:`h-6 w-6 text-white`})}),(0,M.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,M.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,M.jsxs)(`div`,{className:x(`w-full lg:w-80 flex-shrink-0`,`bg-white dark:bg-dark-100`,`rounded-xl p-4 lg:p-5`,`overflow-y-auto max-h-[25vh] lg:max-h-[90vh]`),children:[(0,M.jsxs)(`div`,{className:`mb-4`,children:[(0,M.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:i(`gallery.prompt`)}),(0,M.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,M.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(h,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.model`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(d,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.size`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(`span`,{className:`w-4 h-4 flex items-center justify-center text-gray-400 dark:text-gray-500 text-xs font-bold`,children:`Q`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.quality`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,M.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,M.jsx)(_,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,M.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[i(`gallery.created`),`:`]}),(0,M.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:(e=>new Date(e).toLocaleString(void 0,{year:`numeric`,month:`long`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}))(e.createdAt)})]})]}),(0,M.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,M.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.png`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:x(`flex-1 flex items-center justify-center gap-2 py-2.5 rounded-lg`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white font-medium text-sm`,`transition-colors`),children:[(0,M.jsx)(v,{className:`h-4 w-4`}),i(`gallery.download`)]}),n&&(0,M.jsx)(`button`,{onClick:()=>n(e.id),className:x(`p-2.5 rounded-lg`,`bg-gray-100 dark:bg-dark-200`,`hover:bg-red-100 dark:hover:bg-red-900/30`,`text-gray-600 dark:text-gray-300`,`hover:text-red-600 dark:hover:text-red-400`,`transition-colors`),title:`Delete image`,children:(0,M.jsx)(y,{className:`h-4 w-4`})})]})]})]})]}),document.body)},P=o(`components:image-gallery`),F=({onImageCountChange:e})=>{let{t}=s(),n=w(),[r,i]=(0,A.useState)(null),[a,o]=(0,A.useState)(null),{data:c,fetchNextPage:u,hasNextPage:d,isFetchingNextPage:p,isLoading:h}=k({queryKey:[`image-gallery`],queryFn:async({pageParam:e})=>{let n=await b.getGallery({limit:20,offset:e});if(!n.success||!n.data)throw Error(t(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.images.length,0);return n<e.total?n:void 0}}),g=(0,A.useMemo)(()=>c?.pages.flatMap(e=>e.images)??[],[c]),_=c?.pages[0]?.total??0,C=p;(0,A.useEffect)(()=>{e?.(_)},[_,e]);let T=()=>{u()},E=async(e,s)=>{if(s.stopPropagation(),!a){o(e);try{(await b.deleteGalleryImage(e)).success?(await n.invalidateQueries({queryKey:[`image-gallery`]}),l.success(t(`imageGallery.deleteSuccess`)),r?.id===e&&i(null)):l.error(t(`imageGallery.deleteFailed`))}catch(e){P.error(`Failed to delete image:`,e),l.error(t(`imageGallery.deleteFailed`))}finally{o(null)}}},D=(e,t)=>{t.stopPropagation();let n=document.createElement(`a`);n.href=e.imageData,n.download=`generated-${e.id}.png`,document.body.appendChild(n),n.click(),document.body.removeChild(n)},O=e=>new Date(e).toLocaleDateString(void 0,{year:`numeric`,month:`short`,day:`numeric`});return h?(0,M.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,M.jsx)(f,{className:`h-8 w-8 animate-spin text-gray-400 dark:text-gray-500`})}):g.length===0?(0,M.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-20 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,M.jsx)(m,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,M.jsx)(`h3`,{className:`text-lg font-medium text-gray-900 dark:text-gray-100 mb-2`,children:t(`imageGallery.noImages`)}),(0,M.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400 max-w-sm`,children:t(`imageGallery.noImagesHint`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)(`div`,{className:x(`columns-1 sm:columns-2 lg:columns-3 xl:columns-4`,`gap-4 space-y-4`),children:g.map(e=>(0,M.jsxs)(`div`,{className:x(`group relative break-inside-avoid cursor-pointer overflow-hidden rounded-2xl`,`bg-gray-100 dark:bg-dark-200`,`border border-gray-200/80 dark:border-white/10`,`transition-[border-color,transform] duration-200`,`hover:border-gray-300 dark:hover:border-white/20`),children:[(0,M.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`w-full h-auto object-cover`,loading:`lazy`}),(0,M.jsx)(`button`,{type:`button`,className:`absolute inset-0 z-[1] rounded-2xl focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-primary-500`,onClick:()=>i(e),"aria-label":e.prompt}),(0,M.jsxs)(`div`,{className:x(`pointer-events-none absolute inset-0 z-[2] bg-gradient-to-t from-black/80 via-black/20 to-transparent`,`opacity-100 transition-opacity duration-200 sm:opacity-0 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,`flex flex-col justify-end p-3`),children:[(0,M.jsx)(`p`,{className:`text-white text-sm line-clamp-2 mb-2`,children:e.prompt}),(0,M.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,M.jsx)(`span`,{className:`text-white/70 text-xs`,children:O(e.createdAt)}),(0,M.jsxs)(`div`,{className:`pointer-events-auto flex items-center gap-1`,children:[(0,M.jsx)(`button`,{onClick:t=>D(e,t),className:x(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-white/30`,`transition-colors`),title:t(`imageGallery.download`),children:(0,M.jsx)(v,{className:`h-4 w-4 text-white`})}),(0,M.jsx)(`button`,{onClick:t=>E(e.id,t),disabled:a===e.id,className:x(`p-1.5 rounded-lg`,`bg-white/20 hover:bg-red-500/80`,`transition-colors`,a===e.id&&`opacity-50 cursor-not-allowed`),title:t(`imageGallery.delete`),children:a===e.id?(0,M.jsx)(f,{className:`h-4 w-4 text-white animate-spin`}):(0,M.jsx)(y,{className:`h-4 w-4 text-white`})})]})]})]})]},e.id))}),d&&(0,M.jsx)(`div`,{className:`flex justify-center mt-8`,children:(0,M.jsx)(S,{onClick:T,disabled:C,variant:`outline`,className:`px-6`,children:C?(0,M.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,M.jsx)(f,{className:`h-4 w-4 animate-spin`}),t(`common.loading`)]}):t(`imageGallery.loadMore`,{current:g.length,total:_})})}),r&&(0,M.jsx)(N,{image:r,onClose:()=>i(null),onDelete:e=>{E(e,{stopPropagation:()=>{}})},onDownload:e=>{D(e,{stopPropagation:()=>{}})}})]})},I=o(`components:image-generation-panel`),L=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=s(),[i,a]=(0,A.useState)([]),[o,u]=(0,A.useState)(``),[d,m]=(0,A.useState)(``),[h,_]=(0,A.useState)(``),[y,C]=(0,A.useState)(`1024x1024`),[w,T]=(0,A.useState)(`standard`),[E,D]=(0,A.useState)(!1),[O,k]=(0,A.useState)(null),[N,P]=(0,A.useState)([`512x512`,`768x768`,`1024x1024`]),[F,L]=(0,A.useState)([`standard`,`high`]),[R,z]=(0,A.useState)(null),B=A.useId();(0,A.useEffect)(()=>{e&&(async()=>{try{let e=await b.getPlugins();if(e.success&&e.data&&(a(e.data),e.data.length>0)){let t=e.data[0];u(t.id),t.models.length>0&&m(t.models[0]),t.config?.sizes&&(P(t.config.sizes),C(t.config.default_size||t.config.sizes[0]||`1024x1024`)),t.config?.qualities&&(L(t.config.qualities),T(t.config.default_quality||t.config.qualities[0]||`standard`)),z(t.config?.max_prompt_length??null)}}catch(e){I.error(`Failed to load image generation plugins:`,e)}})()},[e]),(0,A.useEffect)(()=>{if(!e)return;let n=document.body.style.overflow,r=e=>{e.key===`Escape`&&t()};return document.body.style.overflow=`hidden`,document.addEventListener(`keydown`,r),()=>{document.body.style.overflow=n,document.removeEventListener(`keydown`,r)}},[e,t]);let[V,H]=(0,A.useState)(o);if(o!==V){H(o);let e=i.find(e=>e.id===o);e&&(e.models.length>0&&!e.models.includes(d)&&m(e.models[0]),e.config?.sizes&&(P(e.config.sizes),e.config.sizes.includes(y)||C(e.config.default_size||e.config.sizes[0])),e.config?.qualities&&(L(e.config.qualities),e.config.qualities.includes(w)||T(e.config.default_quality||e.config.qualities[0])),z(e.config?.max_prompt_length??null))}let U=async()=>{if(!d||!h.trim()){l.error(r(`imageGeneration.enterPrompt`));return}if(R&&h.length>R){l.error(r(`imageGeneration.promptTooLong`,{max:R.toLocaleString()}));return}D(!0),k(null);try{let e=await b.generate({model:d,prompt:h.trim(),size:y,quality:w});if(e.success&&e.data?.images&&e.data.images.length>0){let i=e.data.images[0],a=null;i.b64_json?a=`data:image/png;base64,${i.b64_json}`:i.url&&(a=i.url),a&&(l.success(r(`imageGeneration.success`)),n?(n(a,h.trim(),d),_(``),k(null),t()):k(a))}else l.error(r(`imageGeneration.failed`))}catch(e){I.error(`Image generation failed:`,e);let t=e instanceof Error?e.message:r(`imageGeneration.failed`);l.error(t)}finally{D(!1)}},W=()=>{if(!O)return;let e=document.createElement(`a`);e.href=O,e.download=`generated-image-${Date.now()}.png`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e)return null;let G=i.find(e=>e.id===o);return(0,j.createPortal)((0,M.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":B,children:[(0,M.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:t}),(0,M.jsxs)(`div`,{className:x(`relative bg-white/95 dark:bg-dark-25/95`,`border border-gray-200/80 dark:border-white/10`,`rounded-3xl shadow-2xl backdrop-blur-xl`,`flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden`),onClick:e=>e.stopPropagation(),children:[(0,M.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-5 py-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:[(0,M.jsx)(`div`,{children:(0,M.jsx)(`h2`,{id:B,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,M.jsx)(`button`,{onClick:t,className:`rounded-xl p-2 text-gray-500 transition-colors hover:bg-gray-100 hover:text-gray-900 dark:text-dark-500 dark:hover:bg-white/[0.06] dark:hover:text-dark-900`,title:r(`common.close`,{defaultValue:`Close`}),children:(0,M.jsx)(g,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,M.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 p-5 scrollbar-thin sm:p-6`,children:i.length===0?(0,M.jsxs)(`div`,{className:`text-center py-8`,children:[(0,M.jsx)(p,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,M.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,M.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,M.jsx)(`select`,{value:o,onChange:e=>u(e.target.value),className:x(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:i.map(e=>(0,M.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,M.jsx)(`select`,{value:d,onChange:e=>m(e.target.value),className:x(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:G?.models.map(e=>(0,M.jsx)(`option`,{value:e,children:e},e))})]})]}),(0,M.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.size`)}),(0,M.jsx)(`select`,{value:y,onChange:e=>C(e.target.value),className:x(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:N.map(e=>(0,M.jsx)(`option`,{value:e,children:e},e))})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,M.jsx)(`select`,{value:w,onChange:e=>T(e.target.value),className:x(`w-full rounded-xl px-3 py-2.5 text-sm`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`),children:F.map(e=>(0,M.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,M.jsxs)(`div`,{children:[(0,M.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,M.jsx)(`textarea`,{value:h,onChange:e=>_(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:x(`w-full resize-none rounded-2xl px-4 py-3 text-sm leading-6`,`bg-white/70 dark:bg-white/[0.035]`,`border border-gray-200/80 dark:border-white/10`,`text-gray-900 dark:text-gray-100`,`placeholder-gray-500 dark:placeholder-gray-400`,`focus:outline-none focus:ring-2 focus:ring-primary-500/20`,R&&h.length>R&&`border-red-500 dark:border-red-500`)}),R&&(0,M.jsxs)(`div`,{className:x(`mt-1 text-end text-xs`,h.length>R?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[h.length.toLocaleString(),` /`,` `,R.toLocaleString()]})]}),O&&(0,M.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,M.jsx)(`img`,{src:O,alt:`Generated`,className:`w-full h-auto`}),(0,M.jsx)(`button`,{onClick:W,className:x(`absolute bottom-3 end-3 rounded-lg p-2`,`bg-white/90 dark:bg-dark-100/90`,`hover:bg-white dark:hover:bg-dark-100`,`border border-gray-200 dark:border-dark-300`,`transition-colors`),title:r(`imageGallery.download`),children:(0,M.jsx)(v,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]})}),i.length>0&&(0,M.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,M.jsx)(S,{onClick:U,disabled:E||!h.trim()||!d,className:x(`w-full py-2.5 rounded-xl font-medium`,`bg-primary-600 dark:bg-primary-600`,`hover:bg-primary-700 dark:hover:bg-primary-500`,`text-white`,`disabled:opacity-50 disabled:cursor-not-allowed`,`transition-colors`),children:E?(0,M.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,M.jsx)(f,{className:`h-4 w-4 animate-spin`}),r(`imageGeneration.generating`)]}):(0,M.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,M.jsx)(c,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},R=()=>{let{t:e}=s(),[t,n]=(0,A.useState)(null),[r,i]=(0,A.useState)(!1),[a,o]=(0,A.useState)(0),c=(0,A.useCallback)(()=>{o(e=>e+1)},[]);return(0,M.jsxs)(T,{width:`wide`,children:[(0,M.jsx)(E,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,M.jsx)(`span`,{className:`inline-flex rounded-full border border-gray-200/80 bg-white/60 px-2.5 py-1 text-xs text-gray-500 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-500`,children:e(`gallery.imageCount`,{count:t})}):null,actions:(0,M.jsxs)(S,{onClick:()=>i(!0),className:`gap-2 px-5`,children:[(0,M.jsx)(u,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]})}),(0,M.jsx)(F,{onImageCountChange:n},a),(0,M.jsx)(L,{isOpen:r,onClose:()=>i(!1),onImageGenerated:c})]})};export{R as GalleryPage,R as default};
|
|
@@ -0,0 +1 @@
|
|
|
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{a,c as o,i as s,l as c,n as l,o as u,s as d,t as f,u as p}from"./useTranslation-CP6Cg-EI.js";import{Dt as m,Nt as h,O as g,St as _,T as v,Vt as y,Z as b,_ as x,bt as S,d as C,h as ee,k as w,n as te,ot as T,pt as E,u as ne,vt as D}from"./ui-vendor-njo77ljx.js";import{f as O}from"./api-BNnUZaFX.js";import{t as k}from"./utils-D0l9J3P-.js";import{t as A}from"./Button-BZBnLKRn.js";import{a as j,i as re,z as ie}from"../assets/index-Cp8PdlFo.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=>{o(e)||(R(e)?n(z(e)):d(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),s=t?.transSupportBasicHtmlNodes?t.transKeepBasicHtmlNodesFor??[]:[];return a.forEach((e,a)=>{if(o(e)){i+=`${e}`;return}if((0,L.isValidElement)(e)){let{props:c,type:l}=e,u=Object.keys(c).length,d=s.indexOf(l)>-1,f=c.children;if(!f&&d&&!u){i+=`<${l}/>`;return}if(!f&&(!d||u)||c.i18nIsDynamicList){i+=`<${a}></${a}>`;return}if(d&&u<=1){let e=o(f)?f:H(f,t,n,r);i+=`<${l}>${e}</${l}>`;return}let p=H(f,t,n,r);i+=`<${a}>${p}</${a}>`;return}if(e===null){c(n,`TRANS_NULL_VALUE`,`Passed in a null value as child`,{i18nKey:r});return}if(d(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}c(n,`TRANS_INVALID_OBJ`,`Invalid child - Object should only have keys {{ value, format }} (format is optional).`,{i18nKey:r,child:e});return}c(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+=`<`,o+=1)}else a+=e[o],o+=1;return a},de=(e,t,n,r,i,s,c)=>{if(n===``)return[];let l=i.transKeepBasicHtmlNodesFor||[],f=n&&new RegExp(l.map(e=>`<${e}`).join(`|`)).test(n);if(!e&&!t&&!f&&!c)return[n];let p=t??{},m=e=>{B(e).forEach(e=>{o(e)||(R(e)?m(z(e)):d(e)&&!(0,L.isValidElement)(e)&&Object.assign(p,e))})};m(e);let h=ue(n,l,p),g=se.parse(`<0>${h}</0>`),_={...p,...s},v=(e,t,n)=>{let r=z(e),i=b(r,t.children,n);return ce(r)&&i.length===0||e.props?.i18nIsDynamicList?r:i},y=(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)}))},b=(e,n,s)=>{let p=B(e),m=B(n),h={};return m.reduce((e,n,m)=>{let g=n.children?.[0]?.content&&r.services.interpolator.interpolate(n.children[0].content,_,r.language);if(n.type===`tag`){let a=p[parseInt(n.name,10)];!a&&t&&(a=t[n.name]),s.length===1&&!a&&(a=s[0][n.name]),a||(a={});let x={...n.attrs};c&&Object.keys(x).forEach(e=>{let t=x[e];o(t)&&(x[e]=u(t))});let S=Object.keys(x).length===0?a:le({props:x},a),C=(0,L.isValidElement)(S),ee=C&&R(n,!0)&&!n.voidElement,w=f&&d(S)&&S.dummy&&!C,te=d(t)&&Object.hasOwnProperty.call(t,n.name);if(o(S)){let t=r.services.interpolator.interpolate(S,_,r.language);e.push(t)}else if(R(S)||ee)y(S,v(S,n,s),e,m);else if(w)y(S,b(p,n.children,s),e,m);else if(Number.isNaN(parseFloat(n.name)))if(te)y(S,v(S,n,s),e,m,n.voidElement);else if(i.transSupportBasicHtmlNodes&&l.indexOf(n.name)>-1)if(n.voidElement)e.push((0,L.createElement)(n.name,{key:`${n.name}-${m}`}));else{let t=h[n.name]||0;h[n.name]=t+1;let r,i=0;for(let e=0;e<p.length;e+=1){let a=p[e];if((0,L.isValidElement)(a)&&a.type===n.name){if(i===t){r=a;break}i+=1}}let a=b(r?B(z(r)):p,n.children,s);e.push((0,L.createElement)(n.name,{key:`${n.name}-${m}`},a))}else if(n.voidElement)e.push(`<${n.name} />`);else{let t=b(p,n.children,s);e.push(`<${n.name}>${t}</${n.name}>`)}else if(d(S)&&!C){let t=n.children[0]?g:null;t&&e.push(t)}else y(S,g,e,m,n.children.length!==1||!g)}else if(n.type===`text`){let t=i.transWrapTextNodes,o=typeof i.unescape==`function`?i.unescape:a().unescape,s=c?o(r.services.interpolator.interpolate(n.content,_,r.language)):r.services.interpolator.interpolate(n.content,_,r.language);t?e.push((0,L.createElement)(t,{key:`${n.name}-${m}`},s)):e.push(s)}return e},[])};return z(b([{dummy:!0,children:e||[]}],g,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):d(e)?pe(e,t):(p(n,`TRANS_INVALID_COMPONENTS`,`<Trans /> "components" prop expects an object or array`,{i18nKey:r}),null):null,W=e=>!d(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:c={},values:l,defaults:u,components:d,ns:f,i18n:m,t:h,shouldUnescape:g,..._}){let v=m||s();if(!v)return p(v,`NO_I18NEXT_INSTANCE`,`Trans: You need to pass in an i18next instance using i18nextReactModule`,{i18nKey:r}),e;let y=h||v.t.bind(v)||(e=>e),b={...a(),...v.options?.react},x=f||y.ns||v.options?.defaultNS;x=o(x)?[x]:x||[`translation`];let{transDefaultProps:S}=b,C=S?.tOptions?{...S.tOptions,...c}:c,ee=g??S?.shouldUnescape,w=S?.values?{...S.values,...l}:l,te=S?.components?{...S.components,...d}:d,T=H(e,b,v,r),E=u||C?.defaultValue||T||b.transEmptyNodeValue||(typeof r==`function`?ie(r):r),{hashTransKey:ne}=b,D=r||(ne?ne(T||E):T||E);l=v.options?.interpolation?.defaultVariables?w&&Object.keys(w).length>0?{...w,...v.options.interpolation.defaultVariables}:{...v.options.interpolation.defaultVariables}:w;let O=V(e);O&&typeof O.count==`number`&&t===void 0&&(t=O.count);let k=l||t!==void 0&&!v.options?.interpolation?.alwaysFormat||!e?C.interpolation:{interpolation:{...C.interpolation,prefix:`#$?`,suffix:`?$#`}},A={...C,context:i||C.context,count:t,...l,...k,defaultValue:E,ns:x},j=D?y(D,A):E;j===D&&E&&(j=E);let re=me(te,j,v,r),M=re||e,N=null;W(re)&&(N=re,M=e);let P=de(M,N,j,v,b,A,ee),F=n??b.defaultTransParent;return F?(0,L.createElement)(F,_,P):P}function ge({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a={},values:o,defaults:c,components:u,ns:d,i18n:f,t:p,shouldUnescape:m,...h}){let{i18n:g,defaultNS:_}=(0,L.useContext)(l)||{},v=f||g||s(),y=p||v?.t.bind(v);return he({children:e,count:t,parent:n,i18nKey:r,context:i,tOptions:a,values:o,defaults:c,components:u,ns:d||y?.ns||_||v?.options?.defaultNS,i18n:v,t:p,shouldUnescape:m,...h})}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}=f(),[t,n]=(0,L.useState)(null),[r,i]=(0,L.useState)([]),[a,o]=(0,L.useState)([]),[s,c]=(0,L.useState)([]),[l,u]=(0,L.useState)(null),[d,p]=(0,L.useState)(null),[ie,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(a.filter(e=>e.type===`permission_response`).map(e=>String(e.data.tool_call_id||``)));return a.filter(t=>{if(t.type!==`permission_request`)return!1;let n=String(t.data.tool_call_id||``);return n&&!e.has(n)})},[a]),Re=(0,L.useMemo)(()=>Ae(a,e),[a,e]),$=(0,L.useCallback)(async()=>{try{let[e,t,r,a,o,s]=await Promise.all([O.status(),O.listRuns(30),O.currentModel(),O.currentFallback(),O.usage(``,100),O.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&&(u(r.data),he(String(r.data.provider||``)),_e(String(r.data.model||``))),a.success&&a.data&&p(a.data),o.success&&o.data&&M(String(o.data.text||``)),s.success&&s.data&&c(s.data.automations)}catch(t){K.error(`Failed to load Libre Claw overview:`,t),y.error(e(`libreClaw.toasts.loadStatusFailed`))}finally{ae(!1)}},[e]),ze=(0,L.useCallback)(async(e,t=!1)=>{let n=t?0:a.length>0&&a[a.length-1]?.event_id||0;try{let r=await O.getEvents(e,n);r.success&&r.data&&o(e=>t?r.data?.events||[]:[...e,...r.data?.events||[]])}catch(e){K.error(`Failed to load Libre Claw events:`,e)}},[a]);(0,L.useEffect)(()=>{let e=window.setTimeout(()=>{$()},0);return()=>window.clearTimeout(e)},[$]),(0,L.useEffect)(()=>{if(!N){let e=window.setTimeout(()=>{o([])},0);return()=>window.clearTimeout(e)}let e=N;O.getEvents(e,0).then(e=>{e.success&&e.data&&o(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),O.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()){y.error(e(`libreClaw.toasts.enterTask`));return}I(!0);try{let t=await O.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(``),y.success(e(`libreClaw.toasts.runStarted`))}else y.error(t.error||e(`libreClaw.toasts.startRunFailed`))}catch(t){K.error(`Failed to start Libre Claw run:`,t),y.error(e(`libreClaw.toasts.startRunFailed`))}finally{I(!1)}},Ve=async t=>{try{await O.cancelRun(t),await $(),y.success(e(`libreClaw.toasts.runCancelled`))}catch(t){K.error(`Failed to cancel Libre Claw run:`,t),y.error(e(`libreClaw.toasts.cancelRunFailed`))}},He=async(t,n)=>{if(!N)return;let r=String(t.data.tool_call_id||``);if(r)try{await O.resolvePermission(N,r,n),await ze(N,!0),y.success(e(n===`deny`?`libreClaw.toasts.denied`:`libreClaw.toasts.approved`))}catch(t){K.error(`Failed to resolve Libre Claw permission:`,t),y.error(e(`libreClaw.toasts.resolvePermissionFailed`))}},Ue=async()=>{if(!W.trim()||!q.trim()){y.error(e(`libreClaw.toasts.providerModelRequired`));return}R(!0);try{let t=await O.updateModel(W,q,ye);t.success&&t.data?(u(t.data),y.success(e(`libreClaw.toasts.modelUpdated`))):y.error(t.error||e(`libreClaw.toasts.updateModelFailed`))}catch(t){K.error(`Failed to update Libre Claw model:`,t),y.error(e(`libreClaw.toasts.updateModelFailed`))}finally{R(!1)}},We=async()=>{ce(!0);try{let t=await O.updateTheme(Te,Y);t.success?y.success(e(`libreClaw.toasts.themeUpdated`)):y.error(t.error||e(`libreClaw.toasts.updateThemeFailed`))}catch(t){K.error(`Failed to update Libre Claw theme:`,t),y.error(e(`libreClaw.toasts.updateThemeFailed`))}finally{ce(!1)}},Ge=async()=>{if(!je.trim()||!Ne.trim()||!Z.trim()){y.error(e(`libreClaw.toasts.automationRequired`));return}le(!0);try{let t=await O.createAutomation({name:je,schedule:Ne,prompt:Z,route:Fe});t.success?(Me(``),X(``),Pe(``),await $(),y.success(e(`libreClaw.toasts.automationCreated`))):y.error(t.error||e(`libreClaw.toasts.createAutomationFailed`))}catch(t){K.error(`Failed to create Libre Claw automation:`,t),y.error(e(`libreClaw.toasts.createAutomationFailed`))}finally{le(!1)}},Ke=async(t,n)=>{try{n===`pause`&&await O.pauseAutomation(t),n===`resume`&&await O.resumeAutomation(t),n===`run`&&await O.runAutomationNow(t),n===`delete`&&await O.deleteAutomation(t),await $(),y.success(e(`libreClaw.toasts.automationUpdated`))}catch(t){K.error(`Failed to update Libre Claw automation:`,t),y.error(e(`libreClaw.toasts.updateAutomationFailed`))}};return(0,G.jsxs)(j,{width:`wide`,contentClassName:`space-y-6`,children:[(0,G.jsx)(re,{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)(A,{variant:`secondary`,size:`sm`,onClick:$,children:[(0,G.jsx)(v,{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)(T,{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)(C,{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)(g,{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)(A,{onClick:Be,loading:oe,children:[(0,G.jsx)(_,{className:`h-4 w-4`}),e(`libreClaw.startRun.run`)]})]})]})}),(0,G.jsx)(J,{title:e(`libreClaw.modelRoute.title`),icon:(0,G.jsx)(b,{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)(A,{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)(A,{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`)]})]}),l&&(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(l,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)(m,{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:k(`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)(E,{className:`h-4 w-4`}),actions:Q&&[`queued`,`running`,`blocked`].includes(Q.state)?(0,G.jsxs)(A,{variant:`danger`,size:`sm`,onClick:()=>Ve(Q.run_id),children:[(0,G.jsx)(ee,{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)(x,{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)(A,{size:`sm`,onClick:()=>He(t,`allow_once`),children:[(0,G.jsx)(D,{className:`h-4 w-4`}),e(`libreClaw.approvals.allowOnce`)]}),(0,G.jsx)(A,{size:`sm`,variant:`secondary`,onClick:()=>He(t,`always_allow_tool`),children:e(`libreClaw.approvals.alwaysAllowTool`)}),(0,G.jsxs)(A,{size:`sm`,variant:`danger`,onClick:()=>He(t,`deny`),children:[(0,G.jsx)(te,{className:`h-4 w-4`}),e(`libreClaw.approvals.deny`)]})]})]},t.event_id))]}),(0,G.jsxs)(`div`,{className:`space-y-3`,children:[a.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)(S,{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)(A,{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:[s.length===0&&(0,G.jsx)(Oe,{text:e(`libreClaw.automations.empty`)}),s.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)(g,{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)(g,{className:`h-4 w-4`}):(0,G.jsx)(w,{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)(ne,{className:`h-4 w-4`})})]})]})},t.automation_id))]})]})}),(0,G.jsx)(J,{title:e(`libreClaw.usageFallback.title`),icon:(0,G.jsx)(m,{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:ie||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(d||{},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)(h,{className:`h-7 w-7 animate-spin text-primary-600`})})]})},be=({status:e,t})=>{let n=!!e?.connected;return(0,G.jsxs)(`span`,{className:k(`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:k(`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:k(`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:k(`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:k(`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:k(`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};
|