Skip to content

Commit 02ebac6

Browse files
committed
refactor(channels): share turn dispatch results
1 parent f94d970 commit 02ebac6

21 files changed

Lines changed: 380 additions & 68 deletions

File tree

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
81de442c9e0c902621f316297af3ad6c48a07c0c6bbfa5ca984419cfdb7f4292 plugin-sdk-api-baseline.json
2-
136836d047bd0fb0723047945fdbd931a9128552ff49e8a27937d54dba0e9709 plugin-sdk-api-baseline.jsonl
1+
ae28566c922ce79527943b069abc199de28e3898ec08eea12c4ff6050795f276 plugin-sdk-api-baseline.json
2+
79446b23832949553b23e7cf92be37b81c69d123fc09bed6f8fc04bd98e9257d plugin-sdk-api-baseline.jsonl

extensions/discord/src/monitor/message-handler.process.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
} from "openclaw/plugin-sdk/channel-reply-pipeline";
1414
import { resolveChannelStreamingBlockEnabled } from "openclaw/plugin-sdk/channel-streaming";
1515
import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";
16-
import { runPreparedInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";
16+
import {
17+
hasFinalInboundReplyDispatch,
18+
runPreparedInboundReplyTurn,
19+
} from "openclaw/plugin-sdk/inbound-reply-dispatch";
1720
import { resolveMarkdownTableMode } from "openclaw/plugin-sdk/markdown-table-runtime";
1821
import { getAgentScopedMediaLocalRoots } from "openclaw/plugin-sdk/media-runtime";
1922
import { resolveChunkMode } from "openclaw/plugin-sdk/reply-chunking";
@@ -643,7 +646,7 @@ export async function processDiscordMessage(
643646
return;
644647
}
645648

646-
if (!dispatchResult?.queuedFinal) {
649+
if (!hasFinalInboundReplyDispatch(dispatchResult)) {
647650
if (isGuildMessage) {
648651
clearHistoryEntriesIfEnabled({
649652
historyMap: guildHistories,

extensions/imessage/src/monitor/monitor-provider.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ import {
1212
} from "openclaw/plugin-sdk/conversation-runtime";
1313
import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";
1414
import { normalizeScpRemoteHost } from "openclaw/plugin-sdk/host-runtime";
15-
import { runPreparedInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";
15+
import {
16+
hasFinalInboundReplyDispatch,
17+
runPreparedInboundReplyTurn,
18+
} from "openclaw/plugin-sdk/inbound-reply-dispatch";
1619
import { isInboundPathAllowed, kindFromMime } from "openclaw/plugin-sdk/media-runtime";
1720
import {
1821
clearHistoryEntriesIfEnabled,
@@ -487,9 +490,7 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
487490
},
488491
}),
489492
});
490-
const queuedFinal = dispatchResult.queuedFinal;
491-
492-
if (!queuedFinal) {
493+
if (!hasFinalInboundReplyDispatch(dispatchResult)) {
493494
if (decision.isGroup && decision.historyKey) {
494495
clearHistoryEntriesIfEnabled({
495496
historyMap: groupHistories,

extensions/line/src/monitor.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import type { webhook } from "@line/bot-sdk";
22
import { createChannelReplyPipeline } from "openclaw/plugin-sdk/channel-reply-pipeline";
33
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
44
import { recordInboundSession } from "openclaw/plugin-sdk/conversation-runtime";
5-
import { runPreparedInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";
5+
import {
6+
hasFinalInboundReplyDispatch,
7+
runPreparedInboundReplyTurn,
8+
} from "openclaw/plugin-sdk/inbound-reply-dispatch";
69
import {
710
dispatchReplyWithBufferedBlockDispatcher,
811
chunkMarkdownText,
@@ -306,9 +309,7 @@ export async function monitorLineProvider(
306309
},
307310
}),
308311
});
309-
const queuedFinal = dispatchResult.queuedFinal;
310-
311-
if (!queuedFinal) {
312+
if (!hasFinalInboundReplyDispatch(dispatchResult)) {
312313
logVerbose(`line: no response generated for message from ${ctxPayload.From}`);
313314
}
314315
} catch (err) {

extensions/matrix/src/matrix/monitor/handler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
evaluateSupplementalContextVisibility,
44
resolveChannelContextVisibilityMode,
55
} from "openclaw/plugin-sdk/context-visibility-runtime";
6+
import { hasFinalInboundReplyDispatch } from "openclaw/plugin-sdk/inbound-reply-dispatch";
67
import type { GetReplyOptions } from "openclaw/plugin-sdk/reply-runtime";
78
import {
89
loadSessionStore,
@@ -1963,7 +1964,7 @@ export function createMatrixRoomMessageHandler(params: MatrixMonitorHandlerParam
19631964
if (isRoom && triggerSnapshot) {
19641965
roomHistoryTracker.consumeHistory(_route.agentId, roomId, triggerSnapshot, _messageId);
19651966
}
1966-
if (!queuedFinal) {
1967+
if (!hasFinalInboundReplyDispatch({ queuedFinal, counts })) {
19671968
await commitInboundEventIfClaimed();
19681969
return;
19691970
}

extensions/msteams/src/monitor-handler/message-handler.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
shouldIncludeSupplementalContext,
1212
} from "openclaw/plugin-sdk/context-visibility-runtime";
1313
import { evaluateSenderGroupAccessForPolicy } from "openclaw/plugin-sdk/group-access";
14-
import { dispatchReplyFromConfigWithSettledDispatcher } from "openclaw/plugin-sdk/inbound-reply-dispatch";
14+
import {
15+
dispatchReplyFromConfigWithSettledDispatcher,
16+
hasFinalInboundReplyDispatch,
17+
resolveInboundReplyDispatchCounts,
18+
} from "openclaw/plugin-sdk/inbound-reply-dispatch";
1519
import {
1620
buildPendingHistoryContextFromMap,
1721
clearHistoryEntriesIfEnabled,
@@ -864,11 +868,12 @@ export function createMSTeamsMessageHandler(deps: MSTeamsMessageHandlerDeps) {
864868
}),
865869
});
866870
const queuedFinal = dispatchResult?.queuedFinal ?? false;
867-
const counts = dispatchResult?.counts ?? { tool: 0, block: 0, final: 0 };
871+
const counts = resolveInboundReplyDispatchCounts(dispatchResult);
872+
const hasFinalResponse = hasFinalInboundReplyDispatch(dispatchResult);
868873

869874
log.info("dispatch complete", { queuedFinal, counts });
870875

871-
if (!queuedFinal) {
876+
if (!hasFinalResponse) {
872877
if (isRoomish && historyKey) {
873878
clearHistoryEntriesIfEnabled({
874879
historyMap: conversationHistories,

extensions/signal/src/monitor/event-handler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import {
2525
toInternalMessageReceivedContext,
2626
triggerInternalHook,
2727
} from "openclaw/plugin-sdk/hook-runtime";
28-
import { runPreparedInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";
28+
import {
29+
hasFinalInboundReplyDispatch,
30+
runPreparedInboundReplyTurn,
31+
} from "openclaw/plugin-sdk/inbound-reply-dispatch";
2932
import { kindFromMime } from "openclaw/plugin-sdk/media-runtime";
3033
import {
3134
buildPendingHistoryContextFromMap,
@@ -351,8 +354,7 @@ export function createSignalEventHandler(deps: SignalEventHandlerDeps) {
351354
}
352355
},
353356
});
354-
const queuedFinal = dispatchResult?.queuedFinal ?? false;
355-
if (!queuedFinal) {
357+
if (!hasFinalInboundReplyDispatch(dispatchResult)) {
356358
if (entry.isGroup && historyKey) {
357359
clearHistoryEntriesIfEnabled({
358360
historyMap: deps.groupHistories,

extensions/slack/src/monitor/message-handler/dispatch.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import {
1818
resolveChannelStreamingPreviewToolProgress,
1919
} from "openclaw/plugin-sdk/channel-streaming";
2020
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
21-
import { runPreparedInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";
21+
import {
22+
hasVisibleInboundReplyDispatch,
23+
runPreparedInboundReplyTurn,
24+
} from "openclaw/plugin-sdk/inbound-reply-dispatch";
2225
import { resolveAgentOutboundIdentity } from "openclaw/plugin-sdk/outbound-runtime";
2326
import { clearHistoryEntriesIfEnabled } from "openclaw/plugin-sdk/reply-history";
2427
import { resolveSendableOutboundReplyParts } from "openclaw/plugin-sdk/reply-payload";
@@ -1099,12 +1102,13 @@ export async function dispatchPreparedSlackMessage(prepared: PreparedSlackMessag
10991102
}
11001103
}
11011104

1102-
const anyReplyDelivered =
1103-
observedReplyDelivery ||
1104-
queuedFinal ||
1105-
streamFallbackDelivered ||
1106-
(counts.block ?? 0) > 0 ||
1107-
(counts.final ?? 0) > 0;
1105+
const anyReplyDelivered = hasVisibleInboundReplyDispatch(
1106+
{ queuedFinal, counts },
1107+
{
1108+
observedReplyDelivery,
1109+
fallbackDelivered: streamFallbackDelivered,
1110+
},
1111+
);
11081112

11091113
if (statusReactionsEnabled) {
11101114
if (dispatchError) {

extensions/telegram/src/bot-message-dispatch.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ import type {
1717
TelegramAccountConfig,
1818
} from "openclaw/plugin-sdk/config-types";
1919
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
20-
import { runPreparedInboundReplyTurn } from "openclaw/plugin-sdk/inbound-reply-dispatch";
20+
import {
21+
hasFinalInboundReplyDispatch,
22+
runPreparedInboundReplyTurn,
23+
} from "openclaw/plugin-sdk/inbound-reply-dispatch";
2124
import {
2225
createOutboundPayloadPlan,
2326
projectOutboundPayloadPlanForDelivery,
@@ -1306,7 +1309,13 @@ export const dispatchTelegramMessage = async ({
13061309
});
13071310
}
13081311

1309-
const hasFinalResponse = queuedFinal || sentFallback || deliverySummary.delivered;
1312+
const hasFinalResponse = hasFinalInboundReplyDispatch(
1313+
{ queuedFinal },
1314+
{
1315+
fallbackDelivered: sentFallback,
1316+
deliverySummaryDelivered: deliverySummary.delivered,
1317+
},
1318+
);
13101319

13111320
if (statusReactionController && !hasFinalResponse) {
13121321
void finalizeTelegramStatusReaction({ outcome: "error", hasFinalResponse: false }).catch(

extensions/whatsapp/src/auto-reply/monitor/inbound-dispatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { hasVisibleInboundReplyDispatch } from "openclaw/plugin-sdk/inbound-reply-dispatch";
12
import {
23
type DeliverableWhatsAppOutboundPayload,
34
normalizeWhatsAppOutboundPayload,
@@ -388,8 +389,7 @@ export async function dispatchWhatsAppBufferedReply(params: {
388389
},
389390
});
390391

391-
const didQueueVisibleReply =
392-
queuedFinal || counts.tool > 0 || counts.block > 0 || counts.final > 0;
392+
const didQueueVisibleReply = hasVisibleInboundReplyDispatch({ queuedFinal, counts });
393393
if (!didQueueVisibleReply) {
394394
if (params.shouldClearGroupHistory) {
395395
params.groupHistories.set(params.groupHistoryKey, []);

0 commit comments

Comments
 (0)