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