@zhin.js/adapter-email 3.0.2 → 4.0.0
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 +50 -0
- package/README.md +47 -104
- package/adapters/email.ts +29 -0
- package/lib/endpoint.d.ts +25 -32
- package/lib/endpoint.js +181 -323
- package/lib/index.d.ts +3 -10
- package/lib/index.js +3 -23
- package/lib/protocol.d.ts +107 -0
- package/lib/protocol.js +160 -0
- package/lib/transport.d.ts +32 -0
- package/lib/transport.js +27 -0
- package/package.json +36 -7
- package/plugin.ts +8 -0
- package/schema.json +133 -0
- package/src/endpoint.ts +231 -398
- package/src/index.ts +27 -29
- package/src/protocol.ts +269 -0
- package/src/transport.ts +65 -0
- package/lib/adapter.d.ts +0 -14
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -21
- 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/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 -49
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -2
- package/lib/types.js.map +0 -1
- package/src/adapter.ts +0 -24
- package/src/segment-mapper.ts +0 -1
- package/src/types.ts +0 -52
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @zhin.js/adapter-email
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 7db69c1: 命令前缀改为适配器配置项:`MessageDispatcher` 不再硬编码 `/`,默认按消息所属适配器实例 config 的 `commandPrefix` 解析(默认 `''` 无前缀,任意文本按命令匹配),`endpoints[i].commandPrefix` 逐项覆盖;`ImRuntime({ commandPrefix })` 仍可设全局静态前缀。全部 20 个平台适配器 schema 新增 `commandPrefix` 属性。
|
|
8
|
+
|
|
9
|
+
BREAKING(行为变化):未配置时命令不再需要 `/` 前缀——原 `/zt` 写法不再命中,直接发 `zt` 即可;需要斜杠风格的适配器请在配置里显式设 `commandPrefix: '/'`。
|
|
10
|
+
|
|
11
|
+
- 713445c: 适配器配置格式定稿(不兼容旧格式):`plugins.<adapter>` 顶层仅共享字段 + `commandPrefix`,`endpoints[i]` 携带 endpoint 级字段(`name` + 凭据,各 schema 已类型化),`endpoints` 为必填(icqq 另需顶层 `master`);icqq 新增 `trusted` 列表(顶层/逐项均可)。scaffold-wizard 全部字段式与自定义 configure() 产出改为新格式,examples(full-bot / qq-games-bot)与 20 个适配器 README 同步迁移。
|
|
12
|
+
- Updated dependencies [7db69c1]
|
|
13
|
+
- Updated dependencies [e5c84ed]
|
|
14
|
+
- Updated dependencies [3ea84a0]
|
|
15
|
+
- Updated dependencies [1ddcd70]
|
|
16
|
+
- Updated dependencies [ac9da66]
|
|
17
|
+
- @zhin.js/core@1.4.0
|
|
18
|
+
- @zhin.js/adapter@1.1.0
|
|
19
|
+
- @zhin.js/plugin-runtime@1.1.0
|
|
20
|
+
- zhin.js@5.0.0
|
|
21
|
+
|
|
22
|
+
## 3.0.3
|
|
23
|
+
|
|
24
|
+
### Patch Changes
|
|
25
|
+
|
|
26
|
+
- cc5c94d: 约定式插件运行时迁移(breaking):插件与适配器由 `usePlugin()` / `extends Adapter` 迁移为 `definePlugin` / `defineAdapter` + `plugin.ts` + 约定目录(`adapters/`、`commands/`、`components/`、`tools/` 等)。
|
|
27
|
+
|
|
28
|
+
- 新增约定式运行时包:`@zhin.js/plugin-runtime`、`@zhin.js/adapter`、`@zhin.js/runtime`、`@zhin.js/host-http`(首版 1.0.0 走 init-publish,不在本 changeset 内 bump)。
|
|
29
|
+
- 全部 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 推迟的连接模式已补齐。
|
|
30
|
+
- 游戏 / 工具 / 服务插件同步迁移到约定目录结构。
|
|
31
|
+
- CLI 增加 plugin-runtime host installer(http/database/outbound/schedule/console 等)。
|
|
32
|
+
|
|
33
|
+
后续加固(同批):
|
|
34
|
+
|
|
35
|
+
- CLI:`zhin runtime start --daemon`(pidfile/崩溃拉起/风暴保护),orphan watchdog 防僵尸进程;legacy `zhin dev` / `zhin start` 已移除(含 `zhin restart`),`zhin stop` 兼容新 daemon。
|
|
36
|
+
- 安全:builtin 工具统一走 `security/policy-facade.ts` 的 `runToolPolicies`(声明式策略表,deny 优先);审计日志 close flush + 背压队列;`splitCompoundCommand` 引号感知、`extractCommandName` 去引号堵绕过。
|
|
37
|
+
- 日志:Logger 双堆栈修复、本地时区、`getLogger` 挂树(`setLevel` 递归生效)、第三方库(log4js/discord)桥接、启动人读总结。
|
|
38
|
+
- 结构:`plugins/games/shared` 迁为 `packages/game-kit`(`@zhin.js/game-kit`);死目录 `plugins/adapters/common` 删除。
|
|
39
|
+
- 脚手架:`create-zhin-app` / `zhin new` / scaffold-wizard 生成物改为 Plugin Runtime 形态(minimal-bot 同构,新配置格式)。
|
|
40
|
+
- Console:endpoint.list 真实名称与 phase、schema:get-all 按 instanceKey 映射、db:\* 接 DatabaseHost。
|
|
41
|
+
|
|
42
|
+
注:按仓库发布惯例(见 1bb345dd2),本次 breaking 迁移统一使用 patch,避免 zhin.js 5.0 级联。
|
|
43
|
+
|
|
44
|
+
- Updated dependencies [16ec4e8]
|
|
45
|
+
- Updated dependencies [cc5c94d]
|
|
46
|
+
- Updated dependencies [447f3e2]
|
|
47
|
+
- @zhin.js/core@1.3.5
|
|
48
|
+
- zhin.js@4.1.3
|
|
49
|
+
- @zhin.js/logger@1.0.75
|
|
50
|
+
- @zhin.js/plugin-runtime@1.0.1
|
|
51
|
+
- @zhin.js/adapter@1.0.1
|
|
52
|
+
|
|
3
53
|
## 3.0.2
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# @zhin.js/adapter-email
|
|
2
2
|
|
|
3
|
-
Zhin.js
|
|
3
|
+
Zhin.js 邮件适配器(Plugin Runtime),通过 SMTP 发送和 IMAP 接收邮件,将邮箱作为聊天通道接入。
|
|
4
4
|
|
|
5
5
|
## 功能特性
|
|
6
6
|
|
|
7
7
|
- SMTP 邮件发送(基于 nodemailer)
|
|
8
8
|
- IMAP 邮件接收(基于 imap + mailparser)
|
|
9
|
-
-
|
|
10
|
-
- 定时轮询新邮件
|
|
9
|
+
- 定时轮询未读邮件
|
|
11
10
|
- TLS/SSL 加密连接
|
|
11
|
+
- 约定式 `defineAdapter` / `definePlugin`(无需 `usePlugin`)
|
|
12
12
|
|
|
13
13
|
## 安装
|
|
14
14
|
|
|
@@ -16,135 +16,78 @@ Zhin.js 邮件适配器,通过 SMTP 发送和 IMAP 接收邮件,将邮箱作
|
|
|
16
16
|
pnpm add @zhin.js/adapter-email
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
## Plugin Runtime
|
|
20
|
+
|
|
21
|
+
- `@zhin.js/adapter` — 约定式 `adapters/email.ts`(`defineAdapter`)
|
|
22
|
+
- `@zhin.js/core` — `messageGatewayToken` 入站/出站
|
|
23
|
+
- `@zhin.js/plugin-runtime` — `plugin.ts`(`definePlugin`)
|
|
24
|
+
- 配置经插件 `schema.json` 落到 `plugins.<instanceKey>`(`smtp` / `imap`)
|
|
25
|
+
|
|
26
|
+
入站:`gateway.receive({ adapter, target: fromEmail, content: text, sender, metadata })`
|
|
27
|
+
出站:`send({ target, payload })` → nodemailer(payload 已由 gateway/core 渲染;无 segment-mapper)
|
|
28
|
+
|
|
19
29
|
## 前置条件
|
|
20
30
|
|
|
21
31
|
| 要求 | 说明 |
|
|
22
32
|
|------|------|
|
|
23
|
-
| **邮箱账号** | 可用的 SMTP 发信与 IMAP
|
|
24
|
-
| **应用专用密码** | Gmail、Outlook
|
|
33
|
+
| **邮箱账号** | 可用的 SMTP 发信与 IMAP 收信账号 |
|
|
34
|
+
| **应用专用密码** | Gmail、Outlook 等常需应用密码 |
|
|
25
35
|
| **网络** | 出站可连 SMTP/IMAP 端口(465/587/993 等) |
|
|
26
|
-
| **host-
|
|
27
|
-
|
|
28
|
-
必填字段见 `EmailEndpointConfig`:`context`、`name`、`smtp`、`imap`(含 `auth.user` / `auth.pass` 与 `user` / `password`)。
|
|
36
|
+
| **host-http** | 不需要;IMAP 轮询在适配器内完成 |
|
|
29
37
|
|
|
30
38
|
## 最小配置
|
|
31
39
|
|
|
32
40
|
```yaml
|
|
41
|
+
# zhin.config.yml(Plugin Runtime)
|
|
33
42
|
plugins:
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
user: bot@example.com
|
|
51
|
-
password: "${EMAIL_PASSWORD}"
|
|
43
|
+
email:
|
|
44
|
+
endpoints:
|
|
45
|
+
- name: my-email-bot
|
|
46
|
+
smtp:
|
|
47
|
+
host: smtp.example.com
|
|
48
|
+
port: 465
|
|
49
|
+
secure: true
|
|
50
|
+
auth:
|
|
51
|
+
user: bot@example.com
|
|
52
|
+
pass: "${EMAIL_PASSWORD}"
|
|
53
|
+
imap:
|
|
54
|
+
host: imap.example.com
|
|
55
|
+
port: 993
|
|
56
|
+
tls: true
|
|
57
|
+
user: bot@example.com
|
|
58
|
+
password: "${EMAIL_PASSWORD}"
|
|
52
59
|
```
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-email`(`instanceKey: email`)。
|
|
55
62
|
|
|
56
63
|
### 可选 IMAP 字段
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
port: 993
|
|
62
|
-
tls: true
|
|
63
|
-
user: bot@example.com
|
|
64
|
-
password: "${EMAIL_PASSWORD}"
|
|
65
|
-
# checkInterval: 30000 # 轮询间隔(毫秒),默认 30 秒
|
|
66
|
-
# mailbox: INBOX # 监听的邮箱文件夹
|
|
67
|
-
# markSeen: true # 已读标记
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### TypeScript 配置
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
import { defineConfig } from 'zhin.js'
|
|
74
|
-
|
|
75
|
-
export default defineConfig({
|
|
76
|
-
endpoints: [
|
|
77
|
-
{
|
|
78
|
-
context: 'email',
|
|
79
|
-
name: 'my-email-bot',
|
|
80
|
-
smtp: {
|
|
81
|
-
host: 'smtp.example.com',
|
|
82
|
-
port: 465,
|
|
83
|
-
secure: true,
|
|
84
|
-
auth: {
|
|
85
|
-
user: 'bot@example.com',
|
|
86
|
-
pass: process.env.EMAIL_PASSWORD!,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
imap: {
|
|
90
|
-
host: 'imap.example.com',
|
|
91
|
-
port: 993,
|
|
92
|
-
tls: true,
|
|
93
|
-
user: 'bot@example.com',
|
|
94
|
-
password: process.env.EMAIL_PASSWORD!,
|
|
95
|
-
},
|
|
96
|
-
}
|
|
97
|
-
],
|
|
98
|
-
plugins: ['@zhin.js/adapter-email']
|
|
99
|
-
})
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## 使用示例
|
|
65
|
+
- `checkInterval`:轮询间隔(毫秒),默认 `60000`
|
|
66
|
+
- `mailbox`:默认 `INBOX`
|
|
67
|
+
- `markSeen`:默认 `true`
|
|
103
68
|
|
|
104
|
-
###
|
|
69
|
+
### 附件下载
|
|
105
70
|
|
|
106
|
-
|
|
107
|
-
import { usePlugin, MessageCommand } from 'zhin.js'
|
|
71
|
+
`attachments.enabled: true` 时,入站邮件附件会落盘并把保存信息写入消息 metadata(`attachments: [{ filename, path, contentType, size }]`):
|
|
108
72
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
new MessageCommand('status')
|
|
113
|
-
.desc('查询状态')
|
|
114
|
-
.action(() => 'Agent 运行中')
|
|
115
|
-
)
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
### 消息处理
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
import { usePlugin } from 'zhin.js'
|
|
122
|
-
|
|
123
|
-
const { root } = usePlugin()
|
|
124
|
-
|
|
125
|
-
root.addMiddleware(async (message, next) => {
|
|
126
|
-
if (message.$adapter === 'email') {
|
|
127
|
-
console.log('收到邮件:', message.$sender.name, message.$content)
|
|
128
|
-
}
|
|
129
|
-
await next()
|
|
130
|
-
})
|
|
131
|
-
```
|
|
73
|
+
- `downloadPath`:保存目录,默认 `./downloads/email`
|
|
74
|
+
- `maxFileSize`:单附件上限(字节),默认 10MB,超限跳过
|
|
75
|
+
- `allowedTypes`:允许的 MIME 类型白名单,不在列表内跳过
|
|
132
76
|
|
|
133
77
|
## 故障排查
|
|
134
78
|
|
|
135
79
|
| 现象 | 排查 |
|
|
136
80
|
|------|------|
|
|
137
|
-
| IMAP 连接失败 | 主机/端口/TLS
|
|
138
|
-
| 收不到新邮件 |
|
|
139
|
-
| SMTP 发送失败 | `secure`
|
|
140
|
-
| 重复处理邮件 |
|
|
81
|
+
| IMAP 连接失败 | 主机/端口/TLS;是否需应用专用密码 |
|
|
82
|
+
| 收不到新邮件 | `checkInterval` / `mailbox`;确认 `open()` 后才准入入站 |
|
|
83
|
+
| SMTP 发送失败 | `secure` 与端口匹配;发信地址与 `auth.user` 一致 |
|
|
84
|
+
| 重复处理邮件 | `markSeen: true`;避免多实例轮询同一邮箱 |
|
|
141
85
|
|
|
142
86
|
建议使用环境变量存储邮箱密码,勿提交到版本库。
|
|
143
87
|
|
|
144
88
|
## AI 工具
|
|
145
89
|
|
|
146
|
-
技能说明见 `agent/skills/email.md
|
|
147
|
-
|
|
90
|
+
技能说明见 `agent/skills/email.md`。
|
|
148
91
|
|
|
149
92
|
## 文档链接
|
|
150
93
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convention entry: discover `adapters/email.ts` → defineAdapter.
|
|
3
|
+
*/
|
|
4
|
+
import { defineAdapter } from '@zhin.js/adapter';
|
|
5
|
+
import { messageGatewayToken } from '@zhin.js/core/runtime';
|
|
6
|
+
import { EmailEndpoint } from '../src/endpoint.js';
|
|
7
|
+
import {
|
|
8
|
+
resolveEmailConfig,
|
|
9
|
+
type EmailAdapterConfig,
|
|
10
|
+
} from '../src/protocol.js';
|
|
11
|
+
|
|
12
|
+
export { EmailEndpoint } from '../src/endpoint.js';
|
|
13
|
+
export type { EmailEndpointOptions } from '../src/endpoint.js';
|
|
14
|
+
export type {
|
|
15
|
+
EmailImapFetchMessage,
|
|
16
|
+
EmailImapTransport,
|
|
17
|
+
EmailSmtpTransport,
|
|
18
|
+
} from '../src/transport.js';
|
|
19
|
+
|
|
20
|
+
export default defineAdapter<EmailAdapterConfig>({
|
|
21
|
+
capabilities: ['inbound', 'outbound'],
|
|
22
|
+
create(context) {
|
|
23
|
+
return new EmailEndpoint({
|
|
24
|
+
id: context.id,
|
|
25
|
+
gateway: context.use(messageGatewayToken),
|
|
26
|
+
config: resolveEmailConfig(context.config),
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
});
|
package/lib/endpoint.d.ts
CHANGED
|
@@ -1,33 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
private formatSendContent;
|
|
27
|
-
private downloadAttachment;
|
|
28
|
-
/**
|
|
29
|
-
* HTML → 纯文本转换,处理常见标签和实体
|
|
30
|
-
*/
|
|
31
|
-
static htmlToText(html: string): string;
|
|
1
|
+
import type { EndpointInstance } from '@zhin.js/adapter';
|
|
2
|
+
import type { MessageGateway } from '@zhin.js/core/runtime';
|
|
3
|
+
import type { CapabilityId } from '@zhin.js/plugin-runtime';
|
|
4
|
+
import { type EmailMessage, type ResolvedEmailConfig } from './protocol.js';
|
|
5
|
+
import { type EmailImapTransport, type EmailSmtpTransport } from './transport.js';
|
|
6
|
+
export interface EmailEndpointOptions {
|
|
7
|
+
readonly id: CapabilityId;
|
|
8
|
+
readonly gateway: MessageGateway;
|
|
9
|
+
readonly config: ResolvedEmailConfig;
|
|
10
|
+
readonly createSmtp?: (config: ResolvedEmailConfig['smtp']) => EmailSmtpTransport | Promise<EmailSmtpTransport>;
|
|
11
|
+
readonly createImap?: (config: ResolvedEmailConfig['imap']) => EmailImapTransport;
|
|
12
|
+
}
|
|
13
|
+
export declare class EmailEndpoint implements EndpointInstance {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(options: EmailEndpointOptions);
|
|
16
|
+
start(): Promise<void>;
|
|
17
|
+
open(): void;
|
|
18
|
+
close(): void;
|
|
19
|
+
stop(): Promise<void>;
|
|
20
|
+
send({ target, payload }: {
|
|
21
|
+
readonly target: string;
|
|
22
|
+
readonly payload: unknown;
|
|
23
|
+
}): Promise<string>;
|
|
24
|
+
/** Test / internal: admit a parsed mail when the endpoint is open. */
|
|
25
|
+
admit(email: EmailMessage): void;
|
|
32
26
|
}
|
|
33
|
-
//# sourceMappingURL=endpoint.d.ts.map
|