fix: honor googlechat action discovery account config

This commit is contained in:
Tak Hoffman 2026-04-03 11:13:23 -05:00
parent a2836e6db6
commit 632a10cddc
No known key found for this signature in database
2 changed files with 30 additions and 11 deletions

View File

@ -69,6 +69,27 @@ describe("googlechat message actions", () => {
});
});
it("honors account-scoped reaction gates during discovery", () => {
resolveGoogleChatAccount.mockImplementation(({ accountId }: { accountId?: string | null }) => ({
enabled: true,
credentialSource: "service-account",
config: {
actions: { reactions: accountId === "work" },
},
}));
expect(
googlechatMessageActions.describeMessageTool?.({ cfg: {} as never, accountId: "default" }),
).toEqual({
actions: ["send", "upload-file"],
});
expect(
googlechatMessageActions.describeMessageTool?.({ cfg: {} as never, accountId: "work" }),
).toEqual({
actions: ["send", "upload-file", "react", "reactions"],
});
});
it("sends messages with uploaded media through the resolved space", async () => {
resolveGoogleChatAccount.mockReturnValue({
credentialSource: "service-account",

View File

@ -31,15 +31,9 @@ function listEnabledAccounts(cfg: OpenClawConfig) {
);
}
function isReactionsEnabled(accounts: ReturnType<typeof listEnabledAccounts>, cfg: OpenClawConfig) {
function isReactionsEnabled(accounts: Array<{ config: { actions?: unknown } }>) {
for (const account of accounts) {
const gate = createActionGate(
(account.config.actions ??
(cfg.channels?.["googlechat"] as { actions?: unknown })?.actions) as Record<
string,
boolean | undefined
>,
);
const gate = createActionGate(account.config.actions as Record<string, boolean | undefined>);
if (gate("reactions")) {
return true;
}
@ -76,15 +70,19 @@ async function loadGoogleChatActionMedia(params: {
}
export const googlechatMessageActions: ChannelMessageActionAdapter = {
describeMessageTool: ({ cfg }) => {
const accounts = listEnabledAccounts(cfg);
describeMessageTool: ({ cfg, accountId }) => {
const accounts = accountId
? [resolveGoogleChatAccount({ cfg, accountId })].filter(
(account) => account.enabled && account.credentialSource !== "none",
)
: listEnabledAccounts(cfg);
if (accounts.length === 0) {
return null;
}
const actions = new Set<ChannelMessageActionName>([]);
actions.add("send");
actions.add("upload-file");
if (isReactionsEnabled(accounts, cfg)) {
if (isReactionsEnabled(accounts)) {
actions.add("react");
actions.add("reactions");
}