pikiloom 0.4.20 → 0.4.21

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