@searchfe/openclaw-baiduapp 0.1.6 → 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 +15 -1
- package/dist/index.js +60 -49
- 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;
|
|
@@ -387,7 +394,14 @@ interface MoltbotPluginApi {
|
|
|
387
394
|
registerChannel: (opts: {
|
|
388
395
|
plugin: unknown;
|
|
389
396
|
}) => void;
|
|
390
|
-
|
|
397
|
+
registerHttpRoute: (params: {
|
|
398
|
+
path: string;
|
|
399
|
+
handler: (req: IncomingMessage, res: ServerResponse) => Promise<boolean | void> | boolean | void;
|
|
400
|
+
auth: 'plugin' | 'gateway';
|
|
401
|
+
match?: 'exact' | 'prefix';
|
|
402
|
+
replaceExisting?: boolean;
|
|
403
|
+
}) => void;
|
|
404
|
+
registerHttpHandler: any;
|
|
391
405
|
runtime?: unknown;
|
|
392
406
|
[key: string]: unknown;
|
|
393
407
|
}
|
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
|
|
|
@@ -4448,6 +4444,7 @@ async function dispatchBaiduAppMessage(params) {
|
|
|
4448
4444
|
cfg: safeCfg,
|
|
4449
4445
|
dispatcherOptions: {
|
|
4450
4446
|
deliver: async (payload) => {
|
|
4447
|
+
console.log("DELIVER123", payload);
|
|
4451
4448
|
const rawText = payload.text ?? "";
|
|
4452
4449
|
if (!rawText.trim()) {
|
|
4453
4450
|
logger2.debug("deliver callback: empty text, skipping");
|
|
@@ -4487,7 +4484,6 @@ var streams = /* @__PURE__ */ new Map();
|
|
|
4487
4484
|
var msgidToStreamId = /* @__PURE__ */ new Map();
|
|
4488
4485
|
var STREAM_TTL_MS = 10 * 60 * 1e3;
|
|
4489
4486
|
var STREAM_MAX_BYTES = 512e3;
|
|
4490
|
-
var MAX_MESSAGE_BYTES = 2048;
|
|
4491
4487
|
function normalizeWebhookPath(raw) {
|
|
4492
4488
|
const trimmed = raw.trim();
|
|
4493
4489
|
if (!trimmed) {
|
|
@@ -4520,26 +4516,6 @@ function truncateUtf8Bytes(text, maxBytes) {
|
|
|
4520
4516
|
const slice = buf.subarray(buf.length - maxBytes);
|
|
4521
4517
|
return slice.toString("utf8");
|
|
4522
4518
|
}
|
|
4523
|
-
function splitMessageByBytes(text, maxBytes = MAX_MESSAGE_BYTES) {
|
|
4524
|
-
const result = [];
|
|
4525
|
-
let current = "";
|
|
4526
|
-
let currentBytes = 0;
|
|
4527
|
-
for (const char of text) {
|
|
4528
|
-
const charBytes = Buffer.byteLength(char, "utf8");
|
|
4529
|
-
if (currentBytes + charBytes > maxBytes && current.length > 0) {
|
|
4530
|
-
result.push(current);
|
|
4531
|
-
current = char;
|
|
4532
|
-
currentBytes = charBytes;
|
|
4533
|
-
} else {
|
|
4534
|
-
current += char;
|
|
4535
|
-
currentBytes += charBytes;
|
|
4536
|
-
}
|
|
4537
|
-
}
|
|
4538
|
-
if (current.length > 0) {
|
|
4539
|
-
result.push(current);
|
|
4540
|
-
}
|
|
4541
|
-
return result;
|
|
4542
|
-
}
|
|
4543
4519
|
function jsonOk(res, body) {
|
|
4544
4520
|
res.statusCode = 200;
|
|
4545
4521
|
res.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
@@ -4962,6 +4938,8 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4962
4938
|
finished: false,
|
|
4963
4939
|
content: ""
|
|
4964
4940
|
});
|
|
4941
|
+
let nextChunkKey = 0;
|
|
4942
|
+
let activeSendQueue = Promise.resolve();
|
|
4965
4943
|
logger2.info(`stream created: streamId=${streamId} msgid=${msgid ?? "none"}`);
|
|
4966
4944
|
const core = tryGetBaiduAppRuntime();
|
|
4967
4945
|
if (core) {
|
|
@@ -4972,6 +4950,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4972
4950
|
logger2.info(`agent dispatch started: streamId=${streamId} canSendActive=${target.account.canSendActive}`);
|
|
4973
4951
|
const hooks = {
|
|
4974
4952
|
onChunk: (text) => {
|
|
4953
|
+
console.log("CHUNK123", text);
|
|
4975
4954
|
const current = streams.get(streamId);
|
|
4976
4955
|
if (!current) {
|
|
4977
4956
|
return;
|
|
@@ -4981,6 +4960,32 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
4981
4960
|
`chunk received: streamId=${streamId} chunkLen=${text.length} totalLen=${current.content.length}`
|
|
4982
4961
|
);
|
|
4983
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
|
+
});
|
|
4984
4989
|
},
|
|
4985
4990
|
onError: (err) => {
|
|
4986
4991
|
const current = streams.get(streamId);
|
|
@@ -5002,6 +5007,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5002
5007
|
log: target.runtime.log,
|
|
5003
5008
|
error: target.runtime.error
|
|
5004
5009
|
}).then(async () => {
|
|
5010
|
+
await activeSendQueue;
|
|
5005
5011
|
const current = streams.get(streamId);
|
|
5006
5012
|
if (current) {
|
|
5007
5013
|
current.finished = true;
|
|
@@ -5015,28 +5021,13 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
5015
5021
|
`active send skipped: appKey/appSecret not configured for account ${target.account.accountId}`
|
|
5016
5022
|
);
|
|
5017
5023
|
} else if (!contentLen) {
|
|
5018
|
-
logger2.warn(
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
|
|
5025
|
-
);
|
|
5026
|
-
for (let i = 0; i < chunks.length; i++) {
|
|
5027
|
-
await sendBaiduAppMessage(target.account, chunks[i], {
|
|
5028
|
-
msgid,
|
|
5029
|
-
streamId,
|
|
5030
|
-
chunkKey: i
|
|
5031
|
-
});
|
|
5032
|
-
logger2.debug(`active send chunk ${i + 1}/${chunks.length} sent: streamId=${streamId}`);
|
|
5033
|
-
}
|
|
5034
|
-
logger2.info(
|
|
5035
|
-
`[REPLY-MODE:ACTIVE-SEND] active send complete: streamId=${streamId} chunks=${chunks.length}`
|
|
5036
|
-
);
|
|
5037
|
-
} catch (err) {
|
|
5038
|
-
logger2.error(`active send failed: streamId=${streamId} error=${String(err)}`);
|
|
5039
|
-
}
|
|
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
|
+
);
|
|
5040
5031
|
}
|
|
5041
5032
|
}
|
|
5042
5033
|
}).catch((err) => {
|
|
@@ -5098,6 +5089,19 @@ var baiduAppPlugin = {
|
|
|
5098
5089
|
polls: false,
|
|
5099
5090
|
activeSend: true
|
|
5100
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
|
+
},
|
|
5101
5105
|
configSchema: BaiduAppConfigJsonSchema,
|
|
5102
5106
|
reload: { configPrefixes: ["channels.openclaw-baiduapp"] },
|
|
5103
5107
|
config: {
|
|
@@ -5413,7 +5417,14 @@ var plugin = {
|
|
|
5413
5417
|
setBaiduAppRuntime(api.runtime);
|
|
5414
5418
|
}
|
|
5415
5419
|
api.registerChannel({ plugin: baiduAppPlugin });
|
|
5416
|
-
if (api.
|
|
5420
|
+
if (api.registerHttpRoute) {
|
|
5421
|
+
api.registerHttpRoute({
|
|
5422
|
+
path: "/openclaw-baiduapp",
|
|
5423
|
+
auth: "plugin",
|
|
5424
|
+
match: "prefix",
|
|
5425
|
+
handler: handleBaiduAppWebhookRequest
|
|
5426
|
+
});
|
|
5427
|
+
} else if (api.registerHttpHandler) {
|
|
5417
5428
|
api.registerHttpHandler(handleBaiduAppWebhookRequest);
|
|
5418
5429
|
}
|
|
5419
5430
|
}
|