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/travel-pairing.mjs
CHANGED
|
@@ -6282,16 +6282,15 @@ function stripInjectedContext(text2) {
|
|
|
6282
6282
|
function escapeRegExp(s) {
|
|
6283
6283
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6284
6284
|
}
|
|
6285
|
-
var
|
|
6285
|
+
var SYSTEM_REMINDER_BLOCK, INJECT_SECTION_HEADS, KNOWN_INJECTED_TEXT, INJECTED_LINE_PREFIXES, XML_BLOCK;
|
|
6286
6286
|
var init_strip_injected = __esm({
|
|
6287
6287
|
"src/messages/strip-injected.ts"() {
|
|
6288
6288
|
"use strict";
|
|
6289
|
-
SKILL_GATE_HINT_PREFIX = "\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1";
|
|
6290
6289
|
SYSTEM_REMINDER_BLOCK = /<system-reminder>[\s\S]*?<\/system-reminder>/g;
|
|
6291
6290
|
INJECT_SECTION_HEADS = /^(本轮对话|当前情绪状态|当前模式)/;
|
|
6292
6291
|
KNOWN_INJECTED_TEXT = [
|
|
6293
|
-
|
|
6294
|
-
// skill-gate
|
|
6292
|
+
"\u8FD9\u6761\u6D88\u606F\u662F\u5F00\u53D1\u4EFB\u52A1",
|
|
6293
|
+
// 旧版 skill-gate 提示前缀,兼容未打标签的历史
|
|
6295
6294
|
"\u5F00\u53D1\u4EFB\u52A1\u8DEF\u6807\uFF0C\u6309\u573A\u666F\u5BF9\u53F7\u5165\u5EA7",
|
|
6296
6295
|
// skill-gate hint(0912 老文案,历史 JSONL 兼容)
|
|
6297
6296
|
"\u3010\u5B9A\u65F6\u5FC3\u8DF3\u3011\u8BF7 read HEARTBEAT.md"
|
|
@@ -10916,32 +10915,32 @@ CREATE TABLE IF NOT EXISTS cluster_members (
|
|
|
10916
10915
|
return { built: !hasStats, ms: Date.now() - started };
|
|
10917
10916
|
}
|
|
10918
10917
|
async close() {
|
|
10919
|
-
const
|
|
10918
|
+
const errors3 = [];
|
|
10920
10919
|
try {
|
|
10921
10920
|
this.capture?.close();
|
|
10922
10921
|
} catch (error) {
|
|
10923
|
-
|
|
10922
|
+
errors3.push(error);
|
|
10924
10923
|
}
|
|
10925
10924
|
try {
|
|
10926
10925
|
this.db.close();
|
|
10927
10926
|
} catch (error) {
|
|
10928
|
-
|
|
10927
|
+
errors3.push(error);
|
|
10929
10928
|
}
|
|
10930
10929
|
try {
|
|
10931
10930
|
await this.vectors?.close();
|
|
10932
10931
|
} catch (error) {
|
|
10933
|
-
|
|
10932
|
+
errors3.push(error);
|
|
10934
10933
|
} finally {
|
|
10935
10934
|
this.vectors = null;
|
|
10936
10935
|
}
|
|
10937
10936
|
try {
|
|
10938
10937
|
this.releaseRuntimeWriter?.();
|
|
10939
10938
|
} catch (error) {
|
|
10940
|
-
|
|
10939
|
+
errors3.push(error);
|
|
10941
10940
|
} finally {
|
|
10942
10941
|
this.releaseRuntimeWriter = void 0;
|
|
10943
10942
|
}
|
|
10944
|
-
if (
|
|
10943
|
+
if (errors3.length) throw new AggregateError(errors3, "MEM7_CLOSE_FAILED");
|
|
10945
10944
|
}
|
|
10946
10945
|
// ── memcell 账本 ──────────────────────────────────────────
|
|
10947
10946
|
insertMemcell(cell) {
|
|
@@ -14846,6 +14845,159 @@ var init_router = __esm({
|
|
|
14846
14845
|
}
|
|
14847
14846
|
});
|
|
14848
14847
|
|
|
14848
|
+
// src/services/adaptive-proxy.ts
|
|
14849
|
+
var adaptive_proxy_exports = {};
|
|
14850
|
+
__export(adaptive_proxy_exports, {
|
|
14851
|
+
createProxySocketAgent: () => createProxySocketAgent,
|
|
14852
|
+
getProxyDispatcher: () => getProxyDispatcher,
|
|
14853
|
+
isAdaptiveProxy: () => isAdaptiveProxy
|
|
14854
|
+
});
|
|
14855
|
+
import net from "node:net";
|
|
14856
|
+
import tls from "node:tls";
|
|
14857
|
+
import { HttpsProxyAgent } from "https-proxy-agent";
|
|
14858
|
+
import { Agent as Agent2, Client, ProxyAgent, errors as errors2 } from "undici";
|
|
14859
|
+
function proxyAddress(value) {
|
|
14860
|
+
const bareLoopback = /^(?:localhost\.?|127(?:\.\d{1,3}){3}|\[::1\]):\d+$/i;
|
|
14861
|
+
return new URL(bareLoopback.test(value) ? `http://${value}` : value);
|
|
14862
|
+
}
|
|
14863
|
+
function localProxyKey(url) {
|
|
14864
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return;
|
|
14865
|
+
const host = url.hostname.replace(/\.$/, "");
|
|
14866
|
+
if (host !== "localhost" && host !== "[::1]" && !/^127\./.test(host)) return;
|
|
14867
|
+
return `${host}:${url.port || (url.protocol === "https:" ? 443 : 80)}`;
|
|
14868
|
+
}
|
|
14869
|
+
function isAdaptiveProxy(proxy) {
|
|
14870
|
+
return localProxyKey(proxyAddress(proxy.trim())) !== void 0;
|
|
14871
|
+
}
|
|
14872
|
+
function proxyUnavailable(key4) {
|
|
14873
|
+
return (unreachableUntil.get(key4) ?? -Infinity) > Date.now();
|
|
14874
|
+
}
|
|
14875
|
+
function markUnavailable(key4) {
|
|
14876
|
+
unreachableUntil.set(key4, Date.now() + RETRY_PROXY_AFTER_MS);
|
|
14877
|
+
}
|
|
14878
|
+
function isTcpDialFailure(error) {
|
|
14879
|
+
if (error instanceof AggregateError) {
|
|
14880
|
+
return error.errors.length > 0 && error.errors.every(isTcpDialFailure);
|
|
14881
|
+
}
|
|
14882
|
+
const err = error;
|
|
14883
|
+
return err?.syscall === "connect" && dialFailureCodes.has(err.code ?? "");
|
|
14884
|
+
}
|
|
14885
|
+
function getProxyDispatcher(value) {
|
|
14886
|
+
const raw = value?.trim();
|
|
14887
|
+
if (!raw) return;
|
|
14888
|
+
const cached2 = dispatchers.get(raw);
|
|
14889
|
+
if (cached2) return cached2;
|
|
14890
|
+
const url = proxyAddress(raw);
|
|
14891
|
+
const key4 = localProxyKey(url);
|
|
14892
|
+
const dispatcher = key4 ? new AdaptiveProxyDispatcher(url.href, key4) : new ProxyAgent({ uri: url.href });
|
|
14893
|
+
dispatchers.set(raw, dispatcher);
|
|
14894
|
+
return dispatcher;
|
|
14895
|
+
}
|
|
14896
|
+
function createProxySocketAgent(value) {
|
|
14897
|
+
const url = proxyAddress(value.trim());
|
|
14898
|
+
const key4 = localProxyKey(url);
|
|
14899
|
+
return key4 ? new AdaptiveProxySocketAgent(url, key4) : new HttpsProxyAgent(url);
|
|
14900
|
+
}
|
|
14901
|
+
var RETRY_PROXY_AFTER_MS, LOCAL_CONNECT_TIMEOUT_MS, unreachableUntil, failedProxyDials, dispatchers, direct, dialFailureCodes, AdaptiveProxyDispatcher, AdaptiveProxySocketAgent;
|
|
14902
|
+
var init_adaptive_proxy = __esm({
|
|
14903
|
+
"src/services/adaptive-proxy.ts"() {
|
|
14904
|
+
"use strict";
|
|
14905
|
+
RETRY_PROXY_AFTER_MS = 5e3;
|
|
14906
|
+
LOCAL_CONNECT_TIMEOUT_MS = 1e3;
|
|
14907
|
+
unreachableUntil = /* @__PURE__ */ new Map();
|
|
14908
|
+
failedProxyDials = /* @__PURE__ */ new WeakSet();
|
|
14909
|
+
dispatchers = /* @__PURE__ */ new Map();
|
|
14910
|
+
direct = new Agent2();
|
|
14911
|
+
dialFailureCodes = /* @__PURE__ */ new Set(["ECONNREFUSED", "ETIMEDOUT", "ENETUNREACH", "EHOSTUNREACH", "EADDRNOTAVAIL"]);
|
|
14912
|
+
AdaptiveProxyDispatcher = class extends ProxyAgent {
|
|
14913
|
+
constructor(uri, key4) {
|
|
14914
|
+
super({
|
|
14915
|
+
uri,
|
|
14916
|
+
proxyTls: { timeout: LOCAL_CONNECT_TIMEOUT_MS },
|
|
14917
|
+
clientFactory(origin, opts) {
|
|
14918
|
+
const { connect } = opts;
|
|
14919
|
+
return new Client(origin, {
|
|
14920
|
+
connect(options, callback) {
|
|
14921
|
+
let tcpConnected = false;
|
|
14922
|
+
const socket = connect(options, (...result) => {
|
|
14923
|
+
const [error] = result;
|
|
14924
|
+
if (error && !tcpConnected && (isTcpDialFailure(error) || error.code === "UND_ERR_CONNECT_TIMEOUT")) {
|
|
14925
|
+
markUnavailable(key4);
|
|
14926
|
+
failedProxyDials.add(error);
|
|
14927
|
+
}
|
|
14928
|
+
callback(...result);
|
|
14929
|
+
});
|
|
14930
|
+
socket.once("connect", () => {
|
|
14931
|
+
tcpConnected = true;
|
|
14932
|
+
});
|
|
14933
|
+
return socket;
|
|
14934
|
+
}
|
|
14935
|
+
});
|
|
14936
|
+
}
|
|
14937
|
+
});
|
|
14938
|
+
this.key = key4;
|
|
14939
|
+
}
|
|
14940
|
+
dispatch(options, handler) {
|
|
14941
|
+
if (!this.closed && !this.destroyed && proxyUnavailable(this.key)) {
|
|
14942
|
+
const headers = options.headers;
|
|
14943
|
+
const keys = !headers ? [] : Array.isArray(headers) ? headers.filter((_, index) => index % 2 === 0) : Symbol.iterator in headers ? Array.from(headers, ([name]) => name) : Object.keys(headers);
|
|
14944
|
+
if (keys.some((name) => name.toLowerCase() === "proxy-authorization")) {
|
|
14945
|
+
throw new errors2.InvalidArgumentError("Proxy-Authorization should be sent in ProxyAgent constructor");
|
|
14946
|
+
}
|
|
14947
|
+
return direct.dispatch(options, handler);
|
|
14948
|
+
}
|
|
14949
|
+
let connected = false;
|
|
14950
|
+
const extended = handler;
|
|
14951
|
+
const guarded = {
|
|
14952
|
+
onConnect: (abort) => {
|
|
14953
|
+
connected = true;
|
|
14954
|
+
handler.onConnect?.(abort);
|
|
14955
|
+
},
|
|
14956
|
+
onError: (error) => {
|
|
14957
|
+
if (!connected && failedProxyDials.has(error)) {
|
|
14958
|
+
direct.dispatch(options, handler);
|
|
14959
|
+
} else {
|
|
14960
|
+
handler.onError?.(error);
|
|
14961
|
+
}
|
|
14962
|
+
},
|
|
14963
|
+
onHeaders: handler.onHeaders?.bind(handler),
|
|
14964
|
+
onData: handler.onData?.bind(handler),
|
|
14965
|
+
onComplete: handler.onComplete?.bind(handler),
|
|
14966
|
+
onUpgrade: handler.onUpgrade?.bind(handler),
|
|
14967
|
+
onResponseStarted: handler.onResponseStarted?.bind(handler),
|
|
14968
|
+
onBodySent: handler.onBodySent?.bind(handler),
|
|
14969
|
+
onRequestSent: extended.onRequestSent?.bind(handler)
|
|
14970
|
+
};
|
|
14971
|
+
return super.dispatch(options, guarded);
|
|
14972
|
+
}
|
|
14973
|
+
};
|
|
14974
|
+
AdaptiveProxySocketAgent = class extends HttpsProxyAgent {
|
|
14975
|
+
constructor(url, key4) {
|
|
14976
|
+
super(url);
|
|
14977
|
+
this.key = key4;
|
|
14978
|
+
}
|
|
14979
|
+
async connect(req, opts) {
|
|
14980
|
+
if (!proxyUnavailable(this.key)) {
|
|
14981
|
+
try {
|
|
14982
|
+
return await super.connect(req, opts);
|
|
14983
|
+
} catch (error) {
|
|
14984
|
+
if (!isTcpDialFailure(error)) throw error;
|
|
14985
|
+
markUnavailable(this.key);
|
|
14986
|
+
if (req.destroyed) throw error;
|
|
14987
|
+
}
|
|
14988
|
+
}
|
|
14989
|
+
if (!opts.secureEndpoint) return net.connect({ ...opts, path: void 0 });
|
|
14990
|
+
const { host, servername } = opts;
|
|
14991
|
+
return tls.connect({
|
|
14992
|
+
...opts,
|
|
14993
|
+
path: void 0,
|
|
14994
|
+
servername: servername ?? (host && !net.isIP(host) ? host : void 0)
|
|
14995
|
+
});
|
|
14996
|
+
}
|
|
14997
|
+
};
|
|
14998
|
+
}
|
|
14999
|
+
});
|
|
15000
|
+
|
|
14849
15001
|
// src/calendar/dispatches.ts
|
|
14850
15002
|
var dispatches_exports = {};
|
|
14851
15003
|
__export(dispatches_exports, {
|
|
@@ -14906,10 +15058,10 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
14906
15058
|
if (db2.isTransaction) throw new Error("REPLICATION_TRANSACTION_ALREADY_OPEN");
|
|
14907
15059
|
const exec = db2.exec, prepare = db2.prepare;
|
|
14908
15060
|
let active, failed = false, closed = false, reading = false;
|
|
14909
|
-
let
|
|
15061
|
+
let direct2;
|
|
14910
15062
|
const check = () => {
|
|
14911
15063
|
if (closed) throw new Error("REPLICATION_TRANSACTION_CLOSED");
|
|
14912
|
-
|
|
15064
|
+
direct2?.assertOpen();
|
|
14913
15065
|
};
|
|
14914
15066
|
const wrappedExec = function(sql) {
|
|
14915
15067
|
check();
|
|
@@ -14980,10 +15132,10 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
14980
15132
|
db2.prepare = checkedPrepare;
|
|
14981
15133
|
const transaction = (operation) => {
|
|
14982
15134
|
check();
|
|
14983
|
-
if (db2.isTransaction) return
|
|
15135
|
+
if (db2.isTransaction) return direct2.scope(operation);
|
|
14984
15136
|
db2.exec("BEGIN IMMEDIATE");
|
|
14985
15137
|
try {
|
|
14986
|
-
const result =
|
|
15138
|
+
const result = direct2.scope(operation);
|
|
14987
15139
|
if (result && typeof result.then === "function") throw new Error("REPLICATION_ASYNC_TRANSACTION");
|
|
14988
15140
|
db2.exec("COMMIT");
|
|
14989
15141
|
return result;
|
|
@@ -14992,10 +15144,10 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
14992
15144
|
throw error;
|
|
14993
15145
|
}
|
|
14994
15146
|
};
|
|
14995
|
-
|
|
15147
|
+
direct2 = installAutocommitCapture(db2, transaction);
|
|
14996
15148
|
return {
|
|
14997
15149
|
assertOpen: check,
|
|
14998
|
-
scope: (operation) =>
|
|
15150
|
+
scope: (operation) => direct2.scope(operation),
|
|
14999
15151
|
transaction,
|
|
15000
15152
|
close() {
|
|
15001
15153
|
if (closed) return;
|
|
@@ -15004,7 +15156,7 @@ function installSQLiteWriteCapture(db2, source) {
|
|
|
15004
15156
|
source.endCapture(active);
|
|
15005
15157
|
active = void 0;
|
|
15006
15158
|
}
|
|
15007
|
-
|
|
15159
|
+
direct2.close();
|
|
15008
15160
|
db2.prepare = prepare;
|
|
15009
15161
|
db2.exec = exec;
|
|
15010
15162
|
closed = true;
|
|
@@ -17534,7 +17686,7 @@ __export(voice_chat_tts_daemon_exports, {
|
|
|
17534
17686
|
stopTtsDaemon: () => stopTtsDaemon
|
|
17535
17687
|
});
|
|
17536
17688
|
import { spawn } from "child_process";
|
|
17537
|
-
import
|
|
17689
|
+
import net2 from "net";
|
|
17538
17690
|
import path13 from "path";
|
|
17539
17691
|
import fs10 from "fs";
|
|
17540
17692
|
function _log(msg2) {
|
|
@@ -17542,7 +17694,7 @@ function _log(msg2) {
|
|
|
17542
17694
|
}
|
|
17543
17695
|
function _healthOnce() {
|
|
17544
17696
|
return new Promise((resolve13) => {
|
|
17545
|
-
const sock =
|
|
17697
|
+
const sock = net2.connect(SOCK_PATH);
|
|
17546
17698
|
sock.setTimeout(2e3);
|
|
17547
17699
|
sock.on("connect", () => {
|
|
17548
17700
|
sock.write(JSON.stringify({ action: "health" }) + "\n");
|
|
@@ -17595,9 +17747,6 @@ async function startTtsDaemon(warmupCfg) {
|
|
|
17595
17747
|
_log(`spawning ${script}`);
|
|
17596
17748
|
const env = {
|
|
17597
17749
|
...process.env,
|
|
17598
|
-
// 显式注入代理(dashscope SDK 不自动读系统代理)
|
|
17599
|
-
HTTP_PROXY: process.env.HTTP_PROXY || "http://127.0.0.1:7892",
|
|
17600
|
-
HTTPS_PROXY: process.env.HTTPS_PROXY || "http://127.0.0.1:7892",
|
|
17601
17750
|
TTS_DAEMON_SOCK: SOCK_PATH,
|
|
17602
17751
|
...warmupCfg?.apiKey ? { ALIYUN_API_KEY: warmupCfg.apiKey } : {},
|
|
17603
17752
|
...warmupCfg?.model ? { TTS_MODEL: warmupCfg.model } : {},
|
|
@@ -17667,7 +17816,6 @@ __export(withRetry_exports, {
|
|
|
17667
17816
|
getRetryDelay: () => getRetryDelay,
|
|
17668
17817
|
readWithTimeout: () => readWithTimeout
|
|
17669
17818
|
});
|
|
17670
|
-
import { ProxyAgent } from "undici";
|
|
17671
17819
|
function sleep2(ms, signal) {
|
|
17672
17820
|
return new Promise((resolve13, reject) => {
|
|
17673
17821
|
if (signal?.aborted) {
|
|
@@ -17735,15 +17883,6 @@ function shouldRetry(status, errorBody) {
|
|
|
17735
17883
|
if (errorBody?.includes('"type":"overloaded_error"')) return true;
|
|
17736
17884
|
return false;
|
|
17737
17885
|
}
|
|
17738
|
-
function getProxyDispatcher(proxyUrl) {
|
|
17739
|
-
if (!proxyUrl) return void 0;
|
|
17740
|
-
let agent = proxyAgentCache.get(proxyUrl);
|
|
17741
|
-
if (!agent) {
|
|
17742
|
-
agent = new ProxyAgent({ uri: proxyUrl });
|
|
17743
|
-
proxyAgentCache.set(proxyUrl, agent);
|
|
17744
|
-
}
|
|
17745
|
-
return agent;
|
|
17746
|
-
}
|
|
17747
17886
|
async function* fetchWithRetry(url, init, providerLabel, proxy, beforeRequest, retryPolicy) {
|
|
17748
17887
|
const configuredRetries = getMaxRetries();
|
|
17749
17888
|
const maxRetries = retryPolicy?.maxRetries === void 0 ? configuredRetries : Math.min(configuredRetries, Math.max(0, Math.floor(retryPolicy.maxRetries)));
|
|
@@ -17881,10 +18020,11 @@ function readWithTimeout(reader, timeoutMs, signal) {
|
|
|
17881
18020
|
if (onAbort) signal?.removeEventListener("abort", onAbort);
|
|
17882
18021
|
});
|
|
17883
18022
|
}
|
|
17884
|
-
var DEFAULT_MAX_RETRIES, BASE_DELAY_MS, MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, READ_TIMEOUT_MS, FIRST_READ_TIMEOUT_MS, NO_PROGRESS_TIMEOUT_MS
|
|
18023
|
+
var DEFAULT_MAX_RETRIES, BASE_DELAY_MS, MAX_DELAY_MS, DEFAULT_TIMEOUT_MS, READ_TIMEOUT_MS, FIRST_READ_TIMEOUT_MS, NO_PROGRESS_TIMEOUT_MS;
|
|
17885
18024
|
var init_withRetry = __esm({
|
|
17886
18025
|
"src/services/withRetry.ts"() {
|
|
17887
18026
|
"use strict";
|
|
18027
|
+
init_adaptive_proxy();
|
|
17888
18028
|
DEFAULT_MAX_RETRIES = 10;
|
|
17889
18029
|
BASE_DELAY_MS = 500;
|
|
17890
18030
|
MAX_DELAY_MS = 32e3;
|
|
@@ -17892,7 +18032,6 @@ var init_withRetry = __esm({
|
|
|
17892
18032
|
READ_TIMEOUT_MS = 6e4;
|
|
17893
18033
|
FIRST_READ_TIMEOUT_MS = parseInt(process.env.API_TIMEOUT_MS || "", 10) || 6e5;
|
|
17894
18034
|
NO_PROGRESS_TIMEOUT_MS = parseInt(process.env.STREAM_NO_PROGRESS_TIMEOUT_MS || "", 10) || 3e5;
|
|
17895
|
-
proxyAgentCache = /* @__PURE__ */ new Map();
|
|
17896
18035
|
}
|
|
17897
18036
|
});
|
|
17898
18037
|
|
|
@@ -19164,8 +19303,8 @@ init_key_service_store();
|
|
|
19164
19303
|
init_key_service_store();
|
|
19165
19304
|
import { createServer } from "node:https";
|
|
19166
19305
|
function createKeyServiceServer(options) {
|
|
19167
|
-
const { store, ...
|
|
19168
|
-
const server = createServer({ ...
|
|
19306
|
+
const { store, ...tls3 } = options;
|
|
19307
|
+
const server = createServer({ ...tls3, minVersion: "TLSv1.3", requestCert: true, rejectUnauthorized: true }, async (req, res) => {
|
|
19169
19308
|
res.setHeader("Cache-Control", "no-store");
|
|
19170
19309
|
res.setHeader("Content-Type", "application/json");
|
|
19171
19310
|
const reply = (status, error) => {
|
|
@@ -19429,7 +19568,7 @@ function validManagement(input) {
|
|
|
19429
19568
|
return true;
|
|
19430
19569
|
}
|
|
19431
19570
|
function createTravelAuthorityServer(options) {
|
|
19432
|
-
const { authority, proxyFingerprints = [], allowedPeers = {}, managementPeers = {}, recoveryPeers = {}, retirementPeers = {}, bootstrapPeers = {}, maximumInFlight = 16, requestTimeoutMs = 8e3, ...
|
|
19571
|
+
const { authority, proxyFingerprints = [], allowedPeers = {}, managementPeers = {}, recoveryPeers = {}, retirementPeers = {}, bootstrapPeers = {}, maximumInFlight = 16, requestTimeoutMs = 8e3, ...tls3 } = options;
|
|
19433
19572
|
const proxies = /* @__PURE__ */ new Set(), peers = /* @__PURE__ */ new Map(), managers = /* @__PURE__ */ new Map();
|
|
19434
19573
|
const fingerprint2 = (value) => {
|
|
19435
19574
|
const normalized = value.replaceAll(":", "").toLowerCase();
|
|
@@ -19474,7 +19613,7 @@ function createTravelAuthorityServer(options) {
|
|
|
19474
19613
|
retirees.set(fp, new Set(credentials.map((credential) => authority.authenticateRetirement(credential).credentialHash)));
|
|
19475
19614
|
}
|
|
19476
19615
|
const reports = /* @__PURE__ */ new Set(), management = /* @__PURE__ */ new Set();
|
|
19477
|
-
const server = createServer2({ ...
|
|
19616
|
+
const server = createServer2({ ...tls3, minVersion: "TLSv1.3", requestCert: true, rejectUnauthorized: true }, async (req, res) => {
|
|
19478
19617
|
res.setHeader("Content-Type", "application/json");
|
|
19479
19618
|
res.setHeader("Cache-Control", "no-store");
|
|
19480
19619
|
const reply = (status, value) => {
|
|
@@ -20329,7 +20468,7 @@ function decodeBody(value, maximum = 16 * 1024 * 1024) {
|
|
|
20329
20468
|
return body;
|
|
20330
20469
|
}
|
|
20331
20470
|
function createTravelGatewayServer(options) {
|
|
20332
|
-
const { authority, store, allowedPeers, recoveryPeers = {}, platform, assertReady, ...
|
|
20471
|
+
const { authority, store, allowedPeers, recoveryPeers = {}, platform, assertReady, ...tls3 } = options, peers = /* @__PURE__ */ new Map(), recovery = /* @__PURE__ */ new Map();
|
|
20333
20472
|
for (const [fingerprint2, credential] of Object.entries(allowedPeers)) {
|
|
20334
20473
|
const normalized = fingerprint2.replaceAll(":", "").toLowerCase();
|
|
20335
20474
|
if (!/^[a-f0-9]{64}$/.test(normalized) || peers.has(normalized)) throw new Error("TRAVEL_GATEWAY_INVALID_LISTENER");
|
|
@@ -20342,7 +20481,7 @@ function createTravelGatewayServer(options) {
|
|
|
20342
20481
|
}
|
|
20343
20482
|
if (!peers.size || typeof platform.deliver !== "function") throw new Error("TRAVEL_GATEWAY_INVALID_LISTENER");
|
|
20344
20483
|
let inFlight = 0;
|
|
20345
|
-
const server = createServer3({ ...
|
|
20484
|
+
const server = createServer3({ ...tls3, minVersion: "TLSv1.3", requestCert: true, rejectUnauthorized: true }, async (req, res) => {
|
|
20346
20485
|
res.setHeader("Cache-Control", "no-store");
|
|
20347
20486
|
res.setHeader("Content-Type", "application/json");
|
|
20348
20487
|
const reply = (status, value) => {
|
|
@@ -20723,12 +20862,55 @@ var AgentRegistryImpl = class {
|
|
|
20723
20862
|
var agentRegistry = new AgentRegistryImpl();
|
|
20724
20863
|
|
|
20725
20864
|
// src/channels/discord.ts
|
|
20726
|
-
|
|
20727
|
-
import {
|
|
20728
|
-
|
|
20865
|
+
init_adaptive_proxy();
|
|
20866
|
+
import { Client as Client2, GatewayIntentBits, MessageFlags, Partials, ApplicationCommandOptionType } from "discord.js";
|
|
20867
|
+
|
|
20868
|
+
// src/channels/discord-gateway-proxy.ts
|
|
20869
|
+
init_adaptive_proxy();
|
|
20870
|
+
import { AsyncLocalStorage as AsyncLocalStorage4 } from "node:async_hooks";
|
|
20871
|
+
import https from "node:https";
|
|
20872
|
+
import { SimpleShardingStrategy } from "@discordjs/ws";
|
|
20873
|
+
var gatewayRoute = new AsyncLocalStorage4();
|
|
20874
|
+
function gatewayDestination(url) {
|
|
20875
|
+
const { hostname, port } = new URL(url);
|
|
20876
|
+
return `${hostname.replace(/^\[|\]$/g, "")}:${port || 443}`;
|
|
20877
|
+
}
|
|
20878
|
+
var installed = false;
|
|
20879
|
+
function discordGatewayProxy(proxy) {
|
|
20880
|
+
if (!installed) {
|
|
20881
|
+
installed = true;
|
|
20882
|
+
const request4 = https.request;
|
|
20883
|
+
https.request = (...args) => {
|
|
20884
|
+
const route = gatewayRoute.getStore();
|
|
20885
|
+
const [options] = args;
|
|
20886
|
+
if (route && options && typeof options === "object" && !(options instanceof URL) && options.agent === void 0 && options.headers?.Upgrade === "websocket" && route.destinations.has(`${options.hostname ?? options.host}:${options.port ?? 443}`)) {
|
|
20887
|
+
args[0] = { ...options, agent: route.agent };
|
|
20888
|
+
}
|
|
20889
|
+
return Reflect.apply(request4, https, args);
|
|
20890
|
+
};
|
|
20891
|
+
}
|
|
20892
|
+
const agent = createProxySocketAgent(proxy);
|
|
20893
|
+
return (manager) => {
|
|
20894
|
+
const strategy = new SimpleShardingStrategy(manager);
|
|
20895
|
+
const destinations = /* @__PURE__ */ new Set();
|
|
20896
|
+
const retrieveSession = manager.options.retrieveSessionInfo.bind(manager.options);
|
|
20897
|
+
manager.options.retrieveSessionInfo = async (shardId) => {
|
|
20898
|
+
const session = await retrieveSession(shardId);
|
|
20899
|
+
if (session?.resumeURL) destinations.add(gatewayDestination(session.resumeURL));
|
|
20900
|
+
return session;
|
|
20901
|
+
};
|
|
20902
|
+
const connect = strategy.connect.bind(strategy);
|
|
20903
|
+
strategy.connect = async () => {
|
|
20904
|
+
const { url } = await manager.fetchGatewayInformation();
|
|
20905
|
+
destinations.add(gatewayDestination(url));
|
|
20906
|
+
return gatewayRoute.run({ agent, destinations }, connect);
|
|
20907
|
+
};
|
|
20908
|
+
return strategy;
|
|
20909
|
+
};
|
|
20910
|
+
}
|
|
20729
20911
|
|
|
20730
20912
|
// src/memory/external-effect.ts
|
|
20731
|
-
import { AsyncLocalStorage as
|
|
20913
|
+
import { AsyncLocalStorage as AsyncLocalStorage6 } from "node:async_hooks";
|
|
20732
20914
|
import { createHash as createHash25 } from "node:crypto";
|
|
20733
20915
|
import { join as join18 } from "node:path";
|
|
20734
20916
|
|
|
@@ -20848,8 +21030,8 @@ function assertMemoryExecution(stateDir, workspace, context) {
|
|
|
20848
21030
|
// src/mem7/host-turn.ts
|
|
20849
21031
|
init_store();
|
|
20850
21032
|
init_host_turns();
|
|
20851
|
-
import { AsyncLocalStorage as
|
|
20852
|
-
var turns = new
|
|
21033
|
+
import { AsyncLocalStorage as AsyncLocalStorage5 } from "node:async_hooks";
|
|
21034
|
+
var turns = new AsyncLocalStorage5();
|
|
20853
21035
|
function hasHostTurnContext() {
|
|
20854
21036
|
return Boolean(turns.getStore());
|
|
20855
21037
|
}
|
|
@@ -20893,8 +21075,8 @@ function beginHostTurnEffect() {
|
|
|
20893
21075
|
|
|
20894
21076
|
// src/memory/external-effect.ts
|
|
20895
21077
|
init_runtime_authority();
|
|
20896
|
-
var effects = new
|
|
20897
|
-
var externalFences = new
|
|
21078
|
+
var effects = new AsyncLocalStorage6();
|
|
21079
|
+
var externalFences = new AsyncLocalStorage6();
|
|
20898
21080
|
function withExternalEffectFence(check, run) {
|
|
20899
21081
|
return externalFences.run(check, run);
|
|
20900
21082
|
}
|
|
@@ -21183,7 +21365,7 @@ var DiscordAdapter = class _DiscordAdapter {
|
|
|
21183
21365
|
// 🔴 P0: 消息去重 — Discord RESUME 重连会重放 messageCreate
|
|
21184
21366
|
recentMessageIds = /* @__PURE__ */ new Set();
|
|
21185
21367
|
constructor(clientOrConfig, config) {
|
|
21186
|
-
if (clientOrConfig instanceof
|
|
21368
|
+
if (clientOrConfig instanceof Client2) {
|
|
21187
21369
|
this.client = clientOrConfig;
|
|
21188
21370
|
this.config = config ?? {};
|
|
21189
21371
|
this.ownsClient = false;
|
|
@@ -21201,24 +21383,10 @@ var DiscordAdapter = class _DiscordAdapter {
|
|
|
21201
21383
|
partials: [Partials.Channel, Partials.Message]
|
|
21202
21384
|
};
|
|
21203
21385
|
if (this.config.proxy) {
|
|
21204
|
-
|
|
21205
|
-
clientOptions.
|
|
21206
|
-
const httpsAgent = new HttpsProxyAgent(proxyUrl);
|
|
21207
|
-
const https = __require("https");
|
|
21208
|
-
const origRequest = https.request;
|
|
21209
|
-
if (!origRequest.__discordProxyPatched) {
|
|
21210
|
-
https.request = function(opts, cb) {
|
|
21211
|
-
const host = typeof opts === "string" ? "" : opts?.hostname || opts?.host || "";
|
|
21212
|
-
if ((host.includes("discord") || host.includes("gateway")) && typeof opts === "object" && !opts.agent) {
|
|
21213
|
-
opts.agent = httpsAgent;
|
|
21214
|
-
}
|
|
21215
|
-
return origRequest.call(this, opts, cb);
|
|
21216
|
-
};
|
|
21217
|
-
https.request.__discordProxyPatched = true;
|
|
21218
|
-
console.log(`[discord] https.request patched for Discord gateway \u2192 ${proxyUrl}`);
|
|
21219
|
-
}
|
|
21386
|
+
clientOptions.rest = { agent: getProxyDispatcher(this.config.proxy) };
|
|
21387
|
+
clientOptions.ws = { buildStrategy: discordGatewayProxy(this.config.proxy) };
|
|
21220
21388
|
}
|
|
21221
|
-
this.client = new
|
|
21389
|
+
this.client = new Client2(clientOptions);
|
|
21222
21390
|
this.ownsClient = true;
|
|
21223
21391
|
}
|
|
21224
21392
|
this.progressCards = new DiscordProgressCards({
|
|
@@ -21279,7 +21447,7 @@ var DiscordAdapter = class _DiscordAdapter {
|
|
|
21279
21447
|
}
|
|
21280
21448
|
try {
|
|
21281
21449
|
const init = { signal: AbortSignal.timeout(HISTORY_ATTACH_TIMEOUT_MS) };
|
|
21282
|
-
if (this.config.proxy) init.dispatcher =
|
|
21450
|
+
if (this.config.proxy) init.dispatcher = getProxyDispatcher(this.config.proxy);
|
|
21283
21451
|
const res = await fetch(att.url, init);
|
|
21284
21452
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
21285
21453
|
const buf = Buffer.from(await res.arrayBuffer());
|
|
@@ -24072,7 +24240,7 @@ import { promisify as promisify3 } from "node:util";
|
|
|
24072
24240
|
init_voice_chat_tts_daemon();
|
|
24073
24241
|
import * as path14 from "node:path";
|
|
24074
24242
|
import * as os6 from "node:os";
|
|
24075
|
-
import
|
|
24243
|
+
import net3 from "net";
|
|
24076
24244
|
var execFileAsync = promisify3(execFile);
|
|
24077
24245
|
var VOICE_DIR = path14.join(os6.tmpdir(), "engine-voice");
|
|
24078
24246
|
async function ttsCosyvoiceWorker(text2, cfg, onChunk) {
|
|
@@ -24084,7 +24252,7 @@ async function ttsCosyvoiceWorker(text2, cfg, onChunk) {
|
|
|
24084
24252
|
}
|
|
24085
24253
|
}
|
|
24086
24254
|
return new Promise((resolve13, reject) => {
|
|
24087
|
-
const sock =
|
|
24255
|
+
const sock = net3.connect(getSockPath());
|
|
24088
24256
|
let buf = "";
|
|
24089
24257
|
const finish = (err) => {
|
|
24090
24258
|
try {
|
|
@@ -24296,8 +24464,8 @@ var DeskBuddyAdapter = class {
|
|
|
24296
24464
|
startAsr() {
|
|
24297
24465
|
if (this.asrSock) return;
|
|
24298
24466
|
const port = this.asrBackend === "sensevoice" ? 9790 : 9791;
|
|
24299
|
-
const
|
|
24300
|
-
const sock =
|
|
24467
|
+
const net4 = __require("node:net");
|
|
24468
|
+
const sock = net4.connect(port, "127.0.0.1");
|
|
24301
24469
|
sock.setNoDelay(true);
|
|
24302
24470
|
this.asrSock = sock;
|
|
24303
24471
|
this.asrBuf = "";
|
|
@@ -24849,7 +25017,7 @@ var CcBridgeAdapter = class {
|
|
|
24849
25017
|
|
|
24850
25018
|
// src/channels/telegram.ts
|
|
24851
25019
|
import fs13 from "node:fs";
|
|
24852
|
-
import { AsyncLocalStorage as
|
|
25020
|
+
import { AsyncLocalStorage as AsyncLocalStorage7 } from "node:async_hooks";
|
|
24853
25021
|
import path17 from "node:path";
|
|
24854
25022
|
|
|
24855
25023
|
// src/channels/telegram-offset.ts
|
|
@@ -25041,7 +25209,7 @@ var PreviewEditThrottle = class {
|
|
|
25041
25209
|
/** 提交一次编辑;返回的 promise 在"该内容(或其后覆盖它的更新内容)真实落盘"后 settle,失败 reject */
|
|
25042
25210
|
submit(key4, req, run) {
|
|
25043
25211
|
const s = this.st.get(key4) ?? { lastEditAt: -Infinity, timer: null, pending: null, pendingRun: null, waiters: [] };
|
|
25044
|
-
const guardedRun =
|
|
25212
|
+
const guardedRun = AsyncLocalStorage7.bind(run);
|
|
25045
25213
|
this.st.set(key4, s);
|
|
25046
25214
|
return new Promise((resolve13, reject) => {
|
|
25047
25215
|
const waiter = { resolve: resolve13, reject };
|
|
@@ -26227,9 +26395,6 @@ var QrManager = class {
|
|
|
26227
26395
|
}
|
|
26228
26396
|
};
|
|
26229
26397
|
|
|
26230
|
-
// src/channels/whatsapp/socket.ts
|
|
26231
|
-
import { HttpsProxyAgent as HttpsProxyAgent2 } from "https-proxy-agent";
|
|
26232
|
-
|
|
26233
26398
|
// src/version.ts
|
|
26234
26399
|
import { readFileSync as readFileSync12 } from "node:fs";
|
|
26235
26400
|
import { dirname as dirname10, join as join22 } from "node:path";
|
|
@@ -26256,7 +26421,7 @@ function readEngineVersion() {
|
|
|
26256
26421
|
}
|
|
26257
26422
|
|
|
26258
26423
|
// src/channels/whatsapp/socket.ts
|
|
26259
|
-
|
|
26424
|
+
init_adaptive_proxy();
|
|
26260
26425
|
var VERSION_SOURCE_URL = "https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts";
|
|
26261
26426
|
var VERSION_FETCH_TIMEOUT_MS = 3e3;
|
|
26262
26427
|
var VERSION_FALLBACK_TIMEOUT_MS = 5e3;
|
|
@@ -26350,7 +26515,7 @@ async function makeWaSocket(opts) {
|
|
|
26350
26515
|
connectTimeoutMs: 6e4,
|
|
26351
26516
|
defaultQueryTimeoutMs: 6e4,
|
|
26352
26517
|
// ws 层代理(https-proxy-agent,baileys 原生支持)
|
|
26353
|
-
agent: opts.proxy ?
|
|
26518
|
+
agent: opts.proxy ? createProxySocketAgent(opts.proxy) : void 0,
|
|
26354
26519
|
// 媒体上传/下载走 native fetch,只认 undici dispatcher(防线 4,见文件头)
|
|
26355
26520
|
fetchAgent: opts.proxy ? getProxyDispatcher(opts.proxy) : void 0,
|
|
26356
26521
|
auth: { creds: auth.state.creds, keys },
|
|
@@ -27380,9 +27545,9 @@ function isPlanMode() {
|
|
|
27380
27545
|
init_runtime_authority();
|
|
27381
27546
|
|
|
27382
27547
|
// src/continuity/gateway-context.ts
|
|
27383
|
-
import { AsyncLocalStorage as
|
|
27384
|
-
var contexts = new
|
|
27385
|
-
var outputKinds = new
|
|
27548
|
+
import { AsyncLocalStorage as AsyncLocalStorage8 } from "node:async_hooks";
|
|
27549
|
+
var contexts = new AsyncLocalStorage8();
|
|
27550
|
+
var outputKinds = new AsyncLocalStorage8();
|
|
27386
27551
|
var travelOutputKind = () => outputKinds.getStore() ?? "REPLY";
|
|
27387
27552
|
function withTravelOutputKind(kind, run) {
|
|
27388
27553
|
return outputKinds.run(kind, run);
|
|
@@ -27517,7 +27682,9 @@ function emitHookResponse(data) {
|
|
|
27517
27682
|
|
|
27518
27683
|
// src/skills/skill-gate.ts
|
|
27519
27684
|
init_strip_injected();
|
|
27685
|
+
init_writer();
|
|
27520
27686
|
var USER_CHANNELS = /* @__PURE__ */ new Set(["discord", "feishu", "wechat", "telegram", "cli", "console", "voice-chat", "deskBuddy", "ccBridge"]);
|
|
27687
|
+
var SKILL_CHANNELS = /* @__PURE__ */ new Set([...USER_CHANNELS, "chan7", "webhook"]);
|
|
27521
27688
|
var loadedBySession = /* @__PURE__ */ new Map();
|
|
27522
27689
|
var MAX_TRACKED_SESSIONS = 100;
|
|
27523
27690
|
function beginSkillGate(sessionId) {
|
|
@@ -31017,12 +31184,12 @@ var QueryEngine = class _QueryEngine {
|
|
|
31017
31184
|
try {
|
|
31018
31185
|
const url = "https://localhost:8116/voice-reply";
|
|
31019
31186
|
if (url.startsWith("https://")) {
|
|
31020
|
-
const
|
|
31187
|
+
const https2 = await import("node:https");
|
|
31021
31188
|
const postData = JSON.stringify({ text: line, isPlaceholder: true });
|
|
31022
31189
|
assertExternalEffectCurrent();
|
|
31023
31190
|
beginHostTurnEffect();
|
|
31024
31191
|
await new Promise((resolve13, reject) => {
|
|
31025
|
-
const req =
|
|
31192
|
+
const req = https2.request(url, {
|
|
31026
31193
|
method: "POST",
|
|
31027
31194
|
headers: { "Content-Type": "application/json", "Content-Length": Buffer.byteLength(postData) },
|
|
31028
31195
|
rejectUnauthorized: false
|
|
@@ -33969,11 +34136,10 @@ var DingTalkAdapter = class _DingTalkAdapter {
|
|
|
33969
34136
|
throw new Error("dingtalk clientId/clientSecret \u672A\u914D\u7F6E\uFF08\u5F00\u53D1\u8005\u540E\u53F0 \u2192 \u5E94\u7528 \u2192 \u51ED\u8BC1\uFF09");
|
|
33970
34137
|
}
|
|
33971
34138
|
if (this.cfg.proxy) {
|
|
33972
|
-
const { getProxyDispatcher: getProxyDispatcher2 } = await Promise.resolve().then(() => (
|
|
34139
|
+
const { createProxySocketAgent: createProxySocketAgent2, getProxyDispatcher: getProxyDispatcher2 } = await Promise.resolve().then(() => (init_adaptive_proxy(), adaptive_proxy_exports));
|
|
33973
34140
|
const dispatcher = getProxyDispatcher2(this.cfg.proxy);
|
|
33974
34141
|
this.baseFetch = (url, init) => this.fetchImpl(url, { ...init, dispatcher });
|
|
33975
|
-
|
|
33976
|
-
this.wsAgent = new HttpsProxyAgent3(this.cfg.proxy);
|
|
34142
|
+
this.wsAgent = createProxySocketAgent2(this.cfg.proxy);
|
|
33977
34143
|
this.token = new DingTalkTokenManager(this.cfg.clientId, this.cfg.clientSecret, (u, i) => this.baseFetch(u, i), this.now);
|
|
33978
34144
|
console.log(`[dingtalk] outbound via proxy ${this.cfg.proxy}`);
|
|
33979
34145
|
}
|
|
@@ -34534,7 +34700,7 @@ var DING_EDIT_INTERVAL_MS = 300;
|
|
|
34534
34700
|
|
|
34535
34701
|
// src/channels/wecom-stream.ts
|
|
34536
34702
|
import { EventEmitter as EventEmitter2 } from "node:events";
|
|
34537
|
-
import { AsyncLocalStorage as
|
|
34703
|
+
import { AsyncLocalStorage as AsyncLocalStorage9 } from "node:async_hooks";
|
|
34538
34704
|
import { createHash as createHash35 } from "node:crypto";
|
|
34539
34705
|
var WECOM_WS_URL = "wss://openws.work.weixin.qq.com";
|
|
34540
34706
|
var HEARTBEAT_MS2 = 3e4;
|
|
@@ -34860,7 +35026,7 @@ var WecomStreamClient = class extends EventEmitter2 {
|
|
|
34860
35026
|
const item = {
|
|
34861
35027
|
frame,
|
|
34862
35028
|
// The ack event which pumps this queue has another async context. Keep the sender's guards.
|
|
34863
|
-
send:
|
|
35029
|
+
send: AsyncLocalStorage9.bind((ws) => {
|
|
34864
35030
|
assertExternalEffectCurrent();
|
|
34865
35031
|
ws.send(JSON.stringify(frame));
|
|
34866
35032
|
}),
|
|
@@ -35170,12 +35336,11 @@ var WecomAdapter = class {
|
|
|
35170
35336
|
this.loadRoutes();
|
|
35171
35337
|
let wsAgent;
|
|
35172
35338
|
if (this.cfg.proxy) {
|
|
35173
|
-
const { getProxyDispatcher: getProxyDispatcher2 } = await Promise.resolve().then(() => (
|
|
35339
|
+
const { createProxySocketAgent: createProxySocketAgent2, getProxyDispatcher: getProxyDispatcher2 } = await Promise.resolve().then(() => (init_adaptive_proxy(), adaptive_proxy_exports));
|
|
35174
35340
|
const dispatcher = getProxyDispatcher2(this.cfg.proxy);
|
|
35175
35341
|
const base = this.fetchImpl;
|
|
35176
35342
|
this.fetchImpl = (url, init) => base(url, { ...init, dispatcher });
|
|
35177
|
-
|
|
35178
|
-
wsAgent = new HttpsProxyAgent3(this.cfg.proxy);
|
|
35343
|
+
wsAgent = createProxySocketAgent2(this.cfg.proxy);
|
|
35179
35344
|
}
|
|
35180
35345
|
let wsCtor = this.cfg.wsCtor;
|
|
35181
35346
|
if (!wsCtor) {
|
|
@@ -35810,7 +35975,7 @@ async function deliverChannelGatewayEffect(adapter, effect, body, assertCurrent)
|
|
|
35810
35975
|
// src/continuity/gateway-feishu.ts
|
|
35811
35976
|
init_gateway_media();
|
|
35812
35977
|
import * as lark2 from "@larksuiteoapi/node-sdk";
|
|
35813
|
-
import { AsyncLocalStorage as
|
|
35978
|
+
import { AsyncLocalStorage as AsyncLocalStorage10 } from "node:async_hooks";
|
|
35814
35979
|
import { basename as basename6 } from "node:path";
|
|
35815
35980
|
|
|
35816
35981
|
// src/continuity/gateway-feishu-render.ts
|
|
@@ -35843,7 +36008,7 @@ var quiet = { error: () => {
|
|
|
35843
36008
|
}, debug: () => {
|
|
35844
36009
|
}, trace: () => {
|
|
35845
36010
|
} };
|
|
35846
|
-
var dispatchContext = new
|
|
36011
|
+
var dispatchContext = new AsyncLocalStorage10();
|
|
35847
36012
|
var format = "engine7-feishu-gateway-inbound-v1";
|
|
35848
36013
|
function createFeishuGatewayDispatcher(options) {
|
|
35849
36014
|
return new lark2.EventDispatcher({ verificationToken: options.verificationToken, encryptKey: options.encryptKey, logger: quiet }).register({
|
|
@@ -36029,9 +36194,9 @@ import { basename as basename7 } from "node:path";
|
|
|
36029
36194
|
function createRemoteTravelChannel(block, stateDir, channel = "feishu") {
|
|
36030
36195
|
if (!stateDir || !runtimeAuthorityFor(stateDir)) throw new Error("TRAVEL_GATEWAY_RUNTIME_REQUIRED");
|
|
36031
36196
|
validateTravelChannels(stateDir, { [channel]: block });
|
|
36032
|
-
const
|
|
36033
|
-
if (!
|
|
36034
|
-
const client = new TravelGatewayClient({ url: block.gatewayUrl, ca: readPrivateFile(
|
|
36197
|
+
const tls3 = block.gatewayTls;
|
|
36198
|
+
if (!tls3 || ["caFile", "certFile", "keyFile"].some((key4) => typeof tls3[key4] !== "string" || !tls3[key4])) throw new Error("TRAVEL_GATEWAY_REMOTE_CONFIG_REQUIRED");
|
|
36199
|
+
const client = new TravelGatewayClient({ url: block.gatewayUrl, ca: readPrivateFile(tls3.caFile, 1024 * 1024), cert: readPrivateFile(tls3.certFile, 1024 * 1024), key: readPrivateFile(tls3.keyFile, 16384) });
|
|
36035
36200
|
return new RemoteTravelChannel({ client, channel, permit: () => runtimeAuthorityFor(stateDir).assert("INPUT"), pollIntervalMs: block.gatewayPollIntervalMs });
|
|
36036
36201
|
}
|
|
36037
36202
|
var RemoteTravelChannel = class {
|
|
@@ -36628,8 +36793,8 @@ var ChannelManager = class {
|
|
|
36628
36793
|
/** 停止所有 adapter */
|
|
36629
36794
|
async stopAll() {
|
|
36630
36795
|
const results = await Promise.allSettled(this.adapters.map(async (adapter) => adapter.disconnect()));
|
|
36631
|
-
const
|
|
36632
|
-
if (
|
|
36796
|
+
const errors3 = results.flatMap((result) => result.status === "rejected" ? [result.reason] : []);
|
|
36797
|
+
if (errors3.length) throw new AggregateError(errors3, "CHANNEL_STOP_FAILED");
|
|
36633
36798
|
}
|
|
36634
36799
|
/** 通道是否有已注册 adapter(投递前置判断用;1105 inbox-poller route 白名单替代硬编码) */
|
|
36635
36800
|
hasChannel(channelName) {
|
|
@@ -36742,7 +36907,7 @@ function path35(value) {
|
|
|
36742
36907
|
if (typeof value !== "string" || !isAbsolute5(value)) throw new Error("TRAVEL_GATEWAY_ABSOLUTE_PATH_REQUIRED");
|
|
36743
36908
|
return resolve11(value);
|
|
36744
36909
|
}
|
|
36745
|
-
function
|
|
36910
|
+
function tls2(config) {
|
|
36746
36911
|
return { ca: readPrivateFile(path35(config?.caFile), 1024 * 1024), cert: readPrivateFile(path35(config?.certFile), 1024 * 1024), key: readPrivateFile(path35(config?.keyFile), 16384) };
|
|
36747
36912
|
}
|
|
36748
36913
|
async function startTravelGateway(config) {
|
|
@@ -36751,7 +36916,7 @@ async function startTravelGateway(config) {
|
|
|
36751
36916
|
for (const [name, value] of Object.entries(config.channels ?? {})) if (value?.enabled && !["feishu", "discord", "wechat"].includes(name)) throw new Error("TRAVEL_CHANNEL_NOT_CONTROLLED");
|
|
36752
36917
|
const feishuIngress = config.ingressEnabled !== false && config.feishu?.ingressEnabled !== false && config.channels?.feishu?.enabled !== false;
|
|
36753
36918
|
if (feishuIngress && !/^cli_[0-9a-fA-F]{16}$/.test(config.feishu?.appId)) throw new Error("TRAVEL_FEISHU_INVALID_CONFIG");
|
|
36754
|
-
const keyConfig = { url: config.keyService.url, identity: config.keyService.identity, minimumDeletionWatermark: config.keyService.minimumDeletionWatermark, ...
|
|
36919
|
+
const keyConfig = { url: config.keyService.url, identity: config.keyService.identity, minimumDeletionWatermark: config.keyService.minimumDeletionWatermark, ...tls2(config.keyService.tls), timeoutMs: 1e4 };
|
|
36755
36920
|
const material = await fetchTravelKey(keyConfig);
|
|
36756
36921
|
const keyDigest = createHash37("sha256").update(material.key).digest("hex");
|
|
36757
36922
|
let keyWatermark = material.deletionWatermark;
|
|
@@ -36805,7 +36970,7 @@ async function startTravelGateway(config) {
|
|
|
36805
36970
|
await store.migrateStoredInputs();
|
|
36806
36971
|
if (config.previouslyProcessedPlatformIds) store.importProcessedInputs(config.previouslyProcessedPlatformIds);
|
|
36807
36972
|
platform = createFeishuGatewayPlatform(config.feishu);
|
|
36808
|
-
server = createTravelGatewayServer({ ...
|
|
36973
|
+
server = createTravelGatewayServer({ ...tls2(config.tls), store, authority, allowedPeers: config.allowedPeers, recoveryPeers: config.recoveryPeers, assertReady: assertKey, platform: { deliver: async (effect, body, assertCurrent) => {
|
|
36809
36974
|
const packet = effect.kind === "MEDIA" ? (await Promise.resolve().then(() => (init_gateway_media(), gateway_media_exports))).decodeGatewayMedia(body).metadata : JSON.parse(body.toString());
|
|
36810
36975
|
const channel = packet.channel ?? "feishu";
|
|
36811
36976
|
if (channel === "feishu") return platform.deliver(effect, body, () => {
|
|
@@ -36826,7 +36991,7 @@ async function startTravelGateway(config) {
|
|
|
36826
36991
|
if (config.control) {
|
|
36827
36992
|
if (!Number.isSafeInteger(config.control.port) || config.control.port < 0 || config.control.port > 65535 || typeof config.control.host !== "string" || !config.control.host) throw new Error("TRAVEL_CONTROL_INVALID_LISTENER");
|
|
36828
36993
|
controlServer = createTravelAuthorityServer({
|
|
36829
|
-
...
|
|
36994
|
+
...tls2(config.control.tls ?? config.tls),
|
|
36830
36995
|
authority,
|
|
36831
36996
|
proxyFingerprints: config.control.proxyFingerprints,
|
|
36832
36997
|
allowedPeers: config.control.allowedPeers,
|
|
@@ -36963,7 +37128,7 @@ if (process.argv[1] && /[\\/](gateway-main\.ts|travel-gateway\.mjs)$/.test(proce
|
|
|
36963
37128
|
// src/continuity/pairing-control.ts
|
|
36964
37129
|
async function startPairingControl(config) {
|
|
36965
37130
|
const directory2 = resolve12(config.directory), file2 = join32(directory2, "pairing.json"), read2 = (name) => readPrivateFile(join32(directory2, name), 65536);
|
|
36966
|
-
const
|
|
37131
|
+
const tls3 = { ca: read2("ca.pem"), cert: read2("server.pem"), key: read2("server.key") };
|
|
36967
37132
|
const authority = new TravelAuthority({ directory: join32(directory2, "authority") });
|
|
36968
37133
|
let binding;
|
|
36969
37134
|
try {
|
|
@@ -36995,7 +37160,7 @@ async function startPairingControl(config) {
|
|
|
36995
37160
|
} finally {
|
|
36996
37161
|
key4.fill(0);
|
|
36997
37162
|
}
|
|
36998
|
-
const keyServer = createKeyServiceServer({ ...
|
|
37163
|
+
const keyServer = createKeyServiceServer({ ...tls3, store: keys });
|
|
36999
37164
|
await new Promise((done, reject) => {
|
|
37000
37165
|
keyServer.once("error", reject);
|
|
37001
37166
|
keyServer.listen(config.ports.key, "127.0.0.1", done);
|
|
@@ -37025,7 +37190,7 @@ async function startPairingControl(config) {
|
|
|
37025
37190
|
let ingress = existsSync15(join32(directory2, "ingress-enabled.json"));
|
|
37026
37191
|
let gateway = await startTravelGateway({ ...gatewayConfig, ingressEnabled: ingress, feishu: { ...gatewayConfig.feishu, ingressEnabled: ingress && config.channels?.feishu?.enabled === true } });
|
|
37027
37192
|
let changing = false, closed = false;
|
|
37028
|
-
const pairServer = createServer4({ ...
|
|
37193
|
+
const pairServer = createServer4({ ...tls3, minVersion: "TLSv1.3", requestCert: true, rejectUnauthorized: true }, async (req, res) => {
|
|
37029
37194
|
res.setHeader("Content-Type", "application/json");
|
|
37030
37195
|
res.setHeader("Cache-Control", "no-store");
|
|
37031
37196
|
try {
|
|
@@ -37086,7 +37251,7 @@ async function startPairingControl(config) {
|
|
|
37086
37251
|
keyServer.closeAllConnections();
|
|
37087
37252
|
await new Promise((done) => keyServer.close(() => done()));
|
|
37088
37253
|
keys.close();
|
|
37089
|
-
|
|
37254
|
+
tls3.key.fill(0);
|
|
37090
37255
|
};
|
|
37091
37256
|
return { binding, keyServer, pairServer, get gateway() {
|
|
37092
37257
|
return gateway;
|