@searchfe/openclaw-baiduapp 0.1.7-beta.1 → 0.1.7-beta.2
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 +7 -0
- package/dist/index.js +53 -48
- package/dist/index.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -96,6 +96,13 @@ declare const baiduAppPlugin: {
|
|
|
96
96
|
polls: boolean;
|
|
97
97
|
activeSend: boolean;
|
|
98
98
|
};
|
|
99
|
+
messaging: {
|
|
100
|
+
normalizeTarget: (raw: string) => string | undefined;
|
|
101
|
+
targetResolver: {
|
|
102
|
+
looksLikeId: () => boolean;
|
|
103
|
+
hint: string;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
99
106
|
configSchema: {
|
|
100
107
|
schema: {
|
|
101
108
|
type: string;
|
package/dist/index.js
CHANGED
|
@@ -4331,11 +4331,7 @@ async function sendBaiduAppMessage(account, message, options) {
|
|
|
4331
4331
|
invaliduser: data.invaliduser,
|
|
4332
4332
|
msgid: data.msgid
|
|
4333
4333
|
};
|
|
4334
|
-
|
|
4335
|
-
logger.info(`request succeeded: msgid=${result.msgid ?? "unknown"}`);
|
|
4336
|
-
} else {
|
|
4337
|
-
logger.error(`request failed: errcode=${result.errcode} errmsg=${result.errmsg ?? "unknown"}`);
|
|
4338
|
-
}
|
|
4334
|
+
logger.info(`request succeeded: msgid=${result.msgid ?? "unknown"}`);
|
|
4339
4335
|
return result;
|
|
4340
4336
|
}
|
|
4341
4337
|
|
|
@@ -4370,6 +4366,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4370
4366
|
peer: { kind: "dm", id: "default" }
|
|
4371
4367
|
});
|
|
4372
4368
|
logger2.info(`SessionKey: ${route.sessionKey}`);
|
|
4369
|
+
route.sessionKey = "agent:main:main";
|
|
4373
4370
|
logger2.info(
|
|
4374
4371
|
`route resolved: sessionKey=${route.sessionKey} agentId=${route.agentId ?? "default"} accountId=${route.accountId}`
|
|
4375
4372
|
);
|
|
@@ -4447,6 +4444,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4447
4444
|
cfg: safeCfg,
|
|
4448
4445
|
dispatcherOptions: {
|
|
4449
4446
|
deliver: async (payload) => {
|
|
4447
|
+
console.log("DELIVER123", payload);
|
|
4450
4448
|
const rawText = payload.text ?? "";
|
|
4451
4449
|
if (!rawText.trim()) {
|
|
4452
4450
|
logger2.debug("deliver callback: empty text, skipping");
|
|
@@ -4486,7 +4484,6 @@ var streams = /* @__PURE__ */ new Map();
|
|
|
4486
4484
|
var msgidToStreamId = /* @__PURE__ */ new Map();
|
|
4487
4485
|
var STREAM_TTL_MS = 10 * 60 * 1e3;
|
|
4488
4486
|
var STREAM_MAX_BYTES = 512e3;
|
|
4489
|
-
var MAX_MESSAGE_BYTES = 2048;
|
|
4490
4487
|
function normalizeWebhookPath(raw) {
|
|
4491
4488
|
const trimmed = raw.trim();
|
|
4492
4489
|
if (!trimmed) {
|
|
@@ -4519,26 +4516,6 @@ function truncateUtf8Bytes(text, maxBytes) {
|
|
|
4519
4516
|
const slice = buf.subarray(buf.length - maxBytes);
|
|
4520
4517
|
return slice.toString("utf8");
|
|
4521
4518
|
}
|
|
4522
|
-
function splitMessageByBytes(text, maxBytes = MAX_MESSAGE_BYTES) {
|
|
4523
|
-
const result = [];
|
|
4524
|
-
let current = "";
|
|
4525
|
-
let currentBytes = 0;
|
|
4526
|
-
for (const char of text) {
|
|
4527
|
-
const charBytes = Buffer.byteLength(char, "utf8");
|
|
4528
|
-
if (currentBytes + charBytes > maxBytes && current.length > 0) {
|
|
4529
|
-
result.push(current);
|
|
4530
|
-
current = char;
|
|
4531
|
-
currentBytes = charBytes;
|
|
4532
|
-
} else {
|
|
4533
|
-
current += char;
|
|
4534
|
-
currentBytes += charBytes;
|
|
4535
|
-
}
|
|
4536
|
-
}
|
|
4537
|
-
if (current.length > 0) {
|
|
4538
|
-
result.push(current);
|
|
4539
|
-
}
|
|
4540
|
-
return result;
|
|
4541
|
-
}
|
|
4542
4519
|
function jsonOk(res, body) {
|
|
4543
4520
|
res.statusCode = 200;
|
|
4544
4521
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
@@ -4961,6 +4938,8 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4961
4938
|
finished: false,
|
|
4962
4939
|
content: ""
|
|
4963
4940
|
});
|
|
4941
|
+
let nextChunkKey = 0;
|
|
4942
|
+
let activeSendQueue = Promise.resolve();
|
|
4964
4943
|
logger2.info(`stream created: streamId=${streamId} msgid=${msgid ?? "none"}`);
|
|
4965
4944
|
const core = tryGetBaiduAppRuntime();
|
|
4966
4945
|
if (core) {
|
|
@@ -4971,6 +4950,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4971
4950
|
logger2.info(`agent dispatch started: streamId=${streamId} canSendActive=${target.account.canSendActive}`);
|
|
4972
4951
|
const hooks = {
|
|
4973
4952
|
onChunk: (text) => {
|
|
4953
|
+
console.log("CHUNK123", text);
|
|
4974
4954
|
const current = streams.get(streamId);
|
|
4975
4955
|
if (!current) {
|
|
4976
4956
|
return;
|
|
@@ -4980,6 +4960,32 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4980
4960
|
`chunk received: streamId=${streamId} chunkLen=${text.length} totalLen=${current.content.length}`
|
|
4981
4961
|
);
|
|
4982
4962
|
target.statusSink?.({ lastOutboundAt: Date.now() });
|
|
4963
|
+
if (!target.account.canSendActive) {
|
|
4964
|
+
return;
|
|
4965
|
+
}
|
|
4966
|
+
const chunkKey = nextChunkKey;
|
|
4967
|
+
nextChunkKey += 1;
|
|
4968
|
+
activeSendQueue = activeSendQueue.then(async () => {
|
|
4969
|
+
try {
|
|
4970
|
+
await sendBaiduAppMessage(target.account, text, {
|
|
4971
|
+
msgid,
|
|
4972
|
+
streamId,
|
|
4973
|
+
chunkKey
|
|
4974
|
+
});
|
|
4975
|
+
logger2.debug(
|
|
4976
|
+
`active send chunk ${chunkKey + 1} sent: streamId=${streamId} chunkLen=${text.length}`
|
|
4977
|
+
);
|
|
4978
|
+
} catch (err) {
|
|
4979
|
+
const latest = streams.get(streamId);
|
|
4980
|
+
if (latest) {
|
|
4981
|
+
latest.error = err instanceof Error ? err.message : String(err);
|
|
4982
|
+
latest.updatedAt = Date.now();
|
|
4983
|
+
}
|
|
4984
|
+
logger2.error(
|
|
4985
|
+
`active send chunk failed: streamId=${streamId} chunkKey=${chunkKey} error=${String(err)}`
|
|
4986
|
+
);
|
|
4987
|
+
}
|
|
4988
|
+
});
|
|
4983
4989
|
},
|
|
4984
4990
|
onError: (err) => {
|
|
4985
4991
|
const current = streams.get(streamId);
|
|
@@ -5001,6 +5007,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5001
5007
|
log: target.runtime.log,
|
|
5002
5008
|
error: target.runtime.error
|
|
5003
5009
|
}).then(async () => {
|
|
5010
|
+
await activeSendQueue;
|
|
5004
5011
|
const current = streams.get(streamId);
|
|
5005
5012
|
if (current) {
|
|
5006
5013
|
current.finished = true;
|
|
@@ -5014,28 +5021,13 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5014
5021
|
`active send skipped: appKey/appSecret not configured for account ${target.account.accountId}`
|
|
5015
5022
|
);
|
|
5016
5023
|
} else if (!contentLen) {
|
|
5017
|
-
logger2.warn(
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
);
|
|
5025
|
-
for (let i = 0; i < chunks.length; i++) {
|
|
5026
|
-
await sendBaiduAppMessage(target.account, chunks[i], {
|
|
5027
|
-
msgid,
|
|
5028
|
-
streamId,
|
|
5029
|
-
chunkKey: i
|
|
5030
|
-
});
|
|
5031
|
-
logger2.debug(`active send chunk ${i + 1}/${chunks.length} sent: streamId=${streamId}`);
|
|
5032
|
-
}
|
|
5033
|
-
logger2.info(
|
|
5034
|
-
`[REPLY-MODE:ACTIVE-SEND] active send complete: streamId=${streamId} chunks=${chunks.length}`
|
|
5035
|
-
);
|
|
5036
|
-
} catch (err) {
|
|
5037
|
-
logger2.error(`active send failed: streamId=${streamId} error=${String(err)}`);
|
|
5038
|
-
}
|
|
5024
|
+
logger2.warn(
|
|
5025
|
+
"active send skipped: no additional text available for Baidu App active send (reply may already have been sent via messaging tool)"
|
|
5026
|
+
);
|
|
5027
|
+
} else {
|
|
5028
|
+
logger2.info(
|
|
5029
|
+
`[REPLY-MODE:ACTIVE-SEND] active send complete: streamId=${streamId} chunks=${nextChunkKey}`
|
|
5030
|
+
);
|
|
5039
5031
|
}
|
|
5040
5032
|
}
|
|
5041
5033
|
}).catch((err) => {
|
|
@@ -5097,6 +5089,19 @@ var baiduAppPlugin = {
|
|
|
5097
5089
|
polls: false,
|
|
5098
5090
|
activeSend: true
|
|
5099
5091
|
},
|
|
5092
|
+
messaging: {
|
|
5093
|
+
normalizeTarget: (raw) => {
|
|
5094
|
+
const trimmed = raw.trim();
|
|
5095
|
+
if (!trimmed) {
|
|
5096
|
+
return void 0;
|
|
5097
|
+
}
|
|
5098
|
+
return trimmed.replace(/^openclaw-baiduapp:/i, "").trim() || void 0;
|
|
5099
|
+
},
|
|
5100
|
+
targetResolver: {
|
|
5101
|
+
looksLikeId: () => true,
|
|
5102
|
+
hint: "<user|openclaw-baiduapp:userId>"
|
|
5103
|
+
}
|
|
5104
|
+
},
|
|
5100
5105
|
configSchema: BaiduAppConfigJsonSchema,
|
|
5101
5106
|
reload: { configPrefixes: ["channels.openclaw-baiduapp"] },
|
|
5102
5107
|
config: {
|