pikiloom 0.4.24 → 0.4.26
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/dashboard/dist/assets/{AgentTab-D3U-vwIw.js → AgentTab-BNJ73P0m.js} +1 -1
- package/dashboard/dist/assets/{ConnectionModal-DQHeAsB3.js → ConnectionModal-Dt05H2f9.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-AO4JoPpf.js → DirBrowser-D-GT-G-w.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-BCCPKzoi.js → ExtensionsTab-BrJMulJR.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-Bc20xVsq.js → IMAccessTab-auPnx468.js} +1 -1
- package/dashboard/dist/assets/{Modal-Ds_Yj4DN.js → Modal-lYfO9m-I.js} +1 -1
- package/dashboard/dist/assets/{Modals-VhIHAoTS.js → Modals-PRdWOIY9.js} +1 -1
- package/dashboard/dist/assets/{Select-B2e5zNQe.js → Select-BhbU-rll.js} +1 -1
- package/dashboard/dist/assets/SessionPanel-_0dLWvEb.js +1 -0
- package/dashboard/dist/assets/{SystemTab--Qlps8hZ.js → SystemTab-CN_QrRKt.js} +1 -1
- package/dashboard/dist/assets/index-CP3LYJR2.js +23 -0
- package/dashboard/dist/assets/{index-CxKN1UnH.js → index-C_neLnaO.js} +3 -3
- package/dashboard/dist/assets/{shared-DTiZXFp_.js → shared-C5uXvhZJ.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dist/agent/session.js +11 -3
- package/package.json +1 -1
- package/dashboard/dist/assets/SessionPanel-DD1k_k6Z.js +0 -1
- package/dashboard/dist/assets/index-CV4bsimV.js +0 -23
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s}from"./react-vendor-C7Sl8SE7.js";import{N as t,m as i,S as a}from"./index-
|
|
1
|
+
import{j as s}from"./react-vendor-C7Sl8SE7.js";import{N as t,m as i,S as a}from"./index-C_neLnaO.js";function o({primary:e,secondary:l,tertiary:n}){return s.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e&&s.jsxs(i,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(i,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),n&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:n})]})}function c({children:e,className:l}){return s.jsx(t,{padding:"md",elevation:"flat",className:l,children:e})}export{o as A,c as S};
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
<link rel="icon" type="image/png" href="/logo.png">
|
|
7
7
|
<title>Pikiloom</title>
|
|
8
8
|
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-C_neLnaO.js"></script>
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/react-vendor-C7Sl8SE7.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/router-DHISdpPk.js">
|
|
12
12
|
<link rel="stylesheet" crossorigin href="/assets/index-CyCspgtc.css">
|
package/dist/agent/session.js
CHANGED
|
@@ -553,10 +553,18 @@ export function importFilesIntoWorkspace(workspacePath, files) {
|
|
|
553
553
|
const imported = [];
|
|
554
554
|
const realWorkspace = fs.realpathSync(workspacePath);
|
|
555
555
|
for (const filePath of files) {
|
|
556
|
-
const
|
|
557
|
-
if (!fs.existsSync(
|
|
556
|
+
const resolved = path.resolve(filePath);
|
|
557
|
+
if (!fs.existsSync(resolved) || !fs.statSync(resolved).isFile())
|
|
558
558
|
continue;
|
|
559
|
-
|
|
559
|
+
// Resolve symlinks on the source too — realWorkspace is already realpath'd,
|
|
560
|
+
// so comparing it against a merely path.resolve'd source makes a file that
|
|
561
|
+
// ALREADY lives in the workspace look "outside" whenever a path component is
|
|
562
|
+
// a symlink (macOS /tmp → /private/tmp, or an iCloud-synced ~/Desktop). That
|
|
563
|
+
// mis-detection re-copies an already-staged attachment under a collision
|
|
564
|
+
// name, so the same image lands in the prompt TWICE and renders twice.
|
|
565
|
+
// realpath'ing both sides keeps the in-workspace check symlink-safe.
|
|
566
|
+
const sourcePath = fs.realpathSync(resolved);
|
|
567
|
+
const relPath = path.relative(realWorkspace, sourcePath);
|
|
560
568
|
if (relPath && !relPath.startsWith('..') && !path.isAbsolute(relPath)) {
|
|
561
569
|
imported.push(relPath.split(path.sep).join(path.posix.sep));
|
|
562
570
|
continue;
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as t,j as n}from"./react-vendor-C7Sl8SE7.js";import{c as pt,I as xt,S as ke,m as Se,a as j,u as Xe,d as kt,g as St,l as bt,e as vt,j as yt,f as It,s as Tt,X as jt}from"./index-CxKN1UnH.js";import{l as Rt,n as Ye,m as wt,a as Nt,b as Ot,p as Et,T as Mt,R as Lt,U as Ve,c as Ct,d as Ge,e as At,L as Pt,I as Ft}from"./index-CV4bsimV.js";import{M as Ze,a as et}from"./Modal-Ds_Yj4DN.js";import"./router-DHISdpPk.js";import"./Select-B2e5zNQe.js";import"./DirBrowser-AO4JoPpf.js";import"./markdown-DxQYQFeH.js";import"./ExtensionsTab-BCCPKzoi.js";function Ht({snapshot:f}){const[r,h]=t.useState(f.currentIndex??0),[L,R]=t.useState(""),[x,p]=t.useState(!1),[W,k]=t.useState(null);t.useEffect(()=>{h(f.currentIndex??0),R(""),k(null)},[f.promptId,f.currentIndex]);const w=f.questions||[],v=w[r]||null,X=w.length,N=!!(v?.options&&v.options.length),d=N?!!v?.allowFreeform:!0,F=o=>{o&&(h(g=>g+1),R(""))},ne=async o=>{if(!x){p(!0),k(null);try{const g=await j.interactionSelectOption(f.promptId,o);if(!g.ok){k(g.error||"Failed to submit selection.");return}F(g.advanced)}catch(g){k(g?.message||"Network error.")}finally{p(!1)}}},O=async()=>{if(x)return;const o=L.trim();if(!o&&!v?.allowEmpty){k("Please enter a response.");return}p(!0),k(null);try{const g=await j.interactionSubmitText(f.promptId,o);if(!g.ok){k(g.error||"Failed to submit answer.");return}F(g.advanced)}catch(g){k(g?.message||"Network error.")}finally{p(!1)}},m=async()=>{if(!x){p(!0),k(null);try{const o=await j.interactionSkip(f.promptId);if(!o.ok){k(o.error||"Failed to skip.");return}F(o.advanced)}catch(o){k(o?.message||"Network error.")}finally{p(!1)}}},H=async()=>{if(!x){p(!0);try{await j.interactionCancel(f.promptId)}catch{}}},Y=t.useMemo(()=>{const o=[];return f.hint&&o.push(f.hint),X>1&&o.push(`Question ${r+1} of ${X}`),o.join(" · ")||void 0},[f.hint,r,X]);return n.jsxs(Ze,{open:!0,onClose:H,wide:N&&(v?.options?.length||0)>3,children:[n.jsx(et,{title:f.title||"Pikiloom needs your input",description:Y,onClose:H}),v?n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-fg-5",children:v.header||"Question"}),n.jsx("div",{className:"mt-1 whitespace-pre-wrap text-sm leading-relaxed text-fg",children:v.prompt})]}),N&&n.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:(v.options||[]).map(o=>n.jsxs("button",{type:"button",disabled:x,onClick:()=>ne(o.value||o.label),className:pt("group rounded-lg border border-edge bg-panel-alt px-3 py-2 text-left text-sm transition","hover:border-control-border-h hover:bg-control-h hover:shadow-sm","focus:outline-none focus:ring-2 focus:ring-[var(--th-glow-a)]","disabled:cursor-not-allowed disabled:opacity-50"),children:[n.jsx("div",{className:"font-medium text-fg group-hover:text-fg",children:o.label}),o.description&&n.jsx("div",{className:"mt-0.5 text-xs leading-snug text-fg-4",children:o.description})]},o.value||o.label))}),d&&n.jsx("div",{children:n.jsx(xt,{value:L,onChange:o=>R(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.shiftKey&&!x&&(o.preventDefault(),O())},placeholder:N?"Or type a custom answer…":"Type your answer…",disabled:x,autoFocus:!N})}),W&&n.jsx("div",{className:"rounded-md border border-red-300/40 bg-red-500/10 px-3 py-2 text-xs text-red-600",children:W}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("div",{className:"text-xs text-fg-5",children:x?n.jsxs("span",{className:"inline-flex items-center gap-2",children:[n.jsx(ke,{})," Submitting…"]}):n.jsxs("span",{children:["Press ",n.jsx("kbd",{className:"rounded border border-edge bg-panel-alt px-1.5 py-0.5 text-[10px] uppercase",children:"Enter"})," to send"]})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(Se,{variant:"ghost",size:"sm",onClick:m,disabled:x,children:"Skip"}),d&&n.jsx(Se,{variant:"primary",size:"sm",onClick:O,disabled:x||!L.trim()&&!v.allowEmpty,children:"Submit"})]})]})]}):n.jsxs("div",{className:"py-6 text-center text-sm text-fg-5",children:[n.jsx(ke,{className:"mr-2 inline-block"})," Waiting for the agent…"]})]})}const Pe=12,Je=160,qt=96,Dt=[],Ut=[],_t=[],$t=20,z=new Map;function Bt(f,r){return`${f}:${r}`}function Qt(f,r){for(z.delete(f),z.set(f,r);z.size>$t;)z.delete(z.keys().next().value)}const er=t.memo(function({session:r,workdir:h,active:L=!0,onSessionChange:R,initialPendingPrompt:x,initialPendingImageUrls:p,onPendingPromptConsumed:W}){const k=Xe(e=>e.locale),w=Xe(e=>e.agentStatus?.agents?.find(s=>s.agent===r.agent)??null),v=w?.selectedEffort??null,X=w?.selectedModel??null,N=w?.byokProviderName??null,d=t.useMemo(()=>kt(k),[k]),F=St(r.agent||""),ne=bt(r),O=!!x||!!(p&&p.length),[m,H]=t.useState(null),[Y,o]=t.useState(!O),[g,Fe]=t.useState(!1),[i,q]=t.useState(null),[V,G]=t.useState(!1),[se,be]=t.useState(null),[tt,He]=t.useState(0),[rt,ve]=t.useState(null),[le,ae]=t.useState([]),[nt,oe]=t.useState([]),[J,ye]=t.useState([]),[S,ue]=t.useState(x||null),[E,ce]=t.useState(p||[]),[st,ie]=t.useState(null),Ie=t.useRef(null);Ie.current=st;const[qe,D]=t.useState([]),De=t.useRef([]);De.current=qe;const Z=t.useRef(null),[lt,Ue]=t.useState(null),[de,ee]=t.useState(null),[te,Te]=t.useState(""),[C,je]=t.useState(!1),at=!!w?.capabilities?.fork,Re=t.useRef(null),U=t.useRef(p||[]),M=t.useRef(i),_e=t.useRef(V);M.current=i,_e.current=V;const A=t.useRef(null),fe=t.useRef(null),_=t.useRef(!0),$=t.useRef(!1),me=t.useRef(null),we=t.useRef(!1),B=t.useRef(O),re=t.useRef(!1),P=t.useRef(!1),Ne=t.useRef(!1),Oe=t.useRef(!1),$e=t.useRef({model:null,effort:null}),ot=t.useCallback(e=>{$e.current=e},[]);t.useEffect(()=>{Ne.current||!O||(Ne.current=!0,x&&!S&&ue(x),p&&p.length&&!E.length&&(ce(p),U.current=p),o(!1),He(e=>e+1),W?.())},[O,W]);const I=t.useCallback(()=>{ue(null),ce(e=>{for(const s of e)URL.revokeObjectURL(s);return[]}),U.current=[],ie(null)},[]),Q=t.useCallback(()=>{D(e=>{if(!e.length)return e;for(const s of e)for(const l of s.imageUrls)URL.revokeObjectURL(l);return[]}),Z.current=null},[]),Be=t.useCallback((e,s)=>{const l=!!M.current||_e.current,a=s||[];if(l){const u=`local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;Z.current=u,D(c=>[...c,{localId:u,taskId:null,prompt:e||"",imageUrls:a}]);return}for(const u of U.current)URL.revokeObjectURL(u);Z.current=null,ue(e||null),ce(a),U.current=a,ie(null)},[]),ut=t.useCallback(e=>{const s=Z.current;if(s){Z.current=null,D(l=>{const a=l.findIndex(c=>c.localId===s);if(a<0)return l;const u=l.slice();return u[a]={...u[a],taskId:e},u});return}ie(e)},[]),ct=t.useCallback(async()=>{if(!de)return;const e=te.trim();if(e){je(!0);try{const s=await j.forkSession(h,r.agent||"",r.sessionId,de.atTurn,e,{});if(!s.ok||!s.sessionKey){je(!1);return}const[l,a]=s.sessionKey.split(":");ee(null),Te(""),R?.({agent:l,sessionId:a,workdir:h})}finally{je(!1)}}},[de,te,h,r.agent,r.sessionId,R]);Re.current=ct;const ge=t.useCallback(async(e,s={})=>{try{const l=await Rt({workdir:h,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:s.force});return l.ok?Ye(l):null}catch{return null}},[h,r.agent,r.sessionId]),T=t.useCallback(async({keepOlder:e,force:s=!1,scrollToBottom:l=!1})=>{const a=r.sessionId;if(me.current===a)return!1;me.current=a;try{const u=await ge({turnOffset:0,turnLimit:Pe},{force:s});if(!u||r.sessionId!==a)return!1;if(l&&($.current=!0),H(c=>!c||!e?u:wt(c,u)),o(!1),re.current&&(re.current=!1,I()),P.current){const c=P.current;P.current=!1;const b=c!==!0?c.taskId:null;M.current&&(c===!0||M.current.taskId===b)&&q(null)}return!0}finally{me.current===a&&(me.current=null)}},[ge,I,r.sessionId]),he=t.useCallback(async()=>{if(!m?.hasOlder||we.current)return;const e=A.current;e&&(fe.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),we.current=!0,Fe(!0);try{const s=await ge({turnOffset:Math.max(0,m.totalTurns-m.startTurn),turnLimit:Pe});s?H(l=>l?Nt(l,s):s):fe.current=null}finally{we.current=!1,Fe(!1)}},[ge,m]),pe=t.useRef(null),K=t.useCallback(e=>{if(e?.sessionId&&e.sessionId!==r.sessionId&&(Oe.current=!0,Ee.current=`${r.agent}:${e.sessionId}`,R?.({agent:r.agent||"",sessionId:e.sessionId,workdir:h})),!e){const l=pe.current;G(!1),l==="streaming"?(re.current=!0,P.current=!0,T({keepOlder:!0,force:!0,scrollToBottom:_.current})):q(null),l==="done"?(I(),Q()):l===null&&B.current&&T({keepOlder:!0,force:!0}),l!==null&&(B.current=!1),ve(null),be(null),ae([]),oe([]),ye([]),pe.current=null;return}if(be(e.phase),ve(e.taskId||null),ae(e.queuedTaskIds&&e.queuedTaskIds.length?e.queuedTaskIds:Dt),oe(e.queuedTasks&&e.queuedTasks.length?e.queuedTasks:Ut),ye(Array.isArray(e.interactions)&&e.interactions.length?e.interactions:_t),e.phase==="streaming"){if(P.current&&M.current&&M.current.taskId!==null&&M.current.taskId!==(e.taskId||null)&&!(e.text||"").trim()||q({taskId:e.taskId||null,phase:"streaming",text:e.text||"",thinking:e.thinking||"",activity:e.activity,plan:e.plan??null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,startedAt:typeof e.startedAt=="number"?e.startedAt:null,error:null,question:e.question??null}),G(!0),e.taskId&&e.taskId!==Ie.current){const a=De.current,u=a.findIndex(c=>c.taskId===e.taskId);if(u>=0){const c=a[u];for(const b of U.current)URL.revokeObjectURL(b);ue(c.prompt||null),ce(c.imageUrls),U.current=c.imageUrls,ie(e.taskId),D(b=>b.filter((gt,ht)=>ht!==u))}}_.current&&($.current=!0)}else if(e.phase==="queued")q(null),G(!1);else if(e.phase==="done"){G(!1),q(b=>b?{...b,phase:"done",error:e.error??null}:e.error?{taskId:e.taskId||null,phase:"done",text:"",thinking:"",activity:"",plan:null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,error:e.error}:b);const l=!!e.queuedTaskIds?.length,a=M.current,u=!!a&&Ot(a),c=!!e.incomplete&&u&&!l;pe.current!=="done"&&(l||(re.current=!0),P.current=c?!1:{taskId:e.taskId||null},T({keepOlder:!0,force:!0,scrollToBottom:_.current})),l||(B.current=!1)}const s=new Set;if(e.taskId&&s.add(e.taskId),Array.isArray(e.queuedTaskIds))for(const l of e.queuedTaskIds)s.add(l);D(l=>{let a=!1;const u=[];for(const c of l)if(!c.taskId||s.has(c.taskId))u.push(c);else{for(const b of c.imageUrls)URL.revokeObjectURL(b);a=!0}return a?u:l}),pe.current=e.phase},[I,Q,T,r.sessionId,r.agent,R,h]),Qe=t.useRef(K);Qe.current=K;const Ke=t.useCallback(()=>{B.current=!0,He(e=>e+1)},[]),it=t.useCallback(async e=>{try{await j.recallSessionMessage(e),Ie.current===e&&I(),D(s=>{let l=!1;const a=[];for(const u of s)if(u.taskId===e){for(const c of u.imageUrls)URL.revokeObjectURL(c);l=!0}else a.push(u);return l?a:s}),ae(s=>s.filter(l=>l!==e)),oe(s=>s.filter(l=>l.taskId!==e)),ve(s=>s===e?null:s)}catch{}},[I]),dt=t.useCallback(async e=>{try{await j.steerSession(e)}catch{}},[]),ft=t.useCallback(async()=>{try{await j.stopSession(r.agent||"",r.sessionId)}catch{}},[r.agent,r.sessionId]),xe=Bt(r.agent||"",r.sessionId);t.useEffect(()=>{if(Oe.current){Oe.current=!1;let u=!1;return T({keepOlder:!0,force:!0}).finally(()=>{u||o(!1)}),()=>{u=!0}}let e=!1;const s=Et({workdir:h,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:Pe},{allowStale:!0}),l=O&&!Ne.current,a=s?.ok?Ye(s):z.get(xe)||null;return o(l?!1:!a),H(a),q(null),G(!1),be(null),ae([]),oe([]),ye([]),l||(I(),Q(),B.current=!1,re.current=!1,P.current=!1),_.current=!0,$.current=!0,l||T({keepOlder:!1,force:!0}).finally(()=>{e||o(!1)}),()=>{e=!0}},[T,r.agent,r.sessionId,h,xe,I,Q]),t.useEffect(()=>{m&&m.turns.length>0&&Qt(xe,m)},[xe,m]),t.useEffect(()=>{L&&T({keepOlder:!0,force:!0})},[L,T]);const Ee=t.useRef(`${r.agent}:${r.sessionId}`);Ee.current=`${r.agent}:${r.sessionId}`,vt("stream-update",t.useCallback(e=>{e.key===Ee.current&&K(e.snapshot??null)},[K])),t.useEffect(()=>{let e=!0;return j.getSessionStreamState(r.agent||"",r.sessionId).then(s=>{e&&Qe.current(s.state)}).catch(()=>{}),()=>{e=!1}},[r.agent,r.sessionId,tt]),yt(t.useCallback(()=>{j.getSessionStreamState(r.agent||"",r.sessionId).then(e=>{K(e.state)}).catch(()=>{}),T({keepOlder:!0,force:!0})},[K,r.agent,r.sessionId,T])),t.useEffect(()=>{!B.current&&ne!=="running"&&!V&&!i&&!se&&le.length===0&&(I(),Q())},[ne,V,i,se,le.length,I,Q]),t.useLayoutEffect(()=>{const e=fe.current,s=A.current;!e||!s||(fe.current=null,s.scrollTop=e.scrollTop+(s.scrollHeight-e.scrollHeight))},[m?.turns.length]),t.useLayoutEffect(()=>{if(!$.current)return;const e=A.current;e&&($.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{_.current&&(e.scrollTop=e.scrollHeight)}))},[m,i]),t.useLayoutEffect(()=>{if(!S)return;const e=A.current;e&&(e.scrollTop=e.scrollHeight)},[S]),t.useEffect(()=>{if(!m?.hasOlder||Y||g)return;const e=A.current;e&&e.scrollHeight<=e.clientHeight+Je&&he()},[m?.hasOlder,m?.turns.length,he,Y,g]);const mt=t.useCallback(()=>{const e=A.current;if(!e)return;const s=e.scrollHeight-e.scrollTop-e.clientHeight;_.current=s<=qt,e.scrollTop<=Je&&he()},[he]),Me=i?.model||r.model||X||null,Le=It(r.agent||"",i?.effort||r.thinkingEffort||v||null,r.workflowEnabled??w?.workflowEnabled)||null,ze=Me?Tt(Me):null,Ce=jt(r,{streaming:V,hasLiveStream:!!i,streamPhase:se,queuedTaskCount:le.length}),y=m?.turns||[],Ae=t.useMemo(()=>{if(!E.length||!y.length)return!1;const e=y[y.length-1];return!e.user||(e.user.text?.trim()||"")!==(S||"").trim()?!1:e.user.blocks.filter(l=>l.type==="image").length<E.length},[y,S,E.length]),We=t.useMemo(()=>{let e=y;if(Ae){const b=e[e.length-1];e=[...e.slice(0,-1),{...b,user:null}]}if(!i||!e.length)return e;const s=e[e.length-1];if(!s.assistant)return e;const l=S??(i.question||null),a=(i.text||"").trim(),u=s.assistant.text?.trim()||"";return(l!=null?s.user?.text?.trim()===l.trim():!!u&&!!a&&(a.startsWith(u)||u.startsWith(a)))?[...e.slice(0,-1),{...s,assistant:null}]:e},[y,i,S,Ae]);return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{ref:A,onScroll:mt,className:"flex-1 overflow-y-auto overscroll-contain",children:Y&&!S&&!E.length&&!i?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(ke,{className:"h-5 w-5 text-fg-4"})}):We.length===0&&!S&&!E.length&&!i&&!Ce?n.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:d("hub.noMessages")}):n.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(m?.hasOlder||g)&&n.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[g?n.jsx(ke,{className:"h-3 w-3 text-fg-5"}):n.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/35"}),n.jsx("span",{children:d(g?"hub.loadingOlderTurns":"hub.loadOlderTurnsHint")})]}),r.migratedFrom?.kind==="fork"&&r.migratedFrom.sessionId&&n.jsxs("button",{type:"button",onClick:()=>R?.({agent:r.migratedFrom.agent||r.agent||"",sessionId:r.migratedFrom.sessionId,workdir:h}),className:"mb-4 inline-flex items-center gap-1.5 rounded-md border border-edge bg-panel-alt px-2.5 py-1 text-[11px] text-fg-5 transition hover:border-edge-h hover:text-fg-2",title:`#${r.migratedFrom.sessionId.slice(0,8)}`,children:[n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"6",cy:"6",r:"2"}),n.jsx("circle",{cx:"18",cy:"6",r:"2"}),n.jsx("circle",{cx:"12",cy:"20",r:"2"}),n.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),n.jsx("path",{d:"M12 14v4"})]}),n.jsx("span",{children:d("hub.forkBadge")}),n.jsxs("span",{className:"font-mono",children:["#",r.migratedFrom.sessionId.slice(0,8)]}),typeof r.migratedFrom.forkedAtTurn=="number"&&n.jsxs("span",{className:"text-fg-5/70",children:["· ",d("hub.forkBadgeAt").replace("{turn}",String(r.migratedFrom.forkedAtTurn+1))]})]}),We.map((e,s)=>{const l=(m?.startTurn||0)+s;return n.jsx(Mt,{turn:e,turnIndex:l,agent:r.agent||"",meta:F,model:ze,effort:Le,providerName:N,t:d,workdir:h,onResend:a=>{$.current=!0,Be(a);const u=$e.current;j.sendSessionMessage(h,r.agent||"",r.sessionId,a,{model:u.model||Me||void 0,effort:u.effort||Le||void 0}).then(c=>{c.ok&&Ke()}).catch(()=>{I()})},onEdit:a=>Ue(a),onFork:at?a=>{Te(""),ee({atTurn:a})}:void 0},`${m?.startTurn||0}:${s}`)}),Ce&&n.jsx("div",{className:"mb-5 animate-in",children:n.jsx(Lt,{detail:Ce,t:d})}),(S||E.length>0)&&(Ae||!(S&&y.length>0&&y[y.length-1]?.user?.text?.trim()===S.trim()))&&n.jsxs("div",{className:"session-turn",children:[n.jsx(Ve,{text:S||"",blocks:E.map(e=>({type:"image",content:e})),t:d}),!i&&n.jsx("div",{className:"mt-3 mb-5 animate-in",children:n.jsx(Ct,{className:"text-fg-5"})})]}),i&&Ge(i)&&!S&&i.question&&!(y.length>0&&y[y.length-1]?.user?.text?.trim()===i.question.trim())&&n.jsx("div",{className:"session-turn",children:n.jsx(Ve,{text:i.question,t:d})}),i&&Ge(i)&&n.jsxs("div",{className:"mb-6",children:[n.jsx(At,{agent:r.agent||"",meta:F,model:ze,effort:Le,providerName:N,previewMeta:i.previewMeta,liveStartedAt:i.phase==="streaming"?i.startedAt??null:null}),n.jsx(Pt,{stream:i,t:d,workdir:h})]}),n.jsx("div",{className:"h-4"})]})}),n.jsx(Ft,{session:r,workdir:h,onStreamQueued:Ke,onSendStart:Be,onSendTaskAssigned:ut,onSessionChange:R,t:d,streamPhase:se,streamTaskId:rt,queuedTaskIds:le,queuedTasks:nt,pendingQueuedSends:qe,onRecall:it,onSteer:dt,onStopAll:ft,editDraft:lt,onEditDraftConsumed:()=>Ue(null),onSelectionChange:ot}),de&&n.jsxs(Ze,{open:!0,onClose:()=>{C||ee(null)},children:[n.jsx(et,{title:d("hub.forkPromptTitle"),description:d("hub.forkPromptHint"),onClose:()=>{C||ee(null)}}),n.jsx("textarea",{autoFocus:!0,value:te,disabled:C,onChange:e=>Te(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&te.trim()&&!C&&(e.preventDefault(),Re.current?.())},placeholder:d("hub.forkPromptPlaceholder"),className:"w-full min-h-[120px] resize-y rounded-md border border-edge bg-panel-alt px-3 py-2 text-[13px] leading-relaxed text-fg outline-none focus:border-edge-h"}),n.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[n.jsx(Se,{variant:"ghost",disabled:C,onClick:()=>ee(null),children:d("modal.cancel")}),n.jsx(Se,{variant:"primary",disabled:C||!te.trim(),onClick:()=>{Re.current?.()},children:d(C?"hub.forkSubmitting":"hub.forkSubmit")})]})]}),L&&J.length>0&&n.jsx(Ht,{snapshot:J[J.length-1]},J[J.length-1].promptId)]})});export{er as SessionPanel};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-DD1k_k6Z.js","assets/react-vendor-C7Sl8SE7.js","assets/index-CxKN1UnH.js","assets/router-DHISdpPk.js","assets/index-CyCspgtc.css","assets/Modal-Ds_Yj4DN.js","assets/Select-B2e5zNQe.js","assets/DirBrowser-AO4JoPpf.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-BCCPKzoi.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as M,a as Z,u as Le,i as jn,f as Tt,A as cs,s as $t,S as pe,B as nt,g as rn,w as ds,b as us,E as Jt,C as un,d as hs,e as wn,h as xs,n as ps,j as fs,k as Ln,l as Pt,m as Re,D as Ft,o as gs,p as Mn,_ as Tn,T as ms,q as bs}from"./index-CxKN1UnH.js";import{j as e,r,a as hn}from"./react-vendor-C7Sl8SE7.js";import{I as vs}from"./Select-B2e5zNQe.js";import{M as Ot,a as Dt}from"./Modal-Ds_Yj4DN.js";import{D as js}from"./DirBrowser-AO4JoPpf.js";import{n as ws,r as ks,M as xn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as ys}from"./ExtensionsTab-BCCPKzoi.js";function Ns({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("shrink-0 text-fg-5/40 transition-transform duration-200",t&&"rotate-180",n),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function st({open:t,onToggle:n,dot:s,label:a,preview:l,badge:c,collapsedContent:x,children:d,className:m}){return e.jsxs("div",{className:M("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",m),children:[e.jsxs("button",{onClick:n,className:"w-full flex items-center gap-2.5 px-3.5 py-2.5 text-left hover:bg-panel-h/40 transition-colors",children:[s&&e.jsx("span",{className:M("h-[7px] w-[7px] shrink-0 rounded-full",s.color,s.pulse&&"animate-pulse")}),e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:a}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:l}),c,e.jsx(Ns,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Ss=5e3,Cs=15e3,Wt=8,Bt=30,Ls=1,tt=new Map,Ce=new Map,Zt=new Set,En=[];let Et=0;function en(t){return typeof t=="number"&&Number.isFinite(t)}function ze(t,n,s,a){for(t.delete(n),t.set(n,s);t.size>a;){const l=t.keys().next().value;if(!l)break;t.delete(l)}}function In(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(ze(t,n,s,t===Ce?Bt:Wt),s.value)}function An(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:en(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:en(t.turnOffset)?t.turnOffset:void 0,turnLimit:en(t.turnLimit)?t.turnLimit:void 0}}function pn(t){const n=An(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function Rn(){for(;Et<Ls;){const t=En.shift();if(!t)return;Et+=1,t().finally(()=>{Et=Math.max(0,Et-1),Rn()})}}async function Ms(t,n={}){const s=t;if(!n.force){const c=In(tt,s);if(c)return c}const a=tt.get(s);if(a?.promise)return a.promise;const l=Z.getWorkspaceSessions(t,n.request).then(c=>(ze(tt,s,{value:c,expiresAt:c.ok?Date.now()+Ss:0},Wt),c)).finally(()=>{const c=tt.get(s);c?.promise&&ze(tt,s,{value:c.value,expiresAt:c.expiresAt},Wt)});return ze(tt,s,{value:a?.value,expiresAt:a?.expiresAt??0,promise:l},Wt),l}function Ts(t,n={}){const s=pn(t),a=Ce.get(s);return a?.value?.ok&&(n.allowStale||a.expiresAt>Date.now())?a.value:null}async function Es(t,n={}){const s=An(t),a=pn(s);if(!n.force){const x=In(Ce,a);if(x?.ok)return x}const l=Ce.get(a);if(l?.promise)return l.promise;const c=Z.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(ze(Ce,a,{value:x,expiresAt:x.ok?Date.now()+Cs:0},Bt),x)).finally(()=>{const x=Ce.get(a);x?.promise&&ze(Ce,a,{value:x.value,expiresAt:x.expiresAt},Bt)});return ze(Ce,a,{value:l?.value,expiresAt:l?.expiresAt??0,promise:c},Bt),c}function Is(t){const n=pn(t);Ts(t)||Zt.has(n)||Ce.get(n)?.promise||(Zt.add(n),En.push(async()=>{try{await Es(t)}catch{}finally{Zt.delete(n)}}),Rn())}function Zr(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(x=>({role:x.role,text:x.text,blocks:[{type:"text",content:x.text}]}))||[],s=Rs(n),a=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),l=t.window?.endTurn??a,c=t.window?.startTurn??Math.max(0,l-s.length);return{turns:s,startTurn:c,endTurn:l,totalTurns:a,hasOlder:t.window?.hasOlder??c>0}}function eo(t,n){const s=Math.max(0,t.startTurn-n.startTurn);return{turns:[...n.turns.slice(0,s),...t.turns],startTurn:n.startTurn,endTurn:t.endTurn,totalTurns:Math.max(t.totalTurns,n.totalTurns),hasOlder:n.hasOlder}}function to(t,n){if(n.startTurn<=t.startTurn)return n;const s=Math.max(0,n.startTurn-t.startTurn);return{turns:[...t.turns.slice(0,s),...n.turns],startTurn:t.startTurn,endTurn:n.endTurn,totalTurns:n.totalTurns,hasOlder:t.startTurn>0}}function As(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
|
|
3
|
-
|
|
4
|
-
`),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function Rs(t){const n=[];let s={user:null,assistant:null};for(const a of t)if(a.role==="user"){if(s.assistant&&_n(a.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=a}else s.assistant?s.assistant=As(s.assistant,a):s.assistant=a;return(s.user||s.assistant)&&n.push(s),n}const _s=new Set(["task-notification","system-reminder","persisted-output","local-command-stdout","local-command-caveat","local-command-stderr","ide_opened_file","ide_diagnostics","ide_selection","event","analysis","case_id","tool-use-id","output-file"]),Ps=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function _n(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&_s.has(s[1].toLowerCase())?!0:Ps.some(a=>t.includes(a))}function Pn(t,n){const s=t.split(`
|
|
5
|
-
`).filter(a=>a.trim());return s.length<=n?s.join(`
|
|
6
|
-
`):s.slice(-n).join(`
|
|
7
|
-
`)}function Ws(t){const n=String(t||"").trim().toLowerCase();return n?n.startsWith("interrupted by user")?"interrupted":n.startsWith("timed out")||n.startsWith("stopped before completion")||n.includes("max tokens")?"incomplete":"error":"error"}function tn(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function Bs(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function Wn(t){if(!Number.isFinite(t)||t<=0)return"0 B";if(t<1024)return`${t} B`;const n=t/1024;if(n<1024)return`${n.toFixed(n>=100?0:1)} KB`;const s=n/1024;return`${s.toFixed(s>=100?0:1)} MB`}async function $s(t){if(typeof ClipboardItem>"u"||!navigator.clipboard?.write)return!1;try{return await navigator.clipboard.write([new ClipboardItem({[t.type||"image/png"]:t})]),!0}catch{return!1}}function Q(t,n=120){if(t==null)return"";const a=(typeof t=="string"?t:String(t)).replace(/\s+/g," ").trim();return a.length<=n?a:a.slice(0,Math.max(0,n-1))+"…"}function Os(t){if(!t)return null;try{const n=JSON.parse(t);return n&&typeof n=="object"&&!Array.isArray(n)?n:null}catch{return null}}function Bn(t){const n=String(t.toolName||"").trim()||"Tool",s=Os(t.content);if(!s)return n;const a=Q(s.description,120);switch(n){case"Read":{const l=Q(s.file_path||s.path,140);return l?`Read ${l}`:"Read"}case"Edit":{const l=Q(s.file_path||s.path,140);return l?`Edit ${l}`:"Edit"}case"Write":{const l=Q(s.file_path||s.path,140);return l?`Write ${l}`:"Write"}case"Glob":{const l=Q(s.pattern||s.glob,120);return l?`Glob ${l}`:"Glob"}case"Grep":{const l=Q(s.pattern||s.query,120);return l?`Grep ${l}`:"Grep"}case"WebFetch":{const l=Q(s.url,120);return l?`WebFetch ${l}`:"WebFetch"}case"WebSearch":{const l=Q(s.query,120);return l?`WebSearch ${l}`:"WebSearch"}case"TodoWrite":return"Update plan";case"AskUserQuestion":{const c=(Array.isArray(s.questions)?s.questions:[])[0],x=Q(c?.question||s.question,120);return x?`Ask user: ${x}`:"Ask user"}case"Task":{const l=Q(s.description||s.prompt,120);return l?`Task: ${l}`:"Task"}case"Bash":{if(a)return`Bash: ${a}`;const l=Q(s.command,120);return l?`Bash: ${l}`:"Bash"}default:{const l=n.match(/^mcp__[^_]+__(.+)$/),c=l?l[1]:n;if(c==="im_send_file"){const d=Q(s.path,120);return d?`Send file: ${d}`:"Send file"}if(c==="im_list_files")return"List workspace files";if(a)return`${n}: ${a}`;const x=Q(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return x?`${n}: ${x}`:n}}}function Ds(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
|
|
8
|
-
`).map(a=>a.trim()).find(Boolean)||"";return s?Q(s,140):"result"}function Fs(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),a=t.slice(n+1).trim();return!s||!a?null:{agent:s,sessionId:a}}const gt=new Map;function Us(t,n){return`${t}:${n}`}function zs(t){const n=(()=>{try{return new URL(t.baseURL).host.toLowerCase()}catch{return""}})();return n.includes("openrouter")?"openrouter":n.includes("anthropic")?"anthropic":n.includes("deepseek")?"deepseek":n.includes("googleapis")||n.includes("vertex")?"google":n.includes("openai.com")?"openai":n.includes("dashscope")||n.includes("qwen")||n.includes("aliyun")?"qwen":n.includes("volces")||n.includes("volcengine")||n.includes("doubao")?"doubao":n.includes("bigmodel")||n.includes("zhipu")||n.includes("z.ai")?"glm":n.includes("minimax")?"minimax":t.kind==="anthropic"?"anthropic":t.kind==="google"?"google":t.kind==="openai"?"openai":"custom"}const Ks=r.memo(function({session:n,workdir:s,onStreamQueued:a,onSendStart:l,onSendTaskAssigned:c,onSessionChange:x,t:d,streamPhase:m,streamTaskId:v,queuedTaskIds:g,queuedTasks:j,pendingQueuedSends:C,onRecall:k,onSteer:R,onStopAll:I,editDraft:_,onEditDraftConsumed:B,onSelectionChange:y}){const[O,ee]=r.useState(""),[A,K]=r.useState(!1),[$,D]=r.useState(null),[ce,P]=r.useState(()=>new Set),[re,oe]=r.useState(()=>new Set),V=r.useRef({prompt:"",files:[]}),Me=Le(i=>i.agentStatus?.agents??null),[z,mt]=r.useState(Me||[]),[fe,ot]=r.useState(""),[Ke,He]=r.useState(""),[ie,_e]=r.useState(""),[te,Te]=r.useState([]),[Pe,Ve]=r.useState(null),[de,bt]=r.useState(null),[ge,le]=r.useState(null),[We,Ee]=r.useState(null),[it,Ie]=r.useState(null),[ne,me]=r.useState(void 0),[L,Y]=r.useState("closed"),[G,vt]=r.useState(null),Ae=r.useRef(null),Ge=r.useRef(!1),Be=r.useRef(null),zt=r.useRef(null),ue=r.useRef(null),be=r.useRef([]),[ve,jt]=r.useState([]),[ae,$e]=r.useState(!1),[qe,Qe]=r.useState(0),Ye=r.useRef(null),he=Le(i=>i.refreshAgentStatus),[je,Xe]=r.useState([]),[Oe,we]=r.useState([]),[lt,at]=r.useState({}),se=r.useCallback(async()=>{try{const[i,p,b]=await Promise.all([fetch("/api/models/providers").then(S=>S.json()),fetch("/api/models/profiles").then(S=>S.json()),fetch("/api/models/agents").then(S=>S.json())]);if(i?.ok&&we(i.providers||[]),p?.ok&&Xe(p.profiles||[]),b?.ok){const S={};for(const F of b.bindings||[])S[F.agent]=F.activeProfileId;at(S)}}catch{}},[]);r.useEffect(()=>{se()},[se]),r.useEffect(()=>{Me?.length&&mt(Me)},[Me]),r.useEffect(()=>{be.current=te},[te]);const ke=Us(n.agent||"",n.sessionId),Je=r.useRef(ke);Je.current=ke,r.useEffect(()=>{const i=gt.get(ke);return i&&(gt.delete(ke),i.text&&ee(i.text),i.files.length&&Te(i.files.map(tn))),()=>{const p=Ae.current?.value||"",b=be.current.map(S=>S.file);for(const S of be.current)URL.revokeObjectURL(S.previewUrl);p||b.length?gt.set(Je.current,{text:p,files:b}):gt.delete(Je.current)}},[ke]);const wt=r.useRef({agent:n.agent||"",sessionId:n.sessionId});r.useEffect(()=>{const i=wt.current,p={agent:n.agent||"",sessionId:n.sessionId};wt.current=p,!(i.agent===p.agent&&jn(i.sessionId)&&!jn(p.sessionId))&&(ot(""),He(""),_e(""),le(null),Ee(null),Ie(null),Y("closed"))},[n.agent,n.sessionId]),r.useEffect(()=>{_!=null&&(ee(_),B?.(),requestAnimationFrame(()=>{const i=Ae.current;i&&(i.focus(),i.setSelectionRange(_.length,_.length))}))},[_,B]),r.useEffect(()=>{if(!s)return;let i=!1;return Z.getSkills(s).then(p=>{!i&&p.ok&&jt(p.skills)}).catch(()=>{}),()=>{i=!0}},[s]);const ct=ae?(()=>{const i=O.match(/^\/(\S*)$/);return i?i[1].toLowerCase():null})():null,ye=ct!==null?ve.filter(i=>i.name.toLowerCase().includes(ct)||i.label&&i.label.toLowerCase().includes(ct)):[];r.useEffect(()=>{Qe(0)},[ae,O]),r.useEffect(()=>{if(!ae||!Ye.current)return;const i=Ye.current.querySelector(`[data-skill-idx="${qe}"]`);i&&i.scrollIntoView({block:"nearest"})},[qe,ae]),r.useEffect(()=>{if(!ae)return;const i=p=>{Ye.current?.contains(p.target)||Ae.current?.contains(p.target)||$e(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[ae]),r.useEffect(()=>{if(L==="closed")return;const i=p=>{const b=p.target;ue.current?.contains(b)||document.getElementById("cascade-portal")?.contains(b)||(Y("closed"),le(null),Ee(null),Ie(null))};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[L]),r.useLayoutEffect(()=>{if(L==="closed"||!ue.current){vt(null);return}const i=ue.current.getBoundingClientRect();vt({left:i.left,bottom:window.innerHeight-i.top+8})},[L]);const kt=g&&g.length?g[0]:null;r.useEffect(()=>{$&&(kt||m!==null&&m!=="queued")&&D(null)},[m,$,kt]),r.useEffect(()=>{const i=Ae.current;i&&(i.style.height="auto",i.style.height=Math.min(i.scrollHeight,200)+"px")},[O]);const dt=r.useCallback(i=>{const p=Array.from(i||[]).filter(b=>b.type.startsWith("image/"));p.length&&Te(b=>[...b,...p.map(tn)])},[]),yt=r.useCallback(()=>{Ve(null),Te(i=>(Bs(i),[]))},[]),Nt=r.useCallback(i=>{Te(p=>{const b=p.find(S=>S.id===i);return b&&URL.revokeObjectURL(b.previewUrl),p.filter(S=>S.id!==i)}),Ve(p=>p===i?null:p)},[]),St=r.useCallback(()=>{const i=O.trim(),p=te.map(q=>q.file);if(!i&&p.length===0||A)return;const b=fe||n.agent||z.find(q=>q.isDefault)?.agent||"";if(!b)return;const S=z.find(q=>q.agent===b)||null,F=!!n.agent&&b===n.agent,Ne=(Ke||F&&n.model||""||S?.selectedModel||"").trim()||null,Se=b==="gemini"?null:(ie||(F?Tt(b,n.thinkingEffort,n.workflowEnabled):"")||Tt(b,S?.selectedEffort,S?.workflowEnabled)||"").trim()||null,J=b!==n.agent,Xt=J?"":n.sessionId,is=J&&n.agent?n.agent:null,ls=J&&n.sessionId?n.sessionId:null;K(!0),V.current={prompt:i,files:p},ee(""),gt.delete(Je.current);const as=p.length?p.map(q=>URL.createObjectURL(q)):void 0;yt(),l(i,as),a(),Z.sendSessionMessage(s,b,Xt,i,{attachments:p,model:Ne,effort:Se,previousAgent:is,previousSessionId:ls}).then(q=>{if(q.taskId&&(D(q.taskId),c?.(q.taskId)),!q.ok)return;const ft=typeof q.sessionKey=="string"?Fs(q.sessionKey):null;ft&&(ft.agent!==n.agent||ft.sessionId!==n.sessionId)&&ft&&x?.({...ft,workdir:s})}).catch(()=>{}).finally(()=>K(!1))},[z,yt,te,O,l,c,x,a,fe,ie,Ke,A,n.agent,n.sessionId,s]),ut=m==="streaming",xe=(()=>{const i=[];return g&&g.length&&i.push(...g),m==="queued"&&v&&!i.includes(v)&&i.unshift(v),$&&!i.includes($)&&(m==="queued"||!m)&&i.push($),i})(),Ct=xe[xe.length-1]||null,ht=xe.length>0,Kt=ht||ut;r.useEffect(()=>{const i=p=>xe.includes(p)||p===v;P(p=>{let b=!1;const S=new Set;for(const F of p)i(F)?S.add(F):b=!0;return b?S:p}),oe(p=>{let b=!1;const S=new Set;for(const F of p)i(F)?S.add(F):b=!0;return b?S:p})},[xe,v]),r.useEffect(()=>{!ht&&V.current.files.length&&(V.current={prompt:"",files:[]})},[ht]);const Ht=r.useCallback(i=>{if(!ce.has(i)){if(P(p=>{const b=new Set(p);return b.add(i),b}),i===Ct){const p=V.current;p.prompt&&ee(p.prompt),p.files.length&&Te(p.files.map(tn)),V.current={prompt:"",files:[]}}k?.(i),i===$&&D(null)}},[ce,Ct,$,k]),[o,h]=r.useState(!1),u=r.useCallback(async()=>{if(!(o||!I)){h(!0);try{await I()}finally{h(!1)}}},[o,I]),f=r.useCallback(i=>{re.has(i)||(oe(p=>{const b=new Set(p);return b.add(i),b}),R?.(i),i===$&&D(null))},[re,$,R]),w=r.useCallback(i=>{ee(`/${i.name} `),$e(!1),requestAnimationFrame(()=>{const p=Ae.current;p&&(p.focus(),p.setSelectionRange(p.value.length,p.value.length))})},[]),N=r.useCallback(i=>{ee(i);const p=/^\/\S*$/.test(i)&&ve.length>0;$e(p)},[ve.length]),T=i=>{if(ae&&ye.length>0){if(i.key==="ArrowDown"){i.preventDefault(),Qe(p=>(p+1)%ye.length);return}if(i.key==="ArrowUp"){i.preventDefault(),Qe(p=>(p-1+ye.length)%ye.length);return}if(i.key==="Tab"||i.key==="Enter"&&!i.shiftKey&&!Ge.current){i.preventDefault(),w(ye[qe]);return}if(i.key==="Escape"){i.preventDefault(),$e(!1);return}}i.key==="Enter"&&!i.shiftKey&&!Ge.current&&(i.preventDefault(),St())},X=r.useCallback(i=>{const p=Array.from(i.clipboardData?.items||[]).filter(b=>b.kind==="file"&&b.type.startsWith("image/")).map(b=>b.getAsFile()).filter(b=>!!b);p.length&&(i.preventDefault(),dt(p))},[dt]),E=fe||n.agent||z.find(i=>i.isDefault)?.agent||z.find(i=>i.installed)?.agent||z[0]?.agent||"",W=z.find(i=>i.agent===E)||null,U=ge||E,xt=z.find(i=>i.agent===U)||W,Lt=r.useMemo(()=>{if(!xt)return[];const i=[];for(const b of xt.models||[])i.push({id:b.id,label:b.id,kind:"native",description:b.alias&&b.alias.toLowerCase()!==b.id.toLowerCase()?b.alias:void 0});const p=new Set(cs[U]||[]);for(const b of je){const S=Oe.find(Ne=>Ne.id===b.providerId);if(!S||!p.has(S.kind))continue;const F=b.name.trim().toLowerCase()!==b.modelId.trim().toLowerCase();i.push({id:b.modelId,label:b.name,kind:"profile",profileId:b.id,description:F?`${S.name} · ${b.modelId}`:S.name})}return i},[xt,U,je,Oe]),Jn=r.useMemo(()=>Lt.findIndex(i=>i.kind==="profile"),[Lt]),Zn=lt[U]||null,mn=!!n.agent&&E===n.agent,pt=Ke||mn&&n.model||""||W?.selectedModel||"",Mt=E==="gemini"?"":ie||(mn?Tt(E,n.thinkingEffort,n.workflowEnabled):"")||Tt(E,W?.selectedEffort,W?.workflowEnabled)||"";r.useEffect(()=>{y?.({model:pt||null,effort:Mt||null})},[pt,Mt,y]);const es=Jt[U]||[],De=Pe&&te.find(i=>i.id===Pe)||null,ts=De?{key:De.id,url:De.previewUrl,name:De.file.name,size:De.file.size,file:De.file,onRemove:()=>Nt(De.id)}:de?{key:de,url:de}:null,bn=(!!O.trim()||te.length>0)&&!A&&!!E,Vt=()=>{le(null),Ee(null),Ie(null),me(void 0)},Gt=r.useCallback(async(i,p,b)=>{const S=i==="gemini"?"":b||"";if(ne!==void 0)try{await fetch(`/api/models/agents/${i}/active`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileId:ne})}),se(),he()}catch{}ot(i),He(p),_e(S),Vt(),Y("closed")},[ne,se,he]),ns=()=>{L==="closed"?(Vt(),he(),se(),Y("agent")):(Vt(),Y("closed"))},qt=ge||E,vn=rn(qt),Qt=We??pt,Ze=it??Mt,ss=Qt?$t(Qt):"",Fe=(()=>{const i=lt[qt];return i?je.find(p=>p.id===i)??null:null})(),et=Fe?Oe.find(i=>i.id===Fe.providerId)??null:null,rs=et?zs(et):null,Yt=Fe?Fe.name.trim().toLowerCase()!==Fe.modelId.trim().toLowerCase()?Fe.name:$t(Fe.modelId):ss,os=[vn.shortLabel,et?et.name:null,Yt||null,Ze?Ze.charAt(0).toUpperCase()+Ze.slice(1):null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:zt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[Kt&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[ut&&e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-primary/20 bg-primary/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx(pe,{className:"h-3 w-3 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-[12px] font-medium text-fg-3 truncate",children:d("hub.running")}),e.jsxs("button",{onClick:u,disabled:o,title:d("hub.stopHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none shrink-0",children:[o?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),d("hub.stop")]})]}),xe.map((i,p)=>{const b=p===xe.length-1,S=xe.length>1?`${d("hub.queued")} #${p+1}`:d("hub.queued"),F=C?.find(J=>J.taskId===i)||(b?C?.find(J=>!J.taskId):void 0),Ne=j?.find(J=>J.taskId===i)?.prompt||F?.prompt||null,Se=F?.imageUrls?.length?F.imageUrls:[];return e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-warn/25 bg-warn/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-warn animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-warn shrink-0",children:S}),Se.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Se.slice(0,3).map((J,Xt)=>e.jsx("button",{type:"button",onClick:()=>bt(J),title:d("hub.previewImage"),className:"block h-5 w-5 shrink-0 overflow-hidden rounded border border-warn/30 transition-opacity hover:opacity-80",children:e.jsx("img",{src:J,alt:"",className:"h-full w-full object-cover"})},`${J}-${Xt}`)),Se.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",Se.length-3]})]}),Ne&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:Ne})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>f(i),disabled:re.has(i),title:d("hub.steerHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-blue-400 hover:bg-blue-400/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[re.has(i)?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),d("hub.steer")]}),e.jsxs("button",{onClick:()=>Ht(i),disabled:ce.has(i),title:d("hub.recallHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[ce.has(i)?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]}),d("hub.recall")]})]})]},i)})]}),e.jsxs("div",{className:"relative rounded-xl border border-edge/40 bg-panel shadow-sm transition-[border-color,box-shadow] duration-200 focus-within:border-fg-5/40 focus-within:shadow-md",children:[e.jsx("input",{ref:Be,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:i=>{dt(i.target.files),i.target.value=""}}),te.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:te.map(i=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>Ve(i.id),title:d("hub.previewImage"),className:"group relative h-[72px] w-[72px] overflow-hidden rounded-lg border border-edge/30 bg-panel-alt/30",children:[e.jsx("img",{src:i.previewUrl,alt:i.file.name,className:"h-full w-full object-cover transition-transform duration-200 group-hover:scale-[1.03]"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent px-1.5 pb-1 pt-3 text-left",children:e.jsx("div",{className:"truncate text-[8px] font-medium text-white/90 leading-tight",children:i.file.name})})]}),e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),Nt(i.id)},title:d("hub.removeImage"),className:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-black/65 text-white/75 transition-colors hover:bg-black/80 hover:text-white",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]},i.id))})}),ae&&ye.length>0&&e.jsxs("div",{ref:Ye,className:"absolute bottom-full left-0 right-0 mb-1.5 z-50 max-h-[200px] overflow-y-auto rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg animate-in",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-edge/20",children:e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d("hub.skills")})}),e.jsx("div",{className:"py-1",children:ye.map((i,p)=>e.jsxs("button",{"data-skill-idx":p,onMouseDown:b=>{b.preventDefault(),w(i)},onMouseEnter:()=>Qe(p),className:M("flex flex-col w-full px-3 py-1.5 text-left transition-colors",p===qe?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",i.name]}),(i.label||i.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:i.label||i.description})]},i.name))})]}),e.jsx("textarea",{ref:Ae,value:O,onChange:i=>N(i.target.value),onPaste:X,onKeyDown:T,onCompositionStart:()=>{Ge.current=!0},onCompositionEnd:()=>{Ge.current=!1},placeholder:d("hub.inputPlaceholder"),rows:1,className:"w-full resize-none bg-transparent px-4 pt-3 pb-1 text-[13.5px] text-fg outline-none placeholder:text-fg-5/25 leading-[1.6]",style:{maxHeight:200,overflow:O.split(`
|
|
9
|
-
`).length>6?"auto":"hidden"}}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>Be.current?.click(),title:d("hub.addImages"),className:"flex h-7 w-7 items-center justify-center rounded-lg text-fg-5/50 transition-colors hover:bg-panel-h/60 hover:text-fg-3",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})}),e.jsxs("button",{ref:ue,onClick:ns,disabled:!z.length,title:z.length?os:void 0,className:M("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",L!=="closed"?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[z.length?e.jsx(nt,{brand:qt,size:12}):e.jsx(pe,{className:"h-3 w-3"}),z.length?e.jsxs("span",{className:"flex items-center gap-1 max-w-[460px] min-w-0 truncate",children:[e.jsx("span",{className:"shrink-0",children:vn.shortLabel}),et&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(nt,{brand:rs||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:et.name})]}),Yt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:Qt||void 0,children:Yt})]}),Ze&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"shrink-0",children:Ze.charAt(0).toUpperCase()+Ze.slice(1)})]})]}):e.jsx("span",{className:"max-w-[420px] truncate",children:d("hub.selectAgent")}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:M("text-fg-5/30 transition-transform duration-200",L!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),L!=="closed"&&G&&hn.createPortal(e.jsxs("div",{id:"cascade-portal",className:"fixed z-[200] w-[300px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in",style:{left:G.left,bottom:G.bottom},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5 border-b border-edge/20",children:[L!=="agent"&&e.jsx("button",{onClick:()=>{if(L==="effort"){const i=xt?.capabilities?.modelSwitch!==!1;Y(i?"model":"agent")}else Y("agent")},className:"p-0.5 rounded text-fg-5/50 hover:text-fg-3 transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d(L==="agent"?"hub.selectAgent":L==="model"?"hub.selectModel":"hub.selectEffort")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const p=xt?.capabilities?.modelSwitch!==!1?["agent","model","effort"]:["agent","effort"],b=p.indexOf(L);return p.map((S,F)=>e.jsx("span",{className:M("w-1.5 h-1.5 rounded-full transition-colors",L===S?"bg-primary":F<b?"bg-primary/40":"bg-fg-5/15")},S))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[L==="agent"&&z.filter(i=>i.installed).map(i=>{const p=rn(i.agent),b=ds(i.usage),S=b?us(b):"ok";return e.jsxs(nn,{selected:i.agent===(ge||E),onClick:()=>{if(le(i.agent),Ee(i.selectedModel||""),Ie(i.selectedEffort||""),!(i.capabilities?.modelSwitch!==!1)){(Jt[i.agent]||[]).length?Y("effort"):Gt(i.agent,i.selectedModel||"",null);return}Y("model")},children:[e.jsx(nt,{brand:i.agent,size:14}),e.jsx("span",{style:{color:p.color},children:p.label}),b&&e.jsxs("span",{className:M("ml-auto font-mono text-[10px]",S==="err"?"text-err":S==="warn"?"text-warn":"text-fg-5"),children:[b.label," ",Math.round(b.usedPercent??0),"%"]})]},i.agent)}),L==="model"&&e.jsxs(e.Fragment,{children:[Lt.map((i,p)=>{const b=p===0&&i.kind==="native",S=p===Jn&&i.kind==="profile",F=ne!==void 0?ne:Zn,Ne=i.kind==="profile"?!!i.profileId&&i.profileId===F:!F&&i.id===(We??pt);return e.jsxs("div",{children:[b&&e.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupNative")}),S&&e.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupProfiles")}),e.jsx(nn,{selected:Ne,onClick:()=>{const Se=ge||E;if(Ee(i.id),me(i.profileId??null),Jt[Se]?.length){Y("effort");return}Gt(Se,i.id,null)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:M("truncate text-[11.5px]",i.kind==="native"&&"font-mono text-[11px]"),title:i.id,children:i.label}),i.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:i.description})]})})]},`${i.kind}:${i.profileId||i.id}`)}),Lt.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]}),L==="effort"&&es.map(i=>e.jsx(nn,{selected:i===(it||Mt),onClick:()=>{Ie(i),Gt(ge||E,We??pt,i)},children:i.charAt(0).toUpperCase()+i.slice(1)},i))]})]}),document.body),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:St,disabled:!bn,className:M("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",bn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:A?e.jsx(pe,{className:"h-3.5 w-3.5"}):e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})]}),e.jsx(Hs,{source:ts,onClose:()=>{Ve(null),bt(null)},t:d})]})});function Hs({source:t,onClose:n,t:s}){const[a,l]=r.useState(!1);if(r.useEffect(()=>{l(!1)},[t?.key]),r.useEffect(()=>{if(!t)return;const d=m=>{m.key==="Escape"&&n()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[t,n]),!t)return null;const c=t.file,x=t.onRemove;return hn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center bg-black/72 px-4 py-6 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[1024px]",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-[11px] text-white/72",children:[t.name&&e.jsx("span",{className:"truncate font-medium text-white/90",children:t.name}),typeof t.size=="number"&&e.jsx("span",{children:Wn(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await $s(c)&&(l(!0),window.setTimeout(()=>l(!1),1600))},className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s(a?"hub.copied":"hub.copyImage")}),x&&e.jsx("button",{type:"button",onClick:x,className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s("hub.removeImage")}),e.jsx("button",{type:"button",onClick:n,className:"flex h-9 w-9 items-center justify-center rounded-full border border-white/12 bg-white/10 text-white/88 transition-colors hover:bg-white/14",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-white/10 bg-black/35 shadow-[0_20px_70px_rgba(0,0,0,0.45)]",children:e.jsx("img",{src:t.url,alt:t.name||"",className:"max-h-[80vh] w-full object-contain"})})]})}),document.body)}function nn({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:M("flex items-center gap-2 w-full px-3 py-2 text-[12px] text-left transition-colors",t?"text-fg bg-panel-h font-medium":"text-fg-3 hover:bg-panel-alt/50 hover:text-fg-2"),children:[s,t&&e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"ml-auto text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),!t&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"ml-auto text-fg-5/20",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})})]})}function Vs(){return function(t){ws(t)}}const fn=[ks,Vs],$n=t=>/^https?:\/\//.test(t),Gs=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function qs(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function Qs(t){let n=t.trim();const s=[["`","`"],['"','"'],["'","'"],["<",">"]];let a=!0;for(;a&&n.length>=2;){a=!1;for(const[l,c]of s)n.startsWith(l)&&n.endsWith(c)&&(n=n.slice(l.length,-c.length).trim(),a=!0)}return n}function On(t){let n=Qs(t),s="";for(;n.length>1;){const a=n[n.length-1];if(!a||!/[),.;!?]/.test(a)||a==="."&&/^\.[A-Za-z0-9_-]+$/.test(n))break;s=a+s,n=n.slice(0,-1)}return{text:n,trailing:s}}function on(t){const n=On(t).text;if(!n||$n(n)||Gs(n)&&!n.startsWith("file://"))return!1;const s=qs(n);if(!s)return!1;if(s.startsWith("file://"))return s.length>7;if(/^[A-Za-z]:[\\/]/.test(s))return!0;if(/^(\/|~\/|\.{1,2}\/)/.test(s))return s.length>1;if(s.includes("/")){const a=s.split("/")[0]||"";return!/^[A-Za-z0-9-]+\.[A-Za-z]{2,}$/.test(a)}return!1}function gn(t,n){Z.openInEditor(t,void 0,n||void 0).catch(()=>{})}function Dn(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),gn(n,s))}function Ys({locator:t,workdir:n,children:s}){return e.jsx("span",{role:"link",tabIndex:0,title:t,className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",onClick:()=>gn(t,n),onKeyDown:a=>Dn(a,t,n),children:s??t})}function Xs({text:t}){const[n,s]=r.useState(!1),a=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:a,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function kn(t){const n=on(t),s=/^(npm |npx |git |python|pip |yarn |pnpm |cargo |go |make )/.test(t);return n?"bg-blue-500/8 border-blue-400/12 text-blue-300/90":s?"bg-amber-500/8 border-amber-400/10 text-amber-300/80":"bg-[rgba(255,255,255,0.06)] border-edge/20 text-fg-3"}function Ut(t={}){const n=t.workdir||null;return{h1:({children:s})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:s}),h2:({children:s})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:s}),h3:({children:s})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:s}),p:({children:s})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:s}),strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-fg",children:s}),em:({children:s})=>e.jsx("em",{className:"italic text-fg-3",children:s}),a:({href:s,children:a})=>s&&$n(s)?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",children:a}):s&&on(s)?e.jsx(Ys,{locator:On(s).text,workdir:n,children:a}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:a}),ul:({children:s})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:s}),ol:({children:s})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:s}),li:({children:s})=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"shrink-0 mt-[10px] w-[5px] h-[5px] rounded-full bg-fg-5/40"}),e.jsx("span",{className:"flex-1",children:s})]}),blockquote:({children:s})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:s}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:s,children:a})=>{const l=String(a).replace(/\n$/,""),c=/language-(\w+)/.exec(s||"");if(!c&&!s&&!l.includes(`
|
|
10
|
-
`))return on(l)?e.jsx("code",{role:"link",tabIndex:0,title:l,className:M("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",kn(l)),onClick:()=>gn(l,n),onKeyDown:d=>Dn(d,l,n),children:l}):e.jsx("code",{className:M("px-1.5 py-[1px] rounded text-[12px] font-mono border",kn(l)),children:l});const x=c?.[1]||"";return e.jsxs("div",{className:"rounded-lg overflow-hidden border border-edge/30 bg-[rgba(0,0,0,0.25)] my-3 not-prose",children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-1.5 border-b border-edge/15 bg-[rgba(0,0,0,0.12)]",children:[e.jsx("span",{className:"text-[10px] font-mono text-fg-5/50",children:x||"text"}),e.jsx(Xs,{text:l})]}),e.jsx("pre",{className:"px-3.5 py-3 text-[12px] leading-[1.65] text-fg-3 font-mono whitespace-pre-wrap break-words overflow-x-auto",children:e.jsx("code",{children:l})})]})},pre:({children:s})=>e.jsx(e.Fragment,{children:s}),table:({children:s})=>e.jsx("div",{className:"my-3 overflow-x-auto rounded-lg border border-edge/30",children:e.jsx("table",{className:"w-full text-[12.5px]",children:s})}),thead:({children:s})=>e.jsx("thead",{className:"bg-[rgba(0,0,0,0.1)]",children:s}),th:({children:s})=>e.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-fg-3 border-b border-edge/30",children:s}),td:({children:s})=>e.jsx("td",{className:"px-3 py-1.5 text-fg-4 border-t border-edge/12",children:s}),tr:({children:s})=>e.jsx("tr",{className:"even:bg-[rgba(255,255,255,0.015)]",children:s})}}Ut();function rt(t){return!!t?.steps?.length}function Js(t,n){let s=t;for(const[a,l]of Object.entries(n))s=s.replace(new RegExp(`\\{${a}\\}`,"g"),l);return s}function Zs({status:t}){return t==="completed"?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):t==="inProgress"?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-400 animate-pulse"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/25"})}function Fn({plan:t,t:n,className:s}){const[a,l]=r.useState(!1);if(!rt(t))return null;const c=t.steps.length,x=t.steps.filter(v=>v.status==="completed").length,d=c>0&&x===c,m=Js(n("hub.planProgress"),{done:String(x),total:String(c)});return e.jsx(st,{open:a,onToggle:()=>l(v=>!v),dot:{color:d?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!d},label:m,preview:t.explanation?e.jsx("span",{className:"text-[11.5px] text-fg-4 truncate",children:t.explanation}):void 0,badge:e.jsx("span",{className:M("rounded-md border px-1.5 py-0.5 text-[10px] font-mono",d?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(d?"hub.planDone":"hub.planInProgress")}),className:s,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-1",children:t.steps.map((v,g)=>{const j=v.status==="completed"?"text-fg-5 line-through decoration-fg-5/40":v.status==="inProgress"?"text-fg-3":"text-fg-4";return e.jsxs("div",{className:"flex items-center gap-2 py-[2px]",children:[e.jsx("span",{className:"shrink-0 flex items-center justify-center w-[10px]",children:e.jsx(Zs,{status:v.status})}),e.jsx("span",{className:M("text-[12px] leading-[1.5]",j),children:v.step})]},`${g}:${v.step}`)})})})}function Un({url:t,fileName:n,fileSize:s,caption:a}){return e.jsxs("div",{className:"flex flex-col gap-1 max-w-[340px]",children:[e.jsxs("a",{href:t,download:n,target:"_blank",rel:"noreferrer",title:a||n,className:M("group inline-flex items-center gap-2.5 rounded-md no-underline","border border-fg-6/40 bg-fg-6/[0.05] px-3 py-2","hover:bg-fg-6/[0.12] hover:border-fg-6/60 transition-colors"),children:[e.jsx("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded bg-fg-6/10 text-fg-3",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12.5px] font-medium text-fg-2",children:n}),typeof s=="number"&&s>0&&e.jsx("span",{className:"block text-[11px] text-fg-5/70",children:Wn(s)})]}),e.jsx("span",{className:"shrink-0 text-fg-5/50 group-hover:text-fg-3 transition-colors",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),a&&e.jsx("span",{className:"px-0.5 text-[11.5px] leading-[1.55] text-fg-4 break-words",children:a})]})}function zn(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
|
|
11
|
-
`).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||rt(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function no(t){return zn(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function er(t){return t.phase!=="done"||!t.error?null:zn(t)?"hub.streamErrored":"hub.streamFailed"}function tr({detail:t,t:n,className:s}){const a=Ws(t);if(a==="interrupted")return e.jsxs("div",{className:M("flex items-center gap-1.5 text-[11px] text-fg-5/55",s),children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-[2px] bg-fg-5/45 shrink-0"}),e.jsx("span",{children:n("hub.turnStopped")})]});const l=a==="error"?{dot:"bg-rose-400/55",text:"text-rose-300/65"}:{dot:"bg-fg-5/40",text:"text-fg-5/55"};return e.jsxs("div",{className:M("flex items-start gap-1.5 text-[11px] leading-[1.6]",l.text,s),children:[e.jsx("span",{className:M("mt-[5px] h-1 w-1 rounded-full shrink-0",l.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const nr=64;function sr(t,n){const[s,a]=r.useState(t),l=r.useRef(0),c=r.useRef(null);return r.useEffect(()=>{if(n<=0)return;const x=Date.now()-l.current,d=()=>{l.current=Date.now(),a(t)};return x>=n?d():(c.current&&clearTimeout(c.current),c.current=window.setTimeout(d,n-x)),()=>{c.current&&clearTimeout(c.current)}},[t,n]),n<=0?t:s}function so({stream:t,t:n,workdir:s}){const a=rt(t.plan),[l,c]=r.useState(!1),[x,d]=r.useState(!1),m=r.useRef(null),v=r.useRef(null),g=er(t),j=r.useMemo(()=>(t.activity||"").split(`
|
|
12
|
-
`).filter(Boolean),[t.activity]),C=t.previewMeta?.toolCalls??[],k=j[j.length-1]||C[C.length-1]?.summary||"";r.useLayoutEffect(()=>{const y=m.current;y&&l&&(y.scrollTop=y.scrollHeight)},[l,t.activity,C.length]),r.useLayoutEffect(()=>{const y=v.current;y&&x&&(y.scrollTop=y.scrollHeight)},[x,t.thinking]);const R=t.subAgents??null,I=sr(t.text,t.phase==="streaming"?nr:0),_=r.useMemo(()=>Ut({workdir:s}),[s]),B=r.useMemo(()=>e.jsx(xn,{remarkPlugins:fn,components:_,children:I}),[I,_]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[a&&e.jsx(Fn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),R&&R.length>0&&R.map(y=>e.jsx(Kn,{sub:y,t:n},y.id)),(C.length>0||j.length>0)&&e.jsx(st,{open:l,onToggle:()=>c(y=>!y),dot:{color:"bg-cyan-400/60",pulse:!0},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[12px] text-fg-4 truncate",children:k}),badge:(C.length||j.length)>1?e.jsx(un,{children:C.length||j.length}):void 0,children:e.jsx("div",{ref:m,className:"px-3.5 py-2.5 space-y-0.5 max-h-[280px] overflow-y-auto",children:C.length>0?C.map(y=>e.jsx(rr,{call:y},y.id)):j.map((y,O)=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate",children:y})]},O))})}),t.thinking&&e.jsx(st,{open:x,onToggle:()=>d(y=>!y),dot:{color:"bg-violet-400/50",pulse:!0},label:n("hub.thinking"),collapsedContent:e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:Pn(t.thinking,3)}),children:e.jsx("div",{ref:v,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[280px] overflow-y-auto",children:t.thinking})}),t.text&&e.jsxs("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:[B,t.phase==="streaming"&&e.jsx(ln,{className:"ml-1 inline-flex align-text-bottom text-fg-4"})]}),t.artifacts&&t.artifacts.length>0&&e.jsx("div",{className:"flex flex-col gap-2",children:t.artifacts.map((y,O)=>y.kind==="photo"?e.jsx("a",{href:y.url,target:"_blank",rel:"noreferrer",className:"inline-block",children:e.jsx("img",{src:y.url,alt:y.caption||y.fileName,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain hover:opacity-90 transition-opacity"})},O):e.jsx(Un,{url:y.url,fileName:y.fileName,fileSize:y.fileSize,caption:y.caption},O))}),!t.text&&t.phase==="streaming"&&e.jsx("div",{className:"py-1",children:e.jsx(ln,{className:"text-fg-5"})}),t.phase==="streaming"&&(t.generatingImages??0)>0&&e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-fg-4",children:[e.jsxs("span",{className:"relative inline-flex items-center justify-center w-3 h-3",children:[e.jsx("span",{className:"absolute inline-flex w-3 h-3 rounded-full bg-cyan-400/40 animate-ping"}),e.jsx("span",{className:"relative inline-block w-1.5 h-1.5 rounded-full bg-cyan-400/80"})]}),e.jsx("span",{children:t.generatingImages===1?"Generating image…":`Generating ${t.generatingImages} images…`})]}),g&&t.error&&e.jsx(tr,{detail:t.error,t:n,className:"pt-0.5"})]})}function rr({call:t}){const[n,s]=r.useState(!1),a=!!(t.input||t.result),l=t.status==="failed"?"bg-rose-400/70":t.status==="running"?"bg-cyan-400/70":"bg-fg-5/30";return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>a&&s(c=>!c),className:`flex w-full items-center gap-1.5 py-[2px] text-left min-w-0 ${a?"cursor-pointer hover:bg-white/[0.03] rounded":"cursor-default"}`,title:a?void 0:t.summary,children:[e.jsx("span",{className:`w-1 h-1 rounded-full shrink-0 ${l} ${t.status==="running"?"animate-pulse":""}`}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate flex-1",children:t.summary}),a&&e.jsx("span",{className:`shrink-0 text-[9px] text-fg-5/40 transition-transform ${n?"rotate-90":""}`,children:"▸"})]}),n&&e.jsxs("div",{className:"ml-2.5 mt-0.5 mb-1 space-y-1 border-l border-white/[0.06] pl-2.5",children:[t.input&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-4/80 max-h-[140px] overflow-y-auto",children:t.input}),t.result&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-5/70 max-h-[140px] overflow-y-auto border-t border-white/[0.04] pt-1",children:t.result})]})]})}function ln({className:t}){return e.jsxs("span",{className:`thinking-dots inline-flex items-center gap-[3px] ${t||""}`,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}function Kn({sub:t,t:n}){const[s,a]=r.useState(!1),l=t.status,c=l==="failed"?"bg-rose-400/60":l==="done"?"bg-emerald-400/55":"bg-amber-400/60",x=l==="running",d=t.tools,m=r.useMemo(()=>{const j=new Set,C=[];for(const k of d)j.has(k.name)||(j.add(k.name),C.push(k.name));return C},[d]),v=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",g=t.model?$t(t.model):null;return e.jsx(st,{open:s,onToggle:()=>a(j=>!j),dot:{color:c,pulse:x},label:v,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),g&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:g}),!t.description&&m.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:m.join(" · ")})]}),badge:d.length>0?e.jsx(un,{children:d.length}):void 0,children:e.jsxs("div",{className:"px-3.5 py-2.5 space-y-1 max-h-[260px] overflow-y-auto",children:[t.description&&e.jsx("div",{className:"mb-1.5 text-[12px] text-fg-3 leading-[1.55]",children:t.description}),d.length===0?e.jsxs("div",{className:"text-[11px] font-mono text-fg-5/50",children:["— ",n("hub.subAgentWaiting")||"waiting for first tool…"]}):d.map(j=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/65 truncate",children:j.summary})]},j.id))]})})}function or({message:t,t:n,workdir:s}){const{activityBlocks:a,thinkingBlocks:l,planBlocks:c,subAgentBlocks:x,outputBlocks:d,noticeBlocks:m}=Hn(t.blocks),v=[...c].reverse().find(j=>rt(j.plan));return a.length>0||x.length>0||!!v?.plan||l.length>0||d.length>0||m.length>0?e.jsxs("div",{className:"space-y-3",children:[a.length>0&&e.jsx(ar,{blocks:a,t:n}),x.map(j=>j.subAgent?e.jsx(Kn,{sub:j.subAgent,t:n},j.toolId||j.subAgent.id):null),v?.plan&&e.jsx(Fn,{plan:v.plan,t:n,className:"max-w-[760px]"}),l.length>0&&e.jsx(dr,{blocks:l,t:n}),d.length>0&&e.jsx(xr,{blocks:d,t:n,workdir:s}),m.length>0&&e.jsx(lr,{blocks:m,t:n})]}):null}function ir(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:a,subAgentBlocks:l,outputBlocks:c,noticeBlocks:x}=Hn(t.blocks);return c.length>0||n.length>0||l.length>0||s.length>0||a.some(d=>rt(d.plan))||x.length>0}function Hn(t){const n=t.filter(s=>s.type==="plan"||s.type==="tool_use"||s.type==="tool_result"||s.type==="image"||s.type==="file"||s.type==="sub_agent"||!!s.content.trim());return{activityBlocks:n.filter(s=>s.type==="tool_use"||s.type==="tool_result"),thinkingBlocks:n.filter(s=>s.type==="thinking"),planBlocks:n.filter(s=>s.type==="plan"&&rt(s.plan)),subAgentBlocks:n.filter(s=>s.type==="sub_agent"),outputBlocks:n.filter(s=>s.type==="text"||s.type==="image"||s.type==="file"),noticeBlocks:n.filter(s=>s.type==="system_notice")}}function lr({blocks:t,t:n}){const s=t.map(a=>a.content).filter(Boolean).join(`
|
|
13
|
-
|
|
14
|
-
`).trim();return s?e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/[0.06] px-3 py-2 text-[12.5px] leading-[1.7] text-fg-3",children:[e.jsx("span",{className:"mt-[6px] h-1.5 w-1.5 rounded-full bg-amber-400/70 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-mono uppercase tracking-wide text-amber-300/80",children:n("hub.systemNotice")||"Agent notice"}),e.jsx("div",{className:"mt-0.5 break-words whitespace-pre-wrap",children:s})]})]}):null}function ar({blocks:t,t:n}){const[s,a]=r.useState(!1),l=t.filter(m=>m.type==="tool_use"),c=l.length,x=l[l.length-1],d=x?Bn(x):"";return e.jsx(st,{open:s,onToggle:()=>a(m=>!m),dot:{color:"bg-cyan-400/60"},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[11.5px] font-mono text-fg-4 truncate",children:d}),badge:c>0?e.jsx(un,{children:c}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((m,v)=>e.jsx(cr,{block:m},v))})})}function cr({block:t}){const[n,s]=r.useState(!1),a=t.type==="tool_use",l=a?Bn(t):Ds(t);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&s(c=>!c),className:M("flex items-center gap-2 py-[3px] w-full text-left group rounded-sm transition-colors",t.content&&"hover:bg-panel-h/30"),children:[e.jsx("span",{className:M("h-1.5 w-1.5 rounded-full shrink-0",a?"bg-fg-5/40":"bg-ok/40")}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 group-hover:text-fg-3 transition-colors truncate",children:l})]}),n&&t.content&&e.jsx("pre",{className:"ml-3 mt-1 mb-2 p-3 rounded-md bg-inset border border-edge text-[11px] leading-[1.6] text-fg-4 font-mono whitespace-pre-wrap break-words max-h-[240px] overflow-y-auto",children:t.content.length>3e3?t.content.slice(0,3e3)+`
|
|
15
|
-
…`:t.content})]})}function dr({blocks:t,t:n}){const[s,a]=r.useState(!1),l=r.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
|
|
16
|
-
|
|
17
|
-
`).trim();if(!c)return null;const x=Pn(c,3);return e.jsx(st,{open:s,onToggle:()=>a(d=>!d),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:x?e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:x}):void 0,children:e.jsx(ur,{scrollRef:l,text:c})})}function ur({scrollRef:t,text:n}){return r.useLayoutEffect(()=>{const s=t.current;s&&(s.scrollTop=s.scrollHeight)},[t]),e.jsx("div",{ref:t,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[320px] overflow-y-auto",children:n})}function hr({block:t,onLightbox:n,t:s}){const a=t.imageCaption?.trim()||"",[l,c]=r.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:a||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),a&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>c(x=>!x),"aria-expanded":l,className:M("self-start inline-flex items-center gap-1 px-2 py-[3px] rounded-md","text-[11px] font-medium tracking-wide","border border-fg-6/40 bg-fg-6/[0.06] text-fg-3","hover:bg-fg-6/[0.12] hover:text-fg-2 hover:border-fg-6/60","transition-colors"),title:s(l?"hub.imagePromptHide":"hub.imagePromptShow"),children:[e.jsx("span",{"aria-hidden":!0,className:"text-[9px] leading-none",children:l?"▾":"▸"}),e.jsx("span",{children:s("hub.imagePrompt")})]}),l&&e.jsx("div",{className:"rounded-md border border-fg-6/30 bg-fg-6/[0.05] px-3 py-2 max-w-[400px] max-h-[260px] overflow-y-auto",children:e.jsx("div",{className:"text-[11.5px] leading-[1.65] text-fg-3 whitespace-pre-wrap break-words",children:a})})]})]})}function xr({blocks:t,t:n,workdir:s}){const a=t.filter(g=>g.type==="text"),l=t.filter(g=>g.type==="image"),c=t.filter(g=>g.type==="file"),x=a.map(g=>g.content).filter(Boolean).join(`
|
|
18
|
-
|
|
19
|
-
`),[d,m]=r.useState(null),v=r.useMemo(()=>Ut({workdir:s}),[s]);return!x.trim()&&l.length===0&&c.length===0?null:e.jsxs(e.Fragment,{children:[x.trim()&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:e.jsx(xn,{remarkPlugins:fn,components:v,children:x})}),l.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:l.map((g,j)=>e.jsx(hr,{block:g,onLightbox:m,t:n},j))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((g,j)=>e.jsx(Un,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},j))}),d&&e.jsx(Vn,{src:d,onClose:()=>m(null)})]})}const ro=r.memo(function({turn:n,turnIndex:s,agent:a,meta:l,model:c,effort:x,providerName:d,t:m,workdir:v,onResend:g,onEdit:j,onFork:C}){const k=n.user&&_n(n.user.text),R=C&&typeof s=="number"?()=>C(s):void 0,I=r.useMemo(()=>Ut({workdir:v}),[v]),_=!!n.assistant&&ir(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!k&&e.jsx(Gn,{text:n.user.text,blocks:n.user.blocks,t:m,onResend:g,onEdit:j,onFork:R}),k&&n.user&&!n.assistant&&e.jsx("div",{className:"mb-4 px-4 py-3 rounded-lg bg-[rgba(255,255,255,0.02)] border border-edge/20 text-[12.5px] leading-[1.7] text-fg-4",children:e.jsx(xn,{remarkPlugins:fn,components:I,children:n.user.text})}),_&&e.jsxs(e.Fragment,{children:[e.jsx(mr,{agent:a,meta:l,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(or,{message:n.assistant,t:m,workdir:v})})]})]})});function Vn({src:t,onClose:n}){return r.useEffect(()=>{const s=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),hn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm cursor-zoom-out",onClick:n,children:e.jsx("img",{src:t,className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl",onClick:s=>s.stopPropagation()})}),document.body)}const pr=1500,fr=16,yn=8;function gr(t){const n=t.split(`
|
|
20
|
-
`);return n.length<=yn?t:n.slice(0,yn).join(`
|
|
21
|
-
`)}function Gn({text:t,blocks:n,t:s,onResend:a,onEdit:l,onFork:c}){const[x,d]=r.useState(!1),[m,v]=r.useState(!1),[g,j]=r.useState(null),C=t?t.split(`
|
|
22
|
-
`).length:0,k=!!t&&(t.length>pr||C>fr),[R,I]=r.useState(!1),_=t?k&&!R?gr(t):t:"",B=!!(a||l||c),y=n?.filter(A=>A.type==="image")||[],O=()=>{navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),1500)}).catch(()=>{})},ee=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(C));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[_,k&&!R&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),k&&e.jsx("button",{type:"button",onClick:()=>I(A=>!A),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:R?s("hub.collapse"):ee}),y.length>0&&e.jsx("div",{className:M("flex flex-wrap gap-2",t&&"mt-2"),children:y.map((A,K)=>e.jsx("img",{src:A.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(A.content)},K))})]}),g&&e.jsx(Vn,{src:g,onClose:()=>j(null)}),B&&e.jsxs("div",{className:M("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(It,{label:s(m?"hub.copied":"hub.copy"),onClick:O,children:m?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),a&&e.jsx(It,{label:s("hub.rerun"),onClick:()=>a(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),l&&e.jsx(It,{label:s("hub.edit"),onClick:()=>l(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),c&&e.jsx(It,{label:s("hub.fork"),onClick:c,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]})})]})]})}function It({label:t,onClick:n,children:s}){return e.jsx("button",{onClick:n,title:t,className:"flex items-center justify-center w-7 h-7 rounded border border-fg-6 bg-panel text-fg-4 shadow-sm hover:text-fg-2 hover:border-edge-h hover:bg-panel-h transition-colors",children:s})}function mr({agent:t,meta:n,model:s,effort:a,providerName:l,previewMeta:c,liveStartedAt:x}){const d=c?.contextPercent??null,m=c?.contextUsedTokens??0,v=c?.turnOutputTokens??0,g=d!=null||m>0||v>0,j=x!=null&&x>0,C=c?.providerName??l??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(nt,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||a)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&a?" · ":"",a||""]}),C&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/70 px-1.5 py-px rounded bg-fg-5/8",title:`This turn is routed through ${C} (BYOK), not the agent CLI's native auth.`,children:["via ",C]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:wr(c),children:[d!=null&&e.jsx(kr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",jr(m)]}),v>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",qn(v)]}),j&&e.jsx(br,{startedAt:x,leadingDot:g})]})]})}function br({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const l=setInterval(()=>s(c=>c+1),1e3);return()=>clearInterval(l)},[]);const a=Math.max(0,Date.now()-t);return e.jsxs("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:[n?"· ":"",vr(a)]})}function vr(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),a=n%60;return s<60?`${s}m${a.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function jr(t){return`${qn(t)} tok`}function qn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function wr(t){if(!t)return"";const n=[];return t.contextPercent!=null&&n.push(`Context: ${t.contextPercent.toFixed(1)}%`),t.inputTokens!=null&&n.push(`Input: ${t.inputTokens.toLocaleString()}`),t.turnOutputTokens!=null?n.push(`Output (turn): ${t.turnOutputTokens.toLocaleString()}`):t.outputTokens!=null&&n.push(`Output: ${t.outputTokens.toLocaleString()}`),t.cachedInputTokens!=null&&n.push(`Cached: ${t.cachedInputTokens.toLocaleString()}`),n.join(" · ")}function kr({pct:t}){const n=t>=85?"bg-rose-400/70":t>=60?"bg-amber-400/70":"bg-emerald-400/70";return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${n}`})}function Nn(t,n,s){return t==="zh-CN"?n:s}function yr({open:t,onClose:n,workdir:s}){const a=Le(c=>c.locale),l=s.split("/").pop()||s;return e.jsxs(Ot,{open:t,onClose:n,wide:!0,children:[e.jsx(Dt,{title:Nn(a,`${l} — 项目扩展`,`${l} — Project Extensions`),description:Nn(a,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(ys,{workdir:s}):null]})}let Sn=Tn(()=>import("./SessionPanel-DD1k_k6Z.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function an(){return Sn??=Tn(()=>import("./SessionPanel-DD1k_k6Z.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Sn}const Nr=r.lazy(async()=>({default:(await an()).SessionPanel})),sn=5,Sr=240,Cr=120,Lr=12,Mr=900*1e3,H=(t,n)=>`${t}:${n}`;function Tr(t){const n=new Map;for(const d of t)n.set(H(d.agent||"",d.sessionId),d);const s=new Map,a=new Set;for(const d of t){const m=d.migratedFrom;if(!m||m.kind!=="fork"||!m.sessionId)continue;const v=H(m.agent||d.agent||"",m.sessionId);n.has(v)&&(a.add(H(d.agent||"",d.sessionId)),s.has(v)||s.set(v,[]),s.get(v).push(d))}const l=[],c=new Set,x=(d,m)=>{const v=H(d.agent||"",d.sessionId);if(c.has(v))return;c.add(v),l.push(Object.assign({},d,{__forkDepth:m}));const g=s.get(v);if(g)for(const j of g)x(j,m+1)};for(const d of t){const m=H(d.agent||"",d.sessionId);a.has(m)||x(d,0)}for(const d of t)x(d,0);return l}let Er=0;function At(){return`mk-${Date.now().toString(36)}-${(++Er).toString(36)}`}function Rt(t){try{const n=localStorage.getItem(t);if(n!=null)return n;const s=sessionStorage.getItem(t);if(s!=null){try{localStorage.setItem(t,s),sessionStorage.removeItem(t)}catch{}return s}}catch{}return null}function _t(t,n){try{localStorage.setItem(t,n)}catch{}}const Ir=[1,2,3,6],cn=6;function Ar(t){for(const n of Ir)if(n>=t)return n;return cn}function Cn(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function Ue(t,n){const s=Ar(t);return s>n?s:n}function Rr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function _r(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function Qn(t){switch(t){case"cursor":return"hub.openTargetCursor";case"windsurf":return"hub.openTargetWindsurf";case"finder":return"hub.openTargetFinder";case"default":return"hub.openTargetDefault";default:return"hub.openTargetVsCode"}}const Pr=r.memo(function({active:n=!0}){const s=Le(o=>o.locale),a=Le(o=>o.state?.runtimeWorkdir??null),l=r.useMemo(()=>hs(s),[s]),[c,x]=r.useState([]),[d,m]=r.useState({}),[v,g]=r.useState({}),[j,C]=r.useState(!0),[k,R]=r.useState(()=>{const o=Rt("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Cn()}),[I,_]=r.useState(()=>{const o=Rt("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Cn()}),[B,y]=r.useState(()=>{try{const o=Rt("pikiloom-open-sessions");if(o){const h=JSON.parse(o);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||At()}))}}catch{}return[]}),[O,ee]=r.useState(()=>{const o=Rt("pikiloom-active-slot");if(o!=null){const h=Number(o);if(Number.isFinite(h)&&h>=0)return h}return 0}),A=r.useCallback(o=>{R(o),_t("pikiloom-layout-mode",String(o))},[]),K=r.useCallback(o=>{_(o),_t("pikiloom-layout-floor",String(o))},[]),$=r.useCallback(o=>{y(h=>{const u=typeof o=="function"?o(h):o,f=u.map(({pendingPrompt:w,pendingImageUrls:N,...T})=>T);return _t("pikiloom-open-sessions",JSON.stringify(f)),u})},[]),D=r.useCallback(o=>{ee(h=>{const u=typeof o=="function"?o(h):o;return _t("pikiloom-active-slot",String(u)),u})},[]),ce=r.useCallback(o=>{A(o),K(o)},[A,K]);r.useEffect(()=>{$(o=>o.length>k?o.slice(0,k):o),D(o=>o>=k?k-1:o)},[k]);const[P,re]=r.useState(!1),oe=r.useRef(k);oe.current=k;const V=r.useRef(I);V.current=I;const Me=r.useRef(O);Me.current=O;const z=r.useRef(B);z.current=B;const mt=r.useRef(-1),fe=B[O]??null,ot=r.useCallback(o=>{if(!o){$([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:At()};$(u=>{const f=u.findIndex(N=>N.agent===h.agent&&N.sessionId===h.sessionId);if(f>=0)return D(f),u;if(u.length<oe.current){const N=[...u,h];return D(N.length-1),N}if(oe.current<cn){const N=[...u,h];return A(Ue(N.length,V.current)),D(N.length-1),N}const w=[...u];return w[Me.current]=h,w})},[$,D,A]),[Ke,He]=r.useState(!1),[ie,_e]=r.useState(null),[te,Te]=r.useState(""),[Pe,Ve]=r.useState("all"),[de,bt]=r.useState({}),ge=r.useDeferredValue(te),le=r.useRef(!1),We=r.useRef({}),Ee=r.useRef(d);Ee.current=d;const it=r.useRef(de);it.current=de;const Ie=r.useRef(new Set),ne=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values(ne.current))clearTimeout(o)},[]);const me=r.useCallback(async()=>{try{const o=await Z.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((f,w)=>f.path===h[w].path&&f.name===h[w].name)?u:h),le.current=!0}catch{le.current=!0}finally{C(!1)}},[]);r.useEffect(()=>{me()},[me]);const L=r.useCallback(async(o,h={})=>{if(!We.current[o]){We.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Ms(o,{force:h.force});r.startTransition(()=>{m(f=>{const w=u.sessions||[],N=f[o]||[],T=new Set(w.map(E=>H(E.agent||"",E.sessionId))),X=N.filter(E=>{if(E.runState!=="running")return!1;const W=H(E.agent||"",E.sessionId);if(T.has(W))return!1;const U=it.current[W];return!(U?.resolvedKey&&U.resolvedKey!==W)});return{...f,[o]:X.length?[...X,...w]:w}})})}catch{h.background||r.startTransition(()=>{m(u=>({...u,[o]:[]}))})}finally{We.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),Y=r.useRef(a);r.useEffect(()=>{a!==Y.current&&(Y.current=a,!(!a||!le.current)&&me().then(()=>{L(a,{force:!0})}))},[a,me,L]);const G=r.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(an(),Is({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Lr}))},[]),vt=r.useCallback((o,h,u=Cr)=>{const f=`${h}:${H(o.agent||"",o.sessionId)}`,w=ne.current[f];w&&clearTimeout(w),ne.current[f]=setTimeout(()=>{delete ne.current[f],G(o,h)},u)},[G]),Ae=r.useCallback((o,h)=>{const u=`${h}:${H(o.agent||"",o.sessionId)}`,f=ne.current[u];f&&(clearTimeout(f),delete ne.current[u])},[]);r.useEffect(()=>{n&&an()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||v[h.path])return;const f=setTimeout(()=>{L(h.path)},u*90);o.push(f)}),()=>{for(const h of o)clearTimeout(h)}},[n,L,v,d,c]);const Ge=r.useRef(new Map);wn(n&&le.current&&c.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=o.key,u=h?c.filter(N=>(Ee.current[N.path]||[]).some(T=>H(T.agent||"",T.sessionId)===h)):c,f=u.length?u:c,w=Ge.current;for(const N of f)w.has(N.path)&&clearTimeout(w.get(N.path)),w.set(N.path,setTimeout(()=>{w.delete(N.path),L(N.path,{background:!0,force:!0})},300))},[c,L]));const Be=r.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:xs(o,de[H(h,o.sessionId)]||null)},[de]);wn("stream-update",r.useCallback(o=>{const h=o.key;if(!h)return;const u=ps(h,o.snapshot??null);bt(f=>{if(!u){const W=f[h];return!W||W.phase==="done"?f:{...f,[h]:{...W,phase:"done",updatedAt:Date.now()}}}const w=(W,U)=>!!W&&!!U&&W.phase===U.phase&&W.resolvedKey===U.resolvedKey&&W.sessionId===U.sessionId&&W.incomplete===U.incomplete&&W.error===U.error,N=w(f[h],u),T=u.resolvedKey===h||w(f[u.resolvedKey],{...u,key:u.resolvedKey});if(N&&T)return f;const X=Date.now()-Mr,E={};for(const[W,U]of Object.entries(f))U.phase==="done"&&U.updatedAt<X||(E[W]=U);return E[h]=u,u.resolvedKey!==h&&(E[u.resolvedKey]={...u,key:u.resolvedKey}),E})},[])),fs(r.useCallback(()=>{if(!(!n||!le.current||c.length===0))for(const o of c)L(o.path,{background:!0,force:!0})},[n,c,L])),r.useEffect(()=>{if(!n||!le.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)L(u.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,L,c]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const f=(d[h.path]||[])[0];if(!f)return;const w=`${h.path}:${H(f.agent||"",f.sessionId)}`;if(Ie.current.has(w))return;const N=setTimeout(()=>{Ie.current.add(w),G(f,h.path)},Sr+u*120);o.push(N)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,G,c]);const zt=r.useCallback(async o=>{try{(await Z.addWorkspace(o)).ok&&(He(!1),await me(),L(o))}catch{}},[me,L]),[ue,be]=r.useState(null),[ve,jt]=r.useState(!1),[ae,$e]=r.useState(null),qe=r.useCallback(o=>{be(o)},[]),Qe=r.useCallback(async()=>{const o=ue;if(o){jt(!0);try{await Z.removeWorkspace(o),x(h=>h.filter(u=>u.path!==o)),m(h=>{const u={...h};return delete u[o],u}),$(h=>{const u=h.filter(f=>f.workdir!==o);return u.length!==h.length&&A(Ue(u.length,V.current)),u}),D(0),be(null)}catch{}finally{jt(!1)}}},[ue]),Ye=r.useCallback(o=>{L(o,{force:!0})},[L]),[he,je]=r.useState(null),[Xe,Oe]=r.useState(!1),[we,lt]=r.useState(!1),at=Le(o=>o.toast),[se,ke]=r.useState(null),Je=r.useCallback((o,h,u)=>{ke({anchor:{right:o.right,bottom:o.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:Ln(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!se)return;const o=()=>ke(null),h=u=>{u.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",h)}},[se]);const wt=r.useCallback(o=>{Oe(!1),je(o),ke(null)},[]),ct=r.useCallback(async()=>{const o=he;if(o){lt(!0);try{const h=await Z.deleteSession(o.workdir,o.agent,o.sessionId,Xe);if(!h.ok){const u=h.error?.includes("still running")?l("session.deleteRunningError"):h.error||l("session.deleteFailed");at(u,!1);return}m(u=>{const f=u[o.workdir];if(!f)return u;const w=f.filter(N=>!(N.agent===o.agent&&N.sessionId===o.sessionId));return w.length===f.length?u:{...u,[o.workdir]:w}}),$(u=>{const f=u.filter(w=>!(w.workdir===o.workdir&&w.agent===o.agent&&w.sessionId===o.sessionId));return f.length!==u.length&&A(Ue(f.length,V.current)),f}),je(null)}catch(h){at(h?.message||l("session.deleteFailed"),!1)}finally{lt(!1)}}},[he,Xe,l,at]),ye=r.useCallback(o=>{$(h=>{let u=!1;const f=h.map(w=>w.mountKey===o&&(w.pendingPrompt!=null||w.pendingImageUrls)?(u=!0,{...w,pendingPrompt:null,pendingImageUrls:void 0}):w);return u?f:h})},[$]),kt=r.useCallback((o,h,u)=>{G({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),m(N=>{const T=N[o.workdir]||[];if(T.some(W=>W.sessionId===o.sessionId&&W.agent===o.agent))return N;const E={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...N,[o.workdir]:[E,...T]}});const f=mt.current,w={...o,mountKey:At(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};r.startTransition(()=>{_e(null),$(N=>{if(f>=N.length)return[...N,w];const T=[...N];return T[f]=w,T}),D(f>=0?f:0)}),L(o.workdir,{background:!0,force:!0})},[L,G,$,D]),dt=r.useCallback(o=>{z.current.length>=oe.current&&oe.current<cn&&A(Ue(oe.current+1,V.current)),_e(o)},[A]),yt=r.useCallback(()=>{_e(null),A(Ue(z.current.length,V.current))},[A]),Nt=r.useCallback((o,h)=>{G(o,h);const u=o.agent||"";z.current.some(f=>f.agent===u&&f.sessionId===o.sessionId)&&A(Ue(z.current.length,V.current)),_e(null),r.startTransition(()=>{ot({agent:u,sessionId:o.sessionId,workdir:h})})},[G,A]),St=r.useCallback((o,h)=>{G({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{h!=null?($(u=>{if(h>=u.length)return u;const f=[...u];return f[h]={...u[h],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},f}),D(h)):ot({...o,mountKey:At()})}),L(o.workdir,{background:!0,force:!0})},[L,G]),ut=r.useCallback(o=>{let h=o;if(Pe==="running"?h=h.filter(u=>Pt(u)==="running"):Pe==="review"&&(h=h.filter(u=>Pt(u)==="incomplete")),ge.trim()){const u=ge.toLowerCase();h=h.filter(f=>(f.lastMessageText||"").toLowerCase().includes(u)||(f.lastQuestion||"").toLowerCase().includes(u)||(f.lastAnswer||"").toLowerCase().includes(u)||(f.title||"").toLowerCase().includes(u)||(f.agent||"").toLowerCase().includes(u))}return h},[ge,Pe]),xe=r.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(Be),f=new Map;for(const N of u){const T=H(N.agent||"",N.sessionId),X=de[T],E=X?.resolvedKey&&X.resolvedKey!==T?X.resolvedKey:T,W=f.get(E);if(!W){f.set(E,N);continue}H(W.agent||"",W.sessionId)!==E&&T===E&&f.set(E,N)}const w=ut([...f.values()]);o[h.path]=Tr(w)}return o},[c,d,de,ut,Be]),Ct=r.useCallback(o=>{const h=(d[o.workdir]||[]).find(u=>u.sessionId===o.sessionId&&u.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return Be(h)},[Be,d]),ht=r.useMemo(()=>new Set(B.map(o=>H(o.agent,o.sessionId))),[B]),Kt=fe?H(fe.agent,fe.sessionId):null,Ht=r.useCallback(o=>{$(h=>{const u=h.filter((f,w)=>w!==o);return u.length===0?D(0):Me.current>=u.length&&D(u.length-1),A(Ue(u.length,V.current)),u})},[$,D,A]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:te,onChange:o=>Te(o.target.value),placeholder:l("hub.search"),className:"w-full rounded-lg border border-edge/40 bg-inset/50 pl-8 pr-7 py-1.5 text-[12px] text-fg outline-none placeholder:text-fg-5/30 focus:border-primary/30 focus:bg-inset focus:shadow-[0_0_0_3px_rgba(99,102,241,0.06)] transition-all duration-200"}),te&&e.jsx("button",{onClick:()=>Te(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-fg-5/30 hover:text-fg-4 transition-colors",children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex items-center rounded-lg bg-inset/30 border border-edge/20 p-0.5",children:["all","running","review"].map(o=>e.jsx("button",{onClick:()=>Ve(o),className:M("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",Pe===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1),inset_0_1px_0_rgba(255,255,255,0.04)]":"text-fg-5/60 hover:text-fg-4"),children:l(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(pe,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!Ke?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:l("hub.noWorkspaces")}):c.map(o=>e.jsx(Or,{workspace:o,sessions:xe[o.path]||[],loading:!!v[o.path]||!(o.path in d),isActive:o.path===a,selectedKey:Kt,openSessionKeys:ht,onSelectSession:Nt,onNewSession:dt,onRefresh:Ye,onRemove:qe,onExtensions:$e,onWarmSession:vt,onCancelWarmSession:Ae,onSessionMenuOpen:Je,t:l},o.path))}),e.jsxs("div",{className:"shrink-0 border-t border-edge/20 px-3 py-2 space-y-1.5",children:[e.jsx("div",{className:"flex items-center rounded-md bg-inset/30 border border-edge/20 p-0.5",children:[1,2,3,6].map(o=>e.jsx("button",{onClick:()=>ce(o),className:M("flex-1 flex items-center justify-center p-1.5 rounded transition-all",k===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1)]":"text-fg-5/40 hover:text-fg-4"),title:l(`hub.layout${o}`),children:o===1?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"})}):o===2?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"12",rx:"1.5"}),e.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"1.5"})]}):o===3?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"0.5",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"11.5",y:"2",width:"4",height:"12",rx:"1"})]}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:[e.jsx("rect",{x:"0.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"0.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"})]})},o))}),e.jsxs(Re,{variant:"ghost",size:"sm",onClick:()=>He(o=>!o),className:"w-full",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),l("hub.addWorkspace")]})]})]}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden gap-0",children:e.jsx("div",{className:"flex-1 min-h-0 grid gap-3",style:{gridTemplateColumns:`repeat(${k===6?3:k}, 1fr)`,gridTemplateRows:k===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=ie?B.length<k?B.length:O:-1;return mt.current=o,Array.from({length:k},(h,u)=>{if(ie&&u===o)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-edge bg-panel flex flex-col",style:{boxShadow:"var(--th-card-shadow)"},children:e.jsx(Br,{workdir:ie,workspaceName:c.find(T=>T.path===ie)?.name||ie.split("/").pop()||"",onSessionCreated:kt,onClose:yt,t:l},ie)},`new-${ie}`);const f=B[u]??null;if(!f)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-dashed border-edge/40 bg-panel/30 flex items-center justify-center",children:e.jsxs("div",{className:"text-center px-4",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"mx-auto text-fg-5/20 mb-2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("div",{className:"text-[12px] text-fg-5/40",children:l("hub.emptySlot")})]})},`empty-${u}`);const w=Ct(f),N=u===O;return e.jsxs("div",{className:M("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",N?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:N?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>D(u),children:[e.jsxs("div",{className:M("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",N?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const T=Pt(w);return e.jsx(Ft,{variant:T==="running"?"ok":T==="waiting"?"info":T==="incomplete"?"warn":"idle",pulse:T==="running"||T==="waiting"})})(),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-0",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-fg-5",children:f.workdir.split("/").pop()||f.workdir}),e.jsx("span",{className:"shrink-0 text-fg-6 text-[10px] mx-1",children:"/"}),e.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-fg-3",children:w.title||w.lastQuestion?.slice(0,60)||f.sessionId.slice(0,12)})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-2.5 pl-4 text-[9px] text-fg-5/50 tabular-nums",children:[e.jsx("span",{title:l("hub.created"),children:gs(w.createdAt)}),w.runUpdatedAt&&e.jsx("span",{title:l("hub.updated"),children:Mn(w.runUpdatedAt)}),!!w.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),w.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:T=>{T.stopPropagation(),re(X=>!X)},className:M("p-0.5 rounded transition-colors",P?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:l("hub.files"),children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})})}),e.jsx("button",{onClick:T=>{T.stopPropagation(),Ht(u)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:l("hub.closePanel"),children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Nr,{session:w,workdir:f.workdir,active:n&&N,onSessionChange:T=>St(T,u),initialPendingPrompt:f.pendingPrompt??null,initialPendingImageUrls:f.pendingImageUrls,onPendingPromptConsumed:()=>ye(f.mountKey)},f.mountKey)})})]},f.mountKey||H(f.agent,f.sessionId))})})()})}),P&&fe&&e.jsx(Fr,{workdir:fe.workdir,onClose:()=>re(!1),t:l}),e.jsx(Wr,{open:Ke,initialPath:a||void 0,onAdd:zt,onClose:()=>He(!1),t:l}),e.jsxs(Ot,{open:!!ue,onClose:()=>!ve&&be(null),children:[e.jsx(Dt,{title:l("hub.removeWorkspace"),onClose:()=>!ve&&be(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:l("modal.confirmRemoveWorkspaceHint")}),ue&&e.jsx("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 font-mono text-[11px] text-fg-4 break-all",children:ue}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Re,{variant:"ghost",onClick:()=>be(null),disabled:ve,children:l("modal.cancel")}),e.jsx(Re,{variant:"primary",onClick:Qe,disabled:ve,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(ve?"modal.removing":"modal.remove")})]})]}),se&&(()=>{const h=Math.max(8,Math.min(se.anchor.right-160,window.innerWidth-160-8)),u=Math.min(se.anchor.bottom+4,window.innerHeight-60);return e.jsx("div",{className:"fixed z-[60] min-w-[160px] rounded-md border border-edge bg-panel/95 backdrop-blur-md py-1",style:{left:h,top:u,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:f=>f.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>wt(se.target),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-[12px] text-fg-2 hover:bg-panel-h/60 hover:text-red-400 transition-colors",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),e.jsx("path",{d:"M10 11v6"}),e.jsx("path",{d:"M14 11v6"}),e.jsx("path",{d:"M9 6V4a2 2 0 012-2h2a2 2 0 012 2v2"})]}),l("session.delete")]})})})(),e.jsxs(Ot,{open:!!he,onClose:()=>!we&&je(null),children:[e.jsx(Dt,{title:l("session.deleteTitle"),onClose:()=>!we&&je(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("session.deleteHint")}),he&&e.jsxs("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 text-[11px] text-fg-4 break-all",children:[e.jsx("span",{className:"font-mono text-fg-5",children:he.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:he.title})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:!Xe,onChange:()=>Oe(!1),disabled:we,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:l("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:l("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:Xe,onChange:()=>Oe(!0),disabled:we,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:l("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:l("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Re,{variant:"ghost",onClick:()=>je(null),disabled:we,children:l("modal.cancel")}),e.jsx(Re,{variant:"primary",onClick:ct,disabled:we,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(we?"session.deleting":"modal.remove")})]})]}),e.jsx(yr,{open:!!ae,onClose:()=>$e(null),workdir:ae||""})]})});function Wr({open:t,initialPath:n,onAdd:s,onClose:a,t:l}){const[c,x]=r.useState(""),d=r.useCallback(m=>x(m),[]);return r.useEffect(()=>{t&&x("")},[t]),e.jsxs(Ot,{open:t,onClose:a,children:[e.jsx(Dt,{title:l("hub.addWorkspace"),onClose:a}),e.jsx(js,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:l}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Re,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:l("hub.add")}),e.jsx(Re,{variant:"secondary",onClick:a,className:"flex-1",children:l("hub.cancel")})]})]})}function Br({workdir:t,workspaceName:n,onSessionCreated:s,onClose:a,t:l}){const[c,x]=r.useState(null),[d,m]=r.useState([]),v=r.useRef(null),g=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),C=r.useCallback(()=>{},[]),k=r.useCallback((_,B)=>{x(_||null),v.current=_||null;const y=B||[];m(y),g.current=y},[]),R=r.useCallback(_=>{const B=g.current;g.current=[],s(_,v.current||void 0,B.length?B:void 0)},[s]),I=!!c||d.length>0;return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 h-10 border-b border-edge/50 bg-panel/40 backdrop-blur-md z-10",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[13px] font-medium text-fg truncate",children:l("hub.newSession")}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-fg-5/60 shrink-0",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"})}),e.jsx("span",{className:"max-w-[80px] truncate",children:n})]}),e.jsx(Ft,{variant:I?"ok":"idle",pulse:I}),!I&&e.jsx("button",{onClick:a,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:I?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(Gn,{text:c||"",blocks:d.map(_=>({type:"image",content:_})),t:l}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(ln,{className:"text-fg-5"})})]}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"text-center space-y-1.5",children:e.jsx("div",{className:"text-[13px] text-fg-5",children:l("hub.newSessionHint")})})})}),e.jsx(Ks,{session:j,workdir:t,onStreamQueued:C,onSendStart:k,onSessionChange:R,t:l,streamPhase:null})]})}function $r({git:t}){if(!t)return null;const n=[t.detached?`detached HEAD${t.shortSha?` @ ${t.shortSha}`:""}`:`branch ${t.branch??"?"}`,t.upstream?`upstream ${t.upstream}`:t.detached?"":"no upstream",t.ahead||t.behind?`↑${t.ahead} ahead · ↓${t.behind} behind`:"",t.changed>0?`${t.changed} changed (${t.staged} staged · ${t.unstaged} unstaged · ${t.untracked} untracked)`:"clean"].filter(Boolean).join(`
|
|
23
|
-
`);return e.jsx(ms,{content:n,className:M("shrink-0 items-center",t.changed>0?"text-amber-400/80":t.ahead||t.behind?"text-sky-400/70":"text-fg-5/50"),onClick:s=>s.stopPropagation(),children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.5"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.5"}),e.jsx("circle",{cx:"18",cy:"8",r:"2.5"}),e.jsx("path",{d:"M6 8.5v7"}),e.jsx("path",{d:"M18 10.5c0 4.5-6 3-6 7.5"})]})})}const Or=r.memo(function({workspace:n,sessions:s,loading:a,isActive:l,selectedKey:c,openSessionKeys:x,onSelectSession:d,onNewSession:m,onRefresh:v,onRemove:g,onExtensions:j,onWarmSession:C,onCancelWarmSession:k,onSessionMenuOpen:R,t:I}){const[_,B]=r.useState(!0),[y,O]=r.useState(sn);r.useEffect(()=>{O(sn)},[s.length]);const ee=s.slice(0,y),A=s.length-y,K=n.path,[$,D]=r.useState(null),ce=r.useCallback(()=>{Z.getWorkspaceGit(K).then(P=>D(P.git)).catch(()=>D(null))},[K]);return r.useEffect(()=>{ce()},[ce]),e.jsxs("div",{className:"border-b border-edge/30",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-panel-h/50 transition-colors",onClick:()=>B(P=>!P),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:M("shrink-0 text-fg-5 transition-transform duration-150",_&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[e.jsx("span",{className:M("min-w-0 truncate text-[12px] font-semibold",l?"text-primary":"text-fg-3"),children:n.name}),e.jsx($r,{git:$})]}),l&&e.jsx(Ft,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:P=>{P.stopPropagation(),m(K)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:I("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:P=>{P.stopPropagation(),j(K)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:I("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:P=>{P.stopPropagation(),v(K),ce()},className:"p-1 rounded text-fg-5 hover:text-fg-2 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),!l&&e.jsx("button",{onClick:P=>{P.stopPropagation(),g(K)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),_&&e.jsx("div",{className:"pb-1",children:a?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):s.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:I("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[ee.map(P=>{const re=H(P.agent||"",P.sessionId),oe=P.__forkDepth||0;return e.jsx(Dr,{session:P,isSelected:c===re,isOpen:x?.has(re)??!1,forkDepth:oe,onClick:()=>d(P,K),onWarm:()=>C(P,K),onCancelWarm:()=>k(P,K),onShowMenu:V=>R(V,P,K),menuLabel:I("session.openActions")},re)}),A>0&&e.jsxs("button",{onClick:()=>O(P=>P+sn),className:"flex items-center gap-1.5 w-full px-3 py-1.5 text-[11px] text-fg-5 hover:text-fg-3 hover:bg-panel-h/50 transition-colors",children:[e.jsxs("span",{children:["+ ",I("hub.nMore").replace("{n}",String(A))]}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]})})]})}),Dr=r.memo(function({session:n,isSelected:s,isOpen:a,forkDepth:l=0,onClick:c,onWarm:x,onCancelWarm:d,onShowMenu:m,menuLabel:v}){const g=rn(n.agent||""),j=Pt(n),C=Ln(n).slice(0,500)||n.sessionId.slice(0,16),k=bs(n,C).slice(0,500),R=n.model?$t(n.model):null,I=l>0?Math.min(l,3)*14:0,_=a?10:12,B=r.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:x,onFocus:x,onMouseLeave:d,onBlur:d,className:M("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":a?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:_+I,...a?{borderLeft:`2px solid ${s?g.color:`${g.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[l>0&&e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-fg-5/60 shrink-0","aria-label":"Fork",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]}),e.jsx(nt,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),R&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:R}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5 shrink-0 transition-opacity group-hover:opacity-0 group-focus-within:opacity-0",children:[!!n.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5 text-fg-5/50 tabular-nums",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-50",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),n.numTurns]}),e.jsx("span",{className:"tabular-nums",children:Mn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Ft,{variant:j==="running"?"ok":j==="waiting"?"info":j==="incomplete"?"warn":"idle",pulse:j==="running"||j==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:C})]}),k&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:k})})]}),e.jsx("button",{ref:B,type:"button","aria-label":v,"aria-haspopup":"menu",onMouseDown:y=>{y.stopPropagation()},onClick:y=>{y.stopPropagation(),y.preventDefault(),B.current&&m(B.current.getBoundingClientRect())},className:"absolute top-1.5 right-1.5 p-1 rounded text-fg-5 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:bg-panel-h hover:text-fg-2 transition-opacity",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"5",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})})]})}),Fr=r.memo(function({workdir:n,onClose:s,t:a}){const l=Le(g=>g.state?.hostApp??null),c=Le(g=>g.state?.platform??null),x=Le(g=>g.toast),[d,m]=r.useState(()=>_r(l,c)),v=r.useCallback(async g=>{try{const j=await Z.openInEditor(g,d);if(!j.ok)throw new Error(j.error||`Failed to open ${g}`)}catch(j){x(j?.message||String(j),!1)}},[d,x]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:a("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:a("hub.closePanel"),children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"shrink-0 px-2.5 py-1.5 border-b border-edge/20 flex items-center gap-2",children:[e.jsx(vs,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:a(Qn(g))})),onChange:g=>{Rr(g)&&m(g)},renderIcon:g=>e.jsx(Yn,{target:g,size:14})}),e.jsx(Re,{size:"sm",variant:"ghost",onClick:()=>v(n),className:"flex-1 min-w-0 text-[11px]",children:a("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(Ur,{basePath:n,openTarget:d,onOpenPath:v,t:a})})]})});function Yn({target:t,size:n=16}){return t==="default"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 16 16",className:"shrink-0 text-fg-4",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 3H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-2"}),e.jsx("path",{d:"M9 2h5v5"}),e.jsx("path",{d:"M14 2L7 9"})]}):e.jsx(nt,{brand:t,size:n})}function Ur({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:a,t:l}){const[c,x]=r.useState([]),[d,m]=r.useState(!0);r.useEffect(()=>{let g=!1;return m(!0),Z.lsDir(t,!0,n).then(j=>{!g&&j.ok&&x(j.dirs.slice(0,50).map(C=>({entry:C,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||m(!1)}),()=>{g=!0}},[t,n]);const v=r.useCallback(g=>{const j=C=>C.map(k=>k.entry.path===g?k.expanded?{...k,expanded:!1}:k.children===null?(Z.lsDir(g,!0,n).then(R=>{R.ok&&x(I=>dn(I,g,{children:R.dirs.slice(0,50).map(_=>({entry:_,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(R=>dn(R,g,{children:[],loading:!1}))}),{...k,loading:!0,expanded:!0}):{...k,expanded:!0}:k.children?{...k,children:j(k.children)}:k);x(C=>j(C))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(Xn,{nodes:c,depth:0,onToggle:v,openTarget:s,onOpenPath:a,t:l})})}function Xn({nodes:t,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(zr,{node:x,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c},x.entry.path))})}function zr({node:t,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c}){const{entry:x,expanded:d,children:m,loading:v}=t,g=n*14,[j,C]=r.useState(!1),k=c(Qn(a)),R=c("hub.openWithTarget").replace("{target}",k);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),className:M("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",x.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+g,paddingRight:8},children:[x.isDir?v?e.jsx(pe,{className:"h-2 w-2 text-fg-5 shrink-0"}):e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:M("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),x.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:x.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:I=>{I.stopPropagation(),l(x.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:R,children:e.jsx(Yn,{target:a,subtle:!0})}),!x.isDir&&e.jsx(Kr,{filePath:x.path,t:c})]})]}),x.isDir&&d&&m&&m.length>0&&e.jsx(Xn,{nodes:m,depth:n+1,onToggle:s,openTarget:a,onOpenPath:l,t:c})]})}function Kr({filePath:t,t:n}){const[s,a]=r.useState(!1);return e.jsx("button",{onClick:l=>{l.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{a(!0),setTimeout(()=>a(!1),1500)}).catch(()=>{})},className:M("p-0.5 rounded transition-colors",s?"text-ok":"text-fg-5 hover:text-fg-3"),title:n("hub.copied"),children:s?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})}function dn(t,n,s){return t.map(a=>a.entry.path===n?{...a,...s}:a.children?{...a,children:dn(a.children,n,s)}:a)}const oo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Pr},Symbol.toStringTag,{value:"Module"}));export{Ks as I,so as L,tr as R,ro as T,Gn as U,eo as a,zn as b,ln as c,no as d,mr as e,oo as i,Es as l,to as m,Zr as n,Ts as p};
|