@okxweb3/a2a-node 0.2.9 → 0.2.10-beta-98689bff7a-260826152645
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -0
- package/dist/cli.js +1644 -262
- package/dist/index.js +1440 -211
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -3772,6 +3772,10 @@ function isDaemonCommand(value) {
|
|
|
3772
3772
|
if (parsed.type === "xmtp-send") {
|
|
3773
3773
|
return typeof parsed.jobId === "string" && typeof parsed.message === "string";
|
|
3774
3774
|
}
|
|
3775
|
+
if (parsed.type === "signal-publish") {
|
|
3776
|
+
const command = parsed;
|
|
3777
|
+
return typeof command.serviceId === "string" && !!command.signal && typeof command.signal === "object";
|
|
3778
|
+
}
|
|
3775
3779
|
if (parsed.type === "xmtp-get-pending-list") {
|
|
3776
3780
|
return true;
|
|
3777
3781
|
}
|
|
@@ -3881,6 +3885,15 @@ var init_command_store = __esm({
|
|
|
3881
3885
|
createdAt: Date.now()
|
|
3882
3886
|
};
|
|
3883
3887
|
}
|
|
3888
|
+
createSignalPublishCommand(params) {
|
|
3889
|
+
return {
|
|
3890
|
+
id: (0, import_node_crypto2.randomUUID)(),
|
|
3891
|
+
type: "signal-publish",
|
|
3892
|
+
serviceId: params.serviceId,
|
|
3893
|
+
signal: params.signal,
|
|
3894
|
+
createdAt: Date.now()
|
|
3895
|
+
};
|
|
3896
|
+
}
|
|
3884
3897
|
createXmtpGetConversationHistoryCommand(params) {
|
|
3885
3898
|
return {
|
|
3886
3899
|
id: (0, import_node_crypto2.randomUUID)(),
|
|
@@ -4677,7 +4690,7 @@ var require_is = __commonJS({
|
|
|
4677
4690
|
function isPrimitive(wat) {
|
|
4678
4691
|
return wat === null || typeof wat !== "object" && typeof wat !== "function";
|
|
4679
4692
|
}
|
|
4680
|
-
function
|
|
4693
|
+
function isPlainObject6(wat) {
|
|
4681
4694
|
return isBuiltin(wat, "Object");
|
|
4682
4695
|
}
|
|
4683
4696
|
function isEvent(wat) {
|
|
@@ -4693,7 +4706,7 @@ var require_is = __commonJS({
|
|
|
4693
4706
|
return Boolean(wat && wat.then && typeof wat.then === "function");
|
|
4694
4707
|
}
|
|
4695
4708
|
function isSyntheticEvent(wat) {
|
|
4696
|
-
return
|
|
4709
|
+
return isPlainObject6(wat) && "nativeEvent" in wat && "preventDefault" in wat && "stopPropagation" in wat;
|
|
4697
4710
|
}
|
|
4698
4711
|
function isNaN2(wat) {
|
|
4699
4712
|
return typeof wat === "number" && wat !== wat;
|
|
@@ -4716,7 +4729,7 @@ var require_is = __commonJS({
|
|
|
4716
4729
|
exports2.isEvent = isEvent;
|
|
4717
4730
|
exports2.isInstanceOf = isInstanceOf;
|
|
4718
4731
|
exports2.isNaN = isNaN2;
|
|
4719
|
-
exports2.isPlainObject =
|
|
4732
|
+
exports2.isPlainObject = isPlainObject6;
|
|
4720
4733
|
exports2.isPrimitive = isPrimitive;
|
|
4721
4734
|
exports2.isRegExp = isRegExp;
|
|
4722
4735
|
exports2.isString = isString;
|
|
@@ -6524,7 +6537,7 @@ var require_path = __commonJS({
|
|
|
6524
6537
|
function isAbsolute4(path2) {
|
|
6525
6538
|
return path2.charAt(0) === "/";
|
|
6526
6539
|
}
|
|
6527
|
-
function
|
|
6540
|
+
function join35(...args) {
|
|
6528
6541
|
return normalizePath(args.join("/"));
|
|
6529
6542
|
}
|
|
6530
6543
|
function dirname10(path2) {
|
|
@@ -6549,7 +6562,7 @@ var require_path = __commonJS({
|
|
|
6549
6562
|
exports2.basename = basename10;
|
|
6550
6563
|
exports2.dirname = dirname10;
|
|
6551
6564
|
exports2.isAbsolute = isAbsolute4;
|
|
6552
|
-
exports2.join =
|
|
6565
|
+
exports2.join = join35;
|
|
6553
6566
|
exports2.normalizePath = normalizePath;
|
|
6554
6567
|
exports2.relative = relative;
|
|
6555
6568
|
exports2.resolve = resolve14;
|
|
@@ -15497,12 +15510,12 @@ var require_supports_color = __commonJS({
|
|
|
15497
15510
|
"use strict";
|
|
15498
15511
|
var os = require("os");
|
|
15499
15512
|
var tty = require("tty");
|
|
15500
|
-
var
|
|
15513
|
+
var hasFlag4 = require_has_flag();
|
|
15501
15514
|
var { env } = process;
|
|
15502
15515
|
var forceColor;
|
|
15503
|
-
if (
|
|
15516
|
+
if (hasFlag4("no-color") || hasFlag4("no-colors") || hasFlag4("color=false") || hasFlag4("color=never")) {
|
|
15504
15517
|
forceColor = 0;
|
|
15505
|
-
} else if (
|
|
15518
|
+
} else if (hasFlag4("color") || hasFlag4("colors") || hasFlag4("color=true") || hasFlag4("color=always")) {
|
|
15506
15519
|
forceColor = 1;
|
|
15507
15520
|
}
|
|
15508
15521
|
if ("FORCE_COLOR" in env) {
|
|
@@ -15529,10 +15542,10 @@ var require_supports_color = __commonJS({
|
|
|
15529
15542
|
if (forceColor === 0) {
|
|
15530
15543
|
return 0;
|
|
15531
15544
|
}
|
|
15532
|
-
if (
|
|
15545
|
+
if (hasFlag4("color=16m") || hasFlag4("color=full") || hasFlag4("color=truecolor")) {
|
|
15533
15546
|
return 3;
|
|
15534
15547
|
}
|
|
15535
|
-
if (
|
|
15548
|
+
if (hasFlag4("color=256")) {
|
|
15536
15549
|
return 2;
|
|
15537
15550
|
}
|
|
15538
15551
|
if (haveStream && !streamIsTTY && forceColor === void 0) {
|
|
@@ -15783,7 +15796,7 @@ var require_promisify = __commonJS({
|
|
|
15783
15796
|
"../../node_modules/agent-base/dist/src/promisify.js"(exports2) {
|
|
15784
15797
|
"use strict";
|
|
15785
15798
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
15786
|
-
function
|
|
15799
|
+
function promisify4(fn) {
|
|
15787
15800
|
return function(req, opts) {
|
|
15788
15801
|
return new Promise((resolve14, reject) => {
|
|
15789
15802
|
fn.call(this, req, opts, (err2, rtn) => {
|
|
@@ -15796,7 +15809,7 @@ var require_promisify = __commonJS({
|
|
|
15796
15809
|
});
|
|
15797
15810
|
};
|
|
15798
15811
|
}
|
|
15799
|
-
exports2.default =
|
|
15812
|
+
exports2.default = promisify4;
|
|
15800
15813
|
}
|
|
15801
15814
|
});
|
|
15802
15815
|
|
|
@@ -25241,7 +25254,7 @@ var require_websocket2 = __commonJS({
|
|
|
25241
25254
|
var http2 = require("http");
|
|
25242
25255
|
var net = require("net");
|
|
25243
25256
|
var tls = require("tls");
|
|
25244
|
-
var { randomBytes: randomBytes4, createHash:
|
|
25257
|
+
var { randomBytes: randomBytes4, createHash: createHash7 } = require("crypto");
|
|
25245
25258
|
var { Duplex, Readable } = require("stream");
|
|
25246
25259
|
var { URL: URL2 } = require("url");
|
|
25247
25260
|
var PerMessageDeflate = require_permessage_deflate();
|
|
@@ -25901,7 +25914,7 @@ var require_websocket2 = __commonJS({
|
|
|
25901
25914
|
abortHandshake(websocket, socket, "Invalid Upgrade header");
|
|
25902
25915
|
return;
|
|
25903
25916
|
}
|
|
25904
|
-
const digest =
|
|
25917
|
+
const digest = createHash7("sha1").update(key + GUID).digest("base64");
|
|
25905
25918
|
if (res.headers["sec-websocket-accept"] !== digest) {
|
|
25906
25919
|
abortHandshake(websocket, socket, "Invalid Sec-WebSocket-Accept header");
|
|
25907
25920
|
return;
|
|
@@ -26268,7 +26281,7 @@ var require_websocket_server = __commonJS({
|
|
|
26268
26281
|
var EventEmitter2 = require("events");
|
|
26269
26282
|
var http2 = require("http");
|
|
26270
26283
|
var { Duplex } = require("stream");
|
|
26271
|
-
var { createHash:
|
|
26284
|
+
var { createHash: createHash7 } = require("crypto");
|
|
26272
26285
|
var extension = require_extension();
|
|
26273
26286
|
var PerMessageDeflate = require_permessage_deflate();
|
|
26274
26287
|
var subprotocol = require_subprotocol();
|
|
@@ -26569,7 +26582,7 @@ var require_websocket_server = __commonJS({
|
|
|
26569
26582
|
);
|
|
26570
26583
|
}
|
|
26571
26584
|
if (this._state > RUNNING) return abortHandshake(socket, 503);
|
|
26572
|
-
const digest =
|
|
26585
|
+
const digest = createHash7("sha1").update(key + GUID).digest("base64");
|
|
26573
26586
|
const headers = [
|
|
26574
26587
|
"HTTP/1.1 101 Switching Protocols",
|
|
26575
26588
|
"Upgrade: websocket",
|
|
@@ -26934,7 +26947,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
26934
26947
|
client: {
|
|
26935
26948
|
id: "gateway-client",
|
|
26936
26949
|
displayName: "okx-a2a-node",
|
|
26937
|
-
version: "0.2.
|
|
26950
|
+
version: "0.2.10-beta-98689bff7a-260826152645",
|
|
26938
26951
|
platform: "node",
|
|
26939
26952
|
mode: "backend",
|
|
26940
26953
|
instanceId
|
|
@@ -26945,7 +26958,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
26945
26958
|
commands: [],
|
|
26946
26959
|
permissions: {},
|
|
26947
26960
|
locale: Intl.DateTimeFormat().resolvedOptions().locale || "en-US",
|
|
26948
|
-
userAgent: `okx-a2a-node/${"0.2.
|
|
26961
|
+
userAgent: `okx-a2a-node/${"0.2.10-beta-98689bff7a-260826152645"}`,
|
|
26949
26962
|
auth: {
|
|
26950
26963
|
...config.token ? { token: config.token } : {},
|
|
26951
26964
|
...config.password ? { password: config.password } : {}
|
|
@@ -28912,7 +28925,7 @@ var init_sentry_config = __esm({
|
|
|
28912
28925
|
environment = process.env.SENTRY_ENV === "dev" ? "dev" : "prod";
|
|
28913
28926
|
SENTRY_CONFIG = {
|
|
28914
28927
|
projectName: "okx/openclaw-okx-a2a-extension",
|
|
28915
|
-
release: "0.2.
|
|
28928
|
+
release: "0.2.10-beta-98689bff7a-260826152645",
|
|
28916
28929
|
environment,
|
|
28917
28930
|
runtimeContainer: normalizeRuntimeContainer(process.env.OKX_A2A_RUNTIME_CONTAINER)
|
|
28918
28931
|
};
|
|
@@ -29201,7 +29214,7 @@ var require_BufferList = __commonJS({
|
|
|
29201
29214
|
this.head = this.tail = null;
|
|
29202
29215
|
this.length = 0;
|
|
29203
29216
|
};
|
|
29204
|
-
BufferList.prototype.join = function
|
|
29217
|
+
BufferList.prototype.join = function join35(s) {
|
|
29205
29218
|
if (this.length === 0) return "";
|
|
29206
29219
|
var p = this.head;
|
|
29207
29220
|
var ret = "" + p.data;
|
|
@@ -40082,7 +40095,7 @@ async function exportDiagnosticLogs(options) {
|
|
|
40082
40095
|
node: process.version,
|
|
40083
40096
|
platform: process.platform,
|
|
40084
40097
|
arch: process.arch,
|
|
40085
|
-
packageVersion: true ? "0.2.
|
|
40098
|
+
packageVersion: true ? "0.2.10-beta-98689bff7a-260826152645" : "unknown",
|
|
40086
40099
|
sensitiveContentIncluded: options.includeSensitiveContent,
|
|
40087
40100
|
listenerAndLlmContentIncluded: true,
|
|
40088
40101
|
credentialsAlwaysRedacted: true,
|
|
@@ -65284,6 +65297,530 @@ var init_xmtp_debug = __esm({
|
|
|
65284
65297
|
}
|
|
65285
65298
|
});
|
|
65286
65299
|
|
|
65300
|
+
// src/signal-trading/config.ts
|
|
65301
|
+
function isPlainObject2(value) {
|
|
65302
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
65303
|
+
}
|
|
65304
|
+
function requireObject(value, path2) {
|
|
65305
|
+
if (!isPlainObject2(value)) {
|
|
65306
|
+
throw new Error(`${path2} must be an object`);
|
|
65307
|
+
}
|
|
65308
|
+
return value;
|
|
65309
|
+
}
|
|
65310
|
+
function requireString(value, path2) {
|
|
65311
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
65312
|
+
throw new Error(`${path2} must be a non-empty string`);
|
|
65313
|
+
}
|
|
65314
|
+
return value.trim();
|
|
65315
|
+
}
|
|
65316
|
+
function optionalString(value, path2) {
|
|
65317
|
+
return value === void 0 ? void 0 : requireString(value, path2);
|
|
65318
|
+
}
|
|
65319
|
+
function requireBoolean(value, path2) {
|
|
65320
|
+
if (typeof value !== "boolean") {
|
|
65321
|
+
throw new Error(`${path2} must be a boolean`);
|
|
65322
|
+
}
|
|
65323
|
+
return value;
|
|
65324
|
+
}
|
|
65325
|
+
function requireInteger(value, path2, minimum) {
|
|
65326
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < minimum) {
|
|
65327
|
+
throw new Error(`${path2} must be an integer >= ${minimum}`);
|
|
65328
|
+
}
|
|
65329
|
+
return value;
|
|
65330
|
+
}
|
|
65331
|
+
function requireArray(value, path2) {
|
|
65332
|
+
if (!Array.isArray(value)) {
|
|
65333
|
+
throw new Error(`${path2} must be an array`);
|
|
65334
|
+
}
|
|
65335
|
+
return value;
|
|
65336
|
+
}
|
|
65337
|
+
function parseStringArray2(value, path2) {
|
|
65338
|
+
return requireArray(value, path2).map((item, index2) => requireString(item, `${path2}[${index2}]`));
|
|
65339
|
+
}
|
|
65340
|
+
function parseProviderRoute(value, index2) {
|
|
65341
|
+
const path2 = `config.provider.routes[${index2}]`;
|
|
65342
|
+
const input = requireObject(value, path2);
|
|
65343
|
+
const myAgentId = optionalString(input.myAgentId, `${path2}.myAgentId`);
|
|
65344
|
+
const toXmtpAddress = optionalString(input.toXmtpAddress, `${path2}.toXmtpAddress`);
|
|
65345
|
+
return {
|
|
65346
|
+
serviceId: requireString(input.serviceId, `${path2}.serviceId`),
|
|
65347
|
+
subscriptionId: requireString(input.subscriptionId, `${path2}.subscriptionId`),
|
|
65348
|
+
jobId: requireString(input.jobId, `${path2}.jobId`),
|
|
65349
|
+
...myAgentId ? { myAgentId } : {},
|
|
65350
|
+
toAgentId: requireString(input.toAgentId, `${path2}.toAgentId`),
|
|
65351
|
+
...toXmtpAddress ? { toXmtpAddress } : {}
|
|
65352
|
+
};
|
|
65353
|
+
}
|
|
65354
|
+
function parseBuyerSubscription(value, index2) {
|
|
65355
|
+
const path2 = `config.buyer.subscriptions[${index2}]`;
|
|
65356
|
+
const input = requireObject(value, path2);
|
|
65357
|
+
return {
|
|
65358
|
+
serviceId: requireString(input.serviceId, `${path2}.serviceId`),
|
|
65359
|
+
subscriptionId: requireString(input.subscriptionId, `${path2}.subscriptionId`),
|
|
65360
|
+
jobId: requireString(input.jobId, `${path2}.jobId`),
|
|
65361
|
+
providerAgentId: requireString(input.providerAgentId, `${path2}.providerAgentId`)
|
|
65362
|
+
};
|
|
65363
|
+
}
|
|
65364
|
+
function parseRiskPolicy(value) {
|
|
65365
|
+
const input = requireObject(value, "config.buyer.riskPolicy");
|
|
65366
|
+
const allowedSides = parseStringArray2(input.allowedSides, "config.buyer.riskPolicy.allowedSides");
|
|
65367
|
+
for (const side of allowedSides) {
|
|
65368
|
+
if (side !== "BUY" && side !== "SELL") {
|
|
65369
|
+
throw new Error("config.buyer.riskPolicy.allowedSides supports only BUY and SELL");
|
|
65370
|
+
}
|
|
65371
|
+
}
|
|
65372
|
+
const allowedTokenIds = parseStringArray2(
|
|
65373
|
+
input.allowedTokenIds,
|
|
65374
|
+
"config.buyer.riskPolicy.allowedTokenIds"
|
|
65375
|
+
);
|
|
65376
|
+
let allowedMarketSeries;
|
|
65377
|
+
if (input.allowedMarketSeries !== void 0) {
|
|
65378
|
+
allowedMarketSeries = requireArray(
|
|
65379
|
+
input.allowedMarketSeries,
|
|
65380
|
+
"config.buyer.riskPolicy.allowedMarketSeries"
|
|
65381
|
+
).map((value2, index2) => {
|
|
65382
|
+
const path2 = `config.buyer.riskPolicy.allowedMarketSeries[${index2}]`;
|
|
65383
|
+
const series = requireObject(value2, path2);
|
|
65384
|
+
const outcomes = parseStringArray2(series.outcomes, `${path2}.outcomes`);
|
|
65385
|
+
if (outcomes.length === 0) {
|
|
65386
|
+
throw new Error(`${path2}.outcomes must not be empty`);
|
|
65387
|
+
}
|
|
65388
|
+
return {
|
|
65389
|
+
slugPrefix: requireString(series.slugPrefix, `${path2}.slugPrefix`),
|
|
65390
|
+
outcomes,
|
|
65391
|
+
...series.seriesSlug === void 0 ? {} : { seriesSlug: requireString(series.seriesSlug, `${path2}.seriesSlug`) },
|
|
65392
|
+
...series.cryptoMarketConfigId === void 0 ? {} : {
|
|
65393
|
+
cryptoMarketConfigId: requireString(
|
|
65394
|
+
series.cryptoMarketConfigId,
|
|
65395
|
+
`${path2}.cryptoMarketConfigId`
|
|
65396
|
+
)
|
|
65397
|
+
}
|
|
65398
|
+
};
|
|
65399
|
+
});
|
|
65400
|
+
}
|
|
65401
|
+
if (allowedTokenIds.length === 0 && !allowedMarketSeries?.length) {
|
|
65402
|
+
throw new Error(
|
|
65403
|
+
"config.buyer.riskPolicy requires allowedTokenIds or allowedMarketSeries"
|
|
65404
|
+
);
|
|
65405
|
+
}
|
|
65406
|
+
return {
|
|
65407
|
+
allowedTokenIds,
|
|
65408
|
+
...allowedMarketSeries?.length ? { allowedMarketSeries } : {},
|
|
65409
|
+
allowedSides,
|
|
65410
|
+
...input.minBuyUsdc === void 0 ? {} : { minBuyUsdc: requireString(input.minBuyUsdc, "config.buyer.riskPolicy.minBuyUsdc") },
|
|
65411
|
+
...input.maxBuyUsdc === void 0 ? {} : { maxBuyUsdc: requireString(input.maxBuyUsdc, "config.buyer.riskPolicy.maxBuyUsdc") },
|
|
65412
|
+
...input.minSellShares === void 0 ? {} : {
|
|
65413
|
+
minSellShares: requireString(
|
|
65414
|
+
input.minSellShares,
|
|
65415
|
+
"config.buyer.riskPolicy.minSellShares"
|
|
65416
|
+
)
|
|
65417
|
+
},
|
|
65418
|
+
...input.maxSellShares === void 0 ? {} : {
|
|
65419
|
+
maxSellShares: requireString(
|
|
65420
|
+
input.maxSellShares,
|
|
65421
|
+
"config.buyer.riskPolicy.maxSellShares"
|
|
65422
|
+
)
|
|
65423
|
+
},
|
|
65424
|
+
...input.minOrderShares === void 0 ? {} : {
|
|
65425
|
+
minOrderShares: requireString(
|
|
65426
|
+
input.minOrderShares,
|
|
65427
|
+
"config.buyer.riskPolicy.minOrderShares"
|
|
65428
|
+
)
|
|
65429
|
+
},
|
|
65430
|
+
...input.maxBuyPrice === void 0 ? {} : { maxBuyPrice: requireString(input.maxBuyPrice, "config.buyer.riskPolicy.maxBuyPrice") },
|
|
65431
|
+
...input.minSellPrice === void 0 ? {} : {
|
|
65432
|
+
minSellPrice: requireString(
|
|
65433
|
+
input.minSellPrice,
|
|
65434
|
+
"config.buyer.riskPolicy.minSellPrice"
|
|
65435
|
+
)
|
|
65436
|
+
},
|
|
65437
|
+
...input.minOrderAmount === void 0 ? {} : {
|
|
65438
|
+
minOrderAmount: requireString(
|
|
65439
|
+
input.minOrderAmount,
|
|
65440
|
+
"config.buyer.riskPolicy.minOrderAmount"
|
|
65441
|
+
)
|
|
65442
|
+
},
|
|
65443
|
+
...input.maxOrderAmount === void 0 ? {} : {
|
|
65444
|
+
maxOrderAmount: requireString(
|
|
65445
|
+
input.maxOrderAmount,
|
|
65446
|
+
"config.buyer.riskPolicy.maxOrderAmount"
|
|
65447
|
+
)
|
|
65448
|
+
},
|
|
65449
|
+
maxSlippageBps: requireInteger(
|
|
65450
|
+
input.maxSlippageBps,
|
|
65451
|
+
"config.buyer.riskPolicy.maxSlippageBps",
|
|
65452
|
+
0
|
|
65453
|
+
),
|
|
65454
|
+
maxSignalAgeMs: requireInteger(
|
|
65455
|
+
input.maxSignalAgeMs,
|
|
65456
|
+
"config.buyer.riskPolicy.maxSignalAgeMs",
|
|
65457
|
+
1
|
|
65458
|
+
),
|
|
65459
|
+
...input.minTimeToExpiryMs === void 0 ? {} : {
|
|
65460
|
+
minTimeToExpiryMs: requireInteger(
|
|
65461
|
+
input.minTimeToExpiryMs,
|
|
65462
|
+
"config.buyer.riskPolicy.minTimeToExpiryMs",
|
|
65463
|
+
0
|
|
65464
|
+
)
|
|
65465
|
+
},
|
|
65466
|
+
...input.minEventTimeToCloseMs === void 0 ? {} : {
|
|
65467
|
+
minEventTimeToCloseMs: requireInteger(
|
|
65468
|
+
input.minEventTimeToCloseMs,
|
|
65469
|
+
"config.buyer.riskPolicy.minEventTimeToCloseMs",
|
|
65470
|
+
0
|
|
65471
|
+
)
|
|
65472
|
+
}
|
|
65473
|
+
};
|
|
65474
|
+
}
|
|
65475
|
+
function parseBuyer(value) {
|
|
65476
|
+
const input = requireObject(value, "config.buyer");
|
|
65477
|
+
const executionMode = requireString(input.executionMode, "config.buyer.executionMode");
|
|
65478
|
+
if (executionMode !== "DRY_RUN" && executionMode !== "LIVE") {
|
|
65479
|
+
throw new Error("config.buyer.executionMode must be DRY_RUN or LIVE");
|
|
65480
|
+
}
|
|
65481
|
+
let polymarket;
|
|
65482
|
+
if (input.polymarket !== void 0) {
|
|
65483
|
+
const polymarketInput = requireObject(input.polymarket, "config.buyer.polymarket");
|
|
65484
|
+
const bin = optionalString(polymarketInput.bin, "config.buyer.polymarket.bin");
|
|
65485
|
+
const timeoutMs = polymarketInput.timeoutMs === void 0 ? void 0 : requireInteger(polymarketInput.timeoutMs, "config.buyer.polymarket.timeoutMs", 1);
|
|
65486
|
+
polymarket = {
|
|
65487
|
+
...bin ? { bin } : {},
|
|
65488
|
+
...timeoutMs ? { timeoutMs } : {}
|
|
65489
|
+
};
|
|
65490
|
+
}
|
|
65491
|
+
return {
|
|
65492
|
+
enabled: requireBoolean(input.enabled, "config.buyer.enabled"),
|
|
65493
|
+
executionMode,
|
|
65494
|
+
subscriptions: requireArray(input.subscriptions, "config.buyer.subscriptions").map(parseBuyerSubscription),
|
|
65495
|
+
riskPolicy: parseRiskPolicy(input.riskPolicy),
|
|
65496
|
+
...polymarket ? { polymarket } : {}
|
|
65497
|
+
};
|
|
65498
|
+
}
|
|
65499
|
+
function parseSignalTradingConfig(value) {
|
|
65500
|
+
const input = requireObject(value, "config");
|
|
65501
|
+
if (input.version !== SIGNAL_TRADING_CONFIG_VERSION) {
|
|
65502
|
+
throw new Error(`config.version must be ${SIGNAL_TRADING_CONFIG_VERSION}`);
|
|
65503
|
+
}
|
|
65504
|
+
let provider;
|
|
65505
|
+
if (input.provider !== void 0) {
|
|
65506
|
+
const providerInput = requireObject(input.provider, "config.provider");
|
|
65507
|
+
provider = {
|
|
65508
|
+
routes: requireArray(providerInput.routes, "config.provider.routes").map(parseProviderRoute)
|
|
65509
|
+
};
|
|
65510
|
+
}
|
|
65511
|
+
const buyer = input.buyer === void 0 ? void 0 : parseBuyer(input.buyer);
|
|
65512
|
+
return {
|
|
65513
|
+
version: SIGNAL_TRADING_CONFIG_VERSION,
|
|
65514
|
+
...provider ? { provider } : {},
|
|
65515
|
+
...buyer ? { buyer } : {}
|
|
65516
|
+
};
|
|
65517
|
+
}
|
|
65518
|
+
function resolveSignalTradingDir(homeDir) {
|
|
65519
|
+
return (0, import_node_path30.join)(resolveTaskPaths(homeDir).homeDir, "signal-trading");
|
|
65520
|
+
}
|
|
65521
|
+
function resolveSignalTradingConfigPath(homeDir) {
|
|
65522
|
+
return (0, import_node_path30.join)(resolveSignalTradingDir(homeDir), "config.json");
|
|
65523
|
+
}
|
|
65524
|
+
function loadSignalTradingConfig(homeDir) {
|
|
65525
|
+
const path2 = resolveSignalTradingConfigPath(homeDir);
|
|
65526
|
+
if (!(0, import_node_fs25.existsSync)(path2)) {
|
|
65527
|
+
throw new Error(`signal trading config not found: ${path2}`);
|
|
65528
|
+
}
|
|
65529
|
+
let parsed;
|
|
65530
|
+
try {
|
|
65531
|
+
parsed = JSON.parse((0, import_node_fs25.readFileSync)(path2, "utf8"));
|
|
65532
|
+
} catch (error) {
|
|
65533
|
+
throw new Error(
|
|
65534
|
+
`signal trading config is not valid JSON: ${path2}: ${error instanceof Error ? error.message : String(error)}`
|
|
65535
|
+
);
|
|
65536
|
+
}
|
|
65537
|
+
return parseSignalTradingConfig(parsed);
|
|
65538
|
+
}
|
|
65539
|
+
var import_node_fs25, import_node_path30, SIGNAL_TRADING_CONFIG_VERSION;
|
|
65540
|
+
var init_config = __esm({
|
|
65541
|
+
"src/signal-trading/config.ts"() {
|
|
65542
|
+
"use strict";
|
|
65543
|
+
import_node_fs25 = require("node:fs");
|
|
65544
|
+
import_node_path30 = require("node:path");
|
|
65545
|
+
init_paths();
|
|
65546
|
+
SIGNAL_TRADING_CONFIG_VERSION = 1;
|
|
65547
|
+
}
|
|
65548
|
+
});
|
|
65549
|
+
|
|
65550
|
+
// src/signal-trading/protocol.ts
|
|
65551
|
+
function isPlainObject3(value) {
|
|
65552
|
+
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
65553
|
+
}
|
|
65554
|
+
function requireObject2(value, path2) {
|
|
65555
|
+
if (!isPlainObject3(value)) {
|
|
65556
|
+
throw new Error(`${path2} must be an object`);
|
|
65557
|
+
}
|
|
65558
|
+
return value;
|
|
65559
|
+
}
|
|
65560
|
+
function requireString2(value, path2) {
|
|
65561
|
+
if (typeof value !== "string" || value.trim().length === 0) {
|
|
65562
|
+
throw new Error(`${path2} must be a non-empty string`);
|
|
65563
|
+
}
|
|
65564
|
+
return value.trim();
|
|
65565
|
+
}
|
|
65566
|
+
function optionalString2(value, path2) {
|
|
65567
|
+
if (value === void 0) {
|
|
65568
|
+
return void 0;
|
|
65569
|
+
}
|
|
65570
|
+
return requireString2(value, path2);
|
|
65571
|
+
}
|
|
65572
|
+
function requireEnum(value, path2, values) {
|
|
65573
|
+
if (typeof value !== "string" || !values.includes(value)) {
|
|
65574
|
+
throw new Error(`${path2} must be one of ${values.join(", ")}`);
|
|
65575
|
+
}
|
|
65576
|
+
return value;
|
|
65577
|
+
}
|
|
65578
|
+
function requireFiniteNumber(value, path2) {
|
|
65579
|
+
if (typeof value !== "number" || !Number.isFinite(value)) {
|
|
65580
|
+
throw new Error(`${path2} must be a finite number`);
|
|
65581
|
+
}
|
|
65582
|
+
return value;
|
|
65583
|
+
}
|
|
65584
|
+
function requireInteger2(value, path2, minimum = 0) {
|
|
65585
|
+
const parsed = requireFiniteNumber(value, path2);
|
|
65586
|
+
if (!Number.isInteger(parsed) || parsed < minimum) {
|
|
65587
|
+
throw new Error(`${path2} must be an integer >= ${minimum}`);
|
|
65588
|
+
}
|
|
65589
|
+
return parsed;
|
|
65590
|
+
}
|
|
65591
|
+
function requireIsoTimestamp(value, path2) {
|
|
65592
|
+
const timestamp = requireString2(value, path2);
|
|
65593
|
+
if (!Number.isFinite(Date.parse(timestamp))) {
|
|
65594
|
+
throw new Error(`${path2} must be an ISO-8601 timestamp`);
|
|
65595
|
+
}
|
|
65596
|
+
return timestamp;
|
|
65597
|
+
}
|
|
65598
|
+
function readStringRecord2(value, path2) {
|
|
65599
|
+
if (value === void 0) {
|
|
65600
|
+
return void 0;
|
|
65601
|
+
}
|
|
65602
|
+
const input = requireObject2(value, path2);
|
|
65603
|
+
const result = {};
|
|
65604
|
+
for (const [key, item] of Object.entries(input)) {
|
|
65605
|
+
result[key] = requireString2(item, `${path2}.${key}`);
|
|
65606
|
+
}
|
|
65607
|
+
return result;
|
|
65608
|
+
}
|
|
65609
|
+
function parseTradingSignalV1(value) {
|
|
65610
|
+
const input = requireObject2(value, "signal");
|
|
65611
|
+
const specVersion = requireEnum(input.specVersion, "signal.specVersion", [SIGNAL_SPEC_VERSION]);
|
|
65612
|
+
const emittedAt = requireIsoTimestamp(input.emittedAt, "signal.emittedAt");
|
|
65613
|
+
const expiresAt = requireIsoTimestamp(input.expiresAt, "signal.expiresAt");
|
|
65614
|
+
if (Date.parse(expiresAt) <= Date.parse(emittedAt)) {
|
|
65615
|
+
throw new Error("signal.expiresAt must be later than signal.emittedAt");
|
|
65616
|
+
}
|
|
65617
|
+
const instrumentInput = requireObject2(input.instrument, "signal.instrument");
|
|
65618
|
+
const instrument = {
|
|
65619
|
+
symbol: requireString2(instrumentInput.symbol, "signal.instrument.symbol"),
|
|
65620
|
+
marketType: requireEnum(
|
|
65621
|
+
instrumentInput.marketType,
|
|
65622
|
+
"signal.instrument.marketType",
|
|
65623
|
+
["SPOT", "PERP", "ONCHAIN"]
|
|
65624
|
+
)
|
|
65625
|
+
};
|
|
65626
|
+
const chainId = optionalString2(instrumentInput.chainId, "signal.instrument.chainId");
|
|
65627
|
+
const tokenIn = optionalString2(instrumentInput.tokenIn, "signal.instrument.tokenIn");
|
|
65628
|
+
const tokenOut = optionalString2(instrumentInput.tokenOut, "signal.instrument.tokenOut");
|
|
65629
|
+
if (chainId) {
|
|
65630
|
+
instrument.chainId = chainId;
|
|
65631
|
+
}
|
|
65632
|
+
if (tokenIn) {
|
|
65633
|
+
instrument.tokenIn = tokenIn;
|
|
65634
|
+
}
|
|
65635
|
+
if (tokenOut) {
|
|
65636
|
+
instrument.tokenOut = tokenOut;
|
|
65637
|
+
}
|
|
65638
|
+
const intentInput = requireObject2(input.intent, "signal.intent");
|
|
65639
|
+
const action = requireEnum(
|
|
65640
|
+
intentInput.action,
|
|
65641
|
+
"signal.intent.action",
|
|
65642
|
+
["ENTER", "EXIT", "REBALANCE", "CANCEL", "NO_TRADE"]
|
|
65643
|
+
);
|
|
65644
|
+
let intent;
|
|
65645
|
+
if (action === "ENTER" || action === "EXIT") {
|
|
65646
|
+
intent = {
|
|
65647
|
+
action,
|
|
65648
|
+
side: requireEnum(intentInput.side, "signal.intent.side", ["BUY", "SELL"]),
|
|
65649
|
+
orderType: requireEnum(
|
|
65650
|
+
intentInput.orderType,
|
|
65651
|
+
"signal.intent.orderType",
|
|
65652
|
+
["MARKET", "LIMIT"]
|
|
65653
|
+
)
|
|
65654
|
+
};
|
|
65655
|
+
} else if (action === "REBALANCE") {
|
|
65656
|
+
const targetWeightBps = requireInteger2(
|
|
65657
|
+
intentInput.targetWeightBps,
|
|
65658
|
+
"signal.intent.targetWeightBps"
|
|
65659
|
+
);
|
|
65660
|
+
if (targetWeightBps > 1e4) {
|
|
65661
|
+
throw new Error("signal.intent.targetWeightBps must be <= 10000");
|
|
65662
|
+
}
|
|
65663
|
+
intent = { action, targetWeightBps };
|
|
65664
|
+
} else if (action === "CANCEL") {
|
|
65665
|
+
intent = {
|
|
65666
|
+
action,
|
|
65667
|
+
targetSignalId: optionalString2(intentInput.targetSignalId, "signal.intent.targetSignalId"),
|
|
65668
|
+
targetExecutionId: optionalString2(
|
|
65669
|
+
intentInput.targetExecutionId,
|
|
65670
|
+
"signal.intent.targetExecutionId"
|
|
65671
|
+
)
|
|
65672
|
+
};
|
|
65673
|
+
} else {
|
|
65674
|
+
intent = {
|
|
65675
|
+
action,
|
|
65676
|
+
reason: requireString2(intentInput.reason, "signal.intent.reason")
|
|
65677
|
+
};
|
|
65678
|
+
}
|
|
65679
|
+
let sizing;
|
|
65680
|
+
if (input.sizing !== void 0) {
|
|
65681
|
+
const sizingInput = requireObject2(input.sizing, "signal.sizing");
|
|
65682
|
+
sizing = {
|
|
65683
|
+
type: requireEnum(
|
|
65684
|
+
sizingInput.type,
|
|
65685
|
+
"signal.sizing.type",
|
|
65686
|
+
["FIXED_BASE", "FIXED_QUOTE", "PORTFOLIO_BPS"]
|
|
65687
|
+
),
|
|
65688
|
+
value: requireString2(sizingInput.value, "signal.sizing.value")
|
|
65689
|
+
};
|
|
65690
|
+
} else if (action === "ENTER" || action === "EXIT") {
|
|
65691
|
+
throw new Error(`signal.sizing is required for ${action} signals`);
|
|
65692
|
+
}
|
|
65693
|
+
let constraints;
|
|
65694
|
+
if (input.constraints !== void 0) {
|
|
65695
|
+
const constraintsInput = requireObject2(input.constraints, "signal.constraints");
|
|
65696
|
+
constraints = {};
|
|
65697
|
+
const limitPrice = optionalString2(constraintsInput.limitPrice, "signal.constraints.limitPrice");
|
|
65698
|
+
if (limitPrice) {
|
|
65699
|
+
constraints.limitPrice = limitPrice;
|
|
65700
|
+
}
|
|
65701
|
+
if (constraintsInput.maxSlippageBps !== void 0) {
|
|
65702
|
+
constraints.maxSlippageBps = requireInteger2(
|
|
65703
|
+
constraintsInput.maxSlippageBps,
|
|
65704
|
+
"signal.constraints.maxSlippageBps"
|
|
65705
|
+
);
|
|
65706
|
+
}
|
|
65707
|
+
if (constraintsInput.timeInForce !== void 0) {
|
|
65708
|
+
constraints.timeInForce = requireEnum(
|
|
65709
|
+
constraintsInput.timeInForce,
|
|
65710
|
+
"signal.constraints.timeInForce",
|
|
65711
|
+
["GTC", "IOC", "FOK"]
|
|
65712
|
+
);
|
|
65713
|
+
}
|
|
65714
|
+
}
|
|
65715
|
+
return {
|
|
65716
|
+
specVersion,
|
|
65717
|
+
signalId: requireString2(input.signalId, "signal.signalId"),
|
|
65718
|
+
serviceId: requireString2(input.serviceId, "signal.serviceId"),
|
|
65719
|
+
subscriptionId: requireString2(input.subscriptionId, "signal.subscriptionId"),
|
|
65720
|
+
providerAgentId: requireString2(input.providerAgentId, "signal.providerAgentId"),
|
|
65721
|
+
sequence: requireInteger2(input.sequence, "signal.sequence", 1),
|
|
65722
|
+
emittedAt,
|
|
65723
|
+
expiresAt,
|
|
65724
|
+
instrument,
|
|
65725
|
+
intent,
|
|
65726
|
+
...sizing ? { sizing } : {},
|
|
65727
|
+
...constraints ? { constraints } : {},
|
|
65728
|
+
...input.metadata !== void 0 ? { metadata: readStringRecord2(input.metadata, "signal.metadata") } : {}
|
|
65729
|
+
};
|
|
65730
|
+
}
|
|
65731
|
+
function buildSignalEnvelopePayload(signal) {
|
|
65732
|
+
return { type: SIGNAL_PAYLOAD_TYPE, signal };
|
|
65733
|
+
}
|
|
65734
|
+
function extractSignalEnvelopePayload(envelope) {
|
|
65735
|
+
if (!isPlainObject3(envelope) || !isPlainObject3(envelope.payload)) {
|
|
65736
|
+
return null;
|
|
65737
|
+
}
|
|
65738
|
+
if (envelope.payload.type !== SIGNAL_PAYLOAD_TYPE) {
|
|
65739
|
+
return null;
|
|
65740
|
+
}
|
|
65741
|
+
return {
|
|
65742
|
+
type: SIGNAL_PAYLOAD_TYPE,
|
|
65743
|
+
signal: parseTradingSignalV1(envelope.payload.signal)
|
|
65744
|
+
};
|
|
65745
|
+
}
|
|
65746
|
+
function hasSignalEnvelopePayload(envelope) {
|
|
65747
|
+
return isPlainObject3(envelope) && isPlainObject3(envelope.payload) && envelope.payload.type === SIGNAL_PAYLOAD_TYPE;
|
|
65748
|
+
}
|
|
65749
|
+
var SIGNAL_PAYLOAD_TYPE, SIGNAL_SPEC_VERSION;
|
|
65750
|
+
var init_protocol = __esm({
|
|
65751
|
+
"src/signal-trading/protocol.ts"() {
|
|
65752
|
+
"use strict";
|
|
65753
|
+
SIGNAL_PAYLOAD_TYPE = "signal";
|
|
65754
|
+
SIGNAL_SPEC_VERSION = "1.0";
|
|
65755
|
+
}
|
|
65756
|
+
});
|
|
65757
|
+
|
|
65758
|
+
// src/signal-trading/publisher.ts
|
|
65759
|
+
async function handleSignalPublishCommand(params) {
|
|
65760
|
+
const signal = parseTradingSignalV1(params.command.signal);
|
|
65761
|
+
if (params.command.serviceId !== signal.serviceId) {
|
|
65762
|
+
throw new Error(
|
|
65763
|
+
`signal publish --service-id ${params.command.serviceId} does not match signal.serviceId ${signal.serviceId}`
|
|
65764
|
+
);
|
|
65765
|
+
}
|
|
65766
|
+
const config = loadSignalTradingConfig(params.homeDir);
|
|
65767
|
+
const routes = config.provider?.routes.filter((route) => {
|
|
65768
|
+
return route.serviceId === signal.serviceId && route.subscriptionId === signal.subscriptionId;
|
|
65769
|
+
}) ?? [];
|
|
65770
|
+
if (routes.length === 0) {
|
|
65771
|
+
throw new Error(
|
|
65772
|
+
`no provider route configured for serviceId=${signal.serviceId} subscriptionId=${signal.subscriptionId}`
|
|
65773
|
+
);
|
|
65774
|
+
}
|
|
65775
|
+
const deliveries = [];
|
|
65776
|
+
for (const route of routes) {
|
|
65777
|
+
if (route.myAgentId && route.myAgentId !== signal.providerAgentId) {
|
|
65778
|
+
throw new Error(
|
|
65779
|
+
`provider route myAgentId=${route.myAgentId} does not match signal.providerAgentId=${signal.providerAgentId}`
|
|
65780
|
+
);
|
|
65781
|
+
}
|
|
65782
|
+
const childCommand = {
|
|
65783
|
+
id: (0, import_node_crypto14.randomUUID)(),
|
|
65784
|
+
type: "xmtp-send",
|
|
65785
|
+
jobId: route.jobId,
|
|
65786
|
+
message: `Trading signal ${signal.signalId} from service ${signal.serviceId}`,
|
|
65787
|
+
sessionAgentId: route.toAgentId,
|
|
65788
|
+
myAgentId: route.myAgentId ?? signal.providerAgentId,
|
|
65789
|
+
toAgentId: route.toAgentId,
|
|
65790
|
+
toXmtpAddress: route.toXmtpAddress,
|
|
65791
|
+
payload: buildSignalEnvelopePayload(signal),
|
|
65792
|
+
createdAt: params.command.createdAt
|
|
65793
|
+
};
|
|
65794
|
+
const result = await handleXmtpSendCommand({
|
|
65795
|
+
command: childCommand,
|
|
65796
|
+
service: params.service,
|
|
65797
|
+
store: params.store,
|
|
65798
|
+
sessionStore: params.sessionStore
|
|
65799
|
+
});
|
|
65800
|
+
deliveries.push({
|
|
65801
|
+
subscriptionId: route.subscriptionId,
|
|
65802
|
+
jobId: route.jobId,
|
|
65803
|
+
toAgentId: route.toAgentId,
|
|
65804
|
+
messageId: result.messageId
|
|
65805
|
+
});
|
|
65806
|
+
}
|
|
65807
|
+
return {
|
|
65808
|
+
signalId: signal.signalId,
|
|
65809
|
+
serviceId: signal.serviceId,
|
|
65810
|
+
deliveries
|
|
65811
|
+
};
|
|
65812
|
+
}
|
|
65813
|
+
var import_node_crypto14;
|
|
65814
|
+
var init_publisher = __esm({
|
|
65815
|
+
"src/signal-trading/publisher.ts"() {
|
|
65816
|
+
"use strict";
|
|
65817
|
+
import_node_crypto14 = require("node:crypto");
|
|
65818
|
+
init_xmtp_send();
|
|
65819
|
+
init_config();
|
|
65820
|
+
init_protocol();
|
|
65821
|
+
}
|
|
65822
|
+
});
|
|
65823
|
+
|
|
65287
65824
|
// src/command-processor.ts
|
|
65288
65825
|
function commandSentryExtra(command, extra = {}) {
|
|
65289
65826
|
const base = {
|
|
@@ -65308,6 +65845,11 @@ function commandSentryExtra(command, extra = {}) {
|
|
|
65308
65845
|
base.myAgentId = command.myAgentId ?? "";
|
|
65309
65846
|
base.toAgentId = command.toAgentId ?? "";
|
|
65310
65847
|
base.toXmtpAddress = command.toXmtpAddress ?? "";
|
|
65848
|
+
} else if (command.type === "signal-publish") {
|
|
65849
|
+
base.serviceId = command.serviceId;
|
|
65850
|
+
base.signalId = command.signal.signalId;
|
|
65851
|
+
base.subscriptionId = command.signal.subscriptionId;
|
|
65852
|
+
base.agentId = command.signal.providerAgentId;
|
|
65311
65853
|
} else if (command.type === "xmtp-deny-pending-conversation") {
|
|
65312
65854
|
base.groupId = command.groupId;
|
|
65313
65855
|
base.jobId = command.jobId ?? "";
|
|
@@ -65560,6 +66102,16 @@ async function handleDaemonCommand(command, params) {
|
|
|
65560
66102
|
});
|
|
65561
66103
|
return { ok: true, messageId: result.messageId };
|
|
65562
66104
|
}
|
|
66105
|
+
if (command.type === "signal-publish") {
|
|
66106
|
+
const payload = await handleSignalPublishCommand({
|
|
66107
|
+
command,
|
|
66108
|
+
service: params.service,
|
|
66109
|
+
store: params.store,
|
|
66110
|
+
sessionStore: params.sessionStore,
|
|
66111
|
+
homeDir: params.homeDir
|
|
66112
|
+
});
|
|
66113
|
+
return { ok: true, payload };
|
|
66114
|
+
}
|
|
65563
66115
|
if (command.type === "xmtp-get-pending-list") {
|
|
65564
66116
|
return { ok: true, payload: await listPendingTaskRequests(params) };
|
|
65565
66117
|
}
|
|
@@ -65642,12 +66194,12 @@ async function listPendingTaskRequests(params) {
|
|
|
65642
66194
|
}
|
|
65643
66195
|
async function denyPendingConversationsByJobId(jobId, params, content2) {
|
|
65644
66196
|
const pending = await listPendingTaskRequests(params);
|
|
65645
|
-
const matched = pending.filter((item) =>
|
|
66197
|
+
const matched = pending.filter((item) => isPlainObject4(item) && readString4(item.jobId) === jobId);
|
|
65646
66198
|
const clientAddresses = [...params.service.getClients().keys()];
|
|
65647
66199
|
const targetsByKey = collectDenyTargetsFromPending(matched, clientAddresses);
|
|
65648
66200
|
const groupIds = /* @__PURE__ */ new Set();
|
|
65649
66201
|
for (const item of matched) {
|
|
65650
|
-
if (!
|
|
66202
|
+
if (!isPlainObject4(item)) {
|
|
65651
66203
|
continue;
|
|
65652
66204
|
}
|
|
65653
66205
|
const groupId = readString4(item.groupId);
|
|
@@ -65674,7 +66226,7 @@ async function denyPendingConversationsByJobId(jobId, params, content2) {
|
|
|
65674
66226
|
function collectDenyTargetsFromPending(pending, fallbackAddresses) {
|
|
65675
66227
|
const targetsByKey = /* @__PURE__ */ new Map();
|
|
65676
66228
|
for (const item of pending) {
|
|
65677
|
-
if (!
|
|
66229
|
+
if (!isPlainObject4(item)) {
|
|
65678
66230
|
continue;
|
|
65679
66231
|
}
|
|
65680
66232
|
const groupId = readString4(item.groupId);
|
|
@@ -65699,7 +66251,7 @@ ${groupId}`, {
|
|
|
65699
66251
|
async function resolvePendingTargetsByGroupId(groupId, addresses, params) {
|
|
65700
66252
|
const addressSet = addresses ? new Set(addresses) : null;
|
|
65701
66253
|
const pending = (await listPendingTaskRequests(params)).filter((item) => {
|
|
65702
|
-
if (!
|
|
66254
|
+
if (!isPlainObject4(item) || readString4(item.groupId) !== groupId) {
|
|
65703
66255
|
return false;
|
|
65704
66256
|
}
|
|
65705
66257
|
const address = readString4(item.myXmtpAddress);
|
|
@@ -65819,7 +66371,7 @@ function filterKnownPendingGroups(items, sessionStore) {
|
|
|
65819
66371
|
return items;
|
|
65820
66372
|
}
|
|
65821
66373
|
return items.filter((item) => {
|
|
65822
|
-
if (!
|
|
66374
|
+
if (!isPlainObject4(item)) {
|
|
65823
66375
|
return true;
|
|
65824
66376
|
}
|
|
65825
66377
|
const jobId = readString4(item.jobId);
|
|
@@ -65830,7 +66382,7 @@ function filterKnownPendingGroups(items, sessionStore) {
|
|
|
65830
66382
|
return sessionStore.querySessions({ jobId, toAgentId, limit: 1 }).length === 0;
|
|
65831
66383
|
});
|
|
65832
66384
|
}
|
|
65833
|
-
function
|
|
66385
|
+
function isPlainObject4(value) {
|
|
65834
66386
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
65835
66387
|
}
|
|
65836
66388
|
function readString4(value) {
|
|
@@ -65964,6 +66516,11 @@ function formatCommandCompleted(command, result) {
|
|
|
65964
66516
|
if (command.type === "xmtp-send") {
|
|
65965
66517
|
return `[okx-agent-task] xmtp-send command completed id=${command.id} job=${command.jobId} messageId=${result.messageId}`;
|
|
65966
66518
|
}
|
|
66519
|
+
if (command.type === "signal-publish") {
|
|
66520
|
+
const payload = isPlainObject4(result.payload) ? result.payload : {};
|
|
66521
|
+
const deliveries = Array.isArray(payload.deliveries) ? payload.deliveries.length : 0;
|
|
66522
|
+
return `[signal-trading] signal-publish command completed id=${command.id} service=${command.serviceId} signal=${command.signal.signalId} deliveries=${deliveries}`;
|
|
66523
|
+
}
|
|
65967
66524
|
if (command.type === "xmtp-get-pending-list") {
|
|
65968
66525
|
return `[okx-agent-task] xmtp-get-pending-list command completed id=${command.id}`;
|
|
65969
66526
|
}
|
|
@@ -65984,8 +66541,8 @@ function formatCommandCompleted(command, result) {
|
|
|
65984
66541
|
return `[okx-agent-task] xmtp-refresh-agents command completed id=${command.id}`;
|
|
65985
66542
|
}
|
|
65986
66543
|
function formatXmtpDebugCompleted(command, payload) {
|
|
65987
|
-
const record =
|
|
65988
|
-
const summary =
|
|
66544
|
+
const record = isPlainObject4(payload) ? payload : {};
|
|
66545
|
+
const summary = isPlainObject4(record.summary) ? record.summary : {};
|
|
65989
66546
|
const count = command.action === "group-list" ? record.groupCount ?? 0 : command.action === "group-inspect" ? record.conversationFound ? 1 : 0 : summary.matchedCount ?? 0;
|
|
65990
66547
|
return `[okx-agent-task] xmtp-debug command completed id=${command.id} action=${command.action} rows=${String(count)}`;
|
|
65991
66548
|
}
|
|
@@ -66139,6 +66696,7 @@ var init_command_processor = __esm({
|
|
|
66139
66696
|
init_user_attention_ipc();
|
|
66140
66697
|
init_sentry_logger();
|
|
66141
66698
|
init_xmtp_debug();
|
|
66699
|
+
init_publisher();
|
|
66142
66700
|
DEFAULT_COMMAND_EXECUTION_TIMEOUT_MS = 5e4;
|
|
66143
66701
|
DEFAULT_COMMAND_STALE_TIMEOUT_MS = 12e4;
|
|
66144
66702
|
DEFAULT_AI_COMMAND_STALE_TIMEOUT_MS = 30 * 6e4;
|
|
@@ -66192,7 +66750,7 @@ function tryMarkProcessed(messageId) {
|
|
|
66192
66750
|
}
|
|
66193
66751
|
return true;
|
|
66194
66752
|
}
|
|
66195
|
-
function
|
|
66753
|
+
function isPlainObject5(value) {
|
|
66196
66754
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
66197
66755
|
}
|
|
66198
66756
|
function safeStringify(value) {
|
|
@@ -66249,9 +66807,9 @@ function readNumber(value) {
|
|
|
66249
66807
|
}
|
|
66250
66808
|
function resolveSessionAgentId(params) {
|
|
66251
66809
|
const { chatType, payload, myXmtpAddress } = params;
|
|
66252
|
-
const payloadObject =
|
|
66253
|
-
const sender =
|
|
66254
|
-
const message =
|
|
66810
|
+
const payloadObject = isPlainObject5(payload) ? payload : null;
|
|
66811
|
+
const sender = isPlainObject5(payloadObject?.sender) ? payloadObject.sender : null;
|
|
66812
|
+
const message = isPlainObject5(payloadObject?.message) ? payloadObject.message : null;
|
|
66255
66813
|
const localAgentId = XmtpService.getInstance().getAgentByAddress(myXmtpAddress)?.agentId ?? null;
|
|
66256
66814
|
if (chatType === "group") {
|
|
66257
66815
|
return readString5(sender?.agentId) ?? readString5(payloadObject?.receiverAgentId) ?? localAgentId;
|
|
@@ -66262,7 +66820,7 @@ function resolveSessionAgentId(params) {
|
|
|
66262
66820
|
return localAgentId;
|
|
66263
66821
|
}
|
|
66264
66822
|
function routeMessage(chatType, parsed, payload) {
|
|
66265
|
-
if (!parsed || !
|
|
66823
|
+
if (!parsed || !isPlainObject5(payload)) {
|
|
66266
66824
|
return {
|
|
66267
66825
|
jobId: BACKUP_JOB_ID,
|
|
66268
66826
|
route: "backup",
|
|
@@ -66274,7 +66832,7 @@ function routeMessage(chatType, parsed, payload) {
|
|
|
66274
66832
|
return jobId ? { jobId, route: "job", routeReason: "group-job-id" } : { jobId: BACKUP_JOB_ID, route: "backup", routeReason: "group-missing-job-id" };
|
|
66275
66833
|
}
|
|
66276
66834
|
if (chatType === "dm") {
|
|
66277
|
-
const message =
|
|
66835
|
+
const message = isPlainObject5(payload.message) ? payload.message : null;
|
|
66278
66836
|
const nestedJobId = readString5(message?.jobId);
|
|
66279
66837
|
const directJobId = readString5(payload.jobId);
|
|
66280
66838
|
const jobId = nestedJobId ?? directJobId;
|
|
@@ -66287,10 +66845,10 @@ function routeMessage(chatType, parsed, payload) {
|
|
|
66287
66845
|
return { jobId: BACKUP_JOB_ID, route: "backup", routeReason: "unknown-conversation" };
|
|
66288
66846
|
}
|
|
66289
66847
|
function extractDirectToUserNotification(payload) {
|
|
66290
|
-
if (!
|
|
66848
|
+
if (!isPlainObject5(payload)) {
|
|
66291
66849
|
return { kind: "none" };
|
|
66292
66850
|
}
|
|
66293
|
-
const message =
|
|
66851
|
+
const message = isPlainObject5(payload.message) ? payload.message : null;
|
|
66294
66852
|
if (message?.isDirectToUser !== true) {
|
|
66295
66853
|
return { kind: "none" };
|
|
66296
66854
|
}
|
|
@@ -66314,10 +66872,10 @@ function extractDirectToUserNotification(payload) {
|
|
|
66314
66872
|
};
|
|
66315
66873
|
}
|
|
66316
66874
|
function extractSystemNotification(payload) {
|
|
66317
|
-
if (!
|
|
66875
|
+
if (!isPlainObject5(payload)) {
|
|
66318
66876
|
return null;
|
|
66319
66877
|
}
|
|
66320
|
-
const message =
|
|
66878
|
+
const message = isPlainObject5(payload.message) ? payload.message : null;
|
|
66321
66879
|
const isDirectCommunication = message?.isDirectCommunication === true;
|
|
66322
66880
|
if (message?.source !== "system" && !isDirectCommunication) {
|
|
66323
66881
|
return null;
|
|
@@ -66609,7 +67167,7 @@ function maybeNotifyInboundAgentMessage(params) {
|
|
|
66609
67167
|
return;
|
|
66610
67168
|
}
|
|
66611
67169
|
const content2 = payloadObject.content;
|
|
66612
|
-
const sender =
|
|
67170
|
+
const sender = isPlainObject5(payloadObject.sender) ? payloadObject.sender : null;
|
|
66613
67171
|
const localAgent = XmtpService.getInstance().getAgentByAddress(params.deps.myXmtpAddress);
|
|
66614
67172
|
void notifyAgentMessageToUserAttention({
|
|
66615
67173
|
direction: "inbound" /* INBOUND */,
|
|
@@ -66640,11 +67198,11 @@ function stringifySystemPayload(payload) {
|
|
|
66640
67198
|
}
|
|
66641
67199
|
}
|
|
66642
67200
|
function summarizePayloadForLog(payload) {
|
|
66643
|
-
if (!
|
|
67201
|
+
if (!isPlainObject5(payload)) {
|
|
66644
67202
|
return "payload=non-object";
|
|
66645
67203
|
}
|
|
66646
|
-
const message =
|
|
66647
|
-
const sender =
|
|
67204
|
+
const message = isPlainObject5(payload.message) ? payload.message : null;
|
|
67205
|
+
const sender = isPlainObject5(payload.sender) ? payload.sender : null;
|
|
66648
67206
|
const jobId = readString5(payload.jobId) ?? readString5(message?.jobId);
|
|
66649
67207
|
const parts = [
|
|
66650
67208
|
readString5(payload.msgType) ? `type=${readString5(payload.msgType)}` : null,
|
|
@@ -66913,7 +67471,7 @@ async function verifyInboundA2AGroupMessage(params) {
|
|
|
66913
67471
|
messageId,
|
|
66914
67472
|
groupId,
|
|
66915
67473
|
jobId,
|
|
66916
|
-
agentId: readString5(
|
|
67474
|
+
agentId: readString5(isPlainObject5(payload.sender) ? payload.sender.agentId : null),
|
|
66917
67475
|
localAgentId: myAgent?.agentId ?? null,
|
|
66918
67476
|
senderAddress,
|
|
66919
67477
|
senderInboxId,
|
|
@@ -66939,7 +67497,7 @@ async function verifyInboundA2AGroupMessage(params) {
|
|
|
66939
67497
|
});
|
|
66940
67498
|
return false;
|
|
66941
67499
|
}
|
|
66942
|
-
const sender =
|
|
67500
|
+
const sender = isPlainObject5(payload.sender) ? payload.sender : null;
|
|
66943
67501
|
const senderAgentId = readString5(sender?.agentId);
|
|
66944
67502
|
const senderRole = readNumber(sender?.role);
|
|
66945
67503
|
if (!senderAgentId || !myAgent) {
|
|
@@ -67163,7 +67721,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67163
67721
|
timing.mark("payloadParse", parseStartedAt);
|
|
67164
67722
|
const directToUser = chatType === "dm" && parseResult.ok ? extractDirectToUserNotification(parseResult.data) : { kind: "none" };
|
|
67165
67723
|
if (directToUser.kind === "invalid") {
|
|
67166
|
-
const droppedMessageId = messageId || `direct-to-user-${(0,
|
|
67724
|
+
const droppedMessageId = messageId || `direct-to-user-${(0, import_node_crypto15.randomUUID)()}`;
|
|
67167
67725
|
logger.error(
|
|
67168
67726
|
LogEvent.INBOUND_DROP_DM_INVALID_PAYLOAD,
|
|
67169
67727
|
new Error("Invalid direct-to-user system DM"),
|
|
@@ -67187,7 +67745,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67187
67745
|
await dispatchDirectToUserNotification({
|
|
67188
67746
|
deps,
|
|
67189
67747
|
notification: directToUser.notification,
|
|
67190
|
-
messageId: messageId || `direct-to-user-${(0,
|
|
67748
|
+
messageId: messageId || `direct-to-user-${(0, import_node_crypto15.randomUUID)()}`,
|
|
67191
67749
|
timing,
|
|
67192
67750
|
source: options.source ?? "live"
|
|
67193
67751
|
});
|
|
@@ -67195,7 +67753,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67195
67753
|
}
|
|
67196
67754
|
const systemNotification = chatType === "dm" && parseResult.ok ? extractSystemNotification(parseResult.data) : null;
|
|
67197
67755
|
if (systemNotification) {
|
|
67198
|
-
const systemMessageId = messageId || `system-${(0,
|
|
67756
|
+
const systemMessageId = messageId || `system-${(0, import_node_crypto15.randomUUID)()}`;
|
|
67199
67757
|
logWithTimestamp(
|
|
67200
67758
|
`[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)}`
|
|
67201
67759
|
);
|
|
@@ -67394,7 +67952,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67394
67952
|
);
|
|
67395
67953
|
}
|
|
67396
67954
|
if (route.route === "job" && chatType === "group") {
|
|
67397
|
-
const payloadObject =
|
|
67955
|
+
const payloadObject = isPlainObject5(parseResult.ok ? parseResult.data : null) ? parseResult.data : null;
|
|
67398
67956
|
const service = XmtpService.getInstance();
|
|
67399
67957
|
const trustedSystemSender = service.isTrustedSystemAccountSender({
|
|
67400
67958
|
senderAddress,
|
|
@@ -67420,7 +67978,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67420
67978
|
});
|
|
67421
67979
|
return true;
|
|
67422
67980
|
}
|
|
67423
|
-
const sender =
|
|
67981
|
+
const sender = isPlainObject5(payloadObject?.sender) ? payloadObject.sender : null;
|
|
67424
67982
|
const localAgent = service.getAgentByAddress(deps.myXmtpAddress);
|
|
67425
67983
|
const myAgentId = localAgent?.agentId ?? readString5(payloadObject?.receiverAgentId) ?? sessionAgentId ?? null;
|
|
67426
67984
|
const toAgentId = readString5(sender?.agentId);
|
|
@@ -67440,7 +67998,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67440
67998
|
if (!accepted) {
|
|
67441
67999
|
return true;
|
|
67442
68000
|
}
|
|
67443
|
-
const routedMessageId = messageId || `group-${(0,
|
|
68001
|
+
const routedMessageId = messageId || `group-${(0, import_node_crypto15.randomUUID)()}`;
|
|
67444
68002
|
const sessionKey = ensureInboundGroupSession(deps, {
|
|
67445
68003
|
jobId: route.jobId,
|
|
67446
68004
|
myAgentId,
|
|
@@ -67448,6 +68006,35 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67448
68006
|
groupId: conversationId,
|
|
67449
68007
|
toAgentXmtpAddress: senderAddress || readString5(payloadObject?.fromXmtpAddress)
|
|
67450
68008
|
});
|
|
68009
|
+
if (hasSignalEnvelopePayload(parseResult.data)) {
|
|
68010
|
+
try {
|
|
68011
|
+
const signalPayload = extractSignalEnvelopePayload(parseResult.data);
|
|
68012
|
+
if (!signalPayload) {
|
|
68013
|
+
throw new Error("signal envelope payload is missing");
|
|
68014
|
+
}
|
|
68015
|
+
if (!toAgentId) {
|
|
68016
|
+
throw new Error("signal envelope sender.agentId is missing");
|
|
68017
|
+
}
|
|
68018
|
+
if (!deps.onSignalTradingSignal) {
|
|
68019
|
+
throw new Error("signal buyer runtime is unavailable");
|
|
68020
|
+
}
|
|
68021
|
+
await deps.onSignalTradingSignal({
|
|
68022
|
+
signal: signalPayload.signal,
|
|
68023
|
+
jobId: route.jobId,
|
|
68024
|
+
senderAgentId: toAgentId,
|
|
68025
|
+
messageId: routedMessageId
|
|
68026
|
+
});
|
|
68027
|
+
logWithTimestamp(
|
|
68028
|
+
`[signal-trading] inbound signal handled signal=${signalPayload.signal.signalId} service=${signalPayload.signal.serviceId} job=${shortenLogValue(route.jobId)} message=${shortenLogValue(routedMessageId)}`
|
|
68029
|
+
);
|
|
68030
|
+
} catch (error) {
|
|
68031
|
+
logWithTimestamp(
|
|
68032
|
+
`[signal-trading] inbound signal rejected job=${shortenLogValue(route.jobId)} message=${shortenLogValue(routedMessageId)}:`,
|
|
68033
|
+
error
|
|
68034
|
+
);
|
|
68035
|
+
}
|
|
68036
|
+
return true;
|
|
68037
|
+
}
|
|
67451
68038
|
const dispatchStartedAt = Date.now();
|
|
67452
68039
|
void Promise.resolve(deps.onSessionMessage?.({
|
|
67453
68040
|
sessionKey,
|
|
@@ -67506,7 +68093,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67506
68093
|
return true;
|
|
67507
68094
|
}
|
|
67508
68095
|
const stored = {
|
|
67509
|
-
id: messageId || `local-${(0,
|
|
68096
|
+
id: messageId || `local-${(0, import_node_crypto15.randomUUID)()}`,
|
|
67510
68097
|
direction: "inbound",
|
|
67511
68098
|
route: route.route,
|
|
67512
68099
|
routeReason: route.routeReason,
|
|
@@ -67524,8 +68111,8 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67524
68111
|
await deps.store.append(route.jobId, stored, sessionAgentId);
|
|
67525
68112
|
timing.mark("storeAppend", storeAppendStartedAt);
|
|
67526
68113
|
if ((route.route === "job" || parseResult.ok && !isA2AEnvelope(stored.payload)) && !options.skipNotify) {
|
|
67527
|
-
const payloadObject =
|
|
67528
|
-
const sender =
|
|
68114
|
+
const payloadObject = isPlainObject5(stored.payload) ? stored.payload : null;
|
|
68115
|
+
const sender = isPlainObject5(payloadObject?.sender) ? payloadObject.sender : null;
|
|
67529
68116
|
const localAgent = XmtpService.getInstance().getAgentByAddress(deps.myXmtpAddress);
|
|
67530
68117
|
const sessionKey = route.route === "job" ? buildSessionKey({
|
|
67531
68118
|
jobId: route.jobId,
|
|
@@ -67543,8 +68130,8 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
67543
68130
|
});
|
|
67544
68131
|
}
|
|
67545
68132
|
if (route.route === "job" && chatType === "group" && conversationId && senderAddress) {
|
|
67546
|
-
const payloadObject =
|
|
67547
|
-
const sender =
|
|
68133
|
+
const payloadObject = isPlainObject5(stored.payload) ? stored.payload : null;
|
|
68134
|
+
const sender = isPlainObject5(payloadObject?.sender) ? payloadObject.sender : null;
|
|
67548
68135
|
await deps.store.updateXmtpSession(route.jobId, {
|
|
67549
68136
|
xmtpGroupId: conversationId,
|
|
67550
68137
|
myXmtpAddress: deps.myXmtpAddress,
|
|
@@ -67671,7 +68258,8 @@ function createMiddlewareFromCoreDeps(store, deps, extra) {
|
|
|
67671
68258
|
allowGroup: deps.allowGroup,
|
|
67672
68259
|
onMessageProcessed: deps.onMessageProcessed,
|
|
67673
68260
|
onJobMessageStored: extra?.onJobMessageStored,
|
|
67674
|
-
onSessionMessage: extra?.onSessionMessage
|
|
68261
|
+
onSessionMessage: extra?.onSessionMessage,
|
|
68262
|
+
onSignalTradingSignal: extra?.onSignalTradingSignal
|
|
67675
68263
|
});
|
|
67676
68264
|
}
|
|
67677
68265
|
function processOfflineFromCoreDeps(store, ctx, deps, options) {
|
|
@@ -67681,13 +68269,14 @@ function processOfflineFromCoreDeps(store, ctx, deps, options) {
|
|
|
67681
68269
|
sessionStore: options.sessionStore,
|
|
67682
68270
|
allowGroup: deps.allowGroup,
|
|
67683
68271
|
onJobMessageStored: options.onJobMessageStored,
|
|
67684
|
-
onSessionMessage: options.onSessionMessage
|
|
68272
|
+
onSessionMessage: options.onSessionMessage,
|
|
68273
|
+
onSignalTradingSignal: options.onSignalTradingSignal
|
|
67685
68274
|
}, { ...options, source: "replay" });
|
|
67686
68275
|
}
|
|
67687
68276
|
function buildSystemStoredMessage(params) {
|
|
67688
68277
|
const now = Date.now();
|
|
67689
68278
|
return {
|
|
67690
|
-
id: params.id ?? `system-${now}-${(0,
|
|
68279
|
+
id: params.id ?? `system-${now}-${(0, import_node_crypto15.randomUUID)()}`,
|
|
67691
68280
|
direction: "system",
|
|
67692
68281
|
route: "backup",
|
|
67693
68282
|
routeReason: params.reason,
|
|
@@ -67703,14 +68292,14 @@ function buildSystemStoredMessage(params) {
|
|
|
67703
68292
|
};
|
|
67704
68293
|
}
|
|
67705
68294
|
function isA2AEnvelope(payload) {
|
|
67706
|
-
return
|
|
68295
|
+
return isPlainObject5(payload) && payload.msgType === A2A_MESSAGE_TYPE;
|
|
67707
68296
|
}
|
|
67708
|
-
var
|
|
68297
|
+
var import_node_crypto15, PROCESSED_IDS_MAX, processedMessageIds, INBOUND_TRANSPORT, INBOUND_EVENT_FAMILY, INBOUND_TERMINAL_FIELDS;
|
|
67709
68298
|
var init_message_handler = __esm({
|
|
67710
68299
|
"src/message-handler.ts"() {
|
|
67711
68300
|
"use strict";
|
|
67712
68301
|
init_log();
|
|
67713
|
-
|
|
68302
|
+
import_node_crypto15 = require("node:crypto");
|
|
67714
68303
|
init_dist2();
|
|
67715
68304
|
init_a2a();
|
|
67716
68305
|
init_envelope_shared();
|
|
@@ -67725,6 +68314,7 @@ var init_message_handler = __esm({
|
|
|
67725
68314
|
init_session_store();
|
|
67726
68315
|
init_agent_message_notice();
|
|
67727
68316
|
init_ai_provider();
|
|
68317
|
+
init_protocol();
|
|
67728
68318
|
PROCESSED_IDS_MAX = 1e3;
|
|
67729
68319
|
processedMessageIds = /* @__PURE__ */ new Map();
|
|
67730
68320
|
INBOUND_TRANSPORT = "xmtp";
|
|
@@ -67777,7 +68367,7 @@ function isOriginalParentProcessAlive(options) {
|
|
|
67777
68367
|
}
|
|
67778
68368
|
function registerUserAttentionWatcher(options) {
|
|
67779
68369
|
return options.store.registerUserAttentionWatcher({
|
|
67780
|
-
id: options.id ?? (0,
|
|
68370
|
+
id: options.id ?? (0, import_node_crypto16.randomUUID)(),
|
|
67781
68371
|
provider: options.provider,
|
|
67782
68372
|
jobId: options.jobId,
|
|
67783
68373
|
nowMs: options.nowMs ?? Date.now(),
|
|
@@ -67856,11 +68446,11 @@ function userWatchEventDeliveredSentryExtra(event) {
|
|
|
67856
68446
|
hasDecision: String(event.hasDecision)
|
|
67857
68447
|
};
|
|
67858
68448
|
}
|
|
67859
|
-
var
|
|
68449
|
+
var import_node_crypto16, USER_ATTENTION_WATCH_REPLACED_MESSAGE, USER_ATTENTION_WATCHER_SCAN_MS, USER_ATTENTION_WATCHER_TTL_MS, USER_ATTENTION_WATCH_PARENT_CHECK_MS;
|
|
67860
68450
|
var init_user_attention_watchers = __esm({
|
|
67861
68451
|
"src/user-attention-watchers.ts"() {
|
|
67862
68452
|
"use strict";
|
|
67863
|
-
|
|
68453
|
+
import_node_crypto16 = require("node:crypto");
|
|
67864
68454
|
init_sentry_logger();
|
|
67865
68455
|
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.";
|
|
67866
68456
|
USER_ATTENTION_WATCHER_SCAN_MS = 500;
|
|
@@ -67869,6 +68459,639 @@ var init_user_attention_watchers = __esm({
|
|
|
67869
68459
|
}
|
|
67870
68460
|
});
|
|
67871
68461
|
|
|
68462
|
+
// src/signal-trading/execution.ts
|
|
68463
|
+
function defaultPolymarketCommandRunner(bin, args, options) {
|
|
68464
|
+
return execFileAsync3(bin, args, {
|
|
68465
|
+
windowsHide: true,
|
|
68466
|
+
timeout: options.timeoutMs,
|
|
68467
|
+
maxBuffer: MAX_POLYMARKET_OUTPUT_BYTES
|
|
68468
|
+
});
|
|
68469
|
+
}
|
|
68470
|
+
async function defaultPolymarketEventFetcher(slug, options) {
|
|
68471
|
+
const response = await fetch(
|
|
68472
|
+
`https://gamma-api.polymarket.com/events/slug/${encodeURIComponent(slug)}`,
|
|
68473
|
+
{ signal: AbortSignal.timeout(options.timeoutMs) }
|
|
68474
|
+
);
|
|
68475
|
+
if (!response.ok) {
|
|
68476
|
+
throw new Error(`Gamma API returned HTTP ${response.status}`);
|
|
68477
|
+
}
|
|
68478
|
+
return response.json();
|
|
68479
|
+
}
|
|
68480
|
+
function normalizeDecimal(value, path2) {
|
|
68481
|
+
const trimmed = value.trim();
|
|
68482
|
+
const match = /^(?:0|[1-9]\d*)(?:\.(\d+))?$/.exec(trimmed);
|
|
68483
|
+
if (!match || /^0(?:\.0+)?$/.test(trimmed)) {
|
|
68484
|
+
throw new Error(`${path2} must be a positive decimal string`);
|
|
68485
|
+
}
|
|
68486
|
+
const fraction = match[1] ?? "";
|
|
68487
|
+
return {
|
|
68488
|
+
digits: BigInt(trimmed.replace(".", "")),
|
|
68489
|
+
scale: fraction.length
|
|
68490
|
+
};
|
|
68491
|
+
}
|
|
68492
|
+
function comparePositiveDecimals(left, right) {
|
|
68493
|
+
const a = normalizeDecimal(left, "left decimal");
|
|
68494
|
+
const b = normalizeDecimal(right, "right decimal");
|
|
68495
|
+
const scale = Math.max(a.scale, b.scale);
|
|
68496
|
+
const aScaled = a.digits * 10n ** BigInt(scale - a.scale);
|
|
68497
|
+
const bScaled = b.digits * 10n ** BigInt(scale - b.scale);
|
|
68498
|
+
return aScaled < bScaled ? -1 : aScaled > bScaled ? 1 : 0;
|
|
68499
|
+
}
|
|
68500
|
+
function formatDecimal(digits, scale) {
|
|
68501
|
+
const raw = digits.toString().padStart(scale + 1, "0");
|
|
68502
|
+
if (scale === 0) {
|
|
68503
|
+
return raw;
|
|
68504
|
+
}
|
|
68505
|
+
const integer = raw.slice(0, -scale);
|
|
68506
|
+
const fraction = raw.slice(-scale).replace(/0+$/, "");
|
|
68507
|
+
return fraction ? `${integer}.${fraction}` : integer;
|
|
68508
|
+
}
|
|
68509
|
+
function adjustPriceByBps(value, bps, side) {
|
|
68510
|
+
const parsed = normalizeDecimal(value, "Polymarket reference price");
|
|
68511
|
+
const scale = Math.max(parsed.scale, 6);
|
|
68512
|
+
const scaled = parsed.digits * 10n ** BigInt(scale - parsed.scale);
|
|
68513
|
+
const factor = BigInt(side === "buy" ? 1e4 + bps : 1e4 - bps);
|
|
68514
|
+
const product = scaled * factor;
|
|
68515
|
+
const quotient = product / 10000n;
|
|
68516
|
+
const adjusted = side === "buy" && product % 10000n !== 0n ? quotient + 1n : quotient;
|
|
68517
|
+
if (adjusted <= 0n) {
|
|
68518
|
+
throw new Error("calculated Polymarket limit price must be positive");
|
|
68519
|
+
}
|
|
68520
|
+
return formatDecimal(adjusted, scale);
|
|
68521
|
+
}
|
|
68522
|
+
function divideDecimal(left, right, outputScale = 6) {
|
|
68523
|
+
const numerator = normalizeDecimal(left, "Polymarket BUY amount");
|
|
68524
|
+
const denominator = normalizeDecimal(right, "Polymarket BUY limit price");
|
|
68525
|
+
const scaledNumerator = numerator.digits * 10n ** BigInt(denominator.scale + outputScale);
|
|
68526
|
+
const scaledDenominator = denominator.digits * 10n ** BigInt(numerator.scale);
|
|
68527
|
+
const quotient = scaledNumerator / scaledDenominator;
|
|
68528
|
+
if (quotient <= 0n) {
|
|
68529
|
+
throw new Error("calculated Polymarket order size must be positive");
|
|
68530
|
+
}
|
|
68531
|
+
return formatDecimal(quotient, outputScale);
|
|
68532
|
+
}
|
|
68533
|
+
function minDecimal(left, right) {
|
|
68534
|
+
return comparePositiveDecimals(left, right) <= 0 ? left : right;
|
|
68535
|
+
}
|
|
68536
|
+
function maxDecimal(left, right) {
|
|
68537
|
+
return comparePositiveDecimals(left, right) >= 0 ? left : right;
|
|
68538
|
+
}
|
|
68539
|
+
function alignPriceToTick(value, tickSize, side) {
|
|
68540
|
+
const price = normalizeDecimal(value, "Polymarket limit price");
|
|
68541
|
+
const tick = normalizeDecimal(tickSize, "Polymarket tick size");
|
|
68542
|
+
const scale = Math.max(price.scale, tick.scale);
|
|
68543
|
+
const scaledPrice = price.digits * 10n ** BigInt(scale - price.scale);
|
|
68544
|
+
const scaledTick = tick.digits * 10n ** BigInt(scale - tick.scale);
|
|
68545
|
+
const quotient = scaledPrice / scaledTick;
|
|
68546
|
+
const alignedTicks = side === "sell" && scaledPrice % scaledTick !== 0n ? quotient + 1n : quotient;
|
|
68547
|
+
const aligned = alignedTicks * scaledTick;
|
|
68548
|
+
if (aligned <= 0n) {
|
|
68549
|
+
throw new Error("calculated Polymarket tick-aligned limit price must be positive");
|
|
68550
|
+
}
|
|
68551
|
+
return formatDecimal(aligned, scale);
|
|
68552
|
+
}
|
|
68553
|
+
function requireBuyerSubscription(buyer, signal, context) {
|
|
68554
|
+
const subscription = buyer.subscriptions.find((candidate) => {
|
|
68555
|
+
return candidate.serviceId === signal.serviceId && candidate.subscriptionId === signal.subscriptionId && candidate.jobId === context.jobId && candidate.providerAgentId === signal.providerAgentId;
|
|
68556
|
+
});
|
|
68557
|
+
if (!subscription) {
|
|
68558
|
+
throw new Error(
|
|
68559
|
+
`signal subscription is not configured for serviceId=${signal.serviceId} subscriptionId=${signal.subscriptionId} jobId=${context.jobId}`
|
|
68560
|
+
);
|
|
68561
|
+
}
|
|
68562
|
+
if (context.senderAgentId !== signal.providerAgentId) {
|
|
68563
|
+
throw new Error(
|
|
68564
|
+
`signal providerAgentId=${signal.providerAgentId} does not match verified senderAgentId=${context.senderAgentId}`
|
|
68565
|
+
);
|
|
68566
|
+
}
|
|
68567
|
+
}
|
|
68568
|
+
function buildPolymarketExecutionPlan(signalValue, buyer, context, market, nowMs = Date.now()) {
|
|
68569
|
+
const signal = parseTradingSignalV1(signalValue);
|
|
68570
|
+
validateSignalPreconditions(signal, buyer, context, nowMs);
|
|
68571
|
+
if (signal.intent.action !== "ENTER" && signal.intent.action !== "EXIT") {
|
|
68572
|
+
throw new Error(`Polymarket demo does not execute ${signal.intent.action} signals`);
|
|
68573
|
+
}
|
|
68574
|
+
if (!signal.sizing) {
|
|
68575
|
+
throw new Error(`signal.sizing is required for ${signal.intent.action} signals`);
|
|
68576
|
+
}
|
|
68577
|
+
if (signal.intent.orderType !== "MARKET") {
|
|
68578
|
+
throw new Error("Polymarket demo accepts MARKET intents only");
|
|
68579
|
+
}
|
|
68580
|
+
if (!buyer.riskPolicy.allowedSides.includes(signal.intent.side)) {
|
|
68581
|
+
throw new Error(`signal side ${signal.intent.side} is not allowed by risk policy`);
|
|
68582
|
+
}
|
|
68583
|
+
const expectedSizing = signal.intent.side === "BUY" ? "FIXED_QUOTE" : "FIXED_BASE";
|
|
68584
|
+
if (signal.sizing.type !== expectedSizing) {
|
|
68585
|
+
throw new Error(`${signal.intent.side} market orders require sizing.type=${expectedSizing}`);
|
|
68586
|
+
}
|
|
68587
|
+
normalizeDecimal(signal.sizing.value, "signal.sizing.value");
|
|
68588
|
+
const side = signal.intent.side.toLowerCase();
|
|
68589
|
+
const minimumAmount = side === "buy" ? buyer.riskPolicy.minBuyUsdc ?? buyer.riskPolicy.minOrderAmount : buyer.riskPolicy.minSellShares ?? buyer.riskPolicy.minOrderAmount;
|
|
68590
|
+
const maximumAmount = side === "buy" ? buyer.riskPolicy.maxBuyUsdc ?? buyer.riskPolicy.maxOrderAmount : buyer.riskPolicy.maxSellShares ?? buyer.riskPolicy.maxOrderAmount;
|
|
68591
|
+
if (!maximumAmount) {
|
|
68592
|
+
throw new Error(
|
|
68593
|
+
side === "buy" ? "config.buyer.riskPolicy.maxBuyUsdc is required for BUY" : "config.buyer.riskPolicy.maxSellShares is required for SELL"
|
|
68594
|
+
);
|
|
68595
|
+
}
|
|
68596
|
+
if (minimumAmount && comparePositiveDecimals(signal.sizing.value, minimumAmount) < 0) {
|
|
68597
|
+
throw new Error(
|
|
68598
|
+
`signal amount ${signal.sizing.value} is below ${side} risk minimum ${minimumAmount}`
|
|
68599
|
+
);
|
|
68600
|
+
}
|
|
68601
|
+
if (comparePositiveDecimals(signal.sizing.value, maximumAmount) > 0) {
|
|
68602
|
+
throw new Error(
|
|
68603
|
+
`signal amount ${signal.sizing.value} exceeds ${side} risk maximum ${maximumAmount}`
|
|
68604
|
+
);
|
|
68605
|
+
}
|
|
68606
|
+
if (signal.constraints?.maxSlippageBps !== void 0 && signal.constraints.maxSlippageBps > buyer.riskPolicy.maxSlippageBps) {
|
|
68607
|
+
throw new Error(
|
|
68608
|
+
`signal maxSlippageBps ${signal.constraints.maxSlippageBps} exceeds risk policy ${buyer.riskPolicy.maxSlippageBps}`
|
|
68609
|
+
);
|
|
68610
|
+
}
|
|
68611
|
+
if (buyer.riskPolicy.maxSlippageBps > 1e4) {
|
|
68612
|
+
throw new Error("config.buyer.riskPolicy.maxSlippageBps must be <= 10000");
|
|
68613
|
+
}
|
|
68614
|
+
const tokenId = signal.metadata?.polymarketTokenId ?? signal.instrument.symbol;
|
|
68615
|
+
if (!buyer.riskPolicy.allowedTokenIds.includes(tokenId)) {
|
|
68616
|
+
throw new Error(`Polymarket token ${tokenId} is not allowlisted`);
|
|
68617
|
+
}
|
|
68618
|
+
normalizeDecimal(market.referencePrice, "Polymarket reference price");
|
|
68619
|
+
if (comparePositiveDecimals(market.referencePrice, "1") > 0) {
|
|
68620
|
+
throw new Error("Polymarket reference price must be <= 1");
|
|
68621
|
+
}
|
|
68622
|
+
const slippageBps = signal.constraints?.maxSlippageBps ?? buyer.riskPolicy.maxSlippageBps;
|
|
68623
|
+
const slippageLimit = adjustPriceByBps(market.referencePrice, slippageBps, side);
|
|
68624
|
+
let limitPrice;
|
|
68625
|
+
if (side === "buy") {
|
|
68626
|
+
const maxBuyPrice = buyer.riskPolicy.maxBuyPrice;
|
|
68627
|
+
if (!maxBuyPrice) {
|
|
68628
|
+
throw new Error("config.buyer.riskPolicy.maxBuyPrice is required for BUY");
|
|
68629
|
+
}
|
|
68630
|
+
if (comparePositiveDecimals(market.referencePrice, maxBuyPrice) > 0) {
|
|
68631
|
+
throw new Error(
|
|
68632
|
+
`Polymarket BUY reference price ${market.referencePrice} exceeds maxBuyPrice ${maxBuyPrice}`
|
|
68633
|
+
);
|
|
68634
|
+
}
|
|
68635
|
+
limitPrice = alignPriceToTick(minDecimal(slippageLimit, maxBuyPrice), market.tickSize, side);
|
|
68636
|
+
} else {
|
|
68637
|
+
const minSellPrice = buyer.riskPolicy.minSellPrice;
|
|
68638
|
+
if (!minSellPrice) {
|
|
68639
|
+
throw new Error("config.buyer.riskPolicy.minSellPrice is required for SELL");
|
|
68640
|
+
}
|
|
68641
|
+
if (comparePositiveDecimals(market.referencePrice, minSellPrice) < 0) {
|
|
68642
|
+
throw new Error(
|
|
68643
|
+
`Polymarket SELL reference price ${market.referencePrice} is below minSellPrice ${minSellPrice}`
|
|
68644
|
+
);
|
|
68645
|
+
}
|
|
68646
|
+
limitPrice = alignPriceToTick(maxDecimal(slippageLimit, minSellPrice), market.tickSize, side);
|
|
68647
|
+
}
|
|
68648
|
+
const size3 = side === "buy" ? divideDecimal(signal.sizing.value, limitPrice) : signal.sizing.value;
|
|
68649
|
+
if (comparePositiveDecimals(limitPrice, "1") > 0) {
|
|
68650
|
+
throw new Error("calculated Polymarket limit price must be <= 1");
|
|
68651
|
+
}
|
|
68652
|
+
const minOrderSize = market.minOrderSize ?? buyer.riskPolicy.minOrderShares;
|
|
68653
|
+
if (minOrderSize && comparePositiveDecimals(size3, minOrderSize) < 0) {
|
|
68654
|
+
throw new Error(
|
|
68655
|
+
`calculated Polymarket order size ${size3} is below market minimum ${minOrderSize}`
|
|
68656
|
+
);
|
|
68657
|
+
}
|
|
68658
|
+
return {
|
|
68659
|
+
bin: buyer.polymarket?.bin ?? process.env.POLYMARKET_BIN ?? "polymarket",
|
|
68660
|
+
args: [
|
|
68661
|
+
"-o",
|
|
68662
|
+
"json",
|
|
68663
|
+
"clob",
|
|
68664
|
+
"create-order",
|
|
68665
|
+
"--token",
|
|
68666
|
+
tokenId,
|
|
68667
|
+
"--side",
|
|
68668
|
+
side,
|
|
68669
|
+
"--price",
|
|
68670
|
+
limitPrice,
|
|
68671
|
+
"--size",
|
|
68672
|
+
size3,
|
|
68673
|
+
"--order-type",
|
|
68674
|
+
"FOK"
|
|
68675
|
+
],
|
|
68676
|
+
tokenId,
|
|
68677
|
+
side,
|
|
68678
|
+
amount: signal.sizing.value,
|
|
68679
|
+
referencePrice: market.referencePrice,
|
|
68680
|
+
limitPrice,
|
|
68681
|
+
size: size3
|
|
68682
|
+
};
|
|
68683
|
+
}
|
|
68684
|
+
function validateSignalPreconditions(signal, buyer, context, nowMs) {
|
|
68685
|
+
if (!buyer.enabled) {
|
|
68686
|
+
throw new Error("signal buyer runtime is disabled");
|
|
68687
|
+
}
|
|
68688
|
+
requireBuyerSubscription(buyer, signal, context);
|
|
68689
|
+
const emittedAtMs = Date.parse(signal.emittedAt);
|
|
68690
|
+
const expiresAtMs = Date.parse(signal.expiresAt);
|
|
68691
|
+
if (expiresAtMs <= nowMs) {
|
|
68692
|
+
throw new Error(`signal ${signal.signalId} is expired`);
|
|
68693
|
+
}
|
|
68694
|
+
if (buyer.riskPolicy.minTimeToExpiryMs !== void 0 && expiresAtMs - nowMs < buyer.riskPolicy.minTimeToExpiryMs) {
|
|
68695
|
+
throw new Error(
|
|
68696
|
+
`signal ${signal.signalId} expires too soon for minTimeToExpiryMs=${buyer.riskPolicy.minTimeToExpiryMs}`
|
|
68697
|
+
);
|
|
68698
|
+
}
|
|
68699
|
+
if (emittedAtMs > nowMs + MAX_FUTURE_CLOCK_SKEW_MS) {
|
|
68700
|
+
throw new Error(`signal ${signal.signalId} emittedAt is too far in the future`);
|
|
68701
|
+
}
|
|
68702
|
+
if (nowMs - emittedAtMs > buyer.riskPolicy.maxSignalAgeMs) {
|
|
68703
|
+
throw new Error(`signal ${signal.signalId} exceeds maxSignalAgeMs`);
|
|
68704
|
+
}
|
|
68705
|
+
if (signal.instrument.marketType !== "ONCHAIN") {
|
|
68706
|
+
throw new Error("Polymarket execution requires instrument.marketType=ONCHAIN");
|
|
68707
|
+
}
|
|
68708
|
+
if (signal.metadata?.venue?.toLowerCase() !== "polymarket") {
|
|
68709
|
+
throw new Error("signal.metadata.venue must be polymarket");
|
|
68710
|
+
}
|
|
68711
|
+
}
|
|
68712
|
+
function receiptPath(homeDir, idempotencyKey) {
|
|
68713
|
+
const digest = (0, import_node_crypto17.createHash)("sha256").update(idempotencyKey).digest("hex");
|
|
68714
|
+
return (0, import_node_path31.join)(resolveSignalTradingDir(homeDir), "executions", `${digest}.json`);
|
|
68715
|
+
}
|
|
68716
|
+
function readReceipt(path2) {
|
|
68717
|
+
if (!(0, import_node_fs26.existsSync)(path2)) {
|
|
68718
|
+
return null;
|
|
68719
|
+
}
|
|
68720
|
+
try {
|
|
68721
|
+
return JSON.parse((0, import_node_fs26.readFileSync)(path2, "utf8"));
|
|
68722
|
+
} catch {
|
|
68723
|
+
return null;
|
|
68724
|
+
}
|
|
68725
|
+
}
|
|
68726
|
+
function claimReceipt(path2, receipt) {
|
|
68727
|
+
(0, import_node_fs26.mkdirSync)((0, import_node_path31.join)(path2, ".."), { recursive: true });
|
|
68728
|
+
let fd;
|
|
68729
|
+
try {
|
|
68730
|
+
fd = (0, import_node_fs26.openSync)(path2, "wx", 384);
|
|
68731
|
+
} catch (error) {
|
|
68732
|
+
if (error.code === "EEXIST") {
|
|
68733
|
+
return false;
|
|
68734
|
+
}
|
|
68735
|
+
throw error;
|
|
68736
|
+
}
|
|
68737
|
+
try {
|
|
68738
|
+
(0, import_node_fs26.writeSync)(fd, JSON.stringify(receipt, null, 2));
|
|
68739
|
+
} finally {
|
|
68740
|
+
(0, import_node_fs26.closeSync)(fd);
|
|
68741
|
+
}
|
|
68742
|
+
return true;
|
|
68743
|
+
}
|
|
68744
|
+
function updateReceipt(path2, receipt) {
|
|
68745
|
+
const temporaryPath = `${path2}.${process.pid}.${(0, import_node_crypto17.randomUUID)()}.tmp`;
|
|
68746
|
+
(0, import_node_fs26.writeFileSync)(temporaryPath, JSON.stringify(receipt, null, 2), { mode: 384 });
|
|
68747
|
+
(0, import_node_fs26.renameSync)(temporaryPath, path2);
|
|
68748
|
+
}
|
|
68749
|
+
function boundedOutput(value) {
|
|
68750
|
+
if (typeof value !== "string" || value.length === 0) {
|
|
68751
|
+
return void 0;
|
|
68752
|
+
}
|
|
68753
|
+
return value.slice(0, MAX_RECEIPT_OUTPUT_CHARS);
|
|
68754
|
+
}
|
|
68755
|
+
function parsePolymarketStringArray(value, path2) {
|
|
68756
|
+
let parsed = value;
|
|
68757
|
+
if (typeof parsed === "string") {
|
|
68758
|
+
try {
|
|
68759
|
+
parsed = JSON.parse(parsed);
|
|
68760
|
+
} catch (error) {
|
|
68761
|
+
throw new Error(
|
|
68762
|
+
`${path2} is not valid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
68763
|
+
);
|
|
68764
|
+
}
|
|
68765
|
+
}
|
|
68766
|
+
if (!Array.isArray(parsed) || parsed.some((item) => typeof item !== "string")) {
|
|
68767
|
+
throw new Error(`${path2} must be an array of strings`);
|
|
68768
|
+
}
|
|
68769
|
+
return parsed;
|
|
68770
|
+
}
|
|
68771
|
+
function asRecord(value) {
|
|
68772
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
68773
|
+
}
|
|
68774
|
+
async function authorizeRotatingPolymarketToken(signal, buyer, runner, eventFetcher) {
|
|
68775
|
+
const tokenId = signal.metadata?.polymarketTokenId ?? signal.instrument.symbol;
|
|
68776
|
+
if (buyer.riskPolicy.allowedTokenIds.includes(tokenId)) {
|
|
68777
|
+
return { buyer };
|
|
68778
|
+
}
|
|
68779
|
+
const marketSlug = signal.metadata?.market;
|
|
68780
|
+
const outcome = signal.metadata?.outcome;
|
|
68781
|
+
if (!marketSlug || !outcome) {
|
|
68782
|
+
throw new Error(`Polymarket token ${tokenId} is not allowlisted`);
|
|
68783
|
+
}
|
|
68784
|
+
const allowedSeries = buyer.riskPolicy.allowedMarketSeries?.find((series) => {
|
|
68785
|
+
return marketSlug.startsWith(series.slugPrefix) && series.outcomes.some((allowed) => allowed.toLowerCase() === outcome.toLowerCase());
|
|
68786
|
+
});
|
|
68787
|
+
if (!allowedSeries) {
|
|
68788
|
+
throw new Error(`Polymarket token ${tokenId} is not allowlisted`);
|
|
68789
|
+
}
|
|
68790
|
+
const bin = buyer.polymarket?.bin ?? process.env.POLYMARKET_BIN ?? "polymarket";
|
|
68791
|
+
const timeoutMs = buyer.polymarket?.timeoutMs ?? DEFAULT_POLYMARKET_TIMEOUT_MS;
|
|
68792
|
+
let eventValue;
|
|
68793
|
+
let cliError;
|
|
68794
|
+
try {
|
|
68795
|
+
const result = await runner(bin, ["-o", "json", "events", "get", marketSlug], { timeoutMs });
|
|
68796
|
+
eventValue = JSON.parse(result.stdout);
|
|
68797
|
+
const record = asRecord(eventValue);
|
|
68798
|
+
if (record?.error) {
|
|
68799
|
+
throw new Error(String(record.error));
|
|
68800
|
+
}
|
|
68801
|
+
} catch (error) {
|
|
68802
|
+
eventValue = void 0;
|
|
68803
|
+
cliError = error instanceof Error ? error.message : String(error);
|
|
68804
|
+
}
|
|
68805
|
+
if (eventValue === void 0) {
|
|
68806
|
+
try {
|
|
68807
|
+
eventValue = await eventFetcher(marketSlug, { timeoutMs });
|
|
68808
|
+
} catch (error) {
|
|
68809
|
+
throw new Error(
|
|
68810
|
+
`failed to verify rotating Polymarket event ${marketSlug}: CLI=${cliError}; Gamma=${error instanceof Error ? error.message : String(error)}`
|
|
68811
|
+
);
|
|
68812
|
+
}
|
|
68813
|
+
}
|
|
68814
|
+
const event = asRecord(eventValue);
|
|
68815
|
+
if (!event || event.error || event.slug !== marketSlug || event.active !== true || event.closed === true) {
|
|
68816
|
+
throw new Error(`Polymarket event ${marketSlug} is not active`);
|
|
68817
|
+
}
|
|
68818
|
+
if (allowedSeries.seriesSlug && event.seriesSlug !== allowedSeries.seriesSlug) {
|
|
68819
|
+
throw new Error(
|
|
68820
|
+
`Polymarket event ${marketSlug} does not belong to series ${allowedSeries.seriesSlug}`
|
|
68821
|
+
);
|
|
68822
|
+
}
|
|
68823
|
+
const markets = Array.isArray(event.markets) ? event.markets : [];
|
|
68824
|
+
let verifiedMinOrderSize;
|
|
68825
|
+
let verifiedTickSize;
|
|
68826
|
+
let verificationFailure;
|
|
68827
|
+
const tokenVerified = markets.some((marketValue) => {
|
|
68828
|
+
const market = asRecord(marketValue);
|
|
68829
|
+
if (market?.active !== true || market.closed === true) {
|
|
68830
|
+
return false;
|
|
68831
|
+
}
|
|
68832
|
+
if ((market.acceptingOrders ?? market.accepting_orders) !== true) {
|
|
68833
|
+
return false;
|
|
68834
|
+
}
|
|
68835
|
+
if (allowedSeries.cryptoMarketConfigId && market.cryptoMarketConfigId !== allowedSeries.cryptoMarketConfigId) {
|
|
68836
|
+
return false;
|
|
68837
|
+
}
|
|
68838
|
+
const outcomes = parsePolymarketStringArray(market.outcomes, "market.outcomes");
|
|
68839
|
+
const tokenIds = parsePolymarketStringArray(
|
|
68840
|
+
market.clobTokenIds ?? market.clob_token_ids,
|
|
68841
|
+
"market.clobTokenIds"
|
|
68842
|
+
);
|
|
68843
|
+
if (outcomes.length !== tokenIds.length) {
|
|
68844
|
+
throw new Error("market outcomes and CLOB token IDs have different lengths");
|
|
68845
|
+
}
|
|
68846
|
+
const outcomeIndex = outcomes.findIndex((candidateOutcome, index2) => {
|
|
68847
|
+
return candidateOutcome.toLowerCase() === outcome.toLowerCase() && tokenIds[index2] === tokenId;
|
|
68848
|
+
});
|
|
68849
|
+
if (outcomeIndex < 0) {
|
|
68850
|
+
return false;
|
|
68851
|
+
}
|
|
68852
|
+
const endValue = market.endDate ?? market.end_date ?? event.endDate ?? event.end_date;
|
|
68853
|
+
const endMs = typeof endValue === "string" ? Date.parse(endValue) : Number.NaN;
|
|
68854
|
+
const closeSafetyMs = buyer.riskPolicy.minEventTimeToCloseMs ?? buyer.riskPolicy.minTimeToExpiryMs ?? 0;
|
|
68855
|
+
if (!Number.isFinite(endMs) || endMs - Date.now() < closeSafetyMs) {
|
|
68856
|
+
verificationFailure = `event closes within minEventTimeToCloseMs=${closeSafetyMs}`;
|
|
68857
|
+
return false;
|
|
68858
|
+
}
|
|
68859
|
+
if (Date.parse(signal.expiresAt) > endMs - closeSafetyMs) {
|
|
68860
|
+
verificationFailure = "signal expiresAt exceeds the independently verified event close margin";
|
|
68861
|
+
return false;
|
|
68862
|
+
}
|
|
68863
|
+
const minOrderSize = market.orderMinSize ?? market.order_min_size;
|
|
68864
|
+
if (typeof minOrderSize === "number" || typeof minOrderSize === "string") {
|
|
68865
|
+
verifiedMinOrderSize = String(minOrderSize);
|
|
68866
|
+
}
|
|
68867
|
+
const tickSize = market.orderPriceMinTickSize ?? market.order_price_min_tick_size;
|
|
68868
|
+
if (typeof tickSize === "number" || typeof tickSize === "string") {
|
|
68869
|
+
verifiedTickSize = String(tickSize);
|
|
68870
|
+
}
|
|
68871
|
+
return true;
|
|
68872
|
+
});
|
|
68873
|
+
if (!tokenVerified) {
|
|
68874
|
+
if (verificationFailure) {
|
|
68875
|
+
throw new Error(`Polymarket event ${marketSlug} is unsafe: ${verificationFailure}`);
|
|
68876
|
+
}
|
|
68877
|
+
throw new Error(
|
|
68878
|
+
`Polymarket token ${tokenId} does not match outcome ${outcome} in active event ${marketSlug}`
|
|
68879
|
+
);
|
|
68880
|
+
}
|
|
68881
|
+
return {
|
|
68882
|
+
buyer: {
|
|
68883
|
+
...buyer,
|
|
68884
|
+
riskPolicy: {
|
|
68885
|
+
...buyer.riskPolicy,
|
|
68886
|
+
allowedTokenIds: [...buyer.riskPolicy.allowedTokenIds, tokenId]
|
|
68887
|
+
}
|
|
68888
|
+
},
|
|
68889
|
+
...verifiedMinOrderSize ? { minOrderSize: verifiedMinOrderSize } : {},
|
|
68890
|
+
...verifiedTickSize ? { tickSize: verifiedTickSize } : {}
|
|
68891
|
+
};
|
|
68892
|
+
}
|
|
68893
|
+
async function queryPolymarketMarketSnapshot(signal, buyer, runner, knownTickSize) {
|
|
68894
|
+
if (signal.intent.action !== "ENTER" && signal.intent.action !== "EXIT") {
|
|
68895
|
+
throw new Error(`cannot query a price for ${signal.intent.action}`);
|
|
68896
|
+
}
|
|
68897
|
+
const tokenId = signal.metadata?.polymarketTokenId ?? signal.instrument.symbol;
|
|
68898
|
+
const side = signal.intent.side.toLowerCase();
|
|
68899
|
+
const bin = buyer.polymarket?.bin ?? process.env.POLYMARKET_BIN ?? "polymarket";
|
|
68900
|
+
const result = await runner(bin, ["-o", "json", "clob", "price", "--side", side, tokenId], {
|
|
68901
|
+
timeoutMs: buyer.polymarket?.timeoutMs ?? DEFAULT_POLYMARKET_TIMEOUT_MS
|
|
68902
|
+
});
|
|
68903
|
+
let value;
|
|
68904
|
+
try {
|
|
68905
|
+
value = JSON.parse(result.stdout);
|
|
68906
|
+
} catch (error) {
|
|
68907
|
+
throw new Error(
|
|
68908
|
+
`Polymarket price query returned invalid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
68909
|
+
);
|
|
68910
|
+
}
|
|
68911
|
+
const record = asRecord(value);
|
|
68912
|
+
const price = typeof record?.price === "string" || typeof record?.price === "number" ? String(record.price) : typeof value === "string" || typeof value === "number" ? String(value) : void 0;
|
|
68913
|
+
if (!price) {
|
|
68914
|
+
throw new Error("Polymarket price query did not return a price");
|
|
68915
|
+
}
|
|
68916
|
+
normalizeDecimal(price, "Polymarket reference price");
|
|
68917
|
+
let tickSize = knownTickSize;
|
|
68918
|
+
if (!tickSize) {
|
|
68919
|
+
const tickResult = await runner(bin, ["-o", "json", "clob", "tick-size", tokenId], {
|
|
68920
|
+
timeoutMs: buyer.polymarket?.timeoutMs ?? DEFAULT_POLYMARKET_TIMEOUT_MS
|
|
68921
|
+
});
|
|
68922
|
+
let tickValue;
|
|
68923
|
+
try {
|
|
68924
|
+
tickValue = JSON.parse(tickResult.stdout);
|
|
68925
|
+
} catch (error) {
|
|
68926
|
+
throw new Error(
|
|
68927
|
+
`Polymarket tick-size query returned invalid JSON: ${error instanceof Error ? error.message : String(error)}`
|
|
68928
|
+
);
|
|
68929
|
+
}
|
|
68930
|
+
const tickRecord = asRecord(tickValue);
|
|
68931
|
+
const candidate = tickRecord?.tickSize ?? tickRecord?.tick_size ?? tickRecord?.minimumTickSize ?? tickRecord?.minimum_tick_size;
|
|
68932
|
+
tickSize = typeof candidate === "string" || typeof candidate === "number" ? String(candidate) : typeof tickValue === "string" || typeof tickValue === "number" ? String(tickValue) : void 0;
|
|
68933
|
+
}
|
|
68934
|
+
if (!tickSize) {
|
|
68935
|
+
throw new Error("Polymarket tick-size query did not return a tick size");
|
|
68936
|
+
}
|
|
68937
|
+
normalizeDecimal(tickSize, "Polymarket tick size");
|
|
68938
|
+
return { referencePrice: price, tickSize };
|
|
68939
|
+
}
|
|
68940
|
+
var import_node_child_process9, import_node_crypto17, import_node_fs26, import_node_path31, import_node_util3, execFileAsync3, DEFAULT_POLYMARKET_TIMEOUT_MS, MAX_POLYMARKET_OUTPUT_BYTES, MAX_RECEIPT_OUTPUT_CHARS, MAX_FUTURE_CLOCK_SKEW_MS, SignalTradingBuyerRuntime;
|
|
68941
|
+
var init_execution = __esm({
|
|
68942
|
+
"src/signal-trading/execution.ts"() {
|
|
68943
|
+
"use strict";
|
|
68944
|
+
import_node_child_process9 = require("node:child_process");
|
|
68945
|
+
import_node_crypto17 = require("node:crypto");
|
|
68946
|
+
import_node_fs26 = require("node:fs");
|
|
68947
|
+
import_node_path31 = require("node:path");
|
|
68948
|
+
import_node_util3 = require("node:util");
|
|
68949
|
+
init_log();
|
|
68950
|
+
init_config();
|
|
68951
|
+
init_protocol();
|
|
68952
|
+
execFileAsync3 = (0, import_node_util3.promisify)(import_node_child_process9.execFile);
|
|
68953
|
+
DEFAULT_POLYMARKET_TIMEOUT_MS = 3e4;
|
|
68954
|
+
MAX_POLYMARKET_OUTPUT_BYTES = 1048576;
|
|
68955
|
+
MAX_RECEIPT_OUTPUT_CHARS = 16384;
|
|
68956
|
+
MAX_FUTURE_CLOCK_SKEW_MS = 3e4;
|
|
68957
|
+
SignalTradingBuyerRuntime = class {
|
|
68958
|
+
constructor(homeDir, runner = defaultPolymarketCommandRunner, eventFetcher = defaultPolymarketEventFetcher) {
|
|
68959
|
+
this.homeDir = homeDir;
|
|
68960
|
+
this.runner = runner;
|
|
68961
|
+
this.eventFetcher = eventFetcher;
|
|
68962
|
+
}
|
|
68963
|
+
homeDir;
|
|
68964
|
+
runner;
|
|
68965
|
+
eventFetcher;
|
|
68966
|
+
async process(signalValue, context) {
|
|
68967
|
+
const config = loadSignalTradingConfig(this.homeDir);
|
|
68968
|
+
if (!config.buyer) {
|
|
68969
|
+
throw new Error("signal buyer config is missing");
|
|
68970
|
+
}
|
|
68971
|
+
const signal = parseTradingSignalV1(signalValue);
|
|
68972
|
+
const idempotencyKey = `${signal.providerAgentId}:${signal.subscriptionId}:${signal.signalId}`;
|
|
68973
|
+
const path2 = receiptPath(this.homeDir, idempotencyKey);
|
|
68974
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
68975
|
+
if (signal.intent.action === "NO_TRADE") {
|
|
68976
|
+
validateSignalPreconditions(signal, config.buyer, context, Date.now());
|
|
68977
|
+
const receipt = {
|
|
68978
|
+
idempotencyKey,
|
|
68979
|
+
signalId: signal.signalId,
|
|
68980
|
+
serviceId: signal.serviceId,
|
|
68981
|
+
subscriptionId: signal.subscriptionId,
|
|
68982
|
+
providerAgentId: signal.providerAgentId,
|
|
68983
|
+
jobId: context.jobId,
|
|
68984
|
+
messageId: context.messageId,
|
|
68985
|
+
status: "SKIPPED",
|
|
68986
|
+
executionMode: config.buyer.executionMode,
|
|
68987
|
+
skipReason: signal.intent.reason,
|
|
68988
|
+
createdAt: now,
|
|
68989
|
+
updatedAt: now
|
|
68990
|
+
};
|
|
68991
|
+
if (!claimReceipt(path2, receipt)) {
|
|
68992
|
+
const existing = readReceipt(path2);
|
|
68993
|
+
if (!existing) {
|
|
68994
|
+
throw new Error(`signal execution receipt exists but cannot be read: ${path2}`);
|
|
68995
|
+
}
|
|
68996
|
+
return { handled: true, duplicate: true, receipt: existing };
|
|
68997
|
+
}
|
|
68998
|
+
logWithTimestamp(
|
|
68999
|
+
`[signal-trading] skipped NO_TRADE signal=${signal.signalId} service=${signal.serviceId} job=${context.jobId} reason=${signal.intent.reason}`
|
|
69000
|
+
);
|
|
69001
|
+
return { handled: true, duplicate: false, receipt };
|
|
69002
|
+
}
|
|
69003
|
+
const existingReceipt = readReceipt(path2);
|
|
69004
|
+
if (existingReceipt) {
|
|
69005
|
+
return { handled: true, duplicate: true, receipt: existingReceipt };
|
|
69006
|
+
}
|
|
69007
|
+
validateSignalPreconditions(signal, config.buyer, context, Date.now());
|
|
69008
|
+
const authorization = await authorizeRotatingPolymarketToken(
|
|
69009
|
+
signal,
|
|
69010
|
+
config.buyer,
|
|
69011
|
+
this.runner,
|
|
69012
|
+
this.eventFetcher
|
|
69013
|
+
);
|
|
69014
|
+
const marketSnapshot = await queryPolymarketMarketSnapshot(
|
|
69015
|
+
signal,
|
|
69016
|
+
authorization.buyer,
|
|
69017
|
+
this.runner,
|
|
69018
|
+
authorization.tickSize
|
|
69019
|
+
);
|
|
69020
|
+
const plan = buildPolymarketExecutionPlan(
|
|
69021
|
+
signal,
|
|
69022
|
+
authorization.buyer,
|
|
69023
|
+
context,
|
|
69024
|
+
{
|
|
69025
|
+
...marketSnapshot,
|
|
69026
|
+
...authorization.minOrderSize ? { minOrderSize: authorization.minOrderSize } : {}
|
|
69027
|
+
}
|
|
69028
|
+
);
|
|
69029
|
+
const initialReceipt = {
|
|
69030
|
+
idempotencyKey,
|
|
69031
|
+
signalId: signal.signalId,
|
|
69032
|
+
serviceId: signal.serviceId,
|
|
69033
|
+
subscriptionId: signal.subscriptionId,
|
|
69034
|
+
providerAgentId: signal.providerAgentId,
|
|
69035
|
+
jobId: context.jobId,
|
|
69036
|
+
messageId: context.messageId,
|
|
69037
|
+
status: "PROCESSING",
|
|
69038
|
+
executionMode: config.buyer.executionMode,
|
|
69039
|
+
command: { bin: plan.bin, args: plan.args },
|
|
69040
|
+
createdAt: now,
|
|
69041
|
+
updatedAt: now
|
|
69042
|
+
};
|
|
69043
|
+
if (!claimReceipt(path2, initialReceipt)) {
|
|
69044
|
+
const existing = readReceipt(path2);
|
|
69045
|
+
if (!existing) {
|
|
69046
|
+
throw new Error(`signal execution receipt exists but cannot be read: ${path2}`);
|
|
69047
|
+
}
|
|
69048
|
+
return { handled: true, duplicate: true, receipt: existing };
|
|
69049
|
+
}
|
|
69050
|
+
if (config.buyer.executionMode === "DRY_RUN") {
|
|
69051
|
+
const receipt = {
|
|
69052
|
+
...initialReceipt,
|
|
69053
|
+
status: "DRY_RUN",
|
|
69054
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
69055
|
+
};
|
|
69056
|
+
updateReceipt(path2, receipt);
|
|
69057
|
+
logWithTimestamp(
|
|
69058
|
+
`[signal-trading] dry-run signal=${signal.signalId} service=${signal.serviceId} job=${context.jobId}`
|
|
69059
|
+
);
|
|
69060
|
+
return { handled: true, duplicate: false, receipt };
|
|
69061
|
+
}
|
|
69062
|
+
try {
|
|
69063
|
+
const result = await this.runner(plan.bin, plan.args, {
|
|
69064
|
+
timeoutMs: config.buyer.polymarket?.timeoutMs ?? DEFAULT_POLYMARKET_TIMEOUT_MS
|
|
69065
|
+
});
|
|
69066
|
+
const receipt = {
|
|
69067
|
+
...initialReceipt,
|
|
69068
|
+
status: "SUBMITTED",
|
|
69069
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
69070
|
+
...boundedOutput(result.stdout) ? { stdout: boundedOutput(result.stdout) } : {},
|
|
69071
|
+
...boundedOutput(result.stderr) ? { stderr: boundedOutput(result.stderr) } : {}
|
|
69072
|
+
};
|
|
69073
|
+
updateReceipt(path2, receipt);
|
|
69074
|
+
logWithTimestamp(
|
|
69075
|
+
`[signal-trading] Polymarket order submitted signal=${signal.signalId} service=${signal.serviceId} job=${context.jobId}`
|
|
69076
|
+
);
|
|
69077
|
+
return { handled: true, duplicate: false, receipt };
|
|
69078
|
+
} catch (error) {
|
|
69079
|
+
const receipt = {
|
|
69080
|
+
...initialReceipt,
|
|
69081
|
+
status: "UNKNOWN",
|
|
69082
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
69083
|
+
error: error instanceof Error ? error.message : String(error)
|
|
69084
|
+
};
|
|
69085
|
+
updateReceipt(path2, receipt);
|
|
69086
|
+
throw new Error(
|
|
69087
|
+
`Polymarket CLI execution became UNKNOWN for signal=${signal.signalId}; automatic retry is disabled: ${receipt.error}`
|
|
69088
|
+
);
|
|
69089
|
+
}
|
|
69090
|
+
}
|
|
69091
|
+
};
|
|
69092
|
+
}
|
|
69093
|
+
});
|
|
69094
|
+
|
|
67872
69095
|
// src/listener.ts
|
|
67873
69096
|
var listener_exports = {};
|
|
67874
69097
|
__export(listener_exports, {
|
|
@@ -67931,12 +69154,12 @@ async function isGatewayAvailableForHeartbeat(options) {
|
|
|
67931
69154
|
}
|
|
67932
69155
|
async function getHermesGatewayPluginStatus(options = {}) {
|
|
67933
69156
|
const env = options.env ?? process.env;
|
|
67934
|
-
const hermesHome = env.HERMES_HOME?.trim() || (0,
|
|
67935
|
-
const pluginYamlPath = (0,
|
|
67936
|
-
if (!(0,
|
|
69157
|
+
const hermesHome = env.HERMES_HOME?.trim() || (0, import_node_path32.join)((0, import_node_os11.homedir)(), ".hermes");
|
|
69158
|
+
const pluginYamlPath = (0, import_node_path32.join)(hermesHome, "plugins", "platforms", "okx-a2a", "plugin.yaml");
|
|
69159
|
+
if (!(0, import_node_fs27.existsSync)(pluginYamlPath)) {
|
|
67937
69160
|
return { enabled: false, reason: "plugin_yaml_missing", hermesHome, checkedPath: pluginYamlPath };
|
|
67938
69161
|
}
|
|
67939
|
-
const configPath = (0,
|
|
69162
|
+
const configPath = (0, import_node_path32.join)(hermesHome, "config.yaml");
|
|
67940
69163
|
let content2;
|
|
67941
69164
|
try {
|
|
67942
69165
|
content2 = await (0, import_promises13.readFile)(configPath, "utf8");
|
|
@@ -68097,6 +69320,7 @@ async function runListenerWithLock(options, paths) {
|
|
|
68097
69320
|
logWithTimestamp("[okx-agent-task] user_attention watcher coordinator scanning SQLite watcher state");
|
|
68098
69321
|
let stopping = false;
|
|
68099
69322
|
const service = XmtpService.getInstance();
|
|
69323
|
+
const signalBuyerRuntime = new SignalTradingBuyerRuntime(options.homeDir);
|
|
68100
69324
|
const agentRefreshCoordinator = new AgentRefreshCoordinator({
|
|
68101
69325
|
lookup: (previousFingerprint) => listAllAgentsWithMetadata(previousFingerprint),
|
|
68102
69326
|
refresh: () => service.refreshAgents(),
|
|
@@ -68127,6 +69351,9 @@ async function runListenerWithLock(options, paths) {
|
|
|
68127
69351
|
},
|
|
68128
69352
|
onSessionMessage: async (event) => {
|
|
68129
69353
|
await enqueueAiSessionMessageDispatch({ commands, event });
|
|
69354
|
+
},
|
|
69355
|
+
onSignalTradingSignal: async (event) => {
|
|
69356
|
+
await signalBuyerRuntime.process(event.signal, event);
|
|
68130
69357
|
}
|
|
68131
69358
|
}),
|
|
68132
69359
|
processOfflineMessage: (ctx, deps, replayOptions) => processOfflineFromCoreDeps(store, ctx, deps, {
|
|
@@ -68137,6 +69364,9 @@ async function runListenerWithLock(options, paths) {
|
|
|
68137
69364
|
},
|
|
68138
69365
|
onSessionMessage: async (event) => {
|
|
68139
69366
|
await enqueueAiSessionMessageDispatch({ commands, event });
|
|
69367
|
+
},
|
|
69368
|
+
onSignalTradingSignal: async (event) => {
|
|
69369
|
+
await signalBuyerRuntime.process(event.signal, event);
|
|
68140
69370
|
}
|
|
68141
69371
|
}),
|
|
68142
69372
|
notifySessionExpired: (command) => {
|
|
@@ -68168,12 +69398,12 @@ async function runListenerWithLock(options, paths) {
|
|
|
68168
69398
|
});
|
|
68169
69399
|
}
|
|
68170
69400
|
});
|
|
68171
|
-
service.setPluginVersion("0.2.
|
|
69401
|
+
service.setPluginVersion("0.2.10-beta-98689bff7a-260826152645");
|
|
68172
69402
|
await service.init();
|
|
68173
69403
|
const pluginVersionStatus = service.pluginVersionStatus;
|
|
68174
69404
|
if (pluginVersionStatus.unavailable) {
|
|
68175
69405
|
throw new Error(
|
|
68176
|
-
`@okxweb3/a2a-node v${"0.2.
|
|
69406
|
+
`@okxweb3/a2a-node v${"0.2.10-beta-98689bff7a-260826152645"} is below the required minimum v${pluginVersionStatus.minVersion}`
|
|
68177
69407
|
);
|
|
68178
69408
|
}
|
|
68179
69409
|
const systemConfig = service.getSystemConfig();
|
|
@@ -68201,7 +69431,7 @@ async function runListenerWithLock(options, paths) {
|
|
|
68201
69431
|
onchainosAgentId: "*",
|
|
68202
69432
|
reason: "system-config missing sentryDsn",
|
|
68203
69433
|
pluginId: "@okxweb3/a2a-node",
|
|
68204
|
-
pluginVersion: "0.2.
|
|
69434
|
+
pluginVersion: "0.2.10-beta-98689bff7a-260826152645"
|
|
68205
69435
|
});
|
|
68206
69436
|
}
|
|
68207
69437
|
logWithTimestamp(
|
|
@@ -68631,15 +69861,15 @@ async function timeSettled(fn) {
|
|
|
68631
69861
|
return { durationMs: Date.now() - startedAt, error };
|
|
68632
69862
|
}
|
|
68633
69863
|
}
|
|
68634
|
-
var
|
|
69864
|
+
var import_node_fs27, import_promises13, import_node_os11, 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;
|
|
68635
69865
|
var init_listener = __esm({
|
|
68636
69866
|
"src/listener.ts"() {
|
|
68637
69867
|
"use strict";
|
|
68638
69868
|
init_log();
|
|
68639
|
-
|
|
69869
|
+
import_node_fs27 = require("node:fs");
|
|
68640
69870
|
import_promises13 = require("node:fs/promises");
|
|
68641
69871
|
import_node_os11 = require("node:os");
|
|
68642
|
-
|
|
69872
|
+
import_node_path32 = require("node:path");
|
|
68643
69873
|
init_onchainos();
|
|
68644
69874
|
init_system_config();
|
|
68645
69875
|
init_offline_replay_capability();
|
|
@@ -68663,6 +69893,7 @@ var init_listener = __esm({
|
|
|
68663
69893
|
init_sentry_logger();
|
|
68664
69894
|
init_runtime_metadata();
|
|
68665
69895
|
init_sentry_config();
|
|
69896
|
+
init_execution();
|
|
68666
69897
|
DEFAULT_OFFLINE_REPLAY_INTERVAL_SEC = 300;
|
|
68667
69898
|
DEFAULT_XMTP_CLIENT_RECYCLE_INTERVAL_SEC = 6 * 60 * 60;
|
|
68668
69899
|
XMTP_CLIENT_RECYCLE_INTERVAL_ENV = "OKX_A2A_XMTP_CLIENT_RECYCLE_INTERVAL_SEC";
|
|
@@ -68884,9 +70115,9 @@ async function handleXmtpTestCommand(args, releaseInfo) {
|
|
|
68884
70115
|
async function startXmtpTest(args, releaseInfo) {
|
|
68885
70116
|
assertKnownOptions(args, /* @__PURE__ */ new Set(["--name", "--run-id", "--json"]));
|
|
68886
70117
|
const paths = resolveTaskPaths();
|
|
68887
|
-
const testsDir = (0,
|
|
70118
|
+
const testsDir = (0, import_node_path33.join)(paths.homeDir, "xmtp-tests");
|
|
68888
70119
|
await ensurePrivateDir(testsDir);
|
|
68889
|
-
const active = await readJsonIfExists((0,
|
|
70120
|
+
const active = await readJsonIfExists((0, import_node_path33.join)(testsDir, ACTIVE_FILE));
|
|
68890
70121
|
if (active?.runId) {
|
|
68891
70122
|
throw new Error(
|
|
68892
70123
|
`XMTP test ${active.runId} is already active. Run \`okx-a2a xmtp-test stop\` first.`
|
|
@@ -68925,7 +70156,7 @@ async function startXmtpTest(args, releaseInfo) {
|
|
|
68925
70156
|
...releaseInfo
|
|
68926
70157
|
};
|
|
68927
70158
|
await writeJson(files.manifestPath, manifest);
|
|
68928
|
-
await writeJson((0,
|
|
70159
|
+
await writeJson((0, import_node_path33.join)(testsDir, ACTIVE_FILE), {
|
|
68929
70160
|
runId,
|
|
68930
70161
|
startedAt: manifest.startedAt
|
|
68931
70162
|
});
|
|
@@ -68948,7 +70179,7 @@ Run \`okx-a2a xmtp-test watch\` to open the realtime dashboard.`);
|
|
|
68948
70179
|
async function stopXmtpTest(args) {
|
|
68949
70180
|
assertKnownOptions(args, /* @__PURE__ */ new Set(["--json"]));
|
|
68950
70181
|
const testsDir = resolveTestsDir();
|
|
68951
|
-
const activePath = (0,
|
|
70182
|
+
const activePath = (0, import_node_path33.join)(testsDir, ACTIVE_FILE);
|
|
68952
70183
|
const active = await readJsonIfExists(activePath);
|
|
68953
70184
|
if (!active?.runId) {
|
|
68954
70185
|
throw new Error("No active XMTP test.");
|
|
@@ -69242,17 +70473,17 @@ function formatJobEvent(event) {
|
|
|
69242
70473
|
return `${timestamp} ${businessEvent.padEnd(34)} ${role}#${agent} ${source}${timings.length > 0 ? ` ${timings.join(" ")}` : ""}`;
|
|
69243
70474
|
}
|
|
69244
70475
|
function resolveTestsDir() {
|
|
69245
|
-
return (0,
|
|
70476
|
+
return (0, import_node_path33.join)(resolveTaskPaths().homeDir, "xmtp-tests");
|
|
69246
70477
|
}
|
|
69247
70478
|
function resolveRunFiles(testsDir, runId) {
|
|
69248
70479
|
validateRunId(runId);
|
|
69249
|
-
const runDir = (0,
|
|
70480
|
+
const runDir = (0, import_node_path33.join)(testsDir, runId);
|
|
69250
70481
|
return {
|
|
69251
70482
|
testsDir,
|
|
69252
70483
|
runDir,
|
|
69253
|
-
manifestPath: (0,
|
|
69254
|
-
eventsPath: (0,
|
|
69255
|
-
summaryPath: (0,
|
|
70484
|
+
manifestPath: (0, import_node_path33.join)(runDir, "manifest.json"),
|
|
70485
|
+
eventsPath: (0, import_node_path33.join)(runDir, "events.jsonl"),
|
|
70486
|
+
summaryPath: (0, import_node_path33.join)(runDir, "summary.json")
|
|
69256
70487
|
};
|
|
69257
70488
|
}
|
|
69258
70489
|
async function resolveRequestedRunId(testsDir, args, preferActive = false) {
|
|
@@ -69260,7 +70491,7 @@ async function resolveRequestedRunId(testsDir, args, preferActive = false) {
|
|
|
69260
70491
|
if (requested) {
|
|
69261
70492
|
return validateRunId(requested);
|
|
69262
70493
|
}
|
|
69263
|
-
const active = await readJsonIfExists((0,
|
|
70494
|
+
const active = await readJsonIfExists((0, import_node_path33.join)(testsDir, ACTIVE_FILE));
|
|
69264
70495
|
if (active?.runId && (preferActive || !args.includes("--latest"))) {
|
|
69265
70496
|
return validateRunId(active.runId);
|
|
69266
70497
|
}
|
|
@@ -69286,7 +70517,7 @@ async function findLatestRunId(testsDir) {
|
|
|
69286
70517
|
continue;
|
|
69287
70518
|
}
|
|
69288
70519
|
const manifest = await readJsonIfExists(
|
|
69289
|
-
(0,
|
|
70520
|
+
(0, import_node_path33.join)(testsDir, entry.name, "manifest.json")
|
|
69290
70521
|
);
|
|
69291
70522
|
if (manifest?.runId && manifest.startedAt) {
|
|
69292
70523
|
manifests.push(manifest);
|
|
@@ -69521,12 +70752,12 @@ function formatPercent(value) {
|
|
|
69521
70752
|
function validTimestamp(value) {
|
|
69522
70753
|
return typeof value === "string" && Number.isFinite(Date.parse(value));
|
|
69523
70754
|
}
|
|
69524
|
-
var import_promises14,
|
|
70755
|
+
var import_promises14, import_node_path33, RUN_ID_PATTERN2, ACTIVE_FILE;
|
|
69525
70756
|
var init_xmtp_test_cli = __esm({
|
|
69526
70757
|
"src/xmtp-test-cli.ts"() {
|
|
69527
70758
|
"use strict";
|
|
69528
70759
|
import_promises14 = require("node:fs/promises");
|
|
69529
|
-
|
|
70760
|
+
import_node_path33 = require("node:path");
|
|
69530
70761
|
init_daemon();
|
|
69531
70762
|
init_log_tail();
|
|
69532
70763
|
init_paths();
|
|
@@ -69535,6 +70766,145 @@ var init_xmtp_test_cli = __esm({
|
|
|
69535
70766
|
}
|
|
69536
70767
|
});
|
|
69537
70768
|
|
|
70769
|
+
// src/signal-trading/cli.ts
|
|
70770
|
+
var cli_exports = {};
|
|
70771
|
+
__export(cli_exports, {
|
|
70772
|
+
handleSignalCommand: () => handleSignalCommand,
|
|
70773
|
+
printSignalUsage: () => printSignalUsage
|
|
70774
|
+
});
|
|
70775
|
+
function printSignalUsage() {
|
|
70776
|
+
console.log(`Usage: okx-a2a signal publish --service-id <id> (--file <path> | --stdin) [--json]
|
|
70777
|
+
|
|
70778
|
+
Commands:
|
|
70779
|
+
publish Validate a TradingSignalV1 JSON message and ask the daemon to deliver it
|
|
70780
|
+
to the configured job route for serviceId + subscriptionId.
|
|
70781
|
+
|
|
70782
|
+
Options:
|
|
70783
|
+
--service-id <id> Signal service whose configured subscribers should be notified.
|
|
70784
|
+
--file <path> Read one TradingSignalV1 JSON object from a file.
|
|
70785
|
+
--stdin Read one TradingSignalV1 JSON object from standard input.
|
|
70786
|
+
--json Print machine-readable command result JSON.
|
|
70787
|
+
`);
|
|
70788
|
+
}
|
|
70789
|
+
function readOption3(args, name) {
|
|
70790
|
+
const index2 = args.indexOf(name);
|
|
70791
|
+
return index2 < 0 ? void 0 : args[index2 + 1];
|
|
70792
|
+
}
|
|
70793
|
+
function hasFlag(args, name) {
|
|
70794
|
+
return args.includes(name);
|
|
70795
|
+
}
|
|
70796
|
+
function assertKnownPublishOptions(args) {
|
|
70797
|
+
const valueOptions = /* @__PURE__ */ new Set(["--service-id", "--file"]);
|
|
70798
|
+
const flags = /* @__PURE__ */ new Set(["--stdin", "--json", "--help", "-h"]);
|
|
70799
|
+
for (let index2 = 0; index2 < args.length; index2++) {
|
|
70800
|
+
const arg = args[index2];
|
|
70801
|
+
if (flags.has(arg)) {
|
|
70802
|
+
continue;
|
|
70803
|
+
}
|
|
70804
|
+
if (valueOptions.has(arg)) {
|
|
70805
|
+
if (!args[index2 + 1] || args[index2 + 1].startsWith("--")) {
|
|
70806
|
+
throw new Error(`signal publish option ${arg} requires a value`);
|
|
70807
|
+
}
|
|
70808
|
+
index2++;
|
|
70809
|
+
continue;
|
|
70810
|
+
}
|
|
70811
|
+
throw new Error(`signal publish unknown argument: ${arg}`);
|
|
70812
|
+
}
|
|
70813
|
+
}
|
|
70814
|
+
async function readStream(stream) {
|
|
70815
|
+
const chunks = [];
|
|
70816
|
+
for await (const chunk of stream) {
|
|
70817
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));
|
|
70818
|
+
}
|
|
70819
|
+
return Buffer.concat(chunks).toString("utf8");
|
|
70820
|
+
}
|
|
70821
|
+
async function readSignalJson(args, stdin) {
|
|
70822
|
+
const filePath = readOption3(args, "--file");
|
|
70823
|
+
const fromStdin = hasFlag(args, "--stdin");
|
|
70824
|
+
if (!!filePath === fromStdin) {
|
|
70825
|
+
throw new Error("signal publish requires exactly one of --file <path> or --stdin");
|
|
70826
|
+
}
|
|
70827
|
+
const raw = filePath ? (0, import_node_fs28.readFileSync)(filePath, "utf8") : await readStream(stdin);
|
|
70828
|
+
if (!raw.trim()) {
|
|
70829
|
+
throw new Error("signal publish input is empty");
|
|
70830
|
+
}
|
|
70831
|
+
try {
|
|
70832
|
+
return JSON.parse(raw);
|
|
70833
|
+
} catch (error) {
|
|
70834
|
+
throw new Error(`signal publish input is not valid JSON: ${error instanceof Error ? error.message : String(error)}`);
|
|
70835
|
+
}
|
|
70836
|
+
}
|
|
70837
|
+
async function handleSignalCommand(args, options = {}) {
|
|
70838
|
+
const subcommand = args[0];
|
|
70839
|
+
if (!subcommand || subcommand === "help" || args.every((arg) => arg === "--help" || arg === "-h")) {
|
|
70840
|
+
printSignalUsage();
|
|
70841
|
+
return;
|
|
70842
|
+
}
|
|
70843
|
+
if (subcommand !== "publish") {
|
|
70844
|
+
throw new Error(`Unknown signal command: ${subcommand}`);
|
|
70845
|
+
}
|
|
70846
|
+
const commandArgs = args.slice(1);
|
|
70847
|
+
if (hasFlag(commandArgs, "--help") || hasFlag(commandArgs, "-h")) {
|
|
70848
|
+
printSignalUsage();
|
|
70849
|
+
return;
|
|
70850
|
+
}
|
|
70851
|
+
assertKnownPublishOptions(commandArgs);
|
|
70852
|
+
const serviceId = readOption3(commandArgs, "--service-id")?.trim();
|
|
70853
|
+
if (!serviceId) {
|
|
70854
|
+
throw new Error("signal publish requires --service-id <id>");
|
|
70855
|
+
}
|
|
70856
|
+
const signal = parseTradingSignalV1(
|
|
70857
|
+
await readSignalJson(commandArgs, options.stdin ?? process.stdin)
|
|
70858
|
+
);
|
|
70859
|
+
if (signal.serviceId !== serviceId) {
|
|
70860
|
+
throw new Error(
|
|
70861
|
+
`signal publish --service-id ${serviceId} does not match signal.serviceId ${signal.serviceId}`
|
|
70862
|
+
);
|
|
70863
|
+
}
|
|
70864
|
+
await ensureDaemonReady({ commandName: "signal publish", stderr: process.stderr });
|
|
70865
|
+
const commands = new CommandStore(options.homeDir);
|
|
70866
|
+
try {
|
|
70867
|
+
const command = commands.createSignalPublishCommand({ serviceId, signal });
|
|
70868
|
+
await commands.submit(command);
|
|
70869
|
+
const result = await commands.waitForResult(command.id, Number.POSITIVE_INFINITY);
|
|
70870
|
+
const json = hasFlag(commandArgs, "--json");
|
|
70871
|
+
if (!result) {
|
|
70872
|
+
throw new Error("signal publish finished without a daemon result");
|
|
70873
|
+
}
|
|
70874
|
+
if (!result.ok) {
|
|
70875
|
+
if (json) {
|
|
70876
|
+
console.log(JSON.stringify({ ok: false, commandId: command.id, error: result.error ?? null }));
|
|
70877
|
+
}
|
|
70878
|
+
throw new Error(result.error ?? "signal publish failed");
|
|
70879
|
+
}
|
|
70880
|
+
const payload = result.payload;
|
|
70881
|
+
if (json) {
|
|
70882
|
+
console.log(JSON.stringify({ ok: true, commandId: command.id, ...payload }));
|
|
70883
|
+
} else {
|
|
70884
|
+
console.log(
|
|
70885
|
+
`ok=true signal=${payload.signalId} service=${payload.serviceId} deliveries=${payload.deliveries.length}`
|
|
70886
|
+
);
|
|
70887
|
+
for (const delivery of payload.deliveries) {
|
|
70888
|
+
console.log(
|
|
70889
|
+
`jobId=${delivery.jobId} subscriptionId=${delivery.subscriptionId} toAgentId=${delivery.toAgentId} messageId=${delivery.messageId}`
|
|
70890
|
+
);
|
|
70891
|
+
}
|
|
70892
|
+
}
|
|
70893
|
+
} finally {
|
|
70894
|
+
commands.close();
|
|
70895
|
+
}
|
|
70896
|
+
}
|
|
70897
|
+
var import_node_fs28;
|
|
70898
|
+
var init_cli = __esm({
|
|
70899
|
+
"src/signal-trading/cli.ts"() {
|
|
70900
|
+
"use strict";
|
|
70901
|
+
import_node_fs28 = require("node:fs");
|
|
70902
|
+
init_daemon();
|
|
70903
|
+
init_command_store();
|
|
70904
|
+
init_protocol();
|
|
70905
|
+
}
|
|
70906
|
+
});
|
|
70907
|
+
|
|
69538
70908
|
// ../../node_modules/@xmtp/content-type-primitives/dist/index.js
|
|
69539
70909
|
var ContentTypeId;
|
|
69540
70910
|
var init_dist5 = __esm({
|
|
@@ -80172,7 +81542,7 @@ var require_mock_interceptor = __commonJS({
|
|
|
80172
81542
|
var require_mock_client = __commonJS({
|
|
80173
81543
|
"../../node_modules/undici/lib/mock/mock-client.js"(exports2, module2) {
|
|
80174
81544
|
"use strict";
|
|
80175
|
-
var { promisify:
|
|
81545
|
+
var { promisify: promisify4 } = require("util");
|
|
80176
81546
|
var Client2 = require_client2();
|
|
80177
81547
|
var { buildMockDispatch } = require_mock_utils();
|
|
80178
81548
|
var {
|
|
@@ -80212,7 +81582,7 @@ var require_mock_client = __commonJS({
|
|
|
80212
81582
|
return new MockInterceptor(opts, this[kDispatches]);
|
|
80213
81583
|
}
|
|
80214
81584
|
async [kClose]() {
|
|
80215
|
-
await
|
|
81585
|
+
await promisify4(this[kOriginalClose])();
|
|
80216
81586
|
this[kConnected] = 0;
|
|
80217
81587
|
this[kMockAgent][Symbols.kClients].delete(this[kOrigin]);
|
|
80218
81588
|
}
|
|
@@ -80225,7 +81595,7 @@ var require_mock_client = __commonJS({
|
|
|
80225
81595
|
var require_mock_pool = __commonJS({
|
|
80226
81596
|
"../../node_modules/undici/lib/mock/mock-pool.js"(exports2, module2) {
|
|
80227
81597
|
"use strict";
|
|
80228
|
-
var { promisify:
|
|
81598
|
+
var { promisify: promisify4 } = require("util");
|
|
80229
81599
|
var Pool = require_pool();
|
|
80230
81600
|
var { buildMockDispatch } = require_mock_utils();
|
|
80231
81601
|
var {
|
|
@@ -80265,7 +81635,7 @@ var require_mock_pool = __commonJS({
|
|
|
80265
81635
|
return new MockInterceptor(opts, this[kDispatches]);
|
|
80266
81636
|
}
|
|
80267
81637
|
async [kClose]() {
|
|
80268
|
-
await
|
|
81638
|
+
await promisify4(this[kOriginalClose])();
|
|
80269
81639
|
this[kConnected] = 0;
|
|
80270
81640
|
this[kMockAgent][Symbols.kClients].delete(this[kOrigin]);
|
|
80271
81641
|
}
|
|
@@ -86912,7 +88282,7 @@ var require_fetch_pb = __commonJS({
|
|
|
86912
88282
|
}
|
|
86913
88283
|
});
|
|
86914
88284
|
}
|
|
86915
|
-
function
|
|
88285
|
+
function isPlainObject6(value) {
|
|
86916
88286
|
const isObject = Object.prototype.toString.call(value).slice(8, -1) === "Object";
|
|
86917
88287
|
const isObjLike = value !== null && isObject;
|
|
86918
88288
|
if (!isObjLike || !isObject) {
|
|
@@ -86935,7 +88305,7 @@ var require_fetch_pb = __commonJS({
|
|
|
86935
88305
|
const isNonEmptyPrimitiveArray = Array.isArray(value) && value.every((v) => isPrimitive(v)) && value.length > 0;
|
|
86936
88306
|
const isNonZeroValuePrimitive = isPrimitive(value) && !isZeroValuePrimitive(value);
|
|
86937
88307
|
let objectToMerge = {};
|
|
86938
|
-
if (
|
|
88308
|
+
if (isPlainObject6(value)) {
|
|
86939
88309
|
objectToMerge = flattenRequestPayload(value, newPath);
|
|
86940
88310
|
} else if (isNonZeroValuePrimitive || isNonEmptyPrimitiveArray) {
|
|
86941
88311
|
objectToMerge = { [newPath]: value };
|
|
@@ -112504,10 +113874,10 @@ var require_node4 = __commonJS({
|
|
|
112504
113874
|
|
|
112505
113875
|
// ../../node_modules/@xmtp/content-type-remote-attachment/dist/index.js
|
|
112506
113876
|
async function encrypt(plain, secret, additionalData) {
|
|
112507
|
-
const salt =
|
|
112508
|
-
const nonce =
|
|
113877
|
+
const salt = import_node_crypto18.webcrypto.getRandomValues(new Uint8Array(KDFSaltSize));
|
|
113878
|
+
const nonce = import_node_crypto18.webcrypto.getRandomValues(new Uint8Array(AESGCMNonceSize));
|
|
112509
113879
|
const key = await hkdf(secret, salt);
|
|
112510
|
-
const encrypted = await
|
|
113880
|
+
const encrypted = await import_node_crypto18.webcrypto.subtle.encrypt(aesGcmParams(nonce), key, plain);
|
|
112511
113881
|
return new Ciphertext({
|
|
112512
113882
|
aes256GcmHkdfSha256: {
|
|
112513
113883
|
payload: new Uint8Array(encrypted),
|
|
@@ -112521,7 +113891,7 @@ async function decrypt(encrypted, secret, additionalData) {
|
|
|
112521
113891
|
throw new Error("invalid payload ciphertext");
|
|
112522
113892
|
}
|
|
112523
113893
|
const key = await hkdf(secret, encrypted.aes256GcmHkdfSha256.hkdfSalt);
|
|
112524
|
-
const decrypted = await
|
|
113894
|
+
const decrypted = await import_node_crypto18.webcrypto.subtle.decrypt(aesGcmParams(encrypted.aes256GcmHkdfSha256.gcmNonce), key, encrypted.aes256GcmHkdfSha256.payload);
|
|
112525
113895
|
return new Uint8Array(decrypted);
|
|
112526
113896
|
}
|
|
112527
113897
|
function aesGcmParams(nonce, additionalData) {
|
|
@@ -112532,18 +113902,18 @@ function aesGcmParams(nonce, additionalData) {
|
|
|
112532
113902
|
return spec;
|
|
112533
113903
|
}
|
|
112534
113904
|
async function hkdf(secret, salt) {
|
|
112535
|
-
const key = await
|
|
113905
|
+
const key = await import_node_crypto18.webcrypto.subtle.importKey("raw", secret, "HKDF", false, [
|
|
112536
113906
|
"deriveKey"
|
|
112537
113907
|
]);
|
|
112538
|
-
return
|
|
113908
|
+
return import_node_crypto18.webcrypto.subtle.deriveKey({ name: "HKDF", hash: "SHA-256", salt, info: hkdfNoInfo }, key, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"]);
|
|
112539
113909
|
}
|
|
112540
|
-
var import_proto,
|
|
113910
|
+
var import_proto, import_node_crypto18, ContentTypeAttachment, AttachmentCodec, KDFSaltSize, AESGCMNonceSize, AESGCMTagLength, Ciphertext, hkdfNoInfo, ContentTypeRemoteAttachment, RemoteAttachmentCodec;
|
|
112541
113911
|
var init_dist6 = __esm({
|
|
112542
113912
|
"../../node_modules/@xmtp/content-type-remote-attachment/dist/index.js"() {
|
|
112543
113913
|
init_dist5();
|
|
112544
113914
|
init_secp256k12();
|
|
112545
113915
|
import_proto = __toESM(require_node4(), 1);
|
|
112546
|
-
|
|
113916
|
+
import_node_crypto18 = require("node:crypto");
|
|
112547
113917
|
ContentTypeAttachment = new ContentTypeId({
|
|
112548
113918
|
authorityId: "xmtp.org",
|
|
112549
113919
|
typeId: "attachment",
|
|
@@ -112623,7 +113993,7 @@ var init_dist6 = __esm({
|
|
|
112623
113993
|
if (payload.length === 0) {
|
|
112624
113994
|
throw new Error(`no payload for remote attachment at ${remoteAttachment.url}`);
|
|
112625
113995
|
}
|
|
112626
|
-
const digestBytes = new Uint8Array(await
|
|
113996
|
+
const digestBytes = new Uint8Array(await import_node_crypto18.webcrypto.subtle.digest("SHA-256", payload));
|
|
112627
113997
|
const digest = etc.bytesToHex(digestBytes);
|
|
112628
113998
|
if (digest !== remoteAttachment.contentDigest) {
|
|
112629
113999
|
throw new Error("content digest does not match");
|
|
@@ -112647,7 +114017,7 @@ var init_dist6 = __esm({
|
|
|
112647
114017
|
return codec.decode(encodedContent, codecRegistry);
|
|
112648
114018
|
}
|
|
112649
114019
|
static async encodeEncrypted(content$1, codec) {
|
|
112650
|
-
const secret =
|
|
114020
|
+
const secret = import_node_crypto18.webcrypto.getRandomValues(new Uint8Array(32));
|
|
112651
114021
|
const encodedContent = import_proto.content.EncodedContent.encode(codec.encode(content$1, {
|
|
112652
114022
|
codecFor() {
|
|
112653
114023
|
return void 0;
|
|
@@ -112660,7 +114030,7 @@ var init_dist6 = __esm({
|
|
|
112660
114030
|
if (!salt || !nonce || !payload) {
|
|
112661
114031
|
throw new Error("missing encryption key");
|
|
112662
114032
|
}
|
|
112663
|
-
const digestBytes = new Uint8Array(await
|
|
114033
|
+
const digestBytes = new Uint8Array(await import_node_crypto18.webcrypto.subtle.digest("SHA-256", payload));
|
|
112664
114034
|
const digest = etc.bytesToHex(digestBytes);
|
|
112665
114035
|
return {
|
|
112666
114036
|
digest,
|
|
@@ -112715,9 +114085,9 @@ var init_dist6 = __esm({
|
|
|
112715
114085
|
|
|
112716
114086
|
// ../core/src/file-upload-safety.ts
|
|
112717
114087
|
function getUnsafeFileUploadReason(filePath, sensitiveUploadReg = []) {
|
|
112718
|
-
const expanded = (0,
|
|
112719
|
-
const target = (0,
|
|
112720
|
-
const targetName = (0,
|
|
114088
|
+
const expanded = (0, import_node_path34.resolve)(expandHome(filePath));
|
|
114089
|
+
const target = (0, import_node_fs29.realpathSync)(expanded);
|
|
114090
|
+
const targetName = (0, import_node_path34.basename)(target);
|
|
112721
114091
|
if (targetName === ".env" || targetName.startsWith(".env.")) {
|
|
112722
114092
|
return ".env";
|
|
112723
114093
|
}
|
|
@@ -112730,13 +114100,13 @@ function getUnsafeFileUploadReason(filePath, sensitiveUploadReg = []) {
|
|
|
112730
114100
|
return null;
|
|
112731
114101
|
}
|
|
112732
114102
|
for (const dir of SENSITIVE_HOME_DIRS) {
|
|
112733
|
-
const sensitiveDir = safeRealpath((0,
|
|
114103
|
+
const sensitiveDir = safeRealpath((0, import_node_path34.join)(home, dir));
|
|
112734
114104
|
if (sensitiveDir && isPathInside(target, sensitiveDir)) {
|
|
112735
114105
|
return `~/${dir}`;
|
|
112736
114106
|
}
|
|
112737
114107
|
}
|
|
112738
114108
|
for (const file of SENSITIVE_HOME_FILES) {
|
|
112739
|
-
const sensitiveFile = safeRealpath((0,
|
|
114109
|
+
const sensitiveFile = safeRealpath((0, import_node_path34.join)(home, file));
|
|
112740
114110
|
if (sensitiveFile && target === sensitiveFile) {
|
|
112741
114111
|
return `~/${file}`;
|
|
112742
114112
|
}
|
|
@@ -112764,27 +114134,27 @@ function expandHome(filePath) {
|
|
|
112764
114134
|
if (filePath === "~") {
|
|
112765
114135
|
return (0, import_node_os12.homedir)();
|
|
112766
114136
|
}
|
|
112767
|
-
if (filePath.startsWith(`~${
|
|
112768
|
-
return (0,
|
|
114137
|
+
if (filePath.startsWith(`~${import_node_path34.sep}`)) {
|
|
114138
|
+
return (0, import_node_path34.join)((0, import_node_os12.homedir)(), filePath.slice(2));
|
|
112769
114139
|
}
|
|
112770
114140
|
return filePath;
|
|
112771
114141
|
}
|
|
112772
114142
|
function safeRealpath(path2) {
|
|
112773
|
-
if (!(0,
|
|
114143
|
+
if (!(0, import_node_fs29.existsSync)(path2)) {
|
|
112774
114144
|
return null;
|
|
112775
114145
|
}
|
|
112776
|
-
return (0,
|
|
114146
|
+
return (0, import_node_fs29.realpathSync)(path2);
|
|
112777
114147
|
}
|
|
112778
114148
|
function isPathInside(target, dir) {
|
|
112779
|
-
return target === dir || target.startsWith(`${dir}${
|
|
114149
|
+
return target === dir || target.startsWith(`${dir}${import_node_path34.sep}`);
|
|
112780
114150
|
}
|
|
112781
|
-
var
|
|
114151
|
+
var import_node_fs29, import_node_os12, import_node_path34, SENSITIVE_HOME_DIRS, SENSITIVE_HOME_FILES, UNSAFE_FILE_UPLOAD_MESSAGE;
|
|
112782
114152
|
var init_file_upload_safety = __esm({
|
|
112783
114153
|
"../core/src/file-upload-safety.ts"() {
|
|
112784
114154
|
"use strict";
|
|
112785
|
-
|
|
114155
|
+
import_node_fs29 = require("node:fs");
|
|
112786
114156
|
import_node_os12 = require("node:os");
|
|
112787
|
-
|
|
114157
|
+
import_node_path34 = require("node:path");
|
|
112788
114158
|
SENSITIVE_HOME_DIRS = [
|
|
112789
114159
|
".ssh",
|
|
112790
114160
|
".gnupg",
|
|
@@ -112792,7 +114162,7 @@ var init_file_upload_safety = __esm({
|
|
|
112792
114162
|
".azure",
|
|
112793
114163
|
".kube",
|
|
112794
114164
|
".docker",
|
|
112795
|
-
(0,
|
|
114165
|
+
(0, import_node_path34.join)(".config", "gcloud")
|
|
112796
114166
|
];
|
|
112797
114167
|
SENSITIVE_HOME_FILES = [
|
|
112798
114168
|
".npmrc",
|
|
@@ -112821,8 +114191,8 @@ async function handleFileCommand(args) {
|
|
|
112821
114191
|
filePath: readRequiredOption(rest, "--file-path"),
|
|
112822
114192
|
agentId: readRequiredOption(rest, "--agent-id"),
|
|
112823
114193
|
jobId: readRequiredOption(rest, "--job-id"),
|
|
112824
|
-
filename:
|
|
112825
|
-
mimeType:
|
|
114194
|
+
filename: readOption4(rest, "--filename"),
|
|
114195
|
+
mimeType: readOption4(rest, "--mime-type")
|
|
112826
114196
|
});
|
|
112827
114197
|
return;
|
|
112828
114198
|
}
|
|
@@ -112834,7 +114204,7 @@ async function handleFileCommand(args) {
|
|
|
112834
114204
|
salt: readRequiredOption(rest, "--salt"),
|
|
112835
114205
|
nonce: readRequiredOption(rest, "--nonce"),
|
|
112836
114206
|
secret: readRequiredOption(rest, "--secret"),
|
|
112837
|
-
filename:
|
|
114207
|
+
filename: readOption4(rest, "--filename")
|
|
112838
114208
|
});
|
|
112839
114209
|
return;
|
|
112840
114210
|
}
|
|
@@ -112854,7 +114224,7 @@ function hasHelpFlag(args) {
|
|
|
112854
114224
|
return args.some((arg) => arg === "-h" || arg === "--help" || arg === "help");
|
|
112855
114225
|
}
|
|
112856
114226
|
async function uploadFile(params) {
|
|
112857
|
-
const filename = params.filename || (0,
|
|
114227
|
+
const filename = params.filename || (0, import_node_path35.basename)(params.filePath);
|
|
112858
114228
|
const mimeType = params.mimeType || "application/octet-stream";
|
|
112859
114229
|
const uploadConfig = readUploadSystemConfig();
|
|
112860
114230
|
const unsafeReason = getUnsafeFileUploadReason(params.filePath, uploadConfig.sensitiveUploadReg);
|
|
@@ -112870,16 +114240,16 @@ async function uploadFile(params) {
|
|
|
112870
114240
|
return;
|
|
112871
114241
|
}
|
|
112872
114242
|
const maxFileSizeBytes = uploadConfig.maxFileSizeBytes;
|
|
112873
|
-
const fileSize = (0,
|
|
114243
|
+
const fileSize = (0, import_node_fs30.statSync)(params.filePath).size;
|
|
112874
114244
|
if (fileSize > maxFileSizeBytes) {
|
|
112875
114245
|
throw new Error(formatFileTooLargeMessage(maxFileSizeBytes));
|
|
112876
114246
|
}
|
|
112877
|
-
const data = (0,
|
|
114247
|
+
const data = (0, import_node_fs30.readFileSync)(params.filePath);
|
|
112878
114248
|
const attachment = { filename, mimeType, data: new Uint8Array(data) };
|
|
112879
114249
|
const encrypted = await RemoteAttachmentCodec.encodeEncrypted(attachment, new AttachmentCodec());
|
|
112880
114250
|
ensureFileDirs();
|
|
112881
|
-
const encryptedPath = (0,
|
|
112882
|
-
(0,
|
|
114251
|
+
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto19.randomUUID)()}.enc`);
|
|
114252
|
+
(0, import_node_fs30.writeFileSync)(encryptedPath, encrypted.payload);
|
|
112883
114253
|
try {
|
|
112884
114254
|
const stdout = runOnchainos([
|
|
112885
114255
|
"agent",
|
|
@@ -112915,14 +114285,14 @@ async function uploadFile(params) {
|
|
|
112915
114285
|
}, null, 2));
|
|
112916
114286
|
} finally {
|
|
112917
114287
|
try {
|
|
112918
|
-
(0,
|
|
114288
|
+
(0, import_node_fs30.unlinkSync)(encryptedPath);
|
|
112919
114289
|
} catch {
|
|
112920
114290
|
}
|
|
112921
114291
|
}
|
|
112922
114292
|
}
|
|
112923
114293
|
async function downloadFile(params) {
|
|
112924
114294
|
ensureFileDirs();
|
|
112925
|
-
const encryptedPath = (0,
|
|
114295
|
+
const encryptedPath = (0, import_node_path35.resolve)(FILE_WORK_DIR, `${(0, import_node_crypto19.randomUUID)()}.enc`);
|
|
112926
114296
|
try {
|
|
112927
114297
|
const stdout = runOnchainos([
|
|
112928
114298
|
"agent",
|
|
@@ -112946,8 +114316,8 @@ async function downloadFile(params) {
|
|
|
112946
114316
|
}));
|
|
112947
114317
|
throw new Error(`file download failed: ${stdout}`);
|
|
112948
114318
|
}
|
|
112949
|
-
const payload = new Uint8Array((0,
|
|
112950
|
-
const digestBytes = new Uint8Array(await
|
|
114319
|
+
const payload = new Uint8Array((0, import_node_fs30.readFileSync)(encryptedPath));
|
|
114320
|
+
const digestBytes = new Uint8Array(await import_node_crypto19.webcrypto.subtle.digest("SHA-256", payload));
|
|
112951
114321
|
const actualDigest = Array.from(digestBytes).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
112952
114322
|
if (actualDigest !== params.digest) {
|
|
112953
114323
|
throw new Error(`file download digest verification failed: expected=${params.digest}, actual=${actualDigest}`);
|
|
@@ -112955,15 +114325,15 @@ async function downloadFile(params) {
|
|
|
112955
114325
|
const decryptedBytes = await decryptAttachmentPayload(payload, params);
|
|
112956
114326
|
const encodedContent = import_proto2.content.EncodedContent.decode(decryptedBytes);
|
|
112957
114327
|
const attachment = new AttachmentCodec().decode(encodedContent);
|
|
112958
|
-
const outputFilename = params.filename || attachment.filename || `${(0,
|
|
114328
|
+
const outputFilename = params.filename || attachment.filename || `${(0, import_node_crypto19.randomUUID)()}.bin`;
|
|
112959
114329
|
const outputDir = DOWNLOADS_DIR;
|
|
112960
114330
|
ensureA2aTaskDir(outputDir);
|
|
112961
|
-
const outputPath = (0,
|
|
112962
|
-
(0,
|
|
114331
|
+
const outputPath = (0, import_node_path35.resolve)(outputDir, (0, import_node_path35.basename)(outputFilename));
|
|
114332
|
+
(0, import_node_fs30.writeFileSync)(outputPath, attachment.data);
|
|
112963
114333
|
console.log(outputPath);
|
|
112964
114334
|
} finally {
|
|
112965
114335
|
try {
|
|
112966
|
-
(0,
|
|
114336
|
+
(0, import_node_fs30.unlinkSync)(encryptedPath);
|
|
112967
114337
|
} catch {
|
|
112968
114338
|
}
|
|
112969
114339
|
}
|
|
@@ -112972,15 +114342,15 @@ async function decryptAttachmentPayload(payload, params) {
|
|
|
112972
114342
|
const secretBytes = new Uint8Array(Buffer.from(params.secret, "base64"));
|
|
112973
114343
|
const saltBytes = new Uint8Array(Buffer.from(params.salt, "base64"));
|
|
112974
114344
|
const nonceBytes = new Uint8Array(Buffer.from(params.nonce, "base64"));
|
|
112975
|
-
const hkdfKey = await
|
|
112976
|
-
const aesKey = await
|
|
114345
|
+
const hkdfKey = await import_node_crypto19.webcrypto.subtle.importKey("raw", secretBytes, "HKDF", false, ["deriveKey"]);
|
|
114346
|
+
const aesKey = await import_node_crypto19.webcrypto.subtle.deriveKey(
|
|
112977
114347
|
{ name: "HKDF", hash: "SHA-256", salt: saltBytes, info: new Uint8Array().buffer },
|
|
112978
114348
|
hkdfKey,
|
|
112979
114349
|
{ name: "AES-GCM", length: 256 },
|
|
112980
114350
|
false,
|
|
112981
114351
|
["decrypt"]
|
|
112982
114352
|
);
|
|
112983
|
-
return new Uint8Array(await
|
|
114353
|
+
return new Uint8Array(await import_node_crypto19.webcrypto.subtle.decrypt({ name: "AES-GCM", iv: nonceBytes }, aesKey, toArrayBuffer(payload)));
|
|
112984
114354
|
}
|
|
112985
114355
|
function toArrayBuffer(bytes) {
|
|
112986
114356
|
return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
|
|
@@ -113060,7 +114430,7 @@ function readUploadSystemConfig() {
|
|
|
113060
114430
|
const res = parseCliJson2(stdout, "system-config");
|
|
113061
114431
|
if (res.data && typeof res.data === "object") {
|
|
113062
114432
|
ensureA2aTaskDir(OKX_A2A_PATHS.xmtpDir);
|
|
113063
|
-
(0,
|
|
114433
|
+
(0, import_node_fs30.writeFileSync)(SYSTEM_CONFIG_PATH, JSON.stringify(res.data));
|
|
113064
114434
|
}
|
|
113065
114435
|
return parseUploadSystemConfig(res.data ?? {});
|
|
113066
114436
|
} catch {
|
|
@@ -113083,10 +114453,10 @@ function fileCliSentryExtra(operation, reason, extra = {}) {
|
|
|
113083
114453
|
}
|
|
113084
114454
|
function readSystemConfigFromCache() {
|
|
113085
114455
|
try {
|
|
113086
|
-
if (!(0,
|
|
114456
|
+
if (!(0, import_node_fs30.existsSync)(SYSTEM_CONFIG_PATH)) {
|
|
113087
114457
|
return null;
|
|
113088
114458
|
}
|
|
113089
|
-
return JSON.parse((0,
|
|
114459
|
+
return JSON.parse((0, import_node_fs30.readFileSync)(SYSTEM_CONFIG_PATH, "utf8"));
|
|
113090
114460
|
} catch {
|
|
113091
114461
|
return null;
|
|
113092
114462
|
}
|
|
@@ -113106,7 +114476,7 @@ function readCommand(envName, fallback) {
|
|
|
113106
114476
|
const raw = process.env[envName] || fallback;
|
|
113107
114477
|
return raw.match(/(?:[^\s"]+|"[^"]*")+/g)?.map((part) => part.replace(/^"|"$/g, "")) || [fallback];
|
|
113108
114478
|
}
|
|
113109
|
-
function
|
|
114479
|
+
function readOption4(args, name) {
|
|
113110
114480
|
const index2 = args.indexOf(name);
|
|
113111
114481
|
if (index2 === -1) {
|
|
113112
114482
|
return void 0;
|
|
@@ -113114,20 +114484,20 @@ function readOption3(args, name) {
|
|
|
113114
114484
|
return args[index2 + 1];
|
|
113115
114485
|
}
|
|
113116
114486
|
function readRequiredOption(args, name) {
|
|
113117
|
-
const value =
|
|
114487
|
+
const value = readOption4(args, name);
|
|
113118
114488
|
if (!value) {
|
|
113119
114489
|
throw new Error(`${name} is required`);
|
|
113120
114490
|
}
|
|
113121
114491
|
return value;
|
|
113122
114492
|
}
|
|
113123
|
-
var
|
|
114493
|
+
var import_node_crypto19, import_node_fs30, import_node_path35, import_proto2, OKX_A2A_PATHS, OKX_A2A_HOME_DIR, FILE_WORK_DIR, DOWNLOADS_DIR, SYSTEM_CONFIG_PATH;
|
|
113124
114494
|
var init_file_cli = __esm({
|
|
113125
114495
|
"src/file-cli.ts"() {
|
|
113126
114496
|
"use strict";
|
|
113127
114497
|
init_win_spawn();
|
|
113128
|
-
|
|
113129
|
-
|
|
113130
|
-
|
|
114498
|
+
import_node_crypto19 = require("node:crypto");
|
|
114499
|
+
import_node_fs30 = require("node:fs");
|
|
114500
|
+
import_node_path35 = require("node:path");
|
|
113131
114501
|
init_dist6();
|
|
113132
114502
|
import_proto2 = __toESM(require_node4());
|
|
113133
114503
|
init_a2a_paths();
|
|
@@ -113138,7 +114508,7 @@ var init_file_cli = __esm({
|
|
|
113138
114508
|
OKX_A2A_HOME_DIR = OKX_A2A_PATHS.homeDir;
|
|
113139
114509
|
FILE_WORK_DIR = process.env.OKX_A2A_FILE_WORK_DIR || OKX_A2A_PATHS.filesDir;
|
|
113140
114510
|
DOWNLOADS_DIR = process.env.OKX_A2A_DOWNLOADS_DIR || OKX_A2A_PATHS.downloadsDir;
|
|
113141
|
-
SYSTEM_CONFIG_PATH = (0,
|
|
114511
|
+
SYSTEM_CONFIG_PATH = (0, import_node_path35.resolve)(OKX_A2A_PATHS.xmtpDir, "system-config.json");
|
|
113142
114512
|
}
|
|
113143
114513
|
});
|
|
113144
114514
|
|
|
@@ -115701,7 +117071,7 @@ function isPostjectRunnable() {
|
|
|
115701
117071
|
function resolvePostjectCommand() {
|
|
115702
117072
|
try {
|
|
115703
117073
|
const cliPath = (0, import_node_module.createRequire)(__filename).resolve("postject/dist/cli.js");
|
|
115704
|
-
if ((0,
|
|
117074
|
+
if ((0, import_node_fs31.existsSync)(cliPath)) {
|
|
115705
117075
|
return { command: process.execPath, prefixArgs: [cliPath] };
|
|
115706
117076
|
}
|
|
115707
117077
|
} catch {
|
|
@@ -115772,37 +117142,37 @@ function buildSeaConfig(entryPath, blobPath) {
|
|
|
115772
117142
|
}
|
|
115773
117143
|
async function installWindowsNativeLauncher(options) {
|
|
115774
117144
|
const nodeExe = options.nodeExe ?? process.execPath;
|
|
115775
|
-
if (!(0,
|
|
117145
|
+
if (!(0, import_node_fs31.existsSync)(options.cliPath)) {
|
|
115776
117146
|
throw new Error(`cannot build okx-a2a.exe: CLI entry not found at ${options.cliPath}`);
|
|
115777
117147
|
}
|
|
115778
|
-
if (!(0,
|
|
117148
|
+
if (!(0, import_node_fs31.existsSync)(nodeExe)) {
|
|
115779
117149
|
throw new Error(`cannot build okx-a2a.exe: node executable not found at ${nodeExe}`);
|
|
115780
117150
|
}
|
|
115781
|
-
const exePath = (0,
|
|
115782
|
-
(0,
|
|
115783
|
-
const work = (0,
|
|
117151
|
+
const exePath = (0, import_node_path36.join)(options.targetDir, NATIVE_LAUNCHER_EXE_NAME);
|
|
117152
|
+
(0, import_node_fs31.mkdirSync)(options.targetDir, { recursive: true });
|
|
117153
|
+
const work = (0, import_node_fs31.mkdtempSync)((0, import_node_path36.join)((0, import_node_os13.tmpdir)(), "okx-a2a-sea-"));
|
|
115784
117154
|
try {
|
|
115785
|
-
const entryPath = (0,
|
|
115786
|
-
const blobPath = (0,
|
|
115787
|
-
const configPath = (0,
|
|
115788
|
-
(0,
|
|
115789
|
-
(0,
|
|
115790
|
-
(0,
|
|
117155
|
+
const entryPath = (0, import_node_path36.join)(work, "launcher-entry.js");
|
|
117156
|
+
const blobPath = (0, import_node_path36.join)(work, "okx-a2a.blob");
|
|
117157
|
+
const configPath = (0, import_node_path36.join)(work, "sea-config.json");
|
|
117158
|
+
(0, import_node_fs31.writeFileSync)(entryPath, buildLauncherEntryJs(options.cliPath), "utf8");
|
|
117159
|
+
(0, import_node_fs31.writeFileSync)(configPath, buildSeaConfig(entryPath, blobPath), "utf8");
|
|
117160
|
+
(0, import_node_child_process10.execFileSync)(nodeExe, ["--experimental-sea-config", configPath], {
|
|
115791
117161
|
stdio: "ignore",
|
|
115792
117162
|
windowsHide: true
|
|
115793
117163
|
});
|
|
115794
|
-
(0,
|
|
117164
|
+
(0, import_node_fs31.copyFileSync)(nodeExe, exePath);
|
|
115795
117165
|
const isMac = process.platform === "darwin";
|
|
115796
117166
|
if (isMac) {
|
|
115797
117167
|
try {
|
|
115798
|
-
(0,
|
|
117168
|
+
(0, import_node_child_process10.execFileSync)("codesign", ["--remove-signature", exePath], { stdio: "ignore" });
|
|
115799
117169
|
} catch {
|
|
115800
117170
|
}
|
|
115801
117171
|
}
|
|
115802
117172
|
injectSeaBlob(exePath, blobPath, isMac);
|
|
115803
117173
|
if (isMac) {
|
|
115804
117174
|
try {
|
|
115805
|
-
(0,
|
|
117175
|
+
(0, import_node_child_process10.execFileSync)("codesign", ["--sign", "-", exePath], { stdio: "ignore" });
|
|
115806
117176
|
} catch {
|
|
115807
117177
|
}
|
|
115808
117178
|
}
|
|
@@ -115811,19 +117181,19 @@ async function installWindowsNativeLauncher(options) {
|
|
|
115811
117181
|
);
|
|
115812
117182
|
return { exePath, cliPath: options.cliPath, nodeExe };
|
|
115813
117183
|
} finally {
|
|
115814
|
-
(0,
|
|
117184
|
+
(0, import_node_fs31.rmSync)(work, { recursive: true, force: true });
|
|
115815
117185
|
}
|
|
115816
117186
|
}
|
|
115817
|
-
function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2 =
|
|
117187
|
+
function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2 = import_node_fs31.existsSync) {
|
|
115818
117188
|
const dirs = pathValue.split(";").map((d) => d.trim()).filter(Boolean);
|
|
115819
117189
|
if (appData) {
|
|
115820
|
-
dirs.push((0,
|
|
117190
|
+
dirs.push((0, import_node_path36.join)(appData, "npm"));
|
|
115821
117191
|
}
|
|
115822
117192
|
if (userProfile) {
|
|
115823
|
-
dirs.push((0,
|
|
117193
|
+
dirs.push((0, import_node_path36.join)(userProfile, ".local", "bin"));
|
|
115824
117194
|
}
|
|
115825
117195
|
for (const dir of dirs) {
|
|
115826
|
-
const candidate = (0,
|
|
117196
|
+
const candidate = (0, import_node_path36.join)(dir, NATIVE_LAUNCHER_EXE_NAME);
|
|
115827
117197
|
if (fileExists2(candidate)) {
|
|
115828
117198
|
return candidate;
|
|
115829
117199
|
}
|
|
@@ -115832,11 +117202,11 @@ function findWindowsNativeOkxA2aExe(pathValue, appData, userProfile, fileExists2
|
|
|
115832
117202
|
}
|
|
115833
117203
|
function resolveRunningCliPath() {
|
|
115834
117204
|
const fromArgv = process.argv[1];
|
|
115835
|
-
if (fromArgv && /(?:^|[\\/])cli\.js$/.test(fromArgv) && (0,
|
|
117205
|
+
if (fromArgv && /(?:^|[\\/])cli\.js$/.test(fromArgv) && (0, import_node_fs31.existsSync)(fromArgv)) {
|
|
115836
117206
|
return fromArgv;
|
|
115837
117207
|
}
|
|
115838
|
-
const beside = (0,
|
|
115839
|
-
if ((0,
|
|
117208
|
+
const beside = (0, import_node_path36.join)(__dirname, "cli.js");
|
|
117209
|
+
if ((0, import_node_fs31.existsSync)(beside)) {
|
|
115840
117210
|
return beside;
|
|
115841
117211
|
}
|
|
115842
117212
|
if (fromArgv) {
|
|
@@ -115854,19 +117224,19 @@ async function ensureWindowsNativeLauncher(options = {}) {
|
|
|
115854
117224
|
if (existing) {
|
|
115855
117225
|
return { exePath: existing, installed: false };
|
|
115856
117226
|
}
|
|
115857
|
-
const targetDir = env.APPDATA ? (0,
|
|
117227
|
+
const targetDir = env.APPDATA ? (0, import_node_path36.join)(env.APPDATA, "npm") : (0, import_node_path36.join)(env.USERPROFILE ?? (0, import_node_os13.homedir)(), ".local", "bin");
|
|
115858
117228
|
const result = await installWindowsNativeLauncher({ cliPath: resolveRunningCliPath(), targetDir });
|
|
115859
117229
|
return { exePath: result.exePath, installed: true };
|
|
115860
117230
|
}
|
|
115861
|
-
var
|
|
117231
|
+
var import_node_child_process10, import_node_fs31, import_node_module, import_node_os13, import_node_path36, SEA_SENTINEL_FUSE, NATIVE_LAUNCHER_EXE_NAME, POSTJECT_SPEC, POSTJECT_BIN;
|
|
115862
117232
|
var init_win_native_launcher = __esm({
|
|
115863
117233
|
"src/win-native-launcher.ts"() {
|
|
115864
117234
|
"use strict";
|
|
115865
|
-
|
|
115866
|
-
|
|
117235
|
+
import_node_child_process10 = require("node:child_process");
|
|
117236
|
+
import_node_fs31 = require("node:fs");
|
|
115867
117237
|
import_node_module = require("node:module");
|
|
115868
117238
|
import_node_os13 = require("node:os");
|
|
115869
|
-
|
|
117239
|
+
import_node_path36 = require("node:path");
|
|
115870
117240
|
init_win_compat();
|
|
115871
117241
|
init_win_spawn();
|
|
115872
117242
|
SEA_SENTINEL_FUSE = "NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2";
|
|
@@ -115958,13 +117328,13 @@ function parseUpdateArgs(args) {
|
|
|
115958
117328
|
const target = hasExplicitTarget ? first : null;
|
|
115959
117329
|
const optionArgs = hasExplicitTarget ? args.slice(1) : args;
|
|
115960
117330
|
assertOnlyKnownUpdateOptions(optionArgs);
|
|
115961
|
-
const requestedRelease =
|
|
117331
|
+
const requestedRelease = readOption5(optionArgs, "--release");
|
|
115962
117332
|
const release = requestedRelease ?? "latest";
|
|
115963
117333
|
if (!isSupportedRelease(release)) {
|
|
115964
117334
|
throw new Error(`unsupported release: ${release}`);
|
|
115965
117335
|
}
|
|
115966
|
-
const restart =
|
|
115967
|
-
const yes =
|
|
117336
|
+
const restart = hasFlag2(optionArgs, "--restart");
|
|
117337
|
+
const yes = hasFlag2(optionArgs, "--yes");
|
|
115968
117338
|
if (restart && !yes) {
|
|
115969
117339
|
throw new Error("update --restart requires --yes");
|
|
115970
117340
|
}
|
|
@@ -115982,12 +117352,12 @@ function parseSetupArgs(args) {
|
|
|
115982
117352
|
const target = hasExplicitTarget ? first : null;
|
|
115983
117353
|
const optionArgs = hasExplicitTarget ? args.slice(1) : args;
|
|
115984
117354
|
assertOnlyKnownUpdateOptions(optionArgs, "setup");
|
|
115985
|
-
const requestedRelease =
|
|
117355
|
+
const requestedRelease = readOption5(optionArgs, "--release");
|
|
115986
117356
|
const release = requestedRelease ?? "latest";
|
|
115987
117357
|
if (!isSupportedRelease(release)) {
|
|
115988
117358
|
throw new Error(`unsupported release: ${release}`);
|
|
115989
117359
|
}
|
|
115990
|
-
const json =
|
|
117360
|
+
const json = hasFlag2(optionArgs, "--json");
|
|
115991
117361
|
return { target, release, releaseExplicit: requestedRelease !== void 0, json };
|
|
115992
117362
|
}
|
|
115993
117363
|
function buildNpmPackageSpec(target, release) {
|
|
@@ -116050,7 +117420,7 @@ async function handleSetupCommand(args) {
|
|
|
116050
117420
|
printSetupUsage();
|
|
116051
117421
|
return;
|
|
116052
117422
|
}
|
|
116053
|
-
if (
|
|
117423
|
+
if (hasFlag2(args, "--json")) {
|
|
116054
117424
|
await handleSetupJson(args);
|
|
116055
117425
|
return;
|
|
116056
117426
|
}
|
|
@@ -116608,7 +117978,7 @@ async function getCurrentNodeCliVersion() {
|
|
|
116608
117978
|
return await getGlobalNpmPackageVersion(UPDATE_PACKAGES.node) ?? getBundledNodeCliVersion();
|
|
116609
117979
|
}
|
|
116610
117980
|
function getBundledNodeCliVersion() {
|
|
116611
|
-
return true ? "0.2.
|
|
117981
|
+
return true ? "0.2.10-beta-98689bff7a-260826152645" : null;
|
|
116612
117982
|
}
|
|
116613
117983
|
function readConfiguredAiProvider() {
|
|
116614
117984
|
const explicit = process.env.OKX_A2A_AI_PROVIDER || process.env.OKX_AGENT_TASK_AI_CLI;
|
|
@@ -116793,17 +118163,17 @@ async function updateHermes(release, options) {
|
|
|
116793
118163
|
assertNotRunningInsideGateway("hermes");
|
|
116794
118164
|
}
|
|
116795
118165
|
const spec = buildNpmPackageSpec("hermes", release);
|
|
116796
|
-
const workDir = await (0, import_promises15.mkdtemp)((0,
|
|
118166
|
+
const workDir = await (0, import_promises15.mkdtemp)((0, import_node_path37.join)((0, import_node_os14.tmpdir)(), `okx-a2a-${label}-hermes-`));
|
|
116797
118167
|
try {
|
|
116798
118168
|
console.log(`[${label}] downloading ${spec}`);
|
|
116799
118169
|
const npmTarball = await npmPack(spec, workDir);
|
|
116800
|
-
const npmPackageDir = (0,
|
|
118170
|
+
const npmPackageDir = (0, import_node_path37.join)(workDir, "npm-package");
|
|
116801
118171
|
await runCommand("tar", ["-xzf", npmTarball, "-C", npmPackageDir], { ensureDir: npmPackageDir });
|
|
116802
|
-
const pluginTarball = await findHermesPluginTarball((0,
|
|
116803
|
-
const pluginDir = (0,
|
|
118172
|
+
const pluginTarball = await findHermesPluginTarball((0, import_node_path37.join)(npmPackageDir, "package", "dist"));
|
|
118173
|
+
const pluginDir = (0, import_node_path37.join)(workDir, "plugin");
|
|
116804
118174
|
await runCommand("tar", ["-xzf", pluginTarball, "-C", pluginDir], { ensureDir: pluginDir });
|
|
116805
118175
|
const unpackedPluginDir = await findFirstDirectory(pluginDir);
|
|
116806
|
-
const installer = (0,
|
|
118176
|
+
const installer = (0, import_node_path37.join)(unpackedPluginDir, "scripts", "install-or-upgrade.sh");
|
|
116807
118177
|
console.log(`[${label}] running ${installer}`);
|
|
116808
118178
|
await runCommand("bash", [installer, ...options.restart ? ["--restart"] : []], { cwd: unpackedPluginDir });
|
|
116809
118179
|
await normalizeHermesOkxA2aPluginConfig();
|
|
@@ -116818,7 +118188,7 @@ async function updateHermes(release, options) {
|
|
|
116818
118188
|
}
|
|
116819
118189
|
}
|
|
116820
118190
|
async function installGatewayPluginForDoctor(target) {
|
|
116821
|
-
const release = isPrereleaseVersion("0.2.
|
|
118191
|
+
const release = isPrereleaseVersion("0.2.10-beta-98689bff7a-260826152645") ? "beta" : "latest";
|
|
116822
118192
|
const insideTargetGateway = detectGatewayInvocation() === target;
|
|
116823
118193
|
const options = {
|
|
116824
118194
|
restart: !insideTargetGateway,
|
|
@@ -116869,7 +118239,7 @@ async function ensureHermesOkxA2aPluginConfig(configFile = resolveHermesConfigPa
|
|
|
116869
118239
|
if (options.dryRun) {
|
|
116870
118240
|
return true;
|
|
116871
118241
|
}
|
|
116872
|
-
await (0, import_promises15.mkdir)((0,
|
|
118242
|
+
await (0, import_promises15.mkdir)((0, import_node_path37.resolve)(configFile, ".."), { recursive: true });
|
|
116873
118243
|
await (0, import_promises15.writeFile)(configFile, "plugins:\n enabled:\n - okx-a2a\n");
|
|
116874
118244
|
console.log(`[update] added Hermes plugins.enabled okx-a2a entry in ${configFile}`);
|
|
116875
118245
|
return true;
|
|
@@ -117109,7 +118479,7 @@ function findFirstEnabledListItem(lines, startIndex, enabledIndent) {
|
|
|
117109
118479
|
return null;
|
|
117110
118480
|
}
|
|
117111
118481
|
function resolveHermesConfigPath() {
|
|
117112
|
-
return (0,
|
|
118482
|
+
return (0, import_node_path37.join)(process.env.HERMES_HOME ?? (0, import_node_path37.join)((0, import_node_os14.homedir)(), ".hermes"), "config.yaml");
|
|
117113
118483
|
}
|
|
117114
118484
|
function lineIndent(line) {
|
|
117115
118485
|
const match = line.match(/^\s*/);
|
|
@@ -117187,13 +118557,13 @@ async function assertGatewayPluginInstalled(target) {
|
|
|
117187
118557
|
);
|
|
117188
118558
|
}
|
|
117189
118559
|
function resolveHermesPluginYamlPath() {
|
|
117190
|
-
return (0,
|
|
118560
|
+
return (0, import_node_path37.join)(process.env.HERMES_HOME ?? (0, import_node_path37.join)((0, import_node_os14.homedir)(), ".hermes"), "plugins", "platforms", "okx-a2a", "plugin.yaml");
|
|
117191
118561
|
}
|
|
117192
118562
|
async function isGatewayPluginInstalled(target) {
|
|
117193
118563
|
if (target === "openclaw") {
|
|
117194
118564
|
return (await getInstalledOpenClawPluginInfo()).installed;
|
|
117195
118565
|
}
|
|
117196
|
-
return (0,
|
|
118566
|
+
return (0, import_node_fs32.existsSync)(resolveHermesPluginYamlPath());
|
|
117197
118567
|
}
|
|
117198
118568
|
async function getInstalledGatewayPluginVersion(target) {
|
|
117199
118569
|
if (target === "hermes") {
|
|
@@ -117280,7 +118650,7 @@ function parsePackageVersionFromText(output5) {
|
|
|
117280
118650
|
return output5.match(/@okxweb3\/a2a-openclaw@([0-9A-Za-z.+-]+)/)?.[1] ?? null;
|
|
117281
118651
|
}
|
|
117282
118652
|
async function getInstalledHermesPluginVersion() {
|
|
117283
|
-
const pluginYaml = (0,
|
|
118653
|
+
const pluginYaml = (0, import_node_path37.join)(process.env.HERMES_HOME ?? (0, import_node_path37.join)((0, import_node_os14.homedir)(), ".hermes"), "plugins", "platforms", "okx-a2a", "plugin.yaml");
|
|
117284
118654
|
try {
|
|
117285
118655
|
const content2 = await (0, import_promises15.readFile)(pluginYaml, "utf8");
|
|
117286
118656
|
return parsePluginYamlVersion(content2);
|
|
@@ -117338,7 +118708,7 @@ async function npmPack(spec, destination) {
|
|
|
117338
118708
|
if (!tarballName) {
|
|
117339
118709
|
throw new Error(`Unable to detect npm pack tarball from output: ${output5.trim()}`);
|
|
117340
118710
|
}
|
|
117341
|
-
return (0,
|
|
118711
|
+
return (0, import_node_path37.resolve)(destination, (0, import_node_path37.basename)(tarballName));
|
|
117342
118712
|
}
|
|
117343
118713
|
async function findHermesPluginTarball(distDir) {
|
|
117344
118714
|
const entries = await (0, import_promises15.readdir)(distDir);
|
|
@@ -117346,7 +118716,7 @@ async function findHermesPluginTarball(distDir) {
|
|
|
117346
118716
|
if (!tarball) {
|
|
117347
118717
|
throw new Error(`Hermes npm package did not contain dist/okx-a2a-hermes-plugin-*.tar.gz`);
|
|
117348
118718
|
}
|
|
117349
|
-
return (0,
|
|
118719
|
+
return (0, import_node_path37.join)(distDir, tarball);
|
|
117350
118720
|
}
|
|
117351
118721
|
async function findFirstDirectory(parent) {
|
|
117352
118722
|
const entries = await (0, import_promises15.readdir)(parent, { withFileTypes: true });
|
|
@@ -117354,16 +118724,16 @@ async function findFirstDirectory(parent) {
|
|
|
117354
118724
|
if (!dir) {
|
|
117355
118725
|
throw new Error(`No unpacked plugin directory found under ${parent}`);
|
|
117356
118726
|
}
|
|
117357
|
-
return (0,
|
|
118727
|
+
return (0, import_node_path37.join)(parent, dir.name);
|
|
117358
118728
|
}
|
|
117359
|
-
function
|
|
118729
|
+
function readOption5(args, name) {
|
|
117360
118730
|
const index2 = args.indexOf(name);
|
|
117361
118731
|
if (index2 === -1) {
|
|
117362
118732
|
return void 0;
|
|
117363
118733
|
}
|
|
117364
118734
|
return args[index2 + 1];
|
|
117365
118735
|
}
|
|
117366
|
-
function
|
|
118736
|
+
function hasFlag2(args, name) {
|
|
117367
118737
|
return args.includes(name);
|
|
117368
118738
|
}
|
|
117369
118739
|
function isHelpArg3(value) {
|
|
@@ -117405,7 +118775,7 @@ async function runCommand(command, args, options = {}) {
|
|
|
117405
118775
|
await new Promise((resolvePromise, reject) => {
|
|
117406
118776
|
const invocation = buildExternalCommandInvocation(command, args);
|
|
117407
118777
|
const redirect = redirectCommandStdoutToStderr || options.redirectStdoutToStderr === true;
|
|
117408
|
-
const child = (0,
|
|
118778
|
+
const child = (0, import_node_child_process11.spawn)(invocation.command, invocation.args, {
|
|
117409
118779
|
cwd: options.cwd,
|
|
117410
118780
|
stdio: redirect ? [options.inheritStdin ? "inherit" : "ignore", "pipe", "pipe"] : "inherit",
|
|
117411
118781
|
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
@@ -117449,7 +118819,7 @@ async function runCommand(command, args, options = {}) {
|
|
|
117449
118819
|
async function runCommandCapture(command, args) {
|
|
117450
118820
|
return await new Promise((resolvePromise, reject) => {
|
|
117451
118821
|
const invocation = buildExternalCommandInvocation(command, args);
|
|
117452
|
-
const child = (0,
|
|
118822
|
+
const child = (0, import_node_child_process11.spawn)(invocation.command, invocation.args, {
|
|
117453
118823
|
stdio: ["ignore", "pipe", "pipe"],
|
|
117454
118824
|
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
117455
118825
|
});
|
|
@@ -117482,7 +118852,7 @@ ${stderr}`));
|
|
|
117482
118852
|
async function runCommandCaptureOptional(command, args) {
|
|
117483
118853
|
return await new Promise((resolvePromise) => {
|
|
117484
118854
|
const invocation = buildExternalCommandInvocation(command, args);
|
|
117485
|
-
const child = (0,
|
|
118855
|
+
const child = (0, import_node_child_process11.spawn)(invocation.command, invocation.args, {
|
|
117486
118856
|
stdio: ["ignore", "pipe", "ignore"],
|
|
117487
118857
|
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
117488
118858
|
});
|
|
@@ -117502,7 +118872,7 @@ async function runCommandCaptureOptional(command, args) {
|
|
|
117502
118872
|
async function runCommandCaptureStatus(command, args, options = {}) {
|
|
117503
118873
|
return await new Promise((resolvePromise) => {
|
|
117504
118874
|
const invocation = buildExternalCommandInvocation(command, args);
|
|
117505
|
-
const child = (0,
|
|
118875
|
+
const child = (0, import_node_child_process11.spawn)(invocation.command, invocation.args, {
|
|
117506
118876
|
stdio: ["ignore", "pipe", "pipe"],
|
|
117507
118877
|
windowsVerbatimArguments: invocation.windowsVerbatimArguments
|
|
117508
118878
|
});
|
|
@@ -117575,15 +118945,15 @@ function buildExternalCommandInvocation(command, args, platform = process.platfo
|
|
|
117575
118945
|
function formatExternalCommand(command, args) {
|
|
117576
118946
|
return [command, ...args].join(" ");
|
|
117577
118947
|
}
|
|
117578
|
-
var
|
|
118948
|
+
var import_node_child_process11, import_node_fs32, import_promises15, import_node_os14, 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;
|
|
117579
118949
|
var init_update_cli = __esm({
|
|
117580
118950
|
"src/update-cli.ts"() {
|
|
117581
118951
|
"use strict";
|
|
117582
|
-
|
|
117583
|
-
|
|
118952
|
+
import_node_child_process11 = require("node:child_process");
|
|
118953
|
+
import_node_fs32 = require("node:fs");
|
|
117584
118954
|
import_promises15 = require("node:fs/promises");
|
|
117585
118955
|
import_node_os14 = require("node:os");
|
|
117586
|
-
|
|
118956
|
+
import_node_path37 = require("node:path");
|
|
117587
118957
|
init_ai_command();
|
|
117588
118958
|
init_win_spawn();
|
|
117589
118959
|
init_ai_provider();
|
|
@@ -117871,7 +119241,7 @@ async function runDoctor(options = {}) {
|
|
|
117871
119241
|
platform: options.platform ?? process.platform,
|
|
117872
119242
|
env: options.env ?? process.env,
|
|
117873
119243
|
target: options.target ?? resolveDoctorTarget(options.env ?? process.env),
|
|
117874
|
-
cliVersion: options.cliVersion ?? (true ? "0.2.
|
|
119244
|
+
cliVersion: options.cliVersion ?? (true ? "0.2.10-beta-98689bff7a-260826152645" : "0.0.0"),
|
|
117875
119245
|
fixMode: options.fix === true,
|
|
117876
119246
|
nonInteractive: options.nonInteractive === true,
|
|
117877
119247
|
packageChanged: false,
|
|
@@ -118079,11 +119449,11 @@ async function writeStdoutAndExit(output5, code) {
|
|
|
118079
119449
|
});
|
|
118080
119450
|
process.exit(code);
|
|
118081
119451
|
}
|
|
118082
|
-
var
|
|
119452
|
+
var import_node_path38, DOCTOR_MIN_NODE_VERSION, DOCTOR_DAEMON_READY_TIMEOUT_MS, DOCTOR_DAEMON_WAIT_HEARTBEAT_MS, NODE_PACKAGE_SPEC, CODEX_INSTALL_SPEC, CLAUDE_INSTALL_SPEC, nodeVersionChecker, npmChecker, cliVersionChecker, windowsNativeLauncherChecker, providerBindingChecker, providerCliChecker, gatewayPluginChecker, gatewayConfigChecker, daemonChecker, agentRefreshChecker, gatewayReachableChecker, autostartChecker, CHECKERS, STATUS_MARK;
|
|
118083
119453
|
var init_doctor_cli = __esm({
|
|
118084
119454
|
"src/doctor-cli.ts"() {
|
|
118085
119455
|
"use strict";
|
|
118086
|
-
|
|
119456
|
+
import_node_path38 = require("node:path");
|
|
118087
119457
|
init_log();
|
|
118088
119458
|
init_win_compat();
|
|
118089
119459
|
init_ai_command();
|
|
@@ -118270,7 +119640,7 @@ var init_doctor_cli = __esm({
|
|
|
118270
119640
|
command: "okx-a2a doctor --fix"
|
|
118271
119641
|
},
|
|
118272
119642
|
data: {
|
|
118273
|
-
appDataNpm: ctx.env.APPDATA ? (0,
|
|
119643
|
+
appDataNpm: ctx.env.APPDATA ? (0, import_node_path38.join)(ctx.env.APPDATA, "npm") : null
|
|
118274
119644
|
}
|
|
118275
119645
|
};
|
|
118276
119646
|
},
|
|
@@ -118878,10 +120248,10 @@ var init_doctor_cli = __esm({
|
|
|
118878
120248
|
});
|
|
118879
120249
|
|
|
118880
120250
|
// src/cli.ts
|
|
118881
|
-
var
|
|
118882
|
-
var
|
|
120251
|
+
var import_node_child_process12 = require("node:child_process");
|
|
120252
|
+
var import_node_fs33 = require("node:fs");
|
|
118883
120253
|
var import_node_os15 = require("node:os");
|
|
118884
|
-
var
|
|
120254
|
+
var import_node_path39 = require("node:path");
|
|
118885
120255
|
init_daemon();
|
|
118886
120256
|
init_command_store();
|
|
118887
120257
|
init_file_store();
|
|
@@ -118899,7 +120269,7 @@ init_sentry_config();
|
|
|
118899
120269
|
init_runtime_metadata();
|
|
118900
120270
|
var CURRENT_GATEWAY_SESSION_KEYS_ENV4 = "OKX_A2A_CURRENT_GATEWAY_SESSION_KEYS";
|
|
118901
120271
|
function printUsage3() {
|
|
118902
|
-
console.log(`okx-a2a ${"0.2.
|
|
120272
|
+
console.log(`okx-a2a ${"0.2.10-beta-98689bff7a-260826152645"}
|
|
118903
120273
|
|
|
118904
120274
|
Usage:
|
|
118905
120275
|
okx-a2a <command> [options]
|
|
@@ -118929,6 +120299,7 @@ Commands:
|
|
|
118929
120299
|
Alias for runtime switch-current
|
|
118930
120300
|
job-provider Manage job-to-provider bindings
|
|
118931
120301
|
xmtp-send Queue an XMTP message through the running daemon
|
|
120302
|
+
signal Publish a TradingSignalV1 through configured daemon routes
|
|
118932
120303
|
capabilities Print machine-readable A2A capability negotiation status (used by OnchainOS)
|
|
118933
120304
|
|
|
118934
120305
|
Global options:
|
|
@@ -118939,7 +120310,7 @@ Run \`okx-a2a <command> -h\` for command-specific help.
|
|
|
118939
120310
|
`);
|
|
118940
120311
|
}
|
|
118941
120312
|
function printVersion() {
|
|
118942
|
-
console.log("0.2.
|
|
120313
|
+
console.log("0.2.10-beta-98689bff7a-260826152645");
|
|
118943
120314
|
}
|
|
118944
120315
|
function printDaemonUsage() {
|
|
118945
120316
|
console.log(`Usage: okx-a2a daemon <start|restart|stop|status|autostart> [options]
|
|
@@ -119094,6 +120465,10 @@ function printCommandUsage(command) {
|
|
|
119094
120465
|
printXmtpSendUsage();
|
|
119095
120466
|
return true;
|
|
119096
120467
|
}
|
|
120468
|
+
if (command === "signal") {
|
|
120469
|
+
console.log("Usage: okx-a2a signal publish --service-id <id> (--file <path> | --stdin) [--json]");
|
|
120470
|
+
return true;
|
|
120471
|
+
}
|
|
119097
120472
|
return false;
|
|
119098
120473
|
}
|
|
119099
120474
|
function printUserUsageProxy() {
|
|
@@ -119194,18 +120569,18 @@ function isVersionArg(value) {
|
|
|
119194
120569
|
function hasVersionFlag(args) {
|
|
119195
120570
|
return args.some(isVersionArg);
|
|
119196
120571
|
}
|
|
119197
|
-
function
|
|
120572
|
+
function readOption6(args, name) {
|
|
119198
120573
|
const index2 = args.indexOf(name);
|
|
119199
120574
|
if (index2 === -1) {
|
|
119200
120575
|
return void 0;
|
|
119201
120576
|
}
|
|
119202
120577
|
return args[index2 + 1];
|
|
119203
120578
|
}
|
|
119204
|
-
function
|
|
120579
|
+
function hasFlag3(args, name) {
|
|
119205
120580
|
return args.includes(name);
|
|
119206
120581
|
}
|
|
119207
120582
|
function readLifecycleProviderOption(args) {
|
|
119208
|
-
return
|
|
120583
|
+
return readOption6(args, "--provider") ?? readOption6(args, "--ai-provider");
|
|
119209
120584
|
}
|
|
119210
120585
|
function maybeRedirectDaemonSelfLog() {
|
|
119211
120586
|
if (process.env.OKX_AGENT_TASK_SELF_LOG !== "1") {
|
|
@@ -119213,14 +120588,14 @@ function maybeRedirectDaemonSelfLog() {
|
|
|
119213
120588
|
}
|
|
119214
120589
|
try {
|
|
119215
120590
|
const logPath = resolveTaskPaths().listenerLogPath;
|
|
119216
|
-
(0,
|
|
119217
|
-
const fd = (0,
|
|
120591
|
+
(0, import_node_fs33.mkdirSync)((0, import_node_path39.join)(logPath, ".."), { recursive: true });
|
|
120592
|
+
const fd = (0, import_node_fs33.openSync)(logPath, "a");
|
|
119218
120593
|
const writeToLog = ((chunk, encoding, cb) => {
|
|
119219
120594
|
try {
|
|
119220
120595
|
if (typeof chunk === "string") {
|
|
119221
|
-
(0,
|
|
120596
|
+
(0, import_node_fs33.writeSync)(fd, chunk);
|
|
119222
120597
|
} else {
|
|
119223
|
-
(0,
|
|
120598
|
+
(0, import_node_fs33.writeSync)(fd, chunk);
|
|
119224
120599
|
}
|
|
119225
120600
|
} catch {
|
|
119226
120601
|
}
|
|
@@ -119236,7 +120611,7 @@ function maybeRedirectDaemonSelfLog() {
|
|
|
119236
120611
|
}
|
|
119237
120612
|
}
|
|
119238
120613
|
function shouldInstallAutostart(args) {
|
|
119239
|
-
return !
|
|
120614
|
+
return !hasFlag3(args, "--no-autostart");
|
|
119240
120615
|
}
|
|
119241
120616
|
function printStopDaemonResult(result) {
|
|
119242
120617
|
if (result.stopped) {
|
|
@@ -119287,7 +120662,7 @@ async function tailLogFile(logPath) {
|
|
|
119287
120662
|
fallbackStarted = true;
|
|
119288
120663
|
tailLogFileWithNode(logPath, reason).then(resolve14, reject);
|
|
119289
120664
|
};
|
|
119290
|
-
const child = (0,
|
|
120665
|
+
const child = (0, import_node_child_process12.spawn)("tail", ["-n", "600", "-f", logPath], { stdio: "inherit" });
|
|
119291
120666
|
child.on("error", (error) => {
|
|
119292
120667
|
fallback(`tail_spawn_${error.code ?? "error"}`);
|
|
119293
120668
|
});
|
|
@@ -119320,7 +120695,7 @@ async function handleLogs(args) {
|
|
|
119320
120695
|
return;
|
|
119321
120696
|
}
|
|
119322
120697
|
if (subcommand === "llm") {
|
|
119323
|
-
await tailLogFile((0,
|
|
120698
|
+
await tailLogFile((0, import_node_path39.join)(paths.logsDir, "llm.log"));
|
|
119324
120699
|
return;
|
|
119325
120700
|
}
|
|
119326
120701
|
throw new Error("logs requires <server|llm|export>");
|
|
@@ -119366,15 +120741,15 @@ async function queueXmtpSend(args) {
|
|
|
119366
120741
|
]),
|
|
119367
120742
|
flags: /* @__PURE__ */ new Set(["--json"])
|
|
119368
120743
|
});
|
|
119369
|
-
const json =
|
|
119370
|
-
const explicitJobId =
|
|
119371
|
-
const message =
|
|
119372
|
-
const replyToMessageId =
|
|
119373
|
-
const sessionAgentId =
|
|
119374
|
-
const explicitToAgentId =
|
|
119375
|
-
const sessionKey =
|
|
119376
|
-
const toXmtpAddress =
|
|
119377
|
-
const payloadOverride = parseXmtpSendPayloadOption(
|
|
120744
|
+
const json = hasFlag3(args, "--json");
|
|
120745
|
+
const explicitJobId = readOption6(args, "--job-id");
|
|
120746
|
+
const message = readOption6(args, "--message");
|
|
120747
|
+
const replyToMessageId = readOption6(args, "--reply-to");
|
|
120748
|
+
const sessionAgentId = readOption6(args, "--session-agent-id") ?? process.env.OKX_AGENT_TASK_CURRENT_SESSION_AGENT_ID;
|
|
120749
|
+
const explicitToAgentId = readOption6(args, "--to-agent-id");
|
|
120750
|
+
const sessionKey = readOption6(args, "--session-key");
|
|
120751
|
+
const toXmtpAddress = readOption6(args, "--to-address") ?? readOption6(args, "--to-xmtp-address");
|
|
120752
|
+
const payloadOverride = parseXmtpSendPayloadOption(readOption6(args, "--payload"));
|
|
119378
120753
|
const target = resolveXmtpSendTarget({
|
|
119379
120754
|
sessionKey,
|
|
119380
120755
|
jobId: explicitJobId,
|
|
@@ -119554,8 +120929,8 @@ function assertOnlyKnownOptions(args, input) {
|
|
|
119554
120929
|
}
|
|
119555
120930
|
}
|
|
119556
120931
|
async function queueXmtpDaemonCommand(args, type) {
|
|
119557
|
-
const json =
|
|
119558
|
-
const timeoutMsRaw =
|
|
120932
|
+
const json = hasFlag3(args, "--json");
|
|
120933
|
+
const timeoutMsRaw = readOption6(args, "--timeout-ms");
|
|
119559
120934
|
const wait3 = type === "xmtp-get-pending-list" || type === "xmtp-deny-pending-conversation" || type === "xmtp-refresh-agents";
|
|
119560
120935
|
await assertDaemonRunningForQueuedCommand2(type);
|
|
119561
120936
|
const commands = new CommandStore();
|
|
@@ -119635,8 +121010,8 @@ async function handleAgentCommand(args) {
|
|
|
119635
121010
|
throw new Error("agent requires <refresh|bypass>");
|
|
119636
121011
|
}
|
|
119637
121012
|
function handleAgentBypassCommand(args) {
|
|
119638
|
-
const json =
|
|
119639
|
-
const rawMode =
|
|
121013
|
+
const json = hasFlag3(args, "--json");
|
|
121014
|
+
const rawMode = readOption6(args, "--mode") ?? args.find((arg) => !arg.startsWith("--"));
|
|
119640
121015
|
const store = new SessionStore();
|
|
119641
121016
|
try {
|
|
119642
121017
|
if (rawMode) {
|
|
@@ -119668,16 +121043,16 @@ function outputAgentBypass(json, enabled) {
|
|
|
119668
121043
|
console.log(`AI bypass permissions: ${enabled ? "on" : "off"}`);
|
|
119669
121044
|
}
|
|
119670
121045
|
function readRequiredOption4(args, name) {
|
|
119671
|
-
const value =
|
|
121046
|
+
const value = readOption6(args, name);
|
|
119672
121047
|
if (!value) {
|
|
119673
121048
|
throw new Error(`${name} is required`);
|
|
119674
121049
|
}
|
|
119675
121050
|
return value;
|
|
119676
121051
|
}
|
|
119677
121052
|
function readDenyPendingConversationOptions(args) {
|
|
119678
|
-
const jobId =
|
|
119679
|
-
const groupId =
|
|
119680
|
-
const agentId =
|
|
121053
|
+
const jobId = readOption6(args, "--job-id");
|
|
121054
|
+
const groupId = readOption6(args, "--group-id");
|
|
121055
|
+
const agentId = readOption6(args, "--agent-id");
|
|
119681
121056
|
const content2 = readOptionalNonEmptyOption(args, "--content", "task reject --content");
|
|
119682
121057
|
if (jobId) {
|
|
119683
121058
|
if (groupId || agentId) {
|
|
@@ -119695,10 +121070,10 @@ function readDenyPendingConversationOptions(args) {
|
|
|
119695
121070
|
};
|
|
119696
121071
|
}
|
|
119697
121072
|
function readOptionalNonEmptyOption(args, name, label) {
|
|
119698
|
-
if (!
|
|
121073
|
+
if (!hasFlag3(args, name)) {
|
|
119699
121074
|
return void 0;
|
|
119700
121075
|
}
|
|
119701
|
-
const value =
|
|
121076
|
+
const value = readOption6(args, name);
|
|
119702
121077
|
if (value === void 0 || value.trim().length === 0) {
|
|
119703
121078
|
throw new Error(`${label} requires a non-empty string`);
|
|
119704
121079
|
}
|
|
@@ -119970,7 +121345,7 @@ async function handleAiProvider(args) {
|
|
|
119970
121345
|
return;
|
|
119971
121346
|
}
|
|
119972
121347
|
const subcommand = args[0] ?? "status";
|
|
119973
|
-
const json =
|
|
121348
|
+
const json = hasFlag3(args, "--json");
|
|
119974
121349
|
const store = new SessionStore();
|
|
119975
121350
|
try {
|
|
119976
121351
|
if (subcommand === "status") {
|
|
@@ -119986,7 +121361,7 @@ async function handleAiProvider(args) {
|
|
|
119986
121361
|
return;
|
|
119987
121362
|
}
|
|
119988
121363
|
if (subcommand === "set") {
|
|
119989
|
-
const rawProvider =
|
|
121364
|
+
const rawProvider = readOption6(args, "--provider") ?? args[1];
|
|
119990
121365
|
if (!rawProvider) {
|
|
119991
121366
|
throw new Error("ai-provider set requires --provider <codex|claude|hermes|openclaw>");
|
|
119992
121367
|
}
|
|
@@ -120043,7 +121418,7 @@ async function handleRuntimeSwitch(args) {
|
|
|
120043
121418
|
options: /* @__PURE__ */ new Set(),
|
|
120044
121419
|
flags: /* @__PURE__ */ new Set(["--json"])
|
|
120045
121420
|
});
|
|
120046
|
-
const json =
|
|
121421
|
+
const json = hasFlag3(args, "--json");
|
|
120047
121422
|
const store = new SessionStore();
|
|
120048
121423
|
try {
|
|
120049
121424
|
const result = await performRuntimeSwitch(store);
|
|
@@ -120097,7 +121472,7 @@ async function handleJobProvider(args) {
|
|
|
120097
121472
|
}
|
|
120098
121473
|
const subcommand = args[0] ?? "get";
|
|
120099
121474
|
const rest = args.slice(1);
|
|
120100
|
-
const json =
|
|
121475
|
+
const json = hasFlag3(rest, "--json");
|
|
120101
121476
|
const store = new SessionStore();
|
|
120102
121477
|
try {
|
|
120103
121478
|
if (subcommand === "get") {
|
|
@@ -120129,7 +121504,7 @@ async function handleJobProvider(args) {
|
|
|
120129
121504
|
}
|
|
120130
121505
|
if (subcommand === "unset") {
|
|
120131
121506
|
const jobId = readRequiredOption4(rest, "--job-id");
|
|
120132
|
-
const expectedProviderRaw =
|
|
121507
|
+
const expectedProviderRaw = readOption6(rest, "--provider");
|
|
120133
121508
|
const expectedProvider = expectedProviderRaw ? normalizeAiProvider(expectedProviderRaw) : null;
|
|
120134
121509
|
const existing = store.getJobProviderBinding(jobId);
|
|
120135
121510
|
const providerMatched = !!existing && (!expectedProvider || existing.provider === expectedProvider);
|
|
@@ -120168,9 +121543,9 @@ async function handleJobProvider(args) {
|
|
|
120168
121543
|
return;
|
|
120169
121544
|
}
|
|
120170
121545
|
if (subcommand === "list") {
|
|
120171
|
-
const rawProvider =
|
|
121546
|
+
const rawProvider = readOption6(rest, "--provider");
|
|
120172
121547
|
const provider = rawProvider ? normalizeAiProvider(rawProvider) : void 0;
|
|
120173
|
-
const rawLimit =
|
|
121548
|
+
const rawLimit = readOption6(rest, "--limit");
|
|
120174
121549
|
const limit = rawLimit ? Number(rawLimit) : void 0;
|
|
120175
121550
|
const bindings = store.listJobProviderBindings({ provider, limit });
|
|
120176
121551
|
if (json) {
|
|
@@ -120190,7 +121565,7 @@ async function handleJobProvider(args) {
|
|
|
120190
121565
|
async function handleConfig(args) {
|
|
120191
121566
|
const subcommand = args[0];
|
|
120192
121567
|
const configArgs = args.slice(1);
|
|
120193
|
-
const json =
|
|
121568
|
+
const json = hasFlag3(args, "--json");
|
|
120194
121569
|
if (!subcommand || hasHelpFlag5(args)) {
|
|
120195
121570
|
printConfigUsage();
|
|
120196
121571
|
return;
|
|
@@ -120202,7 +121577,7 @@ async function handleConfig(args) {
|
|
|
120202
121577
|
if (subcommand !== "provider") {
|
|
120203
121578
|
throw new Error(`Unknown config command: ${subcommand}`);
|
|
120204
121579
|
}
|
|
120205
|
-
const rawProvider =
|
|
121580
|
+
const rawProvider = readOption6(configArgs, "--provider") ?? configArgs.find((arg) => !arg.startsWith("--"));
|
|
120206
121581
|
if (json && !rawProvider) {
|
|
120207
121582
|
throw new Error("config provider --json requires --provider <codex|claude|hermes|openclaw>");
|
|
120208
121583
|
}
|
|
@@ -120241,7 +121616,7 @@ Commands:
|
|
|
120241
121616
|
}
|
|
120242
121617
|
function handleConfigPermissions(args, json) {
|
|
120243
121618
|
const paths = resolveTaskPaths();
|
|
120244
|
-
const rawPreset =
|
|
121619
|
+
const rawPreset = readOption6(args, "--preset") ?? args.find((arg) => !arg.startsWith("--"));
|
|
120245
121620
|
const configPath = resolveTaskConfigPath(paths.homeDir);
|
|
120246
121621
|
if (rawPreset) {
|
|
120247
121622
|
const preset2 = writeAiPermissionPresetToConfig(paths.homeDir, rawPreset);
|
|
@@ -120279,11 +121654,11 @@ async function initDirectCliSentry() {
|
|
|
120279
121654
|
}
|
|
120280
121655
|
cliSentryInitAttempted = true;
|
|
120281
121656
|
try {
|
|
120282
|
-
const configPath = (0,
|
|
120283
|
-
if (!(0,
|
|
121657
|
+
const configPath = (0, import_node_path39.join)(resolveTaskHomeForSentryConfig(), "xmtp", "system-config.json");
|
|
121658
|
+
if (!(0, import_node_fs33.existsSync)(configPath)) {
|
|
120284
121659
|
return;
|
|
120285
121660
|
}
|
|
120286
|
-
const config = JSON.parse((0,
|
|
121661
|
+
const config = JSON.parse((0, import_node_fs33.readFileSync)(configPath, "utf8"));
|
|
120287
121662
|
if (typeof config.sentryDsn !== "string" || !config.sentryDsn) {
|
|
120288
121663
|
return;
|
|
120289
121664
|
}
|
|
@@ -120308,11 +121683,11 @@ function resolveTaskHomeForSentryConfig() {
|
|
|
120308
121683
|
try {
|
|
120309
121684
|
const home = (0, import_node_os15.homedir)();
|
|
120310
121685
|
if (home) {
|
|
120311
|
-
return (0,
|
|
121686
|
+
return (0, import_node_path39.join)(home, ".okx-agent-task");
|
|
120312
121687
|
}
|
|
120313
121688
|
} catch {
|
|
120314
121689
|
}
|
|
120315
|
-
return (0,
|
|
121690
|
+
return (0, import_node_path39.resolve)(process.cwd(), ".okx-agent-task");
|
|
120316
121691
|
}
|
|
120317
121692
|
function directCliSentryExtra(operation, extra = {}) {
|
|
120318
121693
|
return {
|
|
@@ -120420,7 +121795,7 @@ async function main() {
|
|
|
120420
121795
|
if (command === "xmtp-test") {
|
|
120421
121796
|
const { handleXmtpTestCommand: handleXmtpTestCommand2 } = await Promise.resolve().then(() => (init_xmtp_test_cli(), xmtp_test_cli_exports));
|
|
120422
121797
|
await handleXmtpTestCommand2(process.argv.slice(3), {
|
|
120423
|
-
packageVersion: "0.2.
|
|
121798
|
+
packageVersion: "0.2.10-beta-98689bff7a-260826152645",
|
|
120424
121799
|
agentSdkVersion: "2.3.0",
|
|
120425
121800
|
nodeSdkVersion: "6.1.0",
|
|
120426
121801
|
nodeBindingsVersion: "1.11.0"
|
|
@@ -120433,6 +121808,13 @@ async function main() {
|
|
|
120433
121808
|
await flushDirectCliSentry();
|
|
120434
121809
|
return;
|
|
120435
121810
|
}
|
|
121811
|
+
if (command === "signal") {
|
|
121812
|
+
await initDirectCliSentry();
|
|
121813
|
+
const { handleSignalCommand: handleSignalCommand2 } = await Promise.resolve().then(() => (init_cli(), cli_exports));
|
|
121814
|
+
await handleSignalCommand2(process.argv.slice(3));
|
|
121815
|
+
await flushDirectCliSentry();
|
|
121816
|
+
return;
|
|
121817
|
+
}
|
|
120436
121818
|
if (command === "task") {
|
|
120437
121819
|
await initDirectCliSentry();
|
|
120438
121820
|
await handleTaskCommand(process.argv.slice(3));
|
|
@@ -120525,7 +121907,7 @@ function shouldDeferHelpToNestedHandler(command, args) {
|
|
|
120525
121907
|
if (command === "xmtp-test") {
|
|
120526
121908
|
return true;
|
|
120527
121909
|
}
|
|
120528
|
-
if (command !== "session" && command !== "user" && command !== "task") {
|
|
121910
|
+
if (command !== "session" && command !== "user" && command !== "task" && command !== "signal") {
|
|
120529
121911
|
return false;
|
|
120530
121912
|
}
|
|
120531
121913
|
return args.some((arg) => !isHelpArg4(arg));
|