fourth-spark 0.12.0-canary.5 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  {
2
- "id": "27aa812c-d94e-4b86-abba-4da9c1dd71e6",
2
+ "id": "946f913b-28ab-4ae9-8730-46e8284b79a6",
3
3
  "prevId": "894d91ca-b47b-4255-8fd4-47d73ed9526e",
4
4
  "version": "7",
5
5
  "dialect": "postgresql",
@@ -61,8 +61,8 @@
61
61
  {
62
62
  "idx": 8,
63
63
  "version": "7",
64
- "when": 1792633505362,
65
- "tag": "0008_rich_moonstone",
64
+ "when": 1792676069453,
65
+ "tag": "0008_lazy_warhawk",
66
66
  "breakpoints": true
67
67
  }
68
68
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fourth-spark",
3
- "version": "0.12.0-canary.5",
3
+ "version": "0.12.0",
4
4
  "description": "AI Agent Platform — multi-repo agent management based on OpenCode",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -520,7 +520,7 @@ Please change the parent <Route path="${S}"> to <Route path="${S==="/"?"*":`${S}
520
520
  */const s$=[["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",s$),Yp="fourth-spark-server-url";function o$(){if(typeof window>"u")return!1;const t=window.Capacitor;return typeof(t==null?void 0:t.isNativePlatform)=="function"&&t.isNativePlatform()}function s0(){return localStorage.getItem(Yp)??""}function l$(e){const t=e.replace(/\/+$/,"");t?localStorage.setItem(Yp,t):localStorage.removeItem(Yp)}function Qv(){return localStorage.getItem(Yp)??""}class Qa 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(s0()+e,{...t,headers:{Accept:"application/json",...t!=null&&t.body?{"Content-Type":"application/json"}:{},...t==null?void 0:t.headers}})}catch(a){throw new Qa(a instanceof Error?a.message:"Network request failed",0)}if(!n.ok){const a=await n.text().catch(()=>"");throw new Qa(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 nM(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 u$(){return Ia(await Te("/api/repos"),"repos")}async function c$(e,t,n,r){return Te("/api/repos",{method:"POST",body:JSON.stringify({name:e,gitUrl:t,localPath:n,runtimeType:r})})}async function d$(e){return Te("/api/repos/resolve",{method:"POST",body:JSON.stringify({localPath:e})})}async function f$(e,t){return Te("/api/fs/browse",{method:"POST",body:JSON.stringify({path:e,showHidden:t})})}async function h$(e,t){return Te("/api/repos/clone",{method:"POST",body:JSON.stringify({gitUrl:e,targetDir:t})})}async function m$(e){await Te(`/api/repos/${encodeURIComponent(e)}`,{method:"DELETE"})}async function p$(e){await Te(`/api/repos/${encodeURIComponent(e)}/start`,{method:"POST"})}async function g$(e){await Te(`/api/repos/${encodeURIComponent(e)}/stop`,{method:"POST"})}async function b$(e){return Te(`/api/repos/${encodeURIComponent(e)}/branches`)}async function x$(e,t){return Te(`/api/repos/${encodeURIComponent(e)}/checkout`,{method:"POST",body:JSON.stringify({branch:t})})}async function y$(e){return Te(`/api/repos/${encodeURIComponent(e)}/pull`,{method:"POST"})}function nt(e){return`/api/repos/${encodeURIComponent(e)}`}async function v$(e){return Ia(await Te(`${nt(e)}/workspaces`),"workspaces")}async function E$(e,t){await Te(`${nt(e)}/workspaces/${encodeURIComponent(t)}`,{method:"DELETE"})}async function N$(e){return Te(`${nt(e)}/workspaces/cleanup`,{method:"POST"})}async function S$(e,t){await Te(`/api/repos/${e}/worktree`,{method:"PATCH",body:JSON.stringify({enabled:t})})}async function w$(e,t){await Te(`/api/repos/${e}/runtime`,{method:"PATCH",body:JSON.stringify({runtimeType:t})})}async function _$(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 nM(await Te(`${nt(e)}/sessions${r?`?${r}`:""}`),"sessions")}async function T$(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 A$(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 C$(e,t){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/actions/abort`,{method:"POST"})}async function k$(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/questions/reply`,{method:"POST",body:JSON.stringify({answers:n})})}async function O$(e,t){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/questions/reject`,{method:"POST"})}async function I$(e,t,n){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/actions/revert`,{method:"POST",body:JSON.stringify({messageID:n})})}function fA(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 hA(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(fA);return{messages:f,total:f.length,hasMore:!1}}const u=o,d=Array.isArray(u.messages)?u.messages:[];return{messages:d.map(fA),total:u.total??d.length,hasMore:u.hasMore??!1}}async function R$(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/status`)}async function M$(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`)}async function j$(e,t){return Te(`${nt(e)}/sessions/snapshot/${encodeURIComponent(t)}`)}async function rM(e){return Te(`${nt(e)}/sessions/all-links`)}async function D$(e,t,n,r){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`,{method:"POST",body:JSON.stringify({type:n,targetId:r})})}async function L$(e,t,n,r){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`,{method:"DELETE",body:JSON.stringify({type:n,targetId:r})})}async function aM(){return Ia(await Te("/api/custom-agents"))}async function P$(e){return Te("/api/custom-agents",{method:"POST",body:JSON.stringify(e)})}async function B$(e,t){return Te(`/api/custom-agents/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify(t)})}async function iM(e){await Te(`/api/custom-agents/${encodeURIComponent(e)}`,{method:"DELETE"})}async function mA(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/export`)}async function U$(e){return Te("/api/custom-agents/import",{method:"POST",body:JSON.stringify(e)})}async function F$(e){await Te("/api/custom-agents/reorder",{method:"PATCH",body:JSON.stringify({items:e})})}async function z$(e,t){await Te(`${nt(e)}/custom-agents/reorder`,{method:"PATCH",body:JSON.stringify({items:t})})}async function sM(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 H$(e,t,n){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify(n)})}async function $$(e,t){await Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/${encodeURIComponent(t)}`,{method:"DELETE"})}async function G$(e,t){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/extract`,{method:"POST",body:JSON.stringify({sessionIds:t})})}async function pA(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/stats`)}async function Y$(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/consolidate`,{method:"POST"})}async function FE(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/sessions`)}async function oM(e){return Ia(await Te(`${nt(e)}/custom-agents`))}async function q$(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 lM(){return Ia(await Te("/api/prompt-fragments"))}async function K$(e){return Te("/api/prompt-fragments",{method:"POST",body:JSON.stringify(e)})}async function V$(e,t){return Te(`/api/prompt-fragments/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify(t)})}async function W$(e){await Te(`/api/prompt-fragments/${encodeURIComponent(e)}`,{method:"DELETE"})}async function gA(e){return Ia(await Te(`${nt(e)}/tags`))}async function bA(e,t){return Ia(await Te(`${nt(e)}/milestones`))}async function xA(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)),nM(await Te(`${nt(e)}/issues?${r}`),"issues")}async function X$(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 Z$(e,t,n){await Te(`${nt(e)}/issues/${t}/children`,{method:"POST",body:JSON.stringify({childNumber:n})})}async function uM(e,t,n){return Te(`${nt(e)}/issues/${t}`,{method:"PATCH",body:JSON.stringify(n)})}async function J$(e,t){return Ia(await Te(`${nt(e)}/issues/${t}/pulls`))}async function yA(e,t="open"){return Ia(await Te(`${nt(e)}/pulls?state=${encodeURIComponent(t)}`))}async function eG(e,t="all"){return Te(`${nt(e)}/pulls/sync`,{method:"POST",body:JSON.stringify({state:t})})}async function tG(e,t){return Te(`${nt(e)}/pulls/${t}`)}async function nG(e,t){await Te(`${nt(e)}/pulls/${t}/merge`,{method:"POST"})}async function zE(e,t){return Ia(await Te(`${nt(e)}/pulls/${t}/issues`))}async function rG(e,t,n){await Te(`${nt(e)}/pulls/${t}/issues`,{method:"POST",body:JSON.stringify({issueNumber:n})})}async function aG(e,t,n){await Te(`${nt(e)}/pulls/${t}/issues/${n}`,{method:"DELETE"})}async function iG(e,t){return Te(`${nt(e)}/pulls/${t}/comments`)}async function sG(e,t){return Te(`${nt(e)}/issues/${t}/comments`)}async function vA(e,t,n){return Te(`${nt(e)}/issues/${t}/comments`,{method:"POST",body:JSON.stringify({body:n})})}async function oG(e,t,n){return Te(`${nt(e)}/issues/${t}/polish`,{method:"POST",body:JSON.stringify({draft:n})})}async function EA(e,t){return Te(`${nt(e)}/issues/${t}/draft`)}async function lG(e,t,n){return Te(`${nt(e)}/issues/polish-create`,{method:"POST",body:JSON.stringify({title:t,body:n})})}async function NA(e){return Te(`${nt(e)}/issues/draft-create`)}async function uG(e){await Te(`${nt(e)}/issues/draft-create`,{method:"DELETE"})}async function cG(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({title:n})})}async function dG(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({completedAt:n})})}async function fG(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({pinnedAt:n})})}async function hG(){return Te("/api/agents-md")}async function mG(e){await Te("/api/agents-md",{method:"PUT",body:JSON.stringify({content:e})})}async function pG(e){return Te(`/api/repos/${encodeURIComponent(e)}/agents-md`)}async function gG(e,t){await Te(`/api/repos/${encodeURIComponent(e)}/agents-md`,{method:"PUT",body:JSON.stringify({content:t})})}function bG(e){return`${s0()}${nt(e)}/events`}async function xG(e){return Te(`${nt(e)}/sessions/status`)}async function jl(){return Te("/api/settings")}async function qp(e,t){await Te(`/api/settings/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify({value:t})})}async function Zv(){return Te("/api/cloud/status")}async function yG(){return Te("/api/cloud/reload",{method:"POST"})}async function vG(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 HE(){return Ia(await Te("/api/git-hosts"),"gitHosts")}async function EG(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 NG(e){await Te(`/api/git-hosts/${encodeURIComponent(e)}`,{method:"DELETE"})}async function $E(e){return Te(`/api/usage${e?`?provider=${encodeURIComponent(e)}`:""}`)}async function SG(e,t="callback"){return Te("/api/usage/oauth/authorize",{method:"POST",body:JSON.stringify({provider:e,method:t})})}async function wG(e,t,n="callback"){const r=n==="device"?"?method=device":"";return Te(`/api/usage/oauth/${encodeURIComponent(e)}/logins/${encodeURIComponent(t)}${r}`)}async function Ty(e,t,n="callback"){const r=n==="device"?"?method=device":"";await Te(`/api/usage/oauth/${encodeURIComponent(e)}/logins/${encodeURIComponent(t)}${r}`,{method:"DELETE"})}async function GE(e,t){return Te("/api/usage/switch",{method:"POST",body:JSON.stringify({accountId:e,...t?{provider:t}:{}})})}async function _G(){return Te("/api/usage/authorize",{method:"POST"})}async function TG(e,t){return Te("/api/usage/exchange",{method:"POST",body:JSON.stringify({pendingId:e,code:t})})}async function AG(e,t){let n;try{n=await fetch(`${s0()}/api/usage/accounts`,{method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify({provider:e,key:t})})}catch(a){throw new Qa(a instanceof Error?a.message:"Network request failed",0)}const r=await n.text();try{return JSON.parse(r)}catch(a){throw a instanceof SyntaxError?new Qa(r.trim()||`${n.status} ${n.statusText}`,n.status):a}}async function CG(e){await Te(`/api/usage/accounts/${encodeURIComponent(e)}`,{method:"DELETE"})}async function kG(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/files`)}function OG(e,t,n){return`${s0()}${nt(e)}/sessions/${encodeURIComponent(t)}/files/${n}`}async function Ay(e,t,n,r){const a=new URLSearchParams({from:String(e),to:String(t),groupBy:n});return Te(`/api/analytics/summary?${a}`)}const Jv=50,SA=20,IG=200,wA=1e3,Cy=2e3,_A=500,RG=5,MG=500,jG=5*1024*1024,TA=10,cM=4e3,DG=300,LG=2e3,PG=2e3,BG=300,UG=300,FG=500,zG=2e3,HG=30*6e4,AA=[{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 YE(e){const t=e.trim(),n=t.charCodeAt(0)||0;return{...AA[n%AA.length],initial:(t.charAt(0)||"?").toUpperCase()}}const CA=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},$G=(e=>e?CA(e):CA),GG=e=>e;function YG(e,t=GG){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 kA=e=>{const t=$G(e),n=r=>YG(t,r);return Object.assign(n,t),n},$i=(e=>e?kA(e):kA),OA="fs-nav-collapsed",IA="fs-session-panel-collapsed",ys=$i(e=>({navCollapsed:localStorage.getItem(OA)==="true",sessionPanelCollapsed:localStorage.getItem(IA)==="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(OA,String(n)),{navCollapsed:n}})},toggleSessionPanel(){e(t=>{const n=!t.sessionPanelCollapsed;return localStorage.setItem(IA,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 u$(),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 c$(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 m$(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},ky="fs-theme";function dM(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function RA(e){return e==="system"?dM():e}function MA(e){e==="system"?document.documentElement.removeAttribute("data-theme"):document.documentElement.setAttribute("data-theme",e)}const e1=$i((e,t)=>({preference:localStorage.getItem(ky)??"system",resolved:RA(localStorage.getItem(ky)??"system"),cycle(){const n=["system","light","dark"],r=n[(n.indexOf(t().preference)+1)%n.length],a=RA(r);localStorage.setItem(ky,r),MA(r),e({preference:r,resolved:a})},init(){MA(t().preference);const n=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>{const{preference:a}=t();if(a==="system"){const i=dM();e({resolved:i})}};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)}}));let fM=()=>{},hM=()=>{};function qG(e,t){fM=e,hM=t}function xl(e,t="info",n,r){fM(e,t,n,r)}function KG(e){hM(e)}let Oy=0;const sa=$i(e=>({agents:[],loaded:!1,loadAgents:async t=>{const n=++Oy;try{const r=t?await oM(t):await aM();if(Oy!==n)return;e({agents:r,loaded:!0})}catch(r){if(Oy!==n)return;e({loaded:!0});let a="加载 Agent 列表失败";if(r instanceof Qa)try{const i=JSON.parse(r.message);i.error&&(a=i.error)}catch{r.message&&(a=r.message)}xl(a,"error")}}}));let il=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:()=>{++il,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 Z$(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 uM(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=++il;try{const a=await xA(n,"all",{limit:wA});if(il!==r)return;e({issues:a.items,issueTotal:a.total,loaded:!0})}catch{if(il!==r)return;e({loaded:!0})}},syncIssues:async n=>{const r=++il;e({syncing:!0,syncError:null});try{await X$(n,"open");const[a,i,o]=await Promise.all([xA(n,"all",{limit:wA}),gA(n),bA(n)]);if(il!==r)return;e({issues:a.items,issueTotal:a.total,tags:i,milestones:o,syncing:!1})}catch(a){if(il!==r)return;let i="同步 Issue 失败";if(a instanceof Qa)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 gA(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 bA(n);e({milestones:r})}catch{}},setMilestoneFilter:n=>e({selectedMilestoneId:n})}));let sl=0;const pn=$i((e,t)=>({pulls:[],loaded:!1,syncing:!1,syncError:null,selectedPrId:null,viewingPrId:null,matchingPrId:null,matchingCandidateIssueId:null,clearPulls:()=>{++sl,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 rG(n,r,a),!0}catch{return!1}},unlinkIssue:async(n,r,a)=>{try{return await aG(n,r,a),!0}catch{return!1}},loadPulls:async n=>{const r=++sl;try{const a=await yA(n,"all");if(sl!==r)return;e({pulls:a,loaded:!0})}catch{if(sl!==r)return;e({loaded:!0})}},syncPulls:async n=>{const r=++sl;e({syncing:!0,syncError:null});try{await eG(n,"open");const a=await yA(n,"all");if(sl!==r)return;e({pulls:a,syncing:!1})}catch(a){if(sl!==r)return;let i="同步 PR 失败";if(a instanceof Qa)try{const o=JSON.parse(a.message);o.error&&(i=o.error)}catch{a.message&&(i=a.message)}e({syncing:!1,syncError:i})}}})),VG=new Set(["tool","tool-use","tool_use","tool-call","tool_call","tool-result","tool_result"]),WG=new Set(["thinking","reasoning","reason"]),XG=new Set(["text","output_text","message"]),QG=new Set(["file","image"]);function Kp(e){var n;const t=((n=e.type)==null?void 0:n.toLowerCase())??"";return VG.has(t)||e.toolName!=null||e.tool!=null?"tool":QG.has(t)?"file":WG.has(t)?"thinking":XG.has(t)||e.content!=null||e.text!=null?"text":"other"}function t1(e){return e.content??e.text??""}function mM(e){return e.toolName??e.tool??"tool"}function o0(e){var t;return e.input??((t=e.state)==null?void 0:t.input)}function qE(e){var t;return e.output??((t=e.state)==null?void 0:t.output)}function KE(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":qE(e)!=null?"completed":"running"}function jA(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 pM(e){return e.filter(t=>Dl(t.status)==="completed").length}function jf(e){const t=mM(e).toLowerCase();return t==="question"||t==="mcp_question"}function ZG(e){const t=o0(e);if(!t||typeof t!="object")return null;const n=t;return Array.isArray(n.questions)?n.questions:null}function Vp(e){if(!jf(e))return!1;const t=KE(e);return t==="pending"||t==="running"}const JG=/\bses_[a-zA-Z0-9]+/;function eY(e){var a;const t=o0(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=qE(e);if(typeof r=="string"){const i=JG.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 gM(e){return`question-${e}`}function Iy(e,t){const n=t.find(a=>a.id===e),r=(n==null?void 0:n.title)||e.slice(-8);xl(`${r} — 等待回复`,"warning",e,{id:gM(e),persistent:!0})}function tY(e){var t;for(const n of e)if((t=n.parts)!=null&&t.some(r=>jf(r)&&Vp(r)))return!0;return!1}const Df=[],Lf=[],DA=[],Bu={},Ry=new Set;function LA(e){return e.id??e.callID}async function PA(e,t,n){try{const[r,a]=await Promise.all([M$(e,t),rM(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 fG(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 dG(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([_$(n,{limit:IG}),rM(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 T$(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&&xl("已自动分配为处理人","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:SA}:void 0,[o,u]=await Promise.allSettled([j$(n,r),hA(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(v=>v.id===r?{...v,...d.session}:v))),u.status==="fulfilled"){let v=u.value.messages;if(f){const _=v.findIndex(S=>S.id===f);_>=0&&(v=v.slice(0,_+1))}const N=b.messages[r]??[];v.length>=N.length&&(x.messages={...b.messages,[r]:v}),x.messagesMeta={...b.messagesMeta,[r]:{total:Math.max(u.value.total,N.length),hasMore:u.value.hasMore,loading:!1}}}return x}),u.status==="fulfilled"&&tY(u.value.messages)&&Iy(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 hA(n,r,{limit:SA,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 D$(n,r,a,i),await PA(n,r,e),!0}catch{return!1}},removeLink:async(n,r,a,i)=>{try{return await L$(n,r,a,i),await PA(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 A$(n,u,r,d==null?void 0:d.agent,a,i,o),f&&(Bu[u]=(Bu[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 k$(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 O$(n,r)}catch{}},abortSession:async n=>{const r=t().activeSessionId;if(r){try{await C$(n,r)}catch{}t().setSessionStatus(r,"idle")}},clearSessions:()=>{++Zm;for(const n of Object.keys(Bu))delete Bu[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=Bu[n]||0;if(r.role==="user"&&b>0){const x=[...f[n]??[]];x.push(r.id),f={...f,[n]:x},Bu[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=>jf(i)&&Vp(i))&&Iy(n,t().sessions)},updateMessagePart:(n,r,a)=>{e(i=>{const o=i.messages[n]??[],u=o.findIndex(v=>v.id===r),d=u>=0?o[u]:{id:r,role:"assistant"},f=d.parts?[...d.parts]:[],m=LA(a),p=m!=null?f.findIndex(v=>LA(v)===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}}}),jf(a)&&Vp(a)&&Iy(n,t().sessions)},appendMessagePartDelta:(n,r,a,i)=>{e(o=>{const u=o.messages[n]??[],d=u.findIndex(v=>v.id===r),f=d>=0?u[d]:{id:r,role:"assistant"},m=f.parts?[...f.parts]:[],p=m.findIndex(v=>v.id===a);if(p>=0){const v=m[p],N=(v.content??v.text??"")+i;m[p]=v.content!=null?{...v,content:N}:{...v,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 Ry.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")KG(gM(n)),xl(`${u} — 完成`,"success",n);else if(r==="busy"&&(i===void 0||i==="idle"))xl(`${u} — 开始运行`,"info",n);else if(r==="retry")xl(`${u} — 进入重试`,"warning",n);else if(r==="error"){const d=a?`${u} — 错误: ${a}`:`${u} — 发生错误`;xl(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)=>{Ry.add(r),e(i=>({sessions:i.sessions.map(o=>o.id===r?{...o,title:a}:o)}));try{await cG(n,r,a)}catch{Ry.delete(r),await t().loadSessions(n)}},revertToMessage:async(n,r,a)=>{try{return await I$(n,r,a),await t().refreshSessionData(n,r),!0}catch{return!1}}})),Tl="__guide__",Bt=Date.now(),Sn=864e5,bM="guide-agent-",tc=`${bM}1`,VE="guide-session-run-1",nY={id:VE,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}}},xM=[{id:"guide-issue-1",repoId:Tl,number:42,title:"添加用户认证模块",body:"实现 JWT 认证,包括登录、注册和 token 刷新。",state:"open",labels:[{id:1,name:"feature",color:"0075ca"}],htmlUrl:"#",authorLogin:"demo-user",createdAt:Bt-Sn,updatedAt:Bt-36e5},{id:"guide-issue-2",repoId:Tl,number:41,title:"修复登录页样式错位",body:"移动端登录表单在小屏幕下溢出。",state:"closed",labels:[{id:2,name:"bug",color:"d73a4a"}],htmlUrl:"#",authorLogin:"demo-user",createdAt:Bt-2*Sn,updatedAt:Bt-Sn}],yM=[{id:"guide-pr-1",repoId:Tl,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-Sn,updatedAt:Bt-36e5,mergedAt:null},{id:"guide-pr-2",repoId:Tl,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*Sn,updatedAt:Bt-Sn,mergedAt:Bt-Sn}],rY=[{id:"guide-tag-1",repoId:Tl,name:"bug",color:"d73a4a",description:null,createdAt:Bt},{id:"guide-tag-2",repoId:Tl,name:"feature",color:"0075ca",description:null,createdAt:Bt},{id:"guide-tag-3",repoId:Tl,name:"priority",color:"e4e669",description:null,createdAt:Bt}],aY={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*Sn,updatedAt:Bt-Sn},iY=[{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*Sn},{content:"用户偏好 TypeScript strict 模式",importance:.75,category:"编码规范",action:"update",ts:Bt-3*Sn},{content:"用户偏好 TypeScript strict 模式,所有新文件必须启用 strictNullChecks",importance:.92,category:"编码规范",action:"reinforce",ts:Bt-Sn}],createdAt:Bt-7*Sn,updatedAt:Bt-Sn},{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*Sn},{content:"项目使用 Tailwind CSS 4 + zustand 状态管理,组件优先使用函数式写法",importance:.85,category:"技术栈",action:"merge",ts:Bt-2*Sn}],createdAt:Bt-5*Sn,updatedAt:Bt-2*Sn},{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*Sn},{content:"Git 提交信息使用 conventional commits 格式",importance:.45,category:"工作流",action:"decay",ts:Bt-4*Sn}],createdAt:Bt-10*Sn,updatedAt:Bt-4*Sn}];let Zt=null;function sY(e){Zt&&(e!=="dev"&&(Je.setState({issues:Zt.issues,tags:Zt.tags,loaded:Zt.issueLoaded,viewingIssueId:null,viewingTreeRootId:null}),pn.setState({pulls:Zt.pulls,loaded:Zt.prLoaded,viewingPrId:null})),e!=="agent"&&sa.setState({agents:Zt.agents}),e!=="run"&&Me.setState({sessions:Zt.sessions,activeSessionId:Zt.activeSessionId}))}function oY(e){if(!Zt){const t=Je.getState(),n=pn.getState(),r=sa.getState(),a=Me.getState();Zt={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(sY(e),e==="run"){const t=Zt.sessions.some(n=>n.id===VE);Me.setState({sessions:t?Zt.sessions:[...Zt.sessions,nY]})}else if(e==="dev")Je.setState({issues:xM,tags:rY,loaded:!0}),pn.setState({pulls:yM,loaded:!0});else if(e==="agent"){const t=Zt.agents.some(n=>n.id===tc);sa.setState({agents:t?Zt.agents:[...Zt.agents,aY]})}}function BA(){Zt&&(Je.setState({issues:Zt.issues,tags:Zt.tags,loaded:Zt.issueLoaded,viewingIssueId:null,viewingTreeRootId:null}),pn.setState({pulls:Zt.pulls,loaded:Zt.prLoaded,viewingPrId:null}),sa.setState({agents:Zt.agents}),Me.setState({sessions:Zt.sessions,activeSessionId:Zt.activeSessionId}),lY("id"),Zt=null)}function vM(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 lY(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 uY(){const e=xM[0].id;Je.setState({viewingIssueId:e}),vM("id",e)}function cY(){const e=yM[0].id;pn.setState({viewingPrId:e}),vM("id",e)}function dY(){Me.setState({activeSessionId:VE})}function fY(){Me.setState({activeSessionId:null})}function hY(){return tc}const n1=[{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 mY(e){return e?n1.filter(t=>t.section===e):n1}function EM(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 pY=6,UA=12,FA=200,zA=80,HA=288,$A=8,gY=768;function bY(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 xY(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 yY(e,t){const n={position:"fixed"},r=window.innerWidth,a=window.innerHeight,i=e.top+e.height+UA,o=e.top-UA;let u=t==="bottom-right"?e.left+e.width-HA:e.left;return u=Math.max($A,Math.min(u,r-HA-$A)),n.left=u,i+160<a?n.top=i:n.bottom=a-o,n}function My(e){const t=document.querySelector(e);t&&t.click()}const GA={selectMockIssue:uY,selectMockPr:cY,selectMockSession:dY,clearActiveSession:fY};function vY(){return window.innerWidth<gY}function EY({direction:e}){const t=e==="left"?sh:Io;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 NY({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(Et,{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 SY(){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?mY(r):n1,[n,r]),v=o<x.length?x[o]:void 0,N=x.length,_=o===0,S=o===N-1,C=y.useCallback(()=>{if(!n||!v)return;const L=v.padding??pY;f(bY(v.target,L))},[n,v]),A=y.useCallback(L=>{const B=L.replace("__MOCK_AGENT__",hY());return B.startsWith("/")?B:i?`/${encodeURIComponent(i)}/${B}`:`/${B}`},[i]);y.useEffect(()=>{n&&(u(0),p.current=-1)},[n]),y.useEffect(()=>{if(!n||!v)return;const L=p.current,B=L>=0?x[L]:null;B!=null&&B.triggerClick&&document.querySelector(B.target)&&My(B.triggerClick);const G=(B==null?void 0:B.mockScope)??null,re=v.mockScope??null;re&&re!==G?(oY(re),b.current=re):!re&&b.current&&(BA(),b.current=null);const X=v.route?A(v.route):null,K=X&&!t.pathname.startsWith(X);K&&e(X);const H=setTimeout(()=>{v.setupFn&&GA[v.setupFn]&&GA[v.setupFn](),setTimeout(()=>{v.triggerClick&&!document.querySelector(v.target)&&My(v.triggerClick),setTimeout(C,zA)},v.setupFn?FA:0)},K?FA:re&&re!==G?zA:0);return p.current=o,()=>clearTimeout(H)},[n,o,v,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)&&My(L.triggerClick),b.current&&(BA(),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||!v)return null;const j=vY()&&v.mobileSwipeHint&&!d;if(!d&&!j)return null;const U=()=>{_||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(EY,{direction:v.mobileSwipeHint}),c.jsx(NY,{step:v,stepIdx:o,total:N,isFirst:_,isLast:S,onPrev:U,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:xY(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:yY(d,v.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(Et,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:v.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:v.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:U,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 NM=[{segment:"run",icon:BE,label:"运行面板",global:!1},{segment:"dev/issues",icon:Az,label:"研发",global:!1,matchPrefix:"dev"},{segment:"agents",icon:rz,label:"Agents",global:!1}];function SM(e,t,n){return t?`/${e}`:n?`/${encodeURIComponent(n)}/${e}`:`/${e}`}function wM(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 wY(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function _Y({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(GR,{className:"h-3 w-3 shrink-0 text-fg-4"}),c.jsxs("span",{className:"truncate",children:[c.jsx("span",{className:"sm:hidden",children:f?wY(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(hi,{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(a0,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"管理仓库"})]})})]})]})}function TY({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),v=y.useCallback(()=>{a(!1),b(null)},[]);y.useEffect(()=>{if(!r)return;const S=C=>{x.current&&!x.current.contains(C.target)&&v()};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[r,v]);const N=async()=>{if(r){v();return}a(!0),d(!0),b(null);try{o(await b$(e))}catch{b("加载分支失败")}finally{d(!1)}},_=async S=>{if(!(S===t||f)){m(S),b(null);try{const C=await x$(e,S);n(e,C.branch),v()}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(Kl,{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($t,{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(hi,{className:"h-3 w-3 shrink-0"}):f===S?c.jsx($t,{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($t,{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 AY(){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.12.0-canary.5"&&t(i.latestVersion)}).catch(()=>{});n();const r=setInterval(n,HG),a=()=>n();return window.addEventListener("focus",a),()=>{clearInterval(r),window.removeEventListener("focus",a)}},[]),e}function CY({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(Dz,{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(ih,{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(a0,{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(EM(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(YR,{className:"h-3.5 w-3.5 text-fg-4"}),"功能引导"]})]})]})}function kY(){const e=zn(),t=or(),n=We(p=>p.repos),r=We(p=>p.activeRepoId),a=We(p=>p.setActiveRepo),i=e1(p=>p.preference),o=e1(p=>p.cycle),u=i==="light"?XH:i==="dark"?kH:AH,d=n.find(p=>p.id===r),f=AY(),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 v=((N=t.pathname.match(/\/(run|agents|issues|pulls)/))==null?void 0:N[1])??"run";e(`/${encodeURIComponent(b.name)}/${v}`)};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.12.0-canary.5"]}),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(_Y,{repos:n,activeRepoId:r,onRepoChange:m}),d&&r&&c.jsx(TY,{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(ih,{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(a0,{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(EM(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(YR,{className:"h-4 w-4"})})]}),c.jsx(CY,{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 OY(){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:NM.map(a=>{const i=wM(a,r.pathname,e);return c.jsxs($p,{to:SM(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($p,{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(a0,{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(pz,{className:"h-4 w-4"}):c.jsx(hz,{className:"h-4 w-4"})})]})}function IY(){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:NM.map(n=>{const r=wM(n,t.pathname,e);return c.jsx($p,{to:SM(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 RY(){return c.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-base text-fg",children:[c.jsx(kY,{}),c.jsxs("div",{className:"flex min-h-0 flex-1",children:[c.jsx(OY,{}),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(aF,{})})]}),c.jsx(IY,{}),c.jsx(SY,{})]})}let MY=0;const ar=$i(e=>({toasts:[],addToast:(t,n="info",r,a)=>{const i=(a==null?void 0:a.id)??`toast-${++MY}-${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)}))},cM)},removeToast:t=>{e(n=>({toasts:n.toasts.filter(r=>r.id!==t)}))}})),jY={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 YA(){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(v=>v.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))},DG))},[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=jY[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 ${cM}ms linear forwards`}})]})})},m.id)})})}const DY=1e3,LY=5e3,Jm="freeze-mon-buffer",PY=4*1024*1024;class BY{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(),DY),this.persistTimer=window.setInterval(()=>this.persist(),LY)}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<=PY);)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 BY;function UY(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 Vl(e){const t=ir(e);return t&&"properties"in t?t.properties:e}function FY(e){const t=ir(e);return typeof(t==null?void 0:t.type)=="string"?t.type:void 0}function zY(e){const t=ir(Vl(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 HY(e){const t=ir(Vl(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 _M(e){const t=ir(Vl(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 $Y(e){const t=Vl(e);if(Array.isArray(t))return t;const n=ir(t);return n&&Array.isArray(n.todos)?n.todos:[]}function _i(e){return typeof e=="number"?e:0}function GY(e){const t=ir(Vl(e));if(!t||typeof t.id!="string")return null;const n={id:t.id},r=typeof t.title=="string"?t.title:typeof t.name=="string"?t.name:void 0;r&&(n.title=r),typeof t.agent=="string"&&(n.agent=t.agent),typeof t.cost=="number"&&(n.cost=t.cost);const a=typeof t.parentID=="string"?t.parentID:typeof t.parent_id=="string"?t.parent_id:void 0;a&&(n.parentID=a);const i=ir(t.tokens),o=typeof t.tokens_input=="number"||typeof t.tokens_output=="number";if(i||o){const d=i?ir(i.cache):null;n.tokens={input:_i(i==null?void 0:i.input)||_i(t.tokens_input),output:_i(i==null?void 0:i.output)||_i(t.tokens_output),reasoning:_i(i==null?void 0:i.reasoning)||_i(t.tokens_reasoning),cache:{read:_i(d==null?void 0:d.read)||_i(t.tokens_cache_read),write:_i(d==null?void 0:d.write)||_i(t.tokens_cache_write)}}}const u=ir(t.model);return u&&(n.model={providerID:typeof u.providerID=="string"?u.providerID:void 0,modelID:typeof u.modelID=="string"?u.modelID:void 0,variant:typeof u.variant=="string"?u.variant:void 0}),n}function YY(e){const t=ir(Vl(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 qY(e){const t=Vl(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 qA(e,t,n,r){switch(e==="message"||e===""?FY(t)??e:e){case"message.updated":{const i=zY(t);i&&r.updateMessage(n,i);break}case"session.updated":{const i=GY(t);i&&r.updateSessionInfo(i);break}case"message.part.updated":{const{messageId:i,part:o}=HY(t);o&&i&&r.updateMessagePart(n,i,o);break}case"message.part.delta":{const i=_M(t);i&&r.appendMessagePartDelta(n,i.messageId,i.partId,i.delta);break}case"todo.updated":{r.updateTodos(n,$Y(t));break}case"session.status":{const i=qY(t);i&&r.setSessionStatus(n,i);break}case"session.idle":{r.setSessionStatus(n,"idle");break}case"session.error":{const i=YY(t);r.setSessionStatus(n,"error",i??void 0);break}}}const KY=1e3,VY=3e4;class WY{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=bG(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(KY*2**this.attempts,VY);this.attempts++,this.reconnectTimer=setTimeout(()=>this.connect(),a)}}}handleRaw(t,n){if(!(n instanceof MessageEvent))return;vs.tick("sse");const r=UY(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 XY=6e4;class QY{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()},XY)}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),xG(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 ZY=600*1e3,JY=200;class eq{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];qA(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()},JY))}cancelFlush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null)}bufferDelta(t){const n=_M(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)qA(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)},ZY))}clearIdleTimer(){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null)}}class tq{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 WY(t,(r,a,i)=>{this.ensureWorker(r,t,n).dispatch(a,i)}),this.dispatcher.start(),this.supervisor=new QY(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 eq(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 Wp=new tq;function Oc({onConfirm:e,size:t="sm",variant:n="ghost",triggerClassName:r,stopPropagation:a,title:i="删除",disabled:o=!1,children:u}){const[d,f]=y.useState(!1),m=t==="sm"?"h-3.5 w-3.5":"h-4 w-4",p=t==="sm"?"p-1":"p-1.5",b=n==="outlined"?"rounded-md":"rounded",x=t==="sm"?"gap-0.5":"gap-1",v=a?N=>N.stopPropagation():void 0;return d?c.jsxs("div",{className:ie("flex items-center",x),onClick:v,children:[c.jsx("button",{type:"button",onClick:()=>{e(),f(!1)},disabled:o,className:ie(b,p,"text-red-400 hover:bg-red-500/10",n==="outlined"&&"border border-red-500/30"),children:c.jsx(hi,{className:m})}),c.jsx("button",{type:"button",onClick:()=>f(!1),className:ie(b,p,"text-fg-4 hover:bg-elevated",n==="outlined"&&"border border-line"),children:c.jsx(Et,{className:m})})]}):c.jsxs(c.Fragment,{children:[u,c.jsx("button",{type:"button",onClick:N=>{v==null||v(N),f(!0)},title:i,disabled:o,className:ie(b,p,r??"text-fg-5 hover:text-red-400",n==="outlined"&&"border border-line transition-colors hover:border-red-500/30"),children:c.jsx(i0,{className:m})})]})}function nq(e,t){if(e instanceof Qa)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),v=y.useRef(e);v.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 v.current();if(x.current!==C)return;d(A)}catch(A){if(x.current!==C)return;const I=nq(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 rq=["Sisyphus - ultraworker","Prometheus - Plan Builder","Atlas - Plan Executor","Hephaestus - Deep Agent"],aq="pinned_models",ol="__system_prompt__",KA=[{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"}],iq={bg:"bg-elevated",text:"text-fg-4"};function TM(e){if(e==="general")return iq;let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return KA[Math.abs(t)%KA.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 AM={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 sq({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(Et,{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=AM[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 VA({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),v=TM(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",v.bg,v.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=AM[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(Oc,{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(PE,{className:"h-3.5 w-3.5"})})})})]}),b&&c.jsx(sq,{memory:e,onClose:()=>x(!1)})]})}const oq=14400*1e3;function lq(e){if(!e)return"下次:待定";const t=e+oq,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 uq({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:lq(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 cq({agentId:e}){const t=e.startsWith(bM),[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),[v,N]=y.useState(null),[_,S]=y.useState(!1),{data:C,loading:A,reload:I}=lc(()=>t?Promise.resolve(iY):sM(e,{includeSuperseded:a}),[e,a,t],{showErrorToast:!t,errorMessage:"加载记忆失败"}),O=C??[],k=y.useCallback(()=>{t||pA(e).then(N).catch(()=>N(null))},[e,t]);y.useEffect(()=>{k()},[k]);const j=async()=>{S(!0);try{await Y$(e)}catch{S(!1);return}const D=setInterval(()=>{pA(e).then(z=>{N(z),z.lastConsolidatedAt&&(!(v!=null&&v.lastConsolidatedAt)||z.lastConsolidatedAt>v.lastConsolidatedAt)&&(clearInterval(D),S(!1),I())}).catch(()=>{})},5e3);setTimeout(()=>{clearInterval(D),S(!1)},3e5)},{data:U,loading:P}=lc(()=>FE(e),[e,o],{skip:!o,errorMessage:"加载 Session 列表失败"}),L=U??[],B=O.filter(D=>!D.supersededBy),G=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 H$(e,D,z),await I()},V=async D=>{await $$(e,D),await I()},H=D=>{f(z=>{const $=new Set(z);return $.has(D)?$.delete(D):$.add(D),$})},q=async()=>{if(d.size!==0){p(!0),x(null);try{const $=(await G$(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:G.length})]})}),c.jsx(uq,{stats:v,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=TM(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($t,{className:"h-4 w-4 fs-spin text-fg-5"})}):G.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:[G.map(D=>c.jsx(VA,{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(VA,{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(r0,{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($t,{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 q(),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($t,{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 dq({agentId:e}){const{data:t,loading:n}=lc(()=>FE(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(r0,{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($t,{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 fq({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??""),[v,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),[U,P]=y.useState([]);y.useEffect(()=>{if(!r){P([]);return}let Q=!1;return(async()=>{try{const[D,z]=await Promise.all([jl(),kc(r)]);if(Q)return;const $=D[aq],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,ol),$}),G=Q=>{B(D=>{if(D.includes(Q))return D.filter(M=>M!==Q);const z=D.indexOf(ol),$=[...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!==ol),K=(()=>{const Q=L.indexOf(ol);return Q<0?-1:L.slice(0,Q).filter(D=>D!==ol).length})(),V=L.map(Q=>{var D;return Q===ol?C:(D=t.find(z=>z.id===Q))==null?void 0:D.content}).filter(Boolean).join(`
523
+ )`}function yY(e,t){const n={position:"fixed"},r=window.innerWidth,a=window.innerHeight,i=e.top+e.height+UA,o=e.top-UA;let u=t==="bottom-right"?e.left+e.width-HA:e.left;return u=Math.max($A,Math.min(u,r-HA-$A)),n.left=u,i+160<a?n.top=i:n.bottom=a-o,n}function My(e){const t=document.querySelector(e);t&&t.click()}const GA={selectMockIssue:uY,selectMockPr:cY,selectMockSession:dY,clearActiveSession:fY};function vY(){return window.innerWidth<gY}function EY({direction:e}){const t=e==="left"?sh:Io;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 NY({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(Et,{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 SY(){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?mY(r):n1,[n,r]),v=o<x.length?x[o]:void 0,N=x.length,_=o===0,S=o===N-1,C=y.useCallback(()=>{if(!n||!v)return;const L=v.padding??pY;f(bY(v.target,L))},[n,v]),A=y.useCallback(L=>{const B=L.replace("__MOCK_AGENT__",hY());return B.startsWith("/")?B:i?`/${encodeURIComponent(i)}/${B}`:`/${B}`},[i]);y.useEffect(()=>{n&&(u(0),p.current=-1)},[n]),y.useEffect(()=>{if(!n||!v)return;const L=p.current,B=L>=0?x[L]:null;B!=null&&B.triggerClick&&document.querySelector(B.target)&&My(B.triggerClick);const G=(B==null?void 0:B.mockScope)??null,re=v.mockScope??null;re&&re!==G?(oY(re),b.current=re):!re&&b.current&&(BA(),b.current=null);const X=v.route?A(v.route):null,K=X&&!t.pathname.startsWith(X);K&&e(X);const H=setTimeout(()=>{v.setupFn&&GA[v.setupFn]&&GA[v.setupFn](),setTimeout(()=>{v.triggerClick&&!document.querySelector(v.target)&&My(v.triggerClick),setTimeout(C,zA)},v.setupFn?FA:0)},K?FA:re&&re!==G?zA:0);return p.current=o,()=>clearTimeout(H)},[n,o,v,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)&&My(L.triggerClick),b.current&&(BA(),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||!v)return null;const j=vY()&&v.mobileSwipeHint&&!d;if(!d&&!j)return null;const U=()=>{_||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(EY,{direction:v.mobileSwipeHint}),c.jsx(NY,{step:v,stepIdx:o,total:N,isFirst:_,isLast:S,onPrev:U,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:xY(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:yY(d,v.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(Et,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:v.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:v.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:U,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 NM=[{segment:"run",icon:BE,label:"运行面板",global:!1},{segment:"dev/issues",icon:Az,label:"研发",global:!1,matchPrefix:"dev"},{segment:"agents",icon:rz,label:"Agents",global:!1}];function SM(e,t,n){return t?`/${e}`:n?`/${encodeURIComponent(n)}/${e}`:`/${e}`}function wM(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 wY(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function _Y({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(GR,{className:"h-3 w-3 shrink-0 text-fg-4"}),c.jsxs("span",{className:"truncate",children:[c.jsx("span",{className:"sm:hidden",children:f?wY(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(hi,{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(a0,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"管理仓库"})]})})]})]})}function TY({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),v=y.useCallback(()=>{a(!1),b(null)},[]);y.useEffect(()=>{if(!r)return;const S=C=>{x.current&&!x.current.contains(C.target)&&v()};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[r,v]);const N=async()=>{if(r){v();return}a(!0),d(!0),b(null);try{o(await b$(e))}catch{b("加载分支失败")}finally{d(!1)}},_=async S=>{if(!(S===t||f)){m(S),b(null);try{const C=await x$(e,S);n(e,C.branch),v()}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(Kl,{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($t,{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(hi,{className:"h-3 w-3 shrink-0"}):f===S?c.jsx($t,{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($t,{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 AY(){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.12.0"&&t(i.latestVersion)}).catch(()=>{});n();const r=setInterval(n,HG),a=()=>n();return window.addEventListener("focus",a),()=>{clearInterval(r),window.removeEventListener("focus",a)}},[]),e}function CY({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(Dz,{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(ih,{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(a0,{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(EM(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(YR,{className:"h-3.5 w-3.5 text-fg-4"}),"功能引导"]})]})]})}function kY(){const e=zn(),t=or(),n=We(p=>p.repos),r=We(p=>p.activeRepoId),a=We(p=>p.setActiveRepo),i=e1(p=>p.preference),o=e1(p=>p.cycle),u=i==="light"?XH:i==="dark"?kH:AH,d=n.find(p=>p.id===r),f=AY(),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 v=((N=t.pathname.match(/\/(run|agents|issues|pulls)/))==null?void 0:N[1])??"run";e(`/${encodeURIComponent(b.name)}/${v}`)};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.12.0"]}),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(_Y,{repos:n,activeRepoId:r,onRepoChange:m}),d&&r&&c.jsx(TY,{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(ih,{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(a0,{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(EM(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(YR,{className:"h-4 w-4"})})]}),c.jsx(CY,{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 OY(){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:NM.map(a=>{const i=wM(a,r.pathname,e);return c.jsxs($p,{to:SM(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($p,{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(a0,{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(pz,{className:"h-4 w-4"}):c.jsx(hz,{className:"h-4 w-4"})})]})}function IY(){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:NM.map(n=>{const r=wM(n,t.pathname,e);return c.jsx($p,{to:SM(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 RY(){return c.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-base text-fg",children:[c.jsx(kY,{}),c.jsxs("div",{className:"flex min-h-0 flex-1",children:[c.jsx(OY,{}),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(aF,{})})]}),c.jsx(IY,{}),c.jsx(SY,{})]})}let MY=0;const ar=$i(e=>({toasts:[],addToast:(t,n="info",r,a)=>{const i=(a==null?void 0:a.id)??`toast-${++MY}-${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)}))},cM)},removeToast:t=>{e(n=>({toasts:n.toasts.filter(r=>r.id!==t)}))}})),jY={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 YA(){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(v=>v.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))},DG))},[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=jY[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 ${cM}ms linear forwards`}})]})})},m.id)})})}const DY=1e3,LY=5e3,Jm="freeze-mon-buffer",PY=4*1024*1024;class BY{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(),DY),this.persistTimer=window.setInterval(()=>this.persist(),LY)}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<=PY);)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 BY;function UY(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 Vl(e){const t=ir(e);return t&&"properties"in t?t.properties:e}function FY(e){const t=ir(e);return typeof(t==null?void 0:t.type)=="string"?t.type:void 0}function zY(e){const t=ir(Vl(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 HY(e){const t=ir(Vl(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 _M(e){const t=ir(Vl(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 $Y(e){const t=Vl(e);if(Array.isArray(t))return t;const n=ir(t);return n&&Array.isArray(n.todos)?n.todos:[]}function _i(e){return typeof e=="number"?e:0}function GY(e){const t=ir(Vl(e));if(!t||typeof t.id!="string")return null;const n={id:t.id},r=typeof t.title=="string"?t.title:typeof t.name=="string"?t.name:void 0;r&&(n.title=r),typeof t.agent=="string"&&(n.agent=t.agent),typeof t.cost=="number"&&(n.cost=t.cost);const a=typeof t.parentID=="string"?t.parentID:typeof t.parent_id=="string"?t.parent_id:void 0;a&&(n.parentID=a);const i=ir(t.tokens),o=typeof t.tokens_input=="number"||typeof t.tokens_output=="number";if(i||o){const d=i?ir(i.cache):null;n.tokens={input:_i(i==null?void 0:i.input)||_i(t.tokens_input),output:_i(i==null?void 0:i.output)||_i(t.tokens_output),reasoning:_i(i==null?void 0:i.reasoning)||_i(t.tokens_reasoning),cache:{read:_i(d==null?void 0:d.read)||_i(t.tokens_cache_read),write:_i(d==null?void 0:d.write)||_i(t.tokens_cache_write)}}}const u=ir(t.model);return u&&(n.model={providerID:typeof u.providerID=="string"?u.providerID:void 0,modelID:typeof u.modelID=="string"?u.modelID:void 0,variant:typeof u.variant=="string"?u.variant:void 0}),n}function YY(e){const t=ir(Vl(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 qY(e){const t=Vl(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 qA(e,t,n,r){switch(e==="message"||e===""?FY(t)??e:e){case"message.updated":{const i=zY(t);i&&r.updateMessage(n,i);break}case"session.updated":{const i=GY(t);i&&r.updateSessionInfo(i);break}case"message.part.updated":{const{messageId:i,part:o}=HY(t);o&&i&&r.updateMessagePart(n,i,o);break}case"message.part.delta":{const i=_M(t);i&&r.appendMessagePartDelta(n,i.messageId,i.partId,i.delta);break}case"todo.updated":{r.updateTodos(n,$Y(t));break}case"session.status":{const i=qY(t);i&&r.setSessionStatus(n,i);break}case"session.idle":{r.setSessionStatus(n,"idle");break}case"session.error":{const i=YY(t);r.setSessionStatus(n,"error",i??void 0);break}}}const KY=1e3,VY=3e4;class WY{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=bG(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(KY*2**this.attempts,VY);this.attempts++,this.reconnectTimer=setTimeout(()=>this.connect(),a)}}}handleRaw(t,n){if(!(n instanceof MessageEvent))return;vs.tick("sse");const r=UY(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 XY=6e4;class QY{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()},XY)}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),xG(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 ZY=600*1e3,JY=200;class eq{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];qA(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()},JY))}cancelFlush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null)}bufferDelta(t){const n=_M(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)qA(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)},ZY))}clearIdleTimer(){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null)}}class tq{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 WY(t,(r,a,i)=>{this.ensureWorker(r,t,n).dispatch(a,i)}),this.dispatcher.start(),this.supervisor=new QY(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 eq(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 Wp=new tq;function Oc({onConfirm:e,size:t="sm",variant:n="ghost",triggerClassName:r,stopPropagation:a,title:i="删除",disabled:o=!1,children:u}){const[d,f]=y.useState(!1),m=t==="sm"?"h-3.5 w-3.5":"h-4 w-4",p=t==="sm"?"p-1":"p-1.5",b=n==="outlined"?"rounded-md":"rounded",x=t==="sm"?"gap-0.5":"gap-1",v=a?N=>N.stopPropagation():void 0;return d?c.jsxs("div",{className:ie("flex items-center",x),onClick:v,children:[c.jsx("button",{type:"button",onClick:()=>{e(),f(!1)},disabled:o,className:ie(b,p,"text-red-400 hover:bg-red-500/10",n==="outlined"&&"border border-red-500/30"),children:c.jsx(hi,{className:m})}),c.jsx("button",{type:"button",onClick:()=>f(!1),className:ie(b,p,"text-fg-4 hover:bg-elevated",n==="outlined"&&"border border-line"),children:c.jsx(Et,{className:m})})]}):c.jsxs(c.Fragment,{children:[u,c.jsx("button",{type:"button",onClick:N=>{v==null||v(N),f(!0)},title:i,disabled:o,className:ie(b,p,r??"text-fg-5 hover:text-red-400",n==="outlined"&&"border border-line transition-colors hover:border-red-500/30"),children:c.jsx(i0,{className:m})})]})}function nq(e,t){if(e instanceof Qa)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),v=y.useRef(e);v.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 v.current();if(x.current!==C)return;d(A)}catch(A){if(x.current!==C)return;const I=nq(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 rq=["Sisyphus - ultraworker","Prometheus - Plan Builder","Atlas - Plan Executor","Hephaestus - Deep Agent"],aq="pinned_models",ol="__system_prompt__",KA=[{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"}],iq={bg:"bg-elevated",text:"text-fg-4"};function TM(e){if(e==="general")return iq;let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return KA[Math.abs(t)%KA.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 AM={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 sq({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(Et,{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=AM[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 VA({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),v=TM(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",v.bg,v.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=AM[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(Oc,{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(PE,{className:"h-3.5 w-3.5"})})})})]}),b&&c.jsx(sq,{memory:e,onClose:()=>x(!1)})]})}const oq=14400*1e3;function lq(e){if(!e)return"下次:待定";const t=e+oq,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 uq({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:lq(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 cq({agentId:e}){const t=e.startsWith(bM),[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),[v,N]=y.useState(null),[_,S]=y.useState(!1),{data:C,loading:A,reload:I}=lc(()=>t?Promise.resolve(iY):sM(e,{includeSuperseded:a}),[e,a,t],{showErrorToast:!t,errorMessage:"加载记忆失败"}),O=C??[],k=y.useCallback(()=>{t||pA(e).then(N).catch(()=>N(null))},[e,t]);y.useEffect(()=>{k()},[k]);const j=async()=>{S(!0);try{await Y$(e)}catch{S(!1);return}const D=setInterval(()=>{pA(e).then(z=>{N(z),z.lastConsolidatedAt&&(!(v!=null&&v.lastConsolidatedAt)||z.lastConsolidatedAt>v.lastConsolidatedAt)&&(clearInterval(D),S(!1),I())}).catch(()=>{})},5e3);setTimeout(()=>{clearInterval(D),S(!1)},3e5)},{data:U,loading:P}=lc(()=>FE(e),[e,o],{skip:!o,errorMessage:"加载 Session 列表失败"}),L=U??[],B=O.filter(D=>!D.supersededBy),G=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 H$(e,D,z),await I()},V=async D=>{await $$(e,D),await I()},H=D=>{f(z=>{const $=new Set(z);return $.has(D)?$.delete(D):$.add(D),$})},q=async()=>{if(d.size!==0){p(!0),x(null);try{const $=(await G$(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:G.length})]})}),c.jsx(uq,{stats:v,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=TM(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($t,{className:"h-4 w-4 fs-spin text-fg-5"})}):G.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:[G.map(D=>c.jsx(VA,{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(VA,{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(r0,{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($t,{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 q(),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($t,{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 dq({agentId:e}){const{data:t,loading:n}=lc(()=>FE(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(r0,{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($t,{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 fq({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??""),[v,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),[U,P]=y.useState([]);y.useEffect(()=>{if(!r){P([]);return}let Q=!1;return(async()=>{try{const[D,z]=await Promise.all([jl(),kc(r)]);if(Q)return;const $=D[aq],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,ol),$}),G=Q=>{B(D=>{if(D.includes(Q))return D.filter(M=>M!==Q);const z=D.indexOf(ol),$=[...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!==ol),K=(()=>{const Q=L.indexOf(ol);return Q<0?-1:L.slice(0,Q).filter(D=>D!==ol).length})(),V=L.map(Q=>{var D;return Q===ol?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,v,N,_){return f(m(x,N,_),x.align)}function u(x,v,N,_){const S=p(x,N,_),C=f([S]);return C.slice(0,C.indexOf(`
650
650
  `))}function d(x,v,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,v){return n1e(x,{align:v,alignDelimiters:r,padding:n,stringLength:a})}function m(x,v,N){const _=x.children;let S=-1;const C=[],A=v.enter("table");for(;++S<_.length;)C[S]=p(_[S],v,N);return A(),C}function p(x,v,N){const _=x.children;let S=-1;const C=[],A=v.enter("tableRow");for(;++S<_.length;)C[S]=d(_[S],x,v,N);return A(),C}function b(x,v,N){let _=F8.inlineCode(x,v,N);return N.stack.includes("tableCell")&&(_=_.replace(/\|/g,"\\$&")),_}}function $1e(){return{exit:{taskListCheckValueChecked:NI,taskListCheckValueUnchecked:NI,paragraph:Y1e}}}function G1e(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:q1e}}}function NI(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function Y1e(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 q1e(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=F8.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 K1e(){return[_ve(),qve(),Xve(),L1e(),$1e()]}function V1e(e){return{extensions:[Tve(),Kve(e),Qve(),H1e(e),G1e()]}}const W1e={tokenize:tEe,partial:!0},z8={tokenize:nEe,partial:!0},H8={tokenize:rEe,partial:!0},$8={tokenize:aEe,partial:!0},X1e={tokenize:iEe,partial:!0},G8={name:"wwwAutolink",tokenize:J1e,previous:q8},Y8={name:"protocolAutolink",tokenize:eEe,previous:K8},Bs={name:"emailAutolink",tokenize:Z1e,previous:V8},Yi={};function Q1e(){return{text:Yi}}let hl=48;for(;hl<123;)Yi[hl]=Bs,hl++,hl===58?hl=65:hl===91&&(hl=97);Yi[43]=Bs;Yi[45]=Bs;Yi[46]=Bs;Yi[95]=Bs;Yi[72]=[Bs,Y8];Yi[104]=[Bs,Y8];Yi[87]=[Bs,G8];Yi[119]=[Bs,G8];function Z1e(e,t,n){const r=this;let a,i;return o;function o(p){return!fE(p)||!V8.call(r,r.previous)||lw(r.events)?n(p):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),u(p))}function u(p){return fE(p)?(e.consume(p),u):p===64?(e.consume(p),d):n(p)}function d(p){return p===46?e.check(X1e,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 J1e(e,t,n){const r=this;return a;function a(o){return o!==87&&o!==119||!q8.call(r,r.previous)||lw(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(W1e,e.attempt(z8,e.attempt(H8,i),n),n)(o))}function i(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function eEe(e,t,n){const r=this;let a="",i=!1;return o;function o(p){return(p===72||p===104)&&K8.call(r,r.previous)&&!lw(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||$g(p)||en(p)||$l(p)||rb(p)?n(p):e.attempt(z8,e.attempt(H8,m),n)(p)}function m(p){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(p)}}function tEe(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 nEe(e,t,n){let r,a,i;return o;function o(f){return f===46||f===95?e.check($8,d,u)(f):f===null||en(f)||$l(f)||f!==45&&rb(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 rEe(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($8,t,i)(o):o===null||en(o)||$l(o)?t(o):(e.consume(o),a)}function i(o){return o===41&&r++,e.consume(o),a}}function aEe(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||en(u)||$l(u)?t(u):n(u)}function a(u){return u===null||u===40||u===91||en(u)||$l(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 iEe(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||en(e)}function K8(e){return!Hr(e)}function V8(e){return!(e===47||fE(e))}function fE(e){return e===43||e===45||e===46||e===95||Or(e)}function lw(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 sEe={tokenize:mEe,partial:!0};function oEe(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:dEe,continuation:{tokenize:fEe},exit:hEe}},text:{91:{name:"gfmFootnoteCall",tokenize:cEe},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:lEe,resolveTo:uEe}}}}function lEe(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=fi(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 uEe(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 cEe(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||en(p))return n(p);if(p===93){e.exit("chunkString");const b=e.exit("gfmFootnoteCallString");return a.includes(fi(r.sliceSerialize(b)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(p)}return en(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 dEe(e,t,n){const r=this,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i,o=0,u;return d;function d(v){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(v),e.exit("gfmFootnoteDefinitionLabelMarker"),f}function f(v){return v===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(v),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",m):n(v)}function m(v){if(o>999||v===93&&!u||v===null||v===91||en(v))return n(v);if(v===93){e.exit("chunkString");const N=e.exit("gfmFootnoteDefinitionLabelString");return i=fi(r.sliceSerialize(N)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(v),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),b}return en(v)||(u=!0),o++,e.consume(v),v===92?p:m}function p(v){return v===91||v===92||v===93?(e.consume(v),o++,m):m(v)}function b(v){return v===58?(e.enter("definitionMarker"),e.consume(v),e.exit("definitionMarker"),a.includes(i)||a.push(i),At(e,x,"gfmFootnoteDefinitionWhitespace")):n(v)}function x(v){return t(v)}}function fEe(e,t,n){return e.check(Oh,t,e.attempt(sEe,t,n))}function hEe(e){e.exit("gfmFootnoteDefinition")}function mEe(e,t,n){const r=this;return At(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 pEe(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,ab(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(v){return f===126&&m[m.length-1][1].type!=="characterEscape"?d(v):(o.enter("strikethroughSequenceTemporary"),x(v))}function x(v){const N=vc(f);if(v===126)return p>1?d(v):(o.consume(v),p++,x);if(p<2&&!n)return d(v);const _=o.exit("strikethroughSequenceTemporary"),S=vc(v);return _._open=!S||S===2&&!!N,_._close=!N||N===2&&!!S,u(v)}}}class gEe{constructor(){this.map=[]}add(t,n,r){bEe(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 bEe(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 xEe(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 yEe(){return{flow:{null:{name:"table",tokenize:vEe,resolveAll:EEe}}}}function vEe(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 G=B>-1?r.events[B][1].type:null,re=G==="tableHead"||G==="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)?At(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||en(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)?At(e,v,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(L):v(L))}function v(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)?At(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)?At(e,I,"whitespace")(L):I(L)}function I(L){return L===124?v(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)?At(e,j,"whitespace")(L):(e.enter("data"),U(L))}function U(L){return L===null||L===124||en(L)?(e.exit("data"),j(L)):(e.consume(L),L===92?P:U)}function P(L){return L===92||L===124?(e.consume(L),U):U(L)}}function EEe(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 gEe;for(;++n<e.length;){const x=e[n],v=x[1];x[0]==="enter"?v.type==="tableHead"?(u=!1,d!==0&&(SI(b,t,d,f,m),m=void 0,d=0),f={type:"table",start:Object.assign({},v.start),end:Object.assign({},v.end)},b.add(n,0,[["enter",f,t]])):v.type==="tableRow"||v.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({},v.start),end:Object.assign({},v.end)},b.add(n,0,[["enter",m,t]])),a=v.type==="tableDelimiterRow"?2:m?3:1):a&&(v.type==="data"||v.type==="tableDelimiterMarker"||v.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)):v.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])):v.type==="tableHead"?(u=!0,d=n):v.type==="tableRow"||v.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&&(v.type==="data"||v.type==="tableDelimiterMarker"||v.type==="tableDelimiterFiller")&&(o[3]=n)}for(d!==0&&SI(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=xEe(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({},Xu(t.events,n[0])),e.add(n[0],0,[["exit",i,t]]));const d=Xu(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=Xu(t.events,n[2]),m=Xu(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 v=n[2]+1,N=n[3]-n[2]-1;e.add(v,N,[])}}e.add(n[3]+1,0,[["exit",p,t]])}return a!==void 0&&(i.end=Object.assign({},Xu(t.events,a)),e.add(a,0,[["exit",i,t]]),i=void 0),i}function SI(e,t,n,r,a){const i=[],o=Xu(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 Xu(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const NEe={name:"tasklistCheck",tokenize:wEe};function SEe(){return{text:{91:NEe}}}function wEe(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 en(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:_Ee},t,n)(d):n(d)}}function _Ee(e,t,n){return At(e,r,"whitespace");function r(a){return a===null?n(a):t(a)}}function TEe(e){return NP([Q1e(),oEe(),pEe(e),yEe(),SEe()])}const AEe={};function Yl(e){const t=this,n=e||AEe,r=t.data(),a=r.micromarkExtensions||(r.micromarkExtensions=[]),i=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);a.push(TEe(n)),i.push(K1e()),o.push(V1e(n))}function uw(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 W8(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 X8(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 CEe(e){return e==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"}function kEe({repoId:e,issueNumber:t,onPublished:n}){const[r,a]=y.useState(""),[i,o]=y.useState(!1),u=y.useRef(null),d=y.useCallback(()=>oG(e,t,r.trim()),[e,t,r]),f=y.useCallback(()=>EA(e,t).then(O=>O.body),[e,t]),m=y.useCallback(()=>EA(e,t).then(O=>O.body||null),[e,t]),{phase:p,result:b,busy:x,setBusy:v,polish:N,discard:_,escalate:S,setResult:C}=sP({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)){v(!0);try{const O=await vA(e,t,r.trim());n(O),a(""),ar.getState().addToast("评论已发布","success")}catch(O){ar.getState().addToast(O instanceof Error?O.message:"发布失败","error")}finally{v(!1)}}},I=async()=>{if(!(!(b!=null&&b.trim())||x)){v(!0);try{const O=await vA(e,t,b.trim());n(O),a(""),_(),ar.getState().addToast("评论已发布","success")}catch(O){ar.getState().addToast(O instanceof Error?O.message:"发布失败","error")}finally{v(!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(Co,{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(Mf,{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(ME,{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(Co,{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(Mf,{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(Co,{className:"h-3.5 w-3.5"}),p==="polishing"?"润色中...":"AI 润色"]})]})]})}function Q8({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),v=Je(S=>S.updateIssueState);y.useEffect(()=>{o&&(p(!0),sG(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(sh,{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(jE,{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(VR,{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(Kl,{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 v(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(qR,{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(BE,{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(ZR,{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(Et,{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(Gl,{remarkPlugins:[Yl],rehypePlugins:[Vg],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:W8(S.created_at)})]}),c.jsx("div",{className:"markdown-body mt-2 text-sm leading-relaxed text-fg-3",children:c.jsx(Gl,{remarkPlugins:[Yl],rehypePlugins:[Vg],children:S.body})})]},S.id))})]}),o&&c.jsx(kEe,{repoId:o,issueNumber:e.number,onPublished:S=>f(C=>[...C,S])},e.id)]})})]})}function OEe({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(Ml,{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",X8(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(ln,{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 Z8({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,v]=y.useState([]),[N,_]=y.useState(!1),S=zn(),C=pn(j=>j.unlinkIssue);y.useEffect(()=>{i&&(b(!0),iG(i,e.number).then(m).catch(()=>m([])).finally(()=>b(!1)))},[i,e.number]),y.useEffect(()=>{i&&zE(i,e.number).then(v).catch(()=>v([]))},[i,e.number]);const A=async j=>{if(!(u||!i)){d(!0);try{if(await nG(i,e.number),j&&x.length>0){const U=x.filter(P=>P.state==="open");await Promise.all(U.map(P=>uM(i,P.number,{state:"closed"}))),v(P=>P.map(L=>L.state==="open"?{...L,state:"closed"}:L)),Je.getState().loadIssues(i),ar.getState().addToast(`PR #${e.number} 合入成功,已关闭 ${U.length} 个 Issue`,"success")}else ar.getState().addToast(`PR #${e.number} 合入成功`,"success");pn.getState().loadPulls(i)}catch(U){let P="合入失败";if(U instanceof Qa)try{P=JSON.parse(U.message).error??P}catch{P=U.message}ar.getState().addToast(P,"error")}finally{d(!1)}}},I=async j=>{if(!i)return;await C(i,e.number,j)&&v(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(sh,{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",X8(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(Ml,{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:["合并于 ",uw(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(VR,{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(DE,{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(a$,{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(cA,{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(cA,{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(Et,{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(qR,{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(Wz,{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(Ro,{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(Yr,{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(_H,{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(Io,{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(Gl,{remarkPlugins:[Yl],rehypePlugins:[Vg],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:W8(j.created_at)})]}),c.jsx("div",{className:"markdown-body mt-2 text-sm leading-relaxed text-fg-3",children:c.jsx(Gl,{remarkPlugins:[Yl],rehypePlugins:[Vg],children:j.body})})]},j.id))})]})]})})]})}function IEe({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=pn(A=>A.enterMatchMode),[b,x]=y.useState([]),[v,N]=y.useState(null),[_,S]=y.useState(!1);y.useEffect(()=>{if(!m){x([]);return}J$(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),tG(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(Ml,{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(ln,{className:"inline h-3 w-3 -mt-px"})," Conflict"]})]})]}),n==="issue"||b.length===0?c.jsx(Q8,{issue:e,milestone:t,onBack:u,onClose:d,onToggleSidebar:f}):r!=null?v?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(Rf,{className:"h-3.5 w-3.5"}),"返回列表"]})}),c.jsx(Z8,{pr:v,onBack:o,onEnterMatch:()=>p(v.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(OEe,{prs:b,onSelect:i})})})]})}const J8=[{key:"open",label:"开放"},{key:"closed",label:"已关闭"},{key:"all",label:"全部"}];function REe({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:v,closedCount:N,totalCount:_,epicCount:S,taskCount:C,strayCount:A,afterStateCount:I,uniqueAuthors:O,uniqueAssignees:k}){const j=Je(H=>H.syncing),U=Je(H=>H.syncIssues),P=Je(H=>H.tags),L=Je(H=>H.tagFilterMode),B=Je(H=>H.cycleTagFilter),G=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 U(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(Mo,{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(Yr,{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:J8.map(({key:H,label:q})=>{const Q=H==="open"?v: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:[q,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(Et,{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(q=>q.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 q=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:[q,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 q=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",q==="include"?"ring-1 ring-current shadow-sm":q==="exclude"?"opacity-90 line-through decoration-2":"opacity-50 hover:opacity-80"),style:q==="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:q==="include"?`inset 0 0 0 1px color-mix(in srgb, #${H.color} 50%, transparent)`:void 0},children:[q==="exclude"&&c.jsx("span",{className:"mr-1 text-[10px]",children:"✕"}),H.name]},H.id)}),L.size>0&&c.jsx("button",{type:"button",onClick:G,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 q=X===H.id;return c.jsxs("button",{type:"button",onClick:()=>K(q?null:H.id),className:ie("shrink-0 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",q?"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 MEe({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(jE,{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 wI=y.memo(MEe,(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 jEe({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(jE,{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:uw(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(bH,{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 DEe=y.memo(jEe,(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 LEe(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 _I({session:e,onSelect:t}){var r,a;const n=LEe(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 eB({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(IE,{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(_I,{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(_I,{session:o,onSelect:()=>t(o.id)},o.id))})]})]})})]})}function PEe({sessions:e,onSessionSelect:t}){return c.jsx("div",{className:"flex w-full flex-col",children:c.jsx(eB,{sessions:e,onSelect:t})})}function tB({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(tB,{issue:u,childrenMap:t,currentId:n,onSelect:r,depth:a+1},u.id))]})]})}function BEe(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 UEe({rootIssue:e,childrenMap:t,currentId:n,onSelect:r,sessions:a,onSessionSelect:i}){const{total:o,closed:u}=BEe(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(IH,{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(tB,{issue:e,childrenMap:t,currentId:n,onSelect:r,depth:0})})]}),c.jsx(eB,{sessions:a,onSelect:i})]})}function TI({total:e,page:t,pageSize:n=Jv,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(sh,{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(Io,{className:"h-4 w-4"})})]})]})}function hE({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 FEe({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:v,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 G=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"&&!G.has(V)||K==="exclude"&&G.has(V)))return!1}return!0}),k=o.trim().toLowerCase(),j=k?O.filter(B=>`#${B.number} ${B.title}`.toLowerCase().includes(k)):O,U=u?j.filter(B=>B.milestoneId===u):j,P=d?U.filter(B=>B.authorLogin===d):U,L=f?P.filter(B=>(B.assignees??[]).some(G=>G.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:v.filter(A=>b(A)==="epic").length,task:v.filter(A=>b(A)==="task").length,stray:v.filter(A=>b(A)==="stray").length,afterState:v.length}),[e,v,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:v,finalFiltered:N,counts:_,uniqueAuthors:S,uniqueAssignees:C}}const AI=8;function zEe(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 nB({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||zEe(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)>AI||Math.abs(b)>AI)&&(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 HEe(){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),[v,N]=y.useState(null),[_,S]=y.useState(null),[C,A]=y.useState(null),[I,O]=y.useState(0),[k,j]=OE(),U=Je(ee=>ee.issues),P=Je(ee=>ee.loaded),L=Je(ee=>ee.syncing),B=Je(ee=>ee.syncIssues),G=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),q=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]),je=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(()=>{q&&(X(q),H(q))},[q,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:un,uniqueAssignees:In}=FEe({issues:U,tags:G,milestones:K,tagFilterMode:re,stateFilter:e,typeFilter:n,searchQuery:o,selectedMilestoneId:V,selectedAuthor:_,selectedAssignee:C}),fr=y.useMemo(()=>{const ee=I*Jv;return Be.slice(ee,ee+Jv)},[Be,I]),vn=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=U.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]),vi=nB({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",...vi,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"}),q&&c.jsx("div",{className:"flex items-center gap-1",children:c.jsx("button",{type:"button",onClick:()=>q&&void B(q),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(Mo,{className:ie("h-3.5 w-3.5",L&&"animate-spin")})})})]}),a&&c.jsx(m5,{onDone:()=>i(!1)}),c.jsx("div",{className:"flex border-b border-line",children:J8.map(({key:ee,label:ve})=>{const ze=ee==="open"?Fe.open:ee==="closed"?Fe.closed:U.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(Et,{className:"h-3 w-3"})})]})})]}):c.jsxs(c.Fragment,{children:[c.jsx(REe,{stateFilter:e,setStateFilter:t,typeFilter:n,setTypeFilter:r,searchQuery:o,setSearchQuery:u,expandedFilter:v,setExpandedFilter:N,selectedAuthor:_,setSelectedAuthor:S,selectedAssignee:C,setSelectedAssignee:A,creating:a,setCreating:i,openCount:Fe.open,closedCount:Fe.closed,totalCount:U.length,epicCount:Fe.epic,taskCount:Fe.task,strayCount:Fe.stray,afterStateCount:Fe.afterState,uniqueAuthors:un,uniqueAssignees:In}),a&&c.jsx(m5,{onDone:()=>i(!1)})]}),c.jsx("div",{className:ie("flex-1 overflow-y-auto",M?"px-2 py-2":"px-3 py-3"),children:q?P?Be.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:U.length===0?"点击 ↻ 同步 Issues":"无匹配 Issue"}):c.jsx("ul",{className:ie(M?"space-y-0.5":"space-y-1"),children:fr.map(ee=>M?c.jsx(wI,{issue:ee,sessionCount:vn.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(DEe,{issue:ee,sessionCount:vn.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($t,{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(TI,{total:Be.length,page:I,onPageChange:O})]}),M&&c.jsx(hE,{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(wI,{issue:ee,sessionCount:vn.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(TI,{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(IEe,{issue:hr,milestone:hr.milestoneId?Ke.get(hr.milestoneId):void 0,tab:le,prNumber:ne,onTabChange:xe,onSelectPr:we,onBackToPrList:Le,onBack:()=>{je(),p(!1)},onClose:()=>{je(),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(Et,{className:"h-4 w-4"})})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:d?(()=>{const ee=U.find(ve=>ve.id===d);return ee?c.jsx(UEe,{rootIssue:ee,childrenMap:Ee,currentId:M,onSelect:ve=>{ae(ve),f(ve,d),p(!1)},sessions:ha,onSessionSelect:Ra}):null})():c.jsx(PEe,{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 $Ee({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",CEe(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 GEe({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 YEe=y.memo(GEe,(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 qEe({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(ln,{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:uw(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 KEe=y.memo(qEe,(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),CI=[{key:"open",label:"开放"},{key:"merged",label:"已合并"},{key:"closed",label:"已关闭"},{key:"all",label:"全部"}];function VEe({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(DE,{className:"ml-auto h-3.5 w-3.5 shrink-0 text-emerald-400"})]})})})})}function WEe({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}zE(m,e.number).then(x).catch(()=>x([]))},[m,e.number]);const v=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(Ml,{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(Z8,{pr:e,onBack:o,onClose:u,onEnterMatch:d,onNavigateToIssue:f}):v?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(Rf,{className:"h-3.5 w-3.5"}),"返回列表"]})}),c.jsx(Q8,{issue:v,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($Ee,{issues:b,onSelect:a})})})]})}function XEe(){const[e,t]=y.useState("open"),[n,r]=y.useState(""),a=pn(ae=>ae.setViewingPr),[i,o]=y.useState(""),[u,d]=OE(),f=zn(),m=We(qr),p=pn(ae=>ae.pulls),b=pn(ae=>ae.syncing),x=pn(ae=>ae.syncPulls),v=pn(ae=>ae.syncError),N=pn(ae=>ae.matchingPrId),_=pn(ae=>ae.enterMatchMode),S=pn(ae=>ae.exitMatchMode),C=pn(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(()=>{v&&ar.getState().addToast(v,"error")},[v]),y.useEffect(()=>{const ae=u.get("prId");if(!ae)return;const je=new URLSearchParams(u);je.delete("prId"),je.set("id",ae),d(je,{replace:!0})},[u,d]),y.useEffect(()=>{if(u.get("id"))return;const ae=pn.getState().viewingPrId;ae&&d({id:ae},{replace:!0})},[d,u.get]);const U=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 je={id:O};ae==="issue"&&(je.tab="issue"),d(je,{replace:!1})},[O,d]),B=y.useCallback(ae=>{O&&d({id:O,tab:"issue",issueId:ae},{replace:!1})},[O,d]),G=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}zE(A,re.number).then(ae=>K(new Set(ae.map(je=>je.id)))).catch(()=>K(new Set))},[A,re]);const V=async ae=>{if(!re)return;X.has(ae.id)?await pn.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,q=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(Et,{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(Et,{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(VEe,{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(Mo,{className:ie("h-3.5 w-3.5",b&&"animate-spin")})})]}),c.jsx("div",{className:"flex border-b border-line",children:CI.map(({key:ae,label:je})=>{const xe=ae==="open"?H:ae==="merged"?q: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:[je,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(Et,{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(Mo,{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:CI.map(({key:ae,label:je})=>{const xe=ae==="open"?H:ae==="merged"?q: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:[je,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(Et,{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(Ml,{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(YEe,{pr:ae,isActive:ae.id===(O??N),onSelect:()=>U(ae.id)},ae.id):c.jsx(KEe,{pr:ae,onSelect:()=>U(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(WEe,{pr:ne,tab:k,issueId:j,onTabChange:L,onSelectIssue:B,onBackToIssueList:G,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(Ml,{className:"mx-auto h-12 w-12 opacity-20"}),c.jsx("p",{className:"mt-3 font-mono text-xs",children:"选择一个 PR 查看详情"})]})})]})}function kI(e,t){return e?`/${encodeURIComponent(e)}/dev/${t}`:`/dev/${t}`}function OI(){const e=zn(),t=or(),n=We(qr),r=Je(d=>d.issues),a=pn(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(kI(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(kI(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(Ml,{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(HEe,{}):c.jsx(XEe,{})})]})}const QEe=/^[\w.-]+@([\w.-]+):([\w.-]+)\/([\w.-]+?)(?:\.git)?$/,ZEe=/^https?:\/\/([\w.-]+)(?::\d+)?\/([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:\/)?$/,JEe=/^ssh:\/\/[\w.-]+@([\w.-]+)(?::\d+)?\/([\w.-]+)\/([\w.-]+?)(?:\.git)?$/;function rB(e){for(const t of[QEe,ZEe,JEe]){const n=e.match(t);if(n)return n[1]}return null}function II({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 f$(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 v=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(Io,{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(XR,{className:"h-3.5 w-3.5"}):c.jsx(WR,{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($t,{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(uA,{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):v(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(Kl,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):c.jsx(uA,{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:()=>v(A.name),className:"shrink-0 px-2 py-2 text-fg-5 hover:text-fg-2",title:"进入目录",children:c.jsx(Io,{className:"h-3.5 w-3.5"})})]},A.name))]})})]})}function eNe({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),[v,N]=y.useState("opencode"),[_,S]=y.useState(!1),[C,A]=y.useState(!1),[I,O]=y.useState(""),[k,j]=y.useState(null),U=We(q=>q.addRepo),P=o.trim()!==""&&d.trim()!==""&&a.trim()!==""&&!_&&!C,L=q=>{const Q=q instanceof Error?q.message:"操作失败";try{return JSON.parse(Q).error??Q}catch{return Q}},B=async q=>{const Q=q.trim();if(Q){S(!0),O("");try{const D=await d$(Q);i(D.localPath),D.name&&u(D.name),D.gitUrl&&f(D.gitUrl)}catch(D){O(L(D))}S(!1)}},G=y.useRef(B);G.current=B,y.useEffect(()=>{if(n!=="browse")return;const q=a.trim();if(!q)return;const Q=setTimeout(()=>{G.current(q)},FG);return()=>clearTimeout(Q)},[a,n]),y.useEffect(()=>{const q=d.trim();if(!q){j(null);return}const Q=rB(q);if(!Q){j(null);return}let D=!1;const z=setTimeout(()=>{HE().then($=>{if(D)return;const M=$.some(le=>le.host.toLowerCase()===Q.toLowerCase());j(M?null:Q)}).catch(()=>{D||j(null)})},UG);return()=>{D=!0,clearTimeout(z)}},[d]);const re=q=>{i(q),O(""),B(q)},X=q=>{p(q),x(!1)},K=async()=>{const q=d.trim();if(!q){O("请输入 Git 仓库地址");return}A(!0),O("");try{const Q=m.trim()||void 0,D=await h$(q,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 U(o.trim(),d.trim(),a.trim(),v)&&e()},H=q=>{r(q),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:q=>q.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(Et,{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($z,{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(Kl,{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(II,{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:q=>i(q.target.value),onBlur:q=>void B(q.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:q=>f(q.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:q=>p(q.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(q=>!q),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(II,{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($t,{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:q=>u(q.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:q=>f(q.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(ln,{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(q=>c.jsx("button",{type:"button",onClick:()=>N(q.value),className:`flex-1 rounded-lg border px-3 py-2 text-sm font-medium transition-colors ${v===q.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:q.label},q.value))}),c.jsx("span",{className:"text-[11px] text-fg-5",children:v==="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 tNe({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(()=>{pG(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 gG(e,r),o(r)}catch(N){b(N instanceof Error?N.message:String(N))}m(!1)},v=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(Et,{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(ln,{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($t,{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||!v,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(oh,{className:"h-3.5 w-3.5"}),f?"保存中…":"保存"]})]})]})})}const mE=1024,pE=mE*1024,RI=pE*1024;function MI(e){return!e||e<=0?"0 B":e<mE?`${e} B`:e<pE?`${(e/mE).toFixed(1)} KB`:e<RI?`${(e/pE).toFixed(1)} MB`:`${(e/RI).toFixed(2)} GB`}const Pv="ws/";function nNe({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(()=>v$(e),[e,t],{skip:!t,showErrorToast:!1,errorMessage:"加载失败"}),x=u??p,v=async C=>{a(C),d(null);try{await E$(e,C),b()}catch(A){d(A instanceof Qa?A.message:"删除失败")}a(null)},N=async()=>{o(!0),d(null);try{await N$(e),b()}catch(C){d(C instanceof Qa?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(RE,{className:"h-3 w-3 shrink-0"}):c.jsx(kr,{className:"h-3 w-3 shrink-0"}),c.jsx(Kl,{className:"h-3 w-3 shrink-0 text-fg-5"}),c.jsx("span",{children:"工作空间"}),f!==null&&c.jsxs("span",{className:"text-fg-5",children:["(",_,") · ",MI(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(Et,{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(Pv),I=A?C.branch.slice(Pv.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:Pv}),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(rH,{className:"h-2.5 w-2.5"}),MI(C.diskUsage)]}),c.jsx("button",{type:"button",onClick:()=>void v(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(i0,{className:"h-3 w-3"})})]},C.id)})})]})]})}function aB(){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),v=ar(P=>P.addToast),[N,_]=y.useState(null),[S,C]=y.useState(null),A=y.useRef(null),[I,O]=y.useState(null);y.useEffect(()=>{HE().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=rB(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 g$(P):await p$(P),await i()}catch{}p(null)},U=async P=>{x(P);try{const L=await y$(P);await i();const B=L.alreadyUpToDate?"info":"success";v(L.summary,B,void 0,{persistent:!0})}catch(L){let B="拉取失败";if(L instanceof Qa)try{B=JSON.parse(L.message).error??L.message}catch{B=L.message}v(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(Yr,{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(Yr,{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(Ez,{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(Gp,{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(Gp,{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(ln,{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 U(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(WF,{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(Xv,{className:"h-3 w-3 fill-current"}),"停止"]}):c.jsxs(c.Fragment,{children:[c.jsx(BE,{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(ME,{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 G=P.runtimeType==="claude-code"?"opencode":"claude-code";await w$(P.id,G),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 S$(P.id,!P.worktreeEnabled),i()},children:[c.jsx(Kl,{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(Ro,{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(i0,{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(hi,{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(nNe,{repoId:P.id})]},P.id)})}),c.jsxs("p",{className:"mt-3 text-xs text-fg-5",children:[t.length," 个仓库"]}),o&&c.jsx(eNe,{onClose:()=>u(!1)}),N&&c.jsx(tNe,{repoId:N.id,repoName:N.name,onClose:()=>_(null)})]})}function rNe(){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(aB,{})})})}/*! Capacitor: https://capacitorjs.com/ - MIT License */var Sc;(function(e){e.Unimplemented="UNIMPLEMENTED",e.Unavailable="UNAVAILABLE"})(Sc||(Sc={}));class Bv extends Error{constructor(t,n,r){super(t),this.message=t,this.code=n,this.data=r}}const aNe=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"},iNe=e=>{const t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},a=()=>t!==null?t.name:aNe(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 v=a(),N=u(p);let _;const S=async()=>(!_&&v in b?_=typeof b[v]=="function"?_=await b[v]():_=b[v]:t!==null&&!_&&"web"in b&&(_=typeof b.web=="function"?_=await b.web():_=b.web),_),C=(U,P)=>{var L,B;if(N){const G=N==null?void 0:N.methods.find(re=>P===re.name);if(G)return G.rtype==="promise"?re=>n.nativePromise(p,P.toString(),re):(re,X)=>n.nativeCallback(p,P.toString(),re,X);if(U)return(L=U[P])===null||L===void 0?void 0:L.bind(U)}else{if(U)return(B=U[P])===null||B===void 0?void 0:B.bind(U);throw new Bv(`"${p}" plugin is not implemented on ${v}`,Sc.Unimplemented)}},A=U=>{let P;const L=(...B)=>{const G=S().then(re=>{const X=C(re,U);if(X){const K=X(...B);return P=K==null?void 0:K.remove,K}else throw new Bv(`"${p}.${U}()" is not implemented on ${v}`,Sc.Unimplemented)});return U==="addListener"&&(G.remove=async()=>P()),G};return L.toString=()=>`${U.toString()}() { [capacitor code] }`,Object.defineProperty(L,"name",{value:U,writable:!1,configurable:!1}),L},I=A("addListener"),O=A("removeListener"),k=(U,P)=>{const L=I({eventName:U},P),B=async()=>{const re=await L;O({eventName:U,callbackId:re},P)},G=new Promise(re=>L.then(()=>re({remove:B})));return G.remove=async()=>{console.warn("Using addListener() without 'await' is deprecated."),await B()},G},j=new Proxy({},{get(U,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?[v]:[]])}),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=Bv,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},sNe=e=>e.Capacitor=iNe(e),Xg=sNe(typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}),db=Xg.registerPlugin;class cw{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 Xg.Exception(t,Sc.Unimplemented)}unavailable(t="not available"){return new Xg.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 jI=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),DI=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent);class oNe extends cw{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=DI(a).trim(),i=DI(i).trim(),n[a]=i}),n}async setCookie(t){try{const n=jI(t.key),r=jI(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)}}}db("CapacitorCookies",{web:()=>new oNe});const lNe=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)}),uNe=(e={})=>{const t=Object.keys(e);return Object.keys(e).map(a=>a.toLocaleLowerCase()).reduce((a,i,o)=>(a[i]=e[t[o]],a),{})},cNe=(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,dNe=(e,t={})=>{const n=Object.assign({method:e.method||"GET",headers:e.headers},t),a=uNe(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 fNe extends cw{async request(t){const n=dNe(t,t.webFetchExtra),r=cNe(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 lNe(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"}))}}db("CapacitorHttp",{web:()=>new fNe});var LI;(function(e){e.Dark="DARK",e.Light="LIGHT",e.Default="DEFAULT"})(LI||(LI={}));var PI;(function(e){e.StatusBar="StatusBar",e.NavigationBar="NavigationBar"})(PI||(PI={}));class hNe extends cw{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")}}db("SystemBars",{web:()=>new hNe});const mNe="modulepreload",pNe=function(e){return"/"+e},BI={},gNe=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=pNe(f),f in BI)return;BI[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":mNe,m||(b.as="script"),b.crossOrigin="",b.href=f,d&&b.setAttribute("nonce",d),document.head.appendChild(b),m)return new Promise((x,v)=>{b.addEventListener("load",x),b.addEventListener("error",()=>v(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)})},Ku=db("SpeechRecognition",{web:()=>gNe(()=>import("./web-oSAqA2w0.js"),[]).then(e=>new e.SpeechRecognitionWeb)});function bNe(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 gE=Xg.isNativePlatform(),Uv=!gE&&typeof window<"u"?window.SpeechRecognition??window.webkitSpeechRecognition:void 0,Fv=16e3;function xNe(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),v=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([]),U=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||U.current){n(!1),b("idle");return}o("识别中…"),b("recognizing");const q=H.reduce((ne,ae)=>ne+ae.length,0),Q=new Float32Array(q);let D=0;for(const ne of H)Q.set(ne,D),D+=ne.length;const z=bNe(Q,Fv),$=new FormData;$.append("audio",z,"recording.wav");try{const ne=await fetch("/api/transcribe",{method:"POST",body:$});if(U.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(v.current=!0,S.current&&(clearTimeout(S.current),S.current=null),gE){await Ku.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]),G=y.useCallback(async()=>{var D;U.current=!1,a(""),o(""),d(null),b("idle");const{available:H}=await Ku.available();if(!H){d("当前设备不支持语音识别");return}if((await Ku.requestPermissions()).speechRecognition!=="granted"){d("请允许语音识别权限");return}const Q=[];Q.push(await Ku.addListener("partialResults",z=>{o(z.matches[0]??"")})),Q.push(await Ku.addListener("listeningState",z=>{const $=z.status==="started";n($),$&&b("recording"),$||o("")})),N.current=Q;try{const z=await Ku.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(!Uv)return!1;U.current=!1,a(""),o(""),A.current="",d(null),b("idle"),v.current=!1;const H=new Uv;H.lang=e,H.continuous=!0,H.interimResults=!0,H.maxAlternatives=1,H.onstart=()=>{n(!0),b("recording"),_.current=!1,S.current=setTimeout(()=>{!_.current&&!v.current&&(C.current=!0,v.current=!0,H.stop(),d("语音识别服务不可用(Chrome/Edge 需连接 Google 服务器),下次将使用服务端识别"))},5e3)},H.onresult=q=>{_.current=!0,S.current&&(clearTimeout(S.current),S.current=null);let Q="",D="";for(let z=q.resultIndex;z<q.results.length;z++){const $=q.results[z][0].transcript;q.results[z].isFinal?Q+=$:D+=$}Q&&a(z=>z+Q),o(D),A.current=D},H.onerror=q=>{switch(q.error!=="no-speech"&&q.error!=="aborted"&&(v.current=!0),q.error){case"not-allowed":d("请允许麦克风权限");break;case"network":d("网络错误,请检查连接");break;case"no-speech":case"aborted":return;default:d(`语音识别错误:${q.error}`)}},H.onend=()=>{if(v.current&&A.current&&a(q=>q+A.current),o(""),A.current="",!v.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()=>{U.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:Fv,channelCount:1}})}catch{d("请允许麦克风权限");return}const q=new AudioContext({sampleRate:Fv}),Q=q.createMediaStreamSource(H),D=q.createScriptProcessor(4096,1,1);j.current=[],D.onaudioprocess=z=>{j.current.push(new Float32Array(z.inputBuffer.getChannelData(0)))},Q.connect(D),D.connect(q.destination),I.current=q,O.current=H,k.current=D,n(!0),b("recording")},[]),K=y.useCallback(()=>{gE?G():Uv&&!C.current&&re()||X()},[G,re,X]);y.useEffect(()=>{if(!t){m(0);return}if(x.current)return;let H=!1,q=null,Q=null,D=0;return(async()=>{try{if(q=await navigator.mediaDevices.getUserMedia({audio:!0}),H){q.getTracks().forEach(ne=>ne.stop());return}Q=new AudioContext;const z=Q.createMediaStreamSource(q),$=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 je=0;je<M.length;je++)ae+=M[je];m(ae/(M.length*255)),le=ne}D=requestAnimationFrame(oe)};D=requestAnimationFrame(oe)}catch{}})(),()=>{H=!0,cancelAnimationFrame(D),q==null||q.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,q,Q,D;v.current=!0,(H=x.current)==null||H.stop(),(q=k.current)==null||q.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(()=>{U.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 yNe=240,vNe=1e3;function iB(e){const t=xNe(),[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))},vNe)):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,yNe)}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 sB=["image/png","image/jpeg","image/gif","image/webp"];let UI=0;function oB(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||!v,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(oh,{className:"h-3.5 w-3.5"}),f?"保存中…":"保存"]})]})]})})}const mE=1024,pE=mE*1024,RI=pE*1024;function MI(e){return!e||e<=0?"0 B":e<mE?`${e} B`:e<pE?`${(e/mE).toFixed(1)} KB`:e<RI?`${(e/pE).toFixed(1)} MB`:`${(e/RI).toFixed(2)} GB`}const Pv="ws/";function nNe({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(()=>v$(e),[e,t],{skip:!t,showErrorToast:!1,errorMessage:"加载失败"}),x=u??p,v=async C=>{a(C),d(null);try{await E$(e,C),b()}catch(A){d(A instanceof Qa?A.message:"删除失败")}a(null)},N=async()=>{o(!0),d(null);try{await N$(e),b()}catch(C){d(C instanceof Qa?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(RE,{className:"h-3 w-3 shrink-0"}):c.jsx(kr,{className:"h-3 w-3 shrink-0"}),c.jsx(Kl,{className:"h-3 w-3 shrink-0 text-fg-5"}),c.jsx("span",{children:"工作空间"}),f!==null&&c.jsxs("span",{className:"text-fg-5",children:["(",_,") · ",MI(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(Et,{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(Pv),I=A?C.branch.slice(Pv.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:Pv}),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(rH,{className:"h-2.5 w-2.5"}),MI(C.diskUsage)]}),c.jsx("button",{type:"button",onClick:()=>void v(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(i0,{className:"h-3 w-3"})})]},C.id)})})]})]})}function aB(){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),v=ar(P=>P.addToast),[N,_]=y.useState(null),[S,C]=y.useState(null),A=y.useRef(null),[I,O]=y.useState(null);y.useEffect(()=>{HE().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=rB(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 g$(P):await p$(P),await i()}catch{}p(null)},U=async P=>{x(P);try{const L=await y$(P);await i();const B=L.alreadyUpToDate?"info":"success";v(L.summary,B,void 0,{persistent:!0})}catch(L){let B="拉取失败";if(L instanceof Qa)try{B=JSON.parse(L.message).error??L.message}catch{B=L.message}v(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(Yr,{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(Yr,{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(Ez,{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(Gp,{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(Gp,{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(ln,{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 U(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(WF,{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(Xv,{className:"h-3 w-3 fill-current"}),"停止"]}):c.jsxs(c.Fragment,{children:[c.jsx(BE,{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(ME,{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 G=P.runtimeType==="claude-code"?"opencode":"claude-code";await w$(P.id,G),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 S$(P.id,!P.worktreeEnabled),i()},children:[c.jsx(Kl,{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(Ro,{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(i0,{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(hi,{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(nNe,{repoId:P.id})]},P.id)})}),c.jsxs("p",{className:"mt-3 text-xs text-fg-5",children:[t.length," 个仓库"]}),o&&c.jsx(eNe,{onClose:()=>u(!1)}),N&&c.jsx(tNe,{repoId:N.id,repoName:N.name,onClose:()=>_(null)})]})}function rNe(){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(aB,{})})})}/*! Capacitor: https://capacitorjs.com/ - MIT License */var Sc;(function(e){e.Unimplemented="UNIMPLEMENTED",e.Unavailable="UNAVAILABLE"})(Sc||(Sc={}));class Bv extends Error{constructor(t,n,r){super(t),this.message=t,this.code=n,this.data=r}}const aNe=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"},iNe=e=>{const t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},a=()=>t!==null?t.name:aNe(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 v=a(),N=u(p);let _;const S=async()=>(!_&&v in b?_=typeof b[v]=="function"?_=await b[v]():_=b[v]:t!==null&&!_&&"web"in b&&(_=typeof b.web=="function"?_=await b.web():_=b.web),_),C=(U,P)=>{var L,B;if(N){const G=N==null?void 0:N.methods.find(re=>P===re.name);if(G)return G.rtype==="promise"?re=>n.nativePromise(p,P.toString(),re):(re,X)=>n.nativeCallback(p,P.toString(),re,X);if(U)return(L=U[P])===null||L===void 0?void 0:L.bind(U)}else{if(U)return(B=U[P])===null||B===void 0?void 0:B.bind(U);throw new Bv(`"${p}" plugin is not implemented on ${v}`,Sc.Unimplemented)}},A=U=>{let P;const L=(...B)=>{const G=S().then(re=>{const X=C(re,U);if(X){const K=X(...B);return P=K==null?void 0:K.remove,K}else throw new Bv(`"${p}.${U}()" is not implemented on ${v}`,Sc.Unimplemented)});return U==="addListener"&&(G.remove=async()=>P()),G};return L.toString=()=>`${U.toString()}() { [capacitor code] }`,Object.defineProperty(L,"name",{value:U,writable:!1,configurable:!1}),L},I=A("addListener"),O=A("removeListener"),k=(U,P)=>{const L=I({eventName:U},P),B=async()=>{const re=await L;O({eventName:U,callbackId:re},P)},G=new Promise(re=>L.then(()=>re({remove:B})));return G.remove=async()=>{console.warn("Using addListener() without 'await' is deprecated."),await B()},G},j=new Proxy({},{get(U,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?[v]:[]])}),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=Bv,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},sNe=e=>e.Capacitor=iNe(e),Xg=sNe(typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}),db=Xg.registerPlugin;class cw{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 Xg.Exception(t,Sc.Unimplemented)}unavailable(t="not available"){return new Xg.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 jI=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),DI=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent);class oNe extends cw{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=DI(a).trim(),i=DI(i).trim(),n[a]=i}),n}async setCookie(t){try{const n=jI(t.key),r=jI(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)}}}db("CapacitorCookies",{web:()=>new oNe});const lNe=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)}),uNe=(e={})=>{const t=Object.keys(e);return Object.keys(e).map(a=>a.toLocaleLowerCase()).reduce((a,i,o)=>(a[i]=e[t[o]],a),{})},cNe=(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,dNe=(e,t={})=>{const n=Object.assign({method:e.method||"GET",headers:e.headers},t),a=uNe(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 fNe extends cw{async request(t){const n=dNe(t,t.webFetchExtra),r=cNe(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 lNe(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"}))}}db("CapacitorHttp",{web:()=>new fNe});var LI;(function(e){e.Dark="DARK",e.Light="LIGHT",e.Default="DEFAULT"})(LI||(LI={}));var PI;(function(e){e.StatusBar="StatusBar",e.NavigationBar="NavigationBar"})(PI||(PI={}));class hNe extends cw{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")}}db("SystemBars",{web:()=>new hNe});const mNe="modulepreload",pNe=function(e){return"/"+e},BI={},gNe=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=pNe(f),f in BI)return;BI[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":mNe,m||(b.as="script"),b.crossOrigin="",b.href=f,d&&b.setAttribute("nonce",d),document.head.appendChild(b),m)return new Promise((x,v)=>{b.addEventListener("load",x),b.addEventListener("error",()=>v(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)})},Ku=db("SpeechRecognition",{web:()=>gNe(()=>import("./web-BXz3ECVP.js"),[]).then(e=>new e.SpeechRecognitionWeb)});function bNe(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 gE=Xg.isNativePlatform(),Uv=!gE&&typeof window<"u"?window.SpeechRecognition??window.webkitSpeechRecognition:void 0,Fv=16e3;function xNe(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),v=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([]),U=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||U.current){n(!1),b("idle");return}o("识别中…"),b("recognizing");const q=H.reduce((ne,ae)=>ne+ae.length,0),Q=new Float32Array(q);let D=0;for(const ne of H)Q.set(ne,D),D+=ne.length;const z=bNe(Q,Fv),$=new FormData;$.append("audio",z,"recording.wav");try{const ne=await fetch("/api/transcribe",{method:"POST",body:$});if(U.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(v.current=!0,S.current&&(clearTimeout(S.current),S.current=null),gE){await Ku.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]),G=y.useCallback(async()=>{var D;U.current=!1,a(""),o(""),d(null),b("idle");const{available:H}=await Ku.available();if(!H){d("当前设备不支持语音识别");return}if((await Ku.requestPermissions()).speechRecognition!=="granted"){d("请允许语音识别权限");return}const Q=[];Q.push(await Ku.addListener("partialResults",z=>{o(z.matches[0]??"")})),Q.push(await Ku.addListener("listeningState",z=>{const $=z.status==="started";n($),$&&b("recording"),$||o("")})),N.current=Q;try{const z=await Ku.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(!Uv)return!1;U.current=!1,a(""),o(""),A.current="",d(null),b("idle"),v.current=!1;const H=new Uv;H.lang=e,H.continuous=!0,H.interimResults=!0,H.maxAlternatives=1,H.onstart=()=>{n(!0),b("recording"),_.current=!1,S.current=setTimeout(()=>{!_.current&&!v.current&&(C.current=!0,v.current=!0,H.stop(),d("语音识别服务不可用(Chrome/Edge 需连接 Google 服务器),下次将使用服务端识别"))},5e3)},H.onresult=q=>{_.current=!0,S.current&&(clearTimeout(S.current),S.current=null);let Q="",D="";for(let z=q.resultIndex;z<q.results.length;z++){const $=q.results[z][0].transcript;q.results[z].isFinal?Q+=$:D+=$}Q&&a(z=>z+Q),o(D),A.current=D},H.onerror=q=>{switch(q.error!=="no-speech"&&q.error!=="aborted"&&(v.current=!0),q.error){case"not-allowed":d("请允许麦克风权限");break;case"network":d("网络错误,请检查连接");break;case"no-speech":case"aborted":return;default:d(`语音识别错误:${q.error}`)}},H.onend=()=>{if(v.current&&A.current&&a(q=>q+A.current),o(""),A.current="",!v.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()=>{U.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:Fv,channelCount:1}})}catch{d("请允许麦克风权限");return}const q=new AudioContext({sampleRate:Fv}),Q=q.createMediaStreamSource(H),D=q.createScriptProcessor(4096,1,1);j.current=[],D.onaudioprocess=z=>{j.current.push(new Float32Array(z.inputBuffer.getChannelData(0)))},Q.connect(D),D.connect(q.destination),I.current=q,O.current=H,k.current=D,n(!0),b("recording")},[]),K=y.useCallback(()=>{gE?G():Uv&&!C.current&&re()||X()},[G,re,X]);y.useEffect(()=>{if(!t){m(0);return}if(x.current)return;let H=!1,q=null,Q=null,D=0;return(async()=>{try{if(q=await navigator.mediaDevices.getUserMedia({audio:!0}),H){q.getTracks().forEach(ne=>ne.stop());return}Q=new AudioContext;const z=Q.createMediaStreamSource(q),$=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 je=0;je<M.length;je++)ae+=M[je];m(ae/(M.length*255)),le=ne}D=requestAnimationFrame(oe)};D=requestAnimationFrame(oe)}catch{}})(),()=>{H=!0,cancelAnimationFrame(D),q==null||q.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,q,Q,D;v.current=!0,(H=x.current)==null||H.stop(),(q=k.current)==null||q.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(()=>{U.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 yNe=240,vNe=1e3;function iB(e){const t=xNe(),[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))},vNe)):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,yNe)}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 sB=["image/png","image/jpeg","image/gif","image/webp"];let UI=0;function oB(e){return e.split(`
653
653
  `).length>RG||e.length>MG}function ENe(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}function NNe(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 SNe({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 dw({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(SNe,{url:e,label:t,onClose:()=>a(!1)})]})}function lB(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=TA-C;for(const I of N){if(A<=0){S.push(`最多 ${TA} 张图片`);break}if(!sB.includes(I.type)){S.push(`${I.name||"文件"}:格式不支持`);continue}if(I.size>jG){S.push(`${I.name}:超过 5MB`);continue}_.push({_id:`att-${++UI}`,mime:I.type,url:await NNe(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 _=++UI,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)},[]),v=t.map(({mime:N,url:_,filename:S})=>({mime:N,url:_,filename:S}));return{attachments:t,foldedTexts:r,promptFiles:v,error:i,setError:o,addFiles:u,onPaste:d,addFoldedText:f,expandFoldedTexts:m,remove:p,removeFoldedText:b,clear:x}}function wNe({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(Et,{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 _Ne({fold:e,index:t,onRemove:n}){const[r,a]=y.useState(!1),i=`粘贴文本 #${t} · ${e.lineCount}行 · ${ENe(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(Ro,{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(Et,{className:"h-2.5 w-2.5",strokeWidth:2.5})})]}),r&&c.jsx(wNe,{text:e.text,label:i,onClose:()=>a(!1)})]})}function uB({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:sB.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(iH,{className:"h-4 w-4"})})]})}function cB({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(dw,{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(Et,{className:"h-2.5 w-2.5",strokeWidth:2.5})})]},u._id)),(t??[]).map((u,d)=>c.jsx(_Ne,{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 FI=(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]}),nu=(function(e){if(e==null)return CNe;if(typeof e=="string")return ANe(e);if(typeof e=="object")return TNe(e);if(typeof e=="function")return fw(e);throw new Error("Expected function, string, or array as `test`")});function TNe(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=nu(e[n]);return fw(r);function r(...a){let i=-1;for(;++i<t.length;)if(t[i].apply(this,a))return!0;return!1}}function ANe(e){return fw(t);function t(n){return n.tagName===e}}function fw(e){return t;function t(n,r,a){return!!(kNe(n)&&e.call(this,n,typeof r=="number"?r:void 0,a||void 0))}}function CNe(e){return!!(e&&typeof e=="object"&&"type"in e&&e.type==="element"&&"tagName"in e&&typeof e.tagName=="string")}function kNe(e){return e!==null&&typeof e=="object"&&"type"in e&&"tagName"in e}const zI=/\n/g,HI=/[\t ]+/g,bE=nu("br"),$I=nu(PNe),ONe=nu("p"),GI=nu("tr"),INe=nu(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",LNe,BNe]),dB=nu(["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 RNe(e,t){const n=t||{},r="children"in e?e.children:[],a=dB(e),i=mB(e,{whitespace:n.whitespace||"normal"}),o=[];(e.type==="text"||e.type==="comment")&&o.push(...hB(e,{breakBefore:!0,breakAfter:!0}));let u=-1;for(;++u<r.length;)o.push(...fB(r[u],e,{whitespace:i,breakBefore:u?void 0:a,breakAfter:u<r.length-1?bE(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(`
@@ -1 +1 @@
1
- import{W as e}from"./index-hTZ7nR78.js";class t extends e{available(){throw this.unimplemented("Method not implemented on web.")}start(o){throw this.unimplemented("Method not implemented on web.")}stop(){throw this.unimplemented("Method not implemented on web.")}getSupportedLanguages(){throw this.unimplemented("Method not implemented on web.")}hasPermission(){throw this.unimplemented("Method not implemented on web.")}isListening(){throw this.unimplemented("Method not implemented on web.")}requestPermission(){throw this.unimplemented("Method not implemented on web.")}checkPermissions(){throw this.unimplemented("Method not implemented on web.")}requestPermissions(){throw this.unimplemented("Method not implemented on web.")}}const m=new t;export{m as SpeechRecognition,t as SpeechRecognitionWeb};
1
+ import{W as e}from"./index-DP_wGOuZ.js";class t extends e{available(){throw this.unimplemented("Method not implemented on web.")}start(o){throw this.unimplemented("Method not implemented on web.")}stop(){throw this.unimplemented("Method not implemented on web.")}getSupportedLanguages(){throw this.unimplemented("Method not implemented on web.")}hasPermission(){throw this.unimplemented("Method not implemented on web.")}isListening(){throw this.unimplemented("Method not implemented on web.")}requestPermission(){throw this.unimplemented("Method not implemented on web.")}checkPermissions(){throw this.unimplemented("Method not implemented on web.")}requestPermissions(){throw this.unimplemented("Method not implemented on web.")}}const m=new t;export{m as SpeechRecognition,t as SpeechRecognitionWeb};
package/public/index.html CHANGED
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover" />
6
6
  <title>Fourth Spark</title>
7
- <script type="module" crossorigin src="/assets/index-hTZ7nR78.js"></script>
7
+ <script type="module" crossorigin src="/assets/index-DP_wGOuZ.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/assets/index-BuDNYraG.css">
9
9
  </head>
10
10
  <body>