@zhin.js/adapter-lark 4.0.1 → 4.0.3
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 +48 -0
- package/README.md +59 -84
- package/adapters/lark.ts +26 -0
- package/agent/tools/add_members.ts +22 -0
- package/agent/tools/create_chat.ts +20 -0
- package/agent/tools/dissolve_chat.ts +18 -0
- package/agent/tools/get_user.ts +18 -0
- package/agent/tools/remove_managers.ts +22 -0
- package/agent/tools/set_managers.ts +22 -0
- package/agent/tools/update_chat.ts +23 -0
- package/agent/tools/upload_file.ts +27 -0
- package/lib/endpoint.d.ts +41 -72
- package/lib/endpoint.js +219 -563
- package/lib/index.d.ts +5 -15
- package/lib/index.js +5 -216
- package/lib/lark-agent-deps.d.ts +27 -0
- package/lib/lark-agent-deps.js +30 -0
- package/lib/platform-permit.d.ts +1 -2
- package/lib/platform-permit.js +4 -2
- package/lib/protocol.d.ts +111 -0
- package/lib/protocol.js +204 -0
- package/lib/webhook.d.ts +13 -0
- package/lib/webhook.js +67 -0
- package/package.json +50 -21
- package/plugin.ts +12 -0
- package/schema.json +25 -0
- package/src/endpoint.ts +354 -705
- package/src/index.ts +46 -236
- package/src/lark-agent-deps.ts +62 -0
- package/src/platform-permit.ts +1 -2
- package/src/protocol.ts +332 -0
- package/src/webhook.ts +101 -0
- package/lib/adapter.d.ts +0 -20
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -48
- package/lib/adapter.js.map +0 -1
- package/lib/endpoint.d.ts.map +0 -1
- package/lib/endpoint.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/platform-permit.d.ts.map +0 -1
- package/lib/platform-permit.js.map +0 -1
- package/lib/segment-mapper.d.ts +0 -2
- package/lib/segment-mapper.d.ts.map +0 -1
- package/lib/segment-mapper.js +0 -2
- package/lib/segment-mapper.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/src/adapter.ts +0 -57
- package/src/segment-mapper.ts +0 -1
- package/src/types.ts +0 -58
- /package/{skills/lark → agent}/PERMITS.md +0 -0
- /package/{skills/lark/SKILL.md → agent/skills/lark.md} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,53 @@
|
|
|
1
1
|
# @zhin.js/adapter-lark
|
|
2
2
|
|
|
3
|
+
## 4.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- cc5c94d: 约定式插件运行时迁移(breaking):插件与适配器由 `usePlugin()` / `extends Adapter` 迁移为 `definePlugin` / `defineAdapter` + `plugin.ts` + 约定目录(`adapters/`、`commands/`、`components/`、`tools/` 等)。
|
|
8
|
+
|
|
9
|
+
- 新增约定式运行时包:`@zhin.js/plugin-runtime`、`@zhin.js/adapter`、`@zhin.js/runtime`、`@zhin.js/host-http`(首版 1.0.0 走 init-publish,不在本 changeset 内 bump)。
|
|
10
|
+
- 全部 20 个平台适配器改为约定式 `defineAdapter`,旧 `usePlugin` / `extends Adapter` / `segment-mapper` 生产入口已删除;onebot11 反向 WSS、onebot12 webhook/wss、milky sse/webhook/wss、satori webhook、kook webhook、qq webhook/middleware 等 slice 1 推迟的连接模式已补齐。
|
|
11
|
+
- 游戏 / 工具 / 服务插件同步迁移到约定目录结构。
|
|
12
|
+
- CLI 增加 plugin-runtime host installer(http/database/outbound/schedule/console 等)。
|
|
13
|
+
|
|
14
|
+
后续加固(同批):
|
|
15
|
+
|
|
16
|
+
- CLI:`zhin runtime start --daemon`(pidfile/崩溃拉起/风暴保护),orphan watchdog 防僵尸进程;legacy `zhin dev` / `zhin start` 已移除(含 `zhin restart`),`zhin stop` 兼容新 daemon。
|
|
17
|
+
- 安全:builtin 工具统一走 `security/policy-facade.ts` 的 `runToolPolicies`(声明式策略表,deny 优先);审计日志 close flush + 背压队列;`splitCompoundCommand` 引号感知、`extractCommandName` 去引号堵绕过。
|
|
18
|
+
- 日志:Logger 双堆栈修复、本地时区、`getLogger` 挂树(`setLevel` 递归生效)、第三方库(log4js/discord)桥接、启动人读总结。
|
|
19
|
+
- 结构:`plugins/games/shared` 迁为 `packages/game-kit`(`@zhin.js/game-kit`);死目录 `plugins/adapters/common` 删除。
|
|
20
|
+
- 脚手架:`create-zhin-app` / `zhin new` / scaffold-wizard 生成物改为 Plugin Runtime 形态(minimal-bot 同构,新配置格式)。
|
|
21
|
+
- Console:endpoint.list 真实名称与 phase、schema:get-all 按 instanceKey 映射、db:\* 接 DatabaseHost。
|
|
22
|
+
|
|
23
|
+
注:按仓库发布惯例(见 1bb345dd2),本次 breaking 迁移统一使用 patch,避免 zhin.js 5.0 级联。
|
|
24
|
+
|
|
25
|
+
- Updated dependencies [16ec4e8]
|
|
26
|
+
- Updated dependencies [cc5c94d]
|
|
27
|
+
- Updated dependencies [447f3e2]
|
|
28
|
+
- @zhin.js/core@1.3.5
|
|
29
|
+
- @zhin.js/agent@1.0.4
|
|
30
|
+
- @zhin.js/host-http@1.0.1
|
|
31
|
+
- zhin.js@4.1.3
|
|
32
|
+
- @zhin.js/logger@1.0.75
|
|
33
|
+
- @zhin.js/plugin-runtime@1.0.1
|
|
34
|
+
- @zhin.js/adapter@1.0.1
|
|
35
|
+
|
|
36
|
+
## 4.0.2
|
|
37
|
+
|
|
38
|
+
### Patch Changes
|
|
39
|
+
|
|
40
|
+
- 872c583: Slack 适配器 Phase 1/2:mrkdwn 出站、长消息切分、斜杠/按钮 ephemeral 反馈、入站 mrkdwn→Markdown、editMessage 对齐 core。
|
|
41
|
+
|
|
42
|
+
Logger 表格日志与 string-width 列宽;Agent AI Handler 框线表格与 introspection/MCP 导出;Core side-event 归一化;Schedule 时区规划;多适配器 side-event 与 API surface 更新。
|
|
43
|
+
|
|
44
|
+
- 872c583: fix: 代码格式优化
|
|
45
|
+
- Updated dependencies [872c583]
|
|
46
|
+
- Updated dependencies [872c583]
|
|
47
|
+
- @zhin.js/agent@1.0.3
|
|
48
|
+
- @zhin.js/host-router@2.0.3
|
|
49
|
+
- zhin.js@4.1.2
|
|
50
|
+
|
|
3
51
|
## 4.0.1
|
|
4
52
|
|
|
5
53
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
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
|
-
- 群管理 AI 工具(通过包内 `skills/lark/SKILL.md` 与 `addTool` 暴露给 AI)
|
|
7
|
+
- Webhook 事件接收(`httpHostToken` POST + 可选 verificationToken / encryptKey 签名)
|
|
8
|
+
- URL 验证挑战(`url_verification`)
|
|
9
|
+
- Tenant Access Token 自动刷新
|
|
10
|
+
- 支持飞书与 Lark 国际版 API 基址
|
|
11
|
+
- 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
|
|
13
12
|
|
|
14
13
|
## 安装
|
|
15
14
|
|
|
@@ -17,99 +16,75 @@ Zhin.js 飞书 / Lark 适配器,支持飞书机器人的消息收发和群管
|
|
|
17
16
|
pnpm add @zhin.js/adapter-lark
|
|
18
17
|
```
|
|
19
18
|
|
|
20
|
-
##
|
|
19
|
+
## Plugin Runtime
|
|
21
20
|
|
|
22
|
-
- `@zhin.js/
|
|
21
|
+
- `@zhin.js/adapter` — 约定式 `adapters/lark.ts`(`defineAdapter`)
|
|
22
|
+
- `@zhin.js/core` — `messageGatewayToken` 入站/出站
|
|
23
|
+
- `@zhin.js/host-http` — `httpHostToken` 注册 Webhook 路由(**非** legacy host-router/Koa)
|
|
24
|
+
- `@zhin.js/plugin-runtime` — `plugin.ts`(`definePlugin`)
|
|
25
|
+
- 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`
|
|
23
26
|
|
|
24
|
-
|
|
27
|
+
入站:`gateway.receive({ adapter, target: chat_id, content: text, sender, metadata })`
|
|
28
|
+
出站:`send({ target, payload })` → `im/v1/messages`
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
# zhin.config.yml
|
|
28
|
-
endpoints:
|
|
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
|
-
endpoints: [
|
|
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
|
-
```
|
|
30
|
+
入站 `metadata.mentioned`:**未接线**。消息事件的 `mentions[]` 元素含 `id.open_id`,但本适配器拿不到 bot 自身的 open_id——配置(`appId` / `appSecret` / `name` 等)不含 bot open_id,代码也未调用 `bot/v3/info` 获取应用信息,故无可靠判据比对 mentions。
|
|
63
31
|
|
|
64
|
-
##
|
|
32
|
+
## 前置条件
|
|
65
33
|
|
|
66
|
-
|
|
34
|
+
1. 在 [飞书开放平台](https://open.feishu.cn/)(或 Lark)创建企业自建应用
|
|
35
|
+
2. 获取 **App ID**、**App Secret**
|
|
36
|
+
3. 启用机器人能力并配置事件订阅 URL:`https://your-domain/lark/webhook`
|
|
37
|
+
4. Runtime Host(`http`)须已 listen,Webhook 才可达
|
|
67
38
|
|
|
68
|
-
|
|
69
|
-
import { usePlugin, MessageCommand } from 'zhin.js'
|
|
39
|
+
必填字段:`appId`、`appSecret`。
|
|
70
40
|
|
|
71
|
-
|
|
41
|
+
## 最小配置
|
|
72
42
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
43
|
+
```yaml
|
|
44
|
+
# zhin.config.yml(Plugin Runtime)
|
|
45
|
+
plugins:
|
|
46
|
+
lark:
|
|
47
|
+
name: my-lark-bot
|
|
48
|
+
appId: ${LARK_APP_ID}
|
|
49
|
+
appSecret: ${LARK_APP_SECRET}
|
|
50
|
+
webhookPath: /lark/webhook # 可选,默认 /lark/webhook
|
|
51
|
+
encryptKey: ${LARK_ENCRYPT_KEY} # 可选
|
|
52
|
+
verificationToken: ${LARK_VERIFY_TOKEN} # 可选
|
|
53
|
+
isFeishu: true # 可选,默认 true
|
|
54
|
+
# apiBaseUrl: https://open.feishu.cn/open-apis
|
|
80
55
|
```
|
|
81
56
|
|
|
82
|
-
|
|
57
|
+
根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-lark`(`instanceKey: lark`)。
|
|
83
58
|
|
|
84
|
-
|
|
85
|
-
import { usePlugin } from 'zhin.js'
|
|
59
|
+
## 环境变量
|
|
86
60
|
|
|
87
|
-
|
|
61
|
+
| 变量 | 说明 |
|
|
62
|
+
|------|------|
|
|
63
|
+
| `LARK_APP_ID` | 应用 App ID |
|
|
64
|
+
| `LARK_APP_SECRET` | 应用 App Secret |
|
|
65
|
+
| `LARK_BOT_NAME` | 默认 endpoint 名称(可选) |
|
|
88
66
|
|
|
89
|
-
|
|
90
|
-
if (message.$adapter === 'lark') {
|
|
91
|
-
console.log('收到飞书消息:', message.$content)
|
|
92
|
-
}
|
|
93
|
-
await next()
|
|
94
|
-
})
|
|
95
|
-
```
|
|
67
|
+
## 消息类型映射
|
|
96
68
|
|
|
97
|
-
|
|
69
|
+
| 飞书类型 | 入站 content(文本摘要) | 出站 wire |
|
|
70
|
+
|----------|--------------------------|-----------|
|
|
71
|
+
| text | 原文 | text |
|
|
72
|
+
| image | `[image]` | image(需 `file_key`) |
|
|
73
|
+
| file | `[file: name]` | file |
|
|
74
|
+
| audio / video / sticker | `[audio]` / `[video]` / `[sticker]` | — |
|
|
75
|
+
| card | — | interactive |
|
|
98
76
|
|
|
99
|
-
|
|
77
|
+
## Agent 工具
|
|
100
78
|
|
|
101
|
-
-
|
|
79
|
+
`agent/` 目录保留(get_user、群聊、管理员、上传文件等)。Endpoint 在 `start` 时自注册到 `lark-agent-deps`。
|
|
102
80
|
|
|
103
|
-
|
|
81
|
+
## 平台权限(platform permit)
|
|
104
82
|
|
|
105
|
-
|
|
83
|
+
`plugin.ts` 在 generation setup 注册 `src/platform-permit.ts` checker,并在 dispose 注销;CapabilityIngress 与 ToolSystem 统一经 Core `canAccessTool()` 消费工具权限。
|
|
106
84
|
|
|
107
|
-
|
|
108
|
-
2. 创建应用并获取 `App ID` 和 `App Secret`
|
|
109
|
-
3. 配置事件回调 URL:`http://your-server:8086/api/lark/webhook`
|
|
110
|
-
4. 订阅 `im.message.receive_v1` 事件
|
|
111
|
-
5. 发布应用
|
|
85
|
+
## 测试
|
|
112
86
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
87
|
+
```bash
|
|
88
|
+
pnpm --filter @zhin.js/adapter-lark build
|
|
89
|
+
pnpm --filter @zhin.js/adapter-lark test
|
|
90
|
+
```
|
package/adapters/lark.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convention entry: discover `adapters/lark.ts` → defineAdapter.
|
|
3
|
+
*/
|
|
4
|
+
import { defineAdapter } from '@zhin.js/adapter';
|
|
5
|
+
import { messageGatewayToken } from '@zhin.js/core/runtime';
|
|
6
|
+
import { httpHostToken } from '@zhin.js/host-http';
|
|
7
|
+
import { LarkEndpoint } from '../src/endpoint.js';
|
|
8
|
+
import {
|
|
9
|
+
resolveLarkConfig,
|
|
10
|
+
type LarkAdapterConfig,
|
|
11
|
+
} from '../src/protocol.js';
|
|
12
|
+
|
|
13
|
+
export { LarkEndpoint } from '../src/endpoint.js';
|
|
14
|
+
export type { LarkEndpointOptions, LarkFetch } from '../src/endpoint.js';
|
|
15
|
+
|
|
16
|
+
export default defineAdapter<LarkAdapterConfig>({
|
|
17
|
+
capabilities: ['inbound', 'outbound'],
|
|
18
|
+
create(context) {
|
|
19
|
+
return new LarkEndpoint({
|
|
20
|
+
id: context.id,
|
|
21
|
+
gateway: context.use(messageGatewayToken),
|
|
22
|
+
http: context.use(httpHostToken),
|
|
23
|
+
config: resolveLarkConfig(context.config),
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
+
import { platformPermit } from '../../src/platform-permit.js';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; user_ids: string }>({
|
|
7
|
+
description: '添加飞书群成员',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
10
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
11
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
12
|
+
}),
|
|
13
|
+
platforms: ['lark'],
|
|
14
|
+
tags: ['lark'],
|
|
15
|
+
permissions: [platformPermit('chat_admin')],
|
|
16
|
+
async execute({ endpoint_id, chat_id, user_ids }: { endpoint_id: string; chat_id: string; user_ids: string }) {
|
|
17
|
+
const endpoint = getLarkAgentDeps().getEndpoint(endpoint_id);
|
|
18
|
+
const success = await endpoint.addChatMembers(chat_id, user_ids.split(','));
|
|
19
|
+
return { success, message: success ? '成员添加成功' : '添加失败' };
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
+
export default defineAgentTool<{ endpoint_id: string; name: string; members: string; owner?: string }>({
|
|
5
|
+
description: '创建飞书群聊',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
8
|
+
name: z.string().describe('群名'),
|
|
9
|
+
members: z.string().describe('成员 open_id 列表,逗号分隔'),
|
|
10
|
+
owner: z.string().optional().describe('群主 open_id(可选)'),
|
|
11
|
+
}),
|
|
12
|
+
platforms: ['lark'],
|
|
13
|
+
tags: ['lark'],
|
|
14
|
+
async execute({ endpoint_id, name, members, owner }: { endpoint_id: string; name: string; members: string; owner?: string }) {
|
|
15
|
+
const endpoint = getLarkAgentDeps().getEndpoint(endpoint_id);
|
|
16
|
+
const chatId = await endpoint.createChat(name, members.split(','), owner);
|
|
17
|
+
return { success: !!chatId, chat_id: chatId, message: chatId ? `群聊创建成功: ${chatId}` : '创建失败' };
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string }>({
|
|
5
|
+
description: '解散飞书群聊(需要群主权限)',
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
8
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
9
|
+
}),
|
|
10
|
+
platforms: ['lark'],
|
|
11
|
+
tags: ['lark'],
|
|
12
|
+
async execute({ endpoint_id, chat_id }: { endpoint_id: string; chat_id: string }) {
|
|
13
|
+
const endpoint = getLarkAgentDeps().getEndpoint(endpoint_id);
|
|
14
|
+
const success = await endpoint.dissolveChat(chat_id);
|
|
15
|
+
return { success, message: success ? '群聊已解散' : '解散失败' };
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{ endpoint_id: string; user_id: string }>({
|
|
6
|
+
description: '获取飞书用户信息',
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
9
|
+
user_id: z.string().describe('用户 ID (open_id)'),
|
|
10
|
+
}),
|
|
11
|
+
platforms: ['lark'],
|
|
12
|
+
tags: ['lark'],
|
|
13
|
+
async execute({ endpoint_id, user_id }: { endpoint_id: string; user_id: string }) {
|
|
14
|
+
const endpoint = getLarkAgentDeps().getEndpoint(endpoint_id);
|
|
15
|
+
return await endpoint.getUserInfo(user_id);
|
|
16
|
+
},
|
|
17
|
+
});
|
|
18
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
+
import { platformPermit } from '../../src/platform-permit.js';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; user_ids: string }>({
|
|
7
|
+
description: '移除飞书群管理员',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
10
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
11
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
12
|
+
}),
|
|
13
|
+
platforms: ['lark'],
|
|
14
|
+
tags: ['lark'],
|
|
15
|
+
permissions: [platformPermit('manage_managers')],
|
|
16
|
+
async execute({ endpoint_id, chat_id, user_ids }: { endpoint_id: string; chat_id: string; user_ids: string }) {
|
|
17
|
+
const endpoint = getLarkAgentDeps().getEndpoint(endpoint_id);
|
|
18
|
+
const success = await endpoint.removeChatManagers(chat_id, user_ids.split(','));
|
|
19
|
+
return { success, message: success ? '管理员移除成功' : '移除失败' };
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
+
import { platformPermit } from '../../src/platform-permit.js';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; user_ids: string }>({
|
|
7
|
+
description: '设置飞书群管理员',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
10
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
11
|
+
user_ids: z.string().describe('用户 open_id 列表,逗号分隔'),
|
|
12
|
+
}),
|
|
13
|
+
platforms: ['lark'],
|
|
14
|
+
tags: ['lark'],
|
|
15
|
+
permissions: [platformPermit('manage_managers')],
|
|
16
|
+
async execute({ endpoint_id, chat_id, user_ids }: { endpoint_id: string; chat_id: string; user_ids: string }) {
|
|
17
|
+
const endpoint = getLarkAgentDeps().getEndpoint(endpoint_id);
|
|
18
|
+
const success = await endpoint.setChatManagers(chat_id, user_ids.split(','));
|
|
19
|
+
return { success, message: success ? '管理员设置成功' : '设置失败' };
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
+
import { platformPermit } from '../../src/platform-permit.js';
|
|
5
|
+
|
|
6
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; name?: string; description?: string }>({
|
|
7
|
+
description: '更新飞书群聊信息(群名、描述)',
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
10
|
+
chat_id: z.string().describe('群聊 ID'),
|
|
11
|
+
name: z.string().optional().describe('新群名(可选)'),
|
|
12
|
+
description: z.string().optional().describe('新描述(可选)'),
|
|
13
|
+
}),
|
|
14
|
+
platforms: ['lark'],
|
|
15
|
+
tags: ['lark'],
|
|
16
|
+
permissions: [platformPermit('chat_admin')],
|
|
17
|
+
async execute({ endpoint_id, chat_id, name, description }: { endpoint_id: string; chat_id: string; name?: string; description?: string }) {
|
|
18
|
+
const endpoint = getLarkAgentDeps().getEndpoint(endpoint_id);
|
|
19
|
+
const success = await endpoint.updateChatInfo(chat_id, { name, description });
|
|
20
|
+
return { success, message: success ? '群信息更新成功' : '更新失败' };
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
+
|
|
5
|
+
export default defineAgentTool<{
|
|
6
|
+
endpoint_id: string;
|
|
7
|
+
file_path: string;
|
|
8
|
+
file_type: 'image' | 'file' | 'video' | 'audio';
|
|
9
|
+
}>({
|
|
10
|
+
description: '上传文件到飞书(image/file/video/audio)',
|
|
11
|
+
inputSchema: z.object({
|
|
12
|
+
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
13
|
+
file_path: z.string().describe('本地文件路径'),
|
|
14
|
+
file_type: z.enum(['image', 'file', 'video', 'audio']).default('file').describe('飞书文件类型'),
|
|
15
|
+
}),
|
|
16
|
+
platforms: ['lark'],
|
|
17
|
+
tags: ['lark'],
|
|
18
|
+
async execute({ endpoint_id, file_path, file_type }: {
|
|
19
|
+
endpoint_id: string;
|
|
20
|
+
file_path: string;
|
|
21
|
+
file_type: 'image' | 'file' | 'video' | 'audio';
|
|
22
|
+
}) {
|
|
23
|
+
const endpoint = getLarkAgentDeps().getEndpoint(endpoint_id);
|
|
24
|
+
const result = await endpoint.uploadFile(file_path, file_type);
|
|
25
|
+
return { success: true, file_key: result, message: `文件已上传,file_key: ${result}` };
|
|
26
|
+
},
|
|
27
|
+
});
|
package/lib/endpoint.d.ts
CHANGED
|
@@ -1,84 +1,53 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
private
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
import type { EndpointInstance } from '@zhin.js/adapter';
|
|
2
|
+
import type { MessageGateway } from '@zhin.js/core/runtime';
|
|
3
|
+
import type { HttpHost } from '@zhin.js/host-http';
|
|
4
|
+
import type { CapabilityId } from '@zhin.js/plugin-runtime';
|
|
5
|
+
import { type LarkMessage, type ResolvedLarkConfig } from './protocol.js';
|
|
6
|
+
export type LarkFetch = (url: string, init?: {
|
|
7
|
+
readonly method?: string;
|
|
8
|
+
readonly headers?: Record<string, string>;
|
|
9
|
+
readonly body?: string | FormData;
|
|
10
|
+
}) => Promise<{
|
|
11
|
+
readonly ok: boolean;
|
|
12
|
+
readonly status: number;
|
|
13
|
+
text(): Promise<string>;
|
|
14
|
+
json(): Promise<unknown>;
|
|
15
|
+
}>;
|
|
16
|
+
export interface LarkEndpointOptions {
|
|
17
|
+
readonly id: CapabilityId;
|
|
18
|
+
readonly gateway: MessageGateway;
|
|
19
|
+
readonly http: HttpHost;
|
|
20
|
+
readonly config: ResolvedLarkConfig;
|
|
21
|
+
readonly fetch?: LarkFetch;
|
|
22
|
+
}
|
|
23
|
+
export declare class LarkEndpoint implements EndpointInstance {
|
|
24
|
+
#private;
|
|
25
|
+
constructor(options: LarkEndpointOptions);
|
|
26
|
+
/** Used by webhook handler. */
|
|
27
|
+
get isOpen(): boolean;
|
|
28
|
+
get config(): ResolvedLarkConfig;
|
|
29
|
+
start(): Promise<void>;
|
|
30
|
+
open(): void;
|
|
31
|
+
close(): void;
|
|
32
|
+
stop(): Promise<void>;
|
|
33
|
+
send({ target, payload }: {
|
|
34
|
+
readonly target: string;
|
|
35
|
+
readonly payload: unknown;
|
|
36
|
+
}): Promise<string>;
|
|
37
|
+
/** Test / internal: admit a parsed message when open (non-webhook path). */
|
|
38
|
+
admit(msg: LarkMessage): void;
|
|
39
|
+
getUserInfo(userId: string, userIdType?: 'open_id' | 'user_id' | 'union_id'): Promise<unknown>;
|
|
40
|
+
getChatInfo(chatId: string): Promise<unknown>;
|
|
32
41
|
uploadFile(filePath: string, fileType?: 'image' | 'file' | 'video' | 'audio'): Promise<string | null>;
|
|
33
|
-
/**
|
|
34
|
-
* 创建群聊
|
|
35
|
-
* @param name 群名
|
|
36
|
-
* @param userIds 成员 open_id 列表
|
|
37
|
-
* @param ownerId 群主 open_id
|
|
38
|
-
*/
|
|
39
42
|
createChat(name: string, userIds: string[], ownerId?: string): Promise<string | null>;
|
|
40
|
-
/**
|
|
41
|
-
* 更新群信息
|
|
42
|
-
* @param chatId 群聊 ID
|
|
43
|
-
* @param options 更新选项
|
|
44
|
-
*/
|
|
45
43
|
updateChatInfo(chatId: string, options: {
|
|
46
44
|
name?: string;
|
|
47
45
|
description?: string;
|
|
48
46
|
}): Promise<boolean>;
|
|
49
|
-
/**
|
|
50
|
-
* 添加群成员
|
|
51
|
-
* @param chatId 群聊 ID
|
|
52
|
-
* @param userIds 用户 ID 列表
|
|
53
|
-
*/
|
|
54
47
|
addChatMembers(chatId: string, userIds: string[]): Promise<boolean>;
|
|
55
|
-
/**
|
|
56
|
-
* 移除群成员
|
|
57
|
-
* @param chatId 群聊 ID
|
|
58
|
-
* @param userIds 用户 ID 列表
|
|
59
|
-
*/
|
|
60
48
|
removeChatMembers(chatId: string, userIds: string[]): Promise<boolean>;
|
|
61
|
-
|
|
62
|
-
* 获取群成员列表
|
|
63
|
-
* @param chatId 群聊 ID
|
|
64
|
-
*/
|
|
65
|
-
getChatMembers(chatId: string): Promise<any[]>;
|
|
66
|
-
/**
|
|
67
|
-
* 解散群聊
|
|
68
|
-
* @param chatId 群聊 ID
|
|
69
|
-
*/
|
|
49
|
+
getChatMembers(chatId: string): Promise<unknown[]>;
|
|
70
50
|
dissolveChat(chatId: string): Promise<boolean>;
|
|
71
|
-
/**
|
|
72
|
-
* 设置群管理员
|
|
73
|
-
* @param chatId 群聊 ID
|
|
74
|
-
* @param userIds 用户 ID 列表
|
|
75
|
-
*/
|
|
76
51
|
setChatManagers(chatId: string, userIds: string[]): Promise<boolean>;
|
|
77
|
-
/**
|
|
78
|
-
* 移除群管理员
|
|
79
|
-
* @param chatId 群聊 ID
|
|
80
|
-
* @param userIds 用户 ID 列表
|
|
81
|
-
*/
|
|
82
52
|
removeChatManagers(chatId: string, userIds: string[]): Promise<boolean>;
|
|
83
53
|
}
|
|
84
|
-
//# sourceMappingURL=endpoint.d.ts.map
|