engine7 7.1.148 → 7.1.149
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/bg-worker.mjs +141 -36
- package/dist/cli.mjs +2175 -1348
- package/dist/engine-startup.mjs +1362 -992
- package/dist/main.mjs +1374 -996
- package/dist/recall-worker.mjs +135 -29
- package/dist/topics-worker.mjs +123 -28
- package/dist/travel-gateway.mjs +265 -100
- package/dist/travel-host.mjs +63 -47
- package/dist/travel-node.mjs +2 -3
- package/dist/travel-oss-bundle-stream.mjs +1 -1
- package/dist/travel-pairing.mjs +271 -106
- package/dist/travel-sync-worker.mjs +223 -114
- package/dist/web-console.mjs +298 -50
- package/package.json +1 -1
package/dist/bg-worker.mjs
CHANGED
|
@@ -6118,16 +6118,15 @@ function stripInjectedContext(text2) {
|
|
|
6118
6118
|
function escapeRegExp(s) {
|
|
6119
6119
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6120
6120
|
}
|
|
6121
|
-
var
|
|
6121
|
+
var SYSTEM_REMINDER_BLOCK, INJECT_SECTION_HEADS, KNOWN_INJECTED_TEXT, INJECTED_LINE_PREFIXES, XML_BLOCK;
|
|
6122
6122
|
var init_strip_injected = __esm({
|
|
6123
6123
|
"src/messages/strip-injected.ts"() {
|
|
6124
6124
|
"use strict";
|
|
6125
|
-
SKILL_GATE_HINT_PREFIX = "\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1";
|
|
6126
6125
|
SYSTEM_REMINDER_BLOCK = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
6127
6126
|
INJECT_SECTION_HEADS = /^(本轮对话|当前情绪状态|当前模式)/;
|
|
6128
6127
|
KNOWN_INJECTED_TEXT = [
|
|
6129
|
-
|
|
6130
|
-
// skill-gate
|
|
6128
|
+
"\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1",
|
|
6129
|
+
// 旧版 skill-gate 提示前缀,兼容未打标签的历史
|
|
6131
6130
|
"\u5F00\u53D1\u4EFB\u52A1\u8DEF\u6807\uFF0C\u6309\u573A\u666F\u5BF9\u53F7\u5165\u5EA7",
|
|
6132
6131
|
// skill-gate hint(0912 老文案,历史 JSONL 兼容)
|
|
6133
6132
|
"\u3010\u5B9A\u65F6\u5FC3\u8DF3\u3011\u8BF7 read HEARTBEAT.md"
|
|
@@ -9848,10 +9847,10 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
9848
9847
|
if (db2.isTransaction) throw new Error("REPLICATION_TRANSACTION_ALREADY_OPEN");
|
|
9849
9848
|
const exec = db2.exec, prepare = db2.prepare;
|
|
9850
9849
|
let active, failed = false, closed = false, reading = false;
|
|
9851
|
-
let
|
|
9850
|
+
let direct2;
|
|
9852
9851
|
const check = () => {
|
|
9853
9852
|
if (closed) throw new Error("REPLICATION_TRANSACTION_CLOSED");
|
|
9854
|
-
|
|
9853
|
+
direct2?.assertOpen();
|
|
9855
9854
|
};
|
|
9856
9855
|
const wrappedExec = function(sql) {
|
|
9857
9856
|
check();
|
|
@@ -9922,10 +9921,10 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
9922
9921
|
db2.prepare = checkedPrepare;
|
|
9923
9922
|
const transaction = (operation) => {
|
|
9924
9923
|
check();
|
|
9925
|
-
if (db2.isTransaction) return
|
|
9924
|
+
if (db2.isTransaction) return direct2.scope(operation);
|
|
9926
9925
|
db2.exec("BEGIN IMMEDIATE");
|
|
9927
9926
|
try {
|
|
9928
|
-
const result =
|
|
9927
|
+
const result = direct2.scope(operation);
|
|
9929
9928
|
if (result && typeof result.then === "function") throw new Error("REPLICATION_ASYNC_TRANSACTION");
|
|
9930
9929
|
db2.exec("COMMIT");
|
|
9931
9930
|
return result;
|
|
@@ -9934,10 +9933,10 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
9934
9933
|
throw error;
|
|
9935
9934
|
}
|
|
9936
9935
|
};
|
|
9937
|
-
|
|
9936
|
+
direct2 = installAutocommitCapture(db2, transaction);
|
|
9938
9937
|
return {
|
|
9939
9938
|
assertOpen: check,
|
|
9940
|
-
scope: (operation) =>
|
|
9939
|
+
scope: (operation) => direct2.scope(operation),
|
|
9941
9940
|
transaction,
|
|
9942
9941
|
close() {
|
|
9943
9942
|
if (closed) return;
|
|
@@ -9946,7 +9945,7 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
9946
9945
|
source.endCapture(active);
|
|
9947
9946
|
active = void 0;
|
|
9948
9947
|
}
|
|
9949
|
-
|
|
9948
|
+
direct2.close();
|
|
9950
9949
|
db2.prepare = prepare;
|
|
9951
9950
|
db2.exec = exec;
|
|
9952
9951
|
closed = true;
|
|
@@ -13975,32 +13974,32 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
13975
13974
|
return { built: !hasStats, ms: Date.now() - started };
|
|
13976
13975
|
}
|
|
13977
13976
|
async close() {
|
|
13978
|
-
const
|
|
13977
|
+
const errors2 = [];
|
|
13979
13978
|
try {
|
|
13980
13979
|
this.capture?.close();
|
|
13981
13980
|
} catch (error) {
|
|
13982
|
-
|
|
13981
|
+
errors2.push(error);
|
|
13983
13982
|
}
|
|
13984
13983
|
try {
|
|
13985
13984
|
this.db.close();
|
|
13986
13985
|
} catch (error) {
|
|
13987
|
-
|
|
13986
|
+
errors2.push(error);
|
|
13988
13987
|
}
|
|
13989
13988
|
try {
|
|
13990
13989
|
await this.vectors?.close();
|
|
13991
13990
|
} catch (error) {
|
|
13992
|
-
|
|
13991
|
+
errors2.push(error);
|
|
13993
13992
|
} finally {
|
|
13994
13993
|
this.vectors = null;
|
|
13995
13994
|
}
|
|
13996
13995
|
try {
|
|
13997
13996
|
this.releaseRuntimeWriter?.();
|
|
13998
13997
|
} catch (error) {
|
|
13999
|
-
|
|
13998
|
+
errors2.push(error);
|
|
14000
13999
|
} finally {
|
|
14001
14000
|
this.releaseRuntimeWriter = void 0;
|
|
14002
14001
|
}
|
|
14003
|
-
if (
|
|
14002
|
+
if (errors2.length) throw new AggregateError(errors2, "MEM7_CLOSE_FAILED");
|
|
14004
14003
|
}
|
|
14005
14004
|
// ── memcell 账本 ──────────────────────────────────────────
|
|
14006
14005
|
insertMemcell(cell) {
|
|
@@ -15283,7 +15282,7 @@ var init_capture_cache = __esm({
|
|
|
15283
15282
|
});
|
|
15284
15283
|
|
|
15285
15284
|
// src/travel/apply-transaction.ts
|
|
15286
|
-
import { closeSync as closeSync7, existsSync as existsSync8, fsyncSync as fsyncSync6, lstatSync as lstatSync9, mkdirSync as mkdirSync10, openSync as openSync7, readFileSync as readFileSync12, readSync as readSync2, renameSync as renameSync6, rmSync, writeFileSync as writeFileSync8 } from "node:fs";
|
|
15285
|
+
import { closeSync as closeSync7, existsSync as existsSync8, fsyncSync as fsyncSync6, linkSync, lstatSync as lstatSync9, mkdirSync as mkdirSync10, openSync as openSync7, readFileSync as readFileSync12, readSync as readSync2, renameSync as renameSync6, rmSync, writeFileSync as writeFileSync8 } from "node:fs";
|
|
15287
15286
|
import { dirname as dirname7, join as join15, resolve as resolve8 } from "node:path";
|
|
15288
15287
|
import { createHash as createHash21, randomUUID as randomUUID11 } from "node:crypto";
|
|
15289
15288
|
function assertPath(root, rel) {
|
|
@@ -15299,7 +15298,7 @@ function assertPath(root, rel) {
|
|
|
15299
15298
|
}
|
|
15300
15299
|
return path22;
|
|
15301
15300
|
}
|
|
15302
|
-
function atomic(path22, body) {
|
|
15301
|
+
function atomic(path22, body, exclusive = false) {
|
|
15303
15302
|
const temp = path22 + "." + randomUUID11() + ".tmp";
|
|
15304
15303
|
let fd;
|
|
15305
15304
|
try {
|
|
@@ -15308,7 +15307,8 @@ function atomic(path22, body) {
|
|
|
15308
15307
|
fsyncSync6(fd);
|
|
15309
15308
|
closeSync7(fd);
|
|
15310
15309
|
fd = void 0;
|
|
15311
|
-
|
|
15310
|
+
if (exclusive) linkSync(temp, path22);
|
|
15311
|
+
else renameSync6(temp, path22);
|
|
15312
15312
|
} finally {
|
|
15313
15313
|
if (fd !== void 0) closeSync7(fd);
|
|
15314
15314
|
rmSync(temp, { force: true });
|
|
@@ -25916,13 +25916,15 @@ function beginSkillGate(sessionId) {
|
|
|
25916
25916
|
function isUserChannel(ch) {
|
|
25917
25917
|
return !!ch && USER_CHANNELS.has(ch);
|
|
25918
25918
|
}
|
|
25919
|
-
var USER_CHANNELS, loadedBySession, MAX_TRACKED_SESSIONS;
|
|
25919
|
+
var USER_CHANNELS, SKILL_CHANNELS, loadedBySession, MAX_TRACKED_SESSIONS;
|
|
25920
25920
|
var init_skill_gate = __esm({
|
|
25921
25921
|
"src/skills/skill-gate.ts"() {
|
|
25922
25922
|
"use strict";
|
|
25923
25923
|
init_strip_injected();
|
|
25924
|
+
init_writer();
|
|
25924
25925
|
init_cpu_router_scene();
|
|
25925
25926
|
USER_CHANNELS = /* @__PURE__ */ new Set(["discord", "feishu", "wechat", "telegram", "cli", "console", "voice-chat", "deskBuddy", "ccBridge"]);
|
|
25927
|
+
SKILL_CHANNELS = /* @__PURE__ */ new Set([...USER_CHANNELS, "chan7", "webhook"]);
|
|
25926
25928
|
loadedBySession = /* @__PURE__ */ new Map();
|
|
25927
25929
|
MAX_TRACKED_SESSIONS = 100;
|
|
25928
25930
|
}
|
|
@@ -26710,8 +26712,120 @@ var init_provider = __esm({
|
|
|
26710
26712
|
}
|
|
26711
26713
|
});
|
|
26712
26714
|
|
|
26715
|
+
// src/services/adaptive-proxy.ts
|
|
26716
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
26717
|
+
import { Agent, Client, ProxyAgent, errors } from "undici";
|
|
26718
|
+
function proxyAddress(value) {
|
|
26719
|
+
const bareLoopback = /^(?:localhost\.?|127(?:\.\d{1,3}){3}|\[::1\]):\d+$/i;
|
|
26720
|
+
return new URL(bareLoopback.test(value) ? `http://${value}` : value);
|
|
26721
|
+
}
|
|
26722
|
+
function localProxyKey(url) {
|
|
26723
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
26724
|
+
const host = url.hostname.replace(/\.$/, "");
|
|
26725
|
+
if (host !== "localhost" && host !== "[::1]" && !/^127\./.test(host)) return;
|
|
26726
|
+
return `${host}:${url.port || (url.protocol === "https:" ? 443 : 80)}`;
|
|
26727
|
+
}
|
|
26728
|
+
function proxyUnavailable(key5) {
|
|
26729
|
+
return (unreachableUntil.get(key5) ?? -Infinity) > Date.now();
|
|
26730
|
+
}
|
|
26731
|
+
function markUnavailable(key5) {
|
|
26732
|
+
unreachableUntil.set(key5, Date.now() + RETRY_PROXY_AFTER_MS);
|
|
26733
|
+
}
|
|
26734
|
+
function isTcpDialFailure(error) {
|
|
26735
|
+
if (error instanceof AggregateError) {
|
|
26736
|
+
return error.errors.length > 0 && error.errors.every(isTcpDialFailure);
|
|
26737
|
+
}
|
|
26738
|
+
const err = error;
|
|
26739
|
+
return err?.syscall === "connect" && dialFailureCodes.has(err.code ?? "");
|
|
26740
|
+
}
|
|
26741
|
+
function getProxyDispatcher(value) {
|
|
26742
|
+
const raw = value?.trim();
|
|
26743
|
+
if (!raw) return;
|
|
26744
|
+
const cached = dispatchers.get(raw);
|
|
26745
|
+
if (cached) return cached;
|
|
26746
|
+
const url = proxyAddress(raw);
|
|
26747
|
+
const key5 = localProxyKey(url);
|
|
26748
|
+
const dispatcher = key5 ? new AdaptiveProxyDispatcher(url.href, key5) : new ProxyAgent({ uri: url.href });
|
|
26749
|
+
dispatchers.set(raw, dispatcher);
|
|
26750
|
+
return dispatcher;
|
|
26751
|
+
}
|
|
26752
|
+
var RETRY_PROXY_AFTER_MS, LOCAL_CONNECT_TIMEOUT_MS, unreachableUntil, failedProxyDials, dispatchers, direct, dialFailureCodes, AdaptiveProxyDispatcher;
|
|
26753
|
+
var init_adaptive_proxy = __esm({
|
|
26754
|
+
"src/services/adaptive-proxy.ts"() {
|
|
26755
|
+
"use strict";
|
|
26756
|
+
RETRY_PROXY_AFTER_MS = 5e3;
|
|
26757
|
+
LOCAL_CONNECT_TIMEOUT_MS = 1e3;
|
|
26758
|
+
unreachableUntil = /* @__PURE__ */ new Map();
|
|
26759
|
+
failedProxyDials = /* @__PURE__ */ new WeakSet();
|
|
26760
|
+
dispatchers = /* @__PURE__ */ new Map();
|
|
26761
|
+
direct = new Agent();
|
|
26762
|
+
dialFailureCodes = /* @__PURE__ */ new Set(["ECONNREFUSED", "ETIMEDOUT", "ENETUNREACH", "EHOSTUNREACH", "EADDRNOTAVAIL"]);
|
|
26763
|
+
AdaptiveProxyDispatcher = class extends ProxyAgent {
|
|
26764
|
+
constructor(uri, key5) {
|
|
26765
|
+
super({
|
|
26766
|
+
uri,
|
|
26767
|
+
proxyTls: { timeout: LOCAL_CONNECT_TIMEOUT_MS },
|
|
26768
|
+
clientFactory(origin, opts) {
|
|
26769
|
+
const { connect } = opts;
|
|
26770
|
+
return new Client(origin, {
|
|
26771
|
+
connect(options, callback) {
|
|
26772
|
+
let tcpConnected = false;
|
|
26773
|
+
const socket = connect(options, (...result) => {
|
|
26774
|
+
const [error] = result;
|
|
26775
|
+
if (error && !tcpConnected && (isTcpDialFailure(error) || error.code === "UND_ERR_CONNECT_TIMEOUT")) {
|
|
26776
|
+
markUnavailable(key5);
|
|
26777
|
+
failedProxyDials.add(error);
|
|
26778
|
+
}
|
|
26779
|
+
callback(...result);
|
|
26780
|
+
});
|
|
26781
|
+
socket.once("connect", () => {
|
|
26782
|
+
tcpConnected = true;
|
|
26783
|
+
});
|
|
26784
|
+
return socket;
|
|
26785
|
+
}
|
|
26786
|
+
});
|
|
26787
|
+
}
|
|
26788
|
+
});
|
|
26789
|
+
this.key = key5;
|
|
26790
|
+
}
|
|
26791
|
+
dispatch(options, handler) {
|
|
26792
|
+
if (!this.closed && !this.destroyed && proxyUnavailable(this.key)) {
|
|
26793
|
+
const headers = options.headers;
|
|
26794
|
+
const keys = !headers ? [] : Array.isArray(headers) ? headers.filter((_, index) => index % 2 === 0) : Symbol.iterator in headers ? Array.from(headers, ([name]) => name) : Object.keys(headers);
|
|
26795
|
+
if (keys.some((name) => name.toLowerCase() === "proxy-authorization")) {
|
|
26796
|
+
throw new errors.InvalidArgumentError("Proxy-Authorization should be sent in ProxyAgent constructor");
|
|
26797
|
+
}
|
|
26798
|
+
return direct.dispatch(options, handler);
|
|
26799
|
+
}
|
|
26800
|
+
let connected = false;
|
|
26801
|
+
const extended = handler;
|
|
26802
|
+
const guarded = {
|
|
26803
|
+
onConnect: (abort) => {
|
|
26804
|
+
connected = true;
|
|
26805
|
+
handler.onConnect?.(abort);
|
|
26806
|
+
},
|
|
26807
|
+
onError: (error) => {
|
|
26808
|
+
if (!connected && failedProxyDials.has(error)) {
|
|
26809
|
+
direct.dispatch(options, handler);
|
|
26810
|
+
} else {
|
|
26811
|
+
handler.onError?.(error);
|
|
26812
|
+
}
|
|
26813
|
+
},
|
|
26814
|
+
onHeaders: handler.onHeaders?.bind(handler),
|
|
26815
|
+
onData: handler.onData?.bind(handler),
|
|
26816
|
+
onComplete: handler.onComplete?.bind(handler),
|
|
26817
|
+
onUpgrade: handler.onUpgrade?.bind(handler),
|
|
26818
|
+
onResponseStarted: handler.onResponseStarted?.bind(handler),
|
|
26819
|
+
onBodySent: handler.onBodySent?.bind(handler),
|
|
26820
|
+
onRequestSent: extended.onRequestSent?.bind(handler)
|
|
26821
|
+
};
|
|
26822
|
+
return super.dispatch(options, guarded);
|
|
26823
|
+
}
|
|
26824
|
+
};
|
|
26825
|
+
}
|
|
26826
|
+
});
|
|
26827
|
+
|
|
26713
26828
|
// src/services/withRetry.ts
|
|
26714
|
-
import { ProxyAgent } from "undici";
|
|
26715
26829
|
function sleep(ms, signal) {
|
|
26716
26830
|
return new Promise((resolve26, reject) => {
|
|
26717
26831
|
if (signal?.aborted) {
|
|
@@ -26779,15 +26893,6 @@ function shouldRetry(status, errorBody) {
|
|
|
26779
26893
|
if (errorBody?.includes('"type":"overloaded_error"')) return true;
|
|
26780
26894
|
return false;
|
|
26781
26895
|
}
|
|
26782
|
-
function getProxyDispatcher(proxyUrl) {
|
|
26783
|
-
if (!proxyUrl) return void 0;
|
|
26784
|
-
let agent = proxyAgentCache.get(proxyUrl);
|
|
26785
|
-
if (!agent) {
|
|
26786
|
-
agent = new ProxyAgent({ uri: proxyUrl });
|
|
26787
|
-
proxyAgentCache.set(proxyUrl, agent);
|
|
26788
|
-
}
|
|
26789
|
-
return agent;
|
|
26790
|
-
}
|
|
26791
26896
|
async function* fetchWithRetry(url, init, providerLabel, proxy, beforeRequest, retryPolicy) {
|
|
26792
26897
|
const configuredRetries = getMaxRetries();
|
|
26793
26898
|
const maxRetries = retryPolicy?.maxRetries === void 0 ? configuredRetries : Math.min(configuredRetries, Math.max(0, Math.floor(retryPolicy.maxRetries)));
|
|
@@ -26925,10 +27030,11 @@ function readWithTimeout(reader, timeoutMs, signal) {
|
|
|
26925
27030
|
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
26926
27031
|
});
|
|
26927
27032
|
}
|
|
26928
|
-
var DEFAULT_MAX_RETRIES, BASE_DELAY_MS, MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, READ_TIMEOUT_MS, FIRST_READ_TIMEOUT_MS, NO_PROGRESS_TIMEOUT_MS
|
|
27033
|
+
var DEFAULT_MAX_RETRIES, BASE_DELAY_MS, MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, READ_TIMEOUT_MS, FIRST_READ_TIMEOUT_MS, NO_PROGRESS_TIMEOUT_MS;
|
|
26929
27034
|
var init_withRetry = __esm({
|
|
26930
27035
|
"src/services/withRetry.ts"() {
|
|
26931
27036
|
"use strict";
|
|
27037
|
+
init_adaptive_proxy();
|
|
26932
27038
|
DEFAULT_MAX_RETRIES = 10;
|
|
26933
27039
|
BASE_DELAY_MS = 500;
|
|
26934
27040
|
MAX_DELAY_MS = 32e3;
|
|
@@ -26936,7 +27042,6 @@ var init_withRetry = __esm({
|
|
|
26936
27042
|
READ_TIMEOUT_MS = 6e4;
|
|
26937
27043
|
FIRST_READ_TIMEOUT_MS = parseInt(process.env.API_TIMEOUT_MS || "", 10) || 6e5;
|
|
26938
27044
|
NO_PROGRESS_TIMEOUT_MS = parseInt(process.env.STREAM_NO_PROGRESS_TIMEOUT_MS || "", 10) || 3e5;
|
|
26939
|
-
proxyAgentCache = /* @__PURE__ */ new Map();
|
|
26940
27045
|
}
|
|
26941
27046
|
});
|
|
26942
27047
|
|
|
@@ -44332,12 +44437,12 @@ function createSqliteMaintenance(stateDir2, options = {}) {
|
|
|
44332
44437
|
child = fork(entry, ["--sqlite-maintenance", path22, JSON.stringify({ stateDir: stateDir2, minFreeBytes: options.minFreeBytes })], launchOptions);
|
|
44333
44438
|
console.log("[bg-worker] SQLite physical reclaim started");
|
|
44334
44439
|
const current2 = child;
|
|
44335
|
-
let output = "",
|
|
44440
|
+
let output = "", errors2 = "";
|
|
44336
44441
|
current2.stdout?.on("data", (data) => {
|
|
44337
44442
|
output = (output + String(data)).slice(-4096);
|
|
44338
44443
|
});
|
|
44339
44444
|
current2.stderr?.on("data", (data) => {
|
|
44340
|
-
|
|
44445
|
+
errors2 = (errors2 + String(data)).slice(-4096);
|
|
44341
44446
|
});
|
|
44342
44447
|
current2.on("message", (message) => {
|
|
44343
44448
|
if (message?.type === "sqliteMaintenancePhase") options.onPhase?.(message.phase);
|
|
@@ -44353,7 +44458,7 @@ function createSqliteMaintenance(stateDir2, options = {}) {
|
|
|
44353
44458
|
if (child === current2) child = void 0;
|
|
44354
44459
|
nextCheck = Date.now() + (options.checkIntervalMs ?? 6e4);
|
|
44355
44460
|
if (code === 0 && output.trim()) console.log(`[bg-worker] SQLite physical reclaim ${output.trim()}`);
|
|
44356
|
-
else console.log(`[bg-worker] SQLite physical reclaim deferred${
|
|
44461
|
+
else console.log(`[bg-worker] SQLite physical reclaim deferred${errors2 ? `: ${errors2.trim()}` : " (input or shutdown)"}`);
|
|
44357
44462
|
resolve26();
|
|
44358
44463
|
};
|
|
44359
44464
|
current2.once("close", finish);
|