Skip to content

Commit 0ee5f47

Browse files
committed
fix(feishu): enforce bitable account gates
1 parent 73bb84e commit 0ee5f47

4 files changed

Lines changed: 88 additions & 5 deletions

File tree

‎extensions/feishu/src/accounts.ts‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,32 @@ export function resolveDefaultFeishuAccountId(cfg: ClawdbotConfig): string {
181181
return resolveDefaultAccountId(cfg);
182182
}
183183

184+
function resolveRawFeishuAccountConfig(
185+
accounts: Record<string, Partial<FeishuConfig>> | undefined,
186+
accountId: string,
187+
): Partial<FeishuConfig> | undefined {
188+
if (!accounts || typeof accounts !== "object") {
189+
return undefined;
190+
}
191+
if (Object.hasOwn(accounts, accountId)) {
192+
return accounts[accountId];
193+
}
194+
const normalized = accountId.toLowerCase();
195+
const matchKey = Object.keys(accounts).find((key) => key.toLowerCase() === normalized);
196+
return matchKey ? accounts[matchKey] : undefined;
197+
}
198+
184199
/**
185200
* Merge top-level config with account-specific config.
186201
* Account-specific fields override top-level fields.
187202
*/
188203
function mergeFeishuAccountConfig(cfg: ClawdbotConfig, accountId: string): FeishuConfig {
189204
const feishuCfg = cfg.channels?.feishu as FeishuConfig | undefined;
205+
const accounts = feishuCfg?.accounts as Record<string, Partial<FeishuConfig>> | undefined;
206+
const accountTools = resolveRawFeishuAccountConfig(accounts, accountId)?.tools;
190207
const merged = resolveMergedAccountConfig<FeishuConfig>({
191208
channelConfig: feishuCfg,
192-
accounts: feishuCfg?.accounts as Record<string, Partial<FeishuConfig>> | undefined,
209+
accounts,
193210
accountId,
194211
omitKeys: ["defaultAccount"],
195212
nestedObjectKeys: ["tools"],
@@ -211,6 +228,16 @@ function mergeFeishuAccountConfig(cfg: ClawdbotConfig, accountId: string): Feish
211228
},
212229
};
213230
}
231+
if (accountTools?.bitable === undefined && accountTools?.base !== undefined) {
232+
return {
233+
...merged,
234+
tools: {
235+
...merged.tools,
236+
bitable: accountTools.base,
237+
base: accountTools.base,
238+
},
239+
};
240+
}
214241
return merged;
215242
}
216243

‎extensions/feishu/src/bitable.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
55
import { Type, type TSchema } from "typebox";
66
import type { OpenClawPluginApi } from "../runtime-api.js";
77
import { listEnabledFeishuAccounts } from "./accounts.js";
8-
import { createFeishuToolClient, resolveAnyEnabledFeishuToolsConfig } from "./tool-account.js";
8+
import { createFeishuClient } from "./client.js";
9+
import { resolveAnyEnabledFeishuToolsConfig, resolveFeishuToolAccount } from "./tool-account.js";
10+
import { resolveToolsConfig } from "./tools-config.js";
911

1012
// ============ Helpers ============
1113

@@ -593,8 +595,13 @@ export function registerFeishuBitableTools(api: OpenClawPluginApi) {
593595

594596
type AccountAwareParams = { accountId?: string };
595597

596-
const getClient = (params: AccountAwareParams | undefined, defaultAccountId?: string) =>
597-
createFeishuToolClient({ api, executeParams: params, defaultAccountId });
598+
const getClient = (params: AccountAwareParams | undefined, defaultAccountId?: string) => {
599+
const account = resolveFeishuToolAccount({ api, executeParams: params, defaultAccountId });
600+
if (!resolveToolsConfig(account.config.tools).bitable) {
601+
throw new Error(`Feishu Bitable tools are disabled for account "${account.accountId}"`);
602+
}
603+
return createFeishuClient(account);
604+
};
598605

599606
const registerBitableTool = <
600607
// oxlint-disable-next-line typescript/no-unnecessary-type-parameters -- Tool params bind each schema-specific executor to its registered tool.

‎extensions/feishu/src/tool-account-routing.test.ts‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,38 @@ describe("feishu tool account routing", () => {
217217
expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-b");
218218
});
219219

220+
test("bitable tool rejects a disabled contextual account when another account enables it", async () => {
221+
const { api, resolveTool } = createToolFactoryHarness(
222+
createConfig({
223+
toolsA: { bitable: false },
224+
toolsB: { bitable: true },
225+
}),
226+
);
227+
registerFeishuBitableTools(api);
228+
229+
const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "a" });
230+
const result = await tool.execute("call", { url: "invalid-url" });
231+
232+
expect(createFeishuClientMock).not.toHaveBeenCalled();
233+
expect(result.details.error).toBe('Feishu Bitable tools are disabled for account "a"');
234+
});
235+
236+
test("bitable tool rejects an explicit disabled account override", async () => {
237+
const { api, resolveTool } = createToolFactoryHarness(
238+
createConfig({
239+
toolsA: { bitable: false },
240+
toolsB: { bitable: true },
241+
}),
242+
);
243+
registerFeishuBitableTools(api);
244+
245+
const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "b" });
246+
const result = await tool.execute("call", { url: "invalid-url", accountId: "a" });
247+
248+
expect(createFeishuClientMock).not.toHaveBeenCalled();
249+
expect(result.details.error).toBe('Feishu Bitable tools are disabled for account "a"');
250+
});
251+
220252
test("bitable tool routes to agentAccountId and allows explicit accountId override", async () => {
221253
const { api, resolveTool } = createToolFactoryHarness(createConfig({}));
222254
registerFeishuBitableTools(api);
@@ -289,6 +321,23 @@ describe("feishu tool account routing", () => {
289321
expect(createFeishuClientMock.mock.calls.at(-1)?.[0]?.appId).toBe("app-a");
290322
});
291323

324+
test("account base alias disable wins over inherited top-level bitable enable", async () => {
325+
const { api, resolveTool } = createToolFactoryHarness(
326+
createConfig({
327+
topTools: { bitable: true },
328+
toolsA: { base: false },
329+
toolsB: { bitable: true },
330+
}),
331+
);
332+
registerFeishuBitableTools(api);
333+
334+
const tool = resolveTool("feishu_bitable_get_meta", { agentAccountId: "a" });
335+
const result = await tool.execute("call", { url: "invalid-url" });
336+
337+
expect(createFeishuClientMock).not.toHaveBeenCalled();
338+
expect(result.details.error).toBe('Feishu Bitable tools are disabled for account "a"');
339+
});
340+
292341
test("bitable tools are not registered when account bitable configs disable them", async () => {
293342
const { api, registered, resolveTool } = createToolFactoryHarness(
294343
createConfig({

‎extensions/feishu/src/types.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export type FeishuToolsConfig = {
9898
scopes?: boolean;
9999
/** Bitable/Base operations (default: true). */
100100
bitable?: boolean;
101-
/** Backward-compatible alias for bitable tools. */
101+
/** @deprecated Use bitable. */
102102
base?: boolean;
103103
};
104104

0 commit comments

Comments
 (0)