@searchfe/openclaw-baiduapp 0.1.12-beta.1 → 0.1.12-beta.3
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 +37 -6
- package/dist/index.js.map +1 -1
- package/openclaw.plugin.json +1 -1
- package/package.json +3 -9
- package/cli.js +0 -282
- package/src/cli-qrcode.mjs +0 -5
package/dist/index.js
CHANGED
|
@@ -28506,6 +28506,7 @@ async function handleBaiduAppWebhookRequest(req, res) {
|
|
|
28506
28506
|
// src/poller.ts
|
|
28507
28507
|
var DEFAULT_POLL_INTERVAL_MS = 3e3;
|
|
28508
28508
|
var DEFAULT_POLL_REQUEST_TIMEOUT_MS = 1e4;
|
|
28509
|
+
var pollerLogger = createLogger("openclaw-baiduapp:poller");
|
|
28509
28510
|
var accountPollers = /* @__PURE__ */ new Map();
|
|
28510
28511
|
function buildPollingTextInboundMessage(content) {
|
|
28511
28512
|
return {
|
|
@@ -28541,8 +28542,10 @@ async function dispatchPendingPollingMessages(data, target) {
|
|
|
28541
28542
|
const list = Array.isArray(item.list) ? item.list : [];
|
|
28542
28543
|
const { content, files } = parseTextAndFilesFromList(list);
|
|
28543
28544
|
if (typeof content !== "string" && files.length === 0) {
|
|
28545
|
+
pollerLogger.debug(`dispatch skip: msgId=${item.msgId ?? "?"} agentId=${item.agentId ?? "none"} reason=no-content`);
|
|
28544
28546
|
continue;
|
|
28545
28547
|
}
|
|
28548
|
+
pollerLogger.info(`dispatch msg: msgId=${item.msgId ?? "?"} agentId=${item.agentId ?? "none"} files=${files.length} hasText=${typeof content === "string"}`);
|
|
28546
28549
|
await processBaiduAppInboundMessage({
|
|
28547
28550
|
target,
|
|
28548
28551
|
msg: {
|
|
@@ -28627,6 +28630,7 @@ async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions)
|
|
|
28627
28630
|
version: PLUGIN_VERSION
|
|
28628
28631
|
};
|
|
28629
28632
|
const body = JSON.stringify(payload);
|
|
28633
|
+
logger3.debug(`poll request: accountId=${account.accountId} url=${endpoint} sessionId=${payload.sessionId}`);
|
|
28630
28634
|
const requestSignal = createAbortSignalController({
|
|
28631
28635
|
signal: requestOptions?.signal,
|
|
28632
28636
|
timeoutMs: requestOptions?.timeoutMs
|
|
@@ -28645,6 +28649,7 @@ async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions)
|
|
|
28645
28649
|
} catch (error) {
|
|
28646
28650
|
requestSignal.cleanup();
|
|
28647
28651
|
if (requestSignal.didTimeout()) {
|
|
28652
|
+
logger3.warn(`poll timeout: accountId=${account.accountId} timeoutMs=${requestOptions?.timeoutMs}`);
|
|
28648
28653
|
return buildPollResult({
|
|
28649
28654
|
ok: false,
|
|
28650
28655
|
error: {
|
|
@@ -28654,6 +28659,7 @@ async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions)
|
|
|
28654
28659
|
});
|
|
28655
28660
|
}
|
|
28656
28661
|
if (isAbortError2(error)) {
|
|
28662
|
+
logger3.debug(`poll aborted: accountId=${account.accountId}`);
|
|
28657
28663
|
return buildPollResult({
|
|
28658
28664
|
ok: false,
|
|
28659
28665
|
error: {
|
|
@@ -28662,17 +28668,20 @@ async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions)
|
|
|
28662
28668
|
}
|
|
28663
28669
|
});
|
|
28664
28670
|
}
|
|
28671
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
28672
|
+
logger3.error(`poll request failed: accountId=${account.accountId} error=${errMsg}`);
|
|
28665
28673
|
return buildPollResult({
|
|
28666
28674
|
ok: false,
|
|
28667
28675
|
error: {
|
|
28668
28676
|
kind: "request-failed",
|
|
28669
|
-
message:
|
|
28677
|
+
message: errMsg
|
|
28670
28678
|
}
|
|
28671
28679
|
});
|
|
28672
28680
|
}
|
|
28673
28681
|
const responseText = await response.text();
|
|
28674
28682
|
requestSignal.cleanup();
|
|
28675
28683
|
if (!responseText) {
|
|
28684
|
+
logger3.warn(`poll empty response: accountId=${account.accountId} status=${response.status}`);
|
|
28676
28685
|
return buildPollResult({
|
|
28677
28686
|
ok: false,
|
|
28678
28687
|
error: {
|
|
@@ -28685,6 +28694,7 @@ async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions)
|
|
|
28685
28694
|
try {
|
|
28686
28695
|
parsed = JSON.parse(responseText);
|
|
28687
28696
|
} catch {
|
|
28697
|
+
logger3.warn(`poll invalid json: accountId=${account.accountId} status=${response.status}`);
|
|
28688
28698
|
return buildPollResult({
|
|
28689
28699
|
ok: false,
|
|
28690
28700
|
error: {
|
|
@@ -28693,10 +28703,12 @@ async function pollBaiduAppChatlistOnce(account, loggerOptions, requestOptions)
|
|
|
28693
28703
|
}
|
|
28694
28704
|
});
|
|
28695
28705
|
}
|
|
28706
|
+
const msgList = Array.isArray(parsed.data?.msgList) ? parsed.data.msgList : [];
|
|
28696
28707
|
if (parsed.code !== 0) {
|
|
28697
|
-
logger3.debug(`
|
|
28708
|
+
logger3.debug(`poll non-zero code: accountId=${account.accountId} code=${String(parsed.code)} message=${parsed.message}`);
|
|
28709
|
+
} else {
|
|
28710
|
+
logger3.debug(`poll ok: accountId=${account.accountId} status=${response.status} msgCount=${msgList.length}`);
|
|
28698
28711
|
}
|
|
28699
|
-
const msgList = Array.isArray(parsed.data?.msgList) ? parsed.data.msgList : [];
|
|
28700
28712
|
return buildPollResult({
|
|
28701
28713
|
ok: true,
|
|
28702
28714
|
data: msgList
|
|
@@ -28706,6 +28718,7 @@ function scheduleNextPoll(account, state) {
|
|
|
28706
28718
|
if (state.stopped) {
|
|
28707
28719
|
return;
|
|
28708
28720
|
}
|
|
28721
|
+
pollerLogger.debug(`schedule next poll: accountId=${account.accountId} intervalMs=${state.intervalMs}`);
|
|
28709
28722
|
state.timer = setTimeout(() => {
|
|
28710
28723
|
void runPollCycle(account, state);
|
|
28711
28724
|
}, state.intervalMs);
|
|
@@ -28714,6 +28727,9 @@ async function runPollCycle(account, state) {
|
|
|
28714
28727
|
if (state.stopped || state.pending) {
|
|
28715
28728
|
return;
|
|
28716
28729
|
}
|
|
28730
|
+
state.cycleCount += 1;
|
|
28731
|
+
const cycle = state.cycleCount;
|
|
28732
|
+
pollerLogger.debug(`poll cycle #${cycle} start: accountId=${account.accountId}`);
|
|
28717
28733
|
const controller = new AbortController();
|
|
28718
28734
|
state.activeController = controller;
|
|
28719
28735
|
const pending = (async () => {
|
|
@@ -28723,9 +28739,18 @@ async function runPollCycle(account, state) {
|
|
|
28723
28739
|
fetchImpl: state.fetchImpl,
|
|
28724
28740
|
timeoutMs: state.requestTimeoutMs
|
|
28725
28741
|
});
|
|
28742
|
+
if (!result2.ok && result2.error) {
|
|
28743
|
+
if (result2.error.kind !== "aborted") {
|
|
28744
|
+
pollerLogger.warn(`poll cycle #${cycle} error: accountId=${account.accountId} kind=${result2.error.kind} msg=${result2.error.message}`);
|
|
28745
|
+
}
|
|
28746
|
+
} else if (result2.data.length > 0) {
|
|
28747
|
+
pollerLogger.info(`poll cycle #${cycle} msgs: accountId=${account.accountId} count=${result2.data.length}`);
|
|
28748
|
+
}
|
|
28726
28749
|
await dispatchPendingPollingMessages(result2.data, state.dispatchTarget);
|
|
28727
28750
|
} catch (error) {
|
|
28728
28751
|
if (!(state.stopped && isAbortError2(error))) {
|
|
28752
|
+
const errMsg = error instanceof Error ? error.message : String(error);
|
|
28753
|
+
pollerLogger.error(`poll cycle #${cycle} unhandled error: accountId=${account.accountId} error=${errMsg}`);
|
|
28729
28754
|
state.onError?.(error);
|
|
28730
28755
|
}
|
|
28731
28756
|
} finally {
|
|
@@ -28743,18 +28768,23 @@ async function runPollCycle(account, state) {
|
|
|
28743
28768
|
}
|
|
28744
28769
|
function startAccountPolling(params) {
|
|
28745
28770
|
if (accountPollers.has(params.account.accountId)) {
|
|
28771
|
+
pollerLogger.debug(`polling already running: accountId=${params.account.accountId}, skip`);
|
|
28746
28772
|
return;
|
|
28747
28773
|
}
|
|
28774
|
+
const intervalMs = params.intervalMs ?? DEFAULT_POLL_INTERVAL_MS;
|
|
28775
|
+
const requestTimeoutMs = params.requestTimeoutMs ?? DEFAULT_POLL_REQUEST_TIMEOUT_MS;
|
|
28776
|
+
pollerLogger.info(`start polling: accountId=${params.account.accountId} intervalMs=${intervalMs} timeoutMs=${requestTimeoutMs} apiBase=${params.account.apiBase}`);
|
|
28748
28777
|
const state = {
|
|
28749
28778
|
stopped: false,
|
|
28750
28779
|
timer: null,
|
|
28751
28780
|
activeController: null,
|
|
28752
28781
|
pending: null,
|
|
28753
|
-
intervalMs
|
|
28754
|
-
requestTimeoutMs
|
|
28782
|
+
intervalMs,
|
|
28783
|
+
requestTimeoutMs,
|
|
28755
28784
|
fetchImpl: params.fetchImpl,
|
|
28756
28785
|
onError: params.onError,
|
|
28757
|
-
dispatchTarget: params.dispatchTarget
|
|
28786
|
+
dispatchTarget: params.dispatchTarget,
|
|
28787
|
+
cycleCount: 0
|
|
28758
28788
|
};
|
|
28759
28789
|
accountPollers.set(params.account.accountId, state);
|
|
28760
28790
|
void runPollCycle(params.account, state);
|
|
@@ -28764,6 +28794,7 @@ function stopAccountPolling(accountId) {
|
|
|
28764
28794
|
if (!state) {
|
|
28765
28795
|
return;
|
|
28766
28796
|
}
|
|
28797
|
+
pollerLogger.info(`stop polling: accountId=${accountId} totalCycles=${state.cycleCount}`);
|
|
28767
28798
|
state.stopped = true;
|
|
28768
28799
|
if (state.timer) {
|
|
28769
28800
|
clearTimeout(state.timer);
|