

























@@ -36,6 +36,28 @@ vi.mock("./runtime-api.js", () => ({
3636return phone ? `+${phone}` : null;
3737},
3838logVerbose: () => {},
39+resolveChannelSourceReplyDeliveryMode: ({
40+ cfg,
41+ ctx,
42+}: {
43+cfg: {
44+messages?: {
45+visibleReplies?: "automatic" | "message_tool";
46+groupChat?: { visibleReplies?: "automatic" | "message_tool" };
47+};
48+};
49+ctx: { ChatType?: string; CommandSource?: "native" };
50+}) => {
51+if (ctx.CommandSource === "native") {
52+return "automatic";
53+}
54+if (ctx.ChatType === "group" || ctx.ChatType === "channel") {
55+const configuredMode =
56+cfg.messages?.groupChat?.visibleReplies ?? cfg.messages?.visibleReplies;
57+return configuredMode === "automatic" ? "automatic" : "message_tool_only";
58+}
59+return cfg.messages?.visibleReplies === "message_tool" ? "message_tool_only" : "automatic";
60+},
3961resolveChunkMode: () => "length",
4062resolveIdentityNamePrefix: (cfg: {
4163agents?: { list?: Array<{ id?: string; default?: boolean; identity?: { name?: string } }> };
@@ -139,6 +161,17 @@ function getCapturedOnError() {
139161)?.dispatcherOptions?.onError;
140162}
141163164+function getCapturedReplyOptions() {
165+return (
166+capturedDispatchParams as {
167+replyOptions?: {
168+disableBlockStreaming?: boolean;
169+sourceReplyDeliveryMode?: "automatic" | "message_tool_only";
170+};
171+}
172+)?.replyOptions;
173+}
174+142175type BufferedReplyParams = Parameters<typeof dispatchWhatsAppBufferedReply>[0];
143176144177function makeReplyLogger(): BufferedReplyParams["replyLogger"] {
@@ -575,41 +608,63 @@ describe("whatsapp inbound dispatch", () => {
575608it("maps WhatsApp blockStreaming=true to disableBlockStreaming=false", async () => {
576609await dispatchBufferedReply();
577610578-expect(
579-(
580-capturedDispatchParams as {
581-replyOptions?: { disableBlockStreaming?: boolean };
582-}
583-)?.replyOptions?.disableBlockStreaming,
584-).toBe(false);
611+expect(getCapturedReplyOptions()?.disableBlockStreaming).toBe(false);
585612});
586613587614it("maps WhatsApp blockStreaming=false to disableBlockStreaming=true", async () => {
588615await dispatchBufferedReply({
589616cfg: { channels: { whatsapp: { blockStreaming: false } } } as never,
590617});
591618592-expect(
593-(
594-capturedDispatchParams as {
595-replyOptions?: { disableBlockStreaming?: boolean };
596-}
597-)?.replyOptions?.disableBlockStreaming,
598-).toBe(true);
619+expect(getCapturedReplyOptions()?.disableBlockStreaming).toBe(true);
599620});
600621601622it("leaves disableBlockStreaming undefined when WhatsApp blockStreaming is unset", async () => {
602623await dispatchBufferedReply({
603624cfg: { channels: { whatsapp: {} } } as never,
604625});
605626606-expect(
607-(
608-capturedDispatchParams as {
609-replyOptions?: { disableBlockStreaming?: boolean };
610-}
611-)?.replyOptions?.disableBlockStreaming,
612-).toBeUndefined();
627+expect(getCapturedReplyOptions()?.disableBlockStreaming).toBeUndefined();
628+});
629+630+it("leaves WhatsApp direct reply mode unset by default", async () => {
631+await dispatchBufferedReply({
632+context: { Body: "hi", ChatType: "direct" },
633+msg: makeMsg({ from: "+15550001000", chatType: "direct" }),
634+});
635+636+expect(getCapturedReplyOptions()).toMatchObject({
637+disableBlockStreaming: false,
638+});
639+expect(getCapturedReplyOptions()?.sourceReplyDeliveryMode).toBeUndefined();
640+});
641+642+it("defaults WhatsApp group replies to message-tool-only and disables source streaming", async () => {
643+await dispatchBufferedReply({
644+context: { Body: "hi", ChatType: "group" },
645+msg: makeMsg({ from: "120363000000000000@g.us", chatType: "group" }),
646+});
647+648+expect(getCapturedReplyOptions()).toMatchObject({
649+sourceReplyDeliveryMode: "message_tool_only",
650+disableBlockStreaming: true,
651+});
652+});
653+654+it("honors automatic visible replies for WhatsApp groups", async () => {
655+await dispatchBufferedReply({
656+cfg: {
657+channels: { whatsapp: { blockStreaming: true } },
658+messages: { groupChat: { visibleReplies: "automatic" } },
659+} as never,
660+context: { Body: "hi", ChatType: "group" },
661+msg: makeMsg({ from: "120363000000000000@g.us", chatType: "group" }),
662+});
663+664+expect(getCapturedReplyOptions()).toMatchObject({
665+sourceReplyDeliveryMode: "automatic",
666+disableBlockStreaming: false,
667+});
613668});
614669615670it("treats block-only turns as visible replies instead of silent turns", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。