@xuanyue202/dingtalk 2026.3.21

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.
@@ -0,0 +1,1256 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * 钉钉账户级配置 Schema
5
+ *
6
+ * 配置字段说明:
7
+ * - enabled: 是否启用该渠道
8
+ * - clientId: 钉钉应用的 AppKey
9
+ * - clientSecret: 钉钉应用的 AppSecret
10
+ * - dmPolicy: 单聊策略 (open=开放, pairing=配对, allowlist=白名单)
11
+ * - groupPolicy: 群聊策略 (open=开放, allowlist=白名单, disabled=禁用)
12
+ * - requireMention: 群聊是否需要 @机器人
13
+ * - allowFrom: 单聊白名单用户 ID 列表
14
+ * - groupAllowFrom: 群聊白名单会话 ID 列表
15
+ * - historyLimit: 历史消息数量限制
16
+ * - textChunkLimit: 文本分块大小限制
17
+ * - longTaskNoticeDelayMs: 长任务提醒延迟(毫秒,0 表示关闭)
18
+ * - enableAICard: 是否启用 AI Card 流式响应
19
+ * - maxFileSizeMB: 媒体文件大小限制 (MB)
20
+ * - inboundMedia: 入站媒体归档与保留策略
21
+ */
22
+ declare const DingtalkAccountSchema: z.ZodObject<{
23
+ /** 账户显示名 */
24
+ name: z.ZodOptional<z.ZodString>;
25
+ /** 是否启用钉钉渠道 */
26
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
27
+ /** 钉钉应用 AppKey (clientId) */
28
+ clientId: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, unknown>;
29
+ /** 钉钉应用 AppSecret (clientSecret) */
30
+ clientSecret: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, unknown>;
31
+ /** 单聊策略: open=开放, pairing=配对, allowlist=白名单 */
32
+ dmPolicy: z.ZodDefault<z.ZodOptional<z.ZodEnum<["open", "pairing", "allowlist"]>>>;
33
+ /** 群聊策略: open=开放, allowlist=白名单, disabled=禁用 */
34
+ groupPolicy: z.ZodDefault<z.ZodOptional<z.ZodEnum<["open", "allowlist", "disabled"]>>>;
35
+ /** 群聊是否需要 @机器人才响应 */
36
+ requireMention: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
37
+ /** 单聊白名单: 允许的用户 ID 列表 */
38
+ allowFrom: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
39
+ /** 群聊白名单: 允许的会话 ID 列表 */
40
+ groupAllowFrom: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
41
+ /** 历史消息数量限制 */
42
+ historyLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
43
+ /** 文本分块大小限制 (钉钉单条消息最大 4000 字符) */
44
+ textChunkLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
45
+ /** 长任务提醒延迟(毫秒),0 表示关闭 */
46
+ longTaskNoticeDelayMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
47
+ /** 是否启用 AI Card 流式响应 */
48
+ enableAICard: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
49
+ /** Gateway auth token(Bearer) */
50
+ gatewayToken: z.ZodOptional<z.ZodString>;
51
+ /** Gateway auth password(替代 gatewayToken) */
52
+ gatewayPassword: z.ZodOptional<z.ZodString>;
53
+ /** 媒体文件大小限制 (MB),默认 100MB */
54
+ maxFileSizeMB: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
55
+ /** 入站媒体归档策略 */
56
+ inboundMedia: z.ZodOptional<z.ZodObject<{
57
+ dir: z.ZodOptional<z.ZodString>;
58
+ keepDays: z.ZodOptional<z.ZodNumber>;
59
+ }, "strip", z.ZodTypeAny, {
60
+ dir?: string | undefined;
61
+ keepDays?: number | undefined;
62
+ }, {
63
+ dir?: string | undefined;
64
+ keepDays?: number | undefined;
65
+ }>>;
66
+ }, "strip", z.ZodTypeAny, {
67
+ enabled: boolean;
68
+ dmPolicy: "open" | "pairing" | "allowlist";
69
+ groupPolicy: "open" | "allowlist" | "disabled";
70
+ requireMention: boolean;
71
+ historyLimit: number;
72
+ textChunkLimit: number;
73
+ longTaskNoticeDelayMs: number;
74
+ enableAICard: boolean;
75
+ maxFileSizeMB: number;
76
+ name?: string | undefined;
77
+ clientId?: string | undefined;
78
+ clientSecret?: string | undefined;
79
+ allowFrom?: string[] | undefined;
80
+ groupAllowFrom?: string[] | undefined;
81
+ gatewayToken?: string | undefined;
82
+ gatewayPassword?: string | undefined;
83
+ inboundMedia?: {
84
+ dir?: string | undefined;
85
+ keepDays?: number | undefined;
86
+ } | undefined;
87
+ }, {
88
+ name?: string | undefined;
89
+ enabled?: boolean | undefined;
90
+ clientId?: unknown;
91
+ clientSecret?: unknown;
92
+ dmPolicy?: "open" | "pairing" | "allowlist" | undefined;
93
+ groupPolicy?: "open" | "allowlist" | "disabled" | undefined;
94
+ requireMention?: boolean | undefined;
95
+ allowFrom?: string[] | undefined;
96
+ groupAllowFrom?: string[] | undefined;
97
+ historyLimit?: number | undefined;
98
+ textChunkLimit?: number | undefined;
99
+ longTaskNoticeDelayMs?: number | undefined;
100
+ enableAICard?: boolean | undefined;
101
+ gatewayToken?: string | undefined;
102
+ gatewayPassword?: string | undefined;
103
+ maxFileSizeMB?: number | undefined;
104
+ inboundMedia?: {
105
+ dir?: string | undefined;
106
+ keepDays?: number | undefined;
107
+ } | undefined;
108
+ }>;
109
+ /**
110
+ * 钉钉渠道配置 Schema(支持多账户)
111
+ */
112
+ declare const DingtalkConfigSchema: z.ZodObject<{
113
+ /** 账户显示名 */
114
+ name: z.ZodOptional<z.ZodString>;
115
+ /** 是否启用钉钉渠道 */
116
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
117
+ /** 钉钉应用 AppKey (clientId) */
118
+ clientId: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, unknown>;
119
+ /** 钉钉应用 AppSecret (clientSecret) */
120
+ clientSecret: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, unknown>;
121
+ /** 单聊策略: open=开放, pairing=配对, allowlist=白名单 */
122
+ dmPolicy: z.ZodDefault<z.ZodOptional<z.ZodEnum<["open", "pairing", "allowlist"]>>>;
123
+ /** 群聊策略: open=开放, allowlist=白名单, disabled=禁用 */
124
+ groupPolicy: z.ZodDefault<z.ZodOptional<z.ZodEnum<["open", "allowlist", "disabled"]>>>;
125
+ /** 群聊是否需要 @机器人才响应 */
126
+ requireMention: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
127
+ /** 单聊白名单: 允许的用户 ID 列表 */
128
+ allowFrom: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
129
+ /** 群聊白名单: 允许的会话 ID 列表 */
130
+ groupAllowFrom: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
131
+ /** 历史消息数量限制 */
132
+ historyLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
133
+ /** 文本分块大小限制 (钉钉单条消息最大 4000 字符) */
134
+ textChunkLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
135
+ /** 长任务提醒延迟(毫秒),0 表示关闭 */
136
+ longTaskNoticeDelayMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
137
+ /** 是否启用 AI Card 流式响应 */
138
+ enableAICard: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
139
+ /** Gateway auth token(Bearer) */
140
+ gatewayToken: z.ZodOptional<z.ZodString>;
141
+ /** Gateway auth password(替代 gatewayToken) */
142
+ gatewayPassword: z.ZodOptional<z.ZodString>;
143
+ /** 媒体文件大小限制 (MB),默认 100MB */
144
+ maxFileSizeMB: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
145
+ /** 入站媒体归档策略 */
146
+ inboundMedia: z.ZodOptional<z.ZodObject<{
147
+ dir: z.ZodOptional<z.ZodString>;
148
+ keepDays: z.ZodOptional<z.ZodNumber>;
149
+ }, "strip", z.ZodTypeAny, {
150
+ dir?: string | undefined;
151
+ keepDays?: number | undefined;
152
+ }, {
153
+ dir?: string | undefined;
154
+ keepDays?: number | undefined;
155
+ }>>;
156
+ } & {
157
+ defaultAccount: z.ZodOptional<z.ZodString>;
158
+ accounts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
159
+ /** 账户显示名 */
160
+ name: z.ZodOptional<z.ZodString>;
161
+ /** 是否启用钉钉渠道 */
162
+ enabled: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
163
+ /** 钉钉应用 AppKey (clientId) */
164
+ clientId: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, unknown>;
165
+ /** 钉钉应用 AppSecret (clientSecret) */
166
+ clientSecret: z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, unknown>;
167
+ /** 单聊策略: open=开放, pairing=配对, allowlist=白名单 */
168
+ dmPolicy: z.ZodDefault<z.ZodOptional<z.ZodEnum<["open", "pairing", "allowlist"]>>>;
169
+ /** 群聊策略: open=开放, allowlist=白名单, disabled=禁用 */
170
+ groupPolicy: z.ZodDefault<z.ZodOptional<z.ZodEnum<["open", "allowlist", "disabled"]>>>;
171
+ /** 群聊是否需要 @机器人才响应 */
172
+ requireMention: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
173
+ /** 单聊白名单: 允许的用户 ID 列表 */
174
+ allowFrom: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
175
+ /** 群聊白名单: 允许的会话 ID 列表 */
176
+ groupAllowFrom: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
177
+ /** 历史消息数量限制 */
178
+ historyLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
179
+ /** 文本分块大小限制 (钉钉单条消息最大 4000 字符) */
180
+ textChunkLimit: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
181
+ /** 长任务提醒延迟(毫秒),0 表示关闭 */
182
+ longTaskNoticeDelayMs: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
183
+ /** 是否启用 AI Card 流式响应 */
184
+ enableAICard: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
185
+ /** Gateway auth token(Bearer) */
186
+ gatewayToken: z.ZodOptional<z.ZodString>;
187
+ /** Gateway auth password(替代 gatewayToken) */
188
+ gatewayPassword: z.ZodOptional<z.ZodString>;
189
+ /** 媒体文件大小限制 (MB),默认 100MB */
190
+ maxFileSizeMB: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
191
+ /** 入站媒体归档策略 */
192
+ inboundMedia: z.ZodOptional<z.ZodObject<{
193
+ dir: z.ZodOptional<z.ZodString>;
194
+ keepDays: z.ZodOptional<z.ZodNumber>;
195
+ }, "strip", z.ZodTypeAny, {
196
+ dir?: string | undefined;
197
+ keepDays?: number | undefined;
198
+ }, {
199
+ dir?: string | undefined;
200
+ keepDays?: number | undefined;
201
+ }>>;
202
+ }, "strip", z.ZodTypeAny, {
203
+ enabled: boolean;
204
+ dmPolicy: "open" | "pairing" | "allowlist";
205
+ groupPolicy: "open" | "allowlist" | "disabled";
206
+ requireMention: boolean;
207
+ historyLimit: number;
208
+ textChunkLimit: number;
209
+ longTaskNoticeDelayMs: number;
210
+ enableAICard: boolean;
211
+ maxFileSizeMB: number;
212
+ name?: string | undefined;
213
+ clientId?: string | undefined;
214
+ clientSecret?: string | undefined;
215
+ allowFrom?: string[] | undefined;
216
+ groupAllowFrom?: string[] | undefined;
217
+ gatewayToken?: string | undefined;
218
+ gatewayPassword?: string | undefined;
219
+ inboundMedia?: {
220
+ dir?: string | undefined;
221
+ keepDays?: number | undefined;
222
+ } | undefined;
223
+ }, {
224
+ name?: string | undefined;
225
+ enabled?: boolean | undefined;
226
+ clientId?: unknown;
227
+ clientSecret?: unknown;
228
+ dmPolicy?: "open" | "pairing" | "allowlist" | undefined;
229
+ groupPolicy?: "open" | "allowlist" | "disabled" | undefined;
230
+ requireMention?: boolean | undefined;
231
+ allowFrom?: string[] | undefined;
232
+ groupAllowFrom?: string[] | undefined;
233
+ historyLimit?: number | undefined;
234
+ textChunkLimit?: number | undefined;
235
+ longTaskNoticeDelayMs?: number | undefined;
236
+ enableAICard?: boolean | undefined;
237
+ gatewayToken?: string | undefined;
238
+ gatewayPassword?: string | undefined;
239
+ maxFileSizeMB?: number | undefined;
240
+ inboundMedia?: {
241
+ dir?: string | undefined;
242
+ keepDays?: number | undefined;
243
+ } | undefined;
244
+ }>>>;
245
+ }, "strip", z.ZodTypeAny, {
246
+ enabled: boolean;
247
+ dmPolicy: "open" | "pairing" | "allowlist";
248
+ groupPolicy: "open" | "allowlist" | "disabled";
249
+ requireMention: boolean;
250
+ historyLimit: number;
251
+ textChunkLimit: number;
252
+ longTaskNoticeDelayMs: number;
253
+ enableAICard: boolean;
254
+ maxFileSizeMB: number;
255
+ name?: string | undefined;
256
+ clientId?: string | undefined;
257
+ clientSecret?: string | undefined;
258
+ allowFrom?: string[] | undefined;
259
+ groupAllowFrom?: string[] | undefined;
260
+ gatewayToken?: string | undefined;
261
+ gatewayPassword?: string | undefined;
262
+ inboundMedia?: {
263
+ dir?: string | undefined;
264
+ keepDays?: number | undefined;
265
+ } | undefined;
266
+ defaultAccount?: string | undefined;
267
+ accounts?: Record<string, {
268
+ enabled: boolean;
269
+ dmPolicy: "open" | "pairing" | "allowlist";
270
+ groupPolicy: "open" | "allowlist" | "disabled";
271
+ requireMention: boolean;
272
+ historyLimit: number;
273
+ textChunkLimit: number;
274
+ longTaskNoticeDelayMs: number;
275
+ enableAICard: boolean;
276
+ maxFileSizeMB: number;
277
+ name?: string | undefined;
278
+ clientId?: string | undefined;
279
+ clientSecret?: string | undefined;
280
+ allowFrom?: string[] | undefined;
281
+ groupAllowFrom?: string[] | undefined;
282
+ gatewayToken?: string | undefined;
283
+ gatewayPassword?: string | undefined;
284
+ inboundMedia?: {
285
+ dir?: string | undefined;
286
+ keepDays?: number | undefined;
287
+ } | undefined;
288
+ }> | undefined;
289
+ }, {
290
+ name?: string | undefined;
291
+ enabled?: boolean | undefined;
292
+ clientId?: unknown;
293
+ clientSecret?: unknown;
294
+ dmPolicy?: "open" | "pairing" | "allowlist" | undefined;
295
+ groupPolicy?: "open" | "allowlist" | "disabled" | undefined;
296
+ requireMention?: boolean | undefined;
297
+ allowFrom?: string[] | undefined;
298
+ groupAllowFrom?: string[] | undefined;
299
+ historyLimit?: number | undefined;
300
+ textChunkLimit?: number | undefined;
301
+ longTaskNoticeDelayMs?: number | undefined;
302
+ enableAICard?: boolean | undefined;
303
+ gatewayToken?: string | undefined;
304
+ gatewayPassword?: string | undefined;
305
+ maxFileSizeMB?: number | undefined;
306
+ inboundMedia?: {
307
+ dir?: string | undefined;
308
+ keepDays?: number | undefined;
309
+ } | undefined;
310
+ defaultAccount?: string | undefined;
311
+ accounts?: Record<string, {
312
+ name?: string | undefined;
313
+ enabled?: boolean | undefined;
314
+ clientId?: unknown;
315
+ clientSecret?: unknown;
316
+ dmPolicy?: "open" | "pairing" | "allowlist" | undefined;
317
+ groupPolicy?: "open" | "allowlist" | "disabled" | undefined;
318
+ requireMention?: boolean | undefined;
319
+ allowFrom?: string[] | undefined;
320
+ groupAllowFrom?: string[] | undefined;
321
+ historyLimit?: number | undefined;
322
+ textChunkLimit?: number | undefined;
323
+ longTaskNoticeDelayMs?: number | undefined;
324
+ enableAICard?: boolean | undefined;
325
+ gatewayToken?: string | undefined;
326
+ gatewayPassword?: string | undefined;
327
+ maxFileSizeMB?: number | undefined;
328
+ inboundMedia?: {
329
+ dir?: string | undefined;
330
+ keepDays?: number | undefined;
331
+ } | undefined;
332
+ }> | undefined;
333
+ }>;
334
+ type DingtalkConfig = z.output<typeof DingtalkConfigSchema>;
335
+ type DingtalkAccountConfig = z.output<typeof DingtalkAccountSchema>;
336
+ type PartialDingtalkAccountConfig = Partial<DingtalkAccountConfig>;
337
+ type PartialDingtalkConfig = Partial<Omit<DingtalkConfig, "accounts">> & {
338
+ accounts?: Record<string, PartialDingtalkAccountConfig>;
339
+ };
340
+ interface PluginConfig$1 {
341
+ channels?: {
342
+ dingtalk?: PartialDingtalkConfig;
343
+ };
344
+ }
345
+ declare const DEFAULT_ACCOUNT_ID = "default";
346
+
347
+ /**
348
+ * 钉钉出站适配器
349
+ *
350
+ * 实现 ChannelOutboundAdapter 接口,提供:
351
+ * - sendText: 发送文本消息
352
+ * - sendMedia: 发送媒体消息(含回退逻辑)
353
+ * - chunker: 长消息分块(利用 Moltbot 核心的 markdown-aware 分块)
354
+ *
355
+ * 配置:
356
+ * - deliveryMode: "direct" (直接发送,不使用队列)
357
+ * - textChunkLimit: 4000 (钉钉 Markdown 消息最大字符数)
358
+ * - chunkerMode: "markdown" (使用 markdown 感知的分块模式)
359
+ */
360
+
361
+ /**
362
+ * 发送结果类型
363
+ */
364
+ interface SendResult {
365
+ channel: string;
366
+ messageId: string;
367
+ chatId?: string;
368
+ conversationId?: string;
369
+ }
370
+
371
+ /**
372
+ * 钉钉 Onboarding 适配器
373
+ *
374
+ * 实现 ChannelOnboardingAdapter 接口,提供:
375
+ * - getStatus: 获取渠道配置状态
376
+ * - configure: 交互式配置向导
377
+ * - dmPolicy: DM 策略配置
378
+ * - disable: 禁用渠道
379
+ */
380
+
381
+ /**
382
+ * 配置接口类型
383
+ */
384
+ interface PluginConfig {
385
+ channels?: {
386
+ dingtalk?: Partial<DingtalkConfig>;
387
+ };
388
+ }
389
+ /**
390
+ * WizardPrompter 接口(简化版)
391
+ */
392
+ interface WizardPrompter {
393
+ note: (message: string, title?: string) => Promise<void>;
394
+ text: (opts: {
395
+ message: string;
396
+ placeholder?: string;
397
+ initialValue?: string;
398
+ validate?: (value: string | undefined) => string | undefined;
399
+ }) => Promise<string | symbol>;
400
+ confirm: (opts: {
401
+ message: string;
402
+ initialValue?: boolean;
403
+ }) => Promise<boolean>;
404
+ select: <T>(opts: {
405
+ message: string;
406
+ options: Array<{
407
+ value: T;
408
+ label: string;
409
+ }>;
410
+ initialValue?: T;
411
+ }) => Promise<T | symbol>;
412
+ }
413
+
414
+ /**
415
+ * 发送消息结果
416
+ */
417
+ interface DingtalkSendResult {
418
+ /** 消息 ID */
419
+ messageId: string;
420
+ /** 会话 ID */
421
+ conversationId: string;
422
+ }
423
+ /**
424
+ * 解析后的钉钉账户配置
425
+ * 用于 ChannelPlugin config 适配器
426
+ */
427
+ interface ResolvedDingtalkAccount {
428
+ /** 账户 ID */
429
+ accountId: string;
430
+ /** 是否启用 */
431
+ enabled: boolean;
432
+ /** 是否已配置(有凭证) */
433
+ configured: boolean;
434
+ /** 客户端 ID */
435
+ clientId?: string;
436
+ }
437
+
438
+ /**
439
+ * 钉钉渠道插件
440
+ *
441
+ * 实现 ChannelPlugin 接口,提供完整的钉钉消息渠道功能
442
+ */
443
+ declare const dingtalkPlugin: {
444
+ id: string;
445
+ /**
446
+ * 渠道元数据
447
+ * Requirements: 1.2
448
+ */
449
+ meta: {
450
+ id: "dingtalk";
451
+ label: "DingTalk";
452
+ selectionLabel: "DingTalk (钉钉)";
453
+ docsPath: "/channels/dingtalk";
454
+ docsLabel: "dingtalk";
455
+ blurb: "钉钉企业消息";
456
+ aliases: readonly ["ding"];
457
+ order: 71;
458
+ };
459
+ /**
460
+ * 渠道能力声明
461
+ * Requirements: 1.3
462
+ */
463
+ capabilities: {
464
+ chatTypes: readonly ["direct", "channel"];
465
+ media: boolean;
466
+ reactions: boolean;
467
+ threads: boolean;
468
+ edit: boolean;
469
+ reply: boolean;
470
+ polls: boolean;
471
+ blockStreaming: boolean;
472
+ };
473
+ /**
474
+ * 配置 Schema
475
+ * Requirements: 1.4
476
+ */
477
+ configSchema: {
478
+ schema: {
479
+ type: string;
480
+ additionalProperties: boolean;
481
+ properties: {
482
+ enabled: {
483
+ type: string;
484
+ };
485
+ name: {
486
+ type: string;
487
+ };
488
+ defaultAccount: {
489
+ type: string;
490
+ };
491
+ clientId: {
492
+ type: string;
493
+ };
494
+ clientSecret: {
495
+ type: string;
496
+ };
497
+ connectionMode: {
498
+ type: string;
499
+ enum: string[];
500
+ };
501
+ dmPolicy: {
502
+ type: string;
503
+ enum: string[];
504
+ };
505
+ groupPolicy: {
506
+ type: string;
507
+ enum: string[];
508
+ };
509
+ requireMention: {
510
+ type: string;
511
+ };
512
+ allowFrom: {
513
+ type: string;
514
+ items: {
515
+ type: string;
516
+ };
517
+ };
518
+ groupAllowFrom: {
519
+ type: string;
520
+ items: {
521
+ type: string;
522
+ };
523
+ };
524
+ historyLimit: {
525
+ type: string;
526
+ minimum: number;
527
+ };
528
+ textChunkLimit: {
529
+ type: string;
530
+ minimum: number;
531
+ };
532
+ longTaskNoticeDelayMs: {
533
+ type: string;
534
+ minimum: number;
535
+ };
536
+ enableAICard: {
537
+ type: string;
538
+ };
539
+ gatewayToken: {
540
+ type: string;
541
+ };
542
+ gatewayPassword: {
543
+ type: string;
544
+ };
545
+ maxFileSizeMB: {
546
+ type: string;
547
+ minimum: number;
548
+ };
549
+ inboundMedia: {
550
+ type: string;
551
+ additionalProperties: boolean;
552
+ properties: {
553
+ dir: {
554
+ type: string;
555
+ };
556
+ keepDays: {
557
+ type: string;
558
+ minimum: number;
559
+ };
560
+ };
561
+ };
562
+ accounts: {
563
+ type: string;
564
+ additionalProperties: {
565
+ type: string;
566
+ additionalProperties: boolean;
567
+ properties: {
568
+ name: {
569
+ type: string;
570
+ };
571
+ enabled: {
572
+ type: string;
573
+ };
574
+ clientId: {
575
+ type: string;
576
+ };
577
+ clientSecret: {
578
+ type: string;
579
+ };
580
+ connectionMode: {
581
+ type: string;
582
+ enum: string[];
583
+ };
584
+ dmPolicy: {
585
+ type: string;
586
+ enum: string[];
587
+ };
588
+ groupPolicy: {
589
+ type: string;
590
+ enum: string[];
591
+ };
592
+ requireMention: {
593
+ type: string;
594
+ };
595
+ allowFrom: {
596
+ type: string;
597
+ items: {
598
+ type: string;
599
+ };
600
+ };
601
+ groupAllowFrom: {
602
+ type: string;
603
+ items: {
604
+ type: string;
605
+ };
606
+ };
607
+ historyLimit: {
608
+ type: string;
609
+ minimum: number;
610
+ };
611
+ textChunkLimit: {
612
+ type: string;
613
+ minimum: number;
614
+ };
615
+ longTaskNoticeDelayMs: {
616
+ type: string;
617
+ minimum: number;
618
+ };
619
+ enableAICard: {
620
+ type: string;
621
+ };
622
+ gatewayToken: {
623
+ type: string;
624
+ };
625
+ gatewayPassword: {
626
+ type: string;
627
+ };
628
+ maxFileSizeMB: {
629
+ type: string;
630
+ minimum: number;
631
+ };
632
+ inboundMedia: {
633
+ type: string;
634
+ additionalProperties: boolean;
635
+ properties: {
636
+ dir: {
637
+ type: string;
638
+ };
639
+ keepDays: {
640
+ type: string;
641
+ minimum: number;
642
+ };
643
+ };
644
+ };
645
+ };
646
+ };
647
+ };
648
+ };
649
+ };
650
+ };
651
+ /**
652
+ * 配置重载触发器
653
+ */
654
+ reload: {
655
+ configPrefixes: string[];
656
+ };
657
+ /**
658
+ * 账户配置适配器
659
+ * Requirements: 2.1, 2.2, 2.3
660
+ */
661
+ config: {
662
+ /**
663
+ * 列出所有账户 ID
664
+ * Requirements: 2.1
665
+ */
666
+ listAccountIds: (cfg: PluginConfig$1) => string[];
667
+ /**
668
+ * 解析账户配置
669
+ * Requirements: 2.2
670
+ */
671
+ resolveAccount: (cfg: PluginConfig$1, accountId?: string) => ResolvedDingtalkAccount;
672
+ /**
673
+ * 获取默认账户 ID
674
+ */
675
+ defaultAccountId: (cfg: PluginConfig$1) => string;
676
+ /**
677
+ * 设置账户启用状态
678
+ */
679
+ setAccountEnabled: (params: {
680
+ cfg: PluginConfig$1;
681
+ accountId?: string;
682
+ enabled: boolean;
683
+ }) => PluginConfig$1;
684
+ /**
685
+ * 删除账户配置
686
+ */
687
+ deleteAccount: (params: {
688
+ cfg: PluginConfig$1;
689
+ accountId?: string;
690
+ }) => PluginConfig$1;
691
+ /**
692
+ * 检查账户是否已配置
693
+ * Requirements: 2.3
694
+ */
695
+ isConfigured: (_account: ResolvedDingtalkAccount, cfg: PluginConfig$1, accountId?: string) => boolean;
696
+ /**
697
+ * 描述账户信息
698
+ */
699
+ describeAccount: (account: ResolvedDingtalkAccount) => {
700
+ accountId: string;
701
+ enabled: boolean;
702
+ configured: boolean;
703
+ };
704
+ /**
705
+ * 解析白名单
706
+ */
707
+ resolveAllowFrom: (params: {
708
+ cfg: PluginConfig$1;
709
+ accountId?: string;
710
+ }) => string[];
711
+ /**
712
+ * 格式化白名单条目
713
+ */
714
+ formatAllowFrom: (params: {
715
+ allowFrom: (string | number)[];
716
+ }) => string[];
717
+ };
718
+ /**
719
+ * 安全警告收集器
720
+ */
721
+ security: {
722
+ collectWarnings: (params: {
723
+ cfg: PluginConfig$1;
724
+ }) => string[];
725
+ };
726
+ /**
727
+ * 设置向导适配器
728
+ */
729
+ setup: {
730
+ resolveAccountId: (params: {
731
+ cfg: PluginConfig$1;
732
+ accountId?: string;
733
+ }) => string;
734
+ applyAccountConfig: (params: {
735
+ cfg: PluginConfig$1;
736
+ accountId?: string;
737
+ config?: Record<string, unknown>;
738
+ }) => PluginConfig$1;
739
+ };
740
+ /**
741
+ * Onboarding 适配器
742
+ */
743
+ onboarding: {
744
+ channel: "dingtalk";
745
+ getStatus: (params: {
746
+ cfg: PluginConfig;
747
+ }) => Promise<{
748
+ channel: "dingtalk";
749
+ configured: boolean;
750
+ statusLines: string[];
751
+ selectionHint: string;
752
+ quickstartScore: number;
753
+ }>;
754
+ configure: (params: {
755
+ cfg: PluginConfig;
756
+ prompter: WizardPrompter;
757
+ }) => Promise<{
758
+ cfg: PluginConfig;
759
+ accountId: string;
760
+ }>;
761
+ dmPolicy: {
762
+ label: string;
763
+ channel: "dingtalk";
764
+ policyKey: string;
765
+ allowFromKey: string;
766
+ getCurrent: (cfg: PluginConfig) => "open" | "pairing" | "allowlist";
767
+ setPolicy: (cfg: PluginConfig, policy: "open" | "pairing" | "allowlist") => PluginConfig;
768
+ promptAllowFrom: (params: {
769
+ cfg: PluginConfig;
770
+ prompter: WizardPrompter;
771
+ }) => Promise<PluginConfig>;
772
+ };
773
+ disable: (cfg: PluginConfig) => PluginConfig;
774
+ };
775
+ /**
776
+ * 出站消息适配器
777
+ * Requirements: 7.1, 7.6
778
+ */
779
+ outbound: {
780
+ deliveryMode: "direct";
781
+ textChunkLimit: number;
782
+ chunkerMode: "markdown";
783
+ chunker: (text: string, limit: number) => string[];
784
+ sendText: (params: {
785
+ cfg: PluginConfig$1;
786
+ to: string;
787
+ text: string;
788
+ accountId?: string;
789
+ }) => Promise<SendResult>;
790
+ sendMedia: (params: {
791
+ cfg: PluginConfig$1;
792
+ to: string;
793
+ text?: string;
794
+ mediaUrl?: string;
795
+ accountId?: string;
796
+ }) => Promise<SendResult>;
797
+ };
798
+ /**
799
+ * Gateway 连接管理适配器
800
+ * Requirements: 3.1
801
+ */
802
+ gateway: {
803
+ /**
804
+ * 启动账户连接
805
+ * Requirements: 3.1
806
+ */
807
+ startAccount: (ctx: {
808
+ cfg: PluginConfig$1;
809
+ runtime?: unknown;
810
+ channelRuntime?: unknown;
811
+ abortSignal?: AbortSignal;
812
+ accountId: string;
813
+ setStatus?: (status: Record<string, unknown>) => void;
814
+ log?: {
815
+ info: (msg: string) => void;
816
+ error: (msg: string) => void;
817
+ };
818
+ }) => Promise<void>;
819
+ stopAccount: (ctx: {
820
+ accountId: string;
821
+ }) => Promise<void>;
822
+ getStatus: () => {
823
+ connected: boolean;
824
+ };
825
+ };
826
+ };
827
+
828
+ /**
829
+ * 钉钉发送消息 API
830
+ *
831
+ * 提供:
832
+ * - sendMessageDingtalk: 发送 Markdown 消息(单聊/群聊)
833
+ *
834
+ * API 文档:
835
+ * - 单聊: https://open.dingtalk.com/document/orgapp/chatbots-send-one-on-one-chat-messages-in-batches
836
+ * - 群聊: https://open.dingtalk.com/document/orgapp/the-robot-sends-a-group-message
837
+ */
838
+
839
+ /**
840
+ * 发送消息参数
841
+ */
842
+ interface SendMessageParams {
843
+ /** 钉钉配置 */
844
+ cfg: DingtalkConfig;
845
+ /** 目标 ID(用户 ID 或会话 ID) */
846
+ to: string;
847
+ /** 消息文本内容 */
848
+ text: string;
849
+ /** 聊天类型 */
850
+ chatType: "direct" | "group";
851
+ /** Markdown 消息标题(可选) */
852
+ title?: string;
853
+ }
854
+ /**
855
+ * 发送 Markdown 消息到钉钉
856
+ *
857
+ * 根据 chatType 调用不同的 API:
858
+ * - direct: /v1.0/robot/oToMessages/batchSend (单聊批量发送)
859
+ * - group: /v1.0/robot/groupMessages/send (群聊发送)
860
+ *
861
+ * 始终使用 sampleMarkdown 模板,支持表格、代码块等格式
862
+ *
863
+ * @param params 发送参数
864
+ * @returns 发送结果
865
+ * @throws Error 如果凭证未配置或 API 调用失败
866
+ */
867
+ declare function sendMessageDingtalk(params: SendMessageParams): Promise<DingtalkSendResult>;
868
+
869
+ /**
870
+ * 钉钉插件运行时管理
871
+ *
872
+ * 提供对 Moltbot 核心运行时的访问。
873
+ *
874
+ * 重要:这个模块存储完整的 PluginRuntime,包含 core.channel.routing、
875
+ * core.channel.reply 等 API,用于消息分发到 Agent。
876
+ *
877
+ * 使用方式:
878
+ * 1. 插件注册时调用 setDingtalkRuntime(runtime) 设置完整 runtime
879
+ * 2. 消息处理时调用 getDingtalkRuntime() 获取 runtime 进行分发
880
+ */
881
+ /**
882
+ * Moltbot 插件运行时接口
883
+ *
884
+ * 包含 Moltbot 核心 API,用于:
885
+ * - 路由解析 (channel.routing.resolveAgentRoute)
886
+ * - 实时消息分发 (channel.reply.dispatchReplyWithDispatcher /
887
+ * channel.reply.dispatchReplyWithBufferedBlockDispatcher)
888
+ * - 系统事件 (system.enqueueSystemEvent)
889
+ */
890
+ interface PluginRuntime {
891
+ /** 日志函数 */
892
+ log?: (msg: string) => void;
893
+ /** 错误日志函数 */
894
+ error?: (msg: string) => void;
895
+ /** Moltbot 核心 API */
896
+ channel?: {
897
+ routing?: {
898
+ resolveAgentRoute?: (params: {
899
+ cfg: unknown;
900
+ channel: string;
901
+ peer: {
902
+ kind: string;
903
+ id: string;
904
+ };
905
+ }) => {
906
+ sessionKey: string;
907
+ accountId: string;
908
+ agentId?: string;
909
+ };
910
+ };
911
+ session?: {
912
+ resolveStorePath?: (store: unknown, params: {
913
+ agentId?: string;
914
+ }) => string | undefined;
915
+ recordInboundSession?: (params: {
916
+ storePath: string;
917
+ sessionKey: string;
918
+ ctx: unknown;
919
+ updateLastRoute?: {
920
+ sessionKey: string;
921
+ channel: string;
922
+ to: string;
923
+ accountId?: string;
924
+ threadId?: string | number;
925
+ };
926
+ onRecordError?: (err: unknown) => void;
927
+ }) => Promise<void>;
928
+ };
929
+ reply?: {
930
+ dispatchReplyWithDispatcher?: (params: {
931
+ ctx: unknown;
932
+ cfg: unknown;
933
+ dispatcherOptions: {
934
+ deliver: (payload: unknown, info?: {
935
+ kind?: string;
936
+ }) => Promise<void>;
937
+ onError?: (err: unknown, info: {
938
+ kind: string;
939
+ }) => void;
940
+ onSkip?: (payload: unknown, info: {
941
+ kind: string;
942
+ reason: string;
943
+ }) => void;
944
+ onReplyStart?: () => Promise<void> | void;
945
+ humanDelay?: unknown;
946
+ };
947
+ replyOptions?: unknown;
948
+ }) => Promise<unknown>;
949
+ dispatchReplyFromConfig?: (params: {
950
+ ctx: unknown;
951
+ cfg: unknown;
952
+ dispatcher?: unknown;
953
+ replyOptions?: unknown;
954
+ }) => Promise<{
955
+ queuedFinal: boolean;
956
+ counts: {
957
+ final: number;
958
+ };
959
+ }>;
960
+ dispatchReplyWithBufferedBlockDispatcher?: (params: {
961
+ ctx: unknown;
962
+ cfg: unknown;
963
+ dispatcherOptions: {
964
+ deliver: (payload: unknown, info?: {
965
+ kind?: string;
966
+ }) => Promise<void>;
967
+ onError?: (err: unknown, info: {
968
+ kind: string;
969
+ }) => void;
970
+ onSkip?: (payload: unknown, info: {
971
+ kind: string;
972
+ reason: string;
973
+ }) => void;
974
+ onReplyStart?: () => Promise<void> | void;
975
+ humanDelay?: unknown;
976
+ };
977
+ replyOptions?: unknown;
978
+ }) => Promise<unknown>;
979
+ finalizeInboundContext?: (ctx: unknown) => unknown;
980
+ createReplyDispatcher?: (params: unknown) => unknown;
981
+ createReplyDispatcherWithTyping?: (params: unknown) => {
982
+ dispatcher: unknown;
983
+ replyOptions?: unknown;
984
+ markDispatchIdle?: () => void;
985
+ };
986
+ resolveHumanDelayConfig?: (cfg: unknown, agentId?: string) => unknown;
987
+ resolveEnvelopeFormatOptions?: (cfg: unknown) => unknown;
988
+ formatAgentEnvelope?: (params: unknown) => string;
989
+ };
990
+ text?: {
991
+ resolveTextChunkLimit?: (params: {
992
+ cfg: unknown;
993
+ channel: string;
994
+ defaultLimit?: number;
995
+ }) => number;
996
+ resolveChunkMode?: (cfg: unknown, channel: string) => unknown;
997
+ resolveMarkdownTableMode?: (params: {
998
+ cfg: unknown;
999
+ channel: string;
1000
+ }) => unknown;
1001
+ convertMarkdownTables?: (text: string, mode: unknown) => string;
1002
+ chunkTextWithMode?: (text: string, limit: number, mode: unknown) => string[];
1003
+ /** Markdown 感知的文本分块,不会在代码块中间断开 */
1004
+ chunkMarkdownText?: (text: string, limit: number) => string[];
1005
+ };
1006
+ };
1007
+ system?: {
1008
+ enqueueSystemEvent?: (message: string, options?: unknown) => void;
1009
+ };
1010
+ [key: string]: unknown;
1011
+ }
1012
+ /**
1013
+ * 设置钉钉插件运行时
1014
+ *
1015
+ * 在插件注册时由 Moltbot 调用,传入完整的 PluginRuntime。
1016
+ *
1017
+ * @param next Moltbot 插件运行时实例(完整版,包含 core API)
1018
+ */
1019
+ declare function setDingtalkRuntime(next: PluginRuntime): void;
1020
+ /**
1021
+ * 获取钉钉插件运行时
1022
+ *
1023
+ * 在消息处理时调用,获取完整的 runtime 用于分发消息到 Agent。
1024
+ *
1025
+ * @returns Moltbot 插件运行时实例
1026
+ * @throws Error 如果运行时未初始化(插件未正确注册)
1027
+ */
1028
+ declare function getDingtalkRuntime(): PluginRuntime;
1029
+
1030
+ /**
1031
+ * @xuanyue202/dingtalk
1032
+ * 钉钉渠道插件入口
1033
+ *
1034
+ * 导出:
1035
+ * - dingtalkPlugin: ChannelPlugin 实现
1036
+ * - sendMessageDingtalk: 发送消息函数
1037
+ * - DEFAULT_ACCOUNT_ID: 默认账户 ID
1038
+ *
1039
+ * Requirements: 1.1
1040
+ */
1041
+ /**
1042
+ * Moltbot 插件 API 接口
1043
+ *
1044
+ * 包含:
1045
+ * - registerChannel: 注册渠道插件
1046
+ * - runtime: 完整的 Moltbot 运行时(包含 core API)
1047
+ */
1048
+ interface MoltbotPluginApi {
1049
+ registerChannel: (opts: {
1050
+ plugin: unknown;
1051
+ }) => void;
1052
+ /** Moltbot 运行时,包含 channel.routing、channel.reply 等核心 API */
1053
+ runtime?: unknown;
1054
+ [key: string]: unknown;
1055
+ }
1056
+
1057
+ /**
1058
+ * 钉钉插件定义
1059
+ *
1060
+ * 包含:
1061
+ * - id: 插件标识符
1062
+ * - name: 插件名称
1063
+ * - description: 插件描述
1064
+ * - configSchema: 配置 JSON Schema
1065
+ * - register: 注册函数,调用 api.registerChannel 并设置 runtime
1066
+ *
1067
+ * Requirements: 1.1
1068
+ */
1069
+ declare const plugin: {
1070
+ id: string;
1071
+ name: string;
1072
+ description: string;
1073
+ configSchema: {
1074
+ type: string;
1075
+ additionalProperties: boolean;
1076
+ properties: {
1077
+ enabled: {
1078
+ type: string;
1079
+ };
1080
+ name: {
1081
+ type: string;
1082
+ };
1083
+ defaultAccount: {
1084
+ type: string;
1085
+ };
1086
+ clientId: {
1087
+ type: string;
1088
+ };
1089
+ clientSecret: {
1090
+ type: string;
1091
+ };
1092
+ dmPolicy: {
1093
+ type: string;
1094
+ enum: string[];
1095
+ };
1096
+ groupPolicy: {
1097
+ type: string;
1098
+ enum: string[];
1099
+ };
1100
+ requireMention: {
1101
+ type: string;
1102
+ };
1103
+ allowFrom: {
1104
+ type: string;
1105
+ items: {
1106
+ type: string;
1107
+ };
1108
+ };
1109
+ groupAllowFrom: {
1110
+ type: string;
1111
+ items: {
1112
+ type: string;
1113
+ };
1114
+ };
1115
+ historyLimit: {
1116
+ type: string;
1117
+ minimum: number;
1118
+ };
1119
+ textChunkLimit: {
1120
+ type: string;
1121
+ minimum: number;
1122
+ };
1123
+ longTaskNoticeDelayMs: {
1124
+ type: string;
1125
+ minimum: number;
1126
+ };
1127
+ connectionMode: {
1128
+ type: string;
1129
+ enum: string[];
1130
+ };
1131
+ enableAICard: {
1132
+ type: string;
1133
+ };
1134
+ gatewayToken: {
1135
+ type: string;
1136
+ };
1137
+ gatewayPassword: {
1138
+ type: string;
1139
+ };
1140
+ maxFileSizeMB: {
1141
+ type: string;
1142
+ minimum: number;
1143
+ };
1144
+ inboundMedia: {
1145
+ type: string;
1146
+ additionalProperties: boolean;
1147
+ properties: {
1148
+ dir: {
1149
+ type: string;
1150
+ };
1151
+ keepDays: {
1152
+ type: string;
1153
+ minimum: number;
1154
+ };
1155
+ };
1156
+ };
1157
+ accounts: {
1158
+ type: string;
1159
+ additionalProperties: {
1160
+ type: string;
1161
+ additionalProperties: boolean;
1162
+ properties: {
1163
+ name: {
1164
+ type: string;
1165
+ };
1166
+ enabled: {
1167
+ type: string;
1168
+ };
1169
+ clientId: {
1170
+ type: string;
1171
+ };
1172
+ clientSecret: {
1173
+ type: string;
1174
+ };
1175
+ dmPolicy: {
1176
+ type: string;
1177
+ enum: string[];
1178
+ };
1179
+ groupPolicy: {
1180
+ type: string;
1181
+ enum: string[];
1182
+ };
1183
+ requireMention: {
1184
+ type: string;
1185
+ };
1186
+ allowFrom: {
1187
+ type: string;
1188
+ items: {
1189
+ type: string;
1190
+ };
1191
+ };
1192
+ groupAllowFrom: {
1193
+ type: string;
1194
+ items: {
1195
+ type: string;
1196
+ };
1197
+ };
1198
+ historyLimit: {
1199
+ type: string;
1200
+ minimum: number;
1201
+ };
1202
+ textChunkLimit: {
1203
+ type: string;
1204
+ minimum: number;
1205
+ };
1206
+ longTaskNoticeDelayMs: {
1207
+ type: string;
1208
+ minimum: number;
1209
+ };
1210
+ connectionMode: {
1211
+ type: string;
1212
+ enum: string[];
1213
+ };
1214
+ enableAICard: {
1215
+ type: string;
1216
+ };
1217
+ gatewayToken: {
1218
+ type: string;
1219
+ };
1220
+ gatewayPassword: {
1221
+ type: string;
1222
+ };
1223
+ maxFileSizeMB: {
1224
+ type: string;
1225
+ minimum: number;
1226
+ };
1227
+ inboundMedia: {
1228
+ type: string;
1229
+ additionalProperties: boolean;
1230
+ properties: {
1231
+ dir: {
1232
+ type: string;
1233
+ };
1234
+ keepDays: {
1235
+ type: string;
1236
+ minimum: number;
1237
+ };
1238
+ };
1239
+ };
1240
+ };
1241
+ };
1242
+ };
1243
+ };
1244
+ };
1245
+ /**
1246
+ * 注册钉钉渠道插件
1247
+ *
1248
+ * 1. 设置完整的 Moltbot 运行时(包含 core API)
1249
+ * 2. 调用 api.registerChannel 将 dingtalkPlugin 注册到 Moltbot
1250
+ *
1251
+ * Requirements: 1.1
1252
+ */
1253
+ register(api: MoltbotPluginApi): void;
1254
+ };
1255
+
1256
+ export { DEFAULT_ACCOUNT_ID, type DingtalkAccountConfig, type DingtalkConfig, type DingtalkSendResult, type MoltbotPluginApi, type ResolvedDingtalkAccount, plugin as default, dingtalkPlugin, getDingtalkRuntime, sendMessageDingtalk, setDingtalkRuntime };