@zhin.js/adapter-lark 4.0.2 → 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 +33 -0
- package/README.md +59 -88
- package/adapters/lark.ts +26 -0
- package/agent/tools/add_members.ts +2 -2
- package/agent/tools/create_chat.ts +2 -2
- package/agent/tools/dissolve_chat.ts +2 -2
- package/agent/tools/get_user.ts +2 -2
- package/agent/tools/remove_managers.ts +2 -2
- package/agent/tools/set_managers.ts +2 -2
- package/agent/tools/update_chat.ts +2 -2
- package/agent/tools/upload_file.ts +2 -2
- package/lib/endpoint.d.ts +53 -0
- package/lib/endpoint.js +333 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +5 -0
- package/lib/lark-agent-deps.d.ts +27 -0
- package/lib/lark-agent-deps.js +30 -0
- package/lib/platform-permit.d.ts +15 -0
- package/lib/{src/platform-permit.js → platform-permit.js} +1 -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 +43 -24
- package/plugin.ts +12 -0
- package/schema.json +25 -0
- package/src/endpoint.ts +354 -705
- package/src/index.ts +45 -59
- package/src/lark-agent-deps.ts +53 -9
- package/src/platform-permit.ts +1 -1
- package/src/protocol.ts +332 -0
- package/src/webhook.ts +101 -0
- package/lib/agent/tools/add_members.js +0 -21
- package/lib/agent/tools/add_members.js.map +0 -1
- package/lib/agent/tools/create_chat.js +0 -20
- package/lib/agent/tools/create_chat.js.map +0 -1
- package/lib/agent/tools/dissolve_chat.js +0 -18
- package/lib/agent/tools/dissolve_chat.js.map +0 -1
- package/lib/agent/tools/get_user.js +0 -17
- package/lib/agent/tools/get_user.js.map +0 -1
- package/lib/agent/tools/remove_managers.js +0 -21
- package/lib/agent/tools/remove_managers.js.map +0 -1
- package/lib/agent/tools/set_managers.js +0 -21
- package/lib/agent/tools/set_managers.js.map +0 -1
- package/lib/agent/tools/update_chat.js +0 -22
- package/lib/agent/tools/update_chat.js.map +0 -1
- package/lib/agent/tools/upload_file.js +0 -19
- package/lib/agent/tools/upload_file.js.map +0 -1
- package/lib/src/adapter.js +0 -48
- package/lib/src/adapter.js.map +0 -1
- package/lib/src/endpoint.js +0 -677
- package/lib/src/endpoint.js.map +0 -1
- package/lib/src/index.js +0 -43
- package/lib/src/index.js.map +0 -1
- package/lib/src/lark-agent-deps.js +0 -10
- package/lib/src/lark-agent-deps.js.map +0 -1
- package/lib/src/platform-permit.js.map +0 -1
- package/lib/src/segment-mapper.js +0 -2
- package/lib/src/segment-mapper.js.map +0 -1
- package/lib/src/types.js +0 -2
- package/lib/src/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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
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
|
+
|
|
3
36
|
## 4.0.2
|
|
4
37
|
|
|
5
38
|
### 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 工具(`agent/tools/` 平台工具 + `agent/skills/lark.md`;群管标准工具由 `createSceneManagementTools` 注册)
|
|
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,103 +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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
await next()
|
|
94
|
-
})
|
|
95
|
-
```
|
|
61
|
+
| 变量 | 说明 |
|
|
62
|
+
|------|------|
|
|
63
|
+
| `LARK_APP_ID` | 应用 App ID |
|
|
64
|
+
| `LARK_APP_SECRET` | 应用 App Secret |
|
|
65
|
+
| `LARK_BOT_NAME` | 默认 endpoint 名称(可选) |
|
|
96
66
|
|
|
97
|
-
##
|
|
67
|
+
## 消息类型映射
|
|
98
68
|
|
|
99
|
-
|
|
|
100
|
-
|
|
101
|
-
|
|
|
102
|
-
|
|
|
103
|
-
|
|
|
104
|
-
|
|
|
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 |
|
|
105
76
|
|
|
77
|
+
## Agent 工具
|
|
106
78
|
|
|
107
|
-
|
|
79
|
+
`agent/` 目录保留(get_user、群聊、管理员、上传文件等)。Endpoint 在 `start` 时自注册到 `lark-agent-deps`。
|
|
108
80
|
|
|
109
|
-
##
|
|
81
|
+
## 平台权限(platform permit)
|
|
110
82
|
|
|
111
|
-
|
|
112
|
-
2. 创建应用并获取 `App ID` 和 `App Secret`
|
|
113
|
-
3. 配置事件回调 URL:`http://your-server:8086/api/lark/webhook`
|
|
114
|
-
4. 订阅 `im.message.receive_v1` 事件
|
|
115
|
-
5. 发布应用
|
|
83
|
+
`plugin.ts` 在 generation setup 注册 `src/platform-permit.ts` checker,并在 dispose 注销;CapabilityIngress 与 ToolSystem 统一经 Core `canAccessTool()` 消费工具权限。
|
|
116
84
|
|
|
117
|
-
##
|
|
85
|
+
## 测试
|
|
118
86
|
|
|
119
|
-
|
|
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
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
4
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
5
5
|
|
|
6
|
-
export default
|
|
6
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; user_ids: string }>({
|
|
7
7
|
description: '添加飞书群成员',
|
|
8
8
|
inputSchema: z.object({
|
|
9
9
|
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
-
export default
|
|
4
|
+
export default defineAgentTool<{ endpoint_id: string; name: string; members: string; owner?: string }>({
|
|
5
5
|
description: '创建飞书群聊',
|
|
6
6
|
inputSchema: z.object({
|
|
7
7
|
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
|
-
export default
|
|
4
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string }>({
|
|
5
5
|
description: '解散飞书群聊(需要群主权限)',
|
|
6
6
|
inputSchema: z.object({
|
|
7
7
|
endpoint_id: z.string().describe('Endpoint 名称'),
|
package/agent/tools/get_user.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{ endpoint_id: string; user_id: string }>({
|
|
6
6
|
description: '获取飞书用户信息',
|
|
7
7
|
inputSchema: z.object({
|
|
8
8
|
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
4
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
5
5
|
|
|
6
|
-
export default
|
|
6
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; user_ids: string }>({
|
|
7
7
|
description: '移除飞书群管理员',
|
|
8
8
|
inputSchema: z.object({
|
|
9
9
|
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
4
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
5
5
|
|
|
6
|
-
export default
|
|
6
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; user_ids: string }>({
|
|
7
7
|
description: '设置飞书群管理员',
|
|
8
8
|
inputSchema: z.object({
|
|
9
9
|
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
4
|
import { platformPermit } from '../../src/platform-permit.js';
|
|
5
5
|
|
|
6
|
-
export default
|
|
6
|
+
export default defineAgentTool<{ endpoint_id: string; chat_id: string; name?: string; description?: string }>({
|
|
7
7
|
description: '更新飞书群聊信息(群名、描述)',
|
|
8
8
|
inputSchema: z.object({
|
|
9
9
|
endpoint_id: z.string().describe('Endpoint 名称'),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { defineAgentTool } from '@zhin.js/agent/tools';
|
|
2
2
|
import { z } from 'zod';
|
|
3
3
|
import { getLarkAgentDeps } from '../../src/lark-agent-deps.js';
|
|
4
4
|
|
|
5
|
-
export default
|
|
5
|
+
export default defineAgentTool<{
|
|
6
6
|
endpoint_id: string;
|
|
7
7
|
file_path: string;
|
|
8
8
|
file_type: 'image' | 'file' | 'video' | 'audio';
|
|
@@ -0,0 +1,53 @@
|
|
|
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>;
|
|
41
|
+
uploadFile(filePath: string, fileType?: 'image' | 'file' | 'video' | 'audio'): Promise<string | null>;
|
|
42
|
+
createChat(name: string, userIds: string[], ownerId?: string): Promise<string | null>;
|
|
43
|
+
updateChatInfo(chatId: string, options: {
|
|
44
|
+
name?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
}): Promise<boolean>;
|
|
47
|
+
addChatMembers(chatId: string, userIds: string[]): Promise<boolean>;
|
|
48
|
+
removeChatMembers(chatId: string, userIds: string[]): Promise<boolean>;
|
|
49
|
+
getChatMembers(chatId: string): Promise<unknown[]>;
|
|
50
|
+
dissolveChat(chatId: string): Promise<boolean>;
|
|
51
|
+
setChatManagers(chatId: string, userIds: string[]): Promise<boolean>;
|
|
52
|
+
removeChatManagers(chatId: string, userIds: string[]): Promise<boolean>;
|
|
53
|
+
}
|