fourth-spark 0.11.38 → 0.11.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/drizzle/meta/0008_snapshot.json +1 -1
- package/drizzle/meta/_journal.json +2 -2
- package/package.json +1 -1
- package/public/assets/{index-i2c7SmfO.js → index-zCZNajXb.js} +2 -2
- package/public/assets/{web-bl6X0lUC.js → web-DmC2q7pI.js} +1 -1
- package/public/index.html +1 -1
- /package/drizzle/{0008_dapper_wolfsbane.sql → 0008_nifty_stryfe.sql} +0 -0
package/package.json
CHANGED
|
@@ -520,7 +520,7 @@ Please change the parent <Route path="${S}"> to <Route path="${S==="/"?"*":`${S}
|
|
|
520
520
|
*/const e$=[["path",{d:"M4 14a1 1 0 0 1-.78-1.63l9.9-10.2a.5.5 0 0 1 .86.46l-1.92 6.02A1 1 0 0 0 13 10h7a1 1 0 0 1 .78 1.63l-9.9 10.2a.5.5 0 0 1-.86-.46l1.92-6.02A1 1 0 0 0 11 14z",key:"1xq2db"}]],Cc=Ie("zap",e$),Yp="fourth-spark-server-url";function t$(){if(typeof window>"u")return!1;const t=window.Capacitor;return typeof(t==null?void 0:t.isNativePlatform)=="function"&&t.isNativePlatform()}function PE(){return localStorage.getItem(Yp)??""}function n$(e){const t=e.replace(/\/+$/,"");t?localStorage.setItem(Yp,t):localStorage.removeItem(Yp)}function Wv(){return localStorage.getItem(Yp)??""}class Li extends Error{constructor(n,r){super(n);pt(this,"status");this.name="ApiError",this.status=r}}async function Te(e,t){let n;try{n=await fetch(PE()+e,{...t,headers:{Accept:"application/json",...t!=null&&t.body?{"Content-Type":"application/json"}:{},...t==null?void 0:t.headers}})}catch(a){throw new Li(a instanceof Error?a.message:"Network request failed",0)}if(!n.ok){const a=await n.text().catch(()=>"");throw new Li(a.trim()||`${n.status} ${n.statusText}`,n.status)}if(n.status===204)return;const r=await n.text();if(r)return JSON.parse(r)}function Ia(e,...t){if(Array.isArray(e))return e;if(e&&typeof e=="object"){const n=e;for(const r of[...t,"data","items"])if(Array.isArray(n[r]))return n[r]}return[]}function JR(e,...t){if(e&&typeof e=="object"&&!Array.isArray(e)){const r=e;if(Array.isArray(r.items)&&typeof r.total=="number")return{items:r.items,total:r.total,limit:typeof r.limit=="number"?r.limit:50,offset:typeof r.offset=="number"?r.offset:0}}const n=Ia(e,...t);return{items:n,total:n.length,limit:n.length,offset:0}}async function r$(){return Ia(await Te("/api/repos"),"repos")}async function a$(e,t,n,r){return Te("/api/repos",{method:"POST",body:JSON.stringify({name:e,gitUrl:t,localPath:n,runtimeType:r})})}async function i$(e){return Te("/api/repos/resolve",{method:"POST",body:JSON.stringify({localPath:e})})}async function s$(e,t){return Te("/api/fs/browse",{method:"POST",body:JSON.stringify({path:e,showHidden:t})})}async function o$(e,t){return Te("/api/repos/clone",{method:"POST",body:JSON.stringify({gitUrl:e,targetDir:t})})}async function l$(e){await Te(`/api/repos/${encodeURIComponent(e)}`,{method:"DELETE"})}async function u$(e){await Te(`/api/repos/${encodeURIComponent(e)}/start`,{method:"POST"})}async function c$(e){await Te(`/api/repos/${encodeURIComponent(e)}/stop`,{method:"POST"})}async function d$(e){return Te(`/api/repos/${encodeURIComponent(e)}/branches`)}async function f$(e,t){return Te(`/api/repos/${encodeURIComponent(e)}/checkout`,{method:"POST",body:JSON.stringify({branch:t})})}async function h$(e){return Te(`/api/repos/${encodeURIComponent(e)}/pull`,{method:"POST"})}function nt(e){return`/api/repos/${encodeURIComponent(e)}`}async function m$(e){return Ia(await Te(`${nt(e)}/workspaces`),"workspaces")}async function p$(e,t){await Te(`${nt(e)}/workspaces/${encodeURIComponent(t)}`,{method:"DELETE"})}async function g$(e){return Te(`${nt(e)}/workspaces/cleanup`,{method:"POST"})}async function b$(e,t){await Te(`/api/repos/${e}/worktree`,{method:"PATCH",body:JSON.stringify({enabled:t})})}async function x$(e,t){await Te(`/api/repos/${e}/runtime`,{method:"PATCH",body:JSON.stringify({runtimeType:t})})}async function y$(e,t){const n=new URLSearchParams;n.set("limit",String(t.limit)),(t==null?void 0:t.offset)!=null&&n.set("offset",String(t.offset));const r=n.toString();return JR(await Te(`${nt(e)}/sessions${r?`?${r}`:""}`),"sessions")}async function v$(e,t,n,r,a,i,o,u){return Te(`${nt(e)}/sessions`,{method:"POST",body:JSON.stringify({message:t,agent:n,model:r,variant:a,issueId:i,customAgentId:o,files:u})})}async function E$(e,t,n,r,a,i,o){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/actions/prompt`,{method:"POST",body:JSON.stringify({content:n,agent:r,model:a,variant:i,files:o})})}async function N$(e,t){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/actions/abort`,{method:"POST"})}async function S$(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/questions/reply`,{method:"POST",body:JSON.stringify({answers:n})})}async function w$(e,t){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/questions/reject`,{method:"POST"})}async function _$(e,t,n){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/actions/revert`,{method:"POST",body:JSON.stringify({messageID:n})})}function lA(e){const t=e,n=t.info;if(n&&typeof n.id=="string"){const r=Array.isArray(t.parts)?t.parts:void 0;return{...n,...r?{parts:r}:{}}}return t}async function uA(e,t,n){const r=new URLSearchParams;n!=null&&n.limit&&r.set("limit",String(n.limit)),n!=null&&n.before&&r.set("before",n.before);const a=r.toString(),i=`${nt(e)}/sessions/${encodeURIComponent(t)}/messages${a?`?${a}`:""}`,o=await Te(i);if(Array.isArray(o)){const f=o.map(lA);return{messages:f,total:f.length,hasMore:!1}}const u=o,d=Array.isArray(u.messages)?u.messages:[];return{messages:d.map(lA),total:u.total??d.length,hasMore:u.hasMore??!1}}async function T$(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/status`)}async function A$(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`)}async function C$(e,t){return Te(`${nt(e)}/sessions/snapshot/${encodeURIComponent(t)}`)}async function eM(e){return Te(`${nt(e)}/sessions/all-links`)}async function k$(e,t,n,r){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`,{method:"POST",body:JSON.stringify({type:n,targetId:r})})}async function O$(e,t,n,r){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/links`,{method:"DELETE",body:JSON.stringify({type:n,targetId:r})})}async function tM(){return Ia(await Te("/api/custom-agents"))}async function I$(e){return Te("/api/custom-agents",{method:"POST",body:JSON.stringify(e)})}async function R$(e,t){return Te(`/api/custom-agents/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify(t)})}async function nM(e){await Te(`/api/custom-agents/${encodeURIComponent(e)}`,{method:"DELETE"})}async function cA(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/export`)}async function M$(e){return Te("/api/custom-agents/import",{method:"POST",body:JSON.stringify(e)})}async function D$(e){await Te("/api/custom-agents/reorder",{method:"PATCH",body:JSON.stringify({items:e})})}async function j$(e,t){await Te(`${nt(e)}/custom-agents/reorder`,{method:"PATCH",body:JSON.stringify({items:t})})}async function rM(e,t){const n=new URLSearchParams;t!=null&&t.category&&n.set("category",t.category),t!=null&&t.includeSuperseded&&n.set("includeSuperseded","true");const r=n.toString();return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories${r?`?${r}`:""}`)}async function L$(e,t,n){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify(n)})}async function P$(e,t){await Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/${encodeURIComponent(t)}`,{method:"DELETE"})}async function B$(e,t){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/extract`,{method:"POST",body:JSON.stringify({sessionIds:t})})}async function dA(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/stats`)}async function U$(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/memories/consolidate`,{method:"POST"})}async function BE(e){return Te(`/api/custom-agents/${encodeURIComponent(e)}/sessions`)}async function aM(e){return Ia(await Te(`${nt(e)}/custom-agents`))}async function F$(e,t){return Te(`${nt(e)}/custom-agents`,{method:"POST",body:JSON.stringify(t)})}async function kc(e){return Ia(await Te(`${nt(e)}/models`))}async function iM(){return Ia(await Te("/api/prompt-fragments"))}async function z$(e){return Te("/api/prompt-fragments",{method:"POST",body:JSON.stringify(e)})}async function H$(e,t){return Te(`/api/prompt-fragments/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify(t)})}async function $$(e){await Te(`/api/prompt-fragments/${encodeURIComponent(e)}`,{method:"DELETE"})}async function fA(e){return Ia(await Te(`${nt(e)}/tags`))}async function hA(e,t){return Ia(await Te(`${nt(e)}/milestones`))}async function mA(e,t="open",n){const r=new URLSearchParams({state:t});return(n==null?void 0:n.limit)!=null&&r.set("limit",String(n.limit)),(n==null?void 0:n.offset)!=null&&r.set("offset",String(n.offset)),JR(await Te(`${nt(e)}/issues?${r}`),"issues")}async function Y$(e,t="all"){return Te(`${nt(e)}/issues/sync`,{method:"POST",body:JSON.stringify({state:t})})}async function q$(e,t,n){return Te(`${nt(e)}/issues`,{method:"POST",body:JSON.stringify({title:t,body:n})})}async function G$(e,t,n){await Te(`${nt(e)}/issues/${t}/children`,{method:"POST",body:JSON.stringify({childNumber:n})})}async function sM(e,t,n){return Te(`${nt(e)}/issues/${t}`,{method:"PATCH",body:JSON.stringify(n)})}async function K$(e,t){return Ia(await Te(`${nt(e)}/issues/${t}/pulls`))}async function pA(e,t="open"){return Ia(await Te(`${nt(e)}/pulls?state=${encodeURIComponent(t)}`))}async function V$(e,t="all"){return Te(`${nt(e)}/pulls/sync`,{method:"POST",body:JSON.stringify({state:t})})}async function W$(e,t){return Te(`${nt(e)}/pulls/${t}`)}async function X$(e,t){await Te(`${nt(e)}/pulls/${t}/merge`,{method:"POST"})}async function UE(e,t){return Ia(await Te(`${nt(e)}/pulls/${t}/issues`))}async function Q$(e,t,n){await Te(`${nt(e)}/pulls/${t}/issues`,{method:"POST",body:JSON.stringify({issueNumber:n})})}async function Z$(e,t,n){await Te(`${nt(e)}/pulls/${t}/issues/${n}`,{method:"DELETE"})}async function J$(e,t){return Te(`${nt(e)}/pulls/${t}/comments`)}async function eY(e,t){return Te(`${nt(e)}/issues/${t}/comments`)}async function gA(e,t,n){return Te(`${nt(e)}/issues/${t}/comments`,{method:"POST",body:JSON.stringify({body:n})})}async function tY(e,t,n){return Te(`${nt(e)}/issues/${t}/polish`,{method:"POST",body:JSON.stringify({draft:n})})}async function bA(e,t){return Te(`${nt(e)}/issues/${t}/draft`)}async function nY(e,t,n){return Te(`${nt(e)}/issues/polish-create`,{method:"POST",body:JSON.stringify({title:t,body:n})})}async function xA(e){return Te(`${nt(e)}/issues/draft-create`)}async function rY(e){await Te(`${nt(e)}/issues/draft-create`,{method:"DELETE"})}async function aY(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({title:n})})}async function iY(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({completedAt:n})})}async function sY(e,t,n){await Te(`${nt(e)}/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({pinnedAt:n})})}async function oY(){return Te("/api/agents-md")}async function lY(e){await Te("/api/agents-md",{method:"PUT",body:JSON.stringify({content:e})})}async function uY(e){return Te(`/api/repos/${encodeURIComponent(e)}/agents-md`)}async function cY(e,t){await Te(`/api/repos/${encodeURIComponent(e)}/agents-md`,{method:"PUT",body:JSON.stringify({content:t})})}function dY(e){return`${PE()}${nt(e)}/events`}async function fY(e){return Te(`${nt(e)}/sessions/status`)}async function Ml(){return Te("/api/settings")}async function qp(e,t){await Te(`/api/settings/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify({value:t})})}async function Xv(){return Te("/api/cloud/status")}async function hY(){return Te("/api/cloud/reload",{method:"POST"})}async function mY(e){try{return(await Te("/api/cloud/test",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({url:e})})).connected}catch{return!1}}async function FE(){return Ia(await Te("/api/git-hosts"),"gitHosts")}async function pY(e,t,n,r="gitea"){return Te("/api/git-hosts",{method:"POST",body:JSON.stringify({host:e,name:t,token:n,platform:r})})}async function gY(e){await Te(`/api/git-hosts/${encodeURIComponent(e)}`,{method:"DELETE"})}async function oM(){return Te("/api/usage")}async function lM(e){return Te("/api/usage/switch",{method:"POST",body:JSON.stringify({accountId:e})})}async function bY(){return Te("/api/usage/authorize",{method:"POST"})}async function xY(e,t){return Te("/api/usage/exchange",{method:"POST",body:JSON.stringify({pendingId:e,code:t})})}async function yY(e,t){return Te(`${nt(e)}/sessions/${encodeURIComponent(t)}/files`)}function vY(e,t,n){return`${PE()}${nt(e)}/sessions/${encodeURIComponent(t)}/files/${n}`}async function wy(e,t,n,r){const a=new URLSearchParams({from:String(e),to:String(t),groupBy:n});return Te(`/api/analytics/summary?${a}`)}const Qv=50,yA=20,EY=200,vA=1e3,_y=2e3,EA=500,NY=5,SY=500,wY=5*1024*1024,NA=10,uM=4e3,_Y=300,TY=2e3,AY=2e3,CY=300,kY=300,OY=500,IY=2e3,RY=30*6e4,SA=[{bg:"bg-blue-500/15",text:"text-blue-500"},{bg:"bg-purple-500/15",text:"text-purple-500"},{bg:"bg-emerald-500/15",text:"text-emerald-500"},{bg:"bg-amber-500/15",text:"text-amber-500"},{bg:"bg-rose-500/15",text:"text-rose-500"},{bg:"bg-cyan-500/15",text:"text-cyan-500"},{bg:"bg-indigo-500/15",text:"text-indigo-500"},{bg:"bg-orange-500/15",text:"text-orange-500"}];function zE(e){const t=e.trim(),n=t.charCodeAt(0)||0;return{...SA[n%SA.length],initial:(t.charAt(0)||"?").toUpperCase()}}const wA=e=>{let t;const n=new Set,r=(f,m)=>{const p=typeof f=="function"?f(t):f;if(!Object.is(p,t)){const b=t;t=m??(typeof p!="object"||p===null)?p:Object.assign({},t,p),n.forEach(x=>x(t,b))}},a=()=>t,u={setState:r,getState:a,getInitialState:()=>d,subscribe:f=>(n.add(f),()=>n.delete(f))},d=t=e(r,a,u);return u},MY=(e=>e?wA(e):wA),DY=e=>e;function jY(e,t=DY){const n=Vn.useSyncExternalStore(e.subscribe,Vn.useCallback(()=>t(e.getState()),[e,t]),Vn.useCallback(()=>t(e.getInitialState()),[e,t]));return Vn.useDebugValue(n),n}const _A=e=>{const t=MY(e),n=r=>jY(t,r);return Object.assign(n,t),n},$i=(e=>e?_A(e):_A),TA="fs-nav-collapsed",AA="fs-session-panel-collapsed",ys=$i(e=>({navCollapsed:localStorage.getItem(TA)==="true",sessionPanelCollapsed:localStorage.getItem(AA)==="true",guideTourOpen:!1,guideTourSection:null,startGuideTour(t){e({guideTourOpen:!0,guideTourSection:t??null})},stopGuideTour(){e({guideTourOpen:!1,guideTourSection:null})},toggleNav(){e(t=>{const n=!t.navCollapsed;return localStorage.setItem(TA,String(n)),{navCollapsed:n}})},toggleSessionPanel(){e(t=>{const n=!t.sessionPanelCollapsed;return localStorage.setItem(AA,String(n)),{sessionPanelCollapsed:n}})}})),go="fs-active-repo",We=$i((e,t)=>({repos:[],activeRepoId:localStorage.getItem(go),loading:!0,loadError:null,loadRepos:async()=>{e({loading:!0,loadError:null});try{const n=await r$(),r=t().activeRepoId,a=r&&n.some(o=>o.id===r);e({repos:n,loading:!1,activeRepoId:a?r:n.length>0?n[0].id:null});const i=t().activeRepoId;i?localStorage.setItem(go,i):localStorage.removeItem(go)}catch(n){e({loading:!1,loadError:n instanceof Error?n.message:"Failed to load repos"})}},setActiveRepo:n=>{e({activeRepoId:n}),n?localStorage.setItem(go,n):localStorage.removeItem(go)},addRepo:async(n,r,a,i)=>{try{const o=await a$(n,r,a,i);return e(u=>({repos:[...u.repos,o],activeRepoId:o.id})),localStorage.setItem(go,o.id),o}catch(o){return e({loadError:o instanceof Error?o.message:"Failed to add repo"}),null}},removeRepo:async n=>{try{await l$(n)}catch{}e(r=>{const a=r.repos.filter(o=>o.id!==n),i=r.activeRepoId===n?a.length>0?a[0].id:null:r.activeRepoId;return i?localStorage.setItem(go,i):localStorage.removeItem(go),{repos:a,activeRepoId:i}})},updateRepoBranch:(n,r)=>{e(a=>({repos:a.repos.map(i=>i.id===n?{...i,branch:r}:i)}))}})),qr=e=>{var t;return((t=e.repos.find(n=>n.id===e.activeRepoId))==null?void 0:t.name)??null},Ty="fs-theme";function cM(){return window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function CA(e){return e==="system"?cM():e}function kA(e){e==="system"?document.documentElement.removeAttribute("data-theme"):document.documentElement.setAttribute("data-theme",e)}const Zv=$i((e,t)=>({preference:localStorage.getItem(Ty)??"system",resolved:CA(localStorage.getItem(Ty)??"system"),cycle(){const n=["system","light","dark"],r=n[(n.indexOf(t().preference)+1)%n.length],a=CA(r);localStorage.setItem(Ty,r),kA(r),e({preference:r,resolved:a})},init(){kA(t().preference);const n=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>{const{preference:a}=t();if(a==="system"){const i=cM();e({resolved:i})}};return n.addEventListener("change",r),()=>n.removeEventListener("change",r)}}));let dM=()=>{},fM=()=>{};function LY(e,t){dM=e,fM=t}function gl(e,t="info",n,r){dM(e,t,n,r)}function PY(e){fM(e)}let Ay=0;const ia=$i(e=>({agents:[],loaded:!1,loadAgents:async t=>{const n=++Ay;try{const r=t?await aM(t):await tM();if(Ay!==n)return;e({agents:r,loaded:!0})}catch(r){if(Ay!==n)return;e({loaded:!0});let a="加载 Agent 列表失败";if(r instanceof Li)try{const i=JSON.parse(r.message);i.error&&(a=i.error)}catch{r.message&&(a=r.message)}gl(a,"error")}}}));let rl=0;const Je=$i((e,t)=>({issues:[],issueTotal:0,tags:[],tagFilterMode:new Map,milestones:[],selectedMilestoneId:null,loaded:!1,syncing:!1,syncError:null,selectedIssueId:null,viewingIssueId:null,viewingTreeRootId:null,matchingParentId:null,matchingCandidateId:null,clearIssues:()=>{++rl,e({issues:[],issueTotal:0,tags:[],tagFilterMode:new Map,milestones:[],selectedMilestoneId:null,loaded:!1,syncError:null,selectedIssueId:null,viewingIssueId:null,viewingTreeRootId:null,matchingParentId:null,matchingCandidateId:null})},setSelectedIssue:n=>e({selectedIssueId:n}),setViewingIssue:(n,r)=>e({viewingIssueId:n,viewingTreeRootId:r??null}),enterMatchMode:n=>e({matchingParentId:n,matchingCandidateId:null}),exitMatchMode:()=>{e({matchingParentId:null,matchingCandidateId:null})},linkChild:async(n,r,a)=>{var i;try{await G$(n,r,a);const o=(i=t().issues.find(u=>u.number===r))==null?void 0:i.id;return o&&e(u=>({issues:u.issues.map(d=>d.number===a?{...d,parentId:o}:d),matchingCandidateId:null})),!0}catch{return!1}},updateIssueState:async(n,r,a)=>{try{const i=await sM(n,r,{state:a});return e(o=>({issues:o.issues.map(u=>u.number===r?{...u,state:i.state}:u)})),!0}catch{return!1}},loadIssues:async n=>{const r=++rl;try{const a=await mA(n,"all",{limit:vA});if(rl!==r)return;e({issues:a.items,issueTotal:a.total,loaded:!0})}catch{if(rl!==r)return;e({loaded:!0})}},syncIssues:async n=>{const r=++rl;e({syncing:!0,syncError:null});try{await Y$(n,"open");const[a,i,o]=await Promise.all([mA(n,"all",{limit:vA}),fA(n),hA(n)]);if(rl!==r)return;e({issues:a.items,issueTotal:a.total,tags:i,milestones:o,syncing:!1})}catch(a){if(rl!==r)return;let i="同步 Issue 失败";if(a instanceof Li)try{const o=JSON.parse(a.message);o.error&&(i=o.error)}catch{a.message&&(i=a.message)}e({syncing:!1,syncError:i})}},createIssue:async(n,r,a)=>{try{const i=await q$(n,r,a);return e(o=>({issues:[i,...o.issues]})),i}catch{return null}},loadTags:async n=>{try{const r=await fA(n);e({tags:r})}catch{}},cycleTagFilter:n=>{e(r=>{const a=new Map(r.tagFilterMode),i=a.get(n);return i?i==="include"?a.set(n,"exclude"):a.delete(n):a.set(n,"include"),{tagFilterMode:a}})},clearTagFilter:()=>e({tagFilterMode:new Map}),loadMilestones:async n=>{try{const r=await hA(n);e({milestones:r})}catch{}},setMilestoneFilter:n=>e({selectedMilestoneId:n})}));let al=0;const mn=$i((e,t)=>({pulls:[],loaded:!1,syncing:!1,syncError:null,selectedPrId:null,viewingPrId:null,matchingPrId:null,matchingCandidateIssueId:null,clearPulls:()=>{++al,e({pulls:[],loaded:!1,syncError:null,selectedPrId:null,viewingPrId:null,matchingPrId:null,matchingCandidateIssueId:null})},setViewingPr:n=>e({viewingPrId:n}),enterMatchMode:n=>e({matchingPrId:n,matchingCandidateIssueId:null}),exitMatchMode:()=>{const n=t().matchingPrId;e({matchingPrId:null,matchingCandidateIssueId:null,selectedPrId:n})},linkIssue:async(n,r,a)=>{try{return await Q$(n,r,a),!0}catch{return!1}},unlinkIssue:async(n,r,a)=>{try{return await Z$(n,r,a),!0}catch{return!1}},loadPulls:async n=>{const r=++al;try{const a=await pA(n,"all");if(al!==r)return;e({pulls:a,loaded:!0})}catch{if(al!==r)return;e({loaded:!0})}},syncPulls:async n=>{const r=++al;e({syncing:!0,syncError:null});try{await V$(n,"open");const a=await pA(n,"all");if(al!==r)return;e({pulls:a,syncing:!1})}catch(a){if(al!==r)return;let i="同步 PR 失败";if(a instanceof Li)try{const o=JSON.parse(a.message);o.error&&(i=o.error)}catch{a.message&&(i=a.message)}e({syncing:!1,syncError:i})}}})),BY=new Set(["tool","tool-use","tool_use","tool-call","tool_call","tool-result","tool_result"]),UY=new Set(["thinking","reasoning","reason"]),FY=new Set(["text","output_text","message"]),zY=new Set(["file","image"]);function Gp(e){var n;const t=((n=e.type)==null?void 0:n.toLowerCase())??"";return BY.has(t)||e.toolName!=null||e.tool!=null?"tool":zY.has(t)?"file":UY.has(t)?"thinking":FY.has(t)||e.content!=null||e.text!=null?"text":"other"}function Jv(e){return e.content??e.text??""}function hM(e){return e.toolName??e.tool??"tool"}function i0(e){var t;return e.input??((t=e.state)==null?void 0:t.input)}function HE(e){var t;return e.output??((t=e.state)==null?void 0:t.output)}function $E(e){var n,r,a;const t=(r=(n=e.state)==null?void 0:n.status)==null?void 0:r.toLowerCase();return t==="completed"||t==="done"||t==="success"?"completed":t==="error"||t==="failed"||((a=e.state)==null?void 0:a.error)!=null?"error":t==="pending"||t==="queued"?"pending":t==="running"||t==="in_progress"?"running":HE(e)!=null?"completed":"running"}function OA(e){if(e==null)return"";if(typeof e=="string")return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function Dl(e){const t=e==null?void 0:e.toLowerCase();return t==="in_progress"||t==="in-progress"||t==="active"?"in_progress":t==="completed"||t==="done"||t==="complete"?"completed":t==="cancelled"||t==="canceled"?"cancelled":"pending"}function mM(e){return e.filter(t=>Dl(t.status)==="completed").length}function Mf(e){const t=hM(e).toLowerCase();return t==="question"||t==="mcp_question"}function HY(e){const t=i0(e);if(!t||typeof t!="object")return null;const n=t;return Array.isArray(n.questions)?n.questions:null}function Kp(e){if(!Mf(e))return!1;const t=$E(e);return t==="pending"||t==="running"}const $Y=/\bses_[a-zA-Z0-9]+/;function YY(e){var a;const t=i0(e);if(t&&typeof t=="object"){const i=t;if(typeof i.task_id=="string"&&i.task_id.startsWith("ses_"))return i.task_id}const n=(a=e.state)==null?void 0:a.metadata;if(n){const i=n.session_id??n.sessionId;if(typeof i=="string"&&i.startsWith("ses_"))return i}const r=HE(e);if(typeof r=="string"){const i=$Y.exec(r);if(i)return i[0]}if(r&&typeof r=="object"){const i=r,o=i.session_id??i.sessionId??i.task_id;if(typeof o=="string"&&o.startsWith("ses_"))return o}return null}let Zm=0;function pM(e){return`question-${e}`}function Cy(e,t){const n=t.find(a=>a.id===e),r=(n==null?void 0:n.title)||e.slice(-8);gl(`${r} — 等待回复`,"warning",e,{id:pM(e),persistent:!0})}function qY(e){var t;for(const n of e)if((t=n.parts)!=null&&t.some(r=>Mf(r)&&Kp(r)))return!0;return!1}const Df=[],jf=[],IA=[],Pu={},ky=new Set;function RA(e){return e.id??e.callID}async function MA(e,t,n){try{const[r,a]=await Promise.all([A$(e,t),eM(e).catch(()=>null)]);n(i=>{const o={sessionLinks:{...i.sessionLinks,[t]:r}};return a&&(o.allSessionLinks=a),o})}catch{}}const Me=$i((e,t)=>({sessions:[],activeSessionId:null,messages:{},messagesMeta:{},todos:{},sessionStatuses:{},errorReasons:{},queuedMessageIds:{},sessionLinks:{},allSessionLinks:{},sessionModels:{},sessionVariants:{},sessionFilter:"active",sessionSearch:"",loadingSessions:!1,loadError:null,sendError:null,setSessionModel:(n,r)=>e(a=>({sessionModels:{...a.sessionModels,[n]:r}})),setSessionVariant:(n,r)=>e(a=>({sessionVariants:{...a.sessionVariants,[n]:r}})),setSessionFilter:n=>e({sessionFilter:n}),setSessionSearch:n=>e({sessionSearch:n}),toggleSessionPin:async(n,r)=>{const a=t().sessions.find(o=>o.id===r);if(!a)return;const i=a.pinnedAt?null:Date.now();e(o=>({sessions:o.sessions.map(u=>u.id===r?{...u,pinnedAt:i??void 0}:u)}));try{await sY(n,r,i)}catch{await t().loadSessions(n)}},toggleSessionComplete:async(n,r)=>{const a=t().sessions.find(o=>o.id===r);if(!a)return;const i=a.completedAt?null:Date.now();e(o=>({sessions:o.sessions.map(u=>u.id===r?{...u,completedAt:i??void 0}:u)}));try{await iY(n,r,i)}catch{await t().loadSessions(n)}},loadSessions:async n=>{const r=++Zm;e({loadingSessions:!0,loadError:null});try{const[a,i]=await Promise.all([y$(n,{limit:EY}),eM(n).catch(()=>null)]);if(Zm!==r)return;const o={sessions:a.items,loadingSessions:!1};i&&(o.allSessionLinks=i),e(o)}catch(a){if(Zm!==r)return;e({loadingSessions:!1,loadError:a instanceof Error?a.message:"Failed to load sessions"})}},createSession:async(n,r,a,i,o,u,d,f)=>{e({sendError:null});try{const m=await v$(n,r,a,i,o,u,d,f);return e(p=>({sessions:[m,...p.sessions.filter(b=>b.id!==m.id)],activeSessionId:m.id,messages:{...p.messages,[m.id]:[]}})),t().setSessionStatus(m.id,"busy"),u&&gl("已自动分配为处理人","success"),m}catch(m){return e({sendError:m instanceof Error?m.message:"Failed to create session"}),null}},setActiveSession:async(n,r)=>{e({activeSessionId:r,sendError:null}),await t().refreshSessionData(n,r)},refreshSessionData:async(n,r)=>{var m,p;const i=!t().messages[r]||t().messages[r].length===0?{limit:yA}:void 0,[o,u]=await Promise.allSettled([C$(n,r),uA(n,r,i)]),d=o.status==="fulfilled"?o.value:null,f=(p=(m=d==null?void 0:d.session)==null?void 0:m.revert)==null?void 0:p.messageID;e(b=>{const x={};if(d&&(d.status&&(x.sessionStatuses={...b.sessionStatuses,[r]:d.status.type}),d.todos&&(x.todos={...b.todos,[r]:d.todos}),d.links&&(x.sessionLinks={...b.sessionLinks,[r]:d.links}),d.session&&(x.sessions=b.sessions.map(E=>E.id===r?{...E,...d.session}:E))),u.status==="fulfilled"){let E=u.value.messages;if(f){const _=E.findIndex(S=>S.id===f);_>=0&&(E=E.slice(0,_+1))}const N=b.messages[r]??[];E.length>=N.length&&(x.messages={...b.messages,[r]:E}),x.messagesMeta={...b.messagesMeta,[r]:{total:Math.max(u.value.total,N.length),hasMore:u.value.hasMore,loading:!1}}}return x}),u.status==="fulfilled"&&qY(u.value.messages)&&Cy(r,t().sessions)},loadMoreMessages:async(n,r)=>{var u;const a=t().messagesMeta[r];if(!(a!=null&&a.hasMore)||a.loading)return;const o=(u=(t().messages[r]??[])[0])==null?void 0:u.id;e(d=>({messagesMeta:{...d.messagesMeta,[r]:{...a,loading:!0}}}));try{const d=await uA(n,r,{limit:yA,before:o});e(f=>{const m=f.messages[r]??[];return{messages:{...f.messages,[r]:[...d.messages,...m]},messagesMeta:{...f.messagesMeta,[r]:{total:d.total,hasMore:d.hasMore,loading:!1}}}})}catch{e(d=>({messagesMeta:{...d.messagesMeta,[r]:{...a,loading:!1}}}))}},addLink:async(n,r,a,i)=>{try{return await k$(n,r,a,i),await MA(n,r,e),!0}catch{return!1}},removeLink:async(n,r,a,i)=>{try{return await O$(n,r,a,i),await MA(n,r,e),!0}catch{return!1}},sendMessage:async(n,r,a,i,o)=>{const u=t().activeSessionId;if(!u)return!1;const d=t().sessions.find(m=>m.id===u),f=t().sessionStatuses[u]==="busy";e({sendError:null}),d!=null&&d.completedAt&&e(m=>({sessions:m.sessions.map(p=>p.id===u?{...p,completedAt:void 0}:p)})),f||t().setSessionStatus(u,"busy");try{return await E$(n,u,r,d==null?void 0:d.agent,a,i,o),f&&(Pu[u]=(Pu[u]||0)+1),!0}catch(m){return e({sendError:m instanceof Error?m.message:"Failed to send message"}),f||t().setSessionStatus(u,"idle"),!1}},replyQuestion:async(n,r)=>{const a=t().activeSessionId;if(a)try{await S$(n,a,r)}catch(i){e({sendError:i instanceof Error?i.message:"Failed to reply to question"})}},rejectQuestion:async n=>{const r=t().activeSessionId;if(r)try{await w$(n,r)}catch{}},abortSession:async n=>{const r=t().activeSessionId;if(r){try{await N$(n,r)}catch{}t().setSessionStatus(r,"idle")}},clearSessions:()=>{++Zm;for(const n of Object.keys(Pu))delete Pu[n];e({sessions:[],activeSessionId:null,messages:{},messagesMeta:{},todos:{},sessionStatuses:{},errorReasons:{},queuedMessageIds:{},sessionLinks:{},allSessionLinks:{},sessionModels:{},sessionVariants:{},sessionSearch:"",loadError:null,sendError:null})},updateMessage:(n,r)=>{var a;e(i=>{const o=i.messages[n]??[],u=o.findIndex(p=>p.id===r.id);let d,f=i.queuedMessageIds,m=i.messagesMeta;if(u>=0){const p={...o[u],...r};(!r.parts||r.parts.length===0)&&o[u].parts&&(p.parts=o[u].parts),d=[...o],d[u]=p}else{d=[...o,r];const p=m[n];p&&(m={...m,[n]:{...p,total:p.total+1}});const b=Pu[n]||0;if(r.role==="user"&&b>0){const x=[...f[n]??[]];x.push(r.id),f={...f,[n]:x},Pu[n]=b-1}else if(r.role==="assistant"){const x=f[n];x&&x.length>0&&(f={...f,[n]:x.slice(1)})}}return{messages:{...i.messages,[n]:d},messagesMeta:m,queuedMessageIds:f}}),(a=r.parts)!=null&&a.some(i=>Mf(i)&&Kp(i))&&Cy(n,t().sessions)},updateMessagePart:(n,r,a)=>{e(i=>{const o=i.messages[n]??[],u=o.findIndex(E=>E.id===r),d=u>=0?o[u]:{id:r,role:"assistant"},f=d.parts?[...d.parts]:[],m=RA(a),p=m!=null?f.findIndex(E=>RA(E)===m):-1;p>=0?f[p]={...f[p],...a}:f.push(a);const b={...d,parts:f},x=u>=0?[...o]:[...o,b];return u>=0&&(x[u]=b),{messages:{...i.messages,[n]:x}}}),Mf(a)&&Kp(a)&&Cy(n,t().sessions)},appendMessagePartDelta:(n,r,a,i)=>{e(o=>{const u=o.messages[n]??[],d=u.findIndex(E=>E.id===r),f=d>=0?u[d]:{id:r,role:"assistant"},m=f.parts?[...f.parts]:[],p=m.findIndex(E=>E.id===a);if(p>=0){const E=m[p],N=(E.content??E.text??"")+i;m[p]=E.content!=null?{...E,content:N}:{...E,text:N}}else m.push({id:a,type:"text",text:i});const b={...f,parts:m},x=d>=0?[...u]:[...u,b];return d>=0&&(x[d]=b),{messages:{...o.messages,[n]:x}}})},updateTodos:(n,r)=>{e(a=>({todos:{...a.todos,[n]:r}}))},updateSessionInfo:n=>{e(r=>r.sessions.some(i=>i.id===n.id)?{sessions:r.sessions.map(i=>{if(i.id!==n.id)return i;const o={...i,...n};return ky.has(n.id)&&i.title&&(o.title=i.title),o})}:{sessions:[n,...r.sessions]})},setSessionStatus:(n,r,a)=>{const i=t().sessionStatuses[n];if(i!==r){const o=t().sessions.find(d=>d.id===n),u=(o==null?void 0:o.title)||n.slice(-8);if(r==="idle"&&i!==void 0&&i!=="idle")PY(pM(n)),gl(`${u} — 完成`,"success",n);else if(r==="busy"&&(i===void 0||i==="idle"))gl(`${u} — 开始运行`,"info",n);else if(r==="retry")gl(`${u} — 进入重试`,"warning",n);else if(r==="error"){const d=a?`${u} — 错误: ${a}`:`${u} — 发生错误`;gl(d,"error",n)}}e(o=>{const u=a?{...o.errorReasons,[n]:a}:r!=="error"?(()=>{const{[n]:d,...f}=o.errorReasons;return f})():o.errorReasons;return{sessionStatuses:{...o.sessionStatuses,[n]:r},errorReasons:u}})},bulkSetStatuses:n=>{e({sessionStatuses:{...t().sessionStatuses,...n}})},renameSession:async(n,r,a)=>{ky.add(r),e(i=>({sessions:i.sessions.map(o=>o.id===r?{...o,title:a}:o)}));try{await aY(n,r,a)}catch{ky.delete(r),await t().loadSessions(n)}},revertToMessage:async(n,r,a)=>{try{return await _$(n,r,a),await t().refreshSessionData(n,r),!0}catch{return!1}}})),wl="__guide__",Bt=Date.now(),Nn=864e5,gM="guide-agent-",tc=`${gM}1`,YE="guide-session-run-1",GY={id:YE,title:"示例对话:添加用户认证",agent:"Sisyphus",createdAt:new Date(Bt-36e5).toISOString(),time:{created:Bt-36e5,updated:Bt-6e5},cost:.12,tokens:{input:4200,output:1800,reasoning:320,cache:{read:800,write:200}}},bM=[{id:"guide-issue-1",repoId:wl,number:42,title:"添加用户认证模块",body:"实现 JWT 认证,包括登录、注册和 token 刷新。",state:"open",labels:[{id:1,name:"feature",color:"0075ca"}],htmlUrl:"#",authorLogin:"demo-user",createdAt:Bt-Nn,updatedAt:Bt-36e5},{id:"guide-issue-2",repoId:wl,number:41,title:"修复登录页样式错位",body:"移动端登录表单在小屏幕下溢出。",state:"closed",labels:[{id:2,name:"bug",color:"d73a4a"}],htmlUrl:"#",authorLogin:"demo-user",createdAt:Bt-2*Nn,updatedAt:Bt-Nn}],xM=[{id:"guide-pr-1",repoId:wl,number:10,title:"feat: add auth module",body:"Implements JWT authentication.",state:"open",headBranch:"feat/auth",baseBranch:"main",labels:[{id:1,name:"feature",color:"0075ca"}],htmlUrl:"#",authorLogin:"demo-user",mergeable:"true",draft:0,commentCount:0,additions:320,deletions:12,changedFilesCount:8,createdAt:Bt-Nn,updatedAt:Bt-36e5,mergedAt:null},{id:"guide-pr-2",repoId:wl,number:9,title:"fix: login page CSS overflow",state:"merged",headBranch:"fix/login-css",baseBranch:"main",draft:0,commentCount:1,additions:15,deletions:3,changedFilesCount:2,createdAt:Bt-2*Nn,updatedAt:Bt-Nn,mergedAt:Bt-Nn}],KY=[{id:"guide-tag-1",repoId:wl,name:"bug",color:"d73a4a",description:null,createdAt:Bt},{id:"guide-tag-2",repoId:wl,name:"feature",color:"0075ca",description:null,createdAt:Bt},{id:"guide-tag-3",repoId:wl,name:"priority",color:"e4e669",description:null,createdAt:Bt}],VY={id:tc,name:"示例 Agent",description:"用于功能引导的演示 Agent",baseAgent:"Sisyphus - ultraworker",model:null,variant:null,systemPrompt:"",systemPromptPosition:0,isSystem:0,memoryModel:null,fragments:[],repoId:null,sortOrder:999,createdAt:Bt-7*Nn,updatedAt:Bt-Nn},WY=[{id:"guide-mem-1",customAgentId:tc,sessionId:"guide-session-1",mergedFrom:null,content:"用户偏好 TypeScript strict 模式,所有新文件必须启用 strictNullChecks",category:"编码规范",importance:.92,supersededBy:null,history:[{content:"用户使用 TypeScript",importance:.5,category:"编码规范",action:"create",ts:Bt-7*Nn},{content:"用户偏好 TypeScript strict 模式",importance:.75,category:"编码规范",action:"update",ts:Bt-3*Nn},{content:"用户偏好 TypeScript strict 模式,所有新文件必须启用 strictNullChecks",importance:.92,category:"编码规范",action:"reinforce",ts:Bt-Nn}],createdAt:Bt-7*Nn,updatedAt:Bt-Nn},{id:"guide-mem-2",customAgentId:tc,sessionId:"guide-session-2",mergedFrom:["guide-mem-old-1","guide-mem-old-2"],content:"项目使用 Tailwind CSS 4 + zustand 状态管理,组件优先使用函数式写法",category:"技术栈",importance:.85,supersededBy:null,history:[{content:"项目使用 Tailwind CSS",importance:.6,category:"技术栈",action:"create",ts:Bt-5*Nn},{content:"项目使用 Tailwind CSS 4 + zustand 状态管理,组件优先使用函数式写法",importance:.85,category:"技术栈",action:"merge",ts:Bt-2*Nn}],createdAt:Bt-5*Nn,updatedAt:Bt-2*Nn},{id:"guide-mem-3",customAgentId:tc,sessionId:"guide-session-1",mergedFrom:null,content:"Git 提交信息使用 conventional commits 格式",category:"工作流",importance:.45,supersededBy:null,history:[{content:"Git 提交信息使用 conventional commits 格式",importance:.7,category:"工作流",action:"create",ts:Bt-10*Nn},{content:"Git 提交信息使用 conventional commits 格式",importance:.45,category:"工作流",action:"decay",ts:Bt-4*Nn}],createdAt:Bt-10*Nn,updatedAt:Bt-4*Nn}];let Qt=null;function XY(e){Qt&&(e!=="dev"&&(Je.setState({issues:Qt.issues,tags:Qt.tags,loaded:Qt.issueLoaded,viewingIssueId:null,viewingTreeRootId:null}),mn.setState({pulls:Qt.pulls,loaded:Qt.prLoaded,viewingPrId:null})),e!=="agent"&&ia.setState({agents:Qt.agents}),e!=="run"&&Me.setState({sessions:Qt.sessions,activeSessionId:Qt.activeSessionId}))}function QY(e){if(!Qt){const t=Je.getState(),n=mn.getState(),r=ia.getState(),a=Me.getState();Qt={issues:t.issues,tags:t.tags,issueLoaded:t.loaded,pulls:n.pulls,prLoaded:n.loaded,agents:r.agents,sessions:a.sessions,activeSessionId:a.activeSessionId}}if(XY(e),e==="run"){const t=Qt.sessions.some(n=>n.id===YE);Me.setState({sessions:t?Qt.sessions:[...Qt.sessions,GY]})}else if(e==="dev")Je.setState({issues:bM,tags:KY,loaded:!0}),mn.setState({pulls:xM,loaded:!0});else if(e==="agent"){const t=Qt.agents.some(n=>n.id===tc);ia.setState({agents:t?Qt.agents:[...Qt.agents,VY]})}}function DA(){Qt&&(Je.setState({issues:Qt.issues,tags:Qt.tags,loaded:Qt.issueLoaded,viewingIssueId:null,viewingTreeRootId:null}),mn.setState({pulls:Qt.pulls,loaded:Qt.prLoaded,viewingPrId:null}),ia.setState({agents:Qt.agents}),Me.setState({sessions:Qt.sessions,activeSessionId:Qt.activeSessionId}),ZY("id"),Qt=null)}function yM(e,t){const n=new URL(window.location.href);n.searchParams.set(e,t),window.history.replaceState(null,"",n.toString()),window.dispatchEvent(new PopStateEvent("popstate"))}function ZY(e){const t=new URL(window.location.href);t.searchParams.has(e)&&(t.searchParams.delete(e),window.history.replaceState(null,"",t.toString()),window.dispatchEvent(new PopStateEvent("popstate")))}function JY(){const e=bM[0].id;Je.setState({viewingIssueId:e}),yM("id",e)}function eq(){const e=xM[0].id;mn.setState({viewingPrId:e}),yM("id",e)}function tq(){Me.setState({activeSessionId:YE})}function nq(){Me.setState({activeSessionId:null})}function rq(){return tc}const e1=[{target:'[data-guide="repo-switcher"]',title:"切换仓库",description:"点击这里可以在已注册的仓库之间快速切换。每个仓库拥有独立的 Agent 运行时和会话。",position:"bottom",section:"repos",padding:4},{target:'[data-guide="manage-repos"]',title:"管理仓库",description:"在仓库下拉菜单底部,点击「管理仓库」可以注册新仓库、启停 Agent 进程、配置运行时类型。",position:"bottom-right",section:"repos",padding:4,triggerClick:'[data-guide="repo-switcher"]'},{target:'[data-guide="repo-overflow-dropdown"]',title:"仓库高级操作",description:"每个仓库卡片的 ⋯ 菜单包含重要功能:切换运行时(OpenCode ↔ Claude Code)、开关 Worktree 任务隔离、编辑 AGENTS.md 配置。",position:"bottom-right",section:"repos",padding:4,route:"/repos",triggerClick:'[data-guide="repo-overflow-btn"]'},{target:'[data-guide="run-new-input"]',title:"新建对话",description:"选择 Agent 后输入指令开始任务。按 Tab 键可快速切换 Agent,底部可选择 Variant(默认 / max / high)控制推理强度。",position:"bottom",section:"run",padding:8,route:"run",mockScope:"run",setupFn:"clearActiveSession"},{target:'[data-guide="run-panel-handle"]',title:"运行记录面板",description:"拖动此手柄可收起/展开左侧运行记录列表。移动端可左右滑动打开。面板内可按「进行中 / 全部」筛选。",position:"bottom",section:"run",padding:6,mockScope:"run",setupFn:"clearActiveSession",mobileSwipeHint:"right"},{target:'[data-guide="run-input-bar"]',title:"快捷短语与追加输入",description:"对话进行中可在此追加指令。上方的快捷短语按钮(如「继续」)支持一键发送,可在设置 → 通用中自定义。底部可切换模型和 Variant。",position:"bottom",section:"run",padding:8,mockScope:"run",setupFn:"selectMockSession"},{target:'[data-guide="run-side-tabs"]',title:"右侧面板",description:"待办:Agent 的任务进度清单。输入:本次对话中你发送的所有消息。关联:Session 关联的 Issue 和 PR。子任务:Agent 派生的子 Session。",position:"bottom-right",section:"run",padding:6,mockScope:"run",setupFn:"selectMockSession",mobileSwipeHint:"left"},{target:'[data-guide="issue-sync-create"]',title:"同步与创建",description:"点击 ↻ 从 Git 平台同步 Issue 和 PR 数据(首次使用必须先同步)。点击 + 可直接创建新 Issue。",position:"bottom",section:"dev",padding:6,route:"dev/issues",mockScope:"dev"},{target:'[data-guide="issue-tag-filter"]',title:"标签筛选(三态)",description:"单击标签 → 包含筛选(高亮);再单击 → 排除筛选(划线);第三次单击 → 取消。支持同时选择多个标签组合筛选。",position:"bottom",section:"dev",padding:4,mockScope:"dev",triggerClick:'[data-guide="issue-tag-filter"]'},{target:'[data-guide="issue-actions"]',title:"Issue 操作",description:"查看源站、关闭/重新打开 Issue、新建 Agent 任务处理此 Issue。右侧面板按钮可展开运行记录侧边栏。",position:"bottom-right",section:"dev",padding:6,mockScope:"dev",setupFn:"selectMockIssue"},{target:'[data-guide="pr-actions"]',title:"PR 操作",description:"查看源站、合入 PR、解决冲突。当 PR 关联了 Issue 时,可选择合入并同时关闭关联的 Issues。",position:"bottom-right",section:"dev",padding:6,route:"dev/pulls",mockScope:"dev",setupFn:"selectMockPr"},{target:'[data-guide="agents-header"]',title:"创建与导入 Agent",description:"点击「创建」基于 base agent + 模型 + 提示词片段组合一个自定义 Agent。点击「导入」可从 JSON 文件恢复其他实例导出的 Agent。",position:"bottom-right",section:"agents",padding:6,route:"agents",mockScope:"agent"},{target:'[data-guide="agents-fragments"]',title:"提示词片段",description:"可复用的提示词模块,可在多个 Agent 间共享。创建 Agent 时选择片段并排序拼接顺序,构建最终的 System Prompt。",position:"bottom",section:"agents",padding:6,mockScope:"agent",triggerClick:'[data-guide="agents-fragments"]'},{target:'[data-guide="agent-detail-actions"]',title:"Agent 导出与共享",description:"下载或复制 Agent 的 JSON 配置,可在不同 Fourth Spark 实例间导入共享。包含提示词片段和所有配置。",position:"bottom-right",section:"agents",padding:4,route:"agents/__MOCK_AGENT__",mockScope:"agent"},{target:'[data-guide="agent-memory-section"]',title:"Agent 记忆",description:"Agent 在每次对话结束后自动提取经验记忆。每条记忆有分类标签和重要度评分(⚡)。系统定期自动整理:合并重复内容、衰减不活跃的记忆、强化反复验证的经验。",position:"bottom",section:"agents",padding:6,mockScope:"agent"},{target:'[data-guide="agent-memory-version"]',title:"记忆版本历史",description:"点击版本标签可查看这条记忆的完整演化轨迹:首次提取 → 内容重写 → 多条合并 → 反复验证后强化 → 长期未用后衰减。每个版本记录了当时的内容、重要度评分和触发动作。",position:"bottom",section:"agents",padding:4,mockScope:"agent"}];function aq(e){return e?e1.filter(t=>t.section===e):e1}function vM(e){if(e==="/repos"||e==="/settings")return"repos";const t=e.replace(/^\/[^/]+\//,"");return t.startsWith("run")?"run":t.startsWith("dev")?"dev":t.startsWith("agents")?"agents":null}const iq=6,jA=12,LA=200,PA=80,BA=288,UA=8,sq=768;function oq(e,t){const n=document.querySelector(e);if(!n)return null;const r=n.getBoundingClientRect();return r.width===0&&r.height===0||r.right<0||r.bottom<0||r.left>window.innerWidth||r.top>window.innerHeight?null:{top:r.top-t,left:r.left-t,width:r.width+t*2,height:r.height+t*2}}function lq(e){const{top:t,left:n,width:r,height:a}=e,i=n+r,o=t+a;return`polygon(
|
|
521
521
|
0% 0%, 100% 0%, 100% 100%, 0% 100%, 0% 0%,
|
|
522
522
|
${n}px ${t}px, ${n}px ${o}px, ${i}px ${o}px, ${i}px ${t}px, ${n}px ${t}px
|
|
523
|
-
)`}function uq(e,t){const n={position:"fixed"},r=window.innerWidth,a=window.innerHeight,i=e.top+e.height+jA,o=e.top-jA;let u=t==="bottom-right"?e.left+e.width-BA:e.left;return u=Math.max(UA,Math.min(u,r-BA-UA)),n.left=u,i+160<a?n.top=i:n.bottom=a-o,n}function Oy(e){const t=document.querySelector(e);t&&t.click()}const FA={selectMockIssue:JY,selectMockPr:eq,selectMockSession:tq,clearActiveSession:nq};function cq(){return window.innerWidth<sq}function dq({direction:e}){const t=e==="left"?ih:Oo;return c.jsx("div",{className:"pointer-events-none fixed inset-0 z-[9999] flex items-center justify-center",children:c.jsxs("div",{className:`flex items-center gap-1 rounded-full bg-blue-500/20 px-6 py-4 ${e==="left"?"fs-swipe-left":"fs-swipe-right"}`,children:[c.jsx(t,{className:"h-8 w-8 text-blue-400",strokeWidth:2.5}),c.jsx(t,{className:"h-8 w-8 text-blue-400/60",strokeWidth:2.5}),c.jsx(t,{className:"h-8 w-8 text-blue-400/30",strokeWidth:2.5})]})})}function fq({step:e,stepIdx:t,total:n,isFirst:r,isLast:a,onPrev:i,onNext:o,onClose:u}){return c.jsx("div",{className:"fixed inset-x-0 bottom-24 z-[10000] flex justify-center px-4",children:c.jsxs("div",{className:"w-72 rounded-xl border border-line bg-surface p-4 shadow-2xl",children:[c.jsx("button",{type:"button",onClick:u,className:"absolute right-2 top-2 rounded-md p-1 text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3","aria-label":"关闭引导",children:c.jsx(At,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:e.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:e.description}),c.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[c.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-fg-5",children:[t+1," / ",n]}),c.jsxs("div",{className:"flex items-center gap-2",children:[!r&&c.jsx("button",{type:"button",onClick:i,className:"rounded-md px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"上一步"}),c.jsx("button",{type:"button",onClick:o,className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:a?"完成":"下一步"})]})]})]})})}function hq(){const e=zn(),t=or(),n=ys(L=>L.guideTourOpen),r=ys(L=>L.guideTourSection),a=ys(L=>L.stopGuideTour),i=We(qr),[o,u]=y.useState(0),[d,f]=y.useState(null),m=y.useRef(null),p=y.useRef(-1),b=y.useRef(null),x=y.useMemo(()=>n?aq(r):e1,[n,r]),E=o<x.length?x[o]:void 0,N=x.length,_=o===0,S=o===N-1,C=y.useCallback(()=>{if(!n||!E)return;const L=E.padding??iq;f(oq(E.target,L))},[n,E]),A=y.useCallback(L=>{const B=L.replace("__MOCK_AGENT__",rq());return B.startsWith("/")?B:i?`/${encodeURIComponent(i)}/${B}`:`/${B}`},[i]);y.useEffect(()=>{n&&(u(0),p.current=-1)},[n]),y.useEffect(()=>{if(!n||!E)return;const L=p.current,B=L>=0?x[L]:null;B!=null&&B.triggerClick&&document.querySelector(B.target)&&Oy(B.triggerClick);const Y=(B==null?void 0:B.mockScope)??null,re=E.mockScope??null;re&&re!==Y?(QY(re),b.current=re):!re&&b.current&&(DA(),b.current=null);const X=E.route?A(E.route):null,K=X&&!t.pathname.startsWith(X);K&&e(X);const H=setTimeout(()=>{E.setupFn&&FA[E.setupFn]&&FA[E.setupFn](),setTimeout(()=>{E.triggerClick&&!document.querySelector(E.target)&&Oy(E.triggerClick),setTimeout(C,PA)},E.setupFn?LA:0)},K?LA:re&&re!==Y?PA:0);return p.current=o,()=>clearTimeout(H)},[n,o,E,e,t.pathname,C,A,x]),y.useLayoutEffect(()=>{C()},[C]),y.useEffect(()=>{if(n)return window.addEventListener("resize",C),window.addEventListener("scroll",C,!0),()=>{window.removeEventListener("resize",C),window.removeEventListener("scroll",C,!0)}},[n,C]);const I=y.useRef(o);I.current=o;const O=y.useRef(x);O.current=x;const k=y.useCallback(()=>{const L=O.current[I.current];L!=null&&L.triggerClick&&document.querySelector(L.target)&&Oy(L.triggerClick),b.current&&(DA(),b.current=null),a()},[a]);if(y.useEffect(()=>{if(!n)return;const L=B=>{B.key==="Escape"&&k()};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[n,k]),!n||!E)return null;const j=cq()&&E.mobileSwipeHint&&!d;if(!d&&!j)return null;const F=()=>{_||u(L=>L-1)},P=()=>{S?k():u(L=>L+1)};return j?gs.createPortal(c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"fixed inset-0 z-[9998] bg-black/60",onClick:k}),c.jsx(dq,{direction:E.mobileSwipeHint}),c.jsx(fq,{step:E,stepIdx:o,total:N,isFirst:_,isLast:S,onPrev:F,onNext:P,onClose:k})]}),document.body):gs.createPortal(c.jsxs("div",{className:"fixed inset-0 z-[9999]",children:[c.jsx("div",{className:"absolute inset-0 bg-black/60 transition-[clip-path] duration-200",style:{clipPath:lq(d)},onClick:k}),c.jsx("div",{className:"pointer-events-none absolute rounded-lg ring-2 ring-blue-500 ring-offset-2 ring-offset-transparent transition-all duration-200",style:{top:d==null?void 0:d.top,left:d==null?void 0:d.left,width:d==null?void 0:d.width,height:d==null?void 0:d.height}}),c.jsxs("div",{ref:m,className:"fixed z-[10000] w-72 rounded-xl border border-line bg-surface p-4 shadow-2xl",style:uq(d,E.position),children:[c.jsx("button",{type:"button",onClick:k,className:"absolute right-2 top-2 rounded-md p-1 text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3","aria-label":"关闭引导",children:c.jsx(At,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:E.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:E.description}),c.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[c.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-fg-5",children:[o+1," / ",N]}),c.jsxs("div",{className:"flex items-center gap-2",children:[!_&&c.jsx("button",{type:"button",onClick:F,className:"rounded-md px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"上一步"}),c.jsx("button",{type:"button",onClick:P,className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:S?"完成":"下一步"})]})]})]})]}),document.body)}const EM=[{segment:"run",icon:LE,label:"运行面板",global:!1},{segment:"dev/issues",icon:Ez,label:"研发",global:!1,matchPrefix:"dev"},{segment:"agents",icon:QF,label:"Agents",global:!1}];function NM(e,t,n){return t?`/${e}`:n?`/${encodeURIComponent(n)}/${e}`:`/${e}`}function SM(e,t,n){if(!e.matchPrefix)return!1;const r=e.global?`/${e.matchPrefix}`:n?`/${encodeURIComponent(n)}/${e.matchPrefix}`:null;return r?t===r||t.startsWith(`${r}/`):!1}function mq(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function pq({repos:e,activeRepoId:t,onRepoChange:n}){const r=zn(),[a,i]=y.useState(!1),[o,u]=y.useState(-1),d=y.useRef(null),f=e.find(b=>b.id===t),m=y.useCallback(()=>{i(!1),u(-1)},[]);y.useEffect(()=>{if(!a)return;const b=x=>{d.current&&!d.current.contains(x.target)&&m()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[a,m]);const p=y.useCallback(b=>{if(a)switch(b.key){case"Escape":b.preventDefault(),m();break;case"ArrowDown":b.preventDefault(),u(x=>Math.min(x+1,e.length-1));break;case"ArrowUp":b.preventDefault(),u(x=>Math.max(x-1,0));break;case"Enter":o>=0&&o<e.length&&(b.preventDefault(),n(e[o].id),m());break}},[a,m,o,e,n]);return c.jsxs("div",{ref:d,className:"relative",onKeyDown:p,children:[c.jsxs("button",{type:"button","data-guide":"repo-switcher",onClick:()=>i(b=>!b),"aria-label":"切换仓库","aria-haspopup":"listbox","aria-expanded":a,className:"flex max-w-[140px] items-center gap-1 rounded-md border border-line bg-base px-2 py-1 text-xs text-fg-2 transition-colors hover:border-blue-500 sm:max-w-[200px]",children:[c.jsx(FR,{className:"h-3 w-3 shrink-0 text-fg-4"}),c.jsxs("span",{className:"truncate",children:[c.jsx("span",{className:"sm:hidden",children:f?mq(f.name):""}),c.jsx("span",{className:"hidden sm:inline",children:(f==null?void 0:f.name)??""})]}),c.jsx(kr,{className:ie("h-3 w-3 shrink-0 text-fg-4 transition-transform",a&&"rotate-180")})]}),a&&c.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-64 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[c.jsx("div",{role:"listbox","aria-label":"仓库列表",className:"max-h-64 overflow-y-auto py-1",children:e.map((b,x)=>c.jsxs("button",{type:"button",role:"option","aria-selected":b.id===t,onClick:()=>{n(b.id),m()},className:ie("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",b.id===t?"font-medium text-blue-600":"text-fg-2 hover:bg-elevated",o===x&&"bg-elevated"),children:[b.id===t?c.jsx(fi,{className:"h-3 w-3 shrink-0"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:b.name})]},b.id))}),c.jsx("div",{className:"border-t border-line",children:c.jsxs("button",{type:"button","data-guide":"manage-repos",onClick:()=>{r("/repos"),m()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:[c.jsx(r0,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"管理仓库"})]})})]})]})}function gq({repoId:e,currentBranch:t}){const n=We(S=>S.updateRepoBranch),[r,a]=y.useState(!1),[i,o]=y.useState(null),[u,d]=y.useState(!1),[f,m]=y.useState(null),[p,b]=y.useState(null),x=y.useRef(null),E=y.useCallback(()=>{a(!1),b(null)},[]);y.useEffect(()=>{if(!r)return;const S=C=>{x.current&&!x.current.contains(C.target)&&E()};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[r,E]);const N=async()=>{if(r){E();return}a(!0),d(!0),b(null);try{o(await d$(e))}catch{b("加载分支失败")}finally{d(!1)}},_=async S=>{if(!(S===t||f)){m(S),b(null);try{const C=await f$(e,S);n(e,C.branch),E()}catch(C){b(C instanceof Error?C.message:"切换失败")}finally{m(null)}}};return t?c.jsxs("div",{ref:x,className:"relative",children:[c.jsxs("button",{type:"button",onClick:N,className:"flex items-center gap-1 rounded-md bg-elevated px-2 py-1 text-xs text-fg-3 transition-colors hover:bg-blue-500/10 hover:text-blue-600",children:[c.jsx(Gl,{className:"h-3 w-3"}),t,c.jsx(kr,{className:ie("h-3 w-3 transition-transform",r&&"rotate-180")})]}),r&&c.jsxs("div",{className:"absolute right-0 top-full z-50 mt-1 w-56 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[u?c.jsx("div",{className:"flex items-center justify-center py-4",children:c.jsx(nn,{className:"h-4 w-4 animate-spin text-fg-4"})}):i?c.jsxs("div",{className:"max-h-64 overflow-y-auto py-1",children:[i.local.map(S=>c.jsxs("button",{type:"button",disabled:f!==null,onClick:()=>_(S),className:ie("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",S===t?"font-medium text-blue-600":"text-fg-2 hover:bg-elevated"),children:[S===t?c.jsx(fi,{className:"h-3 w-3 shrink-0"}):f===S?c.jsx(nn,{className:"h-3 w-3 shrink-0 animate-spin"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:S})]},S)),i.remote.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"mx-3 my-1 border-t border-line"}),c.jsx("div",{className:"px-3 py-1 text-[10px] font-medium uppercase tracking-wider text-fg-4",children:"Remote"}),i.remote.map(S=>c.jsxs("button",{type:"button",disabled:f!==null,onClick:()=>_(S),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[f===S?c.jsx(nn,{className:"h-3 w-3 shrink-0 animate-spin"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:S})]},`remote-${S}`))]})]}):null,p&&c.jsx("div",{className:"border-t border-line px-3 py-2 text-xs text-red-500",children:p})]})]}):null}function bq(){const[e,t]=y.useState(null);return y.useEffect(()=>{const n=()=>fetch("/api/health").then(i=>i.json()).then(i=>{i.latestVersion&&i.latestVersion!=="0.11.38"&&t(i.latestVersion)}).catch(()=>{});n();const r=setInterval(n,RY),a=()=>n();return window.addEventListener("focus",a),()=>{clearInterval(r),window.removeEventListener("focus",a)}},[]),e}function xq({navigate:e,cycle:t,themeLabel:n,ThemeIcon:r}){const[a,i]=y.useState(!1),o=y.useRef(null);return y.useEffect(()=>{if(!a)return;const u=d=>{o.current&&!o.current.contains(d.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[a]),c.jsxs("div",{ref:o,className:"relative md:hidden",children:[c.jsx("button",{type:"button",onClick:()=>i(u=>!u),"aria-label":"更多",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(kz,{className:"h-4 w-4"})}),a&&c.jsxs("div",{className:"absolute right-0 top-full z-50 mt-1 w-40 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[c.jsxs("button",{type:"button",onClick:()=>{e("/analytics"),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(ah,{className:"h-3.5 w-3.5 text-fg-4"}),"统计"]}),c.jsxs("button",{type:"button",onClick:()=>{e("/settings"),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(r0,{className:"h-3.5 w-3.5 text-fg-4"}),"设置"]}),c.jsxs("button",{type:"button",onClick:()=>{t(),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(r,{className:"h-3.5 w-3.5 text-fg-4"}),n]}),c.jsxs("a",{href:"https://github.com/kinminghao/fourth-spark",target:"_blank",rel:"noopener noreferrer",onClick:()=>i(!1),className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx("svg",{className:"h-3.5 w-3.5 text-fg-4",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})}),"GitHub"]}),c.jsxs("button",{type:"button",onClick:()=>{ys.getState().startGuideTour(vM(window.location.pathname)),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(zR,{className:"h-3.5 w-3.5 text-fg-4"}),"功能引导"]})]})]})}function yq(){const e=zn(),t=or(),n=We(p=>p.repos),r=We(p=>p.activeRepoId),a=We(p=>p.setActiveRepo),i=Zv(p=>p.preference),o=Zv(p=>p.cycle),u=i==="light"?YH:i==="dark"?SH:EH,d=n.find(p=>p.id===r),f=bq(),m=p=>{var N;if(!p)return;a(p);const b=n.find(_=>_.id===p);if(!b)return;const x=t.pathname.match(/\/dev\/(issues|pulls)/);if(x){e(`/${encodeURIComponent(b.name)}/dev/${x[1]}`);return}const E=((N=t.pathname.match(/\/(run|agents|issues|pulls)/))==null?void 0:N[1])??"run";e(`/${encodeURIComponent(b.name)}/${E}`)};return c.jsxs("header",{className:"shrink-0 border-b border-line bg-surface pt-[var(--safe-top)]",children:[c.jsxs("div",{className:"flex h-12 items-center justify-between px-4",children:[c.jsxs("div",{className:"flex items-center gap-2.5",children:[c.jsx(Cc,{className:"h-5 w-5 text-blue-500"}),c.jsx("span",{className:"hidden text-sm font-bold tracking-tight text-fg sm:inline",children:"Fourth Spark"}),c.jsxs("span",{className:"hidden rounded bg-elevated px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-fg-4 sm:inline",children:["v","0.11.38"]}),f&&c.jsxs("span",{className:"hidden text-[10px] text-amber-500 sm:inline",children:["→ v",f," 可用,运行"," ",c.jsx("code",{className:"rounded bg-amber-500/10 px-1 font-mono",children:"fourth-spark upgrade"})," 更新"]})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[n.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(pq,{repos:n,activeRepoId:r,onRepoChange:m}),d&&r&&c.jsx(gq,{repoId:r,currentBranch:d.branch})]}),c.jsxs("div",{className:"hidden items-center gap-1 md:flex",children:[c.jsx("button",{type:"button",onClick:()=>e("/analytics"),"aria-label":"统计",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(ah,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>e("/settings"),"aria-label":"设置",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(r0,{className:"h-4 w-4"})}),c.jsx("a",{href:"https://github.com/kinminghao/fourth-spark",target:"_blank",rel:"noopener noreferrer","aria-label":"GitHub",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})})}),c.jsx("button",{type:"button",onClick:o,"aria-label":`主题: ${i}`,className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(u,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>ys.getState().startGuideTour(vM(t.pathname)),"aria-label":"功能引导",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(zR,{className:"h-4 w-4"})})]}),c.jsx(xq,{navigate:e,cycle:o,themeLabel:`主题: ${i}`,ThemeIcon:u})]})]}),f&&c.jsx("div",{className:"border-t border-line px-4 py-1.5 sm:hidden",children:c.jsxs("span",{className:"text-[10px] text-amber-500",children:["→ v",f," 可用,运行"," ",c.jsx("code",{className:"rounded bg-amber-500/10 px-1 font-mono",children:"fourth-spark upgrade"})," 更新"]})})]})}function vq(){const e=We(qr),t=ys(a=>a.navCollapsed),n=ys(a=>a.toggleNav),r=or();return c.jsxs("nav",{className:ie("hidden shrink-0 flex-col border-r border-line bg-surface py-2 transition-[width] duration-200 ease-in-out md:flex",t?"w-14":"w-48"),children:[c.jsx("div",{className:"flex flex-1 flex-col",children:EM.map(a=>{const i=SM(a,r.pathname,e);return c.jsxs(Hp,{to:NM(a.segment,a.global,e),title:t?a.label:void 0,className:({isActive:o})=>ie("mx-2 flex items-center rounded-md py-2 text-sm transition-colors",t?"justify-center px-2":"gap-2.5 px-3",o||i?"bg-blue-500/10 font-medium text-blue-600":"text-fg-3 hover:bg-elevated hover:text-fg"),children:[c.jsx(a.icon,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:ie("truncate transition-[opacity,max-width] duration-200 ease-in-out",t?"max-w-0 opacity-0":"max-w-[8rem] opacity-100"),children:a.label})]},a.segment)})}),c.jsxs(Hp,{to:"/settings",title:t?"设置":void 0,className:({isActive:a})=>ie("mx-2 flex items-center rounded-md py-2 text-sm transition-colors",t?"justify-center px-2":"gap-2.5 px-3",a?"bg-blue-500/10 font-medium text-blue-600":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:[c.jsx(r0,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:ie("truncate transition-[opacity,max-width] duration-200 ease-in-out",t?"max-w-0 opacity-0":"max-w-[8rem] opacity-100"),children:"设置"})]}),c.jsx("button",{type:"button",onClick:n,title:t?"展开导航":"收起导航",className:"mx-2 flex items-center justify-center rounded-md py-2 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:t?c.jsx(uz,{className:"h-4 w-4"}):c.jsx(oz,{className:"h-4 w-4"})})]})}function Eq(){const e=We(qr),t=or();return c.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-30 border-t border-line bg-surface pb-[var(--safe-bottom)] md:hidden",children:c.jsx("div",{className:"flex h-14 items-center justify-around",children:EM.map(n=>{const r=SM(n,t.pathname,e);return c.jsx(Hp,{to:NM(n.segment,n.global,e),"aria-label":n.label,className:({isActive:a})=>ie("flex h-10 w-10 items-center justify-center rounded-md transition-colors",a||r?"bg-blue-500/10 text-blue-600":"text-fg-3 hover:bg-elevated hover:text-fg"),children:c.jsx(n.icon,{className:"h-5 w-5 shrink-0"})},n.segment)})})})}function Nq(){return c.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-base text-fg",children:[c.jsx(yq,{}),c.jsxs("div",{className:"flex min-h-0 flex-1",children:[c.jsx(vq,{}),c.jsx("main",{className:"flex min-w-0 flex-1 flex-col overflow-hidden pb-[calc(3.5rem_+_var(--safe-bottom))] md:pb-0",children:c.jsx(Z7,{})})]}),c.jsx(Eq,{}),c.jsx(hq,{})]})}let Sq=0;const ar=$i(e=>({toasts:[],addToast:(t,n="info",r,a)=>{const i=(a==null?void 0:a.id)??`toast-${++Sq}-${Date.now()}`;e(o=>o.toasts.some(u=>u.id===i)?o:{toasts:[...o.toasts,{id:i,message:t,variant:n,sessionId:r,persistent:a==null?void 0:a.persistent}]}),a!=null&&a.persistent||setTimeout(()=>{e(o=>({toasts:o.toasts.filter(u=>u.id!==i)}))},uM)},removeToast:t=>{e(n=>({toasts:n.toasts.filter(r=>r.id!==t)}))}})),wq={info:{icon:"ℹ",badge:"bg-fg/10 text-fg-2",bar:"bg-fg-4"},success:{icon:"✓",badge:"bg-emerald-500/10 text-emerald-500",bar:"bg-emerald-500"},warning:{icon:"⚠",badge:"bg-amber-500/10 text-amber-500",bar:"bg-amber-500"},error:{icon:"✕",badge:"bg-red-500/10 text-red-500",bar:"bg-red-500"}};function zA(){const e=ar(m=>m.toasts),t=ar(m=>m.removeToast),n=Me(m=>m.setActiveSession),r=We(m=>m.activeRepoId),a=We(qr),i=zn(),o=m=>{t(m.id),m.sessionId&&r&&(n(r,m.sessionId),i(`/${encodeURIComponent(a)}/run`))},[u,d]=y.useState([]),f=y.useRef(new Map);return y.useEffect(()=>{const m=new Set(e.map(p=>p.id));d(p=>{let b=p.map(x=>m.has(x.id)||x.exiting?x:{...x,exiting:!0});for(const x of e)b.some(E=>E.id===x.id)||(b=[...b,{...x}]);return b})},[e]),y.useEffect(()=>{const m=f.current;for(const p of u)p.exiting&&!m.has(p.id)&&m.set(p.id,setTimeout(()=>{m.delete(p.id),d(b=>b.filter(x=>x.id!==p.id))},_Y))},[u]),y.useEffect(()=>{const m=f.current;return()=>m.forEach(clearTimeout)},[]),u.length===0?null:c.jsx("div",{className:"pointer-events-none fixed top-4 right-4 z-50 flex w-[calc(100%-2rem)] max-w-sm flex-col",role:"status","aria-live":"polite","aria-atomic":"false",children:u.map(m=>{const p=wq[m.variant];return c.jsx("div",{className:"grid w-full transition-[grid-template-rows] duration-300 ease-out",style:{gridTemplateRows:m.exiting?"0fr":"1fr"},children:c.jsx("div",{className:"min-h-0 overflow-hidden",children:c.jsxs("div",{role:"status",onClick:()=>o(m),style:{animation:`${m.exiting?"toast-out":"toast-in"} 0.3s ease-out forwards`},className:"pointer-events-auto relative mb-2 flex cursor-pointer items-start gap-3 overflow-hidden rounded-xl border border-line bg-surface/80 px-3.5 py-3 shadow-lg shadow-black/5 backdrop-blur-md transition-colors hover:border-line-hard hover:bg-surface/90",children:[c.jsx("span",{"aria-hidden":!0,className:`mt-px flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-xs font-semibold ${p.badge}`,children:p.icon}),c.jsx("p",{className:"min-w-0 flex-1 text-sm leading-snug break-words text-fg",children:m.message}),m.persistent&&!m.exiting&&c.jsx("button",{type:"button","aria-label":"关闭",onClick:b=>{b.stopPropagation(),t(m.id)},className:"mt-px flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-fg-4 transition-colors hover:bg-fg/10 hover:text-fg",children:"✕"}),!m.exiting&&!m.persistent&&c.jsx("span",{"aria-hidden":!0,className:`absolute bottom-0 left-0 h-0.5 w-full origin-left ${p.bar}`,style:{animation:`toast-progress ${uM}ms linear forwards`}})]})})},m.id)})})}const _q=1e3,Tq=5e3,Jm="freeze-mon-buffer",Aq=4*1024*1024;class Cq{constructor(){pt(this,"ring",[]);pt(this,"counters",{sse:0,delta:0,store:0});pt(this,"workerCount",0);pt(this,"sampleTimer",0);pt(this,"persistTimer",0);pt(this,"running",!1)}tick(t){this.counters[t]++}setGauge(t,n){t==="workers"&&(this.workerCount=n)}exportData(){return localStorage.getItem(Jm)??JSON.stringify(this.ring)}start(){if(this.running)return;this.running=!0;const t=localStorage.getItem(Jm);if(t)try{this.ring=JSON.parse(t)}catch{this.ring=[]}this.sampleTimer=window.setInterval(()=>this.sample(),_q),this.persistTimer=window.setInterval(()=>this.persist(),Tq)}stop(){this.running=!1,clearInterval(this.sampleTimer),clearInterval(this.persistTimer),this.persist()}sample(){const t=Me.getState(),n=Object.values(t.messages).reduce((a,i)=>a+i.length,0),r=performance.memory;this.ring.push({ts:Date.now(),sse:this.counters.sse,delta:this.counters.delta,store:this.counters.store,workers:this.workerCount,msgs:n,heap:r?Math.round(r.usedJSHeapSize/1048576):void 0}),this.counters.sse=0,this.counters.delta=0,this.counters.store=0,this.trimToFit()}trimToFit(){for(;this.ring.length>1&&!(new Blob([JSON.stringify(this.ring)]).size<=Aq);)this.ring.shift()}persist(){try{localStorage.setItem(Jm,JSON.stringify(this.ring))}catch{this.ring.splice(0,Math.floor(this.ring.length/2));try{localStorage.setItem(Jm,JSON.stringify(this.ring))}catch{}}}}const vs=new Cq;function kq(e){if(typeof e!="string")return e;const t=e.trim();if(t)try{return JSON.parse(t)}catch{return t}}function ir(e){return e&&typeof e=="object"?e:null}function Kl(e){const t=ir(e);return t&&"properties"in t?t.properties:e}function Oq(e){const t=ir(e);return typeof(t==null?void 0:t.type)=="string"?t.type:void 0}function Iq(e){const t=ir(Kl(e));if(!t)return null;const n=ir(t.info);if(n&&typeof n.id=="string"){const a=Array.isArray(t.parts)?t.parts:void 0;return{...n,...a?{parts:a}:{}}}if(typeof t.id=="string"&&typeof t.role=="string")return t;const r=ir(t.message);return r&&typeof r.id=="string"?r:null}function Rq(e){const t=ir(Kl(e));if(!t)return{};const n=ir(t.part)??t;return typeof n.type!="string"?{}:{messageId:typeof n.messageID=="string"&&n.messageID||typeof n.messageId=="string"&&n.messageId||typeof t.messageID=="string"&&t.messageID||typeof t.messageId=="string"&&t.messageId||void 0,part:n}}function wM(e){const t=ir(Kl(e));if(!t||t.field!=="text")return null;const n=typeof t.messageID=="string"?t.messageID:null,r=typeof t.partID=="string"?t.partID:null,a=typeof t.delta=="string"?t.delta:null;return!n||!r||a===null?null:{messageId:n,partId:r,delta:a}}function Mq(e){const t=Kl(e);if(Array.isArray(t))return t;const n=ir(t);return n&&Array.isArray(n.todos)?n.todos:[]}function wi(e){return typeof e=="number"?e:0}function Dq(e){const t=ir(Kl(e));if(!t||typeof t.id!="string")return null;const n={id:t.id},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:wi(i==null?void 0:i.input)||wi(t.tokens_input),output:wi(i==null?void 0:i.output)||wi(t.tokens_output),reasoning:wi(i==null?void 0:i.reasoning)||wi(t.tokens_reasoning),cache:{read:wi(d==null?void 0:d.read)||wi(t.tokens_cache_read),write:wi(d==null?void 0:d.write)||wi(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 jq(e){const t=ir(Kl(e));if(!t)return null;if(typeof t.message=="string")return t.message;const n=ir(t.error);if(n){const r=ir(n.data);if(typeof(r==null?void 0:r.message)=="string")return`${n.name??"Error"}: ${r.message}`;if(typeof n.message=="string")return`${n.name??"Error"}: ${n.message}`;if(typeof n.name=="string")return String(n.name)}return typeof t.reason=="string"?t.reason:null}function Lq(e){const t=Kl(e);if(typeof t=="string")return t;const n=ir(t);if(typeof(n==null?void 0:n.status)=="string")return n.status;const r=ir(n==null?void 0:n.status);return typeof(r==null?void 0:r.type)=="string"?r.type:typeof(n==null?void 0:n.type)=="string"?n.type:null}function HA(e,t,n,r){switch(e==="message"||e===""?Oq(t)??e:e){case"message.updated":{const i=Iq(t);i&&r.updateMessage(n,i);break}case"session.updated":{const i=Dq(t);i&&r.updateSessionInfo(i);break}case"message.part.updated":{const{messageId:i,part:o}=Rq(t);o&&i&&r.updateMessagePart(n,i,o);break}case"message.part.delta":{const i=wM(t);i&&r.appendMessagePartDelta(n,i.messageId,i.partId,i.delta);break}case"todo.updated":{r.updateTodos(n,Mq(t));break}case"session.status":{const i=Lq(t);i&&r.setSessionStatus(n,i);break}case"session.idle":{r.setSessionStatus(n,"idle");break}case"session.error":{const i=jq(t);r.setSessionStatus(n,"error",i??void 0);break}}}const Pq=1e3,Bq=3e4;class Uq{constructor(t,n){pt(this,"source",null);pt(this,"reconnectTimer",null);pt(this,"attempts",0);pt(this,"disposed",!1);pt(this,"repoId");pt(this,"onEvent");this.repoId=t,this.onEvent=n}start(){this.connect()}stop(){var t;this.disposed=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(t=this.source)==null||t.close(),this.source=null}connect(){if(this.disposed)return;const t=dY(this.repoId),n=new EventSource(t);this.source=n,n.onopen=()=>{this.attempts=0},n.onmessage=a=>{this.handleRaw("message",a)};const r=["message.updated","message.part.updated","message.part.delta","message.removed","todo.updated","session.status","session.idle","session.error","session.updated"];for(const a of r)n.addEventListener(a,i=>{this.handleRaw(a,i)});n.onerror=()=>{if(!(this.disposed||!this.source)&&this.source.readyState===EventSource.CLOSED){this.source.close(),this.source=null;const a=Math.min(Pq*2**this.attempts,Bq);this.attempts++,this.reconnectTimer=setTimeout(()=>this.connect(),a)}}}handleRaw(t,n){if(!(n instanceof MessageEvent))return;vs.tick("sse");const r=kq(n.data);if(r===void 0)return;const a=this.extractSessionId(r);if(!a)return;let i=t;if(t==="message"||t===""){const o=r&&typeof r=="object"?r:null;typeof(o==null?void 0:o.type)=="string"&&(i=o.type)}this.onEvent(a,i,r)}extractSessionId(t){if(!t||typeof t!="object")return null;const n=t;if(n.properties&&typeof n.properties=="object"){const r=n.properties;if(typeof r.sessionID=="string")return r.sessionID;if(typeof r.id=="string")return r.id}return typeof n.sessionID=="string"?n.sessionID:typeof n.sessionId=="string"?n.sessionId:null}}const Fq=6e4;class zq{constructor(t,n){pt(this,"timer",null);pt(this,"paused",!1);pt(this,"repoId");pt(this,"callbacks");this.repoId=t,this.callbacks=n}start(){this.tick(),this.timer=setInterval(()=>{this.paused||this.tick()},Fq)}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}pause(){this.paused=!0}resume(){this.paused=!1,this.tick()}tick(){const t=this.repoId;Me.getState().loadSessions(t),fY(t).then(n=>{const r={};for(const[a,i]of Object.entries(n))r[a]=i.type??"idle";Me.getState().bulkSetStatuses(r);for(const[a,i]of Object.entries(r))(i==="busy"||i==="retry")&&this.callbacks.ensureWorker(a)}).catch(()=>{})}}const Hq=600*1e3,$q=200;class Yq{constructor(t,n,r){pt(this,"sessionId");pt(this,"repoId");pt(this,"idleTimer",null);pt(this,"flushTimer",null);pt(this,"active",!1);pt(this,"alive",!0);pt(this,"callbacks");pt(this,"eventQueue",[]);pt(this,"deltaBuffer",new Map);this.sessionId=t,this.repoId=n,this.callbacks=r,this.resetIdleTimer()}dispatch(t,n){if(this.alive){if(this.resetIdleTimer(),vs.tick("sse"),t==="message.part.delta"){this.bufferDelta(n),this.scheduleFlush();return}if(t==="session.idle"||t==="session.status"||t==="session.error"){this.flush();const r=Me.getState(),a=r.sessionStatuses[this.sessionId];HA(t,n,this.sessionId,r);const i=Me.getState().sessionStatuses[this.sessionId];a&&a!=="idle"&&i==="idle"&&this.callbacks.onSessionIdle(this.sessionId);return}this.eventQueue.push({name:t,data:n}),this.scheduleFlush()}}activate(){this.active=!0,this.clearIdleTimer()}deactivate(){this.active=!1,this.resetIdleTimer()}refreshOnIdle(){Me.getState().refreshSessionData(this.repoId,this.sessionId)}stop(){this.alive=!1,this.flush(),this.clearIdleTimer(),this.cancelFlush()}scheduleFlush(){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.flush()},$q))}cancelFlush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null)}bufferDelta(t){const n=wM(t);if(!n)return;const r=this.deltaBuffer.get(n.partId);r?r.text+=n.delta:this.deltaBuffer.set(n.partId,{messageId:n.messageId,text:n.delta})}flush(){if(this.eventQueue.length===0&&this.deltaBuffer.size===0)return;const t=Me.getState(),n=this.eventQueue;this.eventQueue=[];for(const r of n)HA(r.name,r.data,this.sessionId,t);if(this.deltaBuffer.size>0){const r=this.deltaBuffer;this.deltaBuffer=new Map;for(const[a,{messageId:i,text:o}]of r)vs.tick("delta"),vs.tick("store"),t.appendMessagePartDelta(this.sessionId,i,a,o)}}resetIdleTimer(){this.clearIdleTimer(),!this.active&&(this.idleTimer=setTimeout(()=>{this.callbacks.onWorkerIdle(this.sessionId)},Hq))}clearIdleTimer(){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null)}}class qq{constructor(){pt(this,"workers",new Map);pt(this,"dispatcher",null);pt(this,"supervisor",null);pt(this,"visibilityHandler",null);pt(this,"repoId",null)}start(t){this.stop(),this.repoId=t;const n={onWorkerIdle:r=>this.removeWorker(r),onSessionIdle:r=>{var a;(a=this.workers.get(r))==null||a.refreshOnIdle()}};this.dispatcher=new Uq(t,(r,a,i)=>{this.ensureWorker(r,t,n).dispatch(a,i)}),this.dispatcher.start(),this.supervisor=new zq(t,{ensureWorker:r=>this.ensureWorker(r,t,n)}),this.supervisor.start(),this.visibilityHandler=()=>{var r,a;document.hidden?(r=this.supervisor)==null||r.pause():(a=this.supervisor)==null||a.resume()},document.addEventListener("visibilitychange",this.visibilityHandler)}stop(){var t,n;(t=this.dispatcher)==null||t.stop(),this.dispatcher=null,(n=this.supervisor)==null||n.stop(),this.supervisor=null;for(const r of this.workers.values())r.stop();this.workers.clear(),this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null)}activateSession(t){if(!this.repoId||!t)return;const n=this.repoId;for(const i of this.workers.values())i.sessionId!==t&&i.deactivate();const r={onWorkerIdle:i=>this.removeWorker(i),onSessionIdle:i=>{var o;return(o=this.workers.get(i))==null?void 0:o.refreshOnIdle()}};this.ensureWorker(t,n,r).activate(),Me.getState().refreshSessionData(n,t)}deactivateSession(t){var n;(n=this.workers.get(t))==null||n.deactivate()}ensureWorker(t,n,r){let a=this.workers.get(t);return a||(a=new Yq(t,n,r),this.workers.set(t,a),vs.setGauge("workers",this.workers.size)),a}removeWorker(t){const n=Me.getState().activeSessionId;if(t===n)return;const r=this.workers.get(t);r&&(r.stop(),this.workers.delete(t),vs.setGauge("workers",this.workers.size))}}const Vp=new qq;function oh({onConfirm:e,size:t="sm",variant:n="ghost",triggerClassName:r,stopPropagation:a,title:i="删除",children:o}){const[u,d]=y.useState(!1),f=t==="sm"?"h-3.5 w-3.5":"h-4 w-4",m=t==="sm"?"p-1":"p-1.5",p=n==="outlined"?"rounded-md":"rounded",b=t==="sm"?"gap-0.5":"gap-1",x=a?E=>E.stopPropagation():void 0;return u?c.jsxs("div",{className:ie("flex items-center",b),onClick:x,children:[c.jsx("button",{type:"button",onClick:()=>{e(),d(!1)},className:ie(p,m,"text-red-400 hover:bg-red-500/10",n==="outlined"&&"border border-red-500/30"),children:c.jsx(fi,{className:f})}),c.jsx("button",{type:"button",onClick:()=>d(!1),className:ie(p,m,"text-fg-4 hover:bg-elevated",n==="outlined"&&"border border-line"),children:c.jsx(At,{className:f})})]}):c.jsxs(c.Fragment,{children:[o,c.jsx("button",{type:"button",onClick:E=>{x==null||x(E),d(!0)},title:i,className:ie(p,m,r??"text-fg-5 hover:text-red-400",n==="outlined"&&"border border-line transition-colors hover:border-red-500/30"),children:c.jsx(a0,{className:f})})]})}function Gq(e,t){if(e instanceof Li)try{const n=JSON.parse(e.message);if(n.error)return n.error}catch{if(e.message)return e.message}return e instanceof Error?e.message:t}function lc(e,t,n){const{initialData:r,showErrorToast:a=!0,errorMessage:i="加载失败",skip:o=!1}=n??{},[u,d]=y.useState(r??null),[f,m]=y.useState(!o),[p,b]=y.useState(null),x=y.useRef(0),E=y.useRef(e);E.current=e;const N=y.useRef(i);N.current=i;const _=y.useRef(a);_.current=a;const S=y.useCallback(async()=>{const C=++x.current;m(!0),b(null);try{const A=await E.current();if(x.current!==C)return;d(A)}catch(A){if(x.current!==C)return;const I=Gq(A,N.current);b(I),_.current&&ar.getState().addToast(I,"error")}x.current===C&&m(!1)},[]);return y.useEffect(()=>{if(o){m(!1);return}return S(),()=>{x.current++}},[...t,o,S]),{data:u,loading:f,error:p,reload:S}}const Kq=["Sisyphus - ultraworker","Prometheus - Plan Builder","Atlas - Plan Executor"],Vq="pinned_models",il="__system_prompt__",$A=[{bg:"bg-blue-500/10",text:"text-blue-400"},{bg:"bg-amber-500/10",text:"text-amber-400"},{bg:"bg-green-500/10",text:"text-green-400"},{bg:"bg-purple-500/10",text:"text-purple-400"},{bg:"bg-cyan-500/10",text:"text-cyan-400"},{bg:"bg-rose-500/10",text:"text-rose-400"},{bg:"bg-indigo-500/10",text:"text-indigo-400"},{bg:"bg-orange-500/10",text:"text-orange-400"}],Wq={bg:"bg-elevated",text:"text-fg-4"};function _M(e){if(e==="general")return Wq;let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return $A[Math.abs(t)%$A.length]}function uc(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"刚刚";if(n<60)return`${n} 分钟前`;const r=Math.floor(n/60);if(r<24)return`${r} 小时前`;const a=Math.floor(r/24);return a<30?`${a} 天前`:`${Math.floor(a/30)} 个月前`}const TM={create:{label:"首次提取",color:"text-green-400"},update:{label:"重写",color:"text-blue-400"},merge:{label:"合并",color:"text-purple-400"},decay:{label:"衰减",color:"text-amber-400"},reinforce:{label:"强化",color:"text-emerald-400"},manual:{label:"手动编辑",color:"text-fg-3"}};function Xq({memory:e,onClose:t}){const n=[...e.history??[]].reverse();return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:c.jsxs("div",{className:"mx-4 max-h-[80vh] w-full max-w-lg overflow-y-auto rounded-xl border border-line bg-surface p-5 shadow-xl",onClick:r=>r.stopPropagation(),children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("h3",{className:"text-sm font-semibold text-fg",children:["版本历史 (",n.length+1," 个版本)"]}),c.jsx("button",{type:"button",onClick:t,className:"rounded p-1 text-fg-4 hover:text-fg-3",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"rounded-lg border border-blue-500/20 bg-blue-500/5 p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[10px]",children:[c.jsx("span",{className:"font-medium text-blue-400",children:"当前版本"}),c.jsx("span",{className:"text-fg-5",children:uc(e.updatedAt)}),c.jsxs("span",{className:"text-fg-6",children:["⚡ ",e.importance.toFixed(2)]})]}),c.jsx("p",{className:"text-xs leading-relaxed text-fg",children:e.content})]}),n.map((r,a)=>{const i=TM[r.action]??{label:r.action,color:"text-fg-4"};return c.jsxs("div",{className:"rounded-lg border border-line bg-base p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[10px]",children:[c.jsx("span",{className:ie("font-medium",i.color),children:i.label}),c.jsx("span",{className:"text-fg-5",children:uc(r.ts)}),c.jsxs("span",{className:"text-fg-6",children:["⚡ ",r.importance.toFixed(2)]}),r.source&&c.jsxs("span",{className:"text-fg-6",children:["· ",r.source]})]}),c.jsx("p",{className:"text-xs leading-relaxed text-fg-4",children:r.content})]},a)}),n.length===0&&c.jsx("div",{className:"py-4 text-center text-xs text-fg-5",children:"暂无历史版本"})]})]})})}function YA({memory:e,categories:t,onUpdate:n,onDelete:r}){var C;const[a,i]=y.useState(!1),[o,u]=y.useState(e.content),[d,f]=y.useState(e.category),[m,p]=y.useState(!1),[b,x]=y.useState(!1),E=_M(e.category),N=(C=e.history)==null?void 0:C[e.history.length-1],_=N&&Math.abs(N.importance-e.importance)>.001,S=async()=>{p(!0);try{await n(e.id,{content:o,category:d}),i(!1)}finally{p(!1)}};return a?c.jsxs("div",{className:"rounded-lg border border-blue-500/30 bg-blue-500/5 p-3 space-y-2",children:[c.jsx("textarea",{value:o,onChange:A=>u(A.target.value),rows:3,className:"w-full resize-y rounded-md border border-line bg-surface px-3 py-2 font-mono text-xs leading-relaxed text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("select",{value:d,onChange:A=>f(A.target.value),className:"rounded-md border border-line bg-surface px-2 py-1 text-xs text-fg focus:border-blue-500 focus:outline-none",children:t.map(A=>c.jsx("option",{value:A,children:A},A))}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:()=>{i(!1),u(e.content),f(e.category)},className:"rounded-md px-3 py-1 text-xs text-fg-4 hover:bg-elevated",children:"取消"}),c.jsx("button",{type:"button",onClick:()=>void S(),disabled:m||!o.trim(),className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white hover:bg-blue-500 disabled:opacity-40",children:m?"保存中…":"保存"})]})]}):c.jsxs("div",{className:"group/mem rounded-lg border border-line bg-base px-3 py-2.5",children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx("span",{className:ie("mt-0.5 shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",E.bg,E.text),children:e.category}),c.jsx("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-fg",children:e.content})]}),c.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-[11px] text-fg-5",children:[c.jsxs("span",{className:"flex items-center gap-0.5",children:[c.jsx(Cc,{className:"h-3 w-3"}),_&&N?`${N.importance.toFixed(2)}→${e.importance.toFixed(2)}`:e.importance.toFixed(2)]}),c.jsx("span",{children:"·"}),c.jsx("span",{children:uc(e.updatedAt)}),e.supersededBy&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsx("span",{className:"text-amber-400",children:e.supersededBy==="user-deleted"?"已删除":e.supersededBy==="consolidated-out"?"已整理":"已合并"})]}),e.history&&e.history.length>0&&(()=>{const A=e.history[e.history.length-1],I=TM[A.action];return c.jsxs("button",{type:"button",onClick:()=>x(!0),"data-guide":e.id==="guide-mem-1"?"agent-memory-version":void 0,className:ie("rounded px-1.5 py-0.5 text-[10px] font-medium transition-opacity hover:opacity-80",A.action==="update"?"bg-blue-500/10 text-blue-400":A.action==="merge"?"bg-purple-500/10 text-purple-400":A.action==="decay"?"bg-amber-500/10 text-amber-400":A.action==="reinforce"?"bg-emerald-500/10 text-emerald-400":A.action==="manual"?"bg-fg/10 text-fg-3":"bg-green-500/10 text-green-400"),children:[(I==null?void 0:I.label)??A.action," · ",e.history.length,"版"]})})(),c.jsx("div",{className:"flex-1"}),!e.supersededBy&&c.jsx("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover/mem:opacity-100",children:c.jsx(oh,{onConfirm:()=>void r(e.id),children:c.jsx("button",{type:"button",onClick:()=>i(!0),className:"rounded p-1 text-fg-5 hover:text-fg-3",children:c.jsx(jE,{className:"h-3.5 w-3.5"})})})})]}),b&&c.jsx(Xq,{memory:e,onClose:()=>x(!1)})]})}const Qq=14400*1e3;function Zq(e){if(!e)return"下次:待定";const t=e+Qq,n=Date.now();if(t<=n)return"下次:即将运行";const r=t-n,a=Math.floor(r/6e4);if(a<60)return`下次:约 ${a} 分钟后`;const i=Math.floor(a/60);return i<24?`下次:约 ${i} 小时后`:`下次:约 ${Math.floor(i/24)} 天后`}function Jq({stats:e,running:t,onTrigger:n}){if(!e)return null;const r=e.lastActions;return c.jsxs("div",{className:"rounded-lg bg-elevated px-3 py-2 text-[11px] tabular-nums text-fg-5",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[c.jsx("span",{children:e.lastConsolidatedAt?`上次整理:${uc(e.lastConsolidatedAt)}`:"尚未整理"}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{children:Zq(e.lastConsolidatedAt)}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:n,disabled:t,className:"rounded px-2 py-0.5 text-[10px] font-medium text-fg-4 transition-colors hover:bg-surface hover:text-fg-3 disabled:opacity-40",children:t?"整理中…":"立即整理"})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1",children:[r&&c.jsxs(c.Fragment,{children:[c.jsxs("span",{children:[r.update," 更新 ",r.merge," 合并 ",r.delete," 清理 ",r.decayed," 降权"]}),c.jsx("span",{className:"text-fg-6",children:"·"})]}),c.jsxs("span",{children:["活跃 ",e.totalActive," 条"]}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsxs("span",{children:["衰减中 ",e.stale]})]})]})}function eG({agentId:e}){const t=e.startsWith(gM),[n,r]=y.useState(null),[a,i]=y.useState(!1),[o,u]=y.useState(!1),[d,f]=y.useState(new Set),[m,p]=y.useState(!1),[b,x]=y.useState(null),[E,N]=y.useState(null),[_,S]=y.useState(!1),{data:C,loading:A,reload:I}=lc(()=>t?Promise.resolve(WY):rM(e,{includeSuperseded:a}),[e,a,t],{showErrorToast:!t,errorMessage:"加载记忆失败"}),O=C??[],k=y.useCallback(()=>{t||dA(e).then(N).catch(()=>N(null))},[e,t]);y.useEffect(()=>{k()},[k]);const j=async()=>{S(!0);try{await U$(e)}catch{S(!1);return}const D=setInterval(()=>{dA(e).then(z=>{N(z),z.lastConsolidatedAt&&(!(E!=null&&E.lastConsolidatedAt)||z.lastConsolidatedAt>E.lastConsolidatedAt)&&(clearInterval(D),S(!1),I())}).catch(()=>{})},5e3);setTimeout(()=>{clearInterval(D),S(!1)},3e5)},{data:F,loading:P}=lc(()=>BE(e),[e,o],{skip:!o,errorMessage:"加载 Session 列表失败"}),L=F??[],B=O.filter(D=>!D.supersededBy),Y=n?B.filter(D=>D.category===n):B,re=O.filter(D=>D.supersededBy),X=y.useMemo(()=>new Set(O.map(D=>D.sessionId).filter(Boolean)),[O]),K=async(D,z)=>{await L$(e,D,z),await I()},V=async D=>{await P$(e,D),await I()},H=D=>{f(z=>{const $=new Set(z);return $.has(D)?$.delete(D):$.add(D),$})},G=async()=>{if(d.size!==0){p(!0),x(null);try{const $=(await B$(e,[...d])).results;if($){const M=$.filter(oe=>oe.status==="ok"),le=$.filter(oe=>oe.status!=="ok");M.length>0&&x(`提取成功 ${M.reduce((oe,ne)=>oe+(ne.actions??0),0)} 条记忆`),le.length>0&&x(oe=>(oe?`${oe};`:"")+le.map(ne=>ne.error??ne.status).join(";")),M.length>0&&await I()}f(new Set)}catch(D){x(`请求失败: ${D instanceof Error?D.message:String(D)}`)}p(!1)}},Q=y.useMemo(()=>[...new Set(B.map(z=>z.category))].sort(),[B]);return c.jsxs("section",{"data-guide":"agent-memory-section",className:"rounded-xl border border-line bg-surface p-5 space-y-4",children:[c.jsx("div",{className:"flex items-center justify-between",children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(oc,{className:"h-4 w-4 text-purple-400"}),c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"记忆"}),!A&&c.jsx("span",{className:"rounded-full bg-elevated px-1.5 py-0.5 text-[10px] tabular-nums text-fg-4",children:Y.length})]})}),c.jsx(Jq,{stats:E,running:_,onTrigger:()=>void j()}),c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[c.jsx("button",{type:"button",onClick:()=>r(null),className:ie("rounded-full px-2.5 py-0.5 text-[11px] font-medium transition-colors",n===null?"bg-fg/10 text-fg":"text-fg-4 hover:text-fg-3"),children:"全部"}),Q.map(D=>{const z=_M(D);return c.jsx("button",{type:"button",onClick:()=>r(n===D?null:D),className:ie("rounded-full px-2.5 py-0.5 text-[11px] font-medium transition-colors",n===D?ie(z.bg,z.text):"text-fg-4 hover:text-fg-3"),children:D},D)})]}),A?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):Y.length===0&&re.length===0?c.jsx("div",{className:"py-8 text-center text-xs text-fg-5",children:"暂无记忆。使用此 Agent 完成 Session 后将自动提取。"}):c.jsxs("div",{className:"space-y-1.5",children:[Y.map(D=>c.jsx(YA,{memory:D,categories:Q,onUpdate:K,onDelete:V},D.id)),re.length>0&&c.jsxs("div",{className:"pt-1",children:[c.jsxs("button",{type:"button",onClick:()=>i(!a),className:"flex items-center gap-1 text-[11px] text-fg-5 hover:text-fg-3",children:[c.jsx("span",{children:a?"▾":"▸"}),"已合并/已删除 (",re.length,")"]}),a&&c.jsx("div",{className:"mt-1.5 space-y-1.5 opacity-60",children:re.map(D=>c.jsx(YA,{memory:D,categories:Q,onUpdate:K,onDelete:V},D.id))})]})]}),c.jsxs("div",{className:"border-t border-line pt-3",children:[c.jsxs("button",{type:"button",onClick:()=>u(!o),className:"flex items-center gap-1.5 text-xs font-medium text-fg-4 hover:text-fg-3",children:[c.jsx(n0,{className:"h-3.5 w-3.5"}),c.jsxs("span",{children:[o?"▾":"▸"," 从 Session 提取记忆"]})]}),o&&c.jsx("div",{className:"mt-2 space-y-1.5",children:P?c.jsx("div",{className:"flex items-center justify-center py-4",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):L.length===0?c.jsx("p",{className:"py-4 text-center text-xs text-fg-5",children:"暂无 Session 记录。"}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"max-h-64 space-y-1 overflow-y-auto",children:L.map(D=>{const z=X.has(D.id);return c.jsxs("label",{className:ie("flex cursor-pointer items-center gap-2.5 rounded-md border px-3 py-2 transition-colors",d.has(D.id)?"border-purple-500/30 bg-purple-500/5":"border-line bg-base hover:bg-elevated/60"),children:[c.jsx("input",{type:"checkbox",checked:d.has(D.id),onChange:()=>H(D.id),className:"h-3.5 w-3.5 shrink-0 cursor-pointer rounded border-line accent-purple-500"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"block truncate text-xs text-fg",children:D.title||D.id.slice(-8)}),c.jsx("span",{className:"text-[11px] text-fg-5",children:uc(D.timeCreated)})]}),c.jsx("span",{className:ie("shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium",z?"bg-green-500/10 text-green-400":"bg-elevated text-fg-5"),children:z?"已提取":"未提取"})]},D.id)})}),d.size>0&&c.jsxs("button",{type:"button",onClick:()=>void G(),disabled:m,className:"flex w-full items-center justify-center gap-1.5 rounded-lg bg-purple-600 py-2 text-xs font-medium text-white transition-colors hover:bg-purple-500 disabled:opacity-40",children:[m?c.jsx(nn,{className:"h-3.5 w-3.5 fs-spin"}):c.jsx(oc,{className:"h-3.5 w-3.5"}),m?"提取中…":`提取选中 Session 的记忆 (${d.size})`]}),b&&c.jsx("p",{className:ie("mt-1.5 rounded-md px-3 py-1.5 text-xs",b.includes("成功")?"bg-green-500/10 text-green-400":"bg-red-500/10 text-red-400"),children:b})]})})]})]})}function tG({agentId:e}){const{data:t,loading:n}=lc(()=>BE(e),[e],{errorMessage:"加载 Session 历史失败"}),r=t??[];return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(n0,{className:"h-4 w-4 text-fg-4"}),c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Session 历史"}),!n&&c.jsx("span",{className:"rounded-full bg-elevated px-1.5 py-0.5 text-[10px] tabular-nums text-fg-4",children:r.length})]}),c.jsx("div",{className:"mt-3",children:n?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):r.length===0?c.jsx("p",{className:"py-8 text-center text-xs text-fg-5",children:"暂无 Session 记录。"}):c.jsx("div",{className:"space-y-1",children:r.map(a=>c.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-line bg-base px-4 py-2.5",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"block truncate text-xs font-medium text-fg",children:a.title||a.id.slice(-8)}),c.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-fg-5",children:[c.jsx("span",{children:uc(a.timeCreated)}),a.cost>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsxs("span",{children:["$",a.cost.toFixed(4)]})]}),(a.tokensInput>0||a.tokensOutput>0)&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsxs("span",{children:[Math.round((a.tokensInput+a.tokensOutput)/1e3),"K tokens"]})]})]})]}),a.completedAt?c.jsx("span",{className:"shrink-0 rounded-full bg-green-500/10 px-2 py-0.5 text-[10px] font-medium text-green-400",children:"完成"}):c.jsx("span",{className:"shrink-0 rounded-full bg-elevated px-2 py-0.5 text-[10px] font-medium text-fg-5",children:"进行中"})]},a.id))})})]})}function nG({agent:e,fragments:t,onSave:n}){const r=We(Q=>Q.activeRepoId),[a,i]=y.useState(!1),[o,u]=y.useState(e.name),[d,f]=y.useState(e.description??""),[m,p]=y.useState(e.baseAgent),[b,x]=y.useState(e.model??""),[E,N]=y.useState(e.variant??""),[_,S]=y.useState(e.memoryModel??""),[C,A]=y.useState(e.systemPrompt),[I,O]=y.useState(!1),[k,j]=y.useState(!1),[F,P]=y.useState([]);y.useEffect(()=>{if(!r){P([]);return}let Q=!1;return(async()=>{try{const[D,z]=await Promise.all([Ml(),kc(r)]);if(Q)return;const $=D[Vq],M=$?JSON.parse($):[],le=M.length>0?z.filter(oe=>M.includes(oe.id)):z;P(le.length>0?le:z)}catch{Q||P([])}})(),()=>{Q=!0}},[r]);const[L,B]=y.useState(()=>{const Q=e.fragments.map(M=>M.id),D=e.systemPromptPosition??-1,z=D>=0&&D<=Q.length?D:Q.length,$=[...Q];return $.splice(z,0,il),$}),Y=Q=>{B(D=>{if(D.includes(Q))return D.filter(M=>M!==Q);const z=D.indexOf(il),$=[...D];return $.splice(z>=0?z:$.length,0,Q),$})},re=(Q,D)=>{const z=Q+D;z<0||z>=L.length||B($=>{const M=[...$];return[M[Q],M[z]]=[M[z],M[Q]],M})},X=L.filter(Q=>Q!==il),K=(()=>{const Q=L.indexOf(il);return Q<0?-1:L.slice(0,Q).filter(D=>D!==il).length})(),V=L.map(Q=>{var D;return Q===il?C:(D=t.find(z=>z.id===Q))==null?void 0:D.content}).filter(Boolean).join(`
|
|
523
|
+
)`}function uq(e,t){const n={position:"fixed"},r=window.innerWidth,a=window.innerHeight,i=e.top+e.height+jA,o=e.top-jA;let u=t==="bottom-right"?e.left+e.width-BA:e.left;return u=Math.max(UA,Math.min(u,r-BA-UA)),n.left=u,i+160<a?n.top=i:n.bottom=a-o,n}function Oy(e){const t=document.querySelector(e);t&&t.click()}const FA={selectMockIssue:JY,selectMockPr:eq,selectMockSession:tq,clearActiveSession:nq};function cq(){return window.innerWidth<sq}function dq({direction:e}){const t=e==="left"?ih:Oo;return c.jsx("div",{className:"pointer-events-none fixed inset-0 z-[9999] flex items-center justify-center",children:c.jsxs("div",{className:`flex items-center gap-1 rounded-full bg-blue-500/20 px-6 py-4 ${e==="left"?"fs-swipe-left":"fs-swipe-right"}`,children:[c.jsx(t,{className:"h-8 w-8 text-blue-400",strokeWidth:2.5}),c.jsx(t,{className:"h-8 w-8 text-blue-400/60",strokeWidth:2.5}),c.jsx(t,{className:"h-8 w-8 text-blue-400/30",strokeWidth:2.5})]})})}function fq({step:e,stepIdx:t,total:n,isFirst:r,isLast:a,onPrev:i,onNext:o,onClose:u}){return c.jsx("div",{className:"fixed inset-x-0 bottom-24 z-[10000] flex justify-center px-4",children:c.jsxs("div",{className:"w-72 rounded-xl border border-line bg-surface p-4 shadow-2xl",children:[c.jsx("button",{type:"button",onClick:u,className:"absolute right-2 top-2 rounded-md p-1 text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3","aria-label":"关闭引导",children:c.jsx(At,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:e.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:e.description}),c.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[c.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-fg-5",children:[t+1," / ",n]}),c.jsxs("div",{className:"flex items-center gap-2",children:[!r&&c.jsx("button",{type:"button",onClick:i,className:"rounded-md px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"上一步"}),c.jsx("button",{type:"button",onClick:o,className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:a?"完成":"下一步"})]})]})]})})}function hq(){const e=zn(),t=or(),n=ys(L=>L.guideTourOpen),r=ys(L=>L.guideTourSection),a=ys(L=>L.stopGuideTour),i=We(qr),[o,u]=y.useState(0),[d,f]=y.useState(null),m=y.useRef(null),p=y.useRef(-1),b=y.useRef(null),x=y.useMemo(()=>n?aq(r):e1,[n,r]),E=o<x.length?x[o]:void 0,N=x.length,_=o===0,S=o===N-1,C=y.useCallback(()=>{if(!n||!E)return;const L=E.padding??iq;f(oq(E.target,L))},[n,E]),A=y.useCallback(L=>{const B=L.replace("__MOCK_AGENT__",rq());return B.startsWith("/")?B:i?`/${encodeURIComponent(i)}/${B}`:`/${B}`},[i]);y.useEffect(()=>{n&&(u(0),p.current=-1)},[n]),y.useEffect(()=>{if(!n||!E)return;const L=p.current,B=L>=0?x[L]:null;B!=null&&B.triggerClick&&document.querySelector(B.target)&&Oy(B.triggerClick);const Y=(B==null?void 0:B.mockScope)??null,re=E.mockScope??null;re&&re!==Y?(QY(re),b.current=re):!re&&b.current&&(DA(),b.current=null);const X=E.route?A(E.route):null,K=X&&!t.pathname.startsWith(X);K&&e(X);const H=setTimeout(()=>{E.setupFn&&FA[E.setupFn]&&FA[E.setupFn](),setTimeout(()=>{E.triggerClick&&!document.querySelector(E.target)&&Oy(E.triggerClick),setTimeout(C,PA)},E.setupFn?LA:0)},K?LA:re&&re!==Y?PA:0);return p.current=o,()=>clearTimeout(H)},[n,o,E,e,t.pathname,C,A,x]),y.useLayoutEffect(()=>{C()},[C]),y.useEffect(()=>{if(n)return window.addEventListener("resize",C),window.addEventListener("scroll",C,!0),()=>{window.removeEventListener("resize",C),window.removeEventListener("scroll",C,!0)}},[n,C]);const I=y.useRef(o);I.current=o;const O=y.useRef(x);O.current=x;const k=y.useCallback(()=>{const L=O.current[I.current];L!=null&&L.triggerClick&&document.querySelector(L.target)&&Oy(L.triggerClick),b.current&&(DA(),b.current=null),a()},[a]);if(y.useEffect(()=>{if(!n)return;const L=B=>{B.key==="Escape"&&k()};return document.addEventListener("keydown",L),()=>document.removeEventListener("keydown",L)},[n,k]),!n||!E)return null;const j=cq()&&E.mobileSwipeHint&&!d;if(!d&&!j)return null;const F=()=>{_||u(L=>L-1)},P=()=>{S?k():u(L=>L+1)};return j?gs.createPortal(c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"fixed inset-0 z-[9998] bg-black/60",onClick:k}),c.jsx(dq,{direction:E.mobileSwipeHint}),c.jsx(fq,{step:E,stepIdx:o,total:N,isFirst:_,isLast:S,onPrev:F,onNext:P,onClose:k})]}),document.body):gs.createPortal(c.jsxs("div",{className:"fixed inset-0 z-[9999]",children:[c.jsx("div",{className:"absolute inset-0 bg-black/60 transition-[clip-path] duration-200",style:{clipPath:lq(d)},onClick:k}),c.jsx("div",{className:"pointer-events-none absolute rounded-lg ring-2 ring-blue-500 ring-offset-2 ring-offset-transparent transition-all duration-200",style:{top:d==null?void 0:d.top,left:d==null?void 0:d.left,width:d==null?void 0:d.width,height:d==null?void 0:d.height}}),c.jsxs("div",{ref:m,className:"fixed z-[10000] w-72 rounded-xl border border-line bg-surface p-4 shadow-2xl",style:uq(d,E.position),children:[c.jsx("button",{type:"button",onClick:k,className:"absolute right-2 top-2 rounded-md p-1 text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3","aria-label":"关闭引导",children:c.jsx(At,{className:"h-3.5 w-3.5"})}),c.jsx("h3",{className:"pr-6 text-sm font-semibold text-fg",children:E.title}),c.jsx("p",{className:"mt-1.5 text-xs leading-relaxed text-fg-3",children:E.description}),c.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[c.jsxs("span",{className:"font-mono text-[11px] tabular-nums text-fg-5",children:[o+1," / ",N]}),c.jsxs("div",{className:"flex items-center gap-2",children:[!_&&c.jsx("button",{type:"button",onClick:F,className:"rounded-md px-3 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"上一步"}),c.jsx("button",{type:"button",onClick:P,className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:S?"完成":"下一步"})]})]})]})]}),document.body)}const EM=[{segment:"run",icon:LE,label:"运行面板",global:!1},{segment:"dev/issues",icon:Ez,label:"研发",global:!1,matchPrefix:"dev"},{segment:"agents",icon:QF,label:"Agents",global:!1}];function NM(e,t,n){return t?`/${e}`:n?`/${encodeURIComponent(n)}/${e}`:`/${e}`}function SM(e,t,n){if(!e.matchPrefix)return!1;const r=e.global?`/${e.matchPrefix}`:n?`/${encodeURIComponent(n)}/${e.matchPrefix}`:null;return r?t===r||t.startsWith(`${r}/`):!1}function mq(e){const t=e.lastIndexOf("/");return t>=0?e.slice(t+1):e}function pq({repos:e,activeRepoId:t,onRepoChange:n}){const r=zn(),[a,i]=y.useState(!1),[o,u]=y.useState(-1),d=y.useRef(null),f=e.find(b=>b.id===t),m=y.useCallback(()=>{i(!1),u(-1)},[]);y.useEffect(()=>{if(!a)return;const b=x=>{d.current&&!d.current.contains(x.target)&&m()};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[a,m]);const p=y.useCallback(b=>{if(a)switch(b.key){case"Escape":b.preventDefault(),m();break;case"ArrowDown":b.preventDefault(),u(x=>Math.min(x+1,e.length-1));break;case"ArrowUp":b.preventDefault(),u(x=>Math.max(x-1,0));break;case"Enter":o>=0&&o<e.length&&(b.preventDefault(),n(e[o].id),m());break}},[a,m,o,e,n]);return c.jsxs("div",{ref:d,className:"relative",onKeyDown:p,children:[c.jsxs("button",{type:"button","data-guide":"repo-switcher",onClick:()=>i(b=>!b),"aria-label":"切换仓库","aria-haspopup":"listbox","aria-expanded":a,className:"flex max-w-[140px] items-center gap-1 rounded-md border border-line bg-base px-2 py-1 text-xs text-fg-2 transition-colors hover:border-blue-500 sm:max-w-[200px]",children:[c.jsx(FR,{className:"h-3 w-3 shrink-0 text-fg-4"}),c.jsxs("span",{className:"truncate",children:[c.jsx("span",{className:"sm:hidden",children:f?mq(f.name):""}),c.jsx("span",{className:"hidden sm:inline",children:(f==null?void 0:f.name)??""})]}),c.jsx(kr,{className:ie("h-3 w-3 shrink-0 text-fg-4 transition-transform",a&&"rotate-180")})]}),a&&c.jsxs("div",{className:"absolute left-0 top-full z-50 mt-1 w-64 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[c.jsx("div",{role:"listbox","aria-label":"仓库列表",className:"max-h-64 overflow-y-auto py-1",children:e.map((b,x)=>c.jsxs("button",{type:"button",role:"option","aria-selected":b.id===t,onClick:()=>{n(b.id),m()},className:ie("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",b.id===t?"font-medium text-blue-600":"text-fg-2 hover:bg-elevated",o===x&&"bg-elevated"),children:[b.id===t?c.jsx(fi,{className:"h-3 w-3 shrink-0"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:b.name})]},b.id))}),c.jsx("div",{className:"border-t border-line",children:c.jsxs("button",{type:"button","data-guide":"manage-repos",onClick:()=>{r("/repos"),m()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:[c.jsx(r0,{className:"h-3 w-3 shrink-0"}),c.jsx("span",{children:"管理仓库"})]})})]})]})}function gq({repoId:e,currentBranch:t}){const n=We(S=>S.updateRepoBranch),[r,a]=y.useState(!1),[i,o]=y.useState(null),[u,d]=y.useState(!1),[f,m]=y.useState(null),[p,b]=y.useState(null),x=y.useRef(null),E=y.useCallback(()=>{a(!1),b(null)},[]);y.useEffect(()=>{if(!r)return;const S=C=>{x.current&&!x.current.contains(C.target)&&E()};return document.addEventListener("mousedown",S),()=>document.removeEventListener("mousedown",S)},[r,E]);const N=async()=>{if(r){E();return}a(!0),d(!0),b(null);try{o(await d$(e))}catch{b("加载分支失败")}finally{d(!1)}},_=async S=>{if(!(S===t||f)){m(S),b(null);try{const C=await f$(e,S);n(e,C.branch),E()}catch(C){b(C instanceof Error?C.message:"切换失败")}finally{m(null)}}};return t?c.jsxs("div",{ref:x,className:"relative",children:[c.jsxs("button",{type:"button",onClick:N,className:"flex items-center gap-1 rounded-md bg-elevated px-2 py-1 text-xs text-fg-3 transition-colors hover:bg-blue-500/10 hover:text-blue-600",children:[c.jsx(Gl,{className:"h-3 w-3"}),t,c.jsx(kr,{className:ie("h-3 w-3 transition-transform",r&&"rotate-180")})]}),r&&c.jsxs("div",{className:"absolute right-0 top-full z-50 mt-1 w-56 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[u?c.jsx("div",{className:"flex items-center justify-center py-4",children:c.jsx(nn,{className:"h-4 w-4 animate-spin text-fg-4"})}):i?c.jsxs("div",{className:"max-h-64 overflow-y-auto py-1",children:[i.local.map(S=>c.jsxs("button",{type:"button",disabled:f!==null,onClick:()=>_(S),className:ie("flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs transition-colors",S===t?"font-medium text-blue-600":"text-fg-2 hover:bg-elevated"),children:[S===t?c.jsx(fi,{className:"h-3 w-3 shrink-0"}):f===S?c.jsx(nn,{className:"h-3 w-3 shrink-0 animate-spin"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:S})]},S)),i.remote.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"mx-3 my-1 border-t border-line"}),c.jsx("div",{className:"px-3 py-1 text-[10px] font-medium uppercase tracking-wider text-fg-4",children:"Remote"}),i.remote.map(S=>c.jsxs("button",{type:"button",disabled:f!==null,onClick:()=>_(S),className:"flex w-full items-center gap-2 px-3 py-1.5 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[f===S?c.jsx(nn,{className:"h-3 w-3 shrink-0 animate-spin"}):c.jsx("span",{className:"h-3 w-3 shrink-0"}),c.jsx("span",{className:"truncate",children:S})]},`remote-${S}`))]})]}):null,p&&c.jsx("div",{className:"border-t border-line px-3 py-2 text-xs text-red-500",children:p})]})]}):null}function bq(){const[e,t]=y.useState(null);return y.useEffect(()=>{const n=()=>fetch("/api/health").then(i=>i.json()).then(i=>{i.latestVersion&&i.latestVersion!=="0.11.39"&&t(i.latestVersion)}).catch(()=>{});n();const r=setInterval(n,RY),a=()=>n();return window.addEventListener("focus",a),()=>{clearInterval(r),window.removeEventListener("focus",a)}},[]),e}function xq({navigate:e,cycle:t,themeLabel:n,ThemeIcon:r}){const[a,i]=y.useState(!1),o=y.useRef(null);return y.useEffect(()=>{if(!a)return;const u=d=>{o.current&&!o.current.contains(d.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[a]),c.jsxs("div",{ref:o,className:"relative md:hidden",children:[c.jsx("button",{type:"button",onClick:()=>i(u=>!u),"aria-label":"更多",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(kz,{className:"h-4 w-4"})}),a&&c.jsxs("div",{className:"absolute right-0 top-full z-50 mt-1 w-40 overflow-hidden rounded-lg border border-line bg-surface shadow-lg",children:[c.jsxs("button",{type:"button",onClick:()=>{e("/analytics"),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(ah,{className:"h-3.5 w-3.5 text-fg-4"}),"统计"]}),c.jsxs("button",{type:"button",onClick:()=>{e("/settings"),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(r0,{className:"h-3.5 w-3.5 text-fg-4"}),"设置"]}),c.jsxs("button",{type:"button",onClick:()=>{t(),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(r,{className:"h-3.5 w-3.5 text-fg-4"}),n]}),c.jsxs("a",{href:"https://github.com/kinminghao/fourth-spark",target:"_blank",rel:"noopener noreferrer",onClick:()=>i(!1),className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx("svg",{className:"h-3.5 w-3.5 text-fg-4",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})}),"GitHub"]}),c.jsxs("button",{type:"button",onClick:()=>{ys.getState().startGuideTour(vM(window.location.pathname)),i(!1)},className:"flex w-full items-center gap-2.5 px-3 py-2 text-left text-xs text-fg-2 transition-colors hover:bg-elevated",children:[c.jsx(zR,{className:"h-3.5 w-3.5 text-fg-4"}),"功能引导"]})]})]})}function yq(){const e=zn(),t=or(),n=We(p=>p.repos),r=We(p=>p.activeRepoId),a=We(p=>p.setActiveRepo),i=Zv(p=>p.preference),o=Zv(p=>p.cycle),u=i==="light"?YH:i==="dark"?SH:EH,d=n.find(p=>p.id===r),f=bq(),m=p=>{var N;if(!p)return;a(p);const b=n.find(_=>_.id===p);if(!b)return;const x=t.pathname.match(/\/dev\/(issues|pulls)/);if(x){e(`/${encodeURIComponent(b.name)}/dev/${x[1]}`);return}const E=((N=t.pathname.match(/\/(run|agents|issues|pulls)/))==null?void 0:N[1])??"run";e(`/${encodeURIComponent(b.name)}/${E}`)};return c.jsxs("header",{className:"shrink-0 border-b border-line bg-surface pt-[var(--safe-top)]",children:[c.jsxs("div",{className:"flex h-12 items-center justify-between px-4",children:[c.jsxs("div",{className:"flex items-center gap-2.5",children:[c.jsx(Cc,{className:"h-5 w-5 text-blue-500"}),c.jsx("span",{className:"hidden text-sm font-bold tracking-tight text-fg sm:inline",children:"Fourth Spark"}),c.jsxs("span",{className:"hidden rounded bg-elevated px-1.5 py-0.5 text-[10px] font-medium tabular-nums text-fg-4 sm:inline",children:["v","0.11.39"]}),f&&c.jsxs("span",{className:"hidden text-[10px] text-amber-500 sm:inline",children:["→ v",f," 可用,运行"," ",c.jsx("code",{className:"rounded bg-amber-500/10 px-1 font-mono",children:"fourth-spark upgrade"})," 更新"]})]}),c.jsxs("div",{className:"flex items-center gap-3",children:[n.length>0&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(pq,{repos:n,activeRepoId:r,onRepoChange:m}),d&&r&&c.jsx(gq,{repoId:r,currentBranch:d.branch})]}),c.jsxs("div",{className:"hidden items-center gap-1 md:flex",children:[c.jsx("button",{type:"button",onClick:()=>e("/analytics"),"aria-label":"统计",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(ah,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>e("/settings"),"aria-label":"设置",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(r0,{className:"h-4 w-4"})}),c.jsx("a",{href:"https://github.com/kinminghao/fourth-spark",target:"_blank",rel:"noopener noreferrer","aria-label":"GitHub",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("path",{d:"M12 .297c-6.63 0-12 5.373-12 12 0 5.303 3.438 9.8 8.205 11.385.6.113.82-.258.82-.577 0-.285-.01-1.04-.015-2.04-3.338.724-4.042-1.61-4.042-1.61C4.422 18.07 3.633 17.7 3.633 17.7c-1.087-.744.084-.729.084-.729 1.205.084 1.838 1.236 1.838 1.236 1.07 1.835 2.809 1.305 3.495.998.108-.776.417-1.305.76-1.605-2.665-.3-5.466-1.332-5.466-5.93 0-1.31.465-2.38 1.235-3.22-.135-.303-.54-1.523.105-3.176 0 0 1.005-.322 3.3 1.23.96-.267 1.98-.399 3-.405 1.02.006 2.04.138 3 .405 2.28-1.552 3.285-1.23 3.285-1.23.645 1.653.24 2.873.12 3.176.765.84 1.23 1.91 1.23 3.22 0 4.61-2.805 5.625-5.475 5.92.42.36.81 1.096.81 2.22 0 1.606-.015 2.896-.015 3.286 0 .315.21.69.825.57C20.565 22.092 24 17.592 24 12.297c0-6.627-5.373-12-12-12"})})}),c.jsx("button",{type:"button",onClick:o,"aria-label":`主题: ${i}`,className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(u,{className:"h-4 w-4"})}),c.jsx("button",{type:"button",onClick:()=>ys.getState().startGuideTour(vM(t.pathname)),"aria-label":"功能引导",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(zR,{className:"h-4 w-4"})})]}),c.jsx(xq,{navigate:e,cycle:o,themeLabel:`主题: ${i}`,ThemeIcon:u})]})]}),f&&c.jsx("div",{className:"border-t border-line px-4 py-1.5 sm:hidden",children:c.jsxs("span",{className:"text-[10px] text-amber-500",children:["→ v",f," 可用,运行"," ",c.jsx("code",{className:"rounded bg-amber-500/10 px-1 font-mono",children:"fourth-spark upgrade"})," 更新"]})})]})}function vq(){const e=We(qr),t=ys(a=>a.navCollapsed),n=ys(a=>a.toggleNav),r=or();return c.jsxs("nav",{className:ie("hidden shrink-0 flex-col border-r border-line bg-surface py-2 transition-[width] duration-200 ease-in-out md:flex",t?"w-14":"w-48"),children:[c.jsx("div",{className:"flex flex-1 flex-col",children:EM.map(a=>{const i=SM(a,r.pathname,e);return c.jsxs(Hp,{to:NM(a.segment,a.global,e),title:t?a.label:void 0,className:({isActive:o})=>ie("mx-2 flex items-center rounded-md py-2 text-sm transition-colors",t?"justify-center px-2":"gap-2.5 px-3",o||i?"bg-blue-500/10 font-medium text-blue-600":"text-fg-3 hover:bg-elevated hover:text-fg"),children:[c.jsx(a.icon,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:ie("truncate transition-[opacity,max-width] duration-200 ease-in-out",t?"max-w-0 opacity-0":"max-w-[8rem] opacity-100"),children:a.label})]},a.segment)})}),c.jsxs(Hp,{to:"/settings",title:t?"设置":void 0,className:({isActive:a})=>ie("mx-2 flex items-center rounded-md py-2 text-sm transition-colors",t?"justify-center px-2":"gap-2.5 px-3",a?"bg-blue-500/10 font-medium text-blue-600":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:[c.jsx(r0,{className:"h-4 w-4 shrink-0"}),c.jsx("span",{className:ie("truncate transition-[opacity,max-width] duration-200 ease-in-out",t?"max-w-0 opacity-0":"max-w-[8rem] opacity-100"),children:"设置"})]}),c.jsx("button",{type:"button",onClick:n,title:t?"展开导航":"收起导航",className:"mx-2 flex items-center justify-center rounded-md py-2 text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:t?c.jsx(uz,{className:"h-4 w-4"}):c.jsx(oz,{className:"h-4 w-4"})})]})}function Eq(){const e=We(qr),t=or();return c.jsx("nav",{className:"fixed bottom-0 left-0 right-0 z-30 border-t border-line bg-surface pb-[var(--safe-bottom)] md:hidden",children:c.jsx("div",{className:"flex h-14 items-center justify-around",children:EM.map(n=>{const r=SM(n,t.pathname,e);return c.jsx(Hp,{to:NM(n.segment,n.global,e),"aria-label":n.label,className:({isActive:a})=>ie("flex h-10 w-10 items-center justify-center rounded-md transition-colors",a||r?"bg-blue-500/10 text-blue-600":"text-fg-3 hover:bg-elevated hover:text-fg"),children:c.jsx(n.icon,{className:"h-5 w-5 shrink-0"})},n.segment)})})})}function Nq(){return c.jsxs("div",{className:"flex h-full flex-col overflow-hidden bg-base text-fg",children:[c.jsx(yq,{}),c.jsxs("div",{className:"flex min-h-0 flex-1",children:[c.jsx(vq,{}),c.jsx("main",{className:"flex min-w-0 flex-1 flex-col overflow-hidden pb-[calc(3.5rem_+_var(--safe-bottom))] md:pb-0",children:c.jsx(Z7,{})})]}),c.jsx(Eq,{}),c.jsx(hq,{})]})}let Sq=0;const ar=$i(e=>({toasts:[],addToast:(t,n="info",r,a)=>{const i=(a==null?void 0:a.id)??`toast-${++Sq}-${Date.now()}`;e(o=>o.toasts.some(u=>u.id===i)?o:{toasts:[...o.toasts,{id:i,message:t,variant:n,sessionId:r,persistent:a==null?void 0:a.persistent}]}),a!=null&&a.persistent||setTimeout(()=>{e(o=>({toasts:o.toasts.filter(u=>u.id!==i)}))},uM)},removeToast:t=>{e(n=>({toasts:n.toasts.filter(r=>r.id!==t)}))}})),wq={info:{icon:"ℹ",badge:"bg-fg/10 text-fg-2",bar:"bg-fg-4"},success:{icon:"✓",badge:"bg-emerald-500/10 text-emerald-500",bar:"bg-emerald-500"},warning:{icon:"⚠",badge:"bg-amber-500/10 text-amber-500",bar:"bg-amber-500"},error:{icon:"✕",badge:"bg-red-500/10 text-red-500",bar:"bg-red-500"}};function zA(){const e=ar(m=>m.toasts),t=ar(m=>m.removeToast),n=Me(m=>m.setActiveSession),r=We(m=>m.activeRepoId),a=We(qr),i=zn(),o=m=>{t(m.id),m.sessionId&&r&&(n(r,m.sessionId),i(`/${encodeURIComponent(a)}/run`))},[u,d]=y.useState([]),f=y.useRef(new Map);return y.useEffect(()=>{const m=new Set(e.map(p=>p.id));d(p=>{let b=p.map(x=>m.has(x.id)||x.exiting?x:{...x,exiting:!0});for(const x of e)b.some(E=>E.id===x.id)||(b=[...b,{...x}]);return b})},[e]),y.useEffect(()=>{const m=f.current;for(const p of u)p.exiting&&!m.has(p.id)&&m.set(p.id,setTimeout(()=>{m.delete(p.id),d(b=>b.filter(x=>x.id!==p.id))},_Y))},[u]),y.useEffect(()=>{const m=f.current;return()=>m.forEach(clearTimeout)},[]),u.length===0?null:c.jsx("div",{className:"pointer-events-none fixed top-4 right-4 z-50 flex w-[calc(100%-2rem)] max-w-sm flex-col",role:"status","aria-live":"polite","aria-atomic":"false",children:u.map(m=>{const p=wq[m.variant];return c.jsx("div",{className:"grid w-full transition-[grid-template-rows] duration-300 ease-out",style:{gridTemplateRows:m.exiting?"0fr":"1fr"},children:c.jsx("div",{className:"min-h-0 overflow-hidden",children:c.jsxs("div",{role:"status",onClick:()=>o(m),style:{animation:`${m.exiting?"toast-out":"toast-in"} 0.3s ease-out forwards`},className:"pointer-events-auto relative mb-2 flex cursor-pointer items-start gap-3 overflow-hidden rounded-xl border border-line bg-surface/80 px-3.5 py-3 shadow-lg shadow-black/5 backdrop-blur-md transition-colors hover:border-line-hard hover:bg-surface/90",children:[c.jsx("span",{"aria-hidden":!0,className:`mt-px flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-xs font-semibold ${p.badge}`,children:p.icon}),c.jsx("p",{className:"min-w-0 flex-1 text-sm leading-snug break-words text-fg",children:m.message}),m.persistent&&!m.exiting&&c.jsx("button",{type:"button","aria-label":"关闭",onClick:b=>{b.stopPropagation(),t(m.id)},className:"mt-px flex h-5 w-5 shrink-0 items-center justify-center rounded-full text-fg-4 transition-colors hover:bg-fg/10 hover:text-fg",children:"✕"}),!m.exiting&&!m.persistent&&c.jsx("span",{"aria-hidden":!0,className:`absolute bottom-0 left-0 h-0.5 w-full origin-left ${p.bar}`,style:{animation:`toast-progress ${uM}ms linear forwards`}})]})})},m.id)})})}const _q=1e3,Tq=5e3,Jm="freeze-mon-buffer",Aq=4*1024*1024;class Cq{constructor(){pt(this,"ring",[]);pt(this,"counters",{sse:0,delta:0,store:0});pt(this,"workerCount",0);pt(this,"sampleTimer",0);pt(this,"persistTimer",0);pt(this,"running",!1)}tick(t){this.counters[t]++}setGauge(t,n){t==="workers"&&(this.workerCount=n)}exportData(){return localStorage.getItem(Jm)??JSON.stringify(this.ring)}start(){if(this.running)return;this.running=!0;const t=localStorage.getItem(Jm);if(t)try{this.ring=JSON.parse(t)}catch{this.ring=[]}this.sampleTimer=window.setInterval(()=>this.sample(),_q),this.persistTimer=window.setInterval(()=>this.persist(),Tq)}stop(){this.running=!1,clearInterval(this.sampleTimer),clearInterval(this.persistTimer),this.persist()}sample(){const t=Me.getState(),n=Object.values(t.messages).reduce((a,i)=>a+i.length,0),r=performance.memory;this.ring.push({ts:Date.now(),sse:this.counters.sse,delta:this.counters.delta,store:this.counters.store,workers:this.workerCount,msgs:n,heap:r?Math.round(r.usedJSHeapSize/1048576):void 0}),this.counters.sse=0,this.counters.delta=0,this.counters.store=0,this.trimToFit()}trimToFit(){for(;this.ring.length>1&&!(new Blob([JSON.stringify(this.ring)]).size<=Aq);)this.ring.shift()}persist(){try{localStorage.setItem(Jm,JSON.stringify(this.ring))}catch{this.ring.splice(0,Math.floor(this.ring.length/2));try{localStorage.setItem(Jm,JSON.stringify(this.ring))}catch{}}}}const vs=new Cq;function kq(e){if(typeof e!="string")return e;const t=e.trim();if(t)try{return JSON.parse(t)}catch{return t}}function ir(e){return e&&typeof e=="object"?e:null}function Kl(e){const t=ir(e);return t&&"properties"in t?t.properties:e}function Oq(e){const t=ir(e);return typeof(t==null?void 0:t.type)=="string"?t.type:void 0}function Iq(e){const t=ir(Kl(e));if(!t)return null;const n=ir(t.info);if(n&&typeof n.id=="string"){const a=Array.isArray(t.parts)?t.parts:void 0;return{...n,...a?{parts:a}:{}}}if(typeof t.id=="string"&&typeof t.role=="string")return t;const r=ir(t.message);return r&&typeof r.id=="string"?r:null}function Rq(e){const t=ir(Kl(e));if(!t)return{};const n=ir(t.part)??t;return typeof n.type!="string"?{}:{messageId:typeof n.messageID=="string"&&n.messageID||typeof n.messageId=="string"&&n.messageId||typeof t.messageID=="string"&&t.messageID||typeof t.messageId=="string"&&t.messageId||void 0,part:n}}function wM(e){const t=ir(Kl(e));if(!t||t.field!=="text")return null;const n=typeof t.messageID=="string"?t.messageID:null,r=typeof t.partID=="string"?t.partID:null,a=typeof t.delta=="string"?t.delta:null;return!n||!r||a===null?null:{messageId:n,partId:r,delta:a}}function Mq(e){const t=Kl(e);if(Array.isArray(t))return t;const n=ir(t);return n&&Array.isArray(n.todos)?n.todos:[]}function wi(e){return typeof e=="number"?e:0}function Dq(e){const t=ir(Kl(e));if(!t||typeof t.id!="string")return null;const n={id:t.id},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:wi(i==null?void 0:i.input)||wi(t.tokens_input),output:wi(i==null?void 0:i.output)||wi(t.tokens_output),reasoning:wi(i==null?void 0:i.reasoning)||wi(t.tokens_reasoning),cache:{read:wi(d==null?void 0:d.read)||wi(t.tokens_cache_read),write:wi(d==null?void 0:d.write)||wi(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 jq(e){const t=ir(Kl(e));if(!t)return null;if(typeof t.message=="string")return t.message;const n=ir(t.error);if(n){const r=ir(n.data);if(typeof(r==null?void 0:r.message)=="string")return`${n.name??"Error"}: ${r.message}`;if(typeof n.message=="string")return`${n.name??"Error"}: ${n.message}`;if(typeof n.name=="string")return String(n.name)}return typeof t.reason=="string"?t.reason:null}function Lq(e){const t=Kl(e);if(typeof t=="string")return t;const n=ir(t);if(typeof(n==null?void 0:n.status)=="string")return n.status;const r=ir(n==null?void 0:n.status);return typeof(r==null?void 0:r.type)=="string"?r.type:typeof(n==null?void 0:n.type)=="string"?n.type:null}function HA(e,t,n,r){switch(e==="message"||e===""?Oq(t)??e:e){case"message.updated":{const i=Iq(t);i&&r.updateMessage(n,i);break}case"session.updated":{const i=Dq(t);i&&r.updateSessionInfo(i);break}case"message.part.updated":{const{messageId:i,part:o}=Rq(t);o&&i&&r.updateMessagePart(n,i,o);break}case"message.part.delta":{const i=wM(t);i&&r.appendMessagePartDelta(n,i.messageId,i.partId,i.delta);break}case"todo.updated":{r.updateTodos(n,Mq(t));break}case"session.status":{const i=Lq(t);i&&r.setSessionStatus(n,i);break}case"session.idle":{r.setSessionStatus(n,"idle");break}case"session.error":{const i=jq(t);r.setSessionStatus(n,"error",i??void 0);break}}}const Pq=1e3,Bq=3e4;class Uq{constructor(t,n){pt(this,"source",null);pt(this,"reconnectTimer",null);pt(this,"attempts",0);pt(this,"disposed",!1);pt(this,"repoId");pt(this,"onEvent");this.repoId=t,this.onEvent=n}start(){this.connect()}stop(){var t;this.disposed=!0,this.reconnectTimer&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),(t=this.source)==null||t.close(),this.source=null}connect(){if(this.disposed)return;const t=dY(this.repoId),n=new EventSource(t);this.source=n,n.onopen=()=>{this.attempts=0},n.onmessage=a=>{this.handleRaw("message",a)};const r=["message.updated","message.part.updated","message.part.delta","message.removed","todo.updated","session.status","session.idle","session.error","session.updated"];for(const a of r)n.addEventListener(a,i=>{this.handleRaw(a,i)});n.onerror=()=>{if(!(this.disposed||!this.source)&&this.source.readyState===EventSource.CLOSED){this.source.close(),this.source=null;const a=Math.min(Pq*2**this.attempts,Bq);this.attempts++,this.reconnectTimer=setTimeout(()=>this.connect(),a)}}}handleRaw(t,n){if(!(n instanceof MessageEvent))return;vs.tick("sse");const r=kq(n.data);if(r===void 0)return;const a=this.extractSessionId(r);if(!a)return;let i=t;if(t==="message"||t===""){const o=r&&typeof r=="object"?r:null;typeof(o==null?void 0:o.type)=="string"&&(i=o.type)}this.onEvent(a,i,r)}extractSessionId(t){if(!t||typeof t!="object")return null;const n=t;if(n.properties&&typeof n.properties=="object"){const r=n.properties;if(typeof r.sessionID=="string")return r.sessionID;if(typeof r.id=="string")return r.id}return typeof n.sessionID=="string"?n.sessionID:typeof n.sessionId=="string"?n.sessionId:null}}const Fq=6e4;class zq{constructor(t,n){pt(this,"timer",null);pt(this,"paused",!1);pt(this,"repoId");pt(this,"callbacks");this.repoId=t,this.callbacks=n}start(){this.tick(),this.timer=setInterval(()=>{this.paused||this.tick()},Fq)}stop(){this.timer&&(clearInterval(this.timer),this.timer=null)}pause(){this.paused=!0}resume(){this.paused=!1,this.tick()}tick(){const t=this.repoId;Me.getState().loadSessions(t),fY(t).then(n=>{const r={};for(const[a,i]of Object.entries(n))r[a]=i.type??"idle";Me.getState().bulkSetStatuses(r);for(const[a,i]of Object.entries(r))(i==="busy"||i==="retry")&&this.callbacks.ensureWorker(a)}).catch(()=>{})}}const Hq=600*1e3,$q=200;class Yq{constructor(t,n,r){pt(this,"sessionId");pt(this,"repoId");pt(this,"idleTimer",null);pt(this,"flushTimer",null);pt(this,"active",!1);pt(this,"alive",!0);pt(this,"callbacks");pt(this,"eventQueue",[]);pt(this,"deltaBuffer",new Map);this.sessionId=t,this.repoId=n,this.callbacks=r,this.resetIdleTimer()}dispatch(t,n){if(this.alive){if(this.resetIdleTimer(),vs.tick("sse"),t==="message.part.delta"){this.bufferDelta(n),this.scheduleFlush();return}if(t==="session.idle"||t==="session.status"||t==="session.error"){this.flush();const r=Me.getState(),a=r.sessionStatuses[this.sessionId];HA(t,n,this.sessionId,r);const i=Me.getState().sessionStatuses[this.sessionId];a&&a!=="idle"&&i==="idle"&&this.callbacks.onSessionIdle(this.sessionId);return}this.eventQueue.push({name:t,data:n}),this.scheduleFlush()}}activate(){this.active=!0,this.clearIdleTimer()}deactivate(){this.active=!1,this.resetIdleTimer()}refreshOnIdle(){Me.getState().refreshSessionData(this.repoId,this.sessionId)}stop(){this.alive=!1,this.flush(),this.clearIdleTimer(),this.cancelFlush()}scheduleFlush(){this.flushTimer||(this.flushTimer=setTimeout(()=>{this.flushTimer=null,this.flush()},$q))}cancelFlush(){this.flushTimer&&(clearTimeout(this.flushTimer),this.flushTimer=null)}bufferDelta(t){const n=wM(t);if(!n)return;const r=this.deltaBuffer.get(n.partId);r?r.text+=n.delta:this.deltaBuffer.set(n.partId,{messageId:n.messageId,text:n.delta})}flush(){if(this.eventQueue.length===0&&this.deltaBuffer.size===0)return;const t=Me.getState(),n=this.eventQueue;this.eventQueue=[];for(const r of n)HA(r.name,r.data,this.sessionId,t);if(this.deltaBuffer.size>0){const r=this.deltaBuffer;this.deltaBuffer=new Map;for(const[a,{messageId:i,text:o}]of r)vs.tick("delta"),vs.tick("store"),t.appendMessagePartDelta(this.sessionId,i,a,o)}}resetIdleTimer(){this.clearIdleTimer(),!this.active&&(this.idleTimer=setTimeout(()=>{this.callbacks.onWorkerIdle(this.sessionId)},Hq))}clearIdleTimer(){this.idleTimer&&(clearTimeout(this.idleTimer),this.idleTimer=null)}}class qq{constructor(){pt(this,"workers",new Map);pt(this,"dispatcher",null);pt(this,"supervisor",null);pt(this,"visibilityHandler",null);pt(this,"repoId",null)}start(t){this.stop(),this.repoId=t;const n={onWorkerIdle:r=>this.removeWorker(r),onSessionIdle:r=>{var a;(a=this.workers.get(r))==null||a.refreshOnIdle()}};this.dispatcher=new Uq(t,(r,a,i)=>{this.ensureWorker(r,t,n).dispatch(a,i)}),this.dispatcher.start(),this.supervisor=new zq(t,{ensureWorker:r=>this.ensureWorker(r,t,n)}),this.supervisor.start(),this.visibilityHandler=()=>{var r,a;document.hidden?(r=this.supervisor)==null||r.pause():(a=this.supervisor)==null||a.resume()},document.addEventListener("visibilitychange",this.visibilityHandler)}stop(){var t,n;(t=this.dispatcher)==null||t.stop(),this.dispatcher=null,(n=this.supervisor)==null||n.stop(),this.supervisor=null;for(const r of this.workers.values())r.stop();this.workers.clear(),this.visibilityHandler&&(document.removeEventListener("visibilitychange",this.visibilityHandler),this.visibilityHandler=null)}activateSession(t){if(!this.repoId||!t)return;const n=this.repoId;for(const i of this.workers.values())i.sessionId!==t&&i.deactivate();const r={onWorkerIdle:i=>this.removeWorker(i),onSessionIdle:i=>{var o;return(o=this.workers.get(i))==null?void 0:o.refreshOnIdle()}};this.ensureWorker(t,n,r).activate(),Me.getState().refreshSessionData(n,t)}deactivateSession(t){var n;(n=this.workers.get(t))==null||n.deactivate()}ensureWorker(t,n,r){let a=this.workers.get(t);return a||(a=new Yq(t,n,r),this.workers.set(t,a),vs.setGauge("workers",this.workers.size)),a}removeWorker(t){const n=Me.getState().activeSessionId;if(t===n)return;const r=this.workers.get(t);r&&(r.stop(),this.workers.delete(t),vs.setGauge("workers",this.workers.size))}}const Vp=new qq;function oh({onConfirm:e,size:t="sm",variant:n="ghost",triggerClassName:r,stopPropagation:a,title:i="删除",children:o}){const[u,d]=y.useState(!1),f=t==="sm"?"h-3.5 w-3.5":"h-4 w-4",m=t==="sm"?"p-1":"p-1.5",p=n==="outlined"?"rounded-md":"rounded",b=t==="sm"?"gap-0.5":"gap-1",x=a?E=>E.stopPropagation():void 0;return u?c.jsxs("div",{className:ie("flex items-center",b),onClick:x,children:[c.jsx("button",{type:"button",onClick:()=>{e(),d(!1)},className:ie(p,m,"text-red-400 hover:bg-red-500/10",n==="outlined"&&"border border-red-500/30"),children:c.jsx(fi,{className:f})}),c.jsx("button",{type:"button",onClick:()=>d(!1),className:ie(p,m,"text-fg-4 hover:bg-elevated",n==="outlined"&&"border border-line"),children:c.jsx(At,{className:f})})]}):c.jsxs(c.Fragment,{children:[o,c.jsx("button",{type:"button",onClick:E=>{x==null||x(E),d(!0)},title:i,className:ie(p,m,r??"text-fg-5 hover:text-red-400",n==="outlined"&&"border border-line transition-colors hover:border-red-500/30"),children:c.jsx(a0,{className:f})})]})}function Gq(e,t){if(e instanceof Li)try{const n=JSON.parse(e.message);if(n.error)return n.error}catch{if(e.message)return e.message}return e instanceof Error?e.message:t}function lc(e,t,n){const{initialData:r,showErrorToast:a=!0,errorMessage:i="加载失败",skip:o=!1}=n??{},[u,d]=y.useState(r??null),[f,m]=y.useState(!o),[p,b]=y.useState(null),x=y.useRef(0),E=y.useRef(e);E.current=e;const N=y.useRef(i);N.current=i;const _=y.useRef(a);_.current=a;const S=y.useCallback(async()=>{const C=++x.current;m(!0),b(null);try{const A=await E.current();if(x.current!==C)return;d(A)}catch(A){if(x.current!==C)return;const I=Gq(A,N.current);b(I),_.current&&ar.getState().addToast(I,"error")}x.current===C&&m(!1)},[]);return y.useEffect(()=>{if(o){m(!1);return}return S(),()=>{x.current++}},[...t,o,S]),{data:u,loading:f,error:p,reload:S}}const Kq=["Sisyphus - ultraworker","Prometheus - Plan Builder","Atlas - Plan Executor"],Vq="pinned_models",il="__system_prompt__",$A=[{bg:"bg-blue-500/10",text:"text-blue-400"},{bg:"bg-amber-500/10",text:"text-amber-400"},{bg:"bg-green-500/10",text:"text-green-400"},{bg:"bg-purple-500/10",text:"text-purple-400"},{bg:"bg-cyan-500/10",text:"text-cyan-400"},{bg:"bg-rose-500/10",text:"text-rose-400"},{bg:"bg-indigo-500/10",text:"text-indigo-400"},{bg:"bg-orange-500/10",text:"text-orange-400"}],Wq={bg:"bg-elevated",text:"text-fg-4"};function _M(e){if(e==="general")return Wq;let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return $A[Math.abs(t)%$A.length]}function uc(e){const t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return"刚刚";if(n<60)return`${n} 分钟前`;const r=Math.floor(n/60);if(r<24)return`${r} 小时前`;const a=Math.floor(r/24);return a<30?`${a} 天前`:`${Math.floor(a/30)} 个月前`}const TM={create:{label:"首次提取",color:"text-green-400"},update:{label:"重写",color:"text-blue-400"},merge:{label:"合并",color:"text-purple-400"},decay:{label:"衰减",color:"text-amber-400"},reinforce:{label:"强化",color:"text-emerald-400"},manual:{label:"手动编辑",color:"text-fg-3"}};function Xq({memory:e,onClose:t}){const n=[...e.history??[]].reverse();return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50",onClick:t,children:c.jsxs("div",{className:"mx-4 max-h-[80vh] w-full max-w-lg overflow-y-auto rounded-xl border border-line bg-surface p-5 shadow-xl",onClick:r=>r.stopPropagation(),children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("h3",{className:"text-sm font-semibold text-fg",children:["版本历史 (",n.length+1," 个版本)"]}),c.jsx("button",{type:"button",onClick:t,className:"rounded p-1 text-fg-4 hover:text-fg-3",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"rounded-lg border border-blue-500/20 bg-blue-500/5 p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[10px]",children:[c.jsx("span",{className:"font-medium text-blue-400",children:"当前版本"}),c.jsx("span",{className:"text-fg-5",children:uc(e.updatedAt)}),c.jsxs("span",{className:"text-fg-6",children:["⚡ ",e.importance.toFixed(2)]})]}),c.jsx("p",{className:"text-xs leading-relaxed text-fg",children:e.content})]}),n.map((r,a)=>{const i=TM[r.action]??{label:r.action,color:"text-fg-4"};return c.jsxs("div",{className:"rounded-lg border border-line bg-base p-3",children:[c.jsxs("div",{className:"mb-1 flex items-center gap-2 text-[10px]",children:[c.jsx("span",{className:ie("font-medium",i.color),children:i.label}),c.jsx("span",{className:"text-fg-5",children:uc(r.ts)}),c.jsxs("span",{className:"text-fg-6",children:["⚡ ",r.importance.toFixed(2)]}),r.source&&c.jsxs("span",{className:"text-fg-6",children:["· ",r.source]})]}),c.jsx("p",{className:"text-xs leading-relaxed text-fg-4",children:r.content})]},a)}),n.length===0&&c.jsx("div",{className:"py-4 text-center text-xs text-fg-5",children:"暂无历史版本"})]})]})})}function YA({memory:e,categories:t,onUpdate:n,onDelete:r}){var C;const[a,i]=y.useState(!1),[o,u]=y.useState(e.content),[d,f]=y.useState(e.category),[m,p]=y.useState(!1),[b,x]=y.useState(!1),E=_M(e.category),N=(C=e.history)==null?void 0:C[e.history.length-1],_=N&&Math.abs(N.importance-e.importance)>.001,S=async()=>{p(!0);try{await n(e.id,{content:o,category:d}),i(!1)}finally{p(!1)}};return a?c.jsxs("div",{className:"rounded-lg border border-blue-500/30 bg-blue-500/5 p-3 space-y-2",children:[c.jsx("textarea",{value:o,onChange:A=>u(A.target.value),rows:3,className:"w-full resize-y rounded-md border border-line bg-surface px-3 py-2 font-mono text-xs leading-relaxed text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none"}),c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("select",{value:d,onChange:A=>f(A.target.value),className:"rounded-md border border-line bg-surface px-2 py-1 text-xs text-fg focus:border-blue-500 focus:outline-none",children:t.map(A=>c.jsx("option",{value:A,children:A},A))}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:()=>{i(!1),u(e.content),f(e.category)},className:"rounded-md px-3 py-1 text-xs text-fg-4 hover:bg-elevated",children:"取消"}),c.jsx("button",{type:"button",onClick:()=>void S(),disabled:m||!o.trim(),className:"rounded-md bg-blue-600 px-3 py-1 text-xs font-medium text-white hover:bg-blue-500 disabled:opacity-40",children:m?"保存中…":"保存"})]})]}):c.jsxs("div",{className:"group/mem rounded-lg border border-line bg-base px-3 py-2.5",children:[c.jsxs("div",{className:"flex items-start gap-2",children:[c.jsx("span",{className:ie("mt-0.5 shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",E.bg,E.text),children:e.category}),c.jsx("p",{className:"min-w-0 flex-1 text-xs leading-relaxed text-fg",children:e.content})]}),c.jsxs("div",{className:"mt-1.5 flex items-center gap-2 text-[11px] text-fg-5",children:[c.jsxs("span",{className:"flex items-center gap-0.5",children:[c.jsx(Cc,{className:"h-3 w-3"}),_&&N?`${N.importance.toFixed(2)}→${e.importance.toFixed(2)}`:e.importance.toFixed(2)]}),c.jsx("span",{children:"·"}),c.jsx("span",{children:uc(e.updatedAt)}),e.supersededBy&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsx("span",{className:"text-amber-400",children:e.supersededBy==="user-deleted"?"已删除":e.supersededBy==="consolidated-out"?"已整理":"已合并"})]}),e.history&&e.history.length>0&&(()=>{const A=e.history[e.history.length-1],I=TM[A.action];return c.jsxs("button",{type:"button",onClick:()=>x(!0),"data-guide":e.id==="guide-mem-1"?"agent-memory-version":void 0,className:ie("rounded px-1.5 py-0.5 text-[10px] font-medium transition-opacity hover:opacity-80",A.action==="update"?"bg-blue-500/10 text-blue-400":A.action==="merge"?"bg-purple-500/10 text-purple-400":A.action==="decay"?"bg-amber-500/10 text-amber-400":A.action==="reinforce"?"bg-emerald-500/10 text-emerald-400":A.action==="manual"?"bg-fg/10 text-fg-3":"bg-green-500/10 text-green-400"),children:[(I==null?void 0:I.label)??A.action," · ",e.history.length,"版"]})})(),c.jsx("div",{className:"flex-1"}),!e.supersededBy&&c.jsx("div",{className:"flex items-center gap-0.5 opacity-0 transition-opacity group-hover/mem:opacity-100",children:c.jsx(oh,{onConfirm:()=>void r(e.id),children:c.jsx("button",{type:"button",onClick:()=>i(!0),className:"rounded p-1 text-fg-5 hover:text-fg-3",children:c.jsx(jE,{className:"h-3.5 w-3.5"})})})})]}),b&&c.jsx(Xq,{memory:e,onClose:()=>x(!1)})]})}const Qq=14400*1e3;function Zq(e){if(!e)return"下次:待定";const t=e+Qq,n=Date.now();if(t<=n)return"下次:即将运行";const r=t-n,a=Math.floor(r/6e4);if(a<60)return`下次:约 ${a} 分钟后`;const i=Math.floor(a/60);return i<24?`下次:约 ${i} 小时后`:`下次:约 ${Math.floor(i/24)} 天后`}function Jq({stats:e,running:t,onTrigger:n}){if(!e)return null;const r=e.lastActions;return c.jsxs("div",{className:"rounded-lg bg-elevated px-3 py-2 text-[11px] tabular-nums text-fg-5",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-3 gap-y-1",children:[c.jsx("span",{children:e.lastConsolidatedAt?`上次整理:${uc(e.lastConsolidatedAt)}`:"尚未整理"}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{children:Zq(e.lastConsolidatedAt)}),c.jsx("div",{className:"flex-1"}),c.jsx("button",{type:"button",onClick:n,disabled:t,className:"rounded px-2 py-0.5 text-[10px] font-medium text-fg-4 transition-colors hover:bg-surface hover:text-fg-3 disabled:opacity-40",children:t?"整理中…":"立即整理"})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1",children:[r&&c.jsxs(c.Fragment,{children:[c.jsxs("span",{children:[r.update," 更新 ",r.merge," 合并 ",r.delete," 清理 ",r.decayed," 降权"]}),c.jsx("span",{className:"text-fg-6",children:"·"})]}),c.jsxs("span",{children:["活跃 ",e.totalActive," 条"]}),c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsxs("span",{children:["衰减中 ",e.stale]})]})]})}function eG({agentId:e}){const t=e.startsWith(gM),[n,r]=y.useState(null),[a,i]=y.useState(!1),[o,u]=y.useState(!1),[d,f]=y.useState(new Set),[m,p]=y.useState(!1),[b,x]=y.useState(null),[E,N]=y.useState(null),[_,S]=y.useState(!1),{data:C,loading:A,reload:I}=lc(()=>t?Promise.resolve(WY):rM(e,{includeSuperseded:a}),[e,a,t],{showErrorToast:!t,errorMessage:"加载记忆失败"}),O=C??[],k=y.useCallback(()=>{t||dA(e).then(N).catch(()=>N(null))},[e,t]);y.useEffect(()=>{k()},[k]);const j=async()=>{S(!0);try{await U$(e)}catch{S(!1);return}const D=setInterval(()=>{dA(e).then(z=>{N(z),z.lastConsolidatedAt&&(!(E!=null&&E.lastConsolidatedAt)||z.lastConsolidatedAt>E.lastConsolidatedAt)&&(clearInterval(D),S(!1),I())}).catch(()=>{})},5e3);setTimeout(()=>{clearInterval(D),S(!1)},3e5)},{data:F,loading:P}=lc(()=>BE(e),[e,o],{skip:!o,errorMessage:"加载 Session 列表失败"}),L=F??[],B=O.filter(D=>!D.supersededBy),Y=n?B.filter(D=>D.category===n):B,re=O.filter(D=>D.supersededBy),X=y.useMemo(()=>new Set(O.map(D=>D.sessionId).filter(Boolean)),[O]),K=async(D,z)=>{await L$(e,D,z),await I()},V=async D=>{await P$(e,D),await I()},H=D=>{f(z=>{const $=new Set(z);return $.has(D)?$.delete(D):$.add(D),$})},G=async()=>{if(d.size!==0){p(!0),x(null);try{const $=(await B$(e,[...d])).results;if($){const M=$.filter(oe=>oe.status==="ok"),le=$.filter(oe=>oe.status!=="ok");M.length>0&&x(`提取成功 ${M.reduce((oe,ne)=>oe+(ne.actions??0),0)} 条记忆`),le.length>0&&x(oe=>(oe?`${oe};`:"")+le.map(ne=>ne.error??ne.status).join(";")),M.length>0&&await I()}f(new Set)}catch(D){x(`请求失败: ${D instanceof Error?D.message:String(D)}`)}p(!1)}},Q=y.useMemo(()=>[...new Set(B.map(z=>z.category))].sort(),[B]);return c.jsxs("section",{"data-guide":"agent-memory-section",className:"rounded-xl border border-line bg-surface p-5 space-y-4",children:[c.jsx("div",{className:"flex items-center justify-between",children:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(oc,{className:"h-4 w-4 text-purple-400"}),c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"记忆"}),!A&&c.jsx("span",{className:"rounded-full bg-elevated px-1.5 py-0.5 text-[10px] tabular-nums text-fg-4",children:Y.length})]})}),c.jsx(Jq,{stats:E,running:_,onTrigger:()=>void j()}),c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[c.jsx("button",{type:"button",onClick:()=>r(null),className:ie("rounded-full px-2.5 py-0.5 text-[11px] font-medium transition-colors",n===null?"bg-fg/10 text-fg":"text-fg-4 hover:text-fg-3"),children:"全部"}),Q.map(D=>{const z=_M(D);return c.jsx("button",{type:"button",onClick:()=>r(n===D?null:D),className:ie("rounded-full px-2.5 py-0.5 text-[11px] font-medium transition-colors",n===D?ie(z.bg,z.text):"text-fg-4 hover:text-fg-3"),children:D},D)})]}),A?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):Y.length===0&&re.length===0?c.jsx("div",{className:"py-8 text-center text-xs text-fg-5",children:"暂无记忆。使用此 Agent 完成 Session 后将自动提取。"}):c.jsxs("div",{className:"space-y-1.5",children:[Y.map(D=>c.jsx(YA,{memory:D,categories:Q,onUpdate:K,onDelete:V},D.id)),re.length>0&&c.jsxs("div",{className:"pt-1",children:[c.jsxs("button",{type:"button",onClick:()=>i(!a),className:"flex items-center gap-1 text-[11px] text-fg-5 hover:text-fg-3",children:[c.jsx("span",{children:a?"▾":"▸"}),"已合并/已删除 (",re.length,")"]}),a&&c.jsx("div",{className:"mt-1.5 space-y-1.5 opacity-60",children:re.map(D=>c.jsx(YA,{memory:D,categories:Q,onUpdate:K,onDelete:V},D.id))})]})]}),c.jsxs("div",{className:"border-t border-line pt-3",children:[c.jsxs("button",{type:"button",onClick:()=>u(!o),className:"flex items-center gap-1.5 text-xs font-medium text-fg-4 hover:text-fg-3",children:[c.jsx(n0,{className:"h-3.5 w-3.5"}),c.jsxs("span",{children:[o?"▾":"▸"," 从 Session 提取记忆"]})]}),o&&c.jsx("div",{className:"mt-2 space-y-1.5",children:P?c.jsx("div",{className:"flex items-center justify-center py-4",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):L.length===0?c.jsx("p",{className:"py-4 text-center text-xs text-fg-5",children:"暂无 Session 记录。"}):c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"max-h-64 space-y-1 overflow-y-auto",children:L.map(D=>{const z=X.has(D.id);return c.jsxs("label",{className:ie("flex cursor-pointer items-center gap-2.5 rounded-md border px-3 py-2 transition-colors",d.has(D.id)?"border-purple-500/30 bg-purple-500/5":"border-line bg-base hover:bg-elevated/60"),children:[c.jsx("input",{type:"checkbox",checked:d.has(D.id),onChange:()=>H(D.id),className:"h-3.5 w-3.5 shrink-0 cursor-pointer rounded border-line accent-purple-500"}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"block truncate text-xs text-fg",children:D.title||D.id.slice(-8)}),c.jsx("span",{className:"text-[11px] text-fg-5",children:uc(D.timeCreated)})]}),c.jsx("span",{className:ie("shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium",z?"bg-green-500/10 text-green-400":"bg-elevated text-fg-5"),children:z?"已提取":"未提取"})]},D.id)})}),d.size>0&&c.jsxs("button",{type:"button",onClick:()=>void G(),disabled:m,className:"flex w-full items-center justify-center gap-1.5 rounded-lg bg-purple-600 py-2 text-xs font-medium text-white transition-colors hover:bg-purple-500 disabled:opacity-40",children:[m?c.jsx(nn,{className:"h-3.5 w-3.5 fs-spin"}):c.jsx(oc,{className:"h-3.5 w-3.5"}),m?"提取中…":`提取选中 Session 的记忆 (${d.size})`]}),b&&c.jsx("p",{className:ie("mt-1.5 rounded-md px-3 py-1.5 text-xs",b.includes("成功")?"bg-green-500/10 text-green-400":"bg-red-500/10 text-red-400"),children:b})]})})]})]})}function tG({agentId:e}){const{data:t,loading:n}=lc(()=>BE(e),[e],{errorMessage:"加载 Session 历史失败"}),r=t??[];return c.jsxs("section",{className:"rounded-xl border border-line bg-surface p-5",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(n0,{className:"h-4 w-4 text-fg-4"}),c.jsx("h2",{className:"text-sm font-semibold text-fg",children:"Session 历史"}),!n&&c.jsx("span",{className:"rounded-full bg-elevated px-1.5 py-0.5 text-[10px] tabular-nums text-fg-4",children:r.length})]}),c.jsx("div",{className:"mt-3",children:n?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"})}):r.length===0?c.jsx("p",{className:"py-8 text-center text-xs text-fg-5",children:"暂无 Session 记录。"}):c.jsx("div",{className:"space-y-1",children:r.map(a=>c.jsxs("div",{className:"flex items-center gap-3 rounded-lg border border-line bg-base px-4 py-2.5",children:[c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsx("span",{className:"block truncate text-xs font-medium text-fg",children:a.title||a.id.slice(-8)}),c.jsxs("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-fg-5",children:[c.jsx("span",{children:uc(a.timeCreated)}),a.cost>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsxs("span",{children:["$",a.cost.toFixed(4)]})]}),(a.tokensInput>0||a.tokensOutput>0)&&c.jsxs(c.Fragment,{children:[c.jsx("span",{children:"·"}),c.jsxs("span",{children:[Math.round((a.tokensInput+a.tokensOutput)/1e3),"K tokens"]})]})]})]}),a.completedAt?c.jsx("span",{className:"shrink-0 rounded-full bg-green-500/10 px-2 py-0.5 text-[10px] font-medium text-green-400",children:"完成"}):c.jsx("span",{className:"shrink-0 rounded-full bg-elevated px-2 py-0.5 text-[10px] font-medium text-fg-5",children:"进行中"})]},a.id))})})]})}function nG({agent:e,fragments:t,onSave:n}){const r=We(Q=>Q.activeRepoId),[a,i]=y.useState(!1),[o,u]=y.useState(e.name),[d,f]=y.useState(e.description??""),[m,p]=y.useState(e.baseAgent),[b,x]=y.useState(e.model??""),[E,N]=y.useState(e.variant??""),[_,S]=y.useState(e.memoryModel??""),[C,A]=y.useState(e.systemPrompt),[I,O]=y.useState(!1),[k,j]=y.useState(!1),[F,P]=y.useState([]);y.useEffect(()=>{if(!r){P([]);return}let Q=!1;return(async()=>{try{const[D,z]=await Promise.all([Ml(),kc(r)]);if(Q)return;const $=D[Vq],M=$?JSON.parse($):[],le=M.length>0?z.filter(oe=>M.includes(oe.id)):z;P(le.length>0?le:z)}catch{Q||P([])}})(),()=>{Q=!0}},[r]);const[L,B]=y.useState(()=>{const Q=e.fragments.map(M=>M.id),D=e.systemPromptPosition??-1,z=D>=0&&D<=Q.length?D:Q.length,$=[...Q];return $.splice(z,0,il),$}),Y=Q=>{B(D=>{if(D.includes(Q))return D.filter(M=>M!==Q);const z=D.indexOf(il),$=[...D];return $.splice(z>=0?z:$.length,0,Q),$})},re=(Q,D)=>{const z=Q+D;z<0||z>=L.length||B($=>{const M=[...$];return[M[Q],M[z]]=[M[z],M[Q]],M})},X=L.filter(Q=>Q!==il),K=(()=>{const Q=L.indexOf(il);return Q<0?-1:L.slice(0,Q).filter(D=>D!==il).length})(),V=L.map(Q=>{var D;return Q===il?C:(D=t.find(z=>z.id===Q))==null?void 0:D.content}).filter(Boolean).join(`
|
|
524
524
|
|
|
525
525
|
---
|
|
526
526
|
|
|
@@ -649,7 +649,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
|
|
|
649
649
|
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:b,table:o,tableCell:d,tableRow:u}};function o(x,E,N,_){return f(m(x,N,_),x.align)}function u(x,E,N,_){const S=p(x,N,_),C=f([S]);return C.slice(0,C.indexOf(`
|
|
650
650
|
`))}function d(x,E,N,_){const S=N.enter("tableCell"),C=N.enter("phrasing"),A=N.containerPhrasing(x,{..._,before:i,after:i});return C(),S(),A}function f(x,E){return Gve(x,{align:E,alignDelimiters:r,padding:n,stringLength:a})}function m(x,E,N){const _=x.children;let S=-1;const C=[],A=E.enter("table");for(;++S<_.length;)C[S]=p(_[S],E,N);return A(),C}function p(x,E,N){const _=x.children;let S=-1;const C=[],A=E.enter("tableRow");for(;++S<_.length;)C[S]=d(_[S],x,E,N);return A(),C}function b(x,E,N){let _=U8.inlineCode(x,E,N);return N.stack.includes("tableCell")&&(_=_.replace(/\|/g,"\\$&")),_}}function M1e(){return{exit:{taskListCheckValueChecked:xI,taskListCheckValueUnchecked:xI,paragraph:j1e}}}function D1e(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:L1e}}}function xI(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function j1e(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const a=t.children;let i=-1,o;for(;++i<a.length;){const u=a[i];if(u.type==="paragraph"){o=u;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function L1e(e,t,n,r){const a=e.children[0],i=typeof e.checked=="boolean"&&a&&a.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",u=n.createTracker(r);i&&u.move(o);let d=U8.listItem(e,t,n,{...r,...u.current()});return i&&(d=d.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,f)),d;function f(m){return m+o}}function P1e(){return[pve(),Lve(),Fve(),T1e(),M1e()]}function B1e(e){return{extensions:[gve(),Pve(e),zve(),R1e(e),D1e()]}}const U1e={tokenize:q1e,partial:!0},F8={tokenize:G1e,partial:!0},z8={tokenize:K1e,partial:!0},H8={tokenize:V1e,partial:!0},F1e={tokenize:W1e,partial:!0},$8={name:"wwwAutolink",tokenize:$1e,previous:q8},Y8={name:"protocolAutolink",tokenize:Y1e,previous:G8},Bs={name:"emailAutolink",tokenize:H1e,previous:K8},qi={};function z1e(){return{text:qi}}let dl=48;for(;dl<123;)qi[dl]=Bs,dl++,dl===58?dl=65:dl===91&&(dl=97);qi[43]=Bs;qi[45]=Bs;qi[46]=Bs;qi[95]=Bs;qi[72]=[Bs,Y8];qi[104]=[Bs,Y8];qi[87]=[Bs,$8];qi[119]=[Bs,$8];function H1e(e,t,n){const r=this;let a,i;return o;function o(p){return!cE(p)||!K8.call(r,r.previous)||aw(r.events)?n(p):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),u(p))}function u(p){return cE(p)?(e.consume(p),u):p===64?(e.consume(p),d):n(p)}function d(p){return p===46?e.check(F1e,m,f)(p):p===45||p===95||Or(p)?(i=!0,e.consume(p),d):m(p)}function f(p){return e.consume(p),a=!0,d}function m(p){return i&&a&&Hr(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(p)):n(p)}}function $1e(e,t,n){const r=this;return a;function a(o){return o!==87&&o!==119||!q8.call(r,r.previous)||aw(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(U1e,e.attempt(F8,e.attempt(z8,i),n),n)(o))}function i(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function Y1e(e,t,n){const r=this;let a="",i=!1;return o;function o(p){return(p===72||p===104)&&G8.call(r,r.previous)&&!aw(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),a+=String.fromCodePoint(p),e.consume(p),u):n(p)}function u(p){if(Hr(p)&&a.length<5)return a+=String.fromCodePoint(p),e.consume(p),u;if(p===58){const b=a.toLowerCase();if(b==="http"||b==="https")return e.consume(p),d}return n(p)}function d(p){return p===47?(e.consume(p),i?f:(i=!0,d)):n(p)}function f(p){return p===null||Hg(p)||Jt(p)||Hl(p)||tb(p)?n(p):e.attempt(F8,e.attempt(z8,m),n)(p)}function m(p){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(p)}}function q1e(e,t,n){let r=0;return a;function a(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),a):o===46&&r===3?(e.consume(o),i):n(o)}function i(o){return o===null?n(o):t(o)}}function G1e(e,t,n){let r,a,i;return o;function o(f){return f===46||f===95?e.check(H8,d,u)(f):f===null||Jt(f)||Hl(f)||f!==45&&tb(f)?d(f):(i=!0,e.consume(f),o)}function u(f){return f===95?r=!0:(a=r,r=void 0),e.consume(f),o}function d(f){return a||r||!i?n(f):t(f)}}function K1e(e,t){let n=0,r=0;return a;function a(o){return o===40?(n++,e.consume(o),a):o===41&&r<n?i(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(H8,t,i)(o):o===null||Jt(o)||Hl(o)?t(o):(e.consume(o),a)}function i(o){return o===41&&r++,e.consume(o),a}}function V1e(e,t,n){return r;function r(u){return u===33||u===34||u===39||u===41||u===42||u===44||u===46||u===58||u===59||u===63||u===95||u===126?(e.consume(u),r):u===38?(e.consume(u),i):u===93?(e.consume(u),a):u===60||u===null||Jt(u)||Hl(u)?t(u):n(u)}function a(u){return u===null||u===40||u===91||Jt(u)||Hl(u)?t(u):r(u)}function i(u){return Hr(u)?o(u):n(u)}function o(u){return u===59?(e.consume(u),r):Hr(u)?(e.consume(u),o):n(u)}}function W1e(e,t,n){return r;function r(i){return e.consume(i),a}function a(i){return Or(i)?n(i):t(i)}}function q8(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||Jt(e)}function G8(e){return!Hr(e)}function K8(e){return!(e===47||cE(e))}function cE(e){return e===43||e===45||e===46||e===95||Or(e)}function aw(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const X1e={tokenize:aEe,partial:!0};function Q1e(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:tEe,continuation:{tokenize:nEe},exit:rEe}},text:{91:{name:"gfmFootnoteCall",tokenize:eEe},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Z1e,resolveTo:J1e}}}}function Z1e(e,t,n){const r=this;let a=r.events.length;const i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;a--;){const d=r.events[a][1];if(d.type==="labelImage"){o=d;break}if(d.type==="gfmFootnoteCall"||d.type==="labelLink"||d.type==="label"||d.type==="image"||d.type==="link")break}return u;function u(d){if(!o||!o._balanced)return n(d);const f=di(r.sliceSerialize({start:o.end,end:r.now()}));return f.codePointAt(0)!==94||!i.includes(f.slice(1))?n(d):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(d),e.exit("gfmFootnoteCallLabelMarker"),t(d))}}function J1e(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},a={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};a.end.column++,a.end.offset++,a.end._bufferIndex++;const i={type:"gfmFootnoteCallString",start:Object.assign({},a.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},i.start),end:Object.assign({},i.end)},u=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",a,t],["exit",a,t],["enter",i,t],["enter",o,t],["exit",o,t],["exit",i,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...u),e}function eEe(e,t,n){const r=this,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i=0,o;return u;function u(p){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),d}function d(p){return p!==94?n(p):(e.enter("gfmFootnoteCallMarker"),e.consume(p),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",f)}function f(p){if(i>999||p===93&&!o||p===null||p===91||Jt(p))return n(p);if(p===93){e.exit("chunkString");const b=e.exit("gfmFootnoteCallString");return a.includes(di(r.sliceSerialize(b)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(p),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(p)}return Jt(p)||(o=!0),i++,e.consume(p),p===92?m:f}function m(p){return p===91||p===92||p===93?(e.consume(p),i++,f):f(p)}}function tEe(e,t,n){const r=this,a=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let i,o=0,u;return d;function d(E){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(E),e.exit("gfmFootnoteDefinitionLabelMarker"),f}function f(E){return E===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(E),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",m):n(E)}function m(E){if(o>999||E===93&&!u||E===null||E===91||Jt(E))return n(E);if(E===93){e.exit("chunkString");const N=e.exit("gfmFootnoteDefinitionLabelString");return i=di(r.sliceSerialize(N)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(E),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),b}return Jt(E)||(u=!0),o++,e.consume(E),E===92?p:m}function p(E){return E===91||E===92||E===93?(e.consume(E),o++,m):m(E)}function b(E){return E===58?(e.enter("definitionMarker"),e.consume(E),e.exit("definitionMarker"),a.includes(i)||a.push(i),Tt(e,x,"gfmFootnoteDefinitionWhitespace")):n(E)}function x(E){return t(E)}}function nEe(e,t,n){return e.check(Oh,t,e.attempt(X1e,t,n))}function rEe(e){e.exit("gfmFootnoteDefinition")}function aEe(e,t,n){const r=this;return Tt(e,a,"gfmFootnoteDefinitionIndent",5);function a(i){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(i):n(i)}}function iEe(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:i,resolveAll:a};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function a(o,u){let d=-1;for(;++d<o.length;)if(o[d][0]==="enter"&&o[d][1].type==="strikethroughSequenceTemporary"&&o[d][1]._close){let f=d;for(;f--;)if(o[f][0]==="exit"&&o[f][1].type==="strikethroughSequenceTemporary"&&o[f][1]._open&&o[d][1].end.offset-o[d][1].start.offset===o[f][1].end.offset-o[f][1].start.offset){o[d][1].type="strikethroughSequence",o[f][1].type="strikethroughSequence";const m={type:"strikethrough",start:Object.assign({},o[f][1].start),end:Object.assign({},o[d][1].end)},p={type:"strikethroughText",start:Object.assign({},o[f][1].end),end:Object.assign({},o[d][1].start)},b=[["enter",m,u],["enter",o[f][1],u],["exit",o[f][1],u],["enter",p,u]],x=u.parser.constructs.insideSpan.null;x&&Ca(b,b.length,0,nb(x,o.slice(f+1,d),u)),Ca(b,b.length,0,[["exit",p,u],["enter",o[d][1],u],["exit",o[d][1],u],["exit",m,u]]),Ca(o,f-1,d-f+3,b),d=f+b.length-2;break}}for(d=-1;++d<o.length;)o[d][1].type==="strikethroughSequenceTemporary"&&(o[d][1].type="data");return o}function i(o,u,d){const f=this.previous,m=this.events;let p=0;return b;function b(E){return f===126&&m[m.length-1][1].type!=="characterEscape"?d(E):(o.enter("strikethroughSequenceTemporary"),x(E))}function x(E){const N=vc(f);if(E===126)return p>1?d(E):(o.consume(E),p++,x);if(p<2&&!n)return d(E);const _=o.exit("strikethroughSequenceTemporary"),S=vc(E);return _._open=!S||S===2&&!!N,_._close=!N||N===2&&!!S,u(E)}}}class sEe{constructor(){this.map=[]}add(t,n,r){oEe(this,t,n,r)}consume(t){if(this.map.sort(function(i,o){return i[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let a=r.pop();for(;a;){for(const i of a)t.push(i);a=r.pop()}this.map.length=0}}function oEe(e,t,n,r){let a=0;if(!(n===0&&r.length===0)){for(;a<e.map.length;){if(e.map[a][0]===t){e.map[a][1]+=n,e.map[a][2].push(...r);return}a+=1}e.map.push([t,n,r])}}function lEe(e,t){let n=!1;const r=[];for(;t<e.length;){const a=e[t];if(n){if(a[0]==="enter")a[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(a[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const i=r.length-1;r[i]=r[i]==="left"?"center":"right"}}else if(a[1].type==="tableDelimiterRow")break}else a[0]==="enter"&&a[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function uEe(){return{flow:{null:{name:"table",tokenize:cEe,resolveAll:dEe}}}}function cEe(e,t,n){const r=this;let a=0,i=0,o;return u;function u(L){let B=r.events.length-1;for(;B>-1;){const X=r.events[B][1].type;if(X==="lineEnding"||X==="linePrefix")B--;else break}const Y=B>-1?r.events[B][1].type:null,re=Y==="tableHead"||Y==="tableRow"?k:d;return re===k&&r.parser.lazy[r.now().line]?n(L):re(L)}function d(L){return e.enter("tableHead"),e.enter("tableRow"),f(L)}function f(L){return L===124||(o=!0,i+=1),m(L)}function m(L){return L===null?n(L):et(L)?i>1?(i=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(L),e.exit("lineEnding"),x):n(L):gt(L)?Tt(e,m,"whitespace")(L):(i+=1,o&&(o=!1,a+=1),L===124?(e.enter("tableCellDivider"),e.consume(L),e.exit("tableCellDivider"),o=!0,m):(e.enter("data"),p(L)))}function p(L){return L===null||L===124||Jt(L)?(e.exit("data"),m(L)):(e.consume(L),L===92?b:p)}function b(L){return L===92||L===124?(e.consume(L),p):p(L)}function x(L){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(L):(e.enter("tableDelimiterRow"),o=!1,gt(L)?Tt(e,E,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(L):E(L))}function E(L){return L===45||L===58?_(L):L===124?(o=!0,e.enter("tableCellDivider"),e.consume(L),e.exit("tableCellDivider"),N):O(L)}function N(L){return gt(L)?Tt(e,_,"whitespace")(L):_(L)}function _(L){return L===58?(i+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(L),e.exit("tableDelimiterMarker"),S):L===45?(i+=1,S(L)):L===null||et(L)?I(L):O(L)}function S(L){return L===45?(e.enter("tableDelimiterFiller"),C(L)):O(L)}function C(L){return L===45?(e.consume(L),C):L===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(L),e.exit("tableDelimiterMarker"),A):(e.exit("tableDelimiterFiller"),A(L))}function A(L){return gt(L)?Tt(e,I,"whitespace")(L):I(L)}function I(L){return L===124?E(L):L===null||et(L)?!o||a!==i?O(L):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(L)):O(L)}function O(L){return n(L)}function k(L){return e.enter("tableRow"),j(L)}function j(L){return L===124?(e.enter("tableCellDivider"),e.consume(L),e.exit("tableCellDivider"),j):L===null||et(L)?(e.exit("tableRow"),t(L)):gt(L)?Tt(e,j,"whitespace")(L):(e.enter("data"),F(L))}function F(L){return L===null||L===124||Jt(L)?(e.exit("data"),j(L)):(e.consume(L),L===92?P:F)}function P(L){return L===92||L===124?(e.consume(L),F):F(L)}}function dEe(e,t){let n=-1,r=!0,a=0,i=[0,0,0,0],o=[0,0,0,0],u=!1,d=0,f,m,p;const b=new sEe;for(;++n<e.length;){const x=e[n],E=x[1];x[0]==="enter"?E.type==="tableHead"?(u=!1,d!==0&&(yI(b,t,d,f,m),m=void 0,d=0),f={type:"table",start:Object.assign({},E.start),end:Object.assign({},E.end)},b.add(n,0,[["enter",f,t]])):E.type==="tableRow"||E.type==="tableDelimiterRow"?(r=!0,p=void 0,i=[0,0,0,0],o=[0,n+1,0,0],u&&(u=!1,m={type:"tableBody",start:Object.assign({},E.start),end:Object.assign({},E.end)},b.add(n,0,[["enter",m,t]])),a=E.type==="tableDelimiterRow"?2:m?3:1):a&&(E.type==="data"||E.type==="tableDelimiterMarker"||E.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(i[1]!==0&&(o[0]=o[1],p=Np(b,t,i,a,void 0,p),i=[0,0,0,0]),o[2]=n)):E.type==="tableCellDivider"&&(r?r=!1:(i[1]!==0&&(o[0]=o[1],p=Np(b,t,i,a,void 0,p)),i=o,o=[i[1],n,0,0])):E.type==="tableHead"?(u=!0,d=n):E.type==="tableRow"||E.type==="tableDelimiterRow"?(d=n,i[1]!==0?(o[0]=o[1],p=Np(b,t,i,a,n,p)):o[1]!==0&&(p=Np(b,t,o,a,n,p)),a=0):a&&(E.type==="data"||E.type==="tableDelimiterMarker"||E.type==="tableDelimiterFiller")&&(o[3]=n)}for(d!==0&&yI(b,t,d,f,m),b.consume(t.events),n=-1;++n<t.events.length;){const x=t.events[n];x[0]==="enter"&&x[1].type==="table"&&(x[1]._align=lEe(t.events,n))}return e}function Np(e,t,n,r,a,i){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",u="tableContent";n[0]!==0&&(i.end=Object.assign({},Wu(t.events,n[0])),e.add(n[0],0,[["exit",i,t]]));const d=Wu(t.events,n[1]);if(i={type:o,start:Object.assign({},d),end:Object.assign({},d)},e.add(n[1],0,[["enter",i,t]]),n[2]!==0){const f=Wu(t.events,n[2]),m=Wu(t.events,n[3]),p={type:u,start:Object.assign({},f),end:Object.assign({},m)};if(e.add(n[2],0,[["enter",p,t]]),r!==2){const b=t.events[n[2]],x=t.events[n[3]];if(b[1].end=Object.assign({},x[1].end),b[1].type="chunkText",b[1].contentType="text",n[3]>n[2]+1){const E=n[2]+1,N=n[3]-n[2]-1;e.add(E,N,[])}}e.add(n[3]+1,0,[["exit",p,t]])}return a!==void 0&&(i.end=Object.assign({},Wu(t.events,a)),e.add(a,0,[["exit",i,t]]),i=void 0),i}function yI(e,t,n,r,a){const i=[],o=Wu(t.events,n);a&&(a.end=Object.assign({},o),i.push(["exit",a,t])),r.end=Object.assign({},o),i.push(["exit",r,t]),e.add(n+1,0,i)}function Wu(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const fEe={name:"tasklistCheck",tokenize:mEe};function hEe(){return{text:{91:fEe}}}function mEe(e,t,n){const r=this;return a;function a(d){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(d):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(d),e.exit("taskListCheckMarker"),i)}function i(d){return Jt(d)?(e.enter("taskListCheckValueUnchecked"),e.consume(d),e.exit("taskListCheckValueUnchecked"),o):d===88||d===120?(e.enter("taskListCheckValueChecked"),e.consume(d),e.exit("taskListCheckValueChecked"),o):n(d)}function o(d){return d===93?(e.enter("taskListCheckMarker"),e.consume(d),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),u):n(d)}function u(d){return et(d)?t(d):gt(d)?e.check({tokenize:pEe},t,n)(d):n(d)}}function pEe(e,t,n){return Tt(e,r,"whitespace");function r(a){return a===null?n(a):t(a)}}function gEe(e){return EP([z1e(),Q1e(),iEe(e),uEe(),hEe()])}const bEe={};function Yl(e){const t=this,n=e||bEe,r=t.data(),a=r.micromarkExtensions||(r.micromarkExtensions=[]),i=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);a.push(gEe(n)),i.push(P1e()),o.push(B1e(n))}function iw(e){const t=e<1e12?e*1e3:e,n=Date.now()-t;return n<6e4?"刚刚":n<36e5?`${Math.floor(n/6e4)}分钟前`:n<864e5?`${Math.floor(n/36e5)}小时前`:n<2592e6?`${Math.floor(n/864e5)}天前`:new Date(t).toLocaleDateString("zh-CN",{month:"short",day:"numeric"})}function V8(e){const t=new Date(e);return t.toLocaleDateString("zh-CN",{month:"short",day:"numeric"})+" "+t.toLocaleTimeString("zh-CN",{hour:"2-digit",minute:"2-digit"})}function W8(e){return e==="merged"?"bg-purple-500/15 text-purple-400":e==="closed"?"bg-red-500/15 text-red-400":"bg-emerald-500/15 text-emerald-400"}function xEe(e){return e==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"}function yEe({repoId:e,issueNumber:t,onPublished:n}){const[r,a]=y.useState(""),[i,o]=y.useState(!1),u=y.useRef(null),d=y.useCallback(()=>tY(e,t,r.trim()),[e,t,r]),f=y.useCallback(()=>bA(e,t).then(O=>O.body),[e,t]),m=y.useCallback(()=>bA(e,t).then(O=>O.body||null),[e,t]),{phase:p,result:b,busy:x,setBusy:E,polish:N,discard:_,escalate:S,setResult:C}=iP({repoId:e,startPolish:d,fetchResult:f,loadExisting:m});y.useEffect(()=>{if(!i)return;const O=k=>{u.current&&!u.current.contains(k.target)&&o(!1)};return document.addEventListener("mousedown",O),()=>document.removeEventListener("mousedown",O)},[i]);const A=async()=>{if(!(!r.trim()||x)){E(!0);try{const O=await gA(e,t,r.trim());n(O),a(""),ar.getState().addToast("评论已发布","success")}catch(O){ar.getState().addToast(O instanceof Error?O.message:"发布失败","error")}finally{E(!1)}}},I=async()=>{if(!(!(b!=null&&b.trim())||x)){E(!0);try{const O=await gA(e,t,b.trim());n(O),a(""),_(),ar.getState().addToast("评论已发布","success")}catch(O){ar.getState().addToast(O instanceof Error?O.message:"发布失败","error")}finally{E(!1)}}};return p==="preview"?c.jsxs("div",{className:"mt-8 border-t border-line pt-6",children:[c.jsxs("h3",{className:"mb-3 flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-fg-4",children:[c.jsx(ec,{className:"h-3.5 w-3.5 text-amber-400"}),"AI 润色结果"]}),c.jsx("div",{className:"rounded-lg border border-amber-500/30 bg-amber-500/5 px-4 py-3",children:c.jsx("textarea",{value:b??"",onChange:O=>C(O.target.value),rows:6,className:"w-full resize-none bg-transparent text-sm text-fg placeholder:text-fg-6 focus:outline-none"})}),c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[c.jsxs("button",{type:"button",disabled:x,onClick:()=>void I(),className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(Rf,{className:"h-3.5 w-3.5"}),"发布评论"]}),c.jsx("button",{type:"button",onClick:_,className:"ml-auto rounded-md px-2.5 py-1.5 text-xs text-fg-5 transition-colors hover:text-fg-3",children:"放弃"}),c.jsxs("div",{className:"relative",ref:u,children:[c.jsx("button",{type:"button",onClick:()=>o(!i),className:"flex h-7 w-7 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(IE,{className:"h-3.5 w-3.5"})}),i&&c.jsxs("div",{className:"absolute right-0 bottom-full z-20 mb-1 min-w-[140px] overflow-hidden rounded-lg border border-line bg-elevated shadow-lg",children:[c.jsxs("button",{type:"button",onClick:()=>{o(!1),N()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",children:[c.jsx(ec,{className:"h-3 w-3"}),"重新润色"]}),c.jsx("button",{type:"button",onClick:()=>{o(!1),S()},className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",children:"转入深度对话"})]})]})]})]}):c.jsxs("div",{className:"mt-8 border-t border-line pt-6",children:[c.jsx("h3",{className:"mb-3 text-xs font-semibold uppercase tracking-wider text-fg-4",children:"添加评论"}),c.jsx("textarea",{value:r,onChange:O=>a(O.target.value),placeholder:"写下你的评论...",rows:4,disabled:p==="polishing",className:"w-full resize-none rounded-lg border border-line bg-base px-3 py-2.5 text-sm text-fg placeholder:text-fg-6 focus:border-fg-5 focus:outline-none disabled:opacity-50"}),c.jsxs("div",{className:"mt-2.5 flex items-center gap-2",children:[c.jsxs("button",{type:"button",disabled:!r.trim()||x||p==="polishing",onClick:()=>void A(),className:"flex items-center gap-1.5 rounded-md bg-blue-600 px-3 py-1.5 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(Rf,{className:"h-3.5 w-3.5"}),x?"发送中...":"直接发送"]}),c.jsxs("button",{type:"button",disabled:!r.trim()||p==="polishing",onClick:()=>void N(),className:"flex items-center gap-1.5 rounded-md border border-amber-500/30 bg-amber-500/10 px-3 py-1.5 text-xs font-medium text-amber-400 transition-colors hover:bg-amber-500/20 disabled:opacity-40",children:[c.jsx(ec,{className:"h-3.5 w-3.5"}),p==="polishing"?"润色中...":"AI 润色"]})]})]})}function X8({issue:e,milestone:t,onBack:n,onClose:r,onToggleSidebar:a}){var _;const i=zn(),o=We(S=>S.activeRepoId),u=We(qr),[d,f]=y.useState([]),[m,p]=y.useState(!1),[b,x]=y.useState(!1),E=Je(S=>S.updateIssueState);y.useEffect(()=>{o&&(p(!0),eY(o,e.number).then(f).catch(()=>f([])).finally(()=>p(!1)))},[o,e.number]);const N=()=>{Je.getState().setSelectedIssue(e.id),Me.setState({activeSessionId:null}),i(`/${encodeURIComponent(u)}/run`)};return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c.jsxs("header",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 md:flex-row md:items-center md:gap-3 md:px-6",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[c.jsx("button",{type:"button",onClick:n,"aria-label":"返回列表",className:"-ml-1 shrink-0 rounded-md p-1.5 text-fg-3 transition-colors hover:bg-elevated hover:text-fg md:hidden",children:c.jsx(ih,{className:"h-5 w-5"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",e.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",e.number," ",e.state]}),(_=e.labels)==null?void 0:_.map(S=>c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${S.color}20`,color:`#${S.color}`},children:S.name},S.id)),t&&c.jsxs("span",{className:"flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium bg-indigo-500/15 text-indigo-400",children:[c.jsx(RE,{className:"h-2.5 w-2.5"}),t.title]})]}),c.jsx("h2",{className:"mt-1 text-base font-semibold text-fg",children:e.title}),(e.authorLogin||e.assignees&&e.assignees.length>0)&&c.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2 text-xs text-fg-4",children:[e.authorLogin&&c.jsxs("span",{className:"flex items-center gap-1.5",children:[e.authorAvatar&&c.jsx("img",{src:e.authorAvatar,alt:"",className:"h-4 w-4 rounded-full"}),e.authorLogin]}),e.assignees&&e.assignees.length>0&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx("span",{className:"text-fg-5",children:"→"}),c.jsx("span",{className:"flex items-center -space-x-1",children:e.assignees.map(S=>c.jsx("img",{src:S.avatar_url,alt:S.login,title:S.login,className:"h-4 w-4 rounded-full ring-1 ring-surface"},S.login))}),c.jsx("span",{className:"text-fg-4",children:e.assignees.map(S=>S.login).join(", ")})]})]})]})]}),c.jsxs("div",{"data-guide":"issue-actions",className:"flex shrink-0 flex-wrap items-center gap-2",children:[e.htmlUrl&&c.jsxs("a",{href:e.htmlUrl,target:"_blank",rel:"noopener noreferrer",className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 font-mono text-xs text-fg-3 transition-colors hover:border-fg-5 hover:text-fg",children:[c.jsx(YR,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"源站"})]}),c.jsxs("button",{type:"button",onClick:()=>{Je.getState().enterMatchMode(e.id),Me.setState({activeSessionId:null}),i(`/${encodeURIComponent(u)}/run`)},className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 text-xs text-fg-3 transition-colors hover:border-blue-500/50 hover:text-blue-400",children:[c.jsx(Gl,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"匹配子任务"})]}),c.jsx("button",{type:"button",disabled:b,onClick:async()=>{x(!0),await E(o,e.number,e.state==="open"?"closed":"open"),x(!1)},className:ie("flex h-8 items-center gap-1.5 rounded-md border px-2.5 text-xs font-medium transition-colors disabled:opacity-40",e.state==="open"?"border-red-500/30 text-red-400 hover:border-red-500/60 hover:bg-red-500/10":"border-emerald-500/30 text-emerald-400 hover:border-emerald-500/60 hover:bg-emerald-500/10"),children:e.state==="open"?c.jsxs(c.Fragment,{children:[c.jsx(HR,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"关闭"})]}):c.jsxs(c.Fragment,{children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"重新打开"})]})}),c.jsxs("button",{type:"button",onClick:N,className:"flex h-8 items-center gap-1.5 rounded-md bg-blue-600 px-3 text-xs font-medium text-white transition-colors hover:bg-blue-500",children:[c.jsx(LE,{className:"h-3.5 w-3.5 fill-current"}),c.jsx("span",{className:"hidden sm:inline",children:"新建任务"})]}),a&&c.jsx("button",{type:"button",onClick:a,title:"面板",className:"flex h-8 w-8 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2",children:c.jsx(VR,{className:"h-4 w-4"})}),r&&c.jsx("button",{type:"button",onClick:r,title:"关闭详情",className:"hidden h-8 w-8 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2 md:flex",children:c.jsx(At,{className:"h-4 w-4"})})]})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6",children:[e.body?c.jsx("div",{className:"markdown-body leading-relaxed",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[Kg],children:e.body})}):c.jsx("p",{className:"py-10 text-center font-mono text-xs text-fg-5",children:"该 Issue 没有描述内容"}),m?c.jsx("p",{className:"mt-8 text-center font-mono text-xs text-fg-6",children:"加载评论…"}):d.length>0&&c.jsxs("div",{className:"mt-8 border-t border-line pt-6",children:[c.jsxs("h3",{className:"mb-4 text-xs font-semibold uppercase tracking-wider text-fg-4",children:["评论 (",d.length,")"]}),c.jsx("div",{className:"space-y-4",children:d.map(S=>c.jsxs("div",{className:"rounded-lg border border-line bg-elevated/40 px-4 py-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("img",{src:S.user.avatar_url,alt:S.user.login,className:"h-5 w-5 rounded-full"}),c.jsx("span",{className:"text-xs font-semibold text-fg-2",children:S.user.login}),c.jsx("span",{className:"text-[10px] text-fg-6",children:V8(S.created_at)})]}),c.jsx("div",{className:"markdown-body mt-2 text-sm leading-relaxed text-fg-3",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[Kg],children:S.body})})]},S.id))})]}),o&&c.jsx(yEe,{repoId:o,issueNumber:e.number,onPublished:S=>f(C=>[...C,S])},e.id)]})})]})}function vEe({prs:e,onSelect:t}){return e.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-fg-5",children:[c.jsx(Il,{className:"h-8 w-8"}),c.jsx("p",{className:"font-mono text-xs",children:"该 Issue 没有关联的 PR"})]}):c.jsx("ul",{className:"space-y-2",children:e.map(n=>{var r;return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:()=>t(n.number),className:"group flex w-full flex-col gap-1.5 rounded-lg border border-line bg-elevated/30 px-4 py-3 text-left transition-colors hover:border-blue-500/40 hover:bg-elevated/60",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",W8(n.state)),children:["#",n.number," ",n.state]}),n.mergeable===!1&&c.jsxs("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold bg-red-500/15 text-red-400",children:[c.jsx(On,{className:"inline h-3 w-3 -mt-px"})," Conflict"]}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg-2 group-hover:text-fg",children:n.title})]}),c.jsx("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-fg-5",children:((r=n.user)==null?void 0:r.login)&&c.jsxs("span",{className:"flex items-center gap-1",children:[n.user.avatar_url&&c.jsx("img",{src:n.user.avatar_url,alt:"",className:"h-3.5 w-3.5 rounded-full"}),n.user.login]})})]})},n.number)})})}function Q8({pr:e,onBack:t,onClose:n,onEnterMatch:r,onNavigateToIssue:a}){var k;const i=We(j=>j.activeRepoId),o=We(qr),[u,d]=y.useState(!1),[f,m]=y.useState([]),[p,b]=y.useState(!1),[x,E]=y.useState([]),[N,_]=y.useState(!1),S=zn(),C=mn(j=>j.unlinkIssue);y.useEffect(()=>{i&&(b(!0),J$(i,e.number).then(m).catch(()=>m([])).finally(()=>b(!1)))},[i,e.number]),y.useEffect(()=>{i&&UE(i,e.number).then(E).catch(()=>E([]))},[i,e.number]);const A=async j=>{if(!(u||!i)){d(!0);try{if(await X$(i,e.number),j&&x.length>0){const F=x.filter(P=>P.state==="open");await Promise.all(F.map(P=>sM(i,P.number,{state:"closed"}))),E(P=>P.map(L=>L.state==="open"?{...L,state:"closed"}:L)),Je.getState().loadIssues(i),ar.getState().addToast(`PR #${e.number} 合入成功,已关闭 ${F.length} 个 Issue`,"success")}else ar.getState().addToast(`PR #${e.number} 合入成功`,"success");mn.getState().loadPulls(i)}catch(F){let P="合入失败";if(F instanceof Li)try{P=JSON.parse(F.message).error??P}catch{P=F.message}ar.getState().addToast(P,"error")}finally{d(!1)}}},I=async j=>{if(!i)return;await C(i,e.number,j)&&E(P=>P.filter(L=>L.number!==j))},O=()=>{const j=`请解决 PR #${e.number} 的合并冲突: ${e.title}`;Me.setState({activeSessionId:null}),S(`/${encodeURIComponent(o)}/run?draft=${encodeURIComponent(j)}`)};return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[c.jsxs("header",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 md:flex-row md:items-center md:gap-3 md:px-6",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:[c.jsx("button",{type:"button",onClick:t,"aria-label":"返回列表",className:"-ml-1 shrink-0 rounded-md p-1.5 text-fg-3 transition-colors hover:bg-elevated hover:text-fg md:hidden",children:c.jsx(ih,{className:"h-5 w-5"})}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-1.5",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",W8(e.state)),children:["#",e.number," ",e.state]}),e.draft===1&&c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-bold bg-fg-6/15 text-fg-4",children:"DRAFT"}),e.mergeable==="false"&&e.state==="open"&&c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold bg-red-500/15 text-red-400",children:"Conflict"}),(k=e.labels)==null?void 0:k.map(j=>c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${j.color}20`,color:`#${j.color}`},children:j.name},j.id))]}),c.jsx("h2",{className:"mt-1 text-base font-semibold text-fg",children:e.title}),c.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2 text-xs text-fg-4",children:[c.jsxs("span",{className:"flex min-w-0 items-center gap-1 font-mono text-[11px] text-fg-5",children:[c.jsx(Il,{className:"h-3.5 w-3.5 shrink-0"}),c.jsxs("span",{className:"truncate",children:[e.headBranch," → ",e.baseBranch]})]}),e.authorLogin&&c.jsxs("span",{className:"flex items-center gap-1.5",children:[e.authorAvatar&&c.jsx("img",{src:e.authorAvatar,alt:"",className:"h-4 w-4 rounded-full"}),e.authorLogin]}),e.mergedAt&&c.jsxs("span",{className:"text-purple-400",children:["合并于 ",iw(e.mergedAt)]})]})]})]}),c.jsxs("div",{"data-guide":"pr-actions",className:"flex shrink-0 flex-wrap items-center gap-2",children:[e.htmlUrl&&c.jsxs("a",{href:e.htmlUrl,target:"_blank",rel:"noopener noreferrer",className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 font-mono text-xs text-fg-3 transition-colors hover:border-fg-5 hover:text-fg",children:[c.jsx(YR,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"源站"})]}),c.jsxs("button",{type:"button",onClick:r,className:"flex h-8 items-center gap-1.5 rounded-md border border-line px-2.5 text-xs text-fg-3 transition-colors hover:border-blue-500/50 hover:text-blue-400",children:[c.jsx(ME,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"关联 Issue"})]}),e.state==="open"&&c.jsxs(c.Fragment,{children:[e.mergeable==="false"&&c.jsxs("button",{type:"button",onClick:O,className:"flex h-8 items-center gap-1.5 rounded-md border border-amber-500/30 px-2.5 text-xs font-medium text-amber-400 transition-colors hover:border-amber-500/60 hover:bg-amber-500/10",children:[c.jsx(ZH,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"解冲突"})]}),c.jsxs("button",{type:"button",disabled:u||e.mergeable==="false",onClick:()=>void A(!1),className:"flex h-8 items-center gap-1.5 rounded-md border border-emerald-500/30 px-2.5 text-xs font-medium text-emerald-400 transition-colors hover:border-emerald-500/60 hover:bg-emerald-500/10 disabled:opacity-40",children:[c.jsx(sA,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"合入"})]}),x.some(j=>j.state==="open")&&c.jsxs("button",{type:"button",disabled:u||e.mergeable==="false",onClick:()=>void A(!0),className:"flex h-8 items-center gap-1.5 rounded-md bg-blue-600 px-3 text-xs font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sA,{className:"h-3.5 w-3.5"}),c.jsx("span",{className:"hidden sm:inline",children:"合入并关闭 Issues"})]})]}),n&&c.jsx("button",{type:"button",onClick:n,title:"关闭详情",className:"hidden h-8 w-8 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2 md:flex",children:c.jsx(At,{className:"h-4 w-4"})})]})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsxs("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6",children:[x.length>0&&c.jsxs("div",{className:"mb-6 rounded-lg border border-line bg-elevated/30 px-4 py-3",children:[c.jsxs("h3",{className:"mb-2 flex items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-fg-4",children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),"关联 Issues (",x.length,")"]}),c.jsx("div",{className:"space-y-1.5",children:x.map(j=>c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>a==null?void 0:a(j.id),className:"flex min-w-0 flex-1 items-center gap-2 rounded-md px-1 py-0.5 transition-colors hover:bg-elevated/60",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-medium",j.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",j.number]}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-left text-sm text-fg-2",children:j.title})]}),c.jsx("button",{type:"button",onClick:()=>void I(j.number),title:"取消关联",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:bg-red-500/10 hover:text-red-400",children:c.jsx(HR,{className:"h-3.5 w-3.5"})})]},j.id))})]}),(e.commitCount!=null||e.additions!=null)&&c.jsxs("div",{className:"mb-6 rounded-lg border border-line bg-elevated/30 px-4 py-3",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-fg-3",children:[e.commitCount!=null&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx($z,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{className:"font-medium",children:e.commitCount})," 次提交"]}),e.changedFilesCount!=null&&c.jsxs("span",{className:"flex items-center gap-1",children:[c.jsx(Io,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{className:"font-medium",children:e.changedFilesCount})," 个文件"]}),e.additions!=null&&c.jsxs("span",{className:"flex items-center gap-1 text-emerald-400",children:[c.jsx(ua,{className:"h-3 w-3"}),c.jsx("span",{className:"font-mono font-medium",children:e.additions})]}),e.deletions!=null&&c.jsxs("span",{className:"flex items-center gap-1 text-red-400",children:[c.jsx(yH,{className:"h-3 w-3"}),c.jsx("span",{className:"font-mono font-medium",children:e.deletions})]})]}),e.diffStats&&e.diffStats.length>0&&c.jsxs("div",{className:"mt-3 border-t border-line pt-3",children:[c.jsxs("button",{type:"button",onClick:()=>_(j=>!j),className:"flex w-full items-center gap-1.5 text-xs font-semibold uppercase tracking-wider text-fg-4 transition-colors hover:text-fg-2",children:[N?c.jsx(kr,{className:"h-3.5 w-3.5"}):c.jsx(Oo,{className:"h-3.5 w-3.5"}),"变更文件 (",e.diffStats.length,")"]}),N&&c.jsx("div",{className:"mt-2 space-y-0.5",children:e.diffStats.map(j=>c.jsxs("div",{className:"flex items-center gap-2 rounded px-2 py-1 text-xs hover:bg-elevated/50",children:[c.jsx("span",{className:ie("w-14 shrink-0 rounded px-1 py-0.5 text-center font-mono text-[10px] font-medium",j.status==="added"?"bg-emerald-500/15 text-emerald-400":j.status==="removed"?"bg-red-500/15 text-red-400":"bg-blue-500/15 text-blue-400"),children:j.status==="added"?"新增":j.status==="removed"?"删除":j.status==="renamed"?"重命名":"修改"}),c.jsx("span",{className:"min-w-0 flex-1 truncate font-mono text-fg-3",title:j.filename,children:j.filename}),c.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-emerald-400",children:["+",j.additions]}),c.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-red-400",children:["-",j.deletions]})]},j.filename))})]})]}),e.body?c.jsx("div",{className:"markdown-body leading-relaxed",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[Kg],children:e.body})}):c.jsx("p",{className:"py-10 text-center font-mono text-xs text-fg-5",children:"该 PR 没有描述内容"}),p?c.jsx("p",{className:"mt-8 text-center font-mono text-xs text-fg-6",children:"加载评论…"}):f.length>0&&c.jsxs("div",{className:"mt-8 border-t border-line pt-6",children:[c.jsxs("h3",{className:"mb-4 text-xs font-semibold uppercase tracking-wider text-fg-4",children:["评论 (",f.length,")"]}),c.jsx("div",{className:"space-y-4",children:f.map(j=>c.jsxs("div",{className:"rounded-lg border border-line bg-elevated/40 px-4 py-3",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("img",{src:j.user.avatar_url,alt:j.user.login,className:"h-5 w-5 rounded-full"}),c.jsx("span",{className:"text-xs font-semibold text-fg-2",children:j.user.login}),c.jsx("span",{className:"text-[10px] text-fg-6",children:V8(j.created_at)})]}),c.jsx("div",{className:"markdown-body mt-2 text-sm leading-relaxed text-fg-3",children:c.jsx($l,{remarkPlugins:[Yl],rehypePlugins:[Kg],children:j.body})})]},j.id))})]})]})})]})}function EEe({issue:e,milestone:t,tab:n,prNumber:r,onTabChange:a,onSelectPr:i,onBackToPrList:o,onBack:u,onClose:d,onToggleSidebar:f}){const m=We(A=>A.activeRepoId),p=mn(A=>A.enterMatchMode),[b,x]=y.useState([]),[E,N]=y.useState(null),[_,S]=y.useState(!1);y.useEffect(()=>{if(!m){x([]);return}K$(m,e.number).then(x).catch(()=>x([]))},[m,e.number]),y.useEffect(()=>{if(!m||r==null){N(null);return}let A=!1;return S(!0),W$(m,r).then(I=>{A||N(I)}).catch(()=>{A||N(null)}).finally(()=>{A||S(!1)}),()=>{A=!0}},[m,r]);const C=b.some(A=>A.mergeable===!1);return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[b.length>0&&c.jsxs("div",{className:"flex shrink-0 items-center border-b border-line bg-surface",children:[c.jsxs("button",{type:"button",onClick:()=>a("issue"),className:ie("flex items-center gap-1.5 border-b-2 px-4 py-2.5 text-xs font-medium transition-colors",n==="issue"?"border-blue-500 text-fg":"border-transparent text-fg-4 hover:text-fg-2"),children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),"Issue"]}),c.jsxs("button",{type:"button",onClick:()=>a("pr"),className:ie("flex items-center gap-1.5 border-b-2 px-4 py-2.5 text-xs font-medium transition-colors",n==="pr"?"border-blue-500 text-fg":"border-transparent text-fg-4 hover:text-fg-2"),children:[c.jsx(Il,{className:"h-3.5 w-3.5"}),"PR",c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",n==="pr"?"bg-blue-500/10 text-blue-500":"bg-elevated text-fg-5"),children:b.length}),C&&c.jsxs("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-semibold bg-red-500/15 text-red-400",children:[c.jsx(On,{className:"inline h-3 w-3 -mt-px"})," Conflict"]})]})]}),n==="issue"||b.length===0?c.jsx(X8,{issue:e,milestone:t,onBack:u,onClose:d,onToggleSidebar:f}):r!=null?E?c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[c.jsx("div",{className:"flex shrink-0 items-center border-b border-line bg-elevated/30 px-4 py-2",children:c.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:[c.jsx(If,{className:"h-3.5 w-3.5"}),"返回列表"]})}),c.jsx(Q8,{pr:E,onBack:o,onEnterMatch:()=>p(E.id)})]}):c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:_?"加载 PR…":"PR 未找到"})}):c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsx("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6",children:c.jsx(vEe,{prs:b,onSelect:i})})})]})}const Z8=[{key:"open",label:"开放"},{key:"closed",label:"已关闭"},{key:"all",label:"全部"}];function NEe({stateFilter:e,setStateFilter:t,typeFilter:n,setTypeFilter:r,searchQuery:a,setSearchQuery:i,expandedFilter:o,setExpandedFilter:u,selectedAuthor:d,setSelectedAuthor:f,selectedAssignee:m,setSelectedAssignee:p,creating:b,setCreating:x,openCount:E,closedCount:N,totalCount:_,epicCount:S,taskCount:C,strayCount:A,afterStateCount:I,uniqueAuthors:O,uniqueAssignees:k}){const j=Je(H=>H.syncing),F=Je(H=>H.syncIssues),P=Je(H=>H.tags),L=Je(H=>H.tagFilterMode),B=Je(H=>H.cycleTagFilter),Y=Je(H=>H.clearTagFilter),re=Je(H=>H.milestones),X=Je(H=>H.selectedMilestoneId),K=Je(H=>H.setMilestoneFilter),V=We(H=>H.activeRepoId);return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-2 border-b border-line px-4 py-2.5",children:[c.jsx("span",{className:"shrink-0 text-sm font-semibold text-fg md:order-1",children:"Issues"}),V&&c.jsxs("div",{"data-guide":"issue-sync-create",className:"ml-auto flex shrink-0 items-center gap-1 md:order-last md:ml-0",children:[c.jsx("button",{type:"button",onClick:()=>V&&void F(V),disabled:j,title:"同步 Issues",className:"flex h-8 w-8 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:c.jsx(Rl,{className:ie("h-3.5 w-3.5",j&&"animate-spin")})}),c.jsx("button",{type:"button",onClick:()=>x(!b),title:"新建 Issue",className:ie("flex h-8 w-8 items-center justify-center rounded-md transition-colors",b?"bg-blue-600 text-white":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:c.jsx(ua,{className:"h-3.5 w-3.5"})})]}),c.jsx("div",{className:"w-full md:order-2 md:w-auto",children:c.jsx("div",{className:"flex shrink-0 items-center rounded-lg bg-elevated/60 p-0.5",children:Z8.map(({key:H,label:G})=>{const Q=H==="open"?E:H==="closed"?N:_;return c.jsxs("button",{type:"button",onClick:()=>t(H),className:ie("flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",e===H?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-2"),children:[G,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",e===H?"bg-blue-500/10 text-blue-500":"text-fg-5"),children:Q})]},H)})})}),c.jsx("div",{className:"w-full md:order-5 md:w-auto md:min-w-0 md:flex-1 md:px-1",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2.5 py-1.5",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:a,onChange:H=>i(H.target.value),placeholder:"搜索 issue...",className:"min-w-0 flex-1 bg-transparent text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),a&&c.jsx("button",{type:"button",onClick:()=>i(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})}),c.jsx("div",{className:"hidden md:order-3 md:mx-1 md:block md:h-4 md:w-px md:shrink-0 md:bg-line"}),c.jsxs("div",{className:"flex w-full gap-2 overflow-x-auto scrollbar-none md:order-4 md:w-auto md:overflow-visible",children:[c.jsxs("button",{type:"button",onClick:()=>u(o==="type"?null:"type"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="type"?"bg-elevated text-fg":n!=="all"?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["类型",n!=="all"&&c.jsx("span",{className:"rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:n==="epic"?"Epic":n==="task"?"任务":"游离"}),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="type"&&"rotate-180")})]}),c.jsxs("button",{type:"button","data-guide":"issue-tag-filter",onClick:()=>u(o==="tag"?null:"tag"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="tag"?"bg-elevated text-fg":L.size>0?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["标签",L.size>0&&c.jsx("span",{className:"rounded-full bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:L.size}),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="tag"&&"rotate-180")})]}),c.jsxs("button",{type:"button",onClick:()=>u(o==="milestone"?null:"milestone"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="milestone"?"bg-elevated text-fg":X?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["Milestone",X&&(()=>{const H=re.find(G=>G.id===X);return H?c.jsx("span",{className:"rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:H.title}):null})(),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="milestone"&&"rotate-180")})]}),c.jsxs("button",{type:"button",onClick:()=>u(o==="author"?null:"author"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="author"?"bg-elevated text-fg":d?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["Author",d&&c.jsx("span",{className:"rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:d}),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="author"&&"rotate-180")})]}),c.jsxs("button",{type:"button",onClick:()=>u(o==="assignee"?null:"assignee"),className:ie("flex shrink-0 items-center gap-1 rounded-md px-2 py-1 text-xs font-medium transition-colors",o==="assignee"?"bg-elevated text-fg":m?"text-fg-2":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),children:["Assignee",m&&c.jsx("span",{className:"rounded bg-blue-500/10 px-1.5 py-0.5 text-[10px] text-blue-400",children:m}),c.jsx(kr,{className:ie("h-3 w-3 transition-transform",o==="assignee"&&"rotate-180")})]})]})]}),o==="type"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:["epic","stray","task","all"].map(H=>{const G=H==="epic"?"Epic":H==="stray"?"游离":H==="task"?"任务":"全部",Q=H==="epic"?S:H==="stray"?A:H==="task"?C:I,D=n===H;return c.jsxs("button",{type:"button",onClick:()=>r(D&&H!=="all"?"all":H),className:ie("flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-semibold transition-colors",D?H==="epic"?"bg-amber-400/15 text-amber-400":H==="stray"?"bg-sky-400/15 text-sky-400":H==="task"?"bg-violet-400/15 text-violet-400":"bg-fg-6/20 text-fg-3":"bg-elevated/60 text-fg-5 hover:bg-elevated hover:text-fg-3"),children:[G,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px] font-medium",D?"opacity-70":"text-fg-6"),children:Q})]},H)})}),o==="tag"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:P.length===0?c.jsx("span",{className:"text-xs text-fg-5",children:"暂无标签"}):c.jsxs(c.Fragment,{children:[P.map(H=>{const G=L.get(H.id);return c.jsxs("button",{type:"button",onClick:()=>B(H.id),className:ie("shrink-0 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",G==="include"?"ring-1 ring-current shadow-sm":G==="exclude"?"opacity-90 line-through decoration-2":"opacity-50 hover:opacity-80"),style:G==="exclude"?{backgroundColor:`#${H.color}10`,color:`#${H.color}`,boxShadow:`inset 0 0 0 1px color-mix(in srgb, #${H.color} 30%, transparent)`}:{backgroundColor:`#${H.color}18`,color:`#${H.color}`,boxShadow:G==="include"?`inset 0 0 0 1px color-mix(in srgb, #${H.color} 50%, transparent)`:void 0},children:[G==="exclude"&&c.jsx("span",{className:"mr-1 text-[10px]",children:"✕"}),H.name]},H.id)}),L.size>0&&c.jsx("button",{type:"button",onClick:Y,className:"shrink-0 rounded-md px-2 py-1 text-[10px] text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3",children:"清除"})]})}),o==="milestone"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:re.length===0?c.jsx("span",{className:"text-xs text-fg-5",children:"暂无里程碑"}):c.jsxs(c.Fragment,{children:[re.map(H=>{const G=X===H.id;return c.jsxs("button",{type:"button",onClick:()=>K(G?null:H.id),className:ie("shrink-0 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",G?"bg-indigo-500/15 text-indigo-400 ring-1 ring-indigo-400/50 shadow-sm":"bg-elevated/60 text-fg-5 hover:bg-elevated hover:text-fg-3"),children:[H.title,H.state==="closed"&&c.jsx("span",{className:"ml-1 text-[10px] opacity-60",children:"✓"})]},H.id)}),X&&c.jsx("button",{type:"button",onClick:()=>K(null),className:"shrink-0 rounded-md px-2 py-1 text-[10px] text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3",children:"清除"})]})}),o==="author"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:O.length===0?c.jsx("span",{className:"text-xs text-fg-5",children:"同步后可见作者"}):c.jsxs(c.Fragment,{children:[O.map(H=>c.jsxs("button",{type:"button",onClick:()=>f(d===H.login?null:H.login),className:ie("flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",d===H.login?"bg-blue-500/15 text-blue-400 ring-1 ring-blue-500/30 shadow-sm":"bg-elevated/60 text-fg-5 hover:bg-elevated hover:text-fg-3"),children:[H.avatar&&c.jsx("img",{src:H.avatar,alt:"",className:"h-4 w-4 rounded-full"}),H.login]},H.login)),d&&c.jsx("button",{type:"button",onClick:()=>f(null),className:"shrink-0 rounded-md px-2 py-1 text-[10px] text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3",children:"清除"})]})}),o==="assignee"&&c.jsx("div",{className:"flex items-center gap-2 overflow-x-auto border-b border-line px-4 py-2",style:{scrollbarWidth:"none"},children:k.length===0?c.jsx("span",{className:"text-xs text-fg-5",children:"同步后可见指派人"}):c.jsxs(c.Fragment,{children:[k.map(H=>c.jsxs("button",{type:"button",onClick:()=>p(m===H.login?null:H.login),className:ie("flex shrink-0 items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",m===H.login?"bg-blue-500/15 text-blue-400 ring-1 ring-blue-500/30 shadow-sm":"bg-elevated/60 text-fg-5 hover:bg-elevated hover:text-fg-3"),children:[H.avatar&&c.jsx("img",{src:H.avatar,alt:"",className:"h-4 w-4 rounded-full"}),H.login]},H.login)),m&&c.jsx("button",{type:"button",onClick:()=>p(null),className:"shrink-0 rounded-md px-2 py-1 text-[10px] text-fg-5 transition-colors hover:bg-elevated hover:text-fg-3",children:"清除"})]})})]})}function SEe({issue:e,sessionCount:t,isActive:n,isEpic:r,milestone:a,onSelect:i}){return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:i,className:ie("group flex w-full items-center gap-2.5 rounded-md px-2.5 py-2 text-left transition-colors",n?"border-l-2 border-blue-500 bg-elevated/80":"border-l-2 border-transparent hover:bg-elevated/50"),children:[c.jsx("span",{className:ie("flex h-10 w-10 shrink-0 items-center justify-center rounded-full font-mono text-sm font-bold",e.state==="open"?"bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 text-emerald-400 ring-1 ring-emerald-500/25":"bg-gradient-to-br from-purple-500/20 to-purple-500/5 text-purple-400 ring-1 ring-purple-500/25"),children:e.number}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[r&&c.jsx("span",{className:"shrink-0 rounded px-1 py-0.5 text-[9px] font-bold tracking-wide bg-amber-400/12 text-amber-400",children:"EPIC"}),c.jsx("span",{className:"min-w-0 text-xs font-medium text-fg-2 group-hover:text-fg",children:e.title})]}),e.labels&&e.labels.length>0&&c.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.labels.map(o=>c.jsx("span",{className:"rounded px-1 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${o.color}20`,color:`#${o.color}`},children:o.name},o.id))}),a&&c.jsxs("span",{className:"mt-1 flex items-center gap-1 text-[10px] text-indigo-400/70",children:[c.jsx(RE,{className:"h-2.5 w-2.5"}),a.title]})]}),t>0&&c.jsx("span",{className:"shrink-0 rounded-full bg-elevated px-1.5 py-0.5 font-mono text-[10px] text-fg-5",children:t})]})})}const vI=y.memo(SEe,(e,t)=>{var n,r;return e.issue.id===t.issue.id&&e.issue.state===t.issue.state&&e.issue.title===t.issue.title&&e.sessionCount===t.sessionCount&&e.isActive===t.isActive&&e.isEpic===t.isEpic&&((n=e.milestone)==null?void 0:n.id)===((r=t.milestone)==null?void 0:r.id)});function wEe({issue:e,sessionCount:t,isEpic:n,milestone:r,onSelect:a}){return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:a,className:"group flex w-full items-center gap-3 border-b border-line px-4 py-3 text-left transition-colors hover:bg-elevated/50",children:[c.jsx("span",{className:ie("flex h-10 w-10 shrink-0 items-center justify-center rounded-full font-mono text-sm font-bold",e.state==="open"?"bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 text-emerald-400 ring-1 ring-emerald-500/25":"bg-gradient-to-br from-purple-500/20 to-purple-500/5 text-purple-400 ring-1 ring-purple-500/25"),children:e.number}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[n&&c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[9px] font-bold tracking-wide bg-amber-400/12 text-amber-400",children:"EPIC"}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg-2 group-hover:text-fg",children:e.title}),r&&c.jsxs("span",{className:"hidden shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[10px] font-medium bg-indigo-500/15 text-indigo-400 sm:flex",children:[c.jsx(RE,{className:"h-2.5 w-2.5"}),r.title]}),t>0&&c.jsxs("span",{className:"shrink-0 rounded-full bg-elevated px-2 py-0.5 font-mono text-[10px] text-fg-5",children:[t," 次运行"]}),e.assignees&&e.assignees.length>0&&c.jsxs("div",{className:"hidden shrink-0 items-center -space-x-1.5 sm:flex",children:[e.assignees.slice(0,3).map(i=>c.jsx("img",{src:i.avatar_url,alt:i.login,title:i.login,className:"h-5 w-5 rounded-full ring-2 ring-surface"},i.login)),e.assignees.length>3&&c.jsxs("span",{className:"flex h-5 w-5 items-center justify-center rounded-full bg-elevated text-[9px] font-medium text-fg-4 ring-2 ring-surface",children:["+",e.assignees.length-3]})]})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[e.authorLogin&&c.jsxs("span",{className:"shrink-0 text-[11px] text-fg-5",title:e.authorLogin,children:[e.authorAvatar&&c.jsx("img",{src:e.authorAvatar,alt:"",className:"mr-1 inline-block h-3.5 w-3.5 rounded-full align-text-bottom"}),e.authorLogin]}),e.authorLogin&&c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx("span",{className:"shrink-0 text-[11px] text-fg-6",children:iw(e.createdAt)}),(e.commentCount??0)>0&&c.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 text-[11px] text-fg-6",children:[c.jsx("span",{className:"text-fg-6",children:"·"}),c.jsx(dH,{className:"h-3 w-3"}),e.commentCount]}),(e.labels&&e.labels.length>0||(e.commentCount??0)>0||e.authorLogin)&&e.labels&&e.labels.length>0&&c.jsx("span",{className:"text-fg-6",children:"·"}),e.labels&&e.labels.length>0?e.labels.map(i=>c.jsx("span",{className:"rounded px-1.5 py-0.5 text-[11px] font-medium",style:{backgroundColor:`#${i.color}20`,color:`#${i.color}`},children:i.name},i.id)):e.authorLogin?null:c.jsx("span",{className:"text-[11px] text-fg-6",children:" "})]})]})]})})}const _Ee=y.memo(wEe,(e,t)=>{var n,r;return e.issue.id===t.issue.id&&e.issue.state===t.issue.state&&e.issue.title===t.issue.title&&e.sessionCount===t.sessionCount&&e.isEpic===t.isEpic&&((n=e.milestone)==null?void 0:n.id)===((r=t.milestone)==null?void 0:r.id)});function TEe(e){var i;const t=typeof((i=e.time)==null?void 0:i.created)=="number"?e.time.created:e.createdAt?Date.parse(e.createdAt):0;if(!t||Number.isNaN(t))return"";const n=t<1e12?t*1e3:t,r=new Date(n);return r.toDateString()===new Date().toDateString()?r.toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"}):r.toLocaleDateString(void 0,{month:"short",day:"numeric"})}function EI({session:e,onSelect:t}){var r,a;const n=TEe(e);return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:t,className:"block w-full rounded-md border-l-2 border-transparent px-2.5 py-2 text-left transition-colors hover:bg-elevated/50",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"min-w-0 truncate font-mono text-xs text-fg-3",children:((r=e.agent)==null?void 0:r.trim())||"默认"}),n&&c.jsx("span",{className:"ml-auto shrink-0 font-mono text-[10px] tabular-nums text-fg-5",children:n})]}),c.jsx("div",{className:"mt-0.5 truncate text-sm text-fg-2",children:((a=e.title)==null?void 0:a.trim())||"未命名运行"})]})})}function J8({sessions:e,onSelect:t}){const n=Je(o=>o.issues),r=new Map(n.map(o=>[o.id,o])),a=new Map,i=[];for(const o of e)if(o.issueId&&r.has(o.issueId)){const u=a.get(o.issueId)??[];u.push(o),a.set(o.issueId,u)}else i.push(o);return c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col border-t border-line",children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-line px-3 py-3",children:[c.jsx(kE,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-fg-4",children:"运行记录"}),c.jsx("span",{className:"ml-auto rounded-full bg-elevated px-1.5 py-0.5 font-mono text-[10px] text-fg-5",children:e.length})]}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:e.length===0?c.jsx("p",{className:"px-2 py-4 text-center font-mono text-[10px] text-fg-6",children:"暂无运行记录"}):c.jsxs("div",{className:"space-y-3",children:[[...a.entries()].map(([o,u])=>{const d=r.get(o);return c.jsxs("div",{children:[c.jsxs("div",{className:"mb-1 flex items-center gap-1.5 px-1",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-medium",d.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",d.number]}),c.jsx("span",{className:"min-w-0 truncate text-xs font-medium text-fg-3",children:d.title})]}),c.jsx("ul",{className:"space-y-0.5",children:u.map(f=>c.jsx(EI,{session:f,onSelect:()=>t(f.id)},f.id))})]},o)}),i.length>0&&c.jsxs("div",{children:[a.size>0&&c.jsx("div",{className:"mb-1 px-1",children:c.jsx("span",{className:"text-xs font-medium text-fg-5",children:"未关联 Issue"})}),c.jsx("ul",{className:"space-y-0.5",children:i.map(o=>c.jsx(EI,{session:o,onSelect:()=>t(o.id)},o.id))})]})]})})]})}function AEe({sessions:e,onSessionSelect:t}){return c.jsx("div",{className:"flex w-full flex-col",children:c.jsx(J8,{sessions:e,onSelect:t})})}function eB({issue:e,childrenMap:t,currentId:n,onSelect:r,depth:a}){const i=t.get(e.id)??[],o=e.id===n;return c.jsxs("div",{children:[c.jsxs("button",{type:"button",onClick:()=>r(e.id),className:ie("group flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs transition-colors",o?"bg-blue-500/10 text-blue-400":"text-fg-4 hover:bg-elevated/60 hover:text-fg-2"),style:{paddingLeft:`${a*18+8}px`},children:[c.jsx("span",{className:ie("h-1.5 w-1.5 shrink-0 rounded-full",e.state==="open"?"bg-emerald-400":"bg-purple-400")}),c.jsxs("span",{className:"shrink-0 font-mono text-[10px] text-fg-6",children:["#",e.number]}),c.jsx("span",{className:"min-w-0 truncate",children:e.title})]}),i.length>0&&c.jsxs("div",{className:"relative",children:[c.jsx("div",{className:"absolute top-0 bottom-3 w-px bg-line",style:{left:`${a*18+16}px`}}),i.map(u=>c.jsx(eB,{issue:u,childrenMap:t,currentId:n,onSelect:r,depth:a+1},u.id))]})]})}function CEe(e,t){let n=0,r=0;const a=[...t.get(e)??[]];for(let i=0;i<a.length;i++){const o=a[i];n++,o.state==="closed"&&r++;const u=t.get(o.id);u&&a.push(...u)}return{total:n,closed:r}}function kEe({rootIssue:e,childrenMap:t,currentId:n,onSelect:r,sessions:a,onSessionSelect:i}){const{total:o,closed:u}=CEe(e.id,t),d=o===0?0:Math.round(u/o*100);return c.jsxs("div",{className:"flex w-full flex-col",children:[c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[c.jsxs("div",{className:"flex items-center gap-1.5 border-b border-line px-3 py-3",children:[c.jsx(_H,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-fg-4",children:"子任务树"})]}),o>0&&c.jsxs("div",{className:"border-b border-line px-3 py-2",children:[c.jsx("div",{className:"h-1 overflow-hidden rounded-full bg-elevated",children:c.jsx("div",{className:"h-full rounded-full bg-gradient-to-r from-emerald-400 to-blue-500 transition-all",style:{width:`${d}%`}})}),c.jsxs("p",{className:"mt-1 font-mono text-[10px] text-fg-6",children:[u," / ",o," completed"]})]}),c.jsx("div",{className:"flex-1 overflow-y-auto py-2",children:c.jsx(eB,{issue:e,childrenMap:t,currentId:n,onSelect:r,depth:0})})]}),c.jsx(J8,{sessions:a,onSelect:i})]})}function NI({total:e,page:t,pageSize:n=Qv,onPageChange:r}){const a=Math.max(1,n),i=Math.max(1,Math.ceil(e/a));if(i<=1)return null;const o=t*n+1,u=Math.min((t+1)*n,e);return c.jsxs("div",{className:"flex items-center justify-between border-t border-line px-3 py-2",children:[c.jsxs("span",{className:"font-mono text-[11px] text-fg-5",children:[o,"–",u," / ",e]}),c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("button",{type:"button",disabled:t<=0,onClick:()=>r(t-1),className:ie("flex h-7 w-7 items-center justify-center rounded-md transition-colors",t<=0?"text-fg-6 cursor-not-allowed":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:c.jsx(ih,{className:"h-4 w-4"})}),c.jsxs("span",{className:"min-w-[3rem] text-center font-mono text-xs text-fg-3",children:[t+1," / ",i]}),c.jsx("button",{type:"button",disabled:t>=i-1,onClick:()=>r(t+1),className:ie("flex h-7 w-7 items-center justify-center rounded-md transition-colors",t>=i-1?"text-fg-6 cursor-not-allowed":"text-fg-4 hover:bg-elevated hover:text-fg-2"),children:c.jsx(Oo,{className:"h-4 w-4"})})]})]})}function dE({side:e,open:t,onClose:n,children:r,width:a="w-80"}){const i=e==="left";return c.jsxs("div",{className:"md:hidden",children:[t&&c.jsx("div",{className:"fixed inset-0 z-40 bg-black/50",onClick:n,"aria-hidden":"true"}),c.jsx("div",{className:ie("fixed top-0 bottom-0 z-50 flex flex-col bg-surface pt-[var(--safe-top)] pb-[var(--safe-bottom)] shadow-xl transition-transform duration-200 ease-out",a,i?"left-0 border-r border-line":"right-0 border-l border-line",t?"translate-x-0":i?"-translate-x-full":"translate-x-full"),children:r})]})}function OEe({issues:e,tags:t,milestones:n,tagFilterMode:r,stateFilter:a,typeFilter:i,searchQuery:o,selectedMilestoneId:u,selectedAuthor:d,selectedAssignee:f}){const{childIssueIds:m,childrenMap:p}=y.useMemo(()=>{const A=new Set(e.filter(O=>O.parentId).map(O=>O.parentId)),I=new Map;for(const O of e)if(O.parentId){const k=I.get(O.parentId);k?k.push(O):I.set(O.parentId,[O])}return{childIssueIds:A,childrenMap:I}},[e]),b=y.useMemo(()=>A=>A.parentId?"task":m.has(A.id)?"epic":"stray",[m]),x=y.useMemo(()=>new Map(n.map(A=>[A.id,A])),[n]),{afterState:E,finalFiltered:N}=y.useMemo(()=>{const A=a==="all"?e:e.filter(B=>B.state===a),I=i==="all"?A:A.filter(B=>b(B)===i),O=r.size===0?I:I.filter(B=>{var re;const Y=new Set((B.labels??[]).map(X=>X.name));for(const[X,K]of r){const V=(re=t.find(H=>H.id===X))==null?void 0:re.name;if(V&&(K==="include"&&!Y.has(V)||K==="exclude"&&Y.has(V)))return!1}return!0}),k=o.trim().toLowerCase(),j=k?O.filter(B=>`#${B.number} ${B.title}`.toLowerCase().includes(k)):O,F=u?j.filter(B=>B.milestoneId===u):j,P=d?F.filter(B=>B.authorLogin===d):F,L=f?P.filter(B=>(B.assignees??[]).some(Y=>Y.login===f)):P;return{afterState:A,finalFiltered:L}},[e,a,i,r,t,o,u,d,f,b]),_=y.useMemo(()=>({open:e.filter(A=>A.state==="open").length,closed:e.filter(A=>A.state==="closed").length,epic:E.filter(A=>b(A)==="epic").length,task:E.filter(A=>b(A)==="task").length,stray:E.filter(A=>b(A)==="stray").length,afterState:E.length}),[e,E,b]),S=y.useMemo(()=>{const A=new Map;for(const I of e)I.authorLogin&&!A.has(I.authorLogin)&&A.set(I.authorLogin,{login:I.authorLogin,avatar:I.authorAvatar});return[...A.values()]},[e]),C=y.useMemo(()=>{const A=new Map;for(const I of e)for(const O of I.assignees??[])A.has(O.login)||A.set(O.login,{login:O.login,avatar:O.avatar_url});return[...A.values()]},[e]);return{childrenMap:p,issueType:b,milestoneMap:x,afterState:E,finalFiltered:N,counts:_,uniqueAuthors:S,uniqueAssignees:C}}const SI=8;function IEe(e,t){let n=e instanceof Element?e:null;for(;n&&n!==t;){if(n.scrollWidth>n.clientWidth){const r=getComputedStyle(n).overflowX;if(r==="auto"||r==="scroll")return!0}n=n.parentElement}return!1}function tB({onSwipeLeft:e,onSwipeRight:t,threshold:n=40,disabled:r=!1}={}){const a=y.useRef({x0:0,y0:0,dir:null,on:!1}),i=y.useRef(0),o=y.useCallback(f=>{if(r||IEe(f.target,f.currentTarget))return;const m=f.touches[0];a.current={x0:m.clientX,y0:m.clientY,dir:null,on:!0},i.current=0},[r]),u=y.useCallback(f=>{const m=a.current;if(!m.on)return;const p=f.touches[0].clientX-m.x0,b=f.touches[0].clientY-m.y0;if(!m.dir){(Math.abs(p)>SI||Math.abs(b)>SI)&&(m.dir=Math.abs(p)>Math.abs(b)?"h":"v");return}if(m.dir==="v"){m.on=!1;return}i.current=p},[]),d=y.useCallback(()=>{const f=a.current;if(!f.on||f.dir!=="h"){f.on=!1;return}f.on=!1;const m=i.current;m>n?t==null||t():m<-n&&(e==null||e())},[n,e,t]);return{onTouchStart:o,onTouchMove:u,onTouchEnd:d}}function REe(){const[e,t]=y.useState("open"),[n,r]=y.useState("stray"),[a,i]=y.useState(!1),[o,u]=y.useState(""),d=Je(ee=>ee.viewingTreeRootId),f=Je(ee=>ee.setViewingIssue),[m,p]=y.useState(!1),[b,x]=y.useState(!1),[E,N]=y.useState(null),[_,S]=y.useState(null),[C,A]=y.useState(null),[I,O]=y.useState(0),[k,j]=CE(),F=Je(ee=>ee.issues),P=Je(ee=>ee.loaded),L=Je(ee=>ee.syncing),B=Je(ee=>ee.syncIssues),Y=Je(ee=>ee.tags),re=Je(ee=>ee.tagFilterMode),X=Je(ee=>ee.loadTags),K=Je(ee=>ee.milestones),V=Je(ee=>ee.selectedMilestoneId),H=Je(ee=>ee.loadMilestones),G=We(ee=>ee.activeRepoId),Q=Je(ee=>ee.syncError),D=We(qr),z=Me(ee=>ee.sessions),$=zn(),M=k.get("id"),le=k.get("tab")==="pr"?"pr":"issue",oe=k.get("prId"),ne=oe?Number.parseInt(oe,10):null;y.useEffect(()=>{const ee=k.get("issueId");if(!ee)return;const ve=new URLSearchParams(k);ve.delete("issueId"),ve.set("id",ee),j(ve,{replace:!0})},[k,j]),y.useEffect(()=>{if(k.get("id"))return;const ee=Je.getState().viewingIssueId;ee&&j({id:ee},{replace:!0})},[k.get,j]);const ae=y.useCallback(ee=>{j({id:ee},{replace:!1})},[j]),De=y.useCallback(()=>{j({},{replace:!1}),f(null)},[j,f]),xe=y.useCallback(ee=>{if(!M)return;const ve={id:M};ee==="pr"&&(ve.tab="pr"),j(ve,{replace:!1})},[M,j]),we=y.useCallback(ee=>{M&&j({id:M,tab:"pr",prId:String(ee)},{replace:!1})},[M,j]),Le=y.useCallback(()=>{M&&j({id:M,tab:"pr"},{replace:!1})},[M,j]);y.useEffect(()=>{G&&(X(G),H(G))},[G,X,H]),y.useEffect(()=>{Q&&ar.getState().addToast(Q,"error")},[Q]),y.useEffect(()=>{O(0)},[]);const{childrenMap:Ee,issueType:st,milestoneMap:Ke,finalFiltered:Be,counts:Fe,uniqueAuthors:ln,uniqueAssignees:In}=OEe({issues:F,tags:Y,milestones:K,tagFilterMode:re,stateFilter:e,typeFilter:n,searchQuery:o,selectedMilestoneId:V,selectedAuthor:_,selectedAssignee:C}),fr=y.useMemo(()=>{const ee=I*Qv;return Be.slice(ee,ee+Qv)},[Be,I]),yn=y.useMemo(()=>{const ee=new Map;for(const ve of z)ve.issueId&&!ve.parentID&&ee.set(ve.issueId,(ee.get(ve.issueId)??0)+1);return ee},[z]),hr=F.find(ee=>ee.id===M)??null,ha=y.useMemo(()=>{if(!M)return[];const ee=new Set([M]);if(d){ee.add(d);const ve=[...Ee.get(d)??[]];for(let ze=0;ze<ve.length;ze++){ee.add(ve[ze].id);const at=Ee.get(ve[ze].id);at&&ve.push(...at)}}return z.filter(ve=>ve.issueId&&ee.has(ve.issueId)&&!ve.parentID)},[M,d,Ee,z]),Ra=y.useCallback(ee=>{Me.setState({activeSessionId:ee}),$(`/${encodeURIComponent(D)}/run`)},[$,D]),Lt=y.useCallback((ee,ve)=>{ae(ee),f(ee,ve==="epic"?ee:null)},[ae,f]),yi=tB({onSwipeRight:()=>x(!0),onSwipeLeft:()=>p(!0),disabled:!M||b||m});return c.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 overflow-hidden",...yi,children:[c.jsxs("div",{className:ie("shrink-0 flex-col bg-surface",M?"hidden md:flex md:w-80 border-r border-line":"flex w-full"),children:[M?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-3",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-fg-3",children:"Issues"}),G&&c.jsx("div",{className:"flex items-center gap-1",children:c.jsx("button",{type:"button",onClick:()=>G&&void B(G),disabled:L,title:"同步",className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:c.jsx(Rl,{className:ie("h-3.5 w-3.5",L&&"animate-spin")})})})]}),a&&c.jsx(c5,{onDone:()=>i(!1)}),c.jsx("div",{className:"flex border-b border-line",children:Z8.map(({key:ee,label:ve})=>{const ze=ee==="open"?Fe.open:ee==="closed"?Fe.closed:F.length;return c.jsxs("button",{type:"button",onClick:()=>t(ee),className:ie("flex flex-1 items-center justify-center gap-1.5 py-2 text-xs font-medium transition-colors",e===ee?"border-b-2 border-blue-500 text-blue-500":"text-fg-4 hover:text-fg-2"),children:[ve,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",e===ee?"bg-blue-500/10 text-blue-500":"bg-elevated text-fg-5"),children:ze})]},ee)})}),c.jsx("div",{className:"border-b border-line px-3 py-2",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2 py-1",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:o,onChange:ee=>u(ee.target.value),placeholder:"搜索 issue...",className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),o&&c.jsx("button",{type:"button",onClick:()=>u(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})})]}):c.jsxs(c.Fragment,{children:[c.jsx(NEe,{stateFilter:e,setStateFilter:t,typeFilter:n,setTypeFilter:r,searchQuery:o,setSearchQuery:u,expandedFilter:E,setExpandedFilter:N,selectedAuthor:_,setSelectedAuthor:S,selectedAssignee:C,setSelectedAssignee:A,creating:a,setCreating:i,openCount:Fe.open,closedCount:Fe.closed,totalCount:F.length,epicCount:Fe.epic,taskCount:Fe.task,strayCount:Fe.stray,afterStateCount:Fe.afterState,uniqueAuthors:ln,uniqueAssignees:In}),a&&c.jsx(c5,{onDone:()=>i(!1)})]}),c.jsx("div",{className:ie("flex-1 overflow-y-auto",M?"px-2 py-2":"px-3 py-3"),children:G?P?Be.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:F.length===0?"点击 ↻ 同步 Issues":"无匹配 Issue"}):c.jsx("ul",{className:ie(M?"space-y-0.5":"space-y-1"),children:fr.map(ee=>M?c.jsx(vI,{issue:ee,sessionCount:yn.get(ee.id)??0,isActive:M===ee.id,isEpic:st(ee)==="epic",milestone:ee.milestoneId?Ke.get(ee.milestoneId):void 0,onSelect:()=>Lt(ee.id,st(ee))},ee.id):c.jsx(_Ee,{issue:ee,sessionCount:yn.get(ee.id)??0,isEpic:st(ee)==="epic",milestone:ee.milestoneId?Ke.get(ee.milestoneId):void 0,onSelect:()=>Lt(ee.id,st(ee))},ee.id))}):c.jsxs("div",{className:"flex flex-col items-center gap-2 py-8",children:[c.jsx(nn,{className:"h-4 w-4 fs-spin text-fg-5"}),c.jsx("p",{className:"text-xs text-fg-5",children:"加载中…"})]}):c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:"请先选择一个仓库"})}),c.jsx(NI,{total:Be.length,page:I,onPageChange:O})]}),M&&c.jsx(dE,{side:"left",open:b,onClose:()=>x(!1),children:c.jsxs("div",{className:"flex h-full flex-col",children:[c.jsx("div",{className:"border-b border-line px-3 py-3",children:c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-fg-3",children:"Issues"})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:Be.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:"无匹配 Issue"}):c.jsx("ul",{className:"space-y-0.5",children:fr.map(ee=>c.jsx(vI,{issue:ee,sessionCount:yn.get(ee.id)??0,isActive:M===ee.id,isEpic:st(ee)==="epic",milestone:ee.milestoneId?Ke.get(ee.milestoneId):void 0,onSelect:()=>{Lt(ee.id,st(ee)),x(!1)}},ee.id))})}),c.jsx(NI,{total:Be.length,page:I,onPageChange:O})]})}),M&&c.jsx("div",{className:"relative flex min-w-0 flex-1 flex-col bg-term",children:hr?c.jsxs(c.Fragment,{children:[c.jsx(EEe,{issue:hr,milestone:hr.milestoneId?Ke.get(hr.milestoneId):void 0,tab:le,prNumber:ne,onTabChange:xe,onSelectPr:we,onBackToPrList:Le,onBack:()=>{De(),p(!1)},onClose:()=>{De(),p(!1)},onToggleSidebar:()=>p(ee=>!ee)}),m&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"absolute inset-0 z-10 bg-black/30",onClick:()=>p(!1)}),c.jsxs("div",{className:"absolute right-0 top-0 bottom-0 z-20 flex w-[280px] flex-col border-l border-line bg-surface shadow-xl",children:[c.jsxs("div",{className:"flex shrink-0 items-center justify-between border-b border-line px-3 py-2.5",children:[c.jsx("span",{className:"text-[11px] font-semibold uppercase tracking-wider text-fg-4",children:d?"子任务树 & 运行记录":"运行记录"}),c.jsx("button",{type:"button",onClick:()=>p(!1),className:"flex h-6 w-6 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-hidden",children:d?(()=>{const ee=F.find(ve=>ve.id===d);return ee?c.jsx(kEe,{rootIssue:ee,childrenMap:Ee,currentId:M,onSelect:ve=>{ae(ve),f(ve,d),p(!1)},sessions:ha,onSessionSelect:Ra}):null})():c.jsx(AEe,{sessions:ha,onSessionSelect:Ra})})]})]})]}):c.jsx("div",{className:"flex flex-1 items-center justify-center",children:c.jsx("p",{className:"font-mono text-xs text-fg-5",children:"Issue 未找到"})})})]})}function MEe({issues:e,onSelect:t}){const n=Me(a=>a.sessions),r=new Map;for(const a of n)a.issueId&&!a.parentID&&r.set(a.issueId,(r.get(a.issueId)??0)+1);return e.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-fg-5",children:[c.jsx(ql,{className:"h-8 w-8"}),c.jsx("p",{className:"font-mono text-xs",children:"该 PR 没有关联的 Issue"})]}):c.jsx("ul",{className:"space-y-2",children:e.map(a=>{const i=r.get(a.id)??0;return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:()=>t(a.id),className:"group flex w-full flex-col gap-1.5 rounded-lg border border-line bg-elevated/30 px-4 py-3 text-left transition-colors hover:border-blue-500/40 hover:bg-elevated/60",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-[10px] font-semibold",xEe(a.state)),children:["#",a.number," ",a.state]}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg-2 group-hover:text-fg",children:a.title}),i>0&&c.jsxs("span",{className:"shrink-0 rounded-full bg-elevated px-2 py-0.5 font-mono text-[10px] text-fg-5",children:[i," 次运行"]})]}),c.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-[11px] text-fg-5",children:[a.authorLogin&&c.jsxs("span",{className:"flex items-center gap-1",children:[a.authorAvatar&&c.jsx("img",{src:a.authorAvatar,alt:"",className:"h-3.5 w-3.5 rounded-full"}),a.authorLogin]}),a.labels&&a.labels.length>0&&a.labels.map(o=>c.jsx("span",{className:"rounded px-1.5 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${o.color}20`,color:`#${o.color}`},children:o.name},o.id))]})]})},a.id)})})}function DEe({pr:e,isActive:t,onSelect:n}){return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:n,className:ie("group flex w-full items-center gap-2.5 rounded-md px-2.5 py-2 text-left transition-colors",t?"border-l-2 border-blue-500 bg-elevated/80":"border-l-2 border-transparent hover:bg-elevated/50"),children:[c.jsx("span",{className:ie("flex h-10 w-10 shrink-0 items-center justify-center rounded-full font-mono text-sm font-bold ring-1",e.state==="merged"?"bg-gradient-to-br from-purple-500/20 to-purple-500/5 text-purple-400 ring-purple-500/25":e.state==="closed"?"bg-gradient-to-br from-red-500/20 to-red-500/5 text-red-400 ring-red-500/25":"bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 text-emerald-400 ring-emerald-500/25"),children:e.number}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[e.draft===1&&c.jsx("span",{className:"shrink-0 rounded px-1 py-0.5 text-[9px] font-bold bg-fg-6/15 text-fg-4",children:"DRAFT"}),c.jsx("span",{className:"min-w-0 text-xs font-medium text-fg-2 group-hover:text-fg",children:e.title})]}),c.jsxs("div",{className:"mt-0.5 truncate font-mono text-[10px] text-fg-6",children:[e.headBranch," → ",e.baseBranch]}),e.labels&&e.labels.length>0&&c.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.labels.map(r=>c.jsx("span",{className:"rounded px-1 py-0.5 text-[10px] font-medium",style:{backgroundColor:`#${r.color}20`,color:`#${r.color}`},children:r.name},r.id))})]})]})})}const jEe=y.memo(DEe,(e,t)=>e.pr.number===t.pr.number&&e.pr.state===t.pr.state&&e.pr.title===t.pr.title&&e.pr.draft===t.pr.draft&&e.isActive===t.isActive);function LEe({pr:e,onSelect:t}){return c.jsx("li",{children:c.jsxs("button",{type:"button",onClick:t,className:"group flex w-full items-center gap-3 border-b border-line px-4 py-3 text-left transition-colors hover:bg-elevated/50",children:[c.jsx("span",{className:ie("flex h-10 w-10 shrink-0 items-center justify-center rounded-full font-mono text-sm font-bold ring-1",e.state==="merged"?"bg-gradient-to-br from-purple-500/20 to-purple-500/5 text-purple-400 ring-purple-500/25":e.state==="closed"?"bg-gradient-to-br from-red-500/20 to-red-500/5 text-red-400 ring-red-500/25":"bg-gradient-to-br from-emerald-500/20 to-emerald-500/5 text-emerald-400 ring-emerald-500/25"),children:e.number}),c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[e.draft===1&&c.jsx("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[9px] font-bold tracking-wide bg-fg-6/15 text-fg-4",children:"DRAFT"}),c.jsx("span",{className:"min-w-0 flex-1 truncate text-sm font-medium text-fg-2 group-hover:text-fg",children:e.title}),e.mergeable==="false"&&e.state==="open"&&c.jsxs("span",{className:"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-semibold bg-red-500/15 text-red-400",children:[c.jsx(On,{className:"inline h-3 w-3 -mt-px"})," Conflict"]}),e.assignees&&e.assignees.length>0&&c.jsx("div",{className:"hidden shrink-0 items-center -space-x-1.5 sm:flex",children:e.assignees.slice(0,3).map(n=>c.jsx("img",{src:n.avatar_url,alt:n.login,title:n.login,className:"h-5 w-5 rounded-full ring-2 ring-surface"},n.login))})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-1",children:[c.jsxs("span",{className:"shrink-0 font-mono text-[11px] text-fg-5",children:[e.headBranch," → ",e.baseBranch]}),c.jsx("span",{className:"text-fg-6",children:"·"}),e.authorLogin&&c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"shrink-0 text-[11px] text-fg-5",title:e.authorLogin,children:[e.authorAvatar&&c.jsx("img",{src:e.authorAvatar,alt:"",className:"mr-1 inline-block h-3.5 w-3.5 rounded-full align-text-bottom"}),e.authorLogin]}),c.jsx("span",{className:"text-fg-6",children:"·"})]}),c.jsx("span",{className:"shrink-0 text-[11px] text-fg-6",children:iw(e.createdAt)}),e.labels&&e.labels.length>0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-fg-6",children:"·"}),e.labels.map(n=>c.jsx("span",{className:"rounded px-1.5 py-0.5 text-[11px] font-medium",style:{backgroundColor:`#${n.color}20`,color:`#${n.color}`},children:n.name},n.id))]})]})]})]})})}const PEe=y.memo(LEe,(e,t)=>e.pr.number===t.pr.number&&e.pr.state===t.pr.state&&e.pr.title===t.pr.title&&e.pr.draft===t.pr.draft&&e.pr.mergeable===t.pr.mergeable),wI=[{key:"open",label:"开放"},{key:"merged",label:"已合并"},{key:"closed",label:"已关闭"},{key:"all",label:"全部"}];function BEe({issue:e,linked:t,onToggle:n}){return c.jsx("li",{children:c.jsx("button",{type:"button",onClick:n,className:ie("group flex w-full items-start gap-2 rounded-md px-3 py-2.5 text-left transition-colors",t?"border-l-2 border-emerald-500 bg-emerald-500/5":"border-l-2 border-transparent hover:bg-elevated/50"),children:c.jsx("div",{className:"min-w-0 flex-1",children:c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsxs("span",{className:ie("shrink-0 rounded px-1.5 py-0.5 font-mono text-xs font-medium",e.state==="open"?"bg-emerald-500/15 text-emerald-400":"bg-purple-500/15 text-purple-400"),children:["#",e.number]}),c.jsx("span",{className:"min-w-0 truncate text-sm font-medium text-fg-2",children:e.title}),t&&c.jsx(ME,{className:"ml-auto h-3.5 w-3.5 shrink-0 text-emerald-400"})]})})})})}function UEe({pr:e,tab:t,issueId:n,onTabChange:r,onSelectIssue:a,onBackToIssueList:i,onBack:o,onClose:u,onEnterMatch:d,onNavigateToIssue:f}){const m=We(N=>N.activeRepoId),p=Je(N=>N.issues),[b,x]=y.useState([]);y.useEffect(()=>{if(!m){x([]);return}UE(m,e.number).then(x).catch(()=>x([]))},[m,e.number]);const E=n?p.find(N=>N.id===n)??b.find(N=>N.id===n)??null:null;return c.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden",children:[b.length>0&&c.jsxs("div",{className:"flex shrink-0 items-center border-b border-line bg-surface",children:[c.jsxs("button",{type:"button",onClick:()=>r("pr"),className:ie("flex items-center gap-1.5 border-b-2 px-4 py-2.5 text-xs font-medium transition-colors",t==="pr"?"border-blue-500 text-fg":"border-transparent text-fg-4 hover:text-fg-2"),children:[c.jsx(Il,{className:"h-3.5 w-3.5"}),"PR"]}),c.jsxs("button",{type:"button",onClick:()=>r("issue"),className:ie("flex items-center gap-1.5 border-b-2 px-4 py-2.5 text-xs font-medium transition-colors",t==="issue"?"border-blue-500 text-fg":"border-transparent text-fg-4 hover:text-fg-2"),children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),"Issue",c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",t==="issue"?"bg-blue-500/10 text-blue-500":"bg-elevated text-fg-5"),children:b.length})]})]}),t==="pr"||b.length===0?c.jsx(Q8,{pr:e,onBack:o,onClose:u,onEnterMatch:d,onNavigateToIssue:f}):E?c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden",children:[c.jsx("div",{className:"flex shrink-0 items-center border-b border-line bg-elevated/30 px-4 py-2",children:c.jsxs("button",{type:"button",onClick:i,className:"flex items-center gap-1 rounded-md px-2 py-1 text-xs text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:[c.jsx(If,{className:"h-3.5 w-3.5"}),"返回列表"]})}),c.jsx(X8,{issue:E,onBack:i})]}):c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto",children:c.jsx("div",{className:"mx-auto max-w-3xl px-4 py-6 md:px-6",children:c.jsx(MEe,{issues:b,onSelect:a})})})]})}function FEe(){const[e,t]=y.useState("open"),[n,r]=y.useState(""),a=mn(ae=>ae.setViewingPr),[i,o]=y.useState(""),[u,d]=CE(),f=zn(),m=We(qr),p=mn(ae=>ae.pulls),b=mn(ae=>ae.syncing),x=mn(ae=>ae.syncPulls),E=mn(ae=>ae.syncError),N=mn(ae=>ae.matchingPrId),_=mn(ae=>ae.enterMatchMode),S=mn(ae=>ae.exitMatchMode),C=mn(ae=>ae.linkIssue),A=We(ae=>ae.activeRepoId),I=Je(ae=>ae.issues),O=u.get("id"),k=u.get("tab")==="issue"?"issue":"pr",j=u.get("issueId");y.useEffect(()=>{E&&ar.getState().addToast(E,"error")},[E]),y.useEffect(()=>{const ae=u.get("prId");if(!ae)return;const De=new URLSearchParams(u);De.delete("prId"),De.set("id",ae),d(De,{replace:!0})},[u,d]),y.useEffect(()=>{if(u.get("id"))return;const ae=mn.getState().viewingPrId;ae&&d({id:ae},{replace:!0})},[d,u.get]);const F=y.useCallback(ae=>{d({id:ae},{replace:!1}),a(ae)},[d,a]),P=y.useCallback(()=>{d({},{replace:!1}),a(null)},[d,a]),L=y.useCallback(ae=>{if(!O)return;const De={id:O};ae==="issue"&&(De.tab="issue"),d(De,{replace:!1})},[O,d]),B=y.useCallback(ae=>{O&&d({id:O,tab:"issue",issueId:ae},{replace:!1})},[O,d]),Y=y.useCallback(()=>{O&&d({id:O,tab:"issue"},{replace:!1})},[O,d]),re=N?p.find(ae=>ae.id===N)??null:null,[X,K]=y.useState(new Set);y.useEffect(()=>{if(!A||!re){K(new Set);return}UE(A,re.number).then(ae=>K(new Set(ae.map(De=>De.id)))).catch(()=>K(new Set))},[A,re]);const V=async ae=>{if(!re)return;X.has(ae.id)?await mn.getState().unlinkIssue(A,re.number,ae.number)&&K(we=>{const Le=new Set(we);return Le.delete(ae.id),Le}):await C(A,re.number,ae.number)&&K(we=>new Set(we).add(ae.id))},H=p.filter(ae=>ae.state==="open").length,G=p.filter(ae=>ae.state==="merged").length,Q=p.filter(ae=>ae.state==="closed").length,D=e==="all"?p:p.filter(ae=>ae.state===e),z=n.trim().toLowerCase(),$=z?D.filter(ae=>`#${ae.number} ${ae.title} ${ae.headBranch} ${ae.baseBranch}`.toLowerCase().includes(z)):D,M=i.trim().toLowerCase(),le=M?I.filter(ae=>`#${ae.number} ${ae.title}`.toLowerCase().includes(M)):I,oe=p.find(ae=>ae.id===O)??null,ne=A?re??oe:null;return c.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 overflow-hidden",children:[c.jsxs("div",{className:ie("shrink-0 flex-col bg-surface",ne?"hidden md:flex md:w-80 border-r border-line":"flex w-full"),children:[N?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-3",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-blue-400",children:"选择 Issue 关联"}),c.jsxs("button",{type:"button",onClick:S,className:"flex h-7 items-center gap-1 rounded-md px-2 text-xs text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:[c.jsx(At,{className:"h-3.5 w-3.5"}),"完成"]})]}),c.jsx("div",{className:"border-b border-line px-3 py-2",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2 py-1",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:i,onChange:ae=>o(ae.target.value),placeholder:"搜索 issue...",className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),i&&c.jsx("button",{type:"button",onClick:()=>o(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})}),c.jsx("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:le.length===0?c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:I.length===0?"暂无 Issue,请先同步":"无匹配 Issue"}):c.jsx("ul",{className:"space-y-0.5",children:le.map(ae=>c.jsx(BEe,{issue:ae,linked:X.has(ae.id),onToggle:()=>void V(ae)},ae.id))})})]}):ne?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-3 py-3",children:[c.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider text-fg-3",children:"Pull Requests"}),A&&c.jsx("button",{type:"button",onClick:()=>A&&void x(A),disabled:b,title:"同步",className:"flex h-7 w-7 items-center justify-center rounded-md text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-40",children:c.jsx(Rl,{className:ie("h-3.5 w-3.5",b&&"animate-spin")})})]}),c.jsx("div",{className:"flex border-b border-line",children:wI.map(({key:ae,label:De})=>{const xe=ae==="open"?H:ae==="merged"?G:ae==="closed"?Q:p.length;return c.jsxs("button",{type:"button",onClick:()=>t(ae),className:ie("flex flex-1 items-center justify-center gap-1.5 py-2 text-xs font-medium transition-colors",e===ae?"border-b-2 border-blue-500 text-blue-500":"text-fg-4 hover:text-fg-2"),children:[De,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",e===ae?"bg-blue-500/10 text-blue-500":"bg-elevated text-fg-5"),children:xe})]},ae)})}),c.jsx("div",{className:"border-b border-line px-3 py-2",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2 py-1",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:n,onChange:ae=>r(ae.target.value),placeholder:"搜索 PR...",className:"min-w-0 flex-1 bg-transparent font-mono text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),n&&c.jsx("button",{type:"button",onClick:()=>r(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})})]}):c.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-2 border-b border-line px-4 py-2.5",children:[c.jsx("span",{className:"shrink-0 text-sm font-semibold text-fg md:order-1",children:"Pull Requests"}),c.jsx("button",{type:"button",onClick:()=>A&&void x(A),disabled:b||!A,title:"同步 PR",className:"ml-auto flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:border-fg-5 hover:text-fg-2 disabled:opacity-40 md:order-last md:ml-0",children:c.jsx(Rl,{className:ie("h-4 w-4",b&&"animate-spin")})}),c.jsx("div",{className:"w-full md:order-2 md:w-auto",children:c.jsx("div",{className:"flex shrink-0 items-center rounded-lg bg-elevated/60 p-0.5",children:wI.map(({key:ae,label:De})=>{const xe=ae==="open"?H:ae==="merged"?G:ae==="closed"?Q:p.length;return c.jsxs("button",{type:"button",onClick:()=>t(ae),className:ie("flex items-center gap-1.5 rounded-md px-2.5 py-1 text-xs font-medium transition-colors",e===ae?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-2"),children:[De,c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",e===ae?"bg-blue-500/10 text-blue-500":"text-fg-5"),children:xe})]},ae)})})}),c.jsx("div",{className:"w-full md:order-3 md:w-auto md:min-w-0 md:flex-1 md:px-1",children:c.jsxs("div",{className:"flex items-center gap-2 rounded-md border border-line bg-base px-2.5 py-1.5",children:[c.jsx(Ao,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("input",{type:"text",value:n,onChange:ae=>r(ae.target.value),placeholder:"搜索 PR...",className:"min-w-0 flex-1 bg-transparent text-xs text-fg placeholder:text-fg-6 focus:outline-none"}),n&&c.jsx("button",{type:"button",onClick:()=>r(""),className:"shrink-0 text-fg-5 hover:text-fg-3",children:c.jsx(At,{className:"h-3 w-3"})})]})})]}),!N&&c.jsx("div",{className:ie("flex-1 overflow-y-auto",ne?"px-2 py-2":"px-3 py-3"),children:A?$.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center gap-2 py-16 text-fg-5",children:[c.jsx(Il,{className:"h-8 w-8"}),c.jsx("p",{className:"font-mono text-xs",children:p.length===0?"点击 ↻ 同步 PR":"没有匹配的 PR"})]}):c.jsx("ul",{className:ie(ne?"space-y-0.5":"space-y-1"),children:$.map(ae=>ne?c.jsx(jEe,{pr:ae,isActive:ae.id===(O??N),onSelect:()=>F(ae.id)},ae.id):c.jsx(PEe,{pr:ae,onSelect:()=>F(ae.id)},ae.id))}):c.jsx("p",{className:"px-2 py-8 text-center font-mono text-xs text-fg-5",children:"请先选择一个仓库"})})]}),ne?c.jsx(UEe,{pr:ne,tab:k,issueId:j,onTabChange:L,onSelectIssue:B,onBackToIssueList:Y,onBack:()=>{P(),N&&S()},onClose:()=>{P(),N&&S()},onEnterMatch:()=>_(ne.id),onNavigateToIssue:ae=>{m&&f(`/${encodeURIComponent(m)}/dev/issues?id=${encodeURIComponent(ae)}`)}},`${ne.id}-${N??"view"}`):c.jsx("div",{className:"hidden flex-1 items-center justify-center md:flex",children:c.jsxs("div",{className:"text-center text-fg-5",children:[c.jsx(Il,{className:"mx-auto h-12 w-12 opacity-20"}),c.jsx("p",{className:"mt-3 font-mono text-xs",children:"选择一个 PR 查看详情"})]})})]})}function _I(e,t){return e?`/${encodeURIComponent(e)}/dev/${t}`:`/dev/${t}`}function TI(){const e=zn(),t=or(),n=We(qr),r=Je(d=>d.issues),a=mn(d=>d.pulls),i=t.pathname.endsWith("/pulls")?"pulls":"issues",o=r.filter(d=>d.state==="open").length,u=a.filter(d=>d.state==="open").length;return c.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[c.jsx("div",{className:"flex shrink-0 items-center gap-1 border-b border-line bg-surface px-3 py-2",children:c.jsxs("div",{className:"flex items-center rounded-lg bg-elevated/60 p-0.5",children:[c.jsxs("button",{type:"button",onClick:()=>e(_I(n,"issues")),className:ie("flex items-center gap-1.5 rounded-md px-3 py-1 text-xs font-medium transition-colors",i==="issues"?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-2"),children:[c.jsx(ql,{className:"h-3.5 w-3.5"}),"Issues",c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",i==="issues"?"bg-blue-500/10 text-blue-500":"text-fg-5"),children:o})]}),c.jsxs("button",{type:"button",onClick:()=>e(_I(n,"pulls")),className:ie("flex items-center gap-1.5 rounded-md px-3 py-1 text-xs font-medium transition-colors",i==="pulls"?"bg-surface text-fg shadow-sm":"text-fg-4 hover:text-fg-2"),children:[c.jsx(Il,{className:"h-3.5 w-3.5"}),"PRs",c.jsx("span",{className:ie("rounded-full px-1.5 py-0.5 font-mono text-[10px]",i==="pulls"?"bg-blue-500/10 text-blue-500":"text-fg-5"),children:u})]})]})}),c.jsx("div",{className:"flex min-h-0 min-w-0 flex-1 overflow-hidden",children:i==="issues"?c.jsx(REe,{}):c.jsx(FEe,{})})]})}const zEe=/^[\w.-]+@([\w.-]+):([\w.-]+)\/([\w.-]+?)(?:\.git)?$/,HEe=/^https?:\/\/([\w.-]+)(?::\d+)?\/([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:\/)?$/,$Ee=/^ssh:\/\/[\w.-]+@([\w.-]+)(?::\d+)?\/([\w.-]+)\/([\w.-]+?)(?:\.git)?$/;function nB(e){for(const t of[zEe,HEe,$Ee]){const n=e.match(t);if(n)return n[1]}return null}function AI({onSelect:e}){const[t,n]=y.useState(""),[r,a]=y.useState(null),[i,o]=y.useState([]),[u,d]=y.useState(!0),[f,m]=y.useState(""),[p,b]=y.useState(!1),x=y.useCallback(async A=>{d(!0),m("");try{const I=await s$(A,p);n(I.path),a(I.parent),o(I.entries)}catch(I){const O=I instanceof Error?I.message:"无法读取目录";try{const k=JSON.parse(O);m(k.error??O)}catch{m(O)}}d(!1)},[p]);y.useEffect(()=>{x()},[x]);const E=A=>{x(`${t}/${A}`)},N=()=>{r&&x(r)},_=A=>{const O=`/${t.split("/").filter(Boolean).slice(0,A+1).join("/")}`;x(O)},S=A=>{e(`${t}/${A}`)},C=t.split("/").filter(Boolean);return c.jsxs("div",{className:"flex flex-col gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1 overflow-x-auto text-xs",children:[c.jsx("button",{type:"button",onClick:()=>void x("/"),className:"shrink-0 rounded px-1 py-0.5 text-fg-4 hover:bg-elevated hover:text-fg-2",children:"/"}),C.map((A,I)=>c.jsxs("span",{className:"flex shrink-0 items-center gap-1",children:[c.jsx(Oo,{className:"h-3 w-3 text-fg-5"}),c.jsx("button",{type:"button",onClick:()=>_(I),className:`rounded px-1 py-0.5 ${I===C.length-1?"font-medium text-fg":"text-fg-4 hover:bg-elevated hover:text-fg-2"}`,children:A})]},I))]}),c.jsx("button",{type:"button",onClick:()=>b(A=>!A),className:"ml-2 shrink-0 rounded-md p-1 text-fg-4 hover:bg-elevated hover:text-fg-2",title:p?"隐藏隐藏文件":"显示隐藏文件",children:p?c.jsx(GR,{className:"h-3.5 w-3.5"}):c.jsx(qR,{className:"h-3.5 w-3.5"})})]}),c.jsx("div",{className:"max-h-52 overflow-y-auto rounded-lg border border-line bg-base",children:u?c.jsx("div",{className:"flex items-center justify-center py-8",children:c.jsx(nn,{className:"h-4 w-4 animate-spin text-fg-4"})}):f?c.jsx("div",{className:"px-3 py-4 text-center text-xs text-red-500",children:f}):c.jsxs(c.Fragment,{children:[r!==null&&c.jsxs("button",{type:"button",onClick:N,className:"flex w-full items-center gap-2 border-b border-line px-3 py-2 text-left text-sm text-fg-3 hover:bg-elevated",children:[c.jsx(iA,{className:"h-3.5 w-3.5 text-fg-5"}),c.jsx("span",{children:".."})]}),i.length===0&&c.jsx("div",{className:"px-3 py-4 text-center text-xs text-fg-5",children:"空目录"}),i.map(A=>c.jsxs("div",{className:"flex items-center border-b border-line last:border-0",children:[c.jsxs("button",{type:"button",onClick:()=>A.isGitRepo?S(A.name):E(A.name),className:"flex min-w-0 flex-1 items-center gap-2 px-3 py-2 text-left text-sm hover:bg-elevated",children:[A.isGitRepo?c.jsx(Gl,{className:"h-3.5 w-3.5 shrink-0 text-emerald-500"}):c.jsx(iA,{className:"h-3.5 w-3.5 shrink-0 text-fg-4"}),c.jsx("span",{className:`truncate ${A.isGitRepo?"text-fg font-medium":"text-fg-3"}`,children:A.name}),A.isGitRepo&&c.jsx("span",{className:"ml-auto shrink-0 rounded bg-emerald-500/10 px-1.5 py-0.5 text-[10px] font-medium text-emerald-500",children:"git"})]}),A.isGitRepo&&c.jsx("button",{type:"button",onClick:()=>E(A.name),className:"shrink-0 px-2 py-2 text-fg-5 hover:text-fg-2",title:"进入目录",children:c.jsx(Oo,{className:"h-3.5 w-3.5"})})]},A.name))]})})]})}function YEe({onClose:e}){const t=zn(),[n,r]=y.useState("browse"),[a,i]=y.useState(""),[o,u]=y.useState(""),[d,f]=y.useState(""),[m,p]=y.useState(""),[b,x]=y.useState(!1),[E,N]=y.useState("opencode"),[_,S]=y.useState(!1),[C,A]=y.useState(!1),[I,O]=y.useState(""),[k,j]=y.useState(null),F=We(G=>G.addRepo),P=o.trim()!==""&&d.trim()!==""&&a.trim()!==""&&!_&&!C,L=G=>{const Q=G instanceof Error?G.message:"操作失败";try{return JSON.parse(Q).error??Q}catch{return Q}},B=async G=>{const Q=G.trim();if(Q){S(!0),O("");try{const D=await i$(Q);i(D.localPath),D.name&&u(D.name),D.gitUrl&&f(D.gitUrl)}catch(D){O(L(D))}S(!1)}},Y=y.useRef(B);Y.current=B,y.useEffect(()=>{if(n!=="browse")return;const G=a.trim();if(!G)return;const Q=setTimeout(()=>{Y.current(G)},OY);return()=>clearTimeout(Q)},[a,n]),y.useEffect(()=>{const G=d.trim();if(!G){j(null);return}const Q=nB(G);if(!Q){j(null);return}let D=!1;const z=setTimeout(()=>{FE().then($=>{if(D)return;const M=$.some(le=>le.host.toLowerCase()===Q.toLowerCase());j(M?null:Q)}).catch(()=>{D||j(null)})},kY);return()=>{D=!0,clearTimeout(z)}},[d]);const re=G=>{i(G),O(""),B(G)},X=G=>{p(G),x(!1)},K=async()=>{const G=d.trim();if(!G){O("请输入 Git 仓库地址");return}A(!0),O("");try{const Q=m.trim()||void 0,D=await o$(G,Q);i(D.localPath),D.name&&u(D.name),D.gitUrl&&f(D.gitUrl)}catch(Q){O(L(Q))}A(!1)},V=async()=>{if(!P)return;O(""),await F(o.trim(),d.trim(),a.trim(),E)&&e()},H=G=>{r(G),i(""),u(""),f(""),p(""),x(!1),O(""),j(null)};return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:e,children:c.jsxs("div",{className:"w-full max-w-lg rounded-xl border border-line bg-surface p-6 shadow-2xl",onClick:G=>G.stopPropagation(),children:[c.jsxs("div",{className:"mb-5 flex items-center justify-between",children:[c.jsx("h2",{className:"text-base font-semibold text-fg",children:"添加仓库"}),c.jsx("button",{type:"button",onClick:e,className:"rounded-md p-1 text-fg-4 hover:bg-elevated hover:text-fg-2",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsxs("div",{className:"mb-4 flex gap-1 rounded-lg border border-line bg-base p-1",children:[c.jsxs("button",{type:"button",onClick:()=>H("browse"),className:`flex flex-1 items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors ${n==="browse"?"bg-elevated text-fg shadow-sm":"text-fg-4 hover:text-fg-2"}`,children:[c.jsx(Pz,{className:"h-3.5 w-3.5"}),"已有仓库"]}),c.jsxs("button",{type:"button",onClick:()=>H("clone"),className:`flex flex-1 items-center justify-center gap-1.5 rounded-md px-3 py-1.5 text-sm font-medium transition-colors ${n==="clone"?"bg-elevated text-fg shadow-sm":"text-fg-4 hover:text-fg-2"}`,children:[c.jsx(Gl,{className:"h-3.5 w-3.5"}),"克隆新仓库"]})]}),c.jsxs("div",{className:"flex flex-col gap-4",children:[n==="browse"?c.jsxs(c.Fragment,{children:[c.jsx(AI,{onSelect:re}),c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{htmlFor:"m-path",className:"text-xs font-medium text-fg-3",children:"本地路径"}),c.jsx("input",{id:"m-path",value:a,onChange:G=>i(G.target.value),onBlur:G=>void B(G.target.value),placeholder:"/home/you/code/repo",className:"w-full rounded-lg border border-line bg-base px-3 py-2 font-mono text-sm text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"}),c.jsx("span",{className:"text-[11px] text-fg-5",children:_?"正在读取 Git 信息…":"点选目录或手动输入路径"})]})]}):c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{htmlFor:"m-clone-url",className:"text-xs font-medium text-fg-3",children:"Git 仓库地址"}),c.jsx("input",{id:"m-clone-url",value:d,onChange:G=>f(G.target.value),placeholder:"https://github.com/org/repo.git",className:"w-full rounded-lg border border-line bg-base px-3 py-2 font-mono text-xs text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]}),c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{className:"text-xs font-medium text-fg-3",children:"目标目录"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("input",{value:m,onChange:G=>p(G.target.value),placeholder:"默认: ~/.fourth-spark/repos/",className:"min-w-0 flex-1 rounded-lg border border-line bg-base px-3 py-2 font-mono text-xs text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"}),c.jsx("button",{type:"button",onClick:()=>x(G=>!G),className:`shrink-0 rounded-lg border px-2.5 py-2 text-sm transition-colors ${b?"border-blue-500 bg-blue-500/10 text-blue-600":"border-line bg-base text-fg-4 hover:bg-elevated hover:text-fg-2"}`,children:c.jsx(kr,{className:`h-3.5 w-3.5 transition-transform ${b?"rotate-180":""}`})})]}),b&&c.jsx(AI,{onSelect:X}),c.jsx("span",{className:"text-[11px] text-fg-5",children:"留空则克隆到默认目录,选择目录后仓库将克隆到该目录下"})]}),c.jsx("button",{type:"button",onClick:K,disabled:C||!d.trim(),className:"w-full rounded-lg bg-emerald-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-emerald-500 disabled:cursor-not-allowed disabled:bg-fg-6 disabled:text-fg-4",children:C?c.jsxs("span",{className:"flex items-center justify-center gap-1.5",children:[c.jsx(nn,{className:"h-3.5 w-3.5 animate-spin"}),"正在克隆仓库…"]}):"克隆"}),a&&c.jsxs("div",{className:"rounded-md bg-emerald-500/10 px-3 py-2 text-xs text-emerald-600",children:["克隆完成: ",c.jsx("span",{className:"font-mono",children:a})]})]}),c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{htmlFor:"m-name",className:"text-xs font-medium text-fg-3",children:"名称"}),c.jsx("input",{id:"m-name",value:o,onChange:G=>u(G.target.value),placeholder:"my-project",className:"w-full rounded-lg border border-line bg-base px-3 py-2 text-sm text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]}),n==="browse"&&c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{htmlFor:"m-git",className:"text-xs font-medium text-fg-3",children:"Git 远程地址"}),c.jsx("input",{id:"m-git",value:d,onChange:G=>f(G.target.value),placeholder:"https://github.com/org/repo.git",className:"w-full rounded-lg border border-line bg-base px-3 py-2 font-mono text-xs text-fg placeholder:text-fg-5 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20"})]}),k&&c.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-amber-500/10 px-3 py-2 text-xs text-amber-600",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsxs("span",{children:["源站 ",c.jsx("strong",{children:k})," 尚未配置访问凭证,Issue/PR 同步将不可用。",c.jsx("button",{type:"button",onClick:()=>{e(),t("/settings")},className:"ml-1 font-medium underline hover:text-amber-700",children:"去配置"})]})]}),c.jsxs("div",{className:"flex flex-col gap-1.5",children:[c.jsx("label",{className:"text-xs font-medium text-fg-3",children:"运行时"}),c.jsx("div",{className:"flex gap-2",children:[{value:"opencode",label:"OpenCode"},{value:"claude-code",label:"Claude Code"}].map(G=>c.jsx("button",{type:"button",onClick:()=>N(G.value),className:`flex-1 rounded-lg border px-3 py-2 text-sm font-medium transition-colors ${E===G.value?"border-blue-500 bg-blue-500/10 text-blue-600":"border-line bg-base text-fg-4 hover:bg-elevated hover:text-fg-2"}`,children:G.label},G.value))}),c.jsx("span",{className:"text-[11px] text-fg-5",children:E==="claude-code"?"需要本地安装 Claude Code CLI":"需要本地安装 OpenCode CLI"})]}),I&&c.jsx("p",{className:"rounded-md bg-red-500/10 px-3 py-2 text-xs text-red-500",children:I}),c.jsxs("div",{className:"mt-1 flex items-center justify-end gap-2",children:[c.jsx("button",{type:"button",onClick:e,className:"rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"取消"}),c.jsx("button",{type:"button",onClick:V,disabled:!P,className:"rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 disabled:cursor-not-allowed disabled:bg-fg-6 disabled:text-fg-4",children:"添加仓库"})]})]})]})})}function qEe({repoId:e,repoName:t,onClose:n}){const[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(!0),[f,m]=y.useState(!1),[p,b]=y.useState(null);y.useEffect(()=>{uY(e).then(N=>{a(N.content),o(N.content),d(!1)}).catch(N=>{b(N instanceof Error?N.message:String(N)),d(!1)})},[e]);const x=async()=>{m(!0),b(null);try{await cY(e,r),o(r)}catch(N){b(N instanceof Error?N.message:String(N))}m(!1)},E=r!==i;return c.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",onClick:n,children:c.jsxs("div",{className:"flex w-full max-w-2xl flex-col rounded-xl border border-line bg-surface p-6 shadow-2xl",onClick:N=>N.stopPropagation(),children:[c.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsxs("h2",{className:"text-base font-semibold text-fg",children:[t," — AGENTS.md"]}),c.jsx("p",{className:"mt-0.5 text-xs text-fg-4",children:"仅对此仓库生效,修改后 opencode 热加载即时生效。"})]}),c.jsx("button",{type:"button",onClick:n,className:"shrink-0 rounded-md p-1 text-fg-4 hover:bg-elevated hover:text-fg-2",children:c.jsx(At,{className:"h-4 w-4"})})]}),p&&c.jsxs("div",{className:"mb-3 flex items-start gap-2 rounded-lg bg-red-500/10 px-3 py-2 text-xs text-red-400",children:[c.jsx(On,{className:"mt-0.5 h-3.5 w-3.5 shrink-0"}),c.jsx("span",{className:"min-w-0 break-words",children:p})]}),u?c.jsxs("div",{className:"flex flex-col items-center gap-2.5 py-16 text-fg-5",children:[c.jsx(nn,{className:"h-5 w-5 fs-spin"}),c.jsx("p",{className:"text-xs",children:"加载中…"})]}):c.jsx("textarea",{value:r,onChange:N=>a(N.target.value),spellCheck:!1,className:"h-96 w-full resize-y rounded-lg border border-line bg-base px-4 py-3 font-mono text-sm leading-relaxed text-fg placeholder:text-fg-6 focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20",placeholder:`# AGENTS.md
|
|
651
651
|
|
|
652
|
-
在此编写该仓库的 Agent 指令…`}),c.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[c.jsx("button",{type:"button",onClick:n,className:"rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"关闭"}),c.jsxs("button",{type:"button",onClick:()=>void x(),disabled:f||!E,className:"flex items-center gap-1.5 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),f?"保存中…":"保存"]})]})]})})}const fE=1024,hE=fE*1024,CI=hE*1024;function kI(e){return!e||e<=0?"0 B":e<fE?`${e} B`:e<hE?`${(e/fE).toFixed(1)} KB`:e<CI?`${(e/hE).toFixed(1)} MB`:`${(e/CI).toFixed(2)} GB`}const Dv="ws/";function GEe({repoId:e}){const[t,n]=y.useState(!1),[r,a]=y.useState(null),[i,o]=y.useState(!1),[u,d]=y.useState(null),{data:f,loading:m,error:p,reload:b}=lc(()=>m$(e),[e,t],{skip:!t,showErrorToast:!1,errorMessage:"加载失败"}),x=u??p,E=async C=>{a(C),d(null);try{await p$(e,C),b()}catch(A){d(A instanceof Li?A.message:"删除失败")}a(null)},N=async()=>{o(!0),d(null);try{await g$(e),b()}catch(C){d(C instanceof Li?C.message:"清理失败")}o(!1)},_=(f==null?void 0:f.length)??0,S=(f==null?void 0:f.reduce((C,A)=>C+(A.diskUsage||0),0))??0;return c.jsxs("div",{className:"mt-3 border-t border-line pt-3",children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>n(C=>!C),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left text-xs font-medium text-fg-3 transition-colors hover:text-fg-2",children:[t?c.jsx(OE,{className:"h-3 w-3 shrink-0"}):c.jsx(kr,{className:"h-3 w-3 shrink-0"}),c.jsx(Gl,{className:"h-3 w-3 shrink-0 text-fg-5"}),c.jsx("span",{children:"工作空间"}),f!==null&&c.jsxs("span",{className:"text-fg-5",children:["(",_,") · ",kI(S)]})]}),t&&_>0&&c.jsxs("button",{type:"button",onClick:()=>void N(),disabled:i,className:"flex h-6 shrink-0 items-center gap-1 rounded border border-line px-2 text-xs text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-50",children:[i?c.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):null,"清理已合并"]})]}),t&&c.jsxs("div",{className:"mt-2",children:[x&&c.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 rounded border border-red-500/30 bg-red-500/5 px-2 py-1 text-xs text-red-600",children:[c.jsx("span",{className:"truncate",children:x}),c.jsx("button",{type:"button",onClick:()=>d(null),className:"shrink-0 rounded p-0.5 transition-colors hover:bg-red-500/10",children:c.jsx(At,{className:"h-3 w-3"})})]}),m&&f===null?c.jsx("div",{className:"flex justify-center py-3",children:c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-fg-5 border-t-transparent"})}):_===0?c.jsx("p",{className:"py-2 text-center text-xs text-fg-5",children:"暂无工作空间"}):c.jsx("ul",{className:"space-y-1",children:f==null?void 0:f.map(C=>{const A=C.branch.startsWith(Dv),I=A?C.branch.slice(Dv.length):C.branch,O=C.status==="active"?"bg-emerald-500/10 text-emerald-600":C.status==="idle"?"bg-amber-500/10 text-amber-600":"bg-fg-6/30 text-fg-4",k=C.status==="active"?"活跃":C.status==="idle"?"空闲":C.status==="merged"?"已合并":C.status==="stale"?"陈旧":C.status,j=C.status!=="active";return c.jsxs("li",{className:"flex items-center gap-2 rounded-md border border-line bg-elevated/40 px-2 py-1.5 text-xs",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[C.running&&C.port&&c.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",title:`运行中 :${C.port}`}),c.jsxs("span",{className:"min-w-0 truncate font-mono",children:[A&&c.jsx("span",{className:"text-fg-5",children:Dv}),c.jsx("span",{className:"text-fg-2",children:I})]})]}),c.jsx("span",{className:ie("shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium",O),children:k}),c.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 text-fg-5",children:[c.jsx(Qz,{className:"h-2.5 w-2.5"}),kI(C.diskUsage)]}),c.jsx("button",{type:"button",onClick:()=>void E(C.id),disabled:!j||r===C.id,title:j?"删除工作空间":"活跃工作空间无法删除",className:"flex h-5 w-5 shrink-0 items-center justify-center rounded text-fg-5 transition-colors hover:bg-red-500/10 hover:text-red-500 disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-fg-5",children:r===C.id?c.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsx(a0,{className:"h-3 w-3"})})]},C.id)})})]})]})}function rB(){const e=zn(),t=We(P=>P.repos),n=We(P=>P.activeRepoId),r=We(P=>P.setActiveRepo),a=We(P=>P.removeRepo),i=We(P=>P.loadRepos),[o,u]=y.useState(!1),[d,f]=y.useState(null),[m,p]=y.useState(null),[b,x]=y.useState(null),E=ar(P=>P.addToast),[N,_]=y.useState(null),[S,C]=y.useState(null),A=y.useRef(null),[I,O]=y.useState(null);y.useEffect(()=>{FE().then(P=>O(new Set(P.map(L=>L.host.toLowerCase())))).catch(()=>{})},[]);const k=y.useMemo(()=>{if(!I)return new Set;const P=new Set;for(const L of t){const B=nB(L.gitUrl);B&&!I.has(B.toLowerCase())&&P.add(L.id)}return P},[t,I]);y.useEffect(()=>{if(!S)return;const P=L=>{A.current&&!A.current.contains(L.target)&&C(null)};return document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[S]);const j=async(P,L)=>{p(P);try{L?await c$(P):await u$(P),await i()}catch{}p(null)},F=async P=>{x(P);try{const L=await h$(P);await i();const B=L.alreadyUpToDate?"info":"success";E(L.summary,B,void 0,{persistent:!0})}catch(L){let B="拉取失败";if(L instanceof Li)try{B=JSON.parse(L.message).error??L.message}catch{B=L.message}E(B,"error",void 0,{persistent:!0})}x(null)};return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"mb-6 flex items-center justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("h1",{className:"text-lg font-semibold text-fg",children:"仓库管理"}),c.jsx("p",{className:"mt-0.5 text-sm text-fg-4",children:"管理代码仓库,每个仓库对应一个独立的 Agent 运行环境"})]}),c.jsxs("button",{type:"button",onClick:()=>u(!0),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-blue-600 px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 md:px-4",children:[c.jsx(ua,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden md:inline",children:"添加仓库"})]})]}),t.length===0?c.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-xl border border-dashed border-line-hard py-16 text-center",children:[c.jsx("div",{className:"rounded-full bg-elevated p-3",children:c.jsx(ua,{className:"h-6 w-6 text-fg-4"})}),c.jsx("p",{className:"text-sm font-medium text-fg-3",children:"暂无代码仓库"}),c.jsx("p",{className:"text-xs text-fg-5",children:"添加一个本地仓库开始使用"}),c.jsx("button",{type:"button",onClick:()=>u(!0),className:"mt-2 rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"添加仓库"})]}):c.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:t.map((P,L)=>{const B=P.id===n;return c.jsxs("div",{className:ie("rounded-xl border p-4 transition-colors",B?"border-blue-500/40 bg-blue-500/5":"border-line"),children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>r(P.id),className:"flex min-w-0 items-center gap-2 text-left",children:[B?c.jsx(ql,{className:"h-4 w-4 shrink-0 text-blue-500"}):c.jsx(pz,{className:"h-4 w-4 shrink-0 text-fg-5"}),c.jsx("span",{className:ie("truncate font-medium",B?"text-fg":"text-fg-2"),children:P.name})]}),c.jsxs("span",{className:ie("inline-flex shrink-0 items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium",P.running?"bg-emerald-500/10 text-emerald-600":"bg-fg-6/30 text-fg-4"),children:[c.jsx("span",{className:ie("h-1.5 w-1.5 rounded-full",P.running?"bg-emerald-500":"bg-fg-5")}),P.running?"运行中":"已停止"]})]}),c.jsxs("dl",{className:"mt-3 space-y-1 font-mono text-xs text-fg-4",children:[c.jsxs("div",{className:"flex gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"Git"}),c.jsx("dd",{className:"min-w-0 truncate",children:P.gitUrl})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"路径"}),c.jsxs("dd",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsx("span",{className:"truncate",children:P.localPath}),c.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(P.localPath),title:"复制路径",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:text-fg-3",children:c.jsx($p,{className:"h-3 w-3"})})]})]}),P.running&&P.port&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"直连"}),c.jsxs("dd",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsxs("a",{href:`http://127.0.0.1:${P.port}`,target:"_blank",rel:"noopener noreferrer",className:"truncate text-blue-500 hover:underline",children:["127.0.0.1:",P.port]}),c.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(`http://127.0.0.1:${P.port}`),title:"复制链接",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:text-fg-3",children:c.jsx($p,{className:"h-3 w-3"})})]})]})]}),k.has(P.id)&&c.jsxs("button",{type:"button",onClick:()=>e("/settings"),className:"mt-2 flex w-full items-center gap-1.5 rounded-md bg-amber-500/10 px-2.5 py-1.5 text-left text-xs text-amber-600 transition-colors hover:bg-amber-500/15",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{children:"缺少 Git 源站凭证,Issue/PR 同步不可用"})]}),c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[c.jsx("button",{type:"button",onClick:()=>void F(P.id),disabled:b===P.id,className:"flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-md border border-blue-500/30 px-2.5 text-xs font-medium text-blue-600 transition-colors hover:bg-blue-500/10 disabled:opacity-50",children:b===P.id?c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsxs(c.Fragment,{children:[c.jsx($F,{className:"h-3 w-3"}),"拉取"]})}),c.jsx("button",{type:"button",onClick:()=>void j(P.id,P.running),disabled:m===P.id,className:ie("flex h-8 flex-1 items-center justify-center gap-1.5 rounded-md border text-xs font-medium transition-colors disabled:opacity-50",P.running?"border-amber-500/30 text-amber-600 hover:bg-amber-500/10":"border-emerald-500/30 text-emerald-600 hover:bg-emerald-500/10"),children:m===P.id?c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):P.running?c.jsxs(c.Fragment,{children:[c.jsx(Vv,{className:"h-3 w-3 fill-current"}),"停止"]}):c.jsxs(c.Fragment,{children:[c.jsx(LE,{className:"h-3 w-3 fill-current"}),"启动"]})}),c.jsxs("div",{className:"relative",ref:S===P.id?A:void 0,children:[c.jsx("button",{type:"button","data-guide":L===0?"repo-overflow-btn":void 0,onClick:()=>C(S===P.id?null:P.id),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(IE,{className:"h-4 w-4"})}),S===P.id&&c.jsxs("div",{"data-guide":L===0?"repo-overflow-dropdown":void 0,className:"absolute right-0 top-full z-20 mt-1 min-w-[160px] overflow-hidden rounded-lg border border-line bg-elevated shadow-lg",children:[c.jsx("button",{type:"button",className:ie("flex w-full items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-base/60",P.runtimeType==="claude-code"?"text-orange-500":"text-sky-500"),onClick:async()=>{C(null);const Y=P.runtimeType==="claude-code"?"opencode":"claude-code";await x$(P.id,Y),i()},children:P.runtimeType==="claude-code"?"Claude → OpenCode":"OpenCode → Claude"}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",onClick:async()=>{C(null),await b$(P.id,!P.worktreeEnabled),i()},children:[c.jsx(Gl,{className:"h-3 w-3"}),c.jsx("span",{children:"Worktree"}),c.jsx("span",{className:ie("ml-auto text-[10px]",P.worktreeEnabled?"text-violet-500":"text-fg-5"),children:P.worktreeEnabled?"已开启":"已关闭"})]}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",onClick:()=>{C(null),_({id:P.id,name:P.name})},children:[c.jsx(Io,{className:"h-3 w-3"}),"配置"]}),c.jsx("div",{className:"my-0.5 border-t border-line"}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-red-500 transition-colors hover:bg-red-500/10",onClick:()=>{C(null),f(P.id)},children:[c.jsx(a0,{className:"h-3 w-3"}),"删除仓库"]})]})]})]}),d===P.id&&c.jsxs("div",{className:"mt-2 flex items-center justify-between rounded-md border border-red-500/20 bg-red-500/5 px-3 py-2",children:[c.jsx("span",{className:"text-xs text-red-500",children:"确认删除此仓库?"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>{a(P.id),f(null)},className:"flex h-6 items-center gap-1 rounded border border-red-500/30 px-2 text-xs text-red-500 transition-colors hover:bg-red-500/10",children:[c.jsx(fi,{className:"h-3 w-3"}),"确认"]}),c.jsx("button",{type:"button",onClick:()=>f(null),className:"flex h-6 items-center gap-1 rounded border border-line px-2 text-xs text-fg-4 transition-colors hover:bg-elevated",children:"取消"})]})]}),P.worktreeEnabled&&c.jsx(GEe,{repoId:P.id})]},P.id)})}),c.jsxs("p",{className:"mt-3 text-xs text-fg-5",children:[t.length," 个仓库"]}),o&&c.jsx(YEe,{onClose:()=>u(!1)}),N&&c.jsx(qEe,{repoId:N.id,repoName:N.name,onClose:()=>_(null)})]})}function KEe(){return c.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:c.jsx("div",{className:"mx-auto max-w-4xl",children:c.jsx(rB,{})})})}/*! Capacitor: https://capacitorjs.com/ - MIT License */var Sc;(function(e){e.Unimplemented="UNIMPLEMENTED",e.Unavailable="UNAVAILABLE"})(Sc||(Sc={}));class jv extends Error{constructor(t,n,r){super(t),this.message=t,this.code=n,this.data=r}}const VEe=e=>{var t,n;return e!=null&&e.androidBridge?"android":!((n=(t=e==null?void 0:e.webkit)===null||t===void 0?void 0:t.messageHandlers)===null||n===void 0)&&n.bridge?"ios":"web"},WEe=e=>{const t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},a=()=>t!==null?t.name:VEe(e),i=()=>a()!=="web",o=p=>{const b=f.get(p);return!!(b!=null&&b.platforms.has(a())||u(p))},u=p=>{var b;return(b=n.PluginHeaders)===null||b===void 0?void 0:b.find(x=>x.name===p)},d=p=>e.console.error(p),f=new Map,m=(p,b={})=>{const x=f.get(p);if(x)return console.warn(`Capacitor plugin "${p}" already registered. Cannot register plugins twice.`),x.proxy;const E=a(),N=u(p);let _;const S=async()=>(!_&&E in b?_=typeof b[E]=="function"?_=await b[E]():_=b[E]:t!==null&&!_&&"web"in b&&(_=typeof b.web=="function"?_=await b.web():_=b.web),_),C=(F,P)=>{var L,B;if(N){const Y=N==null?void 0:N.methods.find(re=>P===re.name);if(Y)return Y.rtype==="promise"?re=>n.nativePromise(p,P.toString(),re):(re,X)=>n.nativeCallback(p,P.toString(),re,X);if(F)return(L=F[P])===null||L===void 0?void 0:L.bind(F)}else{if(F)return(B=F[P])===null||B===void 0?void 0:B.bind(F);throw new jv(`"${p}" plugin is not implemented on ${E}`,Sc.Unimplemented)}},A=F=>{let P;const L=(...B)=>{const Y=S().then(re=>{const X=C(re,F);if(X){const K=X(...B);return P=K==null?void 0:K.remove,K}else throw new jv(`"${p}.${F}()" is not implemented on ${E}`,Sc.Unimplemented)});return F==="addListener"&&(Y.remove=async()=>P()),Y};return L.toString=()=>`${F.toString()}() { [capacitor code] }`,Object.defineProperty(L,"name",{value:F,writable:!1,configurable:!1}),L},I=A("addListener"),O=A("removeListener"),k=(F,P)=>{const L=I({eventName:F},P),B=async()=>{const re=await L;O({eventName:F,callbackId:re},P)},Y=new Promise(re=>L.then(()=>re({remove:B})));return Y.remove=async()=>{console.warn("Using addListener() without 'await' is deprecated."),await B()},Y},j=new Proxy({},{get(F,P){switch(P){case"$$typeof":return;case"toJSON":return()=>({});case"addListener":return N?k:I;case"removeListener":return O;default:return A(P)}}});return r[p]=j,f.set(p,{name:p,proxy:j,platforms:new Set([...Object.keys(b),...N?[E]:[]])}),j};return n.convertFileSrc||(n.convertFileSrc=p=>p),n.getPlatform=a,n.handleError=d,n.isNativePlatform=i,n.isPluginAvailable=o,n.registerPlugin=m,n.Exception=jv,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},XEe=e=>e.Capacitor=WEe(e),Wg=XEe(typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}),ub=Wg.registerPlugin;class sw{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(t,n){let r=!1;this.listeners[t]||(this.listeners[t]=[],r=!0),this.listeners[t].push(n);const i=this.windowListeners[t];i&&!i.registered&&this.addWindowListener(i),r&&this.sendRetainedArgumentsForEvent(t);const o=async()=>this.removeListener(t,n);return Promise.resolve({remove:o})}async removeAllListeners(){this.listeners={};for(const t in this.windowListeners)this.removeWindowListener(this.windowListeners[t]);this.windowListeners={}}notifyListeners(t,n,r){const a=this.listeners[t];if(!a){if(r){let i=this.retainedEventArguments[t];i||(i=[]),i.push(n),this.retainedEventArguments[t]=i}return}a.forEach(i=>i(n))}hasListeners(t){var n;return!!(!((n=this.listeners[t])===null||n===void 0)&&n.length)}registerWindowListener(t,n){this.windowListeners[n]={registered:!1,windowEventName:t,pluginEventName:n,handler:r=>{this.notifyListeners(n,r)}}}unimplemented(t="not implemented"){return new Wg.Exception(t,Sc.Unimplemented)}unavailable(t="not available"){return new Wg.Exception(t,Sc.Unavailable)}async removeListener(t,n){const r=this.listeners[t];if(!r)return;const a=r.indexOf(n);a!==-1&&this.listeners[t].splice(a,1),this.listeners[t].length||this.removeWindowListener(this.windowListeners[t])}addWindowListener(t){window.addEventListener(t.windowEventName,t.handler),t.registered=!0}removeWindowListener(t){t&&(window.removeEventListener(t.windowEventName,t.handler),t.registered=!1)}sendRetainedArgumentsForEvent(t){const n=this.retainedEventArguments[t];n&&(delete this.retainedEventArguments[t],n.forEach(r=>{this.notifyListeners(t,r)}))}}const OI=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),II=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent);class QEe extends sw{async getCookies(){const t=document.cookie,n={};return t.split(";").forEach(r=>{if(r.length<=0)return;let[a,i]=r.replace(/=/,"CAP_COOKIE").split("CAP_COOKIE");a=II(a).trim(),i=II(i).trim(),n[a]=i}),n}async setCookie(t){try{const n=OI(t.key),r=OI(t.value),a=t.expires?`; expires=${t.expires.replace("expires=","")}`:"",i=(t.path||"/").replace("path=",""),o=t.url!=null&&t.url.length>0?`domain=${t.url}`:"";document.cookie=`${n}=${r||""}${a}; path=${i}; ${o};`}catch(n){return Promise.reject(n)}}async deleteCookie(t){try{document.cookie=`${t.key}=; Max-Age=0`}catch(n){return Promise.reject(n)}}async clearCookies(){try{const t=document.cookie.split(";")||[];for(const n of t)document.cookie=n.replace(/^ +/,"").replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)}catch(t){return Promise.reject(t)}}async clearAllCookies(){try{await this.clearCookies()}catch(t){return Promise.reject(t)}}}ub("CapacitorCookies",{web:()=>new QEe});const ZEe=async e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const a=r.result;t(a.indexOf(",")>=0?a.split(",")[1]:a)},r.onerror=a=>n(a),r.readAsDataURL(e)}),JEe=(e={})=>{const t=Object.keys(e);return Object.keys(e).map(a=>a.toLocaleLowerCase()).reduce((a,i,o)=>(a[i]=e[t[o]],a),{})},eNe=(e,t=!0)=>e?Object.entries(e).reduce((r,a)=>{const[i,o]=a;let u,d;return Array.isArray(o)?(d="",o.forEach(f=>{u=t?encodeURIComponent(f):f,d+=`${i}=${u}&`}),d.slice(0,-1)):(u=t?encodeURIComponent(o):o,d=`${i}=${u}`),`${r}&${d}`},"").substr(1):null,tNe=(e,t={})=>{const n=Object.assign({method:e.method||"GET",headers:e.headers},t),a=JEe(e.headers)["content-type"]||"";if(typeof e.data=="string")n.body=e.data;else if(a.includes("application/x-www-form-urlencoded")){const i=new URLSearchParams;for(const[o,u]of Object.entries(e.data||{}))i.set(o,u);n.body=i.toString()}else if(a.includes("multipart/form-data")||e.data instanceof FormData){const i=new FormData;if(e.data instanceof FormData)e.data.forEach((u,d)=>{i.append(d,u)});else for(const u of Object.keys(e.data))i.append(u,e.data[u]);n.body=i;const o=new Headers(n.headers);o.delete("content-type"),n.headers=o}else(a.includes("application/json")||typeof e.data=="object")&&(n.body=JSON.stringify(e.data));return n};class nNe extends sw{async request(t){const n=tNe(t,t.webFetchExtra),r=eNe(t.params,t.shouldEncodeUrlParams),a=r?`${t.url}?${r}`:t.url,i=await fetch(a,n),o=i.headers.get("content-type")||"";let{responseType:u="text"}=i.ok?t:{};o.includes("application/json")&&(u="json");let d,f;switch(u){case"arraybuffer":case"blob":f=await i.blob(),d=await ZEe(f);break;case"json":d=await i.json();break;case"document":case"text":default:d=await i.text()}const m={};return i.headers.forEach((p,b)=>{m[b]=p}),{data:d,headers:m,status:i.status,url:i.url}}async get(t){return this.request(Object.assign(Object.assign({},t),{method:"GET"}))}async post(t){return this.request(Object.assign(Object.assign({},t),{method:"POST"}))}async put(t){return this.request(Object.assign(Object.assign({},t),{method:"PUT"}))}async patch(t){return this.request(Object.assign(Object.assign({},t),{method:"PATCH"}))}async delete(t){return this.request(Object.assign(Object.assign({},t),{method:"DELETE"}))}}ub("CapacitorHttp",{web:()=>new nNe});var RI;(function(e){e.Dark="DARK",e.Light="LIGHT",e.Default="DEFAULT"})(RI||(RI={}));var MI;(function(e){e.StatusBar="StatusBar",e.NavigationBar="NavigationBar"})(MI||(MI={}));class rNe extends sw{async setStyle(){this.unavailable("not available for web")}async setAnimation(){this.unavailable("not available for web")}async show(){this.unavailable("not available for web")}async hide(){this.unavailable("not available for web")}}ub("SystemBars",{web:()=>new rNe});const aNe="modulepreload",iNe=function(e){return"/"+e},DI={},sNe=function(t,n,r){let a=Promise.resolve();if(n&&n.length>0){let o=function(f){return Promise.all(f.map(m=>Promise.resolve(m).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const u=document.querySelector("meta[property=csp-nonce]"),d=(u==null?void 0:u.nonce)||(u==null?void 0:u.getAttribute("nonce"));a=o(n.map(f=>{if(f=iNe(f),f in DI)return;DI[f]=!0;const m=f.endsWith(".css"),p=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${f}"]${p}`))return;const b=document.createElement("link");if(b.rel=m?"stylesheet":aNe,m||(b.as="script"),b.crossOrigin="",b.href=f,d&&b.setAttribute("nonce",d),document.head.appendChild(b),m)return new Promise((x,E)=>{b.addEventListener("load",x),b.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${f}`)))})}))}function i(o){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=o,window.dispatchEvent(u),!u.defaultPrevented)throw o}return a.then(o=>{for(const u of o||[])u.status==="rejected"&&i(u.reason);return t().catch(i)})},Gu=ub("SpeechRecognition",{web:()=>sNe(()=>import("./web-bl6X0lUC.js"),[]).then(e=>new e.SpeechRecognitionWeb)});function oNe(e,t){const n=e.length,r=new ArrayBuffer(44+n*2),a=new DataView(r),i=(o,u)=>{for(let d=0;d<u.length;d++)a.setUint8(o+d,u.charCodeAt(d))};i(0,"RIFF"),a.setUint32(4,36+n*2,!0),i(8,"WAVE"),i(12,"fmt "),a.setUint32(16,16,!0),a.setUint16(20,1,!0),a.setUint16(22,1,!0),a.setUint32(24,t,!0),a.setUint32(28,t*2,!0),a.setUint16(32,2,!0),a.setUint16(34,16,!0),i(36,"data"),a.setUint32(40,n*2,!0);for(let o=0;o<n;o++){const u=Math.max(-1,Math.min(1,e[o]));a.setInt16(44+o*2,u<0?u*32768:u*32767,!0)}return new Blob([r],{type:"audio/wav"})}const mE=Wg.isNativePlatform(),Lv=!mE&&typeof window<"u"?window.SpeechRecognition??window.webkitSpeechRecognition:void 0,Pv=16e3;function lNe(e="zh-CN"){const[t,n]=y.useState(!1),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(null),[f,m]=y.useState(0),[p,b]=y.useState("idle"),x=y.useRef(null),E=y.useRef(!1),N=y.useRef([]),_=y.useRef(!1),S=y.useRef(null),C=y.useRef(!1),A=y.useRef(""),I=y.useRef(null),O=y.useRef(null),k=y.useRef(null),j=y.useRef([]),F=y.useRef(!1),P=!0,L=y.useCallback(async()=>{var M,le,oe;(M=k.current)==null||M.disconnect(),(le=O.current)==null||le.getTracks().forEach(ne=>ne.stop()),await((oe=I.current)==null?void 0:oe.close().catch(()=>{}));const H=j.current;if(j.current=[],k.current=null,O.current=null,I.current=null,H.length===0||F.current){n(!1),b("idle");return}o("识别中…"),b("recognizing");const G=H.reduce((ne,ae)=>ne+ae.length,0),Q=new Float32Array(G);let D=0;for(const ne of H)Q.set(ne,D),D+=ne.length;const z=oNe(Q,Pv),$=new FormData;$.append("audio",z,"recording.wav");try{const ne=await fetch("/api/transcribe",{method:"POST",body:$});if(F.current)return;if(ne.ok){const{text:ae}=await ne.json();ae?(a(ae),b("done")):b("idle")}else{const ae=await ne.json().catch(()=>({error:`HTTP ${ne.status}`}));d(ae.error??`HTTP ${ne.status}`),b("idle")}}catch(ne){d(`语音识别失败:${ne instanceof Error?ne.message:String(ne)}`),b("idle")}finally{o(""),n(!1)}},[]),B=y.useCallback(async()=>{if(E.current=!0,S.current&&(clearTimeout(S.current),S.current=null),mE){await Gu.stop().catch(()=>{});for(const H of N.current)await H.remove().catch(()=>{});N.current=[],n(!1),o("")}else x.current?x.current.stop():I.current?await L():(n(!1),b("idle"))},[L]),Y=y.useCallback(async()=>{var D;F.current=!1,a(""),o(""),d(null),b("idle");const{available:H}=await Gu.available();if(!H){d("当前设备不支持语音识别");return}if((await Gu.requestPermissions()).speechRecognition!=="granted"){d("请允许语音识别权限");return}const Q=[];Q.push(await Gu.addListener("partialResults",z=>{o(z.matches[0]??"")})),Q.push(await Gu.addListener("listeningState",z=>{const $=z.status==="started";n($),$&&b("recording"),$||o("")})),N.current=Q;try{const z=await Gu.start({language:e,partialResults:!0,maxResults:1});(D=z.matches)!=null&&D.length&&a($=>{var M;return $+((M=z.matches)==null?void 0:M.join(""))})}catch(z){d(`语音识别错误:${z instanceof Error?z.message:String(z)}`);for(const $ of Q)await $.remove().catch(()=>{});N.current=[]}},[e]),re=y.useCallback(()=>{if(!Lv)return!1;F.current=!1,a(""),o(""),A.current="",d(null),b("idle"),E.current=!1;const H=new Lv;H.lang=e,H.continuous=!0,H.interimResults=!0,H.maxAlternatives=1,H.onstart=()=>{n(!0),b("recording"),_.current=!1,S.current=setTimeout(()=>{!_.current&&!E.current&&(C.current=!0,E.current=!0,H.stop(),d("语音识别服务不可用(Chrome/Edge 需连接 Google 服务器),下次将使用服务端识别"))},5e3)},H.onresult=G=>{_.current=!0,S.current&&(clearTimeout(S.current),S.current=null);let Q="",D="";for(let z=G.resultIndex;z<G.results.length;z++){const $=G.results[z][0].transcript;G.results[z].isFinal?Q+=$:D+=$}Q&&a(z=>z+Q),o(D),A.current=D},H.onerror=G=>{switch(G.error!=="no-speech"&&G.error!=="aborted"&&(E.current=!0),G.error){case"not-allowed":d("请允许麦克风权限");break;case"network":d("网络错误,请检查连接");break;case"no-speech":case"aborted":return;default:d(`语音识别错误:${G.error}`)}},H.onend=()=>{if(E.current&&A.current&&a(G=>G+A.current),o(""),A.current="",!E.current)try{H.start();return}catch{}n(!1),x.current=null},x.current=H;try{return H.start(),!0}catch{return!1}},[e]),X=y.useCallback(async()=>{F.current=!1,a(""),o(""),d(null),b("idle");try{const z=await fetch("/api/transcribe/status"),{available:$}=await z.json();if(!$){d("语音识别服务未就绪,请稍后重试");return}}catch{d("无法连接语音识别服务");return}let H;try{H=await navigator.mediaDevices.getUserMedia({audio:{sampleRate:Pv,channelCount:1}})}catch{d("请允许麦克风权限");return}const G=new AudioContext({sampleRate:Pv}),Q=G.createMediaStreamSource(H),D=G.createScriptProcessor(4096,1,1);j.current=[],D.onaudioprocess=z=>{j.current.push(new Float32Array(z.inputBuffer.getChannelData(0)))},Q.connect(D),D.connect(G.destination),I.current=G,O.current=H,k.current=D,n(!0),b("recording")},[]),K=y.useCallback(()=>{mE?Y():Lv&&!C.current&&re()||X()},[Y,re,X]);y.useEffect(()=>{if(!t){m(0);return}if(x.current)return;let H=!1,G=null,Q=null,D=0;return(async()=>{try{if(G=await navigator.mediaDevices.getUserMedia({audio:!0}),H){G.getTracks().forEach(ne=>ne.stop());return}Q=new AudioContext;const z=Q.createMediaStreamSource(G),$=Q.createAnalyser();$.fftSize=256,z.connect($);const M=new Uint8Array($.frequencyBinCount);let le=0;const oe=()=>{if(H)return;$.getByteFrequencyData(M);const ne=performance.now();if(ne-le>80){let ae=0;for(let De=0;De<M.length;De++)ae+=M[De];m(ae/(M.length*255)),le=ne}D=requestAnimationFrame(oe)};D=requestAnimationFrame(oe)}catch{}})(),()=>{H=!0,cancelAnimationFrame(D),G==null||G.getTracks().forEach(z=>z.stop()),Q==null||Q.close().catch(()=>{}),m(0)}},[t]),y.useEffect(()=>{!t&&p==="recording"&&b(r?"done":"idle")},[t,p,r]),y.useEffect(()=>()=>{var H,G,Q,D;E.current=!0,(H=x.current)==null||H.stop(),(G=k.current)==null||G.disconnect(),(Q=O.current)==null||Q.getTracks().forEach(z=>z.stop()),(D=I.current)==null||D.close().catch(()=>{});for(const z of N.current)z.remove().catch(()=>{})},[]);const V=y.useCallback(()=>{F.current=!0,a(""),o(""),A.current="",b("idle")},[]);return{isSupported:P,isListening:t,phase:p,transcript:r,interimTranscript:i,error:u,volumeLevel:f,start:K,stop:B,resetTranscript:V}}const uNe=240,cNe=1e3;function aB(e){const t=lNe(),[n,r]=y.useState(""),[a,i]=y.useState(0),o=y.useRef(null),u=y.useRef(null),d=y.useRef(0);y.useEffect(()=>(t.phase==="recording"?(d.current=Date.now(),i(0),u.current=setInterval(()=>{i(Math.floor((Date.now()-d.current)/1e3))},cNe)):u.current&&(clearInterval(u.current),u.current=null),()=>{u.current&&(clearInterval(u.current),u.current=null)}),[t.phase]),y.useEffect(()=>{t.phase==="done"&&(r(t.transcript),requestAnimationFrame(()=>{const b=o.current;b&&(b.focus(),b.setSelectionRange(b.value.length,b.value.length))}))},[t.phase,t.transcript]),y.useLayoutEffect(()=>{if(t.phase!=="done")return;const b=o.current;b&&(b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,uNe)}px`)},[t.phase]);const f=y.useCallback(()=>{t.stop(),t.resetTranscript(),r("")},[t]),m=y.useCallback(async()=>{const b=n.trim();if(!b){f();return}await e(b)!==!1&&(t.resetTranscript(),r(""))},[n,e,f,t]);y.useEffect(()=>{if(t.phase==="idle")return;const b=x=>{if(x.key==="Escape"&&t.phase!=="recognizing"){x.preventDefault(),f();return}if(t.phase==="done"&&x.key==="Enter"&&(x.metaKey||x.ctrlKey)){if(x.isComposing)return;x.preventDefault(),m()}};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[t.phase,f,m]);const p=y.useCallback(b=>{b.nativeEvent.isComposing||b.keyCode===229||b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),m())},[m]);return{stt:t,editText:n,setEditText:r,elapsed:a,textareaRef:o,cancel:f,confirm:m,handleTextareaKeyDown:p}}const iB=["image/png","image/jpeg","image/gif","image/webp"];let jI=0;function sB(e){return e.split(`
|
|
652
|
+
在此编写该仓库的 Agent 指令…`}),c.jsxs("div",{className:"mt-4 flex items-center justify-end gap-2",children:[c.jsx("button",{type:"button",onClick:n,className:"rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"关闭"}),c.jsxs("button",{type:"button",onClick:()=>void x(),disabled:f||!E,className:"flex items-center gap-1.5 rounded-lg bg-blue-600 px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 disabled:opacity-40",children:[c.jsx(sh,{className:"h-3.5 w-3.5"}),f?"保存中…":"保存"]})]})]})})}const fE=1024,hE=fE*1024,CI=hE*1024;function kI(e){return!e||e<=0?"0 B":e<fE?`${e} B`:e<hE?`${(e/fE).toFixed(1)} KB`:e<CI?`${(e/hE).toFixed(1)} MB`:`${(e/CI).toFixed(2)} GB`}const Dv="ws/";function GEe({repoId:e}){const[t,n]=y.useState(!1),[r,a]=y.useState(null),[i,o]=y.useState(!1),[u,d]=y.useState(null),{data:f,loading:m,error:p,reload:b}=lc(()=>m$(e),[e,t],{skip:!t,showErrorToast:!1,errorMessage:"加载失败"}),x=u??p,E=async C=>{a(C),d(null);try{await p$(e,C),b()}catch(A){d(A instanceof Li?A.message:"删除失败")}a(null)},N=async()=>{o(!0),d(null);try{await g$(e),b()}catch(C){d(C instanceof Li?C.message:"清理失败")}o(!1)},_=(f==null?void 0:f.length)??0,S=(f==null?void 0:f.reduce((C,A)=>C+(A.diskUsage||0),0))??0;return c.jsxs("div",{className:"mt-3 border-t border-line pt-3",children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>n(C=>!C),className:"flex min-w-0 flex-1 items-center gap-1.5 text-left text-xs font-medium text-fg-3 transition-colors hover:text-fg-2",children:[t?c.jsx(OE,{className:"h-3 w-3 shrink-0"}):c.jsx(kr,{className:"h-3 w-3 shrink-0"}),c.jsx(Gl,{className:"h-3 w-3 shrink-0 text-fg-5"}),c.jsx("span",{children:"工作空间"}),f!==null&&c.jsxs("span",{className:"text-fg-5",children:["(",_,") · ",kI(S)]})]}),t&&_>0&&c.jsxs("button",{type:"button",onClick:()=>void N(),disabled:i,className:"flex h-6 shrink-0 items-center gap-1 rounded border border-line px-2 text-xs text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2 disabled:opacity-50",children:[i?c.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):null,"清理已合并"]})]}),t&&c.jsxs("div",{className:"mt-2",children:[x&&c.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2 rounded border border-red-500/30 bg-red-500/5 px-2 py-1 text-xs text-red-600",children:[c.jsx("span",{className:"truncate",children:x}),c.jsx("button",{type:"button",onClick:()=>d(null),className:"shrink-0 rounded p-0.5 transition-colors hover:bg-red-500/10",children:c.jsx(At,{className:"h-3 w-3"})})]}),m&&f===null?c.jsx("div",{className:"flex justify-center py-3",children:c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-fg-5 border-t-transparent"})}):_===0?c.jsx("p",{className:"py-2 text-center text-xs text-fg-5",children:"暂无工作空间"}):c.jsx("ul",{className:"space-y-1",children:f==null?void 0:f.map(C=>{const A=C.branch.startsWith(Dv),I=A?C.branch.slice(Dv.length):C.branch,O=C.status==="active"?"bg-emerald-500/10 text-emerald-600":C.status==="idle"?"bg-amber-500/10 text-amber-600":"bg-fg-6/30 text-fg-4",k=C.status==="active"?"活跃":C.status==="idle"?"空闲":C.status==="merged"?"已合并":C.status==="stale"?"陈旧":C.status,j=C.status!=="active";return c.jsxs("li",{className:"flex items-center gap-2 rounded-md border border-line bg-elevated/40 px-2 py-1.5 text-xs",children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5",children:[C.running&&C.port&&c.jsx("span",{className:"h-1.5 w-1.5 shrink-0 rounded-full bg-emerald-500",title:`运行中 :${C.port}`}),c.jsxs("span",{className:"min-w-0 truncate font-mono",children:[A&&c.jsx("span",{className:"text-fg-5",children:Dv}),c.jsx("span",{className:"text-fg-2",children:I})]})]}),c.jsx("span",{className:ie("shrink-0 rounded-full px-1.5 py-0.5 text-[10px] font-medium",O),children:k}),c.jsxs("span",{className:"flex shrink-0 items-center gap-0.5 text-fg-5",children:[c.jsx(Qz,{className:"h-2.5 w-2.5"}),kI(C.diskUsage)]}),c.jsx("button",{type:"button",onClick:()=>void E(C.id),disabled:!j||r===C.id,title:j?"删除工作空间":"活跃工作空间无法删除",className:"flex h-5 w-5 shrink-0 items-center justify-center rounded text-fg-5 transition-colors hover:bg-red-500/10 hover:text-red-500 disabled:cursor-not-allowed disabled:opacity-30 disabled:hover:bg-transparent disabled:hover:text-fg-5",children:r===C.id?c.jsx("span",{className:"inline-block h-2.5 w-2.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsx(a0,{className:"h-3 w-3"})})]},C.id)})})]})]})}function rB(){const e=zn(),t=We(P=>P.repos),n=We(P=>P.activeRepoId),r=We(P=>P.setActiveRepo),a=We(P=>P.removeRepo),i=We(P=>P.loadRepos),[o,u]=y.useState(!1),[d,f]=y.useState(null),[m,p]=y.useState(null),[b,x]=y.useState(null),E=ar(P=>P.addToast),[N,_]=y.useState(null),[S,C]=y.useState(null),A=y.useRef(null),[I,O]=y.useState(null);y.useEffect(()=>{FE().then(P=>O(new Set(P.map(L=>L.host.toLowerCase())))).catch(()=>{})},[]);const k=y.useMemo(()=>{if(!I)return new Set;const P=new Set;for(const L of t){const B=nB(L.gitUrl);B&&!I.has(B.toLowerCase())&&P.add(L.id)}return P},[t,I]);y.useEffect(()=>{if(!S)return;const P=L=>{A.current&&!A.current.contains(L.target)&&C(null)};return document.addEventListener("mousedown",P),()=>document.removeEventListener("mousedown",P)},[S]);const j=async(P,L)=>{p(P);try{L?await c$(P):await u$(P),await i()}catch{}p(null)},F=async P=>{x(P);try{const L=await h$(P);await i();const B=L.alreadyUpToDate?"info":"success";E(L.summary,B,void 0,{persistent:!0})}catch(L){let B="拉取失败";if(L instanceof Li)try{B=JSON.parse(L.message).error??L.message}catch{B=L.message}E(B,"error",void 0,{persistent:!0})}x(null)};return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"mb-6 flex items-center justify-between gap-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("h1",{className:"text-lg font-semibold text-fg",children:"仓库管理"}),c.jsx("p",{className:"mt-0.5 text-sm text-fg-4",children:"管理代码仓库,每个仓库对应一个独立的 Agent 运行环境"})]}),c.jsxs("button",{type:"button",onClick:()=>u(!0),className:"flex shrink-0 items-center gap-1.5 rounded-lg bg-blue-600 px-3 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-500 md:px-4",children:[c.jsx(ua,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden md:inline",children:"添加仓库"})]})]}),t.length===0?c.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-xl border border-dashed border-line-hard py-16 text-center",children:[c.jsx("div",{className:"rounded-full bg-elevated p-3",children:c.jsx(ua,{className:"h-6 w-6 text-fg-4"})}),c.jsx("p",{className:"text-sm font-medium text-fg-3",children:"暂无代码仓库"}),c.jsx("p",{className:"text-xs text-fg-5",children:"添加一个本地仓库开始使用"}),c.jsx("button",{type:"button",onClick:()=>u(!0),className:"mt-2 rounded-lg border border-line px-4 py-2 text-sm text-fg-3 transition-colors hover:bg-elevated hover:text-fg",children:"添加仓库"})]}):c.jsx("div",{className:"grid grid-cols-1 gap-3 md:grid-cols-2",children:t.map((P,L)=>{const B=P.id===n;return c.jsxs("div",{className:ie("rounded-xl border p-4 transition-colors",B?"border-blue-500/40 bg-blue-500/5":"border-line"),children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>r(P.id),className:"flex min-w-0 items-center gap-2 text-left",children:[B?c.jsx(ql,{className:"h-4 w-4 shrink-0 text-blue-500"}):c.jsx(pz,{className:"h-4 w-4 shrink-0 text-fg-5"}),c.jsx("span",{className:ie("truncate font-medium",B?"text-fg":"text-fg-2"),children:P.name})]}),c.jsxs("span",{className:ie("inline-flex shrink-0 items-center gap-1.5 rounded-full px-2 py-0.5 text-xs font-medium",P.running?"bg-emerald-500/10 text-emerald-600":"bg-fg-6/30 text-fg-4"),children:[c.jsx("span",{className:ie("h-1.5 w-1.5 rounded-full",P.running?"bg-emerald-500":"bg-fg-5")}),P.running?"运行中":"已停止"]})]}),c.jsxs("dl",{className:"mt-3 space-y-1 font-mono text-xs text-fg-4",children:[c.jsxs("div",{className:"flex gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"Git"}),c.jsx("dd",{className:"min-w-0 truncate",children:P.gitUrl})]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"路径"}),c.jsxs("dd",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsx("span",{className:"truncate",children:P.localPath}),c.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(P.localPath),title:"复制路径",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:text-fg-3",children:c.jsx($p,{className:"h-3 w-3"})})]})]}),P.running&&P.port&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("dt",{className:"shrink-0 text-fg-5",children:"直连"}),c.jsxs("dd",{className:"flex min-w-0 items-center gap-1.5",children:[c.jsxs("a",{href:`http://127.0.0.1:${P.port}`,target:"_blank",rel:"noopener noreferrer",className:"truncate text-blue-500 hover:underline",children:["127.0.0.1:",P.port]}),c.jsx("button",{type:"button",onClick:()=>void navigator.clipboard.writeText(`http://127.0.0.1:${P.port}`),title:"复制链接",className:"shrink-0 rounded p-0.5 text-fg-5 transition-colors hover:text-fg-3",children:c.jsx($p,{className:"h-3 w-3"})})]})]})]}),k.has(P.id)&&c.jsxs("button",{type:"button",onClick:()=>e("/settings"),className:"mt-2 flex w-full items-center gap-1.5 rounded-md bg-amber-500/10 px-2.5 py-1.5 text-left text-xs text-amber-600 transition-colors hover:bg-amber-500/15",children:[c.jsx(On,{className:"h-3.5 w-3.5 shrink-0"}),c.jsx("span",{children:"缺少 Git 源站凭证,Issue/PR 同步不可用"})]}),c.jsxs("div",{className:"mt-3 flex items-center gap-2",children:[c.jsx("button",{type:"button",onClick:()=>void F(P.id),disabled:b===P.id,className:"flex h-8 shrink-0 items-center justify-center gap-1.5 rounded-md border border-blue-500/30 px-2.5 text-xs font-medium text-blue-600 transition-colors hover:bg-blue-500/10 disabled:opacity-50",children:b===P.id?c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):c.jsxs(c.Fragment,{children:[c.jsx($F,{className:"h-3 w-3"}),"拉取"]})}),c.jsx("button",{type:"button",onClick:()=>void j(P.id,P.running),disabled:m===P.id,className:ie("flex h-8 flex-1 items-center justify-center gap-1.5 rounded-md border text-xs font-medium transition-colors disabled:opacity-50",P.running?"border-amber-500/30 text-amber-600 hover:bg-amber-500/10":"border-emerald-500/30 text-emerald-600 hover:bg-emerald-500/10"),children:m===P.id?c.jsx("span",{className:"inline-block h-3.5 w-3.5 animate-spin rounded-full border-2 border-current border-t-transparent"}):P.running?c.jsxs(c.Fragment,{children:[c.jsx(Vv,{className:"h-3 w-3 fill-current"}),"停止"]}):c.jsxs(c.Fragment,{children:[c.jsx(LE,{className:"h-3 w-3 fill-current"}),"启动"]})}),c.jsxs("div",{className:"relative",ref:S===P.id?A:void 0,children:[c.jsx("button",{type:"button","data-guide":L===0?"repo-overflow-btn":void 0,onClick:()=>C(S===P.id?null:P.id),className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-md border border-line text-fg-4 transition-colors hover:bg-elevated hover:text-fg-2",children:c.jsx(IE,{className:"h-4 w-4"})}),S===P.id&&c.jsxs("div",{"data-guide":L===0?"repo-overflow-dropdown":void 0,className:"absolute right-0 top-full z-20 mt-1 min-w-[160px] overflow-hidden rounded-lg border border-line bg-elevated shadow-lg",children:[c.jsx("button",{type:"button",className:ie("flex w-full items-center gap-2 px-3 py-2 text-left text-xs transition-colors hover:bg-base/60",P.runtimeType==="claude-code"?"text-orange-500":"text-sky-500"),onClick:async()=>{C(null);const Y=P.runtimeType==="claude-code"?"opencode":"claude-code";await x$(P.id,Y),i()},children:P.runtimeType==="claude-code"?"Claude → OpenCode":"OpenCode → Claude"}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",onClick:async()=>{C(null),await b$(P.id,!P.worktreeEnabled),i()},children:[c.jsx(Gl,{className:"h-3 w-3"}),c.jsx("span",{children:"Worktree"}),c.jsx("span",{className:ie("ml-auto text-[10px]",P.worktreeEnabled?"text-violet-500":"text-fg-5"),children:P.worktreeEnabled?"已开启":"已关闭"})]}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-fg-3 transition-colors hover:bg-base/60",onClick:()=>{C(null),_({id:P.id,name:P.name})},children:[c.jsx(Io,{className:"h-3 w-3"}),"配置"]}),c.jsx("div",{className:"my-0.5 border-t border-line"}),c.jsxs("button",{type:"button",className:"flex w-full items-center gap-2 px-3 py-2 text-left text-xs text-red-500 transition-colors hover:bg-red-500/10",onClick:()=>{C(null),f(P.id)},children:[c.jsx(a0,{className:"h-3 w-3"}),"删除仓库"]})]})]})]}),d===P.id&&c.jsxs("div",{className:"mt-2 flex items-center justify-between rounded-md border border-red-500/20 bg-red-500/5 px-3 py-2",children:[c.jsx("span",{className:"text-xs text-red-500",children:"确认删除此仓库?"}),c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("button",{type:"button",onClick:()=>{a(P.id),f(null)},className:"flex h-6 items-center gap-1 rounded border border-red-500/30 px-2 text-xs text-red-500 transition-colors hover:bg-red-500/10",children:[c.jsx(fi,{className:"h-3 w-3"}),"确认"]}),c.jsx("button",{type:"button",onClick:()=>f(null),className:"flex h-6 items-center gap-1 rounded border border-line px-2 text-xs text-fg-4 transition-colors hover:bg-elevated",children:"取消"})]})]}),P.worktreeEnabled&&c.jsx(GEe,{repoId:P.id})]},P.id)})}),c.jsxs("p",{className:"mt-3 text-xs text-fg-5",children:[t.length," 个仓库"]}),o&&c.jsx(YEe,{onClose:()=>u(!1)}),N&&c.jsx(qEe,{repoId:N.id,repoName:N.name,onClose:()=>_(null)})]})}function KEe(){return c.jsx("div",{className:"flex-1 overflow-y-auto p-6",children:c.jsx("div",{className:"mx-auto max-w-4xl",children:c.jsx(rB,{})})})}/*! Capacitor: https://capacitorjs.com/ - MIT License */var Sc;(function(e){e.Unimplemented="UNIMPLEMENTED",e.Unavailable="UNAVAILABLE"})(Sc||(Sc={}));class jv extends Error{constructor(t,n,r){super(t),this.message=t,this.code=n,this.data=r}}const VEe=e=>{var t,n;return e!=null&&e.androidBridge?"android":!((n=(t=e==null?void 0:e.webkit)===null||t===void 0?void 0:t.messageHandlers)===null||n===void 0)&&n.bridge?"ios":"web"},WEe=e=>{const t=e.CapacitorCustomPlatform||null,n=e.Capacitor||{},r=n.Plugins=n.Plugins||{},a=()=>t!==null?t.name:VEe(e),i=()=>a()!=="web",o=p=>{const b=f.get(p);return!!(b!=null&&b.platforms.has(a())||u(p))},u=p=>{var b;return(b=n.PluginHeaders)===null||b===void 0?void 0:b.find(x=>x.name===p)},d=p=>e.console.error(p),f=new Map,m=(p,b={})=>{const x=f.get(p);if(x)return console.warn(`Capacitor plugin "${p}" already registered. Cannot register plugins twice.`),x.proxy;const E=a(),N=u(p);let _;const S=async()=>(!_&&E in b?_=typeof b[E]=="function"?_=await b[E]():_=b[E]:t!==null&&!_&&"web"in b&&(_=typeof b.web=="function"?_=await b.web():_=b.web),_),C=(F,P)=>{var L,B;if(N){const Y=N==null?void 0:N.methods.find(re=>P===re.name);if(Y)return Y.rtype==="promise"?re=>n.nativePromise(p,P.toString(),re):(re,X)=>n.nativeCallback(p,P.toString(),re,X);if(F)return(L=F[P])===null||L===void 0?void 0:L.bind(F)}else{if(F)return(B=F[P])===null||B===void 0?void 0:B.bind(F);throw new jv(`"${p}" plugin is not implemented on ${E}`,Sc.Unimplemented)}},A=F=>{let P;const L=(...B)=>{const Y=S().then(re=>{const X=C(re,F);if(X){const K=X(...B);return P=K==null?void 0:K.remove,K}else throw new jv(`"${p}.${F}()" is not implemented on ${E}`,Sc.Unimplemented)});return F==="addListener"&&(Y.remove=async()=>P()),Y};return L.toString=()=>`${F.toString()}() { [capacitor code] }`,Object.defineProperty(L,"name",{value:F,writable:!1,configurable:!1}),L},I=A("addListener"),O=A("removeListener"),k=(F,P)=>{const L=I({eventName:F},P),B=async()=>{const re=await L;O({eventName:F,callbackId:re},P)},Y=new Promise(re=>L.then(()=>re({remove:B})));return Y.remove=async()=>{console.warn("Using addListener() without 'await' is deprecated."),await B()},Y},j=new Proxy({},{get(F,P){switch(P){case"$$typeof":return;case"toJSON":return()=>({});case"addListener":return N?k:I;case"removeListener":return O;default:return A(P)}}});return r[p]=j,f.set(p,{name:p,proxy:j,platforms:new Set([...Object.keys(b),...N?[E]:[]])}),j};return n.convertFileSrc||(n.convertFileSrc=p=>p),n.getPlatform=a,n.handleError=d,n.isNativePlatform=i,n.isPluginAvailable=o,n.registerPlugin=m,n.Exception=jv,n.DEBUG=!!n.DEBUG,n.isLoggingEnabled=!!n.isLoggingEnabled,n},XEe=e=>e.Capacitor=WEe(e),Wg=XEe(typeof globalThis<"u"?globalThis:typeof self<"u"?self:typeof window<"u"?window:typeof global<"u"?global:{}),ub=Wg.registerPlugin;class sw{constructor(){this.listeners={},this.retainedEventArguments={},this.windowListeners={}}addListener(t,n){let r=!1;this.listeners[t]||(this.listeners[t]=[],r=!0),this.listeners[t].push(n);const i=this.windowListeners[t];i&&!i.registered&&this.addWindowListener(i),r&&this.sendRetainedArgumentsForEvent(t);const o=async()=>this.removeListener(t,n);return Promise.resolve({remove:o})}async removeAllListeners(){this.listeners={};for(const t in this.windowListeners)this.removeWindowListener(this.windowListeners[t]);this.windowListeners={}}notifyListeners(t,n,r){const a=this.listeners[t];if(!a){if(r){let i=this.retainedEventArguments[t];i||(i=[]),i.push(n),this.retainedEventArguments[t]=i}return}a.forEach(i=>i(n))}hasListeners(t){var n;return!!(!((n=this.listeners[t])===null||n===void 0)&&n.length)}registerWindowListener(t,n){this.windowListeners[n]={registered:!1,windowEventName:t,pluginEventName:n,handler:r=>{this.notifyListeners(n,r)}}}unimplemented(t="not implemented"){return new Wg.Exception(t,Sc.Unimplemented)}unavailable(t="not available"){return new Wg.Exception(t,Sc.Unavailable)}async removeListener(t,n){const r=this.listeners[t];if(!r)return;const a=r.indexOf(n);a!==-1&&this.listeners[t].splice(a,1),this.listeners[t].length||this.removeWindowListener(this.windowListeners[t])}addWindowListener(t){window.addEventListener(t.windowEventName,t.handler),t.registered=!0}removeWindowListener(t){t&&(window.removeEventListener(t.windowEventName,t.handler),t.registered=!1)}sendRetainedArgumentsForEvent(t){const n=this.retainedEventArguments[t];n&&(delete this.retainedEventArguments[t],n.forEach(r=>{this.notifyListeners(t,r)}))}}const OI=e=>encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape),II=e=>e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent);class QEe extends sw{async getCookies(){const t=document.cookie,n={};return t.split(";").forEach(r=>{if(r.length<=0)return;let[a,i]=r.replace(/=/,"CAP_COOKIE").split("CAP_COOKIE");a=II(a).trim(),i=II(i).trim(),n[a]=i}),n}async setCookie(t){try{const n=OI(t.key),r=OI(t.value),a=t.expires?`; expires=${t.expires.replace("expires=","")}`:"",i=(t.path||"/").replace("path=",""),o=t.url!=null&&t.url.length>0?`domain=${t.url}`:"";document.cookie=`${n}=${r||""}${a}; path=${i}; ${o};`}catch(n){return Promise.reject(n)}}async deleteCookie(t){try{document.cookie=`${t.key}=; Max-Age=0`}catch(n){return Promise.reject(n)}}async clearCookies(){try{const t=document.cookie.split(";")||[];for(const n of t)document.cookie=n.replace(/^ +/,"").replace(/=.*/,`=;expires=${new Date().toUTCString()};path=/`)}catch(t){return Promise.reject(t)}}async clearAllCookies(){try{await this.clearCookies()}catch(t){return Promise.reject(t)}}}ub("CapacitorCookies",{web:()=>new QEe});const ZEe=async e=>new Promise((t,n)=>{const r=new FileReader;r.onload=()=>{const a=r.result;t(a.indexOf(",")>=0?a.split(",")[1]:a)},r.onerror=a=>n(a),r.readAsDataURL(e)}),JEe=(e={})=>{const t=Object.keys(e);return Object.keys(e).map(a=>a.toLocaleLowerCase()).reduce((a,i,o)=>(a[i]=e[t[o]],a),{})},eNe=(e,t=!0)=>e?Object.entries(e).reduce((r,a)=>{const[i,o]=a;let u,d;return Array.isArray(o)?(d="",o.forEach(f=>{u=t?encodeURIComponent(f):f,d+=`${i}=${u}&`}),d.slice(0,-1)):(u=t?encodeURIComponent(o):o,d=`${i}=${u}`),`${r}&${d}`},"").substr(1):null,tNe=(e,t={})=>{const n=Object.assign({method:e.method||"GET",headers:e.headers},t),a=JEe(e.headers)["content-type"]||"";if(typeof e.data=="string")n.body=e.data;else if(a.includes("application/x-www-form-urlencoded")){const i=new URLSearchParams;for(const[o,u]of Object.entries(e.data||{}))i.set(o,u);n.body=i.toString()}else if(a.includes("multipart/form-data")||e.data instanceof FormData){const i=new FormData;if(e.data instanceof FormData)e.data.forEach((u,d)=>{i.append(d,u)});else for(const u of Object.keys(e.data))i.append(u,e.data[u]);n.body=i;const o=new Headers(n.headers);o.delete("content-type"),n.headers=o}else(a.includes("application/json")||typeof e.data=="object")&&(n.body=JSON.stringify(e.data));return n};class nNe extends sw{async request(t){const n=tNe(t,t.webFetchExtra),r=eNe(t.params,t.shouldEncodeUrlParams),a=r?`${t.url}?${r}`:t.url,i=await fetch(a,n),o=i.headers.get("content-type")||"";let{responseType:u="text"}=i.ok?t:{};o.includes("application/json")&&(u="json");let d,f;switch(u){case"arraybuffer":case"blob":f=await i.blob(),d=await ZEe(f);break;case"json":d=await i.json();break;case"document":case"text":default:d=await i.text()}const m={};return i.headers.forEach((p,b)=>{m[b]=p}),{data:d,headers:m,status:i.status,url:i.url}}async get(t){return this.request(Object.assign(Object.assign({},t),{method:"GET"}))}async post(t){return this.request(Object.assign(Object.assign({},t),{method:"POST"}))}async put(t){return this.request(Object.assign(Object.assign({},t),{method:"PUT"}))}async patch(t){return this.request(Object.assign(Object.assign({},t),{method:"PATCH"}))}async delete(t){return this.request(Object.assign(Object.assign({},t),{method:"DELETE"}))}}ub("CapacitorHttp",{web:()=>new nNe});var RI;(function(e){e.Dark="DARK",e.Light="LIGHT",e.Default="DEFAULT"})(RI||(RI={}));var MI;(function(e){e.StatusBar="StatusBar",e.NavigationBar="NavigationBar"})(MI||(MI={}));class rNe extends sw{async setStyle(){this.unavailable("not available for web")}async setAnimation(){this.unavailable("not available for web")}async show(){this.unavailable("not available for web")}async hide(){this.unavailable("not available for web")}}ub("SystemBars",{web:()=>new rNe});const aNe="modulepreload",iNe=function(e){return"/"+e},DI={},sNe=function(t,n,r){let a=Promise.resolve();if(n&&n.length>0){let o=function(f){return Promise.all(f.map(m=>Promise.resolve(m).then(p=>({status:"fulfilled",value:p}),p=>({status:"rejected",reason:p}))))};document.getElementsByTagName("link");const u=document.querySelector("meta[property=csp-nonce]"),d=(u==null?void 0:u.nonce)||(u==null?void 0:u.getAttribute("nonce"));a=o(n.map(f=>{if(f=iNe(f),f in DI)return;DI[f]=!0;const m=f.endsWith(".css"),p=m?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${f}"]${p}`))return;const b=document.createElement("link");if(b.rel=m?"stylesheet":aNe,m||(b.as="script"),b.crossOrigin="",b.href=f,d&&b.setAttribute("nonce",d),document.head.appendChild(b),m)return new Promise((x,E)=>{b.addEventListener("load",x),b.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${f}`)))})}))}function i(o){const u=new Event("vite:preloadError",{cancelable:!0});if(u.payload=o,window.dispatchEvent(u),!u.defaultPrevented)throw o}return a.then(o=>{for(const u of o||[])u.status==="rejected"&&i(u.reason);return t().catch(i)})},Gu=ub("SpeechRecognition",{web:()=>sNe(()=>import("./web-DmC2q7pI.js"),[]).then(e=>new e.SpeechRecognitionWeb)});function oNe(e,t){const n=e.length,r=new ArrayBuffer(44+n*2),a=new DataView(r),i=(o,u)=>{for(let d=0;d<u.length;d++)a.setUint8(o+d,u.charCodeAt(d))};i(0,"RIFF"),a.setUint32(4,36+n*2,!0),i(8,"WAVE"),i(12,"fmt "),a.setUint32(16,16,!0),a.setUint16(20,1,!0),a.setUint16(22,1,!0),a.setUint32(24,t,!0),a.setUint32(28,t*2,!0),a.setUint16(32,2,!0),a.setUint16(34,16,!0),i(36,"data"),a.setUint32(40,n*2,!0);for(let o=0;o<n;o++){const u=Math.max(-1,Math.min(1,e[o]));a.setInt16(44+o*2,u<0?u*32768:u*32767,!0)}return new Blob([r],{type:"audio/wav"})}const mE=Wg.isNativePlatform(),Lv=!mE&&typeof window<"u"?window.SpeechRecognition??window.webkitSpeechRecognition:void 0,Pv=16e3;function lNe(e="zh-CN"){const[t,n]=y.useState(!1),[r,a]=y.useState(""),[i,o]=y.useState(""),[u,d]=y.useState(null),[f,m]=y.useState(0),[p,b]=y.useState("idle"),x=y.useRef(null),E=y.useRef(!1),N=y.useRef([]),_=y.useRef(!1),S=y.useRef(null),C=y.useRef(!1),A=y.useRef(""),I=y.useRef(null),O=y.useRef(null),k=y.useRef(null),j=y.useRef([]),F=y.useRef(!1),P=!0,L=y.useCallback(async()=>{var M,le,oe;(M=k.current)==null||M.disconnect(),(le=O.current)==null||le.getTracks().forEach(ne=>ne.stop()),await((oe=I.current)==null?void 0:oe.close().catch(()=>{}));const H=j.current;if(j.current=[],k.current=null,O.current=null,I.current=null,H.length===0||F.current){n(!1),b("idle");return}o("识别中…"),b("recognizing");const G=H.reduce((ne,ae)=>ne+ae.length,0),Q=new Float32Array(G);let D=0;for(const ne of H)Q.set(ne,D),D+=ne.length;const z=oNe(Q,Pv),$=new FormData;$.append("audio",z,"recording.wav");try{const ne=await fetch("/api/transcribe",{method:"POST",body:$});if(F.current)return;if(ne.ok){const{text:ae}=await ne.json();ae?(a(ae),b("done")):b("idle")}else{const ae=await ne.json().catch(()=>({error:`HTTP ${ne.status}`}));d(ae.error??`HTTP ${ne.status}`),b("idle")}}catch(ne){d(`语音识别失败:${ne instanceof Error?ne.message:String(ne)}`),b("idle")}finally{o(""),n(!1)}},[]),B=y.useCallback(async()=>{if(E.current=!0,S.current&&(clearTimeout(S.current),S.current=null),mE){await Gu.stop().catch(()=>{});for(const H of N.current)await H.remove().catch(()=>{});N.current=[],n(!1),o("")}else x.current?x.current.stop():I.current?await L():(n(!1),b("idle"))},[L]),Y=y.useCallback(async()=>{var D;F.current=!1,a(""),o(""),d(null),b("idle");const{available:H}=await Gu.available();if(!H){d("当前设备不支持语音识别");return}if((await Gu.requestPermissions()).speechRecognition!=="granted"){d("请允许语音识别权限");return}const Q=[];Q.push(await Gu.addListener("partialResults",z=>{o(z.matches[0]??"")})),Q.push(await Gu.addListener("listeningState",z=>{const $=z.status==="started";n($),$&&b("recording"),$||o("")})),N.current=Q;try{const z=await Gu.start({language:e,partialResults:!0,maxResults:1});(D=z.matches)!=null&&D.length&&a($=>{var M;return $+((M=z.matches)==null?void 0:M.join(""))})}catch(z){d(`语音识别错误:${z instanceof Error?z.message:String(z)}`);for(const $ of Q)await $.remove().catch(()=>{});N.current=[]}},[e]),re=y.useCallback(()=>{if(!Lv)return!1;F.current=!1,a(""),o(""),A.current="",d(null),b("idle"),E.current=!1;const H=new Lv;H.lang=e,H.continuous=!0,H.interimResults=!0,H.maxAlternatives=1,H.onstart=()=>{n(!0),b("recording"),_.current=!1,S.current=setTimeout(()=>{!_.current&&!E.current&&(C.current=!0,E.current=!0,H.stop(),d("语音识别服务不可用(Chrome/Edge 需连接 Google 服务器),下次将使用服务端识别"))},5e3)},H.onresult=G=>{_.current=!0,S.current&&(clearTimeout(S.current),S.current=null);let Q="",D="";for(let z=G.resultIndex;z<G.results.length;z++){const $=G.results[z][0].transcript;G.results[z].isFinal?Q+=$:D+=$}Q&&a(z=>z+Q),o(D),A.current=D},H.onerror=G=>{switch(G.error!=="no-speech"&&G.error!=="aborted"&&(E.current=!0),G.error){case"not-allowed":d("请允许麦克风权限");break;case"network":d("网络错误,请检查连接");break;case"no-speech":case"aborted":return;default:d(`语音识别错误:${G.error}`)}},H.onend=()=>{if(E.current&&A.current&&a(G=>G+A.current),o(""),A.current="",!E.current)try{H.start();return}catch{}n(!1),x.current=null},x.current=H;try{return H.start(),!0}catch{return!1}},[e]),X=y.useCallback(async()=>{F.current=!1,a(""),o(""),d(null),b("idle");try{const z=await fetch("/api/transcribe/status"),{available:$}=await z.json();if(!$){d("语音识别服务未就绪,请稍后重试");return}}catch{d("无法连接语音识别服务");return}let H;try{H=await navigator.mediaDevices.getUserMedia({audio:{sampleRate:Pv,channelCount:1}})}catch{d("请允许麦克风权限");return}const G=new AudioContext({sampleRate:Pv}),Q=G.createMediaStreamSource(H),D=G.createScriptProcessor(4096,1,1);j.current=[],D.onaudioprocess=z=>{j.current.push(new Float32Array(z.inputBuffer.getChannelData(0)))},Q.connect(D),D.connect(G.destination),I.current=G,O.current=H,k.current=D,n(!0),b("recording")},[]),K=y.useCallback(()=>{mE?Y():Lv&&!C.current&&re()||X()},[Y,re,X]);y.useEffect(()=>{if(!t){m(0);return}if(x.current)return;let H=!1,G=null,Q=null,D=0;return(async()=>{try{if(G=await navigator.mediaDevices.getUserMedia({audio:!0}),H){G.getTracks().forEach(ne=>ne.stop());return}Q=new AudioContext;const z=Q.createMediaStreamSource(G),$=Q.createAnalyser();$.fftSize=256,z.connect($);const M=new Uint8Array($.frequencyBinCount);let le=0;const oe=()=>{if(H)return;$.getByteFrequencyData(M);const ne=performance.now();if(ne-le>80){let ae=0;for(let De=0;De<M.length;De++)ae+=M[De];m(ae/(M.length*255)),le=ne}D=requestAnimationFrame(oe)};D=requestAnimationFrame(oe)}catch{}})(),()=>{H=!0,cancelAnimationFrame(D),G==null||G.getTracks().forEach(z=>z.stop()),Q==null||Q.close().catch(()=>{}),m(0)}},[t]),y.useEffect(()=>{!t&&p==="recording"&&b(r?"done":"idle")},[t,p,r]),y.useEffect(()=>()=>{var H,G,Q,D;E.current=!0,(H=x.current)==null||H.stop(),(G=k.current)==null||G.disconnect(),(Q=O.current)==null||Q.getTracks().forEach(z=>z.stop()),(D=I.current)==null||D.close().catch(()=>{});for(const z of N.current)z.remove().catch(()=>{})},[]);const V=y.useCallback(()=>{F.current=!0,a(""),o(""),A.current="",b("idle")},[]);return{isSupported:P,isListening:t,phase:p,transcript:r,interimTranscript:i,error:u,volumeLevel:f,start:K,stop:B,resetTranscript:V}}const uNe=240,cNe=1e3;function aB(e){const t=lNe(),[n,r]=y.useState(""),[a,i]=y.useState(0),o=y.useRef(null),u=y.useRef(null),d=y.useRef(0);y.useEffect(()=>(t.phase==="recording"?(d.current=Date.now(),i(0),u.current=setInterval(()=>{i(Math.floor((Date.now()-d.current)/1e3))},cNe)):u.current&&(clearInterval(u.current),u.current=null),()=>{u.current&&(clearInterval(u.current),u.current=null)}),[t.phase]),y.useEffect(()=>{t.phase==="done"&&(r(t.transcript),requestAnimationFrame(()=>{const b=o.current;b&&(b.focus(),b.setSelectionRange(b.value.length,b.value.length))}))},[t.phase,t.transcript]),y.useLayoutEffect(()=>{if(t.phase!=="done")return;const b=o.current;b&&(b.style.height="auto",b.style.height=`${Math.min(b.scrollHeight,uNe)}px`)},[t.phase]);const f=y.useCallback(()=>{t.stop(),t.resetTranscript(),r("")},[t]),m=y.useCallback(async()=>{const b=n.trim();if(!b){f();return}await e(b)!==!1&&(t.resetTranscript(),r(""))},[n,e,f,t]);y.useEffect(()=>{if(t.phase==="idle")return;const b=x=>{if(x.key==="Escape"&&t.phase!=="recognizing"){x.preventDefault(),f();return}if(t.phase==="done"&&x.key==="Enter"&&(x.metaKey||x.ctrlKey)){if(x.isComposing)return;x.preventDefault(),m()}};return window.addEventListener("keydown",b),()=>window.removeEventListener("keydown",b)},[t.phase,f,m]);const p=y.useCallback(b=>{b.nativeEvent.isComposing||b.keyCode===229||b.key==="Enter"&&(b.metaKey||b.ctrlKey)&&(b.preventDefault(),m())},[m]);return{stt:t,editText:n,setEditText:r,elapsed:a,textareaRef:o,cancel:f,confirm:m,handleTextareaKeyDown:p}}const iB=["image/png","image/jpeg","image/gif","image/webp"];let jI=0;function sB(e){return e.split(`
|
|
653
653
|
`).length>NY||e.length>SY}function dNe(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/(1024*1024)).toFixed(1)}MB`}function fNe(e){return new Promise((t,n)=>{const r=new FileReader;r.onload=()=>t(String(r.result)),r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function hNe({url:e,label:t,onClose:n}){return y.useEffect(()=>{const r=a=>{a.key==="Escape"&&(a.preventDefault(),n())};return window.addEventListener("keydown",r,!0),()=>window.removeEventListener("keydown",r,!0)},[n]),c.jsx("div",{role:"dialog","aria-modal":"true","aria-label":t,onClick:n,className:"fixed inset-0 z-50 flex cursor-zoom-out items-center justify-center bg-black/80 p-8 backdrop-blur-sm",children:c.jsx("img",{src:e,alt:t,className:"max-h-full max-w-full object-contain"})})}function ow({url:e,label:t,className:n}){const[r,a]=y.useState(!1);return c.jsxs(c.Fragment,{children:[c.jsx("button",{type:"button",onClick:()=>a(!0),"aria-label":`预览 ${t}`,className:"block cursor-zoom-in rounded-md transition-opacity duration-150 hover:opacity-80",children:c.jsx("img",{src:e,alt:t,className:ie("rounded-md border border-line",n)})}),r&&c.jsx(hNe,{url:e,label:t,onClose:()=>a(!1)})]})}function oB(e=!0){const[t,n]=y.useState([]),[r,a]=y.useState([]),[i,o]=y.useState(null);y.useEffect(()=>{o(null),e||n([])},[e]);const u=async N=>{const _=[],S=[],C=t.length;let A=NA-C;for(const I of N){if(A<=0){S.push(`最多 ${NA} 张图片`);break}if(!iB.includes(I.type)){S.push(`${I.name||"文件"}:格式不支持`);continue}if(I.size>wY){S.push(`${I.name}:超过 5MB`);continue}_.push({_id:`att-${++jI}`,mime:I.type,url:await fNe(I),filename:I.name}),A--}_.length>0&&n(I=>[...I,..._]),o(S.length>0?S.join(";"):null)},d=N=>{const _=Array.from(N.clipboardData.files);if(_.length!==0){if(N.preventDefault(),!e){o("当前模型不支持图片");return}u(_)}},f=N=>{const _=++jI,S=N.split(`
|
|
654
654
|
`).length,C=new TextEncoder().encode(N).byteLength,A=`[粘贴文本 #${_} · ${S}行]`,I={_id:`fold-${_}`,text:N,lineCount:S,byteSize:C,placeholder:A};return a(O=>[...O,I]),I},m=N=>{let _=N;for(const S of r)_=_.replace(S.placeholder,S.text);return _},p=N=>n(_=>_.filter(S=>S._id!==N)),b=N=>a(_=>_.filter(S=>S._id!==N)),x=y.useCallback(()=>{n([]),a([]),o(null)},[]),E=t.map(({mime:N,url:_,filename:S})=>({mime:N,url:_,filename:S}));return{attachments:t,foldedTexts:r,promptFiles:E,error:i,setError:o,addFiles:u,onPaste:d,addFoldedText:f,expandFoldedTexts:m,remove:p,removeFoldedText:b,clear:x}}function mNe({text:e,label:t,onClose:n}){y.useEffect(()=>{const i=o=>{o.key==="Escape"&&(o.preventDefault(),n())};return window.addEventListener("keydown",i,!0),()=>window.removeEventListener("keydown",i,!0)},[n]);const r=e.split(`
|
|
655
655
|
`),a=String(r.length).length;return c.jsx("div",{role:"dialog","aria-modal":"true","aria-label":t,onClick:n,className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4 backdrop-blur-sm md:p-8",children:c.jsxs("div",{onClick:i=>i.stopPropagation(),className:"flex max-h-full w-full max-w-4xl flex-col overflow-hidden rounded-lg border border-line bg-term",children:[c.jsxs("div",{className:"flex items-center justify-between border-b border-line px-4 py-2",children:[c.jsx("span",{className:"font-mono text-xs text-fg-3",children:t}),c.jsx("button",{type:"button",onClick:n,className:"text-fg-5 hover:text-fg-2",children:c.jsx(At,{className:"h-4 w-4"})})]}),c.jsx("pre",{className:"overflow-auto p-4 font-mono text-xs leading-relaxed text-fg-2",children:r.map((i,o)=>c.jsxs("div",{children:[c.jsx("span",{className:"mr-3 inline-block select-none text-right text-fg-6",style:{width:`${a}ch`},children:o+1}),i]},o))})]})})}function pNe({fold:e,index:t,onRemove:n}){const[r,a]=y.useState(!1),i=`粘贴文本 #${t} · ${e.lineCount}行 · ${dNe(e.byteSize)}`;return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"group relative flex items-center gap-1.5 rounded-md border border-line bg-elevated/50 px-2.5 py-1.5",children:[c.jsxs("button",{type:"button",onClick:()=>a(!0),className:"flex items-center gap-1.5 font-mono text-xs text-fg-3 transition-colors hover:text-fg",children:[c.jsx(Io,{className:"h-3.5 w-3.5 shrink-0 text-fg-5"}),c.jsx("span",{children:i})]}),c.jsx("button",{type:"button",onClick:n,"aria-label":"移除粘贴文本",className:"flex h-4 w-4 shrink-0 items-center justify-center rounded-full text-fg-5 transition-colors hover:text-fg-2",children:c.jsx(At,{className:"h-2.5 w-2.5",strokeWidth:2.5})})]}),r&&c.jsx(mNe,{text:e.text,label:i,onClose:()=>a(!1)})]})}function lB({onFiles:e,disabled:t,allowed:n}){const r=y.useRef(null);return c.jsxs(c.Fragment,{children:[c.jsx("input",{ref:r,type:"file",accept:iB.join(","),multiple:!0,hidden:!0,onChange:a=>{e(Array.from(a.target.files??[])),a.target.value=""}}),c.jsx("button",{type:"button",onClick:()=>{var a;return(a=r.current)==null?void 0:a.click()},disabled:t||!n,"aria-label":"Attach image",title:n?"附加图片":"当前模型不支持图片",className:"flex h-7 w-7 shrink-0 items-center justify-center rounded-md text-fg-5 transition-colors duration-150 hover:text-fg-3 disabled:cursor-not-allowed disabled:text-fg-6/40",children:c.jsx(Jz,{className:"h-4 w-4"})})]})}function uB({attachments:e,foldedTexts:t,error:n,onRemove:r,onRemoveFoldedText:a,className:i}){const o=e.length>0||(t??[]).length>0;return!o&&!n?null:c.jsxs("div",{className:i,children:[o&&c.jsxs("div",{className:"mb-2 flex flex-wrap gap-2",children:[e.map(u=>c.jsxs("div",{className:"group relative",children:[c.jsx(ow,{url:u.url,label:u.filename??"attachment",className:"h-16 w-16 object-cover"}),c.jsx("button",{type:"button",onClick:()=>r(u._id),"aria-label":"Remove attachment",className:"absolute -right-1.5 -top-1.5 flex h-4 w-4 items-center justify-center rounded-full border border-line bg-term text-fg-4 opacity-0 transition-opacity duration-150 hover:text-fg-2 group-hover:opacity-100",children:c.jsx(At,{className:"h-2.5 w-2.5",strokeWidth:2.5})})]},u._id)),(t??[]).map((u,d)=>c.jsx(pNe,{fold:u,index:d+1,onRemove:()=>a==null?void 0:a(u._id)},u._id))]}),n&&c.jsx("div",{className:"mb-2 font-mono text-[11px] text-red-400",children:n})]})}const LI=(function(e,t,n){const r=Ih(n);if(!e||!e.type||!e.children)throw new Error("Expected parent node");if(typeof t=="number"){if(t<0||t===Number.POSITIVE_INFINITY)throw new Error("Expected positive finite number as index")}else if(t=e.children.indexOf(t),t<0)throw new Error("Expected child node or index");for(;++t<e.children.length;)if(r(e.children[t],t,e))return e.children[t]}),tu=(function(e){if(e==null)return xNe;if(typeof e=="string")return bNe(e);if(typeof e=="object")return gNe(e);if(typeof e=="function")return lw(e);throw new Error("Expected function, string, or array as `test`")});function gNe(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=tu(e[n]);return lw(r);function r(...a){let i=-1;for(;++i<t.length;)if(t[i].apply(this,a))return!0;return!1}}function bNe(e){return lw(t);function t(n){return n.tagName===e}}function lw(e){return t;function t(n,r,a){return!!(yNe(n)&&e.call(this,n,typeof r=="number"?r:void 0,a||void 0))}}function xNe(e){return!!(e&&typeof e=="object"&&"type"in e&&e.type==="element"&&"tagName"in e&&typeof e.tagName=="string")}function yNe(e){return e!==null&&typeof e=="object"&&"type"in e&&"tagName"in e}const PI=/\n/g,BI=/[\t ]+/g,pE=tu("br"),UI=tu(ANe),vNe=tu("p"),FI=tu("tr"),ENe=tu(["datalist","head","noembed","noframes","noscript","rp","script","style","template","title",TNe,CNe]),cB=tu(["address","article","aside","blockquote","body","caption","center","dd","dialog","dir","dl","dt","div","figure","figcaption","footer","form,","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","legend","li","listing","main","menu","nav","ol","p","plaintext","pre","section","ul","xmp"]);function NNe(e,t){const n=t||{},r="children"in e?e.children:[],a=cB(e),i=hB(e,{whitespace:n.whitespace||"normal"}),o=[];(e.type==="text"||e.type==="comment")&&o.push(...fB(e,{breakBefore:!0,breakAfter:!0}));let u=-1;for(;++u<r.length;)o.push(...dB(r[u],e,{whitespace:i,breakBefore:u?void 0:a,breakAfter:u<r.length-1?pE(r[u+1]):a}));const d=[];let f;for(u=-1;++u<o.length;){const m=o[u];typeof m=="number"?f!==void 0&&m>f&&(f=m):m&&(f!==void 0&&f>-1&&d.push(`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{W as e}from"./index-
|
|
1
|
+
import{W as e}from"./index-zCZNajXb.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-
|
|
7
|
+
<script type="module" crossorigin src="/assets/index-zCZNajXb.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-BRyHYssj.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
|
File without changes
|