@zhin.js/adapter-dingtalk 1.0.38 → 1.0.40
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 +14 -0
- package/lib/adapter.d.ts +17 -0
- package/lib/adapter.d.ts.map +1 -0
- package/lib/adapter.js +280 -0
- package/lib/adapter.js.map +1 -0
- package/lib/bot.d.ts +46 -0
- package/lib/bot.d.ts.map +1 -0
- package/lib/bot.js +532 -0
- package/lib/bot.js.map +1 -0
- package/lib/index.d.ts +4 -108
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +9 -869
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +58 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +5 -0
- package/lib/types.js.map +1 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/lib/adapter.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 钉钉适配器
|
|
3
|
+
*/
|
|
4
|
+
import { Adapter, Plugin } from "zhin.js";
|
|
5
|
+
import { DingTalkBot } from "./bot.js";
|
|
6
|
+
import type { DingTalkBotConfig } from "./types.js";
|
|
7
|
+
export declare class DingTalkAdapter extends Adapter<DingTalkBot> {
|
|
8
|
+
#private;
|
|
9
|
+
constructor(plugin: Plugin, router: any);
|
|
10
|
+
createBot(config: DingTalkBotConfig): DingTalkBot;
|
|
11
|
+
kickMember(botId: string, sceneId: string, userId: string): Promise<boolean>;
|
|
12
|
+
setGroupName(botId: string, sceneId: string, name: string): Promise<boolean>;
|
|
13
|
+
getGroupInfo(botId: string, sceneId: string): Promise<any>;
|
|
14
|
+
start(): Promise<void>;
|
|
15
|
+
private registerDingTalkPlatformTools;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,EACP,MAAM,EAKP,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD,qBAAa,eAAgB,SAAQ,OAAO,CAAC,WAAW,CAAC;;gBAG3C,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG;IAKvC,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW;IAI3C,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMzD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAMzD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAM3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAgB5B,OAAO,CAAC,6BAA6B;CAgPtC"}
|
package/lib/adapter.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 钉钉适配器
|
|
3
|
+
*/
|
|
4
|
+
import { Adapter, createGroupManagementTools, GROUP_MANAGEMENT_SKILL_KEYWORDS, GROUP_MANAGEMENT_SKILL_TAGS, } from "zhin.js";
|
|
5
|
+
import { DingTalkBot } from "./bot.js";
|
|
6
|
+
export class DingTalkAdapter extends Adapter {
|
|
7
|
+
#router;
|
|
8
|
+
constructor(plugin, router) {
|
|
9
|
+
super(plugin, "dingtalk", []);
|
|
10
|
+
this.#router = router;
|
|
11
|
+
}
|
|
12
|
+
createBot(config) {
|
|
13
|
+
return new DingTalkBot(this, this.#router, config);
|
|
14
|
+
}
|
|
15
|
+
async kickMember(botId, sceneId, userId) {
|
|
16
|
+
const bot = this.bots.get(botId);
|
|
17
|
+
if (!bot)
|
|
18
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
19
|
+
return bot.updateChat(sceneId, { del_useridlist: [userId] });
|
|
20
|
+
}
|
|
21
|
+
async setGroupName(botId, sceneId, name) {
|
|
22
|
+
const bot = this.bots.get(botId);
|
|
23
|
+
if (!bot)
|
|
24
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
25
|
+
return bot.updateChat(sceneId, { name });
|
|
26
|
+
}
|
|
27
|
+
async getGroupInfo(botId, sceneId) {
|
|
28
|
+
const bot = this.bots.get(botId);
|
|
29
|
+
if (!bot)
|
|
30
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
31
|
+
return bot.getChatInfo(sceneId);
|
|
32
|
+
}
|
|
33
|
+
async start() {
|
|
34
|
+
this.registerDingTalkPlatformTools();
|
|
35
|
+
const groupTools = createGroupManagementTools(this, this.name);
|
|
36
|
+
groupTools.forEach((t) => this.addTool(t));
|
|
37
|
+
this.declareSkill({
|
|
38
|
+
description: "钉钉群管理:踢人、禁言、设管理员、改群名、查成员等。仅有昵称时请先 list_members 获取 user_id 再操作。",
|
|
39
|
+
keywords: GROUP_MANAGEMENT_SKILL_KEYWORDS,
|
|
40
|
+
tags: GROUP_MANAGEMENT_SKILL_TAGS,
|
|
41
|
+
});
|
|
42
|
+
await super.start();
|
|
43
|
+
}
|
|
44
|
+
registerDingTalkPlatformTools() {
|
|
45
|
+
this.addTool({
|
|
46
|
+
name: "dingtalk_get_user",
|
|
47
|
+
description: "获取钉钉用户信息",
|
|
48
|
+
parameters: {
|
|
49
|
+
type: "object",
|
|
50
|
+
properties: {
|
|
51
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
52
|
+
user_id: { type: "string", description: "用户 ID" },
|
|
53
|
+
},
|
|
54
|
+
required: ["bot", "user_id"],
|
|
55
|
+
},
|
|
56
|
+
platforms: ["dingtalk"],
|
|
57
|
+
scopes: ["group", "private"],
|
|
58
|
+
permissionLevel: "user",
|
|
59
|
+
execute: async (args) => {
|
|
60
|
+
const { bot: botId, user_id } = args;
|
|
61
|
+
const bot = this.bots.get(botId);
|
|
62
|
+
if (!bot)
|
|
63
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
64
|
+
return await bot.getUserInfo(user_id);
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
this.addTool({
|
|
68
|
+
name: "dingtalk_get_dept_users",
|
|
69
|
+
description: "获取钉钉部门用户列表",
|
|
70
|
+
parameters: {
|
|
71
|
+
type: "object",
|
|
72
|
+
properties: {
|
|
73
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
74
|
+
dept_id: { type: "number", description: "部门 ID" },
|
|
75
|
+
},
|
|
76
|
+
required: ["bot", "dept_id"],
|
|
77
|
+
},
|
|
78
|
+
platforms: ["dingtalk"],
|
|
79
|
+
scopes: ["group", "private"],
|
|
80
|
+
permissionLevel: "user",
|
|
81
|
+
execute: async (args) => {
|
|
82
|
+
const { bot: botId, dept_id } = args;
|
|
83
|
+
const bot = this.bots.get(botId);
|
|
84
|
+
if (!bot)
|
|
85
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
86
|
+
const users = await bot.getDepartmentUsers(dept_id);
|
|
87
|
+
return { users, count: users.length };
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
this.addTool({
|
|
91
|
+
name: "dingtalk_list_departments",
|
|
92
|
+
description: "获取钉钉部门列表",
|
|
93
|
+
parameters: {
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: {
|
|
96
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
97
|
+
dept_id: { type: "number", description: "父部门 ID,默认 1(根部门)" },
|
|
98
|
+
},
|
|
99
|
+
required: ["bot"],
|
|
100
|
+
},
|
|
101
|
+
platforms: ["dingtalk"],
|
|
102
|
+
scopes: ["group", "private"],
|
|
103
|
+
permissionLevel: "user",
|
|
104
|
+
execute: async (args) => {
|
|
105
|
+
const { bot: botId, dept_id = 1 } = args;
|
|
106
|
+
const bot = this.bots.get(botId);
|
|
107
|
+
if (!bot)
|
|
108
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
109
|
+
const departments = await bot.getDepartmentList(dept_id);
|
|
110
|
+
return { departments, count: departments.length };
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
this.addTool({
|
|
114
|
+
name: "dingtalk_send_work_notice",
|
|
115
|
+
description: "向指定用户发送钉钉工作通知",
|
|
116
|
+
parameters: {
|
|
117
|
+
type: "object",
|
|
118
|
+
properties: {
|
|
119
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
120
|
+
user_ids: {
|
|
121
|
+
type: "array",
|
|
122
|
+
items: { type: "string" },
|
|
123
|
+
description: "用户 ID 列表",
|
|
124
|
+
},
|
|
125
|
+
content: { type: "string", description: "通知内容" },
|
|
126
|
+
},
|
|
127
|
+
required: ["bot", "user_ids", "content"],
|
|
128
|
+
},
|
|
129
|
+
platforms: ["dingtalk"],
|
|
130
|
+
scopes: ["group", "private"],
|
|
131
|
+
permissionLevel: "group_admin",
|
|
132
|
+
execute: async (args) => {
|
|
133
|
+
const { bot: botId, user_ids, content } = args;
|
|
134
|
+
const bot = this.bots.get(botId);
|
|
135
|
+
if (!bot)
|
|
136
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
137
|
+
const msgContent = { msgtype: "text", text: { content } };
|
|
138
|
+
const success = await bot.sendWorkNotice(user_ids, msgContent);
|
|
139
|
+
return {
|
|
140
|
+
success,
|
|
141
|
+
message: success ? "工作通知已发送" : "发送失败",
|
|
142
|
+
};
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
this.addTool({
|
|
146
|
+
name: "dingtalk_create_chat",
|
|
147
|
+
description: "创建钉钉群聊",
|
|
148
|
+
parameters: {
|
|
149
|
+
type: "object",
|
|
150
|
+
properties: {
|
|
151
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
152
|
+
name: { type: "string", description: "群名" },
|
|
153
|
+
owner: { type: "string", description: "群主用户 ID" },
|
|
154
|
+
members: {
|
|
155
|
+
type: "array",
|
|
156
|
+
items: { type: "string" },
|
|
157
|
+
description: "成员用户 ID 列表",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
required: ["bot", "name", "owner", "members"],
|
|
161
|
+
},
|
|
162
|
+
platforms: ["dingtalk"],
|
|
163
|
+
scopes: ["group", "private"],
|
|
164
|
+
permissionLevel: "group_admin",
|
|
165
|
+
execute: async (args) => {
|
|
166
|
+
const { bot: botId, name, owner, members } = args;
|
|
167
|
+
const bot = this.bots.get(botId);
|
|
168
|
+
if (!bot)
|
|
169
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
170
|
+
const chatId = await bot.createChat(name, owner, members);
|
|
171
|
+
return {
|
|
172
|
+
success: !!chatId,
|
|
173
|
+
chat_id: chatId,
|
|
174
|
+
message: chatId ? `群聊创建成功: ${chatId}` : "创建失败",
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
});
|
|
178
|
+
this.addTool({
|
|
179
|
+
name: "dingtalk_add_chat_members",
|
|
180
|
+
description: "向钉钉群聊添加成员",
|
|
181
|
+
parameters: {
|
|
182
|
+
type: "object",
|
|
183
|
+
properties: {
|
|
184
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
185
|
+
chat_id: { type: "string", description: "群聊 ID" },
|
|
186
|
+
user_ids: {
|
|
187
|
+
type: "array",
|
|
188
|
+
items: { type: "string" },
|
|
189
|
+
description: "要添加的用户 ID 列表",
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
required: ["bot", "chat_id", "user_ids"],
|
|
193
|
+
},
|
|
194
|
+
platforms: ["dingtalk"],
|
|
195
|
+
scopes: ["group"],
|
|
196
|
+
permissionLevel: "group_admin",
|
|
197
|
+
execute: async (args) => {
|
|
198
|
+
const { bot: botId, chat_id, user_ids } = args;
|
|
199
|
+
const bot = this.bots.get(botId);
|
|
200
|
+
if (!bot)
|
|
201
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
202
|
+
const success = await bot.updateChat(chat_id, {
|
|
203
|
+
add_useridlist: user_ids,
|
|
204
|
+
});
|
|
205
|
+
return { success, message: success ? "成员添加成功" : "添加失败" };
|
|
206
|
+
},
|
|
207
|
+
});
|
|
208
|
+
this.addTool({
|
|
209
|
+
name: "dingtalk_dept_info",
|
|
210
|
+
description: "获取钉钉部门详细信息",
|
|
211
|
+
parameters: {
|
|
212
|
+
type: "object",
|
|
213
|
+
properties: {
|
|
214
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
215
|
+
dept_id: { type: "string", description: "部门 ID" },
|
|
216
|
+
},
|
|
217
|
+
required: ["bot", "dept_id"],
|
|
218
|
+
},
|
|
219
|
+
platforms: ["dingtalk"],
|
|
220
|
+
scopes: ["group", "private"],
|
|
221
|
+
permissionLevel: "user",
|
|
222
|
+
execute: async (args) => {
|
|
223
|
+
const { bot: botId, dept_id } = args;
|
|
224
|
+
const bot = this.bots.get(botId);
|
|
225
|
+
if (!bot)
|
|
226
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
227
|
+
const info = await bot.getDepartmentInfo(Number(dept_id));
|
|
228
|
+
return info;
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
this.addTool({
|
|
232
|
+
name: "dingtalk_update_chat",
|
|
233
|
+
description: "更新钉钉群聊设置(改名、换群主、增减成员)",
|
|
234
|
+
parameters: {
|
|
235
|
+
type: "object",
|
|
236
|
+
properties: {
|
|
237
|
+
bot: { type: "string", description: "Bot 名称" },
|
|
238
|
+
chat_id: { type: "string", description: "群聊 ID" },
|
|
239
|
+
name: { type: "string", description: "新群名(可选)" },
|
|
240
|
+
owner: { type: "string", description: "新群主 userId(可选)" },
|
|
241
|
+
add_members: {
|
|
242
|
+
type: "string",
|
|
243
|
+
description: "要添加的成员 userId,逗号分隔(可选)",
|
|
244
|
+
},
|
|
245
|
+
remove_members: {
|
|
246
|
+
type: "string",
|
|
247
|
+
description: "要移除的成员 userId,逗号分隔(可选)",
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
required: ["bot", "chat_id"],
|
|
251
|
+
},
|
|
252
|
+
platforms: ["dingtalk"],
|
|
253
|
+
scopes: ["group"],
|
|
254
|
+
permissionLevel: "group_admin",
|
|
255
|
+
execute: async (args) => {
|
|
256
|
+
const { bot: botId, chat_id, name, owner, add_members, remove_members, } = args;
|
|
257
|
+
const bot = this.bots.get(botId);
|
|
258
|
+
if (!bot)
|
|
259
|
+
throw new Error(`Bot ${botId} 不存在`);
|
|
260
|
+
const options = {};
|
|
261
|
+
if (name)
|
|
262
|
+
options.name = name;
|
|
263
|
+
if (owner)
|
|
264
|
+
options.owner = owner;
|
|
265
|
+
if (add_members)
|
|
266
|
+
options.add_useridlist = add_members
|
|
267
|
+
.split(",")
|
|
268
|
+
.map((s) => s.trim());
|
|
269
|
+
if (remove_members)
|
|
270
|
+
options.del_useridlist = remove_members
|
|
271
|
+
.split(",")
|
|
272
|
+
.map((s) => s.trim());
|
|
273
|
+
await bot.updateChat(chat_id, options);
|
|
274
|
+
return { success: true, message: "群聊设置已更新" };
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
this.plugin.logger.debug("已注册钉钉平台管理工具");
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,OAAO,EAEP,0BAA0B,EAC1B,+BAA+B,EAC/B,2BAA2B,GAE5B,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC,MAAM,OAAO,eAAgB,SAAQ,OAAoB;IACvD,OAAO,CAAM;IAEb,YAAY,MAAc,EAAE,MAAW;QACrC,KAAK,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IAED,SAAS,CAAC,MAAyB;QACjC,OAA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OAAO,GAAQ,EAAE,CAAC;gBACxB,IAAI,IAAI;oBAAE,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;gBAC9B,IAAI,KAAK;oBAAE,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;gBACjC,IAAI,WAAW;oBACb,OAAO,CAAC,cAAc,GAAG,WAAW;yBACjC,KAAK,CAAC,GAAG,CAAC;yBACV,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBAClC,IAAI,cAAc;oBAChB,OAAO,CAAC,cAAc,GAAG,cAAc;yBACpC,KAAK,CAAC,GAAG,CAAC;yBACV,GAAG,CAAC,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBAClC,MAAM,GAAG,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;YAC/C,CAAC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;IAC1C,CAAC;CACF"}
|
package/lib/bot.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 钉钉 Bot 实现
|
|
3
|
+
*/
|
|
4
|
+
import { Bot, Message, SendOptions } from "zhin.js";
|
|
5
|
+
import type { DingTalkBotConfig, DingTalkMessage } from "./types.js";
|
|
6
|
+
import type { DingTalkAdapter } from "./adapter.js";
|
|
7
|
+
export declare class DingTalkBot implements Bot<DingTalkBotConfig, DingTalkMessage> {
|
|
8
|
+
adapter: DingTalkAdapter;
|
|
9
|
+
$config: DingTalkBotConfig;
|
|
10
|
+
$connected: boolean;
|
|
11
|
+
private router;
|
|
12
|
+
private accessToken;
|
|
13
|
+
private baseURL;
|
|
14
|
+
private sessionWebhooks;
|
|
15
|
+
get $id(): string;
|
|
16
|
+
get logger(): import("zhin.js").Logger;
|
|
17
|
+
constructor(adapter: DingTalkAdapter, router: any, $config: DingTalkBotConfig);
|
|
18
|
+
private request;
|
|
19
|
+
private setupWebhookRoute;
|
|
20
|
+
private handleWebhook;
|
|
21
|
+
private verifySignature;
|
|
22
|
+
private handleEvent;
|
|
23
|
+
private ensureAccessToken;
|
|
24
|
+
private refreshAccessToken;
|
|
25
|
+
$formatMessage(msg: DingTalkMessage): Message<DingTalkMessage>;
|
|
26
|
+
private parseMessageContent;
|
|
27
|
+
$sendMessage(options: SendOptions): Promise<string>;
|
|
28
|
+
$recallMessage(id: string): Promise<void>;
|
|
29
|
+
private formatSendContent;
|
|
30
|
+
$connect(): Promise<void>;
|
|
31
|
+
$disconnect(): Promise<void>;
|
|
32
|
+
getUserInfo(userId: string): Promise<any>;
|
|
33
|
+
getDepartmentUsers(deptId: number): Promise<any[]>;
|
|
34
|
+
sendWorkNotice(userIdList: string[], content: any): Promise<boolean>;
|
|
35
|
+
getDepartmentList(deptId?: number): Promise<any[]>;
|
|
36
|
+
getDepartmentInfo(deptId: number): Promise<any>;
|
|
37
|
+
createChat(name: string, ownerUserId: string, userIdList: string[]): Promise<string | null>;
|
|
38
|
+
getChatInfo(chatId: string): Promise<any>;
|
|
39
|
+
updateChat(chatId: string, options: {
|
|
40
|
+
name?: string;
|
|
41
|
+
owner?: string;
|
|
42
|
+
add_useridlist?: string[];
|
|
43
|
+
del_useridlist?: string[];
|
|
44
|
+
}): Promise<boolean>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=bot.d.ts.map
|
package/lib/bot.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot.d.ts","sourceRoot":"","sources":["../src/bot.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EACL,GAAG,EACH,OAAO,EACP,WAAW,EAIZ,MAAM,SAAS,CAAC;AAGjB,OAAO,KAAK,EACV,iBAAi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