@dsh-sup/dsh-core-linux-x64 0.1.6-BETA.11 → 0.1.6-BETA.12
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 +17 -12
- package/package.json +1 -1
- package/ui-react/assets/{InstancesPage--LhDhPDs.js → InstancesPage-DadqCqud.js} +1 -1
- package/ui-react/assets/{LanPage-D7soTx9V.js → LanPage-DWzQ-VLz.js} +1 -1
- package/ui-react/assets/{OverviewPage-DxCKB6BV.js → OverviewPage-D9y-GeR2.js} +1 -1
- package/ui-react/assets/{PluginsPage-mISvN5b8.js → PluginsPage-BwLIhj7E.js} +1 -1
- package/ui-react/assets/{RouterPage-vhAx87Fo.js → RouterPage-BeMIxdSL.js} +1 -1
- package/ui-react/assets/{SettingsPage-DgA5JCBo.js → SettingsPage-R7lkiQwq.js} +1 -1
- package/ui-react/assets/{TasksPage-CGdHy0sy.js → TasksPage-A3SFro8F.js} +1 -1
- package/ui-react/assets/openExternal-DOkxrLUq.js +1 -0
- package/ui-react/assets/{supervisor-C_6Efj6Z.js → supervisor-Btn_MIEc.js} +2 -2
- package/ui-react/assets/supervisor-YWIsBeZU.css +2 -0
- package/ui-react/supervisor.html +2 -2
- package/ui-react/assets/openExternal-CBH3SnvT.js +0 -1
- package/ui-react/assets/supervisor-B5Bq0rnN.css +0 -2
package/core.cjs
CHANGED
|
@@ -947,7 +947,7 @@ var require_version = __commonJS({
|
|
|
947
947
|
var fs2 = require("node:fs");
|
|
948
948
|
var path2 = require("node:path");
|
|
949
949
|
function guardVersion() {
|
|
950
|
-
if (true) return String("0.1.6-BETA.
|
|
950
|
+
if (true) return String("0.1.6-BETA.12");
|
|
951
951
|
try {
|
|
952
952
|
return JSON.parse(fs2.readFileSync(path2.join(__dirname, "..", "..", "package.json"), "utf8")).version || "unknown";
|
|
953
953
|
} catch {
|
|
@@ -4755,8 +4755,8 @@ var require_capability_profile = __commonJS({
|
|
|
4755
4755
|
autostart: true,
|
|
4756
4756
|
// 期望 schtasks(实测覆写)
|
|
4757
4757
|
frpExpose: true,
|
|
4758
|
-
//
|
|
4759
|
-
//
|
|
4758
|
+
// 可打开,但 win32 的两种启动形态(explorer.exe 调度器 / 裸 URL 直启解析到的浏览器)退出码都不携带
|
|
4759
|
+
// 窗口是否出现的信息,故每次调用最多到 handedOff(见 browser.js#ownsItsWindow)。能力位只声明「能交出去」。
|
|
4760
4760
|
openBrowser: true,
|
|
4761
4761
|
hostService: "windows-service",
|
|
4762
4762
|
guardAutostart: true,
|
|
@@ -5496,26 +5496,30 @@ var require_browser = __commonJS({
|
|
|
5496
5496
|
};
|
|
5497
5497
|
}
|
|
5498
5498
|
var CONFIRMED_TEXT = "\u5DF2\u5728\u7CFB\u7EDF\u6D4F\u89C8\u5668\u6253\u5F00";
|
|
5499
|
-
var HANDEDOFF_TEXT = "\u5DF2\u628A\u5730\u5740\u4EA4\u7ED9\u7CFB\u7EDF\uFF0C\u4F46\
|
|
5499
|
+
var HANDEDOFF_TEXT = "\u5DF2\u628A\u5730\u5740\u4EA4\u7ED9\u7CFB\u7EDF\uFF0C\u4F46\u8FD9\u6B21\u542F\u52A8\u62FF\u4E0D\u5230\u7A97\u53E3\u662F\u5426\u51FA\u73B0\u7684\u8BC1\u636E";
|
|
5500
5500
|
var FAILURE_TEXT = {
|
|
5501
5501
|
"unsafe-url": "\u5730\u5740\u4E0D\u662F http(s) \u7EDD\u5BF9 URL\uFF0C\u5DF2\u62D2\u7EDD\u4EA4\u7ED9\u6D4F\u89C8\u5668",
|
|
5502
5502
|
"no-launcher": "\u672A\u627E\u5230\u53EF\u7528\u7684\u6D4F\u89C8\u5668\u542F\u52A8\u547D\u4EE4\uFF0C\u8BF7\u624B\u52A8\u6253\u5F00\u8BE5\u5730\u5740",
|
|
5503
5503
|
"spawn-failed": "\u6D4F\u89C8\u5668\u542F\u52A8\u5931\u8D25\uFF08\u7CFB\u7EDF\u62D2\u7EDD\u4E86\u8BE5\u547D\u4EE4\uFF09",
|
|
5504
|
-
"exit-nonzero": "\
|
|
5505
|
-
"killed-by-signal": "\u6D4F\u89C8\u5668\u542F\u52A8\u547D\u4EE4\u88AB\u7CFB\u7EDF\u7EC8\u6B62",
|
|
5504
|
+
"exit-nonzero": "\u7CFB\u7EDF\u62D2\u7EDD\u4E86\u8FD9\u4E2A\u5730\u5740\uFF08\u542F\u52A8\u547D\u4EE4\u975E 0 \u9000\u51FA\uFF09\uFF0C\u7A97\u53E3\u672A\u51FA\u73B0",
|
|
5505
|
+
"killed-by-signal": "\u6D4F\u89C8\u5668\u542F\u52A8\u547D\u4EE4\u88AB\u7CFB\u7EDF\u7EC8\u6B62\uFF0C\u7A97\u53E3\u672A\u51FA\u73B0",
|
|
5506
5506
|
"no-desktop-session": "\u5F53\u524D\u6CA1\u6709\u56FE\u5F62\u4F1A\u8BDD\uFF0C\u65E0\u6CD5\u8C03\u8D77\u6D4F\u89C8\u5668",
|
|
5507
5507
|
"unsupported-platform": "\u5F53\u524D\u5E73\u53F0\u4E0D\u5728\u4EA7\u54C1\u652F\u6301\u7684\u684C\u9762\u5E73\u53F0\u5185\uFF0C\u8BF7\u624B\u52A8\u6253\u5F00\u8BE5\u5730\u5740"
|
|
5508
5508
|
};
|
|
5509
|
+
function ownsItsWindow(via, platform) {
|
|
5510
|
+
if (via !== "dispatcher") return false;
|
|
5511
|
+
return platform !== "win32";
|
|
5512
|
+
}
|
|
5509
5513
|
function openPlan(platform, url, opts) {
|
|
5510
5514
|
const o = opts || {};
|
|
5511
5515
|
const pl = platform || process.platform;
|
|
5512
5516
|
const db = o.defaultBrowser;
|
|
5513
5517
|
const engine = db && db.bin ? engineOf(db.bin) : "other";
|
|
5514
5518
|
if (engine === "chromium" || engine === "firefox") {
|
|
5515
|
-
return { bin: db.bin, engine, via: "browser", baseArgs: (db.baseArgs || []).concat([url]),
|
|
5519
|
+
return { bin: db.bin, engine, via: "browser", baseArgs: (db.baseArgs || []).concat([url]), exitIsEvidence: ownsItsWindow("browser", pl) };
|
|
5516
5520
|
}
|
|
5517
5521
|
const c = openCommand(pl, url);
|
|
5518
|
-
return { bin: c.cmd, engine: "other", via: "dispatcher", baseArgs: c.args,
|
|
5522
|
+
return { bin: c.cmd, engine: "other", via: "dispatcher", baseArgs: c.args, exitIsEvidence: ownsItsWindow("dispatcher", pl) };
|
|
5519
5523
|
}
|
|
5520
5524
|
function observeSpawn(child, windowMs, setTimeoutFn) {
|
|
5521
5525
|
return new Promise((resolve) => {
|
|
@@ -5552,7 +5556,7 @@ var require_browser = __commonJS({
|
|
|
5552
5556
|
else if (typeof opts.resolveDefault === "function") db = opts.resolveDefault(pl, opts.resolveDeps || {});
|
|
5553
5557
|
else db = resolveDefaultBrowser(pl, opts.resolveDeps || {});
|
|
5554
5558
|
const plan = openPlan(pl, url, { defaultBrowser: db });
|
|
5555
|
-
const evidence = { bin: plan.bin, engine: plan.engine, via: plan.via, exitCode: null, exitSignal: null, error: null };
|
|
5559
|
+
const evidence = { bin: plan.bin, engine: plan.engine, via: plan.via, ownsWindow: plan.exitIsEvidence === true, exitCode: null, exitSignal: null, error: null };
|
|
5556
5560
|
const desktopAvailable = typeof opts.desktopAvailable === "function" ? opts.desktopAvailable : desktop.sessionAvailable;
|
|
5557
5561
|
if (pl === "linux" && !desktopAvailable()) {
|
|
5558
5562
|
return outcome({ ok: false, reason: "no-desktop-session", url, evidence });
|
|
@@ -5573,7 +5577,8 @@ var require_browser = __commonJS({
|
|
|
5573
5577
|
evidence.exitCode = seen.code === void 0 ? null : seen.code;
|
|
5574
5578
|
evidence.exitSignal = seen.signal === void 0 ? null : seen.signal;
|
|
5575
5579
|
if (seen.stage === "error") return outcome({ ok: false, reason: "spawn-failed", url, evidence });
|
|
5576
|
-
|
|
5580
|
+
const exitDecides = seen.stage === "exit" && plan.exitIsEvidence === true;
|
|
5581
|
+
if (exitDecides && (seen.code !== 0 || seen.signal)) {
|
|
5577
5582
|
return outcome({
|
|
5578
5583
|
ok: false,
|
|
5579
5584
|
reason: seen.signal ? "killed-by-signal" : "exit-nonzero",
|
|
@@ -5582,8 +5587,7 @@ var require_browser = __commonJS({
|
|
|
5582
5587
|
error: FAILURE_TEXT[seen.signal ? "killed-by-signal" : "exit-nonzero"] + "\uFF08" + (seen.signal || seen.code) + "\uFF09"
|
|
5583
5588
|
});
|
|
5584
5589
|
}
|
|
5585
|
-
|
|
5586
|
-
return outcome({ ok: true, confirmed: exitEvidence, handedOff: !exitEvidence, url, evidence });
|
|
5590
|
+
return outcome({ ok: true, confirmed: exitDecides, handedOff: !exitDecides, url, evidence });
|
|
5587
5591
|
}
|
|
5588
5592
|
function _spawnDetachedIgnored(bin, args) {
|
|
5589
5593
|
try {
|
|
@@ -5826,6 +5830,7 @@ var require_browser = __commonJS({
|
|
|
5826
5830
|
launchIsolated,
|
|
5827
5831
|
openCommand,
|
|
5828
5832
|
openPlan,
|
|
5833
|
+
ownsItsWindow,
|
|
5829
5834
|
isolatedPlan,
|
|
5830
5835
|
observeSpawn,
|
|
5831
5836
|
isSafeHttpUrl,
|
package/package.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{F as e,I as t,L as n,N as r,O as i,R as a,S as o,U as s,V as c,_ as l,a as u,b as d,c as f,g as p,k as m,n as h,o as g,t as _,v,x as y,y as b}from"./supervisor-BbSavtNN.js";import{r as x,t as S}from"./openExternal-
|
|
1
|
+
import{F as e,I as t,L as n,N as r,O as i,R as a,S as o,U as s,V as c,_ as l,a as u,b as d,c as f,g as p,k as m,n as h,o as g,t as _,v,x as y,y as b}from"./supervisor-BbSavtNN.js";import{r as x,t as S}from"./openExternal-DOkxrLUq.js";import{n as C,t as w}from"./rocket-CLAmwatt.js";import{t as ee}from"./shield-check-CMRwmPpk.js";import{c as T,f as E,o as D,s as te}from"./supervisor-Btn_MIEc.js";import{t as O}from"./useSupervisorAction-q0YJmhui.js";import{c as k,i as A,o as j,r as M,t as N}from"./widgets-BbRkZm-Z.js";var ne=r(`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`}]]),P=r(`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`}]]),F=r(`square`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}]]),I=s(c(),1),L=a();function R({onRegisterActions:r}){let{snap:a}=_(),{busy:s,run:c}=O(),R=e(),[z,B]=(0,I.useState)(!1),[V,H]=(0,I.useState)(``),[U,W]=(0,I.useState)(``),[G,K]=(0,I.useState)(``),q=a.instances?.instances??[],[J,Y]=(0,I.useState)(null);(0,I.useEffect)(()=>{let e=!0;return u.envStatus().then(t=>{e&&Y(t.capabilities??null)}).catch(()=>void 0),()=>{e=!1}},[]);let X=J!==null&&J.sandboxLaunch===!1,Z=J?.sandboxEnforcement===`supervise`,Q=J==null?null:J.sandboxEnforcement===`cgroup`?`cgroup 内核硬限`:Z?`采样式软限(超限由守卫按拍数收割重启,非内核级强制)`:`无内核级限额`;(0,I.useEffect)(()=>(r?.({onAdd:()=>B(!0)}),()=>r?.(null)),[r]);let $=(e,t)=>c(e,t),re=e=>c(e,()=>S(()=>u.instanceOpenWeb(e)).then(()=>void 0));async function ie(){if(X){i.error(`当前平台不支持沙箱实例(见 /env/status 能力矩阵)`);return}let e=parseInt(U,10);if(!Number.isFinite(e)||e<=0){i.error(`请填写有效端口`);return}let t=G?G.split(/\n/).map(e=>e.trim()).filter(Boolean):[];try{let n=await u.instanceAdd({name:V.trim()||`沙箱 `+e,port:e,command:t});if(n&&n.ok===!1){i.error(n.error||`添加失败`);return}i.success(`已添加实例`),B(!1),H(``),W(``),K(``),h.refresh()}catch(e){i.error(String(e))}}async function ae(e){await c(e.id,async()=>{let t=await u.instanceCheckUpdate(e.id);t.updateAvailable?(i.success(`发现新版 `+t.latest+`,可点「更新」升级`),se(t=>new Map(t).set(e.id,!0))):t.latest?i.info(`已是最新 `+t.latest):i.error(t.error||`版本检测失败`)})}let[oe,se]=(0,I.useState)(new Map);async function ce(e){await R({title:`升级该沙箱实例的 DSH 到最新版?`,description:`实例会短暂重启,进行中的请求中断。`,confirmText:`升级`})&&await c(e.id,()=>u.instanceUpgrade(e.id),{success:`升级已开始…`})}async function le(e){await R({title:`删除实例「`+e.name+`」?`,description:`将彻底删除该沙箱实例(含配置与运行时数据)。此操作不可恢复。`,confirmText:`删除实例`,tone:`destructive`})&&await c(e.id,async()=>{let t=await u.instanceRemove(e.id);t&&t.ok!==!1&&t.dataPreserved===!0?i.warning(`实例已移除,但因其单元仍在运行,数据目录已保留(未删除)——请先停止实例再删数据`):t&&t.ok===!1&&i.error(t.error||`删除失败`),h.refresh()})}let ue=({it:e})=>{let r=e.state?.running??!1,i=e.state?.lifecyclePhase,a=te(i,r),o=e.updateJob,c=o?.state===`running`,l=e.state?.allocation?.memoryMax||`—`,d=e.state?.allocation?.cpuQuota||`—`,p=e.state?.usage,h=p&&typeof p.memMb==`number`?p.memMb:null,g=p&&typeof p.cpuPct==`number`?p.cpuPct:null,_=s===e.id;return(0,L.jsxs)(N,{className:`overflow-visible`,children:[(0,L.jsxs)(`div`,{className:`grid grid-cols-1 @min-[720px]:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]`,children:[(0,L.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,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,L.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,L.jsx)(`strong`,{className:`truncate text-lg font-semibold tracking-[-0.01em] text-foreground`,children:e.name}),e.version?(0,L.jsxs)(`span`,{className:`font-mono text-sm text-muted-foreground`,children:[`v`,e.version]}):null]}),oe.get(e.id)?(0,L.jsxs)(t,{className:`text-primary-foreground`,onClick:()=>void ce(e),size:`chip`,children:[(0,L.jsx)(P,{className:`size-3`}),`更新`]}):(0,L.jsxs)(t,{className:`bg-primary/10 text-primary hover:bg-primary/15`,disabled:_||c,onClick:()=>void ae(e),size:`chip`,variant:`ghost`,children:[(0,L.jsx)(P,{className:n(`size-3`,_&&`animate-spin`)}),`检测更新`]})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,L.jsx)(k,{tone:a.tone,ping:a.tone===`ok`}),(0,L.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:a.label})]}),c?(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(f,{className:`size-3`}),`正在升级 DeepSeek Harness(`,o?.step||``,`)…`]}):null,e.state?.installing?(0,L.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(f,{className:`size-3`}),`正在安装…`]}):null,i===`FAILED`?(0,L.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-destructive`,children:[(0,L.jsx)(m,{className:`size-3.5`}),(0,L.jsx)(`span`,{className:`truncate`,children:e.state?.lastError||`失败`})]}):null]}),(0,L.jsx)(`div`,{className:`flex items-center bg-[image:var(--panel-accent-gradient)] px-6 py-5`,children:(0,L.jsxs)(`div`,{className:`grid w-full grid-cols-2 gap-x-6 gap-y-4 sm:grid-cols-4`,children:[(0,L.jsx)(A,{icon:(0,L.jsx)(E,{className:`size-4`}),label:`端口`,value:String(e.port),mono:!0}),(0,L.jsx)(A,{icon:(0,L.jsx)(F,{className:`size-4`}),label:`PID`,value:e.state?.pid?String(e.state.pid):`—`,mono:!0}),(0,L.jsx)(A,{icon:(0,L.jsx)(P,{className:`size-4`}),label:`重启次数`,value:String(e.state?.restartCount??0),mono:!0}),(0,L.jsx)(A,{icon:(0,L.jsx)(m,{className:`size-4`}),label:`最近故障`,value:e.state?.lastFailure?D(e.state.lastFailure):`无`,warn:!!e.state?.lastFailure})]})})]}),(0,L.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-t border-border/60 px-6 py-3`,children:[(0,L.jsxs)(`span`,{className:`hidden min-w-0 items-center lg:inline-flex gap-2 text-xs text-muted-foreground`,children:[(0,L.jsx)(M,{domain:`sandbox`}),(0,L.jsx)(j,{tone:e.remoteMode&&e.remoteMode!==`off`?`boot`:`off`,children:e.remoteMode===`wan`?`远程·公网`:e.remoteMode===`lan`?`远程·局域网`:`远程关闭`}),(0,L.jsxs)(`span`,{className:`whitespace-nowrap`,title:`配额由守卫按机器预算与活跃实例数动态推导`+(Q?`;执行档位:`+Q:``),children:[`配额 内存 `,l,` · CPU `,d,Z?`(软限)`:``]}),h===null&&g===null?null:(0,L.jsxs)(`span`,{className:`whitespace-nowrap`,title:`监督拍实测值(最近一次采样;停止或未采到不显示)`,children:[`占用 `,h===null?`—`:`${h}MB`,g===null?``:` · CPU ${Math.round(g)}%`]})]}),(0,L.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[(0,L.jsxs)(t,{disabled:!r,onClick:()=>void re(e.id),size:`sm`,title:`打开 DSH Web(自动带认证连接)`,variant:`outline`,className:`hidden md:inline-flex`,children:[(0,L.jsx)(x,{className:`size-4`}),`DSH Web`]}),(0,L.jsx)(t,{disabled:c,onClick:()=>void $(e.id,()=>r?u.instanceStop(e.id):u.instanceStart(e.id)),size:`sm`,variant:`outline`,children:r?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(C,{className:`size-4 text-status-error`}),`停止实例`]}):(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(w,{className:`size-4 text-primary`}),`启动实例`]})}),(0,L.jsx)(`span`,{"aria-hidden":`true`,className:`mx-1 h-5 w-px bg-border`}),(0,L.jsxs)(t,{disabled:_,onClick:()=>void $(e.id,()=>u.instanceUpdate(e.id,{guardian:!e.guardian})),size:`sm`,variant:`outline`,children:[(0,L.jsx)(ee,{className:n(`size-4`,e.guardian?`text-status-ok`:`text-muted-foreground`)}),e.guardian?`停止守护`:`启动守护`]}),(0,L.jsxs)(t,{className:`hidden h-[30px] md:inline-flex`,disabled:_,onClick:()=>void le(e),size:`sm`,variant:`destructive`,children:[(0,L.jsx)(T,{className:`size-4`}),`删除`]})]})]})]})};return(0,L.jsxs)(`div`,{className:`grid content-start gap-4`,children:[X?(0,L.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,L.jsx)(m,{className:`mt-0.5 size-3.5 shrink-0 text-amber-500`}),(0,L.jsxs)(`span`,{children:[`当前平台(`,J?.platform||`未知`,`)不支持沙箱实例(能力矩阵见 /env/status 的 capabilities.sandboxLaunch;限额执行档位见 capabilities.sandboxEnforcement)。 原生 DSH 主实例不受影响。`]})]}):null,q.length?(0,L.jsx)(`div`,{className:`grid gap-3`,children:q.map(e=>(0,L.jsx)(ue,{it:e},e.id))}):(0,L.jsx)(`div`,{className:`grid min-h-[220px] place-items-center rounded-lg border border-dashed border-border text-center`,children:(0,L.jsxs)(`div`,{children:[(0,L.jsx)(ne,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,L.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`尚未添加沙箱实例`}),(0,L.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:X?`当前平台不支持沙箱实例(见上方说明)`:`点击顶部「添加实例」创建沙箱`})]})}),(0,L.jsx)(v,{open:z,onOpenChange:B,children:(0,L.jsxs)(b,{className:`max-w-[440px]`,children:[(0,L.jsx)(y,{children:(0,L.jsx)(o,{children:`添加 DSH 实例`})}),(0,L.jsxs)(`div`,{className:`grid gap-3`,children:[(0,L.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,L.jsx)(p,{children:`实例名称`}),(0,L.jsx)(l,{placeholder:`如 沙箱二开`,value:V,onChange:e=>H(e.target.value)})]}),(0,L.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,L.jsx)(p,{children:`监听端口`}),(0,L.jsx)(l,{inputMode:`numeric`,placeholder:`如 3082`,value:U,onChange:e=>W(e.target.value)})]}),(0,L.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,L.jsx)(p,{children:`启动命令(每项一参数,可留空用默认)`}),(0,L.jsx)(g,{className:`min-h-[72px] font-mono text-sm`,placeholder:`node
|
|
2
2
|
/usr/local/bin/dsh
|
|
3
3
|
web`,value:G,onChange:e=>K(e.target.value)})]}),(0,L.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`内存/CPU 配额无需填写:启动时由守卫按机器预算与活跃实例数自动推导,实例增减后动态重分配。`,Q?` 执行档位:${Q}。`:``]})]}),(0,L.jsxs)(d,{children:[(0,L.jsx)(t,{onClick:()=>B(!1),variant:`outline`,children:`取消`}),(0,L.jsx)(t,{onClick:()=>void ie(),children:`添加`})]})]})})]})}export{R as InstancesPage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{F as e,H as t,I as n,L as r,N as i,O as a,R as o,S as s,U as c,V as l,_ as u,a as d,b as f,g as p,s as m,t as h,v as g,x as _,y as v}from"./supervisor-BbSavtNN.js";import{n as y,r as b,t as ee}from"./openExternal-
|
|
1
|
+
import{F as e,H as t,I as n,L as r,N as i,O as a,R as o,S as s,U as c,V as l,_ as u,a as d,b as f,g as p,s as m,t as h,v as g,x as _,y as v}from"./supervisor-BbSavtNN.js";import{n as y,r as b,t as ee}from"./openExternal-DOkxrLUq.js";import{t as x}from"./useSupervisorAction-q0YJmhui.js";import{n as S,o as C,r as w,t as T}from"./widgets-BbRkZm-Z.js";var te=i(`eye-off`,[[`path`,{d:`M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49`,key:`ct8e1f`}],[`path`,{d:`M14.084 14.158a3 3 0 0 1-4.242-4.242`,key:`151rxh`}],[`path`,{d:`M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143`,key:`13bj9a`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}]]),ne=i(`eye`,[[`path`,{d:`M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0`,key:`1nclc0`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]),re=i(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),ie=i(`key-round`,[[`path`,{d:`M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z`,key:`1s6t7t`}],[`circle`,{cx:`16.5`,cy:`7.5`,r:`.5`,fill:`currentColor`,key:`w0ekpg`}]]),ae=i(`landmark`,[[`path`,{d:`M10 18v-7`,key:`wt116b`}],[`path`,{d:`M11.119 2.205a2 2 0 0 1 1.762 0l7.84 3.846A.5.5 0 0 1 20.5 7h-17a.5.5 0 0 1-.22-.949z`,key:`yxxwt6`}],[`path`,{d:`M14 18v-7`,key:`vav6t3`}],[`path`,{d:`M18 18v-7`,key:`aexdmj`}],[`path`,{d:`M3 22h18`,key:`8prr45`}],[`path`,{d:`M6 18v-7`,key:`1ivflk`}]]),oe=i(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),se=i(`wrench`,[[`path`,{d:`M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.106-3.105c.32-.322.863-.22.983.218a6 6 0 0 1-8.259 7.057l-7.91 7.91a1 1 0 0 1-2.999-3l7.91-7.91a6 6 0 0 1 7.057-8.259c.438.12.54.662.219.984z`,key:`1ngwbx`}]]),E=t(((e,t)=>{t.exports=`SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED`})),D=t(((e,t)=>{var n=E();function r(){}function i(){}i.resetWarningCache=r,t.exports=function(){function e(e,t,r,i,a,o){if(o!==n){var s=Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw s.name=`Invariant Violation`,s}}e.isRequired=e;function t(){return e}var a={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:r};return a.PropTypes=a,a}})),O=t(((e,t)=>{t.exports=D()()})),k=c(l(),1),A=c(O(),1),j=function(e,t){let n=e,r=N[t],i=null,a=0,o=null,s=[],c={},l=function(e,t){a=n*4+17,i=function(e){let t=Array(e);for(let n=0;n<e;n+=1){t[n]=Array(e);for(let r=0;r<e;r+=1)t[n][r]=null}return t}(a),u(0,0),u(a-7,0),u(0,a-7),p(),f(),h(e,t),n>=7&&m(e),o??=v(n,r,s),g(o,t)},u=function(e,t){for(let n=-1;n<=7;n+=1)if(!(e+n<=-1||a<=e+n))for(let r=-1;r<=7;r+=1)t+r<=-1||a<=t+r||(0<=n&&n<=6&&(r==0||r==6)||0<=r&&r<=6&&(n==0||n==6)||2<=n&&n<=4&&2<=r&&r<=4?i[e+n][t+r]=!0:i[e+n][t+r]=!1)},d=function(){let e=0,t=0;for(let n=0;n<8;n+=1){l(!0,n);let r=F.getLostPoint(c);(n==0||e>r)&&(e=r,t=n)}return t},f=function(){for(let e=8;e<a-8;e+=1)i[e][6]??(i[e][6]=e%2==0);for(let e=8;e<a-8;e+=1)i[6][e]??(i[6][e]=e%2==0)},p=function(){let e=F.getPatternPosition(n);for(let t=0;t<e.length;t+=1)for(let n=0;n<e.length;n+=1){let r=e[t],a=e[n];if(i[r][a]==null)for(let e=-2;e<=2;e+=1)for(let t=-2;t<=2;t+=1)e==-2||e==2||t==-2||t==2||e==0&&t==0?i[r+e][a+t]=!0:i[r+e][a+t]=!1}},m=function(e){let t=F.getBCHTypeNumber(n);for(let n=0;n<18;n+=1){let r=!e&&(t>>n&1)==1;i[Math.floor(n/3)][n%3+a-8-3]=r}for(let n=0;n<18;n+=1){let r=!e&&(t>>n&1)==1;i[n%3+a-8-3][Math.floor(n/3)]=r}},h=function(e,t){let n=r<<3|t,o=F.getBCHTypeInfo(n);for(let t=0;t<15;t+=1){let n=!e&&(o>>t&1)==1;t<6?i[t][8]=n:t<8?i[t+1][8]=n:i[a-15+t][8]=n}for(let t=0;t<15;t+=1){let n=!e&&(o>>t&1)==1;t<8?i[8][a-t-1]=n:t<9?i[8][15-t-1+1]=n:i[8][15-t-1]=n}i[a-8][8]=!e},g=function(e,t){let n=-1,r=a-1,o=7,s=0,c=F.getMaskFunction(t);for(let t=a-1;t>0;t-=2)for(t==6&&--t;;){for(let n=0;n<2;n+=1)if(i[r][t-n]==null){let a=!1;s<e.length&&(a=(e[s]>>>o&1)==1),c(r,t-n)&&(a=!a),i[r][t-n]=a,--o,o==-1&&(s+=1,o=7)}if(r+=n,r<0||a<=r){r-=n,n=-n;break}}},_=function(e,t){let n=0,r=0,i=0,a=Array(t.length),o=Array(t.length);for(let s=0;s<t.length;s+=1){let c=t[s].dataCount,l=t[s].totalCount-c;r=Math.max(r,c),i=Math.max(i,l),a[s]=Array(c);for(let t=0;t<a[s].length;t+=1)a[s][t]=255&e.getBuffer()[t+n];n+=c;let u=F.getErrorCorrectPolynomial(l),d=L(a[s],u.getLength()-1).mod(u);o[s]=Array(u.getLength()-1);for(let e=0;e<o[s].length;e+=1){let t=e+d.getLength()-o[s].length;o[s][e]=t>=0?d.getAt(t):0}}let s=0;for(let e=0;e<t.length;e+=1)s+=t[e].totalCount;let c=Array(s),l=0;for(let e=0;e<r;e+=1)for(let n=0;n<t.length;n+=1)e<a[n].length&&(c[l]=a[n][e],l+=1);for(let e=0;e<i;e+=1)for(let n=0;n<t.length;n+=1)e<o[n].length&&(c[l]=o[n][e],l+=1);return c},v=function(e,t,n){let r=R.getRSBlocks(e,t),i=z();for(let t=0;t<n.length;t+=1){let r=n[t];i.put(r.getMode(),4),i.put(r.getLength(),F.getLengthInBits(r.getMode(),e)),r.write(i)}let a=0;for(let e=0;e<r.length;e+=1)a+=r[e].dataCount;if(i.getLengthInBits()>a*8)throw`code length overflow. (`+i.getLengthInBits()+`>`+a*8+`)`;for(i.getLengthInBits()+4<=a*8&&i.put(0,4);i.getLengthInBits()%8!=0;)i.putBit(!1);for(;!(i.getLengthInBits()>=a*8||(i.put(236,8),i.getLengthInBits()>=a*8));)i.put(17,8);return _(i,r)};c.addData=function(e,t){t||=`Byte`;let n=null;switch(t){case`Numeric`:n=B(e);break;case`Alphanumeric`:n=V(e);break;case`Byte`:n=H(e);break;case`Kanji`:n=U(e);break;default:throw`mode:`+t}s.push(n),o=null},c.isDark=function(e,t){if(e<0||a<=e||t<0||a<=t)throw e+`,`+t;return i[e][t]},c.getModuleCount=function(){return a},c.make=function(){if(n<1){let e=1;for(;e<40;e++){let t=R.getRSBlocks(e,r),n=z();for(let t=0;t<s.length;t++){let r=s[t];n.put(r.getMode(),4),n.put(r.getLength(),F.getLengthInBits(r.getMode(),e)),r.write(n)}let i=0;for(let e=0;e<t.length;e++)i+=t[e].dataCount;if(n.getLengthInBits()<=i*8)break}n=e}l(!1,d())},c.createTableTag=function(e,t){e||=2,t=t===void 0?e*4:t;let n=``;n+=`<table style="`,n+=` border-width: 0px; border-style: none;`,n+=` border-collapse: collapse;`,n+=` padding: 0px; margin: `+t+`px;`,n+=`">`,n+=`<tbody>`;for(let t=0;t<c.getModuleCount();t+=1){n+=`<tr>`;for(let r=0;r<c.getModuleCount();r+=1)n+=`<td style="`,n+=` border-width: 0px; border-style: none;`,n+=` border-collapse: collapse;`,n+=` padding: 0px; margin: 0px;`,n+=` width: `+e+`px;`,n+=` height: `+e+`px;`,n+=` background-color: `,n+=c.isDark(t,r)?`#000000`:`#ffffff`,n+=`;`,n+=`"/>`;n+=`</tr>`}return n+=`</tbody>`,n+=`</table>`,n},c.createSvgTag=function(e,t,n,r){let i={};typeof arguments[0]==`object`&&(i=arguments[0],e=i.cellSize,t=i.margin,n=i.alt,r=i.title),e||=2,t=t===void 0?e*4:t,n=typeof n==`string`?{text:n}:n||{},n.text=n.text||null,n.id=n.text?n.id||`qrcode-description`:null,r=typeof r==`string`?{text:r}:r||{},r.text=r.text||null,r.id=r.text?r.id||`qrcode-title`:null;let a=c.getModuleCount()*e+t*2,o,s,l,u,d=``,f;for(f=`l`+e+`,0 0,`+e+` -`+e+`,0 0,-`+e+`z `,d+=`<svg version="1.1" xmlns="http://www.w3.org/2000/svg"`,d+=i.scalable?``:` width="`+a+`px" height="`+a+`px"`,d+=` viewBox="0 0 `+a+` `+a+`" `,d+=` preserveAspectRatio="xMinYMin meet"`,d+=r.text||n.text?` role="img" aria-labelledby="`+y([r.id,n.id].join(` `).trim())+`"`:``,d+=`>`,d+=r.text?`<title id="`+y(r.id)+`">`+y(r.text)+`</title>`:``,d+=n.text?`<description id="`+y(n.id)+`">`+y(n.text)+`</description>`:``,d+=`<rect width="100%" height="100%" fill="white" cx="0" cy="0"/>`,d+=`<path d="`,l=0;l<c.getModuleCount();l+=1)for(u=l*e+t,o=0;o<c.getModuleCount();o+=1)c.isDark(l,o)&&(s=o*e+t,d+=`M`+s+`,`+u+f);return d+=`" stroke="transparent" fill="black"/>`,d+=`</svg>`,d},c.createDataURL=function(e,t){e||=2,t=t===void 0?e*4:t;let n=c.getModuleCount()*e+t*2,r=t,i=n-t;return J(n,n,function(t,n){if(r<=t&&t<i&&r<=n&&n<i){let i=Math.floor((t-r)/e),a=Math.floor((n-r)/e);return+!c.isDark(a,i)}return 1})},c.createImgTag=function(e,t,n){e||=2,t=t===void 0?e*4:t;let r=c.getModuleCount()*e+t*2,i=``;return i+=`<img`,i+=` src="`,i+=c.createDataURL(e,t),i+=`"`,i+=` width="`,i+=r,i+=`"`,i+=` height="`,i+=r,i+=`"`,n&&(i+=` alt="`,i+=y(n),i+=`"`),i+=`/>`,i};let y=function(e){let t=``;for(let n=0;n<e.length;n+=1){let r=e.charAt(n);switch(r){case`<`:t+=`<`;break;case`>`:t+=`>`;break;case`&`:t+=`&`;break;case`"`:t+=`"`;break;default:t+=r}}return t},b=function(e){e=e===void 0?2:e;let t=c.getModuleCount()*1+e*2,n=e,r=t-e,i,a,o,s,l,u={"██":`█`,"█ ":`▀`," █":`▄`," ":` `},d={"██":`▀`,"█ ":`▀`," █":` `," ":` `},f=``;for(i=0;i<t;i+=2){for(o=Math.floor((i-n)/1),s=Math.floor((i+1-n)/1),a=0;a<t;a+=1)l=`█`,n<=a&&a<r&&n<=i&&i<r&&c.isDark(o,Math.floor((a-n)/1))&&(l=` `),n<=a&&a<r&&n<=i+1&&i+1<r&&c.isDark(s,Math.floor((a-n)/1))?l+=` `:l+=`█`,f+=e<1&&i+1>=r?d[l]:u[l];f+=`
|
|
2
2
|
`}return t%2&&e>0?f.substring(0,f.length-t-1)+Array(t+1).join(`▀`):f.substring(0,f.length-1)};return c.createASCII=function(e,t){if(e||=1,e<2)return b(t);--e,t=t===void 0?e*2:t;let n=c.getModuleCount()*e+t*2,r=t,i=n-t,a,o,s,l,u=Array(e+1).join(`██`),d=Array(e+1).join(` `),f=``,p=``;for(a=0;a<n;a+=1){for(s=Math.floor((a-r)/e),p=``,o=0;o<n;o+=1)l=1,r<=o&&o<i&&r<=a&&a<i&&c.isDark(s,Math.floor((o-r)/e))&&(l=0),p+=l?u:d;for(s=0;s<e;s+=1)f+=p+`
|
|
3
3
|
`}return f.substring(0,f.length-1)},c.renderTo2dContext=function(e,t){t||=2;let n=c.getModuleCount();for(let r=0;r<n;r++)for(let i=0;i<n;i++)e.fillStyle=c.isDark(r,i)?`black`:`white`,e.fillRect(i*t,r*t,t,t)},c};j.stringToBytes=function(e){let t=[];for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);t.push(r&255)}return t},j.createStringToBytes=function(e,t){let n=function(){let n=K(e),r=function(){let e=n.read();if(e==-1)throw`eof`;return e},i=0,a={};for(;;){let e=n.read();if(e==-1)break;let t=r(),o=r(),s=r(),c=String.fromCharCode(e<<8|t);a[c]=o<<8|s,i+=1}if(i!=t)throw i+` != `+t;return a}();return function(e){let t=[];for(let r=0;r<e.length;r+=1){let i=e.charCodeAt(r);if(i<128)t.push(i);else{let i=n[e.charAt(r)];typeof i==`number`?(i&255)==i?t.push(i):(t.push(i>>>8),t.push(i&255)):t.push(63)}}return t}};var M={MODE_NUMBER:1,MODE_ALPHA_NUM:2,MODE_8BIT_BYTE:4,MODE_KANJI:8},N={L:1,M:0,Q:3,H:2},P={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7},F=function(){let e=[[],[6,18],[6,22],[6,26],[6,30],[6,34],[6,22,38],[6,24,42],[6,26,46],[6,28,50],[6,30,54],[6,32,58],[6,34,62],[6,26,46,66],[6,26,48,70],[6,26,50,74],[6,30,54,78],[6,30,56,82],[6,30,58,86],[6,34,62,90],[6,28,50,72,94],[6,26,50,74,98],[6,30,54,78,102],[6,28,54,80,106],[6,32,58,84,110],[6,30,58,86,114],[6,34,62,90,118],[6,26,50,74,98,122],[6,30,54,78,102,126],[6,26,52,78,104,130],[6,30,56,82,108,134],[6,34,60,86,112,138],[6,30,58,86,114,142],[6,34,62,90,118,146],[6,30,54,78,102,126,150],[6,24,50,76,102,128,154],[6,28,54,80,106,132,158],[6,32,58,84,110,136,162],[6,26,54,82,110,138,166],[6,30,58,86,114,142,170]],t=1335,n=7973,r={},i=function(e){let t=0;for(;e!=0;)t+=1,e>>>=1;return t};return r.getBCHTypeInfo=function(e){let n=e<<10;for(;i(n)-i(t)>=0;)n^=t<<i(n)-i(t);return(e<<10|n)^21522},r.getBCHTypeNumber=function(e){let t=e<<12;for(;i(t)-i(n)>=0;)t^=n<<i(t)-i(n);return e<<12|t},r.getPatternPosition=function(t){return e[t-1]},r.getMaskFunction=function(e){switch(e){case P.PATTERN000:return function(e,t){return(e+t)%2==0};case P.PATTERN001:return function(e,t){return e%2==0};case P.PATTERN010:return function(e,t){return t%3==0};case P.PATTERN011:return function(e,t){return(e+t)%3==0};case P.PATTERN100:return function(e,t){return(Math.floor(e/2)+Math.floor(t/3))%2==0};case P.PATTERN101:return function(e,t){return e*t%2+e*t%3==0};case P.PATTERN110:return function(e,t){return(e*t%2+e*t%3)%2==0};case P.PATTERN111:return function(e,t){return(e*t%3+(e+t)%2)%2==0};default:throw`bad maskPattern:`+e}},r.getErrorCorrectPolynomial=function(e){let t=L([1],0);for(let n=0;n<e;n+=1)t=t.multiply(L([1,I.gexp(n)],0));return t},r.getLengthInBits=function(e,t){if(1<=t&&t<10)switch(e){case M.MODE_NUMBER:return 10;case M.MODE_ALPHA_NUM:return 9;case M.MODE_8BIT_BYTE:return 8;case M.MODE_KANJI:return 8;default:throw`mode:`+e}else if(t<27)switch(e){case M.MODE_NUMBER:return 12;case M.MODE_ALPHA_NUM:return 11;case M.MODE_8BIT_BYTE:return 16;case M.MODE_KANJI:return 10;default:throw`mode:`+e}else if(t<41)switch(e){case M.MODE_NUMBER:return 14;case M.MODE_ALPHA_NUM:return 13;case M.MODE_8BIT_BYTE:return 16;case M.MODE_KANJI:return 12;default:throw`mode:`+e}else throw`type:`+t},r.getLostPoint=function(e){let t=e.getModuleCount(),n=0;for(let r=0;r<t;r+=1)for(let i=0;i<t;i+=1){let a=0,o=e.isDark(r,i);for(let n=-1;n<=1;n+=1)if(!(r+n<0||t<=r+n))for(let s=-1;s<=1;s+=1)i+s<0||t<=i+s||(n!=0||s!=0)&&o==e.isDark(r+n,i+s)&&(a+=1);a>5&&(n+=3+a-5)}for(let r=0;r<t-1;r+=1)for(let i=0;i<t-1;i+=1){let t=0;e.isDark(r,i)&&(t+=1),e.isDark(r+1,i)&&(t+=1),e.isDark(r,i+1)&&(t+=1),e.isDark(r+1,i+1)&&(t+=1),(t==0||t==4)&&(n+=3)}for(let r=0;r<t;r+=1)for(let i=0;i<t-6;i+=1)e.isDark(r,i)&&!e.isDark(r,i+1)&&e.isDark(r,i+2)&&e.isDark(r,i+3)&&e.isDark(r,i+4)&&!e.isDark(r,i+5)&&e.isDark(r,i+6)&&(n+=40);for(let r=0;r<t;r+=1)for(let i=0;i<t-6;i+=1)e.isDark(i,r)&&!e.isDark(i+1,r)&&e.isDark(i+2,r)&&e.isDark(i+3,r)&&e.isDark(i+4,r)&&!e.isDark(i+5,r)&&e.isDark(i+6,r)&&(n+=40);let r=0;for(let n=0;n<t;n+=1)for(let i=0;i<t;i+=1)e.isDark(i,n)&&(r+=1);let i=Math.abs(100*r/t/t-50)/5;return n+=i*10,n},r}(),I=function(){let e=Array(256),t=Array(256);for(let t=0;t<8;t+=1)e[t]=1<<t;for(let t=8;t<256;t+=1)e[t]=e[t-4]^e[t-5]^e[t-6]^e[t-8];for(let n=0;n<255;n+=1)t[e[n]]=n;let n={};return n.glog=function(e){if(e<1)throw`glog(`+e+`)`;return t[e]},n.gexp=function(t){for(;t<0;)t+=255;for(;t>=256;)t-=255;return e[t]},n}(),L=function(e,t){if(e.length===void 0)throw e.length+`/`+t;let n=function(){let n=0;for(;n<e.length&&e[n]==0;)n+=1;let r=Array(e.length-n+t);for(let t=0;t<e.length-n;t+=1)r[t]=e[t+n];return r}(),r={};return r.getAt=function(e){return n[e]},r.getLength=function(){return n.length},r.multiply=function(e){let t=Array(r.getLength()+e.getLength()-1);for(let n=0;n<r.getLength();n+=1)for(let i=0;i<e.getLength();i+=1)t[n+i]^=I.gexp(I.glog(r.getAt(n))+I.glog(e.getAt(i)));return L(t,0)},r.mod=function(e){if(r.getLength()-e.getLength()<0)return r;let t=I.glog(r.getAt(0))-I.glog(e.getAt(0)),n=Array(r.getLength());for(let e=0;e<r.getLength();e+=1)n[e]=r.getAt(e);for(let r=0;r<e.getLength();r+=1)n[r]^=I.gexp(I.glog(e.getAt(r))+t);return L(n,0).mod(e)},r},R=function(){let e=[[1,26,19],[1,26,16],[1,26,13],[1,26,9],[1,44,34],[1,44,28],[1,44,22],[1,44,16],[1,70,55],[1,70,44],[2,35,17],[2,35,13],[1,100,80],[2,50,32],[2,50,24],[4,25,9],[1,134,108],[2,67,43],[2,33,15,2,34,16],[2,33,11,2,34,12],[2,86,68],[4,43,27],[4,43,19],[4,43,15],[2,98,78],[4,49,31],[2,32,14,4,33,15],[4,39,13,1,40,14],[2,121,97],[2,60,38,2,61,39],[4,40,18,2,41,19],[4,40,14,2,41,15],[2,146,116],[3,58,36,2,59,37],[4,36,16,4,37,17],[4,36,12,4,37,13],[2,86,68,2,87,69],[4,69,43,1,70,44],[6,43,19,2,44,20],[6,43,15,2,44,16],[4,101,81],[1,80,50,4,81,51],[4,50,22,4,51,23],[3,36,12,8,37,13],[2,116,92,2,117,93],[6,58,36,2,59,37],[4,46,20,6,47,21],[7,42,14,4,43,15],[4,133,107],[8,59,37,1,60,38],[8,44,20,4,45,21],[12,33,11,4,34,12],[3,145,115,1,146,116],[4,64,40,5,65,41],[11,36,16,5,37,17],[11,36,12,5,37,13],[5,109,87,1,110,88],[5,65,41,5,66,42],[5,54,24,7,55,25],[11,36,12,7,37,13],[5,122,98,1,123,99],[7,73,45,3,74,46],[15,43,19,2,44,20],[3,45,15,13,46,16],[1,135,107,5,136,108],[10,74,46,1,75,47],[1,50,22,15,51,23],[2,42,14,17,43,15],[5,150,120,1,151,121],[9,69,43,4,70,44],[17,50,22,1,51,23],[2,42,14,19,43,15],[3,141,113,4,142,114],[3,70,44,11,71,45],[17,47,21,4,48,22],[9,39,13,16,40,14],[3,135,107,5,136,108],[3,67,41,13,68,42],[15,54,24,5,55,25],[15,43,15,10,44,16],[4,144,116,4,145,117],[17,68,42],[17,50,22,6,51,23],[19,46,16,6,47,17],[2,139,111,7,140,112],[17,74,46],[7,54,24,16,55,25],[34,37,13],[4,151,121,5,152,122],[4,75,47,14,76,48],[11,54,24,14,55,25],[16,45,15,14,46,16],[6,147,117,4,148,118],[6,73,45,14,74,46],[11,54,24,16,55,25],[30,46,16,2,47,17],[8,132,106,4,133,107],[8,75,47,13,76,48],[7,54,24,22,55,25],[22,45,15,13,46,16],[10,142,114,2,143,115],[19,74,46,4,75,47],[28,50,22,6,51,23],[33,46,16,4,47,17],[8,152,122,4,153,123],[22,73,45,3,74,46],[8,53,23,26,54,24],[12,45,15,28,46,16],[3,147,117,10,148,118],[3,73,45,23,74,46],[4,54,24,31,55,25],[11,45,15,31,46,16],[7,146,116,7,147,117],[21,73,45,7,74,46],[1,53,23,37,54,24],[19,45,15,26,46,16],[5,145,115,10,146,116],[19,75,47,10,76,48],[15,54,24,25,55,25],[23,45,15,25,46,16],[13,145,115,3,146,116],[2,74,46,29,75,47],[42,54,24,1,55,25],[23,45,15,28,46,16],[17,145,115],[10,74,46,23,75,47],[10,54,24,35,55,25],[19,45,15,35,46,16],[17,145,115,1,146,116],[14,74,46,21,75,47],[29,54,24,19,55,25],[11,45,15,46,46,16],[13,145,115,6,146,116],[14,74,46,23,75,47],[44,54,24,7,55,25],[59,46,16,1,47,17],[12,151,121,7,152,122],[12,75,47,26,76,48],[39,54,24,14,55,25],[22,45,15,41,46,16],[6,151,121,14,152,122],[6,75,47,34,76,48],[46,54,24,10,55,25],[2,45,15,64,46,16],[17,152,122,4,153,123],[29,74,46,14,75,47],[49,54,24,10,55,25],[24,45,15,46,46,16],[4,152,122,18,153,123],[13,74,46,32,75,47],[48,54,24,14,55,25],[42,45,15,32,46,16],[20,147,117,4,148,118],[40,75,47,7,76,48],[43,54,24,22,55,25],[10,45,15,67,46,16],[19,148,118,6,149,119],[18,75,47,31,76,48],[34,54,24,34,55,25],[20,45,15,61,46,16]],t=function(e,t){let n={};return n.totalCount=e,n.dataCount=t,n},n={},r=function(t,n){switch(n){case N.L:return e[(t-1)*4+0];case N.M:return e[(t-1)*4+1];case N.Q:return e[(t-1)*4+2];case N.H:return e[(t-1)*4+3];default:return}};return n.getRSBlocks=function(e,n){let i=r(e,n);if(i===void 0)throw`bad rs block @ typeNumber:`+e+`/errorCorrectionLevel:`+n;let a=i.length/3,o=[];for(let e=0;e<a;e+=1){let n=i[e*3+0],r=i[e*3+1],a=i[e*3+2];for(let e=0;e<n;e+=1)o.push(t(r,a))}return o},n}(),z=function(){let e=[],t=0,n={};return n.getBuffer=function(){return e},n.getAt=function(t){let n=Math.floor(t/8);return(e[n]>>>7-t%8&1)==1},n.put=function(e,t){for(let r=0;r<t;r+=1)n.putBit((e>>>t-r-1&1)==1)},n.getLengthInBits=function(){return t},n.putBit=function(n){let r=Math.floor(t/8);e.length<=r&&e.push(0),n&&(e[r]|=128>>>t%8),t+=1},n},B=function(e){let t=M.MODE_NUMBER,n=e,r={};r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){let t=n,r=0;for(;r+2<t.length;)e.put(i(t.substring(r,r+3)),10),r+=3;r<t.length&&(t.length-r==1?e.put(i(t.substring(r,r+1)),4):t.length-r==2&&e.put(i(t.substring(r,r+2)),7))};let i=function(e){let t=0;for(let n=0;n<e.length;n+=1)t=t*10+a(e.charAt(n));return t},a=function(e){if(`0`<=e&&e<=`9`)return e.charCodeAt(0)-48;throw`illegal char :`+e};return r},V=function(e){let t=M.MODE_ALPHA_NUM,n=e,r={};r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){let t=n,r=0;for(;r+1<t.length;)e.put(i(t.charAt(r))*45+i(t.charAt(r+1)),11),r+=2;r<t.length&&e.put(i(t.charAt(r)),6)};let i=function(e){if(`0`<=e&&e<=`9`)return e.charCodeAt(0)-48;if(`A`<=e&&e<=`Z`)return e.charCodeAt(0)-65+10;switch(e){case` `:return 36;case`$`:return 37;case`%`:return 38;case`*`:return 39;case`+`:return 40;case`-`:return 41;case`.`:return 42;case`/`:return 43;case`:`:return 44;default:throw`illegal char :`+e}};return r},H=function(e){let t=M.MODE_8BIT_BYTE,n=j.stringToBytes(e),r={};return r.getMode=function(){return t},r.getLength=function(e){return n.length},r.write=function(e){for(let t=0;t<n.length;t+=1)e.put(n[t],8)},r},U=function(e){let t=M.MODE_KANJI,n=j.stringToBytes;(function(e,t){let r=n(e);if(r.length!=2||(r[0]<<8|r[1])!=t)throw`sjis not supported.`})(`友`,38726);let r=n(e),i={};return i.getMode=function(){return t},i.getLength=function(e){return~~(r.length/2)},i.write=function(e){let t=r,n=0;for(;n+1<t.length;){let r=(255&t[n])<<8|255&t[n+1];if(33088<=r&&r<=40956)r-=33088;else if(57408<=r&&r<=60351)r-=49472;else throw`illegal char at `+(n+1)+`/`+r;r=(r>>>8&255)*192+(r&255),e.put(r,13),n+=2}if(n<t.length)throw`illegal char at `+(n+1)},i},W=function(){let e=[],t={};return t.writeByte=function(t){e.push(t&255)},t.writeShort=function(e){t.writeByte(e),t.writeByte(e>>>8)},t.writeBytes=function(e,n,r){n||=0,r||=e.length;for(let i=0;i<r;i+=1)t.writeByte(e[i+n])},t.writeString=function(e){for(let n=0;n<e.length;n+=1)t.writeByte(e.charCodeAt(n))},t.toByteArray=function(){return e},t.toString=function(){let t=``;t+=`[`;for(let n=0;n<e.length;n+=1)n>0&&(t+=`,`),t+=e[n];return t+=`]`,t},t},G=function(){let e=0,t=0,n=0,r=``,i={},a=function(e){r+=String.fromCharCode(o(e&63))},o=function(e){if(e<0)throw`n:`+e;if(e<26)return 65+e;if(e<52)return 97+(e-26);if(e<62)return 48+(e-52);if(e==62)return 43;if(e==63)return 47;throw`n:`+e};return i.writeByte=function(r){for(e=e<<8|r&255,t+=8,n+=1;t>=6;)a(e>>>t-6),t-=6},i.flush=function(){if(t>0&&(a(e<<6-t),e=0,t=0),n%3!=0){let e=3-n%3;for(let t=0;t<e;t+=1)r+=`=`}},i.toString=function(){return r},i},K=function(e){let t=e,n=0,r=0,i=0,a={};a.read=function(){for(;i<8;){if(n>=t.length){if(i==0)return-1;throw`unexpected end of file./`+i}let e=t.charAt(n);if(n+=1,e==`=`)return i=0,-1;e.match(/^\s$/)||(r=r<<6|o(e.charCodeAt(0)),i+=6)}let e=r>>>i-8&255;return i-=8,e};let o=function(e){if(65<=e&&e<=90)return e-65;if(97<=e&&e<=122)return e-97+26;if(48<=e&&e<=57)return e-48+52;if(e==43)return 62;if(e==47)return 63;throw`c:`+e};return a},q=function(e,t){let n=e,r=t,i=Array(e*t),a={};a.setPixel=function(e,t,r){i[t*n+e]=r},a.write=function(e){e.writeString(`GIF87a`),e.writeShort(n),e.writeShort(r),e.writeByte(128),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(0),e.writeByte(255),e.writeByte(255),e.writeByte(255),e.writeString(`,`),e.writeShort(0),e.writeShort(0),e.writeShort(n),e.writeShort(r),e.writeByte(0);let t=s(2);e.writeByte(2);let i=0;for(;t.length-i>255;)e.writeByte(255),e.writeBytes(t,i,255),i+=255;e.writeByte(t.length-i),e.writeBytes(t,i,t.length-i),e.writeByte(0),e.writeString(`;`)};let o=function(e){let t=e,n=0,r=0,i={};return i.write=function(e,i){if(e>>>i)throw`length over`;for(;n+i>=8;)t.writeByte(255&(e<<n|r)),i-=8-n,e>>>=8-n,r=0,n=0;r=e<<n|r,n+=i},i.flush=function(){n>0&&t.writeByte(r)},i},s=function(e){let t=1<<e,n=(1<<e)+1,r=e+1,a=c();for(let e=0;e<t;e+=1)a.add(String.fromCharCode(e));a.add(String.fromCharCode(t)),a.add(String.fromCharCode(n));let s=W(),l=o(s);l.write(t,r);let u=0,d=String.fromCharCode(i[u]);for(u+=1;u<i.length;){let e=String.fromCharCode(i[u]);u+=1,a.contains(d+e)?d+=e:(l.write(a.indexOf(d),r),a.size()<4095&&(a.size()==1<<r&&(r+=1),a.add(d+e)),d=e)}return l.write(a.indexOf(d),r),l.write(n,r),l.flush(),s.toByteArray()},c=function(){let e={},t=0,n={};return n.add=function(r){if(n.contains(r))throw`dup key:`+r;e[r]=t,t+=1},n.size=function(){return t},n.indexOf=function(t){return e[t]},n.contains=function(t){return e[t]!==void 0},n};return a},J=function(e,t,n){let r=q(e,t);for(let i=0;i<t;i+=1)for(let t=0;t<e;t+=1)r.setPixel(t,i,n(t,i));let i=W();r.write(i);let a=G(),o=i.toByteArray();for(let e=0;e<o.length;e+=1)a.writeByte(o[e]);return a.flush(),`data:image/gif;base64,`+a};j.stringToBytes;function Y(){return Y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},Y.apply(null,arguments)}function X(e,t){if(e==null)return{};var n,r,i=ce(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(r=0;r<a.length;r++)n=a[r],t.indexOf(n)===-1&&{}.propertyIsEnumerable.call(e,n)&&(i[n]=e[n])}return i}function ce(e,t){if(e==null)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)!==-1)continue;n[r]=e[r]}return n}var le=[`bgColor`,`bgD`,`fgD`,`fgColor`,`size`,`title`,`viewBoxSize`,`xmlns`],ue={bgColor:A.default.oneOfType([A.default.object,A.default.string]).isRequired,bgD:A.default.string.isRequired,fgColor:A.default.oneOfType([A.default.object,A.default.string]).isRequired,fgD:A.default.string.isRequired,size:A.default.number.isRequired,title:A.default.string,viewBoxSize:A.default.number.isRequired,xmlns:A.default.string},Z=(0,k.forwardRef)(function(e,t){var n=e.bgColor,r=e.bgD,i=e.fgD,a=e.fgColor,o=e.size,s=e.title,c=e.viewBoxSize,l=e.xmlns,u=l===void 0?`http://www.w3.org/2000/svg`:l,d=X(e,le);return k.createElement(`svg`,Y({},d,{height:o,ref:t,viewBox:`0 0 ${c} ${c}`,width:o,xmlns:u}),s?k.createElement(`title`,null,s):null,k.createElement(`path`,{d:r,fill:n}),k.createElement(`path`,{d:i,fill:a}))});Z.displayName=`QRCodeSvg`,Z.propTypes=ue;var de=[`bgColor`,`fgColor`,`level`,`size`,`value`];j.stringToBytes=function(e){return Array.from(new TextEncoder().encode(e))};var fe={bgColor:A.default.oneOfType([A.default.object,A.default.string]),fgColor:A.default.oneOfType([A.default.object,A.default.string]),level:A.default.string,size:A.default.number,value:A.default.string.isRequired},Q=(0,k.forwardRef)(function(e,t){var n=e.bgColor,r=n===void 0?`#FFFFFF`:n,i=e.fgColor,a=i===void 0?`#000000`:i,o=e.level,s=o===void 0?`L`:o,c=e.size,l=c===void 0?256:c,u=e.value,d=X(e,de),f=j(0,s);f.addData(u),f.make();var p=f.getModuleCount(),m=Array.from({length:p},function(e,t){return Array.from({length:p},function(e,n){return f.isDark(t,n)})});return k.createElement(Z,Y({},d,{bgColor:r,bgD:m.map(function(e,t){return e.map(function(e,n){return e?``:`M ${n} ${t} l 1 0 0 1 -1 0 Z`}).join(` `)}).join(` `),fgColor:a,fgD:m.map(function(e,t){return e.map(function(e,n){return e?`M ${n} ${t} l 1 0 0 1 -1 0 Z`:``}).join(` `)}).join(` `),ref:t,size:l,viewBoxSize:p}))});Q.displayName=`QRCode`,Q.propTypes=fe;var $=o(),pe=e=>({mode:e,ready:!1,accessUrl:null,reasons:[`远程服务未就绪`]});function me(){let{snap:t}=h(),{busy:i,run:o}=x(),c=[...t.instances?.native?[t.instances.native]:[],...t.instances?.instances??[]],l=t.lan?.items??[],E=t.frp,[D,O]=(0,k.useState)(``),[A,j]=(0,k.useState)(`7000`),[M,N]=(0,k.useState)(``),[P,F]=(0,k.useState)(!1),[I,L]=(0,k.useState)(null),[R,z]=(0,k.useState)(``),[B,V]=(0,k.useState)(!1),H=e();(0,k.useEffect)(()=>{!E||P||(O(E.settings.serverAddr||``),j(String(E.settings.serverPort||7e3)),F(!0))},[E,P]);function U(){let e={serverAddr:D,serverPort:parseInt(A,10)||7e3},t=M.trim();return t&&(e.authToken=t),e}async function W(e,t,n){let r=!1,i=await o(e.id,()=>d.remoteSetMode(e.id,t).then(e=>(r=e?.tokenAutoAllocated===!0,e)),{success:n});return i&&r&&a.info(`已自动生成访问令牌,点钥匙按钮可查看或修改`),i}async function G(e){await H({title:`开启远程控制?`,description:`「`+(e.name||e.id)+`」将开启局域网反向代理,同网段设备可访问该实例(无访问令牌时自动生成一个,可在钥匙按钮处查看)。`,confirmText:`开启远程控制`})&&await W(e,`lan`,`已开启远程控制(局域网)`)}async function K(e){await H({title:`切换到公网访问?`,description:`「`+(e.name||e.id)+`」的访问端口将映射到公网(frps),互联网上任何人都可尝试触达(访问令牌是硬性前置,缺失时自动生成)。`,confirmText:`切换到公网`})&&await W(e,`wan`,`已切换到公网访问`)}function q(e,t){z(t??``),V(!1),L({id:e.id,name:e.name,current:t})}async function J(){let e=I;if(!e)return;let t=R.trim();if(!t){a.error(`令牌不能为空`);return}if(t.length<8){a.error(`远程访问令牌至少 8 位(公网暴露可被暴力枚举)`);return}L(null),(e.current===null||e.current!==t)&&await o(e.id,()=>d.remoteSetToken(e.id,t),{success:`访问令牌已设置`})}async function Y(){await o(`frp-save`,()=>d.remoteFrpServer(U()),{success:`已保存 FRP 配置`})}return(0,$.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,$.jsxs)(`div`,{className:`grid items-start gap-4 @min-[900px]:grid-cols-[minmax(0,1fr)_420px]`,children:[(0,$.jsxs)(T,{children:[(0,$.jsx)(S,{title:`远程控制`,subtitle:`为本地 DSH 实例开启远程访问:局域网直连或经 FRP 公网(需实例运行中)`}),(0,$.jsx)(`div`,{className:`grid`,children:c.length?c.map(e=>{let t=e.state?.running??!1,a=l.find(t=>t.dshPort===e.port),o=e.remoteMode??`off`,s=o===`off`?null:a?.remote??pe(o),c=s?.accessUrl??null,u=typeof e.remoteToken==`string`&&e.remoteToken.trim()?e.remoteToken.trim():null,d=s?.ready&&c?u?c+`?token=`+encodeURIComponent(u):c:null,f=u!==null||!!a?.tokenSet,p=o===`off`?(0,$.jsx)(C,{tone:`off`,children:`远程关闭`}):s?.ready?(0,$.jsx)(C,{tone:o===`wan`?`boot`:`ok`,children:o===`wan`?`公网就绪`:`局域网就绪`}):(0,$.jsx)(`span`,{title:(s?.reasons??[]).join(`;`),children:(0,$.jsx)(C,{tone:`off`,children:`远程停止`})});return(0,$.jsxs)(`div`,{className:`grid grid-cols-[auto_minmax(0,1fr)_auto] items-stretch gap-4 border-b border-border/60 px-5 py-4 last:border-b-0`,children:[d?(0,$.jsx)(`div`,{className:`flex shrink-0 items-center rounded-lg border border-border bg-white p-1.5`,title:u?`扫码访问该实例远程地址(已带访问令牌,一次出示后凭 Cookie)`:`扫码访问该实例远程地址`,children:(0,$.jsx)(Q,{value:d,size:88})}):(0,$.jsx)(`div`,{className:`grid size-[96px] shrink-0 place-items-center rounded-lg border border-dashed border-border/70 text-center text-[11px] leading-tight text-muted-foreground/60`,children:t?o===`off`?`开启远程后生成二维码`:`远程就绪后生成二维码`:`启动后可用`}),(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-col`,children:[(0,$.jsxs)(`div`,{className:`pt-2.5 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(w,{domain:e.domain}),(0,$.jsx)(`strong`,{className:`truncate text-sm font-semibold text-foreground`,children:e.name}),p]}),(0,$.jsxs)(`div`,{className:`mt-auto grid content-end gap-1.5 pb-1`,children:[(0,$.jsxs)(`div`,{className:`text-xs text-muted-foreground`,children:[`端口 `,e.port,o!==`off`&&a?.wanPort?` · 访问端口 `+a.wanPort+(o===`wan`?`(公网同号)`:``):``]}),c?(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void ee(()=>y(c)),className:`inline-flex max-w-full items-center gap-1 truncate text-xs text-primary hover:underline`,title:u?`令牌绝不进浏览器启动参数,故直接打开需自行附加 ?token=;扫码可直达`:`在系统浏览器中打开该地址`,children:[(0,$.jsx)(b,{className:`size-3 shrink-0`}),c]}):!t||o===`off`?(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground/70`,children:t?`远程未开启`:`实例未运行,启动后可开启远程`}):null,s&&!s.ready?(0,$.jsx)(`div`,{className:`text-xs text-muted-foreground/70`,children:(s.reasons??[]).slice(0,2).join(`;`)||`等待代理分配访问地址…`}):null]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col items-end justify-center gap-2`,children:[(0,$.jsxs)(`div`,{className:r(`flex items-center gap-2`,!t&&`pointer-events-none opacity-50`),children:[(0,$.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`远程控制`}),(0,$.jsx)(m,{checked:o!==`off`,disabled:!t||i===e.id,onCheckedChange:t=>{if(!t){W(e,`off`,`已关闭远程控制`);return}G(e)}})]}),o!==`off`&&(0,$.jsxs)(`div`,{className:r(`flex items-center gap-1`,(!t||i===e.id)&&`pointer-events-none opacity-50`),children:[(0,$.jsxs)(n,{className:`h-7 px-2 text-xs`,size:`chip`,variant:o===`lan`?`default`:`outline`,title:`局域网反向代理访问(同网段)`,onClick:()=>{o!==`lan`&&W(e,`lan`,`已切换到局域网访问`)},children:[(0,$.jsx)(ae,{className:`size-3.5`}),`局域网`]}),(0,$.jsxs)(n,{className:`h-7 px-2 text-xs`,size:`chip`,variant:o===`wan`?`default`:`outline`,title:E?.settings?.serverAddr?`经 FRP 暴露到公网(需访问令牌)`:`需先在右侧配置 frps 服务器地址`,onClick:()=>{o!==`wan`&&K(e)},children:[(0,$.jsx)(re,{className:`size-3.5`}),`公网`]})]}),(0,$.jsx)(n,{className:`h-7 px-1.5`,disabled:i===e.id,onClick:()=>void q(e,u),size:`chip`,title:f?`访问令牌已设置(点击查看或修改)`:`未设访问令牌:局域网侧同网段可直接访问,公网模式会被安全闸拒绝,点击设置`,variant:`outline`,children:(0,$.jsx)(ie,{className:r(`size-3.5`,f?`text-status-ok`:`text-amber-500`)})})]})]},e.id)}):(0,$.jsx)(`div`,{className:`px-5 py-8 text-center text-sm text-muted-foreground`,children:`暂无实例(在「实例管理」添加后将出现在这里)`})})]}),(0,$.jsxs)(T,{children:[(0,$.jsx)(S,{title:`公网访问(FRP 内网穿透)`,subtitle:`存在「公网」模式的实例时 frpc 自动常驻并建立隧道`,actions:(0,$.jsx)(C,{tone:E?.running?`ok`:E?.installed?`warn`:`off`,children:E?.running?`frpc 运行中`:E?.installed?`已安装 · 未运行`:`未安装`})}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,$.jsx)(p,{children:`frps 地址`}),(0,$.jsx)(u,{placeholder:`如 1.2.3.4`,value:D,onChange:e=>O(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,$.jsx)(p,{children:`frps 端口`}),(0,$.jsx)(u,{inputMode:`numeric`,placeholder:`7000`,value:A,onChange:e=>j(e.target.value)})]}),(0,$.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,$.jsx)(p,{children:`auth token`}),(0,$.jsx)(u,{type:`password`,autoComplete:`new-password`,placeholder:E?.settings?.authTokenSet?`已设置 · 留空不修改,输入即轮换`:`frps 的 auth.token`,value:M,onChange:e=>N(e.target.value)})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-5 pb-4`,children:[(0,$.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[E?.installed?``:`需安装 frpc`,(E?.instancesExposed?.length??0)>0?` · 公网实例 `+E?.instancesExposed?.length+` 个`:` · 无公网模式实例`]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsxs)(n,{disabled:i===`frp-inst`,onClick:()=>void o(`frp-inst`,()=>d.remoteFrpInstall(),{success:`frpc 安装完成`}),variant:`outline`,children:[(0,$.jsx)(se,{className:`size-4`}),`安装 frpc`]}),(0,$.jsxs)(n,{disabled:i===`frp-save`,onClick:()=>void Y(),children:[(0,$.jsx)(oe,{className:`size-4`}),`保存并应用`]})]})]}),E?.logTail?.length?(0,$.jsx)(`pre`,{className:`mx-5 mb-4 max-h-[160px] overflow-auto whitespace-pre-wrap break-all rounded-md bg-muted/70 p-3 font-mono text-xs leading-relaxed text-muted-foreground`,children:E.logTail.join(`
|
|
4
4
|
`)}):null]})]}),(0,$.jsx)(g,{open:!!I,onOpenChange:e=>!e&&L(null),children:(0,$.jsxs)(v,{className:`max-w-[420px]`,children:[(0,$.jsx)(_,{children:(0,$.jsxs)(s,{children:[`访问令牌`,I?.name?` · `+I.name:``]})}),(0,$.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`远程访问需携带此令牌:首次在地址后附加 `,(0,$.jsx)(`code`,{className:`break-all`,children:`?token=令牌`}),`(只需一次,之后凭会话 Cookie 访问)。`,I?.current==null?`令牌明文只在内核所在机器上下发,当前面板读不到现值——输入即设为新令牌。`:`公网模式硬性要求它;此处显示的是当前生效值,改成新值即轮换。`]}),(0,$.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,$.jsx)(u,{className:`flex-1`,type:B?`text`:`password`,autoComplete:`off`,placeholder:`输入访问令牌`,value:R,onChange:e=>z(e.target.value),onKeyDown:e=>{e.key===`Enter`&&J()}}),I?.current!=null&&(0,$.jsx)(n,{className:`h-9 px-2`,size:`chip`,variant:`outline`,title:B?`隐藏令牌`:`显示令牌`,onClick:()=>V(e=>!e),children:B?(0,$.jsx)(te,{className:`size-4`}):(0,$.jsx)(ne,{className:`size-4`})})]}),(0,$.jsxs)(f,{children:[(0,$.jsx)(n,{variant:`outline`,onClick:()=>L(null),children:`取消`}),(0,$.jsx)(n,{disabled:!R.trim()||i===I?.id,onClick:()=>void J(),children:`保存`})]})]})})]})}export{me as LanPage};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{F as e,I as t,L as n,N as r,O as i,R as a,S as o,U as s,V as c,a as l,b as u,k as d,t as f,v as ee,x as p,y as m}from"./supervisor-BbSavtNN.js";import{r as h,t as g}from"./openExternal-
|
|
1
|
+
import{F as e,I as t,L as n,N as r,O as i,R as a,S as o,U as s,V as c,a as l,b as u,k as d,t as f,v as ee,x as p,y as m}from"./supervisor-BbSavtNN.js";import{r as h,t as g}from"./openExternal-DOkxrLUq.js";import{n as _,t as v}from"./rocket-CLAmwatt.js";import{t as y}from"./refresh-cw-B-VAKpDt.js";import{t as te}from"./shield-check-CMRwmPpk.js";import{c as b,f as x,n as S,o as C,t as w}from"./supervisor-Btn_MIEc.js";import{t as T}from"./useSupervisorAction-q0YJmhui.js";import{c as E,i as D,n as O,o as k,t as A}from"./widgets-BbRkZm-Z.js";import{t as j}from"./format-QeaTKFhQ.js";var M=r(`arrow-up-right`,[[`path`,{d:`M7 7h10v10`,key:`1tivn9`}],[`path`,{d:`M7 17 17 7`,key:`1vkiza`}]]),N=r(`circle-dot`,[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}]]),P=r(`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`}]]),F=s(c(),1),I=a();function L(e,t){return e===`dsh-main`||e===`supervisor-api`?`boot`:(t||``).startsWith(`inst:`)?`ok`:e===`relay`?`warn`:e.startsWith(`managed:`)?`boot`:`off`}function R(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 z(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 B({providers:e=[]}){let{snap:t}=f(),r=t.ports?.records??null,i=(0,F.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,I.jsxs)(A,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,I.jsx)(O,{title:`运行状态`,subtitle:`核心服务与端口实时状态`,actions:i?(0,I.jsxs)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:[i.length,` 端口`]}):null}),i?(0,I.jsxs)(`div`,{className:`min-h-0 overflow-x-auto`,children:[(0,I.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,I.jsx)(`span`,{children:`端口`}),(0,I.jsx)(`span`,{children:`服务`}),(0,I.jsx)(`span`,{className:`text-right`,children:`归属`}),(0,I.jsx)(`span`,{className:`text-right`,children:`状态`})]}),(0,I.jsx)(`div`,{className:`max-h-[340px] overflow-y-auto overscroll-contain`,children:i.map((t,r)=>(0,I.jsxs)(`div`,{className:n(`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,I.jsx)(`code`,{className:`font-mono text-sm tabular-nums text-foreground`,children:t.port}),(0,I.jsx)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:(0,I.jsx)(`span`,{className:`truncate text-xs text-foreground`,children:R(t)})}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:(0,I.jsx)(k,{tone:L(t.role,t.owner),children:z(t,e)})}),(0,I.jsx)(`div`,{className:`flex justify-end`,children:t.active===!0?(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-status-ok`,children:[(0,I.jsx)(N,{className:`size-3`}),`运行中`]}):t.active===!1?(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-muted-foreground`,children:[(0,I.jsx)(N,{className:`size-3 opacity-50`}),`未运行`]}):(0,I.jsxs)(`span`,{className:`inline-flex items-center gap-1 whitespace-nowrap text-[11px] text-muted-foreground`,children:[(0,I.jsx)(N,{className:`size-3 opacity-40`}),`状态未知`]})})]},t.port+`-`+t.owner))})]}):(0,I.jsx)(`div`,{className:`px-5 py-6 text-center text-xs text-muted-foreground`,children:`运行状态加载中…`})]})}var V=new Set([`dist_registry_selected`,`gui_autostart_changed`,`autostart_changed`,`lan_panel_changed`,`lan_dsh_token_updated`]);function H(){let{snap:r}=f(),{busy:a,run:s}=T(),c=e(),[d,w]=(0,F.useState)(!1),[O,k]=(0,F.useState)(null),j=r.status,N=j?.native,L=N?.installed??!1,R=N?.state||(L?`installed`:`uninstalled`),z=R===`installing`,H=z||R===`uninstalling`,G=j?.version,K=j?.upgrade,q=S[j?.phase??``]??{label:j?.phase||`未知`,tone:`off`},J=!!j?.dshPid,Y=K?.state===`running`,X=(0,F.useMemo)(()=>r.events.filter(e=>!V.has(e.type)),[r.events]);async function Z(){await s(`dsh`,()=>J?l.lifecycleStop(`dsh`):l.lifecycleStart(`dsh`),{success:J?`正在停止 DSH…`:`正在启动 DSH…`})}async function ne(){await c({title:`停止 DSH?`,description:`主干 DeepSeek Harness 正在运行;停止会中断进行中的请求,远程访问同时不可用。`,confirmText:`停止 DSH`})&&await Z()}async function re(){await s(`web`,()=>g(()=>l.instanceOpenWeb(`main`)).then(()=>void 0))}async function Q(){await s(`chk`,async()=>{let e=await l.nativeCheckUpdate();if(e?.ok===!1){i.error(e.error||`检测失败`);return}e?.updateAvailable&&e.latest?i.success(`发现新版本 `+e.latest+(e.installed?`(当前 `+e.installed+`),可一键升级`:``)):i.success(`已是最新版本`+(e.installed?`(`+e.installed+`)`:``))})}async function ie(){w(!1),await s(`upg`,()=>l.nativeUpgrade(),{success:`升级已开始,请耐心等待…`})}async function ae(){await c({title:`在线安装最新版 DeepSeek Harness?`,description:`需数分钟,自动适配最快镜像源。`,confirmText:`安装`})&&await s(`inst`,()=>l.nativeInstall(),{success:`开始安装 DeepSeek Harness…`})}async function oe(){await c({title:`彻底卸载 DeepSeek Harness?`,description:`删除全部文件、数据、缓存与日志,不留残留。`,confirmText:`卸载 DSH`,tone:`destructive`})&&await s(`uni`,()=>l.nativeUninstall(),{success:`开始卸载…`})}(0,F.useEffect)(()=>{L&&l.instances().then(e=>{let t=e?.native?.guardian;typeof t==`boolean`&&k(t)}).catch(()=>{})},[L,j?.dshPid]);async function se(){let e=O!==!0;await s(`gu`,()=>l.nativeSettings({guardian:e}).then(e=>{let t=e?.main?.guardian;return typeof t==`boolean`&&k(t),e}),{success:e?`已开启 DSH 进程守护(崩溃自动拉起)`:`已关闭 DSH 进程守护(崩溃后不再自动拉起)`,refresh:!1})}let $=L&&(N?.version||G?.installed)||`—`;return(0,I.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,I.jsxs)(A,{children:[(0,I.jsxs)(`div`,{className:`grid grid-cols-1 @min-[720px]:grid-cols-[minmax(0,5fr)_minmax(0,6fr)]`,children:[(0,I.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,I.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,I.jsx)(`h3`,{className:`truncate text-xl font-semibold tracking-[-0.01em] text-foreground`,children:`DeepSeek Harness`}),(0,I.jsxs)(`span`,{className:`shrink-0 font-mono text-sm text-muted-foreground`,children:[`v`,$]})]}),a===`chk`?(0,I.jsxs)(t,{size:`chip`,disabled:!0,children:[(0,I.jsx)(y,{className:`size-3 animate-spin`}),`检测中…`]}):G?.updateAvailable&&G.latest?(0,I.jsxs)(t,{className:`text-primary-foreground`,size:`chip`,onClick:()=>w(!0),children:[(0,I.jsx)(M,{className:`size-3`}),`升级到 v`,G.latest]}):Y?(0,I.jsxs)(t,{size:`chip`,disabled:!0,children:[(0,I.jsx)(y,{className:`size-3 animate-spin`}),`升级中…`]}):(0,I.jsxs)(t,{className:`bg-primary/10 text-primary hover:bg-primary/15`,onClick:()=>void Q(),size:`chip`,variant:`ghost`,children:[(0,I.jsx)(y,{className:`size-3`}),`检测更新`]})]}),H?(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(E,{tone:`boot`,ping:!0}),(0,I.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:z?`正在安装 DeepSeek Harness…`:`正在卸载 DeepSeek Harness…`})]}):(0,I.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,I.jsx)(E,{tone:q.tone,ping:q.tone===`ok`}),(0,I.jsx)(`span`,{className:`text-base font-semibold leading-none text-foreground`,children:q.label})]}),Y&&K?(0,I.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`size-1.5 animate-pulse rounded-full bg-primary`}),`正在升级(`,K.step||K.targetVersion||``,`)…`]}):null,K?.state===`failed`?(0,I.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`升级失败:`,K.lastError||`未知原因`,K.rolledBack?`(已回滚)`:``]}):null,H&&(N?.installLog??[]).length?(0,I.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:(N?.installLog??[]).slice(-6).join(`
|
|
2
2
|
`)}):null]}),(0,I.jsx)(`div`,{className:`flex items-center bg-[image:var(--panel-accent-gradient)] px-6 py-5`,children:(0,I.jsxs)(`div`,{className:`grid w-full grid-cols-2 gap-x-6 gap-y-4 @min-[560px]:grid-cols-4`,children:[(0,I.jsx)(D,{icon:(0,I.jsx)(x,{className:`size-4`}),label:`端口`,value:j?.dshPort?String(j.dshPort):`—`,mono:!0}),(0,I.jsx)(D,{icon:(0,I.jsx)(P,{className:`size-4`}),label:`PID`,value:j?.dshPid?String(j.dshPid):`—`,mono:!0}),(0,I.jsx)(D,{icon:(0,I.jsx)(y,{className:`size-4`}),label:`重启次数`,value:String(j?.restartCount??0),mono:!0}),(0,I.jsx)(D,{icon:(0,I.jsx)(M,{className:`size-4`}),label:`最近故障`,value:j?.lastFailure?C(j?.lastFailure):`无`,warn:!!j?.lastFailure})]})})]}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-t border-border/60 px-6 py-3`,children:[(0,I.jsx)(`div`,{className:`hidden lg:block`,children:(0,I.jsx)(U,{})}),(0,I.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[!L&&!H?(0,I.jsxs)(t,{size:`sm`,disabled:a===`inst`,onClick:()=>void ae(),children:[(0,I.jsx)(v,{className:`size-4`}),`安装 DSH`]}):L&&!H&&!Y?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)(t,{disabled:!J,onClick:()=>void re(),size:`sm`,variant:`outline`,className:`hidden md:inline-flex`,children:[(0,I.jsx)(h,{className:`size-4`}),`DSH Web`]}),(0,I.jsx)(t,{disabled:a===`dsh`,onClick:()=>void(J?ne():Z()),size:`sm`,variant:`outline`,children:J?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(_,{className:`size-4 text-status-error`}),`停止 DSH`]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(v,{className:`size-4 text-primary`}),`启动 DSH`]})}),(0,I.jsx)(`span`,{"aria-hidden":`true`,className:`mx-1 h-5 w-px bg-border`}),(0,I.jsxs)(t,{className:`h-[30px]`,disabled:a===`gu`||O===null,onClick:()=>void se(),size:`sm`,variant:`outline`,children:[(0,I.jsx)(te,{className:n(`size-4`,O===!0?`text-status-ok`:`text-muted-foreground`)}),O===!0?`停止守护`:`启动守护`]})]}):null,L&&!H?(0,I.jsx)(I.Fragment,{children:(0,I.jsxs)(t,{className:`hidden h-[30px] md:inline-flex`,disabled:a===`uni`,onClick:()=>void oe(),size:`sm`,variant:`destructive`,children:[(0,I.jsx)(b,{className:`size-4`}),`卸载 DSH`]})}):null]})]})]}),(0,I.jsxs)(`div`,{className:`grid items-start gap-4 @min-[860px]:grid-cols-[minmax(0,1fr)_420px]`,children:[(0,I.jsx)(W,{events:X}),(0,I.jsx)(B,{providers:r.providers?.providers??[]})]}),(0,I.jsx)(ee,{open:d,onOpenChange:w,children:(0,I.jsxs)(m,{className:`max-w-[420px]`,children:[(0,I.jsx)(p,{children:(0,I.jsx)(o,{children:`升级 DeepSeek Harness`})}),(0,I.jsxs)(`div`,{className:`grid gap-3`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-center gap-3 rounded-md bg-muted px-4 py-3`,children:[(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`当前版本`}),(0,I.jsx)(`strong`,{className:`font-mono text-base text-foreground`,children:G?.installed||$})]}),(0,I.jsx)(M,{className:`size-4 text-muted-foreground`}),(0,I.jsxs)(`div`,{className:`text-center`,children:[(0,I.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:`新版本`}),(0,I.jsx)(`strong`,{className:`font-mono text-base text-primary`,children:G?.latest||`—`})]})]}),(0,I.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:`升级将先停止 DSH、安装新版本后自动拉起(需数分钟)。期间进行中的请求会中断,失败会自动回滚到当前版本。`})]}),(0,I.jsxs)(u,{children:[(0,I.jsx)(t,{onClick:()=>w(!1),variant:`outline`,children:`取消`}),(0,I.jsx)(t,{disabled:a===`upg`||Y,onClick:()=>void ie(),children:a===`upg`||Y?`升级中…`:`开始升级`})]})]})})]})}function U(){let[e,t]=(0,F.useState)(null),[r,i]=(0,F.useState)(null);(0,F.useEffect)(()=>{let e=!0,n=async()=>{let[n,r]=await Promise.all([l.nodeLts().catch(()=>null),l.envStatus().catch(()=>null)]);e&&(t(n),i(r?.catalog?.items??null))};n();let r=setInterval(n,6e5);return()=>{e=!1,clearInterval(r)}},[]);let a=Object.entries(r??{}).filter(([,e])=>e.required);return!e?.current&&a.length===0?(0,I.jsx)(`span`,{className:`min-w-[120px] text-xs text-muted-foreground`,children:`环境检测…`}):(0,I.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`whitespace-nowrap`,children:`环境检测`}),a.map(([e,t])=>{let r=t.state===`ok`||t.state===`configured`;return(0,I.jsxs)(`span`,{title:t.detail||void 0,className:n(`inline-flex items-center gap-1 whitespace-nowrap rounded-full px-2 py-0.5`,r?`text-muted-foreground/70`:`bg-warning-background font-semibold text-warning`),children:[!r&&(0,I.jsx)(d,{className:`size-3`}),t.label,` `,t.detail||`—`]},e)}),e?.ltsLine===!1?(0,I.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`,title:e.suggested||void 0,children:[(0,I.jsx)(d,{className:`size-3`}),`非 LTS 线(建议偶数主版本)`]}):e?.ltsLine===!0?(0,I.jsx)(`span`,{className:`hidden whitespace-nowrap text-muted-foreground/70 sm:inline`,children:`LTS 线`}):null]})}function W({events:e}){let[t,n]=(0,F.useState)(12),r=e.length;(0,F.useEffect)(()=>{n(12)},[e]);let i=(0,F.useRef)(null),a=(0,F.useRef)(!1);(0,F.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,I.jsxs)(A,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,I.jsx)(O,{title:`事件日志`,subtitle:`核心运行状态遥测`,actions:(0,I.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:r})}),r?(0,I.jsxs)(`div`,{className:`flex max-h-[450px] min-h-0 flex-col overflow-y-auto overscroll-contain`,children:[o.map((e,t)=>(0,I.jsx)(G,{e},e.seq??t)),(0,I.jsx)(`div`,{ref:i,className:`px-5 py-2 text-center text-[11px] text-muted-foreground`,children:s?`下滑加载更多…`:`已加载全部`})]}):(0,I.jsx)(`div`,{className:`px-5 py-6 text-center text-xs text-muted-foreground`,children:`暂无核心运行状态事件`})]})}function G({e}){let t=q[e.type]??`boot`,n=w[e.type]??e.type,r=K(e);return(0,I.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,I.jsx)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:j(e.ts)}),(0,I.jsx)(k,{tone:t,children:n}),(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:r})]})}function K(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 C(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`)return(t.name||(t.id===`main`?`原生 DSH`:t.id||`实例`))+` · 进程守护`+(t.enabled===!0?` → 开启`:` → 关闭`);if(e.type===`dsh_remote_changed`||e.type===`inst_remote_changed`)return(t.name||(t.id===`main`?`原生 DSH`:t.id||`实例`))+` · 远程控制 → `+(t.mode===`lan`?`局域网`:t.mode===`wan`?`公网`:`关闭`);if(e.type===`dsh_remote_token_changed`||e.type===`inst_remote_token_changed`)return(t.name||(t.id===`main`?`原生 DSH`:t.id||`实例`))+` · 访问令牌`+(t.tokenSet===!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 q={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`,api_offline:`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`,inst_remote_changed:`warn`,dsh_remote_token_changed:`warn`,inst_remote_token_changed:`warn`,lan_frp_blocked:`warn`,proxy_update_available:`warn`,upgrade_started:`warn`,upgrade_stopping_dsh:`warn`,inst_restarted:`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{H as OverviewPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{E as e,F as t,I as n,L as r,N as i,O as a,R as o,S as s,U as c,V as l,_ as u,a as d,d as f,f as p,h as m,l as h,m as g,p as _,u as v,v as y,x as b,y as x}from"./supervisor-BbSavtNN.js";import{n as S,t as C}from"./rocket-CLAmwatt.js";import{t as w}from"./refresh-cw-B-VAKpDt.js";import{t as T}from"./jobs-BjLbfJTM.js";import{c as E,u as D}from"./supervisor-C_6Efj6Z.js";import{t as O}from"./useSupervisorAction-q0YJmhui.js";import{n as k,o as A,t as j}from"./widgets-BbRkZm-Z.js";var M=i(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),N=i(`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`}]]),P=c(l(),1);function F(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 I=o(),L=24;async function R(e,t,n){if(!e.length)return;let r=a.loading(`正在`+t+` `+n+` 个插件…(0/`+e.length+`)`),i=0,o=0;for(let s of e){let c=await T(()=>d.pluginInstallStatus(s));c.state===`done`?i++:c.state===`failed`&&o++,a.loading(`正在`+t+` `+n+` 个插件…(`+(i+o)+`/`+e.length+`)`,{id:r})}o===0?a.success(t+`完成(`+i+`/`+e.length+`)`,{id:r}):a.warning(t+`结束:成功 `+i+`,失败 `+o,{id:r})}async function z(e,t,n=3e5,r=2e3){let i=await e(),a=Date.now()+n;for(;t(i)&&Date.now()<a;)await new Promise(e=>setTimeout(e,r)),i=await e();return i}function B(){let[e,t]=(0,P.useState)(`market`),[i,a]=(0,P.useState)(0);return(0,I.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`div`,{className:`flex gap-1 rounded-lg bg-muted p-1`,children:[`market`,`installed`].map(i=>(0,I.jsxs)(n,{className:r(`font-medium`,e===i?`bg-card text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-card/60 hover:text-foreground`),onClick:()=>t(i),size:`sm`,variant:`ghost`,children:[i===`market`?(0,I.jsx)(N,{className:`size-3.5`}):(0,I.jsx)(D,{className:`size-3.5`}),i===`market`?`插件商店`:`已安装`]},i))}),e===`market`?(0,I.jsx)(V,{onSettled:()=>a(e=>e+1)}):null]}),e===`market`?(0,I.jsx)(H,{nonce:i}):(0,I.jsx)(G,{})]})}function V({onSettled:e}){let[t,i]=(0,P.useState)(!1);async function o(){i(!0);try{let t=await d.market(!0),n=t.building?await z(()=>d.market(),e=>!!e.building):t;n.error?a.error(`索引刷新失败:`+n.error+`(暂用旧索引的 `+n.plugins.length+` 个)`):n.plugins.length?a.success(`插件索引已刷新(`+n.plugins.length+` 个)`):a.error(`索引刷新失败:无结果`),e?.()}catch(e){a.error(String(e))}i(!1)}return(0,I.jsxs)(n,{disabled:t,onClick:()=>void o(),size:`chip`,variant:`outline`,children:[(0,I.jsx)(w,{className:r(`size-3.5`,t&&`animate-spin`)}),`刷新`]})}function H({nonce:e=0}){let[t,i]=(0,P.useState)(null),[o,c]=(0,P.useState)(!1),[l,S]=(0,P.useState)(null),[C,w]=(0,P.useState)(``),[E,D]=(0,P.useState)(`all`),[O,k]=(0,P.useState)(`all`),[j,N]=(0,P.useState)(0),[F,R]=(0,P.useState)(null),[B,V]=(0,P.useState)([]),[H,G]=(0,P.useState)(`native`);(0,P.useEffect)(()=>{let e=!0;return(async()=>{try{let t=await d.market();if(t.building&&(e&&c(!0),t=await z(()=>d.market(),e=>!!e.building)),!e)return;c(!1),i(t.plugins.length?t:null),S(t.plugins.length?null:t.error||`索引为空,点「刷新」重建`),N(L)}catch(t){e&&(c(!1),S(String(t)))}})(),()=>{e=!1}},[e]);let K=(0,P.useMemo)(()=>{if(!t)return[];let e=C.trim().toLowerCase();return t.plugins.filter(t=>(E===`all`||t.category===E)&&(O===`all`||t.source===O)&&(!e||(t.name+` `+(t.description||``)).toLowerCase().includes(e)))},[t,C,E,O]),q=(0,P.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 J(e){R(e),G(`native`);try{let e=await d.instances();V((e.instances??[]).filter(e=>e.domain===`sandbox`).map(e=>({id:e.id,name:e.name})))}catch{V([])}}async function Y(){if(F)try{let e=await d.pluginInstall(F.name,H);if(e.ok===!1){a.error(e.error||`安装失败`);return}if(R(null),e.jobId){let t=a.loading(`正在安装 `+F.name+`…`),n=await T(()=>d.pluginInstallStatus(e.jobId));n.state===`done`?a.success(`已安装 `+F.name,{id:t}):n.state===`failed`?a.error(`安装失败:`+(n.error||`未知原因`),{id:t}):a.warning(`安装仍在进行(超时未完成,可稍后查看)`,{id:t})}else a.success(`安装任务已提交`)}catch(e){a.error(String(e))}}return(0,I.jsxs)(`div`,{className:`grid content-start gap-3`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`relative min-w-[220px] flex-1`,children:[(0,I.jsx)(M,{className:`absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)(u,{className:`pl-8`,placeholder:`搜索插件名称、描述…`,value:C,onChange:e=>w(e.target.value)})]}),(0,I.jsxs)(h,{value:E,onValueChange:D,children:[(0,I.jsx)(p,{className:`h-9 w-[150px] shrink-0`,children:(0,I.jsx)(_,{placeholder:`全部分类`})}),(0,I.jsxs)(v,{children:[(0,I.jsx)(f,{value:`all`,children:`全部分类`}),q.map(([e,t])=>(0,I.jsxs)(f,{value:e,children:[e,` (`,t,`)`]},e))]})]}),(0,I.jsxs)(h,{value:O,onValueChange:k,children:[(0,I.jsx)(p,{className:`h-9 w-[130px] shrink-0`,children:(0,I.jsx)(_,{placeholder:`全部来源`})}),(0,I.jsxs)(v,{children:[(0,I.jsx)(f,{value:`all`,children:`全部来源`}),(0,I.jsx)(f,{value:`npm`,children:`npm`}),(0,I.jsx)(f,{value:`github`,children:`GitHub`}),(0,I.jsx)(f,{value:`community`,children:`社区`}),(0,I.jsx)(f,{value:`official`,children:`官方`})]})]})]}),t?(0,I.jsxs)(I.Fragment,{children:[(0,I.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]}),K.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`grid grid-cols-1 gap-3 @min-[640px]:grid-cols-2 @min-[1000px]:grid-cols-3`,children:K.slice(0,j).map(e=>(0,I.jsxs)(`div`,{className:`flex min-h-[150px] flex-col rounded-lg border border-border bg-card p-4`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsx)(`strong`,{className:`truncate font-mono text-sm text-foreground`,children:e.name}),(0,I.jsx)(A,{tone:W(e.source),children:U(e.source)})]}),(0,I.jsx)(`p`,{className:`mt-2 line-clamp-3 min-h-[36px] text-xs leading-relaxed text-muted-foreground`,children:e.description||`(无描述)`}),(0,I.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:e.category}),e.version?(0,I.jsxs)(`span`,{className:`font-mono`,children:[`v`,e.version]}):null,e.stars?(0,I.jsxs)(`span`,{children:[`⭐`,e.stars]}):null]}),(0,I.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2 pt-3`,children:[(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.author||``}),(0,I.jsx)(n,{onClick:()=>void J(e),size:`chip`,children:`安装`})]})]},e.name))}),j<K.length?(0,I.jsxs)(n,{className:`justify-self-center`,onClick:()=>N(e=>e+L),variant:`outline`,children:[`加载更多(`,j,`/`,K.length,`)`]}):null]}):(0,I.jsx)(`div`,{className:`grid place-items-center rounded-lg border border-dashed border-border py-16 text-sm text-muted-foreground`,children:`无匹配插件`})]}):(0,I.jsx)(`div`,{className:`grid place-items-center py-20 text-sm text-muted-foreground`,children:o?`正在构建插件索引(首次约需数分钟,可留在本页)…`:l||`加载插件索引…`}),(0,I.jsx)(y,{open:!!F,onOpenChange:e=>!e&&R(null),children:(0,I.jsxs)(x,{className:`max-w-[400px]`,children:[(0,I.jsx)(b,{children:(0,I.jsxs)(s,{children:[`安装插件 — `,F?.name]})}),(0,I.jsx)(`div`,{className:`grid gap-2`,children:(0,I.jsx)(g,{value:H,onValueChange:G,className:`grid gap-2`,children:[[`native`,`原生实例`],[`all`,`所有实例(含原生)`]].concat(B.map(e=>[`id:`+e.id,e.name+`(`+e.id.slice(0,8)+`…)`])).map(([e,t])=>(0,I.jsxs)(`label`,{className:r(`flex cursor-pointer items-center gap-2 rounded-md border px-3 py-2 text-sm`,H===e?`border-primary/40 bg-primary/[0.05] text-foreground`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,I.jsx)(m,{value:e}),t]},e))})}),(0,I.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,I.jsx)(n,{onClick:()=>R(null),variant:`outline`,children:`取消`}),(0,I.jsx)(n,{onClick:()=>void Y(),children:`开始安装`})]})]})})]})}var U=e=>({npm:`npm`,github:`GitHub`,community:`社区`,official:`官方`})[e]??e,W=e=>e===`official`?`boot`:e===`npm`?`ok`:e===`github`?`warn`:`off`;function G(){let[i,o]=(0,P.useState)(null),[s,c]=(0,P.useState)(`all`),[l,u]=(0,P.useState)(new Set),[f,p]=(0,P.useState)(new Map),[m,h]=(0,P.useState)(!1),{busy:g,run:_}=O(),v=t(),y=async()=>{let e=await d.pluginsInstalled().catch(()=>null);o(e)};(0,P.useEffect)(()=>{y()},[]);let b=i?.thirdParty??[],x=e=>e.targets&&e.targets.length?e.targets:[`native`],T=b.filter(e=>s===`all`||x(e).includes(s)),M=e=>u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),N=T.length>0&&T.every(e=>l.has(e.name)),L=()=>u(N?new Set:new Set(T.map(e=>e.name))),B=T.filter(e=>l.has(e.name)),V=B.some(e=>f.has(e.name)),H=B.filter(e=>e.enabled),U=B.filter(e=>!e.enabled);async function W(){h(!0);try{let e=await d.pluginsCheckUpdates(!0),t=e.refreshing?await z(()=>d.pluginsCheckUpdates(),e=>!!e.refreshing):e,n=new Map;for(let e of t.plugins??[]){if(!e.updateAvailable)continue;let t=e.targets?.find(e=>e.latest)?.latest||``;n.set(e.name,t)}p(n);let r=(t.plugins??[]).filter(e=>e.error),i=n.size?`发现 `+n.size+` 个可更新插件`:`全部插件已是最新`;!t.checkedAt&&t.error?a.error(`检查更新失败:`+t.error):r.length?a.warning(r.length+` 个插件取不到最新版本(`+(r[0].error||``)+(r.length>1?` 等`:``)+`)· `+i):a.success(i),await y()}catch(e){a.error(String(e))}h(!1)}async function G(){let e=B.filter(e=>f.has(e.name)).map(e=>e.name);if(!e.length){a.info(`所选插件均无可用更新`);return}u(new Set),p(t=>{let n=new Map(t);for(let t of e)n.delete(t);return n}),await _(`upd-sel`,async()=>{let t=[];for(let n of e)try{let e=await d.pluginUpdate(n);e.jobId&&t.push(e.jobId)}catch{}await R(t,`更新`,e.length)},{success:`已提交 `+e.length+` 个插件的更新任务`,refresh:!1,onDone:()=>void y()})}async function K(){let e=B.map(e=>e.name);await v({title:`卸载所选插件?`,description:(0,I.jsxs)(I.Fragment,{children:[`将卸载所选 `,e.length,` 个插件:`,(0,I.jsx)(`ul`,{className:`mt-2 max-h-[180px] overflow-auto rounded-md border border-border/70 bg-muted/40 px-3 py-2`,children:e.map(e=>(0,I.jsx)(`li`,{className:`truncate text-foreground`,children:e},e))})]}),confirmText:`卸载`,tone:`destructive`})&&(u(new Set),await _(`uni-sel`,async()=>{let t=[];for(let n of e)try{let e=await d.pluginUninstall(n);e.jobId&&t.push(e.jobId)}catch{}await R(t,`卸载`,e.length)},{success:`已提交 `+e.length+` 个插件的卸载任务`,refresh:!1,onDone:()=>void y()}))}async function q(){let e=H.map(e=>e.name);u(new Set),await _(`stop-sel`,async()=>{for(let t of e)try{await d.pluginDisable(t)}catch{}},{success:`已停止 `+e.length+` 个插件`,refresh:!1,onDone:()=>void y()})}async function J(){let e=U.map(e=>e.name);u(new Set),await _(`start-sel`,async()=>{for(let t of e)try{await d.pluginEnable(t)}catch{}},{success:`已启动 `+e.length+` 个插件`,refresh:!1,onDone:()=>void y()})}let Y=`grid grid-cols-[88px_minmax(0,1fr)_120px_84px_36px] items-center gap-3`;return(0,I.jsxs)(j,{className:`overflow-hidden`,children:[(0,I.jsx)(k,{title:`已安装插件`+(i?`(`+T.length+`)`:``),subtitle:s===`all`?`全部实例`:`实例:`+((i?.targets??[]).find(e=>e.id===s)?.name??s),actions:(0,I.jsxs)(I.Fragment,{children:[V?(0,I.jsxs)(n,{disabled:g===`upd-sel`,onClick:()=>void G(),size:`sm`,children:[(0,I.jsx)(w,{className:`size-3.5`}),`更新(`,B.filter(e=>f.has(e.name)).length,`)`]}):(0,I.jsxs)(n,{disabled:m,onClick:()=>void W(),size:`sm`,variant:`outline`,children:[(0,I.jsx)(w,{className:r(`size-3.5`,m&&`animate-spin`)}),m?`检查中…`:`检查更新`]}),B.length>0?(0,I.jsxs)(I.Fragment,{children:[H.length>0?(0,I.jsxs)(n,{disabled:g===`stop-sel`,onClick:()=>void q(),size:`sm`,variant:`outline`,children:[(0,I.jsx)(S,{className:`size-3.5`}),`停用(`,H.length,`)`]}):null,U.length>0?(0,I.jsxs)(n,{disabled:g===`start-sel`,onClick:()=>void J(),size:`sm`,variant:`outline`,children:[(0,I.jsx)(C,{className:`size-3.5`}),`启动(`,U.length,`)`]}):null,(0,I.jsxs)(n,{className:`h-[30px]`,disabled:g===`uni-sel`,onClick:()=>void K(),size:`sm`,variant:`destructive`,children:[(0,I.jsx)(E,{className:`size-3.5`}),`卸载(`,B.length,`)`]})]}):null]})}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 border-b border-border/60 px-5 py-2.5`,children:[(0,I.jsx)(n,{className:r(s===`all`?`bg-primary/10 text-primary hover:bg-primary/15`:`text-muted-foreground hover:bg-muted hover:text-foreground`),onClick:()=>c(`all`),size:`sm`,variant:`ghost`,children:`全部实例`}),(i?.targets??[]).map(e=>(0,I.jsx)(n,{className:r(s===e.id?`bg-primary/10 text-primary hover:bg-primary/15`:`text-muted-foreground hover:bg-muted hover:text-foreground`),onClick:()=>c(e.id),size:`sm`,variant:`ghost`,children:e.name},e.id))]}),i?T.length?(0,I.jsx)(I.Fragment,{children:(0,I.jsxs)(`div`,{className:`overflow-x-auto`,children:[(0,I.jsxs)(`div`,{className:r(Y,`min-w-[720px] border-b border-border/70 bg-muted px-5 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`),children:[(0,I.jsx)(`span`,{children:`来源`}),(0,I.jsx)(`span`,{children:`插件`}),(0,I.jsx)(`span`,{children:`版本`}),(0,I.jsx)(`span`,{className:`text-right`,children:`大小`}),(0,I.jsx)(`span`,{className:`flex justify-end`,children:(0,I.jsx)(e,{"aria-label":`全选`,checked:N,onChange:L})})]}),(0,I.jsx)(`div`,{className:`max-h-[560px] overflow-auto`,children:T.map(t=>{let n=l.has(t.name),i=f.get(t.name);return(0,I.jsxs)(`label`,{className:r(Y,`min-h-[46px] min-w-[720px] w-full cursor-pointer border-b border-border/50 px-5 py-2 text-left transition-colors last:border-b-0 hover:bg-muted/40`,n&&`bg-muted/70 shadow-[inset_3px_0_0_var(--primary)]`),children:[(0,I.jsx)(`span`,{className:`inline-flex w-fit min-w-0 items-center`,children:(0,I.jsx)(A,{tone:t.bundle?`boot`:t.source?.includes(`github`)?`warn`:t.source===`npm`?`ok`:`off`,children:t.bundle?`bundle`:t.source===`npm`?`npm`:t.source?.includes(`github`)?`GitHub`:t.source&&t.source!==t.name?`本地`:`—`})}),(0,I.jsx)(`span`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2`,children:(0,I.jsxs)(`span`,{className:`grid min-w-0 gap-0.5`,children:[(0,I.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsx)(`strong`,{className:`truncate font-mono text-[13px] font-semibold leading-tight text-foreground`,children:t.name}),(0,I.jsx)(A,{tone:t.enabled?`ok`:`off`,children:t.enabled?`已启用`:`已停用`})]}),t.description?(0,I.jsx)(`span`,{className:`truncate text-xs leading-tight text-muted-foreground`,children:t.description}):null]})}),(0,I.jsx)(`span`,{className:`min-w-0`,children:i?(0,I.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:t.version?`v`+t.version:`—`}),(0,I.jsx)(A,{tone:`warn`,children:`可更新`})]}):(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.version?`v`+t.version:`—`})}),(0,I.jsx)(`span`,{className:`text-right font-mono text-xs tabular-nums text-foreground`,children:t.size?F(t.size):`—`}),(0,I.jsx)(`span`,{className:`flex justify-end`,children:(0,I.jsx)(e,{"aria-label":`选择 `+t.name,checked:n,onChange:()=>M(t.name)})})]},t.name)})})]})}):(0,I.jsxs)(`div`,{className:`grid place-items-center rounded-lg border-0 py-16 text-center`,children:[(0,I.jsx)(D,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`当前实例均未安装第三方插件`})]}):(0,I.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:`加载中…`})]})}export{B as PluginsPage};
|
|
1
|
+
import{E as e,F as t,I as n,L as r,N as i,O as a,R as o,S as s,U as c,V as l,_ as u,a as d,d as f,f as p,h as m,l as h,m as g,p as _,u as v,v as y,x as b,y as x}from"./supervisor-BbSavtNN.js";import{n as S,t as C}from"./rocket-CLAmwatt.js";import{t as w}from"./refresh-cw-B-VAKpDt.js";import{t as T}from"./jobs-BjLbfJTM.js";import{c as E,u as D}from"./supervisor-Btn_MIEc.js";import{t as O}from"./useSupervisorAction-q0YJmhui.js";import{n as k,o as A,t as j}from"./widgets-BbRkZm-Z.js";var M=i(`search`,[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]]),N=i(`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`}]]),P=c(l(),1);function F(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 I=o(),L=24;async function R(e,t,n){if(!e.length)return;let r=a.loading(`正在`+t+` `+n+` 个插件…(0/`+e.length+`)`),i=0,o=0;for(let s of e){let c=await T(()=>d.pluginInstallStatus(s));c.state===`done`?i++:c.state===`failed`&&o++,a.loading(`正在`+t+` `+n+` 个插件…(`+(i+o)+`/`+e.length+`)`,{id:r})}o===0?a.success(t+`完成(`+i+`/`+e.length+`)`,{id:r}):a.warning(t+`结束:成功 `+i+`,失败 `+o,{id:r})}async function z(e,t,n=3e5,r=2e3){let i=await e(),a=Date.now()+n;for(;t(i)&&Date.now()<a;)await new Promise(e=>setTimeout(e,r)),i=await e();return i}function B(){let[e,t]=(0,P.useState)(`market`),[i,a]=(0,P.useState)(0);return(0,I.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,I.jsx)(`div`,{className:`flex gap-1 rounded-lg bg-muted p-1`,children:[`market`,`installed`].map(i=>(0,I.jsxs)(n,{className:r(`font-medium`,e===i?`bg-card text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-card/60 hover:text-foreground`),onClick:()=>t(i),size:`sm`,variant:`ghost`,children:[i===`market`?(0,I.jsx)(N,{className:`size-3.5`}):(0,I.jsx)(D,{className:`size-3.5`}),i===`market`?`插件商店`:`已安装`]},i))}),e===`market`?(0,I.jsx)(V,{onSettled:()=>a(e=>e+1)}):null]}),e===`market`?(0,I.jsx)(H,{nonce:i}):(0,I.jsx)(G,{})]})}function V({onSettled:e}){let[t,i]=(0,P.useState)(!1);async function o(){i(!0);try{let t=await d.market(!0),n=t.building?await z(()=>d.market(),e=>!!e.building):t;n.error?a.error(`索引刷新失败:`+n.error+`(暂用旧索引的 `+n.plugins.length+` 个)`):n.plugins.length?a.success(`插件索引已刷新(`+n.plugins.length+` 个)`):a.error(`索引刷新失败:无结果`),e?.()}catch(e){a.error(String(e))}i(!1)}return(0,I.jsxs)(n,{disabled:t,onClick:()=>void o(),size:`chip`,variant:`outline`,children:[(0,I.jsx)(w,{className:r(`size-3.5`,t&&`animate-spin`)}),`刷新`]})}function H({nonce:e=0}){let[t,i]=(0,P.useState)(null),[o,c]=(0,P.useState)(!1),[l,S]=(0,P.useState)(null),[C,w]=(0,P.useState)(``),[E,D]=(0,P.useState)(`all`),[O,k]=(0,P.useState)(`all`),[j,N]=(0,P.useState)(0),[F,R]=(0,P.useState)(null),[B,V]=(0,P.useState)([]),[H,G]=(0,P.useState)(`native`);(0,P.useEffect)(()=>{let e=!0;return(async()=>{try{let t=await d.market();if(t.building&&(e&&c(!0),t=await z(()=>d.market(),e=>!!e.building)),!e)return;c(!1),i(t.plugins.length?t:null),S(t.plugins.length?null:t.error||`索引为空,点「刷新」重建`),N(L)}catch(t){e&&(c(!1),S(String(t)))}})(),()=>{e=!1}},[e]);let K=(0,P.useMemo)(()=>{if(!t)return[];let e=C.trim().toLowerCase();return t.plugins.filter(t=>(E===`all`||t.category===E)&&(O===`all`||t.source===O)&&(!e||(t.name+` `+(t.description||``)).toLowerCase().includes(e)))},[t,C,E,O]),q=(0,P.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 J(e){R(e),G(`native`);try{let e=await d.instances();V((e.instances??[]).filter(e=>e.domain===`sandbox`).map(e=>({id:e.id,name:e.name})))}catch{V([])}}async function Y(){if(F)try{let e=await d.pluginInstall(F.name,H);if(e.ok===!1){a.error(e.error||`安装失败`);return}if(R(null),e.jobId){let t=a.loading(`正在安装 `+F.name+`…`),n=await T(()=>d.pluginInstallStatus(e.jobId));n.state===`done`?a.success(`已安装 `+F.name,{id:t}):n.state===`failed`?a.error(`安装失败:`+(n.error||`未知原因`),{id:t}):a.warning(`安装仍在进行(超时未完成,可稍后查看)`,{id:t})}else a.success(`安装任务已提交`)}catch(e){a.error(String(e))}}return(0,I.jsxs)(`div`,{className:`grid content-start gap-3`,children:[(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,I.jsxs)(`div`,{className:`relative min-w-[220px] flex-1`,children:[(0,I.jsx)(M,{className:`absolute left-2.5 top-1/2 size-4 -translate-y-1/2 text-muted-foreground`}),(0,I.jsx)(u,{className:`pl-8`,placeholder:`搜索插件名称、描述…`,value:C,onChange:e=>w(e.target.value)})]}),(0,I.jsxs)(h,{value:E,onValueChange:D,children:[(0,I.jsx)(p,{className:`h-9 w-[150px] shrink-0`,children:(0,I.jsx)(_,{placeholder:`全部分类`})}),(0,I.jsxs)(v,{children:[(0,I.jsx)(f,{value:`all`,children:`全部分类`}),q.map(([e,t])=>(0,I.jsxs)(f,{value:e,children:[e,` (`,t,`)`]},e))]})]}),(0,I.jsxs)(h,{value:O,onValueChange:k,children:[(0,I.jsx)(p,{className:`h-9 w-[130px] shrink-0`,children:(0,I.jsx)(_,{placeholder:`全部来源`})}),(0,I.jsxs)(v,{children:[(0,I.jsx)(f,{value:`all`,children:`全部来源`}),(0,I.jsx)(f,{value:`npm`,children:`npm`}),(0,I.jsx)(f,{value:`github`,children:`GitHub`}),(0,I.jsx)(f,{value:`community`,children:`社区`}),(0,I.jsx)(f,{value:`official`,children:`官方`})]})]})]}),t?(0,I.jsxs)(I.Fragment,{children:[(0,I.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]}),K.length?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`div`,{className:`grid grid-cols-1 gap-3 @min-[640px]:grid-cols-2 @min-[1000px]:grid-cols-3`,children:K.slice(0,j).map(e=>(0,I.jsxs)(`div`,{className:`flex min-h-[150px] flex-col rounded-lg border border-border bg-card p-4`,children:[(0,I.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,I.jsx)(`strong`,{className:`truncate font-mono text-sm text-foreground`,children:e.name}),(0,I.jsx)(A,{tone:W(e.source),children:U(e.source)})]}),(0,I.jsx)(`p`,{className:`mt-2 line-clamp-3 min-h-[36px] text-xs leading-relaxed text-muted-foreground`,children:e.description||`(无描述)`}),(0,I.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,I.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5`,children:e.category}),e.version?(0,I.jsxs)(`span`,{className:`font-mono`,children:[`v`,e.version]}):null,e.stars?(0,I.jsxs)(`span`,{children:[`⭐`,e.stars]}):null]}),(0,I.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2 pt-3`,children:[(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.author||``}),(0,I.jsx)(n,{onClick:()=>void J(e),size:`chip`,children:`安装`})]})]},e.name))}),j<K.length?(0,I.jsxs)(n,{className:`justify-self-center`,onClick:()=>N(e=>e+L),variant:`outline`,children:[`加载更多(`,j,`/`,K.length,`)`]}):null]}):(0,I.jsx)(`div`,{className:`grid place-items-center rounded-lg border border-dashed border-border py-16 text-sm text-muted-foreground`,children:`无匹配插件`})]}):(0,I.jsx)(`div`,{className:`grid place-items-center py-20 text-sm text-muted-foreground`,children:o?`正在构建插件索引(首次约需数分钟,可留在本页)…`:l||`加载插件索引…`}),(0,I.jsx)(y,{open:!!F,onOpenChange:e=>!e&&R(null),children:(0,I.jsxs)(x,{className:`max-w-[400px]`,children:[(0,I.jsx)(b,{children:(0,I.jsxs)(s,{children:[`安装插件 — `,F?.name]})}),(0,I.jsx)(`div`,{className:`grid gap-2`,children:(0,I.jsx)(g,{value:H,onValueChange:G,className:`grid gap-2`,children:[[`native`,`原生实例`],[`all`,`所有实例(含原生)`]].concat(B.map(e=>[`id:`+e.id,e.name+`(`+e.id.slice(0,8)+`…)`])).map(([e,t])=>(0,I.jsxs)(`label`,{className:r(`flex cursor-pointer items-center gap-2 rounded-md border px-3 py-2 text-sm`,H===e?`border-primary/40 bg-primary/[0.05] text-foreground`:`border-border text-muted-foreground hover:bg-muted`),children:[(0,I.jsx)(m,{value:e}),t]},e))})}),(0,I.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,I.jsx)(n,{onClick:()=>R(null),variant:`outline`,children:`取消`}),(0,I.jsx)(n,{onClick:()=>void Y(),children:`开始安装`})]})]})})]})}var U=e=>({npm:`npm`,github:`GitHub`,community:`社区`,official:`官方`})[e]??e,W=e=>e===`official`?`boot`:e===`npm`?`ok`:e===`github`?`warn`:`off`;function G(){let[i,o]=(0,P.useState)(null),[s,c]=(0,P.useState)(`all`),[l,u]=(0,P.useState)(new Set),[f,p]=(0,P.useState)(new Map),[m,h]=(0,P.useState)(!1),{busy:g,run:_}=O(),v=t(),y=async()=>{let e=await d.pluginsInstalled().catch(()=>null);o(e)};(0,P.useEffect)(()=>{y()},[]);let b=i?.thirdParty??[],x=e=>e.targets&&e.targets.length?e.targets:[`native`],T=b.filter(e=>s===`all`||x(e).includes(s)),M=e=>u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),N=T.length>0&&T.every(e=>l.has(e.name)),L=()=>u(N?new Set:new Set(T.map(e=>e.name))),B=T.filter(e=>l.has(e.name)),V=B.some(e=>f.has(e.name)),H=B.filter(e=>e.enabled),U=B.filter(e=>!e.enabled);async function W(){h(!0);try{let e=await d.pluginsCheckUpdates(!0),t=e.refreshing?await z(()=>d.pluginsCheckUpdates(),e=>!!e.refreshing):e,n=new Map;for(let e of t.plugins??[]){if(!e.updateAvailable)continue;let t=e.targets?.find(e=>e.latest)?.latest||``;n.set(e.name,t)}p(n);let r=(t.plugins??[]).filter(e=>e.error),i=n.size?`发现 `+n.size+` 个可更新插件`:`全部插件已是最新`;!t.checkedAt&&t.error?a.error(`检查更新失败:`+t.error):r.length?a.warning(r.length+` 个插件取不到最新版本(`+(r[0].error||``)+(r.length>1?` 等`:``)+`)· `+i):a.success(i),await y()}catch(e){a.error(String(e))}h(!1)}async function G(){let e=B.filter(e=>f.has(e.name)).map(e=>e.name);if(!e.length){a.info(`所选插件均无可用更新`);return}u(new Set),p(t=>{let n=new Map(t);for(let t of e)n.delete(t);return n}),await _(`upd-sel`,async()=>{let t=[];for(let n of e)try{let e=await d.pluginUpdate(n);e.jobId&&t.push(e.jobId)}catch{}await R(t,`更新`,e.length)},{success:`已提交 `+e.length+` 个插件的更新任务`,refresh:!1,onDone:()=>void y()})}async function K(){let e=B.map(e=>e.name);await v({title:`卸载所选插件?`,description:(0,I.jsxs)(I.Fragment,{children:[`将卸载所选 `,e.length,` 个插件:`,(0,I.jsx)(`ul`,{className:`mt-2 max-h-[180px] overflow-auto rounded-md border border-border/70 bg-muted/40 px-3 py-2`,children:e.map(e=>(0,I.jsx)(`li`,{className:`truncate text-foreground`,children:e},e))})]}),confirmText:`卸载`,tone:`destructive`})&&(u(new Set),await _(`uni-sel`,async()=>{let t=[];for(let n of e)try{let e=await d.pluginUninstall(n);e.jobId&&t.push(e.jobId)}catch{}await R(t,`卸载`,e.length)},{success:`已提交 `+e.length+` 个插件的卸载任务`,refresh:!1,onDone:()=>void y()}))}async function q(){let e=H.map(e=>e.name);u(new Set),await _(`stop-sel`,async()=>{for(let t of e)try{await d.pluginDisable(t)}catch{}},{success:`已停止 `+e.length+` 个插件`,refresh:!1,onDone:()=>void y()})}async function J(){let e=U.map(e=>e.name);u(new Set),await _(`start-sel`,async()=>{for(let t of e)try{await d.pluginEnable(t)}catch{}},{success:`已启动 `+e.length+` 个插件`,refresh:!1,onDone:()=>void y()})}let Y=`grid grid-cols-[88px_minmax(0,1fr)_120px_84px_36px] items-center gap-3`;return(0,I.jsxs)(j,{className:`overflow-hidden`,children:[(0,I.jsx)(k,{title:`已安装插件`+(i?`(`+T.length+`)`:``),subtitle:s===`all`?`全部实例`:`实例:`+((i?.targets??[]).find(e=>e.id===s)?.name??s),actions:(0,I.jsxs)(I.Fragment,{children:[V?(0,I.jsxs)(n,{disabled:g===`upd-sel`,onClick:()=>void G(),size:`sm`,children:[(0,I.jsx)(w,{className:`size-3.5`}),`更新(`,B.filter(e=>f.has(e.name)).length,`)`]}):(0,I.jsxs)(n,{disabled:m,onClick:()=>void W(),size:`sm`,variant:`outline`,children:[(0,I.jsx)(w,{className:r(`size-3.5`,m&&`animate-spin`)}),m?`检查中…`:`检查更新`]}),B.length>0?(0,I.jsxs)(I.Fragment,{children:[H.length>0?(0,I.jsxs)(n,{disabled:g===`stop-sel`,onClick:()=>void q(),size:`sm`,variant:`outline`,children:[(0,I.jsx)(S,{className:`size-3.5`}),`停用(`,H.length,`)`]}):null,U.length>0?(0,I.jsxs)(n,{disabled:g===`start-sel`,onClick:()=>void J(),size:`sm`,variant:`outline`,children:[(0,I.jsx)(C,{className:`size-3.5`}),`启动(`,U.length,`)`]}):null,(0,I.jsxs)(n,{className:`h-[30px]`,disabled:g===`uni-sel`,onClick:()=>void K(),size:`sm`,variant:`destructive`,children:[(0,I.jsx)(E,{className:`size-3.5`}),`卸载(`,B.length,`)`]})]}):null]})}),(0,I.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5 border-b border-border/60 px-5 py-2.5`,children:[(0,I.jsx)(n,{className:r(s===`all`?`bg-primary/10 text-primary hover:bg-primary/15`:`text-muted-foreground hover:bg-muted hover:text-foreground`),onClick:()=>c(`all`),size:`sm`,variant:`ghost`,children:`全部实例`}),(i?.targets??[]).map(e=>(0,I.jsx)(n,{className:r(s===e.id?`bg-primary/10 text-primary hover:bg-primary/15`:`text-muted-foreground hover:bg-muted hover:text-foreground`),onClick:()=>c(e.id),size:`sm`,variant:`ghost`,children:e.name},e.id))]}),i?T.length?(0,I.jsx)(I.Fragment,{children:(0,I.jsxs)(`div`,{className:`overflow-x-auto`,children:[(0,I.jsxs)(`div`,{className:r(Y,`min-w-[720px] border-b border-border/70 bg-muted px-5 py-2 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`),children:[(0,I.jsx)(`span`,{children:`来源`}),(0,I.jsx)(`span`,{children:`插件`}),(0,I.jsx)(`span`,{children:`版本`}),(0,I.jsx)(`span`,{className:`text-right`,children:`大小`}),(0,I.jsx)(`span`,{className:`flex justify-end`,children:(0,I.jsx)(e,{"aria-label":`全选`,checked:N,onChange:L})})]}),(0,I.jsx)(`div`,{className:`max-h-[560px] overflow-auto`,children:T.map(t=>{let n=l.has(t.name),i=f.get(t.name);return(0,I.jsxs)(`label`,{className:r(Y,`min-h-[46px] min-w-[720px] w-full cursor-pointer border-b border-border/50 px-5 py-2 text-left transition-colors last:border-b-0 hover:bg-muted/40`,n&&`bg-muted/70 shadow-[inset_3px_0_0_var(--primary)]`),children:[(0,I.jsx)(`span`,{className:`inline-flex w-fit min-w-0 items-center`,children:(0,I.jsx)(A,{tone:t.bundle?`boot`:t.source?.includes(`github`)?`warn`:t.source===`npm`?`ok`:`off`,children:t.bundle?`bundle`:t.source===`npm`?`npm`:t.source?.includes(`github`)?`GitHub`:t.source&&t.source!==t.name?`本地`:`—`})}),(0,I.jsx)(`span`,{className:`grid min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2`,children:(0,I.jsxs)(`span`,{className:`grid min-w-0 gap-0.5`,children:[(0,I.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,I.jsx)(`strong`,{className:`truncate font-mono text-[13px] font-semibold leading-tight text-foreground`,children:t.name}),(0,I.jsx)(A,{tone:t.enabled?`ok`:`off`,children:t.enabled?`已启用`:`已停用`})]}),t.description?(0,I.jsx)(`span`,{className:`truncate text-xs leading-tight text-muted-foreground`,children:t.description}):null]})}),(0,I.jsx)(`span`,{className:`min-w-0`,children:i?(0,I.jsxs)(`span`,{className:`inline-flex flex-wrap items-center gap-1.5`,children:[(0,I.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:t.version?`v`+t.version:`—`}),(0,I.jsx)(A,{tone:`warn`,children:`可更新`})]}):(0,I.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:t.version?`v`+t.version:`—`})}),(0,I.jsx)(`span`,{className:`text-right font-mono text-xs tabular-nums text-foreground`,children:t.size?F(t.size):`—`}),(0,I.jsx)(`span`,{className:`flex justify-end`,children:(0,I.jsx)(e,{"aria-label":`选择 `+t.name,checked:n,onChange:()=>M(t.name)})})]},t.name)})})]})}):(0,I.jsxs)(`div`,{className:`grid place-items-center rounded-lg border-0 py-16 text-center`,children:[(0,I.jsx)(D,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,I.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`当前实例均未安装第三方插件`})]}):(0,I.jsx)(`div`,{className:`py-16 text-center text-sm text-muted-foreground`,children:`加载中…`})]})}export{B as PluginsPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{A as e,F as t,I as n,L as r,N as i,O as a,R as o,S as s,U as c,V as l,_ as u,a as d,d as f,f as p,g as m,l as h,n as g,o as _,p as v,t as y,u as b,v as x,x as S,y as C}from"./supervisor-BbSavtNN.js";import{i as w,t as T}from"./openExternal-CBH3SnvT.js";import{n as E,t as D}from"./rocket-CLAmwatt.js";import{t as O}from"./refresh-cw-B-VAKpDt.js";import{t as k}from"./jobs-BjLbfJTM.js";import{c as A,f as j,l as M}from"./supervisor-C_6Efj6Z.js";import{t as N}from"./useSupervisorAction-q0YJmhui.js";import{a as P,c as F,i as I,o as L,s as R,t as z}from"./widgets-BbRkZm-Z.js";import{n as B}from"./format-QeaTKFhQ.js";var V=i(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),H=i(`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`}]]),U=i(`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`}]]),W=i(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),G=c(l(),1),K=o();function q(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 J(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 Y(e){return[...e].sort((e,t)=>{let n=e=>e.selected?0:e.usable&&!q(e.quota)?1:2;return n(e)-n(t)})}var X=`grid-cols-[minmax(0,1fr)_230px_84px]`;function Z({onRegisterActions:t}){let{snap:i}=y(),{busy:a,run:o}=N(),[s,c]=(0,G.useState)(!1),[l,u]=(0,G.useState)(!1),f=i.router,p=i.providers;(0,G.useEffect)(()=>(t?.({onAdd:()=>c(!0),onDelete:()=>u(!0)}),()=>t?.(null)),[t]);function m(e,t,n){return o(e,t,{success:n})}let h=p?.providers??[];return(0,K.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,K.jsxs)(z,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-border/70 px-5 py-3.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(F,{tone:f?.running?`ok`:`off`,ping:!!f?.running}),(0,K.jsx)(`strong`,{className:`text-xl font-semibold tracking-[-0.01em] text-foreground`,children:f?.running?`路由运行中`:`路由已停止`})]}),(0,K.jsx)(n,{"aria-label":f?.running?`停止路由`:`启动路由`,className:r(`px-1`,f?.running?`text-status-error`:`text-primary`),disabled:a===`sw`,onClick:()=>void m(`sw`,()=>f?.running?d.lifecycleStop(`router`):d.lifecycleStart(`router`),f?.running?`路由已停止`:`路由已启动`),title:f?.running?`停止路由`:`启动路由`,variant:`ghost`,children:f?.running?(0,K.jsx)(E,{className:`size-6`}):(0,K.jsx)(D,{className:`size-6`})})]}),(0,K.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,K.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,K.jsx)(I,{icon:(0,K.jsx)(j,{className:`size-4`}),label:`总请求 / 失败`,value:B(f?.usage?.requests)+` / `+B(f?.usage?.errors),mono:!0})}),(0,K.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,K.jsx)(I,{icon:(0,K.jsx)(e,{className:`size-4`}),label:`总 Tokens`,value:B(f?.usage?.totalTokens),mono:!0})}),(0,K.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,K.jsx)(I,{icon:(0,K.jsx)(W,{className:`size-4`}),label:`Prompt / Completion`,value:B(f?.usage?.promptTokens)+` / `+B(f?.usage?.completionTokens),mono:!0})}),(0,K.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,K.jsx)(I,{icon:(0,K.jsx)(H,{className:`size-4`}),label:`估算费用`,value:f?.usage?.costUsd?`$`+Number(f.usage.costUsd).toFixed(4):`—`,mono:!0,warn:!f?.usage?.costUsd})})]})]}),h.length?(0,K.jsx)(`div`,{className:`grid gap-4 @min-[900px]:grid-cols-2`,children:h.map(e=>(0,K.jsx)($,{p:e,proxyApps:p?.proxyApps??[],busy:a===e.id,onAction:m},e.id))}):(0,K.jsx)(`div`,{className:`grid min-h-[200px] place-items-center rounded-lg border border-dashed border-border text-center`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(j,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`尚未添加供应商`}),(0,K.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`点击「添加供应商」录入 API Key / Command Code`})]})}),(0,K.jsx)(ie,{open:s,onOpenChange:c,presets:p?.presets??[],proxyApps:p?.proxyApps??[],onDone:()=>g.refresh()}),(0,K.jsx)(Q,{open:l,onOpenChange:u,providers:h})]})}function Q({open:e,onOpenChange:r,providers:i}){let[o,c]=(0,G.useState)(null),l=t();async function u(e){if(await l({title:`删除供应商「`+e.name+`」?`,description:`其下全部账号与 Key 将被移除,不可恢复。`,confirmText:`删除`,tone:`destructive`})){c(e.id);try{await d.providerRemove(e.id),a.success(`已删除供应商「`+e.name+`」`),await g.refresh()}catch(e){a.error(String(e))}finally{c(null)}}}return(0,K.jsx)(x,{open:e,onOpenChange:r,children:(0,K.jsxs)(C,{className:`max-w-[440px]`,children:[(0,K.jsx)(S,{children:(0,K.jsx)(s,{children:`删除供应商`})}),(0,K.jsx)(`div`,{className:`grid gap-1.5`,children:i.length?i.map(e=>(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`strong`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.kind===`proxy`?`反代`:`直连`,` · `,(e.accounts??[]).length,` 账号`]})]}),(0,K.jsxs)(n,{disabled:o===e.id,onClick:()=>void u(e),size:`chip`,variant:`destructive`,children:[o===e.id?(0,K.jsx)(O,{className:`size-3 animate-spin`}):(0,K.jsx)(A,{className:`size-3`}),`删除`]})]},e.id)):(0,K.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`暂无供应商`})}),(0,K.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,K.jsx)(n,{onClick:()=>r(!1),variant:`outline`,children:`关闭`})})]})})}function $({p:e,proxyApps:t,busy:i,onAction:o}){let s=Y(e.accounts??[]),c=s.find(e=>e.selected)||s.find(e=>e.usable&&!q(e.quota))||s[0],[l,u]=(0,G.useState)(!1),f=e.kind===`proxy`?(t??[]).find(t=>t.id===e.proxyAppId)??null:null,p=e.apiBase||(e.apiPort?`http://127.0.0.1:`+e.apiPort+`/v1`:null);return(0,K.jsxs)(z,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`strong`,{className:`truncate text-sm font-semibold text-foreground`,children:e.name}),e.kind===`proxy`&&f&&f.installed?f.updateAvailable?(0,K.jsxs)(n,{className:`gap-1 rounded-full px-2.5 text-xs text-warning`,disabled:i,onClick:()=>void o(`proxy-upd-`+e.id,async()=>{let t=e.proxyAppId,n=await d.proxyUpdateApply(t);if(n.ok===!1){a.error(n.error||`提交失败`);return}let r=a.loading(`正在更新 `+e.name+` 的全部实例…`),i=await k(()=>d.proxyUpdateStatus(t),{onTick:t=>{let n=t?.steps||[],i=n.filter(e=>e.state===`done`).length;n.length&&a.loading(`正在更新 `+e.name+`…(`+i+`/`+n.length+` 实例)`,{id:r})}}),o=i.snapshot;i.state===`done`?a.success(`更新完成`+(o?.restarted?`(已重启 `+o.restarted+` 个实例)`:``),{id:r}):i.state===`failed`?a.error(`更新失败:`+(i.error||(o?.errors?o.errors+` 个实例失败`:`未知原因`)),{id:r}):a.warning(`更新仍在进行(超时未完成,可稍后查看)`,{id:r}),await g.refresh()},void 0),size:`chip`,title:`检测到新版本,点击更新该应用全部实例`,variant:`outline`,children:[(0,K.jsx)(O,{className:`size-3`}),`更新 v`,f.latest]}):(0,K.jsxs)(n,{className:`gap-1 rounded-full px-2.5 text-xs font-mono text-muted-foreground`,disabled:i,onClick:()=>{o(`proxy-chk-`+e.id,async()=>{let t=await d.proxyUpdateCheck();if(await g.refresh(),!t.ok){a.error(t.error||`版本检测失败`);return}let n=t.versions?.[e.proxyAppId||``]||null,r=f.installed;a.info(n&&n!==r?`发现新版本 v`+n+`,点击版本胶囊更新`:`已是最新版本 v`+r)},void 0)},size:`chip`,title:`检测是否有新版本`,variant:`outline`,children:[`v`,f.installed,(0,K.jsx)(O,{className:r(`size-3`,i&&`animate-spin`)})]}):null]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5`,children:[(0,K.jsxs)(n,{disabled:i,onClick:()=>u(!0),size:`sm`,variant:`outline`,children:[(0,K.jsx)(M,{className:`size-3.5`}),`添加`]}),e.activated?(0,K.jsxs)(n,{disabled:i,onClick:()=>void o(`deact`,()=>d.providerDeactivate(e.id).then(()=>void 0),`已停用供应商(资源已回收)`),size:`sm`,variant:`outline`,children:[(0,K.jsx)(E,{className:`size-3.5`}),`停用`]}):(0,K.jsxs)(n,{disabled:i,onClick:()=>void o(`act`,()=>d.providerActivate(e.id).then(()=>void 0),`已启用供应商`),size:`sm`,variant:`outline`,children:[(0,K.jsx)(D,{className:`size-3.5`}),`启用`]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 px-5 py-2.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`API 地址`}),(0,K.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:e.activated&&p?(0,K.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,children:p}):(0,K.jsx)(`span`,{className:`truncate text-xs text-muted-foreground/70`,children:`服务未启用`})}),e.activated&&p?(0,K.jsxs)(n,{onClick:()=>void navigator.clipboard.writeText(p||``).then(()=>a.success(`已复制 API 地址`)),size:`sm`,title:`复制该供应商 API 地址`,variant:`outline`,children:[(0,K.jsx)(w,{className:`size-3.5`}),`复制`]}):null]}),c?(0,K.jsx)(te,{acc:c,busy:i,p:e,onAction:o}):(0,K.jsx)(`div`,{className:`px-5 py-3 text-xs text-muted-foreground`,children:`暂无账号数据`}),s.length?(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-col border-t border-border/60`,children:[(0,K.jsxs)(`div`,{className:r(`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`,X),children:[(0,K.jsx)(`span`,{children:`Key`}),(0,K.jsx)(`span`,{className:`text-center`,children:`用量`}),(0,K.jsx)(`span`,{className:`text-center`,children:`操作`})]}),(0,K.jsx)(`div`,{className:`max-h-[288px] min-h-0 overflow-y-auto overscroll-contain`,children:s.map((t,n)=>(0,K.jsx)(`div`,{className:r(n>0&&`border-t border-border/50`),children:(0,K.jsx)(ne,{a:t,p:e,busy:i,onAction:o})},t.keyId))})]}):(0,K.jsx)(`p`,{className:`border-t border-border/60 px-5 py-3 text-xs text-muted-foreground`,children:`暂无 Keys — 点「添加」录入`}),(0,K.jsx)(ee,{open:l,onOpenChange:u,p:e})]})}function ee({open:e,onOpenChange:r,p:i}){let o=i.accounts??[],c=t(),[l,u]=(0,G.useState)(``),[f,p]=(0,G.useState)(!1),[h,v]=(0,G.useState)(!1),y=i.kind===`proxy`;async function b(){v(!0);try{let e=await T(()=>d.proxyLoginStart());if(!e||e.ok!==!0)return;e.isolated===!1&&a.warning(`默认浏览器不支持隔离窗口:本次登录会带现有登录态,换账号请先在该浏览器退出`,{duration:8e3});let t=await d.proxyLoginWait(e.waitMs??18e4);if(!t.ok||!t.apiKey){a.error(t.error||`登录未完成`);return}await d.proxyAddKey(i.id,t.apiKey),a.success(`已通过登录添加账号 `+(t.userName||t.keyName||``)),r(!1),await g.refresh()}catch(e){a.error(String(e))}finally{v(!1)}}async function w(){let e=l.split(/[,;\s]+/).map(e=>e.trim()).filter(Boolean);if(!e.length){a.error(`请输入至少一个 Key`);return}p(!0);try{if(y)for(let t of e){let e=await d.proxyAddKey(i.id,t);if(e&&e.limited===`credits`){let t=e.account?.limit?.recovery;a.warning(`已添加:该账号额度用尽`+(t?.type===`at`&&t.at?`(预计 ${J(t.at)} 自动恢复)`:`(等待月度重置后自动恢复)`))}}else{let t=await d.providerKeysSet(i.id,{add:e});if(t.ok===!1){a.error(t.error||`添加失败`);return}let n=typeof t.added==`number`?t.added:e.length,o=t.discardedKeys||[];if(o.length){let e=o.slice(0,3).map(e=>`${e.key}(${e.error})`).join(`;`);a.warning(`已添加 ${n} 个,${o.length} 个失败被丢弃:${e}${o.length>3?` …`:``}`)}else a.success(`已添加 `+n+` 个 Key(`+(y?`反代账号`:`API Key`)+`)`);u(``),r(!1),await g.refresh();return}a.success(`已添加 `+e.length+` 个 Key(`+(y?`反代账号`:`API Key`)+`)`),u(``),r(!1),await g.refresh()}catch(e){a.error(String(e))}finally{p(!1)}}async function E(e){if(await c({title:`移除 Key `+e+`?`,description:`该凭据将从供应商中移除,不可恢复。`,confirmText:`移除`,tone:`destructive`})){p(!0);try{if(y){let t=o.find(t=>t.maskedKey===e||e.startsWith(t.maskedKey));t&&await d.proxyRemoveKey(i.id,t.keyId)}else{let t=await d.providerKeysSet(i.id,{removeMasked:[e]});if(t.ok===!1){a.error(t.error||`移除失败`);return}}a.success(`已移除`),r(!1),await g.refresh()}catch(e){a.error(String(e))}finally{p(!1)}}}return(0,K.jsx)(x,{open:e,onOpenChange:r,children:(0,K.jsxs)(C,{className:`max-w-[440px]`,children:[(0,K.jsx)(S,{children:(0,K.jsxs)(s,{children:[`添加 / 管理 Key — `,i.name]})}),(0,K.jsxs)(`div`,{className:`grid gap-3`,children:[y?(0,K.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,K.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`一键登录`}),(0,K.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:`浏览器打开 Command Code 授权,自动添加账号`})]}),(0,K.jsx)(n,{disabled:h||f,onClick:()=>void b(),size:`sm`,children:h?`等待授权…`:`一键登录`})]}):null,(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:[y?`已录入账号(反代)`:`已录入 API Key`,`(`,o.length,`)`]}),o.length?(0,K.jsx)(`div`,{className:`grid max-h-[180px] gap-1 overflow-auto`,children:o.map(e=>(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(`code`,{className:`truncate font-mono text-xs`,children:e.maskedKey}),e.selected?(0,K.jsx)(L,{tone:`ok`,children:`当前`}):null]}),(0,K.jsx)(n,{size:`chip`,variant:`ghost`,className:`text-destructive`,disabled:f,onClick:()=>void E(e.maskedKey),title:`移除该 Key`,children:(0,K.jsx)(A,{className:`size-3.5`})})]},e.keyId))}):(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`尚未录入 `,y?`账号`:`Key`]})]}),(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsxs)(m,{className:`text-xs text-muted-foreground`,children:[`添加 `,y?`账号 Key / Command Code`:`API Key`,`(每行一个,支持逗号/分号分隔)`]}),(0,K.jsx)(_,{className:`h-20 resize-none font-mono text-xs`,placeholder:y?`sk-... 或 Command Code,每行一个`:`sk-... 每行一个`,value:l,onChange:e=>u(e.target.value)})]})]}),(0,K.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,K.jsx)(n,{onClick:()=>r(!1),variant:`outline`,children:`取消`}),(0,K.jsx)(n,{disabled:f||!l.trim(),onClick:()=>void w(),children:f?`保存中…`:`添加`})]})]})})}function te({acc:t,busy:i,p:a,onAction:o}){let s=t.quota,c=!!t.selected,l=!!t.locked,u=s&&s.monthlyRemaining,f=s?.monthly?.percent,p=Number.isFinite(Number(f))?f+`%`:Number.isFinite(Number(u))?`$ `+Number(u).toFixed(2):`—`;return(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-5 py-3`,children:[(0,K.jsxs)(`div`,{className:`grid min-w-[180px] content-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:c?l?`当前账号(锁定)`:`当前在用账号`:`选择账号`}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(P,{className:`max-w-[150px]`,children:t.maskedKey}),c?(0,K.jsxs)(n,{className:`gap-1 px-2`,disabled:i,onClick:()=>o(`refresh`,()=>d.providerRefresh(a.id).then(()=>void 0),`额度已刷新`),size:`chip`,variant:`outline`,children:[(0,K.jsx)(O,{className:r(`size-3`,i&&`animate-spin`)}),`刷新`]}):null]})]}),(0,K.jsxs)(`div`,{className:`grid min-w-0 flex-1 grid-cols-3 items-stretch gap-2`,children:[(0,K.jsx)(R,{icon:(0,K.jsx)(O,{className:`size-3.5`}),label:`5小时`,value:(s?.rolling?.percent??0)+`%`,danger:s?.rolling?.status===`rate-limited`}),(0,K.jsx)(R,{icon:(0,K.jsx)(e,{className:`size-3.5`}),label:`每周`,value:(s?.weekly?.percent??0)+`%`,danger:s?.weekly?.status===`rate-limited`}),(0,K.jsx)(R,{icon:(0,K.jsx)(j,{className:`size-3.5`}),label:`每月`,value:p,danger:s?.monthly?.status===`rate-limited`||Number(s?.monthly?.percent??0)>=100})]})]})}function ne({a:e,p:t,busy:i,onAction:a}){let o=!!e.selected,s=e.instanceStatus===`frozen`?`frozen`:e.status||``,c=e.limit?.kind,l=s===`frozen`||!!c||!o&&q(e.quota),u=c===`credits`?e.limit?.recovery?.type===`at`&&e.limit?.recovery?.at?`额度用尽(预计 ${J(e.limit.recovery.at)} 月度重置后自动恢复)`:`额度用尽(待月度重置后自动恢复)`:c===`window`?e.limit?.reason??`时间窗额度已用尽(到 resetAt 自动恢复)`:c===`banned`?`账号被封禁`:null,f=B(e.requests||0)+` 次 · `+B(e.totalTokens||0)+` tok`,[p,m]=(0,G.useState)(!1),h;return h=l&&!o?(0,K.jsxs)(n,{size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,onClick:()=>m(!0),title:u??`查看该账号限额情况`,children:[(0,K.jsx)(V,{className:`size-3.5`}),`限额`]}):o?(0,K.jsxs)(n,{disabled:i,onClick:()=>a(`refresh`,()=>d.providerRefresh(t.id).then(()=>void 0),`额度已刷新`),size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,children:[(0,K.jsx)(O,{className:r(`size-3.5`,i&&`animate-spin`)}),`刷新`]}):(0,K.jsxs)(n,{disabled:i,size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,onClick:()=>{t.kind===`proxy`?a(`sel`,()=>d.proxySelect(t.id,e.keyId).then(()=>void 0),`已切换账号`):a(`use`,()=>d.providerKeyUse(t.id,e.keyId).then(()=>void 0),`已锁定 Key`)},children:[(0,K.jsx)(U,{className:`size-3.5`}),`切换`]}),(0,K.jsxs)(`div`,{className:r(`grid items-center gap-2 px-5 py-2.5 hover:bg-muted/40`,X,o&&`bg-muted/60 shadow-[inset_3px_0_0_var(--primary)]`),children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(P,{children:e.maskedKey}),s===`registering`?(0,K.jsx)(L,{tone:`off`,children:`检测中…`}):null,s===`banned`?(0,K.jsx)(L,{tone:`err`,children:`封号`}):null,c===`credits`?(0,K.jsx)(`span`,{title:e.limit?.reason??`额度用尽`,children:(0,K.jsx)(L,{tone:`err`,children:`额度用尽`})}):null,c===`window`?(0,K.jsx)(`span`,{title:e.limit?.reason??`时间窗额度已用尽`,children:(0,K.jsx)(L,{tone:`warn`,children:`窗口用尽`})}):null]}),(0,K.jsx)(`span`,{className:`truncate text-right text-xs tabular-nums text-muted-foreground`,title:f,children:f}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:h}),(0,K.jsx)(re,{open:p,onOpenChange:m,a:e,p:t})]})}function re({open:e,onOpenChange:t,a:r,p:i}){let a=r.quota,o=(()=>{let e=a?.monthly?.percent;if(e!=null&&Number.isFinite(Number(e)))return Number(e);let t=Number(a?.credits?.monthlyCredits??a?.monthlyRemaining);return Number.isFinite(t)&&t>=0?Math.min(100,Math.round((10-t)/10*100)):0})(),c=a?.monthly?.status?{...a.monthly,percent:o}:{status:`ok`,percent:o,resetsAt:a?.monthly?.resetsAt},l=(()=>{let e=a?.credits?.monthlyCredits,t=a?.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)})(),u=(e,t,n)=>(0,K.jsxs)(`div`,{className:`grid gap-1 rounded-md border border-border/70 bg-muted/40 px-3 py-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:t}),(0,K.jsx)(L,{tone:e?.status===`rate-limited`||Number(e?.percent)>=100?`err`:`ok`,children:e?.status===`rate-limited`||Number(e?.percent)>=100?`已限额`:`正常`})]}),(0,K.jsxs)(`strong`,{className:`text-xl font-semibold tabular-nums text-foreground`,children:[e?.percent??0,`%`]}),n?(0,K.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:n}):null,e?.resetsAt?(0,K.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,K.jsx)(x,{open:e,onOpenChange:t,children:(0,K.jsxs)(C,{className:`max-w-[420px]`,children:[(0,K.jsx)(S,{children:(0,K.jsx)(s,{children:`限额详情`})}),(0,K.jsxs)(`div`,{className:`grid gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,K.jsx)(`span`,{children:`账号`}),(0,K.jsx)(`code`,{className:`font-mono`,children:r.maskedKey}),(0,K.jsx)(`span`,{className:`ml-auto text-xs`,children:i.name})]}),a?(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[u(a.rolling,`5小时`),u(a.weekly,`每周`),u(c,`每月`),a.credits||a.monthlyRemaining!=null?(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`月度额度(Command)`}),a.credits?.belowThreshold?(0,K.jsx)(L,{tone:`warn`,children:`低于充值线`}):a.credits&&Number.isFinite(Number(a.credits.monthlyCredits))&&Number(a.credits.monthlyCredits)<=0?(0,K.jsx)(L,{tone:`err`,children:`额度用尽`}):(0,K.jsx)(L,{tone:`ok`,children:`正常`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:Number(a.monthlyResetAt)>Date.now()?`月度额度预计 ${J(Number(a.monthlyResetAt))} 重置(随订阅续期)`:`月度额度已于 ${J(Number(a.monthlyResetAt))} 重置`}),l?(0,K.jsx)(`span`,{className:`text-sm font-semibold tabular-nums text-foreground`,children:l}):null]})]}):null]}):(0,K.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`暂无额度数据 — 点「刷新」获取`}),a?(0,K.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`当前用量统计:`,B(r.requests||0),` 次请求 · `,B(r.totalTokens||0),` tokens`,a.monthly?.resetsAt?`。最迟限额将于月窗口重置后自动解除。`:``]}):null]}),(0,K.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,K.jsx)(n,{onClick:()=>t(!1),variant:`outline`,children:`关闭`})})]})})}function ie({open:e,onOpenChange:t,presets:i,proxyApps:o,onDone:c}){let[l,g]=(0,G.useState)(``),[_,y]=(0,G.useState)(``),[w,T]=(0,G.useState)(``),[E,D]=(0,G.useState)(`preset`),[O,k]=(0,G.useState)(!1);async function A(){if(E===`preset`&&!l){a.error(`请选择供应商`);return}if(E===`proxy`&&!_){a.error(`请选择反代应用`);return}k(!0);try{let e=E===`preset`?await d.providerAdd({presetId:l,name:w||void 0,keys:[]}):await d.providerAdd({kind:`proxy`,appId:_,name:w||void 0,keys:[]});if(e.ok===!1){a.error(e.error||`添加失败`);return}a.success(`已添加供应商,请在卡片上点「添加」录入 Key`),t(!1),T(``),g(``),y(``),c()}catch(e){a.error(String(e))}finally{k(!1)}}let j=(i??[]).find(e=>e.id===l);return(0,K.jsx)(x,{open:e,onOpenChange:t,children:(0,K.jsxs)(C,{className:`max-w-[420px]`,children:[(0,K.jsx)(S,{children:(0,K.jsx)(s,{children:`添加供应商`})}),(0,K.jsxs)(`div`,{className:`grid gap-3`,children:[(0,K.jsx)(`div`,{className:`flex gap-1.5 rounded-lg bg-muted p-1`,children:[`preset`,`proxy`].map(e=>(0,K.jsx)(n,{className:r(`flex-1 rounded-md font-medium`,E===e?`bg-card text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-card/60 hover:text-foreground`),onClick:()=>D(e),size:`sm`,variant:`ghost`,children:e===`preset`?`直连预设`:`反代应用`},e))}),E===`preset`?(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsx)(m,{children:`供应商`}),(0,K.jsxs)(h,{value:l,onValueChange:g,children:[(0,K.jsx)(p,{className:`w-full`,children:(0,K.jsx)(v,{placeholder:`-- 选择供应商 --`})}),(0,K.jsx)(b,{children:(i??[]).map(e=>(0,K.jsx)(f,{value:e.id,children:e.name},e.id))})]}),j?.note?(0,K.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:j.note}):null]}):(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsx)(m,{children:`反代应用`}),(0,K.jsxs)(h,{value:_,onValueChange:y,children:[(0,K.jsx)(p,{className:`w-full`,children:(0,K.jsx)(v,{placeholder:`-- 选择应用 --`})}),(0,K.jsx)(b,{children:(o??[]).map(e=>(0,K.jsx)(f,{value:e.id,children:e.name},e.id))})]})]}),(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsx)(m,{children:`供应商名称(可选)`}),(0,K.jsx)(u,{placeholder:`自定义名称,如:Open Code ZEN`,value:w,onChange:e=>T(e.target.value)})]}),(0,K.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:`只添加供应商不填 Key;添加后在供应商卡片上点「添加」录入 API Key。`})]}),(0,K.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,K.jsx)(n,{onClick:()=>t(!1),variant:`outline`,children:`取消`}),(0,K.jsx)(n,{disabled:O,onClick:()=>void A(),children:O?`添加中…`:`添加供应商`})]})]})})}export{Z as RouterPage};
|
|
1
|
+
import{A as e,F as t,I as n,L as r,N as i,O as a,R as o,S as s,U as c,V as l,_ as u,a as d,d as f,f as p,g as m,l as h,n as g,o as _,p as v,t as y,u as b,v as x,x as S,y as C}from"./supervisor-BbSavtNN.js";import{i as w,t as T}from"./openExternal-DOkxrLUq.js";import{n as E,t as D}from"./rocket-CLAmwatt.js";import{t as O}from"./refresh-cw-B-VAKpDt.js";import{t as k}from"./jobs-BjLbfJTM.js";import{c as A,f as j,l as M}from"./supervisor-Btn_MIEc.js";import{t as N}from"./useSupervisorAction-q0YJmhui.js";import{a as P,c as F,i as I,o as L,s as R,t as z}from"./widgets-BbRkZm-Z.js";import{n as B}from"./format-QeaTKFhQ.js";var V=i(`ban`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M4.929 4.929 19.07 19.071`,key:`196cmz`}]]),H=i(`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`}]]),U=i(`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`}]]),W=i(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),G=c(l(),1),K=o();function q(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 J(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 Y(e){return[...e].sort((e,t)=>{let n=e=>e.selected?0:e.usable&&!q(e.quota)?1:2;return n(e)-n(t)})}var X=`grid-cols-[minmax(0,1fr)_230px_84px]`;function Z({onRegisterActions:t}){let{snap:i}=y(),{busy:a,run:o}=N(),[s,c]=(0,G.useState)(!1),[l,u]=(0,G.useState)(!1),f=i.router,p=i.providers;(0,G.useEffect)(()=>(t?.({onAdd:()=>c(!0),onDelete:()=>u(!0)}),()=>t?.(null)),[t]);function m(e,t,n){return o(e,t,{success:n})}let h=p?.providers??[];return(0,K.jsxs)(`div`,{className:`grid content-start gap-4`,children:[(0,K.jsxs)(z,{children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-border/70 px-5 py-3.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(F,{tone:f?.running?`ok`:`off`,ping:!!f?.running}),(0,K.jsx)(`strong`,{className:`text-xl font-semibold tracking-[-0.01em] text-foreground`,children:f?.running?`路由运行中`:`路由已停止`})]}),(0,K.jsx)(n,{"aria-label":f?.running?`停止路由`:`启动路由`,className:r(`px-1`,f?.running?`text-status-error`:`text-primary`),disabled:a===`sw`,onClick:()=>void m(`sw`,()=>f?.running?d.lifecycleStop(`router`):d.lifecycleStart(`router`),f?.running?`路由已停止`:`路由已启动`),title:f?.running?`停止路由`:`启动路由`,variant:`ghost`,children:f?.running?(0,K.jsx)(E,{className:`size-6`}):(0,K.jsx)(D,{className:`size-6`})})]}),(0,K.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,K.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,K.jsx)(I,{icon:(0,K.jsx)(j,{className:`size-4`}),label:`总请求 / 失败`,value:B(f?.usage?.requests)+` / `+B(f?.usage?.errors),mono:!0})}),(0,K.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,K.jsx)(I,{icon:(0,K.jsx)(e,{className:`size-4`}),label:`总 Tokens`,value:B(f?.usage?.totalTokens),mono:!0})}),(0,K.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,K.jsx)(I,{icon:(0,K.jsx)(W,{className:`size-4`}),label:`Prompt / Completion`,value:B(f?.usage?.promptTokens)+` / `+B(f?.usage?.completionTokens),mono:!0})}),(0,K.jsx)(`div`,{className:`px-5 py-3.5`,children:(0,K.jsx)(I,{icon:(0,K.jsx)(H,{className:`size-4`}),label:`估算费用`,value:f?.usage?.costUsd?`$`+Number(f.usage.costUsd).toFixed(4):`—`,mono:!0,warn:!f?.usage?.costUsd})})]})]}),h.length?(0,K.jsx)(`div`,{className:`grid gap-4 @min-[900px]:grid-cols-2`,children:h.map(e=>(0,K.jsx)($,{p:e,proxyApps:p?.proxyApps??[],busy:a===e.id,onAction:m},e.id))}):(0,K.jsx)(`div`,{className:`grid min-h-[200px] place-items-center rounded-lg border border-dashed border-border text-center`,children:(0,K.jsxs)(`div`,{children:[(0,K.jsx)(j,{className:`mx-auto mb-3 size-8 text-muted-foreground`}),(0,K.jsx)(`p`,{className:`text-sm font-medium text-foreground`,children:`尚未添加供应商`}),(0,K.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`点击「添加供应商」录入 API Key / Command Code`})]})}),(0,K.jsx)(ie,{open:s,onOpenChange:c,presets:p?.presets??[],proxyApps:p?.proxyApps??[],onDone:()=>g.refresh()}),(0,K.jsx)(Q,{open:l,onOpenChange:u,providers:h})]})}function Q({open:e,onOpenChange:r,providers:i}){let[o,c]=(0,G.useState)(null),l=t();async function u(e){if(await l({title:`删除供应商「`+e.name+`」?`,description:`其下全部账号与 Key 将被移除,不可恢复。`,confirmText:`删除`,tone:`destructive`})){c(e.id);try{await d.providerRemove(e.id),a.success(`已删除供应商「`+e.name+`」`),await g.refresh()}catch(e){a.error(String(e))}finally{c(null)}}}return(0,K.jsx)(x,{open:e,onOpenChange:r,children:(0,K.jsxs)(C,{className:`max-w-[440px]`,children:[(0,K.jsx)(S,{children:(0,K.jsx)(s,{children:`删除供应商`})}),(0,K.jsx)(`div`,{className:`grid gap-1.5`,children:i.length?i.map(e=>(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`strong`,{className:`truncate text-sm font-medium text-foreground`,children:e.name}),(0,K.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[e.kind===`proxy`?`反代`:`直连`,` · `,(e.accounts??[]).length,` 账号`]})]}),(0,K.jsxs)(n,{disabled:o===e.id,onClick:()=>void u(e),size:`chip`,variant:`destructive`,children:[o===e.id?(0,K.jsx)(O,{className:`size-3 animate-spin`}):(0,K.jsx)(A,{className:`size-3`}),`删除`]})]},e.id)):(0,K.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:`暂无供应商`})}),(0,K.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,K.jsx)(n,{onClick:()=>r(!1),variant:`outline`,children:`关闭`})})]})})}function $({p:e,proxyApps:t,busy:i,onAction:o}){let s=Y(e.accounts??[]),c=s.find(e=>e.selected)||s.find(e=>e.usable&&!q(e.quota))||s[0],[l,u]=(0,G.useState)(!1),f=e.kind===`proxy`?(t??[]).find(t=>t.id===e.proxyAppId)??null:null,p=e.apiBase||(e.apiPort?`http://127.0.0.1:`+e.apiPort+`/v1`:null);return(0,K.jsxs)(z,{className:`flex min-h-0 flex-col overflow-hidden`,children:[(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`strong`,{className:`truncate text-sm font-semibold text-foreground`,children:e.name}),e.kind===`proxy`&&f&&f.installed?f.updateAvailable?(0,K.jsxs)(n,{className:`gap-1 rounded-full px-2.5 text-xs text-warning`,disabled:i,onClick:()=>void o(`proxy-upd-`+e.id,async()=>{let t=e.proxyAppId,n=await d.proxyUpdateApply(t);if(n.ok===!1){a.error(n.error||`提交失败`);return}let r=a.loading(`正在更新 `+e.name+` 的全部实例…`),i=await k(()=>d.proxyUpdateStatus(t),{onTick:t=>{let n=t?.steps||[],i=n.filter(e=>e.state===`done`).length;n.length&&a.loading(`正在更新 `+e.name+`…(`+i+`/`+n.length+` 实例)`,{id:r})}}),o=i.snapshot;i.state===`done`?a.success(`更新完成`+(o?.restarted?`(已重启 `+o.restarted+` 个实例)`:``),{id:r}):i.state===`failed`?a.error(`更新失败:`+(i.error||(o?.errors?o.errors+` 个实例失败`:`未知原因`)),{id:r}):a.warning(`更新仍在进行(超时未完成,可稍后查看)`,{id:r}),await g.refresh()},void 0),size:`chip`,title:`检测到新版本,点击更新该应用全部实例`,variant:`outline`,children:[(0,K.jsx)(O,{className:`size-3`}),`更新 v`,f.latest]}):(0,K.jsxs)(n,{className:`gap-1 rounded-full px-2.5 text-xs font-mono text-muted-foreground`,disabled:i,onClick:()=>{o(`proxy-chk-`+e.id,async()=>{let t=await d.proxyUpdateCheck();if(await g.refresh(),!t.ok){a.error(t.error||`版本检测失败`);return}let n=t.versions?.[e.proxyAppId||``]||null,r=f.installed;a.info(n&&n!==r?`发现新版本 v`+n+`,点击版本胶囊更新`:`已是最新版本 v`+r)},void 0)},size:`chip`,title:`检测是否有新版本`,variant:`outline`,children:[`v`,f.installed,(0,K.jsx)(O,{className:r(`size-3`,i&&`animate-spin`)})]}):null]}),(0,K.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1.5`,children:[(0,K.jsxs)(n,{disabled:i,onClick:()=>u(!0),size:`sm`,variant:`outline`,children:[(0,K.jsx)(M,{className:`size-3.5`}),`添加`]}),e.activated?(0,K.jsxs)(n,{disabled:i,onClick:()=>void o(`deact`,()=>d.providerDeactivate(e.id).then(()=>void 0),`已停用供应商(资源已回收)`),size:`sm`,variant:`outline`,children:[(0,K.jsx)(E,{className:`size-3.5`}),`停用`]}):(0,K.jsxs)(n,{disabled:i,onClick:()=>void o(`act`,()=>d.providerActivate(e.id).then(()=>void 0),`已启用供应商`),size:`sm`,variant:`outline`,children:[(0,K.jsx)(D,{className:`size-3.5`}),`启用`]})]})]}),(0,K.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-border/60 px-5 py-2.5`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`API 地址`}),(0,K.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:e.activated&&p?(0,K.jsx)(`code`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-foreground`,children:p}):(0,K.jsx)(`span`,{className:`truncate text-xs text-muted-foreground/70`,children:`服务未启用`})}),e.activated&&p?(0,K.jsxs)(n,{onClick:()=>void navigator.clipboard.writeText(p||``).then(()=>a.success(`已复制 API 地址`)),size:`sm`,title:`复制该供应商 API 地址`,variant:`outline`,children:[(0,K.jsx)(w,{className:`size-3.5`}),`复制`]}):null]}),c?(0,K.jsx)(te,{acc:c,busy:i,p:e,onAction:o}):(0,K.jsx)(`div`,{className:`px-5 py-3 text-xs text-muted-foreground`,children:`暂无账号数据`}),s.length?(0,K.jsxs)(`div`,{className:`flex min-h-0 flex-col border-t border-border/60`,children:[(0,K.jsxs)(`div`,{className:r(`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`,X),children:[(0,K.jsx)(`span`,{children:`Key`}),(0,K.jsx)(`span`,{className:`text-center`,children:`用量`}),(0,K.jsx)(`span`,{className:`text-center`,children:`操作`})]}),(0,K.jsx)(`div`,{className:`max-h-[288px] min-h-0 overflow-y-auto overscroll-contain`,children:s.map((t,n)=>(0,K.jsx)(`div`,{className:r(n>0&&`border-t border-border/50`),children:(0,K.jsx)(ne,{a:t,p:e,busy:i,onAction:o})},t.keyId))})]}):(0,K.jsx)(`p`,{className:`border-t border-border/60 px-5 py-3 text-xs text-muted-foreground`,children:`暂无 Keys — 点「添加」录入`}),(0,K.jsx)(ee,{open:l,onOpenChange:u,p:e})]})}function ee({open:e,onOpenChange:r,p:i}){let o=i.accounts??[],c=t(),[l,u]=(0,G.useState)(``),[f,p]=(0,G.useState)(!1),[h,v]=(0,G.useState)(!1),y=i.kind===`proxy`;async function b(){v(!0);try{let e=await T(()=>d.proxyLoginStart());if(!e||e.ok!==!0)return;e.isolated===!1&&a.warning(`默认浏览器不支持隔离窗口:本次登录会带现有登录态,换账号请先在该浏览器退出`,{duration:8e3});let t=await d.proxyLoginWait(e.waitMs??18e4);if(!t.ok||!t.apiKey){a.error(t.error||`登录未完成`);return}await d.proxyAddKey(i.id,t.apiKey),a.success(`已通过登录添加账号 `+(t.userName||t.keyName||``)),r(!1),await g.refresh()}catch(e){a.error(String(e))}finally{v(!1)}}async function w(){let e=l.split(/[,;\s]+/).map(e=>e.trim()).filter(Boolean);if(!e.length){a.error(`请输入至少一个 Key`);return}p(!0);try{if(y)for(let t of e){let e=await d.proxyAddKey(i.id,t);if(e&&e.limited===`credits`){let t=e.account?.limit?.recovery;a.warning(`已添加:该账号额度用尽`+(t?.type===`at`&&t.at?`(预计 ${J(t.at)} 自动恢复)`:`(等待月度重置后自动恢复)`))}}else{let t=await d.providerKeysSet(i.id,{add:e});if(t.ok===!1){a.error(t.error||`添加失败`);return}let n=typeof t.added==`number`?t.added:e.length,o=t.discardedKeys||[];if(o.length){let e=o.slice(0,3).map(e=>`${e.key}(${e.error})`).join(`;`);a.warning(`已添加 ${n} 个,${o.length} 个失败被丢弃:${e}${o.length>3?` …`:``}`)}else a.success(`已添加 `+n+` 个 Key(`+(y?`反代账号`:`API Key`)+`)`);u(``),r(!1),await g.refresh();return}a.success(`已添加 `+e.length+` 个 Key(`+(y?`反代账号`:`API Key`)+`)`),u(``),r(!1),await g.refresh()}catch(e){a.error(String(e))}finally{p(!1)}}async function E(e){if(await c({title:`移除 Key `+e+`?`,description:`该凭据将从供应商中移除,不可恢复。`,confirmText:`移除`,tone:`destructive`})){p(!0);try{if(y){let t=o.find(t=>t.maskedKey===e||e.startsWith(t.maskedKey));t&&await d.proxyRemoveKey(i.id,t.keyId)}else{let t=await d.providerKeysSet(i.id,{removeMasked:[e]});if(t.ok===!1){a.error(t.error||`移除失败`);return}}a.success(`已移除`),r(!1),await g.refresh()}catch(e){a.error(String(e))}finally{p(!1)}}}return(0,K.jsx)(x,{open:e,onOpenChange:r,children:(0,K.jsxs)(C,{className:`max-w-[440px]`,children:[(0,K.jsx)(S,{children:(0,K.jsxs)(s,{children:[`添加 / 管理 Key — `,i.name]})}),(0,K.jsxs)(`div`,{className:`grid gap-3`,children:[y?(0,K.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,K.jsxs)(`div`,{className:`grid gap-0.5`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`一键登录`}),(0,K.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:`浏览器打开 Command Code 授权,自动添加账号`})]}),(0,K.jsx)(n,{disabled:h||f,onClick:()=>void b(),size:`sm`,children:h?`等待授权…`:`一键登录`})]}):null,(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsxs)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:[y?`已录入账号(反代)`:`已录入 API Key`,`(`,o.length,`)`]}),o.length?(0,K.jsx)(`div`,{className:`grid max-h-[180px] gap-1 overflow-auto`,children:o.map(e=>(0,K.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,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(`code`,{className:`truncate font-mono text-xs`,children:e.maskedKey}),e.selected?(0,K.jsx)(L,{tone:`ok`,children:`当前`}):null]}),(0,K.jsx)(n,{size:`chip`,variant:`ghost`,className:`text-destructive`,disabled:f,onClick:()=>void E(e.maskedKey),title:`移除该 Key`,children:(0,K.jsx)(A,{className:`size-3.5`})})]},e.keyId))}):(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`尚未录入 `,y?`账号`:`Key`]})]}),(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsxs)(m,{className:`text-xs text-muted-foreground`,children:[`添加 `,y?`账号 Key / Command Code`:`API Key`,`(每行一个,支持逗号/分号分隔)`]}),(0,K.jsx)(_,{className:`h-20 resize-none font-mono text-xs`,placeholder:y?`sk-... 或 Command Code,每行一个`:`sk-... 每行一个`,value:l,onChange:e=>u(e.target.value)})]})]}),(0,K.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,K.jsx)(n,{onClick:()=>r(!1),variant:`outline`,children:`取消`}),(0,K.jsx)(n,{disabled:f||!l.trim(),onClick:()=>void w(),children:f?`保存中…`:`添加`})]})]})})}function te({acc:t,busy:i,p:a,onAction:o}){let s=t.quota,c=!!t.selected,l=!!t.locked,u=s&&s.monthlyRemaining,f=s?.monthly?.percent,p=Number.isFinite(Number(f))?f+`%`:Number.isFinite(Number(u))?`$ `+Number(u).toFixed(2):`—`;return(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-4 px-5 py-3`,children:[(0,K.jsxs)(`div`,{className:`grid min-w-[180px] content-center gap-1`,children:[(0,K.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:c?l?`当前账号(锁定)`:`当前在用账号`:`选择账号`}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(P,{className:`max-w-[150px]`,children:t.maskedKey}),c?(0,K.jsxs)(n,{className:`gap-1 px-2`,disabled:i,onClick:()=>o(`refresh`,()=>d.providerRefresh(a.id).then(()=>void 0),`额度已刷新`),size:`chip`,variant:`outline`,children:[(0,K.jsx)(O,{className:r(`size-3`,i&&`animate-spin`)}),`刷新`]}):null]})]}),(0,K.jsxs)(`div`,{className:`grid min-w-0 flex-1 grid-cols-3 items-stretch gap-2`,children:[(0,K.jsx)(R,{icon:(0,K.jsx)(O,{className:`size-3.5`}),label:`5小时`,value:(s?.rolling?.percent??0)+`%`,danger:s?.rolling?.status===`rate-limited`}),(0,K.jsx)(R,{icon:(0,K.jsx)(e,{className:`size-3.5`}),label:`每周`,value:(s?.weekly?.percent??0)+`%`,danger:s?.weekly?.status===`rate-limited`}),(0,K.jsx)(R,{icon:(0,K.jsx)(j,{className:`size-3.5`}),label:`每月`,value:p,danger:s?.monthly?.status===`rate-limited`||Number(s?.monthly?.percent??0)>=100})]})]})}function ne({a:e,p:t,busy:i,onAction:a}){let o=!!e.selected,s=e.instanceStatus===`frozen`?`frozen`:e.status||``,c=e.limit?.kind,l=s===`frozen`||!!c||!o&&q(e.quota),u=c===`credits`?e.limit?.recovery?.type===`at`&&e.limit?.recovery?.at?`额度用尽(预计 ${J(e.limit.recovery.at)} 月度重置后自动恢复)`:`额度用尽(待月度重置后自动恢复)`:c===`window`?e.limit?.reason??`时间窗额度已用尽(到 resetAt 自动恢复)`:c===`banned`?`账号被封禁`:null,f=B(e.requests||0)+` 次 · `+B(e.totalTokens||0)+` tok`,[p,m]=(0,G.useState)(!1),h;return h=l&&!o?(0,K.jsxs)(n,{size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,onClick:()=>m(!0),title:u??`查看该账号限额情况`,children:[(0,K.jsx)(V,{className:`size-3.5`}),`限额`]}):o?(0,K.jsxs)(n,{disabled:i,onClick:()=>a(`refresh`,()=>d.providerRefresh(t.id).then(()=>void 0),`额度已刷新`),size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,children:[(0,K.jsx)(O,{className:r(`size-3.5`,i&&`animate-spin`)}),`刷新`]}):(0,K.jsxs)(n,{disabled:i,size:`chip`,variant:`outline`,className:`w-[70px] gap-1 px-1.5`,onClick:()=>{t.kind===`proxy`?a(`sel`,()=>d.proxySelect(t.id,e.keyId).then(()=>void 0),`已切换账号`):a(`use`,()=>d.providerKeyUse(t.id,e.keyId).then(()=>void 0),`已锁定 Key`)},children:[(0,K.jsx)(U,{className:`size-3.5`}),`切换`]}),(0,K.jsxs)(`div`,{className:r(`grid items-center gap-2 px-5 py-2.5 hover:bg-muted/40`,X,o&&`bg-muted/60 shadow-[inset_3px_0_0_var(--primary)]`),children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(P,{children:e.maskedKey}),s===`registering`?(0,K.jsx)(L,{tone:`off`,children:`检测中…`}):null,s===`banned`?(0,K.jsx)(L,{tone:`err`,children:`封号`}):null,c===`credits`?(0,K.jsx)(`span`,{title:e.limit?.reason??`额度用尽`,children:(0,K.jsx)(L,{tone:`err`,children:`额度用尽`})}):null,c===`window`?(0,K.jsx)(`span`,{title:e.limit?.reason??`时间窗额度已用尽`,children:(0,K.jsx)(L,{tone:`warn`,children:`窗口用尽`})}):null]}),(0,K.jsx)(`span`,{className:`truncate text-right text-xs tabular-nums text-muted-foreground`,title:f,children:f}),(0,K.jsx)(`div`,{className:`flex justify-end`,children:h}),(0,K.jsx)(re,{open:p,onOpenChange:m,a:e,p:t})]})}function re({open:e,onOpenChange:t,a:r,p:i}){let a=r.quota,o=(()=>{let e=a?.monthly?.percent;if(e!=null&&Number.isFinite(Number(e)))return Number(e);let t=Number(a?.credits?.monthlyCredits??a?.monthlyRemaining);return Number.isFinite(t)&&t>=0?Math.min(100,Math.round((10-t)/10*100)):0})(),c=a?.monthly?.status?{...a.monthly,percent:o}:{status:`ok`,percent:o,resetsAt:a?.monthly?.resetsAt},l=(()=>{let e=a?.credits?.monthlyCredits,t=a?.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)})(),u=(e,t,n)=>(0,K.jsxs)(`div`,{className:`grid gap-1 rounded-md border border-border/70 bg-muted/40 px-3 py-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:t}),(0,K.jsx)(L,{tone:e?.status===`rate-limited`||Number(e?.percent)>=100?`err`:`ok`,children:e?.status===`rate-limited`||Number(e?.percent)>=100?`已限额`:`正常`})]}),(0,K.jsxs)(`strong`,{className:`text-xl font-semibold tabular-nums text-foreground`,children:[e?.percent??0,`%`]}),n?(0,K.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:n}):null,e?.resetsAt?(0,K.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,K.jsx)(x,{open:e,onOpenChange:t,children:(0,K.jsxs)(C,{className:`max-w-[420px]`,children:[(0,K.jsx)(S,{children:(0,K.jsx)(s,{children:`限额详情`})}),(0,K.jsxs)(`div`,{className:`grid gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,K.jsx)(`span`,{children:`账号`}),(0,K.jsx)(`code`,{className:`font-mono`,children:r.maskedKey}),(0,K.jsx)(`span`,{className:`ml-auto text-xs`,children:i.name})]}),a?(0,K.jsxs)(`div`,{className:`grid grid-cols-3 gap-2`,children:[u(a.rolling,`5小时`),u(a.weekly,`每周`),u(c,`每月`),a.credits||a.monthlyRemaining!=null?(0,K.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,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-foreground`,children:`月度额度(Command)`}),a.credits?.belowThreshold?(0,K.jsx)(L,{tone:`warn`,children:`低于充值线`}):a.credits&&Number.isFinite(Number(a.credits.monthlyCredits))&&Number(a.credits.monthlyCredits)<=0?(0,K.jsx)(L,{tone:`err`,children:`额度用尽`}):(0,K.jsx)(L,{tone:`ok`,children:`正常`})]}),(0,K.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,K.jsx)(`span`,{className:`text-[11px] leading-tight text-muted-foreground`,children:Number(a.monthlyResetAt)>Date.now()?`月度额度预计 ${J(Number(a.monthlyResetAt))} 重置(随订阅续期)`:`月度额度已于 ${J(Number(a.monthlyResetAt))} 重置`}),l?(0,K.jsx)(`span`,{className:`text-sm font-semibold tabular-nums text-foreground`,children:l}):null]})]}):null]}):(0,K.jsx)(`p`,{className:`py-6 text-center text-sm text-muted-foreground`,children:`暂无额度数据 — 点「刷新」获取`}),a?(0,K.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`当前用量统计:`,B(r.requests||0),` 次请求 · `,B(r.totalTokens||0),` tokens`,a.monthly?.resetsAt?`。最迟限额将于月窗口重置后自动解除。`:``]}):null]}),(0,K.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,K.jsx)(n,{onClick:()=>t(!1),variant:`outline`,children:`关闭`})})]})})}function ie({open:e,onOpenChange:t,presets:i,proxyApps:o,onDone:c}){let[l,g]=(0,G.useState)(``),[_,y]=(0,G.useState)(``),[w,T]=(0,G.useState)(``),[E,D]=(0,G.useState)(`preset`),[O,k]=(0,G.useState)(!1);async function A(){if(E===`preset`&&!l){a.error(`请选择供应商`);return}if(E===`proxy`&&!_){a.error(`请选择反代应用`);return}k(!0);try{let e=E===`preset`?await d.providerAdd({presetId:l,name:w||void 0,keys:[]}):await d.providerAdd({kind:`proxy`,appId:_,name:w||void 0,keys:[]});if(e.ok===!1){a.error(e.error||`添加失败`);return}a.success(`已添加供应商,请在卡片上点「添加」录入 Key`),t(!1),T(``),g(``),y(``),c()}catch(e){a.error(String(e))}finally{k(!1)}}let j=(i??[]).find(e=>e.id===l);return(0,K.jsx)(x,{open:e,onOpenChange:t,children:(0,K.jsxs)(C,{className:`max-w-[420px]`,children:[(0,K.jsx)(S,{children:(0,K.jsx)(s,{children:`添加供应商`})}),(0,K.jsxs)(`div`,{className:`grid gap-3`,children:[(0,K.jsx)(`div`,{className:`flex gap-1.5 rounded-lg bg-muted p-1`,children:[`preset`,`proxy`].map(e=>(0,K.jsx)(n,{className:r(`flex-1 rounded-md font-medium`,E===e?`bg-card text-foreground shadow-sm`:`bg-transparent text-muted-foreground hover:bg-card/60 hover:text-foreground`),onClick:()=>D(e),size:`sm`,variant:`ghost`,children:e===`preset`?`直连预设`:`反代应用`},e))}),E===`preset`?(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsx)(m,{children:`供应商`}),(0,K.jsxs)(h,{value:l,onValueChange:g,children:[(0,K.jsx)(p,{className:`w-full`,children:(0,K.jsx)(v,{placeholder:`-- 选择供应商 --`})}),(0,K.jsx)(b,{children:(i??[]).map(e=>(0,K.jsx)(f,{value:e.id,children:e.name},e.id))})]}),j?.note?(0,K.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:j.note}):null]}):(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsx)(m,{children:`反代应用`}),(0,K.jsxs)(h,{value:_,onValueChange:y,children:[(0,K.jsx)(p,{className:`w-full`,children:(0,K.jsx)(v,{placeholder:`-- 选择应用 --`})}),(0,K.jsx)(b,{children:(o??[]).map(e=>(0,K.jsx)(f,{value:e.id,children:e.name},e.id))})]})]}),(0,K.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,K.jsx)(m,{children:`供应商名称(可选)`}),(0,K.jsx)(u,{placeholder:`自定义名称,如:Open Code ZEN`,value:w,onChange:e=>T(e.target.value)})]}),(0,K.jsx)(`p`,{className:`text-xs leading-relaxed text-muted-foreground`,children:`只添加供应商不填 Key;添加后在供应商卡片上点「添加」录入 API Key。`})]}),(0,K.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,K.jsx)(n,{onClick:()=>t(!1),variant:`outline`,children:`取消`}),(0,K.jsx)(n,{disabled:O,onClick:()=>void A(),children:O?`添加中…`:`添加供应商`})]})]})})}export{Z as RouterPage};
|