pikiloom 0.4.58 → 0.4.60

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-CLlOp3lJ.js → AgentTab-KSanVg_l.js} +1 -1
  2. package/dashboard/dist/assets/{ConnectionModal-BJhiouLS.js → ConnectionModal-BSoA2mZL.js} +1 -1
  3. package/dashboard/dist/assets/{DirBrowser-H0N2gMRB.js → DirBrowser-zKX7wmty.js} +1 -1
  4. package/dashboard/dist/assets/{ExtensionsTab-5uaiMRcm.js → ExtensionsTab-DKLjCr4u.js} +1 -1
  5. package/dashboard/dist/assets/{IMAccessTab-ClNbxnzS.js → IMAccessTab-BhvB7Hes.js} +1 -1
  6. package/dashboard/dist/assets/{Modal-Cy1zHcC7.js → Modal-Qwlap_Fl.js} +1 -1
  7. package/dashboard/dist/assets/{Modals-BrLADO-I.js → Modals-2Zw2FSLo.js} +1 -1
  8. package/dashboard/dist/assets/{Select-D4DbOixc.js → Select-dIxoi_TN.js} +1 -1
  9. package/dashboard/dist/assets/SessionPanel--D5NGYgd.js +1 -0
  10. package/dashboard/dist/assets/{SystemTab-CDrID55_.js → SystemTab-CtjiZa5s.js} +1 -1
  11. package/dashboard/dist/assets/index-BDSh0L9U.js +3 -0
  12. package/dashboard/dist/assets/index-DN0a6ZnO.js +23 -0
  13. package/dashboard/dist/assets/{shared-DQyw9U1Z.js → shared-D2sGZJ9f.js} +1 -1
  14. package/dashboard/dist/index.html +1 -1
  15. package/dist/agent/drivers/claude.js +34 -3
  16. package/dist/agent/drivers/codex.js +24 -4
  17. package/dist/agent/turn-snapshot.js +141 -0
  18. package/dist/bot/bot.js +11 -0
  19. package/dist/dashboard/routes/sessions.js +30 -9
  20. package/package.json +1 -1
  21. package/dashboard/dist/assets/SessionPanel-1hemRLg_.js +0 -1
  22. package/dashboard/dist/assets/index-Iot9Vn3K.js +0 -3
  23. package/dashboard/dist/assets/index-QFqtuRrZ.js +0 -23
@@ -0,0 +1,23 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel--D5NGYgd.js","assets/react-vendor-C7Sl8SE7.js","assets/index-BDSh0L9U.js","assets/router-DHISdpPk.js","assets/index-BO-FYAny.css","assets/Modal-Qwlap_Fl.js","assets/Select-dIxoi_TN.js","assets/DirBrowser-zKX7wmty.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-DKLjCr4u.js"])))=>i.map(i=>d[i]);
2
+ import{c as C,a as ie,u as le,i as ct,f as _t,A as js,s as zt,S as ge,B as dt,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-BDSh0L9U.js";import{j as e,r as i,a as gn}from"./react-vendor-C7Sl8SE7.js";import{I as Es}from"./Select-dIxoi_TN.js";import{M as Kt,a as Ht}from"./Modal-Qwlap_Fl.js";import{D as Ms}from"./DirBrowser-zKX7wmty.js";import{n as As,r as Ps,M as mn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Rs}from"./ExtensionsTab-DKLjCr4u.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 ut({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,lt=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(lt,s);if(c)return c}const a=lt.get(s);if(a?.promise)return a.promise;const r=ie.getWorkspaceSessions(t,n.request).then(c=>(qe(lt,s,{value:c,expiresAt:c.ok?Date.now()+Ws:0},Ft),c)).finally(()=>{const c=lt.get(s);c?.promise&&qe(lt,s,{value:c.value,expiresAt:c.expiresAt},Ft)});return qe(lt,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 Co(t){const n=t.streaming||t.liveStreamPhase==="streaming",s=t.queuedTaskCount>0||t.pendingQueuedCount>0||t.streamPhase==="queued";return n||s}function Io(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 Lo(t,n){return t==null||n==null?!0:t===n}function To(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 ht(t){return(t||"").replace(/\s+/g," ").trim()}function Ks(t,n){return ht(t)===ht(n)}function Hs(t,n){const s=ht(t),a=ht(n);return!!s&&!!a&&s!==a&&s.endsWith(a)}function Vs(t,n){return n&&(!t||Hs(n,t))?n:t||n||null}function Eo(t,n){return!Vs(t,n)}function Gs(t){for(let n=t.length-1;n>=0;n--){const s=t[n].plan;if(s?.steps?.length)return s}return null}function Mo(t,n){if(Ks(t,n))return!0;const s=ht(t),a=ht(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 Ao(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 Po(t,n){const s=Math.max(0,t.startTurn-n.startTurn);return{turns:[...n.turns.slice(0,s),...t.turns],startTurn:n.startTurn,endTurn:t.endTurn,totalTurns:Math.max(t.totalTurns,n.totalTurns),hasOlder:n.hasOlder}}function Ro(t,n){if(n.startTurn<=t.startTurn)return n;const s=Math.max(0,n.startTurn-t.startTurn);return{turns:[...t.turns.slice(0,s),...n.turns],startTurn:t.startTurn,endTurn:n.endTurn,totalTurns:n.totalTurns,hasOlder:t.startTurn>0}}function qs(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=qs(s.assistant,a):s.assistant=a;return(s.user||s.assistant)&&n.push(s),n}const Ys=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"]),Xs=["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&&Ys.has(s[1].toLowerCase())?!0:Xs.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 Zs(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 Js(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 er(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}const tr=/\.(png|jpe?g|gif|webp|bmp|svg|avif|heic|heif|tiff?|ico)$/i;function Tn(t){return t.type?t.type.startsWith("image/"):tr.test(t.name||"")}function nr(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 sr(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 rr(){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 or(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 ir(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=ir(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 ar(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 lr(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 bt=new Map;function cr(t,n){return`${t}:${n}`}const dr=[],ur=[],hr={};function pr(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 xr=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:y,onRecall:N,onSteer:$,onStopAll:O,editDraft:A,onEditDraftConsumed:P,onSelectionChange:z}){const[H,Y]=i.useState(""),[M,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,pt]=i.useState(""),[Qe,Ye]=i.useState(""),[se,$e]=i.useState(void 0),[Oe,Xe]=i.useState(""),[re,De]=i.useState([]),[be,Ze]=i.useState(null),[Le,kt]=i.useState(null),[ve,ce]=i.useState(null),[Je,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),et=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),[tt,nt]=i.useState(0),st=i.useRef(null),Ae=le(l=>l.refreshAgentStatus),Ne=le(l=>l.modelLayer),ze=le(l=>l.ensureModelLayer),xt=le(l=>l.refreshModelLayer),ue=Ne?.providers??dr,rt=Ne?.profiles??ur,ot=Ne?.activeProfiles??hr;i.useEffect(()=>{ze()},[ze]),i.useEffect(()=>{pe?.length&&wt(pe)},[pe]),i.useEffect(()=>{ke.current=re},[re]);const ae=cr(n.agent||"",n.sessionId),Pe=i.useRef(ae);Pe.current=ae,i.useEffect(()=>{const l=bt.get(ae);return l&&(bt.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?bt.set(Pe.current,{text:f,files:w}):bt.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&&ct(l.sessionId)&&!ct(f.sessionId))&&(pt(""),Ye(""),$e(void 0),Xe(""),ce(null),Te(null),Ee(null),xe("closed"))},[n.agent,n.sessionId]),i.useEffect(()=>{A!=null&&(Y(A),P?.(),requestAnimationFrame(()=>{const l=Me.current;l&&(l.focus(),l.setSelectionRange(A.length,A.length))}))},[A,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 ft=de?(()=>{const l=H.match(/^\/(\S*)$/);return l?l[1].toLowerCase():null})():null,Se=ft!==null?ye.filter(l=>l.name.toLowerCase().includes(ft)||l.label&&l.label.toLowerCase().includes(ft)):[];i.useEffect(()=>{nt(0)},[de,H]),i.useEffect(()=>{if(!de||!st.current)return;const l=st.current.querySelector(`[data-skill-idx="${tt}"]`);l&&l.scrollIntoView({block:"nearest"})},[tt,de]),i.useEffect(()=>{if(!de)return;const l=f=>{st.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")},[H]);const Ke=i.useCallback(l=>{const f=Array.from(l||[]).filter(Tn);f.length&&De(w=>[...w,...f.map(ln)])},[]),Lt=i.useCallback(()=>{Ze(null),De(l=>(er(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)}),Ze(f=>f===l?null:f)},[]),Et=i.useCallback(()=>{const l=H.trim(),f=re.map(ee=>ee.file);if(!l&&f.length===0||M)return;const w=me||n.agent||V.find(ee=>ee.isDefault)?.agent||"";if(!w)return;const L=V.find(ee=>ee.agent===w)||null,K=!!n.agent&&w===n.agent,oe=(Qe||K&&n.model||""||L?.selectedModel||"").trim()||null,Ce=se!==void 0?se:K&&n.model?n.profileId??null:void 0,_e=w==="gemini"?null:(Oe||(K?_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(""),bt.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 mt=typeof ee.sessionKey=="string"?lr(ee.sessionKey):null;mt&&(mt.agent!==n.agent||mt.sessionId!==n.sessionId)&&mt&&p?.({...mt,workdir:s})}).catch(()=>{}).finally(()=>te(!1))},[V,Lt,re,H,r,c,p,a,me,Oe,Qe,se,M,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,gt=he.length>0,Yt=gt||Mt;i.useEffect(()=>{const l=f=>he.includes(f)||f===v;Z(f=>{let w=!1;const L=new Set;for(const K of f)l(K)?L.add(K):w=!0;return w?L:f}),ne(f=>{let w=!1;const L=new Set;for(const K of f)l(K)?L.add(K):w=!0;return w?L:f})},[he,v]),i.useEffect(()=>{!gt&&Q.current.files.length&&(Q.current={prompt:"",files:[]})},[gt]);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:[]}}N?.(l),l===T&&D(null)}},[I,At,T,N]),[it,o]=i.useState(!1),h=i.useCallback(async()=>{if(!(it||!O)){o(!0);try{await O()}finally{o(!1)}}},[it,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]),k=l=>{if(de&&Se.length>0){if(l.key==="ArrowDown"){l.preventDefault(),nt(f=>(f+1)%Se.length);return}if(l.key==="ArrowUp"){l.preventDefault(),nt(f=>(f-1+Se.length)%Se.length);return}if(l.key==="Tab"||l.key==="Enter"&&!l.shiftKey&&!et.current){l.preventDefault(),x(Se[tt]);return}if(l.key==="Escape"){l.preventDefault(),Ue(!1);return}}l.key==="Enter"&&!l.shiftKey&&!et.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"),K=L?nr(L):[],oe=(f.getData("text/uri-list")||f.getData("text/plain")||"").trim();/^data:image\//i.test(oe)&&K.push(oe);const Ce=K.map(B=>sr(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(),rr().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||"",U=V.find(l=>l.agent===_)||null,W=ve||_,F=V.find(l=>l.agent===W)||U,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 rt){const L=ue.find(oe=>oe.id===w.providerId);if(!L||!f.has(L.kind))continue;const K=w.name.trim().toLowerCase()!==w.modelId.trim().toLowerCase();l.push({id:w.modelId,label:w.name,kind:"profile",profileId:w.id,description:K?`${L.name} · ${w.modelId}`:L.name})}return l},[F,W,rt,ue]),yn=i.useMemo(()=>Re.findIndex(l=>l.kind==="profile"),[Re]),cs=ot[W]||null,Zt=!!n.agent&&_===n.agent,Pt=se!==void 0?se:Zt?n.profileId??null:void 0,Rt=Qe||Zt&&n.model||""||U?.selectedModel||"",Jt=_==="gemini"?"":Oe||(Zt?_t(_,n.thinkingEffort,n.workflowEnabled):"")||_t(_,U?.selectedEffort,U?.workflowEnabled)||"";i.useEffect(()=>{z?.({model:Rt||null,effort:Jt||null})},[Rt,Jt,z]);const ds=U?.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=(!!H.trim()||re.length>0)&&!M&&!!_,en=()=>{ce(null),Te(null),Ee(null),we(void 0)},Sn=i.useCallback((l,f,w)=>{pt(l),Ye(f),w!==void 0&&$e(w),l!==_&&Xe(""),en(),xe("closed")},[_]),hs=i.useCallback(l=>{Xe(l),Ee(null)},[]),ps=()=>{E==="closed"?(en(),Ae(),xt(),xe("agent")):(en(),xe("closed"))},tn=ve||_,Cn=dn(tn),nn=Je??Rt,xs=yt??Jt,fs=nn?zt(nn):"",Ve=(()=>{const l=!ve&&Pt!==void 0?Pt:ot[tn]??null;return l?rt.find(f=>f.id===l)??null:null})(),at=Ve?ue.find(l=>l.id===Ve.providerId)??null:null,gs=at?pr(at):null,sn=Ve?Ve.name.trim().toLowerCase()!==Ve.modelId.trim().toLowerCase()?Ve.name:zt(Ve.modelId):fs,ms=[Cn.shortLabel,at?at.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:it,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:[it?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),K=L?d("hub.steering"):he.length>1?`${d("hub.queued")} #${f+1}`:d("hub.queued"),oe=y?.find(X=>X.taskId===l)||(w?y?.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:K}),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:()=>Ze(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:st,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:()=>nt(f),className:C("flex flex-col w-full px-3 py-1.5 text-left transition-colors",f===tt?"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:H,onChange:l=>b(l.target.value),onPaste:S,onKeyDown:k,onCompositionStart:()=>{et.current=!0},onCompositionEnd:()=>{et.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:H.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(dt,{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}),at&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(dt,{brand:gs||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:at.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,K)=>e.jsx("span",{className:C("w-1.5 h-1.5 rounded-full transition-colors",E===L?"bg-primary":K<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(dt,{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",K=je!==void 0?je:W===_&&Pt!==void 0?Pt:cs,oe=l.kind==="profile"?!!l.profileId&&l.profileId===K:!K&&l.id===(Je??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(gr,{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:M?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(fr,{source:us,onClose:()=>{Ze(null),kt(null)},t:d})]})});function fr({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 or(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 gr({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 y=N=>{p.current&&!p.current.contains(N.target)&&c(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[r]),!n.length)return null;const d=n.find(y=>y.id===t)?.label||t||"—",m=n.findIndex(y=>y.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(y=>!y),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(y=>e.jsx(un,{selected:y.id===t,onClick:()=>{s(y.id),c(!1)},children:y.label},y.id))})]})}function mr(){return function(t){As(t)}}const jn=[Ps,mr],qn=t=>/^https?:\/\//.test(t),br=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function vr(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)||br(n)&&!n.startsWith("file://"))return!1;const s=vr(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 jr="text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",wr="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??jr,onClick:r=>{r.stopPropagation(),kn(t,n)},onKeyDown:r=>Yn(r,t,n),children:a??t})}function kr(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=kr(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??wr,children:r.display},c):e.jsx("span",{children:r.value},c))}):e.jsx(e.Fragment,{children:t})}function yr({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(yr,{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 jt(t){return!!t?.steps?.length}function Nr(t,n){let s=t;for(const[a,r]of Object.entries(n))s=s.replace(new RegExp(`\\{${a}\\}`,"g"),r);return s}function Sr({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(!jt(t))return null;const c=t.steps.length,p=t.steps.filter(v=>v.status==="completed").length,d=c>0&&p===c,m=Nr(n("hub.planProgress"),{done:String(p),total:String(c)});return e.jsx(ut,{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(Sr,{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||jt(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function _o(t){return es(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function Cr(t){return t.phase!=="done"||!t.error?null:es(t)?"hub.streamErrored":"hub.streamFailed"}function Ir({detail:t,t:n,className:s}){const a=Js(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 Lr=64;function Tr(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 Wo({stream:t,t:n,workdir:s}){const a=jt(t.plan),[r,c]=i.useState(!1),[p,d]=i.useState(!1),m=i.useRef(null),v=i.useRef(null),g=Cr(t),j=i.useMemo(()=>(t.activity||"").split(`
12
+ `).filter(Boolean),[t.activity]),y=t.previewMeta?.toolCalls??[],N=j[j.length-1]||y[y.length-1]?.summary||"",$=y.length,O=t.previewMeta?.contextPercent??null,A=t.previewMeta?.contextUsedTokens??0,P=t.previewMeta?.turnOutputTokens??0,z=t.phase==="streaming",H=z&&t.startedAt!=null&&t.startedAt>0,Y=z;i.useLayoutEffect(()=>{const I=m.current;I&&r&&(I.scrollTop=I.scrollHeight)},[r,t.activity,y.length]),i.useLayoutEffect(()=>{const I=v.current;I&&p&&(I.scrollTop=I.scrollHeight)},[p,t.thinking]);const M=t.subAgents??null,te=Tr(t.text,t.phase==="streaming"?Lr: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]"}),M&&M.length>0&&M.map(I=>e.jsx(ns,{sub:I,t:n},I.id)),(y.length>0||j.length>0)&&e.jsx(ut,{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:N,workdir:s})}),badge:(y.length||j.length)>1?e.jsx(fn,{children:y.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:y.length>0?y.map(I=>e.jsx(Er,{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(ut,{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(Mr,{toolCount:$,ctxPct:O,ctxTokens:A,turnOutTokens:P,startedAt:H?t.startedAt:null}),g&&t.error&&e.jsx(Ir,{detail:t.error,t:n,className:"pt-0.5"})]})}function Er({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 Mr({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(Ar,{toolCount:t,ctxPct:n,ctxTokens:s,turnOutTokens:a,startedAt:r})]})}function Ar({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(Pr,{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 Pr({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:Zs(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,y=[];for(const N of d)j.has(N.name)||(j.add(N.name),y.push(N.name));return y},[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(ut,{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 Rr({message:t,t:n,workdir:s}){const{activityBlocks:a,thinkingBlocks:r,planBlocks:c,subAgentBlocks:p,outputBlocks:d,noticeBlocks:m}=ss(t.blocks),v=Gs(c);return a.length>0||p.length>0||!!v||r.length>0||d.length>0||m.length>0?e.jsxs("div",{className:"space-y-3",children:[a.length>0&&e.jsx(Br,{blocks:a,t:n,workdir:s}),p.map(j=>j.subAgent?e.jsx(ns,{sub:j.subAgent,t:n},j.toolId||j.subAgent.id):null),v&&e.jsx(Zn,{plan:v,t:n,className:"max-w-[760px]"}),r.length>0&&e.jsx(Or,{blocks:r,t:n}),d.length>0&&e.jsx(Ur,{blocks:d,t:n,workdir:s}),m.length>0&&e.jsx(Wr,{blocks:m,t:n})]}):null}function _r(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=>jt(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"&&jt(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 Wr({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 Br({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(ut,{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($r,{block:v,workdir:s},g))})})}function $r({block:t,workdir:n}){const[s,a]=i.useState(!1),r=t.type==="tool_use",c=r?Gn(t):ar(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 Or({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(ut,{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(Dr,{scrollRef:r,text:c})})}function Dr({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 Fr({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 Ur({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(Fr,{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 Bo=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:y,hideHeaderUsage:N,isTail:$}){const O=n.user&&Un(n.user.text),A=y&&typeof s=="number"?()=>y(s):void 0,P=i.useMemo(()=>qt({workdir:v}),[v]),z=!!n.assistant&&_r(n.assistant);return e.jsxs("div",{className:C("session-turn",$&&"session-turn--live"),children:[n.user&&!O&&e.jsx(os,{text:n.user.text,blocks:n.user.blocks,t:m,onResend:g,onEdit:j,onFork:A}),O&&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:P,children:n.user.text})}),z&&e.jsxs(e.Fragment,{children:[e.jsx(Vr,{agent:a,meta:r,model:c,effort:p,providerName:d,previewMeta:n.assistant.usage??null,hideContextUsage:N}),e.jsx("div",{className:"mb-6",children:e.jsx(Rr,{message:n.assistant,t:m,workdir:v})})]})]})});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 zr=1500,Kr=16,Mn=8;function Hr(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),y=t?t.split(`
22
+ `).length:0,N=!!t&&(t.length>zr||y>Kr),[$,O]=i.useState(!1),A=t?N&&!$?Hr(t):t:"",P=!!(a||r||c),z=n?.filter(M=>M.type==="image")||[],H=()=>{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(y));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[A,N&&!$&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),N&&e.jsx("button",{type:"button",onClick:()=>O(M=>!M),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}),z.length>0&&e.jsx("div",{className:C("flex flex-wrap gap-2",t&&"mt-2"),children:z.map((M,te)=>e.jsx("img",{src:M.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(M.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:H,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 Vr({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(dt,{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:Gr(c),children:[d!=null&&e.jsx(qr,{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 Gr(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 qr({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--D5NGYgd.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function hn(){return Pn??=Bn(()=>import("./SessionPanel--D5NGYgd.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Pn}const Yr=i.lazy(async()=>({default:(await hn()).SessionPanel})),cn=5,Xr=240,Zr=120,Jr=12,eo=900*1e3,q=(t,n)=>`${t}:${n}`;function to(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 no=0;function vt(){return`mk-${Date.now().toString(36)}-${(++no).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 so=[1,2,3,6],pn=6;function ro(t){for(const n of so)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=ro(t);return s>n?s:n}function oo(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function io(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 ao=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,y]=i.useState(!0),[N,$]=i.useState(()=>{const o=$t("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Rn()}),[O,A]=i.useState(()=>{const o=$t("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Rn()}),[P,z]=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||vt()}))}}catch{}return[]}),[H,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}),M=i.useCallback(o=>{$(o),Ot("pikiloom-layout-mode",String(o))},[]),te=i.useCallback(o=>{A(o),Ot("pikiloom-layout-floor",String(o))},[]),T=i.useCallback(o=>{z(h=>{const u=typeof o=="function"?o(h):o,x=u.map(({pendingPrompt:b,pendingImageUrls:k,...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=>{M(o),te(o)},[M,te]);i.useEffect(()=>{T(o=>o.length>N?o.slice(0,N):o),D(o=>o>=N?N-1:o)},[N]);const[Z,R]=i.useState(!1),ne=i.useRef(N);ne.current=N;const Q=i.useRef(O);Q.current=O;const pe=i.useRef(H);pe.current=H;const V=i.useRef(P);V.current=P;const wt=i.useRef(-1),me=P[H]??null,pt=i.useCallback(o=>{if(!o){T([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:vt()};T(u=>{const x=u.findIndex(k=>k.agent===h.agent&&k.sessionId===h.sessionId);if(x>=0)return D(x),u;if(u.length<ne.current){const k=[...u,h];return D(k.length-1),k}if(ne.current<pn){const k=[...u,h];return M(Ge(k.length,Q.current)),D(k.length-1),k}const b=[...u];return b[pe.current]=h,b})},[T,D,M]),[Qe,Ye]=i.useState(!1),[se,$e]=i.useState(null),[Oe,Xe]=i.useState(""),[re,De]=i.useState("all"),[be,Ze]=i.useState({}),[Le,kt]=i.useState({}),ve=i.useDeferredValue(Oe),ce=i.useRef(!1),Je=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 k=In(b,x.agent,x.sessionId);return k===x.sessionId?x:(h=!0,{...x,sessionId:k})});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{y(!1)}},[]);i.useEffect(()=>{we()},[we]);const E=i.useCallback(async(o,h={})=>{if(!Je.current[o]){Je.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||{},k=x[o];return k&&Object.keys(k).length===Object.keys(b).length&&Object.entries(b).every(([S,_])=>k[S]===_)?x:{...x,[o]:b}}),m(x=>{const b=u.sessions||[],k=x[o]||[],S=new Set(b.map(U=>q(U.agent||"",U.sessionId))),_=k.filter(U=>{if(U.runState!=="running")return!1;const W=q(U.agent||"",U.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{Je.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:Jr}))},[]),Nt=i.useCallback((o,h,u=Zr)=>{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 et=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(k=>(Te.current[k.path]||[]).some(S=>q(S.agent||"",S.sessionId)===h)):c,x=u.length?u:c,b=et.current;for(const k of x)b.has(k.path)&&clearTimeout(b.get(k.path)),b.set(k.path,setTimeout(()=>{b.delete(k.path),E(k.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);Ze(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,k=b(x[h],u),S=u.resolvedKey===h||b(x[u.resolvedKey],{...u,key:u.resolvedKey});if(k&&S)return x;const _=Date.now()-eo,U={};for(const[W,F]of Object.entries(x))F.phase==="done"&&F.updatedAt<_||(U[W]=F);return U[h]=u,u.resolvedKey!==h&&(U[u.resolvedKey]={...u,key:u.resolvedKey}),U})},[])),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 k=setTimeout(()=>{Ee.current.add(b),J(x,h.path)},Xr+u*120);o.push(k)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,J,c]);const Qt=i.useCallback(async o=>{try{(await ie.addWorkspace(o)).ok&&(Ye(!1),await we(),E(o))}catch{}},[we,E]),[fe,ke]=i.useState(null),[ye,St]=i.useState(!1),[de,Ue]=i.useState(null),tt=i.useCallback(o=>{ke(o)},[]),nt=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&&M(Ge(u.length,Q.current)),u}),D(0),ke(null)}catch{}finally{St(!1)}}},[fe]),st=i.useCallback(o=>{E(o,{force:!0})},[E]),[Ae,Ne]=i.useState(null),[ze,xt]=i.useState(!1),[ue,rt]=i.useState(!1),ot=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 ft=i.useCallback(o=>{xt(!1),Ne(o),Pe(null)},[]),Se=i.useCallback(async()=>{const o=Ae;if(o){rt(!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");ot(u,!1);return}m(u=>{const x=u[o.workdir];if(!x)return u;const b=x.filter(k=>!(k.agent===o.agent&&k.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&&M(Ge(x.length,Q.current)),x}),Ne(null)}catch(h){ot(h?.message||r("session.deleteFailed"),!1)}finally{rt(!1)}}},[Ae,ze,r,ot]),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(k=>{const S=k[o.workdir]||[];if(S.some(W=>W.sessionId===o.sessionId&&W.agent===o.agent))return k;const U={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...k,[o.workdir]:[U,...S]}});const x=wt.current,b={...o,mountKey:vt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};i.startTransition(()=>{$e(null),T(k=>{if(x>=k.length)return[...k,b];const S=[...k];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&&M(Ge(ne.current+1,Q.current)),$e(o)},[M]),Tt=i.useCallback(()=>{$e(null),M(Ge(V.current.length,Q.current))},[M]),Et=i.useCallback((o,h)=>{J(o,h);const u=o.agent||"";V.current.some(x=>x.agent===u&&x.sessionId===o.sessionId)&&M(Ge(V.current.length,Q.current)),$e(null),i.startTransition(()=>{pt({agent:u,sessionId:o.sessionId,workdir:h})})},[J,M]),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],k=b.agent===o.agent&&ct(b.sessionId)&&!ct(o.sessionId);return x[h]={...b,agent:o.agent,sessionId:o.sessionId,workdir:o.workdir,mountKey:k?b.mountKey:vt(),pendingPrompt:k?b.pendingPrompt:null,pendingImageUrls:k?b.pendingImageUrls:void 0},x}),D(h)):pt({...o,mountKey:vt()})}),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),U=be[_],W=x?In(x,S.agent||"",S.sessionId):S.sessionId,F=U?.resolvedKey&&U.resolvedKey!==_?U.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 k=he([...b.values()]);o[h.path]=to(k)}return o},[c,d,be,Le,he,Fe]),gt=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,it=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),M(Ge(u.length,Q.current)),u})},[T,D,M]);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=>Xe(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:()=>Xe(""),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&&!Qe?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:r("hub.noWorkspaces")}):c.map(o=>e.jsx(ho,{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:st,onRemove:tt,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",N===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1)]":"text-fg-5/40 hover:text-fg-4"),title: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:()=>Ye(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(${N===6?3:N}, 1fr)`,gridTemplateRows:N===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=se?P.length<N?P.length:H:-1;return wt.current=o,Array.from({length:N},(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(co,{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=gt(x),k=u===H;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",k?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:k?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>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",k?"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)||(ct(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(),it(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(Yr,{session:b,workdir:x.workdir,active:n&&k,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(xo,{workdir:me.workdir,onClose:()=>R(!1),t:r}),e.jsx(lo,{open:Qe,initialPath:a||void 0,onAdd:Qt,onClose:()=>Ye(!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:nt,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:()=>ft(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:()=>xt(!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:()=>xt(!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 lo({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 co({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"}),[]),y=i.useCallback(()=>{},[]),N=i.useCallback((A,P)=>{p(A||null),v.current=A||null;const z=P||[];m(z),g.current=z},[]),$=i.useCallback(A=>{const P=g.current;g.current=[],s(A,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(A=>({type:"image",content:A})),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(xr,{session:j,workdir:t,onStreamQueued:y,onSendStart:N,onSessionChange:$,t:r,streamPhase:null})]})}function uo({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 ho=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:y,onWarmSession:N,onCancelWarmSession:$,onSessionMenuOpen:O,t:A}){const[P,z]=i.useState(!0),[H,Y]=i.useState(cn);i.useEffect(()=>{Y(cn)},[s.length]);const M=s.slice(0,H),te=s.length-H,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:()=>z(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(uo,{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:A("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:R=>{R.stopPropagation(),j(T)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:A("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick: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"})]})}),y&&!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:A("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:A("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[M.map(R=>{const ne=q(R.agent||"",R.sessionId),Q=R.__forkDepth||0;return e.jsx(po,{session:R,isSelected:c===ne,isOpen:p?.has(ne)??!1,forkDepth:Q,onClick:()=>d(R,T),onWarm:()=>N(R,T),onCancelWarm:()=>$(R,T),onShowMenu:pe=>O(pe,R,T),menuLabel:A("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:["+ ",A("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"})})]})]})})]})}),po=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),y=_n(n).slice(0,500)||(ct(n.sessionId)?"":n.sessionId.slice(0,16)),N=Ts(n,y).slice(0,500),$=n.model?zt(n.model):null,O=r>0?Math.min(r,3)*14:0,A=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:A+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(dt,{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:y})]}),N&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:N})})]}),e.jsx("button",{ref:P,type:"button","aria-label":v,"aria-haspopup":"menu",onMouseDown:z=>{z.stopPropagation()},onClick:z=>{z.stopPropagation(),z.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"})]})})]})}),xo=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(()=>io(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=>{oo(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(fo,{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(dt,{brand:t,size:n})}function fo({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(y=>({entry:y,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||m(!1)}),()=>{g=!0}},[t,n]);const v=i.useCallback(g=>{const j=y=>y.map(N=>N.entry.path===g?N.expanded?{...N,expanded:!1}:N.children===null?(ie.lsDir(g,!0,n).then($=>{$.ok&&p(O=>xn(O,g,{children:$.dirs.slice(0,50).map(A=>({entry:A,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{p($=>xn($,g,{children:[],loading:!1}))}),{...N,loading:!0,expanded:!0}):{...N,expanded:!0}:N.children?{...N,children:j(N.children)}:N);p(y=>j(y))},[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(go,{node:p,depth:n,onToggle:s,openTarget:a,onOpenPath:r,t:c},p.entry.path))})}function go({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,y]=i.useState(!1),N=c(is(a)),$=c("hub.openWithTarget").replace("{target}",N);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:p.isDir?()=>s(p.path):void 0,onMouseEnter:()=>y(!0),onMouseLeave:()=>y(!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(mo,{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 mo({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 $o=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:ao},Symbol.toStringTag,{value:"Module"}));export{xr as I,Wo as L,Ir as R,Bo as T,os as U,Po as a,es as b,Ks as c,Lo as d,Vs as e,Eo as f,Hs as g,jt as h,Mo as i,_o as j,To as k,Fs as l,Ro as m,Ao as n,Io as o,Ds as p,_r as q,ts as r,Co as s,Vr as t,Mr as u,$o as v};
@@ -1 +1 @@
1
- import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-Iot9Vn3K.js";function o({primary:e,secondary:l,tertiary:n}){return s.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e&&s.jsxs(i,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(i,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),n&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:n})]})}function c({children:e,className:l}){return s.jsx(t,{padding:"md",elevation:"flat",className:l,children:e})}export{o as A,c as S};
1
+ import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-BDSh0L9U.js";function o({primary:e,secondary:l,tertiary:n}){return s.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e&&s.jsxs(i,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(i,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),n&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:n})]})}function c({children:e,className:l}){return s.jsx(t,{padding:"md",elevation:"flat",className:l,children:e})}export{o as A,c as S};
@@ -6,7 +6,7 @@
6
6
  <link rel="icon" type="image/png" href="/logo.png">
7
7
  <title>Pikiloom</title>
8
8
  <link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
9
- <script type="module" crossorigin src="/assets/index-Iot9Vn3K.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-BDSh0L9U.js"></script>
10
10
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-C7Sl8SE7.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/router-DHISdpPk.js">
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-BO-FYAny.css">
@@ -7,6 +7,7 @@ import { Q, run, agentError, agentLog, agentWarn, buildStreamPreviewMeta, comput
7
7
  import { AGENT_STREAM_HARD_KILL_GRACE_MS, AGENT_GRACEFUL_ABORT_GRACE_MS, SESSION_RUNNING_THRESHOLD_MS } from '../../core/constants.js';
8
8
  import { terminateProcessTree } from '../../core/process-control.js';
9
9
  import { getHome, IS_MAC, encodePathAsDirName } from '../../core/platform.js';
10
+ import { loadDeliveredTurns, buildRecoveryQueue, normalizeSnapshotPrompt } from '../turn-snapshot.js';
10
11
  function buildClaudeUserMessage(prompt, attachments) {
11
12
  const content = [];
12
13
  for (const filePath of attachments) {
@@ -1516,6 +1517,9 @@ function isClaudeSyntheticResumeNoise(text) {
1516
1517
  return t === 'no response requested.' || t === 'no response requested';
1517
1518
  }
1518
1519
  const CLAUDE_INCOMPLETE_TURN_NOTICE = '⚠️ This reply ended before a closing message was delivered (interrupted, or the model returned an empty final response).';
1520
+ // Shown under a reply we restored from pikiloom's delivery snapshot because the agent transcript
1521
+ // lost it (see turn-snapshot.ts). The content above is what was actually streamed to the user.
1522
+ const CLAUDE_RECOVERED_TURN_NOTICE = 'ℹ️ Restored by pikiloom from the delivered reply — the agent’s own transcript dropped this turn.';
1519
1523
  function getClaudeSessionMessages(opts) {
1520
1524
  const projectDir = path.join(getHome(), '.claude', 'projects', claudeProjectDirName(opts.workdir));
1521
1525
  const filePath = path.join(projectDir, `${opts.sessionId}.jsonl`);
@@ -1527,6 +1531,13 @@ function getClaudeSessionMessages(opts) {
1527
1531
  const lines = content.split('\n').filter(l => l.trim());
1528
1532
  const allMsgs = [];
1529
1533
  const richMsgs = [];
1534
+ // Delivered-reply snapshots keyed by prompt, consumed at tombstones to restore swallowed turns.
1535
+ const recoveryQueue = buildRecoveryQueue(loadDeliveredTurns(opts.sessionId));
1536
+ let lastUserPromptNorm = '';
1537
+ const takeRecoveredTurn = (promptNorm) => {
1538
+ const list = promptNorm ? recoveryQueue.get(promptNorm) : undefined;
1539
+ return list && list.length ? list.shift() : null;
1540
+ };
1530
1541
  let pendingRole = null;
1531
1542
  let pendingTextParts = [];
1532
1543
  let pendingBlocks = [];
@@ -1699,6 +1710,8 @@ function getClaudeSessionMessages(opts) {
1699
1710
  pendingRole = 'user';
1700
1711
  pendingTextParts = text ? [text] : [];
1701
1712
  pendingBlocks = text ? [{ type: 'text', content: text }, ...imageBlocks] : [...imageBlocks];
1713
+ if (text)
1714
+ lastUserPromptNorm = normalizeSnapshotPrompt(text);
1702
1715
  }
1703
1716
  }
1704
1717
  else if (ev.type === 'assistant') {
@@ -1715,7 +1728,21 @@ function getClaudeSessionMessages(opts) {
1715
1728
  if (pendingRole === 'user')
1716
1729
  flush();
1717
1730
  pendingRole = 'assistant';
1718
- pendingBlocks.push({ type: 'system_notice', content: displayText });
1731
+ // If this tombstone is the whole assistant turn (nothing landed in the jsonl) and we
1732
+ // hold a delivered-reply snapshot for the preceding prompt, restore the real reply
1733
+ // instead of the "ended before a closing message" notice. When partial content did
1734
+ // land (pending blocks already present) we leave it — partial + notice is truthful.
1735
+ const turnEmpty = pendingBlocks.length === 0 && pendingTextParts.length === 0;
1736
+ const recovered = (displayText === CLAUDE_INCOMPLETE_TURN_NOTICE && turnEmpty)
1737
+ ? takeRecoveredTurn(lastUserPromptNorm) : null;
1738
+ if (recovered) {
1739
+ pendingTextParts.push(recovered);
1740
+ pendingBlocks.push({ type: 'text', content: recovered });
1741
+ pendingBlocks.push({ type: 'system_notice', content: CLAUDE_RECOVERED_TURN_NOTICE });
1742
+ }
1743
+ else {
1744
+ pendingBlocks.push({ type: 'system_notice', content: displayText });
1745
+ }
1719
1746
  continue;
1720
1747
  }
1721
1748
  if (pendingRole === 'user')
@@ -2104,8 +2131,12 @@ export function claudeNativeUsage(opts) {
2104
2131
  // through a long 429 stretch instead of freezing on the first degraded read).
2105
2132
  if (!result && (!claudeUsageCache.lastGood || claudeUsageCache.lastGood.source === 'ratelimit-headers')) {
2106
2133
  const token = getClaudeOAuthToken();
2107
- if (token)
2108
- result = await claudeUsageForToken(token, opts);
2134
+ // Flag the header-probe stand-in as degraded so surfaces can say "only 5h/7d, Fable/Extra
2135
+ // pending" instead of silently presenting a coarse read as the full picture.
2136
+ if (token) {
2137
+ const probe = await claudeUsageForToken(token, opts);
2138
+ result = probe ? { ...probe, degraded: true } : probe;
2139
+ }
2109
2140
  agentLog(`[usage] native oauth usage read failed; header-probe fallback -> ${result ? result.source : 'null'}`);
2110
2141
  }
2111
2142
  if (result) {
@@ -523,14 +523,34 @@ function buildCodexAssistantText(blocks) {
523
523
  return toolNames.join(', ');
524
524
  return blocks.find(block => block.type === 'tool_result' && block.content.trim())?.content.trim() || '';
525
525
  }
526
+ function normalizeCodexOverlayQuestion(value) {
527
+ return stripInjectedPrompts(value || '').replace(/\s+/g, ' ').trim();
528
+ }
529
+ function previousUserQuestionForAssistant(richMessages, assistantIndex) {
530
+ for (let i = assistantIndex - 1; i >= 0; i--) {
531
+ const message = richMessages[i];
532
+ if (message.role === 'user')
533
+ return normalizeCodexOverlayQuestion(message.text);
534
+ }
535
+ return '';
536
+ }
537
+ function findCodexManagedPreviewAssistantIndex(richMessages, managedLastQuestion) {
538
+ const expectedQuestion = normalizeCodexOverlayQuestion(managedLastQuestion);
539
+ if (!expectedQuestion)
540
+ return -1;
541
+ for (let i = richMessages.length - 1; i >= 0; i--) {
542
+ if (richMessages[i].role !== 'assistant')
543
+ continue;
544
+ if (previousUserQuestionForAssistant(richMessages, i) === expectedQuestion)
545
+ return i;
546
+ }
547
+ return -1;
548
+ }
526
549
  function overlayCodexManagedPreview(workdir, sessionId, richMessages) {
527
550
  const managed = findPikiloomSession(workdir, 'codex', sessionId);
528
551
  if (!managed)
529
552
  return richMessages;
530
- const assistantIndex = [...richMessages]
531
- .map((message, index) => ({ message, index }))
532
- .reverse()
533
- .find(entry => entry.message.role === 'assistant')?.index ?? -1;
553
+ const assistantIndex = findCodexManagedPreviewAssistantIndex(richMessages, managed.lastQuestion);
534
554
  if (assistantIndex < 0)
535
555
  return richMessages;
536
556
  const current = richMessages[assistantIndex];