pikiloom 0.4.57 → 0.4.59

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 (23) hide show
  1. package/dashboard/dist/assets/{AgentTab-C70YRlou.js → AgentTab-0iSS-Bby.js} +1 -1
  2. package/dashboard/dist/assets/{ConnectionModal-BPt5l2wn.js → ConnectionModal-DRg8X2s1.js} +1 -1
  3. package/dashboard/dist/assets/{DirBrowser-DZf3XKxC.js → DirBrowser-Br3AnAYT.js} +1 -1
  4. package/dashboard/dist/assets/{ExtensionsTab-T2alhEfj.js → ExtensionsTab-CHO2uMeN.js} +1 -1
  5. package/dashboard/dist/assets/{IMAccessTab-DTsO14F0.js → IMAccessTab-7v8e2UqN.js} +1 -1
  6. package/dashboard/dist/assets/{Modal-C-vJb5Y9.js → Modal-bvNc9zVs.js} +1 -1
  7. package/dashboard/dist/assets/{Modals-DH5AsfTd.js → Modals-CXBXc4Xx.js} +1 -1
  8. package/dashboard/dist/assets/{Select-BwFCJffL.js → Select-D-rJwrhF.js} +1 -1
  9. package/dashboard/dist/assets/SessionPanel-CoIrjkQt.js +1 -0
  10. package/dashboard/dist/assets/{SystemTab-CcL68JTe.js → SystemTab-NTIGkssg.js} +1 -1
  11. package/dashboard/dist/assets/index-BO-FYAny.css +1 -0
  12. package/dashboard/dist/assets/index-CPmFmj6P.js +23 -0
  13. package/dashboard/dist/assets/index-h42cuqnj.js +3 -0
  14. package/dashboard/dist/assets/{shared-nIWLHc59.js → shared-CUTx2Dth.js} +1 -1
  15. package/dashboard/dist/index.html +2 -2
  16. package/dist/agent/drivers/claude.js +6 -2
  17. package/dist/agent/drivers/codex.js +24 -4
  18. package/dist/dashboard/routes/sessions.js +46 -10
  19. package/package.json +1 -1
  20. package/dashboard/dist/assets/SessionPanel-BIR5_DfM.js +0 -1
  21. package/dashboard/dist/assets/index-C-0KAo9r.js +0 -23
  22. package/dashboard/dist/assets/index-DjGKuUL5.js +0 -3
  23. package/dashboard/dist/assets/index-N_mAxxEJ.css +0 -1
@@ -0,0 +1,23 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-CoIrjkQt.js","assets/react-vendor-C7Sl8SE7.js","assets/index-h42cuqnj.js","assets/router-DHISdpPk.js","assets/index-BO-FYAny.css","assets/Modal-bvNc9zVs.js","assets/Select-D-rJwrhF.js","assets/DirBrowser-Br3AnAYT.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-CHO2uMeN.js"])))=>i.map(i=>d[i]);
2
+ import{c as C,a as ie,u as le,i as dt,f as _t,A as js,s as zt,S as ge,B as ut,g as dn,w as ws,b as ks,C as fn,d as ys,r as In,e as Ln,h as Ns,n as Ss,j as Cs,k as _n,l as Dt,m as We,D as Gt,o as Is,p as Wn,_ as Bn,T as Ls,q as Ts}from"./index-h42cuqnj.js";import{j as e,r as i,a as gn}from"./react-vendor-C7Sl8SE7.js";import{I as Es}from"./Select-D-rJwrhF.js";import{M as Kt,a as Ht}from"./Modal-bvNc9zVs.js";import{D as Ms}from"./DirBrowser-Br3AnAYT.js";import{n as As,r as Ps,M as mn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Rs}from"./ExtensionsTab-CHO2uMeN.js";function _s({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("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 ht({open:t,onToggle:n,dot:s,label:a,preview:r,badge:c,collapsedContent:p,children:d,className:m}){return e.jsxs("div",{className:C("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:C("h-[7px] w-[7px] shrink-0 rounded-full",s.color,s.pulse&&"animate-pulse")}),e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:a}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:r}),c,e.jsx(_s,{open:t})]}),!t&&p,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Ws=5e3,Bs=15e3,Ft=8,Ut=30,$s=1,ct=new Map,Ie=new Map,on=new Set,$n=[];let Wt=0;function an(t){return typeof t=="number"&&Number.isFinite(t)}function qe(t,n,s,a){for(t.delete(n),t.set(n,s);t.size>a;){const r=t.keys().next().value;if(!r)break;t.delete(r)}}function On(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(qe(t,n,s,t===Ie?Ut:Ft),s.value)}function Dn(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:an(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:an(t.turnOffset)?t.turnOffset:void 0,turnLimit:an(t.turnLimit)?t.turnLimit:void 0}}function bn(t){const n=Dn(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function Fn(){for(;Wt<$s;){const t=$n.shift();if(!t)return;Wt+=1,t().finally(()=>{Wt=Math.max(0,Wt-1),Fn()})}}async function Os(t,n={}){const s=t;if(!n.force){const c=On(ct,s);if(c)return c}const a=ct.get(s);if(a?.promise)return a.promise;const r=ie.getWorkspaceSessions(t,n.request).then(c=>(qe(ct,s,{value:c,expiresAt:c.ok?Date.now()+Ws:0},Ft),c)).finally(()=>{const c=ct.get(s);c?.promise&&qe(ct,s,{value:c.value,expiresAt:c.expiresAt},Ft)});return qe(ct,s,{value:a?.value,expiresAt:a?.expiresAt??0,promise:r},Ft),r}function Ds(t,n={}){const s=bn(t),a=Ie.get(s);return a?.value?.ok&&(n.allowStale||a.expiresAt>Date.now())?a.value:null}async function Fs(t,n={}){const s=Dn(t),a=bn(s);if(!n.force){const p=On(Ie,a);if(p?.ok)return p}const r=Ie.get(a);if(r?.promise)return r.promise;const c=ie.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(p=>(qe(Ie,a,{value:p,expiresAt:p.ok?Date.now()+Bs:0},Ut),p)).finally(()=>{const p=Ie.get(a);p?.promise&&qe(Ie,a,{value:p.value,expiresAt:p.expiresAt},Ut)});return qe(Ie,a,{value:r?.value,expiresAt:r?.expiresAt??0,promise:c},Ut),c}function Us(t){const n=bn(t);Ds(t)||on.has(n)||Ie.get(n)?.promise||(on.add(n),$n.push(async()=>{try{await Fs(t)}catch{}finally{on.delete(n)}}),Fn())}function So(t){const n=t.streaming||t.liveStreamPhase==="streaming",s=t.queuedTaskCount>0||t.pendingQueuedCount>0||t.streamPhase==="queued";return n||s}function Co(t){const{pendingTaskId:n,streamTaskId:s,queuedTaskIds:a}=t;return!n||n===s?!1:!!a&&a.includes(n)}function zs(t){const{queuedTaskIds:n,streamPhase:s,streamTaskId:a,localTaskId:r}=t,c=[];n&&n.length&&c.push(...n),s==="queued"&&a&&!c.includes(a)&&c.unshift(a),r&&!c.includes(r)&&(s==="queued"||!s)&&c.push(r);const p=s==="streaming"?a??null:null;return p?c.filter(d=>d!==p):c}function Io(t,n){return t==null||n==null?!0:t===n}function Lo(t){return t.liveTurnStreaming||t.pendingBubbleDots||t.streamPhase==="done"&&!t.streaming&&t.queuedTaskCount===0&&t.pendingQueuedCount===0?!1:t.sessionRunning||t.streaming||t.streamPhase==="streaming"||t.streamPhase==="queued"||t.queuedTaskCount>0||t.pendingQueuedCount>0}function pt(t){return(t||"").replace(/\s+/g," ").trim()}function Ks(t,n){return pt(t)===pt(n)}function Hs(t,n){const s=pt(t),a=pt(n);return!!s&&!!a&&s!==a&&s.endsWith(a)}function Vs(t,n){return n&&(!t||Hs(n,t))?n:t||n||null}function To(t,n){return!Vs(t,n)}function Eo(t,n){if(Ks(t,n))return!0;const s=pt(t),a=pt(n);if(!s||!a||s.length>=a.length||!/(?:\.\.\.|…)$/.test(s))return!1;const r=s.replace(/(?:\s*(?:\.\.\.|…))+$/,"").trim(),c=r.length-4;return c<32?!1:a.startsWith(r.slice(0,c))}function Mo(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(p=>({role:p.role,text:p.text,blocks:[{type:"text",content:p.text}]}))||[],s=qs(n),a=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),r=t.window?.endTurn??a,c=t.window?.startTurn??Math.max(0,r-s.length);return{turns:s,startTurn:c,endTurn:r,totalTurns:a,hasOlder:t.window?.hasOlder??c>0}}function Ao(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 Po(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 Gs(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
3
+
4
+ `),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function qs(t){const n=[];let s={user:null,assistant:null};for(const a of t)if(a.role==="user"){if(s.assistant&&Un(a.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=a}else s.assistant?s.assistant=Gs(s.assistant,a):s.assistant=a;return(s.user||s.assistant)&&n.push(s),n}const Qs=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"]),Ys=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function Un(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Qs.has(s[1].toLowerCase())?!0:Ys.some(a=>t.includes(a))}function vn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function zn(t){return`${vn(t)} tok`}function Kn(t){return t>=85?"bg-rose-400/70":t>=60?"bg-amber-400/70":"bg-emerald-400/70"}function Xs(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),a=n%60;return s<60?`${s}m${a.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function Hn(t,n){const s=t.split(`
5
+ `).filter(a=>a.trim());return s.length<=n?s.join(`
6
+ `):s.slice(-n).join(`
7
+ `)}function Zs(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 Js(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}const er=/\.(png|jpe?g|gif|webp|bmp|svg|avif|heic|heif|tiff?|ico)$/i;function Tn(t){return t.type?t.type.startsWith("image/"):er.test(t.name||"")}function tr(t){const n=[],s=/<img\b[^>]*?\bsrc\s*=\s*["'](data:image\/[^"']+)["']/gi;let a;for(;a=s.exec(t);)n.push(a[1]);return n}function nr(t,n="pasted-image"){const s=/^data:(image\/[a-z0-9.+-]+);base64,(.*)$/is.exec(t.trim());if(!s)return null;const a=s[1].toLowerCase();try{const r=atob(s[2].replace(/\s+/g,"")),c=new Uint8Array(r.length);for(let d=0;d<r.length;d++)c[d]=r.charCodeAt(d);const p=a.split("/")[1]?.split("+")[0]||"png";return new File([c],`${n}.${p}`,{type:a})}catch{return null}}async function sr(){try{if(typeof navigator>"u"||!navigator.clipboard?.read)return[];const t=await navigator.clipboard.read(),n=[];for(const s of t){const a=s.types.find(p=>p.startsWith("image/"));if(!a)continue;const r=await s.getType(a),c=a.split("/")[1]?.split("+")[0]||"png";n.push(new File([r],`pasted-image.${c}`,{type:a}))}return n}catch{return[]}}function Vn(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 rr(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 G(t,n=120){if(t==null)return"";const a=(typeof t=="string"?t:String(t)).replace(/\s+/g," ").trim();return a.length<=n?a:a.slice(0,Math.max(0,n-1))+"…"}function or(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 Gn(t){const n=String(t.toolName||"").trim()||"Tool",s=or(t.content);if(!s)return n;const a=G(s.description,120);switch(n){case"Read":{const r=G(s.file_path||s.path,140);return r?`Read ${r}`:"Read"}case"Edit":{const r=G(s.file_path||s.path,140);return r?`Edit ${r}`:"Edit"}case"Write":{const r=G(s.file_path||s.path,140);return r?`Write ${r}`:"Write"}case"Glob":{const r=G(s.pattern||s.glob,120);return r?`Glob ${r}`:"Glob"}case"Grep":{const r=G(s.pattern||s.query,120);return r?`Grep ${r}`:"Grep"}case"WebFetch":{const r=G(s.url,120);return r?`WebFetch ${r}`:"WebFetch"}case"WebSearch":{const r=G(s.query,120);return r?`WebSearch ${r}`:"WebSearch"}case"TodoWrite":return"Update plan";case"TaskCreate":{const r=G(s.subject,120);return r?`Create task: ${r}`:"Create task"}case"TaskUpdate":{const r=G(s.taskId,24),c=G(s.status,24);return r?`Update task ${r}${c?` → ${c}`:""}`:"Update task"}case"AskUserQuestion":{const c=(Array.isArray(s.questions)?s.questions:[])[0],p=G(c?.question||s.question,120);return p?`Ask user: ${p}`:"Ask user"}case"Task":{const r=G(s.description||s.prompt,120);return r?`Task: ${r}`:"Task"}case"Bash":{if(a)return`Bash: ${a}`;const r=G(s.command,120);return r?`Bash: ${r}`:"Bash"}case"exec_command":case"shell":case"local_shell":{const r=G(s.cmd||s.command,140);return r?`Run shell: ${r}`:"Run shell"}case"apply_patch":{const r=G(s.path||s.file_path,140);return r?`Edit ${r}`:"Edit files"}default:{const r=n.match(/^mcp__[^_]+__(.+)$/),c=r?r[1]:n;if(c==="im_send_file"){const d=G(s.path,120);return d?`Send file: ${d}`:"Send file"}if(c==="im_list_files")return"List workspace files";if(a)return`${n}: ${a}`;const p=G(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return p?`${n}: ${p}`:n}}}function ir(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
8
+ `).map(a=>a.trim()).find(Boolean)||"";return s?G(s,140):"result"}function ar(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),a=t.slice(n+1).trim();return!s||!a?null:{agent:s,sessionId:a}}const vt=new Map;function lr(t,n){return`${t}:${n}`}const cr=[],dr=[],ur={};function hr(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 pr=i.memo(function({session:n,workdir:s,onStreamQueued:a,onSendStart:r,onSendTaskAssigned:c,onSessionChange:p,t:d,streamPhase:m,streamTaskId:v,queuedTaskIds:g,queuedTasks:j,pendingQueuedSends:N,onRecall:k,onSteer:$,onStopAll:O,editDraft:M,onEditDraftConsumed:P,onSelectionChange:K}){const[U,Y]=i.useState(""),[A,te]=i.useState(!1),[T,D]=i.useState(null),[I,Z]=i.useState(()=>new Set),[R,ne]=i.useState(()=>new Set),Q=i.useRef({prompt:"",files:[]}),pe=le(l=>l.agentStatus?.agents??null),[V,wt]=i.useState(pe||[]),[me,xt]=i.useState(""),[Ye,Xe]=i.useState(""),[se,$e]=i.useState(void 0),[Oe,Ze]=i.useState(""),[re,De]=i.useState([]),[be,Je]=i.useState(null),[Le,kt]=i.useState(null),[ve,ce]=i.useState(null),[et,Te]=i.useState(null),[yt,Ee]=i.useState(null),[je,we]=i.useState(void 0),[E,xe]=i.useState("closed"),[J,Nt]=i.useState(null),Me=i.useRef(null),tt=i.useRef(!1),Fe=i.useRef(null),Qt=i.useRef(null),fe=i.useRef(null),ke=i.useRef([]),[ye,St]=i.useState([]),[de,Ue]=i.useState(!1),[nt,st]=i.useState(0),rt=i.useRef(null),Ae=le(l=>l.refreshAgentStatus),Ne=le(l=>l.modelLayer),ze=le(l=>l.ensureModelLayer),ft=le(l=>l.refreshModelLayer),ue=Ne?.providers??cr,ot=Ne?.profiles??dr,it=Ne?.activeProfiles??ur;i.useEffect(()=>{ze()},[ze]),i.useEffect(()=>{pe?.length&&wt(pe)},[pe]),i.useEffect(()=>{ke.current=re},[re]);const ae=lr(n.agent||"",n.sessionId),Pe=i.useRef(ae);Pe.current=ae,i.useEffect(()=>{const l=vt.get(ae);return l&&(vt.delete(ae),l.text&&Y(l.text),l.files.length&&De(l.files.map(ln))),()=>{const f=Me.current?.value||"",w=ke.current.map(L=>L.file);for(const L of ke.current)URL.revokeObjectURL(L.previewUrl);f||w.length?vt.set(Pe.current,{text:f,files:w}):vt.delete(Pe.current)}},[ae]);const Ct=i.useRef({agent:n.agent||"",sessionId:n.sessionId});i.useEffect(()=>{const l=Ct.current,f={agent:n.agent||"",sessionId:n.sessionId};Ct.current=f,!(l.agent===f.agent&&dt(l.sessionId)&&!dt(f.sessionId))&&(xt(""),Xe(""),$e(void 0),Ze(""),ce(null),Te(null),Ee(null),xe("closed"))},[n.agent,n.sessionId]),i.useEffect(()=>{M!=null&&(Y(M),P?.(),requestAnimationFrame(()=>{const l=Me.current;l&&(l.focus(),l.setSelectionRange(M.length,M.length))}))},[M,P]),i.useEffect(()=>{if(!s)return;let l=!1;return ie.getSkills(s).then(f=>{!l&&f.ok&&St(f.skills)}).catch(()=>{}),()=>{l=!0}},[s]);const gt=de?(()=>{const l=U.match(/^\/(\S*)$/);return l?l[1].toLowerCase():null})():null,Se=gt!==null?ye.filter(l=>l.name.toLowerCase().includes(gt)||l.label&&l.label.toLowerCase().includes(gt)):[];i.useEffect(()=>{st(0)},[de,U]),i.useEffect(()=>{if(!de||!rt.current)return;const l=rt.current.querySelector(`[data-skill-idx="${nt}"]`);l&&l.scrollIntoView({block:"nearest"})},[nt,de]),i.useEffect(()=>{if(!de)return;const l=f=>{rt.current?.contains(f.target)||Me.current?.contains(f.target)||Ue(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[de]),i.useEffect(()=>{if(E==="closed")return;const l=f=>{const w=f.target;fe.current?.contains(w)||document.getElementById("cascade-portal")?.contains(w)||(xe("closed"),ce(null),Te(null),Ee(null))};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[E]),i.useLayoutEffect(()=>{if(E==="closed"||!fe.current){Nt(null);return}const l=fe.current.getBoundingClientRect();Nt({left:l.left,bottom:window.innerHeight-l.top+8})},[E]);const It=g&&g.length?g[0]:null;i.useEffect(()=>{T&&(It||m!==null&&m!=="queued")&&D(null)},[m,T,It]),i.useEffect(()=>{const l=Me.current;l&&(l.style.height="auto",l.style.height=Math.min(l.scrollHeight,200)+"px")},[U]);const Ke=i.useCallback(l=>{const f=Array.from(l||[]).filter(Tn);f.length&&De(w=>[...w,...f.map(ln)])},[]),Lt=i.useCallback(()=>{Je(null),De(l=>(Js(l),[]))},[]),Tt=i.useCallback(l=>{De(f=>{const w=f.find(L=>L.id===l);return w&&URL.revokeObjectURL(w.previewUrl),f.filter(L=>L.id!==l)}),Je(f=>f===l?null:f)},[]),Et=i.useCallback(()=>{const l=U.trim(),f=re.map(ee=>ee.file);if(!l&&f.length===0||A)return;const w=me||n.agent||V.find(ee=>ee.isDefault)?.agent||"";if(!w)return;const L=V.find(ee=>ee.agent===w)||null,H=!!n.agent&&w===n.agent,oe=(Ye||H&&n.model||""||L?.selectedModel||"").trim()||null,Ce=se!==void 0?se:H&&n.model?n.profileId??null:void 0,_e=w==="gemini"?null:(Oe||(H?_t(w,n.thinkingEffort,n.workflowEnabled):"")||_t(w,L?.selectedEffort,L?.workflowEnabled)||"").trim()||null,B=w!==n.agent,X=B?"":n.sessionId,rn=B&&n.agent?n.agent:null,bs=B&&n.sessionId?n.sessionId:null;te(!0),Q.current={prompt:l,files:f},Y(""),vt.delete(Pe.current);const vs=f.length?f.map(ee=>URL.createObjectURL(ee)):void 0;Lt(),r(l,vs),a(),ie.sendSessionMessage(s,w,X,l,{attachments:f,model:oe,profileId:Ce,effort:_e,previousAgent:rn,previousSessionId:bs}).then(ee=>{if(ee.taskId&&(D(ee.taskId),c?.(ee.taskId)),!ee.ok)return;const bt=typeof ee.sessionKey=="string"?ar(ee.sessionKey):null;bt&&(bt.agent!==n.agent||bt.sessionId!==n.sessionId)&&bt&&p?.({...bt,workdir:s})}).catch(()=>{}).finally(()=>te(!1))},[V,Lt,re,U,r,c,p,a,me,Oe,Ye,se,A,n.agent,n.sessionId,n.model,n.profileId,s]),Mt=m==="streaming",he=zs({queuedTaskIds:g,streamPhase:m,streamTaskId:v,localTaskId:T}),At=he[he.length-1]||null,mt=he.length>0,Yt=mt||Mt;i.useEffect(()=>{const l=f=>he.includes(f)||f===v;Z(f=>{let w=!1;const L=new Set;for(const H of f)l(H)?L.add(H):w=!0;return w?L:f}),ne(f=>{let w=!1;const L=new Set;for(const H of f)l(H)?L.add(H):w=!0;return w?L:f})},[he,v]),i.useEffect(()=>{!mt&&Q.current.files.length&&(Q.current={prompt:"",files:[]})},[mt]);const Xt=i.useCallback(l=>{if(!I.has(l)){if(Z(f=>{const w=new Set(f);return w.add(l),w}),l===At){const f=Q.current;f.prompt&&Y(f.prompt),f.files.length&&De(f.files.map(ln)),Q.current={prompt:"",files:[]}}k?.(l),l===T&&D(null)}},[I,At,T,k]),[at,o]=i.useState(!1),h=i.useCallback(async()=>{if(!(at||!O)){o(!0);try{await O()}finally{o(!1)}}},[at,O]),u=i.useCallback(l=>{R.has(l)||(ne(f=>{const w=new Set(f);return w.add(l),w}),$?.(l),l===T&&D(null))},[R,T,$]),x=i.useCallback(l=>{Y(`/${l.name} `),Ue(!1),requestAnimationFrame(()=>{const f=Me.current;f&&(f.focus(),f.setSelectionRange(f.value.length,f.value.length))})},[]),b=i.useCallback(l=>{Y(l);const f=/^\/\S*$/.test(l)&&ye.length>0;Ue(f)},[ye.length]),y=l=>{if(de&&Se.length>0){if(l.key==="ArrowDown"){l.preventDefault(),st(f=>(f+1)%Se.length);return}if(l.key==="ArrowUp"){l.preventDefault(),st(f=>(f-1+Se.length)%Se.length);return}if(l.key==="Tab"||l.key==="Enter"&&!l.shiftKey&&!tt.current){l.preventDefault(),x(Se[nt]);return}if(l.key==="Escape"){l.preventDefault(),Ue(!1);return}}l.key==="Enter"&&!l.shiftKey&&!tt.current&&(l.preventDefault(),Et())},S=i.useCallback(l=>{const f=l.clipboardData;if(!f)return;const w=Array.from(f.items).filter(B=>B.kind==="file").map(B=>B.getAsFile()).filter(B=>!!B&&Tn(B));if(w.length){l.preventDefault(),Ke(w);return}const L=f.getData("text/html"),H=L?tr(L):[],oe=(f.getData("text/uri-list")||f.getData("text/plain")||"").trim();/^data:image\//i.test(oe)&&H.push(oe);const Ce=H.map(B=>nr(B)).filter(B=>!!B);if(Ce.length){l.preventDefault(),Ke(Ce);return}(Array.from(f.items).some(B=>B.kind==="file")||Array.from(f.types||[]).some(B=>B==="Files"||B.startsWith("image/")))&&!oe&&(l.preventDefault(),sr().then(B=>{B.length&&Ke(B)}))},[Ke]),_=me||n.agent||V.find(l=>l.isDefault)?.agent||V.find(l=>l.installed)?.agent||V[0]?.agent||"",z=V.find(l=>l.agent===_)||null,W=ve||_,F=V.find(l=>l.agent===W)||z,Re=i.useMemo(()=>{if(!F)return[];const l=[];for(const w of F.models||[])l.push({id:w.id,label:w.id,kind:"native",description:w.alias&&w.alias.toLowerCase()!==w.id.toLowerCase()?w.alias:void 0});const f=new Set(js[W]||[]);for(const w of ot){const L=ue.find(oe=>oe.id===w.providerId);if(!L||!f.has(L.kind))continue;const H=w.name.trim().toLowerCase()!==w.modelId.trim().toLowerCase();l.push({id:w.modelId,label:w.name,kind:"profile",profileId:w.id,description:H?`${L.name} · ${w.modelId}`:L.name})}return l},[F,W,ot,ue]),yn=i.useMemo(()=>Re.findIndex(l=>l.kind==="profile"),[Re]),cs=it[W]||null,Zt=!!n.agent&&_===n.agent,Pt=se!==void 0?se:Zt?n.profileId??null:void 0,Rt=Ye||Zt&&n.model||""||z?.selectedModel||"",Jt=_==="gemini"?"":Oe||(Zt?_t(_,n.thinkingEffort,n.workflowEnabled):"")||_t(_,z?.selectedEffort,z?.workflowEnabled)||"";i.useEffect(()=>{K?.({model:Rt||null,effort:Jt||null})},[Rt,Jt,K]);const ds=z?.effortOptions??[],He=be&&re.find(l=>l.id===be)||null,us=He?{key:He.id,url:He.previewUrl,name:He.file.name,size:He.file.size,file:He.file,onRemove:()=>Tt(He.id)}:Le?{key:Le,url:Le}:null,Nn=(!!U.trim()||re.length>0)&&!A&&!!_,en=()=>{ce(null),Te(null),Ee(null),we(void 0)},Sn=i.useCallback((l,f,w)=>{xt(l),Xe(f),w!==void 0&&$e(w),l!==_&&Ze(""),en(),xe("closed")},[_]),hs=i.useCallback(l=>{Ze(l),Ee(null)},[]),ps=()=>{E==="closed"?(en(),Ae(),ft(),xe("agent")):(en(),xe("closed"))},tn=ve||_,Cn=dn(tn),nn=et??Rt,xs=yt??Jt,fs=nn?zt(nn):"",Ve=(()=>{const l=!ve&&Pt!==void 0?Pt:it[tn]??null;return l?ot.find(f=>f.id===l)??null:null})(),lt=Ve?ue.find(l=>l.id===Ve.providerId)??null:null,gs=lt?hr(lt):null,sn=Ve?Ve.name.trim().toLowerCase()!==Ve.modelId.trim().toLowerCase()?Ve.name:zt(Ve.modelId):fs,ms=[Cn.shortLabel,lt?lt.name:null,sn||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:[Yt&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[Mt&&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(ge,{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:at,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:[at?e.jsx(ge,{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")]})]}),he.map((l,f)=>{const w=f===he.length-1,L=R.has(l),H=L?d("hub.steering"):he.length>1?`${d("hub.queued")} #${f+1}`:d("hub.queued"),oe=N?.find(X=>X.taskId===l)||(w?N?.find(X=>!X.taskId):void 0),Ce=j?.find(X=>X.taskId===l)||null,_e=Ce?.prompt||oe?.prompt||null,B=oe?.imageUrls?.length?oe.imageUrls:(Ce?.attachments||[]).filter(X=>X.type==="image").map(X=>X.content);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:[L?e.jsx(ge,{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:H}),B.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[B.slice(0,3).map((X,rn)=>e.jsx("button",{type:"button",onClick:()=>kt(X),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:X,alt:"",className:"h-full w-full object-cover"})},`${X}-${rn}`)),B.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",B.length-3]})]}),_e&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:_e})]}),!L&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>u(l),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:()=>Xt(l),disabled:I.has(l),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:[I.has(l)?e.jsx(ge,{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")]})]})]},l)})]}),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:Fe,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:l=>{Ke(l.target.files),l.target.value=""}}),re.length>0&&e.jsx("div",{className:"px-4 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:re.map(l=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>Je(l.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:l.previewUrl,alt:l.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:l.file.name})})]}),e.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),Tt(l.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"})]})})]},l.id))})}),de&&Se.length>0&&e.jsxs("div",{ref:rt,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:Se.map((l,f)=>e.jsxs("button",{"data-skill-idx":f,onMouseDown:w=>{w.preventDefault(),x(l)},onMouseEnter:()=>st(f),className:C("flex flex-col w-full px-3 py-1.5 text-left transition-colors",f===nt?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",l.name]}),(l.label||l.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:l.label||l.description})]},l.name))})]}),e.jsx("textarea",{ref:Me,value:U,onChange:l=>b(l.target.value),onPaste:S,onKeyDown:y,onCompositionStart:()=>{tt.current=!0},onCompositionEnd:()=>{tt.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:U.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:()=>Fe.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:fe,onClick:ps,disabled:!V.length,title:V.length?ms:void 0,className:C("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:[V.length?e.jsx(ut,{brand:tn,size:12}):e.jsx(ge,{className:"h-3 w-3"}),V.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:Cn.shortLabel}),lt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(ut,{brand:gs||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:lt.name})]}),sn&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:nn||void 0,children:sn})]})]}):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:C("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"&&J&&gn.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:J.left,bottom:J.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:()=>xe("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=F?.capabilities?.modelSwitch!==!1?["agent","model"]:["agent"],w=f.indexOf(E);return f.map((L,H)=>e.jsx("span",{className:C("w-1.5 h-1.5 rounded-full transition-colors",E===L?"bg-primary":H<w?"bg-primary/40":"bg-fg-5/15")},L))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[E==="agent"&&V.filter(l=>l.installed).map(l=>{const f=dn(l.agent),w=ws(l.usage),L=w?ks(w):"ok";return e.jsxs(un,{selected:l.agent===(ve||_),onClick:()=>{if(ce(l.agent),Te(l.selectedModel||""),Ee(l.selectedEffort||""),!(l.capabilities?.modelSwitch!==!1)){Sn(l.agent,l.selectedModel||"");return}xe("model")},children:[e.jsx(ut,{brand:l.agent,size:14}),e.jsx("span",{style:{color:f.color},children:f.label}),w&&e.jsxs("span",{className:C("ml-auto font-mono text-[10px]",L==="err"?"text-err":L==="warn"?"text-warn":"text-fg-5"),children:[w.label," ",Math.round(w.usedPercent??0),"%"]})]},l.agent)}),E==="model"&&e.jsxs(e.Fragment,{children:[Re.map((l,f)=>{const w=f===0&&l.kind==="native",L=f===yn&&l.kind==="profile",H=je!==void 0?je:W===_&&Pt!==void 0?Pt:cs,oe=l.kind==="profile"?!!l.profileId&&l.profileId===H:!H&&l.id===(et??Rt);return e.jsxs("div",{children:[w&&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")}),L&&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(un,{selected:oe,onClick:()=>{const Ce=ve||_,_e=l.profileId??null;Te(l.id),we(_e),Sn(Ce,l.id,_e)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:C("truncate text-[11.5px]",l.kind==="native"&&"font-mono text-[11px]"),title:l.id,children:l.label}),l.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:l.description})]})})]},`${l.kind}:${l.profileId||l.id}`)}),Re.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(fr,{current:xs,options:ds,onSelect:hs,label:d("hub.selectEffort")}),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:Et,disabled:!Nn,className:C("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",Nn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:A?e.jsx(ge,{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(xr,{source:us,onClose:()=>{Je(null),kt(null)},t:d})]})});function xr({source:t,onClose:n,t:s}){const[a,r]=i.useState(!1);if(i.useEffect(()=>{r(!1)},[t?.key]),i.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,p=t.onRemove;return gn.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:Vn(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await rr(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(a?"hub.copied":"hub.copyImage")}),p&&e.jsx("button",{type:"button",onClick:p,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 un({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:C("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 fr({current:t,options:n,onSelect:s,label:a}){const[r,c]=i.useState(!1),p=i.useRef(null);if(i.useEffect(()=>{if(!r)return;const N=k=>{p.current&&!p.current.contains(k.target)&&c(!1)};return document.addEventListener("mousedown",N),()=>document.removeEventListener("mousedown",N)},[r]),!n.length)return null;const d=n.find(N=>N.id===t)?.label||t||"—",m=n.findIndex(N=>N.id===t),v=n.length>1&&m>=0?m/(n.length-1):.5,g=Math.round(-80+v*160),j=t==="ultra";return e.jsxs("div",{className:"relative shrink-0",ref:p,children:[e.jsxs("button",{type:"button",onClick:()=>c(N=>!N),title:a,className:C("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:j?"url(#effortUltraGrad)":"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[j&&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:C("shrink-0",j&&"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:C("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(N=>e.jsx(un,{selected:N.id===t,onClick:()=>{s(N.id),c(!1)},children:N.label},N.id))})]})}function gr(){return function(t){As(t)}}const jn=[Ps,gr],qn=t=>/^https?:\/\//.test(t),mr=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function br(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function Qn(t){let n=t.trim();const s=[["`","`"],['"','"'],["'","'"],["<",">"]];let a=!0;for(;a&&n.length>=2;){a=!1;for(const[r,c]of s)n.startsWith(r)&&n.endsWith(c)&&(n=n.slice(r.length,-c.length).trim(),a=!0)}return n}function wn(t){let n=Qn(t),s="";for(;n.length>1;){const a=n[n.length-1];if(!a||!/[),.;!?]/.test(a)||a==="."&&/^\.[A-Za-z0-9_-]+$/.test(n))break;s=a+s,n=n.slice(0,-1)}return{text:n,trailing:s}}function Vt(t){const n=wn(t).text;if(!n||qn(n)||mr(n)&&!n.startsWith("file://"))return!1;const s=br(n);if(!s)return!1;if(s.startsWith("file://"))return s.length>7;if(/^[A-Za-z]:[\\/]/.test(s))return!0;if(/^(\/|~\/|\.{1,2}\/)/.test(s))return s.length>1;if(s.includes("/")){const a=s.split("/")[0]||"";return!/^[A-Za-z0-9-]+\.[A-Za-z]{2,}$/.test(a)}return!1}function kn(t,n){ie.openInEditor(t,void 0,n||void 0).catch(()=>{})}function Yn(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),t.stopPropagation(),kn(n,s))}const vr="text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",jr="underline decoration-dotted decoration-fg-5/40 underline-offset-2 cursor-pointer hover:text-blue-300 hover:decoration-blue-300/50 transition-colors";function Xn({locator:t,workdir:n,className:s,children:a}){return e.jsx("span",{role:"link",tabIndex:0,title:t,className:s??vr,onClick:r=>{r.stopPropagation(),kn(t,n)},onKeyDown:r=>Yn(r,t,n),children:a??t})}function wr(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:a,trailing:r}=wn(s),c=Qn(a);c&&!c.endsWith("…")&&Vt(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 Be({text:t,workdir:n,className:s}){const a=wr(t);return a.some(r=>r.type==="link")?e.jsx(e.Fragment,{children:a.map((r,c)=>r.type==="link"?e.jsx(Xn,{locator:r.locator,workdir:n,className:s??jr,children:r.display},c):e.jsx("span",{children:r.value},c))}):e.jsx(e.Fragment,{children:t})}function kr({text:t}){const[n,s]=i.useState(!1),a=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:a,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function En(t){const n=Vt(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 qt(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 break-words",children:s}),strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-fg",children:s}),em:({children:s})=>e.jsx("em",{className:"italic text-fg-3",children:s}),a:({href:s,children:a})=>s&&qn(s)?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",children:a}):s&&Vt(s)?e.jsx(Xn,{locator:wn(s).text,workdir:n,children:a}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:a}),ul:({children:s})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:s}),ol:({children:s})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:s}),li:({children:s})=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"shrink-0 mt-[10px] w-[5px] h-[5px] rounded-full bg-fg-5/40"}),e.jsx("span",{className:"flex-1",children:s})]}),blockquote:({children:s})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:s}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:s,children:a})=>{const r=String(a).replace(/\n$/,""),c=/language-(\w+)/.exec(s||"");if(!c&&!s&&!r.includes(`
10
+ `))return Vt(r)?e.jsx("code",{role:"link",tabIndex:0,title:r,className:C("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",En(r)),onClick:()=>kn(r,n),onKeyDown:d=>Yn(d,r,n),children:r}):e.jsx("code",{className:C("px-1.5 py-[1px] rounded text-[12px] font-mono border",En(r)),children:r});const p=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:p||"text"}),e.jsx(kr,{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})}}qt();function Qe(t){return!!t?.steps?.length}function yr(t,n){let s=t;for(const[a,r]of Object.entries(n))s=s.replace(new RegExp(`\\{${a}\\}`,"g"),r);return s}function Nr({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 Zn({plan:t,t:n,className:s}){const[a,r]=i.useState(!1);if(!Qe(t))return null;const c=t.steps.length,p=t.steps.filter(v=>v.status==="completed").length,d=c>0&&p===c,m=yr(n("hub.planProgress"),{done:String(p),total:String(c)});return e.jsx(ht,{open:a,onToggle:()=>r(v=>!v),dot:{color:d?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!d},label:m,preview:t.explanation?e.jsx("span",{className:"text-[11.5px] text-fg-4 truncate",children:t.explanation}):void 0,badge:e.jsx("span",{className:C("rounded-md border px-1.5 py-0.5 text-[10px] font-mono",d?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(d?"hub.planDone":"hub.planInProgress")}),className:s,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-1",children:t.steps.map((v,g)=>{const j=v.status==="completed"?"text-fg-5 line-through decoration-fg-5/40":v.status==="inProgress"?"text-fg-3":"text-fg-4";return e.jsxs("div",{className:"flex items-center gap-2 py-[2px]",children:[e.jsx("span",{className:"shrink-0 flex items-center justify-center w-[10px]",children:e.jsx(Nr,{status:v.status})}),e.jsx("span",{className:C("text-[12px] leading-[1.5]",j),children:v.step})]},`${g}:${v.step}`)})})})}function Jn({url:t,fileName:n,fileSize:s,caption:a}){return e.jsxs("div",{className:"flex flex-col gap-1 max-w-[340px]",children:[e.jsxs("a",{href:t,download:n,target:"_blank",rel:"noreferrer",title:a||n,className:C("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:Vn(s)})]}),e.jsx("span",{className:"shrink-0 text-fg-5/50 group-hover:text-fg-3 transition-colors",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),a&&e.jsx("span",{className:"px-0.5 text-[11.5px] leading-[1.55] text-fg-4 break-words",children:a})]})}function es(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
11
+ `).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||Qe(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function Ro(t){return es(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function Sr(t){return t.phase!=="done"||!t.error?null:es(t)?"hub.streamErrored":"hub.streamFailed"}function Cr({detail:t,t:n,className:s}){const a=Zs(t);if(a==="interrupted")return e.jsxs("div",{className:C("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=a==="error"?{dot:"bg-rose-400/55",text:"text-rose-300/65"}:{dot:"bg-fg-5/40",text:"text-fg-5/55"};return e.jsxs("div",{className:C("flex items-start gap-1.5 text-[11px] leading-[1.6]",r.text,s),children:[e.jsx("span",{className:C("mt-[5px] h-1 w-1 rounded-full shrink-0",r.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const Ir=64;function Lr(t,n){const[s,a]=i.useState(t),r=i.useRef(0),c=i.useRef(null);return i.useEffect(()=>{if(n<=0)return;const p=Date.now()-r.current,d=()=>{r.current=Date.now(),a(t)};return p>=n?d():(c.current&&clearTimeout(c.current),c.current=window.setTimeout(d,n-p)),()=>{c.current&&clearTimeout(c.current)}},[t,n]),n<=0?t:s}function _o({stream:t,t:n,workdir:s}){const a=Qe(t.plan),[r,c]=i.useState(!1),[p,d]=i.useState(!1),m=i.useRef(null),v=i.useRef(null),g=Sr(t),j=i.useMemo(()=>(t.activity||"").split(`
12
+ `).filter(Boolean),[t.activity]),N=t.previewMeta?.toolCalls??[],k=j[j.length-1]||N[N.length-1]?.summary||"",$=N.length,O=t.previewMeta?.contextPercent??null,M=t.previewMeta?.contextUsedTokens??0,P=t.previewMeta?.turnOutputTokens??0,K=t.phase==="streaming",U=K&&t.startedAt!=null&&t.startedAt>0,Y=K;i.useLayoutEffect(()=>{const I=m.current;I&&r&&(I.scrollTop=I.scrollHeight)},[r,t.activity,N.length]),i.useLayoutEffect(()=>{const I=v.current;I&&p&&(I.scrollTop=I.scrollHeight)},[p,t.thinking]);const A=t.subAgents??null,te=Lr(t.text,t.phase==="streaming"?Ir:0),T=i.useMemo(()=>qt({workdir:s}),[s]),D=i.useMemo(()=>e.jsx(mn,{remarkPlugins:jn,components:T,children:te}),[te,T]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[a&&e.jsx(Zn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),A&&A.length>0&&A.map(I=>e.jsx(ns,{sub:I,t:n},I.id)),(N.length>0||j.length>0)&&e.jsx(ht,{open:r,onToggle:()=>c(I=>!I),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(Be,{text:k,workdir:s})}),badge:(N.length||j.length)>1?e.jsx(fn,{children:N.length||j.length}):void 0,children:e.jsx("div",{ref:m,className:"px-3.5 py-2.5 space-y-0.5 max-h-[280px] overflow-y-auto",children:N.length>0?N.map(I=>e.jsx(Tr,{call:I,workdir:s},I.id)):j.map((I,Z)=>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(Be,{text:I,workdir:s})})]},Z))})}),t.thinking&&e.jsx(ht,{open:p,onToggle:()=>d(I=>!I),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:Hn(t.thinking,3)}),children:e.jsx("div",{ref:v,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[280px] overflow-y-auto",children:t.thinking})}),t.text&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:D}),t.artifacts&&t.artifacts.length>0&&e.jsx("div",{className:"flex flex-col gap-2",children:t.artifacts.map((I,Z)=>I.kind==="photo"?e.jsx("a",{href:I.url,target:"_blank",rel:"noreferrer",className:"inline-block",children:e.jsx("img",{src:I.url,alt:I.caption||I.fileName,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain hover:opacity-90 transition-opacity"})},Z):e.jsx(Jn,{url:I.url,fileName:I.fileName,fileSize:I.fileSize,caption:I.caption},Z))}),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…`})]}),Y&&e.jsx(Er,{toolCount:$,ctxPct:O,ctxTokens:M,turnOutTokens:P,startedAt:U?t.startedAt:null}),g&&t.error&&e.jsx(Cr,{detail:t.error,t:n,className:"pt-0.5"})]})}function Tr({call:t,workdir:n}){const[s,a]=i.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&&a(p=>!p),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(Be,{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(Be,{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(Be,{text:t.result,workdir:n})})]})]})}function ts({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 Er({toolCount:t,ctxPct:n,ctxTokens:s,turnOutTokens:a,startedAt:r}){return e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-mono text-fg-5/50 tabular-nums",children:[e.jsx(ts,{className:"text-fg-5/45 shrink-0"}),e.jsx(Mr,{toolCount:t,ctxPct:n,ctxTokens:s,turnOutTokens:a,startedAt:r})]})}function Mr({toolCount:t,ctxPct:n,ctxTokens:s,turnOutTokens:a,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 ${Kn(n)}`}),n.toFixed(1),"%"]},"ctx")),s>0&&c.push(e.jsx("span",{className:"text-fg-5/40",children:zn(s)},"tok")),a>0&&c.push(e.jsxs("span",{className:"text-fg-5/40",children:["↑",vn(a)]},"out")),r!=null&&c.push(e.jsx(Ar,{startedAt:r},"elapsed")),c.length?e.jsx("span",{className:"shrink-0 flex items-center gap-1.5",children:c.map((p,d)=>e.jsxs("span",{className:"flex items-center gap-1.5",children:[d>0&&e.jsx("span",{className:"text-fg-5/25",children:"·"}),p]},d))}):null}function Ar({startedAt:t}){const[,n]=i.useState(0);i.useEffect(()=>{const a=setInterval(()=>n(r=>r+1),1e3);return()=>clearInterval(a)},[]);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:Xs(s)})}function ns({sub:t,t:n}){const[s,a]=i.useState(!1),r=t.status,c=r==="failed"?"bg-rose-400/60":r==="done"?"bg-emerald-400/55":"bg-amber-400/60",p=r==="running",d=t.tools,m=i.useMemo(()=>{const j=new Set,N=[];for(const k of d)j.has(k.name)||(j.add(k.name),N.push(k.name));return N},[d]),v=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",g=t.model?zt(t.model):null;return e.jsx(ht,{open:s,onToggle:()=>a(j=>!j),dot:{color:c,pulse:p},label:v,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),g&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:g}),!t.description&&m.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:m.join(" · ")})]}),badge:d.length>0?e.jsx(fn,{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 Pr({message:t,t:n,workdir:s,fallbackPlan:a}){const{activityBlocks:r,thinkingBlocks:c,planBlocks:p,subAgentBlocks:d,outputBlocks:m,noticeBlocks:v}=ss(t.blocks),j=[...p].reverse().find(k=>Qe(k.plan))?.plan??(Qe(a)?a:null);return r.length>0||d.length>0||!!j||c.length>0||m.length>0||v.length>0?e.jsxs("div",{className:"space-y-3",children:[r.length>0&&e.jsx(Wr,{blocks:r,t:n,workdir:s}),d.map(k=>k.subAgent?e.jsx(ns,{sub:k.subAgent,t:n},k.toolId||k.subAgent.id):null),j&&e.jsx(Zn,{plan:j,t:n,className:"max-w-[760px]"}),c.length>0&&e.jsx($r,{blocks:c,t:n}),m.length>0&&e.jsx(Fr,{blocks:m,t:n,workdir:s}),v.length>0&&e.jsx(_r,{blocks:v,t:n})]}):null}function Rr(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:a,subAgentBlocks:r,outputBlocks:c,noticeBlocks:p}=ss(t.blocks);return c.length>0||n.length>0||r.length>0||s.length>0||a.some(d=>Qe(d.plan))||p.length>0}function ss(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"&&Qe(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 _r({blocks:t,t:n}){const s=t.map(a=>a.content).filter(Boolean).join(`
13
+
14
+ `).trim();return s?e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/[0.06] px-3 py-2 text-[12.5px] leading-[1.7] text-fg-3",children:[e.jsx("span",{className:"mt-[6px] h-1.5 w-1.5 rounded-full bg-amber-400/70 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-mono uppercase tracking-wide text-amber-300/80",children:n("hub.systemNotice")||"Agent notice"}),e.jsx("div",{className:"mt-0.5 break-words whitespace-pre-wrap",children:s})]})]}):null}function Wr({blocks:t,t:n,workdir:s}){const[a,r]=i.useState(!1),c=t.filter(v=>v.type==="tool_use"),p=c.length,d=c[c.length-1],m=d?Gn(d):"";return e.jsx(ht,{open:a,onToggle:()=>r(v=>!v),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(Be,{text:m,workdir:s})}),badge:p>0?e.jsx(fn,{children:p}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((v,g)=>e.jsx(Br,{block:v,workdir:s},g))})})}function Br({block:t,workdir:n}){const[s,a]=i.useState(!1),r=t.type==="tool_use",c=r?Gn(t):ir(t),p=t.content.length>3e3?t.content.slice(0,3e3)+`
15
+ …`:t.content;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&a(d=>!d),className:C("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:C("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(Be,{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(Be,{text:p,workdir:n})})]})}function $r({blocks:t,t:n}){const[s,a]=i.useState(!1),r=i.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
16
+
17
+ `).trim();if(!c)return null;const p=Hn(c,3);return e.jsx(ht,{open:s,onToggle:()=>a(d=>!d),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:p?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:p}):void 0,children:e.jsx(Or,{scrollRef:r,text:c})})}function Or({scrollRef:t,text:n}){return i.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 Dr({block:t,onLightbox:n,t:s}){const a=t.imageCaption?.trim()||"",r=t.imageCaptionKind==="prompt",[c,p]=i.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:a||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),a&&(r?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>p(d=>!d),"aria-expanded":c,className:C("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:a})})]}):e.jsx("figcaption",{className:"text-[11px] leading-[1.55] text-fg-5 max-w-[400px] break-words whitespace-pre-wrap",children:a}))]})}function Fr({blocks:t,t:n,workdir:s}){const a=t.filter(g=>g.type==="text"),r=t.filter(g=>g.type==="image"),c=t.filter(g=>g.type==="file"),p=a.map(g=>g.content).filter(Boolean).join(`
18
+
19
+ `),[d,m]=i.useState(null),v=i.useMemo(()=>qt({workdir:s}),[s]);return!p.trim()&&r.length===0&&c.length===0?null:e.jsxs(e.Fragment,{children:[p.trim()&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:e.jsx(mn,{remarkPlugins:jn,components:v,children:p})}),r.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:r.map((g,j)=>e.jsx(Dr,{block:g,onLightbox:m,t:n},j))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((g,j)=>e.jsx(Jn,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},j))}),d&&e.jsx(rs,{src:d,onClose:()=>m(null)})]})}const Wo=i.memo(function({turn:n,turnIndex:s,agent:a,meta:r,model:c,effort:p,providerName:d,t:m,workdir:v,onResend:g,onEdit:j,onFork:N,hideHeaderUsage:k,fallbackPlan:$,isTail:O}){const M=n.user&&Un(n.user.text),P=N&&typeof s=="number"?()=>N(s):void 0,K=i.useMemo(()=>qt({workdir:v}),[v]),U=!!n.assistant&&Rr(n.assistant);return e.jsxs("div",{className:C("session-turn",O&&"session-turn--live"),children:[n.user&&!M&&e.jsx(os,{text:n.user.text,blocks:n.user.blocks,t:m,onResend:g,onEdit:j,onFork:P}),M&&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(mn,{remarkPlugins:jn,components:K,children:n.user.text})}),U&&e.jsxs(e.Fragment,{children:[e.jsx(Hr,{agent:a,meta:r,model:c,effort:p,providerName:d,previewMeta:n.assistant.usage??null,hideContextUsage:k}),e.jsx("div",{className:"mb-6",children:e.jsx(Pr,{message:n.assistant,t:m,workdir:v,fallbackPlan:$})})]})]})});function rs({src:t,onClose:n}){return i.useEffect(()=>{const s=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),gn.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 Ur=1500,zr=16,Mn=8;function Kr(t){const n=t.split(`
20
+ `);return n.length<=Mn?t:n.slice(0,Mn).join(`
21
+ `)}function os({text:t,blocks:n,t:s,onResend:a,onEdit:r,onFork:c}){const[p,d]=i.useState(!1),[m,v]=i.useState(!1),[g,j]=i.useState(null),N=t?t.split(`
22
+ `).length:0,k=!!t&&(t.length>Ur||N>zr),[$,O]=i.useState(!1),M=t?k&&!$?Kr(t):t:"",P=!!(a||r||c),K=n?.filter(A=>A.type==="image")||[],U=()=>{navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),1500)}).catch(()=>{})},Y=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(N));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:[M,k&&!$&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),k&&e.jsx("button",{type:"button",onClick:()=>O(A=>!A),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:$?s("hub.collapse"):Y}),K.length>0&&e.jsx("div",{className:C("flex flex-wrap gap-2",t&&"mt-2"),children:K.map((A,te)=>e.jsx("img",{src:A.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(A.content)},te))})]}),g&&e.jsx(rs,{src:g,onClose:()=>j(null)}),P&&e.jsxs("div",{className:C("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",p?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(Bt,{label:s(m?"hub.copied":"hub.copy"),onClick:U,children:m?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),a&&e.jsx(Bt,{label:s("hub.rerun"),onClick:()=>a(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),r&&e.jsx(Bt,{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(Bt,{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 Bt({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 Hr({agent:t,meta:n,model:s,effort:a,providerName:r,previewMeta:c,hideContextUsage:p}){const d=p?null:c?.contextPercent??null,m=p?0:c?.contextUsedTokens??0,v=p?0:c?.turnOutputTokens??0,g=d!=null||m>0||v>0,j=c?.providerName??r??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(ut,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||a)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&a?" · ":"",a||""]}),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]}),g&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:Vr(c),children:[d!=null&&e.jsx(Gr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",zn(m)]}),v>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",vn(v)]})]})]})}function Vr(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 Gr({pct:t}){return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Kn(t)}`})}function An(t,n,s){return t==="zh-CN"?n:s}function qr({open:t,onClose:n,workdir:s}){const a=le(c=>c.locale),r=s.split("/").pop()||s;return e.jsxs(Kt,{open:t,onClose:n,wide:!0,children:[e.jsx(Ht,{title:An(a,`${r} — 项目扩展`,`${r} — Project Extensions`),description:An(a,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(Rs,{workdir:s}):null]})}let Pn=Bn(()=>import("./SessionPanel-CoIrjkQt.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function hn(){return Pn??=Bn(()=>import("./SessionPanel-CoIrjkQt.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Pn}const Qr=i.lazy(async()=>({default:(await hn()).SessionPanel})),cn=5,Yr=240,Xr=120,Zr=12,Jr=900*1e3,q=(t,n)=>`${t}:${n}`;function eo(t){const n=new Map;for(const d of t)n.set(q(d.agent||"",d.sessionId),d);const s=new Map,a=new Set;for(const d of t){const m=d.migratedFrom;if(!m||m.kind!=="fork"||!m.sessionId)continue;const v=q(m.agent||d.agent||"",m.sessionId);n.has(v)&&(a.add(q(d.agent||"",d.sessionId)),s.has(v)||s.set(v,[]),s.get(v).push(d))}const r=[],c=new Set,p=(d,m)=>{const v=q(d.agent||"",d.sessionId);if(c.has(v))return;c.add(v),r.push(Object.assign({},d,{__forkDepth:m}));const g=s.get(v);if(g)for(const j of g)p(j,m+1)};for(const d of t){const m=q(d.agent||"",d.sessionId);a.has(m)||p(d,0)}for(const d of t)p(d,0);return r}let to=0;function jt(){return`mk-${Date.now().toString(36)}-${(++to).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 Ot(t,n){try{localStorage.setItem(t,n)}catch{}}const no=[1,2,3,6],pn=6;function so(t){for(const n of no)if(n>=t)return n;return pn}function Rn(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function Ge(t,n){const s=so(t);return s>n?s:n}function ro(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function oo(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function is(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 io=i.memo(function({active:n=!0}){const s=le(o=>o.locale),a=le(o=>o.state?.runtimeWorkdir??null),r=i.useMemo(()=>ys(s),[s]),[c,p]=i.useState([]),[d,m]=i.useState({}),[v,g]=i.useState({}),[j,N]=i.useState(!0),[k,$]=i.useState(()=>{const o=$t("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Rn()}),[O,M]=i.useState(()=>{const o=$t("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Rn()}),[P,K]=i.useState(()=>{try{const o=$t("pikiloom-open-sessions");if(o){const h=JSON.parse(o);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||jt()}))}}catch{}return[]}),[U,Y]=i.useState(()=>{const o=$t("pikiloom-active-slot");if(o!=null){const h=Number(o);if(Number.isFinite(h)&&h>=0)return h}return 0}),A=i.useCallback(o=>{$(o),Ot("pikiloom-layout-mode",String(o))},[]),te=i.useCallback(o=>{M(o),Ot("pikiloom-layout-floor",String(o))},[]),T=i.useCallback(o=>{K(h=>{const u=typeof o=="function"?o(h):o,x=u.map(({pendingPrompt:b,pendingImageUrls:y,...S})=>S);return Ot("pikiloom-open-sessions",JSON.stringify(x)),u})},[]),D=i.useCallback(o=>{Y(h=>{const u=typeof o=="function"?o(h):o;return Ot("pikiloom-active-slot",String(u)),u})},[]),I=i.useCallback(o=>{A(o),te(o)},[A,te]);i.useEffect(()=>{T(o=>o.length>k?o.slice(0,k):o),D(o=>o>=k?k-1:o)},[k]);const[Z,R]=i.useState(!1),ne=i.useRef(k);ne.current=k;const Q=i.useRef(O);Q.current=O;const pe=i.useRef(U);pe.current=U;const V=i.useRef(P);V.current=P;const wt=i.useRef(-1),me=P[U]??null,xt=i.useCallback(o=>{if(!o){T([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:jt()};T(u=>{const x=u.findIndex(y=>y.agent===h.agent&&y.sessionId===h.sessionId);if(x>=0)return D(x),u;if(u.length<ne.current){const y=[...u,h];return D(y.length-1),y}if(ne.current<pn){const y=[...u,h];return A(Ge(y.length,Q.current)),D(y.length-1),y}const b=[...u];return b[pe.current]=h,b})},[T,D,A]),[Ye,Xe]=i.useState(!1),[se,$e]=i.useState(null),[Oe,Ze]=i.useState(""),[re,De]=i.useState("all"),[be,Je]=i.useState({}),[Le,kt]=i.useState({}),ve=i.useDeferredValue(Oe),ce=i.useRef(!1),et=i.useRef({}),Te=i.useRef(d);Te.current=d;const yt=i.useRef(be);yt.current=be;const Ee=i.useRef(new Set),je=i.useRef({});i.useEffect(()=>()=>{for(const o of Object.values(je.current))clearTimeout(o)},[]),i.useEffect(()=>{T(o=>{let h=!1;const u=o.map(x=>{const b=Le[x.workdir];if(!b)return x;const y=In(b,x.agent,x.sessionId);return y===x.sessionId?x:(h=!0,{...x,sessionId:y})});return h?u:o})},[Le,T]);const we=i.useCallback(async()=>{try{const o=await ie.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&p(u=>u.length===h.length&&u.every((x,b)=>x.path===h[b].path&&x.name===h[b].name)?u:h),ce.current=!0}catch{ce.current=!0}finally{N(!1)}},[]);i.useEffect(()=>{we()},[we]);const E=i.useCallback(async(o,h={})=>{if(!et.current[o]){et.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Os(o,{force:h.force});i.startTransition(()=>{kt(x=>{const b=u.promotions||{},y=x[o];return y&&Object.keys(y).length===Object.keys(b).length&&Object.entries(b).every(([S,_])=>y[S]===_)?x:{...x,[o]:b}}),m(x=>{const b=u.sessions||[],y=x[o]||[],S=new Set(b.map(z=>q(z.agent||"",z.sessionId))),_=y.filter(z=>{if(z.runState!=="running")return!1;const W=q(z.agent||"",z.sessionId);if(S.has(W))return!1;const F=yt.current[W];return!(F?.resolvedKey&&F.resolvedKey!==W)});return{...x,[o]:_.length?[..._,...b]:b}})})}catch{h.background||i.startTransition(()=>{m(u=>({...u,[o]:[]}))})}finally{et.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),xe=i.useRef(a);i.useEffect(()=>{a!==xe.current&&(xe.current=a,!(!a||!ce.current)&&we().then(()=>{E(a,{force:!0})}))},[a,we,E]);const J=i.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(hn(),Us({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Zr}))},[]),Nt=i.useCallback((o,h,u=Xr)=>{const x=`${h}:${q(o.agent||"",o.sessionId)}`,b=je.current[x];b&&clearTimeout(b),je.current[x]=setTimeout(()=>{delete je.current[x],J(o,h)},u)},[J]),Me=i.useCallback((o,h)=>{const u=`${h}:${q(o.agent||"",o.sessionId)}`,x=je.current[u];x&&(clearTimeout(x),delete je.current[u])},[]);i.useEffect(()=>{n&&hn()},[n]),i.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||v[h.path])return;const x=setTimeout(()=>{E(h.path)},u*90);o.push(x)}),()=>{for(const h of o)clearTimeout(h)}},[n,E,v,d,c]);const tt=i.useRef(new Map);Ln(n&&ce.current&&c.length>0?"sessions-changed":null,i.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=o.key,u=h?c.filter(y=>(Te.current[y.path]||[]).some(S=>q(S.agent||"",S.sessionId)===h)):c,x=u.length?u:c,b=tt.current;for(const y of x)b.has(y.path)&&clearTimeout(b.get(y.path)),b.set(y.path,setTimeout(()=>{b.delete(y.path),E(y.path,{background:!0,force:!0})},300))},[c,E]));const Fe=i.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:Ns(o,be[q(h,o.sessionId)]||null)},[be]);Ln("stream-update",i.useCallback(o=>{const h=o.key;if(!h)return;const u=Ss(h,o.snapshot??null);Je(x=>{if(!u){const W=x[h];return!W||W.phase==="done"?x:{...x,[h]:{...W,phase:"done",updatedAt:Date.now()}}}const b=(W,F)=>!!W&&!!F&&W.phase===F.phase&&W.resolvedKey===F.resolvedKey&&W.sessionId===F.sessionId&&W.incomplete===F.incomplete&&W.error===F.error,y=b(x[h],u),S=u.resolvedKey===h||b(x[u.resolvedKey],{...u,key:u.resolvedKey});if(y&&S)return x;const _=Date.now()-Jr,z={};for(const[W,F]of Object.entries(x))F.phase==="done"&&F.updatedAt<_||(z[W]=F);return z[h]=u,u.resolvedKey!==h&&(z[u.resolvedKey]={...u,key:u.resolvedKey}),z})},[])),Cs(i.useCallback(()=>{if(!(!n||!ce.current||c.length===0))for(const o of c)E(o.path,{background:!0,force:!0})},[n,c,E])),i.useEffect(()=>{if(!n||!ce.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)E(u.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,E,c]),i.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const x=(d[h.path]||[])[0];if(!x)return;const b=`${h.path}:${q(x.agent||"",x.sessionId)}`;if(Ee.current.has(b))return;const y=setTimeout(()=>{Ee.current.add(b),J(x,h.path)},Yr+u*120);o.push(y)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,J,c]);const Qt=i.useCallback(async o=>{try{(await ie.addWorkspace(o)).ok&&(Xe(!1),await we(),E(o))}catch{}},[we,E]),[fe,ke]=i.useState(null),[ye,St]=i.useState(!1),[de,Ue]=i.useState(null),nt=i.useCallback(o=>{ke(o)},[]),st=i.useCallback(async()=>{const o=fe;if(o){St(!0);try{await ie.removeWorkspace(o),p(h=>h.filter(u=>u.path!==o)),m(h=>{const u={...h};return delete u[o],u}),T(h=>{const u=h.filter(x=>x.workdir!==o);return u.length!==h.length&&A(Ge(u.length,Q.current)),u}),D(0),ke(null)}catch{}finally{St(!1)}}},[fe]),rt=i.useCallback(o=>{E(o,{force:!0})},[E]),[Ae,Ne]=i.useState(null),[ze,ft]=i.useState(!1),[ue,ot]=i.useState(!1),it=le(o=>o.toast),[ae,Pe]=i.useState(null),Ct=i.useCallback((o,h,u)=>{Pe({anchor:{right:o.right,bottom:o.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:_n(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);i.useEffect(()=>{if(!ae)return;const o=()=>Pe(null),h=u=>{u.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",h)}},[ae]);const gt=i.useCallback(o=>{ft(!1),Ne(o),Pe(null)},[]),Se=i.useCallback(async()=>{const o=Ae;if(o){ot(!0);try{const h=await ie.deleteSession(o.workdir,o.agent,o.sessionId,ze);if(!h.ok){const u=h.error?.includes("still running")?r("session.deleteRunningError"):h.error||r("session.deleteFailed");it(u,!1);return}m(u=>{const x=u[o.workdir];if(!x)return u;const b=x.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return b.length===x.length?u:{...u,[o.workdir]:b}}),T(u=>{const x=u.filter(b=>!(b.workdir===o.workdir&&b.agent===o.agent&&b.sessionId===o.sessionId));return x.length!==u.length&&A(Ge(x.length,Q.current)),x}),Ne(null)}catch(h){it(h?.message||r("session.deleteFailed"),!1)}finally{ot(!1)}}},[Ae,ze,r,it]),It=i.useCallback(o=>{T(h=>{let u=!1;const x=h.map(b=>b.mountKey===o&&(b.pendingPrompt!=null||b.pendingImageUrls)?(u=!0,{...b,pendingPrompt:null,pendingImageUrls:void 0}):b);return u?x:h})},[T]),Ke=i.useCallback((o,h,u)=>{J({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),m(y=>{const S=y[o.workdir]||[];if(S.some(W=>W.sessionId===o.sessionId&&W.agent===o.agent))return y;const z={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[z,...S]}});const x=wt.current,b={...o,mountKey:jt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};i.startTransition(()=>{$e(null),T(y=>{if(x>=y.length)return[...y,b];const S=[...y];return S[x]=b,S}),D(x>=0?x:0)}),E(o.workdir,{background:!0,force:!0})},[E,J,T,D]),Lt=i.useCallback(o=>{V.current.length>=ne.current&&ne.current<pn&&A(Ge(ne.current+1,Q.current)),$e(o)},[A]),Tt=i.useCallback(()=>{$e(null),A(Ge(V.current.length,Q.current))},[A]),Et=i.useCallback((o,h)=>{J(o,h);const u=o.agent||"";V.current.some(x=>x.agent===u&&x.sessionId===o.sessionId)&&A(Ge(V.current.length,Q.current)),$e(null),i.startTransition(()=>{xt({agent:u,sessionId:o.sessionId,workdir:h})})},[J,A]),Mt=i.useCallback((o,h)=>{J({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),i.startTransition(()=>{h!=null?(T(u=>{if(h>=u.length)return u;const x=[...u],b=u[h],y=b.agent===o.agent&&dt(b.sessionId)&&!dt(o.sessionId);return x[h]={...b,agent:o.agent,sessionId:o.sessionId,workdir:o.workdir,mountKey:y?b.mountKey:jt(),pendingPrompt:y?b.pendingPrompt:null,pendingImageUrls:y?b.pendingImageUrls:void 0},x}),D(h)):xt({...o,mountKey:jt()})}),E(o.workdir,{background:!0,force:!0})},[E,J]),he=i.useCallback(o=>{let h=o;if(re==="running"?h=h.filter(u=>Dt(u)==="running"):re==="review"&&(h=h.filter(u=>Dt(u)==="incomplete")),ve.trim()){const u=ve.toLowerCase();h=h.filter(x=>(x.lastMessageText||"").toLowerCase().includes(u)||(x.lastQuestion||"").toLowerCase().includes(u)||(x.lastAnswer||"").toLowerCase().includes(u)||(x.title||"").toLowerCase().includes(u)||(x.agent||"").toLowerCase().includes(u))}return h},[ve,re]),At=i.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(Fe),x=Le[h.path],b=new Map;for(const S of u){const _=q(S.agent||"",S.sessionId),z=be[_],W=x?In(x,S.agent||"",S.sessionId):S.sessionId,F=z?.resolvedKey&&z.resolvedKey!==_?z.resolvedKey:W!==S.sessionId?q(S.agent||"",W):_,Re=b.get(F);if(!Re){b.set(F,S);continue}q(Re.agent||"",Re.sessionId)!==F&&_===F&&b.set(F,S)}const y=he([...b.values()]);o[h.path]=eo(y)}return o},[c,d,be,Le,he,Fe]),mt=i.useCallback(o=>{const h=(d[o.workdir]||[]).find(u=>u.sessionId===o.sessionId&&u.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return Fe(h)},[Fe,d]),Yt=i.useMemo(()=>new Set(P.map(o=>q(o.agent,o.sessionId))),[P]),Xt=me?q(me.agent,me.sessionId):null,at=i.useCallback(o=>{T(h=>{const u=h.filter((x,b)=>b!==o);return u.length===0?D(0):pe.current>=u.length&&D(u.length-1),A(Ge(u.length,Q.current)),u})},[T,D,A]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:Oe,onChange:o=>Ze(o.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"}),Oe&&e.jsx("button",{onClick:()=>Ze(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-fg-5/30 hover:text-fg-4 transition-colors",children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex items-center rounded-lg bg-inset/30 border border-edge/20 p-0.5",children:["all","running","review"].map(o=>e.jsx("button",{onClick:()=>De(o),className:C("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",re===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1),inset_0_1px_0_rgba(255,255,255,0.04)]":"text-fg-5/60 hover:text-fg-4"),children:r(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(ge,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!Ye?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:r("hub.noWorkspaces")}):c.map(o=>e.jsx(uo,{workspace:o,sessions:At[o.path]||[],loading:!!v[o.path]||!(o.path in d),isActive:o.path===a,removable:o.removable!==!1,selectedKey:Xt,openSessionKeys:Yt,onSelectSession:Et,onNewSession:Lt,onRefresh:rt,onRemove:nt,onExtensions:Ue,onWarmSession:Nt,onCancelWarmSession:Me,onSessionMenuOpen:Ct,t:r},o.path))}),e.jsxs("div",{className:"shrink-0 border-t border-edge/20 px-3 py-2 space-y-1.5",children:[e.jsx("div",{className:"flex items-center rounded-md bg-inset/30 border border-edge/20 p-0.5",children:[1,2,3,6].map(o=>e.jsx("button",{onClick:()=>I(o),className:C("flex-1 flex items-center justify-center p-1.5 rounded transition-all",k===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1)]":"text-fg-5/40 hover:text-fg-4"),title:r(`hub.layout${o}`),children:o===1?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"})}):o===2?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"12",rx:"1.5"}),e.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"1.5"})]}):o===3?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"0.5",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"11.5",y:"2",width:"4",height:"12",rx:"1"})]}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:[e.jsx("rect",{x:"0.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"0.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"})]})},o))}),e.jsxs(We,{variant:"ghost",size:"sm",onClick:()=>Xe(o=>!o),className:"w-full",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),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(${k===6?3:k}, 1fr)`,gridTemplateRows:k===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=se?P.length<k?P.length:U:-1;return wt.current=o,Array.from({length:k},(h,u)=>{if(se&&u===o)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-edge bg-panel flex flex-col",style:{boxShadow:"var(--th-card-shadow)"},children:e.jsx(lo,{workdir:se,workspaceName:c.find(S=>S.path===se)?.name||se.split("/").pop()||"",onSessionCreated:Ke,onClose:Tt,t:r},se)},`new-${se}`);const x=P[u]??null;if(!x)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 b=mt(x),y=u===U;return e.jsxs("div",{className:C("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>D(u),children:[e.jsxs("div",{className:C("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const S=Dt(b);return e.jsx(Gt,{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:x.workdir.split("/").pop()||x.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:b.title||b.lastQuestion?.slice(0,60)||(dt(x.sessionId)?r("hub.newSession"):x.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:Is(b.createdAt)}),b.runUpdatedAt&&e.jsx("span",{title:r("hub.updated"),children:Wn(b.runUpdatedAt)}),!!b.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"})}),b.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:S=>{S.stopPropagation(),R(_=>!_)},className:C("p-0.5 rounded transition-colors",Z?"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(),at(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(i.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Qr,{session:b,workdir:x.workdir,active:n&&y,onSessionChange:S=>Mt(S,u),initialPendingPrompt:x.pendingPrompt??null,initialPendingImageUrls:x.pendingImageUrls,onPendingPromptConsumed:()=>It(x.mountKey)},x.mountKey)})})]},x.mountKey||q(x.agent,x.sessionId))})})()})}),Z&&me&&e.jsx(po,{workdir:me.workdir,onClose:()=>R(!1),t:r}),e.jsx(ao,{open:Ye,initialPath:a||void 0,onAdd:Qt,onClose:()=>Xe(!1),t:r}),e.jsxs(Kt,{open:!!fe,onClose:()=>!ye&&ke(null),children:[e.jsx(Ht,{title:r("hub.removeWorkspace"),onClose:()=>!ye&&ke(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")}),fe&&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:fe}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(We,{variant:"ghost",onClick:()=>ke(null),disabled:ye,children:r("modal.cancel")}),e.jsx(We,{variant:"primary",onClick:st,disabled:ye,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:r(ye?"modal.removing":"modal.remove")})]})]}),ae&&(()=>{const h=Math.max(8,Math.min(ae.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ae.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:x=>x.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>gt(ae.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(Kt,{open:!!Ae,onClose:()=>!ue&&Ne(null),children:[e.jsx(Ht,{title:r("session.deleteTitle"),onClose:()=>!ue&&Ne(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:r("session.deleteHint")}),Ae&&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:Ae.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Ae.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:!ze,onChange:()=>ft(!1),disabled:ue,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:ze,onChange:()=>ft(!0),disabled:ue,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(We,{variant:"ghost",onClick:()=>Ne(null),disabled:ue,children:r("modal.cancel")}),e.jsx(We,{variant:"primary",onClick:Se,disabled:ue,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:r(ue?"session.deleting":"modal.remove")})]})]}),e.jsx(qr,{open:!!de,onClose:()=>Ue(null),workdir:de||""})]})});function ao({open:t,initialPath:n,onAdd:s,onClose:a,t:r}){const[c,p]=i.useState(""),d=i.useCallback(m=>p(m),[]);return i.useEffect(()=>{t&&p("")},[t]),e.jsxs(Kt,{open:t,onClose:a,children:[e.jsx(Ht,{title:r("hub.addWorkspace"),onClose:a}),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(We,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:r("hub.add")}),e.jsx(We,{variant:"secondary",onClick:a,className:"flex-1",children:r("hub.cancel")})]})]})}function lo({workdir:t,workspaceName:n,onSessionCreated:s,onClose:a,t:r}){const[c,p]=i.useState(null),[d,m]=i.useState([]),v=i.useRef(null),g=i.useRef([]),j=i.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),N=i.useCallback(()=>{},[]),k=i.useCallback((M,P)=>{p(M||null),v.current=M||null;const K=P||[];m(K),g.current=K},[]),$=i.useCallback(M=>{const P=g.current;g.current=[],s(M,v.current||void 0,P.length?P:void 0)},[s]),O=!!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(Gt,{variant:O?"ok":"idle",pulse:O}),!O&&e.jsx("button",{onClick:a,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:O?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(os,{text:c||"",blocks:d.map(M=>({type:"image",content:M})),t:r}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(ts,{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(pr,{session:j,workdir:t,onStreamQueued:N,onSendStart:k,onSessionChange:$,t:r,streamPhase:null})]})}function co({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:C("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 uo=i.memo(function({workspace:n,sessions:s,loading:a,isActive:r,selectedKey:c,openSessionKeys:p,onSelectSession:d,onNewSession:m,onRefresh:v,onRemove:g,onExtensions:j,removable:N,onWarmSession:k,onCancelWarmSession:$,onSessionMenuOpen:O,t:M}){const[P,K]=i.useState(!0),[U,Y]=i.useState(cn);i.useEffect(()=>{Y(cn)},[s.length]);const A=s.slice(0,U),te=s.length-U,T=n.path,[D,I]=i.useState(null),Z=i.useCallback(()=>{ie.getWorkspaceGit(T).then(R=>I(R.git)).catch(()=>I(null))},[T]);return i.useEffect(()=>{Z()},[Z]),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:()=>K(R=>!R),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:C("shrink-0 text-fg-5 transition-transform duration-150",P&&"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:C("min-w-0 truncate text-[12px] font-semibold",r?"text-primary":"text-fg-3"),children:n.name}),e.jsx(co,{git:D})]}),r&&e.jsx(Gt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:R=>{R.stopPropagation(),m(T)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:M("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:R=>{R.stopPropagation(),j(T)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:M("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:R=>{R.stopPropagation(),v(T),Z()},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"})]})}),N&&!r&&e.jsx("button",{onClick:R=>{R.stopPropagation(),g(T)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",title:M("hub.removeWorkspace"),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"})]})})]})]}),P&&e.jsx("div",{className:"pb-1",children:a?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(ge,{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:M("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[A.map(R=>{const ne=q(R.agent||"",R.sessionId),Q=R.__forkDepth||0;return e.jsx(ho,{session:R,isSelected:c===ne,isOpen:p?.has(ne)??!1,forkDepth:Q,onClick:()=>d(R,T),onWarm:()=>k(R,T),onCancelWarm:()=>$(R,T),onShowMenu:pe=>O(pe,R,T),menuLabel:M("session.openActions")},ne)}),te>0&&e.jsxs("button",{onClick:()=>Y(R=>R+cn),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:["+ ",M("hub.nMore").replace("{n}",String(te))]}),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"})})]})]})})]})}),ho=i.memo(function({session:n,isSelected:s,isOpen:a,forkDepth:r=0,onClick:c,onWarm:p,onCancelWarm:d,onShowMenu:m,menuLabel:v}){const g=dn(n.agent||""),j=Dt(n),N=_n(n).slice(0,500)||(dt(n.sessionId)?"":n.sessionId.slice(0,16)),k=Ts(n,N).slice(0,500),$=n.model?zt(n.model):null,O=r>0?Math.min(r,3)*14:0,M=a?10:12,P=i.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:p,onFocus:p,onMouseLeave:d,onBlur:d,className:C("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":a?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:M+O,...a?{borderLeft:`2px solid ${s?g.color:`${g.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[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(ut,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),$&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:$}),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:Wn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Gt,{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:N})]}),k&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:k})})]}),e.jsx("button",{ref:P,type:"button","aria-label":v,"aria-haspopup":"menu",onMouseDown:K=>{K.stopPropagation()},onClick:K=>{K.stopPropagation(),K.preventDefault(),P.current&&m(P.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"})]})})]})}),po=i.memo(function({workdir:n,onClose:s,t:a}){const r=le(g=>g.state?.hostApp??null),c=le(g=>g.state?.platform??null),p=le(g=>g.toast),[d,m]=i.useState(()=>oo(r,c)),v=i.useCallback(async g=>{try{const j=await ie.openInEditor(g,d);if(!j.ok)throw new Error(j.error||`Failed to open ${g}`)}catch(j){p(j?.message||String(j),!1)}},[d,p]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:a("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:a("hub.closePanel"),children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"shrink-0 px-2.5 py-1.5 border-b border-edge/20 flex items-center gap-2",children:[e.jsx(Es,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:a(is(g))})),onChange:g=>{ro(g)&&m(g)},renderIcon:g=>e.jsx(as,{target:g,size:14})}),e.jsx(We,{size:"sm",variant:"ghost",onClick:()=>v(n),className:"flex-1 min-w-0 text-[11px]",children:a("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(xo,{basePath:n,openTarget:d,onOpenPath:v,t:a})})]})});function as({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(ut,{brand:t,size:n})}function xo({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:a,t:r}){const[c,p]=i.useState([]),[d,m]=i.useState(!0);i.useEffect(()=>{let g=!1;return m(!0),ie.lsDir(t,!0,n).then(j=>{!g&&j.ok&&p(j.dirs.slice(0,50).map(N=>({entry:N,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||m(!1)}),()=>{g=!0}},[t,n]);const v=i.useCallback(g=>{const j=N=>N.map(k=>k.entry.path===g?k.expanded?{...k,expanded:!1}:k.children===null?(ie.lsDir(g,!0,n).then($=>{$.ok&&p(O=>xn(O,g,{children:$.dirs.slice(0,50).map(M=>({entry:M,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{p($=>xn($,g,{children:[],loading:!1}))}),{...k,loading:!0,expanded:!0}):{...k,expanded:!0}:k.children?{...k,children:j(k.children)}:k);p(N=>j(N))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(ge,{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(ls,{nodes:c,depth:0,onToggle:v,openTarget:s,onOpenPath:a,t:r})})}function ls({nodes:t,depth:n,onToggle:s,openTarget:a,onOpenPath:r,t:c}){return e.jsx(e.Fragment,{children:t.map(p=>e.jsx(fo,{node:p,depth:n,onToggle:s,openTarget:a,onOpenPath:r,t:c},p.entry.path))})}function fo({node:t,depth:n,onToggle:s,openTarget:a,onOpenPath:r,t:c}){const{entry:p,expanded:d,children:m,loading:v}=t,g=n*14,[j,N]=i.useState(!1),k=c(is(a)),$=c("hub.openWithTarget").replace("{target}",k);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:p.isDir?()=>s(p.path):void 0,onMouseEnter:()=>N(!0),onMouseLeave:()=>N(!1),className:C("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",p.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+g,paddingRight:8},children:[p.isDir?v?e.jsx(ge,{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:C("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"}),p.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:p.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:O=>{O.stopPropagation(),r(p.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:$,children:e.jsx(as,{target:a,subtle:!0})}),!p.isDir&&e.jsx(go,{filePath:p.path,t:c})]})]}),p.isDir&&d&&m&&m.length>0&&e.jsx(ls,{nodes:m,depth:n+1,onToggle:s,openTarget:a,onOpenPath:r,t:c})]})}function go({filePath:t,t:n}){const[s,a]=i.useState(!1);return e.jsx("button",{onClick:r=>{r.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{a(!0),setTimeout(()=>a(!1),1500)}).catch(()=>{})},className:C("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(a=>a.entry.path===n?{...a,...s}:a.children?{...a,children:xn(a.children,n,s)}:a)}const Bo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:io},Symbol.toStringTag,{value:"Module"}));export{pr as I,_o as L,Cr as R,Wo as T,os as U,Ao as a,es as b,Ks as c,Io as d,Vs as e,To as f,Hs as g,Qe as h,Eo as i,Ro as j,Lo as k,Fs as l,Po as m,Mo as n,Co as o,Ds as p,Rr as q,ts as r,So as s,Hr as t,Er as u,Bo as v};