pikiloom 0.4.29 → 0.4.30

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.
@@ -0,0 +1,23 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-DRrCVpih.js","assets/react-vendor-C7Sl8SE7.js","assets/index-CJm8YsKX.js","assets/router-DHISdpPk.js","assets/index-CXIN3nTr.css","assets/Modal-B4wc5184.js","assets/Select-xEvJAcZi.js","assets/DirBrowser-DPNjooga.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-Bv_23Acs.js"])))=>i.map(i=>d[i]);
2
+ import{c as I,a as ee,u as ye,i as Dt,f as Et,A as us,s as Ft,S as pe,B as rt,g as an,w as hs,b as xs,E as tn,C as pn,d as ps,r as Nn,e as Sn,h as fs,n as gs,j as ms,k as An,l as Bt,m as Ee,D as Kt,o as bs,p as Rn,_ as Pn,T as vs,q as js}from"./index-CJm8YsKX.js";import{j as e,r,a as fn}from"./react-vendor-C7Sl8SE7.js";import{I as ws}from"./Select-xEvJAcZi.js";import{M as Ut,a as zt}from"./Modal-B4wc5184.js";import{D as ks}from"./DirBrowser-DPNjooga.js";import{n as ys,r as Ns,M as gn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Ss}from"./ExtensionsTab-Bv_23Acs.js";function Cs({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:I("shrink-0 text-fg-5/40 transition-transform duration-200",t&&"rotate-180",n),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function ot({open:t,onToggle:n,dot:s,label:l,preview:i,badge:c,collapsedContent:x,children:d,className:b}){return e.jsxs("div",{className:I("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:I("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(Cs,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Ts=5e3,Is=15e3,$t=8,Ot=30,Ls=1,st=new Map,ke=new Map,nn=new Set,_n=[];let At=0;function sn(t){return typeof t=="number"&&Number.isFinite(t)}function ze(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 Wn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(ze(t,n,s,t===ke?Ot:$t),s.value)}function Bn(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:sn(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:sn(t.turnOffset)?t.turnOffset:void 0,turnLimit:sn(t.turnLimit)?t.turnLimit:void 0}}function mn(t){const n=Bn(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function $n(){for(;At<Ls;){const t=_n.shift();if(!t)return;At+=1,t().finally(()=>{At=Math.max(0,At-1),$n()})}}async function Ms(t,n={}){const s=t;if(!n.force){const c=Wn(st,s);if(c)return c}const l=st.get(s);if(l?.promise)return l.promise;const i=ee.getWorkspaceSessions(t,n.request).then(c=>(ze(st,s,{value:c,expiresAt:c.ok?Date.now()+Ts:0},$t),c)).finally(()=>{const c=st.get(s);c?.promise&&ze(st,s,{value:c.value,expiresAt:c.expiresAt},$t)});return ze(st,s,{value:l?.value,expiresAt:l?.expiresAt??0,promise:i},$t),i}function Es(t,n={}){const s=mn(t),l=ke.get(s);return l?.value?.ok&&(n.allowStale||l.expiresAt>Date.now())?l.value:null}async function As(t,n={}){const s=Bn(t),l=mn(s);if(!n.force){const x=Wn(ke,l);if(x?.ok)return x}const i=ke.get(l);if(i?.promise)return i.promise;const c=ee.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(ze(ke,l,{value:x,expiresAt:x.ok?Date.now()+Is:0},Ot),x)).finally(()=>{const x=ke.get(l);x?.promise&&ze(ke,l,{value:x.value,expiresAt:x.expiresAt},Ot)});return ze(ke,l,{value:i?.value,expiresAt:i?.expiresAt??0,promise:c},Ot),c}function Rs(t){const n=mn(t);Es(t)||nn.has(n)||ke.get(n)?.promise||(nn.add(n),_n.push(async()=>{try{await As(t)}catch{}finally{nn.delete(n)}}),$n())}function no(t){const n=t.streaming||t.liveStreamPhase==="streaming",s=t.queuedTaskCount>0||t.pendingQueuedCount>0||t.streamPhase==="queued";return n||s}function so(t){const{pendingTaskId:n,streamTaskId:s,queuedTaskIds:l}=t;return!n||n===s?!1:!!l&&l.includes(n)}function Ps(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 ro(t,n){return t==null||n==null?!0:t===n}function Cn(t){return(t||"").replace(/\s+/g," ").trim()}function oo(t,n){return Cn(t)===Cn(n)}function io(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=Ws(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 lo(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 ao(t,n){if(n.startTurn<=t.startTurn)return n;const s=Math.max(0,n.startTurn-t.startTurn);return{turns:[...t.turns.slice(0,s),...n.turns],startTurn:t.startTurn,endTurn:n.endTurn,totalTurns:n.totalTurns,hasOlder:t.startTurn>0}}function _s(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
3
+
4
+ `),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function Ws(t){const n=[];let s={user:null,assistant:null};for(const l of t)if(l.role==="user"){if(s.assistant&&On(l.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=l}else s.assistant?s.assistant=_s(s.assistant,l):s.assistant=l;return(s.user||s.assistant)&&n.push(s),n}const Bs=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"]),$s=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function On(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Bs.has(s[1].toLowerCase())?!0:$s.some(l=>t.includes(l))}function Dn(t,n){const s=t.split(`
5
+ `).filter(l=>l.trim());return s.length<=n?s.join(`
6
+ `):s.slice(-n).join(`
7
+ `)}function Os(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 rn(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function Ds(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function Fn(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 Fs(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 Us(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 Un(t){const n=String(t.toolName||"").trim()||"Tool",s=Us(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 zs(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 Ks(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 jt=new Map;function Hs(t,n){return`${t}:${n}`}function Vs(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 Gs=r.memo(function({session:n,workdir:s,onStreamQueued:l,onSendStart:i,onSendTaskAssigned:c,onSessionChange:x,t:d,streamPhase:b,streamTaskId:w,queuedTaskIds:g,queuedTasks:j,pendingQueuedSends:T,onRecall:N,onSteer:E,onStopAll:L,editDraft:A,onEditDraftConsumed:_,onSelectionChange:S}){const[B,te]=r.useState(""),[M,G]=r.useState(!1),[W,D]=r.useState(null),[ae,R]=r.useState(()=>new Set),[ce,re]=r.useState(()=>new Set),Y=r.useRef({prompt:"",files:[]}),Ne=ye(a=>a.agentStatus?.agents??null),[K,wt]=r.useState(Ne||[]),[fe,lt]=r.useState(""),[Ke,He]=r.useState(""),[oe,Ae]=r.useState(""),[ne,Se]=r.useState([]),[Re,Ve]=r.useState(null),[de,kt]=r.useState(null),[ue,Ge]=r.useState(null),[Pe,se]=r.useState(null),[qe,Ce]=r.useState(null),[Te,at]=r.useState(void 0),[$,q]=r.useState("closed"),[U,ct]=r.useState(null),Q=r.useRef(null),Qe=r.useRef(!1),yt=r.useRef(null),Vt=r.useRef(null),ge=r.useRef(null),dt=r.useRef([]),[me,_e]=r.useState([]),[X,We]=r.useState(!1),[Be,$e]=r.useState(0),Ye=r.useRef(null),ut=ye(a=>a.refreshAgentStatus),[ht,Ie]=r.useState([]),[be,Xe]=r.useState([]),[Je,ve]=r.useState({}),Le=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&&Xe(a.providers||[]),f?.ok&&Ie(f.profiles||[]),m?.ok){const C={};for(const z of m.bindings||[])C[z.agent]=z.activeProfileId;ve(C)}}catch{}},[]);r.useEffect(()=>{Le()},[Le]),r.useEffect(()=>{Ne?.length&&wt(Ne)},[Ne]),r.useEffect(()=>{dt.current=ne},[ne]);const je=Hs(n.agent||"",n.sessionId),ie=r.useRef(je);ie.current=je,r.useEffect(()=>{const a=jt.get(je);return a&&(jt.delete(je),a.text&&te(a.text),a.files.length&&Se(a.files.map(rn))),()=>{const f=Q.current?.value||"",m=dt.current.map(C=>C.file);for(const C of dt.current)URL.revokeObjectURL(C.previewUrl);f||m.length?jt.set(ie.current,{text:f,files:m}):jt.delete(ie.current)}},[je]);const Ze=r.useRef({agent:n.agent||"",sessionId:n.sessionId});r.useEffect(()=>{const a=Ze.current,f={agent:n.agent||"",sessionId:n.sessionId};Ze.current=f,!(a.agent===f.agent&&Dt(a.sessionId)&&!Dt(f.sessionId))&&(lt(""),He(""),Ae(""),Ge(null),se(null),Ce(null),q("closed"))},[n.agent,n.sessionId]),r.useEffect(()=>{A!=null&&(te(A),_?.(),requestAnimationFrame(()=>{const a=Q.current;a&&(a.focus(),a.setSelectionRange(A.length,A.length))}))},[A,_]),r.useEffect(()=>{if(!s)return;let a=!1;return ee.getSkills(s).then(f=>{!a&&f.ok&&_e(f.skills)}).catch(()=>{}),()=>{a=!0}},[s]);const xt=X?(()=>{const a=B.match(/^\/(\S*)$/);return a?a[1].toLowerCase():null})():null,we=xt!==null?me.filter(a=>a.name.toLowerCase().includes(xt)||a.label&&a.label.toLowerCase().includes(xt)):[];r.useEffect(()=>{$e(0)},[X,B]),r.useEffect(()=>{if(!X||!Ye.current)return;const a=Ye.current.querySelector(`[data-skill-idx="${Be}"]`);a&&a.scrollIntoView({block:"nearest"})},[Be,X]),r.useEffect(()=>{if(!X)return;const a=f=>{Ye.current?.contains(f.target)||Q.current?.contains(f.target)||We(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[X]),r.useEffect(()=>{if($==="closed")return;const a=f=>{const m=f.target;ge.current?.contains(m)||document.getElementById("cascade-portal")?.contains(m)||(q("closed"),Ge(null),se(null),Ce(null))};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[$]),r.useLayoutEffect(()=>{if($==="closed"||!ge.current){ct(null);return}const a=ge.current.getBoundingClientRect();ct({left:a.left,bottom:window.innerHeight-a.top+8})},[$]);const Nt=g&&g.length?g[0]:null;r.useEffect(()=>{W&&(Nt||b!==null&&b!=="queued")&&D(null)},[b,W,Nt]),r.useEffect(()=>{const a=Q.current;a&&(a.style.height="auto",a.style.height=Math.min(a.scrollHeight,200)+"px")},[B]);const pt=r.useCallback(a=>{const f=Array.from(a||[]).filter(m=>m.type.startsWith("image/"));f.length&&Se(m=>[...m,...f.map(rn)])},[]),St=r.useCallback(()=>{Ve(null),Se(a=>(Ds(a),[]))},[]),Ct=r.useCallback(a=>{Se(f=>{const m=f.find(C=>C.id===a);return m&&URL.revokeObjectURL(m.previewUrl),f.filter(C=>C.id!==a)}),Ve(f=>f===a?null:f)},[]),Tt=r.useCallback(()=>{const a=B.trim(),f=ne.map(J=>J.file);if(!a&&f.length===0||M)return;const m=fe||n.agent||K.find(J=>J.isDefault)?.agent||"";if(!m)return;const C=K.find(J=>J.agent===m)||null,z=!!n.agent&&m===n.agent,xe=(Ke||z&&n.model||""||C?.selectedModel||"").trim()||null,Fe=m==="gemini"?null:(oe||(z?Et(m,n.thinkingEffort,n.workflowEnabled):"")||Et(m,C?.selectedEffort,C?.workflowEnabled)||"").trim()||null,Me=m!==n.agent,le=Me?"":n.sessionId,en=Me&&n.agent?n.agent:null,cs=Me&&n.sessionId?n.sessionId:null;G(!0),Y.current={prompt:a,files:f},te(""),jt.delete(ie.current);const ds=f.length?f.map(J=>URL.createObjectURL(J)):void 0;St(),i(a,ds),l(),ee.sendSessionMessage(s,m,le,a,{attachments:f,model:xe,effort:Fe,previousAgent:en,previousSessionId:cs}).then(J=>{if(J.taskId&&(D(J.taskId),c?.(J.taskId)),!J.ok)return;const vt=typeof J.sessionKey=="string"?Ks(J.sessionKey):null;vt&&(vt.agent!==n.agent||vt.sessionId!==n.sessionId)&&vt&&x?.({...vt,workdir:s})}).catch(()=>{}).finally(()=>G(!1))},[K,St,ne,B,i,c,x,l,fe,oe,Ke,M,n.agent,n.sessionId,s]),It=b==="streaming",he=Ps({queuedTaskIds:g,streamPhase:b,streamTaskId:w,localTaskId:W}),ft=he[he.length-1]||null,gt=he.length>0,Gt=gt||It;r.useEffect(()=>{const a=f=>he.includes(f)||f===w;R(f=>{let m=!1;const C=new Set;for(const z of f)a(z)?C.add(z):m=!0;return m?C:f}),re(f=>{let m=!1;const C=new Set;for(const z of f)a(z)?C.add(z):m=!0;return m?C:f})},[he,w]),r.useEffect(()=>{!gt&&Y.current.files.length&&(Y.current={prompt:"",files:[]})},[gt]);const qt=r.useCallback(a=>{if(!ae.has(a)){if(R(f=>{const m=new Set(f);return m.add(a),m}),a===ft){const f=Y.current;f.prompt&&te(f.prompt),f.files.length&&Se(f.files.map(rn)),Y.current={prompt:"",files:[]}}N?.(a),a===W&&D(null)}},[ae,ft,W,N]),[et,Lt]=r.useState(!1),o=r.useCallback(async()=>{if(!(et||!L)){Lt(!0);try{await L()}finally{Lt(!1)}}},[et,L]),h=r.useCallback(a=>{ce.has(a)||(re(f=>{const m=new Set(f);return m.add(a),m}),E?.(a),a===W&&D(null))},[ce,W,E]),u=r.useCallback(a=>{te(`/${a.name} `),We(!1),requestAnimationFrame(()=>{const f=Q.current;f&&(f.focus(),f.setSelectionRange(f.value.length,f.value.length))})},[]),p=r.useCallback(a=>{te(a);const f=/^\/\S*$/.test(a)&&me.length>0;We(f)},[me.length]),v=a=>{if(X&&we.length>0){if(a.key==="ArrowDown"){a.preventDefault(),$e(f=>(f+1)%we.length);return}if(a.key==="ArrowUp"){a.preventDefault(),$e(f=>(f-1+we.length)%we.length);return}if(a.key==="Tab"||a.key==="Enter"&&!a.shiftKey&&!Qe.current){a.preventDefault(),u(we[Be]);return}if(a.key==="Escape"){a.preventDefault(),We(!1);return}}a.key==="Enter"&&!a.shiftKey&&!Qe.current&&(a.preventDefault(),Tt())},y=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(),pt(f))},[pt]),k=fe||n.agent||K.find(a=>a.isDefault)?.agent||K.find(a=>a.installed)?.agent||K[0]?.agent||"",H=K.find(a=>a.agent===k)||null,F=ue||k,P=K.find(a=>a.agent===F)||H,O=r.useMemo(()=>{if(!P)return[];const a=[];for(const m of P.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(us[F]||[]);for(const m of ht){const C=be.find(xe=>xe.id===m.providerId);if(!C||!f.has(C.kind))continue;const z=m.name.trim().toLowerCase()!==m.modelId.trim().toLowerCase();a.push({id:m.modelId,label:m.name,kind:"profile",profileId:m.id,description:z?`${C.name} · ${m.modelId}`:C.name})}return a},[P,F,ht,be]),mt=r.useMemo(()=>O.findIndex(a=>a.kind==="profile"),[O]),jn=Je[F]||null,wn=!!n.agent&&k===n.agent,bt=Ke||wn&&n.model||""||H?.selectedModel||"",Mt=k==="gemini"?"":oe||(wn?Et(k,n.thinkingEffort,n.workflowEnabled):"")||Et(k,H?.selectedEffort,H?.workflowEnabled)||"";r.useEffect(()=>{S?.({model:bt||null,effort:Mt||null})},[bt,Mt,S]);const ss=tn[F]||[],Oe=Re&&ne.find(a=>a.id===Re)||null,rs=Oe?{key:Oe.id,url:Oe.previewUrl,name:Oe.file.name,size:Oe.file.size,file:Oe.file,onRemove:()=>Ct(Oe.id)}:de?{key:de,url:de}:null,kn=(!!B.trim()||ne.length>0)&&!M&&!!k,Qt=()=>{Ge(null),se(null),Ce(null),at(void 0)},Yt=r.useCallback(async(a,f,m)=>{const C=a==="gemini"?"":m||"";if(Te!==void 0)try{await fetch(`/api/models/agents/${a}/active`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileId:Te})}),Le(),ut()}catch{}lt(a),He(f),Ae(C),Qt(),q("closed")},[Te,Le,ut]),os=()=>{$==="closed"?(Qt(),ut(),Le(),q("agent")):(Qt(),q("closed"))},Xt=ue||k,yn=an(Xt),Jt=Pe??bt,tt=qe??Mt,is=Jt?Ft(Jt):"",De=(()=>{const a=Je[Xt];return a?ht.find(f=>f.id===a)??null:null})(),nt=De?be.find(a=>a.id===De.providerId)??null:null,ls=nt?Vs(nt):null,Zt=De?De.name.trim().toLowerCase()!==De.modelId.trim().toLowerCase()?De.name:Ft(De.modelId):is,as=[yn.shortLabel,nt?nt.name:null,Zt||null,tt?tt.charAt(0).toUpperCase()+tt.slice(1):null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:Vt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[Gt&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[It&&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:o,disabled:et,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:[et?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=ce.has(a),z=C?d("hub.steering"):he.length>1?`${d("hub.queued")} #${f+1}`:d("hub.queued"),xe=T?.find(le=>le.taskId===a)||(m?T?.find(le=>!le.taskId):void 0),Fe=j?.find(le=>le.taskId===a)?.prompt||xe?.prompt||null,Me=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:z}),Me.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Me.slice(0,3).map((le,en)=>e.jsx("button",{type:"button",onClick:()=>kt(le),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:le,alt:"",className:"h-full w-full object-cover"})},`${le}-${en}`)),Me.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",Me.length-3]})]}),Fe&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:Fe})]}),!C&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>h(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:()=>qt(a),disabled:ae.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:[ae.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:yt,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:a=>{pt(a.target.files),a.target.value=""}}),ne.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:ne.map(a=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>Ve(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(),Ct(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))})}),X&&we.length>0&&e.jsxs("div",{ref:Ye,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:we.map((a,f)=>e.jsxs("button",{"data-skill-idx":f,onMouseDown:m=>{m.preventDefault(),u(a)},onMouseEnter:()=>$e(f),className:I("flex flex-col w-full px-3 py-1.5 text-left transition-colors",f===Be?"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:Q,value:B,onChange:a=>p(a.target.value),onPaste:y,onKeyDown:v,onCompositionStart:()=>{Qe.current=!0},onCompositionEnd:()=>{Qe.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:B.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:()=>yt.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:ge,onClick:os,disabled:!K.length,title:K.length?as:void 0,className:I("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",$!=="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(rt,{brand:Xt,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:yn.shortLabel}),nt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(rt,{brand:ls||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:nt.name})]}),Zt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:Jt||void 0,children:Zt})]}),tt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"shrink-0",children:tt.charAt(0).toUpperCase()+tt.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:I("text-fg-5/30 transition-transform duration-200",$!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),$!=="closed"&&U&&fn.createPortal(e.jsxs("div",{id:"cascade-portal",className:"fixed z-[200] w-[300px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in",style:{left:U.left,bottom:U.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:[$!=="agent"&&e.jsx("button",{onClick:()=>{if($==="effort"){const a=P?.capabilities?.modelSwitch!==!1;q(a?"model":"agent")}else q("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($==="agent"?"hub.selectAgent":$==="model"?"hub.selectModel":"hub.selectEffort")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const f=P?.capabilities?.modelSwitch!==!1?["agent","model","effort"]:["agent","effort"],m=f.indexOf($);return f.map((C,z)=>e.jsx("span",{className:I("w-1.5 h-1.5 rounded-full transition-colors",$===C?"bg-primary":z<m?"bg-primary/40":"bg-fg-5/15")},C))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[$==="agent"&&K.filter(a=>a.installed).map(a=>{const f=an(a.agent),m=hs(a.usage),C=m?xs(m):"ok";return e.jsxs(on,{selected:a.agent===(ue||k),onClick:()=>{if(Ge(a.agent),se(a.selectedModel||""),Ce(a.selectedEffort||""),!(a.capabilities?.modelSwitch!==!1)){(tn[a.agent]||[]).length?q("effort"):Yt(a.agent,a.selectedModel||"",null);return}q("model")},children:[e.jsx(rt,{brand:a.agent,size:14}),e.jsx("span",{style:{color:f.color},children:f.label}),m&&e.jsxs("span",{className:I("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)}),$==="model"&&e.jsxs(e.Fragment,{children:[O.map((a,f)=>{const m=f===0&&a.kind==="native",C=f===mt&&a.kind==="profile",z=Te!==void 0?Te:jn,xe=a.kind==="profile"?!!a.profileId&&a.profileId===z:!z&&a.id===(Pe??bt);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(on,{selected:xe,onClick:()=>{const Fe=ue||k;if(se(a.id),at(a.profileId??null),tn[Fe]?.length){q("effort");return}Yt(Fe,a.id,null)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:I("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}`)}),O.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]}),$==="effort"&&ss.map(a=>e.jsx(on,{selected:a===(qe||Mt),onClick:()=>{Ce(a),Yt(ue||k,Pe??bt,a)},children:a.charAt(0).toUpperCase()+a.slice(1)},a))]})]}),document.body),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:Tt,disabled:!kn,className:I("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",kn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:M?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(qs,{source:rs,onClose:()=>{Ve(null),kt(null)},t:d})]})});function qs({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 fn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center bg-black/72 px-4 py-6 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[1024px]",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-[11px] text-white/72",children:[t.name&&e.jsx("span",{className:"truncate font-medium text-white/90",children:t.name}),typeof t.size=="number"&&e.jsx("span",{children:Fn(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await Fs(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 on({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:I("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 Qs(){return function(t){ys(t)}}const bn=[Ns,Qs],zn=t=>/^https?:\/\//.test(t),Ys=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function Xs(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function Js(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 Kn(t){let n=Js(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 cn(t){const n=Kn(t).text;if(!n||zn(n)||Ys(n)&&!n.startsWith("file://"))return!1;const s=Xs(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 vn(t,n){ee.openInEditor(t,void 0,n||void 0).catch(()=>{})}function Hn(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),vn(n,s))}function Zs({locator:t,workdir:n,children:s}){return e.jsx("span",{role:"link",tabIndex:0,title:t,className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",onClick:()=>vn(t,n),onKeyDown:l=>Hn(l,t,n),children:s??t})}function er({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 Tn(t){const n=cn(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 Ht(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&&zn(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&&cn(s)?e.jsx(Zs,{locator:Kn(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 cn(i)?e.jsx("code",{role:"link",tabIndex:0,title:i,className:I("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",Tn(i)),onClick:()=>vn(i,n),onKeyDown:d=>Hn(d,i,n),children:i}):e.jsx("code",{className:I("px-1.5 py-[1px] rounded text-[12px] font-mono border",Tn(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(er,{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})}}Ht();function it(t){return!!t?.steps?.length}function tr(t,n){let s=t;for(const[l,i]of Object.entries(n))s=s.replace(new RegExp(`\\{${l}\\}`,"g"),i);return s}function nr({status:t}){return t==="completed"?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):t==="inProgress"?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-400 animate-pulse"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/25"})}function Vn({plan:t,t:n,className:s}){const[l,i]=r.useState(!1);if(!it(t))return null;const c=t.steps.length,x=t.steps.filter(w=>w.status==="completed").length,d=c>0&&x===c,b=tr(n("hub.planProgress"),{done:String(x),total:String(c)});return e.jsx(ot,{open:l,onToggle:()=>i(w=>!w),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:I("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((w,g)=>{const j=w.status==="completed"?"text-fg-5 line-through decoration-fg-5/40":w.status==="inProgress"?"text-fg-3":"text-fg-4";return e.jsxs("div",{className:"flex items-center gap-2 py-[2px]",children:[e.jsx("span",{className:"shrink-0 flex items-center justify-center w-[10px]",children:e.jsx(nr,{status:w.status})}),e.jsx("span",{className:I("text-[12px] leading-[1.5]",j),children:w.step})]},`${g}:${w.step}`)})})})}function Gn({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:I("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:Fn(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 qn(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
11
+ `).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||it(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function co(t){return qn(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function sr(t){return t.phase!=="done"||!t.error?null:qn(t)?"hub.streamErrored":"hub.streamFailed"}function rr({detail:t,t:n,className:s}){const l=Os(t);if(l==="interrupted")return e.jsxs("div",{className:I("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:I("flex items-start gap-1.5 text-[11px] leading-[1.6]",i.text,s),children:[e.jsx("span",{className:I("mt-[5px] h-1 w-1 rounded-full shrink-0",i.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const or=64;function ir(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 uo({stream:t,t:n,workdir:s}){const l=it(t.plan),[i,c]=r.useState(!1),[x,d]=r.useState(!1),b=r.useRef(null),w=r.useRef(null),g=sr(t),j=r.useMemo(()=>(t.activity||"").split(`
12
+ `).filter(Boolean),[t.activity]),T=t.previewMeta?.toolCalls??[],N=j[j.length-1]||T[T.length-1]?.summary||"";r.useLayoutEffect(()=>{const S=b.current;S&&i&&(S.scrollTop=S.scrollHeight)},[i,t.activity,T.length]),r.useLayoutEffect(()=>{const S=w.current;S&&x&&(S.scrollTop=S.scrollHeight)},[x,t.thinking]);const E=t.subAgents??null,L=ir(t.text,t.phase==="streaming"?or:0),A=r.useMemo(()=>Ht({workdir:s}),[s]),_=r.useMemo(()=>e.jsx(gn,{remarkPlugins:bn,components:A,children:L}),[L,A]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[l&&e.jsx(Vn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),E&&E.length>0&&E.map(S=>e.jsx(Qn,{sub:S,t:n},S.id)),(T.length>0||j.length>0)&&e.jsx(ot,{open:i,onToggle:()=>c(S=>!S),dot:{color:"bg-cyan-400/60",pulse:!0},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[12px] text-fg-4 truncate",children:N}),badge:(T.length||j.length)>1?e.jsx(pn,{children:T.length||j.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:T.length>0?T.map(S=>e.jsx(lr,{call:S},S.id)):j.map((S,B)=>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:S})]},B))})}),t.thinking&&e.jsx(ot,{open:x,onToggle:()=>d(S=>!S),dot:{color:"bg-violet-400/50",pulse:!0},label:n("hub.thinking"),collapsedContent:e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:Dn(t.thinking,3)}),children:e.jsx("div",{ref:w,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:[_,t.phase==="streaming"&&e.jsx(dn,{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((S,B)=>S.kind==="photo"?e.jsx("a",{href:S.url,target:"_blank",rel:"noreferrer",className:"inline-block",children:e.jsx("img",{src:S.url,alt:S.caption||S.fileName,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain hover:opacity-90 transition-opacity"})},B):e.jsx(Gn,{url:S.url,fileName:S.fileName,fileSize:S.fileSize,caption:S.caption},B))}),!t.text&&t.phase==="streaming"&&e.jsx("div",{className:"py-1",children:e.jsx(dn,{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…`})]}),g&&t.error&&e.jsx(rr,{detail:t.error,t:n,className:"pt-0.5"})]})}function lr({call:t}){const[n,s]=r.useState(!1),l=!!(t.input||t.result),i=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:()=>l&&s(c=>!c),className:`flex w-full items-center gap-1.5 py-[2px] text-left min-w-0 ${l?"cursor-pointer hover:bg-white/[0.03] rounded":"cursor-default"}`,title:l?void 0:t.summary,children:[e.jsx("span",{className:`w-1 h-1 rounded-full shrink-0 ${i} ${t.status==="running"?"animate-pulse":""}`}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate flex-1",children:t.summary}),l&&e.jsx("span",{className:`shrink-0 text-[9px] text-fg-5/40 transition-transform ${n?"rotate-90":""}`,children:"▸"})]}),n&&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:t.input}),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:t.result})]})]})}function dn({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 Qn({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 j=new Set,T=[];for(const N of d)j.has(N.name)||(j.add(N.name),T.push(N.name));return T},[d]),w=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",g=t.model?Ft(t.model):null;return e.jsx(ot,{open:s,onToggle:()=>l(j=>!j),dot:{color:c,pulse:x},label:w,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(pn,{children:d.length}):void 0,children:e.jsxs("div",{className:"px-3.5 py-2.5 space-y-1 max-h-[260px] overflow-y-auto",children:[t.description&&e.jsx("div",{className:"mb-1.5 text-[12px] text-fg-3 leading-[1.55]",children:t.description}),d.length===0?e.jsxs("div",{className:"text-[11px] font-mono text-fg-5/50",children:["— ",n("hub.subAgentWaiting")||"waiting for first tool…"]}):d.map(j=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/65 truncate",children:j.summary})]},j.id))]})})}function ar({message:t,t:n,workdir:s}){const{activityBlocks:l,thinkingBlocks:i,planBlocks:c,subAgentBlocks:x,outputBlocks:d,noticeBlocks:b}=Yn(t.blocks),w=[...c].reverse().find(j=>it(j.plan));return l.length>0||x.length>0||!!w?.plan||i.length>0||d.length>0||b.length>0?e.jsxs("div",{className:"space-y-3",children:[l.length>0&&e.jsx(ur,{blocks:l,t:n}),x.map(j=>j.subAgent?e.jsx(Qn,{sub:j.subAgent,t:n},j.toolId||j.subAgent.id):null),w?.plan&&e.jsx(Vn,{plan:w.plan,t:n,className:"max-w-[760px]"}),i.length>0&&e.jsx(xr,{blocks:i,t:n}),d.length>0&&e.jsx(gr,{blocks:d,t:n,workdir:s}),b.length>0&&e.jsx(dr,{blocks:b,t:n})]}):null}function cr(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:l,subAgentBlocks:i,outputBlocks:c,noticeBlocks:x}=Yn(t.blocks);return c.length>0||n.length>0||i.length>0||s.length>0||l.some(d=>it(d.plan))||x.length>0}function Yn(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"&&it(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 dr({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 ur({blocks:t,t:n}){const[s,l]=r.useState(!1),i=t.filter(b=>b.type==="tool_use"),c=i.length,x=i[i.length-1],d=x?Un(x):"";return e.jsx(ot,{open:s,onToggle:()=>l(b=>!b),dot:{color:"bg-cyan-400/60"},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[11.5px] font-mono text-fg-4 truncate",children:d}),badge:c>0?e.jsx(pn,{children:c}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((b,w)=>e.jsx(hr,{block:b},w))})})}function hr({block:t}){const[n,s]=r.useState(!1),l=t.type==="tool_use",i=l?Un(t):zs(t);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&s(c=>!c),className:I("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:I("h-1.5 w-1.5 rounded-full shrink-0",l?"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:i})]}),n&&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:t.content.length>3e3?t.content.slice(0,3e3)+`
15
+ …`:t.content})]})}function xr({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=Dn(c,3);return e.jsx(ot,{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(pr,{scrollRef:i,text:c})})}function pr({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 fr({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:I("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 gr({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),w=r.useMemo(()=>Ht({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(gn,{remarkPlugins:bn,components:w,children:x})}),i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:i.map((g,j)=>e.jsx(fr,{block:g,onLightbox:b,t:n},j))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((g,j)=>e.jsx(Gn,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},j))}),d&&e.jsx(Xn,{src:d,onClose:()=>b(null)})]})}const ho=r.memo(function({turn:n,turnIndex:s,agent:l,meta:i,model:c,effort:x,providerName:d,t:b,workdir:w,onResend:g,onEdit:j,onFork:T}){const N=n.user&&On(n.user.text),E=T&&typeof s=="number"?()=>T(s):void 0,L=r.useMemo(()=>Ht({workdir:w}),[w]),A=!!n.assistant&&cr(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!N&&e.jsx(Jn,{text:n.user.text,blocks:n.user.blocks,t:b,onResend:g,onEdit:j,onFork:E}),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(gn,{remarkPlugins:bn,components:L,children:n.user.text})}),A&&e.jsxs(e.Fragment,{children:[e.jsx(jr,{agent:l,meta:i,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(ar,{message:n.assistant,t:b,workdir:w})})]})]})});function Xn({src:t,onClose:n}){return r.useEffect(()=>{const s=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),fn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm cursor-zoom-out",onClick:n,children:e.jsx("img",{src:t,className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl",onClick:s=>s.stopPropagation()})}),document.body)}const mr=1500,br=16,In=8;function vr(t){const n=t.split(`
20
+ `);return n.length<=In?t:n.slice(0,In).join(`
21
+ `)}function Jn({text:t,blocks:n,t:s,onResend:l,onEdit:i,onFork:c}){const[x,d]=r.useState(!1),[b,w]=r.useState(!1),[g,j]=r.useState(null),T=t?t.split(`
22
+ `).length:0,N=!!t&&(t.length>mr||T>br),[E,L]=r.useState(!1),A=t?N&&!E?vr(t):t:"",_=!!(l||i||c),S=n?.filter(M=>M.type==="image")||[],B=()=>{navigator.clipboard.writeText(t).then(()=>{w(!0),setTimeout(()=>w(!1),1500)}).catch(()=>{})},te=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(T));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[A,N&&!E&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),N&&e.jsx("button",{type:"button",onClick:()=>L(M=>!M),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:E?s("hub.collapse"):te}),S.length>0&&e.jsx("div",{className:I("flex flex-wrap gap-2",t&&"mt-2"),children:S.map((M,G)=>e.jsx("img",{src:M.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(M.content)},G))})]}),g&&e.jsx(Xn,{src:g,onClose:()=>j(null)}),_&&e.jsxs("div",{className:I("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(Rt,{label:s(b?"hub.copied":"hub.copy"),onClick:B,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(Rt,{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(Rt,{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(Rt,{label:s("hub.fork"),onClick:c,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]})})]})]})}function Rt({label:t,onClick:n,children:s}){return e.jsx("button",{onClick:n,title:t,className:"flex items-center justify-center w-7 h-7 rounded border border-fg-6 bg-panel text-fg-4 shadow-sm hover:text-fg-2 hover:border-edge-h hover:bg-panel-h transition-colors",children:s})}function jr({agent:t,meta:n,model:s,effort:l,providerName:i,previewMeta:c,liveStartedAt:x}){const d=c?.contextPercent??null,b=c?.contextUsedTokens??0,w=c?.turnOutputTokens??0,g=d!=null||b>0||w>0,j=x!=null&&x>0,T=c?.providerName??i??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(rt,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||l)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&l?" · ":"",l||""]}),T&&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 ${T} (BYOK), not the agent CLI's native auth.`,children:["via ",T]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:Nr(c),children:[d!=null&&e.jsx(Sr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),b>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",yr(b)]}),w>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Zn(w)]}),j&&e.jsx(wr,{startedAt:x,leadingDot:g})]})]})}function wr({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?"· ":"",kr(l)]})}function kr(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 yr(t){return`${Zn(t)} tok`}function Zn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function Nr(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 Sr({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 Ln(t,n,s){return t==="zh-CN"?n:s}function Cr({open:t,onClose:n,workdir:s}){const l=ye(c=>c.locale),i=s.split("/").pop()||s;return e.jsxs(Ut,{open:t,onClose:n,wide:!0,children:[e.jsx(zt,{title:Ln(l,`${i} — 项目扩展`,`${i} — Project Extensions`),description:Ln(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(Ss,{workdir:s}):null]})}let Mn=Pn(()=>import("./SessionPanel-DRrCVpih.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function un(){return Mn??=Pn(()=>import("./SessionPanel-DRrCVpih.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Mn}const Tr=r.lazy(async()=>({default:(await un()).SessionPanel})),ln=5,Ir=240,Lr=120,Mr=12,Er=900*1e3,V=(t,n)=>`${t}:${n}`;function Ar(t){const n=new Map;for(const d of t)n.set(V(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 w=V(b.agent||d.agent||"",b.sessionId);n.has(w)&&(l.add(V(d.agent||"",d.sessionId)),s.has(w)||s.set(w,[]),s.get(w).push(d))}const i=[],c=new Set,x=(d,b)=>{const w=V(d.agent||"",d.sessionId);if(c.has(w))return;c.add(w),i.push(Object.assign({},d,{__forkDepth:b}));const g=s.get(w);if(g)for(const j of g)x(j,b+1)};for(const d of t){const b=V(d.agent||"",d.sessionId);l.has(b)||x(d,0)}for(const d of t)x(d,0);return i}let Rr=0;function Pt(){return`mk-${Date.now().toString(36)}-${(++Rr).toString(36)}`}function _t(t){try{const n=localStorage.getItem(t);if(n!=null)return n;const s=sessionStorage.getItem(t);if(s!=null){try{localStorage.setItem(t,s),sessionStorage.removeItem(t)}catch{}return s}}catch{}return null}function Wt(t,n){try{localStorage.setItem(t,n)}catch{}}const Pr=[1,2,3,6],hn=6;function _r(t){for(const n of Pr)if(n>=t)return n;return hn}function En(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function Ue(t,n){const s=_r(t);return s>n?s:n}function Wr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Br(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function es(t){switch(t){case"cursor":return"hub.openTargetCursor";case"windsurf":return"hub.openTargetWindsurf";case"finder":return"hub.openTargetFinder";case"default":return"hub.openTargetDefault";default:return"hub.openTargetVsCode"}}const $r=r.memo(function({active:n=!0}){const s=ye(o=>o.locale),l=ye(o=>o.state?.runtimeWorkdir??null),i=r.useMemo(()=>ps(s),[s]),[c,x]=r.useState([]),[d,b]=r.useState({}),[w,g]=r.useState({}),[j,T]=r.useState(!0),[N,E]=r.useState(()=>{const o=_t("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):En()}),[L,A]=r.useState(()=>{const o=_t("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):En()}),[_,S]=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||Pt()}))}}catch{}return[]}),[B,te]=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}),M=r.useCallback(o=>{E(o),Wt("pikiloom-layout-mode",String(o))},[]),G=r.useCallback(o=>{A(o),Wt("pikiloom-layout-floor",String(o))},[]),W=r.useCallback(o=>{S(h=>{const u=typeof o=="function"?o(h):o,p=u.map(({pendingPrompt:v,pendingImageUrls:y,...k})=>k);return Wt("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),D=r.useCallback(o=>{te(h=>{const u=typeof o=="function"?o(h):o;return Wt("pikiloom-active-slot",String(u)),u})},[]),ae=r.useCallback(o=>{M(o),G(o)},[M,G]);r.useEffect(()=>{W(o=>o.length>N?o.slice(0,N):o),D(o=>o>=N?N-1:o)},[N]);const[R,ce]=r.useState(!1),re=r.useRef(N);re.current=N;const Y=r.useRef(L);Y.current=L;const Ne=r.useRef(B);Ne.current=B;const K=r.useRef(_);K.current=_;const wt=r.useRef(-1),fe=_[B]??null,lt=r.useCallback(o=>{if(!o){W([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:Pt()};W(u=>{const p=u.findIndex(y=>y.agent===h.agent&&y.sessionId===h.sessionId);if(p>=0)return D(p),u;if(u.length<re.current){const y=[...u,h];return D(y.length-1),y}if(re.current<hn){const y=[...u,h];return M(Ue(y.length,Y.current)),D(y.length-1),y}const v=[...u];return v[Ne.current]=h,v})},[W,D,M]),[Ke,He]=r.useState(!1),[oe,Ae]=r.useState(null),[ne,Se]=r.useState(""),[Re,Ve]=r.useState("all"),[de,kt]=r.useState({}),[ue,Ge]=r.useState({}),Pe=r.useDeferredValue(ne),se=r.useRef(!1),qe=r.useRef({}),Ce=r.useRef(d);Ce.current=d;const Te=r.useRef(de);Te.current=de;const at=r.useRef(new Set),$=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values($.current))clearTimeout(o)},[]),r.useEffect(()=>{W(o=>{let h=!1;const u=o.map(p=>{const v=ue[p.workdir];if(!v)return p;const y=Nn(v,p.agent,p.sessionId);return y===p.sessionId?p:(h=!0,{...p,sessionId:y})});return h?u:o})},[ue,W]);const q=r.useCallback(async()=>{try{const o=await ee.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((p,v)=>p.path===h[v].path&&p.name===h[v].name)?u:h),se.current=!0}catch{se.current=!0}finally{T(!1)}},[]);r.useEffect(()=>{q()},[q]);const U=r.useCallback(async(o,h={})=>{if(!qe.current[o]){qe.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Ms(o,{force:h.force});r.startTransition(()=>{Ge(p=>{const v=u.promotions||{},y=p[o];return y&&Object.keys(y).length===Object.keys(v).length&&Object.entries(v).every(([k,H])=>y[k]===H)?p:{...p,[o]:v}}),b(p=>{const v=u.sessions||[],y=p[o]||[],k=new Set(v.map(F=>V(F.agent||"",F.sessionId))),H=y.filter(F=>{if(F.runState!=="running")return!1;const P=V(F.agent||"",F.sessionId);if(k.has(P))return!1;const O=Te.current[P];return!(O?.resolvedKey&&O.resolvedKey!==P)});return{...p,[o]:H.length?[...H,...v]:v}})})}catch{h.background||r.startTransition(()=>{b(u=>({...u,[o]:[]}))})}finally{qe.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),ct=r.useRef(l);r.useEffect(()=>{l!==ct.current&&(ct.current=l,!(!l||!se.current)&&q().then(()=>{U(l,{force:!0})}))},[l,q,U]);const Q=r.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(un(),Rs({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Mr}))},[]),Qe=r.useCallback((o,h,u=Lr)=>{const p=`${h}:${V(o.agent||"",o.sessionId)}`,v=$.current[p];v&&clearTimeout(v),$.current[p]=setTimeout(()=>{delete $.current[p],Q(o,h)},u)},[Q]),yt=r.useCallback((o,h)=>{const u=`${h}:${V(o.agent||"",o.sessionId)}`,p=$.current[u];p&&(clearTimeout(p),delete $.current[u])},[]);r.useEffect(()=>{n&&un()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||w[h.path])return;const p=setTimeout(()=>{U(h.path)},u*90);o.push(p)}),()=>{for(const h of o)clearTimeout(h)}},[n,U,w,d,c]);const Vt=r.useRef(new Map);Sn(n&&se.current&&c.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=o.key,u=h?c.filter(y=>(Ce.current[y.path]||[]).some(k=>V(k.agent||"",k.sessionId)===h)):c,p=u.length?u:c,v=Vt.current;for(const y of p)v.has(y.path)&&clearTimeout(v.get(y.path)),v.set(y.path,setTimeout(()=>{v.delete(y.path),U(y.path,{background:!0,force:!0})},300))},[c,U]));const ge=r.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:fs(o,de[V(h,o.sessionId)]||null)},[de]);Sn("stream-update",r.useCallback(o=>{const h=o.key;if(!h)return;const u=gs(h,o.snapshot??null);kt(p=>{if(!u){const P=p[h];return!P||P.phase==="done"?p:{...p,[h]:{...P,phase:"done",updatedAt:Date.now()}}}const v=(P,O)=>!!P&&!!O&&P.phase===O.phase&&P.resolvedKey===O.resolvedKey&&P.sessionId===O.sessionId&&P.incomplete===O.incomplete&&P.error===O.error,y=v(p[h],u),k=u.resolvedKey===h||v(p[u.resolvedKey],{...u,key:u.resolvedKey});if(y&&k)return p;const H=Date.now()-Er,F={};for(const[P,O]of Object.entries(p))O.phase==="done"&&O.updatedAt<H||(F[P]=O);return F[h]=u,u.resolvedKey!==h&&(F[u.resolvedKey]={...u,key:u.resolvedKey}),F})},[])),ms(r.useCallback(()=>{if(!(!n||!se.current||c.length===0))for(const o of c)U(o.path,{background:!0,force:!0})},[n,c,U])),r.useEffect(()=>{if(!n||!se.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)U(u.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,U,c]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const v=`${h.path}:${V(p.agent||"",p.sessionId)}`;if(at.current.has(v))return;const y=setTimeout(()=>{at.current.add(v),Q(p,h.path)},Ir+u*120);o.push(y)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,Q,c]);const dt=r.useCallback(async o=>{try{(await ee.addWorkspace(o)).ok&&(He(!1),await q(),U(o))}catch{}},[q,U]),[me,_e]=r.useState(null),[X,We]=r.useState(!1),[Be,$e]=r.useState(null),Ye=r.useCallback(o=>{_e(o)},[]),ut=r.useCallback(async()=>{const o=me;if(o){We(!0);try{await ee.removeWorkspace(o),x(h=>h.filter(u=>u.path!==o)),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&&M(Ue(u.length,Y.current)),u}),D(0),_e(null)}catch{}finally{We(!1)}}},[me]),ht=r.useCallback(o=>{U(o,{force:!0})},[U]),[Ie,be]=r.useState(null),[Xe,Je]=r.useState(!1),[ve,Le]=r.useState(!1),je=ye(o=>o.toast),[ie,Ze]=r.useState(null),xt=r.useCallback((o,h,u)=>{Ze({anchor:{right:o.right,bottom:o.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:An(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!ie)return;const o=()=>Ze(null),h=u=>{u.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",h)}},[ie]);const we=r.useCallback(o=>{Je(!1),be(o),Ze(null)},[]),Nt=r.useCallback(async()=>{const o=Ie;if(o){Le(!0);try{const h=await ee.deleteSession(o.workdir,o.agent,o.sessionId,Xe);if(!h.ok){const u=h.error?.includes("still running")?i("session.deleteRunningError"):h.error||i("session.deleteFailed");je(u,!1);return}b(u=>{const p=u[o.workdir];if(!p)return u;const v=p.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return v.length===p.length?u:{...u,[o.workdir]:v}}),W(u=>{const p=u.filter(v=>!(v.workdir===o.workdir&&v.agent===o.agent&&v.sessionId===o.sessionId));return p.length!==u.length&&M(Ue(p.length,Y.current)),p}),be(null)}catch(h){je(h?.message||i("session.deleteFailed"),!1)}finally{Le(!1)}}},[Ie,Xe,i,je]),pt=r.useCallback(o=>{W(h=>{let u=!1;const p=h.map(v=>v.mountKey===o&&(v.pendingPrompt!=null||v.pendingImageUrls)?(u=!0,{...v,pendingPrompt:null,pendingImageUrls:void 0}):v);return u?p:h})},[W]),St=r.useCallback((o,h,u)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),b(y=>{const k=y[o.workdir]||[];if(k.some(P=>P.sessionId===o.sessionId&&P.agent===o.agent))return y;const F={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[F,...k]}});const p=wt.current,v={...o,mountKey:Pt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};r.startTransition(()=>{Ae(null),W(y=>{if(p>=y.length)return[...y,v];const k=[...y];return k[p]=v,k}),D(p>=0?p:0)}),U(o.workdir,{background:!0,force:!0})},[U,Q,W,D]),Ct=r.useCallback(o=>{K.current.length>=re.current&&re.current<hn&&M(Ue(re.current+1,Y.current)),Ae(o)},[M]),Tt=r.useCallback(()=>{Ae(null),M(Ue(K.current.length,Y.current))},[M]),It=r.useCallback((o,h)=>{Q(o,h);const u=o.agent||"";K.current.some(p=>p.agent===u&&p.sessionId===o.sessionId)&&M(Ue(K.current.length,Y.current)),Ae(null),r.startTransition(()=>{lt({agent:u,sessionId:o.sessionId,workdir:h})})},[Q,M]),he=r.useCallback((o,h)=>{Q({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}),D(h)):lt({...o,mountKey:Pt()})}),U(o.workdir,{background:!0,force:!0})},[U,Q]),ft=r.useCallback(o=>{let h=o;if(Re==="running"?h=h.filter(u=>Bt(u)==="running"):Re==="review"&&(h=h.filter(u=>Bt(u)==="incomplete")),Pe.trim()){const u=Pe.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},[Pe,Re]),gt=r.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(ge),p=ue[h.path],v=new Map;for(const k of u){const H=V(k.agent||"",k.sessionId),F=de[H],P=p?Nn(p,k.agent||"",k.sessionId):k.sessionId,O=F?.resolvedKey&&F.resolvedKey!==H?F.resolvedKey:P!==k.sessionId?V(k.agent||"",P):H,mt=v.get(O);if(!mt){v.set(O,k);continue}V(mt.agent||"",mt.sessionId)!==O&&H===O&&v.set(O,k)}const y=ft([...v.values()]);o[h.path]=Ar(y)}return o},[c,d,de,ue,ft,ge]),Gt=r.useCallback(o=>{const h=(d[o.workdir]||[]).find(u=>u.sessionId===o.sessionId&&u.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return ge(h)},[ge,d]),qt=r.useMemo(()=>new Set(_.map(o=>V(o.agent,o.sessionId))),[_]),et=fe?V(fe.agent,fe.sessionId):null,Lt=r.useCallback(o=>{W(h=>{const u=h.filter((p,v)=>v!==o);return u.length===0?D(0):Ne.current>=u.length&&D(u.length-1),M(Ue(u.length,Y.current)),u})},[W,D,M]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:ne,onChange:o=>Se(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"}),ne&&e.jsx("button",{onClick:()=>Se(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-fg-5/30 hover:text-fg-4 transition-colors",children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex items-center rounded-lg bg-inset/30 border border-edge/20 p-0.5",children:["all","running","review"].map(o=>e.jsx("button",{onClick:()=>Ve(o),className:I("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",Re===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1),inset_0_1px_0_rgba(255,255,255,0.04)]":"text-fg-5/60 hover:text-fg-4"),children:i(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(pe,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!Ke?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:i("hub.noWorkspaces")}):c.map(o=>e.jsx(Ur,{workspace:o,sessions:gt[o.path]||[],loading:!!w[o.path]||!(o.path in d),isActive:o.path===l,selectedKey:et,openSessionKeys:qt,onSelectSession:It,onNewSession:Ct,onRefresh:ht,onRemove:Ye,onExtensions:$e,onWarmSession:Qe,onCancelWarmSession:yt,onSessionMenuOpen:xt,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:()=>ae(o),className:I("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(Ee,{variant:"ghost",size:"sm",onClick:()=>He(o=>!o),className:"w-full",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),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=oe?_.length<N?_.length:B:-1;return wt.current=o,Array.from({length:N},(h,u)=>{if(oe&&u===o)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-edge bg-panel flex flex-col",style:{boxShadow:"var(--th-card-shadow)"},children:e.jsx(Dr,{workdir:oe,workspaceName:c.find(k=>k.path===oe)?.name||oe.split("/").pop()||"",onSessionCreated:St,onClose:Tt,t:i},oe)},`new-${oe}`);const p=_[u]??null;if(!p)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-dashed border-edge/40 bg-panel/30 flex items-center justify-center",children:e.jsxs("div",{className:"text-center px-4",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"mx-auto text-fg-5/20 mb-2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("div",{className:"text-[12px] text-fg-5/40",children:i("hub.emptySlot")})]})},`empty-${u}`);const v=Gt(p),y=u===B;return e.jsxs("div",{className:I("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>D(u),children:[e.jsxs("div",{className:I("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const k=Bt(v);return e.jsx(Kt,{variant:k==="running"?"ok":k==="waiting"?"info":k==="incomplete"?"warn":"idle",pulse:k==="running"||k==="waiting"})})(),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-0",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-fg-5",children:p.workdir.split("/").pop()||p.workdir}),e.jsx("span",{className:"shrink-0 text-fg-6 text-[10px] mx-1",children:"/"}),e.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-fg-3",children:v.title||v.lastQuestion?.slice(0,60)||(Dt(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:bs(v.createdAt)}),v.runUpdatedAt&&e.jsx("span",{title:i("hub.updated"),children:Rn(v.runUpdatedAt)}),!!v.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),v.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:k=>{k.stopPropagation(),ce(H=>!H)},className:I("p-0.5 rounded transition-colors",R?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title: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:k=>{k.stopPropagation(),Lt(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(Tr,{session:v,workdir:p.workdir,active:n&&y,onSessionChange:k=>he(k,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>pt(p.mountKey)},p.mountKey)})})]},p.mountKey||V(p.agent,p.sessionId))})})()})}),R&&fe&&e.jsx(Kr,{workdir:fe.workdir,onClose:()=>ce(!1),t:i}),e.jsx(Or,{open:Ke,initialPath:l||void 0,onAdd:dt,onClose:()=>He(!1),t:i}),e.jsxs(Ut,{open:!!me,onClose:()=>!X&&_e(null),children:[e.jsx(zt,{title:i("hub.removeWorkspace"),onClose:()=>!X&&_e(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")}),me&&e.jsx("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 font-mono text-[11px] text-fg-4 break-all",children:me}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ee,{variant:"ghost",onClick:()=>_e(null),disabled:X,children:i("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:ut,disabled:X,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(X?"modal.removing":"modal.remove")})]})]}),ie&&(()=>{const h=Math.max(8,Math.min(ie.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ie.anchor.bottom+4,window.innerHeight-60);return e.jsx("div",{className:"fixed z-[60] min-w-[160px] rounded-md border border-edge bg-panel/95 backdrop-blur-md py-1",style:{left:h,top:u,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:p=>p.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>we(ie.target),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-[12px] text-fg-2 hover:bg-panel-h/60 hover:text-red-400 transition-colors",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),e.jsx("path",{d:"M10 11v6"}),e.jsx("path",{d:"M14 11v6"}),e.jsx("path",{d:"M9 6V4a2 2 0 012-2h2a2 2 0 012 2v2"})]}),i("session.delete")]})})})(),e.jsxs(Ut,{open:!!Ie,onClose:()=>!ve&&be(null),children:[e.jsx(zt,{title:i("session.deleteTitle"),onClose:()=>!ve&&be(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("session.deleteHint")}),Ie&&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:Ie.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Ie.title})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:!Xe,onChange:()=>Je(!1),disabled:ve,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:Xe,onChange:()=>Je(!0),disabled:ve,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(Ee,{variant:"ghost",onClick:()=>be(null),disabled:ve,children:i("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:Nt,disabled:ve,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(ve?"session.deleting":"modal.remove")})]})]}),e.jsx(Cr,{open:!!Be,onClose:()=>$e(null),workdir:Be||""})]})});function Or({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(Ut,{open:t,onClose:l,children:[e.jsx(zt,{title:i("hub.addWorkspace"),onClose:l}),e.jsx(ks,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:i}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ee,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:i("hub.add")}),e.jsx(Ee,{variant:"secondary",onClick:l,className:"flex-1",children:i("hub.cancel")})]})]})}function Dr({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:i}){const[c,x]=r.useState(null),[d,b]=r.useState([]),w=r.useRef(null),g=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),T=r.useCallback(()=>{},[]),N=r.useCallback((A,_)=>{x(A||null),w.current=A||null;const S=_||[];b(S),g.current=S},[]),E=r.useCallback(A=>{const _=g.current;g.current=[],s(A,w.current||void 0,_.length?_:void 0)},[s]),L=!!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(Kt,{variant:L?"ok":"idle",pulse:L}),!L&&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:L?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(Jn,{text:c||"",blocks:d.map(A=>({type:"image",content:A})),t:i}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(dn,{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(Gs,{session:j,workdir:t,onStreamQueued:T,onSendStart:N,onSessionChange:E,t:i,streamPhase:null})]})}function Fr({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(vs,{content:n,className:I("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 Ur=r.memo(function({workspace:n,sessions:s,loading:l,isActive:i,selectedKey:c,openSessionKeys:x,onSelectSession:d,onNewSession:b,onRefresh:w,onRemove:g,onExtensions:j,onWarmSession:T,onCancelWarmSession:N,onSessionMenuOpen:E,t:L}){const[A,_]=r.useState(!0),[S,B]=r.useState(ln);r.useEffect(()=>{B(ln)},[s.length]);const te=s.slice(0,S),M=s.length-S,G=n.path,[W,D]=r.useState(null),ae=r.useCallback(()=>{ee.getWorkspaceGit(G).then(R=>D(R.git)).catch(()=>D(null))},[G]);return r.useEffect(()=>{ae()},[ae]),e.jsxs("div",{className:"border-b border-edge/30",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-panel-h/50 transition-colors",onClick:()=>_(R=>!R),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:I("shrink-0 text-fg-5 transition-transform duration-150",A&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[e.jsx("span",{className:I("min-w-0 truncate text-[12px] font-semibold",i?"text-primary":"text-fg-3"),children:n.name}),e.jsx(Fr,{git:W})]}),i&&e.jsx(Kt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:R=>{R.stopPropagation(),b(G)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:L("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:R=>{R.stopPropagation(),j(G)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:L("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:R=>{R.stopPropagation(),w(G),ae()},className:"p-1 rounded text-fg-5 hover:text-fg-2 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),!i&&e.jsx("button",{onClick:R=>{R.stopPropagation(),g(G)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),A&&e.jsx("div",{className:"pb-1",children: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:L("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[te.map(R=>{const ce=V(R.agent||"",R.sessionId),re=R.__forkDepth||0;return e.jsx(zr,{session:R,isSelected:c===ce,isOpen:x?.has(ce)??!1,forkDepth:re,onClick:()=>d(R,G),onWarm:()=>T(R,G),onCancelWarm:()=>N(R,G),onShowMenu:Y=>E(Y,R,G),menuLabel:L("session.openActions")},ce)}),M>0&&e.jsxs("button",{onClick:()=>B(R=>R+ln),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:["+ ",L("hub.nMore").replace("{n}",String(M))]}),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:w}){const g=an(n.agent||""),j=Bt(n),T=An(n).slice(0,500)||(Dt(n.sessionId)?"":n.sessionId.slice(0,16)),N=js(n,T).slice(0,500),E=n.model?Ft(n.model):null,L=i>0?Math.min(i,3)*14:0,A=l?10:12,_=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:I("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:A+L,...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(rt,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),E&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:E}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5 shrink-0 transition-opacity group-hover:opacity-0 group-focus-within:opacity-0",children:[!!n.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5 text-fg-5/50 tabular-nums",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-50",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),n.numTurns]}),e.jsx("span",{className:"tabular-nums",children:Rn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Kt,{variant:j==="running"?"ok":j==="waiting"?"info":j==="incomplete"?"warn":"idle",pulse:j==="running"||j==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:T})]}),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:_,type:"button","aria-label":w,"aria-haspopup":"menu",onMouseDown:S=>{S.stopPropagation()},onClick:S=>{S.stopPropagation(),S.preventDefault(),_.current&&b(_.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"})]})})]})}),Kr=r.memo(function({workdir:n,onClose:s,t:l}){const i=ye(g=>g.state?.hostApp??null),c=ye(g=>g.state?.platform??null),x=ye(g=>g.toast),[d,b]=r.useState(()=>Br(i,c)),w=r.useCallback(async g=>{try{const j=await ee.openInEditor(g,d);if(!j.ok)throw new Error(j.error||`Failed to open ${g}`)}catch(j){x(j?.message||String(j),!1)}},[d,x]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:l("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:l("hub.closePanel"),children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"shrink-0 px-2.5 py-1.5 border-b border-edge/20 flex items-center gap-2",children:[e.jsx(ws,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:l(es(g))})),onChange:g=>{Wr(g)&&b(g)},renderIcon:g=>e.jsx(ts,{target:g,size:14})}),e.jsx(Ee,{size:"sm",variant:"ghost",onClick:()=>w(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(Hr,{basePath:n,openTarget:d,onOpenPath:w,t:l})})]})});function ts({target:t,size:n=16}){return t==="default"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 16 16",className:"shrink-0 text-fg-4",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 3H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-2"}),e.jsx("path",{d:"M9 2h5v5"}),e.jsx("path",{d:"M14 2L7 9"})]}):e.jsx(rt,{brand:t,size:n})}function Hr({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),ee.lsDir(t,!0,n).then(j=>{!g&&j.ok&&x(j.dirs.slice(0,50).map(T=>({entry:T,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||b(!1)}),()=>{g=!0}},[t,n]);const w=r.useCallback(g=>{const j=T=>T.map(N=>N.entry.path===g?N.expanded?{...N,expanded:!1}:N.children===null?(ee.lsDir(g,!0,n).then(E=>{E.ok&&x(L=>xn(L,g,{children:E.dirs.slice(0,50).map(A=>({entry:A,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(E=>xn(E,g,{children:[],loading:!1}))}),{...N,loading:!0,expanded:!0}):{...N,expanded:!0}:N.children?{...N,children:j(N.children)}:N);x(T=>j(T))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(ns,{nodes:c,depth:0,onToggle:w,openTarget:s,onOpenPath:l,t:i})})}function ns({nodes:t,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(Vr,{node:x,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c},x.entry.path))})}function Vr({node:t,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c}){const{entry:x,expanded:d,children:b,loading:w}=t,g=n*14,[j,T]=r.useState(!1),N=c(es(l)),E=c("hub.openWithTarget").replace("{target}",N);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),className:I("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?w?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:I("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),x.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:x.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:L=>{L.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:E,children:e.jsx(ts,{target:l,subtle:!0})}),!x.isDir&&e.jsx(Gr,{filePath:x.path,t:c})]})]}),x.isDir&&d&&b&&b.length>0&&e.jsx(ns,{nodes:b,depth:n+1,onToggle:s,openTarget:l,onOpenPath:i,t:c})]})}function Gr({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:I("p-0.5 rounded transition-colors",s?"text-ok":"text-fg-5 hover:text-fg-3"),title:n("hub.copied"),children:s?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})}function xn(t,n,s){return t.map(l=>l.entry.path===n?{...l,...s}:l.children?{...l,children:xn(l.children,n,s)}:l)}const xo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:$r},Symbol.toStringTag,{value:"Module"}));export{Gs as I,uo as L,rr as R,ho as T,Jn as U,lo as a,qn as b,oo as c,ro as d,dn as e,co as f,jr as g,xo as i,As as l,ao as m,io as n,so as o,Es as p,no 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-CLGovkkw.js";function o({primary:e,secondary:l,tertiary:n}){return s.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e&&s.jsxs(i,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(i,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),n&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:n})]})}function c({children:e,className:l}){return s.jsx(t,{padding:"md",elevation:"flat",className:l,children:e})}export{o as A,c as S};
1
+ import{j as s}from"./react-vendor-C7Sl8SE7.js";import{O as t,m as i,S as a}from"./index-CJm8YsKX.js";function o({primary:e,secondary:l,tertiary:n}){return s.jsxs("div",{className:"flex flex-col gap-2 pt-1 sm:flex-row sm:flex-wrap sm:items-center sm:justify-between",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e&&s.jsxs(i,{tone:"primary",onClick:e.onClick,disabled:e.disabled,children:[e.loading&&s.jsx(a,{}),e.label]}),l&&s.jsx(i,{tone:"secondary",onClick:l.onClick,disabled:l.disabled,children:l.label})]}),n&&s.jsx("div",{className:"text-xs leading-relaxed text-fg-4",children:n})]})}function c({children:e,className:l}){return s.jsx(t,{padding:"md",elevation:"flat",className:l,children:e})}export{o as A,c as S};
@@ -6,7 +6,7 @@
6
6
  <link rel="icon" type="image/png" href="/logo.png">
7
7
  <title>Pikiloom</title>
8
8
  <link href="https://fonts.googleapis.com/css2?family=Geist:wght@400;500;600;700&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
9
- <script type="module" crossorigin src="/assets/index-CLGovkkw.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-CJm8YsKX.js"></script>
10
10
  <link rel="modulepreload" crossorigin href="/assets/react-vendor-C7Sl8SE7.js">
11
11
  <link rel="modulepreload" crossorigin href="/assets/router-DHISdpPk.js">
12
12
  <link rel="stylesheet" crossorigin href="/assets/index-CXIN3nTr.css">
package/dist/bot/bot.js CHANGED
@@ -21,6 +21,7 @@ export { envBool, envString, envInt, shellSplit, whichSync, fmtTokens, fmtUptime
21
21
  export { getHostBatteryData, getHostCpuUsageData, getHostDisplayName, getHostMemoryUsageData } from './host.js';
22
22
  export { readGitStatus, formatGitStatusLine } from '../core/git.js';
23
23
  import { BOT_TIMEOUTS } from '../core/constants.js';
24
+ import { queuedIdsToDeferForSteer } from './queue-steer.js';
24
25
  export const DEFAULT_RUN_TIMEOUT_S = BOT_TIMEOUTS.defaultRunTimeoutS;
25
26
  const MACOS_USER_ACTIVITY_PULSE_INTERVAL_MS = BOT_TIMEOUTS.macosUserActivityPulseInterval;
26
27
  const MACOS_USER_ACTIVITY_PULSE_TIMEOUT_S = BOT_TIMEOUTS.macosUserActivityPulseTimeoutS;
@@ -332,7 +333,7 @@ export class Bot {
332
333
  snap.queuedTaskIds = next.length ? next : undefined;
333
334
  snap.updatedAt = now;
334
335
  }
335
- else {
336
+ else if (snap.taskId === event.taskId) {
336
337
  this.streamSnapshots.delete(sessionKey);
337
338
  this.forgetPromotion(sessionKey);
338
339
  }
@@ -949,9 +950,8 @@ export class Bot {
949
950
  if (t)
950
951
  t.deferForSteer = false;
951
952
  }
952
- const targetIdx = queuedIds.indexOf(targetTaskId);
953
- for (let i = 0; i < targetIdx; i++) {
954
- const t = this.activeTasks.get(queuedIds[i]);
953
+ for (const id of queuedIdsToDeferForSteer(queuedIds, targetTaskId)) {
954
+ const t = this.activeTasks.get(id);
955
955
  if (t && t.status === 'queued' && !t.cancelled)
956
956
  t.deferForSteer = true;
957
957
  }
@@ -0,0 +1,5 @@
1
+ export function queuedIdsToDeferForSteer(queuedIds, targetTaskId) {
2
+ if (!queuedIds.includes(targetTaskId))
3
+ return [];
4
+ return queuedIds.filter(id => id !== targetTaskId);
5
+ }
@@ -21,11 +21,14 @@ function projectInteractions(snap) {
21
21
  currentIndex: it.currentIndex,
22
22
  questions: (it.questions || []).map((q) => ({
23
23
  id: String(q.id),
24
- text: String(q.text ?? q.label ?? ''),
24
+ header: q.header ?? undefined,
25
+ text: String(q.prompt ?? q.text ?? q.label ?? ''),
25
26
  type: q.type,
26
- choices: Array.isArray(q.choices)
27
- ? q.choices.map((c) => ({ label: String(c.label ?? c), description: c.description }))
27
+ choices: Array.isArray(q.options ?? q.choices)
28
+ ? (q.options ?? q.choices).map((c) => ({ label: String(c.label ?? c), description: c.description ?? undefined, value: c.value ?? c.label }))
28
29
  : undefined,
30
+ allowFreeform: q.allowFreeform,
31
+ allowEmpty: q.allowEmpty,
29
32
  })),
30
33
  }));
31
34
  }
@@ -45,6 +48,7 @@ export function projectSnapshot(sessionKey, snap) {
45
48
  return compact({
46
49
  phase: snap.phase,
47
50
  taskId: snap.taskId ?? undefined,
51
+ sessionId: snap.sessionId ?? undefined,
48
52
  agent: agent || undefined,
49
53
  model: snap.model ?? undefined,
50
54
  effort: snap.effort ?? undefined,
@@ -4,11 +4,14 @@ export function emptySnapshot() {
4
4
  }
5
5
  const APPEND_FIELDS = ['text', 'reasoning'];
6
6
  const STRUCT_FIELDS = ['plan', 'toolCalls', 'subAgents', 'usage', 'artifacts', 'interactions', 'queued'];
7
- const SCALAR_FIELDS = ['phase', 'taskId', 'agent', 'model', 'effort', 'prompt', 'activity', 'error', 'incomplete', 'startedAt', 'updatedAt'];
7
+ const SCALAR_FIELDS = ['phase', 'taskId', 'sessionId', 'agent', 'model', 'effort', 'prompt', 'activity', 'error', 'incomplete', 'startedAt', 'updatedAt'];
8
8
  export function diffSnapshot(prev, next) {
9
9
  const patch = {};
10
10
  let set;
11
- const put = (k, v) => { (set ||= {})[k] = v; };
11
+ // Coerce undefined null so a field-clear survives JSON serialization on the
12
+ // wire (JSON.stringify drops undefined-valued keys, which would otherwise leave
13
+ // the receiver's cumulative snapshot holding the previous turn's value).
14
+ const put = (k, v) => { (set ||= {})[k] = v === undefined ? null : v; };
12
15
  for (const f of APPEND_FIELDS) {
13
16
  const a = prev[f] ?? '';
14
17
  const b = next[f] ?? '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pikiloom",
3
- "version": "0.4.29",
3
+ "version": "0.4.30",
4
4
  "description": "Put the world's smartest AI agents in your pocket. Command local Claude & Gemini via IM. | 让最好用的 IM 变成你电脑上的顶级 Agent 控制台",
5
5
  "type": "module",
6
6
  "bin": {
@@ -1 +0,0 @@
1
- import{r as t,j as n}from"./react-vendor-C7Sl8SE7.js";import{c as It,I as bt,S as Ie,m as be,a as j,u as Je,d as vt,g as yt,l as Tt,e as jt,j as Rt,f as wt,s as Nt,Y as Ot}from"./index-CLGovkkw.js";import{l as Et,n as Ze,m as Ct,a as Mt,b as Lt,p as Pt,s as Se,T as qt,R as At,U as et,c as Ft,d as tt,e as Ht,L as Ut,I as Dt}from"./index-DcYOI6rL.js";import{M as nt,a as st}from"./Modal-D_PUi-5O.js";import"./router-DHISdpPk.js";import"./Select-Cp5VXb_2.js";import"./DirBrowser-BINh_7NB.js";import"./markdown-DxQYQFeH.js";import"./ExtensionsTab-CHpd147b.js";function Qt({snapshot:i}){const[r,f]=t.useState(i.currentIndex??0),[R,w]=t.useState(""),[k,p]=t.useState(!1),[V,I]=t.useState(null);t.useEffect(()=>{f(i.currentIndex??0),w(""),I(null)},[i.promptId,i.currentIndex]);const O=i.questions||[],b=O[r]||null,G=O.length,E=!!(b?.options&&b.options.length),m=E?!!b?.allowFreeform:!0,U=u=>{u&&(f(h=>h+1),w(""))},ce=async u=>{if(!k){p(!0),I(null);try{const h=await j.interactionSelectOption(i.promptId,u);if(!h.ok){I(h.error||"Failed to submit selection.");return}U(h.advanced)}catch(h){I(h?.message||"Network error.")}finally{p(!1)}}},C=async()=>{if(k)return;const u=R.trim();if(!u&&!b?.allowEmpty){I("Please enter a response.");return}p(!0),I(null);try{const h=await j.interactionSubmitText(i.promptId,u);if(!h.ok){I(h.error||"Failed to submit answer.");return}U(h.advanced)}catch(h){I(h?.message||"Network error.")}finally{p(!1)}},g=async()=>{if(!k){p(!0),I(null);try{const u=await j.interactionSkip(i.promptId);if(!u.ok){I(u.error||"Failed to skip.");return}U(u.advanced)}catch(u){I(u?.message||"Network error.")}finally{p(!1)}}},D=async()=>{if(!k){p(!0);try{await j.interactionCancel(i.promptId)}catch{}}},J=t.useMemo(()=>{const u=[];return i.hint&&u.push(i.hint),G>1&&u.push(`Question ${r+1} of ${G}`),u.join(" · ")||void 0},[i.hint,r,G]);return n.jsxs(nt,{open:!0,onClose:D,wide:E&&(b?.options?.length||0)>3,children:[n.jsx(st,{title:i.title||"Pikiloom needs your input",description:J,onClose:D}),b?n.jsxs("div",{className:"space-y-4",children:[n.jsxs("div",{children:[n.jsx("div",{className:"text-xs font-medium uppercase tracking-wide text-fg-5",children:b.header||"Question"}),n.jsx("div",{className:"mt-1 whitespace-pre-wrap text-sm leading-relaxed text-fg",children:b.prompt})]}),E&&n.jsx("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-2",children:(b.options||[]).map(u=>n.jsxs("button",{type:"button",disabled:k,onClick:()=>ce(u.value||u.label),className:It("group rounded-lg border border-edge bg-panel-alt px-3 py-2 text-left text-sm transition","hover:border-control-border-h hover:bg-control-h hover:shadow-sm","focus:outline-none focus:ring-2 focus:ring-[var(--th-glow-a)]","disabled:cursor-not-allowed disabled:opacity-50"),children:[n.jsx("div",{className:"font-medium text-fg group-hover:text-fg",children:u.label}),u.description&&n.jsx("div",{className:"mt-0.5 text-xs leading-snug text-fg-4",children:u.description})]},u.value||u.label))}),m&&n.jsx("div",{children:n.jsx(bt,{value:R,onChange:u=>w(u.target.value),onKeyDown:u=>{u.key==="Enter"&&!u.shiftKey&&!k&&(u.preventDefault(),C())},placeholder:E?"Or type a custom answer…":"Type your answer…",disabled:k,autoFocus:!E})}),V&&n.jsx("div",{className:"rounded-md border border-red-300/40 bg-red-500/10 px-3 py-2 text-xs text-red-600",children:V}),n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("div",{className:"text-xs text-fg-5",children:k?n.jsxs("span",{className:"inline-flex items-center gap-2",children:[n.jsx(Ie,{})," Submitting…"]}):n.jsxs("span",{children:["Press ",n.jsx("kbd",{className:"rounded border border-edge bg-panel-alt px-1.5 py-0.5 text-[10px] uppercase",children:"Enter"})," to send"]})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(be,{variant:"ghost",size:"sm",onClick:g,disabled:k,children:"Skip"}),m&&n.jsx(be,{variant:"primary",size:"sm",onClick:C,disabled:k||!R.trim()&&!b.allowEmpty,children:"Submit"})]})]})]}):n.jsxs("div",{className:"py-6 text-center text-sm text-fg-5",children:[n.jsx(Ie,{className:"mr-2 inline-block"})," Waiting for the agent…"]})]})}function _t(i){const r=i.streaming||i.liveStreamPhase==="streaming",f=i.queuedTaskCount>0||i.pendingQueuedCount>0||i.streamPhase==="queued";return r||f}function $t(i){const{pendingTaskId:r,streamTaskId:f,queuedTaskIds:R}=i;return!r||r===f?!1:!!R&&R.includes(r)}const Fe=12,rt=160,Bt=96,Kt=[],Wt=[],zt=[],Yt=20,X=new Map;function Xt(i,r){return`${i}:${r}`}function Vt(i,r){for(X.delete(i),X.set(i,r);X.size>Yt;)X.delete(X.keys().next().value)}const ar=t.memo(function({session:r,workdir:f,active:R=!0,onSessionChange:w,initialPendingPrompt:k,initialPendingImageUrls:p,onPendingPromptConsumed:V}){const I=Je(e=>e.locale),O=Je(e=>e.agentStatus?.agents?.find(s=>s.agent===r.agent)??null),b=O?.selectedEffort??null,G=O?.selectedModel??null,E=O?.byokProviderName??null,m=t.useMemo(()=>vt(I),[I]),U=yt(r.agent||""),ce=Tt(r),C=!!k||!!(p&&p.length),[g,D]=t.useState(null),[J,u]=t.useState(!C),[h,He]=t.useState(!1),[d,P]=t.useState(null),[Z,ee]=t.useState(!1),[Q,ve]=t.useState(null),[lt,Ue]=t.useState(0),[at,ye]=t.useState(null),[_,ie]=t.useState([]),[ot,de]=t.useState([]),[te,Te]=t.useState([]),[x,re]=t.useState(k||null),[M,ne]=t.useState(p||[]),[ut,se]=t.useState(null),$=t.useRef(null);$.current=ut;const De=t.useRef(x);De.current=x;const[Qe,q]=t.useState([]),je=t.useRef([]);je.current=Qe;const le=t.useRef(null),[ct,_e]=t.useState(null),[fe,ae]=t.useState(null),[oe,Re]=t.useState(""),[A,we]=t.useState(!1),it=!!O?.capabilities?.fork,Ne=t.useRef(null),L=t.useRef(p||[]),N=t.useRef(d),$e=t.useRef(Z);N.current=d,$e.current=Z;const Be=t.useRef(_);Be.current=_;const Ke=t.useRef(Q);Ke.current=Q;const F=t.useRef(null),me=t.useRef(null),B=t.useRef(!0),K=t.useRef(!1),ge=t.useRef(null),Oe=t.useRef(!1),W=t.useRef(C),ue=t.useRef(!1),H=t.useRef(!1),Ee=t.useRef(!1),Ce=t.useRef(!1),We=t.useRef({model:null,effort:null}),dt=t.useCallback(e=>{We.current=e},[]);t.useEffect(()=>{Ee.current||!C||(Ee.current=!0,k&&!x&&re(k),p&&p.length&&!M.length&&(ne(p),L.current=p),u(!1),Ue(e=>e+1),V?.())},[C,V]);const y=t.useCallback(()=>{re(null),ne(e=>{for(const s of e)URL.revokeObjectURL(s);return[]}),L.current=[],se(null)},[]),z=t.useCallback(()=>{q(e=>{if(!e.length)return e;for(const s of e)for(const l of s.imageUrls)URL.revokeObjectURL(l);return[]}),le.current=null},[]),ze=t.useCallback((e,s)=>{const l=_t({streaming:$e.current,liveStreamPhase:N.current?.phase??null,streamPhase:Ke.current,queuedTaskCount:Be.current.length,pendingQueuedCount:je.current.length}),a=s||[];if(l){const o=`local-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;le.current=o,q(c=>[...c,{localId:o,taskId:null,prompt:e||"",imageUrls:a}]);return}N.current?.phase==="done"&&P(null);for(const o of L.current)URL.revokeObjectURL(o);le.current=null,re(e||null),ne(a),L.current=a,se(null)},[]),ft=t.useCallback(e=>{const s=le.current;if(s){le.current=null,q(l=>{const a=l.findIndex(c=>c.localId===s);if(a<0)return l;const o=l.slice();return o[a]={...o[a],taskId:e},o});return}se(e)},[]),mt=t.useCallback(async()=>{if(!fe)return;const e=oe.trim();if(e){we(!0);try{const s=await j.forkSession(f,r.agent||"",r.sessionId,fe.atTurn,e,{});if(!s.ok||!s.sessionKey){we(!1);return}const[l,a]=s.sessionKey.split(":");ae(null),Re(""),w?.({agent:l,sessionId:a,workdir:f})}finally{we(!1)}}},[fe,oe,f,r.agent,r.sessionId,w]);Ne.current=mt;const he=t.useCallback(async(e,s={})=>{try{const l=await Et({workdir:f,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:e.turnOffset,turnLimit:e.turnLimit,lastNTurns:e.lastNTurns},{force:s.force});return l.ok?Ze(l):null}catch{return null}},[f,r.agent,r.sessionId]),T=t.useCallback(async({keepOlder:e,force:s=!1,scrollToBottom:l=!1})=>{const a=r.sessionId;if(ge.current===a)return!1;ge.current=a;try{const o=await he({turnOffset:0,turnLimit:Fe},{force:s});if(!o||r.sessionId!==a)return!1;if(l&&(K.current=!0),D(c=>!c||!e?o:Ct(c,o)),u(!1),ue.current&&(ue.current=!1,y()),H.current){const c=H.current;H.current=!1;const S=c!==!0?c.taskId:null;N.current&&(c===!0||N.current.taskId===S)&&P(null)}return!0}finally{ge.current===a&&(ge.current=null)}},[he,y,r.sessionId]),pe=t.useCallback(async()=>{if(!g?.hasOlder||Oe.current)return;const e=F.current;e&&(me.current={scrollHeight:e.scrollHeight,scrollTop:e.scrollTop}),Oe.current=!0,He(!0);try{const s=await he({turnOffset:Math.max(0,g.totalTurns-g.startTurn),turnLimit:Fe});s?D(l=>l?Mt(l,s):s):me.current=null}finally{Oe.current=!1,He(!1)}},[he,g]),xe=t.useRef(null),Y=t.useCallback(e=>{if(e?.sessionId&&e.sessionId!==r.sessionId&&(Ce.current=!0,Me.current=`${r.agent}:${e.sessionId}`,w?.({agent:r.agent||"",sessionId:e.sessionId,workdir:f})),!e){const l=xe.current;ee(!1),l==="streaming"?(ue.current=!0,H.current=!0,T({keepOlder:!0,force:!0,scrollToBottom:B.current})):P(null),W.current&&l!=="streaming"?T({keepOlder:!0,force:!0}):(l==="done"&&(y(),z()),l!==null&&(W.current=!1)),ye(null),ve(null),ie([]),de([]),Te([]),xe.current=null;return}if(ve(e.phase),ye(e.taskId||null),ie(e.queuedTaskIds&&e.queuedTaskIds.length?e.queuedTaskIds:Kt),de(e.queuedTasks&&e.queuedTasks.length?e.queuedTasks:Wt),Te(Array.isArray(e.interactions)&&e.interactions.length?e.interactions:zt),$t({pendingTaskId:$.current,streamTaskId:e.taskId||null,queuedTaskIds:e.queuedTaskIds})){const l=$.current,a=De.current||"",o=L.current;q(c=>c.some(S=>S.taskId===l)?c:[...c,{localId:`demote-${l}`,taskId:l,prompt:a,imageUrls:o}]),re(null),ne([]),L.current=[],se(null),$.current=null}if(e.phase==="streaming"){if(H.current&&N.current&&N.current.taskId!==null&&N.current.taskId!==(e.taskId||null)&&!(e.text||"").trim()||P({taskId:e.taskId||null,phase:"streaming",text:e.text||"",thinking:e.thinking||"",activity:e.activity,plan:e.plan??null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,startedAt:typeof e.startedAt=="number"?e.startedAt:null,error:null,question:e.question??null}),ee(!0),e.taskId&&e.taskId!==$.current){const a=je.current,o=a.findIndex(c=>c.taskId===e.taskId);if(o>=0){const c=a[o];for(const S of L.current)URL.revokeObjectURL(S);re(c.prompt||null),ne(c.imageUrls),L.current=c.imageUrls,se(e.taskId),q(S=>S.filter((kt,St)=>St!==o))}}B.current&&(K.current=!0)}else if(e.phase==="queued")P(null),ee(!1);else if(e.phase==="done"){ee(!1),P(S=>S?{...S,phase:"done",error:e.error??null}:e.error?{taskId:e.taskId||null,phase:"done",text:"",thinking:"",activity:"",plan:null,model:e.model??null,effort:e.effort??null,previewMeta:e.previewMeta??null,subAgents:e.previewMeta?.subAgents??null,generatingImages:e.previewMeta?.generatingImages??0,artifacts:e.artifacts??null,error:e.error}:S);const l=!!e.queuedTaskIds?.length,a=N.current,o=!!a&&Lt(a),c=!!e.incomplete&&o&&!l;xe.current!=="done"&&(l||(ue.current=!0),H.current=c?!1:{taskId:e.taskId||null},T({keepOlder:!0,force:!0,scrollToBottom:B.current})),l||(W.current=!1)}const s=new Set;if(e.taskId&&s.add(e.taskId),Array.isArray(e.queuedTaskIds))for(const l of e.queuedTaskIds)s.add(l);q(l=>{let a=!1;const o=[];for(const c of l)if(!c.taskId||s.has(c.taskId))o.push(c);else{for(const S of c.imageUrls)URL.revokeObjectURL(S);a=!0}return a?o:l}),xe.current=e.phase},[y,z,T,r.sessionId,r.agent,w,f]),Ye=t.useRef(Y);Ye.current=Y;const Xe=t.useCallback(()=>{W.current=!0,Ue(e=>e+1)},[]),gt=t.useCallback(async e=>{try{await j.recallSessionMessage(e),$.current===e&&y(),q(s=>{let l=!1;const a=[];for(const o of s)if(o.taskId===e){for(const c of o.imageUrls)URL.revokeObjectURL(c);l=!0}else a.push(o);return l?a:s}),ie(s=>s.filter(l=>l!==e)),de(s=>s.filter(l=>l.taskId!==e)),ye(s=>s===e?null:s)}catch{}},[y]),ht=t.useCallback(async e=>{try{await j.steerSession(e)}catch{}},[]),pt=t.useCallback(async()=>{try{await j.stopSession(r.agent||"",r.sessionId)}catch{}},[r.agent,r.sessionId]),ke=Xt(r.agent||"",r.sessionId);t.useEffect(()=>{if(Ce.current){Ce.current=!1;let o=!1;return T({keepOlder:!0,force:!0}).finally(()=>{o||u(!1)}),()=>{o=!0}}let e=!1;const s=Pt({workdir:f,agent:r.agent||"",sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:Fe},{allowStale:!0}),l=C&&!Ee.current,a=s?.ok?Ze(s):X.get(ke)||null;return u(l?!1:!a),D(a),P(null),ee(!1),ve(null),ie([]),de([]),Te([]),l||(y(),z(),W.current=!1,ue.current=!1,H.current=!1),B.current=!0,K.current=!0,l||T({keepOlder:!1,force:!0}).finally(()=>{e||u(!1)}),()=>{e=!0}},[T,r.agent,r.sessionId,f,ke,y,z]),t.useEffect(()=>{g&&g.turns.length>0&&Vt(ke,g)},[ke,g]),t.useEffect(()=>{R&&T({keepOlder:!0,force:!0})},[R,T]);const Me=t.useRef(`${r.agent}:${r.sessionId}`);Me.current=`${r.agent}:${r.sessionId}`,jt("stream-update",t.useCallback(e=>{e.key===Me.current&&Y(e.snapshot??null)},[Y])),t.useEffect(()=>{let e=!0;return j.getSessionStreamState(r.agent||"",r.sessionId).then(s=>{e&&Ye.current(s.state)}).catch(()=>{}),()=>{e=!1}},[r.agent,r.sessionId,lt]),Rt(t.useCallback(()=>{j.getSessionStreamState(r.agent||"",r.sessionId).then(e=>{Y(e.state)}).catch(()=>{}),T({keepOlder:!0,force:!0})},[Y,r.agent,r.sessionId,T])),t.useEffect(()=>{!W.current&&ce!=="running"&&!Z&&!d&&!Q&&_.length===0&&(y(),z())},[ce,Z,d,Q,_.length,y,z]),t.useLayoutEffect(()=>{const e=me.current,s=F.current;!e||!s||(me.current=null,s.scrollTop=e.scrollTop+(s.scrollHeight-e.scrollHeight))},[g?.turns.length]),t.useLayoutEffect(()=>{if(!K.current)return;const e=F.current;e&&(K.current=!1,e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{B.current&&(e.scrollTop=e.scrollHeight)}))},[g,d]),t.useLayoutEffect(()=>{if(!x)return;const e=F.current;e&&(e.scrollTop=e.scrollHeight)},[x]),t.useEffect(()=>{if(!g?.hasOlder||J||h)return;const e=F.current;e&&e.scrollHeight<=e.clientHeight+rt&&pe()},[g?.hasOlder,g?.turns.length,pe,J,h]);const xt=t.useCallback(()=>{const e=F.current;if(!e)return;const s=e.scrollHeight-e.scrollTop-e.clientHeight;B.current=s<=Bt,e.scrollTop<=rt&&pe()},[pe]),Le=d?.model||r.model||G||null,Pe=wt(r.agent||"",d?.effort||r.thinkingEffort||b||null,r.workflowEnabled??O?.workflowEnabled)||null,Ve=Le?Nt(Le):null,qe=Ot(r,{streaming:Z,hasLiveStream:!!d,streamPhase:Q,queuedTaskCount:_.length}),v=g?.turns||[],Ae=t.useMemo(()=>{if(!M.length||!v.length)return!1;const e=v[v.length-1];return!e.user||!Se(e.user.text,x)?!1:e.user.blocks.filter(l=>l.type==="image").length<M.length},[v,x,M.length]),Ge=t.useMemo(()=>{let e=v;if(Ae){const S=e[e.length-1];e=[...e.slice(0,-1),{...S,user:null}]}if(!d||!e.length)return e;const s=e[e.length-1];if(!s.assistant)return e;const l=x??(d.question||null),a=(d.text||"").trim(),o=s.assistant.text?.trim()||"";return(l!=null?Se(s.user?.text,l):!!o&&!!a&&(a.startsWith(o)||o.startsWith(a)))?[...e.slice(0,-1),{...s,assistant:null}]:e},[v,d,x,Ae]);return n.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[n.jsx("div",{ref:F,onScroll:xt,className:"flex-1 overflow-y-auto overscroll-contain",children:J&&!x&&!M.length&&!d?n.jsx("div",{className:"flex items-center justify-center py-20",children:n.jsx(Ie,{className:"h-5 w-5 text-fg-4"})}):Ge.length===0&&!x&&!M.length&&!d&&!qe?n.jsx("div",{className:"py-20 text-center text-[13px] text-fg-5",children:m("hub.noMessages")}):n.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[(g?.hasOlder||h)&&n.jsxs("div",{className:"mb-4 flex items-center justify-center gap-2 text-[11px] text-fg-5",children:[h?n.jsx(Ie,{className:"h-3 w-3 text-fg-5"}):n.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/35"}),n.jsx("span",{children:m(h?"hub.loadingOlderTurns":"hub.loadOlderTurnsHint")})]}),r.migratedFrom?.kind==="fork"&&r.migratedFrom.sessionId&&n.jsxs("button",{type:"button",onClick:()=>w?.({agent:r.migratedFrom.agent||r.agent||"",sessionId:r.migratedFrom.sessionId,workdir:f}),className:"mb-4 inline-flex items-center gap-1.5 rounded-md border border-edge bg-panel-alt px-2.5 py-1 text-[11px] text-fg-5 transition hover:border-edge-h hover:text-fg-2",title:`#${r.migratedFrom.sessionId.slice(0,8)}`,children:[n.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[n.jsx("circle",{cx:"6",cy:"6",r:"2"}),n.jsx("circle",{cx:"18",cy:"6",r:"2"}),n.jsx("circle",{cx:"12",cy:"20",r:"2"}),n.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),n.jsx("path",{d:"M12 14v4"})]}),n.jsx("span",{children:m("hub.forkBadge")}),n.jsxs("span",{className:"font-mono",children:["#",r.migratedFrom.sessionId.slice(0,8)]}),typeof r.migratedFrom.forkedAtTurn=="number"&&n.jsxs("span",{className:"text-fg-5/70",children:["· ",m("hub.forkBadgeAt").replace("{turn}",String(r.migratedFrom.forkedAtTurn+1))]})]}),Ge.map((e,s)=>{const l=(g?.startTurn||0)+s;return n.jsx(qt,{turn:e,turnIndex:l,agent:r.agent||"",meta:U,model:Ve,effort:Pe,providerName:E,t:m,workdir:f,onResend:a=>{K.current=!0,ze(a);const o=We.current;j.sendSessionMessage(f,r.agent||"",r.sessionId,a,{model:o.model||Le||void 0,effort:o.effort||Pe||void 0}).then(c=>{c.ok&&Xe()}).catch(()=>{y()})},onEdit:a=>_e(a),onFork:it?a=>{Re(""),ae({atTurn:a})}:void 0},`${g?.startTurn||0}:${s}`)}),qe&&n.jsx("div",{className:"mb-5 animate-in",children:n.jsx(At,{detail:qe,t:m})}),(x||M.length>0)&&(Ae||!(x&&v.length>0&&Se(v[v.length-1]?.user?.text,x)))&&n.jsxs("div",{className:"session-turn",children:[n.jsx(et,{text:x||"",blocks:M.map(e=>({type:"image",content:e})),t:m}),!d&&n.jsx("div",{className:"mt-3 mb-5 animate-in",children:n.jsx(Ft,{className:"text-fg-5"})})]}),d&&tt(d)&&!x&&d.question&&!(v.length>0&&Se(v[v.length-1]?.user?.text,d.question))&&n.jsx("div",{className:"session-turn",children:n.jsx(et,{text:d.question,t:m})}),d&&tt(d)&&n.jsxs("div",{className:"mb-6",children:[n.jsx(Ht,{agent:r.agent||"",meta:U,model:Ve,effort:Pe,providerName:E,previewMeta:d.previewMeta,liveStartedAt:d.phase==="streaming"?d.startedAt??null:null}),n.jsx(Ut,{stream:d,t:m,workdir:f})]}),n.jsx("div",{className:"h-4"})]})}),n.jsx(Dt,{session:r,workdir:f,onStreamQueued:Xe,onSendStart:ze,onSendTaskAssigned:ft,onSessionChange:w,t:m,streamPhase:Q,streamTaskId:at,queuedTaskIds:_,queuedTasks:ot,pendingQueuedSends:Qe,onRecall:gt,onSteer:ht,onStopAll:pt,editDraft:ct,onEditDraftConsumed:()=>_e(null),onSelectionChange:dt}),fe&&n.jsxs(nt,{open:!0,onClose:()=>{A||ae(null)},children:[n.jsx(st,{title:m("hub.forkPromptTitle"),description:m("hub.forkPromptHint"),onClose:()=>{A||ae(null)}}),n.jsx("textarea",{autoFocus:!0,value:oe,disabled:A,onChange:e=>Re(e.target.value),onKeyDown:e=>{e.key==="Enter"&&(e.metaKey||e.ctrlKey)&&oe.trim()&&!A&&(e.preventDefault(),Ne.current?.())},placeholder:m("hub.forkPromptPlaceholder"),className:"w-full min-h-[120px] resize-y rounded-md border border-edge bg-panel-alt px-3 py-2 text-[13px] leading-relaxed text-fg outline-none focus:border-edge-h"}),n.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[n.jsx(be,{variant:"ghost",disabled:A,onClick:()=>ae(null),children:m("modal.cancel")}),n.jsx(be,{variant:"primary",disabled:A||!oe.trim(),onClick:()=>{Ne.current?.()},children:m(A?"hub.forkSubmitting":"hub.forkSubmit")})]})]}),R&&te.length>0&&n.jsx(Qt,{snapshot:te[te.length-1]},te[te.length-1].promptId)]})});export{ar as SessionPanel};