@okxweb3/a2a-node 0.1.9 → 0.1.10-beta-114515ea34-260721221928
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 +0 -1
- package/dist/cli.js +38 -532
- package/dist/index.js +34 -529
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -8302,7 +8302,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
8302
8302
|
client: {
|
|
8303
8303
|
id: "gateway-client",
|
|
8304
8304
|
displayName: "okx-a2a-node",
|
|
8305
|
-
version: "0.1.
|
|
8305
|
+
version: "0.1.10-beta-114515ea34-260721221928",
|
|
8306
8306
|
platform: "node",
|
|
8307
8307
|
mode: "backend",
|
|
8308
8308
|
instanceId
|
|
@@ -8313,7 +8313,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
8313
8313
|
commands: [],
|
|
8314
8314
|
permissions: {},
|
|
8315
8315
|
locale: Intl.DateTimeFormat().resolvedOptions().locale || "en-US",
|
|
8316
|
-
userAgent: `okx-a2a-node/${"0.1.
|
|
8316
|
+
userAgent: `okx-a2a-node/${"0.1.10-beta-114515ea34-260721221928"}`,
|
|
8317
8317
|
auth: {
|
|
8318
8318
|
...config.token ? { token: config.token } : {},
|
|
8319
8319
|
...config.password ? { password: config.password } : {}
|
|
@@ -24327,9 +24327,7 @@ var init_events = __esm({
|
|
|
24327
24327
|
OUTBOUND_ELIGIBILITY_CHECKED: "Outbound eligibility checked",
|
|
24328
24328
|
AGENT_CLIENT_CREATED: "Agent client created",
|
|
24329
24329
|
AGENT_CLIENT_REMOVED: "Agent client removed",
|
|
24330
|
-
ADDRESS_SYNC_COMPLETED: "Address sync completed",
|
|
24331
24330
|
AGENT_REFRESH_SESSION_EXPIRED: "Agent refresh aborted: onchainos session expired, local clients taken offline",
|
|
24332
|
-
OFFLINE_REPLAY_MESSAGE_REPLAYED: "Offline replay message replayed",
|
|
24333
24331
|
AGENTS_WAKEUP_NOTIFIED: "Agents wakeup notified",
|
|
24334
24332
|
CONFIG_SENSITIVE_WORDS_REFRESHED: "Sensitive words config refreshed",
|
|
24335
24333
|
CONFIG_SYSTEM_REFRESHED: "System config refreshed",
|
|
@@ -24360,7 +24358,6 @@ var init_events = __esm({
|
|
|
24360
24358
|
HEARTBEAT_GATEWAY_CHECK_FAILED: "Heartbeat gateway check failed",
|
|
24361
24359
|
MESSAGE_PARSE_FAILED: "Message parse failed",
|
|
24362
24360
|
MESSAGE_HANDLER_ERROR: "Message handler error",
|
|
24363
|
-
OFFLINE_REPLAY_FAILED: "Offline replay failed",
|
|
24364
24361
|
INBOUND_ROUTING_FAILED: "Inbound routing failed",
|
|
24365
24362
|
CONVERSATION_NOT_FOUND: "Conversation not found for send",
|
|
24366
24363
|
XMTP_SEND_FAILED: "XMTP send failed",
|
|
@@ -24375,7 +24372,6 @@ var init_events = __esm({
|
|
|
24375
24372
|
INBOUND_SENSITIVE_CHECK_FAILED: "Inbound sensitive check failed",
|
|
24376
24373
|
FILE_UPLOAD_FAILED: "File upload failed",
|
|
24377
24374
|
FILE_DOWNLOAD_FAILED: "File download failed",
|
|
24378
|
-
OFFLINE_REPLAY_MESSAGE_FAILED: "Offline replay message failed",
|
|
24379
24375
|
PENDING_NOTIFICATION_FAILED: "Pending notification failed",
|
|
24380
24376
|
GATEWAY_CONNECT_FAILED: "Gateway connect failed",
|
|
24381
24377
|
GATEWAY_REQUEST_FAILED: "Gateway request failed",
|
|
@@ -24590,7 +24586,6 @@ var init_sentry_logger = __esm({
|
|
|
24590
24586
|
LogEvent.MESSAGE_SENT,
|
|
24591
24587
|
LogEvent.AGENT_CLIENT_CREATED,
|
|
24592
24588
|
LogEvent.AGENT_CLIENT_REMOVED,
|
|
24593
|
-
LogEvent.ADDRESS_SYNC_COMPLETED,
|
|
24594
24589
|
LogEvent.AGENTS_REFRESHED,
|
|
24595
24590
|
LogEvent.AGENTS_WAKEUP_NOTIFIED,
|
|
24596
24591
|
LogEvent.AGENT_LIST_QUERIED,
|
|
@@ -24603,7 +24598,6 @@ var init_sentry_logger = __esm({
|
|
|
24603
24598
|
LogEvent.GROUP_CONSENT_CHANGED,
|
|
24604
24599
|
LogEvent.INBOUND_HANDLER_ENTERED,
|
|
24605
24600
|
LogEvent.MESSAGE_RECEIVED,
|
|
24606
|
-
LogEvent.OFFLINE_REPLAY_MESSAGE_REPLAYED,
|
|
24607
24601
|
LogEvent.AGENT_REFRESH_SESSION_EXPIRED,
|
|
24608
24602
|
LogEvent.OUTBOUND_ELIGIBILITY_CHECKED,
|
|
24609
24603
|
LogEvent.OUTBOUND_BLOCKED_INELIGIBLE,
|
|
@@ -25584,7 +25578,7 @@ var init_sentry_config = __esm({
|
|
|
25584
25578
|
environment = process.env.SENTRY_ENV === "dev" ? "dev" : "prod";
|
|
25585
25579
|
SENTRY_CONFIG = {
|
|
25586
25580
|
projectName: "okx/openclaw-okx-a2a-extension",
|
|
25587
|
-
release: "0.1.
|
|
25581
|
+
release: "0.1.10-beta-114515ea34-260721221928",
|
|
25588
25582
|
environment,
|
|
25589
25583
|
runtimeContainer: normalizeRuntimeContainer(process.env.OKX_A2A_RUNTIME_CONTAINER)
|
|
25590
25584
|
};
|
|
@@ -71171,6 +71165,23 @@ var init_dist4 = __esm({
|
|
|
71171
71165
|
}
|
|
71172
71166
|
});
|
|
71173
71167
|
|
|
71168
|
+
// ../core/src/xmtp-sdk/middleware/self-filter.ts
|
|
71169
|
+
function selfFilterMiddleware() {
|
|
71170
|
+
return async (ctx, next) => {
|
|
71171
|
+
const ownInboxId = ctx.client?.inboxId;
|
|
71172
|
+
const senderInboxId = ctx.message?.senderInboxId;
|
|
71173
|
+
if (ownInboxId && senderInboxId && String(senderInboxId).toLowerCase() === String(ownInboxId).toLowerCase()) {
|
|
71174
|
+
return;
|
|
71175
|
+
}
|
|
71176
|
+
await next();
|
|
71177
|
+
};
|
|
71178
|
+
}
|
|
71179
|
+
var init_self_filter = __esm({
|
|
71180
|
+
"../core/src/xmtp-sdk/middleware/self-filter.ts"() {
|
|
71181
|
+
"use strict";
|
|
71182
|
+
}
|
|
71183
|
+
});
|
|
71184
|
+
|
|
71174
71185
|
// ../core/src/xmtp-sdk/extract-job-id.ts
|
|
71175
71186
|
function extractJobIdFromContent(content3) {
|
|
71176
71187
|
const raw = typeof content3 === "string" ? content3 : JSON.stringify(content3) ?? "";
|
|
@@ -71209,23 +71220,6 @@ var init_extract_job_id = __esm({
|
|
|
71209
71220
|
}
|
|
71210
71221
|
});
|
|
71211
71222
|
|
|
71212
|
-
// ../core/src/xmtp-sdk/middleware/self-filter.ts
|
|
71213
|
-
function selfFilterMiddleware() {
|
|
71214
|
-
return async (ctx, next) => {
|
|
71215
|
-
const ownInboxId = ctx.client?.inboxId;
|
|
71216
|
-
const senderInboxId = ctx.message?.senderInboxId;
|
|
71217
|
-
if (ownInboxId && senderInboxId && String(senderInboxId).toLowerCase() === String(ownInboxId).toLowerCase()) {
|
|
71218
|
-
return;
|
|
71219
|
-
}
|
|
71220
|
-
await next();
|
|
71221
|
-
};
|
|
71222
|
-
}
|
|
71223
|
-
var init_self_filter = __esm({
|
|
71224
|
-
"../core/src/xmtp-sdk/middleware/self-filter.ts"() {
|
|
71225
|
-
"use strict";
|
|
71226
|
-
}
|
|
71227
|
-
});
|
|
71228
|
-
|
|
71229
71223
|
// ../core/src/xmtp-sdk/inbound-timing.ts
|
|
71230
71224
|
function createInboundTimingTracker(xmtpSentAtMs, xmtpReceivedAtMs = Date.now()) {
|
|
71231
71225
|
const durations = {};
|
|
@@ -85374,57 +85368,6 @@ async function loadSystemConfigWith(dataDir, fetcher) {
|
|
|
85374
85368
|
});
|
|
85375
85369
|
return null;
|
|
85376
85370
|
}
|
|
85377
|
-
function loadSyncByAddress(dataDir) {
|
|
85378
|
-
const map = /* @__PURE__ */ new Map();
|
|
85379
|
-
try {
|
|
85380
|
-
const path = cachePath(dataDir, "last-sync.json");
|
|
85381
|
-
if (!(0, import_node_fs15.existsSync)(path)) {
|
|
85382
|
-
return map;
|
|
85383
|
-
}
|
|
85384
|
-
const data = JSON.parse((0, import_node_fs15.readFileSync)(path, "utf-8"));
|
|
85385
|
-
const obj = data?.syncByAddress;
|
|
85386
|
-
if (obj && typeof obj === "object" && !Array.isArray(obj)) {
|
|
85387
|
-
for (const [addr, ts] of Object.entries(obj)) {
|
|
85388
|
-
if (typeof ts === "number" && ts > 0) {
|
|
85389
|
-
map.set(addr, ts);
|
|
85390
|
-
}
|
|
85391
|
-
}
|
|
85392
|
-
}
|
|
85393
|
-
} catch (err2) {
|
|
85394
|
-
logWithTimestamp("[xmtp-sdk] failed to read last-sync.json cache:", err2);
|
|
85395
|
-
logger.error(LogEvent.CACHE_LOAD_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), { cacheName: "last-sync" });
|
|
85396
|
-
}
|
|
85397
|
-
return map;
|
|
85398
|
-
}
|
|
85399
|
-
function saveSyncForAddress(dataDir, address, timestampMs) {
|
|
85400
|
-
try {
|
|
85401
|
-
let data = {};
|
|
85402
|
-
const path = cachePath(dataDir, "last-sync.json");
|
|
85403
|
-
if ((0, import_node_fs15.existsSync)(path)) {
|
|
85404
|
-
try {
|
|
85405
|
-
const raw = JSON.parse((0, import_node_fs15.readFileSync)(path, "utf-8"));
|
|
85406
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
85407
|
-
data = raw;
|
|
85408
|
-
}
|
|
85409
|
-
} catch {
|
|
85410
|
-
}
|
|
85411
|
-
}
|
|
85412
|
-
if (!data.syncByAddress || typeof data.syncByAddress !== "object") {
|
|
85413
|
-
data.syncByAddress = {};
|
|
85414
|
-
}
|
|
85415
|
-
data.syncByAddress[address] = timestampMs;
|
|
85416
|
-
(0, import_node_fs15.writeFileSync)(path, JSON.stringify(data, null, 2));
|
|
85417
|
-
} catch (err2) {
|
|
85418
|
-
logWithTimestamp(
|
|
85419
|
-
`[xmtp-sdk] failed to write last-sync.json (address=${address}):`,
|
|
85420
|
-
err2
|
|
85421
|
-
);
|
|
85422
|
-
logger.error(LogEvent.CACHE_WRITE_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), {
|
|
85423
|
-
cacheName: "last-sync",
|
|
85424
|
-
walletAddress: address
|
|
85425
|
-
});
|
|
85426
|
-
}
|
|
85427
|
-
}
|
|
85428
85371
|
function formatFileTooLargeMessage(maxFileSizeBytes) {
|
|
85429
85372
|
const mb = Math.max(1, Math.floor(maxFileSizeBytes / 1024 / 1024));
|
|
85430
85373
|
return `This file is too large to process directly (current limit is ${mb}MB per file). Try sharing it another way:
|
|
@@ -85542,7 +85485,6 @@ function parseSystemConfig(raw) {
|
|
|
85542
85485
|
}, []) : [];
|
|
85543
85486
|
return {
|
|
85544
85487
|
heartbeatInterval: typeof raw.heartbeatInterval === "number" ? raw.heartbeatInterval : SYSTEM_CONFIG_DEFAULTS.heartbeatInterval,
|
|
85545
|
-
offlineReplayInterval: typeof raw.offlineReplayInterval === "number" && Number.isFinite(raw.offlineReplayInterval) && raw.offlineReplayInterval > 0 ? raw.offlineReplayInterval : SYSTEM_CONFIG_DEFAULTS.offlineReplayInterval,
|
|
85546
85488
|
xmtpClientRecycleInterval: typeof raw.xmtpClientRecycleInterval === "number" && Number.isFinite(raw.xmtpClientRecycleInterval) && raw.xmtpClientRecycleInterval > 0 ? raw.xmtpClientRecycleInterval : SYSTEM_CONFIG_DEFAULTS.xmtpClientRecycleInterval,
|
|
85547
85489
|
maxFileSizeBytes: typeof raw.maxFileSizeBytes === "number" && Number.isFinite(raw.maxFileSizeBytes) && raw.maxFileSizeBytes > 0 ? raw.maxFileSizeBytes : SYSTEM_CONFIG_DEFAULTS.maxFileSizeBytes,
|
|
85548
85490
|
sensitiveUploadReg: parseStringArray(raw.SENSITIVE_UPLOAD_REG),
|
|
@@ -85595,23 +85537,6 @@ function parseGroupPayload(content3) {
|
|
|
85595
85537
|
function isAgentUnavailable(agent) {
|
|
85596
85538
|
return isAgentXmtpBlocked(agent);
|
|
85597
85539
|
}
|
|
85598
|
-
function createOfflineReplayAddressSummary(address) {
|
|
85599
|
-
return {
|
|
85600
|
-
address,
|
|
85601
|
-
replayed: 0,
|
|
85602
|
-
skipped: 0,
|
|
85603
|
-
conversations: 0,
|
|
85604
|
-
conversationsWithMessages: 0,
|
|
85605
|
-
conversationsWithMissedMessages: 0,
|
|
85606
|
-
emptyConversations: 0,
|
|
85607
|
-
selfOnlyConversations: 0,
|
|
85608
|
-
syncAllMs: 0,
|
|
85609
|
-
listMs: 0,
|
|
85610
|
-
messagesMs: 0,
|
|
85611
|
-
handleMs: 0,
|
|
85612
|
-
durationMs: 0
|
|
85613
|
-
};
|
|
85614
|
-
}
|
|
85615
85540
|
var import_node_fs15, import_node_path19, DEFAULT_DATA_DIR, SENSITIVE_WORDS_LAZY_RETRY_COOLDOWN_MS, SESSION_EXPIRED_RE, SYSTEM_CONFIG_DEFAULTS, SEMVER_RE, isRecord2, isPositiveNumber, SYSTEM_CONFIG_VALIDATORS, SENDER_BLACKLISTED_MESSAGE, RECIPIENT_BLACKLISTED_MESSAGE, XmtpService;
|
|
85616
85541
|
var init_xmtp_sdk = __esm({
|
|
85617
85542
|
"../core/src/xmtp-sdk/index.ts"() {
|
|
@@ -85621,7 +85546,6 @@ var init_xmtp_sdk = __esm({
|
|
|
85621
85546
|
import_node_path19 = require("node:path");
|
|
85622
85547
|
init_dist4();
|
|
85623
85548
|
init_sentry_logger();
|
|
85624
|
-
init_extract_job_id();
|
|
85625
85549
|
init_self_filter();
|
|
85626
85550
|
init_logging();
|
|
85627
85551
|
init_sensitive_word();
|
|
@@ -85634,7 +85558,6 @@ var init_xmtp_sdk = __esm({
|
|
|
85634
85558
|
SESSION_EXPIRED_RE = /session expired/i;
|
|
85635
85559
|
SYSTEM_CONFIG_DEFAULTS = {
|
|
85636
85560
|
heartbeatInterval: 60,
|
|
85637
|
-
offlineReplayInterval: 300,
|
|
85638
85561
|
xmtpClientRecycleInterval: 6 * 60 * 60,
|
|
85639
85562
|
maxFileSizeBytes: 100 * 1024 * 1024,
|
|
85640
85563
|
sensitiveUploadReg: [],
|
|
@@ -85649,7 +85572,6 @@ var init_xmtp_sdk = __esm({
|
|
|
85649
85572
|
isPositiveNumber = (value) => typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
85650
85573
|
SYSTEM_CONFIG_VALIDATORS = {
|
|
85651
85574
|
heartbeatInterval: isPositiveNumber,
|
|
85652
|
-
offlineReplayInterval: isPositiveNumber,
|
|
85653
85575
|
xmtpClientRecycleInterval: isPositiveNumber,
|
|
85654
85576
|
maxFileSizeBytes: isPositiveNumber,
|
|
85655
85577
|
SENSITIVE_UPLOAD_REG: (value) => Array.isArray(value) && value.every((item) => typeof item === "string"),
|
|
@@ -85691,7 +85613,6 @@ var init_xmtp_sdk = __esm({
|
|
|
85691
85613
|
minVersion: ""
|
|
85692
85614
|
};
|
|
85693
85615
|
dataDir = DEFAULT_DATA_DIR;
|
|
85694
|
-
syncByAddress = /* @__PURE__ */ new Map();
|
|
85695
85616
|
agentListFingerprint;
|
|
85696
85617
|
// Only one refreshAgents can be in flight at a time; concurrent calls
|
|
85697
85618
|
// coalesce onto the same promise. This avoids duplicate Agent.create()
|
|
@@ -85760,10 +85681,7 @@ var init_xmtp_sdk = __esm({
|
|
|
85760
85681
|
this._onAfterInitError = null;
|
|
85761
85682
|
this._backupReady = afterInit ? afterInit().catch((err2) => {
|
|
85762
85683
|
this._onAfterInitError = err2 instanceof Error ? err2 : new Error(String(err2));
|
|
85763
|
-
logWithTimestamp(
|
|
85764
|
-
"[xmtp-sdk] tools.onAfterInit failed (will retry on first use):",
|
|
85765
|
-
err2
|
|
85766
|
-
);
|
|
85684
|
+
logWithTimestamp("[xmtp-sdk] tools.onAfterInit failed:", err2);
|
|
85767
85685
|
}) : Promise.resolve();
|
|
85768
85686
|
if (sensitiveWordsResult.status === "fulfilled" && sensitiveWordsResult.value !== null) {
|
|
85769
85687
|
this.sensitiveWords = sensitiveWordsResult.value;
|
|
@@ -85861,10 +85779,6 @@ var init_xmtp_sdk = __esm({
|
|
|
85861
85779
|
);
|
|
85862
85780
|
return this.clients;
|
|
85863
85781
|
}
|
|
85864
|
-
this.syncByAddress = loadSyncByAddress(this.dataDir);
|
|
85865
|
-
logWithTimestamp(
|
|
85866
|
-
`[xmtp-sdk] sync timestamps: ${this.syncByAddress.size} addresses on record`
|
|
85867
|
-
);
|
|
85868
85782
|
if (!this.tools.listAllAgentsWithMetadata) {
|
|
85869
85783
|
throw new Error("tools.listAllAgentsWithMetadata is required");
|
|
85870
85784
|
}
|
|
@@ -86192,25 +86106,6 @@ var init_xmtp_sdk = __esm({
|
|
|
86192
86106
|
await this.startListeningForAddresses(
|
|
86193
86107
|
added.map((a) => a.communicationAddress)
|
|
86194
86108
|
);
|
|
86195
|
-
for (const agentInfo of added) {
|
|
86196
|
-
const address = agentInfo.communicationAddress;
|
|
86197
|
-
if (this.syncByAddress.has(address) && this.clients.has(address)) {
|
|
86198
|
-
logWithTimestamp(
|
|
86199
|
-
`[xmtp-sdk] refresh: ${address} has a prior sync timestamp, triggering offline replay`
|
|
86200
|
-
);
|
|
86201
|
-
this.replayOfflineMessagesForAddress(address).catch((err2) => {
|
|
86202
|
-
logWithTimestamp(`[xmtp-sdk] refresh: ${address} offline replay failed:`, err2);
|
|
86203
|
-
logger.error(
|
|
86204
|
-
LogEvent.OFFLINE_REPLAY_FAILED,
|
|
86205
|
-
err2 instanceof Error ? err2 : new Error(String(err2)),
|
|
86206
|
-
{
|
|
86207
|
-
walletAddress: address,
|
|
86208
|
-
stage: "refreshAgents/replay"
|
|
86209
|
-
}
|
|
86210
|
-
);
|
|
86211
|
-
});
|
|
86212
|
-
}
|
|
86213
|
-
}
|
|
86214
86109
|
}
|
|
86215
86110
|
return {
|
|
86216
86111
|
added: added.map((a) => `${a.agentId} (${a.communicationAddress})`),
|
|
@@ -86222,11 +86117,8 @@ var init_xmtp_sdk = __esm({
|
|
|
86222
86117
|
async recycleXmtpClients() {
|
|
86223
86118
|
await this._backupReady;
|
|
86224
86119
|
const startedAt = Date.now();
|
|
86225
|
-
const addresses = [];
|
|
86226
86120
|
let recycled = 0;
|
|
86227
86121
|
let failed = 0;
|
|
86228
|
-
let replayed = 0;
|
|
86229
|
-
let skipped2 = 0;
|
|
86230
86122
|
if (!this.tools.createSigner) {
|
|
86231
86123
|
throw new Error("tools.createSigner is required");
|
|
86232
86124
|
}
|
|
@@ -86281,10 +86173,6 @@ var init_xmtp_sdk = __esm({
|
|
|
86281
86173
|
phase: "recycle"
|
|
86282
86174
|
});
|
|
86283
86175
|
await this.startListeningForAddresses([address]);
|
|
86284
|
-
const replaySummary = await this.replayOfflineMessagesForAddress(address);
|
|
86285
|
-
addresses.push(replaySummary);
|
|
86286
|
-
replayed += replaySummary.replayed;
|
|
86287
|
-
skipped2 += replaySummary.skipped;
|
|
86288
86176
|
recycled++;
|
|
86289
86177
|
} catch (err2) {
|
|
86290
86178
|
failed++;
|
|
@@ -86305,10 +86193,7 @@ var init_xmtp_sdk = __esm({
|
|
|
86305
86193
|
clients: this.clients.size,
|
|
86306
86194
|
recycled,
|
|
86307
86195
|
failed,
|
|
86308
|
-
|
|
86309
|
-
skipped: skipped2,
|
|
86310
|
-
durationMs: Date.now() - startedAt,
|
|
86311
|
-
addresses
|
|
86196
|
+
durationMs: Date.now() - startedAt
|
|
86312
86197
|
};
|
|
86313
86198
|
}
|
|
86314
86199
|
setTools(tools) {
|
|
@@ -86577,7 +86462,6 @@ var init_xmtp_sdk = __esm({
|
|
|
86577
86462
|
logWithTimestamp(`${tag} no client found, returning empty`);
|
|
86578
86463
|
return [];
|
|
86579
86464
|
}
|
|
86580
|
-
await agent.client.conversations.syncAll([import_node_bindings2.ConsentState.Unknown]);
|
|
86581
86465
|
const groups = await agent.client.conversations.list({
|
|
86582
86466
|
consentStates: [import_node_bindings2.ConsentState.Unknown]
|
|
86583
86467
|
});
|
|
@@ -86721,21 +86605,6 @@ var init_xmtp_sdk = __esm({
|
|
|
86721
86605
|
onchainosAgentId: onchainosAgent?.agentId,
|
|
86722
86606
|
role: onchainosAgent?.role
|
|
86723
86607
|
};
|
|
86724
|
-
try {
|
|
86725
|
-
await agent.client.conversations.syncAll([
|
|
86726
|
-
import_node_bindings2.ConsentState.Allowed,
|
|
86727
|
-
import_node_bindings2.ConsentState.Unknown
|
|
86728
|
-
]);
|
|
86729
|
-
logWithTimestamp(`${tag} conversations synced (non-Denied)`);
|
|
86730
|
-
} catch (err2) {
|
|
86731
|
-
logWithTimestamp(`${tag} conversation sync failed, skipping this client:`, err2);
|
|
86732
|
-
logger.error(
|
|
86733
|
-
LogEvent.CONVERSATIONS_STREAM_FAILED,
|
|
86734
|
-
err2 instanceof Error ? err2 : void 0,
|
|
86735
|
-
agentExtras(identity3)
|
|
86736
|
-
);
|
|
86737
|
-
return;
|
|
86738
|
-
}
|
|
86739
86608
|
agent.use(loggingMiddleware(identity3));
|
|
86740
86609
|
agent.use(selfFilterMiddleware());
|
|
86741
86610
|
const inboundFactory = this.tools.createInboundMiddleware;
|
|
@@ -86744,15 +86613,7 @@ var init_xmtp_sdk = __esm({
|
|
|
86744
86613
|
inboundFactory({
|
|
86745
86614
|
myXmtpAddress: address,
|
|
86746
86615
|
getTools: () => this.tools,
|
|
86747
|
-
allowGroup: (addr, gid) => this.allowGroup(addr, gid)
|
|
86748
|
-
onMessageProcessed: (sentAtMs) => {
|
|
86749
|
-
const newTs = Math.max(
|
|
86750
|
-
this.syncByAddress.get(address) ?? 0,
|
|
86751
|
-
sentAtMs + 1
|
|
86752
|
-
);
|
|
86753
|
-
this.syncByAddress.set(address, newTs);
|
|
86754
|
-
saveSyncForAddress(this.dataDir, address, newTs);
|
|
86755
|
-
}
|
|
86616
|
+
allowGroup: (addr, gid) => this.allowGroup(addr, gid)
|
|
86756
86617
|
})
|
|
86757
86618
|
);
|
|
86758
86619
|
} else {
|
|
@@ -86760,14 +86621,6 @@ var init_xmtp_sdk = __esm({
|
|
|
86760
86621
|
`${tag} tools.createInboundMiddleware not injected \u2014 inbound routing disabled`
|
|
86761
86622
|
);
|
|
86762
86623
|
}
|
|
86763
|
-
if (!this.syncByAddress.has(address)) {
|
|
86764
|
-
const initialSyncMs = Date.now();
|
|
86765
|
-
this.syncByAddress.set(address, initialSyncMs);
|
|
86766
|
-
saveSyncForAddress(this.dataDir, address, initialSyncMs);
|
|
86767
|
-
logWithTimestamp(
|
|
86768
|
-
`${tag} initialized sync timestamp at ${new Date(initialSyncMs).toISOString()}`
|
|
86769
|
-
);
|
|
86770
|
-
}
|
|
86771
86624
|
const MAX_RETRIES = 5;
|
|
86772
86625
|
const BASE_DELAY_MS = 1e3;
|
|
86773
86626
|
const startWithRetry = async (attempt = 0) => {
|
|
@@ -86776,7 +86629,7 @@ var init_xmtp_sdk = __esm({
|
|
|
86776
86629
|
return;
|
|
86777
86630
|
}
|
|
86778
86631
|
try {
|
|
86779
|
-
await agent.start();
|
|
86632
|
+
await agent.start({ disableSync: true });
|
|
86780
86633
|
} catch (err2) {
|
|
86781
86634
|
logWithTimestamp(`${tag} agent.start error (attempt=${attempt}):`, err2);
|
|
86782
86635
|
logger.error(
|
|
@@ -86812,232 +86665,6 @@ var init_xmtp_sdk = __esm({
|
|
|
86812
86665
|
logWithTimestamp(`${tag} message listener started`);
|
|
86813
86666
|
});
|
|
86814
86667
|
}
|
|
86815
|
-
async replayOfflineMessagesForAddress(address) {
|
|
86816
|
-
const addressReplayStartedAt = Date.now();
|
|
86817
|
-
const summary = createOfflineReplayAddressSummary(address);
|
|
86818
|
-
const agent = this.clients.get(address);
|
|
86819
|
-
if (!agent) {
|
|
86820
|
-
summary.durationMs = Date.now() - addressReplayStartedAt;
|
|
86821
|
-
return summary;
|
|
86822
|
-
}
|
|
86823
|
-
const lastSyncMs = this.syncByAddress.get(address);
|
|
86824
|
-
const tag = `[xmtp-sdk:replay:${address}]`;
|
|
86825
|
-
if (lastSyncMs === void 0) {
|
|
86826
|
-
summary.durationMs = Date.now() - addressReplayStartedAt;
|
|
86827
|
-
return summary;
|
|
86828
|
-
}
|
|
86829
|
-
const sentAfterNs = lastSyncMs * 1e6;
|
|
86830
|
-
const myInboxId = agent.client.inboxId;
|
|
86831
|
-
const handlerDeps = {
|
|
86832
|
-
myXmtpAddress: address,
|
|
86833
|
-
getTools: () => this.tools,
|
|
86834
|
-
allowGroup: (addr, gid) => this.allowGroup(addr, gid)
|
|
86835
|
-
};
|
|
86836
|
-
const processOffline = this.tools.processOfflineMessage;
|
|
86837
|
-
if (!processOffline) {
|
|
86838
|
-
logWithTimestamp(
|
|
86839
|
-
`${tag} tools.processOfflineMessage not injected \u2014 offline replay skipped`
|
|
86840
|
-
);
|
|
86841
|
-
summary.durationMs = Date.now() - addressReplayStartedAt;
|
|
86842
|
-
return summary;
|
|
86843
|
-
}
|
|
86844
|
-
let conversations;
|
|
86845
|
-
try {
|
|
86846
|
-
const syncAllStartedAt = Date.now();
|
|
86847
|
-
await agent.client.conversations.syncAll([
|
|
86848
|
-
import_node_bindings2.ConsentState.Allowed,
|
|
86849
|
-
import_node_bindings2.ConsentState.Unknown
|
|
86850
|
-
]);
|
|
86851
|
-
summary.syncAllMs = Date.now() - syncAllStartedAt;
|
|
86852
|
-
const listStartedAt = Date.now();
|
|
86853
|
-
conversations = await agent.client.conversations.list({
|
|
86854
|
-
consentStates: [import_node_bindings2.ConsentState.Allowed, import_node_bindings2.ConsentState.Unknown]
|
|
86855
|
-
});
|
|
86856
|
-
summary.listMs = Date.now() - listStartedAt;
|
|
86857
|
-
summary.conversations = conversations.length;
|
|
86858
|
-
} catch (err2) {
|
|
86859
|
-
logWithTimestamp(`${tag} conversation sync/list failed, skipping:`, err2);
|
|
86860
|
-
logger.error(
|
|
86861
|
-
LogEvent.OFFLINE_REPLAY_FAILED,
|
|
86862
|
-
err2 instanceof Error ? err2 : void 0,
|
|
86863
|
-
{
|
|
86864
|
-
walletAddress: address,
|
|
86865
|
-
stage: "syncAll/list"
|
|
86866
|
-
}
|
|
86867
|
-
);
|
|
86868
|
-
summary.durationMs = Date.now() - addressReplayStartedAt;
|
|
86869
|
-
return summary;
|
|
86870
|
-
}
|
|
86871
|
-
for (const conv of conversations) {
|
|
86872
|
-
try {
|
|
86873
|
-
const messagesStartedAt = Date.now();
|
|
86874
|
-
const allMessages = await conv.messages({ sentAfterNs });
|
|
86875
|
-
const messagesMs = Date.now() - messagesStartedAt;
|
|
86876
|
-
summary.messagesMs += messagesMs;
|
|
86877
|
-
if (allMessages.length === 0) {
|
|
86878
|
-
summary.emptyConversations++;
|
|
86879
|
-
continue;
|
|
86880
|
-
}
|
|
86881
|
-
summary.conversationsWithMessages++;
|
|
86882
|
-
const missed = allMessages.filter(
|
|
86883
|
-
(msg) => msg.senderInboxId !== myInboxId && (!msg.kind || msg.kind === "application")
|
|
86884
|
-
).sort((a, b) => {
|
|
86885
|
-
const ta = typeof a.sentAtNs === "bigint" ? Number(a.sentAtNs) : Number(a.sentAt ?? 0);
|
|
86886
|
-
const tb = typeof b.sentAtNs === "bigint" ? Number(b.sentAtNs) : Number(b.sentAt ?? 0);
|
|
86887
|
-
return ta - tb;
|
|
86888
|
-
});
|
|
86889
|
-
if (missed.length === 0) {
|
|
86890
|
-
summary.selfOnlyConversations++;
|
|
86891
|
-
const latestMs = allMessages.reduce((max, m) => {
|
|
86892
|
-
const ms = typeof m.sentAtNs === "bigint" ? Number(m.sentAtNs / 1000000n) : Number(m.sentAt ?? 0);
|
|
86893
|
-
return ms > max ? ms : max;
|
|
86894
|
-
}, 0);
|
|
86895
|
-
if (latestMs > 0) {
|
|
86896
|
-
const newTs = Math.max(
|
|
86897
|
-
this.syncByAddress.get(address) ?? 0,
|
|
86898
|
-
latestMs + 1
|
|
86899
|
-
);
|
|
86900
|
-
this.syncByAddress.set(address, newTs);
|
|
86901
|
-
saveSyncForAddress(this.dataDir, address, newTs);
|
|
86902
|
-
}
|
|
86903
|
-
continue;
|
|
86904
|
-
}
|
|
86905
|
-
summary.conversationsWithMissedMessages++;
|
|
86906
|
-
for (const msg of missed) {
|
|
86907
|
-
const content3 = typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content);
|
|
86908
|
-
const preview = content3.length > 80 ? `${content3.slice(0, 80)}...` : content3;
|
|
86909
|
-
const msgSentMs = typeof msg.sentAtNs === "bigint" ? Number(msg.sentAtNs / 1000000n) : Number(msg.sentAt ?? Date.now());
|
|
86910
|
-
try {
|
|
86911
|
-
const senderInboxId = msg.senderInboxId;
|
|
86912
|
-
let cachedSenderAddress = "";
|
|
86913
|
-
let resolved = false;
|
|
86914
|
-
const resolveSenderAddress = async () => {
|
|
86915
|
-
if (resolved) {
|
|
86916
|
-
return cachedSenderAddress;
|
|
86917
|
-
}
|
|
86918
|
-
try {
|
|
86919
|
-
const state = await agent.client.preferences.inboxStateFromInboxIds([senderInboxId]);
|
|
86920
|
-
cachedSenderAddress = state?.[0]?.identifiers?.[0]?.identifier ?? "";
|
|
86921
|
-
} catch {
|
|
86922
|
-
cachedSenderAddress = "";
|
|
86923
|
-
}
|
|
86924
|
-
resolved = true;
|
|
86925
|
-
return cachedSenderAddress;
|
|
86926
|
-
};
|
|
86927
|
-
const fakeCtx = {
|
|
86928
|
-
message: {
|
|
86929
|
-
id: msg.id,
|
|
86930
|
-
senderInboxId,
|
|
86931
|
-
content: msg.content,
|
|
86932
|
-
sentAtNs: msg.sentAtNs,
|
|
86933
|
-
sentAt: msg.sentAt
|
|
86934
|
-
},
|
|
86935
|
-
conversation: conv,
|
|
86936
|
-
getSenderAddress: resolveSenderAddress
|
|
86937
|
-
};
|
|
86938
|
-
const handleStartedAt = Date.now();
|
|
86939
|
-
const handled = await processOffline(fakeCtx, handlerDeps, {
|
|
86940
|
-
skipNotify: true
|
|
86941
|
-
});
|
|
86942
|
-
const handleMs = Date.now() - handleStartedAt;
|
|
86943
|
-
summary.handleMs += handleMs;
|
|
86944
|
-
if (handled) {
|
|
86945
|
-
logWithTimestamp(
|
|
86946
|
-
`${tag} replayed content=${preview}`
|
|
86947
|
-
);
|
|
86948
|
-
summary.replayed++;
|
|
86949
|
-
logger.info(LogEvent.OFFLINE_REPLAY_MESSAGE_REPLAYED, {
|
|
86950
|
-
...agentExtras({
|
|
86951
|
-
walletAddress: address,
|
|
86952
|
-
inboxId: agent.client?.inboxId,
|
|
86953
|
-
onchainosAgentId: this.getAgentByAddress(address)?.agentId,
|
|
86954
|
-
role: this.getAgentByAddress(address)?.role
|
|
86955
|
-
}),
|
|
86956
|
-
...jobIdExtras(msg.content),
|
|
86957
|
-
messageId: msg.id,
|
|
86958
|
-
conversationId: conv.id,
|
|
86959
|
-
stage: "offlineReplay/handleMessage",
|
|
86960
|
-
xmtpSentAtMs: String(msgSentMs),
|
|
86961
|
-
replayLagMs: String(Math.max(0, Date.now() - msgSentMs)),
|
|
86962
|
-
handleMs: String(handleMs)
|
|
86963
|
-
});
|
|
86964
|
-
} else {
|
|
86965
|
-
summary.skipped++;
|
|
86966
|
-
}
|
|
86967
|
-
} catch (err2) {
|
|
86968
|
-
logWithTimestamp(`${tag} replay handling failed: msgId=${msg.id}`, err2);
|
|
86969
|
-
logger.error(
|
|
86970
|
-
LogEvent.OFFLINE_REPLAY_MESSAGE_FAILED,
|
|
86971
|
-
err2 instanceof Error ? err2 : void 0,
|
|
86972
|
-
{
|
|
86973
|
-
walletAddress: address,
|
|
86974
|
-
...jobIdExtras(msg.content),
|
|
86975
|
-
messageId: msg.id,
|
|
86976
|
-
conversationId: conv.id,
|
|
86977
|
-
stage: "offlineReplay/handleMessage",
|
|
86978
|
-
reason: err2 instanceof Error ? err2.name : "unknown_error"
|
|
86979
|
-
}
|
|
86980
|
-
);
|
|
86981
|
-
} finally {
|
|
86982
|
-
const newTs = Math.max(
|
|
86983
|
-
this.syncByAddress.get(address) ?? 0,
|
|
86984
|
-
msgSentMs + 1
|
|
86985
|
-
);
|
|
86986
|
-
this.syncByAddress.set(address, newTs);
|
|
86987
|
-
saveSyncForAddress(this.dataDir, address, newTs);
|
|
86988
|
-
}
|
|
86989
|
-
}
|
|
86990
|
-
} catch (err2) {
|
|
86991
|
-
logWithTimestamp(`${tag} failed to read messages from conversation ${conv.id}:`, err2);
|
|
86992
|
-
logger.error(
|
|
86993
|
-
LogEvent.OFFLINE_REPLAY_FAILED,
|
|
86994
|
-
err2 instanceof Error ? err2 : void 0,
|
|
86995
|
-
{
|
|
86996
|
-
walletAddress: address,
|
|
86997
|
-
stage: "offlineReplay/readConversation",
|
|
86998
|
-
reason: err2 instanceof Error ? err2.name : "unknown_error",
|
|
86999
|
-
conversationId: conv.id
|
|
87000
|
-
}
|
|
87001
|
-
);
|
|
87002
|
-
}
|
|
87003
|
-
}
|
|
87004
|
-
logger.info(LogEvent.ADDRESS_SYNC_COMPLETED, {
|
|
87005
|
-
...agentExtras({
|
|
87006
|
-
walletAddress: address,
|
|
87007
|
-
inboxId: agent.client?.inboxId,
|
|
87008
|
-
onchainosAgentId: this.getAgentByAddress(address)?.agentId
|
|
87009
|
-
}),
|
|
87010
|
-
replayed: String(summary.replayed),
|
|
87011
|
-
skipped: String(summary.skipped),
|
|
87012
|
-
conversationCount: String(summary.conversations),
|
|
87013
|
-
durationMs: String(Date.now() - addressReplayStartedAt)
|
|
87014
|
-
});
|
|
87015
|
-
summary.durationMs = Date.now() - addressReplayStartedAt;
|
|
87016
|
-
return summary;
|
|
87017
|
-
}
|
|
87018
|
-
async replayOfflineMessages() {
|
|
87019
|
-
await this._backupReady;
|
|
87020
|
-
const replayStartedAt = Date.now();
|
|
87021
|
-
let totalReplayed = 0;
|
|
87022
|
-
let totalSkipped = 0;
|
|
87023
|
-
const addresses = [];
|
|
87024
|
-
for (const address of this.clients.keys()) {
|
|
87025
|
-
const summary2 = await this.replayOfflineMessagesForAddress(address);
|
|
87026
|
-
addresses.push(summary2);
|
|
87027
|
-
const { replayed, skipped: skipped2 } = summary2;
|
|
87028
|
-
totalReplayed += replayed;
|
|
87029
|
-
totalSkipped += skipped2;
|
|
87030
|
-
}
|
|
87031
|
-
const summary = {
|
|
87032
|
-
clients: this.clients.size,
|
|
87033
|
-
addressesWithTimestamps: this.syncByAddress.size,
|
|
87034
|
-
replayed: totalReplayed,
|
|
87035
|
-
skipped: totalSkipped,
|
|
87036
|
-
durationMs: Date.now() - replayStartedAt,
|
|
87037
|
-
addresses
|
|
87038
|
-
};
|
|
87039
|
-
return summary;
|
|
87040
|
-
}
|
|
87041
86668
|
};
|
|
87042
86669
|
}
|
|
87043
86670
|
});
|
|
@@ -88332,10 +87959,6 @@ function selectAnyJobTarget(messages) {
|
|
|
88332
87959
|
return null;
|
|
88333
87960
|
}
|
|
88334
87961
|
async function findConversation(agent, target) {
|
|
88335
|
-
await agent.client.conversations.syncAll([
|
|
88336
|
-
import_node_bindings2.ConsentState.Allowed,
|
|
88337
|
-
import_node_bindings2.ConsentState.Unknown
|
|
88338
|
-
]);
|
|
88339
87962
|
const conversations = await agent.client.conversations.list({
|
|
88340
87963
|
consentStates: [import_node_bindings2.ConsentState.Allowed, import_node_bindings2.ConsentState.Unknown]
|
|
88341
87964
|
});
|
|
@@ -88352,10 +87975,6 @@ async function findConversation(agent, target) {
|
|
|
88352
87975
|
return null;
|
|
88353
87976
|
}
|
|
88354
87977
|
async function findGroupConversation(agent, groupId) {
|
|
88355
|
-
await agent.client.conversations.syncAll([
|
|
88356
|
-
import_node_bindings2.ConsentState.Allowed,
|
|
88357
|
-
import_node_bindings2.ConsentState.Unknown
|
|
88358
|
-
]);
|
|
88359
87978
|
const conversation = await agent.client.conversations.getConversationById(groupId);
|
|
88360
87979
|
return conversation instanceof Group ? conversation : null;
|
|
88361
87980
|
}
|
|
@@ -92313,7 +91932,6 @@ async function handleXmtpGetConversationHistory(command, params) {
|
|
|
92313
91932
|
if (!conversation) {
|
|
92314
91933
|
return [];
|
|
92315
91934
|
}
|
|
92316
|
-
await conversation.sync();
|
|
92317
91935
|
const options = command.limit ? { limit: command.limit } : void 0;
|
|
92318
91936
|
const messages = await conversation.messages(options);
|
|
92319
91937
|
const invalidStore = new InvalidXmtpMessageStore(params.homeDir);
|
|
@@ -93451,7 +93069,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
93451
93069
|
messageId: systemMessageId,
|
|
93452
93070
|
systemEvent: systemNotification.event ?? "",
|
|
93453
93071
|
stage: "inbound/system_notification_received",
|
|
93454
|
-
source:
|
|
93072
|
+
source: "live",
|
|
93455
93073
|
isDirectCommunication: String(systemNotification.isDirectCommunication),
|
|
93456
93074
|
providerBinding: providerGate.provider ?? "",
|
|
93457
93075
|
providerBindingCreated: String(providerGate.created)
|
|
@@ -93483,7 +93101,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
93483
93101
|
targetCount: String(targets.length),
|
|
93484
93102
|
systemEvent: systemNotification.event ?? "",
|
|
93485
93103
|
stage: "inbound/system_notification_routed",
|
|
93486
|
-
source:
|
|
93104
|
+
source: "live",
|
|
93487
93105
|
isDirectCommunication: String(systemNotification.isDirectCommunication)
|
|
93488
93106
|
}));
|
|
93489
93107
|
if (!options.skipNotify) {
|
|
@@ -93788,10 +93406,7 @@ function createFileMessageHandler(deps) {
|
|
|
93788
93406
|
return;
|
|
93789
93407
|
}
|
|
93790
93408
|
try {
|
|
93791
|
-
|
|
93792
|
-
if (handled) {
|
|
93793
|
-
deps.onMessageProcessed?.(extractXmtpSentAtMs2(ctx.message));
|
|
93794
|
-
}
|
|
93409
|
+
await processFileMessage(ctx, deps);
|
|
93795
93410
|
} catch (err2) {
|
|
93796
93411
|
logWithTimestamp(`[okx-agent-task:${deps.myXmtpAddress}] process message failed:`, err2);
|
|
93797
93412
|
}
|
|
@@ -93803,21 +93418,10 @@ function createMiddlewareFromCoreDeps(store, deps, extra) {
|
|
|
93803
93418
|
store,
|
|
93804
93419
|
sessionStore: extra?.sessionStore,
|
|
93805
93420
|
allowGroup: deps.allowGroup,
|
|
93806
|
-
onMessageProcessed: deps.onMessageProcessed,
|
|
93807
93421
|
onJobMessageStored: extra?.onJobMessageStored,
|
|
93808
93422
|
onSessionMessage: extra?.onSessionMessage
|
|
93809
93423
|
});
|
|
93810
93424
|
}
|
|
93811
|
-
function processOfflineFromCoreDeps(store, ctx, deps, options) {
|
|
93812
|
-
return processFileMessage(ctx, {
|
|
93813
|
-
myXmtpAddress: deps.myXmtpAddress,
|
|
93814
|
-
store,
|
|
93815
|
-
sessionStore: options.sessionStore,
|
|
93816
|
-
allowGroup: deps.allowGroup,
|
|
93817
|
-
onJobMessageStored: options.onJobMessageStored,
|
|
93818
|
-
onSessionMessage: options.onSessionMessage
|
|
93819
|
-
}, { ...options, source: "replay" });
|
|
93820
|
-
}
|
|
93821
93425
|
function buildSystemStoredMessage(params) {
|
|
93822
93426
|
const now = Date.now();
|
|
93823
93427
|
return {
|
|
@@ -93995,7 +93599,6 @@ var init_user_attention_watchers = __esm({
|
|
|
93995
93599
|
// src/listener.ts
|
|
93996
93600
|
var listener_exports = {};
|
|
93997
93601
|
__export(listener_exports, {
|
|
93998
|
-
DEFAULT_OFFLINE_REPLAY_INTERVAL_SEC: () => DEFAULT_OFFLINE_REPLAY_INTERVAL_SEC,
|
|
93999
93602
|
DEFAULT_XMTP_CLIENT_RECYCLE_INTERVAL_SEC: () => DEFAULT_XMTP_CLIENT_RECYCLE_INTERVAL_SEC,
|
|
94000
93603
|
HEARTBEAT_GATEWAY_CHECK_TIMEOUT_MS: () => HEARTBEAT_GATEWAY_CHECK_TIMEOUT_MS,
|
|
94001
93604
|
XMTP_CLIENT_RECYCLE_INTERVAL_ENV: () => XMTP_CLIENT_RECYCLE_INTERVAL_ENV,
|
|
@@ -94003,17 +93606,9 @@ __export(listener_exports, {
|
|
|
94003
93606
|
hermesConfigEnablesOkxA2a: () => hermesConfigEnablesOkxA2a,
|
|
94004
93607
|
isGatewayAvailableForHeartbeat: () => isGatewayAvailableForHeartbeat,
|
|
94005
93608
|
isHermesGatewayPluginEnabled: () => isHermesGatewayPluginEnabled,
|
|
94006
|
-
resolveOfflineReplayIntervalSec: () => resolveOfflineReplayIntervalSec,
|
|
94007
93609
|
resolveXmtpClientRecycleIntervalSec: () => resolveXmtpClientRecycleIntervalSec,
|
|
94008
93610
|
runListener: () => runListener
|
|
94009
93611
|
});
|
|
94010
|
-
function resolveOfflineReplayIntervalSec(systemConfig) {
|
|
94011
|
-
const interval = systemConfig.offlineReplayInterval;
|
|
94012
|
-
if (typeof interval !== "number" || !Number.isFinite(interval) || interval <= 0) {
|
|
94013
|
-
return DEFAULT_OFFLINE_REPLAY_INTERVAL_SEC;
|
|
94014
|
-
}
|
|
94015
|
-
return interval;
|
|
94016
|
-
}
|
|
94017
93612
|
function resolveXmtpClientRecycleIntervalSec(systemConfig, env = process.env) {
|
|
94018
93613
|
const rawEnvInterval = env[XMTP_CLIENT_RECYCLE_INTERVAL_ENV]?.trim();
|
|
94019
93614
|
if (rawEnvInterval) {
|
|
@@ -94216,16 +93811,6 @@ async function runListenerWithLock(options, paths) {
|
|
|
94216
93811
|
await enqueueAiSessionMessageDispatch({ commands, event });
|
|
94217
93812
|
}
|
|
94218
93813
|
}),
|
|
94219
|
-
processOfflineMessage: (ctx, deps, replayOptions) => processOfflineFromCoreDeps(store, ctx, deps, {
|
|
94220
|
-
...replayOptions,
|
|
94221
|
-
sessionStore,
|
|
94222
|
-
onJobMessageStored: async (event) => {
|
|
94223
|
-
await enqueueAiJobMessageDispatch({ commands, event });
|
|
94224
|
-
},
|
|
94225
|
-
onSessionMessage: async (event) => {
|
|
94226
|
-
await enqueueAiSessionMessageDispatch({ commands, event });
|
|
94227
|
-
}
|
|
94228
|
-
}),
|
|
94229
93814
|
notifySessionExpired: (command) => {
|
|
94230
93815
|
const rawText = `The onchainos login session has expired while running ${command}. Run \`onchainos wallet login\` and restart \`okx-a2a\`.`;
|
|
94231
93816
|
void store.appendBackup(buildSystemStoredMessage({
|
|
@@ -94241,12 +93826,12 @@ async function runListenerWithLock(options, paths) {
|
|
|
94241
93826
|
});
|
|
94242
93827
|
}
|
|
94243
93828
|
});
|
|
94244
|
-
service.setPluginVersion("0.1.
|
|
93829
|
+
service.setPluginVersion("0.1.10-beta-114515ea34-260721221928");
|
|
94245
93830
|
await service.init();
|
|
94246
93831
|
const pluginVersionStatus = service.pluginVersionStatus;
|
|
94247
93832
|
if (pluginVersionStatus.unavailable) {
|
|
94248
93833
|
throw new Error(
|
|
94249
|
-
`@okxweb3/a2a-node v${"0.1.
|
|
93834
|
+
`@okxweb3/a2a-node v${"0.1.10-beta-114515ea34-260721221928"} is below the required minimum v${pluginVersionStatus.minVersion}`
|
|
94250
93835
|
);
|
|
94251
93836
|
}
|
|
94252
93837
|
const systemConfig = service.getSystemConfig();
|
|
@@ -94264,14 +93849,13 @@ async function runListenerWithLock(options, paths) {
|
|
|
94264
93849
|
onchainosAgentId: "*",
|
|
94265
93850
|
reason: "system-config missing sentryDsn",
|
|
94266
93851
|
pluginId: "@okxweb3/a2a-node",
|
|
94267
|
-
pluginVersion: "0.1.
|
|
93852
|
+
pluginVersion: "0.1.10-beta-114515ea34-260721221928"
|
|
94268
93853
|
});
|
|
94269
93854
|
}
|
|
94270
93855
|
logWithTimestamp(
|
|
94271
93856
|
`[okx-agent-task] listener initialized, clients=${service.getClients().size}, home=${store.homeDir}`
|
|
94272
93857
|
);
|
|
94273
93858
|
let maintenanceInFlight = null;
|
|
94274
|
-
let lastRecycleReplayAtMs = 0;
|
|
94275
93859
|
let xmtpRecyclePending = false;
|
|
94276
93860
|
const tryEnterMaintenanceTask = (task) => {
|
|
94277
93861
|
if (task !== "xmtp_recycle" && xmtpRecyclePending) {
|
|
@@ -94391,48 +93975,6 @@ async function runListenerWithLock(options, paths) {
|
|
|
94391
93975
|
leaveMaintenanceTask("sync");
|
|
94392
93976
|
}
|
|
94393
93977
|
};
|
|
94394
|
-
const offlineReplayTick = async () => {
|
|
94395
|
-
if (!tryEnterMaintenanceTask("offline_replay")) {
|
|
94396
|
-
return;
|
|
94397
|
-
}
|
|
94398
|
-
const tickStartedAt = Date.now();
|
|
94399
|
-
try {
|
|
94400
|
-
if (lastRecycleReplayAtMs > 0 && Date.now() - lastRecycleReplayAtMs < offlineReplayIntervalSec * 1e3) {
|
|
94401
|
-
logWithTimestamp(
|
|
94402
|
-
`[okx-agent-task] offline replay skipped: recent recycle replay ${Date.now() - lastRecycleReplayAtMs}ms ago interval=${offlineReplayIntervalSec}s`
|
|
94403
|
-
);
|
|
94404
|
-
return;
|
|
94405
|
-
}
|
|
94406
|
-
const replayResult = await timeSettled(() => service.replayOfflineMessages());
|
|
94407
|
-
const replayMs = replayResult.durationMs;
|
|
94408
|
-
if (replayResult.error) {
|
|
94409
|
-
logger.error(LogEvent.OFFLINE_REPLAY_FAILED, replayResult.error instanceof Error ? replayResult.error : new Error(String(replayResult.error)), {
|
|
94410
|
-
component: "node_listener",
|
|
94411
|
-
stage: "offline_replay_tick",
|
|
94412
|
-
reason: replayResult.error instanceof Error ? replayResult.error.name : "unknown_error",
|
|
94413
|
-
durationMs: String(replayMs),
|
|
94414
|
-
communicationClass: "xmtp_replay_or_storage"
|
|
94415
|
-
});
|
|
94416
|
-
logWithTimestamp(`[okx-agent-task] offline replay failed duration=${replayMs}ms:`, replayResult.error);
|
|
94417
|
-
return;
|
|
94418
|
-
}
|
|
94419
|
-
const replaySummary = replayResult.value;
|
|
94420
|
-
logWithTimestamp(
|
|
94421
|
-
`[okx-agent-task] offline replay tick clients=${replaySummary?.clients ?? service.getClients().size} replayed=${replaySummary?.replayed ?? 0} skipped=${replaySummary?.skipped ?? 0} duration=${replayMs}ms`
|
|
94422
|
-
);
|
|
94423
|
-
} catch (err2) {
|
|
94424
|
-
logger.error(LogEvent.OFFLINE_REPLAY_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), {
|
|
94425
|
-
component: "node_listener",
|
|
94426
|
-
stage: "offline_replay_tick",
|
|
94427
|
-
durationMs: String(Date.now() - tickStartedAt),
|
|
94428
|
-
reason: "offline_replay_tick_exception",
|
|
94429
|
-
communicationClass: "xmtp_replay_or_storage"
|
|
94430
|
-
});
|
|
94431
|
-
logWithTimestamp(`[okx-agent-task] offline replay tick failed total=${Date.now() - tickStartedAt}ms:`, err2);
|
|
94432
|
-
} finally {
|
|
94433
|
-
leaveMaintenanceTask("offline_replay");
|
|
94434
|
-
}
|
|
94435
|
-
};
|
|
94436
93978
|
const xmtpRecycleTick = async () => {
|
|
94437
93979
|
if (!tryEnterMaintenanceTask("xmtp_recycle")) {
|
|
94438
93980
|
xmtpRecyclePending = true;
|
|
@@ -94454,11 +93996,8 @@ async function runListenerWithLock(options, paths) {
|
|
|
94454
93996
|
return;
|
|
94455
93997
|
}
|
|
94456
93998
|
const recycleSummary = recycleResult.value;
|
|
94457
|
-
if ((recycleSummary?.recycled ?? 0) > 0) {
|
|
94458
|
-
lastRecycleReplayAtMs = Date.now();
|
|
94459
|
-
}
|
|
94460
93999
|
logWithTimestamp(
|
|
94461
|
-
`[okx-agent-task] XMTP client recycle tick clients=${recycleSummary?.clients ?? service.getClients().size} recycled=${recycleSummary?.recycled ?? 0} failed=${recycleSummary?.failed ?? 0}
|
|
94000
|
+
`[okx-agent-task] XMTP client recycle tick clients=${recycleSummary?.clients ?? service.getClients().size} recycled=${recycleSummary?.recycled ?? 0} failed=${recycleSummary?.failed ?? 0} duration=${recycleMs}ms`
|
|
94462
94001
|
);
|
|
94463
94002
|
} catch (err2) {
|
|
94464
94003
|
logger.error(LogEvent.XMTP_CONNECTION_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), {
|
|
@@ -94474,10 +94013,8 @@ async function runListenerWithLock(options, paths) {
|
|
|
94474
94013
|
}
|
|
94475
94014
|
};
|
|
94476
94015
|
let intervalSec = Math.max(10, service.getSystemConfig().heartbeatInterval);
|
|
94477
|
-
let offlineReplayIntervalSec = resolveOfflineReplayIntervalSec(service.getSystemConfig());
|
|
94478
94016
|
let xmtpClientRecycleIntervalSec = resolveXmtpClientRecycleIntervalSec(service.getSystemConfig());
|
|
94479
94017
|
let timer;
|
|
94480
|
-
let offlineReplayTimer;
|
|
94481
94018
|
let xmtpClientRecycleTimer;
|
|
94482
94019
|
let stopping = false;
|
|
94483
94020
|
const scheduleSyncTimer = (nextIntervalSec) => {
|
|
@@ -94493,21 +94030,6 @@ async function runListenerWithLock(options, paths) {
|
|
|
94493
94030
|
void syncTick();
|
|
94494
94031
|
}, intervalSec * 1e3);
|
|
94495
94032
|
};
|
|
94496
|
-
const scheduleOfflineReplayTimer = (nextIntervalSec) => {
|
|
94497
|
-
if (stopping) {
|
|
94498
|
-
return;
|
|
94499
|
-
}
|
|
94500
|
-
if (offlineReplayTimer) {
|
|
94501
|
-
clearInterval(offlineReplayTimer);
|
|
94502
|
-
}
|
|
94503
|
-
offlineReplayIntervalSec = resolveOfflineReplayIntervalSec({
|
|
94504
|
-
offlineReplayInterval: nextIntervalSec
|
|
94505
|
-
});
|
|
94506
|
-
logWithTimestamp(`[okx-agent-task] scheduled offline replay interval ${offlineReplayIntervalSec}s`);
|
|
94507
|
-
offlineReplayTimer = setInterval(() => {
|
|
94508
|
-
void offlineReplayTick();
|
|
94509
|
-
}, offlineReplayIntervalSec * 1e3);
|
|
94510
|
-
};
|
|
94511
94033
|
const scheduleXmtpClientRecycleTimer = (nextIntervalSec) => {
|
|
94512
94034
|
if (stopping) {
|
|
94513
94035
|
return;
|
|
@@ -94528,7 +94050,6 @@ async function runListenerWithLock(options, paths) {
|
|
|
94528
94050
|
return;
|
|
94529
94051
|
}
|
|
94530
94052
|
const previousIntervalSec = intervalSec;
|
|
94531
|
-
const previousOfflineReplayIntervalSec = offlineReplayIntervalSec;
|
|
94532
94053
|
const previousXmtpClientRecycleIntervalSec = xmtpClientRecycleIntervalSec;
|
|
94533
94054
|
try {
|
|
94534
94055
|
await service.refreshSystemConfig();
|
|
@@ -94543,13 +94064,6 @@ async function runListenerWithLock(options, paths) {
|
|
|
94543
94064
|
);
|
|
94544
94065
|
scheduleSyncTimer(nextIntervalSec);
|
|
94545
94066
|
}
|
|
94546
|
-
const nextOfflineReplayIntervalSec = resolveOfflineReplayIntervalSec(systemConfig2);
|
|
94547
|
-
if (nextOfflineReplayIntervalSec !== previousOfflineReplayIntervalSec) {
|
|
94548
|
-
logWithTimestamp(
|
|
94549
|
-
`[okx-agent-task] offline replay interval changed from ${previousOfflineReplayIntervalSec}s to ${nextOfflineReplayIntervalSec}s; rescheduling offline replay timer`
|
|
94550
|
-
);
|
|
94551
|
-
scheduleOfflineReplayTimer(nextOfflineReplayIntervalSec);
|
|
94552
|
-
}
|
|
94553
94067
|
const nextXmtpClientRecycleIntervalSec = resolveXmtpClientRecycleIntervalSec(systemConfig2);
|
|
94554
94068
|
if (nextXmtpClientRecycleIntervalSec !== previousXmtpClientRecycleIntervalSec) {
|
|
94555
94069
|
logWithTimestamp(
|
|
@@ -94567,15 +94081,11 @@ async function runListenerWithLock(options, paths) {
|
|
|
94567
94081
|
}
|
|
94568
94082
|
};
|
|
94569
94083
|
scheduleSyncTimer(intervalSec);
|
|
94570
|
-
scheduleOfflineReplayTimer(offlineReplayIntervalSec);
|
|
94571
94084
|
scheduleXmtpClientRecycleTimer(xmtpClientRecycleIntervalSec);
|
|
94572
94085
|
const systemConfigRefreshTimer = setInterval(() => {
|
|
94573
94086
|
void refreshSystemConfigTick();
|
|
94574
94087
|
}, 60 * 60 * 1e3);
|
|
94575
|
-
void (
|
|
94576
|
-
await syncTick();
|
|
94577
|
-
await offlineReplayTick();
|
|
94578
|
-
})();
|
|
94088
|
+
void syncTick();
|
|
94579
94089
|
const commandProcessor = startCommandProcessor({
|
|
94580
94090
|
service,
|
|
94581
94091
|
store,
|
|
@@ -94599,9 +94109,6 @@ async function runListenerWithLock(options, paths) {
|
|
|
94599
94109
|
if (timer) {
|
|
94600
94110
|
clearInterval(timer);
|
|
94601
94111
|
}
|
|
94602
|
-
if (offlineReplayTimer) {
|
|
94603
|
-
clearInterval(offlineReplayTimer);
|
|
94604
|
-
}
|
|
94605
94112
|
if (xmtpClientRecycleTimer) {
|
|
94606
94113
|
clearInterval(xmtpClientRecycleTimer);
|
|
94607
94114
|
}
|
|
@@ -94637,7 +94144,7 @@ async function timeSettled(fn) {
|
|
|
94637
94144
|
return { durationMs: Date.now() - startedAt, error };
|
|
94638
94145
|
}
|
|
94639
94146
|
}
|
|
94640
|
-
var import_node_fs18, import_promises9, import_node_os7, import_node_path23,
|
|
94147
|
+
var import_node_fs18, import_promises9, import_node_os7, import_node_path23, DEFAULT_XMTP_CLIENT_RECYCLE_INTERVAL_SEC, XMTP_CLIENT_RECYCLE_INTERVAL_ENV, HEARTBEAT_GATEWAY_CHECK_TIMEOUT_MS, SHUTDOWN_FORCE_RESOLVE_MS;
|
|
94641
94148
|
var init_listener = __esm({
|
|
94642
94149
|
"src/listener.ts"() {
|
|
94643
94150
|
"use strict";
|
|
@@ -94664,7 +94171,6 @@ var init_listener = __esm({
|
|
|
94664
94171
|
init_openclaw_gateway();
|
|
94665
94172
|
init_sentry_logger();
|
|
94666
94173
|
init_sentry_config();
|
|
94667
|
-
DEFAULT_OFFLINE_REPLAY_INTERVAL_SEC = 300;
|
|
94668
94174
|
DEFAULT_XMTP_CLIENT_RECYCLE_INTERVAL_SEC = 6 * 60 * 60;
|
|
94669
94175
|
XMTP_CLIENT_RECYCLE_INTERVAL_ENV = "OKX_A2A_XMTP_CLIENT_RECYCLE_INTERVAL_SEC";
|
|
94670
94176
|
HEARTBEAT_GATEWAY_CHECK_TIMEOUT_MS = 2e3;
|
|
@@ -98285,7 +97791,7 @@ async function getCurrentNodeCliVersion() {
|
|
|
98285
97791
|
return await getGlobalNpmPackageVersion(UPDATE_PACKAGES.node) ?? getBundledNodeCliVersion();
|
|
98286
97792
|
}
|
|
98287
97793
|
function getBundledNodeCliVersion() {
|
|
98288
|
-
return true ? "0.1.
|
|
97794
|
+
return true ? "0.1.10-beta-114515ea34-260721221928" : null;
|
|
98289
97795
|
}
|
|
98290
97796
|
function readConfiguredAiProvider() {
|
|
98291
97797
|
const explicit = process.env.OKX_A2A_AI_PROVIDER || process.env.OKX_AGENT_TASK_AI_CLI;
|
|
@@ -98495,7 +98001,7 @@ async function updateHermes(release, options) {
|
|
|
98495
98001
|
}
|
|
98496
98002
|
}
|
|
98497
98003
|
async function installGatewayPluginForDoctor(target) {
|
|
98498
|
-
const release = isPrereleaseVersion("0.1.
|
|
98004
|
+
const release = isPrereleaseVersion("0.1.10-beta-114515ea34-260721221928") ? "beta" : "latest";
|
|
98499
98005
|
const insideTargetGateway = detectGatewayInvocation() === target;
|
|
98500
98006
|
const options = {
|
|
98501
98007
|
restart: !insideTargetGateway,
|
|
@@ -99483,7 +98989,7 @@ async function runDoctor(options = {}) {
|
|
|
99483
98989
|
platform: options.platform ?? process.platform,
|
|
99484
98990
|
env: options.env ?? process.env,
|
|
99485
98991
|
target: options.target ?? resolveDoctorTarget(options.env ?? process.env),
|
|
99486
|
-
cliVersion: options.cliVersion ?? (true ? "0.1.
|
|
98992
|
+
cliVersion: options.cliVersion ?? (true ? "0.1.10-beta-114515ea34-260721221928" : "0.0.0"),
|
|
99487
98993
|
fixMode: options.fix === true,
|
|
99488
98994
|
nonInteractive: options.nonInteractive === true,
|
|
99489
98995
|
packageChanged: false,
|
|
@@ -100615,7 +100121,7 @@ init_sentry_logger();
|
|
|
100615
100121
|
init_sentry_config();
|
|
100616
100122
|
var CURRENT_GATEWAY_SESSION_KEYS_ENV4 = "OKX_A2A_CURRENT_GATEWAY_SESSION_KEYS";
|
|
100617
100123
|
function printUsage2() {
|
|
100618
|
-
console.log(`okx-a2a ${"0.1.
|
|
100124
|
+
console.log(`okx-a2a ${"0.1.10-beta-114515ea34-260721221928"}
|
|
100619
100125
|
|
|
100620
100126
|
Usage:
|
|
100621
100127
|
okx-a2a <command> [options]
|
|
@@ -100653,7 +100159,7 @@ Run \`okx-a2a <command> -h\` for command-specific help.
|
|
|
100653
100159
|
`);
|
|
100654
100160
|
}
|
|
100655
100161
|
function printVersion() {
|
|
100656
|
-
console.log("0.1.
|
|
100162
|
+
console.log("0.1.10-beta-114515ea34-260721221928");
|
|
100657
100163
|
}
|
|
100658
100164
|
function printDaemonUsage() {
|
|
100659
100165
|
console.log(`Usage: okx-a2a daemon <start|restart|stop|status|autostart> [options]
|