@openclaw/feishu 2026.2.2 → 2026.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +49 -1
- package/openclaw.plugin.json +1 -0
- package/package.json +9 -5
- package/skills/feishu-doc/SKILL.md +105 -0
- package/skills/feishu-doc/references/block-types.md +103 -0
- package/skills/feishu-drive/SKILL.md +97 -0
- package/skills/feishu-perm/SKILL.md +119 -0
- package/skills/feishu-wiki/SKILL.md +111 -0
- package/src/accounts.ts +144 -0
- package/src/bitable.ts +459 -0
- package/src/bot.ts +871 -0
- package/src/channel.ts +267 -202
- package/src/client.ts +118 -0
- package/src/config-schema.ts +152 -26
- package/src/directory.ts +177 -0
- package/src/doc-schema.ts +47 -0
- package/src/docx.ts +521 -0
- package/src/drive-schema.ts +46 -0
- package/src/drive.ts +227 -0
- package/src/media.ts +527 -0
- package/src/mention.ts +126 -0
- package/src/monitor.ts +190 -0
- package/src/onboarding.ts +278 -200
- package/src/outbound.ts +40 -0
- package/src/perm-schema.ts +52 -0
- package/src/perm.ts +173 -0
- package/src/policy.ts +104 -0
- package/src/probe.ts +44 -0
- package/src/reactions.ts +160 -0
- package/src/reply-dispatcher.ts +184 -0
- package/src/runtime.ts +14 -0
- package/src/send.ts +358 -0
- package/src/targets.ts +78 -0
- package/src/tools-config.ts +21 -0
- package/src/types.ts +75 -0
- package/src/typing.ts +80 -0
- package/src/wiki-schema.ts +55 -0
- package/src/wiki.ts +232 -0
package/src/drive.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type * as Lark from "@larksuiteoapi/node-sdk";
|
|
2
|
+
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
3
|
+
import { listEnabledFeishuAccounts } from "./accounts.js";
|
|
4
|
+
import { createFeishuClient } from "./client.js";
|
|
5
|
+
import { FeishuDriveSchema, type FeishuDriveParams } from "./drive-schema.js";
|
|
6
|
+
import { resolveToolsConfig } from "./tools-config.js";
|
|
7
|
+
|
|
8
|
+
// ============ Helpers ============
|
|
9
|
+
|
|
10
|
+
function json(data: unknown) {
|
|
11
|
+
return {
|
|
12
|
+
content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
|
|
13
|
+
details: data,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// ============ Actions ============
|
|
18
|
+
|
|
19
|
+
async function getRootFolderToken(client: Lark.Client): Promise<string> {
|
|
20
|
+
// Use generic HTTP client to call the root folder meta API
|
|
21
|
+
// as it's not directly exposed in the SDK
|
|
22
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- accessing internal SDK property
|
|
23
|
+
const domain = (client as any).domain ?? "https://open.feishu.cn";
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- accessing internal SDK property
|
|
25
|
+
const res = (await (client as any).httpInstance.get(
|
|
26
|
+
`${domain}/open-apis/drive/explorer/v2/root_folder/meta`,
|
|
27
|
+
)) as { code: number; msg?: string; data?: { token?: string } };
|
|
28
|
+
if (res.code !== 0) {
|
|
29
|
+
throw new Error(res.msg ?? "Failed to get root folder");
|
|
30
|
+
}
|
|
31
|
+
const token = res.data?.token;
|
|
32
|
+
if (!token) {
|
|
33
|
+
throw new Error("Root folder token not found");
|
|
34
|
+
}
|
|
35
|
+
return token;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function listFolder(client: Lark.Client, folderToken?: string) {
|
|
39
|
+
// Filter out invalid folder_token values (empty, "0", etc.)
|
|
40
|
+
const validFolderToken = folderToken && folderToken !== "0" ? folderToken : undefined;
|
|
41
|
+
const res = await client.drive.file.list({
|
|
42
|
+
params: validFolderToken ? { folder_token: validFolderToken } : {},
|
|
43
|
+
});
|
|
44
|
+
if (res.code !== 0) {
|
|
45
|
+
throw new Error(res.msg);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
files:
|
|
50
|
+
res.data?.files?.map((f) => ({
|
|
51
|
+
token: f.token,
|
|
52
|
+
name: f.name,
|
|
53
|
+
type: f.type,
|
|
54
|
+
url: f.url,
|
|
55
|
+
created_time: f.created_time,
|
|
56
|
+
modified_time: f.modified_time,
|
|
57
|
+
owner_id: f.owner_id,
|
|
58
|
+
})) ?? [],
|
|
59
|
+
next_page_token: res.data?.next_page_token,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async function getFileInfo(client: Lark.Client, fileToken: string, folderToken?: string) {
|
|
64
|
+
// Use list with folder_token to find file info
|
|
65
|
+
const res = await client.drive.file.list({
|
|
66
|
+
params: folderToken ? { folder_token: folderToken } : {},
|
|
67
|
+
});
|
|
68
|
+
if (res.code !== 0) {
|
|
69
|
+
throw new Error(res.msg);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const file = res.data?.files?.find((f) => f.token === fileToken);
|
|
73
|
+
if (!file) {
|
|
74
|
+
throw new Error(`File not found: ${fileToken}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
token: file.token,
|
|
79
|
+
name: file.name,
|
|
80
|
+
type: file.type,
|
|
81
|
+
url: file.url,
|
|
82
|
+
created_time: file.created_time,
|
|
83
|
+
modified_time: file.modified_time,
|
|
84
|
+
owner_id: file.owner_id,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function createFolder(client: Lark.Client, name: string, folderToken?: string) {
|
|
89
|
+
// Feishu supports using folder_token="0" as the root folder.
|
|
90
|
+
// We *try* to resolve the real root token (explorer API), but fall back to "0"
|
|
91
|
+
// because some tenants/apps return 400 for that explorer endpoint.
|
|
92
|
+
let effectiveToken = folderToken && folderToken !== "0" ? folderToken : "0";
|
|
93
|
+
if (effectiveToken === "0") {
|
|
94
|
+
try {
|
|
95
|
+
effectiveToken = await getRootFolderToken(client);
|
|
96
|
+
} catch {
|
|
97
|
+
// ignore and keep "0"
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const res = await client.drive.file.createFolder({
|
|
102
|
+
data: {
|
|
103
|
+
name,
|
|
104
|
+
folder_token: effectiveToken,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
if (res.code !== 0) {
|
|
108
|
+
throw new Error(res.msg);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
token: res.data?.token,
|
|
113
|
+
url: res.data?.url,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function moveFile(client: Lark.Client, fileToken: string, type: string, folderToken: string) {
|
|
118
|
+
const res = await client.drive.file.move({
|
|
119
|
+
path: { file_token: fileToken },
|
|
120
|
+
data: {
|
|
121
|
+
type: type as
|
|
122
|
+
| "doc"
|
|
123
|
+
| "docx"
|
|
124
|
+
| "sheet"
|
|
125
|
+
| "bitable"
|
|
126
|
+
| "folder"
|
|
127
|
+
| "file"
|
|
128
|
+
| "mindnote"
|
|
129
|
+
| "slides",
|
|
130
|
+
folder_token: folderToken,
|
|
131
|
+
},
|
|
132
|
+
});
|
|
133
|
+
if (res.code !== 0) {
|
|
134
|
+
throw new Error(res.msg);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
success: true,
|
|
139
|
+
task_id: res.data?.task_id,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function deleteFile(client: Lark.Client, fileToken: string, type: string) {
|
|
144
|
+
const res = await client.drive.file.delete({
|
|
145
|
+
path: { file_token: fileToken },
|
|
146
|
+
params: {
|
|
147
|
+
type: type as
|
|
148
|
+
| "doc"
|
|
149
|
+
| "docx"
|
|
150
|
+
| "sheet"
|
|
151
|
+
| "bitable"
|
|
152
|
+
| "folder"
|
|
153
|
+
| "file"
|
|
154
|
+
| "mindnote"
|
|
155
|
+
| "slides"
|
|
156
|
+
| "shortcut",
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
if (res.code !== 0) {
|
|
160
|
+
throw new Error(res.msg);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
success: true,
|
|
165
|
+
task_id: res.data?.task_id,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ============ Tool Registration ============
|
|
170
|
+
|
|
171
|
+
export function registerFeishuDriveTools(api: OpenClawPluginApi) {
|
|
172
|
+
if (!api.config) {
|
|
173
|
+
api.logger.debug?.("feishu_drive: No config available, skipping drive tools");
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const accounts = listEnabledFeishuAccounts(api.config);
|
|
178
|
+
if (accounts.length === 0) {
|
|
179
|
+
api.logger.debug?.("feishu_drive: No Feishu accounts configured, skipping drive tools");
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const firstAccount = accounts[0];
|
|
184
|
+
const toolsCfg = resolveToolsConfig(firstAccount.config.tools);
|
|
185
|
+
if (!toolsCfg.drive) {
|
|
186
|
+
api.logger.debug?.("feishu_drive: drive tool disabled in config");
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const getClient = () => createFeishuClient(firstAccount);
|
|
191
|
+
|
|
192
|
+
api.registerTool(
|
|
193
|
+
{
|
|
194
|
+
name: "feishu_drive",
|
|
195
|
+
label: "Feishu Drive",
|
|
196
|
+
description:
|
|
197
|
+
"Feishu cloud storage operations. Actions: list, info, create_folder, move, delete",
|
|
198
|
+
parameters: FeishuDriveSchema,
|
|
199
|
+
async execute(_toolCallId, params) {
|
|
200
|
+
const p = params as FeishuDriveParams;
|
|
201
|
+
try {
|
|
202
|
+
const client = getClient();
|
|
203
|
+
switch (p.action) {
|
|
204
|
+
case "list":
|
|
205
|
+
return json(await listFolder(client, p.folder_token));
|
|
206
|
+
case "info":
|
|
207
|
+
return json(await getFileInfo(client, p.file_token));
|
|
208
|
+
case "create_folder":
|
|
209
|
+
return json(await createFolder(client, p.name, p.folder_token));
|
|
210
|
+
case "move":
|
|
211
|
+
return json(await moveFile(client, p.file_token, p.type, p.folder_token));
|
|
212
|
+
case "delete":
|
|
213
|
+
return json(await deleteFile(client, p.file_token, p.type));
|
|
214
|
+
default:
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- exhaustive check fallback
|
|
216
|
+
return json({ error: `Unknown action: ${(p as any).action}` });
|
|
217
|
+
}
|
|
218
|
+
} catch (err) {
|
|
219
|
+
return json({ error: err instanceof Error ? err.message : String(err) });
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
{ name: "feishu_drive" },
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
api.logger.info?.(`feishu_drive: Registered feishu_drive tool`);
|
|
227
|
+
}
|