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/recall-worker.mjs
CHANGED
|
@@ -5714,16 +5714,15 @@ function stripInjectedContext(text2) {
|
|
|
5714
5714
|
function escapeRegExp(s) {
|
|
5715
5715
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5716
5716
|
}
|
|
5717
|
-
var
|
|
5717
|
+
var SYSTEM_REMINDER_BLOCK, INJECT_SECTION_HEADS, KNOWN_INJECTED_TEXT, INJECTED_LINE_PREFIXES, XML_BLOCK;
|
|
5718
5718
|
var init_strip_injected = __esm({
|
|
5719
5719
|
"src/messages/strip-injected.ts"() {
|
|
5720
5720
|
"use strict";
|
|
5721
|
-
SKILL_GATE_HINT_PREFIX = "\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1";
|
|
5722
5721
|
SYSTEM_REMINDER_BLOCK = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
5723
5722
|
INJECT_SECTION_HEADS = /^(本轮对话|当前情绪状态|当前模式)/;
|
|
5724
5723
|
KNOWN_INJECTED_TEXT = [
|
|
5725
|
-
|
|
5726
|
-
// skill-gate
|
|
5724
|
+
"\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1",
|
|
5725
|
+
// 旧版 skill-gate 提示前缀,兼容未打标签的历史
|
|
5727
5726
|
"\u5F00\u53D1\u4EFB\u52A1\u8DEF\u6807\uFF0C\u6309\u573A\u666F\u5BF9\u53F7\u5165\u5EA7",
|
|
5728
5727
|
// skill-gate hint(0912 老文案,历史 JSONL 兼容)
|
|
5729
5728
|
"\u3010\u5B9A\u65F6\u5FC3\u8DF3\u3011\u8BF7 read HEARTBEAT.md"
|
|
@@ -8383,10 +8382,10 @@ function installSQLiteWriteCapture(db, source) {
|
|
|
8383
8382
|
if (db.isTransaction) throw new Error("REPLICATION_TRANSACTION_ALREADY_OPEN");
|
|
8384
8383
|
const exec = db.exec, prepare = db.prepare;
|
|
8385
8384
|
let active, failed = false, closed = false, reading = false;
|
|
8386
|
-
let
|
|
8385
|
+
let direct2;
|
|
8387
8386
|
const check = () => {
|
|
8388
8387
|
if (closed) throw new Error("REPLICATION_TRANSACTION_CLOSED");
|
|
8389
|
-
|
|
8388
|
+
direct2?.assertOpen();
|
|
8390
8389
|
};
|
|
8391
8390
|
const wrappedExec = function(sql) {
|
|
8392
8391
|
check();
|
|
@@ -8457,10 +8456,10 @@ function installSQLiteWriteCapture(db, source) {
|
|
|
8457
8456
|
db.prepare = checkedPrepare;
|
|
8458
8457
|
const transaction = (operation) => {
|
|
8459
8458
|
check();
|
|
8460
|
-
if (db.isTransaction) return
|
|
8459
|
+
if (db.isTransaction) return direct2.scope(operation);
|
|
8461
8460
|
db.exec("BEGIN IMMEDIATE");
|
|
8462
8461
|
try {
|
|
8463
|
-
const result =
|
|
8462
|
+
const result = direct2.scope(operation);
|
|
8464
8463
|
if (result && typeof result.then === "function") throw new Error("REPLICATION_ASYNC_TRANSACTION");
|
|
8465
8464
|
db.exec("COMMIT");
|
|
8466
8465
|
return result;
|
|
@@ -8469,10 +8468,10 @@ function installSQLiteWriteCapture(db, source) {
|
|
|
8469
8468
|
throw error;
|
|
8470
8469
|
}
|
|
8471
8470
|
};
|
|
8472
|
-
|
|
8471
|
+
direct2 = installAutocommitCapture(db, transaction);
|
|
8473
8472
|
return {
|
|
8474
8473
|
assertOpen: check,
|
|
8475
|
-
scope: (operation) =>
|
|
8474
|
+
scope: (operation) => direct2.scope(operation),
|
|
8476
8475
|
transaction,
|
|
8477
8476
|
close() {
|
|
8478
8477
|
if (closed) return;
|
|
@@ -8481,7 +8480,7 @@ function installSQLiteWriteCapture(db, source) {
|
|
|
8481
8480
|
source.endCapture(active);
|
|
8482
8481
|
active = void 0;
|
|
8483
8482
|
}
|
|
8484
|
-
|
|
8483
|
+
direct2.close();
|
|
8485
8484
|
db.prepare = prepare;
|
|
8486
8485
|
db.exec = exec;
|
|
8487
8486
|
closed = true;
|
|
@@ -11963,32 +11962,32 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
11963
11962
|
return { built: !hasStats, ms: Date.now() - started };
|
|
11964
11963
|
}
|
|
11965
11964
|
async close() {
|
|
11966
|
-
const
|
|
11965
|
+
const errors2 = [];
|
|
11967
11966
|
try {
|
|
11968
11967
|
this.capture?.close();
|
|
11969
11968
|
} catch (error) {
|
|
11970
|
-
|
|
11969
|
+
errors2.push(error);
|
|
11971
11970
|
}
|
|
11972
11971
|
try {
|
|
11973
11972
|
this.db.close();
|
|
11974
11973
|
} catch (error) {
|
|
11975
|
-
|
|
11974
|
+
errors2.push(error);
|
|
11976
11975
|
}
|
|
11977
11976
|
try {
|
|
11978
11977
|
await this.vectors?.close();
|
|
11979
11978
|
} catch (error) {
|
|
11980
|
-
|
|
11979
|
+
errors2.push(error);
|
|
11981
11980
|
} finally {
|
|
11982
11981
|
this.vectors = null;
|
|
11983
11982
|
}
|
|
11984
11983
|
try {
|
|
11985
11984
|
this.releaseRuntimeWriter?.();
|
|
11986
11985
|
} catch (error) {
|
|
11987
|
-
|
|
11986
|
+
errors2.push(error);
|
|
11988
11987
|
} finally {
|
|
11989
11988
|
this.releaseRuntimeWriter = void 0;
|
|
11990
11989
|
}
|
|
11991
|
-
if (
|
|
11990
|
+
if (errors2.length) throw new AggregateError(errors2, "MEM7_CLOSE_FAILED");
|
|
11992
11991
|
}
|
|
11993
11992
|
// ── memcell 账本 ──────────────────────────────────────────
|
|
11994
11993
|
insertMemcell(cell) {
|
|
@@ -15945,11 +15944,15 @@ var init_cpu_router_scene = __esm({
|
|
|
15945
15944
|
});
|
|
15946
15945
|
|
|
15947
15946
|
// src/skills/skill-gate.ts
|
|
15947
|
+
var USER_CHANNELS, SKILL_CHANNELS;
|
|
15948
15948
|
var init_skill_gate = __esm({
|
|
15949
15949
|
"src/skills/skill-gate.ts"() {
|
|
15950
15950
|
"use strict";
|
|
15951
15951
|
init_strip_injected();
|
|
15952
|
+
init_writer();
|
|
15952
15953
|
init_cpu_router_scene();
|
|
15954
|
+
USER_CHANNELS = /* @__PURE__ */ new Set(["discord", "feishu", "wechat", "telegram", "cli", "console", "voice-chat", "deskBuddy", "ccBridge"]);
|
|
15955
|
+
SKILL_CHANNELS = /* @__PURE__ */ new Set([...USER_CHANNELS, "chan7", "webhook"]);
|
|
15953
15956
|
}
|
|
15954
15957
|
});
|
|
15955
15958
|
|
|
@@ -16095,8 +16098,120 @@ var init_provider = __esm({
|
|
|
16095
16098
|
}
|
|
16096
16099
|
});
|
|
16097
16100
|
|
|
16101
|
+
// src/services/adaptive-proxy.ts
|
|
16102
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
16103
|
+
import { Agent, Client, ProxyAgent, errors } from "undici";
|
|
16104
|
+
function proxyAddress(value) {
|
|
16105
|
+
const bareLoopback = /^(?:localhost\.?|127(?:\.\d{1,3}){3}|\[::1\]):\d+$/i;
|
|
16106
|
+
return new URL(bareLoopback.test(value) ? `http://${value}` : value);
|
|
16107
|
+
}
|
|
16108
|
+
function localProxyKey(url) {
|
|
16109
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
16110
|
+
const host = url.hostname.replace(/\.$/, "");
|
|
16111
|
+
if (host !== "localhost" && host !== "[::1]" && !/^127\./.test(host)) return;
|
|
16112
|
+
return `${host}:${url.port || (url.protocol === "https:" ? 443 : 80)}`;
|
|
16113
|
+
}
|
|
16114
|
+
function proxyUnavailable(key4) {
|
|
16115
|
+
return (unreachableUntil.get(key4) ?? -Infinity) > Date.now();
|
|
16116
|
+
}
|
|
16117
|
+
function markUnavailable(key4) {
|
|
16118
|
+
unreachableUntil.set(key4, Date.now() + RETRY_PROXY_AFTER_MS);
|
|
16119
|
+
}
|
|
16120
|
+
function isTcpDialFailure(error) {
|
|
16121
|
+
if (error instanceof AggregateError) {
|
|
16122
|
+
return error.errors.length > 0 && error.errors.every(isTcpDialFailure);
|
|
16123
|
+
}
|
|
16124
|
+
const err = error;
|
|
16125
|
+
return err?.syscall === "connect" && dialFailureCodes.has(err.code ?? "");
|
|
16126
|
+
}
|
|
16127
|
+
function getProxyDispatcher(value) {
|
|
16128
|
+
const raw = value?.trim();
|
|
16129
|
+
if (!raw) return;
|
|
16130
|
+
const cached = dispatchers.get(raw);
|
|
16131
|
+
if (cached) return cached;
|
|
16132
|
+
const url = proxyAddress(raw);
|
|
16133
|
+
const key4 = localProxyKey(url);
|
|
16134
|
+
const dispatcher = key4 ? new AdaptiveProxyDispatcher(url.href, key4) : new ProxyAgent({ uri: url.href });
|
|
16135
|
+
dispatchers.set(raw, dispatcher);
|
|
16136
|
+
return dispatcher;
|
|
16137
|
+
}
|
|
16138
|
+
var RETRY_PROXY_AFTER_MS, LOCAL_CONNECT_TIMEOUT_MS, unreachableUntil, failedProxyDials, dispatchers, direct, dialFailureCodes, AdaptiveProxyDispatcher;
|
|
16139
|
+
var init_adaptive_proxy = __esm({
|
|
16140
|
+
"src/services/adaptive-proxy.ts"() {
|
|
16141
|
+
"use strict";
|
|
16142
|
+
RETRY_PROXY_AFTER_MS = 5e3;
|
|
16143
|
+
LOCAL_CONNECT_TIMEOUT_MS = 1e3;
|
|
16144
|
+
unreachableUntil = /* @__PURE__ */ new Map();
|
|
16145
|
+
failedProxyDials = /* @__PURE__ */ new WeakSet();
|
|
16146
|
+
dispatchers = /* @__PURE__ */ new Map();
|
|
16147
|
+
direct = new Agent();
|
|
16148
|
+
dialFailureCodes = /* @__PURE__ */ new Set(["ECONNREFUSED", "ETIMEDOUT", "ENETUNREACH", "EHOSTUNREACH", "EADDRNOTAVAIL"]);
|
|
16149
|
+
AdaptiveProxyDispatcher = class extends ProxyAgent {
|
|
16150
|
+
constructor(uri, key4) {
|
|
16151
|
+
super({
|
|
16152
|
+
uri,
|
|
16153
|
+
proxyTls: { timeout: LOCAL_CONNECT_TIMEOUT_MS },
|
|
16154
|
+
clientFactory(origin, opts) {
|
|
16155
|
+
const { connect } = opts;
|
|
16156
|
+
return new Client(origin, {
|
|
16157
|
+
connect(options, callback) {
|
|
16158
|
+
let tcpConnected = false;
|
|
16159
|
+
const socket = connect(options, (...result) => {
|
|
16160
|
+
const [error] = result;
|
|
16161
|
+
if (error && !tcpConnected && (isTcpDialFailure(error) || error.code === "UND_ERR_CONNECT_TIMEOUT")) {
|
|
16162
|
+
markUnavailable(key4);
|
|
16163
|
+
failedProxyDials.add(error);
|
|
16164
|
+
}
|
|
16165
|
+
callback(...result);
|
|
16166
|
+
});
|
|
16167
|
+
socket.once("connect", () => {
|
|
16168
|
+
tcpConnected = true;
|
|
16169
|
+
});
|
|
16170
|
+
return socket;
|
|
16171
|
+
}
|
|
16172
|
+
});
|
|
16173
|
+
}
|
|
16174
|
+
});
|
|
16175
|
+
this.key = key4;
|
|
16176
|
+
}
|
|
16177
|
+
dispatch(options, handler) {
|
|
16178
|
+
if (!this.closed && !this.destroyed && proxyUnavailable(this.key)) {
|
|
16179
|
+
const headers = options.headers;
|
|
16180
|
+
const keys = !headers ? [] : Array.isArray(headers) ? headers.filter((_, index) => index % 2 === 0) : Symbol.iterator in headers ? Array.from(headers, ([name]) => name) : Object.keys(headers);
|
|
16181
|
+
if (keys.some((name) => name.toLowerCase() === "proxy-authorization")) {
|
|
16182
|
+
throw new errors.InvalidArgumentError("Proxy-Authorization should be sent in ProxyAgent constructor");
|
|
16183
|
+
}
|
|
16184
|
+
return direct.dispatch(options, handler);
|
|
16185
|
+
}
|
|
16186
|
+
let connected = false;
|
|
16187
|
+
const extended = handler;
|
|
16188
|
+
const guarded = {
|
|
16189
|
+
onConnect: (abort) => {
|
|
16190
|
+
connected = true;
|
|
16191
|
+
handler.onConnect?.(abort);
|
|
16192
|
+
},
|
|
16193
|
+
onError: (error) => {
|
|
16194
|
+
if (!connected && failedProxyDials.has(error)) {
|
|
16195
|
+
direct.dispatch(options, handler);
|
|
16196
|
+
} else {
|
|
16197
|
+
handler.onError?.(error);
|
|
16198
|
+
}
|
|
16199
|
+
},
|
|
16200
|
+
onHeaders: handler.onHeaders?.bind(handler),
|
|
16201
|
+
onData: handler.onData?.bind(handler),
|
|
16202
|
+
onComplete: handler.onComplete?.bind(handler),
|
|
16203
|
+
onUpgrade: handler.onUpgrade?.bind(handler),
|
|
16204
|
+
onResponseStarted: handler.onResponseStarted?.bind(handler),
|
|
16205
|
+
onBodySent: handler.onBodySent?.bind(handler),
|
|
16206
|
+
onRequestSent: extended.onRequestSent?.bind(handler)
|
|
16207
|
+
};
|
|
16208
|
+
return super.dispatch(options, guarded);
|
|
16209
|
+
}
|
|
16210
|
+
};
|
|
16211
|
+
}
|
|
16212
|
+
});
|
|
16213
|
+
|
|
16098
16214
|
// src/services/withRetry.ts
|
|
16099
|
-
import { ProxyAgent } from "undici";
|
|
16100
16215
|
function sleep(ms, signal) {
|
|
16101
16216
|
return new Promise((resolve13, reject) => {
|
|
16102
16217
|
if (signal?.aborted) {
|
|
@@ -16164,15 +16279,6 @@ function shouldRetry(status, errorBody) {
|
|
|
16164
16279
|
if (errorBody?.includes('"type":"overloaded_error"')) return true;
|
|
16165
16280
|
return false;
|
|
16166
16281
|
}
|
|
16167
|
-
function getProxyDispatcher(proxyUrl) {
|
|
16168
|
-
if (!proxyUrl) return void 0;
|
|
16169
|
-
let agent = proxyAgentCache.get(proxyUrl);
|
|
16170
|
-
if (!agent) {
|
|
16171
|
-
agent = new ProxyAgent({ uri: proxyUrl });
|
|
16172
|
-
proxyAgentCache.set(proxyUrl, agent);
|
|
16173
|
-
}
|
|
16174
|
-
return agent;
|
|
16175
|
-
}
|
|
16176
16282
|
async function* fetchWithRetry(url, init, providerLabel, proxy, beforeRequest, retryPolicy) {
|
|
16177
16283
|
const configuredRetries = getMaxRetries();
|
|
16178
16284
|
const maxRetries = retryPolicy?.maxRetries === void 0 ? configuredRetries : Math.min(configuredRetries, Math.max(0, Math.floor(retryPolicy.maxRetries)));
|
|
@@ -16310,10 +16416,11 @@ function readWithTimeout(reader, timeoutMs, signal) {
|
|
|
16310
16416
|
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
16311
16417
|
});
|
|
16312
16418
|
}
|
|
16313
|
-
var DEFAULT_MAX_RETRIES, BASE_DELAY_MS, MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, READ_TIMEOUT_MS, FIRST_READ_TIMEOUT_MS, NO_PROGRESS_TIMEOUT_MS
|
|
16419
|
+
var DEFAULT_MAX_RETRIES, BASE_DELAY_MS, MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, READ_TIMEOUT_MS, FIRST_READ_TIMEOUT_MS, NO_PROGRESS_TIMEOUT_MS;
|
|
16314
16420
|
var init_withRetry = __esm({
|
|
16315
16421
|
"src/services/withRetry.ts"() {
|
|
16316
16422
|
"use strict";
|
|
16423
|
+
init_adaptive_proxy();
|
|
16317
16424
|
DEFAULT_MAX_RETRIES = 10;
|
|
16318
16425
|
BASE_DELAY_MS = 500;
|
|
16319
16426
|
MAX_DELAY_MS = 32e3;
|
|
@@ -16321,7 +16428,6 @@ var init_withRetry = __esm({
|
|
|
16321
16428
|
READ_TIMEOUT_MS = 6e4;
|
|
16322
16429
|
FIRST_READ_TIMEOUT_MS = parseInt(process.env.API_TIMEOUT_MS || "", 10) || 6e5;
|
|
16323
16430
|
NO_PROGRESS_TIMEOUT_MS = parseInt(process.env.STREAM_NO_PROGRESS_TIMEOUT_MS || "", 10) || 3e5;
|
|
16324
|
-
proxyAgentCache = /* @__PURE__ */ new Map();
|
|
16325
16431
|
}
|
|
16326
16432
|
});
|
|
16327
16433
|
|
package/dist/topics-worker.mjs
CHANGED
|
@@ -2199,10 +2199,10 @@ function installSQLiteWriteCapture(db, source) {
|
|
|
2199
2199
|
if (db.isTransaction) throw new Error("REPLICATION_TRANSACTION_ALREADY_OPEN");
|
|
2200
2200
|
const exec = db.exec, prepare = db.prepare;
|
|
2201
2201
|
let active, failed = false, closed = false, reading = false;
|
|
2202
|
-
let
|
|
2202
|
+
let direct2;
|
|
2203
2203
|
const check = () => {
|
|
2204
2204
|
if (closed) throw new Error("REPLICATION_TRANSACTION_CLOSED");
|
|
2205
|
-
|
|
2205
|
+
direct2?.assertOpen();
|
|
2206
2206
|
};
|
|
2207
2207
|
const wrappedExec = function(sql) {
|
|
2208
2208
|
check();
|
|
@@ -2273,10 +2273,10 @@ function installSQLiteWriteCapture(db, source) {
|
|
|
2273
2273
|
db.prepare = checkedPrepare;
|
|
2274
2274
|
const transaction = (operation) => {
|
|
2275
2275
|
check();
|
|
2276
|
-
if (db.isTransaction) return
|
|
2276
|
+
if (db.isTransaction) return direct2.scope(operation);
|
|
2277
2277
|
db.exec("BEGIN IMMEDIATE");
|
|
2278
2278
|
try {
|
|
2279
|
-
const result =
|
|
2279
|
+
const result = direct2.scope(operation);
|
|
2280
2280
|
if (result && typeof result.then === "function") throw new Error("REPLICATION_ASYNC_TRANSACTION");
|
|
2281
2281
|
db.exec("COMMIT");
|
|
2282
2282
|
return result;
|
|
@@ -2285,10 +2285,10 @@ function installSQLiteWriteCapture(db, source) {
|
|
|
2285
2285
|
throw error;
|
|
2286
2286
|
}
|
|
2287
2287
|
};
|
|
2288
|
-
|
|
2288
|
+
direct2 = installAutocommitCapture(db, transaction);
|
|
2289
2289
|
return {
|
|
2290
2290
|
assertOpen: check,
|
|
2291
|
-
scope: (operation) =>
|
|
2291
|
+
scope: (operation) => direct2.scope(operation),
|
|
2292
2292
|
transaction,
|
|
2293
2293
|
close() {
|
|
2294
2294
|
if (closed) return;
|
|
@@ -2297,7 +2297,7 @@ function installSQLiteWriteCapture(db, source) {
|
|
|
2297
2297
|
source.endCapture(active);
|
|
2298
2298
|
active = void 0;
|
|
2299
2299
|
}
|
|
2300
|
-
|
|
2300
|
+
direct2.close();
|
|
2301
2301
|
db.prepare = prepare;
|
|
2302
2302
|
db.exec = exec;
|
|
2303
2303
|
closed = true;
|
|
@@ -7104,16 +7104,15 @@ function stripInjectedContext(text2) {
|
|
|
7104
7104
|
function escapeRegExp(s) {
|
|
7105
7105
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
7106
7106
|
}
|
|
7107
|
-
var
|
|
7107
|
+
var SYSTEM_REMINDER_BLOCK, INJECT_SECTION_HEADS, KNOWN_INJECTED_TEXT, INJECTED_LINE_PREFIXES, XML_BLOCK;
|
|
7108
7108
|
var init_strip_injected = __esm({
|
|
7109
7109
|
"src/messages/strip-injected.ts"() {
|
|
7110
7110
|
"use strict";
|
|
7111
|
-
SKILL_GATE_HINT_PREFIX = "\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1";
|
|
7112
7111
|
SYSTEM_REMINDER_BLOCK = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
7113
7112
|
INJECT_SECTION_HEADS = /^(本轮对话|当前情绪状态|当前模式)/;
|
|
7114
7113
|
KNOWN_INJECTED_TEXT = [
|
|
7115
|
-
|
|
7116
|
-
// skill-gate
|
|
7114
|
+
"\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1",
|
|
7115
|
+
// 旧版 skill-gate 提示前缀,兼容未打标签的历史
|
|
7117
7116
|
"\u5F00\u53D1\u4EFB\u52A1\u8DEF\u6807\uFF0C\u6309\u573A\u666F\u5BF9\u53F7\u5165\u5EA7",
|
|
7118
7117
|
// skill-gate hint(0912 老文案,历史 JSONL 兼容)
|
|
7119
7118
|
"\u3010\u5B9A\u65F6\u5FC3\u8DF3\u3011\u8BF7 read HEARTBEAT.md"
|
|
@@ -11271,32 +11270,32 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
11271
11270
|
return { built: !hasStats, ms: Date.now() - started };
|
|
11272
11271
|
}
|
|
11273
11272
|
async close() {
|
|
11274
|
-
const
|
|
11273
|
+
const errors2 = [];
|
|
11275
11274
|
try {
|
|
11276
11275
|
this.capture?.close();
|
|
11277
11276
|
} catch (error) {
|
|
11278
|
-
|
|
11277
|
+
errors2.push(error);
|
|
11279
11278
|
}
|
|
11280
11279
|
try {
|
|
11281
11280
|
this.db.close();
|
|
11282
11281
|
} catch (error) {
|
|
11283
|
-
|
|
11282
|
+
errors2.push(error);
|
|
11284
11283
|
}
|
|
11285
11284
|
try {
|
|
11286
11285
|
await this.vectors?.close();
|
|
11287
11286
|
} catch (error) {
|
|
11288
|
-
|
|
11287
|
+
errors2.push(error);
|
|
11289
11288
|
} finally {
|
|
11290
11289
|
this.vectors = null;
|
|
11291
11290
|
}
|
|
11292
11291
|
try {
|
|
11293
11292
|
this.releaseRuntimeWriter?.();
|
|
11294
11293
|
} catch (error) {
|
|
11295
|
-
|
|
11294
|
+
errors2.push(error);
|
|
11296
11295
|
} finally {
|
|
11297
11296
|
this.releaseRuntimeWriter = void 0;
|
|
11298
11297
|
}
|
|
11299
|
-
if (
|
|
11298
|
+
if (errors2.length) throw new AggregateError(errors2, "MEM7_CLOSE_FAILED");
|
|
11300
11299
|
}
|
|
11301
11300
|
// ── memcell 账本 ──────────────────────────────────────────
|
|
11302
11301
|
insertMemcell(cell) {
|
|
@@ -14024,8 +14023,114 @@ function normalizeUsage(raw) {
|
|
|
14024
14023
|
return { prompt_tokens: prompt, completion_tokens: completion, cached_tokens: cached };
|
|
14025
14024
|
}
|
|
14026
14025
|
|
|
14026
|
+
// src/services/adaptive-proxy.ts
|
|
14027
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
14028
|
+
import { Agent, Client, ProxyAgent, errors } from "undici";
|
|
14029
|
+
var RETRY_PROXY_AFTER_MS = 5e3;
|
|
14030
|
+
var LOCAL_CONNECT_TIMEOUT_MS = 1e3;
|
|
14031
|
+
var unreachableUntil = /* @__PURE__ */ new Map();
|
|
14032
|
+
var failedProxyDials = /* @__PURE__ */ new WeakSet();
|
|
14033
|
+
var dispatchers = /* @__PURE__ */ new Map();
|
|
14034
|
+
var direct = new Agent();
|
|
14035
|
+
function proxyAddress(value) {
|
|
14036
|
+
const bareLoopback = /^(?:localhost\.?|127(?:\.\d{1,3}){3}|\[::1\]):\d+$/i;
|
|
14037
|
+
return new URL(bareLoopback.test(value) ? `http://${value}` : value);
|
|
14038
|
+
}
|
|
14039
|
+
function localProxyKey(url) {
|
|
14040
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
14041
|
+
const host = url.hostname.replace(/\.$/, "");
|
|
14042
|
+
if (host !== "localhost" && host !== "[::1]" && !/^127\./.test(host)) return;
|
|
14043
|
+
return `${host}:${url.port || (url.protocol === "https:" ? 443 : 80)}`;
|
|
14044
|
+
}
|
|
14045
|
+
function proxyUnavailable(key4) {
|
|
14046
|
+
return (unreachableUntil.get(key4) ?? -Infinity) > Date.now();
|
|
14047
|
+
}
|
|
14048
|
+
function markUnavailable(key4) {
|
|
14049
|
+
unreachableUntil.set(key4, Date.now() + RETRY_PROXY_AFTER_MS);
|
|
14050
|
+
}
|
|
14051
|
+
var dialFailureCodes = /* @__PURE__ */ new Set(["ECONNREFUSED", "ETIMEDOUT", "ENETUNREACH", "EHOSTUNREACH", "EADDRNOTAVAIL"]);
|
|
14052
|
+
function isTcpDialFailure(error) {
|
|
14053
|
+
if (error instanceof AggregateError) {
|
|
14054
|
+
return error.errors.length > 0 && error.errors.every(isTcpDialFailure);
|
|
14055
|
+
}
|
|
14056
|
+
const err = error;
|
|
14057
|
+
return err?.syscall === "connect" && dialFailureCodes.has(err.code ?? "");
|
|
14058
|
+
}
|
|
14059
|
+
var AdaptiveProxyDispatcher = class extends ProxyAgent {
|
|
14060
|
+
constructor(uri, key4) {
|
|
14061
|
+
super({
|
|
14062
|
+
uri,
|
|
14063
|
+
proxyTls: { timeout: LOCAL_CONNECT_TIMEOUT_MS },
|
|
14064
|
+
clientFactory(origin, opts) {
|
|
14065
|
+
const { connect } = opts;
|
|
14066
|
+
return new Client(origin, {
|
|
14067
|
+
connect(options, callback) {
|
|
14068
|
+
let tcpConnected = false;
|
|
14069
|
+
const socket = connect(options, (...result) => {
|
|
14070
|
+
const [error] = result;
|
|
14071
|
+
if (error && !tcpConnected && (isTcpDialFailure(error) || error.code === "UND_ERR_CONNECT_TIMEOUT")) {
|
|
14072
|
+
markUnavailable(key4);
|
|
14073
|
+
failedProxyDials.add(error);
|
|
14074
|
+
}
|
|
14075
|
+
callback(...result);
|
|
14076
|
+
});
|
|
14077
|
+
socket.once("connect", () => {
|
|
14078
|
+
tcpConnected = true;
|
|
14079
|
+
});
|
|
14080
|
+
return socket;
|
|
14081
|
+
}
|
|
14082
|
+
});
|
|
14083
|
+
}
|
|
14084
|
+
});
|
|
14085
|
+
this.key = key4;
|
|
14086
|
+
}
|
|
14087
|
+
dispatch(options, handler) {
|
|
14088
|
+
if (!this.closed && !this.destroyed && proxyUnavailable(this.key)) {
|
|
14089
|
+
const headers = options.headers;
|
|
14090
|
+
const keys = !headers ? [] : Array.isArray(headers) ? headers.filter((_, index) => index % 2 === 0) : Symbol.iterator in headers ? Array.from(headers, ([name]) => name) : Object.keys(headers);
|
|
14091
|
+
if (keys.some((name) => name.toLowerCase() === "proxy-authorization")) {
|
|
14092
|
+
throw new errors.InvalidArgumentError("Proxy-Authorization should be sent in ProxyAgent constructor");
|
|
14093
|
+
}
|
|
14094
|
+
return direct.dispatch(options, handler);
|
|
14095
|
+
}
|
|
14096
|
+
let connected = false;
|
|
14097
|
+
const extended = handler;
|
|
14098
|
+
const guarded = {
|
|
14099
|
+
onConnect: (abort) => {
|
|
14100
|
+
connected = true;
|
|
14101
|
+
handler.onConnect?.(abort);
|
|
14102
|
+
},
|
|
14103
|
+
onError: (error) => {
|
|
14104
|
+
if (!connected && failedProxyDials.has(error)) {
|
|
14105
|
+
direct.dispatch(options, handler);
|
|
14106
|
+
} else {
|
|
14107
|
+
handler.onError?.(error);
|
|
14108
|
+
}
|
|
14109
|
+
},
|
|
14110
|
+
onHeaders: handler.onHeaders?.bind(handler),
|
|
14111
|
+
onData: handler.onData?.bind(handler),
|
|
14112
|
+
onComplete: handler.onComplete?.bind(handler),
|
|
14113
|
+
onUpgrade: handler.onUpgrade?.bind(handler),
|
|
14114
|
+
onResponseStarted: handler.onResponseStarted?.bind(handler),
|
|
14115
|
+
onBodySent: handler.onBodySent?.bind(handler),
|
|
14116
|
+
onRequestSent: extended.onRequestSent?.bind(handler)
|
|
14117
|
+
};
|
|
14118
|
+
return super.dispatch(options, guarded);
|
|
14119
|
+
}
|
|
14120
|
+
};
|
|
14121
|
+
function getProxyDispatcher(value) {
|
|
14122
|
+
const raw = value?.trim();
|
|
14123
|
+
if (!raw) return;
|
|
14124
|
+
const cached = dispatchers.get(raw);
|
|
14125
|
+
if (cached) return cached;
|
|
14126
|
+
const url = proxyAddress(raw);
|
|
14127
|
+
const key4 = localProxyKey(url);
|
|
14128
|
+
const dispatcher = key4 ? new AdaptiveProxyDispatcher(url.href, key4) : new ProxyAgent({ uri: url.href });
|
|
14129
|
+
dispatchers.set(raw, dispatcher);
|
|
14130
|
+
return dispatcher;
|
|
14131
|
+
}
|
|
14132
|
+
|
|
14027
14133
|
// src/services/withRetry.ts
|
|
14028
|
-
import { ProxyAgent } from "undici";
|
|
14029
14134
|
var DEFAULT_MAX_RETRIES = 10;
|
|
14030
14135
|
var BASE_DELAY_MS = 500;
|
|
14031
14136
|
var MAX_DELAY_MS = 32e3;
|
|
@@ -14100,16 +14205,6 @@ function shouldRetry(status, errorBody) {
|
|
|
14100
14205
|
if (errorBody?.includes('"type":"overloaded_error"')) return true;
|
|
14101
14206
|
return false;
|
|
14102
14207
|
}
|
|
14103
|
-
var proxyAgentCache = /* @__PURE__ */ new Map();
|
|
14104
|
-
function getProxyDispatcher(proxyUrl) {
|
|
14105
|
-
if (!proxyUrl) return void 0;
|
|
14106
|
-
let agent = proxyAgentCache.get(proxyUrl);
|
|
14107
|
-
if (!agent) {
|
|
14108
|
-
agent = new ProxyAgent({ uri: proxyUrl });
|
|
14109
|
-
proxyAgentCache.set(proxyUrl, agent);
|
|
14110
|
-
}
|
|
14111
|
-
return agent;
|
|
14112
|
-
}
|
|
14113
14208
|
async function* fetchWithRetry(url, init, providerLabel, proxy, beforeRequest, retryPolicy) {
|
|
14114
14209
|
const configuredRetries = getMaxRetries();
|
|
14115
14210
|
const maxRetries = retryPolicy?.maxRetries === void 0 ? configuredRetries : Math.min(configuredRetries, Math.max(0, Math.floor(retryPolicy.maxRetries)));
|