pikiloom 0.4.37 → 0.4.39

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.
Files changed (67) hide show
  1. package/dashboard/dist/assets/{AgentTab-DbFzaIyZ.js → AgentTab-Ds8D6yrl.js} +1 -1
  2. package/dashboard/dist/assets/{ConnectionModal-QNYOWHCU.js → ConnectionModal-Buj2d5L5.js} +1 -1
  3. package/dashboard/dist/assets/{DirBrowser-BGaKHjFT.js → DirBrowser-BTv7rH8E.js} +1 -1
  4. package/dashboard/dist/assets/{ExtensionsTab-D4Gv9b8z.js → ExtensionsTab-BnGwxS9U.js} +1 -1
  5. package/dashboard/dist/assets/{IMAccessTab-DxxoZd84.js → IMAccessTab-DjQnpOmF.js} +1 -1
  6. package/dashboard/dist/assets/{Modal-Nm2e93s5.js → Modal-DpuinsE3.js} +1 -1
  7. package/dashboard/dist/assets/{Modals-BwxZmU0U.js → Modals-Bs842H3n.js} +1 -1
  8. package/dashboard/dist/assets/{Select-SGlII0yx.js → Select-Dvia29HZ.js} +1 -1
  9. package/dashboard/dist/assets/SessionPanel-CVItEgcH.js +1 -0
  10. package/dashboard/dist/assets/{SystemTab-BF6lIAYM.js → SystemTab-BzPtwDxq.js} +1 -1
  11. package/dashboard/dist/assets/index-Bthwt6K_.css +1 -0
  12. package/dashboard/dist/assets/{index-DZiAiRNt.js → index-S0NmlDEH.js} +14 -14
  13. package/dashboard/dist/assets/{index-BP8R_bLT.js → index-yZ-iG1qk.js} +2 -2
  14. package/dashboard/dist/assets/{shared-S0kcs5yP.js → shared-p3kZpiD4.js} +1 -1
  15. package/dashboard/dist/index.html +2 -2
  16. package/dist/agent/kernel-bridge.js +207 -0
  17. package/dist/agent/mcp/capabilities.js +39 -0
  18. package/dist/agent/stream.js +19 -1
  19. package/dist/bot/bot.js +4 -13
  20. package/dist/cli/kernel-app.js +115 -0
  21. package/dist/cli/main.js +7 -0
  22. package/package.json +4 -2
  23. package/packages/kernel/README.md +305 -0
  24. package/packages/kernel/dist/contracts/driver.d.ts +95 -0
  25. package/packages/kernel/dist/contracts/driver.js +1 -0
  26. package/packages/kernel/dist/contracts/ports.d.ts +84 -0
  27. package/packages/kernel/dist/contracts/ports.js +1 -0
  28. package/packages/kernel/dist/contracts/surface.d.ts +92 -0
  29. package/packages/kernel/dist/contracts/surface.js +1 -0
  30. package/packages/kernel/dist/drivers/claude.d.ts +34 -0
  31. package/packages/kernel/dist/drivers/claude.js +500 -0
  32. package/packages/kernel/dist/drivers/codex.d.ts +24 -0
  33. package/packages/kernel/dist/drivers/codex.js +415 -0
  34. package/packages/kernel/dist/drivers/echo.d.ts +20 -0
  35. package/packages/kernel/dist/drivers/echo.js +61 -0
  36. package/packages/kernel/dist/drivers/gemini.d.ts +18 -0
  37. package/packages/kernel/dist/drivers/gemini.js +143 -0
  38. package/packages/kernel/dist/drivers/hermes.d.ts +14 -0
  39. package/packages/kernel/dist/drivers/hermes.js +194 -0
  40. package/packages/kernel/dist/drivers/index.d.ts +5 -0
  41. package/packages/kernel/dist/drivers/index.js +5 -0
  42. package/packages/kernel/dist/index.d.ts +18 -0
  43. package/packages/kernel/dist/index.js +29 -0
  44. package/packages/kernel/dist/ports/defaults.d.ts +59 -0
  45. package/packages/kernel/dist/ports/defaults.js +137 -0
  46. package/packages/kernel/dist/protocol/index.d.ts +309 -0
  47. package/packages/kernel/dist/protocol/index.js +59 -0
  48. package/packages/kernel/dist/runtime/hub.d.ts +68 -0
  49. package/packages/kernel/dist/runtime/hub.js +334 -0
  50. package/packages/kernel/dist/runtime/loom.d.ts +45 -0
  51. package/packages/kernel/dist/runtime/loom.js +72 -0
  52. package/packages/kernel/dist/runtime/pty.d.ts +23 -0
  53. package/packages/kernel/dist/runtime/pty.js +69 -0
  54. package/packages/kernel/dist/runtime/session-runner.d.ts +27 -0
  55. package/packages/kernel/dist/runtime/session-runner.js +210 -0
  56. package/packages/kernel/dist/runtime/tui.d.ts +8 -0
  57. package/packages/kernel/dist/runtime/tui.js +35 -0
  58. package/packages/kernel/dist/runtime/turn.d.ts +17 -0
  59. package/packages/kernel/dist/runtime/turn.js +16 -0
  60. package/packages/kernel/dist/surfaces/cli.d.ts +19 -0
  61. package/packages/kernel/dist/surfaces/cli.js +65 -0
  62. package/packages/kernel/dist/surfaces/index.d.ts +2 -0
  63. package/packages/kernel/dist/surfaces/index.js +2 -0
  64. package/packages/kernel/dist/surfaces/web.d.ts +39 -0
  65. package/packages/kernel/dist/surfaces/web.js +244 -0
  66. package/dashboard/dist/assets/SessionPanel-DYfSlreh.js +0 -1
  67. package/dashboard/dist/assets/index-CtS48Jn-.css +0 -1
@@ -1,23 +1,23 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-DYfSlreh.js","assets/react-vendor-C7Sl8SE7.js","assets/index-BP8R_bLT.js","assets/router-DHISdpPk.js","assets/index-CtS48Jn-.css","assets/Modal-Nm2e93s5.js","assets/Select-SGlII0yx.js","assets/DirBrowser-BGaKHjFT.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-D4Gv9b8z.js"])))=>i.map(i=>d[i]);
2
- import{c as L,a as ne,u as oe,i as Dt,f as Mt,A as vs,s as Ft,S as pe,B as lt,g as cn,w as js,b as ws,C as pn,d as ks,r as Cn,e as Ln,h as ys,n as Ns,j as Ss,k as Pn,l as Bt,m as Pe,D as Vt,o as Cs,p as Rn,_ as _n,T as Ls,q as Is}from"./index-BP8R_bLT.js";import{j as e,r as o,a as fn}from"./react-vendor-C7Sl8SE7.js";import{I as Ts}from"./Select-SGlII0yx.js";import{M as Ut,a as zt}from"./Modal-Nm2e93s5.js";import{D as Es}from"./DirBrowser-BGaKHjFT.js";import{n as Ms,r as As,M as gn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Ps}from"./ExtensionsTab-D4Gv9b8z.js";function Rs({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:L("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 at({open:t,onToggle:n,dot:s,label:l,preview:r,badge:c,collapsedContent:x,children:d,className:g}){return e.jsxs("div",{className:L("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",g),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:L("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:l}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:r}),c,e.jsx(Rs,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const _s=5e3,Ws=15e3,$t=8,Ot=30,Bs=1,it=new Map,Ne=new Map,rn=new Set,Wn=[];let At=0;function on(t){return typeof t=="number"&&Number.isFinite(t)}function Ke(t,n,s,l){for(t.delete(n),t.set(n,s);t.size>l;){const r=t.keys().next().value;if(!r)break;t.delete(r)}}function Bn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(Ke(t,n,s,t===Ne?Ot:$t),s.value)}function $n(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:on(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:on(t.turnOffset)?t.turnOffset:void 0,turnLimit:on(t.turnLimit)?t.turnLimit:void 0}}function mn(t){const n=$n(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function On(){for(;At<Bs;){const t=Wn.shift();if(!t)return;At+=1,t().finally(()=>{At=Math.max(0,At-1),On()})}}async function $s(t,n={}){const s=t;if(!n.force){const c=Bn(it,s);if(c)return c}const l=it.get(s);if(l?.promise)return l.promise;const r=ne.getWorkspaceSessions(t,n.request).then(c=>(Ke(it,s,{value:c,expiresAt:c.ok?Date.now()+_s:0},$t),c)).finally(()=>{const c=it.get(s);c?.promise&&Ke(it,s,{value:c.value,expiresAt:c.expiresAt},$t)});return Ke(it,s,{value:l?.value,expiresAt:l?.expiresAt??0,promise:r},$t),r}function Os(t,n={}){const s=mn(t),l=Ne.get(s);return l?.value?.ok&&(n.allowStale||l.expiresAt>Date.now())?l.value:null}async function Ds(t,n={}){const s=$n(t),l=mn(s);if(!n.force){const x=Bn(Ne,l);if(x?.ok)return x}const r=Ne.get(l);if(r?.promise)return r.promise;const c=ne.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(Ke(Ne,l,{value:x,expiresAt:x.ok?Date.now()+Ws:0},Ot),x)).finally(()=>{const x=Ne.get(l);x?.promise&&Ke(Ne,l,{value:x.value,expiresAt:x.expiresAt},Ot)});return Ke(Ne,l,{value:r?.value,expiresAt:r?.expiresAt??0,promise:c},Ot),c}function Fs(t){const n=mn(t);Os(t)||rn.has(n)||Ne.get(n)?.promise||(rn.add(n),Wn.push(async()=>{try{await Ds(t)}catch{}finally{rn.delete(n)}}),On())}function mo(t){const n=t.streaming||t.liveStreamPhase==="streaming",s=t.queuedTaskCount>0||t.pendingQueuedCount>0||t.streamPhase==="queued";return n||s}function bo(t){const{pendingTaskId:n,streamTaskId:s,queuedTaskIds:l}=t;return!n||n===s?!1:!!l&&l.includes(n)}function Us(t){const{queuedTaskIds:n,streamPhase:s,streamTaskId:l,localTaskId:r}=t,c=[];n&&n.length&&c.push(...n),s==="queued"&&l&&!c.includes(l)&&c.unshift(l),r&&!c.includes(r)&&(s==="queued"||!s)&&c.push(r);const x=s==="streaming"?l??null:null;return x?c.filter(d=>d!==x):c}function vo(t,n){return t==null||n==null?!0:t===n}function Kt(t){return(t||"").replace(/\s+/g," ").trim()}function zs(t,n){return Kt(t)===Kt(n)}function jo(t,n){if(zs(t,n))return!0;const s=Kt(t),l=Kt(n);if(!s||!l||s.length>=l.length||!/(?:\.\.\.|…)$/.test(s))return!1;const r=s.replace(/(?:\s*(?:\.\.\.|…))+$/,"").trim(),c=r.length-4;return c<32?!1:l.startsWith(r.slice(0,c))}function wo(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=Hs(n),l=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),r=t.window?.endTurn??l,c=t.window?.startTurn??Math.max(0,r-s.length);return{turns:s,startTurn:c,endTurn:r,totalTurns:l,hasOlder:t.window?.hasOlder??c>0}}function ko(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 yo(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 Ks(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-CVItEgcH.js","assets/react-vendor-C7Sl8SE7.js","assets/index-yZ-iG1qk.js","assets/router-DHISdpPk.js","assets/index-Bthwt6K_.css","assets/Modal-DpuinsE3.js","assets/Select-Dvia29HZ.js","assets/DirBrowser-BTv7rH8E.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-BnGwxS9U.js"])))=>i.map(i=>d[i]);
2
+ import{c as L,a as ne,u as oe,i as Dt,f as Et,A as vs,s as Ft,S as pe,B as lt,g as cn,w as js,b as ws,C as pn,d as ks,r as Cn,e as Ln,h as ys,n as Ns,j as Ss,k as Pn,l as Bt,m as Pe,D as Vt,o as Cs,p as Rn,_ as _n,T as Ls,q as Is}from"./index-yZ-iG1qk.js";import{j as e,r as o,a as fn}from"./react-vendor-C7Sl8SE7.js";import{I as Ts}from"./Select-Dvia29HZ.js";import{M as Ut,a as zt}from"./Modal-DpuinsE3.js";import{D as Ms}from"./DirBrowser-BTv7rH8E.js";import{n as Es,r as As,M as gn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Ps}from"./ExtensionsTab-BnGwxS9U.js";function Rs({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:L("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 at({open:t,onToggle:n,dot:s,label:l,preview:r,badge:c,collapsedContent:x,children:d,className:m}){return e.jsxs("div",{className:L("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:L("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:l}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:r}),c,e.jsx(Rs,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const _s=5e3,Ws=15e3,$t=8,Ot=30,Bs=1,it=new Map,Ne=new Map,rn=new Set,Wn=[];let At=0;function on(t){return typeof t=="number"&&Number.isFinite(t)}function Ke(t,n,s,l){for(t.delete(n),t.set(n,s);t.size>l;){const r=t.keys().next().value;if(!r)break;t.delete(r)}}function Bn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(Ke(t,n,s,t===Ne?Ot:$t),s.value)}function $n(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:on(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:on(t.turnOffset)?t.turnOffset:void 0,turnLimit:on(t.turnLimit)?t.turnLimit:void 0}}function mn(t){const n=$n(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function On(){for(;At<Bs;){const t=Wn.shift();if(!t)return;At+=1,t().finally(()=>{At=Math.max(0,At-1),On()})}}async function $s(t,n={}){const s=t;if(!n.force){const c=Bn(it,s);if(c)return c}const l=it.get(s);if(l?.promise)return l.promise;const r=ne.getWorkspaceSessions(t,n.request).then(c=>(Ke(it,s,{value:c,expiresAt:c.ok?Date.now()+_s:0},$t),c)).finally(()=>{const c=it.get(s);c?.promise&&Ke(it,s,{value:c.value,expiresAt:c.expiresAt},$t)});return Ke(it,s,{value:l?.value,expiresAt:l?.expiresAt??0,promise:r},$t),r}function Os(t,n={}){const s=mn(t),l=Ne.get(s);return l?.value?.ok&&(n.allowStale||l.expiresAt>Date.now())?l.value:null}async function Ds(t,n={}){const s=$n(t),l=mn(s);if(!n.force){const x=Bn(Ne,l);if(x?.ok)return x}const r=Ne.get(l);if(r?.promise)return r.promise;const c=ne.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(Ke(Ne,l,{value:x,expiresAt:x.ok?Date.now()+Ws:0},Ot),x)).finally(()=>{const x=Ne.get(l);x?.promise&&Ke(Ne,l,{value:x.value,expiresAt:x.expiresAt},Ot)});return Ke(Ne,l,{value:r?.value,expiresAt:r?.expiresAt??0,promise:c},Ot),c}function Fs(t){const n=mn(t);Os(t)||rn.has(n)||Ne.get(n)?.promise||(rn.add(n),Wn.push(async()=>{try{await Ds(t)}catch{}finally{rn.delete(n)}}),On())}function mo(t){const n=t.streaming||t.liveStreamPhase==="streaming",s=t.queuedTaskCount>0||t.pendingQueuedCount>0||t.streamPhase==="queued";return n||s}function bo(t){const{pendingTaskId:n,streamTaskId:s,queuedTaskIds:l}=t;return!n||n===s?!1:!!l&&l.includes(n)}function Us(t){const{queuedTaskIds:n,streamPhase:s,streamTaskId:l,localTaskId:r}=t,c=[];n&&n.length&&c.push(...n),s==="queued"&&l&&!c.includes(l)&&c.unshift(l),r&&!c.includes(r)&&(s==="queued"||!s)&&c.push(r);const x=s==="streaming"?l??null:null;return x?c.filter(d=>d!==x):c}function vo(t,n){return t==null||n==null?!0:t===n}function Kt(t){return(t||"").replace(/\s+/g," ").trim()}function zs(t,n){return Kt(t)===Kt(n)}function jo(t,n){if(zs(t,n))return!0;const s=Kt(t),l=Kt(n);if(!s||!l||s.length>=l.length||!/(?:\.\.\.|…)$/.test(s))return!1;const r=s.replace(/(?:\s*(?:\.\.\.|…))+$/,"").trim(),c=r.length-4;return c<32?!1:l.startsWith(r.slice(0,c))}function wo(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=Hs(n),l=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),r=t.window?.endTurn??l,c=t.window?.startTurn??Math.max(0,r-s.length);return{turns:s,startTurn:c,endTurn:r,totalTurns:l,hasOlder:t.window?.hasOlder??c>0}}function ko(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 yo(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 Ks(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 Hs(t){const n=[];let s={user:null,assistant:null};for(const l of t)if(l.role==="user"){if(s.assistant&&Dn(l.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=l}else s.assistant?s.assistant=Ks(s.assistant,l):s.assistant=l;return(s.user||s.assistant)&&n.push(s),n}const Vs=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"]),Gs=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function Dn(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Vs.has(s[1].toLowerCase())?!0:Gs.some(l=>t.includes(l))}function bn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function Fn(t){return`${bn(t)} tok`}function Un(t){return t>=85?"bg-rose-400/70":t>=60?"bg-amber-400/70":"bg-emerald-400/70"}function qs(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),l=n%60;return s<60?`${s}m${l.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function zn(t,n){const s=t.split(`
5
5
  `).filter(l=>l.trim());return s.length<=n?s.join(`
6
6
  `):s.slice(-n).join(`
7
7
  `)}function Qs(t){const n=String(t||"").trim().toLowerCase();return n?n.startsWith("interrupted by user")?"interrupted":n.startsWith("timed out")||n.startsWith("stopped before completion")||n.includes("max tokens")?"incomplete":"error":"error"}function ln(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function Ys(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function Kn(t){if(!Number.isFinite(t)||t<=0)return"0 B";if(t<1024)return`${t} B`;const n=t/1024;if(n<1024)return`${n.toFixed(n>=100?0:1)} KB`;const s=n/1024;return`${s.toFixed(s>=100?0:1)} MB`}async function Xs(t){if(typeof ClipboardItem>"u"||!navigator.clipboard?.write)return!1;try{return await navigator.clipboard.write([new ClipboardItem({[t.type||"image/png"]:t})]),!0}catch{return!1}}function Z(t,n=120){if(t==null)return"";const l=(typeof t=="string"?t:String(t)).replace(/\s+/g," ").trim();return l.length<=n?l:l.slice(0,Math.max(0,n-1))+"…"}function Zs(t){if(!t)return null;try{const n=JSON.parse(t);return n&&typeof n=="object"&&!Array.isArray(n)?n:null}catch{return null}}function Hn(t){const n=String(t.toolName||"").trim()||"Tool",s=Zs(t.content);if(!s)return n;const l=Z(s.description,120);switch(n){case"Read":{const r=Z(s.file_path||s.path,140);return r?`Read ${r}`:"Read"}case"Edit":{const r=Z(s.file_path||s.path,140);return r?`Edit ${r}`:"Edit"}case"Write":{const r=Z(s.file_path||s.path,140);return r?`Write ${r}`:"Write"}case"Glob":{const r=Z(s.pattern||s.glob,120);return r?`Glob ${r}`:"Glob"}case"Grep":{const r=Z(s.pattern||s.query,120);return r?`Grep ${r}`:"Grep"}case"WebFetch":{const r=Z(s.url,120);return r?`WebFetch ${r}`:"WebFetch"}case"WebSearch":{const r=Z(s.query,120);return r?`WebSearch ${r}`:"WebSearch"}case"TodoWrite":return"Update plan";case"AskUserQuestion":{const c=(Array.isArray(s.questions)?s.questions:[])[0],x=Z(c?.question||s.question,120);return x?`Ask user: ${x}`:"Ask user"}case"Task":{const r=Z(s.description||s.prompt,120);return r?`Task: ${r}`:"Task"}case"Bash":{if(l)return`Bash: ${l}`;const r=Z(s.command,120);return r?`Bash: ${r}`:"Bash"}default:{const r=n.match(/^mcp__[^_]+__(.+)$/),c=r?r[1]:n;if(c==="im_send_file"){const d=Z(s.path,120);return d?`Send file: ${d}`:"Send file"}if(c==="im_list_files")return"List workspace files";if(l)return`${n}: ${l}`;const x=Z(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return x?`${n}: ${x}`:n}}}function Js(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
8
- `).map(l=>l.trim()).find(Boolean)||"";return s?Z(s,140):"result"}function er(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),l=t.slice(n+1).trim();return!s||!l?null:{agent:s,sessionId:l}}const gt=new Map;function tr(t,n){return`${t}:${n}`}const nr=[],sr=[],rr={};function or(t){const n=(()=>{try{return new URL(t.baseURL).host.toLowerCase()}catch{return""}})();return n.includes("openrouter")?"openrouter":n.includes("anthropic")?"anthropic":n.includes("deepseek")?"deepseek":n.includes("googleapis")||n.includes("vertex")?"google":n.includes("openai.com")?"openai":n.includes("dashscope")||n.includes("qwen")||n.includes("aliyun")?"qwen":n.includes("volces")||n.includes("volcengine")||n.includes("doubao")?"doubao":n.includes("bigmodel")||n.includes("zhipu")||n.includes("z.ai")?"glm":n.includes("minimax")?"minimax":t.kind==="anthropic"?"anthropic":t.kind==="google"?"google":t.kind==="openai"?"openai":"custom"}const ir=o.memo(function({session:n,workdir:s,onStreamQueued:l,onSendStart:r,onSendTaskAssigned:c,onSessionChange:x,t:d,streamPhase:g,streamTaskId:b,queuedTaskIds:m,queuedTasks:j,pendingQueuedSends:C,onRecall:y,onSteer:B,onStopAll:A,editDraft:W,onEditDraftConsumed:$,onSelectionChange:U}){const[z,Q]=o.useState(""),[T,K]=o.useState(!1),[P,O]=o.useState(null),[S,E]=o.useState(()=>new Set),[ue,ie]=o.useState(()=>new Set),q=o.useRef({prompt:"",files:[]}),Se=oe(a=>a.agentStatus?.agents??null),[H,mt]=o.useState(Se||[]),[fe,dt]=o.useState(""),[He,Ve]=o.useState(""),[J,_e]=o.useState(void 0),[We,Ge]=o.useState(""),[ee,Be]=o.useState([]),[ge,qe]=o.useState(null),[Ce,bt]=o.useState(null),[me,le]=o.useState(null),[Qe,Le]=o.useState(null),[vt,Ie]=o.useState(null),[se,be]=o.useState(void 0),[M,he]=o.useState("closed"),[Y,jt]=o.useState(null),Te=o.useRef(null),Ye=o.useRef(!1),$e=o.useRef(null),qt=o.useRef(null),xe=o.useRef(null),ve=o.useRef([]),[je,wt]=o.useState([]),[ae,Oe]=o.useState(!1),[Xe,Ze]=o.useState(0),Je=o.useRef(null),Ee=oe(a=>a.refreshAgentStatus),we=oe(a=>a.modelLayer),De=oe(a=>a.ensureModelLayer),ut=oe(a=>a.refreshModelLayer),ce=we?.providers??nr,et=we?.profiles??sr,tt=we?.activeProfiles??rr;o.useEffect(()=>{De()},[De]),o.useEffect(()=>{Se?.length&&mt(Se)},[Se]),o.useEffect(()=>{ve.current=ee},[ee]);const re=tr(n.agent||"",n.sessionId),Me=o.useRef(re);Me.current=re,o.useEffect(()=>{const a=gt.get(re);return a&&(gt.delete(re),a.text&&Q(a.text),a.files.length&&Be(a.files.map(ln))),()=>{const f=Te.current?.value||"",v=ve.current.map(I=>I.file);for(const I of ve.current)URL.revokeObjectURL(I.previewUrl);f||v.length?gt.set(Me.current,{text:f,files:v}):gt.delete(Me.current)}},[re]);const kt=o.useRef({agent:n.agent||"",sessionId:n.sessionId});o.useEffect(()=>{const a=kt.current,f={agent:n.agent||"",sessionId:n.sessionId};kt.current=f,!(a.agent===f.agent&&Dt(a.sessionId)&&!Dt(f.sessionId))&&(dt(""),Ve(""),_e(void 0),Ge(""),le(null),Le(null),Ie(null),he("closed"))},[n.agent,n.sessionId]),o.useEffect(()=>{W!=null&&(Q(W),$?.(),requestAnimationFrame(()=>{const a=Te.current;a&&(a.focus(),a.setSelectionRange(W.length,W.length))}))},[W,$]),o.useEffect(()=>{if(!s)return;let a=!1;return ne.getSkills(s).then(f=>{!a&&f.ok&&wt(f.skills)}).catch(()=>{}),()=>{a=!0}},[s]);const ht=ae?(()=>{const a=z.match(/^\/(\S*)$/);return a?a[1].toLowerCase():null})():null,ke=ht!==null?je.filter(a=>a.name.toLowerCase().includes(ht)||a.label&&a.label.toLowerCase().includes(ht)):[];o.useEffect(()=>{Ze(0)},[ae,z]),o.useEffect(()=>{if(!ae||!Je.current)return;const a=Je.current.querySelector(`[data-skill-idx="${Xe}"]`);a&&a.scrollIntoView({block:"nearest"})},[Xe,ae]),o.useEffect(()=>{if(!ae)return;const a=f=>{Je.current?.contains(f.target)||Te.current?.contains(f.target)||Oe(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[ae]),o.useEffect(()=>{if(M==="closed")return;const a=f=>{const v=f.target;xe.current?.contains(v)||document.getElementById("cascade-portal")?.contains(v)||(he("closed"),le(null),Le(null),Ie(null))};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[M]),o.useLayoutEffect(()=>{if(M==="closed"||!xe.current){jt(null);return}const a=xe.current.getBoundingClientRect();jt({left:a.left,bottom:window.innerHeight-a.top+8})},[M]);const yt=m&&m.length?m[0]:null;o.useEffect(()=>{P&&(yt||g!==null&&g!=="queued")&&O(null)},[g,P,yt]),o.useEffect(()=>{const a=Te.current;a&&(a.style.height="auto",a.style.height=Math.min(a.scrollHeight,200)+"px")},[z]);const xt=o.useCallback(a=>{const f=Array.from(a||[]).filter(v=>v.type.startsWith("image/"));f.length&&Be(v=>[...v,...f.map(ln)])},[]),Nt=o.useCallback(()=>{qe(null),Be(a=>(Ys(a),[]))},[]),St=o.useCallback(a=>{Be(f=>{const v=f.find(I=>I.id===a);return v&&URL.revokeObjectURL(v.previewUrl),f.filter(I=>I.id!==a)}),qe(f=>f===a?null:f)},[]),Ct=o.useCallback(()=>{const a=z.trim(),f=ee.map(X=>X.file);if(!a&&f.length===0||T)return;const v=fe||n.agent||H.find(X=>X.isDefault)?.agent||"";if(!v)return;const I=H.find(X=>X.agent===v)||null,V=!!n.agent&&v===n.agent,ye=(He||V&&n.model||""||I?.selectedModel||"").trim()||null,rt=J!==void 0?J:V&&n.model?n.profileId??null:void 0,ot=v==="gemini"?null:(We||(V?Mt(v,n.thinkingEffort,n.workflowEnabled):"")||Mt(v,I?.selectedEffort,I?.workflowEnabled)||"").trim()||null,te=v!==n.agent,sn=te?"":n.sessionId,gs=te&&n.agent?n.agent:null,ms=te&&n.sessionId?n.sessionId:null;K(!0),q.current={prompt:a,files:f},Q(""),gt.delete(Me.current);const bs=f.length?f.map(X=>URL.createObjectURL(X)):void 0;Nt(),r(a,bs),l(),ne.sendSessionMessage(s,v,sn,a,{attachments:f,model:ye,profileId:rt,effort:ot,previousAgent:gs,previousSessionId:ms}).then(X=>{if(X.taskId&&(O(X.taskId),c?.(X.taskId)),!X.ok)return;const ft=typeof X.sessionKey=="string"?er(X.sessionKey):null;ft&&(ft.agent!==n.agent||ft.sessionId!==n.sessionId)&&ft&&x?.({...ft,workdir:s})}).catch(()=>{}).finally(()=>K(!1))},[H,Nt,ee,z,r,c,x,l,fe,We,He,J,T,n.agent,n.sessionId,n.model,n.profileId,s]),Lt=g==="streaming",de=Us({queuedTaskIds:m,streamPhase:g,streamTaskId:b,localTaskId:P}),It=de[de.length-1]||null,pt=de.length>0,Qt=pt||Lt;o.useEffect(()=>{const a=f=>de.includes(f)||f===b;E(f=>{let v=!1;const I=new Set;for(const V of f)a(V)?I.add(V):v=!0;return v?I:f}),ie(f=>{let v=!1;const I=new Set;for(const V of f)a(V)?I.add(V):v=!0;return v?I:f})},[de,b]),o.useEffect(()=>{!pt&&q.current.files.length&&(q.current={prompt:"",files:[]})},[pt]);const Yt=o.useCallback(a=>{if(!S.has(a)){if(E(f=>{const v=new Set(f);return v.add(a),v}),a===It){const f=q.current;f.prompt&&Q(f.prompt),f.files.length&&Be(f.files.map(ln)),q.current={prompt:"",files:[]}}y?.(a),a===P&&O(null)}},[S,It,P,y]),[nt,i]=o.useState(!1),h=o.useCallback(async()=>{if(!(nt||!A)){i(!0);try{await A()}finally{i(!1)}}},[nt,A]),u=o.useCallback(a=>{ue.has(a)||(ie(f=>{const v=new Set(f);return v.add(a),v}),B?.(a),a===P&&O(null))},[ue,P,B]),p=o.useCallback(a=>{Q(`/${a.name} `),Oe(!1),requestAnimationFrame(()=>{const f=Te.current;f&&(f.focus(),f.setSelectionRange(f.value.length,f.value.length))})},[]),w=o.useCallback(a=>{Q(a);const f=/^\/\S*$/.test(a)&&je.length>0;Oe(f)},[je.length]),k=a=>{if(ae&&ke.length>0){if(a.key==="ArrowDown"){a.preventDefault(),Ze(f=>(f+1)%ke.length);return}if(a.key==="ArrowUp"){a.preventDefault(),Ze(f=>(f-1+ke.length)%ke.length);return}if(a.key==="Tab"||a.key==="Enter"&&!a.shiftKey&&!Ye.current){a.preventDefault(),p(ke[Xe]);return}if(a.key==="Escape"){a.preventDefault(),Oe(!1);return}}a.key==="Enter"&&!a.shiftKey&&!Ye.current&&(a.preventDefault(),Ct())},N=o.useCallback(a=>{const f=Array.from(a.clipboardData?.items||[]).filter(v=>v.kind==="file"&&v.type.startsWith("image/")).map(v=>v.getAsFile()).filter(v=>!!v);f.length&&(a.preventDefault(),xt(f))},[xt]),R=fe||n.agent||H.find(a=>a.isDefault)?.agent||H.find(a=>a.installed)?.agent||H[0]?.agent||"",F=H.find(a=>a.agent===R)||null,_=me||R,D=H.find(a=>a.agent===_)||F,Ae=o.useMemo(()=>{if(!D)return[];const a=[];for(const v of D.models||[])a.push({id:v.id,label:v.id,kind:"native",description:v.alias&&v.alias.toLowerCase()!==v.id.toLowerCase()?v.alias:void 0});const f=new Set(vs[_]||[]);for(const v of et){const I=ce.find(ye=>ye.id===v.providerId);if(!I||!f.has(I.kind))continue;const V=v.name.trim().toLowerCase()!==v.modelId.trim().toLowerCase();a.push({id:v.modelId,label:v.name,kind:"profile",profileId:v.id,description:V?`${I.name} · ${v.modelId}`:I.name})}return a},[D,_,et,ce]),kn=o.useMemo(()=>Ae.findIndex(a=>a.kind==="profile"),[Ae]),ls=tt[_]||null,Xt=!!n.agent&&R===n.agent,Tt=J!==void 0?J:Xt?n.profileId??null:void 0,Et=He||Xt&&n.model||""||F?.selectedModel||"",Zt=R==="gemini"?"":We||(Xt?Mt(R,n.thinkingEffort,n.workflowEnabled):"")||Mt(R,F?.selectedEffort,F?.workflowEnabled)||"";o.useEffect(()=>{U?.({model:Et||null,effort:Zt||null})},[Et,Zt,U]);const as=F?.effortOptions??[],Fe=ge&&ee.find(a=>a.id===ge)||null,cs=Fe?{key:Fe.id,url:Fe.previewUrl,name:Fe.file.name,size:Fe.file.size,file:Fe.file,onRemove:()=>St(Fe.id)}:Ce?{key:Ce,url:Ce}:null,yn=(!!z.trim()||ee.length>0)&&!T&&!!R,Jt=()=>{le(null),Le(null),Ie(null),be(void 0)},Nn=o.useCallback((a,f)=>{dt(a),Ve(f),se!==void 0&&_e(se),a!==R&&Ge(""),Jt(),he("closed")},[se,R]),ds=o.useCallback(a=>{Ge(a),Ie(null)},[]),us=()=>{M==="closed"?(Jt(),Ee(),ut(),he("agent")):(Jt(),he("closed"))},en=me||R,Sn=cn(en),tn=Qe??Et,hs=vt??Zt,xs=tn?Ft(tn):"",Ue=(()=>{const a=!me&&Tt!==void 0?Tt:tt[en]??null;return a?et.find(f=>f.id===a)??null:null})(),st=Ue?ce.find(a=>a.id===Ue.providerId)??null:null,ps=st?or(st):null,nn=Ue?Ue.name.trim().toLowerCase()!==Ue.modelId.trim().toLowerCase()?Ue.name:Ft(Ue.modelId):xs,fs=[Sn.shortLabel,st?st.name:null,nn||null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:qt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[Qt&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[Lt&&e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-primary/20 bg-primary/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx(pe,{className:"h-3 w-3 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-[12px] font-medium text-fg-3 truncate",children:d("hub.running")}),e.jsxs("button",{onClick:h,disabled:nt,title:d("hub.stopHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none shrink-0",children:[nt?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),d("hub.stop")]})]}),de.map((a,f)=>{const v=f===de.length-1,I=ue.has(a),V=I?d("hub.steering"):de.length>1?`${d("hub.queued")} #${f+1}`:d("hub.queued"),ye=C?.find(te=>te.taskId===a)||(v?C?.find(te=>!te.taskId):void 0),rt=j?.find(te=>te.taskId===a)?.prompt||ye?.prompt||null,ot=ye?.imageUrls?.length?ye.imageUrls:[];return e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-warn/25 bg-warn/[0.04] px-3.5 py-1.5 transition-colors",children:[I?e.jsx(pe,{className:"h-3 w-3 text-warn shrink-0"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-warn animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-warn shrink-0",children:V}),ot.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[ot.slice(0,3).map((te,sn)=>e.jsx("button",{type:"button",onClick:()=>bt(te),title:d("hub.previewImage"),className:"block h-5 w-5 shrink-0 overflow-hidden rounded border border-warn/30 transition-opacity hover:opacity-80",children:e.jsx("img",{src:te,alt:"",className:"h-full w-full object-cover"})},`${te}-${sn}`)),ot.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",ot.length-3]})]}),rt&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:rt})]}),!I&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>u(a),title:d("hub.steerHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-blue-400 hover:bg-blue-400/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),d("hub.steer")]}),e.jsxs("button",{onClick:()=>Yt(a),disabled:S.has(a),title:d("hub.recallHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[S.has(a)?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]}),d("hub.recall")]})]})]},a)})]}),e.jsxs("div",{className:"relative rounded-xl border border-edge/40 bg-panel shadow-sm transition-[border-color,box-shadow] duration-200 focus-within:border-fg-5/40 focus-within:shadow-md",children:[e.jsx("input",{ref:$e,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:a=>{xt(a.target.files),a.target.value=""}}),ee.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:ee.map(a=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>qe(a.id),title:d("hub.previewImage"),className:"group relative h-[72px] w-[72px] overflow-hidden rounded-lg border border-edge/30 bg-panel-alt/30",children:[e.jsx("img",{src:a.previewUrl,alt:a.file.name,className:"h-full w-full object-cover transition-transform duration-200 group-hover:scale-[1.03]"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent px-1.5 pb-1 pt-3 text-left",children:e.jsx("div",{className:"truncate text-[8px] font-medium text-white/90 leading-tight",children:a.file.name})})]}),e.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),St(a.id)},title:d("hub.removeImage"),className:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-black/65 text-white/75 transition-colors hover:bg-black/80 hover:text-white",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]},a.id))})}),ae&&ke.length>0&&e.jsxs("div",{ref:Je,className:"absolute bottom-full left-0 right-0 mb-1.5 z-50 max-h-[200px] overflow-y-auto rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg animate-in",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-edge/20",children:e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d("hub.skills")})}),e.jsx("div",{className:"py-1",children:ke.map((a,f)=>e.jsxs("button",{"data-skill-idx":f,onMouseDown:v=>{v.preventDefault(),p(a)},onMouseEnter:()=>Ze(f),className:L("flex flex-col w-full px-3 py-1.5 text-left transition-colors",f===Xe?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",a.name]}),(a.label||a.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:a.label||a.description})]},a.name))})]}),e.jsx("textarea",{ref:Te,value:z,onChange:a=>w(a.target.value),onPaste:N,onKeyDown:k,onCompositionStart:()=>{Ye.current=!0},onCompositionEnd:()=>{Ye.current=!1},placeholder:d("hub.inputPlaceholder"),rows:1,className:"w-full resize-none bg-transparent px-4 pt-3 pb-1 text-[13.5px] text-fg outline-none placeholder:text-fg-5/25 leading-[1.6]",style:{maxHeight:200,overflow:z.split(`
9
- `).length>6?"auto":"hidden"}}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>$e.current?.click(),title:d("hub.addImages"),className:"flex h-7 w-7 items-center justify-center rounded-lg text-fg-5/50 transition-colors hover:bg-panel-h/60 hover:text-fg-3",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})}),e.jsxs("button",{ref:xe,onClick:us,disabled:!H.length,title:H.length?fs:void 0,className:L("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",M!=="closed"?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[H.length?e.jsx(lt,{brand:en,size:12}):e.jsx(pe,{className:"h-3 w-3"}),H.length?e.jsxs("span",{className:"flex items-center gap-1 max-w-[460px] min-w-0 truncate",children:[e.jsx("span",{className:"shrink-0",children:Sn.shortLabel}),st&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(lt,{brand:ps||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:st.name})]}),nn&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:tn||void 0,children:nn})]})]}):e.jsx("span",{className:"max-w-[420px] truncate",children:d("hub.selectAgent")}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:L("text-fg-5/30 transition-transform duration-200",M!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),M!=="closed"&&Y&&fn.createPortal(e.jsxs("div",{id:"cascade-portal",className:"fixed z-[200] w-[300px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in",style:{left:Y.left,bottom:Y.bottom},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5 border-b border-edge/20",children:[M!=="agent"&&e.jsx("button",{onClick:()=>he("agent"),className:"p-0.5 rounded text-fg-5/50 hover:text-fg-3 transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d(M==="agent"?"hub.selectAgent":"hub.selectModel")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const f=D?.capabilities?.modelSwitch!==!1?["agent","model"]:["agent"],v=f.indexOf(M);return f.map((I,V)=>e.jsx("span",{className:L("w-1.5 h-1.5 rounded-full transition-colors",M===I?"bg-primary":V<v?"bg-primary/40":"bg-fg-5/15")},I))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[M==="agent"&&H.filter(a=>a.installed).map(a=>{const f=cn(a.agent),v=js(a.usage),I=v?ws(v):"ok";return e.jsxs(dn,{selected:a.agent===(me||R),onClick:()=>{if(le(a.agent),Le(a.selectedModel||""),Ie(a.selectedEffort||""),!(a.capabilities?.modelSwitch!==!1)){Nn(a.agent,a.selectedModel||"");return}he("model")},children:[e.jsx(lt,{brand:a.agent,size:14}),e.jsx("span",{style:{color:f.color},children:f.label}),v&&e.jsxs("span",{className:L("ml-auto font-mono text-[10px]",I==="err"?"text-err":I==="warn"?"text-warn":"text-fg-5"),children:[v.label," ",Math.round(v.usedPercent??0),"%"]})]},a.agent)}),M==="model"&&e.jsxs(e.Fragment,{children:[Ae.map((a,f)=>{const v=f===0&&a.kind==="native",I=f===kn&&a.kind==="profile",V=se!==void 0?se:_===R&&Tt!==void 0?Tt:ls,ye=a.kind==="profile"?!!a.profileId&&a.profileId===V:!V&&a.id===(Qe??Et);return e.jsxs("div",{children:[v&&e.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupNative")}),I&&e.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupProfiles")}),e.jsx(dn,{selected:ye,onClick:()=>{const rt=me||R;Le(a.id),be(a.profileId??null),Nn(rt,a.id)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:L("truncate text-[11.5px]",a.kind==="native"&&"font-mono text-[11px]"),title:a.id,children:a.label}),a.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:a.description})]})})]},`${a.kind}:${a.profileId||a.id}`)}),Ae.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]})]})]}),document.body),e.jsx(ar,{current:hs,options:as,onSelect:ds,label:d("hub.selectEffort")}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:Ct,disabled:!yn,className:L("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",yn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:T?e.jsx(pe,{className:"h-3.5 w-3.5"}):e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})]}),e.jsx(lr,{source:cs,onClose:()=>{qe(null),bt(null)},t:d})]})});function lr({source:t,onClose:n,t:s}){const[l,r]=o.useState(!1);if(o.useEffect(()=>{r(!1)},[t?.key]),o.useEffect(()=>{if(!t)return;const d=g=>{g.key==="Escape"&&n()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[t,n]),!t)return null;const c=t.file,x=t.onRemove;return fn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center bg-black/72 px-4 py-6 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[1024px]",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-[11px] text-white/72",children:[t.name&&e.jsx("span",{className:"truncate font-medium text-white/90",children:t.name}),typeof t.size=="number"&&e.jsx("span",{children:Kn(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await Xs(c)&&(r(!0),window.setTimeout(()=>r(!1),1600))},className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s(l?"hub.copied":"hub.copyImage")}),x&&e.jsx("button",{type:"button",onClick:x,className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s("hub.removeImage")}),e.jsx("button",{type:"button",onClick:n,className:"flex h-9 w-9 items-center justify-center rounded-full border border-white/12 bg-white/10 text-white/88 transition-colors hover:bg-white/14",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-white/10 bg-black/35 shadow-[0_20px_70px_rgba(0,0,0,0.45)]",children:e.jsx("img",{src:t.url,alt:t.name||"",className:"max-h-[80vh] w-full object-contain"})})]})}),document.body)}function dn({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:L("flex items-center gap-2 w-full px-3 py-2 text-[12px] text-left transition-colors",t?"text-fg bg-panel-h font-medium":"text-fg-3 hover:bg-panel-alt/50 hover:text-fg-2"),children:[s,t&&e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"ml-auto text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),!t&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"ml-auto text-fg-5/20",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})})]})}function ar({current:t,options:n,onSelect:s,label:l}){const[r,c]=o.useState(!1),x=o.useRef(null);if(o.useEffect(()=>{if(!r)return;const g=b=>{x.current&&!x.current.contains(b.target)&&c(!1)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[r]),!n.length)return null;const d=n.find(g=>g.id===t)?.label||(t?t.charAt(0).toUpperCase()+t.slice(1):"—");return e.jsxs("div",{className:"relative shrink-0",ref:x,children:[e.jsxs("button",{type:"button",onClick:()=>c(g=>!g),title:l,className:L("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",r?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"m12 14 4-4"}),e.jsx("path",{d:"M3.34 19a10 10 0 1 1 17.32 0"})]}),e.jsx("span",{className:"shrink-0",children:d}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:L("text-fg-5/30 transition-transform duration-200",r&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),r&&e.jsx("div",{className:"absolute bottom-full left-0 mb-1.5 z-[200] min-w-[150px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in py-1",children:n.map(g=>e.jsx(dn,{selected:g.id===t,onClick:()=>{s(g.id),c(!1)},children:g.label},g.id))})]})}function cr(){return function(t){Ms(t)}}const vn=[As,cr],Vn=t=>/^https?:\/\//.test(t),dr=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function ur(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function Gn(t){let n=t.trim();const s=[["`","`"],['"','"'],["'","'"],["<",">"]];let l=!0;for(;l&&n.length>=2;){l=!1;for(const[r,c]of s)n.startsWith(r)&&n.endsWith(c)&&(n=n.slice(r.length,-c.length).trim(),l=!0)}return n}function jn(t){let n=Gn(t),s="";for(;n.length>1;){const l=n[n.length-1];if(!l||!/[),.;!?]/.test(l)||l==="."&&/^\.[A-Za-z0-9_-]+$/.test(n))break;s=l+s,n=n.slice(0,-1)}return{text:n,trailing:s}}function Ht(t){const n=jn(t).text;if(!n||Vn(n)||dr(n)&&!n.startsWith("file://"))return!1;const s=ur(n);if(!s)return!1;if(s.startsWith("file://"))return s.length>7;if(/^[A-Za-z]:[\\/]/.test(s))return!0;if(/^(\/|~\/|\.{1,2}\/)/.test(s))return s.length>1;if(s.includes("/")){const l=s.split("/")[0]||"";return!/^[A-Za-z0-9-]+\.[A-Za-z]{2,}$/.test(l)}return!1}function wn(t,n){ne.openInEditor(t,void 0,n||void 0).catch(()=>{})}function qn(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),t.stopPropagation(),wn(n,s))}const hr="text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",xr="underline decoration-dotted decoration-fg-5/40 underline-offset-2 cursor-pointer hover:text-blue-300 hover:decoration-blue-300/50 transition-colors";function Qn({locator:t,workdir:n,className:s,children:l}){return e.jsx("span",{role:"link",tabIndex:0,title:t,className:s??hr,onClick:r=>{r.stopPropagation(),wn(t,n)},onKeyDown:r=>qn(r,t,n),children:l??t})}function pr(t){const n=[];if(!t)return n;for(const s of t.split(/(\s+)/)){if(!s)continue;if(/^\s+$/.test(s)){n.push({type:"text",value:s});continue}const{text:l,trailing:r}=jn(s),c=Gn(l);c&&!c.endsWith("…")&&Ht(c)?(n.push({type:"link",locator:c,display:r?s.slice(0,s.length-r.length):s}),r&&n.push({type:"text",value:r})):n.push({type:"text",value:s})}return n}function Re({text:t,workdir:n,className:s}){const l=pr(t);return l.some(r=>r.type==="link")?e.jsx(e.Fragment,{children:l.map((r,c)=>r.type==="link"?e.jsx(Qn,{locator:r.locator,workdir:n,className:s??xr,children:r.display},c):e.jsx("span",{children:r.value},c))}):e.jsx(e.Fragment,{children:t})}function fr({text:t}){const[n,s]=o.useState(!1),l=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:l,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function In(t){const n=Ht(t),s=/^(npm |npx |git |python|pip |yarn |pnpm |cargo |go |make )/.test(t);return n?"bg-blue-500/8 border-blue-400/12 text-blue-300/90":s?"bg-amber-500/8 border-amber-400/10 text-amber-300/80":"bg-[rgba(255,255,255,0.06)] border-edge/20 text-fg-3"}function Gt(t={}){const n=t.workdir||null;return{h1:({children:s})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:s}),h2:({children:s})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:s}),h3:({children:s})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:s}),p:({children:s})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:s}),strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-fg",children:s}),em:({children:s})=>e.jsx("em",{className:"italic text-fg-3",children:s}),a:({href:s,children:l})=>s&&Vn(s)?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",children:l}):s&&Ht(s)?e.jsx(Qn,{locator:jn(s).text,workdir:n,children:l}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:l}),ul:({children:s})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:s}),ol:({children:s})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:s}),li:({children:s})=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"shrink-0 mt-[10px] w-[5px] h-[5px] rounded-full bg-fg-5/40"}),e.jsx("span",{className:"flex-1",children:s})]}),blockquote:({children:s})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:s}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:s,children:l})=>{const r=String(l).replace(/\n$/,""),c=/language-(\w+)/.exec(s||"");if(!c&&!s&&!r.includes(`
10
- `))return Ht(r)?e.jsx("code",{role:"link",tabIndex:0,title:r,className:L("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",In(r)),onClick:()=>wn(r,n),onKeyDown:d=>qn(d,r,n),children:r}):e.jsx("code",{className:L("px-1.5 py-[1px] rounded text-[12px] font-mono border",In(r)),children:r});const x=c?.[1]||"";return e.jsxs("div",{className:"rounded-lg overflow-hidden border border-edge/30 bg-[rgba(0,0,0,0.25)] my-3 not-prose",children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-1.5 border-b border-edge/15 bg-[rgba(0,0,0,0.12)]",children:[e.jsx("span",{className:"text-[10px] font-mono text-fg-5/50",children:x||"text"}),e.jsx(fr,{text:r})]}),e.jsx("pre",{className:"px-3.5 py-3 text-[12px] leading-[1.65] text-fg-3 font-mono whitespace-pre-wrap break-words overflow-x-auto",children:e.jsx("code",{children:r})})]})},pre:({children:s})=>e.jsx(e.Fragment,{children:s}),table:({children:s})=>e.jsx("div",{className:"my-3 overflow-x-auto rounded-lg border border-edge/30",children:e.jsx("table",{className:"w-full text-[12.5px]",children:s})}),thead:({children:s})=>e.jsx("thead",{className:"bg-[rgba(0,0,0,0.1)]",children:s}),th:({children:s})=>e.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-fg-3 border-b border-edge/30",children:s}),td:({children:s})=>e.jsx("td",{className:"px-3 py-1.5 text-fg-4 border-t border-edge/12",children:s}),tr:({children:s})=>e.jsx("tr",{className:"even:bg-[rgba(255,255,255,0.015)]",children:s})}}Gt();function ct(t){return!!t?.steps?.length}function gr(t,n){let s=t;for(const[l,r]of Object.entries(n))s=s.replace(new RegExp(`\\{${l}\\}`,"g"),r);return s}function mr({status:t}){return t==="completed"?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):t==="inProgress"?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-400 animate-pulse"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/25"})}function Yn({plan:t,t:n,className:s}){const[l,r]=o.useState(!1);if(!ct(t))return null;const c=t.steps.length,x=t.steps.filter(b=>b.status==="completed").length,d=c>0&&x===c,g=gr(n("hub.planProgress"),{done:String(x),total:String(c)});return e.jsx(at,{open:l,onToggle:()=>r(b=>!b),dot:{color:d?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!d},label:g,preview:t.explanation?e.jsx("span",{className:"text-[11.5px] text-fg-4 truncate",children:t.explanation}):void 0,badge:e.jsx("span",{className:L("rounded-md border px-1.5 py-0.5 text-[10px] font-mono",d?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(d?"hub.planDone":"hub.planInProgress")}),className:s,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-1",children:t.steps.map((b,m)=>{const j=b.status==="completed"?"text-fg-5 line-through decoration-fg-5/40":b.status==="inProgress"?"text-fg-3":"text-fg-4";return e.jsxs("div",{className:"flex items-center gap-2 py-[2px]",children:[e.jsx("span",{className:"shrink-0 flex items-center justify-center w-[10px]",children:e.jsx(mr,{status:b.status})}),e.jsx("span",{className:L("text-[12px] leading-[1.5]",j),children:b.step})]},`${m}:${b.step}`)})})})}function Xn({url:t,fileName:n,fileSize:s,caption:l}){return e.jsxs("div",{className:"flex flex-col gap-1 max-w-[340px]",children:[e.jsxs("a",{href:t,download:n,target:"_blank",rel:"noreferrer",title:l||n,className:L("group inline-flex items-center gap-2.5 rounded-md no-underline","border border-fg-6/40 bg-fg-6/[0.05] px-3 py-2","hover:bg-fg-6/[0.12] hover:border-fg-6/60 transition-colors"),children:[e.jsx("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded bg-fg-6/10 text-fg-3",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12.5px] font-medium text-fg-2",children:n}),typeof s=="number"&&s>0&&e.jsx("span",{className:"block text-[11px] text-fg-5/70",children:Kn(s)})]}),e.jsx("span",{className:"shrink-0 text-fg-5/50 group-hover:text-fg-3 transition-colors",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),l&&e.jsx("span",{className:"px-0.5 text-[11.5px] leading-[1.55] text-fg-4 break-words",children:l})]})}function Zn(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
11
- `).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||ct(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function No(t){return Zn(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function br(t){return t.phase!=="done"||!t.error?null:Zn(t)?"hub.streamErrored":"hub.streamFailed"}function vr({detail:t,t:n,className:s}){const l=Qs(t);if(l==="interrupted")return e.jsxs("div",{className:L("flex items-center gap-1.5 text-[11px] text-fg-5/55",s),children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-[2px] bg-fg-5/45 shrink-0"}),e.jsx("span",{children:n("hub.turnStopped")})]});const r=l==="error"?{dot:"bg-rose-400/55",text:"text-rose-300/65"}:{dot:"bg-fg-5/40",text:"text-fg-5/55"};return e.jsxs("div",{className:L("flex items-start gap-1.5 text-[11px] leading-[1.6]",r.text,s),children:[e.jsx("span",{className:L("mt-[5px] h-1 w-1 rounded-full shrink-0",r.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const jr=64;function wr(t,n){const[s,l]=o.useState(t),r=o.useRef(0),c=o.useRef(null);return o.useEffect(()=>{if(n<=0)return;const x=Date.now()-r.current,d=()=>{r.current=Date.now(),l(t)};return x>=n?d():(c.current&&clearTimeout(c.current),c.current=window.setTimeout(d,n-x)),()=>{c.current&&clearTimeout(c.current)}},[t,n]),n<=0?t:s}function So({stream:t,t:n,workdir:s}){const l=ct(t.plan),[r,c]=o.useState(!1),[x,d]=o.useState(!1),g=o.useRef(null),b=o.useRef(null),m=br(t),j=o.useMemo(()=>(t.activity||"").split(`
12
- `).filter(Boolean),[t.activity]),C=t.previewMeta?.toolCalls??[],y=j[j.length-1]||C[C.length-1]?.summary||"",B=C.length,A=t.previewMeta?.contextPercent??null,W=t.previewMeta?.contextUsedTokens??0,$=t.previewMeta?.turnOutputTokens??0,U=t.phase==="streaming",z=U&&t.startedAt!=null&&t.startedAt>0,Q=U;o.useLayoutEffect(()=>{const S=g.current;S&&r&&(S.scrollTop=S.scrollHeight)},[r,t.activity,C.length]),o.useLayoutEffect(()=>{const S=b.current;S&&x&&(S.scrollTop=S.scrollHeight)},[x,t.thinking]);const T=t.subAgents??null,K=wr(t.text,t.phase==="streaming"?jr:0),P=o.useMemo(()=>Gt({workdir:s}),[s]),O=o.useMemo(()=>e.jsx(gn,{remarkPlugins:vn,components:P,children:K}),[K,P]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[l&&e.jsx(Yn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),T&&T.length>0&&T.map(S=>e.jsx(es,{sub:S,t:n},S.id)),(C.length>0||j.length>0)&&e.jsx(at,{open:r,onToggle:()=>c(S=>!S),dot:{color:"bg-cyan-400/60",pulse:!0},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[12px] text-fg-4 truncate",children:e.jsx(Re,{text:y,workdir:s})}),badge:(C.length||j.length)>1?e.jsx(pn,{children:C.length||j.length}):void 0,children:e.jsx("div",{ref:g,className:"px-3.5 py-2.5 space-y-0.5 max-h-[280px] overflow-y-auto",children:C.length>0?C.map(S=>e.jsx(kr,{call:S,workdir:s},S.id)):j.map((S,E)=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate",children:e.jsx(Re,{text:S,workdir:s})})]},E))})}),t.thinking&&e.jsx(at,{open:x,onToggle:()=>d(S=>!S),dot:{color:"bg-violet-400/50",pulse:!0},label:n("hub.thinking"),collapsedContent:e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:zn(t.thinking,3)}),children:e.jsx("div",{ref:b,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[280px] overflow-y-auto",children:t.thinking})}),t.text&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:O}),t.artifacts&&t.artifacts.length>0&&e.jsx("div",{className:"flex flex-col gap-2",children:t.artifacts.map((S,E)=>S.kind==="photo"?e.jsx("a",{href:S.url,target:"_blank",rel:"noreferrer",className:"inline-block",children:e.jsx("img",{src:S.url,alt:S.caption||S.fileName,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain hover:opacity-90 transition-opacity"})},E):e.jsx(Xn,{url:S.url,fileName:S.fileName,fileSize:S.fileSize,caption:S.caption},E))}),t.phase==="streaming"&&(t.generatingImages??0)>0&&e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-fg-4",children:[e.jsxs("span",{className:"relative inline-flex items-center justify-center w-3 h-3",children:[e.jsx("span",{className:"absolute inline-flex w-3 h-3 rounded-full bg-cyan-400/40 animate-ping"}),e.jsx("span",{className:"relative inline-block w-1.5 h-1.5 rounded-full bg-cyan-400/80"})]}),e.jsx("span",{children:t.generatingImages===1?"Generating image…":`Generating ${t.generatingImages} images…`})]}),Q&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-mono text-fg-5/50 tabular-nums",children:[e.jsx(Jn,{className:"text-fg-5/45 shrink-0"}),e.jsx(yr,{toolCount:B,ctxPct:A,ctxTokens:W,turnOutTokens:$,startedAt:z?t.startedAt:null})]}),m&&t.error&&e.jsx(vr,{detail:t.error,t:n,className:"pt-0.5"})]})}function kr({call:t,workdir:n}){const[s,l]=o.useState(!1),r=!!(t.input||t.result),c=t.status==="failed"?"bg-rose-400/70":t.status==="running"?"bg-cyan-400/70":"bg-fg-5/30";return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>r&&l(x=>!x),className:`flex w-full items-center gap-1.5 py-[2px] text-left min-w-0 ${r?"cursor-pointer hover:bg-white/[0.03] rounded":"cursor-default"}`,title:r?void 0:t.summary,children:[e.jsx("span",{className:`w-1 h-1 rounded-full shrink-0 ${c} ${t.status==="running"?"animate-pulse":""}`}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate flex-1",children:e.jsx(Re,{text:t.summary,workdir:n})}),r&&e.jsx("span",{className:`shrink-0 text-[9px] text-fg-5/40 transition-transform ${s?"rotate-90":""}`,children:"▸"})]}),s&&e.jsxs("div",{className:"ml-2.5 mt-0.5 mb-1 space-y-1 border-l border-white/[0.06] pl-2.5",children:[t.input&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-4/80 max-h-[140px] overflow-y-auto",children:e.jsx(Re,{text:t.input,workdir:n})}),t.result&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-5/70 max-h-[140px] overflow-y-auto border-t border-white/[0.04] pt-1",children:e.jsx(Re,{text:t.result,workdir:n})})]})]})}function Jn({className:t}){return e.jsxs("span",{className:`thinking-dots inline-flex items-center gap-[3px] ${t||""}`,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}function yr({toolCount:t,ctxPct:n,ctxTokens:s,turnOutTokens:l,startedAt:r}){const c=[];return t>0&&c.push(e.jsxs("span",{className:"flex items-center gap-1 text-fg-5/55",title:`${t} tool ${t===1?"call":"calls"} this turn`,children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M22 12h-4l-3 9L9 3l-3 9H2"})}),t]},"ops")),n!=null&&c.push(e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Un(n)}`}),n.toFixed(1),"%"]},"ctx")),s>0&&c.push(e.jsx("span",{className:"text-fg-5/40",children:Fn(s)},"tok")),l>0&&c.push(e.jsxs("span",{className:"text-fg-5/40",children:["↑",bn(l)]},"out")),r!=null&&c.push(e.jsx(Nr,{startedAt:r},"elapsed")),c.length?e.jsx("span",{className:"shrink-0 flex items-center gap-1.5",children:c.map((x,d)=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[d>0&&e.jsx("span",{className:"text-fg-5/25",children:"·"}),x]},d))}):null}function Nr({startedAt:t}){const[,n]=o.useState(0);o.useEffect(()=>{const l=setInterval(()=>n(r=>r+1),1e3);return()=>clearInterval(l)},[]);const s=Math.max(0,Date.now()-t);return e.jsx("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:qs(s)})}function es({sub:t,t:n}){const[s,l]=o.useState(!1),r=t.status,c=r==="failed"?"bg-rose-400/60":r==="done"?"bg-emerald-400/55":"bg-amber-400/60",x=r==="running",d=t.tools,g=o.useMemo(()=>{const j=new Set,C=[];for(const y of d)j.has(y.name)||(j.add(y.name),C.push(y.name));return C},[d]),b=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",m=t.model?Ft(t.model):null;return e.jsx(at,{open:s,onToggle:()=>l(j=>!j),dot:{color:c,pulse:x},label:b,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),m&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:m}),!t.description&&g.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:g.join(" · ")})]}),badge:d.length>0?e.jsx(pn,{children:d.length}):void 0,children:e.jsxs("div",{className:"px-3.5 py-2.5 space-y-1 max-h-[260px] overflow-y-auto",children:[t.description&&e.jsx("div",{className:"mb-1.5 text-[12px] text-fg-3 leading-[1.55]",children:t.description}),d.length===0?e.jsxs("div",{className:"text-[11px] font-mono text-fg-5/50",children:["— ",n("hub.subAgentWaiting")||"waiting for first tool…"]}):d.map(j=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/65 truncate",children:j.summary})]},j.id))]})})}function Sr({message:t,t:n,workdir:s}){const{activityBlocks:l,thinkingBlocks:r,planBlocks:c,subAgentBlocks:x,outputBlocks:d,noticeBlocks:g}=ts(t.blocks),b=[...c].reverse().find(j=>ct(j.plan));return l.length>0||x.length>0||!!b?.plan||r.length>0||d.length>0||g.length>0?e.jsxs("div",{className:"space-y-3",children:[l.length>0&&e.jsx(Ir,{blocks:l,t:n,workdir:s}),x.map(j=>j.subAgent?e.jsx(es,{sub:j.subAgent,t:n},j.toolId||j.subAgent.id):null),b?.plan&&e.jsx(Yn,{plan:b.plan,t:n,className:"max-w-[760px]"}),r.length>0&&e.jsx(Er,{blocks:r,t:n}),d.length>0&&e.jsx(Pr,{blocks:d,t:n,workdir:s}),g.length>0&&e.jsx(Lr,{blocks:g,t:n})]}):null}function Cr(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:l,subAgentBlocks:r,outputBlocks:c,noticeBlocks:x}=ts(t.blocks);return c.length>0||n.length>0||r.length>0||s.length>0||l.some(d=>ct(d.plan))||x.length>0}function ts(t){const n=t.filter(s=>s.type==="plan"||s.type==="tool_use"||s.type==="tool_result"||s.type==="image"||s.type==="file"||s.type==="sub_agent"||!!s.content.trim());return{activityBlocks:n.filter(s=>s.type==="tool_use"||s.type==="tool_result"),thinkingBlocks:n.filter(s=>s.type==="thinking"),planBlocks:n.filter(s=>s.type==="plan"&&ct(s.plan)),subAgentBlocks:n.filter(s=>s.type==="sub_agent"),outputBlocks:n.filter(s=>s.type==="text"||s.type==="image"||s.type==="file"),noticeBlocks:n.filter(s=>s.type==="system_notice")}}function Lr({blocks:t,t:n}){const s=t.map(l=>l.content).filter(Boolean).join(`
8
+ `).map(l=>l.trim()).find(Boolean)||"";return s?Z(s,140):"result"}function er(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),l=t.slice(n+1).trim();return!s||!l?null:{agent:s,sessionId:l}}const gt=new Map;function tr(t,n){return`${t}:${n}`}const nr=[],sr=[],rr={};function or(t){const n=(()=>{try{return new URL(t.baseURL).host.toLowerCase()}catch{return""}})();return n.includes("openrouter")?"openrouter":n.includes("anthropic")?"anthropic":n.includes("deepseek")?"deepseek":n.includes("googleapis")||n.includes("vertex")?"google":n.includes("openai.com")?"openai":n.includes("dashscope")||n.includes("qwen")||n.includes("aliyun")?"qwen":n.includes("volces")||n.includes("volcengine")||n.includes("doubao")?"doubao":n.includes("bigmodel")||n.includes("zhipu")||n.includes("z.ai")?"glm":n.includes("minimax")?"minimax":t.kind==="anthropic"?"anthropic":t.kind==="google"?"google":t.kind==="openai"?"openai":"custom"}const ir=o.memo(function({session:n,workdir:s,onStreamQueued:l,onSendStart:r,onSendTaskAssigned:c,onSessionChange:x,t:d,streamPhase:m,streamTaskId:b,queuedTaskIds:g,queuedTasks:v,pendingQueuedSends:k,onRecall:y,onSteer:B,onStopAll:A,editDraft:W,onEditDraftConsumed:$,onSelectionChange:U}){const[z,Q]=o.useState(""),[T,K]=o.useState(!1),[P,O]=o.useState(null),[C,M]=o.useState(()=>new Set),[ue,ie]=o.useState(()=>new Set),q=o.useRef({prompt:"",files:[]}),Se=oe(a=>a.agentStatus?.agents??null),[H,mt]=o.useState(Se||[]),[fe,dt]=o.useState(""),[He,Ve]=o.useState(""),[J,_e]=o.useState(void 0),[We,Ge]=o.useState(""),[ee,Be]=o.useState([]),[ge,qe]=o.useState(null),[Ce,bt]=o.useState(null),[me,le]=o.useState(null),[Qe,Le]=o.useState(null),[vt,Ie]=o.useState(null),[se,be]=o.useState(void 0),[E,he]=o.useState("closed"),[Y,jt]=o.useState(null),Te=o.useRef(null),Ye=o.useRef(!1),$e=o.useRef(null),qt=o.useRef(null),xe=o.useRef(null),ve=o.useRef([]),[je,wt]=o.useState([]),[ae,Oe]=o.useState(!1),[Xe,Ze]=o.useState(0),Je=o.useRef(null),Me=oe(a=>a.refreshAgentStatus),we=oe(a=>a.modelLayer),De=oe(a=>a.ensureModelLayer),ut=oe(a=>a.refreshModelLayer),ce=we?.providers??nr,et=we?.profiles??sr,tt=we?.activeProfiles??rr;o.useEffect(()=>{De()},[De]),o.useEffect(()=>{Se?.length&&mt(Se)},[Se]),o.useEffect(()=>{ve.current=ee},[ee]);const re=tr(n.agent||"",n.sessionId),Ee=o.useRef(re);Ee.current=re,o.useEffect(()=>{const a=gt.get(re);return a&&(gt.delete(re),a.text&&Q(a.text),a.files.length&&Be(a.files.map(ln))),()=>{const f=Te.current?.value||"",j=ve.current.map(I=>I.file);for(const I of ve.current)URL.revokeObjectURL(I.previewUrl);f||j.length?gt.set(Ee.current,{text:f,files:j}):gt.delete(Ee.current)}},[re]);const kt=o.useRef({agent:n.agent||"",sessionId:n.sessionId});o.useEffect(()=>{const a=kt.current,f={agent:n.agent||"",sessionId:n.sessionId};kt.current=f,!(a.agent===f.agent&&Dt(a.sessionId)&&!Dt(f.sessionId))&&(dt(""),Ve(""),_e(void 0),Ge(""),le(null),Le(null),Ie(null),he("closed"))},[n.agent,n.sessionId]),o.useEffect(()=>{W!=null&&(Q(W),$?.(),requestAnimationFrame(()=>{const a=Te.current;a&&(a.focus(),a.setSelectionRange(W.length,W.length))}))},[W,$]),o.useEffect(()=>{if(!s)return;let a=!1;return ne.getSkills(s).then(f=>{!a&&f.ok&&wt(f.skills)}).catch(()=>{}),()=>{a=!0}},[s]);const ht=ae?(()=>{const a=z.match(/^\/(\S*)$/);return a?a[1].toLowerCase():null})():null,ke=ht!==null?je.filter(a=>a.name.toLowerCase().includes(ht)||a.label&&a.label.toLowerCase().includes(ht)):[];o.useEffect(()=>{Ze(0)},[ae,z]),o.useEffect(()=>{if(!ae||!Je.current)return;const a=Je.current.querySelector(`[data-skill-idx="${Xe}"]`);a&&a.scrollIntoView({block:"nearest"})},[Xe,ae]),o.useEffect(()=>{if(!ae)return;const a=f=>{Je.current?.contains(f.target)||Te.current?.contains(f.target)||Oe(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[ae]),o.useEffect(()=>{if(E==="closed")return;const a=f=>{const j=f.target;xe.current?.contains(j)||document.getElementById("cascade-portal")?.contains(j)||(he("closed"),le(null),Le(null),Ie(null))};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[E]),o.useLayoutEffect(()=>{if(E==="closed"||!xe.current){jt(null);return}const a=xe.current.getBoundingClientRect();jt({left:a.left,bottom:window.innerHeight-a.top+8})},[E]);const yt=g&&g.length?g[0]:null;o.useEffect(()=>{P&&(yt||m!==null&&m!=="queued")&&O(null)},[m,P,yt]),o.useEffect(()=>{const a=Te.current;a&&(a.style.height="auto",a.style.height=Math.min(a.scrollHeight,200)+"px")},[z]);const xt=o.useCallback(a=>{const f=Array.from(a||[]).filter(j=>j.type.startsWith("image/"));f.length&&Be(j=>[...j,...f.map(ln)])},[]),Nt=o.useCallback(()=>{qe(null),Be(a=>(Ys(a),[]))},[]),St=o.useCallback(a=>{Be(f=>{const j=f.find(I=>I.id===a);return j&&URL.revokeObjectURL(j.previewUrl),f.filter(I=>I.id!==a)}),qe(f=>f===a?null:f)},[]),Ct=o.useCallback(()=>{const a=z.trim(),f=ee.map(X=>X.file);if(!a&&f.length===0||T)return;const j=fe||n.agent||H.find(X=>X.isDefault)?.agent||"";if(!j)return;const I=H.find(X=>X.agent===j)||null,V=!!n.agent&&j===n.agent,ye=(He||V&&n.model||""||I?.selectedModel||"").trim()||null,rt=J!==void 0?J:V&&n.model?n.profileId??null:void 0,ot=j==="gemini"?null:(We||(V?Et(j,n.thinkingEffort,n.workflowEnabled):"")||Et(j,I?.selectedEffort,I?.workflowEnabled)||"").trim()||null,te=j!==n.agent,sn=te?"":n.sessionId,gs=te&&n.agent?n.agent:null,ms=te&&n.sessionId?n.sessionId:null;K(!0),q.current={prompt:a,files:f},Q(""),gt.delete(Ee.current);const bs=f.length?f.map(X=>URL.createObjectURL(X)):void 0;Nt(),r(a,bs),l(),ne.sendSessionMessage(s,j,sn,a,{attachments:f,model:ye,profileId:rt,effort:ot,previousAgent:gs,previousSessionId:ms}).then(X=>{if(X.taskId&&(O(X.taskId),c?.(X.taskId)),!X.ok)return;const ft=typeof X.sessionKey=="string"?er(X.sessionKey):null;ft&&(ft.agent!==n.agent||ft.sessionId!==n.sessionId)&&ft&&x?.({...ft,workdir:s})}).catch(()=>{}).finally(()=>K(!1))},[H,Nt,ee,z,r,c,x,l,fe,We,He,J,T,n.agent,n.sessionId,n.model,n.profileId,s]),Lt=m==="streaming",de=Us({queuedTaskIds:g,streamPhase:m,streamTaskId:b,localTaskId:P}),It=de[de.length-1]||null,pt=de.length>0,Qt=pt||Lt;o.useEffect(()=>{const a=f=>de.includes(f)||f===b;M(f=>{let j=!1;const I=new Set;for(const V of f)a(V)?I.add(V):j=!0;return j?I:f}),ie(f=>{let j=!1;const I=new Set;for(const V of f)a(V)?I.add(V):j=!0;return j?I:f})},[de,b]),o.useEffect(()=>{!pt&&q.current.files.length&&(q.current={prompt:"",files:[]})},[pt]);const Yt=o.useCallback(a=>{if(!C.has(a)){if(M(f=>{const j=new Set(f);return j.add(a),j}),a===It){const f=q.current;f.prompt&&Q(f.prompt),f.files.length&&Be(f.files.map(ln)),q.current={prompt:"",files:[]}}y?.(a),a===P&&O(null)}},[C,It,P,y]),[nt,i]=o.useState(!1),h=o.useCallback(async()=>{if(!(nt||!A)){i(!0);try{await A()}finally{i(!1)}}},[nt,A]),u=o.useCallback(a=>{ue.has(a)||(ie(f=>{const j=new Set(f);return j.add(a),j}),B?.(a),a===P&&O(null))},[ue,P,B]),p=o.useCallback(a=>{Q(`/${a.name} `),Oe(!1),requestAnimationFrame(()=>{const f=Te.current;f&&(f.focus(),f.setSelectionRange(f.value.length,f.value.length))})},[]),w=o.useCallback(a=>{Q(a);const f=/^\/\S*$/.test(a)&&je.length>0;Oe(f)},[je.length]),N=a=>{if(ae&&ke.length>0){if(a.key==="ArrowDown"){a.preventDefault(),Ze(f=>(f+1)%ke.length);return}if(a.key==="ArrowUp"){a.preventDefault(),Ze(f=>(f-1+ke.length)%ke.length);return}if(a.key==="Tab"||a.key==="Enter"&&!a.shiftKey&&!Ye.current){a.preventDefault(),p(ke[Xe]);return}if(a.key==="Escape"){a.preventDefault(),Oe(!1);return}}a.key==="Enter"&&!a.shiftKey&&!Ye.current&&(a.preventDefault(),Ct())},S=o.useCallback(a=>{const f=Array.from(a.clipboardData?.items||[]).filter(j=>j.kind==="file"&&j.type.startsWith("image/")).map(j=>j.getAsFile()).filter(j=>!!j);f.length&&(a.preventDefault(),xt(f))},[xt]),R=fe||n.agent||H.find(a=>a.isDefault)?.agent||H.find(a=>a.installed)?.agent||H[0]?.agent||"",F=H.find(a=>a.agent===R)||null,_=me||R,D=H.find(a=>a.agent===_)||F,Ae=o.useMemo(()=>{if(!D)return[];const a=[];for(const j of D.models||[])a.push({id:j.id,label:j.id,kind:"native",description:j.alias&&j.alias.toLowerCase()!==j.id.toLowerCase()?j.alias:void 0});const f=new Set(vs[_]||[]);for(const j of et){const I=ce.find(ye=>ye.id===j.providerId);if(!I||!f.has(I.kind))continue;const V=j.name.trim().toLowerCase()!==j.modelId.trim().toLowerCase();a.push({id:j.modelId,label:j.name,kind:"profile",profileId:j.id,description:V?`${I.name} · ${j.modelId}`:I.name})}return a},[D,_,et,ce]),kn=o.useMemo(()=>Ae.findIndex(a=>a.kind==="profile"),[Ae]),ls=tt[_]||null,Xt=!!n.agent&&R===n.agent,Tt=J!==void 0?J:Xt?n.profileId??null:void 0,Mt=He||Xt&&n.model||""||F?.selectedModel||"",Zt=R==="gemini"?"":We||(Xt?Et(R,n.thinkingEffort,n.workflowEnabled):"")||Et(R,F?.selectedEffort,F?.workflowEnabled)||"";o.useEffect(()=>{U?.({model:Mt||null,effort:Zt||null})},[Mt,Zt,U]);const as=F?.effortOptions??[],Fe=ge&&ee.find(a=>a.id===ge)||null,cs=Fe?{key:Fe.id,url:Fe.previewUrl,name:Fe.file.name,size:Fe.file.size,file:Fe.file,onRemove:()=>St(Fe.id)}:Ce?{key:Ce,url:Ce}:null,yn=(!!z.trim()||ee.length>0)&&!T&&!!R,Jt=()=>{le(null),Le(null),Ie(null),be(void 0)},Nn=o.useCallback((a,f)=>{dt(a),Ve(f),se!==void 0&&_e(se),a!==R&&Ge(""),Jt(),he("closed")},[se,R]),ds=o.useCallback(a=>{Ge(a),Ie(null)},[]),us=()=>{E==="closed"?(Jt(),Me(),ut(),he("agent")):(Jt(),he("closed"))},en=me||R,Sn=cn(en),tn=Qe??Mt,hs=vt??Zt,xs=tn?Ft(tn):"",Ue=(()=>{const a=!me&&Tt!==void 0?Tt:tt[en]??null;return a?et.find(f=>f.id===a)??null:null})(),st=Ue?ce.find(a=>a.id===Ue.providerId)??null:null,ps=st?or(st):null,nn=Ue?Ue.name.trim().toLowerCase()!==Ue.modelId.trim().toLowerCase()?Ue.name:Ft(Ue.modelId):xs,fs=[Sn.shortLabel,st?st.name:null,nn||null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:qt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[Qt&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[Lt&&e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-primary/20 bg-primary/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx(pe,{className:"h-3 w-3 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-[12px] font-medium text-fg-3 truncate",children:d("hub.running")}),e.jsxs("button",{onClick:h,disabled:nt,title:d("hub.stopHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none shrink-0",children:[nt?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),d("hub.stop")]})]}),de.map((a,f)=>{const j=f===de.length-1,I=ue.has(a),V=I?d("hub.steering"):de.length>1?`${d("hub.queued")} #${f+1}`:d("hub.queued"),ye=k?.find(te=>te.taskId===a)||(j?k?.find(te=>!te.taskId):void 0),rt=v?.find(te=>te.taskId===a)?.prompt||ye?.prompt||null,ot=ye?.imageUrls?.length?ye.imageUrls:[];return e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-warn/25 bg-warn/[0.04] px-3.5 py-1.5 transition-colors",children:[I?e.jsx(pe,{className:"h-3 w-3 text-warn shrink-0"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-warn animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-warn shrink-0",children:V}),ot.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[ot.slice(0,3).map((te,sn)=>e.jsx("button",{type:"button",onClick:()=>bt(te),title:d("hub.previewImage"),className:"block h-5 w-5 shrink-0 overflow-hidden rounded border border-warn/30 transition-opacity hover:opacity-80",children:e.jsx("img",{src:te,alt:"",className:"h-full w-full object-cover"})},`${te}-${sn}`)),ot.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",ot.length-3]})]}),rt&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:rt})]}),!I&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>u(a),title:d("hub.steerHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-blue-400 hover:bg-blue-400/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),d("hub.steer")]}),e.jsxs("button",{onClick:()=>Yt(a),disabled:C.has(a),title:d("hub.recallHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[C.has(a)?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]}),d("hub.recall")]})]})]},a)})]}),e.jsxs("div",{className:"relative rounded-xl border border-edge/40 bg-panel shadow-sm transition-[border-color,box-shadow] duration-200 focus-within:border-fg-5/40 focus-within:shadow-md",children:[e.jsx("input",{ref:$e,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:a=>{xt(a.target.files),a.target.value=""}}),ee.length>0&&e.jsx("div",{className:"px-4 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:ee.map(a=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>qe(a.id),title:d("hub.previewImage"),className:"group relative h-[72px] w-[72px] overflow-hidden rounded-lg border border-edge/30 bg-panel-alt/30",children:[e.jsx("img",{src:a.previewUrl,alt:a.file.name,className:"h-full w-full object-cover transition-transform duration-200 group-hover:scale-[1.03]"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent px-1.5 pb-1 pt-3 text-left",children:e.jsx("div",{className:"truncate text-[8px] font-medium text-white/90 leading-tight",children:a.file.name})})]}),e.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),St(a.id)},title:d("hub.removeImage"),className:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-black/65 text-white/75 transition-colors hover:bg-black/80 hover:text-white",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]},a.id))})}),ae&&ke.length>0&&e.jsxs("div",{ref:Je,className:"absolute bottom-full left-0 right-0 mb-1.5 z-50 max-h-[200px] overflow-y-auto rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg animate-in",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-edge/20",children:e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d("hub.skills")})}),e.jsx("div",{className:"py-1",children:ke.map((a,f)=>e.jsxs("button",{"data-skill-idx":f,onMouseDown:j=>{j.preventDefault(),p(a)},onMouseEnter:()=>Ze(f),className:L("flex flex-col w-full px-3 py-1.5 text-left transition-colors",f===Xe?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",a.name]}),(a.label||a.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:a.label||a.description})]},a.name))})]}),e.jsx("textarea",{ref:Te,value:z,onChange:a=>w(a.target.value),onPaste:S,onKeyDown:N,onCompositionStart:()=>{Ye.current=!0},onCompositionEnd:()=>{Ye.current=!1},placeholder:d("hub.inputPlaceholder"),rows:1,className:"block w-full resize-none bg-transparent px-4 pt-3 pb-1 text-[13.5px] text-fg outline-none placeholder:text-fg-5/25 leading-[1.6]",style:{maxHeight:200,overflow:z.split(`
9
+ `).length>6?"auto":"hidden"}}),e.jsxs("div",{className:"flex items-center gap-1 px-2.5 pb-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>$e.current?.click(),title:d("hub.addImages"),className:"flex h-7 w-7 items-center justify-center rounded-lg text-fg-5/50 transition-colors hover:bg-panel-h/60 hover:text-fg-3",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})}),e.jsxs("button",{ref:xe,onClick:us,disabled:!H.length,title:H.length?fs:void 0,className:L("flex items-center gap-1 h-[28px] pl-2 pr-0.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",E!=="closed"?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[H.length?e.jsx(lt,{brand:en,size:12}):e.jsx(pe,{className:"h-3 w-3"}),H.length?e.jsxs("span",{className:"flex items-center gap-1 max-w-[460px] min-w-0 truncate",children:[e.jsx("span",{className:"shrink-0",children:Sn.shortLabel}),st&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(lt,{brand:ps||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:st.name})]}),nn&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:tn||void 0,children:nn})]})]}):e.jsx("span",{className:"max-w-[420px] truncate",children:d("hub.selectAgent")}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:L("text-fg-5/30 transition-transform duration-200",E!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),E!=="closed"&&Y&&fn.createPortal(e.jsxs("div",{id:"cascade-portal",className:"fixed z-[200] w-[300px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in",style:{left:Y.left,bottom:Y.bottom},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5 border-b border-edge/20",children:[E!=="agent"&&e.jsx("button",{onClick:()=>he("agent"),className:"p-0.5 rounded text-fg-5/50 hover:text-fg-3 transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d(E==="agent"?"hub.selectAgent":"hub.selectModel")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const f=D?.capabilities?.modelSwitch!==!1?["agent","model"]:["agent"],j=f.indexOf(E);return f.map((I,V)=>e.jsx("span",{className:L("w-1.5 h-1.5 rounded-full transition-colors",E===I?"bg-primary":V<j?"bg-primary/40":"bg-fg-5/15")},I))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[E==="agent"&&H.filter(a=>a.installed).map(a=>{const f=cn(a.agent),j=js(a.usage),I=j?ws(j):"ok";return e.jsxs(dn,{selected:a.agent===(me||R),onClick:()=>{if(le(a.agent),Le(a.selectedModel||""),Ie(a.selectedEffort||""),!(a.capabilities?.modelSwitch!==!1)){Nn(a.agent,a.selectedModel||"");return}he("model")},children:[e.jsx(lt,{brand:a.agent,size:14}),e.jsx("span",{style:{color:f.color},children:f.label}),j&&e.jsxs("span",{className:L("ml-auto font-mono text-[10px]",I==="err"?"text-err":I==="warn"?"text-warn":"text-fg-5"),children:[j.label," ",Math.round(j.usedPercent??0),"%"]})]},a.agent)}),E==="model"&&e.jsxs(e.Fragment,{children:[Ae.map((a,f)=>{const j=f===0&&a.kind==="native",I=f===kn&&a.kind==="profile",V=se!==void 0?se:_===R&&Tt!==void 0?Tt:ls,ye=a.kind==="profile"?!!a.profileId&&a.profileId===V:!V&&a.id===(Qe??Mt);return e.jsxs("div",{children:[j&&e.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupNative")}),I&&e.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupProfiles")}),e.jsx(dn,{selected:ye,onClick:()=>{const rt=me||R;Le(a.id),be(a.profileId??null),Nn(rt,a.id)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:L("truncate text-[11.5px]",a.kind==="native"&&"font-mono text-[11px]"),title:a.id,children:a.label}),a.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:a.description})]})})]},`${a.kind}:${a.profileId||a.id}`)}),Ae.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]})]})]}),document.body),e.jsx(ar,{current:hs,options:as,onSelect:ds,label:d("hub.selectEffort")}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:Ct,disabled:!yn,className:L("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",yn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:T?e.jsx(pe,{className:"h-3.5 w-3.5"}):e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})]}),e.jsx(lr,{source:cs,onClose:()=>{qe(null),bt(null)},t:d})]})});function lr({source:t,onClose:n,t:s}){const[l,r]=o.useState(!1);if(o.useEffect(()=>{r(!1)},[t?.key]),o.useEffect(()=>{if(!t)return;const d=m=>{m.key==="Escape"&&n()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[t,n]),!t)return null;const c=t.file,x=t.onRemove;return fn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center bg-black/72 px-4 py-6 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[1024px]",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-[11px] text-white/72",children:[t.name&&e.jsx("span",{className:"truncate font-medium text-white/90",children:t.name}),typeof t.size=="number"&&e.jsx("span",{children:Kn(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await Xs(c)&&(r(!0),window.setTimeout(()=>r(!1),1600))},className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s(l?"hub.copied":"hub.copyImage")}),x&&e.jsx("button",{type:"button",onClick:x,className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s("hub.removeImage")}),e.jsx("button",{type:"button",onClick:n,className:"flex h-9 w-9 items-center justify-center rounded-full border border-white/12 bg-white/10 text-white/88 transition-colors hover:bg-white/14",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-white/10 bg-black/35 shadow-[0_20px_70px_rgba(0,0,0,0.45)]",children:e.jsx("img",{src:t.url,alt:t.name||"",className:"max-h-[80vh] w-full object-contain"})})]})}),document.body)}function dn({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:L("flex items-center gap-2 w-full px-3 py-2 text-[12px] text-left transition-colors",t?"text-fg bg-panel-h font-medium":"text-fg-3 hover:bg-panel-alt/50 hover:text-fg-2"),children:[s,t&&e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"ml-auto text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),!t&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"ml-auto text-fg-5/20",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})})]})}function ar({current:t,options:n,onSelect:s,label:l}){const[r,c]=o.useState(!1),x=o.useRef(null);if(o.useEffect(()=>{if(!r)return;const k=y=>{x.current&&!x.current.contains(y.target)&&c(!1)};return document.addEventListener("mousedown",k),()=>document.removeEventListener("mousedown",k)},[r]),!n.length)return null;const d=n.find(k=>k.id===t)?.label||(t?t.charAt(0).toUpperCase()+t.slice(1):"—"),m=n.findIndex(k=>k.id===t),b=n.length>1&&m>=0?m/(n.length-1):.5,g=Math.round(-80+b*160),v=t==="ultra";return e.jsxs("div",{className:"relative shrink-0",ref:x,children:[e.jsxs("button",{type:"button",onClick:()=>c(k=>!k),title:l,className:L("flex items-center gap-1 h-[28px] pl-0.5 pr-2 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",r?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:v?"url(#effortUltraGrad)":"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[v&&e.jsx("defs",{children:e.jsxs("linearGradient",{id:"effortUltraGrad",x1:"2",y1:"20",x2:"22",y2:"6",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:"0%",stopColor:"#22d3ee"}),e.jsx("stop",{offset:"55%",stopColor:"#a855f7"}),e.jsx("stop",{offset:"100%",stopColor:"#fb7185"})]})}),e.jsx("path",{d:"M3.34 19a10 10 0 1 1 17.32 0"}),e.jsx("path",{d:"M12 14L12 7.5",transform:`rotate(${g} 12 14)`})]}),e.jsx("span",{className:L("shrink-0",v&&"bg-gradient-to-r from-cyan-400 via-purple-400 to-pink-400 bg-clip-text text-transparent font-semibold"),children:d}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:L("text-fg-5/30 transition-transform duration-200",r&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),r&&e.jsx("div",{className:"absolute bottom-full left-0 mb-1.5 z-[200] min-w-[150px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in py-1",children:n.map(k=>e.jsx(dn,{selected:k.id===t,onClick:()=>{s(k.id),c(!1)},children:k.label},k.id))})]})}function cr(){return function(t){Es(t)}}const vn=[As,cr],Vn=t=>/^https?:\/\//.test(t),dr=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function ur(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function Gn(t){let n=t.trim();const s=[["`","`"],['"','"'],["'","'"],["<",">"]];let l=!0;for(;l&&n.length>=2;){l=!1;for(const[r,c]of s)n.startsWith(r)&&n.endsWith(c)&&(n=n.slice(r.length,-c.length).trim(),l=!0)}return n}function jn(t){let n=Gn(t),s="";for(;n.length>1;){const l=n[n.length-1];if(!l||!/[),.;!?]/.test(l)||l==="."&&/^\.[A-Za-z0-9_-]+$/.test(n))break;s=l+s,n=n.slice(0,-1)}return{text:n,trailing:s}}function Ht(t){const n=jn(t).text;if(!n||Vn(n)||dr(n)&&!n.startsWith("file://"))return!1;const s=ur(n);if(!s)return!1;if(s.startsWith("file://"))return s.length>7;if(/^[A-Za-z]:[\\/]/.test(s))return!0;if(/^(\/|~\/|\.{1,2}\/)/.test(s))return s.length>1;if(s.includes("/")){const l=s.split("/")[0]||"";return!/^[A-Za-z0-9-]+\.[A-Za-z]{2,}$/.test(l)}return!1}function wn(t,n){ne.openInEditor(t,void 0,n||void 0).catch(()=>{})}function qn(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),t.stopPropagation(),wn(n,s))}const hr="text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",xr="underline decoration-dotted decoration-fg-5/40 underline-offset-2 cursor-pointer hover:text-blue-300 hover:decoration-blue-300/50 transition-colors";function Qn({locator:t,workdir:n,className:s,children:l}){return e.jsx("span",{role:"link",tabIndex:0,title:t,className:s??hr,onClick:r=>{r.stopPropagation(),wn(t,n)},onKeyDown:r=>qn(r,t,n),children:l??t})}function pr(t){const n=[];if(!t)return n;for(const s of t.split(/(\s+)/)){if(!s)continue;if(/^\s+$/.test(s)){n.push({type:"text",value:s});continue}const{text:l,trailing:r}=jn(s),c=Gn(l);c&&!c.endsWith("…")&&Ht(c)?(n.push({type:"link",locator:c,display:r?s.slice(0,s.length-r.length):s}),r&&n.push({type:"text",value:r})):n.push({type:"text",value:s})}return n}function Re({text:t,workdir:n,className:s}){const l=pr(t);return l.some(r=>r.type==="link")?e.jsx(e.Fragment,{children:l.map((r,c)=>r.type==="link"?e.jsx(Qn,{locator:r.locator,workdir:n,className:s??xr,children:r.display},c):e.jsx("span",{children:r.value},c))}):e.jsx(e.Fragment,{children:t})}function fr({text:t}){const[n,s]=o.useState(!1),l=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:l,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function In(t){const n=Ht(t),s=/^(npm |npx |git |python|pip |yarn |pnpm |cargo |go |make )/.test(t);return n?"bg-blue-500/8 border-blue-400/12 text-blue-300/90":s?"bg-amber-500/8 border-amber-400/10 text-amber-300/80":"bg-[rgba(255,255,255,0.06)] border-edge/20 text-fg-3"}function Gt(t={}){const n=t.workdir||null;return{h1:({children:s})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:s}),h2:({children:s})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:s}),h3:({children:s})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:s}),p:({children:s})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:s}),strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-fg",children:s}),em:({children:s})=>e.jsx("em",{className:"italic text-fg-3",children:s}),a:({href:s,children:l})=>s&&Vn(s)?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",children:l}):s&&Ht(s)?e.jsx(Qn,{locator:jn(s).text,workdir:n,children:l}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:l}),ul:({children:s})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:s}),ol:({children:s})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:s}),li:({children:s})=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"shrink-0 mt-[10px] w-[5px] h-[5px] rounded-full bg-fg-5/40"}),e.jsx("span",{className:"flex-1",children:s})]}),blockquote:({children:s})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:s}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:s,children:l})=>{const r=String(l).replace(/\n$/,""),c=/language-(\w+)/.exec(s||"");if(!c&&!s&&!r.includes(`
10
+ `))return Ht(r)?e.jsx("code",{role:"link",tabIndex:0,title:r,className:L("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",In(r)),onClick:()=>wn(r,n),onKeyDown:d=>qn(d,r,n),children:r}):e.jsx("code",{className:L("px-1.5 py-[1px] rounded text-[12px] font-mono border",In(r)),children:r});const x=c?.[1]||"";return e.jsxs("div",{className:"rounded-lg overflow-hidden border border-edge/30 bg-[rgba(0,0,0,0.25)] my-3 not-prose",children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-1.5 border-b border-edge/15 bg-[rgba(0,0,0,0.12)]",children:[e.jsx("span",{className:"text-[10px] font-mono text-fg-5/50",children:x||"text"}),e.jsx(fr,{text:r})]}),e.jsx("pre",{className:"px-3.5 py-3 text-[12px] leading-[1.65] text-fg-3 font-mono whitespace-pre-wrap break-words overflow-x-auto",children:e.jsx("code",{children:r})})]})},pre:({children:s})=>e.jsx(e.Fragment,{children:s}),table:({children:s})=>e.jsx("div",{className:"my-3 overflow-x-auto rounded-lg border border-edge/30",children:e.jsx("table",{className:"w-full text-[12.5px]",children:s})}),thead:({children:s})=>e.jsx("thead",{className:"bg-[rgba(0,0,0,0.1)]",children:s}),th:({children:s})=>e.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-fg-3 border-b border-edge/30",children:s}),td:({children:s})=>e.jsx("td",{className:"px-3 py-1.5 text-fg-4 border-t border-edge/12",children:s}),tr:({children:s})=>e.jsx("tr",{className:"even:bg-[rgba(255,255,255,0.015)]",children:s})}}Gt();function ct(t){return!!t?.steps?.length}function gr(t,n){let s=t;for(const[l,r]of Object.entries(n))s=s.replace(new RegExp(`\\{${l}\\}`,"g"),r);return s}function mr({status:t}){return t==="completed"?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):t==="inProgress"?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-400 animate-pulse"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/25"})}function Yn({plan:t,t:n,className:s}){const[l,r]=o.useState(!1);if(!ct(t))return null;const c=t.steps.length,x=t.steps.filter(b=>b.status==="completed").length,d=c>0&&x===c,m=gr(n("hub.planProgress"),{done:String(x),total:String(c)});return e.jsx(at,{open:l,onToggle:()=>r(b=>!b),dot:{color:d?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!d},label:m,preview:t.explanation?e.jsx("span",{className:"text-[11.5px] text-fg-4 truncate",children:t.explanation}):void 0,badge:e.jsx("span",{className:L("rounded-md border px-1.5 py-0.5 text-[10px] font-mono",d?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(d?"hub.planDone":"hub.planInProgress")}),className:s,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-1",children:t.steps.map((b,g)=>{const v=b.status==="completed"?"text-fg-5 line-through decoration-fg-5/40":b.status==="inProgress"?"text-fg-3":"text-fg-4";return e.jsxs("div",{className:"flex items-center gap-2 py-[2px]",children:[e.jsx("span",{className:"shrink-0 flex items-center justify-center w-[10px]",children:e.jsx(mr,{status:b.status})}),e.jsx("span",{className:L("text-[12px] leading-[1.5]",v),children:b.step})]},`${g}:${b.step}`)})})})}function Xn({url:t,fileName:n,fileSize:s,caption:l}){return e.jsxs("div",{className:"flex flex-col gap-1 max-w-[340px]",children:[e.jsxs("a",{href:t,download:n,target:"_blank",rel:"noreferrer",title:l||n,className:L("group inline-flex items-center gap-2.5 rounded-md no-underline","border border-fg-6/40 bg-fg-6/[0.05] px-3 py-2","hover:bg-fg-6/[0.12] hover:border-fg-6/60 transition-colors"),children:[e.jsx("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded bg-fg-6/10 text-fg-3",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12.5px] font-medium text-fg-2",children:n}),typeof s=="number"&&s>0&&e.jsx("span",{className:"block text-[11px] text-fg-5/70",children:Kn(s)})]}),e.jsx("span",{className:"shrink-0 text-fg-5/50 group-hover:text-fg-3 transition-colors",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),l&&e.jsx("span",{className:"px-0.5 text-[11.5px] leading-[1.55] text-fg-4 break-words",children:l})]})}function Zn(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
11
+ `).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||ct(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function No(t){return Zn(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function br(t){return t.phase!=="done"||!t.error?null:Zn(t)?"hub.streamErrored":"hub.streamFailed"}function vr({detail:t,t:n,className:s}){const l=Qs(t);if(l==="interrupted")return e.jsxs("div",{className:L("flex items-center gap-1.5 text-[11px] text-fg-5/55",s),children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-[2px] bg-fg-5/45 shrink-0"}),e.jsx("span",{children:n("hub.turnStopped")})]});const r=l==="error"?{dot:"bg-rose-400/55",text:"text-rose-300/65"}:{dot:"bg-fg-5/40",text:"text-fg-5/55"};return e.jsxs("div",{className:L("flex items-start gap-1.5 text-[11px] leading-[1.6]",r.text,s),children:[e.jsx("span",{className:L("mt-[5px] h-1 w-1 rounded-full shrink-0",r.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const jr=64;function wr(t,n){const[s,l]=o.useState(t),r=o.useRef(0),c=o.useRef(null);return o.useEffect(()=>{if(n<=0)return;const x=Date.now()-r.current,d=()=>{r.current=Date.now(),l(t)};return x>=n?d():(c.current&&clearTimeout(c.current),c.current=window.setTimeout(d,n-x)),()=>{c.current&&clearTimeout(c.current)}},[t,n]),n<=0?t:s}function So({stream:t,t:n,workdir:s}){const l=ct(t.plan),[r,c]=o.useState(!1),[x,d]=o.useState(!1),m=o.useRef(null),b=o.useRef(null),g=br(t),v=o.useMemo(()=>(t.activity||"").split(`
12
+ `).filter(Boolean),[t.activity]),k=t.previewMeta?.toolCalls??[],y=v[v.length-1]||k[k.length-1]?.summary||"",B=k.length,A=t.previewMeta?.contextPercent??null,W=t.previewMeta?.contextUsedTokens??0,$=t.previewMeta?.turnOutputTokens??0,U=t.phase==="streaming",z=U&&t.startedAt!=null&&t.startedAt>0,Q=U;o.useLayoutEffect(()=>{const C=m.current;C&&r&&(C.scrollTop=C.scrollHeight)},[r,t.activity,k.length]),o.useLayoutEffect(()=>{const C=b.current;C&&x&&(C.scrollTop=C.scrollHeight)},[x,t.thinking]);const T=t.subAgents??null,K=wr(t.text,t.phase==="streaming"?jr:0),P=o.useMemo(()=>Gt({workdir:s}),[s]),O=o.useMemo(()=>e.jsx(gn,{remarkPlugins:vn,components:P,children:K}),[K,P]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[l&&e.jsx(Yn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),T&&T.length>0&&T.map(C=>e.jsx(es,{sub:C,t:n},C.id)),(k.length>0||v.length>0)&&e.jsx(at,{open:r,onToggle:()=>c(C=>!C),dot:{color:"bg-cyan-400/60",pulse:!0},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[12px] text-fg-4 truncate",children:e.jsx(Re,{text:y,workdir:s})}),badge:(k.length||v.length)>1?e.jsx(pn,{children:k.length||v.length}):void 0,children:e.jsx("div",{ref:m,className:"px-3.5 py-2.5 space-y-0.5 max-h-[280px] overflow-y-auto",children:k.length>0?k.map(C=>e.jsx(kr,{call:C,workdir:s},C.id)):v.map((C,M)=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate",children:e.jsx(Re,{text:C,workdir:s})})]},M))})}),t.thinking&&e.jsx(at,{open:x,onToggle:()=>d(C=>!C),dot:{color:"bg-violet-400/50",pulse:!0},label:n("hub.thinking"),collapsedContent:e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:zn(t.thinking,3)}),children:e.jsx("div",{ref:b,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[280px] overflow-y-auto",children:t.thinking})}),t.text&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:O}),t.artifacts&&t.artifacts.length>0&&e.jsx("div",{className:"flex flex-col gap-2",children:t.artifacts.map((C,M)=>C.kind==="photo"?e.jsx("a",{href:C.url,target:"_blank",rel:"noreferrer",className:"inline-block",children:e.jsx("img",{src:C.url,alt:C.caption||C.fileName,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain hover:opacity-90 transition-opacity"})},M):e.jsx(Xn,{url:C.url,fileName:C.fileName,fileSize:C.fileSize,caption:C.caption},M))}),t.phase==="streaming"&&(t.generatingImages??0)>0&&e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-fg-4",children:[e.jsxs("span",{className:"relative inline-flex items-center justify-center w-3 h-3",children:[e.jsx("span",{className:"absolute inline-flex w-3 h-3 rounded-full bg-cyan-400/40 animate-ping"}),e.jsx("span",{className:"relative inline-block w-1.5 h-1.5 rounded-full bg-cyan-400/80"})]}),e.jsx("span",{children:t.generatingImages===1?"Generating image…":`Generating ${t.generatingImages} images…`})]}),Q&&e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-mono text-fg-5/50 tabular-nums",children:[e.jsx(Jn,{className:"text-fg-5/45 shrink-0"}),e.jsx(yr,{toolCount:B,ctxPct:A,ctxTokens:W,turnOutTokens:$,startedAt:z?t.startedAt:null})]}),g&&t.error&&e.jsx(vr,{detail:t.error,t:n,className:"pt-0.5"})]})}function kr({call:t,workdir:n}){const[s,l]=o.useState(!1),r=!!(t.input||t.result),c=t.status==="failed"?"bg-rose-400/70":t.status==="running"?"bg-cyan-400/70":"bg-fg-5/30";return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>r&&l(x=>!x),className:`flex w-full items-center gap-1.5 py-[2px] text-left min-w-0 ${r?"cursor-pointer hover:bg-white/[0.03] rounded":"cursor-default"}`,title:r?void 0:t.summary,children:[e.jsx("span",{className:`w-1 h-1 rounded-full shrink-0 ${c} ${t.status==="running"?"animate-pulse":""}`}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate flex-1",children:e.jsx(Re,{text:t.summary,workdir:n})}),r&&e.jsx("span",{className:`shrink-0 text-[9px] text-fg-5/40 transition-transform ${s?"rotate-90":""}`,children:"▸"})]}),s&&e.jsxs("div",{className:"ml-2.5 mt-0.5 mb-1 space-y-1 border-l border-white/[0.06] pl-2.5",children:[t.input&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-4/80 max-h-[140px] overflow-y-auto",children:e.jsx(Re,{text:t.input,workdir:n})}),t.result&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-5/70 max-h-[140px] overflow-y-auto border-t border-white/[0.04] pt-1",children:e.jsx(Re,{text:t.result,workdir:n})})]})]})}function Jn({className:t}){return e.jsxs("span",{className:`thinking-dots inline-flex items-center gap-[3px] ${t||""}`,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}function yr({toolCount:t,ctxPct:n,ctxTokens:s,turnOutTokens:l,startedAt:r}){const c=[];return t>0&&c.push(e.jsxs("span",{className:"flex items-center gap-1 text-fg-5/55",title:`${t} tool ${t===1?"call":"calls"} this turn`,children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:e.jsx("path",{d:"M22 12h-4l-3 9L9 3l-3 9H2"})}),t]},"ops")),n!=null&&c.push(e.jsxs("span",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Un(n)}`}),n.toFixed(1),"%"]},"ctx")),s>0&&c.push(e.jsx("span",{className:"text-fg-5/40",children:Fn(s)},"tok")),l>0&&c.push(e.jsxs("span",{className:"text-fg-5/40",children:["↑",bn(l)]},"out")),r!=null&&c.push(e.jsx(Nr,{startedAt:r},"elapsed")),c.length?e.jsx("span",{className:"shrink-0 flex items-center gap-1.5",children:c.map((x,d)=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[d>0&&e.jsx("span",{className:"text-fg-5/25",children:"·"}),x]},d))}):null}function Nr({startedAt:t}){const[,n]=o.useState(0);o.useEffect(()=>{const l=setInterval(()=>n(r=>r+1),1e3);return()=>clearInterval(l)},[]);const s=Math.max(0,Date.now()-t);return e.jsx("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:qs(s)})}function es({sub:t,t:n}){const[s,l]=o.useState(!1),r=t.status,c=r==="failed"?"bg-rose-400/60":r==="done"?"bg-emerald-400/55":"bg-amber-400/60",x=r==="running",d=t.tools,m=o.useMemo(()=>{const v=new Set,k=[];for(const y of d)v.has(y.name)||(v.add(y.name),k.push(y.name));return k},[d]),b=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",g=t.model?Ft(t.model):null;return e.jsx(at,{open:s,onToggle:()=>l(v=>!v),dot:{color:c,pulse:x},label:b,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),g&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:g}),!t.description&&m.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:m.join(" · ")})]}),badge:d.length>0?e.jsx(pn,{children:d.length}):void 0,children:e.jsxs("div",{className:"px-3.5 py-2.5 space-y-1 max-h-[260px] overflow-y-auto",children:[t.description&&e.jsx("div",{className:"mb-1.5 text-[12px] text-fg-3 leading-[1.55]",children:t.description}),d.length===0?e.jsxs("div",{className:"text-[11px] font-mono text-fg-5/50",children:["— ",n("hub.subAgentWaiting")||"waiting for first tool…"]}):d.map(v=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/65 truncate",children:v.summary})]},v.id))]})})}function Sr({message:t,t:n,workdir:s}){const{activityBlocks:l,thinkingBlocks:r,planBlocks:c,subAgentBlocks:x,outputBlocks:d,noticeBlocks:m}=ts(t.blocks),b=[...c].reverse().find(v=>ct(v.plan));return l.length>0||x.length>0||!!b?.plan||r.length>0||d.length>0||m.length>0?e.jsxs("div",{className:"space-y-3",children:[l.length>0&&e.jsx(Ir,{blocks:l,t:n,workdir:s}),x.map(v=>v.subAgent?e.jsx(es,{sub:v.subAgent,t:n},v.toolId||v.subAgent.id):null),b?.plan&&e.jsx(Yn,{plan:b.plan,t:n,className:"max-w-[760px]"}),r.length>0&&e.jsx(Mr,{blocks:r,t:n}),d.length>0&&e.jsx(Pr,{blocks:d,t:n,workdir:s}),m.length>0&&e.jsx(Lr,{blocks:m,t:n})]}):null}function Cr(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:l,subAgentBlocks:r,outputBlocks:c,noticeBlocks:x}=ts(t.blocks);return c.length>0||n.length>0||r.length>0||s.length>0||l.some(d=>ct(d.plan))||x.length>0}function ts(t){const n=t.filter(s=>s.type==="plan"||s.type==="tool_use"||s.type==="tool_result"||s.type==="image"||s.type==="file"||s.type==="sub_agent"||!!s.content.trim());return{activityBlocks:n.filter(s=>s.type==="tool_use"||s.type==="tool_result"),thinkingBlocks:n.filter(s=>s.type==="thinking"),planBlocks:n.filter(s=>s.type==="plan"&&ct(s.plan)),subAgentBlocks:n.filter(s=>s.type==="sub_agent"),outputBlocks:n.filter(s=>s.type==="text"||s.type==="image"||s.type==="file"),noticeBlocks:n.filter(s=>s.type==="system_notice")}}function Lr({blocks:t,t:n}){const s=t.map(l=>l.content).filter(Boolean).join(`
13
13
 
14
- `).trim();return s?e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/[0.06] px-3 py-2 text-[12.5px] leading-[1.7] text-fg-3",children:[e.jsx("span",{className:"mt-[6px] h-1.5 w-1.5 rounded-full bg-amber-400/70 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-mono uppercase tracking-wide text-amber-300/80",children:n("hub.systemNotice")||"Agent notice"}),e.jsx("div",{className:"mt-0.5 break-words whitespace-pre-wrap",children:s})]})]}):null}function Ir({blocks:t,t:n,workdir:s}){const[l,r]=o.useState(!1),c=t.filter(b=>b.type==="tool_use"),x=c.length,d=c[c.length-1],g=d?Hn(d):"";return e.jsx(at,{open:l,onToggle:()=>r(b=>!b),dot:{color:"bg-cyan-400/60"},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[11.5px] font-mono text-fg-4 truncate",children:e.jsx(Re,{text:g,workdir:s})}),badge:x>0?e.jsx(pn,{children:x}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((b,m)=>e.jsx(Tr,{block:b,workdir:s},m))})})}function Tr({block:t,workdir:n}){const[s,l]=o.useState(!1),r=t.type==="tool_use",c=r?Hn(t):Js(t),x=t.content.length>3e3?t.content.slice(0,3e3)+`
15
- …`:t.content;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&l(d=>!d),className:L("flex items-center gap-2 py-[3px] w-full text-left group rounded-sm transition-colors",t.content&&"hover:bg-panel-h/30"),children:[e.jsx("span",{className:L("h-1.5 w-1.5 rounded-full shrink-0",r?"bg-fg-5/40":"bg-ok/40")}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 group-hover:text-fg-3 transition-colors truncate",children:e.jsx(Re,{text:c,workdir:n})})]}),s&&t.content&&e.jsx("pre",{className:"ml-3 mt-1 mb-2 p-3 rounded-md bg-inset border border-edge text-[11px] leading-[1.6] text-fg-4 font-mono whitespace-pre-wrap break-words max-h-[240px] overflow-y-auto",children:e.jsx(Re,{text:x,workdir:n})})]})}function Er({blocks:t,t:n}){const[s,l]=o.useState(!1),r=o.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
14
+ `).trim();return s?e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/[0.06] px-3 py-2 text-[12.5px] leading-[1.7] text-fg-3",children:[e.jsx("span",{className:"mt-[6px] h-1.5 w-1.5 rounded-full bg-amber-400/70 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-mono uppercase tracking-wide text-amber-300/80",children:n("hub.systemNotice")||"Agent notice"}),e.jsx("div",{className:"mt-0.5 break-words whitespace-pre-wrap",children:s})]})]}):null}function Ir({blocks:t,t:n,workdir:s}){const[l,r]=o.useState(!1),c=t.filter(b=>b.type==="tool_use"),x=c.length,d=c[c.length-1],m=d?Hn(d):"";return e.jsx(at,{open:l,onToggle:()=>r(b=>!b),dot:{color:"bg-cyan-400/60"},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[11.5px] font-mono text-fg-4 truncate",children:e.jsx(Re,{text:m,workdir:s})}),badge:x>0?e.jsx(pn,{children:x}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((b,g)=>e.jsx(Tr,{block:b,workdir:s},g))})})}function Tr({block:t,workdir:n}){const[s,l]=o.useState(!1),r=t.type==="tool_use",c=r?Hn(t):Js(t),x=t.content.length>3e3?t.content.slice(0,3e3)+`
15
+ …`:t.content;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&l(d=>!d),className:L("flex items-center gap-2 py-[3px] w-full text-left group rounded-sm transition-colors",t.content&&"hover:bg-panel-h/30"),children:[e.jsx("span",{className:L("h-1.5 w-1.5 rounded-full shrink-0",r?"bg-fg-5/40":"bg-ok/40")}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 group-hover:text-fg-3 transition-colors truncate",children:e.jsx(Re,{text:c,workdir:n})})]}),s&&t.content&&e.jsx("pre",{className:"ml-3 mt-1 mb-2 p-3 rounded-md bg-inset border border-edge text-[11px] leading-[1.6] text-fg-4 font-mono whitespace-pre-wrap break-words max-h-[240px] overflow-y-auto",children:e.jsx(Re,{text:x,workdir:n})})]})}function Mr({blocks:t,t:n}){const[s,l]=o.useState(!1),r=o.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
16
16
 
17
- `).trim();if(!c)return null;const x=zn(c,3);return e.jsx(at,{open:s,onToggle:()=>l(d=>!d),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:x?e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:x}):void 0,children:e.jsx(Mr,{scrollRef:r,text:c})})}function Mr({scrollRef:t,text:n}){return o.useLayoutEffect(()=>{const s=t.current;s&&(s.scrollTop=s.scrollHeight)},[t]),e.jsx("div",{ref:t,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[320px] overflow-y-auto",children:n})}function Ar({block:t,onLightbox:n,t:s}){const l=t.imageCaption?.trim()||"",r=t.imageCaptionKind==="prompt",[c,x]=o.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:l||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),l&&(r?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>x(d=>!d),"aria-expanded":c,className:L("self-start inline-flex items-center gap-1 px-2 py-[3px] rounded-md","text-[11px] font-medium tracking-wide","border border-fg-6/40 bg-fg-6/[0.06] text-fg-3","hover:bg-fg-6/[0.12] hover:text-fg-2 hover:border-fg-6/60","transition-colors"),title:s(c?"hub.imagePromptHide":"hub.imagePromptShow"),children:[e.jsx("span",{"aria-hidden":!0,className:"text-[9px] leading-none",children:c?"▾":"▸"}),e.jsx("span",{children:s("hub.imagePrompt")})]}),c&&e.jsx("div",{className:"rounded-md border border-fg-6/30 bg-fg-6/[0.05] px-3 py-2 max-w-[400px] max-h-[260px] overflow-y-auto",children:e.jsx("div",{className:"text-[11.5px] leading-[1.65] text-fg-3 whitespace-pre-wrap break-words",children:l})})]}):e.jsx("figcaption",{className:"text-[11px] leading-[1.55] text-fg-5 max-w-[400px] break-words whitespace-pre-wrap",children:l}))]})}function Pr({blocks:t,t:n,workdir:s}){const l=t.filter(m=>m.type==="text"),r=t.filter(m=>m.type==="image"),c=t.filter(m=>m.type==="file"),x=l.map(m=>m.content).filter(Boolean).join(`
17
+ `).trim();if(!c)return null;const x=zn(c,3);return e.jsx(at,{open:s,onToggle:()=>l(d=>!d),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:x?e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:x}):void 0,children:e.jsx(Er,{scrollRef:r,text:c})})}function Er({scrollRef:t,text:n}){return o.useLayoutEffect(()=>{const s=t.current;s&&(s.scrollTop=s.scrollHeight)},[t]),e.jsx("div",{ref:t,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[320px] overflow-y-auto",children:n})}function Ar({block:t,onLightbox:n,t:s}){const l=t.imageCaption?.trim()||"",r=t.imageCaptionKind==="prompt",[c,x]=o.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:l||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),l&&(r?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>x(d=>!d),"aria-expanded":c,className:L("self-start inline-flex items-center gap-1 px-2 py-[3px] rounded-md","text-[11px] font-medium tracking-wide","border border-fg-6/40 bg-fg-6/[0.06] text-fg-3","hover:bg-fg-6/[0.12] hover:text-fg-2 hover:border-fg-6/60","transition-colors"),title:s(c?"hub.imagePromptHide":"hub.imagePromptShow"),children:[e.jsx("span",{"aria-hidden":!0,className:"text-[9px] leading-none",children:c?"▾":"▸"}),e.jsx("span",{children:s("hub.imagePrompt")})]}),c&&e.jsx("div",{className:"rounded-md border border-fg-6/30 bg-fg-6/[0.05] px-3 py-2 max-w-[400px] max-h-[260px] overflow-y-auto",children:e.jsx("div",{className:"text-[11.5px] leading-[1.65] text-fg-3 whitespace-pre-wrap break-words",children:l})})]}):e.jsx("figcaption",{className:"text-[11px] leading-[1.55] text-fg-5 max-w-[400px] break-words whitespace-pre-wrap",children:l}))]})}function Pr({blocks:t,t:n,workdir:s}){const l=t.filter(g=>g.type==="text"),r=t.filter(g=>g.type==="image"),c=t.filter(g=>g.type==="file"),x=l.map(g=>g.content).filter(Boolean).join(`
18
18
 
19
- `),[d,g]=o.useState(null),b=o.useMemo(()=>Gt({workdir:s}),[s]);return!x.trim()&&r.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(gn,{remarkPlugins:vn,components:b,children:x})}),r.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:r.map((m,j)=>e.jsx(Ar,{block:m,onLightbox:g,t:n},j))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((m,j)=>e.jsx(Xn,{url:m.content,fileName:m.fileName||"file",fileSize:m.fileSize,caption:m.fileCaption},j))}),d&&e.jsx(ns,{src:d,onClose:()=>g(null)})]})}const Co=o.memo(function({turn:n,turnIndex:s,agent:l,meta:r,model:c,effort:x,providerName:d,t:g,workdir:b,onResend:m,onEdit:j,onFork:C}){const y=n.user&&Dn(n.user.text),B=C&&typeof s=="number"?()=>C(s):void 0,A=o.useMemo(()=>Gt({workdir:b}),[b]),W=!!n.assistant&&Cr(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!y&&e.jsx(ss,{text:n.user.text,blocks:n.user.blocks,t:g,onResend:m,onEdit:j,onFork:B}),y&&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(gn,{remarkPlugins:vn,components:A,children:n.user.text})}),W&&e.jsxs(e.Fragment,{children:[e.jsx(Br,{agent:l,meta:r,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(Sr,{message:n.assistant,t:g,workdir:b})})]})]})});function ns({src:t,onClose:n}){return o.useEffect(()=>{const s=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),fn.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 Rr=1500,_r=16,Tn=8;function Wr(t){const n=t.split(`
19
+ `),[d,m]=o.useState(null),b=o.useMemo(()=>Gt({workdir:s}),[s]);return!x.trim()&&r.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(gn,{remarkPlugins:vn,components:b,children:x})}),r.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:r.map((g,v)=>e.jsx(Ar,{block:g,onLightbox:m,t:n},v))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((g,v)=>e.jsx(Xn,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},v))}),d&&e.jsx(ns,{src:d,onClose:()=>m(null)})]})}const Co=o.memo(function({turn:n,turnIndex:s,agent:l,meta:r,model:c,effort:x,providerName:d,t:m,workdir:b,onResend:g,onEdit:v,onFork:k}){const y=n.user&&Dn(n.user.text),B=k&&typeof s=="number"?()=>k(s):void 0,A=o.useMemo(()=>Gt({workdir:b}),[b]),W=!!n.assistant&&Cr(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!y&&e.jsx(ss,{text:n.user.text,blocks:n.user.blocks,t:m,onResend:g,onEdit:v,onFork:B}),y&&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(gn,{remarkPlugins:vn,components:A,children:n.user.text})}),W&&e.jsxs(e.Fragment,{children:[e.jsx(Br,{agent:l,meta:r,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(Sr,{message:n.assistant,t:m,workdir:b})})]})]})});function ns({src:t,onClose:n}){return o.useEffect(()=>{const s=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),fn.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 Rr=1500,_r=16,Tn=8;function Wr(t){const n=t.split(`
20
20
  `);return n.length<=Tn?t:n.slice(0,Tn).join(`
21
- `)}function ss({text:t,blocks:n,t:s,onResend:l,onEdit:r,onFork:c}){const[x,d]=o.useState(!1),[g,b]=o.useState(!1),[m,j]=o.useState(null),C=t?t.split(`
22
- `).length:0,y=!!t&&(t.length>Rr||C>_r),[B,A]=o.useState(!1),W=t?y&&!B?Wr(t):t:"",$=!!(l||r||c),U=n?.filter(T=>T.type==="image")||[],z=()=>{navigator.clipboard.writeText(t).then(()=>{b(!0),setTimeout(()=>b(!1),1500)}).catch(()=>{})},Q=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(C));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[W,y&&!B&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),y&&e.jsx("button",{type:"button",onClick:()=>A(T=>!T),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:B?s("hub.collapse"):Q}),U.length>0&&e.jsx("div",{className:L("flex flex-wrap gap-2",t&&"mt-2"),children:U.map((T,K)=>e.jsx("img",{src:T.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(T.content)},K))})]}),m&&e.jsx(ns,{src:m,onClose:()=>j(null)}),$&&e.jsxs("div",{className:L("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(Pt,{label:s(g?"hub.copied":"hub.copy"),onClick:z,children:g?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"})]})}),l&&e.jsx(Pt,{label:s("hub.rerun"),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("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),r&&e.jsx(Pt,{label:s("hub.edit"),onClick:()=>r(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(Pt,{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 Pt({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 Br({agent:t,meta:n,model:s,effort:l,providerName:r,previewMeta:c,hideContextUsage:x}){const d=x?null:c?.contextPercent??null,g=x?0:c?.contextUsedTokens??0,b=x?0:c?.turnOutputTokens??0,m=d!=null||g>0||b>0,j=c?.providerName??r??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(lt,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||l)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&l?" · ":"",l||""]}),j&&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 ${j} (BYOK), not the agent CLI's native auth.`,children:["via ",j]}),m&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:$r(c),children:[d!=null&&e.jsx(Or,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),g>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",Fn(g)]}),b>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",bn(b)]})]})]})}function $r(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 Or({pct:t}){return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Un(t)}`})}function En(t,n,s){return t==="zh-CN"?n:s}function Dr({open:t,onClose:n,workdir:s}){const l=oe(c=>c.locale),r=s.split("/").pop()||s;return e.jsxs(Ut,{open:t,onClose:n,wide:!0,children:[e.jsx(zt,{title:En(l,`${r} — 项目扩展`,`${r} — Project Extensions`),description:En(l,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(Ps,{workdir:s}):null]})}let Mn=_n(()=>import("./SessionPanel-DYfSlreh.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function un(){return Mn??=_n(()=>import("./SessionPanel-DYfSlreh.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Mn}const Fr=o.lazy(async()=>({default:(await un()).SessionPanel})),an=5,Ur=240,zr=120,Kr=12,Hr=900*1e3,G=(t,n)=>`${t}:${n}`;function Vr(t){const n=new Map;for(const d of t)n.set(G(d.agent||"",d.sessionId),d);const s=new Map,l=new Set;for(const d of t){const g=d.migratedFrom;if(!g||g.kind!=="fork"||!g.sessionId)continue;const b=G(g.agent||d.agent||"",g.sessionId);n.has(b)&&(l.add(G(d.agent||"",d.sessionId)),s.has(b)||s.set(b,[]),s.get(b).push(d))}const r=[],c=new Set,x=(d,g)=>{const b=G(d.agent||"",d.sessionId);if(c.has(b))return;c.add(b),r.push(Object.assign({},d,{__forkDepth:g}));const m=s.get(b);if(m)for(const j of m)x(j,g+1)};for(const d of t){const g=G(d.agent||"",d.sessionId);l.has(g)||x(d,0)}for(const d of t)x(d,0);return r}let Gr=0;function Rt(){return`mk-${Date.now().toString(36)}-${(++Gr).toString(36)}`}function _t(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 qr=[1,2,3,6],hn=6;function Qr(t){for(const n of qr)if(n>=t)return n;return hn}function An(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function ze(t,n){const s=Qr(t);return s>n?s:n}function Yr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Xr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function rs(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 Zr=o.memo(function({active:n=!0}){const s=oe(i=>i.locale),l=oe(i=>i.state?.runtimeWorkdir??null),r=o.useMemo(()=>ks(s),[s]),[c,x]=o.useState([]),[d,g]=o.useState({}),[b,m]=o.useState({}),[j,C]=o.useState(!0),[y,B]=o.useState(()=>{const i=_t("pikiloom-layout-mode");return i==="1"||i==="2"||i==="3"||i==="6"?Number(i):An()}),[A,W]=o.useState(()=>{const i=_t("pikiloom-layout-floor");return i==="1"||i==="2"||i==="3"||i==="6"?Number(i):An()}),[$,U]=o.useState(()=>{try{const i=_t("pikiloom-open-sessions");if(i){const h=JSON.parse(i);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||Rt()}))}}catch{}return[]}),[z,Q]=o.useState(()=>{const i=_t("pikiloom-active-slot");if(i!=null){const h=Number(i);if(Number.isFinite(h)&&h>=0)return h}return 0}),T=o.useCallback(i=>{B(i),Wt("pikiloom-layout-mode",String(i))},[]),K=o.useCallback(i=>{W(i),Wt("pikiloom-layout-floor",String(i))},[]),P=o.useCallback(i=>{U(h=>{const u=typeof i=="function"?i(h):i,p=u.map(({pendingPrompt:w,pendingImageUrls:k,...N})=>N);return Wt("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),O=o.useCallback(i=>{Q(h=>{const u=typeof i=="function"?i(h):i;return Wt("pikiloom-active-slot",String(u)),u})},[]),S=o.useCallback(i=>{T(i),K(i)},[T,K]);o.useEffect(()=>{P(i=>i.length>y?i.slice(0,y):i),O(i=>i>=y?y-1:i)},[y]);const[E,ue]=o.useState(!1),ie=o.useRef(y);ie.current=y;const q=o.useRef(A);q.current=A;const Se=o.useRef(z);Se.current=z;const H=o.useRef($);H.current=$;const mt=o.useRef(-1),fe=$[z]??null,dt=o.useCallback(i=>{if(!i){P([]),O(0);return}const h=i.mountKey?i:{...i,mountKey:Rt()};P(u=>{const p=u.findIndex(k=>k.agent===h.agent&&k.sessionId===h.sessionId);if(p>=0)return O(p),u;if(u.length<ie.current){const k=[...u,h];return O(k.length-1),k}if(ie.current<hn){const k=[...u,h];return T(ze(k.length,q.current)),O(k.length-1),k}const w=[...u];return w[Se.current]=h,w})},[P,O,T]),[He,Ve]=o.useState(!1),[J,_e]=o.useState(null),[We,Ge]=o.useState(""),[ee,Be]=o.useState("all"),[ge,qe]=o.useState({}),[Ce,bt]=o.useState({}),me=o.useDeferredValue(We),le=o.useRef(!1),Qe=o.useRef({}),Le=o.useRef(d);Le.current=d;const vt=o.useRef(ge);vt.current=ge;const Ie=o.useRef(new Set),se=o.useRef({});o.useEffect(()=>()=>{for(const i of Object.values(se.current))clearTimeout(i)},[]),o.useEffect(()=>{P(i=>{let h=!1;const u=i.map(p=>{const w=Ce[p.workdir];if(!w)return p;const k=Cn(w,p.agent,p.sessionId);return k===p.sessionId?p:(h=!0,{...p,sessionId:k})});return h?u:i})},[Ce,P]);const be=o.useCallback(async()=>{try{const i=await ne.getWorkspaces(),h=i.ok?i.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((p,w)=>p.path===h[w].path&&p.name===h[w].name)?u:h),le.current=!0}catch{le.current=!0}finally{C(!1)}},[]);o.useEffect(()=>{be()},[be]);const M=o.useCallback(async(i,h={})=>{if(!Qe.current[i]){Qe.current[i]=!0,h.background||m(u=>({...u,[i]:!0}));try{const u=await $s(i,{force:h.force});o.startTransition(()=>{bt(p=>{const w=u.promotions||{},k=p[i];return k&&Object.keys(k).length===Object.keys(w).length&&Object.entries(w).every(([N,R])=>k[N]===R)?p:{...p,[i]:w}}),g(p=>{const w=u.sessions||[],k=p[i]||[],N=new Set(w.map(F=>G(F.agent||"",F.sessionId))),R=k.filter(F=>{if(F.runState!=="running")return!1;const _=G(F.agent||"",F.sessionId);if(N.has(_))return!1;const D=vt.current[_];return!(D?.resolvedKey&&D.resolvedKey!==_)});return{...p,[i]:R.length?[...R,...w]:w}})})}catch{h.background||o.startTransition(()=>{g(u=>({...u,[i]:[]}))})}finally{Qe.current[i]=!1,h.background||m(u=>({...u,[i]:!1}))}}},[]),he=o.useRef(l);o.useEffect(()=>{l!==he.current&&(he.current=l,!(!l||!le.current)&&be().then(()=>{M(l,{force:!0})}))},[l,be,M]);const Y=o.useCallback((i,h)=>{const u=i.agent||"";!u||!i.sessionId||(un(),Fs({workdir:h,agent:u,sessionId:i.sessionId,rich:!0,turnOffset:0,turnLimit:Kr}))},[]),jt=o.useCallback((i,h,u=zr)=>{const p=`${h}:${G(i.agent||"",i.sessionId)}`,w=se.current[p];w&&clearTimeout(w),se.current[p]=setTimeout(()=>{delete se.current[p],Y(i,h)},u)},[Y]),Te=o.useCallback((i,h)=>{const u=`${h}:${G(i.agent||"",i.sessionId)}`,p=se.current[u];p&&(clearTimeout(p),delete se.current[u])},[]);o.useEffect(()=>{n&&un()},[n]),o.useEffect(()=>{if(!n)return;const i=[];return c.forEach((h,u)=>{if(d[h.path]||b[h.path])return;const p=setTimeout(()=>{M(h.path)},u*90);i.push(p)}),()=>{for(const h of i)clearTimeout(h)}},[n,M,b,d,c]);const Ye=o.useRef(new Map);Ln(n&&le.current&&c.length>0?"sessions-changed":null,o.useCallback(i=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=i.key,u=h?c.filter(k=>(Le.current[k.path]||[]).some(N=>G(N.agent||"",N.sessionId)===h)):c,p=u.length?u:c,w=Ye.current;for(const k of p)w.has(k.path)&&clearTimeout(w.get(k.path)),w.set(k.path,setTimeout(()=>{w.delete(k.path),M(k.path,{background:!0,force:!0})},300))},[c,M]));const $e=o.useCallback(i=>{const h=i.agent||"";return!h||!i.sessionId?i:ys(i,ge[G(h,i.sessionId)]||null)},[ge]);Ln("stream-update",o.useCallback(i=>{const h=i.key;if(!h)return;const u=Ns(h,i.snapshot??null);qe(p=>{if(!u){const _=p[h];return!_||_.phase==="done"?p:{...p,[h]:{..._,phase:"done",updatedAt:Date.now()}}}const w=(_,D)=>!!_&&!!D&&_.phase===D.phase&&_.resolvedKey===D.resolvedKey&&_.sessionId===D.sessionId&&_.incomplete===D.incomplete&&_.error===D.error,k=w(p[h],u),N=u.resolvedKey===h||w(p[u.resolvedKey],{...u,key:u.resolvedKey});if(k&&N)return p;const R=Date.now()-Hr,F={};for(const[_,D]of Object.entries(p))D.phase==="done"&&D.updatedAt<R||(F[_]=D);return F[h]=u,u.resolvedKey!==h&&(F[u.resolvedKey]={...u,key:u.resolvedKey}),F})},[])),Ss(o.useCallback(()=>{if(!(!n||!le.current||c.length===0))for(const i of c)M(i.path,{background:!0,force:!0})},[n,c,M])),o.useEffect(()=>{if(!n||!le.current||c.length===0)return;const i=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)M(u.path,{background:!0,force:!0})};if(i(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&i()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,M,c]),o.useEffect(()=>{if(!n)return;const i=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const w=`${h.path}:${G(p.agent||"",p.sessionId)}`;if(Ie.current.has(w))return;const k=setTimeout(()=>{Ie.current.add(w),Y(p,h.path)},Ur+u*120);i.push(k)}),()=>{for(const h of i)clearTimeout(h)}},[n,d,Y,c]);const qt=o.useCallback(async i=>{try{(await ne.addWorkspace(i)).ok&&(Ve(!1),await be(),M(i))}catch{}},[be,M]),[xe,ve]=o.useState(null),[je,wt]=o.useState(!1),[ae,Oe]=o.useState(null),Xe=o.useCallback(i=>{ve(i)},[]),Ze=o.useCallback(async()=>{const i=xe;if(i){wt(!0);try{await ne.removeWorkspace(i),x(h=>h.filter(u=>u.path!==i)),g(h=>{const u={...h};return delete u[i],u}),P(h=>{const u=h.filter(p=>p.workdir!==i);return u.length!==h.length&&T(ze(u.length,q.current)),u}),O(0),ve(null)}catch{}finally{wt(!1)}}},[xe]),Je=o.useCallback(i=>{M(i,{force:!0})},[M]),[Ee,we]=o.useState(null),[De,ut]=o.useState(!1),[ce,et]=o.useState(!1),tt=oe(i=>i.toast),[re,Me]=o.useState(null),kt=o.useCallback((i,h,u)=>{Me({anchor:{right:i.right,bottom:i.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:Pn(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);o.useEffect(()=>{if(!re)return;const i=()=>Me(null),h=u=>{u.key==="Escape"&&i()};return window.addEventListener("mousedown",i),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",i),window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i),window.removeEventListener("keydown",h)}},[re]);const ht=o.useCallback(i=>{ut(!1),we(i),Me(null)},[]),ke=o.useCallback(async()=>{const i=Ee;if(i){et(!0);try{const h=await ne.deleteSession(i.workdir,i.agent,i.sessionId,De);if(!h.ok){const u=h.error?.includes("still running")?r("session.deleteRunningError"):h.error||r("session.deleteFailed");tt(u,!1);return}g(u=>{const p=u[i.workdir];if(!p)return u;const w=p.filter(k=>!(k.agent===i.agent&&k.sessionId===i.sessionId));return w.length===p.length?u:{...u,[i.workdir]:w}}),P(u=>{const p=u.filter(w=>!(w.workdir===i.workdir&&w.agent===i.agent&&w.sessionId===i.sessionId));return p.length!==u.length&&T(ze(p.length,q.current)),p}),we(null)}catch(h){tt(h?.message||r("session.deleteFailed"),!1)}finally{et(!1)}}},[Ee,De,r,tt]),yt=o.useCallback(i=>{P(h=>{let u=!1;const p=h.map(w=>w.mountKey===i&&(w.pendingPrompt!=null||w.pendingImageUrls)?(u=!0,{...w,pendingPrompt:null,pendingImageUrls:void 0}):w);return u?p:h})},[P]),xt=o.useCallback((i,h,u)=>{Y({agent:i.agent,sessionId:i.sessionId,runState:"running"},i.workdir),g(k=>{const N=k[i.workdir]||[];if(N.some(_=>_.sessionId===i.sessionId&&_.agent===i.agent))return k;const F={sessionId:i.sessionId,agent:i.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...k,[i.workdir]:[F,...N]}});const p=mt.current,w={...i,mountKey:Rt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};o.startTransition(()=>{_e(null),P(k=>{if(p>=k.length)return[...k,w];const N=[...k];return N[p]=w,N}),O(p>=0?p:0)}),M(i.workdir,{background:!0,force:!0})},[M,Y,P,O]),Nt=o.useCallback(i=>{H.current.length>=ie.current&&ie.current<hn&&T(ze(ie.current+1,q.current)),_e(i)},[T]),St=o.useCallback(()=>{_e(null),T(ze(H.current.length,q.current))},[T]),Ct=o.useCallback((i,h)=>{Y(i,h);const u=i.agent||"";H.current.some(p=>p.agent===u&&p.sessionId===i.sessionId)&&T(ze(H.current.length,q.current)),_e(null),o.startTransition(()=>{dt({agent:u,sessionId:i.sessionId,workdir:h})})},[Y,T]),Lt=o.useCallback((i,h)=>{Y({agent:i.agent,sessionId:i.sessionId,runState:"running"},i.workdir),o.startTransition(()=>{h!=null?(P(u=>{if(h>=u.length)return u;const p=[...u];return p[h]={...u[h],agent:i.agent,sessionId:i.sessionId,workdir:i.workdir},p}),O(h)):dt({...i,mountKey:Rt()})}),M(i.workdir,{background:!0,force:!0})},[M,Y]),de=o.useCallback(i=>{let h=i;if(ee==="running"?h=h.filter(u=>Bt(u)==="running"):ee==="review"&&(h=h.filter(u=>Bt(u)==="incomplete")),me.trim()){const u=me.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},[me,ee]),It=o.useMemo(()=>{const i={};for(const h of c){const u=(d[h.path]||[]).map($e),p=Ce[h.path],w=new Map;for(const N of u){const R=G(N.agent||"",N.sessionId),F=ge[R],_=p?Cn(p,N.agent||"",N.sessionId):N.sessionId,D=F?.resolvedKey&&F.resolvedKey!==R?F.resolvedKey:_!==N.sessionId?G(N.agent||"",_):R,Ae=w.get(D);if(!Ae){w.set(D,N);continue}G(Ae.agent||"",Ae.sessionId)!==D&&R===D&&w.set(D,N)}const k=de([...w.values()]);i[h.path]=Vr(k)}return i},[c,d,ge,Ce,de,$e]),pt=o.useCallback(i=>{const h=(d[i.workdir]||[]).find(u=>u.sessionId===i.sessionId&&u.agent===i.agent)??{sessionId:i.sessionId,agent:i.agent,runState:"running"};return $e(h)},[$e,d]),Qt=o.useMemo(()=>new Set($.map(i=>G(i.agent,i.sessionId))),[$]),Yt=fe?G(fe.agent,fe.sessionId):null,nt=o.useCallback(i=>{P(h=>{const u=h.filter((p,w)=>w!==i);return u.length===0?O(0):Se.current>=u.length&&O(u.length-1),T(ze(u.length,q.current)),u})},[P,O,T]);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:We,onChange:i=>Ge(i.target.value),placeholder:r("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"}),We&&e.jsx("button",{onClick:()=>Ge(""),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(i=>e.jsx("button",{onClick:()=>Be(i),className:L("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",ee===i?"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:r(`hub.filter${i[0].toUpperCase()+i.slice(1)}`)},i))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(pe,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!He?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:r("hub.noWorkspaces")}):c.map(i=>e.jsx(no,{workspace:i,sessions:It[i.path]||[],loading:!!b[i.path]||!(i.path in d),isActive:i.path===l,selectedKey:Yt,openSessionKeys:Qt,onSelectSession:Ct,onNewSession:Nt,onRefresh:Je,onRemove:Xe,onExtensions:Oe,onWarmSession:jt,onCancelWarmSession:Te,onSessionMenuOpen:kt,t:r},i.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(i=>e.jsx("button",{onClick:()=>S(i),className:L("flex-1 flex items-center justify-center p-1.5 rounded transition-all",y===i?"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:r(`hub.layout${i}`),children:i===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"})}):i===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"})]}):i===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"})]})},i))}),e.jsxs(Pe,{variant:"ghost",size:"sm",onClick:()=>Ve(i=>!i),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"})]}),r("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(${y===6?3:y}, 1fr)`,gridTemplateRows:y===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const i=J?$.length<y?$.length:z:-1;return mt.current=i,Array.from({length:y},(h,u)=>{if(J&&u===i)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(eo,{workdir:J,workspaceName:c.find(N=>N.path===J)?.name||J.split("/").pop()||"",onSessionCreated:xt,onClose:St,t:r},J)},`new-${J}`);const p=$[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:r("hub.emptySlot")})]})},`empty-${u}`);const w=pt(p),k=u===z;return e.jsxs("div",{className:L("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",k?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:k?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>O(u),children:[e.jsxs("div",{className:L("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",k?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const N=Bt(w);return e.jsx(Vt,{variant:N==="running"?"ok":N==="waiting"?"info":N==="incomplete"?"warn":"idle",pulse:N==="running"||N==="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:w.title||w.lastQuestion?.slice(0,60)||(Dt(p.sessionId)?r("hub.newSession"):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:r("hub.created"),children:Cs(w.createdAt)}),w.runUpdatedAt&&e.jsx("span",{title:r("hub.updated"),children:Rn(w.runUpdatedAt)}),!!w.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),w.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:N=>{N.stopPropagation(),ue(R=>!R)},className:L("p-0.5 rounded transition-colors",E?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:r("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:N=>{N.stopPropagation(),nt(u)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:r("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(o.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Fr,{session:w,workdir:p.workdir,active:n&&k,onSessionChange:N=>Lt(N,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>yt(p.mountKey)},p.mountKey)})})]},p.mountKey||G(p.agent,p.sessionId))})})()})}),E&&fe&&e.jsx(ro,{workdir:fe.workdir,onClose:()=>ue(!1),t:r}),e.jsx(Jr,{open:He,initialPath:l||void 0,onAdd:qt,onClose:()=>Ve(!1),t:r}),e.jsxs(Ut,{open:!!xe,onClose:()=>!je&&ve(null),children:[e.jsx(zt,{title:r("hub.removeWorkspace"),onClose:()=>!je&&ve(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:r("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:r("modal.confirmRemoveWorkspaceHint")}),xe&&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:xe}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Pe,{variant:"ghost",onClick:()=>ve(null),disabled:je,children:r("modal.cancel")}),e.jsx(Pe,{variant:"primary",onClick:Ze,disabled:je,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:r(je?"modal.removing":"modal.remove")})]})]}),re&&(()=>{const h=Math.max(8,Math.min(re.anchor.right-160,window.innerWidth-160-8)),u=Math.min(re.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:()=>ht(re.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"})]}),r("session.delete")]})})})(),e.jsxs(Ut,{open:!!Ee,onClose:()=>!ce&&we(null),children:[e.jsx(zt,{title:r("session.deleteTitle"),onClose:()=>!ce&&we(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:r("session.deleteHint")}),Ee&&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:Ee.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Ee.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:!De,onChange:()=>ut(!1),disabled:ce,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:r("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:r("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:De,onChange:()=>ut(!0),disabled:ce,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:r("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:r("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Pe,{variant:"ghost",onClick:()=>we(null),disabled:ce,children:r("modal.cancel")}),e.jsx(Pe,{variant:"primary",onClick:ke,disabled:ce,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:r(ce?"session.deleting":"modal.remove")})]})]}),e.jsx(Dr,{open:!!ae,onClose:()=>Oe(null),workdir:ae||""})]})});function Jr({open:t,initialPath:n,onAdd:s,onClose:l,t:r}){const[c,x]=o.useState(""),d=o.useCallback(g=>x(g),[]);return o.useEffect(()=>{t&&x("")},[t]),e.jsxs(Ut,{open:t,onClose:l,children:[e.jsx(zt,{title:r("hub.addWorkspace"),onClose:l}),e.jsx(Es,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:r}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Pe,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:r("hub.add")}),e.jsx(Pe,{variant:"secondary",onClick:l,className:"flex-1",children:r("hub.cancel")})]})]})}function eo({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:r}){const[c,x]=o.useState(null),[d,g]=o.useState([]),b=o.useRef(null),m=o.useRef([]),j=o.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),C=o.useCallback(()=>{},[]),y=o.useCallback((W,$)=>{x(W||null),b.current=W||null;const U=$||[];g(U),m.current=U},[]),B=o.useCallback(W=>{const $=m.current;m.current=[],s(W,b.current||void 0,$.length?$:void 0)},[s]),A=!!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:r("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(Vt,{variant:A?"ok":"idle",pulse:A}),!A&&e.jsx("button",{onClick:l,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:A?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(ss,{text:c||"",blocks:d.map(W=>({type:"image",content:W})),t:r}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(Jn,{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:r("hub.newSessionHint")})})})}),e.jsx(ir,{session:j,workdir:t,onStreamQueued:C,onSendStart:y,onSessionChange:B,t:r,streamPhase:null})]})}function to({git:t}){if(!t)return null;const n=[t.detached?`detached HEAD${t.shortSha?` @ ${t.shortSha}`:""}`:`branch ${t.branch??"?"}`,t.upstream?`upstream ${t.upstream}`:t.detached?"":"no upstream",t.ahead||t.behind?`↑${t.ahead} ahead · ↓${t.behind} behind`:"",t.changed>0?`${t.changed} changed (${t.staged} staged · ${t.unstaged} unstaged · ${t.untracked} untracked)`:"clean"].filter(Boolean).join(`
23
- `);return e.jsx(Ls,{content:n,className:L("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 no=o.memo(function({workspace:n,sessions:s,loading:l,isActive:r,selectedKey:c,openSessionKeys:x,onSelectSession:d,onNewSession:g,onRefresh:b,onRemove:m,onExtensions:j,onWarmSession:C,onCancelWarmSession:y,onSessionMenuOpen:B,t:A}){const[W,$]=o.useState(!0),[U,z]=o.useState(an);o.useEffect(()=>{z(an)},[s.length]);const Q=s.slice(0,U),T=s.length-U,K=n.path,[P,O]=o.useState(null),S=o.useCallback(()=>{ne.getWorkspaceGit(K).then(E=>O(E.git)).catch(()=>O(null))},[K]);return o.useEffect(()=>{S()},[S]),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:()=>$(E=>!E),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:L("shrink-0 text-fg-5 transition-transform duration-150",W&&"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:L("min-w-0 truncate text-[12px] font-semibold",r?"text-primary":"text-fg-3"),children:n.name}),e.jsx(to,{git:P})]}),r&&e.jsx(Vt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:E=>{E.stopPropagation(),g(K)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:A("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:E=>{E.stopPropagation(),j(K)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:A("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:E=>{E.stopPropagation(),b(K),S()},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"})]})}),!r&&e.jsx("button",{onClick:E=>{E.stopPropagation(),m(K)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),W&&e.jsx("div",{className:"pb-1",children:l?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:A("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[Q.map(E=>{const ue=G(E.agent||"",E.sessionId),ie=E.__forkDepth||0;return e.jsx(so,{session:E,isSelected:c===ue,isOpen:x?.has(ue)??!1,forkDepth:ie,onClick:()=>d(E,K),onWarm:()=>C(E,K),onCancelWarm:()=>y(E,K),onShowMenu:q=>B(q,E,K),menuLabel:A("session.openActions")},ue)}),T>0&&e.jsxs("button",{onClick:()=>z(E=>E+an),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:["+ ",A("hub.nMore").replace("{n}",String(T))]}),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"})})]})]})})]})}),so=o.memo(function({session:n,isSelected:s,isOpen:l,forkDepth:r=0,onClick:c,onWarm:x,onCancelWarm:d,onShowMenu:g,menuLabel:b}){const m=cn(n.agent||""),j=Bt(n),C=Pn(n).slice(0,500)||(Dt(n.sessionId)?"":n.sessionId.slice(0,16)),y=Is(n,C).slice(0,500),B=n.model?Ft(n.model):null,A=r>0?Math.min(r,3)*14:0,W=l?10:12,$=o.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:x,onFocus:x,onMouseLeave:d,onBlur:d,className:L("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":l?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:W+A,...l?{borderLeft:`2px solid ${s?m.color:`${m.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[r>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(lt,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:m.color},children:m.shortLabel}),B&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:B}),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(Vt,{variant:j==="running"?"ok":j==="waiting"?"info":j==="incomplete"?"warn":"idle",pulse:j==="running"||j==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:C})]}),y&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:y})})]}),e.jsx("button",{ref:$,type:"button","aria-label":b,"aria-haspopup":"menu",onMouseDown:U=>{U.stopPropagation()},onClick:U=>{U.stopPropagation(),U.preventDefault(),$.current&&g($.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"})]})})]})}),ro=o.memo(function({workdir:n,onClose:s,t:l}){const r=oe(m=>m.state?.hostApp??null),c=oe(m=>m.state?.platform??null),x=oe(m=>m.toast),[d,g]=o.useState(()=>Xr(r,c)),b=o.useCallback(async m=>{try{const j=await ne.openInEditor(m,d);if(!j.ok)throw new Error(j.error||`Failed to open ${m}`)}catch(j){x(j?.message||String(j),!1)}},[d,x]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:l("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:l("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(Ts,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(m=>({value:m,label:l(rs(m))})),onChange:m=>{Yr(m)&&g(m)},renderIcon:m=>e.jsx(os,{target:m,size:14})}),e.jsx(Pe,{size:"sm",variant:"ghost",onClick:()=>b(n),className:"flex-1 min-w-0 text-[11px]",children:l("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(oo,{basePath:n,openTarget:d,onOpenPath:b,t:l})})]})});function os({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(lt,{brand:t,size:n})}function oo({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:l,t:r}){const[c,x]=o.useState([]),[d,g]=o.useState(!0);o.useEffect(()=>{let m=!1;return g(!0),ne.lsDir(t,!0,n).then(j=>{!m&&j.ok&&x(j.dirs.slice(0,50).map(C=>({entry:C,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{m||g(!1)}),()=>{m=!0}},[t,n]);const b=o.useCallback(m=>{const j=C=>C.map(y=>y.entry.path===m?y.expanded?{...y,expanded:!1}:y.children===null?(ne.lsDir(m,!0,n).then(B=>{B.ok&&x(A=>xn(A,m,{children:B.dirs.slice(0,50).map(W=>({entry:W,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(B=>xn(B,m,{children:[],loading:!1}))}),{...y,loading:!0,expanded:!0}):{...y,expanded:!0}:y.children?{...y,children:j(y.children)}:y);x(C=>j(C))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(is,{nodes:c,depth:0,onToggle:b,openTarget:s,onOpenPath:l,t:r})})}function is({nodes:t,depth:n,onToggle:s,openTarget:l,onOpenPath:r,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(io,{node:x,depth:n,onToggle:s,openTarget:l,onOpenPath:r,t:c},x.entry.path))})}function io({node:t,depth:n,onToggle:s,openTarget:l,onOpenPath:r,t:c}){const{entry:x,expanded:d,children:g,loading:b}=t,m=n*14,[j,C]=o.useState(!1),y=c(rs(l)),B=c("hub.openWithTarget").replace("{target}",y);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),className:L("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+m,paddingRight:8},children:[x.isDir?b?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:L("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),x.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:x.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:A=>{A.stopPropagation(),r(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:B,children:e.jsx(os,{target:l,subtle:!0})}),!x.isDir&&e.jsx(lo,{filePath:x.path,t:c})]})]}),x.isDir&&d&&g&&g.length>0&&e.jsx(is,{nodes:g,depth:n+1,onToggle:s,openTarget:l,onOpenPath:r,t:c})]})}function lo({filePath:t,t:n}){const[s,l]=o.useState(!1);return e.jsx("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},className:L("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 xn(t,n,s){return t.map(l=>l.entry.path===n?{...l,...s}:l.children?{...l,children:xn(l.children,n,s)}:l)}const Lo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Zr},Symbol.toStringTag,{value:"Module"}));export{ir as I,So as L,vr as R,Co as T,ss as U,ko as a,Zn as b,zs as c,vo as d,jo as e,Jn as f,No as g,Br as h,Lo as i,Ds as l,yo as m,wo as n,bo as o,Os as p,mo as s};
21
+ `)}function ss({text:t,blocks:n,t:s,onResend:l,onEdit:r,onFork:c}){const[x,d]=o.useState(!1),[m,b]=o.useState(!1),[g,v]=o.useState(null),k=t?t.split(`
22
+ `).length:0,y=!!t&&(t.length>Rr||k>_r),[B,A]=o.useState(!1),W=t?y&&!B?Wr(t):t:"",$=!!(l||r||c),U=n?.filter(T=>T.type==="image")||[],z=()=>{navigator.clipboard.writeText(t).then(()=>{b(!0),setTimeout(()=>b(!1),1500)}).catch(()=>{})},Q=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(k));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:[W,y&&!B&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),y&&e.jsx("button",{type:"button",onClick:()=>A(T=>!T),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:B?s("hub.collapse"):Q}),U.length>0&&e.jsx("div",{className:L("flex flex-wrap gap-2",t&&"mt-2"),children:U.map((T,K)=>e.jsx("img",{src:T.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:()=>v(T.content)},K))})]}),g&&e.jsx(ns,{src:g,onClose:()=>v(null)}),$&&e.jsxs("div",{className:L("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(Pt,{label:s(m?"hub.copied":"hub.copy"),onClick:z,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"})]})}),l&&e.jsx(Pt,{label:s("hub.rerun"),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("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),r&&e.jsx(Pt,{label:s("hub.edit"),onClick:()=>r(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(Pt,{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 Pt({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 Br({agent:t,meta:n,model:s,effort:l,providerName:r,previewMeta:c,hideContextUsage:x}){const d=x?null:c?.contextPercent??null,m=x?0:c?.contextUsedTokens??0,b=x?0:c?.turnOutputTokens??0,g=d!=null||m>0||b>0,v=c?.providerName??r??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(lt,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||l)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&l?" · ":"",l||""]}),v&&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 ${v} (BYOK), not the agent CLI's native auth.`,children:["via ",v]}),g&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:$r(c),children:[d!=null&&e.jsx(Or,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",Fn(m)]}),b>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",bn(b)]})]})]})}function $r(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 Or({pct:t}){return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Un(t)}`})}function Mn(t,n,s){return t==="zh-CN"?n:s}function Dr({open:t,onClose:n,workdir:s}){const l=oe(c=>c.locale),r=s.split("/").pop()||s;return e.jsxs(Ut,{open:t,onClose:n,wide:!0,children:[e.jsx(zt,{title:Mn(l,`${r} — 项目扩展`,`${r} — Project Extensions`),description:Mn(l,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(Ps,{workdir:s}):null]})}let En=_n(()=>import("./SessionPanel-CVItEgcH.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function un(){return En??=_n(()=>import("./SessionPanel-CVItEgcH.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),En}const Fr=o.lazy(async()=>({default:(await un()).SessionPanel})),an=5,Ur=240,zr=120,Kr=12,Hr=900*1e3,G=(t,n)=>`${t}:${n}`;function Vr(t){const n=new Map;for(const d of t)n.set(G(d.agent||"",d.sessionId),d);const s=new Map,l=new Set;for(const d of t){const m=d.migratedFrom;if(!m||m.kind!=="fork"||!m.sessionId)continue;const b=G(m.agent||d.agent||"",m.sessionId);n.has(b)&&(l.add(G(d.agent||"",d.sessionId)),s.has(b)||s.set(b,[]),s.get(b).push(d))}const r=[],c=new Set,x=(d,m)=>{const b=G(d.agent||"",d.sessionId);if(c.has(b))return;c.add(b),r.push(Object.assign({},d,{__forkDepth:m}));const g=s.get(b);if(g)for(const v of g)x(v,m+1)};for(const d of t){const m=G(d.agent||"",d.sessionId);l.has(m)||x(d,0)}for(const d of t)x(d,0);return r}let Gr=0;function Rt(){return`mk-${Date.now().toString(36)}-${(++Gr).toString(36)}`}function _t(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 qr=[1,2,3,6],hn=6;function Qr(t){for(const n of qr)if(n>=t)return n;return hn}function An(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function ze(t,n){const s=Qr(t);return s>n?s:n}function Yr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Xr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function rs(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 Zr=o.memo(function({active:n=!0}){const s=oe(i=>i.locale),l=oe(i=>i.state?.runtimeWorkdir??null),r=o.useMemo(()=>ks(s),[s]),[c,x]=o.useState([]),[d,m]=o.useState({}),[b,g]=o.useState({}),[v,k]=o.useState(!0),[y,B]=o.useState(()=>{const i=_t("pikiloom-layout-mode");return i==="1"||i==="2"||i==="3"||i==="6"?Number(i):An()}),[A,W]=o.useState(()=>{const i=_t("pikiloom-layout-floor");return i==="1"||i==="2"||i==="3"||i==="6"?Number(i):An()}),[$,U]=o.useState(()=>{try{const i=_t("pikiloom-open-sessions");if(i){const h=JSON.parse(i);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||Rt()}))}}catch{}return[]}),[z,Q]=o.useState(()=>{const i=_t("pikiloom-active-slot");if(i!=null){const h=Number(i);if(Number.isFinite(h)&&h>=0)return h}return 0}),T=o.useCallback(i=>{B(i),Wt("pikiloom-layout-mode",String(i))},[]),K=o.useCallback(i=>{W(i),Wt("pikiloom-layout-floor",String(i))},[]),P=o.useCallback(i=>{U(h=>{const u=typeof i=="function"?i(h):i,p=u.map(({pendingPrompt:w,pendingImageUrls:N,...S})=>S);return Wt("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),O=o.useCallback(i=>{Q(h=>{const u=typeof i=="function"?i(h):i;return Wt("pikiloom-active-slot",String(u)),u})},[]),C=o.useCallback(i=>{T(i),K(i)},[T,K]);o.useEffect(()=>{P(i=>i.length>y?i.slice(0,y):i),O(i=>i>=y?y-1:i)},[y]);const[M,ue]=o.useState(!1),ie=o.useRef(y);ie.current=y;const q=o.useRef(A);q.current=A;const Se=o.useRef(z);Se.current=z;const H=o.useRef($);H.current=$;const mt=o.useRef(-1),fe=$[z]??null,dt=o.useCallback(i=>{if(!i){P([]),O(0);return}const h=i.mountKey?i:{...i,mountKey:Rt()};P(u=>{const p=u.findIndex(N=>N.agent===h.agent&&N.sessionId===h.sessionId);if(p>=0)return O(p),u;if(u.length<ie.current){const N=[...u,h];return O(N.length-1),N}if(ie.current<hn){const N=[...u,h];return T(ze(N.length,q.current)),O(N.length-1),N}const w=[...u];return w[Se.current]=h,w})},[P,O,T]),[He,Ve]=o.useState(!1),[J,_e]=o.useState(null),[We,Ge]=o.useState(""),[ee,Be]=o.useState("all"),[ge,qe]=o.useState({}),[Ce,bt]=o.useState({}),me=o.useDeferredValue(We),le=o.useRef(!1),Qe=o.useRef({}),Le=o.useRef(d);Le.current=d;const vt=o.useRef(ge);vt.current=ge;const Ie=o.useRef(new Set),se=o.useRef({});o.useEffect(()=>()=>{for(const i of Object.values(se.current))clearTimeout(i)},[]),o.useEffect(()=>{P(i=>{let h=!1;const u=i.map(p=>{const w=Ce[p.workdir];if(!w)return p;const N=Cn(w,p.agent,p.sessionId);return N===p.sessionId?p:(h=!0,{...p,sessionId:N})});return h?u:i})},[Ce,P]);const be=o.useCallback(async()=>{try{const i=await ne.getWorkspaces(),h=i.ok?i.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((p,w)=>p.path===h[w].path&&p.name===h[w].name)?u:h),le.current=!0}catch{le.current=!0}finally{k(!1)}},[]);o.useEffect(()=>{be()},[be]);const E=o.useCallback(async(i,h={})=>{if(!Qe.current[i]){Qe.current[i]=!0,h.background||g(u=>({...u,[i]:!0}));try{const u=await $s(i,{force:h.force});o.startTransition(()=>{bt(p=>{const w=u.promotions||{},N=p[i];return N&&Object.keys(N).length===Object.keys(w).length&&Object.entries(w).every(([S,R])=>N[S]===R)?p:{...p,[i]:w}}),m(p=>{const w=u.sessions||[],N=p[i]||[],S=new Set(w.map(F=>G(F.agent||"",F.sessionId))),R=N.filter(F=>{if(F.runState!=="running")return!1;const _=G(F.agent||"",F.sessionId);if(S.has(_))return!1;const D=vt.current[_];return!(D?.resolvedKey&&D.resolvedKey!==_)});return{...p,[i]:R.length?[...R,...w]:w}})})}catch{h.background||o.startTransition(()=>{m(u=>({...u,[i]:[]}))})}finally{Qe.current[i]=!1,h.background||g(u=>({...u,[i]:!1}))}}},[]),he=o.useRef(l);o.useEffect(()=>{l!==he.current&&(he.current=l,!(!l||!le.current)&&be().then(()=>{E(l,{force:!0})}))},[l,be,E]);const Y=o.useCallback((i,h)=>{const u=i.agent||"";!u||!i.sessionId||(un(),Fs({workdir:h,agent:u,sessionId:i.sessionId,rich:!0,turnOffset:0,turnLimit:Kr}))},[]),jt=o.useCallback((i,h,u=zr)=>{const p=`${h}:${G(i.agent||"",i.sessionId)}`,w=se.current[p];w&&clearTimeout(w),se.current[p]=setTimeout(()=>{delete se.current[p],Y(i,h)},u)},[Y]),Te=o.useCallback((i,h)=>{const u=`${h}:${G(i.agent||"",i.sessionId)}`,p=se.current[u];p&&(clearTimeout(p),delete se.current[u])},[]);o.useEffect(()=>{n&&un()},[n]),o.useEffect(()=>{if(!n)return;const i=[];return c.forEach((h,u)=>{if(d[h.path]||b[h.path])return;const p=setTimeout(()=>{E(h.path)},u*90);i.push(p)}),()=>{for(const h of i)clearTimeout(h)}},[n,E,b,d,c]);const Ye=o.useRef(new Map);Ln(n&&le.current&&c.length>0?"sessions-changed":null,o.useCallback(i=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=i.key,u=h?c.filter(N=>(Le.current[N.path]||[]).some(S=>G(S.agent||"",S.sessionId)===h)):c,p=u.length?u:c,w=Ye.current;for(const N of p)w.has(N.path)&&clearTimeout(w.get(N.path)),w.set(N.path,setTimeout(()=>{w.delete(N.path),E(N.path,{background:!0,force:!0})},300))},[c,E]));const $e=o.useCallback(i=>{const h=i.agent||"";return!h||!i.sessionId?i:ys(i,ge[G(h,i.sessionId)]||null)},[ge]);Ln("stream-update",o.useCallback(i=>{const h=i.key;if(!h)return;const u=Ns(h,i.snapshot??null);qe(p=>{if(!u){const _=p[h];return!_||_.phase==="done"?p:{...p,[h]:{..._,phase:"done",updatedAt:Date.now()}}}const w=(_,D)=>!!_&&!!D&&_.phase===D.phase&&_.resolvedKey===D.resolvedKey&&_.sessionId===D.sessionId&&_.incomplete===D.incomplete&&_.error===D.error,N=w(p[h],u),S=u.resolvedKey===h||w(p[u.resolvedKey],{...u,key:u.resolvedKey});if(N&&S)return p;const R=Date.now()-Hr,F={};for(const[_,D]of Object.entries(p))D.phase==="done"&&D.updatedAt<R||(F[_]=D);return F[h]=u,u.resolvedKey!==h&&(F[u.resolvedKey]={...u,key:u.resolvedKey}),F})},[])),Ss(o.useCallback(()=>{if(!(!n||!le.current||c.length===0))for(const i of c)E(i.path,{background:!0,force:!0})},[n,c,E])),o.useEffect(()=>{if(!n||!le.current||c.length===0)return;const i=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)E(u.path,{background:!0,force:!0})};if(i(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&i()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,E,c]),o.useEffect(()=>{if(!n)return;const i=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const w=`${h.path}:${G(p.agent||"",p.sessionId)}`;if(Ie.current.has(w))return;const N=setTimeout(()=>{Ie.current.add(w),Y(p,h.path)},Ur+u*120);i.push(N)}),()=>{for(const h of i)clearTimeout(h)}},[n,d,Y,c]);const qt=o.useCallback(async i=>{try{(await ne.addWorkspace(i)).ok&&(Ve(!1),await be(),E(i))}catch{}},[be,E]),[xe,ve]=o.useState(null),[je,wt]=o.useState(!1),[ae,Oe]=o.useState(null),Xe=o.useCallback(i=>{ve(i)},[]),Ze=o.useCallback(async()=>{const i=xe;if(i){wt(!0);try{await ne.removeWorkspace(i),x(h=>h.filter(u=>u.path!==i)),m(h=>{const u={...h};return delete u[i],u}),P(h=>{const u=h.filter(p=>p.workdir!==i);return u.length!==h.length&&T(ze(u.length,q.current)),u}),O(0),ve(null)}catch{}finally{wt(!1)}}},[xe]),Je=o.useCallback(i=>{E(i,{force:!0})},[E]),[Me,we]=o.useState(null),[De,ut]=o.useState(!1),[ce,et]=o.useState(!1),tt=oe(i=>i.toast),[re,Ee]=o.useState(null),kt=o.useCallback((i,h,u)=>{Ee({anchor:{right:i.right,bottom:i.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:Pn(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);o.useEffect(()=>{if(!re)return;const i=()=>Ee(null),h=u=>{u.key==="Escape"&&i()};return window.addEventListener("mousedown",i),window.addEventListener("scroll",i,!0),window.addEventListener("resize",i),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",i),window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",i),window.removeEventListener("keydown",h)}},[re]);const ht=o.useCallback(i=>{ut(!1),we(i),Ee(null)},[]),ke=o.useCallback(async()=>{const i=Me;if(i){et(!0);try{const h=await ne.deleteSession(i.workdir,i.agent,i.sessionId,De);if(!h.ok){const u=h.error?.includes("still running")?r("session.deleteRunningError"):h.error||r("session.deleteFailed");tt(u,!1);return}m(u=>{const p=u[i.workdir];if(!p)return u;const w=p.filter(N=>!(N.agent===i.agent&&N.sessionId===i.sessionId));return w.length===p.length?u:{...u,[i.workdir]:w}}),P(u=>{const p=u.filter(w=>!(w.workdir===i.workdir&&w.agent===i.agent&&w.sessionId===i.sessionId));return p.length!==u.length&&T(ze(p.length,q.current)),p}),we(null)}catch(h){tt(h?.message||r("session.deleteFailed"),!1)}finally{et(!1)}}},[Me,De,r,tt]),yt=o.useCallback(i=>{P(h=>{let u=!1;const p=h.map(w=>w.mountKey===i&&(w.pendingPrompt!=null||w.pendingImageUrls)?(u=!0,{...w,pendingPrompt:null,pendingImageUrls:void 0}):w);return u?p:h})},[P]),xt=o.useCallback((i,h,u)=>{Y({agent:i.agent,sessionId:i.sessionId,runState:"running"},i.workdir),m(N=>{const S=N[i.workdir]||[];if(S.some(_=>_.sessionId===i.sessionId&&_.agent===i.agent))return N;const F={sessionId:i.sessionId,agent:i.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...N,[i.workdir]:[F,...S]}});const p=mt.current,w={...i,mountKey:Rt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};o.startTransition(()=>{_e(null),P(N=>{if(p>=N.length)return[...N,w];const S=[...N];return S[p]=w,S}),O(p>=0?p:0)}),E(i.workdir,{background:!0,force:!0})},[E,Y,P,O]),Nt=o.useCallback(i=>{H.current.length>=ie.current&&ie.current<hn&&T(ze(ie.current+1,q.current)),_e(i)},[T]),St=o.useCallback(()=>{_e(null),T(ze(H.current.length,q.current))},[T]),Ct=o.useCallback((i,h)=>{Y(i,h);const u=i.agent||"";H.current.some(p=>p.agent===u&&p.sessionId===i.sessionId)&&T(ze(H.current.length,q.current)),_e(null),o.startTransition(()=>{dt({agent:u,sessionId:i.sessionId,workdir:h})})},[Y,T]),Lt=o.useCallback((i,h)=>{Y({agent:i.agent,sessionId:i.sessionId,runState:"running"},i.workdir),o.startTransition(()=>{h!=null?(P(u=>{if(h>=u.length)return u;const p=[...u];return p[h]={...u[h],agent:i.agent,sessionId:i.sessionId,workdir:i.workdir},p}),O(h)):dt({...i,mountKey:Rt()})}),E(i.workdir,{background:!0,force:!0})},[E,Y]),de=o.useCallback(i=>{let h=i;if(ee==="running"?h=h.filter(u=>Bt(u)==="running"):ee==="review"&&(h=h.filter(u=>Bt(u)==="incomplete")),me.trim()){const u=me.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},[me,ee]),It=o.useMemo(()=>{const i={};for(const h of c){const u=(d[h.path]||[]).map($e),p=Ce[h.path],w=new Map;for(const S of u){const R=G(S.agent||"",S.sessionId),F=ge[R],_=p?Cn(p,S.agent||"",S.sessionId):S.sessionId,D=F?.resolvedKey&&F.resolvedKey!==R?F.resolvedKey:_!==S.sessionId?G(S.agent||"",_):R,Ae=w.get(D);if(!Ae){w.set(D,S);continue}G(Ae.agent||"",Ae.sessionId)!==D&&R===D&&w.set(D,S)}const N=de([...w.values()]);i[h.path]=Vr(N)}return i},[c,d,ge,Ce,de,$e]),pt=o.useCallback(i=>{const h=(d[i.workdir]||[]).find(u=>u.sessionId===i.sessionId&&u.agent===i.agent)??{sessionId:i.sessionId,agent:i.agent,runState:"running"};return $e(h)},[$e,d]),Qt=o.useMemo(()=>new Set($.map(i=>G(i.agent,i.sessionId))),[$]),Yt=fe?G(fe.agent,fe.sessionId):null,nt=o.useCallback(i=>{P(h=>{const u=h.filter((p,w)=>w!==i);return u.length===0?O(0):Se.current>=u.length&&O(u.length-1),T(ze(u.length,q.current)),u})},[P,O,T]);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:We,onChange:i=>Ge(i.target.value),placeholder:r("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"}),We&&e.jsx("button",{onClick:()=>Ge(""),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(i=>e.jsx("button",{onClick:()=>Be(i),className:L("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",ee===i?"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:r(`hub.filter${i[0].toUpperCase()+i.slice(1)}`)},i))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:v?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&&!He?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:r("hub.noWorkspaces")}):c.map(i=>e.jsx(no,{workspace:i,sessions:It[i.path]||[],loading:!!b[i.path]||!(i.path in d),isActive:i.path===l,selectedKey:Yt,openSessionKeys:Qt,onSelectSession:Ct,onNewSession:Nt,onRefresh:Je,onRemove:Xe,onExtensions:Oe,onWarmSession:jt,onCancelWarmSession:Te,onSessionMenuOpen:kt,t:r},i.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(i=>e.jsx("button",{onClick:()=>C(i),className:L("flex-1 flex items-center justify-center p-1.5 rounded transition-all",y===i?"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:r(`hub.layout${i}`),children:i===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"})}):i===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"})]}):i===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"})]})},i))}),e.jsxs(Pe,{variant:"ghost",size:"sm",onClick:()=>Ve(i=>!i),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"})]}),r("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(${y===6?3:y}, 1fr)`,gridTemplateRows:y===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const i=J?$.length<y?$.length:z:-1;return mt.current=i,Array.from({length:y},(h,u)=>{if(J&&u===i)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(eo,{workdir:J,workspaceName:c.find(S=>S.path===J)?.name||J.split("/").pop()||"",onSessionCreated:xt,onClose:St,t:r},J)},`new-${J}`);const p=$[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:r("hub.emptySlot")})]})},`empty-${u}`);const w=pt(p),N=u===z;return e.jsxs("div",{className:L("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",N?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:N?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>O(u),children:[e.jsxs("div",{className:L("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",N?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const S=Bt(w);return e.jsx(Vt,{variant:S==="running"?"ok":S==="waiting"?"info":S==="incomplete"?"warn":"idle",pulse:S==="running"||S==="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:w.title||w.lastQuestion?.slice(0,60)||(Dt(p.sessionId)?r("hub.newSession"):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:r("hub.created"),children:Cs(w.createdAt)}),w.runUpdatedAt&&e.jsx("span",{title:r("hub.updated"),children:Rn(w.runUpdatedAt)}),!!w.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),w.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:S=>{S.stopPropagation(),ue(R=>!R)},className:L("p-0.5 rounded transition-colors",M?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:r("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:S=>{S.stopPropagation(),nt(u)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:r("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(o.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Fr,{session:w,workdir:p.workdir,active:n&&N,onSessionChange:S=>Lt(S,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>yt(p.mountKey)},p.mountKey)})})]},p.mountKey||G(p.agent,p.sessionId))})})()})}),M&&fe&&e.jsx(ro,{workdir:fe.workdir,onClose:()=>ue(!1),t:r}),e.jsx(Jr,{open:He,initialPath:l||void 0,onAdd:qt,onClose:()=>Ve(!1),t:r}),e.jsxs(Ut,{open:!!xe,onClose:()=>!je&&ve(null),children:[e.jsx(zt,{title:r("hub.removeWorkspace"),onClose:()=>!je&&ve(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:r("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:r("modal.confirmRemoveWorkspaceHint")}),xe&&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:xe}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Pe,{variant:"ghost",onClick:()=>ve(null),disabled:je,children:r("modal.cancel")}),e.jsx(Pe,{variant:"primary",onClick:Ze,disabled:je,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:r(je?"modal.removing":"modal.remove")})]})]}),re&&(()=>{const h=Math.max(8,Math.min(re.anchor.right-160,window.innerWidth-160-8)),u=Math.min(re.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:()=>ht(re.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"})]}),r("session.delete")]})})})(),e.jsxs(Ut,{open:!!Me,onClose:()=>!ce&&we(null),children:[e.jsx(zt,{title:r("session.deleteTitle"),onClose:()=>!ce&&we(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:r("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:!De,onChange:()=>ut(!1),disabled:ce,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:r("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:r("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:De,onChange:()=>ut(!0),disabled:ce,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:r("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:r("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Pe,{variant:"ghost",onClick:()=>we(null),disabled:ce,children:r("modal.cancel")}),e.jsx(Pe,{variant:"primary",onClick:ke,disabled:ce,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:r(ce?"session.deleting":"modal.remove")})]})]}),e.jsx(Dr,{open:!!ae,onClose:()=>Oe(null),workdir:ae||""})]})});function Jr({open:t,initialPath:n,onAdd:s,onClose:l,t:r}){const[c,x]=o.useState(""),d=o.useCallback(m=>x(m),[]);return o.useEffect(()=>{t&&x("")},[t]),e.jsxs(Ut,{open:t,onClose:l,children:[e.jsx(zt,{title:r("hub.addWorkspace"),onClose:l}),e.jsx(Ms,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:r}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Pe,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:r("hub.add")}),e.jsx(Pe,{variant:"secondary",onClick:l,className:"flex-1",children:r("hub.cancel")})]})]})}function eo({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:r}){const[c,x]=o.useState(null),[d,m]=o.useState([]),b=o.useRef(null),g=o.useRef([]),v=o.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),k=o.useCallback(()=>{},[]),y=o.useCallback((W,$)=>{x(W||null),b.current=W||null;const U=$||[];m(U),g.current=U},[]),B=o.useCallback(W=>{const $=g.current;g.current=[],s(W,b.current||void 0,$.length?$:void 0)},[s]),A=!!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:r("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(Vt,{variant:A?"ok":"idle",pulse:A}),!A&&e.jsx("button",{onClick:l,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:A?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(ss,{text:c||"",blocks:d.map(W=>({type:"image",content:W})),t:r}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(Jn,{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:r("hub.newSessionHint")})})})}),e.jsx(ir,{session:v,workdir:t,onStreamQueued:k,onSendStart:y,onSessionChange:B,t:r,streamPhase:null})]})}function to({git:t}){if(!t)return null;const n=[t.detached?`detached HEAD${t.shortSha?` @ ${t.shortSha}`:""}`:`branch ${t.branch??"?"}`,t.upstream?`upstream ${t.upstream}`:t.detached?"":"no upstream",t.ahead||t.behind?`↑${t.ahead} ahead · ↓${t.behind} behind`:"",t.changed>0?`${t.changed} changed (${t.staged} staged · ${t.unstaged} unstaged · ${t.untracked} untracked)`:"clean"].filter(Boolean).join(`
23
+ `);return e.jsx(Ls,{content:n,className:L("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 no=o.memo(function({workspace:n,sessions:s,loading:l,isActive:r,selectedKey:c,openSessionKeys:x,onSelectSession:d,onNewSession:m,onRefresh:b,onRemove:g,onExtensions:v,onWarmSession:k,onCancelWarmSession:y,onSessionMenuOpen:B,t:A}){const[W,$]=o.useState(!0),[U,z]=o.useState(an);o.useEffect(()=>{z(an)},[s.length]);const Q=s.slice(0,U),T=s.length-U,K=n.path,[P,O]=o.useState(null),C=o.useCallback(()=>{ne.getWorkspaceGit(K).then(M=>O(M.git)).catch(()=>O(null))},[K]);return o.useEffect(()=>{C()},[C]),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:()=>$(M=>!M),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:L("shrink-0 text-fg-5 transition-transform duration-150",W&&"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:L("min-w-0 truncate text-[12px] font-semibold",r?"text-primary":"text-fg-3"),children:n.name}),e.jsx(to,{git:P})]}),r&&e.jsx(Vt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:M=>{M.stopPropagation(),m(K)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:A("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:M=>{M.stopPropagation(),v(K)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:A("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:M=>{M.stopPropagation(),b(K),C()},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"})]})}),!r&&e.jsx("button",{onClick:M=>{M.stopPropagation(),g(K)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),W&&e.jsx("div",{className:"pb-1",children:l?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:A("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[Q.map(M=>{const ue=G(M.agent||"",M.sessionId),ie=M.__forkDepth||0;return e.jsx(so,{session:M,isSelected:c===ue,isOpen:x?.has(ue)??!1,forkDepth:ie,onClick:()=>d(M,K),onWarm:()=>k(M,K),onCancelWarm:()=>y(M,K),onShowMenu:q=>B(q,M,K),menuLabel:A("session.openActions")},ue)}),T>0&&e.jsxs("button",{onClick:()=>z(M=>M+an),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:["+ ",A("hub.nMore").replace("{n}",String(T))]}),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"})})]})]})})]})}),so=o.memo(function({session:n,isSelected:s,isOpen:l,forkDepth:r=0,onClick:c,onWarm:x,onCancelWarm:d,onShowMenu:m,menuLabel:b}){const g=cn(n.agent||""),v=Bt(n),k=Pn(n).slice(0,500)||(Dt(n.sessionId)?"":n.sessionId.slice(0,16)),y=Is(n,k).slice(0,500),B=n.model?Ft(n.model):null,A=r>0?Math.min(r,3)*14:0,W=l?10:12,$=o.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:x,onFocus:x,onMouseLeave:d,onBlur:d,className:L("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":l?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:W+A,...l?{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:[r>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(lt,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),B&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:B}),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(Vt,{variant:v==="running"?"ok":v==="waiting"?"info":v==="incomplete"?"warn":"idle",pulse:v==="running"||v==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:k})]}),y&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:y})})]}),e.jsx("button",{ref:$,type:"button","aria-label":b,"aria-haspopup":"menu",onMouseDown:U=>{U.stopPropagation()},onClick:U=>{U.stopPropagation(),U.preventDefault(),$.current&&m($.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"})]})})]})}),ro=o.memo(function({workdir:n,onClose:s,t:l}){const r=oe(g=>g.state?.hostApp??null),c=oe(g=>g.state?.platform??null),x=oe(g=>g.toast),[d,m]=o.useState(()=>Xr(r,c)),b=o.useCallback(async g=>{try{const v=await ne.openInEditor(g,d);if(!v.ok)throw new Error(v.error||`Failed to open ${g}`)}catch(v){x(v?.message||String(v),!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:l("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:l("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(Ts,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:l(rs(g))})),onChange:g=>{Yr(g)&&m(g)},renderIcon:g=>e.jsx(os,{target:g,size:14})}),e.jsx(Pe,{size:"sm",variant:"ghost",onClick:()=>b(n),className:"flex-1 min-w-0 text-[11px]",children:l("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(oo,{basePath:n,openTarget:d,onOpenPath:b,t:l})})]})});function os({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(lt,{brand:t,size:n})}function oo({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:l,t:r}){const[c,x]=o.useState([]),[d,m]=o.useState(!0);o.useEffect(()=>{let g=!1;return m(!0),ne.lsDir(t,!0,n).then(v=>{!g&&v.ok&&x(v.dirs.slice(0,50).map(k=>({entry:k,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||m(!1)}),()=>{g=!0}},[t,n]);const b=o.useCallback(g=>{const v=k=>k.map(y=>y.entry.path===g?y.expanded?{...y,expanded:!1}:y.children===null?(ne.lsDir(g,!0,n).then(B=>{B.ok&&x(A=>xn(A,g,{children:B.dirs.slice(0,50).map(W=>({entry:W,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(B=>xn(B,g,{children:[],loading:!1}))}),{...y,loading:!0,expanded:!0}):{...y,expanded:!0}:y.children?{...y,children:v(y.children)}:y);x(k=>v(k))},[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(is,{nodes:c,depth:0,onToggle:b,openTarget:s,onOpenPath:l,t:r})})}function is({nodes:t,depth:n,onToggle:s,openTarget:l,onOpenPath:r,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(io,{node:x,depth:n,onToggle:s,openTarget:l,onOpenPath:r,t:c},x.entry.path))})}function io({node:t,depth:n,onToggle:s,openTarget:l,onOpenPath:r,t:c}){const{entry:x,expanded:d,children:m,loading:b}=t,g=n*14,[v,k]=o.useState(!1),y=c(rs(l)),B=c("hub.openWithTarget").replace("{target}",y);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>k(!0),onMouseLeave:()=>k(!1),className:L("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?b?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:L("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}),v&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:A=>{A.stopPropagation(),r(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:B,children:e.jsx(os,{target:l,subtle:!0})}),!x.isDir&&e.jsx(lo,{filePath:x.path,t:c})]})]}),x.isDir&&d&&m&&m.length>0&&e.jsx(is,{nodes:m,depth:n+1,onToggle:s,openTarget:l,onOpenPath:r,t:c})]})}function lo({filePath:t,t:n}){const[s,l]=o.useState(!1);return e.jsx("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},className:L("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 xn(t,n,s){return t.map(l=>l.entry.path===n?{...l,...s}:l.children?{...l,children:xn(l.children,n,s)}:l)}const Lo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Zr},Symbol.toStringTag,{value:"Module"}));export{ir as I,So as L,vr as R,Co as T,ss as U,ko as a,Zn as b,zs as c,vo as d,jo as e,Jn as f,No as g,Br as h,Lo as i,Ds as l,yo as m,wo as n,bo as o,Os as p,mo as s};