engine7 7.1.147 → 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/README.md +2 -0
- package/dist/bg-worker.mjs +1553 -759
- package/dist/cli.mjs +31106 -28232
- package/dist/engine-startup.mjs +17589 -15641
- package/dist/main.mjs +17537 -15581
- package/dist/recall-worker.mjs +582 -197
- package/dist/sqlite-maintenance-worker.mjs +9 -0
- package/dist/topics-worker.mjs +224 -44
- package/dist/travel-gateway.mjs +1058 -520
- package/dist/travel-host.mjs +592 -334
- package/dist/travel-node.mjs +94 -18
- package/dist/travel-oss-bundle-stream.mjs +3163 -126
- package/dist/travel-pairing.mjs +1078 -540
- package/dist/travel-sync-worker.mjs +292 -125
- package/dist/web-console.mjs +397 -53
- package/package.json +3 -2
- package/templates/config.template.json +1 -1
|
@@ -289,14 +289,14 @@ var init_capture_cache = __esm({
|
|
|
289
289
|
});
|
|
290
290
|
|
|
291
291
|
// src/travel/apply-transaction.ts
|
|
292
|
-
import { closeSync as closeSync2, existsSync as existsSync4, fsyncSync as fsyncSync2, lstatSync as lstatSync4, mkdirSync as mkdirSync3, openSync as openSync2, readFileSync as
|
|
293
|
-
import { dirname as dirname2, join as
|
|
292
|
+
import { closeSync as closeSync2, existsSync as existsSync4, fsyncSync as fsyncSync2, linkSync, lstatSync as lstatSync4, mkdirSync as mkdirSync3, openSync as openSync2, readFileSync as readFileSync4, readSync as readSync2, renameSync as renameSync3, rmSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
293
|
+
import { dirname as dirname2, join as join5, resolve as resolve2 } from "node:path";
|
|
294
294
|
import { createHash as createHash2, randomUUID as randomUUID3 } from "node:crypto";
|
|
295
295
|
function assertPath(root, rel) {
|
|
296
296
|
if (!safeRel(rel)) throw Error("TRAVEL_UNSAFE_PATH");
|
|
297
297
|
let path5 = root;
|
|
298
298
|
for (const part of rel.split("/")) {
|
|
299
|
-
path5 =
|
|
299
|
+
path5 = join5(path5, part);
|
|
300
300
|
try {
|
|
301
301
|
if (lstatSync4(path5).isSymbolicLink()) throw Error("TRAVEL_UNSAFE_PATH");
|
|
302
302
|
} catch (e) {
|
|
@@ -305,7 +305,7 @@ function assertPath(root, rel) {
|
|
|
305
305
|
}
|
|
306
306
|
return path5;
|
|
307
307
|
}
|
|
308
|
-
function atomic(path5, body) {
|
|
308
|
+
function atomic(path5, body, exclusive = false) {
|
|
309
309
|
const temp = path5 + "." + randomUUID3() + ".tmp";
|
|
310
310
|
let fd;
|
|
311
311
|
try {
|
|
@@ -314,20 +314,21 @@ function atomic(path5, body) {
|
|
|
314
314
|
fsyncSync2(fd);
|
|
315
315
|
closeSync2(fd);
|
|
316
316
|
fd = void 0;
|
|
317
|
-
|
|
317
|
+
if (exclusive) linkSync(temp, path5);
|
|
318
|
+
else renameSync3(temp, path5);
|
|
318
319
|
} finally {
|
|
319
320
|
if (fd !== void 0) closeSync2(fd);
|
|
320
321
|
rmSync(temp, { force: true });
|
|
321
322
|
}
|
|
322
323
|
}
|
|
323
|
-
function save(root, journal) {
|
|
324
|
+
function save(root, journal, exclusive = false) {
|
|
324
325
|
const { digest: _, ...body } = journal;
|
|
325
|
-
atomic(journalFile(root), JSON.stringify({ ...body, digest: hash(JSON.stringify(body)) }));
|
|
326
|
+
atomic(journalFile(root), JSON.stringify({ ...body, digest: hash(JSON.stringify(body)) }), exclusive);
|
|
326
327
|
}
|
|
327
328
|
function read(root) {
|
|
328
329
|
if (!existsSync4(journalFile(root))) return;
|
|
329
|
-
const value = JSON.parse(
|
|
330
|
-
if (value.version !== 1 || value.root !==
|
|
330
|
+
const value = JSON.parse(readFileSync4(journalFile(root), "utf8")), { digest: digest2, ...body } = value;
|
|
331
|
+
if (value.version !== 1 || value.root !== resolve2(root) || !Number.isSafeInteger(value.pid) || value.pid < 1 || !/^[a-f0-9-]{36}$/.test(value.token) || typeof value.committed !== "boolean" || digest2 !== hash(JSON.stringify(body)) || !Array.isArray(value.entries) || value.entries.some((e) => !safeRel(e.rel) || e.oldSha !== void 0 && !/^[a-f0-9]{64}$/.test(e.oldSha) || e.newSha !== void 0 && !/^[a-f0-9]{64}$/.test(e.newSha))) throw Error("TRAVEL_APPLY_RECOVERY_INVALID");
|
|
331
332
|
return value;
|
|
332
333
|
}
|
|
333
334
|
function matches(path5, sha) {
|
|
@@ -360,14 +361,14 @@ function rollback(root, journal) {
|
|
|
360
361
|
renameSync3(old, dest);
|
|
361
362
|
} else if (!entry.oldSha) rmSync(dest, { force: true });
|
|
362
363
|
}
|
|
363
|
-
const state =
|
|
364
|
+
const state = join5(root, ".travel/sync-state.json");
|
|
364
365
|
if (journal.previousState !== null) atomic(state, journal.previousState);
|
|
365
366
|
else rmSync(state, { force: true });
|
|
366
367
|
rmSync(journalFile(root), { force: true });
|
|
367
368
|
rmSync(stage, { recursive: true, force: true });
|
|
368
369
|
}
|
|
369
370
|
function recoverPendingApply(root) {
|
|
370
|
-
root =
|
|
371
|
+
root = resolve2(root);
|
|
371
372
|
const journal = read(root);
|
|
372
373
|
if (!journal) return;
|
|
373
374
|
if (!journal.committed) {
|
|
@@ -385,24 +386,27 @@ function recoverPendingApply(root) {
|
|
|
385
386
|
}
|
|
386
387
|
function newApplyStage(root) {
|
|
387
388
|
const token = randomUUID3(), path5 = assertPath(root, ".travel-sync-staging/" + token);
|
|
388
|
-
mkdirSync3(
|
|
389
|
+
mkdirSync3(join5(path5, "new"), { recursive: true, mode: 448 });
|
|
389
390
|
return { token, path: path5 };
|
|
390
391
|
}
|
|
391
392
|
function promoteFiles(root, stage, entries, commit) {
|
|
392
393
|
let previousState = null;
|
|
393
394
|
try {
|
|
394
|
-
previousState =
|
|
395
|
+
previousState = readFileSync4(join5(root, ".travel/sync-state.json"), "utf8");
|
|
395
396
|
} catch {
|
|
396
397
|
}
|
|
397
|
-
const journal = { version: 1, pid: process.pid, token: stage.token, root:
|
|
398
|
+
const journal = { version: 1, pid: process.pid, token: stage.token, root: resolve2(root), committed: false, entries, previousState };
|
|
398
399
|
for (const entry of entries) {
|
|
399
400
|
const dest = assertPath(root, entry.rel);
|
|
400
401
|
if (entry.before ? fileFingerprint(dest) !== entry.before : existsSync4(dest)) throw Error("TRAVEL_DESTINATION_CHANGED");
|
|
401
402
|
}
|
|
402
|
-
mkdirSync3(
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
403
|
+
mkdirSync3(join5(root, ".travel"), { recursive: true, mode: 448 });
|
|
404
|
+
try {
|
|
405
|
+
save(root, journal, true);
|
|
406
|
+
} catch (error) {
|
|
407
|
+
if (error.code === "EEXIST") throw Error("TRAVEL_APPLY_BUSY");
|
|
408
|
+
throw error;
|
|
409
|
+
}
|
|
406
410
|
try {
|
|
407
411
|
for (const entry of entries) {
|
|
408
412
|
const dest = assertPath(root, entry.rel), old = assertPath(stage.path, "old/" + entry.rel);
|
|
@@ -430,7 +434,7 @@ var init_apply_transaction = __esm({
|
|
|
430
434
|
"src/travel/apply-transaction.ts"() {
|
|
431
435
|
"use strict";
|
|
432
436
|
init_capture_cache();
|
|
433
|
-
journalFile = (root) =>
|
|
437
|
+
journalFile = (root) => join5(root, ".travel/apply-transaction.json");
|
|
434
438
|
safeRel = (rel) => !!rel && !/[\\:\x00-\x1f]/.test(rel) && rel.split("/").every((p) => p && p !== "." && p !== "..");
|
|
435
439
|
hash = (body) => createHash2("sha256").update(body).digest("hex");
|
|
436
440
|
}
|
|
@@ -1865,6 +1869,13 @@ var init_registry = __esm({
|
|
|
1865
1869
|
label: "\u60C5\u611F\u8F6E\u9759\u9ED8\u9608\u503C(\u8D85\u65F6\u4EAE\u5361)",
|
|
1866
1870
|
effect: "hot"
|
|
1867
1871
|
},
|
|
1872
|
+
{
|
|
1873
|
+
path: "display.preview.emotionWaitText",
|
|
1874
|
+
type: "string",
|
|
1875
|
+
group: "display",
|
|
1876
|
+
label: "\u79C1\u804A\u6162\u67E5\u8BE2\u65F6\u81EA\u9009\u7684\u4E00\u53E5\u8BDD",
|
|
1877
|
+
effect: "hot"
|
|
1878
|
+
},
|
|
1868
1879
|
{
|
|
1869
1880
|
path: "display.typing.enabled",
|
|
1870
1881
|
type: "boolean",
|
|
@@ -2917,9 +2928,9 @@ function generateConfig(v) {
|
|
|
2917
2928
|
bindings: []
|
|
2918
2929
|
}
|
|
2919
2930
|
},
|
|
2920
|
-
// cc-run
|
|
2921
|
-
//
|
|
2922
|
-
ccRun: { scope: v.ccRunScope ?? "
|
|
2931
|
+
// cc-run 会话范围:per-session=每次独立会话(缺省,与 cc-run 代码缺省 project 一致——
|
|
2932
|
+
// 1113 spec 要求两处缺省统一,1127 补齐);main=接续该 agent 最近的主对话,须显式选。
|
|
2933
|
+
ccRun: { scope: v.ccRunScope ?? "per-session" },
|
|
2923
2934
|
api: { port: v.apiPort },
|
|
2924
2935
|
// 0909 npm 包默认开:inner-voice + proactive 是开箱即用的核心体验
|
|
2925
2936
|
// (不写 model → 都兜底主模型;proactive 领域/persona 可用 workspace/prompts/ 覆盖)
|
|
@@ -3222,8 +3233,8 @@ __export(secrets_env_exports, {
|
|
|
3222
3233
|
writeSecretsValue: () => writeSecretsValue
|
|
3223
3234
|
});
|
|
3224
3235
|
import { createHash as createHash4 } from "node:crypto";
|
|
3225
|
-
import { chmodSync, existsSync as existsSync9, mkdirSync as mkdirSync6, readFileSync as
|
|
3226
|
-
import { basename, dirname as dirname3, join as
|
|
3236
|
+
import { chmodSync, existsSync as existsSync9, mkdirSync as mkdirSync6, readFileSync as readFileSync7, writeFileSync as writeFileSync6 } from "node:fs";
|
|
3237
|
+
import { basename, dirname as dirname3, join as join11, normalize, resolve as resolve5 } from "node:path";
|
|
3227
3238
|
function secretsHome() {
|
|
3228
3239
|
return process.env.HOME || process.env.USERPROFILE || ".";
|
|
3229
3240
|
}
|
|
@@ -3234,17 +3245,17 @@ function stateKey(stateDir) {
|
|
|
3234
3245
|
return createHash4("sha256").update(normalizeStateDir(stateDir)).digest("hex").slice(0, 8);
|
|
3235
3246
|
}
|
|
3236
3247
|
function isDefaultStateDir(stateDir) {
|
|
3237
|
-
return normalizeStateDir(stateDir) === normalizeStateDir(
|
|
3248
|
+
return normalizeStateDir(stateDir) === normalizeStateDir(join11(secretsHome(), ".engine7"));
|
|
3238
3249
|
}
|
|
3239
3250
|
function secretsCandidates(stateDir, configName) {
|
|
3240
|
-
const shared =
|
|
3251
|
+
const shared = join11(secretsHome(), ".engine7-secrets", `${configName}.env`);
|
|
3241
3252
|
const inState = [
|
|
3242
|
-
|
|
3243
|
-
|
|
3253
|
+
join11(stateDir, "configs", `.env.${configName}`),
|
|
3254
|
+
join11(stateDir, "configs", ".env")
|
|
3244
3255
|
];
|
|
3245
3256
|
if (isDefaultStateDir(stateDir)) return [shared, ...inState];
|
|
3246
3257
|
return [
|
|
3247
|
-
|
|
3258
|
+
join11(secretsHome(), ".engine7-secrets", `${configName}-${stateKey(stateDir)}.env`),
|
|
3248
3259
|
shared,
|
|
3249
3260
|
...inState
|
|
3250
3261
|
];
|
|
@@ -3253,7 +3264,7 @@ function readSecretsEntries(stateDir, configName) {
|
|
|
3253
3264
|
for (const p of secretsCandidates(stateDir, configName)) {
|
|
3254
3265
|
if (!existsSync9(p)) continue;
|
|
3255
3266
|
const entries = [];
|
|
3256
|
-
for (const line of
|
|
3267
|
+
for (const line of readFileSync7(p, "utf-8").split("\n")) {
|
|
3257
3268
|
const t = line.trim();
|
|
3258
3269
|
if (!t || t.startsWith("#")) continue;
|
|
3259
3270
|
const eq = t.indexOf("=");
|
|
@@ -3280,7 +3291,7 @@ function loadSecretsEnv(stateDir, configName, options = {}) {
|
|
|
3280
3291
|
return selected.path;
|
|
3281
3292
|
}
|
|
3282
3293
|
function resolveConfigIdentity(configPath) {
|
|
3283
|
-
const abs =
|
|
3294
|
+
const abs = resolve5(configPath);
|
|
3284
3295
|
const cfgName = basename(abs, ".json");
|
|
3285
3296
|
const cfgDir = dirname3(abs);
|
|
3286
3297
|
const stateDir = basename(cfgDir) === "configs" ? dirname3(cfgDir) : cfgDir;
|
|
@@ -3289,7 +3300,7 @@ function resolveConfigIdentity(configPath) {
|
|
|
3289
3300
|
function engineStateDirOfConfig(configPath, env = process.env) {
|
|
3290
3301
|
let raw;
|
|
3291
3302
|
try {
|
|
3292
|
-
raw = JSON.parse(
|
|
3303
|
+
raw = JSON.parse(readFileSync7(configPath, "utf-8"));
|
|
3293
3304
|
} catch {
|
|
3294
3305
|
return null;
|
|
3295
3306
|
}
|
|
@@ -3305,13 +3316,13 @@ function loadSecretsEnvForConfig(configPath, options = {}) {
|
|
|
3305
3316
|
}
|
|
3306
3317
|
function writeSecretsValue(configPath, envKey, value) {
|
|
3307
3318
|
const { stateDir, configName } = resolveConfigIdentity(configPath);
|
|
3308
|
-
const dir =
|
|
3319
|
+
const dir = join11(secretsHome(), ".engine7-secrets");
|
|
3309
3320
|
mkdirSync6(dir, { recursive: true });
|
|
3310
3321
|
const file = secretsCandidates(stateDir, configName)[0];
|
|
3311
3322
|
const seedFrom = existsSync9(file) ? file : secretsCandidates(stateDir, configName).find((p) => existsSync9(p)) ?? null;
|
|
3312
3323
|
const lines = [];
|
|
3313
3324
|
if (seedFrom) {
|
|
3314
|
-
for (const line of
|
|
3325
|
+
for (const line of readFileSync7(seedFrom, "utf8").split(/\r?\n/)) {
|
|
3315
3326
|
if (new RegExp(`^\\s*${envKey}\\s*=`).test(line)) continue;
|
|
3316
3327
|
lines.push(line);
|
|
3317
3328
|
}
|
|
@@ -3332,8 +3343,17 @@ var init_secrets_env = __esm({
|
|
|
3332
3343
|
});
|
|
3333
3344
|
|
|
3334
3345
|
// src/travel/oss-broker.ts
|
|
3346
|
+
var oss_broker_exports = {};
|
|
3347
|
+
__export(oss_broker_exports, {
|
|
3348
|
+
brokerOssConfig: () => brokerOssConfig,
|
|
3349
|
+
clearOssRequests: () => clearOssRequests,
|
|
3350
|
+
prepareOssRequests: () => prepareOssRequests,
|
|
3351
|
+
settleOssBroker: () => settleOssBroker,
|
|
3352
|
+
signedOssRequest: () => signedOssRequest,
|
|
3353
|
+
withOssBatches: () => withOssBatches
|
|
3354
|
+
});
|
|
3335
3355
|
import { randomBytes } from "node:crypto";
|
|
3336
|
-
import { readFileSync as
|
|
3356
|
+
import { readFileSync as readFileSync8 } from "node:fs";
|
|
3337
3357
|
function clearOssRequests(config) {
|
|
3338
3358
|
cache.delete(config);
|
|
3339
3359
|
}
|
|
@@ -3359,7 +3379,9 @@ async function authorizeHttp(config, operations) {
|
|
|
3359
3379
|
const broker = config.broker;
|
|
3360
3380
|
let result;
|
|
3361
3381
|
try {
|
|
3362
|
-
const
|
|
3382
|
+
const internal = broker.internal ?? config.endpoint.includes("-internal.");
|
|
3383
|
+
const body = { transferId: broker.transferId, internal, ...broker.region !== void 0 ? { region: broker.region } : {}, ...config.bucket ? { bucket: config.bucket } : {}, objects: operations };
|
|
3384
|
+
const response = await fetch(broker.url, { method: "POST", redirect: "error", headers: { Authorization: "Bearer " + broker.apiKey, "Content-Type": "application/json" }, body: JSON.stringify(body), signal: AbortSignal.timeout(2e4) });
|
|
3363
3385
|
if (!response.ok) {
|
|
3364
3386
|
await response.body?.cancel();
|
|
3365
3387
|
throw Error(`TRAVEL_OSS_AUTHORIZATION_HTTP_${response.status}`);
|
|
@@ -3372,6 +3394,14 @@ async function authorizeHttp(config, operations) {
|
|
|
3372
3394
|
}
|
|
3373
3395
|
return result;
|
|
3374
3396
|
}
|
|
3397
|
+
async function settleOssBroker(config) {
|
|
3398
|
+
if (!config.broker) return config;
|
|
3399
|
+
const result = await authorizeHttp(config, []);
|
|
3400
|
+
if (!config.bucket) config.bucket = result.bucket;
|
|
3401
|
+
if (!config.endpoint) config.endpoint = result.endpoint;
|
|
3402
|
+
if (config.broker && result.region !== void 0) config.broker.bucketRegion = result.region;
|
|
3403
|
+
return config;
|
|
3404
|
+
}
|
|
3375
3405
|
async function authorize(config, operations, background = false) {
|
|
3376
3406
|
const broker = config.broker;
|
|
3377
3407
|
let queue = signingQueues.get(broker);
|
|
@@ -3383,8 +3413,8 @@ async function authorize(config, operations, background = false) {
|
|
|
3383
3413
|
const result = current.tail.catch(() => {
|
|
3384
3414
|
}).then(async () => {
|
|
3385
3415
|
const wait = 1e3 - (Date.now() - current.last);
|
|
3386
|
-
if (wait > 0) await new Promise((
|
|
3387
|
-
const timer = setTimeout(
|
|
3416
|
+
if (wait > 0) await new Promise((resolve6) => {
|
|
3417
|
+
const timer = setTimeout(resolve6, wait);
|
|
3388
3418
|
if (background) timer.unref();
|
|
3389
3419
|
});
|
|
3390
3420
|
try {
|
|
@@ -3429,7 +3459,7 @@ async function signedOssRequest(config, operation, refresh = false) {
|
|
|
3429
3459
|
}
|
|
3430
3460
|
throw Error("TRAVEL_OSS_AUTHORIZATION_EXPIRED");
|
|
3431
3461
|
}
|
|
3432
|
-
async function brokerOssConfig(configPath) {
|
|
3462
|
+
async function brokerOssConfig(configPath, options = {}) {
|
|
3433
3463
|
if (!configPath) return null;
|
|
3434
3464
|
const { isUnresolvedEnvRef: isUnresolvedEnvRef2, makeEnvResolver: makeEnvResolver2 } = await Promise.resolve().then(() => (init_loader(), loader_exports));
|
|
3435
3465
|
const { FREE_TIER_RELAY_URL: FREE_TIER_RELAY_URL2 } = await Promise.resolve().then(() => (init_cli_init_config(), cli_init_config_exports));
|
|
@@ -3437,7 +3467,7 @@ async function brokerOssConfig(configPath) {
|
|
|
3437
3467
|
let providers;
|
|
3438
3468
|
try {
|
|
3439
3469
|
loadSecretsEnvForConfig2(configPath);
|
|
3440
|
-
const raw = makeEnvResolver2()(JSON.parse(
|
|
3470
|
+
const raw = makeEnvResolver2()(JSON.parse(readFileSync8(configPath, "utf8")));
|
|
3441
3471
|
providers = { ...raw.models?.providers, ...raw.providers };
|
|
3442
3472
|
} catch {
|
|
3443
3473
|
return null;
|
|
@@ -3461,7 +3491,7 @@ async function brokerOssConfig(configPath) {
|
|
|
3461
3491
|
const credential = provider.apiKey;
|
|
3462
3492
|
if (tried.has(credential)) continue;
|
|
3463
3493
|
tried.add(credential);
|
|
3464
|
-
const config = { bucket: "", endpoint: "", broker: { url: relayOrigin + "/api/engine7/oss/sign", apiKey: provider.apiKey, transferId: randomBytes(32).toString("hex"), providerId: providerId2 } };
|
|
3494
|
+
const config = { bucket: "", endpoint: "", broker: { url: relayOrigin + "/api/engine7/oss/sign", apiKey: provider.apiKey, transferId: randomBytes(32).toString("hex"), providerId: providerId2, ...options.region !== void 0 ? { region: options.region } : {} } };
|
|
3465
3495
|
let result;
|
|
3466
3496
|
try {
|
|
3467
3497
|
result = await authorize(config, []);
|
|
@@ -3474,6 +3504,7 @@ async function brokerOssConfig(configPath) {
|
|
|
3474
3504
|
}
|
|
3475
3505
|
config.bucket = result.bucket;
|
|
3476
3506
|
config.endpoint = result.endpoint;
|
|
3507
|
+
if (result.region !== void 0) config.broker.bucketRegion = result.region;
|
|
3477
3508
|
return config;
|
|
3478
3509
|
}
|
|
3479
3510
|
if (credentialRejected) throw Error("TRAVEL_OSS_CREDENTIALS_UNAVAILABLE");
|
|
@@ -3510,8 +3541,8 @@ __export(oss_transport_exports, {
|
|
|
3510
3541
|
withOssBatches: () => withOssBatches
|
|
3511
3542
|
});
|
|
3512
3543
|
import { createHmac, createHash as createHash5 } from "node:crypto";
|
|
3513
|
-
import { readFileSync as
|
|
3514
|
-
import { join as
|
|
3544
|
+
import { readFileSync as readFileSync9, statSync as statSync2 } from "node:fs";
|
|
3545
|
+
import { join as join12 } from "node:path";
|
|
3515
3546
|
function ossFailureCode(error) {
|
|
3516
3547
|
const message = error instanceof Error ? error.message : "";
|
|
3517
3548
|
const code = /^TRAVEL_[A-Z_0-9]+/.exec(message)?.[0];
|
|
@@ -3536,20 +3567,20 @@ function loadOssConfig(stateDir) {
|
|
|
3536
3567
|
if (ak && sk && bucket && endpoint) return { accessKeyId: ak, accessKeySecret: sk, bucket, endpoint };
|
|
3537
3568
|
if (!stateDir) return null;
|
|
3538
3569
|
try {
|
|
3539
|
-
const ossJsonPath =
|
|
3570
|
+
const ossJsonPath = join12(stateDir, ".travel", "oss.json");
|
|
3540
3571
|
try {
|
|
3541
3572
|
if (statSync2(ossJsonPath).mode & 63) console.warn(`[travel] ${ossJsonPath} \u6743\u9650\u8FC7\u5BBD\uFF08\u5E94 600\uFF09\u2014\u2014OSS \u51ED\u636E\u53EF\u88AB\u540C\u673A\u5176\u4ED6\u7528\u6237\u8BFB\u53D6`);
|
|
3542
3573
|
} catch {
|
|
3543
3574
|
}
|
|
3544
|
-
const file = JSON.parse(
|
|
3575
|
+
const file = JSON.parse(readFileSync9(ossJsonPath, "utf8"));
|
|
3545
3576
|
if (file.accessKeyId && file.accessKeySecret && file.bucket && file.endpoint)
|
|
3546
3577
|
return { accessKeyId: file.accessKeyId, accessKeySecret: file.accessKeySecret, bucket: file.bucket, endpoint: file.endpoint };
|
|
3547
3578
|
} catch {
|
|
3548
3579
|
}
|
|
3549
3580
|
return null;
|
|
3550
3581
|
}
|
|
3551
|
-
async function resolveOssConfig(stateDir, configPath) {
|
|
3552
|
-
return loadOssConfig(stateDir) ?? await brokerOssConfig(configPath);
|
|
3582
|
+
async function resolveOssConfig(stateDir, configPath, options = {}) {
|
|
3583
|
+
return loadOssConfig(stateDir) ?? await brokerOssConfig(configPath, options);
|
|
3553
3584
|
}
|
|
3554
3585
|
function signedHeaders(config, method, resourcePath, headers) {
|
|
3555
3586
|
const date = (/* @__PURE__ */ new Date()).toUTCString();
|
|
@@ -3685,12 +3716,32 @@ var init_oss_transport = __esm({
|
|
|
3685
3716
|
}
|
|
3686
3717
|
});
|
|
3687
3718
|
|
|
3719
|
+
// src/travel/cloud-region.ts
|
|
3720
|
+
async function readCloudRegion(fetchImpl = fetch) {
|
|
3721
|
+
if (process.env.ENGINE7_TRAVEL_TEST_REGION !== void 0) return process.env.ENGINE7_TRAVEL_TEST_REGION;
|
|
3722
|
+
try {
|
|
3723
|
+
const response = await fetchImpl("http://100.100.100.200/latest/meta-data/region-id", { signal: AbortSignal.timeout(1e3) });
|
|
3724
|
+
if (!response.ok) return "";
|
|
3725
|
+
const region = (await response.text()).trim();
|
|
3726
|
+
return /^[a-z0-9-]{1,32}$/.test(region) ? region : "";
|
|
3727
|
+
} catch {
|
|
3728
|
+
return "";
|
|
3729
|
+
}
|
|
3730
|
+
}
|
|
3731
|
+
var cloudRegionPromise, cloudRegion;
|
|
3732
|
+
var init_cloud_region = __esm({
|
|
3733
|
+
"src/travel/cloud-region.ts"() {
|
|
3734
|
+
"use strict";
|
|
3735
|
+
cloudRegion = () => cloudRegionPromise ??= readCloudRegion();
|
|
3736
|
+
}
|
|
3737
|
+
});
|
|
3738
|
+
|
|
3688
3739
|
// src/travel/oss-bundle.ts
|
|
3689
3740
|
import { createHash as createHash6 } from "node:crypto";
|
|
3690
3741
|
import { gzip as gzip2, gunzip } from "node:zlib";
|
|
3691
3742
|
import { promisify as promisify2 } from "node:util";
|
|
3692
3743
|
import { statSync as statSync3 } from "node:fs";
|
|
3693
|
-
import { join as
|
|
3744
|
+
import { join as join13 } from "node:path";
|
|
3694
3745
|
function validateBundleRef(value) {
|
|
3695
3746
|
if (!value || !/^[a-f0-9]{64}$/.test(value.sha256) || !Number.isSafeInteger(value.plainBytes) || value.plainBytes < 12 || value.plainBytes > BUNDLE_RAW_MAX + BUNDLE_HEADER_MAX + 12 || !Array.isArray(value.refs) || !value.refs.length || value.refs.length > BUNDLE_REFS_MAX) throw Error("TRAVEL_INVALID_BUNDLE");
|
|
3696
3747
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -3708,7 +3759,7 @@ function bundleGroups(store, refs) {
|
|
|
3708
3759
|
let group = [], raw = 0, hint = 0;
|
|
3709
3760
|
for (const ref of refs) {
|
|
3710
3761
|
validateChunkRef(ref);
|
|
3711
|
-
const size = statSync3(
|
|
3762
|
+
const size = statSync3(join13(store.dir, ref.sha256 + ".gz")).size;
|
|
3712
3763
|
if (group.length && (raw + ref.bytes > BUNDLE_RAW_MAX || hint + size > 7.5 * 1048576 || group.length >= BUNDLE_REFS_MAX)) {
|
|
3713
3764
|
groups.push(group);
|
|
3714
3765
|
group = [];
|
|
@@ -3756,17 +3807,17 @@ var init_oss_bundle = __esm({
|
|
|
3756
3807
|
});
|
|
3757
3808
|
|
|
3758
3809
|
// src/travel/oss-resume.ts
|
|
3759
|
-
import { appendFileSync, existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as
|
|
3760
|
-
import { join as
|
|
3810
|
+
import { appendFileSync, existsSync as existsSync10, mkdirSync as mkdirSync7, readFileSync as readFileSync10, renameSync as renameSync5, statSync as statSync4, writeFileSync as writeFileSync7 } from "node:fs";
|
|
3811
|
+
import { join as join14 } from "node:path";
|
|
3761
3812
|
import { createHash as createHash7, randomUUID as randomUUID4 } from "node:crypto";
|
|
3762
3813
|
async function openOssResume(stateDir, config, first) {
|
|
3763
3814
|
if (config.broker && !config.broker.tokenId) await ossHeadChunk(config, first.sha256);
|
|
3764
3815
|
const scope = createHash7("sha256").update(JSON.stringify([config.bucket, config.endpoint, config.broker?.url ?? "", config.broker?.tokenId ?? createHash7("sha256").update(config.accessKeyId ?? "").digest("hex")])).digest("hex");
|
|
3765
|
-
mkdirSync7(
|
|
3816
|
+
mkdirSync7(join14(stateDir, ".travel"), { recursive: true, mode: 448 });
|
|
3766
3817
|
const metadata = assertPath(stateDir, ".travel/oss-resume.json"), receipts = assertPath(stateDir, ".travel/oss-upload-receipts.jsonl");
|
|
3767
3818
|
let session;
|
|
3768
3819
|
try {
|
|
3769
|
-
const saved = JSON.parse(
|
|
3820
|
+
const saved = JSON.parse(readFileSync10(metadata, "utf8"));
|
|
3770
3821
|
if (saved.version === 2 && saved.scope === scope && /^(?:[a-f0-9]{64}|legacy)$/.test(saved.transferId) && Number.isSafeInteger(saved.createdAt) && saved.createdAt > Date.now() - KEEP_MS && saved.createdAt <= Date.now()) session = saved;
|
|
3771
3822
|
} catch {
|
|
3772
3823
|
}
|
|
@@ -3782,7 +3833,7 @@ async function openOssResume(stateDir, config, first) {
|
|
|
3782
3833
|
}
|
|
3783
3834
|
const packages = /* @__PURE__ */ new Map();
|
|
3784
3835
|
if (existsSync10(receipts) && statSync4(receipts).size <= 64 * 1048576) {
|
|
3785
|
-
for (const line of
|
|
3836
|
+
for (const line of readFileSync10(receipts, "utf8").split("\n")) try {
|
|
3786
3837
|
const value = JSON.parse(line);
|
|
3787
3838
|
if (value.scope !== scope || value.transferId !== session.transferId || !Number.isSafeInteger(value.at) || value.at < Date.now() - KEEP_MS || value.at > Date.now()) continue;
|
|
3788
3839
|
for (const ref of value.bundles ?? []) {
|
|
@@ -3816,21 +3867,21 @@ var init_oss_resume = __esm({
|
|
|
3816
3867
|
});
|
|
3817
3868
|
|
|
3818
3869
|
// src/travel/oss-bundle-stream.ts
|
|
3819
|
-
import { readFileSync as
|
|
3870
|
+
import { readFileSync as readFileSync11, existsSync as existsSync11 } from "node:fs";
|
|
3820
3871
|
import { fileURLToPath } from "node:url";
|
|
3821
3872
|
function openBundleStream(options) {
|
|
3822
3873
|
let source = options.source;
|
|
3823
3874
|
if (!source) {
|
|
3824
3875
|
for (const url of [new URL("./travel-oss-bundle-stream.mjs", import.meta.url), new URL("../../dist/travel-oss-bundle-stream.mjs", import.meta.url)]) if (existsSync11(fileURLToPath(url))) {
|
|
3825
|
-
source =
|
|
3876
|
+
source = readFileSync11(url, "utf8");
|
|
3826
3877
|
break;
|
|
3827
3878
|
}
|
|
3828
3879
|
}
|
|
3829
3880
|
if (!source) throw Error("TRAVEL_OSS_HELPER_MISSING");
|
|
3830
3881
|
const child = options.spawn("node --input-type=module -e " + quote(bootstrap)), pending = /* @__PURE__ */ new Map();
|
|
3831
3882
|
let sequence = 0, text = "", settled = false, closed = false, resolveReady, rejectReady;
|
|
3832
|
-
const ready = new Promise((
|
|
3833
|
-
resolveReady =
|
|
3883
|
+
const ready = new Promise((resolve6, reject) => {
|
|
3884
|
+
resolveReady = resolve6;
|
|
3834
3885
|
rejectReady = reject;
|
|
3835
3886
|
});
|
|
3836
3887
|
const fail = () => {
|
|
@@ -3881,8 +3932,8 @@ function openBundleStream(options) {
|
|
|
3881
3932
|
await ready;
|
|
3882
3933
|
if (closed) throw Error("TRAVEL_OSS_BUNDLE_CONNECTION_CLOSED");
|
|
3883
3934
|
const id = ++sequence;
|
|
3884
|
-
return new Promise((
|
|
3885
|
-
pending.set(id, { resolve:
|
|
3935
|
+
return new Promise((resolve6, reject) => {
|
|
3936
|
+
pending.set(id, { resolve: resolve6, reject });
|
|
3886
3937
|
child.stdin.write(JSON.stringify({ id, bundles }) + "\n", (error) => {
|
|
3887
3938
|
if (error) {
|
|
3888
3939
|
pending.delete(id);
|
|
@@ -4013,18 +4064,51 @@ var init_oss_bundle_lane = __esm({
|
|
|
4013
4064
|
// src/travel/sync-worker.ts
|
|
4014
4065
|
init_chunk_store();
|
|
4015
4066
|
init_capture_cache();
|
|
4016
|
-
import { join as
|
|
4067
|
+
import { join as join15 } from "node:path";
|
|
4068
|
+
import { readFileSync as readFileSync12 } from "node:fs";
|
|
4017
4069
|
import { createHash as createHash8 } from "node:crypto";
|
|
4018
4070
|
|
|
4071
|
+
// src/travel/ssh.ts
|
|
4072
|
+
function isConnectionError(error) {
|
|
4073
|
+
if (!(error instanceof Error)) return false;
|
|
4074
|
+
if (error.message === "TRAVEL_CONNECTION_CLOSED") return true;
|
|
4075
|
+
const { code, stderr } = error;
|
|
4076
|
+
if (["ECONNRESET", "EHOSTUNREACH", "ENETUNREACH", "ETIMEDOUT"].includes(String(code))) return true;
|
|
4077
|
+
if (code !== 255 && code !== "255" && stderr !== void 0) return false;
|
|
4078
|
+
const diagnostic = stderr ?? error.message;
|
|
4079
|
+
if (/Permission denied|Host key verification failed|REMOTE HOST IDENTIFICATION HAS CHANGED|Connection refused/i.test(diagnostic)) return false;
|
|
4080
|
+
return /^(?:(?:ssh: connect to host .+ port \d+: |client_loop: send disconnect: |kex_exchange_identification: |banner exchange: .+: )(?:No route to host|Network is unreachable|Connection timed out|Connection reset by peer|Broken pipe|Operation timed out)|Connection (?:reset|closed) by |Timeout, server .* not responding)/im.test(diagnostic);
|
|
4081
|
+
}
|
|
4082
|
+
|
|
4019
4083
|
// src/travel/tree-manifest.ts
|
|
4020
4084
|
init_chunk_store();
|
|
4021
4085
|
import { lstatSync as lstatSync3, readdirSync, existsSync as existsSync3 } from "node:fs";
|
|
4022
|
-
import { join as
|
|
4086
|
+
import { join as join4 } from "node:path";
|
|
4023
4087
|
|
|
4024
4088
|
// src/memory/topics-history/import-backups.ts
|
|
4025
4089
|
import { DatabaseSync, backup as backupSqlite } from "node:sqlite";
|
|
4026
4090
|
var TOPICS_BACKUP_RETENTION_MS = 7 * 864e5;
|
|
4027
4091
|
|
|
4092
|
+
// src/travel/exclusions.ts
|
|
4093
|
+
import { readFileSync as readFileSync3 } from "node:fs";
|
|
4094
|
+
import { isAbsolute, join as join3, posix, resolve } from "node:path";
|
|
4095
|
+
|
|
4096
|
+
// src/tools/selfie-references.ts
|
|
4097
|
+
var DEFAULT_REFERENCES = [
|
|
4098
|
+
{ name: "default", p: "images/xiaomei_clean_v2.png" },
|
|
4099
|
+
{ name: "v3", p: "images/xiaomei_clean_v3.png" },
|
|
4100
|
+
{ name: "base", p: "images/xiaomei_base_v3.jpg" },
|
|
4101
|
+
{ name: "blue", p: "images/xiaomei_blue_shirt_base.jpg" },
|
|
4102
|
+
{ name: "office", p: "images/xiaomei_office_final.jpg" }
|
|
4103
|
+
];
|
|
4104
|
+
function selfieReferences(config) {
|
|
4105
|
+
const cfg = config;
|
|
4106
|
+
const refs = cfg?.my_selfie?.references || cfg?.tools?.my_selfie?.references;
|
|
4107
|
+
if (!Array.isArray(refs) || refs.length === 0) return DEFAULT_REFERENCES;
|
|
4108
|
+
const valid = refs.filter((ref) => typeof ref?.name === "string" && typeof ref?.path === "string").map((ref) => ({ name: ref.name, p: ref.path }));
|
|
4109
|
+
return valid.length ? valid : DEFAULT_REFERENCES;
|
|
4110
|
+
}
|
|
4111
|
+
|
|
4028
4112
|
// src/travel/exclusions.ts
|
|
4029
4113
|
var EXCLUDED_NAMES = /* @__PURE__ */ new Set(["node_modules", ".venv", ".venvs", "venv", ".git", "__pycache__", ".cache", "cache", "caches", "tmp", "temp", ".playwright-mcp", ".DS_Store"]);
|
|
4030
4114
|
var EXCLUDED_TOP = /* @__PURE__ */ new Set(["logs", "diagnostics", "node_modules", "CogniFold", "everos-venv", "ollama-models", ".log-baseline.txt"]);
|
|
@@ -4050,17 +4134,46 @@ function excludeReason(relPath, isDir) {
|
|
|
4050
4134
|
}
|
|
4051
4135
|
var WORKSPACE_MEMORY_DIRS = /* @__PURE__ */ new Set(["topics", "memory", "inner-voice", ".calendar", ".proactive", ".system", "docs", "skills"]);
|
|
4052
4136
|
function workspaceTopFileReason(name, size) {
|
|
4053
|
-
if (!(/\.md$/i.test(name) || name === ".gitignore")) return `workspace \u9876\u5C42\u975E md \u6587\u4EF6\u4E0D\u968F\u884C\uFF08${name}\uFF09`;
|
|
4054
|
-
if (typeof size === "number" && size > WORKSPACE_BIG_FILE_BYTES) return `workspace \u9876\u5C42
|
|
4137
|
+
if (!(/\.md$/i.test(name) || name === ".gitignore" || name === ".skill-gate.json")) return `workspace \u9876\u5C42\u975E md \u6587\u4EF6\u4E0D\u968F\u884C\uFF08${name}\uFF09`;
|
|
4138
|
+
if (typeof size === "number" && size > WORKSPACE_BIG_FILE_BYTES) return `workspace \u9876\u5C42\u6587\u4EF6\u8D85 32MB \u4E0D\u968F\u884C\uFF08${name}\uFF09`;
|
|
4055
4139
|
return void 0;
|
|
4056
4140
|
}
|
|
4057
4141
|
var WORKSPACE_MEDIA_EXT = /\.(mp4|mov|mkv|webm|avi|m4v|flv|wmv|mpg|mpeg|mp3|wav|flac|aac|ogg|opus|m4a|zip|rar|7z|dmg|iso)$/i;
|
|
4058
4142
|
var WORKSPACE_BIG_FILE_BYTES = 32 * 1024 * 1024;
|
|
4059
4143
|
var RETURN_MEDIA_KEEP_MS = 14 * 24 * 3600 * 1e3;
|
|
4144
|
+
function isTopicsCleaningWorkPath(relPath) {
|
|
4145
|
+
return /^topics-history\/[a-f0-9]{64}\/(?:page-cache|batches\/[a-f0-9]{64}\/(?:snapshot|cleaned|work))(?:\/|$)/.test(relPath);
|
|
4146
|
+
}
|
|
4147
|
+
function isWorkspacePortraitPath(rel) {
|
|
4148
|
+
return rel.startsWith("workspace/") && /\.(?:png|jpe?g|webp)$/i.test(rel);
|
|
4149
|
+
}
|
|
4150
|
+
function withSelfieReferences(stateDir, configPath, exclude) {
|
|
4151
|
+
let config = {};
|
|
4152
|
+
try {
|
|
4153
|
+
config = JSON.parse(readFileSync3(configPath, "utf8")) ?? {};
|
|
4154
|
+
} catch {
|
|
4155
|
+
}
|
|
4156
|
+
const workspace = resolve(stateDir, "workspace");
|
|
4157
|
+
if (config.agents?.defaults?.workspace && resolve(config.agents.defaults.workspace) !== workspace) return exclude;
|
|
4158
|
+
const photos = /* @__PURE__ */ new Set();
|
|
4159
|
+
const parents = /* @__PURE__ */ new Set();
|
|
4160
|
+
for (const { p } of selfieReferences(config)) {
|
|
4161
|
+
if (!p || isAbsolute(p) || p.includes("..") || /[\\:\x00-\x1f]/.test(p)) continue;
|
|
4162
|
+
const rel = posix.join("workspace", p);
|
|
4163
|
+
if (!isWorkspacePortraitPath(rel)) continue;
|
|
4164
|
+
photos.add(rel);
|
|
4165
|
+
for (let dir = posix.dirname(rel); dir !== "workspace"; dir = posix.dirname(dir)) parents.add(dir);
|
|
4166
|
+
}
|
|
4167
|
+
return (rel, isDir, size, mtimeMs) => {
|
|
4168
|
+
if (!excludeReason(rel, isDir) && (isDir ? parents.has(rel) : photos.has(rel) && (size === void 0 || size <= WORKSPACE_BIG_FILE_BYTES))) return;
|
|
4169
|
+
return exclude(rel, isDir, size, mtimeMs);
|
|
4170
|
+
};
|
|
4171
|
+
}
|
|
4060
4172
|
function syncExcludeWith(mediaPolicy) {
|
|
4061
4173
|
return (relPath, isDir, size, mtimeMs) => {
|
|
4062
4174
|
const parts = relPath.split("/");
|
|
4063
4175
|
const name = parts[parts.length - 1];
|
|
4176
|
+
if (isTopicsCleaningWorkPath(relPath)) return "\u8BDD\u9898\u6E05\u6D17\u4E2D\u95F4\u6587\u4EF6\u7559\u5728\u539F\u673A";
|
|
4064
4177
|
if (parts[0] === "runtime") return "\u5F15\u64CE\u5B89\u88C5\u526F\u672C\u4E0D\u968F\u884C\uFF08\u4E91\u7AEF\u72EC\u7ACB\u5B89\u88C5\u5F53\u524D\u5F15\u64CE\uFF09";
|
|
4065
4178
|
if (!relPath.includes("/") && (relPath === "config.json" || relPath === "secrets.env")) {
|
|
4066
4179
|
return "\u5BF9\u7AEF\u5B89\u88C5\u4EA7\u7269\u4FDD\u62A4\uFF08config \u8D70 config-remap\uFF0Csecrets \u8D70 travel-setup\uFF09";
|
|
@@ -4094,8 +4207,9 @@ function syncExcludeWith(mediaPolicy) {
|
|
|
4094
4207
|
var syncExcludeReason = syncExcludeWith("none");
|
|
4095
4208
|
var syncExcludeToCloud = syncExcludeWith("none");
|
|
4096
4209
|
var syncExcludeToLocal = syncExcludeWith({ windowMs: RETURN_MEDIA_KEEP_MS });
|
|
4097
|
-
function syncExcludeWithDays(days) {
|
|
4098
|
-
|
|
4210
|
+
function syncExcludeWithDays(days, stateDir) {
|
|
4211
|
+
const exclude = days > 0 ? syncExcludeWith({ windowMs: days * 864e5 }) : syncExcludeWith("none");
|
|
4212
|
+
return stateDir ? withSelfieReferences(stateDir, join3(stateDir, "config.json"), exclude) : exclude;
|
|
4099
4213
|
}
|
|
4100
4214
|
|
|
4101
4215
|
// src/travel/tree-manifest.ts
|
|
@@ -4139,7 +4253,7 @@ async function buildTreeManifest(root, store, opts = {}) {
|
|
|
4139
4253
|
const walk = async (dir, rel) => {
|
|
4140
4254
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
4141
4255
|
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
4142
|
-
const childPath =
|
|
4256
|
+
const childPath = join4(dir, entry.name);
|
|
4143
4257
|
if (entry.isSymbolicLink()) {
|
|
4144
4258
|
excluded.push(`${childRel} \u2014 symlink refused`);
|
|
4145
4259
|
continue;
|
|
@@ -4196,7 +4310,7 @@ async function buildTreeManifest(root, store, opts = {}) {
|
|
|
4196
4310
|
if (opts.requireStableDatabases) {
|
|
4197
4311
|
for (const [rel, before] of dbBefore) {
|
|
4198
4312
|
try {
|
|
4199
|
-
if (fileFingerprint(
|
|
4313
|
+
if (fileFingerprint(join4(root, rel)) !== before) throw Error();
|
|
4200
4314
|
} catch {
|
|
4201
4315
|
throw Error("TRAVEL_DATABASE_SOURCE_CHANGED");
|
|
4202
4316
|
}
|
|
@@ -4215,21 +4329,21 @@ import {
|
|
|
4215
4329
|
existsSync as existsSync6,
|
|
4216
4330
|
mkdirSync as mkdirSync4,
|
|
4217
4331
|
openSync as openSync5,
|
|
4218
|
-
readFileSync as
|
|
4332
|
+
readFileSync as readFileSync5,
|
|
4219
4333
|
readSync as readSync5,
|
|
4220
4334
|
renameSync as renameSync4,
|
|
4221
4335
|
rmSync as rmSync2,
|
|
4222
4336
|
writeFileSync as writeFileSync4
|
|
4223
4337
|
} from "node:fs";
|
|
4224
4338
|
import { createHash as createHash3 } from "node:crypto";
|
|
4225
|
-
import { join as
|
|
4339
|
+
import { join as join7, resolve as resolve3 } from "node:path";
|
|
4226
4340
|
init_capture_cache();
|
|
4227
4341
|
init_apply_transaction();
|
|
4228
4342
|
|
|
4229
4343
|
// src/travel/sqlite-snapshot.ts
|
|
4230
4344
|
import { DatabaseSync as DatabaseSync2 } from "node:sqlite";
|
|
4231
4345
|
import { closeSync as closeSync4, fstatSync as fstatSync3, openSync as openSync4, readSync as readSync4, readdirSync as readdirSync2, statSync } from "node:fs";
|
|
4232
|
-
import { join as
|
|
4346
|
+
import { join as join6 } from "node:path";
|
|
4233
4347
|
|
|
4234
4348
|
// src/travel/sqlite-wal.ts
|
|
4235
4349
|
import { closeSync as closeSync3, existsSync as existsSync5, fstatSync as fstatSync2, openSync as openSync3, readSync as readSync3 } from "node:fs";
|
|
@@ -4278,7 +4392,7 @@ function validateSqliteWal(path5) {
|
|
|
4278
4392
|
// src/travel/sqlite-snapshot.ts
|
|
4279
4393
|
function validateDatabaseSnapshots(root, files) {
|
|
4280
4394
|
for (const file of files) {
|
|
4281
|
-
const path5 =
|
|
4395
|
+
const path5 = join6(root, file), fd = openSync4(path5, "r"), header = Buffer.alloc(100);
|
|
4282
4396
|
try {
|
|
4283
4397
|
const size = fstatSync3(fd).size, n = readSync4(fd, header, 0, header.length, 0);
|
|
4284
4398
|
const encoded = header.readUInt16BE(16), pageSize = encoded === 1 ? 65536 : encoded;
|
|
@@ -4389,7 +4503,7 @@ var SYNC_STATE_FILE = ".travel/sync-state.json";
|
|
|
4389
4503
|
var DB_RE = /\.(db|sqlite)$/;
|
|
4390
4504
|
function readSyncState(root) {
|
|
4391
4505
|
try {
|
|
4392
|
-
const value = JSON.parse(
|
|
4506
|
+
const value = JSON.parse(readFileSync5(join7(root, SYNC_STATE_FILE), "utf8"));
|
|
4393
4507
|
if (value?.version !== 1 || !value.files || typeof value.files !== "object") throw new Error("bad");
|
|
4394
4508
|
const files = {};
|
|
4395
4509
|
for (const [rel, sha] of Object.entries(value.files)) {
|
|
@@ -4403,10 +4517,10 @@ function readSyncState(root) {
|
|
|
4403
4517
|
}
|
|
4404
4518
|
}
|
|
4405
4519
|
function writeSyncState(root, files) {
|
|
4406
|
-
mkdirSync4(
|
|
4407
|
-
const temp =
|
|
4520
|
+
mkdirSync4(join7(root, ".travel"), { recursive: true, mode: 448 });
|
|
4521
|
+
const temp = join7(root, ".travel", "sync-state.json.tmp");
|
|
4408
4522
|
writeFileSync4(temp, JSON.stringify({ version: 1, syncedAt: Date.now(), files }));
|
|
4409
|
-
renameSync4(temp,
|
|
4523
|
+
renameSync4(temp, join7(root, SYNC_STATE_FILE));
|
|
4410
4524
|
}
|
|
4411
4525
|
function fileSha(path5) {
|
|
4412
4526
|
try {
|
|
@@ -4429,10 +4543,11 @@ function fileSha(path5) {
|
|
|
4429
4543
|
}
|
|
4430
4544
|
async function applyTree(root, manifestValue, store, lastState, onProgress) {
|
|
4431
4545
|
const manifest = parseTreeManifest(manifestValue);
|
|
4432
|
-
root =
|
|
4546
|
+
root = resolve3(root);
|
|
4433
4547
|
if (ownEnginePid(root, 0) !== null) throw Error("TRAVEL_DESTINATION_RUNNING");
|
|
4434
4548
|
mkdirSync4(root, { recursive: true, mode: 448 });
|
|
4435
4549
|
recoverPendingApply(root);
|
|
4550
|
+
if (lastState === void 0) lastState = readSyncState(root);
|
|
4436
4551
|
const newRels = new Set(manifest.files.map((file) => file.rel));
|
|
4437
4552
|
const byRel = new Map(manifest.files.map((file) => [file.rel, file]));
|
|
4438
4553
|
for (const file of manifest.files) if (/\.(db|sqlite)-(wal|shm)$/.test(file.rel) && !byRel.has(file.rel.replace(/-(wal|shm)$/, ""))) throw Error("TRAVEL_DATABASE_FAMILY_INCOMPLETE");
|
|
@@ -4490,6 +4605,8 @@ async function applyTree(root, manifestValue, store, lastState, onProgress) {
|
|
|
4490
4605
|
if (lastState) {
|
|
4491
4606
|
for (const [rel, sha] of Object.entries(lastState.files)) {
|
|
4492
4607
|
if (newRels.has(rel)) continue;
|
|
4608
|
+
if (isTopicsCleaningWorkPath(rel)) continue;
|
|
4609
|
+
if (isWorkspacePortraitPath(rel) && syncExcludeReason(rel, false)) continue;
|
|
4493
4610
|
const dest = assertPath(root, rel);
|
|
4494
4611
|
if (!existsSync6(dest)) continue;
|
|
4495
4612
|
const before = fileFingerprint(dest);
|
|
@@ -4515,12 +4632,12 @@ async function applyTree(root, manifestValue, store, lastState, onProgress) {
|
|
|
4515
4632
|
const stage = newApplyStage(root);
|
|
4516
4633
|
try {
|
|
4517
4634
|
for (const file of changed.values()) {
|
|
4518
|
-
await store.restoreFile(file.content, assertPath(
|
|
4635
|
+
await store.restoreFile(file.content, assertPath(join7(stage.path, "new"), file.rel), file.mode);
|
|
4519
4636
|
applied++;
|
|
4520
4637
|
appliedBytes += file.content.bytes;
|
|
4521
4638
|
onProgress?.({ files: applied, bytes: appliedBytes });
|
|
4522
4639
|
}
|
|
4523
|
-
validateDatabaseSnapshots(
|
|
4640
|
+
validateDatabaseSnapshots(join7(stage.path, "new"), dbs);
|
|
4524
4641
|
validateDatabaseSnapshots(root, unchangedDbs);
|
|
4525
4642
|
if (ownEnginePid(root, 0) !== null) throw Error("TRAVEL_DESTINATION_RUNNING");
|
|
4526
4643
|
promoteFiles(root, stage, [...promotions.values()], () => {
|
|
@@ -4531,7 +4648,7 @@ async function applyTree(root, manifestValue, store, lastState, onProgress) {
|
|
|
4531
4648
|
rmSync2(assertPath(root, ".travel/pre-copy-only.json"), { force: true });
|
|
4532
4649
|
seedCaptureCache(root, manifest.files);
|
|
4533
4650
|
} catch (error) {
|
|
4534
|
-
if (!existsSync6(
|
|
4651
|
+
if (!existsSync6(join7(root, ".travel/apply-transaction.json"))) rmSync2(stage.path, { recursive: true, force: true });
|
|
4535
4652
|
throw error;
|
|
4536
4653
|
}
|
|
4537
4654
|
return { applied, deleted, skipped };
|
|
@@ -4541,14 +4658,14 @@ function sidecarsOf(dbRel) {
|
|
|
4541
4658
|
}
|
|
4542
4659
|
|
|
4543
4660
|
// src/travel/checked-apply.ts
|
|
4544
|
-
import { isAbsolute, join as
|
|
4661
|
+
import { isAbsolute as isAbsolute2, join as join8 } from "node:path";
|
|
4545
4662
|
init_chunk_store();
|
|
4546
4663
|
init_apply_transaction();
|
|
4547
4664
|
import { existsSync as existsSync7, mkdirSync as mkdirSync5, writeFileSync as writeFileSync5 } from "node:fs";
|
|
4548
4665
|
function markPreCopyOnly(root) {
|
|
4549
|
-
if (!
|
|
4666
|
+
if (!isAbsolute2(root)) throw Error("TRAVEL_UNSAFE_PATH");
|
|
4550
4667
|
if (ownEnginePid(root, 0) !== null) throw Error("TRAVEL_DESTINATION_RUNNING");
|
|
4551
|
-
mkdirSync5(
|
|
4668
|
+
mkdirSync5(join8(root, ".travel"), { recursive: true, mode: 448 });
|
|
4552
4669
|
writeFileSync5(assertPath(root, ".travel/pre-copy-only.json"), JSON.stringify({ version: 1, databasesVerified: false }), { mode: 384 });
|
|
4553
4670
|
return { marked: true };
|
|
4554
4671
|
}
|
|
@@ -4558,20 +4675,21 @@ function assertReturnSourceInactive(root) {
|
|
|
4558
4675
|
}
|
|
4559
4676
|
async function runCheckedCapture(root, days = 14) {
|
|
4560
4677
|
assertReturnSourceInactive(root);
|
|
4561
|
-
return buildTreeManifest(root, openChunkStore(
|
|
4678
|
+
return buildTreeManifest(root, openChunkStore(join8(root, ".travel/chunks")), { exclude: syncExcludeWithDays(days, root), requireStableDatabases: true });
|
|
4562
4679
|
}
|
|
4563
4680
|
async function runCheckedApply(root, manifest, pre = false) {
|
|
4564
|
-
if (!
|
|
4681
|
+
if (!isAbsolute2(root)) throw Error("TRAVEL_UNSAFE_PATH");
|
|
4565
4682
|
if (pre) {
|
|
4566
4683
|
markPreCopyOnly(root);
|
|
4567
4684
|
return { applied: 0, deleted: [], skipped: [] };
|
|
4568
4685
|
}
|
|
4569
|
-
return applyTree(root, manifest, openChunkStore(
|
|
4686
|
+
return applyTree(root, manifest, openChunkStore(join8(root, ".travel/chunks")));
|
|
4570
4687
|
}
|
|
4571
4688
|
|
|
4572
4689
|
// src/travel/sync-worker.ts
|
|
4573
4690
|
init_oss_broker();
|
|
4574
4691
|
init_oss_transport();
|
|
4692
|
+
init_cloud_region();
|
|
4575
4693
|
var bootstrap2 = `import{createInterface}from'node:readline';const rl=createInterface({input:process.stdin,crlfDelay:Infinity}),it=rl[Symbol.asyncIterator]();try{const first=await it.next(),x=JSON.parse(first.value);process.stdin.pause();rl.close();const m=await import('data:text/javascript;base64,'+Buffer.from(x.module).toString('base64'));const running=m.runWorker(x.root);process.stdout.write(JSON.stringify({bootstrap:true})+'\\n');process.stdin.resume();await running}catch(e){console.error(e.message);process.exitCode=1}`;
|
|
4576
4694
|
var WORKER_BOOTSTRAP_COMMAND = "node --input-type=module -e '" + bootstrap2.replace(/'/g, "'\\''") + "'";
|
|
4577
4695
|
var sha2562 = (body) => createHash8("sha256").update(body).digest("hex");
|
|
@@ -4614,15 +4732,15 @@ var ProtocolReader = class {
|
|
|
4614
4732
|
}
|
|
4615
4733
|
readLine() {
|
|
4616
4734
|
if (this.waiter) throw new Error("TRAVEL_PROTOCOL_BUSY");
|
|
4617
|
-
return new Promise((
|
|
4618
|
-
this.waiter = { kind: "line", resolve:
|
|
4735
|
+
return new Promise((resolve6) => {
|
|
4736
|
+
this.waiter = { kind: "line", resolve: resolve6 };
|
|
4619
4737
|
this.drain();
|
|
4620
4738
|
});
|
|
4621
4739
|
}
|
|
4622
4740
|
readBytes(count) {
|
|
4623
4741
|
if (this.waiter) throw new Error("TRAVEL_PROTOCOL_BUSY");
|
|
4624
|
-
return new Promise((
|
|
4625
|
-
this.waiter = { kind: "bytes", count, resolve:
|
|
4742
|
+
return new Promise((resolve6, reject) => {
|
|
4743
|
+
this.waiter = { kind: "bytes", count, resolve: resolve6, reject };
|
|
4626
4744
|
this.drain();
|
|
4627
4745
|
});
|
|
4628
4746
|
}
|
|
@@ -4636,9 +4754,9 @@ var ProtocolReader = class {
|
|
|
4636
4754
|
const rest = total.subarray(newline + 1);
|
|
4637
4755
|
this.buffer = rest.length ? [rest] : [];
|
|
4638
4756
|
this.buffered = rest.length;
|
|
4639
|
-
const
|
|
4757
|
+
const resolve6 = this.waiter.resolve;
|
|
4640
4758
|
this.waiter = null;
|
|
4641
|
-
|
|
4759
|
+
resolve6(line);
|
|
4642
4760
|
continue;
|
|
4643
4761
|
}
|
|
4644
4762
|
break;
|
|
@@ -4649,9 +4767,9 @@ var ProtocolReader = class {
|
|
|
4649
4767
|
const rest = total.subarray(this.waiter.count);
|
|
4650
4768
|
this.buffer = rest.length ? [rest] : [];
|
|
4651
4769
|
this.buffered = rest.length;
|
|
4652
|
-
const
|
|
4770
|
+
const resolve6 = this.waiter.resolve;
|
|
4653
4771
|
this.waiter = null;
|
|
4654
|
-
|
|
4772
|
+
resolve6(body);
|
|
4655
4773
|
continue;
|
|
4656
4774
|
}
|
|
4657
4775
|
break;
|
|
@@ -4666,8 +4784,13 @@ var ProtocolReader = class {
|
|
|
4666
4784
|
}
|
|
4667
4785
|
};
|
|
4668
4786
|
var WorkerConnection = class _WorkerConnection {
|
|
4669
|
-
constructor(child) {
|
|
4787
|
+
constructor(child, classifyExit = false) {
|
|
4670
4788
|
this.child = child;
|
|
4789
|
+
this.classifyExit = classifyExit;
|
|
4790
|
+
this.closed = new Promise((resolve6) => child.once("close", (code, signal) => resolve6({ code, signal })));
|
|
4791
|
+
child.stderr?.on("data", (chunk) => {
|
|
4792
|
+
this.stderr = (this.stderr + String(chunk)).slice(-4096);
|
|
4793
|
+
});
|
|
4671
4794
|
child.stdout.on("data", (chunk) => this.reader.push(chunk));
|
|
4672
4795
|
child.stdout.on("end", () => this.reader.end());
|
|
4673
4796
|
const die = () => {
|
|
@@ -4678,25 +4801,51 @@ var WorkerConnection = class _WorkerConnection {
|
|
|
4678
4801
|
child.stdout.on("error", die);
|
|
4679
4802
|
child.stdin.on("error", die);
|
|
4680
4803
|
child.on("error", die);
|
|
4681
|
-
child.on("exit",
|
|
4804
|
+
child.on("exit", () => {
|
|
4805
|
+
this.broken = true;
|
|
4806
|
+
this.onDied?.();
|
|
4807
|
+
});
|
|
4808
|
+
child.on("close", die);
|
|
4682
4809
|
}
|
|
4683
4810
|
reader = new ProtocolReader();
|
|
4684
4811
|
chain = Promise.resolve();
|
|
4685
4812
|
broken = false;
|
|
4813
|
+
stderr = "";
|
|
4814
|
+
closed;
|
|
4686
4815
|
// 1123 妹妹 review P0:字段按声明序初始化——died 的 executor 先跑,若
|
|
4687
4816
|
// onDied 声明在其后带默认值会把 resolve 覆盖成 noop,died 永远 pending,
|
|
4688
4817
|
// race 防挂整个落空。onDied 必须先声明且默认 null。
|
|
4689
4818
|
onDied = null;
|
|
4690
|
-
died = new Promise((
|
|
4691
|
-
this.onDied =
|
|
4819
|
+
died = new Promise((resolve6) => {
|
|
4820
|
+
this.onDied = resolve6;
|
|
4692
4821
|
});
|
|
4693
4822
|
static from(child) {
|
|
4694
4823
|
return new _WorkerConnection(child);
|
|
4695
4824
|
}
|
|
4696
4825
|
static async fromSource(child, source, root) {
|
|
4697
|
-
const worker = new _WorkerConnection(child);
|
|
4698
|
-
|
|
4699
|
-
|
|
4826
|
+
const worker = new _WorkerConnection(child, true);
|
|
4827
|
+
try {
|
|
4828
|
+
if ((await worker.request({ module: source, root })).bootstrap !== true) throw Error("TRAVEL_PROTOCOL_MISMATCH");
|
|
4829
|
+
return worker;
|
|
4830
|
+
} catch (error) {
|
|
4831
|
+
await worker.close();
|
|
4832
|
+
throw error;
|
|
4833
|
+
}
|
|
4834
|
+
}
|
|
4835
|
+
async disconnected() {
|
|
4836
|
+
if (!this.classifyExit) throw Error("TRAVEL_CONNECTION_CLOSED");
|
|
4837
|
+
let timer;
|
|
4838
|
+
try {
|
|
4839
|
+
const exit = await Promise.race([this.closed, new Promise((resolve6) => {
|
|
4840
|
+
timer = setTimeout(() => resolve6(null), 500);
|
|
4841
|
+
})]);
|
|
4842
|
+
if (!exit || isConnectionError(Object.assign(new Error("ssh"), { code: exit.code, stderr: this.stderr }))) {
|
|
4843
|
+
throw Error("TRAVEL_CONNECTION_CLOSED");
|
|
4844
|
+
}
|
|
4845
|
+
throw Error(`TRAVEL_WORKER_EXIT (${exit.code ?? exit.signal}): ${this.stderr.trim()}`);
|
|
4846
|
+
} finally {
|
|
4847
|
+
if (timer) clearTimeout(timer);
|
|
4848
|
+
}
|
|
4700
4849
|
}
|
|
4701
4850
|
enqueue(operation) {
|
|
4702
4851
|
const next = this.chain.then(operation, operation);
|
|
@@ -4706,24 +4855,24 @@ var WorkerConnection = class _WorkerConnection {
|
|
|
4706
4855
|
}
|
|
4707
4856
|
request(header, payload) {
|
|
4708
4857
|
return this.enqueue(async () => {
|
|
4709
|
-
if (this.broken)
|
|
4710
|
-
const written = new Promise((
|
|
4858
|
+
if (this.broken) return this.disconnected();
|
|
4859
|
+
const written = new Promise((resolve6) => this.child.stdin.write(JSON.stringify(header) + "\n", () => resolve6()));
|
|
4711
4860
|
await Promise.race([written, this.died]);
|
|
4712
|
-
if (this.broken)
|
|
4861
|
+
if (this.broken) return this.disconnected();
|
|
4713
4862
|
if (payload) {
|
|
4714
|
-
const payloadWritten = new Promise((
|
|
4863
|
+
const payloadWritten = new Promise((resolve6) => this.child.stdin.write(payload, () => resolve6()));
|
|
4715
4864
|
await Promise.race([payloadWritten, this.died]);
|
|
4716
|
-
if (this.broken)
|
|
4865
|
+
if (this.broken) return this.disconnected();
|
|
4717
4866
|
}
|
|
4718
4867
|
const line = await this.reader.readLine();
|
|
4719
|
-
if (line === null)
|
|
4868
|
+
if (line === null) return this.disconnected();
|
|
4720
4869
|
const reply = JSON.parse(line);
|
|
4721
4870
|
if (reply?.error) throw new Error(reply.detail ? `${reply.error}: ${reply.detail}` : reply.error);
|
|
4722
4871
|
return reply;
|
|
4723
4872
|
});
|
|
4724
4873
|
}
|
|
4725
|
-
hello(pre = false) {
|
|
4726
|
-
return this.request({ op: "hello", pre });
|
|
4874
|
+
hello(pre = false, owner) {
|
|
4875
|
+
return this.request({ op: "hello", pre, owner });
|
|
4727
4876
|
}
|
|
4728
4877
|
async has(refs) {
|
|
4729
4878
|
return (await this.request({ op: "has", refs })).missing;
|
|
@@ -4734,15 +4883,15 @@ var WorkerConnection = class _WorkerConnection {
|
|
|
4734
4883
|
/** 拉块:应答行后跟原始明文字节(to-local 方向)。 */
|
|
4735
4884
|
async get(sha2563, bytes) {
|
|
4736
4885
|
return this.enqueue(async () => {
|
|
4737
|
-
if (this.broken)
|
|
4738
|
-
const written = new Promise((
|
|
4886
|
+
if (this.broken) return this.disconnected();
|
|
4887
|
+
const written = new Promise((resolve6) => this.child.stdin.write(JSON.stringify({ op: "get", sha256: sha2563, bytes }) + "\n", () => resolve6()));
|
|
4739
4888
|
await Promise.race([written, this.died]);
|
|
4740
|
-
if (this.broken)
|
|
4889
|
+
if (this.broken) return this.disconnected();
|
|
4741
4890
|
const line = await this.reader.readLine();
|
|
4742
|
-
if (line === null)
|
|
4891
|
+
if (line === null) return this.disconnected();
|
|
4743
4892
|
const reply = JSON.parse(line);
|
|
4744
4893
|
if (reply?.error) throw new Error(reply.detail ? `${reply.error}: ${reply.detail}` : reply.error);
|
|
4745
|
-
return
|
|
4894
|
+
return this.reader.readBytes(reply.bytes).catch(() => this.disconnected());
|
|
4746
4895
|
});
|
|
4747
4896
|
}
|
|
4748
4897
|
async manifest(manifest) {
|
|
@@ -4762,11 +4911,11 @@ var WorkerConnection = class _WorkerConnection {
|
|
|
4762
4911
|
/** A single reader serializes descriptors and acknowledgements; payloads use OSS. */
|
|
4763
4912
|
pushViaOss(refs, config, receive, progress) {
|
|
4764
4913
|
return this.enqueue(async () => {
|
|
4765
|
-
if (this.broken)
|
|
4914
|
+
if (this.broken) return this.disconnected();
|
|
4766
4915
|
this.child.stdin.write(JSON.stringify({ op: "oss-push", refs, config }) + "\n");
|
|
4767
4916
|
for (; ; ) {
|
|
4768
4917
|
const line = await this.reader.readLine();
|
|
4769
|
-
if (line === null)
|
|
4918
|
+
if (line === null) return this.disconnected();
|
|
4770
4919
|
const value = JSON.parse(line);
|
|
4771
4920
|
if (value.error) throw Error(value.detail ? `${value.error}: ${value.detail}` : value.error);
|
|
4772
4921
|
if (value.progress) {
|
|
@@ -4800,20 +4949,20 @@ var WorkerConnection = class _WorkerConnection {
|
|
|
4800
4949
|
} catch {
|
|
4801
4950
|
}
|
|
4802
4951
|
await Promise.race([
|
|
4803
|
-
new Promise((
|
|
4952
|
+
new Promise((resolve6) => this.child.once("exit", () => resolve6())),
|
|
4804
4953
|
this.died,
|
|
4805
|
-
new Promise((
|
|
4806
|
-
setTimeout(
|
|
4954
|
+
new Promise((resolve6) => {
|
|
4955
|
+
setTimeout(resolve6, 1e4).unref?.();
|
|
4807
4956
|
})
|
|
4808
4957
|
]);
|
|
4809
4958
|
}
|
|
4810
4959
|
};
|
|
4811
4960
|
async function runWorker(stateDir) {
|
|
4812
|
-
const store = openChunkStore(
|
|
4961
|
+
const store = openChunkStore(join15(stateDir, ".travel/chunks"));
|
|
4813
4962
|
const reader = new ProtocolReader();
|
|
4814
4963
|
process.stdin.on("data", (chunk) => reader.push(chunk));
|
|
4815
4964
|
process.stdin.on("end", () => reader.end());
|
|
4816
|
-
const ended = new Promise((
|
|
4965
|
+
const ended = new Promise((resolve6) => process.stdin.on("end", resolve6));
|
|
4817
4966
|
let pendingManifest = null;
|
|
4818
4967
|
let capturedForReturn = false;
|
|
4819
4968
|
let databasePiecesSeeded = false;
|
|
@@ -4824,10 +4973,19 @@ async function runWorker(stateDir) {
|
|
|
4824
4973
|
try {
|
|
4825
4974
|
const op = JSON.parse(line);
|
|
4826
4975
|
switch (op.op) {
|
|
4827
|
-
case "hello":
|
|
4976
|
+
case "hello": {
|
|
4977
|
+
if (op.owner !== void 0) {
|
|
4978
|
+
try {
|
|
4979
|
+
const owner = JSON.parse(readFileSync12(join15(stateDir, ".travel/owner.json"), "utf8"));
|
|
4980
|
+
if (owner.instanceId !== op.owner) throw Error("TRAVEL_WRONG_REMOTE_OWNER");
|
|
4981
|
+
} catch {
|
|
4982
|
+
throw Error("TRAVEL_WRONG_REMOTE_OWNER");
|
|
4983
|
+
}
|
|
4984
|
+
}
|
|
4828
4985
|
if (op.pre === true) markPreCopyOnly(stateDir);
|
|
4829
|
-
reply = { ok: true, version: 3, stateDir };
|
|
4986
|
+
reply = { ok: true, version: 3, stateDir, region: await cloudRegion() };
|
|
4830
4987
|
break;
|
|
4988
|
+
}
|
|
4831
4989
|
case "has": {
|
|
4832
4990
|
const refs = op.refs ?? [];
|
|
4833
4991
|
if (!Array.isArray(refs) || refs.length > CHUNK_LOOKUP_BATCH) throw new Error("TRAVEL_TOO_MANY_REFS");
|
|
@@ -4865,7 +5023,7 @@ async function runWorker(stateDir) {
|
|
|
4865
5023
|
if (typeof sha !== "string" || !/^[a-f0-9]{64}$/.test(sha) || !Number.isSafeInteger(bytes) || bytes < 1 || bytes > CHUNK_BYTES) throw new Error("TRAVEL_INVALID_CHUNK");
|
|
4866
5024
|
const body = await store.read(sha, bytes);
|
|
4867
5025
|
process.stdout.write(JSON.stringify({ ok: true, bytes: body.length }) + "\n");
|
|
4868
|
-
await new Promise((
|
|
5026
|
+
await new Promise((resolve6) => process.stdout.write(body, () => resolve6()));
|
|
4869
5027
|
reply = null;
|
|
4870
5028
|
break;
|
|
4871
5029
|
}
|
|
@@ -4888,7 +5046,16 @@ async function runWorker(stateDir) {
|
|
|
4888
5046
|
}
|
|
4889
5047
|
const { pushOssBundles: pushOssBundles2 } = await Promise.resolve().then(() => (init_oss_bundle_lane(), oss_bundle_lane_exports));
|
|
4890
5048
|
const { internalEndpointOf: internalEndpointOf2 } = await Promise.resolve().then(() => (init_oss_transport(), oss_transport_exports));
|
|
4891
|
-
const
|
|
5049
|
+
const { settleOssBroker: settleOssBroker2 } = await Promise.resolve().then(() => (init_oss_broker(), oss_broker_exports));
|
|
5050
|
+
const legacy = { ...op.config, endpoint: internalEndpointOf2(op.config.endpoint) };
|
|
5051
|
+
let config = legacy;
|
|
5052
|
+
if (op.config.broker) {
|
|
5053
|
+
try {
|
|
5054
|
+
config = await settleOssBroker2({ ...op.config, endpoint: "", broker: { ...op.config.broker, region: await cloudRegion(), internal: true } });
|
|
5055
|
+
} catch {
|
|
5056
|
+
config = legacy;
|
|
5057
|
+
}
|
|
5058
|
+
}
|
|
4892
5059
|
let acknowledgements = Promise.resolve();
|
|
4893
5060
|
const stream = { ready: Promise.resolve(), close: async () => {
|
|
4894
5061
|
}, receive: (bundles) => {
|