Skip to content

Commit 0efd5b4

Browse files
authored
refactor(channels): move owner policy into plugins (#121257)
* refactor(channels): move owner policy into plugins * test(plugin-sdk): lower surface budget after export removal
1 parent 42283cb commit 0efd5b4

13 files changed

Lines changed: 226 additions & 282 deletions

File tree

‎docs/.generated/plugin-sdk-api-baseline.sha256‎

Lines changed: 116 additions & 116 deletions
Large diffs are not rendered by default.

‎extensions/whatsapp/src/auto-reply/monitor/reaction-eligibility.ts‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { shouldAckReactionForWhatsApp } from "openclaw/plugin-sdk/channel-feedback";
1+
import { shouldAckReaction } from "openclaw/plugin-sdk/channel-feedback";
22
import type { OpenClawConfig } from "openclaw/plugin-sdk/config-contracts";
33
import { requireWhatsAppInboundAdmission } from "../../inbound/admission.js";
44
import type { AdmittedWebInboundMessage } from "../../inbound/types.js";
@@ -38,9 +38,6 @@ export async function resolveWhatsAppReactionEligibility(params: {
3838
agentId: params.agentId,
3939
ackConfig: params.cfg.messages?.ackReaction,
4040
});
41-
const directEnabled = scope === "all" || scope === "direct";
42-
const groupMode =
43-
scope === "all" || scope === "group-all" ? "always" : scope === "direct" ? "never" : "mentions";
4441
const isGroup = admission.conversation.kind === "group";
4542
const activation = isGroup
4643
? await resolveGroupActivationFor({
@@ -52,14 +49,16 @@ export async function resolveWhatsAppReactionEligibility(params: {
5249
})
5350
: null;
5451
if (
55-
!shouldAckReactionForWhatsApp({
56-
emoji,
52+
!emoji ||
53+
!shouldAckReaction({
54+
scope,
5755
isDirect: admission.conversation.kind === "direct",
5856
isGroup,
59-
directEnabled,
60-
groupMode,
61-
wasMentioned: (params.msg.groupMention?.wasMentioned ?? params.msg.wasMentioned) === true,
62-
groupActivated: activation === "always",
57+
isMentionableGroup: isGroup,
58+
canDetectMention: isGroup,
59+
effectiveWasMentioned:
60+
(params.msg.groupMention?.wasMentioned ?? params.msg.wasMentioned) === true,
61+
shouldBypassMention: activation === "always",
6362
})
6463
) {
6564
return DISABLED_REACTION;

‎extensions/whatsapp/src/auto-reply/monitor/reactions.test.ts‎

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import { createWhatsAppStatusReactionController } from "./status-reaction.js";
99

1010
const hoisted = vi.hoisted(() => ({
1111
sendReactionWhatsApp: vi.fn(async () => undefined),
12+
resolveGroupActivationFor: vi.fn(async (): Promise<"always" | "mention"> => "always"),
1213
}));
1314

1415
vi.mock("../../send.js", () => ({
1516
sendReactionWhatsApp: hoisted.sendReactionWhatsApp,
1617
}));
1718

1819
vi.mock("./group-activation.js", () => ({
19-
resolveGroupActivationFor: vi.fn(async () => "always"),
20+
resolveGroupActivationFor: hoisted.resolveGroupActivationFor,
2021
}));
2122

2223
type TestMsgOverrides = NonNullable<Parameters<typeof createTestWebInboundMessage>[0]>;
@@ -233,6 +234,65 @@ describe("maybeSendAckReaction", () => {
233234
expectAckReactionSent("work", cfg);
234235
});
235236

237+
it.each([
238+
{
239+
name: "acks a mentioned group message",
240+
scope: "group-mentions",
241+
activation: "mention",
242+
wasMentioned: true,
243+
expected: true,
244+
},
245+
{
246+
name: "skips an unmentioned inactive group message",
247+
scope: "group-mentions",
248+
activation: "mention",
249+
wasMentioned: false,
250+
expected: false,
251+
},
252+
{
253+
name: "acks an activated group without a literal mention",
254+
scope: "group-mentions",
255+
activation: "always",
256+
wasMentioned: false,
257+
expected: true,
258+
},
259+
{
260+
name: "acks every group message under group-all",
261+
scope: "group-all",
262+
activation: "mention",
263+
wasMentioned: false,
264+
expected: true,
265+
},
266+
{
267+
name: "keeps direct-only scope out of groups",
268+
scope: "direct",
269+
activation: "always",
270+
wasMentioned: true,
271+
expected: false,
272+
},
273+
] as const)("$name", async ({ scope, activation, wasMentioned, expected }) => {
274+
const cfg = createConfig("ack");
275+
cfg.messages!.ackReactionScope = scope;
276+
hoisted.resolveGroupActivationFor.mockResolvedValue(activation);
277+
278+
const ackReaction = await runAckReaction({
279+
cfg,
280+
msg: createMessage({
281+
platform: { chatJid: "[email protected]" },
282+
admission: {
283+
conversation: { kind: "group", id: "[email protected]" },
284+
},
285+
groupMention: { wasMentioned, requireMention: true },
286+
}),
287+
sessionKey: "whatsapp:default:[email protected]",
288+
});
289+
290+
expect(Boolean(ackReaction)).toBe(expected);
291+
if (ackReaction) {
292+
await expect(ackReaction.ackReactionPromise).resolves.toBe(true);
293+
}
294+
});
295+
236296
it("uses the canonical emoji preserved from agent identity", async () => {
237297
const cfg = {
238298
agents: {

‎scripts/plugin-sdk-surface-report.mts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
252252
// +3: session-catalog terminal-start provider request and Gateway params/result contracts.
253253
// +1: worker desktop endpoint contract for desktop-capable worker leases.
254254
// +1: native command spec merger through the native-command-registry facade.
255-
4849,
255+
// -2: remove unused WhatsApp-specific ack policy exports from channel-feedback.
256+
4847,
256257
env,
257258
),
258259
publicFunctionExports: readPluginSdkSurfaceBudgetEnv(
@@ -306,7 +307,8 @@ export function readPluginSdkSurfaceBudgets(env: NodeJS.ProcessEnv = process.env
306307
// +4: focused agent scope functions for doctor migration enumeration.
307308
// +3: channel streaming config reader functions and session-agent scope resolver.
308309
// +1: native command spec merger through the native-command-registry facade.
309-
2921,
310+
// -1: remove the unused WhatsApp-specific ack policy helper.
311+
2920,
310312
env,
311313
),
312314
publicDeprecatedExports: readPluginSdkSurfaceBudgetEnv(

‎src/channels/ack-reactions.test.ts‎

Lines changed: 3 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import {
55
removeAckReactionHandleAfterReply,
66
removeAckReactionAfterReply,
77
shouldAckReaction,
8-
shouldAckReactionForWhatsApp,
98
} from "./ack-reactions.js";
109

1110
const flushMicrotasks = async () => {
@@ -121,101 +120,16 @@ describe("shouldAckReaction", () => {
121120
shouldAckReaction({
122121
...groupMentionsScope,
123122
effectiveWasMentioned: false,
124-
shouldBypassMention: true,
125123
}),
126-
).toBe(true);
127-
});
128-
});
124+
).toBe(false);
129125

130-
describe("shouldAckReactionForWhatsApp", () => {
131-
it("acks a mention in a group that does not require mentions", () => {
132-
// Regression: the gate used to return false whenever the group did not
133-
// require mentions, so an explicitly mentioned message the agent answered
134-
// got no ack under the default scope.
135-
expect(
136-
shouldAckReaction({
137-
scope: "group-mentions",
138-
isDirect: false,
139-
isGroup: true,
140-
isMentionableGroup: true,
141-
canDetectMention: true,
142-
effectiveWasMentioned: true,
143-
}),
144-
).toBe(true);
145126
expect(
146127
shouldAckReaction({
147-
scope: "group-mentions",
148-
isDirect: false,
149-
isGroup: true,
150-
isMentionableGroup: true,
151-
canDetectMention: true,
128+
...groupMentionsScope,
152129
effectiveWasMentioned: false,
153-
}),
154-
).toBe(false);
155-
});
156-
157-
it("respects direct and group modes", () => {
158-
expect(
159-
shouldAckReactionForWhatsApp({
160-
emoji: "👀",
161-
isDirect: true,
162-
isGroup: false,
163-
directEnabled: false,
164-
groupMode: "mentions",
165-
wasMentioned: false,
166-
groupActivated: false,
167-
}),
168-
).toBe(false);
169-
170-
expect(
171-
shouldAckReactionForWhatsApp({
172-
emoji: "👀",
173-
isDirect: false,
174-
isGroup: true,
175-
directEnabled: true,
176-
groupMode: "always",
177-
wasMentioned: false,
178-
groupActivated: false,
179-
}),
180-
).toBe(true);
181-
182-
expect(
183-
shouldAckReactionForWhatsApp({
184-
emoji: "👀",
185-
isDirect: false,
186-
isGroup: true,
187-
directEnabled: true,
188-
groupMode: "never",
189-
wasMentioned: true,
190-
groupActivated: true,
191-
}),
192-
).toBe(false);
193-
});
194-
195-
it("honors mentions or activation for group-mentions", () => {
196-
expect(
197-
shouldAckReactionForWhatsApp({
198-
emoji: "👀",
199-
isDirect: false,
200-
isGroup: true,
201-
directEnabled: true,
202-
groupMode: "mentions",
203-
wasMentioned: false,
204-
groupActivated: true,
130+
shouldBypassMention: true,
205131
}),
206132
).toBe(true);
207-
208-
expect(
209-
shouldAckReactionForWhatsApp({
210-
emoji: "👀",
211-
isDirect: false,
212-
isGroup: true,
213-
directEnabled: true,
214-
groupMode: "mentions",
215-
wasMentioned: false,
216-
groupActivated: false,
217-
}),
218-
).toBe(false);
219133
});
220134
});
221135

‎src/channels/ack-reactions.ts‎

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import { toErrorObject } from "../infra/errors.js";
33

44
export type AckReactionScope = "all" | "direct" | "group-all" | "group-mentions" | "off" | "none";
55

6-
/** WhatsApp group-mode policy; direct-message ack reactions are configured separately. */
7-
export type WhatsAppAckReactionMode = "always" | "mentions" | "never";
8-
96
/** Sent ack reaction state plus the cleanup hook callers can run after reply delivery. */
107
export type AckReactionHandle = {
118
ackReactionPromise: Promise<boolean>;
@@ -67,44 +64,6 @@ export function shouldAckReaction(params: AckReactionGateParams): boolean {
6764
return false;
6865
}
6966

70-
/** Resolves WhatsApp ack policy while preserving the shared mention-only group gate. */
71-
export function shouldAckReactionForWhatsApp(params: {
72-
emoji: string;
73-
isDirect: boolean;
74-
isGroup: boolean;
75-
directEnabled: boolean;
76-
groupMode: WhatsAppAckReactionMode;
77-
wasMentioned: boolean;
78-
groupActivated: boolean;
79-
}): boolean {
80-
if (!params.emoji) {
81-
return false;
82-
}
83-
if (params.isDirect) {
84-
return params.directEnabled;
85-
}
86-
if (!params.isGroup) {
87-
return false;
88-
}
89-
if (params.groupMode === "never") {
90-
return false;
91-
}
92-
if (params.groupMode === "always") {
93-
return true;
94-
}
95-
// WhatsApp "mentions" mode shares the generic group-mentions path so activation bypass and
96-
// mention detection semantics stay aligned with other channels.
97-
return shouldAckReaction({
98-
scope: "group-mentions",
99-
isDirect: false,
100-
isGroup: true,
101-
isMentionableGroup: true,
102-
canDetectMention: true,
103-
effectiveWasMentioned: params.wasMentioned,
104-
shouldBypassMention: params.groupActivated,
105-
});
106-
}
107-
10867
/** Starts sending an ack reaction and returns the success-tracking cleanup handle. */
10968
export function createAckReactionHandle(params: {
11069
ackReactionValue: string;

‎src/channels/streaming.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export type {
4444
StreamingMode,
4545
TextChunkMode,
4646
} from "../config/types.base.js";
47-
export type { SlackChannelStreamingConfig } from "../config/types.slack.js";
4847

4948
// Runtime reads are nested-only; doctor migrates legacy streaming spellings.
5049

‎src/config/types.base.ts‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ export type ChannelStreamingBlockConfig = {
9898
coalesce?: BlockStreamingCoalesceConfig;
9999
};
100100

101-
export type ChannelStreamingConfig = {
101+
export type ChannelStreamingConfig<
102+
TProgress extends ChannelStreamingProgressConfig = ChannelStreamingProgressConfig,
103+
> = {
102104
/**
103105
* Preview streaming mode:
104106
* - "off": disable preview updates
@@ -109,13 +111,10 @@ export type ChannelStreamingConfig = {
109111
mode?: StreamingMode;
110112
/** Chunking mode for outbound text delivery. */
111113
chunkMode?: TextChunkMode;
112-
/**
113-
* Channel-specific native transport streaming toggle.
114-
* Used today by Slack's native stream API.
115-
*/
114+
/** Prefer a channel's native streaming transport over its portable draft path. */
116115
nativeTransport?: boolean;
117116
preview?: ChannelStreamingPreviewConfig;
118-
progress?: ChannelStreamingProgressConfig;
117+
progress?: TProgress;
119118
block?: ChannelStreamingBlockConfig;
120119
};
121120

‎src/config/types.slack.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,26 @@ const slackSecretRefConfig = {
3030
},
3131
} satisfies OpenClawConfig;
3232

33+
const slackStreamingConfig = {
34+
channels: {
35+
slack: {
36+
streaming: {
37+
mode: "progress",
38+
nativeTransport: true,
39+
progress: { nativeTaskCards: true },
40+
},
41+
},
42+
},
43+
} satisfies OpenClawConfig;
44+
3345
describe("Slack config types", () => {
3446
it("accepts SecretRef-backed token fields", () => {
3547
expect(slackSecretRefConfig.channels.slack.relay.authToken).toMatchObject({
3648
id: "SLACK_RELAY_AUTH_TOKEN",
3749
});
3850
});
51+
52+
it("extends generic streaming config with native task cards", () => {
53+
expect(slackStreamingConfig.channels.slack.streaming.progress.nativeTaskCards).toBe(true);
54+
});
3955
});

0 commit comments

Comments
 (0)