pikiloom 0.4.33 → 0.4.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/dashboard/dist/assets/{AgentTab-C9Z6BUng.js → AgentTab-DvqESwfi.js} +1 -1
  2. package/dashboard/dist/assets/{ConnectionModal-DZEnnbRt.js → ConnectionModal-Dju5ooUi.js} +1 -1
  3. package/dashboard/dist/assets/{DirBrowser-DNd06lse.js → DirBrowser-IIrd6DvC.js} +1 -1
  4. package/dashboard/dist/assets/{ExtensionsTab-BXrPOYT9.js → ExtensionsTab-CJruEOtx.js} +1 -1
  5. package/dashboard/dist/assets/{IMAccessTab-gGQ_84mB.js → IMAccessTab-DrkSXehX.js} +1 -1
  6. package/dashboard/dist/assets/{Modal-DqsmC8u2.js → Modal-enSRVh_K.js} +1 -1
  7. package/dashboard/dist/assets/{Modals-CZuvmOU0.js → Modals-D3KV0p79.js} +1 -1
  8. package/dashboard/dist/assets/{Select-Cvo1Mvn_.js → Select-B5l44VMQ.js} +1 -1
  9. package/dashboard/dist/assets/{SessionPanel-DkvJ4WNu.js → SessionPanel-C9Y7P7yk.js} +1 -1
  10. package/dashboard/dist/assets/{SystemTab-BnxqGrbn.js → SystemTab-CVeipfUR.js} +1 -1
  11. package/dashboard/dist/assets/index-DPBa40VJ.js +3 -0
  12. package/dashboard/dist/assets/index-Mb8DbNHN.js +23 -0
  13. package/dashboard/dist/assets/{shared-BoB6k6CT.js → shared-Ct_RTrnU.js} +1 -1
  14. package/dashboard/dist/index.html +1 -1
  15. package/dist/agent/session.js +1 -1
  16. package/dist/agent/stream.js +20 -6
  17. package/dist/bot/bot.js +3 -2
  18. package/dist/dashboard/routes/sessions.js +8 -2
  19. package/dist/dashboard/session-control.js +11 -0
  20. package/dist/model/injector.js +5 -3
  21. package/package.json +1 -1
  22. package/dashboard/dist/assets/index-CBNgeLIy.js +0 -3
  23. package/dashboard/dist/assets/index-CifA8H7w.js +0 -23
@@ -0,0 +1,23 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-C9Y7P7yk.js","assets/react-vendor-C7Sl8SE7.js","assets/index-DPBa40VJ.js","assets/router-DHISdpPk.js","assets/index-CH_4h4ZM.css","assets/Modal-enSRVh_K.js","assets/Select-B5l44VMQ.js","assets/DirBrowser-IIrd6DvC.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-CJruEOtx.js"])))=>i.map(i=>d[i]);
2
+ import{c as L,a as te,u as Ce,i as Ut,f as Rt,A as fs,s as zt,S as pe,B as ot,g as un,w as gs,b as ms,E as rn,C as mn,d as bs,r as Sn,e as Cn,h as vs,n as js,j as ws,k as Rn,l as Ot,m as Re,D as Vt,o as ks,p as Pn,_ as _n,T as ys,q as Ns}from"./index-DPBa40VJ.js";import{j as e,r as o,a as bn}from"./react-vendor-C7Sl8SE7.js";import{I as Ss}from"./Select-B5l44VMQ.js";import{M as Kt,a as Ht}from"./Modal-enSRVh_K.js";import{D as Cs}from"./DirBrowser-IIrd6DvC.js";import{n as Is,r as Ts,M as vn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Ls}from"./ExtensionsTab-CJruEOtx.js";function Ms({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:L("shrink-0 text-fg-5/40 transition-transform duration-200",t&&"rotate-180",n),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function it({open:t,onToggle:n,dot:s,label:l,preview:i,badge:c,collapsedContent:x,children:d,className:b}){return e.jsxs("div",{className:L("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",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:L("h-[7px] w-[7px] shrink-0 rounded-full",s.color,s.pulse&&"animate-pulse")}),e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:l}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:i}),c,e.jsx(Ms,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Es=5e3,As=15e3,Dt=8,Ft=30,Rs=1,rt=new Map,Se=new Map,on=new Set,Wn=[];let Pt=0;function ln(t){return typeof t=="number"&&Number.isFinite(t)}function He(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 Bn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(He(t,n,s,t===Se?Ft:Dt),s.value)}function $n(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:ln(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:ln(t.turnOffset)?t.turnOffset:void 0,turnLimit:ln(t.turnLimit)?t.turnLimit:void 0}}function jn(t){const n=$n(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function On(){for(;Pt<Rs;){const t=Wn.shift();if(!t)return;Pt+=1,t().finally(()=>{Pt=Math.max(0,Pt-1),On()})}}async function Ps(t,n={}){const s=t;if(!n.force){const c=Bn(rt,s);if(c)return c}const l=rt.get(s);if(l?.promise)return l.promise;const i=te.getWorkspaceSessions(t,n.request).then(c=>(He(rt,s,{value:c,expiresAt:c.ok?Date.now()+Es:0},Dt),c)).finally(()=>{const c=rt.get(s);c?.promise&&He(rt,s,{value:c.value,expiresAt:c.expiresAt},Dt)});return He(rt,s,{value:l?.value,expiresAt:l?.expiresAt??0,promise:i},Dt),i}function _s(t,n={}){const s=jn(t),l=Se.get(s);return l?.value?.ok&&(n.allowStale||l.expiresAt>Date.now())?l.value:null}async function Ws(t,n={}){const s=$n(t),l=jn(s);if(!n.force){const x=Bn(Se,l);if(x?.ok)return x}const i=Se.get(l);if(i?.promise)return i.promise;const c=te.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(He(Se,l,{value:x,expiresAt:x.ok?Date.now()+As:0},Ft),x)).finally(()=>{const x=Se.get(l);x?.promise&&He(Se,l,{value:x.value,expiresAt:x.expiresAt},Ft)});return He(Se,l,{value:i?.value,expiresAt:i?.expiresAt??0,promise:c},Ft),c}function Bs(t){const n=jn(t);_s(t)||on.has(n)||Se.get(n)?.promise||(on.add(n),Wn.push(async()=>{try{await Ws(t)}catch{}finally{on.delete(n)}}),On())}function io(t){const n=t.streaming||t.liveStreamPhase==="streaming",s=t.queuedTaskCount>0||t.pendingQueuedCount>0||t.streamPhase==="queued";return n||s}function lo(t){const{pendingTaskId:n,streamTaskId:s,queuedTaskIds:l}=t;return!n||n===s?!1:!!l&&l.includes(n)}function $s(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 ao(t,n){return t==null||n==null?!0:t===n}function In(t){return(t||"").replace(/\s+/g," ").trim()}function co(t,n){return In(t)===In(n)}function uo(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=Ds(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 ho(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 xo(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 Os(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 Ds(t){const n=[];let s={user:null,assistant:null};for(const l of t)if(l.role==="user"){if(s.assistant&&Dn(l.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=l}else s.assistant?s.assistant=Os(s.assistant,l):s.assistant=l;return(s.user||s.assistant)&&n.push(s),n}const Fs=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"]),Us=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function Dn(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Fs.has(s[1].toLowerCase())?!0:Us.some(l=>t.includes(l))}function Fn(t,n){const s=t.split(`
5
+ `).filter(l=>l.trim());return s.length<=n?s.join(`
6
+ `):s.slice(-n).join(`
7
+ `)}function zs(t){const n=String(t||"").trim().toLowerCase();return n?n.startsWith("interrupted by user")?"interrupted":n.startsWith("timed out")||n.startsWith("stopped before completion")||n.includes("max tokens")?"incomplete":"error":"error"}function an(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function Ks(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function Un(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 Hs(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 Y(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 Vs(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 zn(t){const n=String(t.toolName||"").trim()||"Tool",s=Vs(t.content);if(!s)return n;const l=Y(s.description,120);switch(n){case"Read":{const i=Y(s.file_path||s.path,140);return i?`Read ${i}`:"Read"}case"Edit":{const i=Y(s.file_path||s.path,140);return i?`Edit ${i}`:"Edit"}case"Write":{const i=Y(s.file_path||s.path,140);return i?`Write ${i}`:"Write"}case"Glob":{const i=Y(s.pattern||s.glob,120);return i?`Glob ${i}`:"Glob"}case"Grep":{const i=Y(s.pattern||s.query,120);return i?`Grep ${i}`:"Grep"}case"WebFetch":{const i=Y(s.url,120);return i?`WebFetch ${i}`:"WebFetch"}case"WebSearch":{const i=Y(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=Y(c?.question||s.question,120);return x?`Ask user: ${x}`:"Ask user"}case"Task":{const i=Y(s.description||s.prompt,120);return i?`Task: ${i}`:"Task"}case"Bash":{if(l)return`Bash: ${l}`;const i=Y(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=Y(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=Y(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return x?`${n}: ${x}`:n}}}function Gs(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
8
+ `).map(l=>l.trim()).find(Boolean)||"";return s?Y(s,140):"result"}function qs(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 Qs(t,n){return`${t}:${n}`}function Ys(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 Xs=o.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:C,onRecall:y,onSteer:R,onStopAll:M,editDraft:P,onEditDraftConsumed:B,onSelectionChange:N}){const[D,ne]=o.useState(""),[A,H]=o.useState(!1),[O,F]=o.useState(null),[le,_]=o.useState(()=>new Set),[ae,re]=o.useState(()=>new Set),V=o.useRef({prompt:"",files:[]}),Ie=Ce(a=>a.agentStatus?.agents??null),[z,wt]=o.useState(Ie||[]),[fe,at]=o.useState(""),[Ve,Ge]=o.useState(""),[X,Pe]=o.useState(void 0),[_e,ct]=o.useState(""),[Z,We]=o.useState([]),[ge,qe]=o.useState(null),[Te,kt]=o.useState(null),[ce,oe]=o.useState(null),[Be,Le]=o.useState(null),[dt,Me]=o.useState(null),[se,me]=o.useState(void 0),[T,J]=o.useState("closed"),[q,yt]=o.useState(null),Ee=o.useRef(null),Qe=o.useRef(!1),$e=o.useRef(null),qt=o.useRef(null),de=o.useRef(null),be=o.useRef([]),[ve,Nt]=o.useState([]),[ie,Oe]=o.useState(!1),[Ye,Xe]=o.useState(0),Ze=o.useRef(null),Ae=Ce(a=>a.refreshAgentStatus),[je,Je]=o.useState([]),[De,we]=o.useState([]),[ut,ht]=o.useState({}),ue=o.useCallback(async()=>{try{const[a,f,m]=await Promise.all([fetch("/api/models/providers").then(S=>S.json()),fetch("/api/models/profiles").then(S=>S.json()),fetch("/api/models/agents").then(S=>S.json())]);if(a?.ok&&we(a.providers||[]),f?.ok&&Je(f.profiles||[]),m?.ok){const S={};for(const U of m.bindings||[])S[U.agent]=U.activeProfileId;ht(S)}}catch{}},[]);o.useEffect(()=>{ue()},[ue]),o.useEffect(()=>{Ie?.length&&wt(Ie)},[Ie]),o.useEffect(()=>{be.current=Z},[Z]);const ke=Qs(n.agent||"",n.sessionId),et=o.useRef(ke);et.current=ke,o.useEffect(()=>{const a=jt.get(ke);return a&&(jt.delete(ke),a.text&&ne(a.text),a.files.length&&We(a.files.map(an))),()=>{const f=Ee.current?.value||"",m=be.current.map(S=>S.file);for(const S of be.current)URL.revokeObjectURL(S.previewUrl);f||m.length?jt.set(et.current,{text:f,files:m}):jt.delete(et.current)}},[ke]);const St=o.useRef({agent:n.agent||"",sessionId:n.sessionId});o.useEffect(()=>{const a=St.current,f={agent:n.agent||"",sessionId:n.sessionId};St.current=f,!(a.agent===f.agent&&Ut(a.sessionId)&&!Ut(f.sessionId))&&(at(""),Ge(""),Pe(void 0),ct(""),oe(null),Le(null),Me(null),J("closed"))},[n.agent,n.sessionId]),o.useEffect(()=>{P!=null&&(ne(P),B?.(),requestAnimationFrame(()=>{const a=Ee.current;a&&(a.focus(),a.setSelectionRange(P.length,P.length))}))},[P,B]),o.useEffect(()=>{if(!s)return;let a=!1;return te.getSkills(s).then(f=>{!a&&f.ok&&Nt(f.skills)}).catch(()=>{}),()=>{a=!0}},[s]);const xt=ie?(()=>{const a=D.match(/^\/(\S*)$/);return a?a[1].toLowerCase():null})():null,ye=xt!==null?ve.filter(a=>a.name.toLowerCase().includes(xt)||a.label&&a.label.toLowerCase().includes(xt)):[];o.useEffect(()=>{Xe(0)},[ie,D]),o.useEffect(()=>{if(!ie||!Ze.current)return;const a=Ze.current.querySelector(`[data-skill-idx="${Ye}"]`);a&&a.scrollIntoView({block:"nearest"})},[Ye,ie]),o.useEffect(()=>{if(!ie)return;const a=f=>{Ze.current?.contains(f.target)||Ee.current?.contains(f.target)||Oe(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[ie]),o.useEffect(()=>{if(T==="closed")return;const a=f=>{const m=f.target;de.current?.contains(m)||document.getElementById("cascade-portal")?.contains(m)||(J("closed"),oe(null),Le(null),Me(null))};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[T]),o.useLayoutEffect(()=>{if(T==="closed"||!de.current){yt(null);return}const a=de.current.getBoundingClientRect();yt({left:a.left,bottom:window.innerHeight-a.top+8})},[T]);const Ct=g&&g.length?g[0]:null;o.useEffect(()=>{O&&(Ct||b!==null&&b!=="queued")&&F(null)},[b,O,Ct]),o.useEffect(()=>{const a=Ee.current;a&&(a.style.height="auto",a.style.height=Math.min(a.scrollHeight,200)+"px")},[D]);const pt=o.useCallback(a=>{const f=Array.from(a||[]).filter(m=>m.type.startsWith("image/"));f.length&&We(m=>[...m,...f.map(an)])},[]),It=o.useCallback(()=>{qe(null),We(a=>(Ks(a),[]))},[]),Tt=o.useCallback(a=>{We(f=>{const m=f.find(S=>S.id===a);return m&&URL.revokeObjectURL(m.previewUrl),f.filter(S=>S.id!==a)}),qe(f=>f===a?null:f)},[]),Lt=o.useCallback(()=>{const a=D.trim(),f=Z.map(Q=>Q.file);if(!a&&f.length===0||A)return;const m=fe||n.agent||z.find(Q=>Q.isDefault)?.agent||"";if(!m)return;const S=z.find(Q=>Q.agent===m)||null,U=!!n.agent&&m===n.agent,xe=(Ve||U&&n.model||""||S?.selectedModel||"").trim()||null,ze=X!==void 0?X:U&&n.model?n.profileId??null:void 0,st=m==="gemini"?null:(_e||(U?Rt(m,n.thinkingEffort,n.workflowEnabled):"")||Rt(m,S?.selectedEffort,S?.workflowEnabled)||"").trim()||null,ee=m!==n.agent,sn=ee?"":n.sessionId,hs=ee&&n.agent?n.agent:null,xs=ee&&n.sessionId?n.sessionId:null;H(!0),V.current={prompt:a,files:f},ne(""),jt.delete(et.current);const ps=f.length?f.map(Q=>URL.createObjectURL(Q)):void 0;It(),i(a,ps),l(),te.sendSessionMessage(s,m,sn,a,{attachments:f,model:xe,profileId:ze,effort:st,previousAgent:hs,previousSessionId:xs}).then(Q=>{if(Q.taskId&&(F(Q.taskId),c?.(Q.taskId)),!Q.ok)return;const vt=typeof Q.sessionKey=="string"?qs(Q.sessionKey):null;vt&&(vt.agent!==n.agent||vt.sessionId!==n.sessionId)&&vt&&x?.({...vt,workdir:s})}).catch(()=>{}).finally(()=>H(!1))},[z,It,Z,D,i,c,x,l,fe,_e,Ve,X,A,n.agent,n.sessionId,n.model,n.profileId,s]),ft=b==="streaming",he=$s({queuedTaskIds:g,streamPhase:b,streamTaskId:w,localTaskId:O}),Mt=he[he.length-1]||null,gt=he.length>0,Qt=gt||ft;o.useEffect(()=>{const a=f=>he.includes(f)||f===w;_(f=>{let m=!1;const S=new Set;for(const U of f)a(U)?S.add(U):m=!0;return m?S:f}),re(f=>{let m=!1;const S=new Set;for(const U of f)a(U)?S.add(U):m=!0;return m?S:f})},[he,w]),o.useEffect(()=>{!gt&&V.current.files.length&&(V.current={prompt:"",files:[]})},[gt]);const Yt=o.useCallback(a=>{if(!le.has(a)){if(_(f=>{const m=new Set(f);return m.add(a),m}),a===Mt){const f=V.current;f.prompt&&ne(f.prompt),f.files.length&&We(f.files.map(an)),V.current={prompt:"",files:[]}}y?.(a),a===O&&F(null)}},[le,Mt,O,y]),[r,h]=o.useState(!1),u=o.useCallback(async()=>{if(!(r||!M)){h(!0);try{await M()}finally{h(!1)}}},[r,M]),p=o.useCallback(a=>{ae.has(a)||(re(f=>{const m=new Set(f);return m.add(a),m}),R?.(a),a===O&&F(null))},[ae,O,R]),v=o.useCallback(a=>{ne(`/${a.name} `),Oe(!1),requestAnimationFrame(()=>{const f=Ee.current;f&&(f.focus(),f.setSelectionRange(f.value.length,f.value.length))})},[]),k=o.useCallback(a=>{ne(a);const f=/^\/\S*$/.test(a)&&ve.length>0;Oe(f)},[ve.length]),I=a=>{if(ie&&ye.length>0){if(a.key==="ArrowDown"){a.preventDefault(),Xe(f=>(f+1)%ye.length);return}if(a.key==="ArrowUp"){a.preventDefault(),Xe(f=>(f-1+ye.length)%ye.length);return}if(a.key==="Tab"||a.key==="Enter"&&!a.shiftKey&&!Qe.current){a.preventDefault(),v(ye[Ye]);return}if(a.key==="Escape"){a.preventDefault(),Oe(!1);return}}a.key==="Enter"&&!a.shiftKey&&!Qe.current&&(a.preventDefault(),Lt())},G=o.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]),E=fe||n.agent||z.find(a=>a.isDefault)?.agent||z.find(a=>a.installed)?.agent||z[0]?.agent||"",W=z.find(a=>a.agent===E)||null,$=ce||E,Ne=z.find(a=>a.agent===$)||W,mt=o.useMemo(()=>{if(!Ne)return[];const a=[];for(const m of Ne.models||[])a.push({id:m.id,label:m.id,kind:"native",description:m.alias&&m.alias.toLowerCase()!==m.id.toLowerCase()?m.alias:void 0});const f=new Set(fs[$]||[]);for(const m of je){const S=De.find(xe=>xe.id===m.providerId);if(!S||!f.has(S.kind))continue;const U=m.name.trim().toLowerCase()!==m.modelId.trim().toLowerCase();a.push({id:m.modelId,label:m.name,kind:"profile",profileId:m.id,description:U?`${S.name} · ${m.modelId}`:S.name})}return a},[Ne,$,je,De]),rs=o.useMemo(()=>mt.findIndex(a=>a.kind==="profile"),[mt]),os=ut[$]||null,Xt=!!n.agent&&E===n.agent,Et=X!==void 0?X:Xt?n.profileId??null:void 0,bt=Ve||Xt&&n.model||""||W?.selectedModel||"",At=E==="gemini"?"":_e||(Xt?Rt(E,n.thinkingEffort,n.workflowEnabled):"")||Rt(E,W?.selectedEffort,W?.workflowEnabled)||"";o.useEffect(()=>{N?.({model:bt||null,effort:At||null})},[bt,At,N]);const is=rn[$]||[],Fe=ge&&Z.find(a=>a.id===ge)||null,ls=Fe?{key:Fe.id,url:Fe.previewUrl,name:Fe.file.name,size:Fe.file.size,file:Fe.file,onRemove:()=>Tt(Fe.id)}:Te?{key:Te,url:Te}:null,yn=(!!D.trim()||Z.length>0)&&!A&&!!E,Zt=()=>{oe(null),Le(null),Me(null),me(void 0)},Jt=o.useCallback((a,f,m)=>{const S=a==="gemini"?"":m||"";at(a),Ge(f),se!==void 0&&Pe(se),ct(S),Zt(),J("closed")},[se]),as=()=>{T==="closed"?(Zt(),Ae(),ue(),J("agent")):(Zt(),J("closed"))},en=ce||E,Nn=un(en),tn=Be??bt,tt=dt??At,cs=tn?zt(tn):"",Ue=(()=>{const a=!ce&&Et!==void 0?Et:ut[en]??null;return a?je.find(f=>f.id===a)??null:null})(),nt=Ue?De.find(a=>a.id===Ue.providerId)??null:null,ds=nt?Ys(nt):null,nn=Ue?Ue.name.trim().toLowerCase()!==Ue.modelId.trim().toLowerCase()?Ue.name:zt(Ue.modelId):cs,us=[Nn.shortLabel,nt?nt.name:null,nn||null,tt?tt.charAt(0).toUpperCase()+tt.slice(1):null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:qt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[Qt&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[ft&&e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-primary/20 bg-primary/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx(pe,{className:"h-3 w-3 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-[12px] font-medium text-fg-3 truncate",children:d("hub.running")}),e.jsxs("button",{onClick:u,disabled:r,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:[r?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,S=ae.has(a),U=S?d("hub.steering"):he.length>1?`${d("hub.queued")} #${f+1}`:d("hub.queued"),xe=C?.find(ee=>ee.taskId===a)||(m?C?.find(ee=>!ee.taskId):void 0),ze=j?.find(ee=>ee.taskId===a)?.prompt||xe?.prompt||null,st=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:[S?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:U}),st.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[st.slice(0,3).map((ee,sn)=>e.jsx("button",{type:"button",onClick:()=>kt(ee),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:ee,alt:"",className:"h-full w-full object-cover"})},`${ee}-${sn}`)),st.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",st.length-3]})]}),ze&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:ze})]}),!S&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>p(a),title:d("hub.steerHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-blue-400 hover:bg-blue-400/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),d("hub.steer")]}),e.jsxs("button",{onClick:()=>Yt(a),disabled:le.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:[le.has(a)?e.jsx(pe,{className:"h-2.5 w-2.5"}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]}),d("hub.recall")]})]})]},a)})]}),e.jsxs("div",{className:"relative rounded-xl border border-edge/40 bg-panel shadow-sm transition-[border-color,box-shadow] duration-200 focus-within:border-fg-5/40 focus-within:shadow-md",children:[e.jsx("input",{ref:$e,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:a=>{pt(a.target.files),a.target.value=""}}),Z.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:Z.map(a=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>qe(a.id),title:d("hub.previewImage"),className:"group relative h-[72px] w-[72px] overflow-hidden rounded-lg border border-edge/30 bg-panel-alt/30",children:[e.jsx("img",{src:a.previewUrl,alt:a.file.name,className:"h-full w-full object-cover transition-transform duration-200 group-hover:scale-[1.03]"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent px-1.5 pb-1 pt-3 text-left",children:e.jsx("div",{className:"truncate text-[8px] font-medium text-white/90 leading-tight",children:a.file.name})})]}),e.jsx("button",{type:"button",onClick:f=>{f.stopPropagation(),Tt(a.id)},title:d("hub.removeImage"),className:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-black/65 text-white/75 transition-colors hover:bg-black/80 hover:text-white",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]},a.id))})}),ie&&ye.length>0&&e.jsxs("div",{ref:Ze,className:"absolute bottom-full left-0 right-0 mb-1.5 z-50 max-h-[200px] overflow-y-auto rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg animate-in",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-edge/20",children:e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d("hub.skills")})}),e.jsx("div",{className:"py-1",children:ye.map((a,f)=>e.jsxs("button",{"data-skill-idx":f,onMouseDown:m=>{m.preventDefault(),v(a)},onMouseEnter:()=>Xe(f),className:L("flex flex-col w-full px-3 py-1.5 text-left transition-colors",f===Ye?"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:Ee,value:D,onChange:a=>k(a.target.value),onPaste:G,onKeyDown:I,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:D.split(`
9
+ `).length>6?"auto":"hidden"}}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>$e.current?.click(),title:d("hub.addImages"),className:"flex h-7 w-7 items-center justify-center rounded-lg text-fg-5/50 transition-colors hover:bg-panel-h/60 hover:text-fg-3",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})}),e.jsxs("button",{ref:de,onClick:as,disabled:!z.length,title:z.length?us:void 0,className:L("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",T!=="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:[z.length?e.jsx(ot,{brand:en,size:12}):e.jsx(pe,{className:"h-3 w-3"}),z.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:Nn.shortLabel}),nt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(ot,{brand:ds||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:nt.name})]}),nn&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:tn||void 0,children:nn})]}),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:L("text-fg-5/30 transition-transform duration-200",T!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),T!=="closed"&&q&&bn.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:q.left,bottom:q.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:[T!=="agent"&&e.jsx("button",{onClick:()=>{if(T==="effort"){const a=Ne?.capabilities?.modelSwitch!==!1;J(a?"model":"agent")}else J("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(T==="agent"?"hub.selectAgent":T==="model"?"hub.selectModel":"hub.selectEffort")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const f=Ne?.capabilities?.modelSwitch!==!1?["agent","model","effort"]:["agent","effort"],m=f.indexOf(T);return f.map((S,U)=>e.jsx("span",{className:L("w-1.5 h-1.5 rounded-full transition-colors",T===S?"bg-primary":U<m?"bg-primary/40":"bg-fg-5/15")},S))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[T==="agent"&&z.filter(a=>a.installed).map(a=>{const f=un(a.agent),m=gs(a.usage),S=m?ms(m):"ok";return e.jsxs(cn,{selected:a.agent===(ce||E),onClick:()=>{if(oe(a.agent),Le(a.selectedModel||""),Me(a.selectedEffort||""),!(a.capabilities?.modelSwitch!==!1)){(rn[a.agent]||[]).length?J("effort"):Jt(a.agent,a.selectedModel||"",null);return}J("model")},children:[e.jsx(ot,{brand:a.agent,size:14}),e.jsx("span",{style:{color:f.color},children:f.label}),m&&e.jsxs("span",{className:L("ml-auto font-mono text-[10px]",S==="err"?"text-err":S==="warn"?"text-warn":"text-fg-5"),children:[m.label," ",Math.round(m.usedPercent??0),"%"]})]},a.agent)}),T==="model"&&e.jsxs(e.Fragment,{children:[mt.map((a,f)=>{const m=f===0&&a.kind==="native",S=f===rs&&a.kind==="profile",U=se!==void 0?se:$===E&&Et!==void 0?Et:os,xe=a.kind==="profile"?!!a.profileId&&a.profileId===U:!U&&a.id===(Be??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")}),S&&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(cn,{selected:xe,onClick:()=>{const ze=ce||E;if(Le(a.id),me(a.profileId??null),rn[ze]?.length){J("effort");return}Jt(ze,a.id,null)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:L("truncate text-[11.5px]",a.kind==="native"&&"font-mono text-[11px]"),title:a.id,children:a.label}),a.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:a.description})]})})]},`${a.kind}:${a.profileId||a.id}`)}),mt.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]}),T==="effort"&&is.map(a=>e.jsx(cn,{selected:a===(dt||At),onClick:()=>{Me(a),Jt(ce||E,Be??bt,a)},children:a.charAt(0).toUpperCase()+a.slice(1)},a))]})]}),document.body),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:Lt,disabled:!yn,className:L("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",yn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:A?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(Zs,{source:ls,onClose:()=>{qe(null),kt(null)},t:d})]})});function Zs({source:t,onClose:n,t:s}){const[l,i]=o.useState(!1);if(o.useEffect(()=>{i(!1)},[t?.key]),o.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 bn.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:Un(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await Hs(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 cn({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:L("flex items-center gap-2 w-full px-3 py-2 text-[12px] text-left transition-colors",t?"text-fg bg-panel-h font-medium":"text-fg-3 hover:bg-panel-alt/50 hover:text-fg-2"),children:[s,t&&e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"ml-auto text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),!t&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"ml-auto text-fg-5/20",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})})]})}function Js(){return function(t){Is(t)}}const wn=[Ts,Js],Kn=t=>/^https?:\/\//.test(t),er=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function tr(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function nr(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 Hn(t){let n=nr(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 hn(t){const n=Hn(t).text;if(!n||Kn(n)||er(n)&&!n.startsWith("file://"))return!1;const s=tr(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 kn(t,n){te.openInEditor(t,void 0,n||void 0).catch(()=>{})}function Vn(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),kn(n,s))}function sr({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:()=>kn(t,n),onKeyDown:l=>Vn(l,t,n),children:s??t})}function rr({text:t}){const[n,s]=o.useState(!1),l=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:l,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function Tn(t){const n=hn(t),s=/^(npm |npx |git |python|pip |yarn |pnpm |cargo |go |make )/.test(t);return n?"bg-blue-500/8 border-blue-400/12 text-blue-300/90":s?"bg-amber-500/8 border-amber-400/10 text-amber-300/80":"bg-[rgba(255,255,255,0.06)] border-edge/20 text-fg-3"}function Gt(t={}){const n=t.workdir||null;return{h1:({children:s})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:s}),h2:({children:s})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:s}),h3:({children:s})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:s}),p:({children:s})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:s}),strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-fg",children:s}),em:({children:s})=>e.jsx("em",{className:"italic text-fg-3",children:s}),a:({href:s,children:l})=>s&&Kn(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&&hn(s)?e.jsx(sr,{locator:Hn(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 hn(i)?e.jsx("code",{role:"link",tabIndex:0,title:i,className:L("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",Tn(i)),onClick:()=>kn(i,n),onKeyDown:d=>Vn(d,i,n),children:i}):e.jsx("code",{className:L("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(rr,{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})}}Gt();function lt(t){return!!t?.steps?.length}function or(t,n){let s=t;for(const[l,i]of Object.entries(n))s=s.replace(new RegExp(`\\{${l}\\}`,"g"),i);return s}function ir({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 Gn({plan:t,t:n,className:s}){const[l,i]=o.useState(!1);if(!lt(t))return null;const c=t.steps.length,x=t.steps.filter(w=>w.status==="completed").length,d=c>0&&x===c,b=or(n("hub.planProgress"),{done:String(x),total:String(c)});return e.jsx(it,{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:L("rounded-md border px-1.5 py-0.5 text-[10px] font-mono",d?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(d?"hub.planDone":"hub.planInProgress")}),className:s,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-1",children:t.steps.map((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(ir,{status:w.status})}),e.jsx("span",{className:L("text-[12px] leading-[1.5]",j),children:w.step})]},`${g}:${w.step}`)})})})}function qn({url:t,fileName:n,fileSize:s,caption:l}){return e.jsxs("div",{className:"flex flex-col gap-1 max-w-[340px]",children:[e.jsxs("a",{href:t,download:n,target:"_blank",rel:"noreferrer",title:l||n,className:L("group inline-flex items-center gap-2.5 rounded-md no-underline","border border-fg-6/40 bg-fg-6/[0.05] px-3 py-2","hover:bg-fg-6/[0.12] hover:border-fg-6/60 transition-colors"),children:[e.jsx("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded bg-fg-6/10 text-fg-3",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12.5px] font-medium text-fg-2",children:n}),typeof s=="number"&&s>0&&e.jsx("span",{className:"block text-[11px] text-fg-5/70",children:Un(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||lt(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function po(t){return Qn(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function lr(t){return t.phase!=="done"||!t.error?null:Qn(t)?"hub.streamErrored":"hub.streamFailed"}function ar({detail:t,t:n,className:s}){const l=zs(t);if(l==="interrupted")return e.jsxs("div",{className:L("flex items-center gap-1.5 text-[11px] text-fg-5/55",s),children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-[2px] bg-fg-5/45 shrink-0"}),e.jsx("span",{children:n("hub.turnStopped")})]});const 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:L("flex items-start gap-1.5 text-[11px] leading-[1.6]",i.text,s),children:[e.jsx("span",{className:L("mt-[5px] h-1 w-1 rounded-full shrink-0",i.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const cr=64;function dr(t,n){const[s,l]=o.useState(t),i=o.useRef(0),c=o.useRef(null);return o.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 fo({stream:t,t:n,workdir:s}){const l=lt(t.plan),[i,c]=o.useState(!1),[x,d]=o.useState(!1),b=o.useRef(null),w=o.useRef(null),g=lr(t),j=o.useMemo(()=>(t.activity||"").split(`
12
+ `).filter(Boolean),[t.activity]),C=t.previewMeta?.toolCalls??[],y=j[j.length-1]||C[C.length-1]?.summary||"";o.useLayoutEffect(()=>{const N=b.current;N&&i&&(N.scrollTop=N.scrollHeight)},[i,t.activity,C.length]),o.useLayoutEffect(()=>{const N=w.current;N&&x&&(N.scrollTop=N.scrollHeight)},[x,t.thinking]);const R=t.subAgents??null,M=dr(t.text,t.phase==="streaming"?cr:0),P=o.useMemo(()=>Gt({workdir:s}),[s]),B=o.useMemo(()=>e.jsx(vn,{remarkPlugins:wn,components:P,children:M}),[M,P]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[l&&e.jsx(Gn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),R&&R.length>0&&R.map(N=>e.jsx(Yn,{sub:N,t:n},N.id)),(C.length>0||j.length>0)&&e.jsx(it,{open:i,onToggle:()=>c(N=>!N),dot:{color:"bg-cyan-400/60",pulse:!0},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[12px] text-fg-4 truncate",children:y}),badge:(C.length||j.length)>1?e.jsx(mn,{children:C.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:C.length>0?C.map(N=>e.jsx(ur,{call:N},N.id)):j.map((N,D)=>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:N})]},D))})}),t.thinking&&e.jsx(it,{open:x,onToggle:()=>d(N=>!N),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:Fn(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:[B,t.phase==="streaming"&&e.jsx(xn,{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((N,D)=>N.kind==="photo"?e.jsx("a",{href:N.url,target:"_blank",rel:"noreferrer",className:"inline-block",children:e.jsx("img",{src:N.url,alt:N.caption||N.fileName,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain hover:opacity-90 transition-opacity"})},D):e.jsx(qn,{url:N.url,fileName:N.fileName,fileSize:N.fileSize,caption:N.caption},D))}),!t.text&&t.phase==="streaming"&&e.jsx("div",{className:"py-1",children:e.jsx(xn,{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(ar,{detail:t.error,t:n,className:"pt-0.5"})]})}function ur({call:t}){const[n,s]=o.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 xn({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 Yn({sub:t,t:n}){const[s,l]=o.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=o.useMemo(()=>{const j=new Set,C=[];for(const y of d)j.has(y.name)||(j.add(y.name),C.push(y.name));return C},[d]),w=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",g=t.model?zt(t.model):null;return e.jsx(it,{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(mn,{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 hr({message:t,t:n,workdir:s}){const{activityBlocks:l,thinkingBlocks:i,planBlocks:c,subAgentBlocks:x,outputBlocks:d,noticeBlocks:b}=Xn(t.blocks),w=[...c].reverse().find(j=>lt(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(fr,{blocks:l,t:n}),x.map(j=>j.subAgent?e.jsx(Yn,{sub:j.subAgent,t:n},j.toolId||j.subAgent.id):null),w?.plan&&e.jsx(Gn,{plan:w.plan,t:n,className:"max-w-[760px]"}),i.length>0&&e.jsx(mr,{blocks:i,t:n}),d.length>0&&e.jsx(jr,{blocks:d,t:n,workdir:s}),b.length>0&&e.jsx(pr,{blocks:b,t:n})]}):null}function xr(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:l,subAgentBlocks:i,outputBlocks:c,noticeBlocks:x}=Xn(t.blocks);return c.length>0||n.length>0||i.length>0||s.length>0||l.some(d=>lt(d.plan))||x.length>0}function Xn(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"&&lt(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 pr({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 fr({blocks:t,t:n}){const[s,l]=o.useState(!1),i=t.filter(b=>b.type==="tool_use"),c=i.length,x=i[i.length-1],d=x?zn(x):"";return e.jsx(it,{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(mn,{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(gr,{block:b},w))})})}function gr({block:t}){const[n,s]=o.useState(!1),l=t.type==="tool_use",i=l?zn(t):Gs(t);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&s(c=>!c),className:L("flex items-center gap-2 py-[3px] w-full text-left group rounded-sm transition-colors",t.content&&"hover:bg-panel-h/30"),children:[e.jsx("span",{className:L("h-1.5 w-1.5 rounded-full shrink-0",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 mr({blocks:t,t:n}){const[s,l]=o.useState(!1),i=o.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
16
+
17
+ `).trim();if(!c)return null;const x=Fn(c,3);return e.jsx(it,{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(br,{scrollRef:i,text:c})})}function br({scrollRef:t,text:n}){return o.useLayoutEffect(()=>{const s=t.current;s&&(s.scrollTop=s.scrollHeight)},[t]),e.jsx("div",{ref:t,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[320px] overflow-y-auto",children:n})}function vr({block:t,onLightbox:n,t:s}){const l=t.imageCaption?.trim()||"",i=t.imageCaptionKind==="prompt",[c,x]=o.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:l||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),l&&(i?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>x(d=>!d),"aria-expanded":c,className:L("self-start inline-flex items-center gap-1 px-2 py-[3px] rounded-md","text-[11px] font-medium tracking-wide","border border-fg-6/40 bg-fg-6/[0.06] text-fg-3","hover:bg-fg-6/[0.12] hover:text-fg-2 hover:border-fg-6/60","transition-colors"),title:s(c?"hub.imagePromptHide":"hub.imagePromptShow"),children:[e.jsx("span",{"aria-hidden":!0,className:"text-[9px] leading-none",children:c?"▾":"▸"}),e.jsx("span",{children:s("hub.imagePrompt")})]}),c&&e.jsx("div",{className:"rounded-md border border-fg-6/30 bg-fg-6/[0.05] px-3 py-2 max-w-[400px] max-h-[260px] overflow-y-auto",children:e.jsx("div",{className:"text-[11.5px] leading-[1.65] text-fg-3 whitespace-pre-wrap break-words",children:l})})]}):e.jsx("figcaption",{className:"text-[11px] leading-[1.55] text-fg-5 max-w-[400px] break-words whitespace-pre-wrap",children:l}))]})}function jr({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]=o.useState(null),w=o.useMemo(()=>Gt({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(vn,{remarkPlugins:wn,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(vr,{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(qn,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},j))}),d&&e.jsx(Zn,{src:d,onClose:()=>b(null)})]})}const go=o.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:C}){const y=n.user&&Dn(n.user.text),R=C&&typeof s=="number"?()=>C(s):void 0,M=o.useMemo(()=>Gt({workdir:w}),[w]),P=!!n.assistant&&xr(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!y&&e.jsx(Jn,{text:n.user.text,blocks:n.user.blocks,t:b,onResend:g,onEdit:j,onFork:R}),y&&n.user&&!n.assistant&&e.jsx("div",{className:"mb-4 px-4 py-3 rounded-lg bg-[rgba(255,255,255,0.02)] border border-edge/20 text-[12.5px] leading-[1.7] text-fg-4",children:e.jsx(vn,{remarkPlugins:wn,components:M,children:n.user.text})}),P&&e.jsxs(e.Fragment,{children:[e.jsx(Nr,{agent:l,meta:i,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(hr,{message:n.assistant,t:b,workdir:w})})]})]})});function Zn({src:t,onClose:n}){return o.useEffect(()=>{const s=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),bn.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 wr=1500,kr=16,Ln=8;function yr(t){const n=t.split(`
20
+ `);return n.length<=Ln?t:n.slice(0,Ln).join(`
21
+ `)}function Jn({text:t,blocks:n,t:s,onResend:l,onEdit:i,onFork:c}){const[x,d]=o.useState(!1),[b,w]=o.useState(!1),[g,j]=o.useState(null),C=t?t.split(`
22
+ `).length:0,y=!!t&&(t.length>wr||C>kr),[R,M]=o.useState(!1),P=t?y&&!R?yr(t):t:"",B=!!(l||i||c),N=n?.filter(A=>A.type==="image")||[],D=()=>{navigator.clipboard.writeText(t).then(()=>{w(!0),setTimeout(()=>w(!1),1500)}).catch(()=>{})},ne=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(C));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[P,y&&!R&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),y&&e.jsx("button",{type:"button",onClick:()=>M(A=>!A),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:R?s("hub.collapse"):ne}),N.length>0&&e.jsx("div",{className:L("flex flex-wrap gap-2",t&&"mt-2"),children:N.map((A,H)=>e.jsx("img",{src:A.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(A.content)},H))})]}),g&&e.jsx(Zn,{src:g,onClose:()=>j(null)}),B&&e.jsxs("div",{className:L("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(_t,{label:s(b?"hub.copied":"hub.copy"),onClick:D,children:b?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),l&&e.jsx(_t,{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(_t,{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(_t,{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 _t({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 Nr({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,C=c?.providerName??i??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(ot,{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||""]}),C&&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 ${C} (BYOK), not the agent CLI's native auth.`,children:["via ",C]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:Tr(c),children:[d!=null&&e.jsx(Lr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),b>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",Ir(b)]}),w>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",es(w)]}),j&&e.jsx(Sr,{startedAt:x,leadingDot:g})]})]})}function Sr({startedAt:t,leadingDot:n}){const[,s]=o.useState(0);o.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?"· ":"",Cr(l)]})}function Cr(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 Ir(t){return`${es(t)} tok`}function es(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function Tr(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 Lr({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 Mn(t,n,s){return t==="zh-CN"?n:s}function Mr({open:t,onClose:n,workdir:s}){const l=Ce(c=>c.locale),i=s.split("/").pop()||s;return e.jsxs(Kt,{open:t,onClose:n,wide:!0,children:[e.jsx(Ht,{title:Mn(l,`${i} — 项目扩展`,`${i} — Project Extensions`),description:Mn(l,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(Ls,{workdir:s}):null]})}let En=_n(()=>import("./SessionPanel-C9Y7P7yk.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function pn(){return En??=_n(()=>import("./SessionPanel-C9Y7P7yk.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),En}const Er=o.lazy(async()=>({default:(await pn()).SessionPanel})),dn=5,Ar=240,Rr=120,Pr=12,_r=900*1e3,K=(t,n)=>`${t}:${n}`;function Wr(t){const n=new Map;for(const d of t)n.set(K(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=K(b.agent||d.agent||"",b.sessionId);n.has(w)&&(l.add(K(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=K(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=K(d.agent||"",d.sessionId);l.has(b)||x(d,0)}for(const d of t)x(d,0);return i}let Br=0;function Wt(){return`mk-${Date.now().toString(36)}-${(++Br).toString(36)}`}function Bt(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 $t(t,n){try{localStorage.setItem(t,n)}catch{}}const $r=[1,2,3,6],fn=6;function Or(t){for(const n of $r)if(n>=t)return n;return fn}function An(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function Ke(t,n){const s=Or(t);return s>n?s:n}function Dr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Fr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function ts(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 Ur=o.memo(function({active:n=!0}){const s=Ce(r=>r.locale),l=Ce(r=>r.state?.runtimeWorkdir??null),i=o.useMemo(()=>bs(s),[s]),[c,x]=o.useState([]),[d,b]=o.useState({}),[w,g]=o.useState({}),[j,C]=o.useState(!0),[y,R]=o.useState(()=>{const r=Bt("pikiloom-layout-mode");return r==="1"||r==="2"||r==="3"||r==="6"?Number(r):An()}),[M,P]=o.useState(()=>{const r=Bt("pikiloom-layout-floor");return r==="1"||r==="2"||r==="3"||r==="6"?Number(r):An()}),[B,N]=o.useState(()=>{try{const r=Bt("pikiloom-open-sessions");if(r){const h=JSON.parse(r);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||Wt()}))}}catch{}return[]}),[D,ne]=o.useState(()=>{const r=Bt("pikiloom-active-slot");if(r!=null){const h=Number(r);if(Number.isFinite(h)&&h>=0)return h}return 0}),A=o.useCallback(r=>{R(r),$t("pikiloom-layout-mode",String(r))},[]),H=o.useCallback(r=>{P(r),$t("pikiloom-layout-floor",String(r))},[]),O=o.useCallback(r=>{N(h=>{const u=typeof r=="function"?r(h):r,p=u.map(({pendingPrompt:v,pendingImageUrls:k,...I})=>I);return $t("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),F=o.useCallback(r=>{ne(h=>{const u=typeof r=="function"?r(h):r;return $t("pikiloom-active-slot",String(u)),u})},[]),le=o.useCallback(r=>{A(r),H(r)},[A,H]);o.useEffect(()=>{O(r=>r.length>y?r.slice(0,y):r),F(r=>r>=y?y-1:r)},[y]);const[_,ae]=o.useState(!1),re=o.useRef(y);re.current=y;const V=o.useRef(M);V.current=M;const Ie=o.useRef(D);Ie.current=D;const z=o.useRef(B);z.current=B;const wt=o.useRef(-1),fe=B[D]??null,at=o.useCallback(r=>{if(!r){O([]),F(0);return}const h=r.mountKey?r:{...r,mountKey:Wt()};O(u=>{const p=u.findIndex(k=>k.agent===h.agent&&k.sessionId===h.sessionId);if(p>=0)return F(p),u;if(u.length<re.current){const k=[...u,h];return F(k.length-1),k}if(re.current<fn){const k=[...u,h];return A(Ke(k.length,V.current)),F(k.length-1),k}const v=[...u];return v[Ie.current]=h,v})},[O,F,A]),[Ve,Ge]=o.useState(!1),[X,Pe]=o.useState(null),[_e,ct]=o.useState(""),[Z,We]=o.useState("all"),[ge,qe]=o.useState({}),[Te,kt]=o.useState({}),ce=o.useDeferredValue(_e),oe=o.useRef(!1),Be=o.useRef({}),Le=o.useRef(d);Le.current=d;const dt=o.useRef(ge);dt.current=ge;const Me=o.useRef(new Set),se=o.useRef({});o.useEffect(()=>()=>{for(const r of Object.values(se.current))clearTimeout(r)},[]),o.useEffect(()=>{O(r=>{let h=!1;const u=r.map(p=>{const v=Te[p.workdir];if(!v)return p;const k=Sn(v,p.agent,p.sessionId);return k===p.sessionId?p:(h=!0,{...p,sessionId:k})});return h?u:r})},[Te,O]);const me=o.useCallback(async()=>{try{const r=await te.getWorkspaces(),h=r.ok?r.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),oe.current=!0}catch{oe.current=!0}finally{C(!1)}},[]);o.useEffect(()=>{me()},[me]);const T=o.useCallback(async(r,h={})=>{if(!Be.current[r]){Be.current[r]=!0,h.background||g(u=>({...u,[r]:!0}));try{const u=await Ps(r,{force:h.force});o.startTransition(()=>{kt(p=>{const v=u.promotions||{},k=p[r];return k&&Object.keys(k).length===Object.keys(v).length&&Object.entries(v).every(([I,G])=>k[I]===G)?p:{...p,[r]:v}}),b(p=>{const v=u.sessions||[],k=p[r]||[],I=new Set(v.map(E=>K(E.agent||"",E.sessionId))),G=k.filter(E=>{if(E.runState!=="running")return!1;const W=K(E.agent||"",E.sessionId);if(I.has(W))return!1;const $=dt.current[W];return!($?.resolvedKey&&$.resolvedKey!==W)});return{...p,[r]:G.length?[...G,...v]:v}})})}catch{h.background||o.startTransition(()=>{b(u=>({...u,[r]:[]}))})}finally{Be.current[r]=!1,h.background||g(u=>({...u,[r]:!1}))}}},[]),J=o.useRef(l);o.useEffect(()=>{l!==J.current&&(J.current=l,!(!l||!oe.current)&&me().then(()=>{T(l,{force:!0})}))},[l,me,T]);const q=o.useCallback((r,h)=>{const u=r.agent||"";!u||!r.sessionId||(pn(),Bs({workdir:h,agent:u,sessionId:r.sessionId,rich:!0,turnOffset:0,turnLimit:Pr}))},[]),yt=o.useCallback((r,h,u=Rr)=>{const p=`${h}:${K(r.agent||"",r.sessionId)}`,v=se.current[p];v&&clearTimeout(v),se.current[p]=setTimeout(()=>{delete se.current[p],q(r,h)},u)},[q]),Ee=o.useCallback((r,h)=>{const u=`${h}:${K(r.agent||"",r.sessionId)}`,p=se.current[u];p&&(clearTimeout(p),delete se.current[u])},[]);o.useEffect(()=>{n&&pn()},[n]),o.useEffect(()=>{if(!n)return;const r=[];return c.forEach((h,u)=>{if(d[h.path]||w[h.path])return;const p=setTimeout(()=>{T(h.path)},u*90);r.push(p)}),()=>{for(const h of r)clearTimeout(h)}},[n,T,w,d,c]);const Qe=o.useRef(new Map);Cn(n&&oe.current&&c.length>0?"sessions-changed":null,o.useCallback(r=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=r.key,u=h?c.filter(k=>(Le.current[k.path]||[]).some(I=>K(I.agent||"",I.sessionId)===h)):c,p=u.length?u:c,v=Qe.current;for(const k of p)v.has(k.path)&&clearTimeout(v.get(k.path)),v.set(k.path,setTimeout(()=>{v.delete(k.path),T(k.path,{background:!0,force:!0})},300))},[c,T]));const $e=o.useCallback(r=>{const h=r.agent||"";return!h||!r.sessionId?r:vs(r,ge[K(h,r.sessionId)]||null)},[ge]);Cn("stream-update",o.useCallback(r=>{const h=r.key;if(!h)return;const u=js(h,r.snapshot??null);qe(p=>{if(!u){const W=p[h];return!W||W.phase==="done"?p:{...p,[h]:{...W,phase:"done",updatedAt:Date.now()}}}const v=(W,$)=>!!W&&!!$&&W.phase===$.phase&&W.resolvedKey===$.resolvedKey&&W.sessionId===$.sessionId&&W.incomplete===$.incomplete&&W.error===$.error,k=v(p[h],u),I=u.resolvedKey===h||v(p[u.resolvedKey],{...u,key:u.resolvedKey});if(k&&I)return p;const G=Date.now()-_r,E={};for(const[W,$]of Object.entries(p))$.phase==="done"&&$.updatedAt<G||(E[W]=$);return E[h]=u,u.resolvedKey!==h&&(E[u.resolvedKey]={...u,key:u.resolvedKey}),E})},[])),ws(o.useCallback(()=>{if(!(!n||!oe.current||c.length===0))for(const r of c)T(r.path,{background:!0,force:!0})},[n,c,T])),o.useEffect(()=>{if(!n||!oe.current||c.length===0)return;const r=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)T(u.path,{background:!0,force:!0})};if(r(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&r()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,T,c]),o.useEffect(()=>{if(!n)return;const r=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const v=`${h.path}:${K(p.agent||"",p.sessionId)}`;if(Me.current.has(v))return;const k=setTimeout(()=>{Me.current.add(v),q(p,h.path)},Ar+u*120);r.push(k)}),()=>{for(const h of r)clearTimeout(h)}},[n,d,q,c]);const qt=o.useCallback(async r=>{try{(await te.addWorkspace(r)).ok&&(Ge(!1),await me(),T(r))}catch{}},[me,T]),[de,be]=o.useState(null),[ve,Nt]=o.useState(!1),[ie,Oe]=o.useState(null),Ye=o.useCallback(r=>{be(r)},[]),Xe=o.useCallback(async()=>{const r=de;if(r){Nt(!0);try{await te.removeWorkspace(r),x(h=>h.filter(u=>u.path!==r)),b(h=>{const u={...h};return delete u[r],u}),O(h=>{const u=h.filter(p=>p.workdir!==r);return u.length!==h.length&&A(Ke(u.length,V.current)),u}),F(0),be(null)}catch{}finally{Nt(!1)}}},[de]),Ze=o.useCallback(r=>{T(r,{force:!0})},[T]),[Ae,je]=o.useState(null),[Je,De]=o.useState(!1),[we,ut]=o.useState(!1),ht=Ce(r=>r.toast),[ue,ke]=o.useState(null),et=o.useCallback((r,h,u)=>{ke({anchor:{right:r.right,bottom:r.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:Rn(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);o.useEffect(()=>{if(!ue)return;const r=()=>ke(null),h=u=>{u.key==="Escape"&&r()};return window.addEventListener("mousedown",r),window.addEventListener("scroll",r,!0),window.addEventListener("resize",r),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",r),window.removeEventListener("scroll",r,!0),window.removeEventListener("resize",r),window.removeEventListener("keydown",h)}},[ue]);const St=o.useCallback(r=>{De(!1),je(r),ke(null)},[]),xt=o.useCallback(async()=>{const r=Ae;if(r){ut(!0);try{const h=await te.deleteSession(r.workdir,r.agent,r.sessionId,Je);if(!h.ok){const u=h.error?.includes("still running")?i("session.deleteRunningError"):h.error||i("session.deleteFailed");ht(u,!1);return}b(u=>{const p=u[r.workdir];if(!p)return u;const v=p.filter(k=>!(k.agent===r.agent&&k.sessionId===r.sessionId));return v.length===p.length?u:{...u,[r.workdir]:v}}),O(u=>{const p=u.filter(v=>!(v.workdir===r.workdir&&v.agent===r.agent&&v.sessionId===r.sessionId));return p.length!==u.length&&A(Ke(p.length,V.current)),p}),je(null)}catch(h){ht(h?.message||i("session.deleteFailed"),!1)}finally{ut(!1)}}},[Ae,Je,i,ht]),ye=o.useCallback(r=>{O(h=>{let u=!1;const p=h.map(v=>v.mountKey===r&&(v.pendingPrompt!=null||v.pendingImageUrls)?(u=!0,{...v,pendingPrompt:null,pendingImageUrls:void 0}):v);return u?p:h})},[O]),Ct=o.useCallback((r,h,u)=>{q({agent:r.agent,sessionId:r.sessionId,runState:"running"},r.workdir),b(k=>{const I=k[r.workdir]||[];if(I.some(W=>W.sessionId===r.sessionId&&W.agent===r.agent))return k;const E={sessionId:r.sessionId,agent:r.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...k,[r.workdir]:[E,...I]}});const p=wt.current,v={...r,mountKey:Wt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};o.startTransition(()=>{Pe(null),O(k=>{if(p>=k.length)return[...k,v];const I=[...k];return I[p]=v,I}),F(p>=0?p:0)}),T(r.workdir,{background:!0,force:!0})},[T,q,O,F]),pt=o.useCallback(r=>{z.current.length>=re.current&&re.current<fn&&A(Ke(re.current+1,V.current)),Pe(r)},[A]),It=o.useCallback(()=>{Pe(null),A(Ke(z.current.length,V.current))},[A]),Tt=o.useCallback((r,h)=>{q(r,h);const u=r.agent||"";z.current.some(p=>p.agent===u&&p.sessionId===r.sessionId)&&A(Ke(z.current.length,V.current)),Pe(null),o.startTransition(()=>{at({agent:u,sessionId:r.sessionId,workdir:h})})},[q,A]),Lt=o.useCallback((r,h)=>{q({agent:r.agent,sessionId:r.sessionId,runState:"running"},r.workdir),o.startTransition(()=>{h!=null?(O(u=>{if(h>=u.length)return u;const p=[...u];return p[h]={...u[h],agent:r.agent,sessionId:r.sessionId,workdir:r.workdir},p}),F(h)):at({...r,mountKey:Wt()})}),T(r.workdir,{background:!0,force:!0})},[T,q]),ft=o.useCallback(r=>{let h=r;if(Z==="running"?h=h.filter(u=>Ot(u)==="running"):Z==="review"&&(h=h.filter(u=>Ot(u)==="incomplete")),ce.trim()){const u=ce.toLowerCase();h=h.filter(p=>(p.lastMessageText||"").toLowerCase().includes(u)||(p.lastQuestion||"").toLowerCase().includes(u)||(p.lastAnswer||"").toLowerCase().includes(u)||(p.title||"").toLowerCase().includes(u)||(p.agent||"").toLowerCase().includes(u))}return h},[ce,Z]),he=o.useMemo(()=>{const r={};for(const h of c){const u=(d[h.path]||[]).map($e),p=Te[h.path],v=new Map;for(const I of u){const G=K(I.agent||"",I.sessionId),E=ge[G],W=p?Sn(p,I.agent||"",I.sessionId):I.sessionId,$=E?.resolvedKey&&E.resolvedKey!==G?E.resolvedKey:W!==I.sessionId?K(I.agent||"",W):G,Ne=v.get($);if(!Ne){v.set($,I);continue}K(Ne.agent||"",Ne.sessionId)!==$&&G===$&&v.set($,I)}const k=ft([...v.values()]);r[h.path]=Wr(k)}return r},[c,d,ge,Te,ft,$e]),Mt=o.useCallback(r=>{const h=(d[r.workdir]||[]).find(u=>u.sessionId===r.sessionId&&u.agent===r.agent)??{sessionId:r.sessionId,agent:r.agent,runState:"running"};return $e(h)},[$e,d]),gt=o.useMemo(()=>new Set(B.map(r=>K(r.agent,r.sessionId))),[B]),Qt=fe?K(fe.agent,fe.sessionId):null,Yt=o.useCallback(r=>{O(h=>{const u=h.filter((p,v)=>v!==r);return u.length===0?F(0):Ie.current>=u.length&&F(u.length-1),A(Ke(u.length,V.current)),u})},[O,F,A]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:_e,onChange:r=>ct(r.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"}),_e&&e.jsx("button",{onClick:()=>ct(""),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(r=>e.jsx("button",{onClick:()=>We(r),className:L("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",Z===r?"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${r[0].toUpperCase()+r.slice(1)}`)},r))})]}),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&&!Ve?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:i("hub.noWorkspaces")}):c.map(r=>e.jsx(Vr,{workspace:r,sessions:he[r.path]||[],loading:!!w[r.path]||!(r.path in d),isActive:r.path===l,selectedKey:Qt,openSessionKeys:gt,onSelectSession:Tt,onNewSession:pt,onRefresh:Ze,onRemove:Ye,onExtensions:Oe,onWarmSession:yt,onCancelWarmSession:Ee,onSessionMenuOpen:et,t:i},r.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(r=>e.jsx("button",{onClick:()=>le(r),className:L("flex-1 flex items-center justify-center p-1.5 rounded transition-all",y===r?"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${r}`),children:r===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"})}):r===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"})]}):r===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"})]})},r))}),e.jsxs(Re,{variant:"ghost",size:"sm",onClick:()=>Ge(r=>!r),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(${y===6?3:y}, 1fr)`,gridTemplateRows:y===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const r=X?B.length<y?B.length:D:-1;return wt.current=r,Array.from({length:y},(h,u)=>{if(X&&u===r)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(Kr,{workdir:X,workspaceName:c.find(I=>I.path===X)?.name||X.split("/").pop()||"",onSessionCreated:Ct,onClose:It,t:i},X)},`new-${X}`);const p=B[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=Mt(p),k=u===D;return e.jsxs("div",{className:L("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",k?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:k?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>F(u),children:[e.jsxs("div",{className:L("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",k?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const I=Ot(v);return e.jsx(Vt,{variant:I==="running"?"ok":I==="waiting"?"info":I==="incomplete"?"warn":"idle",pulse:I==="running"||I==="waiting"})})(),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-0",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-fg-5",children:p.workdir.split("/").pop()||p.workdir}),e.jsx("span",{className:"shrink-0 text-fg-6 text-[10px] mx-1",children:"/"}),e.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-fg-3",children:v.title||v.lastQuestion?.slice(0,60)||(Ut(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:ks(v.createdAt)}),v.runUpdatedAt&&e.jsx("span",{title:i("hub.updated"),children:Pn(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:I=>{I.stopPropagation(),ae(G=>!G)},className:L("p-0.5 rounded transition-colors",_?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:i("hub.files"),children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})})}),e.jsx("button",{onClick:I=>{I.stopPropagation(),Yt(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(o.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Er,{session:v,workdir:p.workdir,active:n&&k,onSessionChange:I=>Lt(I,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>ye(p.mountKey)},p.mountKey)})})]},p.mountKey||K(p.agent,p.sessionId))})})()})}),_&&fe&&e.jsx(qr,{workdir:fe.workdir,onClose:()=>ae(!1),t:i}),e.jsx(zr,{open:Ve,initialPath:l||void 0,onAdd:qt,onClose:()=>Ge(!1),t:i}),e.jsxs(Kt,{open:!!de,onClose:()=>!ve&&be(null),children:[e.jsx(Ht,{title:i("hub.removeWorkspace"),onClose:()=>!ve&&be(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:i("modal.confirmRemoveWorkspaceHint")}),de&&e.jsx("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 font-mono text-[11px] text-fg-4 break-all",children:de}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Re,{variant:"ghost",onClick:()=>be(null),disabled:ve,children:i("modal.cancel")}),e.jsx(Re,{variant:"primary",onClick:Xe,disabled:ve,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(ve?"modal.removing":"modal.remove")})]})]}),ue&&(()=>{const h=Math.max(8,Math.min(ue.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ue.anchor.bottom+4,window.innerHeight-60);return e.jsx("div",{className:"fixed z-[60] min-w-[160px] rounded-md border border-edge bg-panel/95 backdrop-blur-md py-1",style:{left:h,top:u,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:p=>p.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>St(ue.target),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-[12px] text-fg-2 hover:bg-panel-h/60 hover:text-red-400 transition-colors",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),e.jsx("path",{d:"M10 11v6"}),e.jsx("path",{d:"M14 11v6"}),e.jsx("path",{d:"M9 6V4a2 2 0 012-2h2a2 2 0 012 2v2"})]}),i("session.delete")]})})})(),e.jsxs(Kt,{open:!!Ae,onClose:()=>!we&&je(null),children:[e.jsx(Ht,{title:i("session.deleteTitle"),onClose:()=>!we&&je(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("session.deleteHint")}),Ae&&e.jsxs("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 text-[11px] text-fg-4 break-all",children:[e.jsx("span",{className:"font-mono text-fg-5",children:Ae.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Ae.title})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:!Je,onChange:()=>De(!1),disabled:we,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:i("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:i("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:Je,onChange:()=>De(!0),disabled:we,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:i("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:i("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Re,{variant:"ghost",onClick:()=>je(null),disabled:we,children:i("modal.cancel")}),e.jsx(Re,{variant:"primary",onClick:xt,disabled:we,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(we?"session.deleting":"modal.remove")})]})]}),e.jsx(Mr,{open:!!ie,onClose:()=>Oe(null),workdir:ie||""})]})});function zr({open:t,initialPath:n,onAdd:s,onClose:l,t:i}){const[c,x]=o.useState(""),d=o.useCallback(b=>x(b),[]);return o.useEffect(()=>{t&&x("")},[t]),e.jsxs(Kt,{open:t,onClose:l,children:[e.jsx(Ht,{title:i("hub.addWorkspace"),onClose:l}),e.jsx(Cs,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:i}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Re,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:i("hub.add")}),e.jsx(Re,{variant:"secondary",onClick:l,className:"flex-1",children:i("hub.cancel")})]})]})}function Kr({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:i}){const[c,x]=o.useState(null),[d,b]=o.useState([]),w=o.useRef(null),g=o.useRef([]),j=o.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),C=o.useCallback(()=>{},[]),y=o.useCallback((P,B)=>{x(P||null),w.current=P||null;const N=B||[];b(N),g.current=N},[]),R=o.useCallback(P=>{const B=g.current;g.current=[],s(P,w.current||void 0,B.length?B:void 0)},[s]),M=!!c||d.length>0;return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 h-10 border-b border-edge/50 bg-panel/40 backdrop-blur-md z-10",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[13px] font-medium text-fg truncate",children:i("hub.newSession")}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-fg-5/60 shrink-0",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"})}),e.jsx("span",{className:"max-w-[80px] truncate",children:n})]}),e.jsx(Vt,{variant:M?"ok":"idle",pulse:M}),!M&&e.jsx("button",{onClick:l,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:M?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(Jn,{text:c||"",blocks:d.map(P=>({type:"image",content:P})),t:i}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(xn,{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(Xs,{session:j,workdir:t,onStreamQueued:C,onSendStart:y,onSessionChange:R,t:i,streamPhase:null})]})}function Hr({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(ys,{content:n,className:L("shrink-0 items-center",t.changed>0?"text-amber-400/80":t.ahead||t.behind?"text-sky-400/70":"text-fg-5/50"),onClick:s=>s.stopPropagation(),children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.5"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.5"}),e.jsx("circle",{cx:"18",cy:"8",r:"2.5"}),e.jsx("path",{d:"M6 8.5v7"}),e.jsx("path",{d:"M18 10.5c0 4.5-6 3-6 7.5"})]})})}const Vr=o.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:C,onCancelWarmSession:y,onSessionMenuOpen:R,t:M}){const[P,B]=o.useState(!0),[N,D]=o.useState(dn);o.useEffect(()=>{D(dn)},[s.length]);const ne=s.slice(0,N),A=s.length-N,H=n.path,[O,F]=o.useState(null),le=o.useCallback(()=>{te.getWorkspaceGit(H).then(_=>F(_.git)).catch(()=>F(null))},[H]);return o.useEffect(()=>{le()},[le]),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:()=>B(_=>!_),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:L("shrink-0 text-fg-5 transition-transform duration-150",P&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[e.jsx("span",{className:L("min-w-0 truncate text-[12px] font-semibold",i?"text-primary":"text-fg-3"),children:n.name}),e.jsx(Hr,{git:O})]}),i&&e.jsx(Vt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:_=>{_.stopPropagation(),b(H)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:M("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:_=>{_.stopPropagation(),j(H)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:M("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:_=>{_.stopPropagation(),w(H),le()},className:"p-1 rounded text-fg-5 hover:text-fg-2 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),!i&&e.jsx("button",{onClick:_=>{_.stopPropagation(),g(H)},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"})]})})]})]}),P&&e.jsx("div",{className:"pb-1",children:l?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):s.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:M("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[ne.map(_=>{const ae=K(_.agent||"",_.sessionId),re=_.__forkDepth||0;return e.jsx(Gr,{session:_,isSelected:c===ae,isOpen:x?.has(ae)??!1,forkDepth:re,onClick:()=>d(_,H),onWarm:()=>C(_,H),onCancelWarm:()=>y(_,H),onShowMenu:V=>R(V,_,H),menuLabel:M("session.openActions")},ae)}),A>0&&e.jsxs("button",{onClick:()=>D(_=>_+dn),className:"flex items-center gap-1.5 w-full px-3 py-1.5 text-[11px] text-fg-5 hover:text-fg-3 hover:bg-panel-h/50 transition-colors",children:[e.jsxs("span",{children:["+ ",M("hub.nMore").replace("{n}",String(A))]}),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"})})]})]})})]})}),Gr=o.memo(function({session:n,isSelected:s,isOpen:l,forkDepth:i=0,onClick:c,onWarm:x,onCancelWarm:d,onShowMenu:b,menuLabel:w}){const g=un(n.agent||""),j=Ot(n),C=Rn(n).slice(0,500)||(Ut(n.sessionId)?"":n.sessionId.slice(0,16)),y=Ns(n,C).slice(0,500),R=n.model?zt(n.model):null,M=i>0?Math.min(i,3)*14:0,P=l?10:12,B=o.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:x,onFocus:x,onMouseLeave:d,onBlur:d,className:L("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":l?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:P+M,...l?{borderLeft:`2px solid ${s?g.color:`${g.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[i>0&&e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-fg-5/60 shrink-0","aria-label":"Fork",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]}),e.jsx(ot,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),R&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:R}),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:Pn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Vt,{variant:j==="running"?"ok":j==="waiting"?"info":j==="incomplete"?"warn":"idle",pulse:j==="running"||j==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:C})]}),y&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:y})})]}),e.jsx("button",{ref:B,type:"button","aria-label":w,"aria-haspopup":"menu",onMouseDown:N=>{N.stopPropagation()},onClick:N=>{N.stopPropagation(),N.preventDefault(),B.current&&b(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"})]})})]})}),qr=o.memo(function({workdir:n,onClose:s,t:l}){const i=Ce(g=>g.state?.hostApp??null),c=Ce(g=>g.state?.platform??null),x=Ce(g=>g.toast),[d,b]=o.useState(()=>Fr(i,c)),w=o.useCallback(async g=>{try{const j=await te.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(Ss,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:l(ts(g))})),onChange:g=>{Dr(g)&&b(g)},renderIcon:g=>e.jsx(ns,{target:g,size:14})}),e.jsx(Re,{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(Qr,{basePath:n,openTarget:d,onOpenPath:w,t:l})})]})});function ns({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(ot,{brand:t,size:n})}function Qr({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:l,t:i}){const[c,x]=o.useState([]),[d,b]=o.useState(!0);o.useEffect(()=>{let g=!1;return b(!0),te.lsDir(t,!0,n).then(j=>{!g&&j.ok&&x(j.dirs.slice(0,50).map(C=>({entry:C,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||b(!1)}),()=>{g=!0}},[t,n]);const w=o.useCallback(g=>{const j=C=>C.map(y=>y.entry.path===g?y.expanded?{...y,expanded:!1}:y.children===null?(te.lsDir(g,!0,n).then(R=>{R.ok&&x(M=>gn(M,g,{children:R.dirs.slice(0,50).map(P=>({entry:P,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(R=>gn(R,g,{children:[],loading:!1}))}),{...y,loading:!0,expanded:!0}):{...y,expanded:!0}:y.children?{...y,children:j(y.children)}:y);x(C=>j(C))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(ss,{nodes:c,depth:0,onToggle:w,openTarget:s,onOpenPath:l,t:i})})}function ss({nodes:t,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(Yr,{node:x,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c},x.entry.path))})}function Yr({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,C]=o.useState(!1),y=c(ts(l)),R=c("hub.openWithTarget").replace("{target}",y);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),className:L("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",x.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+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:L("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),x.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:x.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:M=>{M.stopPropagation(),i(x.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:R,children:e.jsx(ns,{target:l,subtle:!0})}),!x.isDir&&e.jsx(Xr,{filePath:x.path,t:c})]})]}),x.isDir&&d&&b&&b.length>0&&e.jsx(ss,{nodes:b,depth:n+1,onToggle:s,openTarget:l,onOpenPath:i,t:c})]})}function Xr({filePath:t,t:n}){const[s,l]=o.useState(!1);return e.jsx("button",{onClick:i=>{i.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},className:L("p-0.5 rounded transition-colors",s?"text-ok":"text-fg-5 hover:text-fg-3"),title:n("hub.copied"),children:s?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})}function gn(t,n,s){return t.map(l=>l.entry.path===n?{...l,...s}:l.children?{...l,children:gn(l.children,n,s)}:l)}const mo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Ur},Symbol.toStringTag,{value:"Module"}));export{Xs as I,fo as L,ar as R,go as T,Jn as U,ho as a,Qn as b,co as c,ao as d,xn as e,po as f,Nr as g,mo as i,Ws as l,xo as m,uo as n,lo as o,_s as p,io 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-CBNgeLIy.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-DPBa40VJ.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-CBNgeLIy.js"></script>
9
+ <script type="module" crossorigin src="/assets/index-DPBa40VJ.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-CH_4h4ZM.css">
@@ -327,7 +327,7 @@ function writeSessionMeta(record) {
327
327
  workspacePath: record.workspacePath,
328
328
  threadId: record.threadId,
329
329
  createdAt: record.createdAt, updatedAt: record.updatedAt,
330
- title: record.title, model: record.model, thinkingEffort: record.thinkingEffort, workflowEnabled: record.workflowEnabled, stagedFiles: record.stagedFiles,
330
+ title: record.title, model: record.model, thinkingEffort: record.thinkingEffort, workflowEnabled: record.workflowEnabled, profileId: record.profileId, stagedFiles: record.stagedFiles,
331
331
  runState: record.runState, runDetail: record.runDetail, runUpdatedAt: record.runUpdatedAt,
332
332
  runPid: record.runPid,
333
333
  classification: record.classification,
@@ -7,7 +7,7 @@ import { terminateProcessTree } from '../core/process-control.js';
7
7
  import { AGENT_DETECT_TIMEOUTS, AGENT_STREAM_HARD_KILL_GRACE_MS, AGENT_UPDATE_TIMEOUTS } from '../core/constants.js';
8
8
  import { awaitAgentUpdateIdle } from './auto-update.js';
9
9
  import { getDriver, allDrivers, getAcceptedProviderKinds, hasDriver } from './driver.js';
10
- import { resolveAgentInjection, getActiveProfile, getActiveProfileId, getProvider, updateProfile, listProfiles, } from '../model/index.js';
10
+ import { resolveAgentInjection, getActiveProfile, getActiveProfileId, getProfile, getProvider, updateProfile, listProfiles, } from '../model/index.js';
11
11
  import { Q, agentLog, agentWarn, agentError, joinErrorMessages, normalizeErrorMessage, buildStreamPreviewMeta, computeContext, shortValue, isPendingSessionId, dedupeStrings, normalizeStreamPreviewPlan, } from './utils.js';
12
12
  import { saveSessionRecord, setSessionRunState, applySessionRunResult, ensureSessionWorkspace, importFilesIntoWorkspace, syncManagedSessionIdentity, summarizePromptTitle, recordFork, resolveCanonicalSessionId, } from './session.js';
13
13
  import { clearAwaitResume } from './await-resume.js';
@@ -361,7 +361,7 @@ function prepareStreamOpts(opts) {
361
361
  },
362
362
  };
363
363
  }
364
- function finalizeStreamResult(result, workdir, prompt, session, workflowEnabled) {
364
+ function finalizeStreamResult(result, workdir, prompt, session, workflowEnabled, profileIdOverride) {
365
365
  if (result.sessionId)
366
366
  syncManagedSessionIdentity(session, workdir, result.sessionId);
367
367
  session.record.model = result.model || session.record.model;
@@ -370,7 +370,9 @@ function finalizeStreamResult(result, workdir, prompt, session, workflowEnabled)
370
370
  if (workflowEnabled !== undefined)
371
371
  session.record.workflowEnabled = workflowEnabled;
372
372
  try {
373
- session.record.profileId = getActiveProfileId(session.record.agent);
373
+ session.record.profileId = profileIdOverride !== undefined
374
+ ? (profileIdOverride || null)
375
+ : getActiveProfileId(session.record.agent);
374
376
  }
375
377
  catch {
376
378
  }
@@ -444,7 +446,7 @@ export async function doStream(opts) {
444
446
  agentWarn(`[mcp] bridge start failed: ${e.message} — proceeding without MCP`);
445
447
  }
446
448
  try {
447
- const injection = await resolveAgentInjection(prepared.agent);
449
+ const injection = await resolveAgentInjection(prepared.agent, prepared.profileId);
448
450
  if (injection) {
449
451
  prepared.extraEnv = { ...(prepared.extraEnv || {}), ...injection.env };
450
452
  if (injection.modelOverride) {
@@ -473,7 +475,9 @@ export async function doStream(opts) {
473
475
  }
474
476
  agentLog(`[byok] ${injection.detail}`);
475
477
  }
476
- const activeProfile = getActiveProfile(prepared.agent);
478
+ const activeProfile = prepared.profileId === undefined
479
+ ? getActiveProfile(prepared.agent)
480
+ : (prepared.profileId ? getProfile(prepared.profileId) : null);
477
481
  if (activeProfile) {
478
482
  if (activeProfile.effort)
479
483
  prepared.thinkingEffort = activeProfile.effort;
@@ -493,6 +497,16 @@ export async function doStream(opts) {
493
497
  if (opts.claudeWorkflowEnabled !== undefined) {
494
498
  session.record.workflowEnabled = opts.claudeWorkflowEnabled;
495
499
  }
500
+ const turnModel = prepared.model
501
+ || (prepared.agent === 'claude' ? prepared.claudeModel
502
+ : prepared.agent === 'codex' ? prepared.codexModel
503
+ : prepared.agent === 'gemini' ? prepared.geminiModel
504
+ : prepared.agent === 'hermes' ? prepared.hermesModel
505
+ : null);
506
+ if (turnModel)
507
+ session.record.model = turnModel;
508
+ if (prepared.profileId !== undefined)
509
+ session.record.profileId = prepared.profileId || null;
496
510
  saveSessionRecord(opts.workdir, session.record);
497
511
  }
498
512
  catch (e) {
@@ -505,7 +519,7 @@ export async function doStream(opts) {
505
519
  }
506
520
  await awaitAgentUpdateIdle(prepared.agent, AGENT_UPDATE_TIMEOUTS.spawnWait);
507
521
  const result = await driver.doStream(prepared);
508
- const finalized = finalizeStreamResult(result, opts.workdir, opts.prompt, session, opts.claudeWorkflowEnabled);
522
+ const finalized = finalizeStreamResult(result, opts.workdir, opts.prompt, session, opts.claudeWorkflowEnabled, opts.profileId);
509
523
  finalized.byokProviderName = prepared.byokProviderName ?? null;
510
524
  finalized.byokProfileName = prepared.byokProfileName ?? null;
511
525
  if (opts.forkOf && finalized.sessionId) {
package/dist/bot/bot.js CHANGED
@@ -1285,8 +1285,8 @@ export class Bot {
1285
1285
  opts.onText?.(text, thinking, activity, meta, plan);
1286
1286
  presenter?.onText(text, thinking, activity, meta, plan);
1287
1287
  this.emitStreamText(taskId, session.key, text, thinking, activity, meta, plan);
1288
- }, undefined, undefined, abortController.signal, this.createInteractionHandler(chatId, taskId), undefined, undefined, (opts.forkOf || opts.workflowEnabled !== undefined)
1289
- ? { ...(opts.forkOf ? { forkOf: opts.forkOf } : {}), ...(opts.workflowEnabled !== undefined ? { workflowEnabled: opts.workflowEnabled } : {}) }
1288
+ }, undefined, undefined, abortController.signal, this.createInteractionHandler(chatId, taskId), undefined, undefined, (opts.forkOf || opts.workflowEnabled !== undefined || opts.profileId !== undefined)
1289
+ ? { ...(opts.forkOf ? { forkOf: opts.forkOf } : {}), ...(opts.workflowEnabled !== undefined ? { workflowEnabled: opts.workflowEnabled } : {}), ...(opts.profileId !== undefined ? { profileId: opts.profileId } : {}) }
1290
1290
  : undefined);
1291
1291
  this.emitStreamDone(taskId, session.key, {
1292
1292
  sessionId: result.sessionId || session.sessionId,
@@ -2042,6 +2042,7 @@ export class Bot {
2042
2042
  const opts = {
2043
2043
  agent: cs.agent, prompt, workdir: sessionWorkdir, timeout: this.runTimeout,
2044
2044
  sessionId: cs.sessionId, model: null,
2045
+ profileId: extras?.profileId,
2045
2046
  thinkingEffort: resolvedThinkingEffort, onText,
2046
2047
  onSessionId: syncNativeSessionId,
2047
2048
  attachments: attachments.length ? attachments : undefined,
@@ -136,6 +136,7 @@ async function parseSessionSendRequest(c) {
136
136
  sessionId: readStringField(form.get('sessionId')),
137
137
  prompt: readStringField(form.get('prompt')),
138
138
  model: readStringField(form.get('model')),
139
+ profileId: form.has('profileId') ? (readStringField(form.get('profileId')) || null) : undefined,
139
140
  effort: readStringField(form.get('effort')).toLowerCase(),
140
141
  workflow: readStringField(form.get('workflow')) === '1',
141
142
  attachments: uploads.attachments,
@@ -151,6 +152,9 @@ async function parseSessionSendRequest(c) {
151
152
  sessionId: readStringField(body?.sessionId),
152
153
  prompt: readStringField(body?.prompt),
153
154
  model: readStringField(body?.model),
155
+ profileId: body && 'profileId' in body
156
+ ? (body.profileId === null ? null : (typeof body.profileId === 'string' && body.profileId.trim() ? body.profileId.trim() : null))
157
+ : undefined,
154
158
  effort: readStringField(body?.effort).toLowerCase(),
155
159
  workflow: body?.workflow === true,
156
160
  attachments: [],
@@ -593,13 +597,14 @@ app.get('/api/session-hub/skills', (c) => {
593
597
  });
594
598
  app.post('/api/session-hub/session/send', async (c) => {
595
599
  try {
596
- const { workdir, agent, sessionId, prompt, model, effort, workflow, attachments, previousAgent, previousSessionId, cleanup } = await parseSessionSendRequest(c);
600
+ const { workdir, agent, sessionId, prompt, model, profileId, effort, workflow, attachments, previousAgent, previousSessionId, cleanup } = await parseSessionSendRequest(c);
597
601
  const queued = await queueDashboardSessionTask({
598
602
  workdir,
599
603
  agent,
600
604
  sessionId,
601
605
  prompt,
602
606
  model,
607
+ ...(profileId !== undefined ? { profileId } : {}),
603
608
  effort,
604
609
  workflow,
605
610
  attachments,
@@ -630,7 +635,7 @@ app.get('/api/session-hub/session/stream-state', (c) => {
630
635
  app.post('/api/session-hub/session/fork', async (c) => {
631
636
  try {
632
637
  const body = await c.req.json();
633
- const { workdir, agent, sessionId, atTurn, prompt, model, effort, attachments } = body || {};
638
+ const { workdir, agent, sessionId, atTurn, prompt, model, profileId, effort, attachments } = body || {};
634
639
  if (!workdir || !agent || !sessionId || typeof atTurn !== 'number' || !prompt) {
635
640
  return c.json({ ok: false, error: 'workdir, agent, sessionId, atTurn (number), and prompt are required' }, 400);
636
641
  }
@@ -641,6 +646,7 @@ app.post('/api/session-hub/session/fork', async (c) => {
641
646
  atTurn,
642
647
  prompt,
643
648
  model: model || null,
649
+ ...(profileId !== undefined ? { profileId } : {}),
644
650
  effort: effort || null,
645
651
  attachments: Array.isArray(attachments) ? attachments : [],
646
652
  });
@@ -42,6 +42,13 @@ function resolveSkillFromPrompt(workdir, prompt) {
42
42
  const resolvedPrompt = `${workdirHint}Read the skill definition at \`${targetPath}\` and execute the instructions defined there.${extra}`;
43
43
  return { resolvedPrompt, skillName: skill.name };
44
44
  }
45
+ function resolveProfileIdOverride(value) {
46
+ if (value === null)
47
+ return null;
48
+ if (typeof value === 'string')
49
+ return value.trim() || null;
50
+ return undefined;
51
+ }
45
52
  function resolveHandoverFrom(request, targetAgent) {
46
53
  const prevAgent = typeof request.previousAgent === 'string' ? request.previousAgent.trim() : '';
47
54
  const prevSessionId = typeof request.previousSessionId === 'string' ? request.previousSessionId.trim() : '';
@@ -70,6 +77,7 @@ export async function queueDashboardSessionTask(request) {
70
77
  ? request.agent
71
78
  : runtime.getRuntimeDefaultAgent(config);
72
79
  const modelId = typeof request.model === 'string' ? request.model.trim() : '';
80
+ const profileId = resolveProfileIdOverride(request.profileId);
73
81
  const { effort: splitEffort, workflow: ultraWorkflow } = decomposeEffortSelection(typeof request.effort === 'string' ? request.effort : '');
74
82
  const thinkingEffort = resolvedAgent === 'gemini' ? '' : splitEffort;
75
83
  const workflowEnabled = ultraWorkflow || request.workflow === true;
@@ -110,6 +118,7 @@ export async function queueDashboardSessionTask(request) {
110
118
  prompt: prompt || 'Please inspect the attached file(s).',
111
119
  attachments,
112
120
  ...(modelId ? { modelId } : {}),
121
+ ...(profileId !== undefined ? { profileId } : {}),
113
122
  ...(thinkingEffort ? { thinkingEffort } : {}),
114
123
  workflowEnabled,
115
124
  ...(handoverFrom ? { handoverFrom } : {}),
@@ -161,6 +170,7 @@ export function forkDashboardSessionTask(request) {
161
170
  return { ok: false, error: `Agent ${agent} does not support fork` };
162
171
  }
163
172
  const modelId = typeof request.model === 'string' ? request.model.trim() : '';
173
+ const profileId = resolveProfileIdOverride(request.profileId);
164
174
  const { effort: splitEffort, workflow: ultraWorkflow } = decomposeEffortSelection(typeof request.effort === 'string' ? request.effort : '');
165
175
  const thinkingEffort = agent === 'gemini' ? '' : splitEffort;
166
176
  let prompt = request.prompt;
@@ -191,6 +201,7 @@ export function forkDashboardSessionTask(request) {
191
201
  attachments,
192
202
  forkOf: { parentSessionId: request.parentSessionId, atTurn: request.atTurn },
193
203
  ...(modelId ? { modelId } : {}),
204
+ ...(profileId !== undefined ? { profileId } : {}),
194
205
  ...(thinkingEffort ? { thinkingEffort } : {}),
195
206
  ...(ultraWorkflow ? { workflowEnabled: true } : {}),
196
207
  });
@@ -1,6 +1,6 @@
1
1
  import { resolveCredential } from '../core/secrets/index.js';
2
2
  import { writeScopedLog } from '../core/logging.js';
3
- import { getActiveProfile, getProvider } from './store.js';
3
+ import { getActiveProfile, getProfile, getProvider } from './store.js';
4
4
  import { peekProviderModelInfo, prefetchProviderModels } from './provider-models.js';
5
5
  import { ensureResponsesBridge, upstreamToken } from './responses-bridge.js';
6
6
  import { ensureAnthropicBridge } from './anthropic-bridge.js';
@@ -314,8 +314,10 @@ const AGENT_INJECT_TABLE = {
314
314
  gemini: geminiInjector,
315
315
  hermes: hermesInjector,
316
316
  };
317
- export async function resolveAgentInjection(agentId) {
318
- const profile = getActiveProfile(agentId);
317
+ export async function resolveAgentInjection(agentId, profileIdOverride) {
318
+ const profile = profileIdOverride === undefined
319
+ ? getActiveProfile(agentId)
320
+ : (profileIdOverride ? getProfile(profileIdOverride) : null);
319
321
  if (!profile)
320
322
  return null;
321
323
  const provider = getProvider(profile.providerId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pikiloom",
3
- "version": "0.4.33",
3
+ "version": "0.4.34",
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": {