@tyanxie/paimon-darwin-arm64 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/paimon +0 -0
- package/package.json +1 -1
- package/web/assets/index-BVDOOsji.js +6 -0
- package/web/index.html +1 -1
- package/web/assets/index-DHQFQfM2.js +0 -6
package/bin/paimon
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{a as l,j as t,r as Ge,c as rn}from"./framework-CY9iUjoF.js";import{s as Re,x as sn,E as Me,u as Ve,K as z,m as wt,C as pe,h as Nt,l as an,S as on,c as Je,X as Xe,L as de,g as kt,W as ln,p as cn,P as ct,T as dn,F as un,e as De,b as pn,i as St,G as xn,H as fn,r as mn,f as hn,k as gn,a as Ct,M as bn,I as vn,o as yn,A as jn,J as wn,d as Nn,O as kn,t as Sn,j as Cn,q as En,n as Tn,R as ve,D as Rn,B as Mn}from"./vendor-BXh3TPFq.js";import{d as Le,M as In,a as An,b as Ln,r as _n,e as Pn,s as On,c as $n,j as Et}from"./markdown-CbB-lJ6c.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))s(a);new MutationObserver(a=>{for(const o of a)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&s(i)}).observe(document,{childList:!0,subtree:!0});function r(a){const o={};return a.integrity&&(o.integrity=a.integrity),a.referrerPolicy&&(o.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?o.credentials="include":a.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function s(a){if(a.ep)return;a.ep=!0;const o=r(a);fetch(a.href,o)}})();function zn(){l.useEffect(()=>{const e=window.visualViewport;if(!e)return;const n=document.documentElement;function r(){if(!e)return;window.innerHeight-e.height>1?(n.style.setProperty("--app-viewport-height",`${e.height}px`),window.scrollY>0&&window.scrollTo(0,0)):n.style.removeProperty("--app-viewport-height")}return e.addEventListener("resize",r),e.addEventListener("scroll",r),()=>{e.removeEventListener("resize",r),e.removeEventListener("scroll",r),n.style.removeProperty("--app-viewport-height")}},[])}const Ze="paimon:accessToken";function Tt(){return localStorage.getItem(Ze)}function Bn(e){localStorage.setItem(Ze,e)}function Rt(){localStorage.removeItem(Ze)}function Fn(){const[e,n]=l.useState(Tt()),[r,s]=l.useState(!1),a=l.useCallback(i=>{s(!1),n(i)},[]),o=l.useCallback(()=>{Rt(),n(null),s(!0)},[]);return{authToken:e,authError:r,handleLogin:a,handleAuthError:o}}const dt={BROWSER_HEARTBEAT_INTERVAL:3e4,BROWSER_PONG_TIMEOUT:1e4};let V=null;const He=new Set;let se=!1,je=null,Q=null,we=null,le=null,ne=null,ie,_e=!1;const Dn=3e3,Hn=3e3;function qn(e){for(const n of He)try{n(e)}catch(r){console.error("[useWebSocket] listener error:",r)}}function Kn(e){je=setInterval(()=>{e.readyState===WebSocket.OPEN&&(e.send(JSON.stringify({type:"ping"})),Q=setTimeout(()=>{e.close()},dt.BROWSER_PONG_TIMEOUT))},dt.BROWSER_HEARTBEAT_INTERVAL)}function Mt(){je&&(clearInterval(je),je=null),Q&&(clearTimeout(Q),Q=null)}function Pe(){se||(we=setTimeout(It,Hn))}function qe(){le&&(clearTimeout(le),le=null)}function It(){if(se||!ne)return;const r=`${`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/browser`}?token=${encodeURIComponent(ne)}`;_e=!1;const s=new WebSocket(r);V=s,K.setState({connectionState:"connecting"}),le=setTimeout(()=>{le=null,s.readyState===WebSocket.CONNECTING&&s.close()},Dn),s.onopen=()=>{qe(),_e=!0,K.setState({connectionState:"connected"}),s.send(JSON.stringify({type:"list"})),Kn(s)},s.onmessage=a=>{try{const o=JSON.parse(a.data);if(o.type==="pong"){Q&&(clearTimeout(Q),Q=null);return}qn(o)}catch{}},s.onclose=a=>{if(qe(),K.setState({connectionState:"disconnected"}),V=null,Mt(),!se&&!_e){const o={};ne&&(o.Authorization=`Bearer ${ne}`),fetch("/api/instances",{headers:o}).then(i=>{i.status===401?ie==null||ie():Pe()}).catch(()=>{Pe()});return}se||Pe()},s.onerror=()=>{s.close()}}const K=Re((e,n)=>({connectionState:"idle",send:r=>{(V==null?void 0:V.readyState)===WebSocket.OPEN&&V.send(JSON.stringify(r))},subscribe:r=>(He.add(r),()=>{He.delete(r)}),connect:(r,s)=>{n().disconnect(),se=!1,ne=r,ie=s,It()},disconnect:()=>{se=!0,ne=null,ie=void 0,Mt(),qe(),we&&(clearTimeout(we),we=null),V&&(V.close(),V=null),e({connectionState:"idle"})}})),re=Re()(sn((e,n)=>({instances:[],instanceListReady:!1,handleMessage:r=>{switch(r.type){case"instance_list":e({instances:r.payload.instances,instanceListReady:!0});break;case"instance_update":{const{instance:s,action:a}=r.payload;a==="connected"?e(o=>({instances:o.instances.some(c=>c.id===s.id)?o.instances.map(c=>c.id===s.id?s:c):[...o.instances,s]})):a==="disconnected"?e(o=>({instances:o.instances.filter(i=>i.id!==s.id)})):a==="updated"&&e(o=>({instances:o.instances.map(i=>i.id===s.id?s:i)}));break}}}}),{name:"paimon:instances",partialize:e=>({instances:e.instances})}));function Un(e){return n=>e?n.instances.find(r=>r.id===e):void 0}const ae={appearance:"paimon:appearance",background:"paimon:background",notification:"paimon:notification"};function Ke(){const e=localStorage.getItem(ae.appearance);return e==="light"||e==="dark"||e==="system"?e:"system"}function At(){const e=localStorage.getItem(ae.background);return e==="mist"||e==="aurora"||e==="ember"?e:"mist"}function Wn(){return localStorage.getItem(ae.notification)==="true"}function Lt(e){return e==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e}function ke(e,n){const r=Lt(e);return document.documentElement.setAttribute("data-theme",r),document.documentElement.setAttribute("data-bg",n),r}const q=Re(e=>({appearance:Ke(),background:At(),resolvedTheme:Lt(Ke()),notification:Wn(),setAppearance:n=>{localStorage.setItem(ae.appearance,n);const r=ke(n,q.getState().background);e({appearance:n,resolvedTheme:r})},setBackground:n=>{localStorage.setItem(ae.background,n),ke(q.getState().appearance,n),e({background:n})},setNotification:n=>{localStorage.setItem(ae.notification,String(n)),e({notification:n})}})),Yn=window.matchMedia("(prefers-color-scheme: dark)");Yn.addEventListener("change",()=>{const{appearance:e,background:n}=q.getState();if(e==="system"){const r=ke(e,n);q.setState({resolvedTheme:r})}});function Gn(){const e=q(r=>r.appearance),n=q(r=>r.setAppearance);return[e,n]}function _t(){const e=q(r=>r.background),n=q(r=>r.setBackground);return[e,n]}function Vn(){return q(e=>e.resolvedTheme)}function Jn(){const e=q(r=>r.notification),n=q(r=>r.setNotification);return[e,n]}ke(Ke(),At());const Xn="/logos/mist/light/paimon-logo.png";function Pt(e,n){return!e||!n?Xn:`/logos/${e}/${n}/paimon-logo.png`}function Qe(){const[e]=_t(),n=Vn();return Pt(e,n)}function Zn(){const{background:e,resolvedTheme:n}=q.getState();return Pt(e,n)}const Ot="Notification"in window;function Qn(e,n){return(e==="streaming"||e==="compacting")&&n==="idle"}function er(){const e=K(o=>o.subscribe),n=Me(),r=l.useRef(n);l.useEffect(()=>{r.current=n},[n]);const s=l.useRef(q.getState().notification);l.useEffect(()=>q.subscribe(o=>{s.current=o.notification}),[]);const a=l.useRef(new Map);l.useEffect(()=>{const o=re.getState().instances;for(const i of o)a.current.set(i.id,i.status)},[]),l.useEffect(()=>e(o=>{if(o.type==="instance_list"){a.current.clear();for(const i of o.payload.instances)a.current.set(i.id,i.status);return}if(o.type==="instance_update"){const{action:i,instance:c}=o.payload;if(i==="disconnected"){a.current.delete(c.id);return}const d=a.current.get(c.id);a.current.set(c.id,c.status),i==="updated"&&s.current&&Qn(d,c.status)&&tr(c.id,c.cwd,r)}}),[e])}function tr(e,n,r){if(document.hasFocus()||!Ot||Notification.permission!=="granted")return;const s=n.split("/").pop()||n,a=new Notification("Paimon",{body:Ve.t("notification.taskComplete",{name:s}),icon:Zn()});a.onclick=()=>{var o;window.focus(),(o=r.current)==null||o.call(r,`/instance/${e}`),a.close()}}function nr(){const{t:e}=z(),n=K(a=>a.connectionState),r=l.useRef(!1);n==="disconnected"&&(r.current=!0),n==="connected"&&(r.current=!1);const s=r.current&&n!=="connected";return t.jsx("span",{className:`w-2 h-2 rounded-full transition-colors ${s?"bg-red-500":"bg-green-500"}`,title:e(s?"common.offline":"common.online")})}function rr(e,n,r=12){const{innerWidth:s,innerHeight:a}=window;let o=e.x,i=e.y;return o+n.width+r>s&&(o=s-n.width-r),i+n.height+r>a&&(i=a-n.height-r),o=Math.max(r,o),i=Math.max(r,i),{left:o,top:i}}function sr({position:e,onClose:n,children:r}){const s=l.useRef(null),a=l.useRef(n);a.current=n;const o=l.useCallback(()=>a.current(),[]);return l.useEffect(()=>{function i(u){s.current&&!s.current.contains(u.target)&&o()}function c(u){s.current&&!s.current.contains(u.target)&&o()}function d(u){u.key==="Escape"&&o()}return document.addEventListener("mousedown",i),document.addEventListener("contextmenu",c),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("contextmenu",c),document.removeEventListener("keydown",d)}},[o]),l.useEffect(()=>{if(s.current){const i=s.current.getBoundingClientRect(),c=rr(e,{width:i.width,height:i.height});s.current.style.left=`${c.left}px`,s.current.style.top=`${c.top}px`,s.current.style.opacity="1"}},[e]),Ge.createPortal(t.jsx("div",{ref:s,className:"glass-popover z-50 py-1.5 min-w-[160px]",style:{position:"fixed",left:e.x,top:e.y,opacity:0},children:r}),document.body)}function ar({icon:e,label:n,danger:r=!1,disabled:s=!1,onClick:a}){return t.jsxs("button",{onClick:o=>{o.stopPropagation(),s||a()},disabled:s,className:`w-full text-left flex items-center gap-2 px-3 py-1.5 text-[13px] leading-[18px] transition-colors ${s?"opacity-40 cursor-default":r?"text-red-500 hover:bg-[var(--fill-tertiary)]":"text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)]"}`,children:[e&&t.jsx("span",{className:"flex-shrink-0 w-4 h-4 flex items-center justify-center",children:e}),t.jsx("span",{children:n})]})}const or=500;function ut({instances:e,selectedId:n,onSelect:r,onShutdown:s,onNewInstance:a}){const{t:o}=z(),i=Me(),c=Qe(),[d,u]=l.useState(null),f=l.useRef(null),m=l.useRef(!1),g=l.useCallback((k,_)=>{k.preventDefault(),k.stopPropagation(),u({position:{x:k.clientX,y:k.clientY},instanceId:_})},[]),v=l.useCallback((k,_)=>{m.current=!1;const y=k.touches[0],w={x:y.clientX,y:y.clientY};f.current=setTimeout(()=>{var M;m.current=!0,(M=navigator.vibrate)==null||M.call(navigator,10),u({position:w,instanceId:_})},or)},[]),N=l.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]),T=l.useCallback(()=>{f.current&&(clearTimeout(f.current),f.current=null)},[]),R=l.useCallback(()=>u(null),[]),[b,h]=l.useState(null),C=l.useRef(null);l.useEffect(()=>()=>{C.current&&clearTimeout(C.current)},[]);const j=l.useCallback(k=>{navigator.clipboard.writeText(k).then(()=>{h(k),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>h(null),1500)},()=>{})},[]),O=l.useMemo(()=>{const k=new Map;for(const _ of e){const y=k.get(_.edgeId);y?y.push(_):k.set(_.edgeId,[_])}return[...k.entries()].sort((_,y)=>_[0].localeCompare(y[0]))},[e]);return t.jsxs("aside",{className:"glass-panel select-none w-[240px] md:w-[240px] flex-shrink-0 flex flex-col overflow-hidden max-md:w-full max-md:flex-1",children:[t.jsx("div",{className:"px-4 pt-4 pb-2",children:t.jsxs("div",{className:"grid grid-cols-[auto_1fr] grid-rows-[auto_auto] gap-x-2.5 items-center",children:[t.jsx("div",{className:"row-span-2",children:t.jsx("img",{src:c,alt:"Paimon",className:"h-[34px] aspect-square object-contain"})}),t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h1",{className:"text-[16px] leading-[20px] max-md:text-[18px] max-md:leading-[24px] font-semibold text-[var(--label-primary)]",children:"Paimon"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:a,title:o("sidebar.newInstance"),className:"select-none w-6 h-6 flex items-center justify-center rounded-full text-[var(--label-secondary)] hover:text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)] transition-all duration-150",children:t.jsx(wt,{size:16})}),t.jsx(nr,{})]})]}),t.jsxs("div",{className:"text-[12px] leading-[15px] max-md:text-[13px] max-md:leading-[18px] text-[var(--label-tertiary)]",children:[o("sidebar.machine",{count:O.length})," · ",o("sidebar.instance",{count:e.length})]})]})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-1 scrollbar-auto",children:e.length===0?t.jsx("div",{className:"px-3 py-8 text-center text-[var(--label-tertiary)] text-[12px] leading-[16px] max-md:text-[13px] max-md:leading-[18px]",children:o("sidebar.noInstances")}):t.jsx("div",{children:O.map(([k,_],y)=>t.jsxs("div",{children:[t.jsxs("button",{type:"button",onClick:()=>j(k),title:k,className:`flex items-center gap-1 px-2.5 pb-1 text-[11px] leading-[14px] font-semibold text-[var(--label-tertiary)] max-w-full max-md:px-3 rounded-[4px] hover:text-[var(--label-secondary)] transition-colors cursor-pointer ${y===0?"pt-1":"pt-3"}`,children:[t.jsx("span",{className:"truncate",children:k}),t.jsx("span",{className:"shrink-0 opacity-60",children:b===k?t.jsx(pe,{size:10,className:"text-green-500"}):t.jsx(Nt,{size:10})})]}),t.jsx("ul",{className:"space-y-0.5 max-md:space-y-1",children:_.map(w=>{var M;return t.jsx("li",{children:t.jsxs("button",{onClick:()=>{m.current||r(w.id)},onContextMenu:P=>g(P,w.id),onTouchStart:P=>v(P,w.id),onTouchEnd:N,onTouchMove:T,className:`w-full text-left px-2.5 py-1.5 max-md:px-3 max-md:py-2.5 rounded-[8px] transition-all duration-150 ${n===w.id?"bg-[rgba(0,145,255,0.08)] dark:bg-[rgba(0,145,255,0.12)]":"hover:bg-[var(--fill-tertiary)]"}`,children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-1.5 h-1.5 max-md:w-2 max-md:h-2 rounded-full flex-shrink-0 transition-colors ${w.status==="streaming"?"bg-[var(--color-accent)] animate-pulse":w.status==="compacting"?"bg-amber-500 animate-pulse":"bg-green-500"}`,title:w.status==="streaming"?o("sidebar.statusStreaming"):w.status==="compacting"?o("sidebar.statusCompacting"):o("sidebar.statusIdle")}),t.jsx("span",{className:"text-[14px] leading-[18px] max-md:text-[15px] max-md:leading-[21px] text-[var(--label-primary)] truncate",children:w.cwd.split("/").pop()||w.cwd})]}),t.jsx("div",{className:"ml-3.5 text-[11px] leading-[14px] max-md:text-[12px] max-md:leading-[16px] text-[var(--label-secondary)] truncate mt-0.5",children:w.model.name||`${w.model.provider}/${w.model.id}`}),((M=w.contextUsage)==null?void 0:M.percent)!=null&&w.contextUsage.percent>0&&t.jsx("div",{className:"ml-3.5 mt-1.5 h-[3px] rounded-full bg-[var(--fill-quaternary)] overflow-hidden",children:t.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${Math.max(2,Math.min(100,w.contextUsage.percent))}%`,backgroundColor:w.contextUsage.percent>=90?"#ff4245":w.contextUsage.percent>=60?"#ff9230":"#30d158"}})})]})},w.id)})})]},k))})}),d&&t.jsx(sr,{position:d.position,onClose:R,children:t.jsx(ar,{icon:t.jsx(an,{size:14}),label:o("sidebar.shutdown"),danger:!0,onClick:()=>{s(d.instanceId),R()}})}),t.jsx("div",{className:"px-3 py-2 border-t border-[var(--separator)]",children:t.jsxs("button",{onClick:()=>i("/settings"),className:"flex items-center gap-2 w-full px-2.5 py-1.5 max-md:py-2.5 rounded-[8px] text-[var(--label-secondary)] hover:text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)] transition-all duration-150",children:[t.jsx(on,{size:15,className:"max-md:w-4 max-md:h-4"}),t.jsx("span",{className:"text-[13px] leading-[18px] max-md:text-[14px] max-md:leading-[20px]",children:o("sidebar.settings")})]})})]})}function Ue(e){const n=e.id??e.__renderKey;if(!n)throw new Error(`SessionEntry missing stable render key: type=${e.type}`);return n}const et=Object.freeze({text:"",images:[]}),Se=Re((e,n)=>({drafts:new Map,setDraft:(r,s)=>{e(a=>{const o=a.drafts.get(r)??et,i=typeof s=="function"?s(o):s,c=new Map(a.drafts);return i.text||i.images.length>0?c.set(r,i):c.delete(r),{drafts:c}})}})),ue=e=>e!==void 0&&e!=="idle";function lr(){return e=>{var n;((n=e.children[0])==null?void 0:n.type)==="yaml"&&(e.children[0]={type:"code",lang:"__frontmatter__",value:e.children[0].value})}}function ir({yamlText:e}){let n=[];try{const r=Et.load(e);r&&typeof r=="object"&&!Array.isArray(r)&&(n=Object.entries(r).map(([s,a])=>{const o=typeof a=="string"?a:JSON.stringify(a,null,2);return[s,o]}))}catch{n=[["raw",e]]}return n.length===0?null:t.jsx("div",{className:"my-2 rounded-[8px] border border-[var(--separator)] overflow-hidden",children:t.jsx("table",{className:"w-full text-[13px]",children:t.jsx("tbody",{children:n.map(([r,s])=>t.jsxs("tr",{className:"border-b last:border-b-0 border-[var(--separator)]",children:[t.jsx("td",{className:"px-3 py-1.5 bg-[var(--fill-quaternary)] text-[var(--label-secondary)] font-medium whitespace-nowrap align-top w-[1%]",children:r}),t.jsx("td",{className:"px-3 py-1.5 text-[var(--label-primary)] whitespace-pre-wrap break-all",children:s})]},r))})})})}function Ce(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(Ce).join(""):typeof e=="object"&&"props"in e?Ce(e.props.children):""}function pt({language:e,children:n}){const{t:r}=z(),[s,a]=l.useState(!1),o=Ce(n).replace(/\n$/,""),i=l.useCallback(()=>{navigator.clipboard.writeText(o),a(!0),setTimeout(()=>a(!1),2e3)},[o]);return t.jsxs("div",{className:"group/code relative my-2 rounded-[8px] bg-[var(--fill-card)] border border-[var(--separator)] overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-[var(--separator)]",children:[t.jsx("span",{className:"text-[11px] text-[var(--label-tertiary)] font-medium",children:e||"code"}),t.jsxs("button",{onClick:i,className:"flex items-center gap-1 text-[11px] text-[var(--label-tertiary)] hover:text-[var(--label-secondary)] transition-colors",children:[s?t.jsx(pe,{size:12}):t.jsx(Nt,{size:12}),r(s?"entries.copied":"entries.copy")]})]}),t.jsx("pre",{className:"px-3 py-2.5 overflow-x-auto text-[13px] leading-[20px]",children:t.jsx("code",{children:n})})]})}const cr={code({className:e,children:n,...r}){const s=/language-(\w+)/.exec(e||"");if((s==null?void 0:s[1])==="__frontmatter__"){const a=Ce(n).replace(/\n$/,"");return t.jsx(ir,{yamlText:a})}return s?t.jsx(pt,{language:s[1],children:n}):String(n).includes(`
|
|
2
|
+
`)?t.jsx(pt,{language:"",children:n}):t.jsx("code",{className:"px-1.5 py-0.5 rounded-[4px] bg-[var(--fill-secondary)] text-[13px] font-mono break-words",...r,children:n})},pre({children:e}){return t.jsx(t.Fragment,{children:e})},p({children:e}){return t.jsx("p",{className:"text-[14px] leading-[22px] text-[var(--label-primary)] mb-2 last:mb-0",children:e})},h1({children:e}){return t.jsx("h1",{className:"text-[20px] leading-[26px] font-semibold text-[var(--label-primary)] mt-4 mb-2",children:e})},h2({children:e}){return t.jsx("h2",{className:"text-[17px] leading-[23px] font-semibold text-[var(--label-primary)] mt-3 mb-1.5",children:e})},h3({children:e}){return t.jsx("h3",{className:"text-[15px] leading-[21px] font-semibold text-[var(--label-primary)] mt-2 mb-1",children:e})},ul({children:e}){return t.jsx("ul",{className:"text-[14px] leading-[22px] text-[var(--label-primary)] pl-5 mb-2 list-disc space-y-0.5",children:e})},ol({children:e}){return t.jsx("ol",{className:"text-[14px] leading-[22px] text-[var(--label-primary)] pl-5 mb-2 list-decimal space-y-0.5",children:e})},li({children:e}){return t.jsx("li",{className:"text-[14px] leading-[22px]",children:e})},blockquote({children:e}){return t.jsx("blockquote",{className:"pl-3 border-l-2 border-[var(--color-accent)] text-[14px] leading-[22px] text-[var(--label-secondary)] my-2",children:e})},table({children:e}){return t.jsx("div",{className:"overflow-x-auto my-2 rounded-[8px] border border-[var(--separator)]",children:t.jsx("table",{className:"w-full text-[13px]",children:e})})},thead({children:e}){return t.jsx("thead",{className:"bg-[var(--fill-tertiary)] text-[var(--label-secondary)]",children:e})},th({children:e}){return t.jsx("th",{className:"px-3 py-1.5 text-left font-medium border-b border-[var(--separator)]",children:e})},td({children:e}){return t.jsx("td",{className:"px-3 py-1.5 border-b border-[var(--separator)]",children:e})},hr(){return t.jsx("hr",{className:"my-3 border-[var(--separator)]"})},a({href:e,children:n}){return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-[var(--color-accent)] hover:underline",children:n})},strong({children:e}){return t.jsx("strong",{className:"font-semibold text-[var(--label-primary)]",children:e})},em({children:e}){return t.jsx("em",{className:"italic text-[var(--label-primary)]",children:e})}};function dr(e){if(!/^---\s*\n/.test(e))return e;const n=e.match(/\n---\s*(?:\n|$)/);if(!n||n.index===void 0)return e;const r=e.slice(4,n.index);let s=!1;try{const a=Et.load(r);s=typeof a=="object"&&a!==null&&!Array.isArray(a)&&Object.keys(a).length>0}catch{}return s?e:"***"+e.slice(3)}var jt;const ur={...Le,attributes:{...Le.attributes,code:[...((jt=Le.attributes)==null?void 0:jt.code)||[],["className",/^language-.+/]]}};function J({content:e}){if(!e.trim())return null;const n=l.useMemo(()=>dr(e),[e]);return t.jsx("div",{className:"markdown-body min-w-0 max-w-full break-words",children:t.jsx(In,{remarkPlugins:[Pn,On,$n,lr],rehypePlugins:[An,[Ln,ur],_n],components:cr,children:n})})}function pr({content:e,streaming:n,autoCollapse:r}){const{t:s}=z(),[a,o]=l.useState(r),i=l.useRef(!1);return l.useEffect(()=>{r&&!i.current&&(i.current=!0,o(!0))},[r]),t.jsxs("div",{className:`rounded-[8px] bg-[var(--fill-card)] border border-[var(--separator)] overflow-hidden transition-all ${a?"max-w-[640px]":""}`,children:[t.jsxs("button",{onClick:()=>o(!a),className:"w-full flex items-center gap-1.5 px-3 py-1.5 text-left hover:bg-[var(--fill-quaternary)] transition-colors",children:[t.jsx(Je,{size:12,className:`text-[var(--label-tertiary)] transition-transform ${a?"":"rotate-90"}`}),t.jsx("span",{className:"text-[12px] font-medium text-[var(--label-tertiary)]",children:s(n?"entries.thinkingStreaming":"entries.thinking")})]}),!a&&t.jsx("div",{className:"px-3 pb-2.5 pt-0.5 text-[var(--label-secondary)] italic",children:t.jsx(J,{content:e})})]})}function X({title:e,trailing:n,onClose:r,children:s}){return t.jsx("div",{className:"fixed-viewport z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:r,children:t.jsxs("div",{className:"w-[90%] max-w-[640px] max-h-[80vh] rounded-[18px] bg-[var(--material-modal)] backdrop-blur-[30px] border border-[var(--separator)] shadow-[0_8px_40px_rgba(0,0,0,0.12)] flex flex-col overflow-hidden",onClick:a=>a.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[var(--separator)]",children:[t.jsx("div",{className:"flex items-center gap-2 text-[15px] font-semibold text-[var(--label-primary)] select-text",children:e}),t.jsxs("div",{className:"flex items-center gap-2 select-text",children:[n,t.jsx("button",{onClick:r,className:"select-none w-7 h-7 flex items-center justify-center rounded-full hover:bg-[var(--fill-secondary)] transition-colors text-[var(--label-secondary)]",children:t.jsx(Xe,{size:14})})]})]}),s]})})}function $t(e){return{read:t.jsx(un,{size:14}),bash:t.jsx(dn,{size:14}),edit:t.jsx(ct,{size:14}),write:t.jsx(ct,{size:14})}[e]??t.jsx(ln,{size:14})}function xr(e,n){switch(e){case"read":{const r=n.path??"",s=n.offset,a=n.limit;if(s!=null||a!=null){const o=s??"",i=a!=null?(s??1)+a-1:"";return`${r} [${o}:${i}]`}return r}case"bash":return n.command?String(n.command).slice(0,80):"";case"edit":return n.path??"";case"write":return n.path??"";default:return""}}function Ee(e,n){let r=0;const s=/`+/g;let a;for(;(a=s.exec(e))!==null;)a[0].length>r&&(r=a[0].length);const o="`".repeat(Math.max(3,r+1));return`${o}${n}
|
|
3
|
+
${e}
|
|
4
|
+
${o}`}const fr={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",json:"json",css:"css",scss:"scss",less:"less",html:"xml",htm:"xml",xml:"xml",svg:"xml",md:"markdown",mdx:"markdown",yaml:"yaml",yml:"yaml",toml:"ini",ini:"ini",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",py:"python",rb:"ruby",rs:"rust",go:"go",java:"java",kt:"kotlin",swift:"swift",c:"c",h:"c",cpp:"cpp",hpp:"cpp",cs:"csharp",php:"php",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"dockerfile",makefile:"makefile",lua:"lua",vim:"vim",diff:"diff",patch:"diff"};function zt(e){var a;const n=e.split("/").pop()??"",r=n.toLowerCase();if(r==="dockerfile")return"dockerfile";if(r==="makefile"||r==="gnumakefile")return"makefile";const s=(a=n.split(".").pop())==null?void 0:a.toLowerCase();if(s)return fr[s]}function mr(e,n){for(const r of e){const s=r.message;if((s==null?void 0:s.role)==="toolResult"&&s.toolCallId===n)return{content:Array.isArray(s.content)?s.content.filter(o=>o.type==="text").map(o=>o.text).join(`
|
|
5
|
+
`):String(s.content??""),isError:s.isError??!1,details:s.details??void 0}}return null}function hr({name:e,args:n,toolCallId:r,entries:s,isAborted:a=!1}){const[o,i]=l.useState(!1),c=xr(e,n),d=l.useMemo(()=>r?mr(s,r):null,[s,r]),u=d!==null,m=((d==null?void 0:d.isError)??!1)||!u&&a,g=e==="read"?gr:e==="bash"?br:e==="write"?vr:e==="edit"?jr:wr;return t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>i(!0),className:"w-full max-w-[640px] flex items-center gap-2.5 px-3 py-2 rounded-[8px] bg-[var(--fill-card)] border border-[var(--separator)] hover:bg-[var(--fill-tertiary)] transition-colors text-left group select-none",children:[t.jsx("span",{className:"text-[var(--label-secondary)] group-hover:text-[var(--color-accent)] transition-colors",children:$t(e)}),t.jsx("span",{className:"text-[13px] font-medium text-[var(--label-primary)]",children:e}),c&&t.jsx("span",{className:"text-[12px] text-[var(--label-tertiary)] truncate flex-1 min-w-0",children:c}),t.jsx("span",{className:"flex-shrink-0 ml-auto",children:!u&&!a?t.jsx(de,{size:14,className:"text-[var(--label-tertiary)] animate-spin"}):m?t.jsx(kt,{size:14,className:"text-red-400"}):t.jsx(Je,{size:14,className:"text-[var(--label-tertiary)] group-hover:text-[var(--label-secondary)] transition-colors"})})]}),o&&t.jsx(g,{name:e,args:n,result:d,isAborted:a,onClose:()=>i(!1)})]})}function xe(){const{t:e}=z();return t.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-[var(--label-tertiary)]",children:[t.jsx(de,{size:14,className:"animate-spin"}),t.jsx("span",{children:e("entries.running")})]})}function fe(){const{t:e}=z();return t.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-red-400",children:[t.jsx(kt,{size:14}),t.jsx("span",{children:e("entries.aborted")})]})}function me({name:e}){return t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-[var(--label-secondary)] select-none",children:$t(e)}),e]})}function gr({name:e,args:n,result:r,isAborted:s,onClose:a}){const o=n.path??"",i=n.offset,c=n.limit,d=zt(o);let u=o;if(i!=null||c!=null){const g=i??"",v=c!=null?(i??1)+c-1:"";u+=` [${g}:${v}]`}const f=d==="markdown",m=r&&!r.isError&&!f?Ee(r.content,d??""):null;return t.jsxs(X,{title:t.jsx(me,{name:e}),onClose:a,children:[t.jsx("div",{className:"px-5 py-2 border-b border-[var(--separator)] bg-[var(--fill-quaternary)]",children:t.jsx("p",{className:"text-[13px] text-[var(--label-secondary)] break-all leading-[20px] font-mono",children:u})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-5 pt-3 pb-5 scrollbar-auto",children:r!==null?r.isError?t.jsx("pre",{className:"text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] px-3 py-2 text-red-400 bg-red-400/5",children:r.content}):f?t.jsx(J,{content:r.content}):t.jsx(J,{content:m}):s?t.jsx(fe,{}):t.jsx(xe,{})})]})}function br({name:e,args:n,result:r,isAborted:s,onClose:a}){const o=n.command??"",i=n.timeout,c=Ee(o,"bash"),d=r&&!r.isError?Ee(r.content.trim(),"plaintext"):null;return t.jsx(X,{title:t.jsx(me,{name:e}),onClose:a,trailing:i!=null?t.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[var(--label-tertiary)]",children:[t.jsx(cn,{size:12}),i,"s"]}):void 0,children:t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto",children:[t.jsx("div",{className:"px-5 pt-3 pb-3 bg-[var(--fill-quaternary)]",children:t.jsx(J,{content:c})}),t.jsxs("div",{className:"px-5 pt-3 pb-5",children:[t.jsx("h4",{className:"text-[11px] font-semibold text-[var(--label-tertiary)] uppercase tracking-wide mb-2",children:"Output"}),r!==null?r.isError?t.jsx("pre",{className:"text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] px-3 py-2 text-red-400 bg-red-400/5",children:r.content}):t.jsx(J,{content:d}):s?t.jsx(fe,{}):t.jsx(xe,{})]})]})})}function vr({name:e,args:n,result:r,isAborted:s,onClose:a}){const{t:o}=z(),i=n.path??"",c=n.content??"",d=zt(i),u=d==="markdown",f=u?null:Ee(c,d??"");return t.jsxs(X,{title:t.jsx(me,{name:e}),onClose:a,children:[t.jsx("div",{className:"px-5 py-2 border-b border-[var(--separator)] bg-[var(--fill-quaternary)]",children:t.jsx("p",{className:"text-[13px] text-[var(--label-secondary)] break-all leading-[20px] font-mono",children:i})}),t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 pt-3 pb-5 space-y-3 scrollbar-auto",children:[t.jsx("section",{children:t.jsx(J,{content:u?c:f})}),r!==null&&t.jsxs("section",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-[var(--label-tertiary)] uppercase tracking-wide mb-1.5",children:o("entries.result")}),t.jsx("pre",{className:`text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] px-3 py-2 ${r.isError?"text-red-400 bg-red-400/5":"text-[var(--label-secondary)] bg-[var(--fill-tertiary)]"}`,children:r.content})]}),r===null&&(s?t.jsx(fe,{}):t.jsx(xe,{}))]})]})}function yr({diff:e}){const n=e.split(`
|
|
6
|
+
`);return t.jsx("pre",{className:"text-[13px] leading-[20px] font-mono overflow-x-auto",children:t.jsx("div",{style:{minWidth:"fit-content"},children:n.map((r,s)=>{const a=r[0];return a==="+"?t.jsx("div",{className:"px-3 rounded-[2px]",style:{backgroundColor:"var(--diff-add-bg)",color:"var(--diff-add-text)"},children:r},s):a==="-"?t.jsx("div",{className:"px-3 rounded-[2px]",style:{backgroundColor:"var(--diff-del-bg)",color:"var(--diff-del-text)"},children:r},s):t.jsx("div",{className:"px-3",style:{color:"var(--diff-context-text)"},children:r},s)})})})}function jr({name:e,args:n,result:r,isAborted:s,onClose:a}){var c;const o=n.path??"",i=(c=r==null?void 0:r.details)==null?void 0:c.diff;return t.jsxs(X,{title:t.jsx(me,{name:e}),onClose:a,children:[t.jsx("div",{className:"px-5 py-2 border-b border-[var(--separator)] bg-[var(--fill-quaternary)]",children:t.jsx("p",{className:"text-[13px] text-[var(--label-secondary)] break-all leading-[20px] font-mono",children:o})}),t.jsx("div",{className:"flex-1 overflow-y-auto pt-3 pb-5 scrollbar-auto",children:r!==null?r.isError?t.jsx("pre",{className:"text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] mx-5 px-3 py-2 text-red-400 bg-red-400/5",children:r.content}):i?t.jsx(yr,{diff:i}):t.jsx("pre",{className:"text-[13px] leading-[20px] whitespace-pre-wrap break-words mx-5 px-3 py-2 text-[var(--label-secondary)] bg-[var(--fill-tertiary)] rounded-[8px]",children:r.content}):s?t.jsx("div",{className:"px-5",children:t.jsx(fe,{})}):t.jsx("div",{className:"px-5",children:t.jsx(xe,{})})})]})}function wr({name:e,args:n,result:r,isAborted:s,onClose:a}){const{t:o}=z();return t.jsx(X,{title:t.jsx(me,{name:e}),onClose:a,children:t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 pt-3 pb-5 space-y-3 scrollbar-auto",children:[t.jsxs("section",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-[var(--label-tertiary)] uppercase tracking-wide mb-1.5",children:o("entries.params")}),t.jsx("pre",{className:"text-[13px] leading-[20px] text-[var(--label-secondary)] whitespace-pre-wrap break-words bg-[var(--fill-tertiary)] rounded-[8px] px-3 py-2 overflow-x-auto",children:JSON.stringify(n,null,2)})]}),r!==null&&t.jsxs("section",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-[var(--label-tertiary)] uppercase tracking-wide mb-1.5",children:o("entries.result")}),t.jsx("pre",{className:`text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] px-3 py-2 overflow-x-auto ${r.isError?"text-red-400 bg-red-400/5":"text-[var(--label-secondary)] bg-[var(--fill-tertiary)]"}`,children:r.content})]}),r===null&&t.jsx("section",{children:s?t.jsx(fe,{}):t.jsx(xe,{})})]})})}function Bt({src:e,alt:n,onClose:r}){const s=l.useCallback(a=>{a.key==="Escape"&&r()},[r]);return l.useEffect(()=>(document.addEventListener("keydown",s),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",s),document.body.style.overflow=""}),[s]),t.jsxs("div",{className:"fixed-viewport z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-[30px] animate-in fade-in duration-150",onClick:r,children:[t.jsx("button",{onClick:r,className:"absolute top-4 right-4 z-10 w-9 h-9 rounded-full bg-[var(--badge-bg)] hover:bg-[var(--badge-bg-hover)] text-[var(--badge-text)] flex items-center justify-center transition-colors","aria-label":"Close",children:t.jsx(Xe,{size:18})}),t.jsx("img",{src:e,alt:n??"Image preview",onClick:a=>a.stopPropagation(),className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl select-none",draggable:!1})]})}function Nr({entry:e,entries:n,isLast:r,isStreaming:s,onReEdit:a}){const o=r&&s;switch(e.type){case"message":return t.jsx(kr,{entry:e,entries:n,streaming:o,onReEdit:a});case"compaction":case"branch_summary":return t.jsx(Tr,{type:e.type,summary:e.summary??""});default:return null}}function kr({entry:e,entries:n,streaming:r,onReEdit:s}){const a=e.message;if(!a)return null;switch(a.role){case"user":return t.jsx(Sr,{content:a.content});case"assistant":return t.jsx(Cr,{content:a.content,entries:n,streaming:r,stopReason:a.stopReason,errorMessage:a.errorMessage,onReEdit:s});case"toolResult":return null;default:return null}}function Sr({content:e}){const[n,r]=l.useState(null);let s="",a=[];return typeof e=="string"?s=e:Array.isArray(e)?(s=e.filter(o=>o.type==="text").map(o=>o.text).join(""),a=e.filter(o=>o.type==="image")):s=JSON.stringify(e),t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex justify-end px-4 py-1.5",children:t.jsxs("div",{className:"max-w-[80%] rounded-[16px] rounded-br-[4px] bg-[var(--color-accent)] text-white",children:[a.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5 p-2 pb-0",children:a.map((o,i)=>{const c=`data:${o.mimeType};base64,${o.data}`;return t.jsx("button",{onClick:()=>r(c),className:"block rounded-[8px] overflow-hidden hover:opacity-90 transition-opacity",children:t.jsx("img",{src:c,alt:`Attached image ${i+1}`,className:"max-w-[200px] max-h-[150px] object-cover",draggable:!1})},i)})}),s&&t.jsx("p",{className:"text-[14px] leading-[21px] whitespace-pre-wrap break-words px-3.5 py-2",children:s}),!s&&a.length>0&&t.jsx("div",{className:"h-2"})]})}),n&&t.jsx(Bt,{src:n,onClose:()=>r(null)})]})}function Cr({content:e,entries:n,streaming:r,stopReason:s,errorMessage:a,onReEdit:o}){if((s==="error"||s==="aborted")&&a&&(!Array.isArray(e)||e.length===0))return t.jsx("div",{className:"px-4",children:t.jsx(xt,{message:a,onReEdit:s==="aborted"?o:void 0})});if(!Array.isArray(e))return t.jsx("div",{className:"px-4",children:t.jsx(J,{content:String(e)})});const i=s==="aborted"||s==="error",c=e[e.length-1],d=r&&(c==null?void 0:c.type)==="thinking",u=e.some(f=>f.type==="text"||f.type==="toolCall")||i;return t.jsxs("div",{className:"px-4 space-y-2",children:[e.map((f,m)=>t.jsx(Er,{block:f,entries:n,streaming:r&&m===e.length-1,autoCollapse:f.type==="thinking"&&u&&!d,isAborted:i},m)),(s==="error"||s==="aborted")&&a&&t.jsx(xt,{message:a,onReEdit:s==="aborted"&&!r?o:void 0}),r&&(c==null?void 0:c.type)!=="thinking"&&t.jsx("span",{className:"inline-block w-2 h-4 bg-[var(--label-tertiary)] rounded-sm animate-pulse"})]})}function Er({block:e,entries:n,streaming:r,autoCollapse:s,isAborted:a}){var o;switch(e.type){case"text":return t.jsx(J,{content:e.text});case"thinking":return(o=e.thinking)!=null&&o.trim()?t.jsx(pr,{content:e.thinking,streaming:r,autoCollapse:s}):null;case"toolCall":return t.jsx(hr,{name:e.name,args:e.arguments,toolCallId:e.id,entries:n,isAborted:a});default:return null}}function Tr({type:e,summary:n}){const{t:r}=z(),[s,a]=l.useState(!1),o=r(e==="compaction"?"entries.contextCompacted":"entries.branchSummary");return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex justify-center px-4 py-2",children:t.jsxs("button",{onClick:()=>n&&a(!0),className:`px-3 py-1 rounded-full bg-[var(--fill-tertiary)] text-[11px] text-[var(--label-tertiary)] transition-colors ${n?"hover:bg-[var(--fill-secondary)] cursor-pointer":""}`,children:[o,n&&t.jsxs("span",{className:"ml-1.5 opacity-70",children:["— ",n.slice(0,60),n.length>60?"...":""]})]})}),s&&t.jsx(X,{title:o,onClose:()=>a(!1),children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4 scrollbar-auto",children:t.jsx(J,{content:n})})})]})}function xt({message:e,onReEdit:n}){var m,g;const{t:r}=z(),[s,a]=l.useState(!1);let o=e,i="",c="",d="";const u=e.indexOf("{");if(u>0){o=e.slice(0,u).trim();try{const v=JSON.parse(e.slice(u));i=((m=v==null?void 0:v.error)==null?void 0:m.message)??e.slice(u),c=((g=v==null?void 0:v.error)==null?void 0:g.type)??"";const N=i.match(/request id:\s*([\w]+)/i);N&&(d=N[1])}catch{i=e.slice(u)}}const f=i.length>200;return t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:f?()=>a(!0):void 0,className:`rounded-[10px] border border-[rgba(255,66,69,0.3)] bg-[rgba(255,66,69,0.06)] dark:bg-[rgba(255,66,69,0.1)] px-3.5 py-2.5 max-w-[640px] ${f?"cursor-pointer":""}`,children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(De,{size:14,className:"text-[#ff4245] flex-shrink-0 mt-0.5"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("p",{className:"text-[12px] font-medium text-[#ff4245]",children:o}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[n&&t.jsx("button",{onClick:v=>{v.stopPropagation(),n()},className:"text-[12px] leading-[15px] text-[var(--color-accent)] hover:opacity-70 active:opacity-50 transition-opacity select-none",children:r("reEdit.button")}),f&&t.jsx(Je,{size:12,className:"text-[var(--label-tertiary)] flex-shrink-0"})]})]}),i&&!f&&t.jsx("p",{className:"text-[11px] text-[var(--label-secondary)] mt-1.5 break-all whitespace-pre-wrap",children:i})]})]})}),s&&t.jsx(X,{title:r("error.title"),onClose:()=>a(!1),children:t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-6 scrollbar-auto",children:[t.jsxs("div",{className:"flex flex-col items-center text-center mb-5",children:[t.jsx("div",{className:"w-10 h-10 rounded-full bg-[rgba(255,66,69,0.1)] dark:bg-[rgba(255,66,69,0.15)] flex items-center justify-center mb-3",children:t.jsx(De,{size:20,className:"text-[#ff4245]"})}),t.jsx("p",{className:"text-[15px] font-semibold text-[#ff4245]",children:o})]}),t.jsxs("div",{className:"rounded-[10px] bg-[var(--fill-card)] p-4 space-y-3",children:[t.jsx(Oe,{label:r("error.message"),value:i}),c&&t.jsx(Oe,{label:r("error.type"),value:c}),d&&t.jsx(Oe,{label:r("error.requestId"),value:d,mono:!0})]})]})})]})}function Oe({label:e,value:n,mono:r}){return t.jsxs("div",{children:[t.jsx("p",{className:"text-[11px] text-[var(--label-tertiary)] mb-0.5",children:e}),t.jsx("p",{className:`text-[14px] leading-[22px] text-[var(--label-primary)] break-all whitespace-pre-wrap ${r?"font-mono text-[13px] leading-[20px]":""}`,children:n})]})}function Ft({title:e,subtitle:n,backTo:r="/",actions:s,children:a}){const o=Me();return t.jsxs("div",{className:"md:hidden flex items-center gap-2",children:[t.jsx("button",{onClick:()=>o(r),"aria-label":"Back to instances",className:"flex select-none items-center text-[var(--label-secondary)] active:opacity-60 transition-opacity",children:t.jsx(pn,{size:20})}),a??t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-[14px] font-medium text-[var(--label-primary)] truncate select-text",children:e}),n&&t.jsx("div",{className:"text-[11px] text-[var(--label-tertiary)] truncate select-text",children:n})]}),s]})]})}function Rr(e,n){if(n&&e.startsWith(n)){const r=e.slice(n.length);return!r||r==="/"?"~":"~"+(r.startsWith("/")?r:"/"+r)}return e}function We(e,n){if(e.length<=n)return e;const r=Math.floor((n-1)/2),s=n-1-r;return e.slice(0,s)+"…"+e.slice(-r)}function Mr(e){const n=e.split("/").filter(Boolean);return n.length<=2?e.length:n.slice(-2).join("/").length}function ft(e,n){if(e.length<=n)return e;const r=Mr(e);if(r+2<=n){const s=n-1-r;return e.slice(0,s)+"…"+e.slice(-r)}return We(e,n)}const Ir=6.2,Ar=20,Lr=8;function mt({icon:e,text:n,copyText:r,title:s}){const[a,o]=l.useState(!1),i=l.useRef(null);l.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const c=l.useCallback(()=>{navigator.clipboard.writeText(r),o(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>o(!1),1500)},[r]);return t.jsxs("button",{type:"button",onClick:c,title:s??r,className:"inline-flex min-w-0 items-center gap-1 rounded-[4px] px-1 py-0.5 -mx-1 transition-colors hover:bg-[var(--fill-tertiary)] active:bg-[var(--fill-secondary)] cursor-pointer select-none",children:[t.jsx("span",{className:"shrink-0 opacity-70",children:a?t.jsx(pe,{size:11,className:"text-green-500"}):e}),t.jsx("span",{className:"truncate",children:n})]})}function ht({title:e,cwd:n,homedir:r,gitBranch:s,actions:a}){const o=n?Rr(n,r):null,i=l.useRef(null),[c,d]=l.useState(o),[u,f]=l.useState(s),m=l.useCallback(()=>{const g=i.current;if(!g)return;const v=g.getBoundingClientRect().width;if(v<=0)return;const N=(o?1:0)+(s?1:0),T=N*Ar+(N-1)*Lr,R=Math.floor((v-T)/Ir);if(o&&s){const b=Math.max(10,Math.floor(R*.6)),h=Math.max(8,R-b);d(ft(o,b)),f(We(s,h))}else o?d(ft(o,Math.max(10,R))):s&&f(We(s,Math.max(8,R)))},[o,s]);return l.useEffect(()=>{const g=i.current;if(!g)return;const v=new ResizeObserver(()=>m());return v.observe(g),m(),()=>v.disconnect()},[m]),l.useEffect(()=>{d(o),f(s),m()},[o,s,m]),t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0 flex-1 min-h-[40px]",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"truncate text-[14px] leading-[20px] font-medium text-[var(--label-primary)] select-text",children:e}),(o||s)&&t.jsxs("div",{ref:i,className:"mt-0.5 flex min-w-0 items-center gap-2 text-[11px] leading-[14px] text-[var(--label-secondary)]",children:[c&&t.jsx(mt,{icon:t.jsx(St,{size:11}),text:c,copyText:n,title:n},n),u&&t.jsx(mt,{icon:t.jsx(xn,{size:11}),text:u,copyText:s},s)]})]}),a]})}function _r(e,n="top",r="right",s=8,a=12){const{innerWidth:o,innerHeight:i}=window,c=r==="left"?{left:Math.max(a,e.left)}:{right:Math.max(a,o-e.right)};return n==="bottom"?{...c,top:Math.max(a,e.bottom+s)}:{...c,bottom:Math.max(a,i-e.top+s)}}function tt({trigger:e,width:n=200,children:r,disabled:s=!1,placement:a="top",align:o="right"}){const[i,c]=l.useState(!1),[d,u]=l.useState(null),f=l.useRef(null),m=l.useRef(null);l.useEffect(()=>{if(!i)return;function T(R){var h,C;const b=R.target;!((h=f.current)!=null&&h.contains(b))&&!((C=m.current)!=null&&C.contains(b))&&c(!1)}return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[i]),l.useEffect(()=>{if(!i)return;const T=()=>c(!1);return window.addEventListener("resize",T),()=>{window.removeEventListener("resize",T)}},[i]);const g=()=>{var R;if(s)return;if(i){c(!1);return}const T=(R=f.current)==null?void 0:R.getBoundingClientRect();T&&(u(_r(T,a,o)),c(!0))},v=()=>c(!1),N=i&&d?Ge.createPortal(t.jsx("div",{ref:m,className:"glass-popover z-50",style:{position:"fixed",...d.left!==void 0?{left:d.left}:{right:d.right},...d.top!==void 0?{top:d.top}:{bottom:d.bottom},width:`${n}px`},children:r(v)}),document.body):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"relative",ref:f,onClick:g,children:e({open:i})}),N]})}function Pr(e,n){const r=new Date(e),a=Date.now()-r.getTime(),o=Math.floor(a/6e4);if(o<1)return n("session.timeJustNow");if(o<60)return`${o}m`;const i=Math.floor(o/60);if(i<24)return`${i}h`;const c=Math.floor(i/24);if(c<7)return`${c}d`;const d=Math.floor(c/7);return d<4?`${d}w`:r.toLocaleDateString()}function Or({sessions:e,loading:n,hasMore:r,total:s,disabled:a,onOpen:o,onNewSession:i,onSwitchSession:c,onLoadMore:d,onFilterChange:u}){const{t:f}=z(),[m,g]=l.useState(""),v=l.useRef(null),N=l.useRef(null),T=l.useCallback(b=>{g(b),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{u(b)},300)},[u]),R=l.useCallback(b=>{if(!r||n)return;const h=b.currentTarget;h.scrollHeight-h.scrollTop-h.clientHeight<40&&d(e.length,m)},[r,n,e.length,m,d]);return t.jsx(tt,{trigger:({open:b})=>t.jsx("button",{className:`flex items-center justify-center w-9 h-9 rounded-[8px] transition-colors ${b?"bg-[rgba(0,0,0,0.11)] dark:bg-[rgba(255,255,255,0.11)]":"hover:bg-[var(--fill-tertiary)]"} ${a?"opacity-40 pointer-events-none":""}`,title:f("session.title"),onClick:()=>{b||(g(""),o())},children:t.jsx(fn,{size:16,className:"text-[var(--label-secondary)]"})}),width:320,disabled:a,placement:"bottom",children:b=>t.jsxs("div",{className:"flex flex-col max-h-[360px]",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 pt-2.5 pb-2",children:[t.jsxs("span",{className:"text-[13px] font-medium text-[var(--label-primary)] select-none",children:[f("session.title"),s>0&&t.jsxs("span",{className:"ml-1.5 text-[11px] font-normal text-[var(--label-tertiary)]",children:["(",s,")"]})]}),t.jsxs("button",{onClick:()=>{i(),b()},disabled:a,className:"flex items-center gap-1 px-2 py-1 rounded-[6px] text-[12px] text-[var(--label-secondary)] hover:text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)] transition-colors disabled:opacity-40",children:[t.jsx(wt,{size:12}),t.jsx("span",{children:f("session.new")})]})]}),t.jsx("div",{className:"px-3 pb-2",children:t.jsx("input",{type:"text",placeholder:f("session.filter"),value:m,onChange:h=>T(h.target.value),className:"w-full px-2.5 py-1.5 rounded-[6px] bg-[var(--fill-tertiary)] text-[12px] text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] outline-none border border-transparent focus:border-[var(--separator)]",autoFocus:!0})}),t.jsx("div",{className:"h-px bg-[var(--separator)] mx-2"}),t.jsx("div",{ref:N,className:"flex-1 overflow-y-auto scrollbar-auto py-1.5 px-1.5",onScroll:R,children:n&&e.length===0?t.jsx("div",{className:"flex items-center justify-center py-6",children:t.jsx(de,{size:16,className:"animate-spin text-[var(--label-tertiary)]"})}):e.length===0?t.jsx("div",{className:"py-4 text-center text-[12px] text-[var(--label-tertiary)] select-none",children:f(m?"session.noMatch":"session.noPrevious")}):t.jsxs(t.Fragment,{children:[e.map(h=>t.jsxs("button",{onClick:()=>{h.isCurrent||(c(h.path),b())},disabled:h.isCurrent,className:`w-full text-left px-2.5 py-2 rounded-[8px] transition-colors mb-0.5 ${h.isCurrent?"bg-[var(--fill-secondary)] cursor-default":"hover:bg-[var(--fill-tertiary)] cursor-pointer"}`,children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:`text-[13px] leading-[18px] truncate ${h.isCurrent?"font-medium text-[var(--color-accent)]":"text-[var(--label-primary)]"}`,children:h.name||h.firstMessage||f("session.empty")}),t.jsx("span",{className:"text-[11px] text-[var(--label-tertiary)] whitespace-nowrap shrink-0",children:Pr(h.modified,f)})]}),h.name&&h.firstMessage&&t.jsx("div",{className:"mt-0.5 text-[11px] leading-[15px] text-[var(--label-tertiary)] truncate",children:h.firstMessage}),t.jsx("div",{className:"mt-0.5 text-[10px] text-[var(--label-quaternary)]",children:f("session.messageCount",{count:h.messageCount})})]},h.id)),n&&e.length>0&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(de,{size:14,className:"animate-spin text-[var(--label-tertiary)]"})})]})})]})})}const $r=["image/png","image/jpeg","image/gif","image/webp"],zr=2048,Br=2048,gt=.85,$e=5*1024*1024;function Dt(){return`img_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}async function bt(e){if(!$r.includes(e.type))throw new Error(`Unsupported image type: ${e.type}`);const n=await createImageBitmap(e),{width:r,height:s}=Dr(n.width,n.height,zr,Br),a=document.createElement("canvas");a.width=r,a.height=s,a.getContext("2d").drawImage(n,0,0,r,s),n.close();let i=e.type,c=gt;e.type!=="image/png"&&e.type!=="image/gif"&&(i="image/jpeg");let d=a.toDataURL(i,c);if(i==="image/jpeg"||i==="image/webp")for(;ze(d)>$e&&c>.3;)c-=.1,d=a.toDataURL(i,c);if(i==="image/png"&&ze(d)>$e)for(i="image/jpeg",c=gt,d=a.toDataURL(i,c);ze(d)>$e&&c>.3;)c-=.1,d=a.toDataURL(i,c);const u=d.split(",")[1];return{id:Dt(),data:u,mimeType:i,previewUrl:d}}function Fr(e){const n=[];for(let r=0;r<e.items.length;r++){const s=e.items[r];if(s.type.startsWith("image/")){const a=s.getAsFile();a&&n.push(a)}}return n}function Dr(e,n,r,s){if(e<=r&&n<=s)return{width:e,height:n};const a=Math.min(r/e,s/n);return{width:Math.round(e*a),height:Math.round(n*a)}}function ze(e){const n=e.split(",")[1];return n?Math.ceil(n.length*3/4):0}let Hr=0,Ne=[];function ee(e,n="info"){const r={id:++Hr,message:e,level:n,phase:"entering"};Ne.forEach(s=>s(r))}const qr=16,Kr=300,Ur={info:3e3,success:3e3,warning:4e3,error:5e3},Wr={info:gn,success:hn,warning:mn,error:De},Yr={info:"var(--toast-icon-info)",success:"var(--toast-icon-success)",warning:"var(--toast-icon-warning)",error:"var(--toast-icon-error)"};function Gr(){const[e,n]=l.useState([]),r=l.useRef(new Set);return l.useEffect(()=>{const s=a=>{n(d=>[...d,a]);const o=setTimeout(()=>{r.current.delete(o),n(d=>d.map(u=>u.id===a.id?{...u,phase:"visible"}:u))},qr);r.current.add(o);const i=Ur[a.level],c=setTimeout(()=>{r.current.delete(c),n(u=>u.map(f=>f.id===a.id?{...f,phase:"exiting"}:f));const d=setTimeout(()=>{r.current.delete(d),n(u=>u.filter(f=>f.id!==a.id))},Kr);r.current.add(d)},i);r.current.add(c)};return Ne.push(s),()=>{Ne=Ne.filter(a=>a!==s),r.current.forEach(a=>clearTimeout(a)),r.current.clear()}},[]),e.length===0?null:t.jsx("div",{className:"fixed top-[max(1rem,env(safe-area-inset-top))] left-1/2 -translate-x-1/2 z-[100] flex flex-col items-center gap-2 pointer-events-none",children:e.map(s=>{const a=Wr[s.level],o=Yr[s.level];return t.jsxs("div",{className:"pointer-events-auto flex items-center gap-2 rounded-full bg-[var(--panel-bg)] backdrop-blur-[30px] border-[0.5px] border-[var(--panel-border)] shadow-[var(--panel-shadow)] px-4 py-2.5 text-[13px] leading-[16px] text-[var(--label-primary)] select-none transition-all duration-300 ease-out",style:s.phase==="entering"?{opacity:0,transform:"translateY(-8px)"}:s.phase==="exiting"?{opacity:0,transform:"translateY(-4px)"}:{opacity:1,transform:"translateY(0)"},children:[t.jsx(a,{size:14,className:"shrink-0",style:{color:o}}),t.jsx("span",{children:s.message})]},s.id)})})}function Vr({currentModel:e,availableModels:n,onSelect:r}){const a=n&&n.length>0&&r,o=new Map;if(n)for(const c of n){const d=o.get(c.provider)??[];d.push(c),o.set(c.provider,d)}const i=c=>c.provider===e.provider&&c.id===e.id;return t.jsx(tt,{disabled:!a,width:280,align:"left",trigger:({open:c})=>t.jsxs("button",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-[9px] bg-[var(--fill-tertiary)] text-[12px] transition-colors ${a?"hover:bg-[var(--fill-secondary)] hover:text-[var(--label-primary)] cursor-pointer":"cursor-default"} text-[var(--label-secondary)]`,children:[t.jsx("span",{className:"max-w-[140px] truncate select-text",children:e.name||e.id}),a&&t.jsx(Ct,{size:10,className:`transition-transform ${c?"rotate-180":""}`})]}),children:c=>t.jsx("div",{className:"max-h-[320px] overflow-y-auto py-1.5 px-1.5 scrollbar-auto",children:Array.from(o.entries()).map(([d,u],f)=>t.jsxs("div",{children:[f>0&&t.jsx("div",{className:"mx-1 my-1 h-px bg-[var(--separator)]"}),t.jsx("div",{className:"px-2.5 pt-2 pb-1 text-[11px] font-bold text-[var(--label-tertiary)] uppercase select-none",children:d}),u.map(m=>{const g=i(m);return t.jsxs("button",{onClick:()=>{g||r==null||r(m.provider,m.id),c()},className:`w-full text-left px-2.5 py-2 rounded-[8px] flex items-center gap-2 transition-colors select-none mb-0.5 ${g?"bg-[var(--fill-secondary)]":"hover:bg-[var(--fill-tertiary)]"}`,children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-[13px] text-[var(--label-primary)] truncate select-text",children:m.name||m.id}),t.jsx("div",{className:"text-[11px] text-[var(--label-tertiary)] truncate select-text",children:m.id})]}),g&&t.jsx(pe,{size:14,className:"text-[var(--color-accent)] flex-shrink-0"})]},`${m.provider}/${m.id}`)})]},d))})})}const Jr=["off","minimal","low","medium","high"];function Xr({currentLevel:e,availableLevels:n,onSelect:r}){const s=!!r,a=n.length>0?n:Jr;return t.jsx(tt,{disabled:!s,width:160,align:"left",trigger:({open:o})=>t.jsxs("button",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-[9px] bg-[var(--fill-tertiary)] text-[12px] transition-colors ${s?"hover:bg-[var(--fill-secondary)] hover:text-[var(--label-primary)] cursor-pointer":"cursor-default"} text-[var(--label-secondary)]`,children:[t.jsx("span",{className:"select-text",children:e}),s&&t.jsx(Ct,{size:10,className:`transition-transform ${o?"rotate-180":""}`})]}),children:o=>t.jsx("div",{className:"py-1.5 px-1.5",children:a.map(i=>{const c=i===e;return t.jsxs("button",{onClick:()=>{c||r==null||r(i),o()},className:`w-full text-left px-2.5 py-2 rounded-[8px] flex items-center gap-2 transition-colors select-none mb-0.5 ${c?"bg-[var(--fill-secondary)]":"hover:bg-[var(--fill-tertiary)]"}`,children:[t.jsx("span",{className:"flex-1 text-[13px] text-[var(--label-primary)]",children:i}),c&&t.jsx(pe,{size:14,className:"text-[var(--color-accent)] flex-shrink-0"})]},i)})})})}function Zr({onClose:e,onConfirm:n}){const{t:r}=z(),[s,a]=l.useState(""),o=l.useCallback(()=>{n(s.trim()||void 0)},[s,n]);return t.jsx(X,{title:r("compact.title"),onClose:e,children:t.jsxs("div",{className:"px-5 py-4 space-y-3",children:[t.jsx("p",{className:"text-[13px] leading-[18px] text-[var(--label-secondary)] select-none",children:r("compact.description")}),t.jsx("textarea",{value:s,onChange:i=>a(i.target.value),placeholder:r("compact.placeholder"),rows:3,className:"w-full px-3 py-2 rounded-[10px] bg-[var(--fill-tertiary)] border border-[var(--separator)] text-[14px] leading-[20px] text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] outline-none resize-none focus:border-[var(--color-accent)] transition-colors"}),t.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[t.jsx("button",{onClick:e,className:"px-3.5 py-1.5 rounded-[8px] text-[13px] text-[var(--label-secondary)] hover:bg-[var(--fill-tertiary)] transition-colors",children:r("common.cancel")}),t.jsx("button",{onClick:o,className:"px-3.5 py-1.5 rounded-[8px] text-[13px] font-medium text-white bg-[var(--color-accent)] hover:opacity-90 active:opacity-80 transition-opacity",children:r("compact.start")})]})]})})}function Qr({ref:e,instance:n,draft:r,onDraftChange:s,onSendMessage:a,onAbort:o,onSetModel:i,onSetThinkingLevel:c,onCompact:d,buttonMode:u,showCompactButton:f,compactDisabled:m,onImageLightbox:g,startBottomFollow:v}){var E;const{t:N}=z(),T=l.useRef(null);l.useImperativeHandle(e,()=>({focus(){const x=T.current;if(!x)return;x.focus();const p=x.value.length;x.selectionStart=x.selectionEnd=p,x.scrollTop=x.scrollHeight}}));const R=l.useRef(null),b=l.useRef(r);b.current=r;const[h,C]=l.useState(!1),j=n==null?void 0:n.status,O=n==null?void 0:n.contextUsage,k=n==null?void 0:n.model,_=n==null?void 0:n.availableModels,y=n==null?void 0:n.thinkingLevel,w=(E=_==null?void 0:_.find(x=>x.provider===(k==null?void 0:k.provider)&&x.id===(k==null?void 0:k.id)))==null?void 0:E.availableThinkingLevels,M=!!O&&O.tokens!=null&&O.percent!=null,P=l.useCallback(x=>{x.style.height="auto";const p=Math.min(x.scrollHeight,150);x.style.height=`${p}px`,x.style.overflowY=x.scrollHeight>150?"auto":"hidden"},[]);l.useLayoutEffect(()=>{T.current&&P(T.current)},[r.text,P]);const $=l.useCallback(x=>{s(p=>({...p,text:x.target.value})),P(x.target)},[s,P]),D=!ue(j)&&(!!r.text.trim()||r.images.length>0),F=l.useCallback(()=>{const x=b.current;if(ue(j)||!x.text.trim()&&x.images.length===0)return;const p=x.images.length?x.images.map(S=>({data:S.data,mimeType:S.mimeType})):void 0;a(x.text.trim(),p),T.current&&(T.current.style.height="auto"),v()},[j,a,v]),W=l.useCallback(x=>{x.nativeEvent.isComposing||x.keyCode===229||x.key==="Enter"&&!x.shiftKey&&(x.preventDefault(),F())},[F]),Y=l.useCallback(x=>{const p=Fr(x.clipboardData);p.length!==0&&(x.preventDefault(),Promise.all(p.map(bt)).then(S=>{s(I=>({...I,images:[...I.images,...S]}))}).catch(S=>{ee(N("eventStream.imageProcessFailed"),"error"),console.error("Image process failed:",S)}))},[s,N]),Z=l.useCallback(x=>{const p=Array.from(x.target.files??[]);p.length!==0&&(Promise.all(p.map(bt)).then(S=>{s(I=>({...I,images:[...I.images,...S]}))}).catch(S=>{ee(N("eventStream.imageProcessFailed"),"error"),console.error("Image process failed:",S)}),x.target.value="")},[s,N]),G=l.useCallback(x=>{s(p=>({...p,images:p.images.filter(S=>S.id!==x)}))},[s]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"glass-panel glass-panel-input px-3 py-2 md:px-4",children:[(j||M)&&t.jsxs("div",{className:"mb-1.5 flex items-center gap-2 px-1 text-[12px] leading-[15px] text-[var(--label-secondary)]",children:[t.jsx(es,{status:j}),M&&t.jsxs("span",{className:"min-w-0 flex items-center gap-1",children:[t.jsx("span",{className:"min-w-0 truncate",children:t.jsx(ts,{contextUsage:O})}),f&&t.jsx("button",{onClick:()=>C(!0),disabled:m,title:N("eventStream.compactContext"),className:"shrink-0 inline-flex items-center justify-center p-0.5 rounded-[4px] text-[var(--label-secondary)] hover:text-[var(--color-accent)] hover:bg-[var(--fill-tertiary)] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:t.jsx(bn,{size:12})})]})]}),t.jsxs("div",{className:"flex flex-col overflow-hidden rounded-[14px] border border-[var(--separator)]",children:[r.images.length>0&&t.jsx("div",{className:"flex gap-2 px-3 pt-2 pb-0 overflow-x-auto scrollbar-none md:px-4",children:r.images.map(x=>t.jsxs("div",{className:"relative flex-shrink-0 group",children:[t.jsx("button",{onClick:()=>g(x.previewUrl),className:"block rounded-[8px] overflow-hidden border border-[var(--separator)] hover:border-[var(--color-accent)] transition-colors",children:t.jsx("img",{src:x.previewUrl,alt:"Attached",className:"w-[60px] h-[60px] object-cover",draggable:!1})}),t.jsx("button",{onClick:()=>G(x.id),className:"absolute -top-1 -right-1 w-[14px] h-[14px] rounded-full bg-[var(--badge-bg)] text-[var(--badge-text)] flex items-center justify-center hover:bg-[var(--badge-bg-hover)] transition-colors","aria-label":"Remove image",children:t.jsx(Xe,{size:8})})]},x.id))}),t.jsx("textarea",{ref:T,rows:1,placeholder:N("eventStream.sendPlaceholder"),value:r.text,onChange:$,onKeyDown:W,onPaste:Y,className:"resize-none bg-transparent text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] text-[16px] leading-[24px] px-3 pt-[9px] pb-0 outline-none overflow-hidden md:px-4 md:pt-[10px] md:text-[14px] md:leading-[22px]"}),t.jsxs("div",{className:"flex items-center justify-between px-1.5 pt-[9px] pb-1.5 md:pt-[10px]",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[k&&t.jsx(Vr,{currentModel:k,availableModels:_,onSelect:i}),y&&t.jsx(Xr,{currentLevel:y,availableLevels:w??[],onSelect:c}),t.jsx("button",{onClick:()=>{var x;return(x=R.current)==null?void 0:x.click()},className:"select-none h-[26px] px-1.5 rounded-[6px] flex items-center justify-center text-[var(--label-secondary)] hover:text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)] transition-colors",title:N("eventStream.attachImage"),children:t.jsx(vn,{size:15})}),t.jsx("input",{ref:R,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",multiple:!0,onChange:Z,className:"hidden"})]}),t.jsx("div",{className:"flex-shrink-0",children:u==="stop"?t.jsx("button",{onClick:o,className:"select-none w-[28px] h-[28px] rounded-full bg-red-500 text-white flex items-center justify-center hover:opacity-90 active:opacity-80 transition-opacity",title:N("eventStream.stop"),children:t.jsx(yn,{size:12,fill:"currentColor"})}):t.jsx("button",{onClick:F,disabled:!D,className:`select-none w-[28px] h-[28px] rounded-full flex items-center justify-center transition-opacity ${D?"bg-[var(--color-accent)] text-white hover:opacity-90 active:opacity-80":"bg-[var(--fill-secondary)] text-[var(--label-tertiary)] opacity-50 cursor-default"}`,title:N("eventStream.send"),children:t.jsx(jn,{size:16,strokeWidth:2.5})})})]})]})]}),h&&t.jsx(Zr,{onClose:()=>C(!1),onConfirm:x=>{d(x),C(!1)}})]})}function es({status:e}){const{t:n}=z();if(!e)return null;const r=e==="streaming",s=e==="compacting",a=r?"bg-[color-mix(in_srgb,var(--color-accent)_12%,transparent)] text-[var(--color-accent)]":s?"bg-amber-500/10 text-amber-500":"bg-green-500/10 text-green-500",o=r?"bg-[var(--color-accent)] animate-pulse":s?"bg-amber-500 animate-pulse":"bg-green-500",i=n(r?"eventStream.statusRunning":s?"eventStream.statusCompacting":"eventStream.statusOnline");return t.jsxs("span",{className:`flex shrink-0 items-center gap-1 rounded-full px-1.5 py-0.5 ${a}`,title:i,role:"status","aria-live":"polite","aria-label":i,children:[t.jsx("span",{"aria-hidden":"true",className:`h-2 w-2 rounded-full ${o}`}),t.jsx("span",{className:"text-[11px] font-medium leading-none",children:i})]})}function ts({contextUsage:e}){const{tokens:n,contextWindow:r,percent:s}=e;if(n==null||s==null)return null;const a=s>90?"#ff4245":s>60?"#ff9230":"#30d158",o=i=>{if(i<1e3)return String(i);if(i<1e4)return`${(i/1e3).toFixed(1)}k`;if(i<1e6)return`${Math.round(i/1e3)}k`;const c=i/1e6;return c%1===0?`${c}M`:`${c.toFixed(1)}M`};return t.jsxs("span",{className:"select-text",style:{color:a},children:[o(n)," / ",o(r)," (",Math.round(s),"%)"]})}let ns=0;function Ht(e,n){return`${e}:${n}:${ns++}`}function Be(e,n,r){return n.id||n.__renderKey?n:{...n,__renderKey:Ht(e,r)}}function rs(e,n){const{t:r}=z(),s=K(p=>p.send),a=K(p=>p.subscribe),o=K(p=>p.connectionState==="connected"),[i,c]=l.useState([]),[d,u]=l.useState(null),f=l.useRef(null),[m,g]=l.useState("idle"),[v,N]=l.useState(null),[T,R]=l.useState(!1),[b,h]=l.useState([]),[C,j]=l.useState(!1),[O,k]=l.useState(!1),[_,y]=l.useState(0),w=l.useRef(0),M=l.useRef(i);M.current=i;const P=l.useRef(m);P.current=m;const $=l.useRef(T);$.current=T;const D=l.useCallback(()=>{c([]),u(null),g("refreshing"),N(null),R(!1),h([]),j(!1),k(!1),y(0)},[]);l.useEffect(()=>a(p=>{switch(p.type){case"forwarded_event":{if(p.payload.instanceId!==e)return;Z(e,p.payload.event,p.payload.data);break}case"history":{if(p.payload.instanceId!==e)return;const S=p.payload.messages,I=p.payload.hasMore??!1;G(e,S,I);break}case"session_list":{if(p.payload.instanceId!==e)return;w.current>0?h(S=>[...S,...p.payload.sessions]):h(p.payload.sessions),k(p.payload.hasMore??!1),y(p.payload.total??p.payload.sessions.length),j(!1);break}case"error":{console.error("[Paimon]",p.payload.message),g("error"),N(p.payload.message);break}case"instance_error":{if(p.payload.instanceId!==e)return;const S=p.payload.action?`error.action.${p.payload.action}`:null,I=S?r(S,{message:p.payload.message,defaultValue:p.payload.message}):p.payload.message;ee(I,"error");break}}}),[e,a]),l.useEffect(()=>{if(o)return D(),s({type:"subscribe",payload:{instanceId:e}}),s({type:"get_history",payload:{instanceId:e}}),()=>{s({type:"unsubscribe",payload:{instanceId:e}})}},[e,o,s,D]);const F=l.useRef(n==null?void 0:n.sessionId),W=l.useRef(e);l.useEffect(()=>{const p=n==null?void 0:n.sessionId;if(e!==W.current){W.current=e,p!==void 0&&(F.current=p);return}F.current!==void 0&&p!==void 0&&p!==F.current&&(D(),s({type:"get_history",payload:{instanceId:e}})),p!==void 0&&(F.current=p)},[n==null?void 0:n.sessionId,e,s,D]);const Y=l.useRef(n==null?void 0:n.status);l.useEffect(()=>{const p=n==null?void 0:n.status;Y.current==="compacting"&&p!=="compacting"&&(D(),s({type:"get_history",payload:{instanceId:e}})),Y.current=p},[n==null?void 0:n.status,e,s,D]);function Z(p,S,I){const B=I;switch(S){case"message_start":{const A=B.message;if(!A||A.role!=="assistant")break;const H=Be(p,{type:"message",timestamp:new Date().toISOString(),message:A},"streaming");f.current=H.__renderKey??H.id??null,u(H);break}case"message_update":{const A=B.message;if(!A)break;u(H=>H?{...H,message:A}:Be(p,{type:"message",timestamp:new Date().toISOString(),message:A},"streaming"));break}case"message_end":{const A=B.message;if(A){const H=f.current??Ht(p,"live"),oe={type:"message",timestamp:new Date().toISOString(),message:A,__renderKey:H};c(te=>[...te,oe])}f.current=null,u(null);break}}}function G(p,S,I){const B=S.map(A=>Be(p,A,"history"));P.current==="loadingMore"?c(A=>[...B,...A]):c(B),R(I),g("idle"),N(null)}const E=l.useCallback(()=>{if(!$.current||P.current!=="idle")return;const p=M.current.length;g("loadingMore"),s({type:"get_history",payload:{instanceId:e,offset:p}})},[e,s]),x=l.useCallback(p=>{const S=(p==null?void 0:p.offset)??0;w.current=S,S===0&&h([]),j(!0),s({type:"list_sessions",payload:{instanceId:e,offset:S,limit:p==null?void 0:p.limit,filter:p==null?void 0:p.filter}})},[e,s]);return{entries:d?[...i,d]:i,streamingEntry:d,isStreaming:d!==null,loadState:m,errorMessage:v,hasMore:T,sessionList:b,sessionListLoading:C,sessionHasMore:O,sessionTotal:_,loadMore:E,requestSessionList:x}}const ss=.5;function as({topChromeHeight:e,bottomChromeHeight:n,bottomSafeGap:r=0}){const s=Math.max(0,n-r),a=Math.max(40,s+12);return{paddingTop:Math.max(24,e-4),paddingBottom:a,scrollButtonBottom:r+a}}function os({previousScrollTop:e,previousScrollHeight:n,nextScrollHeight:r}){return e+r-n}function ls(e){return e==="streaming"||e==="compacting"?"stop":"send"}function Te(e){return Math.max(0,e)}function is({isAtBottom:e,isLoadingMore:n,distanceToBottom:r,overlap:s,force:a=!1,scrollToBottom:o}){return!e||n||!a&&r<=ss&&s<=0?!1:(o(),!0)}function cs({rawScrollTop:e,hasMore:n,canLoadMore:r,isLoadingMore:s,isSuppressed:a}){return e>=0&&Te(e)<100&&n&&r&&!s&&!a}const ds=350,he="data-entry-key",qt=.5,us=3,ps=2e3;function nt(e){return e.getAttribute(he)??void 0}function Kt(e,n){const r=n.closest(`[${he}]`);return!r||!e.contains(r)?null:r}function Ut(e,n){const r=e.querySelectorAll(`[${he}]`);for(const s of r)if(nt(s)===n)return s;return null}function ce(e,n){return n.getBoundingClientRect().top-e.top}function xs(e){const n=e.getBoundingClientRect(),r=n.top+8,s=e.querySelectorAll(`[${he}]`);for(const a of s){const o=a.getBoundingClientRect();if(o.bottom>r&&o.top<n.bottom)return a}return null}function fs(e){const n={fallbackScrollTop:Te(e.scrollTop),fallbackScrollHeight:e.scrollHeight},r=e.getBoundingClientRect(),s=xs(e);if(!s)return n;const a=nt(s);if(!a)return n;const o=s.getBoundingClientRect(),i=Math.min(Math.max(r.top+12,o.top+8),Math.min(o.bottom-1,r.bottom-1)),c=[{x:r.left+r.width/2,y:i},{x:r.left+24,y:i},{x:r.right-24,y:i}];for(const d of c){const u=document.elementsFromPoint(d.x,d.y);for(const f of u){if(f===e||!e.contains(f))continue;const m=Kt(e,f);if(!m||m!==s)continue;const g=f.getBoundingClientRect();if(!(g.bottom<=r.top||g.top>=r.bottom))return{...n,entryKey:a,element:f,elementTop:ce(r,f),entryTop:ce(r,s)}}}return{...n,entryKey:a,entryTop:ce(r,s)}}function vt(e,n){return Math.abs(n)<=qt?!1:(e.scrollTop+=n,!0)}function yt(e,n,{allowDiffFallback:r}){const s=e.getBoundingClientRect();if(n.element&&n.elementTop!=null&&n.element.isConnected&&e.contains(n.element)){const a=Kt(e,n.element),o=a?nt(a):void 0;if(!n.entryKey||o===n.entryKey){const i=ce(s,n.element)-n.elementTop;return{mode:"deep",delta:i,adjusted:vt(e,i)}}}if(n.entryKey&&n.entryTop!=null){const a=Ut(e,n.entryKey);if(a){const o=ce(s,a)-n.entryTop;return{mode:"entry",delta:o,adjusted:vt(e,o)}}}if(r){const a=os({previousScrollTop:n.fallbackScrollTop,previousScrollHeight:n.fallbackScrollHeight,nextScrollHeight:e.scrollHeight}),o=a-e.scrollTop;return e.scrollTop=a,{mode:"diff",delta:o,adjusted:Math.abs(o)>qt}}return{mode:"none",delta:0,adjusted:!1}}function ms({scrollRef:e,contentRef:n,bottomChromeRef:r,entries:s,entriesRef:a,instanceId:o,hasMore:i,shouldScrollToBottom:c,onScrollToBottomHandled:d,onLoadMore:u,bottomChromeHeight:f,bottomSafeGap:m}){const g=l.useRef(!0),[v,N]=l.useState(!1),T=l.useRef(!1),R=l.useRef(!1),b=l.useRef(null),h=l.useRef(null),C=l.useRef(!1),j=l.useRef(null),O=l.useRef(s.length),k=l.useRef(void 0),_=l.useRef(0),y=l.useRef(null),w=l.useCallback(E=>{b.current!=null&&cancelAnimationFrame(b.current),R.current=!0,T.current=!0,E(),b.current=requestAnimationFrame(()=>{R.current=!1,T.current=!1,b.current=null})},[]),M=l.useCallback(()=>{var x;const E=y.current;E&&(E.rafId!=null&&cancelAnimationFrame(E.rafId),(x=E.observer)==null||x.disconnect(),y.current=null)},[]),P=l.useCallback(({force:E=!1}={})=>{const x=e.current,p=n.current,S=r.current;if(!x||!p||!S)return!1;const I=p.querySelectorAll(`[${he}]`),B=I[I.length-1],A=B==null?void 0:B.getBoundingClientRect(),H=S.getBoundingClientRect(),oe=x.scrollHeight-Te(x.scrollTop)-x.clientHeight,te=A?A.bottom-H.top:0;return is({isAtBottom:g.current,isLoadingMore:C.current,distanceToBottom:oe,overlap:te,force:E,scrollToBottom:()=>{M(),w(()=>{x.scrollTop=x.scrollHeight}),N(!1)}})},[e,n,r,w,M]),$=l.useCallback(()=>{var E;(E=h.current)==null||E.call(h),h.current=null},[]),D=l.useCallback(()=>{$();const E=performance.now();let x=null,p=!1;const S=(I=performance.now())=>{x=null,!(p||I-E>=ps)&&(!g.current||C.current||(P(),x=requestAnimationFrame(S)))};S(),h.current=()=>{p=!0,x!=null&&(cancelAnimationFrame(x),x=null)}},[P,$]);l.useLayoutEffect(()=>{C.current||P()},[f,m,P]),l.useLayoutEffect(()=>{const E=n.current;if(!E||typeof ResizeObserver>"u")return;const x=new ResizeObserver(()=>{P()});return x.observe(E),()=>x.disconnect()},[o,n,P]);const F=l.useCallback(()=>{const E=e.current,x=y.current;if(!E||!x)return;let p={mode:"none"};w(()=>{p=yt(E,x.snapshot,{allowDiffFallback:!1})}),p.mode==="none"&&M()},[e,w,M]),W=l.useCallback(()=>{const E=y.current;!E||E.rafId!=null||(E.rafId=requestAnimationFrame(()=>{const x=y.current;!x||x!==E||(x.rafId=null,F())}))},[F]),Y=l.useCallback(E=>{const x=e.current,p=n.current;if(!x||!p||!E.entryKey)return;M();const S={snapshot:E,observer:null,rafId:null,warmupFrame:0};if(y.current=S,typeof ResizeObserver<"u"){const B=new ResizeObserver(()=>{W()});B.observe(p);const A=Ut(x,E.entryKey);A&&A!==p&&B.observe(A),S.observer=B}const I=()=>{const B=y.current;!B||B!==S||B.warmupFrame>=us||(B.rafId=requestAnimationFrame(()=>{const A=y.current;!A||A!==S||(A.rafId=null,A.warmupFrame+=1,F(),I())}))};I()},[e,n,F,W,M]);l.useLayoutEffect(()=>(C.current=!1,j.current=null,k.current=void 0,_.current=0,O.current=a.current.length,g.current=!0,N(!1),()=>{$(),M(),b.current!=null&&(cancelAnimationFrame(b.current),b.current=null),R.current=!1,T.current=!1,C.current=!1,j.current=null,k.current=void 0,_.current=0}),[o,a,M,$]),l.useLayoutEffect(()=>{e.current&&(C.current||P())},[s,o,e,P]),l.useLayoutEffect(()=>{if(!c)return;if(!e.current){d();return}g.current=!0,P({force:!0}),N(!1),d()},[c,s,e,P,d]),l.useLayoutEffect(()=>{const E=e.current;if(C.current&&E&&s.length>O.current){const x=s[0]?Ue(s[0]):void 0;if(!k.current||x!==k.current){const S=j.current;let I={mode:"none"};S&&w(()=>{I=yt(E,S,{allowDiffFallback:!0})}),_.current=performance.now()+ds,S&&S.entryKey&&I.mode!=="none"&&Y(S),C.current=!1,j.current=null,k.current=void 0}else j.current&&(j.current={...j.current,fallbackScrollHeight:E.scrollHeight})}C.current&&!i&&(C.current=!1,j.current=null,k.current=void 0),O.current=s.length},[s,i,o,e,w,Y]);const Z=l.useCallback(()=>{const E=e.current;if(!E)return;const x=E.scrollTop,p=Te(x),S=performance.now()<_.current;if(x<0||T.current||R.current)return;y.current&&M();const I=E.scrollHeight-p-E.clientHeight<60;if(g.current=I,I||$(),N(!I),cs({rawScrollTop:x,hasMore:i,canLoadMore:!!u,isLoadingMore:C.current,isSuppressed:S})&&u){$(),M(),C.current=!0;const A=a.current,H=fs(E);j.current=H,k.current=A[0]?Ue(A[0]):void 0,u()}},[e,a,i,u,M,$]),G=l.useCallback(()=>{e.current&&(M(),w(()=>{e.current.scrollTop=e.current.scrollHeight}),g.current=!0,N(!1))},[e,w,M]);return{handleScroll:Z,scrollToBottom:G,showScrollBtn:v,startBottomFollow:D}}function hs(e,n,r,s){const{t:a}=z(),o=Se(u=>u.setDraft),{canReEdit:i,userContent:c}=l.useMemo(()=>{var f,m;if(r!=="idle"||n.length===0)return{canReEdit:!1,userContent:null};const u=n[n.length-1];if(u.type!=="message"||((f=u.message)==null?void 0:f.role)!=="assistant"||u.message.stopReason!=="aborted")return{canReEdit:!1,userContent:null};for(let g=n.length-2;g>=0;g--){const v=n[g];if(v.type==="message"&&((m=v.message)==null?void 0:m.role)==="user")return{canReEdit:!0,userContent:v.message.content}}return{canReEdit:!1,userContent:null}},[n,r]),d=l.useCallback(()=>{if(!i||c==null)return;const u=Se.getState().drafts.get(e)??et;if(u.text.trim()||u.images.length>0){ee(a("reEdit.draftNotEmpty"),"warning");return}const f=gs(c);Ge.flushSync(()=>{o(e,f)}),s==null||s()},[i,c,e,o,a,s]);return i?d:void 0}function gs(e){let n="";const r=[];if(typeof e=="string")n=e;else if(Array.isArray(e)){const s=[];for(const a of e)if(a.type==="text")s.push(a.text);else if(a.type==="image"){const o=a,i=Dt();r.push({id:i,data:o.data,mimeType:o.mimeType,previewUrl:`data:${o.mimeType};base64,${o.data}`})}n=s.join("")}return{text:n,images:r}}function bs(){const{t:e}=z(),{id:n}=wn(),r=n,s=K(L=>L.send),a=re(Un(r)),o=Se(L=>L.drafts.get(r)??et),i=Se(L=>L.setDraft),{entries:c,isStreaming:d,loadState:u,errorMessage:f,hasMore:m,sessionList:g,sessionListLoading:v,sessionHasMore:N,sessionTotal:T,loadMore:R,requestSessionList:b}=rs(r,a),h=l.useCallback(L=>{i(r,L)},[r,i]),C=l.useCallback((L,U)=>{s({type:"prompt",payload:{instanceId:r,message:L,images:U!=null&&U.length?U:void 0}}),i(r,{text:"",images:[]})},[r,s,i]),j=l.useCallback(()=>{s({type:"abort",payload:{instanceId:r}})},[r,s]),O=l.useCallback((L,U)=>{s({type:"set_model",payload:{instanceId:r,provider:L,id:U}})},[r,s]),k=l.useCallback(L=>{s({type:"set_thinking_level",payload:{instanceId:r,level:L}})},[r,s]),_=l.useCallback(()=>{b({offset:0})},[b]),y=l.useCallback((L,U)=>{b({offset:L,filter:U})},[b]),w=l.useCallback(L=>{b({offset:0,filter:L||void 0})},[b]),M=l.useCallback(()=>{s({type:"new_session",payload:{instanceId:r}})},[r,s]),P=l.useCallback(L=>{s({type:"switch_session",payload:{instanceId:r,path:L}})},[r,s]),$=l.useCallback(L=>{s({type:"compact",payload:{instanceId:r,customInstructions:L}})},[r,s]),D=l.useRef(null),F=hs(r,c,a==null?void 0:a.status,()=>{var L;(L=D.current)==null||L.focus()}),W=l.useRef(null),Y=l.useRef(null),Z=l.useRef(null),G=l.useRef(null),E=l.useRef(null),[x,p]=l.useState(null),S=l.useRef(c);S.current=c;const I=u==="refreshing",B=ls(a==null?void 0:a.status),A=c.length>0&&c[c.length-1].type==="compaction",H=ue(a==null?void 0:a.status),[oe,te]=l.useState(!1),Yt=l.useCallback(()=>{te(!1)},[]),rt=l.useRef(u);l.useLayoutEffect(()=>{rt.current==="refreshing"&&u==="idle"&&te(!0),rt.current=u},[u]);const[Gt,Vt]=l.useState(64),[st,Jt]=l.useState(96),[at,Xt]=l.useState(12),Ie=as({topChromeHeight:Gt,bottomChromeHeight:st,bottomSafeGap:at});l.useLayoutEffect(()=>{const L=(Ae,nn)=>{if(!Ae)return()=>{};const lt=()=>{nn(Math.ceil(Ae.getBoundingClientRect().height))};if(lt(),typeof ResizeObserver>"u")return()=>{};const it=new ResizeObserver(lt);return it.observe(Ae),()=>it.disconnect()},U=L(Z.current,Vt),ge=L(G.current,Jt),be=L(E.current,Xt);return()=>{U(),ge(),be()}},[r]);const{handleScroll:Zt,scrollToBottom:Qt,showScrollBtn:en,startBottomFollow:tn}=ms({scrollRef:W,contentRef:Y,bottomChromeRef:G,entries:c,entriesRef:S,instanceId:r,hasMore:m,shouldScrollToBottom:oe,onScrollToBottomHandled:Yt,onLoadMore:R,bottomChromeHeight:st,bottomSafeGap:at}),ot={title:(a==null?void 0:a.cwd.split("/").pop())||(a==null?void 0:a.cwd)||"",cwd:a==null?void 0:a.cwd,homedir:a==null?void 0:a.homedir,gitBranch:a==null?void 0:a.gitBranch,actions:t.jsx(Or,{sessions:g,loading:v,hasMore:N,total:T,disabled:ue(a==null?void 0:a.status),onOpen:_,onNewSession:M,onSwitchSession:P,onLoadMore:y,onFilterChange:w})};return t.jsxs("div",{className:"relative flex-1 min-w-0 overflow-hidden",children:[t.jsxs("main",{className:"absolute inset-0 flex min-h-0 flex-col overflow-hidden",children:[t.jsx("div",{className:"pointer-events-none absolute left-0 right-0 top-0 z-20 px-3 pt-3 md:px-4 md:pt-4",children:t.jsxs("div",{ref:Z,className:"glass-panel pointer-events-auto mx-auto w-full max-w-[920px] px-3 py-2 md:px-4 md:py-2.5",role:"region","aria-label":"Instance info",children:[t.jsx("div",{className:"hidden md:flex",children:t.jsx(ht,{...ot})}),t.jsx(Ft,{children:t.jsx(ht,{...ot})})]})}),t.jsx("div",{ref:W,onScroll:Zt,style:{overflowAnchor:"none"},"aria-busy":I,className:"absolute bottom-[var(--bottom-safe-gap)] left-0 right-0 top-6 overflow-y-auto scrollbar-auto px-3 md:bottom-0 md:top-7 md:px-4",children:t.jsxs("div",{ref:Y,style:{paddingTop:Ie.paddingTop,paddingBottom:Ie.paddingBottom},className:"mx-auto max-w-[920px] space-y-2",children:[u==="loadingMore"&&t.jsx("div",{className:"text-center text-[var(--label-tertiary)] text-[11px] py-2 select-none",children:"Loading earlier messages..."}),I?t.jsx(vs,{}):u==="error"?t.jsxs("div",{className:"mx-auto mt-8 max-w-[520px] rounded-[12px] border border-[var(--separator)] bg-[var(--fill-card)] px-4 py-3 text-center",children:[t.jsx("div",{className:"text-[13px] text-[var(--label-primary)] select-none",children:"Failed to load conversation"}),f&&t.jsx("div",{className:"mt-1 text-[12px] text-[var(--label-secondary)] break-words select-text",children:f})]}):c.length===0&&!m?t.jsx("div",{className:"text-center text-[var(--label-tertiary)] text-[12px] pt-8 select-none",children:"No messages yet"}):c.map((L,U)=>{const ge=Ue(L),be=U===c.length-1;return t.jsx("div",{"data-entry-key":ge,children:t.jsx(Nr,{entry:L,entries:c,isLast:be,isStreaming:d,onReEdit:be?F:void 0})},ge)})]})}),en&&t.jsx("div",{style:{bottom:Ie.scrollButtonBottom},className:"absolute left-1/2 z-30 -translate-x-1/2",children:t.jsx("button",{onClick:Qt,className:"select-none w-9 h-9 rounded-full bg-[var(--btn-solid)] border border-[var(--separator)] text-[var(--label-secondary)] flex items-center justify-center hover:bg-[var(--btn-solid-hover)] active:scale-95 transition-all shadow-[0_4px_20px_rgba(0,0,0,0.12)]",title:e("eventStream.scrollToBottom"),children:t.jsx(Nn,{size:16})})}),t.jsx("div",{ref:G,className:"pointer-events-none absolute bottom-0 left-0 right-0 z-20 px-3 pb-0 md:px-4",children:t.jsxs("div",{className:"pointer-events-auto mx-auto w-full max-w-[920px]",children:[t.jsx(Qr,{ref:D,instance:a,draft:o,onDraftChange:h,onSendMessage:C,onAbort:j,onSetModel:O,onSetThinkingLevel:k,onCompact:$,buttonMode:B,showCompactButton:!A,compactDisabled:H,onImageLightbox:p,startBottomFollow:tn}),t.jsx("div",{ref:E,className:"h-[var(--bottom-safe-gap)] md:h-0","aria-hidden":"true"})]})})]}),x&&t.jsx(Bt,{src:x,onClose:()=>p(null)})]})}function vs(){return t.jsx("div",{className:"space-y-3 pt-3 select-none","aria-label":"Loading conversation",children:[0,1,2,3].map(e=>t.jsxs("div",{className:"space-y-1.5 animate-pulse",children:[t.jsx("div",{className:"h-3 w-20 rounded-full bg-[var(--fill-tertiary)]"}),t.jsxs("div",{className:"max-w-[680px] space-y-1.5 rounded-[10px] border border-[var(--separator)] bg-[var(--fill-card)] p-3",children:[t.jsx("div",{className:"h-3 w-[82%] rounded-full bg-[var(--fill-secondary)]"}),t.jsx("div",{className:"h-3 w-[64%] rounded-full bg-[var(--fill-tertiary)]"})]})]},e))})}function ys(){const{t:e}=z(),n=Qe();return t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"text-center select-none",children:[t.jsx("img",{src:n,alt:"Paimon",className:"w-16 h-16 mx-auto mb-4 opacity-80"}),t.jsx("div",{className:"text-[14px] text-[var(--label-tertiary)] tracking-wide",children:e("eventStream.tagline")})]})})}function js(){return t.jsx("div",{className:"relative flex-1 min-w-0 overflow-hidden flex flex-col",children:t.jsx(kn,{})})}const ws={common:{cancel:"取消",confirm:"确认",loading:"加载中…",online:"在线",offline:"离线"},login:{subtitle:"输入 Access Token 以连接",placeholder:"Access Token",invalidToken:"Token 无效,请检查后重试。",connect:"连接",verifying:"验证中…",tokenHint:"Token 可在 <1>~/.paimon/hub.json</1> 中找到"},sidebar:{newInstance:"新建实例",machine_one:"{{count}} 台机器",machine_other:"{{count}} 台机器",instance_one:"{{count}} 个实例",instance_other:"{{count}} 个实例",noInstances:"暂无 pi 实例连接",settings:"设置",shutdown:"退出实例",shutdownBusy:"实例正在执行中,请等待完成后再退出",statusStreaming:"生成中",statusCompacting:"压缩中",statusIdle:"空闲"},eventStream:{tagline:"守望 · 交互 · 掌控",sendPlaceholder:"发送消息…",scrollToBottom:"滚到底部",stop:"停止",send:"发送",attachImage:"添加图片",imageProcessFailed:"图片处理失败,请检查图片格式",statusRunning:"执行中",statusCompacting:"压缩中",statusOnline:"在线",compactContext:"压缩上下文",instanceNotFound:"实例不存在"},compact:{title:"压缩上下文",description:"压缩将总结旧的对话内容以释放上下文空间。可选填自定义提示词来指定压缩时关注的方向。",placeholder:"例如:重点保留关于数据库设计的讨论…",start:"开始压缩"},settings:{title:"设置",appearance:"外观",theme:"主题",themeLight:"浅色",themeDark:"深色",themeSystem:"系统",background:"背景",bgMist:"雾",bgAurora:"极光",bgEmber:"余烬",language:"语言",langZhCN:"简体中文",langEn:"English"},notification:{title:"通知",label:"任务完成通知",on:"开启",off:"关闭",denied:"通知权限已被浏览器拒绝,请在浏览器设置中允许",taskComplete:"✅ {{name}} 任务完成"},newInstance:{title:"新建实例",edgeNode:"Edge 节点",noEdges:"没有可用的 Edge 节点",workingDir:"工作目录",pathPlaceholder:"/path/to/your/project",create:"创建",creating:"创建中…",truncatedHint:"输入更多字符以缩小范围…",fetchEdgeError:"获取 Edge 列表失败",noEdgeSelected:"未选择 Edge 节点",requestTimeout:"请求超时",networkError:"网络错误",requestFailed:"请求失败 (HTTP {{status}})"},session:{title:"Sessions",new:"新建",filter:"筛选…",noMatch:"无匹配的 Session",noPrevious:"暂无历史 Session",empty:"空 Session",messageCount_one:"{{count}} 条消息",messageCount_other:"{{count}} 条消息",timeJustNow:"刚刚"},entries:{contextCompacted:"上下文已压缩",branchSummary:"分支摘要",thinking:"思考",thinkingStreaming:"思考中...",running:"执行中...",aborted:"已终止",copied:"已复制",copy:"复制",result:"结果",params:"参数"},reEdit:{button:"重新编辑",draftNotEmpty:"输入框已有内容,请先清空"},error:{title:"错误详情",message:"错误信息",type:"错误类型",requestId:"请求 ID",action:{compact:"压缩失败:{{message}}"}}},Ns={common:{cancel:"Cancel",confirm:"Confirm",loading:"Loading…",online:"Online",offline:"Offline"},login:{subtitle:"Enter access token to connect",placeholder:"Access Token",invalidToken:"Invalid token. Please check and try again.",connect:"Connect",verifying:"Verifying…",tokenHint:"Find your token in <1>~/.paimon/hub.json</1>"},sidebar:{newInstance:"New instance",machine_one:"{{count}} machine",machine_other:"{{count}} machines",instance_one:"{{count}} instance",instance_other:"{{count}} instances",noInstances:"No pi instances connected",settings:"Settings",shutdown:"Shutdown instance",shutdownBusy:"Instance is running, please wait before shutting down",statusStreaming:"Streaming",statusCompacting:"Compacting",statusIdle:"Idle"},eventStream:{tagline:"Watch · Interact · Control",sendPlaceholder:"Send a message...",scrollToBottom:"Scroll to bottom",stop:"Stop",send:"Send",attachImage:"Attach image",imageProcessFailed:"Image processing failed, please check the format",statusRunning:"Running",statusCompacting:"Compacting",statusOnline:"Online",compactContext:"Compact context",instanceNotFound:"Instance not found"},compact:{title:"Compact Context",description:"Compaction summarizes older conversation to free up context space. Optionally provide custom instructions to guide what to focus on.",placeholder:"e.g. Keep the discussion about database design…",start:"Start compaction"},settings:{title:"Settings",appearance:"Appearance",theme:"Theme",themeLight:"Light",themeDark:"Dark",themeSystem:"System",background:"Background",bgMist:"Mist",bgAurora:"Aurora",bgEmber:"Ember",language:"Language",langZhCN:"简体中文",langEn:"English"},notification:{title:"Notification",label:"Task Completion Notification",on:"On",off:"Off",denied:"Notification permission denied. Please allow in browser settings",taskComplete:"✅ {{name}} task completed"},newInstance:{title:"New Instance",edgeNode:"Edge Node",noEdges:"No available Edge nodes",workingDir:"Working Directory",pathPlaceholder:"/path/to/your/project",create:"Create",creating:"Creating…",truncatedHint:"Type more to narrow results…",fetchEdgeError:"Failed to fetch edge list",noEdgeSelected:"No edge selected",requestTimeout:"Request timed out",networkError:"Network error",requestFailed:"Request failed (HTTP {{status}})"},session:{title:"Sessions",new:"New",filter:"Filter…",noMatch:"No matching sessions",noPrevious:"No previous sessions",empty:"Empty session",messageCount_one:"{{count}} message",messageCount_other:"{{count}} messages",timeJustNow:"just now"},entries:{contextCompacted:"Context compacted",branchSummary:"Branch summary",thinking:"Thinking",thinkingStreaming:"Thinking...",running:"Running...",aborted:"Aborted",copied:"Copied",copy:"Copy",result:"Result",params:"Parameters"},reEdit:{button:"Edit",draftNotEmpty:"Input is not empty, please clear first"},error:{title:"Error Details",message:"Error message",type:"Error type",requestId:"Request ID",action:{compact:"Compaction failed: {{message}}"}}},Wt="paimon:language";function ks(){const e=localStorage.getItem(Wt);return e==="zh-CN"||e==="en"?e:"zh-CN"}function Ss(e){localStorage.setItem(Wt,e),Ve.changeLanguage(e)}Ve.use(Sn).init({resources:{"zh-CN":{translation:ws},en:{translation:Ns}},lng:ks(),fallbackLng:"zh-CN",interpolation:{escapeValue:!1}});function Fe({options:e,value:n,onChange:r}){return t.jsx("div",{className:"flex rounded-[8px] bg-[var(--fill-secondary)] p-[2px] select-none",children:e.map(s=>t.jsx("button",{onClick:()=>r(s.value),className:`px-3 py-1.5 rounded-[6px] text-[13px] leading-[18px] transition-all ${n===s.value?"bg-[var(--panel-bg)] text-[var(--label-primary)] font-semibold shadow-sm backdrop-blur-sm":"text-[var(--label-secondary)] font-normal hover:text-[var(--label-primary)]"}`,children:s.label},s.value))})}function ye({label:e,children:n,showSeparator:r=!0}){return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 select-none",children:[t.jsx("span",{className:"text-[14px] leading-[20px] font-semibold text-[var(--label-primary)]",children:e}),n]}),r&&t.jsx("div",{className:"ml-4 border-b border-[var(--separator)]"})]})}function Cs({value:e,onChange:n,options:r}){return t.jsx("div",{className:"flex items-center gap-3 select-none",children:r.map(s=>t.jsxs("button",{onClick:()=>n(s.value),className:"flex flex-col items-center gap-1",children:[t.jsx("div",{className:`w-7 h-7 rounded-full transition-all ${e===s.value?"ring-2 ring-[var(--color-accent)] ring-offset-1":"hover:scale-110"}`,style:{background:`conic-gradient(${s.colors.join(", ")})`}}),t.jsx("span",{className:`text-[12px] leading-[16px] ${e===s.value?"text-[var(--label-primary)] font-semibold":"text-[var(--label-secondary)] font-normal"}`,children:s.label})]},s.value))})}function Es(){const{t:e,i18n:n}=z(),[r,s]=Gn(),[a,o]=_t(),[i,c]=Jn(),d=[{value:"light",label:e("settings.themeLight")},{value:"dark",label:e("settings.themeDark")},{value:"system",label:e("settings.themeSystem")}],u=[{value:"mist",label:e("settings.bgMist"),colors:["#e8f0fe","#f5e6f0","#e6f0f5","#f0f5e6"]},{value:"aurora",label:e("settings.bgAurora"),colors:["#a8d8ea","#aa96da","#8fd3c4","#c4a8d8"]},{value:"ember",label:e("settings.bgEmber"),colors:["#f8d4b0","#f0b0c0","#f8e0a0","#e8c0d0"]}],f=[{value:"zh-CN",label:e("settings.langZhCN")},{value:"en",label:e("settings.langEn")}],m=[{value:"on",label:e("notification.on")},{value:"off",label:e("notification.off")}];return t.jsx("div",{className:"flex-1 flex items-start justify-center p-4 md:p-6 overflow-y-auto scrollbar-auto",children:t.jsxs("div",{className:"w-full max-w-[480px]",children:[t.jsx(Ft,{title:e("settings.title")}),t.jsx("h1",{className:"hidden md:block text-[22px] font-semibold text-[var(--label-primary)] mb-6 px-4 select-none",children:e("settings.title")}),t.jsx("div",{className:"text-[14px] leading-[20px] font-semibold text-[var(--label-primary)] mb-2 px-4 select-none",children:e("settings.appearance")}),t.jsxs("section",{className:"glass-panel overflow-hidden",children:[t.jsx(ye,{label:e("settings.theme"),children:t.jsx(Fe,{options:d,value:r,onChange:s})}),t.jsx(ye,{label:e("settings.background"),showSeparator:!1,children:t.jsx(Cs,{value:a,onChange:o,options:u})})]}),t.jsx("div",{className:"text-[14px] leading-[20px] font-semibold text-[var(--label-primary)] mb-2 mt-6 px-4 select-none",children:e("settings.language")}),t.jsx("section",{className:"glass-panel overflow-hidden",children:t.jsx(ye,{label:e("settings.language"),showSeparator:!1,children:t.jsx(Fe,{options:f,value:n.language,onChange:Ss})})}),Ot&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-[14px] leading-[20px] font-semibold text-[var(--label-primary)] mb-2 mt-6 px-4 select-none",children:e("notification.title")}),t.jsx("section",{className:"glass-panel overflow-hidden",children:t.jsx(ye,{label:e("notification.label"),showSeparator:!1,children:t.jsx(Fe,{options:m,value:i?"on":"off",onChange:async g=>{g==="on"?await Notification.requestPermission()==="granted"?c(!0):ee(e("notification.denied"),"warning"):c(!1)}})})})]})]})})}async function Ye(e,n){const r=Tt(),s=new Headers(n==null?void 0:n.headers);r&&s.set("Authorization",`Bearer ${r}`);const a=await fetch(e,{...n,headers:s});return a.status===401&&(Rt(),window.location.reload()),a}function Ts({value:e,onChange:n,edgeId:r,disabled:s=!1,autoFocus:a=!1,onSubmit:o}){const{t:i}=z(),[c,d]=l.useState([]),[u,f]=l.useState(!1),[m,g]=l.useState(!1),[v,N]=l.useState(-1),[T,R]=l.useState(!1),b=l.useRef(null),h=l.useRef(null),C=l.useRef(null),j=l.useRef(null);l.useEffect(()=>()=>{var y;(y=C.current)==null||y.abort()},[]),l.useEffect(()=>{var y;a&&((y=b.current)==null||y.focus())},[a]);const O=l.useCallback(async(y,w)=>{C.current&&C.current.abort();const M=new AbortController;C.current=M,g(!0);try{const $=await(await Ye(`/api/edges/${encodeURIComponent(y)}/browse?path=${encodeURIComponent(w)}`,{signal:M.signal})).json();if(M.signal.aborted)return;$.error?(d([]),f(!1),R(!1)):(d($.entries??[]),f($.truncated??!1),R(($.entries??[]).length>0||$.truncated)),N(-1)}catch{M.signal.aborted||(d([]),R(!1))}finally{M.signal.aborted||g(!1)}},[]);l.useEffect(()=>{if(!r||!e||!e.startsWith("/")){d([]),R(!1);return}return j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{O(r,e)},250),()=>{j.current&&clearTimeout(j.current)}},[e,r,O]);const k=l.useCallback(y=>{var $;const P=(e.endsWith("/")?e:e.substring(0,e.lastIndexOf("/")+1))+y.name+"/";n(P),N(-1),($=b.current)==null||$.focus()},[e,n]),_=l.useCallback(y=>{if(T&&c.length>0){if(y.key==="ArrowDown"){y.preventDefault(),N(w=>w<c.length-1?w+1:0);return}if(y.key==="ArrowUp"){y.preventDefault(),N(w=>w>0?w-1:c.length-1);return}if(y.key==="Tab"){y.preventDefault(),v>=0&&v<c.length?k(c[v]):c.length===1&&k(c[0]);return}if(y.key==="Enter"&&v>=0&&v<c.length){y.preventDefault(),k(c[v]);return}if(y.key==="Escape"){y.preventDefault(),R(!1),N(-1);return}}y.key==="Enter"&&(y.preventDefault(),o==null||o())},[T,c,v,k,o]);return l.useEffect(()=>{if(v<0||!h.current)return;const w=h.current.children[v];w==null||w.scrollIntoView({block:"nearest"})},[v]),l.useEffect(()=>{d([]),R(!1),N(-1)},[r]),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:b,type:"text",value:e,onChange:y=>n(y.target.value),onKeyDown:_,onFocus:()=>{c.length>0&&R(!0)},onBlur:()=>{setTimeout(()=>R(!1),150)},placeholder:i("newInstance.pathPlaceholder"),disabled:s,spellCheck:!1,autoComplete:"off",className:"w-full rounded-[10px] px-3 py-2 bg-[var(--fill-tertiary)] border border-[var(--separator)] text-[14px] leading-[20px] text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] outline-none focus:border-[var(--color-accent)] transition-colors disabled:opacity-50 pr-8"}),m&&t.jsx("div",{className:"absolute right-2.5 top-1/2 -translate-y-1/2",children:t.jsx(de,{size:14,className:"animate-spin text-[var(--label-tertiary)]"})})]}),T&&t.jsxs("div",{ref:h,className:"max-h-[200px] overflow-y-auto rounded-[10px] border border-[var(--separator)] bg-[var(--fill-quaternary)]",children:[c.map((y,w)=>t.jsxs("button",{type:"button",onMouseDown:M=>{M.preventDefault(),k(y)},onMouseEnter:()=>N(w),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] transition-colors ${w===v?"bg-[var(--fill-secondary)]":"hover:bg-[var(--fill-tertiary)]"}`,children:[t.jsx(St,{size:14,className:"shrink-0 text-[var(--label-tertiary)]"}),t.jsx("span",{className:"text-[var(--label-primary)] truncate",children:y.name})]},y.name)),u&&t.jsx("div",{className:"px-3 py-1.5 text-[12px] text-[var(--label-tertiary)] border-t border-[var(--separator)]",children:i("newInstance.truncatedHint")})]})]})}function Rs({onClose:e,onCreated:n}){const{t:r}=z(),[s,a]=l.useState(""),[o,i]=l.useState([]),[c,d]=l.useState(""),[u,f]=l.useState(!0),[m,g]=l.useState(!1),[v,N]=l.useState(null);l.useEffect(()=>{Ye("/api/edges").then(b=>b.json()).then(b=>{if(i(b.edges),b.edges.length>0){d(b.edges[0].edgeId);const h=b.edges[0].homedir;if(h){const C=h.endsWith("/")?h:h+"/";a(C)}}f(!1)}).catch(()=>{f(!1),N(r("newInstance.fetchEdgeError"))})},[]);const T=l.useCallback(b=>{d(b);const h=o.find(C=>C.edgeId===b);if(h!=null&&h.homedir){const C=h.homedir.endsWith("/")?h.homedir:h.homedir+"/";a(C)}},[o]),R=l.useCallback(async()=>{const b=s.trim();if(!(!b||m)){if(!c){N(r("newInstance.noEdgeSelected"));return}g(!0),N(null);try{const h=await Ye("/api/instances",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:b,edgeId:c}),signal:AbortSignal.timeout(2e4)}),C=await h.json();if(!h.ok||!C.instanceId){N(C.error||r("newInstance.requestFailed",{status:h.status})),g(!1);return}n(C.instanceId)}catch(h){const C=h.name==="TimeoutError"?r("newInstance.requestTimeout"):h.message||r("newInstance.networkError");N(C),g(!1)}}},[s,m,c,n]);return t.jsx(X,{title:t.jsxs(t.Fragment,{children:[t.jsx(Cn,{size:16}),t.jsx("span",{children:r("newInstance.title")})]}),onClose:e,children:t.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"text-[13px] text-[var(--label-secondary)]",children:r("newInstance.edgeNode")}),u?t.jsx("div",{className:"text-[13px] text-[var(--label-tertiary)]",children:r("common.loading")}):o.length===0?t.jsx("div",{className:"text-[12px] text-[#ff4245]",children:r("newInstance.noEdges")}):o.length===1?t.jsxs("div",{className:"text-[13px] text-[var(--label-primary)]",children:[o[0].hostname,t.jsxs("span",{className:"text-[var(--label-tertiary)] ml-1.5",children:["(",o[0].edgeId,")"]})]}):t.jsx("select",{value:c,onChange:b=>T(b.target.value),disabled:m,className:"w-full rounded-[10px] px-3 py-2 bg-[var(--fill-tertiary)] border border-[var(--separator)] text-[14px] text-[var(--label-primary)] outline-none focus:border-[var(--color-accent)] transition-colors disabled:opacity-50",children:o.map(b=>t.jsxs("option",{value:b.edgeId,children:[b.hostname," (",b.edgeId,")"]},b.edgeId))})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"text-[13px] text-[var(--label-secondary)]",children:r("newInstance.workingDir")}),t.jsx(Ts,{value:s,onChange:a,edgeId:c,disabled:m||u,autoFocus:!u,onSubmit:R})]}),v&&t.jsx("div",{className:"text-[12px] leading-[16px] text-[#ff4245] whitespace-pre-wrap break-words",children:v}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[t.jsx("button",{onClick:e,disabled:m,className:"px-3.5 py-1.5 rounded-[8px] text-[13px] text-[var(--label-secondary)] hover:bg-[var(--fill-tertiary)] transition-colors disabled:opacity-50",children:r("common.cancel")}),t.jsx("button",{onClick:R,disabled:m||!s.trim()||!c,className:"px-3.5 py-1.5 rounded-[8px] text-[13px] font-medium text-white bg-[var(--color-accent)] hover:opacity-90 transition-opacity disabled:opacity-40",children:r(m?"newInstance.creating":"newInstance.create")})]})]})})}function Ms({onLogin:e,error:n}){const{t:r}=z(),[s,a]=l.useState(""),[o,i]=l.useState(!1),[c,d]=l.useState(!1),u=Qe(),f=l.useCallback(async m=>{m.preventDefault();const g=s.trim();if(!(!g||o)){i(!0),d(!1);try{if((await fetch("/api/instances",{headers:{Authorization:`Bearer ${g}`}})).status===401){d(!0),i(!1);return}}catch{}i(!1),Bn(g),e(g)}},[s,o,e]);return t.jsx("div",{className:"fixed-viewport flex items-center justify-center p-4 overflow-y-auto",children:t.jsxs("form",{onSubmit:f,className:"glass-panel w-full max-w-[380px] p-8 flex flex-col items-center gap-6",children:[t.jsx("img",{src:u,alt:"Paimon",className:"w-16 h-16 select-none",draggable:!1}),t.jsxs("div",{className:"text-center",children:[t.jsx("h1",{className:"text-[17px] font-semibold text-[var(--label-primary)]",children:"Paimon"}),t.jsx("p",{className:"mt-1 text-[13px] text-[var(--label-secondary)]",children:r("login.subtitle")})]}),t.jsxs("div",{className:"w-full",children:[t.jsx("input",{type:"password",value:s,onChange:m=>a(m.target.value),placeholder:r("login.placeholder"),autoFocus:!0,className:`w-full h-9 px-3 rounded-[9px] text-[13px] bg-[var(--fill-primary)] text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] border outline-none transition-colors ${n||c?"border-red-500 focus:border-red-500":"border-[var(--separator)] focus:border-[var(--color-accent)]"}`}),(n||c)&&t.jsx("p",{className:"mt-2 text-[11px] text-red-500",children:r("login.invalidToken")})]}),t.jsx("button",{type:"submit",disabled:!s.trim()||o,className:"w-full h-9 rounded-[1000px] bg-[var(--color-accent)] text-white text-[13px] font-medium transition-opacity disabled:opacity-40 hover:opacity-90 active:opacity-80",children:r(o?"login.verifying":"login.connect")}),t.jsx("p",{className:"text-[11px] text-[var(--label-tertiary)] text-center leading-relaxed",children:t.jsx(En,{i18nKey:"login.tokenHint",components:{1:t.jsx("code",{className:"px-1 py-0.5 rounded bg-[var(--fill-secondary)] text-[var(--label-secondary)]"})}})})]})})}function Is(){const{pathname:e}=Rn(),n=e.match(/^\/instance\/(.+)$/);return n?n[1]:null}function As(){const{t:e}=z(),{authToken:n,authError:r,handleLogin:s,handleAuthError:a}=Fn(),o=K(j=>j.connect),i=K(j=>j.disconnect),c=K(j=>j.subscribe),d=K(j=>j.send),u=re(j=>j.instances),f=re(j=>j.instanceListReady),m=re(j=>j.handleMessage),g=Me();zn();const v=Is();l.useEffect(()=>(n?o(n,a):i(),()=>i()),[n,o,i,a]),er(),l.useEffect(()=>c(j=>{(j.type==="instance_list"||j.type==="instance_update")&&m(j)}),[c,m]);const N=l.useCallback(j=>{g(`/instance/${j}`)},[g]),T=l.useRef(new Set),R=l.useCallback(j=>{const O=re.getState().instances.find(k=>k.id===j);if(O&&ue(O.status)){ee(e("sidebar.shutdownBusy"),"warning");return}T.current.add(j),d({type:"shutdown",payload:{instanceId:j}})},[d,e]),[b,h]=l.useState(!1),C=l.useCallback(j=>{h(!1),g(`/instance/${j}`)},[g]);return l.useEffect(()=>{if(!f||!v)return;u.some(O=>O.id===v)||(T.current.has(v)?T.current.delete(v):ee(e("eventStream.instanceNotFound"),"error"),g("/"))},[f,v,u,g,e]),n?t.jsxs("div",{className:"h-[var(--app-viewport-height,100dvh)] w-screen animated-bg flex items-stretch p-2 gap-2 md:p-3 md:gap-3 overflow-hidden pb-[max(0.5rem,env(safe-area-inset-bottom))]",children:[t.jsx("div",{className:"hidden md:flex self-stretch",children:t.jsx(ut,{instances:u,selectedId:v,onSelect:N,onShutdown:R,onNewInstance:()=>h(!0)})}),t.jsx(Tn,{children:t.jsxs(ve,{element:t.jsx(js,{}),children:[t.jsx(ve,{path:"/settings",element:t.jsx(Es,{})}),t.jsx(ve,{path:"/instance/:id",element:t.jsx(bs,{})}),t.jsx(ve,{path:"*",element:t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 md:hidden min-w-0 flex flex-col",children:t.jsx(ut,{instances:u,selectedId:v,onSelect:N,onShutdown:R,onNewInstance:()=>h(!0)})}),t.jsx("div",{className:"hidden md:flex flex-1 min-w-0",children:t.jsx(ys,{})})]})})]})}),b&&t.jsx(Rs,{onClose:()=>h(!1),onCreated:C}),t.jsx(Gr,{})]}):t.jsx("div",{className:"h-[var(--app-viewport-height,100dvh)] w-screen animated-bg flex items-stretch overflow-hidden",children:t.jsx(Ms,{onLogin:s,error:r})})}rn.createRoot(document.getElementById("root")).render(t.jsx(Mn,{children:t.jsx(As,{})}));
|
package/web/index.html
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
background-color: #2e1a0a;
|
|
33
33
|
}
|
|
34
34
|
</style>
|
|
35
|
-
<script type="module" crossorigin src="/assets/index-
|
|
35
|
+
<script type="module" crossorigin src="/assets/index-BVDOOsji.js"></script>
|
|
36
36
|
<link rel="modulepreload" crossorigin href="/assets/framework-CY9iUjoF.js">
|
|
37
37
|
<link rel="modulepreload" crossorigin href="/assets/vendor-BXh3TPFq.js">
|
|
38
38
|
<link rel="modulepreload" crossorigin href="/assets/markdown-CbB-lJ6c.js">
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{a as l,j as t,r as Ge,c as rn}from"./framework-CY9iUjoF.js";import{s as Re,x as sn,E as Me,u as Ve,K as B,m as wt,C as pe,h as Nt,l as an,S as on,c as Je,X as Xe,L as de,g as kt,W as ln,p as cn,P as ct,T as dn,F as un,e as De,b as pn,i as St,G as xn,H as fn,r as mn,f as hn,k as gn,a as Ct,M as bn,I as vn,o as yn,A as jn,J as wn,d as Nn,O as kn,t as Sn,j as Cn,q as En,n as Tn,R as ve,D as Rn,B as Mn}from"./vendor-BXh3TPFq.js";import{d as Le,M as In,a as An,b as Ln,r as _n,e as Pn,s as On,c as $n,j as Et}from"./markdown-CbB-lJ6c.js";(function(){const n=document.createElement("link").relList;if(n&&n.supports&&n.supports("modulepreload"))return;for(const a of document.querySelectorAll('link[rel="modulepreload"]'))s(a);new MutationObserver(a=>{for(const o of a)if(o.type==="childList")for(const i of o.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&s(i)}).observe(document,{childList:!0,subtree:!0});function r(a){const o={};return a.integrity&&(o.integrity=a.integrity),a.referrerPolicy&&(o.referrerPolicy=a.referrerPolicy),a.crossOrigin==="use-credentials"?o.credentials="include":a.crossOrigin==="anonymous"?o.credentials="omit":o.credentials="same-origin",o}function s(a){if(a.ep)return;a.ep=!0;const o=r(a);fetch(a.href,o)}})();function zn(){l.useEffect(()=>{const e=window.visualViewport;if(!e)return;const n=document.documentElement;function r(){if(!e)return;window.innerHeight-e.height>1?(n.style.setProperty("--app-viewport-height",`${e.height}px`),window.scrollY>0&&window.scrollTo(0,0)):n.style.removeProperty("--app-viewport-height")}return e.addEventListener("resize",r),e.addEventListener("scroll",r),()=>{e.removeEventListener("resize",r),e.removeEventListener("scroll",r),n.style.removeProperty("--app-viewport-height")}},[])}const Ze="paimon:accessToken";function Tt(){return localStorage.getItem(Ze)}function Bn(e){localStorage.setItem(Ze,e)}function Rt(){localStorage.removeItem(Ze)}function Fn(){const[e,n]=l.useState(Tt()),[r,s]=l.useState(!1),a=l.useCallback(i=>{s(!1),n(i)},[]),o=l.useCallback(()=>{Rt(),n(null),s(!0)},[]);return{authToken:e,authError:r,handleLogin:a,handleAuthError:o}}const dt={BROWSER_HEARTBEAT_INTERVAL:3e4,BROWSER_PONG_TIMEOUT:1e4};let V=null;const He=new Set;let se=!1,je=null,Q=null,we=null,le=null,ne=null,ie,_e=!1;const Dn=3e3,Hn=3e3;function qn(e){for(const n of He)try{n(e)}catch(r){console.error("[useWebSocket] listener error:",r)}}function Kn(e){je=setInterval(()=>{e.readyState===WebSocket.OPEN&&(e.send(JSON.stringify({type:"ping"})),Q=setTimeout(()=>{e.close()},dt.BROWSER_PONG_TIMEOUT))},dt.BROWSER_HEARTBEAT_INTERVAL)}function Mt(){je&&(clearInterval(je),je=null),Q&&(clearTimeout(Q),Q=null)}function Pe(){se||(we=setTimeout(It,Hn))}function qe(){le&&(clearTimeout(le),le=null)}function It(){if(se||!ne)return;const r=`${`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/ws/browser`}?token=${encodeURIComponent(ne)}`;_e=!1;const s=new WebSocket(r);V=s,U.setState({connectionState:"connecting"}),le=setTimeout(()=>{le=null,s.readyState===WebSocket.CONNECTING&&s.close()},Dn),s.onopen=()=>{qe(),_e=!0,U.setState({connectionState:"connected"}),s.send(JSON.stringify({type:"list"})),Kn(s)},s.onmessage=a=>{try{const o=JSON.parse(a.data);if(o.type==="pong"){Q&&(clearTimeout(Q),Q=null);return}qn(o)}catch{}},s.onclose=a=>{if(qe(),U.setState({connectionState:"disconnected"}),V=null,Mt(),!se&&!_e){const o={};ne&&(o.Authorization=`Bearer ${ne}`),fetch("/api/instances",{headers:o}).then(i=>{i.status===401?ie==null||ie():Pe()}).catch(()=>{Pe()});return}se||Pe()},s.onerror=()=>{s.close()}}const U=Re((e,n)=>({connectionState:"idle",send:r=>{(V==null?void 0:V.readyState)===WebSocket.OPEN&&V.send(JSON.stringify(r))},subscribe:r=>(He.add(r),()=>{He.delete(r)}),connect:(r,s)=>{n().disconnect(),se=!1,ne=r,ie=s,It()},disconnect:()=>{se=!0,ne=null,ie=void 0,Mt(),qe(),we&&(clearTimeout(we),we=null),V&&(V.close(),V=null),e({connectionState:"idle"})}})),re=Re()(sn((e,n)=>({instances:[],instanceListReady:!1,handleMessage:r=>{switch(r.type){case"instance_list":e({instances:r.payload.instances,instanceListReady:!0});break;case"instance_update":{const{instance:s,action:a}=r.payload;a==="connected"?e(o=>({instances:o.instances.some(c=>c.id===s.id)?o.instances.map(c=>c.id===s.id?s:c):[...o.instances,s]})):a==="disconnected"?e(o=>({instances:o.instances.filter(i=>i.id!==s.id)})):a==="updated"&&e(o=>({instances:o.instances.map(i=>i.id===s.id?s:i)}));break}}}}),{name:"paimon:instances",partialize:e=>({instances:e.instances})}));function Un(e){return n=>e?n.instances.find(r=>r.id===e):void 0}const ae={appearance:"paimon:appearance",background:"paimon:background",notification:"paimon:notification"};function Ke(){const e=localStorage.getItem(ae.appearance);return e==="light"||e==="dark"||e==="system"?e:"system"}function At(){const e=localStorage.getItem(ae.background);return e==="mist"||e==="aurora"||e==="ember"?e:"mist"}function Wn(){return localStorage.getItem(ae.notification)==="true"}function Lt(e){return e==="system"?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e}function ke(e,n){const r=Lt(e);return document.documentElement.setAttribute("data-theme",r),document.documentElement.setAttribute("data-bg",n),r}const q=Re(e=>({appearance:Ke(),background:At(),resolvedTheme:Lt(Ke()),notification:Wn(),setAppearance:n=>{localStorage.setItem(ae.appearance,n);const r=ke(n,q.getState().background);e({appearance:n,resolvedTheme:r})},setBackground:n=>{localStorage.setItem(ae.background,n),ke(q.getState().appearance,n),e({background:n})},setNotification:n=>{localStorage.setItem(ae.notification,String(n)),e({notification:n})}})),Yn=window.matchMedia("(prefers-color-scheme: dark)");Yn.addEventListener("change",()=>{const{appearance:e,background:n}=q.getState();if(e==="system"){const r=ke(e,n);q.setState({resolvedTheme:r})}});function Gn(){const e=q(r=>r.appearance),n=q(r=>r.setAppearance);return[e,n]}function _t(){const e=q(r=>r.background),n=q(r=>r.setBackground);return[e,n]}function Vn(){return q(e=>e.resolvedTheme)}function Jn(){const e=q(r=>r.notification),n=q(r=>r.setNotification);return[e,n]}ke(Ke(),At());const Xn="/logos/mist/light/paimon-logo.png";function Pt(e,n){return!e||!n?Xn:`/logos/${e}/${n}/paimon-logo.png`}function Qe(){const[e]=_t(),n=Vn();return Pt(e,n)}function Zn(){const{background:e,resolvedTheme:n}=q.getState();return Pt(e,n)}const Ot="Notification"in window;function Qn(e,n){return(e==="streaming"||e==="compacting")&&n==="idle"}function er(){const e=U(o=>o.subscribe),n=Me(),r=l.useRef(n);l.useEffect(()=>{r.current=n},[n]);const s=l.useRef(q.getState().notification);l.useEffect(()=>q.subscribe(o=>{s.current=o.notification}),[]);const a=l.useRef(new Map);l.useEffect(()=>{const o=re.getState().instances;for(const i of o)a.current.set(i.id,i.status)},[]),l.useEffect(()=>e(o=>{if(o.type==="instance_list"){a.current.clear();for(const i of o.payload.instances)a.current.set(i.id,i.status);return}if(o.type==="instance_update"){const{action:i,instance:c}=o.payload;if(i==="disconnected"){a.current.delete(c.id);return}const d=a.current.get(c.id);a.current.set(c.id,c.status),i==="updated"&&s.current&&Qn(d,c.status)&&tr(c.id,c.cwd,r)}}),[e])}function tr(e,n,r){if(document.hasFocus()||!Ot||Notification.permission!=="granted")return;const s=n.split("/").pop()||n,a=new Notification("Paimon",{body:Ve.t("notification.taskComplete",{name:s}),icon:Zn()});a.onclick=()=>{var o;window.focus(),(o=r.current)==null||o.call(r,`/instance/${e}`),a.close()}}function nr(){const{t:e}=B(),n=U(a=>a.connectionState),r=l.useRef(!1);n==="disconnected"&&(r.current=!0),n==="connected"&&(r.current=!1);const s=r.current&&n!=="connected";return t.jsx("span",{className:`w-2 h-2 rounded-full transition-colors ${s?"bg-red-500":"bg-green-500"}`,title:e(s?"common.offline":"common.online")})}function rr(e,n,r=12){const{innerWidth:s,innerHeight:a}=window;let o=e.x,i=e.y;return o+n.width+r>s&&(o=s-n.width-r),i+n.height+r>a&&(i=a-n.height-r),o=Math.max(r,o),i=Math.max(r,i),{left:o,top:i}}function sr({position:e,onClose:n,children:r}){const s=l.useRef(null),a=l.useRef(n);a.current=n;const o=l.useCallback(()=>a.current(),[]);return l.useEffect(()=>{function i(u){s.current&&!s.current.contains(u.target)&&o()}function c(u){s.current&&!s.current.contains(u.target)&&o()}function d(u){u.key==="Escape"&&o()}return document.addEventListener("mousedown",i),document.addEventListener("contextmenu",c),document.addEventListener("keydown",d),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("contextmenu",c),document.removeEventListener("keydown",d)}},[o]),l.useEffect(()=>{if(s.current){const i=s.current.getBoundingClientRect(),c=rr(e,{width:i.width,height:i.height});s.current.style.left=`${c.left}px`,s.current.style.top=`${c.top}px`,s.current.style.opacity="1"}},[e]),Ge.createPortal(t.jsx("div",{ref:s,className:"glass-popover z-50 py-1.5 min-w-[160px]",style:{position:"fixed",left:e.x,top:e.y,opacity:0},children:r}),document.body)}function ar({icon:e,label:n,danger:r=!1,disabled:s=!1,onClick:a}){return t.jsxs("button",{onClick:o=>{o.stopPropagation(),s||a()},disabled:s,className:`w-full text-left flex items-center gap-2 px-3 py-1.5 text-[13px] leading-[18px] transition-colors ${s?"opacity-40 cursor-default":r?"text-red-500 hover:bg-[var(--fill-tertiary)]":"text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)]"}`,children:[e&&t.jsx("span",{className:"flex-shrink-0 w-4 h-4 flex items-center justify-center",children:e}),t.jsx("span",{children:n})]})}const or=500;function ut({instances:e,selectedId:n,onSelect:r,onShutdown:s,onNewInstance:a}){const{t:o}=B(),i=Me(),c=Qe(),[d,u]=l.useState(null),p=l.useRef(null),f=l.useRef(!1),h=l.useCallback((E,_)=>{E.preventDefault(),E.stopPropagation(),u({position:{x:E.clientX,y:E.clientY},instanceId:_})},[]),b=l.useCallback((E,_)=>{f.current=!1;const y=E.touches[0],w={x:y.clientX,y:y.clientY};p.current=setTimeout(()=>{var M;f.current=!0,(M=navigator.vibrate)==null||M.call(navigator,10),u({position:w,instanceId:_})},or)},[]),S=l.useCallback(()=>{p.current&&(clearTimeout(p.current),p.current=null)},[]),T=l.useCallback(()=>{p.current&&(clearTimeout(p.current),p.current=null)},[]),R=l.useCallback(()=>u(null),[]),[g,m]=l.useState(null),C=l.useRef(null);l.useEffect(()=>()=>{C.current&&clearTimeout(C.current)},[]);const j=l.useCallback(E=>{navigator.clipboard.writeText(E).then(()=>{m(E),C.current&&clearTimeout(C.current),C.current=setTimeout(()=>m(null),1500)},()=>{})},[]),z=l.useMemo(()=>{const E=new Map;for(const _ of e){const y=E.get(_.edgeId);y?y.push(_):E.set(_.edgeId,[_])}return[...E.entries()].sort((_,y)=>_[0].localeCompare(y[0]))},[e]);return t.jsxs("aside",{className:"glass-panel select-none w-[240px] md:w-[240px] flex-shrink-0 flex flex-col overflow-hidden max-md:w-full max-md:flex-1",children:[t.jsx("div",{className:"px-4 pt-4 pb-2",children:t.jsxs("div",{className:"grid grid-cols-[auto_1fr] grid-rows-[auto_auto] gap-x-2.5 items-center",children:[t.jsx("div",{className:"row-span-2",children:t.jsx("img",{src:c,alt:"Paimon",className:"h-[34px] aspect-square object-contain"})}),t.jsxs("div",{className:"flex items-center justify-between",children:[t.jsx("h1",{className:"text-[16px] leading-[20px] max-md:text-[18px] max-md:leading-[24px] font-semibold text-[var(--label-primary)]",children:"Paimon"}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("button",{onClick:a,title:o("sidebar.newInstance"),className:"select-none w-6 h-6 flex items-center justify-center rounded-full text-[var(--label-secondary)] hover:text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)] transition-all duration-150",children:t.jsx(wt,{size:16})}),t.jsx(nr,{})]})]}),t.jsxs("div",{className:"text-[12px] leading-[15px] max-md:text-[13px] max-md:leading-[18px] text-[var(--label-tertiary)]",children:[o("sidebar.machine",{count:z.length})," · ",o("sidebar.instance",{count:e.length})]})]})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-1 scrollbar-auto",children:e.length===0?t.jsx("div",{className:"px-3 py-8 text-center text-[var(--label-tertiary)] text-[12px] leading-[16px] max-md:text-[13px] max-md:leading-[18px]",children:o("sidebar.noInstances")}):t.jsx("div",{children:z.map(([E,_],y)=>t.jsxs("div",{children:[t.jsxs("button",{type:"button",onClick:()=>j(E),title:E,className:`flex items-center gap-1 px-2.5 pb-1 text-[11px] leading-[14px] font-semibold text-[var(--label-tertiary)] max-w-full max-md:px-3 rounded-[4px] hover:text-[var(--label-secondary)] transition-colors cursor-pointer ${y===0?"pt-1":"pt-3"}`,children:[t.jsx("span",{className:"truncate",children:E}),t.jsx("span",{className:"shrink-0 opacity-60",children:g===E?t.jsx(pe,{size:10,className:"text-green-500"}):t.jsx(Nt,{size:10})})]}),t.jsx("ul",{className:"space-y-0.5 max-md:space-y-1",children:_.map(w=>{var M;return t.jsx("li",{children:t.jsxs("button",{onClick:()=>{f.current||r(w.id)},onContextMenu:P=>h(P,w.id),onTouchStart:P=>b(P,w.id),onTouchEnd:S,onTouchMove:T,className:`w-full text-left px-2.5 py-1.5 max-md:px-3 max-md:py-2.5 rounded-[8px] transition-all duration-150 ${n===w.id?"bg-[rgba(0,145,255,0.08)] dark:bg-[rgba(0,145,255,0.12)]":"hover:bg-[var(--fill-tertiary)]"}`,children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:`w-1.5 h-1.5 max-md:w-2 max-md:h-2 rounded-full flex-shrink-0 transition-colors ${w.status==="streaming"?"bg-[var(--color-accent)] animate-pulse":w.status==="compacting"?"bg-amber-500 animate-pulse":"bg-green-500"}`,title:w.status==="streaming"?o("sidebar.statusStreaming"):w.status==="compacting"?o("sidebar.statusCompacting"):o("sidebar.statusIdle")}),t.jsx("span",{className:"text-[14px] leading-[18px] max-md:text-[15px] max-md:leading-[21px] text-[var(--label-primary)] truncate",children:w.cwd.split("/").pop()||w.cwd})]}),t.jsx("div",{className:"ml-3.5 text-[11px] leading-[14px] max-md:text-[12px] max-md:leading-[16px] text-[var(--label-secondary)] truncate mt-0.5",children:w.model.name||`${w.model.provider}/${w.model.id}`}),((M=w.contextUsage)==null?void 0:M.percent)!=null&&w.contextUsage.percent>0&&t.jsx("div",{className:"ml-3.5 mt-1.5 h-[3px] rounded-full bg-[var(--fill-quaternary)] overflow-hidden",children:t.jsx("div",{className:"h-full rounded-full transition-all duration-300",style:{width:`${Math.max(2,Math.min(100,w.contextUsage.percent))}%`,backgroundColor:w.contextUsage.percent>=90?"#ff4245":w.contextUsage.percent>=60?"#ff9230":"#30d158"}})})]})},w.id)})})]},E))})}),d&&t.jsx(sr,{position:d.position,onClose:R,children:t.jsx(ar,{icon:t.jsx(an,{size:14}),label:o("sidebar.shutdown"),danger:!0,onClick:()=>{s(d.instanceId),R()}})}),t.jsx("div",{className:"px-3 py-2 border-t border-[var(--separator)]",children:t.jsxs("button",{onClick:()=>i("/settings"),className:"flex items-center gap-2 w-full px-2.5 py-1.5 max-md:py-2.5 rounded-[8px] text-[var(--label-secondary)] hover:text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)] transition-all duration-150",children:[t.jsx(on,{size:15,className:"max-md:w-4 max-md:h-4"}),t.jsx("span",{className:"text-[13px] leading-[18px] max-md:text-[14px] max-md:leading-[20px]",children:o("sidebar.settings")})]})})]})}function Ue(e){const n=e.id??e.__renderKey;if(!n)throw new Error(`SessionEntry missing stable render key: type=${e.type}`);return n}const et=Object.freeze({text:"",images:[]}),Se=Re((e,n)=>({drafts:new Map,setDraft:(r,s)=>{e(a=>{const o=a.drafts.get(r)??et,i=typeof s=="function"?s(o):s,c=new Map(a.drafts);return i.text||i.images.length>0?c.set(r,i):c.delete(r),{drafts:c}})}})),ue=e=>e!==void 0&&e!=="idle";function lr(){return e=>{var n;((n=e.children[0])==null?void 0:n.type)==="yaml"&&(e.children[0]={type:"code",lang:"__frontmatter__",value:e.children[0].value})}}function ir({yamlText:e}){let n=[];try{const r=Et.load(e);r&&typeof r=="object"&&!Array.isArray(r)&&(n=Object.entries(r).map(([s,a])=>{const o=typeof a=="string"?a:JSON.stringify(a,null,2);return[s,o]}))}catch{n=[["raw",e]]}return n.length===0?null:t.jsx("div",{className:"my-2 rounded-[8px] border border-[var(--separator)] overflow-hidden",children:t.jsx("table",{className:"w-full text-[13px]",children:t.jsx("tbody",{children:n.map(([r,s])=>t.jsxs("tr",{className:"border-b last:border-b-0 border-[var(--separator)]",children:[t.jsx("td",{className:"px-3 py-1.5 bg-[var(--fill-quaternary)] text-[var(--label-secondary)] font-medium whitespace-nowrap align-top w-[1%]",children:r}),t.jsx("td",{className:"px-3 py-1.5 text-[var(--label-primary)] whitespace-pre-wrap break-all",children:s})]},r))})})})}function Ce(e){return e==null||typeof e=="boolean"?"":typeof e=="string"||typeof e=="number"?String(e):Array.isArray(e)?e.map(Ce).join(""):typeof e=="object"&&"props"in e?Ce(e.props.children):""}function pt({language:e,children:n}){const{t:r}=B(),[s,a]=l.useState(!1),o=Ce(n).replace(/\n$/,""),i=l.useCallback(()=>{navigator.clipboard.writeText(o),a(!0),setTimeout(()=>a(!1),2e3)},[o]);return t.jsxs("div",{className:"group/code relative my-2 rounded-[8px] bg-[var(--fill-card)] border border-[var(--separator)] overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 border-b border-[var(--separator)]",children:[t.jsx("span",{className:"text-[11px] text-[var(--label-tertiary)] font-medium",children:e||"code"}),t.jsxs("button",{onClick:i,className:"flex items-center gap-1 text-[11px] text-[var(--label-tertiary)] hover:text-[var(--label-secondary)] transition-colors",children:[s?t.jsx(pe,{size:12}):t.jsx(Nt,{size:12}),r(s?"entries.copied":"entries.copy")]})]}),t.jsx("pre",{className:"px-3 py-2.5 overflow-x-auto text-[13px] leading-[20px]",children:t.jsx("code",{children:n})})]})}const cr={code({className:e,children:n,...r}){const s=/language-(\w+)/.exec(e||"");if((s==null?void 0:s[1])==="__frontmatter__"){const a=Ce(n).replace(/\n$/,"");return t.jsx(ir,{yamlText:a})}return s?t.jsx(pt,{language:s[1],children:n}):String(n).includes(`
|
|
2
|
-
`)?t.jsx(pt,{language:"",children:n}):t.jsx("code",{className:"px-1.5 py-0.5 rounded-[4px] bg-[var(--fill-secondary)] text-[13px] font-mono break-words",...r,children:n})},pre({children:e}){return t.jsx(t.Fragment,{children:e})},p({children:e}){return t.jsx("p",{className:"text-[14px] leading-[22px] text-[var(--label-primary)] mb-2 last:mb-0",children:e})},h1({children:e}){return t.jsx("h1",{className:"text-[20px] leading-[26px] font-semibold text-[var(--label-primary)] mt-4 mb-2",children:e})},h2({children:e}){return t.jsx("h2",{className:"text-[17px] leading-[23px] font-semibold text-[var(--label-primary)] mt-3 mb-1.5",children:e})},h3({children:e}){return t.jsx("h3",{className:"text-[15px] leading-[21px] font-semibold text-[var(--label-primary)] mt-2 mb-1",children:e})},ul({children:e}){return t.jsx("ul",{className:"text-[14px] leading-[22px] text-[var(--label-primary)] pl-5 mb-2 list-disc space-y-0.5",children:e})},ol({children:e}){return t.jsx("ol",{className:"text-[14px] leading-[22px] text-[var(--label-primary)] pl-5 mb-2 list-decimal space-y-0.5",children:e})},li({children:e}){return t.jsx("li",{className:"text-[14px] leading-[22px]",children:e})},blockquote({children:e}){return t.jsx("blockquote",{className:"pl-3 border-l-2 border-[var(--color-accent)] text-[14px] leading-[22px] text-[var(--label-secondary)] my-2",children:e})},table({children:e}){return t.jsx("div",{className:"overflow-x-auto my-2 rounded-[8px] border border-[var(--separator)]",children:t.jsx("table",{className:"w-full text-[13px]",children:e})})},thead({children:e}){return t.jsx("thead",{className:"bg-[var(--fill-tertiary)] text-[var(--label-secondary)]",children:e})},th({children:e}){return t.jsx("th",{className:"px-3 py-1.5 text-left font-medium border-b border-[var(--separator)]",children:e})},td({children:e}){return t.jsx("td",{className:"px-3 py-1.5 border-b border-[var(--separator)]",children:e})},hr(){return t.jsx("hr",{className:"my-3 border-[var(--separator)]"})},a({href:e,children:n}){return t.jsx("a",{href:e,target:"_blank",rel:"noopener noreferrer",className:"text-[var(--color-accent)] hover:underline",children:n})},strong({children:e}){return t.jsx("strong",{className:"font-semibold text-[var(--label-primary)]",children:e})},em({children:e}){return t.jsx("em",{className:"italic text-[var(--label-primary)]",children:e})}};function dr(e){if(!/^---\s*\n/.test(e))return e;const n=e.match(/\n---\s*(?:\n|$)/);if(!n||n.index===void 0)return e;const r=e.slice(4,n.index);let s=!1;try{const a=Et.load(r);s=typeof a=="object"&&a!==null&&!Array.isArray(a)&&Object.keys(a).length>0}catch{}return s?e:"***"+e.slice(3)}var jt;const ur={...Le,attributes:{...Le.attributes,code:[...((jt=Le.attributes)==null?void 0:jt.code)||[],["className",/^language-.+/]]}};function J({content:e}){if(!e.trim())return null;const n=l.useMemo(()=>dr(e),[e]);return t.jsx("div",{className:"markdown-body min-w-0 max-w-full break-words",children:t.jsx(In,{remarkPlugins:[Pn,On,$n,lr],rehypePlugins:[An,[Ln,ur],_n],components:cr,children:n})})}function pr({content:e,streaming:n,autoCollapse:r}){const{t:s}=B(),[a,o]=l.useState(r),i=l.useRef(!1);return l.useEffect(()=>{r&&!i.current&&(i.current=!0,o(!0))},[r]),t.jsxs("div",{className:`rounded-[8px] bg-[var(--fill-card)] border border-[var(--separator)] overflow-hidden transition-all ${a?"max-w-[640px]":""}`,children:[t.jsxs("button",{onClick:()=>o(!a),className:"w-full flex items-center gap-1.5 px-3 py-1.5 text-left hover:bg-[var(--fill-quaternary)] transition-colors",children:[t.jsx(Je,{size:12,className:`text-[var(--label-tertiary)] transition-transform ${a?"":"rotate-90"}`}),t.jsx("span",{className:"text-[12px] font-medium text-[var(--label-tertiary)]",children:s(n?"entries.thinkingStreaming":"entries.thinking")})]}),!a&&t.jsx("div",{className:"px-3 pb-2.5 pt-0.5 text-[var(--label-secondary)] italic",children:t.jsx(J,{content:e})})]})}function X({title:e,trailing:n,onClose:r,children:s}){return t.jsx("div",{className:"fixed-viewport z-50 flex items-center justify-center bg-black/40 backdrop-blur-sm",onClick:r,children:t.jsxs("div",{className:"w-[90%] max-w-[640px] max-h-[80vh] rounded-[18px] bg-[var(--material-modal)] backdrop-blur-[30px] border border-[var(--separator)] shadow-[0_8px_40px_rgba(0,0,0,0.12)] flex flex-col overflow-hidden",onClick:a=>a.stopPropagation(),children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-[var(--separator)]",children:[t.jsx("div",{className:"flex items-center gap-2 text-[15px] font-semibold text-[var(--label-primary)] select-text",children:e}),t.jsxs("div",{className:"flex items-center gap-2 select-text",children:[n,t.jsx("button",{onClick:r,className:"select-none w-7 h-7 flex items-center justify-center rounded-full hover:bg-[var(--fill-secondary)] transition-colors text-[var(--label-secondary)]",children:t.jsx(Xe,{size:14})})]})]}),s]})})}function $t(e){return{read:t.jsx(un,{size:14}),bash:t.jsx(dn,{size:14}),edit:t.jsx(ct,{size:14}),write:t.jsx(ct,{size:14})}[e]??t.jsx(ln,{size:14})}function xr(e,n){switch(e){case"read":{const r=n.path??"",s=n.offset,a=n.limit;if(s!=null||a!=null){const o=s??"",i=a!=null?(s??1)+a-1:"";return`${r} [${o}:${i}]`}return r}case"bash":return n.command?String(n.command).slice(0,80):"";case"edit":return n.path??"";case"write":return n.path??"";default:return""}}function Ee(e,n){let r=0;const s=/`+/g;let a;for(;(a=s.exec(e))!==null;)a[0].length>r&&(r=a[0].length);const o="`".repeat(Math.max(3,r+1));return`${o}${n}
|
|
3
|
-
${e}
|
|
4
|
-
${o}`}const fr={ts:"typescript",tsx:"typescript",js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",json:"json",css:"css",scss:"scss",less:"less",html:"xml",htm:"xml",xml:"xml",svg:"xml",md:"markdown",mdx:"markdown",yaml:"yaml",yml:"yaml",toml:"ini",ini:"ini",sh:"bash",bash:"bash",zsh:"bash",fish:"bash",py:"python",rb:"ruby",rs:"rust",go:"go",java:"java",kt:"kotlin",swift:"swift",c:"c",h:"c",cpp:"cpp",hpp:"cpp",cs:"csharp",php:"php",sql:"sql",graphql:"graphql",gql:"graphql",dockerfile:"dockerfile",makefile:"makefile",lua:"lua",vim:"vim",diff:"diff",patch:"diff"};function zt(e){var a;const n=e.split("/").pop()??"",r=n.toLowerCase();if(r==="dockerfile")return"dockerfile";if(r==="makefile"||r==="gnumakefile")return"makefile";const s=(a=n.split(".").pop())==null?void 0:a.toLowerCase();if(s)return fr[s]}function mr(e,n){for(const r of e){const s=r.message;if((s==null?void 0:s.role)==="toolResult"&&s.toolCallId===n)return{content:Array.isArray(s.content)?s.content.filter(o=>o.type==="text").map(o=>o.text).join(`
|
|
5
|
-
`):String(s.content??""),isError:s.isError??!1,details:s.details??void 0}}return null}function hr({name:e,args:n,toolCallId:r,entries:s,isAborted:a=!1}){const[o,i]=l.useState(!1),c=xr(e,n),d=l.useMemo(()=>r?mr(s,r):null,[s,r]),u=d!==null,f=((d==null?void 0:d.isError)??!1)||!u&&a,h=e==="read"?gr:e==="bash"?br:e==="write"?vr:e==="edit"?jr:wr;return t.jsxs(t.Fragment,{children:[t.jsxs("button",{onClick:()=>i(!0),className:"w-full max-w-[640px] flex items-center gap-2.5 px-3 py-2 rounded-[8px] bg-[var(--fill-card)] border border-[var(--separator)] hover:bg-[var(--fill-tertiary)] transition-colors text-left group select-none",children:[t.jsx("span",{className:"text-[var(--label-secondary)] group-hover:text-[var(--color-accent)] transition-colors",children:$t(e)}),t.jsx("span",{className:"text-[13px] font-medium text-[var(--label-primary)]",children:e}),c&&t.jsx("span",{className:"text-[12px] text-[var(--label-tertiary)] truncate flex-1 min-w-0",children:c}),t.jsx("span",{className:"flex-shrink-0 ml-auto",children:!u&&!a?t.jsx(de,{size:14,className:"text-[var(--label-tertiary)] animate-spin"}):f?t.jsx(kt,{size:14,className:"text-red-400"}):t.jsx(Je,{size:14,className:"text-[var(--label-tertiary)] group-hover:text-[var(--label-secondary)] transition-colors"})})]}),o&&t.jsx(h,{name:e,args:n,result:d,isAborted:a,onClose:()=>i(!1)})]})}function xe(){const{t:e}=B();return t.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-[var(--label-tertiary)]",children:[t.jsx(de,{size:14,className:"animate-spin"}),t.jsx("span",{children:e("entries.running")})]})}function fe(){const{t:e}=B();return t.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-red-400",children:[t.jsx(kt,{size:14}),t.jsx("span",{children:e("entries.aborted")})]})}function me({name:e}){return t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-[var(--label-secondary)] select-none",children:$t(e)}),e]})}function gr({name:e,args:n,result:r,isAborted:s,onClose:a}){const o=n.path??"",i=n.offset,c=n.limit,d=zt(o);let u=o;if(i!=null||c!=null){const h=i??"",b=c!=null?(i??1)+c-1:"";u+=` [${h}:${b}]`}const p=d==="markdown",f=r&&!r.isError&&!p?Ee(r.content,d??""):null;return t.jsxs(X,{title:t.jsx(me,{name:e}),onClose:a,children:[t.jsx("div",{className:"px-5 py-2 border-b border-[var(--separator)] bg-[var(--fill-quaternary)]",children:t.jsx("p",{className:"text-[13px] text-[var(--label-secondary)] break-all leading-[20px] font-mono",children:u})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-5 pt-3 pb-5 scrollbar-auto",children:r!==null?r.isError?t.jsx("pre",{className:"text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] px-3 py-2 text-red-400 bg-red-400/5",children:r.content}):p?t.jsx(J,{content:r.content}):t.jsx(J,{content:f}):s?t.jsx(fe,{}):t.jsx(xe,{})})]})}function br({name:e,args:n,result:r,isAborted:s,onClose:a}){const o=n.command??"",i=n.timeout,c=Ee(o,"bash"),d=r&&!r.isError?Ee(r.content.trim(),"plaintext"):null;return t.jsx(X,{title:t.jsx(me,{name:e}),onClose:a,trailing:i!=null?t.jsxs("span",{className:"flex items-center gap-1 text-[11px] text-[var(--label-tertiary)]",children:[t.jsx(cn,{size:12}),i,"s"]}):void 0,children:t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-auto",children:[t.jsx("div",{className:"px-5 pt-3 pb-3 bg-[var(--fill-quaternary)]",children:t.jsx(J,{content:c})}),t.jsxs("div",{className:"px-5 pt-3 pb-5",children:[t.jsx("h4",{className:"text-[11px] font-semibold text-[var(--label-tertiary)] uppercase tracking-wide mb-2",children:"Output"}),r!==null?r.isError?t.jsx("pre",{className:"text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] px-3 py-2 text-red-400 bg-red-400/5",children:r.content}):t.jsx(J,{content:d}):s?t.jsx(fe,{}):t.jsx(xe,{})]})]})})}function vr({name:e,args:n,result:r,isAborted:s,onClose:a}){const{t:o}=B(),i=n.path??"",c=n.content??"",d=zt(i),u=d==="markdown",p=u?null:Ee(c,d??"");return t.jsxs(X,{title:t.jsx(me,{name:e}),onClose:a,children:[t.jsx("div",{className:"px-5 py-2 border-b border-[var(--separator)] bg-[var(--fill-quaternary)]",children:t.jsx("p",{className:"text-[13px] text-[var(--label-secondary)] break-all leading-[20px] font-mono",children:i})}),t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 pt-3 pb-5 space-y-3 scrollbar-auto",children:[t.jsx("section",{children:t.jsx(J,{content:u?c:p})}),r!==null&&t.jsxs("section",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-[var(--label-tertiary)] uppercase tracking-wide mb-1.5",children:o("entries.result")}),t.jsx("pre",{className:`text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] px-3 py-2 ${r.isError?"text-red-400 bg-red-400/5":"text-[var(--label-secondary)] bg-[var(--fill-tertiary)]"}`,children:r.content})]}),r===null&&(s?t.jsx(fe,{}):t.jsx(xe,{}))]})]})}function yr({diff:e}){const n=e.split(`
|
|
6
|
-
`);return t.jsx("pre",{className:"text-[13px] leading-[20px] font-mono overflow-x-auto",children:t.jsx("div",{style:{minWidth:"fit-content"},children:n.map((r,s)=>{const a=r[0];return a==="+"?t.jsx("div",{className:"px-3 rounded-[2px]",style:{backgroundColor:"var(--diff-add-bg)",color:"var(--diff-add-text)"},children:r},s):a==="-"?t.jsx("div",{className:"px-3 rounded-[2px]",style:{backgroundColor:"var(--diff-del-bg)",color:"var(--diff-del-text)"},children:r},s):t.jsx("div",{className:"px-3",style:{color:"var(--diff-context-text)"},children:r},s)})})})}function jr({name:e,args:n,result:r,isAborted:s,onClose:a}){var c;const o=n.path??"",i=(c=r==null?void 0:r.details)==null?void 0:c.diff;return t.jsxs(X,{title:t.jsx(me,{name:e}),onClose:a,children:[t.jsx("div",{className:"px-5 py-2 border-b border-[var(--separator)] bg-[var(--fill-quaternary)]",children:t.jsx("p",{className:"text-[13px] text-[var(--label-secondary)] break-all leading-[20px] font-mono",children:o})}),t.jsx("div",{className:"flex-1 overflow-y-auto pt-3 pb-5 scrollbar-auto",children:r!==null?r.isError?t.jsx("pre",{className:"text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] mx-5 px-3 py-2 text-red-400 bg-red-400/5",children:r.content}):i?t.jsx(yr,{diff:i}):t.jsx("pre",{className:"text-[13px] leading-[20px] whitespace-pre-wrap break-words mx-5 px-3 py-2 text-[var(--label-secondary)] bg-[var(--fill-tertiary)] rounded-[8px]",children:r.content}):s?t.jsx("div",{className:"px-5",children:t.jsx(fe,{})}):t.jsx("div",{className:"px-5",children:t.jsx(xe,{})})})]})}function wr({name:e,args:n,result:r,isAborted:s,onClose:a}){const{t:o}=B();return t.jsx(X,{title:t.jsx(me,{name:e}),onClose:a,children:t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 pt-3 pb-5 space-y-3 scrollbar-auto",children:[t.jsxs("section",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-[var(--label-tertiary)] uppercase tracking-wide mb-1.5",children:o("entries.params")}),t.jsx("pre",{className:"text-[13px] leading-[20px] text-[var(--label-secondary)] whitespace-pre-wrap break-words bg-[var(--fill-tertiary)] rounded-[8px] px-3 py-2 overflow-x-auto",children:JSON.stringify(n,null,2)})]}),r!==null&&t.jsxs("section",{children:[t.jsx("h4",{className:"text-[11px] font-semibold text-[var(--label-tertiary)] uppercase tracking-wide mb-1.5",children:o("entries.result")}),t.jsx("pre",{className:`text-[13px] leading-[20px] whitespace-pre-wrap break-words rounded-[8px] px-3 py-2 overflow-x-auto ${r.isError?"text-red-400 bg-red-400/5":"text-[var(--label-secondary)] bg-[var(--fill-tertiary)]"}`,children:r.content})]}),r===null&&t.jsx("section",{children:s?t.jsx(fe,{}):t.jsx(xe,{})})]})})}function Bt({src:e,alt:n,onClose:r}){const s=l.useCallback(a=>{a.key==="Escape"&&r()},[r]);return l.useEffect(()=>(document.addEventListener("keydown",s),document.body.style.overflow="hidden",()=>{document.removeEventListener("keydown",s),document.body.style.overflow=""}),[s]),t.jsxs("div",{className:"fixed-viewport z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-[30px] animate-in fade-in duration-150",onClick:r,children:[t.jsx("button",{onClick:r,className:"absolute top-4 right-4 z-10 w-9 h-9 rounded-full bg-[var(--badge-bg)] hover:bg-[var(--badge-bg-hover)] text-[var(--badge-text)] flex items-center justify-center transition-colors","aria-label":"Close",children:t.jsx(Xe,{size:18})}),t.jsx("img",{src:e,alt:n??"Image preview",onClick:a=>a.stopPropagation(),className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl select-none",draggable:!1})]})}function Nr({entry:e,entries:n,isLast:r,isStreaming:s,onReEdit:a}){const o=r&&s;switch(e.type){case"message":return t.jsx(kr,{entry:e,entries:n,streaming:o,onReEdit:a});case"compaction":case"branch_summary":return t.jsx(Tr,{type:e.type,summary:e.summary??""});default:return null}}function kr({entry:e,entries:n,streaming:r,onReEdit:s}){const a=e.message;if(!a)return null;switch(a.role){case"user":return t.jsx(Sr,{content:a.content});case"assistant":return t.jsx(Cr,{content:a.content,entries:n,streaming:r,stopReason:a.stopReason,errorMessage:a.errorMessage,onReEdit:s});case"toolResult":return null;default:return null}}function Sr({content:e}){const[n,r]=l.useState(null);let s="",a=[];return typeof e=="string"?s=e:Array.isArray(e)?(s=e.filter(o=>o.type==="text").map(o=>o.text).join(""),a=e.filter(o=>o.type==="image")):s=JSON.stringify(e),t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex justify-end px-4 py-1.5",children:t.jsxs("div",{className:"max-w-[80%] rounded-[16px] rounded-br-[4px] bg-[var(--color-accent)] text-white",children:[a.length>0&&t.jsx("div",{className:"flex flex-wrap gap-1.5 p-2 pb-0",children:a.map((o,i)=>{const c=`data:${o.mimeType};base64,${o.data}`;return t.jsx("button",{onClick:()=>r(c),className:"block rounded-[8px] overflow-hidden hover:opacity-90 transition-opacity",children:t.jsx("img",{src:c,alt:`Attached image ${i+1}`,className:"max-w-[200px] max-h-[150px] object-cover",draggable:!1})},i)})}),s&&t.jsx("p",{className:"text-[14px] leading-[21px] whitespace-pre-wrap break-words px-3.5 py-2",children:s}),!s&&a.length>0&&t.jsx("div",{className:"h-2"})]})}),n&&t.jsx(Bt,{src:n,onClose:()=>r(null)})]})}function Cr({content:e,entries:n,streaming:r,stopReason:s,errorMessage:a,onReEdit:o}){if((s==="error"||s==="aborted")&&a&&(!Array.isArray(e)||e.length===0))return t.jsx("div",{className:"px-4",children:t.jsx(xt,{message:a,onReEdit:s==="aborted"?o:void 0})});if(!Array.isArray(e))return t.jsx("div",{className:"px-4",children:t.jsx(J,{content:String(e)})});const i=s==="aborted"||s==="error",c=e[e.length-1],d=r&&(c==null?void 0:c.type)==="thinking",u=e.some(p=>p.type==="text"||p.type==="toolCall")||i;return t.jsxs("div",{className:"px-4 space-y-2",children:[e.map((p,f)=>t.jsx(Er,{block:p,entries:n,streaming:r&&f===e.length-1,autoCollapse:p.type==="thinking"&&u&&!d,isAborted:i},f)),(s==="error"||s==="aborted")&&a&&t.jsx(xt,{message:a,onReEdit:s==="aborted"&&!r?o:void 0}),r&&(c==null?void 0:c.type)!=="thinking"&&t.jsx("span",{className:"inline-block w-2 h-4 bg-[var(--label-tertiary)] rounded-sm animate-pulse"})]})}function Er({block:e,entries:n,streaming:r,autoCollapse:s,isAborted:a}){var o;switch(e.type){case"text":return t.jsx(J,{content:e.text});case"thinking":return(o=e.thinking)!=null&&o.trim()?t.jsx(pr,{content:e.thinking,streaming:r,autoCollapse:s}):null;case"toolCall":return t.jsx(hr,{name:e.name,args:e.arguments,toolCallId:e.id,entries:n,isAborted:a});default:return null}}function Tr({type:e,summary:n}){const{t:r}=B(),[s,a]=l.useState(!1),o=r(e==="compaction"?"entries.contextCompacted":"entries.branchSummary");return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex justify-center px-4 py-2",children:t.jsxs("button",{onClick:()=>n&&a(!0),className:`px-3 py-1 rounded-full bg-[var(--fill-tertiary)] text-[11px] text-[var(--label-tertiary)] transition-colors ${n?"hover:bg-[var(--fill-secondary)] cursor-pointer":""}`,children:[o,n&&t.jsxs("span",{className:"ml-1.5 opacity-70",children:["— ",n.slice(0,60),n.length>60?"...":""]})]})}),s&&t.jsx(X,{title:o,onClose:()=>a(!1),children:t.jsx("div",{className:"flex-1 overflow-y-auto px-5 py-4 scrollbar-auto",children:t.jsx(J,{content:n})})})]})}function xt({message:e,onReEdit:n}){var f,h;const{t:r}=B(),[s,a]=l.useState(!1);let o=e,i="",c="",d="";const u=e.indexOf("{");if(u>0){o=e.slice(0,u).trim();try{const b=JSON.parse(e.slice(u));i=((f=b==null?void 0:b.error)==null?void 0:f.message)??e.slice(u),c=((h=b==null?void 0:b.error)==null?void 0:h.type)??"";const S=i.match(/request id:\s*([\w]+)/i);S&&(d=S[1])}catch{i=e.slice(u)}}const p=i.length>200;return t.jsxs(t.Fragment,{children:[t.jsx("div",{onClick:p?()=>a(!0):void 0,className:`rounded-[10px] border border-[rgba(255,66,69,0.3)] bg-[rgba(255,66,69,0.06)] dark:bg-[rgba(255,66,69,0.1)] px-3.5 py-2.5 max-w-[640px] ${p?"cursor-pointer":""}`,children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(De,{size:14,className:"text-[#ff4245] flex-shrink-0 mt-0.5"}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("p",{className:"text-[12px] font-medium text-[#ff4245]",children:o}),t.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[n&&t.jsx("button",{onClick:b=>{b.stopPropagation(),n()},className:"text-[12px] leading-[15px] text-[var(--color-accent)] hover:opacity-70 active:opacity-50 transition-opacity select-none",children:r("reEdit.button")}),p&&t.jsx(Je,{size:12,className:"text-[var(--label-tertiary)] flex-shrink-0"})]})]}),i&&!p&&t.jsx("p",{className:"text-[11px] text-[var(--label-secondary)] mt-1.5 break-all whitespace-pre-wrap",children:i})]})]})}),s&&t.jsx(X,{title:r("error.title"),onClose:()=>a(!1),children:t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-6 scrollbar-auto",children:[t.jsxs("div",{className:"flex flex-col items-center text-center mb-5",children:[t.jsx("div",{className:"w-10 h-10 rounded-full bg-[rgba(255,66,69,0.1)] dark:bg-[rgba(255,66,69,0.15)] flex items-center justify-center mb-3",children:t.jsx(De,{size:20,className:"text-[#ff4245]"})}),t.jsx("p",{className:"text-[15px] font-semibold text-[#ff4245]",children:o})]}),t.jsxs("div",{className:"rounded-[10px] bg-[var(--fill-card)] p-4 space-y-3",children:[t.jsx(Oe,{label:r("error.message"),value:i}),c&&t.jsx(Oe,{label:r("error.type"),value:c}),d&&t.jsx(Oe,{label:r("error.requestId"),value:d,mono:!0})]})]})})]})}function Oe({label:e,value:n,mono:r}){return t.jsxs("div",{children:[t.jsx("p",{className:"text-[11px] text-[var(--label-tertiary)] mb-0.5",children:e}),t.jsx("p",{className:`text-[14px] leading-[22px] text-[var(--label-primary)] break-all whitespace-pre-wrap ${r?"font-mono text-[13px] leading-[20px]":""}`,children:n})]})}function Ft({title:e,subtitle:n,backTo:r="/",actions:s,children:a}){const o=Me();return t.jsxs("div",{className:"md:hidden flex items-center gap-2",children:[t.jsx("button",{onClick:()=>o(r),"aria-label":"Back to instances",className:"flex select-none items-center text-[var(--label-secondary)] active:opacity-60 transition-opacity",children:t.jsx(pn,{size:20})}),a??t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-[14px] font-medium text-[var(--label-primary)] truncate select-text",children:e}),n&&t.jsx("div",{className:"text-[11px] text-[var(--label-tertiary)] truncate select-text",children:n})]}),s]})]})}function Rr(e,n){if(n&&e.startsWith(n)){const r=e.slice(n.length);return!r||r==="/"?"~":"~"+(r.startsWith("/")?r:"/"+r)}return e}function We(e,n){if(e.length<=n)return e;const r=Math.floor((n-1)/2),s=n-1-r;return e.slice(0,s)+"…"+e.slice(-r)}function Mr(e){const n=e.split("/").filter(Boolean);return n.length<=2?e.length:n.slice(-2).join("/").length}function ft(e,n){if(e.length<=n)return e;const r=Mr(e);if(r+2<=n){const s=n-1-r;return e.slice(0,s)+"…"+e.slice(-r)}return We(e,n)}const Ir=6.2,Ar=20,Lr=8;function mt({icon:e,text:n,copyText:r,title:s}){const[a,o]=l.useState(!1),i=l.useRef(null);l.useEffect(()=>()=>{i.current&&clearTimeout(i.current)},[]);const c=l.useCallback(()=>{navigator.clipboard.writeText(r),o(!0),i.current&&clearTimeout(i.current),i.current=setTimeout(()=>o(!1),1500)},[r]);return t.jsxs("button",{type:"button",onClick:c,title:s??r,className:"inline-flex min-w-0 items-center gap-1 rounded-[4px] px-1 py-0.5 -mx-1 transition-colors hover:bg-[var(--fill-tertiary)] active:bg-[var(--fill-secondary)] cursor-pointer select-none",children:[t.jsx("span",{className:"shrink-0 opacity-70",children:a?t.jsx(pe,{size:11,className:"text-green-500"}):e}),t.jsx("span",{className:"truncate",children:n})]})}function ht({title:e,cwd:n,homedir:r,gitBranch:s,actions:a}){const o=n?Rr(n,r):null,i=l.useRef(null),[c,d]=l.useState(o),[u,p]=l.useState(s),f=l.useCallback(()=>{const h=i.current;if(!h)return;const b=h.getBoundingClientRect().width;if(b<=0)return;const S=(o?1:0)+(s?1:0),T=S*Ar+(S-1)*Lr,R=Math.floor((b-T)/Ir);if(o&&s){const g=Math.max(10,Math.floor(R*.6)),m=Math.max(8,R-g);d(ft(o,g)),p(We(s,m))}else o?d(ft(o,Math.max(10,R))):s&&p(We(s,Math.max(8,R)))},[o,s]);return l.useEffect(()=>{const h=i.current;if(!h)return;const b=new ResizeObserver(()=>f());return b.observe(h),f(),()=>b.disconnect()},[f]),l.useEffect(()=>{d(o),p(s),f()},[o,s,f]),t.jsxs("div",{className:"flex items-center justify-between gap-2 min-w-0 flex-1 min-h-[40px]",children:[t.jsxs("div",{className:"min-w-0 flex-1",children:[t.jsx("div",{className:"truncate text-[14px] leading-[20px] font-medium text-[var(--label-primary)] select-text",children:e}),(o||s)&&t.jsxs("div",{ref:i,className:"mt-0.5 flex min-w-0 items-center gap-2 text-[11px] leading-[14px] text-[var(--label-secondary)]",children:[c&&t.jsx(mt,{icon:t.jsx(St,{size:11}),text:c,copyText:n,title:n},n),u&&t.jsx(mt,{icon:t.jsx(xn,{size:11}),text:u,copyText:s},s)]})]}),a]})}function _r(e,n="top",r="right",s=8,a=12){const{innerWidth:o,innerHeight:i}=window,c=r==="left"?{left:Math.max(a,e.left)}:{right:Math.max(a,o-e.right)};return n==="bottom"?{...c,top:Math.max(a,e.bottom+s)}:{...c,bottom:Math.max(a,i-e.top+s)}}function tt({trigger:e,width:n=200,children:r,disabled:s=!1,placement:a="top",align:o="right"}){const[i,c]=l.useState(!1),[d,u]=l.useState(null),p=l.useRef(null),f=l.useRef(null);l.useEffect(()=>{if(!i)return;function T(R){var m,C;const g=R.target;!((m=p.current)!=null&&m.contains(g))&&!((C=f.current)!=null&&C.contains(g))&&c(!1)}return document.addEventListener("mousedown",T),()=>document.removeEventListener("mousedown",T)},[i]),l.useEffect(()=>{if(!i)return;const T=()=>c(!1);return window.addEventListener("resize",T),()=>{window.removeEventListener("resize",T)}},[i]);const h=()=>{var R;if(s)return;if(i){c(!1);return}const T=(R=p.current)==null?void 0:R.getBoundingClientRect();T&&(u(_r(T,a,o)),c(!0))},b=()=>c(!1),S=i&&d?Ge.createPortal(t.jsx("div",{ref:f,className:"glass-popover z-50",style:{position:"fixed",...d.left!==void 0?{left:d.left}:{right:d.right},...d.top!==void 0?{top:d.top}:{bottom:d.bottom},width:`${n}px`},children:r(b)}),document.body):null;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"relative",ref:p,onClick:h,children:e({open:i})}),S]})}function Pr(e,n){const r=new Date(e),a=Date.now()-r.getTime(),o=Math.floor(a/6e4);if(o<1)return n("session.timeJustNow");if(o<60)return`${o}m`;const i=Math.floor(o/60);if(i<24)return`${i}h`;const c=Math.floor(i/24);if(c<7)return`${c}d`;const d=Math.floor(c/7);return d<4?`${d}w`:r.toLocaleDateString()}function Or({sessions:e,loading:n,hasMore:r,total:s,disabled:a,onOpen:o,onNewSession:i,onSwitchSession:c,onLoadMore:d,onFilterChange:u}){const{t:p}=B(),[f,h]=l.useState(""),b=l.useRef(null),S=l.useRef(null),T=l.useCallback(g=>{h(g),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{u(g)},300)},[u]),R=l.useCallback(g=>{if(!r||n)return;const m=g.currentTarget;m.scrollHeight-m.scrollTop-m.clientHeight<40&&d(e.length,f)},[r,n,e.length,f,d]);return t.jsx(tt,{trigger:({open:g})=>t.jsx("button",{className:`flex items-center justify-center w-9 h-9 rounded-[8px] transition-colors ${g?"bg-[rgba(0,0,0,0.11)] dark:bg-[rgba(255,255,255,0.11)]":"hover:bg-[var(--fill-tertiary)]"} ${a?"opacity-40 pointer-events-none":""}`,title:p("session.title"),onClick:()=>{g||(h(""),o())},children:t.jsx(fn,{size:16,className:"text-[var(--label-secondary)]"})}),width:320,disabled:a,placement:"bottom",children:g=>t.jsxs("div",{className:"flex flex-col max-h-[360px]",children:[t.jsxs("div",{className:"flex items-center justify-between px-3 pt-2.5 pb-2",children:[t.jsxs("span",{className:"text-[13px] font-medium text-[var(--label-primary)] select-none",children:[p("session.title"),s>0&&t.jsxs("span",{className:"ml-1.5 text-[11px] font-normal text-[var(--label-tertiary)]",children:["(",s,")"]})]}),t.jsxs("button",{onClick:()=>{i(),g()},disabled:a,className:"flex items-center gap-1 px-2 py-1 rounded-[6px] text-[12px] text-[var(--label-secondary)] hover:text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)] transition-colors disabled:opacity-40",children:[t.jsx(wt,{size:12}),t.jsx("span",{children:p("session.new")})]})]}),t.jsx("div",{className:"px-3 pb-2",children:t.jsx("input",{type:"text",placeholder:p("session.filter"),value:f,onChange:m=>T(m.target.value),className:"w-full px-2.5 py-1.5 rounded-[6px] bg-[var(--fill-tertiary)] text-[12px] text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] outline-none border border-transparent focus:border-[var(--separator)]",autoFocus:!0})}),t.jsx("div",{className:"h-px bg-[var(--separator)] mx-2"}),t.jsx("div",{ref:S,className:"flex-1 overflow-y-auto scrollbar-auto py-1.5 px-1.5",onScroll:R,children:n&&e.length===0?t.jsx("div",{className:"flex items-center justify-center py-6",children:t.jsx(de,{size:16,className:"animate-spin text-[var(--label-tertiary)]"})}):e.length===0?t.jsx("div",{className:"py-4 text-center text-[12px] text-[var(--label-tertiary)] select-none",children:p(f?"session.noMatch":"session.noPrevious")}):t.jsxs(t.Fragment,{children:[e.map(m=>t.jsxs("button",{onClick:()=>{m.isCurrent||(c(m.path),g())},disabled:m.isCurrent,className:`w-full text-left px-2.5 py-2 rounded-[8px] transition-colors mb-0.5 ${m.isCurrent?"bg-[var(--fill-secondary)] cursor-default":"hover:bg-[var(--fill-tertiary)] cursor-pointer"}`,children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:`text-[13px] leading-[18px] truncate ${m.isCurrent?"font-medium text-[var(--color-accent)]":"text-[var(--label-primary)]"}`,children:m.name||m.firstMessage||p("session.empty")}),t.jsx("span",{className:"text-[11px] text-[var(--label-tertiary)] whitespace-nowrap shrink-0",children:Pr(m.modified,p)})]}),m.name&&m.firstMessage&&t.jsx("div",{className:"mt-0.5 text-[11px] leading-[15px] text-[var(--label-tertiary)] truncate",children:m.firstMessage}),t.jsx("div",{className:"mt-0.5 text-[10px] text-[var(--label-quaternary)]",children:p("session.messageCount",{count:m.messageCount})})]},m.id)),n&&e.length>0&&t.jsx("div",{className:"flex items-center justify-center py-2",children:t.jsx(de,{size:14,className:"animate-spin text-[var(--label-tertiary)]"})})]})})]})})}const $r=["image/png","image/jpeg","image/gif","image/webp"],zr=2048,Br=2048,gt=.85,$e=5*1024*1024;function Dt(){return`img_${Date.now()}_${Math.random().toString(36).slice(2,8)}`}async function bt(e){if(!$r.includes(e.type))throw new Error(`Unsupported image type: ${e.type}`);const n=await createImageBitmap(e),{width:r,height:s}=Dr(n.width,n.height,zr,Br),a=document.createElement("canvas");a.width=r,a.height=s,a.getContext("2d").drawImage(n,0,0,r,s),n.close();let i=e.type,c=gt;e.type!=="image/png"&&e.type!=="image/gif"&&(i="image/jpeg");let d=a.toDataURL(i,c);if(i==="image/jpeg"||i==="image/webp")for(;ze(d)>$e&&c>.3;)c-=.1,d=a.toDataURL(i,c);if(i==="image/png"&&ze(d)>$e)for(i="image/jpeg",c=gt,d=a.toDataURL(i,c);ze(d)>$e&&c>.3;)c-=.1,d=a.toDataURL(i,c);const u=d.split(",")[1];return{id:Dt(),data:u,mimeType:i,previewUrl:d}}function Fr(e){const n=[];for(let r=0;r<e.items.length;r++){const s=e.items[r];if(s.type.startsWith("image/")){const a=s.getAsFile();a&&n.push(a)}}return n}function Dr(e,n,r,s){if(e<=r&&n<=s)return{width:e,height:n};const a=Math.min(r/e,s/n);return{width:Math.round(e*a),height:Math.round(n*a)}}function ze(e){const n=e.split(",")[1];return n?Math.ceil(n.length*3/4):0}let Hr=0,Ne=[];function ee(e,n="info"){const r={id:++Hr,message:e,level:n,phase:"entering"};Ne.forEach(s=>s(r))}const qr=16,Kr=300,Ur={info:3e3,success:3e3,warning:4e3,error:5e3},Wr={info:gn,success:hn,warning:mn,error:De},Yr={info:"var(--toast-icon-info)",success:"var(--toast-icon-success)",warning:"var(--toast-icon-warning)",error:"var(--toast-icon-error)"};function Gr(){const[e,n]=l.useState([]),r=l.useRef(new Set);return l.useEffect(()=>{const s=a=>{n(d=>[...d,a]);const o=setTimeout(()=>{r.current.delete(o),n(d=>d.map(u=>u.id===a.id?{...u,phase:"visible"}:u))},qr);r.current.add(o);const i=Ur[a.level],c=setTimeout(()=>{r.current.delete(c),n(u=>u.map(p=>p.id===a.id?{...p,phase:"exiting"}:p));const d=setTimeout(()=>{r.current.delete(d),n(u=>u.filter(p=>p.id!==a.id))},Kr);r.current.add(d)},i);r.current.add(c)};return Ne.push(s),()=>{Ne=Ne.filter(a=>a!==s),r.current.forEach(a=>clearTimeout(a)),r.current.clear()}},[]),e.length===0?null:t.jsx("div",{className:"fixed top-[max(1rem,env(safe-area-inset-top))] left-1/2 -translate-x-1/2 z-[100] flex flex-col items-center gap-2 pointer-events-none",children:e.map(s=>{const a=Wr[s.level],o=Yr[s.level];return t.jsxs("div",{className:"pointer-events-auto flex items-center gap-2 rounded-full bg-[var(--panel-bg)] backdrop-blur-[30px] border-[0.5px] border-[var(--panel-border)] shadow-[var(--panel-shadow)] px-4 py-2.5 text-[13px] leading-[16px] text-[var(--label-primary)] select-none transition-all duration-300 ease-out",style:s.phase==="entering"?{opacity:0,transform:"translateY(-8px)"}:s.phase==="exiting"?{opacity:0,transform:"translateY(-4px)"}:{opacity:1,transform:"translateY(0)"},children:[t.jsx(a,{size:14,className:"shrink-0",style:{color:o}}),t.jsx("span",{children:s.message})]},s.id)})})}function Vr({currentModel:e,availableModels:n,onSelect:r}){const a=n&&n.length>0&&r,o=new Map;if(n)for(const c of n){const d=o.get(c.provider)??[];d.push(c),o.set(c.provider,d)}const i=c=>c.provider===e.provider&&c.id===e.id;return t.jsx(tt,{disabled:!a,width:280,align:"left",trigger:({open:c})=>t.jsxs("button",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-[9px] bg-[var(--fill-tertiary)] text-[12px] transition-colors ${a?"hover:bg-[var(--fill-secondary)] hover:text-[var(--label-primary)] cursor-pointer":"cursor-default"} text-[var(--label-secondary)]`,children:[t.jsx("span",{className:"max-w-[140px] truncate select-text",children:e.name||e.id}),a&&t.jsx(Ct,{size:10,className:`transition-transform ${c?"rotate-180":""}`})]}),children:c=>t.jsx("div",{className:"max-h-[320px] overflow-y-auto py-1.5 px-1.5 scrollbar-auto",children:Array.from(o.entries()).map(([d,u],p)=>t.jsxs("div",{children:[p>0&&t.jsx("div",{className:"mx-1 my-1 h-px bg-[var(--separator)]"}),t.jsx("div",{className:"px-2.5 pt-2 pb-1 text-[11px] font-bold text-[var(--label-tertiary)] uppercase select-none",children:d}),u.map(f=>{const h=i(f);return t.jsxs("button",{onClick:()=>{h||r==null||r(f.provider,f.id),c()},className:`w-full text-left px-2.5 py-2 rounded-[8px] flex items-center gap-2 transition-colors select-none mb-0.5 ${h?"bg-[var(--fill-secondary)]":"hover:bg-[var(--fill-tertiary)]"}`,children:[t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsx("div",{className:"text-[13px] text-[var(--label-primary)] truncate select-text",children:f.name||f.id}),t.jsx("div",{className:"text-[11px] text-[var(--label-tertiary)] truncate select-text",children:f.id})]}),h&&t.jsx(pe,{size:14,className:"text-[var(--color-accent)] flex-shrink-0"})]},`${f.provider}/${f.id}`)})]},d))})})}const Jr=["off","minimal","low","medium","high"];function Xr({currentLevel:e,onSelect:n}){const r=!!n;return t.jsx(tt,{disabled:!r,width:160,align:"left",trigger:({open:s})=>t.jsxs("button",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-[9px] bg-[var(--fill-tertiary)] text-[12px] transition-colors ${r?"hover:bg-[var(--fill-secondary)] hover:text-[var(--label-primary)] cursor-pointer":"cursor-default"} text-[var(--label-secondary)]`,children:[t.jsx("span",{className:"select-text",children:e}),r&&t.jsx(Ct,{size:10,className:`transition-transform ${s?"rotate-180":""}`})]}),children:s=>t.jsx("div",{className:"py-1.5 px-1.5",children:Jr.map(a=>{const o=a===e;return t.jsxs("button",{onClick:()=>{o||n==null||n(a),s()},className:`w-full text-left px-2.5 py-2 rounded-[8px] flex items-center gap-2 transition-colors select-none mb-0.5 ${o?"bg-[var(--fill-secondary)]":"hover:bg-[var(--fill-tertiary)]"}`,children:[t.jsx("span",{className:"flex-1 text-[13px] text-[var(--label-primary)]",children:a}),o&&t.jsx(pe,{size:14,className:"text-[var(--color-accent)] flex-shrink-0"})]},a)})})})}function Zr({onClose:e,onConfirm:n}){const{t:r}=B(),[s,a]=l.useState(""),o=l.useCallback(()=>{n(s.trim()||void 0)},[s,n]);return t.jsx(X,{title:r("compact.title"),onClose:e,children:t.jsxs("div",{className:"px-5 py-4 space-y-3",children:[t.jsx("p",{className:"text-[13px] leading-[18px] text-[var(--label-secondary)] select-none",children:r("compact.description")}),t.jsx("textarea",{value:s,onChange:i=>a(i.target.value),placeholder:r("compact.placeholder"),rows:3,className:"w-full px-3 py-2 rounded-[10px] bg-[var(--fill-tertiary)] border border-[var(--separator)] text-[14px] leading-[20px] text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] outline-none resize-none focus:border-[var(--color-accent)] transition-colors"}),t.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[t.jsx("button",{onClick:e,className:"px-3.5 py-1.5 rounded-[8px] text-[13px] text-[var(--label-secondary)] hover:bg-[var(--fill-tertiary)] transition-colors",children:r("common.cancel")}),t.jsx("button",{onClick:o,className:"px-3.5 py-1.5 rounded-[8px] text-[13px] font-medium text-white bg-[var(--color-accent)] hover:opacity-90 active:opacity-80 transition-opacity",children:r("compact.start")})]})]})})}function Qr({ref:e,instance:n,draft:r,onDraftChange:s,onSendMessage:a,onAbort:o,onSetModel:i,onSetThinkingLevel:c,onCompact:d,buttonMode:u,showCompactButton:p,compactDisabled:f,onImageLightbox:h,startBottomFollow:b}){const{t:S}=B(),T=l.useRef(null);l.useImperativeHandle(e,()=>({focus(){const N=T.current;if(!N)return;N.focus();const v=N.value.length;N.selectionStart=N.selectionEnd=v,N.scrollTop=N.scrollHeight}}));const R=l.useRef(null),g=l.useRef(r);g.current=r;const[m,C]=l.useState(!1),j=n==null?void 0:n.status,z=n==null?void 0:n.contextUsage,E=n==null?void 0:n.model,_=n==null?void 0:n.availableModels,y=n==null?void 0:n.thinkingLevel,w=!!z&&z.tokens!=null&&z.percent!=null,M=l.useCallback(N=>{N.style.height="auto";const v=Math.min(N.scrollHeight,150);N.style.height=`${v}px`,N.style.overflowY=N.scrollHeight>150?"auto":"hidden"},[]);l.useLayoutEffect(()=>{T.current&&M(T.current)},[r.text,M]);const P=l.useCallback(N=>{s(v=>({...v,text:N.target.value})),M(N.target)},[s,M]),$=!ue(j)&&(!!r.text.trim()||r.images.length>0),D=l.useCallback(()=>{const N=g.current;if(ue(j)||!N.text.trim()&&N.images.length===0)return;const v=N.images.length?N.images.map(k=>({data:k.data,mimeType:k.mimeType})):void 0;a(N.text.trim(),v),T.current&&(T.current.style.height="auto"),b()},[j,a,b]),K=l.useCallback(N=>{N.nativeEvent.isComposing||N.keyCode===229||N.key==="Enter"&&!N.shiftKey&&(N.preventDefault(),D())},[D]),Y=l.useCallback(N=>{const v=Fr(N.clipboardData);v.length!==0&&(N.preventDefault(),Promise.all(v.map(bt)).then(k=>{s(x=>({...x,images:[...x.images,...k]}))}).catch(k=>{ee(S("eventStream.imageProcessFailed"),"error"),console.error("Image process failed:",k)}))},[s,S]),G=l.useCallback(N=>{const v=Array.from(N.target.files??[]);v.length!==0&&(Promise.all(v.map(bt)).then(k=>{s(x=>({...x,images:[...x.images,...k]}))}).catch(k=>{ee(S("eventStream.imageProcessFailed"),"error"),console.error("Image process failed:",k)}),N.target.value="")},[s,S]),Z=l.useCallback(N=>{s(v=>({...v,images:v.images.filter(k=>k.id!==N)}))},[s]);return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"glass-panel glass-panel-input px-3 py-2 md:px-4",children:[(j||w)&&t.jsxs("div",{className:"mb-1.5 flex items-center gap-2 px-1 text-[12px] leading-[15px] text-[var(--label-secondary)]",children:[t.jsx(es,{status:j}),w&&t.jsxs("span",{className:"min-w-0 flex items-center gap-1",children:[t.jsx("span",{className:"min-w-0 truncate",children:t.jsx(ts,{contextUsage:z})}),p&&t.jsx("button",{onClick:()=>C(!0),disabled:f,title:S("eventStream.compactContext"),className:"shrink-0 inline-flex items-center justify-center p-0.5 rounded-[4px] text-[var(--label-secondary)] hover:text-[var(--color-accent)] hover:bg-[var(--fill-tertiary)] transition-colors disabled:opacity-40 disabled:pointer-events-none",children:t.jsx(bn,{size:12})})]})]}),t.jsxs("div",{className:"flex flex-col overflow-hidden rounded-[14px] border border-[var(--separator)]",children:[r.images.length>0&&t.jsx("div",{className:"flex gap-2 px-3 pt-2 pb-0 overflow-x-auto scrollbar-none md:px-4",children:r.images.map(N=>t.jsxs("div",{className:"relative flex-shrink-0 group",children:[t.jsx("button",{onClick:()=>h(N.previewUrl),className:"block rounded-[8px] overflow-hidden border border-[var(--separator)] hover:border-[var(--color-accent)] transition-colors",children:t.jsx("img",{src:N.previewUrl,alt:"Attached",className:"w-[60px] h-[60px] object-cover",draggable:!1})}),t.jsx("button",{onClick:()=>Z(N.id),className:"absolute -top-1 -right-1 w-[14px] h-[14px] rounded-full bg-[var(--badge-bg)] text-[var(--badge-text)] flex items-center justify-center hover:bg-[var(--badge-bg-hover)] transition-colors","aria-label":"Remove image",children:t.jsx(Xe,{size:8})})]},N.id))}),t.jsx("textarea",{ref:T,rows:1,placeholder:S("eventStream.sendPlaceholder"),value:r.text,onChange:P,onKeyDown:K,onPaste:Y,className:"resize-none bg-transparent text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] text-[16px] leading-[24px] px-3 pt-[9px] pb-0 outline-none overflow-hidden md:px-4 md:pt-[10px] md:text-[14px] md:leading-[22px]"}),t.jsxs("div",{className:"flex items-center justify-between px-1.5 pt-[9px] pb-1.5 md:pt-[10px]",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[E&&t.jsx(Vr,{currentModel:E,availableModels:_,onSelect:i}),y&&t.jsx(Xr,{currentLevel:y,onSelect:c}),t.jsx("button",{onClick:()=>{var N;return(N=R.current)==null?void 0:N.click()},className:"select-none h-[26px] px-1.5 rounded-[6px] flex items-center justify-center text-[var(--label-secondary)] hover:text-[var(--label-primary)] hover:bg-[var(--fill-tertiary)] transition-colors",title:S("eventStream.attachImage"),children:t.jsx(vn,{size:15})}),t.jsx("input",{ref:R,type:"file",accept:"image/png,image/jpeg,image/gif,image/webp",multiple:!0,onChange:G,className:"hidden"})]}),t.jsx("div",{className:"flex-shrink-0",children:u==="stop"?t.jsx("button",{onClick:o,className:"select-none w-[28px] h-[28px] rounded-full bg-red-500 text-white flex items-center justify-center hover:opacity-90 active:opacity-80 transition-opacity",title:S("eventStream.stop"),children:t.jsx(yn,{size:12,fill:"currentColor"})}):t.jsx("button",{onClick:D,disabled:!$,className:`select-none w-[28px] h-[28px] rounded-full flex items-center justify-center transition-opacity ${$?"bg-[var(--color-accent)] text-white hover:opacity-90 active:opacity-80":"bg-[var(--fill-secondary)] text-[var(--label-tertiary)] opacity-50 cursor-default"}`,title:S("eventStream.send"),children:t.jsx(jn,{size:16,strokeWidth:2.5})})})]})]})]}),m&&t.jsx(Zr,{onClose:()=>C(!1),onConfirm:N=>{d(N),C(!1)}})]})}function es({status:e}){const{t:n}=B();if(!e)return null;const r=e==="streaming",s=e==="compacting",a=r?"bg-[color-mix(in_srgb,var(--color-accent)_12%,transparent)] text-[var(--color-accent)]":s?"bg-amber-500/10 text-amber-500":"bg-green-500/10 text-green-500",o=r?"bg-[var(--color-accent)] animate-pulse":s?"bg-amber-500 animate-pulse":"bg-green-500",i=n(r?"eventStream.statusRunning":s?"eventStream.statusCompacting":"eventStream.statusOnline");return t.jsxs("span",{className:`flex shrink-0 items-center gap-1 rounded-full px-1.5 py-0.5 ${a}`,title:i,role:"status","aria-live":"polite","aria-label":i,children:[t.jsx("span",{"aria-hidden":"true",className:`h-2 w-2 rounded-full ${o}`}),t.jsx("span",{className:"text-[11px] font-medium leading-none",children:i})]})}function ts({contextUsage:e}){const{tokens:n,contextWindow:r,percent:s}=e;if(n==null||s==null)return null;const a=s>90?"#ff4245":s>60?"#ff9230":"#30d158",o=i=>{if(i<1e3)return String(i);if(i<1e4)return`${(i/1e3).toFixed(1)}k`;if(i<1e6)return`${Math.round(i/1e3)}k`;const c=i/1e6;return c%1===0?`${c}M`:`${c.toFixed(1)}M`};return t.jsxs("span",{className:"select-text",style:{color:a},children:[o(n)," / ",o(r)," (",Math.round(s),"%)"]})}let ns=0;function Ht(e,n){return`${e}:${n}:${ns++}`}function Be(e,n,r){return n.id||n.__renderKey?n:{...n,__renderKey:Ht(e,r)}}function rs(e,n){const{t:r}=B(),s=U(x=>x.send),a=U(x=>x.subscribe),o=U(x=>x.connectionState==="connected"),[i,c]=l.useState([]),[d,u]=l.useState(null),p=l.useRef(null),[f,h]=l.useState("idle"),[b,S]=l.useState(null),[T,R]=l.useState(!1),[g,m]=l.useState([]),[C,j]=l.useState(!1),[z,E]=l.useState(!1),[_,y]=l.useState(0),w=l.useRef(0),M=l.useRef(i);M.current=i;const P=l.useRef(f);P.current=f;const $=l.useRef(T);$.current=T;const D=l.useCallback(()=>{c([]),u(null),h("refreshing"),S(null),R(!1),m([]),j(!1),E(!1),y(0)},[]);l.useEffect(()=>a(x=>{switch(x.type){case"forwarded_event":{if(x.payload.instanceId!==e)return;Z(e,x.payload.event,x.payload.data);break}case"history":{if(x.payload.instanceId!==e)return;const I=x.payload.messages,O=x.payload.hasMore??!1;N(e,I,O);break}case"session_list":{if(x.payload.instanceId!==e)return;w.current>0?m(I=>[...I,...x.payload.sessions]):m(x.payload.sessions),E(x.payload.hasMore??!1),y(x.payload.total??x.payload.sessions.length),j(!1);break}case"error":{console.error("[Paimon]",x.payload.message),h("error"),S(x.payload.message);break}case"instance_error":{if(x.payload.instanceId!==e)return;const I=x.payload.action?`error.action.${x.payload.action}`:null,O=I?r(I,{message:x.payload.message,defaultValue:x.payload.message}):x.payload.message;ee(O,"error");break}}}),[e,a]),l.useEffect(()=>{if(o)return D(),s({type:"subscribe",payload:{instanceId:e}}),s({type:"get_history",payload:{instanceId:e}}),()=>{s({type:"unsubscribe",payload:{instanceId:e}})}},[e,o,s,D]);const K=l.useRef(n==null?void 0:n.sessionId),Y=l.useRef(e);l.useEffect(()=>{const x=n==null?void 0:n.sessionId;if(e!==Y.current){Y.current=e,x!==void 0&&(K.current=x);return}K.current!==void 0&&x!==void 0&&x!==K.current&&(D(),s({type:"get_history",payload:{instanceId:e}})),x!==void 0&&(K.current=x)},[n==null?void 0:n.sessionId,e,s,D]);const G=l.useRef(n==null?void 0:n.status);l.useEffect(()=>{const x=n==null?void 0:n.status;G.current==="compacting"&&x!=="compacting"&&(D(),s({type:"get_history",payload:{instanceId:e}})),G.current=x},[n==null?void 0:n.status,e,s,D]);function Z(x,I,O){const F=O;switch(I){case"message_start":{const A=F.message;if(!A||A.role!=="assistant")break;const H=Be(x,{type:"message",timestamp:new Date().toISOString(),message:A},"streaming");p.current=H.__renderKey??H.id??null,u(H);break}case"message_update":{const A=F.message;if(!A)break;u(H=>H?{...H,message:A}:Be(x,{type:"message",timestamp:new Date().toISOString(),message:A},"streaming"));break}case"message_end":{const A=F.message;if(A){const H=p.current??Ht(x,"live"),oe={type:"message",timestamp:new Date().toISOString(),message:A,__renderKey:H};c(te=>[...te,oe])}p.current=null,u(null);break}}}function N(x,I,O){const F=I.map(A=>Be(x,A,"history"));P.current==="loadingMore"?c(A=>[...F,...A]):c(F),R(O),h("idle"),S(null)}const v=l.useCallback(()=>{if(!$.current||P.current!=="idle")return;const x=M.current.length;h("loadingMore"),s({type:"get_history",payload:{instanceId:e,offset:x}})},[e,s]),k=l.useCallback(x=>{const I=(x==null?void 0:x.offset)??0;w.current=I,I===0&&m([]),j(!0),s({type:"list_sessions",payload:{instanceId:e,offset:I,limit:x==null?void 0:x.limit,filter:x==null?void 0:x.filter}})},[e,s]);return{entries:d?[...i,d]:i,streamingEntry:d,isStreaming:d!==null,loadState:f,errorMessage:b,hasMore:T,sessionList:g,sessionListLoading:C,sessionHasMore:z,sessionTotal:_,loadMore:v,requestSessionList:k}}const ss=.5;function as({topChromeHeight:e,bottomChromeHeight:n,bottomSafeGap:r=0}){const s=Math.max(0,n-r),a=Math.max(40,s+12);return{paddingTop:Math.max(24,e-4),paddingBottom:a,scrollButtonBottom:r+a}}function os({previousScrollTop:e,previousScrollHeight:n,nextScrollHeight:r}){return e+r-n}function ls(e){return e==="streaming"||e==="compacting"?"stop":"send"}function Te(e){return Math.max(0,e)}function is({isAtBottom:e,isLoadingMore:n,distanceToBottom:r,overlap:s,force:a=!1,scrollToBottom:o}){return!e||n||!a&&r<=ss&&s<=0?!1:(o(),!0)}function cs({rawScrollTop:e,hasMore:n,canLoadMore:r,isLoadingMore:s,isSuppressed:a}){return e>=0&&Te(e)<100&&n&&r&&!s&&!a}const ds=350,he="data-entry-key",qt=.5,us=3,ps=2e3;function nt(e){return e.getAttribute(he)??void 0}function Kt(e,n){const r=n.closest(`[${he}]`);return!r||!e.contains(r)?null:r}function Ut(e,n){const r=e.querySelectorAll(`[${he}]`);for(const s of r)if(nt(s)===n)return s;return null}function ce(e,n){return n.getBoundingClientRect().top-e.top}function xs(e){const n=e.getBoundingClientRect(),r=n.top+8,s=e.querySelectorAll(`[${he}]`);for(const a of s){const o=a.getBoundingClientRect();if(o.bottom>r&&o.top<n.bottom)return a}return null}function fs(e){const n={fallbackScrollTop:Te(e.scrollTop),fallbackScrollHeight:e.scrollHeight},r=e.getBoundingClientRect(),s=xs(e);if(!s)return n;const a=nt(s);if(!a)return n;const o=s.getBoundingClientRect(),i=Math.min(Math.max(r.top+12,o.top+8),Math.min(o.bottom-1,r.bottom-1)),c=[{x:r.left+r.width/2,y:i},{x:r.left+24,y:i},{x:r.right-24,y:i}];for(const d of c){const u=document.elementsFromPoint(d.x,d.y);for(const p of u){if(p===e||!e.contains(p))continue;const f=Kt(e,p);if(!f||f!==s)continue;const h=p.getBoundingClientRect();if(!(h.bottom<=r.top||h.top>=r.bottom))return{...n,entryKey:a,element:p,elementTop:ce(r,p),entryTop:ce(r,s)}}}return{...n,entryKey:a,entryTop:ce(r,s)}}function vt(e,n){return Math.abs(n)<=qt?!1:(e.scrollTop+=n,!0)}function yt(e,n,{allowDiffFallback:r}){const s=e.getBoundingClientRect();if(n.element&&n.elementTop!=null&&n.element.isConnected&&e.contains(n.element)){const a=Kt(e,n.element),o=a?nt(a):void 0;if(!n.entryKey||o===n.entryKey){const i=ce(s,n.element)-n.elementTop;return{mode:"deep",delta:i,adjusted:vt(e,i)}}}if(n.entryKey&&n.entryTop!=null){const a=Ut(e,n.entryKey);if(a){const o=ce(s,a)-n.entryTop;return{mode:"entry",delta:o,adjusted:vt(e,o)}}}if(r){const a=os({previousScrollTop:n.fallbackScrollTop,previousScrollHeight:n.fallbackScrollHeight,nextScrollHeight:e.scrollHeight}),o=a-e.scrollTop;return e.scrollTop=a,{mode:"diff",delta:o,adjusted:Math.abs(o)>qt}}return{mode:"none",delta:0,adjusted:!1}}function ms({scrollRef:e,contentRef:n,bottomChromeRef:r,entries:s,entriesRef:a,instanceId:o,hasMore:i,shouldScrollToBottom:c,onScrollToBottomHandled:d,onLoadMore:u,bottomChromeHeight:p,bottomSafeGap:f}){const h=l.useRef(!0),[b,S]=l.useState(!1),T=l.useRef(!1),R=l.useRef(!1),g=l.useRef(null),m=l.useRef(null),C=l.useRef(!1),j=l.useRef(null),z=l.useRef(s.length),E=l.useRef(void 0),_=l.useRef(0),y=l.useRef(null),w=l.useCallback(v=>{g.current!=null&&cancelAnimationFrame(g.current),R.current=!0,T.current=!0,v(),g.current=requestAnimationFrame(()=>{R.current=!1,T.current=!1,g.current=null})},[]),M=l.useCallback(()=>{var k;const v=y.current;v&&(v.rafId!=null&&cancelAnimationFrame(v.rafId),(k=v.observer)==null||k.disconnect(),y.current=null)},[]),P=l.useCallback(({force:v=!1}={})=>{const k=e.current,x=n.current,I=r.current;if(!k||!x||!I)return!1;const O=x.querySelectorAll(`[${he}]`),F=O[O.length-1],A=F==null?void 0:F.getBoundingClientRect(),H=I.getBoundingClientRect(),oe=k.scrollHeight-Te(k.scrollTop)-k.clientHeight,te=A?A.bottom-H.top:0;return is({isAtBottom:h.current,isLoadingMore:C.current,distanceToBottom:oe,overlap:te,force:v,scrollToBottom:()=>{M(),w(()=>{k.scrollTop=k.scrollHeight}),S(!1)}})},[e,n,r,w,M]),$=l.useCallback(()=>{var v;(v=m.current)==null||v.call(m),m.current=null},[]),D=l.useCallback(()=>{$();const v=performance.now();let k=null,x=!1;const I=(O=performance.now())=>{k=null,!(x||O-v>=ps)&&(!h.current||C.current||(P(),k=requestAnimationFrame(I)))};I(),m.current=()=>{x=!0,k!=null&&(cancelAnimationFrame(k),k=null)}},[P,$]);l.useLayoutEffect(()=>{C.current||P()},[p,f,P]),l.useLayoutEffect(()=>{const v=n.current;if(!v||typeof ResizeObserver>"u")return;const k=new ResizeObserver(()=>{P()});return k.observe(v),()=>k.disconnect()},[o,n,P]);const K=l.useCallback(()=>{const v=e.current,k=y.current;if(!v||!k)return;let x={mode:"none"};w(()=>{x=yt(v,k.snapshot,{allowDiffFallback:!1})}),x.mode==="none"&&M()},[e,w,M]),Y=l.useCallback(()=>{const v=y.current;!v||v.rafId!=null||(v.rafId=requestAnimationFrame(()=>{const k=y.current;!k||k!==v||(k.rafId=null,K())}))},[K]),G=l.useCallback(v=>{const k=e.current,x=n.current;if(!k||!x||!v.entryKey)return;M();const I={snapshot:v,observer:null,rafId:null,warmupFrame:0};if(y.current=I,typeof ResizeObserver<"u"){const F=new ResizeObserver(()=>{Y()});F.observe(x);const A=Ut(k,v.entryKey);A&&A!==x&&F.observe(A),I.observer=F}const O=()=>{const F=y.current;!F||F!==I||F.warmupFrame>=us||(F.rafId=requestAnimationFrame(()=>{const A=y.current;!A||A!==I||(A.rafId=null,A.warmupFrame+=1,K(),O())}))};O()},[e,n,K,Y,M]);l.useLayoutEffect(()=>(C.current=!1,j.current=null,E.current=void 0,_.current=0,z.current=a.current.length,h.current=!0,S(!1),()=>{$(),M(),g.current!=null&&(cancelAnimationFrame(g.current),g.current=null),R.current=!1,T.current=!1,C.current=!1,j.current=null,E.current=void 0,_.current=0}),[o,a,M,$]),l.useLayoutEffect(()=>{e.current&&(C.current||P())},[s,o,e,P]),l.useLayoutEffect(()=>{if(!c)return;if(!e.current){d();return}h.current=!0,P({force:!0}),S(!1),d()},[c,s,e,P,d]),l.useLayoutEffect(()=>{const v=e.current;if(C.current&&v&&s.length>z.current){const k=s[0]?Ue(s[0]):void 0;if(!E.current||k!==E.current){const I=j.current;let O={mode:"none"};I&&w(()=>{O=yt(v,I,{allowDiffFallback:!0})}),_.current=performance.now()+ds,I&&I.entryKey&&O.mode!=="none"&&G(I),C.current=!1,j.current=null,E.current=void 0}else j.current&&(j.current={...j.current,fallbackScrollHeight:v.scrollHeight})}C.current&&!i&&(C.current=!1,j.current=null,E.current=void 0),z.current=s.length},[s,i,o,e,w,G]);const Z=l.useCallback(()=>{const v=e.current;if(!v)return;const k=v.scrollTop,x=Te(k),I=performance.now()<_.current;if(k<0||T.current||R.current)return;y.current&&M();const O=v.scrollHeight-x-v.clientHeight<60;if(h.current=O,O||$(),S(!O),cs({rawScrollTop:k,hasMore:i,canLoadMore:!!u,isLoadingMore:C.current,isSuppressed:I})&&u){$(),M(),C.current=!0;const A=a.current,H=fs(v);j.current=H,E.current=A[0]?Ue(A[0]):void 0,u()}},[e,a,i,u,M,$]),N=l.useCallback(()=>{e.current&&(M(),w(()=>{e.current.scrollTop=e.current.scrollHeight}),h.current=!0,S(!1))},[e,w,M]);return{handleScroll:Z,scrollToBottom:N,showScrollBtn:b,startBottomFollow:D}}function hs(e,n,r,s){const{t:a}=B(),o=Se(u=>u.setDraft),{canReEdit:i,userContent:c}=l.useMemo(()=>{var p,f;if(r!=="idle"||n.length===0)return{canReEdit:!1,userContent:null};const u=n[n.length-1];if(u.type!=="message"||((p=u.message)==null?void 0:p.role)!=="assistant"||u.message.stopReason!=="aborted")return{canReEdit:!1,userContent:null};for(let h=n.length-2;h>=0;h--){const b=n[h];if(b.type==="message"&&((f=b.message)==null?void 0:f.role)==="user")return{canReEdit:!0,userContent:b.message.content}}return{canReEdit:!1,userContent:null}},[n,r]),d=l.useCallback(()=>{if(!i||c==null)return;const u=Se.getState().drafts.get(e)??et;if(u.text.trim()||u.images.length>0){ee(a("reEdit.draftNotEmpty"),"warning");return}const p=gs(c);Ge.flushSync(()=>{o(e,p)}),s==null||s()},[i,c,e,o,a,s]);return i?d:void 0}function gs(e){let n="";const r=[];if(typeof e=="string")n=e;else if(Array.isArray(e)){const s=[];for(const a of e)if(a.type==="text")s.push(a.text);else if(a.type==="image"){const o=a,i=Dt();r.push({id:i,data:o.data,mimeType:o.mimeType,previewUrl:`data:${o.mimeType};base64,${o.data}`})}n=s.join("")}return{text:n,images:r}}function bs(){const{t:e}=B(),{id:n}=wn(),r=n,s=U(L=>L.send),a=re(Un(r)),o=Se(L=>L.drafts.get(r)??et),i=Se(L=>L.setDraft),{entries:c,isStreaming:d,loadState:u,errorMessage:p,hasMore:f,sessionList:h,sessionListLoading:b,sessionHasMore:S,sessionTotal:T,loadMore:R,requestSessionList:g}=rs(r,a),m=l.useCallback(L=>{i(r,L)},[r,i]),C=l.useCallback((L,W)=>{s({type:"prompt",payload:{instanceId:r,message:L,images:W!=null&&W.length?W:void 0}}),i(r,{text:"",images:[]})},[r,s,i]),j=l.useCallback(()=>{s({type:"abort",payload:{instanceId:r}})},[r,s]),z=l.useCallback((L,W)=>{s({type:"set_model",payload:{instanceId:r,provider:L,id:W}})},[r,s]),E=l.useCallback(L=>{s({type:"set_thinking_level",payload:{instanceId:r,level:L}})},[r,s]),_=l.useCallback(()=>{g({offset:0})},[g]),y=l.useCallback((L,W)=>{g({offset:L,filter:W})},[g]),w=l.useCallback(L=>{g({offset:0,filter:L||void 0})},[g]),M=l.useCallback(()=>{s({type:"new_session",payload:{instanceId:r}})},[r,s]),P=l.useCallback(L=>{s({type:"switch_session",payload:{instanceId:r,path:L}})},[r,s]),$=l.useCallback(L=>{s({type:"compact",payload:{instanceId:r,customInstructions:L}})},[r,s]),D=l.useRef(null),K=hs(r,c,a==null?void 0:a.status,()=>{var L;(L=D.current)==null||L.focus()}),Y=l.useRef(null),G=l.useRef(null),Z=l.useRef(null),N=l.useRef(null),v=l.useRef(null),[k,x]=l.useState(null),I=l.useRef(c);I.current=c;const O=u==="refreshing",F=ls(a==null?void 0:a.status),A=c.length>0&&c[c.length-1].type==="compaction",H=ue(a==null?void 0:a.status),[oe,te]=l.useState(!1),Yt=l.useCallback(()=>{te(!1)},[]),rt=l.useRef(u);l.useLayoutEffect(()=>{rt.current==="refreshing"&&u==="idle"&&te(!0),rt.current=u},[u]);const[Gt,Vt]=l.useState(64),[st,Jt]=l.useState(96),[at,Xt]=l.useState(12),Ie=as({topChromeHeight:Gt,bottomChromeHeight:st,bottomSafeGap:at});l.useLayoutEffect(()=>{const L=(Ae,nn)=>{if(!Ae)return()=>{};const lt=()=>{nn(Math.ceil(Ae.getBoundingClientRect().height))};if(lt(),typeof ResizeObserver>"u")return()=>{};const it=new ResizeObserver(lt);return it.observe(Ae),()=>it.disconnect()},W=L(Z.current,Vt),ge=L(N.current,Jt),be=L(v.current,Xt);return()=>{W(),ge(),be()}},[r]);const{handleScroll:Zt,scrollToBottom:Qt,showScrollBtn:en,startBottomFollow:tn}=ms({scrollRef:Y,contentRef:G,bottomChromeRef:N,entries:c,entriesRef:I,instanceId:r,hasMore:f,shouldScrollToBottom:oe,onScrollToBottomHandled:Yt,onLoadMore:R,bottomChromeHeight:st,bottomSafeGap:at}),ot={title:(a==null?void 0:a.cwd.split("/").pop())||(a==null?void 0:a.cwd)||"",cwd:a==null?void 0:a.cwd,homedir:a==null?void 0:a.homedir,gitBranch:a==null?void 0:a.gitBranch,actions:t.jsx(Or,{sessions:h,loading:b,hasMore:S,total:T,disabled:ue(a==null?void 0:a.status),onOpen:_,onNewSession:M,onSwitchSession:P,onLoadMore:y,onFilterChange:w})};return t.jsxs("div",{className:"relative flex-1 min-w-0 overflow-hidden",children:[t.jsxs("main",{className:"absolute inset-0 flex min-h-0 flex-col overflow-hidden",children:[t.jsx("div",{className:"pointer-events-none absolute left-0 right-0 top-0 z-20 px-3 pt-3 md:px-4 md:pt-4",children:t.jsxs("div",{ref:Z,className:"glass-panel pointer-events-auto mx-auto w-full max-w-[920px] px-3 py-2 md:px-4 md:py-2.5",role:"region","aria-label":"Instance info",children:[t.jsx("div",{className:"hidden md:flex",children:t.jsx(ht,{...ot})}),t.jsx(Ft,{children:t.jsx(ht,{...ot})})]})}),t.jsx("div",{ref:Y,onScroll:Zt,style:{overflowAnchor:"none"},"aria-busy":O,className:"absolute bottom-[var(--bottom-safe-gap)] left-0 right-0 top-6 overflow-y-auto scrollbar-auto px-3 md:bottom-0 md:top-7 md:px-4",children:t.jsxs("div",{ref:G,style:{paddingTop:Ie.paddingTop,paddingBottom:Ie.paddingBottom},className:"mx-auto max-w-[920px] space-y-2",children:[u==="loadingMore"&&t.jsx("div",{className:"text-center text-[var(--label-tertiary)] text-[11px] py-2 select-none",children:"Loading earlier messages..."}),O?t.jsx(vs,{}):u==="error"?t.jsxs("div",{className:"mx-auto mt-8 max-w-[520px] rounded-[12px] border border-[var(--separator)] bg-[var(--fill-card)] px-4 py-3 text-center",children:[t.jsx("div",{className:"text-[13px] text-[var(--label-primary)] select-none",children:"Failed to load conversation"}),p&&t.jsx("div",{className:"mt-1 text-[12px] text-[var(--label-secondary)] break-words select-text",children:p})]}):c.length===0&&!f?t.jsx("div",{className:"text-center text-[var(--label-tertiary)] text-[12px] pt-8 select-none",children:"No messages yet"}):c.map((L,W)=>{const ge=Ue(L),be=W===c.length-1;return t.jsx("div",{"data-entry-key":ge,children:t.jsx(Nr,{entry:L,entries:c,isLast:be,isStreaming:d,onReEdit:be?K:void 0})},ge)})]})}),en&&t.jsx("div",{style:{bottom:Ie.scrollButtonBottom},className:"absolute left-1/2 z-30 -translate-x-1/2",children:t.jsx("button",{onClick:Qt,className:"select-none w-9 h-9 rounded-full bg-[var(--btn-solid)] border border-[var(--separator)] text-[var(--label-secondary)] flex items-center justify-center hover:bg-[var(--btn-solid-hover)] active:scale-95 transition-all shadow-[0_4px_20px_rgba(0,0,0,0.12)]",title:e("eventStream.scrollToBottom"),children:t.jsx(Nn,{size:16})})}),t.jsx("div",{ref:N,className:"pointer-events-none absolute bottom-0 left-0 right-0 z-20 px-3 pb-0 md:px-4",children:t.jsxs("div",{className:"pointer-events-auto mx-auto w-full max-w-[920px]",children:[t.jsx(Qr,{ref:D,instance:a,draft:o,onDraftChange:m,onSendMessage:C,onAbort:j,onSetModel:z,onSetThinkingLevel:E,onCompact:$,buttonMode:F,showCompactButton:!A,compactDisabled:H,onImageLightbox:x,startBottomFollow:tn}),t.jsx("div",{ref:v,className:"h-[var(--bottom-safe-gap)] md:h-0","aria-hidden":"true"})]})})]}),k&&t.jsx(Bt,{src:k,onClose:()=>x(null)})]})}function vs(){return t.jsx("div",{className:"space-y-3 pt-3 select-none","aria-label":"Loading conversation",children:[0,1,2,3].map(e=>t.jsxs("div",{className:"space-y-1.5 animate-pulse",children:[t.jsx("div",{className:"h-3 w-20 rounded-full bg-[var(--fill-tertiary)]"}),t.jsxs("div",{className:"max-w-[680px] space-y-1.5 rounded-[10px] border border-[var(--separator)] bg-[var(--fill-card)] p-3",children:[t.jsx("div",{className:"h-3 w-[82%] rounded-full bg-[var(--fill-secondary)]"}),t.jsx("div",{className:"h-3 w-[64%] rounded-full bg-[var(--fill-tertiary)]"})]})]},e))})}function ys(){const{t:e}=B(),n=Qe();return t.jsx("div",{className:"flex-1 flex items-center justify-center",children:t.jsxs("div",{className:"text-center select-none",children:[t.jsx("img",{src:n,alt:"Paimon",className:"w-16 h-16 mx-auto mb-4 opacity-80"}),t.jsx("div",{className:"text-[14px] text-[var(--label-tertiary)] tracking-wide",children:e("eventStream.tagline")})]})})}function js(){return t.jsx("div",{className:"relative flex-1 min-w-0 overflow-hidden flex flex-col",children:t.jsx(kn,{})})}const ws={common:{cancel:"取消",confirm:"确认",loading:"加载中…",online:"在线",offline:"离线"},login:{subtitle:"输入 Access Token 以连接",placeholder:"Access Token",invalidToken:"Token 无效,请检查后重试。",connect:"连接",verifying:"验证中…",tokenHint:"Token 可在 <1>~/.paimon/hub.json</1> 中找到"},sidebar:{newInstance:"新建实例",machine_one:"{{count}} 台机器",machine_other:"{{count}} 台机器",instance_one:"{{count}} 个实例",instance_other:"{{count}} 个实例",noInstances:"暂无 pi 实例连接",settings:"设置",shutdown:"退出实例",shutdownBusy:"实例正在执行中,请等待完成后再退出",statusStreaming:"生成中",statusCompacting:"压缩中",statusIdle:"空闲"},eventStream:{tagline:"守望 · 交互 · 掌控",sendPlaceholder:"发送消息…",scrollToBottom:"滚到底部",stop:"停止",send:"发送",attachImage:"添加图片",imageProcessFailed:"图片处理失败,请检查图片格式",statusRunning:"执行中",statusCompacting:"压缩中",statusOnline:"在线",compactContext:"压缩上下文",instanceNotFound:"实例不存在"},compact:{title:"压缩上下文",description:"压缩将总结旧的对话内容以释放上下文空间。可选填自定义提示词来指定压缩时关注的方向。",placeholder:"例如:重点保留关于数据库设计的讨论…",start:"开始压缩"},settings:{title:"设置",appearance:"外观",theme:"主题",themeLight:"浅色",themeDark:"深色",themeSystem:"系统",background:"背景",bgMist:"雾",bgAurora:"极光",bgEmber:"余烬",language:"语言",langZhCN:"简体中文",langEn:"English"},notification:{title:"通知",label:"任务完成通知",on:"开启",off:"关闭",denied:"通知权限已被浏览器拒绝,请在浏览器设置中允许",taskComplete:"✅ {{name}} 任务完成"},newInstance:{title:"新建实例",edgeNode:"Edge 节点",noEdges:"没有可用的 Edge 节点",workingDir:"工作目录",pathPlaceholder:"/path/to/your/project",create:"创建",creating:"创建中…",truncatedHint:"输入更多字符以缩小范围…",fetchEdgeError:"获取 Edge 列表失败",noEdgeSelected:"未选择 Edge 节点",requestTimeout:"请求超时",networkError:"网络错误",requestFailed:"请求失败 (HTTP {{status}})"},session:{title:"Sessions",new:"新建",filter:"筛选…",noMatch:"无匹配的 Session",noPrevious:"暂无历史 Session",empty:"空 Session",messageCount_one:"{{count}} 条消息",messageCount_other:"{{count}} 条消息",timeJustNow:"刚刚"},entries:{contextCompacted:"上下文已压缩",branchSummary:"分支摘要",thinking:"思考",thinkingStreaming:"思考中...",running:"执行中...",aborted:"已终止",copied:"已复制",copy:"复制",result:"结果",params:"参数"},reEdit:{button:"重新编辑",draftNotEmpty:"输入框已有内容,请先清空"},error:{title:"错误详情",message:"错误信息",type:"错误类型",requestId:"请求 ID",action:{compact:"压缩失败:{{message}}"}}},Ns={common:{cancel:"Cancel",confirm:"Confirm",loading:"Loading…",online:"Online",offline:"Offline"},login:{subtitle:"Enter access token to connect",placeholder:"Access Token",invalidToken:"Invalid token. Please check and try again.",connect:"Connect",verifying:"Verifying…",tokenHint:"Find your token in <1>~/.paimon/hub.json</1>"},sidebar:{newInstance:"New instance",machine_one:"{{count}} machine",machine_other:"{{count}} machines",instance_one:"{{count}} instance",instance_other:"{{count}} instances",noInstances:"No pi instances connected",settings:"Settings",shutdown:"Shutdown instance",shutdownBusy:"Instance is running, please wait before shutting down",statusStreaming:"Streaming",statusCompacting:"Compacting",statusIdle:"Idle"},eventStream:{tagline:"Watch · Interact · Control",sendPlaceholder:"Send a message...",scrollToBottom:"Scroll to bottom",stop:"Stop",send:"Send",attachImage:"Attach image",imageProcessFailed:"Image processing failed, please check the format",statusRunning:"Running",statusCompacting:"Compacting",statusOnline:"Online",compactContext:"Compact context",instanceNotFound:"Instance not found"},compact:{title:"Compact Context",description:"Compaction summarizes older conversation to free up context space. Optionally provide custom instructions to guide what to focus on.",placeholder:"e.g. Keep the discussion about database design…",start:"Start compaction"},settings:{title:"Settings",appearance:"Appearance",theme:"Theme",themeLight:"Light",themeDark:"Dark",themeSystem:"System",background:"Background",bgMist:"Mist",bgAurora:"Aurora",bgEmber:"Ember",language:"Language",langZhCN:"简体中文",langEn:"English"},notification:{title:"Notification",label:"Task Completion Notification",on:"On",off:"Off",denied:"Notification permission denied. Please allow in browser settings",taskComplete:"✅ {{name}} task completed"},newInstance:{title:"New Instance",edgeNode:"Edge Node",noEdges:"No available Edge nodes",workingDir:"Working Directory",pathPlaceholder:"/path/to/your/project",create:"Create",creating:"Creating…",truncatedHint:"Type more to narrow results…",fetchEdgeError:"Failed to fetch edge list",noEdgeSelected:"No edge selected",requestTimeout:"Request timed out",networkError:"Network error",requestFailed:"Request failed (HTTP {{status}})"},session:{title:"Sessions",new:"New",filter:"Filter…",noMatch:"No matching sessions",noPrevious:"No previous sessions",empty:"Empty session",messageCount_one:"{{count}} message",messageCount_other:"{{count}} messages",timeJustNow:"just now"},entries:{contextCompacted:"Context compacted",branchSummary:"Branch summary",thinking:"Thinking",thinkingStreaming:"Thinking...",running:"Running...",aborted:"Aborted",copied:"Copied",copy:"Copy",result:"Result",params:"Parameters"},reEdit:{button:"Edit",draftNotEmpty:"Input is not empty, please clear first"},error:{title:"Error Details",message:"Error message",type:"Error type",requestId:"Request ID",action:{compact:"Compaction failed: {{message}}"}}},Wt="paimon:language";function ks(){const e=localStorage.getItem(Wt);return e==="zh-CN"||e==="en"?e:"zh-CN"}function Ss(e){localStorage.setItem(Wt,e),Ve.changeLanguage(e)}Ve.use(Sn).init({resources:{"zh-CN":{translation:ws},en:{translation:Ns}},lng:ks(),fallbackLng:"zh-CN",interpolation:{escapeValue:!1}});function Fe({options:e,value:n,onChange:r}){return t.jsx("div",{className:"flex rounded-[8px] bg-[var(--fill-secondary)] p-[2px] select-none",children:e.map(s=>t.jsx("button",{onClick:()=>r(s.value),className:`px-3 py-1.5 rounded-[6px] text-[13px] leading-[18px] transition-all ${n===s.value?"bg-[var(--panel-bg)] text-[var(--label-primary)] font-semibold shadow-sm backdrop-blur-sm":"text-[var(--label-secondary)] font-normal hover:text-[var(--label-primary)]"}`,children:s.label},s.value))})}function ye({label:e,children:n,showSeparator:r=!0}){return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 select-none",children:[t.jsx("span",{className:"text-[14px] leading-[20px] font-semibold text-[var(--label-primary)]",children:e}),n]}),r&&t.jsx("div",{className:"ml-4 border-b border-[var(--separator)]"})]})}function Cs({value:e,onChange:n,options:r}){return t.jsx("div",{className:"flex items-center gap-3 select-none",children:r.map(s=>t.jsxs("button",{onClick:()=>n(s.value),className:"flex flex-col items-center gap-1",children:[t.jsx("div",{className:`w-7 h-7 rounded-full transition-all ${e===s.value?"ring-2 ring-[var(--color-accent)] ring-offset-1":"hover:scale-110"}`,style:{background:`conic-gradient(${s.colors.join(", ")})`}}),t.jsx("span",{className:`text-[12px] leading-[16px] ${e===s.value?"text-[var(--label-primary)] font-semibold":"text-[var(--label-secondary)] font-normal"}`,children:s.label})]},s.value))})}function Es(){const{t:e,i18n:n}=B(),[r,s]=Gn(),[a,o]=_t(),[i,c]=Jn(),d=[{value:"light",label:e("settings.themeLight")},{value:"dark",label:e("settings.themeDark")},{value:"system",label:e("settings.themeSystem")}],u=[{value:"mist",label:e("settings.bgMist"),colors:["#e8f0fe","#f5e6f0","#e6f0f5","#f0f5e6"]},{value:"aurora",label:e("settings.bgAurora"),colors:["#a8d8ea","#aa96da","#8fd3c4","#c4a8d8"]},{value:"ember",label:e("settings.bgEmber"),colors:["#f8d4b0","#f0b0c0","#f8e0a0","#e8c0d0"]}],p=[{value:"zh-CN",label:e("settings.langZhCN")},{value:"en",label:e("settings.langEn")}],f=[{value:"on",label:e("notification.on")},{value:"off",label:e("notification.off")}];return t.jsx("div",{className:"flex-1 flex items-start justify-center p-4 md:p-6 overflow-y-auto scrollbar-auto",children:t.jsxs("div",{className:"w-full max-w-[480px]",children:[t.jsx(Ft,{title:e("settings.title")}),t.jsx("h1",{className:"hidden md:block text-[22px] font-semibold text-[var(--label-primary)] mb-6 px-4 select-none",children:e("settings.title")}),t.jsx("div",{className:"text-[14px] leading-[20px] font-semibold text-[var(--label-primary)] mb-2 px-4 select-none",children:e("settings.appearance")}),t.jsxs("section",{className:"glass-panel overflow-hidden",children:[t.jsx(ye,{label:e("settings.theme"),children:t.jsx(Fe,{options:d,value:r,onChange:s})}),t.jsx(ye,{label:e("settings.background"),showSeparator:!1,children:t.jsx(Cs,{value:a,onChange:o,options:u})})]}),t.jsx("div",{className:"text-[14px] leading-[20px] font-semibold text-[var(--label-primary)] mb-2 mt-6 px-4 select-none",children:e("settings.language")}),t.jsx("section",{className:"glass-panel overflow-hidden",children:t.jsx(ye,{label:e("settings.language"),showSeparator:!1,children:t.jsx(Fe,{options:p,value:n.language,onChange:Ss})})}),Ot&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"text-[14px] leading-[20px] font-semibold text-[var(--label-primary)] mb-2 mt-6 px-4 select-none",children:e("notification.title")}),t.jsx("section",{className:"glass-panel overflow-hidden",children:t.jsx(ye,{label:e("notification.label"),showSeparator:!1,children:t.jsx(Fe,{options:f,value:i?"on":"off",onChange:async h=>{h==="on"?await Notification.requestPermission()==="granted"?c(!0):ee(e("notification.denied"),"warning"):c(!1)}})})})]})]})})}async function Ye(e,n){const r=Tt(),s=new Headers(n==null?void 0:n.headers);r&&s.set("Authorization",`Bearer ${r}`);const a=await fetch(e,{...n,headers:s});return a.status===401&&(Rt(),window.location.reload()),a}function Ts({value:e,onChange:n,edgeId:r,disabled:s=!1,autoFocus:a=!1,onSubmit:o}){const{t:i}=B(),[c,d]=l.useState([]),[u,p]=l.useState(!1),[f,h]=l.useState(!1),[b,S]=l.useState(-1),[T,R]=l.useState(!1),g=l.useRef(null),m=l.useRef(null),C=l.useRef(null),j=l.useRef(null);l.useEffect(()=>()=>{var y;(y=C.current)==null||y.abort()},[]),l.useEffect(()=>{var y;a&&((y=g.current)==null||y.focus())},[a]);const z=l.useCallback(async(y,w)=>{C.current&&C.current.abort();const M=new AbortController;C.current=M,h(!0);try{const $=await(await Ye(`/api/edges/${encodeURIComponent(y)}/browse?path=${encodeURIComponent(w)}`,{signal:M.signal})).json();if(M.signal.aborted)return;$.error?(d([]),p(!1),R(!1)):(d($.entries??[]),p($.truncated??!1),R(($.entries??[]).length>0||$.truncated)),S(-1)}catch{M.signal.aborted||(d([]),R(!1))}finally{M.signal.aborted||h(!1)}},[]);l.useEffect(()=>{if(!r||!e||!e.startsWith("/")){d([]),R(!1);return}return j.current&&clearTimeout(j.current),j.current=setTimeout(()=>{z(r,e)},250),()=>{j.current&&clearTimeout(j.current)}},[e,r,z]);const E=l.useCallback(y=>{var $;const P=(e.endsWith("/")?e:e.substring(0,e.lastIndexOf("/")+1))+y.name+"/";n(P),S(-1),($=g.current)==null||$.focus()},[e,n]),_=l.useCallback(y=>{if(T&&c.length>0){if(y.key==="ArrowDown"){y.preventDefault(),S(w=>w<c.length-1?w+1:0);return}if(y.key==="ArrowUp"){y.preventDefault(),S(w=>w>0?w-1:c.length-1);return}if(y.key==="Tab"){y.preventDefault(),b>=0&&b<c.length?E(c[b]):c.length===1&&E(c[0]);return}if(y.key==="Enter"&&b>=0&&b<c.length){y.preventDefault(),E(c[b]);return}if(y.key==="Escape"){y.preventDefault(),R(!1),S(-1);return}}y.key==="Enter"&&(y.preventDefault(),o==null||o())},[T,c,b,E,o]);return l.useEffect(()=>{if(b<0||!m.current)return;const w=m.current.children[b];w==null||w.scrollIntoView({block:"nearest"})},[b]),l.useEffect(()=>{d([]),R(!1),S(-1)},[r]),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsxs("div",{className:"relative",children:[t.jsx("input",{ref:g,type:"text",value:e,onChange:y=>n(y.target.value),onKeyDown:_,onFocus:()=>{c.length>0&&R(!0)},onBlur:()=>{setTimeout(()=>R(!1),150)},placeholder:i("newInstance.pathPlaceholder"),disabled:s,spellCheck:!1,autoComplete:"off",className:"w-full rounded-[10px] px-3 py-2 bg-[var(--fill-tertiary)] border border-[var(--separator)] text-[14px] leading-[20px] text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] outline-none focus:border-[var(--color-accent)] transition-colors disabled:opacity-50 pr-8"}),f&&t.jsx("div",{className:"absolute right-2.5 top-1/2 -translate-y-1/2",children:t.jsx(de,{size:14,className:"animate-spin text-[var(--label-tertiary)]"})})]}),T&&t.jsxs("div",{ref:m,className:"max-h-[200px] overflow-y-auto rounded-[10px] border border-[var(--separator)] bg-[var(--fill-quaternary)]",children:[c.map((y,w)=>t.jsxs("button",{type:"button",onMouseDown:M=>{M.preventDefault(),E(y)},onMouseEnter:()=>S(w),className:`w-full flex items-center gap-2 px-3 py-1.5 text-left text-[13px] transition-colors ${w===b?"bg-[var(--fill-secondary)]":"hover:bg-[var(--fill-tertiary)]"}`,children:[t.jsx(St,{size:14,className:"shrink-0 text-[var(--label-tertiary)]"}),t.jsx("span",{className:"text-[var(--label-primary)] truncate",children:y.name})]},y.name)),u&&t.jsx("div",{className:"px-3 py-1.5 text-[12px] text-[var(--label-tertiary)] border-t border-[var(--separator)]",children:i("newInstance.truncatedHint")})]})]})}function Rs({onClose:e,onCreated:n}){const{t:r}=B(),[s,a]=l.useState(""),[o,i]=l.useState([]),[c,d]=l.useState(""),[u,p]=l.useState(!0),[f,h]=l.useState(!1),[b,S]=l.useState(null);l.useEffect(()=>{Ye("/api/edges").then(g=>g.json()).then(g=>{if(i(g.edges),g.edges.length>0){d(g.edges[0].edgeId);const m=g.edges[0].homedir;if(m){const C=m.endsWith("/")?m:m+"/";a(C)}}p(!1)}).catch(()=>{p(!1),S(r("newInstance.fetchEdgeError"))})},[]);const T=l.useCallback(g=>{d(g);const m=o.find(C=>C.edgeId===g);if(m!=null&&m.homedir){const C=m.homedir.endsWith("/")?m.homedir:m.homedir+"/";a(C)}},[o]),R=l.useCallback(async()=>{const g=s.trim();if(!(!g||f)){if(!c){S(r("newInstance.noEdgeSelected"));return}h(!0),S(null);try{const m=await Ye("/api/instances",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({cwd:g,edgeId:c}),signal:AbortSignal.timeout(2e4)}),C=await m.json();if(!m.ok||!C.instanceId){S(C.error||r("newInstance.requestFailed",{status:m.status})),h(!1);return}n(C.instanceId)}catch(m){const C=m.name==="TimeoutError"?r("newInstance.requestTimeout"):m.message||r("newInstance.networkError");S(C),h(!1)}}},[s,f,c,n]);return t.jsx(X,{title:t.jsxs(t.Fragment,{children:[t.jsx(Cn,{size:16}),t.jsx("span",{children:r("newInstance.title")})]}),onClose:e,children:t.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"text-[13px] text-[var(--label-secondary)]",children:r("newInstance.edgeNode")}),u?t.jsx("div",{className:"text-[13px] text-[var(--label-tertiary)]",children:r("common.loading")}):o.length===0?t.jsx("div",{className:"text-[12px] text-[#ff4245]",children:r("newInstance.noEdges")}):o.length===1?t.jsxs("div",{className:"text-[13px] text-[var(--label-primary)]",children:[o[0].hostname,t.jsxs("span",{className:"text-[var(--label-tertiary)] ml-1.5",children:["(",o[0].edgeId,")"]})]}):t.jsx("select",{value:c,onChange:g=>T(g.target.value),disabled:f,className:"w-full rounded-[10px] px-3 py-2 bg-[var(--fill-tertiary)] border border-[var(--separator)] text-[14px] text-[var(--label-primary)] outline-none focus:border-[var(--color-accent)] transition-colors disabled:opacity-50",children:o.map(g=>t.jsxs("option",{value:g.edgeId,children:[g.hostname," (",g.edgeId,")"]},g.edgeId))})]}),t.jsxs("div",{className:"flex flex-col gap-1.5",children:[t.jsx("label",{className:"text-[13px] text-[var(--label-secondary)]",children:r("newInstance.workingDir")}),t.jsx(Ts,{value:s,onChange:a,edgeId:c,disabled:f||u,autoFocus:!u,onSubmit:R})]}),b&&t.jsx("div",{className:"text-[12px] leading-[16px] text-[#ff4245] whitespace-pre-wrap break-words",children:b}),t.jsxs("div",{className:"flex items-center justify-end gap-2 pt-1",children:[t.jsx("button",{onClick:e,disabled:f,className:"px-3.5 py-1.5 rounded-[8px] text-[13px] text-[var(--label-secondary)] hover:bg-[var(--fill-tertiary)] transition-colors disabled:opacity-50",children:r("common.cancel")}),t.jsx("button",{onClick:R,disabled:f||!s.trim()||!c,className:"px-3.5 py-1.5 rounded-[8px] text-[13px] font-medium text-white bg-[var(--color-accent)] hover:opacity-90 transition-opacity disabled:opacity-40",children:r(f?"newInstance.creating":"newInstance.create")})]})]})})}function Ms({onLogin:e,error:n}){const{t:r}=B(),[s,a]=l.useState(""),[o,i]=l.useState(!1),[c,d]=l.useState(!1),u=Qe(),p=l.useCallback(async f=>{f.preventDefault();const h=s.trim();if(!(!h||o)){i(!0),d(!1);try{if((await fetch("/api/instances",{headers:{Authorization:`Bearer ${h}`}})).status===401){d(!0),i(!1);return}}catch{}i(!1),Bn(h),e(h)}},[s,o,e]);return t.jsx("div",{className:"fixed-viewport flex items-center justify-center p-4 overflow-y-auto",children:t.jsxs("form",{onSubmit:p,className:"glass-panel w-full max-w-[380px] p-8 flex flex-col items-center gap-6",children:[t.jsx("img",{src:u,alt:"Paimon",className:"w-16 h-16 select-none",draggable:!1}),t.jsxs("div",{className:"text-center",children:[t.jsx("h1",{className:"text-[17px] font-semibold text-[var(--label-primary)]",children:"Paimon"}),t.jsx("p",{className:"mt-1 text-[13px] text-[var(--label-secondary)]",children:r("login.subtitle")})]}),t.jsxs("div",{className:"w-full",children:[t.jsx("input",{type:"password",value:s,onChange:f=>a(f.target.value),placeholder:r("login.placeholder"),autoFocus:!0,className:`w-full h-9 px-3 rounded-[9px] text-[13px] bg-[var(--fill-primary)] text-[var(--label-primary)] placeholder:text-[var(--label-tertiary)] border outline-none transition-colors ${n||c?"border-red-500 focus:border-red-500":"border-[var(--separator)] focus:border-[var(--color-accent)]"}`}),(n||c)&&t.jsx("p",{className:"mt-2 text-[11px] text-red-500",children:r("login.invalidToken")})]}),t.jsx("button",{type:"submit",disabled:!s.trim()||o,className:"w-full h-9 rounded-[1000px] bg-[var(--color-accent)] text-white text-[13px] font-medium transition-opacity disabled:opacity-40 hover:opacity-90 active:opacity-80",children:r(o?"login.verifying":"login.connect")}),t.jsx("p",{className:"text-[11px] text-[var(--label-tertiary)] text-center leading-relaxed",children:t.jsx(En,{i18nKey:"login.tokenHint",components:{1:t.jsx("code",{className:"px-1 py-0.5 rounded bg-[var(--fill-secondary)] text-[var(--label-secondary)]"})}})})]})})}function Is(){const{pathname:e}=Rn(),n=e.match(/^\/instance\/(.+)$/);return n?n[1]:null}function As(){const{t:e}=B(),{authToken:n,authError:r,handleLogin:s,handleAuthError:a}=Fn(),o=U(j=>j.connect),i=U(j=>j.disconnect),c=U(j=>j.subscribe),d=U(j=>j.send),u=re(j=>j.instances),p=re(j=>j.instanceListReady),f=re(j=>j.handleMessage),h=Me();zn();const b=Is();l.useEffect(()=>(n?o(n,a):i(),()=>i()),[n,o,i,a]),er(),l.useEffect(()=>c(j=>{(j.type==="instance_list"||j.type==="instance_update")&&f(j)}),[c,f]);const S=l.useCallback(j=>{h(`/instance/${j}`)},[h]),T=l.useRef(new Set),R=l.useCallback(j=>{const z=re.getState().instances.find(E=>E.id===j);if(z&&ue(z.status)){ee(e("sidebar.shutdownBusy"),"warning");return}T.current.add(j),d({type:"shutdown",payload:{instanceId:j}})},[d,e]),[g,m]=l.useState(!1),C=l.useCallback(j=>{m(!1),h(`/instance/${j}`)},[h]);return l.useEffect(()=>{if(!p||!b)return;u.some(z=>z.id===b)||(T.current.has(b)?T.current.delete(b):ee(e("eventStream.instanceNotFound"),"error"),h("/"))},[p,b,u,h,e]),n?t.jsxs("div",{className:"h-[var(--app-viewport-height,100dvh)] w-screen animated-bg flex items-stretch p-2 gap-2 md:p-3 md:gap-3 overflow-hidden pb-[max(0.5rem,env(safe-area-inset-bottom))]",children:[t.jsx("div",{className:"hidden md:flex self-stretch",children:t.jsx(ut,{instances:u,selectedId:b,onSelect:S,onShutdown:R,onNewInstance:()=>m(!0)})}),t.jsx(Tn,{children:t.jsxs(ve,{element:t.jsx(js,{}),children:[t.jsx(ve,{path:"/settings",element:t.jsx(Es,{})}),t.jsx(ve,{path:"/instance/:id",element:t.jsx(bs,{})}),t.jsx(ve,{path:"*",element:t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 md:hidden min-w-0 flex flex-col",children:t.jsx(ut,{instances:u,selectedId:b,onSelect:S,onShutdown:R,onNewInstance:()=>m(!0)})}),t.jsx("div",{className:"hidden md:flex flex-1 min-w-0",children:t.jsx(ys,{})})]})})]})}),g&&t.jsx(Rs,{onClose:()=>m(!1),onCreated:C}),t.jsx(Gr,{})]}):t.jsx("div",{className:"h-[var(--app-viewport-height,100dvh)] w-screen animated-bg flex items-stretch overflow-hidden",children:t.jsx(Ms,{onLogin:s,error:r})})}rn.createRoot(document.getElementById("root")).render(t.jsx(Mn,{children:t.jsx(As,{})}));
|