import 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 { runDriveAction } from "./actions.js"; import { errorResult, json, type DriveClient } from "./common.js"; import { FeishuDriveSchema, type FeishuDriveParams } from "./schemas.js"; type DriveToolSpec
= {
name: string;
label: string;
description: string;
parameters: TSchema;
run: (args: { client: DriveClient; account: ResolvedFeishuAccount }, params: P) => Promise (api: OpenClawPluginApi, spec: DriveToolSpec ) {
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: "drive",
run: async ({ client, account }) =>
json(await spec.run({ client: client as DriveClient, account }, params as P)),
});
} catch (err) {
return errorResult(err);
}
},
},
{ name: spec.name },
);
}
export function registerFeishuDriveTools(api: OpenClawPluginApi) {
if (!api.config) {
api.logger.debug?.("feishu_drive: No config available, skipping drive tools");
return;
}
if (!hasFeishuToolEnabledForAnyAccount(api.config)) {
api.logger.debug?.("feishu_drive: No Feishu accounts configured, skipping drive tools");
return;
}
if (!hasFeishuToolEnabledForAnyAccount(api.config, "drive")) {
api.logger.debug?.("feishu_drive: drive tool disabled in config");
return;
}
registerDriveTool