libre-webui 0.23.0 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/dist/routes/auth.d.ts.map +1 -1
- package/backend/dist/routes/auth.js +20 -3
- package/backend/dist/routes/auth.js.map +1 -1
- package/backend/dist/services/workRuntimeService.d.ts +11 -0
- package/backend/dist/services/workRuntimeService.d.ts.map +1 -1
- package/backend/dist/services/workRuntimeService.js +59 -22
- package/backend/dist/services/workRuntimeService.js.map +1 -1
- package/backend/package.json +1 -1
- package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
- package/frontend/dist/assets/index-BXMQqOXF.js +11 -0
- package/frontend/dist/index.html +9 -9
- package/frontend/dist/js/{ArtifactContainer-CigyGLnW.js → ArtifactContainer-BUjOZ5M5.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-CITpRQXa.js → ArtifactDemoPage-QRve-734.js} +1 -1
- package/frontend/dist/js/{ArtifactSandboxFrame-C8_7sKm1.js → ArtifactSandboxFrame-DhvA-t-7.js} +2 -2
- package/frontend/dist/js/{ArtifactSlideOutPanel-D1f9zUZN.js → ArtifactSlideOutPanel-B8w1Orr1.js} +1 -1
- package/frontend/dist/js/{ChatPage-D-Q1SGlI.js → ChatPage-DKVwaYxn.js} +1 -1
- package/frontend/dist/js/{FirstTimeSetup-DwvqU8Jk.js → FirstTimeSetup-DaQveC0v.js} +1 -1
- package/frontend/dist/js/{GalleryPage-CFU6YW9r.js → GalleryPage-Cz-VvarV.js} +1 -1
- package/frontend/dist/js/{HomePage-CEoZABYG.js → HomePage-DF9pZ5V5.js} +1 -1
- package/frontend/dist/js/{LibreClawPage-VV4sD4-v.js → LibreClawPage-Dw8YQyFj.js} +1 -1
- package/frontend/dist/js/{ModelSelector-DVN9nTCB.js → ModelSelector-Cc91MEm4.js} +1 -1
- package/frontend/dist/js/{ModelsPage-Ce41crA_.js → ModelsPage-BgaQuCry.js} +1 -1
- package/frontend/dist/js/{NotesPage-BV08Gh2X.js → NotesPage-CRAo-TFI.js} +1 -1
- package/frontend/dist/js/{PersonasPage-CSpK5FvR.js → PersonasPage-DpN8DQkY.js} +1 -1
- package/frontend/dist/js/{PluginUsagePage-B9YPhusn.js → PluginUsagePage-5PXXZXle.js} +1 -1
- package/frontend/dist/js/{RichMessageContent-C3qddYMx.js → RichMessageContent-C67tFlr1.js} +1 -1
- package/frontend/dist/js/{SettingsModal-CQSumlFr.js → SettingsModal-BEzMSDlp.js} +1 -1
- package/frontend/dist/js/{SystemPage-7KbZlMb_.js → SystemPage-FUnoW7Er.js} +1 -1
- package/frontend/dist/js/{UserManagementPage-DnyW0Wmx.js → UserManagementPage-SBsRbt0H.js} +1 -1
- package/frontend/dist/js/{WorkPage-B3cuSSwH.js → WorkPage-D3ChSFo-.js} +4 -4
- package/frontend/dist/js/{api-DSzsasYT.js → api-Dw_IuHaz.js} +1 -1
- package/frontend/dist/js/{appStore-CYhqdjge.js → appStore-DAT2R-5p.js} +2 -2
- package/frontend/dist/js/{authStore-CnSn5zM7.js → authStore-CwSMGkEM.js} +3 -3
- package/frontend/dist/js/{chatStore-P1aGCgiF.js → chatStore-BK6YcouV.js} +3 -3
- package/frontend/dist/js/{config-EEx_rELa.js → config-0eBxRk6E.js} +1 -1
- package/frontend/dist/js/{estree-Dc6SMAYy.js → estree-Db_NKIE7.js} +1 -1
- package/frontend/dist/js/{html-Bax5_Bzw.js → html-INl_p8N8.js} +1 -1
- package/frontend/dist/js/{markdown-DxaneQad.js → markdown-DQbfLH11.js} +1 -1
- package/frontend/dist/js/{messageCodeStyles-CxXrl4jD.js → messageCodeStyles-D7zXzjgH.js} +1 -1
- package/frontend/dist/js/{standalone-CCpjftAD.js → standalone-CFSd7xCM.js} +1 -1
- package/frontend/dist/js/{typescript-DtQEF6kq.js → typescript-BIFKSiW0.js} +1 -1
- package/frontend/dist/js/{ui-CUMAcARd.js → ui-CS8EAgvS.js} +2 -2
- package/frontend/dist/js/{workApi-vRuNfpEf.js → workApi-DlmJ72dN.js} +2 -2
- package/package.json +1 -1
- package/frontend/dist/assets/index-CudKJ5Bs.js +0 -27
package/frontend/dist/js/{ArtifactSlideOutPanel-D1f9zUZN.js → ArtifactSlideOutPanel-B8w1Orr1.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{t as i}from"./useTranslation-C3ei3mJq.js";import{t as a}from"./utils-CuC1beTY.js";import{_ as ee,t as o}from"./chatStore-P1aGCgiF.js";import{$t as s,Et as te,Gt as ne,Qt as c,Tt as re,Ut as ie,Xt as ae,cn as oe,dn as l,ln as u,n as d,p as f,qt as p,zt as m}from"./ui-vendor-54SgntkX.js";import{t as h}from"./logger-DSXjF4ye.js";import{t as se}from"./appStore-CYhqdjge.js";import{t as g}from"./Button-BV44cTnj.js";import{t as _}from"./OptimizedSyntaxHighlighter-XwqZEoTf.js";import{a as ce,i as le,l as ue,n as v,o as de,r as y,t as fe}from"./ArtifactSandboxFrame-C8_7sKm1.js";var b=e(t(),1),pe=r(),x=n(),S=h(`components:artifact-slide-out-panel`),C=320,w=.9,me=600,T=()=>{let{t:e,i18n:t}=i(),n=ee(t.language),{artifactPanelOpen:r,artifactPanelArtifact:h,openArtifactPanel:T,closeArtifactPanel:E,theme:D}=se(),O=o(e=>e.currentSession),k=b.useMemo(()=>{if(!h)return[];let e=h.title.trim().toLowerCase(),t=(O?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===h.id)?t:[...t,h]},[O,h]),A=k.findIndex(e=>e.id===h?.id),[he,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(`preview`),[P,F]=(0,b.useState)(me),[I,L]=(0,b.useState)(!1),R=(0,b.useRef)(null),z=(0,b.useRef)(null),B=(0,b.useRef)(0),V=(0,b.useRef)(0),H=(0,b.useRef)(null),U=(0,b.useRef)(null),W=(0,b.useRef)(P),G=h?.id??null;G!==z.current&&(z.current=G,M!==`preview`&&N(`preview`));let K=(0,b.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,F(W.current)}))},[]),q=(0,b.useCallback)(()=>{H.current=null,L(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,F(W.current))},[]),ge=(0,b.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=P,B.current=e.clientX,W.current=P,e.currentTarget.setPointerCapture(e.pointerId),L(!0)},[P]),J=(0,b.useCallback)(e=>{if(!I||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=window.innerWidth*w,i=Math.min(r,Math.max(C,V.current+t));K(i)},[I,n,K]);if((0,b.useEffect)(()=>{if(!I){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[I,J,q]),(0,b.useEffect)(()=>{let e=()=>{let e=window.innerWidth*w;P>e&&F(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[P]),(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r&&E()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,E]),(0,b.useEffect)(()=>{let e=e=>{I||R.current&&!R.current.contains(e.target)&&r&&E()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,E,I]),!h)return null;let Y=h,_e=async e=>{try{await navigator.clipboard.writeText(e),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){S.error(`Failed to copy:`,e)}},ve=()=>{let e=Y.type===`html`?ce(Y.content,Y.title):Y.content,t=new Blob([e],{type:ye(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${be(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ye=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},be=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},xe=()=>{switch(Y.type){case`html`:return(0,x.jsx)(te,{className:`h-5 w-5`});case`react`:return(0,x.jsx)(c,{className:`h-5 w-5`});case`svg`:return(0,x.jsx)(m,{className:`h-5 w-5`});case`code`:return(0,x.jsx)(c,{className:`h-5 w-5`});default:return(0,x.jsx)(m,{className:`h-5 w-5`})}},X=()=>(0,x.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,x.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,x.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,x.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,x.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,x.jsxs)(g,{variant:`outline`,size:`sm`,onClick:()=>N(`code`),className:`mt-4`,children:[(0,x.jsx)(s,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Se=async()=>{try{let e=await y(v(Y.type)??`html`,Y.content,Y.title,{colorScheme:D.mode===`dark`?`dark`:`light`});ue(e,le,Y.title)}catch(e){S.error(`Failed to open the artifact preview:`,e)}},Z=e=>Y.content.trim()?(0,x.jsx)(fe,{content:Y.content,title:Y.title,kind:e,colorScheme:D.mode===`dark`?`dark`:`light`,className:a(`w-full h-full border-0 rounded-lg bg-white`,I&&`pointer-events-none`),fallback:X()}):X(),Ce=()=>(0,x.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:de(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(_,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:Y.content})}),we=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(_,{language:`json`,isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,x.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,x.jsxs)(`div`,{className:`text-center`,children:[(0,x.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},Te=()=>{if(M===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return Ce();case`json`:return we();default:return Q()}},Ee=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,De=$?`100%`:`${P}px`,Oe=(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:a(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),I&&(0,x.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,x.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:De},className:a(`fixed top-0 end-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,x.jsxs)(`div`,{onPointerDown:ge,"data-testid":`artifact-resize-handle`,className:a(`absolute start-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,x.jsx)(`div`,{className:a(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,I&&`bg-primary-500 h-24`)}),(0,x.jsx)(`div`,{className:a(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,I&&`opacity-100`),children:(0,x.jsx)(re,{className:`h-4 w-4`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,x.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:xe()}),(0,x.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:Y.title}),(0,x.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:Y.type.toUpperCase()})]}),(0,x.jsx)(g,{variant:`ghost`,size:`sm`,onClick:E,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,x.jsx)(d,{className:`h-5 w-5`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[k.length>1&&A!==-1&&(0,x.jsxs)(`div`,{className:`me-1 flex items-center gap-0.5`,children:[(0,x.jsx)(g,{variant:`ghost`,size:`sm`,disabled:A===0,onClick:()=>T(k[A-1]),className:`h-8 w-8 p-0`,title:e(`artifacts.previousVersion`),children:(0,x.jsx)(u,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,x.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:A+1,total:k.length})}),(0,x.jsx)(g,{variant:`ghost`,size:`sm`,disabled:A===k.length-1,onClick:()=>T(k[A+1]),className:`h-8 w-8 p-0`,title:e(`artifacts.nextVersion`),children:(0,x.jsx)(oe,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Ee()&&(0,x.jsxs)(x.Fragment,{children:[(0,x.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,x.jsx)(ie,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.preview`)]}),(0,x.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,x.jsx)(s,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,x.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>_e(Y.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:he?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(l,{className:`h-3.5 w-3.5 me-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ae,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.copyButton`)]})}),(0,x.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:ve,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,x.jsx)(p,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.download`)]}),v(Y.type)&&(0,x.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.openInNewWindow`),children:[(0,x.jsx)(ne,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.open`)]})]})]}),Y.description&&(0,x.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:Y.description})}),(0,x.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:Te()}),(0,x.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:(0,x.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,x.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(Y.createdAt).toLocaleString()]}),!$&&(0,x.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]});return(0,pe.createPortal)(Oe,document.body)};export{T as ArtifactSlideOutPanel};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{t as i}from"./useTranslation-C3ei3mJq.js";import{t as a}from"./utils-CuC1beTY.js";import{_ as ee,t as o}from"./chatStore-BK6YcouV.js";import{$t as s,Et as te,Gt as ne,Qt as c,Tt as re,Ut as ie,Xt as ae,cn as oe,dn as l,ln as u,n as d,p as f,qt as p,zt as m}from"./ui-vendor-54SgntkX.js";import{t as h}from"./logger-DSXjF4ye.js";import{t as se}from"./appStore-DAT2R-5p.js";import{t as g}from"./Button-BV44cTnj.js";import{t as _}from"./OptimizedSyntaxHighlighter-XwqZEoTf.js";import{a as ce,i as le,l as ue,n as v,o as de,r as y,t as fe}from"./ArtifactSandboxFrame-DhvA-t-7.js";var b=e(t(),1),pe=r(),x=n(),S=h(`components:artifact-slide-out-panel`),C=320,w=.9,me=600,T=()=>{let{t:e,i18n:t}=i(),n=ee(t.language),{artifactPanelOpen:r,artifactPanelArtifact:h,openArtifactPanel:T,closeArtifactPanel:E,theme:D}=se(),O=o(e=>e.currentSession),k=b.useMemo(()=>{if(!h)return[];let e=h.title.trim().toLowerCase(),t=(O?.messages??[]).flatMap(e=>e.artifacts??[]).filter(t=>t.title.trim().toLowerCase()===e);return t.some(e=>e.id===h.id)?t:[...t,h]},[O,h]),A=k.findIndex(e=>e.id===h?.id),[he,j]=(0,b.useState)(!1),[M,N]=(0,b.useState)(`preview`),[P,F]=(0,b.useState)(me),[I,L]=(0,b.useState)(!1),R=(0,b.useRef)(null),z=(0,b.useRef)(null),B=(0,b.useRef)(0),V=(0,b.useRef)(0),H=(0,b.useRef)(null),U=(0,b.useRef)(null),W=(0,b.useRef)(P),G=h?.id??null;G!==z.current&&(z.current=G,M!==`preview`&&N(`preview`));let K=(0,b.useCallback)(e=>{W.current=e,U.current===null&&(U.current=window.requestAnimationFrame(()=>{U.current=null,F(W.current)}))},[]),q=(0,b.useCallback)(()=>{H.current=null,L(!1),U.current!==null&&(window.cancelAnimationFrame(U.current),U.current=null,F(W.current))},[]),ge=(0,b.useCallback)(e=>{e.preventDefault(),e.stopPropagation(),H.current=e.pointerId,V.current=P,B.current=e.clientX,W.current=P,e.currentTarget.setPointerCapture(e.pointerId),L(!0)},[P]),J=(0,b.useCallback)(e=>{if(!I||H.current!==null&&e.pointerId!==H.current)return;e.preventDefault();let t=(B.current-e.clientX)*(n?-1:1),r=window.innerWidth*w,i=Math.min(r,Math.max(C,V.current+t));K(i)},[I,n,K]);if((0,b.useEffect)(()=>{if(!I){document.body.style.userSelect=``,document.body.style.cursor=``;return}let e=e=>{(H.current===null||e.pointerId===H.current)&&q()};return window.addEventListener(`pointermove`,J,{passive:!1}),window.addEventListener(`pointerup`,e),window.addEventListener(`pointercancel`,e),window.addEventListener(`blur`,q),document.body.style.userSelect=`none`,document.body.style.cursor=`col-resize`,()=>{window.removeEventListener(`pointermove`,J),window.removeEventListener(`pointerup`,e),window.removeEventListener(`pointercancel`,e),window.removeEventListener(`blur`,q),document.body.style.userSelect=``,document.body.style.cursor=``}},[I,J,q]),(0,b.useEffect)(()=>{let e=()=>{let e=window.innerWidth*w;P>e&&F(e)};return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[P]),(0,b.useEffect)(()=>{let e=e=>{e.key===`Escape`&&r&&E()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[r,E]),(0,b.useEffect)(()=>{let e=e=>{I||R.current&&!R.current.contains(e.target)&&r&&E()},t=setTimeout(()=>{window.addEventListener(`mousedown`,e)},100);return()=>{clearTimeout(t),window.removeEventListener(`mousedown`,e)}},[r,E,I]),!h)return null;let Y=h,_e=async e=>{try{await navigator.clipboard.writeText(e),j(!0),setTimeout(()=>j(!1),2e3)}catch(e){S.error(`Failed to copy:`,e)}},ve=()=>{let e=Y.type===`html`?ce(Y.content,Y.title):Y.content,t=new Blob([e],{type:ye(Y.type)}),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`${Y.title}.${be(Y.type)}`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)},ye=e=>{switch(e){case`html`:return`text/html`;case`react`:return`text/javascript`;case`svg`:return`image/svg+xml`;case`css`:return`text/css`;case`json`:return`application/json`;default:return`text/plain`}},be=e=>{switch(e){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`svg`;case`css`:return`css`;case`json`:return`json`;default:return`txt`}},xe=()=>{switch(Y.type){case`html`:return(0,x.jsx)(te,{className:`h-5 w-5`});case`react`:return(0,x.jsx)(c,{className:`h-5 w-5`});case`svg`:return(0,x.jsx)(m,{className:`h-5 w-5`});case`code`:return(0,x.jsx)(c,{className:`h-5 w-5`});default:return(0,x.jsx)(m,{className:`h-5 w-5`})}},X=()=>(0,x.jsx)(`div`,{"data-testid":`artifact-html-fallback`,className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg border border-gray-200 dark:border-dark-200 p-4`,children:(0,x.jsxs)(`div`,{className:`max-w-sm text-center`,children:[(0,x.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-3`}),(0,x.jsx)(`p`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:e(`artifacts.previewUnavailable`)}),(0,x.jsx)(`p`,{className:`mt-1 text-sm text-gray-600 dark:text-gray-400`,children:e(`artifacts.previewUnavailableDescription`)}),(0,x.jsxs)(g,{variant:`outline`,size:`sm`,onClick:()=>N(`code`),className:`mt-4`,children:[(0,x.jsx)(s,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})}),Se=async()=>{try{let e=await y(v(Y.type)??`html`,Y.content,Y.title,{colorScheme:D.mode===`dark`?`dark`:`light`});ue(e,le,Y.title)}catch(e){S.error(`Failed to open the artifact preview:`,e)}},Z=e=>Y.content.trim()?(0,x.jsx)(fe,{content:Y.content,title:Y.title,kind:e,colorScheme:D.mode===`dark`?`dark`:`light`,className:a(`w-full h-full border-0 rounded-lg bg-white`,I&&`pointer-events-none`),fallback:X()}):X(),Ce=()=>(0,x.jsx)(`iframe`,{"data-testid":`artifact-svg-preview`,srcDoc:de(Y.content,Y.title),className:`w-full h-full border-0 rounded-lg bg-white`,sandbox:``,title:Y.title}),Q=()=>(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(_,{language:(()=>{if(Y.language)return Y.language;switch(Y.type){case`html`:return`html`;case`react`:return`jsx`;case`svg`:return`xml`;case`json`:return`json`;default:return`text`}})(),isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:Y.content})}),we=()=>{try{let e=JSON.parse(Y.content),t=JSON.stringify(e,null,2);return(0,x.jsx)(`div`,{className:`h-full overflow-auto`,children:(0,x.jsx)(_,{language:`json`,isDark:D.mode===`dark`,className:`!m-0 !rounded-lg !h-full`,children:t})})}catch{return(0,x.jsx)(`div`,{className:`w-full h-full flex items-center justify-center bg-gray-50 dark:bg-dark-100 rounded-lg`,children:(0,x.jsxs)(`div`,{className:`text-center`,children:[(0,x.jsx)(f,{className:`h-8 w-8 text-primary-500 mx-auto mb-2`}),(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-600`,children:e(`artifacts.invalidJson`)})]})})}},Te=()=>{if(M===`code`)return Q();switch(Y.type){case`html`:return Z(`html`);case`react`:return Z(`react`);case`mermaid`:return Z(`mermaid`);case`svg`:return Ce();case`json`:return we();default:return Q()}},Ee=()=>Y.type===`html`||Y.type===`svg`||Y.type===`react`||Y.type===`mermaid`,$=typeof window<`u`&&window.innerWidth<640,De=$?`100%`:`${P}px`,Oe=(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(`div`,{className:a(`fixed inset-0 bg-black/30 dark:bg-black/50 z-40 transition-opacity duration-300`,r?`opacity-100`:`opacity-0 pointer-events-none`)}),I&&(0,x.jsx)(`div`,{className:`fixed inset-0 z-[55] cursor-col-resize select-none`,"aria-hidden":`true`}),(0,x.jsxs)(`div`,{ref:R,"data-testid":`artifact-slide-out-panel`,style:{width:De},className:a(`fixed top-0 end-0 h-full z-50`,`bg-white dark:bg-dark-25`,`shadow-2xl border-s border-gray-200 dark:border-dark-200`,`flex flex-col`,`transform transition-transform duration-300 ease-out`,r?`translate-x-0`:`translate-x-full rtl:-translate-x-full`),children:[!$&&(0,x.jsxs)(`div`,{onPointerDown:ge,"data-testid":`artifact-resize-handle`,className:a(`absolute start-0 top-0 bottom-0 w-4 -ms-2 cursor-col-resize z-[56]`,`flex items-center justify-center`,`touch-none select-none group`),children:[(0,x.jsx)(`div`,{className:a(`w-1 h-16 rounded-full transition-all duration-200`,`bg-gray-300 dark:bg-dark-300`,`group-hover:bg-primary-500 group-hover:h-24`,I&&`bg-primary-500 h-24`)}),(0,x.jsx)(`div`,{className:a(`absolute left-1/2 -translate-x-1/2 opacity-0 group-hover:opacity-100 transition-opacity`,`text-gray-400 dark:text-dark-500`,I&&`opacity-100`),children:(0,x.jsx)(re,{className:`h-4 w-4`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between p-4 border-b border-gray-200 dark:border-dark-200`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0 flex-1`,children:[(0,x.jsx)(`div`,{className:`text-gray-600 dark:text-gray-400 flex-shrink-0`,children:xe()}),(0,x.jsx)(`h2`,{className:`font-semibold text-gray-900 dark:text-gray-100 truncate`,children:Y.title}),(0,x.jsx)(`span`,{className:`text-xs bg-primary-50 dark:bg-primary-900/20 text-primary-700 dark:text-primary-300 px-2 py-1 rounded-full font-medium flex-shrink-0`,children:Y.type.toUpperCase()})]}),(0,x.jsx)(g,{variant:`ghost`,size:`sm`,onClick:E,className:`h-8 w-8 p-0 hover:bg-gray-100 dark:hover:bg-dark-200 flex-shrink-0`,title:e(`artifacts.closePanelEsc`),children:(0,x.jsx)(d,{className:`h-5 w-5`})})]}),(0,x.jsxs)(`div`,{className:`flex items-center justify-between px-4 py-2 border-b border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:[(0,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[k.length>1&&A!==-1&&(0,x.jsxs)(`div`,{className:`me-1 flex items-center gap-0.5`,children:[(0,x.jsx)(g,{variant:`ghost`,size:`sm`,disabled:A===0,onClick:()=>T(k[A-1]),className:`h-8 w-8 p-0`,title:e(`artifacts.previousVersion`),children:(0,x.jsx)(u,{className:`h-3.5 w-3.5 rtl:rotate-180`})}),(0,x.jsx)(`span`,{className:`whitespace-nowrap text-xs tabular-nums text-gray-500 dark:text-dark-600`,children:e(`artifacts.versionOf`,{current:A+1,total:k.length})}),(0,x.jsx)(g,{variant:`ghost`,size:`sm`,disabled:A===k.length-1,onClick:()=>T(k[A+1]),className:`h-8 w-8 p-0`,title:e(`artifacts.nextVersion`),children:(0,x.jsx)(oe,{className:`h-3.5 w-3.5 rtl:rotate-180`})})]}),Ee()&&(0,x.jsxs)(x.Fragment,{children:[(0,x.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,x.jsx)(ie,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.preview`)]}),(0,x.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,x.jsx)(s,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.code`)]})]})]}),(0,x.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,x.jsx)(g,{variant:`ghost`,size:`sm`,onClick:()=>_e(Y.content),className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.copyContent`),children:he?(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(l,{className:`h-3.5 w-3.5 me-1.5 text-green-500`}),e(`artifacts.copied`)]}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)(ae,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.copyButton`)]})}),(0,x.jsxs)(g,{variant:`ghost`,size:`sm`,onClick:ve,className:`h-8 px-3 text-xs hover:bg-gray-100 dark:hover:bg-dark-200`,title:e(`artifacts.download`),children:[(0,x.jsx)(p,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.download`)]}),v(Y.type)&&(0,x.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.openInNewWindow`),children:[(0,x.jsx)(ne,{className:`h-3.5 w-3.5 me-1.5`}),e(`artifacts.open`)]})]})]}),Y.description&&(0,x.jsx)(`div`,{className:`px-4 py-3 border-b border-gray-100 dark:border-dark-200`,children:(0,x.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-gray-400`,children:Y.description})}),(0,x.jsx)(`div`,{className:`flex-1 p-4 overflow-hidden`,children:Te()}),(0,x.jsx)(`div`,{className:`px-4 py-2 border-t border-gray-100 dark:border-dark-200 bg-gray-50 dark:bg-dark-100/50`,children:(0,x.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,x.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-gray-400`,children:[e(`artifacts.created`),`:`,` `,new Date(Y.createdAt).toLocaleString()]}),!$&&(0,x.jsx)(`div`,{className:`text-xs text-gray-400 dark:text-dark-500`,children:e(`artifacts.dragEdgeToResize`)})]})})]})]});return(0,pe.createPortal)(Oe,document.body)};export{T as ArtifactSlideOutPanel};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{d as i,f as a,u as o}from"./router-vendor-CbPDks39.js";import{t as s}from"./useTranslation-C3ei3mJq.js";import{i as c,n as l,o as u,r as d,t as f}from"./utils-CuC1beTY.js";import{_ as p,a as m,c as h,i as g,l as _,n as v,r as y,t as b}from"./chatStore-P1aGCgiF.js";import{$t as x,An as S,At as C,E as w,Et as T,I as E,J as D,Jt as O,K as k,N as A,O as j,P as M,Qt as N,Rt as ee,S as P,Sn as te,Tn as F,V as ne,Xt as I,_ as L,_n as re,a as R,at as z,c as ie,cn as B,dn as ae,f as oe,ft as V,g as H,gn as se,it as ce,j as le,jn as U,kt as ue,n as W,o as de,ot as fe,r as pe,sn as me,t as he,un as ge,vt as _e,xn as ve,y as ye,yt as be,z as xe,zt as G}from"./ui-vendor-54SgntkX.js";import{i as Se,t as K}from"./logger-DSXjF4ye.js";import{t as Ce}from"./config-EEx_rELa.js";import{S as we,a as Te,b as Ee,d as De,f as Oe,h as ke,n as Ae,o as je,p as Me,r as Ne,v as Pe,w as Fe}from"./api-DSzsasYT.js";import{n as Ie,r as q}from"./authStore-CnSn5zM7.js";import{t as Le}from"./appStore-CYhqdjge.js";import{i as Re,r as ze,t as Be}from"./welcomePrompts-to5mv_gx.js";import{l as Ve}from"./messageCodeStyles-CxXrl4jD.js";import{t as J}from"./Button-BV44cTnj.js";import{d as He,f as Ue,l as We}from"./ui-CUMAcARd.js";import{a as Ge,c as Ke,h as Y,l as qe,o as Je,s as Ye,u as Xe}from"../assets/index-CudKJ5Bs.js";import{c as Ze,s as Qe}from"./ArtifactSandboxFrame-C8_7sKm1.js";import{t as $e}from"./ArtifactContainer-CigyGLnW.js";import{t as et}from"./ModelSelector-DVN9nTCB.js";var tt=r(),X=e(t(),1),Z=n(),nt=({statistics:e,className:t=``})=>{let[n,r]=(0,X.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,Z.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,Z.jsx)(_e,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,Z.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,Z.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,Z.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,Z.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,Z.jsx)(ge,{size:12}):(0,Z.jsx)(B,{size:12,className:`rtl:rotate-180`}),(0,Z.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,Z.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,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,Z.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},rt=K(`components:ttsbutton`),it=null,Q=null,at=0,ot=3e5;async function st(e=!1){let t=Date.now();return!e&&it!==null&&t-at<ot?it:Q||(Q=(async()=>{try{let e=await je.getModels();return e.success&&e.data&&e.data.length>0?(it=e.data,at=t,e.data):(it=[],at=t,[])}catch{return it=[],at=t,[]}finally{Q=null}})(),Q)}var ct=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:c}=s(),{preferences:l}=Le(),[u,d]=(0,X.useState)(`idle`),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)([]),[_,v]=(0,X.useState)(null),y=(0,X.useRef)(null),b=(0,X.useRef)(0);(0,X.useEffect)(()=>{let e=!0;return(async()=>{let t=await st(),n=Ne(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await st(!0)),e&&(g(t),v(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let x=()=>{b.current+=1,y.current?.cancel(),y.current=null,d(`idle`)},S=async()=>{if(r===`blocked`||r===`error`){a?.();return}if(r===`loading`||r===`generating`||r===`buffering`||r===`playing`){i?.();return}if(u===`loading`||u===`generating`||u===`buffering`||u===`playing`){x();return}if(y.current){x();return}let t=Xe();d(`loading`),m(null);let n=b.current+1;b.current=n;try{let r=await t;if(b.current!==n)return;if(r===`blocked`){d(`blocked`);return}let i=l.ttsSettings,a=Te(h,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,u=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),p=f&&i?.voice||a?.config?.default_voice,m=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,v=Math.max(1,a?.config?.max_characters||600),x=Math.min(v,600),S=i?.streamSentences!==!1||e.length>x?Je(e,{locale:c.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=Ye({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>je.generate({model:s,pluginId:u,input:e,voice:m?void 0:p||void 0,voiceProfileId:m,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});y.current=C;let w=Ge(C);try{await C.play(S)}finally{w(),y.current===C&&(y.current=null)}}catch(e){if(b.current!==n)return;if(Ke(e)){d(`idle`);return}if(qe(e)){d(`blocked`);return}let t=e instanceof Error?e.message:o(`ttsButton.generateFailed`);m(t),rt.error(`TTS error:`,e),d(`error`)}};if((0,X.useEffect)(()=>()=>{b.current+=1,y.current?.cancel(),y.current=null},[]),_===!1||_===null)return null;let C={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},w={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`},T=r&&![`idle`,`ended`,`cancelled`].includes(r)?r:u,E=T===`loading`||T===`generating`||T===`buffering`,D=T===`playing`,O=T===`blocked`,k=!!p||T===`error`,A=p||o(k?`ttsButton.playbackFailed`:O?`ttsButton.enableAudio`:D||E?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,Z.jsxs)(`button`,{onClick:S,disabled:!e,title:A,"aria-label":A,"aria-busy":E||void 0,className:f(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,k?`text-red-500 dark:text-red-400`:O?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:D?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!O&&C[n],O&&n===`sm`&&`h-7`,O&&n===`md`&&`h-8`,O&&n===`lg`&&`h-10`,t),children:[E?(0,Z.jsx)(V,{className:f(w[n],`animate-spin`)}):D?(0,Z.jsx)(P,{className:w[n]}):k||O?(0,Z.jsx)(R,{className:w[n]}):(0,Z.jsx)(de,{className:w[n]}),O&&(0,Z.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},lt=new Map;function ut(e,t,n=``){let r=lt.get(e);if(n){if((!r||r.state===`none`)&&(lt.set(e,{state:`open`,startedAt:Date.now()}),!t))return;let n=lt.get(e);t&&n?.state===`open`&<.set(e,{state:`done`,durationMs:Date.now()-n.startedAt});return}if(r&&r.state!==`open`||!t)return;let i=u(t);if(!r){i.thinkingComplete?lt.set(e,{state:`none`}):lt.set(e,{state:`open`,startedAt:Date.now()});return}i.thinkingComplete&<.set(e,{state:`done`,durationMs:Date.now()-r.startedAt})}function dt(e){let t=lt.get(e);if(t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function ft(e){let t=lt.get(e);if(lt.delete(e),t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function pt(e){let t=e/1e3;if(t<.95)return`${Math.max(.1,Math.round(t*10)/10)}s`;if(t<60)return`${Math.round(t)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return r>0?`${n}m ${r}s`:`${n}m`}var mt=/```([^\n`]*)\n([\s\S]*?)\n```/g,ht=/^(?:%%|flowchart|graph|sequenceDiagram|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|mindmap|timeline|gitGraph|quadrantChart|requirementDiagram|sankey-beta|xychart-beta|block-beta|architecture-beta|packet-beta|kanban|radar-beta|treemap-beta|C4Context)\b/i,gt=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,_t=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],vt=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:Dt(e[1]),title:yt(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=Dt(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function yt(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return xt(bt(e))}function bt(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 xt(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 St(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return yt(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&yt(n[1]).trim()||null}function Ct(e){for(let t of[/export\s+default\s+(?:function|class)\s+([A-Z]\w*)/,/export\s+default\s+([A-Z]\w*)\s*(?:;|$)/m,/(?:function|class)\s+([A-Z]\w*)/,/const\s+([A-Z]\w*)\s*[:=]/,/(?:function|const|class)\s+(\w+)/]){let n=e.match(t);if(n)return n[1]}return null}function wt(e){let t=e.match(/^\s*title\s+(.+)$/im);if(t)return t[1].trim();let n=e.trim().match(/^([A-Za-z][\w-]*)/);if(!n)return null;let r=n[1].replace(/-(?:beta|v2)$/i,``).replace(/([a-z])([A-Z])/g,`$1 $2`);return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function Tt(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 Et(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 Dt(e){let t=e.trim().toLowerCase();return _t.includes(t)?t:`text`}function Ot(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 kt(e){let t=[],n=new RegExp(mt),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=At(n,Mt(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 At(e,t){let n=jt(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!gt.test(r)&&!r.includes(`=`)?Ot(r):void 0)||Ot(Pt(n)),fileName:n}}function jt(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&>.test(t[1]))return Nt(t[1]);let n=e.match(gt);return n?Nt(n[0]):void 0}function Mt(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{d as i,f as a,u as o}from"./router-vendor-CbPDks39.js";import{t as s}from"./useTranslation-C3ei3mJq.js";import{i as c,n as l,o as u,r as d,t as f}from"./utils-CuC1beTY.js";import{_ as p,a as m,c as h,i as g,l as _,n as v,r as y,t as b}from"./chatStore-BK6YcouV.js";import{$t as x,An as S,At as C,E as w,Et as T,I as E,J as D,Jt as O,K as k,N as A,O as j,P as M,Qt as N,Rt as ee,S as P,Sn as te,Tn as F,V as ne,Xt as I,_ as L,_n as re,a as R,at as z,c as ie,cn as B,dn as ae,f as oe,ft as V,g as H,gn as se,it as ce,j as le,jn as U,kt as ue,n as W,o as de,ot as fe,r as pe,sn as me,t as he,un as ge,vt as _e,xn as ve,y as ye,yt as be,z as xe,zt as G}from"./ui-vendor-54SgntkX.js";import{i as Se,t as K}from"./logger-DSXjF4ye.js";import{t as Ce}from"./config-0eBxRk6E.js";import{S as we,a as Te,b as Ee,d as De,f as Oe,h as ke,n as Ae,o as je,p as Me,r as Ne,v as Pe,w as Fe}from"./api-Dw_IuHaz.js";import{n as Ie,r as q}from"./authStore-CwSMGkEM.js";import{t as Le}from"./appStore-DAT2R-5p.js";import{i as Re,r as ze,t as Be}from"./welcomePrompts-to5mv_gx.js";import{l as Ve}from"./messageCodeStyles-D7zXzjgH.js";import{t as J}from"./Button-BV44cTnj.js";import{d as He,f as Ue,l as We}from"./ui-CS8EAgvS.js";import{a as Ge,c as Ke,h as Y,l as qe,o as Je,s as Ye,u as Xe}from"../assets/index-BXMQqOXF.js";import{c as Ze,s as Qe}from"./ArtifactSandboxFrame-DhvA-t-7.js";import{t as $e}from"./ArtifactContainer-BUjOZ5M5.js";import{t as et}from"./ModelSelector-Cc91MEm4.js";var tt=r(),X=e(t(),1),Z=n(),nt=({statistics:e,className:t=``})=>{let[n,r]=(0,X.useState)(!1),{t:i}=s(),a=e=>{if(e==null)return`N/A`;let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:`${(t/1e3).toFixed(2)}s`},o=e=>e?`${e.toFixed(1)} t/s`:`N/A`,c=e.prompt_eval_count||0,l=e.eval_count||0,u=c+l,d=a(e.total_duration),f=o(e.tokens_per_second);return(0,Z.jsxs)(`div`,{className:`text-xs text-gray-500 dark:text-dark-500 mt-2 ${t}`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-4 mb-1`,children:[(0,Z.jsxs)(`span`,{className:`flex items-center gap-1 text-gray-600 dark:text-dark-600`,children:[(0,Z.jsx)(_e,{size:12,className:`text-primary-500`}),l,` tokens`]}),(0,Z.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:f}),(0,Z.jsx)(`span`,{className:`text-gray-500 dark:text-dark-500`,children:d}),e.model&&(0,Z.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,Z.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,Z.jsx)(ge,{size:12}):(0,Z.jsx)(B,{size:12,className:`rtl:rotate-180`}),(0,Z.jsx)(`span`,{children:i(`generationStats.details`)})]}),n&&(0,Z.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,Z.jsxs)(`div`,{className:`grid grid-cols-2 gap-x-4 gap-y-2`,children:[(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptTokens`)}),` `,c]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedTokens`)}),` `,l]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTokens`)}),` `,u]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.speed`)}),` `,f]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.promptEval`)}),` `,a(e.prompt_eval_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generation`)}),` `,a(e.eval_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.modelLoad`)}),` `,a(e.load_duration)]}),(0,Z.jsxs)(`div`,{className:`text-gray-700 dark:text-dark-700`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.totalTime`)}),` `,d]})]}),e.created_at&&(0,Z.jsxs)(`div`,{className:`pt-2 border-t border-gray-200 dark:border-dark-300 text-gray-600 dark:text-dark-600`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-gray-800 dark:text-dark-800`,children:i(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString()]})]})]})},rt=K(`components:ttsbutton`),it=null,Q=null,at=0,ot=3e5;async function st(e=!1){let t=Date.now();return!e&&it!==null&&t-at<ot?it:Q||(Q=(async()=>{try{let e=await je.getModels();return e.success&&e.data&&e.data.length>0?(it=e.data,at=t,e.data):(it=[],at=t,[])}catch{return it=[],at=t,[]}finally{Q=null}})(),Q)}var ct=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:c}=s(),{preferences:l}=Le(),[u,d]=(0,X.useState)(`idle`),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)([]),[_,v]=(0,X.useState)(null),y=(0,X.useRef)(null),b=(0,X.useRef)(0);(0,X.useEffect)(()=>{let e=!0;return(async()=>{let t=await st(),n=Ne(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await st(!0)),e&&(g(t),v(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let x=()=>{b.current+=1,y.current?.cancel(),y.current=null,d(`idle`)},S=async()=>{if(r===`blocked`||r===`error`){a?.();return}if(r===`loading`||r===`generating`||r===`buffering`||r===`playing`){i?.();return}if(u===`loading`||u===`generating`||u===`buffering`||u===`playing`){x();return}if(y.current){x();return}let t=Xe();d(`loading`),m(null);let n=b.current+1;b.current=n;try{let r=await t;if(b.current!==n)return;if(r===`blocked`){d(`blocked`);return}let i=l.ttsSettings,a=Te(h,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,u=a?.plugin||i?.pluginId,f=a?.model===i?.model&&(!i?.pluginId||a?.plugin===i.pluginId),p=f&&i?.voice||a?.config?.default_voice,m=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,v=Math.max(1,a?.config?.max_characters||600),x=Math.min(v,600),S=i?.streamSentences!==!1||e.length>x?Je(e,{locale:c.language,maxChars:x,targetChars:Math.min(x,420),minChars:Math.min(x,80)}):[e.trim()];if(S.length===0)throw Error(o(`ttsButton.generateFailed`));let C=Ye({concurrency:3,initialBufferSize:Math.min(2,S.length),generate:(e,{signal:t})=>je.generate({model:s,pluginId:u,input:e,voice:m?void 0:p||void 0,voiceProfileId:m,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});y.current=C;let w=Ge(C);try{await C.play(S)}finally{w(),y.current===C&&(y.current=null)}}catch(e){if(b.current!==n)return;if(Ke(e)){d(`idle`);return}if(qe(e)){d(`blocked`);return}let t=e instanceof Error?e.message:o(`ttsButton.generateFailed`);m(t),rt.error(`TTS error:`,e),d(`error`)}};if((0,X.useEffect)(()=>()=>{b.current+=1,y.current?.cancel(),y.current=null},[]),_===!1||_===null)return null;let C={sm:`h-6 w-6 p-1`,md:`h-8 w-8 p-1.5`,lg:`h-10 w-10 p-2`},w={sm:`h-3.5 w-3.5`,md:`h-4 w-4`,lg:`h-5 w-5`},T=r&&![`idle`,`ended`,`cancelled`].includes(r)?r:u,E=T===`loading`||T===`generating`||T===`buffering`,D=T===`playing`,O=T===`blocked`,k=!!p||T===`error`,A=p||o(k?`ttsButton.playbackFailed`:O?`ttsButton.enableAudio`:D||E?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,Z.jsxs)(`button`,{onClick:S,disabled:!e,title:A,"aria-label":A,"aria-busy":E||void 0,className:f(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-1`,`disabled:opacity-50 disabled:cursor-not-allowed`,k?`text-red-500 dark:text-red-400`:O?`w-auto gap-1 bg-amber-50 px-2 text-amber-700 dark:bg-amber-900/20 dark:text-amber-300`:D?`text-primary-600 dark:text-primary-400 bg-primary-50 dark:bg-primary-900/20`:`text-gray-500 dark:text-gray-400`,!O&&C[n],O&&n===`sm`&&`h-7`,O&&n===`md`&&`h-8`,O&&n===`lg`&&`h-10`,t),children:[E?(0,Z.jsx)(V,{className:f(w[n],`animate-spin`)}):D?(0,Z.jsx)(P,{className:w[n]}):k||O?(0,Z.jsx)(R,{className:w[n]}):(0,Z.jsx)(de,{className:w[n]}),O&&(0,Z.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},lt=new Map;function ut(e,t,n=``){let r=lt.get(e);if(n){if((!r||r.state===`none`)&&(lt.set(e,{state:`open`,startedAt:Date.now()}),!t))return;let n=lt.get(e);t&&n?.state===`open`&<.set(e,{state:`done`,durationMs:Date.now()-n.startedAt});return}if(r&&r.state!==`open`||!t)return;let i=u(t);if(!r){i.thinkingComplete?lt.set(e,{state:`none`}):lt.set(e,{state:`open`,startedAt:Date.now()});return}i.thinkingComplete&<.set(e,{state:`done`,durationMs:Date.now()-r.startedAt})}function dt(e){let t=lt.get(e);if(t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function ft(e){let t=lt.get(e);if(lt.delete(e),t){if(t.state===`done`)return t.durationMs;if(t.state===`open`)return Date.now()-t.startedAt}}function pt(e){let t=e/1e3;if(t<.95)return`${Math.max(.1,Math.round(t*10)/10)}s`;if(t<60)return`${Math.round(t)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return r>0?`${n}m ${r}s`:`${n}m`}var mt=/```([^\n`]*)\n([\s\S]*?)\n```/g,ht=/^(?:%%|flowchart|graph|sequenceDiagram|classDiagram|stateDiagram(?:-v2)?|erDiagram|journey|gantt|pie|mindmap|timeline|gitGraph|quadrantChart|requirementDiagram|sankey-beta|xychart-beta|block-beta|architecture-beta|packet-beta|kanban|radar-beta|treemap-beta|C4Context)\b/i,gt=/[\w@./-]+\.(?:html?|css|mjs|js|jsx|ts|tsx|svg|json|py)/i,_t=[`html`,`react`,`svg`,`mermaid`,`chart`,`code`,`text`,`json`],vt=[{regex:/<artifact\s+type="([^"]+)"\s+title="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>({type:Dt(e[1]),title:yt(e[2]).trim()||`Artifact`,content:e[3].trim()})},{regex:/<artifact\s+type="([^"]+)"[^>]*>([\s\S]*?)<\/artifact>/gi,extract:e=>{let t=Dt(e[1]);return{type:t,title:`${t.toUpperCase()} Artifact`,content:e[2].trim()}}}];function yt(e){if(typeof document<`u`){let t=document.createElement(`div`);return t.innerHTML=e,t.textContent||t.innerText||``}return xt(bt(e))}function bt(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 xt(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 St(e){let t=e.match(/<title[^>]*>([\s\S]*?)<\/title>/i);if(t)return yt(t[1]).trim()||null;let n=e.match(/<h1[^>]*>([\s\S]*?)<\/h1>/i);return n&&yt(n[1]).trim()||null}function Ct(e){for(let t of[/export\s+default\s+(?:function|class)\s+([A-Z]\w*)/,/export\s+default\s+([A-Z]\w*)\s*(?:;|$)/m,/(?:function|class)\s+([A-Z]\w*)/,/const\s+([A-Z]\w*)\s*[:=]/,/(?:function|const|class)\s+(\w+)/]){let n=e.match(t);if(n)return n[1]}return null}function wt(e){let t=e.match(/^\s*title\s+(.+)$/im);if(t)return t[1].trim();let n=e.trim().match(/^([A-Za-z][\w-]*)/);if(!n)return null;let r=n[1].replace(/-(?:beta|v2)$/i,``).replace(/([a-z])([A-Z])/g,`$1 $2`);return`${r.charAt(0).toUpperCase()}${r.slice(1)}`}function Tt(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 Et(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 Dt(e){let t=e.trim().toLowerCase();return _t.includes(t)?t:`text`}function Ot(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 kt(e){let t=[],n=new RegExp(mt),r;for(;(r=n.exec(e))!==null;){let n=r[1].trim(),i=At(n,Mt(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 At(e,t){let n=jt(e)||t,r=e.split(/\s+/).filter(Boolean)[0]?.replace(/[{}[\]()]/g,``);return{language:(r&&!gt.test(r)&&!r.includes(`=`)?Ot(r):void 0)||Ot(Pt(n)),fileName:n}}function jt(e){let t=e.match(/(?:file(?:name)?|path|name)\s*=\s*["']?([^"'\s]+)["']?/i);if(t&>.test(t[1]))return Nt(t[1]);let n=e.match(gt);return n?Nt(n[0]):void 0}function Mt(e,t){let n=e.slice(Math.max(0,t-180),t).split(`
|
|
2
2
|
`).slice(-3).reverse();for(let e of n){let t=e.trim().replace(/^#{1,6}\s*/,``).replace(/^[-*]\s*/,``).replace(/[::]\s*$/,``).match(gt);if(t)return Nt(t[0])}}function Nt(e){return e.replace(/^["'`]+|["'`:]+$/g,``)}function Pt(e){return e?.match(/\.([a-z0-9]+)$/i)?.[1]}function Ft(e){return e?.split(/[\\/]/).pop()}function It(e){let t=Ft(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 Lt(e){let t=Date.now();return{...e,id:`artifact-${t}-${Math.random().toString(36).slice(2,11)}`,createdAt:t,updatedAt:t}}function Rt(e){let t=Ot(e.language)||Ot(Pt(e.fileName));switch(t){case`html`:return{type:`html`,title:St(e.content)||It(e.fileName)||`HTML Document`};case`svg`:return{type:`svg`,title:It(e.fileName)||`SVG Image`};case`react`:return{type:`react`,title:Ct(e.content)||It(e.fileName)||`React Component`,language:`jsx`};case`mermaid`:return{type:`mermaid`,title:wt(e.content)||`Diagram`,language:`mermaid`};case`json`:return{type:`json`,title:It(e.fileName)||`JSON Data`};case`python`:return{type:`code`,title:Tt(e.content)||It(e.fileName)||`Python Code`,language:`python`};case`css`:return{type:`code`,title:It(e.fileName)||`CSS Styles`,language:`css`};case`javascript`:return{type:`code`,title:Et(e.content)||It(e.fileName)||`JavaScript Code`,language:`javascript`};case`typescript`:return{type:`code`,title:It(e.fileName)||`TypeScript Code`,language:`typescript`};default:return t?{type:`code`,title:It(e.fileName)||`${t.toUpperCase()} Code`,language:t}:null}}function zt(e){return(Ot(e.language)||Ot(Pt(e.fileName)))===`html`}function Bt(e){return(Ot(e.language)||Ot(Pt(e.fileName)))===`css`}function Vt(e){return(Ot(e.language)||Ot(Pt(e.fileName)))===`javascript`}function Ht(e){let t=kt(e),n=t.filter(zt);if(n.length===0)return null;let r=t.filter(Bt),i=t.filter(Vt);if(r.length===0&&i.length===0)return null;let a=n.find(e=>/(^|[/\\])index\.html?$/i.test(e.fileName||``))||n[0],o=Ut(a.content,r,i),s=Ze(o,r.map(e=>e.content),i.map(e=>e.content));return Jt(s,`html`)?{artifact:Lt({type:`html`,title:St(s)||It(a.fileName)||`Interactive HTML App`,description:`Bundled generated HTML, CSS, and JavaScript files into one runnable artifact.`,content:s}),ranges:[a,...r,...i]}:null}function Ut(e,t,n){let r=e;for(let e of t){let t=Ft(e.fileName);t&&(r=r.replace(RegExp(`<link\\b[^>]*href=["'][^"']*${qt(t)}["'][^>]*>`,`gi`),``))}for(let e of n){let t=Ft(e.fileName);t&&(r=r.replace(RegExp(`<script\\b[^>]*src=["'][^"']*${qt(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=kt(e);if(Gt(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 Jt(s,`html`)?{artifact:Lt({type:`html`,title:St(s)||`HTML Document`,content:s}),ranges:[{start:r,end:o}]}:null}function Gt(e,t){return t.some(t=>e>=t.start&&e<=t.end)}function Kt(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 qt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Jt(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&&(Qe(t)||t.length>160||r)}if(t===`svg`)return/<svg[^>]*>/.test(e);if(t===`react`)return/<[A-Za-z][^>]*>/.test(e)&&/\b(?:export\s+default|return\s*[(<]|=>\s*[(<]|createRoot|render\s*\()/.test(e);if(t===`mermaid`)return ht.test(e.trim());if(t===`json`)try{return JSON.parse(e),e.trim().length>100}catch{return!1}if(t===`code`){let t=e.split(`
|
|
3
3
|
`).length,n=e.trim().length,r=/function|class|def |import |from |const |let |var |if |for |while |try |catch/.test(e);return(n>500||t>15)&&r}return e.trim().length>200}function Yt(e){let t=[],n=e;for(let e of vt){e.regex.lastIndex=0;let r=[],i;for(;(i=e.regex.exec(n))!==null;){let n=e.extract(i);Jt(n.content,n.type)&&(t.push(Lt({type:n.type,title:n.title,content:n.content})),r.push({start:i.index,end:i.index+i[0].length}))}n=Kt(n,r)}let r=Ht(n);for(;r;)t.push(r.artifact),n=Kt(n,r.ranges),r=Ht(n);let i=Wt(n);i&&(t.push(i.artifact),n=Kt(n,i.ranges));let a=kt(n),o=[];for(let e of a){let n=Rt(e);!n||!Jt(e.content,n.type)||(t.push(Lt({type:n.type,title:n.title,content:e.content,language:n.language})),o.push(e))}return n=Kt(n,o),{content:n.trim(),artifacts:t}}var Xt=K(`components:chat-message`);function Zt({role:e,user:t,personaAvatar:n}){let[r,i]=(0,X.useState)(null);if(e===`assistant`){let e=n?.trim()||``,t=e.startsWith(`data:`)&&e!==r?e:``;return(0,Z.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-sm dark:border-white/[0.09] dark:bg-dark-200 dark:text-dark-950`,children:t?(0,Z.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>i(e)}):e?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,Z.jsx)(Y,{label:null,className:`h-4 w-4`})})}let a=t?.username||`User`,o=t?.avatar?.trim()||``,s=!!o&&o!==r;return(0,Z.jsx)(`div`,{role:s?void 0:`img`,"aria-label":s?void 0:a,"data-testid":`chat-user-avatar`,className:f(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,s?`border border-black/[0.07] bg-white dark:border-white/[0.09] dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:a,children:s?(0,Z.jsx)(`img`,{src:o,alt:a,className:`h-full w-full object-cover`,onError:()=>i(o)}):t?.username?(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,Z.jsx)(ie,{"aria-hidden":`true`,className:`h-4 w-4`})})}var Qt=({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onEditResend:a})=>{let{t:o,i18n:c}=s(),l=e.role===`user`,p=e.role===`system`,{preferences:m}=Le(),{user:h}=Ie(),{setSystemMessage:g,getCurrentPersona:_,currentSession:v,rateMessage:y}=b(),x=_(),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(e.content),[D,O]=(0,X.useState)(null),[A,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(!1),[ee,P]=(0,X.useState)(!1),[te,F]=(0,X.useState)(`idle`),[ne,re]=(0,X.useState)(!1),R=(0,X.useRef)(null),z=(0,X.useRef)(0),ie=(0,X.useRef)(t),B=(0,X.useRef)(!1),oe=async()=>{try{await navigator.clipboard.writeText(e.content),Ve(`success`),re(!0),setTimeout(()=>re(!1),2e3)}catch(e){Xt.error(`Failed to copy message:`,e)}},{thinkingContent:V,thinkingStreaming:ce,parsedContent:U,artifacts:ue}=(0,X.useMemo)(()=>{if(l||p||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:u(e.content),r=n.content,i=t&&!n.thinkingComplete;if(e.artifacts&&e.artifacts.length>0)return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:e.artifacts};if(!t){let e=Yt(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,l,p,t]),de=ce?void 0:e.statistics?.thinking_duration_ms??dt(e.id),fe=(0,X.useCallback)(async e=>{let t=z.current+1;z.current=t,R.current?.cancel(),R.current=null,F(`loading`);try{if(e){let n=await e;if(z.current!==t)return;if(n===`blocked`){F(`blocked`);return}}let n=await je.getModels();if(z.current!==t)return;let r=n.success&&n.data?n.data:[],i=m.ttsSettings,a=Te(r,i?.model,i?.pluginId),o=Ne(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,l=a?.plugin||i?.pluginId,u=o&&i?.voice||a?.config?.default_voice,d=o&&i?.voiceProfileId||void 0,f=Math.max(1,a?.config?.max_characters||600),p=Math.min(f,600),h=i?.streamSentences!==!1||U.length>p?Je(U,{locale:c.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[U.trim()];if(h.length===0){F(`idle`);return}let g=Ye({concurrency:3,initialBufferSize:Math.min(2,h.length),generate:(e,{signal:t})=>je.generate({model:s,pluginId:l,input:e,voice:d?void 0:u||void 0,voiceProfileId:d,speed:i?.speed||1,response_format:a?.config?.default_format},{signal:t}),onStateChange:e=>{z.current===t&&F(e)}});if(z.current!==t){g.cancel();return}R.current=g;let _=Ge(g);try{await g.play(h)}finally{_(),R.current===g&&(R.current=null),z.current===t&&(g.state===`ended`||g.state===`cancelled`)&&F(`idle`)}}catch(e){if(z.current!==t)return;Ke(e)?F(`idle`):qe(e)?F(`blocked`):(Xt.error(`Auto-play TTS failed:`,e),F(`error`))}},[c.language,U,m.ttsSettings]);(0,X.useEffect)(()=>{let e=ie.current&&!t;ie.current=t,e&&!B.current&&!l&&!p&&U&&m.ttsSettings?.enabled&&m.ttsSettings.autoPlay&&(B.current=!0,fe())},[t,l,p,U,m.ttsSettings?.autoPlay,m.ttsSettings?.enabled,fe]),(0,X.useEffect)(()=>()=>{z.current+=1,R.current?.cancel(),R.current=null},[]);let pe=()=>{let e=Xe();fe(e)},he=()=>{z.current+=1,R.current?.cancel(),R.current=null,F(`idle`)},_e=()=>p?o(`chatMessage.system`):l?m.showUsername&&h?.username?h.username:o(`chatMessage.you`):x?.name?x.name:e.model||o(`chatMessage.assistant`),ve=()=>{C(!0),T(e.content)},ye=async()=>{j(!0);try{g(w),C(!1),Xt.debug(`✅ System message updated:`,w)}catch(e){Xt.error(`Failed to save system message:`,e)}finally{j(!1)}},be=()=>{C(!1),T(e.content)},G=()=>{let t=w.trim();C(!1),!(!t||t===e.content)&&a?.(e.id,t)},Se=t=>{v&&y(v.id,e.id,e.rating===t?void 0:t)},K=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,Ce=p&&e.content.length>100;return(0,Z.jsxs)(`div`,{className:f(`group flex py-1.5 transition-colors sm:py-2`,l?`justify-end`:`justify-start`,n),children:[(0,Z.jsxs)(`div`,{className:f(`flex min-w-0 gap-2.5 sm:gap-3`,l?`max-w-[85%] sm:max-w-[70%]`:`w-full`),children:[!l&&!p&&(0,Z.jsx)(Zt,{role:`assistant`,personaAvatar:x?.avatar}),(0,Z.jsxs)(`div`,{className:f(`min-w-0 flex-1`,l?`flex flex-col items-end`:p?`py-1.5`:`py-0.5`),children:[!l&&!p&&(0,Z.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,Z.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-700 rtl:tracking-normal dark:text-dark-700`,children:_e()}),e.model&&x?.name&&(0,Z.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,Z.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-gray-400 dark:text-dark-500`,children:d(e.timestamp,c.language)})]}),(0,Z.jsxs)(`div`,{className:f(!l&&!p&&`text-[0.9375rem] leading-[1.65] text-gray-800 dark:text-dark-800`),children:[e.images&&e.images.length>0&&(0,Z.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,Z.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/[0.06] bg-gray-100 dark:border-white/[0.08] dark:bg-gray-800`,children:(0,Z.jsx)(`img`,{src:e,alt:`Uploaded image ${t+1}`,className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`,onClick:()=>O(e)})},t))}),l?S?(0,Z.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/[0.08] bg-white p-2 shadow-sm dark:border-white/[0.08] dark:bg-dark-100`,children:[(0,Z.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>T(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),G()):e.key===`Escape`&&be()},autoFocus:!0,className:`min-h-[72px] w-full resize-y rounded-xl border-none bg-transparent p-2 text-[0.9375rem] leading-relaxed text-gray-900 focus:outline-none dark:text-dark-900`}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,Z.jsx)(`button`,{onClick:be,className:`rounded-lg px-2.5 py-1 text-xs text-gray-500 transition-colors hover:bg-gray-100 dark:text-dark-600 dark:hover:bg-dark-200`,children:o(`chatMessage.cancelEditing`)}),(0,Z.jsx)(`button`,{onClick:G,className:`rounded-lg bg-gray-900 px-2.5 py-1 text-xs text-white transition-colors hover:bg-gray-700 dark:bg-dark-300 dark:hover:bg-dark-400`,children:o(`chatMessage.saveAndSubmit`)})]})]}):(0,Z.jsx)(`div`,{className:`rounded-2xl rounded-ee-md border border-black/[0.06] bg-gray-900 px-3.5 py-2 text-white shadow-sm dark:border-white/[0.07] dark:bg-dark-300`,children:(0,Z.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):p?(0,Z.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,Z.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,Z.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Z.jsx)(le,{className:`h-2.5 w-2.5 opacity-50`}),o(`chatMessage.system`)]}),(0,Z.jsx)(`div`,{className:`flex items-center gap-1`,children:S?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{onClick:ye,disabled:A,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.saveChanges`),children:(0,Z.jsx)(E,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,Z.jsx)(`button`,{onClick:be,disabled:A,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:o(`chatMessage.cancelEditing`),children:(0,Z.jsx)(W,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,Z.jsx)(`button`,{onClick:ve,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:o(`chatMessage.editSystemMessage`),children:(0,Z.jsx)(k,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),S?(0,Z.jsx)(`textarea`,{dir:`auto`,value:w,onChange:e=>T(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/[0.08] bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-none focus:ring-2 focus:ring-primary-500 dark:border-white/[0.08] dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:o(`chatMessage.systemMessagePlaceholder`),disabled:A}):(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:M?e.content:K(e.content)}),Ce&&(0,Z.jsx)(`button`,{onClick:()=>N(!M),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:M?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(me,{className:`h-3 w-3`}),o(`chatMessage.showLess`)]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(ge,{className:`h-3 w-3`}),o(`chatMessage.showMore`)]})})]})]}):(0,Z.jsxs)(`div`,{className:`relative`,children:[(V||ce)&&(0,Z.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,Z.jsxs)(`button`,{onClick:()=>P(!ee),className:`flex items-center gap-1.5 text-xs text-gray-500 transition-colors hover:text-gray-900 dark:text-dark-600 dark:hover:text-dark-900`,children:[(0,Z.jsx)(se,{className:f(`h-3.5 w-3.5`,ce&&`animate-pulse-subtle motion-reduce:animate-none`)}),ce?(0,Z.jsxs)(`span`,{className:`animate-shimmer bg-gradient-to-r from-gray-400 via-gray-900 to-gray-400 bg-[length:200%_100%] bg-clip-text font-medium text-transparent motion-reduce:animate-none motion-reduce:bg-none motion-reduce:text-gray-500 dark:from-dark-500 dark:via-dark-900 dark:to-dark-500 motion-reduce:dark:text-dark-600`,children:[o(`chatMessage.thinking`),`…`]}):(0,Z.jsx)(`span`,{className:`font-medium`,children:de===void 0?o(`chatMessage.thinking`):o(`chatMessage.thoughtFor`,{duration:pt(de)})}),ee?(0,Z.jsx)(me,{className:`h-3.5 w-3.5`}):(0,Z.jsx)(ge,{className:`h-3.5 w-3.5`})]}),ee&&V&&(0,Z.jsx)(`div`,{className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 dark:bg-dark-200/60`,children:(0,Z.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[13px] leading-relaxed text-gray-600 dark:text-dark-700`,children:V})})]}),(0,Z.jsx)(We,{content:U,isStreaming:t})]}),!l&&!p&&ue.length>0&&(0,Z.jsx)(`div`,{className:`mt-3`,children:(0,Z.jsx)($e,{artifacts:ue})}),!l&&!p&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,Z.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-400 dark:text-dark-500 rtl:tracking-normal`,children:o(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,Z.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,Z.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,Z.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!l&&!p&&e.statistics&&(0,Z.jsx)(`div`,{className:`mt-2`,children:(0,Z.jsx)(nt,{statistics:e.statistics})}),!p&&!t&&(0,Z.jsxs)(`div`,{className:f(`flex items-center gap-0.5 text-gray-400 dark:text-dark-500`,`sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,!l&&[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(te)?`sm:opacity-100`:`sm:opacity-0`,l?`mt-1 justify-end`:`mt-1`),children:[l&&(0,Z.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:d(e.timestamp,c.language),children:[_e(),` ·`,` `,d(e.timestamp,c.language)]}),!l&&U&&(0,Z.jsx)(ct,{text:U,size:`sm`,externalPlaybackState:te,onStopExternal:he,onRetryExternal:pe,className:f(`transition-colors`,te===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),l&&a&&!S&&(0,Z.jsx)(`button`,{onClick:()=>{T(e.content),C(!0)},className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.edit`),children:(0,Z.jsx)(k,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`button`,{onClick:oe,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(ne?`chatMessage.copied`:`chatMessage.copyMessage`),children:ne?(0,Z.jsx)(ae,{className:`h-3.5 w-3.5 text-green-500`}):(0,Z.jsx)(I,{className:`h-3.5 w-3.5`})}),!l&&(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`button`,{onClick:()=>Se(1),className:f(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===1&&`text-primary-600 dark:text-primary-400`),title:o(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,Z.jsx)(H,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,Z.jsx)(`button`,{onClick:()=>Se(-1),className:f(`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,e.rating===-1&&`text-red-500 dark:text-red-400`),title:o(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,Z.jsx)(L,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})})]}),!l&&r&&i&&(0,Z.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:o(`chatMessage.regenerateResponse`),children:(0,Z.jsx)(xe,{className:`h-3.5 w-3.5`})})]})]})]}),l&&(0,Z.jsx)(Zt,{role:`user`,user:h??null})]}),D&&(0,tt.createPortal)((0,Z.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":o(`chatMessage.fullSizeImage`),className:`fixed inset-0 z-[9999] flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>O(null),children:[(0,Z.jsx)(`button`,{className:`absolute end-6 top-6 rounded-full border border-white/15 bg-white/10 p-3 text-white transition-colors hover:bg-white/20`,onClick:e=>{e.stopPropagation(),O(null)},children:(0,Z.jsx)(W,{className:`h-7 w-7`})}),(0,Z.jsx)(`img`,{src:D,alt:o(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})},$t=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,en=220,tn=e=>{let t=e.slice(0,880).replace(/```(?:\w+)?\s*([\s\S]*?)```/g,`$1`).replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/<[^>]+>/g,` `).replace(/[#>*_~`|]/g,` `).replace(/\s+/g,` `).trim();return t.length>en?`${t.slice(0,219).trimEnd()}…`:t},nn=X.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,X.useRef)(null),a=(0,X.useRef)(null),o=(0,X.useRef)(new Map),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(0),p=(0,X.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),m=(0,X.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;!r||!i||(i.focus(),p(r.id,i),n(r.id))},[e,n,p]);if((0,X.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:$t()?`auto`:`smooth`})},[t]),e.length<3)return null;let h=Math.max(0,e.findIndex(e=>e.id===t)),g=e[h]?.id,_=e.findIndex(e=>e.id===c),v=_>=0?e[_]:null,y=_>=0?`conversation-history-preview-${_}`:void 0;return(0,Z.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`pointer-events-none absolute top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9`,style:{insetInlineStart:`max(0.25rem, calc(50% - 27rem))`},onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,Z.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===g,u=Math.abs(a-h),d=c===t.id?y:void 0;return(0,Z.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,Z.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===h?0:-1,className:f(`group flex h-4 w-7 items-center outline-none xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-sm`),onClick:()=>n(t.id),onPointerEnter:e=>p(t.id,e.currentTarget),onFocus:e=>p(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),m(n))},children:(0,Z.jsx)(`span`,{"aria-hidden":`true`,className:f(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),v&&(0,Z.jsx)(`div`,{id:y,role:`tooltip`,className:f(`pointer-events-none absolute start-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,Z.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,Z.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:tn(v.prompt)}),v.response&&(0,Z.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:tn(v.response)})]})})]})}),rn=({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:s,className:c})=>{if(e.length===1){let s=e[0],l=t&&i===s.id,u=l?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,Z.jsx)(Qt,{message:u,isStreaming:l,isLastAssistantMessage:a,onRegenerate:o,className:c})}return(0,Z.jsxs)(`div`,{className:f(`relative py-2`,c),children:[(0,Z.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,Z.jsx)(ue,{className:`h-3 w-3`}),(0,Z.jsxs)(`span`,{children:[e.length,` variants`]})]}),(0,Z.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,c)=>{let l=e.isActive!==!1,u=t&&i===e.id,d=u?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,Z.jsxs)(`div`,{className:f(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||u?`border-primary-500/30 ring-1 ring-primary-500/10 dark:border-primary-400/30`:`border-black/[0.07] hover:bg-white/80 dark:border-white/[0.07] dark:hover:bg-dark-200/70`,!l&&!u&&`cursor-pointer`),role:!l&&!u?`button`:void 0,tabIndex:!l&&!u?0:void 0,onClick:()=>!l&&!u&&s?.(e.id),onKeyDown:t=>{!l&&!u&&(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s?.(e.id))},children:[(0,Z.jsxs)(`div`,{className:f(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||u?`border-primary-500/10 bg-primary-50/50 text-primary-600 dark:border-primary-400/10 dark:bg-primary-900/10 dark:text-primary-400`:`border-black/[0.05] text-gray-400 dark:border-white/[0.05] dark:text-dark-500`),children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:c+1}),u&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:`generating...`})]}),l&&!u&&(0,Z.jsx)(ae,{className:`h-3 w-3`}),!l&&!u&&(0,Z.jsx)(`span`,{className:`text-[10px] opacity-50`,children:`select`})]}),(0,Z.jsx)(`div`,{className:f(!l&&!u&&`opacity-75`),children:(0,Z.jsx)(Qt,{message:d,isStreaming:u,isLastAssistantMessage:a&&(l||u),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 !text-sm`})})]},e.id)})})]})},an={web_search:M,web_fetch:T,exec:ye,browser:T,Read:G,Write:G,Edit:G,image:be,memory_search:O,memory_get:O,working:pe,thinking:pe,default:pe},on={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`},sn=({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,Z.jsx)(`div`,{className:f(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=an[e.name]||an.default,n=on[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,Z.jsxs)(`div`,{className:f(`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,Z.jsx)(`div`,{className:f(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,Z.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,Z.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,Z.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,Z.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,Z.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};K(`components:chat-messages`);var cn=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],ln=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,un=e=>Math.min(120,e*.28),dn=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],className:o,onRegenerate:c,onSelectBranch:l,onEditResend:u,followUpSuggestions:d,onFollowUpSelect:p})=>{let{t:m}=s(),h=(0,X.useRef)(null),g=(0,X.useRef)(void 0),_=(0,X.useRef)(null),v=(0,X.useRef)(null),y=(0,X.useRef)(new Map),b=(0,X.useRef)(null),x=(0,X.useRef)(0),S=(0,X.useRef)(!1),C=(0,X.useRef)(!1),[T,E]=(0,X.useState)(!1),D=(0,X.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]),O=(0,X.useMemo)(()=>{let e=[];for(let t=0;t<D.length;t++){let n=D[t],r=cn(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<D.length;e++){let t=cn(D[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},[D]),k=O.map(e=>e.id).join(``),A=(0,X.useMemo)(()=>k?k.split(``):[],[k]),j=(0,X.useMemo)(()=>new Set(A),[A]),[M,N]=(0,X.useState)(null),ee=(0,X.useCallback)(()=>{let e=_.current;if(!e||A.length===0){N(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(x.current,A.length-1);if(t<=2)n=A.length-1;else{let t=e.scrollTop+un(e.clientHeight);for(;n<A.length-1;){let e=y.current.get(A[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=y.current.get(A[n]);if(!e||e.offsetTop<=t)break;n--}}x.current=n;let r=A[n];N(e=>e===r?e:r)},[A]),P=(0,X.useCallback)(()=>{b.current===null&&(b.current=window.requestAnimationFrame(()=>{b.current=null,ee()}))},[ee]),te=(0,X.useCallback)(()=>{let t=_.current;if(g.current&&clearTimeout(g.current),S.current=!1,g.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;C.current=!n,E(!n&&e.length>0),P()},[e.length,P]),ne=(0,X.useCallback)(()=>{g.current&&clearTimeout(g.current),g.current=setTimeout(te,180)},[te]),I=(0,X.useCallback)((e=!1)=>{C.current&&!e||h.current?.scrollIntoView({behavior:ln()})},[]),L=(0,X.useCallback)(()=>{let t=_.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;if(S.current){C.current=!0,E(!o&&e.length>0),P(),ne();return}C.current=!o,E(!o&&e.length>0),a<=2&&A.length>0?(x.current=A.length-1,N(A[A.length-1])):P()},[A,e.length,ne,P]),re=(0,X.useCallback)(e=>{let t=_.current,n=y.current.get(e);if(!t||!n)return;let r=ln();S.current=!0,C.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-un(t.clientHeight)),behavior:r}),P(),r===`auto`?te():ne()},[te,ne,P]),R=(0,X.useRef)(e.length);if((0,X.useEffect)(()=>{e.length>R.current&&!C.current&&I(),R.current=e.length},[e.length,I]),(0,X.useEffect)(()=>{i&&(t||n)&&!C.current&&requestAnimationFrame(()=>{let e=_.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,X.useEffect)(()=>{P();let e=v.current,t=_.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(P);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,P),()=>{n?.disconnect(),window.removeEventListener(`resize`,P)}},[k,P]),(0,X.useEffect)(()=>()=>{b.current!==null&&(window.cancelAnimationFrame(b.current),b.current=null)},[]),(0,X.useEffect)(()=>()=>{g.current&&clearTimeout(g.current)},[]),e.length===0&&!i)return(0,Z.jsx)(`div`,{className:f(`flex-1 flex items-center justify-center p-6 sm:p-10`,o),children:(0,Z.jsxs)(`div`,{className:`max-w-sm text-center text-gray-500 dark:text-dark-600`,children:[(0,Z.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,Z.jsx)(w,{className:`h-4 w-4`})}),(0,Z.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:m(`chatMessage.startConversation`)}),(0,Z.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:m(`chatMessage.startConversationDescription`)})]})});let z=-1;for(let e=D.length-1;e>=0;e--)if(D[e].messages.some(e=>e.role===`assistant`)){z=e;break}return(0,Z.jsxs)(`div`,{className:f(`relative min-h-0 flex-1`,o),style:{WebkitAppRegion:`no-drag`},children:[(0,Z.jsx)(`div`,{ref:_,"data-testid":`chat-scroll-viewport`,onScroll:L,className:f(`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,Z.jsxs)(`div`,{ref:v,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8`,children:[D.map((e,a)=>{let o=a===z,s=j.has(e.id),d=i&&e.messages.some(e=>e.id===r),f;if(e.messages.length===1){let s=e.messages[0],l=i&&s.id===r,d=l?{...s,content:t??s.content,thinking:n||s.thinking}:s;f=(0,Z.jsx)(Qt,{message:d,isStreaming:l,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onEditResend:i?void 0:u,className:a===0?`mt-3 sm:mt-4`:``})}else f=(0,Z.jsx)(rn,{messages:e.messages,isStreaming:d,streamingMessage:t,streamingThinking:n,streamingMessageId:r||void 0,isLastAssistantMessage:o,onRegenerate:o?c:void 0,onSelectBranch:l,className:a===0?`mt-3 sm:mt-4`:``});return(0,Z.jsx)(`div`,{ref:t=>{s&&(t?y.current.set(e.id,t):y.current.delete(e.id))},"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:f},e.id)}),i&&a.length>0&&(0,Z.jsx)(sn,{tools:a,className:`px-0`}),!i&&d&&d.length>0&&p&&(0,Z.jsxs)(`div`,{className:`mt-1 pb-2`,children:[(0,Z.jsx)(`p`,{className:`mb-1 text-[11px] font-semibold uppercase tracking-[0.08em] text-gray-500 dark:text-dark-500`,children:m(`chat.followUp`)}),(0,Z.jsx)(`div`,{className:`flex flex-col`,children:d.map(e=>(0,Z.jsx)(`button`,{onClick:()=>p(e),dir:`auto`,className:`border-t border-gray-100 py-2 text-start text-[0.9rem] leading-relaxed text-gray-600 transition-colors hover:text-gray-900 dark:border-dark-200 dark:text-dark-600 dark:hover:text-dark-900`,children:e},e))})]}),(0,Z.jsx)(`div`,{ref:h,className:`h-4 sm:h-6`})]})}),(0,Z.jsx)(nn,{items:O,activeId:M,onSelect:re}),T&&(0,Z.jsxs)(`button`,{onClick:()=>{S.current=!1,g.current&&(clearTimeout(g.current),g.current=void 0),C.current=!1,h.current?.scrollIntoView({behavior:ln()}),E(!1)},className:f(`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:m(`chatMessage.scrollToBottom`),children:[(0,Z.jsx)(F,{className:`h-4 w-4`}),(0,Z.jsx)(`span`,{className:`text-xs font-medium`,children:m(`chatMessage.newMessages`)})]})]})};function fn(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 pn=X.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,X.useMemo)(()=>fn(e),[e]);return(0,Z.jsxs)(`div`,{className:`relative w-full`,children:[(0,Z.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:f(`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,Z.jsx)(`div`,{className:`absolute end-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,Z.jsxs)(`div`,{className:f(`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,Z.jsx)(x,{className:`h-3 w-3`}),d&&(0,Z.jsx)(`span`,{children:d}),!d&&u&&(0,Z.jsx)(`span`,{children:`code`})]})})]})});pn.displayName=`CodeAwareTextarea`;var mn=K(`components:media-upload`),hn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,X.useRef)(null),[u,d]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)([]),_=async e=>{if(!(!e||a))for(let t=0;t<e.length;t++){let n=e[t];n.type.startsWith(`image/`)?await v(n):n.type.includes(`pdf`)||n.type.includes(`text`)?await y(n):U.error(`File type not supported: ${n.name}`)}},v=async r=>{if(n-e.length<=0){U.error(`Maximum ${n} images allowed`);return}if(r.size>10485760){U.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>10485760){U.error(`File size must be less than 10MB`);return}m(!0);try{let t=await we.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;g(e=>[...e,n]),i?.(n),U.success(`Document "${e.name}" uploaded`)}else U.error(t.error||`Failed to upload document`)}catch(e){mn.error(`Document upload error:`,e),U.error(`Failed to upload document`)}finally{m(!1)}},b=e=>{e.preventDefault(),a||d(!0)},x=e=>{e.preventDefault(),d(!1)},S=e=>{e.preventDefault(),d(!1),a||_(e.dataTransfer.files)},C=n=>{t(e.filter((e,t)=>t!==n))},w=async e=>{try{let t=await we.deleteDocument(e);t.success?(g(t=>t.filter(t=>t.id!==e)),U.success(`Document removed`)):U.error(t.error||`Failed to remove document`)}catch(e){mn.error(`Error removing document:`,e),U.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]},E=e.length>0||h.length>0;return(0,Z.jsxs)(`div`,{className:f(`space-y-3`,o),children:[(0,Z.jsxs)(`div`,{className:f(`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,Z.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{_(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,Z.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[p?(0,Z.jsx)(V,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`}):(0,Z.jsx)(oe,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,Z.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,Z.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,Z.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-gray-400 mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),E&&(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,Z.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,Z.jsx)(`img`,{src:e,alt:`Upload ${t+1}`,className:`w-full h-full object-cover`}),(0,Z.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,Z.jsx)(W,{className:`h-3 w-3`})})]},`img-${t}`)),h.map(e=>(0,Z.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,Z.jsx)(G,{className:`w-4 h-4 text-red-500 flex-shrink-0`}):(0,Z.jsx)(ee,{className:`w-4 h-4 text-blue-500 flex-shrink-0`}),(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,Z.jsx)(`p`,{className:`text-[10px] text-gray-500 dark:text-gray-400`,children:T(e.size)})]}),(0,Z.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,Z.jsx)(W,{className:`h-3 w-3`})})]},e.id))]})]})},gn=K(`components:document-indicator`),_n=({sessionId:e,className:t=``})=>{let{t:n}=s(),[r,i]=(0,X.useState)([]),[a,o]=(0,X.useState)(!1),[c,u]=(0,X.useState)(null),d=(0,X.useRef)(null),f=(0,X.useCallback)(async()=>{try{let t=await we.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){gn.error(`Failed to load documents:`,e)}},[e]);if((0,X.useEffect)(()=>{f();let e=()=>void f();return window.addEventListener(`libre:documents-updated`,e),()=>window.removeEventListener(`libre:documents-updated`,e)},[f]),(0,X.useEffect)(()=>{if(!a)return;let e=e=>{d.current?.contains(e.target)||(o(!1),u(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let p=async e=>{u(null);try{let t=await we.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){gn.error(`Failed to delete document:`,e),S.error(n(`settings.documents.library.deleteFailed`))}},m=r.reduce((e,t)=>e+t.size,0);return(0,Z.jsxs)(`div`,{ref:d,className:`relative inline-block ${t}`,children:[a&&(0,Z.jsxs)(`div`,{className:`absolute bottom-full left-0 z-50 mb-2 w-80 max-w-[85vw] rounded-xl border border-gray-200 bg-white p-2 shadow-lg dark:border-dark-300 dark:bg-dark-100`,children:[(0,Z.jsx)(`p`,{className:`px-2 pb-1.5 pt-1 text-xs font-medium text-gray-500 dark:text-dark-600`,children:n(`chat.documents.title`)}),(0,Z.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,Z.jsx)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 hover:bg-gray-50 dark:hover:bg-dark-200`,children:c===e.id?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`p`,{className:`min-w-0 flex-1 truncate text-xs text-red-700 dark:text-red-300`,children:n(`settings.documents.library.deleteConfirm`,{name:e.filename})}),(0,Z.jsx)(`button`,{onClick:()=>void p(e.id),className:`shrink-0 text-xs font-medium text-red-600 underline underline-offset-2 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,children:n(`common.delete`)}),(0,Z.jsx)(`button`,{onClick:()=>u(null),className:`shrink-0 text-xs text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,children:n(`common.cancel`)})]}):(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(G,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`p`,{className:`truncate text-xs text-gray-900 dark:text-dark-900`,children:e.filename}),(0,Z.jsxs)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:[l(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,Z.jsx)(`button`,{onClick:()=>u(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,Z.jsx)(W,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),u(null)},className:`
|
|
4
4
|
inline-flex items-center space-x-1 px-2 py-1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./useTranslation-C3ei3mJq.js";import{An as i,Cn as a,Et as o,Ut as s,Wt as c,Xt as l,dn as u,gt as d,k as f,l as p,p as m,t as h}from"./ui-vendor-54SgntkX.js";import{t as g}from"./logger-DSXjF4ye.js";import{D as _}from"./api-DSzsasYT.js";import{n as v}from"./authStore-CnSn5zM7.js";import{g as y,h as b,i as x,n as S,r as C}from"../assets/index-CudKJ5Bs.js";var w=e(t(),1),T=n(),E=g(`components:first-time-setup`),D=({onComplete:e})=>{let{t}=r(),[n,g]=(0,w.useState)(`welcome`),[D,O]=(0,w.useState)(``),[k,ee]=(0,w.useState)(``),[A,j]=(0,w.useState)(``),[M,N]=(0,w.useState)(!1),[P,F]=(0,w.useState)(!1),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(null),[B,V]=(0,w.useState)(!1),[H,U]=(0,w.useState)(!1),[W,G]=(0,w.useState)(``),{login:K,systemInfo:q}=v(),J=q?.turnstile?.siteKey,Y=!!(q?.turnstile?.enabled&&J),X=(0,w.useCallback)(e=>{G(e)},[]),Z=(0,w.useMemo)(()=>I||Y&&!W,[I,Y,W]);(0,w.useEffect)(()=>{n===`encryption-key`&&!R&&_.getEncryptionKey().then(e=>{e.success&&e.data&&z(e.data.encryptionKey)})},[n,R]);let Q=async e=>{if(e.preventDefault(),!D.trim()||!k.trim()||!A.trim()){i.error(t(`setup.admin.fillAllFields`));return}if(k!==A){i.error(t(`auth.signup.passwordMismatch`));return}let n=C(k);if(n){i.error(n);return}if(Y&&!W){i.error(t(`auth.signup.tryAgain`));return}L(!0);try{let e=await _.signup({username:D,password:k,email:``,turnstileToken:W});if(e.success&&e.data){if(!(`token`in e.data)){i.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}K(e.data.user,e.data.token,e.data.systemInfo),i.success(t(`setup.admin.success`)),g(`encryption-key`)}else i.error(e.message||t(`setup.admin.failed`))}catch(e){E.error(`Admin creation error:`,e),i.error(t(`setup.admin.failed`))}finally{G(``),L(!1)}},te=async()=>{if(R)try{await navigator.clipboard.writeText(R),V(!0),i.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>V(!1),3e3)}catch{i.error(t(`setup.encryptionKey.copyFailed`))}},ne=()=>{if(!H){i.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,T.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,T.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]})}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.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,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.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,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,T.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,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(f,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(h,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,T.jsx)(`button`,{onClick:()=>g(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,T.jsx)(a,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,T.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,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]}),(0,T.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,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,T.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,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,T.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsx)(d,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,T.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,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,T.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,T.jsx)(m,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,T.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,T.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,T.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,T.jsxs)(`div`,{className:`mb-6`,children:[(0,T.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:R||t(`setup.encryptionKey.loading`)}),(0,T.jsx)(`button`,{type:`button`,onClick:te,disabled:!R,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:B?(0,T.jsx)(u,{className:`h-5 w-5 text-green-500`}):(0,T.jsx)(l,{className:`h-5 w-5`})})]}),(0,T.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,T.jsx)(`div`,{className:`mb-6`,children:(0,T.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>U(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,T.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,T.jsx)(`button`,{onClick:ne,disabled:!H,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,T.jsx)(a,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,T.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,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]}),(0,T.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,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.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,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.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,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,T.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.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,T.jsx)(`input`,{id:`username`,type:`text`,value:D,onChange:e=>O(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:I})]}),(0,T.jsxs)(`div`,{children:[(0,T.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,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`password`,type:M?`text`:`password`,value:k,onChange:e=>ee(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:I}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:M?(0,T.jsx)(c,{size:20}):(0,T.jsx)(s,{size:20})})]}),(0,T.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:S})]}),(0,T.jsxs)(`div`,{children:[(0,T.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,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`confirmPassword`,type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:I}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:P?(0,T.jsx)(c,{size:20}):(0,T.jsx)(s,{size:20})})]})]}),Y&&J&&(0,T.jsx)(x,{siteKey:J,action:`signup`,disabled:I,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:X}),(0,T.jsxs)(`div`,{className:`flex gap-3`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>g(`welcome`),disabled:I,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,T.jsx)(`button`,{type:`submit`,disabled:Z,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:I?(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(p,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,T.jsx)(`div`,{className:`mt-6 text-center`,children:(0,T.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{D as FirstTimeSetup};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{t as r}from"./useTranslation-C3ei3mJq.js";import{An as i,Cn as a,Et as o,Ut as s,Wt as c,Xt as l,dn as u,gt as d,k as f,l as p,p as m,t as h}from"./ui-vendor-54SgntkX.js";import{t as g}from"./logger-DSXjF4ye.js";import{D as _}from"./api-Dw_IuHaz.js";import{n as v}from"./authStore-CwSMGkEM.js";import{g as y,h as b,i as x,n as S,r as C}from"../assets/index-BXMQqOXF.js";var w=e(t(),1),T=n(),E=g(`components:first-time-setup`),D=({onComplete:e})=>{let{t}=r(),[n,g]=(0,w.useState)(`welcome`),[D,O]=(0,w.useState)(``),[k,ee]=(0,w.useState)(``),[A,j]=(0,w.useState)(``),[M,N]=(0,w.useState)(!1),[P,F]=(0,w.useState)(!1),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(null),[B,V]=(0,w.useState)(!1),[H,U]=(0,w.useState)(!1),[W,G]=(0,w.useState)(``),{login:K,systemInfo:q}=v(),J=q?.turnstile?.siteKey,Y=!!(q?.turnstile?.enabled&&J),X=(0,w.useCallback)(e=>{G(e)},[]),Z=(0,w.useMemo)(()=>I||Y&&!W,[I,Y,W]);(0,w.useEffect)(()=>{n===`encryption-key`&&!R&&_.getEncryptionKey().then(e=>{e.success&&e.data&&z(e.data.encryptionKey)})},[n,R]);let Q=async e=>{if(e.preventDefault(),!D.trim()||!k.trim()||!A.trim()){i.error(t(`setup.admin.fillAllFields`));return}if(k!==A){i.error(t(`auth.signup.passwordMismatch`));return}let n=C(k);if(n){i.error(n);return}if(Y&&!W){i.error(t(`auth.signup.tryAgain`));return}L(!0);try{let e=await _.signup({username:D,password:k,email:``,turnstileToken:W});if(e.success&&e.data){if(!(`token`in e.data)){i.error(t(`setup.admin.approvalUnexpected`,`The initial administrator could not be activated. Please try again.`));return}K(e.data.user,e.data.token,e.data.systemInfo),i.success(t(`setup.admin.success`)),g(`encryption-key`)}else i.error(e.message||t(`setup.admin.failed`))}catch(e){E.error(`Admin creation error:`,e),i.error(t(`setup.admin.failed`))}finally{G(``),L(!1)}},te=async()=>{if(R)try{await navigator.clipboard.writeText(R),V(!0),i.success(t(`setup.encryptionKey.copied`)),setTimeout(()=>V(!1),3e3)}catch{i.error(t(`setup.encryptionKey.copyFailed`))}},ne=()=>{if(!H){i.error(t(`setup.encryptionKey.confirmRequired`));return}e?.()},$=e=>{if(e.key===`Enter`){let t=e.currentTarget.form;t&&t.requestSubmit()}};return n===`welcome`?(0,T.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,T.jsx)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]})}),(0,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.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,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.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,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.description`)})]}),(0,T.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,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(f,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.secure.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.secure.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(h,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.fast.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.fast.description`)})]})]}),(0,T.jsxs)(`div`,{className:`flex items-start gap-3 py-4`,children:[(0,T.jsx)(`div`,{className:`flex-shrink-0 mt-1`,children:(0,T.jsx)(o,{className:`h-5 w-5 text-primary-600 dark:text-primary-400`})}),(0,T.jsxs)(`div`,{children:[(0,T.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-dark-950`,children:t(`setup.welcome.features.openSource.title`)}),(0,T.jsx)(`p`,{className:`text-sm text-gray-600 dark:text-dark-500`,children:t(`setup.welcome.features.openSource.description`)})]})]})]}),(0,T.jsx)(`button`,{onClick:()=>g(`create-admin`),className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.welcome.createAdmin`)}),(0,T.jsx)(a,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):n===`encryption-key`?(0,T.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,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]}),(0,T.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,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-lg`,children:(0,T.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,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.jsx)(`div`,{className:`flex justify-center mb-4`,children:(0,T.jsx)(`div`,{className:`rounded-xl border border-amber-200 bg-amber-500/10 p-3 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsx)(d,{className:`h-8 w-8 text-amber-600 dark:text-amber-400`})})}),(0,T.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,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.encryptionKey.description`)})]}),(0,T.jsx)(`div`,{className:`mb-6 rounded-xl border border-amber-200 bg-amber-500/10 p-4 dark:border-amber-800/60 dark:bg-amber-900/20`,children:(0,T.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,T.jsx)(m,{className:`h-5 w-5 text-amber-600 dark:text-amber-400 flex-shrink-0 mt-0.5`}),(0,T.jsxs)(`div`,{className:`text-sm text-ink`,children:[(0,T.jsx)(`p`,{className:`font-medium mb-1`,children:t(`setup.encryptionKey.warning`)}),(0,T.jsx)(`p`,{children:t(`setup.encryptionKey.warningText`)})]})]})}),(0,T.jsxs)(`div`,{className:`mb-6`,children:[(0,T.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-dark-700 mb-2`,children:t(`setup.encryptionKey.label`)}),(0,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`div`,{className:`w-full break-all rounded-xl border border-gray-200 bg-gray-50 px-3 py-3 pe-12 font-mono text-sm text-gray-900 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800`,children:R||t(`setup.encryptionKey.loading`)}),(0,T.jsx)(`button`,{type:`button`,onClick:te,disabled:!R,className:`absolute end-2 top-1/2 -translate-y-1/2 p-2 text-gray-500 hover:text-gray-700 disabled:opacity-50 dark:text-dark-500 dark:hover:text-dark-700`,title:t(`setup.encryptionKey.copyToClipboard`),children:B?(0,T.jsx)(u,{className:`h-5 w-5 text-green-500`}):(0,T.jsx)(l,{className:`h-5 w-5`})})]}),(0,T.jsx)(`p`,{className:`mt-2 text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.encryptionKey.envNote`)})]}),(0,T.jsx)(`div`,{className:`mb-6`,children:(0,T.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3`,children:[(0,T.jsx)(`input`,{type:`checkbox`,checked:H,onChange:e=>U(e.target.checked),className:`mt-1 h-4 w-4 text-primary-600 focus:ring-primary-500 border-gray-300 dark:border-dark-300 rounded`}),(0,T.jsx)(`span`,{className:`text-sm text-gray-700 dark:text-dark-700`,children:t(`setup.encryptionKey.acknowledgment`)})]})}),(0,T.jsx)(`button`,{onClick:ne,disabled:!H,className:`flex min-h-11 w-full items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`span`,{children:t(`setup.encryptionKey.continue`)}),(0,T.jsx)(a,{size:16,className:`ms-2 rtl:rotate-180`})]})})]})})]}):(0,T.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,T.jsxs)(`div`,{className:`sm:mx-auto sm:w-full sm:max-w-md`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-center gap-2.5 text-gray-900 dark:text-gray-100`,children:[(0,T.jsx)(b,{size:`md`,label:null}),(0,T.jsx)(y,{})]}),(0,T.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,T.jsx)(`div`,{className:`mt-10 sm:mx-auto sm:w-full sm:max-w-md`,children:(0,T.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,T.jsxs)(`div`,{className:`mb-7 text-start`,children:[(0,T.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,T.jsx)(`p`,{className:`text-gray-600 dark:text-dark-500`,children:t(`setup.admin.description`)})]}),(0,T.jsxs)(`form`,{onSubmit:Q,className:`space-y-4`,children:[(0,T.jsxs)(`div`,{children:[(0,T.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,T.jsx)(`input`,{id:`username`,type:`text`,value:D,onChange:e=>O(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.usernamePlaceholder`),required:!0,disabled:I})]}),(0,T.jsxs)(`div`,{children:[(0,T.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,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`password`,type:M?`text`:`password`,value:k,onChange:e=>ee(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.passwordPlaceholder`),required:!0,disabled:I}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>N(!M),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:M?(0,T.jsx)(c,{size:20}):(0,T.jsx)(s,{size:20})})]}),(0,T.jsx)(`p`,{className:`mt-1.5 text-xs text-gray-500 dark:text-dark-500`,children:S})]}),(0,T.jsxs)(`div`,{children:[(0,T.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,T.jsxs)(`div`,{className:`relative`,children:[(0,T.jsx)(`input`,{id:`confirmPassword`,type:P?`text`:`password`,value:A,onChange:e=>j(e.target.value),onKeyDown:$,className:`w-full rounded-xl border border-gray-200 bg-white/80 px-3 py-2.5 pe-10 text-gray-900 transition-colors duration-200 focus:border-primary-500 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.04] dark:text-dark-800`,placeholder:t(`setup.admin.confirmPlaceholder`),required:!0,disabled:I}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>F(!P),className:`absolute inset-y-0 end-0 flex items-center pe-3 text-gray-400 hover:text-gray-600 dark:text-dark-500 dark:hover:text-dark-700`,disabled:I,children:P?(0,T.jsx)(c,{size:20}):(0,T.jsx)(s,{size:20})})]})]}),Y&&J&&(0,T.jsx)(x,{siteKey:J,action:`signup`,disabled:I,errorMessage:t(`auth.signup.tryAgain`),onTokenChange:X}),(0,T.jsxs)(`div`,{className:`flex gap-3`,children:[(0,T.jsx)(`button`,{type:`button`,onClick:()=>g(`welcome`),disabled:I,className:`min-h-11 flex-1 rounded-xl border border-gray-200 bg-transparent px-4 py-2.5 text-sm font-medium text-gray-700 transition-colors duration-200 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-white/10 dark:text-dark-700 dark:hover:bg-white/[0.06]`,children:t(`common.back`)}),(0,T.jsx)(`button`,{type:`submit`,disabled:Z,className:`flex min-h-11 flex-1 items-center justify-center rounded-xl border border-transparent bg-primary-600 px-4 py-2.5 text-sm font-medium text-white transition-colors duration-200 hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50`,children:I?(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(`div`,{className:`me-2 h-4 w-4 animate-spin rounded-full border-b-2 border-white`}),t(`setup.admin.creating`)]}):(0,T.jsxs)(`div`,{className:`flex items-center`,children:[(0,T.jsx)(p,{size:16,className:`me-2`}),t(`setup.admin.createAdmin`)]})})]})]}),(0,T.jsx)(`div`,{className:`mt-6 text-center`,children:(0,T.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:t(`setup.admin.note`)})})]})})]})};export{D as FirstTimeSetup};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{t as i}from"./useTranslation-C3ei3mJq.js";import{t as a}from"./utils-CuC1beTY.js";import{An as o,E as s,It as c,Yt as l,bt as u,ct as d,ft as f,h as p,n as m,o as h,qt as g,tn as _,yt as v}from"./ui-vendor-54SgntkX.js";import{t as y}from"./logger-DSXjF4ye.js";import{g as b,v as x}from"./api-DSzsasYT.js";import{i as ee,n as te,r as S,s as C}from"./imageGenModels-Dx_QMLJQ.js";import{t as ne}from"./appStore-CYhqdjge.js";import{t as w}from"./Button-BV44cTnj.js";import{n as T,t as E}from"./ui-CUMAcARd.js";import{C as D,b as O,v as k,w as A,x as re,y as j}from"../assets/index-CudKJ5Bs.js";var M=class extends re{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:D(t,n.data),hasPreviousPage:A(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function N(e,t){return j(e,M,t)}var P=e(t(),1),ie=r(),F=n(),I=y(`components:image-generation-panel`);function ae(e,t={}){let n=e.config?.sizes&&e.config.sizes.length>0?e.config.sizes:[t.size||e.config?.default_size||`1024x1024`],r=e.config?.qualities&&e.config.qualities.length>0?e.config.qualities:e.config?.omit_quality_when_empty?[]:[t.quality||e.config?.default_quality||`standard`],i=e.config?.styles&&e.config.styles.length>0?e.config.styles:[];return{pluginId:e.id,model:C(e.models,t.model,void 0,``),size:C(n,t.size,e.config?.default_size,`1024x1024`),quality:r.length>0?C(r,t.quality,e.config?.default_quality,`standard`):``,style:i.length>0?C(i,t.style,e.config?.default_style,i[0]):``,sizes:n,qualities:r,styles:i,maxPromptLength:e.config?.max_prompt_length??null,sizeLabel:e.config?.size_label||``}}var oe=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=i(),c=ne(e=>e.preferences.imageGenSettings),l=c?.enabled===!0,[u,d]=(0,P.useState)([]),[f,p]=(0,P.useState)(``),[h,_]=(0,P.useState)(``),[y,b]=(0,P.useState)(``),[C,T]=(0,P.useState)(`1024x1024`),[E,D]=(0,P.useState)(`standard`),[O,k]=(0,P.useState)(``),[A,re]=(0,P.useState)(!1),[j,M]=(0,P.useState)(null),N=(0,P.useRef)(null),[oe,se]=(0,P.useState)([`512x512`,`768x768`,`1024x1024`]),[L,R]=(0,P.useState)([`standard`,`high`]),[z,ce]=(0,P.useState)([]),[B,le]=(0,P.useState)(null),[V,ue]=(0,P.useState)(``),H=P.useId(),U=(0,P.useCallback)((e,t)=>{let n=ae(e,t);p(n.pluginId),_(n.model),T(n.size),D(n.quality),k(n.style),se(n.sizes),R(n.qualities),ce(n.styles),le(n.maxPromptLength),ue(n.sizeLabel)},[]);(0,P.useEffect)(()=>{let t=!1;return e&&l&&(async()=>{try{let e=await x.getPlugins();if(t)return;let n=e.success&&e.data?e.data.filter(e=>e.models.length>0):[];d(n);let r=te(n,c);r?U(r,c):(p(``),_(``))}catch(e){if(t)return;d([]),p(``),_(``),I.error(`Failed to load image generation plugins:`,e)}})(),()=>{t=!0}},[U,l,e,c]),(0,P.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]),(0,P.useEffect)(()=>()=>{N.current?.abort(),N.current=null},[]),(0,P.useEffect)(()=>{e||N.current?.abort()},[e]);let W=()=>{N.current?.abort(),t()},de=e=>{let t=u.find(t=>t.id===e);t&&U(t,{model:h,size:C,quality:E,style:O})},G=async()=>{if(!l||!f||!h||!y.trim()){o.error(r(`imageGeneration.enterPrompt`));return}if(B&&y.length>B){o.error(r(`imageGeneration.promptTooLong`,{max:B.toLocaleString()}));return}let e=new AbortController;N.current?.abort(),N.current=e,re(!0),M(null);try{let i=await x.generate({model:h,pluginId:f,prompt:y.trim(),size:C,quality:E,...O?{style:O}:{}},e.signal);if(e.signal.aborted)return;if(i.success&&i.data?.images&&i.data.images.length>0){let e=ee(i.data.images[0]);e&&(o.success(r(`imageGeneration.success`)),n?(n(e,y.trim(),h),b(``),M(null),t()):M(e))}else o.error(r(`imageGeneration.failed`))}catch(t){if(e.signal.aborted)return;I.error(`Image generation failed:`,t);let n=t instanceof Error?t.message:r(`imageGeneration.failed`);o.error(n)}finally{N.current===e&&(N.current=null,re(!1))}},fe=()=>{N.current?.abort()},pe=()=>{if(!j)return;let e=document.createElement(`a`);e.href=j,e.download=`generated-image-${Date.now()}.${S(j)}`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e||!l)return null;let me=u.find(e=>e.id===f);return(0,ie.createPortal)((0,F.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":H,children:[(0,F.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:W}),(0,F.jsxs)(`div`,{className:a(`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,F.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,F.jsx)(`div`,{children:(0,F.jsx)(`h2`,{id:H,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,F.jsx)(`button`,{onClick:W,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,F.jsx)(m,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,F.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 p-5 scrollbar-thin sm:p-6`,children:me?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,F.jsx)(`select`,{value:f,onChange:e=>de(e.target.value),className:a(`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:u.map(e=>(0,F.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,F.jsx)(`select`,{value:h,onChange:e=>_(e.target.value),className:a(`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:me?.models.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))})]}),z.length>0&&(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.style`)}),(0,F.jsx)(`select`,{value:O,onChange:e=>k(e.target.value),className:a(`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:z.map(e=>(0,F.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,F.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:V||r(`imageGeneration.size`)}),(0,F.jsx)(`select`,{value:C,onChange:e=>T(e.target.value),className:a(`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:oe.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))})]}),L.length>0&&(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,F.jsx)(`select`,{value:E,onChange:e=>D(e.target.value),className:a(`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:L.map(e=>(0,F.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,F.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:a(`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`,B&&y.length>B&&`border-red-500 dark:border-red-500`)}),B&&(0,F.jsxs)(`div`,{className:a(`mt-1 text-end text-xs`,y.length>B?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[y.length.toLocaleString(),` /`,` `,B.toLocaleString()]})]}),j&&(0,F.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,F.jsx)(`img`,{src:j,alt:`Generated`,className:`w-full h-auto`}),(0,F.jsx)(`button`,{onClick:pe,className:a(`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,F.jsx)(g,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]}):(0,F.jsxs)(`div`,{className:`text-center py-8`,children:[(0,F.jsx)(v,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,F.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,F.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]})}),me&&(0,F.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,F.jsx)(w,{onClick:A?fe:G,disabled:!A&&(!l||!y.trim()||!f||!h),className:a(`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:A?(0,F.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,F.jsx)(m,{className:`h-4 w-4`}),r(`common.cancel`)]}):(0,F.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,F.jsx)(s,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},se={video:[],audio:[]};function L({isOpen:e,initialKind:t,onClose:n,onGenerated:r}){let{t:l}=i(),u=O(),[d,p]=(0,P.useState)(t),[g,_]=(0,P.useState)(se),[v,y]=(0,P.useState)(``),[x,ee]=(0,P.useState)(``),[te,S]=(0,P.useState)(``),[C,ne]=(0,P.useState)(!1),[T,E]=(0,P.useState)(null),[D,k]=(0,P.useState)(``),[A,re]=(0,P.useState)(!1),[j,M]=(0,P.useState)(``),[N,I]=(0,P.useState)(!1),[ae,oe]=(0,P.useState)(0),[L,ue]=(0,P.useState)(``),[H,U]=(0,P.useState)(``),[W,de]=(0,P.useState)(``),[G,fe]=(0,P.useState)(!0),[pe,me]=(0,P.useState)(!0),[K,he]=(0,P.useState)(!1),[ge,_e]=(0,P.useState)([]),q=(0,P.useRef)(null),ve=P.useId(),J=()=>{ne(!1),E(null),k(``),re(!1),M(``),I(!1),oe(e=>e+1)},ye=()=>{q.current?.abort(),J(),n()};(0,P.useEffect)(()=>()=>{q.current?.abort(),q.current=null},[]),(0,P.useEffect)(()=>{e||q.current?.abort()},[e]),(0,P.useEffect)(()=>{if(!e)return;let t=!1;return b.getModels().then(e=>{t||!e.success||!e.data||_(e.data)}).catch(()=>{t||o.error(l(`mediaGeneration.loadFailed`))}).finally(()=>{t||me(!1)}),()=>{t=!0}},[e,l]),(0,P.useEffect)(()=>{if(!e)return;let t=!1;return b.listVideoJobs({limit:100,active:!0}).then(e=>{!t&&e.success&&e.data&&_e(e.data.jobs)}).catch(()=>{t||o.error(l(`mediaGeneration.jobsLoadFailed`,{defaultValue:`Failed to load saved video jobs`}))}),()=>{t=!0}},[e,l]);let Y=d===`video`?g.video:g.audio,be=ge.filter(e=>e.status!==`completed`),xe=Y.some(e=>z(e)===v)?v:Y[0]?z(Y[0]):``,X=(0,P.useMemo)(()=>Y.find(e=>z(e)===xe),[xe,Y]),Z=d===`video`?X?.config:void 0,Q=d===`audio`?X:void 0,Se=!!(Q?.mode===`speech`&&Q.config?.supports_voice_cloning),Ce=!!Q?.config?.clone_requires_transcript,$=Se&&C,we=!!(Q?.mode!==`speech`||Q.config?.allows_custom_voice!==!1||Q.config?.voices?.length),Te=Q?.mode===`speech`?Q.config?.max_characters:void 0,Ee=async(e,t,n,r=0)=>{if(e.status!==`pending`&&e.status!==`in_progress`)return e;n&&await ce(3e4,t.signal);try{let n=await b.resumeVideoJob(e.id,t.signal);if(!n.success||!n.data)throw Error(n.message||l(`mediaGeneration.failed`));let r=n.data;return _e(e=>[r,...e.filter(e=>e.id!==r.id)]),Ee(r,t,!0)}catch(n){if(t.signal.aborted||r>=4)throw n;return Ee(e,t,!0,r+1)}},De=async e=>{let t=new AbortController;q.current?.abort(),q.current=t,he(!0);try{let n=await Ee(e,t,!1);if(t.signal.aborted)return;if(n.status===`failed`)throw Error(n.error||l(`mediaGeneration.failed`));o.success(l(`mediaGeneration.success`)),r()}catch(e){if(t.signal.aborted)return;o.error(e instanceof Error?e.message:l(`mediaGeneration.failed`))}finally{q.current===t&&(q.current=null,he(!1))}},Oe=async e=>{try{let t=await b.cancelVideoJob(e.id);if(!t.success)throw Error(t.message||l(`mediaGeneration.failed`));_e(t=>t.filter(t=>t.id!==e.id)),o.success(l(`mediaGeneration.jobCancelled`,{defaultValue:`Video job cancelled at the provider`}))}catch(e){o.error(e instanceof Error?e.message:l(`mediaGeneration.failed`))}};return e?(0,ie.createPortal)((0,F.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,children:[(0,F.jsx)(`button`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:ye,"aria-label":l(`common.close`)}),(0,F.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":ve,className:`relative flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-gray-200/80 bg-white/95 shadow-2xl backdrop-blur-xl dark:border-white/10 dark:bg-dark-25/95`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.08] sm:px-5`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h2`,{id:ve,className:`text-xl text-gray-950 dark:text-dark-950`,children:l(`mediaGeneration.title`)}),(0,F.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-dark-500`,children:l(`mediaGeneration.description`)})]}),(0,F.jsx)(`button`,{onClick:ye,className:`rounded-xl p-2`,children:(0,F.jsx)(m,{className:`h-5 w-5`})})]}),(0,F.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-4 p-4 sm:p-5`,children:[(0,F.jsx)(`div`,{className:`grid grid-cols-2 gap-2 rounded-xl bg-gray-100 p-1 dark:bg-white/[0.05]`,children:[`video`,`audio`].map(e=>(0,F.jsxs)(`button`,{type:`button`,disabled:K,onClick:()=>{p(e),y(``),S(``),J()},className:a(`flex items-center justify-center gap-2 rounded-xl px-3 py-2 text-sm transition-colors`,e===d?`bg-white text-gray-950 shadow-sm dark:bg-white/10 dark:text-white`:`text-gray-500 dark:text-dark-500`,K&&`cursor-not-allowed opacity-50`),children:[e===`video`?(0,F.jsx)(c,{className:`h-4 w-4`}):(0,F.jsx)(h,{className:`h-4 w-4`}),l(`mediaGeneration.${e}`)]},e))}),d===`video`&&be.length>0&&(0,F.jsxs)(`section`,{className:`space-y-2 rounded-xl border border-gray-200/80 bg-gray-50/80 p-3 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:l(`mediaGeneration.savedJobs`,{defaultValue:`Saved video jobs`})}),(0,F.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:l(`mediaGeneration.savedJobsDescription`,{defaultValue:`Closing this panel only stops waiting. Reopen it to resume any provider job listed here.`})})]}),be.map(e=>(0,F.jsxs)(`div`,{"data-testid":`video-job-${e.id}`,className:`flex items-center gap-3 rounded-lg border border-gray-200/70 bg-white/80 p-2.5 dark:border-white/10 dark:bg-dark-50/70`,children:[(0,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsx)(`p`,{className:`truncate text-sm text-gray-900 dark:text-gray-100`,children:e.prompt||e.model}),(0,F.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:[e.model,` ·`,` `,l(`mediaGeneration.jobStatus.${e.status}`,{defaultValue:e.status.replace(`_`,` `)})]}),e.error&&(0,F.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-300`,children:e.error})]}),(e.status===`pending`||e.status===`in_progress`)&&(0,F.jsx)(w,{type:`button`,variant:`outline`,size:`sm`,disabled:K,onClick:()=>void De(e),children:l(`mediaGeneration.resumeJob`,{defaultValue:`Resume`})}),e.cancellable&&(0,F.jsx)(w,{type:`button`,variant:`outline`,size:`sm`,disabled:K,onClick:()=>void Oe(e),children:l(`mediaGeneration.cancelJob`,{defaultValue:`Cancel job`})})]},e.id))]}),pe?(0,F.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,F.jsx)(f,{className:`h-7 w-7 animate-spin`})}):Y.length===0?(0,F.jsx)(`div`,{className:`rounded-xl border border-amber-500/25 bg-amber-500/10 p-4 text-sm text-amber-800 dark:text-amber-200`,children:l(`mediaGeneration.noModels`,{kind:l(`mediaGeneration.${d}`)})}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(R,{label:l(`mediaGeneration.model`),children:(0,F.jsx)(`select`,{value:xe,onChange:e=>{y(e.target.value),S(``),J(),ue(``),U(``),de(``),fe(!0)},className:V,children:Y.map(e=>(0,F.jsxs)(`option`,{value:z(e),children:[e.model,` (`,e.plugin,`mode`in e?` · ${l(`mediaGeneration.${e.mode}`)}`:``,`)`]},z(e)))})}),d===`audio`&&!$&&we?(0,F.jsx)(R,{label:l(`mediaGeneration.voice`),children:(0,F.jsx)(`input`,{value:te,onChange:e=>S(e.target.value),className:V,placeholder:Q?.config?.default_voice||l(`mediaGeneration.providerDefault`)})}):d===`video`?(0,F.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[(0,F.jsx)(R,{label:l(`mediaGeneration.resolution`),children:(0,F.jsxs)(`select`,{value:L,onChange:e=>ue(e.target.value),className:V,children:[(0,F.jsx)(`option`,{value:``,children:l(`mediaGeneration.providerDefault`)}),Z?.resolutions?.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))]})}),(0,F.jsx)(R,{label:l(`mediaGeneration.aspectRatio`),children:(0,F.jsxs)(`select`,{value:H,onChange:e=>U(e.target.value),className:V,children:[(0,F.jsx)(`option`,{value:``,children:l(`mediaGeneration.providerDefault`)}),Z?.aspect_ratios?.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))]})}),(0,F.jsx)(R,{label:l(`mediaGeneration.duration`),children:(0,F.jsxs)(`select`,{value:W,onChange:e=>de(e.target.value),className:V,children:[(0,F.jsx)(`option`,{value:``,children:l(`mediaGeneration.providerDefault`)}),Z?.durations?.map(e=>(0,F.jsxs)(`option`,{value:e,children:[e,`s`]},e))]})})]}):null,Se&&(0,F.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-primary-500/20 bg-primary-500/[0.06] p-4`,children:[(0,F.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:$,onChange:e=>{e.target.checked?ne(!0):J()},className:`mt-0.5`}),(0,F.jsxs)(`span`,{children:[(0,F.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:l(`mediaGeneration.cloneVoice`)}),(0,F.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:l(`mediaGeneration.cloneVoiceDescription`)})]})]}),$&&(0,F.jsxs)(`div`,{className:`space-y-3 border-t border-primary-500/15 pt-3`,children:[(0,F.jsx)(R,{label:l(`mediaGeneration.referenceAudio`),children:(0,F.jsx)(`input`,{type:`file`,accept:Q?.config?.clone_audio_mime_types?.join(`,`)||`audio/wav,audio/mpeg,audio/flac,audio/ogg`,onChange:e=>{let t=e.target.files?.[0]||null,n=Q?.config?.clone_max_audio_bytes;if(t&&n&&t.size>n){o.error(l(`mediaGeneration.referenceAudioTooLarge`,{max:le(n)})),e.target.value=``,E(null);return}E(t)},className:a(V,`file:me-3 file:rounded-lg file:border-0 file:bg-primary-500/10 file:px-3 file:py-1 file:text-primary-700 dark:file:text-primary-300`)},ae)}),(0,F.jsx)(R,{label:l(`mediaGeneration.referenceTranscript`),children:(0,F.jsx)(`textarea`,{value:D,onChange:e=>k(e.target.value),rows:3,required:Ce,className:a(V,`resize-none`),placeholder:l(`mediaGeneration.referenceTranscriptPlaceholder`)})}),(0,F.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>{re(e.target.checked),e.target.checked||(M(``),I(!1))},className:`mt-0.5`}),(0,F.jsxs)(`span`,{children:[(0,F.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:l(`mediaGeneration.saveVoiceProfile`,{defaultValue:`Save as a reusable voice`})}),(0,F.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:l(`mediaGeneration.saveVoiceProfileDescription`,{defaultValue:`Store this reference recording and transcript securely. Libre WebUI sends them to the selected provider for every Speech batch that uses this voice.`})})]})]}),A&&(0,F.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-primary-500/15 bg-white/60 p-3 dark:bg-dark-100/50`,children:[(0,F.jsx)(R,{label:l(`mediaGeneration.voiceProfileName`,{defaultValue:`Saved voice name`}),children:(0,F.jsx)(`input`,{type:`text`,value:j,onChange:e=>M(e.target.value),maxLength:80,autoComplete:`off`,className:V,placeholder:l(`mediaGeneration.voiceProfileNamePlaceholder`,{defaultValue:`For example, My voice`})})}),(0,F.jsxs)(`label`,{className:`flex items-start gap-3 text-xs text-amber-700 dark:text-amber-300`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:N,onChange:e=>I(e.target.checked),className:`mt-0.5`}),(0,F.jsx)(`span`,{children:l(`mediaGeneration.voiceStorageConsent`,{defaultValue:`I confirm that I have the speaker’s permission to clone and store this voice. The reference stays saved until I delete it.`})})]})]}),!A&&(0,F.jsx)(`p`,{className:`text-xs font-normal text-amber-700 dark:text-amber-300`,children:l(`mediaGeneration.cloneConsent`)})]})]}),d===`video`&&Z?.supports_audio&&(0,F.jsxs)(`label`,{className:`flex items-center gap-3 text-sm`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:G,onChange:e=>fe(e.target.checked)}),l(`mediaGeneration.generateAudio`)]}),(0,F.jsxs)(R,{label:d===`video`||Q?.mode===`sound`?l(`mediaGeneration.prompt`):l(`mediaGeneration.text`),children:[(0,F.jsx)(`textarea`,{value:x,onChange:e=>ee(e.target.value),rows:6,maxLength:Te,className:a(V,`resize-none`),placeholder:l(d===`audio`&&Q?.mode===`sound`?`mediaGeneration.soundPlaceholder`:`mediaGeneration.${d}Placeholder`)}),Te&&(0,F.jsxs)(`span`,{className:`block text-end text-xs font-normal text-gray-500 dark:text-dark-500`,children:[x.length,` / `,Te]})]})]})]}),Y.length>0&&(0,F.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-5`,children:(0,F.jsxs)(w,{onClick:K?()=>{q.current?.abort()}:async()=>{if(!X||!x.trim())return;let e=new AbortController;q.current?.abort(),q.current=e,he(!0);try{if(d===`audio`){let t=B(Q?.config?.default_format),n=$?await b.cloneVoice({model:X.model,pluginId:X.plugin,input:x.trim(),referenceAudio:T,referenceText:D.trim()||void 0,responseFormat:t,saveVoiceName:A?j.trim():void 0,consentToStore:A&&N},e.signal):Q?.mode===`sound`?await b.generateSound({model:X.model,pluginId:X.plugin,prompt:x.trim(),voice:te.trim()||Q?.config?.default_voice||void 0,format:`wav`},e.signal):await b.generateAudio({model:X.model,pluginId:X.plugin,input:x.trim(),voice:te.trim()||Q?.config?.default_voice||void 0,response_format:t},e.signal);if(e.signal.aborted)return;if(!n.success)throw Error(n.message);if($&&A&&(await u.invalidateQueries({queryKey:[`tts-voice-profiles`]}),e.signal.aborted))return}else{let t=await b.generateVideo({model:X.model,pluginId:X.plugin,prompt:x.trim(),...W?{duration:Number(W)}:{},...L?{resolution:L}:{},...H?{aspect_ratio:H}:{},...Z?.supports_audio?{generate_audio:G}:{}},e.signal);if(e.signal.aborted)return;if(!t.success||!t.data)throw Error(t.message||l(`mediaGeneration.failed`));let n=t.data;_e(e=>[n,...e.filter(e=>e.id!==n.id)]);let r=await Ee(n,e,!0);if(r.status===`failed`)throw Error(r.error||l(`mediaGeneration.failed`))}if(e.signal.aborted)return;o.success($&&A?l(`mediaGeneration.successWithSavedVoice`,{name:j.trim(),defaultValue:`Media generated and “{{name}}” is now available in Speech settings`}):l(`mediaGeneration.success`)),ee(``),J(),r(),n()}catch(t){if(e.signal.aborted)return;o.error(t instanceof Error?t.message:l(`mediaGeneration.failed`))}finally{q.current===e&&(q.current=null,he(!1))}},disabled:K?!1:!X||!x.trim()||!!(Te&&x.length>Te)||$&&(!T||Ce&&!D.trim()||A&&(!j.trim()||!N)),className:`w-full gap-2`,children:[K?(0,F.jsx)(m,{className:`h-4 w-4`}):(0,F.jsx)(s,{className:`h-4 w-4`}),K?d===`video`?l(`mediaGeneration.stopWaiting`,{defaultValue:`Stop waiting`}):l(`common.cancel`):l(`mediaGeneration.generate`)]})})]})]}),document.body):null}function R({label:e,children:t}){return(0,F.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-gray-700 dark:text-gray-300`,children:[(0,F.jsx)(`span`,{children:e}),t]})}function z(e){return`${e.mode||`default`}::${e.plugin}::${e.model}`}function ce(e,t){return t?.aborted?Promise.reject(t.reason):new Promise((n,r)=>{let i=window.setTimeout(()=>{t?.removeEventListener(`abort`,a),n()},e),a=()=>{window.clearTimeout(i),r(t?.reason)};t?.addEventListener(`abort`,a,{once:!0})})}function B(e){return[`mp3`,`opus`,`aac`,`flac`,`wav`,`pcm`].includes(e||``)?e:`mp3`}function le(e){return e>=1048576?`${Math.ceil(e/1048576)} MB`:`${Math.ceil(e/1024)} KB`}var V=`w-full rounded-xl border border-gray-200/80 bg-white/70 px-3 py-2.5 text-sm text-gray-900 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.035] dark:text-gray-100`,ue=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:o}=i();return(0,P.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,ie.createPortal)((0,F.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,F.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,F.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,F.jsx)(`button`,{onClick:t,className:a(`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,F.jsx)(m,{className:`h-6 w-6 text-white`})}),(0,F.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,F.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,F.jsxs)(`div`,{className:a(`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,F.jsxs)(`div`,{className:`mb-4`,children:[(0,F.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:o(`gallery.prompt`)}),(0,F.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,F.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,F.jsx)(l,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,F.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.model`),`:`]}),(0,F.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,F.jsx)(d,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,F.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.size`),`:`]}),(0,F.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,F.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,F.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.quality`),`:`]}),(0,F.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,F.jsx)(_,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,F.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.created`),`:`]}),(0,F.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,F.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,F.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.${S(e.imageData)}`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:a(`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,F.jsx)(g,{className:`h-4 w-4`}),o(`gallery.download`)]}),n&&(0,F.jsx)(`button`,{onClick:()=>n(e.id),className:a(`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,F.jsx)(p,{className:`h-4 w-4`})})]})]})]})]}),document.body)};function H({kind:e,refreshKey:t,onCountChange:n}){let{t:r}=i(),a=O(),[s,c]=(0,P.useState)(null),[l,d]=(0,P.useState)(null),m=N({queryKey:[`media-gallery`,e||`all`,t||0],queryFn:async({pageParam:t})=>{let n=await b.getGallery({limit:20,offset:t,...e?{kind:e}:{}});if(!n.success||!n.data)throw Error(n.message||r(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.media.length,0);return n<e.total?n:void 0}}),h=(0,P.useMemo)(()=>m.data?.pages.flatMap(e=>e.media)||[],[m.data]),_=m.data?.pages[0]?.total||0;(0,P.useEffect)(()=>n?.(_),[n,_]);let v=async e=>{if(!l){d(e.id);try{let t=await b.deleteGalleryItem(e.id);if(!t.success)throw Error(t.message);c(null),await a.invalidateQueries({queryKey:[`media-gallery`]}),o.success(r(`imageGallery.deleteSuccess`))}catch{o.error(r(`imageGallery.deleteFailed`))}finally{d(null)}}},y=async e=>{let t=await b.getGalleryContent(e.id),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`generated-${e.id}.${de(e.mimeType)}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)};return m.isLoading?(0,F.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,F.jsx)(f,{className:`h-8 w-8 animate-spin text-gray-400`})}):h.length===0?(0,F.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-12 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,F.jsx)(u,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,F.jsx)(`h3`,{className:`text-lg font-medium`,children:r(`mediaGallery.empty`)}),(0,F.jsx)(`p`,{className:`mt-2 max-w-sm text-gray-500 dark:text-gray-400`,children:r(`mediaGallery.emptyHint`)})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:h.map(e=>(0,F.jsxs)(`article`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/70 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,F.jsx)(U,{item:e,onOpenImage:t=>c(W(e,t))}),(0,F.jsxs)(`div`,{className:`space-y-3 p-3`,children:[(0,F.jsx)(`p`,{className:`line-clamp-2 text-sm text-gray-800 dark:text-gray-200`,children:e.prompt}),(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,F.jsx)(`span`,{className:`min-w-0 truncate text-xs text-gray-500`,children:e.model}),(0,F.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,F.jsx)(`button`,{onClick:()=>void y(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:r(`imageGallery.download`),children:(0,F.jsx)(g,{className:`h-4 w-4`})}),(0,F.jsx)(`button`,{onClick:()=>void v(e),disabled:l===e.id,className:`rounded-lg p-1.5 hover:bg-red-500/15 hover:text-red-500`,title:r(`imageGallery.delete`),children:l===e.id?(0,F.jsx)(f,{className:`h-4 w-4 animate-spin`}):(0,F.jsx)(p,{className:`h-4 w-4`})})]})]})]})]},e.id))}),m.hasNextPage&&(0,F.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,F.jsx)(w,{variant:`outline`,disabled:m.isFetchingNextPage,onClick:()=>void m.fetchNextPage(),children:m.isFetchingNextPage?r(`common.loading`):r(`imageGallery.loadMore`,{current:h.length,total:_})})}),s&&(0,F.jsx)(ue,{image:s,onClose:()=>c(null),onDelete:e=>{let t=h.find(t=>t.id===e);t&&v(t)},onDownload:e=>{let t=h.find(t=>t.id===e.id);t&&y(t)}})]})}function U({item:e,onOpenImage:t}){let{data:n,isLoading:r}=k({queryKey:[`media-gallery-content`,e.id],queryFn:()=>b.getGalleryContent(e.id),staleTime:3e5}),i=(0,P.useMemo)(()=>n?URL.createObjectURL(n):``,[n]);return(0,P.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),r||!i?(0,F.jsx)(`div`,{className:`flex aspect-video items-center justify-center bg-gray-100 dark:bg-white/[0.03]`,children:(0,F.jsx)(f,{className:`h-6 w-6 animate-spin text-gray-400`})}):e.kind===`image`?(0,F.jsx)(`button`,{className:`block aspect-square w-full overflow-hidden`,onClick:()=>t(i),children:(0,F.jsx)(`img`,{src:i,alt:e.prompt,className:`h-full w-full object-cover`,loading:`lazy`})}):e.kind===`video`?(0,F.jsx)(`div`,{className:`aspect-video bg-black`,children:(0,F.jsx)(`video`,{src:i,controls:!0,preload:`metadata`,className:`h-full w-full object-contain`})}):(0,F.jsxs)(`div`,{className:`flex min-h-40 flex-col items-center justify-center gap-3 bg-gradient-to-br from-primary-500/10 to-cyan-500/10 p-4`,children:[(0,F.jsx)(h,{className:`h-9 w-9 text-primary-500`}),(0,F.jsx)(`audio`,{src:i,controls:!0,preload:`metadata`,className:`w-full`})]})}function W(e,t){return{id:e.id,userId:e.userId,prompt:e.prompt,model:e.model,imageData:t,size:e.size,quality:e.quality,createdAt:e.createdAt}}function de(e){let t=e.split(`/`)[1]?.split(`;`)[0];return t===`mpeg`?e.startsWith(`audio/`)?`mp3`:`mpeg`:t===`svg+xml`?`svg`:t||`bin`}var G=()=>{let{t:e}=i(),[t,n]=(0,P.useState)(null),[r,o]=(0,P.useState)(!1),[s,l]=(0,P.useState)(null),[u,d]=(0,P.useState)(`all`),[f,p]=(0,P.useState)(0),m=ne(e=>e.preferences.imageGenSettings?.enabled===!0),g=(0,P.useCallback)(()=>{p(e=>e+1)},[]);return(0,F.jsxs)(T,{width:`wide`,children:[(0,F.jsx)(E,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,F.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(`mediaGallery.itemCount`,{count:t})}):null,actions:(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsxs)(w,{onClick:()=>{m&&o(!0)},disabled:!m,className:`gap-2 px-4`,children:[(0,F.jsx)(v,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]}),(0,F.jsxs)(w,{variant:`outline`,onClick:()=>l(`video`),className:`gap-2 px-4`,children:[(0,F.jsx)(c,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.video`)]}),(0,F.jsxs)(w,{variant:`outline`,onClick:()=>l(`audio`),className:`gap-2 px-4`,children:[(0,F.jsx)(h,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.audio`)]})]})}),(0,F.jsx)(`div`,{className:`mb-5 flex flex-wrap gap-2`,children:[`all`,`image`,`video`,`audio`].map(t=>(0,F.jsx)(`button`,{type:`button`,onClick:()=>d(t),className:a(`rounded-full border px-3 py-1.5 text-sm transition-colors`,u===t?`border-gray-950 bg-gray-950 text-white dark:border-white dark:bg-white dark:text-gray-950`:`border-gray-200 text-gray-600 hover:border-gray-400 dark:border-white/10 dark:text-dark-600`),children:e(`mediaGallery.filters.${t}`)},t))}),(0,F.jsx)(H,{kind:u===`all`?void 0:u,refreshKey:f,onCountChange:n}),(0,F.jsx)(oe,{isOpen:r&&m,onClose:()=>o(!1),onImageGenerated:g}),(0,F.jsx)(L,{isOpen:s!==null,initialKind:s||`video`,onClose:()=>l(null),onGenerated:g},s||`closed`)]})};export{G as GalleryPage,G as default};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{n as r}from"./react-vendor-C5yShNlM.js";import{t as i}from"./useTranslation-C3ei3mJq.js";import{t as a}from"./utils-CuC1beTY.js";import{An as o,E as s,It as c,Yt as l,bt as u,ct as d,ft as f,h as p,n as m,o as h,qt as g,tn as _,yt as v}from"./ui-vendor-54SgntkX.js";import{t as y}from"./logger-DSXjF4ye.js";import{g as b,v as x}from"./api-Dw_IuHaz.js";import{i as ee,n as te,r as S,s as C}from"./imageGenModels-Dx_QMLJQ.js";import{t as ne}from"./appStore-DAT2R-5p.js";import{t as w}from"./Button-BV44cTnj.js";import{n as T,t as E}from"./ui-CS8EAgvS.js";import{C as D,b as O,v as k,w as A,x as re,y as j}from"../assets/index-BXMQqOXF.js";var M=class extends re{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:D(t,n.data),hasPreviousPage:A(t,n.data),isFetchNextPageError:l,isFetchingNextPage:u,isFetchPreviousPageError:d,isFetchingPreviousPage:f,isRefetchError:s&&!l&&!d,isRefetching:a&&!u&&!f}}};function N(e,t){return j(e,M,t)}var P=e(t(),1),ie=r(),F=n(),I=y(`components:image-generation-panel`);function ae(e,t={}){let n=e.config?.sizes&&e.config.sizes.length>0?e.config.sizes:[t.size||e.config?.default_size||`1024x1024`],r=e.config?.qualities&&e.config.qualities.length>0?e.config.qualities:e.config?.omit_quality_when_empty?[]:[t.quality||e.config?.default_quality||`standard`],i=e.config?.styles&&e.config.styles.length>0?e.config.styles:[];return{pluginId:e.id,model:C(e.models,t.model,void 0,``),size:C(n,t.size,e.config?.default_size,`1024x1024`),quality:r.length>0?C(r,t.quality,e.config?.default_quality,`standard`):``,style:i.length>0?C(i,t.style,e.config?.default_style,i[0]):``,sizes:n,qualities:r,styles:i,maxPromptLength:e.config?.max_prompt_length??null,sizeLabel:e.config?.size_label||``}}var oe=({isOpen:e,onClose:t,onImageGenerated:n})=>{let{t:r}=i(),c=ne(e=>e.preferences.imageGenSettings),l=c?.enabled===!0,[u,d]=(0,P.useState)([]),[f,p]=(0,P.useState)(``),[h,_]=(0,P.useState)(``),[y,b]=(0,P.useState)(``),[C,T]=(0,P.useState)(`1024x1024`),[E,D]=(0,P.useState)(`standard`),[O,k]=(0,P.useState)(``),[A,re]=(0,P.useState)(!1),[j,M]=(0,P.useState)(null),N=(0,P.useRef)(null),[oe,se]=(0,P.useState)([`512x512`,`768x768`,`1024x1024`]),[L,R]=(0,P.useState)([`standard`,`high`]),[z,ce]=(0,P.useState)([]),[B,le]=(0,P.useState)(null),[V,ue]=(0,P.useState)(``),H=P.useId(),U=(0,P.useCallback)((e,t)=>{let n=ae(e,t);p(n.pluginId),_(n.model),T(n.size),D(n.quality),k(n.style),se(n.sizes),R(n.qualities),ce(n.styles),le(n.maxPromptLength),ue(n.sizeLabel)},[]);(0,P.useEffect)(()=>{let t=!1;return e&&l&&(async()=>{try{let e=await x.getPlugins();if(t)return;let n=e.success&&e.data?e.data.filter(e=>e.models.length>0):[];d(n);let r=te(n,c);r?U(r,c):(p(``),_(``))}catch(e){if(t)return;d([]),p(``),_(``),I.error(`Failed to load image generation plugins:`,e)}})(),()=>{t=!0}},[U,l,e,c]),(0,P.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]),(0,P.useEffect)(()=>()=>{N.current?.abort(),N.current=null},[]),(0,P.useEffect)(()=>{e||N.current?.abort()},[e]);let W=()=>{N.current?.abort(),t()},de=e=>{let t=u.find(t=>t.id===e);t&&U(t,{model:h,size:C,quality:E,style:O})},G=async()=>{if(!l||!f||!h||!y.trim()){o.error(r(`imageGeneration.enterPrompt`));return}if(B&&y.length>B){o.error(r(`imageGeneration.promptTooLong`,{max:B.toLocaleString()}));return}let e=new AbortController;N.current?.abort(),N.current=e,re(!0),M(null);try{let i=await x.generate({model:h,pluginId:f,prompt:y.trim(),size:C,quality:E,...O?{style:O}:{}},e.signal);if(e.signal.aborted)return;if(i.success&&i.data?.images&&i.data.images.length>0){let e=ee(i.data.images[0]);e&&(o.success(r(`imageGeneration.success`)),n?(n(e,y.trim(),h),b(``),M(null),t()):M(e))}else o.error(r(`imageGeneration.failed`))}catch(t){if(e.signal.aborted)return;I.error(`Image generation failed:`,t);let n=t instanceof Error?t.message:r(`imageGeneration.failed`);o.error(n)}finally{N.current===e&&(N.current=null,re(!1))}},fe=()=>{N.current?.abort()},pe=()=>{if(!j)return;let e=document.createElement(`a`);e.href=j,e.download=`generated-image-${Date.now()}.${S(j)}`,document.body.appendChild(e),e.click(),document.body.removeChild(e)};if(!e||!l)return null;let me=u.find(e=>e.id===f);return(0,ie.createPortal)((0,F.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":H,children:[(0,F.jsx)(`div`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:W}),(0,F.jsxs)(`div`,{className:a(`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,F.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,F.jsx)(`div`,{children:(0,F.jsx)(`h2`,{id:H,className:`text-xl font-normal tracking-[-0.025em] text-gray-950 dark:text-dark-950`,children:r(`imageGeneration.title`)})}),(0,F.jsx)(`button`,{onClick:W,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,F.jsx)(m,{className:`h-5 w-5 text-gray-500 dark:text-gray-400`})})]}),(0,F.jsx)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-5 p-5 scrollbar-thin sm:p-6`,children:me?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`settings.plugins.title`)}),(0,F.jsx)(`select`,{value:f,onChange:e=>de(e.target.value),className:a(`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:u.map(e=>(0,F.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.model`)}),(0,F.jsx)(`select`,{value:h,onChange:e=>_(e.target.value),className:a(`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:me?.models.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))})]}),z.length>0&&(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.style`)}),(0,F.jsx)(`select`,{value:O,onChange:e=>k(e.target.value),className:a(`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:z.map(e=>(0,F.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,F.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:V||r(`imageGeneration.size`)}),(0,F.jsx)(`select`,{value:C,onChange:e=>T(e.target.value),className:a(`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:oe.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))})]}),L.length>0&&(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.quality`)}),(0,F.jsx)(`select`,{value:E,onChange:e=>D(e.target.value),className:a(`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:L.map(e=>(0,F.jsx)(`option`,{value:e,children:e.charAt(0).toUpperCase()+e.slice(1)},e))})]})]}),(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`label`,{className:`block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1`,children:r(`imageGeneration.prompt`)}),(0,F.jsx)(`textarea`,{value:y,onChange:e=>b(e.target.value),placeholder:r(`imageGeneration.promptPlaceholder`),rows:5,className:a(`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`,B&&y.length>B&&`border-red-500 dark:border-red-500`)}),B&&(0,F.jsxs)(`div`,{className:a(`mt-1 text-end text-xs`,y.length>B?`text-red-500`:`text-gray-500 dark:text-gray-400`),children:[y.length.toLocaleString(),` /`,` `,B.toLocaleString()]})]}),j&&(0,F.jsxs)(`div`,{className:`relative overflow-hidden rounded-2xl border border-gray-200/80 dark:border-white/10`,children:[(0,F.jsx)(`img`,{src:j,alt:`Generated`,className:`w-full h-auto`}),(0,F.jsx)(`button`,{onClick:pe,className:a(`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,F.jsx)(g,{className:`h-5 w-5 text-gray-700 dark:text-gray-200`})})]})]}):(0,F.jsxs)(`div`,{className:`text-center py-8`,children:[(0,F.jsx)(v,{className:`h-12 w-12 mx-auto mb-3 text-gray-300 dark:text-gray-600`}),(0,F.jsx)(`p`,{className:`text-gray-500 dark:text-gray-400`,children:r(`imageGeneration.noModels`)}),(0,F.jsx)(`p`,{className:`text-sm text-gray-400 dark:text-gray-500 mt-1`,children:r(`imageGeneration.configurePlugin`)})]})}),me&&(0,F.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-6 sm:py-5`,children:(0,F.jsx)(w,{onClick:A?fe:G,disabled:!A&&(!l||!y.trim()||!f||!h),className:a(`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:A?(0,F.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,F.jsx)(m,{className:`h-4 w-4`}),r(`common.cancel`)]}):(0,F.jsxs)(`span`,{className:`flex items-center justify-center gap-2`,children:[(0,F.jsx)(s,{className:`h-4 w-4`}),r(`imageGeneration.generate`)]})})})]})]}),document.body)},se={video:[],audio:[]};function L({isOpen:e,initialKind:t,onClose:n,onGenerated:r}){let{t:l}=i(),u=O(),[d,p]=(0,P.useState)(t),[g,_]=(0,P.useState)(se),[v,y]=(0,P.useState)(``),[x,ee]=(0,P.useState)(``),[te,S]=(0,P.useState)(``),[C,ne]=(0,P.useState)(!1),[T,E]=(0,P.useState)(null),[D,k]=(0,P.useState)(``),[A,re]=(0,P.useState)(!1),[j,M]=(0,P.useState)(``),[N,I]=(0,P.useState)(!1),[ae,oe]=(0,P.useState)(0),[L,ue]=(0,P.useState)(``),[H,U]=(0,P.useState)(``),[W,de]=(0,P.useState)(``),[G,fe]=(0,P.useState)(!0),[pe,me]=(0,P.useState)(!0),[K,he]=(0,P.useState)(!1),[ge,_e]=(0,P.useState)([]),q=(0,P.useRef)(null),ve=P.useId(),J=()=>{ne(!1),E(null),k(``),re(!1),M(``),I(!1),oe(e=>e+1)},ye=()=>{q.current?.abort(),J(),n()};(0,P.useEffect)(()=>()=>{q.current?.abort(),q.current=null},[]),(0,P.useEffect)(()=>{e||q.current?.abort()},[e]),(0,P.useEffect)(()=>{if(!e)return;let t=!1;return b.getModels().then(e=>{t||!e.success||!e.data||_(e.data)}).catch(()=>{t||o.error(l(`mediaGeneration.loadFailed`))}).finally(()=>{t||me(!1)}),()=>{t=!0}},[e,l]),(0,P.useEffect)(()=>{if(!e)return;let t=!1;return b.listVideoJobs({limit:100,active:!0}).then(e=>{!t&&e.success&&e.data&&_e(e.data.jobs)}).catch(()=>{t||o.error(l(`mediaGeneration.jobsLoadFailed`,{defaultValue:`Failed to load saved video jobs`}))}),()=>{t=!0}},[e,l]);let Y=d===`video`?g.video:g.audio,be=ge.filter(e=>e.status!==`completed`),xe=Y.some(e=>z(e)===v)?v:Y[0]?z(Y[0]):``,X=(0,P.useMemo)(()=>Y.find(e=>z(e)===xe),[xe,Y]),Z=d===`video`?X?.config:void 0,Q=d===`audio`?X:void 0,Se=!!(Q?.mode===`speech`&&Q.config?.supports_voice_cloning),Ce=!!Q?.config?.clone_requires_transcript,$=Se&&C,we=!!(Q?.mode!==`speech`||Q.config?.allows_custom_voice!==!1||Q.config?.voices?.length),Te=Q?.mode===`speech`?Q.config?.max_characters:void 0,Ee=async(e,t,n,r=0)=>{if(e.status!==`pending`&&e.status!==`in_progress`)return e;n&&await ce(3e4,t.signal);try{let n=await b.resumeVideoJob(e.id,t.signal);if(!n.success||!n.data)throw Error(n.message||l(`mediaGeneration.failed`));let r=n.data;return _e(e=>[r,...e.filter(e=>e.id!==r.id)]),Ee(r,t,!0)}catch(n){if(t.signal.aborted||r>=4)throw n;return Ee(e,t,!0,r+1)}},De=async e=>{let t=new AbortController;q.current?.abort(),q.current=t,he(!0);try{let n=await Ee(e,t,!1);if(t.signal.aborted)return;if(n.status===`failed`)throw Error(n.error||l(`mediaGeneration.failed`));o.success(l(`mediaGeneration.success`)),r()}catch(e){if(t.signal.aborted)return;o.error(e instanceof Error?e.message:l(`mediaGeneration.failed`))}finally{q.current===t&&(q.current=null,he(!1))}},Oe=async e=>{try{let t=await b.cancelVideoJob(e.id);if(!t.success)throw Error(t.message||l(`mediaGeneration.failed`));_e(t=>t.filter(t=>t.id!==e.id)),o.success(l(`mediaGeneration.jobCancelled`,{defaultValue:`Video job cancelled at the provider`}))}catch(e){o.error(e instanceof Error?e.message:l(`mediaGeneration.failed`))}};return e?(0,ie.createPortal)((0,F.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center p-3 sm:p-6`,children:[(0,F.jsx)(`button`,{className:`absolute inset-0 bg-black/55 backdrop-blur-sm`,onClick:ye,"aria-label":l(`common.close`)}),(0,F.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":ve,className:`relative flex max-h-[92vh] w-full max-w-2xl flex-col overflow-hidden rounded-2xl border border-gray-200/80 bg-white/95 shadow-2xl backdrop-blur-xl dark:border-white/10 dark:bg-dark-25/95`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between border-b border-gray-200/70 px-4 py-3 dark:border-white/[0.08] sm:px-5`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h2`,{id:ve,className:`text-xl text-gray-950 dark:text-dark-950`,children:l(`mediaGeneration.title`)}),(0,F.jsx)(`p`,{className:`mt-1 text-sm text-gray-500 dark:text-dark-500`,children:l(`mediaGeneration.description`)})]}),(0,F.jsx)(`button`,{onClick:ye,className:`rounded-xl p-2`,children:(0,F.jsx)(m,{className:`h-5 w-5`})})]}),(0,F.jsxs)(`div`,{className:`scroll-region min-h-0 flex-1 space-y-4 p-4 sm:p-5`,children:[(0,F.jsx)(`div`,{className:`grid grid-cols-2 gap-2 rounded-xl bg-gray-100 p-1 dark:bg-white/[0.05]`,children:[`video`,`audio`].map(e=>(0,F.jsxs)(`button`,{type:`button`,disabled:K,onClick:()=>{p(e),y(``),S(``),J()},className:a(`flex items-center justify-center gap-2 rounded-xl px-3 py-2 text-sm transition-colors`,e===d?`bg-white text-gray-950 shadow-sm dark:bg-white/10 dark:text-white`:`text-gray-500 dark:text-dark-500`,K&&`cursor-not-allowed opacity-50`),children:[e===`video`?(0,F.jsx)(c,{className:`h-4 w-4`}):(0,F.jsx)(h,{className:`h-4 w-4`}),l(`mediaGeneration.${e}`)]},e))}),d===`video`&&be.length>0&&(0,F.jsxs)(`section`,{className:`space-y-2 rounded-xl border border-gray-200/80 bg-gray-50/80 p-3 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,F.jsxs)(`div`,{children:[(0,F.jsx)(`h3`,{className:`text-sm font-medium text-gray-900 dark:text-gray-100`,children:l(`mediaGeneration.savedJobs`,{defaultValue:`Saved video jobs`})}),(0,F.jsx)(`p`,{className:`mt-0.5 text-xs text-gray-500 dark:text-dark-500`,children:l(`mediaGeneration.savedJobsDescription`,{defaultValue:`Closing this panel only stops waiting. Reopen it to resume any provider job listed here.`})})]}),be.map(e=>(0,F.jsxs)(`div`,{"data-testid":`video-job-${e.id}`,className:`flex items-center gap-3 rounded-lg border border-gray-200/70 bg-white/80 p-2.5 dark:border-white/10 dark:bg-dark-50/70`,children:[(0,F.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,F.jsx)(`p`,{className:`truncate text-sm text-gray-900 dark:text-gray-100`,children:e.prompt||e.model}),(0,F.jsxs)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:[e.model,` ·`,` `,l(`mediaGeneration.jobStatus.${e.status}`,{defaultValue:e.status.replace(`_`,` `)})]}),e.error&&(0,F.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-300`,children:e.error})]}),(e.status===`pending`||e.status===`in_progress`)&&(0,F.jsx)(w,{type:`button`,variant:`outline`,size:`sm`,disabled:K,onClick:()=>void De(e),children:l(`mediaGeneration.resumeJob`,{defaultValue:`Resume`})}),e.cancellable&&(0,F.jsx)(w,{type:`button`,variant:`outline`,size:`sm`,disabled:K,onClick:()=>void Oe(e),children:l(`mediaGeneration.cancelJob`,{defaultValue:`Cancel job`})})]},e.id))]}),pe?(0,F.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,F.jsx)(f,{className:`h-7 w-7 animate-spin`})}):Y.length===0?(0,F.jsx)(`div`,{className:`rounded-xl border border-amber-500/25 bg-amber-500/10 p-4 text-sm text-amber-800 dark:text-amber-200`,children:l(`mediaGeneration.noModels`,{kind:l(`mediaGeneration.${d}`)})}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(R,{label:l(`mediaGeneration.model`),children:(0,F.jsx)(`select`,{value:xe,onChange:e=>{y(e.target.value),S(``),J(),ue(``),U(``),de(``),fe(!0)},className:V,children:Y.map(e=>(0,F.jsxs)(`option`,{value:z(e),children:[e.model,` (`,e.plugin,`mode`in e?` · ${l(`mediaGeneration.${e.mode}`)}`:``,`)`]},z(e)))})}),d===`audio`&&!$&&we?(0,F.jsx)(R,{label:l(`mediaGeneration.voice`),children:(0,F.jsx)(`input`,{value:te,onChange:e=>S(e.target.value),className:V,placeholder:Q?.config?.default_voice||l(`mediaGeneration.providerDefault`)})}):d===`video`?(0,F.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-3`,children:[(0,F.jsx)(R,{label:l(`mediaGeneration.resolution`),children:(0,F.jsxs)(`select`,{value:L,onChange:e=>ue(e.target.value),className:V,children:[(0,F.jsx)(`option`,{value:``,children:l(`mediaGeneration.providerDefault`)}),Z?.resolutions?.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))]})}),(0,F.jsx)(R,{label:l(`mediaGeneration.aspectRatio`),children:(0,F.jsxs)(`select`,{value:H,onChange:e=>U(e.target.value),className:V,children:[(0,F.jsx)(`option`,{value:``,children:l(`mediaGeneration.providerDefault`)}),Z?.aspect_ratios?.map(e=>(0,F.jsx)(`option`,{value:e,children:e},e))]})}),(0,F.jsx)(R,{label:l(`mediaGeneration.duration`),children:(0,F.jsxs)(`select`,{value:W,onChange:e=>de(e.target.value),className:V,children:[(0,F.jsx)(`option`,{value:``,children:l(`mediaGeneration.providerDefault`)}),Z?.durations?.map(e=>(0,F.jsxs)(`option`,{value:e,children:[e,`s`]},e))]})})]}):null,Se&&(0,F.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-primary-500/20 bg-primary-500/[0.06] p-4`,children:[(0,F.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:$,onChange:e=>{e.target.checked?ne(!0):J()},className:`mt-0.5`}),(0,F.jsxs)(`span`,{children:[(0,F.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:l(`mediaGeneration.cloneVoice`)}),(0,F.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:l(`mediaGeneration.cloneVoiceDescription`)})]})]}),$&&(0,F.jsxs)(`div`,{className:`space-y-3 border-t border-primary-500/15 pt-3`,children:[(0,F.jsx)(R,{label:l(`mediaGeneration.referenceAudio`),children:(0,F.jsx)(`input`,{type:`file`,accept:Q?.config?.clone_audio_mime_types?.join(`,`)||`audio/wav,audio/mpeg,audio/flac,audio/ogg`,onChange:e=>{let t=e.target.files?.[0]||null,n=Q?.config?.clone_max_audio_bytes;if(t&&n&&t.size>n){o.error(l(`mediaGeneration.referenceAudioTooLarge`,{max:le(n)})),e.target.value=``,E(null);return}E(t)},className:a(V,`file:me-3 file:rounded-lg file:border-0 file:bg-primary-500/10 file:px-3 file:py-1 file:text-primary-700 dark:file:text-primary-300`)},ae)}),(0,F.jsx)(R,{label:l(`mediaGeneration.referenceTranscript`),children:(0,F.jsx)(`textarea`,{value:D,onChange:e=>k(e.target.value),rows:3,required:Ce,className:a(V,`resize-none`),placeholder:l(`mediaGeneration.referenceTranscriptPlaceholder`)})}),(0,F.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:A,onChange:e=>{re(e.target.checked),e.target.checked||(M(``),I(!1))},className:`mt-0.5`}),(0,F.jsxs)(`span`,{children:[(0,F.jsx)(`span`,{className:`block font-medium text-gray-900 dark:text-gray-100`,children:l(`mediaGeneration.saveVoiceProfile`,{defaultValue:`Save as a reusable voice`})}),(0,F.jsx)(`span`,{className:`mt-0.5 block text-xs font-normal text-gray-500 dark:text-dark-500`,children:l(`mediaGeneration.saveVoiceProfileDescription`,{defaultValue:`Store this reference recording and transcript securely. Libre WebUI sends them to the selected provider for every Speech batch that uses this voice.`})})]})]}),A&&(0,F.jsxs)(`div`,{className:`space-y-3 rounded-lg border border-primary-500/15 bg-white/60 p-3 dark:bg-dark-100/50`,children:[(0,F.jsx)(R,{label:l(`mediaGeneration.voiceProfileName`,{defaultValue:`Saved voice name`}),children:(0,F.jsx)(`input`,{type:`text`,value:j,onChange:e=>M(e.target.value),maxLength:80,autoComplete:`off`,className:V,placeholder:l(`mediaGeneration.voiceProfileNamePlaceholder`,{defaultValue:`For example, My voice`})})}),(0,F.jsxs)(`label`,{className:`flex items-start gap-3 text-xs text-amber-700 dark:text-amber-300`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:N,onChange:e=>I(e.target.checked),className:`mt-0.5`}),(0,F.jsx)(`span`,{children:l(`mediaGeneration.voiceStorageConsent`,{defaultValue:`I confirm that I have the speaker’s permission to clone and store this voice. The reference stays saved until I delete it.`})})]})]}),!A&&(0,F.jsx)(`p`,{className:`text-xs font-normal text-amber-700 dark:text-amber-300`,children:l(`mediaGeneration.cloneConsent`)})]})]}),d===`video`&&Z?.supports_audio&&(0,F.jsxs)(`label`,{className:`flex items-center gap-3 text-sm`,children:[(0,F.jsx)(`input`,{type:`checkbox`,checked:G,onChange:e=>fe(e.target.checked)}),l(`mediaGeneration.generateAudio`)]}),(0,F.jsxs)(R,{label:d===`video`||Q?.mode===`sound`?l(`mediaGeneration.prompt`):l(`mediaGeneration.text`),children:[(0,F.jsx)(`textarea`,{value:x,onChange:e=>ee(e.target.value),rows:6,maxLength:Te,className:a(V,`resize-none`),placeholder:l(d===`audio`&&Q?.mode===`sound`?`mediaGeneration.soundPlaceholder`:`mediaGeneration.${d}Placeholder`)}),Te&&(0,F.jsxs)(`span`,{className:`block text-end text-xs font-normal text-gray-500 dark:text-dark-500`,children:[x.length,` / `,Te]})]})]})]}),Y.length>0&&(0,F.jsx)(`div`,{className:`border-t border-gray-200/70 p-4 dark:border-white/[0.08] sm:px-5`,children:(0,F.jsxs)(w,{onClick:K?()=>{q.current?.abort()}:async()=>{if(!X||!x.trim())return;let e=new AbortController;q.current?.abort(),q.current=e,he(!0);try{if(d===`audio`){let t=B(Q?.config?.default_format),n=$?await b.cloneVoice({model:X.model,pluginId:X.plugin,input:x.trim(),referenceAudio:T,referenceText:D.trim()||void 0,responseFormat:t,saveVoiceName:A?j.trim():void 0,consentToStore:A&&N},e.signal):Q?.mode===`sound`?await b.generateSound({model:X.model,pluginId:X.plugin,prompt:x.trim(),voice:te.trim()||Q?.config?.default_voice||void 0,format:`wav`},e.signal):await b.generateAudio({model:X.model,pluginId:X.plugin,input:x.trim(),voice:te.trim()||Q?.config?.default_voice||void 0,response_format:t},e.signal);if(e.signal.aborted)return;if(!n.success)throw Error(n.message);if($&&A&&(await u.invalidateQueries({queryKey:[`tts-voice-profiles`]}),e.signal.aborted))return}else{let t=await b.generateVideo({model:X.model,pluginId:X.plugin,prompt:x.trim(),...W?{duration:Number(W)}:{},...L?{resolution:L}:{},...H?{aspect_ratio:H}:{},...Z?.supports_audio?{generate_audio:G}:{}},e.signal);if(e.signal.aborted)return;if(!t.success||!t.data)throw Error(t.message||l(`mediaGeneration.failed`));let n=t.data;_e(e=>[n,...e.filter(e=>e.id!==n.id)]);let r=await Ee(n,e,!0);if(r.status===`failed`)throw Error(r.error||l(`mediaGeneration.failed`))}if(e.signal.aborted)return;o.success($&&A?l(`mediaGeneration.successWithSavedVoice`,{name:j.trim(),defaultValue:`Media generated and “{{name}}” is now available in Speech settings`}):l(`mediaGeneration.success`)),ee(``),J(),r(),n()}catch(t){if(e.signal.aborted)return;o.error(t instanceof Error?t.message:l(`mediaGeneration.failed`))}finally{q.current===e&&(q.current=null,he(!1))}},disabled:K?!1:!X||!x.trim()||!!(Te&&x.length>Te)||$&&(!T||Ce&&!D.trim()||A&&(!j.trim()||!N)),className:`w-full gap-2`,children:[K?(0,F.jsx)(m,{className:`h-4 w-4`}):(0,F.jsx)(s,{className:`h-4 w-4`}),K?d===`video`?l(`mediaGeneration.stopWaiting`,{defaultValue:`Stop waiting`}):l(`common.cancel`):l(`mediaGeneration.generate`)]})})]})]}),document.body):null}function R({label:e,children:t}){return(0,F.jsxs)(`label`,{className:`block space-y-1.5 text-sm font-medium text-gray-700 dark:text-gray-300`,children:[(0,F.jsx)(`span`,{children:e}),t]})}function z(e){return`${e.mode||`default`}::${e.plugin}::${e.model}`}function ce(e,t){return t?.aborted?Promise.reject(t.reason):new Promise((n,r)=>{let i=window.setTimeout(()=>{t?.removeEventListener(`abort`,a),n()},e),a=()=>{window.clearTimeout(i),r(t?.reason)};t?.addEventListener(`abort`,a,{once:!0})})}function B(e){return[`mp3`,`opus`,`aac`,`flac`,`wav`,`pcm`].includes(e||``)?e:`mp3`}function le(e){return e>=1048576?`${Math.ceil(e/1048576)} MB`:`${Math.ceil(e/1024)} KB`}var V=`w-full rounded-xl border border-gray-200/80 bg-white/70 px-3 py-2.5 text-sm text-gray-900 focus:outline-none focus:ring-2 focus:ring-primary-500/20 dark:border-white/10 dark:bg-white/[0.035] dark:text-gray-100`,ue=({image:e,onClose:t,onDelete:n,onDownload:r})=>{let{t:o}=i();return(0,P.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,ie.createPortal)((0,F.jsxs)(`div`,{className:`fixed inset-0 z-[99999] flex items-center justify-center`,onClick:t,children:[(0,F.jsx)(`div`,{className:`absolute inset-0 bg-black/90 backdrop-blur-sm`}),(0,F.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,F.jsx)(`button`,{onClick:t,className:a(`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,F.jsx)(m,{className:`h-6 w-6 text-white`})}),(0,F.jsx)(`div`,{className:`flex-1 flex items-center justify-center min-h-0`,children:(0,F.jsx)(`img`,{src:e.imageData,alt:e.prompt,className:`max-w-full max-h-[70vh] lg:max-h-[90vh] object-contain rounded-lg`})}),(0,F.jsxs)(`div`,{className:a(`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,F.jsxs)(`div`,{className:`mb-4`,children:[(0,F.jsx)(`h3`,{className:`text-sm font-medium text-gray-500 dark:text-gray-400 mb-1`,children:o(`gallery.prompt`)}),(0,F.jsx)(`p`,{className:`text-gray-900 dark:text-gray-100 text-sm leading-relaxed`,children:e.prompt})]}),(0,F.jsxs)(`div`,{className:`space-y-3 mb-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,F.jsx)(l,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,F.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.model`),`:`]}),(0,F.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.model})]}),e.size&&(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,F.jsx)(d,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,F.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.size`),`:`]}),(0,F.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100`,children:e.size})]}),e.quality&&(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,F.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,F.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.quality`),`:`]}),(0,F.jsx)(`span`,{className:`text-gray-900 dark:text-gray-100 capitalize`,children:e.quality})]}),(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,F.jsx)(_,{className:`h-4 w-4 text-gray-400 dark:text-gray-500`}),(0,F.jsxs)(`span`,{className:`text-gray-500 dark:text-gray-400`,children:[o(`gallery.created`),`:`]}),(0,F.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,F.jsxs)(`div`,{className:`flex gap-2 pt-4 border-t border-gray-200 dark:border-dark-300`,children:[(0,F.jsxs)(`button`,{onClick:()=>{if(r)r(e);else{let t=document.createElement(`a`);t.href=e.imageData,t.download=`generated-${e.id}.${S(e.imageData)}`,document.body.appendChild(t),t.click(),document.body.removeChild(t)}},className:a(`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,F.jsx)(g,{className:`h-4 w-4`}),o(`gallery.download`)]}),n&&(0,F.jsx)(`button`,{onClick:()=>n(e.id),className:a(`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,F.jsx)(p,{className:`h-4 w-4`})})]})]})]})]}),document.body)};function H({kind:e,refreshKey:t,onCountChange:n}){let{t:r}=i(),a=O(),[s,c]=(0,P.useState)(null),[l,d]=(0,P.useState)(null),m=N({queryKey:[`media-gallery`,e||`all`,t||0],queryFn:async({pageParam:t})=>{let n=await b.getGallery({limit:20,offset:t,...e?{kind:e}:{}});if(!n.success||!n.data)throw Error(n.message||r(`imageGallery.loadFailed`));return n.data},initialPageParam:0,getNextPageParam:(e,t)=>{let n=t.reduce((e,t)=>e+t.media.length,0);return n<e.total?n:void 0}}),h=(0,P.useMemo)(()=>m.data?.pages.flatMap(e=>e.media)||[],[m.data]),_=m.data?.pages[0]?.total||0;(0,P.useEffect)(()=>n?.(_),[n,_]);let v=async e=>{if(!l){d(e.id);try{let t=await b.deleteGalleryItem(e.id);if(!t.success)throw Error(t.message);c(null),await a.invalidateQueries({queryKey:[`media-gallery`]}),o.success(r(`imageGallery.deleteSuccess`))}catch{o.error(r(`imageGallery.deleteFailed`))}finally{d(null)}}},y=async e=>{let t=await b.getGalleryContent(e.id),n=URL.createObjectURL(t),r=document.createElement(`a`);r.href=n,r.download=`generated-${e.id}.${de(e.mimeType)}`,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)};return m.isLoading?(0,F.jsx)(`div`,{className:`flex justify-center py-12`,children:(0,F.jsx)(f,{className:`h-8 w-8 animate-spin text-gray-400`})}):h.length===0?(0,F.jsxs)(`div`,{className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-gray-300 bg-white/30 px-6 py-12 text-center dark:border-white/15 dark:bg-white/[0.02]`,children:[(0,F.jsx)(u,{className:`mb-4 h-10 w-10 text-gray-300 dark:text-gray-600`}),(0,F.jsx)(`h3`,{className:`text-lg font-medium`,children:r(`mediaGallery.empty`)}),(0,F.jsx)(`p`,{className:`mt-2 max-w-sm text-gray-500 dark:text-gray-400`,children:r(`mediaGallery.emptyHint`)})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:h.map(e=>(0,F.jsxs)(`article`,{className:`overflow-hidden rounded-2xl border border-gray-200/80 bg-white/70 dark:border-white/10 dark:bg-white/[0.025]`,children:[(0,F.jsx)(U,{item:e,onOpenImage:t=>c(W(e,t))}),(0,F.jsxs)(`div`,{className:`space-y-3 p-3`,children:[(0,F.jsx)(`p`,{className:`line-clamp-2 text-sm text-gray-800 dark:text-gray-200`,children:e.prompt}),(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,F.jsx)(`span`,{className:`min-w-0 truncate text-xs text-gray-500`,children:e.model}),(0,F.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,F.jsx)(`button`,{onClick:()=>void y(e),className:`rounded-lg p-1.5 hover:bg-gray-100 dark:hover:bg-white/10`,title:r(`imageGallery.download`),children:(0,F.jsx)(g,{className:`h-4 w-4`})}),(0,F.jsx)(`button`,{onClick:()=>void v(e),disabled:l===e.id,className:`rounded-lg p-1.5 hover:bg-red-500/15 hover:text-red-500`,title:r(`imageGallery.delete`),children:l===e.id?(0,F.jsx)(f,{className:`h-4 w-4 animate-spin`}):(0,F.jsx)(p,{className:`h-4 w-4`})})]})]})]})]},e.id))}),m.hasNextPage&&(0,F.jsx)(`div`,{className:`mt-8 flex justify-center`,children:(0,F.jsx)(w,{variant:`outline`,disabled:m.isFetchingNextPage,onClick:()=>void m.fetchNextPage(),children:m.isFetchingNextPage?r(`common.loading`):r(`imageGallery.loadMore`,{current:h.length,total:_})})}),s&&(0,F.jsx)(ue,{image:s,onClose:()=>c(null),onDelete:e=>{let t=h.find(t=>t.id===e);t&&v(t)},onDownload:e=>{let t=h.find(t=>t.id===e.id);t&&y(t)}})]})}function U({item:e,onOpenImage:t}){let{data:n,isLoading:r}=k({queryKey:[`media-gallery-content`,e.id],queryFn:()=>b.getGalleryContent(e.id),staleTime:3e5}),i=(0,P.useMemo)(()=>n?URL.createObjectURL(n):``,[n]);return(0,P.useEffect)(()=>()=>{i&&URL.revokeObjectURL(i)},[i]),r||!i?(0,F.jsx)(`div`,{className:`flex aspect-video items-center justify-center bg-gray-100 dark:bg-white/[0.03]`,children:(0,F.jsx)(f,{className:`h-6 w-6 animate-spin text-gray-400`})}):e.kind===`image`?(0,F.jsx)(`button`,{className:`block aspect-square w-full overflow-hidden`,onClick:()=>t(i),children:(0,F.jsx)(`img`,{src:i,alt:e.prompt,className:`h-full w-full object-cover`,loading:`lazy`})}):e.kind===`video`?(0,F.jsx)(`div`,{className:`aspect-video bg-black`,children:(0,F.jsx)(`video`,{src:i,controls:!0,preload:`metadata`,className:`h-full w-full object-contain`})}):(0,F.jsxs)(`div`,{className:`flex min-h-40 flex-col items-center justify-center gap-3 bg-gradient-to-br from-primary-500/10 to-cyan-500/10 p-4`,children:[(0,F.jsx)(h,{className:`h-9 w-9 text-primary-500`}),(0,F.jsx)(`audio`,{src:i,controls:!0,preload:`metadata`,className:`w-full`})]})}function W(e,t){return{id:e.id,userId:e.userId,prompt:e.prompt,model:e.model,imageData:t,size:e.size,quality:e.quality,createdAt:e.createdAt}}function de(e){let t=e.split(`/`)[1]?.split(`;`)[0];return t===`mpeg`?e.startsWith(`audio/`)?`mp3`:`mpeg`:t===`svg+xml`?`svg`:t||`bin`}var G=()=>{let{t:e}=i(),[t,n]=(0,P.useState)(null),[r,o]=(0,P.useState)(!1),[s,l]=(0,P.useState)(null),[u,d]=(0,P.useState)(`all`),[f,p]=(0,P.useState)(0),m=ne(e=>e.preferences.imageGenSettings?.enabled===!0),g=(0,P.useCallback)(()=>{p(e=>e+1)},[]);return(0,F.jsxs)(T,{width:`wide`,children:[(0,F.jsx)(E,{title:e(`sidebar.navigation.imagine`),description:e(`gallery.subtitle`),meta:t!==null&&t>0?(0,F.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(`mediaGallery.itemCount`,{count:t})}):null,actions:(0,F.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,F.jsxs)(w,{onClick:()=>{m&&o(!0)},disabled:!m,className:`gap-2 px-4`,children:[(0,F.jsx)(v,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`gallery.generate`)]}),(0,F.jsxs)(w,{variant:`outline`,onClick:()=>l(`video`),className:`gap-2 px-4`,children:[(0,F.jsx)(c,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.video`)]}),(0,F.jsxs)(w,{variant:`outline`,onClick:()=>l(`audio`),className:`gap-2 px-4`,children:[(0,F.jsx)(h,{className:`h-4 w-4`,"aria-hidden":`true`}),e(`mediaGeneration.audio`)]})]})}),(0,F.jsx)(`div`,{className:`mb-5 flex flex-wrap gap-2`,children:[`all`,`image`,`video`,`audio`].map(t=>(0,F.jsx)(`button`,{type:`button`,onClick:()=>d(t),className:a(`rounded-full border px-3 py-1.5 text-sm transition-colors`,u===t?`border-gray-950 bg-gray-950 text-white dark:border-white dark:bg-white dark:text-gray-950`:`border-gray-200 text-gray-600 hover:border-gray-400 dark:border-white/10 dark:text-dark-600`),children:e(`mediaGallery.filters.${t}`)},t))}),(0,F.jsx)(H,{kind:u===`all`?void 0:u,refreshKey:f,onCountChange:n}),(0,F.jsx)(oe,{isOpen:r&&m,onClose:()=>o(!1),onImageGenerated:g}),(0,F.jsx)(L,{isOpen:s!==null,initialKind:s||`video`,onClose:()=>l(null),onGenerated:g},s||`closed`)]})};export{G as GalleryPage,G as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{d as r}from"./router-vendor-CbPDks39.js";import{t as i}from"./useTranslation-C3ei3mJq.js";import{a,r as o,t as s}from"./utils-CuC1beTY.js";import{t as c}from"./chatStore-
|
|
1
|
+
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{m as t,p as n}from"./markdown-core-BmPPZiuD.js";import{d as r}from"./router-vendor-CbPDks39.js";import{t as i}from"./useTranslation-C3ei3mJq.js";import{a,r as o,t as s}from"./utils-CuC1beTY.js";import{t as c}from"./chatStore-BK6YcouV.js";import{$ as l,At as u,E as d,Jt as f,bn as p,c as m,hn as h,ot as g}from"./ui-vendor-54SgntkX.js";import{n as _,u as v}from"./authStore-CwSMGkEM.js";import{d as y,f as b,m as x,p as S,t as C}from"../assets/index-BXMQqOXF.js";import{t as w}from"./work-DVgm81bJ.js";var T=e(t(),1),E=n(),D=e=>e<5?[`home.greeting.night`,`Up late`]:e<12?[`home.greeting.morning`,`Morning`]:e<18?[`home.greeting.afternoon`,`Afternoon`]:[`home.greeting.evening`,`Evening`],O=`mb-2 text-xs font-medium text-gray-500 dark:text-dark-500`,k=`group flex w-full items-center gap-2.5 rounded-lg px-2.5 py-1.5 text-start text-sm text-gray-700 transition-colors hover:bg-white hover:text-gray-950 dark:text-dark-700 dark:hover:bg-dark-200 dark:hover:text-dark-950 outline-none focus-visible:ring-2 focus-visible:ring-primary-500/40`,A=()=>{let{t:e,i18n:t}=i(),n=r(),{user:A,systemInfo:j,canUseWork:M,canUseAgents:N}=_(),P=c(e=>e.sessions),F=v(e=>e.tasks),I=v(e=>e.capabilities),L=v(e=>e.loadTasks),R=v(e=>e.loadCapabilities),z=M(),B=N();(0,T.useEffect)(()=>{z&&(L(!0).catch(()=>{}),R().catch(()=>{}))},[z,L,R]);let[V,H]=D(new Date().getHours()),U=e(V,H),W=A?.username,G=[...P].sort((e,t)=>t.updatedAt-e.updatedAt).slice(0,4),K=[...F].sort((e,t)=>new Date(t.updatedAt).getTime()-new Date(e.updatedAt).getTime()).slice(0,3),q=I?.activeRuntimes?.user??0,J=a()?`⌘`:`Ctrl`,Y=G.length>0||K.length>0,X=C(j?.version);return(0,E.jsx)(`div`,{"data-testid":`home-page`,className:`h-full overflow-y-auto scrollbar-thin`,children:(0,E.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-xl flex-col justify-center px-6 py-12`,children:[(0,E.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-gray-950 dark:text-dark-950`,children:W?`${U}, ${W}.`:`${U}.`}),(0,E.jsxs)(`p`,{"data-testid":`app-version`,className:`mt-1 font-mono text-xs text-gray-400 dark:text-dark-500`,children:[window.location.host||`Libre WebUI`,X?` · v${X}`:``]}),(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsx)(`p`,{className:O,children:e(`home.start`,`Start`)}),(0,E.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-new-chat`,className:k,onClick:()=>b(n),children:[(0,E.jsx)(g,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,E.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newChat`,`New Chat`)}),(0,E.jsxs)(`span`,{className:`font-mono text-[10px] tracking-wide text-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,children:[J,`⇧O`]})]}),(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-incognito-chat`,className:k,onClick:()=>y(n),children:[(0,E.jsx)(u,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,E.jsx)(`span`,{className:`flex-1`,children:e(`chat.session.incognito`,`Incognito Chat`)})]}),z&&(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-new-work`,className:k,onClick:()=>S(n),children:[(0,E.jsx)(h,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,E.jsx)(`span`,{className:`flex-1`,children:e(`tabs.newWork`,`New Work`)}),(0,E.jsxs)(`span`,{className:`font-mono text-[10px] tracking-wide text-gray-400 opacity-0 transition-opacity group-hover:opacity-100 dark:text-dark-500`,children:[J,`⇧U`]})]})]})]}),Y&&(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsxs)(`div`,{className:`mb-2 flex items-baseline justify-between`,children:[(0,E.jsx)(`p`,{className:s(O,`mb-0`),children:e(`home.continue`,`Continue`)}),z&&q>0&&(0,E.jsxs)(`span`,{className:`flex items-center gap-1.5 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:[(0,E.jsx)(`span`,{className:`h-1.5 w-1.5 animate-pulse-subtle rounded-full bg-[rgb(48,121,255)]`}),q,` `,e(`home.active`,`active`)]})]}),(0,E.jsxs)(`div`,{className:`-mx-2.5 flex flex-col`,children:[K.map(r=>{let i=x[r.status];return(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-work`,className:k,onClick:()=>n(`/work/${r.id}`),children:[(0,E.jsx)(`span`,{"aria-hidden":`true`,className:s(`h-2 w-2 shrink-0 rounded-full ring-1 ring-black/[0.06] dark:ring-white/[0.1]`,i.animated&&`animate-pulse-subtle`),style:{backgroundColor:i.color}}),(0,E.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`work.tasks.untitled`,`Untitled task`)}),r.hostPath&&(0,E.jsx)(`span`,{className:`hidden max-w-[14rem] shrink-0 truncate font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,title:r.hostPath,children:r.hostPath}),(0,E.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:w(r)?e(i.labelKey,i.label):o(new Date(r.updatedAt).getTime(),t.language)})]},r.id)}),G.map(r=>(0,E.jsxs)(`button`,{type:`button`,"data-testid":`home-continue-chat`,className:k,onClick:()=>n(`/c/${r.id}`),children:[(0,E.jsx)(g,{className:`h-4 w-4 shrink-0 text-gray-400 dark:text-dark-500`}),(0,E.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:r.title||e(`tabs.chat`,`Chat`)}),(0,E.jsx)(`span`,{className:`hidden shrink-0 font-mono text-[10px] text-gray-400 sm:inline dark:text-dark-500`,children:r.model}),(0,E.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-gray-400 dark:text-dark-500`,children:o(r.updatedAt,t.language)})]},r.id))]})]}),(0,E.jsxs)(`div`,{className:`mt-8`,children:[(0,E.jsx)(`p`,{className:O,children:e(`home.explore`,`Explore`)}),(0,E.jsx)(`div`,{className:`-mx-2.5 flex flex-col`,children:[[`/notes`,l,e(`sidebar.navigation.notes`,`Notes`)],[`/models`,f,e(`sidebar.navigation.models`,`Models`)],[`/personas`,m,e(`sidebar.navigation.personas`,`Personas`)],[`/gallery`,d,e(`sidebar.navigation.imagine`,`Imagine`)],...B?[[`/agents`,p,e(`sidebar.navigation.agents`,`Agents`)]]:[]].map(([e,t,r])=>(0,E.jsxs)(`button`,{type:`button`,className:k,onClick:()=>n(e),children:[(0,E.jsx)(t,{className:`h-4 w-4 shrink-0 text-gray-400 transition-colors group-hover:text-gray-600 dark:text-dark-500 dark:group-hover:text-dark-700`}),(0,E.jsx)(`span`,{className:`flex-1`,children:r})]},e))})]})]})})};export{A as HomePage,A as default};
|