@zhin.js/adapter-lark 1.0.64 → 1.0.66
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/CHANGELOG.md +24 -0
- package/lib/adapter.d.ts +0 -4
- package/lib/adapter.d.ts.map +1 -1
- package/lib/adapter.js +1 -209
- package/lib/adapter.js.map +1 -1
- package/lib/index.js +185 -1
- package/lib/index.js.map +1 -1
- package/package.json +6 -6
- package/skills/lark/SKILL.md +51 -3
- package/src/adapter.ts +0 -210
- package/src/index.ts +190 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @zhin.js/adapter-lark
|
|
2
2
|
|
|
3
|
+
## 1.0.66
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 5073d4c: chore: chore: update TypeScript version to ^5.9.3 across all plugins and packages
|
|
8
|
+
feat: enhance ai-text-as-image output registration with off handler for cleanup
|
|
9
|
+
fix: remove unnecessary logging in ensureBuiltinFontsCached function
|
|
10
|
+
refactor: simplify action handlers in html-renderer tools
|
|
11
|
+
chore: add README files for queue-sandbox-poc and event-delivery packages
|
|
12
|
+
chore: adjust pnpm workspace configuration to exclude games directory
|
|
13
|
+
chore: update tsconfig to include plugins directory for TypeScript compilation
|
|
14
|
+
- Updated dependencies [5073d4c]
|
|
15
|
+
- zhin.js@1.0.60
|
|
16
|
+
- @zhin.js/http@1.0.55
|
|
17
|
+
|
|
18
|
+
## 1.0.65
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- c212bf7: fix: 适配器优化
|
|
23
|
+
- Updated dependencies [c212bf7]
|
|
24
|
+
- zhin.js@1.0.59
|
|
25
|
+
- @zhin.js/http@1.0.54
|
|
26
|
+
|
|
3
27
|
## 1.0.64
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/lib/adapter.d.ts
CHANGED
|
@@ -13,9 +13,5 @@ export declare class LarkAdapter extends Adapter<LarkBot> {
|
|
|
13
13
|
getGroupInfo(botId: string, sceneId: string): Promise<any>;
|
|
14
14
|
setGroupName(botId: string, sceneId: string, name: string): Promise<boolean>;
|
|
15
15
|
start(): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* 注册飞书平台特有工具(获取用户、设管等)
|
|
18
|
-
*/
|
|
19
|
-
private registerLarkPlatformTools;
|
|
20
16
|
}
|
|
21
17
|
//# sourceMappingURL=adapter.d.ts.map
|
package/lib/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,EACP,MAAM,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,EACP,MAAM,EACP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,qBAAa,WAAY,SAAQ,OAAO,CAAC,OAAO,CAAC;;gBAGjC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG;IAKvC,SAAS,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO;IAMnC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMzD,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM1C,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM3C,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAQzD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI/B"}
|
package/lib/adapter.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 飞书/Lark 适配器
|
|
3
3
|
*/
|
|
4
|
-
import { Adapter,
|
|
4
|
+
import { Adapter, } from "zhin.js";
|
|
5
5
|
import { LarkBot } from "./bot.js";
|
|
6
6
|
export class LarkAdapter extends Adapter {
|
|
7
7
|
#router;
|
|
@@ -39,215 +39,7 @@ export class LarkAdapter extends Adapter {
|
|
|
39
39
|
}
|
|
40
40
|
// ── 生命周期 ───────────────────────────────────────────────────────
|
|
41
41
|
async start() {
|
|
42
|
-
this.registerLarkPlatformTools();
|
|
43
|
-
const groupTools = createGroupManagementTools(this, this.name);
|
|
44
|
-
groupTools.forEach((t) => this.addTool(t));
|
|
45
42
|
await super.start();
|
|
46
43
|
}
|
|
47
|
-
/**
|
|
48
|
-
* 注册飞书平台特有工具(获取用户、设管等)
|
|
49
|
-
*/
|
|
50
|
-
registerLarkPlatformTools() {
|
|
51
|
-
// 获取用户信息工具
|
|
52
|
-
this.addTool({
|
|
53
|
-
name: 'lark_get_user',
|
|
54
|
-
description: '获取飞书用户信息',
|
|
55
|
-
parameters: {
|
|
56
|
-
type: 'object',
|
|
57
|
-
properties: {
|
|
58
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
59
|
-
user_id: { type: 'string', description: '用户 ID (open_id)' },
|
|
60
|
-
},
|
|
61
|
-
required: ['bot', 'user_id'],
|
|
62
|
-
},
|
|
63
|
-
platforms: ['lark'],
|
|
64
|
-
scopes: ['group', 'private'],
|
|
65
|
-
permissionLevel: 'user',
|
|
66
|
-
execute: async (args) => {
|
|
67
|
-
const { bot: botId, user_id } = args;
|
|
68
|
-
const bot = this.bots.get(botId);
|
|
69
|
-
if (!bot)
|
|
70
|
-
throw new Error(`Bot ${botId} 不存在`);
|
|
71
|
-
return await bot.getUserInfo(user_id);
|
|
72
|
-
},
|
|
73
|
-
});
|
|
74
|
-
// 创建群聊工具
|
|
75
|
-
this.addTool({
|
|
76
|
-
name: 'lark_create_chat',
|
|
77
|
-
description: '创建飞书群聊',
|
|
78
|
-
parameters: {
|
|
79
|
-
type: 'object',
|
|
80
|
-
properties: {
|
|
81
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
82
|
-
name: { type: 'string', description: '群名' },
|
|
83
|
-
members: { type: 'array', items: { type: 'string' }, description: '成员 open_id 列表' },
|
|
84
|
-
owner: { type: 'string', description: '群主 open_id(可选)' },
|
|
85
|
-
},
|
|
86
|
-
required: ['bot', 'name', 'members'],
|
|
87
|
-
},
|
|
88
|
-
platforms: ['lark'],
|
|
89
|
-
scopes: ['group', 'private'],
|
|
90
|
-
permissionLevel: 'group_admin',
|
|
91
|
-
execute: async (args) => {
|
|
92
|
-
const { bot: botId, name, members, owner } = args;
|
|
93
|
-
const bot = this.bots.get(botId);
|
|
94
|
-
if (!bot)
|
|
95
|
-
throw new Error(`Bot ${botId} 不存在`);
|
|
96
|
-
const chatId = await bot.createChat(name, members, owner);
|
|
97
|
-
return { success: !!chatId, chat_id: chatId, message: chatId ? `群聊创建成功: ${chatId}` : '创建失败' };
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
// 更新群信息工具
|
|
101
|
-
this.addTool({
|
|
102
|
-
name: 'lark_update_chat',
|
|
103
|
-
description: '更新飞书群聊信息(群名、描述)',
|
|
104
|
-
parameters: {
|
|
105
|
-
type: 'object',
|
|
106
|
-
properties: {
|
|
107
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
108
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
109
|
-
name: { type: 'string', description: '新群名(可选)' },
|
|
110
|
-
description: { type: 'string', description: '新描述(可选)' },
|
|
111
|
-
},
|
|
112
|
-
required: ['bot', 'chat_id'],
|
|
113
|
-
},
|
|
114
|
-
platforms: ['lark'],
|
|
115
|
-
scopes: ['group'],
|
|
116
|
-
permissionLevel: 'group_admin',
|
|
117
|
-
execute: async (args) => {
|
|
118
|
-
const { bot: botId, chat_id, name, description } = args;
|
|
119
|
-
const bot = this.bots.get(botId);
|
|
120
|
-
if (!bot)
|
|
121
|
-
throw new Error(`Bot ${botId} 不存在`);
|
|
122
|
-
const success = await bot.updateChatInfo(chat_id, { name, description });
|
|
123
|
-
return { success, message: success ? '群信息更新成功' : '更新失败' };
|
|
124
|
-
},
|
|
125
|
-
});
|
|
126
|
-
// 添加群成员工具
|
|
127
|
-
this.addTool({
|
|
128
|
-
name: 'lark_add_members',
|
|
129
|
-
description: '添加飞书群成员',
|
|
130
|
-
parameters: {
|
|
131
|
-
type: 'object',
|
|
132
|
-
properties: {
|
|
133
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
134
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
135
|
-
user_ids: { type: 'array', items: { type: 'string' }, description: '用户 open_id 列表' },
|
|
136
|
-
},
|
|
137
|
-
required: ['bot', 'chat_id', 'user_ids'],
|
|
138
|
-
},
|
|
139
|
-
platforms: ['lark'],
|
|
140
|
-
scopes: ['group'],
|
|
141
|
-
permissionLevel: 'group_admin',
|
|
142
|
-
execute: async (args) => {
|
|
143
|
-
const { bot: botId, chat_id, user_ids } = args;
|
|
144
|
-
const bot = this.bots.get(botId);
|
|
145
|
-
if (!bot)
|
|
146
|
-
throw new Error(`Bot ${botId} 不存在`);
|
|
147
|
-
const success = await bot.addChatMembers(chat_id, user_ids);
|
|
148
|
-
return { success, message: success ? '成员添加成功' : '添加失败' };
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
// 设置群管理员工具
|
|
152
|
-
this.addTool({
|
|
153
|
-
name: 'lark_set_managers',
|
|
154
|
-
description: '设置飞书群管理员',
|
|
155
|
-
parameters: {
|
|
156
|
-
type: 'object',
|
|
157
|
-
properties: {
|
|
158
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
159
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
160
|
-
user_ids: { type: 'array', items: { type: 'string' }, description: '用户 open_id 列表' },
|
|
161
|
-
},
|
|
162
|
-
required: ['bot', 'chat_id', 'user_ids'],
|
|
163
|
-
},
|
|
164
|
-
platforms: ['lark'],
|
|
165
|
-
scopes: ['group'],
|
|
166
|
-
permissionLevel: 'group_owner',
|
|
167
|
-
execute: async (args) => {
|
|
168
|
-
const { bot: botId, chat_id, user_ids } = args;
|
|
169
|
-
const bot = this.bots.get(botId);
|
|
170
|
-
if (!bot)
|
|
171
|
-
throw new Error(`Bot ${botId} 不存在`);
|
|
172
|
-
const success = await bot.setChatManagers(chat_id, user_ids);
|
|
173
|
-
return { success, message: success ? '管理员设置成功' : '设置失败' };
|
|
174
|
-
},
|
|
175
|
-
});
|
|
176
|
-
// 移除群管理员工具
|
|
177
|
-
this.addTool({
|
|
178
|
-
name: 'lark_remove_managers',
|
|
179
|
-
description: '移除飞书群管理员',
|
|
180
|
-
parameters: {
|
|
181
|
-
type: 'object',
|
|
182
|
-
properties: {
|
|
183
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
184
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
185
|
-
user_ids: { type: 'array', items: { type: 'string' }, description: '用户 open_id 列表' },
|
|
186
|
-
},
|
|
187
|
-
required: ['bot', 'chat_id', 'user_ids'],
|
|
188
|
-
},
|
|
189
|
-
platforms: ['lark'],
|
|
190
|
-
scopes: ['group'],
|
|
191
|
-
permissionLevel: 'group_owner',
|
|
192
|
-
execute: async (args) => {
|
|
193
|
-
const { bot: botId, chat_id, user_ids } = args;
|
|
194
|
-
const bot = this.bots.get(botId);
|
|
195
|
-
if (!bot)
|
|
196
|
-
throw new Error(`Bot ${botId} 不存在`);
|
|
197
|
-
const success = await bot.removeChatManagers(chat_id, user_ids);
|
|
198
|
-
return { success, message: success ? '管理员移除成功' : '移除失败' };
|
|
199
|
-
},
|
|
200
|
-
});
|
|
201
|
-
// 解散群聊工具
|
|
202
|
-
this.addTool({
|
|
203
|
-
name: 'lark_dissolve_chat',
|
|
204
|
-
description: '解散飞书群聊(需要群主权限)',
|
|
205
|
-
parameters: {
|
|
206
|
-
type: 'object',
|
|
207
|
-
properties: {
|
|
208
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
209
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
210
|
-
},
|
|
211
|
-
required: ['bot', 'chat_id'],
|
|
212
|
-
},
|
|
213
|
-
platforms: ['lark'],
|
|
214
|
-
scopes: ['group'],
|
|
215
|
-
permissionLevel: 'group_owner',
|
|
216
|
-
execute: async (args) => {
|
|
217
|
-
const { bot: botId, chat_id } = args;
|
|
218
|
-
const bot = this.bots.get(botId);
|
|
219
|
-
if (!bot)
|
|
220
|
-
throw new Error(`Bot ${botId} 不存在`);
|
|
221
|
-
const success = await bot.dissolveChat(chat_id);
|
|
222
|
-
return { success, message: success ? '群聊已解散' : '解散失败' };
|
|
223
|
-
},
|
|
224
|
-
});
|
|
225
|
-
// 文件上传
|
|
226
|
-
this.addTool({
|
|
227
|
-
name: 'lark_upload_file',
|
|
228
|
-
description: '上传文件到飞书(图片/文件/视频/音频)',
|
|
229
|
-
parameters: {
|
|
230
|
-
type: 'object',
|
|
231
|
-
properties: {
|
|
232
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
233
|
-
file_path: { type: 'string', description: '本地文件路径' },
|
|
234
|
-
file_type: { type: 'string', description: '文件类型:image/file/video/audio', enum: ['image', 'file', 'video', 'audio'] },
|
|
235
|
-
},
|
|
236
|
-
required: ['bot', 'file_path', 'file_type'],
|
|
237
|
-
},
|
|
238
|
-
platforms: ['lark'],
|
|
239
|
-
scopes: ['group', 'private'],
|
|
240
|
-
permissionLevel: 'user',
|
|
241
|
-
execute: async (args) => {
|
|
242
|
-
const { bot: botId, file_path, file_type } = args;
|
|
243
|
-
const bot = this.bots.get(botId);
|
|
244
|
-
if (!bot)
|
|
245
|
-
throw new Error(`Bot ${botId} 不存在`);
|
|
246
|
-
const result = await bot.uploadFile(file_path, file_type);
|
|
247
|
-
return { success: true, file_key: result, message: `文件已上传,file_key: ${result}` };
|
|
248
|
-
},
|
|
249
|
-
});
|
|
250
|
-
this.plugin.logger.debug('已注册飞书平台群组管理工具');
|
|
251
|
-
}
|
|
252
44
|
}
|
|
253
45
|
//# sourceMappingURL=adapter.js.map
|
package/lib/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,GAER,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAGnC,MAAM,OAAO,WAAY,SAAQ,OAAgB;IAC7C,OAAO,CAAM;IAEb,YAAY,MAAc,EAAE,MAAW;QACnC,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QAC1B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED,SAAS,CAAC,MAAqB;QAC3B,OAAO,IAAI,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACnD,CAAC;IAED,gEAAgE;IAEhE,KAAK,CAAC,UAAU,CAAC,KAAa,EAAE,OAAe,EAAE,MAAc;QAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;QAC9C,OAAO,GAAG,CAAC,iBAAiB,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IACpD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,OAAe;QAC5C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;QAC9C,OAAO,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,OAAe;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;QAC9C,OAAO,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,KAAa,EAAE,OAAe,EAAE,IAAY;QAC3D,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,IAAI,CAAC,GAAG;YAAE,MAAM,IAAI,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,CAAC;QAC9C,OAAO,GAAG,CAAC,cAAc,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;IACjD,CAAC;IAED,kEAAkE;IAElE,KAAK,CAAC,KAAK;QACP,MAAM,KAAK,CAAC,KAAK,EAAE,CAAC;IACxB,CAAC;CAEJ"}
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 飞书/Lark 适配器入口:类型扩展、导出、注册
|
|
3
3
|
*/
|
|
4
|
-
import { usePlugin } from "zhin.js";
|
|
4
|
+
import { usePlugin, createGroupManagementTools } from "zhin.js";
|
|
5
5
|
import { LarkAdapter } from "./adapter.js";
|
|
6
6
|
export * from "./types.js";
|
|
7
7
|
export { LarkBot } from "./bot.js";
|
|
@@ -22,4 +22,188 @@ useContext("router", (router) => {
|
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
|
+
useContext('tool', 'lark', (toolService, lark) => {
|
|
26
|
+
const groupTools = createGroupManagementTools(lark, 'lark');
|
|
27
|
+
const disposers = groupTools.map(t => toolService.addTool(t, 'lark'));
|
|
28
|
+
disposers.push(toolService.addTool({
|
|
29
|
+
name: 'lark_get_user',
|
|
30
|
+
description: '获取飞书用户信息',
|
|
31
|
+
parameters: {
|
|
32
|
+
type: 'object',
|
|
33
|
+
properties: {
|
|
34
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
35
|
+
user_id: { type: 'string', description: '用户 ID (open_id)' },
|
|
36
|
+
},
|
|
37
|
+
required: ['bot', 'user_id'],
|
|
38
|
+
},
|
|
39
|
+
platforms: ['lark'],
|
|
40
|
+
tags: ['lark'],
|
|
41
|
+
execute: async (args) => {
|
|
42
|
+
const bot = lark.bots.get(args.bot);
|
|
43
|
+
if (!bot)
|
|
44
|
+
throw new Error(`Bot ${args.bot} 不存在`);
|
|
45
|
+
return await bot.getUserInfo(args.user_id);
|
|
46
|
+
},
|
|
47
|
+
}, 'lark'));
|
|
48
|
+
disposers.push(toolService.addTool({
|
|
49
|
+
name: 'lark_create_chat',
|
|
50
|
+
description: '创建飞书群聊',
|
|
51
|
+
parameters: {
|
|
52
|
+
type: 'object',
|
|
53
|
+
properties: {
|
|
54
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
55
|
+
name: { type: 'string', description: '群名' },
|
|
56
|
+
members: { type: 'string', description: '成员 open_id 列表,逗号分隔' },
|
|
57
|
+
owner: { type: 'string', description: '群主 open_id(可选)' },
|
|
58
|
+
},
|
|
59
|
+
required: ['bot', 'name', 'members'],
|
|
60
|
+
},
|
|
61
|
+
platforms: ['lark'],
|
|
62
|
+
tags: ['lark'],
|
|
63
|
+
execute: async (args) => {
|
|
64
|
+
const bot = lark.bots.get(args.bot);
|
|
65
|
+
if (!bot)
|
|
66
|
+
throw new Error(`Bot ${args.bot} 不存在`);
|
|
67
|
+
const chatId = await bot.createChat(args.name, args.members.split(','), args.owner);
|
|
68
|
+
return { success: !!chatId, chat_id: chatId, message: chatId ? `群聊创建成功: ${chatId}` : '创建失败' };
|
|
69
|
+
},
|
|
70
|
+
}, 'lark'));
|
|
71
|
+
disposers.push(toolService.addTool({
|
|
72
|
+
name: 'lark_update_chat',
|
|
73
|
+
description: '更新飞书群聊信息(群名、描述)',
|
|
74
|
+
parameters: {
|
|
75
|
+
type: 'object',
|
|
76
|
+
properties: {
|
|
77
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
78
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
79
|
+
name: { type: 'string', description: '新群名(可选)' },
|
|
80
|
+
description: { type: 'string', description: '新描述(可选)' },
|
|
81
|
+
},
|
|
82
|
+
required: ['bot', 'chat_id'],
|
|
83
|
+
},
|
|
84
|
+
platforms: ['lark'],
|
|
85
|
+
tags: ['lark'],
|
|
86
|
+
execute: async (args) => {
|
|
87
|
+
const bot = lark.bots.get(args.bot);
|
|
88
|
+
if (!bot)
|
|
89
|
+
throw new Error(`Bot ${args.bot} 不存在`);
|
|
90
|
+
const success = await bot.updateChatInfo(args.chat_id, { name: args.name, description: args.description });
|
|
91
|
+
return { success, message: success ? '群信息更新成功' : '更新失败' };
|
|
92
|
+
},
|
|
93
|
+
}, 'lark'));
|
|
94
|
+
disposers.push(toolService.addTool({
|
|
95
|
+
name: 'lark_add_members',
|
|
96
|
+
description: '添加飞书群成员',
|
|
97
|
+
parameters: {
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: {
|
|
100
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
101
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
102
|
+
user_ids: { type: 'string', description: '用户 open_id 列表,逗号分隔' },
|
|
103
|
+
},
|
|
104
|
+
required: ['bot', 'chat_id', 'user_ids'],
|
|
105
|
+
},
|
|
106
|
+
platforms: ['lark'],
|
|
107
|
+
tags: ['lark'],
|
|
108
|
+
execute: async (args) => {
|
|
109
|
+
const bot = lark.bots.get(args.bot);
|
|
110
|
+
if (!bot)
|
|
111
|
+
throw new Error(`Bot ${args.bot} 不存在`);
|
|
112
|
+
const success = await bot.addChatMembers(args.chat_id, args.user_ids.split(','));
|
|
113
|
+
return { success, message: success ? '成员添加成功' : '添加失败' };
|
|
114
|
+
},
|
|
115
|
+
}, 'lark'));
|
|
116
|
+
disposers.push(toolService.addTool({
|
|
117
|
+
name: 'lark_set_managers',
|
|
118
|
+
description: '设置飞书群管理员',
|
|
119
|
+
parameters: {
|
|
120
|
+
type: 'object',
|
|
121
|
+
properties: {
|
|
122
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
123
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
124
|
+
user_ids: { type: 'string', description: '用户 open_id 列表,逗号分隔' },
|
|
125
|
+
},
|
|
126
|
+
required: ['bot', 'chat_id', 'user_ids'],
|
|
127
|
+
},
|
|
128
|
+
platforms: ['lark'],
|
|
129
|
+
tags: ['lark'],
|
|
130
|
+
execute: async (args) => {
|
|
131
|
+
const bot = lark.bots.get(args.bot);
|
|
132
|
+
if (!bot)
|
|
133
|
+
throw new Error(`Bot ${args.bot} 不存在`);
|
|
134
|
+
const success = await bot.setChatManagers(args.chat_id, args.user_ids.split(','));
|
|
135
|
+
return { success, message: success ? '管理员设置成功' : '设置失败' };
|
|
136
|
+
},
|
|
137
|
+
}, 'lark'));
|
|
138
|
+
disposers.push(toolService.addTool({
|
|
139
|
+
name: 'lark_remove_managers',
|
|
140
|
+
description: '移除飞书群管理员',
|
|
141
|
+
parameters: {
|
|
142
|
+
type: 'object',
|
|
143
|
+
properties: {
|
|
144
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
145
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
146
|
+
user_ids: { type: 'string', description: '用户 open_id 列表,逗号分隔' },
|
|
147
|
+
},
|
|
148
|
+
required: ['bot', 'chat_id', 'user_ids'],
|
|
149
|
+
},
|
|
150
|
+
platforms: ['lark'],
|
|
151
|
+
tags: ['lark'],
|
|
152
|
+
execute: async (args) => {
|
|
153
|
+
const bot = lark.bots.get(args.bot);
|
|
154
|
+
if (!bot)
|
|
155
|
+
throw new Error(`Bot ${args.bot} 不存在`);
|
|
156
|
+
const success = await bot.removeChatManagers(args.chat_id, args.user_ids.split(','));
|
|
157
|
+
return { success, message: success ? '管理员移除成功' : '移除失败' };
|
|
158
|
+
},
|
|
159
|
+
}, 'lark'));
|
|
160
|
+
disposers.push(toolService.addTool({
|
|
161
|
+
name: 'lark_dissolve_chat',
|
|
162
|
+
description: '解散飞书群聊(需要群主权限)',
|
|
163
|
+
parameters: {
|
|
164
|
+
type: 'object',
|
|
165
|
+
properties: {
|
|
166
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
167
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
168
|
+
},
|
|
169
|
+
required: ['bot', 'chat_id'],
|
|
170
|
+
},
|
|
171
|
+
platforms: ['lark'],
|
|
172
|
+
tags: ['lark'],
|
|
173
|
+
execute: async (args) => {
|
|
174
|
+
const bot = lark.bots.get(args.bot);
|
|
175
|
+
if (!bot)
|
|
176
|
+
throw new Error(`Bot ${args.bot} 不存在`);
|
|
177
|
+
const success = await bot.dissolveChat(args.chat_id);
|
|
178
|
+
return { success, message: success ? '群聊已解散' : '解散失败' };
|
|
179
|
+
},
|
|
180
|
+
}, 'lark'));
|
|
181
|
+
disposers.push(toolService.addTool({
|
|
182
|
+
name: 'lark_upload_file',
|
|
183
|
+
description: '上传文件到飞书(opus/mp4/pdf/doc/xls/ppt/stream)',
|
|
184
|
+
parameters: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
properties: {
|
|
187
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
188
|
+
file_path: { type: 'string', description: '本地文件路径' },
|
|
189
|
+
file_type: { type: 'string', description: '文件类型', enum: ['opus', 'mp4', 'pdf', 'doc', 'xls', 'ppt', 'stream'] },
|
|
190
|
+
},
|
|
191
|
+
required: ['bot', 'file_path', 'file_type'],
|
|
192
|
+
},
|
|
193
|
+
platforms: ['lark'],
|
|
194
|
+
tags: ['lark'],
|
|
195
|
+
execute: async (args) => {
|
|
196
|
+
const validTypes = ['opus', 'mp4', 'pdf', 'doc', 'xls', 'ppt', 'stream'];
|
|
197
|
+
if (!validTypes.includes(args.file_type)) {
|
|
198
|
+
throw new Error(`不支持的文件类型: ${args.file_type},支持: ${validTypes.join(', ')}`);
|
|
199
|
+
}
|
|
200
|
+
const bot = lark.bots.get(args.bot);
|
|
201
|
+
if (!bot)
|
|
202
|
+
throw new Error(`Bot ${args.bot} 不存在`);
|
|
203
|
+
const result = await bot.uploadFile(args.file_path, args.file_type);
|
|
204
|
+
return { success: true, file_key: result, message: `文件已上传,file_key: ${result}` };
|
|
205
|
+
},
|
|
206
|
+
}, 'lark'));
|
|
207
|
+
return () => disposers.forEach(d => d());
|
|
208
|
+
});
|
|
25
209
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAoD,0BAA0B,EAAoB,MAAM,SAAS,CAAC;AACpI,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAa3C,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3C,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;AAC3B,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;AAEtC,UAA+D,CAAC,QAAQ,EAAE,CAAC,MAA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5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -37,14 +37,14 @@
|
|
|
37
37
|
"axios": "^1.6.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"typescript": "^5.3.0",
|
|
41
|
-
"@types/node": "^22.9.0",
|
|
42
40
|
"@types/koa": "^2.15.0",
|
|
43
|
-
"
|
|
41
|
+
"@types/node": "^22.9.0",
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"zhin.js": "1.0.60"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"zhin.js": "1.0.
|
|
47
|
-
"
|
|
46
|
+
"@zhin.js/http": "1.0.55",
|
|
47
|
+
"zhin.js": "1.0.60"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|
|
50
50
|
"@zhin.js/http": {
|
package/skills/lark/SKILL.md
CHANGED
|
@@ -1,18 +1,66 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: lark
|
|
3
|
-
|
|
3
|
+
platforms:
|
|
4
|
+
- lark
|
|
5
|
+
description: 飞书/Lark 群管理:群管(踢人、查成员/群信息、改群名)、用户查询、群聊创建/更新/解散、添加/移除管理员、文件上传。仅有昵称时请先 list_members 获取 user_id。
|
|
4
6
|
keywords:
|
|
5
7
|
- lark
|
|
6
8
|
- 飞书
|
|
7
9
|
- adapter:lark
|
|
8
10
|
- 群管理
|
|
11
|
+
- 管理员
|
|
12
|
+
- 群聊
|
|
13
|
+
- 文件上传
|
|
9
14
|
- list_members
|
|
10
15
|
tags:
|
|
11
16
|
- group
|
|
12
17
|
- management
|
|
13
|
-
|
|
18
|
+
- im
|
|
19
|
+
- enterprise
|
|
20
|
+
tools:
|
|
21
|
+
# 平台特有工具
|
|
22
|
+
- lark_get_user
|
|
23
|
+
- lark_create_chat
|
|
24
|
+
- lark_update_chat
|
|
25
|
+
- lark_add_members
|
|
26
|
+
- lark_set_managers
|
|
27
|
+
- lark_remove_managers
|
|
28
|
+
- lark_dissolve_chat
|
|
29
|
+
- lark_upload_file
|
|
30
|
+
# 通用群管工具
|
|
31
|
+
- lark_kick_member
|
|
32
|
+
- lark_list_members
|
|
33
|
+
- lark_get_group_info
|
|
34
|
+
- lark_set_group_name
|
|
14
35
|
---
|
|
15
36
|
|
|
37
|
+
## 工具概览
|
|
38
|
+
|
|
39
|
+
### 平台特有
|
|
40
|
+
|
|
41
|
+
| 工具 | 说明 | 权限 |
|
|
42
|
+
|------|------|------|
|
|
43
|
+
| `lark_get_user` | 获取用户信息 | user |
|
|
44
|
+
| `lark_create_chat` | 创建群聊 | group_admin |
|
|
45
|
+
| `lark_update_chat` | 更新群聊设置 | group_admin |
|
|
46
|
+
| `lark_add_members` | 向群聊添加成员 | group_admin |
|
|
47
|
+
| `lark_set_managers` | 设置管理员 | group_admin |
|
|
48
|
+
| `lark_remove_managers` | 移除管理员 | group_admin |
|
|
49
|
+
| `lark_dissolve_chat` | 解散群聊 | group_owner |
|
|
50
|
+
| `lark_upload_file` | 上传文件 | user |
|
|
51
|
+
|
|
52
|
+
### 通用群管
|
|
53
|
+
|
|
54
|
+
| 工具 | 说明 | 权限 |
|
|
55
|
+
|------|------|------|
|
|
56
|
+
| `lark_kick_member` | 踢出成员 | group_admin |
|
|
57
|
+
| `lark_list_members` | 获取成员列表 | user |
|
|
58
|
+
| `lark_get_group_info` | 获取群信息 | user |
|
|
59
|
+
| `lark_set_group_name` | 修改群名称 | group_admin |
|
|
60
|
+
|
|
16
61
|
## 执行规则
|
|
17
62
|
|
|
18
|
-
|
|
63
|
+
1. 仅有昵称时先 `lark_list_members` 或 `lark_get_user` 获取用户 ID
|
|
64
|
+
2. 群聊创建需要至少指定群名和初始成员
|
|
65
|
+
3. 解散群聊操作不可逆,需要群主权限
|
|
66
|
+
4. 文件上传会返回文件 key,可用于消息中引用
|
package/src/adapter.ts
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
import {
|
|
5
5
|
Adapter,
|
|
6
6
|
Plugin,
|
|
7
|
-
createGroupManagementTools,
|
|
8
|
-
type IGroupManagement,
|
|
9
7
|
} from "zhin.js";
|
|
10
8
|
import { LarkBot } from "./bot.js";
|
|
11
9
|
import type { LarkBotConfig } from "./types.js";
|
|
@@ -51,215 +49,7 @@ export class LarkAdapter extends Adapter<LarkBot> {
|
|
|
51
49
|
// ── 生命周期 ───────────────────────────────────────────────────────
|
|
52
50
|
|
|
53
51
|
async start(): Promise<void> {
|
|
54
|
-
this.registerLarkPlatformTools();
|
|
55
|
-
const groupTools = createGroupManagementTools(this as unknown as IGroupManagement, this.name);
|
|
56
|
-
groupTools.forEach((t) => this.addTool(t));
|
|
57
52
|
await super.start();
|
|
58
53
|
}
|
|
59
54
|
|
|
60
|
-
/**
|
|
61
|
-
* 注册飞书平台特有工具(获取用户、设管等)
|
|
62
|
-
*/
|
|
63
|
-
private registerLarkPlatformTools(): void {
|
|
64
|
-
// 获取用户信息工具
|
|
65
|
-
this.addTool({
|
|
66
|
-
name: 'lark_get_user',
|
|
67
|
-
description: '获取飞书用户信息',
|
|
68
|
-
parameters: {
|
|
69
|
-
type: 'object',
|
|
70
|
-
properties: {
|
|
71
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
72
|
-
user_id: { type: 'string', description: '用户 ID (open_id)' },
|
|
73
|
-
},
|
|
74
|
-
required: ['bot', 'user_id'],
|
|
75
|
-
},
|
|
76
|
-
platforms: ['lark'],
|
|
77
|
-
scopes: ['group', 'private'],
|
|
78
|
-
permissionLevel: 'user',
|
|
79
|
-
execute: async (args) => {
|
|
80
|
-
const { bot: botId, user_id } = args;
|
|
81
|
-
const bot = this.bots.get(botId);
|
|
82
|
-
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
83
|
-
return await bot.getUserInfo(user_id);
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// 创建群聊工具
|
|
88
|
-
this.addTool({
|
|
89
|
-
name: 'lark_create_chat',
|
|
90
|
-
description: '创建飞书群聊',
|
|
91
|
-
parameters: {
|
|
92
|
-
type: 'object',
|
|
93
|
-
properties: {
|
|
94
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
95
|
-
name: { type: 'string', description: '群名' },
|
|
96
|
-
members: { type: 'array', items: { type: 'string' }, description: '成员 open_id 列表' },
|
|
97
|
-
owner: { type: 'string', description: '群主 open_id(可选)' },
|
|
98
|
-
},
|
|
99
|
-
required: ['bot', 'name', 'members'],
|
|
100
|
-
},
|
|
101
|
-
platforms: ['lark'],
|
|
102
|
-
scopes: ['group', 'private'],
|
|
103
|
-
permissionLevel: 'group_admin',
|
|
104
|
-
execute: async (args) => {
|
|
105
|
-
const { bot: botId, name, members, owner } = args;
|
|
106
|
-
const bot = this.bots.get(botId);
|
|
107
|
-
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
108
|
-
const chatId = await bot.createChat(name, members, owner);
|
|
109
|
-
return { success: !!chatId, chat_id: chatId, message: chatId ? `群聊创建成功: ${chatId}` : '创建失败' };
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// 更新群信息工具
|
|
114
|
-
this.addTool({
|
|
115
|
-
name: 'lark_update_chat',
|
|
116
|
-
description: '更新飞书群聊信息(群名、描述)',
|
|
117
|
-
parameters: {
|
|
118
|
-
type: 'object',
|
|
119
|
-
properties: {
|
|
120
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
121
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
122
|
-
name: { type: 'string', description: '新群名(可选)' },
|
|
123
|
-
description: { type: 'string', description: '新描述(可选)' },
|
|
124
|
-
},
|
|
125
|
-
required: ['bot', 'chat_id'],
|
|
126
|
-
},
|
|
127
|
-
platforms: ['lark'],
|
|
128
|
-
scopes: ['group'],
|
|
129
|
-
permissionLevel: 'group_admin',
|
|
130
|
-
execute: async (args) => {
|
|
131
|
-
const { bot: botId, chat_id, name, description } = args;
|
|
132
|
-
const bot = this.bots.get(botId);
|
|
133
|
-
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
134
|
-
const success = await bot.updateChatInfo(chat_id, { name, description });
|
|
135
|
-
return { success, message: success ? '群信息更新成功' : '更新失败' };
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
// 添加群成员工具
|
|
140
|
-
this.addTool({
|
|
141
|
-
name: 'lark_add_members',
|
|
142
|
-
description: '添加飞书群成员',
|
|
143
|
-
parameters: {
|
|
144
|
-
type: 'object',
|
|
145
|
-
properties: {
|
|
146
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
147
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
148
|
-
user_ids: { type: 'array', items: { type: 'string' }, description: '用户 open_id 列表' },
|
|
149
|
-
},
|
|
150
|
-
required: ['bot', 'chat_id', 'user_ids'],
|
|
151
|
-
},
|
|
152
|
-
platforms: ['lark'],
|
|
153
|
-
scopes: ['group'],
|
|
154
|
-
permissionLevel: 'group_admin',
|
|
155
|
-
execute: async (args) => {
|
|
156
|
-
const { bot: botId, chat_id, user_ids } = args;
|
|
157
|
-
const bot = this.bots.get(botId);
|
|
158
|
-
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
159
|
-
const success = await bot.addChatMembers(chat_id, user_ids);
|
|
160
|
-
return { success, message: success ? '成员添加成功' : '添加失败' };
|
|
161
|
-
},
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
// 设置群管理员工具
|
|
165
|
-
this.addTool({
|
|
166
|
-
name: 'lark_set_managers',
|
|
167
|
-
description: '设置飞书群管理员',
|
|
168
|
-
parameters: {
|
|
169
|
-
type: 'object',
|
|
170
|
-
properties: {
|
|
171
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
172
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
173
|
-
user_ids: { type: 'array', items: { type: 'string' }, description: '用户 open_id 列表' },
|
|
174
|
-
},
|
|
175
|
-
required: ['bot', 'chat_id', 'user_ids'],
|
|
176
|
-
},
|
|
177
|
-
platforms: ['lark'],
|
|
178
|
-
scopes: ['group'],
|
|
179
|
-
permissionLevel: 'group_owner',
|
|
180
|
-
execute: async (args) => {
|
|
181
|
-
const { bot: botId, chat_id, user_ids } = args;
|
|
182
|
-
const bot = this.bots.get(botId);
|
|
183
|
-
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
184
|
-
const success = await bot.setChatManagers(chat_id, user_ids);
|
|
185
|
-
return { success, message: success ? '管理员设置成功' : '设置失败' };
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
// 移除群管理员工具
|
|
190
|
-
this.addTool({
|
|
191
|
-
name: 'lark_remove_managers',
|
|
192
|
-
description: '移除飞书群管理员',
|
|
193
|
-
parameters: {
|
|
194
|
-
type: 'object',
|
|
195
|
-
properties: {
|
|
196
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
197
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
198
|
-
user_ids: { type: 'array', items: { type: 'string' }, description: '用户 open_id 列表' },
|
|
199
|
-
},
|
|
200
|
-
required: ['bot', 'chat_id', 'user_ids'],
|
|
201
|
-
},
|
|
202
|
-
platforms: ['lark'],
|
|
203
|
-
scopes: ['group'],
|
|
204
|
-
permissionLevel: 'group_owner',
|
|
205
|
-
execute: async (args) => {
|
|
206
|
-
const { bot: botId, chat_id, user_ids } = args;
|
|
207
|
-
const bot = this.bots.get(botId);
|
|
208
|
-
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
209
|
-
const success = await bot.removeChatManagers(chat_id, user_ids);
|
|
210
|
-
return { success, message: success ? '管理员移除成功' : '移除失败' };
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// 解散群聊工具
|
|
215
|
-
this.addTool({
|
|
216
|
-
name: 'lark_dissolve_chat',
|
|
217
|
-
description: '解散飞书群聊(需要群主权限)',
|
|
218
|
-
parameters: {
|
|
219
|
-
type: 'object',
|
|
220
|
-
properties: {
|
|
221
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
222
|
-
chat_id: { type: 'string', description: '群聊 ID' },
|
|
223
|
-
},
|
|
224
|
-
required: ['bot', 'chat_id'],
|
|
225
|
-
},
|
|
226
|
-
platforms: ['lark'],
|
|
227
|
-
scopes: ['group'],
|
|
228
|
-
permissionLevel: 'group_owner',
|
|
229
|
-
execute: async (args) => {
|
|
230
|
-
const { bot: botId, chat_id } = args;
|
|
231
|
-
const bot = this.bots.get(botId);
|
|
232
|
-
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
233
|
-
const success = await bot.dissolveChat(chat_id);
|
|
234
|
-
return { success, message: success ? '群聊已解散' : '解散失败' };
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
// 文件上传
|
|
239
|
-
this.addTool({
|
|
240
|
-
name: 'lark_upload_file',
|
|
241
|
-
description: '上传文件到飞书(图片/文件/视频/音频)',
|
|
242
|
-
parameters: {
|
|
243
|
-
type: 'object',
|
|
244
|
-
properties: {
|
|
245
|
-
bot: { type: 'string', description: 'Bot 名称' },
|
|
246
|
-
file_path: { type: 'string', description: '本地文件路径' },
|
|
247
|
-
file_type: { type: 'string', description: '文件类型:image/file/video/audio', enum: ['image', 'file', 'video', 'audio'] },
|
|
248
|
-
},
|
|
249
|
-
required: ['bot', 'file_path', 'file_type'],
|
|
250
|
-
},
|
|
251
|
-
platforms: ['lark'],
|
|
252
|
-
scopes: ['group', 'private'],
|
|
253
|
-
permissionLevel: 'user',
|
|
254
|
-
execute: async (args) => {
|
|
255
|
-
const { bot: botId, file_path, file_type } = args;
|
|
256
|
-
const bot = this.bots.get(botId);
|
|
257
|
-
if (!bot) throw new Error(`Bot ${botId} 不存在`);
|
|
258
|
-
const result = await bot.uploadFile(file_path, file_type);
|
|
259
|
-
return { success: true, file_key: result, message: `文件已上传,file_key: ${result}` };
|
|
260
|
-
},
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
this.plugin.logger.debug('已注册飞书平台群组管理工具');
|
|
264
|
-
}
|
|
265
55
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 飞书/Lark 适配器入口:类型扩展、导出、注册
|
|
3
3
|
*/
|
|
4
|
-
import { usePlugin, type Plugin, type Context } from "zhin.js";
|
|
4
|
+
import { usePlugin, type Plugin, type Context, type IGroupManagement, createGroupManagementTools, type ToolFeature } from "zhin.js";
|
|
5
5
|
import { LarkAdapter } from "./adapter.js";
|
|
6
6
|
|
|
7
7
|
declare module "zhin.js" {
|
|
@@ -36,3 +36,192 @@ const { provide, useContext } = plugin;
|
|
|
36
36
|
},
|
|
37
37
|
} as Context<"lark">);
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
useContext('tool', 'lark', (toolService: ToolFeature, lark: LarkAdapter) => {
|
|
41
|
+
const groupTools = createGroupManagementTools(
|
|
42
|
+
lark as unknown as IGroupManagement,
|
|
43
|
+
'lark',
|
|
44
|
+
);
|
|
45
|
+
const disposers: (() => void)[] = groupTools.map(t => toolService.addTool(t, 'lark'));
|
|
46
|
+
|
|
47
|
+
disposers.push(toolService.addTool({
|
|
48
|
+
name: 'lark_get_user',
|
|
49
|
+
description: '获取飞书用户信息',
|
|
50
|
+
parameters: {
|
|
51
|
+
type: 'object',
|
|
52
|
+
properties: {
|
|
53
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
54
|
+
user_id: { type: 'string', description: '用户 ID (open_id)' },
|
|
55
|
+
},
|
|
56
|
+
required: ['bot', 'user_id'],
|
|
57
|
+
},
|
|
58
|
+
platforms: ['lark'],
|
|
59
|
+
tags: ['lark'],
|
|
60
|
+
execute: async (args: Record<string, any>) => {
|
|
61
|
+
const bot = lark.bots.get(args.bot);
|
|
62
|
+
if (!bot) throw new Error(`Bot ${args.bot} 不存在`);
|
|
63
|
+
return await bot.getUserInfo(args.user_id);
|
|
64
|
+
},
|
|
65
|
+
}, 'lark'));
|
|
66
|
+
|
|
67
|
+
disposers.push(toolService.addTool({
|
|
68
|
+
name: 'lark_create_chat',
|
|
69
|
+
description: '创建飞书群聊',
|
|
70
|
+
parameters: {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
74
|
+
name: { type: 'string', description: '群名' },
|
|
75
|
+
members: { type: 'string', description: '成员 open_id 列表,逗号分隔' },
|
|
76
|
+
owner: { type: 'string', description: '群主 open_id(可选)' },
|
|
77
|
+
},
|
|
78
|
+
required: ['bot', 'name', 'members'],
|
|
79
|
+
},
|
|
80
|
+
platforms: ['lark'],
|
|
81
|
+
tags: ['lark'],
|
|
82
|
+
execute: async (args: Record<string, any>) => {
|
|
83
|
+
const bot = lark.bots.get(args.bot);
|
|
84
|
+
if (!bot) throw new Error(`Bot ${args.bot} 不存在`);
|
|
85
|
+
const chatId = await bot.createChat(args.name, args.members.split(','), args.owner);
|
|
86
|
+
return { success: !!chatId, chat_id: chatId, message: chatId ? `群聊创建成功: ${chatId}` : '创建失败' };
|
|
87
|
+
},
|
|
88
|
+
}, 'lark'));
|
|
89
|
+
|
|
90
|
+
disposers.push(toolService.addTool({
|
|
91
|
+
name: 'lark_update_chat',
|
|
92
|
+
description: '更新飞书群聊信息(群名、描述)',
|
|
93
|
+
parameters: {
|
|
94
|
+
type: 'object',
|
|
95
|
+
properties: {
|
|
96
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
97
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
98
|
+
name: { type: 'string', description: '新群名(可选)' },
|
|
99
|
+
description: { type: 'string', description: '新描述(可选)' },
|
|
100
|
+
},
|
|
101
|
+
required: ['bot', 'chat_id'],
|
|
102
|
+
},
|
|
103
|
+
platforms: ['lark'],
|
|
104
|
+
tags: ['lark'],
|
|
105
|
+
execute: async (args: Record<string, any>) => {
|
|
106
|
+
const bot = lark.bots.get(args.bot);
|
|
107
|
+
if (!bot) throw new Error(`Bot ${args.bot} 不存在`);
|
|
108
|
+
const success = await bot.updateChatInfo(args.chat_id, { name: args.name, description: args.description });
|
|
109
|
+
return { success, message: success ? '群信息更新成功' : '更新失败' };
|
|
110
|
+
},
|
|
111
|
+
}, 'lark'));
|
|
112
|
+
|
|
113
|
+
disposers.push(toolService.addTool({
|
|
114
|
+
name: 'lark_add_members',
|
|
115
|
+
description: '添加飞书群成员',
|
|
116
|
+
parameters: {
|
|
117
|
+
type: 'object',
|
|
118
|
+
properties: {
|
|
119
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
120
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
121
|
+
user_ids: { type: 'string', description: '用户 open_id 列表,逗号分隔' },
|
|
122
|
+
},
|
|
123
|
+
required: ['bot', 'chat_id', 'user_ids'],
|
|
124
|
+
},
|
|
125
|
+
platforms: ['lark'],
|
|
126
|
+
tags: ['lark'],
|
|
127
|
+
execute: async (args: Record<string, any>) => {
|
|
128
|
+
const bot = lark.bots.get(args.bot);
|
|
129
|
+
if (!bot) throw new Error(`Bot ${args.bot} 不存在`);
|
|
130
|
+
const success = await bot.addChatMembers(args.chat_id, args.user_ids.split(','));
|
|
131
|
+
return { success, message: success ? '成员添加成功' : '添加失败' };
|
|
132
|
+
},
|
|
133
|
+
}, 'lark'));
|
|
134
|
+
|
|
135
|
+
disposers.push(toolService.addTool({
|
|
136
|
+
name: 'lark_set_managers',
|
|
137
|
+
description: '设置飞书群管理员',
|
|
138
|
+
parameters: {
|
|
139
|
+
type: 'object',
|
|
140
|
+
properties: {
|
|
141
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
142
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
143
|
+
user_ids: { type: 'string', description: '用户 open_id 列表,逗号分隔' },
|
|
144
|
+
},
|
|
145
|
+
required: ['bot', 'chat_id', 'user_ids'],
|
|
146
|
+
},
|
|
147
|
+
platforms: ['lark'],
|
|
148
|
+
tags: ['lark'],
|
|
149
|
+
execute: async (args: Record<string, any>) => {
|
|
150
|
+
const bot = lark.bots.get(args.bot);
|
|
151
|
+
if (!bot) throw new Error(`Bot ${args.bot} 不存在`);
|
|
152
|
+
const success = await bot.setChatManagers(args.chat_id, args.user_ids.split(','));
|
|
153
|
+
return { success, message: success ? '管理员设置成功' : '设置失败' };
|
|
154
|
+
},
|
|
155
|
+
}, 'lark'));
|
|
156
|
+
|
|
157
|
+
disposers.push(toolService.addTool({
|
|
158
|
+
name: 'lark_remove_managers',
|
|
159
|
+
description: '移除飞书群管理员',
|
|
160
|
+
parameters: {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: {
|
|
163
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
164
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
165
|
+
user_ids: { type: 'string', description: '用户 open_id 列表,逗号分隔' },
|
|
166
|
+
},
|
|
167
|
+
required: ['bot', 'chat_id', 'user_ids'],
|
|
168
|
+
},
|
|
169
|
+
platforms: ['lark'],
|
|
170
|
+
tags: ['lark'],
|
|
171
|
+
execute: async (args: Record<string, any>) => {
|
|
172
|
+
const bot = lark.bots.get(args.bot);
|
|
173
|
+
if (!bot) throw new Error(`Bot ${args.bot} 不存在`);
|
|
174
|
+
const success = await bot.removeChatManagers(args.chat_id, args.user_ids.split(','));
|
|
175
|
+
return { success, message: success ? '管理员移除成功' : '移除失败' };
|
|
176
|
+
},
|
|
177
|
+
}, 'lark'));
|
|
178
|
+
|
|
179
|
+
disposers.push(toolService.addTool({
|
|
180
|
+
name: 'lark_dissolve_chat',
|
|
181
|
+
description: '解散飞书群聊(需要群主权限)',
|
|
182
|
+
parameters: {
|
|
183
|
+
type: 'object',
|
|
184
|
+
properties: {
|
|
185
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
186
|
+
chat_id: { type: 'string', description: '群聊 ID' },
|
|
187
|
+
},
|
|
188
|
+
required: ['bot', 'chat_id'],
|
|
189
|
+
},
|
|
190
|
+
platforms: ['lark'],
|
|
191
|
+
tags: ['lark'],
|
|
192
|
+
execute: async (args: Record<string, any>) => {
|
|
193
|
+
const bot = lark.bots.get(args.bot);
|
|
194
|
+
if (!bot) throw new Error(`Bot ${args.bot} 不存在`);
|
|
195
|
+
const success = await bot.dissolveChat(args.chat_id);
|
|
196
|
+
return { success, message: success ? '群聊已解散' : '解散失败' };
|
|
197
|
+
},
|
|
198
|
+
}, 'lark'));
|
|
199
|
+
|
|
200
|
+
disposers.push(toolService.addTool({
|
|
201
|
+
name: 'lark_upload_file',
|
|
202
|
+
description: '上传文件到飞书(opus/mp4/pdf/doc/xls/ppt/stream)',
|
|
203
|
+
parameters: {
|
|
204
|
+
type: 'object',
|
|
205
|
+
properties: {
|
|
206
|
+
bot: { type: 'string', description: 'Bot 名称' },
|
|
207
|
+
file_path: { type: 'string', description: '本地文件路径' },
|
|
208
|
+
file_type: { type: 'string', description: '文件类型', enum: ['opus', 'mp4', 'pdf', 'doc', 'xls', 'ppt', 'stream'] },
|
|
209
|
+
},
|
|
210
|
+
required: ['bot', 'file_path', 'file_type'],
|
|
211
|
+
},
|
|
212
|
+
platforms: ['lark'],
|
|
213
|
+
tags: ['lark'],
|
|
214
|
+
execute: async (args: Record<string, any>) => {
|
|
215
|
+
const validTypes = ['opus', 'mp4', 'pdf', 'doc', 'xls', 'ppt', 'stream'];
|
|
216
|
+
if (!validTypes.includes(args.file_type)) {
|
|
217
|
+
throw new Error(`不支持的文件类型: ${args.file_type},支持: ${validTypes.join(', ')}`);
|
|
218
|
+
}
|
|
219
|
+
const bot = lark.bots.get(args.bot);
|
|
220
|
+
if (!bot) throw new Error(`Bot ${args.bot} 不存在`);
|
|
221
|
+
const result = await bot.uploadFile(args.file_path, args.file_type);
|
|
222
|
+
return { success: true, file_key: result, message: `文件已上传,file_key: ${result}` };
|
|
223
|
+
},
|
|
224
|
+
}, 'lark'));
|
|
225
|
+
|
|
226
|
+
return () => disposers.forEach(d => d());
|
|
227
|
+
});
|