pikiloom 0.4.34 → 0.4.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dashboard/dist/assets/{AgentTab-DvqESwfi.js → AgentTab-BFGZXRX9.js} +1 -1
- package/dashboard/dist/assets/{ConnectionModal-Dju5ooUi.js → ConnectionModal-DI0f63Bc.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-IIrd6DvC.js → DirBrowser-CzkwSAi6.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-CJruEOtx.js → ExtensionsTab-BdK8ylOy.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-DrkSXehX.js → IMAccessTab-BdkwcX7w.js} +1 -1
- package/dashboard/dist/assets/{Modal-enSRVh_K.js → Modal-CaNqa2E7.js} +1 -1
- package/dashboard/dist/assets/{Modals-D3KV0p79.js → Modals-2DgJPKGI.js} +1 -1
- package/dashboard/dist/assets/{Select-B5l44VMQ.js → Select-izl0nVH0.js} +1 -1
- package/dashboard/dist/assets/{SessionPanel-C9Y7P7yk.js → SessionPanel-BKde6FwO.js} +1 -1
- package/dashboard/dist/assets/{SystemTab-CVeipfUR.js → SystemTab-DKuQIo87.js} +1 -1
- package/dashboard/dist/assets/{index-DPBa40VJ.js → index-B4_qsasx.js} +3 -3
- package/dashboard/dist/assets/{index-CH_4h4ZM.css → index-CkriX56t.css} +1 -1
- package/dashboard/dist/assets/index-CwfalaN2.js +23 -0
- package/dashboard/dist/assets/{shared-Ct_RTrnU.js → shared-CZ_jczjY.js} +1 -1
- package/dashboard/dist/index.html +2 -2
- package/dist/agent/artifacts.js +26 -0
- package/dist/agent/drivers/claude.js +18 -1
- package/dist/agent/index.js +1 -1
- package/dist/core/constants.js +1 -0
- package/dist/dashboard/routes/sessions.js +13 -10
- package/package.json +1 -1
- package/dashboard/dist/assets/index-Mb8DbNHN.js +0 -23
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-BKde6FwO.js","assets/react-vendor-C7Sl8SE7.js","assets/index-B4_qsasx.js","assets/router-DHISdpPk.js","assets/index-CkriX56t.css","assets/Modal-CaNqa2E7.js","assets/Select-izl0nVH0.js","assets/DirBrowser-CzkwSAi6.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-BdK8ylOy.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as T,a as se,u as Ce,i as Kt,f as Pt,A as bs,s as Ht,S as pe,B as it,g as pn,w as vs,b as js,E as an,C as bn,d as ws,r as In,e as Ln,h as ks,n as ys,j as Ns,k as _n,l as Dt,m as Re,D as Qt,o as Ss,p as Wn,_ as Bn,T as Cs,q as Is}from"./index-B4_qsasx.js";import{j as e,r,a as vn}from"./react-vendor-C7Sl8SE7.js";import{I as Ls}from"./Select-izl0nVH0.js";import{M as Vt,a as Gt}from"./Modal-CaNqa2E7.js";import{D as Ts}from"./DirBrowser-CzkwSAi6.js";import{n as Es,r as Ms,M as jn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as As}from"./ExtensionsTab-BdK8ylOy.js";function Rs({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:T("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 lt({open:t,onToggle:n,dot:s,label:l,preview:i,badge:c,collapsedContent:x,children:d,className:b}){return e.jsxs("div",{className:T("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",b),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:T("h-[7px] w-[7px] shrink-0 rounded-full",s.color,s.pulse&&"animate-pulse")}),e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:l}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:i}),c,e.jsx(Rs,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Ps=5e3,_s=15e3,Ft=8,Ut=30,Ws=1,ot=new Map,Se=new Map,cn=new Set,$n=[];let _t=0;function dn(t){return typeof t=="number"&&Number.isFinite(t)}function Ve(t,n,s,l){for(t.delete(n),t.set(n,s);t.size>l;){const i=t.keys().next().value;if(!i)break;t.delete(i)}}function On(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(Ve(t,n,s,t===Se?Ut:Ft),s.value)}function Dn(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:dn(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:dn(t.turnOffset)?t.turnOffset:void 0,turnLimit:dn(t.turnLimit)?t.turnLimit:void 0}}function wn(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(;_t<Ws;){const t=$n.shift();if(!t)return;_t+=1,t().finally(()=>{_t=Math.max(0,_t-1),Fn()})}}async function Bs(t,n={}){const s=t;if(!n.force){const c=On(ot,s);if(c)return c}const l=ot.get(s);if(l?.promise)return l.promise;const i=se.getWorkspaceSessions(t,n.request).then(c=>(Ve(ot,s,{value:c,expiresAt:c.ok?Date.now()+Ps:0},Ft),c)).finally(()=>{const c=ot.get(s);c?.promise&&Ve(ot,s,{value:c.value,expiresAt:c.expiresAt},Ft)});return Ve(ot,s,{value:l?.value,expiresAt:l?.expiresAt??0,promise:i},Ft),i}function $s(t,n={}){const s=wn(t),l=Se.get(s);return l?.value?.ok&&(n.allowStale||l.expiresAt>Date.now())?l.value:null}async function Os(t,n={}){const s=Dn(t),l=wn(s);if(!n.force){const x=On(Se,l);if(x?.ok)return x}const i=Se.get(l);if(i?.promise)return i.promise;const c=se.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(Ve(Se,l,{value:x,expiresAt:x.ok?Date.now()+_s:0},Ut),x)).finally(()=>{const x=Se.get(l);x?.promise&&Ve(Se,l,{value:x.value,expiresAt:x.expiresAt},Ut)});return Ve(Se,l,{value:i?.value,expiresAt:i?.expiresAt??0,promise:c},Ut),c}function Ds(t){const n=wn(t);$s(t)||cn.has(n)||Se.get(n)?.promise||(cn.add(n),$n.push(async()=>{try{await Os(t)}catch{}finally{cn.delete(n)}}),Fn())}function ho(t){const n=t.streaming||t.liveStreamPhase==="streaming",s=t.queuedTaskCount>0||t.pendingQueuedCount>0||t.streamPhase==="queued";return n||s}function xo(t){const{pendingTaskId:n,streamTaskId:s,queuedTaskIds:l}=t;return!n||n===s?!1:!!l&&l.includes(n)}function Fs(t){const{queuedTaskIds:n,streamPhase:s,streamTaskId:l,localTaskId:i}=t,c=[];n&&n.length&&c.push(...n),s==="queued"&&l&&!c.includes(l)&&c.unshift(l),i&&!c.includes(i)&&(s==="queued"||!s)&&c.push(i);const x=s==="streaming"?l??null:null;return x?c.filter(d=>d!==x):c}function po(t,n){return t==null||n==null?!0:t===n}function Tn(t){return(t||"").replace(/\s+/g," ").trim()}function fo(t,n){return Tn(t)===Tn(n)}function go(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(x=>({role:x.role,text:x.text,blocks:[{type:"text",content:x.text}]}))||[],s=zs(n),l=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),i=t.window?.endTurn??l,c=t.window?.startTurn??Math.max(0,i-s.length);return{turns:s,startTurn:c,endTurn:i,totalTurns:l,hasOlder:t.window?.hasOlder??c>0}}function mo(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 bo(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 Us(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 zs(t){const n=[];let s={user:null,assistant:null};for(const l of t)if(l.role==="user"){if(s.assistant&&Un(l.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=l}else s.assistant?s.assistant=Us(s.assistant,l):s.assistant=l;return(s.user||s.assistant)&&n.push(s),n}const Ks=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"]),Hs=["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&&Ks.has(s[1].toLowerCase())?!0:Hs.some(l=>t.includes(l))}function zn(t,n){const s=t.split(`
|
|
5
|
+
`).filter(l=>l.trim());return s.length<=n?s.join(`
|
|
6
|
+
`):s.slice(-n).join(`
|
|
7
|
+
`)}function Vs(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 un(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function Gs(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function Kn(t){if(!Number.isFinite(t)||t<=0)return"0 B";if(t<1024)return`${t} B`;const n=t/1024;if(n<1024)return`${n.toFixed(n>=100?0:1)} KB`;const s=n/1024;return`${s.toFixed(s>=100?0:1)} MB`}async function qs(t){if(typeof ClipboardItem>"u"||!navigator.clipboard?.write)return!1;try{return await navigator.clipboard.write([new ClipboardItem({[t.type||"image/png"]:t})]),!0}catch{return!1}}function Z(t,n=120){if(t==null)return"";const l=(typeof t=="string"?t:String(t)).replace(/\s+/g," ").trim();return l.length<=n?l:l.slice(0,Math.max(0,n-1))+"…"}function Qs(t){if(!t)return null;try{const n=JSON.parse(t);return n&&typeof n=="object"&&!Array.isArray(n)?n:null}catch{return null}}function Hn(t){const n=String(t.toolName||"").trim()||"Tool",s=Qs(t.content);if(!s)return n;const l=Z(s.description,120);switch(n){case"Read":{const i=Z(s.file_path||s.path,140);return i?`Read ${i}`:"Read"}case"Edit":{const i=Z(s.file_path||s.path,140);return i?`Edit ${i}`:"Edit"}case"Write":{const i=Z(s.file_path||s.path,140);return i?`Write ${i}`:"Write"}case"Glob":{const i=Z(s.pattern||s.glob,120);return i?`Glob ${i}`:"Glob"}case"Grep":{const i=Z(s.pattern||s.query,120);return i?`Grep ${i}`:"Grep"}case"WebFetch":{const i=Z(s.url,120);return i?`WebFetch ${i}`:"WebFetch"}case"WebSearch":{const i=Z(s.query,120);return i?`WebSearch ${i}`:"WebSearch"}case"TodoWrite":return"Update plan";case"AskUserQuestion":{const c=(Array.isArray(s.questions)?s.questions:[])[0],x=Z(c?.question||s.question,120);return x?`Ask user: ${x}`:"Ask user"}case"Task":{const i=Z(s.description||s.prompt,120);return i?`Task: ${i}`:"Task"}case"Bash":{if(l)return`Bash: ${l}`;const i=Z(s.command,120);return i?`Bash: ${i}`:"Bash"}default:{const i=n.match(/^mcp__[^_]+__(.+)$/),c=i?i[1]:n;if(c==="im_send_file"){const d=Z(s.path,120);return d?`Send file: ${d}`:"Send file"}if(c==="im_list_files")return"List workspace files";if(l)return`${n}: ${l}`;const x=Z(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return x?`${n}: ${x}`:n}}}function Ys(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
|
|
8
|
+
`).map(l=>l.trim()).find(Boolean)||"";return s?Z(s,140):"result"}function Xs(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),l=t.slice(n+1).trim();return!s||!l?null:{agent:s,sessionId:l}}const wt=new Map;function Zs(t,n){return`${t}:${n}`}function Js(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 er=r.memo(function({session:n,workdir:s,onStreamQueued:l,onSendStart:i,onSendTaskAssigned:c,onSessionChange:x,t:d,streamPhase:b,streamTaskId:v,queuedTaskIds:g,queuedTasks:w,pendingQueuedSends:S,onRecall:N,onSteer:$,onStopAll:M,editDraft:R,onEditDraftConsumed:P,onSelectionChange:U}){const[D,V]=r.useState(""),[E,z]=r.useState(!1),[W,k]=r.useState(null),[Q,_]=r.useState(()=>new Set),[ae,oe]=r.useState(()=>new Set),G=r.useRef({prompt:"",files:[]}),Ie=Ce(a=>a.agentStatus?.agents??null),[K,kt]=r.useState(Ie||[]),[fe,ct]=r.useState(""),[Ge,qe]=r.useState(""),[J,_e]=r.useState(void 0),[We,dt]=r.useState(""),[ee,Be]=r.useState([]),[ge,Qe]=r.useState(null),[Le,yt]=r.useState(null),[ce,ie]=r.useState(null),[$e,Te]=r.useState(null),[ut,Ee]=r.useState(null),[re,me]=r.useState(void 0),[L,te]=r.useState("closed"),[Y,Nt]=r.useState(null),Me=r.useRef(null),Ye=r.useRef(!1),Oe=r.useRef(null),Xt=r.useRef(null),de=r.useRef(null),be=r.useRef([]),[ve,St]=r.useState([]),[le,De]=r.useState(!1),[Xe,Ze]=r.useState(0),Je=r.useRef(null),Ae=Ce(a=>a.refreshAgentStatus),[je,et]=r.useState([]),[Fe,we]=r.useState([]),[ht,xt]=r.useState({}),ue=r.useCallback(async()=>{try{const[a,f,m]=await Promise.all([fetch("/api/models/providers").then(C=>C.json()),fetch("/api/models/profiles").then(C=>C.json()),fetch("/api/models/agents").then(C=>C.json())]);if(a?.ok&&we(a.providers||[]),f?.ok&&et(f.profiles||[]),m?.ok){const C={};for(const F of m.bindings||[])C[F.agent]=F.activeProfileId;xt(C)}}catch{}},[]);r.useEffect(()=>{ue()},[ue]),r.useEffect(()=>{Ie?.length&&kt(Ie)},[Ie]),r.useEffect(()=>{be.current=ee},[ee]);const ke=Zs(n.agent||"",n.sessionId),tt=r.useRef(ke);tt.current=ke,r.useEffect(()=>{const a=wt.get(ke);return a&&(wt.delete(ke),a.text&&V(a.text),a.files.length&&Be(a.files.map(un))),()=>{const f=Me.current?.value||"",m=be.current.map(C=>C.file);for(const C of be.current)URL.revokeObjectURL(C.previewUrl);f||m.length?wt.set(tt.current,{text:f,files:m}):wt.delete(tt.current)}},[ke]);const Ct=r.useRef({agent:n.agent||"",sessionId:n.sessionId});r.useEffect(()=>{const a=Ct.current,f={agent:n.agent||"",sessionId:n.sessionId};Ct.current=f,!(a.agent===f.agent&&Kt(a.sessionId)&&!Kt(f.sessionId))&&(ct(""),qe(""),_e(void 0),dt(""),ie(null),Te(null),Ee(null),te("closed"))},[n.agent,n.sessionId]),r.useEffect(()=>{R!=null&&(V(R),P?.(),requestAnimationFrame(()=>{const a=Me.current;a&&(a.focus(),a.setSelectionRange(R.length,R.length))}))},[R,P]),r.useEffect(()=>{if(!s)return;let a=!1;return se.getSkills(s).then(f=>{!a&&f.ok&&St(f.skills)}).catch(()=>{}),()=>{a=!0}},[s]);const pt=le?(()=>{const a=D.match(/^\/(\S*)$/);return a?a[1].toLowerCase():null})():null,ye=pt!==null?ve.filter(a=>a.name.toLowerCase().includes(pt)||a.label&&a.label.toLowerCase().includes(pt)):[];r.useEffect(()=>{Ze(0)},[le,D]),r.useEffect(()=>{if(!le||!Je.current)return;const a=Je.current.querySelector(`[data-skill-idx="${Xe}"]`);a&&a.scrollIntoView({block:"nearest"})},[Xe,le]),r.useEffect(()=>{if(!le)return;const a=f=>{Je.current?.contains(f.target)||Me.current?.contains(f.target)||De(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[le]),r.useEffect(()=>{if(L==="closed")return;const a=f=>{const m=f.target;de.current?.contains(m)||document.getElementById("cascade-portal")?.contains(m)||(te("closed"),ie(null),Te(null),Ee(null))};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[L]),r.useLayoutEffect(()=>{if(L==="closed"||!de.current){Nt(null);return}const a=de.current.getBoundingClientRect();Nt({left:a.left,bottom:window.innerHeight-a.top+8})},[L]);const It=g&&g.length?g[0]:null;r.useEffect(()=>{W&&(It||b!==null&&b!=="queued")&&k(null)},[b,W,It]),r.useEffect(()=>{const a=Me.current;a&&(a.style.height="auto",a.style.height=Math.min(a.scrollHeight,200)+"px")},[D]);const ft=r.useCallback(a=>{const f=Array.from(a||[]).filter(m=>m.type.startsWith("image/"));f.length&&Be(m=>[...m,...f.map(un)])},[]),Lt=r.useCallback(()=>{Qe(null),Be(a=>(Gs(a),[]))},[]),Tt=r.useCallback(a=>{Be(f=>{const m=f.find(C=>C.id===a);return m&&URL.revokeObjectURL(m.previewUrl),f.filter(C=>C.id!==a)}),Qe(f=>f===a?null:f)},[]),Et=r.useCallback(()=>{const a=D.trim(),f=ee.map(X=>X.file);if(!a&&f.length===0||E)return;const m=fe||n.agent||K.find(X=>X.isDefault)?.agent||"";if(!m)return;const C=K.find(X=>X.agent===m)||null,F=!!n.agent&&m===n.agent,xe=(Ge||F&&n.model||""||C?.selectedModel||"").trim()||null,Ke=J!==void 0?J:F&&n.model?n.profileId??null:void 0,rt=m==="gemini"?null:(We||(F?Pt(m,n.thinkingEffort,n.workflowEnabled):"")||Pt(m,C?.selectedEffort,C?.workflowEnabled)||"").trim()||null,ne=m!==n.agent,ln=ne?"":n.sessionId,fs=ne&&n.agent?n.agent:null,gs=ne&&n.sessionId?n.sessionId:null;z(!0),G.current={prompt:a,files:f},V(""),wt.delete(tt.current);const ms=f.length?f.map(X=>URL.createObjectURL(X)):void 0;Lt(),i(a,ms),l(),se.sendSessionMessage(s,m,ln,a,{attachments:f,model:xe,profileId:Ke,effort:rt,previousAgent:fs,previousSessionId:gs}).then(X=>{if(X.taskId&&(k(X.taskId),c?.(X.taskId)),!X.ok)return;const jt=typeof X.sessionKey=="string"?Xs(X.sessionKey):null;jt&&(jt.agent!==n.agent||jt.sessionId!==n.sessionId)&&jt&&x?.({...jt,workdir:s})}).catch(()=>{}).finally(()=>z(!1))},[K,Lt,ee,D,i,c,x,l,fe,We,Ge,J,E,n.agent,n.sessionId,n.model,n.profileId,s]),gt=b==="streaming",he=Fs({queuedTaskIds:g,streamPhase:b,streamTaskId:v,localTaskId:W}),Mt=he[he.length-1]||null,mt=he.length>0,Zt=mt||gt;r.useEffect(()=>{const a=f=>he.includes(f)||f===v;_(f=>{let m=!1;const C=new Set;for(const F of f)a(F)?C.add(F):m=!0;return m?C:f}),oe(f=>{let m=!1;const C=new Set;for(const F of f)a(F)?C.add(F):m=!0;return m?C:f})},[he,v]),r.useEffect(()=>{!mt&&G.current.files.length&&(G.current={prompt:"",files:[]})},[mt]);const Jt=r.useCallback(a=>{if(!Q.has(a)){if(_(f=>{const m=new Set(f);return m.add(a),m}),a===Mt){const f=G.current;f.prompt&&V(f.prompt),f.files.length&&Be(f.files.map(un)),G.current={prompt:"",files:[]}}N?.(a),a===W&&k(null)}},[Q,Mt,W,N]),[o,h]=r.useState(!1),u=r.useCallback(async()=>{if(!(o||!M)){h(!0);try{await M()}finally{h(!1)}}},[o,M]),p=r.useCallback(a=>{ae.has(a)||(oe(f=>{const m=new Set(f);return m.add(a),m}),$?.(a),a===W&&k(null))},[ae,W,$]),j=r.useCallback(a=>{V(`/${a.name} `),De(!1),requestAnimationFrame(()=>{const f=Me.current;f&&(f.focus(),f.setSelectionRange(f.value.length,f.value.length))})},[]),y=r.useCallback(a=>{V(a);const f=/^\/\S*$/.test(a)&&ve.length>0;De(f)},[ve.length]),I=a=>{if(le&&ye.length>0){if(a.key==="ArrowDown"){a.preventDefault(),Ze(f=>(f+1)%ye.length);return}if(a.key==="ArrowUp"){a.preventDefault(),Ze(f=>(f-1+ye.length)%ye.length);return}if(a.key==="Tab"||a.key==="Enter"&&!a.shiftKey&&!Ye.current){a.preventDefault(),j(ye[Xe]);return}if(a.key==="Escape"){a.preventDefault(),De(!1);return}}a.key==="Enter"&&!a.shiftKey&&!Ye.current&&(a.preventDefault(),Et())},q=r.useCallback(a=>{const f=Array.from(a.clipboardData?.items||[]).filter(m=>m.kind==="file"&&m.type.startsWith("image/")).map(m=>m.getAsFile()).filter(m=>!!m);f.length&&(a.preventDefault(),ft(f))},[ft]),A=fe||n.agent||K.find(a=>a.isDefault)?.agent||K.find(a=>a.installed)?.agent||K[0]?.agent||"",B=K.find(a=>a.agent===A)||null,O=ce||A,Ne=K.find(a=>a.agent===O)||B,bt=r.useMemo(()=>{if(!Ne)return[];const a=[];for(const m of Ne.models||[])a.push({id:m.id,label:m.id,kind:"native",description:m.alias&&m.alias.toLowerCase()!==m.id.toLowerCase()?m.alias:void 0});const f=new Set(bs[O]||[]);for(const m of je){const C=Fe.find(xe=>xe.id===m.providerId);if(!C||!f.has(C.kind))continue;const F=m.name.trim().toLowerCase()!==m.modelId.trim().toLowerCase();a.push({id:m.modelId,label:m.name,kind:"profile",profileId:m.id,description:F?`${C.name} · ${m.modelId}`:C.name})}return a},[Ne,O,je,Fe]),ls=r.useMemo(()=>bt.findIndex(a=>a.kind==="profile"),[bt]),as=ht[O]||null,en=!!n.agent&&A===n.agent,At=J!==void 0?J:en?n.profileId??null:void 0,vt=Ge||en&&n.model||""||B?.selectedModel||"",Rt=A==="gemini"?"":We||(en?Pt(A,n.thinkingEffort,n.workflowEnabled):"")||Pt(A,B?.selectedEffort,B?.workflowEnabled)||"";r.useEffect(()=>{U?.({model:vt||null,effort:Rt||null})},[vt,Rt,U]);const cs=an[O]||[],Ue=ge&&ee.find(a=>a.id===ge)||null,ds=Ue?{key:Ue.id,url:Ue.previewUrl,name:Ue.file.name,size:Ue.file.size,file:Ue.file,onRemove:()=>Tt(Ue.id)}:Le?{key:Le,url:Le}:null,Sn=(!!D.trim()||ee.length>0)&&!E&&!!A,tn=()=>{ie(null),Te(null),Ee(null),me(void 0)},nn=r.useCallback((a,f,m)=>{const C=a==="gemini"?"":m||"";ct(a),qe(f),re!==void 0&&_e(re),dt(C),tn(),te("closed")},[re]),us=()=>{L==="closed"?(tn(),Ae(),ue(),te("agent")):(tn(),te("closed"))},sn=ce||A,Cn=pn(sn),rn=$e??vt,nt=ut??Rt,hs=rn?Ht(rn):"",ze=(()=>{const a=!ce&&At!==void 0?At:ht[sn]??null;return a?je.find(f=>f.id===a)??null:null})(),st=ze?Fe.find(a=>a.id===ze.providerId)??null:null,xs=st?Js(st):null,on=ze?ze.name.trim().toLowerCase()!==ze.modelId.trim().toLowerCase()?ze.name:Ht(ze.modelId):hs,ps=[Cn.shortLabel,st?st.name:null,on||null,nt?nt.charAt(0).toUpperCase()+nt.slice(1):null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:Xt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[Zt&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[gt&&e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-primary/20 bg-primary/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx(pe,{className:"h-3 w-3 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-[12px] font-medium text-fg-3 truncate",children:d("hub.running")}),e.jsxs("button",{onClick:u,disabled:o,title:d("hub.stopHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none shrink-0",children:[o?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),d("hub.stop")]})]}),he.map((a,f)=>{const m=f===he.length-1,C=ae.has(a),F=C?d("hub.steering"):he.length>1?`${d("hub.queued")} #${f+1}`:d("hub.queued"),xe=S?.find(ne=>ne.taskId===a)||(m?S?.find(ne=>!ne.taskId):void 0),Ke=w?.find(ne=>ne.taskId===a)?.prompt||xe?.prompt||null,rt=xe?.imageUrls?.length?xe.imageUrls:[];return e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-warn/25 bg-warn/[0.04] px-3.5 py-1.5 transition-colors",children:[C?e.jsx(pe,{className:"h-3 w-3 text-warn shrink-0"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-warn animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-warn shrink-0",children:F}),rt.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[rt.slice(0,3).map((ne,ln)=>e.jsx("button",{type:"button",onClick:()=>yt(ne),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:ne,alt:"",className:"h-full w-full object-cover"})},`${ne}-${ln}`)),rt.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",rt.length-3]})]}),Ke&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:Ke})]}),!C&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>p(a),title:d("hub.steerHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-blue-400 hover:bg-blue-400/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),d("hub.steer")]}),e.jsxs("button",{onClick:()=>Jt(a),disabled:Q.has(a),title:d("hub.recallHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[Q.has(a)?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]}),d("hub.recall")]})]})]},a)})]}),e.jsxs("div",{className:"relative rounded-xl border border-edge/40 bg-panel shadow-sm transition-[border-color,box-shadow] duration-200 focus-within:border-fg-5/40 focus-within:shadow-md",children:[e.jsx("input",{ref:Oe,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:a=>{ft(a.target.files),a.target.value=""}}),ee.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:ee.map(a=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>Qe(a.id),title:d("hub.previewImage"),className:"group relative h-[72px] w-[72px] overflow-hidden rounded-lg border border-edge/30 bg-panel-alt/30",children:[e.jsx("img",{src:a.previewUrl,alt:a.file.name,className:"h-full w-full object-cover transition-transform duration-200 group-hover:scale-[1.03]"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent px-1.5 pb-1 pt-3 text-left",children:e.jsx("div",{className:"truncate text-[8px] font-medium text-white/90 leading-tight",children:a.file.name})})]}),e.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),Tt(a.id)},title:d("hub.removeImage"),className:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-black/65 text-white/75 transition-colors hover:bg-black/80 hover:text-white",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]},a.id))})}),le&&ye.length>0&&e.jsxs("div",{ref:Je,className:"absolute bottom-full left-0 right-0 mb-1.5 z-50 max-h-[200px] overflow-y-auto rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg animate-in",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-edge/20",children:e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d("hub.skills")})}),e.jsx("div",{className:"py-1",children:ye.map((a,f)=>e.jsxs("button",{"data-skill-idx":f,onMouseDown:m=>{m.preventDefault(),j(a)},onMouseEnter:()=>Ze(f),className:T("flex flex-col w-full px-3 py-1.5 text-left transition-colors",f===Xe?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",a.name]}),(a.label||a.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:a.label||a.description})]},a.name))})]}),e.jsx("textarea",{ref:Me,value:D,onChange:a=>y(a.target.value),onPaste:q,onKeyDown:I,onCompositionStart:()=>{Ye.current=!0},onCompositionEnd:()=>{Ye.current=!1},placeholder:d("hub.inputPlaceholder"),rows:1,className:"w-full resize-none bg-transparent px-4 pt-3 pb-1 text-[13.5px] text-fg outline-none placeholder:text-fg-5/25 leading-[1.6]",style:{maxHeight:200,overflow:D.split(`
|
|
9
|
+
`).length>6?"auto":"hidden"}}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>Oe.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:de,onClick:us,disabled:!K.length,title:K.length?ps:void 0,className:T("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",L!=="closed"?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[K.length?e.jsx(it,{brand:sn,size:12}):e.jsx(pe,{className:"h-3 w-3"}),K.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}),st&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(it,{brand:xs||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:st.name})]}),on&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:rn||void 0,children:on})]}),nt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"shrink-0",children:nt.charAt(0).toUpperCase()+nt.slice(1)})]})]}):e.jsx("span",{className:"max-w-[420px] truncate",children:d("hub.selectAgent")}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:T("text-fg-5/30 transition-transform duration-200",L!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),L!=="closed"&&Y&&vn.createPortal(e.jsxs("div",{id:"cascade-portal",className:"fixed z-[200] w-[300px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in",style:{left:Y.left,bottom:Y.bottom},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5 border-b border-edge/20",children:[L!=="agent"&&e.jsx("button",{onClick:()=>{if(L==="effort"){const a=Ne?.capabilities?.modelSwitch!==!1;te(a?"model":"agent")}else te("agent")},className:"p-0.5 rounded text-fg-5/50 hover:text-fg-3 transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d(L==="agent"?"hub.selectAgent":L==="model"?"hub.selectModel":"hub.selectEffort")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const f=Ne?.capabilities?.modelSwitch!==!1?["agent","model","effort"]:["agent","effort"],m=f.indexOf(L);return f.map((C,F)=>e.jsx("span",{className:T("w-1.5 h-1.5 rounded-full transition-colors",L===C?"bg-primary":F<m?"bg-primary/40":"bg-fg-5/15")},C))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[L==="agent"&&K.filter(a=>a.installed).map(a=>{const f=pn(a.agent),m=vs(a.usage),C=m?js(m):"ok";return e.jsxs(hn,{selected:a.agent===(ce||A),onClick:()=>{if(ie(a.agent),Te(a.selectedModel||""),Ee(a.selectedEffort||""),!(a.capabilities?.modelSwitch!==!1)){(an[a.agent]||[]).length?te("effort"):nn(a.agent,a.selectedModel||"",null);return}te("model")},children:[e.jsx(it,{brand:a.agent,size:14}),e.jsx("span",{style:{color:f.color},children:f.label}),m&&e.jsxs("span",{className:T("ml-auto font-mono text-[10px]",C==="err"?"text-err":C==="warn"?"text-warn":"text-fg-5"),children:[m.label," ",Math.round(m.usedPercent??0),"%"]})]},a.agent)}),L==="model"&&e.jsxs(e.Fragment,{children:[bt.map((a,f)=>{const m=f===0&&a.kind==="native",C=f===ls&&a.kind==="profile",F=re!==void 0?re:O===A&&At!==void 0?At:as,xe=a.kind==="profile"?!!a.profileId&&a.profileId===F:!F&&a.id===($e??vt);return e.jsxs("div",{children:[m&&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")}),C&&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(hn,{selected:xe,onClick:()=>{const Ke=ce||A;if(Te(a.id),me(a.profileId??null),an[Ke]?.length){te("effort");return}nn(Ke,a.id,null)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:T("truncate text-[11.5px]",a.kind==="native"&&"font-mono text-[11px]"),title:a.id,children:a.label}),a.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:a.description})]})})]},`${a.kind}:${a.profileId||a.id}`)}),bt.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]}),L==="effort"&&cs.map(a=>e.jsx(hn,{selected:a===(ut||Rt),onClick:()=>{Ee(a),nn(ce||A,$e??vt,a)},children:a.charAt(0).toUpperCase()+a.slice(1)},a))]})]}),document.body),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:Et,disabled:!Sn,className:T("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",Sn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:E?e.jsx(pe,{className:"h-3.5 w-3.5"}):e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})]}),e.jsx(tr,{source:ds,onClose:()=>{Qe(null),yt(null)},t:d})]})});function tr({source:t,onClose:n,t:s}){const[l,i]=r.useState(!1);if(r.useEffect(()=>{i(!1)},[t?.key]),r.useEffect(()=>{if(!t)return;const d=b=>{b.key==="Escape"&&n()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[t,n]),!t)return null;const c=t.file,x=t.onRemove;return vn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center bg-black/72 px-4 py-6 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[1024px]",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-[11px] text-white/72",children:[t.name&&e.jsx("span",{className:"truncate font-medium text-white/90",children:t.name}),typeof t.size=="number"&&e.jsx("span",{children:Kn(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await qs(c)&&(i(!0),window.setTimeout(()=>i(!1),1600))},className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s(l?"hub.copied":"hub.copyImage")}),x&&e.jsx("button",{type:"button",onClick:x,className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s("hub.removeImage")}),e.jsx("button",{type:"button",onClick:n,className:"flex h-9 w-9 items-center justify-center rounded-full border border-white/12 bg-white/10 text-white/88 transition-colors hover:bg-white/14",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-white/10 bg-black/35 shadow-[0_20px_70px_rgba(0,0,0,0.45)]",children:e.jsx("img",{src:t.url,alt:t.name||"",className:"max-h-[80vh] w-full object-contain"})})]})}),document.body)}function hn({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:T("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 nr(){return function(t){Es(t)}}const kn=[Ms,nr],Vn=t=>/^https?:\/\//.test(t),sr=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function rr(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function Gn(t){let n=t.trim();const s=[["`","`"],['"','"'],["'","'"],["<",">"]];let l=!0;for(;l&&n.length>=2;){l=!1;for(const[i,c]of s)n.startsWith(i)&&n.endsWith(c)&&(n=n.slice(i.length,-c.length).trim(),l=!0)}return n}function yn(t){let n=Gn(t),s="";for(;n.length>1;){const l=n[n.length-1];if(!l||!/[),.;!?]/.test(l)||l==="."&&/^\.[A-Za-z0-9_-]+$/.test(n))break;s=l+s,n=n.slice(0,-1)}return{text:n,trailing:s}}function qt(t){const n=yn(t).text;if(!n||Vn(n)||sr(n)&&!n.startsWith("file://"))return!1;const s=rr(n);if(!s)return!1;if(s.startsWith("file://"))return s.length>7;if(/^[A-Za-z]:[\\/]/.test(s))return!0;if(/^(\/|~\/|\.{1,2}\/)/.test(s))return s.length>1;if(s.includes("/")){const l=s.split("/")[0]||"";return!/^[A-Za-z0-9-]+\.[A-Za-z]{2,}$/.test(l)}return!1}function Nn(t,n){se.openInEditor(t,void 0,n||void 0).catch(()=>{})}function qn(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),t.stopPropagation(),Nn(n,s))}const or="text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",ir="underline decoration-dotted decoration-fg-5/40 underline-offset-2 cursor-pointer hover:text-blue-300 hover:decoration-blue-300/50 transition-colors";function Qn({locator:t,workdir:n,className:s,children:l}){return e.jsx("span",{role:"link",tabIndex:0,title:t,className:s??or,onClick:i=>{i.stopPropagation(),Nn(t,n)},onKeyDown:i=>qn(i,t,n),children:l??t})}function lr(t){const n=[];if(!t)return n;for(const s of t.split(/(\s+)/)){if(!s)continue;if(/^\s+$/.test(s)){n.push({type:"text",value:s});continue}const{text:l,trailing:i}=yn(s),c=Gn(l);c&&!c.endsWith("…")&&qt(c)?(n.push({type:"link",locator:c,display:i?s.slice(0,s.length-i.length):s}),i&&n.push({type:"text",value:i})):n.push({type:"text",value:s})}return n}function Pe({text:t,workdir:n,className:s}){const l=lr(t);return l.some(i=>i.type==="link")?e.jsx(e.Fragment,{children:l.map((i,c)=>i.type==="link"?e.jsx(Qn,{locator:i.locator,workdir:n,className:s??ir,children:i.display},c):e.jsx("span",{children:i.value},c))}):e.jsx(e.Fragment,{children:t})}function ar({text:t}){const[n,s]=r.useState(!1),l=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:l,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function En(t){const n=qt(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 Yt(t={}){const n=t.workdir||null;return{h1:({children:s})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:s}),h2:({children:s})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:s}),h3:({children:s})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:s}),p:({children:s})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:s}),strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-fg",children:s}),em:({children:s})=>e.jsx("em",{className:"italic text-fg-3",children:s}),a:({href:s,children:l})=>s&&Vn(s)?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",children:l}):s&&qt(s)?e.jsx(Qn,{locator:yn(s).text,workdir:n,children:l}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:l}),ul:({children:s})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:s}),ol:({children:s})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:s}),li:({children:s})=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"shrink-0 mt-[10px] w-[5px] h-[5px] rounded-full bg-fg-5/40"}),e.jsx("span",{className:"flex-1",children:s})]}),blockquote:({children:s})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:s}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:s,children:l})=>{const i=String(l).replace(/\n$/,""),c=/language-(\w+)/.exec(s||"");if(!c&&!s&&!i.includes(`
|
|
10
|
+
`))return qt(i)?e.jsx("code",{role:"link",tabIndex:0,title:i,className:T("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",En(i)),onClick:()=>Nn(i,n),onKeyDown:d=>qn(d,i,n),children:i}):e.jsx("code",{className:T("px-1.5 py-[1px] rounded text-[12px] font-mono border",En(i)),children:i});const x=c?.[1]||"";return e.jsxs("div",{className:"rounded-lg overflow-hidden border border-edge/30 bg-[rgba(0,0,0,0.25)] my-3 not-prose",children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-1.5 border-b border-edge/15 bg-[rgba(0,0,0,0.12)]",children:[e.jsx("span",{className:"text-[10px] font-mono text-fg-5/50",children:x||"text"}),e.jsx(ar,{text:i})]}),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:i})})]})},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})}}Yt();function at(t){return!!t?.steps?.length}function cr(t,n){let s=t;for(const[l,i]of Object.entries(n))s=s.replace(new RegExp(`\\{${l}\\}`,"g"),i);return s}function dr({status:t}){return t==="completed"?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):t==="inProgress"?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-400 animate-pulse"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/25"})}function Yn({plan:t,t:n,className:s}){const[l,i]=r.useState(!1);if(!at(t))return null;const c=t.steps.length,x=t.steps.filter(v=>v.status==="completed").length,d=c>0&&x===c,b=cr(n("hub.planProgress"),{done:String(x),total:String(c)});return e.jsx(lt,{open:l,onToggle:()=>i(v=>!v),dot:{color:d?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!d},label:b,preview:t.explanation?e.jsx("span",{className:"text-[11.5px] text-fg-4 truncate",children:t.explanation}):void 0,badge:e.jsx("span",{className:T("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 w=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(dr,{status:v.status})}),e.jsx("span",{className:T("text-[12px] leading-[1.5]",w),children:v.step})]},`${g}:${v.step}`)})})})}function Xn({url:t,fileName:n,fileSize:s,caption:l}){return e.jsxs("div",{className:"flex flex-col gap-1 max-w-[340px]",children:[e.jsxs("a",{href:t,download:n,target:"_blank",rel:"noreferrer",title:l||n,className:T("group inline-flex items-center gap-2.5 rounded-md no-underline","border border-fg-6/40 bg-fg-6/[0.05] px-3 py-2","hover:bg-fg-6/[0.12] hover:border-fg-6/60 transition-colors"),children:[e.jsx("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded bg-fg-6/10 text-fg-3",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12.5px] font-medium text-fg-2",children:n}),typeof s=="number"&&s>0&&e.jsx("span",{className:"block text-[11px] text-fg-5/70",children:Kn(s)})]}),e.jsx("span",{className:"shrink-0 text-fg-5/50 group-hover:text-fg-3 transition-colors",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),l&&e.jsx("span",{className:"px-0.5 text-[11.5px] leading-[1.55] text-fg-4 break-words",children:l})]})}function Zn(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
|
|
11
|
+
`).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||at(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function vo(t){return Zn(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function ur(t){return t.phase!=="done"||!t.error?null:Zn(t)?"hub.streamErrored":"hub.streamFailed"}function hr({detail:t,t:n,className:s}){const l=Vs(t);if(l==="interrupted")return e.jsxs("div",{className:T("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 i=l==="error"?{dot:"bg-rose-400/55",text:"text-rose-300/65"}:{dot:"bg-fg-5/40",text:"text-fg-5/55"};return e.jsxs("div",{className:T("flex items-start gap-1.5 text-[11px] leading-[1.6]",i.text,s),children:[e.jsx("span",{className:T("mt-[5px] h-1 w-1 rounded-full shrink-0",i.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const xr=64,pr=6;function fr(t,n){const[s,l]=r.useState(t),i=r.useRef(0),c=r.useRef(null);return r.useEffect(()=>{if(n<=0)return;const x=Date.now()-i.current,d=()=>{i.current=Date.now(),l(t)};return x>=n?d():(c.current&&clearTimeout(c.current),c.current=window.setTimeout(d,n-x)),()=>{c.current&&clearTimeout(c.current)}},[t,n]),n<=0?t:s}function jo({stream:t,t:n,workdir:s}){const l=at(t.plan),[i,c]=r.useState(!1),[x,d]=r.useState(!1),b=r.useRef(null),v=r.useRef(null),g=ur(t),w=r.useMemo(()=>(t.activity||"").split(`
|
|
12
|
+
`).filter(Boolean),[t.activity]),S=t.previewMeta?.toolCalls??[],N=w[w.length-1]||S[S.length-1]?.summary||"",$=r.useMemo(()=>[t.text.length,t.thinking.length,S.length,S[S.length-1]?.status??"",(t.activity??"").length,t.generatingImages??0].join("|"),[t.text,t.thinking,S,t.activity,t.generatingImages]),M=r.useRef(Date.now()),[R,P]=r.useState(0);r.useEffect(()=>{M.current=Date.now(),P(0)},[$]),r.useEffect(()=>{if(t.phase!=="streaming"){P(0);return}const k=window.setInterval(()=>{P(Math.floor((Date.now()-M.current)/1e3))},1e3);return()=>window.clearInterval(k)},[t.phase]);const U=S.find(k=>k.status==="running")??null,D=t.phase==="streaming"&&R>=pr&&(t.generatingImages??0)===0;r.useLayoutEffect(()=>{const k=b.current;k&&i&&(k.scrollTop=k.scrollHeight)},[i,t.activity,S.length]),r.useLayoutEffect(()=>{const k=v.current;k&&x&&(k.scrollTop=k.scrollHeight)},[x,t.thinking]);const V=t.subAgents??null,E=fr(t.text,t.phase==="streaming"?xr:0),z=r.useMemo(()=>Yt({workdir:s}),[s]),W=r.useMemo(()=>e.jsx(jn,{remarkPlugins:kn,components:z,children:E}),[E,z]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[l&&e.jsx(Yn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),V&&V.length>0&&V.map(k=>e.jsx(Jn,{sub:k,t:n},k.id)),(S.length>0||w.length>0)&&e.jsx(lt,{open:i,onToggle:()=>c(k=>!k),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(Pe,{text:N,workdir:s})}),badge:(S.length||w.length)>1?e.jsx(bn,{children:S.length||w.length}):void 0,children:e.jsx("div",{ref:b,className:"px-3.5 py-2.5 space-y-0.5 max-h-[280px] overflow-y-auto",children:S.length>0?S.map(k=>e.jsx(gr,{call:k,workdir:s},k.id)):w.map((k,Q)=>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(Pe,{text:k,workdir:s})})]},Q))})}),t.thinking&&e.jsx(lt,{open:x,onToggle:()=>d(k=>!k),dot:{color:"bg-violet-400/50",pulse:!0},label:n("hub.thinking"),collapsedContent:e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:zn(t.thinking,3)}),children:e.jsx("div",{ref:v,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[280px] overflow-y-auto",children:t.thinking})}),t.text&&e.jsxs("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:[W,t.phase==="streaming"&&e.jsx(zt,{className:"ml-1 inline-flex align-text-bottom text-fg-4"})]}),t.artifacts&&t.artifacts.length>0&&e.jsx("div",{className:"flex flex-col gap-2",children:t.artifacts.map((k,Q)=>k.kind==="photo"?e.jsx("a",{href:k.url,target:"_blank",rel:"noreferrer",className:"inline-block",children:e.jsx("img",{src:k.url,alt:k.caption||k.fileName,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain hover:opacity-90 transition-opacity"})},Q):e.jsx(Xn,{url:k.url,fileName:k.fileName,fileSize:k.fileSize,caption:k.caption},Q))}),!t.text&&t.phase==="streaming"&&!D&&e.jsx("div",{className:"py-1",children:e.jsx(zt,{className:"text-fg-5"})}),t.phase==="streaming"&&(t.generatingImages??0)>0&&e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-fg-4",children:[e.jsxs("span",{className:"relative inline-flex items-center justify-center w-3 h-3",children:[e.jsx("span",{className:"absolute inline-flex w-3 h-3 rounded-full bg-cyan-400/40 animate-ping"}),e.jsx("span",{className:"relative inline-block w-1.5 h-1.5 rounded-full bg-cyan-400/80"})]}),e.jsx("span",{children:t.generatingImages===1?"Generating image…":`Generating ${t.generatingImages} images…`})]}),D&&e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-fg-5/55",children:[e.jsx(zt,{className:"text-fg-5/50 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:U?`${n("hub.stillRunning")||"still running"}: ${U.summary}`:n("hub.stillWorking")||"still working…"}),e.jsxs("span",{className:"shrink-0 tabular-nums text-fg-5/45",children:[R,"s"]})]}),g&&t.error&&e.jsx(hr,{detail:t.error,t:n,className:"pt-0.5"})]})}function gr({call:t,workdir:n}){const[s,l]=r.useState(!1),i=!!(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:()=>i&&l(x=>!x),className:`flex w-full items-center gap-1.5 py-[2px] text-left min-w-0 ${i?"cursor-pointer hover:bg-white/[0.03] rounded":"cursor-default"}`,title:i?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(Pe,{text:t.summary,workdir:n})}),i&&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(Pe,{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(Pe,{text:t.result,workdir:n})})]})]})}function zt({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 Jn({sub:t,t:n}){const[s,l]=r.useState(!1),i=t.status,c=i==="failed"?"bg-rose-400/60":i==="done"?"bg-emerald-400/55":"bg-amber-400/60",x=i==="running",d=t.tools,b=r.useMemo(()=>{const w=new Set,S=[];for(const N of d)w.has(N.name)||(w.add(N.name),S.push(N.name));return S},[d]),v=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",g=t.model?Ht(t.model):null;return e.jsx(lt,{open:s,onToggle:()=>l(w=>!w),dot:{color:c,pulse:x},label:v,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),g&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:g}),!t.description&&b.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:b.join(" · ")})]}),badge:d.length>0?e.jsx(bn,{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(w=>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:w.summary})]},w.id))]})})}function mr({message:t,t:n,workdir:s}){const{activityBlocks:l,thinkingBlocks:i,planBlocks:c,subAgentBlocks:x,outputBlocks:d,noticeBlocks:b}=es(t.blocks),v=[...c].reverse().find(w=>at(w.plan));return l.length>0||x.length>0||!!v?.plan||i.length>0||d.length>0||b.length>0?e.jsxs("div",{className:"space-y-3",children:[l.length>0&&e.jsx(jr,{blocks:l,t:n,workdir:s}),x.map(w=>w.subAgent?e.jsx(Jn,{sub:w.subAgent,t:n},w.toolId||w.subAgent.id):null),v?.plan&&e.jsx(Yn,{plan:v.plan,t:n,className:"max-w-[760px]"}),i.length>0&&e.jsx(kr,{blocks:i,t:n}),d.length>0&&e.jsx(Sr,{blocks:d,t:n,workdir:s}),b.length>0&&e.jsx(vr,{blocks:b,t:n})]}):null}function br(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:l,subAgentBlocks:i,outputBlocks:c,noticeBlocks:x}=es(t.blocks);return c.length>0||n.length>0||i.length>0||s.length>0||l.some(d=>at(d.plan))||x.length>0}function es(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"&&at(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 vr({blocks:t,t:n}){const s=t.map(l=>l.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 jr({blocks:t,t:n,workdir:s}){const[l,i]=r.useState(!1),c=t.filter(v=>v.type==="tool_use"),x=c.length,d=c[c.length-1],b=d?Hn(d):"";return e.jsx(lt,{open:l,onToggle:()=>i(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(Pe,{text:b,workdir:s})}),badge:x>0?e.jsx(bn,{children:x}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((v,g)=>e.jsx(wr,{block:v,workdir:s},g))})})}function wr({block:t,workdir:n}){const[s,l]=r.useState(!1),i=t.type==="tool_use",c=i?Hn(t):Ys(t),x=t.content.length>3e3?t.content.slice(0,3e3)+`
|
|
15
|
+
…`:t.content;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&l(d=>!d),className:T("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:T("h-1.5 w-1.5 rounded-full shrink-0",i?"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(Pe,{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(Pe,{text:x,workdir:n})})]})}function kr({blocks:t,t:n}){const[s,l]=r.useState(!1),i=r.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
|
|
16
|
+
|
|
17
|
+
`).trim();if(!c)return null;const x=zn(c,3);return e.jsx(lt,{open:s,onToggle:()=>l(d=>!d),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:x?e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:x}):void 0,children:e.jsx(yr,{scrollRef:i,text:c})})}function yr({scrollRef:t,text:n}){return r.useLayoutEffect(()=>{const s=t.current;s&&(s.scrollTop=s.scrollHeight)},[t]),e.jsx("div",{ref:t,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[320px] overflow-y-auto",children:n})}function Nr({block:t,onLightbox:n,t:s}){const l=t.imageCaption?.trim()||"",i=t.imageCaptionKind==="prompt",[c,x]=r.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:l||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),l&&(i?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>x(d=>!d),"aria-expanded":c,className:T("self-start inline-flex items-center gap-1 px-2 py-[3px] rounded-md","text-[11px] font-medium tracking-wide","border border-fg-6/40 bg-fg-6/[0.06] text-fg-3","hover:bg-fg-6/[0.12] hover:text-fg-2 hover:border-fg-6/60","transition-colors"),title:s(c?"hub.imagePromptHide":"hub.imagePromptShow"),children:[e.jsx("span",{"aria-hidden":!0,className:"text-[9px] leading-none",children:c?"▾":"▸"}),e.jsx("span",{children:s("hub.imagePrompt")})]}),c&&e.jsx("div",{className:"rounded-md border border-fg-6/30 bg-fg-6/[0.05] px-3 py-2 max-w-[400px] max-h-[260px] overflow-y-auto",children:e.jsx("div",{className:"text-[11.5px] leading-[1.65] text-fg-3 whitespace-pre-wrap break-words",children:l})})]}):e.jsx("figcaption",{className:"text-[11px] leading-[1.55] text-fg-5 max-w-[400px] break-words whitespace-pre-wrap",children:l}))]})}function Sr({blocks:t,t:n,workdir:s}){const l=t.filter(g=>g.type==="text"),i=t.filter(g=>g.type==="image"),c=t.filter(g=>g.type==="file"),x=l.map(g=>g.content).filter(Boolean).join(`
|
|
18
|
+
|
|
19
|
+
`),[d,b]=r.useState(null),v=r.useMemo(()=>Yt({workdir:s}),[s]);return!x.trim()&&i.length===0&&c.length===0?null:e.jsxs(e.Fragment,{children:[x.trim()&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:e.jsx(jn,{remarkPlugins:kn,components:v,children:x})}),i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:i.map((g,w)=>e.jsx(Nr,{block:g,onLightbox:b,t:n},w))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((g,w)=>e.jsx(Xn,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},w))}),d&&e.jsx(ts,{src:d,onClose:()=>b(null)})]})}const wo=r.memo(function({turn:n,turnIndex:s,agent:l,meta:i,model:c,effort:x,providerName:d,t:b,workdir:v,onResend:g,onEdit:w,onFork:S}){const N=n.user&&Un(n.user.text),$=S&&typeof s=="number"?()=>S(s):void 0,M=r.useMemo(()=>Yt({workdir:v}),[v]),R=!!n.assistant&&br(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!N&&e.jsx(ns,{text:n.user.text,blocks:n.user.blocks,t:b,onResend:g,onEdit:w,onFork:$}),N&&n.user&&!n.assistant&&e.jsx("div",{className:"mb-4 px-4 py-3 rounded-lg bg-[rgba(255,255,255,0.02)] border border-edge/20 text-[12.5px] leading-[1.7] text-fg-4",children:e.jsx(jn,{remarkPlugins:kn,components:M,children:n.user.text})}),R&&e.jsxs(e.Fragment,{children:[e.jsx(Tr,{agent:l,meta:i,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(mr,{message:n.assistant,t:b,workdir:v})})]})]})});function ts({src:t,onClose:n}){return r.useEffect(()=>{const s=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),vn.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 Cr=1500,Ir=16,Mn=8;function Lr(t){const n=t.split(`
|
|
20
|
+
`);return n.length<=Mn?t:n.slice(0,Mn).join(`
|
|
21
|
+
`)}function ns({text:t,blocks:n,t:s,onResend:l,onEdit:i,onFork:c}){const[x,d]=r.useState(!1),[b,v]=r.useState(!1),[g,w]=r.useState(null),S=t?t.split(`
|
|
22
|
+
`).length:0,N=!!t&&(t.length>Cr||S>Ir),[$,M]=r.useState(!1),R=t?N&&!$?Lr(t):t:"",P=!!(l||i||c),U=n?.filter(E=>E.type==="image")||[],D=()=>{navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),1500)}).catch(()=>{})},V=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(S));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:[R,N&&!$&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),N&&e.jsx("button",{type:"button",onClick:()=>M(E=>!E),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:$?s("hub.collapse"):V}),U.length>0&&e.jsx("div",{className:T("flex flex-wrap gap-2",t&&"mt-2"),children:U.map((E,z)=>e.jsx("img",{src:E.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>w(E.content)},z))})]}),g&&e.jsx(ts,{src:g,onClose:()=>w(null)}),P&&e.jsxs("div",{className:T("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(Wt,{label:s(b?"hub.copied":"hub.copy"),onClick:D,children:b?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),l&&e.jsx(Wt,{label:s("hub.rerun"),onClick:()=>l(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),i&&e.jsx(Wt,{label:s("hub.edit"),onClick:()=>i(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(Wt,{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 Wt({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 Tr({agent:t,meta:n,model:s,effort:l,providerName:i,previewMeta:c,liveStartedAt:x}){const d=c?.contextPercent??null,b=c?.contextUsedTokens??0,v=c?.turnOutputTokens??0,g=d!=null||b>0||v>0,w=x!=null&&x>0,S=c?.providerName??i??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(it,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||l)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&l?" · ":"",l||""]}),S&&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 ${S} (BYOK), not the agent CLI's native auth.`,children:["via ",S]}),(g||w)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:Rr(c),children:[d!=null&&e.jsx(Pr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),b>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",Ar(b)]}),v>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",ss(v)]}),w&&e.jsx(Er,{startedAt:x,leadingDot:g})]})]})}function Er({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const i=setInterval(()=>s(c=>c+1),1e3);return()=>clearInterval(i)},[]);const l=Math.max(0,Date.now()-t);return e.jsxs("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:[n?"· ":"",Mr(l)]})}function Mr(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),l=n%60;return s<60?`${s}m${l.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function Ar(t){return`${ss(t)} tok`}function ss(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function Rr(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 Pr({pct:t}){const n=t>=85?"bg-rose-400/70":t>=60?"bg-amber-400/70":"bg-emerald-400/70";return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${n}`})}function An(t,n,s){return t==="zh-CN"?n:s}function _r({open:t,onClose:n,workdir:s}){const l=Ce(c=>c.locale),i=s.split("/").pop()||s;return e.jsxs(Vt,{open:t,onClose:n,wide:!0,children:[e.jsx(Gt,{title:An(l,`${i} — 项目扩展`,`${i} — Project Extensions`),description:An(l,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(As,{workdir:s}):null]})}let Rn=Bn(()=>import("./SessionPanel-BKde6FwO.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function fn(){return Rn??=Bn(()=>import("./SessionPanel-BKde6FwO.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Rn}const Wr=r.lazy(async()=>({default:(await fn()).SessionPanel})),xn=5,Br=240,$r=120,Or=12,Dr=900*1e3,H=(t,n)=>`${t}:${n}`;function Fr(t){const n=new Map;for(const d of t)n.set(H(d.agent||"",d.sessionId),d);const s=new Map,l=new Set;for(const d of t){const b=d.migratedFrom;if(!b||b.kind!=="fork"||!b.sessionId)continue;const v=H(b.agent||d.agent||"",b.sessionId);n.has(v)&&(l.add(H(d.agent||"",d.sessionId)),s.has(v)||s.set(v,[]),s.get(v).push(d))}const i=[],c=new Set,x=(d,b)=>{const v=H(d.agent||"",d.sessionId);if(c.has(v))return;c.add(v),i.push(Object.assign({},d,{__forkDepth:b}));const g=s.get(v);if(g)for(const w of g)x(w,b+1)};for(const d of t){const b=H(d.agent||"",d.sessionId);l.has(b)||x(d,0)}for(const d of t)x(d,0);return i}let Ur=0;function Bt(){return`mk-${Date.now().toString(36)}-${(++Ur).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 zr=[1,2,3,6],gn=6;function Kr(t){for(const n of zr)if(n>=t)return n;return gn}function Pn(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function He(t,n){const s=Kr(t);return s>n?s:n}function Hr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Vr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function rs(t){switch(t){case"cursor":return"hub.openTargetCursor";case"windsurf":return"hub.openTargetWindsurf";case"finder":return"hub.openTargetFinder";case"default":return"hub.openTargetDefault";default:return"hub.openTargetVsCode"}}const Gr=r.memo(function({active:n=!0}){const s=Ce(o=>o.locale),l=Ce(o=>o.state?.runtimeWorkdir??null),i=r.useMemo(()=>ws(s),[s]),[c,x]=r.useState([]),[d,b]=r.useState({}),[v,g]=r.useState({}),[w,S]=r.useState(!0),[N,$]=r.useState(()=>{const o=$t("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Pn()}),[M,R]=r.useState(()=>{const o=$t("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Pn()}),[P,U]=r.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||Bt()}))}}catch{}return[]}),[D,V]=r.useState(()=>{const o=$t("pikiloom-active-slot");if(o!=null){const h=Number(o);if(Number.isFinite(h)&&h>=0)return h}return 0}),E=r.useCallback(o=>{$(o),Ot("pikiloom-layout-mode",String(o))},[]),z=r.useCallback(o=>{R(o),Ot("pikiloom-layout-floor",String(o))},[]),W=r.useCallback(o=>{U(h=>{const u=typeof o=="function"?o(h):o,p=u.map(({pendingPrompt:j,pendingImageUrls:y,...I})=>I);return Ot("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),k=r.useCallback(o=>{V(h=>{const u=typeof o=="function"?o(h):o;return Ot("pikiloom-active-slot",String(u)),u})},[]),Q=r.useCallback(o=>{E(o),z(o)},[E,z]);r.useEffect(()=>{W(o=>o.length>N?o.slice(0,N):o),k(o=>o>=N?N-1:o)},[N]);const[_,ae]=r.useState(!1),oe=r.useRef(N);oe.current=N;const G=r.useRef(M);G.current=M;const Ie=r.useRef(D);Ie.current=D;const K=r.useRef(P);K.current=P;const kt=r.useRef(-1),fe=P[D]??null,ct=r.useCallback(o=>{if(!o){W([]),k(0);return}const h=o.mountKey?o:{...o,mountKey:Bt()};W(u=>{const p=u.findIndex(y=>y.agent===h.agent&&y.sessionId===h.sessionId);if(p>=0)return k(p),u;if(u.length<oe.current){const y=[...u,h];return k(y.length-1),y}if(oe.current<gn){const y=[...u,h];return E(He(y.length,G.current)),k(y.length-1),y}const j=[...u];return j[Ie.current]=h,j})},[W,k,E]),[Ge,qe]=r.useState(!1),[J,_e]=r.useState(null),[We,dt]=r.useState(""),[ee,Be]=r.useState("all"),[ge,Qe]=r.useState({}),[Le,yt]=r.useState({}),ce=r.useDeferredValue(We),ie=r.useRef(!1),$e=r.useRef({}),Te=r.useRef(d);Te.current=d;const ut=r.useRef(ge);ut.current=ge;const Ee=r.useRef(new Set),re=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values(re.current))clearTimeout(o)},[]),r.useEffect(()=>{W(o=>{let h=!1;const u=o.map(p=>{const j=Le[p.workdir];if(!j)return p;const y=In(j,p.agent,p.sessionId);return y===p.sessionId?p:(h=!0,{...p,sessionId:y})});return h?u:o})},[Le,W]);const me=r.useCallback(async()=>{try{const o=await se.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((p,j)=>p.path===h[j].path&&p.name===h[j].name)?u:h),ie.current=!0}catch{ie.current=!0}finally{S(!1)}},[]);r.useEffect(()=>{me()},[me]);const L=r.useCallback(async(o,h={})=>{if(!$e.current[o]){$e.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Bs(o,{force:h.force});r.startTransition(()=>{yt(p=>{const j=u.promotions||{},y=p[o];return y&&Object.keys(y).length===Object.keys(j).length&&Object.entries(j).every(([I,q])=>y[I]===q)?p:{...p,[o]:j}}),b(p=>{const j=u.sessions||[],y=p[o]||[],I=new Set(j.map(A=>H(A.agent||"",A.sessionId))),q=y.filter(A=>{if(A.runState!=="running")return!1;const B=H(A.agent||"",A.sessionId);if(I.has(B))return!1;const O=ut.current[B];return!(O?.resolvedKey&&O.resolvedKey!==B)});return{...p,[o]:q.length?[...q,...j]:j}})})}catch{h.background||r.startTransition(()=>{b(u=>({...u,[o]:[]}))})}finally{$e.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),te=r.useRef(l);r.useEffect(()=>{l!==te.current&&(te.current=l,!(!l||!ie.current)&&me().then(()=>{L(l,{force:!0})}))},[l,me,L]);const Y=r.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(fn(),Ds({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Or}))},[]),Nt=r.useCallback((o,h,u=$r)=>{const p=`${h}:${H(o.agent||"",o.sessionId)}`,j=re.current[p];j&&clearTimeout(j),re.current[p]=setTimeout(()=>{delete re.current[p],Y(o,h)},u)},[Y]),Me=r.useCallback((o,h)=>{const u=`${h}:${H(o.agent||"",o.sessionId)}`,p=re.current[u];p&&(clearTimeout(p),delete re.current[u])},[]);r.useEffect(()=>{n&&fn()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||v[h.path])return;const p=setTimeout(()=>{L(h.path)},u*90);o.push(p)}),()=>{for(const h of o)clearTimeout(h)}},[n,L,v,d,c]);const Ye=r.useRef(new Map);Ln(n&&ie.current&&c.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=o.key,u=h?c.filter(y=>(Te.current[y.path]||[]).some(I=>H(I.agent||"",I.sessionId)===h)):c,p=u.length?u:c,j=Ye.current;for(const y of p)j.has(y.path)&&clearTimeout(j.get(y.path)),j.set(y.path,setTimeout(()=>{j.delete(y.path),L(y.path,{background:!0,force:!0})},300))},[c,L]));const Oe=r.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:ks(o,ge[H(h,o.sessionId)]||null)},[ge]);Ln("stream-update",r.useCallback(o=>{const h=o.key;if(!h)return;const u=ys(h,o.snapshot??null);Qe(p=>{if(!u){const B=p[h];return!B||B.phase==="done"?p:{...p,[h]:{...B,phase:"done",updatedAt:Date.now()}}}const j=(B,O)=>!!B&&!!O&&B.phase===O.phase&&B.resolvedKey===O.resolvedKey&&B.sessionId===O.sessionId&&B.incomplete===O.incomplete&&B.error===O.error,y=j(p[h],u),I=u.resolvedKey===h||j(p[u.resolvedKey],{...u,key:u.resolvedKey});if(y&&I)return p;const q=Date.now()-Dr,A={};for(const[B,O]of Object.entries(p))O.phase==="done"&&O.updatedAt<q||(A[B]=O);return A[h]=u,u.resolvedKey!==h&&(A[u.resolvedKey]={...u,key:u.resolvedKey}),A})},[])),Ns(r.useCallback(()=>{if(!(!n||!ie.current||c.length===0))for(const o of c)L(o.path,{background:!0,force:!0})},[n,c,L])),r.useEffect(()=>{if(!n||!ie.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)L(u.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,L,c]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const j=`${h.path}:${H(p.agent||"",p.sessionId)}`;if(Ee.current.has(j))return;const y=setTimeout(()=>{Ee.current.add(j),Y(p,h.path)},Br+u*120);o.push(y)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,Y,c]);const Xt=r.useCallback(async o=>{try{(await se.addWorkspace(o)).ok&&(qe(!1),await me(),L(o))}catch{}},[me,L]),[de,be]=r.useState(null),[ve,St]=r.useState(!1),[le,De]=r.useState(null),Xe=r.useCallback(o=>{be(o)},[]),Ze=r.useCallback(async()=>{const o=de;if(o){St(!0);try{await se.removeWorkspace(o),x(h=>h.filter(u=>u.path!==o)),b(h=>{const u={...h};return delete u[o],u}),W(h=>{const u=h.filter(p=>p.workdir!==o);return u.length!==h.length&&E(He(u.length,G.current)),u}),k(0),be(null)}catch{}finally{St(!1)}}},[de]),Je=r.useCallback(o=>{L(o,{force:!0})},[L]),[Ae,je]=r.useState(null),[et,Fe]=r.useState(!1),[we,ht]=r.useState(!1),xt=Ce(o=>o.toast),[ue,ke]=r.useState(null),tt=r.useCallback((o,h,u)=>{ke({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)}})},[]);r.useEffect(()=>{if(!ue)return;const o=()=>ke(null),h=u=>{u.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",h)}},[ue]);const Ct=r.useCallback(o=>{Fe(!1),je(o),ke(null)},[]),pt=r.useCallback(async()=>{const o=Ae;if(o){ht(!0);try{const h=await se.deleteSession(o.workdir,o.agent,o.sessionId,et);if(!h.ok){const u=h.error?.includes("still running")?i("session.deleteRunningError"):h.error||i("session.deleteFailed");xt(u,!1);return}b(u=>{const p=u[o.workdir];if(!p)return u;const j=p.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return j.length===p.length?u:{...u,[o.workdir]:j}}),W(u=>{const p=u.filter(j=>!(j.workdir===o.workdir&&j.agent===o.agent&&j.sessionId===o.sessionId));return p.length!==u.length&&E(He(p.length,G.current)),p}),je(null)}catch(h){xt(h?.message||i("session.deleteFailed"),!1)}finally{ht(!1)}}},[Ae,et,i,xt]),ye=r.useCallback(o=>{W(h=>{let u=!1;const p=h.map(j=>j.mountKey===o&&(j.pendingPrompt!=null||j.pendingImageUrls)?(u=!0,{...j,pendingPrompt:null,pendingImageUrls:void 0}):j);return u?p:h})},[W]),It=r.useCallback((o,h,u)=>{Y({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),b(y=>{const I=y[o.workdir]||[];if(I.some(B=>B.sessionId===o.sessionId&&B.agent===o.agent))return y;const A={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[A,...I]}});const p=kt.current,j={...o,mountKey:Bt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};r.startTransition(()=>{_e(null),W(y=>{if(p>=y.length)return[...y,j];const I=[...y];return I[p]=j,I}),k(p>=0?p:0)}),L(o.workdir,{background:!0,force:!0})},[L,Y,W,k]),ft=r.useCallback(o=>{K.current.length>=oe.current&&oe.current<gn&&E(He(oe.current+1,G.current)),_e(o)},[E]),Lt=r.useCallback(()=>{_e(null),E(He(K.current.length,G.current))},[E]),Tt=r.useCallback((o,h)=>{Y(o,h);const u=o.agent||"";K.current.some(p=>p.agent===u&&p.sessionId===o.sessionId)&&E(He(K.current.length,G.current)),_e(null),r.startTransition(()=>{ct({agent:u,sessionId:o.sessionId,workdir:h})})},[Y,E]),Et=r.useCallback((o,h)=>{Y({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{h!=null?(W(u=>{if(h>=u.length)return u;const p=[...u];return p[h]={...u[h],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},p}),k(h)):ct({...o,mountKey:Bt()})}),L(o.workdir,{background:!0,force:!0})},[L,Y]),gt=r.useCallback(o=>{let h=o;if(ee==="running"?h=h.filter(u=>Dt(u)==="running"):ee==="review"&&(h=h.filter(u=>Dt(u)==="incomplete")),ce.trim()){const u=ce.toLowerCase();h=h.filter(p=>(p.lastMessageText||"").toLowerCase().includes(u)||(p.lastQuestion||"").toLowerCase().includes(u)||(p.lastAnswer||"").toLowerCase().includes(u)||(p.title||"").toLowerCase().includes(u)||(p.agent||"").toLowerCase().includes(u))}return h},[ce,ee]),he=r.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(Oe),p=Le[h.path],j=new Map;for(const I of u){const q=H(I.agent||"",I.sessionId),A=ge[q],B=p?In(p,I.agent||"",I.sessionId):I.sessionId,O=A?.resolvedKey&&A.resolvedKey!==q?A.resolvedKey:B!==I.sessionId?H(I.agent||"",B):q,Ne=j.get(O);if(!Ne){j.set(O,I);continue}H(Ne.agent||"",Ne.sessionId)!==O&&q===O&&j.set(O,I)}const y=gt([...j.values()]);o[h.path]=Fr(y)}return o},[c,d,ge,Le,gt,Oe]),Mt=r.useCallback(o=>{const h=(d[o.workdir]||[]).find(u=>u.sessionId===o.sessionId&&u.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return Oe(h)},[Oe,d]),mt=r.useMemo(()=>new Set(P.map(o=>H(o.agent,o.sessionId))),[P]),Zt=fe?H(fe.agent,fe.sessionId):null,Jt=r.useCallback(o=>{W(h=>{const u=h.filter((p,j)=>j!==o);return u.length===0?k(0):Ie.current>=u.length&&k(u.length-1),E(He(u.length,G.current)),u})},[W,k,E]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:We,onChange:o=>dt(o.target.value),placeholder:i("hub.search"),className:"w-full rounded-lg border border-edge/40 bg-inset/50 pl-8 pr-7 py-1.5 text-[12px] text-fg outline-none placeholder:text-fg-5/30 focus:border-primary/30 focus:bg-inset focus:shadow-[0_0_0_3px_rgba(99,102,241,0.06)] transition-all duration-200"}),We&&e.jsx("button",{onClick:()=>dt(""),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:()=>Be(o),className:T("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",ee===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:i(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:w?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(pe,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!Ge?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:i("hub.noWorkspaces")}):c.map(o=>e.jsx(Xr,{workspace:o,sessions:he[o.path]||[],loading:!!v[o.path]||!(o.path in d),isActive:o.path===l,selectedKey:Zt,openSessionKeys:mt,onSelectSession:Tt,onNewSession:ft,onRefresh:Je,onRemove:Xe,onExtensions:De,onWarmSession:Nt,onCancelWarmSession:Me,onSessionMenuOpen:tt,t:i},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:()=>Q(o),className:T("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:i(`hub.layout${o}`),children:o===1?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"})}):o===2?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"12",rx:"1.5"}),e.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"1.5"})]}):o===3?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"0.5",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"11.5",y:"2",width:"4",height:"12",rx:"1"})]}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:[e.jsx("rect",{x:"0.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"0.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"})]})},o))}),e.jsxs(Re,{variant:"ghost",size:"sm",onClick:()=>qe(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"})]}),i("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=J?P.length<N?P.length:D:-1;return kt.current=o,Array.from({length:N},(h,u)=>{if(J&&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(Qr,{workdir:J,workspaceName:c.find(I=>I.path===J)?.name||J.split("/").pop()||"",onSessionCreated:It,onClose:Lt,t:i},J)},`new-${J}`);const p=P[u]??null;if(!p)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-dashed border-edge/40 bg-panel/30 flex items-center justify-center",children:e.jsxs("div",{className:"text-center px-4",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"mx-auto text-fg-5/20 mb-2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("div",{className:"text-[12px] text-fg-5/40",children:i("hub.emptySlot")})]})},`empty-${u}`);const j=Mt(p),y=u===D;return e.jsxs("div",{className:T("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>k(u),children:[e.jsxs("div",{className:T("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const I=Dt(j);return e.jsx(Qt,{variant:I==="running"?"ok":I==="waiting"?"info":I==="incomplete"?"warn":"idle",pulse:I==="running"||I==="waiting"})})(),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-0",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-fg-5",children:p.workdir.split("/").pop()||p.workdir}),e.jsx("span",{className:"shrink-0 text-fg-6 text-[10px] mx-1",children:"/"}),e.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-fg-3",children:j.title||j.lastQuestion?.slice(0,60)||(Kt(p.sessionId)?i("hub.newSession"):p.sessionId.slice(0,12))})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-2.5 pl-4 text-[9px] text-fg-5/50 tabular-nums",children:[e.jsx("span",{title:i("hub.created"),children:Ss(j.createdAt)}),j.runUpdatedAt&&e.jsx("span",{title:i("hub.updated"),children:Wn(j.runUpdatedAt)}),!!j.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"})}),j.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:I=>{I.stopPropagation(),ae(q=>!q)},className:T("p-0.5 rounded transition-colors",_?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:i("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:I=>{I.stopPropagation(),Jt(u)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:i("hub.closePanel"),children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Wr,{session:j,workdir:p.workdir,active:n&&y,onSessionChange:I=>Et(I,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>ye(p.mountKey)},p.mountKey)})})]},p.mountKey||H(p.agent,p.sessionId))})})()})}),_&&fe&&e.jsx(Jr,{workdir:fe.workdir,onClose:()=>ae(!1),t:i}),e.jsx(qr,{open:Ge,initialPath:l||void 0,onAdd:Xt,onClose:()=>qe(!1),t:i}),e.jsxs(Vt,{open:!!de,onClose:()=>!ve&&be(null),children:[e.jsx(Gt,{title:i("hub.removeWorkspace"),onClose:()=>!ve&&be(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:i("modal.confirmRemoveWorkspaceHint")}),de&&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:de}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Re,{variant:"ghost",onClick:()=>be(null),disabled:ve,children:i("modal.cancel")}),e.jsx(Re,{variant:"primary",onClick:Ze,disabled:ve,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(ve?"modal.removing":"modal.remove")})]})]}),ue&&(()=>{const h=Math.max(8,Math.min(ue.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ue.anchor.bottom+4,window.innerHeight-60);return e.jsx("div",{className:"fixed z-[60] min-w-[160px] rounded-md border border-edge bg-panel/95 backdrop-blur-md py-1",style:{left:h,top:u,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:p=>p.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>Ct(ue.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"})]}),i("session.delete")]})})})(),e.jsxs(Vt,{open:!!Ae,onClose:()=>!we&&je(null),children:[e.jsx(Gt,{title:i("session.deleteTitle"),onClose:()=>!we&&je(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("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:!et,onChange:()=>Fe(!1),disabled:we,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:i("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:i("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:et,onChange:()=>Fe(!0),disabled:we,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:i("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:i("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Re,{variant:"ghost",onClick:()=>je(null),disabled:we,children:i("modal.cancel")}),e.jsx(Re,{variant:"primary",onClick:pt,disabled:we,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(we?"session.deleting":"modal.remove")})]})]}),e.jsx(_r,{open:!!le,onClose:()=>De(null),workdir:le||""})]})});function qr({open:t,initialPath:n,onAdd:s,onClose:l,t:i}){const[c,x]=r.useState(""),d=r.useCallback(b=>x(b),[]);return r.useEffect(()=>{t&&x("")},[t]),e.jsxs(Vt,{open:t,onClose:l,children:[e.jsx(Gt,{title:i("hub.addWorkspace"),onClose:l}),e.jsx(Ts,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:i}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Re,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:i("hub.add")}),e.jsx(Re,{variant:"secondary",onClick:l,className:"flex-1",children:i("hub.cancel")})]})]})}function Qr({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:i}){const[c,x]=r.useState(null),[d,b]=r.useState([]),v=r.useRef(null),g=r.useRef([]),w=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),S=r.useCallback(()=>{},[]),N=r.useCallback((R,P)=>{x(R||null),v.current=R||null;const U=P||[];b(U),g.current=U},[]),$=r.useCallback(R=>{const P=g.current;g.current=[],s(R,v.current||void 0,P.length?P:void 0)},[s]),M=!!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:i("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(Qt,{variant:M?"ok":"idle",pulse:M}),!M&&e.jsx("button",{onClick:l,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:M?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(ns,{text:c||"",blocks:d.map(R=>({type:"image",content:R})),t:i}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(zt,{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:i("hub.newSessionHint")})})})}),e.jsx(er,{session:w,workdir:t,onStreamQueued:S,onSendStart:N,onSessionChange:$,t:i,streamPhase:null})]})}function Yr({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(Cs,{content:n,className:T("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 Xr=r.memo(function({workspace:n,sessions:s,loading:l,isActive:i,selectedKey:c,openSessionKeys:x,onSelectSession:d,onNewSession:b,onRefresh:v,onRemove:g,onExtensions:w,onWarmSession:S,onCancelWarmSession:N,onSessionMenuOpen:$,t:M}){const[R,P]=r.useState(!0),[U,D]=r.useState(xn);r.useEffect(()=>{D(xn)},[s.length]);const V=s.slice(0,U),E=s.length-U,z=n.path,[W,k]=r.useState(null),Q=r.useCallback(()=>{se.getWorkspaceGit(z).then(_=>k(_.git)).catch(()=>k(null))},[z]);return r.useEffect(()=>{Q()},[Q]),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:()=>P(_=>!_),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:T("shrink-0 text-fg-5 transition-transform duration-150",R&&"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:T("min-w-0 truncate text-[12px] font-semibold",i?"text-primary":"text-fg-3"),children:n.name}),e.jsx(Yr,{git:W})]}),i&&e.jsx(Qt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:_=>{_.stopPropagation(),b(z)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:M("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:_=>{_.stopPropagation(),w(z)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:M("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:_=>{_.stopPropagation(),v(z),Q()},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"})]})}),!i&&e.jsx("button",{onClick:_=>{_.stopPropagation(),g(z)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),R&&e.jsx("div",{className:"pb-1",children:l?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):s.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:M("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[V.map(_=>{const ae=H(_.agent||"",_.sessionId),oe=_.__forkDepth||0;return e.jsx(Zr,{session:_,isSelected:c===ae,isOpen:x?.has(ae)??!1,forkDepth:oe,onClick:()=>d(_,z),onWarm:()=>S(_,z),onCancelWarm:()=>N(_,z),onShowMenu:G=>$(G,_,z),menuLabel:M("session.openActions")},ae)}),E>0&&e.jsxs("button",{onClick:()=>D(_=>_+xn),className:"flex items-center gap-1.5 w-full px-3 py-1.5 text-[11px] text-fg-5 hover:text-fg-3 hover:bg-panel-h/50 transition-colors",children:[e.jsxs("span",{children:["+ ",M("hub.nMore").replace("{n}",String(E))]}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]})})]})}),Zr=r.memo(function({session:n,isSelected:s,isOpen:l,forkDepth:i=0,onClick:c,onWarm:x,onCancelWarm:d,onShowMenu:b,menuLabel:v}){const g=pn(n.agent||""),w=Dt(n),S=_n(n).slice(0,500)||(Kt(n.sessionId)?"":n.sessionId.slice(0,16)),N=Is(n,S).slice(0,500),$=n.model?Ht(n.model):null,M=i>0?Math.min(i,3)*14:0,R=l?10:12,P=r.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:x,onFocus:x,onMouseLeave:d,onBlur:d,className:T("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":l?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:R+M,...l?{borderLeft:`2px solid ${s?g.color:`${g.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[i>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(it,{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(Qt,{variant:w==="running"?"ok":w==="waiting"?"info":w==="incomplete"?"warn":"idle",pulse:w==="running"||w==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:S})]}),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:U=>{U.stopPropagation()},onClick:U=>{U.stopPropagation(),U.preventDefault(),P.current&&b(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"})]})})]})}),Jr=r.memo(function({workdir:n,onClose:s,t:l}){const i=Ce(g=>g.state?.hostApp??null),c=Ce(g=>g.state?.platform??null),x=Ce(g=>g.toast),[d,b]=r.useState(()=>Vr(i,c)),v=r.useCallback(async g=>{try{const w=await se.openInEditor(g,d);if(!w.ok)throw new Error(w.error||`Failed to open ${g}`)}catch(w){x(w?.message||String(w),!1)}},[d,x]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:l("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:l("hub.closePanel"),children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"shrink-0 px-2.5 py-1.5 border-b border-edge/20 flex items-center gap-2",children:[e.jsx(Ls,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:l(rs(g))})),onChange:g=>{Hr(g)&&b(g)},renderIcon:g=>e.jsx(os,{target:g,size:14})}),e.jsx(Re,{size:"sm",variant:"ghost",onClick:()=>v(n),className:"flex-1 min-w-0 text-[11px]",children:l("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(eo,{basePath:n,openTarget:d,onOpenPath:v,t:l})})]})});function os({target:t,size:n=16}){return t==="default"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 16 16",className:"shrink-0 text-fg-4",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 3H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-2"}),e.jsx("path",{d:"M9 2h5v5"}),e.jsx("path",{d:"M14 2L7 9"})]}):e.jsx(it,{brand:t,size:n})}function eo({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:l,t:i}){const[c,x]=r.useState([]),[d,b]=r.useState(!0);r.useEffect(()=>{let g=!1;return b(!0),se.lsDir(t,!0,n).then(w=>{!g&&w.ok&&x(w.dirs.slice(0,50).map(S=>({entry:S,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||b(!1)}),()=>{g=!0}},[t,n]);const v=r.useCallback(g=>{const w=S=>S.map(N=>N.entry.path===g?N.expanded?{...N,expanded:!1}:N.children===null?(se.lsDir(g,!0,n).then($=>{$.ok&&x(M=>mn(M,g,{children:$.dirs.slice(0,50).map(R=>({entry:R,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x($=>mn($,g,{children:[],loading:!1}))}),{...N,loading:!0,expanded:!0}):{...N,expanded:!0}:N.children?{...N,children:w(N.children)}:N);x(S=>w(S))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(is,{nodes:c,depth:0,onToggle:v,openTarget:s,onOpenPath:l,t:i})})}function is({nodes:t,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(to,{node:x,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c},x.entry.path))})}function to({node:t,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c}){const{entry:x,expanded:d,children:b,loading:v}=t,g=n*14,[w,S]=r.useState(!1),N=c(rs(l)),$=c("hub.openWithTarget").replace("{target}",N);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>S(!0),onMouseLeave:()=>S(!1),className:T("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",x.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+g,paddingRight:8},children:[x.isDir?v?e.jsx(pe,{className:"h-2 w-2 text-fg-5 shrink-0"}):e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:T("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),x.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:x.name}),w&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:M=>{M.stopPropagation(),i(x.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:$,children:e.jsx(os,{target:l,subtle:!0})}),!x.isDir&&e.jsx(no,{filePath:x.path,t:c})]})]}),x.isDir&&d&&b&&b.length>0&&e.jsx(is,{nodes:b,depth:n+1,onToggle:s,openTarget:l,onOpenPath:i,t:c})]})}function no({filePath:t,t:n}){const[s,l]=r.useState(!1);return e.jsx("button",{onClick:i=>{i.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},className:T("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 mn(t,n,s){return t.map(l=>l.entry.path===n?{...l,...s}:l.children?{...l,children:mn(l.children,n,s)}:l)}const ko=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Gr},Symbol.toStringTag,{value:"Module"}));export{er as I,jo as L,hr as R,wo as T,ns as U,mo as a,Zn as b,fo as c,po as d,zt as e,vo as f,Tr as g,ko as i,Os as l,bo as m,go as n,xo as o,$s as p,ho as s};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-
|
|
1
|
+
import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-B4_qsasx.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,10 +6,10 @@
|
|
|
6
6
|
<link rel="icon" type="image/png" href="/logo.png">
|
|
7
7
|
<title>Pikiloom</title>
|
|
8
8
|
<link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-B4_qsasx.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
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
12
|
+
<link rel="stylesheet" crossorigin href="/assets/index-CkriX56t.css">
|
|
13
13
|
</head>
|
|
14
14
|
<body>
|
|
15
15
|
<div id="root"></div>
|
package/dist/agent/artifacts.js
CHANGED
|
@@ -101,6 +101,32 @@ export function latestDeliveredTaskId(agent, sessionId) {
|
|
|
101
101
|
}
|
|
102
102
|
return latest?.taskId;
|
|
103
103
|
}
|
|
104
|
+
export function tailDeliveredBlocks(agent, sessionId, opts) {
|
|
105
|
+
// While a turn is running or just finished, the bot still knows its task id. Scope
|
|
106
|
+
// strictly to it: the latest turn's deliveries only, and nothing when the latest turn
|
|
107
|
+
// delivered no file — so a prior turn's image does not re-append onto every later reply.
|
|
108
|
+
if (opts.currentTaskId != null) {
|
|
109
|
+
const filter = (a) => a.taskId === opts.currentTaskId;
|
|
110
|
+
return readDeliveredArtifacts(agent, sessionId).some(filter)
|
|
111
|
+
? deliveredArtifactBlocks(agent, sessionId, filter)
|
|
112
|
+
: [];
|
|
113
|
+
}
|
|
114
|
+
// Idle / cold reload: the delivering turn is long over and task ids are not persisted
|
|
115
|
+
// per turn. Fall back to the most recent delivery, suppressed once the session has kept
|
|
116
|
+
// running well past it.
|
|
117
|
+
const latestTask = latestDeliveredTaskId(agent, sessionId);
|
|
118
|
+
const filter = latestTask ? (a) => a.taskId === latestTask : undefined;
|
|
119
|
+
const scoped = readDeliveredArtifacts(agent, sessionId).filter(a => !filter || filter(a));
|
|
120
|
+
if (!scoped.length)
|
|
121
|
+
return [];
|
|
122
|
+
let newestTs = scoped[0].ts;
|
|
123
|
+
for (const a of scoped)
|
|
124
|
+
if (a.ts > newestTs)
|
|
125
|
+
newestTs = a.ts;
|
|
126
|
+
if (opts.lastActivityMs != null && opts.lastActivityMs - newestTs > opts.staleAfterMs)
|
|
127
|
+
return [];
|
|
128
|
+
return deliveredArtifactBlocks(agent, sessionId, filter);
|
|
129
|
+
}
|
|
104
130
|
export function deliveredArtifactBlocks(agent, sessionId, filter) {
|
|
105
131
|
const blocks = [];
|
|
106
132
|
for (const a of readDeliveredArtifacts(agent, sessionId)) {
|
|
@@ -1075,6 +1075,21 @@ export async function doClaudeStream(opts) {
|
|
|
1075
1075
|
return result;
|
|
1076
1076
|
}
|
|
1077
1077
|
export const claudeProjectDirName = encodePathAsDirName;
|
|
1078
|
+
export function normalizeClaudeSessionEntrypoint(workdir, sessionId) {
|
|
1079
|
+
if (!sessionId)
|
|
1080
|
+
return;
|
|
1081
|
+
const home = getHome();
|
|
1082
|
+
if (!home)
|
|
1083
|
+
return;
|
|
1084
|
+
const file = path.join(home, '.claude', 'projects', claudeProjectDirName(workdir), `${sessionId}.jsonl`);
|
|
1085
|
+
try {
|
|
1086
|
+
const data = fs.readFileSync(file, 'utf-8');
|
|
1087
|
+
if (!data.includes('"entrypoint":"sdk-cli"'))
|
|
1088
|
+
return;
|
|
1089
|
+
fs.writeFileSync(file, data.split('"entrypoint":"sdk-cli"').join('"entrypoint":"cli"'));
|
|
1090
|
+
}
|
|
1091
|
+
catch { }
|
|
1092
|
+
}
|
|
1078
1093
|
function extractClaudeTailQA(filePath) {
|
|
1079
1094
|
const lines = readTailLines(filePath, 1024 * 1024);
|
|
1080
1095
|
let lastQuestion = null;
|
|
@@ -2044,7 +2059,9 @@ class ClaudeDriver {
|
|
|
2044
2059
|
capabilities = { fork: true, modelSwitch: true, workflow: true };
|
|
2045
2060
|
acceptedProviderKinds = ['anthropic', 'openai-compatible'];
|
|
2046
2061
|
async doStream(opts) {
|
|
2047
|
-
|
|
2062
|
+
const result = await doClaudeWithRetry(opts);
|
|
2063
|
+
normalizeClaudeSessionEntrypoint(opts.workdir, result.sessionId);
|
|
2064
|
+
return result;
|
|
2048
2065
|
}
|
|
2049
2066
|
async getSessions(workdir, limit) {
|
|
2050
2067
|
return getClaudeSessions(workdir, limit);
|
package/dist/agent/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import './drivers/gemini.js';
|
|
|
4
4
|
import './drivers/hermes.js';
|
|
5
5
|
export { IMAGE_EXTS } from './types.js';
|
|
6
6
|
export { attachAgentImage, attachInlineImage, materializeImage, rewriteAttachmentBlocksForTransport, attachmentUrl, resolveAllowedAttachmentPath, allowedAttachmentRoots, decodeAttachmentPathParam, sessionAttachmentsDir, codexHome, } from './images.js';
|
|
7
|
-
export { deliverArtifact, readDeliveredArtifacts, deliveredArtifactBlocks, latestDeliveredTaskId, mimeForArtifact, } from './artifacts.js';
|
|
7
|
+
export { deliverArtifact, readDeliveredArtifacts, deliveredArtifactBlocks, tailDeliveredBlocks, latestDeliveredTaskId, mimeForArtifact, } from './artifacts.js';
|
|
8
8
|
export { Q, agentLog, agentWarn, agentError, dedupeStrings, numberOrNull, normalizeStreamPreviewPlan, parseTodoWriteAsPlan, normalizeActivityLine, pushRecentActivity, detectClaudeApiError, isRetryableClaudeApiError, detectClaudeModelError, claudeModelErrorMessage, firstNonEmptyLine, shortValue, normalizeErrorMessage, joinErrorMessages, appendSystemPrompt, mimeForExt, computeContext, buildStreamPreviewMeta, summarizeClaudeToolUse, summarizeClaudeToolResult, previewToolCallInput, previewToolCallResult, roundPercent, toIsoFromEpochSeconds, normalizeUsageStatus, labelFromWindowMinutes, usageWindowFromRateLimit, parseJsonTail, modelFamily, normalizeClaudeModelId, emptyUsage, readTailLines, stripInjectedPrompts, sanitizeSessionUserPreviewText, SESSION_PREVIEW_IMAGE_PLACEHOLDER_RE, CLAUDE_AT_MENTION_IMAGE_RE, extractClaudeAtMentionImagePaths, stripClaudeAtMentionImages, isPendingSessionId, emitSessionIdUpdate, sessionListDisplayTitle, } from './utils.js';
|
|
9
9
|
export { updateSessionMeta, promoteSessionId, recordFork, resolveCanonicalSessionId, getSessionPromotions, listPikiloomSessions, findPikiloomSession, getSessionStoredConfig, ensureManagedSession, findManagedThreadSession, stageSessionFiles, mergeManagedAndNativeSessions, managedRecordToSessionInfo, getSessions, getSessionTail, getSessionMessages, applyTurnWindow, applyTurnFilter, classifySession, deriveUserStatus, exportSession, importSession, deleteAgentSession, isProcessAlive, isRunningSessionStale, reconcileOrphanedRunningSessions, } from './session.js';
|
|
10
10
|
export { detectAgentBin, listAgents, resolveDefaultAgent, run, doStream, listModels, resolveAgentModels, getUsage, getAgentBoundModelId, setAgentBoundModelId, } from './stream.js';
|
package/dist/core/constants.js
CHANGED
|
@@ -8,6 +8,7 @@ export const MCP_TIMEOUTS = {
|
|
|
8
8
|
codexMcpRemove: 5_000,
|
|
9
9
|
};
|
|
10
10
|
export const MCP_ARTIFACT_MAX_BYTES = 20 * 1024 * 1024;
|
|
11
|
+
export const DELIVERED_ARTIFACT_TAIL_STALE_MS = 60 * 60_000;
|
|
11
12
|
export const DASHBOARD_TIMEOUTS = {
|
|
12
13
|
agentStatusModels: 4_000,
|
|
13
14
|
agentStatusUsage: 1_500,
|
|
@@ -4,13 +4,13 @@ import os from 'node:os';
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { Readable } from 'node:stream';
|
|
6
6
|
import { loadUserConfig } from '../../core/config/user-config.js';
|
|
7
|
-
import { listAgents, listSkills, decodeAttachmentPathParam, resolveAllowedAttachmentPath, rewriteAttachmentBlocksForTransport,
|
|
7
|
+
import { listAgents, listSkills, decodeAttachmentPathParam, resolveAllowedAttachmentPath, rewriteAttachmentBlocksForTransport, tailDeliveredBlocks, mimeForArtifact, } from '../../agent/index.js';
|
|
8
8
|
import { getSessionStatusForBot } from '../../bot/session-status.js';
|
|
9
9
|
import { findPikiloomSession } from '../../agent/session.js';
|
|
10
10
|
import { readAwaitResume } from '../../agent/await-resume.js';
|
|
11
11
|
import { cancelSessionTask, stopSessionTasks, getSessionStreamState, queueDashboardSessionTask, forkDashboardSessionTask, steerSessionTask, interactionSelectOption, interactionSubmitText, interactionSkip, interactionCancel, getInteractionPrompt, } from '../session-control.js';
|
|
12
12
|
import { querySessions, querySessionTail, querySessionMessages, getWorkspaceOverviews, updateSession, linkSessions, buildMigrationContext, exportSession, importSession, deleteSession, loadWorkspaces, addWorkspace, removeWorkspace, updateWorkspace, } from '../../bot/session-hub.js';
|
|
13
|
-
import { DASHBOARD_PAGINATION } from '../../core/constants.js';
|
|
13
|
+
import { DASHBOARD_PAGINATION, DELIVERED_ARTIFACT_TAIL_STALE_MS } from '../../core/constants.js';
|
|
14
14
|
import { runtime } from '../runtime.js';
|
|
15
15
|
const DEFAULT_SESSION_PAGE_SIZE = DASHBOARD_PAGINATION.defaultPageSize;
|
|
16
16
|
const MAX_SESSION_PAGE_SIZE = DASHBOARD_PAGINATION.maxPageSize;
|
|
@@ -394,13 +394,16 @@ app.post('/api/session-hub/session/messages', async (c) => {
|
|
|
394
394
|
turnLimit: Number.isFinite(turnLimit) ? turnLimit : undefined,
|
|
395
395
|
rich,
|
|
396
396
|
});
|
|
397
|
-
|
|
397
|
+
const record = findPikiloomSession(workdir, agent, sessionId);
|
|
398
|
+
const lastActivity = record ? Date.parse(record.runUpdatedAt || record.updatedAt) : NaN;
|
|
399
|
+
const lastActivityMs = Number.isFinite(lastActivity) ? lastActivity : null;
|
|
400
|
+
return c.json(prepareSessionMessagesForDashboard(result, agent, sessionId, lastActivityMs));
|
|
398
401
|
}
|
|
399
402
|
catch (e) {
|
|
400
403
|
return c.json({ ok: false, error: e.message }, 500);
|
|
401
404
|
}
|
|
402
405
|
});
|
|
403
|
-
function prepareSessionMessagesForDashboard(result, agent, sessionId) {
|
|
406
|
+
function prepareSessionMessagesForDashboard(result, agent, sessionId, lastActivityMs) {
|
|
404
407
|
if (result.richMessages === undefined)
|
|
405
408
|
return result;
|
|
406
409
|
const richMessages = result.richMessages.map(message => ({
|
|
@@ -409,12 +412,12 @@ function prepareSessionMessagesForDashboard(result, agent, sessionId) {
|
|
|
409
412
|
}));
|
|
410
413
|
const includesTail = !result.window || !result.window.hasNewer;
|
|
411
414
|
if (includesTail) {
|
|
412
|
-
//
|
|
413
|
-
//
|
|
414
|
-
// would
|
|
415
|
-
//
|
|
416
|
-
|
|
417
|
-
const delivered = rewriteAttachmentBlocksForTransport(
|
|
415
|
+
// Surface the latest turn's delivered files. Artifacts live in a session-wide
|
|
416
|
+
// manifest, so the dump is scoped to the latest task (without it every file ever
|
|
417
|
+
// sent would re-append onto the latest reply) and suppressed once the session has
|
|
418
|
+
// kept running well past the last delivery — an out-of-band file is only "tail"
|
|
419
|
+
// content for the turn that sent it, not for later turns that delivered nothing.
|
|
420
|
+
const delivered = rewriteAttachmentBlocksForTransport(tailDeliveredBlocks(agent, sessionId, { lastActivityMs, staleAfterMs: DELIVERED_ARTIFACT_TAIL_STALE_MS }), { agent, sessionId });
|
|
418
421
|
if (delivered.length) {
|
|
419
422
|
const text = deliveredSummaryText(delivered);
|
|
420
423
|
richMessages.push({ role: 'assistant', text, blocks: delivered });
|
package/package.json
CHANGED