@searchfe/openclaw-baiduapp 0.1.0-beta.6 → 0.1.0-beta.8

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.js CHANGED
@@ -4111,7 +4111,7 @@ function normalizeAccountId(raw) {
4111
4111
  return trimmed || DEFAULT_ACCOUNT_ID;
4112
4112
  }
4113
4113
  function listConfiguredAccountIds(cfg) {
4114
- const accounts = cfg.channels?.["baidu-app"]?.accounts;
4114
+ const accounts = cfg.channels?.["openclaw-baiduapp"]?.accounts;
4115
4115
  if (!accounts || typeof accounts !== "object") {
4116
4116
  return [];
4117
4117
  }
@@ -4125,7 +4125,7 @@ function listBaiduAppAccountIds(cfg) {
4125
4125
  return ids.sort((a, b) => a.localeCompare(b));
4126
4126
  }
4127
4127
  function resolveDefaultBaiduAppAccountId(cfg) {
4128
- const baiduAppConfig = cfg.channels?.["baidu-app"];
4128
+ const baiduAppConfig = cfg.channels?.["openclaw-baiduapp"];
4129
4129
  if (baiduAppConfig?.defaultAccount?.trim()) {
4130
4130
  return baiduAppConfig.defaultAccount.trim();
4131
4131
  }
@@ -4136,21 +4136,21 @@ function resolveDefaultBaiduAppAccountId(cfg) {
4136
4136
  return ids[0] ?? DEFAULT_ACCOUNT_ID;
4137
4137
  }
4138
4138
  function resolveAccountConfig(cfg, accountId) {
4139
- const accounts = cfg.channels?.["baidu-app"]?.accounts;
4139
+ const accounts = cfg.channels?.["openclaw-baiduapp"]?.accounts;
4140
4140
  if (!accounts || typeof accounts !== "object") {
4141
4141
  return void 0;
4142
4142
  }
4143
4143
  return accounts[accountId];
4144
4144
  }
4145
4145
  function mergeBaiduAppAccountConfig(cfg, accountId) {
4146
- const base = cfg.channels?.["baidu-app"] ?? {};
4146
+ const base = cfg.channels?.["openclaw-baiduapp"] ?? {};
4147
4147
  const { accounts: _ignored, defaultAccount: _ignored2, ...baseConfig } = base;
4148
4148
  const account = resolveAccountConfig(cfg, accountId) ?? {};
4149
4149
  return { ...baseConfig, ...account };
4150
4150
  }
4151
4151
  function resolveBaiduAppAccount(params) {
4152
4152
  const accountId = normalizeAccountId(params.accountId);
4153
- const baseEnabled = params.cfg.channels?.["baidu-app"]?.enabled !== false;
4153
+ const baseEnabled = params.cfg.channels?.["openclaw-baiduapp"]?.enabled !== false;
4154
4154
  const merged = mergeBaiduAppAccountConfig(params.cfg, accountId);
4155
4155
  const enabled = baseEnabled && merged.enabled !== false;
4156
4156
  const isDefaultAccount = accountId === DEFAULT_ACCOUNT_ID;
@@ -4159,7 +4159,7 @@ function resolveBaiduAppAccount(params) {
4159
4159
  const appKey = merged.appKey?.trim() || (isDefaultAccount ? process.env.BAIDU_APP_KEY?.trim() : void 0) || void 0;
4160
4160
  const appSecret = merged.appSecret?.trim() || (isDefaultAccount ? process.env.BAIDU_APP_SECRET?.trim() : void 0) || void 0;
4161
4161
  const configured = Boolean(token && encodingAESKey);
4162
- const canSendActive = Boolean(appKey && appSecret);
4162
+ const canSendActive = Boolean(appKey && token && encodingAESKey);
4163
4163
  const rawApiBase = merged.apiBase?.trim() || (isDefaultAccount ? process.env.BAIDU_API_BASE?.trim() : void 0) || void 0;
4164
4164
  const apiBase = (rawApiBase || DEFAULT_API_BASE).replace(/\/+$/, "");
4165
4165
  return {
@@ -4215,96 +4215,153 @@ function checkDmPolicy(params) {
4215
4215
  return { allowed: true };
4216
4216
  }
4217
4217
  }
4218
-
4219
- // src/api.ts
4220
- var accessTokenCache = /* @__PURE__ */ new Map();
4221
- var ACCESS_TOKEN_TTL_MS = 7200 * 1e3 - 5 * 60 * 1e3;
4222
- async function getAccessToken(account) {
4223
- if (!account.appKey || !account.appSecret) {
4224
- throw new Error("appKey or appSecret not configured");
4225
- }
4226
- const key = `${account.appKey}`;
4227
- const cached = accessTokenCache.get(key);
4228
- if (cached && Date.now() < cached.expiresAt) {
4229
- return cached.token;
4230
- }
4231
- const tokenUrl = `${account.apiBase}/auth/token`;
4232
- const url = `${tokenUrl}?appKey=${encodeURIComponent(account.appKey)}&appSecret=${encodeURIComponent(account.appSecret)}`;
4233
- const resp = await fetch(url);
4234
- const text = await resp.text();
4235
- if (!text) {
4236
- throw new Error(`gettoken failed: empty response (status=${resp.status})`);
4218
+ function decodeEncodingAESKey(encodingAESKey) {
4219
+ const trimmed = encodingAESKey.trim();
4220
+ if (!trimmed) {
4221
+ throw new Error("encodingAESKey missing");
4237
4222
  }
4238
- let data;
4239
- try {
4240
- data = JSON.parse(text);
4241
- } catch {
4242
- throw new Error(`gettoken failed: invalid JSON response (status=${resp.status}, body=${text.slice(0, 200)})`);
4223
+ const withPadding = trimmed.endsWith("=") ? trimmed : `${trimmed}=`;
4224
+ const key = Buffer.from(withPadding, "base64");
4225
+ if (key.length !== 32) {
4226
+ throw new Error(`invalid encodingAESKey (expected 32 bytes after base64 decode, got ${key.length})`);
4227
+ }
4228
+ return key;
4229
+ }
4230
+ var PKCS7_BLOCK_SIZE = 32;
4231
+ function pkcs7Pad(buf, blockSize) {
4232
+ const mod = buf.length % blockSize;
4233
+ const pad = mod === 0 ? blockSize : blockSize - mod;
4234
+ return Buffer.concat([buf, Buffer.alloc(pad, pad)]);
4235
+ }
4236
+ function pkcs7Unpad(buf, blockSize) {
4237
+ if (buf.length === 0) {
4238
+ throw new Error("invalid pkcs7 payload");
4243
4239
  }
4244
- if (data.errcode !== void 0 && data.errcode !== 0) {
4245
- throw new Error(`gettoken failed: ${data.errmsg ?? "unknown error"} (errcode=${data.errcode})`);
4240
+ const pad = buf[buf.length - 1];
4241
+ if (!pad || pad < 1 || pad > blockSize || pad > buf.length) {
4242
+ throw new Error("invalid pkcs7 padding");
4246
4243
  }
4247
- if (!data.access_token) {
4248
- throw new Error("gettoken returned empty access_token");
4244
+ for (let i = 1; i <= pad; i += 1) {
4245
+ if (buf[buf.length - i] !== pad) {
4246
+ throw new Error("invalid pkcs7 padding");
4247
+ }
4249
4248
  }
4250
- accessTokenCache.set(key, {
4251
- token: data.access_token,
4252
- expiresAt: Date.now() + ACCESS_TOKEN_TTL_MS
4249
+ return buf.subarray(0, buf.length - pad);
4250
+ }
4251
+ function sha1Hex(input) {
4252
+ return crypto.createHash("sha1").update(input).digest("hex");
4253
+ }
4254
+ function computeBaiduAppMsgSignature(params) {
4255
+ const parts = [params.token, params.timestamp, params.nonce, params.encrypt].map((value) => String(value ?? "")).sort();
4256
+ return sha1Hex(parts.join(""));
4257
+ }
4258
+ function verifyBaiduAppSignature(params) {
4259
+ const expected = computeBaiduAppMsgSignature({
4260
+ token: params.token,
4261
+ timestamp: params.timestamp,
4262
+ nonce: params.nonce,
4263
+ encrypt: params.encrypt
4253
4264
  });
4254
- return data.access_token;
4265
+ return expected === params.signature;
4255
4266
  }
4256
- function clearAccessTokenCache(account) {
4257
- const key = `${account.appKey}`;
4258
- accessTokenCache.delete(key);
4267
+ function decryptBaiduAppEncrypted(params) {
4268
+ const aesKey = decodeEncodingAESKey(params.encodingAESKey);
4269
+ const iv = aesKey.subarray(0, 16);
4270
+ const decipher = crypto.createDecipheriv("aes-256-cbc", aesKey, iv);
4271
+ decipher.setAutoPadding(false);
4272
+ const decryptedPadded = Buffer.concat([decipher.update(Buffer.from(params.encrypt, "base64")), decipher.final()]);
4273
+ const decrypted = pkcs7Unpad(decryptedPadded, PKCS7_BLOCK_SIZE);
4274
+ if (decrypted.length < 20) {
4275
+ throw new Error(`invalid decrypted payload (expected at least 20 bytes, got ${decrypted.length})`);
4276
+ }
4277
+ const msgLen = decrypted.readUInt32BE(16);
4278
+ const msgStart = 20;
4279
+ const msgEnd = msgStart + msgLen;
4280
+ if (msgEnd > decrypted.length) {
4281
+ throw new Error(`invalid decrypted msg length (msgEnd=${msgEnd}, payloadLength=${decrypted.length})`);
4282
+ }
4283
+ return decrypted.subarray(msgStart, msgEnd).toString("utf8");
4259
4284
  }
4260
- function clearAllAccessTokenCache() {
4261
- accessTokenCache.clear();
4285
+ function encryptBaiduAppPlaintext(params) {
4286
+ const aesKey = decodeEncodingAESKey(params.encodingAESKey);
4287
+ const iv = aesKey.subarray(0, 16);
4288
+ const random16 = crypto.randomBytes(16);
4289
+ const msg = Buffer.from(params.plaintext ?? "", "utf8");
4290
+ const msgLen = Buffer.alloc(4);
4291
+ msgLen.writeUInt32BE(msg.length, 0);
4292
+ const raw = Buffer.concat([random16, msgLen, msg]);
4293
+ const padded = pkcs7Pad(raw, PKCS7_BLOCK_SIZE);
4294
+ const cipher = crypto.createCipheriv("aes-256-cbc", aesKey, iv);
4295
+ cipher.setAutoPadding(false);
4296
+ const encrypted = Buffer.concat([cipher.update(padded), cipher.final()]);
4297
+ return encrypted.toString("base64");
4262
4298
  }
4299
+
4300
+ // src/api.ts
4301
+ var logger = createLogger("openclaw-baiduapp:api");
4263
4302
  async function sendBaiduAppMessage(account, target, message) {
4264
4303
  if (!account.canSendActive) {
4265
4304
  return {
4266
4305
  ok: false,
4267
4306
  errcode: -1,
4268
- errmsg: "Account not configured for active sending (missing appKey or appSecret)"
4307
+ errmsg: "Account not configured for active sending (missing appKey, token, or encodingAESKey)"
4269
4308
  };
4270
4309
  }
4271
- const token = await getAccessToken(account);
4272
4310
  const payload = {
4273
4311
  msgtype: "text",
4274
4312
  text: { content: message },
4275
4313
  touser: target.userId
4276
4314
  };
4315
+ const plaintext = JSON.stringify(payload);
4316
+ const encrypt = encryptBaiduAppPlaintext({
4317
+ encodingAESKey: account.encodingAESKey ?? "",
4318
+ plaintext
4319
+ });
4320
+ const timestamp = String(Math.floor(Date.now() / 1e3));
4321
+ const nonce = crypto.randomBytes(8).toString("hex");
4322
+ const msgSignature = computeBaiduAppMsgSignature({
4323
+ token: account.token ?? "",
4324
+ timestamp,
4325
+ nonce,
4326
+ encrypt
4327
+ });
4277
4328
  const sendMessageUrl = `${account.apiBase}/chat/openclaw/callback`;
4278
- const resp = await fetch(`${sendMessageUrl}?access_token=${encodeURIComponent(token)}`, {
4329
+ const url = `${sendMessageUrl}?timestamp=${encodeURIComponent(timestamp)}&ak=${encodeURIComponent(account.appKey ?? "")}&nonce=${encodeURIComponent(nonce)}&msg_signature=${encodeURIComponent(msgSignature)}`;
4330
+ const body = JSON.stringify({ encrypt });
4331
+ logger.info(`POST ${url}`);
4332
+ logger.debug(`request body: ${body}`);
4333
+ const resp = await fetch(url, {
4279
4334
  method: "POST",
4280
- body: JSON.stringify(payload),
4335
+ body,
4281
4336
  headers: { "Content-Type": "application/json" }
4282
4337
  });
4283
4338
  const text = await resp.text();
4284
4339
  if (!text) {
4285
- return {
4286
- ok: false,
4287
- errcode: resp.status,
4288
- errmsg: `empty response from server (status=${resp.status})`
4289
- };
4340
+ const errmsg = `empty response from server (status=${resp.status})`;
4341
+ logger.error(`request failed: ${errmsg}`);
4342
+ return { ok: false, errcode: resp.status, errmsg };
4290
4343
  }
4291
4344
  let data;
4292
4345
  try {
4293
4346
  data = JSON.parse(text);
4294
4347
  } catch {
4295
- return {
4296
- ok: false,
4297
- errcode: resp.status,
4298
- errmsg: `invalid JSON response (status=${resp.status}, body=${text.slice(0, 200)})`
4299
- };
4348
+ const errmsg = `invalid JSON response (status=${resp.status}, body=${text.slice(0, 200)})`;
4349
+ logger.error(`request failed: ${errmsg}`);
4350
+ return { ok: false, errcode: resp.status, errmsg };
4300
4351
  }
4301
- return {
4352
+ const result = {
4302
4353
  ok: data.errcode === 0,
4303
4354
  errcode: data.errcode,
4304
4355
  errmsg: data.errmsg,
4305
4356
  invaliduser: data.invaliduser,
4306
4357
  msgid: data.msgid
4307
4358
  };
4359
+ if (result.ok) {
4360
+ logger.info(`request succeeded: msgid=${result.msgid ?? "unknown"}`);
4361
+ } else {
4362
+ logger.error(`request failed: errcode=${result.errcode} errmsg=${result.errmsg ?? "unknown"}`);
4363
+ }
4364
+ return result;
4308
4365
  }
4309
4366
 
4310
4367
  // src/bot.ts
@@ -4329,15 +4386,15 @@ function resolveSenderId(msg) {
4329
4386
  async function dispatchBaiduAppMessage(params) {
4330
4387
  const { cfg, account, msg, core, hooks } = params;
4331
4388
  const safeCfg = cfg ?? {};
4332
- const logger = createLogger("baidu-app", { log: params.log, error: params.error });
4389
+ const logger2 = createLogger("openclaw-baiduapp", { log: params.log, error: params.error });
4333
4390
  const senderId = resolveSenderId(msg);
4334
4391
  const chatId = senderId;
4335
4392
  const accountConfig = account?.config ?? {};
4336
4393
  const dmPolicy = resolveDmPolicy(accountConfig);
4337
4394
  const allowFrom = resolveAllowFrom(accountConfig);
4338
- logger.debug(`dispatch: sender=${senderId} dmPolicy=${dmPolicy} allowFrom=[${allowFrom.join(",")}]`);
4395
+ logger2.debug(`dispatch: sender=${senderId} dmPolicy=${dmPolicy} allowFrom=[${allowFrom.join(",")}]`);
4339
4396
  if (dmPolicy === "disabled") {
4340
- logger.info(`dispatch rejected: dm disabled for account ${account.accountId}`);
4397
+ logger2.info(`dispatch rejected: dm disabled for account ${account.accountId}`);
4341
4398
  return;
4342
4399
  }
4343
4400
  const policyResult = checkDmPolicy({
@@ -4346,25 +4403,25 @@ async function dispatchBaiduAppMessage(params) {
4346
4403
  allowFrom
4347
4404
  });
4348
4405
  if (!policyResult.allowed) {
4349
- logger.info(`dispatch rejected: policy=${dmPolicy} reason=${policyResult.reason} sender=${senderId}`);
4406
+ logger2.info(`dispatch rejected: policy=${dmPolicy} reason=${policyResult.reason} sender=${senderId}`);
4350
4407
  return;
4351
4408
  }
4352
4409
  const channel = core.channel;
4353
4410
  if (!channel?.routing?.resolveAgentRoute || !channel.reply?.dispatchReplyWithBufferedBlockDispatcher) {
4354
- logger.warn("core routing or buffered dispatcher missing, skipping dispatch");
4411
+ logger2.warn("core routing or buffered dispatcher missing, skipping dispatch");
4355
4412
  return;
4356
4413
  }
4357
4414
  const route = channel.routing.resolveAgentRoute({
4358
4415
  cfg: safeCfg,
4359
- channel: "baidu-app",
4416
+ channel: "openclaw-baiduapp",
4360
4417
  accountId: account.accountId,
4361
4418
  peer: { kind: "dm", id: chatId }
4362
4419
  });
4363
- logger.info(
4420
+ logger2.info(
4364
4421
  `route resolved: sessionKey=${route.sessionKey} agentId=${route.agentId ?? "default"} accountId=${route.accountId}`
4365
4422
  );
4366
4423
  const rawBody = extractBaiduAppContent(msg);
4367
- logger.debug(
4424
+ logger2.debug(
4368
4425
  `message content extracted: len=${rawBody.length} preview="${rawBody.slice(0, 80)}${rawBody.length > 80 ? "..." : ""}"`
4369
4426
  );
4370
4427
  const fromLabel = `user:${senderId}`;
@@ -4384,7 +4441,7 @@ async function dispatchBaiduAppMessage(params) {
4384
4441
  body: rawBody
4385
4442
  }) : rawBody;
4386
4443
  const msgid = msg.msgid ?? msg.MsgId ?? void 0;
4387
- const from = `baidu-app:user:${senderId}`;
4444
+ const from = `openclaw-baiduapp:user:${senderId}`;
4388
4445
  const to = `user:${senderId}`;
4389
4446
  const ctxPayload = channel.reply?.finalizeInboundContext ? channel.reply.finalizeInboundContext({
4390
4447
  Body: body,
@@ -4398,10 +4455,10 @@ async function dispatchBaiduAppMessage(params) {
4398
4455
  ConversationLabel: fromLabel,
4399
4456
  SenderName: senderId,
4400
4457
  SenderId: senderId,
4401
- Provider: "baidu-app",
4402
- Surface: "baidu-app",
4458
+ Provider: "openclaw-baiduapp",
4459
+ Surface: "openclaw-baiduapp",
4403
4460
  MessageSid: msgid,
4404
- OriginatingChannel: "baidu-app",
4461
+ OriginatingChannel: "openclaw-baiduapp",
4405
4462
  OriginatingTo: to
4406
4463
  }) : {
4407
4464
  Body: body,
@@ -4415,10 +4472,10 @@ async function dispatchBaiduAppMessage(params) {
4415
4472
  ConversationLabel: fromLabel,
4416
4473
  SenderName: senderId,
4417
4474
  SenderId: senderId,
4418
- Provider: "baidu-app",
4419
- Surface: "baidu-app",
4475
+ Provider: "openclaw-baiduapp",
4476
+ Surface: "openclaw-baiduapp",
4420
4477
  MessageSid: msgid,
4421
- OriginatingChannel: "baidu-app",
4478
+ OriginatingChannel: "openclaw-baiduapp",
4422
4479
  OriginatingTo: to
4423
4480
  };
4424
4481
  if (channel.session?.recordInboundSession && storePath) {
@@ -4427,12 +4484,16 @@ async function dispatchBaiduAppMessage(params) {
4427
4484
  sessionKey: ctxPayload.SessionKey ?? route.sessionKey,
4428
4485
  ctx: ctxPayload,
4429
4486
  onRecordError: (err) => {
4430
- logger.error(`baidu-app: failed updating session meta: ${String(err)}`);
4487
+ logger2.error(`openclaw-baiduapp: failed updating session meta: ${String(err)}`);
4431
4488
  }
4432
4489
  });
4433
4490
  }
4434
- const tableMode = channel.text?.resolveMarkdownTableMode ? channel.text.resolveMarkdownTableMode({ cfg: safeCfg, channel: "baidu-app", accountId: account.accountId }) : void 0;
4435
- logger.info(`dispatching to agent: sessionKey=${route.sessionKey} sender=${senderId}`);
4491
+ const tableMode = channel.text?.resolveMarkdownTableMode ? channel.text.resolveMarkdownTableMode({
4492
+ cfg: safeCfg,
4493
+ channel: "openclaw-baiduapp",
4494
+ accountId: account.accountId
4495
+ }) : void 0;
4496
+ logger2.info(`dispatching to agent: sessionKey=${route.sessionKey} sender=${senderId}`);
4436
4497
  await channel.reply.dispatchReplyWithBufferedBlockDispatcher({
4437
4498
  ctx: ctxPayload,
4438
4499
  cfg: safeCfg,
@@ -4440,101 +4501,20 @@ async function dispatchBaiduAppMessage(params) {
4440
4501
  deliver: async (payload) => {
4441
4502
  const rawText = payload.text ?? "";
4442
4503
  if (!rawText.trim()) {
4443
- logger.debug("deliver callback: empty text, skipping");
4504
+ logger2.debug("deliver callback: empty text, skipping");
4444
4505
  return;
4445
4506
  }
4446
4507
  const converted = channel.text?.convertMarkdownTables && tableMode ? channel.text.convertMarkdownTables(rawText, tableMode) : rawText;
4447
- logger.debug(`deliver callback: textLen=${converted.length}`);
4508
+ logger2.debug(`deliver callback: textLen=${converted.length}`);
4448
4509
  hooks.onChunk(converted);
4449
4510
  },
4450
4511
  onError: (err, info) => {
4451
4512
  hooks.onError?.(err);
4452
- logger.error(`${info.kind} reply failed: ${String(err)}`);
4513
+ logger2.error(`${info.kind} reply failed: ${String(err)}`);
4453
4514
  }
4454
4515
  }
4455
4516
  });
4456
- logger.info(`agent reply dispatch complete: sessionKey=${route.sessionKey} sender=${senderId}`);
4457
- }
4458
- function decodeEncodingAESKey(encodingAESKey) {
4459
- const trimmed = encodingAESKey.trim();
4460
- if (!trimmed) {
4461
- throw new Error("encodingAESKey missing");
4462
- }
4463
- const withPadding = trimmed.endsWith("=") ? trimmed : `${trimmed}=`;
4464
- const key = Buffer.from(withPadding, "base64");
4465
- if (key.length !== 32) {
4466
- throw new Error(`invalid encodingAESKey (expected 32 bytes after base64 decode, got ${key.length})`);
4467
- }
4468
- return key;
4469
- }
4470
- var PKCS7_BLOCK_SIZE = 32;
4471
- function pkcs7Pad(buf, blockSize) {
4472
- const mod = buf.length % blockSize;
4473
- const pad = mod === 0 ? blockSize : blockSize - mod;
4474
- return Buffer.concat([buf, Buffer.alloc(pad, pad)]);
4475
- }
4476
- function pkcs7Unpad(buf, blockSize) {
4477
- if (buf.length === 0) {
4478
- throw new Error("invalid pkcs7 payload");
4479
- }
4480
- const pad = buf[buf.length - 1];
4481
- if (!pad || pad < 1 || pad > blockSize || pad > buf.length) {
4482
- throw new Error("invalid pkcs7 padding");
4483
- }
4484
- for (let i = 1; i <= pad; i += 1) {
4485
- if (buf[buf.length - i] !== pad) {
4486
- throw new Error("invalid pkcs7 padding");
4487
- }
4488
- }
4489
- return buf.subarray(0, buf.length - pad);
4490
- }
4491
- function sha1Hex(input) {
4492
- return crypto.createHash("sha1").update(input).digest("hex");
4493
- }
4494
- function computeBaiduAppMsgSignature(params) {
4495
- const parts = [params.token, params.timestamp, params.nonce, params.encrypt].map((value) => String(value ?? "")).sort();
4496
- return sha1Hex(parts.join(""));
4497
- }
4498
- function verifyBaiduAppSignature(params) {
4499
- const expected = computeBaiduAppMsgSignature({
4500
- token: params.token,
4501
- timestamp: params.timestamp,
4502
- nonce: params.nonce,
4503
- encrypt: params.encrypt
4504
- });
4505
- return expected === params.signature;
4506
- }
4507
- function decryptBaiduAppEncrypted(params) {
4508
- const aesKey = decodeEncodingAESKey(params.encodingAESKey);
4509
- const iv = aesKey.subarray(0, 16);
4510
- const decipher = crypto.createDecipheriv("aes-256-cbc", aesKey, iv);
4511
- decipher.setAutoPadding(false);
4512
- const decryptedPadded = Buffer.concat([decipher.update(Buffer.from(params.encrypt, "base64")), decipher.final()]);
4513
- const decrypted = pkcs7Unpad(decryptedPadded, PKCS7_BLOCK_SIZE);
4514
- if (decrypted.length < 20) {
4515
- throw new Error(`invalid decrypted payload (expected at least 20 bytes, got ${decrypted.length})`);
4516
- }
4517
- const msgLen = decrypted.readUInt32BE(16);
4518
- const msgStart = 20;
4519
- const msgEnd = msgStart + msgLen;
4520
- if (msgEnd > decrypted.length) {
4521
- throw new Error(`invalid decrypted msg length (msgEnd=${msgEnd}, payloadLength=${decrypted.length})`);
4522
- }
4523
- return decrypted.subarray(msgStart, msgEnd).toString("utf8");
4524
- }
4525
- function encryptBaiduAppPlaintext(params) {
4526
- const aesKey = decodeEncodingAESKey(params.encodingAESKey);
4527
- const iv = aesKey.subarray(0, 16);
4528
- const random16 = crypto.randomBytes(16);
4529
- const msg = Buffer.from(params.plaintext ?? "", "utf8");
4530
- const msgLen = Buffer.alloc(4);
4531
- msgLen.writeUInt32BE(msg.length, 0);
4532
- const raw = Buffer.concat([random16, msgLen, msg]);
4533
- const padded = pkcs7Pad(raw, PKCS7_BLOCK_SIZE);
4534
- const cipher = crypto.createCipheriv("aes-256-cbc", aesKey, iv);
4535
- cipher.setAutoPadding(false);
4536
- const encrypted = Buffer.concat([cipher.update(padded), cipher.final()]);
4537
- return encrypted.toString("base64");
4517
+ logger2.info(`agent reply dispatch complete: sessionKey=${route.sessionKey} sender=${senderId}`);
4538
4518
  }
4539
4519
 
4540
4520
  // src/runtime.ts
@@ -4778,7 +4758,9 @@ function selectDecryptedTarget(params) {
4778
4758
  return params.candidates[0];
4779
4759
  }
4780
4760
  const accountIds = params.candidates.map((candidate) => candidate.target.account.accountId).join(", ");
4781
- params.logger.warn(`multiple baidu-app accounts matched signature; using first match (accounts: ${accountIds})`);
4761
+ params.logger.warn(
4762
+ `multiple openclaw-baiduapp accounts matched signature; using first match (accounts: ${accountIds})`
4763
+ );
4782
4764
  return params.candidates[0];
4783
4765
  }
4784
4766
  function appendStreamContent(state, nextText) {
@@ -4789,7 +4771,7 @@ ${nextText}`.trim() : nextText.trim();
4789
4771
  state.updatedAt = Date.now();
4790
4772
  }
4791
4773
  function buildLogger(target) {
4792
- return createLogger("baidu-app", {
4774
+ return createLogger("openclaw-baiduapp", {
4793
4775
  log: target.runtime.log,
4794
4776
  error: target.runtime.error
4795
4777
  });
@@ -4821,7 +4803,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
4821
4803
  const nonce = query.get("nonce") ?? "";
4822
4804
  const signature = resolveSignatureParam(query);
4823
4805
  const primary = targets[0];
4824
- const logger = buildLogger(primary);
4806
+ const logger2 = buildLogger(primary);
4825
4807
  if (req.method === "GET") {
4826
4808
  const echostr = query.get("echostr") ?? "";
4827
4809
  if (!timestamp || !nonce || !signature || !echostr) {
@@ -4857,7 +4839,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
4857
4839
  jsonError(res, "decrypt failed");
4858
4840
  return true;
4859
4841
  }
4860
- const selected2 = selectDecryptedTarget({ candidates: decryptedCandidates2, logger });
4842
+ const selected2 = selectDecryptedTarget({ candidates: decryptedCandidates2, logger: logger2 });
4861
4843
  jsonOk(res, selected2.plaintext);
4862
4844
  return true;
4863
4845
  }
@@ -4885,14 +4867,14 @@ async function handleBaiduAppWebhookRequest(req, res) {
4885
4867
  msgSignature = xmlData.MsgSignature ?? signature;
4886
4868
  msgTimestamp = xmlData.TimeStamp ?? timestamp;
4887
4869
  msgNonce = xmlData.Nonce ?? nonce;
4888
- logger.info(`inbound xml parsed: hasEncrypt=${Boolean(encrypt)}, msg_signature=${msgSignature ? "yes" : "no"}`);
4870
+ logger2.info(`inbound xml parsed: hasEncrypt=${Boolean(encrypt)}, msg_signature=${msgSignature ? "yes" : "no"}`);
4889
4871
  } else {
4890
4872
  try {
4891
4873
  const record = JSON.parse(rawBody);
4892
4874
  encrypt = String(record.encrypt ?? record.Encrypt ?? "");
4893
- logger.info(`inbound json parsed: hasEncrypt=${Boolean(encrypt)}`);
4875
+ logger2.info(`inbound json parsed: hasEncrypt=${Boolean(encrypt)}`);
4894
4876
  } catch {
4895
- logger.warn(`inbound payload parse failed: not valid xml or json`);
4877
+ logger2.warn(`inbound payload parse failed: not valid xml or json`);
4896
4878
  jsonError(res, "invalid payload format");
4897
4879
  return true;
4898
4880
  }
@@ -4914,15 +4896,15 @@ async function handleBaiduAppWebhookRequest(req, res) {
4914
4896
  });
4915
4897
  });
4916
4898
  if (signatureMatched.length === 0) {
4917
- logger.warn(`signature verification failed: checked ${targets.length} account(s), none matched`);
4899
+ logger2.warn(`signature verification failed: checked ${targets.length} account(s), none matched`);
4918
4900
  jsonError(res, "unauthorized");
4919
4901
  return true;
4920
4902
  }
4921
- logger.debug(`signature verified: ${signatureMatched.length} account(s) matched`);
4903
+ logger2.debug(`signature verified: ${signatureMatched.length} account(s) matched`);
4922
4904
  const decryptable = signatureMatched.filter((candidate) => Boolean(candidate.account.encodingAESKey));
4923
4905
  if (decryptable.length === 0) {
4924
- logger.warn(`no account has encodingAESKey configured`);
4925
- jsonError(res, "baidu-app not configured");
4906
+ logger2.warn(`no account has encodingAESKey configured`);
4907
+ jsonError(res, "openclaw-baiduapp not configured");
4926
4908
  return true;
4927
4909
  }
4928
4910
  const decryptedCandidates = decryptBaiduAppCandidates({
@@ -4930,15 +4912,15 @@ async function handleBaiduAppWebhookRequest(req, res) {
4930
4912
  encrypt
4931
4913
  });
4932
4914
  if (decryptedCandidates.length === 0) {
4933
- logger.warn(`decrypt failed for all ${decryptable.length} candidate account(s)`);
4915
+ logger2.warn(`decrypt failed for all ${decryptable.length} candidate account(s)`);
4934
4916
  jsonError(res, "decrypt failed");
4935
4917
  return true;
4936
4918
  }
4937
- const selected = selectDecryptedTarget({ candidates: decryptedCandidates, logger });
4919
+ const selected = selectDecryptedTarget({ candidates: decryptedCandidates, logger: logger2 });
4938
4920
  const target = selected.target;
4939
4921
  if (!target.account.configured || !target.account.token || !target.account.encodingAESKey) {
4940
- logger.warn(`selected account ${target.account.accountId} not fully configured`);
4941
- jsonError(res, "baidu-app not configured");
4922
+ logger2.warn(`selected account ${target.account.accountId} not fully configured`);
4923
+ jsonError(res, "openclaw-baiduapp not configured");
4942
4924
  return true;
4943
4925
  }
4944
4926
  const msg = selected.msg;
@@ -4946,13 +4928,13 @@ async function handleBaiduAppWebhookRequest(req, res) {
4946
4928
  const msgtype = String(msg.msgtype ?? msg.MsgType ?? "").toLowerCase();
4947
4929
  const msgid = msg.msgid ?? msg.MsgId ? String(msg.msgid ?? msg.MsgId) : void 0;
4948
4930
  const inboundSenderId = msg.from?.userid?.trim() ?? msg.FromUserName?.trim();
4949
- logger.info(
4931
+ logger2.info(
4950
4932
  `inbound: type=${msgtype || "unknown"} msgid=${msgid ?? "none"} sender=${inboundSenderId ?? "unknown"} account=${target.account.accountId}`
4951
4933
  );
4952
4934
  if (msgtype === "stream") {
4953
4935
  const streamId2 = String(msg.stream?.id ?? "").trim();
4954
4936
  const state = streamId2 ? streams.get(streamId2) : void 0;
4955
- logger.info(
4937
+ logger2.info(
4956
4938
  `[REPLY-MODE:STREAM-POLL] stream poll request: streamId=${streamId2 || "none"} found=${Boolean(state)} finished=${state?.finished ?? "n/a"} contentLen=${state?.content.length ?? 0}`
4957
4939
  );
4958
4940
  const reply = state ? buildStreamReplyFromState(state) : buildStreamReplyFromState({
@@ -4973,7 +4955,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
4973
4955
  }
4974
4956
  if (msgid && msgidToStreamId.has(msgid)) {
4975
4957
  const streamId2 = msgidToStreamId.get(msgid) ?? "";
4976
- logger.debug(`duplicate msgid detected: msgid=${msgid} streamId=${streamId2}, returning placeholder`);
4958
+ logger2.debug(`duplicate msgid detected: msgid=${msgid} streamId=${streamId2}, returning placeholder`);
4977
4959
  const reply = buildStreamPlaceholderReply(streamId2);
4978
4960
  jsonOk(
4979
4961
  res,
@@ -4990,15 +4972,15 @@ async function handleBaiduAppWebhookRequest(req, res) {
4990
4972
  const eventtype = String(
4991
4973
  msg.event?.eventtype ?? msg.Event ?? ""
4992
4974
  ).toLowerCase();
4993
- logger.info(`event received: type=${eventtype || "unknown"}`);
4975
+ logger2.info(`event received: type=${eventtype || "unknown"}`);
4994
4976
  if (eventtype === "enter_chat" || eventtype === "subscribe") {
4995
4977
  const welcome = target.account.config.welcomeText?.trim();
4996
4978
  if (welcome && target.account.canSendActive) {
4997
4979
  const senderId2 = msg.from?.userid?.trim() ?? msg.FromUserName?.trim();
4998
4980
  if (senderId2) {
4999
- logger.info(`sending welcome message to ${senderId2}`);
4981
+ logger2.info(`sending welcome message to ${senderId2}`);
5000
4982
  sendBaiduAppMessage(target.account, { userId: senderId2 }, welcome).catch((err) => {
5001
- logger.error(`failed to send welcome message: ${String(err)}`);
4983
+ logger2.error(`failed to send welcome message: ${String(err)}`);
5002
4984
  });
5003
4985
  }
5004
4986
  }
@@ -5037,7 +5019,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
5037
5019
  finished: false,
5038
5020
  content: ""
5039
5021
  });
5040
- logger.info(`stream created: streamId=${streamId} msgid=${msgid ?? "none"}`);
5022
+ logger2.info(`stream created: streamId=${streamId} msgid=${msgid ?? "none"}`);
5041
5023
  const core = tryGetBaiduAppRuntime();
5042
5024
  const senderId = msg.from?.userid?.trim() ?? msg.FromUserName?.trim();
5043
5025
  if (core) {
@@ -5045,7 +5027,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
5045
5027
  if (state) {
5046
5028
  state.started = true;
5047
5029
  }
5048
- logger.info(
5030
+ logger2.info(
5049
5031
  `agent dispatch started: streamId=${streamId} sender=${senderId ?? "unknown"} canSendActive=${target.account.canSendActive}`
5050
5032
  );
5051
5033
  const hooks = {
@@ -5055,7 +5037,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
5055
5037
  return;
5056
5038
  }
5057
5039
  appendStreamContent(current, text);
5058
- logger.debug(
5040
+ logger2.debug(
5059
5041
  `chunk received: streamId=${streamId} chunkLen=${text.length} totalLen=${current.content.length}`
5060
5042
  );
5061
5043
  target.statusSink?.({ lastOutboundAt: Date.now() });
@@ -5068,7 +5050,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
5068
5050
  current.finished = true;
5069
5051
  current.updatedAt = Date.now();
5070
5052
  }
5071
- logger.error(`baidu-app agent failed: ${String(err)}`);
5053
+ logger2.error(`openclaw-baiduapp agent failed: ${String(err)}`);
5072
5054
  }
5073
5055
  };
5074
5056
  dispatchBaiduAppMessage({
@@ -5085,33 +5067,33 @@ async function handleBaiduAppWebhookRequest(req, res) {
5085
5067
  current.finished = true;
5086
5068
  current.updatedAt = Date.now();
5087
5069
  const contentLen = current.content.trim().length;
5088
- logger.info(
5070
+ logger2.info(
5089
5071
  `agent dispatch done: streamId=${streamId} contentLen=${contentLen} canSendActive=${target.account.canSendActive} sender=${senderId ?? "none"}`
5090
5072
  );
5091
5073
  if (!target.account.canSendActive) {
5092
- logger.warn(
5074
+ logger2.warn(
5093
5075
  `active send skipped: appKey/appSecret not configured for account ${target.account.accountId}`
5094
5076
  );
5095
5077
  } else if (!senderId) {
5096
- logger.warn(`active send skipped: senderId is empty`);
5078
+ logger2.warn(`active send skipped: senderId is empty`);
5097
5079
  } else if (!contentLen) {
5098
- logger.warn(`active send skipped: agent produced no content`);
5080
+ logger2.warn(`active send skipped: agent produced no content`);
5099
5081
  }
5100
5082
  if (target.account.canSendActive && senderId && current.content.trim()) {
5101
5083
  try {
5102
5084
  const chunks = splitMessageByBytes(current.content, MAX_MESSAGE_BYTES);
5103
- logger.info(
5085
+ logger2.info(
5104
5086
  `[REPLY-MODE:ACTIVE-SEND] active send starting: streamId=${streamId} to=${senderId} chunks=${chunks.length} contentLen=${contentLen}`
5105
5087
  );
5106
5088
  for (let i = 0; i < chunks.length; i++) {
5107
5089
  await sendBaiduAppMessage(target.account, { userId: senderId }, chunks[i]);
5108
- logger.debug(`active send chunk ${i + 1}/${chunks.length} sent: streamId=${streamId}`);
5090
+ logger2.debug(`active send chunk ${i + 1}/${chunks.length} sent: streamId=${streamId}`);
5109
5091
  }
5110
- logger.info(
5092
+ logger2.info(
5111
5093
  `[REPLY-MODE:ACTIVE-SEND] active send complete: streamId=${streamId} chunks=${chunks.length}`
5112
5094
  );
5113
5095
  } catch (err) {
5114
- logger.error(`active send failed: streamId=${streamId} error=${String(err)}`);
5096
+ logger2.error(`active send failed: streamId=${streamId} error=${String(err)}`);
5115
5097
  }
5116
5098
  }
5117
5099
  }
@@ -5123,10 +5105,10 @@ async function handleBaiduAppWebhookRequest(req, res) {
5123
5105
  current.finished = true;
5124
5106
  current.updatedAt = Date.now();
5125
5107
  }
5126
- logger.error(`agent dispatch failed: streamId=${streamId} error=${String(err)}`);
5108
+ logger2.error(`agent dispatch failed: streamId=${streamId} error=${String(err)}`);
5127
5109
  });
5128
5110
  } else {
5129
- logger.warn(`runtime not available: streamId=${streamId} \u2014 agent dispatch skipped, no reply will be generated`);
5111
+ logger2.warn(`runtime not available: streamId=${streamId} \u2014 agent dispatch skipped, no reply will be generated`);
5130
5112
  const state = streams.get(streamId);
5131
5113
  if (state) {
5132
5114
  state.finished = true;
@@ -5134,7 +5116,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
5134
5116
  }
5135
5117
  }
5136
5118
  const placeholderReply = buildStreamPlaceholderReply(streamId);
5137
- logger.debug(`stream placeholder reply sent: streamId=${streamId}`);
5119
+ logger2.debug(`stream placeholder reply sent: streamId=${streamId}`);
5138
5120
  jsonOk(
5139
5121
  res,
5140
5122
  buildEncryptedJsonReply({
@@ -5149,18 +5131,18 @@ async function handleBaiduAppWebhookRequest(req, res) {
5149
5131
 
5150
5132
  // src/channel.ts
5151
5133
  var meta = {
5152
- id: "baidu-app",
5134
+ id: "openclaw-baiduapp",
5153
5135
  label: "Baidu App",
5154
5136
  selectionLabel: "Baidu Search AI (\u767E\u5EA6\u641C\u7D22\u5BF9\u8BDD\u5F0FAI)",
5155
- docsPath: "/channels/baidu-app",
5156
- docsLabel: "baidu-app",
5137
+ docsPath: "/channels/openclaw-baiduapp",
5138
+ docsLabel: "openclaw-baiduapp",
5157
5139
  blurb: "\u767E\u5EA6\u641C\u7D22\u5BF9\u8BDD\u5F0FAI\uFF0C\u652F\u6301\u4E3B\u52A8\u53D1\u9001\u6D88\u606F",
5158
5140
  aliases: ["baidu-ai", "\u767E\u5EA6\u641C\u7D22AI"],
5159
5141
  order: 85
5160
5142
  };
5161
5143
  var unregisterHooks = /* @__PURE__ */ new Map();
5162
5144
  var baiduAppPlugin = {
5163
- id: "baidu-app",
5145
+ id: "openclaw-baiduapp",
5164
5146
  meta: {
5165
5147
  ...meta
5166
5148
  },
@@ -5175,21 +5157,21 @@ var baiduAppPlugin = {
5175
5157
  activeSend: true
5176
5158
  },
5177
5159
  configSchema: BaiduAppConfigJsonSchema,
5178
- reload: { configPrefixes: ["channels.baidu-app"] },
5160
+ reload: { configPrefixes: ["channels.openclaw-baiduapp"] },
5179
5161
  config: {
5180
5162
  listAccountIds: (cfg) => listBaiduAppAccountIds(cfg),
5181
5163
  resolveAccount: (cfg, accountId) => resolveBaiduAppAccount({ cfg, accountId }),
5182
5164
  defaultAccountId: (cfg) => resolveDefaultBaiduAppAccountId(cfg),
5183
5165
  setAccountEnabled: (params) => {
5184
5166
  const accountId = params.accountId ?? DEFAULT_ACCOUNT_ID;
5185
- const useAccount = Boolean(params.cfg.channels?.["baidu-app"]?.accounts?.[accountId]);
5167
+ const useAccount = Boolean(params.cfg.channels?.["openclaw-baiduapp"]?.accounts?.[accountId]);
5186
5168
  if (!useAccount) {
5187
5169
  return {
5188
5170
  ...params.cfg,
5189
5171
  channels: {
5190
5172
  ...params.cfg.channels,
5191
- "baidu-app": {
5192
- ...params.cfg.channels?.["baidu-app"] ?? {},
5173
+ "openclaw-baiduapp": {
5174
+ ...params.cfg.channels?.["openclaw-baiduapp"] ?? {},
5193
5175
  enabled: params.enabled
5194
5176
  }
5195
5177
  }
@@ -5199,12 +5181,12 @@ var baiduAppPlugin = {
5199
5181
  ...params.cfg,
5200
5182
  channels: {
5201
5183
  ...params.cfg.channels,
5202
- "baidu-app": {
5203
- ...params.cfg.channels?.["baidu-app"] ?? {},
5184
+ "openclaw-baiduapp": {
5185
+ ...params.cfg.channels?.["openclaw-baiduapp"] ?? {},
5204
5186
  accounts: {
5205
- ...params.cfg.channels?.["baidu-app"]?.accounts ?? {},
5187
+ ...params.cfg.channels?.["openclaw-baiduapp"]?.accounts ?? {},
5206
5188
  [accountId]: {
5207
- ...params.cfg.channels?.["baidu-app"]?.accounts?.[accountId] ?? {},
5189
+ ...params.cfg.channels?.["openclaw-baiduapp"]?.accounts?.[accountId] ?? {},
5208
5190
  enabled: params.enabled
5209
5191
  }
5210
5192
  }
@@ -5215,7 +5197,7 @@ var baiduAppPlugin = {
5215
5197
  deleteAccount: (params) => {
5216
5198
  const accountId = params.accountId ?? DEFAULT_ACCOUNT_ID;
5217
5199
  const next = { ...params.cfg };
5218
- const current = next.channels?.["baidu-app"];
5200
+ const current = next.channels?.["openclaw-baiduapp"];
5219
5201
  if (!current) {
5220
5202
  return next;
5221
5203
  }
@@ -5223,7 +5205,7 @@ var baiduAppPlugin = {
5223
5205
  const { accounts: _ignored, defaultAccount: _ignored2, ...rest } = current;
5224
5206
  next.channels = {
5225
5207
  ...next.channels,
5226
- "baidu-app": { ...rest, enabled: false }
5208
+ "openclaw-baiduapp": { ...rest, enabled: false }
5227
5209
  };
5228
5210
  return next;
5229
5211
  }
@@ -5231,7 +5213,7 @@ var baiduAppPlugin = {
5231
5213
  delete accounts[accountId];
5232
5214
  next.channels = {
5233
5215
  ...next.channels,
5234
- "baidu-app": {
5216
+ "openclaw-baiduapp": {
5235
5217
  ...current,
5236
5218
  accounts: Object.keys(accounts).length > 0 ? accounts : void 0
5237
5219
  }
@@ -5245,7 +5227,7 @@ var baiduAppPlugin = {
5245
5227
  enabled: account.enabled,
5246
5228
  configured: account.configured,
5247
5229
  canSendActive: account.canSendActive,
5248
- webhookPath: account.config.webhookPath ?? "/baidu-app"
5230
+ webhookPath: account.config.webhookPath ?? "/openclaw-baiduapp"
5249
5231
  }),
5250
5232
  resolveAllowFrom: (params) => {
5251
5233
  const account = resolveBaiduAppAccount({ cfg: params.cfg, accountId: params.accountId });
@@ -5259,7 +5241,7 @@ var baiduAppPlugin = {
5259
5241
  if (!raw) {
5260
5242
  return false;
5261
5243
  }
5262
- if (raw.startsWith("baidu-app:")) {
5244
+ if (raw.startsWith("openclaw-baiduapp:")) {
5263
5245
  return true;
5264
5246
  }
5265
5247
  const knownChannelPrefixes = [
@@ -5284,7 +5266,7 @@ var baiduAppPlugin = {
5284
5266
  if (!raw) {
5285
5267
  return null;
5286
5268
  }
5287
- const channelPrefix = "baidu-app:";
5269
+ const channelPrefix = "openclaw-baiduapp:";
5288
5270
  if (raw.startsWith(channelPrefix)) {
5289
5271
  raw = raw.slice(channelPrefix.length);
5290
5272
  }
@@ -5299,9 +5281,9 @@ var baiduAppPlugin = {
5299
5281
  }
5300
5282
  }
5301
5283
  if (to.startsWith("user:")) {
5302
- return { channel: "baidu-app", accountId, to: to.slice(5) };
5284
+ return { channel: "openclaw-baiduapp", accountId, to: to.slice(5) };
5303
5285
  }
5304
- return { channel: "baidu-app", accountId, to };
5286
+ return { channel: "openclaw-baiduapp", accountId, to };
5305
5287
  },
5306
5288
  resolveTargets: (params) => {
5307
5289
  const results = [];
@@ -5316,7 +5298,7 @@ var baiduAppPlugin = {
5316
5298
  }
5317
5299
  return results;
5318
5300
  },
5319
- getTargetFormats: () => ["baidu-app:user:<userId>", "user:<userId>", "<userId>"]
5301
+ getTargetFormats: () => ["openclaw-baiduapp:user:<userId>", "user:<userId>", "<userId>"]
5320
5302
  },
5321
5303
  outbound: {
5322
5304
  deliveryMode: "direct",
@@ -5324,14 +5306,14 @@ var baiduAppPlugin = {
5324
5306
  const account = resolveBaiduAppAccount({ cfg: params.cfg, accountId: params.accountId });
5325
5307
  if (!account.canSendActive) {
5326
5308
  return {
5327
- channel: "baidu-app",
5309
+ channel: "openclaw-baiduapp",
5328
5310
  ok: false,
5329
5311
  messageId: "",
5330
5312
  error: new Error("Account not configured for active sending (missing appKey or appSecret)")
5331
5313
  };
5332
5314
  }
5333
5315
  let to = params.to;
5334
- const channelPrefix = "baidu-app:";
5316
+ const channelPrefix = "openclaw-baiduapp:";
5335
5317
  if (to.startsWith(channelPrefix)) {
5336
5318
  to = to.slice(channelPrefix.length);
5337
5319
  }
@@ -5344,14 +5326,56 @@ var baiduAppPlugin = {
5344
5326
  try {
5345
5327
  const result = await sendBaiduAppMessage(account, target, params.text);
5346
5328
  return {
5347
- channel: "baidu-app",
5329
+ channel: "openclaw-baiduapp",
5330
+ ok: result.ok,
5331
+ messageId: result.msgid ?? "",
5332
+ error: result.ok ? void 0 : new Error(result.errmsg ?? "send failed")
5333
+ };
5334
+ } catch (err) {
5335
+ return {
5336
+ channel: "openclaw-baiduapp",
5337
+ ok: false,
5338
+ messageId: "",
5339
+ error: err instanceof Error ? err : new Error(String(err))
5340
+ };
5341
+ }
5342
+ },
5343
+ sendMedia: async (params) => {
5344
+ const account = resolveBaiduAppAccount({ cfg: params.cfg, accountId: params.accountId ?? void 0 });
5345
+ if (!account.canSendActive) {
5346
+ return {
5347
+ channel: "openclaw-baiduapp",
5348
+ ok: false,
5349
+ messageId: "",
5350
+ error: new Error("Account not configured for active sending (missing appKey or appSecret)")
5351
+ };
5352
+ }
5353
+ let to = params.to;
5354
+ const channelPrefix = "openclaw-baiduapp:";
5355
+ if (to.startsWith(channelPrefix)) {
5356
+ to = to.slice(channelPrefix.length);
5357
+ }
5358
+ const target = to.startsWith("user:") ? { userId: to.slice(5) } : { userId: to };
5359
+ const content = params.text?.trim() || params.mediaUrl || "";
5360
+ if (!content) {
5361
+ return {
5362
+ channel: "openclaw-baiduapp",
5363
+ ok: false,
5364
+ messageId: "",
5365
+ error: new Error("No content to send (media not supported, text is empty)")
5366
+ };
5367
+ }
5368
+ try {
5369
+ const result = await sendBaiduAppMessage(account, target, content);
5370
+ return {
5371
+ channel: "openclaw-baiduapp",
5348
5372
  ok: result.ok,
5349
5373
  messageId: result.msgid ?? "",
5350
5374
  error: result.ok ? void 0 : new Error(result.errmsg ?? "send failed")
5351
5375
  };
5352
5376
  } catch (err) {
5353
5377
  return {
5354
- channel: "baidu-app",
5378
+ channel: "openclaw-baiduapp",
5355
5379
  ok: false,
5356
5380
  messageId: "",
5357
5381
  error: err instanceof Error ? err : new Error(String(err))
@@ -5370,11 +5394,11 @@ var baiduAppPlugin = {
5370
5394
  }
5371
5395
  const account = resolveBaiduAppAccount({ cfg: ctx.cfg, accountId: ctx.accountId });
5372
5396
  if (!account.configured) {
5373
- ctx.log?.info(`[baidu-app] account ${ctx.accountId} not configured; webhook not registered`);
5397
+ ctx.log?.info(`[openclaw-baiduapp] account ${ctx.accountId} not configured; webhook not registered`);
5374
5398
  ctx.setStatus?.({ accountId: ctx.accountId, running: false, configured: false });
5375
5399
  return;
5376
5400
  }
5377
- const path = (account.config.webhookPath ?? "/baidu-app").trim();
5401
+ const path = (account.config.webhookPath ?? "/openclaw-baiduapp").trim();
5378
5402
  const unregister = registerBaiduAppWebhookTarget({
5379
5403
  account,
5380
5404
  config: ctx.cfg ?? {},
@@ -5391,7 +5415,7 @@ var baiduAppPlugin = {
5391
5415
  }
5392
5416
  unregisterHooks.set(ctx.accountId, unregister);
5393
5417
  ctx.log?.info(
5394
- `[baidu-app] webhook registered at ${path} for account ${ctx.accountId} (canSendActive=${account.canSendActive})`
5418
+ `[openclaw-baiduapp] webhook registered at ${path} for account ${ctx.accountId} (canSendActive=${account.canSendActive})`
5395
5419
  );
5396
5420
  ctx.setStatus?.({
5397
5421
  accountId: ctx.accountId,
@@ -5416,7 +5440,7 @@ var baiduAppPlugin = {
5416
5440
  // src/send.ts
5417
5441
  function normalizeTarget(target, type) {
5418
5442
  let normalized = target.trim();
5419
- const channelPrefix = "baidu-app:";
5443
+ const channelPrefix = "openclaw-baiduapp:";
5420
5444
  if (normalized.startsWith(channelPrefix)) {
5421
5445
  normalized = normalized.slice(channelPrefix.length);
5422
5446
  }
@@ -5474,7 +5498,7 @@ async function sendBaidu(account, target, options) {
5474
5498
  };
5475
5499
  }
5476
5500
  let normalizedTarget = target.trim();
5477
- const channelPrefix = "baidu-app:";
5501
+ const channelPrefix = "openclaw-baiduapp:";
5478
5502
  if (normalizedTarget.startsWith(channelPrefix)) {
5479
5503
  normalizedTarget = normalizedTarget.slice(channelPrefix.length);
5480
5504
  }
@@ -5504,6 +5528,6 @@ var plugin = {
5504
5528
  };
5505
5529
  var index_default = plugin;
5506
5530
 
5507
- export { DEFAULT_ACCOUNT_ID, baiduAppPlugin, clearAccessTokenCache, clearAllAccessTokenCache, index_default as default, getAccessToken, getBaiduAppRuntime, normalizeTarget, parseTarget, sendBaidu, sendBaiduAppMessage, sendBaiduDM, setBaiduAppRuntime };
5531
+ export { DEFAULT_ACCOUNT_ID, baiduAppPlugin, index_default as default, getBaiduAppRuntime, normalizeTarget, parseTarget, sendBaidu, sendBaiduAppMessage, sendBaiduDM, setBaiduAppRuntime };
5508
5532
  //# sourceMappingURL=index.js.map
5509
5533
  //# sourceMappingURL=index.js.map