pikiloom 0.4.27 → 0.4.28

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.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-Cnv9o96n.js","assets/react-vendor-C7Sl8SE7.js","assets/index-BlqvzDUL.js","assets/router-DHISdpPk.js","assets/index-CXIN3nTr.css","assets/Modal-M1AP1sgR.js","assets/Select-YubDM16P.js","assets/DirBrowser-Dot7ua9-.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-GioMx4S6.js"])))=>i.map(i=>d[i]);
2
- import{c as M,a as ee,u as ye,i as yn,f as It,A as us,s as Dt,S as pe,B as rt,g as ln,w as hs,b as xs,E as en,C as xn,d as ps,r as Nn,e as Sn,h as fs,n as gs,j as ms,k as An,l as Bt,m as Ie,D as zt,o as bs,p as Rn,_ as _n,T as js,q as vs}from"./index-BlqvzDUL.js";import{j as e,r,a as pn}from"./react-vendor-C7Sl8SE7.js";import{I as ws}from"./Select-YubDM16P.js";import{M as Ft,a as Ut}from"./Modal-M1AP1sgR.js";import{D as ks}from"./DirBrowser-Dot7ua9-.js";import{n as ys,r as Ns,M as fn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Ss}from"./ExtensionsTab-GioMx4S6.js";function Cs({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 ot({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(Cs,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Ls=5e3,Ms=15e3,$t=8,Ot=30,Ts=1,st=new Map,ke=new Map,tn=new Set,Pn=[];let At=0;function nn(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 Wn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(ze(t,n,s,t===ke?Ot:$t),s.value)}function Bn(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:nn(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:nn(t.turnOffset)?t.turnOffset:void 0,turnLimit:nn(t.turnLimit)?t.turnLimit:void 0}}function gn(t){const n=Bn(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function $n(){for(;At<Ts;){const t=Pn.shift();if(!t)return;At+=1,t().finally(()=>{At=Math.max(0,At-1),$n()})}}async function Es(t,n={}){const s=t;if(!n.force){const c=Wn(st,s);if(c)return c}const a=st.get(s);if(a?.promise)return a.promise;const l=ee.getWorkspaceSessions(t,n.request).then(c=>(ze(st,s,{value:c,expiresAt:c.ok?Date.now()+Ls:0},$t),c)).finally(()=>{const c=st.get(s);c?.promise&&ze(st,s,{value:c.value,expiresAt:c.expiresAt},$t)});return ze(st,s,{value:a?.value,expiresAt:a?.expiresAt??0,promise:l},$t),l}function Is(t,n={}){const s=gn(t),a=ke.get(s);return a?.value?.ok&&(n.allowStale||a.expiresAt>Date.now())?a.value:null}async function As(t,n={}){const s=Bn(t),a=gn(s);if(!n.force){const x=Wn(ke,a);if(x?.ok)return x}const l=ke.get(a);if(l?.promise)return l.promise;const c=ee.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(ze(ke,a,{value:x,expiresAt:x.ok?Date.now()+Ms:0},Ot),x)).finally(()=>{const x=ke.get(a);x?.promise&&ze(ke,a,{value:x.value,expiresAt:x.expiresAt},Ot)});return ze(ke,a,{value:l?.value,expiresAt:l?.expiresAt??0,promise:c},Ot),c}function Rs(t){const n=gn(t);Is(t)||tn.has(n)||ke.get(n)?.promise||(tn.add(n),Pn.push(async()=>{try{await As(t)}catch{}finally{tn.delete(n)}}),$n())}function Cn(t){return(t||"").replace(/\s+/g," ").trim()}function to(t,n){return Cn(t)===Cn(n)}function no(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=Ps(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 so(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 ro(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 _s(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-DZVNXptx.js","assets/react-vendor-C7Sl8SE7.js","assets/index-CLGovkkw.js","assets/router-DHISdpPk.js","assets/index-CXIN3nTr.css","assets/Modal-D_PUi-5O.js","assets/Select-Cp5VXb_2.js","assets/DirBrowser-BINh_7NB.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-CHpd147b.js"])))=>i.map(i=>d[i]);
2
+ import{c as M,a as ee,u as ye,i as yn,f as It,A as us,s as Dt,S as pe,B as rt,g as ln,w as hs,b as xs,E as en,C as xn,d as ps,r as Nn,e as Sn,h as fs,n as gs,j as ms,k as An,l as Bt,m as Ie,D as zt,o as bs,p as Rn,_ as _n,T as js,q as vs}from"./index-CLGovkkw.js";import{j as e,r,a as pn}from"./react-vendor-C7Sl8SE7.js";import{I as ws}from"./Select-Cp5VXb_2.js";import{M as Ft,a as Ut}from"./Modal-D_PUi-5O.js";import{D as ks}from"./DirBrowser-BINh_7NB.js";import{n as ys,r as Ns,M as fn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Ss}from"./ExtensionsTab-CHpd147b.js";function Cs({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 ot({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(Cs,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Ls=5e3,Ms=15e3,$t=8,Ot=30,Ts=1,st=new Map,ke=new Map,tn=new Set,Pn=[];let At=0;function nn(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 Wn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(ze(t,n,s,t===ke?Ot:$t),s.value)}function Bn(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:nn(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:nn(t.turnOffset)?t.turnOffset:void 0,turnLimit:nn(t.turnLimit)?t.turnLimit:void 0}}function gn(t){const n=Bn(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function $n(){for(;At<Ts;){const t=Pn.shift();if(!t)return;At+=1,t().finally(()=>{At=Math.max(0,At-1),$n()})}}async function Es(t,n={}){const s=t;if(!n.force){const c=Wn(st,s);if(c)return c}const a=st.get(s);if(a?.promise)return a.promise;const l=ee.getWorkspaceSessions(t,n.request).then(c=>(ze(st,s,{value:c,expiresAt:c.ok?Date.now()+Ls:0},$t),c)).finally(()=>{const c=st.get(s);c?.promise&&ze(st,s,{value:c.value,expiresAt:c.expiresAt},$t)});return ze(st,s,{value:a?.value,expiresAt:a?.expiresAt??0,promise:l},$t),l}function Is(t,n={}){const s=gn(t),a=ke.get(s);return a?.value?.ok&&(n.allowStale||a.expiresAt>Date.now())?a.value:null}async function As(t,n={}){const s=Bn(t),a=gn(s);if(!n.force){const x=Wn(ke,a);if(x?.ok)return x}const l=ke.get(a);if(l?.promise)return l.promise;const c=ee.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(ze(ke,a,{value:x,expiresAt:x.ok?Date.now()+Ms:0},Ot),x)).finally(()=>{const x=ke.get(a);x?.promise&&ze(ke,a,{value:x.value,expiresAt:x.expiresAt},Ot)});return ze(ke,a,{value:l?.value,expiresAt:l?.expiresAt??0,promise:c},Ot),c}function Rs(t){const n=gn(t);Is(t)||tn.has(n)||ke.get(n)?.promise||(tn.add(n),Pn.push(async()=>{try{await As(t)}catch{}finally{tn.delete(n)}}),$n())}function Cn(t){return(t||"").replace(/\s+/g," ").trim()}function to(t,n){return Cn(t)===Cn(n)}function no(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=Ps(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 so(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 ro(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 _s(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
3
3
 
4
4
  `),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function Ps(t){const n=[];let s={user:null,assistant:null};for(const a of t)if(a.role==="user"){if(s.assistant&&On(a.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=a}else s.assistant?s.assistant=_s(s.assistant,a):s.assistant=a;return(s.user||s.assistant)&&n.push(s),n}const Ws=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"]),Bs=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function On(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Ws.has(s[1].toLowerCase())?!0:Bs.some(a=>t.includes(a))}function Dn(t,n){const s=t.split(`
5
5
  `).filter(a=>a.trim());return s.length<=n?s.join(`
@@ -19,5 +19,5 @@ import{c as M,a as ee,u as ye,i as yn,f as It,A as us,s as Dt,S as pe,B as rt,g
19
19
  `),[d,m]=r.useState(null),j=r.useMemo(()=>Kt({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(fn,{remarkPlugins:mn,components:j,children:x})}),l.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:l.map((g,w)=>e.jsx(pr,{block:g,onLightbox:m,t:n},w))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((g,w)=>e.jsx(Gn,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},w))}),d&&e.jsx(Xn,{src:d,onClose:()=>m(null)})]})}const lo=r.memo(function({turn:n,turnIndex:s,agent:a,meta:l,model:c,effort:x,providerName:d,t:m,workdir:j,onResend:g,onEdit:w,onFork:L}){const N=n.user&&On(n.user.text),I=L&&typeof s=="number"?()=>L(s):void 0,T=r.useMemo(()=>Kt({workdir:j}),[j]),A=!!n.assistant&&ar(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!N&&e.jsx(Jn,{text:n.user.text,blocks:n.user.blocks,t:m,onResend:g,onEdit:w,onFork:I}),N&&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(fn,{remarkPlugins:mn,components:T,children:n.user.text})}),A&&e.jsxs(e.Fragment,{children:[e.jsx(jr,{agent:a,meta:l,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(lr,{message:n.assistant,t:m,workdir:j})})]})]})});function Xn({src:t,onClose:n}){return r.useEffect(()=>{const s=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),pn.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 gr=1500,mr=16,Mn=8;function br(t){const n=t.split(`
20
20
  `);return n.length<=Mn?t:n.slice(0,Mn).join(`
21
21
  `)}function Jn({text:t,blocks:n,t:s,onResend:a,onEdit:l,onFork:c}){const[x,d]=r.useState(!1),[m,j]=r.useState(!1),[g,w]=r.useState(null),L=t?t.split(`
22
- `).length:0,N=!!t&&(t.length>gr||L>mr),[I,T]=r.useState(!1),A=t?N&&!I?br(t):t:"",W=!!(a||l||c),S=n?.filter(E=>E.type==="image")||[],B=()=>{navigator.clipboard.writeText(t).then(()=>{j(!0),setTimeout(()=>j(!1),1500)}).catch(()=>{})},te=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(L));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:[A,N&&!I&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),N&&e.jsx("button",{type:"button",onClick:()=>T(E=>!E),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:I?s("hub.collapse"):te}),S.length>0&&e.jsx("div",{className:M("flex flex-wrap gap-2",t&&"mt-2"),children:S.map((E,G)=>e.jsx("img",{src:E.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:()=>w(E.content)},G))})]}),g&&e.jsx(Xn,{src:g,onClose:()=>w(null)}),W&&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(Rt,{label:s(m?"hub.copied":"hub.copy"),onClick:B,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(Rt,{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(Rt,{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(Rt,{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 Rt({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 jr({agent:t,meta:n,model:s,effort:a,providerName:l,previewMeta:c,liveStartedAt:x}){const d=c?.contextPercent??null,m=c?.contextUsedTokens??0,j=c?.turnOutputTokens??0,g=d!=null||m>0||j>0,w=x!=null&&x>0,L=c?.providerName??l??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(rt,{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||""]}),L&&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 ${L} (BYOK), not the agent CLI's native auth.`,children:["via ",L]}),(g||w)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:yr(c),children:[d!=null&&e.jsx(Nr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",kr(m)]}),j>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Zn(j)]}),w&&e.jsx(vr,{startedAt:x,leadingDot:g})]})]})}function vr({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?"· ":"",wr(a)]})}function wr(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 kr(t){return`${Zn(t)} tok`}function Zn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function yr(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 Nr({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 Tn(t,n,s){return t==="zh-CN"?n:s}function Sr({open:t,onClose:n,workdir:s}){const a=ye(c=>c.locale),l=s.split("/").pop()||s;return e.jsxs(Ft,{open:t,onClose:n,wide:!0,children:[e.jsx(Ut,{title:Tn(a,`${l} — 项目扩展`,`${l} — Project Extensions`),description:Tn(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(Ss,{workdir:s}):null]})}let En=_n(()=>import("./SessionPanel-Cnv9o96n.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function dn(){return En??=_n(()=>import("./SessionPanel-Cnv9o96n.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),En}const Cr=r.lazy(async()=>({default:(await dn()).SessionPanel})),on=5,Lr=240,Mr=120,Tr=12,Er=900*1e3,V=(t,n)=>`${t}:${n}`;function Ir(t){const n=new Map;for(const d of t)n.set(V(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 j=V(m.agent||d.agent||"",m.sessionId);n.has(j)&&(a.add(V(d.agent||"",d.sessionId)),s.has(j)||s.set(j,[]),s.get(j).push(d))}const l=[],c=new Set,x=(d,m)=>{const j=V(d.agent||"",d.sessionId);if(c.has(j))return;c.add(j),l.push(Object.assign({},d,{__forkDepth:m}));const g=s.get(j);if(g)for(const w of g)x(w,m+1)};for(const d of t){const m=V(d.agent||"",d.sessionId);a.has(m)||x(d,0)}for(const d of t)x(d,0);return l}let Ar=0;function _t(){return`mk-${Date.now().toString(36)}-${(++Ar).toString(36)}`}function Pt(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 Wt(t,n){try{localStorage.setItem(t,n)}catch{}}const Rr=[1,2,3,6],un=6;function _r(t){for(const n of Rr)if(n>=t)return n;return un}function In(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function Ue(t,n){const s=_r(t);return s>n?s:n}function Pr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Wr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function es(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 Br=r.memo(function({active:n=!0}){const s=ye(o=>o.locale),a=ye(o=>o.state?.runtimeWorkdir??null),l=r.useMemo(()=>ps(s),[s]),[c,x]=r.useState([]),[d,m]=r.useState({}),[j,g]=r.useState({}),[w,L]=r.useState(!0),[N,I]=r.useState(()=>{const o=Pt("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):In()}),[T,A]=r.useState(()=>{const o=Pt("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):In()}),[W,S]=r.useState(()=>{try{const o=Pt("pikiloom-open-sessions");if(o){const h=JSON.parse(o);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||_t()}))}}catch{}return[]}),[B,te]=r.useState(()=>{const o=Pt("pikiloom-active-slot");if(o!=null){const h=Number(o);if(Number.isFinite(h)&&h>=0)return h}return 0}),E=r.useCallback(o=>{I(o),Wt("pikiloom-layout-mode",String(o))},[]),G=r.useCallback(o=>{A(o),Wt("pikiloom-layout-floor",String(o))},[]),P=r.useCallback(o=>{S(h=>{const u=typeof o=="function"?o(h):o,p=u.map(({pendingPrompt:v,pendingImageUrls:y,...k})=>k);return Wt("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),D=r.useCallback(o=>{te(h=>{const u=typeof o=="function"?o(h):o;return Wt("pikiloom-active-slot",String(u)),u})},[]),ae=r.useCallback(o=>{E(o),G(o)},[E,G]);r.useEffect(()=>{P(o=>o.length>N?o.slice(0,N):o),D(o=>o>=N?N-1:o)},[N]);const[R,ce]=r.useState(!1),re=r.useRef(N);re.current=N;const Y=r.useRef(T);Y.current=T;const Ne=r.useRef(B);Ne.current=B;const K=r.useRef(W);K.current=W;const wt=r.useRef(-1),fe=W[B]??null,lt=r.useCallback(o=>{if(!o){P([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:_t()};P(u=>{const p=u.findIndex(y=>y.agent===h.agent&&y.sessionId===h.sessionId);if(p>=0)return D(p),u;if(u.length<re.current){const y=[...u,h];return D(y.length-1),y}if(re.current<un){const y=[...u,h];return E(Ue(y.length,Y.current)),D(y.length-1),y}const v=[...u];return v[Ne.current]=h,v})},[P,D,E]),[Ke,He]=r.useState(!1),[oe,Ae]=r.useState(null),[ne,Se]=r.useState(""),[Re,Ve]=r.useState("all"),[de,kt]=r.useState({}),[ue,Ge]=r.useState({}),_e=r.useDeferredValue(ne),se=r.useRef(!1),qe=r.useRef({}),Ce=r.useRef(d);Ce.current=d;const Le=r.useRef(de);Le.current=de;const at=r.useRef(new Set),$=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values($.current))clearTimeout(o)},[]),r.useEffect(()=>{P(o=>{let h=!1;const u=o.map(p=>{const v=ue[p.workdir];if(!v)return p;const y=Nn(v,p.agent,p.sessionId);return y===p.sessionId?p:(h=!0,{...p,sessionId:y})});return h?u:o})},[ue,P]);const q=r.useCallback(async()=>{try{const o=await ee.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((p,v)=>p.path===h[v].path&&p.name===h[v].name)?u:h),se.current=!0}catch{se.current=!0}finally{L(!1)}},[]);r.useEffect(()=>{q()},[q]);const U=r.useCallback(async(o,h={})=>{if(!qe.current[o]){qe.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Es(o,{force:h.force});r.startTransition(()=>{Ge(p=>{const v=u.promotions||{},y=p[o];return y&&Object.keys(y).length===Object.keys(v).length&&Object.entries(v).every(([k,H])=>y[k]===H)?p:{...p,[o]:v}}),m(p=>{const v=u.sessions||[],y=p[o]||[],k=new Set(v.map(F=>V(F.agent||"",F.sessionId))),H=y.filter(F=>{if(F.runState!=="running")return!1;const _=V(F.agent||"",F.sessionId);if(k.has(_))return!1;const O=Le.current[_];return!(O?.resolvedKey&&O.resolvedKey!==_)});return{...p,[o]:H.length?[...H,...v]:v}})})}catch{h.background||r.startTransition(()=>{m(u=>({...u,[o]:[]}))})}finally{qe.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),ct=r.useRef(a);r.useEffect(()=>{a!==ct.current&&(ct.current=a,!(!a||!se.current)&&q().then(()=>{U(a,{force:!0})}))},[a,q,U]);const Q=r.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(dn(),Rs({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Tr}))},[]),Qe=r.useCallback((o,h,u=Mr)=>{const p=`${h}:${V(o.agent||"",o.sessionId)}`,v=$.current[p];v&&clearTimeout(v),$.current[p]=setTimeout(()=>{delete $.current[p],Q(o,h)},u)},[Q]),yt=r.useCallback((o,h)=>{const u=`${h}:${V(o.agent||"",o.sessionId)}`,p=$.current[u];p&&(clearTimeout(p),delete $.current[u])},[]);r.useEffect(()=>{n&&dn()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||j[h.path])return;const p=setTimeout(()=>{U(h.path)},u*90);o.push(p)}),()=>{for(const h of o)clearTimeout(h)}},[n,U,j,d,c]);const Ht=r.useRef(new Map);Sn(n&&se.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(y=>(Ce.current[y.path]||[]).some(k=>V(k.agent||"",k.sessionId)===h)):c,p=u.length?u:c,v=Ht.current;for(const y of p)v.has(y.path)&&clearTimeout(v.get(y.path)),v.set(y.path,setTimeout(()=>{v.delete(y.path),U(y.path,{background:!0,force:!0})},300))},[c,U]));const ge=r.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:fs(o,de[V(h,o.sessionId)]||null)},[de]);Sn("stream-update",r.useCallback(o=>{const h=o.key;if(!h)return;const u=gs(h,o.snapshot??null);kt(p=>{if(!u){const _=p[h];return!_||_.phase==="done"?p:{...p,[h]:{..._,phase:"done",updatedAt:Date.now()}}}const v=(_,O)=>!!_&&!!O&&_.phase===O.phase&&_.resolvedKey===O.resolvedKey&&_.sessionId===O.sessionId&&_.incomplete===O.incomplete&&_.error===O.error,y=v(p[h],u),k=u.resolvedKey===h||v(p[u.resolvedKey],{...u,key:u.resolvedKey});if(y&&k)return p;const H=Date.now()-Er,F={};for(const[_,O]of Object.entries(p))O.phase==="done"&&O.updatedAt<H||(F[_]=O);return F[h]=u,u.resolvedKey!==h&&(F[u.resolvedKey]={...u,key:u.resolvedKey}),F})},[])),ms(r.useCallback(()=>{if(!(!n||!se.current||c.length===0))for(const o of c)U(o.path,{background:!0,force:!0})},[n,c,U])),r.useEffect(()=>{if(!n||!se.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)U(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,U,c]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const v=`${h.path}:${V(p.agent||"",p.sessionId)}`;if(at.current.has(v))return;const y=setTimeout(()=>{at.current.add(v),Q(p,h.path)},Lr+u*120);o.push(y)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,Q,c]);const dt=r.useCallback(async o=>{try{(await ee.addWorkspace(o)).ok&&(He(!1),await q(),U(o))}catch{}},[q,U]),[me,Pe]=r.useState(null),[X,We]=r.useState(!1),[Be,$e]=r.useState(null),Ye=r.useCallback(o=>{Pe(o)},[]),ut=r.useCallback(async()=>{const o=me;if(o){We(!0);try{await ee.removeWorkspace(o),x(h=>h.filter(u=>u.path!==o)),m(h=>{const u={...h};return delete u[o],u}),P(h=>{const u=h.filter(p=>p.workdir!==o);return u.length!==h.length&&E(Ue(u.length,Y.current)),u}),D(0),Pe(null)}catch{}finally{We(!1)}}},[me]),ht=r.useCallback(o=>{U(o,{force:!0})},[U]),[Me,be]=r.useState(null),[Xe,Je]=r.useState(!1),[je,Te]=r.useState(!1),ve=ye(o=>o.toast),[ie,Ze]=r.useState(null),xt=r.useCallback((o,h,u)=>{Ze({anchor:{right:o.right,bottom:o.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:An(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!ie)return;const o=()=>Ze(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)}},[ie]);const we=r.useCallback(o=>{Je(!1),be(o),Ze(null)},[]),Nt=r.useCallback(async()=>{const o=Me;if(o){Te(!0);try{const h=await ee.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");ve(u,!1);return}m(u=>{const p=u[o.workdir];if(!p)return u;const v=p.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return v.length===p.length?u:{...u,[o.workdir]:v}}),P(u=>{const p=u.filter(v=>!(v.workdir===o.workdir&&v.agent===o.agent&&v.sessionId===o.sessionId));return p.length!==u.length&&E(Ue(p.length,Y.current)),p}),be(null)}catch(h){ve(h?.message||l("session.deleteFailed"),!1)}finally{Te(!1)}}},[Me,Xe,l,ve]),pt=r.useCallback(o=>{P(h=>{let u=!1;const p=h.map(v=>v.mountKey===o&&(v.pendingPrompt!=null||v.pendingImageUrls)?(u=!0,{...v,pendingPrompt:null,pendingImageUrls:void 0}):v);return u?p:h})},[P]),St=r.useCallback((o,h,u)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),m(y=>{const k=y[o.workdir]||[];if(k.some(_=>_.sessionId===o.sessionId&&_.agent===o.agent))return y;const F={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[F,...k]}});const p=wt.current,v={...o,mountKey:_t(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};r.startTransition(()=>{Ae(null),P(y=>{if(p>=y.length)return[...y,v];const k=[...y];return k[p]=v,k}),D(p>=0?p:0)}),U(o.workdir,{background:!0,force:!0})},[U,Q,P,D]),Ct=r.useCallback(o=>{K.current.length>=re.current&&re.current<un&&E(Ue(re.current+1,Y.current)),Ae(o)},[E]),Lt=r.useCallback(()=>{Ae(null),E(Ue(K.current.length,Y.current))},[E]),Mt=r.useCallback((o,h)=>{Q(o,h);const u=o.agent||"";K.current.some(p=>p.agent===u&&p.sessionId===o.sessionId)&&E(Ue(K.current.length,Y.current)),Ae(null),r.startTransition(()=>{lt({agent:u,sessionId:o.sessionId,workdir:h})})},[Q,E]),he=r.useCallback((o,h)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{h!=null?(P(u=>{if(h>=u.length)return u;const p=[...u];return p[h]={...u[h],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},p}),D(h)):lt({...o,mountKey:_t()})}),U(o.workdir,{background:!0,force:!0})},[U,Q]),ft=r.useCallback(o=>{let h=o;if(Re==="running"?h=h.filter(u=>Bt(u)==="running"):Re==="review"&&(h=h.filter(u=>Bt(u)==="incomplete")),_e.trim()){const u=_e.toLowerCase();h=h.filter(p=>(p.lastMessageText||"").toLowerCase().includes(u)||(p.lastQuestion||"").toLowerCase().includes(u)||(p.lastAnswer||"").toLowerCase().includes(u)||(p.title||"").toLowerCase().includes(u)||(p.agent||"").toLowerCase().includes(u))}return h},[_e,Re]),gt=r.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(ge),p=ue[h.path],v=new Map;for(const k of u){const H=V(k.agent||"",k.sessionId),F=de[H],_=p?Nn(p,k.agent||"",k.sessionId):k.sessionId,O=F?.resolvedKey&&F.resolvedKey!==H?F.resolvedKey:_!==k.sessionId?V(k.agent||"",_):H,mt=v.get(O);if(!mt){v.set(O,k);continue}V(mt.agent||"",mt.sessionId)!==O&&H===O&&v.set(O,k)}const y=ft([...v.values()]);o[h.path]=Ir(y)}return o},[c,d,de,ue,ft,ge]),Vt=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 ge(h)},[ge,d]),Gt=r.useMemo(()=>new Set(W.map(o=>V(o.agent,o.sessionId))),[W]),et=fe?V(fe.agent,fe.sessionId):null,Tt=r.useCallback(o=>{P(h=>{const u=h.filter((p,v)=>v!==o);return u.length===0?D(0):Ne.current>=u.length&&D(u.length-1),E(Ue(u.length,Y.current)),u})},[P,D,E]);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:ne,onChange:o=>Se(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"}),ne&&e.jsx("button",{onClick:()=>Se(""),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",Re===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:w?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(Fr,{workspace:o,sessions:gt[o.path]||[],loading:!!j[o.path]||!(o.path in d),isActive:o.path===a,selectedKey:et,openSessionKeys:Gt,onSelectSession:Mt,onNewSession:Ct,onRefresh:ht,onRemove:Ye,onExtensions:$e,onWarmSession:Qe,onCancelWarmSession:yt,onSessionMenuOpen:xt,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:()=>ae(o),className:M("flex-1 flex items-center justify-center p-1.5 rounded transition-all",N===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(Ie,{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(${N===6?3:N}, 1fr)`,gridTemplateRows:N===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=oe?W.length<N?W.length:B:-1;return wt.current=o,Array.from({length:N},(h,u)=>{if(oe&&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(Or,{workdir:oe,workspaceName:c.find(k=>k.path===oe)?.name||oe.split("/").pop()||"",onSessionCreated:St,onClose:Lt,t:l},oe)},`new-${oe}`);const p=W[u]??null;if(!p)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 v=Vt(p),y=u===B;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",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"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",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const k=Bt(v);return e.jsx(zt,{variant:k==="running"?"ok":k==="waiting"?"info":k==="incomplete"?"warn":"idle",pulse:k==="running"||k==="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:p.workdir.split("/").pop()||p.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:v.title||v.lastQuestion?.slice(0,60)||p.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:bs(v.createdAt)}),v.runUpdatedAt&&e.jsx("span",{title:l("hub.updated"),children:Rn(v.runUpdatedAt)}),!!v.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"})}),v.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:k=>{k.stopPropagation(),ce(H=>!H)},className:M("p-0.5 rounded transition-colors",R?"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:k=>{k.stopPropagation(),Tt(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(Cr,{session:v,workdir:p.workdir,active:n&&y,onSessionChange:k=>he(k,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>pt(p.mountKey)},p.mountKey)})})]},p.mountKey||V(p.agent,p.sessionId))})})()})}),R&&fe&&e.jsx(zr,{workdir:fe.workdir,onClose:()=>ce(!1),t:l}),e.jsx($r,{open:Ke,initialPath:a||void 0,onAdd:dt,onClose:()=>He(!1),t:l}),e.jsxs(Ft,{open:!!me,onClose:()=>!X&&Pe(null),children:[e.jsx(Ut,{title:l("hub.removeWorkspace"),onClose:()=>!X&&Pe(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")}),me&&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:me}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ie,{variant:"ghost",onClick:()=>Pe(null),disabled:X,children:l("modal.cancel")}),e.jsx(Ie,{variant:"primary",onClick:ut,disabled:X,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(X?"modal.removing":"modal.remove")})]})]}),ie&&(()=>{const h=Math.max(8,Math.min(ie.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ie.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:p=>p.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>we(ie.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(Ft,{open:!!Me,onClose:()=>!je&&be(null),children:[e.jsx(Ut,{title:l("session.deleteTitle"),onClose:()=>!je&&be(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("session.deleteHint")}),Me&&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:Me.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Me.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:()=>Je(!1),disabled:je,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:()=>Je(!0),disabled:je,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(Ie,{variant:"ghost",onClick:()=>be(null),disabled:je,children:l("modal.cancel")}),e.jsx(Ie,{variant:"primary",onClick:Nt,disabled:je,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(je?"session.deleting":"modal.remove")})]})]}),e.jsx(Sr,{open:!!Be,onClose:()=>$e(null),workdir:Be||""})]})});function $r({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(Ft,{open:t,onClose:a,children:[e.jsx(Ut,{title:l("hub.addWorkspace"),onClose:a}),e.jsx(ks,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:l}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ie,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:l("hub.add")}),e.jsx(Ie,{variant:"secondary",onClick:a,className:"flex-1",children:l("hub.cancel")})]})]})}function Or({workdir:t,workspaceName:n,onSessionCreated:s,onClose:a,t:l}){const[c,x]=r.useState(null),[d,m]=r.useState([]),j=r.useRef(null),g=r.useRef([]),w=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),L=r.useCallback(()=>{},[]),N=r.useCallback((A,W)=>{x(A||null),j.current=A||null;const S=W||[];m(S),g.current=S},[]),I=r.useCallback(A=>{const W=g.current;g.current=[],s(A,j.current||void 0,W.length?W:void 0)},[s]),T=!!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(zt,{variant:T?"ok":"idle",pulse:T}),!T&&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:T?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(Jn,{text:c||"",blocks:d.map(A=>({type:"image",content:A})),t:l}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(cn,{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(Vs,{session:w,workdir:t,onStreamQueued:L,onSendStart:N,onSessionChange:I,t:l,streamPhase:null})]})}function Dr({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(`
22
+ `).length:0,N=!!t&&(t.length>gr||L>mr),[I,T]=r.useState(!1),A=t?N&&!I?br(t):t:"",W=!!(a||l||c),S=n?.filter(E=>E.type==="image")||[],B=()=>{navigator.clipboard.writeText(t).then(()=>{j(!0),setTimeout(()=>j(!1),1500)}).catch(()=>{})},te=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(L));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:[A,N&&!I&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),N&&e.jsx("button",{type:"button",onClick:()=>T(E=>!E),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:I?s("hub.collapse"):te}),S.length>0&&e.jsx("div",{className:M("flex flex-wrap gap-2",t&&"mt-2"),children:S.map((E,G)=>e.jsx("img",{src:E.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:()=>w(E.content)},G))})]}),g&&e.jsx(Xn,{src:g,onClose:()=>w(null)}),W&&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(Rt,{label:s(m?"hub.copied":"hub.copy"),onClick:B,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(Rt,{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(Rt,{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(Rt,{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 Rt({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 jr({agent:t,meta:n,model:s,effort:a,providerName:l,previewMeta:c,liveStartedAt:x}){const d=c?.contextPercent??null,m=c?.contextUsedTokens??0,j=c?.turnOutputTokens??0,g=d!=null||m>0||j>0,w=x!=null&&x>0,L=c?.providerName??l??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(rt,{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||""]}),L&&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 ${L} (BYOK), not the agent CLI's native auth.`,children:["via ",L]}),(g||w)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:yr(c),children:[d!=null&&e.jsx(Nr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",kr(m)]}),j>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Zn(j)]}),w&&e.jsx(vr,{startedAt:x,leadingDot:g})]})]})}function vr({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?"· ":"",wr(a)]})}function wr(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 kr(t){return`${Zn(t)} tok`}function Zn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function yr(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 Nr({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 Tn(t,n,s){return t==="zh-CN"?n:s}function Sr({open:t,onClose:n,workdir:s}){const a=ye(c=>c.locale),l=s.split("/").pop()||s;return e.jsxs(Ft,{open:t,onClose:n,wide:!0,children:[e.jsx(Ut,{title:Tn(a,`${l} — 项目扩展`,`${l} — Project Extensions`),description:Tn(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(Ss,{workdir:s}):null]})}let En=_n(()=>import("./SessionPanel-DZVNXptx.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function dn(){return En??=_n(()=>import("./SessionPanel-DZVNXptx.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),En}const Cr=r.lazy(async()=>({default:(await dn()).SessionPanel})),on=5,Lr=240,Mr=120,Tr=12,Er=900*1e3,V=(t,n)=>`${t}:${n}`;function Ir(t){const n=new Map;for(const d of t)n.set(V(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 j=V(m.agent||d.agent||"",m.sessionId);n.has(j)&&(a.add(V(d.agent||"",d.sessionId)),s.has(j)||s.set(j,[]),s.get(j).push(d))}const l=[],c=new Set,x=(d,m)=>{const j=V(d.agent||"",d.sessionId);if(c.has(j))return;c.add(j),l.push(Object.assign({},d,{__forkDepth:m}));const g=s.get(j);if(g)for(const w of g)x(w,m+1)};for(const d of t){const m=V(d.agent||"",d.sessionId);a.has(m)||x(d,0)}for(const d of t)x(d,0);return l}let Ar=0;function _t(){return`mk-${Date.now().toString(36)}-${(++Ar).toString(36)}`}function Pt(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 Wt(t,n){try{localStorage.setItem(t,n)}catch{}}const Rr=[1,2,3,6],un=6;function _r(t){for(const n of Rr)if(n>=t)return n;return un}function In(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function Ue(t,n){const s=_r(t);return s>n?s:n}function Pr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Wr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function es(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 Br=r.memo(function({active:n=!0}){const s=ye(o=>o.locale),a=ye(o=>o.state?.runtimeWorkdir??null),l=r.useMemo(()=>ps(s),[s]),[c,x]=r.useState([]),[d,m]=r.useState({}),[j,g]=r.useState({}),[w,L]=r.useState(!0),[N,I]=r.useState(()=>{const o=Pt("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):In()}),[T,A]=r.useState(()=>{const o=Pt("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):In()}),[W,S]=r.useState(()=>{try{const o=Pt("pikiloom-open-sessions");if(o){const h=JSON.parse(o);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||_t()}))}}catch{}return[]}),[B,te]=r.useState(()=>{const o=Pt("pikiloom-active-slot");if(o!=null){const h=Number(o);if(Number.isFinite(h)&&h>=0)return h}return 0}),E=r.useCallback(o=>{I(o),Wt("pikiloom-layout-mode",String(o))},[]),G=r.useCallback(o=>{A(o),Wt("pikiloom-layout-floor",String(o))},[]),P=r.useCallback(o=>{S(h=>{const u=typeof o=="function"?o(h):o,p=u.map(({pendingPrompt:v,pendingImageUrls:y,...k})=>k);return Wt("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),D=r.useCallback(o=>{te(h=>{const u=typeof o=="function"?o(h):o;return Wt("pikiloom-active-slot",String(u)),u})},[]),ae=r.useCallback(o=>{E(o),G(o)},[E,G]);r.useEffect(()=>{P(o=>o.length>N?o.slice(0,N):o),D(o=>o>=N?N-1:o)},[N]);const[R,ce]=r.useState(!1),re=r.useRef(N);re.current=N;const Y=r.useRef(T);Y.current=T;const Ne=r.useRef(B);Ne.current=B;const K=r.useRef(W);K.current=W;const wt=r.useRef(-1),fe=W[B]??null,lt=r.useCallback(o=>{if(!o){P([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:_t()};P(u=>{const p=u.findIndex(y=>y.agent===h.agent&&y.sessionId===h.sessionId);if(p>=0)return D(p),u;if(u.length<re.current){const y=[...u,h];return D(y.length-1),y}if(re.current<un){const y=[...u,h];return E(Ue(y.length,Y.current)),D(y.length-1),y}const v=[...u];return v[Ne.current]=h,v})},[P,D,E]),[Ke,He]=r.useState(!1),[oe,Ae]=r.useState(null),[ne,Se]=r.useState(""),[Re,Ve]=r.useState("all"),[de,kt]=r.useState({}),[ue,Ge]=r.useState({}),_e=r.useDeferredValue(ne),se=r.useRef(!1),qe=r.useRef({}),Ce=r.useRef(d);Ce.current=d;const Le=r.useRef(de);Le.current=de;const at=r.useRef(new Set),$=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values($.current))clearTimeout(o)},[]),r.useEffect(()=>{P(o=>{let h=!1;const u=o.map(p=>{const v=ue[p.workdir];if(!v)return p;const y=Nn(v,p.agent,p.sessionId);return y===p.sessionId?p:(h=!0,{...p,sessionId:y})});return h?u:o})},[ue,P]);const q=r.useCallback(async()=>{try{const o=await ee.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((p,v)=>p.path===h[v].path&&p.name===h[v].name)?u:h),se.current=!0}catch{se.current=!0}finally{L(!1)}},[]);r.useEffect(()=>{q()},[q]);const U=r.useCallback(async(o,h={})=>{if(!qe.current[o]){qe.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Es(o,{force:h.force});r.startTransition(()=>{Ge(p=>{const v=u.promotions||{},y=p[o];return y&&Object.keys(y).length===Object.keys(v).length&&Object.entries(v).every(([k,H])=>y[k]===H)?p:{...p,[o]:v}}),m(p=>{const v=u.sessions||[],y=p[o]||[],k=new Set(v.map(F=>V(F.agent||"",F.sessionId))),H=y.filter(F=>{if(F.runState!=="running")return!1;const _=V(F.agent||"",F.sessionId);if(k.has(_))return!1;const O=Le.current[_];return!(O?.resolvedKey&&O.resolvedKey!==_)});return{...p,[o]:H.length?[...H,...v]:v}})})}catch{h.background||r.startTransition(()=>{m(u=>({...u,[o]:[]}))})}finally{qe.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),ct=r.useRef(a);r.useEffect(()=>{a!==ct.current&&(ct.current=a,!(!a||!se.current)&&q().then(()=>{U(a,{force:!0})}))},[a,q,U]);const Q=r.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(dn(),Rs({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Tr}))},[]),Qe=r.useCallback((o,h,u=Mr)=>{const p=`${h}:${V(o.agent||"",o.sessionId)}`,v=$.current[p];v&&clearTimeout(v),$.current[p]=setTimeout(()=>{delete $.current[p],Q(o,h)},u)},[Q]),yt=r.useCallback((o,h)=>{const u=`${h}:${V(o.agent||"",o.sessionId)}`,p=$.current[u];p&&(clearTimeout(p),delete $.current[u])},[]);r.useEffect(()=>{n&&dn()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||j[h.path])return;const p=setTimeout(()=>{U(h.path)},u*90);o.push(p)}),()=>{for(const h of o)clearTimeout(h)}},[n,U,j,d,c]);const Ht=r.useRef(new Map);Sn(n&&se.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(y=>(Ce.current[y.path]||[]).some(k=>V(k.agent||"",k.sessionId)===h)):c,p=u.length?u:c,v=Ht.current;for(const y of p)v.has(y.path)&&clearTimeout(v.get(y.path)),v.set(y.path,setTimeout(()=>{v.delete(y.path),U(y.path,{background:!0,force:!0})},300))},[c,U]));const ge=r.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:fs(o,de[V(h,o.sessionId)]||null)},[de]);Sn("stream-update",r.useCallback(o=>{const h=o.key;if(!h)return;const u=gs(h,o.snapshot??null);kt(p=>{if(!u){const _=p[h];return!_||_.phase==="done"?p:{...p,[h]:{..._,phase:"done",updatedAt:Date.now()}}}const v=(_,O)=>!!_&&!!O&&_.phase===O.phase&&_.resolvedKey===O.resolvedKey&&_.sessionId===O.sessionId&&_.incomplete===O.incomplete&&_.error===O.error,y=v(p[h],u),k=u.resolvedKey===h||v(p[u.resolvedKey],{...u,key:u.resolvedKey});if(y&&k)return p;const H=Date.now()-Er,F={};for(const[_,O]of Object.entries(p))O.phase==="done"&&O.updatedAt<H||(F[_]=O);return F[h]=u,u.resolvedKey!==h&&(F[u.resolvedKey]={...u,key:u.resolvedKey}),F})},[])),ms(r.useCallback(()=>{if(!(!n||!se.current||c.length===0))for(const o of c)U(o.path,{background:!0,force:!0})},[n,c,U])),r.useEffect(()=>{if(!n||!se.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)U(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,U,c]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const v=`${h.path}:${V(p.agent||"",p.sessionId)}`;if(at.current.has(v))return;const y=setTimeout(()=>{at.current.add(v),Q(p,h.path)},Lr+u*120);o.push(y)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,Q,c]);const dt=r.useCallback(async o=>{try{(await ee.addWorkspace(o)).ok&&(He(!1),await q(),U(o))}catch{}},[q,U]),[me,Pe]=r.useState(null),[X,We]=r.useState(!1),[Be,$e]=r.useState(null),Ye=r.useCallback(o=>{Pe(o)},[]),ut=r.useCallback(async()=>{const o=me;if(o){We(!0);try{await ee.removeWorkspace(o),x(h=>h.filter(u=>u.path!==o)),m(h=>{const u={...h};return delete u[o],u}),P(h=>{const u=h.filter(p=>p.workdir!==o);return u.length!==h.length&&E(Ue(u.length,Y.current)),u}),D(0),Pe(null)}catch{}finally{We(!1)}}},[me]),ht=r.useCallback(o=>{U(o,{force:!0})},[U]),[Me,be]=r.useState(null),[Xe,Je]=r.useState(!1),[je,Te]=r.useState(!1),ve=ye(o=>o.toast),[ie,Ze]=r.useState(null),xt=r.useCallback((o,h,u)=>{Ze({anchor:{right:o.right,bottom:o.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:An(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!ie)return;const o=()=>Ze(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)}},[ie]);const we=r.useCallback(o=>{Je(!1),be(o),Ze(null)},[]),Nt=r.useCallback(async()=>{const o=Me;if(o){Te(!0);try{const h=await ee.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");ve(u,!1);return}m(u=>{const p=u[o.workdir];if(!p)return u;const v=p.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return v.length===p.length?u:{...u,[o.workdir]:v}}),P(u=>{const p=u.filter(v=>!(v.workdir===o.workdir&&v.agent===o.agent&&v.sessionId===o.sessionId));return p.length!==u.length&&E(Ue(p.length,Y.current)),p}),be(null)}catch(h){ve(h?.message||l("session.deleteFailed"),!1)}finally{Te(!1)}}},[Me,Xe,l,ve]),pt=r.useCallback(o=>{P(h=>{let u=!1;const p=h.map(v=>v.mountKey===o&&(v.pendingPrompt!=null||v.pendingImageUrls)?(u=!0,{...v,pendingPrompt:null,pendingImageUrls:void 0}):v);return u?p:h})},[P]),St=r.useCallback((o,h,u)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),m(y=>{const k=y[o.workdir]||[];if(k.some(_=>_.sessionId===o.sessionId&&_.agent===o.agent))return y;const F={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[F,...k]}});const p=wt.current,v={...o,mountKey:_t(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};r.startTransition(()=>{Ae(null),P(y=>{if(p>=y.length)return[...y,v];const k=[...y];return k[p]=v,k}),D(p>=0?p:0)}),U(o.workdir,{background:!0,force:!0})},[U,Q,P,D]),Ct=r.useCallback(o=>{K.current.length>=re.current&&re.current<un&&E(Ue(re.current+1,Y.current)),Ae(o)},[E]),Lt=r.useCallback(()=>{Ae(null),E(Ue(K.current.length,Y.current))},[E]),Mt=r.useCallback((o,h)=>{Q(o,h);const u=o.agent||"";K.current.some(p=>p.agent===u&&p.sessionId===o.sessionId)&&E(Ue(K.current.length,Y.current)),Ae(null),r.startTransition(()=>{lt({agent:u,sessionId:o.sessionId,workdir:h})})},[Q,E]),he=r.useCallback((o,h)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{h!=null?(P(u=>{if(h>=u.length)return u;const p=[...u];return p[h]={...u[h],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},p}),D(h)):lt({...o,mountKey:_t()})}),U(o.workdir,{background:!0,force:!0})},[U,Q]),ft=r.useCallback(o=>{let h=o;if(Re==="running"?h=h.filter(u=>Bt(u)==="running"):Re==="review"&&(h=h.filter(u=>Bt(u)==="incomplete")),_e.trim()){const u=_e.toLowerCase();h=h.filter(p=>(p.lastMessageText||"").toLowerCase().includes(u)||(p.lastQuestion||"").toLowerCase().includes(u)||(p.lastAnswer||"").toLowerCase().includes(u)||(p.title||"").toLowerCase().includes(u)||(p.agent||"").toLowerCase().includes(u))}return h},[_e,Re]),gt=r.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(ge),p=ue[h.path],v=new Map;for(const k of u){const H=V(k.agent||"",k.sessionId),F=de[H],_=p?Nn(p,k.agent||"",k.sessionId):k.sessionId,O=F?.resolvedKey&&F.resolvedKey!==H?F.resolvedKey:_!==k.sessionId?V(k.agent||"",_):H,mt=v.get(O);if(!mt){v.set(O,k);continue}V(mt.agent||"",mt.sessionId)!==O&&H===O&&v.set(O,k)}const y=ft([...v.values()]);o[h.path]=Ir(y)}return o},[c,d,de,ue,ft,ge]),Vt=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 ge(h)},[ge,d]),Gt=r.useMemo(()=>new Set(W.map(o=>V(o.agent,o.sessionId))),[W]),et=fe?V(fe.agent,fe.sessionId):null,Tt=r.useCallback(o=>{P(h=>{const u=h.filter((p,v)=>v!==o);return u.length===0?D(0):Ne.current>=u.length&&D(u.length-1),E(Ue(u.length,Y.current)),u})},[P,D,E]);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:ne,onChange:o=>Se(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"}),ne&&e.jsx("button",{onClick:()=>Se(""),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",Re===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:w?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(Fr,{workspace:o,sessions:gt[o.path]||[],loading:!!j[o.path]||!(o.path in d),isActive:o.path===a,selectedKey:et,openSessionKeys:Gt,onSelectSession:Mt,onNewSession:Ct,onRefresh:ht,onRemove:Ye,onExtensions:$e,onWarmSession:Qe,onCancelWarmSession:yt,onSessionMenuOpen:xt,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:()=>ae(o),className:M("flex-1 flex items-center justify-center p-1.5 rounded transition-all",N===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(Ie,{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(${N===6?3:N}, 1fr)`,gridTemplateRows:N===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=oe?W.length<N?W.length:B:-1;return wt.current=o,Array.from({length:N},(h,u)=>{if(oe&&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(Or,{workdir:oe,workspaceName:c.find(k=>k.path===oe)?.name||oe.split("/").pop()||"",onSessionCreated:St,onClose:Lt,t:l},oe)},`new-${oe}`);const p=W[u]??null;if(!p)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 v=Vt(p),y=u===B;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",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"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",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const k=Bt(v);return e.jsx(zt,{variant:k==="running"?"ok":k==="waiting"?"info":k==="incomplete"?"warn":"idle",pulse:k==="running"||k==="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:p.workdir.split("/").pop()||p.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:v.title||v.lastQuestion?.slice(0,60)||p.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:bs(v.createdAt)}),v.runUpdatedAt&&e.jsx("span",{title:l("hub.updated"),children:Rn(v.runUpdatedAt)}),!!v.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"})}),v.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:k=>{k.stopPropagation(),ce(H=>!H)},className:M("p-0.5 rounded transition-colors",R?"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:k=>{k.stopPropagation(),Tt(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(Cr,{session:v,workdir:p.workdir,active:n&&y,onSessionChange:k=>he(k,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>pt(p.mountKey)},p.mountKey)})})]},p.mountKey||V(p.agent,p.sessionId))})})()})}),R&&fe&&e.jsx(zr,{workdir:fe.workdir,onClose:()=>ce(!1),t:l}),e.jsx($r,{open:Ke,initialPath:a||void 0,onAdd:dt,onClose:()=>He(!1),t:l}),e.jsxs(Ft,{open:!!me,onClose:()=>!X&&Pe(null),children:[e.jsx(Ut,{title:l("hub.removeWorkspace"),onClose:()=>!X&&Pe(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")}),me&&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:me}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ie,{variant:"ghost",onClick:()=>Pe(null),disabled:X,children:l("modal.cancel")}),e.jsx(Ie,{variant:"primary",onClick:ut,disabled:X,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(X?"modal.removing":"modal.remove")})]})]}),ie&&(()=>{const h=Math.max(8,Math.min(ie.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ie.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:p=>p.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>we(ie.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(Ft,{open:!!Me,onClose:()=>!je&&be(null),children:[e.jsx(Ut,{title:l("session.deleteTitle"),onClose:()=>!je&&be(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("session.deleteHint")}),Me&&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:Me.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Me.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:()=>Je(!1),disabled:je,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:()=>Je(!0),disabled:je,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(Ie,{variant:"ghost",onClick:()=>be(null),disabled:je,children:l("modal.cancel")}),e.jsx(Ie,{variant:"primary",onClick:Nt,disabled:je,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(je?"session.deleting":"modal.remove")})]})]}),e.jsx(Sr,{open:!!Be,onClose:()=>$e(null),workdir:Be||""})]})});function $r({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(Ft,{open:t,onClose:a,children:[e.jsx(Ut,{title:l("hub.addWorkspace"),onClose:a}),e.jsx(ks,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:l}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ie,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:l("hub.add")}),e.jsx(Ie,{variant:"secondary",onClick:a,className:"flex-1",children:l("hub.cancel")})]})]})}function Or({workdir:t,workspaceName:n,onSessionCreated:s,onClose:a,t:l}){const[c,x]=r.useState(null),[d,m]=r.useState([]),j=r.useRef(null),g=r.useRef([]),w=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),L=r.useCallback(()=>{},[]),N=r.useCallback((A,W)=>{x(A||null),j.current=A||null;const S=W||[];m(S),g.current=S},[]),I=r.useCallback(A=>{const W=g.current;g.current=[],s(A,j.current||void 0,W.length?W:void 0)},[s]),T=!!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(zt,{variant:T?"ok":"idle",pulse:T}),!T&&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:T?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(Jn,{text:c||"",blocks:d.map(A=>({type:"image",content:A})),t:l}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(cn,{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(Vs,{session:w,workdir:t,onStreamQueued:L,onSendStart:N,onSessionChange:I,t:l,streamPhase:null})]})}function Dr({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
23
  `);return e.jsx(js,{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 Fr=r.memo(function({workspace:n,sessions:s,loading:a,isActive:l,selectedKey:c,openSessionKeys:x,onSelectSession:d,onNewSession:m,onRefresh:j,onRemove:g,onExtensions:w,onWarmSession:L,onCancelWarmSession:N,onSessionMenuOpen:I,t:T}){const[A,W]=r.useState(!0),[S,B]=r.useState(on);r.useEffect(()=>{B(on)},[s.length]);const te=s.slice(0,S),E=s.length-S,G=n.path,[P,D]=r.useState(null),ae=r.useCallback(()=>{ee.getWorkspaceGit(G).then(R=>D(R.git)).catch(()=>D(null))},[G]);return r.useEffect(()=>{ae()},[ae]),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:()=>W(R=>!R),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",A&&"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(Dr,{git:P})]}),l&&e.jsx(zt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:R=>{R.stopPropagation(),m(G)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:T("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:R=>{R.stopPropagation(),w(G)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:T("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:R=>{R.stopPropagation(),j(G),ae()},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:R=>{R.stopPropagation(),g(G)},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"})]})})]})]}),A&&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:T("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[te.map(R=>{const ce=V(R.agent||"",R.sessionId),re=R.__forkDepth||0;return e.jsx(Ur,{session:R,isSelected:c===ce,isOpen:x?.has(ce)??!1,forkDepth:re,onClick:()=>d(R,G),onWarm:()=>L(R,G),onCancelWarm:()=>N(R,G),onShowMenu:Y=>I(Y,R,G),menuLabel:T("session.openActions")},ce)}),E>0&&e.jsxs("button",{onClick:()=>B(R=>R+on),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:["+ ",T("hub.nMore").replace("{n}",String(E))]}),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"})})]})]})})]})}),Ur=r.memo(function({session:n,isSelected:s,isOpen:a,forkDepth:l=0,onClick:c,onWarm:x,onCancelWarm:d,onShowMenu:m,menuLabel:j}){const g=ln(n.agent||""),w=Bt(n),L=An(n).slice(0,500)||n.sessionId.slice(0,16),N=vs(n,L).slice(0,500),I=n.model?Dt(n.model):null,T=l>0?Math.min(l,3)*14:0,A=a?10:12,W=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:A+T,...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(rt,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),I&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:I}),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:Rn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(zt,{variant:w==="running"?"ok":w==="waiting"?"info":w==="incomplete"?"warn":"idle",pulse:w==="running"||w==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:L})]}),N&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:N})})]}),e.jsx("button",{ref:W,type:"button","aria-label":j,"aria-haspopup":"menu",onMouseDown:S=>{S.stopPropagation()},onClick:S=>{S.stopPropagation(),S.preventDefault(),W.current&&m(W.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"})]})})]})}),zr=r.memo(function({workdir:n,onClose:s,t:a}){const l=ye(g=>g.state?.hostApp??null),c=ye(g=>g.state?.platform??null),x=ye(g=>g.toast),[d,m]=r.useState(()=>Wr(l,c)),j=r.useCallback(async g=>{try{const w=await ee.openInEditor(g,d);if(!w.ok)throw new Error(w.error||`Failed to open ${g}`)}catch(w){x(w?.message||String(w),!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(ws,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:a(es(g))})),onChange:g=>{Pr(g)&&m(g)},renderIcon:g=>e.jsx(ts,{target:g,size:14})}),e.jsx(Ie,{size:"sm",variant:"ghost",onClick:()=>j(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(Kr,{basePath:n,openTarget:d,onOpenPath:j,t:a})})]})});function ts({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(rt,{brand:t,size:n})}function Kr({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),ee.lsDir(t,!0,n).then(w=>{!g&&w.ok&&x(w.dirs.slice(0,50).map(L=>({entry:L,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||m(!1)}),()=>{g=!0}},[t,n]);const j=r.useCallback(g=>{const w=L=>L.map(N=>N.entry.path===g?N.expanded?{...N,expanded:!1}:N.children===null?(ee.lsDir(g,!0,n).then(I=>{I.ok&&x(T=>hn(T,g,{children:I.dirs.slice(0,50).map(A=>({entry:A,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(I=>hn(I,g,{children:[],loading:!1}))}),{...N,loading:!0,expanded:!0}):{...N,expanded:!0}:N.children?{...N,children:w(N.children)}:N);x(L=>w(L))},[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(ns,{nodes:c,depth:0,onToggle:j,openTarget:s,onOpenPath:a,t:l})})}function ns({nodes:t,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(Hr,{node:x,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c},x.entry.path))})}function Hr({node:t,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c}){const{entry:x,expanded:d,children:m,loading:j}=t,g=n*14,[w,L]=r.useState(!1),N=c(es(a)),I=c("hub.openWithTarget").replace("{target}",N);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>L(!0),onMouseLeave:()=>L(!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?j?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}),w&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:T=>{T.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:I,children:e.jsx(ts,{target:a,subtle:!0})}),!x.isDir&&e.jsx(Vr,{filePath:x.path,t:c})]})]}),x.isDir&&d&&m&&m.length>0&&e.jsx(ns,{nodes:m,depth:n+1,onToggle:s,openTarget:a,onOpenPath:l,t:c})]})}function Vr({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 hn(t,n,s){return t.map(a=>a.entry.path===n?{...a,...s}:a.children?{...a,children:hn(a.children,n,s)}:a)}const ao=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Br},Symbol.toStringTag,{value:"Module"}));export{Vs as I,io as L,sr as R,lo as T,Jn as U,so as a,qn as b,cn as c,oo as d,jr as e,ao as i,As as l,ro as m,no as n,Is as p,to as s};
@@ -1 +1 @@
1
- import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-BlqvzDUL.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};
1
+ import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-CLGovkkw.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-BlqvzDUL.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-CLGovkkw.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-CXIN3nTr.css">
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pikiloom",
3
- "version": "0.4.27",
3
+ "version": "0.4.28",
4
4
  "description": "Put the world's smartest AI agents in your pocket. Command local Claude & Gemini via IM. | 让最好用的 IM 变成你电脑上的顶级 Agent 控制台",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- import{r as t,j as n}from"./react-vendor-C7Sl8SE7.js";import{c as St,I as bt,S as Se,m as be,a as j,u as Ge,d as vt,g as yt,l as It,e as Tt,j as jt,f as Rt,s as wt,Y as Nt}from"./index-BlqvzDUL.js";import{l as Ot,n as Je,m as Et,a as Ct,b as Mt,p as Lt,s as ke,T as Pt,R as At,U as Ze,c as qt,d as et,e as Ft,L as Ht,I as Ut}from"./index-BY7l20bi.js";import{M as rt,a as nt}from"./Modal-M1AP1sgR.js";import"./router-DHISdpPk.js";import"./Select-YubDM16P.js";import"./DirBrowser-Dot7ua9-.js";import"./markdown-DxQYQFeH.js";import"./ExtensionsTab-GioMx4S6.js";function Dt({snapshot:d}){const[r,m]=t.useState(d.currentIndex??0),[M,R]=t.useState(""),[x,p]=t.useState(!1),[X,k]=t.useState(null);t.useEffect(()=>{m(d.currentIndex??0),R(""),k(null)},[d.promptId,d.currentIndex]);const N=d.questions||[],v=N[r]||null,V=N.length,O=!!(v?.options&&v.options.length),f=O?!!v?.allowFreeform:!0,F=o=>{o&&(m(h=>h+1),R(""))},le=async o=>{if(!x){p(!0),k(null);try{const h=await j.interactionSelectOption(d.promptId,o);if(!h.ok){k(h.error||"Failed to submit selection.");return}F(h.advanced)}catch(h){k(h?.message||"Network error.")}finally{p(!1)}}},E=async()=>{if(x)return;const o=M.trim();if(!o&&!v?.allowEmpty){k("Please enter a response.");return}p(!0),k(null);try{const h=await j.interactionSubmitText(d.promptId,o);if(!h.ok){k(h.error||"Failed to submit answer.");return}F(h.advanced)}catch(h){k(h?.message||"Network error.")}finally{p(!1)}},g=async()=>{if(!x){p(!0),k(null);try{const o=await j.interactionSkip(d.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(d.promptId)}catch{}}},G=t.useMemo(()=>{const o=[];return d.hint&&o.push(d.hint),V>1&&o.push(`Question ${r+1} of ${V}`),o.join(" · ")||void 0},[d.hint,r,V]);return n.jsxs(rt,{open:!0,onClose:H,wide:O&&(v?.options?.length||0)>3,children:[n.jsx(nt,{title:d.title||"Pikiloom needs your input",description:G,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})]}),O&&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:()=>le(o.value||o.label),className:St("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))}),f&&n.jsx("div",{children:n.jsx(bt,{value:M,onChange:o=>R(o.target.value),onKeyDown:o=>{o.key==="Enter"&&!o.shiftKey&&!x&&(o.preventDefault(),E())},placeholder:O?"Or type a custom answer…":"Type your answer…",disabled:x,autoFocus:!O})}),X&&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:X}),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(Se,{})," 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(be,{variant:"ghost",size:"sm",onClick:g,disabled:x,children:"Skip"}),f&&n.jsx(be,{variant:"primary",size:"sm",onClick:E,disabled:x||!M.trim()&&!v.allowEmpty,children:"Submit"})]})]})]}):n.jsxs("div",{className:"py-6 text-center text-sm text-fg-5",children:[n.jsx(Se,{className:"mr-2 inline-block"})," Waiting for the agent…"]})]})}function Qt(d){const r=d.streaming||d.liveStreamPhase==="streaming",m=d.queuedTaskCount>0||d.pendingQueuedCount>0||d.streamPhase==="queued";return r||m}const Fe=12,tt=160,_t=96,$t=[],Bt=[],Kt=[],zt=20,Y=new Map;function Wt(d,r){return`${d}:${r}`}function Yt(d,r){for(Y.delete(d),Y.set(d,r);Y.size>zt;)Y.delete(Y.keys().next().value)}const sr=t.memo(function({session:r,workdir:m,active:M=!0,onSessionChange:R,initialPendingPrompt:x,initialPendingImageUrls:p,onPendingPromptConsumed:X}){const k=Ge(e=>e.locale),N=Ge(e=>e.agentStatus?.agents?.find(s=>s.agent===r.agent)??null),v=N?.selectedEffort??null,V=N?.selectedModel??null,O=N?.byokProviderName??null,f=t.useMemo(()=>vt(k),[k]),F=yt(r.agent||""),le=It(r),E=!!x||!!(p&&p.length),[g,H]=t.useState(null),[G,o]=t.useState(!E),[h,He]=t.useState(!1),[i,L]=t.useState(null),[J,Z]=t.useState(!1),[U,ve]=t.useState(null),[st,Ue]=t.useState(0),[lt,ye]=t.useState(null),[D,ae]=t.useState([]),[at,oe]=t.useState([]),[ee,Ie]=t.useState([]),[S,ue]=t.useState(x||null),[C,ce]=t.useState(p||[]),[ot,ie]=t.useState(null),Te=t.useRef(null);Te.current=ot;const[De,Q]=t.useState([]),je=t.useRef([]);je.current=De;const te=t.useRef(null),[ut,Qe]=t.useState(null),[de,re]=t.useState(null),[ne,Re]=t.useState(""),[P,we]=t.useState(!1),ct=!!N?.capabilities?.fork,Ne=t.useRef(null),_=t.useRef(p||[]),w=t.useRef(i),_e=t.useRef(J);w.current=i,_e.current=J;const $e=t.useRef(D);$e.current=D;const Be=t.useRef(U);Be.current=U;const A=t.useRef(null),fe=t.useRef(null),$=t.useRef(!0),B=t.useRef(!1),me=t.useRef(null),Oe=t.useRef(!1),K=t.useRef(E),se=t.useRef(!1),q=t.useRef(!1),Ee=t.useRef(!1),Ce=t.useRef(!1),Ke=t.useRef({model:null,effort:null}),it=t.useCallback(e=>{Ke.current=e},[]);t.useEffect(()=>{Ee.current||!E||(Ee.current=!0,x&&!S&&ue(x),p&&p.length&&!C.length&&(ce(p),_.current=p),o(!1),Ue(e=>e+1),X?.())},[E,X]);const I=t.useCallback(()=>{ue(null),ce(e=>{for(const s of e)URL.revokeObjectURL(s);return[]}),_.current=[],ie(null)},[]),z=t.useCallback(()=>{Q(e=>{if(!e.length)return e;for(const s of e)for(const l of s.imageUrls)URL.revokeObjectURL(l);return[]}),te.current=null},[]),ze=t.useCallback((e,s)=>{const l=Qt({streaming:_e.current,liveStreamPhase:w.current?.phase??null,streamPhase:Be.current,queuedTaskCount:$e.current.length,pendingQueuedCount:je.current.length}),a=s||[];if(l){const u=`local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;te.current=u,Q(c=>[...c,{localId:u,taskId:null,prompt:e||"",imageUrls:a}]);return}w.current?.phase==="done"&&L(null);for(const u of _.current)URL.revokeObjectURL(u);te.current=null,ue(e||null),ce(a),_.current=a,ie(null)},[]),dt=t.useCallback(e=>{const s=te.current;if(s){te.current=null,Q(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)},[]),ft=t.useCallback(async()=>{if(!de)return;const e=ne.trim();if(e){we(!0);try{const s=await j.forkSession(m,r.agent||"",r.sessionId,de.atTurn,e,{});if(!s.ok||!s.sessionKey){we(!1);return}const[l,a]=s.sessionKey.split(":");re(null),Re(""),R?.({agent:l,sessionId:a,workdir:m})}finally{we(!1)}}},[de,ne,m,r.agent,r.sessionId,R]);Ne.current=ft;const ge=t.useCallback(async(e,s={})=>{try{const l=await Ot({workdir:m,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:s.force});return l.ok?Je(l):null}catch{return null}},[m,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:Fe},{force:s});if(!u||r.sessionId!==a)return!1;if(l&&(B.current=!0),H(c=>!c||!e?u:Et(c,u)),o(!1),se.current&&(se.current=!1,I()),q.current){const c=q.current;q.current=!1;const b=c!==!0?c.taskId:null;w.current&&(c===!0||w.current.taskId===b)&&L(null)}return!0}finally{me.current===a&&(me.current=null)}},[ge,I,r.sessionId]),he=t.useCallback(async()=>{if(!g?.hasOlder||Oe.current)return;const e=A.current;e&&(fe.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),Oe.current=!0,He(!0);try{const s=await ge({turnOffset:Math.max(0,g.totalTurns-g.startTurn),turnLimit:Fe});s?H(l=>l?Ct(l,s):s):fe.current=null}finally{Oe.current=!1,He(!1)}},[ge,g]),pe=t.useRef(null),W=t.useCallback(e=>{if(e?.sessionId&&e.sessionId!==r.sessionId&&(Ce.current=!0,Me.current=`${r.agent}:${e.sessionId}`,R?.({agent:r.agent||"",sessionId:e.sessionId,workdir:m})),!e){const l=pe.current;Z(!1),l==="streaming"?(se.current=!0,q.current=!0,T({keepOlder:!0,force:!0,scrollToBottom:$.current})):L(null),K.current&&l!=="streaming"?T({keepOlder:!0,force:!0}):(l==="done"&&(I(),z()),l!==null&&(K.current=!1)),ye(null),ve(null),ae([]),oe([]),Ie([]),pe.current=null;return}if(ve(e.phase),ye(e.taskId||null),ae(e.queuedTaskIds&&e.queuedTaskIds.length?e.queuedTaskIds:$t),oe(e.queuedTasks&&e.queuedTasks.length?e.queuedTasks:Bt),Ie(Array.isArray(e.interactions)&&e.interactions.length?e.interactions:Kt),e.phase==="streaming"){if(q.current&&w.current&&w.current.taskId!==null&&w.current.taskId!==(e.taskId||null)&&!(e.text||"").trim()||L({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}),Z(!0),e.taskId&&e.taskId!==Te.current){const a=je.current,u=a.findIndex(c=>c.taskId===e.taskId);if(u>=0){const c=a[u];for(const b of _.current)URL.revokeObjectURL(b);ue(c.prompt||null),ce(c.imageUrls),_.current=c.imageUrls,ie(e.taskId),Q(b=>b.filter((xt,kt)=>kt!==u))}}$.current&&(B.current=!0)}else if(e.phase==="queued")L(null),Z(!1);else if(e.phase==="done"){Z(!1),L(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=w.current,u=!!a&&Mt(a),c=!!e.incomplete&&u&&!l;pe.current!=="done"&&(l||(se.current=!0),q.current=c?!1:{taskId:e.taskId||null},T({keepOlder:!0,force:!0,scrollToBottom:$.current})),l||(K.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);Q(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,z,T,r.sessionId,r.agent,R,m]),We=t.useRef(W);We.current=W;const Ye=t.useCallback(()=>{K.current=!0,Ue(e=>e+1)},[]),mt=t.useCallback(async e=>{try{await j.recallSessionMessage(e),Te.current===e&&I(),Q(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)),ye(s=>s===e?null:s)}catch{}},[I]),gt=t.useCallback(async e=>{try{await j.steerSession(e)}catch{}},[]),ht=t.useCallback(async()=>{try{await j.stopSession(r.agent||"",r.sessionId)}catch{}},[r.agent,r.sessionId]),xe=Wt(r.agent||"",r.sessionId);t.useEffect(()=>{if(Ce.current){Ce.current=!1;let u=!1;return T({keepOlder:!0,force:!0}).finally(()=>{u||o(!1)}),()=>{u=!0}}let e=!1;const s=Lt({workdir:m,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:Fe},{allowStale:!0}),l=E&&!Ee.current,a=s?.ok?Je(s):Y.get(xe)||null;return o(l?!1:!a),H(a),L(null),Z(!1),ve(null),ae([]),oe([]),Ie([]),l||(I(),z(),K.current=!1,se.current=!1,q.current=!1),$.current=!0,B.current=!0,l||T({keepOlder:!1,force:!0}).finally(()=>{e||o(!1)}),()=>{e=!0}},[T,r.agent,r.sessionId,m,xe,I,z]),t.useEffect(()=>{g&&g.turns.length>0&&Yt(xe,g)},[xe,g]),t.useEffect(()=>{M&&T({keepOlder:!0,force:!0})},[M,T]);const Me=t.useRef(`${r.agent}:${r.sessionId}`);Me.current=`${r.agent}:${r.sessionId}`,Tt("stream-update",t.useCallback(e=>{e.key===Me.current&&W(e.snapshot??null)},[W])),t.useEffect(()=>{let e=!0;return j.getSessionStreamState(r.agent||"",r.sessionId).then(s=>{e&&We.current(s.state)}).catch(()=>{}),()=>{e=!1}},[r.agent,r.sessionId,st]),jt(t.useCallback(()=>{j.getSessionStreamState(r.agent||"",r.sessionId).then(e=>{W(e.state)}).catch(()=>{}),T({keepOlder:!0,force:!0})},[W,r.agent,r.sessionId,T])),t.useEffect(()=>{!K.current&&le!=="running"&&!J&&!i&&!U&&D.length===0&&(I(),z())},[le,J,i,U,D.length,I,z]),t.useLayoutEffect(()=>{const e=fe.current,s=A.current;!e||!s||(fe.current=null,s.scrollTop=e.scrollTop+(s.scrollHeight-e.scrollHeight))},[g?.turns.length]),t.useLayoutEffect(()=>{if(!B.current)return;const e=A.current;e&&(B.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{$.current&&(e.scrollTop=e.scrollHeight)}))},[g,i]),t.useLayoutEffect(()=>{if(!S)return;const e=A.current;e&&(e.scrollTop=e.scrollHeight)},[S]),t.useEffect(()=>{if(!g?.hasOlder||G||h)return;const e=A.current;e&&e.scrollHeight<=e.clientHeight+tt&&he()},[g?.hasOlder,g?.turns.length,he,G,h]);const pt=t.useCallback(()=>{const e=A.current;if(!e)return;const s=e.scrollHeight-e.scrollTop-e.clientHeight;$.current=s<=_t,e.scrollTop<=tt&&he()},[he]),Le=i?.model||r.model||V||null,Pe=Rt(r.agent||"",i?.effort||r.thinkingEffort||v||null,r.workflowEnabled??N?.workflowEnabled)||null,Xe=Le?wt(Le):null,Ae=Nt(r,{streaming:J,hasLiveStream:!!i,streamPhase:U,queuedTaskCount:D.length}),y=g?.turns||[],qe=t.useMemo(()=>{if(!C.length||!y.length)return!1;const e=y[y.length-1];return!e.user||!ke(e.user.text,S)?!1:e.user.blocks.filter(l=>l.type==="image").length<C.length},[y,S,C.length]),Ve=t.useMemo(()=>{let e=y;if(qe){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?ke(s.user?.text,l):!!u&&!!a&&(a.startsWith(u)||u.startsWith(a)))?[...e.slice(0,-1),{...s,assistant:null}]:e},[y,i,S,qe]);return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{ref:A,onScroll:pt,className:"flex-1 overflow-y-auto overscroll-contain",children:G&&!S&&!C.length&&!i?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(Se,{className:"h-5 w-5 text-fg-4"})}):Ve.length===0&&!S&&!C.length&&!i&&!Ae?n.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:f("hub.noMessages")}):n.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(g?.hasOlder||h)&&n.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[h?n.jsx(Se,{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:f(h?"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:m}),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:f("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:["· ",f("hub.forkBadgeAt").replace("{turn}",String(r.migratedFrom.forkedAtTurn+1))]})]}),Ve.map((e,s)=>{const l=(g?.startTurn||0)+s;return n.jsx(Pt,{turn:e,turnIndex:l,agent:r.agent||"",meta:F,model:Xe,effort:Pe,providerName:O,t:f,workdir:m,onResend:a=>{B.current=!0,ze(a);const u=Ke.current;j.sendSessionMessage(m,r.agent||"",r.sessionId,a,{model:u.model||Le||void 0,effort:u.effort||Pe||void 0}).then(c=>{c.ok&&Ye()}).catch(()=>{I()})},onEdit:a=>Qe(a),onFork:ct?a=>{Re(""),re({atTurn:a})}:void 0},`${g?.startTurn||0}:${s}`)}),Ae&&n.jsx("div",{className:"mb-5 animate-in",children:n.jsx(At,{detail:Ae,t:f})}),(S||C.length>0)&&(qe||!(S&&y.length>0&&ke(y[y.length-1]?.user?.text,S)))&&n.jsxs("div",{className:"session-turn",children:[n.jsx(Ze,{text:S||"",blocks:C.map(e=>({type:"image",content:e})),t:f}),!i&&n.jsx("div",{className:"mt-3 mb-5 animate-in",children:n.jsx(qt,{className:"text-fg-5"})})]}),i&&et(i)&&!S&&i.question&&!(y.length>0&&ke(y[y.length-1]?.user?.text,i.question))&&n.jsx("div",{className:"session-turn",children:n.jsx(Ze,{text:i.question,t:f})}),i&&et(i)&&n.jsxs("div",{className:"mb-6",children:[n.jsx(Ft,{agent:r.agent||"",meta:F,model:Xe,effort:Pe,providerName:O,previewMeta:i.previewMeta,liveStartedAt:i.phase==="streaming"?i.startedAt??null:null}),n.jsx(Ht,{stream:i,t:f,workdir:m})]}),n.jsx("div",{className:"h-4"})]})}),n.jsx(Ut,{session:r,workdir:m,onStreamQueued:Ye,onSendStart:ze,onSendTaskAssigned:dt,onSessionChange:R,t:f,streamPhase:U,streamTaskId:lt,queuedTaskIds:D,queuedTasks:at,pendingQueuedSends:De,onRecall:mt,onSteer:gt,onStopAll:ht,editDraft:ut,onEditDraftConsumed:()=>Qe(null),onSelectionChange:it}),de&&n.jsxs(rt,{open:!0,onClose:()=>{P||re(null)},children:[n.jsx(nt,{title:f("hub.forkPromptTitle"),description:f("hub.forkPromptHint"),onClose:()=>{P||re(null)}}),n.jsx("textarea",{autoFocus:!0,value:ne,disabled:P,onChange:e=>Re(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&ne.trim()&&!P&&(e.preventDefault(),Ne.current?.())},placeholder:f("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(be,{variant:"ghost",disabled:P,onClick:()=>re(null),children:f("modal.cancel")}),n.jsx(be,{variant:"primary",disabled:P||!ne.trim(),onClick:()=>{Ne.current?.()},children:f(P?"hub.forkSubmitting":"hub.forkSubmit")})]})]}),M&&ee.length>0&&n.jsx(Dt,{snapshot:ee[ee.length-1]},ee[ee.length-1].promptId)]})});export{sr as SessionPanel};