import { Type, type TSchema } from "@sinclair/typebox"; import type { OpenClawPluginApi } from "openclaw/plugin-sdk"; import type { ResolvedFeishuAccount } from "../types.js"; import { hasFeishuToolEnabledForAnyAccount, withFeishuToolClient } from "../tools-common/tool-exec.js"; import { listAppScopes, runDocAction } from "./actions.js"; import { errorResult, json, type DocClient } from "./common.js"; import { FeishuDocSchema, type FeishuDocParams } from "./schemas.js"; type DocToolSpec
= {
name: string;
label: string;
description: string;
parameters: TSchema;
requiredTool?: "doc" | "scopes";
run: (args: { client: DocClient; account: ResolvedFeishuAccount }, params: P) => Promise (api: OpenClawPluginApi, spec: DocToolSpec ) {
api.registerTool(
{
name: spec.name,
label: spec.label,
description: spec.description,
parameters: spec.parameters,
async execute(_toolCallId, params) {
try {
return await withFeishuToolClient({
api,
toolName: spec.name,
requiredTool: spec.requiredTool,
run: async ({ client, account }) =>
json(await spec.run({ client: client as DocClient, account }, params as P)),
});
} catch (err) {
return errorResult(err);
}
},
},
{ name: spec.name },
);
}
export function registerFeishuDocTools(api: OpenClawPluginApi) {
if (!api.config) {
api.logger.debug?.("feishu_doc: No config available, skipping doc tools");
return;
}
if (!hasFeishuToolEnabledForAnyAccount(api.config)) {
api.logger.debug?.("feishu_doc: No Feishu accounts configured, skipping doc tools");
return;
}
const docEnabled = hasFeishuToolEnabledForAnyAccount(api.config, "doc");
const scopesEnabled = hasFeishuToolEnabledForAnyAccount(api.config, "scopes");
const registered: string[] = [];
if (docEnabled) {
registerDocTool