@searchfe/openclaw-baiduapp 0.1.4 → 0.1.5
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 +11 -0
- package/dist/index.js +279 -222
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -6,6 +6,173 @@ 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
|
+
}
|
|
9
176
|
|
|
10
177
|
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
11
178
|
var external_exports = {};
|
|
@@ -4171,172 +4338,15 @@ function resolveBaiduAppAccount(params) {
|
|
|
4171
4338
|
config: merged
|
|
4172
4339
|
};
|
|
4173
4340
|
}
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
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");
|
|
4341
|
+
function findAccountIdByAppKey(cfg, appKey) {
|
|
4342
|
+
const ids = listBaiduAppAccountIds(cfg);
|
|
4343
|
+
for (const id of ids) {
|
|
4344
|
+
const account = resolveBaiduAppAccount({ cfg, accountId: id });
|
|
4345
|
+
if (account.appKey === appKey) {
|
|
4346
|
+
return id;
|
|
4215
4347
|
}
|
|
4216
4348
|
}
|
|
4217
|
-
return
|
|
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;
|
|
4349
|
+
return void 0;
|
|
4340
4350
|
}
|
|
4341
4351
|
|
|
4342
4352
|
// src/bot.ts
|
|
@@ -4357,25 +4367,24 @@ function extractBaiduAppContent(msg) {
|
|
|
4357
4367
|
async function dispatchBaiduAppMessage(params) {
|
|
4358
4368
|
const { cfg, account, msg, core, hooks } = params;
|
|
4359
4369
|
const safeCfg = cfg ?? {};
|
|
4360
|
-
const
|
|
4370
|
+
const logger3 = createLogger("openclaw-baiduapp", { log: params.log, error: params.error });
|
|
4361
4371
|
const channel = core.channel;
|
|
4362
4372
|
if (!channel?.routing?.resolveAgentRoute || !channel.reply?.dispatchReplyWithBufferedBlockDispatcher) {
|
|
4363
|
-
|
|
4373
|
+
logger3.warn("core routing or buffered dispatcher missing, skipping dispatch");
|
|
4364
4374
|
return;
|
|
4365
4375
|
}
|
|
4376
|
+
const userId = account.appKey ?? account.accountId;
|
|
4366
4377
|
const route = channel.routing.resolveAgentRoute({
|
|
4367
4378
|
cfg: safeCfg,
|
|
4368
4379
|
channel: "openclaw-baiduapp",
|
|
4369
|
-
accountId:
|
|
4370
|
-
peer: { kind: "dm", id:
|
|
4380
|
+
accountId: userId,
|
|
4381
|
+
peer: { kind: "dm", id: userId }
|
|
4371
4382
|
});
|
|
4372
|
-
|
|
4373
|
-
route.sessionKey = "agent:main:main";
|
|
4374
|
-
logger2.info(
|
|
4383
|
+
logger3.info(
|
|
4375
4384
|
`route resolved: sessionKey=${route.sessionKey} agentId=${route.agentId ?? "default"} accountId=${route.accountId}`
|
|
4376
4385
|
);
|
|
4377
4386
|
const rawBody = extractBaiduAppContent(msg);
|
|
4378
|
-
|
|
4387
|
+
logger3.debug(
|
|
4379
4388
|
`message content extracted: len=${rawBody.length} preview="${rawBody.slice(0, 80)}${rawBody.length > 80 ? "..." : ""}"`
|
|
4380
4389
|
);
|
|
4381
4390
|
const storePath = channel.session?.resolveStorePath?.(safeCfg.session?.store, {
|
|
@@ -4386,9 +4395,10 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4386
4395
|
sessionKey: route.sessionKey
|
|
4387
4396
|
}) ?? void 0 : void 0;
|
|
4388
4397
|
const envelopeOptions = channel.reply?.resolveEnvelopeFormatOptions ? channel.reply.resolveEnvelopeFormatOptions(safeCfg) : void 0;
|
|
4398
|
+
const fromLabel = `user:${userId}`;
|
|
4389
4399
|
const body = channel.reply?.formatAgentEnvelope ? channel.reply.formatAgentEnvelope({
|
|
4390
4400
|
channel: "Baidu App",
|
|
4391
|
-
from:
|
|
4401
|
+
from: `user:${userId}`,
|
|
4392
4402
|
previousTimestamp,
|
|
4393
4403
|
envelope: envelopeOptions,
|
|
4394
4404
|
body: rawBody
|
|
@@ -4398,32 +4408,32 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4398
4408
|
Body: body,
|
|
4399
4409
|
RawBody: rawBody,
|
|
4400
4410
|
CommandBody: rawBody,
|
|
4401
|
-
From:
|
|
4402
|
-
To:
|
|
4411
|
+
From: `openclaw-baiduapp:${userId}`,
|
|
4412
|
+
To: `openclaw-baiduapp:${userId}`,
|
|
4403
4413
|
SessionKey: route.sessionKey,
|
|
4404
|
-
AccountId: route.accountId
|
|
4414
|
+
AccountId: route.accountId,
|
|
4405
4415
|
ChatType: "direct",
|
|
4406
|
-
ConversationLabel:
|
|
4416
|
+
ConversationLabel: fromLabel,
|
|
4407
4417
|
Provider: "openclaw-baiduapp",
|
|
4408
4418
|
Surface: "openclaw-baiduapp",
|
|
4409
4419
|
MessageSid: msgid,
|
|
4410
4420
|
OriginatingChannel: "openclaw-baiduapp",
|
|
4411
|
-
OriginatingTo:
|
|
4421
|
+
OriginatingTo: `openclaw-baiduapp:${userId}`
|
|
4412
4422
|
}) : {
|
|
4413
4423
|
Body: body,
|
|
4414
4424
|
RawBody: rawBody,
|
|
4415
4425
|
CommandBody: rawBody,
|
|
4416
|
-
From:
|
|
4417
|
-
To:
|
|
4426
|
+
From: `openclaw-baiduapp:${userId}`,
|
|
4427
|
+
To: `openclaw-baiduapp:${userId}`,
|
|
4418
4428
|
SessionKey: route.sessionKey,
|
|
4419
|
-
AccountId: route.accountId
|
|
4429
|
+
AccountId: route.accountId,
|
|
4420
4430
|
ChatType: "direct",
|
|
4421
|
-
ConversationLabel:
|
|
4431
|
+
ConversationLabel: fromLabel,
|
|
4422
4432
|
Provider: "openclaw-baiduapp",
|
|
4423
4433
|
Surface: "openclaw-baiduapp",
|
|
4424
4434
|
MessageSid: msgid,
|
|
4425
4435
|
OriginatingChannel: "openclaw-baiduapp",
|
|
4426
|
-
OriginatingTo:
|
|
4436
|
+
OriginatingTo: `openclaw-baiduapp:${userId}`
|
|
4427
4437
|
};
|
|
4428
4438
|
if (channel.session?.recordInboundSession && storePath) {
|
|
4429
4439
|
await channel.session.recordInboundSession({
|
|
@@ -4431,7 +4441,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4431
4441
|
sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
|
|
4432
4442
|
ctx: ctxPayload,
|
|
4433
4443
|
onRecordError: (err) => {
|
|
4434
|
-
|
|
4444
|
+
logger3.error(`openclaw-baiduapp: failed updating session meta: ${String(err)}`);
|
|
4435
4445
|
}
|
|
4436
4446
|
});
|
|
4437
4447
|
}
|
|
@@ -4440,7 +4450,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4440
4450
|
channel: "openclaw-baiduapp",
|
|
4441
4451
|
accountId: account.accountId
|
|
4442
4452
|
}) : void 0;
|
|
4443
|
-
|
|
4453
|
+
logger3.info(`dispatching to agent: sessionKey=${route.sessionKey}`);
|
|
4444
4454
|
await channel.reply.dispatchReplyWithBufferedBlockDispatcher({
|
|
4445
4455
|
ctx: ctxPayload,
|
|
4446
4456
|
cfg: safeCfg,
|
|
@@ -4448,20 +4458,20 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4448
4458
|
deliver: async (payload) => {
|
|
4449
4459
|
const rawText = payload.text ?? "";
|
|
4450
4460
|
if (!rawText.trim()) {
|
|
4451
|
-
|
|
4461
|
+
logger3.debug("deliver callback: empty text, skipping");
|
|
4452
4462
|
return;
|
|
4453
4463
|
}
|
|
4454
4464
|
const converted = channel.text?.convertMarkdownTables && tableMode ? channel.text.convertMarkdownTables(rawText, tableMode) : rawText;
|
|
4455
|
-
|
|
4465
|
+
logger3.debug(`deliver callback: textLen=${converted.length}`);
|
|
4456
4466
|
hooks.onChunk(converted);
|
|
4457
4467
|
},
|
|
4458
4468
|
onError: (err, info) => {
|
|
4459
4469
|
hooks.onError?.(err);
|
|
4460
|
-
|
|
4470
|
+
logger3.error(`${info.kind} reply failed: ${String(err)}`);
|
|
4461
4471
|
}
|
|
4462
4472
|
}
|
|
4463
4473
|
});
|
|
4464
|
-
|
|
4474
|
+
logger3.info(`agent reply dispatch complete: sessionKey=${route.sessionKey}`);
|
|
4465
4475
|
}
|
|
4466
4476
|
|
|
4467
4477
|
// src/runtime.ts
|
|
@@ -4750,7 +4760,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4750
4760
|
const nonce = query.get("nonce") ?? "";
|
|
4751
4761
|
const signature = resolveSignatureParam(query);
|
|
4752
4762
|
const primary = targets[0];
|
|
4753
|
-
const
|
|
4763
|
+
const logger3 = buildLogger(primary);
|
|
4754
4764
|
if (req.method === "GET") {
|
|
4755
4765
|
const echostr = query.get("echostr") ?? "";
|
|
4756
4766
|
if (!timestamp || !nonce || !signature || !echostr) {
|
|
@@ -4786,7 +4796,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4786
4796
|
jsonError(res, "decrypt failed");
|
|
4787
4797
|
return true;
|
|
4788
4798
|
}
|
|
4789
|
-
const selected2 = selectDecryptedTarget({ candidates: decryptedCandidates2, logger:
|
|
4799
|
+
const selected2 = selectDecryptedTarget({ candidates: decryptedCandidates2, logger: logger3 });
|
|
4790
4800
|
jsonOk(res, selected2.plaintext);
|
|
4791
4801
|
return true;
|
|
4792
4802
|
}
|
|
@@ -4814,14 +4824,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4814
4824
|
msgSignature = xmlData.MsgSignature ?? signature;
|
|
4815
4825
|
msgTimestamp = xmlData.TimeStamp ?? timestamp;
|
|
4816
4826
|
msgNonce = xmlData.Nonce ?? nonce;
|
|
4817
|
-
|
|
4827
|
+
logger3.info(`inbound xml parsed: hasEncrypt=${Boolean(encrypt)}, msg_signature=${msgSignature ? "yes" : "no"}`);
|
|
4818
4828
|
} else {
|
|
4819
4829
|
try {
|
|
4820
4830
|
const record = JSON.parse(rawBody);
|
|
4821
4831
|
encrypt = String(record.encrypt ?? record.Encrypt ?? "");
|
|
4822
|
-
|
|
4832
|
+
logger3.info(`inbound json parsed: hasEncrypt=${Boolean(encrypt)}`);
|
|
4823
4833
|
} catch {
|
|
4824
|
-
|
|
4834
|
+
logger3.warn(`inbound payload parse failed: not valid xml or json`);
|
|
4825
4835
|
jsonError(res, "invalid payload format");
|
|
4826
4836
|
return true;
|
|
4827
4837
|
}
|
|
@@ -4843,14 +4853,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4843
4853
|
});
|
|
4844
4854
|
});
|
|
4845
4855
|
if (signatureMatched.length === 0) {
|
|
4846
|
-
|
|
4856
|
+
logger3.warn(`signature verification failed: checked ${targets.length} account(s), none matched`);
|
|
4847
4857
|
jsonError(res, "unauthorized");
|
|
4848
4858
|
return true;
|
|
4849
4859
|
}
|
|
4850
|
-
|
|
4860
|
+
logger3.debug(`signature verified: ${signatureMatched.length} account(s) matched`);
|
|
4851
4861
|
const decryptable = signatureMatched.filter((candidate) => Boolean(candidate.account.encodingAESKey));
|
|
4852
4862
|
if (decryptable.length === 0) {
|
|
4853
|
-
|
|
4863
|
+
logger3.warn(`no account has encodingAESKey configured`);
|
|
4854
4864
|
jsonError(res, "openclaw-baiduapp not configured");
|
|
4855
4865
|
return true;
|
|
4856
4866
|
}
|
|
@@ -4859,14 +4869,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4859
4869
|
encrypt
|
|
4860
4870
|
});
|
|
4861
4871
|
if (decryptedCandidates.length === 0) {
|
|
4862
|
-
|
|
4872
|
+
logger3.warn(`decrypt failed for all ${decryptable.length} candidate account(s)`);
|
|
4863
4873
|
jsonError(res, "decrypt failed");
|
|
4864
4874
|
return true;
|
|
4865
4875
|
}
|
|
4866
|
-
const selected = selectDecryptedTarget({ candidates: decryptedCandidates, logger:
|
|
4876
|
+
const selected = selectDecryptedTarget({ candidates: decryptedCandidates, logger: logger3 });
|
|
4867
4877
|
const target = selected.target;
|
|
4868
4878
|
if (!target.account.configured || !target.account.token || !target.account.encodingAESKey) {
|
|
4869
|
-
|
|
4879
|
+
logger3.warn(`selected account ${target.account.accountId} not fully configured`);
|
|
4870
4880
|
jsonError(res, "openclaw-baiduapp not configured");
|
|
4871
4881
|
return true;
|
|
4872
4882
|
}
|
|
@@ -4874,11 +4884,11 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4874
4884
|
target.statusSink?.({ lastInboundAt: Date.now() });
|
|
4875
4885
|
const msgtype = String(msg.msgtype ?? msg.MsgType ?? "").toLowerCase();
|
|
4876
4886
|
const msgid = msg.msgid ?? msg.MsgId ? String(msg.msgid ?? msg.MsgId) : void 0;
|
|
4877
|
-
|
|
4887
|
+
logger3.info(`inbound: type=${msgtype || "unknown"} msgid=${msgid ?? "none"} account=${target.account.accountId}`);
|
|
4878
4888
|
if (msgtype === "stream") {
|
|
4879
4889
|
const streamId2 = String(msg.stream?.id ?? "").trim();
|
|
4880
4890
|
const state = streamId2 ? streams.get(streamId2) : void 0;
|
|
4881
|
-
|
|
4891
|
+
logger3.info(
|
|
4882
4892
|
`[REPLY-MODE:STREAM-POLL] stream poll request: streamId=${streamId2 || "none"} found=${Boolean(state)} finished=${state?.finished ?? "n/a"} contentLen=${state?.content.length ?? 0}`
|
|
4883
4893
|
);
|
|
4884
4894
|
const reply = state ? buildStreamReplyFromState(state) : buildStreamReplyFromState({
|
|
@@ -4899,7 +4909,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4899
4909
|
}
|
|
4900
4910
|
if (msgid && msgidToStreamId.has(msgid)) {
|
|
4901
4911
|
const streamId2 = msgidToStreamId.get(msgid) ?? "";
|
|
4902
|
-
|
|
4912
|
+
logger3.debug(`duplicate msgid detected: msgid=${msgid} streamId=${streamId2}, returning placeholder`);
|
|
4903
4913
|
const reply = buildStreamPlaceholderReply(streamId2);
|
|
4904
4914
|
jsonOk(
|
|
4905
4915
|
res,
|
|
@@ -4916,13 +4926,13 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4916
4926
|
const eventtype = String(
|
|
4917
4927
|
msg.event?.eventtype ?? msg.Event ?? ""
|
|
4918
4928
|
).toLowerCase();
|
|
4919
|
-
|
|
4929
|
+
logger3.info(`event received: type=${eventtype || "unknown"}`);
|
|
4920
4930
|
if (eventtype === "enter_chat" || eventtype === "subscribe") {
|
|
4921
4931
|
const welcome = target.account.config.welcomeText?.trim();
|
|
4922
4932
|
if (welcome && target.account.canSendActive) {
|
|
4923
|
-
|
|
4933
|
+
logger3.info("sending welcome message");
|
|
4924
4934
|
sendBaiduAppMessage(target.account, welcome).catch((err) => {
|
|
4925
|
-
|
|
4935
|
+
logger3.error(`failed to send welcome message: ${String(err)}`);
|
|
4926
4936
|
});
|
|
4927
4937
|
}
|
|
4928
4938
|
jsonOk(
|
|
@@ -4960,14 +4970,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4960
4970
|
finished: false,
|
|
4961
4971
|
content: ""
|
|
4962
4972
|
});
|
|
4963
|
-
|
|
4973
|
+
logger3.info(`stream created: streamId=${streamId} msgid=${msgid ?? "none"}`);
|
|
4964
4974
|
const core = tryGetBaiduAppRuntime();
|
|
4965
4975
|
if (core) {
|
|
4966
4976
|
const state = streams.get(streamId);
|
|
4967
4977
|
if (state) {
|
|
4968
4978
|
state.started = true;
|
|
4969
4979
|
}
|
|
4970
|
-
|
|
4980
|
+
logger3.info(`agent dispatch started: streamId=${streamId} canSendActive=${target.account.canSendActive}`);
|
|
4971
4981
|
const hooks = {
|
|
4972
4982
|
onChunk: (text) => {
|
|
4973
4983
|
const current = streams.get(streamId);
|
|
@@ -4975,7 +4985,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4975
4985
|
return;
|
|
4976
4986
|
}
|
|
4977
4987
|
appendStreamContent(current, text);
|
|
4978
|
-
|
|
4988
|
+
logger3.debug(
|
|
4979
4989
|
`chunk received: streamId=${streamId} chunkLen=${text.length} totalLen=${current.content.length}`
|
|
4980
4990
|
);
|
|
4981
4991
|
target.statusSink?.({ lastOutboundAt: Date.now() });
|
|
@@ -4988,7 +4998,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4988
4998
|
current.finished = true;
|
|
4989
4999
|
current.updatedAt = Date.now();
|
|
4990
5000
|
}
|
|
4991
|
-
|
|
5001
|
+
logger3.error(`openclaw-baiduapp agent failed: ${String(err)}`);
|
|
4992
5002
|
}
|
|
4993
5003
|
};
|
|
4994
5004
|
dispatchBaiduAppMessage({
|
|
@@ -5005,20 +5015,20 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5005
5015
|
current.finished = true;
|
|
5006
5016
|
current.updatedAt = Date.now();
|
|
5007
5017
|
const contentLen = current.content.trim().length;
|
|
5008
|
-
|
|
5018
|
+
logger3.info(
|
|
5009
5019
|
`agent dispatch done: streamId=${streamId} contentLen=${contentLen} canSendActive=${target.account.canSendActive}`
|
|
5010
5020
|
);
|
|
5011
5021
|
if (!target.account.canSendActive) {
|
|
5012
|
-
|
|
5022
|
+
logger3.warn(
|
|
5013
5023
|
`active send skipped: appKey/appSecret not configured for account ${target.account.accountId}`
|
|
5014
5024
|
);
|
|
5015
5025
|
} else if (!contentLen) {
|
|
5016
|
-
|
|
5026
|
+
logger3.warn(`active send skipped: agent produced no content`);
|
|
5017
5027
|
}
|
|
5018
5028
|
if (target.account.canSendActive && current.content.trim()) {
|
|
5019
5029
|
try {
|
|
5020
5030
|
const chunks = splitMessageByBytes(current.content, MAX_MESSAGE_BYTES);
|
|
5021
|
-
|
|
5031
|
+
logger3.info(
|
|
5022
5032
|
`[REPLY-MODE:ACTIVE-SEND] active send starting: streamId=${streamId} chunks=${chunks.length} contentLen=${contentLen}`
|
|
5023
5033
|
);
|
|
5024
5034
|
for (let i = 0; i < chunks.length; i++) {
|
|
@@ -5027,13 +5037,13 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5027
5037
|
streamId,
|
|
5028
5038
|
chunkKey: i
|
|
5029
5039
|
});
|
|
5030
|
-
|
|
5040
|
+
logger3.debug(`active send chunk ${i + 1}/${chunks.length} sent: streamId=${streamId}`);
|
|
5031
5041
|
}
|
|
5032
|
-
|
|
5042
|
+
logger3.info(
|
|
5033
5043
|
`[REPLY-MODE:ACTIVE-SEND] active send complete: streamId=${streamId} chunks=${chunks.length}`
|
|
5034
5044
|
);
|
|
5035
5045
|
} catch (err) {
|
|
5036
|
-
|
|
5046
|
+
logger3.error(`active send failed: streamId=${streamId} error=${String(err)}`);
|
|
5037
5047
|
}
|
|
5038
5048
|
}
|
|
5039
5049
|
}
|
|
@@ -5045,10 +5055,10 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5045
5055
|
current.finished = true;
|
|
5046
5056
|
current.updatedAt = Date.now();
|
|
5047
5057
|
}
|
|
5048
|
-
|
|
5058
|
+
logger3.error(`agent dispatch failed: streamId=${streamId} error=${String(err)}`);
|
|
5049
5059
|
});
|
|
5050
5060
|
} else {
|
|
5051
|
-
|
|
5061
|
+
logger3.warn(`runtime not available: streamId=${streamId} \u2014 agent dispatch skipped, no reply will be generated`);
|
|
5052
5062
|
const state = streams.get(streamId);
|
|
5053
5063
|
if (state) {
|
|
5054
5064
|
state.finished = true;
|
|
@@ -5056,7 +5066,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5056
5066
|
}
|
|
5057
5067
|
}
|
|
5058
5068
|
const placeholderReply = buildStreamPlaceholderReply(streamId);
|
|
5059
|
-
|
|
5069
|
+
logger3.debug(`stream placeholder reply sent: streamId=${streamId}`);
|
|
5060
5070
|
jsonOk(
|
|
5061
5071
|
res,
|
|
5062
5072
|
buildEncryptedJsonReply({
|
|
@@ -5070,6 +5080,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5070
5080
|
}
|
|
5071
5081
|
|
|
5072
5082
|
// src/channel.ts
|
|
5083
|
+
var logger2 = createLogger("openclaw-baiduapp");
|
|
5073
5084
|
var meta = {
|
|
5074
5085
|
id: "openclaw-baiduapp",
|
|
5075
5086
|
label: "Baidu App",
|
|
@@ -5197,8 +5208,10 @@ var baiduAppPlugin = {
|
|
|
5197
5208
|
return true;
|
|
5198
5209
|
},
|
|
5199
5210
|
resolveTarget: (params) => {
|
|
5211
|
+
logger2.debug(`resolveTarget called with target: ${params.target}`);
|
|
5200
5212
|
let raw = (params.target ?? "").trim();
|
|
5201
5213
|
if (!raw) {
|
|
5214
|
+
logger2.debug("resolveTarget: empty target, returning null");
|
|
5202
5215
|
return null;
|
|
5203
5216
|
}
|
|
5204
5217
|
const channelPrefix = "openclaw-baiduapp:";
|
|
@@ -5216,9 +5229,17 @@ var baiduAppPlugin = {
|
|
|
5216
5229
|
}
|
|
5217
5230
|
}
|
|
5218
5231
|
if (to.startsWith("user:")) {
|
|
5219
|
-
|
|
5232
|
+
to = to.slice(5);
|
|
5220
5233
|
}
|
|
5221
|
-
|
|
5234
|
+
if (!accountId) {
|
|
5235
|
+
const matched = findAccountIdByAppKey(params.cfg, to);
|
|
5236
|
+
if (matched) {
|
|
5237
|
+
accountId = matched;
|
|
5238
|
+
}
|
|
5239
|
+
}
|
|
5240
|
+
const result = { channel: "openclaw-baiduapp", accountId, to };
|
|
5241
|
+
logger2.debug(`resolveTarget result: ${JSON.stringify(result)}`);
|
|
5242
|
+
return result;
|
|
5222
5243
|
},
|
|
5223
5244
|
resolveTargets: (params) => {
|
|
5224
5245
|
const results = [];
|
|
@@ -5414,6 +5435,42 @@ var plugin = {
|
|
|
5414
5435
|
if (api.registerHttpHandler) {
|
|
5415
5436
|
api.registerHttpHandler(handleBaiduAppWebhookRequest);
|
|
5416
5437
|
}
|
|
5438
|
+
if (api.on) {
|
|
5439
|
+
const log = api.logger ?? { info: console.log, error: console.error, warn: console.warn, debug: console.log };
|
|
5440
|
+
api.on("message_received", (event, ctx) => {
|
|
5441
|
+
log.info(
|
|
5442
|
+
`[openclaw-baiduapp] message_received event=${JSON.stringify(event)} ctx=${JSON.stringify(ctx)}`
|
|
5443
|
+
);
|
|
5444
|
+
});
|
|
5445
|
+
}
|
|
5446
|
+
if (api.hook) {
|
|
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
|
+
);
|
|
5473
|
+
}
|
|
5417
5474
|
}
|
|
5418
5475
|
};
|
|
5419
5476
|
var index_default = plugin;
|