pikiclaw 0.3.74 → 0.3.76
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -0
- package/README.zh-CN.md +6 -0
- package/dashboard/dist/assets/{AgentTab-CADj3aek.js → AgentTab-B_Ho3mZN.js} +1 -1
- package/dashboard/dist/assets/{BrandIcon-8Kd8Mrvt.js → BrandIcon-DCdjOVU2.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-BP-Q_KSW.js → DirBrowser-B7vCgZK7.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-CrCwGRF8.js → ExtensionsTab-D4mhLfFV.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-CqXyoYWE.js → IMAccessTab-jAXpPlF1.js} +1 -1
- package/dashboard/dist/assets/{Modal-DGTrNLX8.js → Modal-CXC9XnlJ.js} +1 -1
- package/dashboard/dist/assets/{Modals-DYiRSUt4.js → Modals-DQeaEzGg.js} +1 -1
- package/dashboard/dist/assets/{Select-CwiasDWv.js → Select-D8JexIeD.js} +1 -1
- package/dashboard/dist/assets/{SessionPanel-GZ3iSdWI.js → SessionPanel-YiJbo2Jx.js} +1 -1
- package/dashboard/dist/assets/{SystemTab-1TXrP5wu.js → SystemTab-F6hqRfOX.js} +1 -1
- package/dashboard/dist/assets/index-BSXJWJQ3.js +22 -0
- package/dashboard/dist/assets/index-Bw_RfD9b.js +3 -0
- package/dashboard/dist/assets/index-Df1Rxpu7.css +1 -0
- package/dashboard/dist/assets/{shared-Aw_2USbm.js → shared-D8sV7dVi.js} +1 -1
- package/dashboard/dist/index.html +2 -2
- package/dist/agent/drivers/claude-tui.js +4 -3
- package/dist/agent/drivers/claude.js +26 -15
- package/dist/bot/bot.js +1 -0
- package/dist/bot/commands.js +2 -0
- package/dist/channels/dingtalk/bot.js +3 -1
- package/dist/channels/discord/bot.js +3 -1
- package/dist/channels/feishu/bot.js +14 -5
- package/dist/channels/feishu/channel.js +14 -6
- package/dist/channels/feishu/render.js +3 -1
- package/dist/channels/slack/bot.js +3 -1
- package/dist/channels/telegram/bot.js +22 -14
- package/dist/channels/wecom/bot.js +3 -1
- package/dist/channels/weixin/bot.js +3 -1
- package/dist/core/constants.js +9 -0
- package/dist/core/git.js +145 -0
- package/dist/dashboard/routes/config.js +10 -0
- package/package.json +1 -1
- package/dashboard/dist/assets/index-BK4sCKfC.js +0 -3
- package/dashboard/dist/assets/index-BTKVzQa8.css +0 -1
- package/dashboard/dist/assets/index-b9voP9W6.js +0 -22
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-GZ3iSdWI.js","assets/react-vendor-DTcmqLiz.js","assets/index-BK4sCKfC.js","assets/router-Cav8lq-m.js","assets/index-BTKVzQa8.css","assets/Modal-DGTrNLX8.js","assets/Select-CwiasDWv.js","assets/BrandIcon-8Kd8Mrvt.js","assets/DirBrowser-BP-Q_KSW.js","assets/markdown-iTdiLvRJ.js","assets/ExtensionsTab-CrCwGRF8.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as M,a as Q,u as ge,A as ns,s as sn,S as ue,g as Yt,E as Vt,C as rn,b as ss,d as rs,n as os,e as kn,f as It,B as Ce,D as Wt,h as is,i as yn,_ as Nn,j as ls}from"./index-BK4sCKfC.js";import{j as e,r,b as on}from"./react-vendor-DTcmqLiz.js";import{I as as}from"./Select-CwiasDWv.js";import{M as _t,a as Pt}from"./Modal-DGTrNLX8.js";import{B as Je}from"./BrandIcon-8Kd8Mrvt.js";import{D as cs}from"./DirBrowser-BP-Q_KSW.js";import{n as ds,r as us,M as ln}from"./markdown-iTdiLvRJ.js";import{WorkspaceExtensionsBody as hs}from"./ExtensionsTab-CrCwGRF8.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 Ye({open:t,onToggle:n,dot:s,label:l,preview:a,badge:d,collapsedContent:p,children:c,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:l}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:a}),d,e.jsx(ps,{open:t})]}),!t&&p,t&&c&&e.jsx("div",{className:"border-t border-edge",children:c})]})}const xs=5e3,fs=15e3,At=8,Rt=30,gs=1,Qe=new Map,fe=new Map,Gt=new Set,Sn=[];let Et=0;function qt(t){return typeof t=="number"&&Number.isFinite(t)}function Oe(t,n,s,l){for(t.delete(n),t.set(n,s);t.size>l;){const a=t.keys().next().value;if(!a)break;t.delete(a)}}function Cn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(Oe(t,n,s,t===fe?Rt:At),s.value)}function Ln(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:qt(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:qt(t.turnOffset)?t.turnOffset:void 0,turnLimit:qt(t.turnLimit)?t.turnLimit:void 0}}function an(t){const n=Ln(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function En(){for(;Et<gs;){const t=Sn.shift();if(!t)return;Et+=1,t().finally(()=>{Et=Math.max(0,Et-1),En()})}}async function ms(t,n={}){const s=t;if(!n.force){const d=Cn(Qe,s);if(d)return d}const l=Qe.get(s);if(l?.promise)return l.promise;const a=Q.getWorkspaceSessions(t,n.request).then(d=>(Oe(Qe,s,{value:d,expiresAt:d.ok?Date.now()+xs:0},At),d)).finally(()=>{const d=Qe.get(s);d?.promise&&Oe(Qe,s,{value:d.value,expiresAt:d.expiresAt},At)});return Oe(Qe,s,{value:l?.value,expiresAt:l?.expiresAt??0,promise:a},At),a}function bs(t,n={}){const s=an(t),l=fe.get(s);return l?.value?.ok&&(n.allowStale||l.expiresAt>Date.now())?l.value:null}async function vs(t,n={}){const s=Ln(t),l=an(s);if(!n.force){const p=Cn(fe,l);if(p?.ok)return p}const a=fe.get(l);if(a?.promise)return a.promise;const d=Q.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(p=>(Oe(fe,l,{value:p,expiresAt:p.ok?Date.now()+fs:0},Rt),p)).finally(()=>{const p=fe.get(l);p?.promise&&Oe(fe,l,{value:p.value,expiresAt:p.expiresAt},Rt)});return Oe(fe,l,{value:a?.value,expiresAt:a?.expiresAt??0,promise:d},Rt),d}function js(t){const n=an(t);bs(t)||Gt.has(n)||fe.get(n)?.promise||(Gt.add(n),Sn.push(async()=>{try{await vs(t)}catch{}finally{Gt.delete(n)}}),En())}const mt=new Map,Zt=new Set;let $e=null,Le=0,fn=!1,Xe=null,gt=500;const ws=8e3;function ks(t){const n=mt.get(t.type);if(n)for(const s of n)s(t)}function ys(){const t=window.location;return`${t.protocol==="https:"?"wss:":"ws:"}//${t.host}/ws`}function cn(){if($e)return;Mn();const t=new WebSocket(ys());t.onopen=()=>{const n=fn;if(fn=!0,gt=500,n)for(const s of Zt)s()},t.onmessage=n=>{try{const s=JSON.parse(n.data);if(s.type==="pong")return;ks(s)}catch{}},t.onclose=()=>{$e=null,Le>0&&Ss()},t.onerror=()=>{},$e=t}function Ns(){Mn(),$e&&($e.close(),$e=null)}function Mn(){Xe&&(clearTimeout(Xe),Xe=null)}function Ss(){Xe||(Xe=setTimeout(()=>{Xe=null,Le>0&&cn()},gt),gt=Math.min(gt*2,ws))}function Cs(t,n){let s=mt.get(t);s||(s=new Set,mt.set(t,s)),s.add(n),Le++,Le===1&&cn()}function Ls(t,n){const s=mt.get(t);s&&(s.delete(n),s.size===0&&mt.delete(t)),Le=Math.max(0,Le-1),Le===0&&Ns()}typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&Le>0&&!$e&&(gt=500,cn())});function gn(t,n){const s=r.useRef(n);s.current=n,r.useEffect(()=>{if(!t)return;const l=a=>s.current(a);return Cs(t,l),()=>Ls(t,l)},[t])}function Es(t){const n=r.useRef(t);n.current=t,r.useEffect(()=>{const s=()=>n.current();return Zt.add(s),()=>{Zt.delete(s)}},[])}function Hr(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(p=>({role:p.role,text:p.text,blocks:[{type:"text",content:p.text}]}))||[],s=Ts(n),l=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),a=t.window?.endTurn??l,d=t.window?.startTurn??Math.max(0,a-s.length);return{turns:s,startTurn:d,endTurn:a,totalTurns:l,hasOlder:t.window?.hasOlder??d>0}}function Kr(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 Vr(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 Ms(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 Ts(t){const n=[];let s={user:null,assistant:null};for(const l of t)if(l.role==="user"){if(s.assistant&&Tn(l.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=l}else s.assistant?s.assistant=Ms(s.assistant,l):s.assistant=l;return(s.user||s.assistant)&&n.push(s),n}const Is=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"]),As=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function Tn(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Is.has(s[1].toLowerCase())?!0:As.some(l=>t.includes(l))}function In(t,n){const s=t.split(`
|
|
5
|
-
`).filter(l=>l.trim());return s.length<=n?s.join(`
|
|
6
|
-
`):s.slice(-n).join(`
|
|
7
|
-
`)}function Rs(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 Qt(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function _s(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function Ps(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 Ws(t){if(typeof ClipboardItem>"u"||!navigator.clipboard?.write)return!1;try{return await navigator.clipboard.write([new ClipboardItem({[t.type||"image/png"]:t})]),!0}catch{return!1}}function G(t,n=120){if(t==null)return"";const l=(typeof t=="string"?t:String(t)).replace(/\s+/g," ").trim();return l.length<=n?l:l.slice(0,Math.max(0,n-1))+"…"}function Bs(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 An(t){const n=String(t.toolName||"").trim()||"Tool",s=Bs(t.content);if(!s)return n;const l=G(s.description,120);switch(n){case"Read":{const a=G(s.file_path||s.path,140);return a?`Read ${a}`:"Read"}case"Edit":{const a=G(s.file_path||s.path,140);return a?`Edit ${a}`:"Edit"}case"Write":{const a=G(s.file_path||s.path,140);return a?`Write ${a}`:"Write"}case"Glob":{const a=G(s.pattern||s.glob,120);return a?`Glob ${a}`:"Glob"}case"Grep":{const a=G(s.pattern||s.query,120);return a?`Grep ${a}`:"Grep"}case"WebFetch":{const a=G(s.url,120);return a?`WebFetch ${a}`:"WebFetch"}case"WebSearch":{const a=G(s.query,120);return a?`WebSearch ${a}`:"WebSearch"}case"TodoWrite":return"Update plan";case"AskUserQuestion":{const d=(Array.isArray(s.questions)?s.questions:[])[0],p=G(d?.question||s.question,120);return p?`Ask user: ${p}`:"Ask user"}case"Task":{const a=G(s.description||s.prompt,120);return a?`Task: ${a}`:"Task"}case"Bash":{if(l)return`Bash: ${l}`;const a=G(s.command,120);return a?`Bash: ${a}`:"Bash"}default:{const a=n.match(/^mcp__[^_]+__(.+)$/),d=a?a[1]:n;if(d==="im_send_file"){const c=G(s.path,120);return c?`Send file: ${c}`:"Send file"}if(d==="im_list_files")return"List workspace files";if(l)return`${n}: ${l}`;const p=G(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return p?`${n}: ${p}`:n}}}function Os(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
|
|
8
|
-
`).map(l=>l.trim()).find(Boolean)||"";return s?G(s,140):"result"}function $s(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),l=t.slice(n+1).trim();return!s||!l?null:{agent:s,sessionId:l}}const ft=new Map;function Ds(t,n){return`${t}:${n}`}function Fs(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 Us=r.memo(function({session:n,workdir:s,onStreamQueued:l,onSendStart:a,onSendTaskAssigned:d,onSessionChange:p,t:c,streamPhase:m,streamTaskId:v,queuedTaskIds:g,queuedTasks:j,pendingQueuedSends:L,onRecall:k,onSteer:N,onStopAll:T,editDraft:A,onEditDraftConsumed:W,onSelectionChange:$}){const[H,R]=r.useState(""),[I,z]=r.useState(!1),[E,J]=r.useState(null),[le,Ee]=r.useState(()=>new Set),[ae,et]=r.useState(()=>new Set),me=r.useRef({prompt:"",files:[]}),be=ge(i=>i.agentStatus?.agents??null),[B,De]=r.useState(be||[]),[Me,tt]=r.useState(""),[ve,bt]=r.useState(""),[ce,vt]=r.useState(""),[X,Y]=r.useState([]),[Fe,Te]=r.useState(null),[Ue,nt]=r.useState(null),[Z,re]=r.useState(null),[_,je]=r.useState(null),[q,Ie]=r.useState(null),[Ae,jt]=r.useState(void 0),[P,ee]=r.useState("closed"),[he,we]=r.useState(null),te=r.useRef(null),Re=r.useRef(!1),st=r.useRef(null),wt=r.useRef(null),ze=r.useRef(null),rt=r.useRef([]),[ot,ke]=r.useState([]),[K,pe]=r.useState(!1),[ye,ne]=r.useState(0),_e=r.useRef(null),Pe=ge(i=>i.refreshAgentStatus),[de,it]=r.useState([]),[lt,Bt]=r.useState([]),[kt,Ot]=r.useState({}),at=r.useCallback(async()=>{try{const[i,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(i?.ok&&Bt(i.providers||[]),x?.ok&&it(x.profiles||[]),b?.ok){const S={};for(const O of b.bindings||[])S[O.agent]=O.activeProfileId;Ot(S)}}catch{}},[]);r.useEffect(()=>{be?.length&&De(be)},[be]),r.useEffect(()=>{rt.current=X},[X]);const We=Ds(n.agent||"",n.sessionId),He=r.useRef(We);He.current=We,r.useEffect(()=>{const i=ft.get(We);return i&&(ft.delete(We),i.text&&R(i.text),i.files.length&&Y(i.files.map(Qt))),()=>{const x=te.current?.value||"",b=rt.current.map(S=>S.file);for(const S of rt.current)URL.revokeObjectURL(S.previewUrl);x||b.length?ft.set(He.current,{text:x,files:b}):ft.delete(He.current)}},[We]),r.useEffect(()=>{tt(""),bt(""),vt(""),re(null),je(null),Ie(null),ee("closed")},[n.agent,n.sessionId]),r.useEffect(()=>{A!=null&&(R(A),W?.(),requestAnimationFrame(()=>{const i=te.current;i&&(i.focus(),i.setSelectionRange(A.length,A.length))}))},[A,W]),r.useEffect(()=>{if(!s)return;let i=!1;return Q.getSkills(s).then(x=>{!i&&x.ok&&ke(x.skills)}).catch(()=>{}),()=>{i=!0}},[s]);const Ke=K?(()=>{const i=H.match(/^\/(\S*)$/);return i?i[1].toLowerCase():null})():null,xe=Ke!==null?ot.filter(i=>i.name.toLowerCase().includes(Ke)||i.label&&i.label.toLowerCase().includes(Ke)):[];r.useEffect(()=>{ne(0)},[K,H]),r.useEffect(()=>{if(!K||!_e.current)return;const i=_e.current.querySelector(`[data-skill-idx="${ye}"]`);i&&i.scrollIntoView({block:"nearest"})},[ye,K]),r.useEffect(()=>{if(!K)return;const i=x=>{_e.current?.contains(x.target)||te.current?.contains(x.target)||pe(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[K]),r.useEffect(()=>{if(P==="closed")return;const i=x=>{const b=x.target;ze.current?.contains(b)||document.getElementById("cascade-portal")?.contains(b)||(ee("closed"),re(null),je(null),Ie(null))};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[P]),r.useLayoutEffect(()=>{if(P==="closed"||!ze.current){we(null);return}const i=ze.current.getBoundingClientRect();we({left:i.left,bottom:window.innerHeight-i.top+8})},[P]);const yt=g&&g.length?g[0]:null;r.useEffect(()=>{E&&(yt||m!==null&&m!=="queued")&&J(null)},[m,E,yt]),r.useEffect(()=>{const i=te.current;i&&(i.style.height="auto",i.style.height=Math.min(i.scrollHeight,200)+"px")},[H]);const ct=r.useCallback(i=>{const x=Array.from(i||[]).filter(b=>b.type.startsWith("image/"));x.length&&Y(b=>[...b,...x.map(Qt)])},[]),Nt=r.useCallback(()=>{Te(null),Y(i=>(_s(i),[]))},[]),St=r.useCallback(i=>{Y(x=>{const b=x.find(S=>S.id===i);return b&&URL.revokeObjectURL(b.previewUrl),x.filter(S=>S.id!==i)}),Te(x=>x===i?null:x)},[]),o=r.useCallback(()=>{const i=H.trim(),x=X.map(V=>V.file);if(!i&&x.length===0||I)return;const b=Me||n.agent||B.find(V=>V.isDefault)?.agent||"";if(!b)return;const S=B.find(V=>V.agent===b)||null,O=(ve||S?.selectedModel||"").trim()||null,Se=b==="gemini"?null:(ce||S?.selectedEffort||"").trim()||null,oe=b!==n.agent,ie=oe?"":n.sessionId,Kt=oe&&n.agent?n.agent:null,es=oe&&n.sessionId?n.sessionId:null;z(!0),me.current={prompt:i,files:x},R(""),ft.delete(He.current);const ts=x.length?x.map(V=>URL.createObjectURL(V)):void 0;Nt(),a(i,ts),l(),Q.sendSessionMessage(s,b,ie,i,{attachments:x,model:O,effort:Se,previousAgent:Kt,previousSessionId:es}).then(V=>{if(V.taskId&&(J(V.taskId),d?.(V.taskId)),!V.ok)return;const xt=typeof V.sessionKey=="string"?$s(V.sessionKey):null;xt&&(xt.agent!==n.agent||xt.sessionId!==n.sessionId)&&xt&&p?.({...xt,workdir:s})}).catch(()=>{}).finally(()=>z(!1))},[B,Nt,X,H,a,d,p,l,Me,ce,ve,I,n.agent,n.sessionId,s]),u=m==="streaming",h=(()=>{const i=[];return g&&g.length&&i.push(...g),m==="queued"&&v&&!i.includes(v)&&i.unshift(v),E&&!i.includes(E)&&(m==="queued"||!m)&&i.push(E),i})(),f=h[h.length-1]||null,w=h.length>0,y=w||u;r.useEffect(()=>{const i=x=>h.includes(x)||x===v;Ee(x=>{let b=!1;const S=new Set;for(const O of x)i(O)?S.add(O):b=!0;return b?S:x}),et(x=>{let b=!1;const S=new Set;for(const O of x)i(O)?S.add(O):b=!0;return b?S:x})},[h,v]),r.useEffect(()=>{!w&&me.current.files.length&&(me.current={prompt:"",files:[]})},[w]);const C=r.useCallback(i=>{if(!le.has(i)){if(Ee(x=>{const b=new Set(x);return b.add(i),b}),i===f){const x=me.current;x.prompt&&R(x.prompt),x.files.length&&Y(x.files.map(Qt)),me.current={prompt:"",files:[]}}k?.(i),i===E&&J(null)}},[le,f,E,k]),[F,U]=r.useState(!1),se=r.useCallback(async()=>{if(!(F||!T)){U(!0);try{await T()}finally{U(!1)}}},[F,T]),dt=r.useCallback(i=>{ae.has(i)||(et(x=>{const b=new Set(x);return b.add(i),b}),N?.(i),i===E&&J(null))},[ae,E,N]),hn=r.useCallback(i=>{R(`/${i.name} `),pe(!1),requestAnimationFrame(()=>{const x=te.current;x&&(x.focus(),x.setSelectionRange(x.value.length,x.value.length))})},[]),zn=r.useCallback(i=>{R(i);const x=/^\/\S*$/.test(i)&&ot.length>0;pe(x)},[ot.length]),Hn=i=>{if(K&&xe.length>0){if(i.key==="ArrowDown"){i.preventDefault(),ne(x=>(x+1)%xe.length);return}if(i.key==="ArrowUp"){i.preventDefault(),ne(x=>(x-1+xe.length)%xe.length);return}if(i.key==="Tab"||i.key==="Enter"&&!i.shiftKey&&!Re.current){i.preventDefault(),hn(xe[ye]);return}if(i.key==="Escape"){i.preventDefault(),pe(!1);return}}i.key==="Enter"&&!i.shiftKey&&!Re.current&&(i.preventDefault(),o())},Kn=r.useCallback(i=>{const x=Array.from(i.clipboardData?.items||[]).filter(b=>b.kind==="file"&&b.type.startsWith("image/")).map(b=>b.getAsFile()).filter(b=>!!b);x.length&&(i.preventDefault(),ct(x))},[ct]),Ne=Me||n.agent||B.find(i=>i.isDefault)?.agent||B.find(i=>i.installed)?.agent||B[0]?.agent||"",$t=B.find(i=>i.agent===Ne)||null,ut=Z||Ne,ht=B.find(i=>i.agent===ut)||$t,Ct=r.useMemo(()=>{if(!ht)return[];const i=[];for(const b of ht.models||[])i.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(ns[ut]||[]);for(const b of de){const S=lt.find(Se=>Se.id===b.providerId);if(!S||!x.has(S.kind))continue;const O=b.name.trim().toLowerCase()!==b.modelId.trim().toLowerCase();i.push({id:b.modelId,label:b.name,kind:"profile",profileId:b.id,description:O?`${S.name} · ${b.modelId}`:S.name})}return i},[ht,ut,de,lt]),Vn=r.useMemo(()=>Ct.findIndex(i=>i.kind==="profile"),[Ct]),Gn=kt[ut]||null,pt=ve||$t?.selectedModel||"",Lt=Ne==="gemini"?"":ce||$t?.selectedEffort||"";r.useEffect(()=>{$?.({model:pt||null,effort:Lt||null})},[pt,Lt,$]);const qn=Vt[ut]||[],Be=Fe&&X.find(i=>i.id===Fe)||null,Qn=Be?{key:Be.id,url:Be.previewUrl,name:Be.file.name,size:Be.file.size,file:Be.file,onRemove:()=>St(Be.id)}:Ue?{key:Ue,url:Ue}:null,pn=(!!H.trim()||X.length>0)&&!I&&!!Ne,Dt=()=>{re(null),je(null),Ie(null),jt(void 0)},Ft=r.useCallback(async(i,x,b)=>{const S=i==="gemini"?"":b||"";if(Ae!==void 0)try{await fetch(`/api/models/agents/${i}/active`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileId:Ae})}),at(),Pe()}catch{}tt(i),bt(x),vt(S),Dt(),ee("closed")},[Ae,at,Pe]),Jn=()=>{P==="closed"?(Dt(),Pe(),at(),ee("agent")):(Dt(),ee("closed"))},Ut=Z||Ne,xn=Yt(Ut),zt=_??pt,Ve=q??Lt,Xn=zt?sn(zt):"",Ge=(()=>{const i=kt[Ut];return i?de.find(x=>x.id===i)??null:null})(),qe=Ge?lt.find(i=>i.id===Ge.providerId)??null:null,Yn=qe?Fs(qe):null,Ht=Ge&&Ge.name.trim().toLowerCase()!==Ge.modelId.trim().toLowerCase()?Ge.name:Xn,Zn=[xn.shortLabel,qe?qe.name:null,Ht||null,Ve?Ve.charAt(0).toUpperCase()+Ve.slice(1):null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:wt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[y&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[u&&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(ue,{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:c("hub.running")}),e.jsxs("button",{onClick:se,disabled:F,title:c("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:[F?e.jsx(ue,{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"})}),c("hub.stop")]})]}),h.map((i,x)=>{const b=x===h.length-1,S=h.length>1?`${c("hub.queued")} #${x+1}`:c("hub.queued"),O=L?.find(ie=>ie.taskId===i)||(b?L?.find(ie=>!ie.taskId):void 0),Se=j?.find(ie=>ie.taskId===i)?.prompt||O?.prompt||null,oe=O?.imageUrls?.length?O.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}),oe.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[oe.slice(0,3).map((ie,Kt)=>e.jsx("button",{type:"button",onClick:()=>nt(ie),title:c("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:ie,alt:"",className:"h-full w-full object-cover"})},`${ie}-${Kt}`)),oe.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",oe.length-3]})]}),Se&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:Se})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>dt(i),disabled:ae.has(i),title:c("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:[ae.has(i)?e.jsx(ue,{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"})}),c("hub.steer")]}),e.jsxs("button",{onClick:()=>C(i),disabled:le.has(i),title:c("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(i)?e.jsx(ue,{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"})]}),c("hub.recall")]})]})]},i)})]}),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:st,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:i=>{ct(i.target.files),i.target.value=""}}),X.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:X.map(i=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>Te(i.id),title:c("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:i.previewUrl,alt:i.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:i.file.name})})]}),e.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),St(i.id)},title:c("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"})]})})]},i.id))})}),K&&xe.length>0&&e.jsxs("div",{ref:_e,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:c("hub.skills")})}),e.jsx("div",{className:"py-1",children:xe.map((i,x)=>e.jsxs("button",{"data-skill-idx":x,onMouseDown:b=>{b.preventDefault(),hn(i)},onMouseEnter:()=>ne(x),className:M("flex flex-col w-full px-3 py-1.5 text-left transition-colors",x===ye?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",i.name]}),(i.label||i.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:i.label||i.description})]},i.name))})]}),e.jsx("textarea",{ref:te,value:H,onChange:i=>zn(i.target.value),onPaste:Kn,onKeyDown:Hn,onCompositionStart:()=>{Re.current=!0},onCompositionEnd:()=>{Re.current=!1},placeholder:c("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:H.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:()=>st.current?.click(),title:c("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:ze,onClick:Jn,disabled:!B.length,title:B.length?Zn: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",P!=="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:[B.length?e.jsx(Je,{brand:Ut,size:12}):e.jsx(ue,{className:"h-3 w-3"}),B.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:xn.shortLabel}),qe&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(Je,{brand:Yn||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:qe.name})]}),Ht&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:zt||void 0,children:Ht})]}),Ve&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"shrink-0",children:Ve.charAt(0).toUpperCase()+Ve.slice(1)})]})]}):e.jsx("span",{className:"max-w-[420px] truncate",children:c("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",P!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),P!=="closed"&&he&&on.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:he.left,bottom:he.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:[P!=="agent"&&e.jsx("button",{onClick:()=>{if(P==="effort"){const i=ht?.capabilities?.modelSwitch!==!1;ee(i?"model":"agent")}else ee("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:c(P==="agent"?"hub.selectAgent":P==="model"?"hub.selectModel":"hub.selectEffort")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const x=ht?.capabilities?.modelSwitch!==!1?["agent","model","effort"]:["agent","effort"],b=x.indexOf(P);return x.map((S,O)=>e.jsx("span",{className:M("w-1.5 h-1.5 rounded-full transition-colors",P===S?"bg-primary":O<b?"bg-primary/40":"bg-fg-5/15")},S))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[P==="agent"&&B.filter(i=>i.installed).map(i=>{const x=Yt(i.agent);return e.jsxs(Jt,{selected:i.agent===(Z||Ne),onClick:()=>{if(re(i.agent),je(i.selectedModel||""),Ie(i.selectedEffort||""),!(i.capabilities?.modelSwitch!==!1)){(Vt[i.agent]||[]).length?ee("effort"):Ft(i.agent,i.selectedModel||"",null);return}ee("model")},children:[e.jsx(Je,{brand:i.agent,size:14}),e.jsx("span",{style:{color:x.color},children:x.label})]},i.agent)}),P==="model"&&e.jsxs(e.Fragment,{children:[Ct.map((i,x)=>{const b=x===0&&i.kind==="native",S=x===Vn&&i.kind==="profile",O=Ae!==void 0?Ae:Gn,Se=i.kind==="profile"?!!i.profileId&&i.profileId===O:!O&&i.id===(_??pt);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:c("hub.modelGroupNative")}),S&&e.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:c("hub.modelGroupProfiles")}),e.jsx(Jt,{selected:Se,onClick:()=>{const oe=Z||Ne;if(je(i.id),jt(i.profileId??null),Vt[oe]?.length){ee("effort");return}Ft(oe,i.id,null)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:M("truncate text-[11.5px]",i.kind==="native"&&"font-mono text-[11px]"),title:i.id,children:i.label}),i.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:i.description})]})})]},`${i.kind}:${i.profileId||i.id}`)}),Ct.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:c("config.noModel")})]}),P==="effort"&&qn.map(i=>e.jsx(Jt,{selected:i===(q||Lt),onClick:()=>{Ie(i),Ft(Z||Ne,_??pt,i)},children:i.charAt(0).toUpperCase()+i.slice(1)},i))]})]}),document.body),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:o,disabled:!pn,className:M("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",pn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:I?e.jsx(ue,{className:"h-3.5 w-3.5"}):e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})]}),e.jsx(zs,{source:Qn,onClose:()=>{Te(null),nt(null)},t:c})]})});function zs({source:t,onClose:n,t:s}){const[l,a]=r.useState(!1);if(r.useEffect(()=>{a(!1)},[t?.key]),r.useEffect(()=>{if(!t)return;const c=m=>{m.key==="Escape"&&n()};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,n]),!t)return null;const d=t.file,p=t.onRemove;return on.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:c=>c.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:Ps(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[d&&e.jsx("button",{type:"button",onClick:async()=>{await Ws(d)&&(a(!0),window.setTimeout(()=>a(!1),1600))},className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s(l?"hub.copied":"hub.copyImage")}),p&&e.jsx("button",{type:"button",onClick:p,className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s("hub.removeImage")}),e.jsx("button",{type:"button",onClick:n,className:"flex h-9 w-9 items-center justify-center rounded-full border border-white/12 bg-white/10 text-white/88 transition-colors hover:bg-white/14",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-white/10 bg-black/35 shadow-[0_20px_70px_rgba(0,0,0,0.45)]",children:e.jsx("img",{src:t.url,alt:t.name||"",className:"max-h-[80vh] w-full object-contain"})})]})}),document.body)}function Jt({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 Hs(){return function(t){ds(t)}}const dn=[us,Hs],Ks=t=>/^https?:\/\//.test(t),mn=t=>/^(\/|~\/|\.\.?\/)/.test(t);function Vs({text:t}){const[n,s]=r.useState(!1),l=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:l,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function bn(t){const n=/^[.~/].*\.\w+$/.test(t)||/^[a-z][\w-]*\//.test(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"}const un={h1:({children:t})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:t}),h2:({children:t})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:t}),h3:({children:t})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:t}),p:({children:t})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:t}),strong:({children:t})=>e.jsx("strong",{className:"font-semibold text-fg",children:t}),em:({children:t})=>e.jsx("em",{className:"italic text-fg-3",children:t}),a:({href:t,children:n})=>t&&Ks(t)?e.jsx("a",{href:t,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:n}):t&&mn(t)?e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",onClick:()=>Q.openInEditor(t),children:n}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:n}),ul:({children:t})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:t}),ol:({children:t})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:t}),li:({children:t})=>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:t})]}),blockquote:({children:t})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:t}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:t,children:n,...s})=>{const l=String(n).replace(/\n$/,""),a=/language-(\w+)/.exec(t||"");if(!a&&!t&&!l.includes(`
|
|
10
|
-
`))return mn(l)?e.jsx("code",{className:M("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",bn(l)),onClick:()=>Q.openInEditor(l),children:l}):e.jsx("code",{className:M("px-1.5 py-[1px] rounded text-[12px] font-mono border",bn(l)),children:l});const d=a?.[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:d||"text"}),e.jsx(Vs,{text:l})]}),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:l})})]})},pre:({children:t})=>e.jsx(e.Fragment,{children:t}),table:({children:t})=>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:t})}),thead:({children:t})=>e.jsx("thead",{className:"bg-[rgba(0,0,0,0.1)]",children:t}),th:({children:t})=>e.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-fg-3 border-b border-edge/30",children:t}),td:({children:t})=>e.jsx("td",{className:"px-3 py-1.5 text-fg-4 border-t border-edge/12",children:t}),tr:({children:t})=>e.jsx("tr",{className:"even:bg-[rgba(255,255,255,0.015)]",children:t})};function Ze(t){return!!t?.steps?.length}function Gs(t,n){let s=t;for(const[l,a]of Object.entries(n))s=s.replace(new RegExp(`\\{${l}\\}`,"g"),a);return s}function qs({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 Rn({plan:t,t:n,className:s}){const[l,a]=r.useState(!1);if(!Ze(t))return null;const d=t.steps.length,p=t.steps.filter(v=>v.status==="completed").length,c=d>0&&p===d,m=Gs(n("hub.planProgress"),{done:String(p),total:String(d)});return e.jsx(Ye,{open:l,onToggle:()=>a(v=>!v),dot:{color:c?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!c},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",c?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(c?"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(qs,{status:v.status})}),e.jsx("span",{className:M("text-[12px] leading-[1.5]",j),children:v.step})]},`${g}:${v.step}`)})})})}function _n(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
|
|
11
|
-
`).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||Ze(t.plan)||!!(t.subAgents&&t.subAgents.length)}function Gr(t){return _n(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function Qs(t){return t.phase!=="done"||!t.error?null:_n(t)?"hub.streamErrored":"hub.streamFailed"}function Js({detail:t,t:n,className:s}){const l=Rs(t);if(l==="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 a=l==="error"?{dot:"bg-rose-400/55",text:"text-rose-300/65"}:{dot:"bg-fg-5/40",text:"text-fg-5/55"};return e.jsxs("div",{className:M("flex items-start gap-1.5 text-[11px] leading-[1.6]",a.text,s),children:[e.jsx("span",{className:M("mt-[5px] h-1 w-1 rounded-full shrink-0",a.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}function qr({stream:t,t:n}){const s=Ze(t.plan),[l,a]=r.useState(!1),[d,p]=r.useState(!1),c=r.useRef(null),m=r.useRef(null),v=Qs(t),g=r.useMemo(()=>(t.activity||"").split(`
|
|
12
|
-
`).filter(Boolean),[t.activity]),j=t.previewMeta?.toolCalls??[],L=g[g.length-1]||j[j.length-1]?.summary||"";r.useLayoutEffect(()=>{const N=c.current;N&&l&&(N.scrollTop=N.scrollHeight)},[l,t.activity,j.length]),r.useLayoutEffect(()=>{const N=m.current;N&&d&&(N.scrollTop=N.scrollHeight)},[d,t.thinking]);const k=t.subAgents??null;return e.jsxs("div",{className:"space-y-3 animate-in",children:[s&&e.jsx(Rn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),k&&k.length>0&&k.map(N=>e.jsx(Pn,{sub:N,t:n},N.id)),(j.length>0||g.length>0)&&e.jsx(Ye,{open:l,onToggle:()=>a(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:L}),badge:(j.length||g.length)>1?e.jsx(rn,{children:j.length||g.length}):void 0,children:e.jsx("div",{ref:c,className:"px-3.5 py-2.5 space-y-0.5 max-h-[280px] overflow-y-auto",children:j.length>0?j.map(N=>e.jsx(Xs,{call:N},N.id)):g.map((N,T)=>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))})}),t.thinking&&e.jsx(Ye,{open:d,onToggle:()=>p(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:In(t.thinking,3)}),children:e.jsx("div",{ref:m,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:[e.jsx(ln,{remarkPlugins:dn,components:un,children:t.text}),t.phase==="streaming"&&e.jsx(en,{className:"ml-1 inline-flex align-text-bottom text-fg-4"})]}),!t.text&&t.phase==="streaming"&&e.jsx("div",{className:"py-1",children:e.jsx(en,{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…`})]}),v&&t.error&&e.jsx(Js,{detail:t.error,t:n,className:"pt-0.5"})]})}function Xs({call:t}){const[n,s]=r.useState(!1),l=!!(t.input||t.result),a=t.status==="failed"?"bg-rose-400/70":t.status==="running"?"bg-cyan-400/70":"bg-fg-5/30";return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>l&&s(d=>!d),className:`flex w-full items-center gap-1.5 py-[2px] text-left min-w-0 ${l?"cursor-pointer hover:bg-white/[0.03] rounded":"cursor-default"}`,title:l?void 0:t.summary,children:[e.jsx("span",{className:`w-1 h-1 rounded-full shrink-0 ${a} ${t.status==="running"?"animate-pulse":""}`}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate flex-1",children:t.summary}),l&&e.jsx("span",{className:`shrink-0 text-[9px] text-fg-5/40 transition-transform ${n?"rotate-90":""}`,children:"▸"})]}),n&&e.jsxs("div",{className:"ml-2.5 mt-0.5 mb-1 space-y-1 border-l border-white/[0.06] pl-2.5",children:[t.input&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-4/80 max-h-[140px] overflow-y-auto",children:t.input}),t.result&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-5/70 max-h-[140px] overflow-y-auto border-t border-white/[0.04] pt-1",children:t.result})]})]})}function en({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 Pn({sub:t,t:n}){const[s,l]=r.useState(!1),a=t.status,d=a==="failed"?"bg-rose-400/60":a==="done"?"bg-emerald-400/55":"bg-amber-400/60",p=a==="running",c=t.tools,m=r.useMemo(()=>{const j=new Set,L=[];for(const k of c)j.has(k.name)||(j.add(k.name),L.push(k.name));return L},[c]),v=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",g=t.model?sn(t.model):null;return e.jsx(Ye,{open:s,onToggle:()=>l(j=>!j),dot:{color:d,pulse:p},label:v,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),g&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:g}),!t.description&&m.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:m.join(" · ")})]}),badge:c.length>0?e.jsx(rn,{children:c.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}),c.length===0?e.jsxs("div",{className:"text-[11px] font-mono text-fg-5/50",children:["— ",n("hub.subAgentWaiting")||"waiting for first tool…"]}):c.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 Ys({message:t,t:n}){const{activityBlocks:s,thinkingBlocks:l,planBlocks:a,subAgentBlocks:d,outputBlocks:p,noticeBlocks:c}=Wn(t.blocks),m=[...a].reverse().find(g=>Ze(g.plan));return s.length>0||d.length>0||!!m?.plan||l.length>0||p.length>0||c.length>0?e.jsxs("div",{className:"space-y-3",children:[s.length>0&&e.jsx(tr,{blocks:s,t:n}),d.map(g=>g.subAgent?e.jsx(Pn,{sub:g.subAgent,t:n},g.toolId||g.subAgent.id):null),m?.plan&&e.jsx(Rn,{plan:m.plan,t:n,className:"max-w-[760px]"}),l.length>0&&e.jsx(sr,{blocks:l,t:n}),p.length>0&&e.jsx(ir,{blocks:p,t:n}),c.length>0&&e.jsx(er,{blocks:c,t:n})]}):null}function Zs(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:l,subAgentBlocks:a,outputBlocks:d,noticeBlocks:p}=Wn(t.blocks);return d.length>0||n.length>0||a.length>0||s.length>0||l.some(c=>Ze(c.plan))||p.length>0}function Wn(t){const n=t.filter(s=>s.type==="plan"||s.type==="tool_use"||s.type==="tool_result"||s.type==="image"||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"&&Ze(s.plan)),subAgentBlocks:n.filter(s=>s.type==="sub_agent"),outputBlocks:n.filter(s=>s.type==="text"||s.type==="image"),noticeBlocks:n.filter(s=>s.type==="system_notice")}}function er({blocks:t,t:n}){const s=t.map(l=>l.content).filter(Boolean).join(`
|
|
13
|
-
|
|
14
|
-
`).trim();return s?e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/[0.06] px-3 py-2 text-[12.5px] leading-[1.7] text-fg-3",children:[e.jsx("span",{className:"mt-[6px] h-1.5 w-1.5 rounded-full bg-amber-400/70 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-mono uppercase tracking-wide text-amber-300/80",children:n("hub.systemNotice")||"Agent notice"}),e.jsx("div",{className:"mt-0.5 break-words whitespace-pre-wrap",children:s})]})]}):null}function tr({blocks:t,t:n}){const[s,l]=r.useState(!1),a=t.filter(m=>m.type==="tool_use"),d=a.length,p=a[a.length-1],c=p?An(p):"";return e.jsx(Ye,{open:s,onToggle:()=>l(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:c}),badge:d>0?e.jsx(rn,{children:d}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((m,v)=>e.jsx(nr,{block:m},v))})})}function nr({block:t}){const[n,s]=r.useState(!1),l=t.type==="tool_use",a=l?An(t):Os(t);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&s(d=>!d),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",l?"bg-fg-5/40":"bg-ok/40")}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 group-hover:text-fg-3 transition-colors truncate",children:a})]}),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 sr({blocks:t,t:n}){const[s,l]=r.useState(!1),a=r.useRef(null),d=t.map(c=>c.content).filter(Boolean).join(`
|
|
16
|
-
|
|
17
|
-
`).trim();if(!d)return null;const p=In(d,3);return e.jsx(Ye,{open:s,onToggle:()=>l(c=>!c),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:p?e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:p}):void 0,children:e.jsx(rr,{scrollRef:a,text:d})})}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 or({block:t,onLightbox:n,t:s}){const l=t.imageCaption?.trim()||"",[a,d]=r.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:l||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),l&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>d(p=>!p),"aria-expanded":a,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(a?"hub.imagePromptHide":"hub.imagePromptShow"),children:[e.jsx("span",{"aria-hidden":!0,className:"text-[9px] leading-none",children:a?"▾":"▸"}),e.jsx("span",{children:s("hub.imagePrompt")})]}),a&&e.jsx("div",{className:"rounded-md border border-fg-6/30 bg-fg-6/[0.05] px-3 py-2 max-w-[400px] max-h-[260px] overflow-y-auto",children:e.jsx("div",{className:"text-[11.5px] leading-[1.65] text-fg-3 whitespace-pre-wrap break-words",children:l})})]})]})}function ir({blocks:t,t:n}){const s=t.filter(c=>c.type==="text"),l=t.filter(c=>c.type==="image"),a=s.map(c=>c.content).filter(Boolean).join(`
|
|
18
|
-
|
|
19
|
-
`),[d,p]=r.useState(null);return!a.trim()&&l.length===0?null:e.jsxs(e.Fragment,{children:[a.trim()&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:e.jsx(ln,{remarkPlugins:dn,components:un,children:a})}),l.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:l.map((c,m)=>e.jsx(or,{block:c,onLightbox:p,t:n},m))}),d&&e.jsx(Bn,{src:d,onClose:()=>p(null)})]})}const Qr=r.memo(function({turn:n,turnIndex:s,agent:l,meta:a,model:d,effort:p,providerName:c,t:m,onResend:v,onEdit:g,onFork:j}){const L=n.user&&Tn(n.user.text),k=j&&typeof s=="number"?()=>j(s):void 0,N=!!n.assistant&&Zs(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!L&&e.jsx(On,{text:n.user.text,blocks:n.user.blocks,t:m,onResend:v,onEdit:g,onFork:k}),L&&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(ln,{remarkPlugins:dn,components:un,children:n.user.text})}),N&&e.jsxs(e.Fragment,{children:[e.jsx(dr,{agent:l,meta:a,model:d,effort:p,providerName:c,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(Ys,{message:n.assistant,t:m})})]})]})});function Bn({src:t,onClose:n}){return r.useEffect(()=>{const s=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),on.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 lr=1500,ar=16,vn=8;function cr(t){const n=t.split(`
|
|
20
|
-
`);return n.length<=vn?t:n.slice(0,vn).join(`
|
|
21
|
-
`)}function On({text:t,blocks:n,t:s,onResend:l,onEdit:a,onFork:d}){const[p,c]=r.useState(!1),[m,v]=r.useState(!1),[g,j]=r.useState(null),L=t?t.split(`
|
|
22
|
-
`).length:0,k=!!t&&(t.length>lr||L>ar),[N,T]=r.useState(!1),A=t?k&&!N?cr(t):t:"",W=!!(l||a||d),$=n?.filter(I=>I.type==="image")||[],H=()=>{navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),1500)}).catch(()=>{})},R=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(L));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[A,k&&!N&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),k&&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:N?s("hub.collapse"):R}),$.length>0&&e.jsx("div",{className:M("flex flex-wrap gap-2",t&&"mt-2"),children:$.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(Bn,{src:g,onClose:()=>j(null)}),W&&e.jsxs("div",{className:M("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",p?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(Mt,{label:s(m?"hub.copied":"hub.copy"),onClick:H,children:m?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),l&&e.jsx(Mt,{label:s("hub.rerun"),onClick:()=>l(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),a&&e.jsx(Mt,{label:s("hub.edit"),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("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"})]})}),d&&e.jsx(Mt,{label:s("hub.fork"),onClick:d,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 Mt({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 dr({agent:t,meta:n,model:s,effort:l,providerName:a,previewMeta:d,liveStartedAt:p}){const c=d?.contextPercent??null,m=d?.contextUsedTokens??0,v=d?.turnOutputTokens??0,g=c!=null||m>0||v>0,j=p!=null&&p>0,L=d?.providerName??a??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(Je,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||l)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&l?" · ":"",l||""]}),L&&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 ${L} (BYOK), not the agent CLI's native auth.`,children:["via ",L]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:xr(d),children:[c!=null&&e.jsx(fr,{pct:c}),e.jsx("span",{children:c!=null?`${c.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",pr(m)]}),v>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",$n(v)]}),j&&e.jsx(ur,{startedAt:p,leadingDot:g})]})]})}function ur({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const a=setInterval(()=>s(d=>d+1),1e3);return()=>clearInterval(a)},[]);const l=Math.max(0,Date.now()-t);return e.jsxs("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:[n?"· ":"",hr(l)]})}function hr(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),l=n%60;return s<60?`${s}m${l.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function pr(t){return`${$n(t)} tok`}function $n(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function xr(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 fr({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 jn(t,n,s){return t==="zh-CN"?n:s}function gr({open:t,onClose:n,workdir:s}){const l=ge(d=>d.locale),a=s.split("/").pop()||s;return e.jsxs(_t,{open:t,onClose:n,wide:!0,children:[e.jsx(Pt,{title:jn(l,`${a} — 项目扩展`,`${a} — Project Extensions`),description:jn(l,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiclaw/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiclaw/skills/ in the workspace directory."),onClose:n}),t?e.jsx(hs,{workdir:s}):null]})}let wn=Nn(()=>import("./SessionPanel-GZ3iSdWI.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]));function tn(){return wn??=Nn(()=>import("./SessionPanel-GZ3iSdWI.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10])),wn}const mr=r.lazy(async()=>({default:(await tn()).SessionPanel})),Xt=5,br=240,vr=120,jr=12,wr=900*1e3,D=(t,n)=>`${t}:${n}`;function kr(t){const n=new Map;for(const c of t)n.set(D(c.agent||"",c.sessionId),c);const s=new Map,l=new Set;for(const c of t){const m=c.migratedFrom;if(!m||m.kind!=="fork"||!m.sessionId)continue;const v=D(m.agent||c.agent||"",m.sessionId);n.has(v)&&(l.add(D(c.agent||"",c.sessionId)),s.has(v)||s.set(v,[]),s.get(v).push(c))}const a=[],d=new Set,p=(c,m)=>{const v=D(c.agent||"",c.sessionId);if(d.has(v))return;d.add(v),a.push(Object.assign({},c,{__forkDepth:m}));const g=s.get(v);if(g)for(const j of g)p(j,m+1)};for(const c of t){const m=D(c.agent||"",c.sessionId);l.has(m)||p(c,0)}for(const c of t)p(c,0);return a}let yr=0;function Tt(){return`mk-${Date.now().toString(36)}-${(++yr).toString(36)}`}function Nr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Sr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function Dn(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 Cr=r.memo(function({active:n=!0}){const s=ge(o=>o.locale),l=ge(o=>o.state?.runtimeWorkdir??null),a=r.useMemo(()=>ss(s),[s]),[d,p]=r.useState([]),[c,m]=r.useState({}),[v,g]=r.useState({}),[j,L]=r.useState(!0),[k,N]=r.useState(()=>{try{const u=sessionStorage.getItem("pikiclaw-layout-mode");if(u==="1"||u==="2"||u==="3"||u==="6")return Number(u)}catch{}const o=window.innerWidth;return o>=1920?3:o>=1280?2:1}),[T,A]=r.useState(()=>{try{const o=sessionStorage.getItem("pikiclaw-open-sessions");if(o){const u=JSON.parse(o);if(Array.isArray(u))return u.map(h=>({...h,mountKey:h.mountKey||Tt()}))}}catch{}return[]}),[W,$]=r.useState(()=>{try{const o=sessionStorage.getItem("pikiclaw-active-slot");if(o!=null){const u=Number(o);if(Number.isFinite(u)&&u>=0)return u}}catch{}return 0}),H=r.useCallback(o=>{N(o);try{sessionStorage.setItem("pikiclaw-layout-mode",String(o))}catch{}},[]),R=r.useCallback(o=>{A(u=>{const h=typeof o=="function"?o(u):o;try{const f=h.map(({pendingPrompt:w,pendingImageUrls:y,...C})=>C);sessionStorage.setItem("pikiclaw-open-sessions",JSON.stringify(f))}catch{}return h})},[]),I=r.useCallback(o=>{$(u=>{const h=typeof o=="function"?o(u):o;try{sessionStorage.setItem("pikiclaw-active-slot",String(h))}catch{}return h})},[]);r.useEffect(()=>{R(o=>o.length>k?o.slice(0,k):o),I(o=>o>=k?k-1:o)},[k]);const[z,E]=r.useState(!1),J=r.useRef(k);J.current=k;const le=r.useRef(W);le.current=W;const Ee=r.useRef(-1),ae=T[W]??null,et=r.useCallback(o=>{if(!o){R([]),I(0);return}const u=o.mountKey?o:{...o,mountKey:Tt()};R(h=>{const f=h.findIndex(y=>y.agent===u.agent&&y.sessionId===u.sessionId);if(f>=0)return I(f),h;if(h.length<J.current){const y=[...h,u];return I(y.length-1),y}const w=[...h];return w[le.current]=u,w})},[]),[me,be]=r.useState(!1),[B,De]=r.useState(null),[Me,tt]=r.useState(""),[ve,bt]=r.useState("all"),[ce,vt]=r.useState({}),X=r.useDeferredValue(Me),Y=r.useRef(!1),Fe=r.useRef({}),Te=r.useRef(c);Te.current=c;const Ue=r.useRef(ce);Ue.current=ce;const nt=r.useRef(new Set),Z=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values(Z.current))clearTimeout(o)},[]);const re=r.useCallback(async()=>{try{const o=await Q.getWorkspaces(),u=o.ok?o.workspaces:[];u.length&&p(h=>h.length===u.length&&h.every((f,w)=>f.path===u[w].path&&f.name===u[w].name)?h:u),Y.current=!0}catch{Y.current=!0}finally{L(!1)}},[]);r.useEffect(()=>{re()},[re]);const _=r.useCallback(async(o,u={})=>{if(!Fe.current[o]){Fe.current[o]=!0,u.background||g(h=>({...h,[o]:!0}));try{const h=await ms(o,{force:u.force});r.startTransition(()=>{m(f=>{const w=h.sessions||[],y=f[o]||[],C=new Set(w.map(U=>D(U.agent||"",U.sessionId))),F=y.filter(U=>{if(U.runState!=="running")return!1;const se=D(U.agent||"",U.sessionId);if(C.has(se))return!1;const dt=Ue.current[se];return!(dt?.resolvedKey&&dt.resolvedKey!==se)});return{...f,[o]:F.length?[...F,...w]:w}})})}catch{u.background||r.startTransition(()=>{m(h=>({...h,[o]:[]}))})}finally{Fe.current[o]=!1,u.background||g(h=>({...h,[o]:!1}))}}},[]),je=r.useRef(l);r.useEffect(()=>{l!==je.current&&(je.current=l,!(!l||!Y.current)&&re().then(()=>{_(l,{force:!0})}))},[l,re,_]);const q=r.useCallback((o,u)=>{const h=o.agent||"";!h||!o.sessionId||(tn(),js({workdir:u,agent:h,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:jr}))},[]),Ie=r.useCallback((o,u,h=vr)=>{const f=`${u}:${D(o.agent||"",o.sessionId)}`,w=Z.current[f];w&&clearTimeout(w),Z.current[f]=setTimeout(()=>{delete Z.current[f],q(o,u)},h)},[q]),Ae=r.useCallback((o,u)=>{const h=`${u}:${D(o.agent||"",o.sessionId)}`,f=Z.current[h];f&&(clearTimeout(f),delete Z.current[h])},[]);r.useEffect(()=>{n&&tn()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return d.forEach((u,h)=>{if(c[u.path]||v[u.path])return;const f=setTimeout(()=>{_(u.path)},h*90);o.push(f)}),()=>{for(const u of o)clearTimeout(u)}},[n,_,v,c,d]);const jt=r.useRef(new Map);gn(n&&Y.current&&d.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const u=o.key,h=u?d.filter(y=>(Te.current[y.path]||[]).some(C=>D(C.agent||"",C.sessionId)===u)):d,f=h.length?h:d,w=jt.current;for(const y of f)w.has(y.path)&&clearTimeout(w.get(y.path)),w.set(y.path,setTimeout(()=>{w.delete(y.path),_(y.path,{background:!0,force:!0})},300))},[d,_]));const P=r.useCallback(o=>{const u=o.agent||"";return!u||!o.sessionId?o:rs(o,ce[D(u,o.sessionId)]||null)},[ce]);gn("stream-update",r.useCallback(o=>{const u=o.key;u&&vt(h=>{const f={},w=Date.now()-wr;for(const[C,F]of Object.entries(h))F.updatedAt>=w&&(f[C]=F);const y=os(u,o.snapshot??null);if(!y){const C=f[u];return C&&C.phase!=="done"&&(f[u]={...C,phase:"done",updatedAt:Date.now()}),f}return f[u]=y,y.resolvedKey!==u&&(f[y.resolvedKey]={...y,key:y.resolvedKey}),f})},[])),Es(r.useCallback(()=>{if(!(!n||!Y.current||d.length===0))for(const o of d)_(o.path,{background:!0,force:!0})},[n,d,_])),r.useEffect(()=>{if(!n||!Y.current||d.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const h of d)_(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,_,d]),r.useEffect(()=>{if(!n)return;const o=[];return d.forEach((u,h)=>{const f=(c[u.path]||[])[0];if(!f)return;const w=`${u.path}:${D(f.agent||"",f.sessionId)}`;if(nt.current.has(w))return;const y=setTimeout(()=>{nt.current.add(w),q(f,u.path)},br+h*120);o.push(y)}),()=>{for(const u of o)clearTimeout(u)}},[n,c,q,d]);const ee=r.useCallback(async o=>{try{(await Q.addWorkspace(o)).ok&&(be(!1),await re(),_(o))}catch{}},[re,_]),[he,we]=r.useState(null),[te,Re]=r.useState(!1),[st,wt]=r.useState(null),ze=r.useCallback(o=>{we(o)},[]),rt=r.useCallback(async()=>{const o=he;if(o){Re(!0);try{await Q.removeWorkspace(o),p(u=>u.filter(h=>h.path!==o)),m(u=>{const h={...u};return delete h[o],h}),R(u=>u.filter(h=>h.workdir!==o)),I(0),we(null)}catch{}finally{Re(!1)}}},[he]),ot=r.useCallback(o=>{_(o,{force:!0})},[_]),[ke,K]=r.useState(null),[pe,ye]=r.useState(!1),[ne,_e]=r.useState(!1),Pe=ge(o=>o.toast),[de,it]=r.useState(null),lt=r.useCallback((o,u,h)=>{it({anchor:{right:o.right,bottom:o.bottom},target:{workdir:h,agent:u.agent||"",sessionId:u.sessionId,title:kn(u).slice(0,120)||u.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!de)return;const o=()=>it(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)}},[de]);const Bt=r.useCallback(o=>{ye(!1),K(o),it(null)},[]),kt=r.useCallback(async()=>{const o=ke;if(o){_e(!0);try{const u=await Q.deleteSession(o.workdir,o.agent,o.sessionId,pe);if(!u.ok){const h=u.error?.includes("still running")?a("session.deleteRunningError"):u.error||a("session.deleteFailed");Pe(h,!1);return}m(h=>{const f=h[o.workdir];if(!f)return h;const w=f.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return w.length===f.length?h:{...h,[o.workdir]:w}}),R(h=>h.filter(f=>!(f.workdir===o.workdir&&f.agent===o.agent&&f.sessionId===o.sessionId))),K(null)}catch(u){Pe(u?.message||a("session.deleteFailed"),!1)}finally{_e(!1)}}},[ke,pe,a,Pe]),Ot=r.useCallback(o=>{R(u=>{let h=!1;const f=u.map(w=>w.mountKey===o&&(w.pendingPrompt!=null||w.pendingImageUrls)?(h=!0,{...w,pendingPrompt:null,pendingImageUrls:void 0}):w);return h?f:u})},[R]),at=r.useCallback((o,u,h)=>{q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),m(y=>{const C=y[o.workdir]||[];if(C.some(se=>se.sessionId===o.sessionId&&se.agent===o.agent))return y;const U={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:u,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[U,...C]}});const f=Ee.current,w={...o,mountKey:Tt(),pendingPrompt:u||null,pendingImageUrls:h&&h.length?h:void 0};r.startTransition(()=>{De(null),R(y=>{if(f>=y.length)return[...y,w];const C=[...y];return C[f]=w,C}),I(f>=0?f:0)}),_(o.workdir,{background:!0,force:!0})},[_,q,R,I]),We=r.useCallback((o,u)=>{q(o,u),De(null),r.startTransition(()=>{et({agent:o.agent||"",sessionId:o.sessionId,workdir:u})})},[q]),He=r.useCallback((o,u)=>{q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{u!=null?(R(h=>{if(u>=h.length)return h;const f=[...h];return f[u]={...h[u],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},f}),I(u)):et({...o,mountKey:Tt()})}),_(o.workdir,{background:!0,force:!0})},[_,q]),Ke=r.useCallback(o=>{let u=o;if(ve==="running"?u=u.filter(h=>It(h)==="running"):ve==="review"&&(u=u.filter(h=>It(h)==="incomplete")),X.trim()){const h=X.toLowerCase();u=u.filter(f=>(f.lastMessageText||"").toLowerCase().includes(h)||(f.lastQuestion||"").toLowerCase().includes(h)||(f.lastAnswer||"").toLowerCase().includes(h)||(f.title||"").toLowerCase().includes(h)||(f.agent||"").toLowerCase().includes(h))}return u},[X,ve]),xe=r.useMemo(()=>{const o={};for(const u of d){const h=(c[u.path]||[]).map(P),f=new Map;for(const y of h){const C=D(y.agent||"",y.sessionId),F=ce[C],U=F?.resolvedKey&&F.resolvedKey!==C?F.resolvedKey:C,se=f.get(U);if(!se){f.set(U,y);continue}D(se.agent||"",se.sessionId)!==U&&C===U&&f.set(U,y)}const w=Ke([...f.values()]);o[u.path]=kr(w)}return o},[d,c,ce,Ke,P]),yt=r.useCallback(o=>{const u=(c[o.workdir]||[]).find(h=>h.sessionId===o.sessionId&&h.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return P(u)},[P,c]),ct=r.useMemo(()=>new Set(T.map(o=>D(o.agent,o.sessionId))),[T]),Nt=ae?D(ae.agent,ae.sessionId):null,St=r.useCallback(o=>{R(u=>{const h=u.filter((f,w)=>w!==o);return h.length===0?I(0):le.current>=h.length&&I(h.length-1),h})},[]);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:Me,onChange:o=>tt(o.target.value),placeholder:a("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"}),Me&&e.jsx("button",{onClick:()=>tt(""),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:()=>bt(o),className:M("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",ve===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:a(`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(ue,{className:"h-4 w-4 text-fg-5"})}):d.length===0&&!me?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:a("hub.noWorkspaces")}):d.map(o=>e.jsx(Mr,{workspace:o,sessions:xe[o.path]||[],loading:!!v[o.path]||!(o.path in c),isActive:o.path===l,selectedKey:Nt,openSessionKeys:ct,onSelectSession:We,onNewSession:De,onRefresh:ot,onRemove:ze,onExtensions:wt,onWarmSession:Ie,onCancelWarmSession:Ae,onSessionMenuOpen:lt,t:a},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:()=>H(o),className:M("flex-1 flex items-center justify-center p-1.5 rounded transition-all",k===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:a(`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(Ce,{variant:"ghost",size:"sm",onClick:()=>be(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"})]}),a("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(${k===6?3:k}, 1fr)`,gridTemplateRows:k===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=B?T.length<k?T.length:W:-1;return Ee.current=o,Array.from({length:k},(u,h)=>{if(B&&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(Er,{workdir:B,workspaceName:d.find(C=>C.path===B)?.name||B.split("/").pop()||"",onSessionCreated:at,onClose:()=>De(null),t:a},B)},`new-${B}`);const f=T[h]??null;if(!f)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:a("hub.emptySlot")})]})},`empty-${h}`);const w=yt(f),y=h===W;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",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>I(h),children:[e.jsxs("div",{className:M("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const C=It(w);return e.jsx(Wt,{variant:C==="running"?"ok":C==="waiting"?"info":C==="incomplete"?"warn":"idle",pulse:C==="running"||C==="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:f.workdir.split("/").pop()||f.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)||f.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:a("hub.created"),children:is(w.createdAt)}),w.runUpdatedAt&&e.jsx("span",{title:a("hub.updated"),children:yn(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:C=>{C.stopPropagation(),E(F=>!F)},className:M("p-0.5 rounded transition-colors",z?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:a("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:C=>{C.stopPropagation(),St(h)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:a("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(mr,{session:w,workdir:f.workdir,active:n&&y,onSessionChange:C=>He(C,h),initialPendingPrompt:f.pendingPrompt??null,initialPendingImageUrls:f.pendingImageUrls,onPendingPromptConsumed:()=>Ot(f.mountKey)},f.mountKey)})})]},f.mountKey||D(f.agent,f.sessionId))})})()})}),z&&ae&&e.jsx(Ir,{workdir:ae.workdir,onClose:()=>E(!1),t:a}),e.jsx(Lr,{open:me,initialPath:l||void 0,onAdd:ee,onClose:()=>be(!1),t:a}),e.jsxs(_t,{open:!!he,onClose:()=>!te&&we(null),children:[e.jsx(Pt,{title:a("hub.removeWorkspace"),onClose:()=>!te&&we(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:a("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:a("modal.confirmRemoveWorkspaceHint")}),he&&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:he}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ce,{variant:"ghost",onClick:()=>we(null),disabled:te,children:a("modal.cancel")}),e.jsx(Ce,{variant:"primary",onClick:rt,disabled:te,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:a(te?"modal.removing":"modal.remove")})]})]}),de&&(()=>{const u=Math.max(8,Math.min(de.anchor.right-160,window.innerWidth-160-8)),h=Math.min(de.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:f=>f.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>Bt(de.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"})]}),a("session.delete")]})})})(),e.jsxs(_t,{open:!!ke,onClose:()=>!ne&&K(null),children:[e.jsx(Pt,{title:a("session.deleteTitle"),onClose:()=>!ne&&K(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:a("session.deleteHint")}),ke&&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:ke.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:ke.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:!pe,onChange:()=>ye(!1),disabled:ne,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:a("session.deletePikiclawOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:a("session.deletePikiclawOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:pe,onChange:()=>ye(!0),disabled:ne,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:a("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:a("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ce,{variant:"ghost",onClick:()=>K(null),disabled:ne,children:a("modal.cancel")}),e.jsx(Ce,{variant:"primary",onClick:kt,disabled:ne,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:a(ne?"session.deleting":"modal.remove")})]})]}),e.jsx(gr,{open:!!st,onClose:()=>wt(null),workdir:st||""})]})});function Lr({open:t,initialPath:n,onAdd:s,onClose:l,t:a}){const[d,p]=r.useState(""),c=r.useCallback(m=>p(m),[]);return r.useEffect(()=>{t&&p("")},[t]),e.jsxs(_t,{open:t,onClose:l,children:[e.jsx(Pt,{title:a("hub.addWorkspace"),onClose:l}),e.jsx(cs,{initialPath:n,maxHeight:360,minHeight:200,onSelect:c,t:a}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ce,{disabled:!d,onClick:()=>d&&s(d),className:"flex-1",children:a("hub.add")}),e.jsx(Ce,{variant:"secondary",onClick:l,className:"flex-1",children:a("hub.cancel")})]})]})}function Er({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:a}){const[d,p]=r.useState(null),[c,m]=r.useState([]),v=r.useRef(null),g=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),L=r.useCallback(()=>{},[]),k=r.useCallback((A,W)=>{p(A||null),v.current=A||null;const $=W||[];m($),g.current=$},[]),N=r.useCallback(A=>{const W=g.current;g.current=[],s(A,v.current||void 0,W.length?W:void 0)},[s]),T=!!d||c.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:a("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(Wt,{variant:T?"ok":"idle",pulse:T}),!T&&e.jsx("button",{onClick:l,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:T?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(On,{text:d||"",blocks:c.map(A=>({type:"image",content:A})),t:a}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(en,{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:a("hub.newSessionHint")})})})}),e.jsx(Us,{session:j,workdir:t,onStreamQueued:L,onSendStart:k,onSessionChange:N,t:a,streamPhase:null})]})}const Mr=r.memo(function({workspace:n,sessions:s,loading:l,isActive:a,selectedKey:d,openSessionKeys:p,onSelectSession:c,onNewSession:m,onRefresh:v,onRemove:g,onExtensions:j,onWarmSession:L,onCancelWarmSession:k,onSessionMenuOpen:N,t:T}){const[A,W]=r.useState(!0),[$,H]=r.useState(Xt);r.useEffect(()=>{H(Xt)},[s.length]);const R=s.slice(0,$),I=s.length-$,z=n.path;return 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:()=>W(E=>!E),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",A&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),e.jsx("span",{className:M("flex-1 min-w-0 truncate text-[12px] font-semibold",a?"text-primary":"text-fg-3"),children:n.name}),a&&e.jsx(Wt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:E=>{E.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:E=>{E.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:E=>{E.stopPropagation(),v(z)},className:"p-1 rounded text-fg-5 hover:text-fg-2 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),!a&&e.jsx("button",{onClick:E=>{E.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"})]})})]})]}),A&&e.jsx("div",{className:"pb-1",children:l?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(ue,{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:[R.map(E=>{const J=D(E.agent||"",E.sessionId),le=E.__forkDepth||0;return e.jsx(Tr,{session:E,isSelected:d===J,isOpen:p?.has(J)??!1,forkDepth:le,onClick:()=>c(E,z),onWarm:()=>L(E,z),onCancelWarm:()=>k(E,z),onShowMenu:Ee=>N(Ee,E,z),menuLabel:T("session.openActions")},J)}),I>0&&e.jsxs("button",{onClick:()=>H(E=>E+Xt),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"})})]})]})})]})}),Tr=r.memo(function({session:n,isSelected:s,isOpen:l,forkDepth:a=0,onClick:d,onWarm:p,onCancelWarm:c,onShowMenu:m,menuLabel:v}){const g=Yt(n.agent||""),j=It(n),L=kn(n).slice(0,500)||n.sessionId.slice(0,16),k=ls(n,L).slice(0,500),N=n.model?sn(n.model):null,T=a>0?Math.min(a,3)*14:0,A=l?10:12,W=r.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:d,onMouseEnter:p,onFocus:p,onMouseLeave:c,onBlur:c,className:M("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":l?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:A+T,...l?{borderLeft:`2px solid ${s?g.color:`${g.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[a>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(Je,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),N&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:N}),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:yn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Wt,{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:L})]}),k&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:k})})]}),e.jsx("button",{ref:W,type:"button","aria-label":v,"aria-haspopup":"menu",onMouseDown:$=>{$.stopPropagation()},onClick:$=>{$.stopPropagation(),$.preventDefault(),W.current&&m(W.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"})]})})]})}),Ir=r.memo(function({workdir:n,onClose:s,t:l}){const a=ge(g=>g.state?.hostApp??null),d=ge(g=>g.state?.platform??null),p=ge(g=>g.toast),[c,m]=r.useState(()=>Sr(a,d)),v=r.useCallback(async g=>{try{const j=await Q.openInEditor(g,c);if(!j.ok)throw new Error(j.error||`Failed to open ${g}`)}catch(j){p(j?.message||String(j),!1)}},[c,p]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:l("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:l("hub.closePanel"),children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"shrink-0 px-2.5 py-1.5 border-b border-edge/20 flex items-center gap-2",children:[e.jsx(as,{value:c,options:(d==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:l(Dn(g))})),onChange:g=>{Nr(g)&&m(g)},renderIcon:g=>e.jsx(Fn,{target:g,size:14})}),e.jsx(Ce,{size:"sm",variant:"ghost",onClick:()=>v(n),className:"flex-1 min-w-0 text-[11px]",children:l("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(Ar,{basePath:n,openTarget:c,onOpenPath:v,t:l})})]})});function Fn({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(Je,{brand:t,size:n})}function Ar({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:l,t:a}){const[d,p]=r.useState([]),[c,m]=r.useState(!0);r.useEffect(()=>{let g=!1;return m(!0),Q.lsDir(t,!0,n).then(j=>{!g&&j.ok&&p(j.dirs.slice(0,50).map(L=>({entry:L,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||m(!1)}),()=>{g=!0}},[t,n]);const v=r.useCallback(g=>{const j=L=>L.map(k=>k.entry.path===g?k.expanded?{...k,expanded:!1}:k.children===null?(Q.lsDir(g,!0,n).then(N=>{N.ok&&p(T=>nn(T,g,{children:N.dirs.slice(0,50).map(A=>({entry:A,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{p(N=>nn(N,g,{children:[],loading:!1}))}),{...k,loading:!0,expanded:!0}):{...k,expanded:!0}:k.children?{...k,children:j(k.children)}:k);p(L=>j(L))},[n]);return c?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(ue,{className:"h-3 w-3 text-fg-5"})}):d.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(Un,{nodes:d,depth:0,onToggle:v,openTarget:s,onOpenPath:l,t:a})})}function Un({nodes:t,depth:n,onToggle:s,openTarget:l,onOpenPath:a,t:d}){return e.jsx(e.Fragment,{children:t.map(p=>e.jsx(Rr,{node:p,depth:n,onToggle:s,openTarget:l,onOpenPath:a,t:d},p.entry.path))})}function Rr({node:t,depth:n,onToggle:s,openTarget:l,onOpenPath:a,t:d}){const{entry:p,expanded:c,children:m,loading:v}=t,g=n*14,[j,L]=r.useState(!1),k=d(Dn(l)),N=d("hub.openWithTarget").replace("{target}",k);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:p.isDir?()=>s(p.path):void 0,onMouseEnter:()=>L(!0),onMouseLeave:()=>L(!1),className:M("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",p.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+g,paddingRight:8},children:[p.isDir?v?e.jsx(ue,{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",c&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),p.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:p.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:T=>{T.stopPropagation(),a(p.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:N,children:e.jsx(Fn,{target:l,subtle:!0})}),!p.isDir&&e.jsx(_r,{filePath:p.path,t:d})]})]}),p.isDir&&c&&m&&m.length>0&&e.jsx(Un,{nodes:m,depth:n+1,onToggle:s,openTarget:l,onOpenPath:a,t:d})]})}function _r({filePath:t,t:n}){const[s,l]=r.useState(!1);return e.jsx("button",{onClick:a=>{a.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!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 nn(t,n,s){return t.map(l=>l.entry.path===n?{...l,...s}:l.children?{...l,children:nn(l.children,n,s)}:l)}const Jr=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Cr},Symbol.toStringTag,{value:"Module"}));export{Us as I,qr as L,Js as R,Qr as T,On as U,Kr as a,_n as b,Es as c,en as d,Gr as e,dr as f,Jr as i,vs as l,Vr as m,Hr as n,bs as p,gn as u};
|