@okxweb3/a2a-node 0.2.18 → 0.2.19-beta-fe6942ad54-261125201445
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/cli.js +1607 -225
- package/dist/index.js +1478 -120
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -114,7 +114,8 @@ function resolveTaskPaths(homeDir = resolveTaskHome()) {
|
|
|
114
114
|
completedCommandsDir: (0, import_node_path2.join)(homeDir, "commands", "completed"),
|
|
115
115
|
pidPath: (0, import_node_path2.join)(homeDir, "run", "listener.pid"),
|
|
116
116
|
daemonLockPath: (0, import_node_path2.join)(homeDir, "run", "daemon.lock"),
|
|
117
|
-
listenerLogPath: (0, import_node_path2.join)(homeDir, "logs", "listener.log")
|
|
117
|
+
listenerLogPath: (0, import_node_path2.join)(homeDir, "logs", "listener.log"),
|
|
118
|
+
devkitServerDbPath: (0, import_node_path2.join)(homeDir, "sqlite", DEVKIT_SERVER_DB_NAME)
|
|
118
119
|
};
|
|
119
120
|
}
|
|
120
121
|
function ensureTaskHome(homeDir) {
|
|
@@ -126,13 +127,14 @@ function encodeJobIdForFile(jobId) {
|
|
|
126
127
|
function ensureTaskDir(dir) {
|
|
127
128
|
return ensureA2aTaskDir(dir);
|
|
128
129
|
}
|
|
129
|
-
var import_node_path2, BACKUP_JOB_ID;
|
|
130
|
+
var import_node_path2, BACKUP_JOB_ID, DEVKIT_SERVER_DB_NAME;
|
|
130
131
|
var init_paths = __esm({
|
|
131
132
|
"src/paths.ts"() {
|
|
132
133
|
"use strict";
|
|
133
134
|
import_node_path2 = require("node:path");
|
|
134
135
|
init_a2a_paths();
|
|
135
136
|
BACKUP_JOB_ID = "backup";
|
|
137
|
+
DEVKIT_SERVER_DB_NAME = "devkit-server.sqlite";
|
|
136
138
|
}
|
|
137
139
|
});
|
|
138
140
|
|
|
@@ -495,7 +497,7 @@ function normalizeGatewayRouteChatType(explicit, parsed, threadId) {
|
|
|
495
497
|
}
|
|
496
498
|
function matchingGatewayRouteFromSessionKey(sessionKey, expected, provider) {
|
|
497
499
|
const parsed = parseGatewayRouteSessionKey(sessionKey, provider);
|
|
498
|
-
if (
|
|
500
|
+
if (parsed?.platform !== expected.platform || parsed.chatId !== expected.chatId) {
|
|
499
501
|
return null;
|
|
500
502
|
}
|
|
501
503
|
return {
|
|
@@ -1765,7 +1767,7 @@ async function readDaemonLock(lockPath) {
|
|
|
1765
1767
|
async function markDaemonReady(lockPath) {
|
|
1766
1768
|
const current = await readDaemonLock(lockPath);
|
|
1767
1769
|
const metadata = current.metadata;
|
|
1768
|
-
if (
|
|
1770
|
+
if (metadata?.pid !== process.pid) {
|
|
1769
1771
|
return;
|
|
1770
1772
|
}
|
|
1771
1773
|
await (0, import_promises.writeFile)(ownerPath(lockPath), `${JSON.stringify({
|
|
@@ -2219,7 +2221,7 @@ async function installWindowsAutostart() {
|
|
|
2219
2221
|
taskHome: taskPaths.homeDir,
|
|
2220
2222
|
...pathValue ? { pathValue } : {}
|
|
2221
2223
|
});
|
|
2222
|
-
await (0, import_promises2.writeFile)(paths.vbsPath,
|
|
2224
|
+
await (0, import_promises2.writeFile)(paths.vbsPath, `\uFEFF${vbsContent}`, "utf16le");
|
|
2223
2225
|
logWinCompat(
|
|
2224
2226
|
`${WIN_COMPAT_LOG_PREFIX} autostart install: wrote vbs=${paths.vbsPath} node=${execPath} cli=${cliPath} taskHome=${taskPaths.homeDir}`
|
|
2225
2227
|
);
|
|
@@ -3357,12 +3359,11 @@ async function ensureAiWorkspace(paths) {
|
|
|
3357
3359
|
}
|
|
3358
3360
|
async function waitForImmediateExit(child, timeoutMs) {
|
|
3359
3361
|
return await new Promise((resolve14) => {
|
|
3360
|
-
let timer;
|
|
3361
3362
|
const onExit = () => {
|
|
3362
3363
|
clearTimeout(timer);
|
|
3363
3364
|
resolve14(true);
|
|
3364
3365
|
};
|
|
3365
|
-
timer = setTimeout(() => {
|
|
3366
|
+
const timer = setTimeout(() => {
|
|
3366
3367
|
child.off("exit", onExit);
|
|
3367
3368
|
resolve14(false);
|
|
3368
3369
|
}, timeoutMs);
|
|
@@ -4395,13 +4396,12 @@ var init_file_store = __esm({
|
|
|
4395
4396
|
withFileLock(path2, operation) {
|
|
4396
4397
|
const previous = this.writeLocks.get(path2) ?? Promise.resolve();
|
|
4397
4398
|
const next = previous.then(operation, operation);
|
|
4398
|
-
let tracked;
|
|
4399
4399
|
const release = () => {
|
|
4400
4400
|
if (this.writeLocks.get(path2) === tracked) {
|
|
4401
4401
|
this.writeLocks.delete(path2);
|
|
4402
4402
|
}
|
|
4403
4403
|
};
|
|
4404
|
-
tracked = next.then(release, release);
|
|
4404
|
+
const tracked = next.then(release, release);
|
|
4405
4405
|
this.writeLocks.set(path2, tracked);
|
|
4406
4406
|
return next;
|
|
4407
4407
|
}
|
|
@@ -20057,7 +20057,25 @@ var init_events = __esm({
|
|
|
20057
20057
|
XMTP_DEBUG_SYNC_FAILED: "XMTP debug sync failed",
|
|
20058
20058
|
// Underlying XMTP SDK client close failed during recycle/removal/shutdown
|
|
20059
20059
|
// (DEXMARKET-9116). Error-level → NOT added to SENTRY_INFO_ALLOWLIST.
|
|
20060
|
-
XMTP_CLIENT_CLOSE_FAILED: "XMTP client close failed"
|
|
20060
|
+
XMTP_CLIENT_CLOSE_FAILED: "XMTP client close failed",
|
|
20061
|
+
// ── devkit custom-server registry + delivery (DEXMARKET-9165) ──────────────
|
|
20062
|
+
// info-level (registered in SENTRY_INFO_ALLOWLIST below):
|
|
20063
|
+
DEVKIT_REGISTER_REQUESTED: "Devkit register requested",
|
|
20064
|
+
DEVKIT_REGISTER_COMPLETED: "Devkit register completed",
|
|
20065
|
+
DEVKIT_UNREGISTER_REQUESTED: "Devkit unregister requested",
|
|
20066
|
+
DEVKIT_UNREGISTER_COMPLETED: "Devkit unregister completed",
|
|
20067
|
+
DEVKIT_DAEMON_STATUS_UNKNOWN: "Devkit daemon status unknown",
|
|
20068
|
+
DEVKIT_ROUTE_DEFAULT_AI: "Devkit route default AI",
|
|
20069
|
+
DEVKIT_ROUTE_CUSTOM_SERVER: "Devkit route custom server",
|
|
20070
|
+
DEVKIT_DELIVERY_ACCEPTED: "Devkit delivery accepted",
|
|
20071
|
+
DEVKIT_DELIVERY_HTTP_ACCEPTED: "Devkit delivery http accepted",
|
|
20072
|
+
DEVKIT_DELIVERY_DROPPED: "Devkit delivery dropped",
|
|
20073
|
+
DEVKIT_DELIVERY_CANCELLED: "Devkit delivery cancelled",
|
|
20074
|
+
// error-level (NOT allowlisted — logger.error):
|
|
20075
|
+
DEVKIT_REGISTER_REJECTED: "Devkit register rejected",
|
|
20076
|
+
DEVKIT_CONFIG_PERSIST_FAILED: "Devkit config persist failed",
|
|
20077
|
+
DEVKIT_ROUTE_CONFIG_READ_FAILED: "Devkit route config read failed",
|
|
20078
|
+
DEVKIT_DELIVERY_HTTP_FAILED: "Devkit delivery http failed"
|
|
20061
20079
|
};
|
|
20062
20080
|
}
|
|
20063
20081
|
});
|
|
@@ -20902,7 +20920,20 @@ var init_sentry_logger = __esm({
|
|
|
20902
20920
|
LogEvent.XMTP_RATE_LIMIT_COOLDOWN_STARTED,
|
|
20903
20921
|
LogEvent.XMTP_RATE_LIMIT_CREATE_SUPPRESSED,
|
|
20904
20922
|
LogEvent.XMTP_RATE_LIMIT_PROBE,
|
|
20905
|
-
LogEvent.XMTP_RATE_LIMIT_RECOVERED
|
|
20923
|
+
LogEvent.XMTP_RATE_LIMIT_RECOVERED,
|
|
20924
|
+
// devkit custom-server registry + delivery info checkpoints (DEXMARKET-9165).
|
|
20925
|
+
// info() drops any event not listed here, so these must stay registered.
|
|
20926
|
+
LogEvent.DEVKIT_REGISTER_REQUESTED,
|
|
20927
|
+
LogEvent.DEVKIT_REGISTER_COMPLETED,
|
|
20928
|
+
LogEvent.DEVKIT_UNREGISTER_REQUESTED,
|
|
20929
|
+
LogEvent.DEVKIT_UNREGISTER_COMPLETED,
|
|
20930
|
+
LogEvent.DEVKIT_DAEMON_STATUS_UNKNOWN,
|
|
20931
|
+
LogEvent.DEVKIT_ROUTE_DEFAULT_AI,
|
|
20932
|
+
LogEvent.DEVKIT_ROUTE_CUSTOM_SERVER,
|
|
20933
|
+
LogEvent.DEVKIT_DELIVERY_ACCEPTED,
|
|
20934
|
+
LogEvent.DEVKIT_DELIVERY_HTTP_ACCEPTED,
|
|
20935
|
+
LogEvent.DEVKIT_DELIVERY_DROPPED,
|
|
20936
|
+
LogEvent.DEVKIT_DELIVERY_CANCELLED
|
|
20906
20937
|
]);
|
|
20907
20938
|
MAX_EXTRA_STRING_LENGTH = 256;
|
|
20908
20939
|
MAX_TAG_VALUE_LENGTH = 128;
|
|
@@ -27018,7 +27049,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
27018
27049
|
client: {
|
|
27019
27050
|
id: "gateway-client",
|
|
27020
27051
|
displayName: "okx-a2a-node",
|
|
27021
|
-
version: "0.2.
|
|
27052
|
+
version: "0.2.19-beta-fe6942ad54-261125201445",
|
|
27022
27053
|
platform: "node",
|
|
27023
27054
|
mode: "backend",
|
|
27024
27055
|
instanceId
|
|
@@ -27029,7 +27060,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
27029
27060
|
commands: [],
|
|
27030
27061
|
permissions: {},
|
|
27031
27062
|
locale: Intl.DateTimeFormat().resolvedOptions().locale || "en-US",
|
|
27032
|
-
userAgent: `okx-a2a-node/${"0.2.
|
|
27063
|
+
userAgent: `okx-a2a-node/${"0.2.19-beta-fe6942ad54-261125201445"}`,
|
|
27033
27064
|
auth: {
|
|
27034
27065
|
...config.token ? { token: config.token } : {},
|
|
27035
27066
|
...config.password ? { password: config.password } : {}
|
|
@@ -28837,7 +28868,6 @@ async function followFile(filePath, onData, options = {}) {
|
|
|
28837
28868
|
let done = false;
|
|
28838
28869
|
await new Promise((resolvePromise, rejectPromise) => {
|
|
28839
28870
|
let watcher;
|
|
28840
|
-
let timer;
|
|
28841
28871
|
const finish = (error) => {
|
|
28842
28872
|
if (done) {
|
|
28843
28873
|
return;
|
|
@@ -28934,7 +28964,7 @@ async function followFile(filePath, onData, options = {}) {
|
|
|
28934
28964
|
checking = false;
|
|
28935
28965
|
}
|
|
28936
28966
|
};
|
|
28937
|
-
timer = setInterval(() => {
|
|
28967
|
+
const timer = setInterval(() => {
|
|
28938
28968
|
void check();
|
|
28939
28969
|
}, pollIntervalMs);
|
|
28940
28970
|
const targetName = (0, import_node_path18.basename)(filePath);
|
|
@@ -29089,7 +29119,7 @@ var init_sentry_config = __esm({
|
|
|
29089
29119
|
environment = process.env.SENTRY_ENV === "dev" ? "dev" : "prod";
|
|
29090
29120
|
SENTRY_CONFIG = {
|
|
29091
29121
|
projectName: "okx/openclaw-okx-a2a-extension",
|
|
29092
|
-
release: "0.2.
|
|
29122
|
+
release: "0.2.19-beta-fe6942ad54-261125201445",
|
|
29093
29123
|
environment,
|
|
29094
29124
|
runtimeContainer: normalizeRuntimeContainer(process.env.OKX_A2A_RUNTIME_CONTAINER)
|
|
29095
29125
|
};
|
|
@@ -39659,8 +39689,8 @@ function readSqliteRows(dbPath, sql, params = []) {
|
|
|
39659
39689
|
if (!(0, import_node_fs17.existsSync)(dbPath)) {
|
|
39660
39690
|
throw unavailable(`SQLite database not found: ${dbPath}`);
|
|
39661
39691
|
}
|
|
39662
|
-
const { DatabaseSync:
|
|
39663
|
-
const db = new
|
|
39692
|
+
const { DatabaseSync: DatabaseSync6 } = loadSqlite3();
|
|
39693
|
+
const db = new DatabaseSync6(dbPath, { readOnly: true });
|
|
39664
39694
|
try {
|
|
39665
39695
|
return db.prepare(sql).all(...params);
|
|
39666
39696
|
} finally {
|
|
@@ -40259,7 +40289,7 @@ async function exportDiagnosticLogs(options) {
|
|
|
40259
40289
|
node: process.version,
|
|
40260
40290
|
platform: process.platform,
|
|
40261
40291
|
arch: process.arch,
|
|
40262
|
-
packageVersion: true ? "0.2.
|
|
40292
|
+
packageVersion: true ? "0.2.19-beta-fe6942ad54-261125201445" : "unknown",
|
|
40263
40293
|
sensitiveContentIncluded: options.includeSensitiveContent,
|
|
40264
40294
|
listenerAndLlmContentIncluded: true,
|
|
40265
40295
|
credentialsAlwaysRedacted: true,
|
|
@@ -41243,19 +41273,33 @@ function buildWhere(filter2, includeCursor) {
|
|
|
41243
41273
|
} else if (filter2.onlyDeleted) {
|
|
41244
41274
|
add("deleted_at IS NOT NULL");
|
|
41245
41275
|
}
|
|
41246
|
-
if (filter2.jobId)
|
|
41247
|
-
|
|
41276
|
+
if (filter2.jobId) {
|
|
41277
|
+
add("job_id = ?", filter2.jobId);
|
|
41278
|
+
}
|
|
41279
|
+
if (filter2.deliveryId) {
|
|
41280
|
+
add("delivery_id = ?", filter2.deliveryId);
|
|
41281
|
+
}
|
|
41248
41282
|
if (filter2.statuses && filter2.statuses.length > 0) {
|
|
41249
41283
|
add(`status IN (${filter2.statuses.map(() => "?").join(", ")})`, ...filter2.statuses);
|
|
41250
41284
|
}
|
|
41251
|
-
if (filter2.reason !== void 0)
|
|
41285
|
+
if (filter2.reason !== void 0) {
|
|
41286
|
+
add("reason = ?", filter2.reason);
|
|
41287
|
+
}
|
|
41252
41288
|
if (filter2.reasonContains !== void 0) {
|
|
41253
41289
|
add("reason LIKE ? ESCAPE '\\'", `%${escapeLike(filter2.reasonContains)}%`);
|
|
41254
41290
|
}
|
|
41255
|
-
if (filter2.createdFrom !== void 0)
|
|
41256
|
-
|
|
41257
|
-
|
|
41258
|
-
if (filter2.
|
|
41291
|
+
if (filter2.createdFrom !== void 0) {
|
|
41292
|
+
add("created_at >= ?", filter2.createdFrom);
|
|
41293
|
+
}
|
|
41294
|
+
if (filter2.createdTo !== void 0) {
|
|
41295
|
+
add("created_at <= ?", filter2.createdTo);
|
|
41296
|
+
}
|
|
41297
|
+
if (filter2.updatedFrom !== void 0) {
|
|
41298
|
+
add("updated_at >= ?", filter2.updatedFrom);
|
|
41299
|
+
}
|
|
41300
|
+
if (filter2.updatedTo !== void 0) {
|
|
41301
|
+
add("updated_at <= ?", filter2.updatedTo);
|
|
41302
|
+
}
|
|
41259
41303
|
for (const extra of filter2.extraEquals ?? []) {
|
|
41260
41304
|
if (extra.value === null) {
|
|
41261
41305
|
add("json_type(extra, ?) = 'null'", extra.path);
|
|
@@ -41879,7 +41923,9 @@ function loadInsertRecords(parsed) {
|
|
|
41879
41923
|
}
|
|
41880
41924
|
content2 = (0, import_node_fs21.readFileSync)(inputFile, "utf8");
|
|
41881
41925
|
} catch (error) {
|
|
41882
|
-
if (error instanceof TradeRecordsCliError)
|
|
41926
|
+
if (error instanceof TradeRecordsCliError) {
|
|
41927
|
+
throw error;
|
|
41928
|
+
}
|
|
41883
41929
|
throw new TradeRecordsCliError("INVALID_INPUT_FILE", `could not read --input-file: ${String(error)}`);
|
|
41884
41930
|
}
|
|
41885
41931
|
return { records: parseRecordArray(content2, "--input-file") };
|
|
@@ -42082,7 +42128,9 @@ function parseExtraFilter(raw) {
|
|
|
42082
42128
|
}
|
|
42083
42129
|
function readTimestamp(parsed, name) {
|
|
42084
42130
|
const raw = readSingle(parsed, name);
|
|
42085
|
-
if (raw === void 0)
|
|
42131
|
+
if (raw === void 0) {
|
|
42132
|
+
return void 0;
|
|
42133
|
+
}
|
|
42086
42134
|
const value = Number(raw);
|
|
42087
42135
|
if (!Number.isSafeInteger(value) || value < 0) {
|
|
42088
42136
|
throw new TradeRecordsCliError("INVALID_ARGUMENT", `--${name} must be a non-negative integer`);
|
|
@@ -42096,7 +42144,9 @@ function assertRange(label, from, to) {
|
|
|
42096
42144
|
}
|
|
42097
42145
|
function readLimit(parsed) {
|
|
42098
42146
|
const raw = readSingle(parsed, "limit");
|
|
42099
|
-
if (raw === void 0)
|
|
42147
|
+
if (raw === void 0) {
|
|
42148
|
+
return 100;
|
|
42149
|
+
}
|
|
42100
42150
|
const limit = Number(raw);
|
|
42101
42151
|
if (!Number.isInteger(limit) || limit < 1 || limit > 1e3) {
|
|
42102
42152
|
throw new TradeRecordsCliError("INVALID_ARGUMENT", "--limit must be an integer between 1 and 1000");
|
|
@@ -42105,7 +42155,9 @@ function readLimit(parsed) {
|
|
|
42105
42155
|
}
|
|
42106
42156
|
function readChoice(parsed, name, choices) {
|
|
42107
42157
|
const value = readSingle(parsed, name);
|
|
42108
|
-
if (value === void 0)
|
|
42158
|
+
if (value === void 0) {
|
|
42159
|
+
return void 0;
|
|
42160
|
+
}
|
|
42109
42161
|
if (!choices.includes(value)) {
|
|
42110
42162
|
throw new TradeRecordsCliError(
|
|
42111
42163
|
"INVALID_ARGUMENT",
|
|
@@ -42176,7 +42228,9 @@ function outputError(json, error) {
|
|
|
42176
42228
|
}
|
|
42177
42229
|
}
|
|
42178
42230
|
function normalizeError(error) {
|
|
42179
|
-
if (error instanceof TradeRecordsCliError)
|
|
42231
|
+
if (error instanceof TradeRecordsCliError) {
|
|
42232
|
+
return error;
|
|
42233
|
+
}
|
|
42180
42234
|
if (error instanceof TradeRecordsStoreError) {
|
|
42181
42235
|
return new TradeRecordsCliError(error.code, error.message);
|
|
42182
42236
|
}
|
|
@@ -42189,7 +42243,9 @@ function normalizeError(error) {
|
|
|
42189
42243
|
);
|
|
42190
42244
|
}
|
|
42191
42245
|
function isBusyError(error) {
|
|
42192
|
-
if (!(error instanceof Error))
|
|
42246
|
+
if (!(error instanceof Error)) {
|
|
42247
|
+
return false;
|
|
42248
|
+
}
|
|
42193
42249
|
const code = error.errcode;
|
|
42194
42250
|
return typeof code === "number" && ((code & 255) === 5 || (code & 255) === 6) || /database is locked|database table is locked/i.test(error.message);
|
|
42195
42251
|
}
|
|
@@ -42238,6 +42294,755 @@ var init_trade_records_cli = __esm({
|
|
|
42238
42294
|
}
|
|
42239
42295
|
});
|
|
42240
42296
|
|
|
42297
|
+
// src/devkit-target.ts
|
|
42298
|
+
function normalizeDevkitTarget(origin, port) {
|
|
42299
|
+
if (typeof origin !== "string" || origin.includes("\\")) {
|
|
42300
|
+
throw new DevkitTargetError("url", "URL must be an HTTP or HTTPS loopback origin");
|
|
42301
|
+
}
|
|
42302
|
+
const originParts = /^(https?):\/\/([^/?#]*)(.*)$/i.exec(origin);
|
|
42303
|
+
if (!originParts) {
|
|
42304
|
+
throw new DevkitTargetError("url", "URL must be an HTTP or HTTPS loopback origin");
|
|
42305
|
+
}
|
|
42306
|
+
let parsedUrl;
|
|
42307
|
+
try {
|
|
42308
|
+
parsedUrl = new URL(origin);
|
|
42309
|
+
} catch {
|
|
42310
|
+
throw new DevkitTargetError("url", "URL must be a valid HTTP or HTTPS loopback origin");
|
|
42311
|
+
}
|
|
42312
|
+
if (parsedUrl.protocol !== "http:" && parsedUrl.protocol !== "https:") {
|
|
42313
|
+
throw new DevkitTargetError("url", "URL protocol must be HTTP or HTTPS");
|
|
42314
|
+
}
|
|
42315
|
+
const rawAuthority = originParts[2];
|
|
42316
|
+
const rawHost = rawAuthority.slice(rawAuthority.lastIndexOf("@") + 1);
|
|
42317
|
+
const hasEmbeddedPort = rawHost.startsWith("[") ? /^\[[^\]]+\]:/.test(rawHost) : rawHost.includes(":");
|
|
42318
|
+
if (rawAuthority.includes("@") || hasEmbeddedPort || originParts[3] !== "" && originParts[3] !== "/") {
|
|
42319
|
+
throw new DevkitTargetError("url", "URL must not include credentials, a port, or a path, query, or fragment");
|
|
42320
|
+
}
|
|
42321
|
+
const hostname = parsedUrl.hostname.toLowerCase();
|
|
42322
|
+
if (!isDevkitLoopbackHostname(hostname)) {
|
|
42323
|
+
throw new DevkitTargetError("url", "URL hostname must be localhost or a loopback address");
|
|
42324
|
+
}
|
|
42325
|
+
if (!Number.isInteger(port) || port < 1 || port > 65535) {
|
|
42326
|
+
throw new DevkitTargetError("port", "Port must be an integer from 1 to 65535");
|
|
42327
|
+
}
|
|
42328
|
+
const normalizedHostname = hostname === "localhost" ? "127.0.0.1" : hostname;
|
|
42329
|
+
return {
|
|
42330
|
+
origin: `${parsedUrl.protocol}//${normalizedHostname}`,
|
|
42331
|
+
port
|
|
42332
|
+
};
|
|
42333
|
+
}
|
|
42334
|
+
function isDevkitLoopbackHostname(hostname) {
|
|
42335
|
+
const address = hostname.startsWith("[") && hostname.endsWith("]") ? hostname.slice(1, -1) : hostname;
|
|
42336
|
+
if (address.toLowerCase() === "localhost") {
|
|
42337
|
+
return true;
|
|
42338
|
+
}
|
|
42339
|
+
return (0, import_node_net2.isIP)(address) === 4 ? address.startsWith("127.") : (0, import_node_net2.isIP)(address) === 6 && address === "::1";
|
|
42340
|
+
}
|
|
42341
|
+
var import_node_net2, DevkitTargetError;
|
|
42342
|
+
var init_devkit_target = __esm({
|
|
42343
|
+
"src/devkit-target.ts"() {
|
|
42344
|
+
"use strict";
|
|
42345
|
+
import_node_net2 = require("node:net");
|
|
42346
|
+
DevkitTargetError = class extends Error {
|
|
42347
|
+
constructor(field, message) {
|
|
42348
|
+
super(message);
|
|
42349
|
+
this.field = field;
|
|
42350
|
+
this.name = "DevkitTargetError";
|
|
42351
|
+
}
|
|
42352
|
+
field;
|
|
42353
|
+
};
|
|
42354
|
+
}
|
|
42355
|
+
});
|
|
42356
|
+
|
|
42357
|
+
// src/devkit-server-store.ts
|
|
42358
|
+
function resolveDevkitServerDbPath(homeDir) {
|
|
42359
|
+
return resolveTaskPaths(homeDir).devkitServerDbPath;
|
|
42360
|
+
}
|
|
42361
|
+
function applyMigrationV2(db) {
|
|
42362
|
+
db.exec(`
|
|
42363
|
+
CREATE TABLE ${TABLE_NAME2} (
|
|
42364
|
+
id INTEGER PRIMARY KEY,
|
|
42365
|
+
origin TEXT NOT NULL,
|
|
42366
|
+
port INTEGER NOT NULL CHECK (port >= 1 AND port <= 65535),
|
|
42367
|
+
event_path TEXT NOT NULL,
|
|
42368
|
+
health_path TEXT NOT NULL,
|
|
42369
|
+
config_version INTEGER NOT NULL,
|
|
42370
|
+
updated_at INTEGER NOT NULL,
|
|
42371
|
+
CHECK (length(origin) > 0),
|
|
42372
|
+
CHECK (substr(event_path,1,1) = '/'),
|
|
42373
|
+
CHECK (substr(health_path,1,1) = '/'),
|
|
42374
|
+
UNIQUE (origin, port)
|
|
42375
|
+
)
|
|
42376
|
+
`);
|
|
42377
|
+
}
|
|
42378
|
+
function migrateV1ToV2(db) {
|
|
42379
|
+
const legacyRows = db.prepare(`
|
|
42380
|
+
SELECT id, origin, port, event_path, health_path, config_version, updated_at
|
|
42381
|
+
FROM ${TABLE_NAME2} ORDER BY id ASC
|
|
42382
|
+
`).all().map((row) => ({ ...parseDevkitServerRow(row), id: readRowNumber(row, "id") }));
|
|
42383
|
+
db.exec(`ALTER TABLE ${TABLE_NAME2} RENAME TO "devkit-server-v1"`);
|
|
42384
|
+
applyMigrationV2(db);
|
|
42385
|
+
const insert = db.prepare(`
|
|
42386
|
+
INSERT INTO ${TABLE_NAME2} (
|
|
42387
|
+
id, origin, port, event_path, health_path, config_version, updated_at
|
|
42388
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
42389
|
+
`);
|
|
42390
|
+
for (const row of legacyRows) {
|
|
42391
|
+
const target = normalizeDevkitTarget(row.origin, row.port);
|
|
42392
|
+
insert.run(
|
|
42393
|
+
row.id,
|
|
42394
|
+
target.origin,
|
|
42395
|
+
target.port,
|
|
42396
|
+
row.event_path,
|
|
42397
|
+
row.health_path,
|
|
42398
|
+
row.config_version,
|
|
42399
|
+
row.updated_at
|
|
42400
|
+
);
|
|
42401
|
+
}
|
|
42402
|
+
db.exec('DROP TABLE "devkit-server-v1"');
|
|
42403
|
+
}
|
|
42404
|
+
function readRowNumber(row, field) {
|
|
42405
|
+
const value = row[field];
|
|
42406
|
+
if (typeof value !== "number" || !Number.isSafeInteger(value)) {
|
|
42407
|
+
throw new DevkitServerStoreError("DATABASE_READ_FAILED", `invalid devkit server field: ${field}`);
|
|
42408
|
+
}
|
|
42409
|
+
return value;
|
|
42410
|
+
}
|
|
42411
|
+
function readRowString(row, field) {
|
|
42412
|
+
const value = row[field];
|
|
42413
|
+
if (typeof value !== "string") {
|
|
42414
|
+
throw new DevkitServerStoreError("DATABASE_READ_FAILED", `invalid devkit server field: ${field}`);
|
|
42415
|
+
}
|
|
42416
|
+
return value;
|
|
42417
|
+
}
|
|
42418
|
+
function parseDevkitServerRow(row) {
|
|
42419
|
+
return {
|
|
42420
|
+
origin: readRowString(row, "origin"),
|
|
42421
|
+
port: readRowNumber(row, "port"),
|
|
42422
|
+
event_path: readRowString(row, "event_path"),
|
|
42423
|
+
health_path: readRowString(row, "health_path"),
|
|
42424
|
+
config_version: readRowNumber(row, "config_version"),
|
|
42425
|
+
updated_at: readRowNumber(row, "updated_at")
|
|
42426
|
+
};
|
|
42427
|
+
}
|
|
42428
|
+
function assertValidPath(path2, label) {
|
|
42429
|
+
if (typeof path2 !== "string" || !path2.startsWith("/") || path2.length === 0) {
|
|
42430
|
+
throw new DevkitServerStoreError("INVALID_CONFIG_PATH", `${label} must start with /`);
|
|
42431
|
+
}
|
|
42432
|
+
}
|
|
42433
|
+
function readPragmaNumber2(db, name) {
|
|
42434
|
+
const row = db.prepare(`PRAGMA ${name}`).get();
|
|
42435
|
+
return Number(row[name] ?? 0);
|
|
42436
|
+
}
|
|
42437
|
+
function assertNotSymlink2(path2, label) {
|
|
42438
|
+
if (!(0, import_node_fs22.existsSync)(path2)) {
|
|
42439
|
+
return;
|
|
42440
|
+
}
|
|
42441
|
+
if ((0, import_node_fs22.lstatSync)(path2).isSymbolicLink()) {
|
|
42442
|
+
throw new DevkitServerStoreError("DATABASE_PATH_UNSAFE", `${label} must not be a symbolic link`);
|
|
42443
|
+
}
|
|
42444
|
+
}
|
|
42445
|
+
function assertSafeDatabasePath2(dbPath) {
|
|
42446
|
+
assertSafeDatabaseFile2(dbPath);
|
|
42447
|
+
for (const suffix of ["-journal", "-wal", "-shm"]) {
|
|
42448
|
+
assertNotSymlink2(`${dbPath}${suffix}`, `devkit server database sidecar ${suffix}`);
|
|
42449
|
+
}
|
|
42450
|
+
}
|
|
42451
|
+
function assertSafeDatabaseFile2(dbPath) {
|
|
42452
|
+
if (!(0, import_node_fs22.existsSync)(dbPath)) {
|
|
42453
|
+
return;
|
|
42454
|
+
}
|
|
42455
|
+
const stat4 = (0, import_node_fs22.lstatSync)(dbPath);
|
|
42456
|
+
if (stat4.isSymbolicLink()) {
|
|
42457
|
+
throw new DevkitServerStoreError(
|
|
42458
|
+
"DATABASE_PATH_UNSAFE",
|
|
42459
|
+
"devkit server database must not be a symbolic link"
|
|
42460
|
+
);
|
|
42461
|
+
}
|
|
42462
|
+
if (!stat4.isFile() || stat4.nlink !== 1) {
|
|
42463
|
+
throw new DevkitServerStoreError(
|
|
42464
|
+
"DATABASE_PATH_UNSAFE",
|
|
42465
|
+
"devkit server database must be a regular file with one hard link"
|
|
42466
|
+
);
|
|
42467
|
+
}
|
|
42468
|
+
}
|
|
42469
|
+
function rollbackQuietly2(db) {
|
|
42470
|
+
try {
|
|
42471
|
+
db.exec("ROLLBACK");
|
|
42472
|
+
} catch {
|
|
42473
|
+
}
|
|
42474
|
+
}
|
|
42475
|
+
function withBusyRetry2(operation) {
|
|
42476
|
+
for (let attempt = 1; ; attempt += 1) {
|
|
42477
|
+
try {
|
|
42478
|
+
return operation();
|
|
42479
|
+
} catch (error) {
|
|
42480
|
+
if (!isSqliteBusyError(error) || attempt >= WRITE_RETRY_ATTEMPTS2) {
|
|
42481
|
+
throw error;
|
|
42482
|
+
}
|
|
42483
|
+
sleepSyncMs3(Math.min(100 * 2 ** (attempt - 1), 1600));
|
|
42484
|
+
}
|
|
42485
|
+
}
|
|
42486
|
+
}
|
|
42487
|
+
function sleepSyncMs3(ms) {
|
|
42488
|
+
const buffer2 = new Int32Array(new SharedArrayBuffer(4));
|
|
42489
|
+
Atomics.wait(buffer2, 0, 0, ms);
|
|
42490
|
+
}
|
|
42491
|
+
function loadSqlite5() {
|
|
42492
|
+
const originalEmitWarning = process.emitWarning;
|
|
42493
|
+
process.emitWarning = ((warning, ...args) => {
|
|
42494
|
+
const message = typeof warning === "string" ? warning : warning.message;
|
|
42495
|
+
if (message.includes("SQLite is an experimental feature") && args.some((arg) => arg === "ExperimentalWarning")) {
|
|
42496
|
+
return;
|
|
42497
|
+
}
|
|
42498
|
+
return originalEmitWarning.call(process, warning, ...args);
|
|
42499
|
+
});
|
|
42500
|
+
try {
|
|
42501
|
+
return require("node:sqlite");
|
|
42502
|
+
} finally {
|
|
42503
|
+
process.emitWarning = originalEmitWarning;
|
|
42504
|
+
}
|
|
42505
|
+
}
|
|
42506
|
+
var import_node_fs22, DatabaseSync4, DEVKIT_SERVER_APPLICATION_ID, DEVKIT_SERVER_SCHEMA_VERSION, TABLE_NAME2, WRITE_RETRY_ATTEMPTS2, DevkitServerStoreError, DevkitServerStore;
|
|
42507
|
+
var init_devkit_server_store = __esm({
|
|
42508
|
+
"src/devkit-server-store.ts"() {
|
|
42509
|
+
"use strict";
|
|
42510
|
+
import_node_fs22 = require("node:fs");
|
|
42511
|
+
init_paths();
|
|
42512
|
+
init_session_store();
|
|
42513
|
+
init_devkit_target();
|
|
42514
|
+
({ DatabaseSync: DatabaseSync4 } = loadSqlite5());
|
|
42515
|
+
DEVKIT_SERVER_APPLICATION_ID = 1329677395;
|
|
42516
|
+
DEVKIT_SERVER_SCHEMA_VERSION = 2;
|
|
42517
|
+
TABLE_NAME2 = `"devkit-server"`;
|
|
42518
|
+
WRITE_RETRY_ATTEMPTS2 = 6;
|
|
42519
|
+
DevkitServerStoreError = class extends Error {
|
|
42520
|
+
code;
|
|
42521
|
+
constructor(code, message) {
|
|
42522
|
+
super(message);
|
|
42523
|
+
this.name = "DevkitServerStoreError";
|
|
42524
|
+
this.code = code;
|
|
42525
|
+
}
|
|
42526
|
+
};
|
|
42527
|
+
DevkitServerStore = class _DevkitServerStore {
|
|
42528
|
+
dbPath;
|
|
42529
|
+
db;
|
|
42530
|
+
constructor(dbPath, db) {
|
|
42531
|
+
this.dbPath = dbPath;
|
|
42532
|
+
this.db = db;
|
|
42533
|
+
}
|
|
42534
|
+
static openForWrite(homeDir) {
|
|
42535
|
+
const paths = resolveTaskPaths(homeDir);
|
|
42536
|
+
const dbPath = paths.devkitServerDbPath;
|
|
42537
|
+
assertNotSymlink2(paths.sqliteDir, "devkit server directory");
|
|
42538
|
+
ensureTaskDir(paths.sqliteDir);
|
|
42539
|
+
assertNotSymlink2(paths.sqliteDir, "devkit server directory");
|
|
42540
|
+
assertSafeDatabasePath2(dbPath);
|
|
42541
|
+
const db = new DatabaseSync4(dbPath);
|
|
42542
|
+
const store = new _DevkitServerStore(dbPath, db);
|
|
42543
|
+
try {
|
|
42544
|
+
store.configureConnectionForWrite();
|
|
42545
|
+
store.ensureSchemaForWrite();
|
|
42546
|
+
return store;
|
|
42547
|
+
} catch (error) {
|
|
42548
|
+
db.close();
|
|
42549
|
+
throw error;
|
|
42550
|
+
}
|
|
42551
|
+
}
|
|
42552
|
+
static openForRead(homeDir) {
|
|
42553
|
+
const dbPath = resolveDevkitServerDbPath(homeDir);
|
|
42554
|
+
if (!(0, import_node_fs22.existsSync)(dbPath)) {
|
|
42555
|
+
return null;
|
|
42556
|
+
}
|
|
42557
|
+
assertSafeDatabaseFile2(dbPath);
|
|
42558
|
+
const db = new DatabaseSync4(dbPath, { readOnly: true });
|
|
42559
|
+
const store = new _DevkitServerStore(dbPath, db);
|
|
42560
|
+
try {
|
|
42561
|
+
db.exec("PRAGMA query_only=ON");
|
|
42562
|
+
store.assertReadableSchema();
|
|
42563
|
+
return store;
|
|
42564
|
+
} catch (error) {
|
|
42565
|
+
db.close();
|
|
42566
|
+
throw error;
|
|
42567
|
+
}
|
|
42568
|
+
}
|
|
42569
|
+
close() {
|
|
42570
|
+
this.db.close();
|
|
42571
|
+
}
|
|
42572
|
+
register(input) {
|
|
42573
|
+
const target = normalizeDevkitTarget(input.origin, input.port);
|
|
42574
|
+
assertValidPath(input.eventPath, "event path");
|
|
42575
|
+
assertValidPath(input.healthPath, "health path");
|
|
42576
|
+
return this.withWriteTransaction(() => {
|
|
42577
|
+
const existing = this.db.prepare(`SELECT config_version FROM ${TABLE_NAME2} WHERE origin = ? AND port = ?`).get(target.origin, target.port);
|
|
42578
|
+
const configVersion = (existing?.config_version ?? 0) + 1;
|
|
42579
|
+
const updatedAt = Date.now();
|
|
42580
|
+
this.db.prepare(`
|
|
42581
|
+
INSERT INTO ${TABLE_NAME2} (
|
|
42582
|
+
origin, port, event_path, health_path, config_version, updated_at
|
|
42583
|
+
) VALUES (?, ?, ?, ?, ?, ?)
|
|
42584
|
+
ON CONFLICT(origin, port) DO UPDATE SET
|
|
42585
|
+
event_path = excluded.event_path,
|
|
42586
|
+
health_path = excluded.health_path,
|
|
42587
|
+
config_version = excluded.config_version,
|
|
42588
|
+
updated_at = excluded.updated_at
|
|
42589
|
+
`).run(target.origin, target.port, input.eventPath, input.healthPath, configVersion, updatedAt);
|
|
42590
|
+
return {
|
|
42591
|
+
origin: target.origin,
|
|
42592
|
+
port: target.port,
|
|
42593
|
+
eventPath: input.eventPath,
|
|
42594
|
+
healthPath: input.healthPath,
|
|
42595
|
+
configVersion,
|
|
42596
|
+
updatedAt
|
|
42597
|
+
};
|
|
42598
|
+
});
|
|
42599
|
+
}
|
|
42600
|
+
unregister(targetInput) {
|
|
42601
|
+
const target = targetInput ? normalizeDevkitTarget(targetInput.origin, targetInput.port) : void 0;
|
|
42602
|
+
return this.withWriteTransaction(() => {
|
|
42603
|
+
const result = target ? this.db.prepare(`DELETE FROM ${TABLE_NAME2} WHERE origin = ? AND port = ?`).run(target.origin, target.port) : this.db.prepare(`DELETE FROM ${TABLE_NAME2}`).run();
|
|
42604
|
+
const removedCount = Number(result.changes);
|
|
42605
|
+
return { removed: removedCount > 0, removedCount };
|
|
42606
|
+
});
|
|
42607
|
+
}
|
|
42608
|
+
readSnapshot() {
|
|
42609
|
+
return this.readSnapshots()[0] ?? null;
|
|
42610
|
+
}
|
|
42611
|
+
readSnapshots() {
|
|
42612
|
+
let rows;
|
|
42613
|
+
try {
|
|
42614
|
+
rows = this.db.prepare(`
|
|
42615
|
+
SELECT origin, port, event_path, health_path, config_version, updated_at
|
|
42616
|
+
FROM ${TABLE_NAME2} ORDER BY origin ASC, port ASC, id ASC
|
|
42617
|
+
`).all().map(parseDevkitServerRow);
|
|
42618
|
+
} catch (error) {
|
|
42619
|
+
throw new DevkitServerStoreError(
|
|
42620
|
+
"DATABASE_READ_FAILED",
|
|
42621
|
+
`failed to read devkit server configs: ${error instanceof Error ? error.message : String(error)}`
|
|
42622
|
+
);
|
|
42623
|
+
}
|
|
42624
|
+
return rows.map((snapshot) => ({
|
|
42625
|
+
origin: snapshot.origin,
|
|
42626
|
+
port: snapshot.port,
|
|
42627
|
+
eventPath: snapshot.event_path,
|
|
42628
|
+
healthPath: snapshot.health_path,
|
|
42629
|
+
configVersion: snapshot.config_version,
|
|
42630
|
+
updatedAt: snapshot.updated_at
|
|
42631
|
+
}));
|
|
42632
|
+
}
|
|
42633
|
+
configureConnectionForWrite() {
|
|
42634
|
+
this.db.exec("PRAGMA busy_timeout=5000");
|
|
42635
|
+
}
|
|
42636
|
+
ensureSchemaForWrite() {
|
|
42637
|
+
withBusyRetry2(() => {
|
|
42638
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
42639
|
+
try {
|
|
42640
|
+
const applicationId = readPragmaNumber2(this.db, "application_id");
|
|
42641
|
+
const userVersion = readPragmaNumber2(this.db, "user_version");
|
|
42642
|
+
const hasTables = Boolean(
|
|
42643
|
+
this.db.prepare("SELECT 1 AS present FROM sqlite_master WHERE type = 'table' LIMIT 1").get()
|
|
42644
|
+
);
|
|
42645
|
+
if (applicationId === 0 && !hasTables && userVersion === 0) {
|
|
42646
|
+
this.db.exec(`PRAGMA application_id=${DEVKIT_SERVER_APPLICATION_ID}`);
|
|
42647
|
+
} else if (applicationId !== DEVKIT_SERVER_APPLICATION_ID) {
|
|
42648
|
+
throw new DevkitServerStoreError(
|
|
42649
|
+
"DATABASE_IDENTITY_MISMATCH",
|
|
42650
|
+
"devkit server database identity does not match"
|
|
42651
|
+
);
|
|
42652
|
+
}
|
|
42653
|
+
if (userVersion > DEVKIT_SERVER_SCHEMA_VERSION) {
|
|
42654
|
+
throw new DevkitServerStoreError(
|
|
42655
|
+
"DATABASE_SCHEMA_TOO_NEW",
|
|
42656
|
+
`devkit server schema version ${userVersion} is newer than supported ${DEVKIT_SERVER_SCHEMA_VERSION}`
|
|
42657
|
+
);
|
|
42658
|
+
}
|
|
42659
|
+
if (userVersion === 0) {
|
|
42660
|
+
applyMigrationV2(this.db);
|
|
42661
|
+
this.db.exec("PRAGMA user_version=2");
|
|
42662
|
+
} else if (userVersion === 1) {
|
|
42663
|
+
migrateV1ToV2(this.db);
|
|
42664
|
+
this.db.exec("PRAGMA user_version=2");
|
|
42665
|
+
}
|
|
42666
|
+
this.db.exec("COMMIT");
|
|
42667
|
+
} catch (error) {
|
|
42668
|
+
rollbackQuietly2(this.db);
|
|
42669
|
+
throw error;
|
|
42670
|
+
}
|
|
42671
|
+
});
|
|
42672
|
+
withBusyRetry2(() => {
|
|
42673
|
+
this.db.exec("PRAGMA journal_mode=WAL");
|
|
42674
|
+
this.db.exec("PRAGMA synchronous=FULL");
|
|
42675
|
+
});
|
|
42676
|
+
}
|
|
42677
|
+
assertReadableSchema() {
|
|
42678
|
+
const applicationId = readPragmaNumber2(this.db, "application_id");
|
|
42679
|
+
if (applicationId !== DEVKIT_SERVER_APPLICATION_ID) {
|
|
42680
|
+
throw new DevkitServerStoreError(
|
|
42681
|
+
"DATABASE_IDENTITY_MISMATCH",
|
|
42682
|
+
"devkit server database identity does not match"
|
|
42683
|
+
);
|
|
42684
|
+
}
|
|
42685
|
+
const userVersion = readPragmaNumber2(this.db, "user_version");
|
|
42686
|
+
if (userVersion > DEVKIT_SERVER_SCHEMA_VERSION) {
|
|
42687
|
+
throw new DevkitServerStoreError(
|
|
42688
|
+
"DATABASE_SCHEMA_TOO_NEW",
|
|
42689
|
+
`devkit server schema version ${userVersion} is newer than supported ${DEVKIT_SERVER_SCHEMA_VERSION}`
|
|
42690
|
+
);
|
|
42691
|
+
}
|
|
42692
|
+
if (userVersion < DEVKIT_SERVER_SCHEMA_VERSION) {
|
|
42693
|
+
throw new DevkitServerStoreError(
|
|
42694
|
+
"DATABASE_MIGRATION_REQUIRED",
|
|
42695
|
+
"devkit server database requires a write command to finish migration"
|
|
42696
|
+
);
|
|
42697
|
+
}
|
|
42698
|
+
}
|
|
42699
|
+
withWriteTransaction(operation) {
|
|
42700
|
+
return withBusyRetry2(() => {
|
|
42701
|
+
this.db.exec("BEGIN IMMEDIATE");
|
|
42702
|
+
try {
|
|
42703
|
+
const result = operation();
|
|
42704
|
+
this.db.exec("COMMIT");
|
|
42705
|
+
return result;
|
|
42706
|
+
} catch (error) {
|
|
42707
|
+
rollbackQuietly2(this.db);
|
|
42708
|
+
throw error;
|
|
42709
|
+
}
|
|
42710
|
+
});
|
|
42711
|
+
}
|
|
42712
|
+
};
|
|
42713
|
+
}
|
|
42714
|
+
});
|
|
42715
|
+
|
|
42716
|
+
// src/devkit-cli.ts
|
|
42717
|
+
var devkit_cli_exports = {};
|
|
42718
|
+
__export(devkit_cli_exports, {
|
|
42719
|
+
handleDevkitCommand: () => handleDevkitCommand,
|
|
42720
|
+
printDevkitUsage: () => printDevkitUsage
|
|
42721
|
+
});
|
|
42722
|
+
async function handleDevkitCommand(args) {
|
|
42723
|
+
const wantsJson = args.includes("--json");
|
|
42724
|
+
const subcommand = args[0];
|
|
42725
|
+
if (!subcommand || isHelpArg2(subcommand)) {
|
|
42726
|
+
printDevkitUsage();
|
|
42727
|
+
return;
|
|
42728
|
+
}
|
|
42729
|
+
if (args.slice(1).some(isHelpArg2)) {
|
|
42730
|
+
printDevkitUsage();
|
|
42731
|
+
return;
|
|
42732
|
+
}
|
|
42733
|
+
if (subcommand === "register") {
|
|
42734
|
+
await handleRegister(args.slice(1), wantsJson);
|
|
42735
|
+
return;
|
|
42736
|
+
}
|
|
42737
|
+
if (subcommand === "unregister") {
|
|
42738
|
+
await handleUnregister(args.slice(1), wantsJson);
|
|
42739
|
+
return;
|
|
42740
|
+
}
|
|
42741
|
+
outputError2(wantsJson, { field: "command", reason: `unknown devkit command: ${subcommand}` });
|
|
42742
|
+
process.exitCode = 1;
|
|
42743
|
+
}
|
|
42744
|
+
function printDevkitUsage() {
|
|
42745
|
+
console.log(`Usage: okx-a2a devkit <register|unregister> [options]
|
|
42746
|
+
|
|
42747
|
+
Commands:
|
|
42748
|
+
register Register a local custom server for daemon auto-message delivery.
|
|
42749
|
+
--url <origin> --port <n> --paths '{"event":"/path","health":"/path"}'
|
|
42750
|
+
Multiple loopback targets are allowed; localhost is stored as IPv4 127.0.0.1.
|
|
42751
|
+
unregister Remove one target with paired --url and --port, or omit both to unregister all.
|
|
42752
|
+
Already queued deliveries keep their captured target snapshot and are not retracted.
|
|
42753
|
+
|
|
42754
|
+
Options:
|
|
42755
|
+
--json Print machine-readable output.`);
|
|
42756
|
+
}
|
|
42757
|
+
async function handleRegister(args, wantsJson) {
|
|
42758
|
+
const operationId = (0, import_node_crypto9.randomUUID)();
|
|
42759
|
+
const startedAt = Date.now();
|
|
42760
|
+
logger.info(LogEvent.DEVKIT_REGISTER_REQUESTED, devkitSentryExtra({ operationId, phase: "requested" }));
|
|
42761
|
+
try {
|
|
42762
|
+
const parsed = parseArgs2(args, { options: /* @__PURE__ */ new Set(["url", "port", "paths"]), flags: /* @__PURE__ */ new Set(["json"]) });
|
|
42763
|
+
const rawOrigin = requireOption(parsed, "url");
|
|
42764
|
+
const rawPort = requireOption(parsed, "port");
|
|
42765
|
+
const target = normalizeDevkitTarget(rawOrigin, parsePortValue(rawPort));
|
|
42766
|
+
const { eventPath, healthPath } = validatePaths(requireOption(parsed, "paths"));
|
|
42767
|
+
let config;
|
|
42768
|
+
try {
|
|
42769
|
+
const store = DevkitServerStore.openForWrite();
|
|
42770
|
+
try {
|
|
42771
|
+
config = store.register({ ...target, eventPath, healthPath });
|
|
42772
|
+
} finally {
|
|
42773
|
+
store.close();
|
|
42774
|
+
}
|
|
42775
|
+
} catch (error) {
|
|
42776
|
+
logger.error(
|
|
42777
|
+
LogEvent.DEVKIT_CONFIG_PERSIST_FAILED,
|
|
42778
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
42779
|
+
devkitSentryExtra({ operationId, phase: "persist_failed", durationMs: Date.now() - startedAt })
|
|
42780
|
+
);
|
|
42781
|
+
outputError2(wantsJson, {
|
|
42782
|
+
field: "config",
|
|
42783
|
+
reason: error instanceof DevkitServerStoreError ? error.message : "failed to persist devkit configuration"
|
|
42784
|
+
});
|
|
42785
|
+
process.exitCode = 1;
|
|
42786
|
+
return;
|
|
42787
|
+
}
|
|
42788
|
+
const outcome = config.configVersion === 1 ? "created" : "updated";
|
|
42789
|
+
const { daemonRunning, warning } = await resolveDaemonStatus(operationId);
|
|
42790
|
+
logger.info(
|
|
42791
|
+
LogEvent.DEVKIT_REGISTER_COMPLETED,
|
|
42792
|
+
devkitSentryExtra({
|
|
42793
|
+
operationId,
|
|
42794
|
+
phase: "completed",
|
|
42795
|
+
outcome,
|
|
42796
|
+
registrationId: String(config.configVersion),
|
|
42797
|
+
daemonRunning: String(daemonRunning),
|
|
42798
|
+
durationMs: Date.now() - startedAt
|
|
42799
|
+
})
|
|
42800
|
+
);
|
|
42801
|
+
outputSuccess(wantsJson, { daemonRunning, warning, configVersion: config.configVersion });
|
|
42802
|
+
} catch (error) {
|
|
42803
|
+
const detail = normalizeError2(error);
|
|
42804
|
+
logger.error(
|
|
42805
|
+
LogEvent.DEVKIT_REGISTER_REJECTED,
|
|
42806
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
42807
|
+
devkitSentryExtra({ operationId, phase: "rejected", reason: detail.field, durationMs: Date.now() - startedAt })
|
|
42808
|
+
);
|
|
42809
|
+
outputError2(wantsJson, detail);
|
|
42810
|
+
process.exitCode = 1;
|
|
42811
|
+
}
|
|
42812
|
+
}
|
|
42813
|
+
async function handleUnregister(args, wantsJson) {
|
|
42814
|
+
const operationId = (0, import_node_crypto9.randomUUID)();
|
|
42815
|
+
const startedAt = Date.now();
|
|
42816
|
+
logger.info(LogEvent.DEVKIT_UNREGISTER_REQUESTED, devkitSentryExtra({ operationId, phase: "requested" }));
|
|
42817
|
+
try {
|
|
42818
|
+
const parsed = parseArgs2(args, { options: /* @__PURE__ */ new Set(["url", "port"]), flags: /* @__PURE__ */ new Set(["json"]) });
|
|
42819
|
+
const rawOrigin = parsed.options.get("url")?.[0];
|
|
42820
|
+
const rawPort = parsed.options.get("port")?.[0];
|
|
42821
|
+
if (rawOrigin === void 0 !== (rawPort === void 0)) {
|
|
42822
|
+
throw new DevkitCliError("command", "--url and --port must be provided together");
|
|
42823
|
+
}
|
|
42824
|
+
const target = rawOrigin === void 0 || rawPort === void 0 ? void 0 : normalizeDevkitTarget(rawOrigin, parsePortValue(rawPort));
|
|
42825
|
+
let result;
|
|
42826
|
+
try {
|
|
42827
|
+
const store = DevkitServerStore.openForWrite();
|
|
42828
|
+
try {
|
|
42829
|
+
result = store.unregister(target);
|
|
42830
|
+
} finally {
|
|
42831
|
+
store.close();
|
|
42832
|
+
}
|
|
42833
|
+
} catch (error) {
|
|
42834
|
+
logger.error(
|
|
42835
|
+
LogEvent.DEVKIT_CONFIG_PERSIST_FAILED,
|
|
42836
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
42837
|
+
devkitSentryExtra({ operationId, phase: "persist_failed", durationMs: Date.now() - startedAt })
|
|
42838
|
+
);
|
|
42839
|
+
outputError2(wantsJson, {
|
|
42840
|
+
field: "config",
|
|
42841
|
+
reason: error instanceof DevkitServerStoreError ? error.message : "failed to persist devkit configuration"
|
|
42842
|
+
});
|
|
42843
|
+
process.exitCode = 1;
|
|
42844
|
+
return;
|
|
42845
|
+
}
|
|
42846
|
+
const outcome = result.removed ? "removed" : "noop";
|
|
42847
|
+
const { daemonRunning, warning } = await resolveDaemonStatus(operationId);
|
|
42848
|
+
logger.info(
|
|
42849
|
+
LogEvent.DEVKIT_UNREGISTER_COMPLETED,
|
|
42850
|
+
devkitSentryExtra({
|
|
42851
|
+
operationId,
|
|
42852
|
+
phase: "completed",
|
|
42853
|
+
outcome,
|
|
42854
|
+
removedCount: result.removedCount,
|
|
42855
|
+
...target ? { targetOrigin: target.origin, targetPort: target.port } : {},
|
|
42856
|
+
daemonRunning: String(daemonRunning),
|
|
42857
|
+
durationMs: Date.now() - startedAt
|
|
42858
|
+
})
|
|
42859
|
+
);
|
|
42860
|
+
outputSuccess(wantsJson, { daemonRunning, warning, removedCount: result.removedCount });
|
|
42861
|
+
} catch (error) {
|
|
42862
|
+
const detail = normalizeError2(error);
|
|
42863
|
+
logger.error(
|
|
42864
|
+
LogEvent.DEVKIT_REGISTER_REJECTED,
|
|
42865
|
+
error instanceof Error ? error : new Error(String(error)),
|
|
42866
|
+
devkitSentryExtra({ operationId, phase: "rejected", reason: detail.field, durationMs: Date.now() - startedAt })
|
|
42867
|
+
);
|
|
42868
|
+
outputError2(wantsJson, detail);
|
|
42869
|
+
process.exitCode = 1;
|
|
42870
|
+
}
|
|
42871
|
+
}
|
|
42872
|
+
async function resolveDaemonStatus(operationId) {
|
|
42873
|
+
try {
|
|
42874
|
+
const status = await getDaemonStatus();
|
|
42875
|
+
if (status.running) {
|
|
42876
|
+
return { daemonRunning: true };
|
|
42877
|
+
}
|
|
42878
|
+
return {
|
|
42879
|
+
daemonRunning: false,
|
|
42880
|
+
warning: { code: "DAEMON_NOT_RUNNING", message: DAEMON_NOT_RUNNING_MESSAGE }
|
|
42881
|
+
};
|
|
42882
|
+
} catch {
|
|
42883
|
+
logger.info(LogEvent.DEVKIT_DAEMON_STATUS_UNKNOWN, devkitSentryExtra({ operationId, phase: "status_unknown" }));
|
|
42884
|
+
return {
|
|
42885
|
+
daemonRunning: null,
|
|
42886
|
+
warning: { code: "DAEMON_STATUS_UNKNOWN", message: DAEMON_STATUS_UNKNOWN_MESSAGE }
|
|
42887
|
+
};
|
|
42888
|
+
}
|
|
42889
|
+
}
|
|
42890
|
+
function parsePortValue(raw) {
|
|
42891
|
+
if (!/^(0|[1-9][0-9]*)$/.test(raw)) {
|
|
42892
|
+
throw new DevkitCliError("port", "--port must be an integer between 1 and 65535");
|
|
42893
|
+
}
|
|
42894
|
+
return Number(raw);
|
|
42895
|
+
}
|
|
42896
|
+
function validatePaths(raw) {
|
|
42897
|
+
let parsed;
|
|
42898
|
+
try {
|
|
42899
|
+
parsed = JSON.parse(raw);
|
|
42900
|
+
} catch {
|
|
42901
|
+
throw new DevkitCliError("paths", "--paths must be valid JSON");
|
|
42902
|
+
}
|
|
42903
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
42904
|
+
throw new DevkitCliError("paths", "--paths must be a JSON object");
|
|
42905
|
+
}
|
|
42906
|
+
const record = parsed;
|
|
42907
|
+
const keys = Object.keys(record);
|
|
42908
|
+
if (keys.length !== 2 || !keys.includes("event") || !keys.includes("health")) {
|
|
42909
|
+
throw new DevkitCliError("paths", '--paths must contain exactly the keys "event" and "health"');
|
|
42910
|
+
}
|
|
42911
|
+
const eventPath = validatePathValue(record.event, "event");
|
|
42912
|
+
const healthPath = validatePathValue(record.health, "health");
|
|
42913
|
+
return { eventPath, healthPath };
|
|
42914
|
+
}
|
|
42915
|
+
function validatePathValue(value, key) {
|
|
42916
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
42917
|
+
throw new DevkitCliError("paths", `--paths.${key} must be a non-empty string`);
|
|
42918
|
+
}
|
|
42919
|
+
if (!value.startsWith("/") || value.startsWith("//")) {
|
|
42920
|
+
throw new DevkitCliError("paths", `--paths.${key} must start with a single "/"`);
|
|
42921
|
+
}
|
|
42922
|
+
if (value.includes("\\") || value.includes("?") || value.includes("#") || value.includes("..")) {
|
|
42923
|
+
throw new DevkitCliError(
|
|
42924
|
+
"paths",
|
|
42925
|
+
`--paths.${key} must not contain a query, fragment, backslash, "..", or an absolute URL`
|
|
42926
|
+
);
|
|
42927
|
+
}
|
|
42928
|
+
if (/^\/[a-zA-Z][a-zA-Z0-9+.-]*:/.test(value)) {
|
|
42929
|
+
throw new DevkitCliError("paths", `--paths.${key} must not be an absolute URL`);
|
|
42930
|
+
}
|
|
42931
|
+
return value;
|
|
42932
|
+
}
|
|
42933
|
+
function parseArgs2(args, spec) {
|
|
42934
|
+
const options = /* @__PURE__ */ new Map();
|
|
42935
|
+
const flags = /* @__PURE__ */ new Set();
|
|
42936
|
+
for (let index2 = 0; index2 < args.length; index2 += 1) {
|
|
42937
|
+
const token = args[index2];
|
|
42938
|
+
if (!token.startsWith("--")) {
|
|
42939
|
+
throw new DevkitCliError("command", `unexpected positional argument: ${token}`);
|
|
42940
|
+
}
|
|
42941
|
+
const name = token.slice(2);
|
|
42942
|
+
if (spec.flags.has(name)) {
|
|
42943
|
+
if (flags.has(name)) {
|
|
42944
|
+
throw new DevkitCliError("command", `${token} must not be repeated`);
|
|
42945
|
+
}
|
|
42946
|
+
flags.add(name);
|
|
42947
|
+
continue;
|
|
42948
|
+
}
|
|
42949
|
+
if (!spec.options.has(name)) {
|
|
42950
|
+
throw new DevkitCliError("command", `unknown option ${token}`);
|
|
42951
|
+
}
|
|
42952
|
+
if (index2 + 1 >= args.length) {
|
|
42953
|
+
throw new DevkitCliError("command", `${token} requires a value`);
|
|
42954
|
+
}
|
|
42955
|
+
const value = args[++index2];
|
|
42956
|
+
if (value.startsWith("--")) {
|
|
42957
|
+
throw new DevkitCliError("command", `${token} requires a value`);
|
|
42958
|
+
}
|
|
42959
|
+
if (options.has(name)) {
|
|
42960
|
+
throw new DevkitCliError("command", `${token} must not be repeated`);
|
|
42961
|
+
}
|
|
42962
|
+
options.set(name, [value]);
|
|
42963
|
+
}
|
|
42964
|
+
return { options, flags };
|
|
42965
|
+
}
|
|
42966
|
+
function requireOption(parsed, name) {
|
|
42967
|
+
const value = parsed.options.get(name)?.[0];
|
|
42968
|
+
if (value === void 0 || value.length === 0) {
|
|
42969
|
+
throw new DevkitCliError(name, `--${name} is required`);
|
|
42970
|
+
}
|
|
42971
|
+
return value;
|
|
42972
|
+
}
|
|
42973
|
+
function outputSuccess(json, result) {
|
|
42974
|
+
if (json) {
|
|
42975
|
+
console.log(JSON.stringify({
|
|
42976
|
+
ok: true,
|
|
42977
|
+
daemonRunning: result.daemonRunning,
|
|
42978
|
+
...result.warning ? { warning: result.warning } : {},
|
|
42979
|
+
...result.configVersion === void 0 ? {} : { configVersion: result.configVersion },
|
|
42980
|
+
...result.removedCount === void 0 ? {} : { removedCount: result.removedCount }
|
|
42981
|
+
}));
|
|
42982
|
+
return;
|
|
42983
|
+
}
|
|
42984
|
+
const daemonText = result.daemonRunning === null ? "unknown" : String(result.daemonRunning);
|
|
42985
|
+
console.log(`ok=true daemonRunning=${daemonText}${result.warning ? ` warning=${result.warning.code}` : ""}${result.removedCount === void 0 ? "" : ` removedCount=${result.removedCount}`}`);
|
|
42986
|
+
if (result.warning) {
|
|
42987
|
+
console.log(result.warning.message);
|
|
42988
|
+
}
|
|
42989
|
+
}
|
|
42990
|
+
function outputError2(json, detail) {
|
|
42991
|
+
if (json) {
|
|
42992
|
+
console.log(JSON.stringify({ ok: false, error: detail.reason }));
|
|
42993
|
+
return;
|
|
42994
|
+
}
|
|
42995
|
+
console.error(`ok=false field=${detail.field} error=${detail.reason}`);
|
|
42996
|
+
}
|
|
42997
|
+
function normalizeError2(error) {
|
|
42998
|
+
if (error instanceof DevkitCliError) {
|
|
42999
|
+
return error.toValidationError();
|
|
43000
|
+
}
|
|
43001
|
+
if (error instanceof DevkitTargetError) {
|
|
43002
|
+
return { field: error.field, reason: error.message };
|
|
43003
|
+
}
|
|
43004
|
+
if (error instanceof DevkitServerStoreError) {
|
|
43005
|
+
return { field: "config", reason: error.message };
|
|
43006
|
+
}
|
|
43007
|
+
return { field: "unknown", reason: error instanceof Error ? error.message : String(error) };
|
|
43008
|
+
}
|
|
43009
|
+
function devkitSentryExtra(extra) {
|
|
43010
|
+
const normalized = { component: "node_devkit" };
|
|
43011
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
43012
|
+
if (value !== void 0) {
|
|
43013
|
+
normalized[key] = String(value);
|
|
43014
|
+
}
|
|
43015
|
+
}
|
|
43016
|
+
return normalized;
|
|
43017
|
+
}
|
|
43018
|
+
function isHelpArg2(value) {
|
|
43019
|
+
return value === "help" || value === "-h" || value === "--help";
|
|
43020
|
+
}
|
|
43021
|
+
var import_node_crypto9, DAEMON_NOT_RUNNING_MESSAGE, DAEMON_STATUS_UNKNOWN_MESSAGE, DevkitCliError;
|
|
43022
|
+
var init_devkit_cli = __esm({
|
|
43023
|
+
"src/devkit-cli.ts"() {
|
|
43024
|
+
"use strict";
|
|
43025
|
+
import_node_crypto9 = require("node:crypto");
|
|
43026
|
+
init_daemon();
|
|
43027
|
+
init_devkit_server_store();
|
|
43028
|
+
init_devkit_target();
|
|
43029
|
+
init_sentry_logger();
|
|
43030
|
+
DAEMON_NOT_RUNNING_MESSAGE = "\u5F53\u524D daemon \u672A\u8FD0\u884C,\u8BF7\u4F7F\u7528 okx-a2a start \u542F\u52A8 daemon";
|
|
43031
|
+
DAEMON_STATUS_UNKNOWN_MESSAGE = "\u914D\u7F6E\u5DF2\u5199\u5165,\u4F46\u65E0\u6CD5\u786E\u8BA4 daemon \u8FD0\u884C\u72B6\u6001";
|
|
43032
|
+
DevkitCliError = class extends Error {
|
|
43033
|
+
field;
|
|
43034
|
+
constructor(field, reason) {
|
|
43035
|
+
super(reason);
|
|
43036
|
+
this.name = "DevkitCliError";
|
|
43037
|
+
this.field = field;
|
|
43038
|
+
}
|
|
43039
|
+
toValidationError() {
|
|
43040
|
+
return { field: this.field, reason: this.message };
|
|
43041
|
+
}
|
|
43042
|
+
};
|
|
43043
|
+
}
|
|
43044
|
+
});
|
|
43045
|
+
|
|
42241
43046
|
// ../core/src/xmtp-sdk/client-lifecycle.ts
|
|
42242
43047
|
async function stopAndCloseXmtpClient(agent, ctx) {
|
|
42243
43048
|
let stopped = true;
|
|
@@ -42383,7 +43188,7 @@ function isResolvedBinUsable(bin) {
|
|
|
42383
43188
|
if (!isPathLikeCommand(bin)) {
|
|
42384
43189
|
return true;
|
|
42385
43190
|
}
|
|
42386
|
-
return process.platform === "win32" ? (0,
|
|
43191
|
+
return process.platform === "win32" ? (0, import_node_fs23.existsSync)(bin) : isExecutable2(bin);
|
|
42387
43192
|
}
|
|
42388
43193
|
function resolvePosixBareCommand(command, pathValue) {
|
|
42389
43194
|
for (const dir of pathValue.split(":")) {
|
|
@@ -42720,7 +43525,7 @@ function isWindowsAppsAlias(candidate) {
|
|
|
42720
43525
|
return candidate.toLowerCase().includes(WINDOWS_APPS_ALIAS_MARKER);
|
|
42721
43526
|
}
|
|
42722
43527
|
function win32FileExists(path2) {
|
|
42723
|
-
return (0,
|
|
43528
|
+
return (0, import_node_fs23.existsSync)(path2);
|
|
42724
43529
|
}
|
|
42725
43530
|
function pickOnchainosWin32Candidate(lines, fileExists2 = win32FileExists) {
|
|
42726
43531
|
const candidates = lines.map((line) => {
|
|
@@ -42776,7 +43581,7 @@ function extractExecutablePath(stdout) {
|
|
|
42776
43581
|
}
|
|
42777
43582
|
function isExecutable2(path2) {
|
|
42778
43583
|
try {
|
|
42779
|
-
(0,
|
|
43584
|
+
(0, import_node_fs23.accessSync)(path2, import_node_fs23.constants.X_OK);
|
|
42780
43585
|
return true;
|
|
42781
43586
|
} catch {
|
|
42782
43587
|
return false;
|
|
@@ -42881,12 +43686,12 @@ async function exec(args, options = {}) {
|
|
|
42881
43686
|
}
|
|
42882
43687
|
throw new Error("OnchainOS command retry exhausted");
|
|
42883
43688
|
}
|
|
42884
|
-
var
|
|
43689
|
+
var import_node_fs23, import_node_child_process8, import_node_path25, import_node_util2, execFileAsync2, resolvedBin, resolvedForEnvBin, resolverRevision, versionProbeInFlight, posixDiscoveryFlights, REDACTED_VALUE_FLAGS, COMMAND_UNAVAILABLE_CODES, ONCHAINOS_VERSION_PROBE_TIMEOUT_MS, ONCHAINOS_BIN_RESOLVE_TIMEOUT_MS, WINDOWS_APPS_ALIAS_MARKER;
|
|
42885
43690
|
var init_bin = __esm({
|
|
42886
43691
|
"../core/src/xmtp-sdk/onchainos/bin.ts"() {
|
|
42887
43692
|
"use strict";
|
|
42888
43693
|
init_log();
|
|
42889
|
-
|
|
43694
|
+
import_node_fs23 = require("node:fs");
|
|
42890
43695
|
import_node_child_process8 = require("node:child_process");
|
|
42891
43696
|
import_node_path25 = require("node:path");
|
|
42892
43697
|
import_node_util2 = require("node:util");
|
|
@@ -42950,12 +43755,12 @@ function createAsyncStreamProxy(stream) {
|
|
|
42950
43755
|
}
|
|
42951
43756
|
});
|
|
42952
43757
|
}
|
|
42953
|
-
var import_node_bindings, import_node_bindings2,
|
|
43758
|
+
var import_node_bindings, import_node_bindings2, import_node_crypto10, import_types, import_node_path26, import_node_process, HistorySyncUrls, envMap, reverseEnvMap, envToString, createBackend, InboxReassignError, AccountAlreadyAssociatedError, MissingContentTypeError, SignerUnavailableError, ClientNotInitializedError, StreamFailedError, StreamInvalidRetryAttemptsError, generateInboxId, getInboxIdForIdentifier, isReaction, isReply, isText, isRemoteAttachment, isAttachment, isMultiRemoteAttachment, isTransactionReference, isGroupUpdated, isReadReceipt, isLeaveRequest, isWalletSendCalls, isIntent, isActions, isMarkdown, CodecRegistry, getContentFromDecodedMessageContent, getContentTypeFromDecodedMessageContent, DecodedMessage, AsyncStream, usableProperties, isUsableProperty, DEFAULT_RETRY_DELAY, DEFAULT_RETRY_ATTEMPTS, createStream, Conversation, Dm, Group, Conversations, DebugInformation, Preferences, networkOptionKeys, hasBackend, resolveBackend$1, createClient, resolveBackend, createEphemeralIdentifier, toInboxUpdatesCountMap, Client;
|
|
42954
43759
|
var init_dist2 = __esm({
|
|
42955
43760
|
"../../node_modules/@xmtp/node-sdk/dist/index.js"() {
|
|
42956
43761
|
import_node_bindings = require("@xmtp/node-bindings");
|
|
42957
43762
|
import_node_bindings2 = require("@xmtp/node-bindings");
|
|
42958
|
-
|
|
43763
|
+
import_node_crypto10 = require("node:crypto");
|
|
42959
43764
|
init_dist();
|
|
42960
43765
|
import_types = require("node:util/types");
|
|
42961
43766
|
import_node_path26 = require("node:path");
|
|
@@ -44717,7 +45522,7 @@ var init_dist2 = __esm({
|
|
|
44717
45522
|
return createBackend({ env: envOrBackend, gatewayHost });
|
|
44718
45523
|
};
|
|
44719
45524
|
createEphemeralIdentifier = () => ({
|
|
44720
|
-
identifier: `0x${(0,
|
|
45525
|
+
identifier: `0x${(0, import_node_crypto10.randomBytes)(20).toString("hex")}`,
|
|
44721
45526
|
identifierKind: 0
|
|
44722
45527
|
});
|
|
44723
45528
|
toInboxUpdatesCountMap = (value) => {
|
|
@@ -56966,20 +57771,20 @@ async function createRemoteAttachmentFromFile(unencryptedFile, uploadCallback) {
|
|
|
56966
57771
|
const fileUrl = await uploadCallback(encryptedAttachment);
|
|
56967
57772
|
return createRemoteAttachment(encryptedAttachment, fileUrl);
|
|
56968
57773
|
}
|
|
56969
|
-
var import_node_events,
|
|
57774
|
+
var import_node_events, import_node_fs24, import_node_path27, import_ts_retry_promise, import_node_crypto11, version2, fromSelf, hasContent, isDM, isGroup, isGroupAdmin, isGroupSuperAdmin, usesCodec, filter, validLogLevels, isLogLevel, getValidLogLevels, parseLogLevel, logDetails, getInstallationInfo, createUser, createIdentifier, createSigner, AgentError, AgentStreamingError, ClientContext, ConversationContext, MessageContext, Agent, CANCEL_ACTION_ID, LimitedMap, cache;
|
|
56970
57775
|
var init_dist4 = __esm({
|
|
56971
57776
|
"../../node_modules/@xmtp/agent-sdk/dist/index.js"() {
|
|
56972
57777
|
init_dist2();
|
|
56973
57778
|
init_dist2();
|
|
56974
57779
|
import_node_events = __toESM(require("node:events"), 1);
|
|
56975
|
-
|
|
57780
|
+
import_node_fs24 = __toESM(require("node:fs"), 1);
|
|
56976
57781
|
import_node_path27 = __toESM(require("node:path"), 1);
|
|
56977
57782
|
import_ts_retry_promise = __toESM(require_retry_promise(), 1);
|
|
56978
57783
|
init_dist3();
|
|
56979
57784
|
init_esm();
|
|
56980
57785
|
init_accounts();
|
|
56981
57786
|
init_chains();
|
|
56982
|
-
|
|
57787
|
+
import_node_crypto11 = require("node:crypto");
|
|
56983
57788
|
version2 = "2.3.1";
|
|
56984
57789
|
fromSelf = (message, client) => {
|
|
56985
57790
|
return message.senderInboxId === client.inboxId;
|
|
@@ -57339,7 +58144,7 @@ var init_dist4 = __esm({
|
|
|
57339
58144
|
initializedOptions.gatewayHost = XMTP_GATEWAY_HOST;
|
|
57340
58145
|
}
|
|
57341
58146
|
if (typeof XMTP_DB_DIRECTORY === "string") {
|
|
57342
|
-
|
|
58147
|
+
import_node_fs24.default.mkdirSync(XMTP_DB_DIRECTORY, { recursive: true, mode: 448 });
|
|
57343
58148
|
initializedOptions.dbPath = (inboxId) => {
|
|
57344
58149
|
const dbPath = import_node_path27.default.join(XMTP_DB_DIRECTORY, `xmtp-${inboxId}.db3`);
|
|
57345
58150
|
console.info(`Saving local database to "${dbPath}"`);
|
|
@@ -57649,7 +58454,7 @@ var init_dist4 = __esm({
|
|
|
57649
58454
|
return this.#client.accountIdentifier?.identifier;
|
|
57650
58455
|
}
|
|
57651
58456
|
};
|
|
57652
|
-
CANCEL_ACTION_ID = (0,
|
|
58457
|
+
CANCEL_ACTION_ID = (0, import_node_crypto11.randomUUID)();
|
|
57653
58458
|
LimitedMap = class {
|
|
57654
58459
|
#map = /* @__PURE__ */ new Map();
|
|
57655
58460
|
#limit;
|
|
@@ -58575,10 +59380,10 @@ function ensureCacheDir(dataDir) {
|
|
|
58575
59380
|
function loadSensitiveWordsFromCache(dataDir) {
|
|
58576
59381
|
try {
|
|
58577
59382
|
const path2 = cachePath(dataDir, "sensitive-words.json");
|
|
58578
|
-
if (!(0,
|
|
59383
|
+
if (!(0, import_node_fs25.existsSync)(path2)) {
|
|
58579
59384
|
return null;
|
|
58580
59385
|
}
|
|
58581
|
-
const data = JSON.parse((0,
|
|
59386
|
+
const data = JSON.parse((0, import_node_fs25.readFileSync)(path2, "utf-8"));
|
|
58582
59387
|
if (Array.isArray(data)) {
|
|
58583
59388
|
return data;
|
|
58584
59389
|
}
|
|
@@ -58592,7 +59397,7 @@ function loadSensitiveWordsFromCache(dataDir) {
|
|
|
58592
59397
|
function saveSensitiveWordsToCache(dataDir, words) {
|
|
58593
59398
|
try {
|
|
58594
59399
|
ensureCacheDir(dataDir);
|
|
58595
|
-
(0,
|
|
59400
|
+
(0, import_node_fs25.writeFileSync)(cachePath(dataDir, "sensitive-words.json"), JSON.stringify(words));
|
|
58596
59401
|
} catch (err2) {
|
|
58597
59402
|
logWithTimestamp(`[xmtp-sdk] failed to write sensitive-words.json:`, err2);
|
|
58598
59403
|
logger.error(LogEvent.CACHE_WRITE_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), { cacheName: "sensitive-words" });
|
|
@@ -58634,10 +59439,10 @@ async function loadSensitiveWordsWith(dataDir, fetcher) {
|
|
|
58634
59439
|
function loadSystemConfigFromCache(dataDir) {
|
|
58635
59440
|
try {
|
|
58636
59441
|
const path2 = cachePath(dataDir, "system-config.json");
|
|
58637
|
-
if (!(0,
|
|
59442
|
+
if (!(0, import_node_fs25.existsSync)(path2)) {
|
|
58638
59443
|
return null;
|
|
58639
59444
|
}
|
|
58640
|
-
const data = JSON.parse((0,
|
|
59445
|
+
const data = JSON.parse((0, import_node_fs25.readFileSync)(path2, "utf-8"));
|
|
58641
59446
|
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
58642
59447
|
return data;
|
|
58643
59448
|
}
|
|
@@ -58651,7 +59456,7 @@ function loadSystemConfigFromCache(dataDir) {
|
|
|
58651
59456
|
function saveSystemConfigToCache(dataDir, config) {
|
|
58652
59457
|
try {
|
|
58653
59458
|
ensureCacheDir(dataDir);
|
|
58654
|
-
(0,
|
|
59459
|
+
(0, import_node_fs25.writeFileSync)(cachePath(dataDir, "system-config.json"), JSON.stringify(config));
|
|
58655
59460
|
} catch (err2) {
|
|
58656
59461
|
logWithTimestamp(`[xmtp-sdk] failed to write system-config.json:`, err2);
|
|
58657
59462
|
logger.error(LogEvent.CACHE_WRITE_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), { cacheName: "system-config" });
|
|
@@ -58701,10 +59506,10 @@ function loadSyncByAddress(dataDir) {
|
|
|
58701
59506
|
const map = /* @__PURE__ */ new Map();
|
|
58702
59507
|
try {
|
|
58703
59508
|
const path2 = cachePath(dataDir, "last-sync.json");
|
|
58704
|
-
if (!(0,
|
|
59509
|
+
if (!(0, import_node_fs25.existsSync)(path2)) {
|
|
58705
59510
|
return map;
|
|
58706
59511
|
}
|
|
58707
|
-
const data = JSON.parse((0,
|
|
59512
|
+
const data = JSON.parse((0, import_node_fs25.readFileSync)(path2, "utf-8"));
|
|
58708
59513
|
const obj = data?.syncByAddress;
|
|
58709
59514
|
if (obj && typeof obj === "object" && !Array.isArray(obj)) {
|
|
58710
59515
|
for (const [addr, ts] of Object.entries(obj)) {
|
|
@@ -58723,9 +59528,9 @@ function saveSyncForAddress(dataDir, address, timestampMs) {
|
|
|
58723
59528
|
try {
|
|
58724
59529
|
let data = {};
|
|
58725
59530
|
const path2 = cachePath(dataDir, "last-sync.json");
|
|
58726
|
-
if ((0,
|
|
59531
|
+
if ((0, import_node_fs25.existsSync)(path2)) {
|
|
58727
59532
|
try {
|
|
58728
|
-
const raw = JSON.parse((0,
|
|
59533
|
+
const raw = JSON.parse((0, import_node_fs25.readFileSync)(path2, "utf-8"));
|
|
58729
59534
|
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
58730
59535
|
data = raw;
|
|
58731
59536
|
}
|
|
@@ -58736,7 +59541,7 @@ function saveSyncForAddress(dataDir, address, timestampMs) {
|
|
|
58736
59541
|
data.syncByAddress = {};
|
|
58737
59542
|
}
|
|
58738
59543
|
data.syncByAddress[address] = timestampMs;
|
|
58739
|
-
(0,
|
|
59544
|
+
(0, import_node_fs25.writeFileSync)(path2, JSON.stringify(data, null, 2));
|
|
58740
59545
|
} catch (err2) {
|
|
58741
59546
|
logWithTimestamp(
|
|
58742
59547
|
`[xmtp-sdk] failed to write last-sync.json (address=${address}):`,
|
|
@@ -58958,12 +59763,12 @@ function createOfflineReplayAddressSummary(address) {
|
|
|
58958
59763
|
durationMs: 0
|
|
58959
59764
|
};
|
|
58960
59765
|
}
|
|
58961
|
-
var
|
|
59766
|
+
var import_node_fs25, import_node_path28, DEFAULT_DATA_DIR, XMTP_INSTALLATION_WARNING_THRESHOLD, XMTP_INSTALLATION_NEAR_LIMIT_THRESHOLD, REPLAY_SCAN_INITIAL_BACKOFF_MS, REPLAY_SCAN_MAX_BACKOFF_MS, SENSITIVE_WORDS_LAZY_RETRY_COOLDOWN_MS, InboundReplayGate, SYSTEM_CONFIG_DEFAULTS, STREAM_RECOVERY_ALERT_THRESHOLD_MS, STREAM_RECOVERY_STABILITY_WINDOW_MS, REPLAY_GATE_DRAIN_MAX_ATTEMPTS, REPLAY_GATE_DRAIN_RETRY_DELAY_MS, SEMVER_RE, isRecord5, isPositiveNumber, SYSTEM_CONFIG_VALIDATORS, XmtpClientCreateBlockedError, XmtpService;
|
|
58962
59767
|
var init_xmtp_sdk = __esm({
|
|
58963
59768
|
"../core/src/xmtp-sdk/index.ts"() {
|
|
58964
59769
|
"use strict";
|
|
58965
59770
|
init_log();
|
|
58966
|
-
|
|
59771
|
+
import_node_fs25 = require("node:fs");
|
|
58967
59772
|
import_node_path28 = require("node:path");
|
|
58968
59773
|
init_dist4();
|
|
58969
59774
|
init_dist2();
|
|
@@ -62607,7 +63412,7 @@ var init_envelope = __esm({
|
|
|
62607
63412
|
});
|
|
62608
63413
|
|
|
62609
63414
|
// src/invalid-message-store.ts
|
|
62610
|
-
function
|
|
63415
|
+
function loadSqlite6() {
|
|
62611
63416
|
const originalEmitWarning = process.emitWarning;
|
|
62612
63417
|
process.emitWarning = ((warning, ...args) => {
|
|
62613
63418
|
const message = typeof warning === "string" ? warning : warning.message;
|
|
@@ -62622,22 +63427,22 @@ function loadSqlite5() {
|
|
|
62622
63427
|
process.emitWarning = originalEmitWarning;
|
|
62623
63428
|
}
|
|
62624
63429
|
}
|
|
62625
|
-
var
|
|
63430
|
+
var import_node_fs26, import_node_path29, DatabaseSync5, InvalidXmtpMessageStore;
|
|
62626
63431
|
var init_invalid_message_store = __esm({
|
|
62627
63432
|
"src/invalid-message-store.ts"() {
|
|
62628
63433
|
"use strict";
|
|
62629
|
-
|
|
63434
|
+
import_node_fs26 = require("node:fs");
|
|
62630
63435
|
import_node_path29 = require("node:path");
|
|
62631
63436
|
init_paths();
|
|
62632
|
-
({ DatabaseSync:
|
|
63437
|
+
({ DatabaseSync: DatabaseSync5 } = loadSqlite6());
|
|
62633
63438
|
InvalidXmtpMessageStore = class {
|
|
62634
63439
|
dbPath;
|
|
62635
63440
|
db;
|
|
62636
63441
|
constructor(homeDir) {
|
|
62637
63442
|
const paths = resolveTaskPaths(homeDir);
|
|
62638
63443
|
this.dbPath = (0, import_node_path29.join)(paths.sqliteDir, "invalid-xmtp-messages.sqlite");
|
|
62639
|
-
(0,
|
|
62640
|
-
this.db = new
|
|
63444
|
+
(0, import_node_fs26.mkdirSync)((0, import_node_path29.dirname)(this.dbPath), { recursive: true });
|
|
63445
|
+
this.db = new DatabaseSync5(this.dbPath);
|
|
62641
63446
|
this.ensureReady();
|
|
62642
63447
|
}
|
|
62643
63448
|
close() {
|
|
@@ -63013,14 +63818,14 @@ function buildSystemMessageIdempotencyKey(input) {
|
|
|
63013
63818
|
return `system-message:${identity}`;
|
|
63014
63819
|
}
|
|
63015
63820
|
function stableHash(value) {
|
|
63016
|
-
return (0,
|
|
63821
|
+
return (0, import_node_crypto12.createHash)("sha256").update(value).digest("hex").slice(0, 24);
|
|
63017
63822
|
}
|
|
63018
|
-
var
|
|
63823
|
+
var import_node_crypto12, DIRECTION_PREFIX, CONTENT_SEPARATOR, ADDRESS_SHORT_HEAD, ADDRESS_SHORT_TAIL, JOB_ID_HEAD, JOB_ID_TAIL, ELLIPSIS, CONTENT_MAX_LINES;
|
|
63019
63824
|
var init_agent_message_notice = __esm({
|
|
63020
63825
|
"src/agent-message-notice.ts"() {
|
|
63021
63826
|
"use strict";
|
|
63022
63827
|
init_log();
|
|
63023
|
-
|
|
63828
|
+
import_node_crypto12 = require("node:crypto");
|
|
63024
63829
|
init_session_store();
|
|
63025
63830
|
init_ai_provider();
|
|
63026
63831
|
init_outbound_behavior();
|
|
@@ -63503,7 +64308,7 @@ async function handleSqliteGroupSendCommand(params) {
|
|
|
63503
64308
|
role: senderAgent?.role,
|
|
63504
64309
|
sendDurationMs: Date.now() - sendStartMs
|
|
63505
64310
|
});
|
|
63506
|
-
const messageId = `outbound-${(0,
|
|
64311
|
+
const messageId = `outbound-${(0, import_node_crypto13.randomUUID)()}`;
|
|
63507
64312
|
await notifyAgentMessageToUserAttention({
|
|
63508
64313
|
direction: "outbound" /* OUTBOUND */,
|
|
63509
64314
|
sender: {
|
|
@@ -63624,7 +64429,7 @@ async function handleGroupSendCommand(params) {
|
|
|
63624
64429
|
sendDurationMs: Date.now() - sendStartMs
|
|
63625
64430
|
});
|
|
63626
64431
|
const now = Date.now();
|
|
63627
|
-
const messageId = `outbound-${(0,
|
|
64432
|
+
const messageId = `outbound-${(0, import_node_crypto13.randomUUID)()}`;
|
|
63628
64433
|
const stored = {
|
|
63629
64434
|
id: messageId,
|
|
63630
64435
|
direction: "outbound",
|
|
@@ -63843,7 +64648,7 @@ async function handleXmtpSendCommand(params) {
|
|
|
63843
64648
|
sendDurationMs: Date.now() - sendStartMs
|
|
63844
64649
|
});
|
|
63845
64650
|
const now = Date.now();
|
|
63846
|
-
const messageId = `outbound-${(0,
|
|
64651
|
+
const messageId = `outbound-${(0, import_node_crypto13.randomUUID)()}`;
|
|
63847
64652
|
const stored = {
|
|
63848
64653
|
id: messageId,
|
|
63849
64654
|
direction: "outbound",
|
|
@@ -63889,14 +64694,14 @@ async function handleXmtpSendCommand(params) {
|
|
|
63889
64694
|
ownedStore?.close();
|
|
63890
64695
|
}
|
|
63891
64696
|
}
|
|
63892
|
-
var
|
|
64697
|
+
var import_node_crypto13, TASK_MIN_VERSION, sqliteGroupSessionPromises, conversationSyncPromises, XMTP_SEND_CHECKPOINT, resolvedAgentByIdCache;
|
|
63893
64698
|
var init_xmtp_send = __esm({
|
|
63894
64699
|
"src/xmtp-send.ts"() {
|
|
63895
64700
|
"use strict";
|
|
63896
64701
|
init_log();
|
|
63897
64702
|
init_sentry_logger();
|
|
63898
64703
|
init_log_fields();
|
|
63899
|
-
|
|
64704
|
+
import_node_crypto13 = require("node:crypto");
|
|
63900
64705
|
init_dist2();
|
|
63901
64706
|
init_envelope();
|
|
63902
64707
|
init_concurrency2();
|
|
@@ -64435,7 +65240,7 @@ function safeProcessCwd() {
|
|
|
64435
65240
|
}
|
|
64436
65241
|
function isDirectory(path2) {
|
|
64437
65242
|
try {
|
|
64438
|
-
return (0,
|
|
65243
|
+
return (0, import_node_fs27.statSync)(path2).isDirectory();
|
|
64439
65244
|
} catch {
|
|
64440
65245
|
return false;
|
|
64441
65246
|
}
|
|
@@ -65761,7 +66566,7 @@ function normalizeAttentionProvider(provider) {
|
|
|
65761
66566
|
return provider === "unknown" ? null : provider;
|
|
65762
66567
|
}
|
|
65763
66568
|
function stableHash2(value) {
|
|
65764
|
-
return (0,
|
|
66569
|
+
return (0, import_node_crypto14.createHash)("sha256").update(value).digest("hex").slice(0, 24);
|
|
65765
66570
|
}
|
|
65766
66571
|
function formatCommand(args) {
|
|
65767
66572
|
return args.map(shellQuote).join(" ");
|
|
@@ -65785,13 +66590,13 @@ function shortenJobId2(jobId) {
|
|
|
65785
66590
|
}
|
|
65786
66591
|
return `${jobId.slice(0, 6)}\u2026${jobId.slice(-4)}`;
|
|
65787
66592
|
}
|
|
65788
|
-
var
|
|
66593
|
+
var import_node_crypto14, import_node_fs27, import_promises12, import_node_os9, import_node_path31, AiRunner, CODEX_TOOL_FAILURE_MARKER;
|
|
65789
66594
|
var init_ai_runner = __esm({
|
|
65790
66595
|
"src/ai-runner.ts"() {
|
|
65791
66596
|
"use strict";
|
|
65792
66597
|
init_log();
|
|
65793
|
-
|
|
65794
|
-
|
|
66598
|
+
import_node_crypto14 = require("node:crypto");
|
|
66599
|
+
import_node_fs27 = require("node:fs");
|
|
65795
66600
|
import_promises12 = require("node:fs/promises");
|
|
65796
66601
|
import_node_os9 = require("node:os");
|
|
65797
66602
|
import_node_path31 = require("node:path");
|
|
@@ -65939,7 +66744,7 @@ var init_ai_runner = __esm({
|
|
|
65939
66744
|
ensureTaskDir(this.logsDir);
|
|
65940
66745
|
const lifecycleLogsEnabled = isAiLifecycleLoggingEnabled();
|
|
65941
66746
|
const logPath = lifecycleLogsEnabled ? this.buildRunLogPath(request) : "";
|
|
65942
|
-
const log = lifecycleLogsEnabled ? (0,
|
|
66747
|
+
const log = lifecycleLogsEnabled ? (0, import_node_fs27.createWriteStream)(logPath, { flags: "a" }) : null;
|
|
65943
66748
|
let existing = null;
|
|
65944
66749
|
let storeReadStartedAt;
|
|
65945
66750
|
let storeReadEndedAt;
|
|
@@ -68411,6 +69216,428 @@ var init_command_processor = __esm({
|
|
|
68411
69216
|
}
|
|
68412
69217
|
});
|
|
68413
69218
|
|
|
69219
|
+
// src/devkit-types.ts
|
|
69220
|
+
var DEVKIT_MAX_CONCURRENCY, DEVKIT_MAX_PENDING, DEVKIT_MAX_PENDING_BYTES, DEVKIT_MAX_MESSAGE_BYTES, DEVKIT_REQUEST_BUDGET_MS, DEVKIT_RESPONSE_DIAGNOSTIC_MAX_BYTES, DEVKIT_RESPONSE_SUMMARY_MAX_CHARS, DEVKIT_OUTCOME, DEVKIT_DROP_REASON;
|
|
69221
|
+
var init_devkit_types = __esm({
|
|
69222
|
+
"src/devkit-types.ts"() {
|
|
69223
|
+
"use strict";
|
|
69224
|
+
DEVKIT_MAX_CONCURRENCY = 16;
|
|
69225
|
+
DEVKIT_MAX_PENDING = 256;
|
|
69226
|
+
DEVKIT_MAX_PENDING_BYTES = 16 * 1024 * 1024;
|
|
69227
|
+
DEVKIT_MAX_MESSAGE_BYTES = 1 * 1024 * 1024;
|
|
69228
|
+
DEVKIT_REQUEST_BUDGET_MS = 5e3;
|
|
69229
|
+
DEVKIT_RESPONSE_DIAGNOSTIC_MAX_BYTES = 4 * 1024;
|
|
69230
|
+
DEVKIT_RESPONSE_SUMMARY_MAX_CHARS = 256;
|
|
69231
|
+
DEVKIT_OUTCOME = {
|
|
69232
|
+
HTTP_ACCEPTED: "http_accepted",
|
|
69233
|
+
DROPPED: "dropped"
|
|
69234
|
+
};
|
|
69235
|
+
DEVKIT_DROP_REASON = {
|
|
69236
|
+
REQUEST_TOO_LARGE: "request_too_large",
|
|
69237
|
+
// serialized > 1 MiB (FR-3-AC-6)
|
|
69238
|
+
PENDING_OVERFLOW: "pending_overflow",
|
|
69239
|
+
// > 256 items or > 16 MiB total pending (NFR-2-AC-1)
|
|
69240
|
+
CONFIG_CHANGED: "config_changed",
|
|
69241
|
+
// snapshot version changed/removed before send (FR-2-AC-6)
|
|
69242
|
+
CONFIG_READ_FAILED: "config_read_failed",
|
|
69243
|
+
// snapshot unreadable/corrupt (FR-2-AC-5)
|
|
69244
|
+
HTTP_STATUS: "http_status",
|
|
69245
|
+
// non-2xx response (FR-3-AC-3)
|
|
69246
|
+
REDIRECT_BLOCKED: "redirect_blocked",
|
|
69247
|
+
// 3xx response, not followed (NFR-3-AC-2)
|
|
69248
|
+
CONNECTION_FAILED: "connection_failed",
|
|
69249
|
+
// ECONNREFUSED / reset / unreachable (FR-3-AC-4)
|
|
69250
|
+
TIMEOUT: "timeout",
|
|
69251
|
+
// exceeded the 5 s budget (FR-3-AC-4)
|
|
69252
|
+
REQUEST_BUILD_ERROR: "request_build_error",
|
|
69253
|
+
// serialization / target build failure
|
|
69254
|
+
RESPONSE_READ_ERROR: "response_read_error",
|
|
69255
|
+
// diagnostic read failure
|
|
69256
|
+
SHUTDOWN_CANCELLED: "shutdown_cancelled"
|
|
69257
|
+
// daemon stopped before send (NFR-2-AC-3)
|
|
69258
|
+
};
|
|
69259
|
+
}
|
|
69260
|
+
});
|
|
69261
|
+
|
|
69262
|
+
// src/devkit-delivery.ts
|
|
69263
|
+
function fallbackDeliveryId(parts) {
|
|
69264
|
+
return `devkit-${parts.jobId ?? "none"}-${parts.sessionKey ?? "none"}-${parts.receivedAt}`;
|
|
69265
|
+
}
|
|
69266
|
+
function buildSessionEnvelope(ev, ctx = {}) {
|
|
69267
|
+
const now = ctx.now ?? Date.now;
|
|
69268
|
+
const receivedAt = Math.floor(now() / 1e3);
|
|
69269
|
+
const jobId = ev.jobId ?? null;
|
|
69270
|
+
const agentId = ev.agentId ?? null;
|
|
69271
|
+
const deliveryId = ev.messageId ?? fallbackDeliveryId({ jobId, sessionKey: ev.sessionKey, receivedAt });
|
|
69272
|
+
const messageId = ev.messageId ?? deliveryId;
|
|
69273
|
+
return {
|
|
69274
|
+
deliveryId,
|
|
69275
|
+
receivedAt,
|
|
69276
|
+
kind: "session",
|
|
69277
|
+
agentId,
|
|
69278
|
+
event: {
|
|
69279
|
+
sessionKey: ev.sessionKey,
|
|
69280
|
+
content: ev.content,
|
|
69281
|
+
messageId,
|
|
69282
|
+
jobId,
|
|
69283
|
+
agentId
|
|
69284
|
+
}
|
|
69285
|
+
};
|
|
69286
|
+
}
|
|
69287
|
+
function buildJobEnvelope(ev, _ctx = {}) {
|
|
69288
|
+
const sessionAgentId = ev.sessionAgentId ?? null;
|
|
69289
|
+
const receivedAt = Math.floor(ev.message.receivedAtMs / 1e3);
|
|
69290
|
+
return {
|
|
69291
|
+
deliveryId: ev.message.id,
|
|
69292
|
+
receivedAt,
|
|
69293
|
+
kind: "job",
|
|
69294
|
+
agentId: sessionAgentId,
|
|
69295
|
+
event: {
|
|
69296
|
+
jobId: ev.jobId,
|
|
69297
|
+
sessionAgentId,
|
|
69298
|
+
message: {
|
|
69299
|
+
...ev.message,
|
|
69300
|
+
content: ev.message.rawText
|
|
69301
|
+
}
|
|
69302
|
+
}
|
|
69303
|
+
};
|
|
69304
|
+
}
|
|
69305
|
+
function classifyHttpOutcome(status) {
|
|
69306
|
+
if (status >= 200 && status < 300) {
|
|
69307
|
+
return { outcome: DEVKIT_OUTCOME.HTTP_ACCEPTED };
|
|
69308
|
+
}
|
|
69309
|
+
if (status >= 300 && status < 400) {
|
|
69310
|
+
return { outcome: DEVKIT_OUTCOME.DROPPED, reason: DEVKIT_DROP_REASON.REDIRECT_BLOCKED };
|
|
69311
|
+
}
|
|
69312
|
+
return { outcome: DEVKIT_OUTCOME.DROPPED, reason: DEVKIT_DROP_REASON.HTTP_STATUS };
|
|
69313
|
+
}
|
|
69314
|
+
function classifyFetchFailure(params) {
|
|
69315
|
+
if (params.cancelledByShutdown) {
|
|
69316
|
+
return DEVKIT_DROP_REASON.SHUTDOWN_CANCELLED;
|
|
69317
|
+
}
|
|
69318
|
+
if (params.timedOut || params.errorCategory === "timeout") {
|
|
69319
|
+
return DEVKIT_DROP_REASON.TIMEOUT;
|
|
69320
|
+
}
|
|
69321
|
+
return DEVKIT_DROP_REASON.CONNECTION_FAILED;
|
|
69322
|
+
}
|
|
69323
|
+
function redactSummary(raw) {
|
|
69324
|
+
const collapsed = raw.replace(/\s+/g, " ").trim();
|
|
69325
|
+
const redacted = collapsed.replace(SECRET_SCHEME_PATTERN, "[REDACTED]").replace(
|
|
69326
|
+
SECRET_KV_PATTERN,
|
|
69327
|
+
(_match, keyQuote, key, keyQuoteClose, sep4) => `${keyQuote}${key}${keyQuoteClose}${sep4}[REDACTED]`
|
|
69328
|
+
);
|
|
69329
|
+
const truncated = redacted.length > DEVKIT_RESPONSE_SUMMARY_MAX_CHARS;
|
|
69330
|
+
return { text: redacted.slice(0, DEVKIT_RESPONSE_SUMMARY_MAX_CHARS), truncated };
|
|
69331
|
+
}
|
|
69332
|
+
async function readRedactedResponse(response) {
|
|
69333
|
+
let bodyText;
|
|
69334
|
+
try {
|
|
69335
|
+
bodyText = await response.text();
|
|
69336
|
+
} catch {
|
|
69337
|
+
return { responseBytesRead: 0, responseTruncated: false, responseSummary: "" };
|
|
69338
|
+
}
|
|
69339
|
+
const bytes = Buffer.from(bodyText, "utf8");
|
|
69340
|
+
const diagnosticSlice = bytes.subarray(0, DEVKIT_RESPONSE_DIAGNOSTIC_MAX_BYTES);
|
|
69341
|
+
const sliceTruncated = bytes.byteLength > DEVKIT_RESPONSE_DIAGNOSTIC_MAX_BYTES;
|
|
69342
|
+
const summary = redactSummary(diagnosticSlice.toString("utf8"));
|
|
69343
|
+
return {
|
|
69344
|
+
responseBytesRead: diagnosticSlice.byteLength,
|
|
69345
|
+
responseTruncated: sliceTruncated || summary.truncated,
|
|
69346
|
+
responseSummary: summary.text
|
|
69347
|
+
};
|
|
69348
|
+
}
|
|
69349
|
+
async function isLoopbackTarget(origin) {
|
|
69350
|
+
let hostname;
|
|
69351
|
+
try {
|
|
69352
|
+
hostname = new URL(origin).hostname;
|
|
69353
|
+
} catch {
|
|
69354
|
+
return false;
|
|
69355
|
+
}
|
|
69356
|
+
if (!isDevkitLoopbackHostname(hostname)) {
|
|
69357
|
+
return false;
|
|
69358
|
+
}
|
|
69359
|
+
if (hostname.toLowerCase() !== "localhost") {
|
|
69360
|
+
return true;
|
|
69361
|
+
}
|
|
69362
|
+
try {
|
|
69363
|
+
const resolved = await (0, import_promises13.lookup)(hostname);
|
|
69364
|
+
return isDevkitLoopbackHostname(resolved.address);
|
|
69365
|
+
} catch {
|
|
69366
|
+
return false;
|
|
69367
|
+
}
|
|
69368
|
+
}
|
|
69369
|
+
function orderingKeyFor(envelope, config) {
|
|
69370
|
+
const routeKey = envelope.kind === "session" ? envelope.event.sessionKey : envelope.event.jobId;
|
|
69371
|
+
return JSON.stringify([config.origin, config.port, envelope.kind, routeKey]);
|
|
69372
|
+
}
|
|
69373
|
+
function targetFields(config) {
|
|
69374
|
+
return {
|
|
69375
|
+
targetOrigin: config.origin,
|
|
69376
|
+
targetPort: config.port,
|
|
69377
|
+
targetId: JSON.stringify([config.origin, config.port])
|
|
69378
|
+
};
|
|
69379
|
+
}
|
|
69380
|
+
function copyConfig(config) {
|
|
69381
|
+
return { ...config };
|
|
69382
|
+
}
|
|
69383
|
+
function sleep4(ms) {
|
|
69384
|
+
return new Promise((resolve14) => setTimeout(resolve14, Math.max(0, ms)));
|
|
69385
|
+
}
|
|
69386
|
+
var import_promises13, COMPONENT, SECRET_KEYS, SECRET_SCHEME_PATTERN, SECRET_KV_PATTERN, DevkitDeliveryDispatcher;
|
|
69387
|
+
var init_devkit_delivery = __esm({
|
|
69388
|
+
"src/devkit-delivery.ts"() {
|
|
69389
|
+
"use strict";
|
|
69390
|
+
import_promises13 = require("node:dns/promises");
|
|
69391
|
+
init_devkit_target();
|
|
69392
|
+
init_sentry_logger();
|
|
69393
|
+
init_error_diagnostics();
|
|
69394
|
+
init_devkit_types();
|
|
69395
|
+
COMPONENT = "node_devkit";
|
|
69396
|
+
SECRET_KEYS = "authorization|bearer|basic|jwt|password|api[_-]?key|secret|token";
|
|
69397
|
+
SECRET_SCHEME_PATTERN = new RegExp(`\\b(?:${SECRET_KEYS})\\s+\\S+`, "gi");
|
|
69398
|
+
SECRET_KV_PATTERN = new RegExp(
|
|
69399
|
+
`("?)(${SECRET_KEYS})("?)\\s*([:=])\\s*"?[^"\\s,}]+`,
|
|
69400
|
+
"gi"
|
|
69401
|
+
);
|
|
69402
|
+
DevkitDeliveryDispatcher = class {
|
|
69403
|
+
now;
|
|
69404
|
+
fetchImpl;
|
|
69405
|
+
diagnosticLogger;
|
|
69406
|
+
pendingQueue = [];
|
|
69407
|
+
pendingBytes = 0;
|
|
69408
|
+
activeKeys = /* @__PURE__ */ new Set();
|
|
69409
|
+
inFlight = /* @__PURE__ */ new Set();
|
|
69410
|
+
activeControllers = /* @__PURE__ */ new Map();
|
|
69411
|
+
shuttingDown = false;
|
|
69412
|
+
constructor(options) {
|
|
69413
|
+
this.now = options.now ?? Date.now;
|
|
69414
|
+
this.fetchImpl = options.fetchImpl ?? fetch;
|
|
69415
|
+
this.diagnosticLogger = options.diagnosticLogger ?? logger;
|
|
69416
|
+
}
|
|
69417
|
+
enqueue(input) {
|
|
69418
|
+
const config = copyConfig(input.config);
|
|
69419
|
+
const serialized = JSON.stringify(input.envelope);
|
|
69420
|
+
const envelope = JSON.parse(serialized);
|
|
69421
|
+
const bytes = Buffer.byteLength(serialized, "utf8");
|
|
69422
|
+
const kind = envelope.kind;
|
|
69423
|
+
const deliveryId = envelope.deliveryId;
|
|
69424
|
+
const item = {
|
|
69425
|
+
envelope,
|
|
69426
|
+
config,
|
|
69427
|
+
serialized,
|
|
69428
|
+
bytes,
|
|
69429
|
+
cancelledByShutdown: false,
|
|
69430
|
+
timedOut: false
|
|
69431
|
+
};
|
|
69432
|
+
if (this.shuttingDown) {
|
|
69433
|
+
this.emitCancelled(item, 0);
|
|
69434
|
+
return false;
|
|
69435
|
+
}
|
|
69436
|
+
if (bytes > DEVKIT_MAX_MESSAGE_BYTES) {
|
|
69437
|
+
this.emitDropped({
|
|
69438
|
+
...targetFields(config),
|
|
69439
|
+
deliveryId,
|
|
69440
|
+
kind,
|
|
69441
|
+
reason: DEVKIT_DROP_REASON.REQUEST_TOO_LARGE,
|
|
69442
|
+
durationMs: 0
|
|
69443
|
+
});
|
|
69444
|
+
return true;
|
|
69445
|
+
}
|
|
69446
|
+
if (this.pendingQueue.length >= DEVKIT_MAX_PENDING || this.pendingBytes + bytes > DEVKIT_MAX_PENDING_BYTES) {
|
|
69447
|
+
this.emitDropped({
|
|
69448
|
+
...targetFields(config),
|
|
69449
|
+
deliveryId,
|
|
69450
|
+
kind,
|
|
69451
|
+
reason: DEVKIT_DROP_REASON.PENDING_OVERFLOW,
|
|
69452
|
+
durationMs: 0
|
|
69453
|
+
});
|
|
69454
|
+
return false;
|
|
69455
|
+
}
|
|
69456
|
+
this.pendingQueue.push(item);
|
|
69457
|
+
this.pendingBytes += bytes;
|
|
69458
|
+
this.diagnosticLogger.info(LogEvent.DEVKIT_DELIVERY_ACCEPTED, {
|
|
69459
|
+
component: COMPONENT,
|
|
69460
|
+
deliveryId,
|
|
69461
|
+
kind,
|
|
69462
|
+
...targetFields(config),
|
|
69463
|
+
agentId: envelope.agentId ?? void 0
|
|
69464
|
+
});
|
|
69465
|
+
this.pump();
|
|
69466
|
+
return true;
|
|
69467
|
+
}
|
|
69468
|
+
pump() {
|
|
69469
|
+
if (this.shuttingDown) {
|
|
69470
|
+
return;
|
|
69471
|
+
}
|
|
69472
|
+
while (this.activeKeys.size < DEVKIT_MAX_CONCURRENCY) {
|
|
69473
|
+
const index2 = this.pendingQueue.findIndex(
|
|
69474
|
+
(item2) => !this.activeKeys.has(orderingKeyFor(item2.envelope, item2.config))
|
|
69475
|
+
);
|
|
69476
|
+
if (index2 === -1) {
|
|
69477
|
+
break;
|
|
69478
|
+
}
|
|
69479
|
+
const [item] = this.pendingQueue.splice(index2, 1);
|
|
69480
|
+
this.pendingBytes -= item.bytes;
|
|
69481
|
+
const key = orderingKeyFor(item.envelope, item.config);
|
|
69482
|
+
this.activeKeys.add(key);
|
|
69483
|
+
const promise = this.send(item).finally(() => {
|
|
69484
|
+
this.activeKeys.delete(key);
|
|
69485
|
+
this.inFlight.delete(promise);
|
|
69486
|
+
this.pump();
|
|
69487
|
+
});
|
|
69488
|
+
this.inFlight.add(promise);
|
|
69489
|
+
}
|
|
69490
|
+
}
|
|
69491
|
+
async send(item) {
|
|
69492
|
+
const startedAt = this.now();
|
|
69493
|
+
const { envelope } = item;
|
|
69494
|
+
const { config } = item;
|
|
69495
|
+
const controller = new AbortController();
|
|
69496
|
+
this.activeControllers.set(item, controller);
|
|
69497
|
+
const loopbackOk = await isLoopbackTarget(config.origin);
|
|
69498
|
+
if (item.cancelledByShutdown) {
|
|
69499
|
+
this.activeControllers.delete(item);
|
|
69500
|
+
this.emitCancelled(item, this.now() - startedAt);
|
|
69501
|
+
return;
|
|
69502
|
+
}
|
|
69503
|
+
if (!loopbackOk) {
|
|
69504
|
+
this.activeControllers.delete(item);
|
|
69505
|
+
this.emitHttpFailed(
|
|
69506
|
+
item,
|
|
69507
|
+
DEVKIT_DROP_REASON.CONNECTION_FAILED,
|
|
69508
|
+
{ errorCategory: "network_unavailable" },
|
|
69509
|
+
this.now() - startedAt
|
|
69510
|
+
);
|
|
69511
|
+
return;
|
|
69512
|
+
}
|
|
69513
|
+
const url = `${config.origin}:${config.port}${config.eventPath}`;
|
|
69514
|
+
const timeoutTimer = setTimeout(() => {
|
|
69515
|
+
item.timedOut = true;
|
|
69516
|
+
controller.abort();
|
|
69517
|
+
}, DEVKIT_REQUEST_BUDGET_MS);
|
|
69518
|
+
let response;
|
|
69519
|
+
try {
|
|
69520
|
+
response = await this.fetchImpl(url, {
|
|
69521
|
+
method: "POST",
|
|
69522
|
+
headers: { "content-type": "application/json" },
|
|
69523
|
+
body: item.serialized,
|
|
69524
|
+
redirect: "manual",
|
|
69525
|
+
signal: controller.signal
|
|
69526
|
+
});
|
|
69527
|
+
} catch (err2) {
|
|
69528
|
+
clearTimeout(timeoutTimer);
|
|
69529
|
+
this.activeControllers.delete(item);
|
|
69530
|
+
const durationMs2 = this.now() - startedAt;
|
|
69531
|
+
if (item.cancelledByShutdown) {
|
|
69532
|
+
this.emitCancelled(item, durationMs2);
|
|
69533
|
+
return;
|
|
69534
|
+
}
|
|
69535
|
+
const diagnostics = buildErrorDiagnostics(
|
|
69536
|
+
LogEvent.DEVKIT_DELIVERY_HTTP_FAILED,
|
|
69537
|
+
err2 instanceof Error ? err2 : void 0,
|
|
69538
|
+
{}
|
|
69539
|
+
);
|
|
69540
|
+
const reason = classifyFetchFailure({
|
|
69541
|
+
cancelledByShutdown: item.cancelledByShutdown,
|
|
69542
|
+
timedOut: item.timedOut,
|
|
69543
|
+
errorCategory: diagnostics.errorCategory
|
|
69544
|
+
});
|
|
69545
|
+
this.emitHttpFailed(item, reason, diagnostics, durationMs2, err2 instanceof Error ? err2 : void 0);
|
|
69546
|
+
return;
|
|
69547
|
+
}
|
|
69548
|
+
clearTimeout(timeoutTimer);
|
|
69549
|
+
this.activeControllers.delete(item);
|
|
69550
|
+
const durationMs = this.now() - startedAt;
|
|
69551
|
+
if (item.cancelledByShutdown) {
|
|
69552
|
+
this.emitCancelled(item, durationMs);
|
|
69553
|
+
return;
|
|
69554
|
+
}
|
|
69555
|
+
const status = response.status;
|
|
69556
|
+
const classified = classifyHttpOutcome(status);
|
|
69557
|
+
if (classified.outcome === DEVKIT_OUTCOME.HTTP_ACCEPTED) {
|
|
69558
|
+
this.diagnosticLogger.info(LogEvent.DEVKIT_DELIVERY_HTTP_ACCEPTED, {
|
|
69559
|
+
component: COMPONENT,
|
|
69560
|
+
deliveryId: envelope.deliveryId,
|
|
69561
|
+
kind: envelope.kind,
|
|
69562
|
+
...targetFields(config),
|
|
69563
|
+
statusCode: status,
|
|
69564
|
+
durationMs
|
|
69565
|
+
});
|
|
69566
|
+
return;
|
|
69567
|
+
}
|
|
69568
|
+
const redaction = await readRedactedResponse(response);
|
|
69569
|
+
this.emitDropped({
|
|
69570
|
+
...targetFields(config),
|
|
69571
|
+
deliveryId: envelope.deliveryId,
|
|
69572
|
+
kind: envelope.kind,
|
|
69573
|
+
reason: classified.reason,
|
|
69574
|
+
statusCode: status,
|
|
69575
|
+
durationMs,
|
|
69576
|
+
...redaction
|
|
69577
|
+
});
|
|
69578
|
+
}
|
|
69579
|
+
async shutdown(deadlineMs) {
|
|
69580
|
+
this.shuttingDown = true;
|
|
69581
|
+
const deadline = this.now() + Math.max(0, deadlineMs);
|
|
69582
|
+
if (this.inFlight.size > 0) {
|
|
69583
|
+
const remaining = Math.max(0, deadline - this.now());
|
|
69584
|
+
await Promise.race([Promise.allSettled(Array.from(this.inFlight)), sleep4(remaining)]);
|
|
69585
|
+
}
|
|
69586
|
+
for (const [item, controller] of this.activeControllers) {
|
|
69587
|
+
item.cancelledByShutdown = true;
|
|
69588
|
+
controller.abort();
|
|
69589
|
+
}
|
|
69590
|
+
const stillPending = this.pendingQueue.splice(0, this.pendingQueue.length);
|
|
69591
|
+
this.pendingBytes = 0;
|
|
69592
|
+
for (const item of stillPending) {
|
|
69593
|
+
this.emitCancelled(item, 0);
|
|
69594
|
+
}
|
|
69595
|
+
}
|
|
69596
|
+
emitDropped(params) {
|
|
69597
|
+
this.diagnosticLogger.info(LogEvent.DEVKIT_DELIVERY_DROPPED, {
|
|
69598
|
+
component: COMPONENT,
|
|
69599
|
+
outcome: DEVKIT_OUTCOME.DROPPED,
|
|
69600
|
+
deliveryId: params.deliveryId,
|
|
69601
|
+
kind: params.kind,
|
|
69602
|
+
targetOrigin: params.targetOrigin,
|
|
69603
|
+
targetPort: params.targetPort,
|
|
69604
|
+
targetId: params.targetId,
|
|
69605
|
+
reason: params.reason,
|
|
69606
|
+
durationMs: params.durationMs,
|
|
69607
|
+
...params.statusCode !== void 0 ? { statusCode: params.statusCode } : {},
|
|
69608
|
+
...params.responseBytesRead !== void 0 ? { responseBytesRead: params.responseBytesRead } : {},
|
|
69609
|
+
...params.responseTruncated !== void 0 ? { responseTruncated: params.responseTruncated } : {},
|
|
69610
|
+
...params.responseSummary !== void 0 ? { responseSummary: params.responseSummary } : {}
|
|
69611
|
+
});
|
|
69612
|
+
}
|
|
69613
|
+
emitHttpFailed(item, reason, diagnostics, durationMs, err2) {
|
|
69614
|
+
this.diagnosticLogger.error(LogEvent.DEVKIT_DELIVERY_HTTP_FAILED, err2, {
|
|
69615
|
+
component: COMPONENT,
|
|
69616
|
+
outcome: DEVKIT_OUTCOME.DROPPED,
|
|
69617
|
+
deliveryId: item.envelope.deliveryId,
|
|
69618
|
+
kind: item.envelope.kind,
|
|
69619
|
+
...targetFields(item.config),
|
|
69620
|
+
reason,
|
|
69621
|
+
durationMs,
|
|
69622
|
+
...diagnostics.errorCategory ? { errorCategory: diagnostics.errorCategory } : {},
|
|
69623
|
+
...diagnostics.errorCode ? { errorCode: diagnostics.errorCode } : {}
|
|
69624
|
+
});
|
|
69625
|
+
}
|
|
69626
|
+
emitCancelled(item, durationMs) {
|
|
69627
|
+
this.diagnosticLogger.info(LogEvent.DEVKIT_DELIVERY_CANCELLED, {
|
|
69628
|
+
component: COMPONENT,
|
|
69629
|
+
outcome: DEVKIT_OUTCOME.DROPPED,
|
|
69630
|
+
deliveryId: item.envelope.deliveryId,
|
|
69631
|
+
kind: item.envelope.kind,
|
|
69632
|
+
...targetFields(item.config),
|
|
69633
|
+
reason: DEVKIT_DROP_REASON.SHUTDOWN_CANCELLED,
|
|
69634
|
+
durationMs
|
|
69635
|
+
});
|
|
69636
|
+
}
|
|
69637
|
+
};
|
|
69638
|
+
}
|
|
69639
|
+
});
|
|
69640
|
+
|
|
68414
69641
|
// src/ai-dispatch-queue.ts
|
|
68415
69642
|
async function enqueueAiJobMessageDispatch(params) {
|
|
68416
69643
|
const commands = params.commands ?? new CommandStore(params.homeDir);
|
|
@@ -68442,6 +69669,127 @@ var init_ai_dispatch_queue = __esm({
|
|
|
68442
69669
|
}
|
|
68443
69670
|
});
|
|
68444
69671
|
|
|
69672
|
+
// src/devkit-router.ts
|
|
69673
|
+
function createDevkitAutoRouter(deps) {
|
|
69674
|
+
const { commands, dispatcher, readSnapshots } = deps;
|
|
69675
|
+
const diagnosticLogger = deps.diagnosticLogger ?? logger;
|
|
69676
|
+
function readConfigSnapshots(phase) {
|
|
69677
|
+
try {
|
|
69678
|
+
const configs = readSnapshots();
|
|
69679
|
+
return {
|
|
69680
|
+
ok: true,
|
|
69681
|
+
// Capture detached, shallow immutable copies before any enqueue can trigger a registry
|
|
69682
|
+
// update. Delivery then owns the exact target/path selected for this inbound message.
|
|
69683
|
+
configs: configs.map((config) => Object.freeze({ ...config }))
|
|
69684
|
+
};
|
|
69685
|
+
} catch (err2) {
|
|
69686
|
+
diagnosticLogger.error(
|
|
69687
|
+
LogEvent.DEVKIT_ROUTE_CONFIG_READ_FAILED,
|
|
69688
|
+
err2 instanceof Error ? err2 : new Error(String(err2)),
|
|
69689
|
+
{
|
|
69690
|
+
component: "node_devkit",
|
|
69691
|
+
phase,
|
|
69692
|
+
outcome: "dropped",
|
|
69693
|
+
reason: "config_read_failed"
|
|
69694
|
+
}
|
|
69695
|
+
);
|
|
69696
|
+
return { ok: false };
|
|
69697
|
+
}
|
|
69698
|
+
}
|
|
69699
|
+
function enqueueForTargets(phase, envelope, configs, eventFields) {
|
|
69700
|
+
for (const config of configs) {
|
|
69701
|
+
const targetId = JSON.stringify([config.origin, config.port]);
|
|
69702
|
+
const targetFields2 = {
|
|
69703
|
+
targetOrigin: config.origin,
|
|
69704
|
+
targetPort: config.port,
|
|
69705
|
+
targetId
|
|
69706
|
+
};
|
|
69707
|
+
try {
|
|
69708
|
+
const accepted = dispatcher.enqueue({ envelope, config });
|
|
69709
|
+
diagnosticLogger.info(LogEvent.DEVKIT_ROUTE_CUSTOM_SERVER, {
|
|
69710
|
+
component: "node_devkit",
|
|
69711
|
+
phase,
|
|
69712
|
+
kind: envelope.kind,
|
|
69713
|
+
deliveryId: envelope.deliveryId,
|
|
69714
|
+
...targetFields2,
|
|
69715
|
+
outcome: accepted ? "accepted" : "dropped",
|
|
69716
|
+
...eventFields
|
|
69717
|
+
});
|
|
69718
|
+
} catch (err2) {
|
|
69719
|
+
diagnosticLogger.error(
|
|
69720
|
+
LogEvent.DEVKIT_ROUTE_CUSTOM_SERVER,
|
|
69721
|
+
err2 instanceof Error ? err2 : new Error(String(err2)),
|
|
69722
|
+
{
|
|
69723
|
+
component: "node_devkit",
|
|
69724
|
+
phase,
|
|
69725
|
+
kind: envelope.kind,
|
|
69726
|
+
deliveryId: envelope.deliveryId,
|
|
69727
|
+
...targetFields2,
|
|
69728
|
+
outcome: "dropped",
|
|
69729
|
+
reason: "enqueue_failed"
|
|
69730
|
+
}
|
|
69731
|
+
);
|
|
69732
|
+
}
|
|
69733
|
+
}
|
|
69734
|
+
}
|
|
69735
|
+
async function routeSession(event) {
|
|
69736
|
+
const read = readConfigSnapshots("session");
|
|
69737
|
+
if (!read.ok) {
|
|
69738
|
+
return;
|
|
69739
|
+
}
|
|
69740
|
+
if (read.configs.length === 0) {
|
|
69741
|
+
await enqueueAiSessionMessageDispatch({ commands, event });
|
|
69742
|
+
diagnosticLogger.info(LogEvent.DEVKIT_ROUTE_DEFAULT_AI, {
|
|
69743
|
+
component: "node_devkit",
|
|
69744
|
+
phase: "session",
|
|
69745
|
+
kind: "session",
|
|
69746
|
+
messageId: event.messageId ?? "",
|
|
69747
|
+
jobId: event.jobId ?? "",
|
|
69748
|
+
agentId: event.agentId ?? ""
|
|
69749
|
+
});
|
|
69750
|
+
return;
|
|
69751
|
+
}
|
|
69752
|
+
const envelope = buildSessionEnvelope(event);
|
|
69753
|
+
enqueueForTargets("session", envelope, read.configs, {
|
|
69754
|
+
messageId: event.messageId ?? "",
|
|
69755
|
+
jobId: event.jobId ?? "",
|
|
69756
|
+
agentId: event.agentId ?? ""
|
|
69757
|
+
});
|
|
69758
|
+
}
|
|
69759
|
+
async function routeJob(event) {
|
|
69760
|
+
const read = readConfigSnapshots("job");
|
|
69761
|
+
if (!read.ok) {
|
|
69762
|
+
return;
|
|
69763
|
+
}
|
|
69764
|
+
if (read.configs.length === 0) {
|
|
69765
|
+
await enqueueAiJobMessageDispatch({ commands, event });
|
|
69766
|
+
diagnosticLogger.info(LogEvent.DEVKIT_ROUTE_DEFAULT_AI, {
|
|
69767
|
+
component: "node_devkit",
|
|
69768
|
+
phase: "job",
|
|
69769
|
+
kind: "job",
|
|
69770
|
+
jobId: event.jobId,
|
|
69771
|
+
agentId: event.sessionAgentId ?? ""
|
|
69772
|
+
});
|
|
69773
|
+
return;
|
|
69774
|
+
}
|
|
69775
|
+
const envelope = buildJobEnvelope(event);
|
|
69776
|
+
enqueueForTargets("job", envelope, read.configs, {
|
|
69777
|
+
messageId: event.message.id,
|
|
69778
|
+
jobId: event.jobId,
|
|
69779
|
+
agentId: event.sessionAgentId ?? ""
|
|
69780
|
+
});
|
|
69781
|
+
}
|
|
69782
|
+
return { routeJob, routeSession };
|
|
69783
|
+
}
|
|
69784
|
+
var init_devkit_router = __esm({
|
|
69785
|
+
"src/devkit-router.ts"() {
|
|
69786
|
+
"use strict";
|
|
69787
|
+
init_ai_dispatch_queue();
|
|
69788
|
+
init_devkit_delivery();
|
|
69789
|
+
init_sentry_logger();
|
|
69790
|
+
}
|
|
69791
|
+
});
|
|
69792
|
+
|
|
68445
69793
|
// src/message-handler.ts
|
|
68446
69794
|
function tryMarkProcessed(messageId) {
|
|
68447
69795
|
if (processedMessageIds.has(messageId)) {
|
|
@@ -69032,7 +70380,7 @@ async function isTrustedDmSender(params) {
|
|
|
69032
70380
|
}
|
|
69033
70381
|
if (trustedInboxIds.length === 0) {
|
|
69034
70382
|
logger.info(LogEvent.DM_WHITELIST_FAIL_OPEN, { ...dmExtras(), reason: "trusted_inbox_list_empty" });
|
|
69035
|
-
return
|
|
70383
|
+
return false;
|
|
69036
70384
|
}
|
|
69037
70385
|
if (!matches(trustedInboxIds)) {
|
|
69038
70386
|
logger.info(LogEvent.INBOUND_DROP_DM_NON_SYSTEM, {
|
|
@@ -69431,7 +70779,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
69431
70779
|
timing.mark("payloadParse", parseStartedAt);
|
|
69432
70780
|
const directToUser = chatType === "dm" && parseResult.ok ? extractDirectToUserNotification(parseResult.data) : { kind: "none" };
|
|
69433
70781
|
if (directToUser.kind === "invalid") {
|
|
69434
|
-
const droppedMessageId = messageId || `direct-to-user-${(0,
|
|
70782
|
+
const droppedMessageId = messageId || `direct-to-user-${(0, import_node_crypto15.randomUUID)()}`;
|
|
69435
70783
|
logger.error(
|
|
69436
70784
|
LogEvent.INBOUND_DROP_DM_INVALID_PAYLOAD,
|
|
69437
70785
|
new Error("Invalid direct-to-user system DM"),
|
|
@@ -69455,7 +70803,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
69455
70803
|
await dispatchDirectToUserNotification({
|
|
69456
70804
|
deps,
|
|
69457
70805
|
notification: directToUser.notification,
|
|
69458
|
-
messageId: messageId || `direct-to-user-${(0,
|
|
70806
|
+
messageId: messageId || `direct-to-user-${(0, import_node_crypto15.randomUUID)()}`,
|
|
69459
70807
|
timing,
|
|
69460
70808
|
source: options.source ?? "live"
|
|
69461
70809
|
});
|
|
@@ -69463,7 +70811,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
69463
70811
|
}
|
|
69464
70812
|
const systemNotification = chatType === "dm" && parseResult.ok ? extractSystemNotification(parseResult.data) : null;
|
|
69465
70813
|
if (systemNotification) {
|
|
69466
|
-
const systemMessageId = messageId || `system-${(0,
|
|
70814
|
+
const systemMessageId = messageId || `system-${(0, import_node_crypto15.randomUUID)()}`;
|
|
69467
70815
|
logWithTimestamp(
|
|
69468
70816
|
`[okx-agent-task:${deps.myXmtpAddress}] xmtp_system_message_received agentId=${systemNotification.agentId ?? ""} msg=${shortenLogValue(systemMessageId)} event=${systemNotification.event ?? ""} job=${shortenLogValue(systemNotification.jobId)} conv=${conversationId} source=${options.source ?? "live"} rawBytes=${Buffer.byteLength(rawText, "utf8")} rawPreview=${previewRawEnvelope(rawText)}`
|
|
69469
70817
|
);
|
|
@@ -69759,7 +71107,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
69759
71107
|
}));
|
|
69760
71108
|
return true;
|
|
69761
71109
|
}
|
|
69762
|
-
const routedMessageId = messageId || `group-${(0,
|
|
71110
|
+
const routedMessageId = messageId || `group-${(0, import_node_crypto15.randomUUID)()}`;
|
|
69763
71111
|
const sessionKey = ensureInboundGroupSession(deps, {
|
|
69764
71112
|
jobId: route.jobId,
|
|
69765
71113
|
myAgentId,
|
|
@@ -69825,7 +71173,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
69825
71173
|
return true;
|
|
69826
71174
|
}
|
|
69827
71175
|
const stored = {
|
|
69828
|
-
id: messageId || `local-${(0,
|
|
71176
|
+
id: messageId || `local-${(0, import_node_crypto15.randomUUID)()}`,
|
|
69829
71177
|
direction: "inbound",
|
|
69830
71178
|
route: route.route,
|
|
69831
71179
|
routeReason: route.routeReason,
|
|
@@ -70006,7 +71354,7 @@ function processOfflineFromCoreDeps(store, ctx, deps, options) {
|
|
|
70006
71354
|
function buildSystemStoredMessage(params) {
|
|
70007
71355
|
const now = Date.now();
|
|
70008
71356
|
return {
|
|
70009
|
-
id: params.id ?? `system-${now}-${(0,
|
|
71357
|
+
id: params.id ?? `system-${now}-${(0, import_node_crypto15.randomUUID)()}`,
|
|
70010
71358
|
direction: "system",
|
|
70011
71359
|
route: "backup",
|
|
70012
71360
|
routeReason: params.reason,
|
|
@@ -70024,12 +71372,12 @@ function buildSystemStoredMessage(params) {
|
|
|
70024
71372
|
function isA2AEnvelope(payload) {
|
|
70025
71373
|
return isPlainObject3(payload) && payload.msgType === A2A_MESSAGE_TYPE;
|
|
70026
71374
|
}
|
|
70027
|
-
var
|
|
71375
|
+
var import_node_crypto15, PROCESSED_IDS_MAX, processedMessageIds, EXTERNAL_JOB_ID_PATTERN, INBOUND_TRANSPORT, INBOUND_EVENT_FAMILY, INBOUND_TERMINAL_FIELDS;
|
|
70028
71376
|
var init_message_handler = __esm({
|
|
70029
71377
|
"src/message-handler.ts"() {
|
|
70030
71378
|
"use strict";
|
|
70031
71379
|
init_log();
|
|
70032
|
-
|
|
71380
|
+
import_node_crypto15 = require("node:crypto");
|
|
70033
71381
|
init_dist2();
|
|
70034
71382
|
init_a2a();
|
|
70035
71383
|
init_envelope_shared();
|
|
@@ -70097,7 +71445,7 @@ function isOriginalParentProcessAlive(options) {
|
|
|
70097
71445
|
}
|
|
70098
71446
|
function registerUserAttentionWatcher(options) {
|
|
70099
71447
|
return options.store.registerUserAttentionWatcher({
|
|
70100
|
-
id: options.id ?? (0,
|
|
71448
|
+
id: options.id ?? (0, import_node_crypto16.randomUUID)(),
|
|
70101
71449
|
provider: options.provider,
|
|
70102
71450
|
jobId: options.jobId,
|
|
70103
71451
|
nowMs: options.nowMs ?? Date.now(),
|
|
@@ -70176,11 +71524,11 @@ function userWatchEventDeliveredSentryExtra(event) {
|
|
|
70176
71524
|
hasDecision: String(event.hasDecision)
|
|
70177
71525
|
};
|
|
70178
71526
|
}
|
|
70179
|
-
var
|
|
71527
|
+
var import_node_crypto16, USER_ATTENTION_WATCH_REPLACED_MESSAGE, USER_ATTENTION_WATCHER_SCAN_MS, USER_ATTENTION_WATCHER_TTL_MS, USER_ATTENTION_WATCH_PARENT_CHECK_MS;
|
|
70180
71528
|
var init_user_attention_watchers = __esm({
|
|
70181
71529
|
"src/user-attention-watchers.ts"() {
|
|
70182
71530
|
"use strict";
|
|
70183
|
-
|
|
71531
|
+
import_node_crypto16 = require("node:crypto");
|
|
70184
71532
|
init_sentry_logger();
|
|
70185
71533
|
USER_ATTENTION_WATCH_REPLACED_MESSAGE = "Another okx-a2a user watch with the same job scope was started, so this watcher has been closed. Do not run this watch command again automatically, because starting another watcher may interrupt a different session that is already monitoring task progress.";
|
|
70186
71534
|
USER_ATTENTION_WATCHER_SCAN_MS = 500;
|
|
@@ -70253,13 +71601,13 @@ async function getHermesGatewayPluginStatus(options = {}) {
|
|
|
70253
71601
|
const env = options.env ?? process.env;
|
|
70254
71602
|
const hermesHome = env.HERMES_HOME?.trim() || (0, import_node_path32.join)((0, import_node_os10.homedir)(), ".hermes");
|
|
70255
71603
|
const pluginYamlPath = (0, import_node_path32.join)(hermesHome, "plugins", "platforms", "okx-a2a", "plugin.yaml");
|
|
70256
|
-
if (!(0,
|
|
71604
|
+
if (!(0, import_node_fs28.existsSync)(pluginYamlPath)) {
|
|
70257
71605
|
return { enabled: false, reason: "plugin_yaml_missing", hermesHome, checkedPath: pluginYamlPath };
|
|
70258
71606
|
}
|
|
70259
71607
|
const configPath = (0, import_node_path32.join)(hermesHome, "config.yaml");
|
|
70260
71608
|
let content2;
|
|
70261
71609
|
try {
|
|
70262
|
-
content2 = await (0,
|
|
71610
|
+
content2 = await (0, import_promises14.readFile)(configPath, "utf8");
|
|
70263
71611
|
} catch {
|
|
70264
71612
|
return { enabled: false, reason: "config_read_error", hermesHome, checkedPath: configPath };
|
|
70265
71613
|
}
|
|
@@ -70380,6 +71728,27 @@ async function runListenerWithLock(options, paths) {
|
|
|
70380
71728
|
const store = new TaskMessageStore(options.homeDir);
|
|
70381
71729
|
const sessionStore = new SessionStore({ homeDir: options.homeDir });
|
|
70382
71730
|
const commands = new CommandStore(options.homeDir);
|
|
71731
|
+
const devkitInitializer = DevkitServerStore.openForWrite(options.homeDir);
|
|
71732
|
+
devkitInitializer.close();
|
|
71733
|
+
const devkitReadSnapshots = () => {
|
|
71734
|
+
const snapshotStore = DevkitServerStore.openForRead(options.homeDir);
|
|
71735
|
+
if (!snapshotStore) {
|
|
71736
|
+
return [];
|
|
71737
|
+
}
|
|
71738
|
+
try {
|
|
71739
|
+
return snapshotStore.readSnapshots();
|
|
71740
|
+
} finally {
|
|
71741
|
+
snapshotStore.close();
|
|
71742
|
+
}
|
|
71743
|
+
};
|
|
71744
|
+
const devkitDispatcher = new DevkitDeliveryDispatcher({
|
|
71745
|
+
homeDir: options.homeDir
|
|
71746
|
+
});
|
|
71747
|
+
const devkitRouter = createDevkitAutoRouter({
|
|
71748
|
+
commands,
|
|
71749
|
+
dispatcher: devkitDispatcher,
|
|
71750
|
+
readSnapshots: devkitReadSnapshots
|
|
71751
|
+
});
|
|
70383
71752
|
await store.ensureReady();
|
|
70384
71753
|
let userAttentionEvents = null;
|
|
70385
71754
|
try {
|
|
@@ -70443,20 +71812,20 @@ async function runListenerWithLock(options, paths) {
|
|
|
70443
71812
|
createInboundMiddleware: (deps) => createMiddlewareFromCoreDeps(store, deps, {
|
|
70444
71813
|
sessionStore,
|
|
70445
71814
|
onJobMessageStored: async (event) => {
|
|
70446
|
-
await
|
|
71815
|
+
await devkitRouter.routeJob(event);
|
|
70447
71816
|
},
|
|
70448
71817
|
onSessionMessage: async (event) => {
|
|
70449
|
-
await
|
|
71818
|
+
await devkitRouter.routeSession(event);
|
|
70450
71819
|
}
|
|
70451
71820
|
}),
|
|
70452
71821
|
processOfflineMessage: (ctx, deps, replayOptions) => processOfflineFromCoreDeps(store, ctx, deps, {
|
|
70453
71822
|
...replayOptions,
|
|
70454
71823
|
sessionStore,
|
|
70455
71824
|
onJobMessageStored: async (event) => {
|
|
70456
|
-
await
|
|
71825
|
+
await devkitRouter.routeJob(event);
|
|
70457
71826
|
},
|
|
70458
71827
|
onSessionMessage: async (event) => {
|
|
70459
|
-
await
|
|
71828
|
+
await devkitRouter.routeSession(event);
|
|
70460
71829
|
}
|
|
70461
71830
|
}),
|
|
70462
71831
|
notifySessionExpired: (command) => {
|
|
@@ -70488,12 +71857,12 @@ async function runListenerWithLock(options, paths) {
|
|
|
70488
71857
|
});
|
|
70489
71858
|
}
|
|
70490
71859
|
});
|
|
70491
|
-
service.setPluginVersion("0.2.
|
|
71860
|
+
service.setPluginVersion("0.2.19-beta-fe6942ad54-261125201445");
|
|
70492
71861
|
await service.init();
|
|
70493
71862
|
const pluginVersionStatus = service.pluginVersionStatus;
|
|
70494
71863
|
if (pluginVersionStatus.unavailable) {
|
|
70495
71864
|
throw new Error(
|
|
70496
|
-
`@okxweb3/a2a-node v${"0.2.
|
|
71865
|
+
`@okxweb3/a2a-node v${"0.2.19-beta-fe6942ad54-261125201445"} is below the required minimum v${pluginVersionStatus.minVersion}`
|
|
70497
71866
|
);
|
|
70498
71867
|
}
|
|
70499
71868
|
const systemConfig = service.getSystemConfig();
|
|
@@ -70521,7 +71890,7 @@ async function runListenerWithLock(options, paths) {
|
|
|
70521
71890
|
onchainosAgentId: "*",
|
|
70522
71891
|
reason: "system-config missing sentryDsn",
|
|
70523
71892
|
pluginId: "@okxweb3/a2a-node",
|
|
70524
|
-
pluginVersion: "0.2.
|
|
71893
|
+
pluginVersion: "0.2.19-beta-fe6942ad54-261125201445"
|
|
70525
71894
|
});
|
|
70526
71895
|
}
|
|
70527
71896
|
logWithTimestamp(
|
|
@@ -70853,6 +72222,7 @@ async function runListenerWithLock(options, paths) {
|
|
|
70853
72222
|
logWithTimestamp("[okx-agent-task] failed to close user_attention IPC wake:", err2);
|
|
70854
72223
|
}
|
|
70855
72224
|
stopClients(service);
|
|
72225
|
+
await devkitDispatcher.shutdown(SHUTDOWN_FORCE_RESOLVE_MS);
|
|
70856
72226
|
sessionStore.close();
|
|
70857
72227
|
clearTimeout(forceResolve);
|
|
70858
72228
|
resolve14();
|
|
@@ -70871,14 +72241,14 @@ async function timeSettled(fn) {
|
|
|
70871
72241
|
return { durationMs: Date.now() - startedAt, error };
|
|
70872
72242
|
}
|
|
70873
72243
|
}
|
|
70874
|
-
var
|
|
72244
|
+
var import_node_fs28, import_promises14, import_node_os10, import_node_path32, DEFAULT_OFFLINE_REPLAY_INTERVAL_SEC, DEFAULT_XMTP_CLIENT_RECYCLE_INTERVAL_SEC, XMTP_CLIENT_RECYCLE_INTERVAL_ENV, HEARTBEAT_GATEWAY_CHECK_TIMEOUT_MS, AUTH_RECOVERY_PROBE_INTERVAL_MS, AUTH_RECOVERY_REFRESH_BACKOFF_MS, AgentRefreshAuthGate, AgentRefreshCoordinator, ListenerDeferredTaskScheduler, ListenerMaintenanceGate, UPGRADE_RECOMMENDATION_IDEMPOTENCY_KEY, SHUTDOWN_FORCE_RESOLVE_MS;
|
|
70875
72245
|
var init_listener = __esm({
|
|
70876
72246
|
"src/listener.ts"() {
|
|
70877
72247
|
"use strict";
|
|
70878
72248
|
init_log();
|
|
70879
72249
|
init_client_lifecycle();
|
|
70880
|
-
|
|
70881
|
-
|
|
72250
|
+
import_node_fs28 = require("node:fs");
|
|
72251
|
+
import_promises14 = require("node:fs/promises");
|
|
70882
72252
|
import_node_os10 = require("node:os");
|
|
70883
72253
|
import_node_path32 = require("node:path");
|
|
70884
72254
|
init_onchainos();
|
|
@@ -70891,7 +72261,9 @@ var init_listener = __esm({
|
|
|
70891
72261
|
init_session_store();
|
|
70892
72262
|
init_command_processor();
|
|
70893
72263
|
init_command_store();
|
|
70894
|
-
|
|
72264
|
+
init_devkit_delivery();
|
|
72265
|
+
init_devkit_router();
|
|
72266
|
+
init_devkit_server_store();
|
|
70895
72267
|
init_message_handler();
|
|
70896
72268
|
init_agent_message_notice();
|
|
70897
72269
|
init_paths();
|
|
@@ -71144,7 +72516,7 @@ async function startXmtpTest(args, releaseInfo) {
|
|
|
71144
72516
|
const runId = requestedRunId ? validateRunId(requestedRunId) : createRunId(requestedName);
|
|
71145
72517
|
const files = resolveRunFiles(testsDir, runId);
|
|
71146
72518
|
try {
|
|
71147
|
-
await (0,
|
|
72519
|
+
await (0, import_promises15.stat)(files.runDir);
|
|
71148
72520
|
throw new Error(`XMTP test run already exists: ${runId}`);
|
|
71149
72521
|
} catch (error) {
|
|
71150
72522
|
if (error.code !== "ENOENT") {
|
|
@@ -71152,7 +72524,7 @@ async function startXmtpTest(args, releaseInfo) {
|
|
|
71152
72524
|
}
|
|
71153
72525
|
}
|
|
71154
72526
|
await ensurePrivateDir(files.runDir);
|
|
71155
|
-
await (0,
|
|
72527
|
+
await (0, import_promises15.writeFile)(files.eventsPath, "", { encoding: "utf8", mode: 384 });
|
|
71156
72528
|
const manifest = {
|
|
71157
72529
|
runId,
|
|
71158
72530
|
name: requestedName,
|
|
@@ -71196,7 +72568,7 @@ async function stopXmtpTest(args) {
|
|
|
71196
72568
|
}
|
|
71197
72569
|
const runId = validateRunId(active.runId);
|
|
71198
72570
|
const files = resolveRunFiles(testsDir, runId);
|
|
71199
|
-
await (0,
|
|
72571
|
+
await (0, import_promises15.unlink)(activePath);
|
|
71200
72572
|
const manifest = await readRequiredJson(files.manifestPath);
|
|
71201
72573
|
const completed = {
|
|
71202
72574
|
...manifest,
|
|
@@ -71514,7 +72886,7 @@ async function resolveRequestedRunId(testsDir, args, preferActive = false) {
|
|
|
71514
72886
|
async function findLatestRunId(testsDir) {
|
|
71515
72887
|
let entries;
|
|
71516
72888
|
try {
|
|
71517
|
-
entries = await (0,
|
|
72889
|
+
entries = await (0, import_promises15.readdir)(testsDir, { withFileTypes: true });
|
|
71518
72890
|
} catch (error) {
|
|
71519
72891
|
if (error.code === "ENOENT") {
|
|
71520
72892
|
return null;
|
|
@@ -71539,7 +72911,7 @@ async function findLatestRunId(testsDir) {
|
|
|
71539
72911
|
async function readMetricEvents(path2) {
|
|
71540
72912
|
let text;
|
|
71541
72913
|
try {
|
|
71542
|
-
text = await (0,
|
|
72914
|
+
text = await (0, import_promises15.readFile)(path2, "utf8");
|
|
71543
72915
|
} catch (error) {
|
|
71544
72916
|
if (error.code === "ENOENT") {
|
|
71545
72917
|
return [];
|
|
@@ -71563,9 +72935,9 @@ function parseMetricEvent(line) {
|
|
|
71563
72935
|
}
|
|
71564
72936
|
}
|
|
71565
72937
|
async function ensurePrivateDir(path2) {
|
|
71566
|
-
await (0,
|
|
72938
|
+
await (0, import_promises15.mkdir)(path2, { recursive: true, mode: 448 });
|
|
71567
72939
|
try {
|
|
71568
|
-
await (0,
|
|
72940
|
+
await (0, import_promises15.chmod)(path2, 448);
|
|
71569
72941
|
} catch (error) {
|
|
71570
72942
|
const code = error.code;
|
|
71571
72943
|
if (code !== "EPERM" && code !== "EACCES") {
|
|
@@ -71575,12 +72947,12 @@ async function ensurePrivateDir(path2) {
|
|
|
71575
72947
|
}
|
|
71576
72948
|
async function writeJson(path2, value) {
|
|
71577
72949
|
const temporary = `${path2}.${process.pid}.tmp`;
|
|
71578
|
-
await (0,
|
|
72950
|
+
await (0, import_promises15.writeFile)(temporary, `${JSON.stringify(value, null, 2)}
|
|
71579
72951
|
`, {
|
|
71580
72952
|
encoding: "utf8",
|
|
71581
72953
|
mode: 384
|
|
71582
72954
|
});
|
|
71583
|
-
await (0,
|
|
72955
|
+
await (0, import_promises15.rename)(temporary, path2);
|
|
71584
72956
|
}
|
|
71585
72957
|
async function readRequiredJson(path2) {
|
|
71586
72958
|
const value = await readJsonIfExists(path2);
|
|
@@ -71591,7 +72963,7 @@ async function readRequiredJson(path2) {
|
|
|
71591
72963
|
}
|
|
71592
72964
|
async function readJsonIfExists(path2) {
|
|
71593
72965
|
try {
|
|
71594
|
-
return JSON.parse(await (0,
|
|
72966
|
+
return JSON.parse(await (0, import_promises15.readFile)(path2, "utf8"));
|
|
71595
72967
|
} catch (error) {
|
|
71596
72968
|
if (error.code === "ENOENT") {
|
|
71597
72969
|
return null;
|
|
@@ -71762,11 +73134,11 @@ function formatPercent(value) {
|
|
|
71762
73134
|
function validTimestamp(value) {
|
|
71763
73135
|
return typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
71764
73136
|
}
|
|
71765
|
-
var
|
|
73137
|
+
var import_promises15, import_node_path33, RUN_ID_PATTERN2, ACTIVE_FILE;
|
|
71766
73138
|
var init_xmtp_test_cli = __esm({
|
|
71767
73139
|
"src/xmtp-test-cli.ts"() {
|
|
71768
73140
|
"use strict";
|
|
71769
|
-
|
|
73141
|
+
import_promises15 = require("node:fs/promises");
|
|
71770
73142
|
import_node_path33 = require("node:path");
|
|
71771
73143
|
init_daemon();
|
|
71772
73144
|
init_log_tail();
|
|
@@ -114745,10 +116117,10 @@ var require_node4 = __commonJS({
|
|
|
114745
116117
|
|
|
114746
116118
|
// ../../node_modules/@xmtp/content-type-remote-attachment/dist/index.js
|
|
114747
116119
|
async function encrypt(plain, secret, additionalData) {
|
|
114748
|
-
const salt =
|
|
114749
|
-
const nonce =
|
|
116120
|
+
const salt = import_node_crypto17.webcrypto.getRandomValues(new Uint8Array(KDFSaltSize));
|
|
116121
|
+
const nonce = import_node_crypto17.webcrypto.getRandomValues(new Uint8Array(AESGCMNonceSize));
|
|
114750
116122
|
const key = await hkdf(secret, salt);
|
|
114751
|
-
const encrypted = await
|
|
116123
|
+
const encrypted = await import_node_crypto17.webcrypto.subtle.encrypt(aesGcmParams(nonce), key, plain);
|
|
114752
116124
|
return new Ciphertext({
|
|
114753
116125
|
aes256GcmHkdfSha256: {
|
|
114754
116126
|
payload: new Uint8Array(encrypted),
|
|
@@ -114762,7 +116134,7 @@ async function decrypt(encrypted, secret, additionalData) {
|
|
|
114762
116134
|
throw new Error("invalid payload ciphertext");
|
|
114763
116135
|
}
|
|
114764
116136
|
const key = await hkdf(secret, encrypted.aes256GcmHkdfSha256.hkdfSalt);
|
|
114765
|
-
const decrypted = await
|
|
116137
|
+
const decrypted = await import_node_crypto17.webcrypto.subtle.decrypt(aesGcmParams(encrypted.aes256GcmHkdfSha256.gcmNonce), key, encrypted.aes256GcmHkdfSha256.payload);
|
|
114766
116138
|
return new Uint8Array(decrypted);
|
|
114767
116139
|
}
|
|
114768
116140
|
function aesGcmParams(nonce, additionalData) {
|
|
@@ -114773,18 +116145,18 @@ function aesGcmParams(nonce, additionalData) {
|
|
|
114773
116145
|
return spec;
|
|
114774
116146
|
}
|
|
114775
116147
|
async function hkdf(secret, salt) {
|
|
114776
|
-
const key = await
|
|
116148
|
+
const key = await import_node_crypto17.webcrypto.subtle.importKey("raw", secret, "HKDF", false, [
|
|
114777
116149
|
"deriveKey"
|
|
114778
116150
|
]);
|
|
114779
|
-
return
|
|
116151
|
+
return import_node_crypto17.webcrypto.subtle.deriveKey({ name: "HKDF", hash: "SHA-256", salt, info: hkdfNoInfo }, key, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
114780
116152
|
}
|
|
114781
|
-
var import_proto,
|
|
116153
|
+
var import_proto, import_node_crypto17, ContentTypeAttachment, AttachmentCodec, KDFSaltSize, AESGCMNonceSize, AESGCMTagLength, Ciphertext, hkdfNoInfo, ContentTypeRemoteAttachment, RemoteAttachmentCodec;
|
|
114782
116154
|
var init_dist6 = __esm({
|
|
114783
116155
|
"../../node_modules/@xmtp/content-type-remote-attachment/dist/index.js"() {
|
|
114784
116156
|
init_dist5();
|
|
114785
116157
|
init_secp256k12();
|
|
114786
116158
|
import_proto = __toESM(require_node4(), 1);
|
|
114787
|
-
|
|
116159
|
+
import_node_crypto17 = require("node:crypto");
|
|
114788
116160
|
ContentTypeAttachment = new ContentTypeId({
|
|
114789
116161
|
authorityId: "xmtp.org",
|
|
114790
116162
|
typeId: "attachment",
|
|
@@ -114864,7 +116236,7 @@ var init_dist6 = __esm({
|
|
|
114864
116236
|
if (payload.length === 0) {
|
|
114865
116237
|
throw new Error(`no payload for remote attachment at ${remoteAttachment.url}`);
|
|
114866
116238
|
}
|
|
114867
|
-
const digestBytes = new Uint8Array(await
|
|
116239
|
+
const digestBytes = new Uint8Array(await import_node_crypto17.webcrypto.subtle.digest("SHA-256", payload));
|
|
114868
116240
|
const digest = etc.bytesToHex(digestBytes);
|
|
114869
116241
|
if (digest !== remoteAttachment.contentDigest) {
|
|
114870
116242
|
throw new Error("content digest does not match");
|
|
@@ -114888,7 +116260,7 @@ var init_dist6 = __esm({
|
|
|
114888
116260
|
return codec.decode(encodedContent, codecRegistry);
|
|
114889
116261
|
}
|
|
114890
116262
|
static async encodeEncrypted(content$1, codec) {
|
|
114891
|
-
const secret =
|
|
116263
|
+
const secret = import_node_crypto17.webcrypto.getRandomValues(new Uint8Array(32));
|
|
114892
116264
|
const encodedContent = import_proto.content.EncodedContent.encode(codec.encode(content$1, {
|
|
114893
116265
|
codecFor() {
|
|
114894
116266
|
return void 0;
|
|
@@ -114901,7 +116273,7 @@ var init_dist6 = __esm({
|
|
|
114901
116273
|
if (!salt || !nonce || !payload) {
|
|
114902
116274
|
throw new Error("missing encryption key");
|
|
114903
116275
|
}
|
|
114904
|
-
const digestBytes = new Uint8Array(await
|
|
116276
|
+
const digestBytes = new Uint8Array(await import_node_crypto17.webcrypto.subtle.digest("SHA-256", payload));
|
|
114905
116277
|
const digest = etc.bytesToHex(digestBytes);
|
|
114906
116278
|
return {
|
|
114907
116279
|
digest,
|
|
@@ -114957,7 +116329,7 @@ var init_dist6 = __esm({
|
|
|
114957
116329
|
// ../core/src/file-upload-safety.ts
|
|
114958
116330
|
function getUnsafeFileUploadReason(filePath, sensitiveUploadReg = []) {
|
|
114959
116331
|
const expanded = (0, import_node_path34.resolve)(expandHome(filePath));
|
|
114960
|
-
const target = (0,
|
|
116332
|
+
const target = (0, import_node_fs29.realpathSync)(expanded);
|
|
114961
116333
|
const targetName = (0, import_node_path34.basename)(target);
|
|
114962
116334
|
if (targetName === ".env" || targetName.startsWith(".env.")) {
|
|
114963
116335
|
return ".env";
|
|
@@ -115011,19 +116383,19 @@ function expandHome(filePath) {
|
|
|
115011
116383
|
return filePath;
|
|
115012
116384
|
}
|
|
115013
116385
|
function safeRealpath(path2) {
|
|
115014
|
-
if (!(0,
|
|
116386
|
+
if (!(0, import_node_fs29.existsSync)(path2)) {
|
|
115015
116387
|
return null;
|
|
115016
116388
|
}
|
|
115017
|
-
return (0,
|
|
116389
|
+
return (0, import_node_fs29.realpathSync)(path2);
|
|
115018
116390
|
}
|
|
115019
116391
|
function isPathInside(target, dir) {
|
|
115020
116392
|
return target === dir || target.startsWith(`${dir}${import_node_path34.sep}`);
|
|
115021
116393
|
}
|
|
115022
|
-
var
|
|
116394
|
+
var import_node_fs29, import_node_os11, import_node_path34, SENSITIVE_HOME_DIRS, SENSITIVE_HOME_FILES, UNSAFE_FILE_UPLOAD_MESSAGE;
|
|
115023
116395
|
var init_file_upload_safety = __esm({
|
|
115024
116396
|
"../core/src/file-upload-safety.ts"() {
|
|
115025
116397
|
"use strict";
|
|
115026
|
-
|
|
116398
|
+
import_node_fs29 = require("node:fs");
|
|
115027
116399
|
import_node_os11 = require("node:os");
|
|
115028
116400
|
import_node_path34 = require("node:path");
|
|
115029
116401
|
SENSITIVE_HOME_DIRS = [
|
|
@@ -115111,16 +116483,16 @@ async function uploadFile(params) {
|
|
|
115111
116483
|
return;
|
|
115112
116484
|
}
|
|
115113
116485
|
const maxFileSizeBytes = uploadConfig.maxFileSizeBytes;
|
|
115114
|
-
const fileSize = (0,
|
|
116486
|
+
const fileSize = (0, import_node_fs30.statSync)(params.filePath).size;
|
|
115115
116487
|
if (fileSize > maxFileSizeBytes) {
|
|
115116
116488
|
throw new Error(formatFileTooLargeMessage(maxFileSizeBytes));
|
|
115117
116489
|
}
|
|
115118
|
-
const data = (0,
|
|
116490
|
+
const data = (0, import_node_fs30.readFileSync)(params.filePath);
|
|
115119
116491
|
const attachment = { filename, mimeType, data: new Uint8Array(data) };
|
|
115120
116492
|
const encrypted = await RemoteAttachmentCodec.encodeEncrypted(attachment, new AttachmentCodec());
|
|
115121
116493
|
ensureFileDirs();
|
|
115122
|
-
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0,
|
|
115123
|
-
(0,
|
|
116494
|
+
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto18.randomUUID)()}.enc`);
|
|
116495
|
+
(0, import_node_fs30.writeFileSync)(encryptedPath, encrypted.payload);
|
|
115124
116496
|
try {
|
|
115125
116497
|
const stdout = runOnchainos([
|
|
115126
116498
|
"agent",
|
|
@@ -115156,14 +116528,14 @@ async function uploadFile(params) {
|
|
|
115156
116528
|
}, null, 2));
|
|
115157
116529
|
} finally {
|
|
115158
116530
|
try {
|
|
115159
|
-
(0,
|
|
116531
|
+
(0, import_node_fs30.unlinkSync)(encryptedPath);
|
|
115160
116532
|
} catch {
|
|
115161
116533
|
}
|
|
115162
116534
|
}
|
|
115163
116535
|
}
|
|
115164
116536
|
async function downloadFile(params) {
|
|
115165
116537
|
ensureFileDirs();
|
|
115166
|
-
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0,
|
|
116538
|
+
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto18.randomUUID)()}.enc`);
|
|
115167
116539
|
try {
|
|
115168
116540
|
const stdout = runOnchainos([
|
|
115169
116541
|
"agent",
|
|
@@ -115187,8 +116559,8 @@ async function downloadFile(params) {
|
|
|
115187
116559
|
}));
|
|
115188
116560
|
throw new Error(`file download failed: ${stdout}`);
|
|
115189
116561
|
}
|
|
115190
|
-
const payload = new Uint8Array((0,
|
|
115191
|
-
const digestBytes = new Uint8Array(await
|
|
116562
|
+
const payload = new Uint8Array((0, import_node_fs30.readFileSync)(encryptedPath));
|
|
116563
|
+
const digestBytes = new Uint8Array(await import_node_crypto18.webcrypto.subtle.digest("SHA-256", payload));
|
|
115192
116564
|
const actualDigest = Array.from(digestBytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
115193
116565
|
if (actualDigest !== params.digest) {
|
|
115194
116566
|
throw new Error(`file download digest verification failed: expected=${params.digest}, actual=${actualDigest}`);
|
|
@@ -115196,15 +116568,15 @@ async function downloadFile(params) {
|
|
|
115196
116568
|
const decryptedBytes = await decryptAttachmentPayload(payload, params);
|
|
115197
116569
|
const encodedContent = import_proto2.content.EncodedContent.decode(decryptedBytes);
|
|
115198
116570
|
const attachment = new AttachmentCodec().decode(encodedContent);
|
|
115199
|
-
const outputFilename = params.filename || attachment.filename || `${(0,
|
|
116571
|
+
const outputFilename = params.filename || attachment.filename || `${(0, import_node_crypto18.randomUUID)()}.bin`;
|
|
115200
116572
|
const outputDir = DOWNLOADS_DIR;
|
|
115201
116573
|
ensureA2aTaskDir(outputDir);
|
|
115202
116574
|
const outputPath = (0, import_node_path35.resolve)(outputDir, (0, import_node_path35.basename)(outputFilename));
|
|
115203
|
-
(0,
|
|
116575
|
+
(0, import_node_fs30.writeFileSync)(outputPath, attachment.data);
|
|
115204
116576
|
console.log(outputPath);
|
|
115205
116577
|
} finally {
|
|
115206
116578
|
try {
|
|
115207
|
-
(0,
|
|
116579
|
+
(0, import_node_fs30.unlinkSync)(encryptedPath);
|
|
115208
116580
|
} catch {
|
|
115209
116581
|
}
|
|
115210
116582
|
}
|
|
@@ -115213,15 +116585,15 @@ async function decryptAttachmentPayload(payload, params) {
|
|
|
115213
116585
|
const secretBytes = new Uint8Array(Buffer.from(params.secret, "base64"));
|
|
115214
116586
|
const saltBytes = new Uint8Array(Buffer.from(params.salt, "base64"));
|
|
115215
116587
|
const nonceBytes = new Uint8Array(Buffer.from(params.nonce, "base64"));
|
|
115216
|
-
const hkdfKey = await
|
|
115217
|
-
const aesKey = await
|
|
116588
|
+
const hkdfKey = await import_node_crypto18.webcrypto.subtle.importKey("raw", secretBytes, "HKDF", false, ["deriveKey"]);
|
|
116589
|
+
const aesKey = await import_node_crypto18.webcrypto.subtle.deriveKey(
|
|
115218
116590
|
{ name: "HKDF", hash: "SHA-256", salt: saltBytes, info: new Uint8Array().buffer },
|
|
115219
116591
|
hkdfKey,
|
|
115220
116592
|
{ name: "AES-GCM", length: 256 },
|
|
115221
116593
|
false,
|
|
115222
116594
|
["decrypt"]
|
|
115223
116595
|
);
|
|
115224
|
-
return new Uint8Array(await
|
|
116596
|
+
return new Uint8Array(await import_node_crypto18.webcrypto.subtle.decrypt({ name: "AES-GCM", iv: nonceBytes }, aesKey, toArrayBuffer(payload)));
|
|
115225
116597
|
}
|
|
115226
116598
|
function toArrayBuffer(bytes) {
|
|
115227
116599
|
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
@@ -115301,7 +116673,7 @@ function readUploadSystemConfig() {
|
|
|
115301
116673
|
const res = parseCliJson2(stdout, "system-config");
|
|
115302
116674
|
if (res.data && typeof res.data === "object") {
|
|
115303
116675
|
ensureA2aTaskDir(OKX_A2A_PATHS.xmtpDir);
|
|
115304
|
-
(0,
|
|
116676
|
+
(0, import_node_fs30.writeFileSync)(SYSTEM_CONFIG_PATH, JSON.stringify(res.data));
|
|
115305
116677
|
}
|
|
115306
116678
|
return parseUploadSystemConfig(res.data ?? {});
|
|
115307
116679
|
} catch {
|
|
@@ -115324,10 +116696,10 @@ function fileCliSentryExtra(operation, reason, extra = {}) {
|
|
|
115324
116696
|
}
|
|
115325
116697
|
function readSystemConfigFromCache() {
|
|
115326
116698
|
try {
|
|
115327
|
-
if (!(0,
|
|
116699
|
+
if (!(0, import_node_fs30.existsSync)(SYSTEM_CONFIG_PATH)) {
|
|
115328
116700
|
return null;
|
|
115329
116701
|
}
|
|
115330
|
-
return JSON.parse((0,
|
|
116702
|
+
return JSON.parse((0, import_node_fs30.readFileSync)(SYSTEM_CONFIG_PATH, "utf8"));
|
|
115331
116703
|
} catch {
|
|
115332
116704
|
return null;
|
|
115333
116705
|
}
|
|
@@ -115361,13 +116733,13 @@ function readRequiredOption(args, name) {
|
|
|
115361
116733
|
}
|
|
115362
116734
|
return value;
|
|
115363
116735
|
}
|
|
115364
|
-
var
|
|
116736
|
+
var import_node_crypto18, import_node_fs30, import_node_path35, import_proto2, OKX_A2A_PATHS, OKX_A2A_HOME_DIR, FILE_WORK_DIR, DOWNLOADS_DIR, SYSTEM_CONFIG_PATH;
|
|
115365
116737
|
var init_file_cli = __esm({
|
|
115366
116738
|
"src/file-cli.ts"() {
|
|
115367
116739
|
"use strict";
|
|
115368
116740
|
init_win_spawn();
|
|
115369
|
-
|
|
115370
|
-
|
|
116741
|
+
import_node_crypto18 = require("node:crypto");
|
|
116742
|
+
import_node_fs30 = require("node:fs");
|
|
115371
116743
|
import_node_path35 = require("node:path");
|
|
115372
116744
|
init_dist6();
|
|
115373
116745
|
import_proto2 = __toESM(require_node4());
|
|
@@ -115390,12 +116762,12 @@ __export(user_attention_cli_exports, {
|
|
|
115390
116762
|
});
|
|
115391
116763
|
async function handleUserCommand(args) {
|
|
115392
116764
|
const subcommand = args[0];
|
|
115393
|
-
if (!subcommand || args.every(
|
|
116765
|
+
if (!subcommand || args.every(isHelpArg3)) {
|
|
115394
116766
|
printUserUsage();
|
|
115395
116767
|
return;
|
|
115396
116768
|
}
|
|
115397
116769
|
if (subcommand === "help") {
|
|
115398
|
-
const helpTarget = args.slice(1).find((arg) => !
|
|
116770
|
+
const helpTarget = args.slice(1).find((arg) => !isHelpArg3(arg));
|
|
115399
116771
|
if (!helpTarget) {
|
|
115400
116772
|
printUserUsage();
|
|
115401
116773
|
return;
|
|
@@ -115412,7 +116784,7 @@ async function handleUserCommand(args) {
|
|
|
115412
116784
|
return;
|
|
115413
116785
|
}
|
|
115414
116786
|
const commandStartedAt = Date.now();
|
|
115415
|
-
const parsed =
|
|
116787
|
+
const parsed = parseArgs3(args.slice(1));
|
|
115416
116788
|
const json = parsed.flags.has("json");
|
|
115417
116789
|
const storeInitStartedAt = Date.now();
|
|
115418
116790
|
const store = new SessionStore();
|
|
@@ -115529,7 +116901,7 @@ async function handleUserCommand(args) {
|
|
|
115529
116901
|
function hasHelpFlag2(args) {
|
|
115530
116902
|
return args.some((arg) => arg === "-h" || arg === "--help");
|
|
115531
116903
|
}
|
|
115532
|
-
function
|
|
116904
|
+
function isHelpArg3(arg) {
|
|
115533
116905
|
return arg === "-h" || arg === "--help" || arg === "help";
|
|
115534
116906
|
}
|
|
115535
116907
|
function printUserUsage() {
|
|
@@ -115861,7 +117233,7 @@ async function watchUserAttentionViaDaemon(store, parsed, json, options) {
|
|
|
115861
117233
|
nextHeartbeatAt = Date.now() + Math.min(1e3, Math.max(100, pollMs));
|
|
115862
117234
|
}
|
|
115863
117235
|
const waitMs = deadline ? Math.max(0, Math.min(pollMs, USER_ATTENTION_WATCH_PARENT_CHECK_MS, deadline - Date.now())) : Math.min(pollMs, USER_ATTENTION_WATCH_PARENT_CHECK_MS);
|
|
115864
|
-
await
|
|
117236
|
+
await sleep5(waitMs);
|
|
115865
117237
|
}
|
|
115866
117238
|
} finally {
|
|
115867
117239
|
watcherCleanup.cleanup();
|
|
@@ -115881,7 +117253,7 @@ async function registerWatcherWithBusyRetry(options) {
|
|
|
115881
117253
|
if (!isSqliteBusyError(err2) || attempt >= attempts) {
|
|
115882
117254
|
throw err2;
|
|
115883
117255
|
}
|
|
115884
|
-
await
|
|
117256
|
+
await sleep5(250 * attempt);
|
|
115885
117257
|
}
|
|
115886
117258
|
}
|
|
115887
117259
|
}
|
|
@@ -116007,7 +117379,7 @@ function createWakeSignal() {
|
|
|
116007
117379
|
}
|
|
116008
117380
|
};
|
|
116009
117381
|
}
|
|
116010
|
-
function
|
|
117382
|
+
function sleep5(ms) {
|
|
116011
117383
|
return new Promise((resolve14) => setTimeout(resolve14, ms));
|
|
116012
117384
|
}
|
|
116013
117385
|
function output(json, payload, human) {
|
|
@@ -116048,7 +117420,7 @@ function runSyncWithoutConsoleOutput(fn) {
|
|
|
116048
117420
|
console.error = originalError;
|
|
116049
117421
|
}
|
|
116050
117422
|
}
|
|
116051
|
-
function
|
|
117423
|
+
function parseArgs3(args) {
|
|
116052
117424
|
const positional = [];
|
|
116053
117425
|
const options = /* @__PURE__ */ new Map();
|
|
116054
117426
|
const flags = /* @__PURE__ */ new Set();
|
|
@@ -116377,7 +117749,7 @@ function parseTelegramTopicSuffix3(parts) {
|
|
|
116377
117749
|
return parts.join(":");
|
|
116378
117750
|
}
|
|
116379
117751
|
function matchingParsedThreadId2(parsed, expected) {
|
|
116380
|
-
if (
|
|
117752
|
+
if (parsed?.platform !== expected.platform || parsed.chatId !== expected.chatId) {
|
|
116381
117753
|
return null;
|
|
116382
117754
|
}
|
|
116383
117755
|
return normalizeOptionalText3(parsed.threadId);
|
|
@@ -116502,12 +117874,12 @@ __export(session_cli_exports, {
|
|
|
116502
117874
|
});
|
|
116503
117875
|
async function handleSessionCommand(args) {
|
|
116504
117876
|
const subcommand = args[0];
|
|
116505
|
-
if (!subcommand || args.every(
|
|
117877
|
+
if (!subcommand || args.every(isHelpArg4)) {
|
|
116506
117878
|
printSessionUsage();
|
|
116507
117879
|
return;
|
|
116508
117880
|
}
|
|
116509
117881
|
if (subcommand === "help") {
|
|
116510
|
-
const helpTarget = args.slice(1).find((arg) => !
|
|
117882
|
+
const helpTarget = args.slice(1).find((arg) => !isHelpArg4(arg));
|
|
116511
117883
|
if (!helpTarget) {
|
|
116512
117884
|
printSessionUsage();
|
|
116513
117885
|
return;
|
|
@@ -116523,7 +117895,7 @@ async function handleSessionCommand(args) {
|
|
|
116523
117895
|
}
|
|
116524
117896
|
return;
|
|
116525
117897
|
}
|
|
116526
|
-
const parsed =
|
|
117898
|
+
const parsed = parseArgs4(args.slice(1));
|
|
116527
117899
|
const json = parsed.flags.has("json");
|
|
116528
117900
|
const store = new SessionStore();
|
|
116529
117901
|
let usedOpenClawGateway = false;
|
|
@@ -116689,9 +118061,9 @@ async function handleSessionCommand(args) {
|
|
|
116689
118061
|
}
|
|
116690
118062
|
}
|
|
116691
118063
|
function hasHelpFlag3(args) {
|
|
116692
|
-
return args.some(
|
|
118064
|
+
return args.some(isHelpArg4);
|
|
116693
118065
|
}
|
|
116694
|
-
function
|
|
118066
|
+
function isHelpArg4(arg) {
|
|
116695
118067
|
return arg === "-h" || arg === "--help" || arg === "help";
|
|
116696
118068
|
}
|
|
116697
118069
|
function printSessionUsage() {
|
|
@@ -117298,7 +118670,7 @@ function parseTelegramTopicSuffix4(parts) {
|
|
|
117298
118670
|
return parts.join(":");
|
|
117299
118671
|
}
|
|
117300
118672
|
function matchingParsedThreadId3(parsed, expected) {
|
|
117301
|
-
if (
|
|
118673
|
+
if (parsed?.platform !== expected.platform || parsed.chatId !== expected.chatId) {
|
|
117302
118674
|
return null;
|
|
117303
118675
|
}
|
|
117304
118676
|
return normalizeOptionalText4(parsed.threadId);
|
|
@@ -117497,7 +118869,7 @@ function normalizeOptionalText4(value) {
|
|
|
117497
118869
|
const normalized = value?.trim();
|
|
117498
118870
|
return normalized ? normalized : null;
|
|
117499
118871
|
}
|
|
117500
|
-
function
|
|
118872
|
+
function parseArgs4(args) {
|
|
117501
118873
|
const positional = [];
|
|
117502
118874
|
const options = /* @__PURE__ */ new Map();
|
|
117503
118875
|
const flags = /* @__PURE__ */ new Set();
|
|
@@ -117580,7 +118952,7 @@ async function handleXmtpDebugCli(args) {
|
|
|
117580
118952
|
throw new Error(`Unknown xmtp-debug command: ${subcommand}`);
|
|
117581
118953
|
}
|
|
117582
118954
|
const action = subcommand;
|
|
117583
|
-
const parsed =
|
|
118955
|
+
const parsed = parseArgs5(args.slice(1));
|
|
117584
118956
|
rejectAccountOverride(parsed);
|
|
117585
118957
|
const groupId = parsed.options.get("group-id");
|
|
117586
118958
|
const jobId = parsed.options.get("job-id");
|
|
@@ -117674,7 +119046,7 @@ Options:
|
|
|
117674
119046
|
--json Print machine-readable JSON.
|
|
117675
119047
|
`);
|
|
117676
119048
|
}
|
|
117677
|
-
function
|
|
119049
|
+
function parseArgs5(args) {
|
|
117678
119050
|
const options = /* @__PURE__ */ new Map();
|
|
117679
119051
|
const flags = /* @__PURE__ */ new Set();
|
|
117680
119052
|
for (let index2 = 0; index2 < args.length; index2 += 1) {
|
|
@@ -117762,7 +119134,7 @@ async function handleAiCommand(args) {
|
|
|
117762
119134
|
return;
|
|
117763
119135
|
}
|
|
117764
119136
|
const subcommand = args[0] ?? "status";
|
|
117765
|
-
const parsed =
|
|
119137
|
+
const parsed = parseArgs6(args.slice(1));
|
|
117766
119138
|
const json = parsed.flags.has("json");
|
|
117767
119139
|
const store = new SessionStore();
|
|
117768
119140
|
try {
|
|
@@ -117886,7 +119258,7 @@ function output4(json, payload, human) {
|
|
|
117886
119258
|
}
|
|
117887
119259
|
console.log(human);
|
|
117888
119260
|
}
|
|
117889
|
-
function
|
|
119261
|
+
function parseArgs6(args) {
|
|
117890
119262
|
const positional = [];
|
|
117891
119263
|
const options = /* @__PURE__ */ new Map();
|
|
117892
119264
|
const flags = /* @__PURE__ */ new Set();
|
|
@@ -117942,7 +119314,7 @@ function isPostjectRunnable() {
|
|
|
117942
119314
|
function resolvePostjectCommand() {
|
|
117943
119315
|
try {
|
|
117944
119316
|
const cliPath = (0, import_node_module.createRequire)(__filename).resolve("postject/dist/cli.js");
|
|
117945
|
-
if ((0,
|
|
119317
|
+
if ((0, import_node_fs31.existsSync)(cliPath)) {
|
|
117946
119318
|
return { command: process.execPath, prefixArgs: [cliPath] };
|
|
117947
119319
|
}
|
|
117948
119320
|
} catch {
|
|
@@ -118013,26 +119385,26 @@ function buildSeaConfig(entryPath, blobPath) {
|
|
|
118013
119385
|
}
|
|
118014
119386
|
async function installWindowsNativeLauncher(options) {
|
|
118015
119387
|
const nodeExe = options.nodeExe ?? process.execPath;
|
|
118016
|
-
if (!(0,
|
|
119388
|
+
if (!(0, import_node_fs31.existsSync)(options.cliPath)) {
|
|
118017
119389
|
throw new Error(`cannot build okx-a2a.exe: CLI entry not found at ${options.cliPath}`);
|
|
118018
119390
|
}
|
|
118019
|
-
if (!(0,
|
|
119391
|
+
if (!(0, import_node_fs31.existsSync)(nodeExe)) {
|
|
118020
119392
|
throw new Error(`cannot build okx-a2a.exe: node executable not found at ${nodeExe}`);
|
|
118021
119393
|
}
|
|
118022
119394
|
const exePath = (0, import_node_path36.join)(options.targetDir, NATIVE_LAUNCHER_EXE_NAME);
|
|
118023
|
-
(0,
|
|
118024
|
-
const work = (0,
|
|
119395
|
+
(0, import_node_fs31.mkdirSync)(options.targetDir, { recursive: true });
|
|
119396
|
+
const work = (0, import_node_fs31.mkdtempSync)((0, import_node_path36.join)((0, import_node_os12.tmpdir)(), "okx-a2a-sea-"));
|
|
118025
119397
|
try {
|
|
118026
119398
|
const entryPath = (0, import_node_path36.join)(work, "launcher-entry.js");
|
|
118027
119399
|
const blobPath = (0, import_node_path36.join)(work, "okx-a2a.blob");
|
|
118028
119400
|
const configPath = (0, import_node_path36.join)(work, "sea-config.json");
|
|
118029
|
-
(0,
|
|
118030
|
-
(0,
|
|
119401
|
+
(0, import_node_fs31.writeFileSync)(entryPath, buildLauncherEntryJs(options.cliPath), "utf8");
|
|
119402
|
+
(0, import_node_fs31.writeFileSync)(configPath, buildSeaConfig(entryPath, blobPath), "utf8");
|
|
118031
119403
|
(0, import_node_child_process9.execFileSync)(nodeExe, ["--experimental-sea-config", configPath], {
|
|
118032
119404
|
stdio: "ignore",
|
|
118033
119405
|
windowsHide: true
|
|
118034
119406
|
});
|
|
118035
|
-
(0,
|
|
119407
|
+
(0, import_node_fs31.copyFileSync)(nodeExe, exePath);
|
|
118036
119408
|
const isMac = process.platform === "darwin";
|
|
118037
119409
|
if (isMac) {
|
|
118038
119410
|
try {
|
|
@@ -118052,10 +119424,10 @@ async function installWindowsNativeLauncher(options) {
|
|
|
118052
119424
|
);
|
|
118053
119425
|
return { exePath, cliPath: options.cliPath, nodeExe };
|
|
118054
119426
|
} finally {
|
|
118055
|
-
(0,
|
|
119427
|
+
(0, import_node_fs31.rmSync)(work, { recursive: true, force: true });
|
|
118056
119428
|
}
|
|
118057
119429
|
}
|
|
118058
|
-
function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2 =
|
|
119430
|
+
function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2 = import_node_fs31.existsSync) {
|
|
118059
119431
|
const dirs = pathValue.split(";").map((d) => d.trim()).filter(Boolean);
|
|
118060
119432
|
if (appData) {
|
|
118061
119433
|
dirs.push((0, import_node_path36.join)(appData, "npm"));
|
|
@@ -118073,11 +119445,11 @@ function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2
|
|
|
118073
119445
|
}
|
|
118074
119446
|
function resolveRunningCliPath() {
|
|
118075
119447
|
const fromArgv = process.argv[1];
|
|
118076
|
-
if (fromArgv && /(?:^|[\\/])cli\.js$/.test(fromArgv) && (0,
|
|
119448
|
+
if (fromArgv && /(?:^|[\\/])cli\.js$/.test(fromArgv) && (0, import_node_fs31.existsSync)(fromArgv)) {
|
|
118077
119449
|
return fromArgv;
|
|
118078
119450
|
}
|
|
118079
119451
|
const beside = (0, import_node_path36.join)(__dirname, "cli.js");
|
|
118080
|
-
if ((0,
|
|
119452
|
+
if ((0, import_node_fs31.existsSync)(beside)) {
|
|
118081
119453
|
return beside;
|
|
118082
119454
|
}
|
|
118083
119455
|
if (fromArgv) {
|
|
@@ -118099,12 +119471,12 @@ async function ensureWindowsNativeLauncher(options = {}) {
|
|
|
118099
119471
|
const result = await installWindowsNativeLauncher({ cliPath: resolveRunningCliPath(), targetDir });
|
|
118100
119472
|
return { exePath: result.exePath, installed: true };
|
|
118101
119473
|
}
|
|
118102
|
-
var import_node_child_process9,
|
|
119474
|
+
var import_node_child_process9, import_node_fs31, import_node_module, import_node_os12, import_node_path36, SEA_SENTINEL_FUSE, NATIVE_LAUNCHER_EXE_NAME, POSTJECT_SPEC, POSTJECT_BIN;
|
|
118103
119475
|
var init_win_native_launcher = __esm({
|
|
118104
119476
|
"src/win-native-launcher.ts"() {
|
|
118105
119477
|
"use strict";
|
|
118106
119478
|
import_node_child_process9 = require("node:child_process");
|
|
118107
|
-
|
|
119479
|
+
import_node_fs31 = require("node:fs");
|
|
118108
119480
|
import_node_module = require("node:module");
|
|
118109
119481
|
import_node_os12 = require("node:os");
|
|
118110
119482
|
import_node_path36 = require("node:path");
|
|
@@ -118246,7 +119618,7 @@ function buildProviderMismatchWarning(target, provider) {
|
|
|
118246
119618
|
].join("\n");
|
|
118247
119619
|
}
|
|
118248
119620
|
async function handleUpdateCommand(args) {
|
|
118249
|
-
if (args.some(
|
|
119621
|
+
if (args.some(isHelpArg5)) {
|
|
118250
119622
|
printUpdateUsage();
|
|
118251
119623
|
return;
|
|
118252
119624
|
}
|
|
@@ -118287,7 +119659,7 @@ function resolveUpdateTarget(target) {
|
|
|
118287
119659
|
return detectGatewayInvocation() ?? "node";
|
|
118288
119660
|
}
|
|
118289
119661
|
async function handleSetupCommand(args) {
|
|
118290
|
-
if (args.some(
|
|
119662
|
+
if (args.some(isHelpArg5)) {
|
|
118291
119663
|
printSetupUsage();
|
|
118292
119664
|
return;
|
|
118293
119665
|
}
|
|
@@ -118864,7 +120236,7 @@ async function getCurrentNodeCliVersion() {
|
|
|
118864
120236
|
return await getGlobalNpmPackageVersion(UPDATE_PACKAGES.node) ?? getBundledNodeCliVersion();
|
|
118865
120237
|
}
|
|
118866
120238
|
function getBundledNodeCliVersion() {
|
|
118867
|
-
return true ? "0.2.
|
|
120239
|
+
return true ? "0.2.19-beta-fe6942ad54-261125201445" : null;
|
|
118868
120240
|
}
|
|
118869
120241
|
function readConfiguredAiProvider() {
|
|
118870
120242
|
const explicit = process.env.OKX_A2A_AI_PROVIDER || process.env.OKX_AGENT_TASK_AI_CLI;
|
|
@@ -119049,7 +120421,7 @@ async function updateHermes(release, options) {
|
|
|
119049
120421
|
assertNotRunningInsideGateway("hermes");
|
|
119050
120422
|
}
|
|
119051
120423
|
const spec = buildNpmPackageSpec("hermes", release);
|
|
119052
|
-
const workDir = await (0,
|
|
120424
|
+
const workDir = await (0, import_promises16.mkdtemp)((0, import_node_path37.join)((0, import_node_os13.tmpdir)(), `okx-a2a-${label}-hermes-`));
|
|
119053
120425
|
try {
|
|
119054
120426
|
console.log(`[${label}] downloading ${spec}`);
|
|
119055
120427
|
const npmTarball = await npmPack(spec, workDir);
|
|
@@ -119070,11 +120442,11 @@ async function updateHermes(release, options) {
|
|
|
119070
120442
|
}
|
|
119071
120443
|
console.log(`[${label}] hermes ${label} done`);
|
|
119072
120444
|
} finally {
|
|
119073
|
-
await (0,
|
|
120445
|
+
await (0, import_promises16.rm)(workDir, { recursive: true, force: true });
|
|
119074
120446
|
}
|
|
119075
120447
|
}
|
|
119076
120448
|
async function installGatewayPluginForDoctor(target) {
|
|
119077
|
-
const release = isPrereleaseVersion("0.2.
|
|
120449
|
+
const release = isPrereleaseVersion("0.2.19-beta-fe6942ad54-261125201445") ? "beta" : "latest";
|
|
119078
120450
|
const insideTargetGateway = detectGatewayInvocation() === target;
|
|
119079
120451
|
const options = {
|
|
119080
120452
|
restart: !insideTargetGateway,
|
|
@@ -119101,7 +120473,7 @@ function setupReadyMessage(target) {
|
|
|
119101
120473
|
async function normalizeHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPath()) {
|
|
119102
120474
|
let content2;
|
|
119103
120475
|
try {
|
|
119104
|
-
content2 = await (0,
|
|
120476
|
+
content2 = await (0, import_promises16.readFile)(configFile, "utf8");
|
|
119105
120477
|
} catch (error) {
|
|
119106
120478
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
119107
120479
|
return false;
|
|
@@ -119112,21 +120484,21 @@ async function normalizeHermesOkxA2aPluginConfig(configFile = resolveHermesConfi
|
|
|
119112
120484
|
if (!normalized.changed) {
|
|
119113
120485
|
return false;
|
|
119114
120486
|
}
|
|
119115
|
-
await (0,
|
|
120487
|
+
await (0, import_promises16.writeFile)(configFile, normalized.content);
|
|
119116
120488
|
console.log(`[update] normalized Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
119117
120489
|
return true;
|
|
119118
120490
|
}
|
|
119119
120491
|
async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPath(), options = {}) {
|
|
119120
120492
|
let content2;
|
|
119121
120493
|
try {
|
|
119122
|
-
content2 = await (0,
|
|
120494
|
+
content2 = await (0, import_promises16.readFile)(configFile, "utf8");
|
|
119123
120495
|
} catch (error) {
|
|
119124
120496
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
119125
120497
|
if (options.dryRun) {
|
|
119126
120498
|
return true;
|
|
119127
120499
|
}
|
|
119128
|
-
await (0,
|
|
119129
|
-
await (0,
|
|
120500
|
+
await (0, import_promises16.mkdir)((0, import_node_path37.resolve)(configFile, ".."), { recursive: true });
|
|
120501
|
+
await (0, import_promises16.writeFile)(configFile, "plugins:\n enabled:\n - okx-a2a\n");
|
|
119130
120502
|
console.log(`[update] added Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
119131
120503
|
return true;
|
|
119132
120504
|
}
|
|
@@ -119137,7 +120509,7 @@ async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPa
|
|
|
119137
120509
|
if (options.dryRun) {
|
|
119138
120510
|
return true;
|
|
119139
120511
|
}
|
|
119140
|
-
await (0,
|
|
120512
|
+
await (0, import_promises16.writeFile)(configFile, normalized.content);
|
|
119141
120513
|
console.log(`[update] normalized Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
119142
120514
|
return true;
|
|
119143
120515
|
}
|
|
@@ -119148,7 +120520,7 @@ async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPa
|
|
|
119148
120520
|
return true;
|
|
119149
120521
|
}
|
|
119150
120522
|
const updated = addHermesOkxA2aEnabled(content2);
|
|
119151
|
-
await (0,
|
|
120523
|
+
await (0, import_promises16.writeFile)(configFile, updated);
|
|
119152
120524
|
console.log(`[update] added Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
119153
120525
|
return true;
|
|
119154
120526
|
}
|
|
@@ -119449,7 +120821,7 @@ async function isGatewayPluginInstalled(target) {
|
|
|
119449
120821
|
if (target === "openclaw") {
|
|
119450
120822
|
return (await getInstalledOpenClawPluginInfo()).installed;
|
|
119451
120823
|
}
|
|
119452
|
-
return (0,
|
|
120824
|
+
return (0, import_node_fs32.existsSync)(resolveHermesPluginYamlPath());
|
|
119453
120825
|
}
|
|
119454
120826
|
async function getInstalledGatewayPluginVersion(target) {
|
|
119455
120827
|
if (target === "hermes") {
|
|
@@ -119538,7 +120910,7 @@ function parsePackageVersionFromText(output5) {
|
|
|
119538
120910
|
async function getInstalledHermesPluginVersion() {
|
|
119539
120911
|
const pluginYaml = (0, import_node_path37.join)(process.env.HERMES_HOME ?? (0, import_node_path37.join)((0, import_node_os13.homedir)(), ".hermes"), "plugins", "platforms", "okx-a2a", "plugin.yaml");
|
|
119540
120912
|
try {
|
|
119541
|
-
const content2 = await (0,
|
|
120913
|
+
const content2 = await (0, import_promises16.readFile)(pluginYaml, "utf8");
|
|
119542
120914
|
return parsePluginYamlVersion(content2);
|
|
119543
120915
|
} catch (error) {
|
|
119544
120916
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
@@ -119597,7 +120969,7 @@ async function npmPack(spec, destination) {
|
|
|
119597
120969
|
return (0, import_node_path37.resolve)(destination, (0, import_node_path37.basename)(tarballName));
|
|
119598
120970
|
}
|
|
119599
120971
|
async function findHermesPluginTarball(distDir) {
|
|
119600
|
-
const entries = await (0,
|
|
120972
|
+
const entries = await (0, import_promises16.readdir)(distDir);
|
|
119601
120973
|
const tarball = entries.find((entry) => /^okx-a2a-hermes-plugin-.+\.tar\.gz$/.test(entry));
|
|
119602
120974
|
if (!tarball) {
|
|
119603
120975
|
throw new Error(`Hermes npm package did not contain dist/okx-a2a-hermes-plugin-*.tar.gz`);
|
|
@@ -119605,7 +120977,7 @@ async function findHermesPluginTarball(distDir) {
|
|
|
119605
120977
|
return (0, import_node_path37.join)(distDir, tarball);
|
|
119606
120978
|
}
|
|
119607
120979
|
async function findFirstDirectory(parent) {
|
|
119608
|
-
const entries = await (0,
|
|
120980
|
+
const entries = await (0, import_promises16.readdir)(parent, { withFileTypes: true });
|
|
119609
120981
|
const dir = entries.find((entry) => entry.isDirectory());
|
|
119610
120982
|
if (!dir) {
|
|
119611
120983
|
throw new Error(`No unpacked plugin directory found under ${parent}`);
|
|
@@ -119622,7 +120994,7 @@ function readOption4(args, name) {
|
|
|
119622
120994
|
function hasFlag(args, name) {
|
|
119623
120995
|
return args.includes(name);
|
|
119624
120996
|
}
|
|
119625
|
-
function
|
|
120997
|
+
function isHelpArg5(value) {
|
|
119626
120998
|
return value === "-h" || value === "--help" || value === "help";
|
|
119627
120999
|
}
|
|
119628
121000
|
function isSupportedRelease(value) {
|
|
@@ -119831,13 +121203,13 @@ function buildExternalCommandInvocation(command, args, platform = process.platfo
|
|
|
119831
121203
|
function formatExternalCommand(command, args) {
|
|
119832
121204
|
return [command, ...args].join(" ");
|
|
119833
121205
|
}
|
|
119834
|
-
var import_node_child_process10,
|
|
121206
|
+
var import_node_child_process10, import_node_fs32, import_promises16, import_node_os13, import_node_path37, UPDATE_PACKAGES, CODEX_NPM_PACKAGE, OPENCLAW_FORCE_INSTALL_FLAG, OPENCLAW_UNSAFE_INSTALL_FLAG, OKX_A2A_PLUGIN_ID, OPENCLAW_SESSION_DM_SCOPE_CONFIG_PATH, OPENCLAW_SESSION_DM_SCOPE_CONFIG_VALUE, OPENCLAW_PLUGIN_ALLOW_CONFIG_PATH, OPENCLAW_OKX_A2A_CONVERSATION_HOOK_ACCESS_CONFIG_PATH, DEFAULT_AI_PROVIDER_LOGIN_TIMEOUT_MS, PROVIDER_CLI_AUTH_PROBE_TIMEOUT_MS, SetupBlockedError, redirectCommandStdoutToStderr;
|
|
119835
121207
|
var init_update_cli = __esm({
|
|
119836
121208
|
"src/update-cli.ts"() {
|
|
119837
121209
|
"use strict";
|
|
119838
121210
|
import_node_child_process10 = require("node:child_process");
|
|
119839
|
-
|
|
119840
|
-
|
|
121211
|
+
import_node_fs32 = require("node:fs");
|
|
121212
|
+
import_promises16 = require("node:fs/promises");
|
|
119841
121213
|
import_node_os13 = require("node:os");
|
|
119842
121214
|
import_node_path37 = require("node:path");
|
|
119843
121215
|
init_ai_command();
|
|
@@ -120127,7 +121499,7 @@ async function runDoctor(options = {}) {
|
|
|
120127
121499
|
platform: options.platform ?? process.platform,
|
|
120128
121500
|
env: options.env ?? process.env,
|
|
120129
121501
|
target: options.target ?? resolveDoctorTarget(options.env ?? process.env),
|
|
120130
|
-
cliVersion: options.cliVersion ?? (true ? "0.2.
|
|
121502
|
+
cliVersion: options.cliVersion ?? (true ? "0.2.19-beta-fe6942ad54-261125201445" : "0.0.0"),
|
|
120131
121503
|
fixMode: options.fix === true,
|
|
120132
121504
|
nonInteractive: options.nonInteractive === true,
|
|
120133
121505
|
packageChanged: false,
|
|
@@ -121105,7 +122477,7 @@ var init_doctor_cli = __esm({
|
|
|
121105
122477
|
title: "Daemon autostart",
|
|
121106
122478
|
status: "fail",
|
|
121107
122479
|
severity: "recommended",
|
|
121108
|
-
detail:
|
|
122480
|
+
detail: `OS autostart is not installed. This is OPTIONAL and NOT blocking \u2014 the daemon runs fine for this session; autostart only makes the A2A service start automatically on every boot/logon so you don't have to start it manually.${needsAdmin ? " On Windows this needs an Administrator terminal." : ""}`,
|
|
121109
122481
|
fix: needsAdmin ? {
|
|
121110
122482
|
kind: "manual",
|
|
121111
122483
|
description: "Optional: to start the A2A daemon automatically at every logon, run this once from an Administrator PowerShell. Skipping it is fine \u2014 just run `okx-a2a daemon start` when you need the daemon.",
|
|
@@ -121164,7 +122536,7 @@ var init_doctor_cli = __esm({
|
|
|
121164
122536
|
});
|
|
121165
122537
|
|
|
121166
122538
|
// src/cli.ts
|
|
121167
|
-
var
|
|
122539
|
+
var import_node_fs33 = require("node:fs");
|
|
121168
122540
|
var import_node_os14 = require("node:os");
|
|
121169
122541
|
var import_node_path39 = require("node:path");
|
|
121170
122542
|
init_daemon();
|
|
@@ -121234,7 +122606,7 @@ init_sentry_config();
|
|
|
121234
122606
|
init_runtime_metadata();
|
|
121235
122607
|
var CURRENT_GATEWAY_SESSION_KEYS_ENV4 = "OKX_A2A_CURRENT_GATEWAY_SESSION_KEYS";
|
|
121236
122608
|
function printUsage3() {
|
|
121237
|
-
console.log(`okx-a2a ${"0.2.
|
|
122609
|
+
console.log(`okx-a2a ${"0.2.19-beta-fe6942ad54-261125201445"}
|
|
121238
122610
|
|
|
121239
122611
|
Usage:
|
|
121240
122612
|
okx-a2a <command> [options]
|
|
@@ -121267,6 +122639,7 @@ Commands:
|
|
|
121267
122639
|
trade-records
|
|
121268
122640
|
Insert, query, and soft-delete local business trade records
|
|
121269
122641
|
capabilities Print machine-readable A2A capability negotiation status (used by OnchainOS)
|
|
122642
|
+
devkit Manage multiple loopback targets; unregister paired --url and --port or omit both to unregister all; localhost maps to IPv4 127.0.0.1; queued deliveries keep their snapshot and are not retracted
|
|
121270
122643
|
|
|
121271
122644
|
Global options:
|
|
121272
122645
|
-h, --help Show help
|
|
@@ -121276,7 +122649,7 @@ Run \`okx-a2a <command> -h\` for command-specific help.
|
|
|
121276
122649
|
`);
|
|
121277
122650
|
}
|
|
121278
122651
|
function printVersion() {
|
|
121279
|
-
console.log("0.2.
|
|
122652
|
+
console.log("0.2.19-beta-fe6942ad54-261125201445");
|
|
121280
122653
|
}
|
|
121281
122654
|
function printDaemonUsage() {
|
|
121282
122655
|
console.log(`Usage: okx-a2a daemon <start|restart|stop|status|autostart> [options]
|
|
@@ -121544,11 +122917,11 @@ Commands:
|
|
|
121544
122917
|
Print setup status JSON to stdout. Installer logs are written to stderr.
|
|
121545
122918
|
`);
|
|
121546
122919
|
}
|
|
121547
|
-
function
|
|
122920
|
+
function isHelpArg6(value) {
|
|
121548
122921
|
return value === "-h" || value === "--help" || value === "help";
|
|
121549
122922
|
}
|
|
121550
122923
|
function hasHelpFlag5(args) {
|
|
121551
|
-
return args.some(
|
|
122924
|
+
return args.some(isHelpArg6);
|
|
121552
122925
|
}
|
|
121553
122926
|
function isVersionArg(value) {
|
|
121554
122927
|
return value === "-v" || value === "--version" || value === "version";
|
|
@@ -121575,14 +122948,14 @@ function maybeRedirectDaemonSelfLog() {
|
|
|
121575
122948
|
}
|
|
121576
122949
|
try {
|
|
121577
122950
|
const logPath = resolveTaskPaths().listenerLogPath;
|
|
121578
|
-
(0,
|
|
121579
|
-
const fd = (0,
|
|
122951
|
+
(0, import_node_fs33.mkdirSync)((0, import_node_path39.join)(logPath, ".."), { recursive: true });
|
|
122952
|
+
const fd = (0, import_node_fs33.openSync)(logPath, "a");
|
|
121580
122953
|
const writeToLog = ((chunk, encoding, cb) => {
|
|
121581
122954
|
try {
|
|
121582
122955
|
if (typeof chunk === "string") {
|
|
121583
|
-
(0,
|
|
122956
|
+
(0, import_node_fs33.writeSync)(fd, chunk);
|
|
121584
122957
|
} else {
|
|
121585
|
-
(0,
|
|
122958
|
+
(0, import_node_fs33.writeSync)(fd, chunk);
|
|
121586
122959
|
}
|
|
121587
122960
|
} catch {
|
|
121588
122961
|
}
|
|
@@ -121932,12 +123305,12 @@ async function queueXmtpDaemonCommand(args, type) {
|
|
|
121932
123305
|
}
|
|
121933
123306
|
async function handleTaskCommand(args) {
|
|
121934
123307
|
const subcommand = args[0];
|
|
121935
|
-
if (!subcommand || args.every(
|
|
123308
|
+
if (!subcommand || args.every(isHelpArg6)) {
|
|
121936
123309
|
printTaskUsage();
|
|
121937
123310
|
return;
|
|
121938
123311
|
}
|
|
121939
123312
|
if (subcommand === "help") {
|
|
121940
|
-
const helpTarget = args.slice(1).find((arg) => !
|
|
123313
|
+
const helpTarget = args.slice(1).find((arg) => !isHelpArg6(arg));
|
|
121941
123314
|
if (!helpTarget) {
|
|
121942
123315
|
printTaskUsage();
|
|
121943
123316
|
return;
|
|
@@ -122626,10 +123999,10 @@ async function initDirectCliSentry() {
|
|
|
122626
123999
|
cliSentryInitAttempted = true;
|
|
122627
124000
|
try {
|
|
122628
124001
|
const configPath = (0, import_node_path39.join)(resolveTaskHomeForSentryConfig(), "xmtp", "system-config.json");
|
|
122629
|
-
if (!(0,
|
|
124002
|
+
if (!(0, import_node_fs33.existsSync)(configPath)) {
|
|
122630
124003
|
return;
|
|
122631
124004
|
}
|
|
122632
|
-
const config = JSON.parse((0,
|
|
124005
|
+
const config = JSON.parse((0, import_node_fs33.readFileSync)(configPath, "utf8"));
|
|
122633
124006
|
if (typeof config.sentryDsn !== "string" || !config.sentryDsn) {
|
|
122634
124007
|
return;
|
|
122635
124008
|
}
|
|
@@ -122691,7 +124064,7 @@ async function main() {
|
|
|
122691
124064
|
assertSupportedNodeVersion();
|
|
122692
124065
|
}
|
|
122693
124066
|
const args = process.argv.slice(3);
|
|
122694
|
-
if (
|
|
124067
|
+
if (isHelpArg6(command)) {
|
|
122695
124068
|
printUsage3();
|
|
122696
124069
|
return;
|
|
122697
124070
|
}
|
|
@@ -122712,6 +124085,15 @@ async function main() {
|
|
|
122712
124085
|
await handleTradeRecordsCommand2(args);
|
|
122713
124086
|
return;
|
|
122714
124087
|
}
|
|
124088
|
+
if (command === "devkit") {
|
|
124089
|
+
const { handleDevkitCommand: handleDevkitCommand2, printDevkitUsage: printDevkitUsage2 } = await Promise.resolve().then(() => (init_devkit_cli(), devkit_cli_exports));
|
|
124090
|
+
if (hasHelpFlag5(args)) {
|
|
124091
|
+
printDevkitUsage2();
|
|
124092
|
+
return;
|
|
124093
|
+
}
|
|
124094
|
+
await handleDevkitCommand2(args);
|
|
124095
|
+
return;
|
|
124096
|
+
}
|
|
122715
124097
|
if (command === "daemon") {
|
|
122716
124098
|
if (hasHelpFlag5(args)) {
|
|
122717
124099
|
printDaemonUsage();
|
|
@@ -122771,7 +124153,7 @@ async function main() {
|
|
|
122771
124153
|
if (command === "xmtp-test") {
|
|
122772
124154
|
const { handleXmtpTestCommand: handleXmtpTestCommand2 } = await Promise.resolve().then(() => (init_xmtp_test_cli(), xmtp_test_cli_exports));
|
|
122773
124155
|
await handleXmtpTestCommand2(process.argv.slice(3), {
|
|
122774
|
-
packageVersion: "0.2.
|
|
124156
|
+
packageVersion: "0.2.19-beta-fe6942ad54-261125201445",
|
|
122775
124157
|
agentSdkVersion: "2.3.1",
|
|
122776
124158
|
nodeSdkVersion: "6.1.1",
|
|
122777
124159
|
nodeBindingsVersion: "1.11.1"
|
|
@@ -122877,12 +124259,12 @@ function shouldDeferHelpToNestedHandler(command, args) {
|
|
|
122877
124259
|
return true;
|
|
122878
124260
|
}
|
|
122879
124261
|
if (command === "trade-records") {
|
|
122880
|
-
return args.some((arg) => !
|
|
124262
|
+
return args.some((arg) => !isHelpArg6(arg));
|
|
122881
124263
|
}
|
|
122882
124264
|
if (command !== "session" && command !== "user" && command !== "task") {
|
|
122883
124265
|
return false;
|
|
122884
124266
|
}
|
|
122885
|
-
return args.some((arg) => !
|
|
124267
|
+
return args.some((arg) => !isHelpArg6(arg));
|
|
122886
124268
|
}
|
|
122887
124269
|
main().then(() => {
|
|
122888
124270
|
if (cliSentryFlushTimedOut) {
|