fourth-spark 0.11.36 → 0.11.37

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.
@@ -520,7 +520,7 @@ Please change the parent <Route path="${S}"> to <Route path="${S==="/"?"*":`${S}
520
520
  */const e$=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],Cc=Ie("zap",e$),Yp="fourth-spark-server-url";function t$(){if(typeof window>"u")return!1;const t=window.Capacitor;return typeof(t==null?void 0:t.isNativePlatform)=="function"&&t.isNativePlatform()}function PE(){return localStorage.getItem(Yp)??""}function n$(e){const t=e.replace(/\/+$/,"");t?localStorage.setItem(Yp,t):localStorage.removeItem(Yp)}function Wv(){return localStorage.getItem(Yp)??""}class Li extends Error{constructor(n,r){super(n);pt(this,"status");this.name="ApiError",this.status=r}}async function Te(e,t){let n;try{n=await fetch(PE()+e,{...t,headers:{Accept:"application/json",...t!=null&&t.body?{"Content-Type":"application/json"}:{},...t==null?void 0:t.headers}})}catch(a){throw new Li(a instanceof Error?a.message:"Network request failed",0)}if(!n.ok){const a=await n.text().catch(()=>"");throw new Li(a.trim()||`${n.status} ${n.statusText}`,n.status)}if(n.status===204)return;const r=await n.text();if(r)return JSON.parse(r)}function Ia(e,...t){if(Array.isArray(e))return e;if(e&&typeof e=="object"){const n=e;for(const r of[...t,"data","items"])if(Array.isArray(n[r]))return n[r]}return[]}function JR(e,...t){if(e&&typeof e=="object"&&!Array.isArray(e)){const r=e;if(Array.isArray(r.items)&&typeof r.total=="number")return{items:r.items,total:r.total,limit:typeof r.limit=="number"?r.limit:50,offset:typeof r.offset=="number"?r.offset:0}}const n=Ia(e,...t);return{items:n,total:n.length,limit:n.length,offset:0}}async function r$(){return Ia(await Te("/api/repos"),"repos")}async function a$(e,t,n,r){return Te("/api/repos",{method:"POST",body:JSON.stringify({name:e,gitUrl:t,localPath:n,runtimeType:r})})}async function i$(e){return Te("/api/repos/resolve",{method:"POST",body:JSON.stringify({localPath:e})})}async function s$(e,t){return Te("/api/fs/browse",{method:"POST",body:JSON.stringify({path:e,showHidden:t})})}async function o$(e,t){return Te("/api/repos/clone",{method:"POST",body:JSON.stringify({gitUrl:e,targetDir:t})})}async function l$(e){await Te(`/api/repos/${encodeURIComponent(e)}`,{method:"DELETE"})}async function u$(e){await Te(`/api/repos/${encodeURIComponent(e)}/start`,{method:"POST"})}async function c$(e){await Te(`/api/repos/${encodeURIComponent(e)}/stop`,{method:"POST"})}async function d$(e){return Te(`/api/repos/${encodeURIComponent(e)}/branches`)}async function f$(e,t){return Te(`/api/repos/${encodeURIComponent(e)}/checkout`,{method:"POST",body:JSON.stringify({branch:t})})}async function h$(e){return Te(`/api/repos/${encodeURIComponent(e)}/pull`,{method:"POST"})}function nt(e){return`/api/repos/${encodeURIComponent(e)}`}async function m$(e){return Ia(await Te(`${nt(e)}/workspaces`),"workspaces")}async function p$(e,t){await Te(`${nt(e)}/workspaces/${encodeURIComponent(t)}`,{method:"DELETE"})}async function g$(e){return Te(`${nt(e)}/workspaces/cleanup`,{method:"POST"})}async function b$(e,t){await Te(`/api/repos/${e}/worktree`,{method:"PATCH",body:JSON.stringify({enabled:t})})}async function x$(e,t){await Te(`/api/repos/${e}/runtime`,{method:"PATCH",body:JSON.stringify({runtimeType:t})})}async function y$(e,t){const n=new URLSearchParams;n.set("limit",String(t.limit)),(t==null?void 0:t.offset)!=null&&n.set("offset",String(t.offset));const r=n.toString();return JR(await Te(`${nt(e)}/sessions${r?`?${r}`:""}`),"sessions")}async function v$(e,t,n,r,a,i,o,u){return Te(`${nt(e)}/sessions`,{method:"POST",body:JSON.stringify({message:t,agent:n,model:r,variant:a,issueId:i,customAgentId:o,files:u})})}async function E$(e,t,n,r,a,i,o){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/actions/prompt`,{method:"POST",body:JSON.stringify({content:n,agent:r,model:a,variant:i,files:o})})}async function N$(e,t){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/actions/abort`,{method:"POST"})}async function S$(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/questions/reply`,{method:"POST",body:JSON.stringify({answers:n})})}async function w$(e,t){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/questions/reject`,{method:"POST"})}async function _$(e,t,n){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/actions/revert`,{method:"POST",body:JSON.stringify({messageID:n})})}function lA(e){const t=e,n=t.info;if(n&&typeof n.id=="string"){const r=Array.isArray(t.parts)?t.parts:void 0;return{...n,...r?{parts:r}:{}}}return t}async function uA(e,t,n){const r=new URLSearchParams;n!=null&&n.limit&&r.set("limit",String(n.limit)),n!=null&&n.before&&r.set("before",n.before);const a=r.toString(),i=`${nt(e)}/sessions/${encodeURIComponent(t)}/messages${a?`?${a}`:""}`,o=await Te(i);if(Array.isArray(o)){const f=o.map(lA);return{messages:f,total:f.length,hasMore:!1}}const u=o,d=Array.isArray(u.messages)?u.messages:[];return{messages:d.map(lA),total:u.total??d.length,hasMore:u.hasMore??!1}}async function T$(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/status`)}async function A$(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`)}async function C$(e,t){return Te(`${nt(e)}/sessions/snapshot/${encodeURIComponent(t)}`)}async function eM(e){return Te(`${nt(e)}/sessions/all-links`)}async function k$(e,t,n,r){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`,{method:"POST",body:JSON.stringify({type:n,targetId:r})})}async function O$(e,t,n,r){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`,{method:"DELETE",body:JSON.stringify({type:n,targetId:r})})}async function tM(){return Ia(await Te("/api/custom-agents"))}async function I$(e){return Te("/api/custom-agents",{method:"POST",body:JSON.stringify(e)})}async function R$(e,t){return Te(`/api/custom-agents/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify(t)})}async function nM(e){await Te(`/api/custom-agents/${encodeURIComponent(e)}`,{method:"DELETE"})}async function cA(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/export`)}async function M$(e){return Te("/api/custom-agents/import",{method:"POST",body:JSON.stringify(e)})}async function D$(e){await Te("/api/custom-agents/reorder",{method:"PATCH",body:JSON.stringify({items:e})})}async function j$(e,t){await Te(`${nt(e)}/custom-agents/reorder`,{method:"PATCH",body:JSON.stringify({items:t})})}async function rM(e,t){const n=new URLSearchParams;t!=null&&t.category&&n.set("category",t.category),t!=null&&t.includeSuperseded&&n.set("includeSuperseded","true");const r=n.toString();return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories${r?`?${r}`:""}`)}async function L$(e,t,n){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify(n)})}async function P$(e,t){await Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/${encodeURIComponent(t)}`,{method:"DELETE"})}async function B$(e,t){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/extract`,{method:"POST",body:JSON.stringify({sessionIds:t})})}async function dA(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/stats`)}async function U$(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/consolidate`,{method:"POST"})}async function BE(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/sessions`)}async function aM(e){return Ia(await Te(`${nt(e)}/custom-agents`))}async function F$(e,t){return Te(`${nt(e)}/custom-agents`,{method:"POST",body:JSON.stringify(t)})}async function kc(e){return Ia(await Te(`${nt(e)}/models`))}async function iM(){return Ia(await Te("/api/prompt-fragments"))}async function z$(e){return Te("/api/prompt-fragments",{method:"POST",body:JSON.stringify(e)})}async function H$(e,t){return Te(`/api/prompt-fragments/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify(t)})}async function $$(e){await Te(`/api/prompt-fragments/${encodeURIComponent(e)}`,{method:"DELETE"})}async function fA(e){return Ia(await Te(`${nt(e)}/tags`))}async function hA(e,t){return Ia(await Te(`${nt(e)}/milestones`))}async function mA(e,t="open",n){const r=new URLSearchParams({state:t});return(n==null?void 0:n.limit)!=null&&r.set("limit",String(n.limit)),(n==null?void 0:n.offset)!=null&&r.set("offset",String(n.offset)),JR(await Te(`${nt(e)}/issues?${r}`),"issues")}async function Y$(e,t="all"){return Te(`${nt(e)}/issues/sync`,{method:"POST",body:JSON.stringify({state:t})})}async function q$(e,t,n){return Te(`${nt(e)}/issues`,{method:"POST",body:JSON.stringify({title:t,body:n})})}async function G$(e,t,n){await Te(`${nt(e)}/issues/${t}/children`,{method:"POST",body:JSON.stringify({childNumber:n})})}async function sM(e,t,n){return Te(`${nt(e)}/issues/${t}`,{method:"PATCH",body:JSON.stringify(n)})}async function K$(e,t){return Ia(await Te(`${nt(e)}/issues/${t}/pulls`))}async function pA(e,t="open"){return Ia(await Te(`${nt(e)}/pulls?state=${encodeURIComponent(t)}`))}async function V$(e,t="all"){return Te(`${nt(e)}/pulls/sync`,{method:"POST",body:JSON.stringify({state:t})})}async function W$(e,t){return Te(`${nt(e)}/pulls/${t}`)}async function X$(e,t){await Te(`${nt(e)}/pulls/${t}/merge`,{method:"POST"})}async function UE(e,t){return Ia(await Te(`${nt(e)}/pulls/${t}/issues`))}async function Q$(e,t,n){await Te(`${nt(e)}/pulls/${t}/issues`,{method:"POST",body:JSON.stringify({issueNumber:n})})}async function Z$(e,t,n){await Te(`${nt(e)}/pulls/${t}/issues/${n}`,{method:"DELETE"})}async function J$(e,t){return Te(`${nt(e)}/pulls/${t}/comments`)}async function eY(e,t){return Te(`${nt(e)}/issues/${t}/comments`)}async function gA(e,t,n){return Te(`${nt(e)}/issues/${t}/comments`,{method:"POST",body:JSON.stringify({body:n})})}async function tY(e,t,n){return Te(`${nt(e)}/issues/${t}/polish`,{method:"POST",body:JSON.stringify({draft:n})})}async function bA(e,t){return Te(`${nt(e)}/issues/${t}/draft`)}async function nY(e,t,n){return Te(`${nt(e)}/issues/polish-create`,{method:"POST",body:JSON.stringify({title:t,body:n})})}async function xA(e){return Te(`${nt(e)}/issues/draft-create`)}async function rY(e){await Te(`${nt(e)}/issues/draft-create`,{method:"DELETE"})}async function aY(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({title:n})})}async function iY(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({completedAt:n})})}async function sY(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({pinnedAt:n})})}async function oY(){return Te("/api/agents-md")}async function lY(e){await Te("/api/agents-md",{method:"PUT",body:JSON.stringify({content:e})})}async function uY(e){return Te(`/api/repos/${encodeURIComponent(e)}/agents-md`)}async function cY(e,t){await Te(`/api/repos/${encodeURIComponent(e)}/agents-md`,{method:"PUT",body:JSON.stringify({content:t})})}function dY(e){return`${PE()}${nt(e)}/events`}async function fY(e){return Te(`${nt(e)}/sessions/status`)}async function Ml(){return Te("/api/settings")}async function qp(e,t){await Te(`/api/settings/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify({value:t})})}async function Xv(){return Te("/api/cloud/status")}async function hY(){return Te("/api/cloud/reload",{method:"POST"})}async function mY(e){try{return(await Te("/api/cloud/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:e})})).connected}catch{return!1}}async function FE(){return Ia(await Te("/api/git-hosts"),"gitHosts")}async function pY(e,t,n,r="gitea"){return Te("/api/git-hosts",{method:"POST",body:JSON.stringify({host:e,name:t,token:n,platform:r})})}async function gY(e){await Te(`/api/git-hosts/${encodeURIComponent(e)}`,{method:"DELETE"})}async function oM(){return Te("/api/usage")}async function lM(e){return Te("/api/usage/switch",{method:"POST",body:JSON.stringify({accountId:e})})}async function bY(){return Te("/api/usage/authorize",{method:"POST"})}async function xY(e,t){return Te("/api/usage/exchange",{method:"POST",body:JSON.stringify({pendingId:e,code:t})})}async function yY(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/files`)}function vY(e,t,n){return`${PE()}${nt(e)}/sessions/${encodeURIComponent(t)}/files/${n}`}async function wy(e,t,n,r){const a=new URLSearchParams({from:String(e),to:String(t),groupBy:n});return Te(`/api/analytics/summary?${a}`)}const Qv=50,yA=20,EY=200,vA=1e3,_y=2e3,EA=500,NY=5,SY=500,wY=5*1024*1024,NA=10,uM=4e3,_Y=300,TY=2e3,AY=2e3,CY=300,kY=300,OY=500,IY=2e3,RY=30*6e4,SA=[{bg:"bg-blue-500/15",text:"text-blue-500"},{bg:"bg-purple-500/15",text:"text-purple-500"},{bg:"bg-emerald-500/15",text:"text-emerald-500"},{bg:"bg-amber-500/15",text:"text-amber-500"},{bg:"bg-rose-500/15",text:"text-rose-500"},{bg:"bg-cyan-500/15",text:"text-cyan-500"},{bg:"bg-indigo-500/15",text:"text-indigo-500"},{bg:"bg-orange-500/15",text:"text-orange-500"}];function zE(e){const t=e.trim(),n=t.charCodeAt(0)||0;return{...SA[n%SA.length],initial:(t.charAt(0)||"?").toUpperCase()}}const wA=e=>{let t;const n=new Set,r=(f,m)=>{const p=typeof f=="function"?f(t):f;if(!Object.is(p,t)){const b=t;t=m??(typeof p!="object"||p===null)?p:Object.assign({},t,p),n.forEach(x=>x(t,b))}},a=()=>t,u={setState:r,getState:a,getInitialState:()=>d,subscribe:f=>(n.add(f),()=>n.delete(f))},d=t=e(r,a,u);return u},MY=(e=>e?wA(e):wA),DY=e=>e;function jY(e,t=DY){const n=Vn.useSyncExternalStore(e.subscribe,Vn.useCallback(()=>t(e.getState()),[e,t]),Vn.useCallback(()=>t(e.getInitialState()),[e,t]));return Vn.useDebugValue(n),n}const _A=e=>{const t=MY(e),n=r=>jY(t,r);return Object.assign(n,t),n},$i=(e=>e?_A(e):_A),TA="fs-nav-collapsed",AA="fs-session-panel-collapsed",ys=$i(e=>({navCollapsed:localStorage.getItem(TA)==="true",sessionPanelCollapsed:localStorage.getItem(AA)==="true",guideTourOpen:!1,guideTourSection:null,startGuideTour(t){e({guideTourOpen:!0,guideTourSection:t??null})},stopGuideTour(){e({guideTourOpen:!1,guideTourSection:null})},toggleNav(){e(t=>{const n=!t.navCollapsed;return localStorage.setItem(TA,String(n)),{navCollapsed:n}})},toggleSessionPanel(){e(t=>{const n=!t.sessionPanelCollapsed;return localStorage.setItem(AA,String(n)),{sessionPanelCollapsed:n}})}})),go="fs-active-repo",We=$i((e,t)=>({repos:[],activeRepoId:localStorage.getItem(go),loading:!0,loadError:null,loadRepos:async()=>{e({loading:!0,loadError:null});try{const n=await r$(),r=t().activeRepoId,a=r&&n.some(o=>o.id===r);e({repos:n,loading:!1,activeRepoId:a?r:n.length>0?n[0].id:null});const i=t().activeRepoId;i?localStorage.setItem(go,i):localStorage.removeItem(go)}catch(n){e({loading:!1,loadError:n instanceof Error?n.message:"Failed to load repos"})}},setActiveRepo:n=>{e({activeRepoId:n}),n?localStorage.setItem(go,n):localStorage.removeItem(go)},addRepo:async(n,r,a,i)=>{try{const o=await a$(n,r,a,i);return e(u=>({repos:[...u.repos,o],activeRepoId:o.id})),localStorage.setItem(go,o.id),o}catch(o){return e({loadError:o instanceof Error?o.message:"Failed to add repo"}),null}},removeRepo:async n=>{try{await l$(n)}catch{}e(r=>{const a=r.repos.filter(o=>o.id!==n),i=r.activeRepoId===n?a.length>0?a[0].id:null:r.activeRepoId;return i?localStorage.setItem(go,i):localStorage.removeItem(go),{repos:a,activeRepoId:i}})},updateRepoBranch:(n,r)=>{e(a=>({repos:a.repos.map(i=>i.id===n?{...i,branch:r}:i)}))}})),qr=e=>{var t;return((t=e.repos.find(n=>n.id===e.activeRepoId))==null?void 0:t.name)??null},Ty="fs-theme";function cM(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function CA(e){return e==="system"?cM():e}function kA(e){e==="system"?document.documentElement.removeAttribute("data-theme"):document.documentElement.setAttribute("data-theme",e)}const Zv=$i((e,t)=>({preference:localStorage.getItem(Ty)??"system",resolved:CA(localStorage.getItem(Ty)??"system"),cycle(){const n=["system","light","dark"],r=n[(n.indexOf(t().preference)+1)%n.length],a=CA(r);localStorage.setItem(Ty,r),kA(r),e({preference:r,resolved:a})},init(){kA(t().preference);const n=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>{const{preference:a}=t();if(a==="system"){const i=cM();e({resolved:i})}};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)}}));let dM=()=>{},fM=()=>{};function LY(e,t){dM=e,fM=t}function gl(e,t="info",n,r){dM(e,t,n,r)}function PY(e){fM(e)}let Ay=0;const ia=$i(e=>({agents:[],loaded:!1,loadAgents:async t=>{const n=++Ay;try{const r=t?await aM(t):await tM();if(Ay!==n)return;e({agents:r,loaded:!0})}catch(r){if(Ay!==n)return;e({loaded:!0});let a="加载 Agent 列表失败";if(r instanceof Li)try{const i=JSON.parse(r.message);i.error&&(a=i.error)}catch{r.message&&(a=r.message)}gl(a,"error")}}}));let rl=0;const Je=$i((e,t)=>({issues:[],issueTotal:0,tags:[],tagFilterMode:new Map,milestones:[],selectedMilestoneId:null,loaded:!1,syncing:!1,syncError:null,selectedIssueId:null,viewingIssueId:null,viewingTreeRootId:null,matchingParentId:null,matchingCandidateId:null,clearIssues:()=>{++rl,e({issues:[],issueTotal:0,tags:[],tagFilterMode:new Map,milestones:[],selectedMilestoneId:null,loaded:!1,syncError:null,selectedIssueId:null,viewingIssueId:null,viewingTreeRootId:null,matchingParentId:null,matchingCandidateId:null})},setSelectedIssue:n=>e({selectedIssueId:n}),setViewingIssue:(n,r)=>e({viewingIssueId:n,viewingTreeRootId:r??null}),enterMatchMode:n=>e({matchingParentId:n,matchingCandidateId:null}),exitMatchMode:()=>{e({matchingParentId:null,matchingCandidateId:null})},linkChild:async(n,r,a)=>{var i;try{await G$(n,r,a);const o=(i=t().issues.find(u=>u.number===r))==null?void 0:i.id;return o&&e(u=>({issues:u.issues.map(d=>d.number===a?{...d,parentId:o}:d),matchingCandidateId:null})),!0}catch{return!1}},updateIssueState:async(n,r,a)=>{try{const i=await sM(n,r,{state:a});return e(o=>({issues:o.issues.map(u=>u.number===r?{...u,state:i.state}:u)})),!0}catch{return!1}},loadIssues:async n=>{const r=++rl;try{const a=await mA(n,"all",{limit:vA});if(rl!==r)return;e({issues:a.items,issueTotal:a.total,loaded:!0})}catch{if(rl!==r)return;e({loaded:!0})}},syncIssues:async n=>{const r=++rl;e({syncing:!0,syncError:null});try{await Y$(n,"open");const[a,i,o]=await Promise.all([mA(n,"all",{limit:vA}),fA(n),hA(n)]);if(rl!==r)return;e({issues:a.items,issueTotal:a.total,tags:i,milestones:o,syncing:!1})}catch(a){if(rl!==r)return;let i="同步 Issue 失败";if(a instanceof Li)try{const o=JSON.parse(a.message);o.error&&(i=o.error)}catch{a.message&&(i=a.message)}e({syncing:!1,syncError:i})}},createIssue:async(n,r,a)=>{try{const i=await q$(n,r,a);return e(o=>({issues:[i,...o.issues]})),i}catch{return null}},loadTags:async n=>{try{const r=await fA(n);e({tags:r})}catch{}},cycleTagFilter:n=>{e(r=>{const a=new Map(r.tagFilterMode),i=a.get(n);return i?i==="include"?a.set(n,"exclude"):a.delete(n):a.set(n,"include"),{tagFilterMode:a}})},clearTagFilter:()=>e({tagFilterMode:new Map}),loadMilestones:async n=>{try{const r=await hA(n);e({milestones:r})}catch{}},setMilestoneFilter:n=>e({selectedMilestoneId:n})}));let al=0;const mn=$i((e,t)=>({pulls:[],loaded:!1,syncing:!1,syncError:null,selectedPrId:null,viewingPrId:null,matchingPrId:null,matchingCandidateIssueId:null,clearPulls:()=>{++al,e({pulls:[],loaded:!1,syncError:null,selectedPrId:null,viewingPrId:null,matchingPrId:null,matchingCandidateIssueId:null})},setViewingPr:n=>e({viewingPrId:n}),enterMatchMode:n=>e({matchingPrId:n,matchingCandidateIssueId:null}),exitMatchMode:()=>{const n=t().matchingPrId;e({matchingPrId:null,matchingCandidateIssueId:null,selectedPrId:n})},linkIssue:async(n,r,a)=>{try{return await Q$(n,r,a),!0}catch{return!1}},unlinkIssue:async(n,r,a)=>{try{return await Z$(n,r,a),!0}catch{return!1}},loadPulls:async n=>{const r=++al;try{const a=await pA(n,"all");if(al!==r)return;e({pulls:a,loaded:!0})}catch{if(al!==r)return;e({loaded:!0})}},syncPulls:async n=>{const r=++al;e({syncing:!0,syncError:null});try{await V$(n,"open");const a=await pA(n,"all");if(al!==r)return;e({pulls:a,syncing:!1})}catch(a){if(al!==r)return;let i="同步 PR 失败";if(a instanceof Li)try{const o=JSON.parse(a.message);o.error&&(i=o.error)}catch{a.message&&(i=a.message)}e({syncing:!1,syncError:i})}}})),BY=new Set(["tool","tool-use","tool_use","tool-call","tool_call","tool-result","tool_result"]),UY=new Set(["thinking","reasoning","reason"]),FY=new Set(["text","output_text","message"]),zY=new Set(["file","image"]);function Gp(e){var n;const t=((n=e.type)==null?void 0:n.toLowerCase())??"";return BY.has(t)||e.toolName!=null||e.tool!=null?"tool":zY.has(t)?"file":UY.has(t)?"thinking":FY.has(t)||e.content!=null||e.text!=null?"text":"other"}function Jv(e){return e.content??e.text??""}function hM(e){return e.toolName??e.tool??"tool"}function i0(e){var t;return e.input??((t=e.state)==null?void 0:t.input)}function HE(e){var t;return e.output??((t=e.state)==null?void 0:t.output)}function $E(e){var n,r,a;const t=(r=(n=e.state)==null?void 0:n.status)==null?void 0:r.toLowerCase();return t==="completed"||t==="done"||t==="success"?"completed":t==="error"||t==="failed"||((a=e.state)==null?void 0:a.error)!=null?"error":t==="pending"||t==="queued"?"pending":t==="running"||t==="in_progress"?"running":HE(e)!=null?"completed":"running"}function OA(e){if(e==null)return"";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Dl(e){const t=e==null?void 0:e.toLowerCase();return t==="in_progress"||t==="in-progress"||t==="active"?"in_progress":t==="completed"||t==="done"||t==="complete"?"completed":t==="cancelled"||t==="canceled"?"cancelled":"pending"}function mM(e){return e.filter(t=>Dl(t.status)==="completed").length}function Mf(e){const t=hM(e).toLowerCase();return t==="question"||t==="mcp_question"}function HY(e){const t=i0(e);if(!t||typeof t!="object")return null;const n=t;return Array.isArray(n.questions)?n.questions:null}function Kp(e){if(!Mf(e))return!1;const t=$E(e);return t==="pending"||t==="running"}const $Y=/\bses_[a-zA-Z0-9]+/;function YY(e){var a;const t=i0(e);if(t&&typeof t=="object"){const i=t;if(typeof i.task_id=="string"&&i.task_id.startsWith("ses_"))return i.task_id}const n=(a=e.state)==null?void 0:a.metadata;if(n){const i=n.session_id??n.sessionId;if(typeof i=="string"&&i.startsWith("ses_"))return i}const r=HE(e);if(typeof r=="string"){const i=$Y.exec(r);if(i)return i[0]}if(r&&typeof r=="object"){const i=r,o=i.session_id??i.sessionId??i.task_id;if(typeof o=="string"&&o.startsWith("ses_"))return o}return null}let Zm=0;function pM(e){return`question-${e}`}function Cy(e,t){const n=t.find(a=>a.id===e),r=(n==null?void 0:n.title)||e.slice(-8);gl(`${r} — 等待回复`,"warning",e,{id:pM(e),persistent:!0})}function qY(e){var t;for(const n of e)if((t=n.parts)!=null&&t.some(r=>Mf(r)&&Kp(r)))return!0;return!1}const Df=[],jf=[],IA=[],Pu={},ky=new Set;function RA(e){return e.id??e.callID}async function MA(e,t,n){try{const[r,a]=await Promise.all([A$(e,t),eM(e).catch(()=>null)]);n(i=>{const o={sessionLinks:{...i.sessionLinks,[t]:r}};return a&&(o.allSessionLinks=a),o})}catch{}}const Me=$i((e,t)=>({sessions:[],activeSessionId:null,messages:{},messagesMeta:{},todos:{},sessionStatuses:{},errorReasons:{},queuedMessageIds:{},sessionLinks:{},allSessionLinks:{},sessionModels:{},sessionVariants:{},sessionFilter:"active",sessionSearch:"",loadingSessions:!1,loadError:null,sendError:null,setSessionModel:(n,r)=>e(a=>({sessionModels:{...a.sessionModels,[n]:r}})),setSessionVariant:(n,r)=>e(a=>({sessionVariants:{...a.sessionVariants,[n]:r}})),setSessionFilter:n=>e({sessionFilter:n}),setSessionSearch:n=>e({sessionSearch:n}),toggleSessionPin:async(n,r)=>{const a=t().sessions.find(o=>o.id===r);if(!a)return;const i=a.pinnedAt?null:Date.now();e(o=>({sessions:o.sessions.map(u=>u.id===r?{...u,pinnedAt:i??void 0}:u)}));try{await sY(n,r,i)}catch{await t().loadSessions(n)}},toggleSessionComplete:async(n,r)=>{const a=t().sessions.find(o=>o.id===r);if(!a)return;const i=a.completedAt?null:Date.now();e(o=>({sessions:o.sessions.map(u=>u.id===r?{...u,completedAt:i??void 0}:u)}));try{await iY(n,r,i)}catch{await t().loadSessions(n)}},loadSessions:async n=>{const r=++Zm;e({loadingSessions:!0,loadError:null});try{const[a,i]=await Promise.all([y$(n,{limit:EY}),eM(n).catch(()=>null)]);if(Zm!==r)return;const o={sessions:a.items,loadingSessions:!1};i&&(o.allSessionLinks=i),e(o)}catch(a){if(Zm!==r)return;e({loadingSessions:!1,loadError:a instanceof Error?a.message:"Failed to load sessions"})}},createSession:async(n,r,a,i,o,u,d,f)=>{e({sendError:null});try{const m=await v$(n,r,a,i,o,u,d,f);return e(p=>({sessions:[m,...p.sessions.filter(b=>b.id!==m.id)],activeSessionId:m.id,messages:{...p.messages,[m.id]:[]}})),t().setSessionStatus(m.id,"busy"),u&&gl("已自动分配为处理人","success"),m}catch(m){return e({sendError:m instanceof Error?m.message:"Failed to create session"}),null}},setActiveSession:async(n,r)=>{e({activeSessionId:r,sendError:null}),await t().refreshSessionData(n,r)},refreshSessionData:async(n,r)=>{var m,p;const i=!t().messages[r]||t().messages[r].length===0?{limit:yA}:void 0,[o,u]=await Promise.allSettled([C$(n,r),uA(n,r,i)]),d=o.status==="fulfilled"?o.value:null,f=(p=(m=d==null?void 0:d.session)==null?void 0:m.revert)==null?void 0:p.messageID;e(b=>{const x={};if(d&&(d.status&&(x.sessionStatuses={...b.sessionStatuses,[r]:d.status.type}),d.todos&&(x.todos={...b.todos,[r]:d.todos}),d.links&&(x.sessionLinks={...b.sessionLinks,[r]:d.links}),d.session&&(x.sessions=b.sessions.map(E=>E.id===r?{...E,...d.session}:E))),u.status==="fulfilled"){let E=u.value.messages;if(f){const _=E.findIndex(S=>S.id===f);_>=0&&(E=E.slice(0,_+1))}const N=b.messages[r]??[];E.length>=N.length&&(x.messages={...b.messages,[r]:E}),x.messagesMeta={...b.messagesMeta,[r]:{total:Math.max(u.value.total,N.length),hasMore:u.value.hasMore,loading:!1}}}return x}),u.status==="fulfilled"&&qY(u.value.messages)&&Cy(r,t().sessions)},loadMoreMessages:async(n,r)=>{var u;const a=t().messagesMeta[r];if(!(a!=null&&a.hasMore)||a.loading)return;const o=(u=(t().messages[r]??[])[0])==null?void 0:u.id;e(d=>({messagesMeta:{...d.messagesMeta,[r]:{...a,loading:!0}}}));try{const d=await uA(n,r,{limit:yA,before:o});e(f=>{const m=f.messages[r]??[];return{messages:{...f.messages,[r]:[...d.messages,...m]},messagesMeta:{...f.messagesMeta,[r]:{total:d.total,hasMore:d.hasMore,loading:!1}}}})}catch{e(d=>({messagesMeta:{...d.messagesMeta,[r]:{...a,loading:!1}}}))}},addLink:async(n,r,a,i)=>{try{return await k$(n,r,a,i),await MA(n,r,e),!0}catch{return!1}},removeLink:async(n,r,a,i)=>{try{return await O$(n,r,a,i),await MA(n,r,e),!0}catch{return!1}},sendMessage:async(n,r,a,i,o)=>{const u=t().activeSessionId;if(!u)return!1;const d=t().sessions.find(m=>m.id===u),f=t().sessionStatuses[u]==="busy";e({sendError:null}),d!=null&&d.completedAt&&e(m=>({sessions:m.sessions.map(p=>p.id===u?{...p,completedAt:void 0}:p)})),f||t().setSessionStatus(u,"busy");try{return await E$(n,u,r,d==null?void 0:d.agent,a,i,o),f&&(Pu[u]=(Pu[u]||0)+1),!0}catch(m){return e({sendError:m instanceof Error?m.message:"Failed to send message"}),f||t().setSessionStatus(u,"idle"),!1}},replyQuestion:async(n,r)=>{const a=t().activeSessionId;if(a)try{await S$(n,a,r)}catch(i){e({sendError:i instanceof Error?i.message:"Failed to reply to question"})}},rejectQuestion:async n=>{const r=t().activeSessionId;if(r)try{await w$(n,r)}catch{}},abortSession:async n=>{const r=t().activeSessionId;if(r){try{await N$(n,r)}catch{}t().setSessionStatus(r,"idle")}},clearSessions:()=>{++Zm;for(const n of Object.keys(Pu))delete Pu[n];e({sessions:[],activeSessionId:null,messages:{},messagesMeta:{},todos:{},sessionStatuses:{},errorReasons:{},queuedMessageIds:{},sessionLinks:{},allSessionLinks:{},sessionModels:{},sessionVariants:{},sessionSearch:"",loadError:null,sendError:null})},updateMessage:(n,r)=>{var a;e(i=>{const o=i.messages[n]??[],u=o.findIndex(p=>p.id===r.id);let d,f=i.queuedMessageIds,m=i.messagesMeta;if(u>=0){const p={...o[u],...r};(!r.parts||r.parts.length===0)&&o[u].parts&&(p.parts=o[u].parts),d=[...o],d[u]=p}else{d=[...o,r];const p=m[n];p&&(m={...m,[n]:{...p,total:p.total+1}});const b=Pu[n]||0;if(r.role==="user"&&b>0){const x=[...f[n]??[]];x.push(r.id),f={...f,[n]:x},Pu[n]=b-1}else if(r.role==="assistant"){const x=f[n];x&&x.length>0&&(f={...f,[n]:x.slice(1)})}}return{messages:{...i.messages,[n]:d},messagesMeta:m,queuedMessageIds:f}}),(a=r.parts)!=null&&a.some(i=>Mf(i)&&Kp(i))&&Cy(n,t().sessions)},updateMessagePart:(n,r,a)=>{e(i=>{const o=i.messages[n]??[],u=o.findIndex(E=>E.id===r),d=u>=0?o[u]:{id:r,role:"assistant"},f=d.parts?[...d.parts]:[],m=RA(a),p=m!=null?f.findIndex(E=>RA(E)===m):-1;p>=0?f[p]={...f[p],...a}:f.push(a);const b={...d,parts:f},x=u>=0?[...o]:[...o,b];return u>=0&&(x[u]=b),{messages:{...i.messages,[n]:x}}}),Mf(a)&&Kp(a)&&Cy(n,t().sessions)},appendMessagePartDelta:(n,r,a,i)=>{e(o=>{const u=o.messages[n]??[],d=u.findIndex(E=>E.id===r),f=d>=0?u[d]:{id:r,role:"assistant"},m=f.parts?[...f.parts]:[],p=m.findIndex(E=>E.id===a);if(p>=0){const E=m[p],N=(E.content??E.text??"")+i;m[p]=E.content!=null?{...E,content:N}:{...E,text:N}}else m.push({id:a,type:"text",text:i});const b={...f,parts:m},x=d>=0?[...u]:[...u,b];return d>=0&&(x[d]=b),{messages:{...o.messages,[n]:x}}})},updateTodos:(n,r)=>{e(a=>({todos:{...a.todos,[n]:r}}))},updateSessionInfo:n=>{e(r=>r.sessions.some(i=>i.id===n.id)?{sessions:r.sessions.map(i=>{if(i.id!==n.id)return i;const o={...i,...n};return ky.has(n.id)&&i.title&&(o.title=i.title),o})}:{sessions:[n,...r.sessions]})},setSessionStatus:(n,r,a)=>{const i=t().sessionStatuses[n];if(i!==r){const o=t().sessions.find(d=>d.id===n),u=(o==null?void 0:o.title)||n.slice(-8);if(r==="idle"&&i!==void 0&&i!=="idle")PY(pM(n)),gl(`${u} — 完成`,"success",n);else if(r==="busy"&&(i===void 0||i==="idle"))gl(`${u} — 开始运行`,"info",n);else if(r==="retry")gl(`${u} — 进入重试`,"warning",n);else if(r==="error"){const d=a?`${u} — 错误: ${a}`:`${u} — 发生错误`;gl(d,"error",n)}}e(o=>{const u=a?{...o.errorReasons,[n]:a}:r!=="error"?(()=>{const{[n]:d,...f}=o.errorReasons;return f})():o.errorReasons;return{sessionStatuses:{...o.sessionStatuses,[n]:r},errorReasons:u}})},bulkSetStatuses:n=>{e({sessionStatuses:{...t().sessionStatuses,...n}})},renameSession:async(n,r,a)=>{ky.add(r),e(i=>({sessions:i.sessions.map(o=>o.id===r?{...o,title:a}:o)}));try{await aY(n,r,a)}catch{ky.delete(r),await t().loadSessions(n)}},revertToMessage:async(n,r,a)=>{try{return await _$(n,r,a),await t().refreshSessionData(n,r),!0}catch{return!1}}})),wl="__guide__",Bt=Date.now(),Nn=864e5,gM="guide-agent-",tc=`${gM}1`,YE="guide-session-run-1",GY={id:YE,title:"示例对话:添加用户认证",agent:"Sisyphus",createdAt:new Date(Bt-36e5).toISOString(),time:{created:Bt-36e5,updated:Bt-6e5},cost:.12,tokens:{input:4200,output:1800,reasoning:320,cache:{read:800,write:200}}},bM=[{id:"guide-issue-1",repoId:wl,number:42,title:"添加用户认证模块",body:"实现 JWT 认证,包括登录、注册和 token 刷新。",state:"open",labels:[{id:1,name:"feature",color:"0075ca"}],htmlUrl:"#",authorLogin:"demo-user",createdAt:Bt-Nn,updatedAt:Bt-36e5},{id:"guide-issue-2",repoId:wl,number:41,title:"修复登录页样式错位",body:"移动端登录表单在小屏幕下溢出。",state:"closed",labels:[{id:2,name:"bug",color:"d73a4a"}],htmlUrl:"#",authorLogin:"demo-user",createdAt:Bt-2*Nn,updatedAt:Bt-Nn}],xM=[{id:"guide-pr-1",repoId:wl,number:10,title:"feat: add auth module",body:"Implements JWT authentication.",state:"open",headBranch:"feat/auth",baseBranch:"main",labels:[{id:1,name:"feature",color:"0075ca"}],htmlUrl:"#",authorLogin:"demo-user",mergeable:"true",draft:0,commentCount:0,additions:320,deletions:12,changedFilesCount:8,createdAt:Bt-Nn,updatedAt:Bt-36e5,mergedAt:null},{id:"guide-pr-2",repoId:wl,number:9,title:"fix: login page CSS overflow",state:"merged",headBranch:"fix/login-css",baseBranch:"main",draft:0,commentCount:1,additions:15,deletions:3,changedFilesCount:2,createdAt:Bt-2*Nn,updatedAt:Bt-Nn,mergedAt:Bt-Nn}],KY=[{id:"guide-tag-1",repoId:wl,name:"bug",color:"d73a4a",description:null,createdAt:Bt},{id:"guide-tag-2",repoId:wl,name:"feature",color:"0075ca",description:null,createdAt:Bt},{id:"guide-tag-3",repoId:wl,name:"priority",color:"e4e669",description:null,createdAt:Bt}],VY={id:tc,name:"示例 Agent",description:"用于功能引导的演示 Agent",baseAgent:"Sisyphus - ultraworker",model:null,variant:null,systemPrompt:"",systemPromptPosition:0,isSystem:0,memoryModel:null,fragments:[],repoId:null,sortOrder:999,createdAt:Bt-7*Nn,updatedAt:Bt-Nn},WY=[{id:"guide-mem-1",customAgentId:tc,sessionId:"guide-session-1",mergedFrom:null,content:"用户偏好 TypeScript strict 模式,所有新文件必须启用 strictNullChecks",category:"编码规范",importance:.92,supersededBy:null,history:[{content:"用户使用 TypeScript",importance:.5,category:"编码规范",action:"create",ts:Bt-7*Nn},{content:"用户偏好 TypeScript strict 模式",importance:.75,category:"编码规范",action:"update",ts:Bt-3*Nn},{content:"用户偏好 TypeScript strict 模式,所有新文件必须启用 strictNullChecks",importance:.92,category:"编码规范",action:"reinforce",ts:Bt-Nn}],createdAt:Bt-7*Nn,updatedAt:Bt-Nn},{id:"guide-mem-2",customAgentId:tc,sessionId:"guide-session-2",mergedFrom:["guide-mem-old-1","guide-mem-old-2"],content:"项目使用 Tailwind CSS 4 + zustand 状态管理,组件优先使用函数式写法",category:"技术栈",importance:.85,supersededBy:null,history:[{content:"项目使用 Tailwind CSS",importance:.6,category:"技术栈",action:"create",ts:Bt-5*Nn},{content:"项目使用 Tailwind CSS 4 + zustand 状态管理,组件优先使用函数式写法",importance:.85,category:"技术栈",action:"merge",ts:Bt-2*Nn}],createdAt:Bt-5*Nn,updatedAt:Bt-2*Nn},{id:"guide-mem-3",customAgentId:tc,sessionId:"guide-session-1",mergedFrom:null,content:"Git 提交信息使用 conventional commits 格式",category:"工作流",importance:.45,supersededBy:null,history:[{content:"Git 提交信息使用 conventional commits 格式",importance:.7,category:"工作流",action:"create",ts:Bt-10*Nn},{content:"Git 提交信息使用 conventional commits 格式",importance:.45,category:"工作流",action:"decay",ts:Bt-4*Nn}],createdAt:Bt-10*Nn,updatedAt:Bt-4*Nn}];let Qt=null;function XY(e){Qt&&(e!=="dev"&&(Je.setState({issues:Qt.issues,tags:Qt.tags,loaded:Qt.issueLoaded,viewingIssueId:null,viewingTreeRootId:null}),mn.setState({pulls:Qt.pulls,loaded:Qt.prLoaded,viewingPrId:null})),e!=="agent"&&ia.setState({agents:Qt.agents}),e!=="run"&&Me.setState({sessions:Qt.sessions,activeSessionId:Qt.activeSessionId}))}function QY(e){if(!Qt){const t=Je.getState(),n=mn.getState(),r=ia.getState(),a=Me.getState();Qt={issues:t.issues,tags:t.tags,issueLoaded:t.loaded,pulls:n.pulls,prLoaded:n.loaded,agents:r.agents,sessions:a.sessions,activeSessionId:a.activeSessionId}}if(XY(e),e==="run"){const t=Qt.sessions.some(n=>n.id===YE);Me.setState({sessions:t?Qt.sessions:[...Qt.sessions,GY]})}else if(e==="dev")Je.setState({issues:bM,tags:KY,loaded:!0}),mn.setState({pulls:xM,loaded:!0});else if(e==="agent"){const t=Qt.agents.some(n=>n.id===tc);ia.setState({agents:t?Qt.agents:[...Qt.agents,VY]})}}function DA(){Qt&&(Je.setState({issues:Qt.issues,tags:Qt.tags,loaded:Qt.issueLoaded,viewingIssueId:null,viewingTreeRootId:null}),mn.setState({pulls:Qt.pulls,loaded:Qt.prLoaded,viewingPrId:null}),ia.setState({agents:Qt.agents}),Me.setState({sessions:Qt.sessions,activeSessionId:Qt.activeSessionId}),ZY("id"),Qt=null)}function yM(e,t){const n=new URL(window.location.href);n.searchParams.set(e,t),window.history.replaceState(null,"",n.toString()),window.dispatchEvent(new PopStateEvent("popstate"))}function ZY(e){const t=new URL(window.location.href);t.searchParams.has(e)&&(t.searchParams.delete(e),window.history.replaceState(null,"",t.toString()),window.dispatchEvent(new PopStateEvent("popstate")))}function JY(){const e=bM[0].id;Je.setState({viewingIssueId:e}),yM("id",e)}function eq(){const e=xM[0].id;mn.setState({viewingPrId:e}),yM("id",e)}function tq(){Me.setState({activeSessionId:YE})}function nq(){Me.setState({activeSessionId:null})}function rq(){return tc}const e1=[{target:'[data-guide="repo-switcher"]',title:"切换仓库",description:"点击这里可以在已注册的仓库之间快速切换。每个仓库拥有独立的 Agent 运行时和会话。",position:"bottom",section:"repos",padding:4},{target:'[data-guide="manage-repos"]',title:"管理仓库",description:"在仓库下拉菜单底部,点击「管理仓库」可以注册新仓库、启停 Agent 进程、配置运行时类型。",position:"bottom-right",section:"repos",padding:4,triggerClick:'[data-guide="repo-switcher"]'},{target:'[data-guide="repo-overflow-dropdown"]',title:"仓库高级操作",description:"每个仓库卡片的 ⋯ 菜单包含重要功能:切换运行时(OpenCode ↔ Claude Code)、开关 Worktree 任务隔离、编辑 AGENTS.md 配置。",position:"bottom-right",section:"repos",padding:4,route:"/repos",triggerClick:'[data-guide="repo-overflow-btn"]'},{target:'[data-guide="run-new-input"]',title:"新建对话",description:"选择 Agent 后输入指令开始任务。按 Tab 键可快速切换 Agent,底部可选择 Variant(默认 / max / high)控制推理强度。",position:"bottom",section:"run",padding:8,route:"run",mockScope:"run",setupFn:"clearActiveSession"},{target:'[data-guide="run-panel-handle"]',title:"运行记录面板",description:"拖动此手柄可收起/展开左侧运行记录列表。移动端可左右滑动打开。面板内可按「进行中 / 全部」筛选。",position:"bottom",section:"run",padding:6,mockScope:"run",setupFn:"clearActiveSession",mobileSwipeHint:"right"},{target:'[data-guide="run-input-bar"]',title:"快捷短语与追加输入",description:"对话进行中可在此追加指令。上方的快捷短语按钮(如「继续」)支持一键发送,可在设置 → 通用中自定义。底部可切换模型和 Variant。",position:"bottom",section:"run",padding:8,mockScope:"run",setupFn:"selectMockSession"},{target:'[data-guide="run-side-tabs"]',title:"右侧面板",description:"待办:Agent 的任务进度清单。输入:本次对话中你发送的所有消息。关联:Session 关联的 Issue 和 PR。子任务:Agent 派生的子 Session。",position:"bottom-right",section:"run",padding:6,mockScope:"run",setupFn:"selectMockSession",mobileSwipeHint:"left"},{target:'[data-guide="issue-sync-create"]',title:"同步与创建",description:"点击 ↻ 从 Git 平台同步 Issue 和 PR 数据(首次使用必须先同步)。点击 + 可直接创建新 Issue。",position:"bottom",section:"dev",padding:6,route:"dev/issues",mockScope:"dev"},{target:'[data-guide="issue-tag-filter"]',title:"标签筛选(三态)",description:"单击标签 → 包含筛选(高亮);再单击 → 排除筛选(划线);第三次单击 → 取消。支持同时选择多个标签组合筛选。",position:"bottom",section:"dev",padding:4,mockScope:"dev",triggerClick:'[data-guide="issue-tag-filter"]'},{target:'[data-guide="issue-actions"]',title:"Issue 操作",description:"查看源站、关闭/重新打开 Issue、新建 Agent 任务处理此 Issue。右侧面板按钮可展开运行记录侧边栏。",position:"bottom-right",section:"dev",padding:6,mockScope:"dev",setupFn:"selectMockIssue"},{target:'[data-guide="pr-actions"]',title:"PR 操作",description:"查看源站、合入 PR、解决冲突。当 PR 关联了 Issue 时,可选择合入并同时关闭关联的 Issues。",position:"bottom-right",section:"dev",padding:6,route:"dev/pulls",mockScope:"dev",setupFn:"selectMockPr"},{target:'[data-guide="agents-header"]',title:"创建与导入 Agent",description:"点击「创建」基于 base agent + 模型 + 提示词片段组合一个自定义 Agent。点击「导入」可从 JSON 文件恢复其他实例导出的 Agent。",position:"bottom-right",section:"agents",padding:6,route:"agents",mockScope:"agent"},{target:'[data-guide="agents-fragments"]',title:"提示词片段",description:"可复用的提示词模块,可在多个 Agent 间共享。创建 Agent 时选择片段并排序拼接顺序,构建最终的 System Prompt。",position:"bottom",section:"agents",padding:6,mockScope:"agent",triggerClick:'[data-guide="agents-fragments"]'},{target:'[data-guide="agent-detail-actions"]',title:"Agent 导出与共享",description:"下载或复制 Agent 的 JSON 配置,可在不同 Fourth Spark 实例间导入共享。包含提示词片段和所有配置。",position:"bottom-right",section:"agents",padding:4,route:"agents/__MOCK_AGENT__",mockScope:"agent"},{target:'[data-guide="agent-memory-section"]',title:"Agent 记忆",description:"Agent 在每次对话结束后自动提取经验记忆。每条记忆有分类标签和重要度评分(⚡)。系统定期自动整理:合并重复内容、衰减不活跃的记忆、强化反复验证的经验。",position:"bottom",section:"agents",padding:6,mockScope:"agent"},{target:'[data-guide="agent-memory-version"]',title:"记忆版本历史",description:"点击版本标签可查看这条记忆的完整演化轨迹:首次提取 → 内容重写 → 多条合并 → 反复验证后强化 → 长期未用后衰减。每个版本记录了当时的内容、重要度评分和触发动作。",position:"bottom",section:"agents",padding:4,mockScope:"agent"}];function aq(e){return e?e1.filter(t=>t.section===e):e1}function vM(e){if(e==="/repos"||e==="/settings")return"repos";const t=e.replace(/^\/[^/]+\//,"");return t.startsWith("run")?"run":t.startsWith("dev")?"dev":t.startsWith("agents")?"agents":null}const iq=6,jA=12,LA=200,PA=80,BA=288,UA=8,sq=768;function oq(e,t){const n=document.querySelector(e);if(!n)return null;const r=n.getBoundingClientRect();return r.width===0&&r.height===0||r.right<0||r.bottom<0||r.left>window.innerWidth||r.top>window.innerHeight?null:{top:r.top-t,left:r.left-t,width:r.width+t*2,height:r.height+t*2}}function lq(e){const{top:t,left:n,width:r,height:a}=e,i=n+r,o=t+a;return`polygon(
521
521
  0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%,
522
522
  ${n}px ${t}px, ${n}px ${o}px, ${i}px ${o}px, ${i}px ${t}px, ${n}px ${t}px
523
- )`}function uq(e,t){const n={position:"fixed"},r=window.innerWidth,a=window.innerHeight,i=e.top+e.height+jA,o=e.top-jA;let u=t==="bottom-right"?e.left+e.width-BA:e.left;return u=Math.max(UA,Math.min(u,r-BA-UA)),n.left=u,i+160<a?n.top=i:n.bottom=a-o,n}function Oy(e){const t=document.querySelector(e);t&&t.click()}const FA={selectMockIssue:JY,selectMockPr:eq,selectMockSession:tq,clearActiveSession:nq};function cq(){return window.innerWidth<sq}function dq({direction:e}){const t=e==="left"?ih:Oo;return c.jsx("div",{className:"pointer-events-none fixed inset-0 z-[9999] flex items-center justify-center",children:c.jsxs("div",{className:`flex items-center gap-1 rounded-full bg-blue-500/20 px-6 py-4 ${e==="left"?"fs-swipe-left":"fs-swipe-right"}`,children:[c.jsx(t,{className:"h-8 w-8 text-blue-400",strokeWidth:2.5}),c.jsx(t,{className:"h-8 w-8 text-blue-400/60",strokeWidth:2.5}),c.jsx(t,{className:"h-8 w-8 text-blue-400/30",strokeWidth:2.5})]})})}function fq({step:e,stepIdx:t,total:n,isFirst:r,isLast:a,onPrev:i,onNext:o,onClose:u}){return c.jsx("div",{className:"fixed inset-x-0 bottom-24 z-[10000] flex justify-center px-4",children:c.jsxs("div",{className:"w-72 rounded-xl border border-line bg-surface p-4 shadow-2xl",children:[c.jsx("button",{type:"button",onClick:u,className:"absolute right-2 top-2 rounded-md p-1 text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3","aria-label":"关闭引导",children:c.jsx(At,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:e.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:e.description}),c.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[c.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-fg-5",children:[t+1," / ",n]}),c.jsxs("div",{className:"flex items-center gap-2",children:[!r&&c.jsx("button",{type:"button",onClick:i,className:"rounded-md px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"上一步"}),c.jsx("button",{type:"button",onClick:o,className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:a?"完成":"下一步"})]})]})]})})}function hq(){const e=zn(),t=or(),n=ys(L=>L.guideTourOpen),r=ys(L=>L.guideTourSection),a=ys(L=>L.stopGuideTour),i=We(qr),[o,u]=y.useState(0),[d,f]=y.useState(null),m=y.useRef(null),p=y.useRef(-1),b=y.useRef(null),x=y.useMemo(()=>n?aq(r):e1,[n,r]),E=o<x.length?x[o]:void 0,N=x.length,_=o===0,S=o===N-1,C=y.useCallback(()=>{if(!n||!E)return;const L=E.padding??iq;f(oq(E.target,L))},[n,E]),A=y.useCallback(L=>{const B=L.replace("__MOCK_AGENT__",rq());return B.startsWith("/")?B:i?`/${encodeURIComponent(i)}/${B}`:`/${B}`},[i]);y.useEffect(()=>{n&&(u(0),p.current=-1)},[n]),y.useEffect(()=>{if(!n||!E)return;const L=p.current,B=L>=0?x[L]:null;B!=null&&B.triggerClick&&document.querySelector(B.target)&&Oy(B.triggerClick);const Y=(B==null?void 0:B.mockScope)??null,re=E.mockScope??null;re&&re!==Y?(QY(re),b.current=re):!re&&b.current&&(DA(),b.current=null);const X=E.route?A(E.route):null,K=X&&!t.pathname.startsWith(X);K&&e(X);const H=setTimeout(()=>{E.setupFn&&FA[E.setupFn]&&FA[E.setupFn](),setTimeout(()=>{E.triggerClick&&!document.querySelector(E.target)&&Oy(E.triggerClick),setTimeout(C,PA)},E.setupFn?LA:0)},K?LA:re&&re!==Y?PA:0);return p.current=o,()=>clearTimeout(H)},[n,o,E,e,t.pathname,C,A,x]),y.useLayoutEffect(()=>{C()},[C]),y.useEffect(()=>{if(n)return window.addEventListener("resize",C),window.addEventListener("scroll",C,!0),()=>{window.removeEventListener("resize",C),window.removeEventListener("scroll",C,!0)}},[n,C]);const I=y.useRef(o);I.current=o;const O=y.useRef(x);O.current=x;const k=y.useCallback(()=>{const L=O.current[I.current];L!=null&&L.triggerClick&&document.querySelector(L.target)&&Oy(L.triggerClick),b.current&&(DA(),b.current=null),a()},[a]);if(y.useEffect(()=>{if(!n)return;const L=B=>{B.key==="Escape"&&k()};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[n,k]),!n||!E)return null;const j=cq()&&E.mobileSwipeHint&&!d;if(!d&&!j)return null;const F=()=>{_||u(L=>L-1)},P=()=>{S?k():u(L=>L+1)};return j?gs.createPortal(c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"fixed inset-0 z-[9998] bg-black/60",onClick:k}),c.jsx(dq,{direction:E.mobileSwipeHint}),c.jsx(fq,{step:E,stepIdx:o,total:N,isFirst:_,isLast:S,onPrev:F,onNext:P,onClose:k})]}),document.body):gs.createPortal(c.jsxs("div",{className:"fixed inset-0 z-[9999]",children:[c.jsx("div",{className:"absolute inset-0 bg-black/60 transition-[clip-path] duration-200",style:{clipPath:lq(d)},onClick:k}),c.jsx("div",{className:"pointer-events-none absolute rounded-lg ring-2 ring-blue-500 ring-offset-2 ring-offset-transparent transition-all duration-200",style:{top:d==null?void 0:d.top,left:d==null?void 0:d.left,width:d==null?void 0:d.width,height:d==null?void 0:d.height}}),c.jsxs("div",{ref:m,className:"fixed z-[10000] w-72 rounded-xl border border-line bg-surface p-4 shadow-2xl",style:uq(d,E.position),children:[c.jsx("button",{type:"button",onClick:k,className:"absolute right-2 top-2 rounded-md p-1 text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3","aria-label":"关闭引导",children:c.jsx(At,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:E.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:E.description}),c.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[c.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-fg-5",children:[o+1," / ",N]}),c.jsxs("div",{className:"flex items-center gap-2",children:[!_&&c.jsx("button",{type:"button",onClick:F,className:"rounded-md px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"上一步"}),c.jsx("button",{type:"button",onClick:P,className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:S?"完成":"下一步"})]})]})]})]}),document.body)}const EM=[{segment:"run",icon:LE,label:"运行面板",global:!1},{segment:"dev/issues",icon:Ez,label:"研发",global:!1,matchPrefix:"dev"},{segment:"agents",icon:QF,label:"Agents",global:!1}];function NM(e,t,n){return t?`/${e}`:n?`/${encodeURIComponent(n)}/${e}`:`/${e}`}function SM(e,t,n){if(!e.matchPrefix)return!1;const r=e.global?`/${e.matchPrefix}`:n?`/${encodeURIComponent(n)}/${e.matchPrefix}`:null;return r?t===r||t.startsWith(`${r}/`):!1}function mq(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function pq({repos:e,activeRepoId:t,onRepoChange:n}){const r=zn(),[a,i]=y.useState(!1),[o,u]=y.useState(-1),d=y.useRef(null),f=e.find(b=>b.id===t),m=y.useCallback(()=>{i(!1),u(-1)},[]);y.useEffect(()=>{if(!a)return;const b=x=>{d.current&&!d.current.contains(x.target)&&m()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[a,m]);const p=y.useCallback(b=>{if(a)switch(b.key){case"Escape":b.preventDefault(),m();break;case"ArrowDown":b.preventDefault(),u(x=>Math.min(x+1,e.length-1));break;case"ArrowUp":b.preventDefault(),u(x=>Math.max(x-1,0));break;case"Enter":o>=0&&o<e.length&&(b.preventDefault(),n(e[o].id),m());break}},[a,m,o,e,n]);return c.jsxs("div",{ref:d,className:"relative",onKeyDown:p,children:[c.jsxs("button",{type:"button","data-guide":"repo-switcher",onClick:()=>i(b=>!b),"aria-label":"切换仓库","aria-haspopup":"listbox","aria-expanded":a,className:"flex max-w-[140px] items-center gap-1 rounded-md border border-line bg-base px-2 py-1 text-xs text-fg-2 transition-colors hover:border-blue-500 sm:max-w-[200px]",children:[c.jsx(FR,{className:"h-3 w-3 shrink-0 text-fg-4"}),c.jsxs("span",{className:"truncate",children:[c.jsx("span",{className:"sm:hidden",children:f?mq(f.name):""}),c.jsx("span",{className:"hidden sm:inline",children:(f==null?void 0:f.name)??""})]}),c.jsx(kr,{className:ie("h-3 w-3 shrink-0 text-fg-4 transition-transform",a&&"rotate-180")})]}),a&&c.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-64 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[c.jsx("div",{role:"listbox","aria-label":"仓库列表",className:"max-h-64 overflow-y-auto py-1",children:e.map((b,x)=>c.jsxs("button",{type:"button",role:"option","aria-selected":b.id===t,onClick:()=>{n(b.id),m()},className:ie("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",b.id===t?"font-medium text-blue-600":"text-fg-2 hover:bg-elevated",o===x&&"bg-elevated"),children:[b.id===t?c.jsx(fi,{className:"h-3 w-3 shrink-0"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:b.name})]},b.id))}),c.jsx("div",{className:"border-t border-line",children:c.jsxs("button",{type:"button","data-guide":"manage-repos",onClick:()=>{r("/repos"),m()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:[c.jsx(r0,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"管理仓库"})]})})]})]})}function gq({repoId:e,currentBranch:t}){const n=We(S=>S.updateRepoBranch),[r,a]=y.useState(!1),[i,o]=y.useState(null),[u,d]=y.useState(!1),[f,m]=y.useState(null),[p,b]=y.useState(null),x=y.useRef(null),E=y.useCallback(()=>{a(!1),b(null)},[]);y.useEffect(()=>{if(!r)return;const S=C=>{x.current&&!x.current.contains(C.target)&&E()};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[r,E]);const N=async()=>{if(r){E();return}a(!0),d(!0),b(null);try{o(await d$(e))}catch{b("加载分支失败")}finally{d(!1)}},_=async S=>{if(!(S===t||f)){m(S),b(null);try{const C=await f$(e,S);n(e,C.branch),E()}catch(C){b(C instanceof Error?C.message:"切换失败")}finally{m(null)}}};return t?c.jsxs("div",{ref:x,className:"relative",children:[c.jsxs("button",{type:"button",onClick:N,className:"flex items-center gap-1 rounded-md bg-elevated px-2 py-1 text-xs text-fg-3 transition-colors hover:bg-blue-500/10 hover:text-blue-600",children:[c.jsx(Gl,{className:"h-3 w-3"}),t,c.jsx(kr,{className:ie("h-3 w-3 transition-transform",r&&"rotate-180")})]}),r&&c.jsxs("div",{className:"absolute right-0 top-full z-50 mt-1 w-56 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[u?c.jsx("div",{className:"flex items-center justify-center py-4",children:c.jsx(nn,{className:"h-4 w-4 animate-spin text-fg-4"})}):i?c.jsxs("div",{className:"max-h-64 overflow-y-auto py-1",children:[i.local.map(S=>c.jsxs("button",{type:"button",disabled:f!==null,onClick:()=>_(S),className:ie("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",S===t?"font-medium text-blue-600":"text-fg-2 hover:bg-elevated"),children:[S===t?c.jsx(fi,{className:"h-3 w-3 shrink-0"}):f===S?c.jsx(nn,{className:"h-3 w-3 shrink-0 animate-spin"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:S})]},S)),i.remote.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"mx-3 my-1 border-t border-line"}),c.jsx("div",{className:"px-3 py-1 text-[10px] font-medium uppercase tracking-wider text-fg-4",children:"Remote"}),i.remote.map(S=>c.jsxs("button",{type:"button",disabled:f!==null,onClick:()=>_(S),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[f===S?c.jsx(nn,{className:"h-3 w-3 shrink-0 animate-spin"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:S})]},`remote-${S}`))]})]}):null,p&&c.jsx("div",{className:"border-t border-line px-3 py-2 text-xs text-red-500",children:p})]})]}):null}function bq(){const[e,t]=y.useState(null);return y.useEffect(()=>{const n=()=>fetch("/api/health").then(i=>i.json()).then(i=>{i.latestVersion&&i.latestVersion!=="0.11.36"&&t(i.latestVersion)}).catch(()=>{});n();const r=setInterval(n,RY),a=()=>n();return window.addEventListener("focus",a),()=>{clearInterval(r),window.removeEventListener("focus",a)}},[]),e}function xq({navigate:e,cycle:t,themeLabel:n,ThemeIcon:r}){const[a,i]=y.useState(!1),o=y.useRef(null);return y.useEffect(()=>{if(!a)return;const u=d=>{o.current&&!o.current.contains(d.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[a]),c.jsxs("div",{ref:o,className:"relative md:hidden",children:[c.jsx("button",{type:"button",onClick:()=>i(u=>!u),"aria-label":"更多",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(kz,{className:"h-4 w-4"})}),a&&c.jsxs("div",{className:"absolute right-0 top-full z-50 mt-1 w-40 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[c.jsxs("button",{type:"button",onClick:()=>{e("/analytics"),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(ah,{className:"h-3.5 w-3.5 text-fg-4"}),"统计"]}),c.jsxs("button",{type:"button",onClick:()=>{e("/settings"),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(r0,{className:"h-3.5 w-3.5 text-fg-4"}),"设置"]}),c.jsxs("button",{type:"button",onClick:()=>{t(),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(r,{className:"h-3.5 w-3.5 text-fg-4"}),n]}),c.jsxs("a",{href:"https://github.com/kinminghao/fourth-spark",target:"_blank",rel:"noopener noreferrer",onClick:()=>i(!1),className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx("svg",{className:"h-3.5 w-3.5 text-fg-4",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})}),"GitHub"]}),c.jsxs("button",{type:"button",onClick:()=>{ys.getState().startGuideTour(vM(window.location.pathname)),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(zR,{className:"h-3.5 w-3.5 text-fg-4"}),"功能引导"]})]})]})}function yq(){const e=zn(),t=or(),n=We(p=>p.repos),r=We(p=>p.activeRepoId),a=We(p=>p.setActiveRepo),i=Zv(p=>p.preference),o=Zv(p=>p.cycle),u=i==="light"?YH:i==="dark"?SH:EH,d=n.find(p=>p.id===r),f=bq(),m=p=>{var N;if(!p)return;a(p);const b=n.find(_=>_.id===p);if(!b)return;const x=t.pathname.match(/\/dev\/(issues|pulls)/);if(x){e(`/${encodeURIComponent(b.name)}/dev/${x[1]}`);return}const E=((N=t.pathname.match(/\/(run|agents|issues|pulls)/))==null?void 0:N[1])??"run";e(`/${encodeURIComponent(b.name)}/${E}`)};return c.jsxs("header",{className:"shrink-0 border-b border-line bg-surface pt-[var(--safe-top)]",children:[c.jsxs("div",{className:"flex h-12 items-center justify-between px-4",children:[c.jsxs("div",{className:"flex items-center gap-2.5",children:[c.jsx(Cc,{className:"h-5 w-5 text-blue-500"}),c.jsx("span",{className:"hidden text-sm font-bold tracking-tight text-fg sm:inline",children:"Fourth Spark"}),c.jsxs("span",{className:"hidden rounded bg-elevated px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-fg-4 sm:inline",children:["v","0.11.36"]}),f&&c.jsxs("span",{className:"hidden text-[10px] text-amber-500 sm:inline",children:["→ v",f," 可用,运行"," ",c.jsx("code",{className:"rounded bg-amber-500/10 px-1 font-mono",children:"fourth-spark upgrade"})," 更新"]})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[n.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(pq,{repos:n,activeRepoId:r,onRepoChange:m}),d&&r&&c.jsx(gq,{repoId:r,currentBranch:d.branch})]}),c.jsxs("div",{className:"hidden items-center gap-1 md:flex",children:[c.jsx("button",{type:"button",onClick:()=>e("/analytics"),"aria-label":"统计",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(ah,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>e("/settings"),"aria-label":"设置",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(r0,{className:"h-4 w-4"})}),c.jsx("a",{href:"https://github.com/kinminghao/fourth-spark",target:"_blank",rel:"noopener noreferrer","aria-label":"GitHub",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})})}),c.jsx("button",{type:"button",onClick:o,"aria-label":`主题: ${i}`,className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(u,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>ys.getState().startGuideTour(vM(t.pathname)),"aria-label":"功能引导",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(zR,{className:"h-4 w-4"})})]}),c.jsx(xq,{navigate:e,cycle:o,themeLabel:`主题: ${i}`,ThemeIcon:u})]})]}),f&&c.jsx("div",{className:"border-t border-line px-4 py-1.5 sm:hidden",children:c.jsxs("span",{className:"text-[10px] text-amber-500",children:["→ v",f," 可用,运行"," ",c.jsx("code",{className:"rounded bg-amber-500/10 px-1 font-mono",children:"fourth-spark upgrade"})," 更新"]})})]})}function vq(){const e=We(qr),t=ys(a=>a.navCollapsed),n=ys(a=>a.toggleNav),r=or();return c.jsxs("nav",{className:ie("hidden shrink-0 flex-col border-r border-line bg-surface py-2 transition-[width] duration-200 ease-in-out md:flex",t?"w-14":"w-48"),children:[c.jsx("div",{className:"flex flex-1 flex-col",children:EM.map(a=>{const i=SM(a,r.pathname,e);return c.jsxs(Hp,{to:NM(a.segment,a.global,e),title:t?a.label:void 0,className:({isActive:o})=>ie("mx-2 flex items-center rounded-md py-2 text-sm transition-colors",t?"justify-center px-2":"gap-2.5 px-3",o||i?"bg-blue-500/10 font-medium text-blue-600":"text-fg-3 hover:bg-elevated hover:text-fg"),children:[c.jsx(a.icon,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:ie("truncate transition-[opacity,max-width] duration-200 ease-in-out",t?"max-w-0 opacity-0":"max-w-[8rem] opacity-100"),children:a.label})]},a.segment)})}),c.jsxs(Hp,{to:"/settings",title:t?"设置":void 0,className:({isActive:a})=>ie("mx-2 flex items-center rounded-md py-2 text-sm transition-colors",t?"justify-center px-2":"gap-2.5 px-3",a?"bg-blue-500/10 font-medium text-blue-600":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:[c.jsx(r0,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:ie("truncate transition-[opacity,max-width] duration-200 ease-in-out",t?"max-w-0 opacity-0":"max-w-[8rem] opacity-100"),children:"设置"})]}),c.jsx("button",{type:"button",onClick:n,title:t?"展开导航":"收起导航",className:"mx-2 flex items-center justify-center rounded-md py-2 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:t?c.jsx(uz,{className:"h-4 w-4"}):c.jsx(oz,{className:"h-4 w-4"})})]})}function Eq(){const e=We(qr),t=or();return c.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-30 border-t border-line bg-surface pb-[var(--safe-bottom)] md:hidden",children:c.jsx("div",{className:"flex h-14 items-center justify-around",children:EM.map(n=>{const r=SM(n,t.pathname,e);return c.jsx(Hp,{to:NM(n.segment,n.global,e),"aria-label":n.label,className:({isActive:a})=>ie("flex h-10 w-10 items-center justify-center rounded-md transition-colors",a||r?"bg-blue-500/10 text-blue-600":"text-fg-3 hover:bg-elevated hover:text-fg"),children:c.jsx(n.icon,{className:"h-5 w-5 shrink-0"})},n.segment)})})})}function Nq(){return c.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-base text-fg",children:[c.jsx(yq,{}),c.jsxs("div",{className:"flex min-h-0 flex-1",children:[c.jsx(vq,{}),c.jsx("main",{className:"flex min-w-0 flex-1 flex-col overflow-hidden pb-[calc(3.5rem_+_var(--safe-bottom))] md:pb-0",children:c.jsx(Z7,{})})]}),c.jsx(Eq,{}),c.jsx(hq,{})]})}let Sq=0;const ar=$i(e=>({toasts:[],addToast:(t,n="info",r,a)=>{const i=(a==null?void 0:a.id)??`toast-${++Sq}-${Date.now()}`;e(o=>o.toasts.some(u=>u.id===i)?o:{toasts:[...o.toasts,{id:i,message:t,variant:n,sessionId:r,persistent:a==null?void 0:a.persistent}]}),a!=null&&a.persistent||setTimeout(()=>{e(o=>({toasts:o.toasts.filter(u=>u.id!==i)}))},uM)},removeToast:t=>{e(n=>({toasts:n.toasts.filter(r=>r.id!==t)}))}})),wq={info:{icon:"ℹ",badge:"bg-fg/10 text-fg-2",bar:"bg-fg-4"},success:{icon:"✓",badge:"bg-emerald-500/10 text-emerald-500",bar:"bg-emerald-500"},warning:{icon:"⚠",badge:"bg-amber-500/10 text-amber-500",bar:"bg-amber-500"},error:{icon:"✕",badge:"bg-red-500/10 text-red-500",bar:"bg-red-500"}};function zA(){const e=ar(m=>m.toasts),t=ar(m=>m.removeToast),n=Me(m=>m.setActiveSession),r=We(m=>m.activeRepoId),a=We(qr),i=zn(),o=m=>{t(m.id),m.sessionId&&r&&(n(r,m.sessionId),i(`/${encodeURIComponent(a)}/run`))},[u,d]=y.useState([]),f=y.useRef(new Map);return y.useEffect(()=>{const m=new Set(e.map(p=>p.id));d(p=>{let b=p.map(x=>m.has(x.id)||x.exiting?x:{...x,exiting:!0});for(const x of e)b.some(E=>E.id===x.id)||(b=[...b,{...x}]);return b})},[e]),y.useEffect(()=>{const m=f.current;for(const p of u)p.exiting&&!m.has(p.id)&&m.set(p.id,setTimeout(()=>{m.delete(p.id),d(b=>b.filter(x=>x.id!==p.id))},_Y))},[u]),y.useEffect(()=>{const m=f.current;return()=>m.forEach(clearTimeout)},[]),u.length===0?null:c.jsx("div",{className:"pointer-events-none fixed top-4 right-4 z-50 flex w-[calc(100%-2rem)] max-w-sm flex-col",role:"status","aria-live":"polite","aria-atomic":"false",children:u.map(m=>{const p=wq[m.variant];return c.jsx("div",{className:"grid w-full transition-[grid-template-rows] duration-300 ease-out",style:{gridTemplateRows:m.exiting?"0fr":"1fr"},children:c.jsx("div",{className:"min-h-0 overflow-hidden",children:c.jsxs("div",{role:"status",onClick:()=>o(m),style:{animation:`${m.exiting?"toast-out":"toast-in"} 0.3s ease-out forwards`},className:"pointer-events-auto relative mb-2 flex cursor-pointer items-start gap-3 overflow-hidden rounded-xl border border-line bg-surface/80 px-3.5 py-3 shadow-lg shadow-black/5 backdrop-blur-md transition-colors hover:border-line-hard hover:bg-surface/90",children:[c.jsx("span",{"aria-hidden":!0,className:`mt-px flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-xs font-semibold ${p.badge}`,children:p.icon}),c.jsx("p",{className:"min-w-0 flex-1 text-sm leading-snug break-words text-fg",children:m.message}),m.persistent&&!m.exiting&&c.jsx("button",{type:"button","aria-label":"关闭",onClick:b=>{b.stopPropagation(),t(m.id)},className:"mt-px flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-fg-4 transition-colors hover:bg-fg/10 hover:text-fg",children:"✕"}),!m.exiting&&!m.persistent&&c.jsx("span",{"aria-hidden":!0,className:`absolute bottom-0 left-0 h-0.5 w-full origin-left ${p.bar}`,style:{animation:`toast-progress ${uM}ms linear forwards`}})]})})},m.id)})})}const _q=1e3,Tq=5e3,Jm="freeze-mon-buffer",Aq=4*1024*1024;class Cq{constructor(){pt(this,"ring",[]);pt(this,"counters",{sse:0,delta:0,store:0});pt(this,"workerCount",0);pt(this,"sampleTimer",0);pt(this,"persistTimer",0);pt(this,"running",!1)}tick(t){this.counters[t]++}setGauge(t,n){t==="workers"&&(this.workerCount=n)}exportData(){return localStorage.getItem(Jm)??JSON.stringify(this.ring)}start(){if(this.running)return;this.running=!0;const t=localStorage.getItem(Jm);if(t)try{this.ring=JSON.parse(t)}catch{this.ring=[]}this.sampleTimer=window.setInterval(()=>this.sample(),_q),this.persistTimer=window.setInterval(()=>this.persist(),Tq)}stop(){this.running=!1,clearInterval(this.sampleTimer),clearInterval(this.persistTimer),this.persist()}sample(){const t=Me.getState(),n=Object.values(t.messages).reduce((a,i)=>a+i.length,0),r=performance.memory;this.ring.push({ts:Date.now(),sse:this.counters.sse,delta:this.counters.delta,store:this.counters.store,workers:this.workerCount,msgs:n,heap:r?Math.round(r.usedJSHeapSize/1048576):void 0}),this.counters.sse=0,this.counters.delta=0,this.counters.store=0,this.trimToFit()}trimToFit(){for(;this.ring.length>1&&!(new Blob([JSON.stringify(this.ring)]).size<=Aq);)this.ring.shift()}persist(){try{localStorage.setItem(Jm,JSON.stringify(this.ring))}catch{this.ring.splice(0,Math.floor(this.ring.length/2));try{localStorage.setItem(Jm,JSON.stringify(this.ring))}catch{}}}}const vs=new Cq;function kq(e){if(typeof e!="string")return e;const t=e.trim();if(t)try{return JSON.parse(t)}catch{return t}}function ir(e){return e&&typeof e=="object"?e:null}function Kl(e){const t=ir(e);return t&&"properties"in t?t.properties:e}function Oq(e){const t=ir(e);return typeof(t==null?void 0:t.type)=="string"?t.type:void 0}function Iq(e){const t=ir(Kl(e));if(!t)return null;const n=ir(t.info);if(n&&typeof n.id=="string"){const a=Array.isArray(t.parts)?t.parts:void 0;return{...n,...a?{parts:a}:{}}}if(typeof t.id=="string"&&typeof t.role=="string")return t;const r=ir(t.message);return r&&typeof r.id=="string"?r:null}function Rq(e){const t=ir(Kl(e));if(!t)return{};const n=ir(t.part)??t;return typeof n.type!="string"?{}:{messageId:typeof n.messageID=="string"&&n.messageID||typeof n.messageId=="string"&&n.messageId||typeof t.messageID=="string"&&t.messageID||typeof t.messageId=="string"&&t.messageId||void 0,part:n}}function wM(e){const t=ir(Kl(e));if(!t||t.field!=="text")return null;const n=typeof t.messageID=="string"?t.messageID:null,r=typeof t.partID=="string"?t.partID:null,a=typeof t.delta=="string"?t.delta:null;return!n||!r||a===null?null:{messageId:n,partId:r,delta:a}}function Mq(e){const t=Kl(e);if(Array.isArray(t))return t;const n=ir(t);return n&&Array.isArray(n.todos)?n.todos:[]}function wi(e){return typeof e=="number"?e:0}function Dq(e){const t=ir(Kl(e));if(!t||typeof t.id!="string")return null;const n={id:t.id};typeof t.title=="string"&&(n.title=t.title),typeof t.agent=="string"&&(n.agent=t.agent),typeof t.cost=="number"&&(n.cost=t.cost);const r=typeof t.parentID=="string"?t.parentID:typeof t.parent_id=="string"?t.parent_id:void 0;r&&(n.parentID=r);const a=ir(t.tokens),i=typeof t.tokens_input=="number"||typeof t.tokens_output=="number";if(a||i){const u=a?ir(a.cache):null;n.tokens={input:wi(a==null?void 0:a.input)||wi(t.tokens_input),output:wi(a==null?void 0:a.output)||wi(t.tokens_output),reasoning:wi(a==null?void 0:a.reasoning)||wi(t.tokens_reasoning),cache:{read:wi(u==null?void 0:u.read)||wi(t.tokens_cache_read),write:wi(u==null?void 0:u.write)||wi(t.tokens_cache_write)}}}const o=ir(t.model);return o&&(n.model={providerID:typeof o.providerID=="string"?o.providerID:void 0,modelID:typeof o.modelID=="string"?o.modelID:void 0,variant:typeof o.variant=="string"?o.variant:void 0}),n}function jq(e){const t=ir(Kl(e));if(!t)return null;if(typeof t.message=="string")return t.message;const n=ir(t.error);if(n){const r=ir(n.data);if(typeof(r==null?void 0:r.message)=="string")return`${n.name??"Error"}: ${r.message}`;if(typeof n.message=="string")return`${n.name??"Error"}: ${n.message}`;if(typeof n.name=="string")return String(n.name)}return typeof t.reason=="string"?t.reason:null}function Lq(e){const t=Kl(e);if(typeof t=="string")return t;const n=ir(t);if(typeof(n==null?void 0:n.status)=="string")return n.status;const r=ir(n==null?void 0:n.status);return typeof(r==null?void 0:r.type)=="string"?r.type:typeof(n==null?void 0:n.type)=="string"?n.type:null}function HA(e,t,n,r){switch(e==="message"||e===""?Oq(t)??e:e){case"message.updated":{const i=Iq(t);i&&r.updateMessage(n,i);break}case"session.updated":{const i=Dq(t);i&&r.updateSessionInfo(i);break}case"message.part.updated":{const{messageId:i,part:o}=Rq(t);o&&i&&r.updateMessagePart(n,i,o);break}case"message.part.delta":{const i=wM(t);i&&r.appendMessagePartDelta(n,i.messageId,i.partId,i.delta);break}case"todo.updated":{r.updateTodos(n,Mq(t));break}case"session.status":{const i=Lq(t);i&&r.setSessionStatus(n,i);break}case"session.idle":{r.setSessionStatus(n,"idle");break}case"session.error":{const i=jq(t);r.setSessionStatus(n,"error",i??void 0);break}}}const Pq=1e3,Bq=3e4;class Uq{constructor(t,n){pt(this,"source",null);pt(this,"reconnectTimer",null);pt(this,"attempts",0);pt(this,"disposed",!1);pt(this,"repoId");pt(this,"onEvent");this.repoId=t,this.onEvent=n}start(){this.connect()}stop(){var t;this.disposed=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(t=this.source)==null||t.close(),this.source=null}connect(){if(this.disposed)return;const t=dY(this.repoId),n=new EventSource(t);this.source=n,n.onopen=()=>{this.attempts=0},n.onmessage=a=>{this.handleRaw("message",a)};const r=["message.updated","message.part.updated","message.part.delta","message.removed","todo.updated","session.status","session.idle","session.error","session.updated"];for(const a of r)n.addEventListener(a,i=>{this.handleRaw(a,i)});n.onerror=()=>{if(!(this.disposed||!this.source)&&this.source.readyState===EventSource.CLOSED){this.source.close(),this.source=null;const a=Math.min(Pq*2**this.attempts,Bq);this.attempts++,this.reconnectTimer=setTimeout(()=>this.connect(),a)}}}handleRaw(t,n){if(!(n instanceof MessageEvent))return;vs.tick("sse");const r=kq(n.data);if(r===void 0)return;const a=this.extractSessionId(r);if(!a)return;let i=t;if(t==="message"||t===""){const o=r&&typeof r=="object"?r:null;typeof(o==null?void 0:o.type)=="string"&&(i=o.type)}this.onEvent(a,i,r)}extractSessionId(t){if(!t||typeof t!="object")return null;const n=t;if(n.properties&&typeof n.properties=="object"){const r=n.properties;if(typeof r.sessionID=="string")return r.sessionID;if(typeof r.id=="string")return r.id}return typeof n.sessionID=="string"?n.sessionID:typeof n.sessionId=="string"?n.sessionId:null}}const Fq=6e4;class zq{constructor(t,n){pt(this,"timer",null);pt(this,"paused",!1);pt(this,"repoId");pt(this,"callbacks");this.repoId=t,this.callbacks=n}start(){this.tick(),this.timer=setInterval(()=>{this.paused||this.tick()},Fq)}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}pause(){this.paused=!0}resume(){this.paused=!1,this.tick()}tick(){const t=this.repoId;Me.getState().loadSessions(t),fY(t).then(n=>{const r={};for(const[a,i]of Object.entries(n))r[a]=i.type??"idle";Me.getState().bulkSetStatuses(r);for(const[a,i]of Object.entries(r))(i==="busy"||i==="retry")&&this.callbacks.ensureWorker(a)}).catch(()=>{})}}const Hq=600*1e3,$q=200;class Yq{constructor(t,n,r){pt(this,"sessionId");pt(this,"repoId");pt(this,"idleTimer",null);pt(this,"flushTimer",null);pt(this,"active",!1);pt(this,"alive",!0);pt(this,"callbacks");pt(this,"eventQueue",[]);pt(this,"deltaBuffer",new Map);this.sessionId=t,this.repoId=n,this.callbacks=r,this.resetIdleTimer()}dispatch(t,n){if(this.alive){if(this.resetIdleTimer(),vs.tick("sse"),t==="message.part.delta"){this.bufferDelta(n),this.scheduleFlush();return}if(t==="session.idle"||t==="session.status"||t==="session.error"){this.flush();const r=Me.getState(),a=r.sessionStatuses[this.sessionId];HA(t,n,this.sessionId,r);const i=Me.getState().sessionStatuses[this.sessionId];a&&a!=="idle"&&i==="idle"&&this.callbacks.onSessionIdle(this.sessionId);return}this.eventQueue.push({name:t,data:n}),this.scheduleFlush()}}activate(){this.active=!0,this.clearIdleTimer()}deactivate(){this.active=!1,this.resetIdleTimer()}refreshOnIdle(){Me.getState().refreshSessionData(this.repoId,this.sessionId)}stop(){this.alive=!1,this.flush(),this.clearIdleTimer(),this.cancelFlush()}scheduleFlush(){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.flush()},$q))}cancelFlush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null)}bufferDelta(t){const n=wM(t);if(!n)return;const r=this.deltaBuffer.get(n.partId);r?r.text+=n.delta:this.deltaBuffer.set(n.partId,{messageId:n.messageId,text:n.delta})}flush(){if(this.eventQueue.length===0&&this.deltaBuffer.size===0)return;const t=Me.getState(),n=this.eventQueue;this.eventQueue=[];for(const r of n)HA(r.name,r.data,this.sessionId,t);if(this.deltaBuffer.size>0){const r=this.deltaBuffer;this.deltaBuffer=new Map;for(const[a,{messageId:i,text:o}]of r)vs.tick("delta"),vs.tick("store"),t.appendMessagePartDelta(this.sessionId,i,a,o)}}resetIdleTimer(){this.clearIdleTimer(),!this.active&&(this.idleTimer=setTimeout(()=>{this.callbacks.onWorkerIdle(this.sessionId)},Hq))}clearIdleTimer(){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null)}}class qq{constructor(){pt(this,"workers",new Map);pt(this,"dispatcher",null);pt(this,"supervisor",null);pt(this,"visibilityHandler",null);pt(this,"repoId",null)}start(t){this.stop(),this.repoId=t;const n={onWorkerIdle:r=>this.removeWorker(r),onSessionIdle:r=>{var a;(a=this.workers.get(r))==null||a.refreshOnIdle()}};this.dispatcher=new Uq(t,(r,a,i)=>{this.ensureWorker(r,t,n).dispatch(a,i)}),this.dispatcher.start(),this.supervisor=new zq(t,{ensureWorker:r=>this.ensureWorker(r,t,n)}),this.supervisor.start(),this.visibilityHandler=()=>{var r,a;document.hidden?(r=this.supervisor)==null||r.pause():(a=this.supervisor)==null||a.resume()},document.addEventListener("visibilitychange",this.visibilityHandler)}stop(){var t,n;(t=this.dispatcher)==null||t.stop(),this.dispatcher=null,(n=this.supervisor)==null||n.stop(),this.supervisor=null;for(const r of this.workers.values())r.stop();this.workers.clear(),this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null)}activateSession(t){if(!this.repoId||!t)return;const n=this.repoId;for(const i of this.workers.values())i.sessionId!==t&&i.deactivate();const r={onWorkerIdle:i=>this.removeWorker(i),onSessionIdle:i=>{var o;return(o=this.workers.get(i))==null?void 0:o.refreshOnIdle()}};this.ensureWorker(t,n,r).activate(),Me.getState().refreshSessionData(n,t)}deactivateSession(t){var n;(n=this.workers.get(t))==null||n.deactivate()}ensureWorker(t,n,r){let a=this.workers.get(t);return a||(a=new Yq(t,n,r),this.workers.set(t,a),vs.setGauge("workers",this.workers.size)),a}removeWorker(t){const n=Me.getState().activeSessionId;if(t===n)return;const r=this.workers.get(t);r&&(r.stop(),this.workers.delete(t),vs.setGauge("workers",this.workers.size))}}const Vp=new qq;function oh({onConfirm:e,size:t="sm",variant:n="ghost",triggerClassName:r,stopPropagation:a,title:i="删除",children:o}){const[u,d]=y.useState(!1),f=t==="sm"?"h-3.5 w-3.5":"h-4 w-4",m=t==="sm"?"p-1":"p-1.5",p=n==="outlined"?"rounded-md":"rounded",b=t==="sm"?"gap-0.5":"gap-1",x=a?E=>E.stopPropagation():void 0;return u?c.jsxs("div",{className:ie("flex items-center",b),onClick:x,children:[c.jsx("button",{type:"button",onClick:()=>{e(),d(!1)},className:ie(p,m,"text-red-400 hover:bg-red-500/10",n==="outlined"&&"border border-red-500/30"),children:c.jsx(fi,{className:f})}),c.jsx("button",{type:"button",onClick:()=>d(!1),className:ie(p,m,"text-fg-4 hover:bg-elevated",n==="outlined"&&"border border-line"),children:c.jsx(At,{className:f})})]}):c.jsxs(c.Fragment,{children:[o,c.jsx("button",{type:"button",onClick:E=>{x==null||x(E),d(!0)},title:i,className:ie(p,m,r??"text-fg-5 hover:text-red-400",n==="outlined"&&"border border-line transition-colors hover:border-red-500/30"),children:c.jsx(a0,{className:f})})]})}function Gq(e,t){if(e instanceof Li)try{const n=JSON.parse(e.message);if(n.error)return n.error}catch{if(e.message)return e.message}return e instanceof Error?e.message:t}function lc(e,t,n){const{initialData:r,showErrorToast:a=!0,errorMessage:i="加载失败",skip:o=!1}=n??{},[u,d]=y.useState(r??null),[f,m]=y.useState(!o),[p,b]=y.useState(null),x=y.useRef(0),E=y.useRef(e);E.current=e;const N=y.useRef(i);N.current=i;const _=y.useRef(a);_.current=a;const S=y.useCallback(async()=>{const C=++x.current;m(!0),b(null);try{const A=await E.current();if(x.current!==C)return;d(A)}catch(A){if(x.current!==C)return;const I=Gq(A,N.current);b(I),_.current&&ar.getState().addToast(I,"error")}x.current===C&&m(!1)},[]);return y.useEffect(()=>{if(o){m(!1);return}return S(),()=>{x.current++}},[...t,o,S]),{data:u,loading:f,error:p,reload:S}}const Kq=["Sisyphus - ultraworker","Prometheus - Plan Builder","Atlas - Plan Executor"],Vq="pinned_models",il="__system_prompt__",$A=[{bg:"bg-blue-500/10",text:"text-blue-400"},{bg:"bg-amber-500/10",text:"text-amber-400"},{bg:"bg-green-500/10",text:"text-green-400"},{bg:"bg-purple-500/10",text:"text-purple-400"},{bg:"bg-cyan-500/10",text:"text-cyan-400"},{bg:"bg-rose-500/10",text:"text-rose-400"},{bg:"bg-indigo-500/10",text:"text-indigo-400"},{bg:"bg-orange-500/10",text:"text-orange-400"}],Wq={bg:"bg-elevated",text:"text-fg-4"};function _M(e){if(e==="general")return Wq;let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return $A[Math.abs(t)%$A.length]}function uc(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"刚刚";if(n<60)return`${n} 分钟前`;const r=Math.floor(n/60);if(r<24)return`${r} 小时前`;const a=Math.floor(r/24);return a<30?`${a} 天前`:`${Math.floor(a/30)} 个月前`}const TM={create:{label:"首次提取",color:"text-green-400"},update:{label:"重写",color:"text-blue-400"},merge:{label:"合并",color:"text-purple-400"},decay:{label:"衰减",color:"text-amber-400"},reinforce:{label:"强化",color:"text-emerald-400"},manual:{label:"手动编辑",color:"text-fg-3"}};function Xq({memory:e,onClose:t}){const n=[...e.history??[]].reverse();return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:c.jsxs("div",{className:"mx-4 max-h-[80vh] w-full max-w-lg overflow-y-auto rounded-xl border border-line bg-surface p-5 shadow-xl",onClick:r=>r.stopPropagation(),children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("h3",{className:"text-sm font-semibold text-fg",children:["版本历史 (",n.length+1," 个版本)"]}),c.jsx("button",{type:"button",onClick:t,className:"rounded p-1 text-fg-4 hover:text-fg-3",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"rounded-lg border border-blue-500/20 bg-blue-500/5 p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[10px]",children:[c.jsx("span",{className:"font-medium text-blue-400",children:"当前版本"}),c.jsx("span",{className:"text-fg-5",children:uc(e.updatedAt)}),c.jsxs("span",{className:"text-fg-6",children:["⚡ ",e.importance.toFixed(2)]})]}),c.jsx("p",{className:"text-xs leading-relaxed text-fg",children:e.content})]}),n.map((r,a)=>{const i=TM[r.action]??{label:r.action,color:"text-fg-4"};return c.jsxs("div",{className:"rounded-lg border border-line bg-base p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[10px]",children:[c.jsx("span",{className:ie("font-medium",i.color),children:i.label}),c.jsx("span",{className:"text-fg-5",children:uc(r.ts)}),c.jsxs("span",{className:"text-fg-6",children:["⚡ ",r.importance.toFixed(2)]}),r.source&&c.jsxs("span",{className:"text-fg-6",children:["· ",r.source]})]}),c.jsx("p",{className:"text-xs leading-relaxed text-fg-4",children:r.content})]},a)}),n.length===0&&c.jsx("div",{className:"py-4 text-center text-xs text-fg-5",children:"暂无历史版本"})]})]})})}function YA({memory:e,categories:t,onUpdate:n,onDelete:r}){var C;const[a,i]=y.useState(!1),[o,u]=y.useState(e.content),[d,f]=y.useState(e.category),[m,p]=y.useState(!1),[b,x]=y.useState(!1),E=_M(e.category),N=(C=e.history)==null?void 0:C[e.history.length-1],_=N&&Math.abs(N.importance-e.importance)>.001,S=async()=>{p(!0);try{await n(e.id,{content:o,category:d}),i(!1)}finally{p(!1)}};return a?c.jsxs("div",{className:"rounded-lg border border-blue-500/30 bg-blue-500/5 p-3 space-y-2",children:[c.jsx("textarea",{value:o,onChange:A=>u(A.target.value),rows:3,className:"w-full resize-y rounded-md border border-line bg-surface px-3 py-2 font-mono text-xs leading-relaxed text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("select",{value:d,onChange:A=>f(A.target.value),className:"rounded-md border border-line bg-surface px-2 py-1 text-xs text-fg focus:border-blue-500 focus:outline-none",children:t.map(A=>c.jsx("option",{value:A,children:A},A))}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:()=>{i(!1),u(e.content),f(e.category)},className:"rounded-md px-3 py-1 text-xs text-fg-4 hover:bg-elevated",children:"取消"}),c.jsx("button",{type:"button",onClick:()=>void S(),disabled:m||!o.trim(),className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white hover:bg-blue-500 disabled:opacity-40",children:m?"保存中…":"保存"})]})]}):c.jsxs("div",{className:"group/mem rounded-lg border border-line bg-base px-3 py-2.5",children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx("span",{className:ie("mt-0.5 shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",E.bg,E.text),children:e.category}),c.jsx("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-fg",children:e.content})]}),c.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-[11px] text-fg-5",children:[c.jsxs("span",{className:"flex items-center gap-0.5",children:[c.jsx(Cc,{className:"h-3 w-3"}),_&&N?`${N.importance.toFixed(2)}→${e.importance.toFixed(2)}`:e.importance.toFixed(2)]}),c.jsx("span",{children:"·"}),c.jsx("span",{children:uc(e.updatedAt)}),e.supersededBy&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsx("span",{className:"text-amber-400",children:e.supersededBy==="user-deleted"?"已删除":e.supersededBy==="consolidated-out"?"已整理":"已合并"})]}),e.history&&e.history.length>0&&(()=>{const A=e.history[e.history.length-1],I=TM[A.action];return c.jsxs("button",{type:"button",onClick:()=>x(!0),"data-guide":e.id==="guide-mem-1"?"agent-memory-version":void 0,className:ie("rounded px-1.5 py-0.5 text-[10px] font-medium transition-opacity hover:opacity-80",A.action==="update"?"bg-blue-500/10 text-blue-400":A.action==="merge"?"bg-purple-500/10 text-purple-400":A.action==="decay"?"bg-amber-500/10 text-amber-400":A.action==="reinforce"?"bg-emerald-500/10 text-emerald-400":A.action==="manual"?"bg-fg/10 text-fg-3":"bg-green-500/10 text-green-400"),children:[(I==null?void 0:I.label)??A.action," · ",e.history.length,"版"]})})(),c.jsx("div",{className:"flex-1"}),!e.supersededBy&&c.jsx("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover/mem:opacity-100",children:c.jsx(oh,{onConfirm:()=>void r(e.id),children:c.jsx("button",{type:"button",onClick:()=>i(!0),className:"rounded p-1 text-fg-5 hover:text-fg-3",children:c.jsx(jE,{className:"h-3.5 w-3.5"})})})})]}),b&&c.jsx(Xq,{memory:e,onClose:()=>x(!1)})]})}const Qq=14400*1e3;function Zq(e){if(!e)return"下次:待定";const t=e+Qq,n=Date.now();if(t<=n)return"下次:即将运行";const r=t-n,a=Math.floor(r/6e4);if(a<60)return`下次:约 ${a} 分钟后`;const i=Math.floor(a/60);return i<24?`下次:约 ${i} 小时后`:`下次:约 ${Math.floor(i/24)} 天后`}function Jq({stats:e,running:t,onTrigger:n}){if(!e)return null;const r=e.lastActions;return c.jsxs("div",{className:"rounded-lg bg-elevated px-3 py-2 text-[11px] tabular-nums text-fg-5",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[c.jsx("span",{children:e.lastConsolidatedAt?`上次整理:${uc(e.lastConsolidatedAt)}`:"尚未整理"}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{children:Zq(e.lastConsolidatedAt)}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:n,disabled:t,className:"rounded px-2 py-0.5 text-[10px] font-medium text-fg-4 transition-colors hover:bg-surface hover:text-fg-3 disabled:opacity-40",children:t?"整理中…":"立即整理"})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1",children:[r&&c.jsxs(c.Fragment,{children:[c.jsxs("span",{children:[r.update," 更新 ",r.merge," 合并 ",r.delete," 清理 ",r.decayed," 降权"]}),c.jsx("span",{className:"text-fg-6",children:"·"})]}),c.jsxs("span",{children:["活跃 ",e.totalActive," 条"]}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsxs("span",{children:["衰减中 ",e.stale]})]})]})}function eG({agentId:e}){const t=e.startsWith(gM),[n,r]=y.useState(null),[a,i]=y.useState(!1),[o,u]=y.useState(!1),[d,f]=y.useState(new Set),[m,p]=y.useState(!1),[b,x]=y.useState(null),[E,N]=y.useState(null),[_,S]=y.useState(!1),{data:C,loading:A,reload:I}=lc(()=>t?Promise.resolve(WY):rM(e,{includeSuperseded:a}),[e,a,t],{showErrorToast:!t,errorMessage:"加载记忆失败"}),O=C??[],k=y.useCallback(()=>{t||dA(e).then(N).catch(()=>N(null))},[e,t]);y.useEffect(()=>{k()},[k]);const j=async()=>{S(!0);try{await U$(e)}catch{S(!1);return}const D=setInterval(()=>{dA(e).then(z=>{N(z),z.lastConsolidatedAt&&(!(E!=null&&E.lastConsolidatedAt)||z.lastConsolidatedAt>E.lastConsolidatedAt)&&(clearInterval(D),S(!1),I())}).catch(()=>{})},5e3);setTimeout(()=>{clearInterval(D),S(!1)},3e5)},{data:F,loading:P}=lc(()=>BE(e),[e,o],{skip:!o,errorMessage:"加载 Session 列表失败"}),L=F??[],B=O.filter(D=>!D.supersededBy),Y=n?B.filter(D=>D.category===n):B,re=O.filter(D=>D.supersededBy),X=y.useMemo(()=>new Set(O.map(D=>D.sessionId).filter(Boolean)),[O]),K=async(D,z)=>{await L$(e,D,z),await I()},V=async D=>{await P$(e,D),await I()},H=D=>{f(z=>{const $=new Set(z);return $.has(D)?$.delete(D):$.add(D),$})},G=async()=>{if(d.size!==0){p(!0),x(null);try{const $=(await B$(e,[...d])).results;if($){const M=$.filter(oe=>oe.status==="ok"),le=$.filter(oe=>oe.status!=="ok");M.length>0&&x(`提取成功 ${M.reduce((oe,ne)=>oe+(ne.actions??0),0)} 条记忆`),le.length>0&&x(oe=>(oe?`${oe};`:"")+le.map(ne=>ne.error??ne.status).join(";")),M.length>0&&await I()}f(new Set)}catch(D){x(`请求失败: ${D instanceof Error?D.message:String(D)}`)}p(!1)}},Q=y.useMemo(()=>[...new Set(B.map(z=>z.category))].sort(),[B]);return c.jsxs("section",{"data-guide":"agent-memory-section",className:"rounded-xl border border-line bg-surface p-5 space-y-4",children:[c.jsx("div",{className:"flex items-center justify-between",children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(oc,{className:"h-4 w-4 text-purple-400"}),c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"记忆"}),!A&&c.jsx("span",{className:"rounded-full bg-elevated px-1.5 py-0.5 text-[10px] tabular-nums text-fg-4",children:Y.length})]})}),c.jsx(Jq,{stats:E,running:_,onTrigger:()=>void j()}),c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[c.jsx("button",{type:"button",onClick:()=>r(null),className:ie("rounded-full px-2.5 py-0.5 text-[11px] font-medium transition-colors",n===null?"bg-fg/10 text-fg":"text-fg-4 hover:text-fg-3"),children:"全部"}),Q.map(D=>{const z=_M(D);return c.jsx("button",{type:"button",onClick:()=>r(n===D?null:D),className:ie("rounded-full px-2.5 py-0.5 text-[11px] font-medium transition-colors",n===D?ie(z.bg,z.text):"text-fg-4 hover:text-fg-3"),children:D},D)})]}),A?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):Y.length===0&&re.length===0?c.jsx("div",{className:"py-8 text-center text-xs text-fg-5",children:"暂无记忆。使用此 Agent 完成 Session 后将自动提取。"}):c.jsxs("div",{className:"space-y-1.5",children:[Y.map(D=>c.jsx(YA,{memory:D,categories:Q,onUpdate:K,onDelete:V},D.id)),re.length>0&&c.jsxs("div",{className:"pt-1",children:[c.jsxs("button",{type:"button",onClick:()=>i(!a),className:"flex items-center gap-1 text-[11px] text-fg-5 hover:text-fg-3",children:[c.jsx("span",{children:a?"▾":"▸"}),"已合并/已删除 (",re.length,")"]}),a&&c.jsx("div",{className:"mt-1.5 space-y-1.5 opacity-60",children:re.map(D=>c.jsx(YA,{memory:D,categories:Q,onUpdate:K,onDelete:V},D.id))})]})]}),c.jsxs("div",{className:"border-t border-line pt-3",children:[c.jsxs("button",{type:"button",onClick:()=>u(!o),className:"flex items-center gap-1.5 text-xs font-medium text-fg-4 hover:text-fg-3",children:[c.jsx(n0,{className:"h-3.5 w-3.5"}),c.jsxs("span",{children:[o?"▾":"▸"," 从 Session 提取记忆"]})]}),o&&c.jsx("div",{className:"mt-2 space-y-1.5",children:P?c.jsx("div",{className:"flex items-center justify-center py-4",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):L.length===0?c.jsx("p",{className:"py-4 text-center text-xs text-fg-5",children:"暂无 Session 记录。"}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"max-h-64 space-y-1 overflow-y-auto",children:L.map(D=>{const z=X.has(D.id);return c.jsxs("label",{className:ie("flex cursor-pointer items-center gap-2.5 rounded-md border px-3 py-2 transition-colors",d.has(D.id)?"border-purple-500/30 bg-purple-500/5":"border-line bg-base hover:bg-elevated/60"),children:[c.jsx("input",{type:"checkbox",checked:d.has(D.id),onChange:()=>H(D.id),className:"h-3.5 w-3.5 shrink-0 cursor-pointer rounded border-line accent-purple-500"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"block truncate text-xs text-fg",children:D.title||D.id.slice(-8)}),c.jsx("span",{className:"text-[11px] text-fg-5",children:uc(D.timeCreated)})]}),c.jsx("span",{className:ie("shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium",z?"bg-green-500/10 text-green-400":"bg-elevated text-fg-5"),children:z?"已提取":"未提取"})]},D.id)})}),d.size>0&&c.jsxs("button",{type:"button",onClick:()=>void G(),disabled:m,className:"flex w-full items-center justify-center gap-1.5 rounded-lg bg-purple-600 py-2 text-xs font-medium text-white transition-colors hover:bg-purple-500 disabled:opacity-40",children:[m?c.jsx(nn,{className:"h-3.5 w-3.5 fs-spin"}):c.jsx(oc,{className:"h-3.5 w-3.5"}),m?"提取中…":`提取选中 Session 的记忆 (${d.size})`]}),b&&c.jsx("p",{className:ie("mt-1.5 rounded-md px-3 py-1.5 text-xs",b.includes("成功")?"bg-green-500/10 text-green-400":"bg-red-500/10 text-red-400"),children:b})]})})]})]})}function tG({agentId:e}){const{data:t,loading:n}=lc(()=>BE(e),[e],{errorMessage:"加载 Session 历史失败"}),r=t??[];return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(n0,{className:"h-4 w-4 text-fg-4"}),c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Session 历史"}),!n&&c.jsx("span",{className:"rounded-full bg-elevated px-1.5 py-0.5 text-[10px] tabular-nums text-fg-4",children:r.length})]}),c.jsx("div",{className:"mt-3",children:n?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):r.length===0?c.jsx("p",{className:"py-8 text-center text-xs text-fg-5",children:"暂无 Session 记录。"}):c.jsx("div",{className:"space-y-1",children:r.map(a=>c.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-line bg-base px-4 py-2.5",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"block truncate text-xs font-medium text-fg",children:a.title||a.id.slice(-8)}),c.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-fg-5",children:[c.jsx("span",{children:uc(a.timeCreated)}),a.cost>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsxs("span",{children:["$",a.cost.toFixed(4)]})]}),(a.tokensInput>0||a.tokensOutput>0)&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsxs("span",{children:[Math.round((a.tokensInput+a.tokensOutput)/1e3),"K tokens"]})]})]})]}),a.completedAt?c.jsx("span",{className:"shrink-0 rounded-full bg-green-500/10 px-2 py-0.5 text-[10px] font-medium text-green-400",children:"完成"}):c.jsx("span",{className:"shrink-0 rounded-full bg-elevated px-2 py-0.5 text-[10px] font-medium text-fg-5",children:"进行中"})]},a.id))})})]})}function nG({agent:e,fragments:t,onSave:n}){const r=We(Q=>Q.activeRepoId),[a,i]=y.useState(!1),[o,u]=y.useState(e.name),[d,f]=y.useState(e.description??""),[m,p]=y.useState(e.baseAgent),[b,x]=y.useState(e.model??""),[E,N]=y.useState(e.variant??""),[_,S]=y.useState(e.memoryModel??""),[C,A]=y.useState(e.systemPrompt),[I,O]=y.useState(!1),[k,j]=y.useState(!1),[F,P]=y.useState([]);y.useEffect(()=>{if(!r){P([]);return}let Q=!1;return(async()=>{try{const[D,z]=await Promise.all([Ml(),kc(r)]);if(Q)return;const $=D[Vq],M=$?JSON.parse($):[],le=M.length>0?z.filter(oe=>M.includes(oe.id)):z;P(le.length>0?le:z)}catch{Q||P([])}})(),()=>{Q=!0}},[r]);const[L,B]=y.useState(()=>{const Q=e.fragments.map(M=>M.id),D=e.systemPromptPosition??-1,z=D>=0&&D<=Q.length?D:Q.length,$=[...Q];return $.splice(z,0,il),$}),Y=Q=>{B(D=>{if(D.includes(Q))return D.filter(M=>M!==Q);const z=D.indexOf(il),$=[...D];return $.splice(z>=0?z:$.length,0,Q),$})},re=(Q,D)=>{const z=Q+D;z<0||z>=L.length||B($=>{const M=[...$];return[M[Q],M[z]]=[M[z],M[Q]],M})},X=L.filter(Q=>Q!==il),K=(()=>{const Q=L.indexOf(il);return Q<0?-1:L.slice(0,Q).filter(D=>D!==il).length})(),V=L.map(Q=>{var D;return Q===il?C:(D=t.find(z=>z.id===Q))==null?void 0:D.content}).filter(Boolean).join(`
523
+ )`}function uq(e,t){const n={position:"fixed"},r=window.innerWidth,a=window.innerHeight,i=e.top+e.height+jA,o=e.top-jA;let u=t==="bottom-right"?e.left+e.width-BA:e.left;return u=Math.max(UA,Math.min(u,r-BA-UA)),n.left=u,i+160<a?n.top=i:n.bottom=a-o,n}function Oy(e){const t=document.querySelector(e);t&&t.click()}const FA={selectMockIssue:JY,selectMockPr:eq,selectMockSession:tq,clearActiveSession:nq};function cq(){return window.innerWidth<sq}function dq({direction:e}){const t=e==="left"?ih:Oo;return c.jsx("div",{className:"pointer-events-none fixed inset-0 z-[9999] flex items-center justify-center",children:c.jsxs("div",{className:`flex items-center gap-1 rounded-full bg-blue-500/20 px-6 py-4 ${e==="left"?"fs-swipe-left":"fs-swipe-right"}`,children:[c.jsx(t,{className:"h-8 w-8 text-blue-400",strokeWidth:2.5}),c.jsx(t,{className:"h-8 w-8 text-blue-400/60",strokeWidth:2.5}),c.jsx(t,{className:"h-8 w-8 text-blue-400/30",strokeWidth:2.5})]})})}function fq({step:e,stepIdx:t,total:n,isFirst:r,isLast:a,onPrev:i,onNext:o,onClose:u}){return c.jsx("div",{className:"fixed inset-x-0 bottom-24 z-[10000] flex justify-center px-4",children:c.jsxs("div",{className:"w-72 rounded-xl border border-line bg-surface p-4 shadow-2xl",children:[c.jsx("button",{type:"button",onClick:u,className:"absolute right-2 top-2 rounded-md p-1 text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3","aria-label":"关闭引导",children:c.jsx(At,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:e.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:e.description}),c.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[c.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-fg-5",children:[t+1," / ",n]}),c.jsxs("div",{className:"flex items-center gap-2",children:[!r&&c.jsx("button",{type:"button",onClick:i,className:"rounded-md px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"上一步"}),c.jsx("button",{type:"button",onClick:o,className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:a?"完成":"下一步"})]})]})]})})}function hq(){const e=zn(),t=or(),n=ys(L=>L.guideTourOpen),r=ys(L=>L.guideTourSection),a=ys(L=>L.stopGuideTour),i=We(qr),[o,u]=y.useState(0),[d,f]=y.useState(null),m=y.useRef(null),p=y.useRef(-1),b=y.useRef(null),x=y.useMemo(()=>n?aq(r):e1,[n,r]),E=o<x.length?x[o]:void 0,N=x.length,_=o===0,S=o===N-1,C=y.useCallback(()=>{if(!n||!E)return;const L=E.padding??iq;f(oq(E.target,L))},[n,E]),A=y.useCallback(L=>{const B=L.replace("__MOCK_AGENT__",rq());return B.startsWith("/")?B:i?`/${encodeURIComponent(i)}/${B}`:`/${B}`},[i]);y.useEffect(()=>{n&&(u(0),p.current=-1)},[n]),y.useEffect(()=>{if(!n||!E)return;const L=p.current,B=L>=0?x[L]:null;B!=null&&B.triggerClick&&document.querySelector(B.target)&&Oy(B.triggerClick);const Y=(B==null?void 0:B.mockScope)??null,re=E.mockScope??null;re&&re!==Y?(QY(re),b.current=re):!re&&b.current&&(DA(),b.current=null);const X=E.route?A(E.route):null,K=X&&!t.pathname.startsWith(X);K&&e(X);const H=setTimeout(()=>{E.setupFn&&FA[E.setupFn]&&FA[E.setupFn](),setTimeout(()=>{E.triggerClick&&!document.querySelector(E.target)&&Oy(E.triggerClick),setTimeout(C,PA)},E.setupFn?LA:0)},K?LA:re&&re!==Y?PA:0);return p.current=o,()=>clearTimeout(H)},[n,o,E,e,t.pathname,C,A,x]),y.useLayoutEffect(()=>{C()},[C]),y.useEffect(()=>{if(n)return window.addEventListener("resize",C),window.addEventListener("scroll",C,!0),()=>{window.removeEventListener("resize",C),window.removeEventListener("scroll",C,!0)}},[n,C]);const I=y.useRef(o);I.current=o;const O=y.useRef(x);O.current=x;const k=y.useCallback(()=>{const L=O.current[I.current];L!=null&&L.triggerClick&&document.querySelector(L.target)&&Oy(L.triggerClick),b.current&&(DA(),b.current=null),a()},[a]);if(y.useEffect(()=>{if(!n)return;const L=B=>{B.key==="Escape"&&k()};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[n,k]),!n||!E)return null;const j=cq()&&E.mobileSwipeHint&&!d;if(!d&&!j)return null;const F=()=>{_||u(L=>L-1)},P=()=>{S?k():u(L=>L+1)};return j?gs.createPortal(c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"fixed inset-0 z-[9998] bg-black/60",onClick:k}),c.jsx(dq,{direction:E.mobileSwipeHint}),c.jsx(fq,{step:E,stepIdx:o,total:N,isFirst:_,isLast:S,onPrev:F,onNext:P,onClose:k})]}),document.body):gs.createPortal(c.jsxs("div",{className:"fixed inset-0 z-[9999]",children:[c.jsx("div",{className:"absolute inset-0 bg-black/60 transition-[clip-path] duration-200",style:{clipPath:lq(d)},onClick:k}),c.jsx("div",{className:"pointer-events-none absolute rounded-lg ring-2 ring-blue-500 ring-offset-2 ring-offset-transparent transition-all duration-200",style:{top:d==null?void 0:d.top,left:d==null?void 0:d.left,width:d==null?void 0:d.width,height:d==null?void 0:d.height}}),c.jsxs("div",{ref:m,className:"fixed z-[10000] w-72 rounded-xl border border-line bg-surface p-4 shadow-2xl",style:uq(d,E.position),children:[c.jsx("button",{type:"button",onClick:k,className:"absolute right-2 top-2 rounded-md p-1 text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3","aria-label":"关闭引导",children:c.jsx(At,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:E.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:E.description}),c.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[c.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-fg-5",children:[o+1," / ",N]}),c.jsxs("div",{className:"flex items-center gap-2",children:[!_&&c.jsx("button",{type:"button",onClick:F,className:"rounded-md px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"上一步"}),c.jsx("button",{type:"button",onClick:P,className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:S?"完成":"下一步"})]})]})]})]}),document.body)}const EM=[{segment:"run",icon:LE,label:"运行面板",global:!1},{segment:"dev/issues",icon:Ez,label:"研发",global:!1,matchPrefix:"dev"},{segment:"agents",icon:QF,label:"Agents",global:!1}];function NM(e,t,n){return t?`/${e}`:n?`/${encodeURIComponent(n)}/${e}`:`/${e}`}function SM(e,t,n){if(!e.matchPrefix)return!1;const r=e.global?`/${e.matchPrefix}`:n?`/${encodeURIComponent(n)}/${e.matchPrefix}`:null;return r?t===r||t.startsWith(`${r}/`):!1}function mq(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function pq({repos:e,activeRepoId:t,onRepoChange:n}){const r=zn(),[a,i]=y.useState(!1),[o,u]=y.useState(-1),d=y.useRef(null),f=e.find(b=>b.id===t),m=y.useCallback(()=>{i(!1),u(-1)},[]);y.useEffect(()=>{if(!a)return;const b=x=>{d.current&&!d.current.contains(x.target)&&m()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[a,m]);const p=y.useCallback(b=>{if(a)switch(b.key){case"Escape":b.preventDefault(),m();break;case"ArrowDown":b.preventDefault(),u(x=>Math.min(x+1,e.length-1));break;case"ArrowUp":b.preventDefault(),u(x=>Math.max(x-1,0));break;case"Enter":o>=0&&o<e.length&&(b.preventDefault(),n(e[o].id),m());break}},[a,m,o,e,n]);return c.jsxs("div",{ref:d,className:"relative",onKeyDown:p,children:[c.jsxs("button",{type:"button","data-guide":"repo-switcher",onClick:()=>i(b=>!b),"aria-label":"切换仓库","aria-haspopup":"listbox","aria-expanded":a,className:"flex max-w-[140px] items-center gap-1 rounded-md border border-line bg-base px-2 py-1 text-xs text-fg-2 transition-colors hover:border-blue-500 sm:max-w-[200px]",children:[c.jsx(FR,{className:"h-3 w-3 shrink-0 text-fg-4"}),c.jsxs("span",{className:"truncate",children:[c.jsx("span",{className:"sm:hidden",children:f?mq(f.name):""}),c.jsx("span",{className:"hidden sm:inline",children:(f==null?void 0:f.name)??""})]}),c.jsx(kr,{className:ie("h-3 w-3 shrink-0 text-fg-4 transition-transform",a&&"rotate-180")})]}),a&&c.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-64 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[c.jsx("div",{role:"listbox","aria-label":"仓库列表",className:"max-h-64 overflow-y-auto py-1",children:e.map((b,x)=>c.jsxs("button",{type:"button",role:"option","aria-selected":b.id===t,onClick:()=>{n(b.id),m()},className:ie("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",b.id===t?"font-medium text-blue-600":"text-fg-2 hover:bg-elevated",o===x&&"bg-elevated"),children:[b.id===t?c.jsx(fi,{className:"h-3 w-3 shrink-0"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:b.name})]},b.id))}),c.jsx("div",{className:"border-t border-line",children:c.jsxs("button",{type:"button","data-guide":"manage-repos",onClick:()=>{r("/repos"),m()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:[c.jsx(r0,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"管理仓库"})]})})]})]})}function gq({repoId:e,currentBranch:t}){const n=We(S=>S.updateRepoBranch),[r,a]=y.useState(!1),[i,o]=y.useState(null),[u,d]=y.useState(!1),[f,m]=y.useState(null),[p,b]=y.useState(null),x=y.useRef(null),E=y.useCallback(()=>{a(!1),b(null)},[]);y.useEffect(()=>{if(!r)return;const S=C=>{x.current&&!x.current.contains(C.target)&&E()};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[r,E]);const N=async()=>{if(r){E();return}a(!0),d(!0),b(null);try{o(await d$(e))}catch{b("加载分支失败")}finally{d(!1)}},_=async S=>{if(!(S===t||f)){m(S),b(null);try{const C=await f$(e,S);n(e,C.branch),E()}catch(C){b(C instanceof Error?C.message:"切换失败")}finally{m(null)}}};return t?c.jsxs("div",{ref:x,className:"relative",children:[c.jsxs("button",{type:"button",onClick:N,className:"flex items-center gap-1 rounded-md bg-elevated px-2 py-1 text-xs text-fg-3 transition-colors hover:bg-blue-500/10 hover:text-blue-600",children:[c.jsx(Gl,{className:"h-3 w-3"}),t,c.jsx(kr,{className:ie("h-3 w-3 transition-transform",r&&"rotate-180")})]}),r&&c.jsxs("div",{className:"absolute right-0 top-full z-50 mt-1 w-56 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[u?c.jsx("div",{className:"flex items-center justify-center py-4",children:c.jsx(nn,{className:"h-4 w-4 animate-spin text-fg-4"})}):i?c.jsxs("div",{className:"max-h-64 overflow-y-auto py-1",children:[i.local.map(S=>c.jsxs("button",{type:"button",disabled:f!==null,onClick:()=>_(S),className:ie("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",S===t?"font-medium text-blue-600":"text-fg-2 hover:bg-elevated"),children:[S===t?c.jsx(fi,{className:"h-3 w-3 shrink-0"}):f===S?c.jsx(nn,{className:"h-3 w-3 shrink-0 animate-spin"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:S})]},S)),i.remote.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"mx-3 my-1 border-t border-line"}),c.jsx("div",{className:"px-3 py-1 text-[10px] font-medium uppercase tracking-wider text-fg-4",children:"Remote"}),i.remote.map(S=>c.jsxs("button",{type:"button",disabled:f!==null,onClick:()=>_(S),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[f===S?c.jsx(nn,{className:"h-3 w-3 shrink-0 animate-spin"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:S})]},`remote-${S}`))]})]}):null,p&&c.jsx("div",{className:"border-t border-line px-3 py-2 text-xs text-red-500",children:p})]})]}):null}function bq(){const[e,t]=y.useState(null);return y.useEffect(()=>{const n=()=>fetch("/api/health").then(i=>i.json()).then(i=>{i.latestVersion&&i.latestVersion!=="0.11.37"&&t(i.latestVersion)}).catch(()=>{});n();const r=setInterval(n,RY),a=()=>n();return window.addEventListener("focus",a),()=>{clearInterval(r),window.removeEventListener("focus",a)}},[]),e}function xq({navigate:e,cycle:t,themeLabel:n,ThemeIcon:r}){const[a,i]=y.useState(!1),o=y.useRef(null);return y.useEffect(()=>{if(!a)return;const u=d=>{o.current&&!o.current.contains(d.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[a]),c.jsxs("div",{ref:o,className:"relative md:hidden",children:[c.jsx("button",{type:"button",onClick:()=>i(u=>!u),"aria-label":"更多",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(kz,{className:"h-4 w-4"})}),a&&c.jsxs("div",{className:"absolute right-0 top-full z-50 mt-1 w-40 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[c.jsxs("button",{type:"button",onClick:()=>{e("/analytics"),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(ah,{className:"h-3.5 w-3.5 text-fg-4"}),"统计"]}),c.jsxs("button",{type:"button",onClick:()=>{e("/settings"),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(r0,{className:"h-3.5 w-3.5 text-fg-4"}),"设置"]}),c.jsxs("button",{type:"button",onClick:()=>{t(),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(r,{className:"h-3.5 w-3.5 text-fg-4"}),n]}),c.jsxs("a",{href:"https://github.com/kinminghao/fourth-spark",target:"_blank",rel:"noopener noreferrer",onClick:()=>i(!1),className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx("svg",{className:"h-3.5 w-3.5 text-fg-4",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})}),"GitHub"]}),c.jsxs("button",{type:"button",onClick:()=>{ys.getState().startGuideTour(vM(window.location.pathname)),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(zR,{className:"h-3.5 w-3.5 text-fg-4"}),"功能引导"]})]})]})}function yq(){const e=zn(),t=or(),n=We(p=>p.repos),r=We(p=>p.activeRepoId),a=We(p=>p.setActiveRepo),i=Zv(p=>p.preference),o=Zv(p=>p.cycle),u=i==="light"?YH:i==="dark"?SH:EH,d=n.find(p=>p.id===r),f=bq(),m=p=>{var N;if(!p)return;a(p);const b=n.find(_=>_.id===p);if(!b)return;const x=t.pathname.match(/\/dev\/(issues|pulls)/);if(x){e(`/${encodeURIComponent(b.name)}/dev/${x[1]}`);return}const E=((N=t.pathname.match(/\/(run|agents|issues|pulls)/))==null?void 0:N[1])??"run";e(`/${encodeURIComponent(b.name)}/${E}`)};return c.jsxs("header",{className:"shrink-0 border-b border-line bg-surface pt-[var(--safe-top)]",children:[c.jsxs("div",{className:"flex h-12 items-center justify-between px-4",children:[c.jsxs("div",{className:"flex items-center gap-2.5",children:[c.jsx(Cc,{className:"h-5 w-5 text-blue-500"}),c.jsx("span",{className:"hidden text-sm font-bold tracking-tight text-fg sm:inline",children:"Fourth Spark"}),c.jsxs("span",{className:"hidden rounded bg-elevated px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-fg-4 sm:inline",children:["v","0.11.37"]}),f&&c.jsxs("span",{className:"hidden text-[10px] text-amber-500 sm:inline",children:["→ v",f," 可用,运行"," ",c.jsx("code",{className:"rounded bg-amber-500/10 px-1 font-mono",children:"fourth-spark upgrade"})," 更新"]})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[n.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(pq,{repos:n,activeRepoId:r,onRepoChange:m}),d&&r&&c.jsx(gq,{repoId:r,currentBranch:d.branch})]}),c.jsxs("div",{className:"hidden items-center gap-1 md:flex",children:[c.jsx("button",{type:"button",onClick:()=>e("/analytics"),"aria-label":"统计",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(ah,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>e("/settings"),"aria-label":"设置",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(r0,{className:"h-4 w-4"})}),c.jsx("a",{href:"https://github.com/kinminghao/fourth-spark",target:"_blank",rel:"noopener noreferrer","aria-label":"GitHub",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})})}),c.jsx("button",{type:"button",onClick:o,"aria-label":`主题: ${i}`,className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(u,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>ys.getState().startGuideTour(vM(t.pathname)),"aria-label":"功能引导",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(zR,{className:"h-4 w-4"})})]}),c.jsx(xq,{navigate:e,cycle:o,themeLabel:`主题: ${i}`,ThemeIcon:u})]})]}),f&&c.jsx("div",{className:"border-t border-line px-4 py-1.5 sm:hidden",children:c.jsxs("span",{className:"text-[10px] text-amber-500",children:["→ v",f," 可用,运行"," ",c.jsx("code",{className:"rounded bg-amber-500/10 px-1 font-mono",children:"fourth-spark upgrade"})," 更新"]})})]})}function vq(){const e=We(qr),t=ys(a=>a.navCollapsed),n=ys(a=>a.toggleNav),r=or();return c.jsxs("nav",{className:ie("hidden shrink-0 flex-col border-r border-line bg-surface py-2 transition-[width] duration-200 ease-in-out md:flex",t?"w-14":"w-48"),children:[c.jsx("div",{className:"flex flex-1 flex-col",children:EM.map(a=>{const i=SM(a,r.pathname,e);return c.jsxs(Hp,{to:NM(a.segment,a.global,e),title:t?a.label:void 0,className:({isActive:o})=>ie("mx-2 flex items-center rounded-md py-2 text-sm transition-colors",t?"justify-center px-2":"gap-2.5 px-3",o||i?"bg-blue-500/10 font-medium text-blue-600":"text-fg-3 hover:bg-elevated hover:text-fg"),children:[c.jsx(a.icon,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:ie("truncate transition-[opacity,max-width] duration-200 ease-in-out",t?"max-w-0 opacity-0":"max-w-[8rem] opacity-100"),children:a.label})]},a.segment)})}),c.jsxs(Hp,{to:"/settings",title:t?"设置":void 0,className:({isActive:a})=>ie("mx-2 flex items-center rounded-md py-2 text-sm transition-colors",t?"justify-center px-2":"gap-2.5 px-3",a?"bg-blue-500/10 font-medium text-blue-600":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:[c.jsx(r0,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:ie("truncate transition-[opacity,max-width] duration-200 ease-in-out",t?"max-w-0 opacity-0":"max-w-[8rem] opacity-100"),children:"设置"})]}),c.jsx("button",{type:"button",onClick:n,title:t?"展开导航":"收起导航",className:"mx-2 flex items-center justify-center rounded-md py-2 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:t?c.jsx(uz,{className:"h-4 w-4"}):c.jsx(oz,{className:"h-4 w-4"})})]})}function Eq(){const e=We(qr),t=or();return c.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-30 border-t border-line bg-surface pb-[var(--safe-bottom)] md:hidden",children:c.jsx("div",{className:"flex h-14 items-center justify-around",children:EM.map(n=>{const r=SM(n,t.pathname,e);return c.jsx(Hp,{to:NM(n.segment,n.global,e),"aria-label":n.label,className:({isActive:a})=>ie("flex h-10 w-10 items-center justify-center rounded-md transition-colors",a||r?"bg-blue-500/10 text-blue-600":"text-fg-3 hover:bg-elevated hover:text-fg"),children:c.jsx(n.icon,{className:"h-5 w-5 shrink-0"})},n.segment)})})})}function Nq(){return c.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-base text-fg",children:[c.jsx(yq,{}),c.jsxs("div",{className:"flex min-h-0 flex-1",children:[c.jsx(vq,{}),c.jsx("main",{className:"flex min-w-0 flex-1 flex-col overflow-hidden pb-[calc(3.5rem_+_var(--safe-bottom))] md:pb-0",children:c.jsx(Z7,{})})]}),c.jsx(Eq,{}),c.jsx(hq,{})]})}let Sq=0;const ar=$i(e=>({toasts:[],addToast:(t,n="info",r,a)=>{const i=(a==null?void 0:a.id)??`toast-${++Sq}-${Date.now()}`;e(o=>o.toasts.some(u=>u.id===i)?o:{toasts:[...o.toasts,{id:i,message:t,variant:n,sessionId:r,persistent:a==null?void 0:a.persistent}]}),a!=null&&a.persistent||setTimeout(()=>{e(o=>({toasts:o.toasts.filter(u=>u.id!==i)}))},uM)},removeToast:t=>{e(n=>({toasts:n.toasts.filter(r=>r.id!==t)}))}})),wq={info:{icon:"ℹ",badge:"bg-fg/10 text-fg-2",bar:"bg-fg-4"},success:{icon:"✓",badge:"bg-emerald-500/10 text-emerald-500",bar:"bg-emerald-500"},warning:{icon:"⚠",badge:"bg-amber-500/10 text-amber-500",bar:"bg-amber-500"},error:{icon:"✕",badge:"bg-red-500/10 text-red-500",bar:"bg-red-500"}};function zA(){const e=ar(m=>m.toasts),t=ar(m=>m.removeToast),n=Me(m=>m.setActiveSession),r=We(m=>m.activeRepoId),a=We(qr),i=zn(),o=m=>{t(m.id),m.sessionId&&r&&(n(r,m.sessionId),i(`/${encodeURIComponent(a)}/run`))},[u,d]=y.useState([]),f=y.useRef(new Map);return y.useEffect(()=>{const m=new Set(e.map(p=>p.id));d(p=>{let b=p.map(x=>m.has(x.id)||x.exiting?x:{...x,exiting:!0});for(const x of e)b.some(E=>E.id===x.id)||(b=[...b,{...x}]);return b})},[e]),y.useEffect(()=>{const m=f.current;for(const p of u)p.exiting&&!m.has(p.id)&&m.set(p.id,setTimeout(()=>{m.delete(p.id),d(b=>b.filter(x=>x.id!==p.id))},_Y))},[u]),y.useEffect(()=>{const m=f.current;return()=>m.forEach(clearTimeout)},[]),u.length===0?null:c.jsx("div",{className:"pointer-events-none fixed top-4 right-4 z-50 flex w-[calc(100%-2rem)] max-w-sm flex-col",role:"status","aria-live":"polite","aria-atomic":"false",children:u.map(m=>{const p=wq[m.variant];return c.jsx("div",{className:"grid w-full transition-[grid-template-rows] duration-300 ease-out",style:{gridTemplateRows:m.exiting?"0fr":"1fr"},children:c.jsx("div",{className:"min-h-0 overflow-hidden",children:c.jsxs("div",{role:"status",onClick:()=>o(m),style:{animation:`${m.exiting?"toast-out":"toast-in"} 0.3s ease-out forwards`},className:"pointer-events-auto relative mb-2 flex cursor-pointer items-start gap-3 overflow-hidden rounded-xl border border-line bg-surface/80 px-3.5 py-3 shadow-lg shadow-black/5 backdrop-blur-md transition-colors hover:border-line-hard hover:bg-surface/90",children:[c.jsx("span",{"aria-hidden":!0,className:`mt-px flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-xs font-semibold ${p.badge}`,children:p.icon}),c.jsx("p",{className:"min-w-0 flex-1 text-sm leading-snug break-words text-fg",children:m.message}),m.persistent&&!m.exiting&&c.jsx("button",{type:"button","aria-label":"关闭",onClick:b=>{b.stopPropagation(),t(m.id)},className:"mt-px flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-fg-4 transition-colors hover:bg-fg/10 hover:text-fg",children:"✕"}),!m.exiting&&!m.persistent&&c.jsx("span",{"aria-hidden":!0,className:`absolute bottom-0 left-0 h-0.5 w-full origin-left ${p.bar}`,style:{animation:`toast-progress ${uM}ms linear forwards`}})]})})},m.id)})})}const _q=1e3,Tq=5e3,Jm="freeze-mon-buffer",Aq=4*1024*1024;class Cq{constructor(){pt(this,"ring",[]);pt(this,"counters",{sse:0,delta:0,store:0});pt(this,"workerCount",0);pt(this,"sampleTimer",0);pt(this,"persistTimer",0);pt(this,"running",!1)}tick(t){this.counters[t]++}setGauge(t,n){t==="workers"&&(this.workerCount=n)}exportData(){return localStorage.getItem(Jm)??JSON.stringify(this.ring)}start(){if(this.running)return;this.running=!0;const t=localStorage.getItem(Jm);if(t)try{this.ring=JSON.parse(t)}catch{this.ring=[]}this.sampleTimer=window.setInterval(()=>this.sample(),_q),this.persistTimer=window.setInterval(()=>this.persist(),Tq)}stop(){this.running=!1,clearInterval(this.sampleTimer),clearInterval(this.persistTimer),this.persist()}sample(){const t=Me.getState(),n=Object.values(t.messages).reduce((a,i)=>a+i.length,0),r=performance.memory;this.ring.push({ts:Date.now(),sse:this.counters.sse,delta:this.counters.delta,store:this.counters.store,workers:this.workerCount,msgs:n,heap:r?Math.round(r.usedJSHeapSize/1048576):void 0}),this.counters.sse=0,this.counters.delta=0,this.counters.store=0,this.trimToFit()}trimToFit(){for(;this.ring.length>1&&!(new Blob([JSON.stringify(this.ring)]).size<=Aq);)this.ring.shift()}persist(){try{localStorage.setItem(Jm,JSON.stringify(this.ring))}catch{this.ring.splice(0,Math.floor(this.ring.length/2));try{localStorage.setItem(Jm,JSON.stringify(this.ring))}catch{}}}}const vs=new Cq;function kq(e){if(typeof e!="string")return e;const t=e.trim();if(t)try{return JSON.parse(t)}catch{return t}}function ir(e){return e&&typeof e=="object"?e:null}function Kl(e){const t=ir(e);return t&&"properties"in t?t.properties:e}function Oq(e){const t=ir(e);return typeof(t==null?void 0:t.type)=="string"?t.type:void 0}function Iq(e){const t=ir(Kl(e));if(!t)return null;const n=ir(t.info);if(n&&typeof n.id=="string"){const a=Array.isArray(t.parts)?t.parts:void 0;return{...n,...a?{parts:a}:{}}}if(typeof t.id=="string"&&typeof t.role=="string")return t;const r=ir(t.message);return r&&typeof r.id=="string"?r:null}function Rq(e){const t=ir(Kl(e));if(!t)return{};const n=ir(t.part)??t;return typeof n.type!="string"?{}:{messageId:typeof n.messageID=="string"&&n.messageID||typeof n.messageId=="string"&&n.messageId||typeof t.messageID=="string"&&t.messageID||typeof t.messageId=="string"&&t.messageId||void 0,part:n}}function wM(e){const t=ir(Kl(e));if(!t||t.field!=="text")return null;const n=typeof t.messageID=="string"?t.messageID:null,r=typeof t.partID=="string"?t.partID:null,a=typeof t.delta=="string"?t.delta:null;return!n||!r||a===null?null:{messageId:n,partId:r,delta:a}}function Mq(e){const t=Kl(e);if(Array.isArray(t))return t;const n=ir(t);return n&&Array.isArray(n.todos)?n.todos:[]}function wi(e){return typeof e=="number"?e:0}function Dq(e){const t=ir(Kl(e));if(!t||typeof t.id!="string")return null;const n={id:t.id};typeof t.title=="string"&&(n.title=t.title),typeof t.agent=="string"&&(n.agent=t.agent),typeof t.cost=="number"&&(n.cost=t.cost);const r=typeof t.parentID=="string"?t.parentID:typeof t.parent_id=="string"?t.parent_id:void 0;r&&(n.parentID=r);const a=ir(t.tokens),i=typeof t.tokens_input=="number"||typeof t.tokens_output=="number";if(a||i){const u=a?ir(a.cache):null;n.tokens={input:wi(a==null?void 0:a.input)||wi(t.tokens_input),output:wi(a==null?void 0:a.output)||wi(t.tokens_output),reasoning:wi(a==null?void 0:a.reasoning)||wi(t.tokens_reasoning),cache:{read:wi(u==null?void 0:u.read)||wi(t.tokens_cache_read),write:wi(u==null?void 0:u.write)||wi(t.tokens_cache_write)}}}const o=ir(t.model);return o&&(n.model={providerID:typeof o.providerID=="string"?o.providerID:void 0,modelID:typeof o.modelID=="string"?o.modelID:void 0,variant:typeof o.variant=="string"?o.variant:void 0}),n}function jq(e){const t=ir(Kl(e));if(!t)return null;if(typeof t.message=="string")return t.message;const n=ir(t.error);if(n){const r=ir(n.data);if(typeof(r==null?void 0:r.message)=="string")return`${n.name??"Error"}: ${r.message}`;if(typeof n.message=="string")return`${n.name??"Error"}: ${n.message}`;if(typeof n.name=="string")return String(n.name)}return typeof t.reason=="string"?t.reason:null}function Lq(e){const t=Kl(e);if(typeof t=="string")return t;const n=ir(t);if(typeof(n==null?void 0:n.status)=="string")return n.status;const r=ir(n==null?void 0:n.status);return typeof(r==null?void 0:r.type)=="string"?r.type:typeof(n==null?void 0:n.type)=="string"?n.type:null}function HA(e,t,n,r){switch(e==="message"||e===""?Oq(t)??e:e){case"message.updated":{const i=Iq(t);i&&r.updateMessage(n,i);break}case"session.updated":{const i=Dq(t);i&&r.updateSessionInfo(i);break}case"message.part.updated":{const{messageId:i,part:o}=Rq(t);o&&i&&r.updateMessagePart(n,i,o);break}case"message.part.delta":{const i=wM(t);i&&r.appendMessagePartDelta(n,i.messageId,i.partId,i.delta);break}case"todo.updated":{r.updateTodos(n,Mq(t));break}case"session.status":{const i=Lq(t);i&&r.setSessionStatus(n,i);break}case"session.idle":{r.setSessionStatus(n,"idle");break}case"session.error":{const i=jq(t);r.setSessionStatus(n,"error",i??void 0);break}}}const Pq=1e3,Bq=3e4;class Uq{constructor(t,n){pt(this,"source",null);pt(this,"reconnectTimer",null);pt(this,"attempts",0);pt(this,"disposed",!1);pt(this,"repoId");pt(this,"onEvent");this.repoId=t,this.onEvent=n}start(){this.connect()}stop(){var t;this.disposed=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(t=this.source)==null||t.close(),this.source=null}connect(){if(this.disposed)return;const t=dY(this.repoId),n=new EventSource(t);this.source=n,n.onopen=()=>{this.attempts=0},n.onmessage=a=>{this.handleRaw("message",a)};const r=["message.updated","message.part.updated","message.part.delta","message.removed","todo.updated","session.status","session.idle","session.error","session.updated"];for(const a of r)n.addEventListener(a,i=>{this.handleRaw(a,i)});n.onerror=()=>{if(!(this.disposed||!this.source)&&this.source.readyState===EventSource.CLOSED){this.source.close(),this.source=null;const a=Math.min(Pq*2**this.attempts,Bq);this.attempts++,this.reconnectTimer=setTimeout(()=>this.connect(),a)}}}handleRaw(t,n){if(!(n instanceof MessageEvent))return;vs.tick("sse");const r=kq(n.data);if(r===void 0)return;const a=this.extractSessionId(r);if(!a)return;let i=t;if(t==="message"||t===""){const o=r&&typeof r=="object"?r:null;typeof(o==null?void 0:o.type)=="string"&&(i=o.type)}this.onEvent(a,i,r)}extractSessionId(t){if(!t||typeof t!="object")return null;const n=t;if(n.properties&&typeof n.properties=="object"){const r=n.properties;if(typeof r.sessionID=="string")return r.sessionID;if(typeof r.id=="string")return r.id}return typeof n.sessionID=="string"?n.sessionID:typeof n.sessionId=="string"?n.sessionId:null}}const Fq=6e4;class zq{constructor(t,n){pt(this,"timer",null);pt(this,"paused",!1);pt(this,"repoId");pt(this,"callbacks");this.repoId=t,this.callbacks=n}start(){this.tick(),this.timer=setInterval(()=>{this.paused||this.tick()},Fq)}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}pause(){this.paused=!0}resume(){this.paused=!1,this.tick()}tick(){const t=this.repoId;Me.getState().loadSessions(t),fY(t).then(n=>{const r={};for(const[a,i]of Object.entries(n))r[a]=i.type??"idle";Me.getState().bulkSetStatuses(r);for(const[a,i]of Object.entries(r))(i==="busy"||i==="retry")&&this.callbacks.ensureWorker(a)}).catch(()=>{})}}const Hq=600*1e3,$q=200;class Yq{constructor(t,n,r){pt(this,"sessionId");pt(this,"repoId");pt(this,"idleTimer",null);pt(this,"flushTimer",null);pt(this,"active",!1);pt(this,"alive",!0);pt(this,"callbacks");pt(this,"eventQueue",[]);pt(this,"deltaBuffer",new Map);this.sessionId=t,this.repoId=n,this.callbacks=r,this.resetIdleTimer()}dispatch(t,n){if(this.alive){if(this.resetIdleTimer(),vs.tick("sse"),t==="message.part.delta"){this.bufferDelta(n),this.scheduleFlush();return}if(t==="session.idle"||t==="session.status"||t==="session.error"){this.flush();const r=Me.getState(),a=r.sessionStatuses[this.sessionId];HA(t,n,this.sessionId,r);const i=Me.getState().sessionStatuses[this.sessionId];a&&a!=="idle"&&i==="idle"&&this.callbacks.onSessionIdle(this.sessionId);return}this.eventQueue.push({name:t,data:n}),this.scheduleFlush()}}activate(){this.active=!0,this.clearIdleTimer()}deactivate(){this.active=!1,this.resetIdleTimer()}refreshOnIdle(){Me.getState().refreshSessionData(this.repoId,this.sessionId)}stop(){this.alive=!1,this.flush(),this.clearIdleTimer(),this.cancelFlush()}scheduleFlush(){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.flush()},$q))}cancelFlush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null)}bufferDelta(t){const n=wM(t);if(!n)return;const r=this.deltaBuffer.get(n.partId);r?r.text+=n.delta:this.deltaBuffer.set(n.partId,{messageId:n.messageId,text:n.delta})}flush(){if(this.eventQueue.length===0&&this.deltaBuffer.size===0)return;const t=Me.getState(),n=this.eventQueue;this.eventQueue=[];for(const r of n)HA(r.name,r.data,this.sessionId,t);if(this.deltaBuffer.size>0){const r=this.deltaBuffer;this.deltaBuffer=new Map;for(const[a,{messageId:i,text:o}]of r)vs.tick("delta"),vs.tick("store"),t.appendMessagePartDelta(this.sessionId,i,a,o)}}resetIdleTimer(){this.clearIdleTimer(),!this.active&&(this.idleTimer=setTimeout(()=>{this.callbacks.onWorkerIdle(this.sessionId)},Hq))}clearIdleTimer(){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null)}}class qq{constructor(){pt(this,"workers",new Map);pt(this,"dispatcher",null);pt(this,"supervisor",null);pt(this,"visibilityHandler",null);pt(this,"repoId",null)}start(t){this.stop(),this.repoId=t;const n={onWorkerIdle:r=>this.removeWorker(r),onSessionIdle:r=>{var a;(a=this.workers.get(r))==null||a.refreshOnIdle()}};this.dispatcher=new Uq(t,(r,a,i)=>{this.ensureWorker(r,t,n).dispatch(a,i)}),this.dispatcher.start(),this.supervisor=new zq(t,{ensureWorker:r=>this.ensureWorker(r,t,n)}),this.supervisor.start(),this.visibilityHandler=()=>{var r,a;document.hidden?(r=this.supervisor)==null||r.pause():(a=this.supervisor)==null||a.resume()},document.addEventListener("visibilitychange",this.visibilityHandler)}stop(){var t,n;(t=this.dispatcher)==null||t.stop(),this.dispatcher=null,(n=this.supervisor)==null||n.stop(),this.supervisor=null;for(const r of this.workers.values())r.stop();this.workers.clear(),this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null)}activateSession(t){if(!this.repoId||!t)return;const n=this.repoId;for(const i of this.workers.values())i.sessionId!==t&&i.deactivate();const r={onWorkerIdle:i=>this.removeWorker(i),onSessionIdle:i=>{var o;return(o=this.workers.get(i))==null?void 0:o.refreshOnIdle()}};this.ensureWorker(t,n,r).activate(),Me.getState().refreshSessionData(n,t)}deactivateSession(t){var n;(n=this.workers.get(t))==null||n.deactivate()}ensureWorker(t,n,r){let a=this.workers.get(t);return a||(a=new Yq(t,n,r),this.workers.set(t,a),vs.setGauge("workers",this.workers.size)),a}removeWorker(t){const n=Me.getState().activeSessionId;if(t===n)return;const r=this.workers.get(t);r&&(r.stop(),this.workers.delete(t),vs.setGauge("workers",this.workers.size))}}const Vp=new qq;function oh({onConfirm:e,size:t="sm",variant:n="ghost",triggerClassName:r,stopPropagation:a,title:i="删除",children:o}){const[u,d]=y.useState(!1),f=t==="sm"?"h-3.5 w-3.5":"h-4 w-4",m=t==="sm"?"p-1":"p-1.5",p=n==="outlined"?"rounded-md":"rounded",b=t==="sm"?"gap-0.5":"gap-1",x=a?E=>E.stopPropagation():void 0;return u?c.jsxs("div",{className:ie("flex items-center",b),onClick:x,children:[c.jsx("button",{type:"button",onClick:()=>{e(),d(!1)},className:ie(p,m,"text-red-400 hover:bg-red-500/10",n==="outlined"&&"border border-red-500/30"),children:c.jsx(fi,{className:f})}),c.jsx("button",{type:"button",onClick:()=>d(!1),className:ie(p,m,"text-fg-4 hover:bg-elevated",n==="outlined"&&"border border-line"),children:c.jsx(At,{className:f})})]}):c.jsxs(c.Fragment,{children:[o,c.jsx("button",{type:"button",onClick:E=>{x==null||x(E),d(!0)},title:i,className:ie(p,m,r??"text-fg-5 hover:text-red-400",n==="outlined"&&"border border-line transition-colors hover:border-red-500/30"),children:c.jsx(a0,{className:f})})]})}function Gq(e,t){if(e instanceof Li)try{const n=JSON.parse(e.message);if(n.error)return n.error}catch{if(e.message)return e.message}return e instanceof Error?e.message:t}function lc(e,t,n){const{initialData:r,showErrorToast:a=!0,errorMessage:i="加载失败",skip:o=!1}=n??{},[u,d]=y.useState(r??null),[f,m]=y.useState(!o),[p,b]=y.useState(null),x=y.useRef(0),E=y.useRef(e);E.current=e;const N=y.useRef(i);N.current=i;const _=y.useRef(a);_.current=a;const S=y.useCallback(async()=>{const C=++x.current;m(!0),b(null);try{const A=await E.current();if(x.current!==C)return;d(A)}catch(A){if(x.current!==C)return;const I=Gq(A,N.current);b(I),_.current&&ar.getState().addToast(I,"error")}x.current===C&&m(!1)},[]);return y.useEffect(()=>{if(o){m(!1);return}return S(),()=>{x.current++}},[...t,o,S]),{data:u,loading:f,error:p,reload:S}}const Kq=["Sisyphus - ultraworker","Prometheus - Plan Builder","Atlas - Plan Executor"],Vq="pinned_models",il="__system_prompt__",$A=[{bg:"bg-blue-500/10",text:"text-blue-400"},{bg:"bg-amber-500/10",text:"text-amber-400"},{bg:"bg-green-500/10",text:"text-green-400"},{bg:"bg-purple-500/10",text:"text-purple-400"},{bg:"bg-cyan-500/10",text:"text-cyan-400"},{bg:"bg-rose-500/10",text:"text-rose-400"},{bg:"bg-indigo-500/10",text:"text-indigo-400"},{bg:"bg-orange-500/10",text:"text-orange-400"}],Wq={bg:"bg-elevated",text:"text-fg-4"};function _M(e){if(e==="general")return Wq;let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return $A[Math.abs(t)%$A.length]}function uc(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"刚刚";if(n<60)return`${n} 分钟前`;const r=Math.floor(n/60);if(r<24)return`${r} 小时前`;const a=Math.floor(r/24);return a<30?`${a} 天前`:`${Math.floor(a/30)} 个月前`}const TM={create:{label:"首次提取",color:"text-green-400"},update:{label:"重写",color:"text-blue-400"},merge:{label:"合并",color:"text-purple-400"},decay:{label:"衰减",color:"text-amber-400"},reinforce:{label:"强化",color:"text-emerald-400"},manual:{label:"手动编辑",color:"text-fg-3"}};function Xq({memory:e,onClose:t}){const n=[...e.history??[]].reverse();return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:c.jsxs("div",{className:"mx-4 max-h-[80vh] w-full max-w-lg overflow-y-auto rounded-xl border border-line bg-surface p-5 shadow-xl",onClick:r=>r.stopPropagation(),children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("h3",{className:"text-sm font-semibold text-fg",children:["版本历史 (",n.length+1," 个版本)"]}),c.jsx("button",{type:"button",onClick:t,className:"rounded p-1 text-fg-4 hover:text-fg-3",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"rounded-lg border border-blue-500/20 bg-blue-500/5 p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[10px]",children:[c.jsx("span",{className:"font-medium text-blue-400",children:"当前版本"}),c.jsx("span",{className:"text-fg-5",children:uc(e.updatedAt)}),c.jsxs("span",{className:"text-fg-6",children:["⚡ ",e.importance.toFixed(2)]})]}),c.jsx("p",{className:"text-xs leading-relaxed text-fg",children:e.content})]}),n.map((r,a)=>{const i=TM[r.action]??{label:r.action,color:"text-fg-4"};return c.jsxs("div",{className:"rounded-lg border border-line bg-base p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[10px]",children:[c.jsx("span",{className:ie("font-medium",i.color),children:i.label}),c.jsx("span",{className:"text-fg-5",children:uc(r.ts)}),c.jsxs("span",{className:"text-fg-6",children:["⚡ ",r.importance.toFixed(2)]}),r.source&&c.jsxs("span",{className:"text-fg-6",children:["· ",r.source]})]}),c.jsx("p",{className:"text-xs leading-relaxed text-fg-4",children:r.content})]},a)}),n.length===0&&c.jsx("div",{className:"py-4 text-center text-xs text-fg-5",children:"暂无历史版本"})]})]})})}function YA({memory:e,categories:t,onUpdate:n,onDelete:r}){var C;const[a,i]=y.useState(!1),[o,u]=y.useState(e.content),[d,f]=y.useState(e.category),[m,p]=y.useState(!1),[b,x]=y.useState(!1),E=_M(e.category),N=(C=e.history)==null?void 0:C[e.history.length-1],_=N&&Math.abs(N.importance-e.importance)>.001,S=async()=>{p(!0);try{await n(e.id,{content:o,category:d}),i(!1)}finally{p(!1)}};return a?c.jsxs("div",{className:"rounded-lg border border-blue-500/30 bg-blue-500/5 p-3 space-y-2",children:[c.jsx("textarea",{value:o,onChange:A=>u(A.target.value),rows:3,className:"w-full resize-y rounded-md border border-line bg-surface px-3 py-2 font-mono text-xs leading-relaxed text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("select",{value:d,onChange:A=>f(A.target.value),className:"rounded-md border border-line bg-surface px-2 py-1 text-xs text-fg focus:border-blue-500 focus:outline-none",children:t.map(A=>c.jsx("option",{value:A,children:A},A))}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:()=>{i(!1),u(e.content),f(e.category)},className:"rounded-md px-3 py-1 text-xs text-fg-4 hover:bg-elevated",children:"取消"}),c.jsx("button",{type:"button",onClick:()=>void S(),disabled:m||!o.trim(),className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white hover:bg-blue-500 disabled:opacity-40",children:m?"保存中…":"保存"})]})]}):c.jsxs("div",{className:"group/mem rounded-lg border border-line bg-base px-3 py-2.5",children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx("span",{className:ie("mt-0.5 shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",E.bg,E.text),children:e.category}),c.jsx("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-fg",children:e.content})]}),c.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-[11px] text-fg-5",children:[c.jsxs("span",{className:"flex items-center gap-0.5",children:[c.jsx(Cc,{className:"h-3 w-3"}),_&&N?`${N.importance.toFixed(2)}→${e.importance.toFixed(2)}`:e.importance.toFixed(2)]}),c.jsx("span",{children:"·"}),c.jsx("span",{children:uc(e.updatedAt)}),e.supersededBy&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsx("span",{className:"text-amber-400",children:e.supersededBy==="user-deleted"?"已删除":e.supersededBy==="consolidated-out"?"已整理":"已合并"})]}),e.history&&e.history.length>0&&(()=>{const A=e.history[e.history.length-1],I=TM[A.action];return c.jsxs("button",{type:"button",onClick:()=>x(!0),"data-guide":e.id==="guide-mem-1"?"agent-memory-version":void 0,className:ie("rounded px-1.5 py-0.5 text-[10px] font-medium transition-opacity hover:opacity-80",A.action==="update"?"bg-blue-500/10 text-blue-400":A.action==="merge"?"bg-purple-500/10 text-purple-400":A.action==="decay"?"bg-amber-500/10 text-amber-400":A.action==="reinforce"?"bg-emerald-500/10 text-emerald-400":A.action==="manual"?"bg-fg/10 text-fg-3":"bg-green-500/10 text-green-400"),children:[(I==null?void 0:I.label)??A.action," · ",e.history.length,"版"]})})(),c.jsx("div",{className:"flex-1"}),!e.supersededBy&&c.jsx("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover/mem:opacity-100",children:c.jsx(oh,{onConfirm:()=>void r(e.id),children:c.jsx("button",{type:"button",onClick:()=>i(!0),className:"rounded p-1 text-fg-5 hover:text-fg-3",children:c.jsx(jE,{className:"h-3.5 w-3.5"})})})})]}),b&&c.jsx(Xq,{memory:e,onClose:()=>x(!1)})]})}const Qq=14400*1e3;function Zq(e){if(!e)return"下次:待定";const t=e+Qq,n=Date.now();if(t<=n)return"下次:即将运行";const r=t-n,a=Math.floor(r/6e4);if(a<60)return`下次:约 ${a} 分钟后`;const i=Math.floor(a/60);return i<24?`下次:约 ${i} 小时后`:`下次:约 ${Math.floor(i/24)} 天后`}function Jq({stats:e,running:t,onTrigger:n}){if(!e)return null;const r=e.lastActions;return c.jsxs("div",{className:"rounded-lg bg-elevated px-3 py-2 text-[11px] tabular-nums text-fg-5",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[c.jsx("span",{children:e.lastConsolidatedAt?`上次整理:${uc(e.lastConsolidatedAt)}`:"尚未整理"}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{children:Zq(e.lastConsolidatedAt)}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:n,disabled:t,className:"rounded px-2 py-0.5 text-[10px] font-medium text-fg-4 transition-colors hover:bg-surface hover:text-fg-3 disabled:opacity-40",children:t?"整理中…":"立即整理"})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1",children:[r&&c.jsxs(c.Fragment,{children:[c.jsxs("span",{children:[r.update," 更新 ",r.merge," 合并 ",r.delete," 清理 ",r.decayed," 降权"]}),c.jsx("span",{className:"text-fg-6",children:"·"})]}),c.jsxs("span",{children:["活跃 ",e.totalActive," 条"]}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsxs("span",{children:["衰减中 ",e.stale]})]})]})}function eG({agentId:e}){const t=e.startsWith(gM),[n,r]=y.useState(null),[a,i]=y.useState(!1),[o,u]=y.useState(!1),[d,f]=y.useState(new Set),[m,p]=y.useState(!1),[b,x]=y.useState(null),[E,N]=y.useState(null),[_,S]=y.useState(!1),{data:C,loading:A,reload:I}=lc(()=>t?Promise.resolve(WY):rM(e,{includeSuperseded:a}),[e,a,t],{showErrorToast:!t,errorMessage:"加载记忆失败"}),O=C??[],k=y.useCallback(()=>{t||dA(e).then(N).catch(()=>N(null))},[e,t]);y.useEffect(()=>{k()},[k]);const j=async()=>{S(!0);try{await U$(e)}catch{S(!1);return}const D=setInterval(()=>{dA(e).then(z=>{N(z),z.lastConsolidatedAt&&(!(E!=null&&E.lastConsolidatedAt)||z.lastConsolidatedAt>E.lastConsolidatedAt)&&(clearInterval(D),S(!1),I())}).catch(()=>{})},5e3);setTimeout(()=>{clearInterval(D),S(!1)},3e5)},{data:F,loading:P}=lc(()=>BE(e),[e,o],{skip:!o,errorMessage:"加载 Session 列表失败"}),L=F??[],B=O.filter(D=>!D.supersededBy),Y=n?B.filter(D=>D.category===n):B,re=O.filter(D=>D.supersededBy),X=y.useMemo(()=>new Set(O.map(D=>D.sessionId).filter(Boolean)),[O]),K=async(D,z)=>{await L$(e,D,z),await I()},V=async D=>{await P$(e,D),await I()},H=D=>{f(z=>{const $=new Set(z);return $.has(D)?$.delete(D):$.add(D),$})},G=async()=>{if(d.size!==0){p(!0),x(null);try{const $=(await B$(e,[...d])).results;if($){const M=$.filter(oe=>oe.status==="ok"),le=$.filter(oe=>oe.status!=="ok");M.length>0&&x(`提取成功 ${M.reduce((oe,ne)=>oe+(ne.actions??0),0)} 条记忆`),le.length>0&&x(oe=>(oe?`${oe};`:"")+le.map(ne=>ne.error??ne.status).join(";")),M.length>0&&await I()}f(new Set)}catch(D){x(`请求失败: ${D instanceof Error?D.message:String(D)}`)}p(!1)}},Q=y.useMemo(()=>[...new Set(B.map(z=>z.category))].sort(),[B]);return c.jsxs("section",{"data-guide":"agent-memory-section",className:"rounded-xl border border-line bg-surface p-5 space-y-4",children:[c.jsx("div",{className:"flex items-center justify-between",children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(oc,{className:"h-4 w-4 text-purple-400"}),c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"记忆"}),!A&&c.jsx("span",{className:"rounded-full bg-elevated px-1.5 py-0.5 text-[10px] tabular-nums text-fg-4",children:Y.length})]})}),c.jsx(Jq,{stats:E,running:_,onTrigger:()=>void j()}),c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[c.jsx("button",{type:"button",onClick:()=>r(null),className:ie("rounded-full px-2.5 py-0.5 text-[11px] font-medium transition-colors",n===null?"bg-fg/10 text-fg":"text-fg-4 hover:text-fg-3"),children:"全部"}),Q.map(D=>{const z=_M(D);return c.jsx("button",{type:"button",onClick:()=>r(n===D?null:D),className:ie("rounded-full px-2.5 py-0.5 text-[11px] font-medium transition-colors",n===D?ie(z.bg,z.text):"text-fg-4 hover:text-fg-3"),children:D},D)})]}),A?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):Y.length===0&&re.length===0?c.jsx("div",{className:"py-8 text-center text-xs text-fg-5",children:"暂无记忆。使用此 Agent 完成 Session 后将自动提取。"}):c.jsxs("div",{className:"space-y-1.5",children:[Y.map(D=>c.jsx(YA,{memory:D,categories:Q,onUpdate:K,onDelete:V},D.id)),re.length>0&&c.jsxs("div",{className:"pt-1",children:[c.jsxs("button",{type:"button",onClick:()=>i(!a),className:"flex items-center gap-1 text-[11px] text-fg-5 hover:text-fg-3",children:[c.jsx("span",{children:a?"▾":"▸"}),"已合并/已删除 (",re.length,")"]}),a&&c.jsx("div",{className:"mt-1.5 space-y-1.5 opacity-60",children:re.map(D=>c.jsx(YA,{memory:D,categories:Q,onUpdate:K,onDelete:V},D.id))})]})]}),c.jsxs("div",{className:"border-t border-line pt-3",children:[c.jsxs("button",{type:"button",onClick:()=>u(!o),className:"flex items-center gap-1.5 text-xs font-medium text-fg-4 hover:text-fg-3",children:[c.jsx(n0,{className:"h-3.5 w-3.5"}),c.jsxs("span",{children:[o?"▾":"▸"," 从 Session 提取记忆"]})]}),o&&c.jsx("div",{className:"mt-2 space-y-1.5",children:P?c.jsx("div",{className:"flex items-center justify-center py-4",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):L.length===0?c.jsx("p",{className:"py-4 text-center text-xs text-fg-5",children:"暂无 Session 记录。"}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"max-h-64 space-y-1 overflow-y-auto",children:L.map(D=>{const z=X.has(D.id);return c.jsxs("label",{className:ie("flex cursor-pointer items-center gap-2.5 rounded-md border px-3 py-2 transition-colors",d.has(D.id)?"border-purple-500/30 bg-purple-500/5":"border-line bg-base hover:bg-elevated/60"),children:[c.jsx("input",{type:"checkbox",checked:d.has(D.id),onChange:()=>H(D.id),className:"h-3.5 w-3.5 shrink-0 cursor-pointer rounded border-line accent-purple-500"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"block truncate text-xs text-fg",children:D.title||D.id.slice(-8)}),c.jsx("span",{className:"text-[11px] text-fg-5",children:uc(D.timeCreated)})]}),c.jsx("span",{className:ie("shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium",z?"bg-green-500/10 text-green-400":"bg-elevated text-fg-5"),children:z?"已提取":"未提取"})]},D.id)})}),d.size>0&&c.jsxs("button",{type:"button",onClick:()=>void G(),disabled:m,className:"flex w-full items-center justify-center gap-1.5 rounded-lg bg-purple-600 py-2 text-xs font-medium text-white transition-colors hover:bg-purple-500 disabled:opacity-40",children:[m?c.jsx(nn,{className:"h-3.5 w-3.5 fs-spin"}):c.jsx(oc,{className:"h-3.5 w-3.5"}),m?"提取中…":`提取选中 Session 的记忆 (${d.size})`]}),b&&c.jsx("p",{className:ie("mt-1.5 rounded-md px-3 py-1.5 text-xs",b.includes("成功")?"bg-green-500/10 text-green-400":"bg-red-500/10 text-red-400"),children:b})]})})]})]})}function tG({agentId:e}){const{data:t,loading:n}=lc(()=>BE(e),[e],{errorMessage:"加载 Session 历史失败"}),r=t??[];return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(n0,{className:"h-4 w-4 text-fg-4"}),c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Session 历史"}),!n&&c.jsx("span",{className:"rounded-full bg-elevated px-1.5 py-0.5 text-[10px] tabular-nums text-fg-4",children:r.length})]}),c.jsx("div",{className:"mt-3",children:n?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):r.length===0?c.jsx("p",{className:"py-8 text-center text-xs text-fg-5",children:"暂无 Session 记录。"}):c.jsx("div",{className:"space-y-1",children:r.map(a=>c.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-line bg-base px-4 py-2.5",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"block truncate text-xs font-medium text-fg",children:a.title||a.id.slice(-8)}),c.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-fg-5",children:[c.jsx("span",{children:uc(a.timeCreated)}),a.cost>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsxs("span",{children:["$",a.cost.toFixed(4)]})]}),(a.tokensInput>0||a.tokensOutput>0)&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsxs("span",{children:[Math.round((a.tokensInput+a.tokensOutput)/1e3),"K tokens"]})]})]})]}),a.completedAt?c.jsx("span",{className:"shrink-0 rounded-full bg-green-500/10 px-2 py-0.5 text-[10px] font-medium text-green-400",children:"完成"}):c.jsx("span",{className:"shrink-0 rounded-full bg-elevated px-2 py-0.5 text-[10px] font-medium text-fg-5",children:"进行中"})]},a.id))})})]})}function nG({agent:e,fragments:t,onSave:n}){const r=We(Q=>Q.activeRepoId),[a,i]=y.useState(!1),[o,u]=y.useState(e.name),[d,f]=y.useState(e.description??""),[m,p]=y.useState(e.baseAgent),[b,x]=y.useState(e.model??""),[E,N]=y.useState(e.variant??""),[_,S]=y.useState(e.memoryModel??""),[C,A]=y.useState(e.systemPrompt),[I,O]=y.useState(!1),[k,j]=y.useState(!1),[F,P]=y.useState([]);y.useEffect(()=>{if(!r){P([]);return}let Q=!1;return(async()=>{try{const[D,z]=await Promise.all([Ml(),kc(r)]);if(Q)return;const $=D[Vq],M=$?JSON.parse($):[],le=M.length>0?z.filter(oe=>M.includes(oe.id)):z;P(le.length>0?le:z)}catch{Q||P([])}})(),()=>{Q=!0}},[r]);const[L,B]=y.useState(()=>{const Q=e.fragments.map(M=>M.id),D=e.systemPromptPosition??-1,z=D>=0&&D<=Q.length?D:Q.length,$=[...Q];return $.splice(z,0,il),$}),Y=Q=>{B(D=>{if(D.includes(Q))return D.filter(M=>M!==Q);const z=D.indexOf(il),$=[...D];return $.splice(z>=0?z:$.length,0,Q),$})},re=(Q,D)=>{const z=Q+D;z<0||z>=L.length||B($=>{const M=[...$];return[M[Q],M[z]]=[M[z],M[Q]],M})},X=L.filter(Q=>Q!==il),K=(()=>{const Q=L.indexOf(il);return Q<0?-1:L.slice(0,Q).filter(D=>D!==il).length})(),V=L.map(Q=>{var D;return Q===il?C:(D=t.find(z=>z.id===Q))==null?void 0:D.content}).filter(Boolean).join(`
524
524
 
525
525
  ---
526
526
 
@@ -649,7 +649,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
649
649
  `,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:b,table:o,tableCell:d,tableRow:u}};function o(x,E,N,_){return f(m(x,N,_),x.align)}function u(x,E,N,_){const S=p(x,N,_),C=f([S]);return C.slice(0,C.indexOf(`
650
650
  `))}function d(x,E,N,_){const S=N.enter("tableCell"),C=N.enter("phrasing"),A=N.containerPhrasing(x,{..._,before:i,after:i});return C(),S(),A}function f(x,E){return Gve(x,{align:E,alignDelimiters:r,padding:n,stringLength:a})}function m(x,E,N){const _=x.children;let S=-1;const C=[],A=E.enter("table");for(;++S<_.length;)C[S]=p(_[S],E,N);return A(),C}function p(x,E,N){const _=x.children;let S=-1;const C=[],A=E.enter("tableRow");for(;++S<_.length;)C[S]=d(_[S],x,E,N);return A(),C}function b(x,E,N){let _=U8.inlineCode(x,E,N);return N.stack.includes("tableCell")&&(_=_.replace(/\|/g,"\\$&")),_}}function M1e(){return{exit:{taskListCheckValueChecked:xI,taskListCheckValueUnchecked:xI,paragraph:j1e}}}function D1e(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:L1e}}}function xI(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function j1e(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const a=t.children;let i=-1,o;for(;++i<a.length;){const u=a[i];if(u.type==="paragraph"){o=u;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function L1e(e,t,n,r){const a=e.children[0],i=typeof e.checked=="boolean"&&a&&a.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",u=n.createTracker(r);i&&u.move(o);let d=U8.listItem(e,t,n,{...r,...u.current()});return i&&(d=d.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,f)),d;function f(m){return m+o}}function P1e(){return[pve(),Lve(),Fve(),T1e(),M1e()]}function B1e(e){return{extensions:[gve(),Pve(e),zve(),R1e(e),D1e()]}}const U1e={tokenize:q1e,partial:!0},F8={tokenize:G1e,partial:!0},z8={tokenize:K1e,partial:!0},H8={tokenize:V1e,partial:!0},F1e={tokenize:W1e,partial:!0},$8={name:"wwwAutolink",tokenize:$1e,previous:q8},Y8={name:"protocolAutolink",tokenize:Y1e,previous:G8},Bs={name:"emailAutolink",tokenize:H1e,previous:K8},qi={};function z1e(){return{text:qi}}let dl=48;for(;dl<123;)qi[dl]=Bs,dl++,dl===58?dl=65:dl===91&&(dl=97);qi[43]=Bs;qi[45]=Bs;qi[46]=Bs;qi[95]=Bs;qi[72]=[Bs,Y8];qi[104]=[Bs,Y8];qi[87]=[Bs,$8];qi[119]=[Bs,$8];function H1e(e,t,n){const r=this;let a,i;return o;function o(p){return!cE(p)||!K8.call(r,r.previous)||aw(r.events)?n(p):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),u(p))}function u(p){return cE(p)?(e.consume(p),u):p===64?(e.consume(p),d):n(p)}function d(p){return p===46?e.check(F1e,m,f)(p):p===45||p===95||Or(p)?(i=!0,e.consume(p),d):m(p)}function f(p){return e.consume(p),a=!0,d}function m(p){return i&&a&&Hr(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(p)):n(p)}}function $1e(e,t,n){const r=this;return a;function a(o){return o!==87&&o!==119||!q8.call(r,r.previous)||aw(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(U1e,e.attempt(F8,e.attempt(z8,i),n),n)(o))}function i(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function Y1e(e,t,n){const r=this;let a="",i=!1;return o;function o(p){return(p===72||p===104)&&G8.call(r,r.previous)&&!aw(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),a+=String.fromCodePoint(p),e.consume(p),u):n(p)}function u(p){if(Hr(p)&&a.length<5)return a+=String.fromCodePoint(p),e.consume(p),u;if(p===58){const b=a.toLowerCase();if(b==="http"||b==="https")return e.consume(p),d}return n(p)}function d(p){return p===47?(e.consume(p),i?f:(i=!0,d)):n(p)}function f(p){return p===null||Hg(p)||Jt(p)||Hl(p)||tb(p)?n(p):e.attempt(F8,e.attempt(z8,m),n)(p)}function m(p){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(p)}}function q1e(e,t,n){let r=0;return a;function a(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),a):o===46&&r===3?(e.consume(o),i):n(o)}function i(o){return o===null?n(o):t(o)}}function G1e(e,t,n){let r,a,i;return o;function o(f){return f===46||f===95?e.check(H8,d,u)(f):f===null||Jt(f)||Hl(f)||f!==45&&tb(f)?d(f):(i=!0,e.consume(f),o)}function u(f){return f===95?r=!0:(a=r,r=void 0),e.consume(f),o}function d(f){return a||r||!i?n(f):t(f)}}function K1e(e,t){let n=0,r=0;return a;function a(o){return o===40?(n++,e.consume(o),a):o===41&&r<n?i(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(H8,t,i)(o):o===null||Jt(o)||Hl(o)?t(o):(e.consume(o),a)}function i(o){return o===41&&r++,e.consume(o),a}}function V1e(e,t,n){return r;function r(u){return u===33||u===34||u===39||u===41||u===42||u===44||u===46||u===58||u===59||u===63||u===95||u===126?(e.consume(u),r):u===38?(e.consume(u),i):u===93?(e.consume(u),a):u===60||u===null||Jt(u)||Hl(u)?t(u):n(u)}function a(u){return u===null||u===40||u===91||Jt(u)||Hl(u)?t(u):r(u)}function i(u){return Hr(u)?o(u):n(u)}function o(u){return u===59?(e.consume(u),r):Hr(u)?(e.consume(u),o):n(u)}}function W1e(e,t,n){return r;function r(i){return e.consume(i),a}function a(i){return Or(i)?n(i):t(i)}}function q8(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Jt(e)}function G8(e){return!Hr(e)}function K8(e){return!(e===47||cE(e))}function cE(e){return e===43||e===45||e===46||e===95||Or(e)}function aw(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const X1e={tokenize:aEe,partial:!0};function Q1e(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:tEe,continuation:{tokenize:nEe},exit:rEe}},text:{91:{name:"gfmFootnoteCall",tokenize:eEe},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Z1e,resolveTo:J1e}}}}function Z1e(e,t,n){const r=this;let a=r.events.length;const i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;a--;){const d=r.events[a][1];if(d.type==="labelImage"){o=d;break}if(d.type==="gfmFootnoteCall"||d.type==="labelLink"||d.type==="label"||d.type==="image"||d.type==="link")break}return u;function u(d){if(!o||!o._balanced)return n(d);const f=di(r.sliceSerialize({start:o.end,end:r.now()}));return f.codePointAt(0)!==94||!i.includes(f.slice(1))?n(d):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),t(d))}}function J1e(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},a={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};a.end.column++,a.end.offset++,a.end._bufferIndex++;const i={type:"gfmFootnoteCallString",start:Object.assign({},a.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},i.start),end:Object.assign({},i.end)},u=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",a,t],["exit",a,t],["enter",i,t],["enter",o,t],["exit",o,t],["exit",i,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...u),e}function eEe(e,t,n){const r=this,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i=0,o;return u;function u(p){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),d}function d(p){return p!==94?n(p):(e.enter("gfmFootnoteCallMarker"),e.consume(p),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",f)}function f(p){if(i>999||p===93&&!o||p===null||p===91||Jt(p))return n(p);if(p===93){e.exit("chunkString");const b=e.exit("gfmFootnoteCallString");return a.includes(di(r.sliceSerialize(b)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(p)}return Jt(p)||(o=!0),i++,e.consume(p),p===92?m:f}function m(p){return p===91||p===92||p===93?(e.consume(p),i++,f):f(p)}}function tEe(e,t,n){const r=this,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i,o=0,u;return d;function d(E){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(E),e.exit("gfmFootnoteDefinitionLabelMarker"),f}function f(E){return E===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(E),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",m):n(E)}function m(E){if(o>999||E===93&&!u||E===null||E===91||Jt(E))return n(E);if(E===93){e.exit("chunkString");const N=e.exit("gfmFootnoteDefinitionLabelString");return i=di(r.sliceSerialize(N)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(E),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),b}return Jt(E)||(u=!0),o++,e.consume(E),E===92?p:m}function p(E){return E===91||E===92||E===93?(e.consume(E),o++,m):m(E)}function b(E){return E===58?(e.enter("definitionMarker"),e.consume(E),e.exit("definitionMarker"),a.includes(i)||a.push(i),Tt(e,x,"gfmFootnoteDefinitionWhitespace")):n(E)}function x(E){return t(E)}}function nEe(e,t,n){return e.check(Oh,t,e.attempt(X1e,t,n))}function rEe(e){e.exit("gfmFootnoteDefinition")}function aEe(e,t,n){const r=this;return Tt(e,a,"gfmFootnoteDefinitionIndent",5);function a(i){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(i):n(i)}}function iEe(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:i,resolveAll:a};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function a(o,u){let d=-1;for(;++d<o.length;)if(o[d][0]==="enter"&&o[d][1].type==="strikethroughSequenceTemporary"&&o[d][1]._close){let f=d;for(;f--;)if(o[f][0]==="exit"&&o[f][1].type==="strikethroughSequenceTemporary"&&o[f][1]._open&&o[d][1].end.offset-o[d][1].start.offset===o[f][1].end.offset-o[f][1].start.offset){o[d][1].type="strikethroughSequence",o[f][1].type="strikethroughSequence";const m={type:"strikethrough",start:Object.assign({},o[f][1].start),end:Object.assign({},o[d][1].end)},p={type:"strikethroughText",start:Object.assign({},o[f][1].end),end:Object.assign({},o[d][1].start)},b=[["enter",m,u],["enter",o[f][1],u],["exit",o[f][1],u],["enter",p,u]],x=u.parser.constructs.insideSpan.null;x&&Ca(b,b.length,0,nb(x,o.slice(f+1,d),u)),Ca(b,b.length,0,[["exit",p,u],["enter",o[d][1],u],["exit",o[d][1],u],["exit",m,u]]),Ca(o,f-1,d-f+3,b),d=f+b.length-2;break}}for(d=-1;++d<o.length;)o[d][1].type==="strikethroughSequenceTemporary"&&(o[d][1].type="data");return o}function i(o,u,d){const f=this.previous,m=this.events;let p=0;return b;function b(E){return f===126&&m[m.length-1][1].type!=="characterEscape"?d(E):(o.enter("strikethroughSequenceTemporary"),x(E))}function x(E){const N=vc(f);if(E===126)return p>1?d(E):(o.consume(E),p++,x);if(p<2&&!n)return d(E);const _=o.exit("strikethroughSequenceTemporary"),S=vc(E);return _._open=!S||S===2&&!!N,_._close=!N||N===2&&!!S,u(E)}}}class sEe{constructor(){this.map=[]}add(t,n,r){oEe(this,t,n,r)}consume(t){if(this.map.sort(function(i,o){return i[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let a=r.pop();for(;a;){for(const i of a)t.push(i);a=r.pop()}this.map.length=0}}function oEe(e,t,n,r){let a=0;if(!(n===0&&r.length===0)){for(;a<e.map.length;){if(e.map[a][0]===t){e.map[a][1]+=n,e.map[a][2].push(...r);return}a+=1}e.map.push([t,n,r])}}function lEe(e,t){let n=!1;const r=[];for(;t<e.length;){const a=e[t];if(n){if(a[0]==="enter")a[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(a[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const i=r.length-1;r[i]=r[i]==="left"?"center":"right"}}else if(a[1].type==="tableDelimiterRow")break}else a[0]==="enter"&&a[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function uEe(){return{flow:{null:{name:"table",tokenize:cEe,resolveAll:dEe}}}}function cEe(e,t,n){const r=this;let a=0,i=0,o;return u;function u(L){let B=r.events.length-1;for(;B>-1;){const X=r.events[B][1].type;if(X==="lineEnding"||X==="linePrefix")B--;else break}const Y=B>-1?r.events[B][1].type:null,re=Y==="tableHead"||Y==="tableRow"?k:d;return re===k&&r.parser.lazy[r.now().line]?n(L):re(L)}function d(L){return e.enter("tableHead"),e.enter("tableRow"),f(L)}function f(L){return L===124||(o=!0,i+=1),m(L)}function m(L){return L===null?n(L):et(L)?i>1?(i=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(L),e.exit("lineEnding"),x):n(L):gt(L)?Tt(e,m,"whitespace")(L):(i+=1,o&&(o=!1,a+=1),L===124?(e.enter("tableCellDivider"),e.consume(L),e.exit("tableCellDivider"),o=!0,m):(e.enter("data"),p(L)))}function p(L){return L===null||L===124||Jt(L)?(e.exit("data"),m(L)):(e.consume(L),L===92?b:p)}function b(L){return L===92||L===124?(e.consume(L),p):p(L)}function x(L){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(L):(e.enter("tableDelimiterRow"),o=!1,gt(L)?Tt(e,E,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(L):E(L))}function E(L){return L===45||L===58?_(L):L===124?(o=!0,e.enter("tableCellDivider"),e.consume(L),e.exit("tableCellDivider"),N):O(L)}function N(L){return gt(L)?Tt(e,_,"whitespace")(L):_(L)}function _(L){return L===58?(i+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(L),e.exit("tableDelimiterMarker"),S):L===45?(i+=1,S(L)):L===null||et(L)?I(L):O(L)}function S(L){return L===45?(e.enter("tableDelimiterFiller"),C(L)):O(L)}function C(L){return L===45?(e.consume(L),C):L===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(L),e.exit("tableDelimiterMarker"),A):(e.exit("tableDelimiterFiller"),A(L))}function A(L){return gt(L)?Tt(e,I,"whitespace")(L):I(L)}function I(L){return L===124?E(L):L===null||et(L)?!o||a!==i?O(L):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(L)):O(L)}function O(L){return n(L)}function k(L){return e.enter("tableRow"),j(L)}function j(L){return L===124?(e.enter("tableCellDivider"),e.consume(L),e.exit("tableCellDivider"),j):L===null||et(L)?(e.exit("tableRow"),t(L)):gt(L)?Tt(e,j,"whitespace")(L):(e.enter("data"),F(L))}function F(L){return L===null||L===124||Jt(L)?(e.exit("data"),j(L)):(e.consume(L),L===92?P:F)}function P(L){return L===92||L===124?(e.consume(L),F):F(L)}}function dEe(e,t){let n=-1,r=!0,a=0,i=[0,0,0,0],o=[0,0,0,0],u=!1,d=0,f,m,p;const b=new sEe;for(;++n<e.length;){const x=e[n],E=x[1];x[0]==="enter"?E.type==="tableHead"?(u=!1,d!==0&&(yI(b,t,d,f,m),m=void 0,d=0),f={type:"table",start:Object.assign({},E.start),end:Object.assign({},E.end)},b.add(n,0,[["enter",f,t]])):E.type==="tableRow"||E.type==="tableDelimiterRow"?(r=!0,p=void 0,i=[0,0,0,0],o=[0,n+1,0,0],u&&(u=!1,m={type:"tableBody",start:Object.assign({},E.start),end:Object.assign({},E.end)},b.add(n,0,[["enter",m,t]])),a=E.type==="tableDelimiterRow"?2:m?3:1):a&&(E.type==="data"||E.type==="tableDelimiterMarker"||E.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(i[1]!==0&&(o[0]=o[1],p=Np(b,t,i,a,void 0,p),i=[0,0,0,0]),o[2]=n)):E.type==="tableCellDivider"&&(r?r=!1:(i[1]!==0&&(o[0]=o[1],p=Np(b,t,i,a,void 0,p)),i=o,o=[i[1],n,0,0])):E.type==="tableHead"?(u=!0,d=n):E.type==="tableRow"||E.type==="tableDelimiterRow"?(d=n,i[1]!==0?(o[0]=o[1],p=Np(b,t,i,a,n,p)):o[1]!==0&&(p=Np(b,t,o,a,n,p)),a=0):a&&(E.type==="data"||E.type==="tableDelimiterMarker"||E.type==="tableDelimiterFiller")&&(o[3]=n)}for(d!==0&&yI(b,t,d,f,m),b.consume(t.events),n=-1;++n<t.events.length;){const x=t.events[n];x[0]==="enter"&&x[1].type==="table"&&(x[1]._align=lEe(t.events,n))}return e}function Np(e,t,n,r,a,i){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",u="tableContent";n[0]!==0&&(i.end=Object.assign({},Wu(t.events,n[0])),e.add(n[0],0,[["exit",i,t]]));const d=Wu(t.events,n[1]);if(i={type:o,start:Object.assign({},d),end:Object.assign({},d)},e.add(n[1],0,[["enter",i,t]]),n[2]!==0){const f=Wu(t.events,n[2]),m=Wu(t.events,n[3]),p={type:u,start:Object.assign({},f),end:Object.assign({},m)};if(e.add(n[2],0,[["enter",p,t]]),r!==2){const b=t.events[n[2]],x=t.events[n[3]];if(b[1].end=Object.assign({},x[1].end),b[1].type="chunkText",b[1].contentType="text",n[3]>n[2]+1){const E=n[2]+1,N=n[3]-n[2]-1;e.add(E,N,[])}}e.add(n[3]+1,0,[["exit",p,t]])}return a!==void 0&&(i.end=Object.assign({},Wu(t.events,a)),e.add(a,0,[["exit",i,t]]),i=void 0),i}function yI(e,t,n,r,a){const i=[],o=Wu(t.events,n);a&&(a.end=Object.assign({},o),i.push(["exit",a,t])),r.end=Object.assign({},o),i.push(["exit",r,t]),e.add(n+1,0,i)}function Wu(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const fEe={name:"tasklistCheck",tokenize:mEe};function hEe(){return{text:{91:fEe}}}function mEe(e,t,n){const r=this;return a;function a(d){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(d):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(d),e.exit("taskListCheckMarker"),i)}function i(d){return Jt(d)?(e.enter("taskListCheckValueUnchecked"),e.consume(d),e.exit("taskListCheckValueUnchecked"),o):d===88||d===120?(e.enter("taskListCheckValueChecked"),e.consume(d),e.exit("taskListCheckValueChecked"),o):n(d)}function o(d){return d===93?(e.enter("taskListCheckMarker"),e.consume(d),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),u):n(d)}function u(d){return et(d)?t(d):gt(d)?e.check({tokenize:pEe},t,n)(d):n(d)}}function pEe(e,t,n){return Tt(e,r,"whitespace");function r(a){return a===null?n(a):t(a)}}function gEe(e){return EP([z1e(),Q1e(),iEe(e),uEe(),hEe()])}const bEe={};function Yl(e){const t=this,n=e||bEe,r=t.data(),a=r.micromarkExtensions||(r.micromarkExtensions=[]),i=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);a.push(gEe(n)),i.push(P1e()),o.push(B1e(n))}function iw(e){const t=e<1e12?e*1e3:e,n=Date.now()-t;return n<6e4?"刚刚":n<36e5?`${Math.floor(n/6e4)}分钟前`:n<864e5?`${Math.floor(n/36e5)}小时前`:n<2592e6?`${Math.floor(n/864e5)}天前`:new Date(t).toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}function V8(e){const t=new Date(e);return t.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})+" "+t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"})}function W8(e){return e==="merged"?"bg-purple-500/15 text-purple-400":e==="closed"?"bg-red-500/15 text-red-400":"bg-emerald-500/15 text-emerald-400"}function xEe(e){return e==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"}function yEe({repoId:e,issueNumber:t,onPublished:n}){const[r,a]=y.useState(""),[i,o]=y.useState(!1),u=y.useRef(null),d=y.useCallback(()=>tY(e,t,r.trim()),[e,t,r]),f=y.useCallback(()=>bA(e,t).then(O=>O.body),[e,t]),m=y.useCallback(()=>bA(e,t).then(O=>O.body||null),[e,t]),{phase:p,result:b,busy:x,setBusy:E,polish:N,discard:_,escalate:S,setResult:C}=iP({repoId:e,startPolish:d,fetchResult:f,loadExisting:m});y.useEffect(()=>{if(!i)return;const O=k=>{u.current&&!u.current.contains(k.target)&&o(!1)};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[i]);const A=async()=>{if(!(!r.trim()||x)){E(!0);try{const O=await gA(e,t,r.trim());n(O),a(""),ar.getState().addToast("评论已发布","success")}catch(O){ar.getState().addToast(O instanceof Error?O.message:"发布失败","error")}finally{E(!1)}}},I=async()=>{if(!(!(b!=null&&b.trim())||x)){E(!0);try{const O=await gA(e,t,b.trim());n(O),a(""),_(),ar.getState().addToast("评论已发布","success")}catch(O){ar.getState().addToast(O instanceof Error?O.message:"发布失败","error")}finally{E(!1)}}};return p==="preview"?c.jsxs("div",{className:"mt-8 border-t border-line pt-6",children:[c.jsxs("h3",{className:"mb-3 flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-fg-4",children:[c.jsx(ec,{className:"h-3.5 w-3.5 text-amber-400"}),"AI 润色结果"]}),c.jsx("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:c.jsx("textarea",{value:b??"",onChange:O=>C(O.target.value),rows:6,className:"w-full resize-none bg-transparent text-sm text-fg placeholder:text-fg-6 focus:outline-none"})}),c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[c.jsxs("button",{type:"button",disabled:x,onClick:()=>void I(),className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(Rf,{className:"h-3.5 w-3.5"}),"发布评论"]}),c.jsx("button",{type:"button",onClick:_,className:"ml-auto rounded-md px-2.5 py-1.5 text-xs text-fg-5 transition-colors hover:text-fg-3",children:"放弃"}),c.jsxs("div",{className:"relative",ref:u,children:[c.jsx("button",{type:"button",onClick:()=>o(!i),className:"flex h-7 w-7 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(IE,{className:"h-3.5 w-3.5"})}),i&&c.jsxs("div",{className:"absolute right-0 bottom-full z-20 mb-1 min-w-[140px] overflow-hidden rounded-lg border border-line bg-elevated shadow-lg",children:[c.jsxs("button",{type:"button",onClick:()=>{o(!1),N()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",children:[c.jsx(ec,{className:"h-3 w-3"}),"重新润色"]}),c.jsx("button",{type:"button",onClick:()=>{o(!1),S()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",children:"转入深度对话"})]})]})]})]}):c.jsxs("div",{className:"mt-8 border-t border-line pt-6",children:[c.jsx("h3",{className:"mb-3 text-xs font-semibold uppercase tracking-wider text-fg-4",children:"添加评论"}),c.jsx("textarea",{value:r,onChange:O=>a(O.target.value),placeholder:"写下你的评论...",rows:4,disabled:p==="polishing",className:"w-full resize-none rounded-lg border border-line bg-base px-3 py-2.5 text-sm text-fg placeholder:text-fg-6 focus:border-fg-5 focus:outline-none disabled:opacity-50"}),c.jsxs("div",{className:"mt-2.5 flex items-center gap-2",children:[c.jsxs("button",{type:"button",disabled:!r.trim()||x||p==="polishing",onClick:()=>void A(),className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(Rf,{className:"h-3.5 w-3.5"}),x?"发送中...":"直接发送"]}),c.jsxs("button",{type:"button",disabled:!r.trim()||p==="polishing",onClick:()=>void N(),className:"flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-1.5 text-xs font-medium text-amber-400 transition-colors hover:bg-amber-500/20 disabled:opacity-40",children:[c.jsx(ec,{className:"h-3.5 w-3.5"}),p==="polishing"?"润色中...":"AI 润色"]})]})]})}function X8({issue:e,milestone:t,onBack:n,onClose:r,onToggleSidebar:a}){var _;const i=zn(),o=We(S=>S.activeRepoId),u=We(qr),[d,f]=y.useState([]),[m,p]=y.useState(!1),[b,x]=y.useState(!1),E=Je(S=>S.updateIssueState);y.useEffect(()=>{o&&(p(!0),eY(o,e.number).then(f).catch(()=>f([])).finally(()=>p(!1)))},[o,e.number]);const N=()=>{Je.getState().setSelectedIssue(e.id),Me.setState({activeSessionId:null}),i(`/${encodeURIComponent(u)}/run`)};return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c.jsxs("header",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 md:flex-row md:items-center md:gap-3 md:px-6",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[c.jsx("button",{type:"button",onClick:n,"aria-label":"返回列表",className:"-ml-1 shrink-0 rounded-md p-1.5 text-fg-3 transition-colors hover:bg-elevated hover:text-fg md:hidden",children:c.jsx(ih,{className:"h-5 w-5"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",e.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",e.number," ",e.state]}),(_=e.labels)==null?void 0:_.map(S=>c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${S.color}20`,color:`#${S.color}`},children:S.name},S.id)),t&&c.jsxs("span",{className:"flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium bg-indigo-500/15 text-indigo-400",children:[c.jsx(RE,{className:"h-2.5 w-2.5"}),t.title]})]}),c.jsx("h2",{className:"mt-1 text-base font-semibold text-fg",children:e.title}),(e.authorLogin||e.assignees&&e.assignees.length>0)&&c.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2 text-xs text-fg-4",children:[e.authorLogin&&c.jsxs("span",{className:"flex items-center gap-1.5",children:[e.authorAvatar&&c.jsx("img",{src:e.authorAvatar,alt:"",className:"h-4 w-4 rounded-full"}),e.authorLogin]}),e.assignees&&e.assignees.length>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx("span",{className:"text-fg-5",children:"→"}),c.jsx("span",{className:"flex items-center -space-x-1",children:e.assignees.map(S=>c.jsx("img",{src:S.avatar_url,alt:S.login,title:S.login,className:"h-4 w-4 rounded-full ring-1 ring-surface"},S.login))}),c.jsx("span",{className:"text-fg-4",children:e.assignees.map(S=>S.login).join(", ")})]})]})]})]}),c.jsxs("div",{"data-guide":"issue-actions",className:"flex shrink-0 flex-wrap items-center gap-2",children:[e.htmlUrl&&c.jsxs("a",{href:e.htmlUrl,target:"_blank",rel:"noopener noreferrer",className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 font-mono text-xs text-fg-3 transition-colors hover:border-fg-5 hover:text-fg",children:[c.jsx(YR,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"源站"})]}),c.jsxs("button",{type:"button",onClick:()=>{Je.getState().enterMatchMode(e.id),Me.setState({activeSessionId:null}),i(`/${encodeURIComponent(u)}/run`)},className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 text-xs text-fg-3 transition-colors hover:border-blue-500/50 hover:text-blue-400",children:[c.jsx(Gl,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"匹配子任务"})]}),c.jsx("button",{type:"button",disabled:b,onClick:async()=>{x(!0),await E(o,e.number,e.state==="open"?"closed":"open"),x(!1)},className:ie("flex h-8 items-center gap-1.5 rounded-md border px-2.5 text-xs font-medium transition-colors disabled:opacity-40",e.state==="open"?"border-red-500/30 text-red-400 hover:border-red-500/60 hover:bg-red-500/10":"border-emerald-500/30 text-emerald-400 hover:border-emerald-500/60 hover:bg-emerald-500/10"),children:e.state==="open"?c.jsxs(c.Fragment,{children:[c.jsx(HR,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"关闭"})]}):c.jsxs(c.Fragment,{children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"重新打开"})]})}),c.jsxs("button",{type:"button",onClick:N,className:"flex h-8 items-center gap-1.5 rounded-md bg-blue-600 px-3 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:[c.jsx(LE,{className:"h-3.5 w-3.5 fill-current"}),c.jsx("span",{className:"hidden sm:inline",children:"新建任务"})]}),a&&c.jsx("button",{type:"button",onClick:a,title:"面板",className:"flex h-8 w-8 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2",children:c.jsx(VR,{className:"h-4 w-4"})}),r&&c.jsx("button",{type:"button",onClick:r,title:"关闭详情",className:"hidden h-8 w-8 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2 md:flex",children:c.jsx(At,{className:"h-4 w-4"})})]})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6",children:[e.body?c.jsx("div",{className:"markdown-body leading-relaxed",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[Kg],children:e.body})}):c.jsx("p",{className:"py-10 text-center font-mono text-xs text-fg-5",children:"该 Issue 没有描述内容"}),m?c.jsx("p",{className:"mt-8 text-center font-mono text-xs text-fg-6",children:"加载评论…"}):d.length>0&&c.jsxs("div",{className:"mt-8 border-t border-line pt-6",children:[c.jsxs("h3",{className:"mb-4 text-xs font-semibold uppercase tracking-wider text-fg-4",children:["评论 (",d.length,")"]}),c.jsx("div",{className:"space-y-4",children:d.map(S=>c.jsxs("div",{className:"rounded-lg border border-line bg-elevated/40 px-4 py-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("img",{src:S.user.avatar_url,alt:S.user.login,className:"h-5 w-5 rounded-full"}),c.jsx("span",{className:"text-xs font-semibold text-fg-2",children:S.user.login}),c.jsx("span",{className:"text-[10px] text-fg-6",children:V8(S.created_at)})]}),c.jsx("div",{className:"markdown-body mt-2 text-sm leading-relaxed text-fg-3",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[Kg],children:S.body})})]},S.id))})]}),o&&c.jsx(yEe,{repoId:o,issueNumber:e.number,onPublished:S=>f(C=>[...C,S])},e.id)]})})]})}function vEe({prs:e,onSelect:t}){return e.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-fg-5",children:[c.jsx(Il,{className:"h-8 w-8"}),c.jsx("p",{className:"font-mono text-xs",children:"该 Issue 没有关联的 PR"})]}):c.jsx("ul",{className:"space-y-2",children:e.map(n=>{var r;return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:()=>t(n.number),className:"group flex w-full flex-col gap-1.5 rounded-lg border border-line bg-elevated/30 px-4 py-3 text-left transition-colors hover:border-blue-500/40 hover:bg-elevated/60",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",W8(n.state)),children:["#",n.number," ",n.state]}),n.mergeable===!1&&c.jsxs("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold bg-red-500/15 text-red-400",children:[c.jsx(On,{className:"inline h-3 w-3 -mt-px"})," Conflict"]}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg-2 group-hover:text-fg",children:n.title})]}),c.jsx("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-fg-5",children:((r=n.user)==null?void 0:r.login)&&c.jsxs("span",{className:"flex items-center gap-1",children:[n.user.avatar_url&&c.jsx("img",{src:n.user.avatar_url,alt:"",className:"h-3.5 w-3.5 rounded-full"}),n.user.login]})})]})},n.number)})})}function Q8({pr:e,onBack:t,onClose:n,onEnterMatch:r,onNavigateToIssue:a}){var k;const i=We(j=>j.activeRepoId),o=We(qr),[u,d]=y.useState(!1),[f,m]=y.useState([]),[p,b]=y.useState(!1),[x,E]=y.useState([]),[N,_]=y.useState(!1),S=zn(),C=mn(j=>j.unlinkIssue);y.useEffect(()=>{i&&(b(!0),J$(i,e.number).then(m).catch(()=>m([])).finally(()=>b(!1)))},[i,e.number]),y.useEffect(()=>{i&&UE(i,e.number).then(E).catch(()=>E([]))},[i,e.number]);const A=async j=>{if(!(u||!i)){d(!0);try{if(await X$(i,e.number),j&&x.length>0){const F=x.filter(P=>P.state==="open");await Promise.all(F.map(P=>sM(i,P.number,{state:"closed"}))),E(P=>P.map(L=>L.state==="open"?{...L,state:"closed"}:L)),Je.getState().loadIssues(i),ar.getState().addToast(`PR #${e.number} 合入成功,已关闭 ${F.length} 个 Issue`,"success")}else ar.getState().addToast(`PR #${e.number} 合入成功`,"success");mn.getState().loadPulls(i)}catch(F){let P="合入失败";if(F instanceof Li)try{P=JSON.parse(F.message).error??P}catch{P=F.message}ar.getState().addToast(P,"error")}finally{d(!1)}}},I=async j=>{if(!i)return;await C(i,e.number,j)&&E(P=>P.filter(L=>L.number!==j))},O=()=>{const j=`请解决 PR #${e.number} 的合并冲突: ${e.title}`;Me.setState({activeSessionId:null}),S(`/${encodeURIComponent(o)}/run?draft=${encodeURIComponent(j)}`)};return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c.jsxs("header",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 md:flex-row md:items-center md:gap-3 md:px-6",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[c.jsx("button",{type:"button",onClick:t,"aria-label":"返回列表",className:"-ml-1 shrink-0 rounded-md p-1.5 text-fg-3 transition-colors hover:bg-elevated hover:text-fg md:hidden",children:c.jsx(ih,{className:"h-5 w-5"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",W8(e.state)),children:["#",e.number," ",e.state]}),e.draft===1&&c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-bold bg-fg-6/15 text-fg-4",children:"DRAFT"}),e.mergeable==="false"&&e.state==="open"&&c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold bg-red-500/15 text-red-400",children:"Conflict"}),(k=e.labels)==null?void 0:k.map(j=>c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${j.color}20`,color:`#${j.color}`},children:j.name},j.id))]}),c.jsx("h2",{className:"mt-1 text-base font-semibold text-fg",children:e.title}),c.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2 text-xs text-fg-4",children:[c.jsxs("span",{className:"flex min-w-0 items-center gap-1 font-mono text-[11px] text-fg-5",children:[c.jsx(Il,{className:"h-3.5 w-3.5 shrink-0"}),c.jsxs("span",{className:"truncate",children:[e.headBranch," → ",e.baseBranch]})]}),e.authorLogin&&c.jsxs("span",{className:"flex items-center gap-1.5",children:[e.authorAvatar&&c.jsx("img",{src:e.authorAvatar,alt:"",className:"h-4 w-4 rounded-full"}),e.authorLogin]}),e.mergedAt&&c.jsxs("span",{className:"text-purple-400",children:["合并于 ",iw(e.mergedAt)]})]})]})]}),c.jsxs("div",{"data-guide":"pr-actions",className:"flex shrink-0 flex-wrap items-center gap-2",children:[e.htmlUrl&&c.jsxs("a",{href:e.htmlUrl,target:"_blank",rel:"noopener noreferrer",className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 font-mono text-xs text-fg-3 transition-colors hover:border-fg-5 hover:text-fg",children:[c.jsx(YR,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"源站"})]}),c.jsxs("button",{type:"button",onClick:r,className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 text-xs text-fg-3 transition-colors hover:border-blue-500/50 hover:text-blue-400",children:[c.jsx(ME,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"关联 Issue"})]}),e.state==="open"&&c.jsxs(c.Fragment,{children:[e.mergeable==="false"&&c.jsxs("button",{type:"button",onClick:O,className:"flex h-8 items-center gap-1.5 rounded-md border border-amber-500/30 px-2.5 text-xs font-medium text-amber-400 transition-colors hover:border-amber-500/60 hover:bg-amber-500/10",children:[c.jsx(ZH,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"解冲突"})]}),c.jsxs("button",{type:"button",disabled:u||e.mergeable==="false",onClick:()=>void A(!1),className:"flex h-8 items-center gap-1.5 rounded-md border border-emerald-500/30 px-2.5 text-xs font-medium text-emerald-400 transition-colors hover:border-emerald-500/60 hover:bg-emerald-500/10 disabled:opacity-40",children:[c.jsx(sA,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"合入"})]}),x.some(j=>j.state==="open")&&c.jsxs("button",{type:"button",disabled:u||e.mergeable==="false",onClick:()=>void A(!0),className:"flex h-8 items-center gap-1.5 rounded-md bg-blue-600 px-3 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sA,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"合入并关闭 Issues"})]})]}),n&&c.jsx("button",{type:"button",onClick:n,title:"关闭详情",className:"hidden h-8 w-8 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2 md:flex",children:c.jsx(At,{className:"h-4 w-4"})})]})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6",children:[x.length>0&&c.jsxs("div",{className:"mb-6 rounded-lg border border-line bg-elevated/30 px-4 py-3",children:[c.jsxs("h3",{className:"mb-2 flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-fg-4",children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),"关联 Issues (",x.length,")"]}),c.jsx("div",{className:"space-y-1.5",children:x.map(j=>c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>a==null?void 0:a(j.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-0.5 transition-colors hover:bg-elevated/60",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-medium",j.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",j.number]}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-left text-sm text-fg-2",children:j.title})]}),c.jsx("button",{type:"button",onClick:()=>void I(j.number),title:"取消关联",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:bg-red-500/10 hover:text-red-400",children:c.jsx(HR,{className:"h-3.5 w-3.5"})})]},j.id))})]}),(e.commitCount!=null||e.additions!=null)&&c.jsxs("div",{className:"mb-6 rounded-lg border border-line bg-elevated/30 px-4 py-3",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-fg-3",children:[e.commitCount!=null&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx($z,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{className:"font-medium",children:e.commitCount})," 次提交"]}),e.changedFilesCount!=null&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(Io,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{className:"font-medium",children:e.changedFilesCount})," 个文件"]}),e.additions!=null&&c.jsxs("span",{className:"flex items-center gap-1 text-emerald-400",children:[c.jsx(ua,{className:"h-3 w-3"}),c.jsx("span",{className:"font-mono font-medium",children:e.additions})]}),e.deletions!=null&&c.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[c.jsx(yH,{className:"h-3 w-3"}),c.jsx("span",{className:"font-mono font-medium",children:e.deletions})]})]}),e.diffStats&&e.diffStats.length>0&&c.jsxs("div",{className:"mt-3 border-t border-line pt-3",children:[c.jsxs("button",{type:"button",onClick:()=>_(j=>!j),className:"flex w-full items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-fg-4 transition-colors hover:text-fg-2",children:[N?c.jsx(kr,{className:"h-3.5 w-3.5"}):c.jsx(Oo,{className:"h-3.5 w-3.5"}),"变更文件 (",e.diffStats.length,")"]}),N&&c.jsx("div",{className:"mt-2 space-y-0.5",children:e.diffStats.map(j=>c.jsxs("div",{className:"flex items-center gap-2 rounded px-2 py-1 text-xs hover:bg-elevated/50",children:[c.jsx("span",{className:ie("w-14 shrink-0 rounded px-1 py-0.5 text-center font-mono text-[10px] font-medium",j.status==="added"?"bg-emerald-500/15 text-emerald-400":j.status==="removed"?"bg-red-500/15 text-red-400":"bg-blue-500/15 text-blue-400"),children:j.status==="added"?"新增":j.status==="removed"?"删除":j.status==="renamed"?"重命名":"修改"}),c.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-fg-3",title:j.filename,children:j.filename}),c.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-emerald-400",children:["+",j.additions]}),c.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-red-400",children:["-",j.deletions]})]},j.filename))})]})]}),e.body?c.jsx("div",{className:"markdown-body leading-relaxed",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[Kg],children:e.body})}):c.jsx("p",{className:"py-10 text-center font-mono text-xs text-fg-5",children:"该 PR 没有描述内容"}),p?c.jsx("p",{className:"mt-8 text-center font-mono text-xs text-fg-6",children:"加载评论…"}):f.length>0&&c.jsxs("div",{className:"mt-8 border-t border-line pt-6",children:[c.jsxs("h3",{className:"mb-4 text-xs font-semibold uppercase tracking-wider text-fg-4",children:["评论 (",f.length,")"]}),c.jsx("div",{className:"space-y-4",children:f.map(j=>c.jsxs("div",{className:"rounded-lg border border-line bg-elevated/40 px-4 py-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("img",{src:j.user.avatar_url,alt:j.user.login,className:"h-5 w-5 rounded-full"}),c.jsx("span",{className:"text-xs font-semibold text-fg-2",children:j.user.login}),c.jsx("span",{className:"text-[10px] text-fg-6",children:V8(j.created_at)})]}),c.jsx("div",{className:"markdown-body mt-2 text-sm leading-relaxed text-fg-3",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[Kg],children:j.body})})]},j.id))})]})]})})]})}function EEe({issue:e,milestone:t,tab:n,prNumber:r,onTabChange:a,onSelectPr:i,onBackToPrList:o,onBack:u,onClose:d,onToggleSidebar:f}){const m=We(A=>A.activeRepoId),p=mn(A=>A.enterMatchMode),[b,x]=y.useState([]),[E,N]=y.useState(null),[_,S]=y.useState(!1);y.useEffect(()=>{if(!m){x([]);return}K$(m,e.number).then(x).catch(()=>x([]))},[m,e.number]),y.useEffect(()=>{if(!m||r==null){N(null);return}let A=!1;return S(!0),W$(m,r).then(I=>{A||N(I)}).catch(()=>{A||N(null)}).finally(()=>{A||S(!1)}),()=>{A=!0}},[m,r]);const C=b.some(A=>A.mergeable===!1);return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[b.length>0&&c.jsxs("div",{className:"flex shrink-0 items-center border-b border-line bg-surface",children:[c.jsxs("button",{type:"button",onClick:()=>a("issue"),className:ie("flex items-center gap-1.5 border-b-2 px-4 py-2.5 text-xs font-medium transition-colors",n==="issue"?"border-blue-500 text-fg":"border-transparent text-fg-4 hover:text-fg-2"),children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),"Issue"]}),c.jsxs("button",{type:"button",onClick:()=>a("pr"),className:ie("flex items-center gap-1.5 border-b-2 px-4 py-2.5 text-xs font-medium transition-colors",n==="pr"?"border-blue-500 text-fg":"border-transparent text-fg-4 hover:text-fg-2"),children:[c.jsx(Il,{className:"h-3.5 w-3.5"}),"PR",c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",n==="pr"?"bg-blue-500/10 text-blue-500":"bg-elevated text-fg-5"),children:b.length}),C&&c.jsxs("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-semibold bg-red-500/15 text-red-400",children:[c.jsx(On,{className:"inline h-3 w-3 -mt-px"})," Conflict"]})]})]}),n==="issue"||b.length===0?c.jsx(X8,{issue:e,milestone:t,onBack:u,onClose:d,onToggleSidebar:f}):r!=null?E?c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[c.jsx("div",{className:"flex shrink-0 items-center border-b border-line bg-elevated/30 px-4 py-2",children:c.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:[c.jsx(If,{className:"h-3.5 w-3.5"}),"返回列表"]})}),c.jsx(Q8,{pr:E,onBack:o,onEnterMatch:()=>p(E.id)})]}):c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:_?"加载 PR…":"PR 未找到"})}):c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsx("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6",children:c.jsx(vEe,{prs:b,onSelect:i})})})]})}const Z8=[{key:"open",label:"开放"},{key:"closed",label:"已关闭"},{key:"all",label:"全部"}];function NEe({stateFilter:e,setStateFilter:t,typeFilter:n,setTypeFilter:r,searchQuery:a,setSearchQuery:i,expandedFilter:o,setExpandedFilter:u,selectedAuthor:d,setSelectedAuthor:f,selectedAssignee:m,setSelectedAssignee:p,creating:b,setCreating:x,openCount:E,closedCount:N,totalCount:_,epicCount:S,taskCount:C,strayCount:A,afterStateCount:I,uniqueAuthors:O,uniqueAssignees:k}){const j=Je(H=>H.syncing),F=Je(H=>H.syncIssues),P=Je(H=>H.tags),L=Je(H=>H.tagFilterMode),B=Je(H=>H.cycleTagFilter),Y=Je(H=>H.clearTagFilter),re=Je(H=>H.milestones),X=Je(H=>H.selectedMilestoneId),K=Je(H=>H.setMilestoneFilter),V=We(H=>H.activeRepoId);return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-2 border-b border-line px-4 py-2.5",children:[c.jsx("span",{className:"shrink-0 text-sm font-semibold text-fg md:order-1",children:"Issues"}),V&&c.jsxs("div",{"data-guide":"issue-sync-create",className:"ml-auto flex shrink-0 items-center gap-1 md:order-last md:ml-0",children:[c.jsx("button",{type:"button",onClick:()=>V&&void F(V),disabled:j,title:"同步 Issues",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:c.jsx(Rl,{className:ie("h-3.5 w-3.5",j&&"animate-spin")})}),c.jsx("button",{type:"button",onClick:()=>x(!b),title:"新建 Issue",className:ie("flex h-8 w-8 items-center justify-center rounded-md transition-colors",b?"bg-blue-600 text-white":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:c.jsx(ua,{className:"h-3.5 w-3.5"})})]}),c.jsx("div",{className:"w-full md:order-2 md:w-auto",children:c.jsx("div",{className:"flex shrink-0 items-center rounded-lg bg-elevated/60 p-0.5",children:Z8.map(({key:H,label:G})=>{const Q=H==="open"?E:H==="closed"?N:_;return c.jsxs("button",{type:"button",onClick:()=>t(H),className:ie("flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",e===H?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-2"),children:[G,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",e===H?"bg-blue-500/10 text-blue-500":"text-fg-5"),children:Q})]},H)})})}),c.jsx("div",{className:"w-full md:order-5 md:w-auto md:min-w-0 md:flex-1 md:px-1",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2.5 py-1.5",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:a,onChange:H=>i(H.target.value),placeholder:"搜索 issue...",className:"min-w-0 flex-1 bg-transparent text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),a&&c.jsx("button",{type:"button",onClick:()=>i(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})}),c.jsx("div",{className:"hidden md:order-3 md:mx-1 md:block md:h-4 md:w-px md:shrink-0 md:bg-line"}),c.jsxs("div",{className:"flex w-full gap-2 overflow-x-auto scrollbar-none md:order-4 md:w-auto md:overflow-visible",children:[c.jsxs("button",{type:"button",onClick:()=>u(o==="type"?null:"type"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="type"?"bg-elevated text-fg":n!=="all"?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["类型",n!=="all"&&c.jsx("span",{className:"rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:n==="epic"?"Epic":n==="task"?"任务":"游离"}),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="type"&&"rotate-180")})]}),c.jsxs("button",{type:"button","data-guide":"issue-tag-filter",onClick:()=>u(o==="tag"?null:"tag"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="tag"?"bg-elevated text-fg":L.size>0?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["标签",L.size>0&&c.jsx("span",{className:"rounded-full bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:L.size}),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="tag"&&"rotate-180")})]}),c.jsxs("button",{type:"button",onClick:()=>u(o==="milestone"?null:"milestone"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="milestone"?"bg-elevated text-fg":X?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["Milestone",X&&(()=>{const H=re.find(G=>G.id===X);return H?c.jsx("span",{className:"rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:H.title}):null})(),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="milestone"&&"rotate-180")})]}),c.jsxs("button",{type:"button",onClick:()=>u(o==="author"?null:"author"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="author"?"bg-elevated text-fg":d?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["Author",d&&c.jsx("span",{className:"rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:d}),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="author"&&"rotate-180")})]}),c.jsxs("button",{type:"button",onClick:()=>u(o==="assignee"?null:"assignee"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="assignee"?"bg-elevated text-fg":m?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["Assignee",m&&c.jsx("span",{className:"rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:m}),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="assignee"&&"rotate-180")})]})]})]}),o==="type"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:["epic","stray","task","all"].map(H=>{const G=H==="epic"?"Epic":H==="stray"?"游离":H==="task"?"任务":"全部",Q=H==="epic"?S:H==="stray"?A:H==="task"?C:I,D=n===H;return c.jsxs("button",{type:"button",onClick:()=>r(D&&H!=="all"?"all":H),className:ie("flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-semibold transition-colors",D?H==="epic"?"bg-amber-400/15 text-amber-400":H==="stray"?"bg-sky-400/15 text-sky-400":H==="task"?"bg-violet-400/15 text-violet-400":"bg-fg-6/20 text-fg-3":"bg-elevated/60 text-fg-5 hover:bg-elevated hover:text-fg-3"),children:[G,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px] font-medium",D?"opacity-70":"text-fg-6"),children:Q})]},H)})}),o==="tag"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:P.length===0?c.jsx("span",{className:"text-xs text-fg-5",children:"暂无标签"}):c.jsxs(c.Fragment,{children:[P.map(H=>{const G=L.get(H.id);return c.jsxs("button",{type:"button",onClick:()=>B(H.id),className:ie("shrink-0 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",G==="include"?"ring-1 ring-current shadow-sm":G==="exclude"?"opacity-90 line-through decoration-2":"opacity-50 hover:opacity-80"),style:G==="exclude"?{backgroundColor:`#${H.color}10`,color:`#${H.color}`,boxShadow:`inset 0 0 0 1px color-mix(in srgb, #${H.color} 30%, transparent)`}:{backgroundColor:`#${H.color}18`,color:`#${H.color}`,boxShadow:G==="include"?`inset 0 0 0 1px color-mix(in srgb, #${H.color} 50%, transparent)`:void 0},children:[G==="exclude"&&c.jsx("span",{className:"mr-1 text-[10px]",children:"✕"}),H.name]},H.id)}),L.size>0&&c.jsx("button",{type:"button",onClick:Y,className:"shrink-0 rounded-md px-2 py-1 text-[10px] text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3",children:"清除"})]})}),o==="milestone"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:re.length===0?c.jsx("span",{className:"text-xs text-fg-5",children:"暂无里程碑"}):c.jsxs(c.Fragment,{children:[re.map(H=>{const G=X===H.id;return c.jsxs("button",{type:"button",onClick:()=>K(G?null:H.id),className:ie("shrink-0 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",G?"bg-indigo-500/15 text-indigo-400 ring-1 ring-indigo-400/50 shadow-sm":"bg-elevated/60 text-fg-5 hover:bg-elevated hover:text-fg-3"),children:[H.title,H.state==="closed"&&c.jsx("span",{className:"ml-1 text-[10px] opacity-60",children:"✓"})]},H.id)}),X&&c.jsx("button",{type:"button",onClick:()=>K(null),className:"shrink-0 rounded-md px-2 py-1 text-[10px] text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3",children:"清除"})]})}),o==="author"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:O.length===0?c.jsx("span",{className:"text-xs text-fg-5",children:"同步后可见作者"}):c.jsxs(c.Fragment,{children:[O.map(H=>c.jsxs("button",{type:"button",onClick:()=>f(d===H.login?null:H.login),className:ie("flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",d===H.login?"bg-blue-500/15 text-blue-400 ring-1 ring-blue-500/30 shadow-sm":"bg-elevated/60 text-fg-5 hover:bg-elevated hover:text-fg-3"),children:[H.avatar&&c.jsx("img",{src:H.avatar,alt:"",className:"h-4 w-4 rounded-full"}),H.login]},H.login)),d&&c.jsx("button",{type:"button",onClick:()=>f(null),className:"shrink-0 rounded-md px-2 py-1 text-[10px] text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3",children:"清除"})]})}),o==="assignee"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:k.length===0?c.jsx("span",{className:"text-xs text-fg-5",children:"同步后可见指派人"}):c.jsxs(c.Fragment,{children:[k.map(H=>c.jsxs("button",{type:"button",onClick:()=>p(m===H.login?null:H.login),className:ie("flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",m===H.login?"bg-blue-500/15 text-blue-400 ring-1 ring-blue-500/30 shadow-sm":"bg-elevated/60 text-fg-5 hover:bg-elevated hover:text-fg-3"),children:[H.avatar&&c.jsx("img",{src:H.avatar,alt:"",className:"h-4 w-4 rounded-full"}),H.login]},H.login)),m&&c.jsx("button",{type:"button",onClick:()=>p(null),className:"shrink-0 rounded-md px-2 py-1 text-[10px] text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3",children:"清除"})]})})]})}function SEe({issue:e,sessionCount:t,isActive:n,isEpic:r,milestone:a,onSelect:i}){return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:i,className:ie("group flex w-full items-center gap-2.5 rounded-md px-2.5 py-2 text-left transition-colors",n?"border-l-2 border-blue-500 bg-elevated/80":"border-l-2 border-transparent hover:bg-elevated/50"),children:[c.jsx("span",{className:ie("flex h-10 w-10 shrink-0 items-center justify-center rounded-full font-mono text-sm font-bold",e.state==="open"?"bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 text-emerald-400 ring-1 ring-emerald-500/25":"bg-gradient-to-br from-purple-500/20 to-purple-500/5 text-purple-400 ring-1 ring-purple-500/25"),children:e.number}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[r&&c.jsx("span",{className:"shrink-0 rounded px-1 py-0.5 text-[9px] font-bold tracking-wide bg-amber-400/12 text-amber-400",children:"EPIC"}),c.jsx("span",{className:"min-w-0 text-xs font-medium text-fg-2 group-hover:text-fg",children:e.title})]}),e.labels&&e.labels.length>0&&c.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.labels.map(o=>c.jsx("span",{className:"rounded px-1 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${o.color}20`,color:`#${o.color}`},children:o.name},o.id))}),a&&c.jsxs("span",{className:"mt-1 flex items-center gap-1 text-[10px] text-indigo-400/70",children:[c.jsx(RE,{className:"h-2.5 w-2.5"}),a.title]})]}),t>0&&c.jsx("span",{className:"shrink-0 rounded-full bg-elevated px-1.5 py-0.5 font-mono text-[10px] text-fg-5",children:t})]})})}const vI=y.memo(SEe,(e,t)=>{var n,r;return e.issue.id===t.issue.id&&e.issue.state===t.issue.state&&e.issue.title===t.issue.title&&e.sessionCount===t.sessionCount&&e.isActive===t.isActive&&e.isEpic===t.isEpic&&((n=e.milestone)==null?void 0:n.id)===((r=t.milestone)==null?void 0:r.id)});function wEe({issue:e,sessionCount:t,isEpic:n,milestone:r,onSelect:a}){return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:a,className:"group flex w-full items-center gap-3 border-b border-line px-4 py-3 text-left transition-colors hover:bg-elevated/50",children:[c.jsx("span",{className:ie("flex h-10 w-10 shrink-0 items-center justify-center rounded-full font-mono text-sm font-bold",e.state==="open"?"bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 text-emerald-400 ring-1 ring-emerald-500/25":"bg-gradient-to-br from-purple-500/20 to-purple-500/5 text-purple-400 ring-1 ring-purple-500/25"),children:e.number}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[n&&c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[9px] font-bold tracking-wide bg-amber-400/12 text-amber-400",children:"EPIC"}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg-2 group-hover:text-fg",children:e.title}),r&&c.jsxs("span",{className:"hidden shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium bg-indigo-500/15 text-indigo-400 sm:flex",children:[c.jsx(RE,{className:"h-2.5 w-2.5"}),r.title]}),t>0&&c.jsxs("span",{className:"shrink-0 rounded-full bg-elevated px-2 py-0.5 font-mono text-[10px] text-fg-5",children:[t," 次运行"]}),e.assignees&&e.assignees.length>0&&c.jsxs("div",{className:"hidden shrink-0 items-center -space-x-1.5 sm:flex",children:[e.assignees.slice(0,3).map(i=>c.jsx("img",{src:i.avatar_url,alt:i.login,title:i.login,className:"h-5 w-5 rounded-full ring-2 ring-surface"},i.login)),e.assignees.length>3&&c.jsxs("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-elevated text-[9px] font-medium text-fg-4 ring-2 ring-surface",children:["+",e.assignees.length-3]})]})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[e.authorLogin&&c.jsxs("span",{className:"shrink-0 text-[11px] text-fg-5",title:e.authorLogin,children:[e.authorAvatar&&c.jsx("img",{src:e.authorAvatar,alt:"",className:"mr-1 inline-block h-3.5 w-3.5 rounded-full align-text-bottom"}),e.authorLogin]}),e.authorLogin&&c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{className:"shrink-0 text-[11px] text-fg-6",children:iw(e.createdAt)}),(e.commentCount??0)>0&&c.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 text-[11px] text-fg-6",children:[c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx(dH,{className:"h-3 w-3"}),e.commentCount]}),(e.labels&&e.labels.length>0||(e.commentCount??0)>0||e.authorLogin)&&e.labels&&e.labels.length>0&&c.jsx("span",{className:"text-fg-6",children:"·"}),e.labels&&e.labels.length>0?e.labels.map(i=>c.jsx("span",{className:"rounded px-1.5 py-0.5 text-[11px] font-medium",style:{backgroundColor:`#${i.color}20`,color:`#${i.color}`},children:i.name},i.id)):e.authorLogin?null:c.jsx("span",{className:"text-[11px] text-fg-6",children:" "})]})]})]})})}const _Ee=y.memo(wEe,(e,t)=>{var n,r;return e.issue.id===t.issue.id&&e.issue.state===t.issue.state&&e.issue.title===t.issue.title&&e.sessionCount===t.sessionCount&&e.isEpic===t.isEpic&&((n=e.milestone)==null?void 0:n.id)===((r=t.milestone)==null?void 0:r.id)});function TEe(e){var i;const t=typeof((i=e.time)==null?void 0:i.created)=="number"?e.time.created:e.createdAt?Date.parse(e.createdAt):0;if(!t||Number.isNaN(t))return"";const n=t<1e12?t*1e3:t,r=new Date(n);return r.toDateString()===new Date().toDateString()?r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):r.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function EI({session:e,onSelect:t}){var r,a;const n=TEe(e);return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:t,className:"block w-full rounded-md border-l-2 border-transparent px-2.5 py-2 text-left transition-colors hover:bg-elevated/50",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"min-w-0 truncate font-mono text-xs text-fg-3",children:((r=e.agent)==null?void 0:r.trim())||"默认"}),n&&c.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] tabular-nums text-fg-5",children:n})]}),c.jsx("div",{className:"mt-0.5 truncate text-sm text-fg-2",children:((a=e.title)==null?void 0:a.trim())||"未命名运行"})]})})}function J8({sessions:e,onSelect:t}){const n=Je(o=>o.issues),r=new Map(n.map(o=>[o.id,o])),a=new Map,i=[];for(const o of e)if(o.issueId&&r.has(o.issueId)){const u=a.get(o.issueId)??[];u.push(o),a.set(o.issueId,u)}else i.push(o);return c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col border-t border-line",children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-line px-3 py-3",children:[c.jsx(kE,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-fg-4",children:"运行记录"}),c.jsx("span",{className:"ml-auto rounded-full bg-elevated px-1.5 py-0.5 font-mono text-[10px] text-fg-5",children:e.length})]}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:e.length===0?c.jsx("p",{className:"px-2 py-4 text-center font-mono text-[10px] text-fg-6",children:"暂无运行记录"}):c.jsxs("div",{className:"space-y-3",children:[[...a.entries()].map(([o,u])=>{const d=r.get(o);return c.jsxs("div",{children:[c.jsxs("div",{className:"mb-1 flex items-center gap-1.5 px-1",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-medium",d.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",d.number]}),c.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-fg-3",children:d.title})]}),c.jsx("ul",{className:"space-y-0.5",children:u.map(f=>c.jsx(EI,{session:f,onSelect:()=>t(f.id)},f.id))})]},o)}),i.length>0&&c.jsxs("div",{children:[a.size>0&&c.jsx("div",{className:"mb-1 px-1",children:c.jsx("span",{className:"text-xs font-medium text-fg-5",children:"未关联 Issue"})}),c.jsx("ul",{className:"space-y-0.5",children:i.map(o=>c.jsx(EI,{session:o,onSelect:()=>t(o.id)},o.id))})]})]})})]})}function AEe({sessions:e,onSessionSelect:t}){return c.jsx("div",{className:"flex w-full flex-col",children:c.jsx(J8,{sessions:e,onSelect:t})})}function eB({issue:e,childrenMap:t,currentId:n,onSelect:r,depth:a}){const i=t.get(e.id)??[],o=e.id===n;return c.jsxs("div",{children:[c.jsxs("button",{type:"button",onClick:()=>r(e.id),className:ie("group flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs transition-colors",o?"bg-blue-500/10 text-blue-400":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),style:{paddingLeft:`${a*18+8}px`},children:[c.jsx("span",{className:ie("h-1.5 w-1.5 shrink-0 rounded-full",e.state==="open"?"bg-emerald-400":"bg-purple-400")}),c.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-fg-6",children:["#",e.number]}),c.jsx("span",{className:"min-w-0 truncate",children:e.title})]}),i.length>0&&c.jsxs("div",{className:"relative",children:[c.jsx("div",{className:"absolute top-0 bottom-3 w-px bg-line",style:{left:`${a*18+16}px`}}),i.map(u=>c.jsx(eB,{issue:u,childrenMap:t,currentId:n,onSelect:r,depth:a+1},u.id))]})]})}function CEe(e,t){let n=0,r=0;const a=[...t.get(e)??[]];for(let i=0;i<a.length;i++){const o=a[i];n++,o.state==="closed"&&r++;const u=t.get(o.id);u&&a.push(...u)}return{total:n,closed:r}}function kEe({rootIssue:e,childrenMap:t,currentId:n,onSelect:r,sessions:a,onSessionSelect:i}){const{total:o,closed:u}=CEe(e.id,t),d=o===0?0:Math.round(u/o*100);return c.jsxs("div",{className:"flex w-full flex-col",children:[c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-line px-3 py-3",children:[c.jsx(_H,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-fg-4",children:"子任务树"})]}),o>0&&c.jsxs("div",{className:"border-b border-line px-3 py-2",children:[c.jsx("div",{className:"h-1 overflow-hidden rounded-full bg-elevated",children:c.jsx("div",{className:"h-full rounded-full bg-gradient-to-r from-emerald-400 to-blue-500 transition-all",style:{width:`${d}%`}})}),c.jsxs("p",{className:"mt-1 font-mono text-[10px] text-fg-6",children:[u," / ",o," completed"]})]}),c.jsx("div",{className:"flex-1 overflow-y-auto py-2",children:c.jsx(eB,{issue:e,childrenMap:t,currentId:n,onSelect:r,depth:0})})]}),c.jsx(J8,{sessions:a,onSelect:i})]})}function NI({total:e,page:t,pageSize:n=Qv,onPageChange:r}){const a=Math.max(1,n),i=Math.max(1,Math.ceil(e/a));if(i<=1)return null;const o=t*n+1,u=Math.min((t+1)*n,e);return c.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[c.jsxs("span",{className:"font-mono text-[11px] text-fg-5",children:[o,"–",u," / ",e]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("button",{type:"button",disabled:t<=0,onClick:()=>r(t-1),className:ie("flex h-7 w-7 items-center justify-center rounded-md transition-colors",t<=0?"text-fg-6 cursor-not-allowed":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:c.jsx(ih,{className:"h-4 w-4"})}),c.jsxs("span",{className:"min-w-[3rem] text-center font-mono text-xs text-fg-3",children:[t+1," / ",i]}),c.jsx("button",{type:"button",disabled:t>=i-1,onClick:()=>r(t+1),className:ie("flex h-7 w-7 items-center justify-center rounded-md transition-colors",t>=i-1?"text-fg-6 cursor-not-allowed":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:c.jsx(Oo,{className:"h-4 w-4"})})]})]})}function dE({side:e,open:t,onClose:n,children:r,width:a="w-80"}){const i=e==="left";return c.jsxs("div",{className:"md:hidden",children:[t&&c.jsx("div",{className:"fixed inset-0 z-40 bg-black/50",onClick:n,"aria-hidden":"true"}),c.jsx("div",{className:ie("fixed top-0 bottom-0 z-50 flex flex-col bg-surface pt-[var(--safe-top)] pb-[var(--safe-bottom)] shadow-xl transition-transform duration-200 ease-out",a,i?"left-0 border-r border-line":"right-0 border-l border-line",t?"translate-x-0":i?"-translate-x-full":"translate-x-full"),children:r})]})}function OEe({issues:e,tags:t,milestones:n,tagFilterMode:r,stateFilter:a,typeFilter:i,searchQuery:o,selectedMilestoneId:u,selectedAuthor:d,selectedAssignee:f}){const{childIssueIds:m,childrenMap:p}=y.useMemo(()=>{const A=new Set(e.filter(O=>O.parentId).map(O=>O.parentId)),I=new Map;for(const O of e)if(O.parentId){const k=I.get(O.parentId);k?k.push(O):I.set(O.parentId,[O])}return{childIssueIds:A,childrenMap:I}},[e]),b=y.useMemo(()=>A=>A.parentId?"task":m.has(A.id)?"epic":"stray",[m]),x=y.useMemo(()=>new Map(n.map(A=>[A.id,A])),[n]),{afterState:E,finalFiltered:N}=y.useMemo(()=>{const A=a==="all"?e:e.filter(B=>B.state===a),I=i==="all"?A:A.filter(B=>b(B)===i),O=r.size===0?I:I.filter(B=>{var re;const Y=new Set((B.labels??[]).map(X=>X.name));for(const[X,K]of r){const V=(re=t.find(H=>H.id===X))==null?void 0:re.name;if(V&&(K==="include"&&!Y.has(V)||K==="exclude"&&Y.has(V)))return!1}return!0}),k=o.trim().toLowerCase(),j=k?O.filter(B=>`#${B.number} ${B.title}`.toLowerCase().includes(k)):O,F=u?j.filter(B=>B.milestoneId===u):j,P=d?F.filter(B=>B.authorLogin===d):F,L=f?P.filter(B=>(B.assignees??[]).some(Y=>Y.login===f)):P;return{afterState:A,finalFiltered:L}},[e,a,i,r,t,o,u,d,f,b]),_=y.useMemo(()=>({open:e.filter(A=>A.state==="open").length,closed:e.filter(A=>A.state==="closed").length,epic:E.filter(A=>b(A)==="epic").length,task:E.filter(A=>b(A)==="task").length,stray:E.filter(A=>b(A)==="stray").length,afterState:E.length}),[e,E,b]),S=y.useMemo(()=>{const A=new Map;for(const I of e)I.authorLogin&&!A.has(I.authorLogin)&&A.set(I.authorLogin,{login:I.authorLogin,avatar:I.authorAvatar});return[...A.values()]},[e]),C=y.useMemo(()=>{const A=new Map;for(const I of e)for(const O of I.assignees??[])A.has(O.login)||A.set(O.login,{login:O.login,avatar:O.avatar_url});return[...A.values()]},[e]);return{childrenMap:p,issueType:b,milestoneMap:x,afterState:E,finalFiltered:N,counts:_,uniqueAuthors:S,uniqueAssignees:C}}const SI=8;function IEe(e,t){let n=e instanceof Element?e:null;for(;n&&n!==t;){if(n.scrollWidth>n.clientWidth){const r=getComputedStyle(n).overflowX;if(r==="auto"||r==="scroll")return!0}n=n.parentElement}return!1}function tB({onSwipeLeft:e,onSwipeRight:t,threshold:n=40,disabled:r=!1}={}){const a=y.useRef({x0:0,y0:0,dir:null,on:!1}),i=y.useRef(0),o=y.useCallback(f=>{if(r||IEe(f.target,f.currentTarget))return;const m=f.touches[0];a.current={x0:m.clientX,y0:m.clientY,dir:null,on:!0},i.current=0},[r]),u=y.useCallback(f=>{const m=a.current;if(!m.on)return;const p=f.touches[0].clientX-m.x0,b=f.touches[0].clientY-m.y0;if(!m.dir){(Math.abs(p)>SI||Math.abs(b)>SI)&&(m.dir=Math.abs(p)>Math.abs(b)?"h":"v");return}if(m.dir==="v"){m.on=!1;return}i.current=p},[]),d=y.useCallback(()=>{const f=a.current;if(!f.on||f.dir!=="h"){f.on=!1;return}f.on=!1;const m=i.current;m>n?t==null||t():m<-n&&(e==null||e())},[n,e,t]);return{onTouchStart:o,onTouchMove:u,onTouchEnd:d}}function REe(){const[e,t]=y.useState("open"),[n,r]=y.useState("stray"),[a,i]=y.useState(!1),[o,u]=y.useState(""),d=Je(ee=>ee.viewingTreeRootId),f=Je(ee=>ee.setViewingIssue),[m,p]=y.useState(!1),[b,x]=y.useState(!1),[E,N]=y.useState(null),[_,S]=y.useState(null),[C,A]=y.useState(null),[I,O]=y.useState(0),[k,j]=CE(),F=Je(ee=>ee.issues),P=Je(ee=>ee.loaded),L=Je(ee=>ee.syncing),B=Je(ee=>ee.syncIssues),Y=Je(ee=>ee.tags),re=Je(ee=>ee.tagFilterMode),X=Je(ee=>ee.loadTags),K=Je(ee=>ee.milestones),V=Je(ee=>ee.selectedMilestoneId),H=Je(ee=>ee.loadMilestones),G=We(ee=>ee.activeRepoId),Q=Je(ee=>ee.syncError),D=We(qr),z=Me(ee=>ee.sessions),$=zn(),M=k.get("id"),le=k.get("tab")==="pr"?"pr":"issue",oe=k.get("prId"),ne=oe?Number.parseInt(oe,10):null;y.useEffect(()=>{const ee=k.get("issueId");if(!ee)return;const ve=new URLSearchParams(k);ve.delete("issueId"),ve.set("id",ee),j(ve,{replace:!0})},[k,j]),y.useEffect(()=>{if(k.get("id"))return;const ee=Je.getState().viewingIssueId;ee&&j({id:ee},{replace:!0})},[k.get,j]);const ae=y.useCallback(ee=>{j({id:ee},{replace:!1})},[j]),De=y.useCallback(()=>{j({},{replace:!1}),f(null)},[j,f]),xe=y.useCallback(ee=>{if(!M)return;const ve={id:M};ee==="pr"&&(ve.tab="pr"),j(ve,{replace:!1})},[M,j]),we=y.useCallback(ee=>{M&&j({id:M,tab:"pr",prId:String(ee)},{replace:!1})},[M,j]),Le=y.useCallback(()=>{M&&j({id:M,tab:"pr"},{replace:!1})},[M,j]);y.useEffect(()=>{G&&(X(G),H(G))},[G,X,H]),y.useEffect(()=>{Q&&ar.getState().addToast(Q,"error")},[Q]),y.useEffect(()=>{O(0)},[]);const{childrenMap:Ee,issueType:st,milestoneMap:Ke,finalFiltered:Be,counts:Fe,uniqueAuthors:ln,uniqueAssignees:In}=OEe({issues:F,tags:Y,milestones:K,tagFilterMode:re,stateFilter:e,typeFilter:n,searchQuery:o,selectedMilestoneId:V,selectedAuthor:_,selectedAssignee:C}),fr=y.useMemo(()=>{const ee=I*Qv;return Be.slice(ee,ee+Qv)},[Be,I]),yn=y.useMemo(()=>{const ee=new Map;for(const ve of z)ve.issueId&&!ve.parentID&&ee.set(ve.issueId,(ee.get(ve.issueId)??0)+1);return ee},[z]),hr=F.find(ee=>ee.id===M)??null,ha=y.useMemo(()=>{if(!M)return[];const ee=new Set([M]);if(d){ee.add(d);const ve=[...Ee.get(d)??[]];for(let ze=0;ze<ve.length;ze++){ee.add(ve[ze].id);const at=Ee.get(ve[ze].id);at&&ve.push(...at)}}return z.filter(ve=>ve.issueId&&ee.has(ve.issueId)&&!ve.parentID)},[M,d,Ee,z]),Ra=y.useCallback(ee=>{Me.setState({activeSessionId:ee}),$(`/${encodeURIComponent(D)}/run`)},[$,D]),Lt=y.useCallback((ee,ve)=>{ae(ee),f(ee,ve==="epic"?ee:null)},[ae,f]),yi=tB({onSwipeRight:()=>x(!0),onSwipeLeft:()=>p(!0),disabled:!M||b||m});return c.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 overflow-hidden",...yi,children:[c.jsxs("div",{className:ie("shrink-0 flex-col bg-surface",M?"hidden md:flex md:w-80 border-r border-line":"flex w-full"),children:[M?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-3",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-fg-3",children:"Issues"}),G&&c.jsx("div",{className:"flex items-center gap-1",children:c.jsx("button",{type:"button",onClick:()=>G&&void B(G),disabled:L,title:"同步",className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:c.jsx(Rl,{className:ie("h-3.5 w-3.5",L&&"animate-spin")})})})]}),a&&c.jsx(c5,{onDone:()=>i(!1)}),c.jsx("div",{className:"flex border-b border-line",children:Z8.map(({key:ee,label:ve})=>{const ze=ee==="open"?Fe.open:ee==="closed"?Fe.closed:F.length;return c.jsxs("button",{type:"button",onClick:()=>t(ee),className:ie("flex flex-1 items-center justify-center gap-1.5 py-2 text-xs font-medium transition-colors",e===ee?"border-b-2 border-blue-500 text-blue-500":"text-fg-4 hover:text-fg-2"),children:[ve,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",e===ee?"bg-blue-500/10 text-blue-500":"bg-elevated text-fg-5"),children:ze})]},ee)})}),c.jsx("div",{className:"border-b border-line px-3 py-2",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2 py-1",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:o,onChange:ee=>u(ee.target.value),placeholder:"搜索 issue...",className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),o&&c.jsx("button",{type:"button",onClick:()=>u(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})})]}):c.jsxs(c.Fragment,{children:[c.jsx(NEe,{stateFilter:e,setStateFilter:t,typeFilter:n,setTypeFilter:r,searchQuery:o,setSearchQuery:u,expandedFilter:E,setExpandedFilter:N,selectedAuthor:_,setSelectedAuthor:S,selectedAssignee:C,setSelectedAssignee:A,creating:a,setCreating:i,openCount:Fe.open,closedCount:Fe.closed,totalCount:F.length,epicCount:Fe.epic,taskCount:Fe.task,strayCount:Fe.stray,afterStateCount:Fe.afterState,uniqueAuthors:ln,uniqueAssignees:In}),a&&c.jsx(c5,{onDone:()=>i(!1)})]}),c.jsx("div",{className:ie("flex-1 overflow-y-auto",M?"px-2 py-2":"px-3 py-3"),children:G?P?Be.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:F.length===0?"点击 ↻ 同步 Issues":"无匹配 Issue"}):c.jsx("ul",{className:ie(M?"space-y-0.5":"space-y-1"),children:fr.map(ee=>M?c.jsx(vI,{issue:ee,sessionCount:yn.get(ee.id)??0,isActive:M===ee.id,isEpic:st(ee)==="epic",milestone:ee.milestoneId?Ke.get(ee.milestoneId):void 0,onSelect:()=>Lt(ee.id,st(ee))},ee.id):c.jsx(_Ee,{issue:ee,sessionCount:yn.get(ee.id)??0,isEpic:st(ee)==="epic",milestone:ee.milestoneId?Ke.get(ee.milestoneId):void 0,onSelect:()=>Lt(ee.id,st(ee))},ee.id))}):c.jsxs("div",{className:"flex flex-col items-center gap-2 py-8",children:[c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"}),c.jsx("p",{className:"text-xs text-fg-5",children:"加载中…"})]}):c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:"请先选择一个仓库"})}),c.jsx(NI,{total:Be.length,page:I,onPageChange:O})]}),M&&c.jsx(dE,{side:"left",open:b,onClose:()=>x(!1),children:c.jsxs("div",{className:"flex h-full flex-col",children:[c.jsx("div",{className:"border-b border-line px-3 py-3",children:c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-fg-3",children:"Issues"})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:Be.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:"无匹配 Issue"}):c.jsx("ul",{className:"space-y-0.5",children:fr.map(ee=>c.jsx(vI,{issue:ee,sessionCount:yn.get(ee.id)??0,isActive:M===ee.id,isEpic:st(ee)==="epic",milestone:ee.milestoneId?Ke.get(ee.milestoneId):void 0,onSelect:()=>{Lt(ee.id,st(ee)),x(!1)}},ee.id))})}),c.jsx(NI,{total:Be.length,page:I,onPageChange:O})]})}),M&&c.jsx("div",{className:"relative flex min-w-0 flex-1 flex-col bg-term",children:hr?c.jsxs(c.Fragment,{children:[c.jsx(EEe,{issue:hr,milestone:hr.milestoneId?Ke.get(hr.milestoneId):void 0,tab:le,prNumber:ne,onTabChange:xe,onSelectPr:we,onBackToPrList:Le,onBack:()=>{De(),p(!1)},onClose:()=>{De(),p(!1)},onToggleSidebar:()=>p(ee=>!ee)}),m&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"absolute inset-0 z-10 bg-black/30",onClick:()=>p(!1)}),c.jsxs("div",{className:"absolute right-0 top-0 bottom-0 z-20 flex w-[280px] flex-col border-l border-line bg-surface shadow-xl",children:[c.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-line px-3 py-2.5",children:[c.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-fg-4",children:d?"子任务树 & 运行记录":"运行记录"}),c.jsx("button",{type:"button",onClick:()=>p(!1),className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:d?(()=>{const ee=F.find(ve=>ve.id===d);return ee?c.jsx(kEe,{rootIssue:ee,childrenMap:Ee,currentId:M,onSelect:ve=>{ae(ve),f(ve,d),p(!1)},sessions:ha,onSessionSelect:Ra}):null})():c.jsx(AEe,{sessions:ha,onSessionSelect:Ra})})]})]})]}):c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"Issue 未找到"})})})]})}function MEe({issues:e,onSelect:t}){const n=Me(a=>a.sessions),r=new Map;for(const a of n)a.issueId&&!a.parentID&&r.set(a.issueId,(r.get(a.issueId)??0)+1);return e.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-fg-5",children:[c.jsx(ql,{className:"h-8 w-8"}),c.jsx("p",{className:"font-mono text-xs",children:"该 PR 没有关联的 Issue"})]}):c.jsx("ul",{className:"space-y-2",children:e.map(a=>{const i=r.get(a.id)??0;return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:()=>t(a.id),className:"group flex w-full flex-col gap-1.5 rounded-lg border border-line bg-elevated/30 px-4 py-3 text-left transition-colors hover:border-blue-500/40 hover:bg-elevated/60",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",xEe(a.state)),children:["#",a.number," ",a.state]}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg-2 group-hover:text-fg",children:a.title}),i>0&&c.jsxs("span",{className:"shrink-0 rounded-full bg-elevated px-2 py-0.5 font-mono text-[10px] text-fg-5",children:[i," 次运行"]})]}),c.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-fg-5",children:[a.authorLogin&&c.jsxs("span",{className:"flex items-center gap-1",children:[a.authorAvatar&&c.jsx("img",{src:a.authorAvatar,alt:"",className:"h-3.5 w-3.5 rounded-full"}),a.authorLogin]}),a.labels&&a.labels.length>0&&a.labels.map(o=>c.jsx("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${o.color}20`,color:`#${o.color}`},children:o.name},o.id))]})]})},a.id)})})}function DEe({pr:e,isActive:t,onSelect:n}){return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:n,className:ie("group flex w-full items-center gap-2.5 rounded-md px-2.5 py-2 text-left transition-colors",t?"border-l-2 border-blue-500 bg-elevated/80":"border-l-2 border-transparent hover:bg-elevated/50"),children:[c.jsx("span",{className:ie("flex h-10 w-10 shrink-0 items-center justify-center rounded-full font-mono text-sm font-bold ring-1",e.state==="merged"?"bg-gradient-to-br from-purple-500/20 to-purple-500/5 text-purple-400 ring-purple-500/25":e.state==="closed"?"bg-gradient-to-br from-red-500/20 to-red-500/5 text-red-400 ring-red-500/25":"bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 text-emerald-400 ring-emerald-500/25"),children:e.number}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[e.draft===1&&c.jsx("span",{className:"shrink-0 rounded px-1 py-0.5 text-[9px] font-bold bg-fg-6/15 text-fg-4",children:"DRAFT"}),c.jsx("span",{className:"min-w-0 text-xs font-medium text-fg-2 group-hover:text-fg",children:e.title})]}),c.jsxs("div",{className:"mt-0.5 truncate font-mono text-[10px] text-fg-6",children:[e.headBranch," → ",e.baseBranch]}),e.labels&&e.labels.length>0&&c.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.labels.map(r=>c.jsx("span",{className:"rounded px-1 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${r.color}20`,color:`#${r.color}`},children:r.name},r.id))})]})]})})}const jEe=y.memo(DEe,(e,t)=>e.pr.number===t.pr.number&&e.pr.state===t.pr.state&&e.pr.title===t.pr.title&&e.pr.draft===t.pr.draft&&e.isActive===t.isActive);function LEe({pr:e,onSelect:t}){return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:t,className:"group flex w-full items-center gap-3 border-b border-line px-4 py-3 text-left transition-colors hover:bg-elevated/50",children:[c.jsx("span",{className:ie("flex h-10 w-10 shrink-0 items-center justify-center rounded-full font-mono text-sm font-bold ring-1",e.state==="merged"?"bg-gradient-to-br from-purple-500/20 to-purple-500/5 text-purple-400 ring-purple-500/25":e.state==="closed"?"bg-gradient-to-br from-red-500/20 to-red-500/5 text-red-400 ring-red-500/25":"bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 text-emerald-400 ring-emerald-500/25"),children:e.number}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[e.draft===1&&c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[9px] font-bold tracking-wide bg-fg-6/15 text-fg-4",children:"DRAFT"}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg-2 group-hover:text-fg",children:e.title}),e.mergeable==="false"&&e.state==="open"&&c.jsxs("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold bg-red-500/15 text-red-400",children:[c.jsx(On,{className:"inline h-3 w-3 -mt-px"})," Conflict"]}),e.assignees&&e.assignees.length>0&&c.jsx("div",{className:"hidden shrink-0 items-center -space-x-1.5 sm:flex",children:e.assignees.slice(0,3).map(n=>c.jsx("img",{src:n.avatar_url,alt:n.login,title:n.login,className:"h-5 w-5 rounded-full ring-2 ring-surface"},n.login))})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[c.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-fg-5",children:[e.headBranch," → ",e.baseBranch]}),c.jsx("span",{className:"text-fg-6",children:"·"}),e.authorLogin&&c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"shrink-0 text-[11px] text-fg-5",title:e.authorLogin,children:[e.authorAvatar&&c.jsx("img",{src:e.authorAvatar,alt:"",className:"mr-1 inline-block h-3.5 w-3.5 rounded-full align-text-bottom"}),e.authorLogin]}),c.jsx("span",{className:"text-fg-6",children:"·"})]}),c.jsx("span",{className:"shrink-0 text-[11px] text-fg-6",children:iw(e.createdAt)}),e.labels&&e.labels.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-fg-6",children:"·"}),e.labels.map(n=>c.jsx("span",{className:"rounded px-1.5 py-0.5 text-[11px] font-medium",style:{backgroundColor:`#${n.color}20`,color:`#${n.color}`},children:n.name},n.id))]})]})]})]})})}const PEe=y.memo(LEe,(e,t)=>e.pr.number===t.pr.number&&e.pr.state===t.pr.state&&e.pr.title===t.pr.title&&e.pr.draft===t.pr.draft&&e.pr.mergeable===t.pr.mergeable),wI=[{key:"open",label:"开放"},{key:"merged",label:"已合并"},{key:"closed",label:"已关闭"},{key:"all",label:"全部"}];function BEe({issue:e,linked:t,onToggle:n}){return c.jsx("li",{children:c.jsx("button",{type:"button",onClick:n,className:ie("group flex w-full items-start gap-2 rounded-md px-3 py-2.5 text-left transition-colors",t?"border-l-2 border-emerald-500 bg-emerald-500/5":"border-l-2 border-transparent hover:bg-elevated/50"),children:c.jsx("div",{className:"min-w-0 flex-1",children:c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-xs font-medium",e.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",e.number]}),c.jsx("span",{className:"min-w-0 truncate text-sm font-medium text-fg-2",children:e.title}),t&&c.jsx(ME,{className:"ml-auto h-3.5 w-3.5 shrink-0 text-emerald-400"})]})})})})}function UEe({pr:e,tab:t,issueId:n,onTabChange:r,onSelectIssue:a,onBackToIssueList:i,onBack:o,onClose:u,onEnterMatch:d,onNavigateToIssue:f}){const m=We(N=>N.activeRepoId),p=Je(N=>N.issues),[b,x]=y.useState([]);y.useEffect(()=>{if(!m){x([]);return}UE(m,e.number).then(x).catch(()=>x([]))},[m,e.number]);const E=n?p.find(N=>N.id===n)??b.find(N=>N.id===n)??null:null;return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[b.length>0&&c.jsxs("div",{className:"flex shrink-0 items-center border-b border-line bg-surface",children:[c.jsxs("button",{type:"button",onClick:()=>r("pr"),className:ie("flex items-center gap-1.5 border-b-2 px-4 py-2.5 text-xs font-medium transition-colors",t==="pr"?"border-blue-500 text-fg":"border-transparent text-fg-4 hover:text-fg-2"),children:[c.jsx(Il,{className:"h-3.5 w-3.5"}),"PR"]}),c.jsxs("button",{type:"button",onClick:()=>r("issue"),className:ie("flex items-center gap-1.5 border-b-2 px-4 py-2.5 text-xs font-medium transition-colors",t==="issue"?"border-blue-500 text-fg":"border-transparent text-fg-4 hover:text-fg-2"),children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),"Issue",c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",t==="issue"?"bg-blue-500/10 text-blue-500":"bg-elevated text-fg-5"),children:b.length})]})]}),t==="pr"||b.length===0?c.jsx(Q8,{pr:e,onBack:o,onClose:u,onEnterMatch:d,onNavigateToIssue:f}):E?c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[c.jsx("div",{className:"flex shrink-0 items-center border-b border-line bg-elevated/30 px-4 py-2",children:c.jsxs("button",{type:"button",onClick:i,className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:[c.jsx(If,{className:"h-3.5 w-3.5"}),"返回列表"]})}),c.jsx(X8,{issue:E,onBack:i})]}):c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsx("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6",children:c.jsx(MEe,{issues:b,onSelect:a})})})]})}function FEe(){const[e,t]=y.useState("open"),[n,r]=y.useState(""),a=mn(ae=>ae.setViewingPr),[i,o]=y.useState(""),[u,d]=CE(),f=zn(),m=We(qr),p=mn(ae=>ae.pulls),b=mn(ae=>ae.syncing),x=mn(ae=>ae.syncPulls),E=mn(ae=>ae.syncError),N=mn(ae=>ae.matchingPrId),_=mn(ae=>ae.enterMatchMode),S=mn(ae=>ae.exitMatchMode),C=mn(ae=>ae.linkIssue),A=We(ae=>ae.activeRepoId),I=Je(ae=>ae.issues),O=u.get("id"),k=u.get("tab")==="issue"?"issue":"pr",j=u.get("issueId");y.useEffect(()=>{E&&ar.getState().addToast(E,"error")},[E]),y.useEffect(()=>{const ae=u.get("prId");if(!ae)return;const De=new URLSearchParams(u);De.delete("prId"),De.set("id",ae),d(De,{replace:!0})},[u,d]),y.useEffect(()=>{if(u.get("id"))return;const ae=mn.getState().viewingPrId;ae&&d({id:ae},{replace:!0})},[d,u.get]);const F=y.useCallback(ae=>{d({id:ae},{replace:!1}),a(ae)},[d,a]),P=y.useCallback(()=>{d({},{replace:!1}),a(null)},[d,a]),L=y.useCallback(ae=>{if(!O)return;const De={id:O};ae==="issue"&&(De.tab="issue"),d(De,{replace:!1})},[O,d]),B=y.useCallback(ae=>{O&&d({id:O,tab:"issue",issueId:ae},{replace:!1})},[O,d]),Y=y.useCallback(()=>{O&&d({id:O,tab:"issue"},{replace:!1})},[O,d]),re=N?p.find(ae=>ae.id===N)??null:null,[X,K]=y.useState(new Set);y.useEffect(()=>{if(!A||!re){K(new Set);return}UE(A,re.number).then(ae=>K(new Set(ae.map(De=>De.id)))).catch(()=>K(new Set))},[A,re]);const V=async ae=>{if(!re)return;X.has(ae.id)?await mn.getState().unlinkIssue(A,re.number,ae.number)&&K(we=>{const Le=new Set(we);return Le.delete(ae.id),Le}):await C(A,re.number,ae.number)&&K(we=>new Set(we).add(ae.id))},H=p.filter(ae=>ae.state==="open").length,G=p.filter(ae=>ae.state==="merged").length,Q=p.filter(ae=>ae.state==="closed").length,D=e==="all"?p:p.filter(ae=>ae.state===e),z=n.trim().toLowerCase(),$=z?D.filter(ae=>`#${ae.number} ${ae.title} ${ae.headBranch} ${ae.baseBranch}`.toLowerCase().includes(z)):D,M=i.trim().toLowerCase(),le=M?I.filter(ae=>`#${ae.number} ${ae.title}`.toLowerCase().includes(M)):I,oe=p.find(ae=>ae.id===O)??null,ne=A?re??oe:null;return c.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 overflow-hidden",children:[c.jsxs("div",{className:ie("shrink-0 flex-col bg-surface",ne?"hidden md:flex md:w-80 border-r border-line":"flex w-full"),children:[N?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-3",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-blue-400",children:"选择 Issue 关联"}),c.jsxs("button",{type:"button",onClick:S,className:"flex h-7 items-center gap-1 rounded-md px-2 text-xs text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:[c.jsx(At,{className:"h-3.5 w-3.5"}),"完成"]})]}),c.jsx("div",{className:"border-b border-line px-3 py-2",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2 py-1",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:i,onChange:ae=>o(ae.target.value),placeholder:"搜索 issue...",className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),i&&c.jsx("button",{type:"button",onClick:()=>o(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:le.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:I.length===0?"暂无 Issue,请先同步":"无匹配 Issue"}):c.jsx("ul",{className:"space-y-0.5",children:le.map(ae=>c.jsx(BEe,{issue:ae,linked:X.has(ae.id),onToggle:()=>void V(ae)},ae.id))})})]}):ne?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-3",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-fg-3",children:"Pull Requests"}),A&&c.jsx("button",{type:"button",onClick:()=>A&&void x(A),disabled:b,title:"同步",className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:c.jsx(Rl,{className:ie("h-3.5 w-3.5",b&&"animate-spin")})})]}),c.jsx("div",{className:"flex border-b border-line",children:wI.map(({key:ae,label:De})=>{const xe=ae==="open"?H:ae==="merged"?G:ae==="closed"?Q:p.length;return c.jsxs("button",{type:"button",onClick:()=>t(ae),className:ie("flex flex-1 items-center justify-center gap-1.5 py-2 text-xs font-medium transition-colors",e===ae?"border-b-2 border-blue-500 text-blue-500":"text-fg-4 hover:text-fg-2"),children:[De,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",e===ae?"bg-blue-500/10 text-blue-500":"bg-elevated text-fg-5"),children:xe})]},ae)})}),c.jsx("div",{className:"border-b border-line px-3 py-2",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2 py-1",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:n,onChange:ae=>r(ae.target.value),placeholder:"搜索 PR...",className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),n&&c.jsx("button",{type:"button",onClick:()=>r(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})})]}):c.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-2 border-b border-line px-4 py-2.5",children:[c.jsx("span",{className:"shrink-0 text-sm font-semibold text-fg md:order-1",children:"Pull Requests"}),c.jsx("button",{type:"button",onClick:()=>A&&void x(A),disabled:b||!A,title:"同步 PR",className:"ml-auto flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2 disabled:opacity-40 md:order-last md:ml-0",children:c.jsx(Rl,{className:ie("h-4 w-4",b&&"animate-spin")})}),c.jsx("div",{className:"w-full md:order-2 md:w-auto",children:c.jsx("div",{className:"flex shrink-0 items-center rounded-lg bg-elevated/60 p-0.5",children:wI.map(({key:ae,label:De})=>{const xe=ae==="open"?H:ae==="merged"?G:ae==="closed"?Q:p.length;return c.jsxs("button",{type:"button",onClick:()=>t(ae),className:ie("flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",e===ae?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-2"),children:[De,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",e===ae?"bg-blue-500/10 text-blue-500":"text-fg-5"),children:xe})]},ae)})})}),c.jsx("div",{className:"w-full md:order-3 md:w-auto md:min-w-0 md:flex-1 md:px-1",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2.5 py-1.5",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:n,onChange:ae=>r(ae.target.value),placeholder:"搜索 PR...",className:"min-w-0 flex-1 bg-transparent text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),n&&c.jsx("button",{type:"button",onClick:()=>r(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})})]}),!N&&c.jsx("div",{className:ie("flex-1 overflow-y-auto",ne?"px-2 py-2":"px-3 py-3"),children:A?$.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-fg-5",children:[c.jsx(Il,{className:"h-8 w-8"}),c.jsx("p",{className:"font-mono text-xs",children:p.length===0?"点击 ↻ 同步 PR":"没有匹配的 PR"})]}):c.jsx("ul",{className:ie(ne?"space-y-0.5":"space-y-1"),children:$.map(ae=>ne?c.jsx(jEe,{pr:ae,isActive:ae.id===(O??N),onSelect:()=>F(ae.id)},ae.id):c.jsx(PEe,{pr:ae,onSelect:()=>F(ae.id)},ae.id))}):c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:"请先选择一个仓库"})})]}),ne?c.jsx(UEe,{pr:ne,tab:k,issueId:j,onTabChange:L,onSelectIssue:B,onBackToIssueList:Y,onBack:()=>{P(),N&&S()},onClose:()=>{P(),N&&S()},onEnterMatch:()=>_(ne.id),onNavigateToIssue:ae=>{m&&f(`/${encodeURIComponent(m)}/dev/issues?id=${encodeURIComponent(ae)}`)}},`${ne.id}-${N??"view"}`):c.jsx("div",{className:"hidden flex-1 items-center justify-center md:flex",children:c.jsxs("div",{className:"text-center text-fg-5",children:[c.jsx(Il,{className:"mx-auto h-12 w-12 opacity-20"}),c.jsx("p",{className:"mt-3 font-mono text-xs",children:"选择一个 PR 查看详情"})]})})]})}function _I(e,t){return e?`/${encodeURIComponent(e)}/dev/${t}`:`/dev/${t}`}function TI(){const e=zn(),t=or(),n=We(qr),r=Je(d=>d.issues),a=mn(d=>d.pulls),i=t.pathname.endsWith("/pulls")?"pulls":"issues",o=r.filter(d=>d.state==="open").length,u=a.filter(d=>d.state==="open").length;return c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[c.jsx("div",{className:"flex shrink-0 items-center gap-1 border-b border-line bg-surface px-3 py-2",children:c.jsxs("div",{className:"flex items-center rounded-lg bg-elevated/60 p-0.5",children:[c.jsxs("button",{type:"button",onClick:()=>e(_I(n,"issues")),className:ie("flex items-center gap-1.5 rounded-md px-3 py-1 text-xs font-medium transition-colors",i==="issues"?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-2"),children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),"Issues",c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",i==="issues"?"bg-blue-500/10 text-blue-500":"text-fg-5"),children:o})]}),c.jsxs("button",{type:"button",onClick:()=>e(_I(n,"pulls")),className:ie("flex items-center gap-1.5 rounded-md px-3 py-1 text-xs font-medium transition-colors",i==="pulls"?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-2"),children:[c.jsx(Il,{className:"h-3.5 w-3.5"}),"PRs",c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",i==="pulls"?"bg-blue-500/10 text-blue-500":"text-fg-5"),children:u})]})]})}),c.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 overflow-hidden",children:i==="issues"?c.jsx(REe,{}):c.jsx(FEe,{})})]})}const zEe=/^[\w.-]+@([\w.-]+):([\w.-]+)\/([\w.-]+?)(?:\.git)?$/,HEe=/^https?:\/\/([\w.-]+)(?::\d+)?\/([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:\/)?$/,$Ee=/^ssh:\/\/[\w.-]+@([\w.-]+)(?::\d+)?\/([\w.-]+)\/([\w.-]+?)(?:\.git)?$/;function nB(e){for(const t of[zEe,HEe,$Ee]){const n=e.match(t);if(n)return n[1]}return null}function AI({onSelect:e}){const[t,n]=y.useState(""),[r,a]=y.useState(null),[i,o]=y.useState([]),[u,d]=y.useState(!0),[f,m]=y.useState(""),[p,b]=y.useState(!1),x=y.useCallback(async A=>{d(!0),m("");try{const I=await s$(A,p);n(I.path),a(I.parent),o(I.entries)}catch(I){const O=I instanceof Error?I.message:"无法读取目录";try{const k=JSON.parse(O);m(k.error??O)}catch{m(O)}}d(!1)},[p]);y.useEffect(()=>{x()},[x]);const E=A=>{x(`${t}/${A}`)},N=()=>{r&&x(r)},_=A=>{const O=`/${t.split("/").filter(Boolean).slice(0,A+1).join("/")}`;x(O)},S=A=>{e(`${t}/${A}`)},C=t.split("/").filter(Boolean);return c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto text-xs",children:[c.jsx("button",{type:"button",onClick:()=>void x("/"),className:"shrink-0 rounded px-1 py-0.5 text-fg-4 hover:bg-elevated hover:text-fg-2",children:"/"}),C.map((A,I)=>c.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[c.jsx(Oo,{className:"h-3 w-3 text-fg-5"}),c.jsx("button",{type:"button",onClick:()=>_(I),className:`rounded px-1 py-0.5 ${I===C.length-1?"font-medium text-fg":"text-fg-4 hover:bg-elevated hover:text-fg-2"}`,children:A})]},I))]}),c.jsx("button",{type:"button",onClick:()=>b(A=>!A),className:"ml-2 shrink-0 rounded-md p-1 text-fg-4 hover:bg-elevated hover:text-fg-2",title:p?"隐藏隐藏文件":"显示隐藏文件",children:p?c.jsx(GR,{className:"h-3.5 w-3.5"}):c.jsx(qR,{className:"h-3.5 w-3.5"})})]}),c.jsx("div",{className:"max-h-52 overflow-y-auto rounded-lg border border-line bg-base",children:u?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 animate-spin text-fg-4"})}):f?c.jsx("div",{className:"px-3 py-4 text-center text-xs text-red-500",children:f}):c.jsxs(c.Fragment,{children:[r!==null&&c.jsxs("button",{type:"button",onClick:N,className:"flex w-full items-center gap-2 border-b border-line px-3 py-2 text-left text-sm text-fg-3 hover:bg-elevated",children:[c.jsx(iA,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{children:".."})]}),i.length===0&&c.jsx("div",{className:"px-3 py-4 text-center text-xs text-fg-5",children:"空目录"}),i.map(A=>c.jsxs("div",{className:"flex items-center border-b border-line last:border-0",children:[c.jsxs("button",{type:"button",onClick:()=>A.isGitRepo?S(A.name):E(A.name),className:"flex min-w-0 flex-1 items-center gap-2 px-3 py-2 text-left text-sm hover:bg-elevated",children:[A.isGitRepo?c.jsx(Gl,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):c.jsx(iA,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:`truncate ${A.isGitRepo?"text-fg font-medium":"text-fg-3"}`,children:A.name}),A.isGitRepo&&c.jsx("span",{className:"ml-auto shrink-0 rounded bg-emerald-500/10 px-1.5 py-0.5 text-[10px] font-medium text-emerald-500",children:"git"})]}),A.isGitRepo&&c.jsx("button",{type:"button",onClick:()=>E(A.name),className:"shrink-0 px-2 py-2 text-fg-5 hover:text-fg-2",title:"进入目录",children:c.jsx(Oo,{className:"h-3.5 w-3.5"})})]},A.name))]})})]})}function YEe({onClose:e}){const t=zn(),[n,r]=y.useState("browse"),[a,i]=y.useState(""),[o,u]=y.useState(""),[d,f]=y.useState(""),[m,p]=y.useState(""),[b,x]=y.useState(!1),[E,N]=y.useState("opencode"),[_,S]=y.useState(!1),[C,A]=y.useState(!1),[I,O]=y.useState(""),[k,j]=y.useState(null),F=We(G=>G.addRepo),P=o.trim()!==""&&d.trim()!==""&&a.trim()!==""&&!_&&!C,L=G=>{const Q=G instanceof Error?G.message:"操作失败";try{return JSON.parse(Q).error??Q}catch{return Q}},B=async G=>{const Q=G.trim();if(Q){S(!0),O("");try{const D=await i$(Q);i(D.localPath),D.name&&u(D.name),D.gitUrl&&f(D.gitUrl)}catch(D){O(L(D))}S(!1)}},Y=y.useRef(B);Y.current=B,y.useEffect(()=>{if(n!=="browse")return;const G=a.trim();if(!G)return;const Q=setTimeout(()=>{Y.current(G)},OY);return()=>clearTimeout(Q)},[a,n]),y.useEffect(()=>{const G=d.trim();if(!G){j(null);return}const Q=nB(G);if(!Q){j(null);return}let D=!1;const z=setTimeout(()=>{FE().then($=>{if(D)return;const M=$.some(le=>le.host.toLowerCase()===Q.toLowerCase());j(M?null:Q)}).catch(()=>{D||j(null)})},kY);return()=>{D=!0,clearTimeout(z)}},[d]);const re=G=>{i(G),O(""),B(G)},X=G=>{p(G),x(!1)},K=async()=>{const G=d.trim();if(!G){O("请输入 Git 仓库地址");return}A(!0),O("");try{const Q=m.trim()||void 0,D=await o$(G,Q);i(D.localPath),D.name&&u(D.name),D.gitUrl&&f(D.gitUrl)}catch(Q){O(L(Q))}A(!1)},V=async()=>{if(!P)return;O(""),await F(o.trim(),d.trim(),a.trim(),E)&&e()},H=G=>{r(G),i(""),u(""),f(""),p(""),x(!1),O(""),j(null)};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:e,children:c.jsxs("div",{className:"w-full max-w-lg rounded-xl border border-line bg-surface p-6 shadow-2xl",onClick:G=>G.stopPropagation(),children:[c.jsxs("div",{className:"mb-5 flex items-center justify-between",children:[c.jsx("h2",{className:"text-base font-semibold text-fg",children:"添加仓库"}),c.jsx("button",{type:"button",onClick:e,className:"rounded-md p-1 text-fg-4 hover:bg-elevated hover:text-fg-2",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"mb-4 flex gap-1 rounded-lg border border-line bg-base p-1",children:[c.jsxs("button",{type:"button",onClick:()=>H("browse"),className:`flex flex-1 items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors ${n==="browse"?"bg-elevated text-fg shadow-sm":"text-fg-4 hover:text-fg-2"}`,children:[c.jsx(Pz,{className:"h-3.5 w-3.5"}),"已有仓库"]}),c.jsxs("button",{type:"button",onClick:()=>H("clone"),className:`flex flex-1 items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors ${n==="clone"?"bg-elevated text-fg shadow-sm":"text-fg-4 hover:text-fg-2"}`,children:[c.jsx(Gl,{className:"h-3.5 w-3.5"}),"克隆新仓库"]})]}),c.jsxs("div",{className:"flex flex-col gap-4",children:[n==="browse"?c.jsxs(c.Fragment,{children:[c.jsx(AI,{onSelect:re}),c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{htmlFor:"m-path",className:"text-xs font-medium text-fg-3",children:"本地路径"}),c.jsx("input",{id:"m-path",value:a,onChange:G=>i(G.target.value),onBlur:G=>void B(G.target.value),placeholder:"/home/you/code/repo",className:"w-full rounded-lg border border-line bg-base px-3 py-2 font-mono text-sm text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"}),c.jsx("span",{className:"text-[11px] text-fg-5",children:_?"正在读取 Git 信息…":"点选目录或手动输入路径"})]})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{htmlFor:"m-clone-url",className:"text-xs font-medium text-fg-3",children:"Git 仓库地址"}),c.jsx("input",{id:"m-clone-url",value:d,onChange:G=>f(G.target.value),placeholder:"https://github.com/org/repo.git",className:"w-full rounded-lg border border-line bg-base px-3 py-2 font-mono text-xs text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]}),c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{className:"text-xs font-medium text-fg-3",children:"目标目录"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{value:m,onChange:G=>p(G.target.value),placeholder:"默认: ~/.fourth-spark/repos/",className:"min-w-0 flex-1 rounded-lg border border-line bg-base px-3 py-2 font-mono text-xs text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"}),c.jsx("button",{type:"button",onClick:()=>x(G=>!G),className:`shrink-0 rounded-lg border px-2.5 py-2 text-sm transition-colors ${b?"border-blue-500 bg-blue-500/10 text-blue-600":"border-line bg-base text-fg-4 hover:bg-elevated hover:text-fg-2"}`,children:c.jsx(kr,{className:`h-3.5 w-3.5 transition-transform ${b?"rotate-180":""}`})})]}),b&&c.jsx(AI,{onSelect:X}),c.jsx("span",{className:"text-[11px] text-fg-5",children:"留空则克隆到默认目录,选择目录后仓库将克隆到该目录下"})]}),c.jsx("button",{type:"button",onClick:K,disabled:C||!d.trim(),className:"w-full rounded-lg bg-emerald-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-fg-6 disabled:text-fg-4",children:C?c.jsxs("span",{className:"flex items-center justify-center gap-1.5",children:[c.jsx(nn,{className:"h-3.5 w-3.5 animate-spin"}),"正在克隆仓库…"]}):"克隆"}),a&&c.jsxs("div",{className:"rounded-md bg-emerald-500/10 px-3 py-2 text-xs text-emerald-600",children:["克隆完成: ",c.jsx("span",{className:"font-mono",children:a})]})]}),c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{htmlFor:"m-name",className:"text-xs font-medium text-fg-3",children:"名称"}),c.jsx("input",{id:"m-name",value:o,onChange:G=>u(G.target.value),placeholder:"my-project",className:"w-full rounded-lg border border-line bg-base px-3 py-2 text-sm text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]}),n==="browse"&&c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{htmlFor:"m-git",className:"text-xs font-medium text-fg-3",children:"Git 远程地址"}),c.jsx("input",{id:"m-git",value:d,onChange:G=>f(G.target.value),placeholder:"https://github.com/org/repo.git",className:"w-full rounded-lg border border-line bg-base px-3 py-2 font-mono text-xs text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]}),k&&c.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsxs("span",{children:["源站 ",c.jsx("strong",{children:k})," 尚未配置访问凭证,Issue/PR 同步将不可用。",c.jsx("button",{type:"button",onClick:()=>{e(),t("/settings")},className:"ml-1 font-medium underline hover:text-amber-700",children:"去配置"})]})]}),c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{className:"text-xs font-medium text-fg-3",children:"运行时"}),c.jsx("div",{className:"flex gap-2",children:[{value:"opencode",label:"OpenCode"},{value:"claude-code",label:"Claude Code"}].map(G=>c.jsx("button",{type:"button",onClick:()=>N(G.value),className:`flex-1 rounded-lg border px-3 py-2 text-sm font-medium transition-colors ${E===G.value?"border-blue-500 bg-blue-500/10 text-blue-600":"border-line bg-base text-fg-4 hover:bg-elevated hover:text-fg-2"}`,children:G.label},G.value))}),c.jsx("span",{className:"text-[11px] text-fg-5",children:E==="claude-code"?"需要本地安装 Claude Code CLI":"需要本地安装 OpenCode CLI"})]}),I&&c.jsx("p",{className:"rounded-md bg-red-500/10 px-3 py-2 text-xs text-red-500",children:I}),c.jsxs("div",{className:"mt-1 flex items-center justify-end gap-2",children:[c.jsx("button",{type:"button",onClick:e,className:"rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"取消"}),c.jsx("button",{type:"button",onClick:V,disabled:!P,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 disabled:cursor-not-allowed disabled:bg-fg-6 disabled:text-fg-4",children:"添加仓库"})]})]})]})})}function qEe({repoId:e,repoName:t,onClose:n}){const[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(!0),[f,m]=y.useState(!1),[p,b]=y.useState(null);y.useEffect(()=>{uY(e).then(N=>{a(N.content),o(N.content),d(!1)}).catch(N=>{b(N instanceof Error?N.message:String(N)),d(!1)})},[e]);const x=async()=>{m(!0),b(null);try{await cY(e,r),o(r)}catch(N){b(N instanceof Error?N.message:String(N))}m(!1)},E=r!==i;return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:n,children:c.jsxs("div",{className:"flex w-full max-w-2xl flex-col rounded-xl border border-line bg-surface p-6 shadow-2xl",onClick:N=>N.stopPropagation(),children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsxs("h2",{className:"text-base font-semibold text-fg",children:[t," — AGENTS.md"]}),c.jsx("p",{className:"mt-0.5 text-xs text-fg-4",children:"仅对此仓库生效,修改后 opencode 热加载即时生效。"})]}),c.jsx("button",{type:"button",onClick:n,className:"shrink-0 rounded-md p-1 text-fg-4 hover:bg-elevated hover:text-fg-2",children:c.jsx(At,{className:"h-4 w-4"})})]}),p&&c.jsxs("div",{className:"mb-3 flex items-start gap-2 rounded-lg bg-red-500/10 px-3 py-2 text-xs text-red-400",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"min-w-0 break-words",children:p})]}),u?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-16 text-fg-5",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin"}),c.jsx("p",{className:"text-xs",children:"加载中…"})]}):c.jsx("textarea",{value:r,onChange:N=>a(N.target.value),spellCheck:!1,className:"h-96 w-full resize-y rounded-lg border border-line bg-base px-4 py-3 font-mono text-sm leading-relaxed text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20",placeholder:`# AGENTS.md
651
651
 
652
- 在此编写该仓库的 Agent 指令…`}),c.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[c.jsx("button",{type:"button",onClick:n,className:"rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"关闭"}),c.jsxs("button",{type:"button",onClick:()=>void x(),disabled:f||!E,className:"flex items-center gap-1.5 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),f?"保存中…":"保存"]})]})]})})}const fE=1024,hE=fE*1024,CI=hE*1024;function kI(e){return!e||e<=0?"0 B":e<fE?`${e} B`:e<hE?`${(e/fE).toFixed(1)} KB`:e<CI?`${(e/hE).toFixed(1)} MB`:`${(e/CI).toFixed(2)} GB`}const Dv="ws/";function GEe({repoId:e}){const[t,n]=y.useState(!1),[r,a]=y.useState(null),[i,o]=y.useState(!1),[u,d]=y.useState(null),{data:f,loading:m,error:p,reload:b}=lc(()=>m$(e),[e,t],{skip:!t,showErrorToast:!1,errorMessage:"加载失败"}),x=u??p,E=async C=>{a(C),d(null);try{await p$(e,C),b()}catch(A){d(A instanceof Li?A.message:"删除失败")}a(null)},N=async()=>{o(!0),d(null);try{await g$(e),b()}catch(C){d(C instanceof Li?C.message:"清理失败")}o(!1)},_=(f==null?void 0:f.length)??0,S=(f==null?void 0:f.reduce((C,A)=>C+(A.diskUsage||0),0))??0;return c.jsxs("div",{className:"mt-3 border-t border-line pt-3",children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>n(C=>!C),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left text-xs font-medium text-fg-3 transition-colors hover:text-fg-2",children:[t?c.jsx(OE,{className:"h-3 w-3 shrink-0"}):c.jsx(kr,{className:"h-3 w-3 shrink-0"}),c.jsx(Gl,{className:"h-3 w-3 shrink-0 text-fg-5"}),c.jsx("span",{children:"工作空间"}),f!==null&&c.jsxs("span",{className:"text-fg-5",children:["(",_,") · ",kI(S)]})]}),t&&_>0&&c.jsxs("button",{type:"button",onClick:()=>void N(),disabled:i,className:"flex h-6 shrink-0 items-center gap-1 rounded border border-line px-2 text-xs text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-50",children:[i?c.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):null,"清理已合并"]})]}),t&&c.jsxs("div",{className:"mt-2",children:[x&&c.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 rounded border border-red-500/30 bg-red-500/5 px-2 py-1 text-xs text-red-600",children:[c.jsx("span",{className:"truncate",children:x}),c.jsx("button",{type:"button",onClick:()=>d(null),className:"shrink-0 rounded p-0.5 transition-colors hover:bg-red-500/10",children:c.jsx(At,{className:"h-3 w-3"})})]}),m&&f===null?c.jsx("div",{className:"flex justify-center py-3",children:c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-fg-5 border-t-transparent"})}):_===0?c.jsx("p",{className:"py-2 text-center text-xs text-fg-5",children:"暂无工作空间"}):c.jsx("ul",{className:"space-y-1",children:f==null?void 0:f.map(C=>{const A=C.branch.startsWith(Dv),I=A?C.branch.slice(Dv.length):C.branch,O=C.status==="active"?"bg-emerald-500/10 text-emerald-600":C.status==="idle"?"bg-amber-500/10 text-amber-600":"bg-fg-6/30 text-fg-4",k=C.status==="active"?"活跃":C.status==="idle"?"空闲":C.status==="merged"?"已合并":C.status==="stale"?"陈旧":C.status,j=C.status!=="active";return c.jsxs("li",{className:"flex items-center gap-2 rounded-md border border-line bg-elevated/40 px-2 py-1.5 text-xs",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[C.running&&C.port&&c.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",title:`运行中 :${C.port}`}),c.jsxs("span",{className:"min-w-0 truncate font-mono",children:[A&&c.jsx("span",{className:"text-fg-5",children:Dv}),c.jsx("span",{className:"text-fg-2",children:I})]})]}),c.jsx("span",{className:ie("shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium",O),children:k}),c.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 text-fg-5",children:[c.jsx(Qz,{className:"h-2.5 w-2.5"}),kI(C.diskUsage)]}),c.jsx("button",{type:"button",onClick:()=>void E(C.id),disabled:!j||r===C.id,title:j?"删除工作空间":"活跃工作空间无法删除",className:"flex h-5 w-5 shrink-0 items-center justify-center rounded text-fg-5 transition-colors hover:bg-red-500/10 hover:text-red-500 disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-fg-5",children:r===C.id?c.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsx(a0,{className:"h-3 w-3"})})]},C.id)})})]})]})}function rB(){const e=zn(),t=We(P=>P.repos),n=We(P=>P.activeRepoId),r=We(P=>P.setActiveRepo),a=We(P=>P.removeRepo),i=We(P=>P.loadRepos),[o,u]=y.useState(!1),[d,f]=y.useState(null),[m,p]=y.useState(null),[b,x]=y.useState(null),E=ar(P=>P.addToast),[N,_]=y.useState(null),[S,C]=y.useState(null),A=y.useRef(null),[I,O]=y.useState(null);y.useEffect(()=>{FE().then(P=>O(new Set(P.map(L=>L.host.toLowerCase())))).catch(()=>{})},[]);const k=y.useMemo(()=>{if(!I)return new Set;const P=new Set;for(const L of t){const B=nB(L.gitUrl);B&&!I.has(B.toLowerCase())&&P.add(L.id)}return P},[t,I]);y.useEffect(()=>{if(!S)return;const P=L=>{A.current&&!A.current.contains(L.target)&&C(null)};return document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[S]);const j=async(P,L)=>{p(P);try{L?await c$(P):await u$(P),await i()}catch{}p(null)},F=async P=>{x(P);try{const L=await h$(P);await i();const B=L.alreadyUpToDate?"info":"success";E(L.summary,B,void 0,{persistent:!0})}catch(L){let B="拉取失败";if(L instanceof Li)try{B=JSON.parse(L.message).error??L.message}catch{B=L.message}E(B,"error",void 0,{persistent:!0})}x(null)};return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"mb-6 flex items-center justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("h1",{className:"text-lg font-semibold text-fg",children:"仓库管理"}),c.jsx("p",{className:"mt-0.5 text-sm text-fg-4",children:"管理代码仓库,每个仓库对应一个独立的 Agent 运行环境"})]}),c.jsxs("button",{type:"button",onClick:()=>u(!0),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-blue-600 px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 md:px-4",children:[c.jsx(ua,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden md:inline",children:"添加仓库"})]})]}),t.length===0?c.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-xl border border-dashed border-line-hard py-16 text-center",children:[c.jsx("div",{className:"rounded-full bg-elevated p-3",children:c.jsx(ua,{className:"h-6 w-6 text-fg-4"})}),c.jsx("p",{className:"text-sm font-medium text-fg-3",children:"暂无代码仓库"}),c.jsx("p",{className:"text-xs text-fg-5",children:"添加一个本地仓库开始使用"}),c.jsx("button",{type:"button",onClick:()=>u(!0),className:"mt-2 rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"添加仓库"})]}):c.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:t.map((P,L)=>{const B=P.id===n;return c.jsxs("div",{className:ie("rounded-xl border p-4 transition-colors",B?"border-blue-500/40 bg-blue-500/5":"border-line"),children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>r(P.id),className:"flex min-w-0 items-center gap-2 text-left",children:[B?c.jsx(ql,{className:"h-4 w-4 shrink-0 text-blue-500"}):c.jsx(pz,{className:"h-4 w-4 shrink-0 text-fg-5"}),c.jsx("span",{className:ie("truncate font-medium",B?"text-fg":"text-fg-2"),children:P.name})]}),c.jsxs("span",{className:ie("inline-flex shrink-0 items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium",P.running?"bg-emerald-500/10 text-emerald-600":"bg-fg-6/30 text-fg-4"),children:[c.jsx("span",{className:ie("h-1.5 w-1.5 rounded-full",P.running?"bg-emerald-500":"bg-fg-5")}),P.running?"运行中":"已停止"]})]}),c.jsxs("dl",{className:"mt-3 space-y-1 font-mono text-xs text-fg-4",children:[c.jsxs("div",{className:"flex gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"Git"}),c.jsx("dd",{className:"min-w-0 truncate",children:P.gitUrl})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"路径"}),c.jsxs("dd",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsx("span",{className:"truncate",children:P.localPath}),c.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(P.localPath),title:"复制路径",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:text-fg-3",children:c.jsx($p,{className:"h-3 w-3"})})]})]}),P.running&&P.port&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"直连"}),c.jsxs("dd",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsxs("a",{href:`http://127.0.0.1:${P.port}`,target:"_blank",rel:"noopener noreferrer",className:"truncate text-blue-500 hover:underline",children:["127.0.0.1:",P.port]}),c.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(`http://127.0.0.1:${P.port}`),title:"复制链接",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:text-fg-3",children:c.jsx($p,{className:"h-3 w-3"})})]})]})]}),k.has(P.id)&&c.jsxs("button",{type:"button",onClick:()=>e("/settings"),className:"mt-2 flex w-full items-center gap-1.5 rounded-md bg-amber-500/10 px-2.5 py-1.5 text-left text-xs text-amber-600 transition-colors hover:bg-amber-500/15",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{children:"缺少 Git 源站凭证,Issue/PR 同步不可用"})]}),c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[c.jsx("button",{type:"button",onClick:()=>void F(P.id),disabled:b===P.id,className:"flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-md border border-blue-500/30 px-2.5 text-xs font-medium text-blue-600 transition-colors hover:bg-blue-500/10 disabled:opacity-50",children:b===P.id?c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsxs(c.Fragment,{children:[c.jsx($F,{className:"h-3 w-3"}),"拉取"]})}),c.jsx("button",{type:"button",onClick:()=>void j(P.id,P.running),disabled:m===P.id,className:ie("flex h-8 flex-1 items-center justify-center gap-1.5 rounded-md border text-xs font-medium transition-colors disabled:opacity-50",P.running?"border-amber-500/30 text-amber-600 hover:bg-amber-500/10":"border-emerald-500/30 text-emerald-600 hover:bg-emerald-500/10"),children:m===P.id?c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):P.running?c.jsxs(c.Fragment,{children:[c.jsx(Vv,{className:"h-3 w-3 fill-current"}),"停止"]}):c.jsxs(c.Fragment,{children:[c.jsx(LE,{className:"h-3 w-3 fill-current"}),"启动"]})}),c.jsxs("div",{className:"relative",ref:S===P.id?A:void 0,children:[c.jsx("button",{type:"button","data-guide":L===0?"repo-overflow-btn":void 0,onClick:()=>C(S===P.id?null:P.id),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(IE,{className:"h-4 w-4"})}),S===P.id&&c.jsxs("div",{"data-guide":L===0?"repo-overflow-dropdown":void 0,className:"absolute right-0 top-full z-20 mt-1 min-w-[160px] overflow-hidden rounded-lg border border-line bg-elevated shadow-lg",children:[c.jsx("button",{type:"button",className:ie("flex w-full items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-base/60",P.runtimeType==="claude-code"?"text-orange-500":"text-sky-500"),onClick:async()=>{C(null);const Y=P.runtimeType==="claude-code"?"opencode":"claude-code";await x$(P.id,Y),i()},children:P.runtimeType==="claude-code"?"Claude → OpenCode":"OpenCode → Claude"}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",onClick:async()=>{C(null),await b$(P.id,!P.worktreeEnabled),i()},children:[c.jsx(Gl,{className:"h-3 w-3"}),c.jsx("span",{children:"Worktree"}),c.jsx("span",{className:ie("ml-auto text-[10px]",P.worktreeEnabled?"text-violet-500":"text-fg-5"),children:P.worktreeEnabled?"已开启":"已关闭"})]}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",onClick:()=>{C(null),_({id:P.id,name:P.name})},children:[c.jsx(Io,{className:"h-3 w-3"}),"配置"]}),c.jsx("div",{className:"my-0.5 border-t border-line"}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-red-500 transition-colors hover:bg-red-500/10",onClick:()=>{C(null),f(P.id)},children:[c.jsx(a0,{className:"h-3 w-3"}),"删除仓库"]})]})]})]}),d===P.id&&c.jsxs("div",{className:"mt-2 flex items-center justify-between rounded-md border border-red-500/20 bg-red-500/5 px-3 py-2",children:[c.jsx("span",{className:"text-xs text-red-500",children:"确认删除此仓库?"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>{a(P.id),f(null)},className:"flex h-6 items-center gap-1 rounded border border-red-500/30 px-2 text-xs text-red-500 transition-colors hover:bg-red-500/10",children:[c.jsx(fi,{className:"h-3 w-3"}),"确认"]}),c.jsx("button",{type:"button",onClick:()=>f(null),className:"flex h-6 items-center gap-1 rounded border border-line px-2 text-xs text-fg-4 transition-colors hover:bg-elevated",children:"取消"})]})]}),P.worktreeEnabled&&c.jsx(GEe,{repoId:P.id})]},P.id)})}),c.jsxs("p",{className:"mt-3 text-xs text-fg-5",children:[t.length," 个仓库"]}),o&&c.jsx(YEe,{onClose:()=>u(!1)}),N&&c.jsx(qEe,{repoId:N.id,repoName:N.name,onClose:()=>_(null)})]})}function KEe(){return c.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:c.jsx("div",{className:"mx-auto max-w-4xl",children:c.jsx(rB,{})})})}/*! Capacitor: https://capacitorjs.com/ - MIT License */var Sc;(function(e){e.Unimplemented="UNIMPLEMENTED",e.Unavailable="UNAVAILABLE"})(Sc||(Sc={}));class jv extends Error{constructor(t,n,r){super(t),this.message=t,this.code=n,this.data=r}}const VEe=e=>{var t,n;return e!=null&&e.androidBridge?"android":!((n=(t=e==null?void 0:e.webkit)===null||t===void 0?void 0:t.messageHandlers)===null||n===void 0)&&n.bridge?"ios":"web"},WEe=e=>{const t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},a=()=>t!==null?t.name:VEe(e),i=()=>a()!=="web",o=p=>{const b=f.get(p);return!!(b!=null&&b.platforms.has(a())||u(p))},u=p=>{var b;return(b=n.PluginHeaders)===null||b===void 0?void 0:b.find(x=>x.name===p)},d=p=>e.console.error(p),f=new Map,m=(p,b={})=>{const x=f.get(p);if(x)return console.warn(`Capacitor plugin "${p}" already registered. Cannot register plugins twice.`),x.proxy;const E=a(),N=u(p);let _;const S=async()=>(!_&&E in b?_=typeof b[E]=="function"?_=await b[E]():_=b[E]:t!==null&&!_&&"web"in b&&(_=typeof b.web=="function"?_=await b.web():_=b.web),_),C=(F,P)=>{var L,B;if(N){const Y=N==null?void 0:N.methods.find(re=>P===re.name);if(Y)return Y.rtype==="promise"?re=>n.nativePromise(p,P.toString(),re):(re,X)=>n.nativeCallback(p,P.toString(),re,X);if(F)return(L=F[P])===null||L===void 0?void 0:L.bind(F)}else{if(F)return(B=F[P])===null||B===void 0?void 0:B.bind(F);throw new jv(`"${p}" plugin is not implemented on ${E}`,Sc.Unimplemented)}},A=F=>{let P;const L=(...B)=>{const Y=S().then(re=>{const X=C(re,F);if(X){const K=X(...B);return P=K==null?void 0:K.remove,K}else throw new jv(`"${p}.${F}()" is not implemented on ${E}`,Sc.Unimplemented)});return F==="addListener"&&(Y.remove=async()=>P()),Y};return L.toString=()=>`${F.toString()}() { [capacitor code] }`,Object.defineProperty(L,"name",{value:F,writable:!1,configurable:!1}),L},I=A("addListener"),O=A("removeListener"),k=(F,P)=>{const L=I({eventName:F},P),B=async()=>{const re=await L;O({eventName:F,callbackId:re},P)},Y=new Promise(re=>L.then(()=>re({remove:B})));return Y.remove=async()=>{console.warn("Using addListener() without 'await' is deprecated."),await B()},Y},j=new Proxy({},{get(F,P){switch(P){case"$$typeof":return;case"toJSON":return()=>({});case"addListener":return N?k:I;case"removeListener":return O;default:return A(P)}}});return r[p]=j,f.set(p,{name:p,proxy:j,platforms:new Set([...Object.keys(b),...N?[E]:[]])}),j};return n.convertFileSrc||(n.convertFileSrc=p=>p),n.getPlatform=a,n.handleError=d,n.isNativePlatform=i,n.isPluginAvailable=o,n.registerPlugin=m,n.Exception=jv,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},XEe=e=>e.Capacitor=WEe(e),Wg=XEe(typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}),ub=Wg.registerPlugin;class sw{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(t,n){let r=!1;this.listeners[t]||(this.listeners[t]=[],r=!0),this.listeners[t].push(n);const i=this.windowListeners[t];i&&!i.registered&&this.addWindowListener(i),r&&this.sendRetainedArgumentsForEvent(t);const o=async()=>this.removeListener(t,n);return Promise.resolve({remove:o})}async removeAllListeners(){this.listeners={};for(const t in this.windowListeners)this.removeWindowListener(this.windowListeners[t]);this.windowListeners={}}notifyListeners(t,n,r){const a=this.listeners[t];if(!a){if(r){let i=this.retainedEventArguments[t];i||(i=[]),i.push(n),this.retainedEventArguments[t]=i}return}a.forEach(i=>i(n))}hasListeners(t){var n;return!!(!((n=this.listeners[t])===null||n===void 0)&&n.length)}registerWindowListener(t,n){this.windowListeners[n]={registered:!1,windowEventName:t,pluginEventName:n,handler:r=>{this.notifyListeners(n,r)}}}unimplemented(t="not implemented"){return new Wg.Exception(t,Sc.Unimplemented)}unavailable(t="not available"){return new Wg.Exception(t,Sc.Unavailable)}async removeListener(t,n){const r=this.listeners[t];if(!r)return;const a=r.indexOf(n);a!==-1&&this.listeners[t].splice(a,1),this.listeners[t].length||this.removeWindowListener(this.windowListeners[t])}addWindowListener(t){window.addEventListener(t.windowEventName,t.handler),t.registered=!0}removeWindowListener(t){t&&(window.removeEventListener(t.windowEventName,t.handler),t.registered=!1)}sendRetainedArgumentsForEvent(t){const n=this.retainedEventArguments[t];n&&(delete this.retainedEventArguments[t],n.forEach(r=>{this.notifyListeners(t,r)}))}}const OI=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),II=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent);class QEe extends sw{async getCookies(){const t=document.cookie,n={};return t.split(";").forEach(r=>{if(r.length<=0)return;let[a,i]=r.replace(/=/,"CAP_COOKIE").split("CAP_COOKIE");a=II(a).trim(),i=II(i).trim(),n[a]=i}),n}async setCookie(t){try{const n=OI(t.key),r=OI(t.value),a=t.expires?`; expires=${t.expires.replace("expires=","")}`:"",i=(t.path||"/").replace("path=",""),o=t.url!=null&&t.url.length>0?`domain=${t.url}`:"";document.cookie=`${n}=${r||""}${a}; path=${i}; ${o};`}catch(n){return Promise.reject(n)}}async deleteCookie(t){try{document.cookie=`${t.key}=; Max-Age=0`}catch(n){return Promise.reject(n)}}async clearCookies(){try{const t=document.cookie.split(";")||[];for(const n of t)document.cookie=n.replace(/^ +/,"").replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)}catch(t){return Promise.reject(t)}}async clearAllCookies(){try{await this.clearCookies()}catch(t){return Promise.reject(t)}}}ub("CapacitorCookies",{web:()=>new QEe});const ZEe=async e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const a=r.result;t(a.indexOf(",")>=0?a.split(",")[1]:a)},r.onerror=a=>n(a),r.readAsDataURL(e)}),JEe=(e={})=>{const t=Object.keys(e);return Object.keys(e).map(a=>a.toLocaleLowerCase()).reduce((a,i,o)=>(a[i]=e[t[o]],a),{})},eNe=(e,t=!0)=>e?Object.entries(e).reduce((r,a)=>{const[i,o]=a;let u,d;return Array.isArray(o)?(d="",o.forEach(f=>{u=t?encodeURIComponent(f):f,d+=`${i}=${u}&`}),d.slice(0,-1)):(u=t?encodeURIComponent(o):o,d=`${i}=${u}`),`${r}&${d}`},"").substr(1):null,tNe=(e,t={})=>{const n=Object.assign({method:e.method||"GET",headers:e.headers},t),a=JEe(e.headers)["content-type"]||"";if(typeof e.data=="string")n.body=e.data;else if(a.includes("application/x-www-form-urlencoded")){const i=new URLSearchParams;for(const[o,u]of Object.entries(e.data||{}))i.set(o,u);n.body=i.toString()}else if(a.includes("multipart/form-data")||e.data instanceof FormData){const i=new FormData;if(e.data instanceof FormData)e.data.forEach((u,d)=>{i.append(d,u)});else for(const u of Object.keys(e.data))i.append(u,e.data[u]);n.body=i;const o=new Headers(n.headers);o.delete("content-type"),n.headers=o}else(a.includes("application/json")||typeof e.data=="object")&&(n.body=JSON.stringify(e.data));return n};class nNe extends sw{async request(t){const n=tNe(t,t.webFetchExtra),r=eNe(t.params,t.shouldEncodeUrlParams),a=r?`${t.url}?${r}`:t.url,i=await fetch(a,n),o=i.headers.get("content-type")||"";let{responseType:u="text"}=i.ok?t:{};o.includes("application/json")&&(u="json");let d,f;switch(u){case"arraybuffer":case"blob":f=await i.blob(),d=await ZEe(f);break;case"json":d=await i.json();break;case"document":case"text":default:d=await i.text()}const m={};return i.headers.forEach((p,b)=>{m[b]=p}),{data:d,headers:m,status:i.status,url:i.url}}async get(t){return this.request(Object.assign(Object.assign({},t),{method:"GET"}))}async post(t){return this.request(Object.assign(Object.assign({},t),{method:"POST"}))}async put(t){return this.request(Object.assign(Object.assign({},t),{method:"PUT"}))}async patch(t){return this.request(Object.assign(Object.assign({},t),{method:"PATCH"}))}async delete(t){return this.request(Object.assign(Object.assign({},t),{method:"DELETE"}))}}ub("CapacitorHttp",{web:()=>new nNe});var RI;(function(e){e.Dark="DARK",e.Light="LIGHT",e.Default="DEFAULT"})(RI||(RI={}));var MI;(function(e){e.StatusBar="StatusBar",e.NavigationBar="NavigationBar"})(MI||(MI={}));class rNe extends sw{async setStyle(){this.unavailable("not available for web")}async setAnimation(){this.unavailable("not available for web")}async show(){this.unavailable("not available for web")}async hide(){this.unavailable("not available for web")}}ub("SystemBars",{web:()=>new rNe});const aNe="modulepreload",iNe=function(e){return"/"+e},DI={},sNe=function(t,n,r){let a=Promise.resolve();if(n&&n.length>0){let o=function(f){return Promise.all(f.map(m=>Promise.resolve(m).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const u=document.querySelector("meta[property=csp-nonce]"),d=(u==null?void 0:u.nonce)||(u==null?void 0:u.getAttribute("nonce"));a=o(n.map(f=>{if(f=iNe(f),f in DI)return;DI[f]=!0;const m=f.endsWith(".css"),p=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${f}"]${p}`))return;const b=document.createElement("link");if(b.rel=m?"stylesheet":aNe,m||(b.as="script"),b.crossOrigin="",b.href=f,d&&b.setAttribute("nonce",d),document.head.appendChild(b),m)return new Promise((x,E)=>{b.addEventListener("load",x),b.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${f}`)))})}))}function i(o){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=o,window.dispatchEvent(u),!u.defaultPrevented)throw o}return a.then(o=>{for(const u of o||[])u.status==="rejected"&&i(u.reason);return t().catch(i)})},Gu=ub("SpeechRecognition",{web:()=>sNe(()=>import("./web-ChiXGxSr.js"),[]).then(e=>new e.SpeechRecognitionWeb)});function oNe(e,t){const n=e.length,r=new ArrayBuffer(44+n*2),a=new DataView(r),i=(o,u)=>{for(let d=0;d<u.length;d++)a.setUint8(o+d,u.charCodeAt(d))};i(0,"RIFF"),a.setUint32(4,36+n*2,!0),i(8,"WAVE"),i(12,"fmt "),a.setUint32(16,16,!0),a.setUint16(20,1,!0),a.setUint16(22,1,!0),a.setUint32(24,t,!0),a.setUint32(28,t*2,!0),a.setUint16(32,2,!0),a.setUint16(34,16,!0),i(36,"data"),a.setUint32(40,n*2,!0);for(let o=0;o<n;o++){const u=Math.max(-1,Math.min(1,e[o]));a.setInt16(44+o*2,u<0?u*32768:u*32767,!0)}return new Blob([r],{type:"audio/wav"})}const mE=Wg.isNativePlatform(),Lv=!mE&&typeof window<"u"?window.SpeechRecognition??window.webkitSpeechRecognition:void 0,Pv=16e3;function lNe(e="zh-CN"){const[t,n]=y.useState(!1),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(null),[f,m]=y.useState(0),[p,b]=y.useState("idle"),x=y.useRef(null),E=y.useRef(!1),N=y.useRef([]),_=y.useRef(!1),S=y.useRef(null),C=y.useRef(!1),A=y.useRef(""),I=y.useRef(null),O=y.useRef(null),k=y.useRef(null),j=y.useRef([]),F=y.useRef(!1),P=!0,L=y.useCallback(async()=>{var M,le,oe;(M=k.current)==null||M.disconnect(),(le=O.current)==null||le.getTracks().forEach(ne=>ne.stop()),await((oe=I.current)==null?void 0:oe.close().catch(()=>{}));const H=j.current;if(j.current=[],k.current=null,O.current=null,I.current=null,H.length===0||F.current){n(!1),b("idle");return}o("识别中…"),b("recognizing");const G=H.reduce((ne,ae)=>ne+ae.length,0),Q=new Float32Array(G);let D=0;for(const ne of H)Q.set(ne,D),D+=ne.length;const z=oNe(Q,Pv),$=new FormData;$.append("audio",z,"recording.wav");try{const ne=await fetch("/api/transcribe",{method:"POST",body:$});if(F.current)return;if(ne.ok){const{text:ae}=await ne.json();ae?(a(ae),b("done")):b("idle")}else{const ae=await ne.json().catch(()=>({error:`HTTP ${ne.status}`}));d(ae.error??`HTTP ${ne.status}`),b("idle")}}catch(ne){d(`语音识别失败:${ne instanceof Error?ne.message:String(ne)}`),b("idle")}finally{o(""),n(!1)}},[]),B=y.useCallback(async()=>{if(E.current=!0,S.current&&(clearTimeout(S.current),S.current=null),mE){await Gu.stop().catch(()=>{});for(const H of N.current)await H.remove().catch(()=>{});N.current=[],n(!1),o("")}else x.current?x.current.stop():I.current?await L():(n(!1),b("idle"))},[L]),Y=y.useCallback(async()=>{var D;F.current=!1,a(""),o(""),d(null),b("idle");const{available:H}=await Gu.available();if(!H){d("当前设备不支持语音识别");return}if((await Gu.requestPermissions()).speechRecognition!=="granted"){d("请允许语音识别权限");return}const Q=[];Q.push(await Gu.addListener("partialResults",z=>{o(z.matches[0]??"")})),Q.push(await Gu.addListener("listeningState",z=>{const $=z.status==="started";n($),$&&b("recording"),$||o("")})),N.current=Q;try{const z=await Gu.start({language:e,partialResults:!0,maxResults:1});(D=z.matches)!=null&&D.length&&a($=>{var M;return $+((M=z.matches)==null?void 0:M.join(""))})}catch(z){d(`语音识别错误:${z instanceof Error?z.message:String(z)}`);for(const $ of Q)await $.remove().catch(()=>{});N.current=[]}},[e]),re=y.useCallback(()=>{if(!Lv)return!1;F.current=!1,a(""),o(""),A.current="",d(null),b("idle"),E.current=!1;const H=new Lv;H.lang=e,H.continuous=!0,H.interimResults=!0,H.maxAlternatives=1,H.onstart=()=>{n(!0),b("recording"),_.current=!1,S.current=setTimeout(()=>{!_.current&&!E.current&&(C.current=!0,E.current=!0,H.stop(),d("语音识别服务不可用(Chrome/Edge 需连接 Google 服务器),下次将使用服务端识别"))},5e3)},H.onresult=G=>{_.current=!0,S.current&&(clearTimeout(S.current),S.current=null);let Q="",D="";for(let z=G.resultIndex;z<G.results.length;z++){const $=G.results[z][0].transcript;G.results[z].isFinal?Q+=$:D+=$}Q&&a(z=>z+Q),o(D),A.current=D},H.onerror=G=>{switch(G.error!=="no-speech"&&G.error!=="aborted"&&(E.current=!0),G.error){case"not-allowed":d("请允许麦克风权限");break;case"network":d("网络错误,请检查连接");break;case"no-speech":case"aborted":return;default:d(`语音识别错误:${G.error}`)}},H.onend=()=>{if(E.current&&A.current&&a(G=>G+A.current),o(""),A.current="",!E.current)try{H.start();return}catch{}n(!1),x.current=null},x.current=H;try{return H.start(),!0}catch{return!1}},[e]),X=y.useCallback(async()=>{F.current=!1,a(""),o(""),d(null),b("idle");try{const z=await fetch("/api/transcribe/status"),{available:$}=await z.json();if(!$){d("语音识别服务未就绪,请稍后重试");return}}catch{d("无法连接语音识别服务");return}let H;try{H=await navigator.mediaDevices.getUserMedia({audio:{sampleRate:Pv,channelCount:1}})}catch{d("请允许麦克风权限");return}const G=new AudioContext({sampleRate:Pv}),Q=G.createMediaStreamSource(H),D=G.createScriptProcessor(4096,1,1);j.current=[],D.onaudioprocess=z=>{j.current.push(new Float32Array(z.inputBuffer.getChannelData(0)))},Q.connect(D),D.connect(G.destination),I.current=G,O.current=H,k.current=D,n(!0),b("recording")},[]),K=y.useCallback(()=>{mE?Y():Lv&&!C.current&&re()||X()},[Y,re,X]);y.useEffect(()=>{if(!t){m(0);return}if(x.current)return;let H=!1,G=null,Q=null,D=0;return(async()=>{try{if(G=await navigator.mediaDevices.getUserMedia({audio:!0}),H){G.getTracks().forEach(ne=>ne.stop());return}Q=new AudioContext;const z=Q.createMediaStreamSource(G),$=Q.createAnalyser();$.fftSize=256,z.connect($);const M=new Uint8Array($.frequencyBinCount);let le=0;const oe=()=>{if(H)return;$.getByteFrequencyData(M);const ne=performance.now();if(ne-le>80){let ae=0;for(let De=0;De<M.length;De++)ae+=M[De];m(ae/(M.length*255)),le=ne}D=requestAnimationFrame(oe)};D=requestAnimationFrame(oe)}catch{}})(),()=>{H=!0,cancelAnimationFrame(D),G==null||G.getTracks().forEach(z=>z.stop()),Q==null||Q.close().catch(()=>{}),m(0)}},[t]),y.useEffect(()=>{!t&&p==="recording"&&b(r?"done":"idle")},[t,p,r]),y.useEffect(()=>()=>{var H,G,Q,D;E.current=!0,(H=x.current)==null||H.stop(),(G=k.current)==null||G.disconnect(),(Q=O.current)==null||Q.getTracks().forEach(z=>z.stop()),(D=I.current)==null||D.close().catch(()=>{});for(const z of N.current)z.remove().catch(()=>{})},[]);const V=y.useCallback(()=>{F.current=!0,a(""),o(""),A.current="",b("idle")},[]);return{isSupported:P,isListening:t,phase:p,transcript:r,interimTranscript:i,error:u,volumeLevel:f,start:K,stop:B,resetTranscript:V}}const uNe=240,cNe=1e3;function aB(e){const t=lNe(),[n,r]=y.useState(""),[a,i]=y.useState(0),o=y.useRef(null),u=y.useRef(null),d=y.useRef(0);y.useEffect(()=>(t.phase==="recording"?(d.current=Date.now(),i(0),u.current=setInterval(()=>{i(Math.floor((Date.now()-d.current)/1e3))},cNe)):u.current&&(clearInterval(u.current),u.current=null),()=>{u.current&&(clearInterval(u.current),u.current=null)}),[t.phase]),y.useEffect(()=>{t.phase==="done"&&(r(t.transcript),requestAnimationFrame(()=>{const b=o.current;b&&(b.focus(),b.setSelectionRange(b.value.length,b.value.length))}))},[t.phase,t.transcript]),y.useLayoutEffect(()=>{if(t.phase!=="done")return;const b=o.current;b&&(b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,uNe)}px`)},[t.phase]);const f=y.useCallback(()=>{t.stop(),t.resetTranscript(),r("")},[t]),m=y.useCallback(async()=>{const b=n.trim();if(!b){f();return}await e(b)!==!1&&(t.resetTranscript(),r(""))},[n,e,f,t]);y.useEffect(()=>{if(t.phase==="idle")return;const b=x=>{if(x.key==="Escape"&&t.phase!=="recognizing"){x.preventDefault(),f();return}if(t.phase==="done"&&x.key==="Enter"&&(x.metaKey||x.ctrlKey)){if(x.isComposing)return;x.preventDefault(),m()}};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[t.phase,f,m]);const p=y.useCallback(b=>{b.nativeEvent.isComposing||b.keyCode===229||b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),m())},[m]);return{stt:t,editText:n,setEditText:r,elapsed:a,textareaRef:o,cancel:f,confirm:m,handleTextareaKeyDown:p}}const iB=["image/png","image/jpeg","image/gif","image/webp"];let jI=0;function sB(e){return e.split(`
652
+ 在此编写该仓库的 Agent 指令…`}),c.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[c.jsx("button",{type:"button",onClick:n,className:"rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"关闭"}),c.jsxs("button",{type:"button",onClick:()=>void x(),disabled:f||!E,className:"flex items-center gap-1.5 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),f?"保存中…":"保存"]})]})]})})}const fE=1024,hE=fE*1024,CI=hE*1024;function kI(e){return!e||e<=0?"0 B":e<fE?`${e} B`:e<hE?`${(e/fE).toFixed(1)} KB`:e<CI?`${(e/hE).toFixed(1)} MB`:`${(e/CI).toFixed(2)} GB`}const Dv="ws/";function GEe({repoId:e}){const[t,n]=y.useState(!1),[r,a]=y.useState(null),[i,o]=y.useState(!1),[u,d]=y.useState(null),{data:f,loading:m,error:p,reload:b}=lc(()=>m$(e),[e,t],{skip:!t,showErrorToast:!1,errorMessage:"加载失败"}),x=u??p,E=async C=>{a(C),d(null);try{await p$(e,C),b()}catch(A){d(A instanceof Li?A.message:"删除失败")}a(null)},N=async()=>{o(!0),d(null);try{await g$(e),b()}catch(C){d(C instanceof Li?C.message:"清理失败")}o(!1)},_=(f==null?void 0:f.length)??0,S=(f==null?void 0:f.reduce((C,A)=>C+(A.diskUsage||0),0))??0;return c.jsxs("div",{className:"mt-3 border-t border-line pt-3",children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>n(C=>!C),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left text-xs font-medium text-fg-3 transition-colors hover:text-fg-2",children:[t?c.jsx(OE,{className:"h-3 w-3 shrink-0"}):c.jsx(kr,{className:"h-3 w-3 shrink-0"}),c.jsx(Gl,{className:"h-3 w-3 shrink-0 text-fg-5"}),c.jsx("span",{children:"工作空间"}),f!==null&&c.jsxs("span",{className:"text-fg-5",children:["(",_,") · ",kI(S)]})]}),t&&_>0&&c.jsxs("button",{type:"button",onClick:()=>void N(),disabled:i,className:"flex h-6 shrink-0 items-center gap-1 rounded border border-line px-2 text-xs text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-50",children:[i?c.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):null,"清理已合并"]})]}),t&&c.jsxs("div",{className:"mt-2",children:[x&&c.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 rounded border border-red-500/30 bg-red-500/5 px-2 py-1 text-xs text-red-600",children:[c.jsx("span",{className:"truncate",children:x}),c.jsx("button",{type:"button",onClick:()=>d(null),className:"shrink-0 rounded p-0.5 transition-colors hover:bg-red-500/10",children:c.jsx(At,{className:"h-3 w-3"})})]}),m&&f===null?c.jsx("div",{className:"flex justify-center py-3",children:c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-fg-5 border-t-transparent"})}):_===0?c.jsx("p",{className:"py-2 text-center text-xs text-fg-5",children:"暂无工作空间"}):c.jsx("ul",{className:"space-y-1",children:f==null?void 0:f.map(C=>{const A=C.branch.startsWith(Dv),I=A?C.branch.slice(Dv.length):C.branch,O=C.status==="active"?"bg-emerald-500/10 text-emerald-600":C.status==="idle"?"bg-amber-500/10 text-amber-600":"bg-fg-6/30 text-fg-4",k=C.status==="active"?"活跃":C.status==="idle"?"空闲":C.status==="merged"?"已合并":C.status==="stale"?"陈旧":C.status,j=C.status!=="active";return c.jsxs("li",{className:"flex items-center gap-2 rounded-md border border-line bg-elevated/40 px-2 py-1.5 text-xs",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[C.running&&C.port&&c.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",title:`运行中 :${C.port}`}),c.jsxs("span",{className:"min-w-0 truncate font-mono",children:[A&&c.jsx("span",{className:"text-fg-5",children:Dv}),c.jsx("span",{className:"text-fg-2",children:I})]})]}),c.jsx("span",{className:ie("shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium",O),children:k}),c.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 text-fg-5",children:[c.jsx(Qz,{className:"h-2.5 w-2.5"}),kI(C.diskUsage)]}),c.jsx("button",{type:"button",onClick:()=>void E(C.id),disabled:!j||r===C.id,title:j?"删除工作空间":"活跃工作空间无法删除",className:"flex h-5 w-5 shrink-0 items-center justify-center rounded text-fg-5 transition-colors hover:bg-red-500/10 hover:text-red-500 disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-fg-5",children:r===C.id?c.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsx(a0,{className:"h-3 w-3"})})]},C.id)})})]})]})}function rB(){const e=zn(),t=We(P=>P.repos),n=We(P=>P.activeRepoId),r=We(P=>P.setActiveRepo),a=We(P=>P.removeRepo),i=We(P=>P.loadRepos),[o,u]=y.useState(!1),[d,f]=y.useState(null),[m,p]=y.useState(null),[b,x]=y.useState(null),E=ar(P=>P.addToast),[N,_]=y.useState(null),[S,C]=y.useState(null),A=y.useRef(null),[I,O]=y.useState(null);y.useEffect(()=>{FE().then(P=>O(new Set(P.map(L=>L.host.toLowerCase())))).catch(()=>{})},[]);const k=y.useMemo(()=>{if(!I)return new Set;const P=new Set;for(const L of t){const B=nB(L.gitUrl);B&&!I.has(B.toLowerCase())&&P.add(L.id)}return P},[t,I]);y.useEffect(()=>{if(!S)return;const P=L=>{A.current&&!A.current.contains(L.target)&&C(null)};return document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[S]);const j=async(P,L)=>{p(P);try{L?await c$(P):await u$(P),await i()}catch{}p(null)},F=async P=>{x(P);try{const L=await h$(P);await i();const B=L.alreadyUpToDate?"info":"success";E(L.summary,B,void 0,{persistent:!0})}catch(L){let B="拉取失败";if(L instanceof Li)try{B=JSON.parse(L.message).error??L.message}catch{B=L.message}E(B,"error",void 0,{persistent:!0})}x(null)};return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"mb-6 flex items-center justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("h1",{className:"text-lg font-semibold text-fg",children:"仓库管理"}),c.jsx("p",{className:"mt-0.5 text-sm text-fg-4",children:"管理代码仓库,每个仓库对应一个独立的 Agent 运行环境"})]}),c.jsxs("button",{type:"button",onClick:()=>u(!0),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-blue-600 px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 md:px-4",children:[c.jsx(ua,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden md:inline",children:"添加仓库"})]})]}),t.length===0?c.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-xl border border-dashed border-line-hard py-16 text-center",children:[c.jsx("div",{className:"rounded-full bg-elevated p-3",children:c.jsx(ua,{className:"h-6 w-6 text-fg-4"})}),c.jsx("p",{className:"text-sm font-medium text-fg-3",children:"暂无代码仓库"}),c.jsx("p",{className:"text-xs text-fg-5",children:"添加一个本地仓库开始使用"}),c.jsx("button",{type:"button",onClick:()=>u(!0),className:"mt-2 rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"添加仓库"})]}):c.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:t.map((P,L)=>{const B=P.id===n;return c.jsxs("div",{className:ie("rounded-xl border p-4 transition-colors",B?"border-blue-500/40 bg-blue-500/5":"border-line"),children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>r(P.id),className:"flex min-w-0 items-center gap-2 text-left",children:[B?c.jsx(ql,{className:"h-4 w-4 shrink-0 text-blue-500"}):c.jsx(pz,{className:"h-4 w-4 shrink-0 text-fg-5"}),c.jsx("span",{className:ie("truncate font-medium",B?"text-fg":"text-fg-2"),children:P.name})]}),c.jsxs("span",{className:ie("inline-flex shrink-0 items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium",P.running?"bg-emerald-500/10 text-emerald-600":"bg-fg-6/30 text-fg-4"),children:[c.jsx("span",{className:ie("h-1.5 w-1.5 rounded-full",P.running?"bg-emerald-500":"bg-fg-5")}),P.running?"运行中":"已停止"]})]}),c.jsxs("dl",{className:"mt-3 space-y-1 font-mono text-xs text-fg-4",children:[c.jsxs("div",{className:"flex gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"Git"}),c.jsx("dd",{className:"min-w-0 truncate",children:P.gitUrl})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"路径"}),c.jsxs("dd",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsx("span",{className:"truncate",children:P.localPath}),c.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(P.localPath),title:"复制路径",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:text-fg-3",children:c.jsx($p,{className:"h-3 w-3"})})]})]}),P.running&&P.port&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"直连"}),c.jsxs("dd",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsxs("a",{href:`http://127.0.0.1:${P.port}`,target:"_blank",rel:"noopener noreferrer",className:"truncate text-blue-500 hover:underline",children:["127.0.0.1:",P.port]}),c.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(`http://127.0.0.1:${P.port}`),title:"复制链接",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:text-fg-3",children:c.jsx($p,{className:"h-3 w-3"})})]})]})]}),k.has(P.id)&&c.jsxs("button",{type:"button",onClick:()=>e("/settings"),className:"mt-2 flex w-full items-center gap-1.5 rounded-md bg-amber-500/10 px-2.5 py-1.5 text-left text-xs text-amber-600 transition-colors hover:bg-amber-500/15",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{children:"缺少 Git 源站凭证,Issue/PR 同步不可用"})]}),c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[c.jsx("button",{type:"button",onClick:()=>void F(P.id),disabled:b===P.id,className:"flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-md border border-blue-500/30 px-2.5 text-xs font-medium text-blue-600 transition-colors hover:bg-blue-500/10 disabled:opacity-50",children:b===P.id?c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsxs(c.Fragment,{children:[c.jsx($F,{className:"h-3 w-3"}),"拉取"]})}),c.jsx("button",{type:"button",onClick:()=>void j(P.id,P.running),disabled:m===P.id,className:ie("flex h-8 flex-1 items-center justify-center gap-1.5 rounded-md border text-xs font-medium transition-colors disabled:opacity-50",P.running?"border-amber-500/30 text-amber-600 hover:bg-amber-500/10":"border-emerald-500/30 text-emerald-600 hover:bg-emerald-500/10"),children:m===P.id?c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):P.running?c.jsxs(c.Fragment,{children:[c.jsx(Vv,{className:"h-3 w-3 fill-current"}),"停止"]}):c.jsxs(c.Fragment,{children:[c.jsx(LE,{className:"h-3 w-3 fill-current"}),"启动"]})}),c.jsxs("div",{className:"relative",ref:S===P.id?A:void 0,children:[c.jsx("button",{type:"button","data-guide":L===0?"repo-overflow-btn":void 0,onClick:()=>C(S===P.id?null:P.id),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(IE,{className:"h-4 w-4"})}),S===P.id&&c.jsxs("div",{"data-guide":L===0?"repo-overflow-dropdown":void 0,className:"absolute right-0 top-full z-20 mt-1 min-w-[160px] overflow-hidden rounded-lg border border-line bg-elevated shadow-lg",children:[c.jsx("button",{type:"button",className:ie("flex w-full items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-base/60",P.runtimeType==="claude-code"?"text-orange-500":"text-sky-500"),onClick:async()=>{C(null);const Y=P.runtimeType==="claude-code"?"opencode":"claude-code";await x$(P.id,Y),i()},children:P.runtimeType==="claude-code"?"Claude → OpenCode":"OpenCode → Claude"}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",onClick:async()=>{C(null),await b$(P.id,!P.worktreeEnabled),i()},children:[c.jsx(Gl,{className:"h-3 w-3"}),c.jsx("span",{children:"Worktree"}),c.jsx("span",{className:ie("ml-auto text-[10px]",P.worktreeEnabled?"text-violet-500":"text-fg-5"),children:P.worktreeEnabled?"已开启":"已关闭"})]}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",onClick:()=>{C(null),_({id:P.id,name:P.name})},children:[c.jsx(Io,{className:"h-3 w-3"}),"配置"]}),c.jsx("div",{className:"my-0.5 border-t border-line"}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-red-500 transition-colors hover:bg-red-500/10",onClick:()=>{C(null),f(P.id)},children:[c.jsx(a0,{className:"h-3 w-3"}),"删除仓库"]})]})]})]}),d===P.id&&c.jsxs("div",{className:"mt-2 flex items-center justify-between rounded-md border border-red-500/20 bg-red-500/5 px-3 py-2",children:[c.jsx("span",{className:"text-xs text-red-500",children:"确认删除此仓库?"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>{a(P.id),f(null)},className:"flex h-6 items-center gap-1 rounded border border-red-500/30 px-2 text-xs text-red-500 transition-colors hover:bg-red-500/10",children:[c.jsx(fi,{className:"h-3 w-3"}),"确认"]}),c.jsx("button",{type:"button",onClick:()=>f(null),className:"flex h-6 items-center gap-1 rounded border border-line px-2 text-xs text-fg-4 transition-colors hover:bg-elevated",children:"取消"})]})]}),P.worktreeEnabled&&c.jsx(GEe,{repoId:P.id})]},P.id)})}),c.jsxs("p",{className:"mt-3 text-xs text-fg-5",children:[t.length," 个仓库"]}),o&&c.jsx(YEe,{onClose:()=>u(!1)}),N&&c.jsx(qEe,{repoId:N.id,repoName:N.name,onClose:()=>_(null)})]})}function KEe(){return c.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:c.jsx("div",{className:"mx-auto max-w-4xl",children:c.jsx(rB,{})})})}/*! Capacitor: https://capacitorjs.com/ - MIT License */var Sc;(function(e){e.Unimplemented="UNIMPLEMENTED",e.Unavailable="UNAVAILABLE"})(Sc||(Sc={}));class jv extends Error{constructor(t,n,r){super(t),this.message=t,this.code=n,this.data=r}}const VEe=e=>{var t,n;return e!=null&&e.androidBridge?"android":!((n=(t=e==null?void 0:e.webkit)===null||t===void 0?void 0:t.messageHandlers)===null||n===void 0)&&n.bridge?"ios":"web"},WEe=e=>{const t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},a=()=>t!==null?t.name:VEe(e),i=()=>a()!=="web",o=p=>{const b=f.get(p);return!!(b!=null&&b.platforms.has(a())||u(p))},u=p=>{var b;return(b=n.PluginHeaders)===null||b===void 0?void 0:b.find(x=>x.name===p)},d=p=>e.console.error(p),f=new Map,m=(p,b={})=>{const x=f.get(p);if(x)return console.warn(`Capacitor plugin "${p}" already registered. Cannot register plugins twice.`),x.proxy;const E=a(),N=u(p);let _;const S=async()=>(!_&&E in b?_=typeof b[E]=="function"?_=await b[E]():_=b[E]:t!==null&&!_&&"web"in b&&(_=typeof b.web=="function"?_=await b.web():_=b.web),_),C=(F,P)=>{var L,B;if(N){const Y=N==null?void 0:N.methods.find(re=>P===re.name);if(Y)return Y.rtype==="promise"?re=>n.nativePromise(p,P.toString(),re):(re,X)=>n.nativeCallback(p,P.toString(),re,X);if(F)return(L=F[P])===null||L===void 0?void 0:L.bind(F)}else{if(F)return(B=F[P])===null||B===void 0?void 0:B.bind(F);throw new jv(`"${p}" plugin is not implemented on ${E}`,Sc.Unimplemented)}},A=F=>{let P;const L=(...B)=>{const Y=S().then(re=>{const X=C(re,F);if(X){const K=X(...B);return P=K==null?void 0:K.remove,K}else throw new jv(`"${p}.${F}()" is not implemented on ${E}`,Sc.Unimplemented)});return F==="addListener"&&(Y.remove=async()=>P()),Y};return L.toString=()=>`${F.toString()}() { [capacitor code] }`,Object.defineProperty(L,"name",{value:F,writable:!1,configurable:!1}),L},I=A("addListener"),O=A("removeListener"),k=(F,P)=>{const L=I({eventName:F},P),B=async()=>{const re=await L;O({eventName:F,callbackId:re},P)},Y=new Promise(re=>L.then(()=>re({remove:B})));return Y.remove=async()=>{console.warn("Using addListener() without 'await' is deprecated."),await B()},Y},j=new Proxy({},{get(F,P){switch(P){case"$$typeof":return;case"toJSON":return()=>({});case"addListener":return N?k:I;case"removeListener":return O;default:return A(P)}}});return r[p]=j,f.set(p,{name:p,proxy:j,platforms:new Set([...Object.keys(b),...N?[E]:[]])}),j};return n.convertFileSrc||(n.convertFileSrc=p=>p),n.getPlatform=a,n.handleError=d,n.isNativePlatform=i,n.isPluginAvailable=o,n.registerPlugin=m,n.Exception=jv,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},XEe=e=>e.Capacitor=WEe(e),Wg=XEe(typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}),ub=Wg.registerPlugin;class sw{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(t,n){let r=!1;this.listeners[t]||(this.listeners[t]=[],r=!0),this.listeners[t].push(n);const i=this.windowListeners[t];i&&!i.registered&&this.addWindowListener(i),r&&this.sendRetainedArgumentsForEvent(t);const o=async()=>this.removeListener(t,n);return Promise.resolve({remove:o})}async removeAllListeners(){this.listeners={};for(const t in this.windowListeners)this.removeWindowListener(this.windowListeners[t]);this.windowListeners={}}notifyListeners(t,n,r){const a=this.listeners[t];if(!a){if(r){let i=this.retainedEventArguments[t];i||(i=[]),i.push(n),this.retainedEventArguments[t]=i}return}a.forEach(i=>i(n))}hasListeners(t){var n;return!!(!((n=this.listeners[t])===null||n===void 0)&&n.length)}registerWindowListener(t,n){this.windowListeners[n]={registered:!1,windowEventName:t,pluginEventName:n,handler:r=>{this.notifyListeners(n,r)}}}unimplemented(t="not implemented"){return new Wg.Exception(t,Sc.Unimplemented)}unavailable(t="not available"){return new Wg.Exception(t,Sc.Unavailable)}async removeListener(t,n){const r=this.listeners[t];if(!r)return;const a=r.indexOf(n);a!==-1&&this.listeners[t].splice(a,1),this.listeners[t].length||this.removeWindowListener(this.windowListeners[t])}addWindowListener(t){window.addEventListener(t.windowEventName,t.handler),t.registered=!0}removeWindowListener(t){t&&(window.removeEventListener(t.windowEventName,t.handler),t.registered=!1)}sendRetainedArgumentsForEvent(t){const n=this.retainedEventArguments[t];n&&(delete this.retainedEventArguments[t],n.forEach(r=>{this.notifyListeners(t,r)}))}}const OI=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),II=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent);class QEe extends sw{async getCookies(){const t=document.cookie,n={};return t.split(";").forEach(r=>{if(r.length<=0)return;let[a,i]=r.replace(/=/,"CAP_COOKIE").split("CAP_COOKIE");a=II(a).trim(),i=II(i).trim(),n[a]=i}),n}async setCookie(t){try{const n=OI(t.key),r=OI(t.value),a=t.expires?`; expires=${t.expires.replace("expires=","")}`:"",i=(t.path||"/").replace("path=",""),o=t.url!=null&&t.url.length>0?`domain=${t.url}`:"";document.cookie=`${n}=${r||""}${a}; path=${i}; ${o};`}catch(n){return Promise.reject(n)}}async deleteCookie(t){try{document.cookie=`${t.key}=; Max-Age=0`}catch(n){return Promise.reject(n)}}async clearCookies(){try{const t=document.cookie.split(";")||[];for(const n of t)document.cookie=n.replace(/^ +/,"").replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)}catch(t){return Promise.reject(t)}}async clearAllCookies(){try{await this.clearCookies()}catch(t){return Promise.reject(t)}}}ub("CapacitorCookies",{web:()=>new QEe});const ZEe=async e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const a=r.result;t(a.indexOf(",")>=0?a.split(",")[1]:a)},r.onerror=a=>n(a),r.readAsDataURL(e)}),JEe=(e={})=>{const t=Object.keys(e);return Object.keys(e).map(a=>a.toLocaleLowerCase()).reduce((a,i,o)=>(a[i]=e[t[o]],a),{})},eNe=(e,t=!0)=>e?Object.entries(e).reduce((r,a)=>{const[i,o]=a;let u,d;return Array.isArray(o)?(d="",o.forEach(f=>{u=t?encodeURIComponent(f):f,d+=`${i}=${u}&`}),d.slice(0,-1)):(u=t?encodeURIComponent(o):o,d=`${i}=${u}`),`${r}&${d}`},"").substr(1):null,tNe=(e,t={})=>{const n=Object.assign({method:e.method||"GET",headers:e.headers},t),a=JEe(e.headers)["content-type"]||"";if(typeof e.data=="string")n.body=e.data;else if(a.includes("application/x-www-form-urlencoded")){const i=new URLSearchParams;for(const[o,u]of Object.entries(e.data||{}))i.set(o,u);n.body=i.toString()}else if(a.includes("multipart/form-data")||e.data instanceof FormData){const i=new FormData;if(e.data instanceof FormData)e.data.forEach((u,d)=>{i.append(d,u)});else for(const u of Object.keys(e.data))i.append(u,e.data[u]);n.body=i;const o=new Headers(n.headers);o.delete("content-type"),n.headers=o}else(a.includes("application/json")||typeof e.data=="object")&&(n.body=JSON.stringify(e.data));return n};class nNe extends sw{async request(t){const n=tNe(t,t.webFetchExtra),r=eNe(t.params,t.shouldEncodeUrlParams),a=r?`${t.url}?${r}`:t.url,i=await fetch(a,n),o=i.headers.get("content-type")||"";let{responseType:u="text"}=i.ok?t:{};o.includes("application/json")&&(u="json");let d,f;switch(u){case"arraybuffer":case"blob":f=await i.blob(),d=await ZEe(f);break;case"json":d=await i.json();break;case"document":case"text":default:d=await i.text()}const m={};return i.headers.forEach((p,b)=>{m[b]=p}),{data:d,headers:m,status:i.status,url:i.url}}async get(t){return this.request(Object.assign(Object.assign({},t),{method:"GET"}))}async post(t){return this.request(Object.assign(Object.assign({},t),{method:"POST"}))}async put(t){return this.request(Object.assign(Object.assign({},t),{method:"PUT"}))}async patch(t){return this.request(Object.assign(Object.assign({},t),{method:"PATCH"}))}async delete(t){return this.request(Object.assign(Object.assign({},t),{method:"DELETE"}))}}ub("CapacitorHttp",{web:()=>new nNe});var RI;(function(e){e.Dark="DARK",e.Light="LIGHT",e.Default="DEFAULT"})(RI||(RI={}));var MI;(function(e){e.StatusBar="StatusBar",e.NavigationBar="NavigationBar"})(MI||(MI={}));class rNe extends sw{async setStyle(){this.unavailable("not available for web")}async setAnimation(){this.unavailable("not available for web")}async show(){this.unavailable("not available for web")}async hide(){this.unavailable("not available for web")}}ub("SystemBars",{web:()=>new rNe});const aNe="modulepreload",iNe=function(e){return"/"+e},DI={},sNe=function(t,n,r){let a=Promise.resolve();if(n&&n.length>0){let o=function(f){return Promise.all(f.map(m=>Promise.resolve(m).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const u=document.querySelector("meta[property=csp-nonce]"),d=(u==null?void 0:u.nonce)||(u==null?void 0:u.getAttribute("nonce"));a=o(n.map(f=>{if(f=iNe(f),f in DI)return;DI[f]=!0;const m=f.endsWith(".css"),p=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${f}"]${p}`))return;const b=document.createElement("link");if(b.rel=m?"stylesheet":aNe,m||(b.as="script"),b.crossOrigin="",b.href=f,d&&b.setAttribute("nonce",d),document.head.appendChild(b),m)return new Promise((x,E)=>{b.addEventListener("load",x),b.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${f}`)))})}))}function i(o){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=o,window.dispatchEvent(u),!u.defaultPrevented)throw o}return a.then(o=>{for(const u of o||[])u.status==="rejected"&&i(u.reason);return t().catch(i)})},Gu=ub("SpeechRecognition",{web:()=>sNe(()=>import("./web-BBBd5rLC.js"),[]).then(e=>new e.SpeechRecognitionWeb)});function oNe(e,t){const n=e.length,r=new ArrayBuffer(44+n*2),a=new DataView(r),i=(o,u)=>{for(let d=0;d<u.length;d++)a.setUint8(o+d,u.charCodeAt(d))};i(0,"RIFF"),a.setUint32(4,36+n*2,!0),i(8,"WAVE"),i(12,"fmt "),a.setUint32(16,16,!0),a.setUint16(20,1,!0),a.setUint16(22,1,!0),a.setUint32(24,t,!0),a.setUint32(28,t*2,!0),a.setUint16(32,2,!0),a.setUint16(34,16,!0),i(36,"data"),a.setUint32(40,n*2,!0);for(let o=0;o<n;o++){const u=Math.max(-1,Math.min(1,e[o]));a.setInt16(44+o*2,u<0?u*32768:u*32767,!0)}return new Blob([r],{type:"audio/wav"})}const mE=Wg.isNativePlatform(),Lv=!mE&&typeof window<"u"?window.SpeechRecognition??window.webkitSpeechRecognition:void 0,Pv=16e3;function lNe(e="zh-CN"){const[t,n]=y.useState(!1),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(null),[f,m]=y.useState(0),[p,b]=y.useState("idle"),x=y.useRef(null),E=y.useRef(!1),N=y.useRef([]),_=y.useRef(!1),S=y.useRef(null),C=y.useRef(!1),A=y.useRef(""),I=y.useRef(null),O=y.useRef(null),k=y.useRef(null),j=y.useRef([]),F=y.useRef(!1),P=!0,L=y.useCallback(async()=>{var M,le,oe;(M=k.current)==null||M.disconnect(),(le=O.current)==null||le.getTracks().forEach(ne=>ne.stop()),await((oe=I.current)==null?void 0:oe.close().catch(()=>{}));const H=j.current;if(j.current=[],k.current=null,O.current=null,I.current=null,H.length===0||F.current){n(!1),b("idle");return}o("识别中…"),b("recognizing");const G=H.reduce((ne,ae)=>ne+ae.length,0),Q=new Float32Array(G);let D=0;for(const ne of H)Q.set(ne,D),D+=ne.length;const z=oNe(Q,Pv),$=new FormData;$.append("audio",z,"recording.wav");try{const ne=await fetch("/api/transcribe",{method:"POST",body:$});if(F.current)return;if(ne.ok){const{text:ae}=await ne.json();ae?(a(ae),b("done")):b("idle")}else{const ae=await ne.json().catch(()=>({error:`HTTP ${ne.status}`}));d(ae.error??`HTTP ${ne.status}`),b("idle")}}catch(ne){d(`语音识别失败:${ne instanceof Error?ne.message:String(ne)}`),b("idle")}finally{o(""),n(!1)}},[]),B=y.useCallback(async()=>{if(E.current=!0,S.current&&(clearTimeout(S.current),S.current=null),mE){await Gu.stop().catch(()=>{});for(const H of N.current)await H.remove().catch(()=>{});N.current=[],n(!1),o("")}else x.current?x.current.stop():I.current?await L():(n(!1),b("idle"))},[L]),Y=y.useCallback(async()=>{var D;F.current=!1,a(""),o(""),d(null),b("idle");const{available:H}=await Gu.available();if(!H){d("当前设备不支持语音识别");return}if((await Gu.requestPermissions()).speechRecognition!=="granted"){d("请允许语音识别权限");return}const Q=[];Q.push(await Gu.addListener("partialResults",z=>{o(z.matches[0]??"")})),Q.push(await Gu.addListener("listeningState",z=>{const $=z.status==="started";n($),$&&b("recording"),$||o("")})),N.current=Q;try{const z=await Gu.start({language:e,partialResults:!0,maxResults:1});(D=z.matches)!=null&&D.length&&a($=>{var M;return $+((M=z.matches)==null?void 0:M.join(""))})}catch(z){d(`语音识别错误:${z instanceof Error?z.message:String(z)}`);for(const $ of Q)await $.remove().catch(()=>{});N.current=[]}},[e]),re=y.useCallback(()=>{if(!Lv)return!1;F.current=!1,a(""),o(""),A.current="",d(null),b("idle"),E.current=!1;const H=new Lv;H.lang=e,H.continuous=!0,H.interimResults=!0,H.maxAlternatives=1,H.onstart=()=>{n(!0),b("recording"),_.current=!1,S.current=setTimeout(()=>{!_.current&&!E.current&&(C.current=!0,E.current=!0,H.stop(),d("语音识别服务不可用(Chrome/Edge 需连接 Google 服务器),下次将使用服务端识别"))},5e3)},H.onresult=G=>{_.current=!0,S.current&&(clearTimeout(S.current),S.current=null);let Q="",D="";for(let z=G.resultIndex;z<G.results.length;z++){const $=G.results[z][0].transcript;G.results[z].isFinal?Q+=$:D+=$}Q&&a(z=>z+Q),o(D),A.current=D},H.onerror=G=>{switch(G.error!=="no-speech"&&G.error!=="aborted"&&(E.current=!0),G.error){case"not-allowed":d("请允许麦克风权限");break;case"network":d("网络错误,请检查连接");break;case"no-speech":case"aborted":return;default:d(`语音识别错误:${G.error}`)}},H.onend=()=>{if(E.current&&A.current&&a(G=>G+A.current),o(""),A.current="",!E.current)try{H.start();return}catch{}n(!1),x.current=null},x.current=H;try{return H.start(),!0}catch{return!1}},[e]),X=y.useCallback(async()=>{F.current=!1,a(""),o(""),d(null),b("idle");try{const z=await fetch("/api/transcribe/status"),{available:$}=await z.json();if(!$){d("语音识别服务未就绪,请稍后重试");return}}catch{d("无法连接语音识别服务");return}let H;try{H=await navigator.mediaDevices.getUserMedia({audio:{sampleRate:Pv,channelCount:1}})}catch{d("请允许麦克风权限");return}const G=new AudioContext({sampleRate:Pv}),Q=G.createMediaStreamSource(H),D=G.createScriptProcessor(4096,1,1);j.current=[],D.onaudioprocess=z=>{j.current.push(new Float32Array(z.inputBuffer.getChannelData(0)))},Q.connect(D),D.connect(G.destination),I.current=G,O.current=H,k.current=D,n(!0),b("recording")},[]),K=y.useCallback(()=>{mE?Y():Lv&&!C.current&&re()||X()},[Y,re,X]);y.useEffect(()=>{if(!t){m(0);return}if(x.current)return;let H=!1,G=null,Q=null,D=0;return(async()=>{try{if(G=await navigator.mediaDevices.getUserMedia({audio:!0}),H){G.getTracks().forEach(ne=>ne.stop());return}Q=new AudioContext;const z=Q.createMediaStreamSource(G),$=Q.createAnalyser();$.fftSize=256,z.connect($);const M=new Uint8Array($.frequencyBinCount);let le=0;const oe=()=>{if(H)return;$.getByteFrequencyData(M);const ne=performance.now();if(ne-le>80){let ae=0;for(let De=0;De<M.length;De++)ae+=M[De];m(ae/(M.length*255)),le=ne}D=requestAnimationFrame(oe)};D=requestAnimationFrame(oe)}catch{}})(),()=>{H=!0,cancelAnimationFrame(D),G==null||G.getTracks().forEach(z=>z.stop()),Q==null||Q.close().catch(()=>{}),m(0)}},[t]),y.useEffect(()=>{!t&&p==="recording"&&b(r?"done":"idle")},[t,p,r]),y.useEffect(()=>()=>{var H,G,Q,D;E.current=!0,(H=x.current)==null||H.stop(),(G=k.current)==null||G.disconnect(),(Q=O.current)==null||Q.getTracks().forEach(z=>z.stop()),(D=I.current)==null||D.close().catch(()=>{});for(const z of N.current)z.remove().catch(()=>{})},[]);const V=y.useCallback(()=>{F.current=!0,a(""),o(""),A.current="",b("idle")},[]);return{isSupported:P,isListening:t,phase:p,transcript:r,interimTranscript:i,error:u,volumeLevel:f,start:K,stop:B,resetTranscript:V}}const uNe=240,cNe=1e3;function aB(e){const t=lNe(),[n,r]=y.useState(""),[a,i]=y.useState(0),o=y.useRef(null),u=y.useRef(null),d=y.useRef(0);y.useEffect(()=>(t.phase==="recording"?(d.current=Date.now(),i(0),u.current=setInterval(()=>{i(Math.floor((Date.now()-d.current)/1e3))},cNe)):u.current&&(clearInterval(u.current),u.current=null),()=>{u.current&&(clearInterval(u.current),u.current=null)}),[t.phase]),y.useEffect(()=>{t.phase==="done"&&(r(t.transcript),requestAnimationFrame(()=>{const b=o.current;b&&(b.focus(),b.setSelectionRange(b.value.length,b.value.length))}))},[t.phase,t.transcript]),y.useLayoutEffect(()=>{if(t.phase!=="done")return;const b=o.current;b&&(b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,uNe)}px`)},[t.phase]);const f=y.useCallback(()=>{t.stop(),t.resetTranscript(),r("")},[t]),m=y.useCallback(async()=>{const b=n.trim();if(!b){f();return}await e(b)!==!1&&(t.resetTranscript(),r(""))},[n,e,f,t]);y.useEffect(()=>{if(t.phase==="idle")return;const b=x=>{if(x.key==="Escape"&&t.phase!=="recognizing"){x.preventDefault(),f();return}if(t.phase==="done"&&x.key==="Enter"&&(x.metaKey||x.ctrlKey)){if(x.isComposing)return;x.preventDefault(),m()}};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[t.phase,f,m]);const p=y.useCallback(b=>{b.nativeEvent.isComposing||b.keyCode===229||b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),m())},[m]);return{stt:t,editText:n,setEditText:r,elapsed:a,textareaRef:o,cancel:f,confirm:m,handleTextareaKeyDown:p}}const iB=["image/png","image/jpeg","image/gif","image/webp"];let jI=0;function sB(e){return e.split(`
653
653
  `).length>NY||e.length>SY}function dNe(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}function fNe(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function hNe({url:e,label:t,onClose:n}){return y.useEffect(()=>{const r=a=>{a.key==="Escape"&&(a.preventDefault(),n())};return window.addEventListener("keydown",r,!0),()=>window.removeEventListener("keydown",r,!0)},[n]),c.jsx("div",{role:"dialog","aria-modal":"true","aria-label":t,onClick:n,className:"fixed inset-0 z-50 flex cursor-zoom-out items-center justify-center bg-black/80 p-8 backdrop-blur-sm",children:c.jsx("img",{src:e,alt:t,className:"max-h-full max-w-full object-contain"})})}function ow({url:e,label:t,className:n}){const[r,a]=y.useState(!1);return c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button",onClick:()=>a(!0),"aria-label":`预览 ${t}`,className:"block cursor-zoom-in rounded-md transition-opacity duration-150 hover:opacity-80",children:c.jsx("img",{src:e,alt:t,className:ie("rounded-md border border-line",n)})}),r&&c.jsx(hNe,{url:e,label:t,onClose:()=>a(!1)})]})}function oB(e=!0){const[t,n]=y.useState([]),[r,a]=y.useState([]),[i,o]=y.useState(null);y.useEffect(()=>{o(null),e||n([])},[e]);const u=async N=>{const _=[],S=[],C=t.length;let A=NA-C;for(const I of N){if(A<=0){S.push(`最多 ${NA} 张图片`);break}if(!iB.includes(I.type)){S.push(`${I.name||"文件"}:格式不支持`);continue}if(I.size>wY){S.push(`${I.name}:超过 5MB`);continue}_.push({_id:`att-${++jI}`,mime:I.type,url:await fNe(I),filename:I.name}),A--}_.length>0&&n(I=>[...I,..._]),o(S.length>0?S.join(";"):null)},d=N=>{const _=Array.from(N.clipboardData.files);if(_.length!==0){if(N.preventDefault(),!e){o("当前模型不支持图片");return}u(_)}},f=N=>{const _=++jI,S=N.split(`
654
654
  `).length,C=new TextEncoder().encode(N).byteLength,A=`[粘贴文本 #${_} · ${S}行]`,I={_id:`fold-${_}`,text:N,lineCount:S,byteSize:C,placeholder:A};return a(O=>[...O,I]),I},m=N=>{let _=N;for(const S of r)_=_.replace(S.placeholder,S.text);return _},p=N=>n(_=>_.filter(S=>S._id!==N)),b=N=>a(_=>_.filter(S=>S._id!==N)),x=y.useCallback(()=>{n([]),a([]),o(null)},[]),E=t.map(({mime:N,url:_,filename:S})=>({mime:N,url:_,filename:S}));return{attachments:t,foldedTexts:r,promptFiles:E,error:i,setError:o,addFiles:u,onPaste:d,addFoldedText:f,expandFoldedTexts:m,remove:p,removeFoldedText:b,clear:x}}function mNe({text:e,label:t,onClose:n}){y.useEffect(()=>{const i=o=>{o.key==="Escape"&&(o.preventDefault(),n())};return window.addEventListener("keydown",i,!0),()=>window.removeEventListener("keydown",i,!0)},[n]);const r=e.split(`
655
655
  `),a=String(r.length).length;return c.jsx("div",{role:"dialog","aria-modal":"true","aria-label":t,onClick:n,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4 backdrop-blur-sm md:p-8",children:c.jsxs("div",{onClick:i=>i.stopPropagation(),className:"flex max-h-full w-full max-w-4xl flex-col overflow-hidden rounded-lg border border-line bg-term",children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-4 py-2",children:[c.jsx("span",{className:"font-mono text-xs text-fg-3",children:t}),c.jsx("button",{type:"button",onClick:n,className:"text-fg-5 hover:text-fg-2",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsx("pre",{className:"overflow-auto p-4 font-mono text-xs leading-relaxed text-fg-2",children:r.map((i,o)=>c.jsxs("div",{children:[c.jsx("span",{className:"mr-3 inline-block select-none text-right text-fg-6",style:{width:`${a}ch`},children:o+1}),i]},o))})]})})}function pNe({fold:e,index:t,onRemove:n}){const[r,a]=y.useState(!1),i=`粘贴文本 #${t} · ${e.lineCount}行 · ${dNe(e.byteSize)}`;return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"group relative flex items-center gap-1.5 rounded-md border border-line bg-elevated/50 px-2.5 py-1.5",children:[c.jsxs("button",{type:"button",onClick:()=>a(!0),className:"flex items-center gap-1.5 font-mono text-xs text-fg-3 transition-colors hover:text-fg",children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("span",{children:i})]}),c.jsx("button",{type:"button",onClick:n,"aria-label":"移除粘贴文本",className:"flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-fg-5 transition-colors hover:text-fg-2",children:c.jsx(At,{className:"h-2.5 w-2.5",strokeWidth:2.5})})]}),r&&c.jsx(mNe,{text:e.text,label:i,onClose:()=>a(!1)})]})}function lB({onFiles:e,disabled:t,allowed:n}){const r=y.useRef(null);return c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:r,type:"file",accept:iB.join(","),multiple:!0,hidden:!0,onChange:a=>{e(Array.from(a.target.files??[])),a.target.value=""}}),c.jsx("button",{type:"button",onClick:()=>{var a;return(a=r.current)==null?void 0:a.click()},disabled:t||!n,"aria-label":"Attach image",title:n?"附加图片":"当前模型不支持图片",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-fg-5 transition-colors duration-150 hover:text-fg-3 disabled:cursor-not-allowed disabled:text-fg-6/40",children:c.jsx(Jz,{className:"h-4 w-4"})})]})}function uB({attachments:e,foldedTexts:t,error:n,onRemove:r,onRemoveFoldedText:a,className:i}){const o=e.length>0||(t??[]).length>0;return!o&&!n?null:c.jsxs("div",{className:i,children:[o&&c.jsxs("div",{className:"mb-2 flex flex-wrap gap-2",children:[e.map(u=>c.jsxs("div",{className:"group relative",children:[c.jsx(ow,{url:u.url,label:u.filename??"attachment",className:"h-16 w-16 object-cover"}),c.jsx("button",{type:"button",onClick:()=>r(u._id),"aria-label":"Remove attachment",className:"absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full border border-line bg-term text-fg-4 opacity-0 transition-opacity duration-150 hover:text-fg-2 group-hover:opacity-100",children:c.jsx(At,{className:"h-2.5 w-2.5",strokeWidth:2.5})})]},u._id)),(t??[]).map((u,d)=>c.jsx(pNe,{fold:u,index:d+1,onRemove:()=>a==null?void 0:a(u._id)},u._id))]}),n&&c.jsx("div",{className:"mb-2 font-mono text-[11px] text-red-400",children:n})]})}const LI=(function(e,t,n){const r=Ih(n);if(!e||!e.type||!e.children)throw new Error("Expected parent node");if(typeof t=="number"){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if(t=e.children.indexOf(t),t<0)throw new Error("Expected child node or index");for(;++t<e.children.length;)if(r(e.children[t],t,e))return e.children[t]}),tu=(function(e){if(e==null)return xNe;if(typeof e=="string")return bNe(e);if(typeof e=="object")return gNe(e);if(typeof e=="function")return lw(e);throw new Error("Expected function, string, or array as `test`")});function gNe(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=tu(e[n]);return lw(r);function r(...a){let i=-1;for(;++i<t.length;)if(t[i].apply(this,a))return!0;return!1}}function bNe(e){return lw(t);function t(n){return n.tagName===e}}function lw(e){return t;function t(n,r,a){return!!(yNe(n)&&e.call(this,n,typeof r=="number"?r:void 0,a||void 0))}}function xNe(e){return!!(e&&typeof e=="object"&&"type"in e&&e.type==="element"&&"tagName"in e&&typeof e.tagName=="string")}function yNe(e){return e!==null&&typeof e=="object"&&"type"in e&&"tagName"in e}const PI=/\n/g,BI=/[\t ]+/g,pE=tu("br"),UI=tu(ANe),vNe=tu("p"),FI=tu("tr"),ENe=tu(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",TNe,CNe]),cB=tu(["address","article","aside","blockquote","body","caption","center","dd","dialog","dir","dl","dt","div","figure","figcaption","footer","form,","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","legend","li","listing","main","menu","nav","ol","p","plaintext","pre","section","ul","xmp"]);function NNe(e,t){const n=t||{},r="children"in e?e.children:[],a=cB(e),i=hB(e,{whitespace:n.whitespace||"normal"}),o=[];(e.type==="text"||e.type==="comment")&&o.push(...fB(e,{breakBefore:!0,breakAfter:!0}));let u=-1;for(;++u<r.length;)o.push(...dB(r[u],e,{whitespace:i,breakBefore:u?void 0:a,breakAfter:u<r.length-1?pE(r[u+1]):a}));const d=[];let f;for(u=-1;++u<o.length;){const m=o[u];typeof m=="number"?f!==void 0&&m>f&&(f=m):m&&(f!==void 0&&f>-1&&d.push(`
@@ -663,6 +663,6 @@ https://github.com/highlightjs/highlight.js/issues/2277`),Tn=Ce,Ut=Xe),dt===void
663
663
  `),r=t.split(`
664
664
  `);return c.jsxs("div",{className:"grid grid-cols-1 gap-px overflow-x-auto rounded text-xs md:grid-cols-2",children:[c.jsx("pre",{className:"min-w-0 whitespace-pre-wrap break-words p-1.5 fs-diff-del",children:n.map((a,i)=>c.jsxs("div",{children:[c.jsx("span",{className:"select-none text-red-400/70",children:"− "}),c.jsx("span",{className:"text-red-400",children:a})]},i))}),c.jsx("pre",{className:"min-w-0 whitespace-pre-wrap break-words p-1.5 fs-diff-add",children:r.map((a,i)=>c.jsxs("div",{children:[c.jsx("span",{className:"select-none text-emerald-400/70",children:"+ "}),c.jsx("span",{className:"text-emerald-400",children:a})]},i))})]})}const VI={completed:{glyph:"✓",color:"text-emerald-400"},in_progress:{glyph:"◌",color:"text-amber-400"},cancelled:{glyph:"✗",color:"text-fg-5"},pending:{glyph:"○",color:"text-fg-4"}};function IB({todos:e}){return c.jsx("ul",{className:"space-y-0.5 text-xs",children:e.map((t,n)=>{var u;const r=((u=t.status)==null?void 0:u.toLowerCase())??"pending",a=r==="in-progress"||r==="active"?"in_progress":r==="done"||r==="complete"?"completed":r==="canceled"?"cancelled":r,i=VI[a]??VI.pending,o=a==="completed"||a==="cancelled";return c.jsxs("li",{className:"flex items-start gap-1.5",children:[c.jsx("span",{className:ie("shrink-0 leading-5",i.color,a==="in_progress"&&"fs-spin"),children:i.glyph}),c.jsx("span",{className:ie("leading-5",o?"text-fg-5 line-through":"text-fg-2"),children:t.content}),t.priority&&c.jsx("span",{className:"ml-auto shrink-0 text-fg-5",children:t.priority})]},n)})})}const gwe={"visual-engineering":"bg-purple-500/15 text-purple-400",quick:"bg-emerald-500/15 text-emerald-400",deep:"bg-blue-500/15 text-blue-400",ultrabrain:"bg-amber-500/15 text-amber-400",artistry:"bg-pink-500/15 text-pink-400",writing:"bg-cyan-500/15 text-cyan-400","unspecified-low":"bg-elevated text-fg-4","unspecified-high":"bg-elevated text-fg-3"},bwe={explore:"bg-teal-500/15 text-teal-400",librarian:"bg-indigo-500/15 text-indigo-400",oracle:"bg-amber-500/15 text-amber-400",metis:"bg-rose-500/15 text-rose-400",momus:"bg-orange-500/15 text-orange-400"};function xwe({record:e}){const[t,n]=y.useState(!1),r=typeof e.category=="string"?e.category:null,a=typeof e.subagent_type=="string"?e.subagent_type:null,i=Oi(e,["description","title"]),o=typeof e.prompt=="string"?e.prompt:null,u=Array.isArray(e.load_skills)?e.load_skills.filter(b=>typeof b=="string"):[],d=typeof e.run_in_background=="boolean"?e.run_in_background:!1,f=typeof e.task_id=="string"?e.task_id:null,m=r??a,p=(r&&gwe[r])??(a&&bwe[a])??"bg-elevated text-fg-3";return c.jsxs("div",{className:"space-y-2",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[m&&c.jsx("span",{className:ie("rounded px-1.5 py-0.5 text-[10px] font-medium",p),children:m}),u.map(b=>c.jsx("span",{className:"rounded bg-elevated px-1.5 py-0.5 text-[10px] text-fg-4",children:b},b)),d&&c.jsx("span",{className:"rounded bg-elevated px-1.5 py-0.5 text-[10px] text-fg-5",children:"bg"}),f&&c.jsxs("span",{className:"rounded bg-elevated px-1.5 py-0.5 font-mono text-[10px] text-fg-5",title:f,children:["↩ ",f.slice(0,16),"…"]})]}),i&&c.jsx("p",{className:"text-xs text-fg-2",children:i}),o&&c.jsxs("div",{children:[c.jsxs("button",{type:"button",onClick:()=>n(b=>!b),className:"flex items-center gap-1 text-[10px] text-fg-4 transition-colors hover:text-fg-2",children:[c.jsx(Oo,{className:ie("h-3 w-3 transition-transform",t&&"rotate-90")}),"Prompt",c.jsxs("span",{className:"text-fg-5",children:["(",o.length," chars)"]})]}),t&&c.jsx("pre",{className:"mt-1 max-h-60 overflow-y-auto whitespace-pre-wrap break-words rounded bg-elevated/50 p-2 text-[11px] leading-relaxed text-fg-3",children:o})]})]})}function ywe(e){const t=YY(e),n=Me(d=>d.activeSessionId),r=Me(d=>d.sessions);if(t)return t;if(!n)return null;const a=i0(e),i=cb(a),o=Oi(i,["description","title"]),u=r.filter(d=>d.parentID===n);if(u.length===0)return null;if(u.length===1)return u[0].id;if(o){const d=u.find(f=>f.title===o);if(d)return d.id}return null}function vwe({part:e}){const t=ywe(e),n=Me(a=>a.setActiveSession),r=We(a=>a.activeRepoId);return t?c.jsxs("button",{type:"button",onClick:a=>{a.stopPropagation(),r&&n(r,t)},className:"mt-2 flex items-center gap-1.5 rounded-md border border-line px-2.5 py-1 font-mono text-xs text-blue-400 transition-colors hover:border-blue-500/50 hover:bg-blue-500/10",children:[c.jsxs("span",{className:"truncate text-fg-5",children:[t.slice(0,20),"…"]}),c.jsx(GF,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"shrink-0",children:"查看子会话"})]}):null}function Ewe(e,t){const n=cb(t);if(!n)return null;const r=e.toLowerCase();if(r==="edit"||r==="patch"){const a=typeof n.oldString=="string"?n.oldString:"",i=typeof n.newString=="string"?n.newString:"";if(a||i)return c.jsx(pwe,{oldStr:a,newStr:i})}if(r==="todowrite"||r==="write_todos"){const a=Array.isArray(n.todos)?n.todos:null;if(a&&a.length>0)return c.jsx(IB,{todos:a})}if(r==="bash"||r==="shell"){const a=Oi(n,["command","cmd","script"]);if(a)return c.jsxs("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-fg-2",children:[c.jsx("span",{className:"select-none text-emerald-400/70",children:"❯ "}),a]})}if(r==="task"||r==="agent")return c.jsx(xwe,{record:n});if(r==="read")return null;if(r==="write"){const a=typeof n.content=="string"?n.content:null;if(a){const i=a.length>EA?`${a.slice(0,EA)}…`:a;return c.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-fg-2",children:i})}}return null}function Nwe(e,t){const n=e.toLowerCase();if(n==="todowrite"||n==="write_todos"){const r=Array.isArray(t)?t:null;if(r&&r.length>0)return c.jsx(IB,{todos:r})}return null}function Swe({part:e}){const t=$E(e),n=t==="running"||t==="pending",[r,a]=y.useState(n),[i,o]=y.useState(!1),u=y.useRef(n);y.useEffect(()=>{u.current!==n&&(a(n),u.current=n)},[n]);const d=We(B=>{const Y=B.repos.find(re=>re.id===B.activeRepoId);return(Y==null?void 0:Y.localPath)??null}),f=hM(e),m=f.toLowerCase(),p=m==="task"||m==="agent",b=i0(e),{label:x,arg:E}=mwe(f,b),N=E&&dwe(E,d),_=Ewe(f,b),S=_?null:OA(b),C=HE(e),A=Nwe(f,C),I=A?"":OA(C),O=hwe[t],k=m==="edit"||m==="patch";let j=0,F=0;if(k){const B=cb(b);if(B){const Y=typeof B.oldString=="string"?B.oldString:"",re=typeof B.newString=="string"?B.newString:"";Y&&(F=Y.split(`
665
665
  `).length),re&&(j=re.split(`
666
- `).length)}}const P=I.length>_y,L=i||!P?I:`${I.slice(0,_y)}…`;return c.jsxs("div",{className:"my-1 overflow-hidden rounded-md border border-line bg-term/70",children:[c.jsxs("button",{type:"button",onClick:()=>a(B=>!B),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left font-mono text-xs transition-colors duration-150 hover:bg-surface/70",children:[c.jsx("span",{className:ie("shrink-0 leading-none",O.color),children:r?"▾":"▸"}),c.jsx("span",{className:"shrink-0 font-medium text-fg",children:x}),N&&c.jsx("span",{className:"truncate text-fg-3",children:N}),k&&(j>0||F>0)&&c.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[11px] leading-none",children:[j>0&&c.jsxs("span",{className:"text-emerald-400",children:["+",j]}),F>0&&c.jsxs("span",{className:"text-red-400",children:["-",F]})]}),c.jsxs("span",{className:ie("ml-auto flex shrink-0 items-center gap-1.5 leading-none",O.color),children:[c.jsx("span",{className:ie(O.spin&&"fs-spin"),children:O.glyph}),c.jsx("span",{children:O.label})]})]}),r&&c.jsx("div",{className:"border-t border-line px-3 py-2",children:c.jsxs("div",{className:ie("ml-1 border-l-2 pl-3 font-mono text-xs",O.accent),children:[_&&c.jsx("section",{className:"mb-2",children:_}),S&&c.jsxs("section",{className:"mb-2",children:[c.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-wider text-fg-5",children:"input"}),c.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-fg-2",children:S})]}),p&&c.jsx(vwe,{part:e}),A&&c.jsx("section",{children:A}),I&&c.jsxs("section",{children:[c.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-wider text-fg-5",children:"output"}),c.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-fg-2",children:L}),P&&c.jsx("button",{type:"button",onClick:()=>o(B=>!B),className:"mt-1 text-blue-400 transition-colors hover:text-blue-300",children:i?"show less":`show ${I.length-_y} more chars`})]}),!_&&!S&&!A&&!I&&c.jsx("div",{className:"text-fg-5",children:"no parameters"})]})})]})}function wwe({text:e}){const[t,n]=y.useState(!1);return c.jsxs("div",{className:"my-1",children:[c.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"flex items-center gap-1.5 font-mono text-xs text-fg-5 transition-colors hover:text-fg-3",children:[t?c.jsx(kr,{className:"h-3 w-3 shrink-0"}):c.jsx(Oo,{className:"h-3 w-3 shrink-0"}),c.jsx(oc,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"thinking"})]}),t&&c.jsx("div",{className:"ml-1.5 mt-1 whitespace-pre-wrap border-l border-line pl-3 text-xs italic leading-relaxed text-fg-4",children:e})]})}function _we(){const[e,t]=y.useState(0);return y.useEffect(()=>{const n=Date.now(),r=setInterval(()=>{t(Math.floor((Date.now()-n)/1e3))},1e3);return()=>clearInterval(r)},[]),c.jsxs("div",{className:"my-1 flex items-center gap-1.5 font-mono text-xs text-fg-5",children:[c.jsx(oc,{className:"h-3 w-3 shrink-0 animate-pulse"}),c.jsx("span",{children:"thinking"}),e>0&&c.jsxs("span",{className:"text-fg-6",children:[e,"s"]})]})}function RB({part:e,className:t}){var n;return e.url?(n=e.mime)!=null&&n.startsWith("image/")?c.jsx(ow,{url:e.url,label:e.filename??"attachment",className:ie("object-contain",t??"max-h-80")}):c.jsxs("div",{className:"flex items-center gap-1.5 font-mono text-xs text-fg-5",children:[c.jsx(CH,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:e.filename??e.mime??"attachment"})]}):null}function Twe({part:e,isStreaming:t}){switch(Gp(e)){case"text":{const r=Jv(e);return r.trim()?c.jsx("div",{className:"markdown-body leading-relaxed",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[iwe],components:{table:owe},children:r})}):null}case"thinking":{const r=Jv(e);return r.trim()?c.jsx(wwe,{text:r}):t?c.jsx(_we,{}):null}case"tool":return Mf(e)?c.jsx(uwe,{part:e}):c.jsx(Swe,{part:e});case"file":return c.jsx(RB,{part:e});default:return null}}function Awe({message:e,isStreaming:t,queued:n}){var m,p,b,x,E,N;const r=e.role==="user",a=e.parts??[],i=a.filter(_=>Gp(_)!=="other");if(r){const _=a.map(Jv).join("").trim(),S=a.filter(I=>Gp(I)==="file"),C=(m=e.time)==null?void 0:m.created,A=C?new Date(C*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):null;return c.jsxs("div",{className:"fs-fade-in rounded-r-md border-l-2 border-emerald-500/40 bg-emerald-500/[0.04] px-3 py-2 font-mono",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[11px]",children:[c.jsx("span",{className:"font-medium text-emerald-400",children:"You"}),A&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{className:"text-fg-5",children:A})]}),n&&c.jsxs("span",{className:"inline-flex items-center gap-1 rounded border border-amber-500/30 px-1.5 py-0.5 text-xs text-amber-400",children:[c.jsx("span",{className:"leading-none",children:"○"}),c.jsx("span",{children:"queued"})]})]}),c.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[c.jsx("span",{className:"shrink-0 select-none text-emerald-400",children:"❯"}),c.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words text-fg",children:_||"…"})]}),S.length>0&&c.jsx("div",{className:"mt-2 flex flex-wrap gap-2 pl-5",children:S.map((I,O)=>c.jsx(RB,{part:I,className:"max-h-40"},I.id??O))})]})}const o=((p=e.info)==null?void 0:p.agent)??e.agent,u=((b=e.info)==null?void 0:b.modelID)??e.modelID,d=(x=e.info)==null?void 0:x.error,f=(E=e.info)==null?void 0:E.finish;return c.jsxs("div",{className:"fs-fade-in font-mono",children:[(o||u)&&c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-xs",children:[o&&c.jsx("span",{className:"text-fg-3",children:o}),o&&u&&c.jsx("span",{className:"text-fg-6",children:"·"}),u&&c.jsx("span",{className:"text-fg-5",children:u})]}),d&&c.jsxs("div",{className:"my-1 flex items-start gap-2 rounded-md border border-red-500/20 bg-red-500/10 px-3 py-2 text-xs text-red-400",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("span",{className:"font-semibold",children:d.name??"Error"}),((N=d.data)==null?void 0:N.message)&&c.jsx("p",{className:"mt-0.5 text-red-400/80",children:d.data.message}),f&&f!=="end"&&c.jsxs("p",{className:"mt-0.5 text-red-400/60",children:["finish: ",f]})]})]}),c.jsx("div",{className:"space-y-2 text-sm text-fg",children:i.length>0?i.map((_,S)=>c.jsx(Twe,{part:_,isStreaming:t},_.id??_.callID??S)):!d&&(t?c.jsx("span",{className:"text-fg-5",children:"…"}):c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-amber-400/80",children:[c.jsx(On,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"空响应 — Agent 未产出任何内容"})]}))})]})}const Fp=$i(e=>({drafts:{},setDraft:(t,n)=>e(r=>{if(!n.trim()){const{[t]:a,...i}=r.drafts;return{drafts:i}}return{drafts:{...r.drafts,[t]:n}}}),clearDraft:t=>e(n=>{const{[t]:r,...a}=n.drafts;return{drafts:a}})}));function MB({isListening:e,disabled:t,onStart:n,onStop:r}){const a=y.useRef(!1),i=u=>{if(t)return;u.preventDefault(),a.current=!0,n();const d=()=>{document.removeEventListener("touchend",d),document.removeEventListener("touchcancel",d),a.current=!1,r()};document.addEventListener("touchend",d,{once:!0}),document.addEventListener("touchcancel",d,{once:!0})},o=()=>{if(t||a.current)return;n();const u=()=>{document.removeEventListener("mouseup",u),r()};document.addEventListener("mouseup",u,{once:!0})};return c.jsx("button",{type:"button",disabled:t,onTouchStart:i,onMouseDown:o,onContextMenu:u=>u.preventDefault(),"aria-label":"按住说话",title:"按住说话",style:{WebkitTouchCallout:"none"},className:ie("flex shrink-0 select-none touch-none items-center justify-center transition-colors duration-150 disabled:cursor-not-allowed disabled:text-fg-6/40","order-first self-stretch w-12 rounded-xl sm:order-none sm:self-auto sm:h-7 sm:w-7 sm:rounded-md",e?"bg-red-500/15 text-red-400 hover:bg-red-500/25":"text-fg-5 hover:text-fg-3"),children:c.jsx(pH,{className:ie("h-6 w-6 sm:h-4 sm:w-4",e&&"animate-pulse")})})}const Cwe=[.85,1.25,.65,1.4,.75,1.15,.95],zv=4,WI=24;function kwe(e){const t=Math.floor(e/60).toString().padStart(2,"0"),n=Math.floor(e%60).toString().padStart(2,"0");return`${t}:${n}`}function Owe({volumeLevel:e}){const t=Math.min(Math.max(e,0),1);return c.jsx("div",{className:"flex h-6 items-center gap-1","aria-hidden":"true",children:Cwe.map((n,r)=>{const a=zv+t*n*(WI-zv),i=Math.max(zv,Math.min(WI,a));return c.jsx("span",{className:"w-1 rounded-full bg-red-400 transition-[height] duration-150 ease-out",style:{height:`${i}px`}},r)})})}function DB({phase:e,transcript:t,interimTranscript:n,editText:r,onEditTextChange:a,onTextareaKeyDown:i,textareaRef:o,wrapperClassName:u}){if(e==="idle")return null;const d=t.length>0||n.length>0;return c.jsx("div",{className:u,children:c.jsxs("div",{className:"max-h-[40vh] overflow-y-auto px-4 py-4",children:[e==="recording"&&c.jsx("div",{className:"text-xl leading-relaxed",children:d?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-fg",children:t}),n&&c.jsx("span",{className:"text-fg-4",children:n})]}):c.jsx("span",{className:"italic text-fg-5",children:"正在聆听…"})}),e==="recognizing"&&c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(nn,{className:"h-5 w-5 shrink-0 text-emerald-400 fs-spin"}),c.jsx("span",{className:"font-mono text-sm text-emerald-400",children:"识别中…"}),n&&c.jsx("span",{className:"truncate text-base text-fg-4",children:n})]}),e==="done"&&c.jsx("textarea",{ref:o,value:r,onChange:f=>a(f.target.value),onKeyDown:i,rows:2,placeholder:"识别结果(可编辑)",className:"w-full resize-none bg-transparent text-xl leading-relaxed text-fg placeholder:text-fg-5 focus:outline-none"})]})})}function jB({phase:e,volumeLevel:t,elapsed:n,editText:r,error:a,onCancel:i,onConfirm:o,idleHint:u,className:d}){return e==="idle"?c.jsx("div",{className:d,children:a?c.jsx("span",{className:"font-mono text-[10px] text-red-400",children:a}):u?c.jsx("span",{className:"font-mono text-[10px] text-fg-6",children:u}):null}):e==="done"?c.jsxs("div",{className:d,children:[c.jsx("span",{className:"hidden font-mono text-[10px] text-fg-6 sm:inline",children:"⌘/Ctrl+⏎ 发送 · Esc 取消"}),c.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c.jsx("button",{type:"button",onClick:i,className:"rounded-md border border-line px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"取消"}),c.jsxs("button",{type:"button",onClick:o,disabled:r.trim().length===0,"aria-label":"发送",className:"flex items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-fg-6/30 disabled:text-fg-5",children:[c.jsx(Rf,{className:"h-3.5 w-3.5",strokeWidth:2.5}),c.jsx("span",{children:"发送"})]})]})]}):c.jsx("div",{className:d,children:e==="recording"?c.jsxs(c.Fragment,{children:[c.jsx(Owe,{volumeLevel:t}),c.jsxs("span",{className:"inline-flex items-center gap-1.5 font-mono text-[11px] font-medium text-red-400",children:[c.jsx("span",{className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-red-400"}),"录音中"]}),c.jsx("span",{className:"font-mono text-[11px] tabular-nums text-fg-4",children:kwe(n)})]}):c.jsxs(c.Fragment,{children:[c.jsx(nn,{className:"h-4 w-4 shrink-0 text-emerald-400 fs-spin"}),c.jsx("span",{className:"font-mono text-[11px] text-emerald-400",children:"识别中…"})]})})}const Iwe=200;function Rwe(){return Me(e=>{const t=e.activeSessionId;if(!t)return!1;const n=e.messages[t]??Df;for(let r=n.length-1;r>=0;r--){const a=n[r].parts;if(a){for(const i of a)if(Gp(i)==="tool"&&Kp(i))return!0}}return!1})}function Mwe(){var le;const[e,t]=y.useState(""),[n,r]=y.useState([]),[a,i]=y.useState([]),o=y.useRef(null),u=Me(oe=>oe.activeSessionId),d=We(oe=>oe.activeRepoId),f=Me(oe=>{const ne=oe.activeSessionId;return ne?oe.sessionModels[ne]??"":""}),m=Me(oe=>{const ne=oe.activeSessionId;return ne?oe.sessionVariants[ne]??"":""}),p=Me(oe=>oe.setSessionModel),b=Me(oe=>oe.setSessionVariant),x=Me(oe=>{const ne=oe.activeSessionId;return ne?oe.sessionStatuses[ne]:void 0}),E=Me(oe=>oe.sendMessage),N=Fp(oe=>oe.setDraft),_=Fp(oe=>oe.clearDraft),S=Rwe(),C=y.useCallback(async oe=>{if(!d||!await E(d,oe,f||void 0,m||void 0))return!1},[d,E,f,m]),A=aB(C);y.useEffect(()=>{if(!d){r([]);return}let oe=!1;return(async()=>{try{const[ne,ae]=await Promise.all([Ml(),kc(d)]);if(oe)return;const De=ne.pinned_models,xe=De?JSON.parse(De):[],we=xe.length>0?ae.filter(Le=>xe.includes(Le.id)):ae;r(we.length>0?we:ae)}catch{oe||r([])}})(),()=>{oe=!0}},[d]),y.useEffect(()=>{let oe=!1;return(async()=>{try{const ne=await Ml();if(oe)return;const ae=ne.quick_inputs;if(ae)try{i(JSON.parse(ae))}catch{}else i([{label:"继续",text:"继续",autoSend:!0}])}catch{}})(),()=>{oe=!0}},[]);const I=x==="busy"&&!S,O=!u;y.useLayoutEffect(()=>{const oe=o.current;oe&&(oe.style.height="auto",oe.style.height=`${Math.min(oe.scrollHeight,Iwe)}px`)},[]);const k=((le=n.find(oe=>oe.id===f))==null?void 0:le.supportsImage)!==!1,{attachments:j,foldedTexts:F,promptFiles:P,error:L,addFiles:B,onPaste:Y,addFoldedText:re,expandFoldedTexts:X,remove:K,removeFoldedText:V,clear:H}=oB(k);y.useEffect(()=>{t(u?Fp.getState().drafts[u]??"":""),H(),A.stt.stop()},[u,H,A.stt.stop]);const G=oe=>{if(Array.from(oe.clipboardData.files).length>0){Y(oe);return}const ae=oe.clipboardData.getData("text/plain");if(!ae||!sB(ae))return;oe.preventDefault();const De=re(ae),xe=oe.currentTarget,we=xe.selectionStart??e.length,Le=xe.selectionEnd??e.length,Ee=e.slice(0,we)+De.placeholder+e.slice(Le);t(Ee),u&&N(u,Ee),requestAnimationFrame(()=>{const st=we+De.placeholder.length;xe.setSelectionRange(st,st)})},Q=oe=>{const ne=F.find(ae=>ae._id===oe);if(ne){const ae=e.replace(ne.placeholder,"");t(ae),u&&N(u,ae)}V(oe)},D=async()=>{const oe=X(e.trim());if(O||!oe&&j.length===0)return;await E(d,oe,f||void 0,m||void 0,P.length>0?P:void 0)&&(t(""),H(),u&&_(u))},z=oe=>{oe.nativeEvent.isComposing||oe.keyCode===229||oe.key==="Enter"&&!oe.shiftKey&&(oe.preventDefault(),D())},$=u?S?"输入回复,或点击上方选项…":I?"输入消息将排队等待处理…":"enter a command…":"select or start a run",M=u?I?"text-amber-400 fs-blink":S?"text-blue-400":"text-emerald-400":"text-fg-6";return c.jsxs("div",{"data-guide":"run-input-bar",className:"relative border-t border-line bg-term px-4 py-4",children:[c.jsx(DB,{phase:A.stt.phase,transcript:A.stt.transcript,interimTranscript:A.stt.interimTranscript,editText:A.editText,onEditTextChange:A.setEditText,onTextareaKeyDown:A.handleTextareaKeyDown,textareaRef:A.textareaRef,wrapperClassName:"absolute bottom-full left-0 right-0 z-20 border-t border-line bg-surface/95 backdrop-blur-sm"}),c.jsx(uB,{attachments:j,foldedTexts:F,error:L,onRemove:K,onRemoveFoldedText:Q,className:"mx-auto max-w-4xl"}),a.length>0&&c.jsx("div",{className:"mx-auto mb-2 flex max-w-4xl gap-1.5 overflow-x-auto scrollbar-none",children:a.map((oe,ne)=>c.jsx("button",{type:"button",disabled:O,onClick:()=>{var ae;oe.autoSend?d&&E(d,oe.text,f||void 0,m||void 0):(t(oe.text),u&&N(u,oe.text),(ae=o.current)==null||ae.focus())},className:"shrink-0 rounded-full border border-line bg-surface px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:oe.label},ne))}),c.jsxs("div",{className:ie("mx-auto flex max-w-4xl items-start gap-2 rounded-lg border px-3 py-2 transition-colors duration-150",O?"border-line":"border-fg-5 focus-within:border-fg-4"),children:[c.jsx("span",{className:ie("select-none pt-px font-mono text-sm leading-6",M),children:"❯"}),c.jsx("textarea",{ref:o,rows:2,value:e,disabled:O,onChange:oe=>{const ne=oe.target.value;t(ne),u&&N(u,ne)},onKeyDown:z,onPaste:G,placeholder:$,className:"flex-1 resize-none bg-transparent font-mono text-sm leading-6 text-fg placeholder:text-fg-6 focus:outline-none disabled:cursor-not-allowed"}),c.jsx(lB,{onFiles:oe=>void B(oe),disabled:O,allowed:k}),c.jsx(MB,{isListening:A.stt.isListening,disabled:O,onStart:A.stt.start,onStop:()=>void A.stt.stop()}),c.jsx("button",{type:"button",onClick:D,disabled:O||e.trim().length===0&&j.length===0&&F.length===0,"aria-label":"Send message",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-emerald-600 text-white transition-colors duration-150 hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-fg-6/30 disabled:text-fg-5",children:c.jsx(UR,{className:"h-4 w-4",strokeWidth:2.5})})]}),A.stt.phase==="idle"?c.jsxs("div",{className:"mx-auto mt-1.5 flex max-w-4xl items-center gap-3 pl-5",children:[A.stt.error&&c.jsx("span",{className:"font-mono text-[10px] text-red-400",children:A.stt.error}),c.jsx("span",{className:"font-mono text-[10px] text-fg-6",children:"⏎ to run · shift+⏎ for newline"}),c.jsxs("div",{className:"ml-auto flex min-w-0 shrink items-center gap-1.5",children:[c.jsxs("select",{value:m,onChange:oe=>{u&&b(u,oe.target.value)},className:"w-16 min-w-0 rounded border border-line bg-surface px-1.5 py-0.5 font-mono text-[11px] text-fg-4 focus:border-fg-5 focus:outline-none",children:[c.jsx("option",{value:"",children:"默认"}),c.jsx("option",{value:"max",children:"max"}),c.jsx("option",{value:"high",children:"high"})]}),n.length>0&&c.jsxs("select",{value:f,onChange:oe=>{u&&p(u,oe.target.value)},className:"w-24 min-w-0 rounded border border-line bg-surface px-1.5 py-0.5 font-mono text-[11px] text-fg-4 focus:border-fg-5 focus:outline-none",children:[c.jsx("option",{value:"",children:"默认模型"}),n.map(oe=>c.jsx("option",{value:oe.id,children:oe.name||oe.id},oe.id))]})]})]}):c.jsx(jB,{phase:A.stt.phase,volumeLevel:A.stt.volumeLevel,elapsed:A.elapsed,editText:A.editText,error:A.stt.error,onCancel:A.cancel,onConfirm:()=>void A.confirm(),className:"mx-auto mt-1.5 flex max-w-4xl items-center gap-3 pl-5"})]})}const Dwe={completed:{glyph:"■",color:"text-emerald-400"},in_progress:{glyph:"■",color:"text-amber-400"},cancelled:{glyph:"■",color:"text-fg-6"},pending:{glyph:"□",color:"text-fg-5"}};function jwe(e){const t=e.find(r=>Dl(r.status)==="in_progress");if(t)return t.content;const n=e.find(r=>Dl(r.status)==="pending");return n?n.content:"all steps complete"}function Lwe({todos:e,onClick:t}){if(e.length===0)return null;const n=e.length,r=mM(e);return c.jsx("div",{className:"rounded-md border border-line bg-term/60 px-3 py-2",children:c.jsxs("button",{type:"button",onClick:t,className:"flex w-full items-center gap-2 text-left font-mono text-xs",children:[c.jsxs("span",{className:"shrink-0 tabular-nums text-fg-4",children:["[",r,"/",n,"]"]}),c.jsx("span",{className:"shrink-0 tracking-tight",children:e.map(a=>{const i=Dwe[Dl(a.status)];return c.jsx("span",{className:i.color,children:i.glyph},a.id)})}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-2",children:jwe(e)}),c.jsx("span",{className:"shrink-0 text-[10px] text-fg-5",children:"详情 →"})]})})}const XI={idle:{glyph:"●",label:"ready",color:"text-emerald-400",spin:!1},busy:{glyph:"◌",label:"running",color:"text-amber-400",spin:!0},retry:{glyph:"◌",label:"retrying",color:"text-amber-400",spin:!0},error:{glyph:"✗",label:"error",color:"text-red-400",spin:!1}};function QI({status:e,reason:t}){const n=XI[e??"idle"]??XI.idle;return c.jsxs("span",{className:ie("flex items-center gap-1.5 rounded border border-line px-2 py-0.5 font-mono text-xs",n.color),title:e==="error"&&t?t:void 0,children:[c.jsx("span",{className:ie("leading-none",n.spin&&"fs-spin"),children:n.glyph}),c.jsx("span",{children:n.label})]})}const ZI=1e6;function Pwe(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(n.role==="assistant"&&n.tokens){const r=n.tokens;if(r.cache&&(r.cache.read>0||r.cache.write>0)||r.input>0||r.output>0)return r}}return null}function JI({session:e,messages:t,contextLimit:n}){var d,f;const r=Pwe(t),a=(e==null?void 0:e.cost)??0;if(!r&&!a)return null;const i=r?r.input+(((d=r.cache)==null?void 0:d.read)??0)+(((f=r.cache)==null?void 0:f.write)??0):0,o=i>0?Math.min(Math.round(i/n*100),999):0,u=o>=80?"text-red-400":o>=50?"text-amber-400":"text-fg-5";return c.jsxs("div",{className:"flex items-center gap-2 font-mono text-[11px] text-fg-5",children:[i>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{title:"当前上下文 = cache_read + cache_write + input (最近一次请求)",children:Nf(i)}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsxs("span",{className:u,title:`上下文占比 (${Nf(n)} 窗口)`,children:[o,"%"]}),c.jsx("span",{className:"text-fg-6",children:"·"})]}),c.jsx("span",{title:"会话累计费用",children:Aa(a)})]})}const Bwe=144,Uwe=64;function Fwe({onToggleSidebar:e}){var oe;const[t,n]=y.useState(""),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(""),f=y.useRef(null),[m,p]=y.useState([]),b=Me(ne=>ne.createSession),x=Me(ne=>ne.sendError),E=We(ne=>ne.activeRepoId),_=ia(ne=>ne.agents).filter(ne=>ne.isSystem<2),S=Je(ne=>ne.selectedIssueId),C=Je(ne=>{if(!u)return null;const ae=ne.issues.find(De=>De.id===u);return ae?`#${ae.number} ${ae.title}`:null}),[A,I]=CE();y.useEffect(()=>{_.length>0&&!r&&a(_[0].id)},[_,r]),y.useEffect(()=>{if(!E){p([]);return}let ne=!1;return kc(E).then(ae=>{ne||p(ae)}).catch(()=>{ne||p([])}),()=>{ne=!0}},[E]);const O=m.length===0||m.some(ne=>ne.supportsImage!==!1),{attachments:k,foldedTexts:j,promptFiles:F,error:P,addFiles:L,onPaste:B,addFoldedText:Y,expandFoldedTexts:re,remove:X,removeFoldedText:K,clear:V}=oB(O);y.useEffect(()=>{S&&(d(S),Je.getState().setSelectedIssue(null))},[S]),y.useEffect(()=>{const ne=A.get("draft");ne&&(n(ne),I({},{replace:!0}))},[A,I]),y.useLayoutEffect(()=>{const ne=f.current;ne&&(ne.style.height="auto",ne.style.height=`${Math.min(ne.scrollHeight,Bwe)}px`)},[]);const H=(oe=_.find(ne=>ne.id===r))==null?void 0:oe.description,G=!!u,Q=ne=>{if(Array.from(ne.clipboardData.files).length>0){B(ne);return}const De=ne.clipboardData.getData("text/plain");if(!De||!sB(De))return;ne.preventDefault();const xe=Y(De),we=ne.currentTarget,Le=we.selectionStart??t.length,Ee=we.selectionEnd??t.length,st=t.slice(0,Le)+xe.placeholder+t.slice(Ee);n(st),requestAnimationFrame(()=>{const Ke=Le+xe.placeholder.length;we.setSelectionRange(Ke,Ke)})},D=ne=>{const ae=j.find(De=>De._id===ne);ae&&n(t.replace(ae.placeholder,"")),K(ne)},z=()=>{const ne=re(t.trim());!E||!ne&&!G&&k.length===0||(n(""),V(),b(E,ne,void 0,void 0,i||void 0,u||void 0,r||void 0,F.length>0?F:void 0))},$=ne=>{if(!(ne.nativeEvent.isComposing||ne.keyCode===229)){if(ne.key==="Tab"&&_.length>1){ne.preventDefault();const ae=_.findIndex(xe=>xe.id===r),De=ne.shiftKey?(ae-1+_.length)%_.length:(ae+1)%_.length;a(_[De].id);return}ne.key==="Enter"&&!ne.shiftKey&&(ne.preventDefault(),z())}},M=y.useCallback(ne=>{E&&b(E,ne,void 0,void 0,i||void 0,u||void 0,r||void 0)},[E,b,u,r,i]),le=aB(M);return c.jsxs("div",{className:"relative flex flex-1 flex-col items-center justify-center bg-term",children:[c.jsx("button",{type:"button",onClick:e,"aria-label":"Open sidebar",className:"absolute left-3 top-3 rounded-lg p-2 text-fg-3 hover:bg-elevated md:hidden",children:c.jsx(DE,{className:"h-5 w-5"})}),c.jsxs("div",{className:"w-full max-w-2xl px-6",children:[c.jsx("div",{className:"mb-8 text-center",children:c.jsxs("div",{className:"font-mono text-2xl text-fg-6",children:[c.jsx("span",{className:"text-emerald-500/60",children:"❯"}),c.jsx("span",{className:"fs-blink text-fg-4",children:" ▋"})]})}),c.jsx(uB,{attachments:k,foldedTexts:j,error:P,onRemove:X,onRemoveFoldedText:D}),c.jsxs("div",{"data-guide":"run-new-input",className:ie("relative rounded-xl border bg-base/80 shadow-sm transition-colors","border-line focus-within:border-fg-5"),children:[c.jsx(DB,{phase:le.stt.phase,transcript:le.stt.transcript,interimTranscript:le.stt.interimTranscript,editText:le.editText,onEditTextChange:le.setEditText,onTextareaKeyDown:le.handleTextareaKeyDown,textareaRef:le.textareaRef,wrapperClassName:"absolute bottom-full left-0 right-0 z-20 mb-2 overflow-hidden rounded-xl border border-line bg-surface/95 backdrop-blur-sm"}),_.length>0&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center gap-1.5 overflow-x-auto px-4 pt-3 pb-1 scrollbar-none",children:[_.map(ne=>{const ae=zE(ne.name);return c.jsxs("button",{type:"button","aria-label":`选择代理 ${ne.name}`,"aria-pressed":r===ne.id,onClick:()=>a(ne.id),className:ie("flex shrink-0 items-center gap-1.5 rounded-full px-3 py-1 text-xs font-medium transition-colors",r===ne.id?"bg-blue-500/15 text-blue-400 ring-1 ring-inset ring-blue-500/30":"text-fg-4 hover:bg-elevated hover:text-fg-3"),children:[c.jsx("span",{className:ie("inline-flex h-4 w-4 items-center justify-center rounded-full text-[10px] font-bold",ae.bg,ae.text),children:ae.initial}),ne.name]},ne.id)}),_.length>1&&c.jsx("span",{className:"hidden shrink-0 ml-auto font-mono text-[10px] text-fg-6 md:inline",children:"Tab 切换"})]}),H&&c.jsx("p",{className:"px-4 pb-1 text-[11px] leading-relaxed text-fg-5",children:H})]}),c.jsxs("div",{className:"flex items-start gap-2 px-4 py-3",children:[c.jsx("span",{className:ie("select-none pt-px font-mono text-sm leading-6","text-emerald-400"),children:"❯"}),c.jsx("textarea",{ref:f,rows:1,value:t,disabled:!E,onChange:ne=>n(ne.target.value),onKeyDown:$,onPaste:Q,placeholder:E?u?"输入补充指令,或直接发送":"让 Agent 做什么?":"请先选择一个仓库",className:"flex-1 resize-none bg-transparent font-mono text-sm leading-6 text-fg placeholder:text-fg-6 focus:outline-none disabled:cursor-not-allowed"}),c.jsx(lB,{onFiles:ne=>void L(ne),disabled:!E,allowed:!0}),c.jsx(MB,{isListening:le.stt.isListening,disabled:!E,onStart:le.stt.start,onStop:()=>void le.stt.stop()}),c.jsx("button",{type:"button",onClick:z,disabled:!E||!t.trim()&&!G&&k.length===0&&j.length===0,"aria-label":"Start run",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-emerald-600 text-white transition-colors duration-150 hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-fg-6/30 disabled:text-fg-5",children:c.jsx(UR,{className:"h-4 w-4",strokeWidth:2.5})})]}),c.jsxs("div",{className:"flex items-center gap-2 border-t border-line/60 px-4 py-1.5",children:[C&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"shrink-0 font-mono text-[11px] text-fg-5",children:"关联"}),c.jsx("span",{className:"min-w-0 truncate rounded bg-blue-500/10 px-1.5 py-0.5 font-mono text-[11px] text-blue-400",children:C}),c.jsx("button",{type:"button",onClick:()=>d(""),className:"shrink-0 text-fg-5 hover:text-fg-3","aria-label":"取消关联",children:c.jsx(At,{className:"h-3 w-3"})})]}),c.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[c.jsx("span",{className:"font-mono text-[11px] text-fg-5",children:"variant"}),c.jsxs("select",{value:i,onChange:ne=>o(ne.target.value),className:"rounded border border-line bg-surface px-2 py-0.5 font-mono text-[11px] text-fg-4 focus:border-fg-5 focus:outline-none",children:[c.jsx("option",{value:"",children:"默认"}),c.jsx("option",{value:"max",children:"max"}),c.jsx("option",{value:"high",children:"high"})]})]})]})]}),c.jsx(jB,{phase:le.stt.phase,volumeLevel:le.stt.volumeLevel,elapsed:le.elapsed,editText:le.editText,error:le.stt.error,onCancel:le.cancel,onConfirm:()=>void le.confirm(),idleHint:"⌘⏎ / ctrl+⏎ 开始运行",className:"mt-2 flex items-center justify-center gap-2"}),x&&c.jsx("div",{className:"mt-3 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-2 font-mono text-xs text-red-400",children:x})]})]})}function eR({body:e}){return e?c.jsx("div",{className:"markdown-body leading-relaxed",children:c.jsx($l,{remarkPlugins:[Yl],children:e})}):c.jsx("p",{className:"py-10 text-center font-mono text-xs text-fg-5",children:"该 Issue 没有描述内容"})}function tR({issue:e}){var t;return c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",e.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",e.number," ",e.state]}),(t=e.labels)==null?void 0:t.map(n=>c.jsx("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${n.color}20`,color:`#${n.color}`},children:n.name},n.id))]}),c.jsx("h2",{className:"mt-0.5 truncate text-sm font-medium text-fg",children:e.title})]})}function zwe({onToggleSidebar:e}){const t=Je(p=>p.matchingParentId),n=Je(p=>p.matchingCandidateId),r=Je(p=>p.issues.find(b=>b.id===t)),a=Je(p=>p.issues.find(b=>b.id===n)),i=Je(p=>p.exitMatchMode),o=Je(p=>p.linkChild),u=We(p=>p.activeRepoId),[d,f]=y.useState(!1);if(!r)return null;const m=async()=>{!a||!u||(f(!0),await o(u,r.number,a.number),f(!1))};return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden bg-term",children:[c.jsxs("header",{className:"flex items-center gap-3 border-b border-line bg-base px-4 py-2.5",children:[c.jsx("button",{type:"button",onClick:e,"aria-label":"Open sidebar",className:"-ml-1 rounded-lg p-1.5 text-fg-3 hover:bg-elevated md:hidden",children:c.jsx(DE,{className:"h-5 w-5"})}),c.jsx("span",{className:"text-xs font-medium text-fg-4",children:"匹配子任务"}),c.jsxs("span",{className:"font-mono text-xs text-fg-3",children:["父: #",r.number]}),c.jsx("div",{className:"flex-1"}),c.jsxs("button",{type:"button","aria-label":"退出匹配模式",onClick:i,className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 text-xs text-fg-3 transition-colors hover:border-fg-5 hover:text-fg",children:[c.jsx(At,{className:"h-3.5 w-3.5"}),"退出匹配"]})]}),c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col md:flex-row",children:[c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden border-b border-line md:border-b-0 md:border-r",children:[c.jsx("div",{className:"border-b border-line/60 px-4 py-2.5",children:c.jsx(tR,{issue:r})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-6",children:c.jsx(eR,{body:r.body})})]}),c.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:a?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"border-b border-line/60 px-4 py-2.5",children:c.jsx(tR,{issue:a})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-6",children:c.jsx(eR,{body:a.body})})]}):c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"← 从左侧列表选择候选 Issue"})})})]}),a&&c.jsx("div",{className:"flex items-center justify-center gap-3 border-t border-line bg-base px-4 py-3",children:c.jsxs("button",{type:"button","aria-label":d?"关联中":`确认将 #${a.number} 设为 #${r.number} 的子任务`,onClick:()=>void m(),disabled:d,className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-4 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-50",children:[c.jsx(fi,{className:"h-3.5 w-3.5"}),d?"关联中…":`确认: 将 #${a.number} 设为 #${r.number} 的子任务`]})})]})}function Hwe({onToggleSidebar:e,onToggleRightPanel:t,rightPanelOpen:n}){var D,z;const r=zn(),a=We(qr),i=Me($=>$.activeSessionId),o=Me($=>$.sessions.find(M=>M.id===$.activeSessionId)??null),u=Me($=>{const M=$.activeSessionId;return M?$.messages[M]??Df:Df}),d=Me($=>{const M=$.activeSessionId;return M?$.todos[M]??jf:jf}),f=Me($=>{const M=$.activeSessionId;return M?$.sessionStatuses[M]:void 0}),m=Me($=>{const M=$.activeSessionId;return M?$.queuedMessageIds[M]??IA:IA}),p=Me($=>{const M=$.activeSessionId;return M?$.errorReasons[M]:void 0}),b=Me($=>{const M=$.activeSessionId;return M?$.messagesMeta[M]:void 0}),x=Me($=>$.loadMoreMessages),E=Me($=>$.sendError),N=Me($=>$.abortSession),_=Me($=>$.revertToMessage),S=We($=>$.activeRepoId),C=We($=>$.repos.find(M=>M.id===$.activeRepoId)),A=(C==null?void 0:C.runtimeType)!=="claude-code",[I,O]=y.useState(null),[k,j]=y.useState(!1),F=Je($=>o!=null&&o.issueId?$.issues.find(M=>M.id===o.issueId):void 0),[P,L]=y.useState([]);y.useEffect(()=>{if(!S){L([]);return}let $=!1;return kc(S).then(M=>{$||L(M)}).catch(()=>{$||L([])}),()=>{$=!0}},[S]);const B=(()=>{var le;const $=(le=o==null?void 0:o.model)==null?void 0:le.modelID;if(!$)return ZI;const M=P.find(oe=>oe.id.endsWith(`/${$}`));return(M==null?void 0:M.contextLimit)??ZI})();y.useEffect(()=>{if(i)return Vp.activateSession(i),()=>Vp.deactivateSession(i)},[i]);const Y=y.useRef(null),re=y.useRef(!0),[X,K]=y.useState(!1);y.useEffect(()=>{const $=Y.current;$&&re.current&&($.scrollTop=$.scrollHeight)},[]),y.useEffect(()=>{re.current=!0,K(!1)},[]),y.useEffect(()=>{if(f!=="busy"&&f!=="retry")return;const $=M=>{if(M.key!=="Escape"||M.defaultPrevented)return;const le=M.target;le instanceof HTMLInputElement||le instanceof HTMLTextAreaElement||le!=null&&le.isContentEditable||S&&N(S)};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[f,N,S]);const V=Je($=>$.matchingParentId);if(!i)return V?c.jsx(zwe,{onToggleSidebar:e}):c.jsx(Fwe,{onToggleSidebar:e});const H=f==="busy",G=f==="retry",Q=H||G;return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden bg-term",children:[c.jsxs("header",{className:"border-b border-line bg-base md:hidden",children:[c.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",onClick:()=>j($=>!$),children:[c.jsxs("div",{className:"flex items-center gap-1",onClick:$=>$.stopPropagation(),children:[c.jsx("button",{type:"button",onClick:e,"aria-label":"Open sidebar",className:"-ml-1 rounded-lg p-1.5 text-fg-3 hover:bg-elevated",children:c.jsx(DE,{className:"h-5 w-5"})}),c.jsx("button",{type:"button",onClick:()=>Me.setState({activeSessionId:null}),"aria-label":"新建运行",title:"新建运行",className:"rounded-lg p-1.5 text-fg-3 hover:bg-elevated",children:c.jsx(ua,{className:"h-5 w-5"})})]}),c.jsxs("div",{className:"min-w-0 flex-1",children:[(o==null?void 0:o.parentID)&&c.jsxs("button",{type:"button","aria-label":"返回父会话",onClick:$=>{$.stopPropagation(),S&&Me.getState().setActiveSession(S,o.parentID)},className:"mb-0.5 flex items-center gap-1 text-[11px] text-fg-4 transition-colors hover:text-blue-400",children:[c.jsx(If,{className:"h-3 w-3"}),"返回父会话"]}),c.jsx("h2",{className:"text-sm font-medium leading-snug text-fg",children:((D=o==null?void 0:o.title)==null?void 0:D.trim())||"untitled run"})]}),Q&&c.jsx("span",{className:ie("h-2 w-2 shrink-0 rounded-full","bg-amber-400 animate-pulse")}),!Q&&f==="error"&&c.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-red-400"}),c.jsx(kr,{className:ie("h-4 w-4 shrink-0 text-fg-5 transition-transform duration-200",k&&"rotate-180")})]}),c.jsx("div",{className:ie("grid transition-[grid-template-rows] duration-200 ease-in-out",k?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:c.jsx("div",{className:"overflow-hidden",children:c.jsxs("div",{className:"flex flex-col gap-2.5 border-t border-line/60 px-4 py-3",children:[(o==null?void 0:o.agent)&&c.jsxs("div",{className:"flex items-center gap-2 font-mono text-xs text-fg-4",children:[c.jsx("span",{className:"w-14 shrink-0 text-fg-5",children:"Agent"}),c.jsx("span",{className:"truncate",children:o.agent})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"w-14 shrink-0 font-mono text-xs text-fg-5",children:"Status"}),c.jsx(QI,{status:f,reason:p})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"w-14 shrink-0 font-mono text-xs text-fg-5",children:"Context"}),c.jsx(JI,{session:o,messages:u,contextLimit:B})]}),F&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"w-14 shrink-0 font-mono text-xs text-fg-5",children:"Issue"}),c.jsxs("button",{type:"button","aria-label":`查看 Issue #${F.number}: ${F.title}`,onClick:()=>r(`/${encodeURIComponent(a)}/dev/issues?id=${F.id}`),className:"flex items-center gap-1.5 truncate font-mono text-xs text-fg-3 transition-colors hover:text-blue-400",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1 py-0.5 text-[10px] font-semibold",F.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",F.number]}),c.jsx("span",{className:"truncate",children:F.title})]})]}),Q&&c.jsxs("button",{type:"button","aria-label":G?"停止重试":"停止运行",onClick:()=>S&&void N(S),className:"mt-0.5 flex w-full items-center justify-center gap-1.5 rounded-md border border-line px-2.5 py-1.5 font-mono text-xs text-fg-2 transition-colors hover:border-red-500/50 hover:text-red-400",children:[c.jsx(Vv,{className:"h-3 w-3 fill-current"}),G?"stop retry":"stop"]})]})})})]}),c.jsxs("header",{className:"hidden items-center gap-3 border-b border-line bg-base px-4 py-2.5 md:flex",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[(o==null?void 0:o.parentID)&&c.jsxs("button",{type:"button","aria-label":"返回父会话",onClick:()=>S&&void Me.getState().setActiveSession(S,o.parentID),className:"mb-0.5 flex items-center gap-1 text-[11px] text-fg-4 transition-colors hover:text-blue-400",children:[c.jsx(If,{className:"h-3 w-3"}),"返回父会话"]}),c.jsx("h2",{className:"truncate text-sm font-medium text-fg",children:((z=o==null?void 0:o.title)==null?void 0:z.trim())||"untitled run"}),(o==null?void 0:o.agent)&&c.jsx("p",{className:"truncate font-mono text-xs text-fg-4",children:o.agent}),c.jsx(JI,{session:o,messages:u,contextLimit:B})]}),F&&c.jsxs("button",{type:"button","aria-label":`查看 Issue #${F.number}: ${F.title}`,onClick:()=>r(`/${encodeURIComponent(a)}/dev/issues?id=${F.id}`),className:"flex items-center gap-1 rounded-md border border-line px-2 py-1 font-mono text-xs text-fg-3 transition-colors hover:border-fg-5 hover:text-fg",children:[c.jsxs("span",{className:ie("rounded px-1 py-0.5 text-[10px] font-semibold",F.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",F.number]}),c.jsx("span",{className:"hidden max-w-[120px] truncate sm:inline",children:F.title})]}),c.jsx(QI,{status:f,reason:p}),t&&c.jsx("button",{type:"button",onClick:t,"aria-label":n?"关闭侧边栏":"打开侧边栏",className:ie("flex items-center justify-center rounded-md border border-line p-1.5 transition-colors",n?"bg-blue-500/10 text-blue-500 hover:bg-blue-500/20":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:c.jsx(VR,{className:"h-4 w-4"})}),Q&&c.jsxs("button",{type:"button","aria-label":G?"停止重试":"停止运行",onClick:()=>S&&void N(S),className:"flex items-center gap-1.5 rounded-md border border-line px-2.5 py-1 font-mono text-xs text-fg-2 transition-colors hover:border-red-500/50 hover:text-red-400",children:[c.jsx(Vv,{className:"h-3 w-3 fill-current"}),G?"stop retry":"stop"]})]}),c.jsxs("div",{className:"relative min-h-0 flex-1",children:[c.jsx("div",{ref:Y,onScroll:()=>{const $=Y.current;if(!$)return;const M=$.scrollHeight-$.clientHeight-$.scrollTop<=Uwe;if(re.current=M,K(!M),$.scrollTop<200&&i&&(b!=null&&b.hasMore)&&!b.loading){const le=$.scrollHeight;x(S,i).then(()=>{requestAnimationFrame(()=>{Y.current&&(Y.current.scrollTop=Y.current.scrollHeight-le)})})}},className:"h-full overflow-y-auto",children:c.jsxs("div",{className:"mx-auto flex max-w-4xl flex-col gap-3 px-4 py-4",children:[(b==null?void 0:b.loading)&&c.jsx("div",{className:"flex justify-center py-2",children:c.jsx("span",{className:"inline-block h-4 w-4 animate-spin rounded-full border-2 border-fg-5 border-t-transparent"})}),b&&!b.loading&&b.hasMore&&c.jsx("button",{type:"button","aria-label":"加载更早的消息",onClick:()=>i&&S&&x(S,i),className:"mx-auto rounded-md border border-line px-3 py-1 font-mono text-xs text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2",children:"加载更早的消息"}),u.length===0?c.jsxs("p",{className:"py-10 text-center font-mono text-xs text-fg-6",children:[c.jsx("span",{className:"text-emerald-500/60",children:"❯"})," waiting for input",c.jsx("span",{className:"fs-blink",children:" ▋"})]}):u.map(($,M)=>c.jsxs(y.Fragment,{children:[M>0&&$.role==="user"&&c.jsx("div",{className:"group/revert relative border-t border-line py-2",children:A&&!Q&&c.jsxs("button",{type:"button","aria-label":"回退到此处",disabled:I!==null,onClick:async()=>{const le=u.length-M;window.confirm(`回退到此处?将移除后续 ${le} 条对话记录(不影响已产生的代码改动)。`)&&(O($.id),await _(S,i,$.id),O(null))},className:"absolute left-1/2 top-1/2 z-10 flex -translate-x-1/2 -translate-y-1/2 items-center gap-1 rounded-full border border-line bg-base px-2.5 py-1 font-mono text-[11px] text-fg-4 opacity-60 shadow-sm transition-all duration-150 hover:border-amber-500/50 hover:text-amber-400 md:opacity-30 md:group-hover/revert:opacity-100 disabled:opacity-50",children:[I===$.id?c.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsx(LH,{className:"h-3 w-3"}),"回退到此处"]})}),c.jsx("div",{"data-message-id":$.id,children:c.jsx(Awe,{message:$,isStreaming:H&&M===u.length-1,queued:m.includes($.id)})})]},$.id)),d.length>0&&c.jsx(Lwe,{todos:[...d],onClick:t})]})}),c.jsx("button",{type:"button",onClick:()=>{const $=Y.current;$&&($.scrollTo({top:$.scrollHeight,behavior:"smooth"}),re.current=!0)},"aria-label":"滚动到底部",className:ie("absolute bottom-4 right-4 z-10 flex h-9 w-9 items-center justify-center rounded-full border border-line bg-surface/90 text-fg-4 shadow-lg backdrop-blur transition-all duration-200","hover:bg-elevated hover:text-fg-2",X?"translate-y-0 opacity-100":"pointer-events-none translate-y-2 opacity-0"),children:c.jsx(kr,{className:"h-4 w-4"})})]}),f==="error"&&p&&c.jsxs("div",{className:"flex items-center gap-2 border-t border-red-500/20 bg-red-500/10 px-4 py-2 font-mono text-xs text-red-400",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:p})]}),E&&c.jsxs("div",{className:"flex items-center gap-2 border-t border-red-500/20 bg-red-500/10 px-4 py-2 font-mono text-xs text-red-400",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:E})]}),c.jsx(Mwe,{})]})}const $we={completed:{glyph:"✓",color:"text-emerald-400",spin:!1},in_progress:{glyph:"◌",color:"text-amber-400",spin:!0},cancelled:{glyph:"✗",color:"text-fg-5",spin:!1},pending:{glyph:"○",color:"text-fg-4",spin:!1}};function Ywe(e){var a;const t=(a=e.time)==null?void 0:a.created;if(!t)return"";const n=t<1e12?t*1e3:t;return new Date(n).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}function qwe(e){if(!e.parts)return"";for(const t of e.parts){const n=t.content??t.text;if(n)return n}return""}function Gwe({todos:e}){if(e.length===0)return c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"暂无待办项"})});const t=e.filter(n=>{const r=Dl(n.status);return r==="completed"||r==="cancelled"}).length;return c.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:[c.jsxs("div",{className:"mb-2 font-mono text-[10px] tabular-nums text-fg-5",children:["进度 ",t,"/",e.length]}),c.jsx("ul",{className:"space-y-1.5",children:e.map(n=>{const r=Dl(n.status),a=$we[r],i=r==="completed"||r==="cancelled";return c.jsxs("li",{className:"flex items-start gap-2 font-mono text-xs",children:[c.jsx("span",{className:ie("shrink-0 leading-5",a.color,a.spin&&"fs-spin"),children:a.glyph}),c.jsx("span",{className:ie("leading-5",i?"text-fg-5 line-through":"text-fg-2"),children:n.content})]},n.id)})})]})}function Kwe({messages:e,onScrollToMessage:t}){const n=e.filter(r=>r.role==="user");return n.length===0?c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"暂无输入记录"})}):c.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-2",children:c.jsx("ul",{className:"space-y-1",children:n.map((r,a)=>{const i=qwe(r),o=Ywe(r);return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:()=>t==null?void 0:t(r.id),className:"group w-full rounded-md px-2 py-1.5 text-left transition-colors hover:bg-elevated/60",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"shrink-0 font-mono text-[10px] text-emerald-400/60",children:"❯"}),c.jsxs("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-fg-5",children:["#",a+1]}),o&&c.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] text-fg-6",children:o})]}),i&&c.jsx("p",{className:"mt-0.5 line-clamp-2 pl-5 text-xs leading-relaxed text-fg-3 group-hover:text-fg-2",children:i})]})},r.id)})})})}function Vwe({linked:e,number:t,title:n,state:r,mergedAt:a,isPr:i,onToggle:o}){const u=i?r==="open"?"bg-emerald-500/15 text-emerald-400":a?"bg-purple-500/15 text-purple-400":"bg-red-500/15 text-red-400":r==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400";return c.jsx("li",{children:c.jsx("button",{type:"button",onClick:o,className:ie("flex w-full items-start gap-2 rounded-md px-2 py-2 text-left transition-colors",e?"border-l-2 border-emerald-500 bg-emerald-500/5":"border-l-2 border-transparent hover:bg-elevated/50"),children:c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-semibold",u),children:["#",t]}),c.jsx("span",{className:"min-w-0 truncate text-xs text-fg-2",children:n}),e&&c.jsx(ME,{className:"ml-auto h-3 w-3 shrink-0 text-emerald-400"})]})})})}function Wwe({links:e,sessionId:t}){var j,F,P,L;const n=zn(),r=We(qr),[a,i]=y.useState(null),[o,u]=y.useState(""),d=y.useRef(null),f=Je(B=>B.issues),m=mn(B=>B.pulls),p=Me(B=>B.addLink),b=Me(B=>B.removeLink),x=new Set(((j=e==null?void 0:e.issues)==null?void 0:j.map(B=>B.id))??[]),E=new Set(((F=e==null?void 0:e.pullRequests)==null?void 0:F.map(B=>B.id))??[]);y.useEffect(()=>{var B;a&&((B=d.current)==null||B.focus())},[a]);const N=()=>{i(null),u("")},_=We(B=>B.activeRepoId),S=async(B,Y,re)=>{!t||!_||(re?await b(_,t,B,Y):await p(_,t,B,Y))},C=o.trim().toLowerCase(),A=C?f.filter(B=>`#${B.number} ${B.title}`.toLowerCase().includes(C)):f,I=C?m.filter(B=>`#${B.number} ${B.title} ${B.headBranch}`.toLowerCase().includes(C)):m,O=((P=e==null?void 0:e.issues)==null?void 0:P.length)??0,k=((L=e==null?void 0:e.pullRequests)==null?void 0:L.length)??0;if(a){const B=a==="issue",Y=B?A:I,re=B?x:E;return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-2",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-blue-400",children:B?"关联 Issue":"关联 PR"}),c.jsxs("button",{type:"button",onClick:N,className:"flex h-6 items-center gap-1 rounded-md px-2 text-xs text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:[c.jsx(At,{className:"h-3.5 w-3.5"}),"完成"]})]}),c.jsx("div",{className:"border-b border-line px-3 py-2",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2 py-1",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{ref:d,type:"text",value:o,onChange:X=>u(X.target.value),placeholder:B?"搜索 issue...":"搜索 PR...",className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),o&&c.jsx("button",{type:"button",onClick:()=>u(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:Y.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:(B?f:m).length===0?B?"暂无 Issue,请先同步":"暂无 PR,请先同步":"无匹配结果"}):c.jsx("ul",{className:"space-y-0.5",children:Y.map(X=>c.jsx(Vwe,{linked:re.has(X.id),number:X.number,title:X.title,state:X.state,mergedAt:B?void 0:X.mergedAt,isPr:!B,onToggle:()=>S(a,X.id,re.has(X.id))},X.id))})})]})}return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-line px-3 py-2",children:[c.jsx("span",{className:"flex-1 font-mono text-[10px] text-fg-5",children:O+k>0?`${O+k} 项关联`:"暂无关联"}),c.jsxs("button",{type:"button",onClick:()=>i("issue"),className:"flex h-6 items-center gap-1 rounded-md border border-line px-1.5 text-fg-4 transition-colors hover:border-emerald-500/50 hover:text-emerald-400",children:[c.jsx(ua,{className:"h-3 w-3"}),c.jsx("span",{className:"text-[10px] font-medium",children:"Issue"})]}),c.jsxs("button",{type:"button",onClick:()=>i("pr"),className:"flex h-6 items-center gap-1 rounded-md border border-line px-1.5 text-fg-4 transition-colors hover:border-blue-500/50 hover:text-blue-400",children:[c.jsx(ua,{className:"h-3 w-3"}),c.jsx("span",{className:"text-[10px] font-medium",children:"PR"})]})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:[O>0&&c.jsxs("div",{className:"mb-3",children:[c.jsxs("div",{className:"mb-1.5 font-mono text-[10px] font-medium uppercase tracking-wider text-fg-5",children:["Issues (",O,")"]}),c.jsx("ul",{className:"space-y-1",children:e==null?void 0:e.issues.map(B=>c.jsxs("li",{className:"group flex items-start gap-1",children:[c.jsxs("button",{type:"button",onClick:()=>n(`/${encodeURIComponent(r)}/dev/issues?id=${encodeURIComponent(B.id)}`),className:"flex min-w-0 flex-1 items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-elevated/60",children:[c.jsxs("span",{className:ie("mt-0.5 shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-semibold",B.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",B.number]}),c.jsx("span",{className:"line-clamp-2 text-xs leading-5 text-fg-3 group-hover:text-fg-2",children:B.title})]}),c.jsx("button",{type:"button",onClick:()=>void S("issue",B.id,!0),className:"mt-1.5 hidden shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:bg-red-500/15 hover:text-red-400 group-hover:block",children:c.jsx(At,{className:"h-3 w-3"})})]},B.id))})]}),k>0&&c.jsxs("div",{children:[c.jsxs("div",{className:"mb-1.5 font-mono text-[10px] font-medium uppercase tracking-wider text-fg-5",children:["Pull Requests (",k,")"]}),c.jsx("ul",{className:"space-y-1",children:e==null?void 0:e.pullRequests.map(B=>c.jsxs("li",{className:"group flex items-start gap-1",children:[c.jsxs("button",{type:"button",onClick:()=>n(`/${encodeURIComponent(r)}/dev/pulls?id=${encodeURIComponent(B.id)}`),className:"flex min-w-0 flex-1 items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-elevated/60",children:[c.jsxs("span",{className:ie("mt-0.5 shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-semibold",B.state==="open"?"bg-emerald-500/15 text-emerald-400":B.mergedAt?"bg-purple-500/15 text-purple-400":"bg-red-500/15 text-red-400"),children:["#",B.number]}),c.jsx("span",{className:"line-clamp-2 text-xs leading-5 text-fg-3 group-hover:text-fg-2",children:B.title})]}),c.jsx("button",{type:"button",onClick:()=>void S("pr",B.id,!0),className:"mt-1.5 hidden shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:bg-red-500/15 hover:text-red-400 group-hover:block",children:c.jsx(At,{className:"h-3 w-3"})})]},B.id))})]}),O===0&&k===0&&c.jsx("div",{className:"flex flex-1 items-center justify-center py-10",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"点击上方按钮添加关联"})})]})]})}const Xwe={"visual-engineering":"bg-purple-500/15 text-purple-400",quick:"bg-emerald-500/15 text-emerald-400",deep:"bg-blue-500/15 text-blue-400",ultrabrain:"bg-amber-500/15 text-amber-400",artistry:"bg-pink-500/15 text-pink-400",writing:"bg-cyan-500/15 text-cyan-400",explore:"bg-teal-500/15 text-teal-400",librarian:"bg-indigo-500/15 text-indigo-400",oracle:"bg-amber-500/15 text-amber-400",metis:"bg-rose-500/15 text-rose-400",momus:"bg-orange-500/15 text-orange-400"};function Qwe(e){switch(e){case"idle":return"bg-emerald-500";case"busy":case"retry":return"bg-amber-500 animate-pulse";case"error":return"bg-red-500";default:return"bg-fg-5"}}function Hv(e){var n;const t=(n=e.time)==null?void 0:n.created;if(t)return t<1e12?t*1e3:t;if(e.createdAt){const r=Date.parse(e.createdAt);if(!Number.isNaN(r))return r}return null}function Zwe(e){const t=Date.now()-e,n=Math.floor(t/1e3);if(n<60)return"just now";const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const a=Math.floor(r/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}function Jwe(){const e=Me(f=>f.sessions),t=Me(f=>f.activeSessionId),n=Me(f=>f.sessionStatuses),r=Me(f=>f.setActiveSession),a=We(f=>f.activeRepoId),i=e.find(f=>f.id===t),o=(i==null?void 0:i.parentID)??t,u=!!(i!=null&&i.parentID),d=e.filter(f=>f.parentID===o).sort((f,m)=>(Hv(m)??0)-(Hv(f)??0));return d.length===0?c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"暂无子任务"})}):c.jsxs("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:[u&&c.jsxs("div",{className:"mb-1.5 px-2 font-mono text-[10px] text-fg-5",children:["同级子任务 (",d.length,")"]}),c.jsx("ul",{className:"space-y-0.5",children:d.map(f=>{const m=f.id===t,p=n[f.id],b=Hv(f),x=(f.agent&&Xwe[f.agent])??"bg-elevated text-fg-4",E=f.title||`${f.id.slice(0,9)}...`;return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:()=>{!m&&a&&r(a,f.id)},className:ie("group flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",m?"border-l-2 border-blue-500 bg-blue-500/5":"border-l-2 border-transparent hover:bg-elevated/60"),children:[c.jsx("span",{className:ie("mt-1 h-2 w-2 shrink-0 rounded-full",Qwe(p))}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[f.agent&&c.jsx("span",{className:ie("shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-medium",x),children:f.agent}),b!=null&&c.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] tabular-nums text-fg-6",children:Zwe(b)})]}),c.jsx("p",{className:ie("mt-0.5 line-clamp-2 text-xs leading-5",m?"text-fg-2":"text-fg-3 group-hover:text-fg-2"),children:E})]})]})},f.id)})})]})}const e_e=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg"]),t_e=new Set([".html",".htm",".md",".txt",".log"]),$v=80,n_e=160,nR=.4;function r_e(e){const t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}function a_e({file:e,repoId:t,sessionId:n,onPreviewFile:r}){const a=r_e(e.path),i=vY(t,n,e.path),o=e.ext.toLowerCase();return e_e.has(o)?c.jsxs("li",{className:"flex items-center gap-2 rounded-md px-2 py-1 hover:bg-elevated/60",title:e.path,children:[c.jsx(tH,{className:"h-3 w-3 shrink-0 text-fg-5","aria-hidden":!0}),c.jsx(ow,{url:i,label:a,className:"h-8 w-8 shrink-0 object-cover"}),c.jsx("span",{className:"min-w-0 truncate text-xs text-fg-3",children:a})]}):t_e.has(o)?c.jsx("li",{children:c.jsxs("button",{type:"button",title:e.path,onClick:()=>r==null?void 0:r({url:i,name:a,ext:o}),className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left transition-colors hover:bg-elevated/60",children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:"min-w-0 truncate text-xs text-fg-3",children:a})]})}):c.jsxs("li",{className:"flex items-center gap-2 rounded-md px-2 py-1",title:e.path,children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:"min-w-0 truncate text-xs text-fg-3",children:a})]})}function i_e({repoId:e,sessionId:t,containerRef:n,onPreviewFile:r}){const[a,i]=y.useState(!1),[o,u]=y.useState(n_e),[d,f]=y.useState([]),[m,p]=y.useState(0),b=y.useRef(null),x=y.useRef(null);y.useEffect(()=>{let A=!1;const I=()=>{yY(e,t).then(k=>{A||f(k)}).catch(()=>{A||f([])})};I();const O=setInterval(I,1e4);return()=>{A=!0,clearInterval(O)}},[e,t]),y.useEffect(()=>{const A=n.current;if(!A)return;const I=()=>p(A.clientHeight);I();const O=new ResizeObserver(I);return O.observe(A),()=>O.disconnect()},[n]);const E=m>0?m*nR:o,N=Math.max($v,E),_=Math.min(o,N),S=y.useCallback(A=>{A.preventDefault();const I=n.current,O=Math.max($v,I?I.clientHeight*nR:N);x.current={startY:A.clientY,startHeight:_,maxHeight:O};const k=F=>{const P=x.current;if(!P)return;const L=P.startY-F.clientY,B=Math.max($v,Math.min(P.startHeight+L,P.maxHeight));b.current&&(b.current.style.height=`${B}px`)},j=()=>{const F=b.current;if(F){const P=parseInt(F.style.height,10);Number.isNaN(P)||u(P)}x.current=null,window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",j)};window.addEventListener("mousemove",k),window.addEventListener("mouseup",j)},[n,_,N]),C=d.length;return a?c.jsxs("div",{ref:b,className:"flex shrink-0 flex-col border-t border-line bg-surface",style:{height:`${_}px`},children:[c.jsx("div",{onMouseDown:S,role:"separator","aria-orientation":"horizontal",className:"flex h-1 shrink-0 cursor-row-resize items-center justify-center bg-line transition-colors hover:bg-blue-500/60",children:c.jsx(Kz,{className:"h-2 w-8 text-fg-6","aria-hidden":!0})}),c.jsxs("button",{type:"button",onClick:()=>i(!1),className:"flex shrink-0 items-center gap-1.5 border-b border-line px-3 py-2 text-left transition-colors hover:bg-elevated/60",children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"变更文件"}),c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:C}),c.jsx(kr,{className:"ml-auto h-3.5 w-3.5 text-fg-5"})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-1 py-1",children:C===0?c.jsx("p",{className:"px-2 py-4 text-center font-mono text-xs text-fg-5",children:"暂无变更文件"}):c.jsx("ul",{className:"space-y-0.5",children:d.map(A=>c.jsx(a_e,{file:A,repoId:e,sessionId:t,onPreviewFile:r},A.path))})})]}):c.jsxs("button",{type:"button",onClick:()=>i(!0),className:"flex w-full shrink-0 items-center gap-1.5 border-t border-line px-3 py-2 text-left transition-colors hover:bg-elevated/60",children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"变更文件"}),c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:C}),c.jsx(OE,{className:"ml-auto h-3.5 w-3.5 text-fg-5"})]})}function rR({todos:e,messages:t,sessionLinks:n,sessionId:r,onScrollToMessage:a,onPreviewFile:i}){var S,C;const[o,u]=y.useState("todo"),d=y.useRef(null),f=We(A=>A.activeRepoId),m=Me(A=>A.sessions),p=Me(A=>A.activeSessionId),b=t.filter(A=>A.role==="user").length,x=(((S=n==null?void 0:n.issues)==null?void 0:S.length)??0)+(((C=n==null?void 0:n.pullRequests)==null?void 0:C.length)??0),E=m.find(A=>A.id===p),N=(E==null?void 0:E.parentID)??p,_=m.filter(A=>A.parentID===N).length;return c.jsxs("div",{ref:d,className:"flex h-full w-72 shrink-0 flex-col border-l border-line bg-surface",children:[c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[c.jsxs("div",{"data-guide":"run-side-tabs",className:"flex items-center border-b border-line",children:[c.jsxs("button",{type:"button",onClick:()=>u("todo"),className:ie("flex flex-1 items-center justify-center gap-1 border-b-2 px-2 py-2.5 text-xs font-medium transition-colors",o==="todo"?"border-blue-500 text-blue-500":"border-transparent text-fg-4 hover:text-fg-2"),children:["待办",e.length>0&&c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:e.length})]}),c.jsxs("button",{type:"button",onClick:()=>u("prompts"),className:ie("flex flex-1 items-center justify-center gap-1 border-b-2 px-2 py-2.5 text-xs font-medium transition-colors",o==="prompts"?"border-blue-500 text-blue-500":"border-transparent text-fg-4 hover:text-fg-2"),children:["输入",b>0&&c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:b})]}),c.jsxs("button",{type:"button",onClick:()=>u("links"),className:ie("flex flex-1 items-center justify-center gap-1 border-b-2 px-2 py-2.5 text-xs font-medium transition-colors",o==="links"?"border-blue-500 text-blue-500":"border-transparent text-fg-4 hover:text-fg-2"),children:["关联",x>0&&c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:x})]}),c.jsxs("button",{type:"button",onClick:()=>u("subtasks"),className:ie("flex flex-1 items-center justify-center gap-1 border-b-2 px-2 py-2.5 text-xs font-medium transition-colors",o==="subtasks"?"border-blue-500 text-blue-500":"border-transparent text-fg-4 hover:text-fg-2"),children:["子任务",_>0&&c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:_})]})]}),o==="todo"?c.jsx(Gwe,{todos:e}):o==="prompts"?c.jsx(Kwe,{messages:t,onScrollToMessage:a}):o==="links"?c.jsx(Wwe,{links:n,sessionId:r}):c.jsx(Jwe,{})]}),r&&f&&c.jsx(i_e,{repoId:f,sessionId:r,containerRef:d,onPreviewFile:i})]})}function gE(e){var t,n;if(typeof((t=e.time)==null?void 0:t.updated)=="number")return e.time.updated;if(typeof((n=e.time)==null?void 0:n.created)=="number")return e.time.created;if(e.createdAt){const r=Date.parse(e.createdAt);return Number.isNaN(r)?0:r}return 0}function s_e(e){const t=gE(e);if(!t)return"";const n=t<1e12?t*1e3:t,r=new Date(n);return r.toDateString()===new Date().toDateString()?r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):r.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function aR(e){navigator.clipboard?navigator.clipboard.writeText(e).catch(()=>iR(e)):iR(e)}function iR(e){const t=document.createElement("textarea");t.value=e,t.style.cssText="position:fixed;opacity:0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}function o_e(e){switch(e){case"idle":return"bg-emerald-500";case"busy":case"retry":return"bg-amber-500 animate-pulse";case"error":return"bg-red-500";default:return"bg-fg-5"}}const sR="fs:swipe-hint-shown",cf=144,l_e=-60,u_e=600,c_e=800;function d_e({session:e,isActive:t,peekHint:n,onSelect:r,onRename:a,onToggleComplete:i,onTogglePin:o,status:u,issue:d,linkedItems:f,todos:m}){var z,$;const p=Fp(M=>M.drafts[e.id]),b=!!e.completedAt,x=!!e.pinnedAt,E=s_e(e),[N,_]=y.useState(!1),[S,C]=y.useState(""),A=y.useRef(null),I=()=>{var M;C(((M=e.title)==null?void 0:M.trim())||""),_(!0),requestAnimationFrame(()=>{var le;return(le=A.current)==null?void 0:le.focus()})},O=()=>{var le;_(!1);const M=S.trim();M&&M!==(((le=e.title)==null?void 0:le.trim())||"")&&a(M)},[k,j]=y.useState(null),F=y.useRef(null),P=y.useRef(!1),L=()=>{F.current&&(clearTimeout(F.current),F.current=null)},B=y.useRef(null),Y=y.useRef(null),re=y.useRef(0),X=y.useRef({x0:0,y0:0,base:0,dir:null,on:!1}),K=M=>{re.current=M;const le=B.current,oe=Y.current;le&&(le.style.transform=M!==0?`translateX(${M}px)`:"",le.style.pointerEvents=M===-cf?"none":""),oe&&(oe.style.width=`${Math.abs(M)}px`)},V=M=>{const le=M.touches[0];X.current={x0:le.clientX,y0:le.clientY,base:re.current,dir:null,on:!0},B.current&&(B.current.style.transition="none"),Y.current&&(Y.current.style.transition="none"),P.current=!1,L(),F.current=setTimeout(()=>{P.current=!0,X.current.on=!1,j({x:le.clientX,y:le.clientY})},500)},H=M=>{const le=X.current;if(!le.on){L();return}const oe=M.touches[0].clientX-le.x0,ne=M.touches[0].clientY-le.y0;if(!le.dir){(Math.abs(oe)>5||Math.abs(ne)>5)&&(le.dir=Math.abs(oe)>Math.abs(ne)?"h":"v",L());return}le.dir!=="v"&&K(Math.max(-cf,Math.min(0,le.base+oe)))},G=M=>{const le=B.current,oe=Y.current;le&&(le.style.transition="transform 200ms ease-out"),oe&&(oe.style.transition="width 200ms ease-out"),K(M)},Q=()=>{if(L(),P.current){P.current=!1;return}X.current.on=!1,G(re.current<-cf/2?-cf:0)},D=()=>G(0);return y.useEffect(()=>{if(!n)return;const M=setTimeout(()=>{const le=B.current,oe=Y.current;le&&(le.style.transition="transform 400ms cubic-bezier(.25,.8,.25,1)"),oe&&(oe.style.transition="width 400ms cubic-bezier(.25,.8,.25,1)"),K(l_e);const ne=setTimeout(()=>{le&&(le.style.transition="transform 500ms cubic-bezier(.25,.8,.25,1)"),oe&&(oe.style.transition="width 500ms cubic-bezier(.25,.8,.25,1)"),K(0)},c_e);return()=>clearTimeout(ne)},u_e);return()=>clearTimeout(M)},[n,K]),c.jsxs("li",{className:"relative overflow-hidden rounded-md",children:[c.jsx("div",{ref:Y,className:"absolute right-0 top-0 bottom-0 z-10 overflow-hidden md:hidden",style:{width:0},children:c.jsxs("div",{className:"absolute right-0 top-0 bottom-0 flex",style:{width:cf},children:[c.jsxs("button",{type:"button",onClick:()=>{o(),D()},className:ie("flex w-12 flex-col items-center justify-center gap-0.5 text-white",x?"bg-amber-500 active:bg-amber-600":"bg-blue-500 active:bg-blue-600"),children:[c.jsx(Sy,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"text-[9px] leading-none",children:x?"取消":"置顶"})]}),c.jsxs("button",{type:"button",onClick:()=>{i(),D()},className:ie("flex w-12 flex-col items-center justify-center gap-0.5 text-white",b?"bg-neutral-500 active:bg-neutral-600":"bg-emerald-500 active:bg-emerald-600"),children:[c.jsx(Ny,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"text-[9px] leading-none",children:b?"撤销":"完成"})]}),c.jsxs("button",{type:"button",onClick:()=>{I(),D()},className:"flex w-12 flex-col items-center justify-center gap-0.5 bg-amber-500 text-white active:bg-amber-600",children:[c.jsx(oA,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"text-[9px] leading-none",children:"重命名"})]})]})}),c.jsxs("div",{ref:B,className:ie("group relative rounded-md border-l-2 will-change-transform",t?"border-blue-500 bg-elevated":"border-transparent bg-surface hover:bg-elevated/50"),onTouchStart:V,onTouchMove:H,onTouchEnd:Q,onContextMenu:M=>M.preventDefault(),children:[c.jsxs("button",{type:"button",onClick:()=>{N||(r(),D())},className:ie("block w-full px-2.5 py-2 text-left",b&&!t&&"opacity-50"),style:{pointerEvents:"auto"},children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:ie("h-1.5 w-1.5 shrink-0 rounded-full",o_e(u))}),c.jsx("span",{className:"min-w-0 truncate font-mono text-xs text-fg-3",children:((z=e.agent)==null?void 0:z.trim())||"默认"}),x&&c.jsx(Sy,{className:"h-3 w-3 shrink-0 text-amber-400"}),b&&c.jsx(Ny,{className:"h-3 w-3 shrink-0 text-emerald-400"}),E&&c.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] tabular-nums text-fg-5",children:E})]}),N?c.jsx("input",{ref:A,type:"text",value:S,onChange:M=>C(M.target.value),onBlur:O,onKeyDown:M=>{M.key==="Enter"&&O(),M.key==="Escape"&&_(!1)},onClick:M=>M.stopPropagation(),className:"mt-0.5 w-full rounded border border-blue-500 bg-base pl-3.5 text-sm text-fg-2 outline-none"}):c.jsxs("div",{className:"mt-0.5 pl-3.5",onDoubleClick:M=>{M.stopPropagation(),I()},children:[(d||f)&&c.jsxs("div",{className:"mb-0.5 flex flex-wrap gap-1",children:[d&&c.jsxs("span",{className:ie("shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-medium leading-none",d.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",d.number]}),f==null?void 0:f.map(M=>c.jsx("span",{className:ie("shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-medium leading-none",M.type==="pr"?M.state==="open"?"bg-blue-500/15 text-blue-400":M.mergedAt?"bg-purple-500/15 text-purple-400":"bg-red-500/15 text-red-400":M.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:M.type==="pr"?`PR#${M.number}`:`#${M.number}`},`${M.type}-${M.number}`))]}),c.jsx("span",{className:"block truncate text-sm text-fg-2",children:(($=e.title)==null?void 0:$.trim())||"未命名运行"}),p&&c.jsxs("span",{className:"mt-0.5 block truncate text-xs text-amber-400/80",children:["✏️ ",p]}),m.length>0&&(()=>{const M=m.length,le=mM(m);return c.jsxs("span",{className:"mt-0.5 flex items-center gap-1.5 font-mono text-[10px]",children:[c.jsx("span",{className:"shrink-0 tracking-tight",children:m.map(oe=>{const ne=Dl(oe.status);return c.jsx("span",{className:ne==="completed"?"text-emerald-400":ne==="in_progress"?"text-amber-400":ne==="cancelled"?"text-fg-6":"text-fg-5",children:ne==="pending"?"□":"■"},oe.id)})}),c.jsxs("span",{className:"tabular-nums text-fg-4",children:[le,"/",M]})]})})()]})]}),c.jsxs("span",{className:"absolute right-1.5 top-1.5 hidden items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 md:flex",children:[c.jsx("button",{type:"button",onClick:o,title:x?"取消置顶":"置顶",className:ie("rounded p-1",x?"text-amber-400 hover:text-amber-300":"text-fg-5 hover:text-amber-400"),children:c.jsx(Sy,{className:"h-3.5 w-3.5"})}),c.jsx("button",{type:"button",onClick:i,title:b?"取消完成":"标记完成",className:ie("rounded p-1",b?"text-emerald-400 hover:text-emerald-300":"text-fg-5 hover:text-emerald-400"),children:c.jsx(Ny,{className:"h-3.5 w-3.5"})}),c.jsx("button",{type:"button",onClick:I,title:"重命名",className:"rounded p-1 text-fg-5 hover:text-fg-2",children:c.jsx(oA,{className:"h-3.5 w-3.5"})}),c.jsx("button",{type:"button",onClick:()=>{var M;aR(JSON.stringify({id:e.id,name:((M=e.title)==null?void 0:M.trim())||""},null,2))},title:"复制 Session JSON",className:"rounded p-1 text-fg-5 hover:text-fg-2",children:c.jsx($p,{className:"h-3.5 w-3.5"})})]})]}),k&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"fixed inset-0 z-50",onClick:()=>j(null),onTouchEnd:()=>j(null)}),c.jsx("div",{className:"fixed z-50 min-w-[160px] rounded-lg border border-line bg-surface py-1 shadow-xl",style:{left:Math.min(k.x,window.innerWidth-176),top:k.y,animation:"ctx-fade-in 150ms ease-out"},children:c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm text-fg-2 active:bg-elevated",onClick:()=>{var M;aR(JSON.stringify({id:e.id,name:((M=e.title)==null?void 0:M.trim())||""},null,2)),j(null)},children:[c.jsx($p,{className:"h-3.5 w-3.5 text-fg-5"}),"复制 Session JSON"]})})]})]})}const f_e=y.memo(d_e,(e,t)=>{var n,r,a,i,o,u,d,f;return e.session.id===t.session.id&&e.session.title===t.session.title&&e.session.agent===t.session.agent&&e.session.completedAt===t.session.completedAt&&e.session.pinnedAt===t.session.pinnedAt&&((n=e.session.time)==null?void 0:n.updated)===((r=t.session.time)==null?void 0:r.updated)&&e.isActive===t.isActive&&e.peekHint===t.peekHint&&e.status===t.status&&((a=e.issue)==null?void 0:a.number)===((i=t.issue)==null?void 0:i.number)&&((o=e.issue)==null?void 0:o.state)===((u=t.issue)==null?void 0:u.state)&&(((d=e.linkedItems)==null?void 0:d.length)??0)===(((f=t.linkedItems)==null?void 0:f.length)??0)&&e.todos===t.todos});function oR({onClose:e}){const[t]=y.useState(()=>typeof window>"u"||localStorage.getItem(sR)?!1:(localStorage.setItem(sR,"1"),!0)),n=Me(O=>O.sessions),r=Me(O=>O.activeSessionId),a=Me(O=>O.sessionStatuses),i=Me(O=>O.sessionFilter),o=Me(O=>O.setSessionFilter),u=Me(O=>O.setActiveSession),d=Me(O=>O.renameSession),f=Me(O=>O.toggleSessionComplete),m=We(O=>O.activeRepoId),p=Je(O=>O.issues),b=Me(O=>O.allSessionLinks),x=Me(O=>O.todos),E=Me(O=>O.sessionSearch),N=Me(O=>O.setSessionSearch),_=Me(O=>O.toggleSessionPin),S=E.toLowerCase(),C=[...n].filter(O=>O.parentID?!1:i==="active"?!O.completedAt:!0).filter(O=>{if(!S)return!0;const k=(O.title??"").toLowerCase(),j=(O.agent??"").toLowerCase();return k.includes(S)||j.includes(S)}).sort((O,k)=>{const j=O.pinnedAt,F=k.pinnedAt;return j&&!F?-1:!j&&F?1:j&&F?F-j:gE(k)-gE(O)}),A=new Map(p.map(O=>[O.id,O])),I=O=>c.jsx("ul",{className:"space-y-0.5",children:O.map((k,j)=>{const F=k.issueId?A.get(k.issueId):void 0,P=b[k.id],L=[];if(P){for(const B of P.issues)L.push({number:B.number,state:B.state,type:"issue"});for(const B of P.pullRequests)L.push({number:B.number,state:B.state,type:"pr",mergedAt:B.mergedAt})}return c.jsx(f_e,{session:k,isActive:k.id===r,peekHint:t&&j===0,status:a[k.id],issue:F?{number:F.number,title:F.title,state:F.state}:void 0,linkedItems:L.length>0?L:void 0,onSelect:()=>{m&&u(m,k.id),e==null||e()},onRename:B=>m&&void d(m,k.id,B),onToggleComplete:()=>m&&void f(m,k.id),onTogglePin:()=>m&&void _(m,k.id),todos:x[k.id]??jf},k.id)})});return c.jsx("div",{className:"flex h-full w-80 shrink-0 flex-col border-r border-line bg-surface",children:c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-3",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-fg-3",children:"运行记录"}),m&&c.jsx("button",{type:"button",onClick:()=>{Me.setState({activeSessionId:null}),e==null||e()},title:"新建运行",className:"flex h-7 w-7 items-center justify-center rounded-md bg-blue-600 text-white transition-colors hover:bg-blue-500",children:c.jsx(ua,{className:"h-4 w-4"})})]}),m&&c.jsx("div",{className:"hidden border-b border-line px-3 py-1.5 md:block",children:c.jsxs("div",{className:"relative",children:[c.jsx(Ao,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-fg-5"}),c.jsx("input",{type:"text",value:E,onChange:O=>N(O.target.value),placeholder:"搜索运行记录...",className:"w-full rounded-md border border-line bg-base py-1 pl-7 pr-7 text-xs text-fg-2 placeholder:text-fg-5 outline-none focus:border-blue-500"}),E&&c.jsx("button",{type:"button",onClick:()=>N(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-0.5 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})}),m&&c.jsx("div",{className:"flex gap-1 border-b border-line px-3 py-1.5",children:[["active","进行中"],["all","全部"]].map(([O,k])=>c.jsx("button",{type:"button",onClick:()=>o(O),className:ie("rounded-md px-2 py-0.5 font-mono text-[11px] transition-colors",i===O?"bg-elevated text-fg-2":"text-fg-5 hover:text-fg-3"),children:k},O))}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:m?C.length===0?c.jsx("p",{className:"px-2 py-6 text-center font-mono text-xs text-fg-5",children:"暂无运行记录"}):c.jsx("div",{children:I(C)}):c.jsx("p",{className:"px-2 py-6 text-center font-mono text-xs text-fg-5",children:"请先选择一个仓库"})})]})})}function h_e(){const[e,t]=y.useState(()=>typeof window<"u"&&window.matchMedia("(min-width: 1280px)").matches);return y.useEffect(()=>{const n=window.matchMedia("(min-width: 1280px)"),r=a=>t(a.matches);return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function lR(e){const t=document.querySelector(`[data-message-id="${e}"]`);t&&(t.scrollIntoView({behavior:"smooth",block:"center"}),t.classList.add("fs-highlight"),setTimeout(()=>t.classList.remove("fs-highlight"),TY))}const uR=new Set([".html",".htm"]),m_e=".md";function p_e({file:e}){const[t,n]=y.useState(null),[r,a]=y.useState(!1);return y.useEffect(()=>{uR.has(e.ext)||(a(!0),n(null),fetch(e.url).then(i=>i.text()).then(i=>n(i)).catch(()=>n("加载失败")).finally(()=>a(!1)))},[e.url,e.ext]),uR.has(e.ext)?c.jsx("iframe",{src:e.url,sandbox:"",title:e.name,className:"h-full w-full border-0 bg-white"}):r?c.jsx("p",{className:"p-8 text-center font-mono text-sm text-fg-5",children:"加载中…"}):e.ext===m_e?c.jsx("div",{className:"h-full overflow-y-auto",children:c.jsx("div",{className:"prose prose-invert max-w-none p-6",children:c.jsx($l,{remarkPlugins:[Yl],children:t??""})})}):c.jsx("pre",{className:"h-full overflow-auto whitespace-pre-wrap p-6 font-mono text-xs leading-relaxed text-fg-2",children:t})}function g_e(e,t){switch(t.type){case"reset":return{tabs:[],activeIdx:null};case"open":{const n=e.tabs.findIndex(r=>r.url===t.info.url);return n>=0?{...e,activeIdx:n}:{tabs:[...e.tabs,t.info],activeIdx:e.tabs.length}}case"close":{const n=e.tabs.filter((a,i)=>i!==t.idx);let r=e.activeIdx;return r===t.idx?r=null:r!==null&&r>t.idx&&(r=r-1),{tabs:n,activeIdx:r}}case"activate":return{...e,activeIdx:t.idx}}}function b_e(e){const[t,n]=y.useReducer(g_e,{tabs:[],activeIdx:null});y.useEffect(()=>{n({type:"reset"})},[]);const r=y.useCallback(o=>n({type:"open",info:o}),[]),a=y.useCallback(o=>n({type:"close",idx:o}),[]),i=y.useCallback(o=>n({type:"activate",idx:o}),[]);return{tabs:t.tabs,activeIdx:t.activeIdx,open:r,close:a,activate:i}}function x_e(){const[e,t]=y.useState(!1),[n,r]=y.useState(!1),[a,i]=y.useState(!1),o=h_e(),u=Me(S=>S.activeSessionId),d=b_e(),f=ys(S=>S.sessionPanelCollapsed),m=ys(S=>S.toggleSessionPanel),p=Me(S=>{const C=S.activeSessionId;return C?S.todos[C]??jf:jf}),b=Me(S=>{const C=S.activeSessionId;return C?S.messages[C]??Df:Df}),x=Me(S=>{const C=S.activeSessionId;return C?S.sessionLinks[C]:void 0});y.useEffect(()=>{o&&u?i(!0):o||i(!1)},[o,u]);const E=a&&!!u,N=()=>{window.matchMedia("(max-width: 767px)").matches?r(S=>!S):i(S=>!S)},_=tB({onSwipeRight:()=>t(!0),onSwipeLeft:()=>r(!0),disabled:e||n});return c.jsxs("div",{className:"flex min-h-0 flex-1",..._,children:[c.jsxs("div",{className:"relative hidden shrink-0 md:flex",children:[c.jsx("div",{className:ie("overflow-hidden transition-[width] duration-200 ease-in-out",f?"w-0":"w-80"),children:c.jsx("div",{className:"h-full w-80",children:c.jsx(oR,{})})}),c.jsx("button",{type:"button","data-guide":"run-panel-handle",onClick:m,title:f?"展开运行记录":"收起运行记录",className:ie("absolute left-full top-1/2 z-20 flex h-14 w-4 -translate-y-1/2 items-center justify-center rounded-r-md border-y border-r border-line text-fg-5 transition-all duration-200 hover:bg-elevated hover:text-fg-3",f?"bg-surface opacity-80 hover:w-5 hover:opacity-100":"bg-surface/80 opacity-40 hover:opacity-100"),children:f?c.jsx(Oo,{className:"h-3 w-3"}):c.jsx(ih,{className:"h-3 w-3"})})]}),c.jsx(dE,{side:"left",open:e,onClose:()=>t(!1),children:c.jsx(oR,{onClose:()=>t(!1)})}),c.jsx(dE,{side:"right",open:n,onClose:()=>r(!1),children:c.jsx(rR,{todos:p,messages:b,sessionLinks:x,sessionId:u,onScrollToMessage:S=>{r(!1),setTimeout(()=>lR(S),CY)}})}),c.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[d.tabs.length>0&&c.jsxs("div",{className:"flex shrink-0 items-end gap-0 border-b border-line bg-surface",children:[c.jsx("button",{type:"button",onClick:()=>d.activate(null),className:ie("flex items-center gap-1.5 border-r border-line px-3 py-1.5 text-xs font-medium transition-colors",d.activeIdx===null?"border-b-2 border-b-blue-500 bg-base text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:"对话"}),d.tabs.map((S,C)=>c.jsxs("div",{className:ie("group flex items-center gap-1 border-r border-line px-2 py-1.5 text-xs transition-colors",d.activeIdx===C?"border-b-2 border-b-blue-500 bg-base text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:[c.jsx("button",{type:"button",onClick:()=>d.activate(C),className:"min-w-0 max-w-[120px] truncate font-mono",title:S.name,children:S.name}),c.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),d.close(C)},className:"shrink-0 rounded p-0.5 text-fg-5 opacity-0 transition-opacity hover:bg-elevated hover:text-fg-2 group-hover:opacity-100",children:c.jsx(At,{className:"h-3 w-3"})})]},S.url))]}),c.jsx("div",{className:ie("min-h-0 flex-1 flex flex-col",d.activeIdx!==null&&"hidden"),children:c.jsx(Hwe,{onToggleSidebar:()=>t(S=>!S),onToggleRightPanel:N,rightPanelOpen:E})}),d.activeIdx!==null&&d.tabs[d.activeIdx]&&c.jsx("div",{className:"min-h-0 flex-1 bg-base",children:c.jsx(p_e,{file:d.tabs[d.activeIdx]})})]}),E&&c.jsx("div",{className:"hidden shrink-0 md:flex",children:c.jsx(rR,{todos:p,messages:b,sessionLinks:x,sessionId:u,onScrollToMessage:lR,onPreviewFile:d.open})})]})}let fs=null;function y_e(e){const t=Date.now()-e,n=Math.floor(t/6e4);return n<1?"刚刚":n<60?`${n} 分钟前`:`${Math.floor(n/60)} 小时前`}const cR=[{id:"repos",label:"仓库",icon:FR},{id:"usage",label:"Claude 账号",icon:Cc},{id:"git",label:"Git 源站",icon:Gl},{id:"models",label:"模型",icon:Op},{id:"agents",label:"AGENTS.md",icon:Io},{id:"general",label:"通用",icon:KR},{id:"diagnostics",label:"诊断",icon:kE}],v_e={id:"server",label:"服务器",icon:ZR};function bE(e){if(!e)return null;const t=new Date(e).getTime()-Date.now();if(t<=0)return"已重置";const n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m 后重置`:`${r}m 后重置`}function E_e(e){return e>=90?"bg-red-500":e>=70?"bg-amber-500":"bg-blue-500"}function Yv({label:e,window:t}){if(!t)return null;const n=Math.round(t.utilization),r=bE(t.resets_at),a=n>=90,i=n>=70;return c.jsxs("div",{className:"space-y-1.5",children:[c.jsxs("div",{className:"flex items-center justify-between gap-3",children:[c.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-fg-3",children:e}),c.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[r&&c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-elevated px-1.5 py-0.5 text-[10px] font-medium text-fg-4 tabular-nums",children:[c.jsx(n0,{className:"h-2.5 w-2.5"}),r]}),c.jsxs("span",{className:ie("text-sm font-bold leading-none tabular-nums",a?"text-red-400":i?"text-amber-400":"text-fg"),children:[n,"%"]})]})]}),c.jsx("div",{className:"h-2.5 overflow-hidden rounded-full bg-elevated ring-1 ring-inset ring-line/60",children:c.jsx("div",{className:ie("h-full rounded-full transition-all duration-500 ease-out",E_e(n),a?"shadow-sm shadow-red-500/50":i?"shadow-sm shadow-amber-500/40":null),style:{width:`${Math.min(n,100)}%`}})})]})}function N_e({account:e,onSwitch:t,switching:n}){var a;const r=e.active;return c.jsxs("div",{className:ie("relative overflow-hidden rounded-xl border bg-base p-4 shadow-sm transition-colors",r?"border-blue-500/30 ring-1 ring-inset ring-blue-500/20":"border-line"),children:[r&&c.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-1 bg-blue-500"}),c.jsxs("div",{className:"flex items-center gap-2.5",children:[c.jsx("div",{className:ie("flex h-7 w-7 shrink-0 items-center justify-center rounded-lg",r?"bg-blue-500/15 text-blue-500":"bg-elevated text-fg-4"),children:c.jsx(XR,{className:"h-3.5 w-3.5"})}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.label}),r&&c.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 rounded-full bg-blue-500/15 px-2 py-0.5 text-[10px] font-semibold text-blue-500",children:[c.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-blue-500 shadow-sm shadow-blue-500/60"}),"当前"]}),!r&&t&&c.jsxs("button",{type:"button",onClick:()=>t(e.id),disabled:n,className:"inline-flex shrink-0 items-center gap-1 rounded-full border border-line px-2 py-0.5 text-[10px] font-medium text-fg-4 transition-colors hover:border-blue-500/50 hover:text-blue-500 disabled:opacity-40",children:[n&&c.jsx(nn,{className:"h-2.5 w-2.5 fs-spin"}),"切换"]}),e.excluded&&c.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-elevated px-2 py-0.5 text-[10px] font-medium text-fg-5",children:[c.jsx(WF,{className:"h-2.5 w-2.5"}),"不自动切"]}),e.needsReauth&&c.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-red-500/15 px-2 py-0.5 text-[10px] font-medium text-red-400",children:[c.jsx(On,{className:"h-2.5 w-2.5"}),"需重新登录"]})]}),e.holders&&e.holders.length>0&&c.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-fg-5",children:[c.jsx(QR,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:e.holders.join(", ")})]}),e.error&&!e.usage?c.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-lg bg-red-500/10 px-3 py-2 text-xs text-red-400",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"min-w-0 break-words",children:e.error})]}):e.usage?c.jsxs("div",{className:"mt-4 space-y-3",children:[c.jsx(Yv,{label:"5 小时窗口",window:e.usage.five_hour}),c.jsx(Yv,{label:"7 天窗口",window:e.usage.seven_day}),(a=e.usage.scoped)==null?void 0:a.map(i=>c.jsx(Yv,{label:i.label,window:i},i.label))]}):null]})}function S_e({onClose:e,onSuccess:t}){const[n,r]=y.useState("idle"),[a,i]=y.useState(""),[o,u]=y.useState(""),[d,f]=y.useState(""),[m,p]=y.useState(""),[b,x]=y.useState(""),[E,N]=y.useState(!1),_=async()=>{r("loading"),p("");try{const C=await bY();i(C.url),u(C.pendingId),r("waiting")}catch(C){p(C instanceof Error?C.message:String(C)),r("error")}},S=async()=>{if(!(!d.trim()||!o)){r("exchanging"),p("");try{const C=await xY(o,d.trim());if(C.ok)x(C.label),N(C.existing),r("done");else{const A=C.detail||C.reason;C.attemptsLeft!==void 0&&C.attemptsLeft>0?(p(`${A}(还可重试 ${C.attemptsLeft} 次)`),r("waiting")):C.reason==="throttled"?(p("请求过快,请稍后再试"),r("waiting")):(p(A),r("error"))}}catch(C){p(C instanceof Error?C.message:String(C)),r("error")}}};return y.useEffect(()=>{_()},[_]),c.jsx("div",{className:"fixed inset-0 z-50 flex items-end justify-center bg-black/50 backdrop-blur-sm sm:items-center",onClick:e,children:c.jsxs("div",{className:"flex w-full max-w-lg flex-col rounded-t-2xl border border-line bg-surface p-5 shadow-2xl sm:rounded-xl",onClick:C=>C.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"登录 Claude 账号"}),c.jsx("button",{type:"button",onClick:e,className:"rounded-md p-1 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-3",children:c.jsx(At,{className:"h-4 w-4"})})]}),n==="loading"&&c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(nn,{className:"h-5 w-5 fs-spin text-fg-4"})}),n==="waiting"&&c.jsxs("div",{className:"mt-4 space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsxs("p",{className:"text-xs text-fg-3",children:[c.jsx("span",{className:"font-medium text-fg",children:"第 1 步:"}),"点击下方链接,在浏览器中登录你的 Claude 账号。"]}),c.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-lg border border-blue-500/30 bg-blue-500/5 px-3 py-2.5 text-xs font-medium text-blue-400 transition-colors hover:bg-blue-500/10",children:[c.jsx(Cc,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:"打开 Claude 登录页面"})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("p",{className:"text-xs text-fg-3",children:[c.jsx("span",{className:"font-medium text-fg",children:"第 2 步:"}),"登录成功后,页面会显示一个授权码,复制粘贴到下方。"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{type:"text",value:d,onChange:C=>f(C.target.value),onKeyDown:C=>{C.key==="Enter"&&S()},placeholder:"粘贴授权码…",className:"min-w-0 flex-1 rounded-md border border-line bg-base px-3 py-2 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsx("button",{type:"button",onClick:()=>void S(),disabled:!d.trim(),className:"shrink-0 rounded-md bg-blue-600 px-4 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:"确认"})]})]}),m&&c.jsxs("div",{className:"flex items-start gap-1.5 rounded-md border border-red-400/30 bg-red-400/5 px-3 py-2",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-red-400"}),c.jsx("span",{className:"text-xs text-red-400",children:m})]})]}),n==="exchanging"&&c.jsxs("div",{className:"flex flex-col items-center gap-2 py-12",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin text-blue-500"}),c.jsx("p",{className:"text-xs text-fg-4",children:"正在验证授权码…"})]}),n==="done"&&c.jsxs("div",{className:"mt-4 space-y-4",children:[c.jsxs("div",{className:"flex flex-col items-center gap-2 py-6",children:[c.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-green-500/10",children:c.jsx(fi,{className:"h-5 w-5 text-green-500"})}),c.jsx("p",{className:"text-sm font-medium text-fg",children:E?"账号已更新":"账号添加成功"}),c.jsx("p",{className:"text-xs text-fg-4",children:b})]}),c.jsx("button",{type:"button",onClick:t,className:"w-full rounded-md bg-blue-600 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:"完成"})]}),n==="error"&&c.jsxs("div",{className:"mt-4 space-y-4",children:[c.jsxs("div",{className:"flex flex-col items-center gap-2 py-6",children:[c.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-red-500/10",children:c.jsx(On,{className:"h-5 w-5 text-red-400"})}),c.jsx("p",{className:"max-w-xs text-center text-xs text-red-400",children:m})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{type:"button",onClick:()=>{f(""),_()},className:"flex-1 rounded-md border border-line py-2 text-xs font-medium text-fg-3 transition-colors hover:bg-elevated",children:"重试"}),c.jsx("button",{type:"button",onClick:e,className:"flex-1 rounded-md bg-blue-600 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:"关闭"})]})]})]})})}function w_e(){const[e,t]=y.useState((fs==null?void 0:fs.data)??null),[n,r]=y.useState(!fs),[a,i]=y.useState(null),[o,u]=y.useState(null),[d,f]=y.useState((fs==null?void 0:fs.fetchedAt)??null),[,m]=y.useState(0),[p,b]=y.useState(!1),x=y.useCallback(S=>{const C=Date.now();fs={data:S,fetchedAt:C},t(S),f(C)},[]),E=y.useCallback(()=>{r(!0),i(null),oM().then(S=>{x(S),r(!1)}).catch(S=>{i(S instanceof Error?S.message:String(S)),r(!1)})},[x]);y.useEffect(()=>{fs||E()},[E]),y.useEffect(()=>{const S=setInterval(()=>m(C=>C+1),3e4);return()=>clearInterval(S)},[]);const N=y.useRef(!1),_=y.useCallback(S=>{N.current||(N.current=!0,u(S),lM(S).then(C=>{x(C),u(null)}).catch(C=>{i(C instanceof Error?C.message:String(C)),u(null)}).finally(()=>{N.current=!1}))},[x]);return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex items-center justify-between gap-3",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[c.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-blue-500/10 text-blue-500",children:c.jsx(Fz,{className:"h-4 w-4"})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Claude 订阅额度"}),c.jsx("p",{className:"mt-0.5 text-xs text-fg-4",children:"各账号的 Pro/Max 订阅窗口用量。"})]})]}),c.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[d&&c.jsx("span",{className:"text-[10px] tabular-nums text-fg-5",children:y_e(d)}),c.jsx("button",{type:"button",onClick:E,disabled:n,className:"rounded-md p-1.5 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:c.jsx(Rl,{className:ie("h-4 w-4",n&&"fs-spin")})})]})]}),c.jsxs("div",{className:"mt-4 space-y-2.5",children:[n&&!e?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin"}),c.jsx("p",{className:"text-xs",children:"加载中…"})]}):a&&!e?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-red-400",children:[c.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-red-500/10",children:c.jsx(On,{className:"h-5 w-5"})}),c.jsx("p",{className:"max-w-xs text-center text-xs leading-relaxed",children:a})]}):e&&e.accounts.length===0?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-elevated text-fg-4",children:c.jsx(QR,{className:"h-5 w-5"})}),c.jsx("p",{className:"max-w-xs text-center text-xs leading-relaxed",children:"暂无账号,点击下方按钮登录 Claude 账号。"})]}):e?e.accounts.map(S=>c.jsx(N_e,{account:S,onSwitch:_,switching:o===S.id},S.id)):null,c.jsxs("button",{type:"button",onClick:()=>b(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-line py-2.5 text-xs text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-3",children:[c.jsx(ua,{className:"h-3.5 w-3.5"})," 添加 Claude 账号"]})]}),p&&c.jsx(S_e,{onClose:()=>b(!1),onSuccess:()=>{b(!1),E()}})]})}function __e({host:e,onDelete:t}){return c.jsxs("div",{className:"group flex items-center gap-3 rounded-lg border border-line bg-base px-4 py-3",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-fg",children:e.name}),c.jsx("span",{className:"rounded bg-elevated px-1.5 py-0.5 font-mono text-[10px] text-fg-4",children:e.platform})]}),c.jsxs("div",{className:"mt-0.5 flex items-center gap-2 font-mono text-xs text-fg-4",children:[c.jsx("span",{children:e.host}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{className:"text-fg-5",children:e.token})]})]}),c.jsx(oh,{onConfirm:t,size:"md",triggerClassName:"text-fg-5 opacity-0 transition-opacity hover:text-red-400 group-hover:opacity-100"})]})}const T_e={github:{scope:"repo",linkFn:()=>"https://github.com/settings/tokens/new?scopes=repo"},gitlab:{scope:"api",linkFn:e=>e?`https://${e}/-/user_settings/personal_access_tokens`:null},gitea:{scope:"issue 和 pull request 读写",linkFn:e=>e?`https://${e}/user/settings/applications`:null}};function A_e({platform:e,host:t}){const n=T_e[e];if(!n)return null;const r=n.linkFn(t);return c.jsxs("p",{className:"text-[11px] leading-relaxed text-fg-5",children:["需要 ",c.jsx("span",{className:"font-medium text-fg-4",children:n.scope})," 权限。",r?c.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"ml-1 text-blue-500 hover:underline",children:"去创建 Token →"}):c.jsx("span",{className:"ml-1 text-fg-6",children:"(填写 Host 后可跳转创建页)"})]})}function C_e({onAdded:e}){const[t,n]=y.useState(!1),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(""),[f,m]=y.useState("gitea"),[p,b]=y.useState(!1),[x,E]=y.useState(!1),N=()=>{a(""),o(""),d(""),m("gitea"),n(!1)},_=async()=>{if(!(!r.trim()||!i.trim()||!u.trim())){b(!0);try{await pY(r.trim(),i.trim(),u.trim(),f),N(),e()}finally{b(!1)}}};return t?c.jsxs("div",{className:"space-y-3 rounded-lg border border-line bg-base p-4",children:[c.jsxs("div",{className:"flex gap-3",children:[c.jsxs("label",{className:"flex-1",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"名称"}),c.jsx("input",{type:"text",value:i,onChange:S=>o(S.target.value),placeholder:"公司 Gitea",className:"mt-1 w-full rounded-md border border-line bg-surface px-3 py-1.5 text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"})]}),c.jsxs("label",{className:"w-28",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"平台"}),c.jsxs("select",{value:f,onChange:S=>m(S.target.value),className:"mt-1 w-full rounded-md border border-line bg-surface px-3 py-1.5 text-sm text-fg focus:border-blue-500 focus:outline-none",children:[c.jsx("option",{value:"gitea",children:"Gitea"}),c.jsx("option",{value:"github",children:"GitHub"}),c.jsx("option",{value:"gitlab",children:"GitLab"})]})]})]}),c.jsxs("label",{className:"block",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"Host"}),c.jsx("input",{type:"text",value:r,onChange:S=>a(S.target.value),placeholder:"git.btsai.work",className:"mt-1 w-full rounded-md border border-line bg-surface px-3 py-1.5 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"})]}),c.jsxs("label",{className:"block",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"Token"}),c.jsxs("div",{className:"relative mt-1",children:[c.jsx("input",{type:x?"text":"password",value:u,onChange:S=>d(S.target.value),placeholder:"Personal Access Token",className:"w-full rounded-md border border-line bg-surface px-3 py-1.5 pr-9 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsx("button",{type:"button",onClick:()=>E(!x),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-fg-5 hover:text-fg-3",children:x?c.jsx(qR,{className:"h-3.5 w-3.5"}):c.jsx(GR,{className:"h-3.5 w-3.5"})})]})]}),c.jsx(A_e,{platform:f,host:r.trim()}),c.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[c.jsx("button",{type:"button",onClick:N,className:"rounded-md px-3 py-1.5 text-xs text-fg-4 hover:bg-elevated",children:"取消"}),c.jsx("button",{type:"button",onClick:()=>void _(),disabled:p||!r.trim()||!i.trim()||!u.trim(),className:"rounded-md bg-blue-600 px-4 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:p?"保存中…":"保存"})]})]}):c.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-line py-2.5 text-xs text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-3",children:[c.jsx(ua,{className:"h-3.5 w-3.5"})," 添加 Git 源站"]})}function k_e(){const[e,t]=y.useState(""),[n,r]=y.useState(""),[a,i]=y.useState(!0),[o,u]=y.useState(!1),[d,f]=y.useState(null);y.useEffect(()=>{oY().then(b=>{t(b.content),r(b.content),i(!1)}).catch(b=>{f(b instanceof Error?b.message:String(b)),i(!1)})},[]);const m=async()=>{u(!0),f(null);try{await lY(e),r(e)}catch(b){f(b instanceof Error?b.message:String(b))}u(!1)},p=e!==n;return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex items-center justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"全局 AGENTS.md"}),c.jsx("p",{className:"mt-1 text-xs text-fg-4",children:"此内容会注入到所有仓库的 Agent 系统指令中。修改后 opencode 热加载,即时生效。"})]}),c.jsxs("button",{type:"button",onClick:()=>void m(),disabled:o||!p,className:"flex shrink-0 items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),o?"保存中…":"保存"]})]}),d&&c.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-lg bg-red-500/10 px-3 py-2 text-xs text-red-400",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"min-w-0 break-words",children:d})]}),c.jsx("div",{className:"mt-4",children:a?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin"}),c.jsx("p",{className:"text-xs",children:"加载中…"})]}):c.jsx("textarea",{value:e,onChange:b=>t(b.target.value),spellCheck:!1,className:"h-96 w-full resize-y rounded-lg border border-line bg-base px-4 py-3 font-mono text-sm leading-relaxed text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20",placeholder:`# AGENTS.md
666
+ `).length)}}const P=I.length>_y,L=i||!P?I:`${I.slice(0,_y)}…`;return c.jsxs("div",{className:"my-1 overflow-hidden rounded-md border border-line bg-term/70",children:[c.jsxs("button",{type:"button",onClick:()=>a(B=>!B),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left font-mono text-xs transition-colors duration-150 hover:bg-surface/70",children:[c.jsx("span",{className:ie("shrink-0 leading-none",O.color),children:r?"▾":"▸"}),c.jsx("span",{className:"shrink-0 font-medium text-fg",children:x}),N&&c.jsx("span",{className:"truncate text-fg-3",children:N}),k&&(j>0||F>0)&&c.jsxs("span",{className:"flex shrink-0 items-center gap-1.5 text-[11px] leading-none",children:[j>0&&c.jsxs("span",{className:"text-emerald-400",children:["+",j]}),F>0&&c.jsxs("span",{className:"text-red-400",children:["-",F]})]}),c.jsxs("span",{className:ie("ml-auto flex shrink-0 items-center gap-1.5 leading-none",O.color),children:[c.jsx("span",{className:ie(O.spin&&"fs-spin"),children:O.glyph}),c.jsx("span",{children:O.label})]})]}),r&&c.jsx("div",{className:"border-t border-line px-3 py-2",children:c.jsxs("div",{className:ie("ml-1 border-l-2 pl-3 font-mono text-xs",O.accent),children:[_&&c.jsx("section",{className:"mb-2",children:_}),S&&c.jsxs("section",{className:"mb-2",children:[c.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-wider text-fg-5",children:"input"}),c.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-fg-2",children:S})]}),p&&c.jsx(vwe,{part:e}),A&&c.jsx("section",{children:A}),I&&c.jsxs("section",{children:[c.jsx("div",{className:"mb-1 text-[10px] uppercase tracking-wider text-fg-5",children:"output"}),c.jsx("pre",{className:"overflow-x-auto whitespace-pre-wrap break-words text-fg-2",children:L}),P&&c.jsx("button",{type:"button",onClick:()=>o(B=>!B),className:"mt-1 text-blue-400 transition-colors hover:text-blue-300",children:i?"show less":`show ${I.length-_y} more chars`})]}),!_&&!S&&!A&&!I&&c.jsx("div",{className:"text-fg-5",children:"no parameters"})]})})]})}function wwe({text:e}){const[t,n]=y.useState(!1);return c.jsxs("div",{className:"my-1",children:[c.jsxs("button",{type:"button",onClick:()=>n(r=>!r),className:"flex items-center gap-1.5 font-mono text-xs text-fg-5 transition-colors hover:text-fg-3",children:[t?c.jsx(kr,{className:"h-3 w-3 shrink-0"}):c.jsx(Oo,{className:"h-3 w-3 shrink-0"}),c.jsx(oc,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"thinking"})]}),t&&c.jsx("div",{className:"ml-1.5 mt-1 whitespace-pre-wrap border-l border-line pl-3 text-xs italic leading-relaxed text-fg-4",children:e})]})}function _we(){const[e,t]=y.useState(0);return y.useEffect(()=>{const n=Date.now(),r=setInterval(()=>{t(Math.floor((Date.now()-n)/1e3))},1e3);return()=>clearInterval(r)},[]),c.jsxs("div",{className:"my-1 flex items-center gap-1.5 font-mono text-xs text-fg-5",children:[c.jsx(oc,{className:"h-3 w-3 shrink-0 animate-pulse"}),c.jsx("span",{children:"thinking"}),e>0&&c.jsxs("span",{className:"text-fg-6",children:[e,"s"]})]})}function RB({part:e,className:t}){var n;return e.url?(n=e.mime)!=null&&n.startsWith("image/")?c.jsx(ow,{url:e.url,label:e.filename??"attachment",className:ie("object-contain",t??"max-h-80")}):c.jsxs("div",{className:"flex items-center gap-1.5 font-mono text-xs text-fg-5",children:[c.jsx(CH,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:e.filename??e.mime??"attachment"})]}):null}function Twe({part:e,isStreaming:t}){switch(Gp(e)){case"text":{const r=Jv(e);return r.trim()?c.jsx("div",{className:"markdown-body leading-relaxed",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[iwe],components:{table:owe},children:r})}):null}case"thinking":{const r=Jv(e);return r.trim()?c.jsx(wwe,{text:r}):t?c.jsx(_we,{}):null}case"tool":return Mf(e)?c.jsx(uwe,{part:e}):c.jsx(Swe,{part:e});case"file":return c.jsx(RB,{part:e});default:return null}}function Awe({message:e,isStreaming:t,queued:n}){var m,p,b,x,E,N;const r=e.role==="user",a=e.parts??[],i=a.filter(_=>Gp(_)!=="other");if(r){const _=a.map(Jv).join("").trim(),S=a.filter(I=>Gp(I)==="file"),C=(m=e.time)==null?void 0:m.created,A=C?new Date(C*1e3).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):null;return c.jsxs("div",{className:"fs-fade-in rounded-r-md border-l-2 border-emerald-500/40 bg-emerald-500/[0.04] px-3 py-2 font-mono",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[11px]",children:[c.jsx("span",{className:"font-medium text-emerald-400",children:"You"}),A&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{className:"text-fg-5",children:A})]}),n&&c.jsxs("span",{className:"inline-flex items-center gap-1 rounded border border-amber-500/30 px-1.5 py-0.5 text-xs text-amber-400",children:[c.jsx("span",{className:"leading-none",children:"○"}),c.jsx("span",{children:"queued"})]})]}),c.jsxs("div",{className:"flex items-start gap-2 text-sm",children:[c.jsx("span",{className:"shrink-0 select-none text-emerald-400",children:"❯"}),c.jsx("span",{className:"min-w-0 flex-1 whitespace-pre-wrap break-words text-fg",children:_||"…"})]}),S.length>0&&c.jsx("div",{className:"mt-2 flex flex-wrap gap-2 pl-5",children:S.map((I,O)=>c.jsx(RB,{part:I,className:"max-h-40"},I.id??O))})]})}const o=((p=e.info)==null?void 0:p.agent)??e.agent,u=((b=e.info)==null?void 0:b.modelID)??e.modelID,d=(x=e.info)==null?void 0:x.error,f=(E=e.info)==null?void 0:E.finish;return c.jsxs("div",{className:"fs-fade-in font-mono",children:[(o||u)&&c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-xs",children:[o&&c.jsx("span",{className:"text-fg-3",children:o}),o&&u&&c.jsx("span",{className:"text-fg-6",children:"·"}),u&&c.jsx("span",{className:"text-fg-5",children:u})]}),d&&c.jsxs("div",{className:"my-1 flex items-start gap-2 rounded-md border border-red-500/20 bg-red-500/10 px-3 py-2 text-xs text-red-400",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("span",{className:"font-semibold",children:d.name??"Error"}),((N=d.data)==null?void 0:N.message)&&c.jsx("p",{className:"mt-0.5 text-red-400/80",children:d.data.message}),f&&f!=="end"&&c.jsxs("p",{className:"mt-0.5 text-red-400/60",children:["finish: ",f]})]})]}),c.jsx("div",{className:"space-y-2 text-sm text-fg",children:i.length>0?i.map((_,S)=>c.jsx(Twe,{part:_,isStreaming:t},_.id??_.callID??S)):!d&&(t?c.jsx("span",{className:"text-fg-5",children:"…"}):c.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-amber-400/80",children:[c.jsx(On,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"空响应 — Agent 未产出任何内容"})]}))})]})}const Fp=$i(e=>({drafts:{},setDraft:(t,n)=>e(r=>{if(!n.trim()){const{[t]:a,...i}=r.drafts;return{drafts:i}}return{drafts:{...r.drafts,[t]:n}}}),clearDraft:t=>e(n=>{const{[t]:r,...a}=n.drafts;return{drafts:a}})}));function MB({isListening:e,disabled:t,onStart:n,onStop:r}){const a=y.useRef(!1),i=u=>{if(t)return;u.preventDefault(),a.current=!0,n();const d=()=>{document.removeEventListener("touchend",d),document.removeEventListener("touchcancel",d),a.current=!1,r()};document.addEventListener("touchend",d,{once:!0}),document.addEventListener("touchcancel",d,{once:!0})},o=()=>{if(t||a.current)return;n();const u=()=>{document.removeEventListener("mouseup",u),r()};document.addEventListener("mouseup",u,{once:!0})};return c.jsx("button",{type:"button",disabled:t,onTouchStart:i,onMouseDown:o,onContextMenu:u=>u.preventDefault(),"aria-label":"按住说话",title:"按住说话",style:{WebkitTouchCallout:"none"},className:ie("flex shrink-0 select-none touch-none items-center justify-center transition-colors duration-150 disabled:cursor-not-allowed disabled:text-fg-6/40","order-first self-stretch w-12 rounded-xl sm:order-none sm:self-auto sm:h-7 sm:w-7 sm:rounded-md",e?"bg-red-500/15 text-red-400 hover:bg-red-500/25":"text-fg-5 hover:text-fg-3"),children:c.jsx(pH,{className:ie("h-6 w-6 sm:h-4 sm:w-4",e&&"animate-pulse")})})}const Cwe=[.85,1.25,.65,1.4,.75,1.15,.95],zv=4,WI=24;function kwe(e){const t=Math.floor(e/60).toString().padStart(2,"0"),n=Math.floor(e%60).toString().padStart(2,"0");return`${t}:${n}`}function Owe({volumeLevel:e}){const t=Math.min(Math.max(e,0),1);return c.jsx("div",{className:"flex h-6 items-center gap-1","aria-hidden":"true",children:Cwe.map((n,r)=>{const a=zv+t*n*(WI-zv),i=Math.max(zv,Math.min(WI,a));return c.jsx("span",{className:"w-1 rounded-full bg-red-400 transition-[height] duration-150 ease-out",style:{height:`${i}px`}},r)})})}function DB({phase:e,transcript:t,interimTranscript:n,editText:r,onEditTextChange:a,onTextareaKeyDown:i,textareaRef:o,wrapperClassName:u}){if(e==="idle")return null;const d=t.length>0||n.length>0;return c.jsx("div",{className:u,children:c.jsxs("div",{className:"max-h-[40vh] overflow-y-auto px-4 py-4",children:[e==="recording"&&c.jsx("div",{className:"text-xl leading-relaxed",children:d?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-fg",children:t}),n&&c.jsx("span",{className:"text-fg-4",children:n})]}):c.jsx("span",{className:"italic text-fg-5",children:"正在聆听…"})}),e==="recognizing"&&c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(nn,{className:"h-5 w-5 shrink-0 text-emerald-400 fs-spin"}),c.jsx("span",{className:"font-mono text-sm text-emerald-400",children:"识别中…"}),n&&c.jsx("span",{className:"truncate text-base text-fg-4",children:n})]}),e==="done"&&c.jsx("textarea",{ref:o,value:r,onChange:f=>a(f.target.value),onKeyDown:i,rows:2,placeholder:"识别结果(可编辑)",className:"w-full resize-none bg-transparent text-xl leading-relaxed text-fg placeholder:text-fg-5 focus:outline-none"})]})})}function jB({phase:e,volumeLevel:t,elapsed:n,editText:r,error:a,onCancel:i,onConfirm:o,idleHint:u,className:d}){return e==="idle"?c.jsx("div",{className:d,children:a?c.jsx("span",{className:"font-mono text-[10px] text-red-400",children:a}):u?c.jsx("span",{className:"font-mono text-[10px] text-fg-6",children:u}):null}):e==="done"?c.jsxs("div",{className:d,children:[c.jsx("span",{className:"hidden font-mono text-[10px] text-fg-6 sm:inline",children:"⌘/Ctrl+⏎ 发送 · Esc 取消"}),c.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c.jsx("button",{type:"button",onClick:i,className:"rounded-md border border-line px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"取消"}),c.jsxs("button",{type:"button",onClick:o,disabled:r.trim().length===0,"aria-label":"发送",className:"flex items-center gap-1.5 rounded-md bg-emerald-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-fg-6/30 disabled:text-fg-5",children:[c.jsx(Rf,{className:"h-3.5 w-3.5",strokeWidth:2.5}),c.jsx("span",{children:"发送"})]})]})]}):c.jsx("div",{className:d,children:e==="recording"?c.jsxs(c.Fragment,{children:[c.jsx(Owe,{volumeLevel:t}),c.jsxs("span",{className:"inline-flex items-center gap-1.5 font-mono text-[11px] font-medium text-red-400",children:[c.jsx("span",{className:"h-1.5 w-1.5 shrink-0 animate-pulse rounded-full bg-red-400"}),"录音中"]}),c.jsx("span",{className:"font-mono text-[11px] tabular-nums text-fg-4",children:kwe(n)})]}):c.jsxs(c.Fragment,{children:[c.jsx(nn,{className:"h-4 w-4 shrink-0 text-emerald-400 fs-spin"}),c.jsx("span",{className:"font-mono text-[11px] text-emerald-400",children:"识别中…"})]})})}const Iwe=200;function Rwe(){return Me(e=>{const t=e.activeSessionId;if(!t)return!1;const n=e.messages[t]??Df;for(let r=n.length-1;r>=0;r--){const a=n[r].parts;if(a){for(const i of a)if(Gp(i)==="tool"&&Kp(i))return!0}}return!1})}function Mwe(){var le;const[e,t]=y.useState(""),[n,r]=y.useState([]),[a,i]=y.useState([]),o=y.useRef(null),u=Me(oe=>oe.activeSessionId),d=We(oe=>oe.activeRepoId),f=Me(oe=>{const ne=oe.activeSessionId;return ne?oe.sessionModels[ne]??"":""}),m=Me(oe=>{const ne=oe.activeSessionId;return ne?oe.sessionVariants[ne]??"":""}),p=Me(oe=>oe.setSessionModel),b=Me(oe=>oe.setSessionVariant),x=Me(oe=>{const ne=oe.activeSessionId;return ne?oe.sessionStatuses[ne]:void 0}),E=Me(oe=>oe.sendMessage),N=Fp(oe=>oe.setDraft),_=Fp(oe=>oe.clearDraft),S=Rwe(),C=y.useCallback(async oe=>{if(!d||!await E(d,oe,f||void 0,m||void 0))return!1},[d,E,f,m]),A=aB(C);y.useEffect(()=>{if(!d){r([]);return}let oe=!1;return(async()=>{try{const[ne,ae]=await Promise.all([Ml(),kc(d)]);if(oe)return;const De=ne.pinned_models,xe=De?JSON.parse(De):[],we=xe.length>0?ae.filter(Le=>xe.includes(Le.id)):ae;r(we.length>0?we:ae)}catch{oe||r([])}})(),()=>{oe=!0}},[d]),y.useEffect(()=>{let oe=!1;return(async()=>{try{const ne=await Ml();if(oe)return;const ae=ne.quick_inputs;if(ae)try{i(JSON.parse(ae))}catch{}else i([{label:"继续",text:"继续",autoSend:!0}])}catch{}})(),()=>{oe=!0}},[]);const I=x==="busy"&&!S,O=!u;y.useLayoutEffect(()=>{const oe=o.current;oe&&(oe.style.height="auto",oe.style.height=`${Math.min(oe.scrollHeight,Iwe)}px`)},[e]);const k=((le=n.find(oe=>oe.id===f))==null?void 0:le.supportsImage)!==!1,{attachments:j,foldedTexts:F,promptFiles:P,error:L,addFiles:B,onPaste:Y,addFoldedText:re,expandFoldedTexts:X,remove:K,removeFoldedText:V,clear:H}=oB(k);y.useEffect(()=>{t(u?Fp.getState().drafts[u]??"":""),H(),A.stt.stop()},[u,H,A.stt.stop]);const G=oe=>{if(Array.from(oe.clipboardData.files).length>0){Y(oe);return}const ae=oe.clipboardData.getData("text/plain");if(!ae||!sB(ae))return;oe.preventDefault();const De=re(ae),xe=oe.currentTarget,we=xe.selectionStart??e.length,Le=xe.selectionEnd??e.length,Ee=e.slice(0,we)+De.placeholder+e.slice(Le);t(Ee),u&&N(u,Ee),requestAnimationFrame(()=>{const st=we+De.placeholder.length;xe.setSelectionRange(st,st)})},Q=oe=>{const ne=F.find(ae=>ae._id===oe);if(ne){const ae=e.replace(ne.placeholder,"");t(ae),u&&N(u,ae)}V(oe)},D=async()=>{const oe=X(e.trim());if(O||!oe&&j.length===0)return;await E(d,oe,f||void 0,m||void 0,P.length>0?P:void 0)&&(t(""),H(),u&&_(u))},z=oe=>{oe.nativeEvent.isComposing||oe.keyCode===229||oe.key==="Enter"&&!oe.shiftKey&&(oe.preventDefault(),D())},$=u?S?"输入回复,或点击上方选项…":I?"输入消息将排队等待处理…":"enter a command…":"select or start a run",M=u?I?"text-amber-400 fs-blink":S?"text-blue-400":"text-emerald-400":"text-fg-6";return c.jsxs("div",{"data-guide":"run-input-bar",className:"relative border-t border-line bg-term px-4 py-4",children:[c.jsx(DB,{phase:A.stt.phase,transcript:A.stt.transcript,interimTranscript:A.stt.interimTranscript,editText:A.editText,onEditTextChange:A.setEditText,onTextareaKeyDown:A.handleTextareaKeyDown,textareaRef:A.textareaRef,wrapperClassName:"absolute bottom-full left-0 right-0 z-20 border-t border-line bg-surface/95 backdrop-blur-sm"}),c.jsx(uB,{attachments:j,foldedTexts:F,error:L,onRemove:K,onRemoveFoldedText:Q,className:"mx-auto max-w-4xl"}),a.length>0&&c.jsx("div",{className:"mx-auto mb-2 flex max-w-4xl gap-1.5 overflow-x-auto scrollbar-none",children:a.map((oe,ne)=>c.jsx("button",{type:"button",disabled:O,onClick:()=>{var ae;oe.autoSend?d&&E(d,oe.text,f||void 0,m||void 0):(t(oe.text),u&&N(u,oe.text),(ae=o.current)==null||ae.focus())},className:"shrink-0 rounded-full border border-line bg-surface px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:oe.label},ne))}),c.jsxs("div",{className:ie("mx-auto flex max-w-4xl items-start gap-2 rounded-lg border px-3 py-2 transition-colors duration-150",O?"border-line":"border-fg-5 focus-within:border-fg-4"),children:[c.jsx("span",{className:ie("select-none pt-px font-mono text-sm leading-6",M),children:"❯"}),c.jsx("textarea",{ref:o,rows:2,value:e,disabled:O,onChange:oe=>{const ne=oe.target.value;t(ne),u&&N(u,ne)},onKeyDown:z,onPaste:G,placeholder:$,className:"flex-1 resize-none bg-transparent font-mono text-sm leading-6 text-fg placeholder:text-fg-6 focus:outline-none disabled:cursor-not-allowed"}),c.jsx(lB,{onFiles:oe=>void B(oe),disabled:O,allowed:k}),c.jsx(MB,{isListening:A.stt.isListening,disabled:O,onStart:A.stt.start,onStop:()=>void A.stt.stop()}),c.jsx("button",{type:"button",onClick:D,disabled:O||e.trim().length===0&&j.length===0&&F.length===0,"aria-label":"Send message",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-emerald-600 text-white transition-colors duration-150 hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-fg-6/30 disabled:text-fg-5",children:c.jsx(UR,{className:"h-4 w-4",strokeWidth:2.5})})]}),A.stt.phase==="idle"?c.jsxs("div",{className:"mx-auto mt-1.5 flex max-w-4xl items-center gap-3 pl-5",children:[A.stt.error&&c.jsx("span",{className:"font-mono text-[10px] text-red-400",children:A.stt.error}),c.jsx("span",{className:"font-mono text-[10px] text-fg-6",children:"⏎ to run · shift+⏎ for newline"}),c.jsxs("div",{className:"ml-auto flex min-w-0 shrink items-center gap-1.5",children:[c.jsxs("select",{value:m,onChange:oe=>{u&&b(u,oe.target.value)},className:"w-16 min-w-0 rounded border border-line bg-surface px-1.5 py-0.5 font-mono text-[11px] text-fg-4 focus:border-fg-5 focus:outline-none",children:[c.jsx("option",{value:"",children:"默认"}),c.jsx("option",{value:"max",children:"max"}),c.jsx("option",{value:"high",children:"high"})]}),n.length>0&&c.jsxs("select",{value:f,onChange:oe=>{u&&p(u,oe.target.value)},className:"w-24 min-w-0 rounded border border-line bg-surface px-1.5 py-0.5 font-mono text-[11px] text-fg-4 focus:border-fg-5 focus:outline-none",children:[c.jsx("option",{value:"",children:"默认模型"}),n.map(oe=>c.jsx("option",{value:oe.id,children:oe.name||oe.id},oe.id))]})]})]}):c.jsx(jB,{phase:A.stt.phase,volumeLevel:A.stt.volumeLevel,elapsed:A.elapsed,editText:A.editText,error:A.stt.error,onCancel:A.cancel,onConfirm:()=>void A.confirm(),className:"mx-auto mt-1.5 flex max-w-4xl items-center gap-3 pl-5"})]})}const Dwe={completed:{glyph:"■",color:"text-emerald-400"},in_progress:{glyph:"■",color:"text-amber-400"},cancelled:{glyph:"■",color:"text-fg-6"},pending:{glyph:"□",color:"text-fg-5"}};function jwe(e){const t=e.find(r=>Dl(r.status)==="in_progress");if(t)return t.content;const n=e.find(r=>Dl(r.status)==="pending");return n?n.content:"all steps complete"}function Lwe({todos:e,onClick:t}){if(e.length===0)return null;const n=e.length,r=mM(e);return c.jsx("div",{className:"rounded-md border border-line bg-term/60 px-3 py-2",children:c.jsxs("button",{type:"button",onClick:t,className:"flex w-full items-center gap-2 text-left font-mono text-xs",children:[c.jsxs("span",{className:"shrink-0 tabular-nums text-fg-4",children:["[",r,"/",n,"]"]}),c.jsx("span",{className:"shrink-0 tracking-tight",children:e.map(a=>{const i=Dwe[Dl(a.status)];return c.jsx("span",{className:i.color,children:i.glyph},a.id)})}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-fg-2",children:jwe(e)}),c.jsx("span",{className:"shrink-0 text-[10px] text-fg-5",children:"详情 →"})]})})}const XI={idle:{glyph:"●",label:"ready",color:"text-emerald-400",spin:!1},busy:{glyph:"◌",label:"running",color:"text-amber-400",spin:!0},retry:{glyph:"◌",label:"retrying",color:"text-amber-400",spin:!0},error:{glyph:"✗",label:"error",color:"text-red-400",spin:!1}};function QI({status:e,reason:t}){const n=XI[e??"idle"]??XI.idle;return c.jsxs("span",{className:ie("flex items-center gap-1.5 rounded border border-line px-2 py-0.5 font-mono text-xs",n.color),title:e==="error"&&t?t:void 0,children:[c.jsx("span",{className:ie("leading-none",n.spin&&"fs-spin"),children:n.glyph}),c.jsx("span",{children:n.label})]})}const ZI=1e6;function Pwe(e){for(let t=e.length-1;t>=0;t--){const n=e[t];if(n.role==="assistant"&&n.tokens){const r=n.tokens;if(r.cache&&(r.cache.read>0||r.cache.write>0)||r.input>0||r.output>0)return r}}return null}function JI({session:e,messages:t,contextLimit:n}){var d,f;const r=Pwe(t),a=(e==null?void 0:e.cost)??0;if(!r&&!a)return null;const i=r?r.input+(((d=r.cache)==null?void 0:d.read)??0)+(((f=r.cache)==null?void 0:f.write)??0):0,o=i>0?Math.min(Math.round(i/n*100),999):0,u=o>=80?"text-red-400":o>=50?"text-amber-400":"text-fg-5";return c.jsxs("div",{className:"flex items-center gap-2 font-mono text-[11px] text-fg-5",children:[i>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{title:"当前上下文 = cache_read + cache_write + input (最近一次请求)",children:Nf(i)}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsxs("span",{className:u,title:`上下文占比 (${Nf(n)} 窗口)`,children:[o,"%"]}),c.jsx("span",{className:"text-fg-6",children:"·"})]}),c.jsx("span",{title:"会话累计费用",children:Aa(a)})]})}const Bwe=144,Uwe=64;function Fwe({onToggleSidebar:e}){var oe;const[t,n]=y.useState(""),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(""),f=y.useRef(null),[m,p]=y.useState([]),b=Me(ne=>ne.createSession),x=Me(ne=>ne.sendError),E=We(ne=>ne.activeRepoId),_=ia(ne=>ne.agents).filter(ne=>ne.isSystem<2),S=Je(ne=>ne.selectedIssueId),C=Je(ne=>{if(!u)return null;const ae=ne.issues.find(De=>De.id===u);return ae?`#${ae.number} ${ae.title}`:null}),[A,I]=CE();y.useEffect(()=>{_.length>0&&!r&&a(_[0].id)},[_,r]),y.useEffect(()=>{if(!E){p([]);return}let ne=!1;return kc(E).then(ae=>{ne||p(ae)}).catch(()=>{ne||p([])}),()=>{ne=!0}},[E]);const O=m.length===0||m.some(ne=>ne.supportsImage!==!1),{attachments:k,foldedTexts:j,promptFiles:F,error:P,addFiles:L,onPaste:B,addFoldedText:Y,expandFoldedTexts:re,remove:X,removeFoldedText:K,clear:V}=oB(O);y.useEffect(()=>{S&&(d(S),Je.getState().setSelectedIssue(null))},[S]),y.useEffect(()=>{const ne=A.get("draft");ne&&(n(ne),I({},{replace:!0}))},[A,I]),y.useLayoutEffect(()=>{const ne=f.current;ne&&(ne.style.height="auto",ne.style.height=`${Math.min(ne.scrollHeight,Bwe)}px`)},[t]);const H=(oe=_.find(ne=>ne.id===r))==null?void 0:oe.description,G=!!u,Q=ne=>{if(Array.from(ne.clipboardData.files).length>0){B(ne);return}const De=ne.clipboardData.getData("text/plain");if(!De||!sB(De))return;ne.preventDefault();const xe=Y(De),we=ne.currentTarget,Le=we.selectionStart??t.length,Ee=we.selectionEnd??t.length,st=t.slice(0,Le)+xe.placeholder+t.slice(Ee);n(st),requestAnimationFrame(()=>{const Ke=Le+xe.placeholder.length;we.setSelectionRange(Ke,Ke)})},D=ne=>{const ae=j.find(De=>De._id===ne);ae&&n(t.replace(ae.placeholder,"")),K(ne)},z=()=>{const ne=re(t.trim());!E||!ne&&!G&&k.length===0||(n(""),V(),b(E,ne,void 0,void 0,i||void 0,u||void 0,r||void 0,F.length>0?F:void 0))},$=ne=>{if(!(ne.nativeEvent.isComposing||ne.keyCode===229)){if(ne.key==="Tab"&&_.length>1){ne.preventDefault();const ae=_.findIndex(xe=>xe.id===r),De=ne.shiftKey?(ae-1+_.length)%_.length:(ae+1)%_.length;a(_[De].id);return}ne.key==="Enter"&&!ne.shiftKey&&(ne.preventDefault(),z())}},M=y.useCallback(ne=>{E&&b(E,ne,void 0,void 0,i||void 0,u||void 0,r||void 0)},[E,b,u,r,i]),le=aB(M);return c.jsxs("div",{className:"relative flex flex-1 flex-col items-center justify-center bg-term",children:[c.jsx("button",{type:"button",onClick:e,"aria-label":"Open sidebar",className:"absolute left-3 top-3 rounded-lg p-2 text-fg-3 hover:bg-elevated md:hidden",children:c.jsx(DE,{className:"h-5 w-5"})}),c.jsxs("div",{className:"w-full max-w-2xl px-6",children:[c.jsx("div",{className:"mb-8 text-center",children:c.jsxs("div",{className:"font-mono text-2xl text-fg-6",children:[c.jsx("span",{className:"text-emerald-500/60",children:"❯"}),c.jsx("span",{className:"fs-blink text-fg-4",children:" ▋"})]})}),c.jsx(uB,{attachments:k,foldedTexts:j,error:P,onRemove:X,onRemoveFoldedText:D}),c.jsxs("div",{"data-guide":"run-new-input",className:ie("relative rounded-xl border bg-base/80 shadow-sm transition-colors","border-line focus-within:border-fg-5"),children:[c.jsx(DB,{phase:le.stt.phase,transcript:le.stt.transcript,interimTranscript:le.stt.interimTranscript,editText:le.editText,onEditTextChange:le.setEditText,onTextareaKeyDown:le.handleTextareaKeyDown,textareaRef:le.textareaRef,wrapperClassName:"absolute bottom-full left-0 right-0 z-20 mb-2 overflow-hidden rounded-xl border border-line bg-surface/95 backdrop-blur-sm"}),_.length>0&&c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center gap-1.5 overflow-x-auto px-4 pt-3 pb-1 scrollbar-none",children:[_.map(ne=>{const ae=zE(ne.name);return c.jsxs("button",{type:"button","aria-label":`选择代理 ${ne.name}`,"aria-pressed":r===ne.id,onClick:()=>a(ne.id),className:ie("flex shrink-0 items-center gap-1.5 rounded-full px-3 py-1 text-xs font-medium transition-colors",r===ne.id?"bg-blue-500/15 text-blue-400 ring-1 ring-inset ring-blue-500/30":"text-fg-4 hover:bg-elevated hover:text-fg-3"),children:[c.jsx("span",{className:ie("inline-flex h-4 w-4 items-center justify-center rounded-full text-[10px] font-bold",ae.bg,ae.text),children:ae.initial}),ne.name]},ne.id)}),_.length>1&&c.jsx("span",{className:"hidden shrink-0 ml-auto font-mono text-[10px] text-fg-6 md:inline",children:"Tab 切换"})]}),H&&c.jsx("p",{className:"px-4 pb-1 text-[11px] leading-relaxed text-fg-5",children:H})]}),c.jsxs("div",{className:"flex items-start gap-2 px-4 py-3",children:[c.jsx("span",{className:ie("select-none pt-px font-mono text-sm leading-6","text-emerald-400"),children:"❯"}),c.jsx("textarea",{ref:f,rows:1,value:t,disabled:!E,onChange:ne=>n(ne.target.value),onKeyDown:$,onPaste:Q,placeholder:E?u?"输入补充指令,或直接发送":"让 Agent 做什么?":"请先选择一个仓库",className:"flex-1 resize-none bg-transparent font-mono text-sm leading-6 text-fg placeholder:text-fg-6 focus:outline-none disabled:cursor-not-allowed"}),c.jsx(lB,{onFiles:ne=>void L(ne),disabled:!E,allowed:!0}),c.jsx(MB,{isListening:le.stt.isListening,disabled:!E,onStart:le.stt.start,onStop:()=>void le.stt.stop()}),c.jsx("button",{type:"button",onClick:z,disabled:!E||!t.trim()&&!G&&k.length===0&&j.length===0,"aria-label":"Start run",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md bg-emerald-600 text-white transition-colors duration-150 hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-fg-6/30 disabled:text-fg-5",children:c.jsx(UR,{className:"h-4 w-4",strokeWidth:2.5})})]}),c.jsxs("div",{className:"flex items-center gap-2 border-t border-line/60 px-4 py-1.5",children:[C&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"shrink-0 font-mono text-[11px] text-fg-5",children:"关联"}),c.jsx("span",{className:"min-w-0 truncate rounded bg-blue-500/10 px-1.5 py-0.5 font-mono text-[11px] text-blue-400",children:C}),c.jsx("button",{type:"button",onClick:()=>d(""),className:"shrink-0 text-fg-5 hover:text-fg-3","aria-label":"取消关联",children:c.jsx(At,{className:"h-3 w-3"})})]}),c.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[c.jsx("span",{className:"font-mono text-[11px] text-fg-5",children:"variant"}),c.jsxs("select",{value:i,onChange:ne=>o(ne.target.value),className:"rounded border border-line bg-surface px-2 py-0.5 font-mono text-[11px] text-fg-4 focus:border-fg-5 focus:outline-none",children:[c.jsx("option",{value:"",children:"默认"}),c.jsx("option",{value:"max",children:"max"}),c.jsx("option",{value:"high",children:"high"})]})]})]})]}),c.jsx(jB,{phase:le.stt.phase,volumeLevel:le.stt.volumeLevel,elapsed:le.elapsed,editText:le.editText,error:le.stt.error,onCancel:le.cancel,onConfirm:()=>void le.confirm(),idleHint:"⌘⏎ / ctrl+⏎ 开始运行",className:"mt-2 flex items-center justify-center gap-2"}),x&&c.jsx("div",{className:"mt-3 rounded-lg border border-red-500/20 bg-red-500/10 px-4 py-2 font-mono text-xs text-red-400",children:x})]})]})}function eR({body:e}){return e?c.jsx("div",{className:"markdown-body leading-relaxed",children:c.jsx($l,{remarkPlugins:[Yl],children:e})}):c.jsx("p",{className:"py-10 text-center font-mono text-xs text-fg-5",children:"该 Issue 没有描述内容"})}function tR({issue:e}){var t;return c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",e.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",e.number," ",e.state]}),(t=e.labels)==null?void 0:t.map(n=>c.jsx("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${n.color}20`,color:`#${n.color}`},children:n.name},n.id))]}),c.jsx("h2",{className:"mt-0.5 truncate text-sm font-medium text-fg",children:e.title})]})}function zwe({onToggleSidebar:e}){const t=Je(p=>p.matchingParentId),n=Je(p=>p.matchingCandidateId),r=Je(p=>p.issues.find(b=>b.id===t)),a=Je(p=>p.issues.find(b=>b.id===n)),i=Je(p=>p.exitMatchMode),o=Je(p=>p.linkChild),u=We(p=>p.activeRepoId),[d,f]=y.useState(!1);if(!r)return null;const m=async()=>{!a||!u||(f(!0),await o(u,r.number,a.number),f(!1))};return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden bg-term",children:[c.jsxs("header",{className:"flex items-center gap-3 border-b border-line bg-base px-4 py-2.5",children:[c.jsx("button",{type:"button",onClick:e,"aria-label":"Open sidebar",className:"-ml-1 rounded-lg p-1.5 text-fg-3 hover:bg-elevated md:hidden",children:c.jsx(DE,{className:"h-5 w-5"})}),c.jsx("span",{className:"text-xs font-medium text-fg-4",children:"匹配子任务"}),c.jsxs("span",{className:"font-mono text-xs text-fg-3",children:["父: #",r.number]}),c.jsx("div",{className:"flex-1"}),c.jsxs("button",{type:"button","aria-label":"退出匹配模式",onClick:i,className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 text-xs text-fg-3 transition-colors hover:border-fg-5 hover:text-fg",children:[c.jsx(At,{className:"h-3.5 w-3.5"}),"退出匹配"]})]}),c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col md:flex-row",children:[c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden border-b border-line md:border-b-0 md:border-r",children:[c.jsx("div",{className:"border-b border-line/60 px-4 py-2.5",children:c.jsx(tR,{issue:r})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-6",children:c.jsx(eR,{body:r.body})})]}),c.jsx("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:a?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"border-b border-line/60 px-4 py-2.5",children:c.jsx(tR,{issue:a})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-6",children:c.jsx(eR,{body:a.body})})]}):c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"← 从左侧列表选择候选 Issue"})})})]}),a&&c.jsx("div",{className:"flex items-center justify-center gap-3 border-t border-line bg-base px-4 py-3",children:c.jsxs("button",{type:"button","aria-label":d?"关联中":`确认将 #${a.number} 设为 #${r.number} 的子任务`,onClick:()=>void m(),disabled:d,className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-4 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-50",children:[c.jsx(fi,{className:"h-3.5 w-3.5"}),d?"关联中…":`确认: 将 #${a.number} 设为 #${r.number} 的子任务`]})})]})}function Hwe({onToggleSidebar:e,onToggleRightPanel:t,rightPanelOpen:n}){var D,z;const r=zn(),a=We(qr),i=Me($=>$.activeSessionId),o=Me($=>$.sessions.find(M=>M.id===$.activeSessionId)??null),u=Me($=>{const M=$.activeSessionId;return M?$.messages[M]??Df:Df}),d=Me($=>{const M=$.activeSessionId;return M?$.todos[M]??jf:jf}),f=Me($=>{const M=$.activeSessionId;return M?$.sessionStatuses[M]:void 0}),m=Me($=>{const M=$.activeSessionId;return M?$.queuedMessageIds[M]??IA:IA}),p=Me($=>{const M=$.activeSessionId;return M?$.errorReasons[M]:void 0}),b=Me($=>{const M=$.activeSessionId;return M?$.messagesMeta[M]:void 0}),x=Me($=>$.loadMoreMessages),E=Me($=>$.sendError),N=Me($=>$.abortSession),_=Me($=>$.revertToMessage),S=We($=>$.activeRepoId),C=We($=>$.repos.find(M=>M.id===$.activeRepoId)),A=(C==null?void 0:C.runtimeType)!=="claude-code",[I,O]=y.useState(null),[k,j]=y.useState(!1),F=Je($=>o!=null&&o.issueId?$.issues.find(M=>M.id===o.issueId):void 0),[P,L]=y.useState([]);y.useEffect(()=>{if(!S){L([]);return}let $=!1;return kc(S).then(M=>{$||L(M)}).catch(()=>{$||L([])}),()=>{$=!0}},[S]);const B=(()=>{var le;const $=(le=o==null?void 0:o.model)==null?void 0:le.modelID;if(!$)return ZI;const M=P.find(oe=>oe.id.endsWith(`/${$}`));return(M==null?void 0:M.contextLimit)??ZI})();y.useEffect(()=>{if(i)return Vp.activateSession(i),()=>Vp.deactivateSession(i)},[i]);const Y=y.useRef(null),re=y.useRef(!0),[X,K]=y.useState(!1);y.useEffect(()=>{re.current=!0,K(!1)},[i]),y.useEffect(()=>{const $=Y.current;$&&re.current&&($.scrollTop=$.scrollHeight)},[u]),y.useEffect(()=>{if(f!=="busy"&&f!=="retry")return;const $=M=>{if(M.key!=="Escape"||M.defaultPrevented)return;const le=M.target;le instanceof HTMLInputElement||le instanceof HTMLTextAreaElement||le!=null&&le.isContentEditable||S&&N(S)};return window.addEventListener("keydown",$),()=>window.removeEventListener("keydown",$)},[f,N,S]);const V=Je($=>$.matchingParentId);if(!i)return V?c.jsx(zwe,{onToggleSidebar:e}):c.jsx(Fwe,{onToggleSidebar:e});const H=f==="busy",G=f==="retry",Q=H||G;return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden bg-term",children:[c.jsxs("header",{className:"border-b border-line bg-base md:hidden",children:[c.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",onClick:()=>j($=>!$),children:[c.jsxs("div",{className:"flex items-center gap-1",onClick:$=>$.stopPropagation(),children:[c.jsx("button",{type:"button",onClick:e,"aria-label":"Open sidebar",className:"-ml-1 rounded-lg p-1.5 text-fg-3 hover:bg-elevated",children:c.jsx(DE,{className:"h-5 w-5"})}),c.jsx("button",{type:"button",onClick:()=>Me.setState({activeSessionId:null}),"aria-label":"新建运行",title:"新建运行",className:"rounded-lg p-1.5 text-fg-3 hover:bg-elevated",children:c.jsx(ua,{className:"h-5 w-5"})})]}),c.jsxs("div",{className:"min-w-0 flex-1",children:[(o==null?void 0:o.parentID)&&c.jsxs("button",{type:"button","aria-label":"返回父会话",onClick:$=>{$.stopPropagation(),S&&Me.getState().setActiveSession(S,o.parentID)},className:"mb-0.5 flex items-center gap-1 text-[11px] text-fg-4 transition-colors hover:text-blue-400",children:[c.jsx(If,{className:"h-3 w-3"}),"返回父会话"]}),c.jsx("h2",{className:"text-sm font-medium leading-snug text-fg",children:((D=o==null?void 0:o.title)==null?void 0:D.trim())||"untitled run"})]}),Q&&c.jsx("span",{className:ie("h-2 w-2 shrink-0 rounded-full","bg-amber-400 animate-pulse")}),!Q&&f==="error"&&c.jsx("span",{className:"h-2 w-2 shrink-0 rounded-full bg-red-400"}),c.jsx(kr,{className:ie("h-4 w-4 shrink-0 text-fg-5 transition-transform duration-200",k&&"rotate-180")})]}),c.jsx("div",{className:ie("grid transition-[grid-template-rows] duration-200 ease-in-out",k?"grid-rows-[1fr]":"grid-rows-[0fr]"),children:c.jsx("div",{className:"overflow-hidden",children:c.jsxs("div",{className:"flex flex-col gap-2.5 border-t border-line/60 px-4 py-3",children:[(o==null?void 0:o.agent)&&c.jsxs("div",{className:"flex items-center gap-2 font-mono text-xs text-fg-4",children:[c.jsx("span",{className:"w-14 shrink-0 text-fg-5",children:"Agent"}),c.jsx("span",{className:"truncate",children:o.agent})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"w-14 shrink-0 font-mono text-xs text-fg-5",children:"Status"}),c.jsx(QI,{status:f,reason:p})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"w-14 shrink-0 font-mono text-xs text-fg-5",children:"Context"}),c.jsx(JI,{session:o,messages:u,contextLimit:B})]}),F&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"w-14 shrink-0 font-mono text-xs text-fg-5",children:"Issue"}),c.jsxs("button",{type:"button","aria-label":`查看 Issue #${F.number}: ${F.title}`,onClick:()=>r(`/${encodeURIComponent(a)}/dev/issues?id=${F.id}`),className:"flex items-center gap-1.5 truncate font-mono text-xs text-fg-3 transition-colors hover:text-blue-400",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1 py-0.5 text-[10px] font-semibold",F.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",F.number]}),c.jsx("span",{className:"truncate",children:F.title})]})]}),Q&&c.jsxs("button",{type:"button","aria-label":G?"停止重试":"停止运行",onClick:()=>S&&void N(S),className:"mt-0.5 flex w-full items-center justify-center gap-1.5 rounded-md border border-line px-2.5 py-1.5 font-mono text-xs text-fg-2 transition-colors hover:border-red-500/50 hover:text-red-400",children:[c.jsx(Vv,{className:"h-3 w-3 fill-current"}),G?"stop retry":"stop"]})]})})})]}),c.jsxs("header",{className:"hidden items-center gap-3 border-b border-line bg-base px-4 py-2.5 md:flex",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[(o==null?void 0:o.parentID)&&c.jsxs("button",{type:"button","aria-label":"返回父会话",onClick:()=>S&&void Me.getState().setActiveSession(S,o.parentID),className:"mb-0.5 flex items-center gap-1 text-[11px] text-fg-4 transition-colors hover:text-blue-400",children:[c.jsx(If,{className:"h-3 w-3"}),"返回父会话"]}),c.jsx("h2",{className:"truncate text-sm font-medium text-fg",children:((z=o==null?void 0:o.title)==null?void 0:z.trim())||"untitled run"}),(o==null?void 0:o.agent)&&c.jsx("p",{className:"truncate font-mono text-xs text-fg-4",children:o.agent}),c.jsx(JI,{session:o,messages:u,contextLimit:B})]}),F&&c.jsxs("button",{type:"button","aria-label":`查看 Issue #${F.number}: ${F.title}`,onClick:()=>r(`/${encodeURIComponent(a)}/dev/issues?id=${F.id}`),className:"flex items-center gap-1 rounded-md border border-line px-2 py-1 font-mono text-xs text-fg-3 transition-colors hover:border-fg-5 hover:text-fg",children:[c.jsxs("span",{className:ie("rounded px-1 py-0.5 text-[10px] font-semibold",F.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",F.number]}),c.jsx("span",{className:"hidden max-w-[120px] truncate sm:inline",children:F.title})]}),c.jsx(QI,{status:f,reason:p}),t&&c.jsx("button",{type:"button",onClick:t,"aria-label":n?"关闭侧边栏":"打开侧边栏",className:ie("flex items-center justify-center rounded-md border border-line p-1.5 transition-colors",n?"bg-blue-500/10 text-blue-500 hover:bg-blue-500/20":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:c.jsx(VR,{className:"h-4 w-4"})}),Q&&c.jsxs("button",{type:"button","aria-label":G?"停止重试":"停止运行",onClick:()=>S&&void N(S),className:"flex items-center gap-1.5 rounded-md border border-line px-2.5 py-1 font-mono text-xs text-fg-2 transition-colors hover:border-red-500/50 hover:text-red-400",children:[c.jsx(Vv,{className:"h-3 w-3 fill-current"}),G?"stop retry":"stop"]})]}),c.jsxs("div",{className:"relative min-h-0 flex-1",children:[c.jsx("div",{ref:Y,onScroll:()=>{const $=Y.current;if(!$)return;const M=$.scrollHeight-$.clientHeight-$.scrollTop<=Uwe;if(re.current=M,K(!M),$.scrollTop<200&&i&&(b!=null&&b.hasMore)&&!b.loading){const le=$.scrollHeight;x(S,i).then(()=>{requestAnimationFrame(()=>{Y.current&&(Y.current.scrollTop=Y.current.scrollHeight-le)})})}},className:"h-full overflow-y-auto",children:c.jsxs("div",{className:"mx-auto flex max-w-4xl flex-col gap-3 px-4 py-4",children:[(b==null?void 0:b.loading)&&c.jsx("div",{className:"flex justify-center py-2",children:c.jsx("span",{className:"inline-block h-4 w-4 animate-spin rounded-full border-2 border-fg-5 border-t-transparent"})}),b&&!b.loading&&b.hasMore&&c.jsx("button",{type:"button","aria-label":"加载更早的消息",onClick:()=>i&&S&&x(S,i),className:"mx-auto rounded-md border border-line px-3 py-1 font-mono text-xs text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2",children:"加载更早的消息"}),u.length===0?c.jsxs("p",{className:"py-10 text-center font-mono text-xs text-fg-6",children:[c.jsx("span",{className:"text-emerald-500/60",children:"❯"})," waiting for input",c.jsx("span",{className:"fs-blink",children:" ▋"})]}):u.map(($,M)=>c.jsxs(y.Fragment,{children:[M>0&&$.role==="user"&&c.jsx("div",{className:"group/revert relative border-t border-line py-2",children:A&&!Q&&c.jsxs("button",{type:"button","aria-label":"回退到此处",disabled:I!==null,onClick:async()=>{const le=u.length-M;window.confirm(`回退到此处?将移除后续 ${le} 条对话记录(不影响已产生的代码改动)。`)&&(O($.id),await _(S,i,$.id),O(null))},className:"absolute left-1/2 top-1/2 z-10 flex -translate-x-1/2 -translate-y-1/2 items-center gap-1 rounded-full border border-line bg-base px-2.5 py-1 font-mono text-[11px] text-fg-4 opacity-60 shadow-sm transition-all duration-150 hover:border-amber-500/50 hover:text-amber-400 md:opacity-30 md:group-hover/revert:opacity-100 disabled:opacity-50",children:[I===$.id?c.jsx("span",{className:"inline-block h-3 w-3 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsx(LH,{className:"h-3 w-3"}),"回退到此处"]})}),c.jsx("div",{"data-message-id":$.id,children:c.jsx(Awe,{message:$,isStreaming:H&&M===u.length-1,queued:m.includes($.id)})})]},$.id)),d.length>0&&c.jsx(Lwe,{todos:[...d],onClick:t})]})}),c.jsx("button",{type:"button",onClick:()=>{const $=Y.current;$&&($.scrollTo({top:$.scrollHeight,behavior:"smooth"}),re.current=!0)},"aria-label":"滚动到底部",className:ie("absolute bottom-4 right-4 z-10 flex h-9 w-9 items-center justify-center rounded-full border border-line bg-surface/90 text-fg-4 shadow-lg backdrop-blur transition-all duration-200","hover:bg-elevated hover:text-fg-2",X?"translate-y-0 opacity-100":"pointer-events-none translate-y-2 opacity-0"),children:c.jsx(kr,{className:"h-4 w-4"})})]}),f==="error"&&p&&c.jsxs("div",{className:"flex items-center gap-2 border-t border-red-500/20 bg-red-500/10 px-4 py-2 font-mono text-xs text-red-400",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:p})]}),E&&c.jsxs("div",{className:"flex items-center gap-2 border-t border-red-500/20 bg-red-500/10 px-4 py-2 font-mono text-xs text-red-400",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:E})]}),c.jsx(Mwe,{})]})}const $we={completed:{glyph:"✓",color:"text-emerald-400",spin:!1},in_progress:{glyph:"◌",color:"text-amber-400",spin:!0},cancelled:{glyph:"✗",color:"text-fg-5",spin:!1},pending:{glyph:"○",color:"text-fg-4",spin:!1}};function Ywe(e){var a;const t=(a=e.time)==null?void 0:a.created;if(!t)return"";const n=t<1e12?t*1e3:t;return new Date(n).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}function qwe(e){if(!e.parts)return"";for(const t of e.parts){const n=t.content??t.text;if(n)return n}return""}function Gwe({todos:e}){if(e.length===0)return c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"暂无待办项"})});const t=e.filter(n=>{const r=Dl(n.status);return r==="completed"||r==="cancelled"}).length;return c.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:[c.jsxs("div",{className:"mb-2 font-mono text-[10px] tabular-nums text-fg-5",children:["进度 ",t,"/",e.length]}),c.jsx("ul",{className:"space-y-1.5",children:e.map(n=>{const r=Dl(n.status),a=$we[r],i=r==="completed"||r==="cancelled";return c.jsxs("li",{className:"flex items-start gap-2 font-mono text-xs",children:[c.jsx("span",{className:ie("shrink-0 leading-5",a.color,a.spin&&"fs-spin"),children:a.glyph}),c.jsx("span",{className:ie("leading-5",i?"text-fg-5 line-through":"text-fg-2"),children:n.content})]},n.id)})})]})}function Kwe({messages:e,onScrollToMessage:t}){const n=e.filter(r=>r.role==="user");return n.length===0?c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"暂无输入记录"})}):c.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-2",children:c.jsx("ul",{className:"space-y-1",children:n.map((r,a)=>{const i=qwe(r),o=Ywe(r);return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:()=>t==null?void 0:t(r.id),className:"group w-full rounded-md px-2 py-1.5 text-left transition-colors hover:bg-elevated/60",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"shrink-0 font-mono text-[10px] text-emerald-400/60",children:"❯"}),c.jsxs("span",{className:"shrink-0 font-mono text-[10px] tabular-nums text-fg-5",children:["#",a+1]}),o&&c.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] text-fg-6",children:o})]}),i&&c.jsx("p",{className:"mt-0.5 line-clamp-2 pl-5 text-xs leading-relaxed text-fg-3 group-hover:text-fg-2",children:i})]})},r.id)})})})}function Vwe({linked:e,number:t,title:n,state:r,mergedAt:a,isPr:i,onToggle:o}){const u=i?r==="open"?"bg-emerald-500/15 text-emerald-400":a?"bg-purple-500/15 text-purple-400":"bg-red-500/15 text-red-400":r==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400";return c.jsx("li",{children:c.jsx("button",{type:"button",onClick:o,className:ie("flex w-full items-start gap-2 rounded-md px-2 py-2 text-left transition-colors",e?"border-l-2 border-emerald-500 bg-emerald-500/5":"border-l-2 border-transparent hover:bg-elevated/50"),children:c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-semibold",u),children:["#",t]}),c.jsx("span",{className:"min-w-0 truncate text-xs text-fg-2",children:n}),e&&c.jsx(ME,{className:"ml-auto h-3 w-3 shrink-0 text-emerald-400"})]})})})}function Wwe({links:e,sessionId:t}){var j,F,P,L;const n=zn(),r=We(qr),[a,i]=y.useState(null),[o,u]=y.useState(""),d=y.useRef(null),f=Je(B=>B.issues),m=mn(B=>B.pulls),p=Me(B=>B.addLink),b=Me(B=>B.removeLink),x=new Set(((j=e==null?void 0:e.issues)==null?void 0:j.map(B=>B.id))??[]),E=new Set(((F=e==null?void 0:e.pullRequests)==null?void 0:F.map(B=>B.id))??[]);y.useEffect(()=>{var B;a&&((B=d.current)==null||B.focus())},[a]);const N=()=>{i(null),u("")},_=We(B=>B.activeRepoId),S=async(B,Y,re)=>{!t||!_||(re?await b(_,t,B,Y):await p(_,t,B,Y))},C=o.trim().toLowerCase(),A=C?f.filter(B=>`#${B.number} ${B.title}`.toLowerCase().includes(C)):f,I=C?m.filter(B=>`#${B.number} ${B.title} ${B.headBranch}`.toLowerCase().includes(C)):m,O=((P=e==null?void 0:e.issues)==null?void 0:P.length)??0,k=((L=e==null?void 0:e.pullRequests)==null?void 0:L.length)??0;if(a){const B=a==="issue",Y=B?A:I,re=B?x:E;return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-2",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-blue-400",children:B?"关联 Issue":"关联 PR"}),c.jsxs("button",{type:"button",onClick:N,className:"flex h-6 items-center gap-1 rounded-md px-2 text-xs text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:[c.jsx(At,{className:"h-3.5 w-3.5"}),"完成"]})]}),c.jsx("div",{className:"border-b border-line px-3 py-2",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2 py-1",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{ref:d,type:"text",value:o,onChange:X=>u(X.target.value),placeholder:B?"搜索 issue...":"搜索 PR...",className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),o&&c.jsx("button",{type:"button",onClick:()=>u(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:Y.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:(B?f:m).length===0?B?"暂无 Issue,请先同步":"暂无 PR,请先同步":"无匹配结果"}):c.jsx("ul",{className:"space-y-0.5",children:Y.map(X=>c.jsx(Vwe,{linked:re.has(X.id),number:X.number,title:X.title,state:X.state,mergedAt:B?void 0:X.mergedAt,isPr:!B,onToggle:()=>S(a,X.id,re.has(X.id))},X.id))})})]})}return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-line px-3 py-2",children:[c.jsx("span",{className:"flex-1 font-mono text-[10px] text-fg-5",children:O+k>0?`${O+k} 项关联`:"暂无关联"}),c.jsxs("button",{type:"button",onClick:()=>i("issue"),className:"flex h-6 items-center gap-1 rounded-md border border-line px-1.5 text-fg-4 transition-colors hover:border-emerald-500/50 hover:text-emerald-400",children:[c.jsx(ua,{className:"h-3 w-3"}),c.jsx("span",{className:"text-[10px] font-medium",children:"Issue"})]}),c.jsxs("button",{type:"button",onClick:()=>i("pr"),className:"flex h-6 items-center gap-1 rounded-md border border-line px-1.5 text-fg-4 transition-colors hover:border-blue-500/50 hover:text-blue-400",children:[c.jsx(ua,{className:"h-3 w-3"}),c.jsx("span",{className:"text-[10px] font-medium",children:"PR"})]})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-3",children:[O>0&&c.jsxs("div",{className:"mb-3",children:[c.jsxs("div",{className:"mb-1.5 font-mono text-[10px] font-medium uppercase tracking-wider text-fg-5",children:["Issues (",O,")"]}),c.jsx("ul",{className:"space-y-1",children:e==null?void 0:e.issues.map(B=>c.jsxs("li",{className:"group flex items-start gap-1",children:[c.jsxs("button",{type:"button",onClick:()=>n(`/${encodeURIComponent(r)}/dev/issues?id=${encodeURIComponent(B.id)}`),className:"flex min-w-0 flex-1 items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-elevated/60",children:[c.jsxs("span",{className:ie("mt-0.5 shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-semibold",B.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",B.number]}),c.jsx("span",{className:"line-clamp-2 text-xs leading-5 text-fg-3 group-hover:text-fg-2",children:B.title})]}),c.jsx("button",{type:"button",onClick:()=>void S("issue",B.id,!0),className:"mt-1.5 hidden shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:bg-red-500/15 hover:text-red-400 group-hover:block",children:c.jsx(At,{className:"h-3 w-3"})})]},B.id))})]}),k>0&&c.jsxs("div",{children:[c.jsxs("div",{className:"mb-1.5 font-mono text-[10px] font-medium uppercase tracking-wider text-fg-5",children:["Pull Requests (",k,")"]}),c.jsx("ul",{className:"space-y-1",children:e==null?void 0:e.pullRequests.map(B=>c.jsxs("li",{className:"group flex items-start gap-1",children:[c.jsxs("button",{type:"button",onClick:()=>n(`/${encodeURIComponent(r)}/dev/pulls?id=${encodeURIComponent(B.id)}`),className:"flex min-w-0 flex-1 items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors hover:bg-elevated/60",children:[c.jsxs("span",{className:ie("mt-0.5 shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-semibold",B.state==="open"?"bg-emerald-500/15 text-emerald-400":B.mergedAt?"bg-purple-500/15 text-purple-400":"bg-red-500/15 text-red-400"),children:["#",B.number]}),c.jsx("span",{className:"line-clamp-2 text-xs leading-5 text-fg-3 group-hover:text-fg-2",children:B.title})]}),c.jsx("button",{type:"button",onClick:()=>void S("pr",B.id,!0),className:"mt-1.5 hidden shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:bg-red-500/15 hover:text-red-400 group-hover:block",children:c.jsx(At,{className:"h-3 w-3"})})]},B.id))})]}),O===0&&k===0&&c.jsx("div",{className:"flex flex-1 items-center justify-center py-10",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"点击上方按钮添加关联"})})]})]})}const Xwe={"visual-engineering":"bg-purple-500/15 text-purple-400",quick:"bg-emerald-500/15 text-emerald-400",deep:"bg-blue-500/15 text-blue-400",ultrabrain:"bg-amber-500/15 text-amber-400",artistry:"bg-pink-500/15 text-pink-400",writing:"bg-cyan-500/15 text-cyan-400",explore:"bg-teal-500/15 text-teal-400",librarian:"bg-indigo-500/15 text-indigo-400",oracle:"bg-amber-500/15 text-amber-400",metis:"bg-rose-500/15 text-rose-400",momus:"bg-orange-500/15 text-orange-400"};function Qwe(e){switch(e){case"idle":return"bg-emerald-500";case"busy":case"retry":return"bg-amber-500 animate-pulse";case"error":return"bg-red-500";default:return"bg-fg-5"}}function Hv(e){var n;const t=(n=e.time)==null?void 0:n.created;if(t)return t<1e12?t*1e3:t;if(e.createdAt){const r=Date.parse(e.createdAt);if(!Number.isNaN(r))return r}return null}function Zwe(e){const t=Date.now()-e,n=Math.floor(t/1e3);if(n<60)return"just now";const r=Math.floor(n/60);if(r<60)return`${r}m ago`;const a=Math.floor(r/60);return a<24?`${a}h ago`:`${Math.floor(a/24)}d ago`}function Jwe(){const e=Me(f=>f.sessions),t=Me(f=>f.activeSessionId),n=Me(f=>f.sessionStatuses),r=Me(f=>f.setActiveSession),a=We(f=>f.activeRepoId),i=e.find(f=>f.id===t),o=(i==null?void 0:i.parentID)??t,u=!!(i!=null&&i.parentID),d=e.filter(f=>f.parentID===o).sort((f,m)=>(Hv(m)??0)-(Hv(f)??0));return d.length===0?c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"暂无子任务"})}):c.jsxs("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:[u&&c.jsxs("div",{className:"mb-1.5 px-2 font-mono text-[10px] text-fg-5",children:["同级子任务 (",d.length,")"]}),c.jsx("ul",{className:"space-y-0.5",children:d.map(f=>{const m=f.id===t,p=n[f.id],b=Hv(f),x=(f.agent&&Xwe[f.agent])??"bg-elevated text-fg-4",E=f.title||`${f.id.slice(0,9)}...`;return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:()=>{!m&&a&&r(a,f.id)},className:ie("group flex w-full items-start gap-2 rounded-md px-2 py-1.5 text-left transition-colors",m?"border-l-2 border-blue-500 bg-blue-500/5":"border-l-2 border-transparent hover:bg-elevated/60"),children:[c.jsx("span",{className:ie("mt-1 h-2 w-2 shrink-0 rounded-full",Qwe(p))}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[f.agent&&c.jsx("span",{className:ie("shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-medium",x),children:f.agent}),b!=null&&c.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] tabular-nums text-fg-6",children:Zwe(b)})]}),c.jsx("p",{className:ie("mt-0.5 line-clamp-2 text-xs leading-5",m?"text-fg-2":"text-fg-3 group-hover:text-fg-2"),children:E})]})]})},f.id)})})]})}const e_e=new Set([".png",".jpg",".jpeg",".gif",".webp",".svg"]),t_e=new Set([".html",".htm",".md",".txt",".log"]),$v=80,n_e=160,nR=.4;function r_e(e){const t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e}function a_e({file:e,repoId:t,sessionId:n,onPreviewFile:r}){const a=r_e(e.path),i=vY(t,n,e.path),o=e.ext.toLowerCase();return e_e.has(o)?c.jsxs("li",{className:"flex items-center gap-2 rounded-md px-2 py-1 hover:bg-elevated/60",title:e.path,children:[c.jsx(tH,{className:"h-3 w-3 shrink-0 text-fg-5","aria-hidden":!0}),c.jsx(ow,{url:i,label:a,className:"h-8 w-8 shrink-0 object-cover"}),c.jsx("span",{className:"min-w-0 truncate text-xs text-fg-3",children:a})]}):t_e.has(o)?c.jsx("li",{children:c.jsxs("button",{type:"button",title:e.path,onClick:()=>r==null?void 0:r({url:i,name:a,ext:o}),className:"flex w-full items-center gap-2 rounded-md px-2 py-1 text-left transition-colors hover:bg-elevated/60",children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:"min-w-0 truncate text-xs text-fg-3",children:a})]})}):c.jsxs("li",{className:"flex items-center gap-2 rounded-md px-2 py-1",title:e.path,children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:"min-w-0 truncate text-xs text-fg-3",children:a})]})}function i_e({repoId:e,sessionId:t,containerRef:n,onPreviewFile:r}){const[a,i]=y.useState(!1),[o,u]=y.useState(n_e),[d,f]=y.useState([]),[m,p]=y.useState(0),b=y.useRef(null),x=y.useRef(null);y.useEffect(()=>{let A=!1;const I=()=>{yY(e,t).then(k=>{A||f(k)}).catch(()=>{A||f([])})};I();const O=setInterval(I,1e4);return()=>{A=!0,clearInterval(O)}},[e,t]),y.useEffect(()=>{const A=n.current;if(!A)return;const I=()=>p(A.clientHeight);I();const O=new ResizeObserver(I);return O.observe(A),()=>O.disconnect()},[n]);const E=m>0?m*nR:o,N=Math.max($v,E),_=Math.min(o,N),S=y.useCallback(A=>{A.preventDefault();const I=n.current,O=Math.max($v,I?I.clientHeight*nR:N);x.current={startY:A.clientY,startHeight:_,maxHeight:O};const k=F=>{const P=x.current;if(!P)return;const L=P.startY-F.clientY,B=Math.max($v,Math.min(P.startHeight+L,P.maxHeight));b.current&&(b.current.style.height=`${B}px`)},j=()=>{const F=b.current;if(F){const P=parseInt(F.style.height,10);Number.isNaN(P)||u(P)}x.current=null,window.removeEventListener("mousemove",k),window.removeEventListener("mouseup",j)};window.addEventListener("mousemove",k),window.addEventListener("mouseup",j)},[n,_,N]),C=d.length;return a?c.jsxs("div",{ref:b,className:"flex shrink-0 flex-col border-t border-line bg-surface",style:{height:`${_}px`},children:[c.jsx("div",{onMouseDown:S,role:"separator","aria-orientation":"horizontal",className:"flex h-1 shrink-0 cursor-row-resize items-center justify-center bg-line transition-colors hover:bg-blue-500/60",children:c.jsx(Kz,{className:"h-2 w-8 text-fg-6","aria-hidden":!0})}),c.jsxs("button",{type:"button",onClick:()=>i(!1),className:"flex shrink-0 items-center gap-1.5 border-b border-line px-3 py-2 text-left transition-colors hover:bg-elevated/60",children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"变更文件"}),c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:C}),c.jsx(kr,{className:"ml-auto h-3.5 w-3.5 text-fg-5"})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto px-1 py-1",children:C===0?c.jsx("p",{className:"px-2 py-4 text-center font-mono text-xs text-fg-5",children:"暂无变更文件"}):c.jsx("ul",{className:"space-y-0.5",children:d.map(A=>c.jsx(a_e,{file:A,repoId:e,sessionId:t,onPreviewFile:r},A.path))})})]}):c.jsxs("button",{type:"button",onClick:()=>i(!0),className:"flex w-full shrink-0 items-center gap-1.5 border-t border-line px-3 py-2 text-left transition-colors hover:bg-elevated/60",children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"变更文件"}),c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:C}),c.jsx(OE,{className:"ml-auto h-3.5 w-3.5 text-fg-5"})]})}function rR({todos:e,messages:t,sessionLinks:n,sessionId:r,onScrollToMessage:a,onPreviewFile:i}){var S,C;const[o,u]=y.useState("todo"),d=y.useRef(null),f=We(A=>A.activeRepoId),m=Me(A=>A.sessions),p=Me(A=>A.activeSessionId),b=t.filter(A=>A.role==="user").length,x=(((S=n==null?void 0:n.issues)==null?void 0:S.length)??0)+(((C=n==null?void 0:n.pullRequests)==null?void 0:C.length)??0),E=m.find(A=>A.id===p),N=(E==null?void 0:E.parentID)??p,_=m.filter(A=>A.parentID===N).length;return c.jsxs("div",{ref:d,className:"flex h-full w-72 shrink-0 flex-col border-l border-line bg-surface",children:[c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[c.jsxs("div",{"data-guide":"run-side-tabs",className:"flex items-center border-b border-line",children:[c.jsxs("button",{type:"button",onClick:()=>u("todo"),className:ie("flex flex-1 items-center justify-center gap-1 border-b-2 px-2 py-2.5 text-xs font-medium transition-colors",o==="todo"?"border-blue-500 text-blue-500":"border-transparent text-fg-4 hover:text-fg-2"),children:["待办",e.length>0&&c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:e.length})]}),c.jsxs("button",{type:"button",onClick:()=>u("prompts"),className:ie("flex flex-1 items-center justify-center gap-1 border-b-2 px-2 py-2.5 text-xs font-medium transition-colors",o==="prompts"?"border-blue-500 text-blue-500":"border-transparent text-fg-4 hover:text-fg-2"),children:["输入",b>0&&c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:b})]}),c.jsxs("button",{type:"button",onClick:()=>u("links"),className:ie("flex flex-1 items-center justify-center gap-1 border-b-2 px-2 py-2.5 text-xs font-medium transition-colors",o==="links"?"border-blue-500 text-blue-500":"border-transparent text-fg-4 hover:text-fg-2"),children:["关联",x>0&&c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:x})]}),c.jsxs("button",{type:"button",onClick:()=>u("subtasks"),className:ie("flex flex-1 items-center justify-center gap-1 border-b-2 px-2 py-2.5 text-xs font-medium transition-colors",o==="subtasks"?"border-blue-500 text-blue-500":"border-transparent text-fg-4 hover:text-fg-2"),children:["子任务",_>0&&c.jsx("span",{className:"font-mono text-[10px] text-fg-5",children:_})]})]}),o==="todo"?c.jsx(Gwe,{todos:e}):o==="prompts"?c.jsx(Kwe,{messages:t,onScrollToMessage:a}):o==="links"?c.jsx(Wwe,{links:n,sessionId:r}):c.jsx(Jwe,{})]}),r&&f&&c.jsx(i_e,{repoId:f,sessionId:r,containerRef:d,onPreviewFile:i})]})}function gE(e){var t,n;if(typeof((t=e.time)==null?void 0:t.updated)=="number")return e.time.updated;if(typeof((n=e.time)==null?void 0:n.created)=="number")return e.time.created;if(e.createdAt){const r=Date.parse(e.createdAt);return Number.isNaN(r)?0:r}return 0}function s_e(e){const t=gE(e);if(!t)return"";const n=t<1e12?t*1e3:t,r=new Date(n);return r.toDateString()===new Date().toDateString()?r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):r.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function aR(e){navigator.clipboard?navigator.clipboard.writeText(e).catch(()=>iR(e)):iR(e)}function iR(e){const t=document.createElement("textarea");t.value=e,t.style.cssText="position:fixed;opacity:0",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}function o_e(e){switch(e){case"idle":return"bg-emerald-500";case"busy":case"retry":return"bg-amber-500 animate-pulse";case"error":return"bg-red-500";default:return"bg-fg-5"}}const sR="fs:swipe-hint-shown",cf=144,l_e=-60,u_e=600,c_e=800;function d_e({session:e,isActive:t,peekHint:n,onSelect:r,onRename:a,onToggleComplete:i,onTogglePin:o,status:u,issue:d,linkedItems:f,todos:m}){var z,$;const p=Fp(M=>M.drafts[e.id]),b=!!e.completedAt,x=!!e.pinnedAt,E=s_e(e),[N,_]=y.useState(!1),[S,C]=y.useState(""),A=y.useRef(null),I=()=>{var M;C(((M=e.title)==null?void 0:M.trim())||""),_(!0),requestAnimationFrame(()=>{var le;return(le=A.current)==null?void 0:le.focus()})},O=()=>{var le;_(!1);const M=S.trim();M&&M!==(((le=e.title)==null?void 0:le.trim())||"")&&a(M)},[k,j]=y.useState(null),F=y.useRef(null),P=y.useRef(!1),L=()=>{F.current&&(clearTimeout(F.current),F.current=null)},B=y.useRef(null),Y=y.useRef(null),re=y.useRef(0),X=y.useRef({x0:0,y0:0,base:0,dir:null,on:!1}),K=M=>{re.current=M;const le=B.current,oe=Y.current;le&&(le.style.transform=M!==0?`translateX(${M}px)`:"",le.style.pointerEvents=M===-cf?"none":""),oe&&(oe.style.width=`${Math.abs(M)}px`)},V=M=>{const le=M.touches[0];X.current={x0:le.clientX,y0:le.clientY,base:re.current,dir:null,on:!0},B.current&&(B.current.style.transition="none"),Y.current&&(Y.current.style.transition="none"),P.current=!1,L(),F.current=setTimeout(()=>{P.current=!0,X.current.on=!1,j({x:le.clientX,y:le.clientY})},500)},H=M=>{const le=X.current;if(!le.on){L();return}const oe=M.touches[0].clientX-le.x0,ne=M.touches[0].clientY-le.y0;if(!le.dir){(Math.abs(oe)>5||Math.abs(ne)>5)&&(le.dir=Math.abs(oe)>Math.abs(ne)?"h":"v",L());return}le.dir!=="v"&&K(Math.max(-cf,Math.min(0,le.base+oe)))},G=M=>{const le=B.current,oe=Y.current;le&&(le.style.transition="transform 200ms ease-out"),oe&&(oe.style.transition="width 200ms ease-out"),K(M)},Q=()=>{if(L(),P.current){P.current=!1;return}X.current.on=!1,G(re.current<-cf/2?-cf:0)},D=()=>G(0);return y.useEffect(()=>{if(!n)return;const M=setTimeout(()=>{const le=B.current,oe=Y.current;le&&(le.style.transition="transform 400ms cubic-bezier(.25,.8,.25,1)"),oe&&(oe.style.transition="width 400ms cubic-bezier(.25,.8,.25,1)"),K(l_e);const ne=setTimeout(()=>{le&&(le.style.transition="transform 500ms cubic-bezier(.25,.8,.25,1)"),oe&&(oe.style.transition="width 500ms cubic-bezier(.25,.8,.25,1)"),K(0)},c_e);return()=>clearTimeout(ne)},u_e);return()=>clearTimeout(M)},[n,K]),c.jsxs("li",{className:"relative overflow-hidden rounded-md",children:[c.jsx("div",{ref:Y,className:"absolute right-0 top-0 bottom-0 z-10 overflow-hidden md:hidden",style:{width:0},children:c.jsxs("div",{className:"absolute right-0 top-0 bottom-0 flex",style:{width:cf},children:[c.jsxs("button",{type:"button",onClick:()=>{o(),D()},className:ie("flex w-12 flex-col items-center justify-center gap-0.5 text-white",x?"bg-amber-500 active:bg-amber-600":"bg-blue-500 active:bg-blue-600"),children:[c.jsx(Sy,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"text-[9px] leading-none",children:x?"取消":"置顶"})]}),c.jsxs("button",{type:"button",onClick:()=>{i(),D()},className:ie("flex w-12 flex-col items-center justify-center gap-0.5 text-white",b?"bg-neutral-500 active:bg-neutral-600":"bg-emerald-500 active:bg-emerald-600"),children:[c.jsx(Ny,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"text-[9px] leading-none",children:b?"撤销":"完成"})]}),c.jsxs("button",{type:"button",onClick:()=>{I(),D()},className:"flex w-12 flex-col items-center justify-center gap-0.5 bg-amber-500 text-white active:bg-amber-600",children:[c.jsx(oA,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"text-[9px] leading-none",children:"重命名"})]})]})}),c.jsxs("div",{ref:B,className:ie("group relative rounded-md border-l-2 will-change-transform",t?"border-blue-500 bg-elevated":"border-transparent bg-surface hover:bg-elevated/50"),onTouchStart:V,onTouchMove:H,onTouchEnd:Q,onContextMenu:M=>M.preventDefault(),children:[c.jsxs("button",{type:"button",onClick:()=>{N||(r(),D())},className:ie("block w-full px-2.5 py-2 text-left",b&&!t&&"opacity-50"),style:{pointerEvents:"auto"},children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:ie("h-1.5 w-1.5 shrink-0 rounded-full",o_e(u))}),c.jsx("span",{className:"min-w-0 truncate font-mono text-xs text-fg-3",children:((z=e.agent)==null?void 0:z.trim())||"默认"}),x&&c.jsx(Sy,{className:"h-3 w-3 shrink-0 text-amber-400"}),b&&c.jsx(Ny,{className:"h-3 w-3 shrink-0 text-emerald-400"}),E&&c.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] tabular-nums text-fg-5",children:E})]}),N?c.jsx("input",{ref:A,type:"text",value:S,onChange:M=>C(M.target.value),onBlur:O,onKeyDown:M=>{M.key==="Enter"&&O(),M.key==="Escape"&&_(!1)},onClick:M=>M.stopPropagation(),className:"mt-0.5 w-full rounded border border-blue-500 bg-base pl-3.5 text-sm text-fg-2 outline-none"}):c.jsxs("div",{className:"mt-0.5 pl-3.5",onDoubleClick:M=>{M.stopPropagation(),I()},children:[(d||f)&&c.jsxs("div",{className:"mb-0.5 flex flex-wrap gap-1",children:[d&&c.jsxs("span",{className:ie("shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-medium leading-none",d.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",d.number]}),f==null?void 0:f.map(M=>c.jsx("span",{className:ie("shrink-0 rounded px-1 py-0.5 font-mono text-[10px] font-medium leading-none",M.type==="pr"?M.state==="open"?"bg-blue-500/15 text-blue-400":M.mergedAt?"bg-purple-500/15 text-purple-400":"bg-red-500/15 text-red-400":M.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:M.type==="pr"?`PR#${M.number}`:`#${M.number}`},`${M.type}-${M.number}`))]}),c.jsx("span",{className:"block truncate text-sm text-fg-2",children:(($=e.title)==null?void 0:$.trim())||"未命名运行"}),p&&c.jsxs("span",{className:"mt-0.5 block truncate text-xs text-amber-400/80",children:["✏️ ",p]}),m.length>0&&(()=>{const M=m.length,le=mM(m);return c.jsxs("span",{className:"mt-0.5 flex items-center gap-1.5 font-mono text-[10px]",children:[c.jsx("span",{className:"shrink-0 tracking-tight",children:m.map(oe=>{const ne=Dl(oe.status);return c.jsx("span",{className:ne==="completed"?"text-emerald-400":ne==="in_progress"?"text-amber-400":ne==="cancelled"?"text-fg-6":"text-fg-5",children:ne==="pending"?"□":"■"},oe.id)})}),c.jsxs("span",{className:"tabular-nums text-fg-4",children:[le,"/",M]})]})})()]})]}),c.jsxs("span",{className:"absolute right-1.5 top-1.5 hidden items-center gap-0.5 opacity-0 transition-opacity group-hover:opacity-100 md:flex",children:[c.jsx("button",{type:"button",onClick:o,title:x?"取消置顶":"置顶",className:ie("rounded p-1",x?"text-amber-400 hover:text-amber-300":"text-fg-5 hover:text-amber-400"),children:c.jsx(Sy,{className:"h-3.5 w-3.5"})}),c.jsx("button",{type:"button",onClick:i,title:b?"取消完成":"标记完成",className:ie("rounded p-1",b?"text-emerald-400 hover:text-emerald-300":"text-fg-5 hover:text-emerald-400"),children:c.jsx(Ny,{className:"h-3.5 w-3.5"})}),c.jsx("button",{type:"button",onClick:I,title:"重命名",className:"rounded p-1 text-fg-5 hover:text-fg-2",children:c.jsx(oA,{className:"h-3.5 w-3.5"})}),c.jsx("button",{type:"button",onClick:()=>{var M;aR(JSON.stringify({id:e.id,name:((M=e.title)==null?void 0:M.trim())||""},null,2))},title:"复制 Session JSON",className:"rounded p-1 text-fg-5 hover:text-fg-2",children:c.jsx($p,{className:"h-3.5 w-3.5"})})]})]}),k&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"fixed inset-0 z-50",onClick:()=>j(null),onTouchEnd:()=>j(null)}),c.jsx("div",{className:"fixed z-50 min-w-[160px] rounded-lg border border-line bg-surface py-1 shadow-xl",style:{left:Math.min(k.x,window.innerWidth-176),top:k.y,animation:"ctx-fade-in 150ms ease-out"},children:c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-sm text-fg-2 active:bg-elevated",onClick:()=>{var M;aR(JSON.stringify({id:e.id,name:((M=e.title)==null?void 0:M.trim())||""},null,2)),j(null)},children:[c.jsx($p,{className:"h-3.5 w-3.5 text-fg-5"}),"复制 Session JSON"]})})]})]})}const f_e=y.memo(d_e,(e,t)=>{var n,r,a,i,o,u,d,f;return e.session.id===t.session.id&&e.session.title===t.session.title&&e.session.agent===t.session.agent&&e.session.completedAt===t.session.completedAt&&e.session.pinnedAt===t.session.pinnedAt&&((n=e.session.time)==null?void 0:n.updated)===((r=t.session.time)==null?void 0:r.updated)&&e.isActive===t.isActive&&e.peekHint===t.peekHint&&e.status===t.status&&((a=e.issue)==null?void 0:a.number)===((i=t.issue)==null?void 0:i.number)&&((o=e.issue)==null?void 0:o.state)===((u=t.issue)==null?void 0:u.state)&&(((d=e.linkedItems)==null?void 0:d.length)??0)===(((f=t.linkedItems)==null?void 0:f.length)??0)&&e.todos===t.todos});function oR({onClose:e}){const[t]=y.useState(()=>typeof window>"u"||localStorage.getItem(sR)?!1:(localStorage.setItem(sR,"1"),!0)),n=Me(O=>O.sessions),r=Me(O=>O.activeSessionId),a=Me(O=>O.sessionStatuses),i=Me(O=>O.sessionFilter),o=Me(O=>O.setSessionFilter),u=Me(O=>O.setActiveSession),d=Me(O=>O.renameSession),f=Me(O=>O.toggleSessionComplete),m=We(O=>O.activeRepoId),p=Je(O=>O.issues),b=Me(O=>O.allSessionLinks),x=Me(O=>O.todos),E=Me(O=>O.sessionSearch),N=Me(O=>O.setSessionSearch),_=Me(O=>O.toggleSessionPin),S=E.toLowerCase(),C=[...n].filter(O=>O.parentID?!1:i==="active"?!O.completedAt:!0).filter(O=>{if(!S)return!0;const k=(O.title??"").toLowerCase(),j=(O.agent??"").toLowerCase();return k.includes(S)||j.includes(S)}).sort((O,k)=>{const j=O.pinnedAt,F=k.pinnedAt;return j&&!F?-1:!j&&F?1:j&&F?F-j:gE(k)-gE(O)}),A=new Map(p.map(O=>[O.id,O])),I=O=>c.jsx("ul",{className:"space-y-0.5",children:O.map((k,j)=>{const F=k.issueId?A.get(k.issueId):void 0,P=b[k.id],L=[];if(P){for(const B of P.issues)L.push({number:B.number,state:B.state,type:"issue"});for(const B of P.pullRequests)L.push({number:B.number,state:B.state,type:"pr",mergedAt:B.mergedAt})}return c.jsx(f_e,{session:k,isActive:k.id===r,peekHint:t&&j===0,status:a[k.id],issue:F?{number:F.number,title:F.title,state:F.state}:void 0,linkedItems:L.length>0?L:void 0,onSelect:()=>{m&&u(m,k.id),e==null||e()},onRename:B=>m&&void d(m,k.id,B),onToggleComplete:()=>m&&void f(m,k.id),onTogglePin:()=>m&&void _(m,k.id),todos:x[k.id]??jf},k.id)})});return c.jsx("div",{className:"flex h-full w-80 shrink-0 flex-col border-r border-line bg-surface",children:c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-3",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-fg-3",children:"运行记录"}),m&&c.jsx("button",{type:"button",onClick:()=>{Me.setState({activeSessionId:null}),e==null||e()},title:"新建运行",className:"flex h-7 w-7 items-center justify-center rounded-md bg-blue-600 text-white transition-colors hover:bg-blue-500",children:c.jsx(ua,{className:"h-4 w-4"})})]}),m&&c.jsx("div",{className:"hidden border-b border-line px-3 py-1.5 md:block",children:c.jsxs("div",{className:"relative",children:[c.jsx(Ao,{className:"pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-fg-5"}),c.jsx("input",{type:"text",value:E,onChange:O=>N(O.target.value),placeholder:"搜索运行记录...",className:"w-full rounded-md border border-line bg-base py-1 pl-7 pr-7 text-xs text-fg-2 placeholder:text-fg-5 outline-none focus:border-blue-500"}),E&&c.jsx("button",{type:"button",onClick:()=>N(""),className:"absolute right-1.5 top-1/2 -translate-y-1/2 rounded p-0.5 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})}),m&&c.jsx("div",{className:"flex gap-1 border-b border-line px-3 py-1.5",children:[["active","进行中"],["all","全部"]].map(([O,k])=>c.jsx("button",{type:"button",onClick:()=>o(O),className:ie("rounded-md px-2 py-0.5 font-mono text-[11px] transition-colors",i===O?"bg-elevated text-fg-2":"text-fg-5 hover:text-fg-3"),children:k},O))}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:m?C.length===0?c.jsx("p",{className:"px-2 py-6 text-center font-mono text-xs text-fg-5",children:"暂无运行记录"}):c.jsx("div",{children:I(C)}):c.jsx("p",{className:"px-2 py-6 text-center font-mono text-xs text-fg-5",children:"请先选择一个仓库"})})]})})}function h_e(){const[e,t]=y.useState(()=>typeof window<"u"&&window.matchMedia("(min-width: 1280px)").matches);return y.useEffect(()=>{const n=window.matchMedia("(min-width: 1280px)"),r=a=>t(a.matches);return n.addEventListener("change",r),()=>n.removeEventListener("change",r)},[]),e}function lR(e){const t=document.querySelector(`[data-message-id="${e}"]`);t&&(t.scrollIntoView({behavior:"smooth",block:"center"}),t.classList.add("fs-highlight"),setTimeout(()=>t.classList.remove("fs-highlight"),TY))}const uR=new Set([".html",".htm"]),m_e=".md";function p_e({file:e}){const[t,n]=y.useState(null),[r,a]=y.useState(!1);return y.useEffect(()=>{uR.has(e.ext)||(a(!0),n(null),fetch(e.url).then(i=>i.text()).then(i=>n(i)).catch(()=>n("加载失败")).finally(()=>a(!1)))},[e.url,e.ext]),uR.has(e.ext)?c.jsx("iframe",{src:e.url,sandbox:"",title:e.name,className:"h-full w-full border-0 bg-white"}):r?c.jsx("p",{className:"p-8 text-center font-mono text-sm text-fg-5",children:"加载中…"}):e.ext===m_e?c.jsx("div",{className:"h-full overflow-y-auto",children:c.jsx("div",{className:"prose prose-invert max-w-none p-6",children:c.jsx($l,{remarkPlugins:[Yl],children:t??""})})}):c.jsx("pre",{className:"h-full overflow-auto whitespace-pre-wrap p-6 font-mono text-xs leading-relaxed text-fg-2",children:t})}function g_e(e,t){switch(t.type){case"reset":return{tabs:[],activeIdx:null};case"open":{const n=e.tabs.findIndex(r=>r.url===t.info.url);return n>=0?{...e,activeIdx:n}:{tabs:[...e.tabs,t.info],activeIdx:e.tabs.length}}case"close":{const n=e.tabs.filter((a,i)=>i!==t.idx);let r=e.activeIdx;return r===t.idx?r=null:r!==null&&r>t.idx&&(r=r-1),{tabs:n,activeIdx:r}}case"activate":return{...e,activeIdx:t.idx}}}function b_e(e){const[t,n]=y.useReducer(g_e,{tabs:[],activeIdx:null});y.useEffect(()=>{n({type:"reset"})},[]);const r=y.useCallback(o=>n({type:"open",info:o}),[]),a=y.useCallback(o=>n({type:"close",idx:o}),[]),i=y.useCallback(o=>n({type:"activate",idx:o}),[]);return{tabs:t.tabs,activeIdx:t.activeIdx,open:r,close:a,activate:i}}function x_e(){const[e,t]=y.useState(!1),[n,r]=y.useState(!1),[a,i]=y.useState(!1),o=h_e(),u=Me(S=>S.activeSessionId),d=b_e(),f=ys(S=>S.sessionPanelCollapsed),m=ys(S=>S.toggleSessionPanel),p=Me(S=>{const C=S.activeSessionId;return C?S.todos[C]??jf:jf}),b=Me(S=>{const C=S.activeSessionId;return C?S.messages[C]??Df:Df}),x=Me(S=>{const C=S.activeSessionId;return C?S.sessionLinks[C]:void 0});y.useEffect(()=>{o&&u?i(!0):o||i(!1)},[o,u]);const E=a&&!!u,N=()=>{window.matchMedia("(max-width: 767px)").matches?r(S=>!S):i(S=>!S)},_=tB({onSwipeRight:()=>t(!0),onSwipeLeft:()=>r(!0),disabled:e||n});return c.jsxs("div",{className:"flex min-h-0 flex-1",..._,children:[c.jsxs("div",{className:"relative hidden shrink-0 md:flex",children:[c.jsx("div",{className:ie("overflow-hidden transition-[width] duration-200 ease-in-out",f?"w-0":"w-80"),children:c.jsx("div",{className:"h-full w-80",children:c.jsx(oR,{})})}),c.jsx("button",{type:"button","data-guide":"run-panel-handle",onClick:m,title:f?"展开运行记录":"收起运行记录",className:ie("absolute left-full top-1/2 z-20 flex h-14 w-4 -translate-y-1/2 items-center justify-center rounded-r-md border-y border-r border-line text-fg-5 transition-all duration-200 hover:bg-elevated hover:text-fg-3",f?"bg-surface opacity-80 hover:w-5 hover:opacity-100":"bg-surface/80 opacity-40 hover:opacity-100"),children:f?c.jsx(Oo,{className:"h-3 w-3"}):c.jsx(ih,{className:"h-3 w-3"})})]}),c.jsx(dE,{side:"left",open:e,onClose:()=>t(!1),children:c.jsx(oR,{onClose:()=>t(!1)})}),c.jsx(dE,{side:"right",open:n,onClose:()=>r(!1),children:c.jsx(rR,{todos:p,messages:b,sessionLinks:x,sessionId:u,onScrollToMessage:S=>{r(!1),setTimeout(()=>lR(S),CY)}})}),c.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[d.tabs.length>0&&c.jsxs("div",{className:"flex shrink-0 items-end gap-0 border-b border-line bg-surface",children:[c.jsx("button",{type:"button",onClick:()=>d.activate(null),className:ie("flex items-center gap-1.5 border-r border-line px-3 py-1.5 text-xs font-medium transition-colors",d.activeIdx===null?"border-b-2 border-b-blue-500 bg-base text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:"对话"}),d.tabs.map((S,C)=>c.jsxs("div",{className:ie("group flex items-center gap-1 border-r border-line px-2 py-1.5 text-xs transition-colors",d.activeIdx===C?"border-b-2 border-b-blue-500 bg-base text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:[c.jsx("button",{type:"button",onClick:()=>d.activate(C),className:"min-w-0 max-w-[120px] truncate font-mono",title:S.name,children:S.name}),c.jsx("button",{type:"button",onClick:A=>{A.stopPropagation(),d.close(C)},className:"shrink-0 rounded p-0.5 text-fg-5 opacity-0 transition-opacity hover:bg-elevated hover:text-fg-2 group-hover:opacity-100",children:c.jsx(At,{className:"h-3 w-3"})})]},S.url))]}),c.jsx("div",{className:ie("min-h-0 flex-1 flex flex-col",d.activeIdx!==null&&"hidden"),children:c.jsx(Hwe,{onToggleSidebar:()=>t(S=>!S),onToggleRightPanel:N,rightPanelOpen:E})}),d.activeIdx!==null&&d.tabs[d.activeIdx]&&c.jsx("div",{className:"min-h-0 flex-1 bg-base",children:c.jsx(p_e,{file:d.tabs[d.activeIdx]})})]}),E&&c.jsx("div",{className:"hidden shrink-0 md:flex",children:c.jsx(rR,{todos:p,messages:b,sessionLinks:x,sessionId:u,onScrollToMessage:lR,onPreviewFile:d.open})})]})}let fs=null;function y_e(e){const t=Date.now()-e,n=Math.floor(t/6e4);return n<1?"刚刚":n<60?`${n} 分钟前`:`${Math.floor(n/60)} 小时前`}const cR=[{id:"repos",label:"仓库",icon:FR},{id:"usage",label:"Claude 账号",icon:Cc},{id:"git",label:"Git 源站",icon:Gl},{id:"models",label:"模型",icon:Op},{id:"agents",label:"AGENTS.md",icon:Io},{id:"general",label:"通用",icon:KR},{id:"diagnostics",label:"诊断",icon:kE}],v_e={id:"server",label:"服务器",icon:ZR};function bE(e){if(!e)return null;const t=new Date(e).getTime()-Date.now();if(t<=0)return"已重置";const n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4);return n>0?`${n}h ${r}m 后重置`:`${r}m 后重置`}function E_e(e){return e>=90?"bg-red-500":e>=70?"bg-amber-500":"bg-blue-500"}function Yv({label:e,window:t}){if(!t)return null;const n=Math.round(t.utilization),r=bE(t.resets_at),a=n>=90,i=n>=70;return c.jsxs("div",{className:"space-y-1.5",children:[c.jsxs("div",{className:"flex items-center justify-between gap-3",children:[c.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-fg-3",children:e}),c.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[r&&c.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full bg-elevated px-1.5 py-0.5 text-[10px] font-medium text-fg-4 tabular-nums",children:[c.jsx(n0,{className:"h-2.5 w-2.5"}),r]}),c.jsxs("span",{className:ie("text-sm font-bold leading-none tabular-nums",a?"text-red-400":i?"text-amber-400":"text-fg"),children:[n,"%"]})]})]}),c.jsx("div",{className:"h-2.5 overflow-hidden rounded-full bg-elevated ring-1 ring-inset ring-line/60",children:c.jsx("div",{className:ie("h-full rounded-full transition-all duration-500 ease-out",E_e(n),a?"shadow-sm shadow-red-500/50":i?"shadow-sm shadow-amber-500/40":null),style:{width:`${Math.min(n,100)}%`}})})]})}function N_e({account:e,onSwitch:t,switching:n}){var a;const r=e.active;return c.jsxs("div",{className:ie("relative overflow-hidden rounded-xl border bg-base p-4 shadow-sm transition-colors",r?"border-blue-500/30 ring-1 ring-inset ring-blue-500/20":"border-line"),children:[r&&c.jsx("span",{"aria-hidden":!0,className:"absolute inset-y-0 left-0 w-1 bg-blue-500"}),c.jsxs("div",{className:"flex items-center gap-2.5",children:[c.jsx("div",{className:ie("flex h-7 w-7 shrink-0 items-center justify-center rounded-lg",r?"bg-blue-500/15 text-blue-500":"bg-elevated text-fg-4"),children:c.jsx(XR,{className:"h-3.5 w-3.5"})}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-semibold text-fg",children:e.label}),r&&c.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1.5 rounded-full bg-blue-500/15 px-2 py-0.5 text-[10px] font-semibold text-blue-500",children:[c.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-blue-500 shadow-sm shadow-blue-500/60"}),"当前"]}),!r&&t&&c.jsxs("button",{type:"button",onClick:()=>t(e.id),disabled:n,className:"inline-flex shrink-0 items-center gap-1 rounded-full border border-line px-2 py-0.5 text-[10px] font-medium text-fg-4 transition-colors hover:border-blue-500/50 hover:text-blue-500 disabled:opacity-40",children:[n&&c.jsx(nn,{className:"h-2.5 w-2.5 fs-spin"}),"切换"]}),e.excluded&&c.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-elevated px-2 py-0.5 text-[10px] font-medium text-fg-5",children:[c.jsx(WF,{className:"h-2.5 w-2.5"}),"不自动切"]}),e.needsReauth&&c.jsxs("span",{className:"inline-flex shrink-0 items-center gap-1 rounded-full bg-red-500/15 px-2 py-0.5 text-[10px] font-medium text-red-400",children:[c.jsx(On,{className:"h-2.5 w-2.5"}),"需重新登录"]})]}),e.holders&&e.holders.length>0&&c.jsxs("div",{className:"mt-2 flex items-center gap-1.5 text-[11px] text-fg-5",children:[c.jsx(QR,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:e.holders.join(", ")})]}),e.error&&!e.usage?c.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-lg bg-red-500/10 px-3 py-2 text-xs text-red-400",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"min-w-0 break-words",children:e.error})]}):e.usage?c.jsxs("div",{className:"mt-4 space-y-3",children:[c.jsx(Yv,{label:"5 小时窗口",window:e.usage.five_hour}),c.jsx(Yv,{label:"7 天窗口",window:e.usage.seven_day}),(a=e.usage.scoped)==null?void 0:a.map(i=>c.jsx(Yv,{label:i.label,window:i},i.label))]}):null]})}function S_e({onClose:e,onSuccess:t}){const[n,r]=y.useState("idle"),[a,i]=y.useState(""),[o,u]=y.useState(""),[d,f]=y.useState(""),[m,p]=y.useState(""),[b,x]=y.useState(""),[E,N]=y.useState(!1),_=async()=>{r("loading"),p("");try{const C=await bY();i(C.url),u(C.pendingId),r("waiting")}catch(C){p(C instanceof Error?C.message:String(C)),r("error")}},S=async()=>{if(!(!d.trim()||!o)){r("exchanging"),p("");try{const C=await xY(o,d.trim());if(C.ok)x(C.label),N(C.existing),r("done");else{const A=C.detail||C.reason;C.attemptsLeft!==void 0&&C.attemptsLeft>0?(p(`${A}(还可重试 ${C.attemptsLeft} 次)`),r("waiting")):C.reason==="throttled"?(p("请求过快,请稍后再试"),r("waiting")):(p(A),r("error"))}}catch(C){p(C instanceof Error?C.message:String(C)),r("error")}}};return y.useEffect(()=>{_()},[_]),c.jsx("div",{className:"fixed inset-0 z-50 flex items-end justify-center bg-black/50 backdrop-blur-sm sm:items-center",onClick:e,children:c.jsxs("div",{className:"flex w-full max-w-lg flex-col rounded-t-2xl border border-line bg-surface p-5 shadow-2xl sm:rounded-xl",onClick:C=>C.stopPropagation(),children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"登录 Claude 账号"}),c.jsx("button",{type:"button",onClick:e,className:"rounded-md p-1 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-3",children:c.jsx(At,{className:"h-4 w-4"})})]}),n==="loading"&&c.jsx("div",{className:"flex items-center justify-center py-12",children:c.jsx(nn,{className:"h-5 w-5 fs-spin text-fg-4"})}),n==="waiting"&&c.jsxs("div",{className:"mt-4 space-y-4",children:[c.jsxs("div",{className:"space-y-2",children:[c.jsxs("p",{className:"text-xs text-fg-3",children:[c.jsx("span",{className:"font-medium text-fg",children:"第 1 步:"}),"点击下方链接,在浏览器中登录你的 Claude 账号。"]}),c.jsxs("a",{href:a,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 rounded-lg border border-blue-500/30 bg-blue-500/5 px-3 py-2.5 text-xs font-medium text-blue-400 transition-colors hover:bg-blue-500/10",children:[c.jsx(Cc,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"truncate",children:"打开 Claude 登录页面"})]})]}),c.jsxs("div",{className:"space-y-2",children:[c.jsxs("p",{className:"text-xs text-fg-3",children:[c.jsx("span",{className:"font-medium text-fg",children:"第 2 步:"}),"登录成功后,页面会显示一个授权码,复制粘贴到下方。"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("input",{type:"text",value:d,onChange:C=>f(C.target.value),onKeyDown:C=>{C.key==="Enter"&&S()},placeholder:"粘贴授权码…",className:"min-w-0 flex-1 rounded-md border border-line bg-base px-3 py-2 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsx("button",{type:"button",onClick:()=>void S(),disabled:!d.trim(),className:"shrink-0 rounded-md bg-blue-600 px-4 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:"确认"})]})]}),m&&c.jsxs("div",{className:"flex items-start gap-1.5 rounded-md border border-red-400/30 bg-red-400/5 px-3 py-2",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0 text-red-400"}),c.jsx("span",{className:"text-xs text-red-400",children:m})]})]}),n==="exchanging"&&c.jsxs("div",{className:"flex flex-col items-center gap-2 py-12",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin text-blue-500"}),c.jsx("p",{className:"text-xs text-fg-4",children:"正在验证授权码…"})]}),n==="done"&&c.jsxs("div",{className:"mt-4 space-y-4",children:[c.jsxs("div",{className:"flex flex-col items-center gap-2 py-6",children:[c.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-green-500/10",children:c.jsx(fi,{className:"h-5 w-5 text-green-500"})}),c.jsx("p",{className:"text-sm font-medium text-fg",children:E?"账号已更新":"账号添加成功"}),c.jsx("p",{className:"text-xs text-fg-4",children:b})]}),c.jsx("button",{type:"button",onClick:t,className:"w-full rounded-md bg-blue-600 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:"完成"})]}),n==="error"&&c.jsxs("div",{className:"mt-4 space-y-4",children:[c.jsxs("div",{className:"flex flex-col items-center gap-2 py-6",children:[c.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-red-500/10",children:c.jsx(On,{className:"h-5 w-5 text-red-400"})}),c.jsx("p",{className:"max-w-xs text-center text-xs text-red-400",children:m})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{type:"button",onClick:()=>{f(""),_()},className:"flex-1 rounded-md border border-line py-2 text-xs font-medium text-fg-3 transition-colors hover:bg-elevated",children:"重试"}),c.jsx("button",{type:"button",onClick:e,className:"flex-1 rounded-md bg-blue-600 py-2 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:"关闭"})]})]})]})})}function w_e(){const[e,t]=y.useState((fs==null?void 0:fs.data)??null),[n,r]=y.useState(!fs),[a,i]=y.useState(null),[o,u]=y.useState(null),[d,f]=y.useState((fs==null?void 0:fs.fetchedAt)??null),[,m]=y.useState(0),[p,b]=y.useState(!1),x=y.useCallback(S=>{const C=Date.now();fs={data:S,fetchedAt:C},t(S),f(C)},[]),E=y.useCallback(()=>{r(!0),i(null),oM().then(S=>{x(S),r(!1)}).catch(S=>{i(S instanceof Error?S.message:String(S)),r(!1)})},[x]);y.useEffect(()=>{fs||E()},[E]),y.useEffect(()=>{const S=setInterval(()=>m(C=>C+1),3e4);return()=>clearInterval(S)},[]);const N=y.useRef(!1),_=y.useCallback(S=>{N.current||(N.current=!0,u(S),lM(S).then(C=>{x(C),u(null)}).catch(C=>{i(C instanceof Error?C.message:String(C)),u(null)}).finally(()=>{N.current=!1}))},[x]);return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex items-center justify-between gap-3",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[c.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-blue-500/10 text-blue-500",children:c.jsx(Fz,{className:"h-4 w-4"})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Claude 订阅额度"}),c.jsx("p",{className:"mt-0.5 text-xs text-fg-4",children:"各账号的 Pro/Max 订阅窗口用量。"})]})]}),c.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[d&&c.jsx("span",{className:"text-[10px] tabular-nums text-fg-5",children:y_e(d)}),c.jsx("button",{type:"button",onClick:E,disabled:n,className:"rounded-md p-1.5 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:c.jsx(Rl,{className:ie("h-4 w-4",n&&"fs-spin")})})]})]}),c.jsxs("div",{className:"mt-4 space-y-2.5",children:[n&&!e?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin"}),c.jsx("p",{className:"text-xs",children:"加载中…"})]}):a&&!e?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-red-400",children:[c.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-red-500/10",children:c.jsx(On,{className:"h-5 w-5"})}),c.jsx("p",{className:"max-w-xs text-center text-xs leading-relaxed",children:a})]}):e&&e.accounts.length===0?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-full bg-elevated text-fg-4",children:c.jsx(QR,{className:"h-5 w-5"})}),c.jsx("p",{className:"max-w-xs text-center text-xs leading-relaxed",children:"暂无账号,点击下方按钮登录 Claude 账号。"})]}):e?e.accounts.map(S=>c.jsx(N_e,{account:S,onSwitch:_,switching:o===S.id},S.id)):null,c.jsxs("button",{type:"button",onClick:()=>b(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-line py-2.5 text-xs text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-3",children:[c.jsx(ua,{className:"h-3.5 w-3.5"})," 添加 Claude 账号"]})]}),p&&c.jsx(S_e,{onClose:()=>b(!1),onSuccess:()=>{b(!1),E()}})]})}function __e({host:e,onDelete:t}){return c.jsxs("div",{className:"group flex items-center gap-3 rounded-lg border border-line bg-base px-4 py-3",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium text-fg",children:e.name}),c.jsx("span",{className:"rounded bg-elevated px-1.5 py-0.5 font-mono text-[10px] text-fg-4",children:e.platform})]}),c.jsxs("div",{className:"mt-0.5 flex items-center gap-2 font-mono text-xs text-fg-4",children:[c.jsx("span",{children:e.host}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{className:"text-fg-5",children:e.token})]})]}),c.jsx(oh,{onConfirm:t,size:"md",triggerClassName:"text-fg-5 opacity-0 transition-opacity hover:text-red-400 group-hover:opacity-100"})]})}const T_e={github:{scope:"repo",linkFn:()=>"https://github.com/settings/tokens/new?scopes=repo"},gitlab:{scope:"api",linkFn:e=>e?`https://${e}/-/user_settings/personal_access_tokens`:null},gitea:{scope:"issue 和 pull request 读写",linkFn:e=>e?`https://${e}/user/settings/applications`:null}};function A_e({platform:e,host:t}){const n=T_e[e];if(!n)return null;const r=n.linkFn(t);return c.jsxs("p",{className:"text-[11px] leading-relaxed text-fg-5",children:["需要 ",c.jsx("span",{className:"font-medium text-fg-4",children:n.scope})," 权限。",r?c.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",className:"ml-1 text-blue-500 hover:underline",children:"去创建 Token →"}):c.jsx("span",{className:"ml-1 text-fg-6",children:"(填写 Host 后可跳转创建页)"})]})}function C_e({onAdded:e}){const[t,n]=y.useState(!1),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(""),[f,m]=y.useState("gitea"),[p,b]=y.useState(!1),[x,E]=y.useState(!1),N=()=>{a(""),o(""),d(""),m("gitea"),n(!1)},_=async()=>{if(!(!r.trim()||!i.trim()||!u.trim())){b(!0);try{await pY(r.trim(),i.trim(),u.trim(),f),N(),e()}finally{b(!1)}}};return t?c.jsxs("div",{className:"space-y-3 rounded-lg border border-line bg-base p-4",children:[c.jsxs("div",{className:"flex gap-3",children:[c.jsxs("label",{className:"flex-1",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"名称"}),c.jsx("input",{type:"text",value:i,onChange:S=>o(S.target.value),placeholder:"公司 Gitea",className:"mt-1 w-full rounded-md border border-line bg-surface px-3 py-1.5 text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"})]}),c.jsxs("label",{className:"w-28",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"平台"}),c.jsxs("select",{value:f,onChange:S=>m(S.target.value),className:"mt-1 w-full rounded-md border border-line bg-surface px-3 py-1.5 text-sm text-fg focus:border-blue-500 focus:outline-none",children:[c.jsx("option",{value:"gitea",children:"Gitea"}),c.jsx("option",{value:"github",children:"GitHub"}),c.jsx("option",{value:"gitlab",children:"GitLab"})]})]})]}),c.jsxs("label",{className:"block",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"Host"}),c.jsx("input",{type:"text",value:r,onChange:S=>a(S.target.value),placeholder:"git.btsai.work",className:"mt-1 w-full rounded-md border border-line bg-surface px-3 py-1.5 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"})]}),c.jsxs("label",{className:"block",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"Token"}),c.jsxs("div",{className:"relative mt-1",children:[c.jsx("input",{type:x?"text":"password",value:u,onChange:S=>d(S.target.value),placeholder:"Personal Access Token",className:"w-full rounded-md border border-line bg-surface px-3 py-1.5 pr-9 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsx("button",{type:"button",onClick:()=>E(!x),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-fg-5 hover:text-fg-3",children:x?c.jsx(qR,{className:"h-3.5 w-3.5"}):c.jsx(GR,{className:"h-3.5 w-3.5"})})]})]}),c.jsx(A_e,{platform:f,host:r.trim()}),c.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[c.jsx("button",{type:"button",onClick:N,className:"rounded-md px-3 py-1.5 text-xs text-fg-4 hover:bg-elevated",children:"取消"}),c.jsx("button",{type:"button",onClick:()=>void _(),disabled:p||!r.trim()||!i.trim()||!u.trim(),className:"rounded-md bg-blue-600 px-4 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:p?"保存中…":"保存"})]})]}):c.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex w-full items-center justify-center gap-1.5 rounded-lg border border-dashed border-line py-2.5 text-xs text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-3",children:[c.jsx(ua,{className:"h-3.5 w-3.5"})," 添加 Git 源站"]})}function k_e(){const[e,t]=y.useState(""),[n,r]=y.useState(""),[a,i]=y.useState(!0),[o,u]=y.useState(!1),[d,f]=y.useState(null);y.useEffect(()=>{oY().then(b=>{t(b.content),r(b.content),i(!1)}).catch(b=>{f(b instanceof Error?b.message:String(b)),i(!1)})},[]);const m=async()=>{u(!0),f(null);try{await lY(e),r(e)}catch(b){f(b instanceof Error?b.message:String(b))}u(!1)},p=e!==n;return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex items-center justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"全局 AGENTS.md"}),c.jsx("p",{className:"mt-1 text-xs text-fg-4",children:"此内容会注入到所有仓库的 Agent 系统指令中。修改后 opencode 热加载,即时生效。"})]}),c.jsxs("button",{type:"button",onClick:()=>void m(),disabled:o||!p,className:"flex shrink-0 items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),o?"保存中…":"保存"]})]}),d&&c.jsxs("div",{className:"mt-3 flex items-start gap-2 rounded-lg bg-red-500/10 px-3 py-2 text-xs text-red-400",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"min-w-0 break-words",children:d})]}),c.jsx("div",{className:"mt-4",children:a?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin"}),c.jsx("p",{className:"text-xs",children:"加载中…"})]}):c.jsx("textarea",{value:e,onChange:b=>t(b.target.value),spellCheck:!1,className:"h-96 w-full resize-y rounded-lg border border-line bg-base px-4 py-3 font-mono text-sm leading-relaxed text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20",placeholder:`# AGENTS.md
667
667
 
668
668
  在此编写全局 Agent 指令…`})}),c.jsx("p",{className:"mt-3 text-[11px] text-fg-5",children:"文件路径:~/.config/opencode/AGENTS.md"})]})}function O_e(){const[e,t]=y.useState([]),[n,r]=y.useState(!0),a=()=>{FE().then(o=>{t(o),r(!1)}).catch(()=>r(!1))};y.useEffect(a,[]);const i=async o=>{await gY(o),t(u=>u.filter(d=>d.id!==o))};return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Git 源站管理"}),c.jsx("p",{className:"mt-1 text-xs text-fg-4",children:"为不同的 Git 托管平台配置访问凭证,用于同步 Issues。系统会根据仓库的 git URL 自动匹配对应的源站。"}),c.jsx("div",{className:"mt-4 space-y-2",children:n?c.jsx("p",{className:"py-4 text-center font-mono text-xs text-fg-5",children:"加载中…"}):c.jsxs(c.Fragment,{children:[e.map(o=>c.jsx(__e,{host:o,onDelete:()=>void i(o.id)},o.id)),c.jsx(C_e,{onAdded:a})]})}),c.jsx("p",{className:"mt-4 text-[11px] text-fg-5",children:"Token 存储在数据库中。也可通过环境变量 GITEA_TOKEN 设置全局 fallback。"})]})}const dR="pinned_models";function I_e(e){const t=new Map;for(const n of e){const r=n.providerName||n.providerID,a=t.get(r);a?a.push(n):t.set(r,[n])}return Array.from(t,([n,r])=>({provider:n,models:r})).sort((n,r)=>{const a=n.models.some(o=>o.configured),i=r.models.some(o=>o.configured);return a!==i?a?-1:1:n.provider.localeCompare(r.provider)})}function R_e(e){return e?e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${Math.round(e/1e3)}K`:String(e):""}function M_e(e){if(!e)return"";const t=[];return e.input!=null&&t.push(`$${e.input}/Mi`),e.output!=null&&t.push(`$${e.output}/Mo`),t.join(" ")}function D_e(){const e=We(A=>A.activeRepoId),[t,n]=y.useState([]),[r,a]=y.useState(new Set),[i,o]=y.useState(!0),[u,d]=y.useState(null),[f,m]=y.useState(null),[p,b]=y.useState("");y.useEffect(()=>{let A=!1;async function I(){o(!0),d(null);try{const[O,k]=await Promise.all([Ml(),e?kc(e):Promise.resolve([])]);if(A)return;const j=O[dR],F=j?JSON.parse(j):[];a(new Set(F)),n(k),m(null),b("")}catch(O){A||d(O instanceof Error?O.message:String(O))}A||o(!1)}return I(),()=>{A=!0}},[e]);const x=async A=>{const I=new Set(r);I.has(A)?I.delete(A):I.add(A),a(I);try{await qp(dR,JSON.stringify([...I]))}catch{a(r)}},E=y.useMemo(()=>I_e(t),[t]),N=t.filter(A=>r.has(A.id)).length,_=f?E.find(A=>A.provider===f):E[0],S=p.trim().toLowerCase(),C=_?S?_.models.filter(A=>(A.name||A.id).toLowerCase().includes(S)||A.id.toLowerCase().includes(S)):_.models:[];return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsx("div",{className:"flex items-center justify-between gap-3",children:c.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[c.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-blue-500/10 text-blue-500",children:c.jsx(Op,{className:"h-4 w-4"})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"常用模型"}),c.jsxs("p",{className:"mt-0.5 text-xs text-fg-4",children:["勾选常用模型,在新建对话时快速选择。",N>0&&c.jsxs("span",{className:"ml-1 text-blue-400",children:["已选 ",N," 个"]})]})]})]})}),c.jsx("div",{className:"mt-4",children:e?i?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin"}),c.jsx("p",{className:"text-xs",children:"加载模型列表…"})]}):u?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-red-400",children:[c.jsx(On,{className:"h-5 w-5"}),c.jsx("p",{className:"max-w-xs text-center text-xs leading-relaxed",children:u})]}):t.length===0?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx(Op,{className:"h-5 w-5"}),c.jsx("p",{className:"text-xs",children:"当前仓库没有可用模型。"})]}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"flex gap-1 overflow-x-auto rounded-lg border border-line bg-base p-1",children:E.map(A=>{var k;const I=A.provider===(f??((k=E[0])==null?void 0:k.provider)),O=A.models.filter(j=>r.has(j.id)).length;return c.jsxs("button",{type:"button",onClick:()=>{m(A.provider),b("")},className:ie("flex shrink-0 items-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",I?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-3"),children:[A.provider,O>0&&c.jsx("span",{className:"rounded-full bg-blue-500/15 px-1.5 py-0.5 text-[10px] font-semibold tabular-nums text-blue-500",children:O})]},A.provider)})}),c.jsxs("div",{className:"mt-3 flex items-center gap-2 rounded-md border border-line bg-base px-3 py-1.5",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:p,onChange:A=>b(A.target.value),placeholder:"搜索模型…",className:"min-w-0 flex-1 bg-transparent text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),p&&c.jsx("button",{type:"button",onClick:()=>b(""),className:"text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]}),c.jsx("div",{className:"mt-3 rounded-lg border border-line bg-base",children:C.length===0?c.jsx("div",{className:"px-3 py-6 text-center text-xs text-fg-5",children:"无匹配模型"}):c.jsx("div",{className:"divide-y divide-line/40",children:C.map(A=>{const I=r.has(A.id),O=R_e(A.contextLimit),k=M_e(A.cost);return c.jsxs("label",{className:ie("flex cursor-pointer items-center gap-3 px-3 py-2 transition-colors hover:bg-elevated/60",I&&"bg-blue-500/5"),children:[c.jsx("input",{type:"checkbox",checked:I,onChange:()=>void x(A.id),className:"h-3.5 w-3.5 shrink-0 cursor-pointer rounded border-line accent-blue-500"}),c.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-xs text-fg",children:A.name||A.id}),c.jsxs("span",{className:"flex shrink-0 items-center gap-2",children:[O&&c.jsx("span",{className:"rounded bg-surface px-1.5 py-0.5 text-[10px] text-fg-5",children:O}),k&&c.jsx("span",{className:"text-[10px] text-fg-6",children:k})]})]},A.id)})})})]}):c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-10 text-fg-5",children:[c.jsx(Op,{className:"h-5 w-5"}),c.jsx("p",{className:"text-xs",children:"请先在左侧选择一个仓库以加载可用模型。"})]})})]})}function j_e(){const[e,t]=y.useState(Wv),[n,r]=y.useState(!1),[a,i]=y.useState(null),[o,u]=y.useState(Wv),d=e!==o,f=async()=>{const p=e.replace(/\/+$/,"");if(p){r(!0),i(null);try{const b=await fetch(`${p}/api/health`,{signal:AbortSignal.timeout(5e3)});i(b.ok?"ok":"fail")}catch{i("fail")}r(!1)}},m=()=>{const p=e.replace(/\/+$/,"");n$(p),u(p),t(p)};return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[c.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-blue-500/10 text-blue-500",children:c.jsx(ZR,{className:"h-4 w-4"})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"服务器连接"}),c.jsx("p",{className:"mt-0.5 text-xs text-fg-4",children:"配置远程 Fourth Spark Server 地址。"})]})]}),c.jsxs("div",{className:"mt-4 space-y-3",children:[c.jsxs("label",{className:"block",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"服务器地址"}),c.jsx("input",{type:"url",value:e,onChange:p=>{t(p.target.value),i(null)},placeholder:"http://192.168.1.100:3000",className:"mt-1 w-full rounded-md border border-line bg-base px-3 py-2 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>void f(),disabled:n||!e.trim(),className:"flex items-center gap-1.5 rounded-md border border-line px-3 py-1.5 text-xs font-medium text-fg-3 transition-colors hover:bg-elevated disabled:opacity-40",children:[n?c.jsx(nn,{className:"h-3.5 w-3.5 fs-spin"}):c.jsx(Rl,{className:"h-3.5 w-3.5"}),"测试连接"]}),c.jsxs("button",{type:"button",onClick:m,disabled:!d,className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),"保存"]}),a==="ok"&&c.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-medium text-green-500",children:[c.jsx(fi,{className:"h-3.5 w-3.5"})," 连接成功"]}),a==="fail"&&c.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-medium text-red-400",children:[c.jsx(On,{className:"h-3.5 w-3.5"})," 连接失败"]})]})]}),c.jsx("p",{className:"mt-4 text-[11px] text-fg-5",children:"保存后需重新打开 App 生效。确保手机与开发机在同一局域网。"})]})}function L_e(){const[e,t]=y.useState("local"),[n,r]=y.useState(!1),[a,i]=y.useState(!1);y.useEffect(()=>{Xv().then(u=>{const d=u.mode==="worker";r(d),t(d?"cloud":"local")}).catch(()=>{}).finally(()=>i(!0))},[]);const o=y.useCallback(u=>{const d=u.mode==="worker";r(d),d&&t("cloud")},[]);return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"flex gap-1 rounded-lg border border-line bg-base p-1",children:[c.jsxs("button",{type:"button",onClick:()=>{n||t("local")},disabled:n,className:ie("flex flex-1 items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",e==="local"?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-3",n&&e!=="local"&&"cursor-not-allowed opacity-40"),title:n?"需先断开账号池连接":void 0,children:[c.jsx(Cc,{className:"h-3.5 w-3.5"}),"本地模式"]}),c.jsxs("button",{type:"button",onClick:()=>t("cloud"),className:ie("flex flex-1 items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-xs font-medium transition-colors",e==="cloud"?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-3"),children:[c.jsx($R,{className:"h-3.5 w-3.5"}),"账号池"]})]}),a&&e==="local"&&c.jsx(w_e,{}),a&&e==="cloud"&&c.jsx(B_e,{onStatusChange:o})]})}function P_e({onClose:e,onSwitched:t}){const[n,r]=y.useState([]),[a,i]=y.useState(!0),[o,u]=y.useState(null),[d,f]=y.useState(null);y.useEffect(()=>{oM().then(x=>r(x.accounts)).catch(()=>{}).finally(()=>i(!1))},[]);const m=async x=>{u(x),f(null);try{await lM(x),t(),e()}catch(E){const N=E instanceof Error?E.message:String(E);f(N||"切换失败"),u(null)}},p=x=>{var E;return(E=x.usage)==null?void 0:E.five_hour},b=x=>{var E;return(E=x.usage)==null?void 0:E.seven_day};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-end justify-center bg-black/50 backdrop-blur-sm sm:items-center",onClick:e,children:c.jsxs("div",{className:"flex max-h-[85vh] w-full flex-col rounded-t-2xl border border-line bg-surface p-4 shadow-2xl sm:mx-4 sm:max-w-lg sm:rounded-xl sm:p-5",onClick:x=>x.stopPropagation(),children:[c.jsxs("div",{className:"flex shrink-0 items-center justify-between",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"切换账号"}),c.jsx("button",{type:"button",onClick:e,className:"rounded-md p-1 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-3",children:c.jsx(At,{className:"h-4 w-4"})})]}),a?c.jsx("div",{className:"flex items-center justify-center py-10",children:c.jsx(nn,{className:"h-5 w-5 fs-spin text-fg-4"})}):n.length===0?c.jsx("p",{className:"py-10 text-center text-xs text-fg-4",children:"暂无可用账号"}):c.jsx("div",{className:"mt-3 min-h-0 flex-1 space-y-1.5 overflow-y-auto pb-[var(--safe-bottom)]",children:n.map(x=>{var E,N,_,S,C,A,I,O;return c.jsxs("button",{type:"button",disabled:o!==null,onClick:()=>{x.active||m(x.id)},className:ie("flex w-full items-center gap-2 rounded-lg border px-3 py-2.5 text-left transition-colors sm:gap-3",x.active?"border-blue-500/40 bg-blue-500/5":"border-line hover:bg-elevated",o===x.id&&"opacity-60"),children:[c.jsx("div",{className:"min-w-0 flex-1",children:c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsx("span",{className:"truncate text-xs font-medium text-fg",children:x.label}),x.active&&c.jsx("span",{className:"rounded bg-blue-500/15 px-1.5 py-0.5 text-[9px] font-semibold text-blue-500",children:"当前"}),o===x.id&&c.jsx(nn,{className:"h-3 w-3 fs-spin text-blue-500"})]})}),c.jsxs("div",{className:"flex shrink-0 gap-2 text-right sm:gap-4",children:[c.jsxs("div",{className:"w-14 sm:w-20",children:[c.jsx("div",{className:"text-[10px] text-fg-5",children:"5h"}),p(x)?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:ie("text-xs font-medium",(((E=p(x))==null?void 0:E.utilization)??0)>80?"text-red-400":"text-fg-3"),children:[Math.round(((N=p(x))==null?void 0:N.utilization)??0),"%"]}),c.jsx("div",{className:"hidden text-[9px] text-fg-5 sm:block",children:(_=p(x))!=null&&_.resets_at?bE((S=p(x))==null?void 0:S.resets_at):""})]}):c.jsx("div",{className:"text-[10px] text-fg-5",children:"—"})]}),c.jsxs("div",{className:"w-14 sm:w-20",children:[c.jsx("div",{className:"text-[10px] text-fg-5",children:"7d"}),b(x)?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:ie("text-xs font-medium",(((C=b(x))==null?void 0:C.utilization)??0)>80?"text-red-400":"text-fg-3"),children:[Math.round(((A=b(x))==null?void 0:A.utilization)??0),"%"]}),c.jsx("div",{className:"hidden text-[9px] text-fg-5 sm:block",children:(I=b(x))!=null&&I.resets_at?bE((O=b(x))==null?void 0:O.resets_at):""})]}):c.jsx("div",{className:"text-[10px] text-fg-5",children:"—"})]})]})]},x.id)})}),d&&c.jsxs("div",{className:"mt-3 flex shrink-0 items-center gap-1.5 rounded-md border border-red-400/30 bg-red-400/5 px-3 py-2",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0 text-red-400"}),c.jsx("span",{className:"text-xs text-red-400",children:d})]})]})})}function B_e({onStatusChange:e}){const[t,n]=y.useState(""),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(""),[f,m]=y.useState(!1),[p,b]=y.useState(null),[x,E]=y.useState(!1),[N,_]=y.useState(null),[S,C]=y.useState(!1);y.useEffect(()=>{let P=!1;return(async()=>{const[L,B]=await Promise.all([Ml().catch(()=>({})),Xv().catch(()=>null)]);if(P)return;const Y=L.cloud_master_url??"",re=L.cloud_worker_id||(B==null?void 0:B.defaultWorkerId)||"";n(Y),o(Y),a(re),d(L.cloud_worker_id??""),_(B)})(),()=>{P=!0}},[]);const I=((N==null?void 0:N.mode)??(i?"worker":"local"))==="worker",O=!I&&!!t.trim()&&!!r.trim(),k=t!==i||r!==u||O,j=async()=>{const P=t.replace(/\/+$/,"");if(!P)return;m(!0),b(null);const L=await mY(P);b(L?"ok":"fail"),m(!1)},F=async()=>{const P=t.replace(/\/+$/,""),L=r.trim();E(!0);try{await qp("cloud_master_url",P),await qp("cloud_worker_id",L),o(P),d(L),n(P),a(L);const B=await hY().catch(()=>null);B&&(_(B),e==null||e(B))}finally{E(!1)}};return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[c.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-blue-500/10 text-blue-500",children:c.jsx($R,{className:"h-4 w-4"})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"账号池配置"}),c.jsx("p",{className:"mt-0.5 text-xs text-fg-4",children:"连接 claude-accounts-pool Master,共享多账号池。"})]})]}),c.jsxs("div",{className:"mt-4 space-y-2",children:[c.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-line bg-base px-3 py-2",children:[c.jsx("span",{className:ie("h-2 w-2 shrink-0 rounded-full",I?"bg-blue-500 shadow-sm shadow-blue-500/60":"bg-green-500 shadow-sm shadow-green-500/60")}),c.jsx("span",{className:"text-xs font-medium text-fg-3",children:I?"Worker 模式":"本地模式"}),I&&(N==null?void 0:N.workerId)&&c.jsx("span",{className:"rounded bg-elevated px-1.5 py-0.5 font-mono text-[10px] text-fg-4",children:N.workerId}),I&&(N==null?void 0:N.connected)!=null&&c.jsx("span",{className:ie("ml-auto text-[10px] font-medium",N.connected?"text-green-500":"text-red-400"),children:N.connected?"已连接":"未连接"})]}),I&&(N==null?void 0:N.heldAccount)&&c.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-line bg-base px-3 py-2",children:[c.jsx(XR,{className:"h-3.5 w-3.5 shrink-0 text-blue-500"}),c.jsx("span",{className:"text-xs text-fg-4",children:"当前账号"}),c.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-fg",children:N.heldAccount.label}),c.jsx("button",{type:"button",onClick:()=>C(!0),className:"ml-auto rounded-md border border-line px-2 py-0.5 text-[10px] font-medium text-fg-4 transition-colors hover:bg-elevated hover:text-fg-3",children:"切换账号"})]})]}),c.jsxs("div",{className:"mt-4 space-y-3",children:[c.jsxs("label",{className:"block",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"Master URL"}),c.jsx("input",{type:"url",value:t,onChange:P=>{n(P.target.value),b(null)},placeholder:"http://100.64.0.36:8787",className:"mt-1 w-full rounded-md border border-line bg-base px-3 py-2 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"})]}),c.jsxs("label",{className:"block",children:[c.jsx("span",{className:"text-xs font-medium text-fg-3",children:"Worker ID"}),c.jsx("input",{type:"text",value:r,onChange:P=>a(P.target.value),placeholder:"fourth-spark-1",className:"mt-1 w-full rounded-md border border-line bg-base px-3 py-2 font-mono text-sm text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsx("span",{className:"mt-1 block text-[11px] text-fg-5",children:"此 Worker 在账号池中的唯一标识,建议用小写字母、数字和连字符。"})]}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>void j(),disabled:f||!t.trim(),className:"flex items-center gap-1.5 rounded-md border border-line px-3 py-1.5 text-xs font-medium text-fg-3 transition-colors hover:bg-elevated disabled:opacity-40",children:[f?c.jsx(nn,{className:"h-3.5 w-3.5 fs-spin"}):c.jsx(Rl,{className:"h-3.5 w-3.5"}),"测试连接"]}),c.jsxs("button",{type:"button",onClick:()=>void F(),disabled:!k||x,className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),x?"保存中…":"保存"]}),p==="ok"&&c.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-medium text-green-500",children:[c.jsx(fi,{className:"h-3.5 w-3.5"})," 连接成功"]}),p==="fail"&&c.jsxs("span",{className:"inline-flex items-center gap-1 text-xs font-medium text-red-400",children:[c.jsx(On,{className:"h-3.5 w-3.5"})," 连接失败"]})]})]}),c.jsx("p",{className:"mt-4 text-[11px] text-fg-5",children:"清空 Master URL 可切回本地模式。"}),S&&c.jsx(P_e,{onClose:()=>C(!1),onSwitched:async()=>{const P=await Xv().catch(()=>null);P&&(_(P),e==null||e(P))}})]})}function U_e(){const[e,t]=y.useState([]),[n,r]=y.useState(!1),[a,i]=y.useState(!1);y.useEffect(()=>{let p=!1;return(async()=>{try{const b=await Ml();if(p)return;const x=b.quick_inputs;if(x)try{t(JSON.parse(x))}catch{}}catch{}p||i(!0)})(),()=>{p=!0}},[]);const o=async()=>{r(!0);try{const p=e.filter(b=>b.label.trim()&&b.text.trim());await qp("quick_inputs",JSON.stringify(p)),t(p)}finally{r(!1)}},u=()=>{t([...e,{label:"",text:"",autoSend:!0}])},d=(p,b)=>{t(e.map((x,E)=>E===p?{...x,...b}:x))},f=p=>{t(e.filter((b,x)=>x!==p))},m=(p,b)=>{const x=p+b;if(x<0||x>=e.length)return;const E=[...e];[E[p],E[x]]=[E[x],E[p]],t(E)};return a?c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex min-w-0 items-center gap-2.5",children:[c.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-lg bg-emerald-500/10 text-emerald-500",children:c.jsx(KR,{className:"h-4 w-4"})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"快捷输入"}),c.jsx("p",{className:"mt-0.5 text-xs text-fg-4",children:"配置常用的快捷输入按钮,显示在对话输入框上方。"})]})]}),c.jsx("div",{className:"mt-4 space-y-2",children:e.map((p,b)=>c.jsxs("div",{className:"flex items-center gap-2 rounded-lg border border-line bg-base px-3 py-2",children:[c.jsxs("div",{className:"flex shrink-0 flex-col gap-0.5",children:[c.jsx("button",{type:"button",onClick:()=>m(b,-1),disabled:b===0,className:"text-fg-5 hover:text-fg-3 disabled:opacity-20",children:c.jsx(OE,{className:"h-3 w-3"})}),c.jsx("button",{type:"button",onClick:()=>m(b,1),disabled:b===e.length-1,className:"text-fg-5 hover:text-fg-3 disabled:opacity-20",children:c.jsx(kr,{className:"h-3 w-3"})})]}),c.jsx("input",{type:"text",value:p.label,onChange:x=>d(b,{label:x.target.value}),placeholder:"按钮文字",className:"w-20 min-w-0 rounded border border-line bg-surface px-2 py-1 text-xs text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsx("input",{type:"text",value:p.text,onChange:x=>d(b,{text:x.target.value}),placeholder:"发送内容",className:"min-w-0 flex-1 rounded border border-line bg-surface px-2 py-1 text-xs text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsxs("label",{className:"flex shrink-0 items-center gap-1 text-[11px] text-fg-4",children:[c.jsx("input",{type:"checkbox",checked:p.autoSend??!1,onChange:x=>d(b,{autoSend:x.target.checked}),className:"h-3.5 w-3.5 rounded border-line"}),"直接发送"]}),c.jsx("button",{type:"button",onClick:()=>f(b),className:"shrink-0 text-fg-5 transition-colors hover:text-red-400",children:c.jsx(a0,{className:"h-3.5 w-3.5"})})]},b))}),c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:u,className:"flex items-center gap-1.5 rounded-md border border-line px-3 py-1.5 text-xs font-medium text-fg-3 transition-colors hover:bg-elevated",children:[c.jsx(ua,{className:"h-3.5 w-3.5"}),"添加"]}),c.jsxs("button",{type:"button",onClick:()=>void o(),disabled:n,className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),n?"保存中…":"保存"]})]}),c.jsx("p",{className:"mt-3 text-[11px] text-fg-5",children:"「直接发送」开启后,点击按钮将直接发送消息;关闭则填入输入框供编辑。"})]}):null}function F_e(){const e=y.useCallback(()=>{const t=vs.exportData(),n=new Blob([t],{type:"application/json"}),r=URL.createObjectURL(n),a=document.createElement("a");a.href=r,a.download=`diagnostics-${new Date().toISOString().slice(0,19).replace(/:/g,"-")}.json`,a.click(),URL.revokeObjectURL(r)},[]);return c.jsx("section",{className:"space-y-4",children:c.jsxs("div",{className:"rounded-lg border border-line bg-surface p-4",children:[c.jsx("p",{className:"text-sm text-fg-3",children:"页面运行期间持续记录性能指标(SSE 频率、消息更新频率、内存占用等)。 遇到卡顿时点击下方按钮下载诊断文件,发给开发者排查。"}),c.jsxs("button",{type:"button",onClick:e,className:"mt-3 inline-flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:[c.jsx(kE,{className:"h-3.5 w-3.5"}),"下载诊断数据"]})]})})}function z_e(){const[e,t]=y.useState("usage"),n=y.useMemo(()=>t$()||Wv()?[...cR,v_e]:cR,[]);return c.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:c.jsxs("div",{className:ie("mx-auto",e==="repos"?"max-w-4xl":"max-w-2xl"),children:[c.jsx("h1",{className:"text-lg font-semibold text-fg",children:"设置"}),c.jsx("p",{className:"mt-0.5 text-sm text-fg-4",children:"全局配置"}),c.jsx("div",{className:"mt-6 flex gap-1 overflow-x-auto rounded-lg border border-line bg-surface p-1 scrollbar-none",children:n.map(r=>c.jsxs("button",{type:"button",onClick:()=>t(r.id),className:ie("flex shrink-0 items-center justify-center gap-1.5 whitespace-nowrap rounded-md px-3 py-1.5 text-xs font-medium transition-colors",e===r.id?"bg-base text-fg shadow-sm":"text-fg-4 hover:text-fg-3"),children:[c.jsx(r.icon,{className:"h-3.5 w-3.5"}),r.label]},r.id))}),c.jsxs("div",{className:"mt-4",children:[e==="repos"&&c.jsx(rB,{}),e==="usage"&&c.jsx(L_e,{}),e==="git"&&c.jsx(O_e,{}),e==="models"&&c.jsx(D_e,{}),e==="agents"&&c.jsx(k_e,{}),e==="general"&&c.jsx(U_e,{}),e==="server"&&c.jsx(j_e,{}),e==="diagnostics"&&c.jsx(F_e,{})]})]})})}function H_e(e){const t=e.match(/^\/([^/]+)\/(run|agents|issues|pulls|dev)/);return t?decodeURIComponent(t[1]):null}function $_e(){const e=We(r=>r.repos),n=We(qr)??(e.length>0?e[0].name:null);return n?c.jsx(Sl,{to:`/${encodeURIComponent(n)}/run`,replace:!0}):c.jsx(Sl,{to:"/repos",replace:!0})}function fR({segment:e}){const{repoId:t}=kR(),{search:n}=or();return t?c.jsx(Sl,{to:`/${encodeURIComponent(t)}/dev/${e}${n}`,replace:!0}):c.jsx(Sl,{to:"/repos",replace:!0})}function Y_e(){const e=or(),t=We(i=>i.activeRepoId),n=We(i=>i.repos),r=We(i=>i.loading),a=We(i=>i.setActiveRepo);return y.useEffect(()=>{vs.start(),LY(ar.getState().addToast,ar.getState().removeToast),We.getState().loadRepos();const i=Zv.getState().init();return()=>{vs.stop(),i()}},[]),y.useEffect(()=>{if(n.length===0)return;const i=H_e(e.pathname);if(!i)return;const o=n.find(u=>u.name===i);o&&o.id!==We.getState().activeRepoId&&a(o.id)},[e.pathname,n,a]),y.useEffect(()=>(t?(Me.getState().clearSessions(),Je.getState().clearIssues(),mn.getState().clearPulls(),Me.getState().loadSessions(t),ia.getState().loadAgents(t),Je.getState().loadIssues(t),mn.getState().loadPulls(t),Vp.start(t)):(Me.getState().clearSessions(),Je.getState().clearIssues(),mn.getState().clearPulls()),()=>Vp.stop()),[t]),r?c.jsx("div",{className:"flex h-screen items-center justify-center bg-base",children:c.jsx("span",{className:"h-6 w-6 animate-spin rounded-full border-2 border-fg-5 border-t-transparent"})}):n.length===0&&e.pathname!=="/repos"?c.jsxs(c.Fragment,{children:[c.jsx(Sl,{to:"/repos",replace:!0}),c.jsx(zA,{})]}):c.jsxs(c.Fragment,{children:[c.jsx(eF,{children:c.jsxs(Fr,{element:c.jsx(Nq,{}),children:[c.jsx(Fr,{path:"/repos",element:po(KEe)}),c.jsx(Fr,{path:"/settings",element:po(z_e)}),c.jsx(Fr,{path:"/analytics",element:po(Fhe)}),c.jsx(Fr,{path:"/:repoId/run",element:po(x_e)}),c.jsx(Fr,{path:"/:repoId/agents",element:po(VK)}),c.jsx(Fr,{path:"/:repoId/agents/:agentId",element:po(rG)}),c.jsx(Fr,{path:"/:repoId/dev",element:c.jsx(Sl,{to:"issues",replace:!0})}),c.jsx(Fr,{path:"/:repoId/dev/issues",element:po(TI)}),c.jsx(Fr,{path:"/:repoId/dev/pulls",element:po(TI)}),c.jsx(Fr,{path:"/:repoId/issues",element:c.jsx(fR,{segment:"issues"})}),c.jsx(Fr,{path:"/:repoId/pulls",element:c.jsx(fR,{segment:"pulls"})}),c.jsx(Fr,{path:"/:repoId",element:c.jsx(Sl,{to:"run",replace:!0})}),c.jsx(Fr,{path:"*",element:c.jsx($_e,{})})]})}),c.jsx(zA,{})]})}function q_e(){return c.jsx(_F,{children:c.jsx(LR,{fallback:(e,t)=>c.jsx(DF,{error:e,reset:t}),children:c.jsx(Y_e,{})})})}const LB=document.getElementById("root");if(!LB)throw new Error("Root element #root not found in index.html");QU.createRoot(LB).render(c.jsx(y.StrictMode,{children:c.jsx(q_e,{})}));export{sw as W};