pikiloom 0.4.30 → 0.4.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dashboard/dist/assets/{AgentTab-B4EYK2m8.js → AgentTab-CYoIkNyL.js} +1 -1
- package/dashboard/dist/assets/{ConnectionModal-BktbmACQ.js → ConnectionModal-CbWtylsE.js} +1 -1
- package/dashboard/dist/assets/{DirBrowser-DPNjooga.js → DirBrowser-BsHjGC5A.js} +1 -1
- package/dashboard/dist/assets/ExtensionsTab-BYoLkIki.js +1 -0
- package/dashboard/dist/assets/{IMAccessTab-1HeNr-tg.js → IMAccessTab-B-SxDXft.js} +1 -1
- package/dashboard/dist/assets/{Modal-B4wc5184.js → Modal-CzQbFS5c.js} +1 -1
- package/dashboard/dist/assets/{Modals-C-2IImYO.js → Modals-V9ykx8c4.js} +1 -1
- package/dashboard/dist/assets/{Select-xEvJAcZi.js → Select-DE6cseW_.js} +1 -1
- package/dashboard/dist/assets/{SessionPanel-DRrCVpih.js → SessionPanel-CMu962uE.js} +1 -1
- package/dashboard/dist/assets/{SystemTab-DTggBzSg.js → SystemTab-Cx6DyiFf.js} +1 -1
- package/dashboard/dist/assets/{index-DVHryefY.js → index-Cjaly0tB.js} +3 -3
- package/dashboard/dist/assets/{index-CJm8YsKX.js → index-Dp_KlJM9.js} +2 -2
- package/dashboard/dist/assets/{shared-CDeMhM6X.js → shared-DQrcGYOc.js} +1 -1
- package/dashboard/dist/index.html +1 -1
- package/dist/agent/artifacts.js +11 -1
- package/dist/agent/index.js +1 -1
- package/dist/bot/bot.js +4 -1
- package/dist/catalog/mcp-servers.js +24 -0
- package/dist/core/utils.js +12 -6
- package/dist/dashboard/routes/sessions.js +7 -2
- package/package.json +1 -1
- package/dashboard/dist/assets/ExtensionsTab-Bv_23Acs.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e,r as f}from"./react-vendor-C7Sl8SE7.js";import{M as v,c as A,N as F,u as x,d as G,a as $,m as w,R as L,F as g,G as O}from"./index-
|
|
1
|
+
import{j as e,r as f}from"./react-vendor-C7Sl8SE7.js";import{M as v,c as A,N as F,u as x,d as G,a as $,m as w,R as L,F as g,G as O}from"./index-Dp_KlJM9.js";import{ClientConnectionPanel as z,ServerConfigPanel as E}from"./ConnectionModal-CbWtylsE.js";import{S as k}from"./shared-DQrcGYOc.js";import"./router-DHISdpPk.js";import"./Modal-CzQbFS5c.js";function j(s){return Number.isFinite(s??NaN)?Math.max(0,Math.min(100,Number(s))):null}function S(s){return Number.isFinite(s??NaN)?Number(s).toFixed(2):null}function W(s){return s?[s.hostName||"—",s.platform,s.arch].filter(Boolean).join(" · "):""}function q(s,r){if(!s)return[];const o=s.totalMem||0,i=s.memoryUsed||o-(s.freeMem||0),t=j(s.memoryPercent||(o>0?i/o*100:0)),a=j(s.cpuUsage?.usedPercent),d=s.loadAverage||null,c=S(d?.one),p=S(d?.five),u=S(d?.fifteen),h=j(d?d.one/Math.max(s.cpuCount||1,1)*100:null),y=[{key:"cpu",label:r("sessions.cpu"),value:a!=null?`${a.toFixed(0)}%`:`${s.cpuCount} cores`,detail:[`${s.cpuCount} cores`,s.cpuModel||""].filter(Boolean),tone:a!=null&&a>=85?"warn":"ok",progressPercent:a},...c&&p&&u?[{key:"cpu-load",label:r("system.cpuLoad"),value:`1m ${c}`,detail:[`5m ${p}`,`15m ${u}`],tone:h!=null&&h>=85?"warn":"muted",progressPercent:h}]:[],{key:"memory",label:r("sessions.memory"),value:`${F(i)} / ${F(o)}`,detail:t!=null?`${t.toFixed(0)}%`:void 0,tone:t!=null&&t>=85?"warn":"ok",progressPercent:t}];if(s.disk){const m=j(parseFloat(String(s.disk.percent).replace("%","")));y.push({key:"disk",label:r("sessions.disk"),value:`${s.disk.used} / ${s.disk.total}`,detail:s.disk.percent,tone:m!=null&&m>=85?"warn":"muted",progressPercent:m})}else if(s.battery){const m=j(parseFloat(String(s.battery.percent).replace("%","")));y.push({key:"battery",label:r("sessions.battery"),value:s.battery.percent,detail:s.battery.state,tone:m!=null&&m<=20?"warn":"muted",progressPercent:m})}return y}function B(s){return s?Array.isArray(s)?s.join(" · "):s:""}function I({items:s,loading:r,className:o}){return r?e.jsx("div",{className:A("space-y-1",o),children:Array.from({length:4},(i,t)=>e.jsxs("div",{className:"grid grid-cols-[80px_auto_1fr] items-baseline gap-x-4 py-1",children:[e.jsx(v,{className:"h-3 w-12"}),e.jsx(v,{className:"h-3 w-24"}),e.jsx(v,{className:"h-3 w-28"})]},t))}):e.jsx("div",{className:A("flex flex-wrap items-baseline gap-x-5 gap-y-1.5",o),children:s.map(i=>{const t=B(i.detail);return e.jsxs("div",{className:"inline-flex items-baseline gap-1.5 whitespace-nowrap",title:t||void 0,children:[e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.12em] text-fg-5",children:i.label}),e.jsx("span",{className:"font-mono text-[12px] tabular-nums text-fg-2",children:i.value}),t&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:["· ",t]})]},i.key)})})}const K=[{key:"screenRecording",labelKey:"perm.screenRecording",reasonZh:"用于截图与界面分析",reasonEn:"For screenshots and UI inspection",guidePathKey:"perm.pathScreenRecording",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"4",y:"5.5",width:"11.5",height:"10",rx:"2.4"}),e.jsx("path",{d:"m17.5 8.4 2.7-1.5v7.2l-2.7-1.5"}),e.jsx("circle",{cx:"9.75",cy:"10.5",r:"1.1",fill:"currentColor",stroke:"none"})]})},{key:"fullDiskAccess",labelKey:"perm.fullDiskAccess",reasonZh:"访问桌面、下载等受保护目录",reasonEn:"Access to Desktop, Downloads and other protected folders",guidePathKey:"perm.pathFullDiskAccess",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"6.2",y:"10.1",width:"11.6",height:"8.6",rx:"2.6"}),e.jsx("path",{d:"M9 10V7.8a3 3 0 1 1 6 0V10"}),e.jsx("circle",{cx:"12",cy:"13.5",r:"0.9",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M12 14.6v1.8"})]})}];function T(s){return s==="zh-CN"?{introWithHost:"请在 macOS 中为 {hostApp} 开启以下权限。",intro:"请在 macOS 中开启以下权限。",status:"状态",summary:"系统位置",loading:"检查中",needsGrant:"需要授权",granted:"已授权",authorize:"授权",openSettings:"前往设置",refreshState:"刷新状态",checking:"检查中...",hostGranted:"{hostApp} 已可直接使用此权限。",hostGrantedFallback:"当前宿主应用已可直接使用此权限。",needsGrantDetail:"尚未授权,可通过右侧按钮发起系统授权。",needsSettingsDetail:"需要在系统设置中手动开启此权限。"}:{introWithHost:"Grant the following permissions to {hostApp} in macOS.",intro:"Grant the following permissions in macOS.",status:"Status",summary:"System path",loading:"Checking",needsGrant:"Needs access",granted:"Granted",authorize:"Authorize",openSettings:"Open settings",refreshState:"Refresh status",checking:"Checking...",hostGranted:"{hostApp} can use this permission now.",hostGrantedFallback:"The current host app can use this permission now.",needsGrantDetail:"Access has not been granted yet. Use the button on the right to trigger the macOS prompt.",needsSettingsDetail:"This permission needs to be enabled manually in System Settings."}}function H(){const s=x(n=>n.state),r=x(n=>n.locale),o=x(n=>n.reload),i=x(n=>n.toast),t=f.useMemo(()=>G(r),[r]),a=T(r),d=s?.permissions||{},c=s?.hostApp||null,p=!s,[u,h]=f.useState(null),y=f.useMemo(()=>K.map(n=>({...n,permission:d[n.key]})),[d]),m=f.useCallback(async n=>{if(!u){h(n);try{const l=await $.requestPermission(n);if(!l.ok){i(l.error||t("perm.requestFailed"),!1);return}l.action==="already_granted"?i(t("perm.alreadyGranted")):l.action==="prompted"?i(t("perm.promptOpened")):i(t("perm.settingsOpened")),await o()}catch(l){i(l instanceof Error?l.message:t("perm.requestFailed"),!1)}finally{h(l=>l===n?null:l)}}},[o,u,t,i]),M=f.useCallback(async()=>{await o()},[o]);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:c?a.introWithHost.replace("{hostApp}",c):a.intro})}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>{M()},children:a.refreshState})]}),e.jsx(L,{children:y.map(n=>{const l=n.permission,b=!!l?.granted,P=!!l&&l.checkable,C=p?a.loading:b?a.granted:a.needsGrant,D=p?"idle":b?"ok":"warn",N=p?a.loading:b?c?a.hostGranted.replace("{hostApp}",c):a.hostGrantedFallback:P?a.needsGrantDetail:a.needsSettingsDetail,R=p?a.checking:P?a.authorize:a.openSettings;return e.jsxs(g,{children:[e.jsx(g.Lead,{icon:n.icon,title:t(n.labelKey),subtitle:r==="zh-CN"?n.reasonZh:n.reasonEn}),e.jsx(g.Status,{children:e.jsx(O,{state:D,label:C})}),e.jsx(g.Field,{children:t(n.guidePathKey)}),e.jsx(g.Action,{children:!b&&e.jsx(w,{variant:"primary",size:"sm",disabled:p||!!u,onClick:()=>{m(n.key)},children:u===n.key?a.checking:R})}),N&&N!==C&&e.jsx(g.Description,{children:N})]},n.key)})})]})}function X({onOpenWorkdir:s}){const r=x(c=>c.state),o=x(c=>c.host),i=x(c=>c.locale),t=f.useMemo(()=>G(i),[i]),a=r?.bot?.workdir||r?.runtimeWorkdir||r?.config.workdir||"",d=W(o);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsx(k,{className:"!p-3.5",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"flex items-baseline gap-2",children:e.jsx("span",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("config.workdir")})}),e.jsx("div",{className:"mt-0.5 break-all font-mono text-[12px] leading-relaxed text-fg-2",children:a||t("sidebar.notSet")})]}),e.jsx(w,{variant:"outline",size:"sm",onClick:s,children:t("sidebar.switchDir")})]})}),e.jsxs(k,{className:"space-y-2 !p-3.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[e.jsx("span",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("app.systemInfo")}),e.jsx("span",{className:"truncate text-[11px] text-fg-5",children:d||t("status.loading")})]}),e.jsxs("div",{className:"text-[11px] text-fg-5",children:[r?.version?`Pikiloom v${r.version}`:"Pikiloom",r?.nodeVersion?` · Node ${r.nodeVersion}`:""]})]}),e.jsx(I,{items:q(o,t),loading:!o})]}),e.jsx(k,{className:"!p-3.5",children:e.jsx(z,{})}),e.jsx(k,{className:"!p-3.5",children:e.jsx(E,{})}),e.jsxs(k,{className:"space-y-2 !p-3.5",children:[e.jsx("div",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("tab.permissions")}),e.jsx(H,{})]})]})}export{X as SystemTab};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-
|
|
2
|
-
import{c as I,a as ee,u as ye,i as Dt,f as Et,A as us,s as Ft,S as pe,B as rt,g as an,w as hs,b as xs,E as tn,C as pn,d as ps,r as Nn,e as Sn,h as fs,n as gs,j as ms,k as An,l as Bt,m as Ee,D as Kt,o as bs,p as Rn,_ as Pn,T as vs,q as js}from"./index-
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-CMu962uE.js","assets/react-vendor-C7Sl8SE7.js","assets/index-Dp_KlJM9.js","assets/router-DHISdpPk.js","assets/index-CXIN3nTr.css","assets/Modal-CzQbFS5c.js","assets/Select-DE6cseW_.js","assets/DirBrowser-BsHjGC5A.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-BYoLkIki.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{c as I,a as ee,u as ye,i as Dt,f as Et,A as us,s as Ft,S as pe,B as rt,g as an,w as hs,b as xs,E as tn,C as pn,d as ps,r as Nn,e as Sn,h as fs,n as gs,j as ms,k as An,l as Bt,m as Ee,D as Kt,o as bs,p as Rn,_ as Pn,T as vs,q as js}from"./index-Dp_KlJM9.js";import{j as e,r,a as fn}from"./react-vendor-C7Sl8SE7.js";import{I as ws}from"./Select-DE6cseW_.js";import{M as Ut,a as zt}from"./Modal-CzQbFS5c.js";import{D as ks}from"./DirBrowser-BsHjGC5A.js";import{n as ys,r as Ns,M as gn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Ss}from"./ExtensionsTab-BYoLkIki.js";function Cs({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:I("shrink-0 text-fg-5/40 transition-transform duration-200",t&&"rotate-180",n),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function ot({open:t,onToggle:n,dot:s,label:l,preview:i,badge:c,collapsedContent:x,children:d,className:b}){return e.jsxs("div",{className:I("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",b),children:[e.jsxs("button",{onClick:n,className:"w-full flex items-center gap-2.5 px-3.5 py-2.5 text-left hover:bg-panel-h/40 transition-colors",children:[s&&e.jsx("span",{className:I("h-[7px] w-[7px] shrink-0 rounded-full",s.color,s.pulse&&"animate-pulse")}),e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:l}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:i}),c,e.jsx(Cs,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Ts=5e3,Is=15e3,$t=8,Ot=30,Ls=1,st=new Map,ke=new Map,nn=new Set,_n=[];let At=0;function sn(t){return typeof t=="number"&&Number.isFinite(t)}function ze(t,n,s,l){for(t.delete(n),t.set(n,s);t.size>l;){const i=t.keys().next().value;if(!i)break;t.delete(i)}}function Wn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(ze(t,n,s,t===ke?Ot:$t),s.value)}function Bn(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:sn(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:sn(t.turnOffset)?t.turnOffset:void 0,turnLimit:sn(t.turnLimit)?t.turnLimit:void 0}}function mn(t){const n=Bn(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function $n(){for(;At<Ls;){const t=_n.shift();if(!t)return;At+=1,t().finally(()=>{At=Math.max(0,At-1),$n()})}}async function Ms(t,n={}){const s=t;if(!n.force){const c=Wn(st,s);if(c)return c}const l=st.get(s);if(l?.promise)return l.promise;const i=ee.getWorkspaceSessions(t,n.request).then(c=>(ze(st,s,{value:c,expiresAt:c.ok?Date.now()+Ts:0},$t),c)).finally(()=>{const c=st.get(s);c?.promise&&ze(st,s,{value:c.value,expiresAt:c.expiresAt},$t)});return ze(st,s,{value:l?.value,expiresAt:l?.expiresAt??0,promise:i},$t),i}function Es(t,n={}){const s=mn(t),l=ke.get(s);return l?.value?.ok&&(n.allowStale||l.expiresAt>Date.now())?l.value:null}async function As(t,n={}){const s=Bn(t),l=mn(s);if(!n.force){const x=Wn(ke,l);if(x?.ok)return x}const i=ke.get(l);if(i?.promise)return i.promise;const c=ee.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(ze(ke,l,{value:x,expiresAt:x.ok?Date.now()+Is:0},Ot),x)).finally(()=>{const x=ke.get(l);x?.promise&&ze(ke,l,{value:x.value,expiresAt:x.expiresAt},Ot)});return ze(ke,l,{value:i?.value,expiresAt:i?.expiresAt??0,promise:c},Ot),c}function Rs(t){const n=mn(t);Es(t)||nn.has(n)||ke.get(n)?.promise||(nn.add(n),_n.push(async()=>{try{await As(t)}catch{}finally{nn.delete(n)}}),$n())}function no(t){const n=t.streaming||t.liveStreamPhase==="streaming",s=t.queuedTaskCount>0||t.pendingQueuedCount>0||t.streamPhase==="queued";return n||s}function so(t){const{pendingTaskId:n,streamTaskId:s,queuedTaskIds:l}=t;return!n||n===s?!1:!!l&&l.includes(n)}function Ps(t){const{queuedTaskIds:n,streamPhase:s,streamTaskId:l,localTaskId:i}=t,c=[];n&&n.length&&c.push(...n),s==="queued"&&l&&!c.includes(l)&&c.unshift(l),i&&!c.includes(i)&&(s==="queued"||!s)&&c.push(i);const x=s==="streaming"?l??null:null;return x?c.filter(d=>d!==x):c}function ro(t,n){return t==null||n==null?!0:t===n}function Cn(t){return(t||"").replace(/\s+/g," ").trim()}function oo(t,n){return Cn(t)===Cn(n)}function io(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(x=>({role:x.role,text:x.text,blocks:[{type:"text",content:x.text}]}))||[],s=Ws(n),l=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),i=t.window?.endTurn??l,c=t.window?.startTurn??Math.max(0,i-s.length);return{turns:s,startTurn:c,endTurn:i,totalTurns:l,hasOlder:t.window?.hasOlder??c>0}}function lo(t,n){const s=Math.max(0,t.startTurn-n.startTurn);return{turns:[...n.turns.slice(0,s),...t.turns],startTurn:n.startTurn,endTurn:t.endTurn,totalTurns:Math.max(t.totalTurns,n.totalTurns),hasOlder:n.hasOlder}}function ao(t,n){if(n.startTurn<=t.startTurn)return n;const s=Math.max(0,n.startTurn-t.startTurn);return{turns:[...t.turns.slice(0,s),...n.turns],startTurn:t.startTurn,endTurn:n.endTurn,totalTurns:n.totalTurns,hasOlder:t.startTurn>0}}function _s(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
|
|
3
3
|
|
|
4
4
|
`),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function Ws(t){const n=[];let s={user:null,assistant:null};for(const l of t)if(l.role==="user"){if(s.assistant&&On(l.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=l}else s.assistant?s.assistant=_s(s.assistant,l):s.assistant=l;return(s.user||s.assistant)&&n.push(s),n}const Bs=new Set(["task-notification","system-reminder","persisted-output","local-command-stdout","local-command-caveat","local-command-stderr","ide_opened_file","ide_diagnostics","ide_selection","event","analysis","case_id","tool-use-id","output-file"]),$s=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function On(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Bs.has(s[1].toLowerCase())?!0:$s.some(l=>t.includes(l))}function Dn(t,n){const s=t.split(`
|
|
5
5
|
`).filter(l=>l.trim());return s.length<=n?s.join(`
|
|
@@ -19,5 +19,5 @@ import{c as I,a as ee,u as ye,i as Dt,f as Et,A as us,s as Ft,S as pe,B as rt,g
|
|
|
19
19
|
`),[d,b]=r.useState(null),w=r.useMemo(()=>Ht({workdir:s}),[s]);return!x.trim()&&i.length===0&&c.length===0?null:e.jsxs(e.Fragment,{children:[x.trim()&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:e.jsx(gn,{remarkPlugins:bn,components:w,children:x})}),i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:i.map((g,j)=>e.jsx(fr,{block:g,onLightbox:b,t:n},j))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((g,j)=>e.jsx(Gn,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},j))}),d&&e.jsx(Xn,{src:d,onClose:()=>b(null)})]})}const ho=r.memo(function({turn:n,turnIndex:s,agent:l,meta:i,model:c,effort:x,providerName:d,t:b,workdir:w,onResend:g,onEdit:j,onFork:T}){const N=n.user&&On(n.user.text),E=T&&typeof s=="number"?()=>T(s):void 0,L=r.useMemo(()=>Ht({workdir:w}),[w]),A=!!n.assistant&&cr(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!N&&e.jsx(Jn,{text:n.user.text,blocks:n.user.blocks,t:b,onResend:g,onEdit:j,onFork:E}),N&&n.user&&!n.assistant&&e.jsx("div",{className:"mb-4 px-4 py-3 rounded-lg bg-[rgba(255,255,255,0.02)] border border-edge/20 text-[12.5px] leading-[1.7] text-fg-4",children:e.jsx(gn,{remarkPlugins:bn,components:L,children:n.user.text})}),A&&e.jsxs(e.Fragment,{children:[e.jsx(jr,{agent:l,meta:i,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(ar,{message:n.assistant,t:b,workdir:w})})]})]})});function Xn({src:t,onClose:n}){return r.useEffect(()=>{const s=l=>{l.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),fn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm cursor-zoom-out",onClick:n,children:e.jsx("img",{src:t,className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl",onClick:s=>s.stopPropagation()})}),document.body)}const mr=1500,br=16,In=8;function vr(t){const n=t.split(`
|
|
20
20
|
`);return n.length<=In?t:n.slice(0,In).join(`
|
|
21
21
|
`)}function Jn({text:t,blocks:n,t:s,onResend:l,onEdit:i,onFork:c}){const[x,d]=r.useState(!1),[b,w]=r.useState(!1),[g,j]=r.useState(null),T=t?t.split(`
|
|
22
|
-
`).length:0,N=!!t&&(t.length>mr||T>br),[E,L]=r.useState(!1),A=t?N&&!E?vr(t):t:"",_=!!(l||i||c),S=n?.filter(M=>M.type==="image")||[],B=()=>{navigator.clipboard.writeText(t).then(()=>{w(!0),setTimeout(()=>w(!1),1500)}).catch(()=>{})},te=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(T));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[A,N&&!E&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),N&&e.jsx("button",{type:"button",onClick:()=>L(M=>!M),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:E?s("hub.collapse"):te}),S.length>0&&e.jsx("div",{className:I("flex flex-wrap gap-2",t&&"mt-2"),children:S.map((M,G)=>e.jsx("img",{src:M.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(M.content)},G))})]}),g&&e.jsx(Xn,{src:g,onClose:()=>j(null)}),_&&e.jsxs("div",{className:I("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(Rt,{label:s(b?"hub.copied":"hub.copy"),onClick:B,children:b?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),l&&e.jsx(Rt,{label:s("hub.rerun"),onClick:()=>l(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),i&&e.jsx(Rt,{label:s("hub.edit"),onClick:()=>i(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),c&&e.jsx(Rt,{label:s("hub.fork"),onClick:c,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]})})]})]})}function Rt({label:t,onClick:n,children:s}){return e.jsx("button",{onClick:n,title:t,className:"flex items-center justify-center w-7 h-7 rounded border border-fg-6 bg-panel text-fg-4 shadow-sm hover:text-fg-2 hover:border-edge-h hover:bg-panel-h transition-colors",children:s})}function jr({agent:t,meta:n,model:s,effort:l,providerName:i,previewMeta:c,liveStartedAt:x}){const d=c?.contextPercent??null,b=c?.contextUsedTokens??0,w=c?.turnOutputTokens??0,g=d!=null||b>0||w>0,j=x!=null&&x>0,T=c?.providerName??i??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(rt,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||l)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&l?" · ":"",l||""]}),T&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/70 px-1.5 py-px rounded bg-fg-5/8",title:`This turn is routed through ${T} (BYOK), not the agent CLI's native auth.`,children:["via ",T]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:Nr(c),children:[d!=null&&e.jsx(Sr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),b>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",yr(b)]}),w>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Zn(w)]}),j&&e.jsx(wr,{startedAt:x,leadingDot:g})]})]})}function wr({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const i=setInterval(()=>s(c=>c+1),1e3);return()=>clearInterval(i)},[]);const l=Math.max(0,Date.now()-t);return e.jsxs("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:[n?"· ":"",kr(l)]})}function kr(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),l=n%60;return s<60?`${s}m${l.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function yr(t){return`${Zn(t)} tok`}function Zn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function Nr(t){if(!t)return"";const n=[];return t.contextPercent!=null&&n.push(`Context: ${t.contextPercent.toFixed(1)}%`),t.inputTokens!=null&&n.push(`Input: ${t.inputTokens.toLocaleString()}`),t.turnOutputTokens!=null?n.push(`Output (turn): ${t.turnOutputTokens.toLocaleString()}`):t.outputTokens!=null&&n.push(`Output: ${t.outputTokens.toLocaleString()}`),t.cachedInputTokens!=null&&n.push(`Cached: ${t.cachedInputTokens.toLocaleString()}`),n.join(" · ")}function Sr({pct:t}){const n=t>=85?"bg-rose-400/70":t>=60?"bg-amber-400/70":"bg-emerald-400/70";return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${n}`})}function Ln(t,n,s){return t==="zh-CN"?n:s}function Cr({open:t,onClose:n,workdir:s}){const l=ye(c=>c.locale),i=s.split("/").pop()||s;return e.jsxs(Ut,{open:t,onClose:n,wide:!0,children:[e.jsx(zt,{title:Ln(l,`${i} — 项目扩展`,`${i} — Project Extensions`),description:Ln(l,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(Ss,{workdir:s}):null]})}let Mn=Pn(()=>import("./SessionPanel-DRrCVpih.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function un(){return Mn??=Pn(()=>import("./SessionPanel-DRrCVpih.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Mn}const Tr=r.lazy(async()=>({default:(await un()).SessionPanel})),ln=5,Ir=240,Lr=120,Mr=12,Er=900*1e3,V=(t,n)=>`${t}:${n}`;function Ar(t){const n=new Map;for(const d of t)n.set(V(d.agent||"",d.sessionId),d);const s=new Map,l=new Set;for(const d of t){const b=d.migratedFrom;if(!b||b.kind!=="fork"||!b.sessionId)continue;const w=V(b.agent||d.agent||"",b.sessionId);n.has(w)&&(l.add(V(d.agent||"",d.sessionId)),s.has(w)||s.set(w,[]),s.get(w).push(d))}const i=[],c=new Set,x=(d,b)=>{const w=V(d.agent||"",d.sessionId);if(c.has(w))return;c.add(w),i.push(Object.assign({},d,{__forkDepth:b}));const g=s.get(w);if(g)for(const j of g)x(j,b+1)};for(const d of t){const b=V(d.agent||"",d.sessionId);l.has(b)||x(d,0)}for(const d of t)x(d,0);return i}let Rr=0;function Pt(){return`mk-${Date.now().toString(36)}-${(++Rr).toString(36)}`}function _t(t){try{const n=localStorage.getItem(t);if(n!=null)return n;const s=sessionStorage.getItem(t);if(s!=null){try{localStorage.setItem(t,s),sessionStorage.removeItem(t)}catch{}return s}}catch{}return null}function Wt(t,n){try{localStorage.setItem(t,n)}catch{}}const Pr=[1,2,3,6],hn=6;function _r(t){for(const n of Pr)if(n>=t)return n;return hn}function En(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function Ue(t,n){const s=_r(t);return s>n?s:n}function Wr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Br(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function es(t){switch(t){case"cursor":return"hub.openTargetCursor";case"windsurf":return"hub.openTargetWindsurf";case"finder":return"hub.openTargetFinder";case"default":return"hub.openTargetDefault";default:return"hub.openTargetVsCode"}}const $r=r.memo(function({active:n=!0}){const s=ye(o=>o.locale),l=ye(o=>o.state?.runtimeWorkdir??null),i=r.useMemo(()=>ps(s),[s]),[c,x]=r.useState([]),[d,b]=r.useState({}),[w,g]=r.useState({}),[j,T]=r.useState(!0),[N,E]=r.useState(()=>{const o=_t("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):En()}),[L,A]=r.useState(()=>{const o=_t("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):En()}),[_,S]=r.useState(()=>{try{const o=_t("pikiloom-open-sessions");if(o){const h=JSON.parse(o);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||Pt()}))}}catch{}return[]}),[B,te]=r.useState(()=>{const o=_t("pikiloom-active-slot");if(o!=null){const h=Number(o);if(Number.isFinite(h)&&h>=0)return h}return 0}),M=r.useCallback(o=>{E(o),Wt("pikiloom-layout-mode",String(o))},[]),G=r.useCallback(o=>{A(o),Wt("pikiloom-layout-floor",String(o))},[]),W=r.useCallback(o=>{S(h=>{const u=typeof o=="function"?o(h):o,p=u.map(({pendingPrompt:v,pendingImageUrls:y,...k})=>k);return Wt("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),D=r.useCallback(o=>{te(h=>{const u=typeof o=="function"?o(h):o;return Wt("pikiloom-active-slot",String(u)),u})},[]),ae=r.useCallback(o=>{M(o),G(o)},[M,G]);r.useEffect(()=>{W(o=>o.length>N?o.slice(0,N):o),D(o=>o>=N?N-1:o)},[N]);const[R,ce]=r.useState(!1),re=r.useRef(N);re.current=N;const Y=r.useRef(L);Y.current=L;const Ne=r.useRef(B);Ne.current=B;const K=r.useRef(_);K.current=_;const wt=r.useRef(-1),fe=_[B]??null,lt=r.useCallback(o=>{if(!o){W([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:Pt()};W(u=>{const p=u.findIndex(y=>y.agent===h.agent&&y.sessionId===h.sessionId);if(p>=0)return D(p),u;if(u.length<re.current){const y=[...u,h];return D(y.length-1),y}if(re.current<hn){const y=[...u,h];return M(Ue(y.length,Y.current)),D(y.length-1),y}const v=[...u];return v[Ne.current]=h,v})},[W,D,M]),[Ke,He]=r.useState(!1),[oe,Ae]=r.useState(null),[ne,Se]=r.useState(""),[Re,Ve]=r.useState("all"),[de,kt]=r.useState({}),[ue,Ge]=r.useState({}),Pe=r.useDeferredValue(ne),se=r.useRef(!1),qe=r.useRef({}),Ce=r.useRef(d);Ce.current=d;const Te=r.useRef(de);Te.current=de;const at=r.useRef(new Set),$=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values($.current))clearTimeout(o)},[]),r.useEffect(()=>{W(o=>{let h=!1;const u=o.map(p=>{const v=ue[p.workdir];if(!v)return p;const y=Nn(v,p.agent,p.sessionId);return y===p.sessionId?p:(h=!0,{...p,sessionId:y})});return h?u:o})},[ue,W]);const q=r.useCallback(async()=>{try{const o=await ee.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((p,v)=>p.path===h[v].path&&p.name===h[v].name)?u:h),se.current=!0}catch{se.current=!0}finally{T(!1)}},[]);r.useEffect(()=>{q()},[q]);const U=r.useCallback(async(o,h={})=>{if(!qe.current[o]){qe.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Ms(o,{force:h.force});r.startTransition(()=>{Ge(p=>{const v=u.promotions||{},y=p[o];return y&&Object.keys(y).length===Object.keys(v).length&&Object.entries(v).every(([k,H])=>y[k]===H)?p:{...p,[o]:v}}),b(p=>{const v=u.sessions||[],y=p[o]||[],k=new Set(v.map(F=>V(F.agent||"",F.sessionId))),H=y.filter(F=>{if(F.runState!=="running")return!1;const P=V(F.agent||"",F.sessionId);if(k.has(P))return!1;const O=Te.current[P];return!(O?.resolvedKey&&O.resolvedKey!==P)});return{...p,[o]:H.length?[...H,...v]:v}})})}catch{h.background||r.startTransition(()=>{b(u=>({...u,[o]:[]}))})}finally{qe.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),ct=r.useRef(l);r.useEffect(()=>{l!==ct.current&&(ct.current=l,!(!l||!se.current)&&q().then(()=>{U(l,{force:!0})}))},[l,q,U]);const Q=r.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(un(),Rs({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Mr}))},[]),Qe=r.useCallback((o,h,u=Lr)=>{const p=`${h}:${V(o.agent||"",o.sessionId)}`,v=$.current[p];v&&clearTimeout(v),$.current[p]=setTimeout(()=>{delete $.current[p],Q(o,h)},u)},[Q]),yt=r.useCallback((o,h)=>{const u=`${h}:${V(o.agent||"",o.sessionId)}`,p=$.current[u];p&&(clearTimeout(p),delete $.current[u])},[]);r.useEffect(()=>{n&&un()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||w[h.path])return;const p=setTimeout(()=>{U(h.path)},u*90);o.push(p)}),()=>{for(const h of o)clearTimeout(h)}},[n,U,w,d,c]);const Vt=r.useRef(new Map);Sn(n&&se.current&&c.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=o.key,u=h?c.filter(y=>(Ce.current[y.path]||[]).some(k=>V(k.agent||"",k.sessionId)===h)):c,p=u.length?u:c,v=Vt.current;for(const y of p)v.has(y.path)&&clearTimeout(v.get(y.path)),v.set(y.path,setTimeout(()=>{v.delete(y.path),U(y.path,{background:!0,force:!0})},300))},[c,U]));const ge=r.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:fs(o,de[V(h,o.sessionId)]||null)},[de]);Sn("stream-update",r.useCallback(o=>{const h=o.key;if(!h)return;const u=gs(h,o.snapshot??null);kt(p=>{if(!u){const P=p[h];return!P||P.phase==="done"?p:{...p,[h]:{...P,phase:"done",updatedAt:Date.now()}}}const v=(P,O)=>!!P&&!!O&&P.phase===O.phase&&P.resolvedKey===O.resolvedKey&&P.sessionId===O.sessionId&&P.incomplete===O.incomplete&&P.error===O.error,y=v(p[h],u),k=u.resolvedKey===h||v(p[u.resolvedKey],{...u,key:u.resolvedKey});if(y&&k)return p;const H=Date.now()-Er,F={};for(const[P,O]of Object.entries(p))O.phase==="done"&&O.updatedAt<H||(F[P]=O);return F[h]=u,u.resolvedKey!==h&&(F[u.resolvedKey]={...u,key:u.resolvedKey}),F})},[])),ms(r.useCallback(()=>{if(!(!n||!se.current||c.length===0))for(const o of c)U(o.path,{background:!0,force:!0})},[n,c,U])),r.useEffect(()=>{if(!n||!se.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)U(u.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,U,c]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const v=`${h.path}:${V(p.agent||"",p.sessionId)}`;if(at.current.has(v))return;const y=setTimeout(()=>{at.current.add(v),Q(p,h.path)},Ir+u*120);o.push(y)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,Q,c]);const dt=r.useCallback(async o=>{try{(await ee.addWorkspace(o)).ok&&(He(!1),await q(),U(o))}catch{}},[q,U]),[me,_e]=r.useState(null),[X,We]=r.useState(!1),[Be,$e]=r.useState(null),Ye=r.useCallback(o=>{_e(o)},[]),ut=r.useCallback(async()=>{const o=me;if(o){We(!0);try{await ee.removeWorkspace(o),x(h=>h.filter(u=>u.path!==o)),b(h=>{const u={...h};return delete u[o],u}),W(h=>{const u=h.filter(p=>p.workdir!==o);return u.length!==h.length&&M(Ue(u.length,Y.current)),u}),D(0),_e(null)}catch{}finally{We(!1)}}},[me]),ht=r.useCallback(o=>{U(o,{force:!0})},[U]),[Ie,be]=r.useState(null),[Xe,Je]=r.useState(!1),[ve,Le]=r.useState(!1),je=ye(o=>o.toast),[ie,Ze]=r.useState(null),xt=r.useCallback((o,h,u)=>{Ze({anchor:{right:o.right,bottom:o.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:An(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!ie)return;const o=()=>Ze(null),h=u=>{u.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",h)}},[ie]);const we=r.useCallback(o=>{Je(!1),be(o),Ze(null)},[]),Nt=r.useCallback(async()=>{const o=Ie;if(o){Le(!0);try{const h=await ee.deleteSession(o.workdir,o.agent,o.sessionId,Xe);if(!h.ok){const u=h.error?.includes("still running")?i("session.deleteRunningError"):h.error||i("session.deleteFailed");je(u,!1);return}b(u=>{const p=u[o.workdir];if(!p)return u;const v=p.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return v.length===p.length?u:{...u,[o.workdir]:v}}),W(u=>{const p=u.filter(v=>!(v.workdir===o.workdir&&v.agent===o.agent&&v.sessionId===o.sessionId));return p.length!==u.length&&M(Ue(p.length,Y.current)),p}),be(null)}catch(h){je(h?.message||i("session.deleteFailed"),!1)}finally{Le(!1)}}},[Ie,Xe,i,je]),pt=r.useCallback(o=>{W(h=>{let u=!1;const p=h.map(v=>v.mountKey===o&&(v.pendingPrompt!=null||v.pendingImageUrls)?(u=!0,{...v,pendingPrompt:null,pendingImageUrls:void 0}):v);return u?p:h})},[W]),St=r.useCallback((o,h,u)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),b(y=>{const k=y[o.workdir]||[];if(k.some(P=>P.sessionId===o.sessionId&&P.agent===o.agent))return y;const F={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[F,...k]}});const p=wt.current,v={...o,mountKey:Pt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};r.startTransition(()=>{Ae(null),W(y=>{if(p>=y.length)return[...y,v];const k=[...y];return k[p]=v,k}),D(p>=0?p:0)}),U(o.workdir,{background:!0,force:!0})},[U,Q,W,D]),Ct=r.useCallback(o=>{K.current.length>=re.current&&re.current<hn&&M(Ue(re.current+1,Y.current)),Ae(o)},[M]),Tt=r.useCallback(()=>{Ae(null),M(Ue(K.current.length,Y.current))},[M]),It=r.useCallback((o,h)=>{Q(o,h);const u=o.agent||"";K.current.some(p=>p.agent===u&&p.sessionId===o.sessionId)&&M(Ue(K.current.length,Y.current)),Ae(null),r.startTransition(()=>{lt({agent:u,sessionId:o.sessionId,workdir:h})})},[Q,M]),he=r.useCallback((o,h)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{h!=null?(W(u=>{if(h>=u.length)return u;const p=[...u];return p[h]={...u[h],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},p}),D(h)):lt({...o,mountKey:Pt()})}),U(o.workdir,{background:!0,force:!0})},[U,Q]),ft=r.useCallback(o=>{let h=o;if(Re==="running"?h=h.filter(u=>Bt(u)==="running"):Re==="review"&&(h=h.filter(u=>Bt(u)==="incomplete")),Pe.trim()){const u=Pe.toLowerCase();h=h.filter(p=>(p.lastMessageText||"").toLowerCase().includes(u)||(p.lastQuestion||"").toLowerCase().includes(u)||(p.lastAnswer||"").toLowerCase().includes(u)||(p.title||"").toLowerCase().includes(u)||(p.agent||"").toLowerCase().includes(u))}return h},[Pe,Re]),gt=r.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(ge),p=ue[h.path],v=new Map;for(const k of u){const H=V(k.agent||"",k.sessionId),F=de[H],P=p?Nn(p,k.agent||"",k.sessionId):k.sessionId,O=F?.resolvedKey&&F.resolvedKey!==H?F.resolvedKey:P!==k.sessionId?V(k.agent||"",P):H,mt=v.get(O);if(!mt){v.set(O,k);continue}V(mt.agent||"",mt.sessionId)!==O&&H===O&&v.set(O,k)}const y=ft([...v.values()]);o[h.path]=Ar(y)}return o},[c,d,de,ue,ft,ge]),Gt=r.useCallback(o=>{const h=(d[o.workdir]||[]).find(u=>u.sessionId===o.sessionId&&u.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return ge(h)},[ge,d]),qt=r.useMemo(()=>new Set(_.map(o=>V(o.agent,o.sessionId))),[_]),et=fe?V(fe.agent,fe.sessionId):null,Lt=r.useCallback(o=>{W(h=>{const u=h.filter((p,v)=>v!==o);return u.length===0?D(0):Ne.current>=u.length&&D(u.length-1),M(Ue(u.length,Y.current)),u})},[W,D,M]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:ne,onChange:o=>Se(o.target.value),placeholder:i("hub.search"),className:"w-full rounded-lg border border-edge/40 bg-inset/50 pl-8 pr-7 py-1.5 text-[12px] text-fg outline-none placeholder:text-fg-5/30 focus:border-primary/30 focus:bg-inset focus:shadow-[0_0_0_3px_rgba(99,102,241,0.06)] transition-all duration-200"}),ne&&e.jsx("button",{onClick:()=>Se(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-fg-5/30 hover:text-fg-4 transition-colors",children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex items-center rounded-lg bg-inset/30 border border-edge/20 p-0.5",children:["all","running","review"].map(o=>e.jsx("button",{onClick:()=>Ve(o),className:I("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",Re===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1),inset_0_1px_0_rgba(255,255,255,0.04)]":"text-fg-5/60 hover:text-fg-4"),children:i(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(pe,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!Ke?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:i("hub.noWorkspaces")}):c.map(o=>e.jsx(Ur,{workspace:o,sessions:gt[o.path]||[],loading:!!w[o.path]||!(o.path in d),isActive:o.path===l,selectedKey:et,openSessionKeys:qt,onSelectSession:It,onNewSession:Ct,onRefresh:ht,onRemove:Ye,onExtensions:$e,onWarmSession:Qe,onCancelWarmSession:yt,onSessionMenuOpen:xt,t:i},o.path))}),e.jsxs("div",{className:"shrink-0 border-t border-edge/20 px-3 py-2 space-y-1.5",children:[e.jsx("div",{className:"flex items-center rounded-md bg-inset/30 border border-edge/20 p-0.5",children:[1,2,3,6].map(o=>e.jsx("button",{onClick:()=>ae(o),className:I("flex-1 flex items-center justify-center p-1.5 rounded transition-all",N===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1)]":"text-fg-5/40 hover:text-fg-4"),title:i(`hub.layout${o}`),children:o===1?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"})}):o===2?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"12",rx:"1.5"}),e.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"1.5"})]}):o===3?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"0.5",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"11.5",y:"2",width:"4",height:"12",rx:"1"})]}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:[e.jsx("rect",{x:"0.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"0.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"})]})},o))}),e.jsxs(Ee,{variant:"ghost",size:"sm",onClick:()=>He(o=>!o),className:"w-full",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),i("hub.addWorkspace")]})]})]}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden gap-0",children:e.jsx("div",{className:"flex-1 min-h-0 grid gap-3",style:{gridTemplateColumns:`repeat(${N===6?3:N}, 1fr)`,gridTemplateRows:N===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=oe?_.length<N?_.length:B:-1;return wt.current=o,Array.from({length:N},(h,u)=>{if(oe&&u===o)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-edge bg-panel flex flex-col",style:{boxShadow:"var(--th-card-shadow)"},children:e.jsx(Dr,{workdir:oe,workspaceName:c.find(k=>k.path===oe)?.name||oe.split("/").pop()||"",onSessionCreated:St,onClose:Tt,t:i},oe)},`new-${oe}`);const p=_[u]??null;if(!p)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-dashed border-edge/40 bg-panel/30 flex items-center justify-center",children:e.jsxs("div",{className:"text-center px-4",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"mx-auto text-fg-5/20 mb-2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("div",{className:"text-[12px] text-fg-5/40",children:i("hub.emptySlot")})]})},`empty-${u}`);const v=Gt(p),y=u===B;return e.jsxs("div",{className:I("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>D(u),children:[e.jsxs("div",{className:I("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const k=Bt(v);return e.jsx(Kt,{variant:k==="running"?"ok":k==="waiting"?"info":k==="incomplete"?"warn":"idle",pulse:k==="running"||k==="waiting"})})(),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-0",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-fg-5",children:p.workdir.split("/").pop()||p.workdir}),e.jsx("span",{className:"shrink-0 text-fg-6 text-[10px] mx-1",children:"/"}),e.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-fg-3",children:v.title||v.lastQuestion?.slice(0,60)||(Dt(p.sessionId)?i("hub.newSession"):p.sessionId.slice(0,12))})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-2.5 pl-4 text-[9px] text-fg-5/50 tabular-nums",children:[e.jsx("span",{title:i("hub.created"),children:bs(v.createdAt)}),v.runUpdatedAt&&e.jsx("span",{title:i("hub.updated"),children:Rn(v.runUpdatedAt)}),!!v.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),v.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:k=>{k.stopPropagation(),ce(H=>!H)},className:I("p-0.5 rounded transition-colors",R?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:i("hub.files"),children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})})}),e.jsx("button",{onClick:k=>{k.stopPropagation(),Lt(u)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:i("hub.closePanel"),children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Tr,{session:v,workdir:p.workdir,active:n&&y,onSessionChange:k=>he(k,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>pt(p.mountKey)},p.mountKey)})})]},p.mountKey||V(p.agent,p.sessionId))})})()})}),R&&fe&&e.jsx(Kr,{workdir:fe.workdir,onClose:()=>ce(!1),t:i}),e.jsx(Or,{open:Ke,initialPath:l||void 0,onAdd:dt,onClose:()=>He(!1),t:i}),e.jsxs(Ut,{open:!!me,onClose:()=>!X&&_e(null),children:[e.jsx(zt,{title:i("hub.removeWorkspace"),onClose:()=>!X&&_e(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:i("modal.confirmRemoveWorkspaceHint")}),me&&e.jsx("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 font-mono text-[11px] text-fg-4 break-all",children:me}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ee,{variant:"ghost",onClick:()=>_e(null),disabled:X,children:i("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:ut,disabled:X,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(X?"modal.removing":"modal.remove")})]})]}),ie&&(()=>{const h=Math.max(8,Math.min(ie.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ie.anchor.bottom+4,window.innerHeight-60);return e.jsx("div",{className:"fixed z-[60] min-w-[160px] rounded-md border border-edge bg-panel/95 backdrop-blur-md py-1",style:{left:h,top:u,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:p=>p.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>we(ie.target),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-[12px] text-fg-2 hover:bg-panel-h/60 hover:text-red-400 transition-colors",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),e.jsx("path",{d:"M10 11v6"}),e.jsx("path",{d:"M14 11v6"}),e.jsx("path",{d:"M9 6V4a2 2 0 012-2h2a2 2 0 012 2v2"})]}),i("session.delete")]})})})(),e.jsxs(Ut,{open:!!Ie,onClose:()=>!ve&&be(null),children:[e.jsx(zt,{title:i("session.deleteTitle"),onClose:()=>!ve&&be(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("session.deleteHint")}),Ie&&e.jsxs("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 text-[11px] text-fg-4 break-all",children:[e.jsx("span",{className:"font-mono text-fg-5",children:Ie.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Ie.title})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:!Xe,onChange:()=>Je(!1),disabled:ve,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:i("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:i("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:Xe,onChange:()=>Je(!0),disabled:ve,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:i("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:i("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ee,{variant:"ghost",onClick:()=>be(null),disabled:ve,children:i("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:Nt,disabled:ve,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(ve?"session.deleting":"modal.remove")})]})]}),e.jsx(Cr,{open:!!Be,onClose:()=>$e(null),workdir:Be||""})]})});function Or({open:t,initialPath:n,onAdd:s,onClose:l,t:i}){const[c,x]=r.useState(""),d=r.useCallback(b=>x(b),[]);return r.useEffect(()=>{t&&x("")},[t]),e.jsxs(Ut,{open:t,onClose:l,children:[e.jsx(zt,{title:i("hub.addWorkspace"),onClose:l}),e.jsx(ks,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:i}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ee,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:i("hub.add")}),e.jsx(Ee,{variant:"secondary",onClick:l,className:"flex-1",children:i("hub.cancel")})]})]})}function Dr({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:i}){const[c,x]=r.useState(null),[d,b]=r.useState([]),w=r.useRef(null),g=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),T=r.useCallback(()=>{},[]),N=r.useCallback((A,_)=>{x(A||null),w.current=A||null;const S=_||[];b(S),g.current=S},[]),E=r.useCallback(A=>{const _=g.current;g.current=[],s(A,w.current||void 0,_.length?_:void 0)},[s]),L=!!c||d.length>0;return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 h-10 border-b border-edge/50 bg-panel/40 backdrop-blur-md z-10",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[13px] font-medium text-fg truncate",children:i("hub.newSession")}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-fg-5/60 shrink-0",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"})}),e.jsx("span",{className:"max-w-[80px] truncate",children:n})]}),e.jsx(Kt,{variant:L?"ok":"idle",pulse:L}),!L&&e.jsx("button",{onClick:l,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:L?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(Jn,{text:c||"",blocks:d.map(A=>({type:"image",content:A})),t:i}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(dn,{className:"text-fg-5"})})]}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"text-center space-y-1.5",children:e.jsx("div",{className:"text-[13px] text-fg-5",children:i("hub.newSessionHint")})})})}),e.jsx(Gs,{session:j,workdir:t,onStreamQueued:T,onSendStart:N,onSessionChange:E,t:i,streamPhase:null})]})}function Fr({git:t}){if(!t)return null;const n=[t.detached?`detached HEAD${t.shortSha?` @ ${t.shortSha}`:""}`:`branch ${t.branch??"?"}`,t.upstream?`upstream ${t.upstream}`:t.detached?"":"no upstream",t.ahead||t.behind?`↑${t.ahead} ahead · ↓${t.behind} behind`:"",t.changed>0?`${t.changed} changed (${t.staged} staged · ${t.unstaged} unstaged · ${t.untracked} untracked)`:"clean"].filter(Boolean).join(`
|
|
22
|
+
`).length:0,N=!!t&&(t.length>mr||T>br),[E,L]=r.useState(!1),A=t?N&&!E?vr(t):t:"",_=!!(l||i||c),S=n?.filter(M=>M.type==="image")||[],B=()=>{navigator.clipboard.writeText(t).then(()=>{w(!0),setTimeout(()=>w(!1),1500)}).catch(()=>{})},te=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(T));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[A,N&&!E&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),N&&e.jsx("button",{type:"button",onClick:()=>L(M=>!M),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:E?s("hub.collapse"):te}),S.length>0&&e.jsx("div",{className:I("flex flex-wrap gap-2",t&&"mt-2"),children:S.map((M,G)=>e.jsx("img",{src:M.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(M.content)},G))})]}),g&&e.jsx(Xn,{src:g,onClose:()=>j(null)}),_&&e.jsxs("div",{className:I("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(Rt,{label:s(b?"hub.copied":"hub.copy"),onClick:B,children:b?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),l&&e.jsx(Rt,{label:s("hub.rerun"),onClick:()=>l(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),i&&e.jsx(Rt,{label:s("hub.edit"),onClick:()=>i(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),c&&e.jsx(Rt,{label:s("hub.fork"),onClick:c,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]})})]})]})}function Rt({label:t,onClick:n,children:s}){return e.jsx("button",{onClick:n,title:t,className:"flex items-center justify-center w-7 h-7 rounded border border-fg-6 bg-panel text-fg-4 shadow-sm hover:text-fg-2 hover:border-edge-h hover:bg-panel-h transition-colors",children:s})}function jr({agent:t,meta:n,model:s,effort:l,providerName:i,previewMeta:c,liveStartedAt:x}){const d=c?.contextPercent??null,b=c?.contextUsedTokens??0,w=c?.turnOutputTokens??0,g=d!=null||b>0||w>0,j=x!=null&&x>0,T=c?.providerName??i??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(rt,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||l)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&l?" · ":"",l||""]}),T&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/70 px-1.5 py-px rounded bg-fg-5/8",title:`This turn is routed through ${T} (BYOK), not the agent CLI's native auth.`,children:["via ",T]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:Nr(c),children:[d!=null&&e.jsx(Sr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),b>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",yr(b)]}),w>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Zn(w)]}),j&&e.jsx(wr,{startedAt:x,leadingDot:g})]})]})}function wr({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const i=setInterval(()=>s(c=>c+1),1e3);return()=>clearInterval(i)},[]);const l=Math.max(0,Date.now()-t);return e.jsxs("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:[n?"· ":"",kr(l)]})}function kr(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),l=n%60;return s<60?`${s}m${l.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function yr(t){return`${Zn(t)} tok`}function Zn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function Nr(t){if(!t)return"";const n=[];return t.contextPercent!=null&&n.push(`Context: ${t.contextPercent.toFixed(1)}%`),t.inputTokens!=null&&n.push(`Input: ${t.inputTokens.toLocaleString()}`),t.turnOutputTokens!=null?n.push(`Output (turn): ${t.turnOutputTokens.toLocaleString()}`):t.outputTokens!=null&&n.push(`Output: ${t.outputTokens.toLocaleString()}`),t.cachedInputTokens!=null&&n.push(`Cached: ${t.cachedInputTokens.toLocaleString()}`),n.join(" · ")}function Sr({pct:t}){const n=t>=85?"bg-rose-400/70":t>=60?"bg-amber-400/70":"bg-emerald-400/70";return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${n}`})}function Ln(t,n,s){return t==="zh-CN"?n:s}function Cr({open:t,onClose:n,workdir:s}){const l=ye(c=>c.locale),i=s.split("/").pop()||s;return e.jsxs(Ut,{open:t,onClose:n,wide:!0,children:[e.jsx(zt,{title:Ln(l,`${i} — 项目扩展`,`${i} — Project Extensions`),description:Ln(l,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(Ss,{workdir:s}):null]})}let Mn=Pn(()=>import("./SessionPanel-CMu962uE.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function un(){return Mn??=Pn(()=>import("./SessionPanel-CMu962uE.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Mn}const Tr=r.lazy(async()=>({default:(await un()).SessionPanel})),ln=5,Ir=240,Lr=120,Mr=12,Er=900*1e3,V=(t,n)=>`${t}:${n}`;function Ar(t){const n=new Map;for(const d of t)n.set(V(d.agent||"",d.sessionId),d);const s=new Map,l=new Set;for(const d of t){const b=d.migratedFrom;if(!b||b.kind!=="fork"||!b.sessionId)continue;const w=V(b.agent||d.agent||"",b.sessionId);n.has(w)&&(l.add(V(d.agent||"",d.sessionId)),s.has(w)||s.set(w,[]),s.get(w).push(d))}const i=[],c=new Set,x=(d,b)=>{const w=V(d.agent||"",d.sessionId);if(c.has(w))return;c.add(w),i.push(Object.assign({},d,{__forkDepth:b}));const g=s.get(w);if(g)for(const j of g)x(j,b+1)};for(const d of t){const b=V(d.agent||"",d.sessionId);l.has(b)||x(d,0)}for(const d of t)x(d,0);return i}let Rr=0;function Pt(){return`mk-${Date.now().toString(36)}-${(++Rr).toString(36)}`}function _t(t){try{const n=localStorage.getItem(t);if(n!=null)return n;const s=sessionStorage.getItem(t);if(s!=null){try{localStorage.setItem(t,s),sessionStorage.removeItem(t)}catch{}return s}}catch{}return null}function Wt(t,n){try{localStorage.setItem(t,n)}catch{}}const Pr=[1,2,3,6],hn=6;function _r(t){for(const n of Pr)if(n>=t)return n;return hn}function En(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function Ue(t,n){const s=_r(t);return s>n?s:n}function Wr(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Br(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function es(t){switch(t){case"cursor":return"hub.openTargetCursor";case"windsurf":return"hub.openTargetWindsurf";case"finder":return"hub.openTargetFinder";case"default":return"hub.openTargetDefault";default:return"hub.openTargetVsCode"}}const $r=r.memo(function({active:n=!0}){const s=ye(o=>o.locale),l=ye(o=>o.state?.runtimeWorkdir??null),i=r.useMemo(()=>ps(s),[s]),[c,x]=r.useState([]),[d,b]=r.useState({}),[w,g]=r.useState({}),[j,T]=r.useState(!0),[N,E]=r.useState(()=>{const o=_t("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):En()}),[L,A]=r.useState(()=>{const o=_t("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):En()}),[_,S]=r.useState(()=>{try{const o=_t("pikiloom-open-sessions");if(o){const h=JSON.parse(o);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||Pt()}))}}catch{}return[]}),[B,te]=r.useState(()=>{const o=_t("pikiloom-active-slot");if(o!=null){const h=Number(o);if(Number.isFinite(h)&&h>=0)return h}return 0}),M=r.useCallback(o=>{E(o),Wt("pikiloom-layout-mode",String(o))},[]),G=r.useCallback(o=>{A(o),Wt("pikiloom-layout-floor",String(o))},[]),W=r.useCallback(o=>{S(h=>{const u=typeof o=="function"?o(h):o,p=u.map(({pendingPrompt:v,pendingImageUrls:y,...k})=>k);return Wt("pikiloom-open-sessions",JSON.stringify(p)),u})},[]),D=r.useCallback(o=>{te(h=>{const u=typeof o=="function"?o(h):o;return Wt("pikiloom-active-slot",String(u)),u})},[]),ae=r.useCallback(o=>{M(o),G(o)},[M,G]);r.useEffect(()=>{W(o=>o.length>N?o.slice(0,N):o),D(o=>o>=N?N-1:o)},[N]);const[R,ce]=r.useState(!1),re=r.useRef(N);re.current=N;const Y=r.useRef(L);Y.current=L;const Ne=r.useRef(B);Ne.current=B;const K=r.useRef(_);K.current=_;const wt=r.useRef(-1),fe=_[B]??null,lt=r.useCallback(o=>{if(!o){W([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:Pt()};W(u=>{const p=u.findIndex(y=>y.agent===h.agent&&y.sessionId===h.sessionId);if(p>=0)return D(p),u;if(u.length<re.current){const y=[...u,h];return D(y.length-1),y}if(re.current<hn){const y=[...u,h];return M(Ue(y.length,Y.current)),D(y.length-1),y}const v=[...u];return v[Ne.current]=h,v})},[W,D,M]),[Ke,He]=r.useState(!1),[oe,Ae]=r.useState(null),[ne,Se]=r.useState(""),[Re,Ve]=r.useState("all"),[de,kt]=r.useState({}),[ue,Ge]=r.useState({}),Pe=r.useDeferredValue(ne),se=r.useRef(!1),qe=r.useRef({}),Ce=r.useRef(d);Ce.current=d;const Te=r.useRef(de);Te.current=de;const at=r.useRef(new Set),$=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values($.current))clearTimeout(o)},[]),r.useEffect(()=>{W(o=>{let h=!1;const u=o.map(p=>{const v=ue[p.workdir];if(!v)return p;const y=Nn(v,p.agent,p.sessionId);return y===p.sessionId?p:(h=!0,{...p,sessionId:y})});return h?u:o})},[ue,W]);const q=r.useCallback(async()=>{try{const o=await ee.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((p,v)=>p.path===h[v].path&&p.name===h[v].name)?u:h),se.current=!0}catch{se.current=!0}finally{T(!1)}},[]);r.useEffect(()=>{q()},[q]);const U=r.useCallback(async(o,h={})=>{if(!qe.current[o]){qe.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Ms(o,{force:h.force});r.startTransition(()=>{Ge(p=>{const v=u.promotions||{},y=p[o];return y&&Object.keys(y).length===Object.keys(v).length&&Object.entries(v).every(([k,H])=>y[k]===H)?p:{...p,[o]:v}}),b(p=>{const v=u.sessions||[],y=p[o]||[],k=new Set(v.map(F=>V(F.agent||"",F.sessionId))),H=y.filter(F=>{if(F.runState!=="running")return!1;const P=V(F.agent||"",F.sessionId);if(k.has(P))return!1;const O=Te.current[P];return!(O?.resolvedKey&&O.resolvedKey!==P)});return{...p,[o]:H.length?[...H,...v]:v}})})}catch{h.background||r.startTransition(()=>{b(u=>({...u,[o]:[]}))})}finally{qe.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),ct=r.useRef(l);r.useEffect(()=>{l!==ct.current&&(ct.current=l,!(!l||!se.current)&&q().then(()=>{U(l,{force:!0})}))},[l,q,U]);const Q=r.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(un(),Rs({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Mr}))},[]),Qe=r.useCallback((o,h,u=Lr)=>{const p=`${h}:${V(o.agent||"",o.sessionId)}`,v=$.current[p];v&&clearTimeout(v),$.current[p]=setTimeout(()=>{delete $.current[p],Q(o,h)},u)},[Q]),yt=r.useCallback((o,h)=>{const u=`${h}:${V(o.agent||"",o.sessionId)}`,p=$.current[u];p&&(clearTimeout(p),delete $.current[u])},[]);r.useEffect(()=>{n&&un()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||w[h.path])return;const p=setTimeout(()=>{U(h.path)},u*90);o.push(p)}),()=>{for(const h of o)clearTimeout(h)}},[n,U,w,d,c]);const Vt=r.useRef(new Map);Sn(n&&se.current&&c.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=o.key,u=h?c.filter(y=>(Ce.current[y.path]||[]).some(k=>V(k.agent||"",k.sessionId)===h)):c,p=u.length?u:c,v=Vt.current;for(const y of p)v.has(y.path)&&clearTimeout(v.get(y.path)),v.set(y.path,setTimeout(()=>{v.delete(y.path),U(y.path,{background:!0,force:!0})},300))},[c,U]));const ge=r.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:fs(o,de[V(h,o.sessionId)]||null)},[de]);Sn("stream-update",r.useCallback(o=>{const h=o.key;if(!h)return;const u=gs(h,o.snapshot??null);kt(p=>{if(!u){const P=p[h];return!P||P.phase==="done"?p:{...p,[h]:{...P,phase:"done",updatedAt:Date.now()}}}const v=(P,O)=>!!P&&!!O&&P.phase===O.phase&&P.resolvedKey===O.resolvedKey&&P.sessionId===O.sessionId&&P.incomplete===O.incomplete&&P.error===O.error,y=v(p[h],u),k=u.resolvedKey===h||v(p[u.resolvedKey],{...u,key:u.resolvedKey});if(y&&k)return p;const H=Date.now()-Er,F={};for(const[P,O]of Object.entries(p))O.phase==="done"&&O.updatedAt<H||(F[P]=O);return F[h]=u,u.resolvedKey!==h&&(F[u.resolvedKey]={...u,key:u.resolvedKey}),F})},[])),ms(r.useCallback(()=>{if(!(!n||!se.current||c.length===0))for(const o of c)U(o.path,{background:!0,force:!0})},[n,c,U])),r.useEffect(()=>{if(!n||!se.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)U(u.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,U,c]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const p=(d[h.path]||[])[0];if(!p)return;const v=`${h.path}:${V(p.agent||"",p.sessionId)}`;if(at.current.has(v))return;const y=setTimeout(()=>{at.current.add(v),Q(p,h.path)},Ir+u*120);o.push(y)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,Q,c]);const dt=r.useCallback(async o=>{try{(await ee.addWorkspace(o)).ok&&(He(!1),await q(),U(o))}catch{}},[q,U]),[me,_e]=r.useState(null),[X,We]=r.useState(!1),[Be,$e]=r.useState(null),Ye=r.useCallback(o=>{_e(o)},[]),ut=r.useCallback(async()=>{const o=me;if(o){We(!0);try{await ee.removeWorkspace(o),x(h=>h.filter(u=>u.path!==o)),b(h=>{const u={...h};return delete u[o],u}),W(h=>{const u=h.filter(p=>p.workdir!==o);return u.length!==h.length&&M(Ue(u.length,Y.current)),u}),D(0),_e(null)}catch{}finally{We(!1)}}},[me]),ht=r.useCallback(o=>{U(o,{force:!0})},[U]),[Ie,be]=r.useState(null),[Xe,Je]=r.useState(!1),[ve,Le]=r.useState(!1),je=ye(o=>o.toast),[ie,Ze]=r.useState(null),xt=r.useCallback((o,h,u)=>{Ze({anchor:{right:o.right,bottom:o.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:An(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!ie)return;const o=()=>Ze(null),h=u=>{u.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",h)}},[ie]);const we=r.useCallback(o=>{Je(!1),be(o),Ze(null)},[]),Nt=r.useCallback(async()=>{const o=Ie;if(o){Le(!0);try{const h=await ee.deleteSession(o.workdir,o.agent,o.sessionId,Xe);if(!h.ok){const u=h.error?.includes("still running")?i("session.deleteRunningError"):h.error||i("session.deleteFailed");je(u,!1);return}b(u=>{const p=u[o.workdir];if(!p)return u;const v=p.filter(y=>!(y.agent===o.agent&&y.sessionId===o.sessionId));return v.length===p.length?u:{...u,[o.workdir]:v}}),W(u=>{const p=u.filter(v=>!(v.workdir===o.workdir&&v.agent===o.agent&&v.sessionId===o.sessionId));return p.length!==u.length&&M(Ue(p.length,Y.current)),p}),be(null)}catch(h){je(h?.message||i("session.deleteFailed"),!1)}finally{Le(!1)}}},[Ie,Xe,i,je]),pt=r.useCallback(o=>{W(h=>{let u=!1;const p=h.map(v=>v.mountKey===o&&(v.pendingPrompt!=null||v.pendingImageUrls)?(u=!0,{...v,pendingPrompt:null,pendingImageUrls:void 0}):v);return u?p:h})},[W]),St=r.useCallback((o,h,u)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),b(y=>{const k=y[o.workdir]||[];if(k.some(P=>P.sessionId===o.sessionId&&P.agent===o.agent))return y;const F={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...y,[o.workdir]:[F,...k]}});const p=wt.current,v={...o,mountKey:Pt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};r.startTransition(()=>{Ae(null),W(y=>{if(p>=y.length)return[...y,v];const k=[...y];return k[p]=v,k}),D(p>=0?p:0)}),U(o.workdir,{background:!0,force:!0})},[U,Q,W,D]),Ct=r.useCallback(o=>{K.current.length>=re.current&&re.current<hn&&M(Ue(re.current+1,Y.current)),Ae(o)},[M]),Tt=r.useCallback(()=>{Ae(null),M(Ue(K.current.length,Y.current))},[M]),It=r.useCallback((o,h)=>{Q(o,h);const u=o.agent||"";K.current.some(p=>p.agent===u&&p.sessionId===o.sessionId)&&M(Ue(K.current.length,Y.current)),Ae(null),r.startTransition(()=>{lt({agent:u,sessionId:o.sessionId,workdir:h})})},[Q,M]),he=r.useCallback((o,h)=>{Q({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{h!=null?(W(u=>{if(h>=u.length)return u;const p=[...u];return p[h]={...u[h],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},p}),D(h)):lt({...o,mountKey:Pt()})}),U(o.workdir,{background:!0,force:!0})},[U,Q]),ft=r.useCallback(o=>{let h=o;if(Re==="running"?h=h.filter(u=>Bt(u)==="running"):Re==="review"&&(h=h.filter(u=>Bt(u)==="incomplete")),Pe.trim()){const u=Pe.toLowerCase();h=h.filter(p=>(p.lastMessageText||"").toLowerCase().includes(u)||(p.lastQuestion||"").toLowerCase().includes(u)||(p.lastAnswer||"").toLowerCase().includes(u)||(p.title||"").toLowerCase().includes(u)||(p.agent||"").toLowerCase().includes(u))}return h},[Pe,Re]),gt=r.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(ge),p=ue[h.path],v=new Map;for(const k of u){const H=V(k.agent||"",k.sessionId),F=de[H],P=p?Nn(p,k.agent||"",k.sessionId):k.sessionId,O=F?.resolvedKey&&F.resolvedKey!==H?F.resolvedKey:P!==k.sessionId?V(k.agent||"",P):H,mt=v.get(O);if(!mt){v.set(O,k);continue}V(mt.agent||"",mt.sessionId)!==O&&H===O&&v.set(O,k)}const y=ft([...v.values()]);o[h.path]=Ar(y)}return o},[c,d,de,ue,ft,ge]),Gt=r.useCallback(o=>{const h=(d[o.workdir]||[]).find(u=>u.sessionId===o.sessionId&&u.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return ge(h)},[ge,d]),qt=r.useMemo(()=>new Set(_.map(o=>V(o.agent,o.sessionId))),[_]),et=fe?V(fe.agent,fe.sessionId):null,Lt=r.useCallback(o=>{W(h=>{const u=h.filter((p,v)=>v!==o);return u.length===0?D(0):Ne.current>=u.length&&D(u.length-1),M(Ue(u.length,Y.current)),u})},[W,D,M]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:ne,onChange:o=>Se(o.target.value),placeholder:i("hub.search"),className:"w-full rounded-lg border border-edge/40 bg-inset/50 pl-8 pr-7 py-1.5 text-[12px] text-fg outline-none placeholder:text-fg-5/30 focus:border-primary/30 focus:bg-inset focus:shadow-[0_0_0_3px_rgba(99,102,241,0.06)] transition-all duration-200"}),ne&&e.jsx("button",{onClick:()=>Se(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-fg-5/30 hover:text-fg-4 transition-colors",children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex items-center rounded-lg bg-inset/30 border border-edge/20 p-0.5",children:["all","running","review"].map(o=>e.jsx("button",{onClick:()=>Ve(o),className:I("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",Re===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1),inset_0_1px_0_rgba(255,255,255,0.04)]":"text-fg-5/60 hover:text-fg-4"),children:i(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(pe,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!Ke?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:i("hub.noWorkspaces")}):c.map(o=>e.jsx(Ur,{workspace:o,sessions:gt[o.path]||[],loading:!!w[o.path]||!(o.path in d),isActive:o.path===l,selectedKey:et,openSessionKeys:qt,onSelectSession:It,onNewSession:Ct,onRefresh:ht,onRemove:Ye,onExtensions:$e,onWarmSession:Qe,onCancelWarmSession:yt,onSessionMenuOpen:xt,t:i},o.path))}),e.jsxs("div",{className:"shrink-0 border-t border-edge/20 px-3 py-2 space-y-1.5",children:[e.jsx("div",{className:"flex items-center rounded-md bg-inset/30 border border-edge/20 p-0.5",children:[1,2,3,6].map(o=>e.jsx("button",{onClick:()=>ae(o),className:I("flex-1 flex items-center justify-center p-1.5 rounded transition-all",N===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1)]":"text-fg-5/40 hover:text-fg-4"),title:i(`hub.layout${o}`),children:o===1?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"})}):o===2?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"12",rx:"1.5"}),e.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"1.5"})]}):o===3?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"0.5",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"11.5",y:"2",width:"4",height:"12",rx:"1"})]}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:[e.jsx("rect",{x:"0.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"0.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"})]})},o))}),e.jsxs(Ee,{variant:"ghost",size:"sm",onClick:()=>He(o=>!o),className:"w-full",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),i("hub.addWorkspace")]})]})]}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden gap-0",children:e.jsx("div",{className:"flex-1 min-h-0 grid gap-3",style:{gridTemplateColumns:`repeat(${N===6?3:N}, 1fr)`,gridTemplateRows:N===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=oe?_.length<N?_.length:B:-1;return wt.current=o,Array.from({length:N},(h,u)=>{if(oe&&u===o)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-edge bg-panel flex flex-col",style:{boxShadow:"var(--th-card-shadow)"},children:e.jsx(Dr,{workdir:oe,workspaceName:c.find(k=>k.path===oe)?.name||oe.split("/").pop()||"",onSessionCreated:St,onClose:Tt,t:i},oe)},`new-${oe}`);const p=_[u]??null;if(!p)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-dashed border-edge/40 bg-panel/30 flex items-center justify-center",children:e.jsxs("div",{className:"text-center px-4",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"mx-auto text-fg-5/20 mb-2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("div",{className:"text-[12px] text-fg-5/40",children:i("hub.emptySlot")})]})},`empty-${u}`);const v=Gt(p),y=u===B;return e.jsxs("div",{className:I("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",y?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:y?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>D(u),children:[e.jsxs("div",{className:I("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",y?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const k=Bt(v);return e.jsx(Kt,{variant:k==="running"?"ok":k==="waiting"?"info":k==="incomplete"?"warn":"idle",pulse:k==="running"||k==="waiting"})})(),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-0",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-fg-5",children:p.workdir.split("/").pop()||p.workdir}),e.jsx("span",{className:"shrink-0 text-fg-6 text-[10px] mx-1",children:"/"}),e.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-fg-3",children:v.title||v.lastQuestion?.slice(0,60)||(Dt(p.sessionId)?i("hub.newSession"):p.sessionId.slice(0,12))})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-2.5 pl-4 text-[9px] text-fg-5/50 tabular-nums",children:[e.jsx("span",{title:i("hub.created"),children:bs(v.createdAt)}),v.runUpdatedAt&&e.jsx("span",{title:i("hub.updated"),children:Rn(v.runUpdatedAt)}),!!v.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),v.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:k=>{k.stopPropagation(),ce(H=>!H)},className:I("p-0.5 rounded transition-colors",R?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:i("hub.files"),children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})})}),e.jsx("button",{onClick:k=>{k.stopPropagation(),Lt(u)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:i("hub.closePanel"),children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Tr,{session:v,workdir:p.workdir,active:n&&y,onSessionChange:k=>he(k,u),initialPendingPrompt:p.pendingPrompt??null,initialPendingImageUrls:p.pendingImageUrls,onPendingPromptConsumed:()=>pt(p.mountKey)},p.mountKey)})})]},p.mountKey||V(p.agent,p.sessionId))})})()})}),R&&fe&&e.jsx(Kr,{workdir:fe.workdir,onClose:()=>ce(!1),t:i}),e.jsx(Or,{open:Ke,initialPath:l||void 0,onAdd:dt,onClose:()=>He(!1),t:i}),e.jsxs(Ut,{open:!!me,onClose:()=>!X&&_e(null),children:[e.jsx(zt,{title:i("hub.removeWorkspace"),onClose:()=>!X&&_e(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:i("modal.confirmRemoveWorkspaceHint")}),me&&e.jsx("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 font-mono text-[11px] text-fg-4 break-all",children:me}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ee,{variant:"ghost",onClick:()=>_e(null),disabled:X,children:i("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:ut,disabled:X,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(X?"modal.removing":"modal.remove")})]})]}),ie&&(()=>{const h=Math.max(8,Math.min(ie.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ie.anchor.bottom+4,window.innerHeight-60);return e.jsx("div",{className:"fixed z-[60] min-w-[160px] rounded-md border border-edge bg-panel/95 backdrop-blur-md py-1",style:{left:h,top:u,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:p=>p.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>we(ie.target),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-[12px] text-fg-2 hover:bg-panel-h/60 hover:text-red-400 transition-colors",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),e.jsx("path",{d:"M10 11v6"}),e.jsx("path",{d:"M14 11v6"}),e.jsx("path",{d:"M9 6V4a2 2 0 012-2h2a2 2 0 012 2v2"})]}),i("session.delete")]})})})(),e.jsxs(Ut,{open:!!Ie,onClose:()=>!ve&&be(null),children:[e.jsx(zt,{title:i("session.deleteTitle"),onClose:()=>!ve&&be(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:i("session.deleteHint")}),Ie&&e.jsxs("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 text-[11px] text-fg-4 break-all",children:[e.jsx("span",{className:"font-mono text-fg-5",children:Ie.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:Ie.title})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:!Xe,onChange:()=>Je(!1),disabled:ve,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:i("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:i("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:Xe,onChange:()=>Je(!0),disabled:ve,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:i("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:i("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Ee,{variant:"ghost",onClick:()=>be(null),disabled:ve,children:i("modal.cancel")}),e.jsx(Ee,{variant:"primary",onClick:Nt,disabled:ve,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:i(ve?"session.deleting":"modal.remove")})]})]}),e.jsx(Cr,{open:!!Be,onClose:()=>$e(null),workdir:Be||""})]})});function Or({open:t,initialPath:n,onAdd:s,onClose:l,t:i}){const[c,x]=r.useState(""),d=r.useCallback(b=>x(b),[]);return r.useEffect(()=>{t&&x("")},[t]),e.jsxs(Ut,{open:t,onClose:l,children:[e.jsx(zt,{title:i("hub.addWorkspace"),onClose:l}),e.jsx(ks,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:i}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Ee,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:i("hub.add")}),e.jsx(Ee,{variant:"secondary",onClick:l,className:"flex-1",children:i("hub.cancel")})]})]})}function Dr({workdir:t,workspaceName:n,onSessionCreated:s,onClose:l,t:i}){const[c,x]=r.useState(null),[d,b]=r.useState([]),w=r.useRef(null),g=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),T=r.useCallback(()=>{},[]),N=r.useCallback((A,_)=>{x(A||null),w.current=A||null;const S=_||[];b(S),g.current=S},[]),E=r.useCallback(A=>{const _=g.current;g.current=[],s(A,w.current||void 0,_.length?_:void 0)},[s]),L=!!c||d.length>0;return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 h-10 border-b border-edge/50 bg-panel/40 backdrop-blur-md z-10",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[13px] font-medium text-fg truncate",children:i("hub.newSession")}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-fg-5/60 shrink-0",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"})}),e.jsx("span",{className:"max-w-[80px] truncate",children:n})]}),e.jsx(Kt,{variant:L?"ok":"idle",pulse:L}),!L&&e.jsx("button",{onClick:l,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:L?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(Jn,{text:c||"",blocks:d.map(A=>({type:"image",content:A})),t:i}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(dn,{className:"text-fg-5"})})]}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"text-center space-y-1.5",children:e.jsx("div",{className:"text-[13px] text-fg-5",children:i("hub.newSessionHint")})})})}),e.jsx(Gs,{session:j,workdir:t,onStreamQueued:T,onSendStart:N,onSessionChange:E,t:i,streamPhase:null})]})}function Fr({git:t}){if(!t)return null;const n=[t.detached?`detached HEAD${t.shortSha?` @ ${t.shortSha}`:""}`:`branch ${t.branch??"?"}`,t.upstream?`upstream ${t.upstream}`:t.detached?"":"no upstream",t.ahead||t.behind?`↑${t.ahead} ahead · ↓${t.behind} behind`:"",t.changed>0?`${t.changed} changed (${t.staged} staged · ${t.unstaged} unstaged · ${t.untracked} untracked)`:"clean"].filter(Boolean).join(`
|
|
23
23
|
`);return e.jsx(vs,{content:n,className:I("shrink-0 items-center",t.changed>0?"text-amber-400/80":t.ahead||t.behind?"text-sky-400/70":"text-fg-5/50"),onClick:s=>s.stopPropagation(),children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.5"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.5"}),e.jsx("circle",{cx:"18",cy:"8",r:"2.5"}),e.jsx("path",{d:"M6 8.5v7"}),e.jsx("path",{d:"M18 10.5c0 4.5-6 3-6 7.5"})]})})}const Ur=r.memo(function({workspace:n,sessions:s,loading:l,isActive:i,selectedKey:c,openSessionKeys:x,onSelectSession:d,onNewSession:b,onRefresh:w,onRemove:g,onExtensions:j,onWarmSession:T,onCancelWarmSession:N,onSessionMenuOpen:E,t:L}){const[A,_]=r.useState(!0),[S,B]=r.useState(ln);r.useEffect(()=>{B(ln)},[s.length]);const te=s.slice(0,S),M=s.length-S,G=n.path,[W,D]=r.useState(null),ae=r.useCallback(()=>{ee.getWorkspaceGit(G).then(R=>D(R.git)).catch(()=>D(null))},[G]);return r.useEffect(()=>{ae()},[ae]),e.jsxs("div",{className:"border-b border-edge/30",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-panel-h/50 transition-colors",onClick:()=>_(R=>!R),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:I("shrink-0 text-fg-5 transition-transform duration-150",A&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[e.jsx("span",{className:I("min-w-0 truncate text-[12px] font-semibold",i?"text-primary":"text-fg-3"),children:n.name}),e.jsx(Fr,{git:W})]}),i&&e.jsx(Kt,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:R=>{R.stopPropagation(),b(G)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:L("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:R=>{R.stopPropagation(),j(G)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:L("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:R=>{R.stopPropagation(),w(G),ae()},className:"p-1 rounded text-fg-5 hover:text-fg-2 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),!i&&e.jsx("button",{onClick:R=>{R.stopPropagation(),g(G)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),A&&e.jsx("div",{className:"pb-1",children:l?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):s.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:L("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[te.map(R=>{const ce=V(R.agent||"",R.sessionId),re=R.__forkDepth||0;return e.jsx(zr,{session:R,isSelected:c===ce,isOpen:x?.has(ce)??!1,forkDepth:re,onClick:()=>d(R,G),onWarm:()=>T(R,G),onCancelWarm:()=>N(R,G),onShowMenu:Y=>E(Y,R,G),menuLabel:L("session.openActions")},ce)}),M>0&&e.jsxs("button",{onClick:()=>B(R=>R+ln),className:"flex items-center gap-1.5 w-full px-3 py-1.5 text-[11px] text-fg-5 hover:text-fg-3 hover:bg-panel-h/50 transition-colors",children:[e.jsxs("span",{children:["+ ",L("hub.nMore").replace("{n}",String(M))]}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]})})]})}),zr=r.memo(function({session:n,isSelected:s,isOpen:l,forkDepth:i=0,onClick:c,onWarm:x,onCancelWarm:d,onShowMenu:b,menuLabel:w}){const g=an(n.agent||""),j=Bt(n),T=An(n).slice(0,500)||(Dt(n.sessionId)?"":n.sessionId.slice(0,16)),N=js(n,T).slice(0,500),E=n.model?Ft(n.model):null,L=i>0?Math.min(i,3)*14:0,A=l?10:12,_=r.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:x,onFocus:x,onMouseLeave:d,onBlur:d,className:I("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":l?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:A+L,...l?{borderLeft:`2px solid ${s?g.color:`${g.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[i>0&&e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-fg-5/60 shrink-0","aria-label":"Fork",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]}),e.jsx(rt,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),E&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:E}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5 shrink-0 transition-opacity group-hover:opacity-0 group-focus-within:opacity-0",children:[!!n.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5 text-fg-5/50 tabular-nums",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-50",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),n.numTurns]}),e.jsx("span",{className:"tabular-nums",children:Rn(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Kt,{variant:j==="running"?"ok":j==="waiting"?"info":j==="incomplete"?"warn":"idle",pulse:j==="running"||j==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:T})]}),N&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:N})})]}),e.jsx("button",{ref:_,type:"button","aria-label":w,"aria-haspopup":"menu",onMouseDown:S=>{S.stopPropagation()},onClick:S=>{S.stopPropagation(),S.preventDefault(),_.current&&b(_.current.getBoundingClientRect())},className:"absolute top-1.5 right-1.5 p-1 rounded text-fg-5 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:bg-panel-h hover:text-fg-2 transition-opacity",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"5",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})})]})}),Kr=r.memo(function({workdir:n,onClose:s,t:l}){const i=ye(g=>g.state?.hostApp??null),c=ye(g=>g.state?.platform??null),x=ye(g=>g.toast),[d,b]=r.useState(()=>Br(i,c)),w=r.useCallback(async g=>{try{const j=await ee.openInEditor(g,d);if(!j.ok)throw new Error(j.error||`Failed to open ${g}`)}catch(j){x(j?.message||String(j),!1)}},[d,x]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:l("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:l("hub.closePanel"),children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"shrink-0 px-2.5 py-1.5 border-b border-edge/20 flex items-center gap-2",children:[e.jsx(ws,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:l(es(g))})),onChange:g=>{Wr(g)&&b(g)},renderIcon:g=>e.jsx(ts,{target:g,size:14})}),e.jsx(Ee,{size:"sm",variant:"ghost",onClick:()=>w(n),className:"flex-1 min-w-0 text-[11px]",children:l("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(Hr,{basePath:n,openTarget:d,onOpenPath:w,t:l})})]})});function ts({target:t,size:n=16}){return t==="default"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 16 16",className:"shrink-0 text-fg-4",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 3H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-2"}),e.jsx("path",{d:"M9 2h5v5"}),e.jsx("path",{d:"M14 2L7 9"})]}):e.jsx(rt,{brand:t,size:n})}function Hr({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:l,t:i}){const[c,x]=r.useState([]),[d,b]=r.useState(!0);r.useEffect(()=>{let g=!1;return b(!0),ee.lsDir(t,!0,n).then(j=>{!g&&j.ok&&x(j.dirs.slice(0,50).map(T=>({entry:T,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||b(!1)}),()=>{g=!0}},[t,n]);const w=r.useCallback(g=>{const j=T=>T.map(N=>N.entry.path===g?N.expanded?{...N,expanded:!1}:N.children===null?(ee.lsDir(g,!0,n).then(E=>{E.ok&&x(L=>xn(L,g,{children:E.dirs.slice(0,50).map(A=>({entry:A,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(E=>xn(E,g,{children:[],loading:!1}))}),{...N,loading:!0,expanded:!0}):{...N,expanded:!0}:N.children?{...N,children:j(N.children)}:N);x(T=>j(T))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(pe,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(ns,{nodes:c,depth:0,onToggle:w,openTarget:s,onOpenPath:l,t:i})})}function ns({nodes:t,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(Vr,{node:x,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c},x.entry.path))})}function Vr({node:t,depth:n,onToggle:s,openTarget:l,onOpenPath:i,t:c}){const{entry:x,expanded:d,children:b,loading:w}=t,g=n*14,[j,T]=r.useState(!1),N=c(es(l)),E=c("hub.openWithTarget").replace("{target}",N);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>T(!0),onMouseLeave:()=>T(!1),className:I("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",x.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+g,paddingRight:8},children:[x.isDir?w?e.jsx(pe,{className:"h-2 w-2 text-fg-5 shrink-0"}):e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:I("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),x.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:x.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:L=>{L.stopPropagation(),i(x.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:E,children:e.jsx(ts,{target:l,subtle:!0})}),!x.isDir&&e.jsx(Gr,{filePath:x.path,t:c})]})]}),x.isDir&&d&&b&&b.length>0&&e.jsx(ns,{nodes:b,depth:n+1,onToggle:s,openTarget:l,onOpenPath:i,t:c})]})}function Gr({filePath:t,t:n}){const[s,l]=r.useState(!1);return e.jsx("button",{onClick:i=>{i.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{l(!0),setTimeout(()=>l(!1),1500)}).catch(()=>{})},className:I("p-0.5 rounded transition-colors",s?"text-ok":"text-fg-5 hover:text-fg-3"),title:n("hub.copied"),children:s?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})}function xn(t,n,s){return t.map(l=>l.entry.path===n?{...l,...s}:l.children?{...l,children:xn(l.children,n,s)}:l)}const xo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:$r},Symbol.toStringTag,{value:"Module"}));export{Gs as I,uo as L,rr as R,ho as T,Jn as U,lo as a,qn as b,oo as c,ro as d,dn as e,co as f,jr as g,xo as i,As as l,ao as m,io as n,so as o,Es as p,no as s};
|