@zhin.js/adapter-email 3.0.1 → 3.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 CHANGED
@@ -1,5 +1,49 @@
1
1
  # @zhin.js/adapter-email
2
2
 
3
+ ## 3.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@4.1.3
30
+ - @zhin.js/logger@1.0.75
31
+ - @zhin.js/plugin-runtime@1.0.1
32
+ - @zhin.js/adapter@1.0.1
33
+
34
+ ## 3.0.2
35
+
36
+ ### Patch Changes
37
+
38
+ - 872c583: Slack 适配器 Phase 1/2:mrkdwn 出站、长消息切分、斜杠/按钮 ephemeral 反馈、入站 mrkdwn→Markdown、editMessage 对齐 core。
39
+
40
+ Logger 表格日志与 string-width 列宽;Agent AI Handler 框线表格与 introspection/MCP 导出;Core side-event 归一化;Schedule 时区规划;多适配器 side-event 与 API surface 更新。
41
+
42
+ - 872c583: fix: 代码格式优化
43
+ - Updated dependencies [872c583]
44
+ - Updated dependencies [872c583]
45
+ - zhin.js@4.1.2
46
+
3
47
  ## 3.0.1
4
48
 
5
49
  ### Patch Changes
package/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  # @zhin.js/adapter-email
2
2
 
3
- Zhin.js 邮件适配器,通过 SMTP 发送和 IMAP 接收邮件,将邮箱作为聊天平台接入。
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,25 +16,31 @@ 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-router** | 不需要;IMAP 轮询在适配器内完成 |
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
- - "@zhin.js/adapter-email"
35
-
36
- endpoints:
37
- - context: email
43
+ email:
38
44
  name: my-email-bot
39
45
  smtp:
40
46
  host: smtp.example.com
@@ -51,96 +57,37 @@ endpoints:
51
57
  password: "${EMAIL_PASSWORD}"
52
58
  ```
53
59
 
54
- ## 配置
60
+ 根插件 `zhin.plugins`(或项目图)需引用 `@zhin.js/adapter-email`(`instanceKey: email`)。
55
61
 
56
62
  ### 可选 IMAP 字段
57
63
 
58
- ```yaml
59
- imap:
60
- host: imap.example.com
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
- ```
64
+ - `checkInterval`:轮询间隔(毫秒),默认 `60000`
65
+ - `mailbox`:默认 `INBOX`
66
+ - `markSeen`:默认 `true`
69
67
 
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
- ## 使用示例
103
-
104
- ### 注册命令
105
-
106
- ```typescript
107
- import { usePlugin, MessageCommand } from 'zhin.js'
108
-
109
- const { addCommand } = usePlugin()
110
-
111
- addCommand(
112
- new MessageCommand('status')
113
- .desc('查询状态')
114
- .action(() => 'Agent 运行中')
115
- )
116
- ```
117
-
118
- ### 消息处理
119
-
120
- ```typescript
121
- import { usePlugin } from 'zhin.js'
68
+ ### 附件下载
122
69
 
123
- const { root } = usePlugin()
70
+ `attachments.enabled: true` 时,入站邮件附件会落盘并把保存信息写入消息 metadata(`attachments: [{ filename, path, contentType, size }]`):
124
71
 
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
- ```
72
+ - `downloadPath`:保存目录,默认 `./downloads/email`
73
+ - `maxFileSize`:单附件上限(字节),默认 10MB,超限跳过
74
+ - `allowedTypes`:允许的 MIME 类型白名单,不在列表内跳过
132
75
 
133
76
  ## 故障排查
134
77
 
135
78
  | 现象 | 排查 |
136
79
  |------|------|
137
- | IMAP 连接失败 | 主机/端口/TLS 是否正确;是否需应用专用密码而非登录密码 |
138
- | 收不到新邮件 | 默认轮询间隔 30s(`checkInterval`);检查 `mailbox` 是否为 `INBOX` |
139
- | SMTP 发送失败 | `secure` 与端口匹配(465 通常 `secure: true`);发信地址与 `auth.user` 一致 |
140
- | 重复处理邮件 | 确认 `markSeen: true`;检查是否多实例同时轮询同一邮箱 |
80
+ | IMAP 连接失败 | 主机/端口/TLS;是否需应用专用密码 |
81
+ | 收不到新邮件 | `checkInterval` / `mailbox`;确认 `open()` 后才准入入站 |
82
+ | SMTP 发送失败 | `secure` 与端口匹配;发信地址与 `auth.user` 一致 |
83
+ | 重复处理邮件 | `markSeen: true`;避免多实例轮询同一邮箱 |
141
84
 
142
85
  建议使用环境变量存储邮箱密码,勿提交到版本库。
143
86
 
87
+ ## AI 工具
88
+
89
+ 技能说明见 `agent/skills/email.md`。
90
+
144
91
  ## 文档链接
145
92
 
146
93
  - [Email 适配器文档](https://zhin.js.org/adapters/email)
@@ -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 { Endpoint, Message, MessageSegment, SendOptions } from 'zhin.js';
2
- import { EventEmitter } from "events";
3
- import type { EmailEndpointConfig, EmailMessage } from "./types.js";
4
- import type { EmailAdapter } from "./adapter.js";
5
- export declare class EmailEndpoint extends EventEmitter implements Endpoint<EmailEndpointConfig, EmailMessage> {
6
- adapter: EmailAdapter;
7
- $config: EmailEndpointConfig;
8
- $connected: boolean;
9
- private smtpTransporter;
10
- private imapConnection;
11
- private checkTimer;
12
- get logger(): import("zhin.js").Logger;
13
- get $id(): string;
14
- constructor(adapter: EmailAdapter, config: EmailEndpointConfig);
15
- $connect(): Promise<void>;
16
- $disconnect(): Promise<void>;
17
- private setupImapListeners;
18
- private startEmailCheck;
19
- private checkForNewEmails;
20
- private handleImapMessage;
21
- private parseEmailMessage;
22
- $formatMessage(emailMsg: EmailMessage): Message<EmailMessage>;
23
- static parseEmailContent(email: EmailMessage): MessageSegment[];
24
- $sendMessage(options: SendOptions): Promise<string>;
25
- $recallMessage(id: string): Promise<void>;
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