@zhin.js/adapter-email 1.0.1 → 1.1.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 +374 -0
- package/README.md +50 -102
- package/adapters/email.js +25 -0
- package/adapters/email.ts +35 -0
- package/lib/client.d.ts +23 -0
- package/lib/client.js +29 -0
- package/lib/endpoint.d.ts +27 -32
- package/lib/endpoint.js +284 -317
- package/lib/index.d.ts +4 -10
- package/lib/index.js +4 -23
- package/lib/protocol.d.ts +138 -0
- package/lib/protocol.js +245 -0
- package/lib/transport.d.ts +32 -0
- package/lib/transport.js +27 -0
- package/package.json +45 -12
- package/plugin.js +8 -0
- package/schema.json +169 -0
- package/src/client.ts +40 -0
- package/src/endpoint.ts +334 -390
- package/src/index.ts +35 -28
- package/src/protocol.ts +384 -0
- package/src/transport.ts +65 -0
- package/lib/adapter.d.ts +0 -12
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -15
- 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/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 -18
- package/src/types.ts +0 -52
- /package/{skills/email/SKILL.md → agent/skills/email.md} +0 -0
package/schema.json
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"additionalProperties": false,
|
|
5
|
+
"properties": {
|
|
6
|
+
"master": {
|
|
7
|
+
"type": [
|
|
8
|
+
"string",
|
|
9
|
+
"number"
|
|
10
|
+
],
|
|
11
|
+
"description": "框架 master(email address;AI/工具权限、endpoint 管理)。endpoints[i].master 可逐项覆盖"
|
|
12
|
+
},
|
|
13
|
+
"trusted": {
|
|
14
|
+
"type": "array",
|
|
15
|
+
"items": {
|
|
16
|
+
"type": [
|
|
17
|
+
"string",
|
|
18
|
+
"number"
|
|
19
|
+
],
|
|
20
|
+
"description": "Trusted email address"
|
|
21
|
+
},
|
|
22
|
+
"description": "框架 trusted 用户列表(弱于 master)。endpoints[i].trusted 可逐项追加"
|
|
23
|
+
},
|
|
24
|
+
"endpoints": {
|
|
25
|
+
"type": "array",
|
|
26
|
+
"description": "多账号:一个插件实例挂多个 endpoint。每项与顶层字段同构(id 必填,其余覆盖顶层)",
|
|
27
|
+
"items": {
|
|
28
|
+
"type": "object",
|
|
29
|
+
"additionalProperties": true,
|
|
30
|
+
"properties": {
|
|
31
|
+
"master": {
|
|
32
|
+
"type": [
|
|
33
|
+
"string",
|
|
34
|
+
"number"
|
|
35
|
+
],
|
|
36
|
+
"description": "本 endpoint 的框架 master(email address);覆盖顶层 master"
|
|
37
|
+
},
|
|
38
|
+
"trusted": {
|
|
39
|
+
"type": "array",
|
|
40
|
+
"items": {
|
|
41
|
+
"type": [
|
|
42
|
+
"string",
|
|
43
|
+
"number"
|
|
44
|
+
],
|
|
45
|
+
"description": "Trusted email address"
|
|
46
|
+
},
|
|
47
|
+
"description": "本 endpoint 的 trusted 列表"
|
|
48
|
+
},
|
|
49
|
+
"smtp": {
|
|
50
|
+
"type": "object",
|
|
51
|
+
"additionalProperties": false,
|
|
52
|
+
"properties": {
|
|
53
|
+
"host": {
|
|
54
|
+
"type": "string"
|
|
55
|
+
},
|
|
56
|
+
"port": {
|
|
57
|
+
"type": "number"
|
|
58
|
+
},
|
|
59
|
+
"secure": {
|
|
60
|
+
"type": "boolean"
|
|
61
|
+
},
|
|
62
|
+
"auth": {
|
|
63
|
+
"type": "object",
|
|
64
|
+
"additionalProperties": false,
|
|
65
|
+
"properties": {
|
|
66
|
+
"user": {
|
|
67
|
+
"type": "string"
|
|
68
|
+
},
|
|
69
|
+
"pass": {
|
|
70
|
+
"type": "string"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
"required": [
|
|
74
|
+
"user",
|
|
75
|
+
"pass"
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"required": [
|
|
80
|
+
"host",
|
|
81
|
+
"port",
|
|
82
|
+
"secure",
|
|
83
|
+
"auth"
|
|
84
|
+
]
|
|
85
|
+
},
|
|
86
|
+
"imap": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"additionalProperties": false,
|
|
89
|
+
"properties": {
|
|
90
|
+
"host": {
|
|
91
|
+
"type": "string"
|
|
92
|
+
},
|
|
93
|
+
"port": {
|
|
94
|
+
"type": "number"
|
|
95
|
+
},
|
|
96
|
+
"tls": {
|
|
97
|
+
"type": "boolean"
|
|
98
|
+
},
|
|
99
|
+
"user": {
|
|
100
|
+
"type": "string"
|
|
101
|
+
},
|
|
102
|
+
"password": {
|
|
103
|
+
"type": "string"
|
|
104
|
+
},
|
|
105
|
+
"checkInterval": {
|
|
106
|
+
"type": "number",
|
|
107
|
+
"default": 60000
|
|
108
|
+
},
|
|
109
|
+
"mailbox": {
|
|
110
|
+
"type": "string",
|
|
111
|
+
"default": "INBOX"
|
|
112
|
+
},
|
|
113
|
+
"markSeen": {
|
|
114
|
+
"type": "boolean",
|
|
115
|
+
"default": true
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"required": [
|
|
119
|
+
"host",
|
|
120
|
+
"port",
|
|
121
|
+
"tls",
|
|
122
|
+
"user",
|
|
123
|
+
"password"
|
|
124
|
+
]
|
|
125
|
+
},
|
|
126
|
+
"attachments": {
|
|
127
|
+
"type": "object",
|
|
128
|
+
"additionalProperties": false,
|
|
129
|
+
"properties": {
|
|
130
|
+
"enabled": {
|
|
131
|
+
"type": "boolean",
|
|
132
|
+
"default": false
|
|
133
|
+
},
|
|
134
|
+
"downloadPath": {
|
|
135
|
+
"type": "string"
|
|
136
|
+
},
|
|
137
|
+
"maxFileSize": {
|
|
138
|
+
"type": "number"
|
|
139
|
+
},
|
|
140
|
+
"allowedTypes": {
|
|
141
|
+
"type": "array",
|
|
142
|
+
"items": {
|
|
143
|
+
"type": "string"
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
"id": {
|
|
149
|
+
"type": "string",
|
|
150
|
+
"description": "Email bot name"
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
"required": [
|
|
154
|
+
"id",
|
|
155
|
+
"smtp",
|
|
156
|
+
"imap"
|
|
157
|
+
]
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
"commandPrefix": {
|
|
161
|
+
"type": "string",
|
|
162
|
+
"default": "",
|
|
163
|
+
"description": "命令前缀(默认 '' 无前缀,任意文本按命令匹配;如 '/' 要求 / 开头)。endpoints[i] 可逐项覆盖"
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
"required": [
|
|
167
|
+
"endpoints"
|
|
168
|
+
]
|
|
169
|
+
}
|
package/src/client.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { EmailImapTransport, EmailSmtpTransport } from './transport.js';
|
|
2
|
+
import { defineEndpointClient } from 'zhin.js/adapter';
|
|
3
|
+
|
|
4
|
+
/** Live SMTP + IMAP client pair exposed to event handlers and plugins. */
|
|
5
|
+
export class EmailClient {
|
|
6
|
+
constructor(
|
|
7
|
+
private readonly resolveSmtp: () => EmailSmtpTransport | null,
|
|
8
|
+
private readonly resolveImap: () => EmailImapTransport | null,
|
|
9
|
+
) {}
|
|
10
|
+
|
|
11
|
+
get smtp(): EmailSmtpTransport {
|
|
12
|
+
const transport = this.resolveSmtp();
|
|
13
|
+
if (!transport) throw new Error('SMTP transporter not connected');
|
|
14
|
+
return transport;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get imap(): EmailImapTransport {
|
|
18
|
+
const transport = this.resolveImap();
|
|
19
|
+
if (!transport) throw new Error('IMAP client not connected');
|
|
20
|
+
return transport;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
verify(): Promise<void> {
|
|
24
|
+
return this.smtp.verify();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
sendMail(options: unknown): Promise<{ messageId?: string }> {
|
|
28
|
+
return this.smtp.sendMail(options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export type EmailClientEventMap = Record<string, unknown>;
|
|
33
|
+
|
|
34
|
+
declare module '@zhin.js/feature-kit' {
|
|
35
|
+
interface AdapterClientRegistry {
|
|
36
|
+
readonly email: { readonly client: EmailClient; readonly events: EmailClientEventMap };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const emailClient = defineEndpointClient<EmailClient, EmailClientEventMap>('email');
|