libre-webui 0.46.0 → 0.46.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/package.json +1 -1
- package/frontend/dist/artifact-runtime/.build-fingerprint +1 -1
- package/frontend/dist/assets/index-CoUBuPQV.js +22 -0
- package/frontend/dist/index.html +20 -20
- package/frontend/dist/js/{ArtifactContainer-BaacvZ8q.js → ArtifactContainer-BJcZu1hG.js} +1 -1
- package/frontend/dist/js/{ArtifactDemoPage-D6pgt8_p.js → ArtifactDemoPage-CEDmVq5I.js} +1 -1
- package/frontend/dist/js/{ArtifactSandboxFrame-BqfRwsQa.js → ArtifactSandboxFrame-iQ9iHO6_.js} +1 -1
- package/frontend/dist/js/{ArtifactSlideOutPanel-BUFb1QaC.js → ArtifactSlideOutPanel-DbfUsCO5.js} +1 -1
- package/frontend/dist/js/{AutomationModal-a9rx93qd.js → AutomationModal-B7im0l4E.js} +1 -1
- package/frontend/dist/js/{AutomationsPage-Bhzy71Cq.js → AutomationsPage-Dr-r5D8f.js} +1 -1
- package/frontend/dist/js/{AvatarUpload-BHHUA-GH.js → AvatarUpload-C3Qy8TkH.js} +1 -1
- package/frontend/dist/js/{CalendarPage-DIlOEXA9.js → CalendarPage-B-wEyqL9.js} +1 -1
- package/frontend/dist/js/{ChannelsPage-BRVs-Kp-.js → ChannelsPage-D3zDMyuU.js} +1 -1
- package/frontend/dist/js/{ChatPage-DqEa_l2u.js → ChatPage-WCWH7j7x.js} +1 -1
- package/frontend/dist/js/{ConnectModels-dimFaMkn.js → ConnectModels-BGp65ytJ.js} +1 -1
- package/frontend/dist/js/{EvaluationsPage-BKVxoUaS.js → EvaluationsPage-BruiPXWA.js} +1 -1
- package/frontend/dist/js/{FirstTimeSetup-MLU3EUOv.js → FirstTimeSetup-pQ-MjnV4.js} +1 -1
- package/frontend/dist/js/{GalleryPage-BqhTNi2p.js → GalleryPage-BIplR7z2.js} +1 -1
- package/frontend/dist/js/{HomePage-B_HbAwgO.js → HomePage-DTtLoltD.js} +1 -1
- package/frontend/dist/js/{LanguageSwitcher-gij6QsCJ.js → LanguageSwitcher-BkXPcNb2.js} +1 -1
- package/frontend/dist/js/{ModelManagerModals-CfcrXIm5.js → ModelManagerModals-DsatvqGr.js} +1 -1
- package/frontend/dist/js/{NotesPage-6qb7awMu.js → NotesPage-CMRTIRbO.js} +1 -1
- package/frontend/dist/js/{PasswordStrengthMeter-MkydwQ8j.js → PasswordStrengthMeter-arTXSwnR.js} +1 -1
- package/frontend/dist/js/{PersonasPage-KRnYk61s.js → PersonasPage-DJy7cCqu.js} +1 -1
- package/frontend/dist/js/{PluginUsagePage-Bm2WXYM5.js → PluginUsagePage-DdX4daCa.js} +1 -1
- package/frontend/dist/js/{RichMessageContent-fyjhRYjT.js → RichMessageContent-BPUCydw1.js} +1 -1
- package/frontend/dist/js/{RichMessageContent-C5hmCcK6.js → RichMessageContent-cM5Pw4o8.js} +1 -1
- package/frontend/dist/js/{SettingsModal-CgtaiEwd.js → SettingsModal-Cx8tQ7zn.js} +3 -3
- package/frontend/dist/js/{ShareDialog-lkQnQmeI.js → ShareDialog-yVjcJ0jy.js} +1 -1
- package/frontend/dist/js/{StrandsPage-sPvcnqzA.js → StrandsPage-C_waoiMS.js} +1 -1
- package/frontend/dist/js/{SystemPage-DwL4p4Rm.js → SystemPage-DaD_JM8S.js} +1 -1
- package/frontend/dist/js/{UserManagementPanel-Dz8Q_Nv7.js → UserManagementPanel-25s9fB6P.js} +1 -1
- package/frontend/dist/js/{WhatsNewModal-CSYCRxyb.js → WhatsNewModal-BZyBsxQZ.js} +1 -1
- package/frontend/dist/js/{WorkPage-zNqtL6D7.js → WorkPage-lCLLCn8L.js} +1 -1
- package/frontend/dist/js/api-BJuWvfL0.js +1 -0
- package/frontend/dist/js/{api-B8EjExUU.js → api-__EtZkwT.js} +1 -1
- package/frontend/dist/js/{appNavigation-C0lNX2LE.js → appNavigation-DtGGxIz_.js} +1 -1
- package/frontend/dist/js/{appStore-BEjqPvpR.js → appStore-xMQ42B4m.js} +2 -2
- package/frontend/dist/js/appVersion-Cx_TO0aQ.js +1 -0
- package/frontend/dist/js/ar-iaqJGlG8.js +2 -0
- package/frontend/dist/js/authStore-BAzfDKkW.js +1 -0
- package/frontend/dist/js/{authStore-BOFcWqii.js → authStore-VeRUWwzv.js} +3 -3
- package/frontend/dist/js/{chatStore-C3c3r8iB.js → chatStore-DM7NfNs8.js} +3 -3
- package/frontend/dist/js/{client-CQZUgw7R.js → client-DBMImFzz.js} +2 -2
- package/frontend/dist/js/{config-Dz__g4tp.js → config-CfmQhxhj.js} +1 -1
- package/frontend/dist/js/de-DrWNHRFs.js +2 -0
- package/frontend/dist/js/{decisionsApi-DWyjcL8B.js → decisionsApi-1EPksZmY.js} +1 -1
- package/frontend/dist/js/decisionsApi-C7Juo1Av.js +1 -0
- package/frontend/dist/js/{evaluationsApi-BE2P4V0I.js → evaluationsApi-BomOD9nq.js} +1 -1
- package/frontend/dist/js/{messageCodeStyles-QRyNUcEv.js → messageCodeStyles-C4KLlfl_.js} +1 -1
- package/frontend/dist/js/{modelPresentation-BqdYlMRq.js → modelPresentation-Jp0roUnl.js} +1 -1
- package/frontend/dist/js/{strandsApi-EFMF0J0x.js → strandsApi-oOCOwXJJ.js} +1 -1
- package/frontend/dist/js/{teamEventStream-aQGd68I4.js → teamEventStream-BGsxBKrP.js} +1 -1
- package/frontend/dist/js/{ui-CKcr9ReZ.js → ui-D5Ws30mx.js} +2 -2
- package/frontend/dist/js/{ui-vendor-BanHlKMb.js → ui-vendor-CmYUVVjB.js} +1 -1
- package/frontend/dist/js/{useChat-DFozXoci.js → useChat-B3oRF8Vk.js} +1 -1
- package/frontend/dist/js/{useDictation-D9lyoqUR.js → useDictation-DzQ0p1L7.js} +1 -1
- package/frontend/dist/js/{workApi-C2R6IiSd.js → workApi-B2IWKsfe.js} +1 -1
- package/frontend/dist/js/workApi-BVxaDn6b.js +1 -0
- package/package.json +1 -1
- package/frontend/dist/assets/index-CjeHi5JU.js +0 -76
- package/frontend/dist/js/api-CCDH67RO.js +0 -1
- package/frontend/dist/js/appVersion-Dv97-qD1.js +0 -1
- package/frontend/dist/js/ar-BM7CvBiJ.js +0 -2
- package/frontend/dist/js/authStore-BNu5iRKd.js +0 -1
- package/frontend/dist/js/de-DtSkfuOa.js +0 -2
- package/frontend/dist/js/decisionsApi-DJWWXd5m.js +0 -1
- package/frontend/dist/js/workApi-CNDPo0bG.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r}from"./router-vendor-ihzG-2y7.js";import{t as i}from"./useTranslation-Bu0AxynE.js";import{At as a,H as o,In as s,Ot as c,Pt as l,Qn as u,Qt as d,Rt as ee,W as f,at as p,br as te,er as m,fr as ne,kr as h,n as g,r as _,s as re,st as ie,tr as v,tt as ae,ut as oe,v as se,wn as y}from"./ui-vendor-BanHlKMb.js";import{_ as b,g as x,i as ce,n as le,r as S,t as C,v as w}from"./ui-CKcr9ReZ.js";import{t as T}from"./confirmStore-CKkUtP9c.js";import{i as E,t as D}from"./utils-DhBboyBg.js";import{t as O}from"./Button-DeV-GhQr.js";import{D as k}from"./api-B8EjExUU.js";import{t as ue}from"./teamEventStream-aQGd68I4.js";import{t as de}from"./authStore-BOFcWqii.js";import{t as fe}from"./chatStore-C3c3r8iB.js";import{t as pe}from"./logger-DAQsBb8I.js";var A=e(t(),1),j=n(),me=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],M=180,he=({calls:e})=>{let{t}=i(),[n,r]=(0,A.useState)(!1),a=e.some(e=>e.status===`denied`);return(0,j.jsxs)(`div`,{className:`mt-1`,"data-testid":`channel-tool-calls`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,className:`flex items-center gap-1 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,"data-testid":`channel-tool-calls-toggle`,children:[n?(0,j.jsx)(m,{className:`h-3 w-3`}):(0,j.jsx)(u,{className:`h-3 w-3`}),(0,j.jsx)(_,{className:`h-3 w-3`}),t(`channels.toolCalls.summary`,{total:e.length})]}),n&&(0,j.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[e.map(e=>(0,j.jsxs)(`div`,{className:`rounded-lg border border-black/6 px-2 py-1 dark:border-white/8`,"data-testid":`channel-tool-call`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,j.jsx)(`span`,{dir:`ltr`,className:`min-w-0 truncate text-[11px] font-medium text-gray-700 dark:text-dark-800`,children:e.name}),(0,j.jsx)(`span`,{className:D(`shrink-0 text-[10px]`,e.status===`succeeded`?`text-emerald-600 dark:text-emerald-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:e.status===`failed`?`text-red-500`:`text-gray-400 dark:text-dark-500`),children:t(`tools.callStatus.${e.status}`)})]}),e.resultPreview&&(0,j.jsx)(`p`,{dir:`ltr`,className:`mt-0.5 whitespace-pre-wrap wrap-break-word font-mono text-[10px] leading-snug text-gray-500 dark:text-dark-600`,children:e.resultPreview.slice(0,M)})]},e.id)),a&&(0,j.jsx)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:t(`channels.toolCalls.deniedHint`)})]})]})},ge=({message:e,currentUserId:t,canModerate:n,actions:r,compact:a=!1})=>{let{t:o,i18n:s}=i(),[l,u]=(0,A.useState)(!1),[d,f]=(0,A.useState)(e.content),[te,m]=(0,A.useState)(!1),h=e.authorKind===`model`,_=!h&&e.author?.userId===t&&!e.deleted,re=h?e.model??o(`channels.modelAuthor`):e.author?.username??o(`channels.unknownAuthor`);return(0,j.jsxs)(`div`,{className:D(`group relative rounded-xl px-2.5 py-1.5 hover:bg-black/2.5 dark:hover:bg-white/3`,a&&`px-2 py-1`),"data-testid":`channel-message`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[h&&(0,j.jsx)(ne,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,j.jsx)(`span`,{className:D(`shrink-0 text-[13px] font-semibold`,h?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:re}),(0,j.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:E(e.createdAt,s.language)}),e.editedAt&&!e.deleted&&(0,j.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:o(`channels.edited`)}),e.pinnedAt&&(0,j.jsx)(p,{role:`img`,"aria-label":o(`channels.pins`),className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,j.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:o(`channels.deletedMessage`)}):l?(0,j.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,j.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),rows:2,"aria-label":o(`channels.edit`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2 py-1 text-[13px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-message-edit`}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,d),u(!1)},"aria-label":o(`channels.confirmEdit`),title:o(`channels.confirmEdit`),className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,j.jsx)(v,{className:`h-3.5 w-3.5`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(!1),"aria-label":o(`channels.cancelEdit`),title:o(`channels.cancelEdit`),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]}):(0,j.jsxs)(j.Fragment,{children:[e.pending?(0,j.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,j.jsx)(ee,{className:`h-3.5 w-3.5 animate-spin`}),o(`channels.modelThinking`)]}):e.error?(0,j.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,j.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),h&&(e.toolCalls?.length??0)>0&&(0,j.jsx)(he,{calls:e.toolCalls}),(e.attachments?.length??0)>0&&(0,j.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>void r.onDownload(e.id,e.filename),className:`flex items-center gap-1.5 rounded-lg border border-black/6 px-2 py-1 text-[12px] text-gray-600 hover:bg-black/3 dark:border-white/8 dark:text-dark-700 dark:hover:bg-white/4`,"data-testid":`channel-attachment`,children:[(0,j.jsx)(oe,{className:`h-3 w-3`}),(0,j.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,j.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,j.jsxs)(`button`,{type:`button`,"aria-pressed":t.mine,onClick:()=>void r.onReact(e,t.emoji,t.mine),className:D(`rounded-full border px-1.5 py-0.5 text-[11px]`,t.mine?`border-primary-400/50 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-black/8 text-gray-600 hover:bg-black/3 dark:border-white/10 dark:text-dark-700`),"data-testid":`channel-reaction`,children:[t.emoji,` `,t.count]},t.emoji))}),!a&&(e.replyCount??0)>0&&r.onReply&&(0,j.jsxs)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`mt-1 flex items-center gap-1 text-[11px] font-medium text-primary-600 hover:underline dark:text-primary-400`,"data-testid":`channel-reply-count`,children:[(0,j.jsx)(c,{className:`h-3 w-3`}),o(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!l&&(0,j.jsxs)(`div`,{className:`absolute -top-2.5 inset-e-2 hidden items-center gap-0.5 rounded-lg border border-black/8 bg-white px-1 py-0.5 shadow-xs group-focus-within:flex group-hover:flex [@media(hover:none)]:flex dark:border-white/10 dark:bg-dark-50`,children:[(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.react`),"aria-label":o(`channels.react`),"aria-haspopup":`true`,"aria-expanded":te,"data-testid":`channel-react`,children:(0,j.jsx)(y,{className:`h-3.5 w-3.5`})}),te&&(0,j.jsx)(`div`,{className:`absolute inset-e-0 top-6 z-10 flex gap-0.5 rounded-lg border border-black/8 bg-white p-1 shadow-md dark:border-white/10 dark:bg-dark-50`,children:me.map(t=>(0,j.jsx)(`button`,{type:`button`,onClick:()=>{let n=!!e.reactions?.find(e=>e.emoji===t)?.mine;r.onReact(e,t,n),m(!1)},"aria-label":o(`channels.reactWith`,{emoji:t}),className:`rounded-sm p-0.5 text-sm hover:bg-black/5 dark:hover:bg-white/8`,children:t},t))})]}),r.onReply&&!e.parentId&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.reply`),"aria-label":o(`channels.reply`),"data-testid":`channel-reply`,children:(0,j.jsx)(c,{className:`h-3.5 w-3.5`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>void r.onPin(e),className:`rounded-sm p-1 text-gray-400 hover:text-amber-500`,title:e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"aria-label":e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"data-testid":`channel-pin`,children:(0,j.jsx)(p,{className:`h-3.5 w-3.5`})}),_&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>{f(e.content),u(!0)},className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.edit`),"aria-label":o(`channels.edit`),"data-testid":`channel-edit`,children:(0,j.jsx)(ie,{className:`h-3.5 w-3.5`})}),(_||n)&&(0,j.jsx)(`button`,{type:`button`,onClick:async()=>{await T({title:o(`channels.deleteMessageConfirmTitle`),description:o(`channels.deleteMessageConfirmDescription`),destructive:!0})&&await r.onDelete(e)},className:`rounded-sm p-1 text-gray-400 hover:text-red-500`,title:o(`channels.deleteMessage`),"aria-label":o(`channels.deleteMessage`),"data-testid":`channel-delete-message`,children:(0,j.jsx)(se,{className:`h-3.5 w-3.5`})})]})]})},N=pe(`pages:channels`),_e=e=>e.type===`dm`?(0,j.jsx)(a,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,j.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}):(0,j.jsx)(d,{className:`h-3.5 w-3.5 shrink-0`}),P=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,ve=()=>{let{t:e}=i(),t=de(e=>e.user),n=fe(e=>e.models),[l,u]=(0,A.useState)([]),[m,_]=(0,A.useState)(null),[ie,v]=(0,A.useState)(!1),[se,y]=(0,A.useState)(!1),[b,x]=(0,A.useState)(!0),[C,w]=(0,A.useState)(null),[E,pe]=(0,A.useState)(null),[me,M]=(0,A.useState)([]),[he,ve]=(0,A.useState)([]),[F,I]=(0,A.useState)(null),[L,R]=(0,A.useState)(null),[Ce,z]=(0,A.useState)([]),[B,we]=(0,A.useState)(``),[V,Te]=(0,A.useState)(``),[H,Ee]=(0,A.useState)(!1),[U,De]=(0,A.useState)(null),[Oe,ke]=(0,A.useState)(!1),[Ae,je]=(0,A.useState)(!1),[W,Me]=(0,A.useState)(``),[Ne,G]=(0,A.useState)(!1),Pe=(0,A.useRef)(null),Fe=(0,A.useRef)(null),[Ie,Le]=r(),K=(0,A.useMemo)(()=>l.find(e=>e.id===C)??null,[l,C]),[Re,ze]=(0,A.useState)(null);C!==Re&&(ze(C),pe(null),R(null),I(null));let q=K?.role===`owner`,J=(0,A.useCallback)(()=>{k.listMine().then(e=>{e.success&&e.data&&u(e.data)}).catch(e=>N.error(`Failed to load channels:`,e)).finally(()=>x(!1))},[]);(0,A.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=Ie.get(`channel`);Y&&C!==Y&&w(Y),(0,A.useEffect)(()=>{Y&&Le({},{replace:!0})},[Y,Le]);let X=(0,A.useRef)(null);(0,A.useLayoutEffect)(()=>(X.current=C?{channelId:C,requestId:0}:null,()=>{X.current=null}),[C]);let Z=(0,A.useCallback)(t=>{let n=X.current;if(!n||n.channelId!==t)return;let r=++n.requestId;k.listMessages(t,{limit:100}).then(e=>{X.current===n&&n.requestId===r&&e.success&&e.data&&pe(e.data)}).catch(t=>{N.error(`Failed to load messages:`,t),h.error(e(`channels.loadFailed`),{id:`channels-load-failed`})})},[e]),Be=(0,A.useRef)(null);(0,A.useEffect)(()=>{Be.current=L},[L]);let Ve=(0,A.useCallback)(e=>{Z(e),k.markRead(e);let t=Be.current;t&&k.thread(t).then(e=>{e.success&&e.data&&z(e.data)}).catch(e=>N.error(`Failed to refresh thread:`,e))},[Z]);(0,A.useEffect)(()=>{if(!C)return;Z(C),k.markRead(C).then(J);let e=new AbortController;return ue({path:`/channels/${C}/events`,signal:e.signal,onEvent:()=>Ve(C)}),()=>e.abort()},[C,Z,J,Ve]);let He=E?.length??0;(0,A.useEffect)(()=>{let e=Fe.current;e&&(e.scrollTop=e.scrollHeight)},[He,C]),(0,A.useEffect)(()=>{if(!C||!F)return;let t=t=>{N.error(`Failed to load channel panel:`,t),h.error(e(`channels.loadFailed`))};F===`members`?k.listMembers(C).then(e=>{e.success&&e.data?M(e.data):t(e.error)}).catch(t):k.listPins(C).then(e=>{e.success&&e.data?ve(e.data):t(e.error)}).catch(t)},[C,F,e]),(0,A.useEffect)(()=>{L&&k.thread(L).then(t=>{t.success&&t.data?z(t.data):h.error(e(`channels.loadFailed`))}).catch(t=>{N.error(`Failed to load thread:`,t),h.error(e(`channels.loadFailed`))})},[L,e]);let Ue=()=>{v(!0),y(!1),k.listPublic().then(e=>{e.success&&e.data?_(e.data):y(!0)}).catch(e=>{N.error(`Failed to load public channels:`,e),y(!0)})},Q=async t=>{if(!C||H)return;let n=B.trim();if(n||U){Ee(!0);try{let r=await k.postMessage(C,{content:n,...t?{parentId:t}:{},...U?{attachmentIds:[U.id]}:{},...V?{mentionModel:V}:{}});if(r.success){if(we(``),De(null),Te(``),Z(C),t){let e=await k.thread(t);e.success&&e.data&&z(e.data)}}else h.error(r.error||e(`channels.sendFailed`))}catch(t){N.error(`Failed to send message:`,t),h.error(e(`channels.sendFailed`))}finally{Ee(!1)}}},We=async t=>{if(C)try{let n=await k.uploadAttachment(C,t);n.success&&n.data?De({id:n.data.id,filename:n.data.filename}):h.error(n.error||e(`channels.uploadFailed`))}catch(t){N.error(`Failed to upload attachment:`,t),h.error(e(`channels.uploadFailed`))}},Ge=async()=>{if(C&&W.trim()){if((await k.addMember(C,W.trim()).catch(()=>void 0))?.success){Me(``);let t=await k.listMembers(C).catch(()=>void 0);t?.success&&t.data&&M(t.data),h.success(e(`channels.memberAdded`))}else h.error(e(`channels.memberAddFailed`))}},Ke={onReply:e=>R(e.id),onEdit:async(t,n)=>{(await k.editMessage(t.id,n).catch(()=>void 0))?.success?C&&Z(C):h.error(e(`channels.editFailed`))},onDelete:async t=>{(await k.deleteMessage(t.id).catch(()=>void 0))?.success?C&&Z(C):h.error(e(`channels.deleteMessageFailed`))},onPin:async t=>{(await k.setPinned(t.id,!t.pinnedAt).catch(()=>void 0))?.success||h.error(e(`channels.pinFailed`)),C&&Z(C)},onReact:async(t,n,r)=>{(await(r?k.removeReaction(t.id,n):k.addReaction(t.id,n)).catch(()=>void 0))?.success||h.error(e(`channels.reactFailed`)),C&&Z(C)},onDownload:async(t,n)=>{try{let e=await k.downloadAttachment(t),r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch(t){N.error(`Failed to download attachment:`,t),h.error(e(`channels.downloadFailed`))}}},$=Ce[0];return(0,j.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,j.jsxs)(`aside`,{className:D(`flex w-64 shrink-0 flex-col border-e border-black/6 dark:border-white/6`,C?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,j.jsx)(ce,{title:e(`channels.title`),className:`gap-y-1 px-3`,actions:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`button`,{type:`button`,onClick:Ue,title:e(`channels.browsePublic`),"aria-label":e(`channels.browsePublic`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-browse`,children:(0,j.jsx)(s,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>je(!0),title:e(`channels.newDm`),"aria-label":e(`channels.newDm`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new-dm`,children:(0,j.jsx)(a,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>ke(!0),title:e(`channels.newChannel`),"aria-label":e(`channels.newChannel`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new`,children:(0,j.jsx)(ae,{className:`h-4 w-4`})})]})}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:b?(0,j.jsx)(le,{size:`sm`,srOnly:!0}):l.length===0?(0,j.jsx)(S,{icon:d,size:`sm`,title:e(`channels.empty`)}):l.map(t=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>w(t.id),className:D(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-[13px]`,C===t.id?`bg-black/5 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-600 hover:bg-black/3 dark:text-dark-700 dark:hover:bg-white/4`),"data-testid":`channel-item`,children:[_e(t),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:P(t)}),(t.unreadCount??0)>0&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`span`,{className:`rounded-full bg-primary-600 px-1.5 text-[10px] font-semibold leading-4 text-white`,"data-testid":`channel-unread`,"aria-hidden":`true`,children:t.unreadCount}),(0,j.jsx)(`span`,{className:`sr-only`,children:e(`channels.unreadCount`,{total:t.unreadCount})})]})]},t.id))})]}),(0,j.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-black/6 px-4 py-2.5 dark:border-white/6`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>w(null),"aria-label":e(`common.back`),title:e(`common.back`),className:`rounded-md p-1 text-gray-500 hover:bg-black/4 md:hidden dark:text-dark-600`,children:(0,j.jsx)(te,{className:`h-4 w-4 rtl:rotate-180`})}),_e(K),(0,j.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,"data-testid":`channel-title`,children:P(K)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(F===`pins`?null:`pins`),title:e(`channels.pins`),"aria-label":e(`channels.pins`),"aria-pressed":F===`pins`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-pins-toggle`,children:(0,j.jsx)(p,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(F===`members`?null:`members`),title:e(`channels.members`),"aria-label":e(`channels.members`),"aria-pressed":F===`members`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-members-toggle`,children:(0,j.jsx)(re,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>G(!0),title:e(`channels.settings`),"aria-label":e(`channels.settings`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-settings`,children:(0,j.jsx)(o,{className:`h-4 w-4`})})]}),(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,j.jsx)(`div`,{ref:Fe,className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-4 py-3 scrollbar-thin`,"data-testid":`channel-timeline`,children:E===null?(0,j.jsx)(le,{size:`sm`,srOnly:!0}):E.length===0?(0,j.jsx)(S,{icon:c,size:`sm`,title:e(`channels.noMessages`)}):E.map(e=>(0,j.jsx)(ge,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke},e.id))}),(0,j.jsxs)(`div`,{className:`border-t border-black/6 p-3 dark:border-white/6`,children:[U&&(0,j.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-1.5 text-xs text-gray-600 dark:border-white/8 dark:text-dark-700`,children:[(0,j.jsx)(oe,{className:`h-3.5 w-3.5`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:U.filename}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>De(null),"aria-label":e(`channels.removeAttachment`),title:e(`channels.removeAttachment`),className:`rounded-sm p-0.5 text-gray-500 hover:text-red-500`,children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,j.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,j.jsx)(`input`,{ref:Pe,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&We(t),e.target.value=``}}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>Pe.current?.click(),title:e(`channels.attach`),"aria-label":e(`channels.attach`),className:`rounded-md p-2 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-attach`,children:(0,j.jsx)(oe,{className:`h-4 w-4`})}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(ne,{className:D(`h-4 w-4`,V?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,j.jsxs)(`select`,{value:V,onChange:e=>Te(e.target.value),className:`max-w-[130px] rounded-md border border-black/8 bg-transparent px-1 py-1 text-[11px] text-gray-600 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-dark-100 dark:text-dark-700`,title:e(`channels.askModel`),"aria-label":e(`channels.askModel`),"data-testid":`channel-mention-model`,children:[(0,j.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,j.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,j.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Q())},rows:1,placeholder:e(`channels.composerPlaceholder`),"aria-label":e(`channels.composerPlaceholder`),className:`max-h-32 min-w-0 flex-1 resize-none rounded-xl border border-black/8 bg-transparent px-3 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-composer`}),(0,j.jsx)(O,{size:`sm`,disabled:H||!B.trim()&&!U,onClick:()=>void Q(),"aria-label":e(`channels.send`),title:e(`channels.send`),"data-testid":`channel-send`,children:H?(0,j.jsx)(ee,{className:`h-4 w-4 animate-spin`}):(0,j.jsx)(f,{className:`h-4 w-4`})})]})]})]}),L&&(0,j.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-thread`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,j.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>R(null),"aria-label":e(`channels.closeThread`),title:e(`channels.closeThread`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:Ce.map(e=>(0,j.jsx)(ge,{message:e,currentUserId:t?.id,canModerate:q,actions:{...Ke,onReply:void 0},compact:!0},e.id))}),(0,j.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/6 p-2 dark:border-white/6`,children:[(0,j.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),$&&Q($.id))},rows:1,placeholder:e(`channels.replyPlaceholder`),"aria-label":e(`channels.replyPlaceholder`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-thread-composer`}),(0,j.jsx)(O,{size:`sm`,disabled:H||!B.trim(),onClick:()=>$&&void Q($.id),"aria-label":e(`channels.send`),title:e(`channels.send`),children:(0,j.jsx)(f,{className:`h-3.5 w-3.5`})})]})]}),F&&(0,j.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-${F}-panel`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,j.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(F===`members`?`channels.members`:`channels.pins`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(null),"aria-label":e(`common.close`),title:e(`common.close`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:F===`members`?(0,j.jsxs)(j.Fragment,{children:[q&&K.type===`private`&&(0,j.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,j.jsx)(`input`,{type:`text`,value:W,onChange:e=>Me(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&Ge()},placeholder:e(`channels.invitePlaceholder`),"aria-label":e(`channels.invitePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent px-2 py-1 text-xs focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-800`,"data-testid":`channel-invite-name`}),(0,j.jsx)(O,{size:`sm`,disabled:!W.trim(),onClick:()=>void Ge(),"aria-label":e(`channels.invite`),title:e(`channels.invite`),"data-testid":`channel-invite-submit`,children:(0,j.jsx)(ae,{className:`h-3.5 w-3.5`})})]}),me.map(n=>(0,j.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-700 dark:text-dark-800`,"data-testid":`channel-member`,children:[(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,j.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:n.role===`owner`?e(`channels.roleOwner`):``}),q&&n.userId!==t?.id&&K.type!==`dm`&&(0,j.jsx)(`button`,{type:`button`,onClick:async()=>{await T({title:e(`channels.removeMemberConfirm`,{name:n.username}),description:e(`channels.removeMemberConfirmDescription`),confirmLabel:e(`common.remove`),destructive:!0})&&((await k.removeMember(K.id,n.userId).catch(()=>void 0))?.success?M(e=>e.filter(e=>e.userId!==n.userId)):h.error(e(`channels.removeMemberFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:e(`channels.removeMember`),"aria-label":e(`channels.removeMemberNamed`,{name:n.username}),children:(0,j.jsx)(g,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,j.jsx)(O,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:async()=>{await T({title:e(`channels.leaveConfirm`,{name:P(K)}),description:e(`channels.leaveConfirmDescription`),confirmLabel:e(`channels.leave`),destructive:!0})&&((await k.removeMember(K.id,t?.id??``).catch(()=>void 0))?.success?(w(null),J()):h.error(e(`channels.leaveFailed`)))},"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):he.length===0?(0,j.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):he.map(e=>(0,j.jsx)(ge,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke,compact:!0},e.id))})]})]})]}):(0,j.jsx)(S,{icon:c,title:e(`channels.selectPrompt`),className:`flex-1 justify-center`})}),Oe&&(0,j.jsx)(ye,{onClose:()=>ke(!1),onCreated:e=>{ke(!1),J(),w(e.id)}}),Ae&&(0,j.jsx)(be,{onClose:()=>je(!1),onOpened:e=>{je(!1),J(),w(e.id)}}),ie&&(0,j.jsx)(xe,{channels:m,failed:se,onRetry:Ue,onClose:()=>v(!1),onJoined:e=>{v(!1),J(),w(e)}}),Ne&&K&&(0,j.jsx)(Se,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),w(null),J()}})]})},ye=({onClose:e,onCreated:t})=>{let{t:n}=i(),[r,a]=(0,A.useState)(``),[o,s]=(0,A.useState)(`public`),[c,l]=(0,A.useState)(``),[u,d]=(0,A.useState)(!1);return(0,j.jsxs)(x,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,j.jsx)(O,{size:`sm`,disabled:u||!r.trim(),onClick:()=>{d(!0),k.create({type:o,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):h.error(e.error||n(`channels.createFailed`))}).catch(()=>h.error(n(`channels.createFailed`))).finally(()=>d(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-name`,className:w,children:n(`channels.nameLabel`)}),(0,j.jsx)(`input`,{id:`create-channel-name`,className:b,value:r,onChange:e=>a(e.target.value),"data-testid":`create-channel-name`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-type`,className:w,children:n(`channels.typeLabel`)}),(0,j.jsxs)(`select`,{id:`create-channel-type`,className:b,value:o,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,j.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,j.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-description`,className:w,children:n(`channels.descriptionLabel`)}),(0,j.jsx)(`textarea`,{id:`create-channel-description`,className:b,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},be=({onClose:e,onOpened:t})=>{let{t:n}=i(),[r,a]=(0,A.useState)(``),[o,s]=(0,A.useState)(!1),c=()=>{r.trim()&&(s(!0),k.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):h.error(e.error||n(`channels.dmFailed`))}).catch(()=>h.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,j.jsx)(x,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,j.jsx)(O,{size:`sm`,disabled:o||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,j.jsx)(`input`,{className:b,value:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"aria-label":n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},xe=({channels:e,failed:t,onRetry:n,onClose:r,onJoined:a})=>{let{t:o}=i();return(0,j.jsx)(x,{titleId:`browse-channels-title`,title:o(`channels.browsePublic`),onClose:r,testId:`browse-channels-modal`,children:t&&e===null?(0,j.jsx)(C,{size:`sm`,message:o(`channels.loadFailed`),onRetry:n}):e===null?(0,j.jsx)(le,{size:`sm`,srOnly:!0}):e.length===0?(0,j.jsx)(S,{icon:s,size:`sm`,title:o(`channels.noPublic`)}):e.map(e=>(0,j.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-3 py-2 dark:border-white/8`,"data-testid":`browse-channel-item`,children:[(0,j.jsx)(d,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,j.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:o(`channels.joined`)}):(0,j.jsx)(O,{size:`sm`,onClick:()=>void k.join(e.id).then(t=>{t.success?a(e.id):h.error(o(`channels.joinFailed`))}).catch(()=>h.error(o(`channels.joinFailed`))),"data-testid":`browse-channel-join`,children:o(`channels.join`)})]},e.id))})},Se=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:a}=i(),[o,s]=(0,A.useState)(e.name),[c,l]=(0,A.useState)(e.description??``),[u,d]=(0,A.useState)(!1);return(0,j.jsxs)(x,{titleId:`channel-settings-title`,title:a(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,j.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,j.jsx)(O,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:async()=>{await T({title:a(`channels.deleteConfirm`,{name:e.name}),description:a(`channels.deleteConfirmDescription`),confirmLabel:a(`channels.delete`),destructive:!0})&&((await k.delete(e.id).catch(()=>void 0))?.success?r():h.error(a(`channels.deleteFailed`)))},"data-testid":`channel-delete`,children:a(`channels.delete`)}),(0,j.jsx)(O,{size:`sm`,disabled:u||!o.trim(),onClick:()=>{d(!0),k.update(e.id,{name:o.trim(),description:c.trim()}).then(e=>{e.success?n():h.error(a(`channels.saveFailed`))}).catch(()=>h.error(a(`channels.saveFailed`))).finally(()=>d(!1))},"data-testid":`channel-settings-save`,children:a(`channels.save`)})]}),children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`channel-settings-name`,className:w,children:a(`channels.nameLabel`)}),(0,j.jsx)(`input`,{id:`channel-settings-name`,className:b,value:o,onChange:e=>s(e.target.value)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`channel-settings-description`,className:w,children:a(`channels.descriptionLabel`)}),(0,j.jsx)(`textarea`,{id:`channel-settings-description`,className:b,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{ve as default};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{i as r}from"./router-vendor-ihzG-2y7.js";import{t as i}from"./useTranslation-Bu0AxynE.js";import{At as a,H as o,In as s,Ot as c,Pt as l,Qn as u,Qt as d,Rt as ee,W as f,at as p,br as te,er as m,fr as ne,kr as h,n as g,r as _,s as re,st as ie,tr as v,tt as ae,ut as oe,v as se,wn as y}from"./ui-vendor-CmYUVVjB.js";import{_ as b,g as x,i as ce,n as le,r as S,t as C,v as w}from"./ui-D5Ws30mx.js";import{t as T}from"./confirmStore-CKkUtP9c.js";import{i as E,t as D}from"./utils-DhBboyBg.js";import{t as O}from"./Button-DeV-GhQr.js";import{D as k}from"./api-__EtZkwT.js";import{t as ue}from"./teamEventStream-BGsxBKrP.js";import{t as de}from"./authStore-VeRUWwzv.js";import{t as fe}from"./chatStore-DM7NfNs8.js";import{t as pe}from"./logger-DAQsBb8I.js";var A=e(t(),1),j=n(),me=[`👍`,`🎉`,`❤️`,`😄`,`👀`,`🚀`],M=180,he=({calls:e})=>{let{t}=i(),[n,r]=(0,A.useState)(!1),a=e.some(e=>e.status===`denied`);return(0,j.jsxs)(`div`,{className:`mt-1`,"data-testid":`channel-tool-calls`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),"aria-expanded":n,className:`flex items-center gap-1 text-[11px] font-medium text-gray-500 hover:text-gray-700 dark:text-dark-600 dark:hover:text-dark-800`,"data-testid":`channel-tool-calls-toggle`,children:[n?(0,j.jsx)(m,{className:`h-3 w-3`}):(0,j.jsx)(u,{className:`h-3 w-3`}),(0,j.jsx)(_,{className:`h-3 w-3`}),t(`channels.toolCalls.summary`,{total:e.length})]}),n&&(0,j.jsxs)(`div`,{className:`mt-1 space-y-1`,children:[e.map(e=>(0,j.jsxs)(`div`,{className:`rounded-lg border border-black/6 px-2 py-1 dark:border-white/8`,"data-testid":`channel-tool-call`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-1.5`,children:[(0,j.jsx)(`span`,{dir:`ltr`,className:`min-w-0 truncate text-[11px] font-medium text-gray-700 dark:text-dark-800`,children:e.name}),(0,j.jsx)(`span`,{className:D(`shrink-0 text-[10px]`,e.status===`succeeded`?`text-emerald-600 dark:text-emerald-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:e.status===`failed`?`text-red-500`:`text-gray-400 dark:text-dark-500`),children:t(`tools.callStatus.${e.status}`)})]}),e.resultPreview&&(0,j.jsx)(`p`,{dir:`ltr`,className:`mt-0.5 whitespace-pre-wrap wrap-break-word font-mono text-[10px] leading-snug text-gray-500 dark:text-dark-600`,children:e.resultPreview.slice(0,M)})]},e.id)),a&&(0,j.jsx)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:t(`channels.toolCalls.deniedHint`)})]})]})},ge=({message:e,currentUserId:t,canModerate:n,actions:r,compact:a=!1})=>{let{t:o,i18n:s}=i(),[l,u]=(0,A.useState)(!1),[d,f]=(0,A.useState)(e.content),[te,m]=(0,A.useState)(!1),h=e.authorKind===`model`,_=!h&&e.author?.userId===t&&!e.deleted,re=h?e.model??o(`channels.modelAuthor`):e.author?.username??o(`channels.unknownAuthor`);return(0,j.jsxs)(`div`,{className:D(`group relative rounded-xl px-2.5 py-1.5 hover:bg-black/2.5 dark:hover:bg-white/3`,a&&`px-2 py-1`),"data-testid":`channel-message`,children:[(0,j.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[h&&(0,j.jsx)(ne,{className:`h-3.5 w-3.5 shrink-0 self-center text-primary-500`}),(0,j.jsx)(`span`,{className:D(`shrink-0 text-[13px] font-semibold`,h?`text-primary-600 dark:text-primary-400`:`text-gray-900 dark:text-dark-900`),children:re}),(0,j.jsx)(`span`,{className:`shrink-0 text-[11px] text-gray-400 dark:text-dark-500`,children:E(e.createdAt,s.language)}),e.editedAt&&!e.deleted&&(0,j.jsx)(`span`,{className:`shrink-0 text-[10px] text-gray-400 dark:text-dark-500`,children:o(`channels.edited`)}),e.pinnedAt&&(0,j.jsx)(p,{role:`img`,"aria-label":o(`channels.pins`),className:`h-3 w-3 shrink-0 text-amber-500`})]}),e.deleted?(0,j.jsx)(`p`,{className:`text-[13px] italic text-gray-400 dark:text-dark-500`,children:o(`channels.deletedMessage`)}):l?(0,j.jsxs)(`div`,{className:`mt-1 flex items-end gap-1.5`,children:[(0,j.jsx)(`textarea`,{value:d,onChange:e=>f(e.target.value),rows:2,"aria-label":o(`channels.edit`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2 py-1 text-[13px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-message-edit`}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>{r.onEdit(e,d),u(!1)},"aria-label":o(`channels.confirmEdit`),title:o(`channels.confirmEdit`),className:`rounded-md p-1.5 text-emerald-600 hover:bg-emerald-50 dark:hover:bg-emerald-900/20`,children:(0,j.jsx)(v,{className:`h-3.5 w-3.5`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>u(!1),"aria-label":o(`channels.cancelEdit`),title:o(`channels.cancelEdit`),className:`rounded-md p-1.5 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]}):(0,j.jsxs)(j.Fragment,{children:[e.pending?(0,j.jsxs)(`p`,{className:`flex items-center gap-1.5 text-[13px] text-gray-400 dark:text-dark-500`,children:[(0,j.jsx)(ee,{className:`h-3.5 w-3.5 animate-spin`}),o(`channels.modelThinking`)]}):e.error?(0,j.jsx)(`p`,{className:`text-[13px] text-red-500`,children:e.error}):(0,j.jsx)(`p`,{className:`whitespace-pre-wrap wrap-break-word text-[13px] leading-relaxed text-gray-800 dark:text-dark-800`,children:e.content}),h&&(e.toolCalls?.length??0)>0&&(0,j.jsx)(he,{calls:e.toolCalls}),(e.attachments?.length??0)>0&&(0,j.jsx)(`div`,{className:`mt-1 space-y-1`,children:e.attachments.map(e=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>void r.onDownload(e.id,e.filename),className:`flex items-center gap-1.5 rounded-lg border border-black/6 px-2 py-1 text-[12px] text-gray-600 hover:bg-black/3 dark:border-white/8 dark:text-dark-700 dark:hover:bg-white/4`,"data-testid":`channel-attachment`,children:[(0,j.jsx)(oe,{className:`h-3 w-3`}),(0,j.jsx)(`span`,{className:`min-w-0 truncate`,children:e.filename})]},e.id))})]}),(e.reactions?.length??0)>0&&(0,j.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.reactions.map(t=>(0,j.jsxs)(`button`,{type:`button`,"aria-pressed":t.mine,onClick:()=>void r.onReact(e,t.emoji,t.mine),className:D(`rounded-full border px-1.5 py-0.5 text-[11px]`,t.mine?`border-primary-400/50 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-black/8 text-gray-600 hover:bg-black/3 dark:border-white/10 dark:text-dark-700`),"data-testid":`channel-reaction`,children:[t.emoji,` `,t.count]},t.emoji))}),!a&&(e.replyCount??0)>0&&r.onReply&&(0,j.jsxs)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`mt-1 flex items-center gap-1 text-[11px] font-medium text-primary-600 hover:underline dark:text-primary-400`,"data-testid":`channel-reply-count`,children:[(0,j.jsx)(c,{className:`h-3 w-3`}),o(`channels.replyCount`,{total:e.replyCount})]}),!e.deleted&&!l&&(0,j.jsxs)(`div`,{className:`absolute -top-2.5 inset-e-2 hidden items-center gap-0.5 rounded-lg border border-black/8 bg-white px-1 py-0.5 shadow-xs group-focus-within:flex group-hover:flex [@media(hover:none)]:flex dark:border-white/10 dark:bg-dark-50`,children:[(0,j.jsxs)(`div`,{className:`relative`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.react`),"aria-label":o(`channels.react`),"aria-haspopup":`true`,"aria-expanded":te,"data-testid":`channel-react`,children:(0,j.jsx)(y,{className:`h-3.5 w-3.5`})}),te&&(0,j.jsx)(`div`,{className:`absolute inset-e-0 top-6 z-10 flex gap-0.5 rounded-lg border border-black/8 bg-white p-1 shadow-md dark:border-white/10 dark:bg-dark-50`,children:me.map(t=>(0,j.jsx)(`button`,{type:`button`,onClick:()=>{let n=!!e.reactions?.find(e=>e.emoji===t)?.mine;r.onReact(e,t,n),m(!1)},"aria-label":o(`channels.reactWith`,{emoji:t}),className:`rounded-sm p-0.5 text-sm hover:bg-black/5 dark:hover:bg-white/8`,children:t},t))})]}),r.onReply&&!e.parentId&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>r.onReply(e),className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.reply`),"aria-label":o(`channels.reply`),"data-testid":`channel-reply`,children:(0,j.jsx)(c,{className:`h-3.5 w-3.5`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>void r.onPin(e),className:`rounded-sm p-1 text-gray-400 hover:text-amber-500`,title:e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"aria-label":e.pinnedAt?o(`channels.unpin`):o(`channels.pin`),"data-testid":`channel-pin`,children:(0,j.jsx)(p,{className:`h-3.5 w-3.5`})}),_&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>{f(e.content),u(!0)},className:`rounded-sm p-1 text-gray-400 hover:text-gray-700 dark:hover:text-dark-800`,title:o(`channels.edit`),"aria-label":o(`channels.edit`),"data-testid":`channel-edit`,children:(0,j.jsx)(ie,{className:`h-3.5 w-3.5`})}),(_||n)&&(0,j.jsx)(`button`,{type:`button`,onClick:async()=>{await T({title:o(`channels.deleteMessageConfirmTitle`),description:o(`channels.deleteMessageConfirmDescription`),destructive:!0})&&await r.onDelete(e)},className:`rounded-sm p-1 text-gray-400 hover:text-red-500`,title:o(`channels.deleteMessage`),"aria-label":o(`channels.deleteMessage`),"data-testid":`channel-delete-message`,children:(0,j.jsx)(se,{className:`h-3.5 w-3.5`})})]})]})},N=pe(`pages:channels`),_e=e=>e.type===`dm`?(0,j.jsx)(a,{className:`h-3.5 w-3.5 shrink-0`}):e.type===`private`?(0,j.jsx)(l,{className:`h-3.5 w-3.5 shrink-0`}):(0,j.jsx)(d,{className:`h-3.5 w-3.5 shrink-0`}),P=e=>e.type===`dm`?e.dmPeer?.username??`…`:e.name,ve=()=>{let{t:e}=i(),t=de(e=>e.user),n=fe(e=>e.models),[l,u]=(0,A.useState)([]),[m,_]=(0,A.useState)(null),[ie,v]=(0,A.useState)(!1),[se,y]=(0,A.useState)(!1),[b,x]=(0,A.useState)(!0),[C,w]=(0,A.useState)(null),[E,pe]=(0,A.useState)(null),[me,M]=(0,A.useState)([]),[he,ve]=(0,A.useState)([]),[F,I]=(0,A.useState)(null),[L,R]=(0,A.useState)(null),[Ce,z]=(0,A.useState)([]),[B,we]=(0,A.useState)(``),[V,Te]=(0,A.useState)(``),[H,Ee]=(0,A.useState)(!1),[U,De]=(0,A.useState)(null),[Oe,ke]=(0,A.useState)(!1),[Ae,je]=(0,A.useState)(!1),[W,Me]=(0,A.useState)(``),[Ne,G]=(0,A.useState)(!1),Pe=(0,A.useRef)(null),Fe=(0,A.useRef)(null),[Ie,Le]=r(),K=(0,A.useMemo)(()=>l.find(e=>e.id===C)??null,[l,C]),[Re,ze]=(0,A.useState)(null);C!==Re&&(ze(C),pe(null),R(null),I(null));let q=K?.role===`owner`,J=(0,A.useCallback)(()=>{k.listMine().then(e=>{e.success&&e.data&&u(e.data)}).catch(e=>N.error(`Failed to load channels:`,e)).finally(()=>x(!1))},[]);(0,A.useEffect)(()=>{J();let e=window.setInterval(J,3e4);return()=>window.clearInterval(e)},[J]);let Y=Ie.get(`channel`);Y&&C!==Y&&w(Y),(0,A.useEffect)(()=>{Y&&Le({},{replace:!0})},[Y,Le]);let X=(0,A.useRef)(null);(0,A.useLayoutEffect)(()=>(X.current=C?{channelId:C,requestId:0}:null,()=>{X.current=null}),[C]);let Z=(0,A.useCallback)(t=>{let n=X.current;if(!n||n.channelId!==t)return;let r=++n.requestId;k.listMessages(t,{limit:100}).then(e=>{X.current===n&&n.requestId===r&&e.success&&e.data&&pe(e.data)}).catch(t=>{N.error(`Failed to load messages:`,t),h.error(e(`channels.loadFailed`),{id:`channels-load-failed`})})},[e]),Be=(0,A.useRef)(null);(0,A.useEffect)(()=>{Be.current=L},[L]);let Ve=(0,A.useCallback)(e=>{Z(e),k.markRead(e);let t=Be.current;t&&k.thread(t).then(e=>{e.success&&e.data&&z(e.data)}).catch(e=>N.error(`Failed to refresh thread:`,e))},[Z]);(0,A.useEffect)(()=>{if(!C)return;Z(C),k.markRead(C).then(J);let e=new AbortController;return ue({path:`/channels/${C}/events`,signal:e.signal,onEvent:()=>Ve(C)}),()=>e.abort()},[C,Z,J,Ve]);let He=E?.length??0;(0,A.useEffect)(()=>{let e=Fe.current;e&&(e.scrollTop=e.scrollHeight)},[He,C]),(0,A.useEffect)(()=>{if(!C||!F)return;let t=t=>{N.error(`Failed to load channel panel:`,t),h.error(e(`channels.loadFailed`))};F===`members`?k.listMembers(C).then(e=>{e.success&&e.data?M(e.data):t(e.error)}).catch(t):k.listPins(C).then(e=>{e.success&&e.data?ve(e.data):t(e.error)}).catch(t)},[C,F,e]),(0,A.useEffect)(()=>{L&&k.thread(L).then(t=>{t.success&&t.data?z(t.data):h.error(e(`channels.loadFailed`))}).catch(t=>{N.error(`Failed to load thread:`,t),h.error(e(`channels.loadFailed`))})},[L,e]);let Ue=()=>{v(!0),y(!1),k.listPublic().then(e=>{e.success&&e.data?_(e.data):y(!0)}).catch(e=>{N.error(`Failed to load public channels:`,e),y(!0)})},Q=async t=>{if(!C||H)return;let n=B.trim();if(n||U){Ee(!0);try{let r=await k.postMessage(C,{content:n,...t?{parentId:t}:{},...U?{attachmentIds:[U.id]}:{},...V?{mentionModel:V}:{}});if(r.success){if(we(``),De(null),Te(``),Z(C),t){let e=await k.thread(t);e.success&&e.data&&z(e.data)}}else h.error(r.error||e(`channels.sendFailed`))}catch(t){N.error(`Failed to send message:`,t),h.error(e(`channels.sendFailed`))}finally{Ee(!1)}}},We=async t=>{if(C)try{let n=await k.uploadAttachment(C,t);n.success&&n.data?De({id:n.data.id,filename:n.data.filename}):h.error(n.error||e(`channels.uploadFailed`))}catch(t){N.error(`Failed to upload attachment:`,t),h.error(e(`channels.uploadFailed`))}},Ge=async()=>{if(C&&W.trim()){if((await k.addMember(C,W.trim()).catch(()=>void 0))?.success){Me(``);let t=await k.listMembers(C).catch(()=>void 0);t?.success&&t.data&&M(t.data),h.success(e(`channels.memberAdded`))}else h.error(e(`channels.memberAddFailed`))}},Ke={onReply:e=>R(e.id),onEdit:async(t,n)=>{(await k.editMessage(t.id,n).catch(()=>void 0))?.success?C&&Z(C):h.error(e(`channels.editFailed`))},onDelete:async t=>{(await k.deleteMessage(t.id).catch(()=>void 0))?.success?C&&Z(C):h.error(e(`channels.deleteMessageFailed`))},onPin:async t=>{(await k.setPinned(t.id,!t.pinnedAt).catch(()=>void 0))?.success||h.error(e(`channels.pinFailed`)),C&&Z(C)},onReact:async(t,n,r)=>{(await(r?k.removeReaction(t.id,n):k.addReaction(t.id,n)).catch(()=>void 0))?.success||h.error(e(`channels.reactFailed`)),C&&Z(C)},onDownload:async(t,n)=>{try{let e=await k.downloadAttachment(t),r=URL.createObjectURL(e),i=document.createElement(`a`);i.href=r,i.download=n,i.click(),URL.revokeObjectURL(r)}catch(t){N.error(`Failed to download attachment:`,t),h.error(e(`channels.downloadFailed`))}}},$=Ce[0];return(0,j.jsxs)(`div`,{className:`flex h-full min-h-0`,children:[(0,j.jsxs)(`aside`,{className:D(`flex w-64 shrink-0 flex-col border-e border-black/6 dark:border-white/6`,C?`hidden md:flex`:`flex`),"data-testid":`channel-rail`,children:[(0,j.jsx)(ce,{title:e(`channels.title`),className:`gap-y-1 px-3`,actions:(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`button`,{type:`button`,onClick:Ue,title:e(`channels.browsePublic`),"aria-label":e(`channels.browsePublic`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-browse`,children:(0,j.jsx)(s,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>je(!0),title:e(`channels.newDm`),"aria-label":e(`channels.newDm`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new-dm`,children:(0,j.jsx)(a,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>ke(!0),title:e(`channels.newChannel`),"aria-label":e(`channels.newChannel`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channels-new`,children:(0,j.jsx)(ae,{className:`h-4 w-4`})})]})}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-2 pb-3 scrollbar-thin`,children:b?(0,j.jsx)(le,{size:`sm`,srOnly:!0}):l.length===0?(0,j.jsx)(S,{icon:d,size:`sm`,title:e(`channels.empty`)}):l.map(t=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>w(t.id),className:D(`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-start text-[13px]`,C===t.id?`bg-black/5 text-gray-900 dark:bg-white/8 dark:text-dark-900`:`text-gray-600 hover:bg-black/3 dark:text-dark-700 dark:hover:bg-white/4`),"data-testid":`channel-item`,children:[_e(t),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:P(t)}),(t.unreadCount??0)>0&&(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`span`,{className:`rounded-full bg-primary-600 px-1.5 text-[10px] font-semibold leading-4 text-white`,"data-testid":`channel-unread`,"aria-hidden":`true`,children:t.unreadCount}),(0,j.jsx)(`span`,{className:`sr-only`,children:e(`channels.unreadCount`,{total:t.unreadCount})})]})]},t.id))})]}),(0,j.jsx)(`main`,{className:`flex min-w-0 flex-1 flex-col`,children:K?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`header`,{className:`flex items-center gap-2 border-b border-black/6 px-4 py-2.5 dark:border-white/6`,children:[(0,j.jsx)(`button`,{type:`button`,onClick:()=>w(null),"aria-label":e(`common.back`),title:e(`common.back`),className:`rounded-md p-1 text-gray-500 hover:bg-black/4 md:hidden dark:text-dark-600`,children:(0,j.jsx)(te,{className:`h-4 w-4 rtl:rotate-180`})}),_e(K),(0,j.jsx)(`h2`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-gray-900 dark:text-dark-900`,"data-testid":`channel-title`,children:P(K)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(F===`pins`?null:`pins`),title:e(`channels.pins`),"aria-label":e(`channels.pins`),"aria-pressed":F===`pins`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-pins-toggle`,children:(0,j.jsx)(p,{className:`h-4 w-4`})}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(F===`members`?null:`members`),title:e(`channels.members`),"aria-label":e(`channels.members`),"aria-pressed":F===`members`,className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-members-toggle`,children:(0,j.jsx)(re,{className:`h-4 w-4`})}),q&&K.type!==`dm`&&(0,j.jsx)(`button`,{type:`button`,onClick:()=>G(!0),title:e(`channels.settings`),"aria-label":e(`channels.settings`),className:`rounded-md p-1.5 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-settings`,children:(0,j.jsx)(o,{className:`h-4 w-4`})})]}),(0,j.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,j.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,j.jsx)(`div`,{ref:Fe,className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-4 py-3 scrollbar-thin`,"data-testid":`channel-timeline`,children:E===null?(0,j.jsx)(le,{size:`sm`,srOnly:!0}):E.length===0?(0,j.jsx)(S,{icon:c,size:`sm`,title:e(`channels.noMessages`)}):E.map(e=>(0,j.jsx)(ge,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke},e.id))}),(0,j.jsxs)(`div`,{className:`border-t border-black/6 p-3 dark:border-white/6`,children:[U&&(0,j.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 rounded-lg border border-black/6 px-2.5 py-1.5 text-xs text-gray-600 dark:border-white/8 dark:text-dark-700`,children:[(0,j.jsx)(oe,{className:`h-3.5 w-3.5`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:U.filename}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>De(null),"aria-label":e(`channels.removeAttachment`),title:e(`channels.removeAttachment`),className:`rounded-sm p-0.5 text-gray-500 hover:text-red-500`,children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,j.jsxs)(`div`,{className:`flex items-end gap-1.5`,children:[(0,j.jsx)(`input`,{ref:Pe,type:`file`,className:`hidden`,onChange:e=>{let t=e.target.files?.[0];t&&We(t),e.target.value=``}}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>Pe.current?.click(),title:e(`channels.attach`),"aria-label":e(`channels.attach`),className:`rounded-md p-2 text-gray-500 hover:bg-black/4 dark:text-dark-600 dark:hover:bg-white/6`,"data-testid":`channel-attach`,children:(0,j.jsx)(oe,{className:`h-4 w-4`})}),(0,j.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,j.jsx)(ne,{className:D(`h-4 w-4`,V?`text-primary-500`:`text-gray-400 dark:text-dark-500`)}),(0,j.jsxs)(`select`,{value:V,onChange:e=>Te(e.target.value),className:`max-w-[130px] rounded-md border border-black/8 bg-transparent px-1 py-1 text-[11px] text-gray-600 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-dark-100 dark:text-dark-700`,title:e(`channels.askModel`),"aria-label":e(`channels.askModel`),"data-testid":`channel-mention-model`,children:[(0,j.jsx)(`option`,{value:``,children:e(`channels.noModel`)}),n.map(e=>(0,j.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),(0,j.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),Q())},rows:1,placeholder:e(`channels.composerPlaceholder`),"aria-label":e(`channels.composerPlaceholder`),className:`max-h-32 min-w-0 flex-1 resize-none rounded-xl border border-black/8 bg-transparent px-3 py-2 text-[13px] text-gray-900 placeholder:text-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-composer`}),(0,j.jsx)(O,{size:`sm`,disabled:H||!B.trim()&&!U,onClick:()=>void Q(),"aria-label":e(`channels.send`),title:e(`channels.send`),"data-testid":`channel-send`,children:H?(0,j.jsx)(ee,{className:`h-4 w-4 animate-spin`}):(0,j.jsx)(f,{className:`h-4 w-4`})})]})]})]}),L&&(0,j.jsxs)(`aside`,{className:`flex w-80 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-thread`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,j.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(`channels.thread`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>R(null),"aria-label":e(`channels.closeThread`),title:e(`channels.closeThread`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1 overflow-y-auto px-3 py-2 scrollbar-thin`,children:Ce.map(e=>(0,j.jsx)(ge,{message:e,currentUserId:t?.id,canModerate:q,actions:{...Ke,onReply:void 0},compact:!0},e.id))}),(0,j.jsxs)(`div`,{className:`flex items-end gap-1.5 border-t border-black/6 p-2 dark:border-white/6`,children:[(0,j.jsx)(`textarea`,{value:B,onChange:e=>we(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),$&&Q($.id))},rows:1,placeholder:e(`channels.replyPlaceholder`),"aria-label":e(`channels.replyPlaceholder`),className:`min-w-0 flex-1 resize-none rounded-lg border border-black/8 bg-transparent px-2.5 py-1.5 text-[13px] text-gray-900 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-900`,"data-testid":`channel-thread-composer`}),(0,j.jsx)(O,{size:`sm`,disabled:H||!B.trim(),onClick:()=>$&&void Q($.id),"aria-label":e(`channels.send`),title:e(`channels.send`),children:(0,j.jsx)(f,{className:`h-3.5 w-3.5`})})]})]}),F&&(0,j.jsxs)(`aside`,{className:`flex w-72 shrink-0 flex-col border-s border-black/6 dark:border-white/6`,"data-testid":`channel-${F}-panel`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-black/6 px-3 py-2 dark:border-white/6`,children:[(0,j.jsx)(`span`,{className:`flex-1 text-xs font-semibold uppercase tracking-wide text-gray-500 dark:text-dark-600`,children:e(F===`members`?`channels.members`:`channels.pins`)}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>I(null),"aria-label":e(`common.close`),title:e(`common.close`),className:`rounded-md p-1 text-gray-400 hover:bg-black/4 dark:hover:bg-white/6`,children:(0,j.jsx)(g,{className:`h-3.5 w-3.5`})})]}),(0,j.jsx)(`div`,{className:`min-h-0 flex-1 space-y-1.5 overflow-y-auto px-3 py-2 scrollbar-thin`,children:F===`members`?(0,j.jsxs)(j.Fragment,{children:[q&&K.type===`private`&&(0,j.jsxs)(`div`,{className:`mb-2 flex gap-1.5`,children:[(0,j.jsx)(`input`,{type:`text`,value:W,onChange:e=>Me(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.nativeEvent.isComposing&&Ge()},placeholder:e(`channels.invitePlaceholder`),"aria-label":e(`channels.invitePlaceholder`),className:`min-w-0 flex-1 rounded-lg border border-black/8 bg-transparent px-2 py-1 text-xs focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:text-dark-800`,"data-testid":`channel-invite-name`}),(0,j.jsx)(O,{size:`sm`,disabled:!W.trim(),onClick:()=>void Ge(),"aria-label":e(`channels.invite`),title:e(`channels.invite`),"data-testid":`channel-invite-submit`,children:(0,j.jsx)(ae,{className:`h-3.5 w-3.5`})})]}),me.map(n=>(0,j.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg px-2 py-1.5 text-[13px] text-gray-700 dark:text-dark-800`,"data-testid":`channel-member`,children:[(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:n.username}),(0,j.jsx)(`span`,{className:`text-[10px] uppercase text-gray-400 dark:text-dark-500`,children:n.role===`owner`?e(`channels.roleOwner`):``}),q&&n.userId!==t?.id&&K.type!==`dm`&&(0,j.jsx)(`button`,{type:`button`,onClick:async()=>{await T({title:e(`channels.removeMemberConfirm`,{name:n.username}),description:e(`channels.removeMemberConfirmDescription`),confirmLabel:e(`common.remove`),destructive:!0})&&((await k.removeMember(K.id,n.userId).catch(()=>void 0))?.success?M(e=>e.filter(e=>e.userId!==n.userId)):h.error(e(`channels.removeMemberFailed`)))},className:`rounded-sm p-1 text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20`,title:e(`channels.removeMember`),"aria-label":e(`channels.removeMemberNamed`,{name:n.username}),children:(0,j.jsx)(g,{className:`h-3 w-3`})})]},n.userId)),!q&&K.type!==`dm`&&(0,j.jsx)(O,{size:`sm`,variant:`ghost`,className:`mt-2 w-full text-red-500`,onClick:async()=>{await T({title:e(`channels.leaveConfirm`,{name:P(K)}),description:e(`channels.leaveConfirmDescription`),confirmLabel:e(`channels.leave`),destructive:!0})&&((await k.removeMember(K.id,t?.id??``).catch(()=>void 0))?.success?(w(null),J()):h.error(e(`channels.leaveFailed`)))},"data-testid":`channel-leave`,children:e(`channels.leave`)})]}):he.length===0?(0,j.jsx)(`p`,{className:`pt-4 text-center text-xs text-gray-400 dark:text-dark-500`,children:e(`channels.noPins`)}):he.map(e=>(0,j.jsx)(ge,{message:e,currentUserId:t?.id,canModerate:q,actions:Ke,compact:!0},e.id))})]})]})]}):(0,j.jsx)(S,{icon:c,title:e(`channels.selectPrompt`),className:`flex-1 justify-center`})}),Oe&&(0,j.jsx)(ye,{onClose:()=>ke(!1),onCreated:e=>{ke(!1),J(),w(e.id)}}),Ae&&(0,j.jsx)(be,{onClose:()=>je(!1),onOpened:e=>{je(!1),J(),w(e.id)}}),ie&&(0,j.jsx)(xe,{channels:m,failed:se,onRetry:Ue,onClose:()=>v(!1),onJoined:e=>{v(!1),J(),w(e)}}),Ne&&K&&(0,j.jsx)(Se,{channel:K,onClose:()=>G(!1),onChanged:()=>{G(!1),J()},onDeleted:()=>{G(!1),w(null),J()}})]})},ye=({onClose:e,onCreated:t})=>{let{t:n}=i(),[r,a]=(0,A.useState)(``),[o,s]=(0,A.useState)(`public`),[c,l]=(0,A.useState)(``),[u,d]=(0,A.useState)(!1);return(0,j.jsxs)(x,{titleId:`create-channel-title`,title:n(`channels.newChannel`),onClose:e,testId:`create-channel-modal`,footer:(0,j.jsx)(O,{size:`sm`,disabled:u||!r.trim(),onClick:()=>{d(!0),k.create({type:o,name:r.trim(),...c.trim()?{description:c.trim()}:{}}).then(e=>{e.success&&e.data?t(e.data):h.error(e.error||n(`channels.createFailed`))}).catch(()=>h.error(n(`channels.createFailed`))).finally(()=>d(!1))},"data-testid":`create-channel-submit`,children:n(`channels.create`)}),children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-name`,className:w,children:n(`channels.nameLabel`)}),(0,j.jsx)(`input`,{id:`create-channel-name`,className:b,value:r,onChange:e=>a(e.target.value),"data-testid":`create-channel-name`})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-type`,className:w,children:n(`channels.typeLabel`)}),(0,j.jsxs)(`select`,{id:`create-channel-type`,className:b,value:o,onChange:e=>s(e.target.value),"data-testid":`create-channel-type`,children:[(0,j.jsx)(`option`,{value:`public`,children:n(`channels.typePublic`)}),(0,j.jsx)(`option`,{value:`private`,children:n(`channels.typePrivate`)})]})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`create-channel-description`,className:w,children:n(`channels.descriptionLabel`)}),(0,j.jsx)(`textarea`,{id:`create-channel-description`,className:b,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})},be=({onClose:e,onOpened:t})=>{let{t:n}=i(),[r,a]=(0,A.useState)(``),[o,s]=(0,A.useState)(!1),c=()=>{r.trim()&&(s(!0),k.openDm(r.trim()).then(e=>{e.success&&e.data?t(e.data):h.error(e.error||n(`channels.dmFailed`))}).catch(()=>h.error(n(`channels.dmFailed`))).finally(()=>s(!1)))};return(0,j.jsx)(x,{titleId:`open-dm-title`,title:n(`channels.newDm`),subtitle:n(`channels.dmHint`),onClose:e,testId:`open-dm-modal`,footer:(0,j.jsx)(O,{size:`sm`,disabled:o||!r.trim(),onClick:c,"data-testid":`open-dm-submit`,children:n(`channels.openDm`)}),children:(0,j.jsx)(`input`,{className:b,value:r,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},placeholder:n(`channels.dmPlaceholder`),"aria-label":n(`channels.dmPlaceholder`),"data-testid":`open-dm-username`})})},xe=({channels:e,failed:t,onRetry:n,onClose:r,onJoined:a})=>{let{t:o}=i();return(0,j.jsx)(x,{titleId:`browse-channels-title`,title:o(`channels.browsePublic`),onClose:r,testId:`browse-channels-modal`,children:t&&e===null?(0,j.jsx)(C,{size:`sm`,message:o(`channels.loadFailed`),onRetry:n}):e===null?(0,j.jsx)(le,{size:`sm`,srOnly:!0}):e.length===0?(0,j.jsx)(S,{icon:s,size:`sm`,title:o(`channels.noPublic`)}):e.map(e=>(0,j.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border border-black/6 px-3 py-2 dark:border-white/8`,"data-testid":`browse-channel-item`,children:[(0,j.jsx)(d,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}),(0,j.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-[13px] text-gray-800 dark:text-dark-800`,children:e.name}),e.isMember?(0,j.jsx)(`span`,{className:`text-[11px] text-gray-400`,children:o(`channels.joined`)}):(0,j.jsx)(O,{size:`sm`,onClick:()=>void k.join(e.id).then(t=>{t.success?a(e.id):h.error(o(`channels.joinFailed`))}).catch(()=>h.error(o(`channels.joinFailed`))),"data-testid":`browse-channel-join`,children:o(`channels.join`)})]},e.id))})},Se=({channel:e,onClose:t,onChanged:n,onDeleted:r})=>{let{t:a}=i(),[o,s]=(0,A.useState)(e.name),[c,l]=(0,A.useState)(e.description??``),[u,d]=(0,A.useState)(!1);return(0,j.jsxs)(x,{titleId:`channel-settings-title`,title:a(`channels.settings`),onClose:t,testId:`channel-settings-modal`,footer:(0,j.jsxs)(`div`,{className:`flex w-full items-center justify-between`,children:[(0,j.jsx)(O,{size:`sm`,variant:`ghost`,className:`text-red-500`,onClick:async()=>{await T({title:a(`channels.deleteConfirm`,{name:e.name}),description:a(`channels.deleteConfirmDescription`),confirmLabel:a(`channels.delete`),destructive:!0})&&((await k.delete(e.id).catch(()=>void 0))?.success?r():h.error(a(`channels.deleteFailed`)))},"data-testid":`channel-delete`,children:a(`channels.delete`)}),(0,j.jsx)(O,{size:`sm`,disabled:u||!o.trim(),onClick:()=>{d(!0),k.update(e.id,{name:o.trim(),description:c.trim()}).then(e=>{e.success?n():h.error(a(`channels.saveFailed`))}).catch(()=>h.error(a(`channels.saveFailed`))).finally(()=>d(!1))},"data-testid":`channel-settings-save`,children:a(`channels.save`)})]}),children:[(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`channel-settings-name`,className:w,children:a(`channels.nameLabel`)}),(0,j.jsx)(`input`,{id:`channel-settings-name`,className:b,value:o,onChange:e=>s(e.target.value)})]}),(0,j.jsxs)(`div`,{children:[(0,j.jsx)(`label`,{htmlFor:`channel-settings-description`,className:w,children:a(`channels.descriptionLabel`)}),(0,j.jsx)(`textarea`,{id:`channel-settings-description`,className:b,rows:2,value:c,onChange:e=>l(e.target.value)})]})]})};export{ve as default};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{d as i,f as a,u as o}from"./router-vendor-ihzG-2y7.js";import{t as s}from"./useTranslation-Bu0AxynE.js";import{Bt as c,Ct as l,F as u,G as d,Hn as f,J as p,Jt as m,L as h,Ln as g,M as _,Nn as v,O as y,Or as b,P as x,Pn as S,Q as C,Qn as w,Rn as T,Rt as E,S as ee,Tt as D,V as O,X as k,Zn as A,_n as te,_r as ne,a as j,an as re,b as ie,c as M,cr as ae,ct as oe,er as N,g as P,jn as F,kr as I,ln as se,lr as ce,m as le,mr as ue,n as L,o as de,p as fe,pr as pe,qt as me,r as he,rn as ge,sn as _e,st as R,tr as ve,tt as ye,ut as be,v as xe,vr as Se,wt as Ce,xr as we,y as Te,yn as z,zn as Ee}from"./ui-vendor-BanHlKMb.js";import{a as De,i as Oe,n as B,s as ke,t as V}from"./utils-DhBboyBg.js";import{_ as H,f as U,g as Ae,m as je,p as W,u as Me,v as Ne}from"./ui-CKcr9ReZ.js";import{t as Pe}from"./ArtifactContainer-BaacvZ8q.js";import{N as G,_ as K,a as Fe,d as q,f as Ie,g as Le,i as J,j as Re,m as ze,n as Be,p as Ve,t as He,w as Ue,x as We,y as Ge}from"./api-B8EjExUU.js";import{t as Ke}from"./appStore-BEjqPvpR.js";import{a as qe,t as Y}from"./logger-DAQsBb8I.js";import{a as Je,i as Ye,o as Xe,r as Ze,s as Qe,t as $e}from"./ttsBatching-yVvnRS5S.js";import{a as et,i as tt,n as nt,o as rt,r as it}from"./useChat-DFozXoci.js";import{E as at,_ as ot,a as st,d as ct,f as lt,g as ut,h as dt,i as ft,l as pt,m as mt,n as ht,o as gt,p as _t,r as vt,t as X,u as yt,v as bt}from"./chatStore-C3c3r8iB.js";import{t as xt}from"./LogoMark-CiSslCTm.js";import{t as St}from"./authStore-BOFcWqii.js";import{t as Ct}from"./useDialogFocus-DpTun-ZV.js";import{t as wt}from"./evaluationsApi-BE2P4V0I.js";import{l as Tt}from"./messageCodeStyles-QRyNUcEv.js";import{t as Z}from"./Button-DeV-GhQr.js";import{n as Et,r as Dt,t as Ot}from"./useDictation-D9lyoqUR.js";import{d as kt,f as At,l as jt,t as Mt}from"./modelPresentation-BqdYlMRq.js";import{n as Nt,t as Pt}from"./composerStyles-BEx0XAp6.js";import{t as Ft}from"./ConnectModels-dimFaMkn.js";import{i as It,r as Lt,t as Rt}from"./welcomePrompts-to5mv_gx.js";var zt=n(),Q=e(t(),1),$=r(),Bt=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},Vt=({status:e})=>e===`running`||e===`awaiting_approval`?(0,$.jsx)(E,{className:`h-3.5 w-3.5 animate-spin`}):e===`succeeded`?(0,$.jsx)(ve,{className:`h-3.5 w-3.5 text-green-600 dark:text-green-400`}):e===`denied`?(0,$.jsx)(L,{className:`h-3.5 w-3.5 text-amber-600 dark:text-amber-400`}):(0,$.jsx)(P,{className:`h-3.5 w-3.5 text-red-500 dark:text-red-400`}),Ht=({call:e})=>{let{t}=s(),[n,r]=(0,Q.useState)(!1),i=t(`tools.callStatus.${e.status}`);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-200 bg-gray-50 dark:bg-dark-50 text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-start`,"aria-expanded":n,children:[n?(0,$.jsx)(N,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(w,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 rtl:rotate-180`}),(0,$.jsx)(he,{className:`h-3.5 w-3.5 shrink-0 text-gray-500 dark:text-gray-400`}),(0,$.jsx)(`span`,{className:`truncate font-medium text-gray-700 dark:text-gray-200`,dir:`ltr`,children:e.name}),e.serverName&&(0,$.jsx)(`span`,{className:`truncate text-xs text-gray-500 dark:text-gray-400`,children:e.serverName}),(0,$.jsxs)(`span`,{className:V(`ms-auto flex shrink-0 items-center gap-1 text-xs`,e.status===`succeeded`?`text-green-600 dark:text-green-400`:e.status===`failed`?`text-red-500 dark:text-red-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(Vt,{status:e.status}),i]})]}),n&&(0,$.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 dark:border-dark-200`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.arguments`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Bt(e.arguments)}),e.resultPreview!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-2 text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.result`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:e.resultPreview})]})]})]})},Ut=({calls:e,className:t})=>e.length===0?null:(0,$.jsx)(`div`,{className:V(`flex flex-col gap-1.5`,t),children:e.map(e=>(0,$.jsx)(Ht,{call:e},e.id))}),Wt=({approval:e,onDecide:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),o=(0,Q.useId)(),c=async(n,r)=>{a(!0);try{await t(e.approvalId,n,r)}catch{a(!1)}},l=r(`tools.approval.description`,{tool:e.toolCall.name,server:e.toolCall.serverName??r(`tools.approval.builtinSource`)});return(0,$.jsxs)(`div`,{role:`group`,"aria-labelledby":o,className:V(`rounded-lg border border-primary-300/70 bg-primary-50 p-3 text-sm dark:border-primary-700/60 dark:bg-primary-900/20`,n),children:[(0,$.jsxs)(`span`,{className:`sr-only`,role:`alert`,"aria-live":`assertive`,children:[r(`tools.approval.title`),`. `,l]}),(0,$.jsxs)(`div`,{id:o,className:`flex items-center gap-2 font-medium text-primary-800 dark:text-primary-200`,children:[(0,$.jsx)(h,{className:`h-4 w-4 shrink-0`}),r(`tools.approval.title`)]}),(0,$.jsx)(`p`,{className:`mt-1 text-primary-800/90 dark:text-primary-100/80`,children:l}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded-sm bg-white/70 p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Bt(e.toolCall.arguments)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(Z,{size:`sm`,disabled:i,onClick:()=>void c(!0,`once`),children:r(`tools.approval.allowOnce`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void c(!0,`session`),children:r(`tools.approval.allowSession`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void c(!0,`always`),children:r(`tools.approval.allowAlways`)}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>void c(!1,`once`),children:r(`tools.approval.deny`)})]})]})},Gt=({statistics:e,expanded:t,onExpandedChange:n,hideModel:r=!1,className:i})=>{let{t:a,i18n:o}=s(),c=(0,Q.useId)(),l=(e,t)=>e.toLocaleString(o.language,{minimumFractionDigits:t,maximumFractionDigits:t}),u=e=>{if(e==null)return a(`generationStats.notAvailable`);let t=e/1e6;if(t<1e3)return`${Math.round(t).toLocaleString(o.language)}ms`;let n=t/1e3;return`${l(n,2)}s`},d=e=>e?a(`generationStats.tokensPerSecond`,{value:l(e,1)}):a(`generationStats.notAvailable`),f=e.prompt_eval_count||0,p=e.eval_count||0,m=f+p,h=u(e.total_duration),g=d(e.tokens_per_second),_=[[a(`generationStats.promptTokens`),f],[a(`generationStats.generatedTokens`),p],[a(`generationStats.totalTokens`),m],[a(`generationStats.speed`),g],[a(`generationStats.promptEval`),u(e.prompt_eval_duration)],[a(`generationStats.generation`),u(e.eval_duration)],[a(`generationStats.modelLoad`),u(e.load_duration)],[a(`generationStats.totalTime`),h]];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{"data-testid":`generation-stats`,className:V(`flex min-w-0 items-center gap-3 text-xs tabular-nums text-ink-subtle`,i),children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),"aria-expanded":t,"aria-controls":c,title:a(`generationStats.details`),className:`flex items-center gap-1 rounded-md transition-colors hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,children:[(0,$.jsx)(me,{"aria-hidden":`true`,className:`h-3 w-3`}),a(`generationStats.tokenCount`,{tokens:p.toLocaleString(o.language)})]}),(0,$.jsx)(`span`,{children:g}),(0,$.jsx)(`span`,{children:h}),e.model&&!r&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate sm:max-w-48`,title:e.model,children:e.model})]}),t&&(0,$.jsxs)(`div`,{id:c,className:`mt-1.5 basis-full rounded-xl border border-line bg-surface-subtle p-3 text-xs`,children:[(0,$.jsx)(`dl`,{className:`grid max-w-md grid-cols-2 gap-x-4 gap-y-1.5`,children:_.map(([e,t])=>(0,$.jsxs)(`div`,{className:`flex gap-1 text-ink-muted`,children:[(0,$.jsx)(`dt`,{className:`font-medium text-ink`,children:e}),(0,$.jsx)(`dd`,{className:`tabular-nums`,children:t})]},e))}),e.created_at&&(0,$.jsxs)(`p`,{className:`mt-2 border-t border-line pt-2 text-ink-muted`,children:[(0,$.jsx)(`span`,{className:`font-medium text-ink`,children:a(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString(o.language)]})]})]})},Kt={maxQuestions:64,minOptions:2,maxOptions:255,minLevels:2,maxLevels:10},qt=(e=`noul`)=>({type:e,instructions:``,options:[{name:``,description:``},{name:``,description:``}],levels:[``,``,``],trueDescription:``,falseDescription:``});function Jt(e){return Object.values(e??{}).map(e=>{let t=qt(e.type);return t.instructions=e.instructions,e.type===`choice`?t.options=Object.entries(e.criteria).map(([e,t])=>({name:e,description:t??``})):e.type===`score`?t.levels=[...e.criteria]:(t.trueDescription=e.criteria?.true??``,t.falseDescription=e.criteria?.false??``),t})}function Yt(e){if(e.length>Kt.maxQuestions)return{ok:!1,error:{kind:`too-many`}};let t={};for(let[n,r]of e.entries()){let e=n+1,i=r.instructions.trim();if(!i)return{ok:!1,error:{kind:`instructions`,question:e}};if(r.type===`choice`){let n=r.options.map(e=>({name:e.name.trim(),description:e.description.trim()})).filter(e=>e.name||e.description),a=new Set(n.map(e=>e.name));if(n.some(e=>!e.name)||a.size!==n.length||n.length<Kt.minOptions||n.length>Kt.maxOptions)return{ok:!1,error:{kind:`options`,question:e}};t[`q${e}`]={type:`choice`,instructions:i,criteria:Object.fromEntries(n.map(e=>[e.name,e.description||null]))}}else if(r.type===`score`){let n=r.levels.map(e=>e.trim()).filter(Boolean);if(n.length<Kt.minLevels||n.length>Kt.maxLevels)return{ok:!1,error:{kind:`levels`,question:e}};t[`q${e}`]={type:`score`,instructions:i,criteria:n}}else{let n=r.trueDescription.trim(),a=r.falseDescription.trim();t[`q${e}`]=n||a?{type:`noul`,instructions:i,criteria:{...n?{true:n}:{},...a?{false:a}:{}}}:{type:`noul`,instructions:i}}}return{ok:!0,questions:Object.keys(t).length>0?t:void 0}}function Xt(e,t){if(!t||t.type===`refusal`)return{label:``,kind:`refusal`,distribution:[]};if(t.type===`noul`){let e=t.noul>=.5;return{label:``,kind:e?`yes`:`no`,probability:e?t.noul:1-t.noul,distribution:[{label:`yes`,probability:t.noul},{label:`no`,probability:1-t.noul}],...t.confidence===void 0?{}:{confidence:t.confidence}}}let n=Object.entries(t.probabilities).map(([e,n])=>({label:t.type===`score`?t.legend[e]??e:String(e),probability:n})).sort((e,t)=>t.probability-e.probability);if(t.type===`choice`)return{label:t.choice,kind:`choice`,probability:t.probabilities[t.choice],distribution:n,...t.confidence===void 0?{}:{confidence:t.confidence}};let r=e?.type===`score`?e.criteria.length:Object.keys(t.legend).length;return{label:n[0]?.label??``,kind:`score`,probability:n[0]?.probability,score:{value:t.score+1,max:r},distribution:n,...t.confidence===void 0?{}:{confidence:t.confidence}}}var Zt=e=>`${(Math.round(e*1e3)/10).toFixed(1)}%`;function Qt(e){let t=e?.decision;if(!t||typeof t!=`object`)return null;let n=t.kind;return n===`state`||n===`cleared`?{kind:n}:n===`answers`&&typeof t.questions==`object`&&typeof t.answers==`object`?t:null}var $t=({value:e,strong:t})=>(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`h-1.5 w-full overflow-hidden rounded-full bg-gray-100 dark:bg-dark-200`,children:(0,$.jsx)(`div`,{className:V(`h-full rounded-full`,t?`bg-primary-500 dark:bg-primary-400`:`bg-gray-300 dark:bg-dark-400`),style:{width:`${Math.max(0,Math.min(1,e))*100}%`}})}),en=({metadata:e})=>{let{t}=s();if(e.kind!==`answers`)return(0,$.jsx)(`p`,{"data-testid":`decision-result-note`,className:`text-sm text-ink-muted`,children:e.kind===`state`?t(`chat.decision.result.stateSaved`):t(`chat.decision.result.cleared`)});let n=e.usage?.inputTokens;return(0,$.jsxs)(`div`,{"data-testid":`decision-result`,className:`space-y-3`,children:[Object.entries(e.questions).map(([n,r])=>{let i=Xt(r,e.answers[n]),a=i.kind===`refusal`?t(`chat.decision.result.declined`):i.kind===`yes`?t(`chat.decision.result.yes`):i.kind===`no`?t(`chat.decision.result.no`):i.label;return(0,$.jsxs)(`section`,{className:`rounded-xl border border-line px-3 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`min-w-0 text-sm text-ink`,children:r.instructions}),(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-ink-muted`,children:t(`chat.decision.types.${r.type}`)})]}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex items-baseline gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,"data-testid":`decision-answer`,className:`text-base font-semibold text-ink`,children:a}),i.probability!==void 0&&(0,$.jsx)(`span`,{className:`text-sm tabular-nums text-primary-700 dark:text-primary-300`,children:Zt(i.probability)}),i.score&&(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-ink-muted`,children:t(`chat.decision.result.score`,{value:i.score.value.toFixed(2),max:i.score.max})})]}),i.kind!==`refusal`&&i.kind!==`yes`&&i.kind!==`no`&&i.distribution.length>1&&(0,$.jsx)(`ul`,{className:`mt-2 space-y-1`,children:i.distribution.map(e=>(0,$.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,10rem)_1fr_3.5rem] items-center gap-2 text-xs`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`truncate text-ink-muted`,children:e.label}),(0,$.jsx)($t,{value:e.probability,strong:e.label===i.label}),(0,$.jsx)(`span`,{className:`text-end tabular-nums text-ink-muted`,children:Zt(e.probability)})]},e.label))}),(i.kind===`yes`||i.kind===`no`)&&i.probability!==void 0&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)($t,{value:i.probability,strong:!0})})]},n)}),(0,$.jsxs)(`p`,{className:`text-[11px] text-ink-subtle`,children:[t(`chat.decision.result.via`,{model:e.model,provider:e.provider}),n!==void 0&&` · ${t(`chat.decision.result.inputTokens`,{tokens:n})}`]})]})},tn=Y(`components:ttsbutton`),nn=null,rn=null,an=0,on=3e5;async function sn(e=!1){let t=Date.now();return!e&&nn!==null&&t-an<on?nn:rn||(rn=(async()=>{try{let e=await Fe.getModels();return e.success&&e.data&&e.data.length>0?(nn=e.data,an=t,e.data):(nn=[],an=t,[])}catch{return nn=[],an=t,[]}finally{rn=null}})(),rn)}var cn=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:c}=s(),{preferences:l}=Ke(),[u,d]=(0,Q.useState)(`idle`),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),[g,_]=(0,Q.useState)(null),v=(0,Q.useRef)(null),b=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await sn(),n=Be(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await sn(!0)),e&&(h(t),_(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let x=()=>{b.current+=1,v.current?.cancel(),v.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`||v.current){x();return}let t=Qe();d(`loading`),p(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=J(m,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,h=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,y=Math.max(1,a?.config?.max_characters||600),x=Math.min(y,600),S=i?.streamSentences!==!1||e.length>x?Ze(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})=>Fe.generate({model:s,pluginId:u,input:e,voice:h?void 0:p||void 0,voiceProfileId:h,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});v.current=C;let w=$e(C);try{await C.play(S)}finally{w(),v.current===C&&(v.current=null)}}catch(e){if(b.current!==n)return;if(Je(e)){d(`idle`);return}if(Xe(e)){d(`blocked`);return}p(o(`ttsButton.generateFailed`)),tn.error(`TTS error:`,e),d(`error`)}};if((0,Q.useEffect)(()=>()=>{b.current+=1,v.current?.cancel(),v.current=null},[]),g===!1||g===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,ee=T===`loading`||T===`generating`||T===`buffering`,D=T===`playing`,O=T===`blocked`,k=!!f||T===`error`,A=f||o(k?`ttsButton.playbackFailed`:O?`ttsButton.enableAudio`:D||ee?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,$.jsxs)(`button`,{onClick:S,disabled:!e,title:A,"aria-label":A,"aria-busy":ee||void 0,className:V(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-hidden 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:[ee?(0,$.jsx)(E,{className:V(w[n],`animate-spin`)}):D?(0,$.jsx)(y,{className:w[n]}):k||O?(0,$.jsx)(j,{className:w[n]}):(0,$.jsx)(de,{className:w[n]}),O&&(0,$.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},ln=80,un=5e3,dn=15e3;function fn({sessionId:e,messageId:t,thinking:n,isThinking:r,isPrivate:i}){let a=Ke(e=>e.preferences.titleSettings),o=(0,Q.useRef)(n),[s,c]=(0,Q.useState)(null),{autoTitle:l,taskModel:u,taskProviderType:d,taskProviderId:f}=a??{};return(0,Q.useEffect)(()=>{o.current=n},[n]),(0,Q.useEffect)(()=>{if(!e||!r||i||!l||!u||qe())return;let n=!1,a,s=``,p=new AbortController,m=async()=>{let r=(o.current??``).slice(-4e3).trim();if(r.length<ln||r===s){n||(a=setTimeout(()=>void m(),400));return}s=r;let i=Date.now(),l=un;try{let i=await G.summarizeThinking(e,{model:u,thinking:r,providerType:d,providerId:f},p.signal);if(!i.success||!i.data?.summary?.trim())throw Error(`Thinking summary unavailable`);n||c({sessionId:e,messageId:t,summary:i.data.summary.trim().slice(0,160)})}catch{l=dn}n||(a=setTimeout(()=>void m(),Math.max(0,l-(Date.now()-i))))};return a=setTimeout(()=>void m(),350),()=>{n=!0,clearTimeout(a),p.abort()}},[e,t,r,i,l,u,d,f]),s&&s.sessionId===e&&s.messageId===t?s.summary:null}var pn=[`accuracy`,`style`,`incomplete`,`harmful`,`formatting`],mn=Y(`components:chat-message`);function hn({role:e,user:t,persona:n,modelAvatar:r}){let{t:i}=s(),[a,o]=(0,Q.useState)(null);if(e===`assistant`){if(n)return(0,$.jsx)(`img`,{src:Le(n,64),alt:n.name,"data-testid":`chat-assistant-avatar`,onError:e=>K(e.currentTarget,n.name,64),className:`mt-0.5 h-8 w-8 shrink-0 rounded-lg object-cover`});let e=r?.trim()??``,t=e.startsWith(`data:`)&&e!==a?e:``;return(0,$.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-xs dark:border-white/9 dark:bg-dark-200 dark:text-dark-950`,children:t?(0,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>o(e)}):e?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,$.jsx)(xt,{label:null,className:`h-4 w-4`})})}let c=t?.username||i(`chatMessage.user`),l=t?.avatar?.trim()||``,u=!!l&&l!==a;return(0,$.jsx)(`div`,{role:u?void 0:`img`,"aria-label":u?void 0:c,"data-testid":`chat-user-avatar`,className:V(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,u?`border border-black/[0.07] bg-white dark:border-white/9 dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:c,children:u?(0,$.jsx)(`img`,{src:l,alt:c,className:`h-full w-full object-cover`,onError:()=>o(l)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(M,{"aria-hidden":`true`,className:`h-4 w-4`})})}var gn=Q.memo(({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onFork:a,onEditResend:o})=>{let{t:c,i18n:l}=s(),u=e.role===`user`,d=e.role===`system`,f=d&&st(e.content),m=f?e.content.slice(ht.length):e.content,h=Ke(e=>e.preferences),g=St(e=>e.user),_=X(e=>e.setSystemMessage),v=X(e=>e.rateMessage),y=X(e=>e.modelMetadata),b=X(e=>e.currentSession?.id),x=X(e=>e.currentSession?.model),w=X(e=>e.currentSession?.isPrivate===!0),T=X(e=>e.getCurrentPersona()),E=e.model||x||``,ee=E?y[E]??Object.entries(y).find(([e])=>e.slice(e.indexOf(`/`)+1)===E)?.[1]:void 0,[D,te]=(0,Q.useState)(!1),[ne,j]=(0,Q.useState)(!1),[M,P]=(0,Q.useState)(e.content),[F,se]=(0,Q.useState)(null),ce=(0,Q.useRef)(null);Ct(ce,{enabled:F!==null,onClose:()=>se(null)});let[ue,de]=(0,Q.useState)(!1),[fe,pe]=(0,Q.useState)(!1),[me,he]=(0,Q.useState)(!1),ge=(0,Q.useId)(),[_e,R]=(0,Q.useState)(`idle`),[ye,be]=(0,Q.useState)(null),[xe,Se]=(0,Q.useState)([]),[Ce,we]=(0,Q.useState)(``),[z,Ee]=(0,Q.useState)(!1),De=(0,Q.useRef)(null),B=(0,Q.useRef)(0),H=(0,Q.useRef)(t),Ae=(0,Q.useRef)(!1),je=async()=>{try{await navigator.clipboard.writeText(e.content),Tt(`success`),Ee(!0),setTimeout(()=>Ee(!1),2e3)}catch(e){mn.error(`Failed to copy message:`,e),I.error(c(`chat.message.copyFailed`))}},W=(0,Q.useMemo)(()=>Qt(e.providerMetadata),[e.providerMetadata]),{thinkingContent:Ne,thinkingStreaming:K,parsedContent:q,artifacts:Ie}=(0,Q.useMemo)(()=>{if(u||d||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:ke(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=rt(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,u,d,t]),Le=K?void 0:e.statistics?.thinking_duration_ms??et(e.id),Re=fn({sessionId:b,messageId:e.id,thinking:Ne,isThinking:K,isPrivate:w}),ze=Le===void 0?c(`chatMessage.thinking`):c(`chatMessage.thoughtFor`,{duration:tt(Le)}),Ve=(0,Q.useCallback)(async e=>{let t=B.current+1;B.current=t,De.current?.cancel(),De.current=null,R(`loading`);try{if(e){let n=await e;if(B.current!==t)return;if(n===`blocked`){R(`blocked`);return}}let n=await Fe.getModels();if(B.current!==t)return;let r=n.success&&n.data?n.data:[],i=h.ttsSettings,a=J(r,i?.model,i?.pluginId),o=Be(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,c=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),m=i?.streamSentences!==!1||q.length>p?Ze(q,{locale:l.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[q.trim()];if(m.length===0){R(`idle`);return}let g=Ye({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>Fe.generate({model:s,pluginId:c,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=>{B.current===t&&R(e)}});if(B.current!==t){g.cancel();return}De.current=g;let _=$e(g);try{await g.play(m)}finally{_(),De.current===g&&(De.current=null),B.current===t&&(g.state===`ended`||g.state===`cancelled`)&&R(`idle`)}}catch(e){if(B.current!==t)return;Je(e)?R(`idle`):Xe(e)?R(`blocked`):(mn.error(`Auto-play TTS failed:`,e),R(`error`))}},[l.language,q,h.ttsSettings]);(0,Q.useEffect)(()=>{let e=H.current&&!t;H.current=t,e&&!Ae.current&&!u&&!d&&q&&h.ttsSettings?.enabled&&h.ttsSettings.autoPlay&&(Ae.current=!0,Ve())},[t,u,d,q,h.ttsSettings?.autoPlay,h.ttsSettings?.enabled,Ve]),(0,Q.useEffect)(()=>()=>{B.current+=1,De.current?.cancel(),De.current=null},[]);let He=()=>{let e=Qe();Ve(e)},Ue=()=>{B.current+=1,De.current?.cancel(),De.current=null,R(`idle`)},We=()=>f?c(`chatMessage.conversationSummary`):d?c(`chatMessage.system`):u?h.showUsername&&g?.username?g.username:c(`chatMessage.you`):T?.name?T.name:ee?.label||E||c(`chatMessage.assistant`),Ge=()=>{te(!0),P(e.content)},[qe,Y]=(0,Q.useState)(!1),nt=async()=>{if(b&&!qe){Y(!0);try{let t=await G.restoreCompaction(b,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;X.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){mn.error(`Failed to restore compacted messages:`,e),I.error(c(`chatMessage.restoreFailed`))}finally{Y(!1)}}},it=async()=>{de(!0);try{_(M),te(!1),mn.debug(`✅ System message updated:`,M)}catch(e){mn.error(`Failed to save system message:`,e)}finally{de(!1)}},at=()=>{te(!1),P(e.content)},ot=()=>{let t=M.trim();te(!1),t&&o?.(e.id,t)},ct=t=>{if(!b)return;let n=e.rating===t;v(b,e.id,n?void 0:t),w||(n?(be(null),wt.deleteFeedback(e.id).catch(()=>I.error(c(`chatMessage.feedbackFailed`)))):(Se([]),we(``),be(t===1?1:-1),wt.upsertFeedback({sessionId:b,messageId:e.id,rating:t===1?1:-1}).catch(()=>I.error(c(`chatMessage.feedbackFailed`)))))},lt=()=>{b&&ye!==null&&(wt.upsertFeedback({sessionId:b,messageId:e.id,rating:ye,tags:xe,...Ce.trim()?{comment:Ce.trim()}:{}}).catch(()=>I.error(c(`chatMessage.feedbackFailed`))),be(null))},ut=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,dt=d&&m.length>100;return(0,$.jsxs)(`div`,{className:V(`group flex py-1.5 transition-colors sm:py-2`,u?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:V(`flex min-w-0 gap-2.5 sm:gap-3`,u?`max-w-[85%] sm:max-w-[70%] wide:sm:max-w-[min(70%,56rem)]`:`w-full`),children:[!u&&!d&&(0,$.jsx)(hn,{role:`assistant`,persona:T,modelAvatar:ee?.avatar}),(0,$.jsxs)(`div`,{className:V(`min-w-0 flex-1`,u?`flex flex-col items-end`:d?`py-1.5`:`py-0.5`),children:[!u&&!d&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-muted rtl:tracking-normal`,children:We()}),e.model&&T?.name&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,$.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-ink-subtle`,children:Oe(e.timestamp,l.language)})]}),(0,$.jsxs)(`div`,{className:V(!u&&!d&&`text-[0.9375rem] leading-[1.65] text-ink`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/6 bg-gray-100 dark:border-white/8 dark:bg-gray-800`,children:(0,$.jsx)(`button`,{type:`button`,className:`block h-full w-full`,"aria-label":c(`chatMessage.openImage`,{number:t+1}),onClick:()=>se(e),children:(0,$.jsx)(`img`,{src:e,alt:c(`chatMessage.uploadedImageAlt`,{number:t+1}),className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`})})},t))}),u?D?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/8 bg-white p-2 shadow-xs focus-within:border-primary-500 focus-within:ring-2 focus-within:ring-primary-500/30 dark:border-white/8 dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{"aria-label":c(`chatMessage.edit`),dir:`auto`,value:M,onChange:e=>P(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||(e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),ot()):e.key===`Escape`&&at())},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-hidden dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:at,children:c(`chatMessage.cancelEditing`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:ot,children:c(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{"data-user-bubble":``,className:`rounded-2xl rounded-ee-md border border-line bg-surface-subtle px-4 py-2.5 text-ink`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):d?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/6 bg-white/55 p-3 dark:border-white/6 dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[f?(0,$.jsx)(k,{className:`h-2.5 w-2.5 opacity-50`}):(0,$.jsx)(O,{className:`h-2.5 w-2.5 opacity-50`}),c(f?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:f?(0,$.jsx)(`button`,{onClick:()=>void nt(),disabled:qe,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.restoreCompacted`),"aria-label":c(`chatMessage.restoreCompacted`),children:(0,$.jsx)(le,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):D?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:it,disabled:ue,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.saveChanges`),"aria-label":c(`chatMessage.saveChanges`),children:(0,$.jsx)(p,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:at,disabled:ue,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.cancelEditing`),"aria-label":c(`chatMessage.cancelEditing`),children:(0,$.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:Ge,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:c(`chatMessage.editSystemMessage`),"aria-label":c(`chatMessage.editSystemMessage`),children:(0,$.jsx)(oe,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),D?(0,$.jsx)(`textarea`,{"aria-label":c(`chatMessage.editSystemMessage`),dir:`auto`,value:M,onChange:e=>P(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/8 bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-hidden focus:ring-2 focus:ring-primary-500 dark:border-white/8 dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:c(`chatMessage.systemMessagePlaceholder`),disabled:ue}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:fe?m:ut(m)}),dt&&(0,$.jsx)(`button`,{type:`button`,"aria-expanded":fe,onClick:()=>pe(!fe),className:`mt-2 flex items-center gap-1 text-xs text-ink-muted transition-colors hover:text-ink`,children:fe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{className:`h-3 w-3`}),c(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`h-3 w-3`}),c(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(Ne||K)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`thinking-toggle`,"aria-expanded":me,"aria-controls":ge,onClick:()=>he(!me),className:`flex min-h-11 max-w-full items-center gap-1.5 rounded-md py-2 text-start text-xs text-ink-muted transition-colors hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/30`,children:[K?(0,$.jsx)(U,{"data-testid":`thinking-generation-indicator`}):(0,$.jsx)(ae,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{role:`status`,"aria-live":K?`polite`:`off`,"aria-atomic":`true`,className:`min-w-0 wrap-anywhere`,children:[(0,$.jsx)(`span`,{"data-testid":`thinking-summary`,dir:`auto`,className:V(`block font-medium`,K&&`animate-slide-up [animation-duration:140ms] motion-reduce:animate-none`),children:Re||(K?`${c(`chatMessage.thinking`)}…`:ze)},Re||`thinking`),Re&&!K&&(0,$.jsx)(`span`,{className:`mt-0.5 block text-ink-subtle`,children:ze})]}),me?(0,$.jsx)(A,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}):(0,$.jsx)(N,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`})]}),(0,$.jsx)(`div`,{id:ge,"data-testid":`thinking-content`,hidden:!me,dir:`auto`,className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 text-[13px] leading-relaxed text-gray-600 dark:bg-dark-200/60 dark:text-dark-700`,children:me&&Ne&&(0,$.jsx)(Me,{content:Ne,isStreaming:K,className:`text-[13px] text-ink-muted`})})]}),W&&!t?(0,$.jsx)(en,{metadata:W}):(0,$.jsx)(Me,{content:q,isStreaming:t&&!(K&&!q)})]}),!u&&!d&&Ie.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Pe,{artifacts:Ie})}),!u&&!d&&Array.isArray(e.providerMetadata?.toolCalls)&&e.providerMetadata.toolCalls.length>0&&(0,$.jsx)(Ut,{calls:e.providerMetadata.toolCalls,className:`mt-2.5`}),!u&&!d&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,$.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-ink-subtle rtl:tracking-normal`,children:c(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,$.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,$.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!d&&!t&&(0,$.jsxs)(`div`,{"data-testid":`message-action-row`,className:V(`flex flex-wrap items-center gap-0.5 text-ink-subtle`,`sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,!u&&(r||ne||ye!==null||[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(_e))?`sm:opacity-100`:`[@media(hover:hover)]:sm:opacity-0`,u?`mt-1 justify-end`:`mt-1.5`),children:[u&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:Oe(e.timestamp,l.language),children:[We(),` ·`,` `,Oe(e.timestamp,l.language)]}),!u&&q&&(0,$.jsx)(cn,{text:q,size:`sm`,externalPlaybackState:_e,onStopExternal:Ue,onRetryExternal:He,className:V(`transition-colors`,_e===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),u&&o&&!D&&(0,$.jsx)(`button`,{onClick:()=>{P(e.content),te(!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:c(`chatMessage.edit`),"aria-label":c(`chatMessage.edit`),children:(0,$.jsx)(oe,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:je,"aria-label":c(z?`chatMessage.copied`:`chatMessage.copyMessage`),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:c(z?`chatMessage.copied`:`chatMessage.copyMessage`),children:z?(0,$.jsx)(ve,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(S,{className:`h-3.5 w-3.5`})}),!u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>ct(1),className:V(`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:c(`chatMessage.goodResponse`),"aria-label":c(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(Te,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>ct(-1),className:V(`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:c(`chatMessage.badResponse`),"aria-label":c(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(ie,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})}),ye!==null&&(0,$.jsxs)(`div`,{className:`ms-1 flex flex-wrap items-center gap-1 rounded-lg border border-gray-200 bg-white px-2 py-1 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`feedback-details`,children:[pn.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>Se(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:V(`rounded-full border px-2 py-0.5 text-[10px]`,xe.includes(e)?`border-primary-500 bg-primary-50 text-primary-700 dark:bg-primary-950/40 dark:text-primary-300`:`border-gray-300 text-gray-500 dark:border-dark-300`),"aria-pressed":xe.includes(e),children:c(`chatMessage.feedbackTags.${e}`)},e)),(0,$.jsx)(`input`,{value:Ce,onChange:e=>we(e.target.value),placeholder:c(`chatMessage.feedbackComment`),"aria-label":c(`chatMessage.feedbackComment`),className:`w-32 rounded-sm border border-gray-300 px-1.5 py-0.5 text-[10px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,maxLength:2e3}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:lt,className:`h-6 px-2 text-[10px]`,children:c(`common.save`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>be(null),"aria-label":c(`common.close`),className:`rounded-sm p-0.5 text-ink-muted hover:text-ink`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]})]}),!u&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:c(`chatMessage.regenerateResponse`),"aria-label":c(`chatMessage.regenerateResponse`),children:(0,$.jsx)(C,{className:`h-3.5 w-3.5`})}),a&&(0,$.jsx)(`button`,{onClick:()=>a(e.id),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:c(`chat.fork.action`),"aria-label":c(`chat.fork.action`),"data-testid":`fork-from-message`,children:(0,$.jsx)(re,{className:`h-3.5 w-3.5`})}),!u&&e.statistics&&(0,$.jsx)(Gt,{statistics:e.statistics,expanded:ne,onExpandedChange:j,hideModel:!!(e.model&&T?.name),className:`ms-2`})]})]})]}),u&&(0,$.jsx)(hn,{role:`user`,user:g??null})]}),F&&(0,zt.createPortal)((0,$.jsxs)(`div`,{ref:ce,role:`dialog`,"aria-modal":`true`,"aria-label":c(`chatMessage.fullSizeImage`),tabIndex:-1,className:`fixed inset-0 z-9999 flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>se(null),children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":c(`common.close`),className:`absolute inset-e-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(),se(null)},children:(0,$.jsx)(L,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:F,alt:c(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})});gn.displayName=`ChatMessage`;var _n=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,vn=220,yn=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>vn?`${t.slice(0,219).trimEnd()}…`:t},bn=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;r&&i&&(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Q.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:_n()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`group/rail pointer-events-none absolute inset-s-[max(0.25rem,calc(50%_-_27rem))] top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9 wide:inset-s-1`,onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 opacity-40 transition-opacity duration-150 scrollbar-none group-hover/rail:opacity-100 group-focus-within/rail:opacity-100 motion-reduce:transition-none [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===h,u=Math.abs(a-m),d=c===t.id?v:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:V(`group flex h-4 w-7 items-center outline-hidden xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-xs`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:V(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,$.jsx)(`div`,{id:v,role:`tooltip`,className:V(`pointer-events-none absolute inset-s-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:yn(_.prompt)}),_.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:yn(_.response)})]})})]})}),xn=Q.memo(({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:c,className:l})=>{let{t:u}=s();if(e.length===1){let s=e[0],c=t&&i===s.id,u=c?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(gn,{message:u,isStreaming:c,isLastAssistantMessage:a,onRegenerate:o,className:l})}return(0,$.jsxs)(`div`,{className:V(`relative py-2`,l),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-muted`,children:[(0,$.jsx)(_e,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:u(`chat.branch.variants`,{count:e.length})})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let l=e.isActive!==!1,d=t&&i===e.id,f=d?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:V(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||d?`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&&!d&&`cursor-pointer`),role:!l&&!d?`button`:void 0,tabIndex:!l&&!d?0:void 0,"aria-label":!l&&!d?u(`chat.branch.selectVariant`,{number:s+1}):void 0,"aria-current":l||d?`true`:void 0,onClick:()=>!l&&!d&&c?.(e.id),onKeyDown:t=>{t.target!==t.currentTarget||l||d||t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),c?.(e.id))},children:[(0,$.jsxs)(`div`,{className:V(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||d?`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/5 text-ink-muted dark:border-white/5`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:s+1}),d&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:u(`chat.branch.generating`)})]}),l&&!d&&(0,$.jsx)(ve,{className:`h-3 w-3`}),!l&&!d&&(0,$.jsx)(`span`,{className:`text-[10px]`,children:u(`chat.branch.select`)})]}),(0,$.jsx)(`div`,{className:V(!l&&!d&&`opacity-75`),children:(0,$.jsx)(gn,{message:f,isStreaming:d,isLastAssistantMessage:a&&(l||d),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 text-sm!`})})]},e.id)})})]})});xn.displayName=`MessageBranch`;var Sn={web_search:d,web_fetch:ge,exec:ee,browser:ge,Read:z,Write:z,Edit:z,image:m,memory_search:F,memory_get:F,working:he,thinking:he,default:he},Cn={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`},wn=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,$.jsx)(`div`,{className:V(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Sn[e.name]||Sn.default,n=Cn[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:V(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(`div`,{className:V(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};Y(`components:chat-messages`);var Tn=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],En=e=>e.messages.every(e=>e.isActive===!1),Dn=e=>e.role===`system`&&!st(e.content),On=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,kn=e=>Math.min(120,e*.28),An=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],activeToolCalls:o,pendingToolApproval:c,onDecideToolApproval:l,className:u,onRegenerate:d,onSelectBranch:f,onEditResend:p,onFork:m,followUpSuggestions:h,onFollowUpSelect:g})=>{let{t:y}=s(),b=(0,Q.useRef)(null),x=(0,Q.useRef)(void 0),S=(0,Q.useRef)(null),C=(0,Q.useRef)(null),[w]=(0,Q.useState)(()=>new Map),T=(0,Q.useRef)(null),E=(0,Q.useRef)(0),ee=(0,Q.useRef)(!1),D=(0,Q.useRef)(!1),[O,k]=(0,Q.useState)(!1),A=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>Dn(e)&&!Dn(t)?-1:Dn(t)&&!Dn(e)?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 Dn(n)&&!Dn(r)?-1:Dn(r)&&!Dn(n)?1:n.timestamp-r.timestamp})},[e]),te=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<A.length;t++){let n=A[t],r=Tn(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<A.length;e++){let t=Tn(A[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},[A]),ne=te.map(e=>e.id).join(``),j=(0,Q.useMemo)(()=>ne?ne.split(``):[],[ne]),re=(0,Q.useMemo)(()=>new Set(j),[j]),ie=(0,Q.useMemo)(()=>{let e=new Map;for(let t of j)e.set(t,e=>{e?w.set(t,e):w.delete(t)});return e},[w,j]),[M,ae]=(0,Q.useState)(null),oe=(0,Q.useCallback)(()=>{let e=S.current;if(!e||j.length===0){ae(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(E.current,j.length-1);if(t<=2)n=j.length-1;else{let t=e.scrollTop+kn(e.clientHeight);for(;n<j.length-1;){let e=w.get(j[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=w.get(j[n]);if(!e||e.offsetTop<=t)break;n--}}E.current=n;let r=j[n];ae(e=>e===r?e:r)},[w,j]),N=(0,Q.useCallback)(()=>{T.current===null&&(T.current=window.requestAnimationFrame(()=>{T.current=null,oe()}))},[oe]),P=(0,Q.useCallback)(()=>{let t=S.current;if(x.current&&clearTimeout(x.current),ee.current=!1,x.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;D.current=!n,k(!n&&e.length>0),N()},[e.length,N]),F=(0,Q.useCallback)(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(P,180)},[P]),I=(0,Q.useCallback)((e=!1)=>{(!D.current||e)&&b.current?.scrollIntoView({behavior:On()})},[]),se=(0,Q.useCallback)(()=>{let t=S.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;ee.current?(D.current=!0,k(!o&&e.length>0),N(),F()):(D.current=!o,k(!o&&e.length>0),a<=2&&j.length>0?(E.current=j.length-1,ae(j[j.length-1])):N())},[j,e.length,F,N]),ce=(0,Q.useCallback)(e=>{let t=S.current,n=w.get(e);if(!t||!n)return;let r=On();ee.current=!0,D.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-kn(t.clientHeight)),behavior:r}),N(),r===`auto`?P():F()},[P,w,F,N]),le=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>le.current&&!D.current&&I(),le.current=e.length},[e.length,I]),(0,Q.useEffect)(()=>{i&&(t||n)&&!D.current&&requestAnimationFrame(()=>{let e=S.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{N();let e=C.current,t=S.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(N);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,N),()=>{n?.disconnect(),window.removeEventListener(`resize`,N)}},[ne,N]),(0,Q.useEffect)(()=>()=>{T.current!==null&&(window.cancelAnimationFrame(T.current),T.current=null)},[]),(0,Q.useEffect)(()=>()=>{x.current&&clearTimeout(x.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:V(`flex-1 flex items-center justify-center p-6 sm:p-10`,u),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-ink-muted`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/6 bg-surface/70 text-gray-500 shadow-xs dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(_,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:y(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:y(`chatMessage.startConversationDescription`)})]})});let ue=-1;for(let e=A.length-1;e>=0;e--)if(A[e].messages.some(e=>e.role===`assistant`)){ue=e;break}return(0,$.jsxs)(`div`,{className:V(`relative min-h-0 flex-1`,u),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:S,"data-testid":`chat-scroll-viewport`,"aria-busy":i,"data-scroll-fade-top":`40`,"data-scroll-fade-bottom":`72`,onScroll:se,className:V(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,$.jsxs)(`div`,{ref:C,"data-testid":`chat-messages-column`,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8 wide:max-w-none wide:md:px-12`,children:[A.map((e,a)=>{let o=a===ue,s=re.has(e.id),c=i&&e.messages.some(e=>e.id===r),l;if(En(e))l=(0,$.jsx)(`div`,{className:`opacity-55`,children:(0,$.jsx)(gn,{message:Tn(e),isStreaming:!1,isLastAssistantMessage:!1,className:a===0?`mt-3 sm:mt-4`:``})});else if(e.messages.length===1){let s=e.messages[0],c=i&&s.id===r,u=c?{...s,content:t??s.content,thinking:n||s.thinking}:s;l=(0,$.jsx)(gn,{message:u,isStreaming:c,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onEditResend:i?void 0:p,onFork:i?void 0:m,className:a===0?`mt-3 sm:mt-4`:``})}else l=(0,$.jsx)(xn,{messages:e.messages,isStreaming:c,streamingMessage:c?t:void 0,streamingThinking:c?n:void 0,streamingMessageId:c&&r||void 0,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onSelectBranch:f,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{className:`[content-visibility:auto] [contain-intrinsic-size:auto_160px]`,ref:ie.get(e.id),"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:l},e.id)}),i&&(o?.length??0)>0&&(0,$.jsx)(Ut,{calls:o??[],className:`pb-2`}),c&&l&&(0,$.jsx)(Wt,{approval:c,onDecide:l,className:`mb-2`}),i&&a.length>0&&(0,$.jsx)(wn,{tools:a,className:`px-0`}),!i&&h&&h.length>0&&g&&(0,$.jsx)(`div`,{role:`group`,"aria-label":y(`chat.followUp`),"data-testid":`follow-up-suggestions`,className:`mt-1 flex flex-wrap gap-1.5 pb-2 ps-[2.625rem] sm:ps-11 wide:max-w-[calc(90ch+2.75rem)]`,children:h.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>g(e),dir:`auto`,className:`flex max-w-full items-start gap-1.5 rounded-2xl border border-line px-3 py-1.5 text-start text-[13px] leading-snug text-ink-muted transition-colors hover:border-line-strong hover:bg-interactive-hover hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,children:[(0,$.jsx)(v,{"aria-hidden":`true`,className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-ink-subtle rtl:-scale-x-100`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:e})]},e))}),(0,$.jsx)(`div`,{ref:b,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(bn,{items:te,activeId:M,onSelect:ce}),O&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-new-messages`,onClick:()=>{ee.current=!1,x.current&&=(clearTimeout(x.current),void 0),D.current=!1,b.current?.scrollIntoView({behavior:On()}),k(!1)},className:V(`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/8`,`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:y(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(we,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:y(`chatMessage.newMessages`)})]})]})};function jn(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 Mn=Q.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Q.useMemo)(()=>jn(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:V(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute inset-e-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:V(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,$.jsx)(Ee,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});Mn.displayName=`CodeAwareTextarea`;var Nn=Y(`components:media-upload`),Pn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)([]),g=async r=>{if(!r||a)return;let i=Array.from(r),o=[];for(let t of i)if(t.type.startsWith(`image/`)){let r=await _(t,n-e.length-o.length);r&&o.push(r)}else t.type.includes(`pdf`)||t.type.includes(`text`)?await v(t):I.error(c(`chat.mediaUpload.unsupportedFileType`,{name:t.name}));o.length>0&&t([...e,...o])},_=(e,t)=>t<=0?(I.error(c(`chat.mediaUpload.maxImagesAllowed`,{count:n})),Promise.resolve(null)):e.size>10485760?(I.error(c(`chat.mediaUpload.imageTooLarge`,{name:e.name})),Promise.resolve(null)):new Promise(t=>{let n=new FileReader;n.onload=()=>t(typeof n.result==`string`?n.result:null),n.onerror=()=>{I.error(c(`chat.mediaUpload.readFailed`,{name:e.name})),t(null)},n.readAsDataURL(e)}),v=async e=>{if(e.size>10485760)I.error(c(`documents.fileSizeTooLarge`));else{p(!0);try{let t=await Re.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),I.success(c(`documents.uploadSuccessWithName`,{name:e.name}))}else I.error(t.error||c(`documents.uploadFailed`))}catch(e){Nn.error(`Document upload error:`,e),I.error(c(`documents.uploadFailed`))}finally{p(!1)}}},y=e=>{e.preventDefault(),a||d(!0)},b=e=>{e.preventDefault(),d(!1)},x=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},C=async e=>{try{let t=await Re.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),I.success(c(`documents.removeSuccess`))):I.error(t.error||c(`documents.removeFailed`))}catch(e){Nn.error(`Error removing document:`,e),I.error(c(`documents.removeFailed`))}},w=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},T=e.length>0||m.length>0;return(0,$.jsxs)(`div`,{className:V(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:V(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:y,onDragLeave:b,onDrop:x,role:`button`,tabIndex:a?-1:0,"aria-disabled":a||void 0,"aria-label":`${c(`chat.mediaUpload.dropImagesHere`)} ${c(`chat.mediaUpload.browse`)}`,onClick:()=>!a&&l.current?.click(),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a||l.current?.click())},children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(E,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`,role:`status`,"aria-label":c(`chat.mediaUpload.uploading`)}):(0,$.jsx)(fe,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-ink-muted mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),T&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:c(`chat.mediaUpload.uploadAlt`,{number:t+1}),className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S(t)},"aria-label":c(`chat.mediaUpload.removeImage`,{number:t+1}),className:`absolute top-0.5 inset-e-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(z,{className:`w-4 h-4 text-red-500 shrink-0`}):(0,$.jsx)(te,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-ink-muted`,children:w(e.size)})]}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),C(e.id)},"aria-label":c(`chat.mediaUpload.removeDocument`,{name:e.filename}),className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},Fn=Y(`components:document-indicator`),In=({sessionId:e,className:t=``})=>{let{t:n}=s(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),u=(0,Q.useRef)(null),d=(0,Q.useCallback)(async()=>{try{let t=await Re.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){Fn.error(`Failed to load documents:`,e)}},[e]);if((0,Q.useEffect)(()=>{let e=setTimeout(()=>void d(),0),t=()=>void d();return window.addEventListener(`libre:documents-updated`,t),()=>{clearTimeout(e),window.removeEventListener(`libre:documents-updated`,t)}},[d]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{u.current?.contains(e.target)||(o(!1),l(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let f=async e=>{l(null);try{let t=await Re.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){Fn.error(`Failed to delete document:`,e),b.error(n(`settings.documents.library.deleteFailed`))}},p=r.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{ref:u,className:`relative inline-block ${t}`,children:[a&&(0,$.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,$.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,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,$.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,$.jsxs)($.Fragment,{children:[(0,$.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,$.jsx)(`button`,{onClick:()=>void f(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,$.jsx)(`button`,{onClick:()=>l(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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-xs text-gray-900 dark:text-dark-900`,children:e.filename}),(0,$.jsxs)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:[B(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,$.jsx)(`button`,{onClick:()=>l(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,$.jsx)(L,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),l(null)},className:`
|
|
1
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,r as n,t as r}from"./react-vendor-C1iE8mnY.js";import{d as i,f as a,u as o}from"./router-vendor-ihzG-2y7.js";import{t as s}from"./useTranslation-Bu0AxynE.js";import{Bt as c,Ct as l,F as u,G as d,Hn as f,J as p,Jt as m,L as h,Ln as g,M as _,Nn as v,O as y,Or as b,P as x,Pn as S,Q as C,Qn as w,Rn as T,Rt as E,S as ee,Tt as D,V as O,X as k,Zn as A,_n as te,_r as ne,a as j,an as re,b as ie,c as M,cr as ae,ct as oe,er as N,g as P,jn as F,kr as I,ln as se,lr as ce,m as le,mr as ue,n as L,o as de,p as fe,pr as pe,qt as me,r as he,rn as ge,sn as _e,st as R,tr as ve,tt as ye,ut as be,v as xe,vr as Se,wt as Ce,xr as we,y as Te,yn as z,zn as Ee}from"./ui-vendor-CmYUVVjB.js";import{a as De,i as Oe,n as B,s as ke,t as V}from"./utils-DhBboyBg.js";import{_ as H,f as U,g as Ae,m as je,p as W,u as Me,v as Ne}from"./ui-D5Ws30mx.js";import{t as Pe}from"./ArtifactContainer-BJcZu1hG.js";import{N as G,_ as K,a as Fe,d as q,f as Ie,g as Le,i as J,j as Re,m as ze,n as Be,p as Ve,t as He,w as Ue,x as We,y as Ge}from"./api-__EtZkwT.js";import{t as Ke}from"./appStore-xMQ42B4m.js";import{a as qe,t as Y}from"./logger-DAQsBb8I.js";import{a as Je,i as Ye,o as Xe,r as Ze,s as Qe,t as $e}from"./ttsBatching-yVvnRS5S.js";import{a as et,i as tt,n as nt,o as rt,r as it}from"./useChat-B3oRF8Vk.js";import{E as at,_ as ot,a as st,d as ct,f as lt,g as ut,h as dt,i as ft,l as pt,m as mt,n as ht,o as gt,p as _t,r as vt,t as X,u as yt,v as bt}from"./chatStore-DM7NfNs8.js";import{t as xt}from"./LogoMark-CiSslCTm.js";import{t as St}from"./authStore-VeRUWwzv.js";import{t as Ct}from"./useDialogFocus-DpTun-ZV.js";import{t as wt}from"./evaluationsApi-BomOD9nq.js";import{l as Tt}from"./messageCodeStyles-C4KLlfl_.js";import{t as Z}from"./Button-DeV-GhQr.js";import{n as Et,r as Dt,t as Ot}from"./useDictation-DzQ0p1L7.js";import{d as kt,f as At,l as jt,t as Mt}from"./modelPresentation-Jp0roUnl.js";import{n as Nt,t as Pt}from"./composerStyles-BEx0XAp6.js";import{t as Ft}from"./ConnectModels-BGp65ytJ.js";import{i as It,r as Lt,t as Rt}from"./welcomePrompts-to5mv_gx.js";var zt=n(),Q=e(t(),1),$=r(),Bt=e=>{try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}},Vt=({status:e})=>e===`running`||e===`awaiting_approval`?(0,$.jsx)(E,{className:`h-3.5 w-3.5 animate-spin`}):e===`succeeded`?(0,$.jsx)(ve,{className:`h-3.5 w-3.5 text-green-600 dark:text-green-400`}):e===`denied`?(0,$.jsx)(L,{className:`h-3.5 w-3.5 text-amber-600 dark:text-amber-400`}):(0,$.jsx)(P,{className:`h-3.5 w-3.5 text-red-500 dark:text-red-400`}),Ht=({call:e})=>{let{t}=s(),[n,r]=(0,Q.useState)(!1),i=t(`tools.callStatus.${e.status}`);return(0,$.jsxs)(`div`,{className:`rounded-lg border border-gray-200 dark:border-dark-200 bg-gray-50 dark:bg-dark-50 text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>r(e=>!e),className:`flex w-full items-center gap-2 px-3 py-2 text-start`,"aria-expanded":n,children:[n?(0,$.jsx)(N,{className:`h-3.5 w-3.5 shrink-0 text-gray-400`}):(0,$.jsx)(w,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 rtl:rotate-180`}),(0,$.jsx)(he,{className:`h-3.5 w-3.5 shrink-0 text-gray-500 dark:text-gray-400`}),(0,$.jsx)(`span`,{className:`truncate font-medium text-gray-700 dark:text-gray-200`,dir:`ltr`,children:e.name}),e.serverName&&(0,$.jsx)(`span`,{className:`truncate text-xs text-gray-500 dark:text-gray-400`,children:e.serverName}),(0,$.jsxs)(`span`,{className:V(`ms-auto flex shrink-0 items-center gap-1 text-xs`,e.status===`succeeded`?`text-green-600 dark:text-green-400`:e.status===`failed`?`text-red-500 dark:text-red-400`:e.status===`denied`?`text-amber-600 dark:text-amber-400`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(Vt,{status:e.status}),i]})]}),n&&(0,$.jsxs)(`div`,{className:`border-t border-gray-200 px-3 py-2 dark:border-dark-200`,children:[(0,$.jsx)(`div`,{className:`text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.arguments`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Bt(e.arguments)}),e.resultPreview!==void 0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`mt-2 text-xs font-medium text-gray-500 dark:text-gray-400`,children:t(`tools.result`)}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-1 max-h-48 overflow-auto whitespace-pre-wrap rounded-sm bg-white p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:e.resultPreview})]})]})]})},Ut=({calls:e,className:t})=>e.length===0?null:(0,$.jsx)(`div`,{className:V(`flex flex-col gap-1.5`,t),children:e.map(e=>(0,$.jsx)(Ht,{call:e},e.id))}),Wt=({approval:e,onDecide:t,className:n})=>{let{t:r}=s(),[i,a]=(0,Q.useState)(!1),o=(0,Q.useId)(),c=async(n,r)=>{a(!0);try{await t(e.approvalId,n,r)}catch{a(!1)}},l=r(`tools.approval.description`,{tool:e.toolCall.name,server:e.toolCall.serverName??r(`tools.approval.builtinSource`)});return(0,$.jsxs)(`div`,{role:`group`,"aria-labelledby":o,className:V(`rounded-lg border border-primary-300/70 bg-primary-50 p-3 text-sm dark:border-primary-700/60 dark:bg-primary-900/20`,n),children:[(0,$.jsxs)(`span`,{className:`sr-only`,role:`alert`,"aria-live":`assertive`,children:[r(`tools.approval.title`),`. `,l]}),(0,$.jsxs)(`div`,{id:o,className:`flex items-center gap-2 font-medium text-primary-800 dark:text-primary-200`,children:[(0,$.jsx)(h,{className:`h-4 w-4 shrink-0`}),r(`tools.approval.title`)]}),(0,$.jsx)(`p`,{className:`mt-1 text-primary-800/90 dark:text-primary-100/80`,children:l}),(0,$.jsx)(`pre`,{dir:`ltr`,className:`mt-2 max-h-32 overflow-auto whitespace-pre-wrap rounded-sm bg-white/70 p-2 font-mono text-xs text-gray-700 dark:bg-dark-100 dark:text-gray-300`,children:Bt(e.toolCall.arguments)}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(Z,{size:`sm`,disabled:i,onClick:()=>void c(!0,`once`),children:r(`tools.approval.allowOnce`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void c(!0,`session`),children:r(`tools.approval.allowSession`)}),(0,$.jsx)(Z,{size:`sm`,variant:`secondary`,disabled:i,onClick:()=>void c(!0,`always`),children:r(`tools.approval.allowAlways`)}),(0,$.jsx)(Z,{size:`sm`,variant:`ghost`,disabled:i,onClick:()=>void c(!1,`once`),children:r(`tools.approval.deny`)})]})]})},Gt=({statistics:e,expanded:t,onExpandedChange:n,hideModel:r=!1,className:i})=>{let{t:a,i18n:o}=s(),c=(0,Q.useId)(),l=(e,t)=>e.toLocaleString(o.language,{minimumFractionDigits:t,maximumFractionDigits:t}),u=e=>{if(e==null)return a(`generationStats.notAvailable`);let t=e/1e6;if(t<1e3)return`${Math.round(t).toLocaleString(o.language)}ms`;let n=t/1e3;return`${l(n,2)}s`},d=e=>e?a(`generationStats.tokensPerSecond`,{value:l(e,1)}):a(`generationStats.notAvailable`),f=e.prompt_eval_count||0,p=e.eval_count||0,m=f+p,h=u(e.total_duration),g=d(e.tokens_per_second),_=[[a(`generationStats.promptTokens`),f],[a(`generationStats.generatedTokens`),p],[a(`generationStats.totalTokens`),m],[a(`generationStats.speed`),g],[a(`generationStats.promptEval`),u(e.prompt_eval_duration)],[a(`generationStats.generation`),u(e.eval_duration)],[a(`generationStats.modelLoad`),u(e.load_duration)],[a(`generationStats.totalTime`),h]];return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{"data-testid":`generation-stats`,className:V(`flex min-w-0 items-center gap-3 text-xs tabular-nums text-ink-subtle`,i),children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!t),"aria-expanded":t,"aria-controls":c,title:a(`generationStats.details`),className:`flex items-center gap-1 rounded-md transition-colors hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,children:[(0,$.jsx)(me,{"aria-hidden":`true`,className:`h-3 w-3`}),a(`generationStats.tokenCount`,{tokens:p.toLocaleString(o.language)})]}),(0,$.jsx)(`span`,{children:g}),(0,$.jsx)(`span`,{children:h}),e.model&&!r&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate sm:max-w-48`,title:e.model,children:e.model})]}),t&&(0,$.jsxs)(`div`,{id:c,className:`mt-1.5 basis-full rounded-xl border border-line bg-surface-subtle p-3 text-xs`,children:[(0,$.jsx)(`dl`,{className:`grid max-w-md grid-cols-2 gap-x-4 gap-y-1.5`,children:_.map(([e,t])=>(0,$.jsxs)(`div`,{className:`flex gap-1 text-ink-muted`,children:[(0,$.jsx)(`dt`,{className:`font-medium text-ink`,children:e}),(0,$.jsx)(`dd`,{className:`tabular-nums`,children:t})]},e))}),e.created_at&&(0,$.jsxs)(`p`,{className:`mt-2 border-t border-line pt-2 text-ink-muted`,children:[(0,$.jsx)(`span`,{className:`font-medium text-ink`,children:a(`generationStats.generatedAt`)}),` `,new Date(e.created_at).toLocaleTimeString(o.language)]})]})]})},Kt={maxQuestions:64,minOptions:2,maxOptions:255,minLevels:2,maxLevels:10},qt=(e=`noul`)=>({type:e,instructions:``,options:[{name:``,description:``},{name:``,description:``}],levels:[``,``,``],trueDescription:``,falseDescription:``});function Jt(e){return Object.values(e??{}).map(e=>{let t=qt(e.type);return t.instructions=e.instructions,e.type===`choice`?t.options=Object.entries(e.criteria).map(([e,t])=>({name:e,description:t??``})):e.type===`score`?t.levels=[...e.criteria]:(t.trueDescription=e.criteria?.true??``,t.falseDescription=e.criteria?.false??``),t})}function Yt(e){if(e.length>Kt.maxQuestions)return{ok:!1,error:{kind:`too-many`}};let t={};for(let[n,r]of e.entries()){let e=n+1,i=r.instructions.trim();if(!i)return{ok:!1,error:{kind:`instructions`,question:e}};if(r.type===`choice`){let n=r.options.map(e=>({name:e.name.trim(),description:e.description.trim()})).filter(e=>e.name||e.description),a=new Set(n.map(e=>e.name));if(n.some(e=>!e.name)||a.size!==n.length||n.length<Kt.minOptions||n.length>Kt.maxOptions)return{ok:!1,error:{kind:`options`,question:e}};t[`q${e}`]={type:`choice`,instructions:i,criteria:Object.fromEntries(n.map(e=>[e.name,e.description||null]))}}else if(r.type===`score`){let n=r.levels.map(e=>e.trim()).filter(Boolean);if(n.length<Kt.minLevels||n.length>Kt.maxLevels)return{ok:!1,error:{kind:`levels`,question:e}};t[`q${e}`]={type:`score`,instructions:i,criteria:n}}else{let n=r.trueDescription.trim(),a=r.falseDescription.trim();t[`q${e}`]=n||a?{type:`noul`,instructions:i,criteria:{...n?{true:n}:{},...a?{false:a}:{}}}:{type:`noul`,instructions:i}}}return{ok:!0,questions:Object.keys(t).length>0?t:void 0}}function Xt(e,t){if(!t||t.type===`refusal`)return{label:``,kind:`refusal`,distribution:[]};if(t.type===`noul`){let e=t.noul>=.5;return{label:``,kind:e?`yes`:`no`,probability:e?t.noul:1-t.noul,distribution:[{label:`yes`,probability:t.noul},{label:`no`,probability:1-t.noul}],...t.confidence===void 0?{}:{confidence:t.confidence}}}let n=Object.entries(t.probabilities).map(([e,n])=>({label:t.type===`score`?t.legend[e]??e:String(e),probability:n})).sort((e,t)=>t.probability-e.probability);if(t.type===`choice`)return{label:t.choice,kind:`choice`,probability:t.probabilities[t.choice],distribution:n,...t.confidence===void 0?{}:{confidence:t.confidence}};let r=e?.type===`score`?e.criteria.length:Object.keys(t.legend).length;return{label:n[0]?.label??``,kind:`score`,probability:n[0]?.probability,score:{value:t.score+1,max:r},distribution:n,...t.confidence===void 0?{}:{confidence:t.confidence}}}var Zt=e=>`${(Math.round(e*1e3)/10).toFixed(1)}%`;function Qt(e){let t=e?.decision;if(!t||typeof t!=`object`)return null;let n=t.kind;return n===`state`||n===`cleared`?{kind:n}:n===`answers`&&typeof t.questions==`object`&&typeof t.answers==`object`?t:null}var $t=({value:e,strong:t})=>(0,$.jsx)(`div`,{"aria-hidden":`true`,className:`h-1.5 w-full overflow-hidden rounded-full bg-gray-100 dark:bg-dark-200`,children:(0,$.jsx)(`div`,{className:V(`h-full rounded-full`,t?`bg-primary-500 dark:bg-primary-400`:`bg-gray-300 dark:bg-dark-400`),style:{width:`${Math.max(0,Math.min(1,e))*100}%`}})}),en=({metadata:e})=>{let{t}=s();if(e.kind!==`answers`)return(0,$.jsx)(`p`,{"data-testid":`decision-result-note`,className:`text-sm text-ink-muted`,children:e.kind===`state`?t(`chat.decision.result.stateSaved`):t(`chat.decision.result.cleared`)});let n=e.usage?.inputTokens;return(0,$.jsxs)(`div`,{"data-testid":`decision-result`,className:`space-y-3`,children:[Object.entries(e.questions).map(([n,r])=>{let i=Xt(r,e.answers[n]),a=i.kind===`refusal`?t(`chat.decision.result.declined`):i.kind===`yes`?t(`chat.decision.result.yes`):i.kind===`no`?t(`chat.decision.result.no`):i.label;return(0,$.jsxs)(`section`,{className:`rounded-xl border border-line px-3 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`min-w-0 text-sm text-ink`,children:r.instructions}),(0,$.jsx)(`span`,{className:`shrink-0 text-[11px] text-ink-muted`,children:t(`chat.decision.types.${r.type}`)})]}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex items-baseline gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,"data-testid":`decision-answer`,className:`text-base font-semibold text-ink`,children:a}),i.probability!==void 0&&(0,$.jsx)(`span`,{className:`text-sm tabular-nums text-primary-700 dark:text-primary-300`,children:Zt(i.probability)}),i.score&&(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-ink-muted`,children:t(`chat.decision.result.score`,{value:i.score.value.toFixed(2),max:i.score.max})})]}),i.kind!==`refusal`&&i.kind!==`yes`&&i.kind!==`no`&&i.distribution.length>1&&(0,$.jsx)(`ul`,{className:`mt-2 space-y-1`,children:i.distribution.map(e=>(0,$.jsxs)(`li`,{className:`grid grid-cols-[minmax(0,10rem)_1fr_3.5rem] items-center gap-2 text-xs`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`truncate text-ink-muted`,children:e.label}),(0,$.jsx)($t,{value:e.probability,strong:e.label===i.label}),(0,$.jsx)(`span`,{className:`text-end tabular-nums text-ink-muted`,children:Zt(e.probability)})]},e.label))}),(i.kind===`yes`||i.kind===`no`)&&i.probability!==void 0&&(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)($t,{value:i.probability,strong:!0})})]},n)}),(0,$.jsxs)(`p`,{className:`text-[11px] text-ink-subtle`,children:[t(`chat.decision.result.via`,{model:e.model,provider:e.provider}),n!==void 0&&` · ${t(`chat.decision.result.inputTokens`,{tokens:n})}`]})]})},tn=Y(`components:ttsbutton`),nn=null,rn=null,an=0,on=3e5;async function sn(e=!1){let t=Date.now();return!e&&nn!==null&&t-an<on?nn:rn||(rn=(async()=>{try{let e=await Fe.getModels();return e.success&&e.data&&e.data.length>0?(nn=e.data,an=t,e.data):(nn=[],an=t,[])}catch{return nn=[],an=t,[]}finally{rn=null}})(),rn)}var cn=({text:e,className:t,size:n=`sm`,externalPlaybackState:r,onStopExternal:i,onRetryExternal:a})=>{let{t:o,i18n:c}=s(),{preferences:l}=Ke(),[u,d]=(0,Q.useState)(`idle`),[f,p]=(0,Q.useState)(null),[m,h]=(0,Q.useState)([]),[g,_]=(0,Q.useState)(null),v=(0,Q.useRef)(null),b=(0,Q.useRef)(0);(0,Q.useEffect)(()=>{let e=!0;return(async()=>{let t=await sn(),n=Be(t,l.ttsSettings?.model,l.ttsSettings?.pluginId);l.ttsSettings?.model&&!n&&(t=await sn(!0)),e&&(h(t),_(t.length>0))})(),()=>{e=!1}},[l.ttsSettings?.model,l.ttsSettings?.pluginId]);let x=()=>{b.current+=1,v.current?.cancel(),v.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`||v.current){x();return}let t=Qe();d(`loading`),p(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=J(m,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,h=f&&i?.voiceProfileId||void 0,g=i?.speed||1,_=a?.config?.default_format,y=Math.max(1,a?.config?.max_characters||600),x=Math.min(y,600),S=i?.streamSentences!==!1||e.length>x?Ze(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})=>Fe.generate({model:s,pluginId:u,input:e,voice:h?void 0:p||void 0,voiceProfileId:h,speed:g,response_format:_},{signal:t}),onStateChange:e=>{b.current===n&&d(e)}});v.current=C;let w=$e(C);try{await C.play(S)}finally{w(),v.current===C&&(v.current=null)}}catch(e){if(b.current!==n)return;if(Je(e)){d(`idle`);return}if(Xe(e)){d(`blocked`);return}p(o(`ttsButton.generateFailed`)),tn.error(`TTS error:`,e),d(`error`)}};if((0,Q.useEffect)(()=>()=>{b.current+=1,v.current?.cancel(),v.current=null},[]),g===!1||g===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,ee=T===`loading`||T===`generating`||T===`buffering`,D=T===`playing`,O=T===`blocked`,k=!!f||T===`error`,A=f||o(k?`ttsButton.playbackFailed`:O?`ttsButton.enableAudio`:D||ee?D?`ttsButton.stopSpeaking`:T===`buffering`?`ttsButton.bufferingSpeech`:T===`generating`?`ttsButton.generatingSpeech`:`ttsButton.preparingSpeech`:`ttsButton.readAloud`);return(0,$.jsxs)(`button`,{onClick:S,disabled:!e,title:A,"aria-label":A,"aria-busy":ee||void 0,className:V(`inline-flex items-center justify-center rounded-full transition-all duration-200`,`hover:bg-gray-100 dark:hover:bg-dark-200`,`focus:outline-hidden 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:[ee?(0,$.jsx)(E,{className:V(w[n],`animate-spin`)}):D?(0,$.jsx)(y,{className:w[n]}):k||O?(0,$.jsx)(j,{className:w[n]}):(0,$.jsx)(de,{className:w[n]}),O&&(0,$.jsx)(`span`,{className:`whitespace-nowrap text-xs font-medium`,children:o(`ttsButton.enableAudioShort`)})]})},ln=80,un=5e3,dn=15e3;function fn({sessionId:e,messageId:t,thinking:n,isThinking:r,isPrivate:i}){let a=Ke(e=>e.preferences.titleSettings),o=(0,Q.useRef)(n),[s,c]=(0,Q.useState)(null),{autoTitle:l,taskModel:u,taskProviderType:d,taskProviderId:f}=a??{};return(0,Q.useEffect)(()=>{o.current=n},[n]),(0,Q.useEffect)(()=>{if(!e||!r||i||!l||!u||qe())return;let n=!1,a,s=``,p=new AbortController,m=async()=>{let r=(o.current??``).slice(-4e3).trim();if(r.length<ln||r===s){n||(a=setTimeout(()=>void m(),400));return}s=r;let i=Date.now(),l=un;try{let i=await G.summarizeThinking(e,{model:u,thinking:r,providerType:d,providerId:f},p.signal);if(!i.success||!i.data?.summary?.trim())throw Error(`Thinking summary unavailable`);n||c({sessionId:e,messageId:t,summary:i.data.summary.trim().slice(0,160)})}catch{l=dn}n||(a=setTimeout(()=>void m(),Math.max(0,l-(Date.now()-i))))};return a=setTimeout(()=>void m(),350),()=>{n=!0,clearTimeout(a),p.abort()}},[e,t,r,i,l,u,d,f]),s&&s.sessionId===e&&s.messageId===t?s.summary:null}var pn=[`accuracy`,`style`,`incomplete`,`harmful`,`formatting`],mn=Y(`components:chat-message`);function hn({role:e,user:t,persona:n,modelAvatar:r}){let{t:i}=s(),[a,o]=(0,Q.useState)(null);if(e===`assistant`){if(n)return(0,$.jsx)(`img`,{src:Le(n,64),alt:n.name,"data-testid":`chat-assistant-avatar`,onError:e=>K(e.currentTarget,n.name,64),className:`mt-0.5 h-8 w-8 shrink-0 rounded-lg object-cover`});let e=r?.trim()??``,t=e.startsWith(`data:`)&&e!==a?e:``;return(0,$.jsx)(`div`,{role:`img`,"aria-label":`Libre WebUI`,"data-testid":`chat-assistant-avatar`,className:`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full border border-black/[0.07] bg-white text-gray-900 shadow-xs dark:border-white/9 dark:bg-dark-200 dark:text-dark-950`,children:t?(0,$.jsx)(`img`,{src:t,alt:``,className:`h-full w-full object-cover`,onError:()=>o(e)}):e?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-base leading-none`,children:e}):(0,$.jsx)(xt,{label:null,className:`h-4 w-4`})})}let c=t?.username||i(`chatMessage.user`),l=t?.avatar?.trim()||``,u=!!l&&l!==a;return(0,$.jsx)(`div`,{role:u?void 0:`img`,"aria-label":u?void 0:c,"data-testid":`chat-user-avatar`,className:V(`mt-0.5 flex h-8 w-8 shrink-0 items-center justify-center overflow-hidden rounded-full`,u?`border border-black/[0.07] bg-white dark:border-white/9 dark:bg-dark-200`:`bg-gray-950 text-white dark:bg-white dark:text-gray-950`),title:c,children:u?(0,$.jsx)(`img`,{src:l,alt:c,className:`h-full w-full object-cover`,onError:()=>o(l)}):t?.username?(0,$.jsx)(`span`,{"aria-hidden":`true`,className:`text-xs font-medium uppercase leading-none`,children:t.username.charAt(0)}):(0,$.jsx)(M,{"aria-hidden":`true`,className:`h-4 w-4`})})}var gn=Q.memo(({message:e,isStreaming:t=!1,className:n,isLastAssistantMessage:r=!1,onRegenerate:i,onFork:a,onEditResend:o})=>{let{t:c,i18n:l}=s(),u=e.role===`user`,d=e.role===`system`,f=d&&st(e.content),m=f?e.content.slice(ht.length):e.content,h=Ke(e=>e.preferences),g=St(e=>e.user),_=X(e=>e.setSystemMessage),v=X(e=>e.rateMessage),y=X(e=>e.modelMetadata),b=X(e=>e.currentSession?.id),x=X(e=>e.currentSession?.model),w=X(e=>e.currentSession?.isPrivate===!0),T=X(e=>e.getCurrentPersona()),E=e.model||x||``,ee=E?y[E]??Object.entries(y).find(([e])=>e.slice(e.indexOf(`/`)+1)===E)?.[1]:void 0,[D,te]=(0,Q.useState)(!1),[ne,j]=(0,Q.useState)(!1),[M,P]=(0,Q.useState)(e.content),[F,se]=(0,Q.useState)(null),ce=(0,Q.useRef)(null);Ct(ce,{enabled:F!==null,onClose:()=>se(null)});let[ue,de]=(0,Q.useState)(!1),[fe,pe]=(0,Q.useState)(!1),[me,he]=(0,Q.useState)(!1),ge=(0,Q.useId)(),[_e,R]=(0,Q.useState)(`idle`),[ye,be]=(0,Q.useState)(null),[xe,Se]=(0,Q.useState)([]),[Ce,we]=(0,Q.useState)(``),[z,Ee]=(0,Q.useState)(!1),De=(0,Q.useRef)(null),B=(0,Q.useRef)(0),H=(0,Q.useRef)(t),Ae=(0,Q.useRef)(!1),je=async()=>{try{await navigator.clipboard.writeText(e.content),Tt(`success`),Ee(!0),setTimeout(()=>Ee(!1),2e3)}catch(e){mn.error(`Failed to copy message:`,e),I.error(c(`chat.message.copyFailed`))}},W=(0,Q.useMemo)(()=>Qt(e.providerMetadata),[e.providerMetadata]),{thinkingContent:Ne,thinkingStreaming:K,parsedContent:q,artifacts:Ie}=(0,Q.useMemo)(()=>{if(u||d||!e.content&&!e.thinking)return{thinkingContent:null,thinkingStreaming:!1,parsedContent:e.content,artifacts:e.artifacts||[]};let n=e.thinking?{thinking:e.thinking,content:e.content,thinkingComplete:!!e.content||!t}:ke(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=rt(r);return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:e.content,artifacts:e.artifacts}}return{thinkingContent:n.thinking,thinkingStreaming:i,parsedContent:r,artifacts:[]}},[e.content,e.thinking,e.artifacts,u,d,t]),Le=K?void 0:e.statistics?.thinking_duration_ms??et(e.id),Re=fn({sessionId:b,messageId:e.id,thinking:Ne,isThinking:K,isPrivate:w}),ze=Le===void 0?c(`chatMessage.thinking`):c(`chatMessage.thoughtFor`,{duration:tt(Le)}),Ve=(0,Q.useCallback)(async e=>{let t=B.current+1;B.current=t,De.current?.cancel(),De.current=null,R(`loading`);try{if(e){let n=await e;if(B.current!==t)return;if(n===`blocked`){R(`blocked`);return}}let n=await Fe.getModels();if(B.current!==t)return;let r=n.success&&n.data?n.data:[],i=h.ttsSettings,a=J(r,i?.model,i?.pluginId),o=Be(r,i?.model,i?.pluginId),s=a?.model||i?.model||`tts-1`,c=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),m=i?.streamSentences!==!1||q.length>p?Ze(q,{locale:l.language,maxChars:p,targetChars:Math.min(p,420),minChars:Math.min(p,80)}):[q.trim()];if(m.length===0){R(`idle`);return}let g=Ye({concurrency:3,initialBufferSize:Math.min(2,m.length),generate:(e,{signal:t})=>Fe.generate({model:s,pluginId:c,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=>{B.current===t&&R(e)}});if(B.current!==t){g.cancel();return}De.current=g;let _=$e(g);try{await g.play(m)}finally{_(),De.current===g&&(De.current=null),B.current===t&&(g.state===`ended`||g.state===`cancelled`)&&R(`idle`)}}catch(e){if(B.current!==t)return;Je(e)?R(`idle`):Xe(e)?R(`blocked`):(mn.error(`Auto-play TTS failed:`,e),R(`error`))}},[l.language,q,h.ttsSettings]);(0,Q.useEffect)(()=>{let e=H.current&&!t;H.current=t,e&&!Ae.current&&!u&&!d&&q&&h.ttsSettings?.enabled&&h.ttsSettings.autoPlay&&(Ae.current=!0,Ve())},[t,u,d,q,h.ttsSettings?.autoPlay,h.ttsSettings?.enabled,Ve]),(0,Q.useEffect)(()=>()=>{B.current+=1,De.current?.cancel(),De.current=null},[]);let He=()=>{let e=Qe();Ve(e)},Ue=()=>{B.current+=1,De.current?.cancel(),De.current=null,R(`idle`)},We=()=>f?c(`chatMessage.conversationSummary`):d?c(`chatMessage.system`):u?h.showUsername&&g?.username?g.username:c(`chatMessage.you`):T?.name?T.name:ee?.label||E||c(`chatMessage.assistant`),Ge=()=>{te(!0),P(e.content)},[qe,Y]=(0,Q.useState)(!1),nt=async()=>{if(b&&!qe){Y(!0);try{let t=await G.restoreCompaction(b,e.id);if(!t.success||!t.data)throw Error(t.error||`Restore failed`);let n=t.data;X.setState(e=>({sessions:e.sessions.map(e=>e.id===n.id?n:e),currentSession:e.currentSession?.id===n.id?n:e.currentSession}))}catch(e){mn.error(`Failed to restore compacted messages:`,e),I.error(c(`chatMessage.restoreFailed`))}finally{Y(!1)}}},it=async()=>{de(!0);try{_(M),te(!1),mn.debug(`✅ System message updated:`,M)}catch(e){mn.error(`Failed to save system message:`,e)}finally{de(!1)}},at=()=>{te(!1),P(e.content)},ot=()=>{let t=M.trim();te(!1),t&&o?.(e.id,t)},ct=t=>{if(!b)return;let n=e.rating===t;v(b,e.id,n?void 0:t),w||(n?(be(null),wt.deleteFeedback(e.id).catch(()=>I.error(c(`chatMessage.feedbackFailed`)))):(Se([]),we(``),be(t===1?1:-1),wt.upsertFeedback({sessionId:b,messageId:e.id,rating:t===1?1:-1}).catch(()=>I.error(c(`chatMessage.feedbackFailed`)))))},lt=()=>{b&&ye!==null&&(wt.upsertFeedback({sessionId:b,messageId:e.id,rating:ye,tags:xe,...Ce.trim()?{comment:Ce.trim()}:{}}).catch(()=>I.error(c(`chatMessage.feedbackFailed`))),be(null))},ut=(e,t=100)=>e.length<=t?e:e.substring(0,t)+`...`,dt=d&&m.length>100;return(0,$.jsxs)(`div`,{className:V(`group flex py-1.5 transition-colors sm:py-2`,u?`justify-end`:`justify-start`,n),children:[(0,$.jsxs)(`div`,{className:V(`flex min-w-0 gap-2.5 sm:gap-3`,u?`max-w-[85%] sm:max-w-[70%] wide:sm:max-w-[min(70%,56rem)]`:`w-full`),children:[!u&&!d&&(0,$.jsx)(hn,{role:`assistant`,persona:T,modelAvatar:ee?.avatar}),(0,$.jsxs)(`div`,{className:V(`min-w-0 flex-1`,u?`flex flex-col items-end`:d?`py-1.5`:`py-0.5`),children:[!u&&!d&&(0,$.jsxs)(`div`,{className:`mb-1 flex items-center gap-2`,children:[(0,$.jsx)(`span`,{dir:`auto`,className:`text-[11px] font-semibold uppercase tracking-[0.08em] text-ink-muted rtl:tracking-normal`,children:We()}),e.model&&T?.name&&(0,$.jsx)(`span`,{dir:`ltr`,className:`max-w-32 truncate rounded-full bg-gray-100 px-2 py-0.5 text-[10px] text-gray-500 dark:bg-dark-200 dark:text-dark-600 sm:max-w-48`,title:e.model,children:e.model}),(0,$.jsx)(`span`,{dir:`auto`,className:`text-[10px] tabular-nums text-ink-subtle`,children:Oe(e.timestamp,l.language)})]}),(0,$.jsxs)(`div`,{className:V(!u&&!d&&`text-[0.9375rem] leading-[1.65] text-ink`),children:[e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1.5 grid max-w-lg grid-cols-2 gap-1.5 sm:grid-cols-3`,children:e.images.map((e,t)=>(0,$.jsx)(`div`,{className:`aspect-square overflow-hidden rounded-xl border border-black/6 bg-gray-100 dark:border-white/8 dark:bg-gray-800`,children:(0,$.jsx)(`button`,{type:`button`,className:`block h-full w-full`,"aria-label":c(`chatMessage.openImage`,{number:t+1}),onClick:()=>se(e),children:(0,$.jsx)(`img`,{src:e,alt:c(`chatMessage.uploadedImageAlt`,{number:t+1}),className:`w-full h-full object-cover cursor-pointer hover:opacity-90 transition-opacity`})})},t))}),u?D?(0,$.jsxs)(`div`,{className:`w-full min-w-[min(28rem,80vw)] rounded-2xl border border-black/8 bg-white p-2 shadow-xs focus-within:border-primary-500 focus-within:ring-2 focus-within:ring-primary-500/30 dark:border-white/8 dark:bg-dark-100`,children:[(0,$.jsx)(`textarea`,{"aria-label":c(`chatMessage.edit`),dir:`auto`,value:M,onChange:e=>P(e.target.value),onKeyDown:e=>{e.nativeEvent.isComposing||e.nativeEvent.keyCode===229||(e.key===`Enter`&&!e.shiftKey?(e.preventDefault(),ot()):e.key===`Escape`&&at())},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-hidden dark:text-dark-900`}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5 px-1 pb-1`,children:[(0,$.jsx)(Z,{type:`button`,variant:`ghost`,size:`sm`,onClick:at,children:c(`chatMessage.cancelEditing`)}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:ot,children:c(`chatMessage.saveAndSubmit`)})]})]}):(0,$.jsx)(`div`,{"data-user-bubble":``,className:`rounded-2xl rounded-ee-md border border-line bg-surface-subtle px-4 py-2.5 text-ink`,children:(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-[0.9375rem] leading-relaxed`,children:e.content})}):d?(0,$.jsxs)(`div`,{className:`relative z-0 rounded-2xl border border-black/6 bg-white/55 p-3 dark:border-white/6 dark:bg-dark-200/45`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between text-[10px] font-semibold uppercase tracking-[0.12em] text-gray-500 dark:text-dark-500`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[f?(0,$.jsx)(k,{className:`h-2.5 w-2.5 opacity-50`}):(0,$.jsx)(O,{className:`h-2.5 w-2.5 opacity-50`}),c(f?`chatMessage.conversationSummary`:`chatMessage.system`)]}),(0,$.jsx)(`div`,{className:`flex items-center gap-1`,children:f?(0,$.jsx)(`button`,{onClick:()=>void nt(),disabled:qe,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.restoreCompacted`),"aria-label":c(`chatMessage.restoreCompacted`),children:(0,$.jsx)(le,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})}):D?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:it,disabled:ue,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.saveChanges`),"aria-label":c(`chatMessage.saveChanges`),children:(0,$.jsx)(p,{className:`h-3 w-3 text-green-600 dark:text-green-400`})}),(0,$.jsx)(`button`,{onClick:at,disabled:ue,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 disabled:opacity-50 dark:hover:bg-dark-300`,title:c(`chatMessage.cancelEditing`),"aria-label":c(`chatMessage.cancelEditing`),children:(0,$.jsx)(L,{className:`h-3 w-3 text-red-600 dark:text-red-400`})})]}):(0,$.jsx)(`button`,{onClick:Ge,className:`rounded-lg p-1.5 transition-colors hover:bg-gray-100 dark:hover:bg-dark-300`,title:c(`chatMessage.editSystemMessage`),"aria-label":c(`chatMessage.editSystemMessage`),children:(0,$.jsx)(oe,{className:`h-3 w-3 text-gray-600 dark:text-gray-400`})})})]}),D?(0,$.jsx)(`textarea`,{"aria-label":c(`chatMessage.editSystemMessage`),dir:`auto`,value:M,onChange:e=>P(e.target.value),className:`min-h-[100px] w-full resize-none rounded-xl border border-black/8 bg-white p-3 text-sm text-gray-900 focus:border-transparent focus:outline-hidden focus:ring-2 focus:ring-primary-500 dark:border-white/8 dark:bg-dark-100 dark:text-dark-900 dark:focus:ring-primary-400`,placeholder:c(`chatMessage.systemMessagePlaceholder`),disabled:ue}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{dir:`auto`,className:`whitespace-pre-wrap text-xs leading-relaxed text-gray-500 dark:text-dark-600`,children:fe?m:ut(m)}),dt&&(0,$.jsx)(`button`,{type:`button`,"aria-expanded":fe,onClick:()=>pe(!fe),className:`mt-2 flex items-center gap-1 text-xs text-ink-muted transition-colors hover:text-ink`,children:fe?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(A,{className:`h-3 w-3`}),c(`chatMessage.showLess`)]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(N,{className:`h-3 w-3`}),c(`chatMessage.showMore`)]})})]})]}):(0,$.jsxs)(`div`,{className:`relative`,children:[(Ne||K)&&(0,$.jsxs)(`div`,{className:`mb-3 border-s border-gray-200 ps-3 dark:border-dark-300`,children:[(0,$.jsxs)(`button`,{type:`button`,"data-testid":`thinking-toggle`,"aria-expanded":me,"aria-controls":ge,onClick:()=>he(!me),className:`flex min-h-11 max-w-full items-center gap-1.5 rounded-md py-2 text-start text-xs text-ink-muted transition-colors hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/30`,children:[K?(0,$.jsx)(U,{"data-testid":`thinking-generation-indicator`}):(0,$.jsx)(ae,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}),(0,$.jsxs)(`span`,{role:`status`,"aria-live":K?`polite`:`off`,"aria-atomic":`true`,className:`min-w-0 wrap-anywhere`,children:[(0,$.jsx)(`span`,{"data-testid":`thinking-summary`,dir:`auto`,className:V(`block font-medium`,K&&`animate-slide-up [animation-duration:140ms] motion-reduce:animate-none`),children:Re||(K?`${c(`chatMessage.thinking`)}…`:ze)},Re||`thinking`),Re&&!K&&(0,$.jsx)(`span`,{className:`mt-0.5 block text-ink-subtle`,children:ze})]}),me?(0,$.jsx)(A,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`}):(0,$.jsx)(N,{"aria-hidden":`true`,className:`h-3.5 w-3.5 shrink-0`})]}),(0,$.jsx)(`div`,{id:ge,"data-testid":`thinking-content`,hidden:!me,dir:`auto`,className:`mt-2 rounded-xl bg-gray-100/60 p-2.5 text-[13px] leading-relaxed text-gray-600 dark:bg-dark-200/60 dark:text-dark-700`,children:me&&Ne&&(0,$.jsx)(Me,{content:Ne,isStreaming:K,className:`text-[13px] text-ink-muted`})})]}),W&&!t?(0,$.jsx)(en,{metadata:W}):(0,$.jsx)(Me,{content:q,isStreaming:t&&!(K&&!q)})]}),!u&&!d&&Ie.length>0&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(Pe,{artifacts:Ie})}),!u&&!d&&Array.isArray(e.providerMetadata?.toolCalls)&&e.providerMetadata.toolCalls.length>0&&(0,$.jsx)(Ut,{calls:e.providerMetadata.toolCalls,className:`mt-2.5`}),!u&&!d&&Array.isArray(e.providerMetadata?.webSearchSources)&&e.providerMetadata.webSearchSources.length>0&&(0,$.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-[0.12em] text-ink-subtle rtl:tracking-normal`,children:c(`chat.message.sources`,`Sources`)}),e.providerMetadata.webSearchSources.map((e,t)=>typeof e?.url==`string`?(0,$.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,dir:`ltr`,className:`inline-flex max-w-[220px] items-center gap-1 rounded-full border border-gray-200 bg-gray-50 px-2 py-0.5 text-[11px] text-gray-600 transition-colors hover:border-primary-300 hover:text-primary-600 dark:border-dark-300 dark:bg-dark-200 dark:text-dark-700 dark:hover:text-primary-400`,title:e.title||e.url,children:[(0,$.jsx)(`span`,{className:`tabular-nums`,children:t+1}),(0,$.jsx)(`span`,{className:`truncate`,children:(()=>{try{return new URL(e.url).hostname.replace(/^www\./,``)}catch{return e.url}})()})]},`${e.url}-${t}`):null)]}),!d&&!t&&(0,$.jsxs)(`div`,{"data-testid":`message-action-row`,className:V(`flex flex-wrap items-center gap-0.5 text-ink-subtle`,`sm:transition-opacity sm:duration-150 sm:group-hover:opacity-100 sm:group-focus-within:opacity-100`,!u&&(r||ne||ye!==null||[`loading`,`generating`,`buffering`,`blocked`,`playing`].includes(_e))?`sm:opacity-100`:`[@media(hover:hover)]:sm:opacity-0`,u?`mt-1 justify-end`:`mt-1.5`),children:[u&&(0,$.jsxs)(`span`,{dir:`auto`,className:`me-1 text-[10px] tabular-nums`,title:Oe(e.timestamp,l.language),children:[We(),` ·`,` `,Oe(e.timestamp,l.language)]}),!u&&q&&(0,$.jsx)(cn,{text:q,size:`sm`,externalPlaybackState:_e,onStopExternal:Ue,onRetryExternal:He,className:V(`transition-colors`,_e===`playing`&&`bg-primary-50 text-primary-600 dark:bg-primary-900/20 dark:text-primary-400`)}),u&&o&&!D&&(0,$.jsx)(`button`,{onClick:()=>{P(e.content),te(!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:c(`chatMessage.edit`),"aria-label":c(`chatMessage.edit`),children:(0,$.jsx)(oe,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`button`,{type:`button`,onClick:je,"aria-label":c(z?`chatMessage.copied`:`chatMessage.copyMessage`),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:c(z?`chatMessage.copied`:`chatMessage.copyMessage`),children:z?(0,$.jsx)(ve,{className:`h-3.5 w-3.5 text-green-500`}):(0,$.jsx)(S,{className:`h-3.5 w-3.5`})}),!u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`button`,{onClick:()=>ct(1),className:V(`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:c(`chatMessage.goodResponse`),"aria-label":c(`chatMessage.goodResponse`),"aria-pressed":e.rating===1,children:(0,$.jsx)(Te,{className:`h-3.5 w-3.5`,fill:e.rating===1?`currentColor`:`none`})}),(0,$.jsx)(`button`,{onClick:()=>ct(-1),className:V(`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:c(`chatMessage.badResponse`),"aria-label":c(`chatMessage.badResponse`),"aria-pressed":e.rating===-1,children:(0,$.jsx)(ie,{className:`h-3.5 w-3.5`,fill:e.rating===-1?`currentColor`:`none`})}),ye!==null&&(0,$.jsxs)(`div`,{className:`ms-1 flex flex-wrap items-center gap-1 rounded-lg border border-gray-200 bg-white px-2 py-1 dark:border-dark-300 dark:bg-dark-100`,"data-testid":`feedback-details`,children:[pn.map(e=>(0,$.jsx)(`button`,{type:`button`,onClick:()=>Se(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),className:V(`rounded-full border px-2 py-0.5 text-[10px]`,xe.includes(e)?`border-primary-500 bg-primary-50 text-primary-700 dark:bg-primary-950/40 dark:text-primary-300`:`border-gray-300 text-gray-500 dark:border-dark-300`),"aria-pressed":xe.includes(e),children:c(`chatMessage.feedbackTags.${e}`)},e)),(0,$.jsx)(`input`,{value:Ce,onChange:e=>we(e.target.value),placeholder:c(`chatMessage.feedbackComment`),"aria-label":c(`chatMessage.feedbackComment`),className:`w-32 rounded-sm border border-gray-300 px-1.5 py-0.5 text-[10px] focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-dark-300 dark:bg-dark-50`,maxLength:2e3}),(0,$.jsx)(Z,{type:`button`,size:`sm`,onClick:lt,className:`h-6 px-2 text-[10px]`,children:c(`common.save`)}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>be(null),"aria-label":c(`common.close`),className:`rounded-sm p-0.5 text-ink-muted hover:text-ink`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]})]}),!u&&r&&i&&(0,$.jsx)(`button`,{onClick:i,className:`flex h-7 w-7 items-center justify-center rounded-full transition-colors hover:bg-gray-100 hover:text-gray-800 dark:hover:bg-dark-200 dark:hover:text-dark-800`,title:c(`chatMessage.regenerateResponse`),"aria-label":c(`chatMessage.regenerateResponse`),children:(0,$.jsx)(C,{className:`h-3.5 w-3.5`})}),a&&(0,$.jsx)(`button`,{onClick:()=>a(e.id),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:c(`chat.fork.action`),"aria-label":c(`chat.fork.action`),"data-testid":`fork-from-message`,children:(0,$.jsx)(re,{className:`h-3.5 w-3.5`})}),!u&&e.statistics&&(0,$.jsx)(Gt,{statistics:e.statistics,expanded:ne,onExpandedChange:j,hideModel:!!(e.model&&T?.name),className:`ms-2`})]})]})]}),u&&(0,$.jsx)(hn,{role:`user`,user:g??null})]}),F&&(0,zt.createPortal)((0,$.jsxs)(`div`,{ref:ce,role:`dialog`,"aria-modal":`true`,"aria-label":c(`chatMessage.fullSizeImage`),tabIndex:-1,className:`fixed inset-0 z-9999 flex items-center justify-center bg-black/85 p-6 backdrop-blur-md`,onClick:()=>se(null),children:[(0,$.jsx)(`button`,{type:`button`,"aria-label":c(`common.close`),className:`absolute inset-e-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(),se(null)},children:(0,$.jsx)(L,{className:`h-7 w-7`})}),(0,$.jsx)(`img`,{src:F,alt:c(`chatMessage.fullSizeImage`),className:`max-h-[90vh] max-w-[90vw] rounded-2xl object-contain shadow-2xl`,onClick:e=>e.stopPropagation()})]}),document.body)]})});gn.displayName=`ChatMessage`;var _n=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches,vn=220,yn=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>vn?`${t.slice(0,219).trimEnd()}…`:t},bn=Q.memo(function({items:e,activeId:t,onSelect:n}){let{t:r}=s(),i=(0,Q.useRef)(null),a=(0,Q.useRef)(null),o=(0,Q.useRef)(new Map),[c,l]=(0,Q.useState)(null),[u,d]=(0,Q.useState)(0),f=(0,Q.useCallback)((e,t)=>{let n=i.current;if(!n)return;let r=n.getBoundingClientRect(),a=t.getBoundingClientRect();d(a.top-r.top+a.height/2),l(e)},[]),p=(0,Q.useCallback)(t=>{let r=e[t],i=r?o.current.get(r.id):void 0;r&&i&&(i.focus(),f(r.id,i),n(r.id))},[e,n,f]);if((0,Q.useEffect)(()=>{if(!t)return;let e=a.current,n=o.current.get(t);if(!e||!n)return;let r=e.getBoundingClientRect(),i=n.getBoundingClientRect(),s=null;i.top<r.top?s=e.scrollTop-(r.top-i.top)-8:i.bottom>r.bottom&&(s=e.scrollTop+(i.bottom-r.bottom)+8),s!==null&&e.scrollTo({top:s,behavior:_n()?`auto`:`smooth`})},[t]),e.length<3)return null;let m=Math.max(0,e.findIndex(e=>e.id===t)),h=e[m]?.id,g=e.findIndex(e=>e.id===c),_=g>=0?e[g]:null,v=g>=0?`conversation-history-preview-${g}`:void 0;return(0,$.jsxs)(`nav`,{ref:i,"data-testid":`conversation-history-rail`,"aria-label":r(`chatHistory.label`),className:`group/rail pointer-events-none absolute inset-s-[max(0.25rem,calc(50%_-_27rem))] top-1/2 z-20 hidden h-[min(58vh,30rem)] w-7 -translate-y-1/2 lg:block xl:w-9 wide:inset-s-1`,onPointerLeave:()=>{i.current?.contains(document.activeElement)||l(null)},children:[(0,$.jsx)(`ol`,{ref:a,className:`pointer-events-auto flex h-full min-h-0 flex-col overflow-y-auto py-2 opacity-40 transition-opacity duration-150 scrollbar-none group-hover/rail:opacity-100 group-focus-within/rail:opacity-100 motion-reduce:transition-none [&::-webkit-scrollbar]:hidden [&>li:first-child]:mt-auto [&>li:last-child]:mb-auto`,children:e.map((t,a)=>{let s=t.id===h,u=Math.abs(a-m),d=c===t.id?v:void 0;return(0,$.jsx)(`li`,{className:`flex h-4 flex-none items-center`,children:(0,$.jsx)(`button`,{ref:e=>{e?o.current.set(t.id,e):o.current.delete(t.id)},type:`button`,"data-testid":`conversation-history-marker`,"aria-current":s?`location`:void 0,"aria-describedby":d,"aria-label":r(`chatHistory.jumpToTurn`,{index:a+1,total:e.length}),tabIndex:a===m?0:-1,className:V(`group flex h-4 w-7 items-center outline-hidden xl:w-9`,`focus-visible:ring-2 focus-visible:ring-primary-500/45 focus-visible:ring-offset-2 focus-visible:ring-offset-canvas`,`rounded-xs`),onClick:()=>n(t.id),onPointerEnter:e=>f(t.id,e.currentTarget),onFocus:e=>f(t.id,e.currentTarget),onBlur:()=>{window.requestAnimationFrame(()=>{i.current?.contains(document.activeElement)||l(null)})},onKeyDown:t=>{if(t.key===`Escape`){l(null);return}let n=null;t.key===`ArrowDown`?n=Math.min(e.length-1,a+1):t.key===`ArrowUp`?n=Math.max(0,a-1):t.key===`Home`?n=0:t.key===`End`&&(n=e.length-1),n!==null&&(t.preventDefault(),p(n))},children:(0,$.jsx)(`span`,{"aria-hidden":`true`,className:V(`block h-0.5 rounded-full transition-[width,background-color,opacity] duration-150 motion-reduce:transition-none`,s?`w-6 bg-ink xl:w-7`:u===1?`w-3.5 bg-ink-subtle opacity-80 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`:`w-2.5 bg-line-strong opacity-70 group-hover:w-5 group-hover:bg-ink-muted group-hover:opacity-100 group-focus-visible:w-5`)})})},t.id)})}),_&&(0,$.jsx)(`div`,{id:v,role:`tooltip`,className:V(`pointer-events-none absolute inset-s-full ms-2 w-72 -translate-y-1/2`,`overflow-hidden rounded-xl border border-line bg-surface-overlay/95 shadow-overlay backdrop-blur-xl`,`animate-fade-in motion-reduce:animate-none`),style:{top:`clamp(3.5rem, ${u}px, calc(100% - 3.5rem))`},children:(0,$.jsxs)(`div`,{className:`px-3.5 py-3`,children:[(0,$.jsx)(`p`,{dir:`auto`,className:`truncate text-[13px] font-semibold leading-5 text-ink`,children:yn(_.prompt)}),_.response&&(0,$.jsx)(`p`,{dir:`auto`,className:`mt-1 line-clamp-3 text-xs leading-5 text-ink-muted`,children:yn(_.response)})]})})]})}),xn=Q.memo(({messages:e,isStreaming:t=!1,streamingMessage:n,streamingThinking:r,streamingMessageId:i,isLastAssistantMessage:a=!1,onRegenerate:o,onSelectBranch:c,className:l})=>{let{t:u}=s();if(e.length===1){let s=e[0],c=t&&i===s.id,u=c?{...s,content:n??s.content,thinking:r||s.thinking}:s;return(0,$.jsx)(gn,{message:u,isStreaming:c,isLastAssistantMessage:a,onRegenerate:o,className:l})}return(0,$.jsxs)(`div`,{className:V(`relative py-2`,l),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 pb-3 text-[10px] font-medium uppercase tracking-[0.12em] text-ink-muted`,children:[(0,$.jsx)(_e,{className:`h-3 w-3`}),(0,$.jsx)(`span`,{children:u(`chat.branch.variants`,{count:e.length})})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:e.map((e,s)=>{let l=e.isActive!==!1,d=t&&i===e.id,f=d?{...e,content:n??e.content,thinking:r||e.thinking}:e;return(0,$.jsxs)(`div`,{className:V(`relative overflow-hidden rounded-2xl border bg-white/45 transition-colors duration-150 dark:bg-dark-200/35`,l||d?`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&&!d&&`cursor-pointer`),role:!l&&!d?`button`:void 0,tabIndex:!l&&!d?0:void 0,"aria-label":!l&&!d?u(`chat.branch.selectVariant`,{number:s+1}):void 0,"aria-current":l||d?`true`:void 0,onClick:()=>!l&&!d&&c?.(e.id),onKeyDown:t=>{t.target!==t.currentTarget||l||d||t.key!==`Enter`&&t.key!==` `||(t.preventDefault(),c?.(e.id))},children:[(0,$.jsxs)(`div`,{className:V(`flex items-center justify-between border-b px-3 py-2 text-[10px] font-medium uppercase tracking-[0.12em]`,l||d?`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/5 text-ink-muted dark:border-white/5`),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`font-medium`,children:s+1}),d&&(0,$.jsx)(`span`,{className:`text-[10px] opacity-70 animate-pulse`,children:u(`chat.branch.generating`)})]}),l&&!d&&(0,$.jsx)(ve,{className:`h-3 w-3`}),!l&&!d&&(0,$.jsx)(`span`,{className:`text-[10px]`,children:u(`chat.branch.select`)})]}),(0,$.jsx)(`div`,{className:V(!l&&!d&&`opacity-75`),children:(0,$.jsx)(gn,{message:f,isStreaming:d,isLastAssistantMessage:a&&(l||d),onRegenerate:l&&!t?o:void 0,className:`px-3 pb-3 text-sm!`})})]},e.id)})})]})});xn.displayName=`MessageBranch`;var Sn={web_search:d,web_fetch:ge,exec:ee,browser:ge,Read:z,Write:z,Edit:z,image:m,memory_search:F,memory_get:F,working:he,thinking:he,default:he},Cn={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`},wn=({tools:e,className:t})=>{if(e.length===0)return null;let n=e.filter(e=>e.phase!==`result`&&e.phase!==`done`);return n.length===0?null:(0,$.jsx)(`div`,{className:V(`flex flex-col gap-1 py-2 px-1`,t),children:n.map(e=>{let t=Sn[e.name]||Sn.default,n=Cn[e.name]||`Using ${e.name}`,r=e.phase===`result`;return(0,$.jsxs)(`div`,{className:V(`flex items-center gap-2 text-sm transition-all duration-300`,r?`text-green-600 dark:text-green-400 opacity-60`:`text-gray-500 dark:text-gray-400`),children:[(0,$.jsx)(`div`,{className:V(`flex items-center justify-center w-5 h-5`,!r&&`animate-spin-slow`),children:(0,$.jsx)(t,{className:`h-3.5 w-3.5`})}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:r?`✓ ${n}`:`${n}…`}),!r&&(0,$.jsxs)(`div`,{className:`flex gap-0.5`,children:[(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`0ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`150ms`}}),(0,$.jsx)(`div`,{className:`w-1 h-1 bg-current rounded-full animate-bounce`,style:{animationDelay:`300ms`}})]})]},e.toolCallId)})})};Y(`components:chat-messages`);var Tn=e=>e.messages.find(e=>e.isActive===!0)||e.messages.find(e=>e.isActive!==!1)||e.messages[0],En=e=>e.messages.every(e=>e.isActive===!1),Dn=e=>e.role===`system`&&!st(e.content),On=()=>typeof window<`u`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches?`auto`:`smooth`,kn=e=>Math.min(120,e*.28),An=({messages:e,streamingMessage:t,streamingThinking:n,streamingMessageId:r,isStreaming:i=!1,toolActivities:a=[],activeToolCalls:o,pendingToolApproval:c,onDecideToolApproval:l,className:u,onRegenerate:d,onSelectBranch:f,onEditResend:p,onFork:m,followUpSuggestions:h,onFollowUpSelect:g})=>{let{t:y}=s(),b=(0,Q.useRef)(null),x=(0,Q.useRef)(void 0),S=(0,Q.useRef)(null),C=(0,Q.useRef)(null),[w]=(0,Q.useState)(()=>new Map),T=(0,Q.useRef)(null),E=(0,Q.useRef)(0),ee=(0,Q.useRef)(!1),D=(0,Q.useRef)(!1),[O,k]=(0,Q.useState)(!1),A=(0,Q.useMemo)(()=>{let t=[],n=new Set,r=[...e].sort((e,t)=>Dn(e)&&!Dn(t)?-1:Dn(t)&&!Dn(e)?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 Dn(n)&&!Dn(r)?-1:Dn(r)&&!Dn(n)?1:n.timestamp-r.timestamp})},[e]),te=(0,Q.useMemo)(()=>{let e=[];for(let t=0;t<A.length;t++){let n=A[t],r=Tn(n);if(r.role!==`user`)continue;let i;for(let e=t+1;e<A.length;e++){let t=Tn(A[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},[A]),ne=te.map(e=>e.id).join(``),j=(0,Q.useMemo)(()=>ne?ne.split(``):[],[ne]),re=(0,Q.useMemo)(()=>new Set(j),[j]),ie=(0,Q.useMemo)(()=>{let e=new Map;for(let t of j)e.set(t,e=>{e?w.set(t,e):w.delete(t)});return e},[w,j]),[M,ae]=(0,Q.useState)(null),oe=(0,Q.useCallback)(()=>{let e=S.current;if(!e||j.length===0){ae(null);return}let t=e.scrollHeight-e.scrollTop-e.clientHeight,n=Math.min(E.current,j.length-1);if(t<=2)n=j.length-1;else{let t=e.scrollTop+kn(e.clientHeight);for(;n<j.length-1;){let e=w.get(j[n+1]);if(!e||e.offsetTop>t)break;n++}for(;n>0;){let e=w.get(j[n]);if(!e||e.offsetTop<=t)break;n--}}E.current=n;let r=j[n];ae(e=>e===r?e:r)},[w,j]),N=(0,Q.useCallback)(()=>{T.current===null&&(T.current=window.requestAnimationFrame(()=>{T.current=null,oe()}))},[oe]),P=(0,Q.useCallback)(()=>{let t=S.current;if(x.current&&clearTimeout(x.current),ee.current=!1,x.current=void 0,!t)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<100;D.current=!n,k(!n&&e.length>0),N()},[e.length,N]),F=(0,Q.useCallback)(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(P,180)},[P]),I=(0,Q.useCallback)((e=!1)=>{(!D.current||e)&&b.current?.scrollIntoView({behavior:On()})},[]),se=(0,Q.useCallback)(()=>{let t=S.current;if(!t)return;let{scrollTop:n,scrollHeight:r,clientHeight:i}=t,a=r-n-i,o=a<100;ee.current?(D.current=!0,k(!o&&e.length>0),N(),F()):(D.current=!o,k(!o&&e.length>0),a<=2&&j.length>0?(E.current=j.length-1,ae(j[j.length-1])):N())},[j,e.length,F,N]),ce=(0,Q.useCallback)(e=>{let t=S.current,n=w.get(e);if(!t||!n)return;let r=On();ee.current=!0,D.current=!0,t.scrollTo({top:Math.max(0,n.offsetTop-kn(t.clientHeight)),behavior:r}),N(),r===`auto`?P():F()},[P,w,F,N]),le=(0,Q.useRef)(e.length);if((0,Q.useEffect)(()=>{e.length>le.current&&!D.current&&I(),le.current=e.length},[e.length,I]),(0,Q.useEffect)(()=>{i&&(t||n)&&!D.current&&requestAnimationFrame(()=>{let e=S.current;e&&(e.scrollTop=e.scrollHeight)})},[i,t,n]),(0,Q.useEffect)(()=>{N();let e=C.current,t=S.current,n=typeof ResizeObserver>`u`?null:new ResizeObserver(N);return e&&n?.observe(e),t&&n?.observe(t),window.addEventListener(`resize`,N),()=>{n?.disconnect(),window.removeEventListener(`resize`,N)}},[ne,N]),(0,Q.useEffect)(()=>()=>{T.current!==null&&(window.cancelAnimationFrame(T.current),T.current=null)},[]),(0,Q.useEffect)(()=>()=>{x.current&&clearTimeout(x.current)},[]),e.length===0&&!i)return(0,$.jsx)(`div`,{className:V(`flex-1 flex items-center justify-center p-6 sm:p-10`,u),children:(0,$.jsxs)(`div`,{className:`max-w-sm text-center text-ink-muted`,children:[(0,$.jsx)(`div`,{className:`mx-auto mb-5 flex h-11 w-11 items-center justify-center rounded-2xl border border-black/6 bg-surface/70 text-gray-500 shadow-xs dark:border-white/[0.07] dark:bg-dark-200/70 dark:text-dark-600`,children:(0,$.jsx)(_,{className:`h-4 w-4`})}),(0,$.jsx)(`h3`,{className:`mb-2 text-lg font-medium tracking-[-0.02em] text-gray-900 dark:text-dark-900 sm:text-xl`,children:y(`chatMessage.startConversation`)}),(0,$.jsx)(`p`,{className:`px-4 text-sm leading-relaxed`,children:y(`chatMessage.startConversationDescription`)})]})});let ue=-1;for(let e=A.length-1;e>=0;e--)if(A[e].messages.some(e=>e.role===`assistant`)){ue=e;break}return(0,$.jsxs)(`div`,{className:V(`relative min-h-0 flex-1`,u),style:{WebkitAppRegion:`no-drag`},children:[(0,$.jsx)(`div`,{ref:S,"data-testid":`chat-scroll-viewport`,"aria-busy":i,"data-scroll-fade-top":`40`,"data-scroll-fade-bottom":`72`,onScroll:se,className:V(`h-full overflow-y-auto scrollbar-thin scrollbar-thumb-gray-300 dark:scrollbar-thumb-gray-600`,`scrollbar-track-transparent hover:scrollbar-thumb-gray-400 dark:hover:scrollbar-thumb-gray-500`,`overscroll-behavior-y-contain`,`[-webkit-overflow-scrolling:touch]`),style:{WebkitOverflowScrolling:`touch`,overscrollBehaviorY:`contain`},children:(0,$.jsxs)(`div`,{ref:C,"data-testid":`chat-messages-column`,className:`mx-auto w-full min-w-0 max-w-3xl px-4 sm:px-6 md:px-8 wide:max-w-none wide:md:px-12`,children:[A.map((e,a)=>{let o=a===ue,s=re.has(e.id),c=i&&e.messages.some(e=>e.id===r),l;if(En(e))l=(0,$.jsx)(`div`,{className:`opacity-55`,children:(0,$.jsx)(gn,{message:Tn(e),isStreaming:!1,isLastAssistantMessage:!1,className:a===0?`mt-3 sm:mt-4`:``})});else if(e.messages.length===1){let s=e.messages[0],c=i&&s.id===r,u=c?{...s,content:t??s.content,thinking:n||s.thinking}:s;l=(0,$.jsx)(gn,{message:u,isStreaming:c,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onEditResend:i?void 0:p,onFork:i?void 0:m,className:a===0?`mt-3 sm:mt-4`:``})}else l=(0,$.jsx)(xn,{messages:e.messages,isStreaming:c,streamingMessage:c?t:void 0,streamingThinking:c?n:void 0,streamingMessageId:c&&r||void 0,isLastAssistantMessage:o,onRegenerate:o?d:void 0,onSelectBranch:f,className:a===0?`mt-3 sm:mt-4`:``});return(0,$.jsx)(`div`,{className:`[content-visibility:auto] [contain-intrinsic-size:auto_160px]`,ref:ie.get(e.id),"data-testid":s?`conversation-turn-anchor`:void 0,"data-history-id":s?e.id:void 0,children:l},e.id)}),i&&(o?.length??0)>0&&(0,$.jsx)(Ut,{calls:o??[],className:`pb-2`}),c&&l&&(0,$.jsx)(Wt,{approval:c,onDecide:l,className:`mb-2`}),i&&a.length>0&&(0,$.jsx)(wn,{tools:a,className:`px-0`}),!i&&h&&h.length>0&&g&&(0,$.jsx)(`div`,{role:`group`,"aria-label":y(`chat.followUp`),"data-testid":`follow-up-suggestions`,className:`mt-1 flex flex-wrap gap-1.5 pb-2 ps-[2.625rem] sm:ps-11 wide:max-w-[calc(90ch+2.75rem)]`,children:h.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>g(e),dir:`auto`,className:`flex max-w-full items-start gap-1.5 rounded-2xl border border-line px-3 py-1.5 text-start text-[13px] leading-snug text-ink-muted transition-colors hover:border-line-strong hover:bg-interactive-hover hover:text-ink focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-primary-500/40`,children:[(0,$.jsx)(v,{"aria-hidden":`true`,className:`mt-0.5 h-3.5 w-3.5 shrink-0 text-ink-subtle rtl:-scale-x-100`}),(0,$.jsx)(`span`,{className:`min-w-0`,children:e})]},e))}),(0,$.jsx)(`div`,{ref:b,className:`h-4 sm:h-6`})]})}),(0,$.jsx)(bn,{items:te,activeId:M,onSelect:ce}),O&&(0,$.jsxs)(`button`,{type:`button`,"data-testid":`chat-new-messages`,onClick:()=>{ee.current=!1,x.current&&=(clearTimeout(x.current),void 0),D.current=!1,b.current?.scrollIntoView({behavior:On()}),k(!1)},className:V(`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/8`,`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:y(`chatMessage.scrollToBottom`),children:[(0,$.jsx)(we,{className:`h-4 w-4`}),(0,$.jsx)(`span`,{className:`text-xs font-medium`,children:y(`chatMessage.newMessages`)})]})]})};function jn(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 Mn=Q.forwardRef(({value:e,onChange:t,className:n,placeholder:r,disabled:i,onKeyDown:a,dir:o=`auto`,...s},c)=>{let{hasCodeBlocks:l,isInCodeBlock:u,language:d}=(0,Q.useMemo)(()=>jn(e),[e]);return(0,$.jsxs)(`div`,{className:`relative w-full`,children:[(0,$.jsx)(`textarea`,{ref:c,value:e,onChange:t,onKeyDown:a,placeholder:r,disabled:i,dir:o,className:V(`w-full resize-none transition-all duration-200`,u&&[`font-mono text-[13px]`,`bg-gray-50 dark:bg-dark-100/50`,`rounded-lg`],n),...s}),l&&(0,$.jsx)(`div`,{className:`absolute inset-e-0 top-0 pointer-events-none flex items-center gap-1`,children:(0,$.jsxs)(`div`,{className:V(`flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium`,`bg-gray-100 dark:bg-dark-200`,`text-gray-500 dark:text-gray-400`,`border border-gray-200/50 dark:border-dark-300/50`,u&&`animate-pulse`),children:[(0,$.jsx)(Ee,{className:`h-3 w-3`}),d&&(0,$.jsx)(`span`,{children:d}),!d&&u&&(0,$.jsx)(`span`,{children:`code`})]})})]})});Mn.displayName=`CodeAwareTextarea`;var Nn=Y(`components:media-upload`),Pn=({images:e,onImagesChange:t,maxImages:n=5,sessionId:r,onDocumentUploaded:i,disabled:a=!1,className:o})=>{let{t:c}=s(),l=(0,Q.useRef)(null),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)([]),g=async r=>{if(!r||a)return;let i=Array.from(r),o=[];for(let t of i)if(t.type.startsWith(`image/`)){let r=await _(t,n-e.length-o.length);r&&o.push(r)}else t.type.includes(`pdf`)||t.type.includes(`text`)?await v(t):I.error(c(`chat.mediaUpload.unsupportedFileType`,{name:t.name}));o.length>0&&t([...e,...o])},_=(e,t)=>t<=0?(I.error(c(`chat.mediaUpload.maxImagesAllowed`,{count:n})),Promise.resolve(null)):e.size>10485760?(I.error(c(`chat.mediaUpload.imageTooLarge`,{name:e.name})),Promise.resolve(null)):new Promise(t=>{let n=new FileReader;n.onload=()=>t(typeof n.result==`string`?n.result:null),n.onerror=()=>{I.error(c(`chat.mediaUpload.readFailed`,{name:e.name})),t(null)},n.readAsDataURL(e)}),v=async e=>{if(e.size>10485760)I.error(c(`documents.fileSizeTooLarge`));else{p(!0);try{let t=await Re.uploadDocument(e,r);if(t.success&&t.data){let n=t.data;h(e=>[...e,n]),i?.(n),I.success(c(`documents.uploadSuccessWithName`,{name:e.name}))}else I.error(t.error||c(`documents.uploadFailed`))}catch(e){Nn.error(`Document upload error:`,e),I.error(c(`documents.uploadFailed`))}finally{p(!1)}}},y=e=>{e.preventDefault(),a||d(!0)},b=e=>{e.preventDefault(),d(!1)},x=e=>{e.preventDefault(),d(!1),a||g(e.dataTransfer.files)},S=n=>{t(e.filter((e,t)=>t!==n))},C=async e=>{try{let t=await Re.deleteDocument(e);t.success?(h(t=>t.filter(t=>t.id!==e)),I.success(c(`documents.removeSuccess`))):I.error(t.error||c(`documents.removeFailed`))}catch(e){Nn.error(`Error removing document:`,e),I.error(c(`documents.removeFailed`))}},w=e=>{if(e===0)return`0 B`;let t=1024,n=[`B`,`KB`,`MB`,`GB`],r=Math.floor(Math.log(e)/Math.log(t));return parseFloat((e/t**r).toFixed(1))+` `+n[r]},T=e.length>0||m.length>0;return(0,$.jsxs)(`div`,{className:V(`space-y-3`,o),children:[(0,$.jsxs)(`div`,{className:V(`border-2 border-dashed rounded-xl p-6 transition-all duration-200 cursor-pointer`,`border-gray-300 dark:border-gray-600`,`hover:border-primary-400 dark:hover:border-primary-500`,u&&`border-primary-500 dark:border-primary-400 bg-primary-50/50 dark:bg-primary-900/10`,a&&`opacity-50 cursor-not-allowed`),onDragOver:y,onDragLeave:b,onDrop:x,role:`button`,tabIndex:a?-1:0,"aria-disabled":a||void 0,"aria-label":`${c(`chat.mediaUpload.dropImagesHere`)} ${c(`chat.mediaUpload.browse`)}`,onClick:()=>!a&&l.current?.click(),onKeyDown:e=>{e.target===e.currentTarget&&(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),a||l.current?.click())},children:[(0,$.jsx)(`input`,{ref:l,type:`file`,multiple:!0,accept:`image/*,.pdf,.txt`,onChange:e=>{g(e.target.files),e.target.value=``},className:`hidden`,disabled:a}),(0,$.jsxs)(`div`,{className:`flex flex-col items-center text-center`,children:[f?(0,$.jsx)(E,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2 animate-spin`,role:`status`,"aria-label":c(`chat.mediaUpload.uploading`)}):(0,$.jsx)(fe,{className:`h-8 w-8 text-gray-400 dark:text-gray-500 mb-2`}),(0,$.jsxs)(`p`,{className:`text-sm text-gray-700 dark:text-gray-300`,children:[c(`chat.mediaUpload.dropImagesHere`),` `,(0,$.jsx)(`span`,{className:`text-primary-600 dark:text-primary-400 font-medium`,children:c(`chat.mediaUpload.browse`)})]}),(0,$.jsx)(`p`,{className:`text-xs text-ink-muted mt-1`,children:c(`chat.mediaUpload.supportedFormats`)})]})]}),T&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.map((e,t)=>(0,$.jsxs)(`div`,{className:`relative group w-16 h-16 rounded-lg overflow-hidden bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[(0,$.jsx)(`img`,{src:e,alt:c(`chat.mediaUpload.uploadAlt`,{number:t+1}),className:`w-full h-full object-cover`}),(0,$.jsx)(`button`,{type:`button`,onClick:e=>{e.stopPropagation(),S(t)},"aria-label":c(`chat.mediaUpload.removeImage`,{number:t+1}),className:`absolute top-0.5 inset-e-0.5 p-0.5 rounded-full bg-black/60 hover:bg-black/80 text-white opacity-0 group-hover:opacity-100 focus-visible:opacity-100 [@media(hover:none)]:opacity-100 transition-opacity`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},`img-${t}`)),m.map(e=>(0,$.jsxs)(`div`,{className:`relative group flex items-center gap-2 px-3 py-2 rounded-lg bg-gray-100 dark:bg-gray-800 border border-gray-200 dark:border-gray-700`,children:[e.fileType===`pdf`?(0,$.jsx)(z,{className:`w-4 h-4 text-red-500 shrink-0`}):(0,$.jsx)(te,{className:`w-4 h-4 text-blue-500 shrink-0`}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-xs font-medium text-gray-900 dark:text-gray-100 truncate max-w-[100px]`,children:e.filename}),(0,$.jsx)(`p`,{className:`text-[10px] text-ink-muted`,children:w(e.size)})]}),(0,$.jsx)(`button`,{type:`button`,onClick:t=>{t.stopPropagation(),C(e.id)},"aria-label":c(`chat.mediaUpload.removeDocument`,{name:e.filename}),className:`p-0.5 rounded-full hover:bg-gray-200 dark:hover:bg-gray-700 text-gray-500 hover:text-red-500 transition-colors`,children:(0,$.jsx)(L,{className:`h-3 w-3`})})]},e.id))]})]})},Fn=Y(`components:document-indicator`),In=({sessionId:e,className:t=``})=>{let{t:n}=s(),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(!1),[c,l]=(0,Q.useState)(null),u=(0,Q.useRef)(null),d=(0,Q.useCallback)(async()=>{try{let t=await Re.getDocuments();t.success&&t.data&&i(t.data.filter(t=>e&&t.sessionId===e||!t.sessionId&&!t.collectionId))}catch(e){Fn.error(`Failed to load documents:`,e)}},[e]);if((0,Q.useEffect)(()=>{let e=setTimeout(()=>void d(),0),t=()=>void d();return window.addEventListener(`libre:documents-updated`,t),()=>{clearTimeout(e),window.removeEventListener(`libre:documents-updated`,t)}},[d]),(0,Q.useEffect)(()=>{if(!a)return;let e=e=>{u.current?.contains(e.target)||(o(!1),l(null))};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[a]),r.length===0)return null;let f=async e=>{l(null);try{let t=await Re.deleteDocument(e);if(!t.success)throw Error(t.error);window.dispatchEvent(new Event(`libre:documents-updated`))}catch(e){Fn.error(`Failed to delete document:`,e),b.error(n(`settings.documents.library.deleteFailed`))}},p=r.reduce((e,t)=>e+t.size,0);return(0,$.jsxs)(`div`,{ref:u,className:`relative inline-block ${t}`,children:[a&&(0,$.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,$.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,$.jsx)(`div`,{className:`max-h-56 overflow-y-auto`,children:r.map(e=>(0,$.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,$.jsxs)($.Fragment,{children:[(0,$.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,$.jsx)(`button`,{onClick:()=>void f(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,$.jsx)(`button`,{onClick:()=>l(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,$.jsxs)($.Fragment,{children:[(0,$.jsx)(z,{className:`h-3.5 w-3.5 shrink-0 text-gray-400 dark:text-dark-500`}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`p`,{className:`truncate text-xs text-gray-900 dark:text-dark-900`,children:e.filename}),(0,$.jsxs)(`p`,{className:`text-[10px] text-gray-400 dark:text-dark-500`,children:[B(e.size),` · `,e.sessionId?n(`settings.documents.library.chatScope`):n(`settings.documents.library.everyChatScope`)]})]}),(0,$.jsx)(`button`,{onClick:()=>l(e.id),className:`shrink-0 text-gray-400 transition-colors hover:text-red-500 dark:text-dark-500`,title:n(`common.delete`),children:(0,$.jsx)(L,{className:`h-3.5 w-3.5`})})]})},e.id))})]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{o(e=>!e),l(null)},className:`
|
|
2
2
|
inline-flex items-center space-x-1 px-2 py-1
|
|
3
3
|
bg-blue-50 dark:bg-blue-900/20
|
|
4
4
|
border border-blue-200 dark:border-blue-800
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{Bn as r,Kt as i,Mn as a,Or as o,Q as s,Qn as c,U as l,et as ee,nt as te,tr as u}from"./ui-vendor-BanHlKMb.js";import{t as d}from"./useTranslation-Bu0AxynE.js";import"./ui-CKcr9ReZ.js";import{u as f,y as p}from"./api-B8EjExUU.js";import{t as m}from"./authStore-BOFcWqii.js";import{t as h}from"./Button-DeV-GhQr.js";import{t as g}from"./chatStore-C3c3r8iB.js";import{t as _}from"./utils-DhBboyBg.js";import{t as v}from"./logger-DAQsBb8I.js";var y=e(t(),1),b=n(),x=v(`components:connect-models`),S=[{id:`llama-cpp`,name:`llama.cpp`,baseUrl:`http://localhost:8080/v1`},{id:`vllm`,name:`vLLM`,baseUrl:`http://localhost:8000/v1`},{id:`llama-swap`,name:`llama-swap`,baseUrl:`http://localhost:8080/v1`},{id:`lm-studio`,name:`LM Studio`,baseUrl:`http://localhost:1234/v1`},{id:`mlx-lm`,name:`mlx-lm`,baseUrl:`http://localhost:8080/v1`}],C=[{id:`openai`,name:`OpenAI`},{id:`anthropic`,name:`Anthropic`},{id:`groq`,name:`Groq`},{id:`openrouter`,name:`OpenRouter`},{id:`gemini`,name:`Google Gemini`},{id:`mistral`,name:`Mistral`},{id:`deepseek`,name:`DeepSeek`},{id:`meta`,name:`Meta`},{id:`modal`,name:`Modal`},{id:`baseten`,name:`Baseten`},{id:`bedrock`,name:`Amazon Bedrock`}],w=({variant:e=`setup`,onDone:t})=>{let{t:n}=d(),{user:v,systemInfo:w}=m(),T=g(e=>e.loadModels),E=v?.role===`admin`||w?.requiresAuth===!1,[D,O]=(0,y.useState)(()=>w?.ollamaEnabled===!1?`disabled`:`checking`),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(S[0]),[N,P]=(0,y.useState)(S[0].baseUrl),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)(!1),[U,W]=(0,y.useState)(null),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=(0,y.useCallback)(async()=>{try{let e=await p.checkHealth();e.success&&e.data?.status===`disabled`?O(`disabled`):e.success&&e.data?.status===`healthy`?O(`healthy`):O(`offline`)}catch{O(`offline`)}},[]);(0,y.useEffect)(()=>{if(w?.ollamaEnabled===!1)return;let e=window.setTimeout(()=>{Y()},0);return()=>window.clearTimeout(e)},[Y,w?.ollamaEnabled]);let X=async e=>{try{(await p.updateSettings({enabled:e})).success?(o.success(n(e?`connectModels.ollama.enabledToast`:`connectModels.ollama.disabledToast`)),e?(O(`checking`),Y()):O(`disabled`)):o.error(n(`connectModels.ollama.settingsFailed`))}catch(e){x.error(`Failed to update Ollama settings:`,e),o.error(n(`connectModels.ollama.settingsFailed`))}},Z=async()=>{R(!0),B(null);try{let e=await f.probeEndpoint(N,`openai`);e.success&&e.data?.reachable?(B(e.data.models),o.success(n(`connectModels.local.reachable`,{count:e.data.models.length}))):(B([]),o.error(e.message||n(`connectModels.local.unreachable`)))}catch(e){x.error(`Endpoint probe failed:`,e),B([]),o.error(n(`connectModels.local.unreachable`))}finally{R(!1)}},ne=async()=>{H(!0);try{let e=N.replace(/\/+$/,``),r=e.endsWith(`/v1`)?e:`${e}/v1`,i=F.trim().length>0,a=`${j.id.toUpperCase().replace(/-/g,`_`)}_API_KEY`,s={id:j.id,name:j.name,type:`completion`,endpoint:`${r}/chat/completions`,api_mode:`chat_completions`,base_url:r,auth:i?{header:`Authorization`,prefix:`Bearer `,key_env:a}:{header:``,prefix:``,key_env:``},model_map:(z??[]).slice(0,50)};if(!(await f.installPlugin(s)).success&&!(await f.updatePlugin(j.id,s)).success){o.error(n(`connectModels.local.enableFailed`));return}i&&await f.setApiKey(j.id,F.trim()),await f.activatePlugin(j.id),await T({quiet:!0}),o.success(n(`connectModels.local.enabled`,{name:j.name})),t?.()}catch(e){x.error(`Failed to enable local provider:`,e),o.error(n(`connectModels.local.enableFailed`))}finally{H(!1)}},re=async()=>{if(U&&G.trim()){J(!0);try{if(!(await f.setApiKey(U.id,G.trim())).success){o.error(n(`connectModels.cloud.saveFailed`));return}await f.activatePlugin(U.id),await T({quiet:!0}),o.success(n(`connectModels.cloud.connected`,{name:U.name})),K(``),t?.()}catch(e){x.error(`Failed to connect cloud provider:`,e),o.error(n(`connectModels.cloud.saveFailed`))}finally{J(!1)}}},Q=`rounded-2xl border border-gray-200/80 bg-white/80 p-4 dark:border-white/10 dark:bg-white/4`,$=`w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800 dark:placeholder-dark-500`,ie={checking:`bg-gray-400 animate-pulse`,healthy:`bg-green-500`,offline:`bg-red-500`,disabled:`bg-gray-400`}[D];return(0,b.jsxs)(`div`,{className:_(`flex w-full flex-col gap-3`,`max-w-lg`),children:[(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(a,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:`Ollama`}),(0,b.jsx)(`span`,{className:_(`h-2 w-2 rounded-full`,ie)})]}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.status.${D}`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[D!==`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>{O(`checking`),Y()},title:n(`connectModels.ollama.recheck`),"aria-label":n(`connectModels.ollama.recheck`),children:(0,b.jsx)(s,{className:_(`h-4 w-4`,D===`checking`&&`animate-spin`)})}),E&&D===`offline`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!1),title:n(`connectModels.ollama.disable`),"aria-label":n(`connectModels.ollama.disable`),children:(0,b.jsx)(ee,{className:`h-4 w-4`})}),E&&D===`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!0),children:n(`connectModels.ollama.enable`)})]})]}),D===`offline`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.offlineHint`)}),D===`healthy`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-success-800 dark:text-success-400`,children:n(`connectModels.ollama.healthyHint`)})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`local`,onClick:()=>A(k===`local`?null:`local`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(l,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.local.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.local.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`local`&&`rotate-90 rtl:rotate-90`)})]}),k===`local`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:S.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>{M(e),P(e.baseUrl),B(null)},"aria-pressed":j.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,j.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),(0,b.jsx)(`input`,{className:$,type:`url`,"aria-label":n(`connectModels.local.urlLabel`),autoCapitalize:`none`,value:N,onChange:e=>{P(e.target.value),B(null)},placeholder:`http://localhost:8080/v1`,spellCheck:!1}),(0,b.jsx)(`input`,{className:$,value:F,onChange:e=>I(e.target.value),placeholder:n(`connectModels.local.keyPlaceholder`),"aria-label":n(`connectModels.local.keyPlaceholder`),type:`password`,autoComplete:`off`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void Z(),disabled:L||!N.trim(),children:[(0,b.jsx)(te,{className:`me-1.5 h-4 w-4`}),n(L?`connectModels.local.testing`:`connectModels.local.test`)]}),(0,b.jsxs)(h,{size:`sm`,onClick:()=>void ne(),disabled:V||!z||z.length===0,children:[(0,b.jsx)(u,{className:`me-1.5 h-4 w-4`}),n(V?`connectModels.local.enabling`:`connectModels.local.enable`)]})]}),z&&z.length>0&&(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[z.slice(0,8).map(e=>(0,b.jsx)(`span`,{className:`rounded-md bg-gray-100 px-2 py-0.5 font-mono text-[10px] text-gray-700 dark:bg-white/6 dark:text-dark-700`,children:e},e)),z.length>8&&(0,b.jsxs)(`span`,{className:`px-1 text-[10px] text-gray-400`,children:[`+`,z.length-8]})]}),z&&z.length===0&&(0,b.jsx)(`p`,{role:`alert`,className:`text-xs text-error-700 dark:text-error-400`,children:n(`connectModels.local.noModels`)})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`cloud`,onClick:()=>A(k===`cloud`?null:`cloud`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(r,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.cloud.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.cloud.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`cloud`&&`rotate-90 rtl:rotate-90`)})]}),k===`cloud`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>W(e),"aria-pressed":U?.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,U?.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),U&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(i,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,b.jsx)(`input`,{className:_($,`ps-9`),value:G,onChange:e=>K(e.target.value),placeholder:n(`connectModels.cloud.keyPlaceholder`,{name:U.name}),"aria-label":n(`connectModels.cloud.keyLabel`,{name:U.name}),type:`password`,autoComplete:`off`})]}),(0,b.jsx)(`div`,{children:(0,b.jsxs)(h,{size:`sm`,onClick:()=>void re(),disabled:q||!G.trim(),children:[(0,b.jsx)(u,{className:`me-1.5 h-4 w-4`}),n(q?`connectModels.cloud.connecting`:`connectModels.cloud.connect`)]})})]})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),e===`setup`&&(0,b.jsx)(`div`,{className:`mt-1 text-center`,children:(0,b.jsx)(`button`,{type:`button`,onClick:()=>t?.(),className:`text-sm text-gray-500 underline-offset-4 hover:underline dark:text-dark-500`,children:n(`connectModels.skip`)})})]})};export{w as t};
|
|
1
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{i as t,t as n}from"./react-vendor-C1iE8mnY.js";import{Bn as r,Kt as i,Mn as a,Or as o,Q as s,Qn as c,U as l,et as ee,nt as te,tr as u}from"./ui-vendor-CmYUVVjB.js";import{t as d}from"./useTranslation-Bu0AxynE.js";import"./ui-D5Ws30mx.js";import{u as f,y as p}from"./api-__EtZkwT.js";import{t as m}from"./authStore-VeRUWwzv.js";import{t as h}from"./Button-DeV-GhQr.js";import{t as g}from"./chatStore-DM7NfNs8.js";import{t as _}from"./utils-DhBboyBg.js";import{t as v}from"./logger-DAQsBb8I.js";var y=e(t(),1),b=n(),x=v(`components:connect-models`),S=[{id:`llama-cpp`,name:`llama.cpp`,baseUrl:`http://localhost:8080/v1`},{id:`vllm`,name:`vLLM`,baseUrl:`http://localhost:8000/v1`},{id:`llama-swap`,name:`llama-swap`,baseUrl:`http://localhost:8080/v1`},{id:`lm-studio`,name:`LM Studio`,baseUrl:`http://localhost:1234/v1`},{id:`mlx-lm`,name:`mlx-lm`,baseUrl:`http://localhost:8080/v1`}],C=[{id:`openai`,name:`OpenAI`},{id:`anthropic`,name:`Anthropic`},{id:`groq`,name:`Groq`},{id:`openrouter`,name:`OpenRouter`},{id:`gemini`,name:`Google Gemini`},{id:`mistral`,name:`Mistral`},{id:`deepseek`,name:`DeepSeek`},{id:`meta`,name:`Meta`},{id:`modal`,name:`Modal`},{id:`baseten`,name:`Baseten`},{id:`bedrock`,name:`Amazon Bedrock`}],w=({variant:e=`setup`,onDone:t})=>{let{t:n}=d(),{user:v,systemInfo:w}=m(),T=g(e=>e.loadModels),E=v?.role===`admin`||w?.requiresAuth===!1,[D,O]=(0,y.useState)(()=>w?.ollamaEnabled===!1?`disabled`:`checking`),[k,A]=(0,y.useState)(null),[j,M]=(0,y.useState)(S[0]),[N,P]=(0,y.useState)(S[0].baseUrl),[F,I]=(0,y.useState)(``),[L,R]=(0,y.useState)(!1),[z,B]=(0,y.useState)(null),[V,H]=(0,y.useState)(!1),[U,W]=(0,y.useState)(null),[G,K]=(0,y.useState)(``),[q,J]=(0,y.useState)(!1),Y=(0,y.useCallback)(async()=>{try{let e=await p.checkHealth();e.success&&e.data?.status===`disabled`?O(`disabled`):e.success&&e.data?.status===`healthy`?O(`healthy`):O(`offline`)}catch{O(`offline`)}},[]);(0,y.useEffect)(()=>{if(w?.ollamaEnabled===!1)return;let e=window.setTimeout(()=>{Y()},0);return()=>window.clearTimeout(e)},[Y,w?.ollamaEnabled]);let X=async e=>{try{(await p.updateSettings({enabled:e})).success?(o.success(n(e?`connectModels.ollama.enabledToast`:`connectModels.ollama.disabledToast`)),e?(O(`checking`),Y()):O(`disabled`)):o.error(n(`connectModels.ollama.settingsFailed`))}catch(e){x.error(`Failed to update Ollama settings:`,e),o.error(n(`connectModels.ollama.settingsFailed`))}},Z=async()=>{R(!0),B(null);try{let e=await f.probeEndpoint(N,`openai`);e.success&&e.data?.reachable?(B(e.data.models),o.success(n(`connectModels.local.reachable`,{count:e.data.models.length}))):(B([]),o.error(e.message||n(`connectModels.local.unreachable`)))}catch(e){x.error(`Endpoint probe failed:`,e),B([]),o.error(n(`connectModels.local.unreachable`))}finally{R(!1)}},ne=async()=>{H(!0);try{let e=N.replace(/\/+$/,``),r=e.endsWith(`/v1`)?e:`${e}/v1`,i=F.trim().length>0,a=`${j.id.toUpperCase().replace(/-/g,`_`)}_API_KEY`,s={id:j.id,name:j.name,type:`completion`,endpoint:`${r}/chat/completions`,api_mode:`chat_completions`,base_url:r,auth:i?{header:`Authorization`,prefix:`Bearer `,key_env:a}:{header:``,prefix:``,key_env:``},model_map:(z??[]).slice(0,50)};if(!(await f.installPlugin(s)).success&&!(await f.updatePlugin(j.id,s)).success){o.error(n(`connectModels.local.enableFailed`));return}i&&await f.setApiKey(j.id,F.trim()),await f.activatePlugin(j.id),await T({quiet:!0}),o.success(n(`connectModels.local.enabled`,{name:j.name})),t?.()}catch(e){x.error(`Failed to enable local provider:`,e),o.error(n(`connectModels.local.enableFailed`))}finally{H(!1)}},re=async()=>{if(U&&G.trim()){J(!0);try{if(!(await f.setApiKey(U.id,G.trim())).success){o.error(n(`connectModels.cloud.saveFailed`));return}await f.activatePlugin(U.id),await T({quiet:!0}),o.success(n(`connectModels.cloud.connected`,{name:U.name})),K(``),t?.()}catch(e){x.error(`Failed to connect cloud provider:`,e),o.error(n(`connectModels.cloud.saveFailed`))}finally{J(!1)}}},Q=`rounded-2xl border border-gray-200/80 bg-white/80 p-4 dark:border-white/10 dark:bg-white/4`,$=`w-full rounded-xl border border-gray-200 bg-white px-3 py-2 text-sm text-gray-900 placeholder-gray-400 focus:border-primary-500 focus:outline-hidden focus:ring-2 focus:ring-primary-500/30 dark:border-white/10 dark:bg-white/[0.035] dark:text-dark-800 dark:placeholder-dark-500`,ie={checking:`bg-gray-400 animate-pulse`,healthy:`bg-green-500`,offline:`bg-red-500`,disabled:`bg-gray-400`}[D];return(0,b.jsxs)(`div`,{className:_(`flex w-full flex-col gap-3`,`max-w-lg`),children:[(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(a,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:`Ollama`}),(0,b.jsx)(`span`,{className:_(`h-2 w-2 rounded-full`,ie)})]}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.status.${D}`)})]}),(0,b.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[D!==`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>{O(`checking`),Y()},title:n(`connectModels.ollama.recheck`),"aria-label":n(`connectModels.ollama.recheck`),children:(0,b.jsx)(s,{className:_(`h-4 w-4`,D===`checking`&&`animate-spin`)})}),E&&D===`offline`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!1),title:n(`connectModels.ollama.disable`),"aria-label":n(`connectModels.ollama.disable`),children:(0,b.jsx)(ee,{className:`h-4 w-4`})}),E&&D===`disabled`&&(0,b.jsx)(h,{variant:`ghost`,size:`sm`,onClick:()=>void X(!0),children:n(`connectModels.ollama.enable`)})]})]}),D===`offline`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-gray-500 dark:text-dark-500`,children:n(`connectModels.ollama.offlineHint`)}),D===`healthy`&&(0,b.jsx)(`p`,{className:`mt-3 text-xs leading-relaxed text-success-800 dark:text-success-400`,children:n(`connectModels.ollama.healthyHint`)})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`local`,onClick:()=>A(k===`local`?null:`local`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(l,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.local.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.local.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`local`&&`rotate-90 rtl:rotate-90`)})]}),k===`local`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:S.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>{M(e),P(e.baseUrl),B(null)},"aria-pressed":j.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,j.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),(0,b.jsx)(`input`,{className:$,type:`url`,"aria-label":n(`connectModels.local.urlLabel`),autoCapitalize:`none`,value:N,onChange:e=>{P(e.target.value),B(null)},placeholder:`http://localhost:8080/v1`,spellCheck:!1}),(0,b.jsx)(`input`,{className:$,value:F,onChange:e=>I(e.target.value),placeholder:n(`connectModels.local.keyPlaceholder`),"aria-label":n(`connectModels.local.keyPlaceholder`),type:`password`,autoComplete:`off`}),(0,b.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,b.jsxs)(h,{variant:`outline`,size:`sm`,onClick:()=>void Z(),disabled:L||!N.trim(),children:[(0,b.jsx)(te,{className:`me-1.5 h-4 w-4`}),n(L?`connectModels.local.testing`:`connectModels.local.test`)]}),(0,b.jsxs)(h,{size:`sm`,onClick:()=>void ne(),disabled:V||!z||z.length===0,children:[(0,b.jsx)(u,{className:`me-1.5 h-4 w-4`}),n(V?`connectModels.local.enabling`:`connectModels.local.enable`)]})]}),z&&z.length>0&&(0,b.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[z.slice(0,8).map(e=>(0,b.jsx)(`span`,{className:`rounded-md bg-gray-100 px-2 py-0.5 font-mono text-[10px] text-gray-700 dark:bg-white/6 dark:text-dark-700`,children:e},e)),z.length>8&&(0,b.jsxs)(`span`,{className:`px-1 text-[10px] text-gray-400`,children:[`+`,z.length-8]})]}),z&&z.length===0&&(0,b.jsx)(`p`,{role:`alert`,className:`text-xs text-error-700 dark:text-error-400`,children:n(`connectModels.local.noModels`)})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),(0,b.jsxs)(`div`,{className:Q,children:[(0,b.jsxs)(`button`,{type:`button`,className:`flex w-full items-center gap-3 text-start`,"aria-expanded":k===`cloud`,onClick:()=>A(k===`cloud`?null:`cloud`),children:[(0,b.jsx)(`div`,{className:`rounded-xl border border-gray-200 bg-gray-50 p-2 dark:border-white/10 dark:bg-white/5`,children:(0,b.jsx)(r,{className:`h-5 w-5 text-gray-700 dark:text-dark-700`})}),(0,b.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,b.jsx)(`span`,{className:`text-sm font-medium text-gray-900 dark:text-dark-900`,children:n(`connectModels.cloud.title`)}),(0,b.jsx)(`p`,{className:`truncate text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.cloud.subtitle`)})]}),(0,b.jsx)(c,{className:_(`h-4 w-4 text-gray-400 transition-transform rtl:rotate-180`,k===`cloud`&&`rotate-90 rtl:rotate-90`)})]}),k===`cloud`&&(0,b.jsx)(`div`,{className:`mt-4 flex flex-col gap-3`,children:E?(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:C.map(e=>(0,b.jsx)(`button`,{type:`button`,onClick:()=>W(e),"aria-pressed":U?.id===e.id,className:_(`rounded-full border px-3 py-1 text-xs transition-colors`,U?.id===e.id?`border-primary-400 bg-primary-500/10 text-primary-600 dark:text-primary-400`:`border-gray-200 text-gray-600 hover:border-gray-300 dark:border-white/10 dark:text-dark-600`),children:e.name},e.id))}),U&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsxs)(`div`,{className:`relative`,children:[(0,b.jsx)(i,{className:`absolute inset-s-3 top-1/2 h-4 w-4 -translate-y-1/2 text-gray-400`}),(0,b.jsx)(`input`,{className:_($,`ps-9`),value:G,onChange:e=>K(e.target.value),placeholder:n(`connectModels.cloud.keyPlaceholder`,{name:U.name}),"aria-label":n(`connectModels.cloud.keyLabel`,{name:U.name}),type:`password`,autoComplete:`off`})]}),(0,b.jsx)(`div`,{children:(0,b.jsxs)(h,{size:`sm`,onClick:()=>void re(),disabled:q||!G.trim(),children:[(0,b.jsx)(u,{className:`me-1.5 h-4 w-4`}),n(q?`connectModels.cloud.connecting`:`connectModels.cloud.connect`)]})})]})]}):(0,b.jsx)(`p`,{className:`text-xs text-gray-500 dark:text-dark-500`,children:n(`connectModels.adminOnly`)})})]}),e===`setup`&&(0,b.jsx)(`div`,{className:`mt-1 text-center`,children:(0,b.jsx)(`button`,{type:`button`,onClick:()=>t?.(),className:`text-sm text-gray-500 underline-offset-4 hover:underline dark:text-dark-500`,children:n(`connectModels.skip`)})})]})};export{w as t};
|