@searchfe/openclaw-baiduapp 0.1.5 → 0.1.6-beta.1
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/index.d.ts +8 -12
- package/dist/index.js +231 -280
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,173 +6,6 @@ var __export = (target, all) => {
|
|
|
6
6
|
for (var name in all)
|
|
7
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
8
|
};
|
|
9
|
-
function decodeEncodingAESKey(encodingAESKey) {
|
|
10
|
-
const trimmed = encodingAESKey.trim();
|
|
11
|
-
if (!trimmed) {
|
|
12
|
-
throw new Error("encodingAESKey missing");
|
|
13
|
-
}
|
|
14
|
-
const withPadding = trimmed.endsWith("=") ? trimmed : `${trimmed}=`;
|
|
15
|
-
const key = Buffer.from(withPadding, "base64");
|
|
16
|
-
if (key.length !== 32) {
|
|
17
|
-
throw new Error(`invalid encodingAESKey (expected 32 bytes after base64 decode, got ${key.length})`);
|
|
18
|
-
}
|
|
19
|
-
return key;
|
|
20
|
-
}
|
|
21
|
-
var PKCS7_BLOCK_SIZE = 32;
|
|
22
|
-
function pkcs7Pad(buf, blockSize) {
|
|
23
|
-
const mod = buf.length % blockSize;
|
|
24
|
-
const pad = mod === 0 ? blockSize : blockSize - mod;
|
|
25
|
-
return Buffer.concat([buf, Buffer.alloc(pad, pad)]);
|
|
26
|
-
}
|
|
27
|
-
function pkcs7Unpad(buf, blockSize) {
|
|
28
|
-
if (buf.length === 0) {
|
|
29
|
-
throw new Error("invalid pkcs7 payload");
|
|
30
|
-
}
|
|
31
|
-
const pad = buf[buf.length - 1];
|
|
32
|
-
if (!pad || pad < 1 || pad > blockSize || pad > buf.length) {
|
|
33
|
-
throw new Error("invalid pkcs7 padding");
|
|
34
|
-
}
|
|
35
|
-
for (let i = 1; i <= pad; i += 1) {
|
|
36
|
-
if (buf[buf.length - i] !== pad) {
|
|
37
|
-
throw new Error("invalid pkcs7 padding");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return buf.subarray(0, buf.length - pad);
|
|
41
|
-
}
|
|
42
|
-
function sha1Hex(input) {
|
|
43
|
-
return crypto.createHash("sha1").update(input).digest("hex");
|
|
44
|
-
}
|
|
45
|
-
function computeBaiduAppMsgSignature(params) {
|
|
46
|
-
const parts = [params.token, params.timestamp, params.nonce, params.encrypt].map((value) => String(value ?? "")).sort();
|
|
47
|
-
return sha1Hex(parts.join(""));
|
|
48
|
-
}
|
|
49
|
-
function verifyBaiduAppSignature(params) {
|
|
50
|
-
const expected = computeBaiduAppMsgSignature({
|
|
51
|
-
token: params.token,
|
|
52
|
-
timestamp: params.timestamp,
|
|
53
|
-
nonce: params.nonce,
|
|
54
|
-
encrypt: params.encrypt
|
|
55
|
-
});
|
|
56
|
-
return expected === params.signature;
|
|
57
|
-
}
|
|
58
|
-
function decryptBaiduAppEncrypted(params) {
|
|
59
|
-
const aesKey = decodeEncodingAESKey(params.encodingAESKey);
|
|
60
|
-
const iv = aesKey.subarray(0, 16);
|
|
61
|
-
const decipher = crypto.createDecipheriv("aes-256-cbc", aesKey, iv);
|
|
62
|
-
decipher.setAutoPadding(false);
|
|
63
|
-
const decryptedPadded = Buffer.concat([decipher.update(Buffer.from(params.encrypt, "base64")), decipher.final()]);
|
|
64
|
-
const decrypted = pkcs7Unpad(decryptedPadded, PKCS7_BLOCK_SIZE);
|
|
65
|
-
if (decrypted.length < 20) {
|
|
66
|
-
throw new Error(`invalid decrypted payload (expected at least 20 bytes, got ${decrypted.length})`);
|
|
67
|
-
}
|
|
68
|
-
const msgLen = decrypted.readUInt32BE(16);
|
|
69
|
-
const msgStart = 20;
|
|
70
|
-
const msgEnd = msgStart + msgLen;
|
|
71
|
-
if (msgEnd > decrypted.length) {
|
|
72
|
-
throw new Error(`invalid decrypted msg length (msgEnd=${msgEnd}, payloadLength=${decrypted.length})`);
|
|
73
|
-
}
|
|
74
|
-
return decrypted.subarray(msgStart, msgEnd).toString("utf8");
|
|
75
|
-
}
|
|
76
|
-
function encryptBaiduAppPlaintext(params) {
|
|
77
|
-
const aesKey = decodeEncodingAESKey(params.encodingAESKey);
|
|
78
|
-
const iv = aesKey.subarray(0, 16);
|
|
79
|
-
const random16 = crypto.randomBytes(16);
|
|
80
|
-
const msg = Buffer.from(params.plaintext ?? "", "utf8");
|
|
81
|
-
const msgLen = Buffer.alloc(4);
|
|
82
|
-
msgLen.writeUInt32BE(msg.length, 0);
|
|
83
|
-
const raw = Buffer.concat([random16, msgLen, msg]);
|
|
84
|
-
const padded = pkcs7Pad(raw, PKCS7_BLOCK_SIZE);
|
|
85
|
-
const cipher = crypto.createCipheriv("aes-256-cbc", aesKey, iv);
|
|
86
|
-
cipher.setAutoPadding(false);
|
|
87
|
-
const encrypted = Buffer.concat([cipher.update(padded), cipher.final()]);
|
|
88
|
-
return encrypted.toString("base64");
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// src/shared/logger.ts
|
|
92
|
-
function createLogger(prefix, opts) {
|
|
93
|
-
const logFn = opts?.log ?? console.log;
|
|
94
|
-
const errorFn = opts?.error ?? console.error;
|
|
95
|
-
return {
|
|
96
|
-
debug: (msg) => logFn(`[${prefix}] [DEBUG] ${msg}`),
|
|
97
|
-
info: (msg) => logFn(`[${prefix}] ${msg}`),
|
|
98
|
-
warn: (msg) => logFn(`[${prefix}] [WARN] ${msg}`),
|
|
99
|
-
error: (msg) => errorFn(`[${prefix}] [ERROR] ${msg}`)
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
var require2 = createRequire(import.meta.url);
|
|
103
|
-
var pkg = require2("../package.json");
|
|
104
|
-
var PLUGIN_VERSION = pkg.version;
|
|
105
|
-
|
|
106
|
-
// src/api.ts
|
|
107
|
-
var logger = createLogger("openclaw-baiduapp");
|
|
108
|
-
async function sendBaiduAppMessage(account, message, options) {
|
|
109
|
-
if (!account.canSendActive) {
|
|
110
|
-
logger.error("Account not configured for active sending (missing appKey, token, or encodingAESKey)");
|
|
111
|
-
return {
|
|
112
|
-
ok: false,
|
|
113
|
-
errcode: -1,
|
|
114
|
-
errmsg: "Account not configured for active sending (missing appKey, token, or encodingAESKey)"
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
const payload = {
|
|
118
|
-
msgtype: "text",
|
|
119
|
-
text: { content: message },
|
|
120
|
-
version: PLUGIN_VERSION,
|
|
121
|
-
...options?.msgid != null ? { msgid: options.msgid } : {},
|
|
122
|
-
...options?.streamId != null ? { streamId: options.streamId } : {},
|
|
123
|
-
...options?.chunkKey != null ? { chunkKey: options.chunkKey } : {}
|
|
124
|
-
};
|
|
125
|
-
const plaintext = JSON.stringify(payload);
|
|
126
|
-
const encrypt = encryptBaiduAppPlaintext({
|
|
127
|
-
encodingAESKey: account.encodingAESKey ?? "",
|
|
128
|
-
plaintext
|
|
129
|
-
});
|
|
130
|
-
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
131
|
-
const nonce = crypto.randomBytes(8).toString("hex");
|
|
132
|
-
const msgSignature = computeBaiduAppMsgSignature({
|
|
133
|
-
token: account.token ?? "",
|
|
134
|
-
timestamp,
|
|
135
|
-
nonce,
|
|
136
|
-
encrypt
|
|
137
|
-
});
|
|
138
|
-
const sendMessageUrl = `${account.apiBase}/chat/openclaw/callback`;
|
|
139
|
-
const url = `${sendMessageUrl}?timestamp=${encodeURIComponent(timestamp)}&ak=${encodeURIComponent(account.appKey ?? "")}&nonce=${encodeURIComponent(nonce)}&msg_signature=${encodeURIComponent(msgSignature)}`;
|
|
140
|
-
const body = JSON.stringify({ encrypt });
|
|
141
|
-
logger.info(`POST ${url}`);
|
|
142
|
-
logger.debug(`request body: ${body}`);
|
|
143
|
-
const resp = await fetch(url, {
|
|
144
|
-
method: "POST",
|
|
145
|
-
body,
|
|
146
|
-
headers: { "Content-Type": "application/json" }
|
|
147
|
-
});
|
|
148
|
-
const text = await resp.text();
|
|
149
|
-
if (!text) {
|
|
150
|
-
const errmsg = `empty response from server (status=${resp.status})`;
|
|
151
|
-
logger.error(`request failed: ${errmsg}`);
|
|
152
|
-
return { ok: false, errcode: resp.status, errmsg };
|
|
153
|
-
}
|
|
154
|
-
let data;
|
|
155
|
-
try {
|
|
156
|
-
data = JSON.parse(text);
|
|
157
|
-
} catch {
|
|
158
|
-
const errmsg = `invalid JSON response (status=${resp.status}, body=${text.slice(0, 200)})`;
|
|
159
|
-
logger.error(`request failed: ${errmsg}`);
|
|
160
|
-
return { ok: false, errcode: resp.status, errmsg };
|
|
161
|
-
}
|
|
162
|
-
const result = {
|
|
163
|
-
ok: data.errcode === 0,
|
|
164
|
-
errcode: data.errcode,
|
|
165
|
-
errmsg: data.errmsg,
|
|
166
|
-
invaliduser: data.invaliduser,
|
|
167
|
-
msgid: data.msgid
|
|
168
|
-
};
|
|
169
|
-
if (result.ok) {
|
|
170
|
-
logger.info(`request succeeded: msgid=${result.msgid ?? "unknown"}`);
|
|
171
|
-
} else {
|
|
172
|
-
logger.error(`request failed: errcode=${result.errcode} errmsg=${result.errmsg ?? "unknown"}`);
|
|
173
|
-
}
|
|
174
|
-
return result;
|
|
175
|
-
}
|
|
176
9
|
|
|
177
10
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
178
11
|
var external_exports = {};
|
|
@@ -4338,15 +4171,172 @@ function resolveBaiduAppAccount(params) {
|
|
|
4338
4171
|
config: merged
|
|
4339
4172
|
};
|
|
4340
4173
|
}
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4174
|
+
|
|
4175
|
+
// src/shared/logger.ts
|
|
4176
|
+
function createLogger(prefix, opts) {
|
|
4177
|
+
const logFn = opts?.log ?? console.log;
|
|
4178
|
+
const errorFn = opts?.error ?? console.error;
|
|
4179
|
+
return {
|
|
4180
|
+
debug: (msg) => logFn(`[${prefix}] [DEBUG] ${msg}`),
|
|
4181
|
+
info: (msg) => logFn(`[${prefix}] ${msg}`),
|
|
4182
|
+
warn: (msg) => logFn(`[${prefix}] [WARN] ${msg}`),
|
|
4183
|
+
error: (msg) => errorFn(`[${prefix}] [ERROR] ${msg}`)
|
|
4184
|
+
};
|
|
4185
|
+
}
|
|
4186
|
+
function decodeEncodingAESKey(encodingAESKey) {
|
|
4187
|
+
const trimmed = encodingAESKey.trim();
|
|
4188
|
+
if (!trimmed) {
|
|
4189
|
+
throw new Error("encodingAESKey missing");
|
|
4190
|
+
}
|
|
4191
|
+
const withPadding = trimmed.endsWith("=") ? trimmed : `${trimmed}=`;
|
|
4192
|
+
const key = Buffer.from(withPadding, "base64");
|
|
4193
|
+
if (key.length !== 32) {
|
|
4194
|
+
throw new Error(`invalid encodingAESKey (expected 32 bytes after base64 decode, got ${key.length})`);
|
|
4195
|
+
}
|
|
4196
|
+
return key;
|
|
4197
|
+
}
|
|
4198
|
+
var PKCS7_BLOCK_SIZE = 32;
|
|
4199
|
+
function pkcs7Pad(buf, blockSize) {
|
|
4200
|
+
const mod = buf.length % blockSize;
|
|
4201
|
+
const pad = mod === 0 ? blockSize : blockSize - mod;
|
|
4202
|
+
return Buffer.concat([buf, Buffer.alloc(pad, pad)]);
|
|
4203
|
+
}
|
|
4204
|
+
function pkcs7Unpad(buf, blockSize) {
|
|
4205
|
+
if (buf.length === 0) {
|
|
4206
|
+
throw new Error("invalid pkcs7 payload");
|
|
4207
|
+
}
|
|
4208
|
+
const pad = buf[buf.length - 1];
|
|
4209
|
+
if (!pad || pad < 1 || pad > blockSize || pad > buf.length) {
|
|
4210
|
+
throw new Error("invalid pkcs7 padding");
|
|
4211
|
+
}
|
|
4212
|
+
for (let i = 1; i <= pad; i += 1) {
|
|
4213
|
+
if (buf[buf.length - i] !== pad) {
|
|
4214
|
+
throw new Error("invalid pkcs7 padding");
|
|
4347
4215
|
}
|
|
4348
4216
|
}
|
|
4349
|
-
return
|
|
4217
|
+
return buf.subarray(0, buf.length - pad);
|
|
4218
|
+
}
|
|
4219
|
+
function sha1Hex(input) {
|
|
4220
|
+
return crypto.createHash("sha1").update(input).digest("hex");
|
|
4221
|
+
}
|
|
4222
|
+
function computeBaiduAppMsgSignature(params) {
|
|
4223
|
+
const parts = [params.token, params.timestamp, params.nonce, params.encrypt].map((value) => String(value ?? "")).sort();
|
|
4224
|
+
return sha1Hex(parts.join(""));
|
|
4225
|
+
}
|
|
4226
|
+
function verifyBaiduAppSignature(params) {
|
|
4227
|
+
const expected = computeBaiduAppMsgSignature({
|
|
4228
|
+
token: params.token,
|
|
4229
|
+
timestamp: params.timestamp,
|
|
4230
|
+
nonce: params.nonce,
|
|
4231
|
+
encrypt: params.encrypt
|
|
4232
|
+
});
|
|
4233
|
+
return expected === params.signature;
|
|
4234
|
+
}
|
|
4235
|
+
function decryptBaiduAppEncrypted(params) {
|
|
4236
|
+
const aesKey = decodeEncodingAESKey(params.encodingAESKey);
|
|
4237
|
+
const iv = aesKey.subarray(0, 16);
|
|
4238
|
+
const decipher = crypto.createDecipheriv("aes-256-cbc", aesKey, iv);
|
|
4239
|
+
decipher.setAutoPadding(false);
|
|
4240
|
+
const decryptedPadded = Buffer.concat([decipher.update(Buffer.from(params.encrypt, "base64")), decipher.final()]);
|
|
4241
|
+
const decrypted = pkcs7Unpad(decryptedPadded, PKCS7_BLOCK_SIZE);
|
|
4242
|
+
if (decrypted.length < 20) {
|
|
4243
|
+
throw new Error(`invalid decrypted payload (expected at least 20 bytes, got ${decrypted.length})`);
|
|
4244
|
+
}
|
|
4245
|
+
const msgLen = decrypted.readUInt32BE(16);
|
|
4246
|
+
const msgStart = 20;
|
|
4247
|
+
const msgEnd = msgStart + msgLen;
|
|
4248
|
+
if (msgEnd > decrypted.length) {
|
|
4249
|
+
throw new Error(`invalid decrypted msg length (msgEnd=${msgEnd}, payloadLength=${decrypted.length})`);
|
|
4250
|
+
}
|
|
4251
|
+
return decrypted.subarray(msgStart, msgEnd).toString("utf8");
|
|
4252
|
+
}
|
|
4253
|
+
function encryptBaiduAppPlaintext(params) {
|
|
4254
|
+
const aesKey = decodeEncodingAESKey(params.encodingAESKey);
|
|
4255
|
+
const iv = aesKey.subarray(0, 16);
|
|
4256
|
+
const random16 = crypto.randomBytes(16);
|
|
4257
|
+
const msg = Buffer.from(params.plaintext ?? "", "utf8");
|
|
4258
|
+
const msgLen = Buffer.alloc(4);
|
|
4259
|
+
msgLen.writeUInt32BE(msg.length, 0);
|
|
4260
|
+
const raw = Buffer.concat([random16, msgLen, msg]);
|
|
4261
|
+
const padded = pkcs7Pad(raw, PKCS7_BLOCK_SIZE);
|
|
4262
|
+
const cipher = crypto.createCipheriv("aes-256-cbc", aesKey, iv);
|
|
4263
|
+
cipher.setAutoPadding(false);
|
|
4264
|
+
const encrypted = Buffer.concat([cipher.update(padded), cipher.final()]);
|
|
4265
|
+
return encrypted.toString("base64");
|
|
4266
|
+
}
|
|
4267
|
+
var require2 = createRequire(import.meta.url);
|
|
4268
|
+
var pkg = require2("../package.json");
|
|
4269
|
+
var PLUGIN_VERSION = pkg.version;
|
|
4270
|
+
|
|
4271
|
+
// src/api.ts
|
|
4272
|
+
var logger = createLogger("openclaw-baiduapp");
|
|
4273
|
+
async function sendBaiduAppMessage(account, message, options) {
|
|
4274
|
+
if (!account.canSendActive) {
|
|
4275
|
+
logger.error("Account not configured for active sending (missing appKey, token, or encodingAESKey)");
|
|
4276
|
+
return {
|
|
4277
|
+
ok: false,
|
|
4278
|
+
errcode: -1,
|
|
4279
|
+
errmsg: "Account not configured for active sending (missing appKey, token, or encodingAESKey)"
|
|
4280
|
+
};
|
|
4281
|
+
}
|
|
4282
|
+
const payload = {
|
|
4283
|
+
msgtype: "text",
|
|
4284
|
+
text: { content: message },
|
|
4285
|
+
version: PLUGIN_VERSION,
|
|
4286
|
+
...options?.msgid != null ? { msgid: options.msgid } : {},
|
|
4287
|
+
...options?.streamId != null ? { streamId: options.streamId } : {},
|
|
4288
|
+
...options?.chunkKey != null ? { chunkKey: options.chunkKey } : {}
|
|
4289
|
+
};
|
|
4290
|
+
const plaintext = JSON.stringify(payload);
|
|
4291
|
+
const encrypt = encryptBaiduAppPlaintext({
|
|
4292
|
+
encodingAESKey: account.encodingAESKey ?? "",
|
|
4293
|
+
plaintext
|
|
4294
|
+
});
|
|
4295
|
+
const timestamp = String(Math.floor(Date.now() / 1e3));
|
|
4296
|
+
const nonce = crypto.randomBytes(8).toString("hex");
|
|
4297
|
+
const msgSignature = computeBaiduAppMsgSignature({
|
|
4298
|
+
token: account.token ?? "",
|
|
4299
|
+
timestamp,
|
|
4300
|
+
nonce,
|
|
4301
|
+
encrypt
|
|
4302
|
+
});
|
|
4303
|
+
const sendMessageUrl = `${account.apiBase}/chat/openclaw/callback`;
|
|
4304
|
+
const url = `${sendMessageUrl}?timestamp=${encodeURIComponent(timestamp)}&ak=${encodeURIComponent(account.appKey ?? "")}&nonce=${encodeURIComponent(nonce)}&msg_signature=${encodeURIComponent(msgSignature)}`;
|
|
4305
|
+
const body = JSON.stringify({ encrypt });
|
|
4306
|
+
logger.info(`POST ${url}`);
|
|
4307
|
+
logger.debug(`request body: ${body}`);
|
|
4308
|
+
const resp = await fetch(url, {
|
|
4309
|
+
method: "POST",
|
|
4310
|
+
body,
|
|
4311
|
+
headers: { "Content-Type": "application/json" }
|
|
4312
|
+
});
|
|
4313
|
+
const text = await resp.text();
|
|
4314
|
+
if (!text) {
|
|
4315
|
+
const errmsg = `empty response from server (status=${resp.status})`;
|
|
4316
|
+
logger.error(`request failed: ${errmsg}`);
|
|
4317
|
+
return { ok: false, errcode: resp.status, errmsg };
|
|
4318
|
+
}
|
|
4319
|
+
let data;
|
|
4320
|
+
try {
|
|
4321
|
+
data = JSON.parse(text);
|
|
4322
|
+
} catch {
|
|
4323
|
+
const errmsg = `invalid JSON response (status=${resp.status}, body=${text.slice(0, 200)})`;
|
|
4324
|
+
logger.error(`request failed: ${errmsg}`);
|
|
4325
|
+
return { ok: false, errcode: resp.status, errmsg };
|
|
4326
|
+
}
|
|
4327
|
+
const result = {
|
|
4328
|
+
ok: data.errcode === 0,
|
|
4329
|
+
errcode: data.errcode,
|
|
4330
|
+
errmsg: data.errmsg,
|
|
4331
|
+
invaliduser: data.invaliduser,
|
|
4332
|
+
msgid: data.msgid
|
|
4333
|
+
};
|
|
4334
|
+
if (result.ok) {
|
|
4335
|
+
logger.info(`request succeeded: msgid=${result.msgid ?? "unknown"}`);
|
|
4336
|
+
} else {
|
|
4337
|
+
logger.error(`request failed: errcode=${result.errcode} errmsg=${result.errmsg ?? "unknown"}`);
|
|
4338
|
+
}
|
|
4339
|
+
return result;
|
|
4350
4340
|
}
|
|
4351
4341
|
|
|
4352
4342
|
// src/bot.ts
|
|
@@ -4367,24 +4357,24 @@ function extractBaiduAppContent(msg) {
|
|
|
4367
4357
|
async function dispatchBaiduAppMessage(params) {
|
|
4368
4358
|
const { cfg, account, msg, core, hooks } = params;
|
|
4369
4359
|
const safeCfg = cfg ?? {};
|
|
4370
|
-
const
|
|
4360
|
+
const logger2 = createLogger("openclaw-baiduapp", { log: params.log, error: params.error });
|
|
4371
4361
|
const channel = core.channel;
|
|
4372
4362
|
if (!channel?.routing?.resolveAgentRoute || !channel.reply?.dispatchReplyWithBufferedBlockDispatcher) {
|
|
4373
|
-
|
|
4363
|
+
logger2.warn("core routing or buffered dispatcher missing, skipping dispatch");
|
|
4374
4364
|
return;
|
|
4375
4365
|
}
|
|
4376
|
-
const userId = account.appKey ?? account.accountId;
|
|
4377
4366
|
const route = channel.routing.resolveAgentRoute({
|
|
4378
4367
|
cfg: safeCfg,
|
|
4379
4368
|
channel: "openclaw-baiduapp",
|
|
4380
|
-
accountId:
|
|
4381
|
-
peer: { kind: "dm", id:
|
|
4369
|
+
accountId: account.accountId,
|
|
4370
|
+
peer: { kind: "dm", id: "default" }
|
|
4382
4371
|
});
|
|
4383
|
-
|
|
4372
|
+
logger2.info(`SessionKey: ${route.sessionKey}`);
|
|
4373
|
+
logger2.info(
|
|
4384
4374
|
`route resolved: sessionKey=${route.sessionKey} agentId=${route.agentId ?? "default"} accountId=${route.accountId}`
|
|
4385
4375
|
);
|
|
4386
4376
|
const rawBody = extractBaiduAppContent(msg);
|
|
4387
|
-
|
|
4377
|
+
logger2.debug(
|
|
4388
4378
|
`message content extracted: len=${rawBody.length} preview="${rawBody.slice(0, 80)}${rawBody.length > 80 ? "..." : ""}"`
|
|
4389
4379
|
);
|
|
4390
4380
|
const storePath = channel.session?.resolveStorePath?.(safeCfg.session?.store, {
|
|
@@ -4395,10 +4385,9 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4395
4385
|
sessionKey: route.sessionKey
|
|
4396
4386
|
}) ?? void 0 : void 0;
|
|
4397
4387
|
const envelopeOptions = channel.reply?.resolveEnvelopeFormatOptions ? channel.reply.resolveEnvelopeFormatOptions(safeCfg) : void 0;
|
|
4398
|
-
const fromLabel = `user:${userId}`;
|
|
4399
4388
|
const body = channel.reply?.formatAgentEnvelope ? channel.reply.formatAgentEnvelope({
|
|
4400
4389
|
channel: "Baidu App",
|
|
4401
|
-
from:
|
|
4390
|
+
from: "",
|
|
4402
4391
|
previousTimestamp,
|
|
4403
4392
|
envelope: envelopeOptions,
|
|
4404
4393
|
body: rawBody
|
|
@@ -4408,32 +4397,34 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4408
4397
|
Body: body,
|
|
4409
4398
|
RawBody: rawBody,
|
|
4410
4399
|
CommandBody: rawBody,
|
|
4411
|
-
From:
|
|
4412
|
-
To:
|
|
4400
|
+
From: "openclaw-baiduapp:user",
|
|
4401
|
+
To: "user",
|
|
4413
4402
|
SessionKey: route.sessionKey,
|
|
4414
|
-
AccountId: route.accountId,
|
|
4403
|
+
AccountId: route.accountId ?? account.accountId,
|
|
4415
4404
|
ChatType: "direct",
|
|
4416
|
-
ConversationLabel:
|
|
4405
|
+
ConversationLabel: "user",
|
|
4417
4406
|
Provider: "openclaw-baiduapp",
|
|
4418
4407
|
Surface: "openclaw-baiduapp",
|
|
4419
4408
|
MessageSid: msgid,
|
|
4420
4409
|
OriginatingChannel: "openclaw-baiduapp",
|
|
4421
|
-
OriginatingTo:
|
|
4410
|
+
OriginatingTo: "user",
|
|
4411
|
+
CommandAuthorized: true
|
|
4422
4412
|
}) : {
|
|
4423
4413
|
Body: body,
|
|
4424
4414
|
RawBody: rawBody,
|
|
4425
4415
|
CommandBody: rawBody,
|
|
4426
|
-
From:
|
|
4427
|
-
To:
|
|
4416
|
+
From: "openclaw-baiduapp:user",
|
|
4417
|
+
To: "user",
|
|
4428
4418
|
SessionKey: route.sessionKey,
|
|
4429
|
-
AccountId: route.accountId,
|
|
4419
|
+
AccountId: route.accountId ?? account.accountId,
|
|
4430
4420
|
ChatType: "direct",
|
|
4431
|
-
ConversationLabel:
|
|
4421
|
+
ConversationLabel: "user",
|
|
4432
4422
|
Provider: "openclaw-baiduapp",
|
|
4433
4423
|
Surface: "openclaw-baiduapp",
|
|
4434
4424
|
MessageSid: msgid,
|
|
4435
4425
|
OriginatingChannel: "openclaw-baiduapp",
|
|
4436
|
-
OriginatingTo:
|
|
4426
|
+
OriginatingTo: "user",
|
|
4427
|
+
CommandAuthorized: true
|
|
4437
4428
|
};
|
|
4438
4429
|
if (channel.session?.recordInboundSession && storePath) {
|
|
4439
4430
|
await channel.session.recordInboundSession({
|
|
@@ -4441,7 +4432,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4441
4432
|
sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
|
|
4442
4433
|
ctx: ctxPayload,
|
|
4443
4434
|
onRecordError: (err) => {
|
|
4444
|
-
|
|
4435
|
+
logger2.error(`openclaw-baiduapp: failed updating session meta: ${String(err)}`);
|
|
4445
4436
|
}
|
|
4446
4437
|
});
|
|
4447
4438
|
}
|
|
@@ -4450,7 +4441,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4450
4441
|
channel: "openclaw-baiduapp",
|
|
4451
4442
|
accountId: account.accountId
|
|
4452
4443
|
}) : void 0;
|
|
4453
|
-
|
|
4444
|
+
logger2.info(`dispatching to agent: sessionKey=${route.sessionKey}`);
|
|
4454
4445
|
await channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
4455
4446
|
ctx: ctxPayload,
|
|
4456
4447
|
cfg: safeCfg,
|
|
@@ -4458,20 +4449,20 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4458
4449
|
deliver: async (payload) => {
|
|
4459
4450
|
const rawText = payload.text ?? "";
|
|
4460
4451
|
if (!rawText.trim()) {
|
|
4461
|
-
|
|
4452
|
+
logger2.debug("deliver callback: empty text, skipping");
|
|
4462
4453
|
return;
|
|
4463
4454
|
}
|
|
4464
4455
|
const converted = channel.text?.convertMarkdownTables && tableMode ? channel.text.convertMarkdownTables(rawText, tableMode) : rawText;
|
|
4465
|
-
|
|
4456
|
+
logger2.debug(`deliver callback: textLen=${converted.length}`);
|
|
4466
4457
|
hooks.onChunk(converted);
|
|
4467
4458
|
},
|
|
4468
4459
|
onError: (err, info) => {
|
|
4469
4460
|
hooks.onError?.(err);
|
|
4470
|
-
|
|
4461
|
+
logger2.error(`${info.kind} reply failed: ${String(err)}`);
|
|
4471
4462
|
}
|
|
4472
4463
|
}
|
|
4473
4464
|
});
|
|
4474
|
-
|
|
4465
|
+
logger2.info(`agent reply dispatch complete: sessionKey=${route.sessionKey}`);
|
|
4475
4466
|
}
|
|
4476
4467
|
|
|
4477
4468
|
// src/runtime.ts
|
|
@@ -4760,7 +4751,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4760
4751
|
const nonce = query.get("nonce") ?? "";
|
|
4761
4752
|
const signature = resolveSignatureParam(query);
|
|
4762
4753
|
const primary = targets[0];
|
|
4763
|
-
const
|
|
4754
|
+
const logger2 = buildLogger(primary);
|
|
4764
4755
|
if (req.method === "GET") {
|
|
4765
4756
|
const echostr = query.get("echostr") ?? "";
|
|
4766
4757
|
if (!timestamp || !nonce || !signature || !echostr) {
|
|
@@ -4796,7 +4787,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4796
4787
|
jsonError(res, "decrypt failed");
|
|
4797
4788
|
return true;
|
|
4798
4789
|
}
|
|
4799
|
-
const selected2 = selectDecryptedTarget({ candidates: decryptedCandidates2, logger:
|
|
4790
|
+
const selected2 = selectDecryptedTarget({ candidates: decryptedCandidates2, logger: logger2 });
|
|
4800
4791
|
jsonOk(res, selected2.plaintext);
|
|
4801
4792
|
return true;
|
|
4802
4793
|
}
|
|
@@ -4824,14 +4815,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4824
4815
|
msgSignature = xmlData.MsgSignature ?? signature;
|
|
4825
4816
|
msgTimestamp = xmlData.TimeStamp ?? timestamp;
|
|
4826
4817
|
msgNonce = xmlData.Nonce ?? nonce;
|
|
4827
|
-
|
|
4818
|
+
logger2.info(`inbound xml parsed: hasEncrypt=${Boolean(encrypt)}, msg_signature=${msgSignature ? "yes" : "no"}`);
|
|
4828
4819
|
} else {
|
|
4829
4820
|
try {
|
|
4830
4821
|
const record = JSON.parse(rawBody);
|
|
4831
4822
|
encrypt = String(record.encrypt ?? record.Encrypt ?? "");
|
|
4832
|
-
|
|
4823
|
+
logger2.info(`inbound json parsed: hasEncrypt=${Boolean(encrypt)}`);
|
|
4833
4824
|
} catch {
|
|
4834
|
-
|
|
4825
|
+
logger2.warn(`inbound payload parse failed: not valid xml or json`);
|
|
4835
4826
|
jsonError(res, "invalid payload format");
|
|
4836
4827
|
return true;
|
|
4837
4828
|
}
|
|
@@ -4853,14 +4844,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4853
4844
|
});
|
|
4854
4845
|
});
|
|
4855
4846
|
if (signatureMatched.length === 0) {
|
|
4856
|
-
|
|
4847
|
+
logger2.warn(`signature verification failed: checked ${targets.length} account(s), none matched`);
|
|
4857
4848
|
jsonError(res, "unauthorized");
|
|
4858
4849
|
return true;
|
|
4859
4850
|
}
|
|
4860
|
-
|
|
4851
|
+
logger2.debug(`signature verified: ${signatureMatched.length} account(s) matched`);
|
|
4861
4852
|
const decryptable = signatureMatched.filter((candidate) => Boolean(candidate.account.encodingAESKey));
|
|
4862
4853
|
if (decryptable.length === 0) {
|
|
4863
|
-
|
|
4854
|
+
logger2.warn(`no account has encodingAESKey configured`);
|
|
4864
4855
|
jsonError(res, "openclaw-baiduapp not configured");
|
|
4865
4856
|
return true;
|
|
4866
4857
|
}
|
|
@@ -4869,14 +4860,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4869
4860
|
encrypt
|
|
4870
4861
|
});
|
|
4871
4862
|
if (decryptedCandidates.length === 0) {
|
|
4872
|
-
|
|
4863
|
+
logger2.warn(`decrypt failed for all ${decryptable.length} candidate account(s)`);
|
|
4873
4864
|
jsonError(res, "decrypt failed");
|
|
4874
4865
|
return true;
|
|
4875
4866
|
}
|
|
4876
|
-
const selected = selectDecryptedTarget({ candidates: decryptedCandidates, logger:
|
|
4867
|
+
const selected = selectDecryptedTarget({ candidates: decryptedCandidates, logger: logger2 });
|
|
4877
4868
|
const target = selected.target;
|
|
4878
4869
|
if (!target.account.configured || !target.account.token || !target.account.encodingAESKey) {
|
|
4879
|
-
|
|
4870
|
+
logger2.warn(`selected account ${target.account.accountId} not fully configured`);
|
|
4880
4871
|
jsonError(res, "openclaw-baiduapp not configured");
|
|
4881
4872
|
return true;
|
|
4882
4873
|
}
|
|
@@ -4884,11 +4875,11 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4884
4875
|
target.statusSink?.({ lastInboundAt: Date.now() });
|
|
4885
4876
|
const msgtype = String(msg.msgtype ?? msg.MsgType ?? "").toLowerCase();
|
|
4886
4877
|
const msgid = msg.msgid ?? msg.MsgId ? String(msg.msgid ?? msg.MsgId) : void 0;
|
|
4887
|
-
|
|
4878
|
+
logger2.info(`inbound: type=${msgtype || "unknown"} msgid=${msgid ?? "none"} account=${target.account.accountId}`);
|
|
4888
4879
|
if (msgtype === "stream") {
|
|
4889
4880
|
const streamId2 = String(msg.stream?.id ?? "").trim();
|
|
4890
4881
|
const state = streamId2 ? streams.get(streamId2) : void 0;
|
|
4891
|
-
|
|
4882
|
+
logger2.info(
|
|
4892
4883
|
`[REPLY-MODE:STREAM-POLL] stream poll request: streamId=${streamId2 || "none"} found=${Boolean(state)} finished=${state?.finished ?? "n/a"} contentLen=${state?.content.length ?? 0}`
|
|
4893
4884
|
);
|
|
4894
4885
|
const reply = state ? buildStreamReplyFromState(state) : buildStreamReplyFromState({
|
|
@@ -4909,7 +4900,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4909
4900
|
}
|
|
4910
4901
|
if (msgid && msgidToStreamId.has(msgid)) {
|
|
4911
4902
|
const streamId2 = msgidToStreamId.get(msgid) ?? "";
|
|
4912
|
-
|
|
4903
|
+
logger2.debug(`duplicate msgid detected: msgid=${msgid} streamId=${streamId2}, returning placeholder`);
|
|
4913
4904
|
const reply = buildStreamPlaceholderReply(streamId2);
|
|
4914
4905
|
jsonOk(
|
|
4915
4906
|
res,
|
|
@@ -4926,13 +4917,13 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4926
4917
|
const eventtype = String(
|
|
4927
4918
|
msg.event?.eventtype ?? msg.Event ?? ""
|
|
4928
4919
|
).toLowerCase();
|
|
4929
|
-
|
|
4920
|
+
logger2.info(`event received: type=${eventtype || "unknown"}`);
|
|
4930
4921
|
if (eventtype === "enter_chat" || eventtype === "subscribe") {
|
|
4931
4922
|
const welcome = target.account.config.welcomeText?.trim();
|
|
4932
4923
|
if (welcome && target.account.canSendActive) {
|
|
4933
|
-
|
|
4924
|
+
logger2.info("sending welcome message");
|
|
4934
4925
|
sendBaiduAppMessage(target.account, welcome).catch((err) => {
|
|
4935
|
-
|
|
4926
|
+
logger2.error(`failed to send welcome message: ${String(err)}`);
|
|
4936
4927
|
});
|
|
4937
4928
|
}
|
|
4938
4929
|
jsonOk(
|
|
@@ -4970,14 +4961,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4970
4961
|
finished: false,
|
|
4971
4962
|
content: ""
|
|
4972
4963
|
});
|
|
4973
|
-
|
|
4964
|
+
logger2.info(`stream created: streamId=${streamId} msgid=${msgid ?? "none"}`);
|
|
4974
4965
|
const core = tryGetBaiduAppRuntime();
|
|
4975
4966
|
if (core) {
|
|
4976
4967
|
const state = streams.get(streamId);
|
|
4977
4968
|
if (state) {
|
|
4978
4969
|
state.started = true;
|
|
4979
4970
|
}
|
|
4980
|
-
|
|
4971
|
+
logger2.info(`agent dispatch started: streamId=${streamId} canSendActive=${target.account.canSendActive}`);
|
|
4981
4972
|
const hooks = {
|
|
4982
4973
|
onChunk: (text) => {
|
|
4983
4974
|
const current = streams.get(streamId);
|
|
@@ -4985,7 +4976,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4985
4976
|
return;
|
|
4986
4977
|
}
|
|
4987
4978
|
appendStreamContent(current, text);
|
|
4988
|
-
|
|
4979
|
+
logger2.debug(
|
|
4989
4980
|
`chunk received: streamId=${streamId} chunkLen=${text.length} totalLen=${current.content.length}`
|
|
4990
4981
|
);
|
|
4991
4982
|
target.statusSink?.({ lastOutboundAt: Date.now() });
|
|
@@ -4998,7 +4989,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4998
4989
|
current.finished = true;
|
|
4999
4990
|
current.updatedAt = Date.now();
|
|
5000
4991
|
}
|
|
5001
|
-
|
|
4992
|
+
logger2.error(`openclaw-baiduapp agent failed: ${String(err)}`);
|
|
5002
4993
|
}
|
|
5003
4994
|
};
|
|
5004
4995
|
dispatchBaiduAppMessage({
|
|
@@ -5015,20 +5006,20 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5015
5006
|
current.finished = true;
|
|
5016
5007
|
current.updatedAt = Date.now();
|
|
5017
5008
|
const contentLen = current.content.trim().length;
|
|
5018
|
-
|
|
5009
|
+
logger2.info(
|
|
5019
5010
|
`agent dispatch done: streamId=${streamId} contentLen=${contentLen} canSendActive=${target.account.canSendActive}`
|
|
5020
5011
|
);
|
|
5021
5012
|
if (!target.account.canSendActive) {
|
|
5022
|
-
|
|
5013
|
+
logger2.warn(
|
|
5023
5014
|
`active send skipped: appKey/appSecret not configured for account ${target.account.accountId}`
|
|
5024
5015
|
);
|
|
5025
5016
|
} else if (!contentLen) {
|
|
5026
|
-
|
|
5017
|
+
logger2.warn(`active send skipped: agent produced no content`);
|
|
5027
5018
|
}
|
|
5028
5019
|
if (target.account.canSendActive && current.content.trim()) {
|
|
5029
5020
|
try {
|
|
5030
5021
|
const chunks = splitMessageByBytes(current.content, MAX_MESSAGE_BYTES);
|
|
5031
|
-
|
|
5022
|
+
logger2.info(
|
|
5032
5023
|
`[REPLY-MODE:ACTIVE-SEND] active send starting: streamId=${streamId} chunks=${chunks.length} contentLen=${contentLen}`
|
|
5033
5024
|
);
|
|
5034
5025
|
for (let i = 0; i < chunks.length; i++) {
|
|
@@ -5037,13 +5028,13 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5037
5028
|
streamId,
|
|
5038
5029
|
chunkKey: i
|
|
5039
5030
|
});
|
|
5040
|
-
|
|
5031
|
+
logger2.debug(`active send chunk ${i + 1}/${chunks.length} sent: streamId=${streamId}`);
|
|
5041
5032
|
}
|
|
5042
|
-
|
|
5033
|
+
logger2.info(
|
|
5043
5034
|
`[REPLY-MODE:ACTIVE-SEND] active send complete: streamId=${streamId} chunks=${chunks.length}`
|
|
5044
5035
|
);
|
|
5045
5036
|
} catch (err) {
|
|
5046
|
-
|
|
5037
|
+
logger2.error(`active send failed: streamId=${streamId} error=${String(err)}`);
|
|
5047
5038
|
}
|
|
5048
5039
|
}
|
|
5049
5040
|
}
|
|
@@ -5055,10 +5046,10 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5055
5046
|
current.finished = true;
|
|
5056
5047
|
current.updatedAt = Date.now();
|
|
5057
5048
|
}
|
|
5058
|
-
|
|
5049
|
+
logger2.error(`agent dispatch failed: streamId=${streamId} error=${String(err)}`);
|
|
5059
5050
|
});
|
|
5060
5051
|
} else {
|
|
5061
|
-
|
|
5052
|
+
logger2.warn(`runtime not available: streamId=${streamId} \u2014 agent dispatch skipped, no reply will be generated`);
|
|
5062
5053
|
const state = streams.get(streamId);
|
|
5063
5054
|
if (state) {
|
|
5064
5055
|
state.finished = true;
|
|
@@ -5066,7 +5057,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5066
5057
|
}
|
|
5067
5058
|
}
|
|
5068
5059
|
const placeholderReply = buildStreamPlaceholderReply(streamId);
|
|
5069
|
-
|
|
5060
|
+
logger2.debug(`stream placeholder reply sent: streamId=${streamId}`);
|
|
5070
5061
|
jsonOk(
|
|
5071
5062
|
res,
|
|
5072
5063
|
buildEncryptedJsonReply({
|
|
@@ -5080,7 +5071,6 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5080
5071
|
}
|
|
5081
5072
|
|
|
5082
5073
|
// src/channel.ts
|
|
5083
|
-
var logger2 = createLogger("openclaw-baiduapp");
|
|
5084
5074
|
var meta = {
|
|
5085
5075
|
id: "openclaw-baiduapp",
|
|
5086
5076
|
label: "Baidu App",
|
|
@@ -5208,10 +5198,8 @@ var baiduAppPlugin = {
|
|
|
5208
5198
|
return true;
|
|
5209
5199
|
},
|
|
5210
5200
|
resolveTarget: (params) => {
|
|
5211
|
-
logger2.debug(`resolveTarget called with target: ${params.target}`);
|
|
5212
5201
|
let raw = (params.target ?? "").trim();
|
|
5213
5202
|
if (!raw) {
|
|
5214
|
-
logger2.debug("resolveTarget: empty target, returning null");
|
|
5215
5203
|
return null;
|
|
5216
5204
|
}
|
|
5217
5205
|
const channelPrefix = "openclaw-baiduapp:";
|
|
@@ -5229,17 +5217,9 @@ var baiduAppPlugin = {
|
|
|
5229
5217
|
}
|
|
5230
5218
|
}
|
|
5231
5219
|
if (to.startsWith("user:")) {
|
|
5232
|
-
|
|
5233
|
-
}
|
|
5234
|
-
if (!accountId) {
|
|
5235
|
-
const matched = findAccountIdByAppKey(params.cfg, to);
|
|
5236
|
-
if (matched) {
|
|
5237
|
-
accountId = matched;
|
|
5238
|
-
}
|
|
5220
|
+
return { channel: "openclaw-baiduapp", accountId, to: to.slice(5) };
|
|
5239
5221
|
}
|
|
5240
|
-
|
|
5241
|
-
logger2.debug(`resolveTarget result: ${JSON.stringify(result)}`);
|
|
5242
|
-
return result;
|
|
5222
|
+
return { channel: "openclaw-baiduapp", accountId, to };
|
|
5243
5223
|
},
|
|
5244
5224
|
resolveTargets: (params) => {
|
|
5245
5225
|
const results = [];
|
|
@@ -5432,44 +5412,15 @@ var plugin = {
|
|
|
5432
5412
|
setBaiduAppRuntime(api.runtime);
|
|
5433
5413
|
}
|
|
5434
5414
|
api.registerChannel({ plugin: baiduAppPlugin });
|
|
5435
|
-
if (api.
|
|
5436
|
-
api.
|
|
5437
|
-
|
|
5438
|
-
|
|
5439
|
-
|
|
5440
|
-
|
|
5441
|
-
log.info(
|
|
5442
|
-
`[openclaw-baiduapp] message_received event=${JSON.stringify(event)} ctx=${JSON.stringify(ctx)}`
|
|
5443
|
-
);
|
|
5415
|
+
if (api.registerHttpRoute) {
|
|
5416
|
+
api.registerHttpRoute({
|
|
5417
|
+
path: "/openclaw-baiduapp",
|
|
5418
|
+
auth: "plugin",
|
|
5419
|
+
match: "prefix",
|
|
5420
|
+
handler: handleBaiduAppWebhookRequest
|
|
5444
5421
|
});
|
|
5445
|
-
}
|
|
5446
|
-
|
|
5447
|
-
const log = api.logger ?? { info: console.log, error: console.error, warn: console.warn, debug: console.log };
|
|
5448
|
-
api.hook(
|
|
5449
|
-
"before_agent_start",
|
|
5450
|
-
{
|
|
5451
|
-
name: "openclaw-baiduapp-before-agent-start",
|
|
5452
|
-
description: "Capture all agent inputs including internal ones (sessions_send, cron, etc.)"
|
|
5453
|
-
},
|
|
5454
|
-
async (event, ctx) => {
|
|
5455
|
-
log.info(
|
|
5456
|
-
`[openclaw-baiduapp] before_agent_start prompt=${String(event.prompt ?? "").slice(0, 200)} sessionKey=${String(ctx.sessionKey ?? "")} agentId=${String(ctx.agentId ?? "")} provider=${String(ctx.messageProvider ?? "")}`
|
|
5457
|
-
);
|
|
5458
|
-
}
|
|
5459
|
-
);
|
|
5460
|
-
api.hook(
|
|
5461
|
-
"agent_end",
|
|
5462
|
-
{
|
|
5463
|
-
name: "openclaw-baiduapp-agent-end",
|
|
5464
|
-
description: "Capture agent completion results"
|
|
5465
|
-
},
|
|
5466
|
-
async (event, ctx) => {
|
|
5467
|
-
const messageCount = Array.isArray(event.messages) ? event.messages.length : 0;
|
|
5468
|
-
log.info(
|
|
5469
|
-
`[openclaw-baiduapp] agent_end success=${String(event.success ?? "unknown")} messages=${messageCount} sessionKey=${String(ctx.sessionKey ?? "")} agentId=${String(ctx.agentId ?? "")}`
|
|
5470
|
-
);
|
|
5471
|
-
}
|
|
5472
|
-
);
|
|
5422
|
+
} else if (api.registerHttpHandler) {
|
|
5423
|
+
api.registerHttpHandler(handleBaiduAppWebhookRequest);
|
|
5473
5424
|
}
|
|
5474
5425
|
}
|
|
5475
5426
|
};
|