@m1heng-clawd/feishu 0.1.11 → 0.1.13
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/README.md +183 -14
- package/index.ts +6 -6
- package/package.json +13 -3
- package/skills/feishu-doc/SKILL.md +40 -2
- package/skills/feishu-task/SKILL.md +210 -0
- package/src/bitable-tools/index.ts +1 -0
- package/src/bot.ts +181 -70
- package/src/channel.ts +4 -0
- package/src/config-schema.ts +6 -0
- package/src/doc-tools/actions.ts +341 -0
- package/src/doc-tools/common.ts +33 -0
- package/src/doc-tools/index.ts +2 -0
- package/src/doc-tools/register.ts +90 -0
- package/src/{doc-schema.ts → doc-tools/schemas.ts} +31 -1
- package/src/drive-tools/actions.ts +182 -0
- package/src/drive-tools/common.ts +18 -0
- package/src/drive-tools/index.ts +2 -0
- package/src/drive-tools/register.ts +71 -0
- package/src/{drive-schema.ts → drive-tools/schemas.ts} +2 -1
- package/src/media.ts +29 -7
- package/src/perm-tools/actions.ts +111 -0
- package/src/perm-tools/common.ts +18 -0
- package/src/perm-tools/index.ts +2 -0
- package/src/perm-tools/register.ts +65 -0
- package/src/policy.ts +13 -0
- package/src/reply-dispatcher.ts +7 -5
- package/src/send.ts +33 -2
- package/src/streaming-card.ts +11 -8
- package/src/task-tools/actions.ts +468 -13
- package/src/task-tools/constants.ts +13 -0
- package/src/task-tools/index.ts +1 -0
- package/src/task-tools/register.ts +175 -13
- package/src/task-tools/schemas.ts +422 -4
- package/src/text/markdown-links.ts +104 -0
- package/src/types.ts +1 -0
- package/src/wiki-tools/actions.ts +166 -0
- package/src/wiki-tools/common.ts +18 -0
- package/src/wiki-tools/index.ts +2 -0
- package/src/wiki-tools/register.ts +66 -0
- package/src/bitable.ts +0 -1
- package/src/docx.ts +0 -276
- package/src/drive.ts +0 -237
- package/src/perm.ts +0 -165
- package/src/task.ts +0 -1
- package/src/wiki.ts +0 -223
- /package/src/{perm-schema.ts → perm-tools/schemas.ts} +0 -0
- /package/src/{wiki-schema.ts → wiki-tools/schemas.ts} +0 -0
package/src/drive.ts
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
2
|
-
import type * as Lark from "@larksuiteoapi/node-sdk";
|
|
3
|
-
import { FeishuDriveSchema, type FeishuDriveParams } from "./drive-schema.js";
|
|
4
|
-
import { hasFeishuToolEnabledForAnyAccount, withFeishuToolClient } from "./tools-common/tool-exec.js";
|
|
5
|
-
import { createAndWriteDoc } from "./doc-write-service.js";
|
|
6
|
-
|
|
7
|
-
// ============ Helpers ============
|
|
8
|
-
|
|
9
|
-
function json(data: unknown) {
|
|
10
|
-
return {
|
|
11
|
-
content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
|
|
12
|
-
details: data,
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// ============ Actions ============
|
|
17
|
-
|
|
18
|
-
async function getRootFolderToken(client: Lark.Client): Promise<string> {
|
|
19
|
-
// Use generic HTTP client to call the root folder meta API
|
|
20
|
-
// as it's not directly exposed in the SDK
|
|
21
|
-
const domain = (client as any).domain ?? "https://open.feishu.cn";
|
|
22
|
-
const res = (await (client as any).httpInstance.get(
|
|
23
|
-
`${domain}/open-apis/drive/explorer/v2/root_folder/meta`,
|
|
24
|
-
)) as { code: number; msg?: string; data?: { token?: string } };
|
|
25
|
-
if (res.code !== 0) throw new Error(res.msg ?? "Failed to get root folder");
|
|
26
|
-
const token = res.data?.token;
|
|
27
|
-
if (!token) throw new Error("Root folder token not found");
|
|
28
|
-
return token;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
async function listFolder(client: Lark.Client, folderToken?: string) {
|
|
32
|
-
// Filter out invalid folder_token values (empty, "0", etc.)
|
|
33
|
-
const validFolderToken = folderToken && folderToken !== "0" ? folderToken : undefined;
|
|
34
|
-
const res = await client.drive.file.list({
|
|
35
|
-
params: validFolderToken ? { folder_token: validFolderToken } : {},
|
|
36
|
-
});
|
|
37
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
38
|
-
|
|
39
|
-
return {
|
|
40
|
-
files:
|
|
41
|
-
res.data?.files?.map((f) => ({
|
|
42
|
-
token: f.token,
|
|
43
|
-
name: f.name,
|
|
44
|
-
type: f.type,
|
|
45
|
-
url: f.url,
|
|
46
|
-
created_time: f.created_time,
|
|
47
|
-
modified_time: f.modified_time,
|
|
48
|
-
owner_id: f.owner_id,
|
|
49
|
-
})) ?? [],
|
|
50
|
-
next_page_token: res.data?.next_page_token,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
async function getFileInfo(client: Lark.Client, fileToken: string, folderToken?: string) {
|
|
55
|
-
// Use list with folder_token to find file info
|
|
56
|
-
const res = await client.drive.file.list({
|
|
57
|
-
params: folderToken ? { folder_token: folderToken } : {},
|
|
58
|
-
});
|
|
59
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
60
|
-
|
|
61
|
-
const file = res.data?.files?.find((f) => f.token === fileToken);
|
|
62
|
-
if (!file) {
|
|
63
|
-
throw new Error(`File not found: ${fileToken}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
token: file.token,
|
|
68
|
-
name: file.name,
|
|
69
|
-
type: file.type,
|
|
70
|
-
url: file.url,
|
|
71
|
-
created_time: file.created_time,
|
|
72
|
-
modified_time: file.modified_time,
|
|
73
|
-
owner_id: file.owner_id,
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async function createFolder(client: Lark.Client, name: string, folderToken?: string) {
|
|
78
|
-
// Feishu supports using folder_token="0" as the root folder.
|
|
79
|
-
// We *try* to resolve the real root token (explorer API), but fall back to "0"
|
|
80
|
-
// because some tenants/apps return 400 for that explorer endpoint.
|
|
81
|
-
let effectiveToken = folderToken && folderToken !== "0" ? folderToken : "0";
|
|
82
|
-
if (effectiveToken === "0") {
|
|
83
|
-
try {
|
|
84
|
-
effectiveToken = await getRootFolderToken(client);
|
|
85
|
-
} catch {
|
|
86
|
-
// ignore and keep "0"
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const res = await client.drive.file.createFolder({
|
|
91
|
-
data: {
|
|
92
|
-
name,
|
|
93
|
-
folder_token: effectiveToken,
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
token: res.data?.token,
|
|
100
|
-
url: res.data?.url,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
async function moveFile(
|
|
105
|
-
client: Lark.Client,
|
|
106
|
-
fileToken: string,
|
|
107
|
-
type: string,
|
|
108
|
-
folderToken: string,
|
|
109
|
-
) {
|
|
110
|
-
const res = await client.drive.file.move({
|
|
111
|
-
path: { file_token: fileToken },
|
|
112
|
-
data: {
|
|
113
|
-
type: type as "doc" | "docx" | "sheet" | "bitable" | "folder" | "file" | "mindnote" | "slides",
|
|
114
|
-
folder_token: folderToken,
|
|
115
|
-
},
|
|
116
|
-
});
|
|
117
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
success: true,
|
|
121
|
-
task_id: res.data?.task_id,
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
async function deleteFile(client: Lark.Client, fileToken: string, type: string) {
|
|
126
|
-
const res = await client.drive.file.delete({
|
|
127
|
-
path: { file_token: fileToken },
|
|
128
|
-
params: {
|
|
129
|
-
type: type as
|
|
130
|
-
| "doc"
|
|
131
|
-
| "docx"
|
|
132
|
-
| "sheet"
|
|
133
|
-
| "bitable"
|
|
134
|
-
| "folder"
|
|
135
|
-
| "file"
|
|
136
|
-
| "mindnote"
|
|
137
|
-
| "slides"
|
|
138
|
-
| "shortcut",
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
success: true,
|
|
145
|
-
task_id: res.data?.task_id,
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
// ============ Import Document Functions ============
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Import markdown content as a new Feishu document
|
|
153
|
-
* Uses create + write approach for reliable content import.
|
|
154
|
-
* Note: docType parameter is accepted for API compatibility but docx is always used.
|
|
155
|
-
*/
|
|
156
|
-
async function importDocument(
|
|
157
|
-
client: Lark.Client,
|
|
158
|
-
title: string,
|
|
159
|
-
content: string,
|
|
160
|
-
mediaMaxBytes: number,
|
|
161
|
-
folderToken?: string,
|
|
162
|
-
_docType?: "docx" | "doc",
|
|
163
|
-
) {
|
|
164
|
-
return createAndWriteDoc(client, title, content, mediaMaxBytes, folderToken);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// ============ Tool Registration ============
|
|
168
|
-
|
|
169
|
-
export function registerFeishuDriveTools(api: OpenClawPluginApi) {
|
|
170
|
-
if (!api.config) {
|
|
171
|
-
api.logger.debug?.("feishu_drive: No config available, skipping drive tools");
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (!hasFeishuToolEnabledForAnyAccount(api.config)) {
|
|
176
|
-
api.logger.debug?.("feishu_drive: No Feishu accounts configured, skipping drive tools");
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
if (!hasFeishuToolEnabledForAnyAccount(api.config, "drive")) {
|
|
181
|
-
api.logger.debug?.("feishu_drive: drive tool disabled in config");
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
api.registerTool(
|
|
186
|
-
{
|
|
187
|
-
name: "feishu_drive",
|
|
188
|
-
label: "Feishu Drive",
|
|
189
|
-
description:
|
|
190
|
-
"Feishu cloud storage operations. Actions: list, info, create_folder, move, delete, import_document. Use 'import_document' to create documents from Markdown with better structure preservation than block-by-block writing.",
|
|
191
|
-
parameters: FeishuDriveSchema,
|
|
192
|
-
async execute(_toolCallId, params) {
|
|
193
|
-
const p = params as FeishuDriveParams;
|
|
194
|
-
try {
|
|
195
|
-
return await withFeishuToolClient({
|
|
196
|
-
api,
|
|
197
|
-
toolName: "feishu_drive",
|
|
198
|
-
requiredTool: "drive",
|
|
199
|
-
run: async ({ client, account }) => {
|
|
200
|
-
const mediaMaxBytes = (account.config?.mediaMaxMb ?? 30) * 1024 * 1024;
|
|
201
|
-
switch (p.action) {
|
|
202
|
-
case "list":
|
|
203
|
-
return json(await listFolder(client, p.folder_token));
|
|
204
|
-
case "info":
|
|
205
|
-
return json(await getFileInfo(client, p.file_token));
|
|
206
|
-
case "create_folder":
|
|
207
|
-
return json(await createFolder(client, p.name, p.folder_token));
|
|
208
|
-
case "move":
|
|
209
|
-
return json(await moveFile(client, p.file_token, p.type, p.folder_token));
|
|
210
|
-
case "delete":
|
|
211
|
-
return json(await deleteFile(client, p.file_token, p.type));
|
|
212
|
-
case "import_document":
|
|
213
|
-
return json(
|
|
214
|
-
await importDocument(
|
|
215
|
-
client,
|
|
216
|
-
p.title,
|
|
217
|
-
p.content,
|
|
218
|
-
mediaMaxBytes,
|
|
219
|
-
p.folder_token,
|
|
220
|
-
(p as any).doc_type || "docx",
|
|
221
|
-
),
|
|
222
|
-
);
|
|
223
|
-
default:
|
|
224
|
-
return json({ error: `Unknown action: ${(p as any).action}` });
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
} catch (err) {
|
|
229
|
-
return json({ error: err instanceof Error ? err.message : String(err) });
|
|
230
|
-
}
|
|
231
|
-
},
|
|
232
|
-
},
|
|
233
|
-
{ name: "feishu_drive" },
|
|
234
|
-
);
|
|
235
|
-
|
|
236
|
-
api.logger.debug?.("feishu_drive: Registered feishu_drive tool");
|
|
237
|
-
}
|
package/src/perm.ts
DELETED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
2
|
-
import type * as Lark from "@larksuiteoapi/node-sdk";
|
|
3
|
-
import { FeishuPermSchema, type FeishuPermParams } from "./perm-schema.js";
|
|
4
|
-
import { hasFeishuToolEnabledForAnyAccount, withFeishuToolClient } from "./tools-common/tool-exec.js";
|
|
5
|
-
|
|
6
|
-
// ============ Helpers ============
|
|
7
|
-
|
|
8
|
-
function json(data: unknown) {
|
|
9
|
-
return {
|
|
10
|
-
content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
|
|
11
|
-
details: data,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type ListTokenType =
|
|
16
|
-
| "doc"
|
|
17
|
-
| "sheet"
|
|
18
|
-
| "file"
|
|
19
|
-
| "wiki"
|
|
20
|
-
| "bitable"
|
|
21
|
-
| "docx"
|
|
22
|
-
| "mindnote"
|
|
23
|
-
| "minutes"
|
|
24
|
-
| "slides";
|
|
25
|
-
type CreateTokenType =
|
|
26
|
-
| "doc"
|
|
27
|
-
| "sheet"
|
|
28
|
-
| "file"
|
|
29
|
-
| "wiki"
|
|
30
|
-
| "bitable"
|
|
31
|
-
| "docx"
|
|
32
|
-
| "folder"
|
|
33
|
-
| "mindnote"
|
|
34
|
-
| "minutes"
|
|
35
|
-
| "slides";
|
|
36
|
-
type MemberType =
|
|
37
|
-
| "email"
|
|
38
|
-
| "openid"
|
|
39
|
-
| "unionid"
|
|
40
|
-
| "openchat"
|
|
41
|
-
| "opendepartmentid"
|
|
42
|
-
| "userid"
|
|
43
|
-
| "groupid"
|
|
44
|
-
| "wikispaceid";
|
|
45
|
-
type PermType = "view" | "edit" | "full_access";
|
|
46
|
-
|
|
47
|
-
// ============ Actions ============
|
|
48
|
-
|
|
49
|
-
async function listMembers(client: Lark.Client, token: string, type: string) {
|
|
50
|
-
const res = await client.drive.permissionMember.list({
|
|
51
|
-
path: { token },
|
|
52
|
-
params: { type: type as ListTokenType },
|
|
53
|
-
});
|
|
54
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
members:
|
|
58
|
-
res.data?.items?.map((m) => ({
|
|
59
|
-
member_type: m.member_type,
|
|
60
|
-
member_id: m.member_id,
|
|
61
|
-
perm: m.perm,
|
|
62
|
-
name: m.name,
|
|
63
|
-
})) ?? [],
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async function addMember(
|
|
68
|
-
client: Lark.Client,
|
|
69
|
-
token: string,
|
|
70
|
-
type: string,
|
|
71
|
-
memberType: string,
|
|
72
|
-
memberId: string,
|
|
73
|
-
perm: string,
|
|
74
|
-
) {
|
|
75
|
-
const res = await client.drive.permissionMember.create({
|
|
76
|
-
path: { token },
|
|
77
|
-
params: { type: type as CreateTokenType, need_notification: false },
|
|
78
|
-
data: {
|
|
79
|
-
member_type: memberType as MemberType,
|
|
80
|
-
member_id: memberId,
|
|
81
|
-
perm: perm as PermType,
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
85
|
-
|
|
86
|
-
return {
|
|
87
|
-
success: true,
|
|
88
|
-
member: res.data?.member,
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async function removeMember(
|
|
93
|
-
client: Lark.Client,
|
|
94
|
-
token: string,
|
|
95
|
-
type: string,
|
|
96
|
-
memberType: string,
|
|
97
|
-
memberId: string,
|
|
98
|
-
) {
|
|
99
|
-
const res = await client.drive.permissionMember.delete({
|
|
100
|
-
path: { token, member_id: memberId },
|
|
101
|
-
params: { type: type as CreateTokenType, member_type: memberType as MemberType },
|
|
102
|
-
});
|
|
103
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
success: true,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// ============ Tool Registration ============
|
|
111
|
-
|
|
112
|
-
export function registerFeishuPermTools(api: OpenClawPluginApi) {
|
|
113
|
-
if (!api.config) {
|
|
114
|
-
api.logger.debug?.("feishu_perm: No config available, skipping perm tools");
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (!hasFeishuToolEnabledForAnyAccount(api.config)) {
|
|
119
|
-
api.logger.debug?.("feishu_perm: No Feishu accounts configured, skipping perm tools");
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (!hasFeishuToolEnabledForAnyAccount(api.config, "perm")) {
|
|
124
|
-
api.logger.debug?.("feishu_perm: perm tool disabled in config (default: false)");
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
api.registerTool(
|
|
129
|
-
{
|
|
130
|
-
name: "feishu_perm",
|
|
131
|
-
label: "Feishu Perm",
|
|
132
|
-
description: "Feishu permission management. Actions: list, add, remove",
|
|
133
|
-
parameters: FeishuPermSchema,
|
|
134
|
-
async execute(_toolCallId, params) {
|
|
135
|
-
const p = params as FeishuPermParams;
|
|
136
|
-
try {
|
|
137
|
-
return await withFeishuToolClient({
|
|
138
|
-
api,
|
|
139
|
-
toolName: "feishu_perm",
|
|
140
|
-
requiredTool: "perm",
|
|
141
|
-
run: async ({ client }) => {
|
|
142
|
-
switch (p.action) {
|
|
143
|
-
case "list":
|
|
144
|
-
return json(await listMembers(client, p.token, p.type));
|
|
145
|
-
case "add":
|
|
146
|
-
return json(
|
|
147
|
-
await addMember(client, p.token, p.type, p.member_type, p.member_id, p.perm),
|
|
148
|
-
);
|
|
149
|
-
case "remove":
|
|
150
|
-
return json(await removeMember(client, p.token, p.type, p.member_type, p.member_id));
|
|
151
|
-
default:
|
|
152
|
-
return json({ error: `Unknown action: ${(p as any).action}` });
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
} catch (err) {
|
|
157
|
-
return json({ error: err instanceof Error ? err.message : String(err) });
|
|
158
|
-
}
|
|
159
|
-
},
|
|
160
|
-
},
|
|
161
|
-
{ name: "feishu_perm" },
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
api.logger.debug?.("feishu_perm: Registered feishu_perm tool");
|
|
165
|
-
}
|
package/src/task.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { registerFeishuTaskTools } from "./task-tools/register.js";
|
package/src/wiki.ts
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
2
|
-
import type * as Lark from "@larksuiteoapi/node-sdk";
|
|
3
|
-
import { FeishuWikiSchema, type FeishuWikiParams } from "./wiki-schema.js";
|
|
4
|
-
import { hasFeishuToolEnabledForAnyAccount, withFeishuToolClient } from "./tools-common/tool-exec.js";
|
|
5
|
-
|
|
6
|
-
// ============ Helpers ============
|
|
7
|
-
|
|
8
|
-
function json(data: unknown) {
|
|
9
|
-
return {
|
|
10
|
-
content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }],
|
|
11
|
-
details: data,
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
type ObjType = "doc" | "sheet" | "mindnote" | "bitable" | "file" | "docx" | "slides";
|
|
16
|
-
|
|
17
|
-
// ============ Actions ============
|
|
18
|
-
|
|
19
|
-
const WIKI_ACCESS_HINT =
|
|
20
|
-
"To grant wiki access: Open wiki space → Settings → Members → Add the bot. " +
|
|
21
|
-
"See: https://open.feishu.cn/document/server-docs/docs/wiki-v2/wiki-qa#a40ad4ca";
|
|
22
|
-
|
|
23
|
-
async function listSpaces(client: Lark.Client) {
|
|
24
|
-
const res = await client.wiki.space.list({});
|
|
25
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
26
|
-
|
|
27
|
-
const spaces =
|
|
28
|
-
res.data?.items?.map((s) => ({
|
|
29
|
-
space_id: s.space_id,
|
|
30
|
-
name: s.name,
|
|
31
|
-
description: s.description,
|
|
32
|
-
visibility: s.visibility,
|
|
33
|
-
})) ?? [];
|
|
34
|
-
|
|
35
|
-
return {
|
|
36
|
-
spaces,
|
|
37
|
-
...(spaces.length === 0 && { hint: WIKI_ACCESS_HINT }),
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
async function listNodes(client: Lark.Client, spaceId: string, parentNodeToken?: string) {
|
|
42
|
-
const res = await client.wiki.spaceNode.list({
|
|
43
|
-
path: { space_id: spaceId },
|
|
44
|
-
params: { parent_node_token: parentNodeToken },
|
|
45
|
-
});
|
|
46
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
nodes:
|
|
50
|
-
res.data?.items?.map((n) => ({
|
|
51
|
-
node_token: n.node_token,
|
|
52
|
-
obj_token: n.obj_token,
|
|
53
|
-
obj_type: n.obj_type,
|
|
54
|
-
title: n.title,
|
|
55
|
-
has_child: n.has_child,
|
|
56
|
-
})) ?? [],
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async function getNode(client: Lark.Client, token: string) {
|
|
61
|
-
const res = await client.wiki.space.getNode({
|
|
62
|
-
params: { token },
|
|
63
|
-
});
|
|
64
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
65
|
-
|
|
66
|
-
const node = res.data?.node;
|
|
67
|
-
return {
|
|
68
|
-
node_token: node?.node_token,
|
|
69
|
-
space_id: node?.space_id,
|
|
70
|
-
obj_token: node?.obj_token,
|
|
71
|
-
obj_type: node?.obj_type,
|
|
72
|
-
title: node?.title,
|
|
73
|
-
parent_node_token: node?.parent_node_token,
|
|
74
|
-
has_child: node?.has_child,
|
|
75
|
-
creator: node?.creator,
|
|
76
|
-
create_time: node?.node_create_time,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
async function createNode(
|
|
81
|
-
client: Lark.Client,
|
|
82
|
-
spaceId: string,
|
|
83
|
-
title: string,
|
|
84
|
-
objType?: string,
|
|
85
|
-
parentNodeToken?: string,
|
|
86
|
-
) {
|
|
87
|
-
const res = await client.wiki.spaceNode.create({
|
|
88
|
-
path: { space_id: spaceId },
|
|
89
|
-
data: {
|
|
90
|
-
obj_type: (objType as ObjType) || "docx",
|
|
91
|
-
node_type: "origin" as const,
|
|
92
|
-
title,
|
|
93
|
-
parent_node_token: parentNodeToken,
|
|
94
|
-
},
|
|
95
|
-
});
|
|
96
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
97
|
-
|
|
98
|
-
const node = res.data?.node;
|
|
99
|
-
return {
|
|
100
|
-
node_token: node?.node_token,
|
|
101
|
-
obj_token: node?.obj_token,
|
|
102
|
-
obj_type: node?.obj_type,
|
|
103
|
-
title: node?.title,
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
async function moveNode(
|
|
108
|
-
client: Lark.Client,
|
|
109
|
-
spaceId: string,
|
|
110
|
-
nodeToken: string,
|
|
111
|
-
targetSpaceId?: string,
|
|
112
|
-
targetParentToken?: string,
|
|
113
|
-
) {
|
|
114
|
-
const res = await client.wiki.spaceNode.move({
|
|
115
|
-
path: { space_id: spaceId, node_token: nodeToken },
|
|
116
|
-
data: {
|
|
117
|
-
target_space_id: targetSpaceId || spaceId,
|
|
118
|
-
target_parent_token: targetParentToken,
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
success: true,
|
|
125
|
-
node_token: res.data?.node?.node_token,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
async function renameNode(
|
|
130
|
-
client: Lark.Client,
|
|
131
|
-
spaceId: string,
|
|
132
|
-
nodeToken: string,
|
|
133
|
-
title: string,
|
|
134
|
-
) {
|
|
135
|
-
const res = await client.wiki.spaceNode.updateTitle({
|
|
136
|
-
path: { space_id: spaceId, node_token: nodeToken },
|
|
137
|
-
data: { title },
|
|
138
|
-
});
|
|
139
|
-
if (res.code !== 0) throw new Error(res.msg);
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
success: true,
|
|
143
|
-
node_token: nodeToken,
|
|
144
|
-
title,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// ============ Tool Registration ============
|
|
149
|
-
|
|
150
|
-
export function registerFeishuWikiTools(api: OpenClawPluginApi) {
|
|
151
|
-
if (!api.config) {
|
|
152
|
-
api.logger.debug?.("feishu_wiki: No config available, skipping wiki tools");
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
if (!hasFeishuToolEnabledForAnyAccount(api.config)) {
|
|
157
|
-
api.logger.debug?.("feishu_wiki: No Feishu accounts configured, skipping wiki tools");
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (!hasFeishuToolEnabledForAnyAccount(api.config, "wiki")) {
|
|
162
|
-
api.logger.debug?.("feishu_wiki: wiki tool disabled in config");
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
api.registerTool(
|
|
167
|
-
{
|
|
168
|
-
name: "feishu_wiki",
|
|
169
|
-
label: "Feishu Wiki",
|
|
170
|
-
description:
|
|
171
|
-
"Feishu knowledge base operations. Actions: spaces, nodes, get, create, move, rename",
|
|
172
|
-
parameters: FeishuWikiSchema,
|
|
173
|
-
async execute(_toolCallId, params) {
|
|
174
|
-
const p = params as FeishuWikiParams;
|
|
175
|
-
try {
|
|
176
|
-
return await withFeishuToolClient({
|
|
177
|
-
api,
|
|
178
|
-
toolName: "feishu_wiki",
|
|
179
|
-
requiredTool: "wiki",
|
|
180
|
-
run: async ({ client }) => {
|
|
181
|
-
switch (p.action) {
|
|
182
|
-
case "spaces":
|
|
183
|
-
return json(await listSpaces(client));
|
|
184
|
-
case "nodes":
|
|
185
|
-
return json(await listNodes(client, p.space_id, p.parent_node_token));
|
|
186
|
-
case "get":
|
|
187
|
-
return json(await getNode(client, p.token));
|
|
188
|
-
case "search":
|
|
189
|
-
return json({
|
|
190
|
-
error:
|
|
191
|
-
"Search is not available. Use feishu_wiki with action: 'nodes' to browse or action: 'get' to lookup by token.",
|
|
192
|
-
});
|
|
193
|
-
case "create":
|
|
194
|
-
return json(
|
|
195
|
-
await createNode(client, p.space_id, p.title, p.obj_type, p.parent_node_token),
|
|
196
|
-
);
|
|
197
|
-
case "move":
|
|
198
|
-
return json(
|
|
199
|
-
await moveNode(
|
|
200
|
-
client,
|
|
201
|
-
p.space_id,
|
|
202
|
-
p.node_token,
|
|
203
|
-
p.target_space_id,
|
|
204
|
-
p.target_parent_token,
|
|
205
|
-
),
|
|
206
|
-
);
|
|
207
|
-
case "rename":
|
|
208
|
-
return json(await renameNode(client, p.space_id, p.node_token, p.title));
|
|
209
|
-
default:
|
|
210
|
-
return json({ error: `Unknown action: ${(p as any).action}` });
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
} catch (err) {
|
|
215
|
-
return json({ error: err instanceof Error ? err.message : String(err) });
|
|
216
|
-
}
|
|
217
|
-
},
|
|
218
|
-
},
|
|
219
|
-
{ name: "feishu_wiki" },
|
|
220
|
-
);
|
|
221
|
-
|
|
222
|
-
api.logger.debug?.("feishu_wiki: Registered feishu_wiki tool");
|
|
223
|
-
}
|
|
File without changes
|
|
File without changes
|