@zhin.js/adapter-lark 1.0.97 → 1.1.2
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 +729 -3
- package/PERMITS.md +22 -0
- package/README.md +69 -83
- package/adapters/lark/index.js +36 -0
- package/adapters/lark/index.ts +41 -0
- package/agents/lark/agent.json +20 -0
- package/agents/lark/boundaries.md +3 -0
- package/agents/lark/conventions.md +3 -0
- package/agents/lark/skills/lark/SKILL.md +22 -0
- package/agents/lark/skills/lark/tools/add_members/index.js +19 -0
- package/agents/lark/skills/lark/tools/add_members/index.ts +19 -0
- package/agents/lark/skills/lark/tools/create_chat/index.js +18 -0
- package/agents/lark/skills/lark/tools/create_chat/index.ts +18 -0
- package/agents/lark/skills/lark/tools/dissolve_chat/index.js +16 -0
- package/agents/lark/skills/lark/tools/dissolve_chat/index.ts +16 -0
- package/agents/lark/skills/lark/tools/get_user/index.js +15 -0
- package/agents/lark/skills/lark/tools/get_user/index.ts +16 -0
- package/agents/lark/skills/lark/tools/remove_managers/index.js +19 -0
- package/agents/lark/skills/lark/tools/remove_managers/index.ts +19 -0
- package/agents/lark/skills/lark/tools/set_managers/index.js +19 -0
- package/agents/lark/skills/lark/tools/set_managers/index.ts +19 -0
- package/agents/lark/skills/lark/tools/update_chat/index.js +20 -0
- package/agents/lark/skills/lark/tools/update_chat/index.ts +20 -0
- package/agents/lark/skills/lark/tools/upload_file/index.js +17 -0
- package/agents/lark/skills/lark/tools/upload_file/index.ts +23 -0
- package/agents/lark/system.md +3 -0
- package/commands/lark/endpoint/add/[id]/index.js +3 -0
- package/commands/lark/endpoint/add/[id]/index.ts +3 -0
- package/commands/lark/endpoint/definition.js +20 -0
- package/commands/lark/endpoint/definition.ts +20 -0
- package/commands/lark/endpoint/list/index.js +3 -0
- package/commands/lark/endpoint/list/index.ts +3 -0
- package/commands/lark/endpoint/remove/[id]/index.js +3 -0
- package/commands/lark/endpoint/remove/[id]/index.ts +3 -0
- package/lib/client.d.ts +12 -0
- package/lib/client.js +2 -0
- package/lib/endpoint.d.ts +100 -0
- package/lib/endpoint.js +497 -0
- package/lib/index.d.ts +6 -15
- package/lib/index.js +6 -209
- package/lib/lark-runtime-state.d.ts +1 -0
- package/lib/lark-runtime-state.js +6 -0
- package/lib/media-upload.d.ts +15 -0
- package/lib/media-upload.js +58 -0
- package/lib/platform-permit.d.ts +14 -0
- package/lib/platform-permit.js +35 -0
- package/lib/protocol.d.ts +119 -0
- package/lib/protocol.js +272 -0
- package/lib/webhook.d.ts +14 -0
- package/lib/webhook.js +73 -0
- package/package.json +76 -21
- package/plugin.js +19 -0
- package/schema.json +110 -0
- package/src/client.ts +16 -0
- package/src/endpoint.ts +590 -0
- package/src/index.ts +51 -227
- package/src/lark-runtime-state.ts +7 -0
- package/src/media-upload.ts +69 -0
- package/src/platform-permit.ts +50 -0
- package/src/protocol.ts +396 -0
- package/src/webhook.ts +110 -0
- package/lib/adapter.d.ts +0 -17
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -45
- package/lib/adapter.js.map +0 -1
- package/lib/bot.d.ts +0 -82
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -638
- package/lib/bot.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types.d.ts +0 -63
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/plugin.yml +0 -3
- package/skills/lark/SKILL.md +0 -89
- package/src/adapter.ts +0 -55
- package/src/bot.ts +0 -712
- package/src/types.ts +0 -58
package/PERMITS.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# 飞书 Lark Platform Permits
|
|
2
|
+
|
|
3
|
+
## 入站字段
|
|
4
|
+
|
|
5
|
+
群聊消息经 `getChatInfo`(TTL 60s)比对 `owner_id` / `user_manager_id_list`:
|
|
6
|
+
|
|
7
|
+
| 字段 | 取值 |
|
|
8
|
+
|------|------|
|
|
9
|
+
| `$sender.role` | `owner` · `admin` · `member` |
|
|
10
|
+
| `$sender.permissions` | `chat_owner` · `chat_admin` · `manage_managers` |
|
|
11
|
+
|
|
12
|
+
## Permit 词汇表
|
|
13
|
+
|
|
14
|
+
| `platform(lark,…)` | 含义 |
|
|
15
|
+
|--------------------|------|
|
|
16
|
+
| `chat_owner` | 群主 |
|
|
17
|
+
| `chat_admin` | 群管理员 |
|
|
18
|
+
| `manage_managers` | 可设/撤管理员 |
|
|
19
|
+
|
|
20
|
+
## 工厂映射
|
|
21
|
+
|
|
22
|
+
`scene_admin` → `chat_admin` · `scene_owner` → `chat_owner`
|
package/README.md
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# @zhin.js/adapter-lark
|
|
2
2
|
|
|
3
|
-
Zhin.js 飞书 / Lark
|
|
3
|
+
Zhin.js 飞书 / Lark 适配器(Plugin Runtime),通过 Runtime Host HTTP Webhook 收发消息。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 功能
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
7
|
+
- Webhook 事件接收(`httpHostToken` POST + 可选 verificationToken / encryptKey 签名)
|
|
8
|
+
- URL 验证挑战(`url_verification`)
|
|
9
|
+
- Tenant Access Token 自动刷新
|
|
10
|
+
- 支持飞书与 Lark 国际版 API 基址
|
|
11
|
+
- canonical `markdown` 段编码为 `interactive` 卡片中的 `lark_md`
|
|
12
|
+
- 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
|
|
13
13
|
|
|
14
14
|
## 安装
|
|
15
15
|
|
|
@@ -17,99 +17,85 @@ Zhin.js 飞书 / Lark 适配器,支持飞书机器人的消息收发和群管
|
|
|
17
17
|
pnpm add @zhin.js/adapter-lark
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
##
|
|
20
|
+
## Plugin Runtime
|
|
21
21
|
|
|
22
|
-
- `@zhin.js/
|
|
22
|
+
- `@zhin.js/adapter` — 约定式 `adapters/lark/index.ts`(`defineAdapter`)
|
|
23
|
+
- `@zhin.js/core` — `Endpoint.emit(...)` 入站、`outboundMessageToken` 出站
|
|
24
|
+
- `@zhin.js/host-http` — `httpHostToken` 注册 Webhook 路由(**非** legacy host-router/Koa)
|
|
25
|
+
- `zhin.js` — `plugin.ts`(`definePlugin`)
|
|
26
|
+
- 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
入站:`gateway.receive({ conversation, message: { conversation, id }, content: text, sender, metadata })`
|
|
29
|
+
出站:`send({ conversation, payload })` → `im/v1/messages`
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
# zhin.config.yml
|
|
28
|
-
bots:
|
|
29
|
-
- context: lark
|
|
30
|
-
name: my-lark-bot
|
|
31
|
-
appId: cli_xxxxxxxxxxxx
|
|
32
|
-
appSecret: xxxxxxxxxxxxxxxxxxxxxxxx
|
|
33
|
-
webhookPath: /lark/webhook
|
|
34
|
-
# 可选配置
|
|
35
|
-
# encryptKey: your-encrypt-key
|
|
36
|
-
# verificationToken: your-token
|
|
37
|
-
# isFeishu: true # 使用飞书 API(默认)
|
|
38
|
-
# apiBaseUrl: https://open.feishu.cn/open-apis # 自定义 API 地址
|
|
39
|
-
|
|
40
|
-
plugins:
|
|
41
|
-
- "@zhin.js/adapter-lark"
|
|
42
|
-
- "@zhin.js/host-router"
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
或使用 TypeScript 配置:
|
|
46
|
-
|
|
47
|
-
```typescript
|
|
48
|
-
import { defineConfig } from 'zhin.js'
|
|
49
|
-
|
|
50
|
-
export default defineConfig({
|
|
51
|
-
bots: [
|
|
52
|
-
{
|
|
53
|
-
context: 'lark',
|
|
54
|
-
name: 'my-lark-bot',
|
|
55
|
-
appId: process.env.LARK_APP_ID!,
|
|
56
|
-
appSecret: process.env.LARK_APP_SECRET!,
|
|
57
|
-
webhookPath: '/lark/webhook',
|
|
58
|
-
}
|
|
59
|
-
],
|
|
60
|
-
plugins: ['@zhin.js/adapter-lark', '@zhin.js/host-router']
|
|
61
|
-
})
|
|
62
|
-
```
|
|
31
|
+
入站 `metadata.mentioned`:**未接线**。消息事件的 `mentions[]` 元素含 `id.open_id`,但本适配器拿不到 bot 自身的 open_id——配置(`appId` / `appSecret` / `id` 等)不含 bot open_id,代码也未调用 `bot/v3/info` 获取应用信息,故无可靠判据比对 mentions。
|
|
63
32
|
|
|
64
|
-
##
|
|
33
|
+
## 前置条件
|
|
65
34
|
|
|
66
|
-
|
|
35
|
+
1. 在 [飞书开放平台](https://open.feishu.cn/)(或 Lark)创建企业自建应用
|
|
36
|
+
2. 获取 **App ID**、**App Secret**
|
|
37
|
+
3. 启用机器人能力并配置事件订阅 URL:`https://your-domain/lark/webhook`
|
|
38
|
+
4. Runtime Host(`http`)须已 listen,Webhook 才可达
|
|
67
39
|
|
|
68
|
-
|
|
69
|
-
import { usePlugin, MessageCommand } from 'zhin.js'
|
|
40
|
+
必填字段(`endpoints[i]`):`id`、`appId`、`appSecret`。
|
|
70
41
|
|
|
71
|
-
|
|
42
|
+
## 最小配置
|
|
72
43
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
44
|
+
```yaml
|
|
45
|
+
# zhin.config.yml(Plugin Runtime)
|
|
46
|
+
plugins:
|
|
47
|
+
lark:
|
|
48
|
+
webhookPath: /lark/webhook # 可选,默认 /lark/webhook
|
|
49
|
+
isFeishu: true # 可选,默认 true
|
|
50
|
+
# apiBaseUrl: https://open.feishu.cn/open-apis
|
|
51
|
+
endpoints:
|
|
52
|
+
- id: my-lark-bot
|
|
53
|
+
appId: ${LARK_APP_ID}
|
|
54
|
+
appSecret: ${LARK_APP_SECRET}
|
|
55
|
+
# encryptKey: ${LARK_ENCRYPT_KEY} # 可选
|
|
56
|
+
# verificationToken: ${LARK_VERIFY_TOKEN} # 可选
|
|
80
57
|
```
|
|
81
58
|
|
|
82
|
-
|
|
59
|
+
根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-lark`(`instanceKey: lark`)。
|
|
83
60
|
|
|
84
|
-
|
|
85
|
-
import { usePlugin } from 'zhin.js'
|
|
61
|
+
## 环境变量
|
|
86
62
|
|
|
87
|
-
|
|
63
|
+
| 变量 | 说明 |
|
|
64
|
+
|------|------|
|
|
65
|
+
| `LARK_APP_ID` | 示例中由 YAML `${LARK_APP_ID}` 引用的 App ID;变量名可自行定义 |
|
|
66
|
+
| `LARK_APP_SECRET` | 示例中由 YAML `${LARK_APP_SECRET}` 引用的 App Secret;变量名可自行定义 |
|
|
88
67
|
|
|
89
|
-
|
|
90
|
-
if (message.$adapter === 'lark') {
|
|
91
|
-
console.log('收到飞书消息:', message.$content)
|
|
92
|
-
}
|
|
93
|
-
await next()
|
|
94
|
-
})
|
|
95
|
-
```
|
|
68
|
+
## 消息类型映射
|
|
96
69
|
|
|
97
|
-
|
|
70
|
+
| 飞书类型 | 入站 content(文本摘要) | 出站 wire |
|
|
71
|
+
|----------|--------------------------|-----------|
|
|
72
|
+
| text | 原文 | text |
|
|
73
|
+
| markdown | 原文 | interactive(`lark_md`) |
|
|
74
|
+
| image | `[image]` | image(需 `file_key`) |
|
|
75
|
+
| file | `[file: name]` | file |
|
|
76
|
+
| audio / video / sticker | `[audio]` / `[video]` / `[sticker]` | — |
|
|
77
|
+
| card | — | interactive |
|
|
98
78
|
|
|
99
|
-
|
|
79
|
+
## Agent 工具
|
|
100
80
|
|
|
101
|
-
|
|
81
|
+
`tools/` 目录提供 get_user、群聊、管理员、上传文件等 Tool。工具声明 `adapter: 'lark'` 后,通过惰性的 `context.$client` 自动取得当前操作的 `LarkClient`;无需把 Endpoint id 暴露给模型。
|
|
102
82
|
|
|
103
|
-
|
|
83
|
+
## 平台权限(platform permit)
|
|
104
84
|
|
|
105
|
-
|
|
85
|
+
`plugin.ts` 在 generation setup 注册 `src/platform-permit.ts` checker,并在 dispose 注销;CapabilityIngress 与 ToolSystem 统一经 Core `canAccessTool()` 消费工具权限。
|
|
106
86
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
87
|
+
## 测试
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
pnpm --filter @zhin.js/adapter-lark build
|
|
91
|
+
pnpm --filter @zhin.js/adapter-lark test
|
|
92
|
+
```
|
|
112
93
|
|
|
113
|
-
##
|
|
94
|
+
## 故障排查
|
|
114
95
|
|
|
115
|
-
|
|
96
|
+
| 现象 | 排查 |
|
|
97
|
+
| --- | --- |
|
|
98
|
+
| URL 验证失败 | 检查公网 HTTPS、`webhookPath`、verification token 与 encrypt key |
|
|
99
|
+
| Tenant Token 获取失败 | 检查 `appId`、`appSecret` 与应用版本是否已发布 |
|
|
100
|
+
| 群里 @机器人不触发 AI | 当前无法可靠判定 bot open_id;使用显式 AI 前缀 |
|
|
101
|
+
| 能收不能发 | 检查机器人消息权限、可见范围与应用是否已加入群聊 |
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
/**
|
|
3
|
+
* Convention entry: discover `adapters/lark/index.ts` → defineAdapter.
|
|
4
|
+
*/
|
|
5
|
+
import { defineAdapter } from 'zhin.js/adapter';
|
|
6
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
7
|
+
import { LarkEndpoint } from "../../lib/endpoint.js";
|
|
8
|
+
import { resolveLarkConfig, } from "../../lib/protocol.js";
|
|
9
|
+
import { larkRuntimeStateToken } from "../../lib/lark-runtime-state.js";
|
|
10
|
+
export { LarkEndpoint } from "../../lib/endpoint.js";
|
|
11
|
+
export default defineAdapter({
|
|
12
|
+
capabilities: ['inbound', 'outbound'],
|
|
13
|
+
operations: ['recall'],
|
|
14
|
+
// image 段 canonical MediaRef 经 /im/v1/images 物化为 image_key
|
|
15
|
+
// (base64 解码 / path 读盘 / url 下载后上传,kind=file 平台引用直通);
|
|
16
|
+
// canonical Markdown 由 endpoint codec 转为 lark_md 消息卡片;
|
|
17
|
+
// 卡片交互未接入出站通道,交互段降级纯文本。
|
|
18
|
+
segments: {
|
|
19
|
+
outboundMedia: ['url', 'upload'],
|
|
20
|
+
interactive: 'text',
|
|
21
|
+
markdown: 'native',
|
|
22
|
+
},
|
|
23
|
+
create(context) {
|
|
24
|
+
const config = resolveLarkConfig(context.config);
|
|
25
|
+
// 注册到插件运行时状态(lark endpoint list 的"运行中"数据源)
|
|
26
|
+
context.use(larkRuntimeStateToken).endpoints.set(config.id, {
|
|
27
|
+
id: config.id,
|
|
28
|
+
mode: 'webhook',
|
|
29
|
+
});
|
|
30
|
+
return new LarkEndpoint({
|
|
31
|
+
id: context.id,
|
|
32
|
+
http: context.use(httpHostToken),
|
|
33
|
+
config,
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convention entry: discover `adapters/lark/index.ts` → defineAdapter.
|
|
3
|
+
*/
|
|
4
|
+
import { defineAdapter } from 'zhin.js/adapter';
|
|
5
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
6
|
+
import { LarkEndpoint } from '../../src/endpoint.js';
|
|
7
|
+
import {
|
|
8
|
+
resolveLarkConfig,
|
|
9
|
+
type LarkEndpointConfig,
|
|
10
|
+
} from '../../src/protocol.js';
|
|
11
|
+
import { larkRuntimeStateToken } from '../../src/lark-runtime-state.js';
|
|
12
|
+
|
|
13
|
+
export { LarkEndpoint } from '../../src/endpoint.js';
|
|
14
|
+
export type { LarkEndpointOptions, LarkFetch } from '../../src/endpoint.js';
|
|
15
|
+
|
|
16
|
+
export default defineAdapter<LarkEndpointConfig>({
|
|
17
|
+
capabilities: ['inbound', 'outbound'],
|
|
18
|
+
operations: ['recall'],
|
|
19
|
+
// image 段 canonical MediaRef 经 /im/v1/images 物化为 image_key
|
|
20
|
+
// (base64 解码 / path 读盘 / url 下载后上传,kind=file 平台引用直通);
|
|
21
|
+
// canonical Markdown 由 endpoint codec 转为 lark_md 消息卡片;
|
|
22
|
+
// 卡片交互未接入出站通道,交互段降级纯文本。
|
|
23
|
+
segments: {
|
|
24
|
+
outboundMedia: ['url', 'upload'],
|
|
25
|
+
interactive: 'text',
|
|
26
|
+
markdown: 'native',
|
|
27
|
+
},
|
|
28
|
+
create(context) {
|
|
29
|
+
const config = resolveLarkConfig(context.config);
|
|
30
|
+
// 注册到插件运行时状态(lark endpoint list 的"运行中"数据源)
|
|
31
|
+
context.use(larkRuntimeStateToken).endpoints.set(config.id, {
|
|
32
|
+
id: config.id,
|
|
33
|
+
mode: 'webhook',
|
|
34
|
+
});
|
|
35
|
+
return new LarkEndpoint({
|
|
36
|
+
id: context.id,
|
|
37
|
+
http: context.use(httpHostToken),
|
|
38
|
+
config,
|
|
39
|
+
});
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "LARK Platform Agent",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Handles lark platform-specific operations and progressively loads only the required platform Skill.",
|
|
5
|
+
"trigger_rules": {
|
|
6
|
+
"file_patterns": [],
|
|
7
|
+
"keywords": [
|
|
8
|
+
"lark",
|
|
9
|
+
"adapter:lark"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"entry_points": [
|
|
13
|
+
"system.md",
|
|
14
|
+
"boundaries.md",
|
|
15
|
+
"conventions.md"
|
|
16
|
+
],
|
|
17
|
+
"platforms": [
|
|
18
|
+
"lark"
|
|
19
|
+
]
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lark
|
|
3
|
+
platforms: [lark]
|
|
4
|
+
description: 飞书用户查询、群聊生命周期、管理员和文件上传能力。
|
|
5
|
+
keywords: [lark, 飞书, user, chat, manager, file]
|
|
6
|
+
tags: [adapter, collaboration]
|
|
7
|
+
tools:
|
|
8
|
+
- get_user
|
|
9
|
+
- create_chat
|
|
10
|
+
- update_chat
|
|
11
|
+
- add_members
|
|
12
|
+
- set_managers
|
|
13
|
+
- remove_managers
|
|
14
|
+
- dissolve_chat
|
|
15
|
+
- upload_file
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# 飞书
|
|
19
|
+
|
|
20
|
+
涉及成员的操作先用 `get_user` 取得稳定用户 ID。创建群聊后可添加成员、更新群设置和维护管理员;解散群聊属于不可逆操作,应依照 Tool 审批策略执行。文件发送前先用 `upload_file` 获得文件标识。
|
|
21
|
+
|
|
22
|
+
当前 Agent Tool 不提供当前群成员列表、踢人或独立群详情查询。
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '添加飞书群成员',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'lark',
|
|
12
|
+
tags: ['lark'],
|
|
13
|
+
permissions: [platformPermission('lark', 'chat_admin')],
|
|
14
|
+
async execute({ chat_id, user_ids }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
const success = await endpoint.addChatMembers(chat_id, user_ids.split(','));
|
|
17
|
+
return { success, message: success ? '成员添加成功' : '添加失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ chat_id: string; user_ids: string }>({
|
|
6
|
+
description: '添加飞书群成员',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'lark',
|
|
12
|
+
tags: ['lark'],
|
|
13
|
+
permissions: [platformPermission('lark', 'chat_admin')],
|
|
14
|
+
async execute({ chat_id, user_ids }: { chat_id: string; user_ids: string }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
const success = await endpoint.addChatMembers(chat_id, user_ids.split(','));
|
|
17
|
+
return { success, message: success ? '成员添加成功' : '添加失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export default defineAgentTool({
|
|
5
|
+
description: '创建飞书群聊',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
name: z.string().describe('群名'),
|
|
8
|
+
members: z.string().describe('成员 open_id 列表,逗号分隔'),
|
|
9
|
+
owner: z.string().optional().describe('群主 open_id(可选)'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'lark',
|
|
12
|
+
tags: ['lark'],
|
|
13
|
+
async execute({ name, members, owner }, context) {
|
|
14
|
+
const endpoint = context.$client;
|
|
15
|
+
const chatId = await endpoint.createChat(name, members.split(','), owner);
|
|
16
|
+
return { success: !!chatId, chat_id: chatId, message: chatId ? `群聊创建成功: ${chatId}` : '创建失败' };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export default defineAgentTool<{ name: string; members: string; owner?: string }>({
|
|
4
|
+
description: '创建飞书群聊',
|
|
5
|
+
inputSchema: z.object({
|
|
6
|
+
name: z.string().describe('群名'),
|
|
7
|
+
members: z.string().describe('成员 open_id 列表,逗号分隔'),
|
|
8
|
+
owner: z.string().optional().describe('群主 open_id(可选)'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'lark',
|
|
11
|
+
tags: ['lark'],
|
|
12
|
+
async execute({ name, members, owner }: { name: string; members: string; owner?: string }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
const chatId = await endpoint.createChat(name, members.split(','), owner);
|
|
15
|
+
return { success: !!chatId, chat_id: chatId, message: chatId ? `群聊创建成功: ${chatId}` : '创建失败' };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export default defineAgentTool({
|
|
5
|
+
description: '解散飞书群聊(需要群主权限)',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'lark',
|
|
10
|
+
tags: ['lark'],
|
|
11
|
+
async execute({ chat_id }, context) {
|
|
12
|
+
const endpoint = context.$client;
|
|
13
|
+
const success = await endpoint.dissolveChat(chat_id);
|
|
14
|
+
return { success, message: success ? '群聊已解散' : '解散失败' };
|
|
15
|
+
},
|
|
16
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export default defineAgentTool<{ chat_id: string }>({
|
|
4
|
+
description: '解散飞书群聊(需要群主权限)',
|
|
5
|
+
inputSchema: z.object({
|
|
6
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
7
|
+
}),
|
|
8
|
+
adapter: 'lark',
|
|
9
|
+
tags: ['lark'],
|
|
10
|
+
async execute({ chat_id }: { chat_id: string }, context) {
|
|
11
|
+
const endpoint = context.$client;
|
|
12
|
+
const success = await endpoint.dissolveChat(chat_id);
|
|
13
|
+
return { success, message: success ? '群聊已解散' : '解散失败' };
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export default defineAgentTool({
|
|
5
|
+
description: '获取飞书用户信息',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
user_id: z.string().describe('用户 ID (open_id)'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'lark',
|
|
10
|
+
tags: ['lark'],
|
|
11
|
+
async execute({ user_id }, context) {
|
|
12
|
+
const endpoint = context.$client;
|
|
13
|
+
return await endpoint.getUserInfo(user_id);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{ user_id: string }>({
|
|
5
|
+
description: '获取飞书用户信息',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
user_id: z.string().describe('用户 ID (open_id)'),
|
|
8
|
+
}),
|
|
9
|
+
adapter: 'lark',
|
|
10
|
+
tags: ['lark'],
|
|
11
|
+
async execute({ user_id }: { user_id: string }, context) {
|
|
12
|
+
const endpoint = context.$client;
|
|
13
|
+
return await endpoint.getUserInfo(user_id);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
16
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '移除飞书群管理员',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'lark',
|
|
12
|
+
tags: ['lark'],
|
|
13
|
+
permissions: [platformPermission('lark', 'manage_managers')],
|
|
14
|
+
async execute({ chat_id, user_ids }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
const success = await endpoint.removeChatManagers(chat_id, user_ids.split(','));
|
|
17
|
+
return { success, message: success ? '管理员移除成功' : '移除失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ chat_id: string; user_ids: string }>({
|
|
6
|
+
description: '移除飞书群管理员',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'lark',
|
|
12
|
+
tags: ['lark'],
|
|
13
|
+
permissions: [platformPermission('lark', 'manage_managers')],
|
|
14
|
+
async execute({ chat_id, user_ids }: { chat_id: string; user_ids: string }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
const success = await endpoint.removeChatManagers(chat_id, user_ids.split(','));
|
|
17
|
+
return { success, message: success ? '管理员移除成功' : '移除失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '设置飞书群管理员',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'lark',
|
|
12
|
+
tags: ['lark'],
|
|
13
|
+
permissions: [platformPermission('lark', 'manage_managers')],
|
|
14
|
+
async execute({ chat_id, user_ids }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
const success = await endpoint.setChatManagers(chat_id, user_ids.split(','));
|
|
17
|
+
return { success, message: success ? '管理员设置成功' : '设置失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ chat_id: string; user_ids: string }>({
|
|
6
|
+
description: '设置飞书群管理员',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
10
|
+
}),
|
|
11
|
+
adapter: 'lark',
|
|
12
|
+
tags: ['lark'],
|
|
13
|
+
permissions: [platformPermission('lark', 'manage_managers')],
|
|
14
|
+
async execute({ chat_id, user_ids }: { chat_id: string; user_ids: string }, context) {
|
|
15
|
+
const endpoint = context.$client;
|
|
16
|
+
const success = await endpoint.setChatManagers(chat_id, user_ids.split(','));
|
|
17
|
+
return { success, message: success ? '管理员设置成功' : '设置失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
5
|
+
export default defineAgentTool({
|
|
6
|
+
description: '更新飞书群聊信息(群名、描述)',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
name: z.string().optional().describe('新群名(可选)'),
|
|
10
|
+
description: z.string().optional().describe('新描述(可选)'),
|
|
11
|
+
}),
|
|
12
|
+
adapter: 'lark',
|
|
13
|
+
tags: ['lark'],
|
|
14
|
+
permissions: [platformPermission('lark', 'chat_admin')],
|
|
15
|
+
async execute({ chat_id, name, description }, context) {
|
|
16
|
+
const endpoint = context.$client;
|
|
17
|
+
const success = await endpoint.updateChatInfo(chat_id, { name, description });
|
|
18
|
+
return { success, message: success ? '群信息更新成功' : '更新失败' };
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { platformPermission } from '@zhin.js/permission';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ chat_id: string; name?: string; description?: string }>({
|
|
6
|
+
description: '更新飞书群聊信息(群名、描述)',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
name: z.string().optional().describe('新群名(可选)'),
|
|
10
|
+
description: z.string().optional().describe('新描述(可选)'),
|
|
11
|
+
}),
|
|
12
|
+
adapter: 'lark',
|
|
13
|
+
tags: ['lark'],
|
|
14
|
+
permissions: [platformPermission('lark', 'chat_admin')],
|
|
15
|
+
async execute({ chat_id, name, description }: { chat_id: string; name?: string; description?: string }, context) {
|
|
16
|
+
const endpoint = context.$client;
|
|
17
|
+
const success = await endpoint.updateChatInfo(chat_id, { name, description });
|
|
18
|
+
return { success, message: success ? '群信息更新成功' : '更新失败' };
|
|
19
|
+
},
|
|
20
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Generated by build-plugin-runtime-entries.mjs. Do not edit.
|
|
2
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export default defineAgentTool({
|
|
5
|
+
description: '上传文件到飞书(image/file/video/audio)',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
file_path: z.string().describe('本地文件路径'),
|
|
8
|
+
file_type: z.enum(['image', 'file', 'video', 'audio']).default('file').describe('飞书文件类型'),
|
|
9
|
+
}),
|
|
10
|
+
adapter: 'lark',
|
|
11
|
+
tags: ['lark'],
|
|
12
|
+
async execute({ file_path, file_type }, context) {
|
|
13
|
+
const endpoint = context.$client;
|
|
14
|
+
const result = await endpoint.uploadFile(file_path, file_type);
|
|
15
|
+
return { success: true, file_key: result, message: `文件已上传,file_key: ${result}` };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/tool';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
export default defineAgentTool<{
|
|
5
|
+
file_path: string;
|
|
6
|
+
file_type: 'image' | 'file' | 'video' | 'audio';
|
|
7
|
+
}>({
|
|
8
|
+
description: '上传文件到飞书(image/file/video/audio)',
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
file_path: z.string().describe('本地文件路径'),
|
|
11
|
+
file_type: z.enum(['image', 'file', 'video', 'audio']).default('file').describe('飞书文件类型'),
|
|
12
|
+
}),
|
|
13
|
+
adapter: 'lark',
|
|
14
|
+
tags: ['lark'],
|
|
15
|
+
async execute({ file_path, file_type }: {
|
|
16
|
+
file_path: string;
|
|
17
|
+
file_type: 'image' | 'file' | 'video' | 'audio';
|
|
18
|
+
}, context) {
|
|
19
|
+
const endpoint = context.$client;
|
|
20
|
+
const result = await endpoint.uploadFile(file_path, file_type);
|
|
21
|
+
return { success: true, file_key: result, message: `文件已上传,file_key: ${result}` };
|
|
22
|
+
},
|
|
23
|
+
});
|