@okxweb3/a2a-node 0.2.19-beta-fe6942ad54-261125201445 → 0.2.19
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 +199 -1558
- package/dist/index.js +109 -1470
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -114,8 +114,7 @@ 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")
|
|
118
|
-
devkitServerDbPath: (0, import_node_path2.join)(homeDir, "sqlite", DEVKIT_SERVER_DB_NAME)
|
|
117
|
+
listenerLogPath: (0, import_node_path2.join)(homeDir, "logs", "listener.log")
|
|
119
118
|
};
|
|
120
119
|
}
|
|
121
120
|
function ensureTaskHome(homeDir) {
|
|
@@ -127,14 +126,13 @@ function encodeJobIdForFile(jobId) {
|
|
|
127
126
|
function ensureTaskDir(dir) {
|
|
128
127
|
return ensureA2aTaskDir(dir);
|
|
129
128
|
}
|
|
130
|
-
var import_node_path2, BACKUP_JOB_ID
|
|
129
|
+
var import_node_path2, BACKUP_JOB_ID;
|
|
131
130
|
var init_paths = __esm({
|
|
132
131
|
"src/paths.ts"() {
|
|
133
132
|
"use strict";
|
|
134
133
|
import_node_path2 = require("node:path");
|
|
135
134
|
init_a2a_paths();
|
|
136
135
|
BACKUP_JOB_ID = "backup";
|
|
137
|
-
DEVKIT_SERVER_DB_NAME = "devkit-server.sqlite";
|
|
138
136
|
}
|
|
139
137
|
});
|
|
140
138
|
|
|
@@ -20057,25 +20055,7 @@ var init_events = __esm({
|
|
|
20057
20055
|
XMTP_DEBUG_SYNC_FAILED: "XMTP debug sync failed",
|
|
20058
20056
|
// Underlying XMTP SDK client close failed during recycle/removal/shutdown
|
|
20059
20057
|
// (DEXMARKET-9116). Error-level → NOT added to SENTRY_INFO_ALLOWLIST.
|
|
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"
|
|
20058
|
+
XMTP_CLIENT_CLOSE_FAILED: "XMTP client close failed"
|
|
20079
20059
|
};
|
|
20080
20060
|
}
|
|
20081
20061
|
});
|
|
@@ -20920,20 +20900,7 @@ var init_sentry_logger = __esm({
|
|
|
20920
20900
|
LogEvent.XMTP_RATE_LIMIT_COOLDOWN_STARTED,
|
|
20921
20901
|
LogEvent.XMTP_RATE_LIMIT_CREATE_SUPPRESSED,
|
|
20922
20902
|
LogEvent.XMTP_RATE_LIMIT_PROBE,
|
|
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
|
|
20903
|
+
LogEvent.XMTP_RATE_LIMIT_RECOVERED
|
|
20937
20904
|
]);
|
|
20938
20905
|
MAX_EXTRA_STRING_LENGTH = 256;
|
|
20939
20906
|
MAX_TAG_VALUE_LENGTH = 128;
|
|
@@ -27049,7 +27016,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
27049
27016
|
client: {
|
|
27050
27017
|
id: "gateway-client",
|
|
27051
27018
|
displayName: "okx-a2a-node",
|
|
27052
|
-
version: "0.2.19
|
|
27019
|
+
version: "0.2.19",
|
|
27053
27020
|
platform: "node",
|
|
27054
27021
|
mode: "backend",
|
|
27055
27022
|
instanceId
|
|
@@ -27060,7 +27027,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
27060
27027
|
commands: [],
|
|
27061
27028
|
permissions: {},
|
|
27062
27029
|
locale: Intl.DateTimeFormat().resolvedOptions().locale || "en-US",
|
|
27063
|
-
userAgent: `okx-a2a-node/${"0.2.19
|
|
27030
|
+
userAgent: `okx-a2a-node/${"0.2.19"}`,
|
|
27064
27031
|
auth: {
|
|
27065
27032
|
...config.token ? { token: config.token } : {},
|
|
27066
27033
|
...config.password ? { password: config.password } : {}
|
|
@@ -29119,7 +29086,7 @@ var init_sentry_config = __esm({
|
|
|
29119
29086
|
environment = process.env.SENTRY_ENV === "dev" ? "dev" : "prod";
|
|
29120
29087
|
SENTRY_CONFIG = {
|
|
29121
29088
|
projectName: "okx/openclaw-okx-a2a-extension",
|
|
29122
|
-
release: "0.2.19
|
|
29089
|
+
release: "0.2.19",
|
|
29123
29090
|
environment,
|
|
29124
29091
|
runtimeContainer: normalizeRuntimeContainer(process.env.OKX_A2A_RUNTIME_CONTAINER)
|
|
29125
29092
|
};
|
|
@@ -39689,8 +39656,8 @@ function readSqliteRows(dbPath, sql, params = []) {
|
|
|
39689
39656
|
if (!(0, import_node_fs17.existsSync)(dbPath)) {
|
|
39690
39657
|
throw unavailable(`SQLite database not found: ${dbPath}`);
|
|
39691
39658
|
}
|
|
39692
|
-
const { DatabaseSync:
|
|
39693
|
-
const db = new
|
|
39659
|
+
const { DatabaseSync: DatabaseSync5 } = loadSqlite3();
|
|
39660
|
+
const db = new DatabaseSync5(dbPath, { readOnly: true });
|
|
39694
39661
|
try {
|
|
39695
39662
|
return db.prepare(sql).all(...params);
|
|
39696
39663
|
} finally {
|
|
@@ -40289,7 +40256,7 @@ async function exportDiagnosticLogs(options) {
|
|
|
40289
40256
|
node: process.version,
|
|
40290
40257
|
platform: process.platform,
|
|
40291
40258
|
arch: process.arch,
|
|
40292
|
-
packageVersion: true ? "0.2.19
|
|
40259
|
+
packageVersion: true ? "0.2.19" : "unknown",
|
|
40293
40260
|
sensitiveContentIncluded: options.includeSensitiveContent,
|
|
40294
40261
|
listenerAndLlmContentIncluded: true,
|
|
40295
40262
|
credentialsAlwaysRedacted: true,
|
|
@@ -42294,755 +42261,6 @@ var init_trade_records_cli = __esm({
|
|
|
42294
42261
|
}
|
|
42295
42262
|
});
|
|
42296
42263
|
|
|
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
|
-
|
|
43046
42264
|
// ../core/src/xmtp-sdk/client-lifecycle.ts
|
|
43047
42265
|
async function stopAndCloseXmtpClient(agent, ctx) {
|
|
43048
42266
|
let stopped = true;
|
|
@@ -43188,7 +42406,7 @@ function isResolvedBinUsable(bin) {
|
|
|
43188
42406
|
if (!isPathLikeCommand(bin)) {
|
|
43189
42407
|
return true;
|
|
43190
42408
|
}
|
|
43191
|
-
return process.platform === "win32" ? (0,
|
|
42409
|
+
return process.platform === "win32" ? (0, import_node_fs22.existsSync)(bin) : isExecutable2(bin);
|
|
43192
42410
|
}
|
|
43193
42411
|
function resolvePosixBareCommand(command, pathValue) {
|
|
43194
42412
|
for (const dir of pathValue.split(":")) {
|
|
@@ -43525,7 +42743,7 @@ function isWindowsAppsAlias(candidate) {
|
|
|
43525
42743
|
return candidate.toLowerCase().includes(WINDOWS_APPS_ALIAS_MARKER);
|
|
43526
42744
|
}
|
|
43527
42745
|
function win32FileExists(path2) {
|
|
43528
|
-
return (0,
|
|
42746
|
+
return (0, import_node_fs22.existsSync)(path2);
|
|
43529
42747
|
}
|
|
43530
42748
|
function pickOnchainosWin32Candidate(lines, fileExists2 = win32FileExists) {
|
|
43531
42749
|
const candidates = lines.map((line) => {
|
|
@@ -43581,7 +42799,7 @@ function extractExecutablePath(stdout) {
|
|
|
43581
42799
|
}
|
|
43582
42800
|
function isExecutable2(path2) {
|
|
43583
42801
|
try {
|
|
43584
|
-
(0,
|
|
42802
|
+
(0, import_node_fs22.accessSync)(path2, import_node_fs22.constants.X_OK);
|
|
43585
42803
|
return true;
|
|
43586
42804
|
} catch {
|
|
43587
42805
|
return false;
|
|
@@ -43686,12 +42904,12 @@ async function exec(args, options = {}) {
|
|
|
43686
42904
|
}
|
|
43687
42905
|
throw new Error("OnchainOS command retry exhausted");
|
|
43688
42906
|
}
|
|
43689
|
-
var
|
|
42907
|
+
var import_node_fs22, 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;
|
|
43690
42908
|
var init_bin = __esm({
|
|
43691
42909
|
"../core/src/xmtp-sdk/onchainos/bin.ts"() {
|
|
43692
42910
|
"use strict";
|
|
43693
42911
|
init_log();
|
|
43694
|
-
|
|
42912
|
+
import_node_fs22 = require("node:fs");
|
|
43695
42913
|
import_node_child_process8 = require("node:child_process");
|
|
43696
42914
|
import_node_path25 = require("node:path");
|
|
43697
42915
|
import_node_util2 = require("node:util");
|
|
@@ -43755,12 +42973,12 @@ function createAsyncStreamProxy(stream) {
|
|
|
43755
42973
|
}
|
|
43756
42974
|
});
|
|
43757
42975
|
}
|
|
43758
|
-
var import_node_bindings, import_node_bindings2,
|
|
42976
|
+
var import_node_bindings, import_node_bindings2, import_node_crypto9, 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;
|
|
43759
42977
|
var init_dist2 = __esm({
|
|
43760
42978
|
"../../node_modules/@xmtp/node-sdk/dist/index.js"() {
|
|
43761
42979
|
import_node_bindings = require("@xmtp/node-bindings");
|
|
43762
42980
|
import_node_bindings2 = require("@xmtp/node-bindings");
|
|
43763
|
-
|
|
42981
|
+
import_node_crypto9 = require("node:crypto");
|
|
43764
42982
|
init_dist();
|
|
43765
42983
|
import_types = require("node:util/types");
|
|
43766
42984
|
import_node_path26 = require("node:path");
|
|
@@ -45522,7 +44740,7 @@ var init_dist2 = __esm({
|
|
|
45522
44740
|
return createBackend({ env: envOrBackend, gatewayHost });
|
|
45523
44741
|
};
|
|
45524
44742
|
createEphemeralIdentifier = () => ({
|
|
45525
|
-
identifier: `0x${(0,
|
|
44743
|
+
identifier: `0x${(0, import_node_crypto9.randomBytes)(20).toString("hex")}`,
|
|
45526
44744
|
identifierKind: 0
|
|
45527
44745
|
});
|
|
45528
44746
|
toInboxUpdatesCountMap = (value) => {
|
|
@@ -57771,20 +56989,20 @@ async function createRemoteAttachmentFromFile(unencryptedFile, uploadCallback) {
|
|
|
57771
56989
|
const fileUrl = await uploadCallback(encryptedAttachment);
|
|
57772
56990
|
return createRemoteAttachment(encryptedAttachment, fileUrl);
|
|
57773
56991
|
}
|
|
57774
|
-
var import_node_events,
|
|
56992
|
+
var import_node_events, import_node_fs23, import_node_path27, import_ts_retry_promise, import_node_crypto10, 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;
|
|
57775
56993
|
var init_dist4 = __esm({
|
|
57776
56994
|
"../../node_modules/@xmtp/agent-sdk/dist/index.js"() {
|
|
57777
56995
|
init_dist2();
|
|
57778
56996
|
init_dist2();
|
|
57779
56997
|
import_node_events = __toESM(require("node:events"), 1);
|
|
57780
|
-
|
|
56998
|
+
import_node_fs23 = __toESM(require("node:fs"), 1);
|
|
57781
56999
|
import_node_path27 = __toESM(require("node:path"), 1);
|
|
57782
57000
|
import_ts_retry_promise = __toESM(require_retry_promise(), 1);
|
|
57783
57001
|
init_dist3();
|
|
57784
57002
|
init_esm();
|
|
57785
57003
|
init_accounts();
|
|
57786
57004
|
init_chains();
|
|
57787
|
-
|
|
57005
|
+
import_node_crypto10 = require("node:crypto");
|
|
57788
57006
|
version2 = "2.3.1";
|
|
57789
57007
|
fromSelf = (message, client) => {
|
|
57790
57008
|
return message.senderInboxId === client.inboxId;
|
|
@@ -58144,7 +57362,7 @@ var init_dist4 = __esm({
|
|
|
58144
57362
|
initializedOptions.gatewayHost = XMTP_GATEWAY_HOST;
|
|
58145
57363
|
}
|
|
58146
57364
|
if (typeof XMTP_DB_DIRECTORY === "string") {
|
|
58147
|
-
|
|
57365
|
+
import_node_fs23.default.mkdirSync(XMTP_DB_DIRECTORY, { recursive: true, mode: 448 });
|
|
58148
57366
|
initializedOptions.dbPath = (inboxId) => {
|
|
58149
57367
|
const dbPath = import_node_path27.default.join(XMTP_DB_DIRECTORY, `xmtp-${inboxId}.db3`);
|
|
58150
57368
|
console.info(`Saving local database to "${dbPath}"`);
|
|
@@ -58454,7 +57672,7 @@ var init_dist4 = __esm({
|
|
|
58454
57672
|
return this.#client.accountIdentifier?.identifier;
|
|
58455
57673
|
}
|
|
58456
57674
|
};
|
|
58457
|
-
CANCEL_ACTION_ID = (0,
|
|
57675
|
+
CANCEL_ACTION_ID = (0, import_node_crypto10.randomUUID)();
|
|
58458
57676
|
LimitedMap = class {
|
|
58459
57677
|
#map = /* @__PURE__ */ new Map();
|
|
58460
57678
|
#limit;
|
|
@@ -59380,10 +58598,10 @@ function ensureCacheDir(dataDir) {
|
|
|
59380
58598
|
function loadSensitiveWordsFromCache(dataDir) {
|
|
59381
58599
|
try {
|
|
59382
58600
|
const path2 = cachePath(dataDir, "sensitive-words.json");
|
|
59383
|
-
if (!(0,
|
|
58601
|
+
if (!(0, import_node_fs24.existsSync)(path2)) {
|
|
59384
58602
|
return null;
|
|
59385
58603
|
}
|
|
59386
|
-
const data = JSON.parse((0,
|
|
58604
|
+
const data = JSON.parse((0, import_node_fs24.readFileSync)(path2, "utf-8"));
|
|
59387
58605
|
if (Array.isArray(data)) {
|
|
59388
58606
|
return data;
|
|
59389
58607
|
}
|
|
@@ -59397,7 +58615,7 @@ function loadSensitiveWordsFromCache(dataDir) {
|
|
|
59397
58615
|
function saveSensitiveWordsToCache(dataDir, words) {
|
|
59398
58616
|
try {
|
|
59399
58617
|
ensureCacheDir(dataDir);
|
|
59400
|
-
(0,
|
|
58618
|
+
(0, import_node_fs24.writeFileSync)(cachePath(dataDir, "sensitive-words.json"), JSON.stringify(words));
|
|
59401
58619
|
} catch (err2) {
|
|
59402
58620
|
logWithTimestamp(`[xmtp-sdk] failed to write sensitive-words.json:`, err2);
|
|
59403
58621
|
logger.error(LogEvent.CACHE_WRITE_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), { cacheName: "sensitive-words" });
|
|
@@ -59439,10 +58657,10 @@ async function loadSensitiveWordsWith(dataDir, fetcher) {
|
|
|
59439
58657
|
function loadSystemConfigFromCache(dataDir) {
|
|
59440
58658
|
try {
|
|
59441
58659
|
const path2 = cachePath(dataDir, "system-config.json");
|
|
59442
|
-
if (!(0,
|
|
58660
|
+
if (!(0, import_node_fs24.existsSync)(path2)) {
|
|
59443
58661
|
return null;
|
|
59444
58662
|
}
|
|
59445
|
-
const data = JSON.parse((0,
|
|
58663
|
+
const data = JSON.parse((0, import_node_fs24.readFileSync)(path2, "utf-8"));
|
|
59446
58664
|
if (data && typeof data === "object" && !Array.isArray(data)) {
|
|
59447
58665
|
return data;
|
|
59448
58666
|
}
|
|
@@ -59456,7 +58674,7 @@ function loadSystemConfigFromCache(dataDir) {
|
|
|
59456
58674
|
function saveSystemConfigToCache(dataDir, config) {
|
|
59457
58675
|
try {
|
|
59458
58676
|
ensureCacheDir(dataDir);
|
|
59459
|
-
(0,
|
|
58677
|
+
(0, import_node_fs24.writeFileSync)(cachePath(dataDir, "system-config.json"), JSON.stringify(config));
|
|
59460
58678
|
} catch (err2) {
|
|
59461
58679
|
logWithTimestamp(`[xmtp-sdk] failed to write system-config.json:`, err2);
|
|
59462
58680
|
logger.error(LogEvent.CACHE_WRITE_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), { cacheName: "system-config" });
|
|
@@ -59506,10 +58724,10 @@ function loadSyncByAddress(dataDir) {
|
|
|
59506
58724
|
const map = /* @__PURE__ */ new Map();
|
|
59507
58725
|
try {
|
|
59508
58726
|
const path2 = cachePath(dataDir, "last-sync.json");
|
|
59509
|
-
if (!(0,
|
|
58727
|
+
if (!(0, import_node_fs24.existsSync)(path2)) {
|
|
59510
58728
|
return map;
|
|
59511
58729
|
}
|
|
59512
|
-
const data = JSON.parse((0,
|
|
58730
|
+
const data = JSON.parse((0, import_node_fs24.readFileSync)(path2, "utf-8"));
|
|
59513
58731
|
const obj = data?.syncByAddress;
|
|
59514
58732
|
if (obj && typeof obj === "object" && !Array.isArray(obj)) {
|
|
59515
58733
|
for (const [addr, ts] of Object.entries(obj)) {
|
|
@@ -59528,9 +58746,9 @@ function saveSyncForAddress(dataDir, address, timestampMs) {
|
|
|
59528
58746
|
try {
|
|
59529
58747
|
let data = {};
|
|
59530
58748
|
const path2 = cachePath(dataDir, "last-sync.json");
|
|
59531
|
-
if ((0,
|
|
58749
|
+
if ((0, import_node_fs24.existsSync)(path2)) {
|
|
59532
58750
|
try {
|
|
59533
|
-
const raw = JSON.parse((0,
|
|
58751
|
+
const raw = JSON.parse((0, import_node_fs24.readFileSync)(path2, "utf-8"));
|
|
59534
58752
|
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
59535
58753
|
data = raw;
|
|
59536
58754
|
}
|
|
@@ -59541,7 +58759,7 @@ function saveSyncForAddress(dataDir, address, timestampMs) {
|
|
|
59541
58759
|
data.syncByAddress = {};
|
|
59542
58760
|
}
|
|
59543
58761
|
data.syncByAddress[address] = timestampMs;
|
|
59544
|
-
(0,
|
|
58762
|
+
(0, import_node_fs24.writeFileSync)(path2, JSON.stringify(data, null, 2));
|
|
59545
58763
|
} catch (err2) {
|
|
59546
58764
|
logWithTimestamp(
|
|
59547
58765
|
`[xmtp-sdk] failed to write last-sync.json (address=${address}):`,
|
|
@@ -59763,12 +58981,12 @@ function createOfflineReplayAddressSummary(address) {
|
|
|
59763
58981
|
durationMs: 0
|
|
59764
58982
|
};
|
|
59765
58983
|
}
|
|
59766
|
-
var
|
|
58984
|
+
var import_node_fs24, 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;
|
|
59767
58985
|
var init_xmtp_sdk = __esm({
|
|
59768
58986
|
"../core/src/xmtp-sdk/index.ts"() {
|
|
59769
58987
|
"use strict";
|
|
59770
58988
|
init_log();
|
|
59771
|
-
|
|
58989
|
+
import_node_fs24 = require("node:fs");
|
|
59772
58990
|
import_node_path28 = require("node:path");
|
|
59773
58991
|
init_dist4();
|
|
59774
58992
|
init_dist2();
|
|
@@ -63412,7 +62630,7 @@ var init_envelope = __esm({
|
|
|
63412
62630
|
});
|
|
63413
62631
|
|
|
63414
62632
|
// src/invalid-message-store.ts
|
|
63415
|
-
function
|
|
62633
|
+
function loadSqlite5() {
|
|
63416
62634
|
const originalEmitWarning = process.emitWarning;
|
|
63417
62635
|
process.emitWarning = ((warning, ...args) => {
|
|
63418
62636
|
const message = typeof warning === "string" ? warning : warning.message;
|
|
@@ -63427,22 +62645,22 @@ function loadSqlite6() {
|
|
|
63427
62645
|
process.emitWarning = originalEmitWarning;
|
|
63428
62646
|
}
|
|
63429
62647
|
}
|
|
63430
|
-
var
|
|
62648
|
+
var import_node_fs25, import_node_path29, DatabaseSync4, InvalidXmtpMessageStore;
|
|
63431
62649
|
var init_invalid_message_store = __esm({
|
|
63432
62650
|
"src/invalid-message-store.ts"() {
|
|
63433
62651
|
"use strict";
|
|
63434
|
-
|
|
62652
|
+
import_node_fs25 = require("node:fs");
|
|
63435
62653
|
import_node_path29 = require("node:path");
|
|
63436
62654
|
init_paths();
|
|
63437
|
-
({ DatabaseSync:
|
|
62655
|
+
({ DatabaseSync: DatabaseSync4 } = loadSqlite5());
|
|
63438
62656
|
InvalidXmtpMessageStore = class {
|
|
63439
62657
|
dbPath;
|
|
63440
62658
|
db;
|
|
63441
62659
|
constructor(homeDir) {
|
|
63442
62660
|
const paths = resolveTaskPaths(homeDir);
|
|
63443
62661
|
this.dbPath = (0, import_node_path29.join)(paths.sqliteDir, "invalid-xmtp-messages.sqlite");
|
|
63444
|
-
(0,
|
|
63445
|
-
this.db = new
|
|
62662
|
+
(0, import_node_fs25.mkdirSync)((0, import_node_path29.dirname)(this.dbPath), { recursive: true });
|
|
62663
|
+
this.db = new DatabaseSync4(this.dbPath);
|
|
63446
62664
|
this.ensureReady();
|
|
63447
62665
|
}
|
|
63448
62666
|
close() {
|
|
@@ -63818,14 +63036,14 @@ function buildSystemMessageIdempotencyKey(input) {
|
|
|
63818
63036
|
return `system-message:${identity}`;
|
|
63819
63037
|
}
|
|
63820
63038
|
function stableHash(value) {
|
|
63821
|
-
return (0,
|
|
63039
|
+
return (0, import_node_crypto11.createHash)("sha256").update(value).digest("hex").slice(0, 24);
|
|
63822
63040
|
}
|
|
63823
|
-
var
|
|
63041
|
+
var import_node_crypto11, DIRECTION_PREFIX, CONTENT_SEPARATOR, ADDRESS_SHORT_HEAD, ADDRESS_SHORT_TAIL, JOB_ID_HEAD, JOB_ID_TAIL, ELLIPSIS, CONTENT_MAX_LINES;
|
|
63824
63042
|
var init_agent_message_notice = __esm({
|
|
63825
63043
|
"src/agent-message-notice.ts"() {
|
|
63826
63044
|
"use strict";
|
|
63827
63045
|
init_log();
|
|
63828
|
-
|
|
63046
|
+
import_node_crypto11 = require("node:crypto");
|
|
63829
63047
|
init_session_store();
|
|
63830
63048
|
init_ai_provider();
|
|
63831
63049
|
init_outbound_behavior();
|
|
@@ -64308,7 +63526,7 @@ async function handleSqliteGroupSendCommand(params) {
|
|
|
64308
63526
|
role: senderAgent?.role,
|
|
64309
63527
|
sendDurationMs: Date.now() - sendStartMs
|
|
64310
63528
|
});
|
|
64311
|
-
const messageId = `outbound-${(0,
|
|
63529
|
+
const messageId = `outbound-${(0, import_node_crypto12.randomUUID)()}`;
|
|
64312
63530
|
await notifyAgentMessageToUserAttention({
|
|
64313
63531
|
direction: "outbound" /* OUTBOUND */,
|
|
64314
63532
|
sender: {
|
|
@@ -64429,7 +63647,7 @@ async function handleGroupSendCommand(params) {
|
|
|
64429
63647
|
sendDurationMs: Date.now() - sendStartMs
|
|
64430
63648
|
});
|
|
64431
63649
|
const now = Date.now();
|
|
64432
|
-
const messageId = `outbound-${(0,
|
|
63650
|
+
const messageId = `outbound-${(0, import_node_crypto12.randomUUID)()}`;
|
|
64433
63651
|
const stored = {
|
|
64434
63652
|
id: messageId,
|
|
64435
63653
|
direction: "outbound",
|
|
@@ -64648,7 +63866,7 @@ async function handleXmtpSendCommand(params) {
|
|
|
64648
63866
|
sendDurationMs: Date.now() - sendStartMs
|
|
64649
63867
|
});
|
|
64650
63868
|
const now = Date.now();
|
|
64651
|
-
const messageId = `outbound-${(0,
|
|
63869
|
+
const messageId = `outbound-${(0, import_node_crypto12.randomUUID)()}`;
|
|
64652
63870
|
const stored = {
|
|
64653
63871
|
id: messageId,
|
|
64654
63872
|
direction: "outbound",
|
|
@@ -64694,14 +63912,14 @@ async function handleXmtpSendCommand(params) {
|
|
|
64694
63912
|
ownedStore?.close();
|
|
64695
63913
|
}
|
|
64696
63914
|
}
|
|
64697
|
-
var
|
|
63915
|
+
var import_node_crypto12, TASK_MIN_VERSION, sqliteGroupSessionPromises, conversationSyncPromises, XMTP_SEND_CHECKPOINT, resolvedAgentByIdCache;
|
|
64698
63916
|
var init_xmtp_send = __esm({
|
|
64699
63917
|
"src/xmtp-send.ts"() {
|
|
64700
63918
|
"use strict";
|
|
64701
63919
|
init_log();
|
|
64702
63920
|
init_sentry_logger();
|
|
64703
63921
|
init_log_fields();
|
|
64704
|
-
|
|
63922
|
+
import_node_crypto12 = require("node:crypto");
|
|
64705
63923
|
init_dist2();
|
|
64706
63924
|
init_envelope();
|
|
64707
63925
|
init_concurrency2();
|
|
@@ -65240,7 +64458,7 @@ function safeProcessCwd() {
|
|
|
65240
64458
|
}
|
|
65241
64459
|
function isDirectory(path2) {
|
|
65242
64460
|
try {
|
|
65243
|
-
return (0,
|
|
64461
|
+
return (0, import_node_fs26.statSync)(path2).isDirectory();
|
|
65244
64462
|
} catch {
|
|
65245
64463
|
return false;
|
|
65246
64464
|
}
|
|
@@ -66566,7 +65784,7 @@ function normalizeAttentionProvider(provider) {
|
|
|
66566
65784
|
return provider === "unknown" ? null : provider;
|
|
66567
65785
|
}
|
|
66568
65786
|
function stableHash2(value) {
|
|
66569
|
-
return (0,
|
|
65787
|
+
return (0, import_node_crypto13.createHash)("sha256").update(value).digest("hex").slice(0, 24);
|
|
66570
65788
|
}
|
|
66571
65789
|
function formatCommand(args) {
|
|
66572
65790
|
return args.map(shellQuote).join(" ");
|
|
@@ -66590,13 +65808,13 @@ function shortenJobId2(jobId) {
|
|
|
66590
65808
|
}
|
|
66591
65809
|
return `${jobId.slice(0, 6)}\u2026${jobId.slice(-4)}`;
|
|
66592
65810
|
}
|
|
66593
|
-
var
|
|
65811
|
+
var import_node_crypto13, import_node_fs26, import_promises12, import_node_os9, import_node_path31, AiRunner, CODEX_TOOL_FAILURE_MARKER;
|
|
66594
65812
|
var init_ai_runner = __esm({
|
|
66595
65813
|
"src/ai-runner.ts"() {
|
|
66596
65814
|
"use strict";
|
|
66597
65815
|
init_log();
|
|
66598
|
-
|
|
66599
|
-
|
|
65816
|
+
import_node_crypto13 = require("node:crypto");
|
|
65817
|
+
import_node_fs26 = require("node:fs");
|
|
66600
65818
|
import_promises12 = require("node:fs/promises");
|
|
66601
65819
|
import_node_os9 = require("node:os");
|
|
66602
65820
|
import_node_path31 = require("node:path");
|
|
@@ -66744,7 +65962,7 @@ var init_ai_runner = __esm({
|
|
|
66744
65962
|
ensureTaskDir(this.logsDir);
|
|
66745
65963
|
const lifecycleLogsEnabled = isAiLifecycleLoggingEnabled();
|
|
66746
65964
|
const logPath = lifecycleLogsEnabled ? this.buildRunLogPath(request) : "";
|
|
66747
|
-
const log = lifecycleLogsEnabled ? (0,
|
|
65965
|
+
const log = lifecycleLogsEnabled ? (0, import_node_fs26.createWriteStream)(logPath, { flags: "a" }) : null;
|
|
66748
65966
|
let existing = null;
|
|
66749
65967
|
let storeReadStartedAt;
|
|
66750
65968
|
let storeReadEndedAt;
|
|
@@ -69216,428 +68434,6 @@ var init_command_processor = __esm({
|
|
|
69216
68434
|
}
|
|
69217
68435
|
});
|
|
69218
68436
|
|
|
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
|
-
|
|
69641
68437
|
// src/ai-dispatch-queue.ts
|
|
69642
68438
|
async function enqueueAiJobMessageDispatch(params) {
|
|
69643
68439
|
const commands = params.commands ?? new CommandStore(params.homeDir);
|
|
@@ -69669,127 +68465,6 @@ var init_ai_dispatch_queue = __esm({
|
|
|
69669
68465
|
}
|
|
69670
68466
|
});
|
|
69671
68467
|
|
|
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
|
-
|
|
69793
68468
|
// src/message-handler.ts
|
|
69794
68469
|
function tryMarkProcessed(messageId) {
|
|
69795
68470
|
if (processedMessageIds.has(messageId)) {
|
|
@@ -70779,7 +69454,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
70779
69454
|
timing.mark("payloadParse", parseStartedAt);
|
|
70780
69455
|
const directToUser = chatType === "dm" && parseResult.ok ? extractDirectToUserNotification(parseResult.data) : { kind: "none" };
|
|
70781
69456
|
if (directToUser.kind === "invalid") {
|
|
70782
|
-
const droppedMessageId = messageId || `direct-to-user-${(0,
|
|
69457
|
+
const droppedMessageId = messageId || `direct-to-user-${(0, import_node_crypto14.randomUUID)()}`;
|
|
70783
69458
|
logger.error(
|
|
70784
69459
|
LogEvent.INBOUND_DROP_DM_INVALID_PAYLOAD,
|
|
70785
69460
|
new Error("Invalid direct-to-user system DM"),
|
|
@@ -70803,7 +69478,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
70803
69478
|
await dispatchDirectToUserNotification({
|
|
70804
69479
|
deps,
|
|
70805
69480
|
notification: directToUser.notification,
|
|
70806
|
-
messageId: messageId || `direct-to-user-${(0,
|
|
69481
|
+
messageId: messageId || `direct-to-user-${(0, import_node_crypto14.randomUUID)()}`,
|
|
70807
69482
|
timing,
|
|
70808
69483
|
source: options.source ?? "live"
|
|
70809
69484
|
});
|
|
@@ -70811,7 +69486,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
70811
69486
|
}
|
|
70812
69487
|
const systemNotification = chatType === "dm" && parseResult.ok ? extractSystemNotification(parseResult.data) : null;
|
|
70813
69488
|
if (systemNotification) {
|
|
70814
|
-
const systemMessageId = messageId || `system-${(0,
|
|
69489
|
+
const systemMessageId = messageId || `system-${(0, import_node_crypto14.randomUUID)()}`;
|
|
70815
69490
|
logWithTimestamp(
|
|
70816
69491
|
`[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)}`
|
|
70817
69492
|
);
|
|
@@ -71107,7 +69782,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
71107
69782
|
}));
|
|
71108
69783
|
return true;
|
|
71109
69784
|
}
|
|
71110
|
-
const routedMessageId = messageId || `group-${(0,
|
|
69785
|
+
const routedMessageId = messageId || `group-${(0, import_node_crypto14.randomUUID)()}`;
|
|
71111
69786
|
const sessionKey = ensureInboundGroupSession(deps, {
|
|
71112
69787
|
jobId: route.jobId,
|
|
71113
69788
|
myAgentId,
|
|
@@ -71173,7 +69848,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
71173
69848
|
return true;
|
|
71174
69849
|
}
|
|
71175
69850
|
const stored = {
|
|
71176
|
-
id: messageId || `local-${(0,
|
|
69851
|
+
id: messageId || `local-${(0, import_node_crypto14.randomUUID)()}`,
|
|
71177
69852
|
direction: "inbound",
|
|
71178
69853
|
route: route.route,
|
|
71179
69854
|
routeReason: route.routeReason,
|
|
@@ -71354,7 +70029,7 @@ function processOfflineFromCoreDeps(store, ctx, deps, options) {
|
|
|
71354
70029
|
function buildSystemStoredMessage(params) {
|
|
71355
70030
|
const now = Date.now();
|
|
71356
70031
|
return {
|
|
71357
|
-
id: params.id ?? `system-${now}-${(0,
|
|
70032
|
+
id: params.id ?? `system-${now}-${(0, import_node_crypto14.randomUUID)()}`,
|
|
71358
70033
|
direction: "system",
|
|
71359
70034
|
route: "backup",
|
|
71360
70035
|
routeReason: params.reason,
|
|
@@ -71372,12 +70047,12 @@ function buildSystemStoredMessage(params) {
|
|
|
71372
70047
|
function isA2AEnvelope(payload) {
|
|
71373
70048
|
return isPlainObject3(payload) && payload.msgType === A2A_MESSAGE_TYPE;
|
|
71374
70049
|
}
|
|
71375
|
-
var
|
|
70050
|
+
var import_node_crypto14, PROCESSED_IDS_MAX, processedMessageIds, EXTERNAL_JOB_ID_PATTERN, INBOUND_TRANSPORT, INBOUND_EVENT_FAMILY, INBOUND_TERMINAL_FIELDS;
|
|
71376
70051
|
var init_message_handler = __esm({
|
|
71377
70052
|
"src/message-handler.ts"() {
|
|
71378
70053
|
"use strict";
|
|
71379
70054
|
init_log();
|
|
71380
|
-
|
|
70055
|
+
import_node_crypto14 = require("node:crypto");
|
|
71381
70056
|
init_dist2();
|
|
71382
70057
|
init_a2a();
|
|
71383
70058
|
init_envelope_shared();
|
|
@@ -71445,7 +70120,7 @@ function isOriginalParentProcessAlive(options) {
|
|
|
71445
70120
|
}
|
|
71446
70121
|
function registerUserAttentionWatcher(options) {
|
|
71447
70122
|
return options.store.registerUserAttentionWatcher({
|
|
71448
|
-
id: options.id ?? (0,
|
|
70123
|
+
id: options.id ?? (0, import_node_crypto15.randomUUID)(),
|
|
71449
70124
|
provider: options.provider,
|
|
71450
70125
|
jobId: options.jobId,
|
|
71451
70126
|
nowMs: options.nowMs ?? Date.now(),
|
|
@@ -71524,11 +70199,11 @@ function userWatchEventDeliveredSentryExtra(event) {
|
|
|
71524
70199
|
hasDecision: String(event.hasDecision)
|
|
71525
70200
|
};
|
|
71526
70201
|
}
|
|
71527
|
-
var
|
|
70202
|
+
var import_node_crypto15, USER_ATTENTION_WATCH_REPLACED_MESSAGE, USER_ATTENTION_WATCHER_SCAN_MS, USER_ATTENTION_WATCHER_TTL_MS, USER_ATTENTION_WATCH_PARENT_CHECK_MS;
|
|
71528
70203
|
var init_user_attention_watchers = __esm({
|
|
71529
70204
|
"src/user-attention-watchers.ts"() {
|
|
71530
70205
|
"use strict";
|
|
71531
|
-
|
|
70206
|
+
import_node_crypto15 = require("node:crypto");
|
|
71532
70207
|
init_sentry_logger();
|
|
71533
70208
|
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.";
|
|
71534
70209
|
USER_ATTENTION_WATCHER_SCAN_MS = 500;
|
|
@@ -71601,13 +70276,13 @@ async function getHermesGatewayPluginStatus(options = {}) {
|
|
|
71601
70276
|
const env = options.env ?? process.env;
|
|
71602
70277
|
const hermesHome = env.HERMES_HOME?.trim() || (0, import_node_path32.join)((0, import_node_os10.homedir)(), ".hermes");
|
|
71603
70278
|
const pluginYamlPath = (0, import_node_path32.join)(hermesHome, "plugins", "platforms", "okx-a2a", "plugin.yaml");
|
|
71604
|
-
if (!(0,
|
|
70279
|
+
if (!(0, import_node_fs27.existsSync)(pluginYamlPath)) {
|
|
71605
70280
|
return { enabled: false, reason: "plugin_yaml_missing", hermesHome, checkedPath: pluginYamlPath };
|
|
71606
70281
|
}
|
|
71607
70282
|
const configPath = (0, import_node_path32.join)(hermesHome, "config.yaml");
|
|
71608
70283
|
let content2;
|
|
71609
70284
|
try {
|
|
71610
|
-
content2 = await (0,
|
|
70285
|
+
content2 = await (0, import_promises13.readFile)(configPath, "utf8");
|
|
71611
70286
|
} catch {
|
|
71612
70287
|
return { enabled: false, reason: "config_read_error", hermesHome, checkedPath: configPath };
|
|
71613
70288
|
}
|
|
@@ -71728,27 +70403,6 @@ async function runListenerWithLock(options, paths) {
|
|
|
71728
70403
|
const store = new TaskMessageStore(options.homeDir);
|
|
71729
70404
|
const sessionStore = new SessionStore({ homeDir: options.homeDir });
|
|
71730
70405
|
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
|
-
});
|
|
71752
70406
|
await store.ensureReady();
|
|
71753
70407
|
let userAttentionEvents = null;
|
|
71754
70408
|
try {
|
|
@@ -71812,20 +70466,20 @@ async function runListenerWithLock(options, paths) {
|
|
|
71812
70466
|
createInboundMiddleware: (deps) => createMiddlewareFromCoreDeps(store, deps, {
|
|
71813
70467
|
sessionStore,
|
|
71814
70468
|
onJobMessageStored: async (event) => {
|
|
71815
|
-
await
|
|
70469
|
+
await enqueueAiJobMessageDispatch({ commands, event });
|
|
71816
70470
|
},
|
|
71817
70471
|
onSessionMessage: async (event) => {
|
|
71818
|
-
await
|
|
70472
|
+
await enqueueAiSessionMessageDispatch({ commands, event });
|
|
71819
70473
|
}
|
|
71820
70474
|
}),
|
|
71821
70475
|
processOfflineMessage: (ctx, deps, replayOptions) => processOfflineFromCoreDeps(store, ctx, deps, {
|
|
71822
70476
|
...replayOptions,
|
|
71823
70477
|
sessionStore,
|
|
71824
70478
|
onJobMessageStored: async (event) => {
|
|
71825
|
-
await
|
|
70479
|
+
await enqueueAiJobMessageDispatch({ commands, event });
|
|
71826
70480
|
},
|
|
71827
70481
|
onSessionMessage: async (event) => {
|
|
71828
|
-
await
|
|
70482
|
+
await enqueueAiSessionMessageDispatch({ commands, event });
|
|
71829
70483
|
}
|
|
71830
70484
|
}),
|
|
71831
70485
|
notifySessionExpired: (command) => {
|
|
@@ -71857,12 +70511,12 @@ async function runListenerWithLock(options, paths) {
|
|
|
71857
70511
|
});
|
|
71858
70512
|
}
|
|
71859
70513
|
});
|
|
71860
|
-
service.setPluginVersion("0.2.19
|
|
70514
|
+
service.setPluginVersion("0.2.19");
|
|
71861
70515
|
await service.init();
|
|
71862
70516
|
const pluginVersionStatus = service.pluginVersionStatus;
|
|
71863
70517
|
if (pluginVersionStatus.unavailable) {
|
|
71864
70518
|
throw new Error(
|
|
71865
|
-
`@okxweb3/a2a-node v${"0.2.19
|
|
70519
|
+
`@okxweb3/a2a-node v${"0.2.19"} is below the required minimum v${pluginVersionStatus.minVersion}`
|
|
71866
70520
|
);
|
|
71867
70521
|
}
|
|
71868
70522
|
const systemConfig = service.getSystemConfig();
|
|
@@ -71890,7 +70544,7 @@ async function runListenerWithLock(options, paths) {
|
|
|
71890
70544
|
onchainosAgentId: "*",
|
|
71891
70545
|
reason: "system-config missing sentryDsn",
|
|
71892
70546
|
pluginId: "@okxweb3/a2a-node",
|
|
71893
|
-
pluginVersion: "0.2.19
|
|
70547
|
+
pluginVersion: "0.2.19"
|
|
71894
70548
|
});
|
|
71895
70549
|
}
|
|
71896
70550
|
logWithTimestamp(
|
|
@@ -72222,7 +70876,6 @@ async function runListenerWithLock(options, paths) {
|
|
|
72222
70876
|
logWithTimestamp("[okx-agent-task] failed to close user_attention IPC wake:", err2);
|
|
72223
70877
|
}
|
|
72224
70878
|
stopClients(service);
|
|
72225
|
-
await devkitDispatcher.shutdown(SHUTDOWN_FORCE_RESOLVE_MS);
|
|
72226
70879
|
sessionStore.close();
|
|
72227
70880
|
clearTimeout(forceResolve);
|
|
72228
70881
|
resolve14();
|
|
@@ -72241,14 +70894,14 @@ async function timeSettled(fn) {
|
|
|
72241
70894
|
return { durationMs: Date.now() - startedAt, error };
|
|
72242
70895
|
}
|
|
72243
70896
|
}
|
|
72244
|
-
var
|
|
70897
|
+
var import_node_fs27, import_promises13, 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;
|
|
72245
70898
|
var init_listener = __esm({
|
|
72246
70899
|
"src/listener.ts"() {
|
|
72247
70900
|
"use strict";
|
|
72248
70901
|
init_log();
|
|
72249
70902
|
init_client_lifecycle();
|
|
72250
|
-
|
|
72251
|
-
|
|
70903
|
+
import_node_fs27 = require("node:fs");
|
|
70904
|
+
import_promises13 = require("node:fs/promises");
|
|
72252
70905
|
import_node_os10 = require("node:os");
|
|
72253
70906
|
import_node_path32 = require("node:path");
|
|
72254
70907
|
init_onchainos();
|
|
@@ -72261,9 +70914,7 @@ var init_listener = __esm({
|
|
|
72261
70914
|
init_session_store();
|
|
72262
70915
|
init_command_processor();
|
|
72263
70916
|
init_command_store();
|
|
72264
|
-
|
|
72265
|
-
init_devkit_router();
|
|
72266
|
-
init_devkit_server_store();
|
|
70917
|
+
init_ai_dispatch_queue();
|
|
72267
70918
|
init_message_handler();
|
|
72268
70919
|
init_agent_message_notice();
|
|
72269
70920
|
init_paths();
|
|
@@ -72516,7 +71167,7 @@ async function startXmtpTest(args, releaseInfo) {
|
|
|
72516
71167
|
const runId = requestedRunId ? validateRunId(requestedRunId) : createRunId(requestedName);
|
|
72517
71168
|
const files = resolveRunFiles(testsDir, runId);
|
|
72518
71169
|
try {
|
|
72519
|
-
await (0,
|
|
71170
|
+
await (0, import_promises14.stat)(files.runDir);
|
|
72520
71171
|
throw new Error(`XMTP test run already exists: ${runId}`);
|
|
72521
71172
|
} catch (error) {
|
|
72522
71173
|
if (error.code !== "ENOENT") {
|
|
@@ -72524,7 +71175,7 @@ async function startXmtpTest(args, releaseInfo) {
|
|
|
72524
71175
|
}
|
|
72525
71176
|
}
|
|
72526
71177
|
await ensurePrivateDir(files.runDir);
|
|
72527
|
-
await (0,
|
|
71178
|
+
await (0, import_promises14.writeFile)(files.eventsPath, "", { encoding: "utf8", mode: 384 });
|
|
72528
71179
|
const manifest = {
|
|
72529
71180
|
runId,
|
|
72530
71181
|
name: requestedName,
|
|
@@ -72568,7 +71219,7 @@ async function stopXmtpTest(args) {
|
|
|
72568
71219
|
}
|
|
72569
71220
|
const runId = validateRunId(active.runId);
|
|
72570
71221
|
const files = resolveRunFiles(testsDir, runId);
|
|
72571
|
-
await (0,
|
|
71222
|
+
await (0, import_promises14.unlink)(activePath);
|
|
72572
71223
|
const manifest = await readRequiredJson(files.manifestPath);
|
|
72573
71224
|
const completed = {
|
|
72574
71225
|
...manifest,
|
|
@@ -72886,7 +71537,7 @@ async function resolveRequestedRunId(testsDir, args, preferActive = false) {
|
|
|
72886
71537
|
async function findLatestRunId(testsDir) {
|
|
72887
71538
|
let entries;
|
|
72888
71539
|
try {
|
|
72889
|
-
entries = await (0,
|
|
71540
|
+
entries = await (0, import_promises14.readdir)(testsDir, { withFileTypes: true });
|
|
72890
71541
|
} catch (error) {
|
|
72891
71542
|
if (error.code === "ENOENT") {
|
|
72892
71543
|
return null;
|
|
@@ -72911,7 +71562,7 @@ async function findLatestRunId(testsDir) {
|
|
|
72911
71562
|
async function readMetricEvents(path2) {
|
|
72912
71563
|
let text;
|
|
72913
71564
|
try {
|
|
72914
|
-
text = await (0,
|
|
71565
|
+
text = await (0, import_promises14.readFile)(path2, "utf8");
|
|
72915
71566
|
} catch (error) {
|
|
72916
71567
|
if (error.code === "ENOENT") {
|
|
72917
71568
|
return [];
|
|
@@ -72935,9 +71586,9 @@ function parseMetricEvent(line) {
|
|
|
72935
71586
|
}
|
|
72936
71587
|
}
|
|
72937
71588
|
async function ensurePrivateDir(path2) {
|
|
72938
|
-
await (0,
|
|
71589
|
+
await (0, import_promises14.mkdir)(path2, { recursive: true, mode: 448 });
|
|
72939
71590
|
try {
|
|
72940
|
-
await (0,
|
|
71591
|
+
await (0, import_promises14.chmod)(path2, 448);
|
|
72941
71592
|
} catch (error) {
|
|
72942
71593
|
const code = error.code;
|
|
72943
71594
|
if (code !== "EPERM" && code !== "EACCES") {
|
|
@@ -72947,12 +71598,12 @@ async function ensurePrivateDir(path2) {
|
|
|
72947
71598
|
}
|
|
72948
71599
|
async function writeJson(path2, value) {
|
|
72949
71600
|
const temporary = `${path2}.${process.pid}.tmp`;
|
|
72950
|
-
await (0,
|
|
71601
|
+
await (0, import_promises14.writeFile)(temporary, `${JSON.stringify(value, null, 2)}
|
|
72951
71602
|
`, {
|
|
72952
71603
|
encoding: "utf8",
|
|
72953
71604
|
mode: 384
|
|
72954
71605
|
});
|
|
72955
|
-
await (0,
|
|
71606
|
+
await (0, import_promises14.rename)(temporary, path2);
|
|
72956
71607
|
}
|
|
72957
71608
|
async function readRequiredJson(path2) {
|
|
72958
71609
|
const value = await readJsonIfExists(path2);
|
|
@@ -72963,7 +71614,7 @@ async function readRequiredJson(path2) {
|
|
|
72963
71614
|
}
|
|
72964
71615
|
async function readJsonIfExists(path2) {
|
|
72965
71616
|
try {
|
|
72966
|
-
return JSON.parse(await (0,
|
|
71617
|
+
return JSON.parse(await (0, import_promises14.readFile)(path2, "utf8"));
|
|
72967
71618
|
} catch (error) {
|
|
72968
71619
|
if (error.code === "ENOENT") {
|
|
72969
71620
|
return null;
|
|
@@ -73134,11 +71785,11 @@ function formatPercent(value) {
|
|
|
73134
71785
|
function validTimestamp(value) {
|
|
73135
71786
|
return typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
73136
71787
|
}
|
|
73137
|
-
var
|
|
71788
|
+
var import_promises14, import_node_path33, RUN_ID_PATTERN2, ACTIVE_FILE;
|
|
73138
71789
|
var init_xmtp_test_cli = __esm({
|
|
73139
71790
|
"src/xmtp-test-cli.ts"() {
|
|
73140
71791
|
"use strict";
|
|
73141
|
-
|
|
71792
|
+
import_promises14 = require("node:fs/promises");
|
|
73142
71793
|
import_node_path33 = require("node:path");
|
|
73143
71794
|
init_daemon();
|
|
73144
71795
|
init_log_tail();
|
|
@@ -116117,10 +114768,10 @@ var require_node4 = __commonJS({
|
|
|
116117
114768
|
|
|
116118
114769
|
// ../../node_modules/@xmtp/content-type-remote-attachment/dist/index.js
|
|
116119
114770
|
async function encrypt(plain, secret, additionalData) {
|
|
116120
|
-
const salt =
|
|
116121
|
-
const nonce =
|
|
114771
|
+
const salt = import_node_crypto16.webcrypto.getRandomValues(new Uint8Array(KDFSaltSize));
|
|
114772
|
+
const nonce = import_node_crypto16.webcrypto.getRandomValues(new Uint8Array(AESGCMNonceSize));
|
|
116122
114773
|
const key = await hkdf(secret, salt);
|
|
116123
|
-
const encrypted = await
|
|
114774
|
+
const encrypted = await import_node_crypto16.webcrypto.subtle.encrypt(aesGcmParams(nonce), key, plain);
|
|
116124
114775
|
return new Ciphertext({
|
|
116125
114776
|
aes256GcmHkdfSha256: {
|
|
116126
114777
|
payload: new Uint8Array(encrypted),
|
|
@@ -116134,7 +114785,7 @@ async function decrypt(encrypted, secret, additionalData) {
|
|
|
116134
114785
|
throw new Error("invalid payload ciphertext");
|
|
116135
114786
|
}
|
|
116136
114787
|
const key = await hkdf(secret, encrypted.aes256GcmHkdfSha256.hkdfSalt);
|
|
116137
|
-
const decrypted = await
|
|
114788
|
+
const decrypted = await import_node_crypto16.webcrypto.subtle.decrypt(aesGcmParams(encrypted.aes256GcmHkdfSha256.gcmNonce), key, encrypted.aes256GcmHkdfSha256.payload);
|
|
116138
114789
|
return new Uint8Array(decrypted);
|
|
116139
114790
|
}
|
|
116140
114791
|
function aesGcmParams(nonce, additionalData) {
|
|
@@ -116145,18 +114796,18 @@ function aesGcmParams(nonce, additionalData) {
|
|
|
116145
114796
|
return spec;
|
|
116146
114797
|
}
|
|
116147
114798
|
async function hkdf(secret, salt) {
|
|
116148
|
-
const key = await
|
|
114799
|
+
const key = await import_node_crypto16.webcrypto.subtle.importKey("raw", secret, "HKDF", false, [
|
|
116149
114800
|
"deriveKey"
|
|
116150
114801
|
]);
|
|
116151
|
-
return
|
|
114802
|
+
return import_node_crypto16.webcrypto.subtle.deriveKey({ name: "HKDF", hash: "SHA-256", salt, info: hkdfNoInfo }, key, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
116152
114803
|
}
|
|
116153
|
-
var import_proto,
|
|
114804
|
+
var import_proto, import_node_crypto16, ContentTypeAttachment, AttachmentCodec, KDFSaltSize, AESGCMNonceSize, AESGCMTagLength, Ciphertext, hkdfNoInfo, ContentTypeRemoteAttachment, RemoteAttachmentCodec;
|
|
116154
114805
|
var init_dist6 = __esm({
|
|
116155
114806
|
"../../node_modules/@xmtp/content-type-remote-attachment/dist/index.js"() {
|
|
116156
114807
|
init_dist5();
|
|
116157
114808
|
init_secp256k12();
|
|
116158
114809
|
import_proto = __toESM(require_node4(), 1);
|
|
116159
|
-
|
|
114810
|
+
import_node_crypto16 = require("node:crypto");
|
|
116160
114811
|
ContentTypeAttachment = new ContentTypeId({
|
|
116161
114812
|
authorityId: "xmtp.org",
|
|
116162
114813
|
typeId: "attachment",
|
|
@@ -116236,7 +114887,7 @@ var init_dist6 = __esm({
|
|
|
116236
114887
|
if (payload.length === 0) {
|
|
116237
114888
|
throw new Error(`no payload for remote attachment at ${remoteAttachment.url}`);
|
|
116238
114889
|
}
|
|
116239
|
-
const digestBytes = new Uint8Array(await
|
|
114890
|
+
const digestBytes = new Uint8Array(await import_node_crypto16.webcrypto.subtle.digest("SHA-256", payload));
|
|
116240
114891
|
const digest = etc.bytesToHex(digestBytes);
|
|
116241
114892
|
if (digest !== remoteAttachment.contentDigest) {
|
|
116242
114893
|
throw new Error("content digest does not match");
|
|
@@ -116260,7 +114911,7 @@ var init_dist6 = __esm({
|
|
|
116260
114911
|
return codec.decode(encodedContent, codecRegistry);
|
|
116261
114912
|
}
|
|
116262
114913
|
static async encodeEncrypted(content$1, codec) {
|
|
116263
|
-
const secret =
|
|
114914
|
+
const secret = import_node_crypto16.webcrypto.getRandomValues(new Uint8Array(32));
|
|
116264
114915
|
const encodedContent = import_proto.content.EncodedContent.encode(codec.encode(content$1, {
|
|
116265
114916
|
codecFor() {
|
|
116266
114917
|
return void 0;
|
|
@@ -116273,7 +114924,7 @@ var init_dist6 = __esm({
|
|
|
116273
114924
|
if (!salt || !nonce || !payload) {
|
|
116274
114925
|
throw new Error("missing encryption key");
|
|
116275
114926
|
}
|
|
116276
|
-
const digestBytes = new Uint8Array(await
|
|
114927
|
+
const digestBytes = new Uint8Array(await import_node_crypto16.webcrypto.subtle.digest("SHA-256", payload));
|
|
116277
114928
|
const digest = etc.bytesToHex(digestBytes);
|
|
116278
114929
|
return {
|
|
116279
114930
|
digest,
|
|
@@ -116329,7 +114980,7 @@ var init_dist6 = __esm({
|
|
|
116329
114980
|
// ../core/src/file-upload-safety.ts
|
|
116330
114981
|
function getUnsafeFileUploadReason(filePath, sensitiveUploadReg = []) {
|
|
116331
114982
|
const expanded = (0, import_node_path34.resolve)(expandHome(filePath));
|
|
116332
|
-
const target = (0,
|
|
114983
|
+
const target = (0, import_node_fs28.realpathSync)(expanded);
|
|
116333
114984
|
const targetName = (0, import_node_path34.basename)(target);
|
|
116334
114985
|
if (targetName === ".env" || targetName.startsWith(".env.")) {
|
|
116335
114986
|
return ".env";
|
|
@@ -116383,19 +115034,19 @@ function expandHome(filePath) {
|
|
|
116383
115034
|
return filePath;
|
|
116384
115035
|
}
|
|
116385
115036
|
function safeRealpath(path2) {
|
|
116386
|
-
if (!(0,
|
|
115037
|
+
if (!(0, import_node_fs28.existsSync)(path2)) {
|
|
116387
115038
|
return null;
|
|
116388
115039
|
}
|
|
116389
|
-
return (0,
|
|
115040
|
+
return (0, import_node_fs28.realpathSync)(path2);
|
|
116390
115041
|
}
|
|
116391
115042
|
function isPathInside(target, dir) {
|
|
116392
115043
|
return target === dir || target.startsWith(`${dir}${import_node_path34.sep}`);
|
|
116393
115044
|
}
|
|
116394
|
-
var
|
|
115045
|
+
var import_node_fs28, import_node_os11, import_node_path34, SENSITIVE_HOME_DIRS, SENSITIVE_HOME_FILES, UNSAFE_FILE_UPLOAD_MESSAGE;
|
|
116395
115046
|
var init_file_upload_safety = __esm({
|
|
116396
115047
|
"../core/src/file-upload-safety.ts"() {
|
|
116397
115048
|
"use strict";
|
|
116398
|
-
|
|
115049
|
+
import_node_fs28 = require("node:fs");
|
|
116399
115050
|
import_node_os11 = require("node:os");
|
|
116400
115051
|
import_node_path34 = require("node:path");
|
|
116401
115052
|
SENSITIVE_HOME_DIRS = [
|
|
@@ -116483,16 +115134,16 @@ async function uploadFile(params) {
|
|
|
116483
115134
|
return;
|
|
116484
115135
|
}
|
|
116485
115136
|
const maxFileSizeBytes = uploadConfig.maxFileSizeBytes;
|
|
116486
|
-
const fileSize = (0,
|
|
115137
|
+
const fileSize = (0, import_node_fs29.statSync)(params.filePath).size;
|
|
116487
115138
|
if (fileSize > maxFileSizeBytes) {
|
|
116488
115139
|
throw new Error(formatFileTooLargeMessage(maxFileSizeBytes));
|
|
116489
115140
|
}
|
|
116490
|
-
const data = (0,
|
|
115141
|
+
const data = (0, import_node_fs29.readFileSync)(params.filePath);
|
|
116491
115142
|
const attachment = { filename, mimeType, data: new Uint8Array(data) };
|
|
116492
115143
|
const encrypted = await RemoteAttachmentCodec.encodeEncrypted(attachment, new AttachmentCodec());
|
|
116493
115144
|
ensureFileDirs();
|
|
116494
|
-
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0,
|
|
116495
|
-
(0,
|
|
115145
|
+
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto17.randomUUID)()}.enc`);
|
|
115146
|
+
(0, import_node_fs29.writeFileSync)(encryptedPath, encrypted.payload);
|
|
116496
115147
|
try {
|
|
116497
115148
|
const stdout = runOnchainos([
|
|
116498
115149
|
"agent",
|
|
@@ -116528,14 +115179,14 @@ async function uploadFile(params) {
|
|
|
116528
115179
|
}, null, 2));
|
|
116529
115180
|
} finally {
|
|
116530
115181
|
try {
|
|
116531
|
-
(0,
|
|
115182
|
+
(0, import_node_fs29.unlinkSync)(encryptedPath);
|
|
116532
115183
|
} catch {
|
|
116533
115184
|
}
|
|
116534
115185
|
}
|
|
116535
115186
|
}
|
|
116536
115187
|
async function downloadFile(params) {
|
|
116537
115188
|
ensureFileDirs();
|
|
116538
|
-
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0,
|
|
115189
|
+
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto17.randomUUID)()}.enc`);
|
|
116539
115190
|
try {
|
|
116540
115191
|
const stdout = runOnchainos([
|
|
116541
115192
|
"agent",
|
|
@@ -116559,8 +115210,8 @@ async function downloadFile(params) {
|
|
|
116559
115210
|
}));
|
|
116560
115211
|
throw new Error(`file download failed: ${stdout}`);
|
|
116561
115212
|
}
|
|
116562
|
-
const payload = new Uint8Array((0,
|
|
116563
|
-
const digestBytes = new Uint8Array(await
|
|
115213
|
+
const payload = new Uint8Array((0, import_node_fs29.readFileSync)(encryptedPath));
|
|
115214
|
+
const digestBytes = new Uint8Array(await import_node_crypto17.webcrypto.subtle.digest("SHA-256", payload));
|
|
116564
115215
|
const actualDigest = Array.from(digestBytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
116565
115216
|
if (actualDigest !== params.digest) {
|
|
116566
115217
|
throw new Error(`file download digest verification failed: expected=${params.digest}, actual=${actualDigest}`);
|
|
@@ -116568,15 +115219,15 @@ async function downloadFile(params) {
|
|
|
116568
115219
|
const decryptedBytes = await decryptAttachmentPayload(payload, params);
|
|
116569
115220
|
const encodedContent = import_proto2.content.EncodedContent.decode(decryptedBytes);
|
|
116570
115221
|
const attachment = new AttachmentCodec().decode(encodedContent);
|
|
116571
|
-
const outputFilename = params.filename || attachment.filename || `${(0,
|
|
115222
|
+
const outputFilename = params.filename || attachment.filename || `${(0, import_node_crypto17.randomUUID)()}.bin`;
|
|
116572
115223
|
const outputDir = DOWNLOADS_DIR;
|
|
116573
115224
|
ensureA2aTaskDir(outputDir);
|
|
116574
115225
|
const outputPath = (0, import_node_path35.resolve)(outputDir, (0, import_node_path35.basename)(outputFilename));
|
|
116575
|
-
(0,
|
|
115226
|
+
(0, import_node_fs29.writeFileSync)(outputPath, attachment.data);
|
|
116576
115227
|
console.log(outputPath);
|
|
116577
115228
|
} finally {
|
|
116578
115229
|
try {
|
|
116579
|
-
(0,
|
|
115230
|
+
(0, import_node_fs29.unlinkSync)(encryptedPath);
|
|
116580
115231
|
} catch {
|
|
116581
115232
|
}
|
|
116582
115233
|
}
|
|
@@ -116585,15 +115236,15 @@ async function decryptAttachmentPayload(payload, params) {
|
|
|
116585
115236
|
const secretBytes = new Uint8Array(Buffer.from(params.secret, "base64"));
|
|
116586
115237
|
const saltBytes = new Uint8Array(Buffer.from(params.salt, "base64"));
|
|
116587
115238
|
const nonceBytes = new Uint8Array(Buffer.from(params.nonce, "base64"));
|
|
116588
|
-
const hkdfKey = await
|
|
116589
|
-
const aesKey = await
|
|
115239
|
+
const hkdfKey = await import_node_crypto17.webcrypto.subtle.importKey("raw", secretBytes, "HKDF", false, ["deriveKey"]);
|
|
115240
|
+
const aesKey = await import_node_crypto17.webcrypto.subtle.deriveKey(
|
|
116590
115241
|
{ name: "HKDF", hash: "SHA-256", salt: saltBytes, info: new Uint8Array().buffer },
|
|
116591
115242
|
hkdfKey,
|
|
116592
115243
|
{ name: "AES-GCM", length: 256 },
|
|
116593
115244
|
false,
|
|
116594
115245
|
["decrypt"]
|
|
116595
115246
|
);
|
|
116596
|
-
return new Uint8Array(await
|
|
115247
|
+
return new Uint8Array(await import_node_crypto17.webcrypto.subtle.decrypt({ name: "AES-GCM", iv: nonceBytes }, aesKey, toArrayBuffer(payload)));
|
|
116597
115248
|
}
|
|
116598
115249
|
function toArrayBuffer(bytes) {
|
|
116599
115250
|
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
@@ -116673,7 +115324,7 @@ function readUploadSystemConfig() {
|
|
|
116673
115324
|
const res = parseCliJson2(stdout, "system-config");
|
|
116674
115325
|
if (res.data && typeof res.data === "object") {
|
|
116675
115326
|
ensureA2aTaskDir(OKX_A2A_PATHS.xmtpDir);
|
|
116676
|
-
(0,
|
|
115327
|
+
(0, import_node_fs29.writeFileSync)(SYSTEM_CONFIG_PATH, JSON.stringify(res.data));
|
|
116677
115328
|
}
|
|
116678
115329
|
return parseUploadSystemConfig(res.data ?? {});
|
|
116679
115330
|
} catch {
|
|
@@ -116696,10 +115347,10 @@ function fileCliSentryExtra(operation, reason, extra = {}) {
|
|
|
116696
115347
|
}
|
|
116697
115348
|
function readSystemConfigFromCache() {
|
|
116698
115349
|
try {
|
|
116699
|
-
if (!(0,
|
|
115350
|
+
if (!(0, import_node_fs29.existsSync)(SYSTEM_CONFIG_PATH)) {
|
|
116700
115351
|
return null;
|
|
116701
115352
|
}
|
|
116702
|
-
return JSON.parse((0,
|
|
115353
|
+
return JSON.parse((0, import_node_fs29.readFileSync)(SYSTEM_CONFIG_PATH, "utf8"));
|
|
116703
115354
|
} catch {
|
|
116704
115355
|
return null;
|
|
116705
115356
|
}
|
|
@@ -116733,13 +115384,13 @@ function readRequiredOption(args, name) {
|
|
|
116733
115384
|
}
|
|
116734
115385
|
return value;
|
|
116735
115386
|
}
|
|
116736
|
-
var
|
|
115387
|
+
var import_node_crypto17, import_node_fs29, import_node_path35, import_proto2, OKX_A2A_PATHS, OKX_A2A_HOME_DIR, FILE_WORK_DIR, DOWNLOADS_DIR, SYSTEM_CONFIG_PATH;
|
|
116737
115388
|
var init_file_cli = __esm({
|
|
116738
115389
|
"src/file-cli.ts"() {
|
|
116739
115390
|
"use strict";
|
|
116740
115391
|
init_win_spawn();
|
|
116741
|
-
|
|
116742
|
-
|
|
115392
|
+
import_node_crypto17 = require("node:crypto");
|
|
115393
|
+
import_node_fs29 = require("node:fs");
|
|
116743
115394
|
import_node_path35 = require("node:path");
|
|
116744
115395
|
init_dist6();
|
|
116745
115396
|
import_proto2 = __toESM(require_node4());
|
|
@@ -116762,12 +115413,12 @@ __export(user_attention_cli_exports, {
|
|
|
116762
115413
|
});
|
|
116763
115414
|
async function handleUserCommand(args) {
|
|
116764
115415
|
const subcommand = args[0];
|
|
116765
|
-
if (!subcommand || args.every(
|
|
115416
|
+
if (!subcommand || args.every(isHelpArg2)) {
|
|
116766
115417
|
printUserUsage();
|
|
116767
115418
|
return;
|
|
116768
115419
|
}
|
|
116769
115420
|
if (subcommand === "help") {
|
|
116770
|
-
const helpTarget = args.slice(1).find((arg) => !
|
|
115421
|
+
const helpTarget = args.slice(1).find((arg) => !isHelpArg2(arg));
|
|
116771
115422
|
if (!helpTarget) {
|
|
116772
115423
|
printUserUsage();
|
|
116773
115424
|
return;
|
|
@@ -116784,7 +115435,7 @@ async function handleUserCommand(args) {
|
|
|
116784
115435
|
return;
|
|
116785
115436
|
}
|
|
116786
115437
|
const commandStartedAt = Date.now();
|
|
116787
|
-
const parsed =
|
|
115438
|
+
const parsed = parseArgs2(args.slice(1));
|
|
116788
115439
|
const json = parsed.flags.has("json");
|
|
116789
115440
|
const storeInitStartedAt = Date.now();
|
|
116790
115441
|
const store = new SessionStore();
|
|
@@ -116901,7 +115552,7 @@ async function handleUserCommand(args) {
|
|
|
116901
115552
|
function hasHelpFlag2(args) {
|
|
116902
115553
|
return args.some((arg) => arg === "-h" || arg === "--help");
|
|
116903
115554
|
}
|
|
116904
|
-
function
|
|
115555
|
+
function isHelpArg2(arg) {
|
|
116905
115556
|
return arg === "-h" || arg === "--help" || arg === "help";
|
|
116906
115557
|
}
|
|
116907
115558
|
function printUserUsage() {
|
|
@@ -117233,7 +115884,7 @@ async function watchUserAttentionViaDaemon(store, parsed, json, options) {
|
|
|
117233
115884
|
nextHeartbeatAt = Date.now() + Math.min(1e3, Math.max(100, pollMs));
|
|
117234
115885
|
}
|
|
117235
115886
|
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);
|
|
117236
|
-
await
|
|
115887
|
+
await sleep4(waitMs);
|
|
117237
115888
|
}
|
|
117238
115889
|
} finally {
|
|
117239
115890
|
watcherCleanup.cleanup();
|
|
@@ -117253,7 +115904,7 @@ async function registerWatcherWithBusyRetry(options) {
|
|
|
117253
115904
|
if (!isSqliteBusyError(err2) || attempt >= attempts) {
|
|
117254
115905
|
throw err2;
|
|
117255
115906
|
}
|
|
117256
|
-
await
|
|
115907
|
+
await sleep4(250 * attempt);
|
|
117257
115908
|
}
|
|
117258
115909
|
}
|
|
117259
115910
|
}
|
|
@@ -117379,7 +116030,7 @@ function createWakeSignal() {
|
|
|
117379
116030
|
}
|
|
117380
116031
|
};
|
|
117381
116032
|
}
|
|
117382
|
-
function
|
|
116033
|
+
function sleep4(ms) {
|
|
117383
116034
|
return new Promise((resolve14) => setTimeout(resolve14, ms));
|
|
117384
116035
|
}
|
|
117385
116036
|
function output(json, payload, human) {
|
|
@@ -117420,7 +116071,7 @@ function runSyncWithoutConsoleOutput(fn) {
|
|
|
117420
116071
|
console.error = originalError;
|
|
117421
116072
|
}
|
|
117422
116073
|
}
|
|
117423
|
-
function
|
|
116074
|
+
function parseArgs2(args) {
|
|
117424
116075
|
const positional = [];
|
|
117425
116076
|
const options = /* @__PURE__ */ new Map();
|
|
117426
116077
|
const flags = /* @__PURE__ */ new Set();
|
|
@@ -117874,12 +116525,12 @@ __export(session_cli_exports, {
|
|
|
117874
116525
|
});
|
|
117875
116526
|
async function handleSessionCommand(args) {
|
|
117876
116527
|
const subcommand = args[0];
|
|
117877
|
-
if (!subcommand || args.every(
|
|
116528
|
+
if (!subcommand || args.every(isHelpArg3)) {
|
|
117878
116529
|
printSessionUsage();
|
|
117879
116530
|
return;
|
|
117880
116531
|
}
|
|
117881
116532
|
if (subcommand === "help") {
|
|
117882
|
-
const helpTarget = args.slice(1).find((arg) => !
|
|
116533
|
+
const helpTarget = args.slice(1).find((arg) => !isHelpArg3(arg));
|
|
117883
116534
|
if (!helpTarget) {
|
|
117884
116535
|
printSessionUsage();
|
|
117885
116536
|
return;
|
|
@@ -117895,7 +116546,7 @@ async function handleSessionCommand(args) {
|
|
|
117895
116546
|
}
|
|
117896
116547
|
return;
|
|
117897
116548
|
}
|
|
117898
|
-
const parsed =
|
|
116549
|
+
const parsed = parseArgs3(args.slice(1));
|
|
117899
116550
|
const json = parsed.flags.has("json");
|
|
117900
116551
|
const store = new SessionStore();
|
|
117901
116552
|
let usedOpenClawGateway = false;
|
|
@@ -118061,9 +116712,9 @@ async function handleSessionCommand(args) {
|
|
|
118061
116712
|
}
|
|
118062
116713
|
}
|
|
118063
116714
|
function hasHelpFlag3(args) {
|
|
118064
|
-
return args.some(
|
|
116715
|
+
return args.some(isHelpArg3);
|
|
118065
116716
|
}
|
|
118066
|
-
function
|
|
116717
|
+
function isHelpArg3(arg) {
|
|
118067
116718
|
return arg === "-h" || arg === "--help" || arg === "help";
|
|
118068
116719
|
}
|
|
118069
116720
|
function printSessionUsage() {
|
|
@@ -118869,7 +117520,7 @@ function normalizeOptionalText4(value) {
|
|
|
118869
117520
|
const normalized = value?.trim();
|
|
118870
117521
|
return normalized ? normalized : null;
|
|
118871
117522
|
}
|
|
118872
|
-
function
|
|
117523
|
+
function parseArgs3(args) {
|
|
118873
117524
|
const positional = [];
|
|
118874
117525
|
const options = /* @__PURE__ */ new Map();
|
|
118875
117526
|
const flags = /* @__PURE__ */ new Set();
|
|
@@ -118952,7 +117603,7 @@ async function handleXmtpDebugCli(args) {
|
|
|
118952
117603
|
throw new Error(`Unknown xmtp-debug command: ${subcommand}`);
|
|
118953
117604
|
}
|
|
118954
117605
|
const action = subcommand;
|
|
118955
|
-
const parsed =
|
|
117606
|
+
const parsed = parseArgs4(args.slice(1));
|
|
118956
117607
|
rejectAccountOverride(parsed);
|
|
118957
117608
|
const groupId = parsed.options.get("group-id");
|
|
118958
117609
|
const jobId = parsed.options.get("job-id");
|
|
@@ -119046,7 +117697,7 @@ Options:
|
|
|
119046
117697
|
--json Print machine-readable JSON.
|
|
119047
117698
|
`);
|
|
119048
117699
|
}
|
|
119049
|
-
function
|
|
117700
|
+
function parseArgs4(args) {
|
|
119050
117701
|
const options = /* @__PURE__ */ new Map();
|
|
119051
117702
|
const flags = /* @__PURE__ */ new Set();
|
|
119052
117703
|
for (let index2 = 0; index2 < args.length; index2 += 1) {
|
|
@@ -119134,7 +117785,7 @@ async function handleAiCommand(args) {
|
|
|
119134
117785
|
return;
|
|
119135
117786
|
}
|
|
119136
117787
|
const subcommand = args[0] ?? "status";
|
|
119137
|
-
const parsed =
|
|
117788
|
+
const parsed = parseArgs5(args.slice(1));
|
|
119138
117789
|
const json = parsed.flags.has("json");
|
|
119139
117790
|
const store = new SessionStore();
|
|
119140
117791
|
try {
|
|
@@ -119258,7 +117909,7 @@ function output4(json, payload, human) {
|
|
|
119258
117909
|
}
|
|
119259
117910
|
console.log(human);
|
|
119260
117911
|
}
|
|
119261
|
-
function
|
|
117912
|
+
function parseArgs5(args) {
|
|
119262
117913
|
const positional = [];
|
|
119263
117914
|
const options = /* @__PURE__ */ new Map();
|
|
119264
117915
|
const flags = /* @__PURE__ */ new Set();
|
|
@@ -119314,7 +117965,7 @@ function isPostjectRunnable() {
|
|
|
119314
117965
|
function resolvePostjectCommand() {
|
|
119315
117966
|
try {
|
|
119316
117967
|
const cliPath = (0, import_node_module.createRequire)(__filename).resolve("postject/dist/cli.js");
|
|
119317
|
-
if ((0,
|
|
117968
|
+
if ((0, import_node_fs30.existsSync)(cliPath)) {
|
|
119318
117969
|
return { command: process.execPath, prefixArgs: [cliPath] };
|
|
119319
117970
|
}
|
|
119320
117971
|
} catch {
|
|
@@ -119385,26 +118036,26 @@ function buildSeaConfig(entryPath, blobPath) {
|
|
|
119385
118036
|
}
|
|
119386
118037
|
async function installWindowsNativeLauncher(options) {
|
|
119387
118038
|
const nodeExe = options.nodeExe ?? process.execPath;
|
|
119388
|
-
if (!(0,
|
|
118039
|
+
if (!(0, import_node_fs30.existsSync)(options.cliPath)) {
|
|
119389
118040
|
throw new Error(`cannot build okx-a2a.exe: CLI entry not found at ${options.cliPath}`);
|
|
119390
118041
|
}
|
|
119391
|
-
if (!(0,
|
|
118042
|
+
if (!(0, import_node_fs30.existsSync)(nodeExe)) {
|
|
119392
118043
|
throw new Error(`cannot build okx-a2a.exe: node executable not found at ${nodeExe}`);
|
|
119393
118044
|
}
|
|
119394
118045
|
const exePath = (0, import_node_path36.join)(options.targetDir, NATIVE_LAUNCHER_EXE_NAME);
|
|
119395
|
-
(0,
|
|
119396
|
-
const work = (0,
|
|
118046
|
+
(0, import_node_fs30.mkdirSync)(options.targetDir, { recursive: true });
|
|
118047
|
+
const work = (0, import_node_fs30.mkdtempSync)((0, import_node_path36.join)((0, import_node_os12.tmpdir)(), "okx-a2a-sea-"));
|
|
119397
118048
|
try {
|
|
119398
118049
|
const entryPath = (0, import_node_path36.join)(work, "launcher-entry.js");
|
|
119399
118050
|
const blobPath = (0, import_node_path36.join)(work, "okx-a2a.blob");
|
|
119400
118051
|
const configPath = (0, import_node_path36.join)(work, "sea-config.json");
|
|
119401
|
-
(0,
|
|
119402
|
-
(0,
|
|
118052
|
+
(0, import_node_fs30.writeFileSync)(entryPath, buildLauncherEntryJs(options.cliPath), "utf8");
|
|
118053
|
+
(0, import_node_fs30.writeFileSync)(configPath, buildSeaConfig(entryPath, blobPath), "utf8");
|
|
119403
118054
|
(0, import_node_child_process9.execFileSync)(nodeExe, ["--experimental-sea-config", configPath], {
|
|
119404
118055
|
stdio: "ignore",
|
|
119405
118056
|
windowsHide: true
|
|
119406
118057
|
});
|
|
119407
|
-
(0,
|
|
118058
|
+
(0, import_node_fs30.copyFileSync)(nodeExe, exePath);
|
|
119408
118059
|
const isMac = process.platform === "darwin";
|
|
119409
118060
|
if (isMac) {
|
|
119410
118061
|
try {
|
|
@@ -119424,10 +118075,10 @@ async function installWindowsNativeLauncher(options) {
|
|
|
119424
118075
|
);
|
|
119425
118076
|
return { exePath, cliPath: options.cliPath, nodeExe };
|
|
119426
118077
|
} finally {
|
|
119427
|
-
(0,
|
|
118078
|
+
(0, import_node_fs30.rmSync)(work, { recursive: true, force: true });
|
|
119428
118079
|
}
|
|
119429
118080
|
}
|
|
119430
|
-
function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2 =
|
|
118081
|
+
function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2 = import_node_fs30.existsSync) {
|
|
119431
118082
|
const dirs = pathValue.split(";").map((d) => d.trim()).filter(Boolean);
|
|
119432
118083
|
if (appData) {
|
|
119433
118084
|
dirs.push((0, import_node_path36.join)(appData, "npm"));
|
|
@@ -119445,11 +118096,11 @@ function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2
|
|
|
119445
118096
|
}
|
|
119446
118097
|
function resolveRunningCliPath() {
|
|
119447
118098
|
const fromArgv = process.argv[1];
|
|
119448
|
-
if (fromArgv && /(?:^|[\\/])cli\.js$/.test(fromArgv) && (0,
|
|
118099
|
+
if (fromArgv && /(?:^|[\\/])cli\.js$/.test(fromArgv) && (0, import_node_fs30.existsSync)(fromArgv)) {
|
|
119449
118100
|
return fromArgv;
|
|
119450
118101
|
}
|
|
119451
118102
|
const beside = (0, import_node_path36.join)(__dirname, "cli.js");
|
|
119452
|
-
if ((0,
|
|
118103
|
+
if ((0, import_node_fs30.existsSync)(beside)) {
|
|
119453
118104
|
return beside;
|
|
119454
118105
|
}
|
|
119455
118106
|
if (fromArgv) {
|
|
@@ -119471,12 +118122,12 @@ async function ensureWindowsNativeLauncher(options = {}) {
|
|
|
119471
118122
|
const result = await installWindowsNativeLauncher({ cliPath: resolveRunningCliPath(), targetDir });
|
|
119472
118123
|
return { exePath: result.exePath, installed: true };
|
|
119473
118124
|
}
|
|
119474
|
-
var import_node_child_process9,
|
|
118125
|
+
var import_node_child_process9, import_node_fs30, import_node_module, import_node_os12, import_node_path36, SEA_SENTINEL_FUSE, NATIVE_LAUNCHER_EXE_NAME, POSTJECT_SPEC, POSTJECT_BIN;
|
|
119475
118126
|
var init_win_native_launcher = __esm({
|
|
119476
118127
|
"src/win-native-launcher.ts"() {
|
|
119477
118128
|
"use strict";
|
|
119478
118129
|
import_node_child_process9 = require("node:child_process");
|
|
119479
|
-
|
|
118130
|
+
import_node_fs30 = require("node:fs");
|
|
119480
118131
|
import_node_module = require("node:module");
|
|
119481
118132
|
import_node_os12 = require("node:os");
|
|
119482
118133
|
import_node_path36 = require("node:path");
|
|
@@ -119618,7 +118269,7 @@ function buildProviderMismatchWarning(target, provider) {
|
|
|
119618
118269
|
].join("\n");
|
|
119619
118270
|
}
|
|
119620
118271
|
async function handleUpdateCommand(args) {
|
|
119621
|
-
if (args.some(
|
|
118272
|
+
if (args.some(isHelpArg4)) {
|
|
119622
118273
|
printUpdateUsage();
|
|
119623
118274
|
return;
|
|
119624
118275
|
}
|
|
@@ -119659,7 +118310,7 @@ function resolveUpdateTarget(target) {
|
|
|
119659
118310
|
return detectGatewayInvocation() ?? "node";
|
|
119660
118311
|
}
|
|
119661
118312
|
async function handleSetupCommand(args) {
|
|
119662
|
-
if (args.some(
|
|
118313
|
+
if (args.some(isHelpArg4)) {
|
|
119663
118314
|
printSetupUsage();
|
|
119664
118315
|
return;
|
|
119665
118316
|
}
|
|
@@ -120236,7 +118887,7 @@ async function getCurrentNodeCliVersion() {
|
|
|
120236
118887
|
return await getGlobalNpmPackageVersion(UPDATE_PACKAGES.node) ?? getBundledNodeCliVersion();
|
|
120237
118888
|
}
|
|
120238
118889
|
function getBundledNodeCliVersion() {
|
|
120239
|
-
return true ? "0.2.19
|
|
118890
|
+
return true ? "0.2.19" : null;
|
|
120240
118891
|
}
|
|
120241
118892
|
function readConfiguredAiProvider() {
|
|
120242
118893
|
const explicit = process.env.OKX_A2A_AI_PROVIDER || process.env.OKX_AGENT_TASK_AI_CLI;
|
|
@@ -120421,7 +119072,7 @@ async function updateHermes(release, options) {
|
|
|
120421
119072
|
assertNotRunningInsideGateway("hermes");
|
|
120422
119073
|
}
|
|
120423
119074
|
const spec = buildNpmPackageSpec("hermes", release);
|
|
120424
|
-
const workDir = await (0,
|
|
119075
|
+
const workDir = await (0, import_promises15.mkdtemp)((0, import_node_path37.join)((0, import_node_os13.tmpdir)(), `okx-a2a-${label}-hermes-`));
|
|
120425
119076
|
try {
|
|
120426
119077
|
console.log(`[${label}] downloading ${spec}`);
|
|
120427
119078
|
const npmTarball = await npmPack(spec, workDir);
|
|
@@ -120442,11 +119093,11 @@ async function updateHermes(release, options) {
|
|
|
120442
119093
|
}
|
|
120443
119094
|
console.log(`[${label}] hermes ${label} done`);
|
|
120444
119095
|
} finally {
|
|
120445
|
-
await (0,
|
|
119096
|
+
await (0, import_promises15.rm)(workDir, { recursive: true, force: true });
|
|
120446
119097
|
}
|
|
120447
119098
|
}
|
|
120448
119099
|
async function installGatewayPluginForDoctor(target) {
|
|
120449
|
-
const release = isPrereleaseVersion("0.2.19
|
|
119100
|
+
const release = isPrereleaseVersion("0.2.19") ? "beta" : "latest";
|
|
120450
119101
|
const insideTargetGateway = detectGatewayInvocation() === target;
|
|
120451
119102
|
const options = {
|
|
120452
119103
|
restart: !insideTargetGateway,
|
|
@@ -120473,7 +119124,7 @@ function setupReadyMessage(target) {
|
|
|
120473
119124
|
async function normalizeHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPath()) {
|
|
120474
119125
|
let content2;
|
|
120475
119126
|
try {
|
|
120476
|
-
content2 = await (0,
|
|
119127
|
+
content2 = await (0, import_promises15.readFile)(configFile, "utf8");
|
|
120477
119128
|
} catch (error) {
|
|
120478
119129
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
120479
119130
|
return false;
|
|
@@ -120484,21 +119135,21 @@ async function normalizeHermesOkxA2aPluginConfig(configFile = resolveHermesConfi
|
|
|
120484
119135
|
if (!normalized.changed) {
|
|
120485
119136
|
return false;
|
|
120486
119137
|
}
|
|
120487
|
-
await (0,
|
|
119138
|
+
await (0, import_promises15.writeFile)(configFile, normalized.content);
|
|
120488
119139
|
console.log(`[update] normalized Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
120489
119140
|
return true;
|
|
120490
119141
|
}
|
|
120491
119142
|
async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPath(), options = {}) {
|
|
120492
119143
|
let content2;
|
|
120493
119144
|
try {
|
|
120494
|
-
content2 = await (0,
|
|
119145
|
+
content2 = await (0, import_promises15.readFile)(configFile, "utf8");
|
|
120495
119146
|
} catch (error) {
|
|
120496
119147
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
120497
119148
|
if (options.dryRun) {
|
|
120498
119149
|
return true;
|
|
120499
119150
|
}
|
|
120500
|
-
await (0,
|
|
120501
|
-
await (0,
|
|
119151
|
+
await (0, import_promises15.mkdir)((0, import_node_path37.resolve)(configFile, ".."), { recursive: true });
|
|
119152
|
+
await (0, import_promises15.writeFile)(configFile, "plugins:\n enabled:\n - okx-a2a\n");
|
|
120502
119153
|
console.log(`[update] added Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
120503
119154
|
return true;
|
|
120504
119155
|
}
|
|
@@ -120509,7 +119160,7 @@ async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPa
|
|
|
120509
119160
|
if (options.dryRun) {
|
|
120510
119161
|
return true;
|
|
120511
119162
|
}
|
|
120512
|
-
await (0,
|
|
119163
|
+
await (0, import_promises15.writeFile)(configFile, normalized.content);
|
|
120513
119164
|
console.log(`[update] normalized Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
120514
119165
|
return true;
|
|
120515
119166
|
}
|
|
@@ -120520,7 +119171,7 @@ async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPa
|
|
|
120520
119171
|
return true;
|
|
120521
119172
|
}
|
|
120522
119173
|
const updated = addHermesOkxA2aEnabled(content2);
|
|
120523
|
-
await (0,
|
|
119174
|
+
await (0, import_promises15.writeFile)(configFile, updated);
|
|
120524
119175
|
console.log(`[update] added Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
120525
119176
|
return true;
|
|
120526
119177
|
}
|
|
@@ -120821,7 +119472,7 @@ async function isGatewayPluginInstalled(target) {
|
|
|
120821
119472
|
if (target === "openclaw") {
|
|
120822
119473
|
return (await getInstalledOpenClawPluginInfo()).installed;
|
|
120823
119474
|
}
|
|
120824
|
-
return (0,
|
|
119475
|
+
return (0, import_node_fs31.existsSync)(resolveHermesPluginYamlPath());
|
|
120825
119476
|
}
|
|
120826
119477
|
async function getInstalledGatewayPluginVersion(target) {
|
|
120827
119478
|
if (target === "hermes") {
|
|
@@ -120910,7 +119561,7 @@ function parsePackageVersionFromText(output5) {
|
|
|
120910
119561
|
async function getInstalledHermesPluginVersion() {
|
|
120911
119562
|
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");
|
|
120912
119563
|
try {
|
|
120913
|
-
const content2 = await (0,
|
|
119564
|
+
const content2 = await (0, import_promises15.readFile)(pluginYaml, "utf8");
|
|
120914
119565
|
return parsePluginYamlVersion(content2);
|
|
120915
119566
|
} catch (error) {
|
|
120916
119567
|
if (isNodeError(error) && error.code === "ENOENT") {
|
|
@@ -120969,7 +119620,7 @@ async function npmPack(spec, destination) {
|
|
|
120969
119620
|
return (0, import_node_path37.resolve)(destination, (0, import_node_path37.basename)(tarballName));
|
|
120970
119621
|
}
|
|
120971
119622
|
async function findHermesPluginTarball(distDir) {
|
|
120972
|
-
const entries = await (0,
|
|
119623
|
+
const entries = await (0, import_promises15.readdir)(distDir);
|
|
120973
119624
|
const tarball = entries.find((entry) => /^okx-a2a-hermes-plugin-.+\.tar\.gz$/.test(entry));
|
|
120974
119625
|
if (!tarball) {
|
|
120975
119626
|
throw new Error(`Hermes npm package did not contain dist/okx-a2a-hermes-plugin-*.tar.gz`);
|
|
@@ -120977,7 +119628,7 @@ async function findHermesPluginTarball(distDir) {
|
|
|
120977
119628
|
return (0, import_node_path37.join)(distDir, tarball);
|
|
120978
119629
|
}
|
|
120979
119630
|
async function findFirstDirectory(parent) {
|
|
120980
|
-
const entries = await (0,
|
|
119631
|
+
const entries = await (0, import_promises15.readdir)(parent, { withFileTypes: true });
|
|
120981
119632
|
const dir = entries.find((entry) => entry.isDirectory());
|
|
120982
119633
|
if (!dir) {
|
|
120983
119634
|
throw new Error(`No unpacked plugin directory found under ${parent}`);
|
|
@@ -120994,7 +119645,7 @@ function readOption4(args, name) {
|
|
|
120994
119645
|
function hasFlag(args, name) {
|
|
120995
119646
|
return args.includes(name);
|
|
120996
119647
|
}
|
|
120997
|
-
function
|
|
119648
|
+
function isHelpArg4(value) {
|
|
120998
119649
|
return value === "-h" || value === "--help" || value === "help";
|
|
120999
119650
|
}
|
|
121000
119651
|
function isSupportedRelease(value) {
|
|
@@ -121203,13 +119854,13 @@ function buildExternalCommandInvocation(command, args, platform = process.platfo
|
|
|
121203
119854
|
function formatExternalCommand(command, args) {
|
|
121204
119855
|
return [command, ...args].join(" ");
|
|
121205
119856
|
}
|
|
121206
|
-
var import_node_child_process10,
|
|
119857
|
+
var import_node_child_process10, import_node_fs31, import_promises15, 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;
|
|
121207
119858
|
var init_update_cli = __esm({
|
|
121208
119859
|
"src/update-cli.ts"() {
|
|
121209
119860
|
"use strict";
|
|
121210
119861
|
import_node_child_process10 = require("node:child_process");
|
|
121211
|
-
|
|
121212
|
-
|
|
119862
|
+
import_node_fs31 = require("node:fs");
|
|
119863
|
+
import_promises15 = require("node:fs/promises");
|
|
121213
119864
|
import_node_os13 = require("node:os");
|
|
121214
119865
|
import_node_path37 = require("node:path");
|
|
121215
119866
|
init_ai_command();
|
|
@@ -121499,7 +120150,7 @@ async function runDoctor(options = {}) {
|
|
|
121499
120150
|
platform: options.platform ?? process.platform,
|
|
121500
120151
|
env: options.env ?? process.env,
|
|
121501
120152
|
target: options.target ?? resolveDoctorTarget(options.env ?? process.env),
|
|
121502
|
-
cliVersion: options.cliVersion ?? (true ? "0.2.19
|
|
120153
|
+
cliVersion: options.cliVersion ?? (true ? "0.2.19" : "0.0.0"),
|
|
121503
120154
|
fixMode: options.fix === true,
|
|
121504
120155
|
nonInteractive: options.nonInteractive === true,
|
|
121505
120156
|
packageChanged: false,
|
|
@@ -122536,7 +121187,7 @@ var init_doctor_cli = __esm({
|
|
|
122536
121187
|
});
|
|
122537
121188
|
|
|
122538
121189
|
// src/cli.ts
|
|
122539
|
-
var
|
|
121190
|
+
var import_node_fs32 = require("node:fs");
|
|
122540
121191
|
var import_node_os14 = require("node:os");
|
|
122541
121192
|
var import_node_path39 = require("node:path");
|
|
122542
121193
|
init_daemon();
|
|
@@ -122606,7 +121257,7 @@ init_sentry_config();
|
|
|
122606
121257
|
init_runtime_metadata();
|
|
122607
121258
|
var CURRENT_GATEWAY_SESSION_KEYS_ENV4 = "OKX_A2A_CURRENT_GATEWAY_SESSION_KEYS";
|
|
122608
121259
|
function printUsage3() {
|
|
122609
|
-
console.log(`okx-a2a ${"0.2.19
|
|
121260
|
+
console.log(`okx-a2a ${"0.2.19"}
|
|
122610
121261
|
|
|
122611
121262
|
Usage:
|
|
122612
121263
|
okx-a2a <command> [options]
|
|
@@ -122639,7 +121290,6 @@ Commands:
|
|
|
122639
121290
|
trade-records
|
|
122640
121291
|
Insert, query, and soft-delete local business trade records
|
|
122641
121292
|
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
|
|
122643
121293
|
|
|
122644
121294
|
Global options:
|
|
122645
121295
|
-h, --help Show help
|
|
@@ -122649,7 +121299,7 @@ Run \`okx-a2a <command> -h\` for command-specific help.
|
|
|
122649
121299
|
`);
|
|
122650
121300
|
}
|
|
122651
121301
|
function printVersion() {
|
|
122652
|
-
console.log("0.2.19
|
|
121302
|
+
console.log("0.2.19");
|
|
122653
121303
|
}
|
|
122654
121304
|
function printDaemonUsage() {
|
|
122655
121305
|
console.log(`Usage: okx-a2a daemon <start|restart|stop|status|autostart> [options]
|
|
@@ -122917,11 +121567,11 @@ Commands:
|
|
|
122917
121567
|
Print setup status JSON to stdout. Installer logs are written to stderr.
|
|
122918
121568
|
`);
|
|
122919
121569
|
}
|
|
122920
|
-
function
|
|
121570
|
+
function isHelpArg5(value) {
|
|
122921
121571
|
return value === "-h" || value === "--help" || value === "help";
|
|
122922
121572
|
}
|
|
122923
121573
|
function hasHelpFlag5(args) {
|
|
122924
|
-
return args.some(
|
|
121574
|
+
return args.some(isHelpArg5);
|
|
122925
121575
|
}
|
|
122926
121576
|
function isVersionArg(value) {
|
|
122927
121577
|
return value === "-v" || value === "--version" || value === "version";
|
|
@@ -122948,14 +121598,14 @@ function maybeRedirectDaemonSelfLog() {
|
|
|
122948
121598
|
}
|
|
122949
121599
|
try {
|
|
122950
121600
|
const logPath = resolveTaskPaths().listenerLogPath;
|
|
122951
|
-
(0,
|
|
122952
|
-
const fd = (0,
|
|
121601
|
+
(0, import_node_fs32.mkdirSync)((0, import_node_path39.join)(logPath, ".."), { recursive: true });
|
|
121602
|
+
const fd = (0, import_node_fs32.openSync)(logPath, "a");
|
|
122953
121603
|
const writeToLog = ((chunk, encoding, cb) => {
|
|
122954
121604
|
try {
|
|
122955
121605
|
if (typeof chunk === "string") {
|
|
122956
|
-
(0,
|
|
121606
|
+
(0, import_node_fs32.writeSync)(fd, chunk);
|
|
122957
121607
|
} else {
|
|
122958
|
-
(0,
|
|
121608
|
+
(0, import_node_fs32.writeSync)(fd, chunk);
|
|
122959
121609
|
}
|
|
122960
121610
|
} catch {
|
|
122961
121611
|
}
|
|
@@ -123305,12 +121955,12 @@ async function queueXmtpDaemonCommand(args, type) {
|
|
|
123305
121955
|
}
|
|
123306
121956
|
async function handleTaskCommand(args) {
|
|
123307
121957
|
const subcommand = args[0];
|
|
123308
|
-
if (!subcommand || args.every(
|
|
121958
|
+
if (!subcommand || args.every(isHelpArg5)) {
|
|
123309
121959
|
printTaskUsage();
|
|
123310
121960
|
return;
|
|
123311
121961
|
}
|
|
123312
121962
|
if (subcommand === "help") {
|
|
123313
|
-
const helpTarget = args.slice(1).find((arg) => !
|
|
121963
|
+
const helpTarget = args.slice(1).find((arg) => !isHelpArg5(arg));
|
|
123314
121964
|
if (!helpTarget) {
|
|
123315
121965
|
printTaskUsage();
|
|
123316
121966
|
return;
|
|
@@ -123999,10 +122649,10 @@ async function initDirectCliSentry() {
|
|
|
123999
122649
|
cliSentryInitAttempted = true;
|
|
124000
122650
|
try {
|
|
124001
122651
|
const configPath = (0, import_node_path39.join)(resolveTaskHomeForSentryConfig(), "xmtp", "system-config.json");
|
|
124002
|
-
if (!(0,
|
|
122652
|
+
if (!(0, import_node_fs32.existsSync)(configPath)) {
|
|
124003
122653
|
return;
|
|
124004
122654
|
}
|
|
124005
|
-
const config = JSON.parse((0,
|
|
122655
|
+
const config = JSON.parse((0, import_node_fs32.readFileSync)(configPath, "utf8"));
|
|
124006
122656
|
if (typeof config.sentryDsn !== "string" || !config.sentryDsn) {
|
|
124007
122657
|
return;
|
|
124008
122658
|
}
|
|
@@ -124064,7 +122714,7 @@ async function main() {
|
|
|
124064
122714
|
assertSupportedNodeVersion();
|
|
124065
122715
|
}
|
|
124066
122716
|
const args = process.argv.slice(3);
|
|
124067
|
-
if (
|
|
122717
|
+
if (isHelpArg5(command)) {
|
|
124068
122718
|
printUsage3();
|
|
124069
122719
|
return;
|
|
124070
122720
|
}
|
|
@@ -124085,15 +122735,6 @@ async function main() {
|
|
|
124085
122735
|
await handleTradeRecordsCommand2(args);
|
|
124086
122736
|
return;
|
|
124087
122737
|
}
|
|
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
|
-
}
|
|
124097
122738
|
if (command === "daemon") {
|
|
124098
122739
|
if (hasHelpFlag5(args)) {
|
|
124099
122740
|
printDaemonUsage();
|
|
@@ -124153,7 +122794,7 @@ async function main() {
|
|
|
124153
122794
|
if (command === "xmtp-test") {
|
|
124154
122795
|
const { handleXmtpTestCommand: handleXmtpTestCommand2 } = await Promise.resolve().then(() => (init_xmtp_test_cli(), xmtp_test_cli_exports));
|
|
124155
122796
|
await handleXmtpTestCommand2(process.argv.slice(3), {
|
|
124156
|
-
packageVersion: "0.2.19
|
|
122797
|
+
packageVersion: "0.2.19",
|
|
124157
122798
|
agentSdkVersion: "2.3.1",
|
|
124158
122799
|
nodeSdkVersion: "6.1.1",
|
|
124159
122800
|
nodeBindingsVersion: "1.11.1"
|
|
@@ -124259,12 +122900,12 @@ function shouldDeferHelpToNestedHandler(command, args) {
|
|
|
124259
122900
|
return true;
|
|
124260
122901
|
}
|
|
124261
122902
|
if (command === "trade-records") {
|
|
124262
|
-
return args.some((arg) => !
|
|
122903
|
+
return args.some((arg) => !isHelpArg5(arg));
|
|
124263
122904
|
}
|
|
124264
122905
|
if (command !== "session" && command !== "user" && command !== "task") {
|
|
124265
122906
|
return false;
|
|
124266
122907
|
}
|
|
124267
|
-
return args.some((arg) => !
|
|
122908
|
+
return args.some((arg) => !isHelpArg5(arg));
|
|
124268
122909
|
}
|
|
124269
122910
|
main().then(() => {
|
|
124270
122911
|
if (cliSentryFlushTimedOut) {
|