@zqagent/core 0.2.12 → 0.2.14
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/dist/cli/index.cjs +441 -184
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +441 -184
- package/dist/cli/index.js.map +1 -1
- package/dist/server/index.cjs +105 -16
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +105 -16
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -11413,7 +11413,7 @@ function buildNodeInfo(store, opts) {
|
|
|
11413
11413
|
nodeId: opts.nodeId ?? ensureNodeId(store),
|
|
11414
11414
|
platform: process.platform,
|
|
11415
11415
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
11416
|
-
version: "0.2.
|
|
11416
|
+
version: "0.2.14",
|
|
11417
11417
|
admin: opts.admin,
|
|
11418
11418
|
projects: opts.projects
|
|
11419
11419
|
};
|
|
@@ -12406,7 +12406,7 @@ function buildNodeHost(store, manager, diskPath) {
|
|
|
12406
12406
|
arch: process.arch,
|
|
12407
12407
|
release: os6.release(),
|
|
12408
12408
|
uptimeSec: Math.round(os6.uptime()),
|
|
12409
|
-
version: "0.2.
|
|
12409
|
+
version: "0.2.14",
|
|
12410
12410
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
12411
12411
|
cpu: {
|
|
12412
12412
|
count: cpus2.length,
|
|
@@ -12776,6 +12776,24 @@ function createApp(store, manager, opts = {}) {
|
|
|
12776
12776
|
ok(res, opts.fleet.status());
|
|
12777
12777
|
}
|
|
12778
12778
|
},
|
|
12779
|
+
// 修改本机节点显示名:写本地配置并立即上报;已接入 Hub 时同步 Hub 记录。
|
|
12780
|
+
// `zqagent rename` 在有 server 在跑时走这里(热生效,免重启)。
|
|
12781
|
+
{
|
|
12782
|
+
method: "POST",
|
|
12783
|
+
pattern: ["fleet", "label"],
|
|
12784
|
+
adminOnly: true,
|
|
12785
|
+
fn: async (_req, res, { body }) => {
|
|
12786
|
+
if (!opts.fleet) {
|
|
12787
|
+
throw new ApiError(503, "fleet_disabled", "\u8282\u70B9\u7BA1\u7406\u63A7\u5236\u5668\u672A\u542F\u7528");
|
|
12788
|
+
}
|
|
12789
|
+
const raw = body ?? {};
|
|
12790
|
+
const label2 = typeof raw.label === "string" ? raw.label.trim() : "";
|
|
12791
|
+
if (!label2) {
|
|
12792
|
+
throw new ApiError(400, "bad_request", "label \u4E0D\u80FD\u4E3A\u7A7A");
|
|
12793
|
+
}
|
|
12794
|
+
ok(res, await opts.fleet.rename(label2));
|
|
12795
|
+
}
|
|
12796
|
+
},
|
|
12779
12797
|
// 运行时热接入:凭一次性注册码或 Hub 账号接入(落盘 fleet.json + 立即连接,免重启)
|
|
12780
12798
|
{
|
|
12781
12799
|
method: "POST",
|
|
@@ -13995,7 +14013,7 @@ function createApp(store, manager, opts = {}) {
|
|
|
13995
14013
|
json(res, 200, {
|
|
13996
14014
|
status: "ok",
|
|
13997
14015
|
// 版本让运维/探针能确认线上跑的是哪个构建(更新与回滚据此判断)
|
|
13998
|
-
version: "0.2.
|
|
14016
|
+
version: "0.2.14",
|
|
13999
14017
|
features: { mcp: hasServerMcpConfig() }
|
|
14000
14018
|
});
|
|
14001
14019
|
return;
|
|
@@ -15689,6 +15707,11 @@ var FleetNodeBridge = class {
|
|
|
15689
15707
|
refreshInfo() {
|
|
15690
15708
|
this._publishInfo();
|
|
15691
15709
|
}
|
|
15710
|
+
/** 本地改名后把 status(含 label)与 info 立即重发,控制台不必等下一次周期上报 */
|
|
15711
|
+
republishLabel() {
|
|
15712
|
+
this._send({ kind: "status", status: this._status(this.isConnected()) });
|
|
15713
|
+
this._publishInfo();
|
|
15714
|
+
}
|
|
15692
15715
|
// ===================== 内部 =====================
|
|
15693
15716
|
_status(online) {
|
|
15694
15717
|
return {
|
|
@@ -15698,7 +15721,7 @@ var FleetNodeBridge = class {
|
|
|
15698
15721
|
label: this.opts.deps.store.loadNodeLabel() ?? void 0,
|
|
15699
15722
|
platform: process.platform,
|
|
15700
15723
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
15701
|
-
version: "0.2.
|
|
15724
|
+
version: "0.2.14",
|
|
15702
15725
|
ip: primaryIp()
|
|
15703
15726
|
};
|
|
15704
15727
|
}
|
|
@@ -15717,7 +15740,23 @@ var FleetNodeBridge = class {
|
|
|
15717
15740
|
byDay: days
|
|
15718
15741
|
};
|
|
15719
15742
|
}
|
|
15743
|
+
/**
|
|
15744
|
+
* 上报 info(项目/会话快照)。
|
|
15745
|
+
*
|
|
15746
|
+
* 失败必须留痕:这是控制台「项目列表」的唯一数据源,静默失败会表现为
|
|
15747
|
+
* 「这台节点永远没有任何项目」,且只能靠网关 detail=null 才发现。
|
|
15748
|
+
* 同时用 try 包住,避免一次读盘异常中断 `_onUp` 后续的状态通知。
|
|
15749
|
+
*/
|
|
15720
15750
|
_publishInfo() {
|
|
15751
|
+
try {
|
|
15752
|
+
this._publishInfoNow();
|
|
15753
|
+
} catch (e) {
|
|
15754
|
+
console.warn(
|
|
15755
|
+
`[fleet] \u8282\u70B9 ${this.nodeId} \u4E0A\u62A5 info \u5931\u8D25: ${e instanceof Error ? e.message : String(e)}`
|
|
15756
|
+
);
|
|
15757
|
+
}
|
|
15758
|
+
}
|
|
15759
|
+
_publishInfoNow() {
|
|
15721
15760
|
const totals = { projects: 0, sessions: 0, running: 0, waiting: 0 };
|
|
15722
15761
|
const sessions = [];
|
|
15723
15762
|
const projects = allProjectSummaries(this.opts.deps.store).map((p) => {
|
|
@@ -15744,7 +15783,15 @@ var FleetNodeBridge = class {
|
|
|
15744
15783
|
totals.sessions += p.sessionCount;
|
|
15745
15784
|
totals.running += running;
|
|
15746
15785
|
totals.waiting += waiting;
|
|
15747
|
-
return {
|
|
15786
|
+
return {
|
|
15787
|
+
id: p.id,
|
|
15788
|
+
name: p.name,
|
|
15789
|
+
sessionCount: p.sessionCount,
|
|
15790
|
+
running,
|
|
15791
|
+
waiting,
|
|
15792
|
+
// 控制台项目列表要展示工作目录(Hub 落盘快照后即可离线查看)
|
|
15793
|
+
workspaceRoot: p.workspaceRoot ?? null
|
|
15794
|
+
};
|
|
15748
15795
|
});
|
|
15749
15796
|
this._send({
|
|
15750
15797
|
kind: "info",
|
|
@@ -15753,7 +15800,7 @@ var FleetNodeBridge = class {
|
|
|
15753
15800
|
label: this.opts.deps.store.loadNodeLabel() ?? void 0,
|
|
15754
15801
|
platform: process.platform,
|
|
15755
15802
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
15756
|
-
version: "0.2.
|
|
15803
|
+
version: "0.2.14",
|
|
15757
15804
|
ip: primaryIp(),
|
|
15758
15805
|
projects,
|
|
15759
15806
|
totals,
|
|
@@ -15963,6 +16010,14 @@ function resolveFleetConfig(store) {
|
|
|
15963
16010
|
return fleetConfigFromEnv(store);
|
|
15964
16011
|
}
|
|
15965
16012
|
|
|
16013
|
+
// src/node-name.ts
|
|
16014
|
+
init_cjs_shims();
|
|
16015
|
+
var os8 = __toESM(require("os"), 1);
|
|
16016
|
+
function defaultNodeLabel() {
|
|
16017
|
+
const name = os8.hostname().trim();
|
|
16018
|
+
return name || "zqagent-node";
|
|
16019
|
+
}
|
|
16020
|
+
|
|
15966
16021
|
// src/server/notify/index.ts
|
|
15967
16022
|
init_cjs_shims();
|
|
15968
16023
|
|
|
@@ -17213,6 +17268,12 @@ async function hubEnrollByAccount(baseUrl, input) {
|
|
|
17213
17268
|
});
|
|
17214
17269
|
return { hubUrl: baseUrl.replace(/\/$/, ""), ...data };
|
|
17215
17270
|
}
|
|
17271
|
+
async function hubUpdateNodeLabelSelf(baseUrl, fleetToken, input) {
|
|
17272
|
+
return await req(baseUrl, fleetToken, "/api/hub/nodes/self/label", {
|
|
17273
|
+
method: "POST",
|
|
17274
|
+
body: JSON.stringify(input)
|
|
17275
|
+
});
|
|
17276
|
+
}
|
|
17216
17277
|
|
|
17217
17278
|
// src/update/controller.ts
|
|
17218
17279
|
init_cjs_shims();
|
|
@@ -17472,12 +17533,12 @@ function selfCheck(binPath, expectedVersion) {
|
|
|
17472
17533
|
// src/update/platform.ts
|
|
17473
17534
|
init_cjs_shims();
|
|
17474
17535
|
var fs25 = __toESM(require("fs"), 1);
|
|
17475
|
-
var
|
|
17536
|
+
var os9 = __toESM(require("os"), 1);
|
|
17476
17537
|
var path29 = __toESM(require("path"), 1);
|
|
17477
17538
|
var import_node_child_process5 = require("child_process");
|
|
17478
17539
|
var import_node_module3 = require("module");
|
|
17479
17540
|
function currentVersion() {
|
|
17480
|
-
const injected = "0.2.
|
|
17541
|
+
const injected = "0.2.14"?.trim();
|
|
17481
17542
|
if (injected) return injected;
|
|
17482
17543
|
try {
|
|
17483
17544
|
const req2 = (0, import_node_module3.createRequire)(importMetaUrl);
|
|
@@ -17515,7 +17576,7 @@ function launchdPlistPath() {
|
|
|
17515
17576
|
const label2 = launchdLabel();
|
|
17516
17577
|
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
17517
17578
|
if (uid === 0) return `/Library/LaunchDaemons/${label2}.plist`;
|
|
17518
|
-
return path29.join(
|
|
17579
|
+
return path29.join(os9.homedir(), "Library", "LaunchAgents", `${label2}.plist`);
|
|
17519
17580
|
}
|
|
17520
17581
|
function serviceManagerFromLaunchctl(output, pid, execPath, sea = true) {
|
|
17521
17582
|
const pidMatch = /^\s*pid = (\d+)\s*$/m.exec(output);
|
|
@@ -18311,7 +18372,7 @@ function startServer(opts = {}) {
|
|
|
18311
18372
|
hubUrl: fleetCred?.hubUrl,
|
|
18312
18373
|
gatewayUrl: fleetCred?.gatewayUrl ?? env2("FLEET_GATEWAY_URL"),
|
|
18313
18374
|
online: fleet?.isConnected() ?? false,
|
|
18314
|
-
label: fleetCred?.label,
|
|
18375
|
+
label: fleetCred?.label ?? store.loadNodeLabel() ?? void 0,
|
|
18315
18376
|
lastError: fleet?.getLastError() ?? void 0,
|
|
18316
18377
|
reconnectCount: fleet?.getErrorCount() ?? 0
|
|
18317
18378
|
};
|
|
@@ -18320,27 +18381,53 @@ function startServer(opts = {}) {
|
|
|
18320
18381
|
status: fleetStatus,
|
|
18321
18382
|
async enroll(input) {
|
|
18322
18383
|
const nodeId = ensureNodeId(store);
|
|
18384
|
+
const label2 = input.label?.trim() || defaultNodeLabel();
|
|
18323
18385
|
const cred = input.account ? await hubEnrollByAccount(input.hubUrl, {
|
|
18324
18386
|
email: input.account.email,
|
|
18325
18387
|
phone: input.account.phone,
|
|
18326
18388
|
password: input.account.password,
|
|
18327
18389
|
code: input.account.smsCode,
|
|
18328
18390
|
nodeId,
|
|
18329
|
-
label:
|
|
18391
|
+
label: label2
|
|
18330
18392
|
}) : await hubEnrollByCode(input.hubUrl, {
|
|
18331
18393
|
code: input.code,
|
|
18332
18394
|
nodeId,
|
|
18333
|
-
label:
|
|
18395
|
+
label: label2
|
|
18334
18396
|
});
|
|
18335
18397
|
const full = {
|
|
18336
18398
|
...cred,
|
|
18337
|
-
label:
|
|
18399
|
+
label: label2,
|
|
18338
18400
|
enrolledAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
18339
18401
|
};
|
|
18340
18402
|
store.saveFleetCredential(full);
|
|
18403
|
+
store.saveNodeLabel(label2);
|
|
18341
18404
|
connectFleet(full);
|
|
18342
18405
|
return fleetStatus();
|
|
18343
18406
|
},
|
|
18407
|
+
async rename(label2) {
|
|
18408
|
+
const name = label2.trim();
|
|
18409
|
+
store.saveNodeLabel(name);
|
|
18410
|
+
if (fleetCred) {
|
|
18411
|
+
fleetCred = { ...fleetCred, label: name };
|
|
18412
|
+
store.saveFleetCredential(fleetCred);
|
|
18413
|
+
}
|
|
18414
|
+
fleet?.republishLabel();
|
|
18415
|
+
let hubSynced = false;
|
|
18416
|
+
let hubError;
|
|
18417
|
+
const cred = fleetCred;
|
|
18418
|
+
if (cred?.hubUrl && cred.fleetToken) {
|
|
18419
|
+
try {
|
|
18420
|
+
await hubUpdateNodeLabelSelf(cred.hubUrl, cred.fleetToken, {
|
|
18421
|
+
nodeId: ensureNodeId(store),
|
|
18422
|
+
label: name
|
|
18423
|
+
});
|
|
18424
|
+
hubSynced = true;
|
|
18425
|
+
} catch (e) {
|
|
18426
|
+
hubError = e instanceof Error ? e.message : String(e);
|
|
18427
|
+
}
|
|
18428
|
+
}
|
|
18429
|
+
return { ...fleetStatus(), hubSynced, hubError };
|
|
18430
|
+
},
|
|
18344
18431
|
unlink() {
|
|
18345
18432
|
fleet?.close();
|
|
18346
18433
|
fleet = null;
|
|
@@ -18635,16 +18722,18 @@ async function runWizard(rl, store, opts) {
|
|
|
18635
18722
|
const prompted = await promptLinkAccount(rl, opts.hubUrl);
|
|
18636
18723
|
if (!prompted) return;
|
|
18637
18724
|
const nodeId = ensureNodeId(store);
|
|
18725
|
+
const label2 = opts.label?.trim() || defaultNodeLabel();
|
|
18638
18726
|
const cred = await hubEnrollByAccount(prompted.hubUrl, {
|
|
18639
18727
|
...prompted.auth,
|
|
18640
18728
|
nodeId,
|
|
18641
|
-
label:
|
|
18729
|
+
label: label2
|
|
18642
18730
|
});
|
|
18643
18731
|
store.saveFleetCredential({
|
|
18644
18732
|
...cred,
|
|
18645
|
-
label:
|
|
18733
|
+
label: label2,
|
|
18646
18734
|
enrolledAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
18647
18735
|
});
|
|
18736
|
+
store.saveNodeLabel(label2);
|
|
18648
18737
|
cliLog(`\u2705 \u5DF2\u63A5\u5165 Hub\uFF1A\u8282\u70B9 ${cred.nodeId}\uFF08\u7F51\u5173 ${cred.gatewayUrl ?? "\u672A\u4E0B\u53D1"}\uFF09`);
|
|
18649
18738
|
cliLog(" \u51ED\u636E\u5DF2\u4FDD\u5B58\u5230 fleet.json\uFF0C\u672C\u6B21\u542F\u52A8\u5373\u8FDE\u63A5 Hub\u3002");
|
|
18650
18739
|
}
|
|
@@ -18704,7 +18793,7 @@ var readline2 = __toESM(require("readline"), 1);
|
|
|
18704
18793
|
init_cjs_shims();
|
|
18705
18794
|
var import_node_child_process6 = require("child_process");
|
|
18706
18795
|
var fs30 = __toESM(require("fs"), 1);
|
|
18707
|
-
var
|
|
18796
|
+
var os10 = __toESM(require("os"), 1);
|
|
18708
18797
|
var path35 = __toESM(require("path"), 1);
|
|
18709
18798
|
|
|
18710
18799
|
// src/cli/link.ts
|