@zqagent/core 0.2.7 → 0.2.10
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 +310 -88
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +310 -88
- package/dist/cli/index.js.map +1 -1
- package/dist/server/index.cjs +201 -45
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +201 -45
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -3724,10 +3724,10 @@ var OpenAIProvider = class {
|
|
|
3724
3724
|
let timer;
|
|
3725
3725
|
try {
|
|
3726
3726
|
for (; ; ) {
|
|
3727
|
-
const idle = new Promise((
|
|
3727
|
+
const idle = new Promise((resolve24) => {
|
|
3728
3728
|
timer = setTimeout(() => {
|
|
3729
3729
|
onIdle();
|
|
3730
|
-
|
|
3730
|
+
resolve24({ timedOut: true });
|
|
3731
3731
|
}, idleMs);
|
|
3732
3732
|
});
|
|
3733
3733
|
const next = iter.next();
|
|
@@ -6048,12 +6048,12 @@ function makeSink(maxBuffer) {
|
|
|
6048
6048
|
};
|
|
6049
6049
|
}
|
|
6050
6050
|
function execAsync(file, argv, opts = {}) {
|
|
6051
|
-
return new Promise((
|
|
6051
|
+
return new Promise((resolve24) => {
|
|
6052
6052
|
const maxBuffer = opts.maxBuffer ?? DEFAULT_MAX_BUFFER;
|
|
6053
6053
|
const out = makeSink(maxBuffer);
|
|
6054
6054
|
const err = makeSink(maxBuffer);
|
|
6055
6055
|
if (opts.signal?.aborted) {
|
|
6056
|
-
|
|
6056
|
+
resolve24({
|
|
6057
6057
|
status: null,
|
|
6058
6058
|
stdout: Buffer.alloc(0),
|
|
6059
6059
|
stderr: Buffer.alloc(0),
|
|
@@ -6074,7 +6074,7 @@ function execAsync(file, argv, opts = {}) {
|
|
|
6074
6074
|
windowsHide: true
|
|
6075
6075
|
});
|
|
6076
6076
|
} catch (e) {
|
|
6077
|
-
|
|
6077
|
+
resolve24({
|
|
6078
6078
|
status: null,
|
|
6079
6079
|
stdout: Buffer.alloc(0),
|
|
6080
6080
|
stderr: Buffer.alloc(0),
|
|
@@ -6111,7 +6111,7 @@ function execAsync(file, argv, opts = {}) {
|
|
|
6111
6111
|
};
|
|
6112
6112
|
if (aborted) result.aborted = true;
|
|
6113
6113
|
if (spawnError) result.error = spawnError;
|
|
6114
|
-
|
|
6114
|
+
resolve24(result);
|
|
6115
6115
|
};
|
|
6116
6116
|
const killAndSettle = () => {
|
|
6117
6117
|
killTree(child.pid);
|
|
@@ -10201,8 +10201,8 @@ var InputRouter = class {
|
|
|
10201
10201
|
}
|
|
10202
10202
|
/** 询问一行:显示 prompt,返回该行内容 */
|
|
10203
10203
|
ask(prompt) {
|
|
10204
|
-
return new Promise((
|
|
10205
|
-
this.pendingAsks.push({ prompt, resolve:
|
|
10204
|
+
return new Promise((resolve24) => {
|
|
10205
|
+
this.pendingAsks.push({ prompt, resolve: resolve24 });
|
|
10206
10206
|
this.pumpAsks();
|
|
10207
10207
|
});
|
|
10208
10208
|
}
|
|
@@ -10299,16 +10299,16 @@ import chalk2 from "chalk";
|
|
|
10299
10299
|
var BRAND_TEXT = "ZQAGENT";
|
|
10300
10300
|
var BRAND_TAGLINE = "ZQAgent \xB7 AI Agent CLI";
|
|
10301
10301
|
var GLYPHS = {
|
|
10302
|
-
Z: ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588
|
|
10303
|
-
Q: [" \u2588\u2588\u2588\u2588\u2588\u2588
|
|
10304
|
-
A: [" \u2588\u2588\u2588\u2588\u2588\
|
|
10305
|
-
G: [" \u2588\u2588\u2588\u2588\u2588\u2588
|
|
10306
|
-
E: ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588
|
|
10307
|
-
N: ["\u2588\u2588\u2588\
|
|
10308
|
-
T: ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588
|
|
10302
|
+
Z: ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ", " \u2588\u2588\u2588 ", " \u2588\u2588\u2588 ", " \u2588\u2588\u2588 ", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ", " "],
|
|
10303
|
+
Q: [" \u2588\u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2584\u2584 \u2588\u2588", " \u2588\u2588\u2588\u2588\u2588\u2588 ", " \u2580\u2580 "],
|
|
10304
|
+
A: [" \u2588\u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 \u2588\u2588", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588", "\u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2588\u2588", " "],
|
|
10305
|
+
G: [" \u2588\u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 ", "\u2588\u2588 \u2588\u2588\u2588", "\u2588\u2588 \u2588\u2588", " \u2588\u2588\u2588\u2588\u2588\u2588 ", " "],
|
|
10306
|
+
E: ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 ", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ", "\u2588\u2588 ", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ", " "],
|
|
10307
|
+
N: ["\u2588\u2588 \u2588\u2588", "\u2588\u2588\u2588 \u2588\u2588", "\u2588\u2588\u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2588\u2588 \u2588\u2588", "\u2588\u2588 \u2588\u2588\u2588\u2588", " "],
|
|
10308
|
+
T: ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588", " \u2588\u2588 ", " \u2588\u2588 ", " \u2588\u2588 ", " \u2588\u2588 ", " "]
|
|
10309
10309
|
};
|
|
10310
10310
|
var GLYPH_ROWS = 6;
|
|
10311
|
-
var GLYPH_COLS =
|
|
10311
|
+
var GLYPH_COLS = 9;
|
|
10312
10312
|
var GRADIENT = [
|
|
10313
10313
|
[34, 211, 238],
|
|
10314
10314
|
[99, 102, 241],
|
|
@@ -10913,15 +10913,36 @@ function parseServeArgs(argv) {
|
|
|
10913
10913
|
return { dataDir, host, port };
|
|
10914
10914
|
}
|
|
10915
10915
|
function buildHotCandidates(explicitDataDir, discovered, fallback) {
|
|
10916
|
-
|
|
10917
|
-
return [{ dataDir: path21.resolve(explicitDataDir), ...fallback }];
|
|
10918
|
-
}
|
|
10919
|
-
const out = [{ dataDir: path21.resolve(DEFAULT_DATA_DIR), ...fallback }];
|
|
10916
|
+
const out = explicitDataDir ? [{ dataDir: path21.resolve(explicitDataDir), ...fallback }] : [{ dataDir: path21.resolve(DEFAULT_DATA_DIR), ...fallback }];
|
|
10920
10917
|
for (const inst of discovered) {
|
|
10921
10918
|
if (!out.some((o) => o.dataDir === inst.dataDir)) out.push(inst);
|
|
10922
10919
|
}
|
|
10923
10920
|
return out;
|
|
10924
10921
|
}
|
|
10922
|
+
function isWindowsAbsolute(p) {
|
|
10923
|
+
return /^[A-Za-z]:[\\/]/.test(p) || /^\\\\/.test(p);
|
|
10924
|
+
}
|
|
10925
|
+
function isAbsolutePath(p) {
|
|
10926
|
+
return path21.isAbsolute(p) || isWindowsAbsolute(p);
|
|
10927
|
+
}
|
|
10928
|
+
function normalizePath(p) {
|
|
10929
|
+
return isWindowsAbsolute(p) ? path21.win32.normalize(p) : path21.normalize(p);
|
|
10930
|
+
}
|
|
10931
|
+
function parseServeCommandLine(line) {
|
|
10932
|
+
if (!/(?:^|\s)["']?serve["']?(?=\s|$)/.test(line)) return null;
|
|
10933
|
+
const m = /--data-dir(?:=|\s+)(?:"([^"]+)"|'([^']+)'|(.+?))(?=\s+--\w|\s*$)/.exec(line);
|
|
10934
|
+
const rawDataDir = (m?.[1] ?? m?.[2] ?? m?.[3] ?? "").trim();
|
|
10935
|
+
if (!rawDataDir || !isAbsolutePath(rawDataDir)) return null;
|
|
10936
|
+
const host = /--host(?:=|\s+)(?:"([^"]+)"|'([^']+)'|(\S+))/.exec(line);
|
|
10937
|
+
const rawHost = (host?.[1] ?? host?.[2] ?? host?.[3] ?? DEFAULT_SERVE_HOST).trim();
|
|
10938
|
+
const portMatch = /--port(?:=|\s+)(\d+)/.exec(line);
|
|
10939
|
+
const port = Number(portMatch?.[1] ?? DEFAULT_SERVE_PORT);
|
|
10940
|
+
return {
|
|
10941
|
+
dataDir: normalizePath(rawDataDir),
|
|
10942
|
+
host: rawHost === "0.0.0.0" || rawHost === "::" || rawHost === "" ? DEFAULT_SERVE_HOST : rawHost,
|
|
10943
|
+
port: Number.isFinite(port) && port > 0 ? port : DEFAULT_SERVE_PORT
|
|
10944
|
+
};
|
|
10945
|
+
}
|
|
10925
10946
|
function processCwd(pid) {
|
|
10926
10947
|
try {
|
|
10927
10948
|
return fs18.readlinkSync(`/proc/${pid}/cwd`);
|
|
@@ -10977,23 +10998,28 @@ function discoverFromPs() {
|
|
|
10977
10998
|
const res = spawnSync2("ps", ["-axo", "command="], { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
|
|
10978
10999
|
if (res.status !== 0 || !res.stdout) return out;
|
|
10979
11000
|
for (const line of res.stdout.split("\n")) {
|
|
10980
|
-
|
|
10981
|
-
|
|
10982
|
-
|
|
10983
|
-
|
|
10984
|
-
|
|
10985
|
-
|
|
10986
|
-
|
|
10987
|
-
|
|
10988
|
-
|
|
10989
|
-
|
|
10990
|
-
|
|
10991
|
-
}
|
|
11001
|
+
const inst = parseServeCommandLine(line);
|
|
11002
|
+
if (inst) out.push(inst);
|
|
11003
|
+
}
|
|
11004
|
+
return out;
|
|
11005
|
+
}
|
|
11006
|
+
function discoverFromWindows() {
|
|
11007
|
+
const out = [];
|
|
11008
|
+
const script = `[Console]::OutputEncoding=[Text.Encoding]::UTF8; Get-CimInstance Win32_Process -Filter "Name='zqagent.exe' OR Name='node.exe'" | ForEach-Object { $_.CommandLine }`;
|
|
11009
|
+
const res = spawnSync2(
|
|
11010
|
+
"powershell.exe",
|
|
11011
|
+
["-NoProfile", "-NonInteractive", "-Command", script],
|
|
11012
|
+
{ encoding: "utf-8", timeout: 15e3, windowsHide: true, stdio: ["ignore", "pipe", "ignore"] }
|
|
11013
|
+
);
|
|
11014
|
+
if (res.status !== 0 || !res.stdout) return out;
|
|
11015
|
+
for (const line of res.stdout.replace(/^\uFEFF/, "").split(/\r?\n/)) {
|
|
11016
|
+
const inst = parseServeCommandLine(line);
|
|
11017
|
+
if (inst) out.push(inst);
|
|
10992
11018
|
}
|
|
10993
11019
|
return out;
|
|
10994
11020
|
}
|
|
10995
11021
|
function discoverRunningServeInstances() {
|
|
10996
|
-
const found = process.platform === "linux" ? discoverFromProc() : discoverFromPs();
|
|
11022
|
+
const found = process.platform === "linux" ? discoverFromProc() : process.platform === "win32" ? discoverFromWindows() : discoverFromPs();
|
|
10997
11023
|
const seen = /* @__PURE__ */ new Set();
|
|
10998
11024
|
return found.filter((inst) => {
|
|
10999
11025
|
if (seen.has(inst.dataDir)) return false;
|
|
@@ -11003,6 +11029,18 @@ function discoverRunningServeInstances() {
|
|
|
11003
11029
|
}
|
|
11004
11030
|
|
|
11005
11031
|
// src/cli/link.ts
|
|
11032
|
+
function expandHome(p) {
|
|
11033
|
+
const home = process.env.HOME || process.env.USERPROFILE;
|
|
11034
|
+
if (!home) return p;
|
|
11035
|
+
if (p === "~") return home;
|
|
11036
|
+
if (p.startsWith("~/") || p.startsWith("~\\")) return path22.join(home, p.slice(2));
|
|
11037
|
+
return p;
|
|
11038
|
+
}
|
|
11039
|
+
function installDataDirHint() {
|
|
11040
|
+
if (process.platform === "darwin") return "$HOME/Library/Application Support/zqagent";
|
|
11041
|
+
if (process.platform === "win32") return "%LOCALAPPDATA%\\zqagent";
|
|
11042
|
+
return "/var/lib/zqagent\uFF08\u9700 root\uFF1B\u666E\u901A\u7528\u6237\u7528 ~/.zqagent_data\uFF09";
|
|
11043
|
+
}
|
|
11006
11044
|
function parseLinkArgs(argv) {
|
|
11007
11045
|
const out = {};
|
|
11008
11046
|
for (let i = 0; i < argv.length; i++) {
|
|
@@ -11076,10 +11114,12 @@ async function enrollViaServer(host, port, adminKey, opts) {
|
|
|
11076
11114
|
return payload?.data;
|
|
11077
11115
|
}
|
|
11078
11116
|
async function linkNode(opts) {
|
|
11079
|
-
const
|
|
11117
|
+
const rawDataDir = opts.dataDir?.trim() || process.env.DATA_DIR?.trim() || void 0;
|
|
11118
|
+
const explicitDataDir = rawDataDir ? expandHome(rawDataDir) : void 0;
|
|
11080
11119
|
const host = opts.host?.trim() || process.env.HOST?.trim() || DEFAULT_SERVE_HOST;
|
|
11081
11120
|
const port = opts.port ?? Number(process.env.PORT ?? DEFAULT_SERVE_PORT);
|
|
11082
|
-
const
|
|
11121
|
+
const running = discoverRunningServeInstances();
|
|
11122
|
+
const candidates = buildHotCandidates(explicitDataDir, running, { host, port });
|
|
11083
11123
|
for (const inst of candidates) {
|
|
11084
11124
|
const store2 = new Store(inst.dataDir);
|
|
11085
11125
|
const adminKey = process.env.ADMIN_API_KEY ?? store2.loadAdminKey();
|
|
@@ -11096,18 +11136,36 @@ async function linkNode(opts) {
|
|
|
11096
11136
|
nodeId,
|
|
11097
11137
|
label: opts.label
|
|
11098
11138
|
});
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
|
|
11139
|
+
try {
|
|
11140
|
+
store.saveFleetCredential({
|
|
11141
|
+
...cred,
|
|
11142
|
+
label: opts.label ?? cred.label,
|
|
11143
|
+
enrolledAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
11144
|
+
});
|
|
11145
|
+
} catch (e) {
|
|
11146
|
+
const err = e;
|
|
11147
|
+
if (err.code === "EACCES" || err.code === "EPERM") {
|
|
11148
|
+
throw new Error(
|
|
11149
|
+
`\u65E0\u6CD5\u5199\u5165\u6570\u636E\u76EE\u5F55 ${dataDir}\uFF08${err.code}: ${err.message}\uFF09
|
|
11150
|
+
\u8BE5\u76EE\u5F55\u5F53\u524D\u7528\u6237\u6CA1\u6709\u5199\u6743\u9650\u3002\u4E24\u79CD\u6539\u6CD5\uFF1A
|
|
11151
|
+
1) \u53BB\u6389 --data-dir\uFF0C\u8BA9 link \u81EA\u52A8\u53D1\u73B0\u672C\u673A\u8FD0\u884C\u7684\u8282\u70B9\uFF08\u63A8\u8350\uFF09\uFF1B
|
|
11152
|
+
2) \u7528\u5F53\u524D\u7528\u6237\u53EF\u5199\u7684\u76EE\u5F55\uFF0C\u672C\u5E73\u53F0\u5B89\u88C5\u811A\u672C\u9ED8\u8BA4\uFF1A${installDataDirHint()}
|
|
11153
|
+
\uFF08\u63A5\u5165\u7801\u4E00\u6B21\u6027\uFF0C\u9700\u8981\u91CD\u65B0\u751F\u6210\uFF09`
|
|
11154
|
+
);
|
|
11155
|
+
}
|
|
11156
|
+
throw e;
|
|
11157
|
+
}
|
|
11158
|
+
const otherRunningDirs = [
|
|
11159
|
+
...new Set(running.map((r) => r.dataDir).filter((d) => d !== dataDir))
|
|
11160
|
+
];
|
|
11104
11161
|
return {
|
|
11105
11162
|
mode: "saved",
|
|
11106
11163
|
nodeId,
|
|
11107
11164
|
gatewayUrl: cred.gatewayUrl,
|
|
11108
11165
|
label: opts.label,
|
|
11109
11166
|
dataDir,
|
|
11110
|
-
explicitDataDir: Boolean(explicitDataDir)
|
|
11167
|
+
explicitDataDir: Boolean(explicitDataDir),
|
|
11168
|
+
runningServiceDirs: otherRunningDirs
|
|
11111
11169
|
};
|
|
11112
11170
|
}
|
|
11113
11171
|
function printLinkHelp() {
|
|
@@ -11149,13 +11207,21 @@ async function runLinkCommand(argv) {
|
|
|
11149
11207
|
cliLog(` \u7F51\u5173: ${r.gatewayUrl ?? "\uFF08\u672A\u4E0B\u53D1\uFF09"}`);
|
|
11150
11208
|
cliLog(` \u6570\u636E\u76EE\u5F55: ${r.dataDir}`);
|
|
11151
11209
|
cliLog(" \u4E0B\u6B21\u542F\u52A8 server \u5373\u81EA\u52A8\u63A5\u5165\uFF1B\u6216\u8FD0\u884C zqagent serve \u5E38\u9A7B\u4E3A\u8282\u70B9\u3002");
|
|
11152
|
-
if (
|
|
11210
|
+
if (r.runningServiceDirs.length > 0) {
|
|
11211
|
+
cliLog("");
|
|
11212
|
+
cliLog("\u26A0\uFE0F \u672C\u673A\u6709\u6B63\u5728\u8FD0\u884C\u7684\u8282\u70B9\uFF0C\u4F46\u6570\u636E\u76EE\u5F55\u4E0E\u672C\u6B21\u5199\u5165\u7684\u4E0D\u4E00\u81F4\uFF1A");
|
|
11213
|
+
cliLog(` \u672C\u6B21\u5199\u5165: ${r.dataDir}`);
|
|
11214
|
+
for (const d of r.runningServiceDirs) cliLog(` \u670D\u52A1\u4F7F\u7528: ${d}`);
|
|
11215
|
+
cliLog(" \u6B63\u5728\u8FD0\u884C\u7684\u670D\u52A1\u8BFB\u4E0D\u5230\u8FD9\u4EFD\u51ED\u636E\uFF0CHub \u4F1A\u4E00\u76F4\u663E\u793A\u672A\u63A5\u5165\u3002");
|
|
11216
|
+
cliLog(" \u8BF7\u786E\u8BA4\u670D\u52A1\u7684\u6570\u636E\u76EE\u5F55\u540E\u91CD\u65B0\u6267\u884C\uFF08\u63A5\u5165\u7801\u4E00\u6B21\u6027\uFF0C\u9700\u8981\u91CD\u65B0\u751F\u6210\uFF09\uFF1A");
|
|
11217
|
+
cliLog(` zqagent link --hub <Hub\u5730\u5740> --code <\u65B0\u63A5\u5165\u7801> --data-dir "${r.runningServiceDirs[0]}"`);
|
|
11218
|
+
} else if (!r.explicitDataDir) {
|
|
11153
11219
|
cliLog("");
|
|
11154
11220
|
cliLog("\u26A0\uFE0F \u672A\u6307\u5B9A --data-dir\uFF0C\u51ED\u636E\u5199\u5165\u4E86\u5F53\u524D\u76EE\u5F55\u4E0B\u7684 .zqagent_data\u3002");
|
|
11155
11221
|
cliLog(" \u82E5\u672C\u673A\u670D\u52A1\u662F\u7531\u5B89\u88C5\u811A\u672C\uFF08systemd / launchd\uFF09\u542F\u52A8\u7684\uFF0C\u5B83\u8BFB\u4E0D\u5230\u8FD9\u4EFD\u51ED\u636E\uFF0C");
|
|
11156
11222
|
cliLog(" Hub \u4F1A\u4E00\u76F4\u663E\u793A\u672A\u5728\u7EBF\u3002\u8BF7\u7528\u670D\u52A1\u7684\u6570\u636E\u76EE\u5F55\u91CD\u65B0\u6267\u884C\uFF1A");
|
|
11157
11223
|
cliLog(" zqagent link --hub <Hub\u5730\u5740> --code <\u65B0\u63A5\u5165\u7801> --data-dir <\u670D\u52A1\u6570\u636E\u76EE\u5F55>");
|
|
11158
|
-
cliLog(
|
|
11224
|
+
cliLog(` \uFF08\u672C\u5E73\u53F0\u5B89\u88C5\u811A\u672C\u9ED8\u8BA4\uFF1A${installDataDirHint()}\uFF1B\u63A5\u5165\u7801\u4E00\u6B21\u6027\uFF0C\u9700\u8981\u91CD\u65B0\u751F\u6210\uFF09`);
|
|
11159
11225
|
}
|
|
11160
11226
|
}
|
|
11161
11227
|
return true;
|
|
@@ -12006,11 +12072,11 @@ function isAffirmative(answer) {
|
|
|
12006
12072
|
return /^(yes|approve|同意|批准|允许|确定|可以|好的|确认)/.test(a);
|
|
12007
12073
|
}
|
|
12008
12074
|
function defer() {
|
|
12009
|
-
let
|
|
12075
|
+
let resolve24;
|
|
12010
12076
|
const promise = new Promise((r) => {
|
|
12011
|
-
|
|
12077
|
+
resolve24 = r;
|
|
12012
12078
|
});
|
|
12013
|
-
return { promise, resolve:
|
|
12079
|
+
return { promise, resolve: resolve24 };
|
|
12014
12080
|
}
|
|
12015
12081
|
var SessionManager = class {
|
|
12016
12082
|
constructor(store, approvalTimeoutMs = APPROVAL_TIMEOUT_MS, opts = {}) {
|
|
@@ -12582,11 +12648,11 @@ data: ${JSON.stringify({ sessionId, seq: entry.seq, ts: entry.ts, data: entry.da
|
|
|
12582
12648
|
status: "pending",
|
|
12583
12649
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
12584
12650
|
};
|
|
12585
|
-
const { promise, resolve:
|
|
12651
|
+
const { promise, resolve: resolve24 } = defer();
|
|
12586
12652
|
const timer = setTimeout(() => {
|
|
12587
12653
|
this._recycleApproval(rt, id);
|
|
12588
12654
|
}, this.approvalTimeoutMs);
|
|
12589
|
-
rt.pendingApprovals.set(id, { promise, resolve:
|
|
12655
|
+
rt.pendingApprovals.set(id, { promise, resolve: resolve24, record, timer });
|
|
12590
12656
|
rt.approvals.set(id, record);
|
|
12591
12657
|
this._setStatus(rt, "waiting_approval");
|
|
12592
12658
|
this._persist(rt);
|
|
@@ -12664,11 +12730,11 @@ data: ${JSON.stringify({ sessionId, seq: entry.seq, ts: entry.ts, data: entry.da
|
|
|
12664
12730
|
status: "pending",
|
|
12665
12731
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
12666
12732
|
};
|
|
12667
|
-
const { promise, resolve:
|
|
12733
|
+
const { promise, resolve: resolve24 } = defer();
|
|
12668
12734
|
const timer = setTimeout(() => {
|
|
12669
12735
|
this._recycleQuestion(rt, qid);
|
|
12670
12736
|
}, this.approvalTimeoutMs);
|
|
12671
|
-
rt.pendingQuestions.set(qid, { promise, resolve:
|
|
12737
|
+
rt.pendingQuestions.set(qid, { promise, resolve: resolve24, record, timer });
|
|
12672
12738
|
rt.questions.set(qid, record);
|
|
12673
12739
|
this._setStatus(rt, "waiting_question");
|
|
12674
12740
|
this._persist(rt);
|
|
@@ -12977,7 +13043,7 @@ data: ${JSON.stringify(entry.data)}
|
|
|
12977
13043
|
if (rt.mcpReady) {
|
|
12978
13044
|
await Promise.race([
|
|
12979
13045
|
rt.mcpReady,
|
|
12980
|
-
new Promise((
|
|
13046
|
+
new Promise((resolve24) => setTimeout(resolve24, 15e3))
|
|
12981
13047
|
]).catch(() => void 0);
|
|
12982
13048
|
}
|
|
12983
13049
|
for await (const event of gen) {
|
|
@@ -13562,7 +13628,7 @@ function buildNodeInfo(store, opts) {
|
|
|
13562
13628
|
nodeId: opts.nodeId ?? ensureNodeId2(store),
|
|
13563
13629
|
platform: process.platform,
|
|
13564
13630
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
13565
|
-
version: "0.2.
|
|
13631
|
+
version: "0.2.10",
|
|
13566
13632
|
admin: opts.admin,
|
|
13567
13633
|
projects: opts.projects
|
|
13568
13634
|
};
|
|
@@ -14555,7 +14621,7 @@ function buildNodeHost(store, manager, diskPath) {
|
|
|
14555
14621
|
arch: process.arch,
|
|
14556
14622
|
release: os6.release(),
|
|
14557
14623
|
uptimeSec: Math.round(os6.uptime()),
|
|
14558
|
-
version: "0.2.
|
|
14624
|
+
version: "0.2.10",
|
|
14559
14625
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
14560
14626
|
cpu: {
|
|
14561
14627
|
count: cpus2.length,
|
|
@@ -14599,7 +14665,7 @@ function saveNotifications(tenant, secretBox, notifications) {
|
|
|
14599
14665
|
var API_PREFIX = "/api/v1";
|
|
14600
14666
|
var MAX_BODY_BYTES = 10 * 1024 * 1024;
|
|
14601
14667
|
function readBody(req2) {
|
|
14602
|
-
return new Promise((
|
|
14668
|
+
return new Promise((resolve24, reject) => {
|
|
14603
14669
|
const chunks = [];
|
|
14604
14670
|
let size = 0;
|
|
14605
14671
|
req2.on("data", (c) => {
|
|
@@ -14612,9 +14678,9 @@ function readBody(req2) {
|
|
|
14612
14678
|
chunks.push(c);
|
|
14613
14679
|
});
|
|
14614
14680
|
req2.on("end", () => {
|
|
14615
|
-
if (chunks.length === 0) return
|
|
14681
|
+
if (chunks.length === 0) return resolve24(void 0);
|
|
14616
14682
|
try {
|
|
14617
|
-
|
|
14683
|
+
resolve24(JSON.parse(Buffer.concat(chunks).toString("utf-8")));
|
|
14618
14684
|
} catch {
|
|
14619
14685
|
reject(new ApiError(400, "bad_request", "\u8BF7\u6C42\u4F53\u4E0D\u662F\u5408\u6CD5 JSON"));
|
|
14620
14686
|
}
|
|
@@ -15130,8 +15196,18 @@ function createApp(store, manager, opts = {}) {
|
|
|
15130
15196
|
applyProvidersPatch(tenant, raw);
|
|
15131
15197
|
if (typeof raw.workspaceRoot === "string") {
|
|
15132
15198
|
const ws = raw.workspaceRoot.trim();
|
|
15133
|
-
|
|
15134
|
-
|
|
15199
|
+
const next = ws ? path30.resolve(ws) : void 0;
|
|
15200
|
+
if (tenant.workspaceRoot) {
|
|
15201
|
+
if (next !== tenant.workspaceRoot) {
|
|
15202
|
+
throw new ApiError(
|
|
15203
|
+
409,
|
|
15204
|
+
"workspace_locked",
|
|
15205
|
+
"\u8BE5\u9879\u76EE\u5DF2\u8BBE\u7F6E\u5DE5\u4F5C\u76EE\u5F55\uFF0C\u4E0D\u80FD\u518D\u4FEE\u6539"
|
|
15206
|
+
);
|
|
15207
|
+
}
|
|
15208
|
+
} else if (next) {
|
|
15209
|
+
tenant.workspaceRoot = next;
|
|
15210
|
+
}
|
|
15135
15211
|
}
|
|
15136
15212
|
if (typeof raw.name === "string" && raw.name.trim()) {
|
|
15137
15213
|
tenant.name = raw.name.trim();
|
|
@@ -16107,7 +16183,7 @@ function createApp(store, manager, opts = {}) {
|
|
|
16107
16183
|
json(res, 200, {
|
|
16108
16184
|
status: "ok",
|
|
16109
16185
|
// 版本让运维/探针能确认线上跑的是哪个构建(更新与回滚据此判断)
|
|
16110
|
-
version: "0.2.
|
|
16186
|
+
version: "0.2.10",
|
|
16111
16187
|
features: { mcp: hasServerMcpConfig() }
|
|
16112
16188
|
});
|
|
16113
16189
|
return;
|
|
@@ -16223,8 +16299,8 @@ async function cachedFetchModels(baseURL, apiKey) {
|
|
|
16223
16299
|
try {
|
|
16224
16300
|
result = await Promise.race([
|
|
16225
16301
|
fetchModels(baseURL, apiKey),
|
|
16226
|
-
new Promise((
|
|
16227
|
-
const t = setTimeout(() =>
|
|
16302
|
+
new Promise((resolve24) => {
|
|
16303
|
+
const t = setTimeout(() => resolve24(null), MODEL_FETCH_TIMEOUT_MS);
|
|
16228
16304
|
t.unref?.();
|
|
16229
16305
|
})
|
|
16230
16306
|
]);
|
|
@@ -16249,8 +16325,8 @@ async function cachedFetchModelsEnriched(baseURL, apiKey, preferred) {
|
|
|
16249
16325
|
if (!target) return r;
|
|
16250
16326
|
const ctx = await Promise.race([
|
|
16251
16327
|
fetchModelContext(baseURL, apiKey, target),
|
|
16252
|
-
new Promise((
|
|
16253
|
-
const t = setTimeout(() =>
|
|
16328
|
+
new Promise((resolve24) => {
|
|
16329
|
+
const t = setTimeout(() => resolve24(void 0), MODEL_FETCH_TIMEOUT_MS);
|
|
16254
16330
|
t.unref?.();
|
|
16255
16331
|
})
|
|
16256
16332
|
]);
|
|
@@ -17379,13 +17455,13 @@ var EVENT_FLUSH_MAX_EVENTS = 60;
|
|
|
17379
17455
|
var EVENT_FLUSH_MAX_BYTES = 200 * 1024;
|
|
17380
17456
|
var LOOP_LAG_WARN_MS = 2e3;
|
|
17381
17457
|
function withTimeout(p, ms) {
|
|
17382
|
-
return new Promise((
|
|
17458
|
+
return new Promise((resolve24, reject) => {
|
|
17383
17459
|
const timer = setTimeout(() => reject(new Error(`\u5B50\u6307\u4EE4\u8D85\u65F6\uFF08${ms}ms\uFF09`)), ms);
|
|
17384
17460
|
timer.unref?.();
|
|
17385
17461
|
p.then(
|
|
17386
17462
|
(v) => {
|
|
17387
17463
|
clearTimeout(timer);
|
|
17388
|
-
|
|
17464
|
+
resolve24(v);
|
|
17389
17465
|
},
|
|
17390
17466
|
(e) => {
|
|
17391
17467
|
clearTimeout(timer);
|
|
@@ -17745,7 +17821,7 @@ var FleetNodeBridge = class {
|
|
|
17745
17821
|
label: this.opts.deps.store.loadNodeLabel() ?? void 0,
|
|
17746
17822
|
platform: process.platform,
|
|
17747
17823
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
17748
|
-
version: "0.2.
|
|
17824
|
+
version: "0.2.10",
|
|
17749
17825
|
ip: primaryIp()
|
|
17750
17826
|
};
|
|
17751
17827
|
}
|
|
@@ -17800,7 +17876,7 @@ var FleetNodeBridge = class {
|
|
|
17800
17876
|
label: this.opts.deps.store.loadNodeLabel() ?? void 0,
|
|
17801
17877
|
platform: process.platform,
|
|
17802
17878
|
mode: process.env.NODE_MODE ?? "standalone",
|
|
17803
|
-
version: "0.2.
|
|
17879
|
+
version: "0.2.10",
|
|
17804
17880
|
ip: primaryIp(),
|
|
17805
17881
|
projects,
|
|
17806
17882
|
totals,
|
|
@@ -19277,8 +19353,10 @@ var PLATFORM_NAMES = {
|
|
|
19277
19353
|
linux: "linux",
|
|
19278
19354
|
win32: "windows"
|
|
19279
19355
|
};
|
|
19356
|
+
var LIBC_VARIANT = "";
|
|
19280
19357
|
function platformKey(platform = process.platform, arch = process.arch) {
|
|
19281
|
-
|
|
19358
|
+
const base = `${PLATFORM_NAMES[platform] ?? platform}-${arch}`;
|
|
19359
|
+
return LIBC_VARIANT ? `${base}-${LIBC_VARIANT}` : base;
|
|
19282
19360
|
}
|
|
19283
19361
|
var SHA256_HEX = /^[0-9a-f]{64}$/;
|
|
19284
19362
|
function isRecord(v) {
|
|
@@ -19465,10 +19543,12 @@ function selfCheck(binPath, expectedVersion) {
|
|
|
19465
19543
|
// src/update/platform.ts
|
|
19466
19544
|
init_esm_shims();
|
|
19467
19545
|
import * as fs27 from "fs";
|
|
19546
|
+
import * as os8 from "os";
|
|
19468
19547
|
import * as path34 from "path";
|
|
19548
|
+
import { spawnSync as spawnSync4 } from "child_process";
|
|
19469
19549
|
import { createRequire as createRequire3 } from "module";
|
|
19470
19550
|
function currentVersion() {
|
|
19471
|
-
const injected = "0.2.
|
|
19551
|
+
const injected = "0.2.10"?.trim();
|
|
19472
19552
|
if (injected) return injected;
|
|
19473
19553
|
try {
|
|
19474
19554
|
const req2 = createRequire3(import.meta.url);
|
|
@@ -19484,6 +19564,7 @@ function isSeaRuntime() {
|
|
|
19484
19564
|
return base !== "node" && base !== "nodejs";
|
|
19485
19565
|
}
|
|
19486
19566
|
var DEFAULT_SERVICE_NAME = "zqagent";
|
|
19567
|
+
var DEFAULT_SERVICE_LABEL = "com.zqagent.node";
|
|
19487
19568
|
function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
|
|
19488
19569
|
const unitName = `${serviceName}.service`;
|
|
19489
19570
|
for (const line of cgroup.split("\n")) {
|
|
@@ -19494,7 +19575,46 @@ function serviceManagerFromCgroup(cgroup, serviceName = DEFAULT_SERVICE_NAME) {
|
|
|
19494
19575
|
}
|
|
19495
19576
|
return null;
|
|
19496
19577
|
}
|
|
19578
|
+
function launchdDomain() {
|
|
19579
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
19580
|
+
return uid === 0 ? "system" : `gui/${uid}`;
|
|
19581
|
+
}
|
|
19582
|
+
function launchdLabel() {
|
|
19583
|
+
return process.env.ZQAGENT_SERVICE_LABEL?.trim() || DEFAULT_SERVICE_LABEL;
|
|
19584
|
+
}
|
|
19585
|
+
function launchdPlistPath() {
|
|
19586
|
+
const label = launchdLabel();
|
|
19587
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : -1;
|
|
19588
|
+
if (uid === 0) return `/Library/LaunchDaemons/${label}.plist`;
|
|
19589
|
+
return path34.join(os8.homedir(), "Library", "LaunchAgents", `${label}.plist`);
|
|
19590
|
+
}
|
|
19591
|
+
function serviceManagerFromLaunchctl(output, pid, execPath, sea = true) {
|
|
19592
|
+
const pidMatch = /^\s*pid = (\d+)\s*$/m.exec(output);
|
|
19593
|
+
if (pidMatch && Number(pidMatch[1]) === pid) return "launchd";
|
|
19594
|
+
const program = /^\s*program = (.+?)\s*$/m.exec(output);
|
|
19595
|
+
if (program) {
|
|
19596
|
+
const shown = program[1].replace(/^"|"$/g, "");
|
|
19597
|
+
if (path34.resolve(shown) === path34.resolve(execPath)) return "launchd";
|
|
19598
|
+
}
|
|
19599
|
+
if (!sea && /^\s*state = /m.test(output)) return "launchd";
|
|
19600
|
+
return null;
|
|
19601
|
+
}
|
|
19602
|
+
function parseLaunchdEnvironment(xml) {
|
|
19603
|
+
const out = {};
|
|
19604
|
+
const marker = xml.indexOf("<key>EnvironmentVariables</key>");
|
|
19605
|
+
if (marker < 0) return out;
|
|
19606
|
+
const open = xml.indexOf("<dict>", marker);
|
|
19607
|
+
if (open < 0) return out;
|
|
19608
|
+
const close = xml.indexOf("</dict>", open);
|
|
19609
|
+
if (close < 0) return out;
|
|
19610
|
+
const body = xml.slice(open + "<dict>".length, close);
|
|
19611
|
+
for (const m of body.matchAll(/<key>([^<]+)<\/key>\s*<string>([^<]*)<\/string>/g)) {
|
|
19612
|
+
out[m[1]] = m[2];
|
|
19613
|
+
}
|
|
19614
|
+
return out;
|
|
19615
|
+
}
|
|
19497
19616
|
function detectServiceManager() {
|
|
19617
|
+
if (process.platform === "darwin") return detectLaunchd();
|
|
19498
19618
|
if (process.platform !== "linux") return null;
|
|
19499
19619
|
const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
|
|
19500
19620
|
try {
|
|
@@ -19506,11 +19626,71 @@ function detectServiceManager() {
|
|
|
19506
19626
|
return null;
|
|
19507
19627
|
}
|
|
19508
19628
|
}
|
|
19629
|
+
function detectLaunchd() {
|
|
19630
|
+
try {
|
|
19631
|
+
const res = spawnSync4(
|
|
19632
|
+
"launchctl",
|
|
19633
|
+
["print", `${launchdDomain()}/${launchdLabel()}`],
|
|
19634
|
+
{ encoding: "utf8", timeout: 3e3 }
|
|
19635
|
+
);
|
|
19636
|
+
if (res.status !== 0 || !res.stdout) return null;
|
|
19637
|
+
return serviceManagerFromLaunchctl(
|
|
19638
|
+
res.stdout,
|
|
19639
|
+
process.pid,
|
|
19640
|
+
process.execPath,
|
|
19641
|
+
isSeaRuntime()
|
|
19642
|
+
);
|
|
19643
|
+
} catch {
|
|
19644
|
+
return null;
|
|
19645
|
+
}
|
|
19646
|
+
}
|
|
19509
19647
|
function serviceManager() {
|
|
19510
19648
|
const v = process.env.ZQAGENT_SERVICE_MANAGER?.trim().toLowerCase();
|
|
19511
19649
|
if (v === "systemd" || v === "launchd") return v;
|
|
19512
19650
|
return detectServiceManager();
|
|
19513
19651
|
}
|
|
19652
|
+
function parseServiceEnvironment(raw) {
|
|
19653
|
+
const out = {};
|
|
19654
|
+
for (const token of raw.trim().split(/\s+/)) {
|
|
19655
|
+
const idx = token.indexOf("=");
|
|
19656
|
+
if (idx > 0) out[token.slice(0, idx)] = token.slice(idx + 1);
|
|
19657
|
+
}
|
|
19658
|
+
return out;
|
|
19659
|
+
}
|
|
19660
|
+
var cachedServiceEnv = null;
|
|
19661
|
+
function readServiceEnvironment() {
|
|
19662
|
+
const serviceName = process.env.ZQAGENT_SERVICE_NAME?.trim() || DEFAULT_SERVICE_NAME;
|
|
19663
|
+
try {
|
|
19664
|
+
const res = spawnSync4(
|
|
19665
|
+
"systemctl",
|
|
19666
|
+
["show", serviceName, "--property=Environment", "--value", "--no-pager"],
|
|
19667
|
+
{ encoding: "utf8", timeout: 3e3 }
|
|
19668
|
+
);
|
|
19669
|
+
if (res.status !== 0 || !res.stdout) return {};
|
|
19670
|
+
return parseServiceEnvironment(res.stdout);
|
|
19671
|
+
} catch {
|
|
19672
|
+
return {};
|
|
19673
|
+
}
|
|
19674
|
+
}
|
|
19675
|
+
function serviceEnvValue(key) {
|
|
19676
|
+
if (process.platform === "darwin") {
|
|
19677
|
+
if (serviceManager() !== "launchd") return void 0;
|
|
19678
|
+
cachedLaunchdEnv ??= readLaunchdEnvironment();
|
|
19679
|
+
return cachedLaunchdEnv[key];
|
|
19680
|
+
}
|
|
19681
|
+
if (process.platform !== "linux") return void 0;
|
|
19682
|
+
if (serviceManager() !== "systemd") return void 0;
|
|
19683
|
+
cachedServiceEnv ??= readServiceEnvironment();
|
|
19684
|
+
return cachedServiceEnv[key];
|
|
19685
|
+
}
|
|
19686
|
+
var cachedLaunchdEnv = null;
|
|
19687
|
+
function readLaunchdEnvironment() {
|
|
19688
|
+
try {
|
|
19689
|
+
return parseLaunchdEnvironment(fs27.readFileSync(launchdPlistPath(), "utf8"));
|
|
19690
|
+
} catch {
|
|
19691
|
+
return {};
|
|
19692
|
+
}
|
|
19693
|
+
}
|
|
19514
19694
|
function selfUpdateCapability(hasPublicKey) {
|
|
19515
19695
|
if (!isSeaRuntime()) {
|
|
19516
19696
|
return {
|
|
@@ -19663,7 +19843,9 @@ function readRollbackTarget(dataDir) {
|
|
|
19663
19843
|
var DEFAULT_BASE = "https://agent.cd-zq.com/downloads/zqagent";
|
|
19664
19844
|
function env(key) {
|
|
19665
19845
|
const v = process.env[key]?.trim();
|
|
19666
|
-
|
|
19846
|
+
if (v) return v;
|
|
19847
|
+
const fromService = serviceEnvValue(key)?.trim();
|
|
19848
|
+
return fromService ? fromService : void 0;
|
|
19667
19849
|
}
|
|
19668
19850
|
function num(key, fallback) {
|
|
19669
19851
|
const n = Number(env(key));
|
|
@@ -19700,7 +19882,7 @@ var UpdateController = class {
|
|
|
19700
19882
|
return parsePublicKey(env("ZQAGENT_UPDATE_PUBKEY") ?? "");
|
|
19701
19883
|
}
|
|
19702
19884
|
get autoUpdateOff() {
|
|
19703
|
-
return
|
|
19885
|
+
return env("ZQAGENT_AUTO_UPDATE") === "0";
|
|
19704
19886
|
}
|
|
19705
19887
|
get enabled() {
|
|
19706
19888
|
return !this.autoUpdateOff && selfUpdateCapability(Boolean(this.publicKey)).ok;
|
|
@@ -19893,11 +20075,11 @@ var UpdateController = class {
|
|
|
19893
20075
|
const minUptime = num("ZQAGENT_UPDATE_MIN_UPTIME_MS", 10 * 60 * 1e3);
|
|
19894
20076
|
const idleMs = num("ZQAGENT_UPDATE_IDLE_MS", 60 * 1e3);
|
|
19895
20077
|
let idleSince = null;
|
|
19896
|
-
return new Promise((
|
|
20078
|
+
return new Promise((resolve24) => {
|
|
19897
20079
|
const timer = setInterval(() => {
|
|
19898
20080
|
if (this.stopped) {
|
|
19899
20081
|
clearInterval(timer);
|
|
19900
|
-
|
|
20082
|
+
resolve24(false);
|
|
19901
20083
|
return;
|
|
19902
20084
|
}
|
|
19903
20085
|
if (Date.now() - this.startedAt < minUptime || !this.opts.isIdle()) {
|
|
@@ -19907,7 +20089,7 @@ var UpdateController = class {
|
|
|
19907
20089
|
idleSince ??= Date.now();
|
|
19908
20090
|
if (Date.now() - idleSince >= idleMs) {
|
|
19909
20091
|
clearInterval(timer);
|
|
19910
|
-
|
|
20092
|
+
resolve24(true);
|
|
19911
20093
|
}
|
|
19912
20094
|
}, 1e3);
|
|
19913
20095
|
timer.unref();
|
|
@@ -20088,6 +20270,46 @@ function exitWhenOrphaned() {
|
|
|
20088
20270
|
}, 1500);
|
|
20089
20271
|
timer.unref();
|
|
20090
20272
|
}
|
|
20273
|
+
var PORT_FALLBACK_LIMIT = 20;
|
|
20274
|
+
function listenWithPortFallback(server, startPort, host, dataDir, limit = PORT_FALLBACK_LIMIT) {
|
|
20275
|
+
return new Promise((resolve24, reject) => {
|
|
20276
|
+
let attempts = 0;
|
|
20277
|
+
const tryListen = (port) => {
|
|
20278
|
+
server.removeAllListeners("listening");
|
|
20279
|
+
const onError = (err) => {
|
|
20280
|
+
if (err.code === "EADDRINUSE" && attempts < limit) {
|
|
20281
|
+
attempts += 1;
|
|
20282
|
+
const next = port + 1;
|
|
20283
|
+
console.warn(`[server] \u7AEF\u53E3 ${port} \u5DF2\u88AB\u5360\u7528\uFF08EADDRINUSE\uFF09\uFF0C\u5C1D\u8BD5 ${next} \u2026`);
|
|
20284
|
+
tryListen(next);
|
|
20285
|
+
return;
|
|
20286
|
+
}
|
|
20287
|
+
server.removeListener("error", onError);
|
|
20288
|
+
console.error(
|
|
20289
|
+
`[server] \u65E0\u6CD5\u76D1\u542C ${host}:${port}\uFF1A${err.message}` + (err.code === "EADDRINUSE" ? `\uFF08\u5DF2\u5C1D\u8BD5 ${attempts + 1} \u4E2A\u7AEF\u53E3\u5747\u88AB\u5360\u7528\uFF09` : "")
|
|
20290
|
+
);
|
|
20291
|
+
reject(err);
|
|
20292
|
+
};
|
|
20293
|
+
server.once("error", onError);
|
|
20294
|
+
server.listen(port, host, () => {
|
|
20295
|
+
server.removeListener("error", onError);
|
|
20296
|
+
const addr = server.address();
|
|
20297
|
+
const actualPort = typeof addr === "object" && addr !== null ? addr.port : port;
|
|
20298
|
+
if (actualPort !== startPort) {
|
|
20299
|
+
console.warn(`[server] \u5DF2\u6539\u7528\u7AEF\u53E3 ${actualPort}\uFF08\u539F\u5B9A ${startPort} \u88AB\u5360\u7528\uFF09`);
|
|
20300
|
+
}
|
|
20301
|
+
try {
|
|
20302
|
+
fs31.mkdirSync(dataDir, { recursive: true });
|
|
20303
|
+
fs31.writeFileSync(path38.join(dataDir, "server-port"), `${actualPort}
|
|
20304
|
+
`);
|
|
20305
|
+
} catch {
|
|
20306
|
+
}
|
|
20307
|
+
resolve24(actualPort);
|
|
20308
|
+
});
|
|
20309
|
+
};
|
|
20310
|
+
tryListen(startPort);
|
|
20311
|
+
});
|
|
20312
|
+
}
|
|
20091
20313
|
function startServer(opts = {}) {
|
|
20092
20314
|
const dataDir = path38.resolve(opts.dataDir ?? env2("DATA_DIR") ?? DEFAULT_DATA_DIR);
|
|
20093
20315
|
const port = opts.port ?? Number(env2("PORT") ?? 8787);
|
|
@@ -20313,11 +20535,11 @@ function startServer(opts = {}) {
|
|
|
20313
20535
|
server.timeout = 0;
|
|
20314
20536
|
server.keepAliveTimeout = 65e3;
|
|
20315
20537
|
server.headersTimeout = 66e3;
|
|
20316
|
-
const ready = new Promise((
|
|
20317
|
-
server
|
|
20538
|
+
const ready = new Promise((resolve24, reject) => {
|
|
20539
|
+
listenWithPortFallback(server, port, host, dataDir).then((actualPort) => {
|
|
20318
20540
|
const info = {
|
|
20319
20541
|
host,
|
|
20320
|
-
port,
|
|
20542
|
+
port: actualPort,
|
|
20321
20543
|
dataDir,
|
|
20322
20544
|
adminKey,
|
|
20323
20545
|
fleetNodeId: fleet ? fleet.getNodeId() : void 0,
|
|
@@ -20330,8 +20552,8 @@ function startServer(opts = {}) {
|
|
|
20330
20552
|
printReady(info, qq);
|
|
20331
20553
|
}
|
|
20332
20554
|
updater?.start();
|
|
20333
|
-
|
|
20334
|
-
});
|
|
20555
|
+
resolve24(info);
|
|
20556
|
+
}, reject);
|
|
20335
20557
|
});
|
|
20336
20558
|
return {
|
|
20337
20559
|
store,
|
|
@@ -20467,7 +20689,7 @@ async function runWizard(rl2, store, opts) {
|
|
|
20467
20689
|
}
|
|
20468
20690
|
async function askHidden(rl2, prompt) {
|
|
20469
20691
|
if (!process.stdin.isTTY) return (await rl2.question(prompt)).trim();
|
|
20470
|
-
return new Promise((
|
|
20692
|
+
return new Promise((resolve24) => {
|
|
20471
20693
|
const saved = process.stdin.listeners("data");
|
|
20472
20694
|
process.stdin.removeAllListeners("data");
|
|
20473
20695
|
cliWrite(prompt);
|
|
@@ -20489,13 +20711,13 @@ async function askHidden(rl2, prompt) {
|
|
|
20489
20711
|
if (ch === "\r" || ch === "\n") {
|
|
20490
20712
|
cleanup();
|
|
20491
20713
|
cliWrite("\n");
|
|
20492
|
-
|
|
20714
|
+
resolve24(buf);
|
|
20493
20715
|
return;
|
|
20494
20716
|
}
|
|
20495
20717
|
if (ch === "") {
|
|
20496
20718
|
cleanup();
|
|
20497
20719
|
cliWrite("\n");
|
|
20498
|
-
|
|
20720
|
+
resolve24("");
|
|
20499
20721
|
return;
|
|
20500
20722
|
}
|
|
20501
20723
|
if (ch === "\x7F" || ch === "\b") {
|
|
@@ -20684,7 +20906,7 @@ function updateSessionMetaFile(stateDir2, sessionId, patch) {
|
|
|
20684
20906
|
// src/cli/debug.ts
|
|
20685
20907
|
init_esm_shims();
|
|
20686
20908
|
import * as fs33 from "fs";
|
|
20687
|
-
import * as
|
|
20909
|
+
import * as os9 from "os";
|
|
20688
20910
|
import * as path42 from "path";
|
|
20689
20911
|
var LOG_NAME = "zqagent-debug.log";
|
|
20690
20912
|
var TRUTHY = /^(1|true|yes|on)$/i;
|
|
@@ -20698,7 +20920,7 @@ function resolveLogFile() {
|
|
|
20698
20920
|
const explicit = process.env.ZQAGENT_DEBUG_LOG;
|
|
20699
20921
|
if (explicit) return path42.resolve(explicit);
|
|
20700
20922
|
const dir = process.env.ZQAGENT_DEBUG_DIR;
|
|
20701
|
-
return path42.join(dir ? path42.resolve(dir) :
|
|
20923
|
+
return path42.join(dir ? path42.resolve(dir) : os9.tmpdir(), LOG_NAME);
|
|
20702
20924
|
}
|
|
20703
20925
|
function enableDebug(argv = process.argv) {
|
|
20704
20926
|
if (enabled) return true;
|
|
@@ -21156,7 +21378,7 @@ function question(prompt) {
|
|
|
21156
21378
|
}
|
|
21157
21379
|
function readPassword(prompt) {
|
|
21158
21380
|
if (!process.stdin.isTTY) return question(prompt);
|
|
21159
|
-
return new Promise((
|
|
21381
|
+
return new Promise((resolve24) => {
|
|
21160
21382
|
const savedDataListeners = process.stdin.listeners("data");
|
|
21161
21383
|
process.stdin.removeAllListeners("data");
|
|
21162
21384
|
cliWrite(prompt);
|
|
@@ -21172,13 +21394,13 @@ function readPassword(prompt) {
|
|
|
21172
21394
|
if (ch === "\r" || ch === "\n") {
|
|
21173
21395
|
cleanup();
|
|
21174
21396
|
cliWrite("\n");
|
|
21175
|
-
|
|
21397
|
+
resolve24(buf);
|
|
21176
21398
|
return;
|
|
21177
21399
|
}
|
|
21178
21400
|
if (ch === "") {
|
|
21179
21401
|
cleanup();
|
|
21180
21402
|
cliWrite("\n");
|
|
21181
|
-
|
|
21403
|
+
resolve24("");
|
|
21182
21404
|
return;
|
|
21183
21405
|
}
|
|
21184
21406
|
if (ch === "\x7F" || ch === "\b") {
|
|
@@ -21613,7 +21835,7 @@ async function offerTerminalSetup(engine, canUseAgent) {
|
|
|
21613
21835
|
}
|
|
21614
21836
|
var KNOWN_SUBCOMMANDS = /* @__PURE__ */ new Set(["link", "serve", "update"]);
|
|
21615
21837
|
function cliVersion() {
|
|
21616
|
-
const env3 = "0.2.
|
|
21838
|
+
const env3 = "0.2.10"?.trim();
|
|
21617
21839
|
if (env3) return env3;
|
|
21618
21840
|
try {
|
|
21619
21841
|
const req2 = createRequire4(import.meta.url);
|