engine7 7.1.130 → 7.1.132
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.mjs +41 -9
- package/dist/engine-startup.mjs +424 -107
- package/dist/main.mjs +424 -107
- package/package.json +1 -1
package/dist/main.mjs
CHANGED
|
@@ -29138,6 +29138,18 @@ function defaultProviderKey(cfg) {
|
|
|
29138
29138
|
}
|
|
29139
29139
|
return "";
|
|
29140
29140
|
}
|
|
29141
|
+
function needsMem7EnableForFreeInstall(cfg) {
|
|
29142
|
+
if (cfg?.mem7?.enabled !== void 0) return false;
|
|
29143
|
+
if (!cfg?.models?.providers?.[FREE_TIER_PROVIDER_ID]) return false;
|
|
29144
|
+
return defaultProviderKey(cfg) !== "";
|
|
29145
|
+
}
|
|
29146
|
+
async function applyMem7EnableForFreeInstall(io) {
|
|
29147
|
+
const cfg = io.all();
|
|
29148
|
+
if (!needsMem7EnableForFreeInstall(cfg)) return false;
|
|
29149
|
+
const changed = await io.set("mem7.enabled", true);
|
|
29150
|
+
if (changed) console.log("[startup] mem7 enabled for legacy free-tier install (1026 \u51B3\u7B56\u8865\u5168\uFF0C1102)");
|
|
29151
|
+
return changed === true;
|
|
29152
|
+
}
|
|
29141
29153
|
function usesDefaultProvider(cfg) {
|
|
29142
29154
|
const defaults = mem7ServiceDefaults(cfg.mem7, cfg.everos?.rerank);
|
|
29143
29155
|
return Object.keys(defaults).length > 0 || [cfg.mem7?.embedding, cfg.mem7?.rerank ?? cfg.everos?.rerank].some((service) => typeof service?.model === "string" && service.model.startsWith(`${FREE_TIER_PROVIDER_ID}/`));
|
|
@@ -29214,6 +29226,96 @@ var init_mem7_services_fixup = __esm({
|
|
|
29214
29226
|
}
|
|
29215
29227
|
});
|
|
29216
29228
|
|
|
29229
|
+
// src/free-tier-apply.ts
|
|
29230
|
+
function isFreeTierConfig(cfg) {
|
|
29231
|
+
const hasProvider = !!cfg?.models?.providers?.[FREE_TIER_PROVIDER_ID];
|
|
29232
|
+
const primary = String(cfg?.agents?.defaults?.model?.primary || "");
|
|
29233
|
+
return hasProvider && primary.startsWith(`${FREE_TIER_PROVIDER_ID}/`);
|
|
29234
|
+
}
|
|
29235
|
+
var init_free_tier_apply = __esm({
|
|
29236
|
+
"src/free-tier-apply.ts"() {
|
|
29237
|
+
"use strict";
|
|
29238
|
+
init_cli_init_config();
|
|
29239
|
+
init_provision_free();
|
|
29240
|
+
init_cli_init_config();
|
|
29241
|
+
}
|
|
29242
|
+
});
|
|
29243
|
+
|
|
29244
|
+
// src/startup/free-tier-nort-fixup.ts
|
|
29245
|
+
function legacyDefaultExtract(cfg) {
|
|
29246
|
+
const ex = cfg?.topics?.extract;
|
|
29247
|
+
if (typeof ex?.model !== "string") return false;
|
|
29248
|
+
const model = ex.model.trim();
|
|
29249
|
+
const provider = typeof ex.provider === "string" ? ex.provider.trim() : "";
|
|
29250
|
+
if (model === FREE_TIER_FAST_REF && (!provider || provider === FREE_TIER_PROVIDER_ID)) return true;
|
|
29251
|
+
return provider === FREE_TIER_PROVIDER_ID && (LANE_MODELS.some((id) => id === model) || model === FREE_TIER_NORT_REF);
|
|
29252
|
+
}
|
|
29253
|
+
function needsFreeTierNortFixup(cfg) {
|
|
29254
|
+
const free = isFreeTierConfig(cfg);
|
|
29255
|
+
if (!free && !legacyDefaultExtract(cfg)) return false;
|
|
29256
|
+
const provider = cfg?.models?.providers?.[FREE_TIER_PROVIDER_ID];
|
|
29257
|
+
if (!provider) return false;
|
|
29258
|
+
const lanes = free || readPath(cfg, "topics.clean.model") === void 0 ? LANE_MODELS : [FREE_TIER_NORT_MODEL];
|
|
29259
|
+
if (lanes.some((id) => !(provider.models || []).some((m) => m?.id === id))) return true;
|
|
29260
|
+
return free && Object.keys(FIELD_REFS).some((path86) => readPath(cfg, path86) === void 0) || legacyDefaultExtract(cfg);
|
|
29261
|
+
}
|
|
29262
|
+
function readPath(obj, dotPath) {
|
|
29263
|
+
return dotPath.split(".").reduce((acc, k) => acc == null ? void 0 : acc[k], obj);
|
|
29264
|
+
}
|
|
29265
|
+
async function applyFreeTierNortFixup(io) {
|
|
29266
|
+
const cfg = io.all();
|
|
29267
|
+
if (!needsFreeTierNortFixup(cfg)) return false;
|
|
29268
|
+
const provider = cfg.models.providers[FREE_TIER_PROVIDER_ID];
|
|
29269
|
+
const registry2 = PROVIDER_DEFS[FREE_TIER_PROVIDER_ID]?.models ?? [];
|
|
29270
|
+
const free = isFreeTierConfig(cfg);
|
|
29271
|
+
const lanes = free || readPath(cfg, "topics.clean.model") === void 0 ? LANE_MODELS : [FREE_TIER_NORT_MODEL];
|
|
29272
|
+
const missingEntries = lanes.filter((id) => !(provider.models || []).some((m) => m?.id === id)).map((id) => registry2.find((m) => m.id === id));
|
|
29273
|
+
if (missingEntries.some((entry) => !entry)) return false;
|
|
29274
|
+
const writes = [];
|
|
29275
|
+
if (missingEntries.length) {
|
|
29276
|
+
const newModels = [...provider.models || [], ...missingEntries.map((entry) => ({ ...entry }))];
|
|
29277
|
+
writes.push([`models.providers.${FREE_TIER_PROVIDER_ID}.models`, newModels]);
|
|
29278
|
+
const pCopy = cfg.providers?.[FREE_TIER_PROVIDER_ID];
|
|
29279
|
+
if (pCopy && pCopy !== provider) pCopy.models = newModels;
|
|
29280
|
+
}
|
|
29281
|
+
for (const [path86, ref] of Object.entries(FIELD_REFS)) {
|
|
29282
|
+
if (free && readPath(cfg, path86) === void 0) writes.push([path86, ref]);
|
|
29283
|
+
}
|
|
29284
|
+
if (!free && readPath(cfg, "topics.clean.model") === void 0) {
|
|
29285
|
+
writes.push(["topics.clean.model", FREE_TIER_FAST_REF]);
|
|
29286
|
+
}
|
|
29287
|
+
const migratedLegacyExtract = legacyDefaultExtract(cfg);
|
|
29288
|
+
if (migratedLegacyExtract) {
|
|
29289
|
+
writes.push(["topics.extract.model", FREE_TIER_NORT_REF]);
|
|
29290
|
+
if ("provider" in cfg.topics.extract) writes.push(["topics.extract.provider", void 0]);
|
|
29291
|
+
}
|
|
29292
|
+
if (!writes.length) return false;
|
|
29293
|
+
let persisted = true;
|
|
29294
|
+
for (const [path86, value] of writes) {
|
|
29295
|
+
if (await io.set(path86, value) === false) persisted = false;
|
|
29296
|
+
}
|
|
29297
|
+
if (!persisted) {
|
|
29298
|
+
console.error("[startup] \u540E\u53F0\u6A21\u578B\u8865\u9F50 **\u672A\u5168\u90E8\u843D\u76D8**\uFF08\u672C\u6B21\u8FD0\u884C\u5185\u5B58\u91CC\u5DF2\u751F\u6548\uFF0C\u914D\u7F6E\u6587\u4EF6\u4ECD\u662F\u65E7\u7684\u2014\u2014\u4E0B\u6B21\u542F\u52A8\u4F1A\u91CD\u653E\uFF09\u3002\u4E0A\u9762 [liveConfig] \u90A3\u51E0\u884C\u662F\u539F\u56E0\u3002");
|
|
29299
|
+
return true;
|
|
29300
|
+
}
|
|
29301
|
+
console.log(`[startup] \u540E\u53F0\u6A21\u578B\u914D\u7F6E\u5DF2\u8865\u9F50\uFF08${writes.map(([p]) => p).join(", ")}\uFF1B\u81EA\u5B9A\u4E49\u6A21\u578B\u4FDD\u7559${migratedLegacyExtract ? `\uFF1B\u65E7\u9ED8\u8BA4 extract \u5DF2\u8FC1 ${FREE_TIER_NORT_REF}` : ""}\uFF09`);
|
|
29302
|
+
return true;
|
|
29303
|
+
}
|
|
29304
|
+
var FIELD_REFS, LANE_MODELS;
|
|
29305
|
+
var init_free_tier_nort_fixup = __esm({
|
|
29306
|
+
"src/startup/free-tier-nort-fixup.ts"() {
|
|
29307
|
+
"use strict";
|
|
29308
|
+
init_cli_init_config();
|
|
29309
|
+
init_free_tier_apply();
|
|
29310
|
+
FIELD_REFS = {
|
|
29311
|
+
"topics.extract.model": FREE_TIER_NORT_REF,
|
|
29312
|
+
"topics.clean.model": FREE_TIER_FAST_REF,
|
|
29313
|
+
"innerVoice.model": FREE_TIER_NORT_REF
|
|
29314
|
+
};
|
|
29315
|
+
LANE_MODELS = [FREE_TIER_FAST_MODEL, FREE_TIER_NORT_MODEL];
|
|
29316
|
+
}
|
|
29317
|
+
});
|
|
29318
|
+
|
|
29217
29319
|
// src/reload/orchestrator.ts
|
|
29218
29320
|
function sliceEnabled(slice) {
|
|
29219
29321
|
if (slice == null) return false;
|
|
@@ -29457,6 +29559,7 @@ async function doReloadConfigInner(config2, deps, provider, force = false) {
|
|
|
29457
29559
|
});
|
|
29458
29560
|
reloadOrchestrator.beginReload();
|
|
29459
29561
|
liveConfig.assign(newConfig);
|
|
29562
|
+
await applyFreeTierNortFixup({ all: () => liveConfig.all(), set: (p, v) => liveConfig.set(p, v) });
|
|
29460
29563
|
await applyMem7ServicesFixup({ all: () => liveConfig.all(), set: (p, v) => liveConfig.set(p, v) });
|
|
29461
29564
|
console.log(`[reload-debug] newConfig.tools.my_voice.provider = ${newConfig?.tools?.my_voice?.provider}`);
|
|
29462
29565
|
console.log(`[reload-debug] post-assign liveConfig.tools.my_voice = ${JSON.stringify(liveConfig.get("tools.my_voice"))}`);
|
|
@@ -29697,6 +29800,7 @@ function startSecretsWatcher(config2, deps, provider, watchFn = fs14.watch) {
|
|
|
29697
29800
|
try {
|
|
29698
29801
|
const content = fs14.readFileSync(p, "utf-8");
|
|
29699
29802
|
let updated = 0;
|
|
29803
|
+
const changedKeys = [];
|
|
29700
29804
|
for (const line of content.split("\n")) {
|
|
29701
29805
|
const trimmed = line.trim();
|
|
29702
29806
|
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
@@ -29705,12 +29809,13 @@ function startSecretsWatcher(config2, deps, provider, watchFn = fs14.watch) {
|
|
|
29705
29809
|
const k = trimmed.slice(0, eq).trim();
|
|
29706
29810
|
const v = trimmed.slice(eq + 1).trim();
|
|
29707
29811
|
if (k) {
|
|
29812
|
+
if (process.env[k] !== v) changedKeys.push(k);
|
|
29708
29813
|
process.env[k] = v;
|
|
29709
29814
|
updated++;
|
|
29710
29815
|
}
|
|
29711
29816
|
}
|
|
29712
29817
|
}
|
|
29713
|
-
console.log(`[secrets-watch] ${updated} keys
|
|
29818
|
+
console.log(`[secrets-watch] ${updated} keys loaded, ${changedKeys.length} changed` + (changedKeys.length ? `: ${changedKeys.join(", ")} (values not logged)` : "") + ` \u2014 from ${p}`);
|
|
29714
29819
|
console.log(`[secrets-watch] force reload\uFF08\u8DF3\u8FC7\u539F\u6587\u5BF9\u6BD4\uFF09`);
|
|
29715
29820
|
const result = await doReloadConfig(config2, deps, provider, true);
|
|
29716
29821
|
console.log(`[secrets-watch] config reloaded: ok=${result.ok} changes=${result.changes.join(",")}`);
|
|
@@ -29766,6 +29871,7 @@ var init_reload = __esm({
|
|
|
29766
29871
|
"use strict";
|
|
29767
29872
|
init_loader();
|
|
29768
29873
|
init_mem7_services_fixup();
|
|
29874
|
+
init_free_tier_nort_fixup();
|
|
29769
29875
|
init_live();
|
|
29770
29876
|
init_secrets_env();
|
|
29771
29877
|
init_orchestrator();
|
|
@@ -38608,6 +38714,27 @@ var init_ffmpeg_path = __esm({
|
|
|
38608
38714
|
}
|
|
38609
38715
|
});
|
|
38610
38716
|
|
|
38717
|
+
// src/utils/api-port.ts
|
|
38718
|
+
var api_port_exports = {};
|
|
38719
|
+
__export(api_port_exports, {
|
|
38720
|
+
computeApiPort: () => computeApiPort
|
|
38721
|
+
});
|
|
38722
|
+
function computeApiPort(config2) {
|
|
38723
|
+
const basePort = config2.api?.port || 16890;
|
|
38724
|
+
const profileId = config2.profile?.id;
|
|
38725
|
+
if (profileId && profileId !== "default") {
|
|
38726
|
+
let hash6 = 0;
|
|
38727
|
+
for (const ch of profileId) hash6 = (hash6 << 5) - hash6 + ch.charCodeAt(0) | 0;
|
|
38728
|
+
return basePort + Math.abs(hash6) % 100;
|
|
38729
|
+
}
|
|
38730
|
+
return basePort;
|
|
38731
|
+
}
|
|
38732
|
+
var init_api_port = __esm({
|
|
38733
|
+
"src/utils/api-port.ts"() {
|
|
38734
|
+
"use strict";
|
|
38735
|
+
}
|
|
38736
|
+
});
|
|
38737
|
+
|
|
38611
38738
|
// src/startup/skill-sync.ts
|
|
38612
38739
|
import * as fs22 from "node:fs";
|
|
38613
38740
|
import * as path19 from "node:path";
|
|
@@ -43996,8 +44123,12 @@ ${conversationText}`
|
|
|
43996
44123
|
let result = "";
|
|
43997
44124
|
let completed = false;
|
|
43998
44125
|
let hadError = false;
|
|
44126
|
+
let completionReason;
|
|
43999
44127
|
for await (const chunk of extractEngine.query(extractMessages, void 0, toolContext)) {
|
|
44000
|
-
if (chunk.type === "result")
|
|
44128
|
+
if (chunk.type === "result") {
|
|
44129
|
+
completionReason = chunk.completionReason;
|
|
44130
|
+
completed = completionReason === "completed";
|
|
44131
|
+
}
|
|
44001
44132
|
if (chunk.type === "error" || chunk.type === "tool_result" && chunk.isError) hadError = true;
|
|
44002
44133
|
if (chunk.type === "text" && chunk.text) {
|
|
44003
44134
|
result += chunk.text;
|
|
@@ -44007,7 +44138,7 @@ ${conversationText}`
|
|
|
44007
44138
|
}
|
|
44008
44139
|
}
|
|
44009
44140
|
if (!completed || hadError || generation !== (state2.generations.get(sessionId) ?? 0)) {
|
|
44010
|
-
console.warn(`[memory] extractMemories incomplete \u2014 input remains eligible, tools=${toolCount}, error=${hadError}`);
|
|
44141
|
+
console.warn(`[memory] extractMemories incomplete \u2014 input remains eligible, tools=${toolCount}, error=${hadError}, reason=${completionReason ?? "unknown"}, reset=${generation !== (state2.generations.get(sessionId) ?? 0)}`);
|
|
44011
44142
|
return;
|
|
44012
44143
|
}
|
|
44013
44144
|
if (maxNewTs > 0) state2.lastTs.set(sessionId, maxNewTs);
|
|
@@ -44034,11 +44165,15 @@ ${conversationText}`
|
|
|
44034
44165
|
},
|
|
44035
44166
|
execute(messages, provider, model, sessionId, disableThinking, intervalMinutes) {
|
|
44036
44167
|
if (!enabled) return Promise.resolve();
|
|
44168
|
+
const generation = state2.generations.get(sessionId) ?? 0;
|
|
44037
44169
|
const previous = state2.tail;
|
|
44038
44170
|
const lastTime = state2.lastExtractTime.get(sessionId);
|
|
44039
44171
|
const alreadyCoolingDown = Boolean(intervalMinutes && intervalMinutes > 0 && lastTime && Date.now() - lastTime < intervalMinutes * 6e4);
|
|
44040
44172
|
const snapshot = structuredClone(messages);
|
|
44041
|
-
const task = (previous ?? Promise.resolve()).then(() =>
|
|
44173
|
+
const task = (previous ?? Promise.resolve()).then(() => {
|
|
44174
|
+
if (generation !== (state2.generations.get(sessionId) ?? 0)) return;
|
|
44175
|
+
return extract(snapshot, provider, model, sessionId, disableThinking, previous && !alreadyCoolingDown ? 0 : intervalMinutes);
|
|
44176
|
+
});
|
|
44042
44177
|
const tail2 = task.finally(() => {
|
|
44043
44178
|
if (state2.tail === tail2) state2.tail = void 0;
|
|
44044
44179
|
});
|
|
@@ -48483,27 +48618,6 @@ var init_qr_render = __esm({
|
|
|
48483
48618
|
}
|
|
48484
48619
|
});
|
|
48485
48620
|
|
|
48486
|
-
// src/utils/api-port.ts
|
|
48487
|
-
var api_port_exports = {};
|
|
48488
|
-
__export(api_port_exports, {
|
|
48489
|
-
computeApiPort: () => computeApiPort
|
|
48490
|
-
});
|
|
48491
|
-
function computeApiPort(config2) {
|
|
48492
|
-
const basePort = config2.api?.port || 16890;
|
|
48493
|
-
const profileId = config2.profile?.id;
|
|
48494
|
-
if (profileId && profileId !== "default") {
|
|
48495
|
-
let hash6 = 0;
|
|
48496
|
-
for (const ch of profileId) hash6 = (hash6 << 5) - hash6 + ch.charCodeAt(0) | 0;
|
|
48497
|
-
return basePort + Math.abs(hash6) % 100;
|
|
48498
|
-
}
|
|
48499
|
-
return basePort;
|
|
48500
|
-
}
|
|
48501
|
-
var init_api_port = __esm({
|
|
48502
|
-
"src/utils/api-port.ts"() {
|
|
48503
|
-
"use strict";
|
|
48504
|
-
}
|
|
48505
|
-
});
|
|
48506
|
-
|
|
48507
48621
|
// src/version.ts
|
|
48508
48622
|
import { readFileSync as readFileSync57 } from "node:fs";
|
|
48509
48623
|
import { dirname as dirname23, join as join77 } from "node:path";
|
|
@@ -49431,7 +49545,7 @@ __export(voice_chat_tts_daemon_exports, {
|
|
|
49431
49545
|
stopTtsDaemon: () => stopTtsDaemon
|
|
49432
49546
|
});
|
|
49433
49547
|
import { spawn as spawn5 } from "child_process";
|
|
49434
|
-
import
|
|
49548
|
+
import net3 from "net";
|
|
49435
49549
|
import path54 from "path";
|
|
49436
49550
|
import fs53 from "fs";
|
|
49437
49551
|
function _log(msg2) {
|
|
@@ -49439,7 +49553,7 @@ function _log(msg2) {
|
|
|
49439
49553
|
}
|
|
49440
49554
|
function _healthOnce() {
|
|
49441
49555
|
return new Promise((resolve26) => {
|
|
49442
|
-
const sock =
|
|
49556
|
+
const sock = net3.connect(SOCK_PATH);
|
|
49443
49557
|
sock.setTimeout(2e3);
|
|
49444
49558
|
sock.on("connect", () => {
|
|
49445
49559
|
sock.write(JSON.stringify({ action: "health" }) + "\n");
|
|
@@ -54706,12 +54820,18 @@ function splitBubbles(message) {
|
|
|
54706
54820
|
init_providers();
|
|
54707
54821
|
init_reload();
|
|
54708
54822
|
|
|
54823
|
+
// src/reload/channels-entry.ts
|
|
54824
|
+
function channelsSelectSlice(cfg) {
|
|
54825
|
+
return { enabled: true, channels: cfg?.channels ?? null };
|
|
54826
|
+
}
|
|
54827
|
+
|
|
54709
54828
|
// src/startup/bootstrap.ts
|
|
54710
54829
|
import * as fs24 from "node:fs";
|
|
54711
54830
|
import * as path21 from "node:path";
|
|
54712
54831
|
|
|
54713
54832
|
// src/pid-lock.ts
|
|
54714
54833
|
import fs15 from "node:fs";
|
|
54834
|
+
import net from "node:net";
|
|
54715
54835
|
import path14 from "node:path";
|
|
54716
54836
|
import { execSync as execSync2 } from "node:child_process";
|
|
54717
54837
|
function enginePidFile(stateDir) {
|
|
@@ -54723,7 +54843,25 @@ function isEngineImage(text) {
|
|
|
54723
54843
|
function isPidAlive(pid) {
|
|
54724
54844
|
try {
|
|
54725
54845
|
process.kill(pid, 0);
|
|
54726
|
-
|
|
54846
|
+
} catch (err) {
|
|
54847
|
+
return err?.code === "EPERM";
|
|
54848
|
+
}
|
|
54849
|
+
return !isPidZombie(pid);
|
|
54850
|
+
}
|
|
54851
|
+
function statFieldIsZombie(statContent) {
|
|
54852
|
+
const state2 = statContent.slice(statContent.lastIndexOf(")") + 2).trim().charAt(0);
|
|
54853
|
+
return state2 === "Z";
|
|
54854
|
+
}
|
|
54855
|
+
function isPidZombie(pid) {
|
|
54856
|
+
try {
|
|
54857
|
+
if (process.platform === "linux") {
|
|
54858
|
+
return statFieldIsZombie(fs15.readFileSync(`/proc/${pid}/stat`, "utf-8"));
|
|
54859
|
+
}
|
|
54860
|
+
if (process.platform === "darwin") {
|
|
54861
|
+
const st = execSync2(`ps -p ${pid} -o stat=`, { encoding: "utf-8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
54862
|
+
return st.trim().startsWith("Z");
|
|
54863
|
+
}
|
|
54864
|
+
return false;
|
|
54727
54865
|
} catch {
|
|
54728
54866
|
return false;
|
|
54729
54867
|
}
|
|
@@ -54806,6 +54944,206 @@ function ownEnginePid(stateDir, myPid = process.pid) {
|
|
|
54806
54944
|
isEngineImage: probeEngineImage
|
|
54807
54945
|
});
|
|
54808
54946
|
}
|
|
54947
|
+
function decidePortEviction(probe) {
|
|
54948
|
+
if (probe.ownerPid === null) return { action: "none" };
|
|
54949
|
+
if (probe.ownerPid === probe.myPid) return { action: "skip-self", pid: probe.ownerPid };
|
|
54950
|
+
const image = probe.imageText ?? "";
|
|
54951
|
+
if (!isEngineImage(image)) return { action: "skip-foreign", pid: probe.ownerPid, reason: "image" };
|
|
54952
|
+
if (imageBasename(image) === "engine7") return { action: "kill", pid: probe.ownerPid };
|
|
54953
|
+
if (probe.commandLineOk === true) return { action: "kill", pid: probe.ownerPid };
|
|
54954
|
+
if (probe.commandLineOk === false) return { action: "skip-foreign", pid: probe.ownerPid, reason: "cmdline" };
|
|
54955
|
+
return { action: "skip-foreign", pid: probe.ownerPid, reason: "cmdline-unprobeable" };
|
|
54956
|
+
}
|
|
54957
|
+
function imageBasename(imageText) {
|
|
54958
|
+
const s = (imageText ?? "").trim();
|
|
54959
|
+
if (!s) return "";
|
|
54960
|
+
const firstField = s.split(",")[0].trim().replace(/^"|"$/g, "");
|
|
54961
|
+
const base = firstField.split(/[\\/]/).pop() ?? firstField;
|
|
54962
|
+
return base.replace(/\.exe$/i, "").toLowerCase();
|
|
54963
|
+
}
|
|
54964
|
+
function pickConflictingPortOwners(probeOutput, port, myPid = process.pid) {
|
|
54965
|
+
if (!probeOutput) return [];
|
|
54966
|
+
const out = /* @__PURE__ */ new Set();
|
|
54967
|
+
const conflict = (addr) => {
|
|
54968
|
+
let a = addr.replace(/^\[/, "").replace(/\]$/, "").toLowerCase();
|
|
54969
|
+
if (a.startsWith("::ffff:")) a = a.slice("::ffff:".length);
|
|
54970
|
+
return a === "*" || a === "0.0.0.0" || a === "127.0.0.1" || a === "::";
|
|
54971
|
+
};
|
|
54972
|
+
for (const line of probeOutput.split(/\r?\n/)) {
|
|
54973
|
+
const net5 = /^\s*TCP\s+(\S*?):(\d+)\s+\S+\s+LISTENING\s+(\d+)\s*$/i.exec(line);
|
|
54974
|
+
if (net5) {
|
|
54975
|
+
const pid = Number(net5[3]);
|
|
54976
|
+
if (Number(net5[2]) === port && conflict(net5[1]) && pid !== myPid) out.add(pid);
|
|
54977
|
+
continue;
|
|
54978
|
+
}
|
|
54979
|
+
const cols = line.trim().split(/\s+/);
|
|
54980
|
+
if (cols.length >= 9 && /^\d+$/.test(cols[1] ?? "")) {
|
|
54981
|
+
const pid = Number(cols[1]);
|
|
54982
|
+
let name = cols[cols.length - 1] ?? "";
|
|
54983
|
+
if (/^\(/.test(name)) name = cols[cols.length - 2] ?? "";
|
|
54984
|
+
const lp = name.lastIndexOf(":");
|
|
54985
|
+
if (lp > 0 && Number(name.slice(lp + 1)) === port && conflict(name.slice(0, lp)) && pid !== myPid) out.add(pid);
|
|
54986
|
+
continue;
|
|
54987
|
+
}
|
|
54988
|
+
if (line.includes("pid=")) {
|
|
54989
|
+
const m = /^\S+\s+\d+\s+\d+\s+(\S+?):(\d+)\s/.exec(line);
|
|
54990
|
+
const pids = [...line.matchAll(/pid=(\d+)/g)].map((x) => Number(x[1]));
|
|
54991
|
+
if (m && Number(m[2]) === port && conflict(m[1])) {
|
|
54992
|
+
for (const pid of pids) if (pid !== myPid) out.add(pid);
|
|
54993
|
+
}
|
|
54994
|
+
}
|
|
54995
|
+
}
|
|
54996
|
+
return [...out];
|
|
54997
|
+
}
|
|
54998
|
+
function probePortOwnersRaw(port) {
|
|
54999
|
+
try {
|
|
55000
|
+
if (process.platform === "win32") {
|
|
55001
|
+
return { output: execSync2("netstat -ano -p tcp", {
|
|
55002
|
+
encoding: "utf-8",
|
|
55003
|
+
timeout: 5e3,
|
|
55004
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
55005
|
+
windowsHide: true
|
|
55006
|
+
// 1011:GUI 宿主下别闪黑窗
|
|
55007
|
+
}), unknown: false };
|
|
55008
|
+
}
|
|
55009
|
+
if (process.platform === "darwin") {
|
|
55010
|
+
return { output: execSync2(`lsof -nP -iTCP:${port} -sTCP:LISTEN`, {
|
|
55011
|
+
encoding: "utf-8",
|
|
55012
|
+
timeout: 5e3,
|
|
55013
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
55014
|
+
}), unknown: false };
|
|
55015
|
+
}
|
|
55016
|
+
return { output: execSync2(`ss -lptn sport = :${port}`, {
|
|
55017
|
+
encoding: "utf-8",
|
|
55018
|
+
timeout: 5e3,
|
|
55019
|
+
stdio: ["ignore", "pipe", "ignore"]
|
|
55020
|
+
}), unknown: false };
|
|
55021
|
+
} catch (err) {
|
|
55022
|
+
const status = err?.status;
|
|
55023
|
+
const unknown = status === null || status === void 0 || status === 127 || status > 1 || err?.code === "ENOENT" || err?.code === "ETIMEDOUT";
|
|
55024
|
+
return { output: null, unknown };
|
|
55025
|
+
}
|
|
55026
|
+
}
|
|
55027
|
+
function engineCommandlineMentions(pid, stateDir) {
|
|
55028
|
+
let cmd = "";
|
|
55029
|
+
try {
|
|
55030
|
+
if (process.platform === "win32") {
|
|
55031
|
+
cmd = execSync2(
|
|
55032
|
+
`powershell -NoProfile -Command "(Get-CimInstance Win32_Process -Filter 'ProcessId=${pid}').CommandLine"`,
|
|
55033
|
+
{ encoding: "utf-8", timeout: 1e4, stdio: ["ignore", "pipe", "ignore"], windowsHide: true }
|
|
55034
|
+
);
|
|
55035
|
+
} else if (process.platform === "darwin") {
|
|
55036
|
+
cmd = execSync2(`ps -p ${pid} -o command=`, { encoding: "utf-8", timeout: 3e3, stdio: ["ignore", "pipe", "ignore"] });
|
|
55037
|
+
} else {
|
|
55038
|
+
cmd = fs15.readFileSync(`/proc/${pid}/cmdline`, "utf-8").replace(/\0/g, " ");
|
|
55039
|
+
}
|
|
55040
|
+
} catch {
|
|
55041
|
+
return false;
|
|
55042
|
+
}
|
|
55043
|
+
return commandlineMentionsEngine(cmd, stateDir);
|
|
55044
|
+
}
|
|
55045
|
+
function commandlineMentionsEngine(cmd, stateDir) {
|
|
55046
|
+
const normalized = (cmd || "").toLowerCase();
|
|
55047
|
+
const dir = (stateDir || "").toLowerCase();
|
|
55048
|
+
if (dir && normalized.includes(dir)) return true;
|
|
55049
|
+
return /(?:^|[\\/":\s])engine7(?=$|[\\/."'\s])/.test(normalized);
|
|
55050
|
+
}
|
|
55051
|
+
function classifyPortOwner(pid, stateDir, myPid) {
|
|
55052
|
+
const imageText = probeImage(pid);
|
|
55053
|
+
const commandLineOk = imageBasename(imageText) === "engine7" ? true : /^(node|electron)(\.exe)?$/i.test(imageBasename(imageText)) ? engineCommandlineMentions(pid, stateDir) : false;
|
|
55054
|
+
return { decision: decidePortEviction({ ownerPid: pid, imageText, commandLineOk, myPid }), imageText };
|
|
55055
|
+
}
|
|
55056
|
+
function skipReason(decision) {
|
|
55057
|
+
return decision.action === "skip-self" ? "\u672C\u8FDB\u7A0B" : decision.action === "skip-foreign" && decision.reason === "image" ? "\u975E\u5F15\u64CE\u6620\u50CF" : decision.action === "skip-foreign" && decision.reason === "cmdline" ? "\u547D\u4EE4\u884C\u4E0D\u542B engine7/stateDir\uFF08\u65E0\u5173 node \u7A0B\u5E8F\uFF09" : "\u547D\u4EE4\u884C\u63A2\u4E0D\u5230\uFF08\u4FDD\u5B88\u4E0D\u6740\uFF09";
|
|
55058
|
+
}
|
|
55059
|
+
async function evictEngineOnApiPort(stateDir, apiPort, myPid = process.pid) {
|
|
55060
|
+
const probe1 = probePortOwnersRaw(apiPort);
|
|
55061
|
+
if (probe1.unknown) {
|
|
55062
|
+
console.error(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u6E05\u573A\u63A2\u9488\u8DD1\u4E0D\u4E86\uFF08\u547D\u4EE4\u7F3A\u5931/\u8D85\u65F6\uFF09\u2014\u2014\u515C\u5E95\u8FD9\u8F6E\u5931\u6548\uFF0C\u7531\u62A2\u9501\u65B9\u8BD5\u7ED1\u7AEF\u53E3\u88C1\u51B3\u3002`);
|
|
55063
|
+
return { killed: [], blockedKind: "foreign", probeUnknown: true, remaining: [] };
|
|
55064
|
+
}
|
|
55065
|
+
const owners = pickConflictingPortOwners(probe1.output, apiPort, myPid);
|
|
55066
|
+
const killed = [];
|
|
55067
|
+
let sawUndead = false;
|
|
55068
|
+
for (const pid of owners) {
|
|
55069
|
+
const { decision, imageText } = classifyPortOwner(pid, stateDir, myPid);
|
|
55070
|
+
if (decision.action !== "kill") {
|
|
55071
|
+
console.error(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u88AB\u975E\u6E05\u573A\u76EE\u6807\u5360\u7528\uFF08pid ${pid}\uFF0C\u6620\u50CF ${(imageText ?? "").trim().slice(0, 60) || "\u63A2\u4E0D\u5230"}\uFF1B${skipReason(decision)}\uFF09\u2014\u2014\u4E0D\u52A8\u5B83\u3002`);
|
|
55072
|
+
continue;
|
|
55073
|
+
}
|
|
55074
|
+
console.log(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u88AB\u65E7\u5F15\u64CE\u5B9E\u4F8B\u5360\u7528\uFF08pid ${pid}\uFF09\uFF0C\u6E05\u573A...`);
|
|
55075
|
+
killAndLog(stateDir, pid, `api port ${apiPort} occupied by stale engine`);
|
|
55076
|
+
if (await waitForPidGone(pid)) killed.push(pid);
|
|
55077
|
+
else sawUndead = true;
|
|
55078
|
+
}
|
|
55079
|
+
const probe2 = probePortOwnersRaw(apiPort);
|
|
55080
|
+
if (probe2.unknown) {
|
|
55081
|
+
if (sawUndead) {
|
|
55082
|
+
console.error(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u7684\u65E7\u5F15\u64CE\u6CA1\u80FD\u6740\u6389\uFF0C\u4E14\u590D\u6838\u63A2\u9488\u4E5F\u5931\u6548\u2014\u2014\u6309\u53CC\u5F00\u98CE\u9669\u5904\u7406\uFF0C\u5F15\u64CE\u62D2\u7EDD\u5E26\u75C5\u542F\u52A8\u3002`);
|
|
55083
|
+
return { killed, blockedKind: "undead", probeUnknown: true, remaining: [] };
|
|
55084
|
+
}
|
|
55085
|
+
console.error(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u590D\u6838\u63A2\u9488\u5931\u6548\u2014\u2014\u7531\u62A2\u9501\u65B9\u8BD5\u7ED1\u7AEF\u53E3\u88C1\u51B3\u3002`);
|
|
55086
|
+
return { killed, blockedKind: "foreign", probeUnknown: true, remaining: [] };
|
|
55087
|
+
}
|
|
55088
|
+
for (const pid of pickConflictingPortOwners(probe2.output, apiPort, myPid)) {
|
|
55089
|
+
const { decision, imageText } = classifyPortOwner(pid, stateDir, myPid);
|
|
55090
|
+
if (decision.action !== "kill") {
|
|
55091
|
+
console.error(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u88AB\u975E\u6E05\u573A\u76EE\u6807\u5360\u7528\uFF08pid ${pid}\uFF0C\u6620\u50CF ${(imageText ?? "").trim().slice(0, 60) || "\u63A2\u4E0D\u5230"}\uFF1B${skipReason(decision)}\uFF09\u2014\u2014\u4E0D\u52A8\u5B83\u3002`);
|
|
55092
|
+
continue;
|
|
55093
|
+
}
|
|
55094
|
+
console.log(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u590D\u6838\u53D1\u73B0\u65B0\u5360\u7528\uFF08pid ${pid}\uFF09\uFF0C\u518D\u6E05\u4E00\u6B21...`);
|
|
55095
|
+
killAndLog(stateDir, pid, `api port ${apiPort} re-check kill`);
|
|
55096
|
+
if (await waitForPidGone(pid)) killed.push(pid);
|
|
55097
|
+
else sawUndead = true;
|
|
55098
|
+
}
|
|
55099
|
+
const probe3 = probePortOwnersRaw(apiPort);
|
|
55100
|
+
const remaining = probe3.unknown ? [] : pickConflictingPortOwners(probe3.output, apiPort, myPid);
|
|
55101
|
+
let remainingEngine = false;
|
|
55102
|
+
for (const pid of remaining) {
|
|
55103
|
+
const { decision, imageText } = classifyPortOwner(pid, stateDir, myPid);
|
|
55104
|
+
if (decision.action === "kill") {
|
|
55105
|
+
remainingEngine = true;
|
|
55106
|
+
continue;
|
|
55107
|
+
}
|
|
55108
|
+
console.error(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u88AB\u975E\u6E05\u573A\u76EE\u6807\u5360\u7528\uFF08pid ${pid}\uFF0C\u6620\u50CF ${(imageText ?? "").trim().slice(0, 60) || "\u63A2\u4E0D\u5230"}\uFF1B${skipReason(decision)}\uFF09\u2014\u2014\u4E0D\u52A8\u5B83\u3002`);
|
|
55109
|
+
}
|
|
55110
|
+
if (sawUndead || remainingEngine) {
|
|
55111
|
+
console.error(`[pid-lock] \u7AEF\u53E3 ${apiPort} \u4ECD\u6709\u5F15\u64CE\u8EAB\u4EFD\u7684\u5360\u7528\u8005\uFF08${remaining.join(",")}\uFF09${sawUndead ? "\uFF08\u6216\u6709\u7B49\u6B7B\u5931\u8D25\uFF09" : ""}\u2014\u2014\u6309\u53CC\u5F00\u98CE\u9669\u5904\u7406\uFF0C\u5F15\u64CE\u62D2\u7EDD\u5E26\u75C5\u542F\u52A8\u3002`);
|
|
55112
|
+
return { killed, blockedKind: "undead", probeUnknown: false, remaining };
|
|
55113
|
+
}
|
|
55114
|
+
if (remaining.length > 0) return { killed, blockedKind: "foreign", probeUnknown: false, remaining };
|
|
55115
|
+
return { killed, blockedKind: "none", probeUnknown: false, remaining: [] };
|
|
55116
|
+
}
|
|
55117
|
+
var EngineLockConflictError = class extends Error {
|
|
55118
|
+
};
|
|
55119
|
+
function tryBindLoopback(port, timeoutMs = 3e3) {
|
|
55120
|
+
return new Promise((resolve26) => {
|
|
55121
|
+
let settled = false;
|
|
55122
|
+
const srv = net.createServer();
|
|
55123
|
+
const finish = (ok) => {
|
|
55124
|
+
if (settled) return;
|
|
55125
|
+
settled = true;
|
|
55126
|
+
clearTimeout(timer);
|
|
55127
|
+
try {
|
|
55128
|
+
srv.close();
|
|
55129
|
+
} catch {
|
|
55130
|
+
}
|
|
55131
|
+
resolve26(ok);
|
|
55132
|
+
};
|
|
55133
|
+
const timer = setTimeout(() => finish(false), timeoutMs);
|
|
55134
|
+
srv.once("error", () => finish(false));
|
|
55135
|
+
srv.listen({ port, host: "127.0.0.1" }, () => finish(true));
|
|
55136
|
+
});
|
|
55137
|
+
}
|
|
55138
|
+
function pickRacingLockOwner(probe) {
|
|
55139
|
+
const cur = parseInt((probe.pidFileContent ?? "").trim(), 10);
|
|
55140
|
+
if (!Number.isInteger(cur) || cur <= 0) return null;
|
|
55141
|
+
if (cur === probe.myPid) return null;
|
|
55142
|
+
if (cur === probe.stalePid) return null;
|
|
55143
|
+
if (!probe.isAlive(cur)) return null;
|
|
55144
|
+
if (!probe.isEngineImage(cur)) return null;
|
|
55145
|
+
return cur;
|
|
55146
|
+
}
|
|
54809
55147
|
async function waitForPidGone(pid, timeoutMs = 5e3) {
|
|
54810
55148
|
const t0 = Date.now();
|
|
54811
55149
|
while (Date.now() - t0 < timeoutMs) {
|
|
@@ -54814,13 +55152,47 @@ async function waitForPidGone(pid, timeoutMs = 5e3) {
|
|
|
54814
55152
|
}
|
|
54815
55153
|
return !isPidAlive(pid);
|
|
54816
55154
|
}
|
|
54817
|
-
function acquireEngineLock(stateDir) {
|
|
55155
|
+
async function acquireEngineLock(stateDir, apiPort) {
|
|
54818
55156
|
const lockFile = enginePidFile(stateDir);
|
|
54819
55157
|
const myPid = process.pid;
|
|
54820
55158
|
const stale = ownEnginePid(stateDir, myPid);
|
|
54821
55159
|
if (stale !== null) {
|
|
54822
55160
|
console.log(`[pid-lock] Stale engine PID ${stale} still alive (engine), killing tree...`);
|
|
54823
55161
|
killAndLog(stateDir, stale, "stale engine in lock file");
|
|
55162
|
+
if (!await waitForPidGone(stale)) {
|
|
55163
|
+
throw new EngineLockConflictError(
|
|
55164
|
+
`pid \u6587\u4EF6\u91CC\u7684\u65E7\u5F15\u64CE\uFF08pid ${stale}\uFF09\u6740\u4E0D\u6389\uFF08\u63D0\u6743/\u6740\u8F6F\u63E1\u7740\uFF1F\uFF09\u2014\u2014\u62D2\u7EDD\u5E26\u75C5\u542F\u52A8\uFF0C\u907F\u514D\u4E0E\u5B83\u53CC\u5F00\u3002 \u5904\u7F6E\uFF1A\u4ECE\u4EFB\u52A1\u7BA1\u7406\u5668\u7ED3\u675F\u8BE5\u8FDB\u7A0B\uFF0C\u6216\u7528\u7BA1\u7406\u5458\u6743\u9650\u91CD\u8BD5\uFF0C\u518D\u542F\u52A8\u5F15\u64CE\u3002`
|
|
55165
|
+
);
|
|
55166
|
+
}
|
|
55167
|
+
}
|
|
55168
|
+
if (apiPort && apiPort > 0) {
|
|
55169
|
+
const evict = await evictEngineOnApiPort(stateDir, apiPort, myPid);
|
|
55170
|
+
if (evict.blockedKind === "undead") {
|
|
55171
|
+
throw new EngineLockConflictError(
|
|
55172
|
+
`API \u7AEF\u53E3 ${apiPort} \u88AB\u6740\u4E0D\u6389\u7684\u65E7\u5F15\u64CE\u5B9E\u4F8B\u5360\u7740\uFF08pid ${evict.remaining.join(",")}\uFF09\u2014\u2014\u62D2\u7EDD\u5E26\u75C5\u542F\u52A8\uFF0C\u907F\u514D\u53CC\u5F00\u3002 \u5904\u7F6E\uFF1A\u4ECE\u4EFB\u52A1\u7BA1\u7406\u5668\u7ED3\u675F\u8BE5\u8FDB\u7A0B\uFF0C\u6216\u6539 config \u7684 api.port\u3002`
|
|
55173
|
+
);
|
|
55174
|
+
}
|
|
55175
|
+
if (evict.probeUnknown) {
|
|
55176
|
+
if (!await tryBindLoopback(apiPort)) {
|
|
55177
|
+
throw new EngineLockConflictError(
|
|
55178
|
+
`API \u7AEF\u53E3 ${apiPort} \u88AB\u8EAB\u4EFD\u4E0D\u660E\u7684\u7A0B\u5E8F\u5360\u7528\uFF08\u6E05\u573A\u63A2\u9488\u5931\u6548\uFF0C\u8BD5\u7ED1\u5931\u8D25\uFF09\u2014\u2014\u62D2\u7EDD\u5E26\u75C5\u542F\u52A8\u3002 \u5904\u7F6E\uFF1A\u627E\u51FA\u5360\u7528\u8005\uFF08netstat -ano | findstr ":${apiPort}" / lsof -iTCP:${apiPort}\uFF09\u6216\u6539 config \u7684 api.port\u3002`
|
|
55179
|
+
);
|
|
55180
|
+
}
|
|
55181
|
+
}
|
|
55182
|
+
}
|
|
55183
|
+
{
|
|
55184
|
+
const racer = pickRacingLockOwner({
|
|
55185
|
+
pidFileContent: readOwnEnginePidText(stateDir),
|
|
55186
|
+
stalePid: stale,
|
|
55187
|
+
myPid,
|
|
55188
|
+
isAlive: isPidAlive,
|
|
55189
|
+
isEngineImage: probeEngineImage
|
|
55190
|
+
});
|
|
55191
|
+
if (racer !== null) {
|
|
55192
|
+
throw new EngineLockConflictError(
|
|
55193
|
+
`\u542F\u52A8\u671F\u95F4\u53E6\u4E00\u4E2A\u5F15\u64CE\uFF08pid ${racer}\uFF09\u5DF2\u62A2\u5230\u8FD9\u4EFD stateDir\u2014\u2014\u672C\u6B21\u542F\u52A8\u9000\u51FA\uFF0C\u907F\u514D\u53CC\u5F00\u3002`
|
|
55194
|
+
);
|
|
55195
|
+
}
|
|
54824
55196
|
}
|
|
54825
55197
|
try {
|
|
54826
55198
|
fs15.mkdirSync(stateDir, { recursive: true });
|
|
@@ -56083,10 +56455,19 @@ async function registerMemoryTools(_engineConfig) {
|
|
|
56083
56455
|
init_license();
|
|
56084
56456
|
init_loader();
|
|
56085
56457
|
init_ffmpeg_path();
|
|
56458
|
+
init_api_port();
|
|
56086
56459
|
init_skill_sync();
|
|
56087
56460
|
async function bootEnvironment(config2) {
|
|
56088
56461
|
process.env.ENGINE_STATE_DIR = config2.stateDir;
|
|
56089
|
-
|
|
56462
|
+
try {
|
|
56463
|
+
await acquireEngineLock(config2.stateDir, computeApiPort(config2));
|
|
56464
|
+
} catch (err) {
|
|
56465
|
+
if (err instanceof EngineLockConflictError) {
|
|
56466
|
+
console.error(`[pid-lock] ${err.message}`);
|
|
56467
|
+
process.exit(1);
|
|
56468
|
+
}
|
|
56469
|
+
throw err;
|
|
56470
|
+
}
|
|
56090
56471
|
process.env.ENGINE_MEDIA_DIR = config2.mediaDir;
|
|
56091
56472
|
process.env.ENGINE7_WORKSPACE = config2.workspace;
|
|
56092
56473
|
process.env.ENGINE7_STATE_DIR = config2.stateDir;
|
|
@@ -56214,18 +56595,7 @@ function applyFreeTierVideoFixup(io) {
|
|
|
56214
56595
|
|
|
56215
56596
|
// src/startup/free-tier-voice-fixup.ts
|
|
56216
56597
|
init_cli_init_config();
|
|
56217
|
-
|
|
56218
|
-
// src/free-tier-apply.ts
|
|
56219
|
-
init_cli_init_config();
|
|
56220
|
-
init_provision_free();
|
|
56221
|
-
init_cli_init_config();
|
|
56222
|
-
function isFreeTierConfig(cfg) {
|
|
56223
|
-
const hasProvider = !!cfg?.models?.providers?.[FREE_TIER_PROVIDER_ID];
|
|
56224
|
-
const primary = String(cfg?.agents?.defaults?.model?.primary || "");
|
|
56225
|
-
return hasProvider && primary.startsWith(`${FREE_TIER_PROVIDER_ID}/`);
|
|
56226
|
-
}
|
|
56227
|
-
|
|
56228
|
-
// src/startup/free-tier-voice-fixup.ts
|
|
56598
|
+
init_free_tier_apply();
|
|
56229
56599
|
function needsFreeTierVoiceFixup(cfg) {
|
|
56230
56600
|
if (!isFreeTierConfig(cfg)) return false;
|
|
56231
56601
|
return cfg?.tools?.my_voice === void 0;
|
|
@@ -56242,64 +56612,8 @@ async function applyFreeTierVoiceFixup(io) {
|
|
|
56242
56612
|
return true;
|
|
56243
56613
|
}
|
|
56244
56614
|
|
|
56245
|
-
// src/startup/free-tier-nort-fixup.ts
|
|
56246
|
-
init_cli_init_config();
|
|
56247
|
-
var FIELD_REFS = {
|
|
56248
|
-
"topics.extract.model": FREE_TIER_NORT_REF,
|
|
56249
|
-
"topics.clean.model": FREE_TIER_FAST_REF,
|
|
56250
|
-
"innerVoice.model": FREE_TIER_NORT_REF
|
|
56251
|
-
};
|
|
56252
|
-
var LANE_MODELS = [FREE_TIER_FAST_MODEL, FREE_TIER_NORT_MODEL];
|
|
56253
|
-
function legacyTwoFieldExtract(cfg) {
|
|
56254
|
-
const ex = cfg?.topics?.extract;
|
|
56255
|
-
return typeof ex?.provider === "string" && ex.provider.trim() === FREE_TIER_PROVIDER_ID && typeof ex?.model === "string" && LANE_MODELS.some((id) => id === ex.model.trim());
|
|
56256
|
-
}
|
|
56257
|
-
function needsFreeTierNortFixup(cfg) {
|
|
56258
|
-
if (!isFreeTierConfig(cfg)) return false;
|
|
56259
|
-
const provider = cfg?.models?.providers?.[FREE_TIER_PROVIDER_ID];
|
|
56260
|
-
if (!provider) return false;
|
|
56261
|
-
if (LANE_MODELS.some((id) => !(provider.models || []).some((m) => m?.id === id))) return true;
|
|
56262
|
-
return Object.keys(FIELD_REFS).some((path86) => readPath(cfg, path86) === void 0) || legacyTwoFieldExtract(cfg);
|
|
56263
|
-
}
|
|
56264
|
-
function readPath(obj, dotPath) {
|
|
56265
|
-
return dotPath.split(".").reduce((acc, k) => acc == null ? void 0 : acc[k], obj);
|
|
56266
|
-
}
|
|
56267
|
-
async function applyFreeTierNortFixup(io) {
|
|
56268
|
-
const cfg = io.all();
|
|
56269
|
-
if (!needsFreeTierNortFixup(cfg)) return false;
|
|
56270
|
-
const provider = cfg.models.providers[FREE_TIER_PROVIDER_ID];
|
|
56271
|
-
const registry2 = PROVIDER_DEFS[FREE_TIER_PROVIDER_ID]?.models ?? [];
|
|
56272
|
-
const missingEntries = LANE_MODELS.filter((id) => !(provider.models || []).some((m) => m?.id === id)).map((id) => registry2.find((m) => m.id === id));
|
|
56273
|
-
if (missingEntries.some((entry) => !entry)) return false;
|
|
56274
|
-
const writes = [];
|
|
56275
|
-
if (missingEntries.length) {
|
|
56276
|
-
const newModels = [...provider.models || [], ...missingEntries.map((entry) => ({ ...entry }))];
|
|
56277
|
-
writes.push([`models.providers.${FREE_TIER_PROVIDER_ID}.models`, newModels]);
|
|
56278
|
-
const pCopy = cfg.providers?.[FREE_TIER_PROVIDER_ID];
|
|
56279
|
-
if (pCopy && pCopy !== provider) pCopy.models = newModels;
|
|
56280
|
-
}
|
|
56281
|
-
for (const [path86, ref] of Object.entries(FIELD_REFS)) {
|
|
56282
|
-
if (readPath(cfg, path86) === void 0) writes.push([path86, ref]);
|
|
56283
|
-
}
|
|
56284
|
-
const migratedLegacyExtract = legacyTwoFieldExtract(cfg);
|
|
56285
|
-
if (migratedLegacyExtract) {
|
|
56286
|
-
writes.push(["topics.extract.model", FREE_TIER_NORT_REF]);
|
|
56287
|
-
writes.push(["topics.extract.provider", void 0]);
|
|
56288
|
-
}
|
|
56289
|
-
if (!writes.length) return false;
|
|
56290
|
-
let persisted = true;
|
|
56291
|
-
for (const [path86, value] of writes) {
|
|
56292
|
-
if (await io.set(path86, value) === false) persisted = false;
|
|
56293
|
-
}
|
|
56294
|
-
if (!persisted) {
|
|
56295
|
-
console.error("[startup] \u514D\u8D39\u6863 nort \u8865\u9F50 **\u672A\u5168\u90E8\u843D\u76D8**\uFF08\u672C\u6B21\u8FD0\u884C\u5185\u5B58\u91CC\u5DF2\u751F\u6548\uFF0C\u914D\u7F6E\u6587\u4EF6\u4ECD\u662F\u65E7\u7684\u2014\u2014\u4E0B\u6B21\u542F\u52A8\u4F1A\u91CD\u653E\uFF09\u3002\u4E0A\u9762 [liveConfig] \u90A3\u51E0\u884C\u662F\u539F\u56E0\u3002");
|
|
56296
|
-
return true;
|
|
56297
|
-
}
|
|
56298
|
-
console.log(`[startup] \u514D\u8D39\u6863\u8865\u9F50\u540E\u53F0\u8F66\u9053\uFF1Aextract/innerVoice \u2192 ${FREE_TIER_NORT_REF}\u3001clean \u2192 ${FREE_TIER_FAST_REF}\uFF08\u5B58\u91CF\u6E05\u6D17\u8D70\u5FEB\u6863\uFF09\uFF08${writes.map(([p]) => p).join(", ")}\uFF1B\u7528\u6237\u81EA\u5DF1\u914D\u8FC7\u7684\u4E0D\u52A8${migratedLegacyExtract ? "\uFF1B\u65E7\u4E24\u5B57\u6BB5 extract \u5DF2\u8FC1 nort" : ""}\uFF09`);
|
|
56299
|
-
return true;
|
|
56300
|
-
}
|
|
56301
|
-
|
|
56302
56615
|
// src/engine-startup.ts
|
|
56616
|
+
init_free_tier_nort_fixup();
|
|
56303
56617
|
init_mem7_services_fixup();
|
|
56304
56618
|
|
|
56305
56619
|
// src/startup/extract-cooldown-fixup.ts
|
|
@@ -62381,7 +62695,7 @@ var VoiceChatPlugin = class {
|
|
|
62381
62695
|
|
|
62382
62696
|
// src/memory/everos/plugin.ts
|
|
62383
62697
|
import { spawn as spawn4 } from "node:child_process";
|
|
62384
|
-
import
|
|
62698
|
+
import net2 from "node:net";
|
|
62385
62699
|
import path46 from "node:path";
|
|
62386
62700
|
import fs48 from "node:fs";
|
|
62387
62701
|
|
|
@@ -62821,7 +63135,7 @@ var EverosPlugin = class {
|
|
|
62821
63135
|
}
|
|
62822
63136
|
async isPortAlive(port) {
|
|
62823
63137
|
return new Promise((resolve26) => {
|
|
62824
|
-
const socket = new
|
|
63138
|
+
const socket = new net2.Socket();
|
|
62825
63139
|
socket.setTimeout(2e3);
|
|
62826
63140
|
socket.on("connect", () => {
|
|
62827
63141
|
socket.destroy();
|
|
@@ -68362,7 +68676,7 @@ import { promisify as promisify4 } from "node:util";
|
|
|
68362
68676
|
import * as fs54 from "node:fs";
|
|
68363
68677
|
import * as path55 from "node:path";
|
|
68364
68678
|
import * as os6 from "node:os";
|
|
68365
|
-
import
|
|
68679
|
+
import net4 from "net";
|
|
68366
68680
|
var execFileAsync2 = promisify4(execFile5);
|
|
68367
68681
|
var VOICE_DIR = path55.join(os6.tmpdir(), "engine-voice");
|
|
68368
68682
|
function wavDurationSec(buf) {
|
|
@@ -68538,7 +68852,7 @@ async function ttsCosyvoiceWorker(text, cfg, onChunk) {
|
|
|
68538
68852
|
}
|
|
68539
68853
|
}
|
|
68540
68854
|
return new Promise((resolve26, reject) => {
|
|
68541
|
-
const sock =
|
|
68855
|
+
const sock = net4.connect(getSockPath());
|
|
68542
68856
|
let buf = "";
|
|
68543
68857
|
const finish = (err) => {
|
|
68544
68858
|
try {
|
|
@@ -68874,8 +69188,8 @@ var DeskBuddyAdapter = class {
|
|
|
68874
69188
|
startAsr() {
|
|
68875
69189
|
if (this.asrSock) return;
|
|
68876
69190
|
const port = this.asrBackend === "sensevoice" ? 9790 : 9791;
|
|
68877
|
-
const
|
|
68878
|
-
const sock =
|
|
69191
|
+
const net5 = __require("node:net");
|
|
69192
|
+
const sock = net5.connect(port, "127.0.0.1");
|
|
68879
69193
|
sock.setNoDelay(true);
|
|
68880
69194
|
this.asrSock = sock;
|
|
68881
69195
|
this.asrBuf = "";
|
|
@@ -82114,6 +82428,7 @@ async function startEngine(config2, opts) {
|
|
|
82114
82428
|
} });
|
|
82115
82429
|
await applyFreeTierVoiceFixup({ all: () => liveConfig.all(), set: (p, v) => liveConfig.set(p, v) });
|
|
82116
82430
|
await applyFreeTierNortFixup({ all: () => liveConfig.all(), set: (p, v) => liveConfig.set(p, v) });
|
|
82431
|
+
await applyMem7EnableForFreeInstall({ all: () => liveConfig.all(), set: (p, v) => liveConfig.set(p, v) });
|
|
82117
82432
|
await applyMem7ServicesFixup({ all: () => liveConfig.all(), set: (p, v) => liveConfig.set(p, v) });
|
|
82118
82433
|
await applyExtractCooldownFixup({ all: () => liveConfig.all(), set: (p, v) => liveConfig.set(p, v) });
|
|
82119
82434
|
let provider;
|
|
@@ -82670,8 +82985,10 @@ async function startEngine(config2, opts) {
|
|
|
82670
82985
|
};
|
|
82671
82986
|
reloadOrchestrator.register({
|
|
82672
82987
|
name: "channels",
|
|
82673
|
-
// channels 段常开(空段 = 全拆,reconcile
|
|
82674
|
-
|
|
82988
|
+
// channels 段常开(空段 = 全拆,reconcile 自然处理)。select 抽出为纯函数——
|
|
82989
|
+
// 它吃的是 resolveEnv **之后**的活树,secrets-only 换 token 也要能触发重建
|
|
82990
|
+
// (1102:这条链没有回归钉害我误诊一轮,见 channels-entry.ts 头注)
|
|
82991
|
+
select: channelsSelectSlice,
|
|
82675
82992
|
start: () => runChannelsReconcile(),
|
|
82676
82993
|
// fire-and-forget:defer 重试不阻塞后续 entry
|
|
82677
82994
|
stop: () => {
|