@dsh-sup/dsh-core-linux-x64 0.1.5-BETA.3 → 0.1.5-BETA.4

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/core.cjs CHANGED
@@ -225,7 +225,7 @@ var require_version = __commonJS({
225
225
  var fs2 = require("node:fs");
226
226
  var path2 = require("node:path");
227
227
  function guardVersion() {
228
- if (true) return String("0.1.5-BETA.3");
228
+ if (true) return String("0.1.5-BETA.4");
229
229
  try {
230
230
  return JSON.parse(fs2.readFileSync(path2.join(__dirname, "..", "..", "package.json"), "utf8")).version || "unknown";
231
231
  } catch {
@@ -269,7 +269,7 @@ var require_matrix = __commonJS({
269
269
  function isSupported(platform, arch) {
270
270
  const p = platform || process.platform;
271
271
  const a = arch || process.arch;
272
- return !!(OS_TAG[p] && (a === "x64" || a === "arm64"));
272
+ return SUPPORTED.some((x) => x.platform === p && x.arch === a);
273
273
  }
274
274
  function frpTag(platform, arch) {
275
275
  const p = platform || process.platform;
@@ -11635,7 +11635,7 @@ var require_watchdog = __commonJS({
11635
11635
  if (inUpdate && !phaseStale) return true;
11636
11636
  try {
11637
11637
  const j = shell.readJournal && shell.readJournal();
11638
- if (j && j.to && !j.confirmed && !j.rolledBack) return true;
11638
+ if (j && j.to && !j.confirmed) return true;
11639
11639
  } catch {
11640
11640
  }
11641
11641
  return false;
@@ -11790,11 +11790,7 @@ var require_shell = __commonJS({
11790
11790
  return readJson(journalPath()) || {
11791
11791
  from: null,
11792
11792
  to: null,
11793
- attempts: 0,
11794
- maxAttempts: 2,
11795
11793
  confirmed: false,
11796
- rolledBack: false,
11797
- pinnedVersions: [],
11798
11794
  startedAt: null,
11799
11795
  lastAttemptAt: null
11800
11796
  };
@@ -11806,9 +11802,7 @@ var require_shell = __commonJS({
11806
11802
  const j = readJournal();
11807
11803
  j.from = from || j.from;
11808
11804
  j.to = to;
11809
- j.attempts = 0;
11810
11805
  j.confirmed = false;
11811
- j.rolledBack = false;
11812
11806
  j.startedAt = (/* @__PURE__ */ new Date()).toISOString();
11813
11807
  writeJournal(j);
11814
11808
  return j;
@@ -11821,45 +11815,19 @@ var require_shell = __commonJS({
11821
11815
  if (cur && cur === j.to && id && id.phase === "ready") {
11822
11816
  if (!j.confirmed) {
11823
11817
  j.confirmed = true;
11824
- j.attempts = 0;
11825
11818
  writeJournal(j);
11826
11819
  }
11827
11820
  return { state: "confirmed", version: cur, reason: "\u58F3\u5DF2\u5065\u5EB7\u8FD0\u884C\u65B0\u7248\u672C", journal: j, identity: id };
11828
11821
  }
11829
- const attempt = id && typeof id.attempt === "number" ? id.attempt : 0;
11830
- if (cur && cur !== j.to && attempt >= (j.maxAttempts || 2)) {
11831
- return {
11832
- state: "should-rollback",
11833
- target: j.to,
11834
- current: cur,
11835
- attempts: attempt,
11836
- reason: `\u58F3 ${attempt} \u6B21\u672A\u80FD\u5728 ${j.to} \u4E0A\u5C31\u7EEA\uFF08\u5F53\u524D ${cur}\uFF09`,
11837
- journal: j,
11838
- identity: id
11839
- };
11840
- }
11841
11822
  return {
11842
11823
  state: "pending",
11843
11824
  target: j.to,
11844
11825
  current: cur,
11845
- attempts: attempt,
11846
11826
  reason: cur === j.to ? "\u7B49\u5F85\u58F3\u4E0A\u62A5\u5C31\u7EEA" : "\u7B49\u5F85\u58F3\u91CD\u542F\u5230\u65B0\u7248\u672C",
11847
11827
  journal: j,
11848
11828
  identity: id
11849
11829
  };
11850
11830
  }
11851
- function rollback(reason) {
11852
- const j = readJournal();
11853
- const bad = j.to;
11854
- if (bad && !j.pinnedVersions.includes(bad)) j.pinnedVersions.push(bad);
11855
- j.rolledBack = true;
11856
- j.confirmed = false;
11857
- j.attempts = 0;
11858
- j.to = null;
11859
- j.lastAttemptAt = (/* @__PURE__ */ new Date()).toISOString();
11860
- writeJournal(j);
11861
- return { ok: true, pinned: bad, reason: reason || null, journal: j };
11862
- }
11863
11831
  function health(payload) {
11864
11832
  const p = payload || {};
11865
11833
  const dir = shellDir();
@@ -11882,7 +11850,6 @@ var require_shell = __commonJS({
11882
11850
  journal: j,
11883
11851
  state: ev.state,
11884
11852
  reason: ev.reason || null,
11885
- pinned: j.pinnedVersions || [],
11886
11853
  dir: shellDir()
11887
11854
  };
11888
11855
  }
@@ -11988,7 +11955,7 @@ var require_shell = __commonJS({
11988
11955
  return { ok: false, error: "\u62C9\u8D77\u65B0\u58F3\u5931\u8D25: " + (e && e.message || e), killed };
11989
11956
  }
11990
11957
  }
11991
- module2.exports = { status, evaluate, health, markPending, rollback, identity, readJournal, shellDir, checkUpdate, restartShell, SHELL_RELEASE_PKG };
11958
+ module2.exports = { status, evaluate, health, markPending, identity, readJournal, shellDir, checkUpdate, restartShell, SHELL_RELEASE_PKG };
11992
11959
  }
11993
11960
  });
11994
11961
 
@@ -16323,26 +16290,6 @@ var require_shell2 = __commonJS({
16323
16290
  return send(r.ok ? 200 : 500, r);
16324
16291
  }).catch((e) => send(500, { ok: false, error: e.message }));
16325
16292
  }
16326
- if (req.method === "POST" && pathname === "/shell/rollback") {
16327
- if (!originAllowed(req, sup.config.apiPort)) {
16328
- req.resume();
16329
- return send(403, {});
16330
- }
16331
- return collectBody(req, res, 8192, (body) => {
16332
- let j = {};
16333
- try {
16334
- j = body ? JSON.parse(body) : {};
16335
- } catch {
16336
- }
16337
- try {
16338
- const r = shell.rollback(j.reason || "manual");
16339
- if (sup.events) sup.events.append("shell_update_rolled_back", { pinned: r.pinned, reason: r.reason });
16340
- return send(200, r);
16341
- } catch (e) {
16342
- return send(500, { ok: false, error: e.message });
16343
- }
16344
- });
16345
- }
16346
16293
  if (req.method === "GET" || req.method === "POST") return send(404, { error: "not found", path: pathname });
16347
16294
  return send(405, { error: "method not allowed" });
16348
16295
  }
@@ -17881,7 +17828,7 @@ var require_settings_view = __commonJS({
17881
17828
  }
17882
17829
  /** 守卫自更新「重启生效」衔接:仅当配置 guardRestartAllowed=true 且存在 systemd 用户单元才执行;
17883
17830
  * 否则返回明确指引(避免误杀/误起守卫)。 */
17884
- /** 自更新后的守卫重启(A2):能力按部署形态自动判定(SEA=systemd 重启闭环;源码形态=拒绝),
17831
+ /** 自更新后的守卫重启(A2):能力按部署形态自动判定(打包态=systemd 重启闭环;源码形态=拒绝),
17885
17832
  * 去掉 guardRestartAllowed 人工配置门槛。重启前落盘「预期版本」,重启后 /status 校验自报版本
17886
17833
  * 达标才算更新成功——闭环可观测,不再出现"装了没生效"的静默失败。 */
17887
17834
  guardSelfUpdateRestart() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-sup/dsh-core-linux-x64",
3
- "version": "0.1.5-BETA.3",
3
+ "version": "0.1.5-BETA.4",
4
4
  "description": "DSH lifecycle guard core (Node launcher) for linux-x64 — requires Node >=18.",
5
5
  "license": "UNLICENSED",
6
6
  "os": [
@@ -1,3 +1,3 @@
1
- import{A as e,E as t,L as n,O as r,P as i,T as a,_ as o,b as s,g as c,h as l,i as u,k as d,m as f,n as p,o as m,r as h,t as g,v as _,y as v,z as y}from"./supervisor-BVac7io-.js";import{t as b}from"./external-link-SYs4QOvn.js";import{n as x,t as ee}from"./rocket-Dt6NGQXE.js";import{t as te}from"./shield-check-B-D3XDKa.js";import{c as ne,f as re,o as S,s as C}from"./supervisor-DX8HnT5i.js";import{t as w}from"./useSupervisorAction-B1Piyga4.js";import{c as T,i as E,o as D,r as O,t as k}from"./widgets-DMpjcPY5.js";var A=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),j=i(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),M=i(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),N=y(n(),1),P=r();function F({onRegisterActions:n}){let{snap:r}=g(),{busy:i,run:y}=w(),[F,I]=(0,N.useState)(!1),[L,R]=(0,N.useState)(null),[z,B]=(0,N.useState)(``),[V,H]=(0,N.useState)(``),[U,W]=(0,N.useState)(``),[G,K]=(0,N.useState)(`4G`),[q,J]=(0,N.useState)(`150%`),Y=r.instances?.instances??[],[X,ie]=(0,N.useState)(null);(0,N.useEffect)(()=>{let e=!0;return h.envStatus().then(t=>{e&&ie(t.capabilities??null)}).catch(()=>void 0),()=>{e=!1}},[]);let Z=X!==null&&X.multiInstance===!1;(0,N.useEffect)(()=>(n?.({onAdd:()=>I(!0)}),()=>n?.(null)),[n]);let Q=(e,t)=>y(e,t);async function ae(){if(Z){d.error(`当前平台不支持沙箱实例(需 Linux + systemd-run)`);return}let e=parseInt(V,10);if(!Number.isFinite(e)||e<=0){d.error(`请填写有效端口`);return}let t=U?U.split(/\n/).map(e=>e.trim()).filter(Boolean):[];try{let n=await h.instanceAdd({name:z.trim()||`沙箱 `+e,port:e,command:t,memoryMax:G||`4G`,cpuQuota:q||`150%`});if(n&&n.ok===!1){d.error(n.error||`添加失败`);return}d.success(`已添加实例`),I(!1),B(``),H(``),W(``),K(`4G`),J(`150%`),p.refresh()}catch(e){d.error(String(e))}}async function oe(e){await y(e.id,async()=>{let t=await h.instanceCheckUpdate(e.id);t.updateAvailable?(d.success(`发现新版 `+t.latest+`,可点「更新」升级`),ce(t=>new Map(t).set(e.id,!0))):t.latest?d.info(`已是最新 `+t.latest):d.error(t.error||`版本检测失败`)})}let[se,ce]=(0,N.useState)(new Map);async function le(e){confirm(`将升级该沙箱实例的 DSH 到最新版(实例会短暂重启,进行中的请求中断)。确定升级?`)&&await y(e.id,()=>h.instanceUpgrade(e.id),{success:`升级已开始…`})}let $=({it:n})=>{let r=n.state?.running??!1,o=n.state?.lifecyclePhase,s=C(o,r),c=n.updateJob,l=c?.state===`running`,u=n.sandbox?.memoryMax||`—`,d=n.sandbox?.cpuQuota||`—`,f=i===n.id;return(0,P.jsxs)(k,{className:`overflow-visible`,children:[(0,P.jsxs)(`div`,{className:`grid grid-cols-1 @min-[720px]:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]`,children:[(0,P.jsxs)(`div`,{className:`flex flex-col gap-4 border-b border-border px-6 py-5 md:border-b-0 md:border-r`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,P.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,P.jsx)(`strong`,{className:`truncate text-lg font-semibold tracking-[-0.01em] text-foreground`,children:n.name}),n.version?(0,P.jsxs)(`span`,{className:`font-mono text-sm text-muted-foreground`,children:[`v`,n.version]}):null]}),se.get(n.id)?(0,P.jsxs)(a,{className:`text-primary-foreground`,onClick:()=>void le(n),size:`chip`,children:[(0,P.jsx)(j,{className:`size-3`}),`更新`]}):(0,P.jsxs)(a,{className:`bg-primary/10 text-primary hover:bg-primary/15`,disabled:f||l,onClick:()=>void oe(n),size:`chip`,variant:`ghost`,children:[(0,P.jsx)(j,{className:t(`size-3`,f&&`animate-spin`)}),`检测更新`]})]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(T,{tone:s.tone,ping:s.tone===`ok`}),(0,P.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:s.label})]}),l?(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,P.jsx)(m,{className:`size-3`}),`正在升级 DeepSeek Harness(`,c?.step||``,`)…`]}):null,n.state?.installing?(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,P.jsx)(m,{className:`size-3`}),`正在安装…`]}):null,o===`FAILED`?(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-destructive`,children:[(0,P.jsx)(e,{className:`size-3.5`}),(0,P.jsx)(`span`,{className:`truncate`,children:n.state?.lastError||`失败`})]}):null]}),(0,P.jsx)(`div`,{className:`flex items-center bg-[image:var(--panel-accent-gradient)] px-6 py-5`,children:(0,P.jsxs)(`div`,{className:`grid w-full grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-4`,children:[(0,P.jsx)(E,{icon:(0,P.jsx)(re,{className:`size-4`}),label:`端口`,value:String(n.port),mono:!0}),(0,P.jsx)(E,{icon:(0,P.jsx)(M,{className:`size-4`}),label:`PID`,value:n.state?.pid?String(n.state.pid):`—`,mono:!0}),(0,P.jsx)(E,{icon:(0,P.jsx)(j,{className:`size-4`}),label:`重启次数`,value:String(n.state?.restartCount??0),mono:!0}),(0,P.jsx)(E,{icon:(0,P.jsx)(e,{className:`size-4`}),label:`最近故障`,value:n.state?.lastFailure?S(n.state.lastFailure):`无`,warn:!!n.state?.lastFailure})]})})]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-t border-border/60 px-6 py-3`,children:[(0,P.jsxs)(`span`,{className:`hidden min-w-0 items-center lg:inline-flex gap-2 text-xs text-muted-foreground`,children:[(0,P.jsx)(O,{domain:`sandbox`}),(0,P.jsx)(D,{tone:n.remoteEnabled?`boot`:`off`,children:n.remoteEnabled?`远程开启`:`远程关闭`}),(0,P.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`内存 `,u,` · CPU `,d]})]}),(0,P.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,P.jsxs)(a,{disabled:!r,onClick:()=>void Q(n.id,()=>h.instanceOpenWeb(n.id)),size:`sm`,title:`打开 DSH Web(自动带认证连接)`,variant:`outline`,className:`hidden md:inline-flex`,children:[(0,P.jsx)(b,{className:`size-4`}),`DSH Web`]}),(0,P.jsx)(a,{disabled:l,onClick:()=>void Q(n.id,()=>r?h.instanceStop(n.id):h.instanceStart(n.id)),size:`sm`,variant:`outline`,children:r?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(x,{className:`size-4 text-status-error`}),`停止实例`]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(ee,{className:`size-4 text-primary`}),`启动实例`]})}),(0,P.jsx)(`span`,{"aria-hidden":`true`,className:`mx-1 h-5 w-px bg-border`}),(0,P.jsxs)(a,{disabled:f,onClick:()=>void Q(n.id,()=>h.instanceUpdate(n.id,{guardian:!n.guardian})),size:`sm`,variant:`outline`,children:[(0,P.jsx)(te,{className:t(`size-4`,n.guardian?`text-status-ok`:`text-muted-foreground`)}),n.guardian?`停止守护`:`启动守护`]}),(0,P.jsxs)(a,{className:`hidden h-[30px] md:inline-flex`,disabled:f,onClick:()=>R(n.id),size:`sm`,variant:`destructive`,children:[(0,P.jsx)(ne,{className:`size-4`}),`删除`]})]})]})]})};return(0,P.jsxs)(`div`,{className:`grid content-start gap-4`,children:[Z?(0,P.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/5 px-3 py-2.5 text-xs text-muted-foreground`,children:[(0,P.jsx)(e,{className:`mt-0.5 size-3.5 shrink-0 text-amber-500`}),(0,P.jsxs)(`span`,{children:[`当前平台(`,X?.platform||`未知`,`)不支持沙箱实例:需 Linux + systemd-run(独立 cgroup 隔离)。 原生 DSH 主实例不受影响。`]})]}):null,Y.length?(0,P.jsx)(`div`,{className:`grid gap-3`,children:Y.map(e=>(0,P.jsx)($,{it:e},e.id))}):(0,P.jsx)(`div`,{className:`grid min-h-[220px] place-items-center rounded-lg border border-dashed border-border text-center`,children:(0,P.jsxs)(`div`,{children:[(0,P.jsx)(A,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,P.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`尚未添加沙箱实例`}),(0,P.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:Z?`当前平台不支持沙箱实例(见上方说明)`:`点击顶部「添加实例」创建沙箱`})]})}),(0,P.jsx)(c,{open:F,onOpenChange:I,children:(0,P.jsxs)(o,{className:`max-w-[440px]`,children:[(0,P.jsx)(v,{children:(0,P.jsx)(s,{children:`添加 DSH 实例`})}),(0,P.jsxs)(`div`,{className:`grid gap-3`,children:[(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,P.jsx)(f,{children:`实例名称`}),(0,P.jsx)(l,{placeholder:`如 沙箱二开`,value:z,onChange:e=>B(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,P.jsx)(f,{children:`监听端口`}),(0,P.jsx)(l,{inputMode:`numeric`,placeholder:`如 3082`,value:V,onChange:e=>H(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,P.jsx)(f,{children:`启动命令(每项一参数,可留空用默认)`}),(0,P.jsx)(u,{className:`min-h-[72px] font-mono text-sm`,placeholder:`node
2
- /home/bowen/.npm-global/bin/dsh
1
+ import{A as e,E as t,L as n,O as r,P as i,T as a,_ as o,b as s,g as c,h as l,i as u,k as d,m as f,n as p,o as m,r as h,t as g,v as _,y as v,z as y}from"./supervisor-BVac7io-.js";import{t as b}from"./external-link-SYs4QOvn.js";import{n as x,t as ee}from"./rocket-Dt6NGQXE.js";import{t as te}from"./shield-check-B-D3XDKa.js";import{c as ne,f as re,o as S,s as C}from"./supervisor-DwJMunGH.js";import{t as w}from"./useSupervisorAction-B1Piyga4.js";import{c as T,i as E,o as D,r as O,t as k}from"./widgets-DMpjcPY5.js";var A=i(`box`,[[`path`,{d:`M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z`,key:`hh9hay`}],[`path`,{d:`m3.3 7 8.7 5 8.7-5`,key:`g66t2b`}],[`path`,{d:`M12 22V12`,key:`d0xqtd`}]]),j=i(`rotate-cw`,[[`path`,{d:`M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8`,key:`1p45f6`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}]]),M=i(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),N=y(n(),1),P=r();function F({onRegisterActions:n}){let{snap:r}=g(),{busy:i,run:y}=w(),[F,I]=(0,N.useState)(!1),[L,R]=(0,N.useState)(null),[z,B]=(0,N.useState)(``),[V,H]=(0,N.useState)(``),[U,W]=(0,N.useState)(``),[G,K]=(0,N.useState)(`4G`),[q,J]=(0,N.useState)(`150%`),Y=r.instances?.instances??[],[X,ie]=(0,N.useState)(null);(0,N.useEffect)(()=>{let e=!0;return h.envStatus().then(t=>{e&&ie(t.capabilities??null)}).catch(()=>void 0),()=>{e=!1}},[]);let Z=X!==null&&X.multiInstance===!1;(0,N.useEffect)(()=>(n?.({onAdd:()=>I(!0)}),()=>n?.(null)),[n]);let Q=(e,t)=>y(e,t);async function ae(){if(Z){d.error(`当前平台不支持沙箱实例(需 Linux + systemd-run)`);return}let e=parseInt(V,10);if(!Number.isFinite(e)||e<=0){d.error(`请填写有效端口`);return}let t=U?U.split(/\n/).map(e=>e.trim()).filter(Boolean):[];try{let n=await h.instanceAdd({name:z.trim()||`沙箱 `+e,port:e,command:t,memoryMax:G||`4G`,cpuQuota:q||`150%`});if(n&&n.ok===!1){d.error(n.error||`添加失败`);return}d.success(`已添加实例`),I(!1),B(``),H(``),W(``),K(`4G`),J(`150%`),p.refresh()}catch(e){d.error(String(e))}}async function oe(e){await y(e.id,async()=>{let t=await h.instanceCheckUpdate(e.id);t.updateAvailable?(d.success(`发现新版 `+t.latest+`,可点「更新」升级`),ce(t=>new Map(t).set(e.id,!0))):t.latest?d.info(`已是最新 `+t.latest):d.error(t.error||`版本检测失败`)})}let[se,ce]=(0,N.useState)(new Map);async function le(e){confirm(`将升级该沙箱实例的 DSH 到最新版(实例会短暂重启,进行中的请求中断)。确定升级?`)&&await y(e.id,()=>h.instanceUpgrade(e.id),{success:`升级已开始…`})}let $=({it:n})=>{let r=n.state?.running??!1,o=n.state?.lifecyclePhase,s=C(o,r),c=n.updateJob,l=c?.state===`running`,u=n.sandbox?.memoryMax||`—`,d=n.sandbox?.cpuQuota||`—`,f=i===n.id;return(0,P.jsxs)(k,{className:`overflow-visible`,children:[(0,P.jsxs)(`div`,{className:`grid grid-cols-1 @min-[720px]:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]`,children:[(0,P.jsxs)(`div`,{className:`flex flex-col gap-4 border-b border-border px-6 py-5 md:border-b-0 md:border-r`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,P.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,P.jsx)(`strong`,{className:`truncate text-lg font-semibold tracking-[-0.01em] text-foreground`,children:n.name}),n.version?(0,P.jsxs)(`span`,{className:`font-mono text-sm text-muted-foreground`,children:[`v`,n.version]}):null]}),se.get(n.id)?(0,P.jsxs)(a,{className:`text-primary-foreground`,onClick:()=>void le(n),size:`chip`,children:[(0,P.jsx)(j,{className:`size-3`}),`更新`]}):(0,P.jsxs)(a,{className:`bg-primary/10 text-primary hover:bg-primary/15`,disabled:f||l,onClick:()=>void oe(n),size:`chip`,variant:`ghost`,children:[(0,P.jsx)(j,{className:t(`size-3`,f&&`animate-spin`)}),`检测更新`]})]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(T,{tone:s.tone,ping:s.tone===`ok`}),(0,P.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:s.label})]}),l?(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,P.jsx)(m,{className:`size-3`}),`正在升级 DeepSeek Harness(`,c?.step||``,`)…`]}):null,n.state?.installing?(0,P.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,P.jsx)(m,{className:`size-3`}),`正在安装…`]}):null,o===`FAILED`?(0,P.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-destructive`,children:[(0,P.jsx)(e,{className:`size-3.5`}),(0,P.jsx)(`span`,{className:`truncate`,children:n.state?.lastError||`失败`})]}):null]}),(0,P.jsx)(`div`,{className:`flex items-center bg-[image:var(--panel-accent-gradient)] px-6 py-5`,children:(0,P.jsxs)(`div`,{className:`grid w-full grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-4`,children:[(0,P.jsx)(E,{icon:(0,P.jsx)(re,{className:`size-4`}),label:`端口`,value:String(n.port),mono:!0}),(0,P.jsx)(E,{icon:(0,P.jsx)(M,{className:`size-4`}),label:`PID`,value:n.state?.pid?String(n.state.pid):`—`,mono:!0}),(0,P.jsx)(E,{icon:(0,P.jsx)(j,{className:`size-4`}),label:`重启次数`,value:String(n.state?.restartCount??0),mono:!0}),(0,P.jsx)(E,{icon:(0,P.jsx)(e,{className:`size-4`}),label:`最近故障`,value:n.state?.lastFailure?S(n.state.lastFailure):`无`,warn:!!n.state?.lastFailure})]})})]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-t border-border/60 px-6 py-3`,children:[(0,P.jsxs)(`span`,{className:`hidden min-w-0 items-center lg:inline-flex gap-2 text-xs text-muted-foreground`,children:[(0,P.jsx)(O,{domain:`sandbox`}),(0,P.jsx)(D,{tone:n.remoteEnabled?`boot`:`off`,children:n.remoteEnabled?`远程开启`:`远程关闭`}),(0,P.jsxs)(`span`,{className:`whitespace-nowrap`,children:[`内存 `,u,` · CPU `,d]})]}),(0,P.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,P.jsxs)(a,{disabled:!r,onClick:()=>void Q(n.id,()=>h.instanceOpenWeb(n.id)),size:`sm`,title:`打开 DSH Web(自动带认证连接)`,variant:`outline`,className:`hidden md:inline-flex`,children:[(0,P.jsx)(b,{className:`size-4`}),`DSH Web`]}),(0,P.jsx)(a,{disabled:l,onClick:()=>void Q(n.id,()=>r?h.instanceStop(n.id):h.instanceStart(n.id)),size:`sm`,variant:`outline`,children:r?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(x,{className:`size-4 text-status-error`}),`停止实例`]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(ee,{className:`size-4 text-primary`}),`启动实例`]})}),(0,P.jsx)(`span`,{"aria-hidden":`true`,className:`mx-1 h-5 w-px bg-border`}),(0,P.jsxs)(a,{disabled:f,onClick:()=>void Q(n.id,()=>h.instanceUpdate(n.id,{guardian:!n.guardian})),size:`sm`,variant:`outline`,children:[(0,P.jsx)(te,{className:t(`size-4`,n.guardian?`text-status-ok`:`text-muted-foreground`)}),n.guardian?`停止守护`:`启动守护`]}),(0,P.jsxs)(a,{className:`hidden h-[30px] md:inline-flex`,disabled:f,onClick:()=>R(n.id),size:`sm`,variant:`destructive`,children:[(0,P.jsx)(ne,{className:`size-4`}),`删除`]})]})]})]})};return(0,P.jsxs)(`div`,{className:`grid content-start gap-4`,children:[Z?(0,P.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/5 px-3 py-2.5 text-xs text-muted-foreground`,children:[(0,P.jsx)(e,{className:`mt-0.5 size-3.5 shrink-0 text-amber-500`}),(0,P.jsxs)(`span`,{children:[`当前平台(`,X?.platform||`未知`,`)不支持沙箱实例:需 Linux + systemd-run(独立 cgroup 隔离)。 原生 DSH 主实例不受影响。`]})]}):null,Y.length?(0,P.jsx)(`div`,{className:`grid gap-3`,children:Y.map(e=>(0,P.jsx)($,{it:e},e.id))}):(0,P.jsx)(`div`,{className:`grid min-h-[220px] place-items-center rounded-lg border border-dashed border-border text-center`,children:(0,P.jsxs)(`div`,{children:[(0,P.jsx)(A,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,P.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`尚未添加沙箱实例`}),(0,P.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:Z?`当前平台不支持沙箱实例(见上方说明)`:`点击顶部「添加实例」创建沙箱`})]})}),(0,P.jsx)(c,{open:F,onOpenChange:I,children:(0,P.jsxs)(o,{className:`max-w-[440px]`,children:[(0,P.jsx)(v,{children:(0,P.jsx)(s,{children:`添加 DSH 实例`})}),(0,P.jsxs)(`div`,{className:`grid gap-3`,children:[(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,P.jsx)(f,{children:`实例名称`}),(0,P.jsx)(l,{placeholder:`如 沙箱二开`,value:z,onChange:e=>B(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,P.jsx)(f,{children:`监听端口`}),(0,P.jsx)(l,{inputMode:`numeric`,placeholder:`如 3082`,value:V,onChange:e=>H(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,P.jsx)(f,{children:`启动命令(每项一参数,可留空用默认)`}),(0,P.jsx)(u,{className:`min-h-[72px] font-mono text-sm`,placeholder:`node
2
+ /usr/local/bin/dsh
3
3
  web`,value:U,onChange:e=>W(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,P.jsx)(f,{children:`内存限额`}),(0,P.jsx)(l,{placeholder:`如 4G`,value:G,onChange:e=>K(e.target.value)})]}),(0,P.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,P.jsx)(f,{children:`CPU 配额`}),(0,P.jsx)(l,{placeholder:`如 150%`,value:q,onChange:e=>J(e.target.value)})]})]})]}),(0,P.jsxs)(_,{children:[(0,P.jsx)(a,{onClick:()=>I(!1),variant:`outline`,children:`取消`}),(0,P.jsx)(a,{onClick:()=>void ae(),children:`添加`})]})]})}),(0,P.jsx)(c,{open:!!L,onOpenChange:e=>!e&&R(null),children:(0,P.jsxs)(o,{className:`max-w-[380px]`,children:[(0,P.jsx)(v,{children:(0,P.jsx)(s,{children:`删除实例?`})}),(0,P.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`将彻底删除该沙箱实例(含配置与运行时数据)。此操作不可恢复。`}),(0,P.jsxs)(_,{children:[(0,P.jsx)(a,{onClick:()=>R(null),variant:`outline`,children:`取消`}),(0,P.jsx)(a,{className:`h-[34px]`,onClick:()=>{let e=L;R(null),e&&y(e,async()=>{let t=await h.instanceRemove(e);t&&t.ok!==!1&&t.dataPreserved===!0?d.warning(`实例已移除,但因其单元仍在运行,数据目录已保留(未删除)——请先停止实例再删数据`):t&&t.ok===!1&&d.error(t.error||`删除失败`),p.refresh()})},variant:`destructive`,children:`删除`})]})]})})]})}export{F as InstancesPage};
@@ -1,2 +1,2 @@
1
- import{A as e,E as t,L as n,O as r,P as i,T as a,_ as o,b as s,g as ee,k as c,r as l,t as u,v as d,y as f,z as p}from"./supervisor-BVac7io-.js";import{t as m}from"./external-link-SYs4QOvn.js";import{n as h,t as g}from"./rocket-Dt6NGQXE.js";import{t as _}from"./refresh-cw-CQuKs_Tk.js";import{t as v}from"./shield-check-B-D3XDKa.js";import{c as y,f as b,n as x,o as S,t as C}from"./supervisor-DX8HnT5i.js";import{t as w}from"./useSupervisorAction-B1Piyga4.js";import{c as T,i as E,n as D,o as O,t as k}from"./widgets-DMpjcPY5.js";import{t as A}from"./format-QeaTKFhQ.js";var j=i(`arrow-up-right`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),M=i(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),N=i(`square-terminal`,[[`path`,{d:`m7 11 2-2-2-2`,key:`1lz0vl`}],[`path`,{d:`M11 13h4`,key:`1p7l4v`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}]]),P=p(n(),1),F=r();function I(e,t){return e===`dsh-main`||e===`supervisor-api`?`boot`:(t||``).startsWith(`inst:`)?`ok`:e===`relay`?`warn`:e.startsWith(`managed:`)?`boot`:`off`}function L(e){let t={"dsh-main":`DSH 主实例`,"supervisor-api":`管家 API`,user:`沙箱实例`,relay:`局域网隧道`,oauthCallback:`登录回调`,proxyInstance:`反代实例`,providerApi:`供应商 API`,"managed:router-daemon":`智能路由`,"managed:lan-daemon":`远程控制`,dynamic:`动态端口`},n=/^managed:(.+)$/.exec(e.role);return n?t[e.role]??n[1]:t[e.role]??e.role}function R(e,t){let n=e.owner||``;if(e.role===`proxyInstance`){let e=(n.split(`:`).pop()||``).slice(-4),r=(t??[]).find(t=>(t.accounts??[]).some(t=>(t.maskedKey||``).endsWith(e)));return r?r.name:`反代`}return n.startsWith(`inst:`)?`沙箱实例`:n.startsWith(`system:`)?`系统`:n.startsWith(`relay:`)?`局域网隧道`:n.startsWith(`dynamic:`)?`动态`:n.startsWith(`providerApi:`)?`供应商`:n.startsWith(`oauth:`)?`登录回调`:n===`router-daemon`||e.role===`managed:router-daemon`?`智能路由`:n===`lan-daemon`||e.role===`managed:lan-daemon`?`远程控制`:e.role===`oauthCallback`?`登录回调`:e.role}function z({providers:e=[]}){let{snap:n}=u(),r=n.ports?.records??null,i=(0,P.useMemo)(()=>r?[...r.filter(e=>e.role!==`supervisor-api`||e.port!==3100&&e.port!==3101)].sort((e,t)=>!!e.active==!!t.active?e.port-t.port:e.active?-1:1):null,[r]);return(0,F.jsxs)(k,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,F.jsx)(D,{title:`运行状态`,subtitle:`核心服务与端口实时状态`,actions:i?(0,F.jsxs)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:[i.length,` 端口`]}):null}),i?(0,F.jsxs)(`div`,{className:`min-h-0 overflow-x-auto`,children:[(0,F.jsxs)(`div`,{className:`grid min-w-[400px] grid-cols-[56px_minmax(0,1fr)_auto_66px] items-center gap-2 border-b border-border/60 bg-muted/60 px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,F.jsx)(`span`,{children:`端口`}),(0,F.jsx)(`span`,{children:`服务`}),(0,F.jsx)(`span`,{className:`text-right`,children:`归属`}),(0,F.jsx)(`span`,{className:`text-right`,children:`状态`})]}),(0,F.jsx)(`div`,{className:`max-h-[340px] overflow-y-auto overscroll-contain`,children:i.map((n,r)=>(0,F.jsxs)(`div`,{className:t(`grid grid-cols-[56px_minmax(0,1fr)_auto_66px] items-center gap-2 px-4 py-2 hover:bg-muted/40`,r>0&&`border-t border-border/50`),children:[(0,F.jsx)(`code`,{className:`font-mono text-sm tabular-nums text-foreground`,children:n.port}),(0,F.jsx)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:(0,F.jsx)(`span`,{className:`truncate text-xs text-foreground`,children:L(n)})}),(0,F.jsx)(`div`,{className:`flex justify-end`,children:(0,F.jsx)(O,{tone:I(n.role,n.owner),children:R(n,e)})}),(0,F.jsx)(`div`,{className:`flex justify-end`,children:n.active===!0?(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-status-ok`,children:[(0,F.jsx)(M,{className:`size-3`}),`运行中`]}):n.active===!1?(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-muted-foreground`,children:[(0,F.jsx)(M,{className:`size-3 opacity-50`}),`未运行`]}):(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-muted-foreground`,children:[(0,F.jsx)(M,{className:`size-3 opacity-40`}),`状态未知`]})})]},n.port+`-`+n.owner))})]}):(0,F.jsx)(`div`,{className:`px-5 py-6 text-center text-xs text-muted-foreground`,children:`运行状态加载中…`})]})}var B=new Set([`dist_registry_selected`,`gui_autostart_changed`,`autostart_changed`,`lan_panel_changed`,`lan_dsh_token_updated`]);function V(){let{snap:e}=u(),{busy:n,run:r}=w(),[i,p]=(0,P.useState)(!1),[C,D]=(0,P.useState)(null),O=e.status,A=O?.native,M=A?.installed??!1,I=A?.state||(M?`installed`:`uninstalled`),L=I===`installing`,R=L||I===`uninstalling`,V=O?.version,W=O?.upgrade,G=x[O?.phase??``]??{label:O?.phase||`未知`,tone:`off`},K=!!O?.dshPid,q=W?.state===`running`,J=(0,P.useMemo)(()=>e.events.filter(e=>!B.has(e.type)),[e.events]);async function Y(){await r(`dsh`,()=>K?l.lifecycleStop(`dsh`):l.lifecycleStart(`dsh`),{success:K?`正在停止 DSH…`:`正在启动 DSH…`})}async function X(){await r(`web`,()=>l.instanceOpenWeb(`main`))}async function Z(){await r(`chk`,async()=>{let e=await l.nativeCheckUpdate();if(e?.ok===!1){c.error(e.error||`检测失败`);return}e?.updateAvailable&&e.latest?c.success(`发现新版本 `+e.latest+(e.installed?`(当前 `+e.installed+`),可一键升级`:``)):c.success(`已是最新版本`+(e.installed?`(`+e.installed+`)`:``))})}async function Q(){p(!1),await r(`upg`,()=>l.nativeUpgrade(),{success:`升级已开始,请耐心等待…`})}async function te(){confirm(`将在线安装最新版 DeepSeek Harness(需数分钟,自动适配最快镜像源)。确定继续?`)&&await r(`inst`,()=>l.nativeInstall(),{success:`开始安装 DeepSeek Harness…`})}async function ne(){confirm(`将彻底卸载 DeepSeek Harness:删除全部文件、数据、缓存与日志,不留残留。确定继续?`)&&await r(`uni`,()=>l.nativeUninstall(),{success:`开始卸载…`})}(0,P.useEffect)(()=>{M&&l.instances().then(e=>{let t=e?.native?.guardian;typeof t==`boolean`&&D(t)}).catch(()=>{})},[M,O?.dshPid]);async function re(){let e=C!==!0;await r(`gu`,()=>l.nativeSettings({guardian:e}).then(e=>{let t=e?.main?.guardian;return typeof t==`boolean`&&D(t),e}),{success:e?`已开启 DSH 进程守护(崩溃自动拉起)`:`已关闭 DSH 进程守护(崩溃后不再自动拉起)`,refresh:!1})}let $=M&&(A?.version||V?.installed)||`—`;return(0,F.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,F.jsxs)(k,{children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 @min-[720px]:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-5 border-b border-border px-6 py-5 md:border-b-0 md:border-r`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,F.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,F.jsx)(`h3`,{className:`truncate text-xl font-semibold tracking-[-0.01em] text-foreground`,children:`DeepSeek Harness`}),(0,F.jsxs)(`span`,{className:`shrink-0 font-mono text-sm text-muted-foreground`,children:[`v`,$]})]}),n===`chk`?(0,F.jsxs)(a,{size:`chip`,disabled:!0,children:[(0,F.jsx)(_,{className:`size-3 animate-spin`}),`检测中…`]}):V?.updateAvailable&&V.latest?(0,F.jsxs)(a,{className:`text-primary-foreground`,size:`chip`,onClick:()=>p(!0),children:[(0,F.jsx)(j,{className:`size-3`}),`升级到 v`,V.latest]}):q?(0,F.jsxs)(a,{size:`chip`,disabled:!0,children:[(0,F.jsx)(_,{className:`size-3 animate-spin`}),`升级中…`]}):(0,F.jsxs)(a,{className:`bg-primary/10 text-primary hover:bg-primary/15`,onClick:()=>void Z(),size:`chip`,variant:`ghost`,children:[(0,F.jsx)(_,{className:`size-3`}),`检测更新`]})]}),R?(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(T,{tone:`boot`,ping:!0}),(0,F.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:L?`正在安装 DeepSeek Harness…`:`正在卸载 DeepSeek Harness…`})]}):(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(T,{tone:G.tone,ping:G.tone===`ok`}),(0,F.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:G.label})]}),q&&W?(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,F.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}),`正在升级(`,W.step||W.targetVersion||``,`)…`]}):null,W?.state===`failed`?(0,F.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`升级失败:`,W.lastError||`未知原因`,W.rolledBack?`(已回滚)`:``]}):null,R&&(A?.installLog??[]).length?(0,F.jsx)(`pre`,{className:`max-h-[120px] overflow-auto whitespace-pre-wrap break-all rounded-md bg-muted/70 p-3 font-mono text-xs leading-relaxed text-muted-foreground`,children:(A?.installLog??[]).slice(-6).join(`
1
+ import{A as e,E as t,L as n,O as r,P as i,T as a,_ as o,b as s,g as ee,k as c,r as l,t as u,v as d,y as f,z as p}from"./supervisor-BVac7io-.js";import{t as m}from"./external-link-SYs4QOvn.js";import{n as h,t as g}from"./rocket-Dt6NGQXE.js";import{t as _}from"./refresh-cw-CQuKs_Tk.js";import{t as v}from"./shield-check-B-D3XDKa.js";import{c as y,f as b,n as x,o as S,t as C}from"./supervisor-DwJMunGH.js";import{t as w}from"./useSupervisorAction-B1Piyga4.js";import{c as T,i as E,n as D,o as O,t as k}from"./widgets-DMpjcPY5.js";import{t as A}from"./format-QeaTKFhQ.js";var j=i(`arrow-up-right`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),M=i(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),N=i(`square-terminal`,[[`path`,{d:`m7 11 2-2-2-2`,key:`1lz0vl`}],[`path`,{d:`M11 13h4`,key:`1p7l4v`}],[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}]]),P=p(n(),1),F=r();function I(e,t){return e===`dsh-main`||e===`supervisor-api`?`boot`:(t||``).startsWith(`inst:`)?`ok`:e===`relay`?`warn`:e.startsWith(`managed:`)?`boot`:`off`}function L(e){let t={"dsh-main":`DSH 主实例`,"supervisor-api":`管家 API`,user:`沙箱实例`,relay:`局域网隧道`,oauthCallback:`登录回调`,proxyInstance:`反代实例`,providerApi:`供应商 API`,"managed:router-daemon":`智能路由`,"managed:lan-daemon":`远程控制`,dynamic:`动态端口`},n=/^managed:(.+)$/.exec(e.role);return n?t[e.role]??n[1]:t[e.role]??e.role}function R(e,t){let n=e.owner||``;if(e.role===`proxyInstance`){let e=(n.split(`:`).pop()||``).slice(-4),r=(t??[]).find(t=>(t.accounts??[]).some(t=>(t.maskedKey||``).endsWith(e)));return r?r.name:`反代`}return n.startsWith(`inst:`)?`沙箱实例`:n.startsWith(`system:`)?`系统`:n.startsWith(`relay:`)?`局域网隧道`:n.startsWith(`dynamic:`)?`动态`:n.startsWith(`providerApi:`)?`供应商`:n.startsWith(`oauth:`)?`登录回调`:n===`router-daemon`||e.role===`managed:router-daemon`?`智能路由`:n===`lan-daemon`||e.role===`managed:lan-daemon`?`远程控制`:e.role===`oauthCallback`?`登录回调`:e.role}function z({providers:e=[]}){let{snap:n}=u(),r=n.ports?.records??null,i=(0,P.useMemo)(()=>r?[...r.filter(e=>e.role!==`supervisor-api`||e.port!==3100&&e.port!==3101)].sort((e,t)=>!!e.active==!!t.active?e.port-t.port:e.active?-1:1):null,[r]);return(0,F.jsxs)(k,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,F.jsx)(D,{title:`运行状态`,subtitle:`核心服务与端口实时状态`,actions:i?(0,F.jsxs)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:[i.length,` 端口`]}):null}),i?(0,F.jsxs)(`div`,{className:`min-h-0 overflow-x-auto`,children:[(0,F.jsxs)(`div`,{className:`grid min-w-[400px] grid-cols-[56px_minmax(0,1fr)_auto_66px] items-center gap-2 border-b border-border/60 bg-muted/60 px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:[(0,F.jsx)(`span`,{children:`端口`}),(0,F.jsx)(`span`,{children:`服务`}),(0,F.jsx)(`span`,{className:`text-right`,children:`归属`}),(0,F.jsx)(`span`,{className:`text-right`,children:`状态`})]}),(0,F.jsx)(`div`,{className:`max-h-[340px] overflow-y-auto overscroll-contain`,children:i.map((n,r)=>(0,F.jsxs)(`div`,{className:t(`grid grid-cols-[56px_minmax(0,1fr)_auto_66px] items-center gap-2 px-4 py-2 hover:bg-muted/40`,r>0&&`border-t border-border/50`),children:[(0,F.jsx)(`code`,{className:`font-mono text-sm tabular-nums text-foreground`,children:n.port}),(0,F.jsx)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:(0,F.jsx)(`span`,{className:`truncate text-xs text-foreground`,children:L(n)})}),(0,F.jsx)(`div`,{className:`flex justify-end`,children:(0,F.jsx)(O,{tone:I(n.role,n.owner),children:R(n,e)})}),(0,F.jsx)(`div`,{className:`flex justify-end`,children:n.active===!0?(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-status-ok`,children:[(0,F.jsx)(M,{className:`size-3`}),`运行中`]}):n.active===!1?(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-muted-foreground`,children:[(0,F.jsx)(M,{className:`size-3 opacity-50`}),`未运行`]}):(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-muted-foreground`,children:[(0,F.jsx)(M,{className:`size-3 opacity-40`}),`状态未知`]})})]},n.port+`-`+n.owner))})]}):(0,F.jsx)(`div`,{className:`px-5 py-6 text-center text-xs text-muted-foreground`,children:`运行状态加载中…`})]})}var B=new Set([`dist_registry_selected`,`gui_autostart_changed`,`autostart_changed`,`lan_panel_changed`,`lan_dsh_token_updated`]);function V(){let{snap:e}=u(),{busy:n,run:r}=w(),[i,p]=(0,P.useState)(!1),[C,D]=(0,P.useState)(null),O=e.status,A=O?.native,M=A?.installed??!1,I=A?.state||(M?`installed`:`uninstalled`),L=I===`installing`,R=L||I===`uninstalling`,V=O?.version,W=O?.upgrade,G=x[O?.phase??``]??{label:O?.phase||`未知`,tone:`off`},K=!!O?.dshPid,q=W?.state===`running`,J=(0,P.useMemo)(()=>e.events.filter(e=>!B.has(e.type)),[e.events]);async function Y(){await r(`dsh`,()=>K?l.lifecycleStop(`dsh`):l.lifecycleStart(`dsh`),{success:K?`正在停止 DSH…`:`正在启动 DSH…`})}async function X(){await r(`web`,()=>l.instanceOpenWeb(`main`))}async function Z(){await r(`chk`,async()=>{let e=await l.nativeCheckUpdate();if(e?.ok===!1){c.error(e.error||`检测失败`);return}e?.updateAvailable&&e.latest?c.success(`发现新版本 `+e.latest+(e.installed?`(当前 `+e.installed+`),可一键升级`:``)):c.success(`已是最新版本`+(e.installed?`(`+e.installed+`)`:``))})}async function Q(){p(!1),await r(`upg`,()=>l.nativeUpgrade(),{success:`升级已开始,请耐心等待…`})}async function te(){confirm(`将在线安装最新版 DeepSeek Harness(需数分钟,自动适配最快镜像源)。确定继续?`)&&await r(`inst`,()=>l.nativeInstall(),{success:`开始安装 DeepSeek Harness…`})}async function ne(){confirm(`将彻底卸载 DeepSeek Harness:删除全部文件、数据、缓存与日志,不留残留。确定继续?`)&&await r(`uni`,()=>l.nativeUninstall(),{success:`开始卸载…`})}(0,P.useEffect)(()=>{M&&l.instances().then(e=>{let t=e?.native?.guardian;typeof t==`boolean`&&D(t)}).catch(()=>{})},[M,O?.dshPid]);async function re(){let e=C!==!0;await r(`gu`,()=>l.nativeSettings({guardian:e}).then(e=>{let t=e?.main?.guardian;return typeof t==`boolean`&&D(t),e}),{success:e?`已开启 DSH 进程守护(崩溃自动拉起)`:`已关闭 DSH 进程守护(崩溃后不再自动拉起)`,refresh:!1})}let $=M&&(A?.version||V?.installed)||`—`;return(0,F.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,F.jsxs)(k,{children:[(0,F.jsxs)(`div`,{className:`grid grid-cols-1 @min-[720px]:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]`,children:[(0,F.jsxs)(`div`,{className:`flex flex-col gap-5 border-b border-border px-6 py-5 md:border-b-0 md:border-r`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,F.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,F.jsx)(`h3`,{className:`truncate text-xl font-semibold tracking-[-0.01em] text-foreground`,children:`DeepSeek Harness`}),(0,F.jsxs)(`span`,{className:`shrink-0 font-mono text-sm text-muted-foreground`,children:[`v`,$]})]}),n===`chk`?(0,F.jsxs)(a,{size:`chip`,disabled:!0,children:[(0,F.jsx)(_,{className:`size-3 animate-spin`}),`检测中…`]}):V?.updateAvailable&&V.latest?(0,F.jsxs)(a,{className:`text-primary-foreground`,size:`chip`,onClick:()=>p(!0),children:[(0,F.jsx)(j,{className:`size-3`}),`升级到 v`,V.latest]}):q?(0,F.jsxs)(a,{size:`chip`,disabled:!0,children:[(0,F.jsx)(_,{className:`size-3 animate-spin`}),`升级中…`]}):(0,F.jsxs)(a,{className:`bg-primary/10 text-primary hover:bg-primary/15`,onClick:()=>void Z(),size:`chip`,variant:`ghost`,children:[(0,F.jsx)(_,{className:`size-3`}),`检测更新`]})]}),R?(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(T,{tone:`boot`,ping:!0}),(0,F.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:L?`正在安装 DeepSeek Harness…`:`正在卸载 DeepSeek Harness…`})]}):(0,F.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,F.jsx)(T,{tone:G.tone,ping:G.tone===`ok`}),(0,F.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:G.label})]}),q&&W?(0,F.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,F.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}),`正在升级(`,W.step||W.targetVersion||``,`)…`]}):null,W?.state===`failed`?(0,F.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`升级失败:`,W.lastError||`未知原因`,W.rolledBack?`(已回滚)`:``]}):null,R&&(A?.installLog??[]).length?(0,F.jsx)(`pre`,{className:`max-h-[120px] overflow-auto whitespace-pre-wrap break-all rounded-md bg-muted/70 p-3 font-mono text-xs leading-relaxed text-muted-foreground`,children:(A?.installLog??[]).slice(-6).join(`
2
2
  `)}):null]}),(0,F.jsx)(`div`,{className:`flex items-center bg-[image:var(--panel-accent-gradient)] px-6 py-5`,children:(0,F.jsxs)(`div`,{className:`grid w-full grid-cols-2 gap-x-6 gap-y-4 @min-[560px]:grid-cols-4`,children:[(0,F.jsx)(E,{icon:(0,F.jsx)(b,{className:`size-4`}),label:`端口`,value:O?.dshPort?String(O.dshPort):`—`,mono:!0}),(0,F.jsx)(E,{icon:(0,F.jsx)(N,{className:`size-4`}),label:`PID`,value:O?.dshPid?String(O.dshPid):`—`,mono:!0}),(0,F.jsx)(E,{icon:(0,F.jsx)(_,{className:`size-4`}),label:`重启次数`,value:String(O?.restartCount??0),mono:!0}),(0,F.jsx)(E,{icon:(0,F.jsx)(j,{className:`size-4`}),label:`最近故障`,value:O?.lastFailure?S(O?.lastFailure):`无`,warn:!!O?.lastFailure})]})})]}),(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-t border-border/60 px-6 py-3`,children:[(0,F.jsx)(`div`,{className:`hidden lg:block`,children:(0,F.jsx)(H,{})}),(0,F.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[!M&&!R?(0,F.jsxs)(a,{size:`sm`,disabled:n===`inst`,onClick:()=>void te(),children:[(0,F.jsx)(g,{className:`size-4`}),`安装 DSH`]}):M&&!R&&!q?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(a,{disabled:!K,onClick:()=>void X(),size:`sm`,variant:`outline`,className:`hidden md:inline-flex`,children:[(0,F.jsx)(m,{className:`size-4`}),`DSH Web`]}),(0,F.jsx)(a,{disabled:n===`dsh`,onClick:()=>void Y(),size:`sm`,variant:`outline`,children:K?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(h,{className:`size-4 text-status-error`}),`停止 DSH`]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(g,{className:`size-4 text-primary`}),`启动 DSH`]})}),(0,F.jsx)(`span`,{"aria-hidden":`true`,className:`mx-1 h-5 w-px bg-border`}),(0,F.jsxs)(a,{className:`h-[30px]`,disabled:n===`gu`||C===null,onClick:()=>void re(),size:`sm`,variant:`outline`,children:[(0,F.jsx)(v,{className:t(`size-4`,C===!0?`text-status-ok`:`text-muted-foreground`)}),C===!0?`停止守护`:`启动守护`]})]}):null,M&&!R?(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)(a,{className:`hidden h-[30px] md:inline-flex`,disabled:n===`uni`,onClick:()=>void ne(),size:`sm`,variant:`destructive`,children:[(0,F.jsx)(y,{className:`size-4`}),`卸载 DSH`]})}):null]})]})]}),(0,F.jsxs)(`div`,{className:`grid items-start gap-4 @min-[860px]:grid-cols-[minmax(0,1fr)_420px]`,children:[(0,F.jsx)(U,{events:J}),(0,F.jsx)(z,{providers:e.providers?.providers??[]})]}),(0,F.jsx)(ee,{open:i,onOpenChange:p,children:(0,F.jsxs)(o,{className:`max-w-[420px]`,children:[(0,F.jsx)(f,{children:(0,F.jsx)(s,{children:`升级 DeepSeek Harness`})}),(0,F.jsxs)(`div`,{className:`grid gap-3`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-center gap-3 rounded-md bg-muted px-4 py-3`,children:[(0,F.jsxs)(`div`,{className:`text-center`,children:[(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`当前版本`}),(0,F.jsx)(`strong`,{className:`font-mono text-base text-foreground`,children:V?.installed||$})]}),(0,F.jsx)(j,{className:`size-4 text-muted-foreground`}),(0,F.jsxs)(`div`,{className:`text-center`,children:[(0,F.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`新版本`}),(0,F.jsx)(`strong`,{className:`font-mono text-base text-primary`,children:V?.latest||`—`})]})]}),(0,F.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:`升级将先停止 DSH、安装新版本后自动拉起(需数分钟)。期间进行中的请求会中断,失败会自动回滚到当前版本。`})]}),(0,F.jsxs)(d,{children:[(0,F.jsx)(a,{onClick:()=>p(!1),variant:`outline`,children:`取消`}),(0,F.jsx)(a,{disabled:n===`upg`||q,onClick:()=>void Q(),children:n===`upg`||q?`升级中…`:`开始升级`})]})]})})]})}function H(){let[t,n]=(0,P.useState)(null);return(0,P.useEffect)(()=>{let e=!0,t=async()=>{let t=await l.nodeLts().catch(()=>null);e&&n(t)};t();let r=setInterval(t,6e5);return()=>{e=!1,clearInterval(r)}},[]),t?.current?(0,F.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,F.jsxs)(`span`,{className:`whitespace-nowrap`,title:t.suggested||void 0,children:[`环境检测 · Node v`,t.current]}),t.ltsLine===!1?(0,F.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap rounded-full bg-warning-background px-2 py-0.5 font-semibold text-warning`,children:[(0,F.jsx)(e,{className:`size-3`}),`非 LTS 线(建议偶数主版本)`]}):t.ltsLine===!0?(0,F.jsx)(`span`,{className:`hidden whitespace-nowrap text-muted-foreground/70 sm:inline`,children:`LTS 线`}):null]}):(0,F.jsx)(`span`,{className:`min-w-[120px] text-xs text-muted-foreground`,children:`环境检测…`})}function U({events:e}){let[t,n]=(0,P.useState)(12),r=e.length;(0,P.useEffect)(()=>{n(12)},[e]);let i=(0,P.useRef)(null),a=(0,P.useRef)(!1);(0,P.useEffect)(()=>{let e=i.current;if(!e)return;let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(a.current||(a.current=!0,n(e=>Math.min(e+12,r)),setTimeout(()=>{a.current=!1},80)))},{rootMargin:`120px 0px`});return t.observe(e),()=>t.disconnect()},[r]);let o=e.slice(0,t),s=t<r;return(0,F.jsxs)(k,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,F.jsx)(D,{title:`事件日志`,subtitle:`核心运行状态遥测`,actions:(0,F.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:r})}),r?(0,F.jsxs)(`div`,{className:`flex max-h-[450px] min-h-0 flex-col overflow-y-auto overscroll-contain`,children:[o.map((e,t)=>(0,F.jsx)(W,{e},e.seq??t)),(0,F.jsx)(`div`,{ref:i,className:`px-5 py-2 text-center text-[11px] text-muted-foreground`,children:s?`下滑加载更多…`:`已加载全部`})]}):(0,F.jsx)(`div`,{className:`px-5 py-6 text-center text-xs text-muted-foreground`,children:`暂无核心运行状态事件`})]})}function W({e}){let t=K[e.type]??`boot`,n=C[e.type]??e.type,r=G(e);return(0,F.jsxs)(`div`,{className:`grid min-w-0 grid-cols-[64px_auto_minmax(0,1fr)] items-center gap-2.5 border-b border-border/60 px-5 py-2 last:border-b-0 max-[640px]:grid-cols-[56px_auto_minmax(0,1fr)] max-[640px]:gap-2`,children:[(0,F.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:A(e.ts)}),(0,F.jsx)(O,{tone:t,children:n}),(0,F.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:r})]})}function G(e){let t=e.data;if(!t)return``;let n=e=>Number(e??0).toLocaleString(`en-US`);if(typeof t.message==`string`)return t.message;if(typeof t.reason==`string`)return S(t.reason);if(typeof t.desired==`string`)return`期望 `+t.desired;if(e.type===`router_usage`)return(t.model||``)+(t.model?` · `:``)+n(t.tokens)+` tokens`;if(e.type===`router_pick`)return[t.provider||``,t.key||``].filter(Boolean).join(` · `);if(e.type===`account_ready`||e.type===`account_frozen`||e.type===`account_banned`||e.type===`account_recovered`||e.type===`account_review`||e.type===`account_exhausted`)return(t.key||``)+(t.key?` · `:``)+(t.provider||``);if(e.type===`provider_quota_refreshed`)return(t.provider||``)+` 额度已刷新`;if(e.type===`proxy_update_available`)return[t.pkg||``,t.from||``,t.to||``].filter(Boolean).join(` → `);if(e.type===`proxy_instance_started`)return`port=`+(t.port??``)+(t.pid?` pid=`+t.pid:``);if(e.type===`dsh_guardian_changed`||e.type===`inst_guardian_changed`||e.type===`dsh_remote_changed`||e.type===`dsh_frp_changed`){let n=t.name||(t.id===`main`?`原生 DSH`:t.id||`实例`),r=e.type.includes(`guardian`)?`进程守护`:e.type.includes(`remote`)?`远程控制`:`FRP`;return n+` · `+r+(t.enabled===!0?` → 开启`:` → 关闭`)}let r=[];return t.pid!==void 0&&r.push(`pid=`+t.pid),t.port!==void 0&&r.push(`port=`+String(t.port)),t.version!==void 0&&r.push(`v`+String(t.version)),t.model&&t.tokens!==void 0&&r.push(n(t.tokens)+` tok`),t.ms!==void 0&&r.push(n(t.ms)+`ms`),r.join(` · `)}var K={running:`ok`,adopted:`ok`,spawned:`ok`,main_instance_registered:`ok`,upgrade_installed:`ok`,upgrade_done:`ok`,api_listening:`ok`,account_ready:`ok`,account_confirmed:`ok`,account_recovered:`ok`,proxy_instance_started:`ok`,proxy_update_applied:`ok`,router_provider_activated:`ok`,router_provider_endpoint:`ok`,inst_running:`ok`,inst_added:`ok`,inst_started:`ok`,lan_instance_started:`ok`,frpc_installed:`ok`,frpc_started:`ok`,plugin_install_done:`ok`,native_installed:`ok`,inst_upgraded:`ok`,plugin_update_done:`ok`,account_frozen:`err`,account_banned:`err`,dsh_exited:`err`,unhealthy:`err`,spawn_failed:`err`,spawn_error:`err`,upgrade_failed:`err`,api_error:`err`,proxy_instance_failed:`err`,inst_failed:`err`,inst_start_failed:`err`,native_install_failed:`err`,native_uninstall_failed:`err`,plugin_install_job_failed:`err`,plugin_update_job_failed:`err`,plugin_uninstall_job_failed:`err`,frpc_install_failed:`err`,router_stream_aborted:`err`,sigkill_sent:`err`,start_timeout:`err`,crash_loop_entered:`err`,guard_exit:`warn`,version_check_failed:`warn`,restart_triggered:`warn`,dsh_not_installed:`warn`,sigterm_sent:`warn`,account_review:`warn`,dsh_guardian_changed:`warn`,inst_guardian_changed:`warn`,dsh_remote_changed:`warn`,dsh_frp_changed:`warn`,proxy_update_available:`warn`,upgrade_started:`warn`,upgrade_stopping_dsh:`warn`,inst_restarted:`warn`,lan_frp_changed:`warn`,native_uninstall_started:`warn`,account_discarded:`off`,router_stopped:`off`,proxy_instance_stopped:`off`,inst_stopped:`off`,inst_removed:`off`,lan_instance_removed:`off`,frpc_stopped:`off`,plugin_uninstall_done:`off`,native_uninstalled:`off`,upgrade_skipped:`off`,router_provider_deactivated:`off`,stop:`off`};export{V as OverviewPage};
@@ -1,4 +1,4 @@
1
- import{E as e,L as t,O as n,P as r,T as i,_ as a,b as o,c as s,d as c,f as l,g as u,h as d,k as f,l as p,p as m,r as h,s as g,u as _,w as v,y,z as b}from"./supervisor-BVac7io-.js";import{n as x,t as S}from"./rocket-Dt6NGQXE.js";import{t as C}from"./refresh-cw-CQuKs_Tk.js";import{t as w}from"./jobs-BjLbfJTM.js";import{c as T,u as E}from"./supervisor-DX8HnT5i.js";import{t as D}from"./useSupervisorAction-B1Piyga4.js";import{n as O,o as k,t as A}from"./widgets-DMpjcPY5.js";var j=r(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),M=r(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),N=b(t(),1);function P(e){return e>=1073741824?`${(e/1024/1024/1024).toFixed(1)} GB`:e>=1048576?`${(e/1024/1024).toFixed(0)} MB`:e>=1024?`${(e/1024).toFixed(0)} KB`:`${e} B`}var F=n(),I=24;async function L(e,t,n){if(!e.length)return;let r=f.loading(`正在`+t+` `+n+` 个插件…(0/`+e.length+`)`),i=0,a=0;for(let o of e){let s=await w(()=>h.pluginInstallStatus(o));s.state===`done`?i++:s.state===`failed`&&a++,f.loading(`正在`+t+` `+n+` 个插件…(`+(i+a)+`/`+e.length+`)`,{id:r})}a===0?f.success(t+`完成(`+i+`/`+e.length+`)`,{id:r}):f.warning(t+`结束:成功 `+i+`,失败 `+a,{id:r})}function R(){let[t,n]=(0,N.useState)(`market`);return(0,F.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,F.jsx)(`div`,{className:`flex gap-1 rounded-lg bg-muted p-1`,children:[`market`,`installed`].map(r=>(0,F.jsxs)(i,{className:e(`font-medium`,t===r?`bg-card text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-card/60 hover:text-foreground`),onClick:()=>n(r),size:`sm`,variant:`ghost`,children:[r===`market`?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(E,{className:`size-3.5`}),r===`market`?`插件商店`:`已安装`]},r))}),t===`market`?(0,F.jsx)(z,{}):null]}),t===`market`?(0,F.jsx)(B,{}):(0,F.jsx)(U,{})]})}function z(){let[t,n]=(0,N.useState)(!1);async function r(){n(!0);try{await h.market(!0),f.success(`插件索引已刷新`)}catch(e){f.error(String(e))}n(!1)}return(0,F.jsxs)(i,{disabled:t,onClick:()=>void r(),size:`chip`,variant:`outline`,children:[(0,F.jsx)(C,{className:e(`size-3.5`,t&&`animate-spin`)}),`刷新`]})}function B(){let[t,n]=(0,N.useState)(null),[r,v]=(0,N.useState)(``),[b,x]=(0,N.useState)(`all`),[S,C]=(0,N.useState)(`all`),[T,E]=(0,N.useState)(0),[D,O]=(0,N.useState)(null),[A,M]=(0,N.useState)([]),[P,L]=(0,N.useState)(`native`);(0,N.useEffect)(()=>{let e=!0;return h.market().then(t=>{e&&(n(t),E(I))}).catch(()=>void 0),()=>{e=!1}},[]);let R=(0,N.useMemo)(()=>{if(!t)return[];let e=r.trim().toLowerCase();return t.plugins.filter(t=>(b===`all`||t.category===b)&&(S===`all`||t.source===S)&&(!e||(t.name+` `+(t.description||``)).toLowerCase().includes(e)))},[t,r,b,S]),z=(0,N.useMemo)(()=>{let e={};for(let n of t?.plugins??[])e[n.category]=(e[n.category]||0)+1;return Object.entries(e).sort((e,t)=>t[1]-e[1])},[t]);async function B(e){O(e),L(`native`);try{let e=await h.instances();M((e.instances??[]).filter(e=>e.domain===`sandbox`).map(e=>({id:e.id,name:e.name})))}catch{M([])}}async function U(){if(D)try{let e=await h.pluginInstall(D.name,P);if(e.ok===!1){f.error(e.error||`安装失败`);return}if(O(null),e.jobId){let t=f.loading(`正在安装 `+D.name+`…`),n=await w(()=>h.pluginInstallStatus(e.jobId));n.state===`done`?f.success(`已安装 `+D.name,{id:t}):n.state===`failed`?f.error(`安装失败:`+(n.error||`未知原因`),{id:t}):f.warning(`安装仍在进行(超时未完成,可稍后查看)`,{id:t})}else f.success(`安装任务已提交`)}catch(e){f.error(String(e))}}return(0,F.jsxs)(`div`,{className:`grid content-start gap-3`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsxs)(`div`,{className:`relative min-w-[220px] flex-1`,children:[(0,F.jsx)(j,{className:`absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,F.jsx)(d,{className:`pl-8`,placeholder:`搜索插件名称、描述…`,value:r,onChange:e=>v(e.target.value)})]}),(0,F.jsxs)(g,{value:b,onValueChange:x,children:[(0,F.jsx)(_,{className:`h-9 w-[150px] shrink-0`,children:(0,F.jsx)(c,{placeholder:`全部分类`})}),(0,F.jsxs)(s,{children:[(0,F.jsx)(p,{value:`all`,children:`全部分类`}),z.map(([e,t])=>(0,F.jsxs)(p,{value:e,children:[e,` (`,t,`)`]},e))]})]}),(0,F.jsxs)(g,{value:S,onValueChange:C,children:[(0,F.jsx)(_,{className:`h-9 w-[130px] shrink-0`,children:(0,F.jsx)(c,{placeholder:`全部来源`})}),(0,F.jsxs)(s,{children:[(0,F.jsx)(p,{value:`all`,children:`全部来源`}),(0,F.jsx)(p,{value:`npm`,children:`npm`}),(0,F.jsx)(p,{value:`github`,children:`GitHub`}),(0,F.jsx)(p,{value:`community`,children:`社区`}),(0,F.jsx)(p,{value:`official`,children:`官方`})]})]})]}),t?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`共 `,t.plugins.length,` 个插件 · 更新 `,t.indexedAt?new Date(t.indexedAt).toLocaleString():`—`,` · npm `,t.sources?.npm||0,` · GitHub `,t.sources?.github||0,` · 社区 `,t.sources?.community||0]}),R.length?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{className:`grid grid-cols-1 gap-3 @min-[640px]:grid-cols-2 @min-[1000px]:grid-cols-3`,children:R.slice(0,T).map(e=>(0,F.jsxs)(`div`,{className:`flex min-h-[150px] flex-col rounded-lg border border-border bg-card p-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,F.jsx)(`strong`,{className:`truncate font-mono text-sm text-foreground`,children:e.name}),(0,F.jsx)(k,{tone:H(e.source),children:V(e.source)})]}),(0,F.jsx)(`p`,{className:`mt-2 line-clamp-3 min-h-[36px] text-xs leading-relaxed text-muted-foreground`,children:e.description||`(无描述)`}),(0,F.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,F.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:e.category}),e.version?(0,F.jsxs)(`span`,{className:`font-mono`,children:[`v`,e.version]}):null,e.stars?(0,F.jsxs)(`span`,{children:[`⭐`,e.stars]}):null]}),(0,F.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2 pt-3`,children:[(0,F.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.author||``}),(0,F.jsx)(i,{onClick:()=>void B(e),size:`chip`,children:`安装`})]})]},e.name))}),T<R.length?(0,F.jsxs)(i,{className:`justify-self-center`,onClick:()=>E(e=>e+I),variant:`outline`,children:[`加载更多(`,T,`/`,R.length,`)`]}):null]}):(0,F.jsx)(`div`,{className:`grid place-items-center rounded-lg border border-dashed border-border py-16 text-sm text-muted-foreground`,children:`无匹配插件`})]}):(0,F.jsx)(`div`,{className:`grid place-items-center py-20 text-sm text-muted-foreground`,children:`加载插件索引…`}),(0,F.jsx)(u,{open:!!D,onOpenChange:e=>!e&&O(null),children:(0,F.jsxs)(a,{className:`max-w-[400px]`,children:[(0,F.jsx)(y,{children:(0,F.jsxs)(o,{children:[`安装插件 — `,D?.name]})}),(0,F.jsx)(`div`,{className:`grid gap-2`,children:(0,F.jsx)(l,{value:P,onValueChange:L,className:`grid gap-2`,children:[[`native`,`原生实例`],[`all`,`所有实例(含原生)`]].concat(A.map(e=>[`id:`+e.id,e.name+`(`+e.id.slice(0,8)+`…)`])).map(([t,n])=>(0,F.jsxs)(`label`,{className:e(`flex cursor-pointer items-center gap-2 rounded-md border px-3 py-2 text-sm`,P===t?`border-primary/40 bg-primary/[0.05] text-foreground`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,F.jsx)(m,{value:t}),n]},t))})}),(0,F.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,F.jsx)(i,{onClick:()=>O(null),variant:`outline`,children:`取消`}),(0,F.jsx)(i,{onClick:()=>void U(),children:`开始安装`})]})]})})]})}var V=e=>({npm:`npm`,github:`GitHub`,community:`社区`,official:`官方`})[e]??e,H=e=>e===`official`?`boot`:e===`npm`?`ok`:e===`github`?`warn`:`off`;function U(){let[t,n]=(0,N.useState)(null),[r,a]=(0,N.useState)(`all`),[o,s]=(0,N.useState)(new Set),[c,l]=(0,N.useState)(new Map),[u,d]=(0,N.useState)(!1),{busy:p,run:m}=D(),g=async()=>{let e=await h.pluginsInstalled().catch(()=>null);n(e)};(0,N.useEffect)(()=>{g()},[]);let _=t?.thirdParty??[],y=e=>e.targets&&e.targets.length?e.targets:[`native`],b=_.filter(e=>r===`all`||y(e).includes(r)),w=e=>s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),j=b.length>0&&b.every(e=>o.has(e.name)),M=()=>s(j?new Set:new Set(b.map(e=>e.name))),I=b.filter(e=>o.has(e.name)),R=I.some(e=>c.has(e.name)),z=I.filter(e=>e.enabled),B=I.filter(e=>!e.enabled);async function V(){d(!0);try{let e=await h.pluginsCheckUpdates(!0),t=new Map;for(let n of e.plugins??[]){if(!n.updateAvailable)continue;let e=n.targets?.find(e=>e.latest)?.latest||``;t.set(n.name,e)}l(t),f.success(t.size?`发现 `+t.size+` 个可更新插件`:`全部插件已是最新`),await g()}catch(e){f.error(String(e))}d(!1)}async function H(){let e=I.filter(e=>c.has(e.name)).map(e=>e.name);if(!e.length){f.info(`所选插件均无可用更新`);return}s(new Set),l(t=>{let n=new Map(t);for(let t of e)n.delete(t);return n}),await m(`upd-sel`,async()=>{let t=[];for(let n of e)try{let e=await h.pluginUpdate(n);e.jobId&&t.push(e.jobId)}catch{}await L(t,`更新`,e.length)},{success:`已提交 `+e.length+` 个插件的更新任务`,refresh:!1,onDone:()=>void g()})}async function U(){let e=I.map(e=>e.name);confirm(`将卸载所选 `+e.length+` 个插件:
1
+ import{E as e,L as t,O as n,P as r,T as i,_ as a,b as o,c as s,d as c,f as l,g as u,h as d,k as f,l as p,p as m,r as h,s as g,u as _,w as v,y,z as b}from"./supervisor-BVac7io-.js";import{n as x,t as S}from"./rocket-Dt6NGQXE.js";import{t as C}from"./refresh-cw-CQuKs_Tk.js";import{t as w}from"./jobs-BjLbfJTM.js";import{c as T,u as E}from"./supervisor-DwJMunGH.js";import{t as D}from"./useSupervisorAction-B1Piyga4.js";import{n as O,o as k,t as A}from"./widgets-DMpjcPY5.js";var j=r(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),M=r(`store`,[[`path`,{d:`M15 21v-5a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v5`,key:`slp6dd`}],[`path`,{d:`M17.774 10.31a1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.451 0 1.12 1.12 0 0 0-1.548 0 2.5 2.5 0 0 1-3.452 0 1.12 1.12 0 0 0-1.549 0 2.5 2.5 0 0 1-3.77-3.248l2.889-4.184A2 2 0 0 1 7 2h10a2 2 0 0 1 1.653.873l2.895 4.192a2.5 2.5 0 0 1-3.774 3.244`,key:`o0xfot`}],[`path`,{d:`M4 10.95V19a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8.05`,key:`wn3emo`}]]),N=b(t(),1);function P(e){return e>=1073741824?`${(e/1024/1024/1024).toFixed(1)} GB`:e>=1048576?`${(e/1024/1024).toFixed(0)} MB`:e>=1024?`${(e/1024).toFixed(0)} KB`:`${e} B`}var F=n(),I=24;async function L(e,t,n){if(!e.length)return;let r=f.loading(`正在`+t+` `+n+` 个插件…(0/`+e.length+`)`),i=0,a=0;for(let o of e){let s=await w(()=>h.pluginInstallStatus(o));s.state===`done`?i++:s.state===`failed`&&a++,f.loading(`正在`+t+` `+n+` 个插件…(`+(i+a)+`/`+e.length+`)`,{id:r})}a===0?f.success(t+`完成(`+i+`/`+e.length+`)`,{id:r}):f.warning(t+`结束:成功 `+i+`,失败 `+a,{id:r})}function R(){let[t,n]=(0,N.useState)(`market`);return(0,F.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,F.jsx)(`div`,{className:`flex gap-1 rounded-lg bg-muted p-1`,children:[`market`,`installed`].map(r=>(0,F.jsxs)(i,{className:e(`font-medium`,t===r?`bg-card text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-card/60 hover:text-foreground`),onClick:()=>n(r),size:`sm`,variant:`ghost`,children:[r===`market`?(0,F.jsx)(M,{className:`size-3.5`}):(0,F.jsx)(E,{className:`size-3.5`}),r===`market`?`插件商店`:`已安装`]},r))}),t===`market`?(0,F.jsx)(z,{}):null]}),t===`market`?(0,F.jsx)(B,{}):(0,F.jsx)(U,{})]})}function z(){let[t,n]=(0,N.useState)(!1);async function r(){n(!0);try{await h.market(!0),f.success(`插件索引已刷新`)}catch(e){f.error(String(e))}n(!1)}return(0,F.jsxs)(i,{disabled:t,onClick:()=>void r(),size:`chip`,variant:`outline`,children:[(0,F.jsx)(C,{className:e(`size-3.5`,t&&`animate-spin`)}),`刷新`]})}function B(){let[t,n]=(0,N.useState)(null),[r,v]=(0,N.useState)(``),[b,x]=(0,N.useState)(`all`),[S,C]=(0,N.useState)(`all`),[T,E]=(0,N.useState)(0),[D,O]=(0,N.useState)(null),[A,M]=(0,N.useState)([]),[P,L]=(0,N.useState)(`native`);(0,N.useEffect)(()=>{let e=!0;return h.market().then(t=>{e&&(n(t),E(I))}).catch(()=>void 0),()=>{e=!1}},[]);let R=(0,N.useMemo)(()=>{if(!t)return[];let e=r.trim().toLowerCase();return t.plugins.filter(t=>(b===`all`||t.category===b)&&(S===`all`||t.source===S)&&(!e||(t.name+` `+(t.description||``)).toLowerCase().includes(e)))},[t,r,b,S]),z=(0,N.useMemo)(()=>{let e={};for(let n of t?.plugins??[])e[n.category]=(e[n.category]||0)+1;return Object.entries(e).sort((e,t)=>t[1]-e[1])},[t]);async function B(e){O(e),L(`native`);try{let e=await h.instances();M((e.instances??[]).filter(e=>e.domain===`sandbox`).map(e=>({id:e.id,name:e.name})))}catch{M([])}}async function U(){if(D)try{let e=await h.pluginInstall(D.name,P);if(e.ok===!1){f.error(e.error||`安装失败`);return}if(O(null),e.jobId){let t=f.loading(`正在安装 `+D.name+`…`),n=await w(()=>h.pluginInstallStatus(e.jobId));n.state===`done`?f.success(`已安装 `+D.name,{id:t}):n.state===`failed`?f.error(`安装失败:`+(n.error||`未知原因`),{id:t}):f.warning(`安装仍在进行(超时未完成,可稍后查看)`,{id:t})}else f.success(`安装任务已提交`)}catch(e){f.error(String(e))}}return(0,F.jsxs)(`div`,{className:`grid content-start gap-3`,children:[(0,F.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,F.jsxs)(`div`,{className:`relative min-w-[220px] flex-1`,children:[(0,F.jsx)(j,{className:`absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,F.jsx)(d,{className:`pl-8`,placeholder:`搜索插件名称、描述…`,value:r,onChange:e=>v(e.target.value)})]}),(0,F.jsxs)(g,{value:b,onValueChange:x,children:[(0,F.jsx)(_,{className:`h-9 w-[150px] shrink-0`,children:(0,F.jsx)(c,{placeholder:`全部分类`})}),(0,F.jsxs)(s,{children:[(0,F.jsx)(p,{value:`all`,children:`全部分类`}),z.map(([e,t])=>(0,F.jsxs)(p,{value:e,children:[e,` (`,t,`)`]},e))]})]}),(0,F.jsxs)(g,{value:S,onValueChange:C,children:[(0,F.jsx)(_,{className:`h-9 w-[130px] shrink-0`,children:(0,F.jsx)(c,{placeholder:`全部来源`})}),(0,F.jsxs)(s,{children:[(0,F.jsx)(p,{value:`all`,children:`全部来源`}),(0,F.jsx)(p,{value:`npm`,children:`npm`}),(0,F.jsx)(p,{value:`github`,children:`GitHub`}),(0,F.jsx)(p,{value:`community`,children:`社区`}),(0,F.jsx)(p,{value:`official`,children:`官方`})]})]})]}),t?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`共 `,t.plugins.length,` 个插件 · 更新 `,t.indexedAt?new Date(t.indexedAt).toLocaleString():`—`,` · npm `,t.sources?.npm||0,` · GitHub `,t.sources?.github||0,` · 社区 `,t.sources?.community||0]}),R.length?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(`div`,{className:`grid grid-cols-1 gap-3 @min-[640px]:grid-cols-2 @min-[1000px]:grid-cols-3`,children:R.slice(0,T).map(e=>(0,F.jsxs)(`div`,{className:`flex min-h-[150px] flex-col rounded-lg border border-border bg-card p-4`,children:[(0,F.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,F.jsx)(`strong`,{className:`truncate font-mono text-sm text-foreground`,children:e.name}),(0,F.jsx)(k,{tone:H(e.source),children:V(e.source)})]}),(0,F.jsx)(`p`,{className:`mt-2 line-clamp-3 min-h-[36px] text-xs leading-relaxed text-muted-foreground`,children:e.description||`(无描述)`}),(0,F.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,F.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:e.category}),e.version?(0,F.jsxs)(`span`,{className:`font-mono`,children:[`v`,e.version]}):null,e.stars?(0,F.jsxs)(`span`,{children:[`⭐`,e.stars]}):null]}),(0,F.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2 pt-3`,children:[(0,F.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.author||``}),(0,F.jsx)(i,{onClick:()=>void B(e),size:`chip`,children:`安装`})]})]},e.name))}),T<R.length?(0,F.jsxs)(i,{className:`justify-self-center`,onClick:()=>E(e=>e+I),variant:`outline`,children:[`加载更多(`,T,`/`,R.length,`)`]}):null]}):(0,F.jsx)(`div`,{className:`grid place-items-center rounded-lg border border-dashed border-border py-16 text-sm text-muted-foreground`,children:`无匹配插件`})]}):(0,F.jsx)(`div`,{className:`grid place-items-center py-20 text-sm text-muted-foreground`,children:`加载插件索引…`}),(0,F.jsx)(u,{open:!!D,onOpenChange:e=>!e&&O(null),children:(0,F.jsxs)(a,{className:`max-w-[400px]`,children:[(0,F.jsx)(y,{children:(0,F.jsxs)(o,{children:[`安装插件 — `,D?.name]})}),(0,F.jsx)(`div`,{className:`grid gap-2`,children:(0,F.jsx)(l,{value:P,onValueChange:L,className:`grid gap-2`,children:[[`native`,`原生实例`],[`all`,`所有实例(含原生)`]].concat(A.map(e=>[`id:`+e.id,e.name+`(`+e.id.slice(0,8)+`…)`])).map(([t,n])=>(0,F.jsxs)(`label`,{className:e(`flex cursor-pointer items-center gap-2 rounded-md border px-3 py-2 text-sm`,P===t?`border-primary/40 bg-primary/[0.05] text-foreground`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,F.jsx)(m,{value:t}),n]},t))})}),(0,F.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,F.jsx)(i,{onClick:()=>O(null),variant:`outline`,children:`取消`}),(0,F.jsx)(i,{onClick:()=>void U(),children:`开始安装`})]})]})})]})}var V=e=>({npm:`npm`,github:`GitHub`,community:`社区`,official:`官方`})[e]??e,H=e=>e===`official`?`boot`:e===`npm`?`ok`:e===`github`?`warn`:`off`;function U(){let[t,n]=(0,N.useState)(null),[r,a]=(0,N.useState)(`all`),[o,s]=(0,N.useState)(new Set),[c,l]=(0,N.useState)(new Map),[u,d]=(0,N.useState)(!1),{busy:p,run:m}=D(),g=async()=>{let e=await h.pluginsInstalled().catch(()=>null);n(e)};(0,N.useEffect)(()=>{g()},[]);let _=t?.thirdParty??[],y=e=>e.targets&&e.targets.length?e.targets:[`native`],b=_.filter(e=>r===`all`||y(e).includes(r)),w=e=>s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),j=b.length>0&&b.every(e=>o.has(e.name)),M=()=>s(j?new Set:new Set(b.map(e=>e.name))),I=b.filter(e=>o.has(e.name)),R=I.some(e=>c.has(e.name)),z=I.filter(e=>e.enabled),B=I.filter(e=>!e.enabled);async function V(){d(!0);try{let e=await h.pluginsCheckUpdates(!0),t=new Map;for(let n of e.plugins??[]){if(!n.updateAvailable)continue;let e=n.targets?.find(e=>e.latest)?.latest||``;t.set(n.name,e)}l(t),f.success(t.size?`发现 `+t.size+` 个可更新插件`:`全部插件已是最新`),await g()}catch(e){f.error(String(e))}d(!1)}async function H(){let e=I.filter(e=>c.has(e.name)).map(e=>e.name);if(!e.length){f.info(`所选插件均无可用更新`);return}s(new Set),l(t=>{let n=new Map(t);for(let t of e)n.delete(t);return n}),await m(`upd-sel`,async()=>{let t=[];for(let n of e)try{let e=await h.pluginUpdate(n);e.jobId&&t.push(e.jobId)}catch{}await L(t,`更新`,e.length)},{success:`已提交 `+e.length+` 个插件的更新任务`,refresh:!1,onDone:()=>void g()})}async function U(){let e=I.map(e=>e.name);confirm(`将卸载所选 `+e.length+` 个插件:
2
2
  `+e.join(`
3
3
  `)+`
4
4
 
@@ -1 +1 @@
1
- import{E as e,L as t,O as n,P as r,T as i,_ as a,b as o,c as s,d as c,g as l,h as u,i as d,j as f,k as p,l as m,m as h,n as g,r as _,s as v,t as y,u as b,y as x,z as S}from"./supervisor-BVac7io-.js";import{n as C,t as w}from"./rocket-Dt6NGQXE.js";import{t as T}from"./refresh-cw-CQuKs_Tk.js";import{t as E}from"./jobs-BjLbfJTM.js";import{c as D,f as O,l as k}from"./supervisor-DX8HnT5i.js";import{t as A}from"./useSupervisorAction-B1Piyga4.js";import{a as j,c as M,i as N,o as P,s as F,t as I}from"./widgets-DMpjcPY5.js";import{n as L}from"./format-QeaTKFhQ.js";var R=r(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),z=r(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),B=r(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),V=r(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),H=r(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),U=S(t(),1),W=n();function G(e){if(!e)return!1;let t=e=>!!(e&&(e.status===`rate-limited`||Number(e.percent)>=100));return t(e.rolling)||t(e.weekly)||t(e.monthly)}function K(e){return!e||!Number.isFinite(e)?``:new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function q(e){return[...e].sort((e,t)=>{let n=e=>e.selected?0:e.usable&&!G(e.quota)?1:2;return n(e)-n(t)})}var J=`grid-cols-[minmax(0,1fr)_230px_84px]`;function Y({onRegisterActions:t}){let{snap:n}=y(),{busy:r,run:a}=A(),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(!1),u=n.router,d=n.providers;(0,U.useEffect)(()=>(t?.({onAdd:()=>s(!0),onDelete:()=>l(!0)}),()=>t?.(null)),[t]);function p(e,t,n){return a(e,t,{success:n})}let m=d?.providers??[];return(0,W.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,W.jsxs)(I,{children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-border/70 px-5 py-3.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(M,{tone:u?.running?`ok`:`off`,ping:!!u?.running}),(0,W.jsx)(`strong`,{className:`text-xl font-semibold tracking-[-0.01em] text-foreground`,children:u?.running?`路由运行中`:`路由已停止`})]}),(0,W.jsx)(i,{"aria-label":u?.running?`停止路由`:`启动路由`,className:e(`px-1`,u?.running?`text-status-error`:`text-primary`),disabled:r===`sw`,onClick:()=>void p(`sw`,()=>u?.running?_.lifecycleStop(`router`):_.lifecycleStart(`router`),u?.running?`路由已停止`:`路由已启动`),title:u?.running?`停止路由`:`启动路由`,variant:`ghost`,children:u?.running?(0,W.jsx)(C,{className:`size-6`}):(0,W.jsx)(w,{className:`size-6`})})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 divide-y divide-border/60 sm:grid-cols-2 sm:divide-y-0 lg:grid-cols-4 lg:divide-x lg:divide-border/60`,children:[(0,W.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,W.jsx)(N,{icon:(0,W.jsx)(O,{className:`size-4`}),label:`总请求 / 失败`,value:L(u?.usage?.requests)+` / `+L(u?.usage?.errors),mono:!0})}),(0,W.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,W.jsx)(N,{icon:(0,W.jsx)(f,{className:`size-4`}),label:`总 Tokens`,value:L(u?.usage?.totalTokens),mono:!0})}),(0,W.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,W.jsx)(N,{icon:(0,W.jsx)(H,{className:`size-4`}),label:`Prompt / Completion`,value:L(u?.usage?.promptTokens)+` / `+L(u?.usage?.completionTokens),mono:!0})}),(0,W.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,W.jsx)(N,{icon:(0,W.jsx)(z,{className:`size-4`}),label:`估算费用`,value:u?.usage?.costUsd?`$`+Number(u.usage.costUsd).toFixed(4):`—`,mono:!0,warn:!u?.usage?.costUsd})})]})]}),m.length?(0,W.jsx)(`div`,{className:`grid gap-4 @min-[900px]:grid-cols-2`,children:m.map(e=>(0,W.jsx)(Z,{p:e,proxyApps:d?.proxyApps??[],busy:r===e.id,onAction:p},e.id))}):(0,W.jsx)(`div`,{className:`grid min-h-[200px] place-items-center rounded-lg border border-dashed border-border text-center`,children:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(O,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,W.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`尚未添加供应商`}),(0,W.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`点击「添加供应商」录入 API Key / Command Code`})]})}),(0,W.jsx)(ne,{open:o,onOpenChange:s,presets:d?.presets??[],proxyApps:d?.proxyApps??[],onDone:()=>g.refresh()}),(0,W.jsx)(X,{open:c,onOpenChange:l,providers:m})]})}function X({open:e,onOpenChange:t,providers:n}){let[r,s]=(0,U.useState)(null);async function c(e){if(confirm(`删除供应商「`+e.name+`」?其下全部账号与 Key 将被移除,不可恢复。`)){s(e.id);try{await _.providerRemove(e.id),p.success(`已删除供应商「`+e.name+`」`),await g.refresh()}catch(e){p.error(String(e))}finally{s(null)}}}return(0,W.jsx)(l,{open:e,onOpenChange:t,children:(0,W.jsxs)(a,{className:`max-w-[440px]`,children:[(0,W.jsx)(x,{children:(0,W.jsx)(o,{children:`删除供应商`})}),(0,W.jsx)(`div`,{className:`grid gap-1.5`,children:n.length?n.map(e=>(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border/70 bg-muted/40 px-3 py-2`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`strong`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,W.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.kind===`proxy`?`反代`:`直连`,` · `,(e.accounts??[]).length,` 账号`]})]}),(0,W.jsxs)(i,{disabled:r===e.id,onClick:()=>void c(e),size:`chip`,variant:`destructive`,children:[r===e.id?(0,W.jsx)(T,{className:`size-3 animate-spin`}):(0,W.jsx)(D,{className:`size-3`}),`删除`]})]},e.id)):(0,W.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`暂无供应商`})}),(0,W.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,W.jsx)(i,{onClick:()=>t(!1),variant:`outline`,children:`关闭`})})]})})}function Z({p:t,proxyApps:n,busy:r,onAction:a}){let o=q(t.accounts??[]),s=o.find(e=>e.selected)||o.find(e=>e.usable&&!G(e.quota))||o[0],[c,l]=(0,U.useState)(!1),u=t.kind===`proxy`?(n??[]).find(e=>e.id===t.proxyAppId)??null:null,d=t.apiBase||(t.apiPort?`http://127.0.0.1:`+t.apiPort+`/v1`:null);return(0,W.jsxs)(I,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border/70 bg-muted px-5 py-3`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`strong`,{className:`truncate text-sm font-semibold text-foreground`,children:t.name}),t.kind===`proxy`&&u&&u.installed?u.updateAvailable?(0,W.jsxs)(i,{className:`gap-1 rounded-full px-2.5 text-xs text-warning`,disabled:r,onClick:()=>void a(`proxy-upd-`+t.id,async()=>{let e=t.proxyAppId,n=await _.proxyUpdateApply(e);if(n.ok===!1){p.error(n.error||`提交失败`);return}let r=p.loading(`正在更新 `+t.name+` 的全部实例…`),i=await E(()=>_.proxyUpdateStatus(e),{onTick:e=>{let n=e?.steps||[],i=n.filter(e=>e.state===`done`).length;n.length&&p.loading(`正在更新 `+t.name+`…(`+i+`/`+n.length+` 实例)`,{id:r})}}),a=i.snapshot;i.state===`done`?p.success(`更新完成`+(a?.restarted?`(已重启 `+a.restarted+` 个实例)`:``),{id:r}):i.state===`failed`?p.error(`更新失败:`+(i.error||(a?.errors?a.errors+` 个实例失败`:`未知原因`)),{id:r}):p.warning(`更新仍在进行(超时未完成,可稍后查看)`,{id:r}),await g.refresh()},void 0),size:`chip`,title:`检测到新版本,点击更新该应用全部实例`,variant:`outline`,children:[(0,W.jsx)(T,{className:`size-3`}),`更新 v`,u.latest]}):(0,W.jsxs)(i,{className:`gap-1 rounded-full px-2.5 text-xs font-mono text-muted-foreground`,disabled:r,onClick:()=>{a(`proxy-chk-`+t.id,async()=>{let e=await _.proxyUpdateCheck();if(await g.refresh(),!e.ok){p.error(e.error||`版本检测失败`);return}let n=e.versions?.[t.proxyAppId||``]||null,r=u.installed;p.info(n&&n!==r?`发现新版本 v`+n+`,点击版本胶囊更新`:`已是最新版本 v`+r)},void 0)},size:`chip`,title:`检测是否有新版本`,variant:`outline`,children:[`v`,u.installed,(0,W.jsx)(T,{className:e(`size-3`,r&&`animate-spin`)})]}):null]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5`,children:[(0,W.jsxs)(i,{disabled:r,onClick:()=>l(!0),size:`sm`,variant:`outline`,children:[(0,W.jsx)(k,{className:`size-3.5`}),`添加`]}),t.activated?(0,W.jsxs)(i,{disabled:r,onClick:()=>void a(`deact`,()=>_.providerDeactivate(t.id).then(()=>void 0),`已停用供应商(资源已回收)`),size:`sm`,variant:`outline`,children:[(0,W.jsx)(C,{className:`size-3.5`}),`停用`]}):(0,W.jsxs)(i,{disabled:r,onClick:()=>void a(`act`,()=>_.providerActivate(t.id).then(()=>void 0),`已启用供应商`),size:`sm`,variant:`outline`,children:[(0,W.jsx)(w,{className:`size-3.5`}),`启用`]})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 px-5 py-2.5`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`API 地址`}),(0,W.jsx)(`div`,{className:`flex h-8 min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-card px-2.5`,children:t.activated&&d?(0,W.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,children:d}):(0,W.jsx)(`span`,{className:`truncate text-xs text-muted-foreground/70`,children:`服务未启用`})}),t.activated&&d?(0,W.jsxs)(i,{onClick:()=>void navigator.clipboard.writeText(d||``).then(()=>p.success(`已复制 API 地址`)),size:`sm`,title:`复制该供应商 API 地址`,variant:`outline`,children:[(0,W.jsx)(B,{className:`size-3.5`}),`复制`]}):null]}),s?(0,W.jsx)($,{acc:s,busy:r,p:t,onAction:a}):(0,W.jsx)(`div`,{className:`px-5 py-3 text-xs text-muted-foreground`,children:`暂无账号数据`}),o.length?(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-col border-t border-border/60`,children:[(0,W.jsxs)(`div`,{className:e(`grid items-center gap-2 border-b border-border/60 bg-muted/60 px-5 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,J),children:[(0,W.jsx)(`span`,{children:`Key`}),(0,W.jsx)(`span`,{className:`text-center`,children:`用量`}),(0,W.jsx)(`span`,{className:`text-center`,children:`操作`})]}),(0,W.jsx)(`div`,{className:`max-h-[288px] min-h-0 overflow-y-auto overscroll-contain`,children:o.map((n,i)=>(0,W.jsx)(`div`,{className:e(i>0&&`border-t border-border/50`),children:(0,W.jsx)(ee,{a:n,p:t,busy:r,onAction:a})},n.keyId))})]}):(0,W.jsx)(`p`,{className:`border-t border-border/60 px-5 py-3 text-xs text-muted-foreground`,children:`暂无 Keys — 点「添加」录入`}),(0,W.jsx)(Q,{open:c,onOpenChange:l,p:t})]})}function Q({open:e,onOpenChange:t,p:n}){let r=n.accounts??[],[s,c]=(0,U.useState)(``),[u,f]=(0,U.useState)(!1),[m,v]=(0,U.useState)(!1),y=n.kind===`proxy`;async function b(){v(!0);try{let e=await _.proxyLoginStart();if(!e.ok){p.error(e.error||`登录发起失败`);return}p.info(`已打开浏览器,请在 Command Code 页面完成授权…`,{duration:4e3});let r=await _.proxyLoginWait(e.waitMs??18e4);if(!r.ok||!r.apiKey){p.error(r.error||`登录未完成`);return}await _.proxyAddKey(n.id,r.apiKey),p.success(`已通过登录添加账号 `+(r.userName||r.keyName||``)),t(!1),await g.refresh()}catch(e){p.error(String(e))}finally{v(!1)}}async function S(){let e=s.split(/[,;\s]+/).map(e=>e.trim()).filter(Boolean);if(!e.length){p.error(`请输入至少一个 Key`);return}f(!0);try{if(y)for(let t of e){let e=await _.proxyAddKey(n.id,t);if(e&&e.limited===`credits`){let t=e.account?.limit?.recovery;p.warning(`已添加:该账号额度用尽`+(t?.type===`at`&&t.at?`(预计 ${K(t.at)} 自动恢复)`:`(等待月度重置后自动恢复)`))}}else{let r=await _.providerKeysSet(n.id,{add:e});if(r.ok===!1){p.error(r.error||`添加失败`);return}let i=typeof r.added==`number`?r.added:e.length,a=r.discardedKeys||[];if(a.length){let e=a.slice(0,3).map(e=>`${e.key}(${e.error})`).join(`;`);p.warning(`已添加 ${i} 个,${a.length} 个失败被丢弃:${e}${a.length>3?` …`:``}`)}else p.success(`已添加 `+i+` 个 Key(`+(y?`反代账号`:`API Key`)+`)`);c(``),t(!1),await g.refresh();return}p.success(`已添加 `+e.length+` 个 Key(`+(y?`反代账号`:`API Key`)+`)`),c(``),t(!1),await g.refresh()}catch(e){p.error(String(e))}finally{f(!1)}}async function C(e){if(confirm(`移除 Key `+e+`?`)){f(!0);try{if(y){let t=r.find(t=>t.maskedKey===e||e.startsWith(t.maskedKey));t&&await _.proxyRemoveKey(n.id,t.keyId)}else{let t=await _.providerKeysSet(n.id,{removeMasked:[e]});if(t.ok===!1){p.error(t.error||`移除失败`);return}}p.success(`已移除`),t(!1),await g.refresh()}catch(e){p.error(String(e))}finally{f(!1)}}}return(0,W.jsx)(l,{open:e,onOpenChange:t,children:(0,W.jsxs)(a,{className:`max-w-[440px]`,children:[(0,W.jsx)(x,{children:(0,W.jsxs)(o,{children:[`添加 / 管理 Key — `,n.name]})}),(0,W.jsxs)(`div`,{className:`grid gap-3`,children:[y?(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border border-border/70 bg-muted/40 px-3 py-2.5`,children:[(0,W.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`一键登录`}),(0,W.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:`浏览器打开 Command Code 授权,自动添加账号`})]}),(0,W.jsx)(i,{disabled:m||u,onClick:()=>void b(),size:`sm`,children:m?`等待授权…`:`一键登录`})]}):null,(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:[y?`已录入账号(反代)`:`已录入 API Key`,`(`,r.length,`)`]}),r.length?(0,W.jsx)(`div`,{className:`grid max-h-[180px] gap-1 overflow-auto`,children:r.map(e=>(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border/70 bg-muted/40 px-2.5 py-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,W.jsx)(`code`,{className:`truncate font-mono text-xs`,children:e.maskedKey}),e.selected?(0,W.jsx)(P,{tone:`ok`,children:`当前`}):null]}),(0,W.jsx)(i,{size:`chip`,variant:`ghost`,className:`text-destructive`,disabled:u,onClick:()=>void C(e.maskedKey),title:`移除该 Key`,children:(0,W.jsx)(D,{className:`size-3.5`})})]},e.keyId))}):(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`尚未录入 `,y?`账号`:`Key`]})]}),(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsxs)(h,{className:`text-xs text-muted-foreground`,children:[`添加 `,y?`账号 Key / Command Code`:`API Key`,`(每行一个,支持逗号/分号分隔)`]}),(0,W.jsx)(d,{className:`h-20 resize-none font-mono text-xs`,placeholder:y?`sk-... 或 Command Code,每行一个`:`sk-... 每行一个`,value:s,onChange:e=>c(e.target.value)})]})]}),(0,W.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,W.jsx)(i,{onClick:()=>t(!1),variant:`outline`,children:`取消`}),(0,W.jsx)(i,{disabled:u||!s.trim(),onClick:()=>void S(),children:u?`保存中…`:`添加`})]})]})})}function $({acc:t,busy:n,p:r,onAction:a}){let o=t.quota,s=!!t.selected,c=!!t.locked,l=o&&o.monthlyRemaining,u=o?.monthly?.percent,d=Number.isFinite(Number(u))?u+`%`:Number.isFinite(Number(l))?`$ `+Number(l).toFixed(2):`—`;return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-5 py-3`,children:[(0,W.jsxs)(`div`,{className:`grid min-w-[180px] content-center gap-1`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:s?c?`当前账号(锁定)`:`当前在用账号`:`选择账号`}),(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(j,{className:`max-w-[150px]`,children:t.maskedKey}),s?(0,W.jsxs)(i,{className:`gap-1 px-2`,disabled:n,onClick:()=>a(`refresh`,()=>_.providerRefresh(r.id).then(()=>void 0),`额度已刷新`),size:`chip`,variant:`outline`,children:[(0,W.jsx)(T,{className:e(`size-3`,n&&`animate-spin`)}),`刷新`]}):null]})]}),(0,W.jsxs)(`div`,{className:`grid min-w-0 flex-1 grid-cols-3 items-stretch gap-2`,children:[(0,W.jsx)(F,{icon:(0,W.jsx)(T,{className:`size-3.5`}),label:`5小时`,value:(o?.rolling?.percent??0)+`%`,danger:o?.rolling?.status===`rate-limited`}),(0,W.jsx)(F,{icon:(0,W.jsx)(f,{className:`size-3.5`}),label:`每周`,value:(o?.weekly?.percent??0)+`%`,danger:o?.weekly?.status===`rate-limited`}),(0,W.jsx)(F,{icon:(0,W.jsx)(O,{className:`size-3.5`}),label:`每月`,value:d,danger:o?.monthly?.status===`rate-limited`||Number(o?.monthly?.percent??0)>=100})]})]})}function ee({a:t,p:n,busy:r,onAction:a}){let o=!!t.selected,s=t.instanceStatus===`frozen`?`frozen`:t.status||``,c=t.limit?.kind,l=s===`frozen`||!!c||!o&&G(t.quota),u=c===`credits`?t.limit?.recovery?.type===`at`&&t.limit?.recovery?.at?`额度用尽(预计 ${K(t.limit.recovery.at)} 月度重置后自动恢复)`:`额度用尽(待月度重置后自动恢复)`:c===`window`?t.limit?.reason??`时间窗额度已用尽(到 resetAt 自动恢复)`:c===`banned`?`账号被封禁`:null,d=L(t.requests||0)+` 次 · `+L(t.totalTokens||0)+` tok`,[f,p]=(0,U.useState)(!1),m;return m=s===`review`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(i,{disabled:r,onClick:()=>void a(`in`,()=>_.providerAccountConfirm(n.id,t.keyId).then(()=>void 0),`已入池`),size:`chip`,variant:`outline`,children:`入池`}),(0,W.jsx)(i,{className:`h-[26px]`,disabled:r,onClick:()=>void a(`out`,()=>_.providerAccountDiscard(n.id,t.keyId).then(()=>void 0),`已作废`),size:`chip`,variant:`destructive`,children:`作废`})]}):l&&!o?(0,W.jsxs)(i,{size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,onClick:()=>p(!0),title:u??`查看该账号限额情况`,children:[(0,W.jsx)(R,{className:`size-3.5`}),`限额`]}):o?(0,W.jsxs)(i,{disabled:r,onClick:()=>a(`refresh`,()=>_.providerRefresh(n.id).then(()=>void 0),`额度已刷新`),size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,children:[(0,W.jsx)(T,{className:e(`size-3.5`,r&&`animate-spin`)}),`刷新`]}):(0,W.jsxs)(i,{disabled:r,size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,onClick:()=>{n.kind===`proxy`?a(`sel`,()=>_.proxySelect(n.id,t.keyId).then(()=>void 0),`已切换账号`):a(`use`,()=>_.providerKeyUse(n.id,t.keyId).then(()=>void 0),`已锁定 Key`)},children:[(0,W.jsx)(V,{className:`size-3.5`}),`切换`]}),(0,W.jsxs)(`div`,{className:e(`grid items-center gap-2 px-5 py-2.5 hover:bg-muted/40`,J,o&&`bg-muted/60 shadow-[inset_3px_0_0_var(--primary)]`),children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,W.jsx)(j,{children:t.maskedKey}),s===`registering`?(0,W.jsx)(P,{tone:`off`,children:`检测中…`}):null,s===`banned`?(0,W.jsx)(P,{tone:`err`,children:`封号`}):null,c===`credits`?(0,W.jsx)(`span`,{title:t.limit?.reason??`额度用尽`,children:(0,W.jsx)(P,{tone:`err`,children:`额度用尽`})}):null,c===`window`?(0,W.jsx)(`span`,{title:t.limit?.reason??`时间窗额度已用尽`,children:(0,W.jsx)(P,{tone:`warn`,children:`窗口用尽`})}):null]}),(0,W.jsx)(`span`,{className:`truncate text-right text-xs tabular-nums text-muted-foreground`,title:d,children:d}),(0,W.jsx)(`div`,{className:`flex justify-end`,children:m}),(0,W.jsx)(te,{open:f,onOpenChange:p,a:t,p:n})]})}function te({open:e,onOpenChange:t,a:n,p:r}){let s=n.quota,c=(()=>{let e=s?.monthly?.percent;if(e!=null&&Number.isFinite(Number(e)))return Number(e);let t=Number(s?.credits?.monthlyCredits??s?.monthlyRemaining);return Number.isFinite(t)&&t>=0?Math.min(100,Math.round((10-t)/10*100)):0})(),u=s?.monthly?.status?{...s.monthly,percent:c}:{status:`ok`,percent:c,resetsAt:s?.monthly?.resetsAt},d=(()=>{let e=s?.credits?.monthlyCredits,t=s?.monthlyRemaining,n=e!=null&&Number.isFinite(Number(e))?Number(e):t!=null&&Number.isFinite(Number(t))?Number(t):null;return n===null?null:`剩余 $`+n.toFixed(2)})(),f=(e,t,n)=>(0,W.jsxs)(`div`,{className:`grid gap-1 rounded-md border border-border/70 bg-muted/40 px-3 py-2.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:t}),(0,W.jsx)(P,{tone:e?.status===`rate-limited`||Number(e?.percent)>=100?`err`:`ok`,children:e?.status===`rate-limited`||Number(e?.percent)>=100?`已限额`:`正常`})]}),(0,W.jsxs)(`strong`,{className:`text-xl font-semibold tabular-nums text-foreground`,children:[e?.percent??0,`%`]}),n?(0,W.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:n}):null,e?.resetsAt?(0,W.jsxs)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:[`重置:`,new Date(e.resetsAt).toLocaleString(`zh-CN`,{month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})]}):null]});return(0,W.jsx)(l,{open:e,onOpenChange:t,children:(0,W.jsxs)(a,{className:`max-w-[420px]`,children:[(0,W.jsx)(x,{children:(0,W.jsx)(o,{children:`限额详情`})}),(0,W.jsxs)(`div`,{className:`grid gap-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,W.jsx)(`span`,{children:`账号`}),(0,W.jsx)(`code`,{className:`font-mono`,children:n.maskedKey}),(0,W.jsx)(`span`,{className:`ml-auto text-xs`,children:r.name})]}),s?(0,W.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[f(s.rolling,`5小时`),f(s.weekly,`每周`),f(u,`每月`),s.credits||s.monthlyRemaining!=null?(0,W.jsxs)(`div`,{className:`col-span-3 flex flex-col gap-1 rounded-md border border-border/70 bg-muted/40 px-3 py-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`月度额度(Command)`}),s.credits?.belowThreshold?(0,W.jsx)(P,{tone:`warn`,children:`低于充值线`}):s.credits&&Number.isFinite(Number(s.credits.monthlyCredits))&&Number(s.credits.monthlyCredits)<=0?(0,W.jsx)(P,{tone:`err`,children:`额度用尽`}):(0,W.jsx)(P,{tone:`ok`,children:`正常`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:Number(s.monthlyResetAt)>Date.now()?`月度额度预计 ${K(Number(s.monthlyResetAt))} 重置(随订阅续期)`:`月度额度已于 ${K(Number(s.monthlyResetAt))} 重置`}),d?(0,W.jsx)(`span`,{className:`text-sm font-semibold tabular-nums text-foreground`,children:d}):null]})]}):null]}):(0,W.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`暂无额度数据 — 点「刷新」获取`}),s?(0,W.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`当前用量统计:`,L(n.requests||0),` 次请求 · `,L(n.totalTokens||0),` tokens`,s.monthly?.resetsAt?`。最迟限额将于月窗口重置后自动解除。`:``]}):null]}),(0,W.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,W.jsx)(i,{onClick:()=>t(!1),variant:`outline`,children:`关闭`})})]})})}function ne({open:t,onOpenChange:n,presets:r,proxyApps:d,onDone:f}){let[g,y]=(0,U.useState)(``),[S,C]=(0,U.useState)(``),[w,T]=(0,U.useState)(``),[E,D]=(0,U.useState)(`preset`),[O,k]=(0,U.useState)(!1);async function A(){if(E===`preset`&&!g){p.error(`请选择供应商`);return}if(E===`proxy`&&!S){p.error(`请选择反代应用`);return}k(!0);try{let e=E===`preset`?await _.providerAdd({presetId:g,name:w||void 0,keys:[]}):await _.providerAdd({kind:`proxy`,appId:S,name:w||void 0,keys:[]});if(e.ok===!1){p.error(e.error||`添加失败`);return}p.success(`已添加供应商,请在卡片上点「添加」录入 Key`),n(!1),T(``),y(``),C(``),f()}catch(e){p.error(String(e))}finally{k(!1)}}let j=(r??[]).find(e=>e.id===g);return(0,W.jsx)(l,{open:t,onOpenChange:n,children:(0,W.jsxs)(a,{className:`max-w-[420px]`,children:[(0,W.jsx)(x,{children:(0,W.jsx)(o,{children:`添加供应商`})}),(0,W.jsxs)(`div`,{className:`grid gap-3`,children:[(0,W.jsx)(`div`,{className:`flex gap-1.5 rounded-lg bg-muted p-1`,children:[`preset`,`proxy`].map(t=>(0,W.jsx)(i,{className:e(`flex-1 rounded-md font-medium`,E===t?`bg-card text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-card/60 hover:text-foreground`),onClick:()=>D(t),size:`sm`,variant:`ghost`,children:t===`preset`?`直连预设`:`反代应用`},t))}),E===`preset`?(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsx)(h,{children:`供应商`}),(0,W.jsxs)(v,{value:g,onValueChange:y,children:[(0,W.jsx)(b,{className:`w-full`,children:(0,W.jsx)(c,{placeholder:`-- 选择供应商 --`})}),(0,W.jsx)(s,{children:(r??[]).map(e=>(0,W.jsx)(m,{value:e.id,children:e.name},e.id))})]}),j?.note?(0,W.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:j.note}):null]}):(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsx)(h,{children:`反代应用`}),(0,W.jsxs)(v,{value:S,onValueChange:C,children:[(0,W.jsx)(b,{className:`w-full`,children:(0,W.jsx)(c,{placeholder:`-- 选择应用 --`})}),(0,W.jsx)(s,{children:(d??[]).map(e=>(0,W.jsx)(m,{value:e.id,children:e.name},e.id))})]})]}),(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsx)(h,{children:`供应商名称(可选)`}),(0,W.jsx)(u,{placeholder:`自定义名称,如:Open Code ZEN`,value:w,onChange:e=>T(e.target.value)})]}),(0,W.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:`只添加供应商不填 Key;添加后在供应商卡片上点「添加」录入 API Key。`})]}),(0,W.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,W.jsx)(i,{onClick:()=>n(!1),variant:`outline`,children:`取消`}),(0,W.jsx)(i,{disabled:O,onClick:()=>void A(),children:O?`添加中…`:`添加供应商`})]})]})})}export{Y as RouterPage};
1
+ import{E as e,L as t,O as n,P as r,T as i,_ as a,b as o,c as s,d as c,g as l,h as u,i as d,j as f,k as p,l as m,m as h,n as g,r as _,s as v,t as y,u as b,y as x,z as S}from"./supervisor-BVac7io-.js";import{n as C,t as w}from"./rocket-Dt6NGQXE.js";import{t as T}from"./refresh-cw-CQuKs_Tk.js";import{t as E}from"./jobs-BjLbfJTM.js";import{c as D,f as O,l as k}from"./supervisor-DwJMunGH.js";import{t as A}from"./useSupervisorAction-B1Piyga4.js";import{a as j,c as M,i as N,o as P,s as F,t as I}from"./widgets-DMpjcPY5.js";import{n as L}from"./format-QeaTKFhQ.js";var R=r(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),z=r(`circle-x`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),B=r(`copy`,[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]),V=r(`repeat`,[[`path`,{d:`m17 2 4 4-4 4`,key:`nntrym`}],[`path`,{d:`M3 11v-1a4 4 0 0 1 4-4h14`,key:`84bu3i`}],[`path`,{d:`m7 22-4-4 4-4`,key:`1wqhfi`}],[`path`,{d:`M21 13v1a4 4 0 0 1-4 4H3`,key:`1rx37r`}]]),H=r(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),U=S(t(),1),W=n();function G(e){if(!e)return!1;let t=e=>!!(e&&(e.status===`rate-limited`||Number(e.percent)>=100));return t(e.rolling)||t(e.weekly)||t(e.monthly)}function K(e){return!e||!Number.isFinite(e)?``:new Date(e).toLocaleString(`zh-CN`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})}function q(e){return[...e].sort((e,t)=>{let n=e=>e.selected?0:e.usable&&!G(e.quota)?1:2;return n(e)-n(t)})}var J=`grid-cols-[minmax(0,1fr)_230px_84px]`;function Y({onRegisterActions:t}){let{snap:n}=y(),{busy:r,run:a}=A(),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(!1),u=n.router,d=n.providers;(0,U.useEffect)(()=>(t?.({onAdd:()=>s(!0),onDelete:()=>l(!0)}),()=>t?.(null)),[t]);function p(e,t,n){return a(e,t,{success:n})}let m=d?.providers??[];return(0,W.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,W.jsxs)(I,{children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-border/70 px-5 py-3.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(M,{tone:u?.running?`ok`:`off`,ping:!!u?.running}),(0,W.jsx)(`strong`,{className:`text-xl font-semibold tracking-[-0.01em] text-foreground`,children:u?.running?`路由运行中`:`路由已停止`})]}),(0,W.jsx)(i,{"aria-label":u?.running?`停止路由`:`启动路由`,className:e(`px-1`,u?.running?`text-status-error`:`text-primary`),disabled:r===`sw`,onClick:()=>void p(`sw`,()=>u?.running?_.lifecycleStop(`router`):_.lifecycleStart(`router`),u?.running?`路由已停止`:`路由已启动`),title:u?.running?`停止路由`:`启动路由`,variant:`ghost`,children:u?.running?(0,W.jsx)(C,{className:`size-6`}):(0,W.jsx)(w,{className:`size-6`})})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 divide-y divide-border/60 sm:grid-cols-2 sm:divide-y-0 lg:grid-cols-4 lg:divide-x lg:divide-border/60`,children:[(0,W.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,W.jsx)(N,{icon:(0,W.jsx)(O,{className:`size-4`}),label:`总请求 / 失败`,value:L(u?.usage?.requests)+` / `+L(u?.usage?.errors),mono:!0})}),(0,W.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,W.jsx)(N,{icon:(0,W.jsx)(f,{className:`size-4`}),label:`总 Tokens`,value:L(u?.usage?.totalTokens),mono:!0})}),(0,W.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,W.jsx)(N,{icon:(0,W.jsx)(H,{className:`size-4`}),label:`Prompt / Completion`,value:L(u?.usage?.promptTokens)+` / `+L(u?.usage?.completionTokens),mono:!0})}),(0,W.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,W.jsx)(N,{icon:(0,W.jsx)(z,{className:`size-4`}),label:`估算费用`,value:u?.usage?.costUsd?`$`+Number(u.usage.costUsd).toFixed(4):`—`,mono:!0,warn:!u?.usage?.costUsd})})]})]}),m.length?(0,W.jsx)(`div`,{className:`grid gap-4 @min-[900px]:grid-cols-2`,children:m.map(e=>(0,W.jsx)(Z,{p:e,proxyApps:d?.proxyApps??[],busy:r===e.id,onAction:p},e.id))}):(0,W.jsx)(`div`,{className:`grid min-h-[200px] place-items-center rounded-lg border border-dashed border-border text-center`,children:(0,W.jsxs)(`div`,{children:[(0,W.jsx)(O,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,W.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`尚未添加供应商`}),(0,W.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`点击「添加供应商」录入 API Key / Command Code`})]})}),(0,W.jsx)(ne,{open:o,onOpenChange:s,presets:d?.presets??[],proxyApps:d?.proxyApps??[],onDone:()=>g.refresh()}),(0,W.jsx)(X,{open:c,onOpenChange:l,providers:m})]})}function X({open:e,onOpenChange:t,providers:n}){let[r,s]=(0,U.useState)(null);async function c(e){if(confirm(`删除供应商「`+e.name+`」?其下全部账号与 Key 将被移除,不可恢复。`)){s(e.id);try{await _.providerRemove(e.id),p.success(`已删除供应商「`+e.name+`」`),await g.refresh()}catch(e){p.error(String(e))}finally{s(null)}}}return(0,W.jsx)(l,{open:e,onOpenChange:t,children:(0,W.jsxs)(a,{className:`max-w-[440px]`,children:[(0,W.jsx)(x,{children:(0,W.jsx)(o,{children:`删除供应商`})}),(0,W.jsx)(`div`,{className:`grid gap-1.5`,children:n.length?n.map(e=>(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border/70 bg-muted/40 px-3 py-2`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`strong`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,W.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.kind===`proxy`?`反代`:`直连`,` · `,(e.accounts??[]).length,` 账号`]})]}),(0,W.jsxs)(i,{disabled:r===e.id,onClick:()=>void c(e),size:`chip`,variant:`destructive`,children:[r===e.id?(0,W.jsx)(T,{className:`size-3 animate-spin`}):(0,W.jsx)(D,{className:`size-3`}),`删除`]})]},e.id)):(0,W.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`暂无供应商`})}),(0,W.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,W.jsx)(i,{onClick:()=>t(!1),variant:`outline`,children:`关闭`})})]})})}function Z({p:t,proxyApps:n,busy:r,onAction:a}){let o=q(t.accounts??[]),s=o.find(e=>e.selected)||o.find(e=>e.usable&&!G(e.quota))||o[0],[c,l]=(0,U.useState)(!1),u=t.kind===`proxy`?(n??[]).find(e=>e.id===t.proxyAppId)??null:null,d=t.apiBase||(t.apiPort?`http://127.0.0.1:`+t.apiPort+`/v1`:null);return(0,W.jsxs)(I,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 border-b border-border/70 bg-muted px-5 py-3`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`strong`,{className:`truncate text-sm font-semibold text-foreground`,children:t.name}),t.kind===`proxy`&&u&&u.installed?u.updateAvailable?(0,W.jsxs)(i,{className:`gap-1 rounded-full px-2.5 text-xs text-warning`,disabled:r,onClick:()=>void a(`proxy-upd-`+t.id,async()=>{let e=t.proxyAppId,n=await _.proxyUpdateApply(e);if(n.ok===!1){p.error(n.error||`提交失败`);return}let r=p.loading(`正在更新 `+t.name+` 的全部实例…`),i=await E(()=>_.proxyUpdateStatus(e),{onTick:e=>{let n=e?.steps||[],i=n.filter(e=>e.state===`done`).length;n.length&&p.loading(`正在更新 `+t.name+`…(`+i+`/`+n.length+` 实例)`,{id:r})}}),a=i.snapshot;i.state===`done`?p.success(`更新完成`+(a?.restarted?`(已重启 `+a.restarted+` 个实例)`:``),{id:r}):i.state===`failed`?p.error(`更新失败:`+(i.error||(a?.errors?a.errors+` 个实例失败`:`未知原因`)),{id:r}):p.warning(`更新仍在进行(超时未完成,可稍后查看)`,{id:r}),await g.refresh()},void 0),size:`chip`,title:`检测到新版本,点击更新该应用全部实例`,variant:`outline`,children:[(0,W.jsx)(T,{className:`size-3`}),`更新 v`,u.latest]}):(0,W.jsxs)(i,{className:`gap-1 rounded-full px-2.5 text-xs font-mono text-muted-foreground`,disabled:r,onClick:()=>{a(`proxy-chk-`+t.id,async()=>{let e=await _.proxyUpdateCheck();if(await g.refresh(),!e.ok){p.error(e.error||`版本检测失败`);return}let n=e.versions?.[t.proxyAppId||``]||null,r=u.installed;p.info(n&&n!==r?`发现新版本 v`+n+`,点击版本胶囊更新`:`已是最新版本 v`+r)},void 0)},size:`chip`,title:`检测是否有新版本`,variant:`outline`,children:[`v`,u.installed,(0,W.jsx)(T,{className:e(`size-3`,r&&`animate-spin`)})]}):null]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5`,children:[(0,W.jsxs)(i,{disabled:r,onClick:()=>l(!0),size:`sm`,variant:`outline`,children:[(0,W.jsx)(k,{className:`size-3.5`}),`添加`]}),t.activated?(0,W.jsxs)(i,{disabled:r,onClick:()=>void a(`deact`,()=>_.providerDeactivate(t.id).then(()=>void 0),`已停用供应商(资源已回收)`),size:`sm`,variant:`outline`,children:[(0,W.jsx)(C,{className:`size-3.5`}),`停用`]}):(0,W.jsxs)(i,{disabled:r,onClick:()=>void a(`act`,()=>_.providerActivate(t.id).then(()=>void 0),`已启用供应商`),size:`sm`,variant:`outline`,children:[(0,W.jsx)(w,{className:`size-3.5`}),`启用`]})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 px-5 py-2.5`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`API 地址`}),(0,W.jsx)(`div`,{className:`flex h-8 min-w-0 flex-1 items-center gap-2 rounded-md border border-border bg-card px-2.5`,children:t.activated&&d?(0,W.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,children:d}):(0,W.jsx)(`span`,{className:`truncate text-xs text-muted-foreground/70`,children:`服务未启用`})}),t.activated&&d?(0,W.jsxs)(i,{onClick:()=>void navigator.clipboard.writeText(d||``).then(()=>p.success(`已复制 API 地址`)),size:`sm`,title:`复制该供应商 API 地址`,variant:`outline`,children:[(0,W.jsx)(B,{className:`size-3.5`}),`复制`]}):null]}),s?(0,W.jsx)($,{acc:s,busy:r,p:t,onAction:a}):(0,W.jsx)(`div`,{className:`px-5 py-3 text-xs text-muted-foreground`,children:`暂无账号数据`}),o.length?(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-col border-t border-border/60`,children:[(0,W.jsxs)(`div`,{className:e(`grid items-center gap-2 border-b border-border/60 bg-muted/60 px-5 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,J),children:[(0,W.jsx)(`span`,{children:`Key`}),(0,W.jsx)(`span`,{className:`text-center`,children:`用量`}),(0,W.jsx)(`span`,{className:`text-center`,children:`操作`})]}),(0,W.jsx)(`div`,{className:`max-h-[288px] min-h-0 overflow-y-auto overscroll-contain`,children:o.map((n,i)=>(0,W.jsx)(`div`,{className:e(i>0&&`border-t border-border/50`),children:(0,W.jsx)(ee,{a:n,p:t,busy:r,onAction:a})},n.keyId))})]}):(0,W.jsx)(`p`,{className:`border-t border-border/60 px-5 py-3 text-xs text-muted-foreground`,children:`暂无 Keys — 点「添加」录入`}),(0,W.jsx)(Q,{open:c,onOpenChange:l,p:t})]})}function Q({open:e,onOpenChange:t,p:n}){let r=n.accounts??[],[s,c]=(0,U.useState)(``),[u,f]=(0,U.useState)(!1),[m,v]=(0,U.useState)(!1),y=n.kind===`proxy`;async function b(){v(!0);try{let e=await _.proxyLoginStart();if(!e.ok){p.error(e.error||`登录发起失败`);return}p.info(`已打开浏览器,请在 Command Code 页面完成授权…`,{duration:4e3});let r=await _.proxyLoginWait(e.waitMs??18e4);if(!r.ok||!r.apiKey){p.error(r.error||`登录未完成`);return}await _.proxyAddKey(n.id,r.apiKey),p.success(`已通过登录添加账号 `+(r.userName||r.keyName||``)),t(!1),await g.refresh()}catch(e){p.error(String(e))}finally{v(!1)}}async function S(){let e=s.split(/[,;\s]+/).map(e=>e.trim()).filter(Boolean);if(!e.length){p.error(`请输入至少一个 Key`);return}f(!0);try{if(y)for(let t of e){let e=await _.proxyAddKey(n.id,t);if(e&&e.limited===`credits`){let t=e.account?.limit?.recovery;p.warning(`已添加:该账号额度用尽`+(t?.type===`at`&&t.at?`(预计 ${K(t.at)} 自动恢复)`:`(等待月度重置后自动恢复)`))}}else{let r=await _.providerKeysSet(n.id,{add:e});if(r.ok===!1){p.error(r.error||`添加失败`);return}let i=typeof r.added==`number`?r.added:e.length,a=r.discardedKeys||[];if(a.length){let e=a.slice(0,3).map(e=>`${e.key}(${e.error})`).join(`;`);p.warning(`已添加 ${i} 个,${a.length} 个失败被丢弃:${e}${a.length>3?` …`:``}`)}else p.success(`已添加 `+i+` 个 Key(`+(y?`反代账号`:`API Key`)+`)`);c(``),t(!1),await g.refresh();return}p.success(`已添加 `+e.length+` 个 Key(`+(y?`反代账号`:`API Key`)+`)`),c(``),t(!1),await g.refresh()}catch(e){p.error(String(e))}finally{f(!1)}}async function C(e){if(confirm(`移除 Key `+e+`?`)){f(!0);try{if(y){let t=r.find(t=>t.maskedKey===e||e.startsWith(t.maskedKey));t&&await _.proxyRemoveKey(n.id,t.keyId)}else{let t=await _.providerKeysSet(n.id,{removeMasked:[e]});if(t.ok===!1){p.error(t.error||`移除失败`);return}}p.success(`已移除`),t(!1),await g.refresh()}catch(e){p.error(String(e))}finally{f(!1)}}}return(0,W.jsx)(l,{open:e,onOpenChange:t,children:(0,W.jsxs)(a,{className:`max-w-[440px]`,children:[(0,W.jsx)(x,{children:(0,W.jsxs)(o,{children:[`添加 / 管理 Key — `,n.name]})}),(0,W.jsxs)(`div`,{className:`grid gap-3`,children:[y?(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-md border border-border/70 bg-muted/40 px-3 py-2.5`,children:[(0,W.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`一键登录`}),(0,W.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:`浏览器打开 Command Code 授权,自动添加账号`})]}),(0,W.jsx)(i,{disabled:m||u,onClick:()=>void b(),size:`sm`,children:m?`等待授权…`:`一键登录`})]}):null,(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:[y?`已录入账号(反代)`:`已录入 API Key`,`(`,r.length,`)`]}),r.length?(0,W.jsx)(`div`,{className:`grid max-h-[180px] gap-1 overflow-auto`,children:r.map(e=>(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border/70 bg-muted/40 px-2.5 py-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,W.jsx)(`code`,{className:`truncate font-mono text-xs`,children:e.maskedKey}),e.selected?(0,W.jsx)(P,{tone:`ok`,children:`当前`}):null]}),(0,W.jsx)(i,{size:`chip`,variant:`ghost`,className:`text-destructive`,disabled:u,onClick:()=>void C(e.maskedKey),title:`移除该 Key`,children:(0,W.jsx)(D,{className:`size-3.5`})})]},e.keyId))}):(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`尚未录入 `,y?`账号`:`Key`]})]}),(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsxs)(h,{className:`text-xs text-muted-foreground`,children:[`添加 `,y?`账号 Key / Command Code`:`API Key`,`(每行一个,支持逗号/分号分隔)`]}),(0,W.jsx)(d,{className:`h-20 resize-none font-mono text-xs`,placeholder:y?`sk-... 或 Command Code,每行一个`:`sk-... 每行一个`,value:s,onChange:e=>c(e.target.value)})]})]}),(0,W.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,W.jsx)(i,{onClick:()=>t(!1),variant:`outline`,children:`取消`}),(0,W.jsx)(i,{disabled:u||!s.trim(),onClick:()=>void S(),children:u?`保存中…`:`添加`})]})]})})}function $({acc:t,busy:n,p:r,onAction:a}){let o=t.quota,s=!!t.selected,c=!!t.locked,l=o&&o.monthlyRemaining,u=o?.monthly?.percent,d=Number.isFinite(Number(u))?u+`%`:Number.isFinite(Number(l))?`$ `+Number(l).toFixed(2):`—`;return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-5 py-3`,children:[(0,W.jsxs)(`div`,{className:`grid min-w-[180px] content-center gap-1`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:s?c?`当前账号(锁定)`:`当前在用账号`:`选择账号`}),(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(j,{className:`max-w-[150px]`,children:t.maskedKey}),s?(0,W.jsxs)(i,{className:`gap-1 px-2`,disabled:n,onClick:()=>a(`refresh`,()=>_.providerRefresh(r.id).then(()=>void 0),`额度已刷新`),size:`chip`,variant:`outline`,children:[(0,W.jsx)(T,{className:e(`size-3`,n&&`animate-spin`)}),`刷新`]}):null]})]}),(0,W.jsxs)(`div`,{className:`grid min-w-0 flex-1 grid-cols-3 items-stretch gap-2`,children:[(0,W.jsx)(F,{icon:(0,W.jsx)(T,{className:`size-3.5`}),label:`5小时`,value:(o?.rolling?.percent??0)+`%`,danger:o?.rolling?.status===`rate-limited`}),(0,W.jsx)(F,{icon:(0,W.jsx)(f,{className:`size-3.5`}),label:`每周`,value:(o?.weekly?.percent??0)+`%`,danger:o?.weekly?.status===`rate-limited`}),(0,W.jsx)(F,{icon:(0,W.jsx)(O,{className:`size-3.5`}),label:`每月`,value:d,danger:o?.monthly?.status===`rate-limited`||Number(o?.monthly?.percent??0)>=100})]})]})}function ee({a:t,p:n,busy:r,onAction:a}){let o=!!t.selected,s=t.instanceStatus===`frozen`?`frozen`:t.status||``,c=t.limit?.kind,l=s===`frozen`||!!c||!o&&G(t.quota),u=c===`credits`?t.limit?.recovery?.type===`at`&&t.limit?.recovery?.at?`额度用尽(预计 ${K(t.limit.recovery.at)} 月度重置后自动恢复)`:`额度用尽(待月度重置后自动恢复)`:c===`window`?t.limit?.reason??`时间窗额度已用尽(到 resetAt 自动恢复)`:c===`banned`?`账号被封禁`:null,d=L(t.requests||0)+` 次 · `+L(t.totalTokens||0)+` tok`,[f,p]=(0,U.useState)(!1),m;return m=s===`review`?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(i,{disabled:r,onClick:()=>void a(`in`,()=>_.providerAccountConfirm(n.id,t.keyId).then(()=>void 0),`已入池`),size:`chip`,variant:`outline`,children:`入池`}),(0,W.jsx)(i,{className:`h-[26px]`,disabled:r,onClick:()=>void a(`out`,()=>_.providerAccountDiscard(n.id,t.keyId).then(()=>void 0),`已作废`),size:`chip`,variant:`destructive`,children:`作废`})]}):l&&!o?(0,W.jsxs)(i,{size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,onClick:()=>p(!0),title:u??`查看该账号限额情况`,children:[(0,W.jsx)(R,{className:`size-3.5`}),`限额`]}):o?(0,W.jsxs)(i,{disabled:r,onClick:()=>a(`refresh`,()=>_.providerRefresh(n.id).then(()=>void 0),`额度已刷新`),size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,children:[(0,W.jsx)(T,{className:e(`size-3.5`,r&&`animate-spin`)}),`刷新`]}):(0,W.jsxs)(i,{disabled:r,size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,onClick:()=>{n.kind===`proxy`?a(`sel`,()=>_.proxySelect(n.id,t.keyId).then(()=>void 0),`已切换账号`):a(`use`,()=>_.providerKeyUse(n.id,t.keyId).then(()=>void 0),`已锁定 Key`)},children:[(0,W.jsx)(V,{className:`size-3.5`}),`切换`]}),(0,W.jsxs)(`div`,{className:e(`grid items-center gap-2 px-5 py-2.5 hover:bg-muted/40`,J,o&&`bg-muted/60 shadow-[inset_3px_0_0_var(--primary)]`),children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,W.jsx)(j,{children:t.maskedKey}),s===`registering`?(0,W.jsx)(P,{tone:`off`,children:`检测中…`}):null,s===`banned`?(0,W.jsx)(P,{tone:`err`,children:`封号`}):null,c===`credits`?(0,W.jsx)(`span`,{title:t.limit?.reason??`额度用尽`,children:(0,W.jsx)(P,{tone:`err`,children:`额度用尽`})}):null,c===`window`?(0,W.jsx)(`span`,{title:t.limit?.reason??`时间窗额度已用尽`,children:(0,W.jsx)(P,{tone:`warn`,children:`窗口用尽`})}):null]}),(0,W.jsx)(`span`,{className:`truncate text-right text-xs tabular-nums text-muted-foreground`,title:d,children:d}),(0,W.jsx)(`div`,{className:`flex justify-end`,children:m}),(0,W.jsx)(te,{open:f,onOpenChange:p,a:t,p:n})]})}function te({open:e,onOpenChange:t,a:n,p:r}){let s=n.quota,c=(()=>{let e=s?.monthly?.percent;if(e!=null&&Number.isFinite(Number(e)))return Number(e);let t=Number(s?.credits?.monthlyCredits??s?.monthlyRemaining);return Number.isFinite(t)&&t>=0?Math.min(100,Math.round((10-t)/10*100)):0})(),u=s?.monthly?.status?{...s.monthly,percent:c}:{status:`ok`,percent:c,resetsAt:s?.monthly?.resetsAt},d=(()=>{let e=s?.credits?.monthlyCredits,t=s?.monthlyRemaining,n=e!=null&&Number.isFinite(Number(e))?Number(e):t!=null&&Number.isFinite(Number(t))?Number(t):null;return n===null?null:`剩余 $`+n.toFixed(2)})(),f=(e,t,n)=>(0,W.jsxs)(`div`,{className:`grid gap-1 rounded-md border border-border/70 bg-muted/40 px-3 py-2.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:t}),(0,W.jsx)(P,{tone:e?.status===`rate-limited`||Number(e?.percent)>=100?`err`:`ok`,children:e?.status===`rate-limited`||Number(e?.percent)>=100?`已限额`:`正常`})]}),(0,W.jsxs)(`strong`,{className:`text-xl font-semibold tabular-nums text-foreground`,children:[e?.percent??0,`%`]}),n?(0,W.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:n}):null,e?.resetsAt?(0,W.jsxs)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:[`重置:`,new Date(e.resetsAt).toLocaleString(`zh-CN`,{month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`})]}):null]});return(0,W.jsx)(l,{open:e,onOpenChange:t,children:(0,W.jsxs)(a,{className:`max-w-[420px]`,children:[(0,W.jsx)(x,{children:(0,W.jsx)(o,{children:`限额详情`})}),(0,W.jsxs)(`div`,{className:`grid gap-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,W.jsx)(`span`,{children:`账号`}),(0,W.jsx)(`code`,{className:`font-mono`,children:n.maskedKey}),(0,W.jsx)(`span`,{className:`ml-auto text-xs`,children:r.name})]}),s?(0,W.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[f(s.rolling,`5小时`),f(s.weekly,`每周`),f(u,`每月`),s.credits||s.monthlyRemaining!=null?(0,W.jsxs)(`div`,{className:`col-span-3 flex flex-col gap-1 rounded-md border border-border/70 bg-muted/40 px-3 py-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`月度额度(Command)`}),s.credits?.belowThreshold?(0,W.jsx)(P,{tone:`warn`,children:`低于充值线`}):s.credits&&Number.isFinite(Number(s.credits.monthlyCredits))&&Number(s.credits.monthlyCredits)<=0?(0,W.jsx)(P,{tone:`err`,children:`额度用尽`}):(0,W.jsx)(P,{tone:`ok`,children:`正常`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:Number(s.monthlyResetAt)>Date.now()?`月度额度预计 ${K(Number(s.monthlyResetAt))} 重置(随订阅续期)`:`月度额度已于 ${K(Number(s.monthlyResetAt))} 重置`}),d?(0,W.jsx)(`span`,{className:`text-sm font-semibold tabular-nums text-foreground`,children:d}):null]})]}):null]}):(0,W.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`暂无额度数据 — 点「刷新」获取`}),s?(0,W.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`当前用量统计:`,L(n.requests||0),` 次请求 · `,L(n.totalTokens||0),` tokens`,s.monthly?.resetsAt?`。最迟限额将于月窗口重置后自动解除。`:``]}):null]}),(0,W.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,W.jsx)(i,{onClick:()=>t(!1),variant:`outline`,children:`关闭`})})]})})}function ne({open:t,onOpenChange:n,presets:r,proxyApps:d,onDone:f}){let[g,y]=(0,U.useState)(``),[S,C]=(0,U.useState)(``),[w,T]=(0,U.useState)(``),[E,D]=(0,U.useState)(`preset`),[O,k]=(0,U.useState)(!1);async function A(){if(E===`preset`&&!g){p.error(`请选择供应商`);return}if(E===`proxy`&&!S){p.error(`请选择反代应用`);return}k(!0);try{let e=E===`preset`?await _.providerAdd({presetId:g,name:w||void 0,keys:[]}):await _.providerAdd({kind:`proxy`,appId:S,name:w||void 0,keys:[]});if(e.ok===!1){p.error(e.error||`添加失败`);return}p.success(`已添加供应商,请在卡片上点「添加」录入 Key`),n(!1),T(``),y(``),C(``),f()}catch(e){p.error(String(e))}finally{k(!1)}}let j=(r??[]).find(e=>e.id===g);return(0,W.jsx)(l,{open:t,onOpenChange:n,children:(0,W.jsxs)(a,{className:`max-w-[420px]`,children:[(0,W.jsx)(x,{children:(0,W.jsx)(o,{children:`添加供应商`})}),(0,W.jsxs)(`div`,{className:`grid gap-3`,children:[(0,W.jsx)(`div`,{className:`flex gap-1.5 rounded-lg bg-muted p-1`,children:[`preset`,`proxy`].map(t=>(0,W.jsx)(i,{className:e(`flex-1 rounded-md font-medium`,E===t?`bg-card text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-card/60 hover:text-foreground`),onClick:()=>D(t),size:`sm`,variant:`ghost`,children:t===`preset`?`直连预设`:`反代应用`},t))}),E===`preset`?(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsx)(h,{children:`供应商`}),(0,W.jsxs)(v,{value:g,onValueChange:y,children:[(0,W.jsx)(b,{className:`w-full`,children:(0,W.jsx)(c,{placeholder:`-- 选择供应商 --`})}),(0,W.jsx)(s,{children:(r??[]).map(e=>(0,W.jsx)(m,{value:e.id,children:e.name},e.id))})]}),j?.note?(0,W.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:j.note}):null]}):(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsx)(h,{children:`反代应用`}),(0,W.jsxs)(v,{value:S,onValueChange:C,children:[(0,W.jsx)(b,{className:`w-full`,children:(0,W.jsx)(c,{placeholder:`-- 选择应用 --`})}),(0,W.jsx)(s,{children:(d??[]).map(e=>(0,W.jsx)(m,{value:e.id,children:e.name},e.id))})]})]}),(0,W.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,W.jsx)(h,{children:`供应商名称(可选)`}),(0,W.jsx)(u,{placeholder:`自定义名称,如:Open Code ZEN`,value:w,onChange:e=>T(e.target.value)})]}),(0,W.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:`只添加供应商不填 Key;添加后在供应商卡片上点「添加」录入 API Key。`})]}),(0,W.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,W.jsx)(i,{onClick:()=>n(!1),variant:`outline`,children:`取消`}),(0,W.jsx)(i,{disabled:O,onClick:()=>void A(),children:O?`添加中…`:`添加供应商`})]})]})})}export{Y as RouterPage};
@@ -1,3 +1,3 @@
1
- import{C as e,E as t,L as n,M as r,N as i,O as a,S as o,T as s,_ as c,a as l,b as u,c as d,d as f,f as p,g as m,h,k as g,l as _,p as v,r as y,s as b,u as x,x as S,y as C,z as w}from"./supervisor-BVac7io-.js";import{t as T}from"./refresh-cw-CQuKs_Tk.js";import{c as E,l as D}from"./supervisor-DX8HnT5i.js";import{t as O}from"./useSupervisorAction-B1Piyga4.js";import{n as k,o as A,t as j}from"./widgets-DMpjcPY5.js";var M=w(n(),1),N=a();function P(){let[e,t]=(0,M.useState)(null),[n,r]=(0,M.useState)(null),[i,a]=(0,M.useState)(null),[o,c]=(0,M.useState)(``),[u,p]=(0,M.useState)(`hide`),{busy:m,run:v}=O(),S=(0,M.useCallback)(async()=>{let[e,n,i,o]=await Promise.all([y.autostart().catch(()=>null),y.lanPanel().catch(()=>null),y.accessKey().catch(()=>null),y.closeAction().catch(()=>null)]);e&&t(e.on),n&&r(n),i&&a(i),o&&p(o.closeAction)},[]);(0,M.useEffect)(()=>{S()},[S]);async function C(e){t(e);try{let n=await y.setAutostart(e);n.ok===!1?(g.error(n.error||`设置失败`),t(!e)):g.success(e?`已开启开机自启(整条服务链)`:`已关闭开机自启`)}catch(n){g.error(String(n)),t(!e)}}async function w(e){r(t=>t&&{...t,enabled:e});try{let t=await y.setLanPanel(e);if(t.ok===!1){g.error(t.error||`设置失败`),r(t=>t&&{...t,enabled:!e});return}r(t),g.success(e?`已开启局域网访问`:`已关闭局域网访问(仅本机)`)}catch(t){g.error(String(t)),r(t=>t&&{...t,enabled:!e})}}async function T(){let e=o.trim();if(e&&e.length<8){g.error(`访问密钥至少 8 位(建议 16+ 位随机串)`);return}await v(`akk`,()=>y.setAccessKey(e),{success:e?`访问密钥已设置`:`访问密钥已清除`,refresh:!1,onDone:()=>{c(``),S()}})}async function E(e){let t=e===`exit`?`exit`:`hide`;p(t),await v(`ca`,()=>y.setCloseAction(t),{success:t===`exit`?`已设为:关闭窗口时退出管家`:`已设为:关闭窗口时隐藏至托盘`,refresh:!1})}return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(j,{children:[(0,N.jsx)(k,{title:`启动`,subtitle:`开机行为与偏好`}),(0,N.jsxs)(`div`,{className:`grid gap-4 px-5 py-4`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-6`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`strong`,{className:`block text-sm font-medium text-foreground`,children:`开机自动启动管家`}),(0,N.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`开机登录后自动启动 DeepSeek Harness 管家(本程序)。不会自动启动任何单个实例——实例是否被自动拉起,由各自「进程守护」开关决定。`})]}),e===null?(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`…`}):(0,N.jsx)(`span`,{title:`开机自启`,children:(0,N.jsx)(l,{checked:e,onCheckedChange:e=>void C(e)})})]}),(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-6 border-t border-border/60 pt-4`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`strong`,{className:`block text-sm font-medium text-foreground`,children:`关闭窗口时`}),(0,N.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`隐藏至托盘:管家与服务继续在后台运行;退出管家:关闭并停止全部服务。`})]}),(0,N.jsxs)(b,{value:u,onValueChange:e=>void E(e),children:[(0,N.jsx)(x,{className:`w-[150px]`,children:(0,N.jsx)(f,{})}),(0,N.jsxs)(d,{children:[(0,N.jsx)(_,{value:`hide`,children:`隐藏至托盘`}),(0,N.jsx)(_,{value:`exit`,children:`退出管家`})]})]})]})]})]}),(0,N.jsxs)(j,{children:[(0,N.jsx)(k,{title:`访问`}),(0,N.jsxs)(`div`,{className:`grid gap-4 px-5 py-4`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-6`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`strong`,{className:`block text-sm font-medium text-foreground`,children:`管家局域网访问`}),n?n.enabled?(0,N.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`开启后,局域网内设备可通过\xA0`,(n.urls??[]).map((e,t)=>(0,N.jsxs)(`span`,{children:[t>0?`、 `:null,(0,N.jsx)(`code`,{className:`rounded bg-muted px-1 py-px font-mono text-foreground`,children:e})]},e)),`\xA0访问本面板。`]}):(0,N.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`关闭后仅本机可访问,局域网设备不可用。`}):null]}),n===null?(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`…`}):(0,N.jsx)(`span`,{title:`局域网访问`,children:(0,N.jsx)(l,{checked:n.enabled,onCheckedChange:e=>void w(e)})})]}),(0,N.jsx)(`div`,{className:`flex items-start justify-between gap-6 border-t border-border/60 pt-4`,children:(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`strong`,{className:`block text-sm font-medium text-foreground`,children:`访问密钥`}),(0,N.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`局域网或公网访问本面板需携带此密钥;本机访问不受影响。留空保存可清除。`,i?.configured?(0,N.jsx)(`span`,{className:`mt-1 block text-status-ok`,children:`当前:已设置`}):(0,N.jsx)(`span`,{className:`mt-1 block text-muted-foreground`,children:`当前:未设置`})]})]})}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(h,{type:`password`,autoComplete:`new-password`,placeholder:`输入 ≥8 位访问密钥(建议随机长串)`,value:o,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T()},className:`flex-1`}),(0,N.jsx)(s,{variant:`outline`,onClick:()=>c(``),disabled:!o&&!i?.configured,children:`清除`}),(0,N.jsx)(s,{disabled:m===`akk`,onClick:()=>void T(),children:i?.configured?`更新密钥`:`设置密钥`})]})]})]})]})}function F(){let[n,a]=(0,M.useState)(null),[c,l]=(0,M.useState)(`auto`),[u,d]=(0,M.useState)([]),[f,m]=(0,M.useState)(``),[_,b]=(0,M.useState)(``),[x,C]=(0,M.useState)(!1),w=(0,M.useRef)(null),{busy:P,run:F}=O();(0,M.useEffect)(()=>{if(!x||!w.current)return;let e=window.setTimeout(()=>{let e=w.current;e&&e.scrollIntoView({block:`start`,behavior:`smooth`})},320);return()=>window.clearTimeout(e)},[x]);let L=(0,M.useCallback)(async()=>{let e=await y.registry().catch(()=>null);a(e)},[]);(0,M.useEffect)(()=>{L()},[L]),(0,M.useEffect)(()=>{n&&(l(n.mode||`auto`),d((n.candidates??[]).map(e=>e.origin)),m(n.manualOrigin||``))},[n]);let R=()=>{let e=_.trim();if(!/^https?:\/\//.test(e)){g.error(`请输入合法的镜像 URL`);return}if(u.includes(e)){g.info(`已在列表中`);return}d(t=>[...t,e]),b(``)};async function z(){let e={mode:c,origins:u};if(c===`manual`){if(!/^https?:\/\//.test(f.trim())){g.error(`手动模式需提供合法镜像 URL`);return}e.manualOrigin=f.trim()}await F(`reg`,()=>y.registrySet(e),{success:`已保存镜像配置`,refresh:!1,onDone:()=>void L()})}async function B(){await F(`regr`,()=>y.registryRefresh(),{success:`已探测镜像`,refresh:!1,onDone:()=>void L()})}let V=e=>{let t=(n?.probes??[]).find(t=>t.origin===e);return t&&t.ok?t.latencyMs:null};return(0,N.jsxs)(j,{children:[(0,N.jsx)(k,{title:`镜像源`,subtitle:`npm 拉取 / 更新检测共用此源`}),(0,N.jsxs)(`div`,{className:`grid gap-3 px-5 py-4`,children:[(0,N.jsxs)(p,{value:c,onValueChange:e=>l(e),className:`flex gap-3`,children:[(0,N.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1.5 text-sm`,children:[(0,N.jsx)(v,{value:`auto`,id:`reg-auto`}),(0,N.jsx)(`span`,{children:`自动(按延迟选最快)`})]}),(0,N.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1.5 text-sm`,children:[(0,N.jsx)(v,{value:`manual`,id:`reg-manual`}),(0,N.jsx)(`span`,{children:`手动(固定指定)`})]})]}),c===`manual`?(0,N.jsx)(`div`,{className:`grid gap-1.5`,children:(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(h,{placeholder:`https://registry.npmmirror.com`,value:f,onChange:e=>m(e.target.value),className:`flex-1`}),(0,N.jsx)(s,{variant:`outline`,onClick:()=>void I(f),children:`测试`})]})}):null,(0,N.jsxs)(S,{open:x,onOpenChange:C,className:`grid gap-1`,children:[(0,N.jsxs)(e,{ref:w,children:[(0,N.jsxs)(`span`,{className:`text-xs font-medium text-foreground`,children:[`候选镜像列表(`,u.length,`)`]}),x?(0,N.jsx)(r,{className:`size-3.5 text-muted-foreground`}):(0,N.jsx)(i,{className:`size-3.5 text-muted-foreground`})]}),x?null:(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border/70 px-3 py-1.5`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(A,{tone:`ok`,children:`当前`}),(0,N.jsx)(`code`,{className:`truncate font-mono text-xs text-muted-foreground`,children:n?.origin||`未选择`})]}),n?.origin&&V(n.origin)!=null?(0,N.jsxs)(`span`,{className:`shrink-0 text-xs font-medium tabular-nums`,children:[V(n.origin),`ms`]}):null]}),(0,N.jsx)(o,{children:(0,N.jsx)(`div`,{className:`rounded-md border border-border/70`,children:u.map((e,t)=>(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-border/50 px-3 py-1.5 last:border-b-0`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[n?.origin===e?(0,N.jsx)(A,{tone:`ok`,children:`当前`}):null,(0,N.jsx)(`code`,{className:`truncate font-mono text-xs text-muted-foreground`,children:e})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[V(e)==null?(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:`—`}):(0,N.jsxs)(`span`,{className:`text-xs font-medium tabular-nums`,title:`延迟毫秒数(自动探测)`,children:[V(e),(0,N.jsx)(`span`,{className:`text-muted-foreground/60`,children:`ms`})]}),(0,N.jsx)(s,{size:`chip`,variant:`ghost`,onClick:()=>d(t=>t.filter(t=>t!==e)),title:`移除该候选镜像`,children:(0,N.jsx)(E,{className:`size-3.5 text-destructive`})})]})]},t))})})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(h,{placeholder:`https://… 添加自定义镜像`,value:_,onChange:e=>b(e.target.value),className:`flex-1`,onKeyDown:e=>{e.key===`Enter`&&R()}}),(0,N.jsxs)(s,{variant:`outline`,onClick:R,children:[(0,N.jsx)(D,{className:`size-4`}),`添加`]})]}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsxs)(s,{size:`sm`,disabled:P===`regr`,onClick:()=>void B(),variant:`outline`,children:[(0,N.jsx)(T,{className:t(`size-3.5`,P===`regr`&&`animate-spin`)}),`重新探测`]}),(0,N.jsx)(s,{disabled:P===`reg`,onClick:()=>void z(),children:`保存`})]})]})]})}async function I(e){if(!/^https?:\/\//.test(e)){g.error(`请输入合法镜像 URL`);return}g.info(`测试中…`);try{let t=await y.registryProbe(e.replace(/\/+$/,``));t&&t.ok===!0&&typeof t.latencyMs==`number`?g.success(`可达,延迟 `+t.latencyMs+` ms`):t&&typeof t.error==`string`&&t.error?g.error(`探测失败:`+t.error):g.error(`不可达`)}catch(e){g.error(`探测失败:`+(e instanceof Error?e.message:String(e)))}}var L=`DeepSeek Harness 管家`,R=`独立于 Harness 运行的系统级守卫:负责启动、存活监测与故障自动重启被监管目标,提供生命周期管理、智能路由、远程控制与多实例沙箱的运维面板。`,z=e=>e?String(e).replace(/^v/i,``):`—`;function B(){let[e,n]=(0,M.useState)(null),[r,i]=(0,M.useState)(null),[a,o]=(0,M.useState)(!1),[l,d]=(0,M.useState)(`dsh`),[f,p]=(0,M.useState)(``),{busy:h,run:_}=O(),v=(0,M.useCallback)(async e=>{d(e),p(``),o(!0);try{let t=e===`dsh`?await y.dshChangelog():await y.guardChangelog();p(t||`(无内容)`)}catch(e){p(`加载失败:`+String(e))}},[]),b=(0,M.useCallback)(async()=>{let[e,t]=await Promise.all([y.guardVersion().catch(()=>null),y.shellStatus().catch(()=>null)]);n(e||{}),i(t?{version:t.identity?.version||null,capable:t.identity?.selfUpdateCapable===!0,installKind:t.identity?.installKind}:{})},[]);(0,M.useEffect)(()=>{b()},[b]),(0,M.useEffect)(()=>{let e=!0;return(async()=>{let[t,r]=await Promise.all([y.selfUpdateStatus().catch(()=>null),y.shellCheckUpdate().catch(()=>null)]);e&&(t&&t.ok!==!1&&n(e=>({...e||{},...t})),r&&i(e=>({...e||{},latest:r.latest||null,updateAvailable:r.updateAvailable===!0,error:r.error||null})))})(),()=>{e=!1}},[]);let x=async()=>{await _(`chk`,async()=>{let e=`内核:状态未知`,t=await y.selfUpdateStatus().catch(()=>null);if(t&&t.ok!==!1)n(t||{}),e=t.updateAvailable&&t.latest?`内核有新版本 `+z(t.latest)+`(当前 `+z(t.installed)+`)`:`内核已是最新(`+z(t.installed)+`)`;else{let r=await y.guardVersion().catch(()=>null);if(r?.upstream===`git-repo`){let t=await y.guardVersionCheck().catch(()=>null);n({...r||{},...t||{}}),e=t?.updateAvailable?`内核源码仓库有上游更新(当前提交 `+(t.commit||r?.commit||`—`)+`)`:`内核源码仓库已是最新(提交 `+(r?.commit||t?.commit||`—`)+`)`}else e=`内核:`+(t&&t.error||`自更新未配置`)}let r=await y.shellCheckUpdate().catch(()=>null),a=`桌面壳:状态未知`;r&&r.ok!==!1?(i(e=>({...e||{},latest:r.latest||null,updateAvailable:r.updateAvailable===!0,error:null})),a=r.updateAvailable&&r.latest?`桌面壳有新版本 `+z(r.latest)+`(当前 `+z(r.installed)+`)`:`桌面壳已是最新(`+z(r.installed)+`)`):(i(e=>({...e||{},error:r&&r.error||`检测失败`})),a=`桌面壳:`+(r&&r.error||`检测失败`)),t?.updateAvailable&&t?.latest||r?.updateAvailable&&r?.latest?g.warning(e+`;`+a):g.success(e+`;`+a)},{refresh:!1})},S=async()=>{window.confirm(`发现内核新版本 `+z(e?.latest)+`,是否立即更新?`)&&await _(`upd`,async()=>{let e=await y.selfUpdateApply();if(e?.ok===!1){g.error(e.error||`更新失败`);return}if(e?.restartRequired){g.success(`内核已更新至 `+z(e.installed||e.latest)+`,正在重启守卫…`);let t=await y.selfUpdateRestart().catch(()=>null);t?.ok===!1&&g.warning(`更新完成,请手动重启守卫:`+(t.error||``))}else g.success(`内核已是最新,无需更新`)},{refresh:!0})},w=async()=>{window.confirm(`将重启桌面壳以应用更新 `+z(r?.latest)+`。
1
+ import{C as e,E as t,L as n,M as r,N as i,O as a,S as o,T as s,_ as c,a as l,b as u,c as d,d as f,f as p,g as m,h,k as g,l as _,p as v,r as y,s as b,u as x,x as S,y as C,z as w}from"./supervisor-BVac7io-.js";import{t as T}from"./refresh-cw-CQuKs_Tk.js";import{c as E,l as D}from"./supervisor-DwJMunGH.js";import{t as O}from"./useSupervisorAction-B1Piyga4.js";import{n as k,o as A,t as j}from"./widgets-DMpjcPY5.js";var M=w(n(),1),N=a();function P(){let[e,t]=(0,M.useState)(null),[n,r]=(0,M.useState)(null),[i,a]=(0,M.useState)(null),[o,c]=(0,M.useState)(``),[u,p]=(0,M.useState)(`hide`),{busy:m,run:v}=O(),S=(0,M.useCallback)(async()=>{let[e,n,i,o]=await Promise.all([y.autostart().catch(()=>null),y.lanPanel().catch(()=>null),y.accessKey().catch(()=>null),y.closeAction().catch(()=>null)]);e&&t(e.on),n&&r(n),i&&a(i),o&&p(o.closeAction)},[]);(0,M.useEffect)(()=>{S()},[S]);async function C(e){t(e);try{let n=await y.setAutostart(e);n.ok===!1?(g.error(n.error||`设置失败`),t(!e)):g.success(e?`已开启开机自启(整条服务链)`:`已关闭开机自启`)}catch(n){g.error(String(n)),t(!e)}}async function w(e){r(t=>t&&{...t,enabled:e});try{let t=await y.setLanPanel(e);if(t.ok===!1){g.error(t.error||`设置失败`),r(t=>t&&{...t,enabled:!e});return}r(t),g.success(e?`已开启局域网访问`:`已关闭局域网访问(仅本机)`)}catch(t){g.error(String(t)),r(t=>t&&{...t,enabled:!e})}}async function T(){let e=o.trim();if(e&&e.length<8){g.error(`访问密钥至少 8 位(建议 16+ 位随机串)`);return}await v(`akk`,()=>y.setAccessKey(e),{success:e?`访问密钥已设置`:`访问密钥已清除`,refresh:!1,onDone:()=>{c(``),S()}})}async function E(e){let t=e===`exit`?`exit`:`hide`;p(t),await v(`ca`,()=>y.setCloseAction(t),{success:t===`exit`?`已设为:关闭窗口时退出管家`:`已设为:关闭窗口时隐藏至托盘`,refresh:!1})}return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(j,{children:[(0,N.jsx)(k,{title:`启动`,subtitle:`开机行为与偏好`}),(0,N.jsxs)(`div`,{className:`grid gap-4 px-5 py-4`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-6`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`strong`,{className:`block text-sm font-medium text-foreground`,children:`开机自动启动管家`}),(0,N.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`开机登录后自动启动 DeepSeek Harness 管家(本程序)。不会自动启动任何单个实例——实例是否被自动拉起,由各自「进程守护」开关决定。`})]}),e===null?(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`…`}):(0,N.jsx)(`span`,{title:`开机自启`,children:(0,N.jsx)(l,{checked:e,onCheckedChange:e=>void C(e)})})]}),(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-6 border-t border-border/60 pt-4`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`strong`,{className:`block text-sm font-medium text-foreground`,children:`关闭窗口时`}),(0,N.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`隐藏至托盘:管家与服务继续在后台运行;退出管家:关闭并停止全部服务。`})]}),(0,N.jsxs)(b,{value:u,onValueChange:e=>void E(e),children:[(0,N.jsx)(x,{className:`w-[150px]`,children:(0,N.jsx)(f,{})}),(0,N.jsxs)(d,{children:[(0,N.jsx)(_,{value:`hide`,children:`隐藏至托盘`}),(0,N.jsx)(_,{value:`exit`,children:`退出管家`})]})]})]})]})]}),(0,N.jsxs)(j,{children:[(0,N.jsx)(k,{title:`访问`}),(0,N.jsxs)(`div`,{className:`grid gap-4 px-5 py-4`,children:[(0,N.jsxs)(`div`,{className:`flex items-start justify-between gap-6`,children:[(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`strong`,{className:`block text-sm font-medium text-foreground`,children:`管家局域网访问`}),n?n.enabled?(0,N.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`开启后,局域网内设备可通过\xA0`,(n.urls??[]).map((e,t)=>(0,N.jsxs)(`span`,{children:[t>0?`、 `:null,(0,N.jsx)(`code`,{className:`rounded bg-muted px-1 py-px font-mono text-foreground`,children:e})]},e)),`\xA0访问本面板。`]}):(0,N.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:`关闭后仅本机可访问,局域网设备不可用。`}):null]}),n===null?(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`…`}):(0,N.jsx)(`span`,{title:`局域网访问`,children:(0,N.jsx)(l,{checked:n.enabled,onCheckedChange:e=>void w(e)})})]}),(0,N.jsx)(`div`,{className:`flex items-start justify-between gap-6 border-t border-border/60 pt-4`,children:(0,N.jsxs)(`div`,{className:`min-w-0`,children:[(0,N.jsx)(`strong`,{className:`block text-sm font-medium text-foreground`,children:`访问密钥`}),(0,N.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`局域网或公网访问本面板需携带此密钥;本机访问不受影响。留空保存可清除。`,i?.configured?(0,N.jsx)(`span`,{className:`mt-1 block text-status-ok`,children:`当前:已设置`}):(0,N.jsx)(`span`,{className:`mt-1 block text-muted-foreground`,children:`当前:未设置`})]})]})}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(h,{type:`password`,autoComplete:`new-password`,placeholder:`输入 ≥8 位访问密钥(建议随机长串)`,value:o,onChange:e=>c(e.target.value),onKeyDown:e=>{e.key===`Enter`&&T()},className:`flex-1`}),(0,N.jsx)(s,{variant:`outline`,onClick:()=>c(``),disabled:!o&&!i?.configured,children:`清除`}),(0,N.jsx)(s,{disabled:m===`akk`,onClick:()=>void T(),children:i?.configured?`更新密钥`:`设置密钥`})]})]})]})]})}function F(){let[n,a]=(0,M.useState)(null),[c,l]=(0,M.useState)(`auto`),[u,d]=(0,M.useState)([]),[f,m]=(0,M.useState)(``),[_,b]=(0,M.useState)(``),[x,C]=(0,M.useState)(!1),w=(0,M.useRef)(null),{busy:P,run:F}=O();(0,M.useEffect)(()=>{if(!x||!w.current)return;let e=window.setTimeout(()=>{let e=w.current;e&&e.scrollIntoView({block:`start`,behavior:`smooth`})},320);return()=>window.clearTimeout(e)},[x]);let L=(0,M.useCallback)(async()=>{let e=await y.registry().catch(()=>null);a(e)},[]);(0,M.useEffect)(()=>{L()},[L]),(0,M.useEffect)(()=>{n&&(l(n.mode||`auto`),d((n.candidates??[]).map(e=>e.origin)),m(n.manualOrigin||``))},[n]);let R=()=>{let e=_.trim();if(!/^https?:\/\//.test(e)){g.error(`请输入合法的镜像 URL`);return}if(u.includes(e)){g.info(`已在列表中`);return}d(t=>[...t,e]),b(``)};async function z(){let e={mode:c,origins:u};if(c===`manual`){if(!/^https?:\/\//.test(f.trim())){g.error(`手动模式需提供合法镜像 URL`);return}e.manualOrigin=f.trim()}await F(`reg`,()=>y.registrySet(e),{success:`已保存镜像配置`,refresh:!1,onDone:()=>void L()})}async function B(){await F(`regr`,()=>y.registryRefresh(),{success:`已探测镜像`,refresh:!1,onDone:()=>void L()})}let V=e=>{let t=(n?.probes??[]).find(t=>t.origin===e);return t&&t.ok?t.latencyMs:null};return(0,N.jsxs)(j,{children:[(0,N.jsx)(k,{title:`镜像源`,subtitle:`npm 拉取 / 更新检测共用此源`}),(0,N.jsxs)(`div`,{className:`grid gap-3 px-5 py-4`,children:[(0,N.jsxs)(p,{value:c,onValueChange:e=>l(e),className:`flex gap-3`,children:[(0,N.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1.5 text-sm`,children:[(0,N.jsx)(v,{value:`auto`,id:`reg-auto`}),(0,N.jsx)(`span`,{children:`自动(按延迟选最快)`})]}),(0,N.jsxs)(`label`,{className:`inline-flex cursor-pointer items-center gap-1.5 text-sm`,children:[(0,N.jsx)(v,{value:`manual`,id:`reg-manual`}),(0,N.jsx)(`span`,{children:`手动(固定指定)`})]})]}),c===`manual`?(0,N.jsx)(`div`,{className:`grid gap-1.5`,children:(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(h,{placeholder:`https://registry.npmmirror.com`,value:f,onChange:e=>m(e.target.value),className:`flex-1`}),(0,N.jsx)(s,{variant:`outline`,onClick:()=>void I(f),children:`测试`})]})}):null,(0,N.jsxs)(S,{open:x,onOpenChange:C,className:`grid gap-1`,children:[(0,N.jsxs)(e,{ref:w,children:[(0,N.jsxs)(`span`,{className:`text-xs font-medium text-foreground`,children:[`候选镜像列表(`,u.length,`)`]}),x?(0,N.jsx)(r,{className:`size-3.5 text-muted-foreground`}):(0,N.jsx)(i,{className:`size-3.5 text-muted-foreground`})]}),x?null:(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-md border border-border/70 px-3 py-1.5`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,N.jsx)(A,{tone:`ok`,children:`当前`}),(0,N.jsx)(`code`,{className:`truncate font-mono text-xs text-muted-foreground`,children:n?.origin||`未选择`})]}),n?.origin&&V(n.origin)!=null?(0,N.jsxs)(`span`,{className:`shrink-0 text-xs font-medium tabular-nums`,children:[V(n.origin),`ms`]}):null]}),(0,N.jsx)(o,{children:(0,N.jsx)(`div`,{className:`rounded-md border border-border/70`,children:u.map((e,t)=>(0,N.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-border/50 px-3 py-1.5 last:border-b-0`,children:[(0,N.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[n?.origin===e?(0,N.jsx)(A,{tone:`ok`,children:`当前`}):null,(0,N.jsx)(`code`,{className:`truncate font-mono text-xs text-muted-foreground`,children:e})]}),(0,N.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[V(e)==null?(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground/50`,children:`—`}):(0,N.jsxs)(`span`,{className:`text-xs font-medium tabular-nums`,title:`延迟毫秒数(自动探测)`,children:[V(e),(0,N.jsx)(`span`,{className:`text-muted-foreground/60`,children:`ms`})]}),(0,N.jsx)(s,{size:`chip`,variant:`ghost`,onClick:()=>d(t=>t.filter(t=>t!==e)),title:`移除该候选镜像`,children:(0,N.jsx)(E,{className:`size-3.5 text-destructive`})})]})]},t))})})]}),(0,N.jsxs)(`div`,{className:`flex gap-2`,children:[(0,N.jsx)(h,{placeholder:`https://… 添加自定义镜像`,value:_,onChange:e=>b(e.target.value),className:`flex-1`,onKeyDown:e=>{e.key===`Enter`&&R()}}),(0,N.jsxs)(s,{variant:`outline`,onClick:R,children:[(0,N.jsx)(D,{className:`size-4`}),`添加`]})]}),(0,N.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,N.jsxs)(s,{size:`sm`,disabled:P===`regr`,onClick:()=>void B(),variant:`outline`,children:[(0,N.jsx)(T,{className:t(`size-3.5`,P===`regr`&&`animate-spin`)}),`重新探测`]}),(0,N.jsx)(s,{disabled:P===`reg`,onClick:()=>void z(),children:`保存`})]})]})]})}async function I(e){if(!/^https?:\/\//.test(e)){g.error(`请输入合法镜像 URL`);return}g.info(`测试中…`);try{let t=await y.registryProbe(e.replace(/\/+$/,``));t&&t.ok===!0&&typeof t.latencyMs==`number`?g.success(`可达,延迟 `+t.latencyMs+` ms`):t&&typeof t.error==`string`&&t.error?g.error(`探测失败:`+t.error):g.error(`不可达`)}catch(e){g.error(`探测失败:`+(e instanceof Error?e.message:String(e)))}}var L=`DeepSeek Harness 管家`,R=`独立于 Harness 运行的系统级守卫:负责启动、存活监测与故障自动重启被监管目标,提供生命周期管理、智能路由、远程控制与多实例沙箱的运维面板。`,z=e=>e?String(e).replace(/^v/i,``):`—`;function B(){let[e,n]=(0,M.useState)(null),[r,i]=(0,M.useState)(null),[a,o]=(0,M.useState)(!1),[l,d]=(0,M.useState)(`dsh`),[f,p]=(0,M.useState)(``),{busy:h,run:_}=O(),v=(0,M.useCallback)(async e=>{d(e),p(``),o(!0);try{let t=e===`dsh`?await y.dshChangelog():await y.guardChangelog();p(t||`(无内容)`)}catch(e){p(`加载失败:`+String(e))}},[]),b=(0,M.useCallback)(async()=>{let[e,t]=await Promise.all([y.guardVersion().catch(()=>null),y.shellStatus().catch(()=>null)]);n(e||{}),i(t?{version:t.identity?.version||null,capable:t.identity?.selfUpdateCapable===!0,installKind:t.identity?.installKind}:{})},[]);(0,M.useEffect)(()=>{b()},[b]),(0,M.useEffect)(()=>{let e=!0;return(async()=>{let[t,r]=await Promise.all([y.selfUpdateStatus().catch(()=>null),y.shellCheckUpdate().catch(()=>null)]);e&&(t&&t.ok!==!1&&n(e=>({...e||{},...t})),r&&i(e=>({...e||{},latest:r.latest||null,updateAvailable:r.updateAvailable===!0,error:r.error||null})))})(),()=>{e=!1}},[]);let x=async()=>{await _(`chk`,async()=>{let e=`内核:状态未知`,t=await y.selfUpdateStatus().catch(()=>null);if(t&&t.ok!==!1)n(t||{}),e=t.updateAvailable&&t.latest?`内核有新版本 `+z(t.latest)+`(当前 `+z(t.installed)+`)`:`内核已是最新(`+z(t.installed)+`)`;else{let r=await y.guardVersion().catch(()=>null);if(r?.upstream===`git-repo`){let t=await y.guardVersionCheck().catch(()=>null);n({...r||{},...t||{}}),e=t?.updateAvailable?`内核源码仓库有上游更新(当前提交 `+(t.commit||r?.commit||`—`)+`)`:`内核源码仓库已是最新(提交 `+(r?.commit||t?.commit||`—`)+`)`}else e=`内核:`+(t&&t.error||`自更新未配置`)}let r=await y.shellCheckUpdate().catch(()=>null),a=`桌面壳:状态未知`;r&&r.ok!==!1?(i(e=>({...e||{},latest:r.latest||null,updateAvailable:r.updateAvailable===!0,error:null})),a=r.updateAvailable&&r.latest?`桌面壳有新版本 `+z(r.latest)+`(当前 `+z(r.installed)+`)`:`桌面壳已是最新(`+z(r.installed)+`)`):(i(e=>({...e||{},error:r&&r.error||`检测失败`})),a=`桌面壳:`+(r&&r.error||`检测失败`)),t?.updateAvailable&&t?.latest||r?.updateAvailable&&r?.latest?g.warning(e+`;`+a):g.success(e+`;`+a)},{refresh:!1})},S=async()=>{window.confirm(`发现内核新版本 `+z(e?.latest)+`,是否立即更新?`)&&await _(`upd`,async()=>{let e=await y.selfUpdateApply();if(e?.ok===!1){g.error(e.error||`更新失败`);return}if(e?.restartRequired){g.success(`内核已更新至 `+z(e.installed||e.latest)+`,正在重启守卫…`);let t=await y.selfUpdateRestart().catch(()=>null);t?.ok===!1&&g.warning(`更新完成,请手动重启守卫:`+(t.error||``))}else g.success(`内核已是最新,无需更新`)},{refresh:!0})},w=async()=>{window.confirm(`将重启桌面壳以应用更新 `+z(r?.latest)+`。
2
2
 
3
3
  桌面壳窗口会关闭并重新打开;内核与被管实例不受影响。是否继续?`)&&await _(`shupd`,async()=>{let e=await y.shellRestart();if(e?.ok===!1){g.error(e.error||`重启桌面壳失败`);return}g.success(`桌面壳正在重启,将在启动时自动更新至 `+z(r?.latest))},{refresh:!1})},E=!!(e?.updateAvailable&&e?.latest&&e.latest!==e?.installed),D=!!(r?.updateAvailable&&r?.latest&&r.latest!==r?.version),P=r?.capable===!1;return(0,N.jsxs)(j,{children:[(0,N.jsx)(k,{title:`关于`,subtitle:L,actions:(0,N.jsxs)(s,{size:`sm`,disabled:h===`chk`,onClick:()=>void x(),variant:`outline`,children:[(0,N.jsx)(T,{className:t(`size-3.5`,h===`chk`&&`animate-spin`)}),`检查更新`]})}),(0,N.jsxs)(`div`,{className:`grid gap-3 px-5 py-4`,children:[(0,N.jsxs)(`div`,{className:`grid grid-cols-[96px_minmax(0,1fr)] items-baseline gap-3`,children:[(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`桌面壳版本`}),(0,N.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium text-foreground`,children:[z(r?.version),r?.installKind?(0,N.jsxs)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:[`(`,r.installKind,`)`]}):null,D?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(A,{tone:`warn`,children:[`可更新 `,z(r?.latest)]}),(0,N.jsxs)(s,{size:`chip`,disabled:h===`shupd`,onClick:()=>void w(),variant:`outline`,children:[(0,N.jsx)(T,{className:t(`size-3`,h===`shupd`&&`animate-spin`)}),`重启并更新`]})]}):null,P?(0,N.jsx)(A,{tone:`off`,children:`当前形态不支持自更新`}):null,r?.error?(0,N.jsx)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:r.error}):null]})]}),(0,N.jsxs)(`div`,{className:`grid grid-cols-[96px_minmax(0,1fr)] items-baseline gap-3`,children:[(0,N.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`内核版本`}),(0,N.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium text-foreground`,children:[z(e?.installed||e?.version),E?(0,N.jsxs)(N.Fragment,{children:[(0,N.jsxs)(A,{tone:`warn`,children:[`可更新 `,z(e?.latest)]}),(0,N.jsxs)(s,{size:`chip`,disabled:h===`upd`,onClick:()=>void S(),variant:`outline`,children:[(0,N.jsx)(T,{className:t(`size-3`,h===`upd`&&`animate-spin`)}),`更新`]})]}):null]})]}),(0,N.jsx)(`p`,{className:`border-t border-border/60 pt-3 text-xs leading-relaxed text-muted-foreground`,children:R}),(0,N.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-border/60 pt-3`,children:[(0,N.jsx)(s,{size:`chip`,variant:`outline`,onClick:()=>void v(`dsh`),children:`DSH 更新日志`}),(0,N.jsx)(s,{size:`chip`,variant:`outline`,onClick:()=>void v(`guard`),children:`管家更新日志`})]})]}),(0,N.jsx)(m,{open:a,onOpenChange:o,children:(0,N.jsxs)(c,{className:`max-w-[560px]`,children:[(0,N.jsx)(C,{children:(0,N.jsx)(u,{children:l===`dsh`?`DeepSeek Harness 更新日志`:`管家更新日志`})}),(0,N.jsx)(`pre`,{className:`max-h-[50vh] overflow-auto whitespace-pre-wrap break-words rounded-md border border-border/60 bg-muted/30 p-3 text-xs leading-relaxed text-foreground`,children:f||`加载中…`})]})})]})}function V(){return(0,N.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,N.jsx)(P,{}),(0,N.jsx)(F,{}),(0,N.jsx)(B,{})]})}export{V as SettingsPage};
@@ -1,2 +1,2 @@
1
- import{E as e,L as t,O as n,T as r,k as i,r as a,z as o}from"./supervisor-BVac7io-.js";import{t as s}from"./refresh-cw-CQuKs_Tk.js";import{a as c,d as l,i as u,r as d}from"./supervisor-DX8HnT5i.js";import{o as f,t as p}from"./widgets-DMpjcPY5.js";import{r as m}from"./format-QeaTKFhQ.js";var h=o(t(),1),g=n();function _(){let[t,n]=(0,h.useState)(null),[o,_]=(0,h.useState)(!1),[v,y]=(0,h.useState)(``);async function b(){try{let e=await a.tasks();n(e.tasks)}catch(e){i.error(String(e))}}(0,h.useEffect)(()=>{b()},[]);async function x(){_(!0);try{await b(),i.success(`任务中心已刷新`)}catch{}finally{_(!1)}}let S=[`native`,`instance`,`plugin`,`proxy-app`],C=(t??[]).filter(e=>!v||e.kind===v);return(0,g.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,g.jsx)(r,{className:e(v?`text-muted-foreground hover:bg-muted hover:text-foreground`:`bg-primary/10 text-primary hover:bg-primary/15`),onClick:()=>y(``),size:`sm`,variant:`ghost`,children:`全部`}),S.map(t=>(0,g.jsx)(r,{className:e(v===t?`bg-primary/10 text-primary hover:bg-primary/15`:`text-muted-foreground hover:bg-muted hover:text-foreground`),onClick:()=>y(t),size:`sm`,variant:`ghost`,children:u[t]||t},t))]}),(0,g.jsxs)(r,{onClick:()=>void x(),variant:`outline`,children:[(0,g.jsx)(s,{className:e(`size-4`,o&&`animate-spin`)}),`刷新`]})]}),t?C.length?(0,g.jsx)(`div`,{className:`grid gap-3`,children:C.map(t=>{let n=c[t.state]||{label:t.state,tone:`off`},r=t.from&&t.to&&t.from!==t.to?t.from+` → `+t.to:t.to?`→ `+t.to:``,i=t.steps||[];return(0,g.jsxs)(p,{className:`p-4`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,g.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,g.jsx)(`span`,{className:`text-sm font-semibold text-foreground`,children:u[t.kind]||t.kind}),(0,g.jsx)(f,{tone:`boot`,children:d[t.action]||t.action}),(0,g.jsx)(`strong`,{className:`truncate text-sm text-foreground`,children:t.target.name}),r?(0,g.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:r}):null]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,g.jsx)(f,{tone:n.tone,children:n.label}),(0,g.jsxs)(`span`,{className:`whitespace-nowrap`,children:[m(t.startedAt),t.finishedAt?` ~ `+m(t.finishedAt):``]})]})]}),t.error?(0,g.jsx)(`p`,{className:`mt-2 truncate text-xs text-destructive`,title:t.error,children:t.error}):null,i.length?(0,g.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:i.map((t,n)=>(0,g.jsxs)(`span`,{className:e(`inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs leading-tight`,t.state===`done`&&`bg-success-background text-success`,t.state===`running`&&`bg-primary/10 text-primary`,t.state===`failed`&&`bg-careful-background text-careful`,(!t.state||t.state===`pending`)&&`bg-muted text-muted-foreground`),children:[t.state===`running`?(0,g.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}):null,t.name]},n))}):null,t.logTail?.length?(0,g.jsxs)(`details`,{className:`mt-3`,children:[(0,g.jsxs)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground`,children:[`日志(`,t.logTail.length,`)`]}),(0,g.jsx)(`pre`,{className:`mt-2 max-h-[180px] overflow-auto whitespace-pre-wrap break-all rounded-md bg-muted/70 p-3 font-mono text-xs leading-relaxed text-muted-foreground`,children:t.logTail.join(`
1
+ import{E as e,L as t,O as n,T as r,k as i,r as a,z as o}from"./supervisor-BVac7io-.js";import{t as s}from"./refresh-cw-CQuKs_Tk.js";import{a as c,d as l,i as u,r as d}from"./supervisor-DwJMunGH.js";import{o as f,t as p}from"./widgets-DMpjcPY5.js";import{r as m}from"./format-QeaTKFhQ.js";var h=o(t(),1),g=n();function _(){let[t,n]=(0,h.useState)(null),[o,_]=(0,h.useState)(!1),[v,y]=(0,h.useState)(``);async function b(){try{let e=await a.tasks();n(e.tasks)}catch(e){i.error(String(e))}}(0,h.useEffect)(()=>{b()},[]);async function x(){_(!0);try{await b(),i.success(`任务中心已刷新`)}catch{}finally{_(!1)}}let S=[`native`,`instance`,`plugin`,`proxy-app`],C=(t??[]).filter(e=>!v||e.kind===v);return(0,g.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,g.jsx)(r,{className:e(v?`text-muted-foreground hover:bg-muted hover:text-foreground`:`bg-primary/10 text-primary hover:bg-primary/15`),onClick:()=>y(``),size:`sm`,variant:`ghost`,children:`全部`}),S.map(t=>(0,g.jsx)(r,{className:e(v===t?`bg-primary/10 text-primary hover:bg-primary/15`:`text-muted-foreground hover:bg-muted hover:text-foreground`),onClick:()=>y(t),size:`sm`,variant:`ghost`,children:u[t]||t},t))]}),(0,g.jsxs)(r,{onClick:()=>void x(),variant:`outline`,children:[(0,g.jsx)(s,{className:e(`size-4`,o&&`animate-spin`)}),`刷新`]})]}),t?C.length?(0,g.jsx)(`div`,{className:`grid gap-3`,children:C.map(t=>{let n=c[t.state]||{label:t.state,tone:`off`},r=t.from&&t.to&&t.from!==t.to?t.from+` → `+t.to:t.to?`→ `+t.to:``,i=t.steps||[];return(0,g.jsxs)(p,{className:`p-4`,children:[(0,g.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,g.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,g.jsx)(`span`,{className:`text-sm font-semibold text-foreground`,children:u[t.kind]||t.kind}),(0,g.jsx)(f,{tone:`boot`,children:d[t.action]||t.action}),(0,g.jsx)(`strong`,{className:`truncate text-sm text-foreground`,children:t.target.name}),r?(0,g.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:r}):null]}),(0,g.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,g.jsx)(f,{tone:n.tone,children:n.label}),(0,g.jsxs)(`span`,{className:`whitespace-nowrap`,children:[m(t.startedAt),t.finishedAt?` ~ `+m(t.finishedAt):``]})]})]}),t.error?(0,g.jsx)(`p`,{className:`mt-2 truncate text-xs text-destructive`,title:t.error,children:t.error}):null,i.length?(0,g.jsx)(`div`,{className:`mt-3 flex flex-wrap items-center gap-1.5`,children:i.map((t,n)=>(0,g.jsxs)(`span`,{className:e(`inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs leading-tight`,t.state===`done`&&`bg-success-background text-success`,t.state===`running`&&`bg-primary/10 text-primary`,t.state===`failed`&&`bg-careful-background text-careful`,(!t.state||t.state===`pending`)&&`bg-muted text-muted-foreground`),children:[t.state===`running`?(0,g.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}):null,t.name]},n))}):null,t.logTail?.length?(0,g.jsxs)(`details`,{className:`mt-3`,children:[(0,g.jsxs)(`summary`,{className:`cursor-pointer text-xs text-muted-foreground hover:text-foreground`,children:[`日志(`,t.logTail.length,`)`]}),(0,g.jsx)(`pre`,{className:`mt-2 max-h-[180px] overflow-auto whitespace-pre-wrap break-all rounded-md bg-muted/70 p-3 font-mono text-xs leading-relaxed text-muted-foreground`,children:t.logTail.join(`
2
2
  `)})]}):null]},t.id)})}):(0,g.jsxs)(`div`,{className:`grid place-items-center rounded-lg border border-dashed border-border py-16 text-center`,children:[(0,g.jsx)(l,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,g.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`暂无任务记录。安装 / 升级 / 卸载 / 更新操作完成后会在此显示状态与历史。`})]}):(0,g.jsx)(`div`,{className:`grid place-items-center py-16 text-sm text-muted-foreground`,children:`加载中…`})]})}export{_ as TasksPage};