@okxweb3/a2a-node 0.0.17 → 0.0.18-beta-8614cb2a91-260625165344
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +268 -115
- package/dist/index.js +99 -57
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -68224,6 +68224,7 @@ var SessionStore = class {
|
|
|
68224
68224
|
choices_json TEXT,
|
|
68225
68225
|
user_content TEXT NOT NULL,
|
|
68226
68226
|
idempotency_key TEXT UNIQUE,
|
|
68227
|
+
expire_time INTEGER,
|
|
68227
68228
|
created_at TEXT NOT NULL,
|
|
68228
68229
|
handled_at TEXT,
|
|
68229
68230
|
deleted_at TEXT,
|
|
@@ -68238,6 +68239,7 @@ var SessionStore = class {
|
|
|
68238
68239
|
this.ensureColumn("user_attention", "deleted_at", "TEXT");
|
|
68239
68240
|
this.ensureColumn("user_attention", "seen", "INTEGER NOT NULL DEFAULT 0");
|
|
68240
68241
|
this.ensureColumn("user_attention", "provider", "TEXT CHECK (provider IN ('codex', 'claude', 'hermes', 'openclaw') OR provider IS NULL)");
|
|
68242
|
+
this.ensureColumn("user_attention", "expire_time", "INTEGER");
|
|
68241
68243
|
this.db.exec(`
|
|
68242
68244
|
CREATE INDEX IF NOT EXISTS idx_user_attention_provider_status_created
|
|
68243
68245
|
ON user_attention(provider, status, created_at)
|
|
@@ -68655,6 +68657,7 @@ var SessionStore = class {
|
|
|
68655
68657
|
}
|
|
68656
68658
|
const provider = normalizeOptionalProvider(input.provider);
|
|
68657
68659
|
const choicesJson = normalizeChoicesJson(input.choices);
|
|
68660
|
+
const expireTime = normalizeOptionalExpireTime(input.expireTime);
|
|
68658
68661
|
return this.transaction(() => {
|
|
68659
68662
|
if (input.idempotencyKey) {
|
|
68660
68663
|
const existing = this.getUserAttentionByIdempotencyKey(input.idempotencyKey);
|
|
@@ -68670,15 +68673,15 @@ var SessionStore = class {
|
|
|
68670
68673
|
const statement = input.idempotencyKey ? this.db.prepare(`
|
|
68671
68674
|
INSERT OR IGNORE INTO user_attention (
|
|
68672
68675
|
id, kind, provider, status, job_id, session_key, llm_content, choices_json, user_content,
|
|
68673
|
-
idempotency_key, created_at, handled_at
|
|
68676
|
+
idempotency_key, expire_time, created_at, handled_at
|
|
68674
68677
|
)
|
|
68675
|
-
VALUES (?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?, ?, NULL)
|
|
68678
|
+
VALUES (?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?, ?, ?, NULL)
|
|
68676
68679
|
`) : this.db.prepare(`
|
|
68677
68680
|
INSERT INTO user_attention (
|
|
68678
68681
|
id, kind, provider, status, job_id, session_key, llm_content, choices_json, user_content,
|
|
68679
|
-
idempotency_key, created_at, handled_at
|
|
68682
|
+
idempotency_key, expire_time, created_at, handled_at
|
|
68680
68683
|
)
|
|
68681
|
-
VALUES (?, ?, ?, 'pending', ?, ?, ?, ?, ?, NULL, ?, NULL)
|
|
68684
|
+
VALUES (?, ?, ?, 'pending', ?, ?, ?, ?, ?, NULL, ?, ?, NULL)
|
|
68682
68685
|
`);
|
|
68683
68686
|
if (input.idempotencyKey) {
|
|
68684
68687
|
statement.run(
|
|
@@ -68691,6 +68694,7 @@ var SessionStore = class {
|
|
|
68691
68694
|
choicesJson,
|
|
68692
68695
|
input.userContent,
|
|
68693
68696
|
input.idempotencyKey,
|
|
68697
|
+
expireTime,
|
|
68694
68698
|
createdAt
|
|
68695
68699
|
);
|
|
68696
68700
|
const existing = this.getUserAttentionByIdempotencyKey(input.idempotencyKey);
|
|
@@ -68708,6 +68712,7 @@ var SessionStore = class {
|
|
|
68708
68712
|
input.llmContent ?? null,
|
|
68709
68713
|
choicesJson,
|
|
68710
68714
|
input.userContent,
|
|
68715
|
+
expireTime,
|
|
68711
68716
|
createdAt
|
|
68712
68717
|
);
|
|
68713
68718
|
const item = this.getUserAttention(id);
|
|
@@ -68724,6 +68729,8 @@ var SessionStore = class {
|
|
|
68724
68729
|
if (!options.includeHandled) {
|
|
68725
68730
|
conditions.push("status = 'pending'");
|
|
68726
68731
|
}
|
|
68732
|
+
conditions.push(activeUserAttentionSql());
|
|
68733
|
+
values.push(this.currentUnixSeconds());
|
|
68727
68734
|
if (options.provider) {
|
|
68728
68735
|
assertAiProvider(options.provider);
|
|
68729
68736
|
conditions.push("provider = ?");
|
|
@@ -68765,19 +68772,21 @@ var SessionStore = class {
|
|
|
68765
68772
|
AND status = 'pending'
|
|
68766
68773
|
AND seen = 0
|
|
68767
68774
|
AND deleted_at IS NULL
|
|
68775
|
+
AND ${activeUserAttentionSql()}
|
|
68768
68776
|
${watchFilter.sql}
|
|
68769
68777
|
ORDER BY created_at DESC, id DESC
|
|
68770
68778
|
LIMIT 1
|
|
68771
|
-
`).get(...watchFilter.values);
|
|
68779
|
+
`).get(this.currentUnixSeconds(), ...watchFilter.values);
|
|
68772
68780
|
const notifications = this.db.prepare(`
|
|
68773
68781
|
SELECT * FROM user_attention
|
|
68774
68782
|
WHERE kind = 'notification'
|
|
68775
68783
|
AND status = 'pending'
|
|
68776
68784
|
AND seen = 0
|
|
68777
68785
|
AND deleted_at IS NULL
|
|
68786
|
+
AND ${activeUserAttentionSql()}
|
|
68778
68787
|
${watchFilter.sql}
|
|
68779
68788
|
ORDER BY created_at ASC, id ASC
|
|
68780
|
-
`).all(...watchFilter.values);
|
|
68789
|
+
`).all(this.currentUnixSeconds(), ...watchFilter.values);
|
|
68781
68790
|
if (!decision && notifications.length === 0) {
|
|
68782
68791
|
return { items: [], hasDecision: false };
|
|
68783
68792
|
}
|
|
@@ -68999,9 +69008,10 @@ var SessionStore = class {
|
|
|
68999
69008
|
AND status = 'pending'
|
|
69000
69009
|
AND seen = 1
|
|
69001
69010
|
AND deleted_at IS NULL
|
|
69011
|
+
AND ${activeUserAttentionSql()}
|
|
69002
69012
|
${providerFilter}
|
|
69003
69013
|
ORDER BY created_at ASC, id ASC
|
|
69004
|
-
`).all(...values);
|
|
69014
|
+
`).all(this.currentUnixSeconds(), ...values);
|
|
69005
69015
|
return rows.map(mapAttentionRow);
|
|
69006
69016
|
}
|
|
69007
69017
|
markUserAttentionHandled(ids) {
|
|
@@ -69212,6 +69222,9 @@ var SessionStore = class {
|
|
|
69212
69222
|
timestamp() {
|
|
69213
69223
|
return this.now().toISOString();
|
|
69214
69224
|
}
|
|
69225
|
+
currentUnixSeconds() {
|
|
69226
|
+
return Math.floor(this.now().getTime() / 1e3);
|
|
69227
|
+
}
|
|
69215
69228
|
};
|
|
69216
69229
|
function assertNonEmpty(value, name2) {
|
|
69217
69230
|
if (!value || value.trim().length === 0) {
|
|
@@ -69256,6 +69269,18 @@ function normalizeOptionalJobId(jobId) {
|
|
|
69256
69269
|
const normalized = jobId?.trim();
|
|
69257
69270
|
return normalized ? normalized : null;
|
|
69258
69271
|
}
|
|
69272
|
+
function normalizeOptionalExpireTime(expireTime) {
|
|
69273
|
+
if (expireTime === null || expireTime === void 0) {
|
|
69274
|
+
return null;
|
|
69275
|
+
}
|
|
69276
|
+
if (!Number.isSafeInteger(expireTime) || expireTime < 0) {
|
|
69277
|
+
throw new Error("expireTime must be a non-negative integer Unix timestamp in seconds");
|
|
69278
|
+
}
|
|
69279
|
+
return expireTime;
|
|
69280
|
+
}
|
|
69281
|
+
function activeUserAttentionSql() {
|
|
69282
|
+
return "(expire_time IS NULL OR expire_time >= ?)";
|
|
69283
|
+
}
|
|
69259
69284
|
function normalizeJobIdList(jobIds) {
|
|
69260
69285
|
return [...new Set(jobIds.map((jobId) => normalizeOptionalJobId(jobId)).filter(isNonNullString))];
|
|
69261
69286
|
}
|
|
@@ -69334,6 +69359,7 @@ function mapAttentionRow(row) {
|
|
|
69334
69359
|
...mapChoices(row.choices_json ?? null),
|
|
69335
69360
|
userContent: row.user_content,
|
|
69336
69361
|
...row.idempotency_key ? { idempotencyKey: row.idempotency_key } : {},
|
|
69362
|
+
...typeof row.expire_time === "number" ? { expireTime: row.expire_time } : {},
|
|
69337
69363
|
createdAt: row.created_at,
|
|
69338
69364
|
...row.handled_at ? { handledAt: row.handled_at } : {}
|
|
69339
69365
|
};
|
|
@@ -74823,7 +74849,7 @@ function loadSqlite3() {
|
|
|
74823
74849
|
}
|
|
74824
74850
|
|
|
74825
74851
|
// src/xmtp-send.ts
|
|
74826
|
-
var
|
|
74852
|
+
var import_node_crypto9 = require("node:crypto");
|
|
74827
74853
|
|
|
74828
74854
|
// ../../node_modules/@xmtp/content-type-primitives/dist/index.js
|
|
74829
74855
|
var ContentTypeId = class _ContentTypeId {
|
|
@@ -85914,6 +85940,9 @@ async function fetchSensitiveWords() {
|
|
|
85914
85940
|
}
|
|
85915
85941
|
|
|
85916
85942
|
// src/agent-message-notice.ts
|
|
85943
|
+
var import_node_crypto8 = require("node:crypto");
|
|
85944
|
+
|
|
85945
|
+
// src/outbound-behavior.ts
|
|
85917
85946
|
var import_node_crypto7 = require("node:crypto");
|
|
85918
85947
|
|
|
85919
85948
|
// src/openclaw-gateway.ts
|
|
@@ -86392,7 +86421,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
86392
86421
|
client: {
|
|
86393
86422
|
id: "gateway-client",
|
|
86394
86423
|
displayName: "okx-a2a-node",
|
|
86395
|
-
version: "0.0.
|
|
86424
|
+
version: "0.0.18-beta-8614cb2a91-260625165344",
|
|
86396
86425
|
platform: "node",
|
|
86397
86426
|
mode: "backend",
|
|
86398
86427
|
instanceId
|
|
@@ -86403,7 +86432,7 @@ function buildConnectParams(config, instanceId, protocolVersion) {
|
|
|
86403
86432
|
commands: [],
|
|
86404
86433
|
permissions: {},
|
|
86405
86434
|
locale: Intl.DateTimeFormat().resolvedOptions().locale || "en-US",
|
|
86406
|
-
userAgent: `okx-a2a-node/${"0.0.
|
|
86435
|
+
userAgent: `okx-a2a-node/${"0.0.18-beta-8614cb2a91-260625165344"}`,
|
|
86407
86436
|
auth: {
|
|
86408
86437
|
...config.token ? { token: config.token } : {},
|
|
86409
86438
|
...config.password ? { password: config.password } : {}
|
|
@@ -86905,7 +86934,8 @@ var SqliteOutboundBehavior = class {
|
|
|
86905
86934
|
userContent: input.userContent,
|
|
86906
86935
|
jobId: input.jobId ?? null,
|
|
86907
86936
|
sessionKey: input.sessionKey ?? null,
|
|
86908
|
-
idempotencyKey: input.idempotencyKey ?? null
|
|
86937
|
+
idempotencyKey: input.idempotencyKey ?? null,
|
|
86938
|
+
expireTime: input.expireTime ?? null
|
|
86909
86939
|
});
|
|
86910
86940
|
await notifyUserAttentionChanged(this.store.homeDir);
|
|
86911
86941
|
return item;
|
|
@@ -86919,7 +86949,8 @@ var SqliteOutboundBehavior = class {
|
|
|
86919
86949
|
choices: input.choices ?? null,
|
|
86920
86950
|
jobId: input.jobId ?? null,
|
|
86921
86951
|
sessionKey: input.sessionKey ?? null,
|
|
86922
|
-
idempotencyKey: input.idempotencyKey ?? null
|
|
86952
|
+
idempotencyKey: input.idempotencyKey ?? null,
|
|
86953
|
+
expireTime: input.expireTime ?? null
|
|
86923
86954
|
});
|
|
86924
86955
|
await notifyUserAttentionChanged(this.store.homeDir);
|
|
86925
86956
|
return item;
|
|
@@ -86934,6 +86965,9 @@ var DEFAULT_GATEWAY_PORT2 = {
|
|
|
86934
86965
|
callPromptUserToLatestSessions
|
|
86935
86966
|
};
|
|
86936
86967
|
var GATEWAY_OUTBOUND_LOG_PREFIX = "[okx-a2a:gateway-outbound]";
|
|
86968
|
+
function resolveUserDeliveryId(input) {
|
|
86969
|
+
return input.idempotencyKey?.trim() || (0, import_node_crypto7.randomUUID)();
|
|
86970
|
+
}
|
|
86937
86971
|
function gatewayOutboundExtra(operation, extra = {}) {
|
|
86938
86972
|
return {
|
|
86939
86973
|
source: "node_gateway_outbound",
|
|
@@ -87114,19 +87148,21 @@ var GatewayOutboundBehavior = class {
|
|
|
87114
87148
|
});
|
|
87115
87149
|
}
|
|
87116
87150
|
async dispatchUser(input) {
|
|
87151
|
+
const deliveryId = resolveUserDeliveryId(input);
|
|
87117
87152
|
const routed = this.resolveUserGatewaySessionKey(input);
|
|
87118
87153
|
if (routed) {
|
|
87119
|
-
await this.dispatchUserToGatewaySession(input, routed);
|
|
87154
|
+
await this.dispatchUserToGatewaySession(input, routed, deliveryId);
|
|
87120
87155
|
return null;
|
|
87121
87156
|
}
|
|
87122
87157
|
errorWithTimestamp(
|
|
87123
|
-
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser latestUserSessions jobId=${input.jobId ?? "(none)"} idempotencyKey=${
|
|
87158
|
+
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser latestUserSessions jobId=${input.jobId ?? "(none)"} idempotencyKey=${deliveryId}`
|
|
87124
87159
|
);
|
|
87125
87160
|
try {
|
|
87126
87161
|
const result = await this.gateway.callDispatchUserToLatestSessions({
|
|
87127
87162
|
content: input.userContent,
|
|
87128
87163
|
...input.jobId ? { jobId: input.jobId } : {},
|
|
87129
|
-
...input.sessionKey ? { currentSessionKey: input.sessionKey } : {}
|
|
87164
|
+
...input.sessionKey ? { currentSessionKey: input.sessionKey } : {},
|
|
87165
|
+
idempotencyKey: deliveryId
|
|
87130
87166
|
});
|
|
87131
87167
|
assertLatestUserFanoutDelivered("okx-a2a.dispatch_user", result);
|
|
87132
87168
|
this.persistDeliveredFallbackRoutes(input.jobId, result);
|
|
@@ -87149,10 +87185,10 @@ var GatewayOutboundBehavior = class {
|
|
|
87149
87185
|
sessionKey: "openclaw:latest-user-sessions",
|
|
87150
87186
|
content: input.userContent,
|
|
87151
87187
|
jobId: input.jobId ?? null,
|
|
87152
|
-
messageId:
|
|
87188
|
+
messageId: deliveryId
|
|
87153
87189
|
});
|
|
87154
87190
|
errorWithTimestamp(
|
|
87155
|
-
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser latestUserSessions buffered idempotencyKey=${
|
|
87191
|
+
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser latestUserSessions buffered idempotencyKey=${deliveryId}: ${err2 instanceof Error ? err2.message : String(err2)}`
|
|
87156
87192
|
);
|
|
87157
87193
|
logger.error(LogEvent.USER_DISPATCH_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), gatewayOutboundExtra("okx-a2a.dispatch_user", {
|
|
87158
87194
|
jobId: input.jobId ?? "",
|
|
@@ -87160,7 +87196,7 @@ var GatewayOutboundBehavior = class {
|
|
|
87160
87196
|
}));
|
|
87161
87197
|
logger.info(LogEvent.GATEWAY_DELIVERY_BUFFERED, gatewayOutboundExtra("okx-a2a.dispatch_user", {
|
|
87162
87198
|
jobId: input.jobId ?? "",
|
|
87163
|
-
messageId:
|
|
87199
|
+
messageId: deliveryId,
|
|
87164
87200
|
status: "buffered"
|
|
87165
87201
|
}));
|
|
87166
87202
|
}
|
|
@@ -87196,16 +87232,17 @@ var GatewayOutboundBehavior = class {
|
|
|
87196
87232
|
}
|
|
87197
87233
|
return null;
|
|
87198
87234
|
}
|
|
87199
|
-
async dispatchUserToGatewaySession(input, routed) {
|
|
87235
|
+
async dispatchUserToGatewaySession(input, routed, deliveryId) {
|
|
87200
87236
|
const gatewaySessionKey = routed.sessionKeys.join(",");
|
|
87201
87237
|
console.error(
|
|
87202
|
-
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser routed sessionKey=${input.sessionKey ?? "(none)"} gatewaySessionKey=${gatewaySessionKey} source=${routed.source} jobId=${input.jobId ?? "(none)"} idempotencyKey=${
|
|
87238
|
+
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser routed sessionKey=${input.sessionKey ?? "(none)"} gatewaySessionKey=${gatewaySessionKey} source=${routed.source} jobId=${input.jobId ?? "(none)"} idempotencyKey=${deliveryId}`
|
|
87203
87239
|
);
|
|
87204
87240
|
try {
|
|
87205
87241
|
const result = await this.gateway.callDispatchUserToLatestSessions({
|
|
87206
87242
|
content: input.userContent,
|
|
87207
87243
|
label: "okx-a2a",
|
|
87208
|
-
...routed.source === "stored_openclaw_routes" ? { sessionKeys: routed.sessionKeys } : { sessionKey: routed.sessionKeys[0] }
|
|
87244
|
+
...routed.source === "stored_openclaw_routes" ? { sessionKeys: routed.sessionKeys } : { sessionKey: routed.sessionKeys[0] },
|
|
87245
|
+
idempotencyKey: deliveryId
|
|
87209
87246
|
});
|
|
87210
87247
|
assertLatestUserFanoutDelivered("okx-a2a.dispatch_user", result);
|
|
87211
87248
|
console.error(`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser routed ok gatewaySessionKey=${gatewaySessionKey} source=${routed.source}`);
|
|
@@ -87218,7 +87255,7 @@ var GatewayOutboundBehavior = class {
|
|
|
87218
87255
|
}));
|
|
87219
87256
|
} catch (err2) {
|
|
87220
87257
|
if (routed.source === "stored_openclaw_routes" && isNoDeliverableUserSessionError(err2)) {
|
|
87221
|
-
await this.repairDispatchUserRoute(input, gatewaySessionKey, routed.source);
|
|
87258
|
+
await this.repairDispatchUserRoute(input, gatewaySessionKey, routed.source, deliveryId);
|
|
87222
87259
|
return;
|
|
87223
87260
|
}
|
|
87224
87261
|
if (!this.store || !isRetryableOpenClawGatewayError(err2)) {
|
|
@@ -87237,10 +87274,10 @@ var GatewayOutboundBehavior = class {
|
|
|
87237
87274
|
sessionKey: routed.sessionKeys[0] ?? "openclaw:routed-user-sessions",
|
|
87238
87275
|
content: input.userContent,
|
|
87239
87276
|
jobId: input.jobId ?? null,
|
|
87240
|
-
messageId:
|
|
87277
|
+
messageId: deliveryId
|
|
87241
87278
|
});
|
|
87242
87279
|
console.error(
|
|
87243
|
-
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser routed buffered gatewaySessionKey=${gatewaySessionKey} source=${routed.source} idempotencyKey=${
|
|
87280
|
+
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser routed buffered gatewaySessionKey=${gatewaySessionKey} source=${routed.source} idempotencyKey=${deliveryId}: ${err2 instanceof Error ? err2.message : String(err2)}`
|
|
87244
87281
|
);
|
|
87245
87282
|
logger.error(LogEvent.USER_DISPATCH_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), gatewayOutboundExtra("okx-a2a.dispatch_user", {
|
|
87246
87283
|
sessionKey: input.sessionKey ?? "",
|
|
@@ -87253,20 +87290,21 @@ var GatewayOutboundBehavior = class {
|
|
|
87253
87290
|
sessionKey: input.sessionKey ?? "",
|
|
87254
87291
|
gatewaySessionKey,
|
|
87255
87292
|
jobId: input.jobId ?? "",
|
|
87256
|
-
messageId:
|
|
87293
|
+
messageId: deliveryId,
|
|
87257
87294
|
source: routed.source,
|
|
87258
87295
|
status: "buffered"
|
|
87259
87296
|
}));
|
|
87260
87297
|
}
|
|
87261
87298
|
}
|
|
87262
|
-
async repairDispatchUserRoute(input, staleGatewaySessionKey, source) {
|
|
87299
|
+
async repairDispatchUserRoute(input, staleGatewaySessionKey, source, deliveryId) {
|
|
87263
87300
|
console.error(
|
|
87264
87301
|
`${GATEWAY_OUTBOUND_LOG_PREFIX} dispatchUser routeRepair latestUserSessions staleGatewaySessionKey=${staleGatewaySessionKey} jobId=${input.jobId ?? "(none)"}`
|
|
87265
87302
|
);
|
|
87266
87303
|
const result = await this.gateway.callDispatchUserToLatestSessions({
|
|
87267
87304
|
content: input.userContent,
|
|
87268
87305
|
...input.jobId ? { jobId: input.jobId } : {},
|
|
87269
|
-
...input.sessionKey ? { currentSessionKey: input.sessionKey } : {}
|
|
87306
|
+
...input.sessionKey ? { currentSessionKey: input.sessionKey } : {},
|
|
87307
|
+
idempotencyKey: deliveryId
|
|
87270
87308
|
});
|
|
87271
87309
|
assertLatestUserFanoutDelivered("okx-a2a.dispatch_user", result);
|
|
87272
87310
|
this.persistDeliveredFallbackRoutes(input.jobId, result, { replaceExisting: true });
|
|
@@ -87283,20 +87321,22 @@ var GatewayOutboundBehavior = class {
|
|
|
87283
87321
|
}));
|
|
87284
87322
|
}
|
|
87285
87323
|
async promptUser(input) {
|
|
87324
|
+
const deliveryId = resolveUserDeliveryId(input);
|
|
87286
87325
|
const routed = this.resolveUserGatewaySessionKey(input);
|
|
87287
87326
|
if (routed) {
|
|
87288
|
-
await this.promptUserToGatewaySession(input, routed);
|
|
87327
|
+
await this.promptUserToGatewaySession(input, routed, deliveryId);
|
|
87289
87328
|
return null;
|
|
87290
87329
|
}
|
|
87291
87330
|
errorWithTimestamp(
|
|
87292
|
-
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser latestUserSessions jobId=${input.jobId ?? "(none)"} idempotencyKey=${
|
|
87331
|
+
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser latestUserSessions jobId=${input.jobId ?? "(none)"} idempotencyKey=${deliveryId}`
|
|
87293
87332
|
);
|
|
87294
87333
|
try {
|
|
87295
87334
|
const result = await this.gateway.callPromptUserToLatestSessions({
|
|
87296
87335
|
userContent: input.userContent,
|
|
87297
87336
|
llmContent: input.llmContent,
|
|
87298
87337
|
...input.jobId ? { jobId: input.jobId } : {},
|
|
87299
|
-
...input.sessionKey ? { currentSessionKey: input.sessionKey } : {}
|
|
87338
|
+
...input.sessionKey ? { currentSessionKey: input.sessionKey } : {},
|
|
87339
|
+
idempotencyKey: deliveryId
|
|
87300
87340
|
});
|
|
87301
87341
|
assertLatestUserFanoutDelivered("okx-a2a.prompt_user", result);
|
|
87302
87342
|
this.persistDeliveredFallbackRoutes(input.jobId, result);
|
|
@@ -87320,10 +87360,10 @@ var GatewayOutboundBehavior = class {
|
|
|
87320
87360
|
content: input.userContent,
|
|
87321
87361
|
llmContent: input.llmContent,
|
|
87322
87362
|
jobId: input.jobId ?? null,
|
|
87323
|
-
messageId:
|
|
87363
|
+
messageId: deliveryId
|
|
87324
87364
|
});
|
|
87325
87365
|
errorWithTimestamp(
|
|
87326
|
-
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser latestUserSessions buffered idempotencyKey=${
|
|
87366
|
+
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser latestUserSessions buffered idempotencyKey=${deliveryId}: ${err2 instanceof Error ? err2.message : String(err2)}`
|
|
87327
87367
|
);
|
|
87328
87368
|
logger.error(LogEvent.PROMPT_USER_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), gatewayOutboundExtra("okx-a2a.prompt_user", {
|
|
87329
87369
|
jobId: input.jobId ?? "",
|
|
@@ -87331,22 +87371,23 @@ var GatewayOutboundBehavior = class {
|
|
|
87331
87371
|
}));
|
|
87332
87372
|
logger.info(LogEvent.GATEWAY_DELIVERY_BUFFERED, gatewayOutboundExtra("okx-a2a.prompt_user", {
|
|
87333
87373
|
jobId: input.jobId ?? "",
|
|
87334
|
-
messageId:
|
|
87374
|
+
messageId: deliveryId,
|
|
87335
87375
|
status: "buffered"
|
|
87336
87376
|
}));
|
|
87337
87377
|
}
|
|
87338
87378
|
return null;
|
|
87339
87379
|
}
|
|
87340
|
-
async promptUserToGatewaySession(input, routed) {
|
|
87380
|
+
async promptUserToGatewaySession(input, routed, deliveryId) {
|
|
87341
87381
|
const gatewaySessionKey = routed.sessionKeys.join(",");
|
|
87342
87382
|
console.error(
|
|
87343
|
-
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser routed sessionKey=${input.sessionKey ?? "(none)"} gatewaySessionKey=${gatewaySessionKey} source=${routed.source} jobId=${input.jobId ?? "(none)"} idempotencyKey=${
|
|
87383
|
+
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser routed sessionKey=${input.sessionKey ?? "(none)"} gatewaySessionKey=${gatewaySessionKey} source=${routed.source} jobId=${input.jobId ?? "(none)"} idempotencyKey=${deliveryId}`
|
|
87344
87384
|
);
|
|
87345
87385
|
try {
|
|
87346
87386
|
const result = await this.gateway.callPromptUserToLatestSessions({
|
|
87347
87387
|
userContent: input.userContent,
|
|
87348
87388
|
llmContent: input.llmContent,
|
|
87349
|
-
...routed.source === "stored_openclaw_routes" ? { sessionKeys: routed.sessionKeys } : { sessionKey: routed.sessionKeys[0] }
|
|
87389
|
+
...routed.source === "stored_openclaw_routes" ? { sessionKeys: routed.sessionKeys } : { sessionKey: routed.sessionKeys[0] },
|
|
87390
|
+
idempotencyKey: deliveryId
|
|
87350
87391
|
});
|
|
87351
87392
|
assertLatestUserFanoutDelivered("okx-a2a.prompt_user", result);
|
|
87352
87393
|
console.error(`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser routed ok gatewaySessionKey=${gatewaySessionKey} source=${routed.source}`);
|
|
@@ -87359,7 +87400,7 @@ var GatewayOutboundBehavior = class {
|
|
|
87359
87400
|
}));
|
|
87360
87401
|
} catch (err2) {
|
|
87361
87402
|
if (routed.source === "stored_openclaw_routes" && isNoDeliverableUserSessionError(err2)) {
|
|
87362
|
-
await this.repairPromptUserRoute(input, gatewaySessionKey, routed.source);
|
|
87403
|
+
await this.repairPromptUserRoute(input, gatewaySessionKey, routed.source, deliveryId);
|
|
87363
87404
|
return;
|
|
87364
87405
|
}
|
|
87365
87406
|
if (!this.store || !isRetryableOpenClawGatewayError(err2)) {
|
|
@@ -87379,10 +87420,10 @@ var GatewayOutboundBehavior = class {
|
|
|
87379
87420
|
content: input.userContent,
|
|
87380
87421
|
llmContent: input.llmContent,
|
|
87381
87422
|
jobId: input.jobId ?? null,
|
|
87382
|
-
messageId:
|
|
87423
|
+
messageId: deliveryId
|
|
87383
87424
|
});
|
|
87384
87425
|
console.error(
|
|
87385
|
-
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser routed buffered gatewaySessionKey=${gatewaySessionKey} source=${routed.source} idempotencyKey=${
|
|
87426
|
+
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser routed buffered gatewaySessionKey=${gatewaySessionKey} source=${routed.source} idempotencyKey=${deliveryId}: ${err2 instanceof Error ? err2.message : String(err2)}`
|
|
87386
87427
|
);
|
|
87387
87428
|
logger.error(LogEvent.PROMPT_USER_FAILED, err2 instanceof Error ? err2 : new Error(String(err2)), gatewayOutboundExtra("routed_prompt_user", {
|
|
87388
87429
|
sessionKey: input.sessionKey ?? "",
|
|
@@ -87395,13 +87436,13 @@ var GatewayOutboundBehavior = class {
|
|
|
87395
87436
|
sessionKey: input.sessionKey ?? "",
|
|
87396
87437
|
gatewaySessionKey,
|
|
87397
87438
|
jobId: input.jobId ?? "",
|
|
87398
|
-
messageId:
|
|
87439
|
+
messageId: deliveryId,
|
|
87399
87440
|
source: routed.source,
|
|
87400
87441
|
status: "buffered"
|
|
87401
87442
|
}));
|
|
87402
87443
|
}
|
|
87403
87444
|
}
|
|
87404
|
-
async repairPromptUserRoute(input, staleGatewaySessionKey, source) {
|
|
87445
|
+
async repairPromptUserRoute(input, staleGatewaySessionKey, source, deliveryId) {
|
|
87405
87446
|
console.error(
|
|
87406
87447
|
`${GATEWAY_OUTBOUND_LOG_PREFIX} promptUser routeRepair latestUserSessions staleGatewaySessionKey=${staleGatewaySessionKey} jobId=${input.jobId ?? "(none)"}`
|
|
87407
87448
|
);
|
|
@@ -87409,7 +87450,8 @@ var GatewayOutboundBehavior = class {
|
|
|
87409
87450
|
userContent: input.userContent,
|
|
87410
87451
|
llmContent: input.llmContent,
|
|
87411
87452
|
...input.jobId ? { jobId: input.jobId } : {},
|
|
87412
|
-
...input.sessionKey ? { currentSessionKey: input.sessionKey } : {}
|
|
87453
|
+
...input.sessionKey ? { currentSessionKey: input.sessionKey } : {},
|
|
87454
|
+
idempotencyKey: deliveryId
|
|
87413
87455
|
});
|
|
87414
87456
|
assertLatestUserFanoutDelivered("okx-a2a.prompt_user", result);
|
|
87415
87457
|
this.persistDeliveredFallbackRoutes(input.jobId, result, { replaceExisting: true });
|
|
@@ -87620,7 +87662,7 @@ function buildSystemMessageIdempotencyKey(input) {
|
|
|
87620
87662
|
return `system-message:${identity3}`;
|
|
87621
87663
|
}
|
|
87622
87664
|
function stableHash2(value) {
|
|
87623
|
-
return (0,
|
|
87665
|
+
return (0, import_node_crypto8.createHash)("sha256").update(value).digest("hex").slice(0, 24);
|
|
87624
87666
|
}
|
|
87625
87667
|
|
|
87626
87668
|
// src/xmtp-send.ts
|
|
@@ -88129,7 +88171,7 @@ async function handleSqliteGroupSendCommand(params) {
|
|
|
88129
88171
|
});
|
|
88130
88172
|
logWithTimestamp(`[okx-agent-task] xmtp envelope ${rawText}`);
|
|
88131
88173
|
await conversation.send(rawText);
|
|
88132
|
-
const messageId = `outbound-${(0,
|
|
88174
|
+
const messageId = `outbound-${(0, import_node_crypto9.randomUUID)()}`;
|
|
88133
88175
|
await notifyAgentMessageToUserAttention({
|
|
88134
88176
|
direction: "outbound" /* OUTBOUND */,
|
|
88135
88177
|
sender: {
|
|
@@ -88267,7 +88309,7 @@ async function handleGroupSendCommand(params) {
|
|
|
88267
88309
|
logWithTimestamp(`[okx-agent-task] xmtp envelope ${rawText}`);
|
|
88268
88310
|
await conversation.send(rawText);
|
|
88269
88311
|
const now = Date.now();
|
|
88270
|
-
const messageId = `outbound-${(0,
|
|
88312
|
+
const messageId = `outbound-${(0, import_node_crypto9.randomUUID)()}`;
|
|
88271
88313
|
const stored = {
|
|
88272
88314
|
id: messageId,
|
|
88273
88315
|
direction: "outbound",
|
|
@@ -88476,7 +88518,7 @@ async function handleXmtpSendCommand(params) {
|
|
|
88476
88518
|
const rawText = target.chatType === "group" ? buildGroupReplyRaw(command, target, target.myXmtpAddress, localAgent) : buildDmReplyRaw(command, target, localAgent?.agentId ?? null);
|
|
88477
88519
|
await conversation.send(rawText);
|
|
88478
88520
|
const now = Date.now();
|
|
88479
|
-
const messageId = `outbound-${(0,
|
|
88521
|
+
const messageId = `outbound-${(0, import_node_crypto9.randomUUID)()}`;
|
|
88480
88522
|
const stored = {
|
|
88481
88523
|
id: messageId,
|
|
88482
88524
|
direction: "outbound",
|
|
@@ -89124,7 +89166,7 @@ function trimForUser2(value) {
|
|
|
89124
89166
|
}
|
|
89125
89167
|
|
|
89126
89168
|
// src/message-handler.ts
|
|
89127
|
-
var
|
|
89169
|
+
var import_node_crypto10 = require("node:crypto");
|
|
89128
89170
|
var PROCESSED_IDS_MAX = 1e3;
|
|
89129
89171
|
var processedMessageIds = /* @__PURE__ */ new Map();
|
|
89130
89172
|
function tryMarkProcessed(messageId) {
|
|
@@ -89876,7 +89918,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
89876
89918
|
timing.mark("payloadParse", parseStartedAt);
|
|
89877
89919
|
const systemNotification = chatType === "dm" && parsed.parsed ? extractSystemNotification(parsed.payload) : null;
|
|
89878
89920
|
if (systemNotification) {
|
|
89879
|
-
const systemMessageId = messageId || `system-${(0,
|
|
89921
|
+
const systemMessageId = messageId || `system-${(0, import_node_crypto10.randomUUID)()}`;
|
|
89880
89922
|
if (!systemNotification.agentId) {
|
|
89881
89923
|
logger.error(
|
|
89882
89924
|
LogEvent.INBOUND_DROP_DM_INVALID_PAYLOAD,
|
|
@@ -90078,7 +90120,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
90078
90120
|
toAgentId
|
|
90079
90121
|
});
|
|
90080
90122
|
const existingSession = deps.sessionStore?.getSession(sessionKey) ?? null;
|
|
90081
|
-
const routedMessageId = messageId || `group-${(0,
|
|
90123
|
+
const routedMessageId = messageId || `group-${(0, import_node_crypto10.randomUUID)()}`;
|
|
90082
90124
|
const consentState = ctx.conversation instanceof Group ? ctx.conversation.consentState : void 0;
|
|
90083
90125
|
if (shouldKeepInboundGroupPendingForBuyer({
|
|
90084
90126
|
consentState,
|
|
@@ -90171,7 +90213,7 @@ async function processFileMessage(ctx, deps, options = {}) {
|
|
|
90171
90213
|
return true;
|
|
90172
90214
|
}
|
|
90173
90215
|
const stored = {
|
|
90174
|
-
id: messageId || `local-${(0,
|
|
90216
|
+
id: messageId || `local-${(0, import_node_crypto10.randomUUID)()}`,
|
|
90175
90217
|
direction: "inbound",
|
|
90176
90218
|
route: route.route,
|
|
90177
90219
|
routeReason: route.routeReason,
|
|
@@ -90307,7 +90349,7 @@ function processOfflineFromCoreDeps(store, ctx, deps, options) {
|
|
|
90307
90349
|
function buildSystemStoredMessage(params) {
|
|
90308
90350
|
const now = Date.now();
|
|
90309
90351
|
return {
|
|
90310
|
-
id: params.id ?? `system-${now}-${(0,
|
|
90352
|
+
id: params.id ?? `system-${now}-${(0, import_node_crypto10.randomUUID)()}`,
|
|
90311
90353
|
direction: "system",
|
|
90312
90354
|
route: "backup",
|
|
90313
90355
|
routeReason: params.reason,
|
|
@@ -90432,7 +90474,7 @@ async function enqueueAiSessionMessageDispatch(params) {
|
|
|
90432
90474
|
}
|
|
90433
90475
|
|
|
90434
90476
|
// src/user-attention-watchers.ts
|
|
90435
|
-
var
|
|
90477
|
+
var import_node_crypto11 = require("node:crypto");
|
|
90436
90478
|
var 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.";
|
|
90437
90479
|
var USER_ATTENTION_WATCHER_SCAN_MS = 500;
|
|
90438
90480
|
var USER_ATTENTION_WATCHER_TTL_MS = 15e3;
|
|
@@ -90474,7 +90516,7 @@ function isOriginalParentProcessAlive(options) {
|
|
|
90474
90516
|
}
|
|
90475
90517
|
function registerUserAttentionWatcher(options) {
|
|
90476
90518
|
return options.store.registerUserAttentionWatcher({
|
|
90477
|
-
id: options.id ?? (0,
|
|
90519
|
+
id: options.id ?? (0, import_node_crypto11.randomUUID)(),
|
|
90478
90520
|
provider: options.provider,
|
|
90479
90521
|
jobId: options.jobId,
|
|
90480
90522
|
nowMs: options.nowMs ?? Date.now(),
|
|
@@ -90558,7 +90600,7 @@ function userWatchEventDeliveredSentryExtra(event) {
|
|
|
90558
90600
|
var environment = process.env.SENTRY_ENV === "dev" ? "dev" : "prod";
|
|
90559
90601
|
var SENTRY_CONFIG = {
|
|
90560
90602
|
projectName: "okx/openclaw-okx-a2a-extension",
|
|
90561
|
-
release: "0.0.
|
|
90603
|
+
release: "0.0.18-beta-8614cb2a91-260625165344",
|
|
90562
90604
|
environment
|
|
90563
90605
|
};
|
|
90564
90606
|
|
|
@@ -90785,12 +90827,12 @@ async function runListenerWithLock(options, paths) {
|
|
|
90785
90827
|
}));
|
|
90786
90828
|
}
|
|
90787
90829
|
});
|
|
90788
|
-
service.setPluginVersion("0.0.
|
|
90830
|
+
service.setPluginVersion("0.0.18-beta-8614cb2a91-260625165344");
|
|
90789
90831
|
await service.init();
|
|
90790
90832
|
const pluginVersionStatus = service.pluginVersionStatus;
|
|
90791
90833
|
if (pluginVersionStatus.unavailable) {
|
|
90792
90834
|
throw new Error(
|
|
90793
|
-
`@okxweb3/a2a-node v${"0.0.
|
|
90835
|
+
`@okxweb3/a2a-node v${"0.0.18-beta-8614cb2a91-260625165344"} is below the required minimum v${pluginVersionStatus.minVersion}`
|
|
90794
90836
|
);
|
|
90795
90837
|
}
|
|
90796
90838
|
const systemConfig = service.getSystemConfig();
|
|
@@ -90808,7 +90850,7 @@ async function runListenerWithLock(options, paths) {
|
|
|
90808
90850
|
onchainosAgentId: "*",
|
|
90809
90851
|
reason: "system-config missing sentryDsn",
|
|
90810
90852
|
pluginId: "@okxweb3/a2a-node",
|
|
90811
|
-
pluginVersion: "0.0.
|
|
90853
|
+
pluginVersion: "0.0.18-beta-8614cb2a91-260625165344"
|
|
90812
90854
|
});
|
|
90813
90855
|
}
|
|
90814
90856
|
logWithTimestamp(
|
package/package.json
CHANGED