engine7 7.1.138 → 7.1.141
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/README.md +3 -1
- package/dist/bg-worker.mjs +134 -128
- package/dist/cli.mjs +4908 -3448
- package/dist/cpu-router-worker.mjs +604 -8
- package/dist/device-connectors/reader +0 -0
- package/dist/engine-startup.mjs +9105 -6642
- package/dist/main.mjs +9082 -6618
- package/dist/optional-deps.json +78 -0
- package/dist/recall-worker.mjs +57 -53
- package/dist/sqlite-maintenance-worker.mjs +16 -18
- package/dist/topics-worker.mjs +56 -52
- package/dist/travel-activation-database.mjs +1077 -0
- package/dist/travel-authority.mjs +46 -25
- package/dist/travel-console.mjs +150 -83
- package/dist/travel-controller.mjs +244 -51
- package/dist/travel-data.mjs +972 -578
- package/dist/travel-gateway.mjs +1529 -745
- package/dist/travel-host.mjs +3970 -3068
- package/dist/travel-initial-baseline.mjs +5959 -0
- package/dist/travel-node-data.mjs +751 -324
- package/dist/travel-node.mjs +2489 -1541
- package/dist/travel-pairing.mjs +1570 -779
- package/dist/travel-resource.mjs +23 -16
- package/dist/travel-retire.mjs +52 -37
- package/dist/web-console.mjs +1972 -320
- package/package.json +13 -8
- package/scripts/verify-cpu-router-package.mjs +14 -1
- package/templates/config.template.json +14 -0
|
@@ -1,12 +1,600 @@
|
|
|
1
1
|
const require=(await import('node:module')).createRequire(import.meta.url)
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __esm = (fn, res) => function __init() {
|
|
5
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
6
|
+
};
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/config/writer.ts
|
|
13
|
+
import fs from "node:fs";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
function isNormalized(text) {
|
|
16
|
+
if (text === "") return true;
|
|
17
|
+
if (text.includes("\r")) return false;
|
|
18
|
+
let minIndent = Infinity;
|
|
19
|
+
for (const line of text.split("\n")) {
|
|
20
|
+
const m = /^( +)\S/.exec(line);
|
|
21
|
+
if (!m) continue;
|
|
22
|
+
const width = m[1].length;
|
|
23
|
+
if (width % 2 !== 0) return false;
|
|
24
|
+
if (width < minIndent) minIndent = width;
|
|
25
|
+
}
|
|
26
|
+
return minIndent === 2 || minIndent === Infinity;
|
|
27
|
+
}
|
|
28
|
+
function rotateBaks(filePath) {
|
|
29
|
+
const dir = path.dirname(filePath);
|
|
30
|
+
const base = path.basename(filePath);
|
|
31
|
+
const baks = fs.readdirSync(dir).filter((n) => n.startsWith(base + ".bak-")).sort();
|
|
32
|
+
while (baks.length >= KEEP_BAKS) {
|
|
33
|
+
const victim = baks.shift();
|
|
34
|
+
try {
|
|
35
|
+
fs.unlinkSync(path.join(dir, victim));
|
|
36
|
+
} catch {
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function sleepSync(ms) {
|
|
41
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
|
|
42
|
+
}
|
|
43
|
+
function errCode(err) {
|
|
44
|
+
return err?.code ?? "";
|
|
45
|
+
}
|
|
46
|
+
function writeFailure(filePath, primary, extra) {
|
|
47
|
+
const code = errCode(primary);
|
|
48
|
+
const reason = RETRYABLE_CODES.has(code) ? `\u76EE\u6807\u6587\u4EF6\u88AB\u5360\u7528\u6216\u4E0D\u53EF\u5199\uFF08${code}\uFF09\u2014\u2014\u8BF7\u5173\u95ED\u6B63\u5728\u4F7F\u7528\u5B83\u7684\u7A0B\u5E8F\uFF08\u7F16\u8F91\u5668\u3001\u6740\u6BD2\u3001\u540C\u6B65\u76D8\u7B49\uFF09\u540E\u91CD\u8BD5` : `\u5199\u5165\u5931\u8D25${code ? `\uFF08${code}\uFF09` : ""}\uFF1A${primary?.message ?? String(primary)}`;
|
|
49
|
+
return new ConfigWriteError(`\u65E0\u6CD5\u5199\u5165 ${filePath}\uFF1A${reason}${extra ? `\uFF1B${extra}` : ""}`, code, primary);
|
|
50
|
+
}
|
|
51
|
+
function renameWithRetry(from, to) {
|
|
52
|
+
for (let attempt = 1; ; attempt++) {
|
|
53
|
+
try {
|
|
54
|
+
fs.renameSync(from, to);
|
|
55
|
+
return;
|
|
56
|
+
} catch (err) {
|
|
57
|
+
if (attempt >= RENAME_ATTEMPTS || !RETRYABLE_CODES.has(errCode(err))) throw err;
|
|
58
|
+
sleepSync(RENAME_RETRY_MS);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
function commitFile(tmp, filePath) {
|
|
63
|
+
try {
|
|
64
|
+
renameWithRetry(tmp, filePath);
|
|
65
|
+
return;
|
|
66
|
+
} catch (primaryErr) {
|
|
67
|
+
const old = `${filePath}.old`;
|
|
68
|
+
try {
|
|
69
|
+
fs.renameSync(filePath, old);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
throw writeFailure(filePath, primaryErr, `\u6539\u540D .old \u5907\u4EFD\u4E5F\u5931\u8D25\uFF08${errCode(err) || "\u672A\u77E5"}\uFF09`);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
fs.renameSync(tmp, filePath);
|
|
75
|
+
} catch (err) {
|
|
76
|
+
try {
|
|
77
|
+
fs.renameSync(old, filePath);
|
|
78
|
+
} catch {
|
|
79
|
+
throw writeFailure(filePath, primaryErr, `\u65B0\u5185\u5BB9\u843D\u76D8\u4E0E\u56DE\u6EDA\u90FD\u5931\u8D25\uFF0C\u65E7\u5185\u5BB9\u7559\u5728 ${old}`);
|
|
80
|
+
}
|
|
81
|
+
throw writeFailure(filePath, primaryErr, `\u6362\u540D\u843D\u76D8\u5931\u8D25\uFF08${errCode(err) || "\u672A\u77E5"}\uFF09`);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
fs.unlinkSync(old);
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function writeConfigAtomic(filePath, obj) {
|
|
90
|
+
const existed = fs.existsSync(filePath);
|
|
91
|
+
let prevText = "";
|
|
92
|
+
let fileMode;
|
|
93
|
+
if (existed) {
|
|
94
|
+
try {
|
|
95
|
+
prevText = fs.readFileSync(filePath, "utf-8");
|
|
96
|
+
fileMode = fs.statSync(filePath).mode & 511;
|
|
97
|
+
} catch (err) {
|
|
98
|
+
throw writeFailure(filePath, err);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const normalized = !existed || !isNormalized(prevText);
|
|
102
|
+
if (prevText) {
|
|
103
|
+
try {
|
|
104
|
+
fs.copyFileSync(filePath, `${filePath}.bak-${Date.now()}`);
|
|
105
|
+
} catch {
|
|
106
|
+
}
|
|
107
|
+
rotateBaks(filePath);
|
|
108
|
+
}
|
|
109
|
+
const content = JSON.stringify(obj, null, 2) + "\n";
|
|
110
|
+
const tmp = path.join(path.dirname(filePath), `.${path.basename(filePath)}.tmp-${process.pid}`);
|
|
111
|
+
try {
|
|
112
|
+
const fd = fs.openSync(tmp, "w", fileMode);
|
|
113
|
+
try {
|
|
114
|
+
if (fileMode !== void 0) fs.fchmodSync(fd, fileMode);
|
|
115
|
+
fs.writeFileSync(fd, content, "utf-8");
|
|
116
|
+
fs.fsyncSync(fd);
|
|
117
|
+
} finally {
|
|
118
|
+
fs.closeSync(fd);
|
|
119
|
+
}
|
|
120
|
+
commitFile(tmp, filePath);
|
|
121
|
+
} catch (err) {
|
|
122
|
+
throw err instanceof ConfigWriteError ? err : writeFailure(filePath, err);
|
|
123
|
+
} finally {
|
|
124
|
+
try {
|
|
125
|
+
fs.unlinkSync(tmp);
|
|
126
|
+
} catch {
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return { normalized };
|
|
130
|
+
}
|
|
131
|
+
var KEEP_BAKS, RENAME_ATTEMPTS, RENAME_RETRY_MS, RETRYABLE_CODES, ConfigWriteError;
|
|
132
|
+
var init_writer = __esm({
|
|
133
|
+
"src/config/writer.ts"() {
|
|
134
|
+
"use strict";
|
|
135
|
+
KEEP_BAKS = 3;
|
|
136
|
+
RENAME_ATTEMPTS = 5;
|
|
137
|
+
RENAME_RETRY_MS = 50;
|
|
138
|
+
RETRYABLE_CODES = /* @__PURE__ */ new Set(["EBUSY", "EPERM", "EACCES"]);
|
|
139
|
+
ConfigWriteError = class extends Error {
|
|
140
|
+
code;
|
|
141
|
+
constructor(message, code, cause) {
|
|
142
|
+
super(message, { cause });
|
|
143
|
+
this.name = "ConfigWriteError";
|
|
144
|
+
this.code = code;
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
// src/config/live.ts
|
|
151
|
+
function markSelfWrite() {
|
|
152
|
+
selfWrite.pending = true;
|
|
153
|
+
}
|
|
154
|
+
var LiveConfigClass, liveConfig, selfWrite;
|
|
155
|
+
var init_live = __esm({
|
|
156
|
+
"src/config/live.ts"() {
|
|
157
|
+
"use strict";
|
|
158
|
+
init_writer();
|
|
159
|
+
LiveConfigClass = class {
|
|
160
|
+
current = null;
|
|
161
|
+
/** 启动时注入(替代 registry.config = config) */
|
|
162
|
+
init(config) {
|
|
163
|
+
this.current = config;
|
|
164
|
+
}
|
|
165
|
+
/** 取整个 config 对象(只读引用,不要缓存) */
|
|
166
|
+
all() {
|
|
167
|
+
if (!this.current) {
|
|
168
|
+
throw new Error("[liveConfig] not initialized \u2014 call liveConfig.init() first");
|
|
169
|
+
}
|
|
170
|
+
return this.current;
|
|
171
|
+
}
|
|
172
|
+
/** 安全取子段('services.voice-chat.start' → current.services.voice-chat.start) */
|
|
173
|
+
get(dotPath) {
|
|
174
|
+
if (!this.current) return void 0;
|
|
175
|
+
return dotPath.split(".").reduce((acc, key) => {
|
|
176
|
+
if (acc == null) return void 0;
|
|
177
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") return void 0;
|
|
178
|
+
return acc[key];
|
|
179
|
+
}, this.current);
|
|
180
|
+
}
|
|
181
|
+
/** reload 时原地更新(Object.assign 保持引用不变)
|
|
182
|
+
* ⚠️ 0908 立法(浅层 assign 陷阱,见 docs/hot-reload-architecture.md):
|
|
183
|
+
* 这是**浅层** assign——顶层 key 被整体换新引用,构造期捕获嵌套子对象
|
|
184
|
+
* (如 config.cron、deps.everosCfg、adapter 的 config 段)的模块 reload 后
|
|
185
|
+
* 拿着的是旧对象。两条出路:(a) 使用时 liveConfig.get() 现读;(b) 注册为
|
|
186
|
+
* reloadOrchestrator entry,key 变化驱动 stop→start 重建。禁止新增"构造期
|
|
187
|
+
* 固化嵌套 config 引用"的代码。(不做 deep-merge:会破坏"删 key"语义。) */
|
|
188
|
+
assign(newConfig) {
|
|
189
|
+
if (!this.current) {
|
|
190
|
+
this.current = newConfig;
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
Object.assign(this.current, newConfig);
|
|
194
|
+
}
|
|
195
|
+
/** 改活树上的值;文件承载路径同步持久化(read-modify-write 回 config 文件) */
|
|
196
|
+
/**
|
|
197
|
+
* 改活树 + 落盘。
|
|
198
|
+
*
|
|
199
|
+
* 返回值 = **落盘**是否成功(活树无论成败都已同步——它是先改的)。绝大多数调用点照旧
|
|
200
|
+
* `void liveConfig.set(...)` 不理它;但**要打成功日志的调用点必须 await 这个布尔值**。
|
|
201
|
+
*
|
|
202
|
+
* 为什么把这个信号交出去(1001 审查捞回):本方法本来是 fire-and-forget,落盘失败只在
|
|
203
|
+
* `persistToFile` 里 warn 一行;而启动早段的调用点(两个免费档 fixup)紧接着打了句
|
|
204
|
+
* "免费档补齐 xxx" 的成功日志 ⇒ 配置**没写进文件**却被读成"写好了":进程内生效、托盘
|
|
205
|
+
* 读文件还是旧值、下次启动重放同一句——正是本仓最恨的假信号。
|
|
206
|
+
*/
|
|
207
|
+
async set(dotPath, val, options) {
|
|
208
|
+
if (!this.current) throw new Error("[liveConfig] not initialized \u2014 call liveConfig.init() first");
|
|
209
|
+
const keys = dotPath.split(".");
|
|
210
|
+
const dangerous = keys.find((k) => k === "__proto__" || k === "constructor" || k === "prototype");
|
|
211
|
+
if (dangerous) throw new Error(`[liveConfig] set: \u8DEF\u5F84\u6BB5\u300C${dangerous}\u300D\u662F\u4FDD\u7559\u540D\uFF0C\u62D2\u7EDD\u5199\u5165\uFF08${dotPath}\uFF09`);
|
|
212
|
+
let obj = this.current;
|
|
213
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
214
|
+
if (obj[keys[i]] == null) obj[keys[i]] = {};
|
|
215
|
+
obj = obj[keys[i]];
|
|
216
|
+
}
|
|
217
|
+
obj[keys[keys.length - 1]] = val;
|
|
218
|
+
return this.persistToFile(dotPath, val, options?.atomic === true);
|
|
219
|
+
}
|
|
220
|
+
/** 把改动写回 config 文件对应段(找不到文件路径则只内存生效)。返回是否真的落盘。 */
|
|
221
|
+
async persistToFile(dotPath, val, atomic = false) {
|
|
222
|
+
const fs4 = await import("node:fs");
|
|
223
|
+
const cfgPath = this.current?._configFilePath;
|
|
224
|
+
if (!cfgPath || !fs4.existsSync(cfgPath)) {
|
|
225
|
+
console.warn(`[liveConfig] set: no config file path, in-memory only (${dotPath})`);
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
try {
|
|
229
|
+
const raw = JSON.parse(fs4.readFileSync(cfgPath, "utf-8"));
|
|
230
|
+
const keys = dotPath.split(".");
|
|
231
|
+
let o = raw;
|
|
232
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
233
|
+
if (o[keys[i]] == null) o[keys[i]] = {};
|
|
234
|
+
o = o[keys[i]];
|
|
235
|
+
}
|
|
236
|
+
o[keys[keys.length - 1]] = val;
|
|
237
|
+
if (atomic) {
|
|
238
|
+
writeConfigAtomic(cfgPath, raw);
|
|
239
|
+
} else fs4.writeFileSync(cfgPath, JSON.stringify(raw, null, 2) + "\n", "utf-8");
|
|
240
|
+
const lastKey = keys[keys.length - 1].toLowerCase();
|
|
241
|
+
const looksSecret = /(^|[-_.])(key|token|secret|passwd|password|passphrase|authorization|auth|cred)([-_.]|$)/.test(lastKey);
|
|
242
|
+
const shown = val !== null && typeof val === "object" ? "{\u2026}" : looksSecret ? "{\u2026}" : JSON.stringify(val);
|
|
243
|
+
console.log(`[liveConfig] persisted ${dotPath} = ${shown} to ${cfgPath}`);
|
|
244
|
+
markSelfWrite();
|
|
245
|
+
return true;
|
|
246
|
+
} catch (e) {
|
|
247
|
+
console.warn(`[liveConfig] persist failed (${dotPath}): ${e.message}`);
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/** 是否已初始化 */
|
|
252
|
+
isReady() {
|
|
253
|
+
return this.current !== null;
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
liveConfig = new LiveConfigClass();
|
|
257
|
+
selfWrite = { pending: false };
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
// src/optional/dep-downloader/optional-deps.json
|
|
262
|
+
var optional_deps_default;
|
|
263
|
+
var init_optional_deps = __esm({
|
|
264
|
+
"src/optional/dep-downloader/optional-deps.json"() {
|
|
265
|
+
optional_deps_default = {
|
|
266
|
+
"//": "\u6309\u9700\u4F9D\u8D56\u6E05\u5355\uFF081115 dmg \u7626\u8EAB\uFF09\u2014\u2014\u586B\u8868\u5373\u6309\u9700\uFF1A\u2460\u8FD9\u91CC\u52A0\u4E00\u6761 \u2461\u8C03\u7528 loadOptionalModule('<key>') \u2462build.mjs \u4F1A\u628A\u5B83\u62F7\u8FDB dist/optional-deps.json\u3001\u5B89\u88C5\u5668 build-resources \u636E\u6B64\u4ECE payload \u88C1\u6389 \u2192 \u81EA\u52A8\u6309\u9700\u3002integrity \u{1F534} \u5FC5\u987B\u53D6\u7248\u672C\u7AEF\u70B9 fetch(registry/<name>/<version>).dist.integrity\uFF08\u6216\u4ED3\u5185 package-lock \u540C\u6761\u76EE\uFF09\u2014\u2014npm view \u6839\u7AEF\u70B9\u6709\u9648\u65E7\u7F13\u5B58\u5751\uFF081115 \u5B9E\u8E29 onnxruntime-common \u5DEE\u4E00\u5B57\u7B26\uFF09\u3002\u{1F534} mem7 \u5168\u94FE\uFF08lancedb/apache-arrow/sqlite\uFF09\u662F\u4EA7\u54C1\u6838\u5FC3\u6C38\u8FDC\u88C5\u673A\u5185\u7F6E\uFF0C\u6C38\u8FDC\u4E0D\u8BB8\u586B\u8FDB\u6765\uFF081115 \u7FC0\u54E5\u5B9A\u8C03\uFF09\u3002",
|
|
267
|
+
"cc-runtime": {
|
|
268
|
+
label: "CC \u8FD0\u884C\u65F6",
|
|
269
|
+
main: {
|
|
270
|
+
name: "@anthropic-ai/claude-agent-sdk",
|
|
271
|
+
version: "0.3.317",
|
|
272
|
+
integrity: "sha512-qoRB5svuBNXm5N5miBj3RS2JyA7daGcdOCopQIdJXMxaYREIvR7P1FFiFhSLwIjh61D9ir8f/8OFm5LyDJspEA=="
|
|
273
|
+
},
|
|
274
|
+
platform: {
|
|
275
|
+
"darwin-x64": {
|
|
276
|
+
name: "@anthropic-ai/claude-agent-sdk-darwin-x64",
|
|
277
|
+
version: "0.3.317",
|
|
278
|
+
integrity: "sha512-GAmOMLr3g3nEQDFcYux5u/duNNXMvJxIBjowgAVp7ndPRbTHpv+jU0JVSa9LdvEycT4ssEvTR/R6eqQ1raBKbw=="
|
|
279
|
+
},
|
|
280
|
+
"darwin-arm64": {
|
|
281
|
+
name: "@anthropic-ai/claude-agent-sdk-darwin-arm64",
|
|
282
|
+
version: "0.3.317",
|
|
283
|
+
integrity: "sha512-SSXvZ04MpfA0hLfGrP9SBTNOgw2p2TsmJAUjr6GA5bM9LVLRLX6pmiIAaTtpaPhslK+zd6Nf5taU/XRldPyUBg=="
|
|
284
|
+
},
|
|
285
|
+
"win32-x64": {
|
|
286
|
+
name: "@anthropic-ai/claude-agent-sdk-win32-x64",
|
|
287
|
+
version: "0.3.317",
|
|
288
|
+
integrity: "sha512-BPxd/DV67LOmPFcq9zrxvs0siTejMGuZDI4sisjFNTssl/Qqma26BXGdHejQlqJqksuzurx+MPq4Jxtzx5UIZw=="
|
|
289
|
+
},
|
|
290
|
+
"linux-x64": {
|
|
291
|
+
name: "@anthropic-ai/claude-agent-sdk-linux-x64",
|
|
292
|
+
version: "0.3.317",
|
|
293
|
+
integrity: "sha512-cjbMfYdESAafCCedRETVIB+rF9HM9hpix/490p0YRccvBhc3uwYuvMQGEHJ9Z+rZujdy49+2lAxq0PZmiCZKjQ=="
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
"cpu-router": {
|
|
298
|
+
label: "CPU \u8DEF\u7531\u5668\u63A8\u7406\u5F15\u64CE",
|
|
299
|
+
main: {
|
|
300
|
+
name: "onnxruntime-node",
|
|
301
|
+
version: "1.19.2",
|
|
302
|
+
integrity: "sha512-9eHMP/HKbbeUcqte1JYzaaRC8JPn7ojWeCeoyShO86TOR97OCyIyAIOGX3V95ErjslVhJRXY8Em/caIUc0hm1Q=="
|
|
303
|
+
},
|
|
304
|
+
extra: [
|
|
305
|
+
{
|
|
306
|
+
name: "onnxruntime-common",
|
|
307
|
+
version: "1.19.2",
|
|
308
|
+
integrity: "sha512-a4R7wYEVFbZBlp0BfhpbFWqe4opCor3KM+5Wm22Az3NGDcQMiU2hfG/0MfnBs+1ZrlSGmlgWeMcXQkDk1UFb8Q=="
|
|
309
|
+
}
|
|
310
|
+
]
|
|
311
|
+
},
|
|
312
|
+
ffmpeg: {
|
|
313
|
+
label: "ffmpeg",
|
|
314
|
+
main: {
|
|
315
|
+
name: "@ffmpeg-installer/ffmpeg",
|
|
316
|
+
version: "1.1.0",
|
|
317
|
+
integrity: "sha512-Uq4rmwkdGxIa9A6Bd/VqqYbT7zqh1GrT5/rFwCwKM70b42W5gIjWeVETq6SdcL0zXqDtY081Ws/iJWhr1+xvQg=="
|
|
318
|
+
},
|
|
319
|
+
platform: {
|
|
320
|
+
"darwin-x64": {
|
|
321
|
+
name: "@ffmpeg-installer/darwin-x64",
|
|
322
|
+
version: "4.1.0",
|
|
323
|
+
integrity: "sha512-Z4EyG3cIFjdhlY8wI9aLUXuH8nVt7E9SlMVZtWvSPnm2sm37/yC2CwjUzyCQbJbySnef1tQwGG2Sx+uWhd9IAw=="
|
|
324
|
+
},
|
|
325
|
+
"darwin-arm64": {
|
|
326
|
+
name: "@ffmpeg-installer/darwin-arm64",
|
|
327
|
+
version: "4.1.5",
|
|
328
|
+
integrity: "sha512-hYyTiP63mXz7wSQfuqfFwfLOfwwFChUedeCVKkBtl/cliaTM7/ePI9bVzfZ2c+dWu3TqCwLDRWNSJ5pqZl8otA=="
|
|
329
|
+
},
|
|
330
|
+
"win32-x64": {
|
|
331
|
+
name: "@ffmpeg-installer/win32-x64",
|
|
332
|
+
version: "4.1.0",
|
|
333
|
+
integrity: "sha512-Drt5u2vzDnIONf4ZEkKtFlbvwj6rI3kxw1Ck9fpudmtgaZIHD4ucsWB2lCZBXRxJgXR+2IMSti+4rtM4C4rXgg=="
|
|
334
|
+
},
|
|
335
|
+
"linux-x64": {
|
|
336
|
+
name: "@ffmpeg-installer/linux-x64",
|
|
337
|
+
version: "4.1.0",
|
|
338
|
+
integrity: "sha512-Y5BWhGLU/WpQjOArNIgXD3z5mxxdV8c41C+U15nsE5yF8tVcdCGet5zPs5Zy3Ta6bU7haGpIzryutqCGQA/W8A=="
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// src/optional/dep-downloader/index.ts
|
|
347
|
+
var dep_downloader_exports = {};
|
|
348
|
+
__export(dep_downloader_exports, {
|
|
349
|
+
OPTIONAL_FEATURES: () => OPTIONAL_FEATURES,
|
|
350
|
+
ensureOptionalFeature: () => ensureOptionalFeature,
|
|
351
|
+
isOptionalFeatureInstalled: () => isOptionalFeatureInstalled,
|
|
352
|
+
loadOptionalModule: () => loadOptionalModule,
|
|
353
|
+
optionalDepsRoot: () => optionalDepsRoot,
|
|
354
|
+
optionalFfmpegPath: () => optionalFfmpegPath,
|
|
355
|
+
prefetchOptionalFeatures: () => prefetchOptionalFeatures
|
|
356
|
+
});
|
|
357
|
+
import * as crypto from "node:crypto";
|
|
358
|
+
import * as fs2 from "node:fs";
|
|
359
|
+
import * as os from "node:os";
|
|
360
|
+
import * as path2 from "node:path";
|
|
361
|
+
import { createRequire } from "node:module";
|
|
362
|
+
import { pathToFileURL } from "node:url";
|
|
363
|
+
function optionalDepsRoot() {
|
|
364
|
+
const env = (process.env.E7_OPTIONAL_DEPS_DIR || "").trim();
|
|
365
|
+
if (env) return env;
|
|
366
|
+
return path2.join(os.homedir(), ".engine7", "optional-deps");
|
|
367
|
+
}
|
|
368
|
+
function sharedNodeModules() {
|
|
369
|
+
return path2.join(optionalDepsRoot(), "node_modules");
|
|
370
|
+
}
|
|
371
|
+
function pkgDir(name) {
|
|
372
|
+
return path2.join(sharedNodeModules(), ...name.split("/"));
|
|
373
|
+
}
|
|
374
|
+
function readConfig(key) {
|
|
375
|
+
try {
|
|
376
|
+
return liveConfig.get(key);
|
|
377
|
+
} catch {
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
function registryBase() {
|
|
381
|
+
const env = (process.env.E7_OPTIONAL_REGISTRY || "").trim();
|
|
382
|
+
return (env || readConfig("optionalDeps.registry") || "https://registry.npmjs.org").replace(/\/$/, "");
|
|
383
|
+
}
|
|
384
|
+
function downloadsEnabled() {
|
|
385
|
+
if ((process.env.E7_OPTIONAL_DEPS || "").trim() === "off") return false;
|
|
386
|
+
return readConfig("optionalDeps.autoDownload") !== false;
|
|
387
|
+
}
|
|
388
|
+
function currentPlatformKey() {
|
|
389
|
+
return `${process.platform}-${process.arch}`;
|
|
390
|
+
}
|
|
391
|
+
function featureSpec(key) {
|
|
392
|
+
const spec = OPTIONAL_FEATURES[key];
|
|
393
|
+
if (!spec) throw new Error(`[dep-downloader] optional-deps.json \u91CC\u6CA1\u6709\u952E\uFF1A${key}`);
|
|
394
|
+
return spec;
|
|
395
|
+
}
|
|
396
|
+
function markerPath(spec) {
|
|
397
|
+
return path2.join(pkgDir(spec.name), ".e7-optional-ok");
|
|
398
|
+
}
|
|
399
|
+
function isPkgInstalled(spec) {
|
|
400
|
+
try {
|
|
401
|
+
return fs2.readFileSync(markerPath(spec), "utf8").trim() === spec.integrity;
|
|
402
|
+
} catch {
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
function isOptionalFeatureInstalled(key) {
|
|
407
|
+
const spec = featureSpec(key);
|
|
408
|
+
if (!isPkgInstalled(spec.main)) return false;
|
|
409
|
+
const plat = spec.platform?.[currentPlatformKey()];
|
|
410
|
+
if (plat && !isPkgInstalled(plat)) return false;
|
|
411
|
+
if ((spec.extra ?? []).some((p) => !isPkgInstalled(p))) return false;
|
|
412
|
+
return fs2.existsSync(path2.join(pkgDir(spec.main.name), "package.json"));
|
|
413
|
+
}
|
|
414
|
+
function acquireLock(name) {
|
|
415
|
+
const dir = path2.join(optionalDepsRoot(), "locks");
|
|
416
|
+
fs2.mkdirSync(dir, { recursive: true });
|
|
417
|
+
const lock = path2.join(dir, name.replace(/[/?%*:|"<>]/g, "_") + ".lock");
|
|
418
|
+
try {
|
|
419
|
+
fs2.mkdirSync(lock);
|
|
420
|
+
fs2.writeFileSync(path2.join(lock, "pid"), String(process.pid));
|
|
421
|
+
return lock;
|
|
422
|
+
} catch {
|
|
423
|
+
try {
|
|
424
|
+
const stat = fs2.statSync(lock);
|
|
425
|
+
if (Date.now() - stat.mtimeMs > LOCK_STALE_MS) {
|
|
426
|
+
fs2.rmSync(lock, { recursive: true, force: true });
|
|
427
|
+
return acquireLock(name);
|
|
428
|
+
}
|
|
429
|
+
return null;
|
|
430
|
+
} catch {
|
|
431
|
+
return acquireLock(name);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
function releaseLock(lock) {
|
|
436
|
+
fs2.rmSync(lock, { recursive: true, force: true });
|
|
437
|
+
}
|
|
438
|
+
function tarballUrl(spec) {
|
|
439
|
+
const scoped = spec.name.startsWith("@");
|
|
440
|
+
const file = `${scoped ? spec.name.slice(spec.name.indexOf("/") + 1) : spec.name}-${spec.version}.tgz`;
|
|
441
|
+
return `${registryBase()}/${spec.name}/-/${file}`;
|
|
442
|
+
}
|
|
443
|
+
async function downloadTo(spec, dest, onProgress) {
|
|
444
|
+
const url = tarballUrl(spec);
|
|
445
|
+
const res = await fetch(url, { redirect: "follow" });
|
|
446
|
+
if (!res.ok || !res.body) throw new Error(`\u4E0B\u8F7D ${spec.name}@${spec.version} \u5931\u8D25\uFF1AHTTP ${res.status}\uFF08${url}\uFF09`);
|
|
447
|
+
const total = Number(res.headers.get("content-length") || 0);
|
|
448
|
+
const hash = crypto.createHash("sha512");
|
|
449
|
+
const fd = fs2.openSync(dest, "w");
|
|
450
|
+
let got = 0;
|
|
451
|
+
try {
|
|
452
|
+
for await (const chunk of res.body) {
|
|
453
|
+
hash.update(chunk);
|
|
454
|
+
fs2.writeSync(fd, chunk);
|
|
455
|
+
got += chunk.length;
|
|
456
|
+
onProgress?.(got, total);
|
|
457
|
+
}
|
|
458
|
+
} finally {
|
|
459
|
+
fs2.closeSync(fd);
|
|
460
|
+
}
|
|
461
|
+
const digest = `sha512-${hash.digest("base64")}`;
|
|
462
|
+
if (digest !== spec.integrity) {
|
|
463
|
+
fs2.rmSync(dest, { force: true });
|
|
464
|
+
throw new Error(`${spec.name}@${spec.version} sha512 \u6821\u9A8C\u5931\u8D25\uFF08${got} \u5B57\u8282\uFF1B\u671F\u671B ${spec.integrity}\uFF1B\u5B9E\u5F97 ${digest}\uFF09\u2014\u2014\u955C\u50CF\u4E0D\u4E00\u81F4\u6216\u4F20\u8F93\u635F\u574F\uFF0C\u62D2\u88C5`);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
async function installPkg(spec, label, onProgress) {
|
|
468
|
+
if (isPkgInstalled(spec)) return;
|
|
469
|
+
const root = optionalDepsRoot();
|
|
470
|
+
fs2.mkdirSync(sharedNodeModules(), { recursive: true });
|
|
471
|
+
const lock = acquireLock(spec.name);
|
|
472
|
+
if (!lock) {
|
|
473
|
+
const deadline = Date.now() + PEER_WAIT_MS;
|
|
474
|
+
while (Date.now() < deadline) {
|
|
475
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
476
|
+
if (isPkgInstalled(spec)) return;
|
|
477
|
+
}
|
|
478
|
+
throw new Error(`${label}\uFF08${spec.name}\uFF09\u6B63\u5728\u88AB\u53E6\u4E00\u5B9E\u4F8B\u5B89\u88C5\u4F46\u8D85\u65F6\u672A\u5B8C\u6210\u2014\u2014\u7A0D\u540E\u91CD\u8BD5`);
|
|
479
|
+
}
|
|
480
|
+
try {
|
|
481
|
+
if (isPkgInstalled(spec)) return;
|
|
482
|
+
const staging = path2.join(root, "staging", `${spec.name.replace(/\//g, "_")}-${process.pid}-${Date.now()}`);
|
|
483
|
+
fs2.mkdirSync(staging, { recursive: true });
|
|
484
|
+
const tgz = `${staging}.tgz`;
|
|
485
|
+
try {
|
|
486
|
+
await downloadTo(spec, tgz, onProgress);
|
|
487
|
+
const tar = nodeRequire("tar");
|
|
488
|
+
await tar.extract({ file: tgz, cwd: staging, strip: 1 });
|
|
489
|
+
fs2.writeFileSync(path2.join(staging, ".e7-optional-ok"), spec.integrity);
|
|
490
|
+
const final = pkgDir(spec.name);
|
|
491
|
+
fs2.mkdirSync(path2.dirname(final), { recursive: true });
|
|
492
|
+
try {
|
|
493
|
+
fs2.renameSync(staging, final);
|
|
494
|
+
} catch {
|
|
495
|
+
if (!isPkgInstalled(spec)) throw new Error(`${spec.name} \u843D\u4F4D\u51B2\u7A81\u4E14\u5BF9\u7AEF\u4EA7\u7269\u4E0D\u5B8C\u6574\u2014\u2014\u91CD\u8BD5`);
|
|
496
|
+
fs2.rmSync(staging, { recursive: true, force: true });
|
|
497
|
+
}
|
|
498
|
+
} finally {
|
|
499
|
+
fs2.rmSync(tgz, { force: true });
|
|
500
|
+
fs2.rmSync(staging, { recursive: true, force: true });
|
|
501
|
+
}
|
|
502
|
+
} finally {
|
|
503
|
+
releaseLock(lock);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function notInstalledError(spec) {
|
|
507
|
+
const err = new Error(`${spec.label}\u672A\u5B89\u88C5\u4E14\u6309\u9700\u4E0B\u8F7D\u5DF2\u5173\u95ED\uFF08E7_OPTIONAL_DEPS=off / optionalDeps.autoDownload=false\uFF09`);
|
|
508
|
+
err.code = "ERR_MODULE_NOT_FOUND";
|
|
509
|
+
return err;
|
|
510
|
+
}
|
|
511
|
+
async function ensureOptionalFeature(key, onProgress) {
|
|
512
|
+
const spec = featureSpec(key);
|
|
513
|
+
if (isOptionalFeatureInstalled(key)) return pkgDir(spec.main.name);
|
|
514
|
+
if (!downloadsEnabled()) throw notInstalledError(spec);
|
|
515
|
+
const plat = spec.platform?.[currentPlatformKey()];
|
|
516
|
+
const pkgs = [spec.main, ...plat ? [plat] : [], ...spec.extra ?? []];
|
|
517
|
+
for (const p of pkgs) await installPkg(p, spec.label, (got, total) => onProgress?.(spec.label, got, total));
|
|
518
|
+
return pkgDir(spec.main.name);
|
|
519
|
+
}
|
|
520
|
+
function requireFromShared(name) {
|
|
521
|
+
const req = createRequire(path2.join(sharedNodeModules(), ".e7-resolve.js"));
|
|
522
|
+
return req(name);
|
|
523
|
+
}
|
|
524
|
+
async function loadOptionalModule(key, onProgress) {
|
|
525
|
+
const spec = featureSpec(key);
|
|
526
|
+
const notFound = (err) => err?.code === "ERR_MODULE_NOT_FOUND" || err?.code === "MODULE_NOT_FOUND";
|
|
527
|
+
try {
|
|
528
|
+
return nodeRequire(spec.main.name);
|
|
529
|
+
} catch (err) {
|
|
530
|
+
if (!notFound(err)) throw err;
|
|
531
|
+
}
|
|
532
|
+
if (!isOptionalFeatureInstalled(key)) {
|
|
533
|
+
if (!downloadsEnabled()) throw notInstalledError(spec);
|
|
534
|
+
await ensureOptionalFeature(key, onProgress);
|
|
535
|
+
}
|
|
536
|
+
const dir = pkgDir(spec.main.name);
|
|
537
|
+
try {
|
|
538
|
+
return requireFromShared(spec.main.name);
|
|
539
|
+
} catch (err) {
|
|
540
|
+
if (err?.code !== "ERR_REQUIRE_ESM") throw err;
|
|
541
|
+
const pkgJson = JSON.parse(fs2.readFileSync(path2.join(dir, "package.json"), "utf8"));
|
|
542
|
+
const entry = typeof pkgJson.exports === "object" && pkgJson.exports?.["."]?.require ? pkgJson.exports["."].require : pkgJson.main ?? "index.js";
|
|
543
|
+
return await import(pathToFileURL(path2.join(dir, typeof entry === "string" ? entry : "index.js")).href);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
function optionalFfmpegPath() {
|
|
547
|
+
const spec = OPTIONAL_FEATURES.ffmpeg;
|
|
548
|
+
if (!spec) return null;
|
|
549
|
+
const plat = spec.platform?.[currentPlatformKey()];
|
|
550
|
+
if (!plat || !isPkgInstalled(plat)) return null;
|
|
551
|
+
const bin = path2.join(pkgDir(plat.name), process.platform === "win32" ? "ffmpeg.exe" : "ffmpeg");
|
|
552
|
+
return fs2.existsSync(bin) ? bin : null;
|
|
553
|
+
}
|
|
554
|
+
function prefetchOptionalFeatures(keys, log = console.log) {
|
|
555
|
+
if (!downloadsEnabled()) return;
|
|
556
|
+
void (async () => {
|
|
557
|
+
for (const key of keys) {
|
|
558
|
+
try {
|
|
559
|
+
if (isOptionalFeatureInstalled(key)) continue;
|
|
560
|
+
log(`[dep-downloader] \u540E\u53F0\u9884\u53D6 ${featureSpec(key).label}\u2026`);
|
|
561
|
+
await ensureOptionalFeature(key);
|
|
562
|
+
log(`[dep-downloader] ${featureSpec(key).label} \u9884\u53D6\u5B8C\u6210`);
|
|
563
|
+
} catch (err) {
|
|
564
|
+
log(`[dep-downloader] \u9884\u53D6 ${key} \u5931\u8D25\uFF08\u7528\u5230\u65F6\u4F1A\u518D\u8BD5\uFF09\uFF1A${err?.message ?? err}`);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
})();
|
|
568
|
+
}
|
|
569
|
+
var nodeRequire, OPTIONAL_FEATURES, LOCK_STALE_MS, PEER_WAIT_MS;
|
|
570
|
+
var init_dep_downloader = __esm({
|
|
571
|
+
"src/optional/dep-downloader/index.ts"() {
|
|
572
|
+
"use strict";
|
|
573
|
+
init_live();
|
|
574
|
+
init_optional_deps();
|
|
575
|
+
nodeRequire = createRequire(import.meta.url);
|
|
576
|
+
OPTIONAL_FEATURES = (() => {
|
|
577
|
+
const raw = optional_deps_default;
|
|
578
|
+
const out = {};
|
|
579
|
+
for (const [key, v] of Object.entries(raw)) {
|
|
580
|
+
if (key === "//") continue;
|
|
581
|
+
const bad = !v?.main?.name || !v?.main?.version || !v?.main?.integrity?.startsWith("sha512-") || v.platform !== void 0 && Object.values(v.platform).some((p) => !p?.name || !p?.version || !p?.integrity?.startsWith("sha512-")) || v.extra !== void 0 && (!Array.isArray(v.extra) || v.extra.some((p) => !p?.name || !p?.version || !p?.integrity?.startsWith("sha512-")));
|
|
582
|
+
if (bad) throw new Error(`[dep-downloader] optional-deps.json \u6761\u76EE ${key} \u7F3A name/version/integrity\uFF08integrity \u53D6 npm view <name>@<version> dist.integrity\uFF09`);
|
|
583
|
+
out[key] = { key, label: v.label ?? key, main: v.main, platform: v.platform, extra: v.extra };
|
|
584
|
+
}
|
|
585
|
+
return out;
|
|
586
|
+
})();
|
|
587
|
+
LOCK_STALE_MS = 15 * 60 * 1e3;
|
|
588
|
+
PEER_WAIT_MS = 10 * 60 * 1e3;
|
|
589
|
+
}
|
|
590
|
+
});
|
|
2
591
|
|
|
3
592
|
// src/router/cpu-router-worker.mjs
|
|
4
593
|
import { parentPort, workerData } from "node:worker_threads";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import { createHash } from "node:crypto";
|
|
594
|
+
import fs3 from "node:fs/promises";
|
|
595
|
+
import path3 from "node:path";
|
|
596
|
+
import { createHash as createHash2 } from "node:crypto";
|
|
8
597
|
import { Tokenizer } from "@huggingface/tokenizers";
|
|
9
|
-
import * as ort from "onnxruntime-node";
|
|
10
598
|
|
|
11
599
|
// src/router/cpu-router-data.mjs
|
|
12
600
|
function sanitizeText(text) {
|
|
@@ -55,19 +643,27 @@ function decodeRouterOutputs(outputs, trainedTasks) {
|
|
|
55
643
|
}
|
|
56
644
|
|
|
57
645
|
// src/router/cpu-router-worker.mjs
|
|
646
|
+
var ort = await (async () => {
|
|
647
|
+
try {
|
|
648
|
+
return await import("onnxruntime-node");
|
|
649
|
+
} catch {
|
|
650
|
+
}
|
|
651
|
+
const { loadOptionalModule: loadOptionalModule2 } = await Promise.resolve().then(() => (init_dep_downloader(), dep_downloader_exports));
|
|
652
|
+
return await loadOptionalModule2("cpu-router");
|
|
653
|
+
})();
|
|
58
654
|
var { modelDir, threads } = workerData;
|
|
59
|
-
var readJson = async (name) => JSON.parse(await
|
|
655
|
+
var readJson = async (name) => JSON.parse(await fs3.readFile(path3.join(modelDir, name), "utf8"));
|
|
60
656
|
var metadata = await readJson("runtime.json");
|
|
61
657
|
var files = ["router.fp32.onnx", "tokenizer.json", "tokenizer_config.json", "metadata.json"];
|
|
62
658
|
if (metadata.schemaVersion !== 1 || metadata.maxLength !== 384) throw new Error("Unsupported CPU router manifest");
|
|
63
659
|
for (const file of files) {
|
|
64
|
-
const data = await
|
|
65
|
-
if (
|
|
660
|
+
const data = await fs3.readFile(path3.join(modelDir, file));
|
|
661
|
+
if (createHash2("sha256").update(data).digest("hex") !== metadata.sha256?.[file]) throw new Error("CPU router integrity check failed");
|
|
66
662
|
}
|
|
67
663
|
var trained = await readJson("metadata.json");
|
|
68
664
|
if (trained.schema_version !== 1 || !Array.isArray(trained.trained_tasks) || JSON.stringify(trained.task_labels?.dev) !== JSON.stringify(["nodev", "dev"]) || JSON.stringify(trained.task_labels?.mode) !== JSON.stringify(["emotion", "work"])) throw new Error("Unsupported CPU router labels");
|
|
69
665
|
var tokenizer = new Tokenizer(await readJson("tokenizer.json"), await readJson("tokenizer_config.json"));
|
|
70
|
-
var session = await ort.InferenceSession.create(
|
|
666
|
+
var session = await ort.InferenceSession.create(path3.join(modelDir, "router.fp32.onnx"), {
|
|
71
667
|
executionProviders: ["cpu"],
|
|
72
668
|
intraOpNumThreads: threads,
|
|
73
669
|
interOpNumThreads: 1,
|
|
Binary file
|