mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-24 23:51:48 +00:00
refactor: dedupe channel and gateway surfaces
This commit is contained in:
@@ -61,6 +61,28 @@ function makeProcessMessageArgs(params: {
|
||||
} as any;
|
||||
}
|
||||
|
||||
function createWhatsAppDirectStreamingArgs(params?: {
|
||||
rememberSentText?: (text: string | undefined, opts: unknown) => void;
|
||||
}) {
|
||||
return makeProcessMessageArgs({
|
||||
routeSessionKey: "agent:main:whatsapp:direct:+1555",
|
||||
groupHistoryKey: "+1555",
|
||||
rememberSentText: params?.rememberSentText,
|
||||
cfg: {
|
||||
channels: { whatsapp: { blockStreaming: true } },
|
||||
messages: {},
|
||||
session: { store: sessionStorePath },
|
||||
} as unknown as ReturnType<typeof import("../../../config/config.js").loadConfig>,
|
||||
msg: {
|
||||
id: "msg1",
|
||||
from: "+1555",
|
||||
to: "+2000",
|
||||
chatType: "direct",
|
||||
body: "hi",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
vi.mock("../../../auto-reply/reply/provider-dispatcher.js", () => ({
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
dispatchReplyWithBufferedBlockDispatcher: vi.fn(async (params: any) => {
|
||||
@@ -243,25 +265,7 @@ describe("web processMessage inbound contract", () => {
|
||||
|
||||
it("suppresses non-final WhatsApp payload delivery", async () => {
|
||||
const rememberSentText = vi.fn();
|
||||
await processMessage(
|
||||
makeProcessMessageArgs({
|
||||
routeSessionKey: "agent:main:whatsapp:direct:+1555",
|
||||
groupHistoryKey: "+1555",
|
||||
rememberSentText,
|
||||
cfg: {
|
||||
channels: { whatsapp: { blockStreaming: true } },
|
||||
messages: {},
|
||||
session: { store: sessionStorePath },
|
||||
} as unknown as ReturnType<typeof import("../../../config/config.js").loadConfig>,
|
||||
msg: {
|
||||
id: "msg1",
|
||||
from: "+1555",
|
||||
to: "+2000",
|
||||
chatType: "direct",
|
||||
body: "hi",
|
||||
},
|
||||
}),
|
||||
);
|
||||
await processMessage(createWhatsAppDirectStreamingArgs({ rememberSentText }));
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
const deliver = (capturedDispatchParams as any)?.dispatcherOptions?.deliver as
|
||||
@@ -280,24 +284,7 @@ describe("web processMessage inbound contract", () => {
|
||||
});
|
||||
|
||||
it("forces disableBlockStreaming for WhatsApp dispatch", async () => {
|
||||
await processMessage(
|
||||
makeProcessMessageArgs({
|
||||
routeSessionKey: "agent:main:whatsapp:direct:+1555",
|
||||
groupHistoryKey: "+1555",
|
||||
cfg: {
|
||||
channels: { whatsapp: { blockStreaming: true } },
|
||||
messages: {},
|
||||
session: { store: sessionStorePath },
|
||||
} as unknown as ReturnType<typeof import("../../../config/config.js").loadConfig>,
|
||||
msg: {
|
||||
id: "msg1",
|
||||
from: "+1555",
|
||||
to: "+2000",
|
||||
chatType: "direct",
|
||||
body: "hi",
|
||||
},
|
||||
}),
|
||||
);
|
||||
await processMessage(createWhatsAppDirectStreamingArgs());
|
||||
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
const replyOptions = (capturedDispatchParams as any)?.replyOptions;
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
import { resolveIdentityNamePrefix } from "../../../agents/identity.js";
|
||||
import { resolveChunkMode, resolveTextChunkLimit } from "../../../auto-reply/chunk.js";
|
||||
import { shouldComputeCommandAuthorized } from "../../../auto-reply/command-detection.js";
|
||||
import {
|
||||
formatInboundEnvelope,
|
||||
resolveEnvelopeFormatOptions,
|
||||
} from "../../../auto-reply/envelope.js";
|
||||
import { formatInboundEnvelope } from "../../../auto-reply/envelope.js";
|
||||
import type { getReplyFromConfig } from "../../../auto-reply/reply.js";
|
||||
import {
|
||||
buildHistoryContextFromEntries,
|
||||
@@ -15,13 +12,10 @@ import { dispatchReplyWithBufferedBlockDispatcher } from "../../../auto-reply/re
|
||||
import type { ReplyPayload } from "../../../auto-reply/types.js";
|
||||
import { toLocationContext } from "../../../channels/location.js";
|
||||
import { createReplyPrefixOptions } from "../../../channels/reply-prefix.js";
|
||||
import { resolveInboundSessionEnvelopeContext } from "../../../channels/session-envelope.js";
|
||||
import type { loadConfig } from "../../../config/config.js";
|
||||
import { resolveMarkdownTableMode } from "../../../config/markdown-tables.js";
|
||||
import {
|
||||
readSessionUpdatedAt,
|
||||
recordSessionMetaFromInbound,
|
||||
resolveStorePath,
|
||||
} from "../../../config/sessions.js";
|
||||
import { recordSessionMetaFromInbound } from "../../../config/sessions.js";
|
||||
import { logVerbose, shouldLogVerbose } from "../../../globals.js";
|
||||
import type { getChildLogger } from "../../../logging.js";
|
||||
import { getAgentScopedMediaLocalRoots } from "../../../media/local-roots.js";
|
||||
@@ -142,12 +136,9 @@ export async function processMessage(params: {
|
||||
suppressGroupHistoryClear?: boolean;
|
||||
}) {
|
||||
const conversationId = params.msg.conversationId ?? params.msg.from;
|
||||
const storePath = resolveStorePath(params.cfg.session?.store, {
|
||||
const { storePath, envelopeOptions, previousTimestamp } = resolveInboundSessionEnvelopeContext({
|
||||
cfg: params.cfg,
|
||||
agentId: params.route.agentId,
|
||||
});
|
||||
const envelopeOptions = resolveEnvelopeFormatOptions(params.cfg);
|
||||
const previousTimestamp = readSessionUpdatedAt({
|
||||
storePath,
|
||||
sessionKey: params.route.sessionKey,
|
||||
});
|
||||
let combinedBody = buildInboundLine({
|
||||
|
||||
Reference in New Issue
Block a user