ppagent 0.0.9 → 0.0.11

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.
Files changed (3) hide show
  1. package/dist/lib.d.ts +3421 -0
  2. package/dist/lib.js +45 -0
  3. package/package.json +1 -1
package/dist/lib.d.ts ADDED
@@ -0,0 +1,3421 @@
1
+ import Emittery from 'emittery';
2
+ import * as fastify from 'fastify';
3
+ import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify';
4
+ import { WebSocket } from 'ws';
5
+ import { ReadStream, Stats } from 'node:fs';
6
+ import { Buffer as Buffer$1 } from 'node:buffer';
7
+ import { ISchema, SchemaProperties } from '@formily/react';
8
+ import * as http from 'http';
9
+ import { AuthenticationClient, RestClient } from '@directus/sdk';
10
+ import pino, { Level } from 'pino';
11
+ import Keyv from 'keyv';
12
+ import { StreamChatReq, CozeAPI, CreateChatData, StreamChatData } from '@coze/api';
13
+ import OpenAI, { ClientOptions } from 'openai';
14
+ import ffmpeg from 'fluent-ffmpeg';
15
+ import { ReadStream as ReadStream$1 } from 'fs';
16
+
17
+ interface IAsyncFile {
18
+ getFormat(): "text" | "binary";
19
+ asBuffer(): Promise<Buffer$1 | undefined>;
20
+ asPath(): Promise<string | undefined>;
21
+ asLocalPath(): Promise<string>;
22
+ /**
23
+ * 确保该文件可以通过url访问,该文件将被复制到public/temp/目录下,同时根据config中httpUrl生成访问路径
24
+ */
25
+ asUrl(): Promise<string>;
26
+ asBase64(): Promise<string | undefined>;
27
+ asText(): Promise<string>;
28
+ asReadStream(): Promise<ReadStream>;
29
+ info(): Promise<Stats>;
30
+ get name(): string;
31
+ }
32
+ interface IAsyncFileSource {
33
+ /**
34
+ * 文件内容或者路径
35
+ */
36
+ data: Buffer$1 | string;
37
+ /**
38
+ * 当路径是一个url的时候,类型为path
39
+ */
40
+ type: "buffer" | "path" | "base64" | "text";
41
+ name: string;
42
+ textEncoding?: BufferEncoding;
43
+ }
44
+ type AsyncFileLoader = () => Promise<IAsyncFileSource>;
45
+ declare class AsyncFile implements IAsyncFile {
46
+ protected loader: AsyncFileLoader;
47
+ protected format: "text" | "binary";
48
+ /**
49
+ * init async file.use loader to load init data.
50
+ * @param loader
51
+ * @param format
52
+ */
53
+ constructor(loader: AsyncFileLoader, format: "text" | "binary");
54
+ protected tempDir: string;
55
+ protected buffer: Buffer$1 | undefined;
56
+ protected path: string | undefined;
57
+ protected localPath: string;
58
+ protected base64: string | undefined;
59
+ protected text: string | undefined;
60
+ protected textEncoding: BufferEncoding | undefined;
61
+ protected _name: string;
62
+ protected url: string;
63
+ protected _info: Stats;
64
+ protected loaded: boolean;
65
+ get name(): string;
66
+ protected load(): Promise<void>;
67
+ protected setSource({ data, type, name, textEncoding }: IAsyncFileSource): Promise<void>;
68
+ protected loadBufferFromPath(localPath: string): Promise<Buffer$1>;
69
+ protected saveFile(): Promise<string>;
70
+ getFormat(): "binary" | "text";
71
+ asBuffer(): Promise<Buffer$1 | undefined>;
72
+ asPath(): Promise<string>;
73
+ asBase64(): Promise<string>;
74
+ asText(): Promise<string>;
75
+ asUrl(): Promise<string>;
76
+ asLocalPath(): Promise<string>;
77
+ asReadStream(): Promise<ReadStream>;
78
+ info(): Promise<Stats>;
79
+ toString(): string;
80
+ /**
81
+ * 从本地路径或者网络url创建
82
+ * @param userPath
83
+ * @param format
84
+ * @returns
85
+ */
86
+ static fromPath(userPath: string, format?: "text" | "binary", fileName?: string, textEncoding?: BufferEncoding): AsyncFile;
87
+ /**
88
+ * 从buffer创建
89
+ * @param buffer
90
+ * @param format
91
+ * @returns
92
+ */
93
+ static fromBuffer(buffer: Buffer$1, name?: string, format?: "text" | "binary", textEncoding?: BufferEncoding): AsyncFile;
94
+ }
95
+
96
+ interface IModelInfo {
97
+ id: string;
98
+ user_created: string;
99
+ date_created: any;
100
+ user_updated?: string;
101
+ date_update?: any;
102
+ name: string;
103
+ desc?: string;
104
+ }
105
+ declare enum SimpleSchemaType {
106
+ text = "text",
107
+ number = "number",
108
+ boolean = "boolean",
109
+ radio = "radio",
110
+ check = "check",
111
+ select = "select",
112
+ date = "date",
113
+ image = "image",// 使用图片链接
114
+ video = "video",// 使用视频链接
115
+ audio = "audio",// 使用音频链接
116
+ url = "url",
117
+ email = "email",
118
+ phone = "phone",
119
+ ipv4 = "ipv4"
120
+ }
121
+ interface ISimpleSchemaItem {
122
+ [key: string]: string | string[] | number[] | ISimpleSchemaItem;
123
+ }
124
+ interface IConfigSchema {
125
+ type?: "simple" | "formily";
126
+ simple?: ISimpleSchemaItem;
127
+ formily?: ISchema;
128
+ }
129
+ declare const SchemaBaseProperties: {
130
+ instanceName: {
131
+ type: string;
132
+ title: string;
133
+ "x-order": number;
134
+ "x-decorator": string;
135
+ "x-component": string;
136
+ "x-component-props": {
137
+ placeholder: string;
138
+ };
139
+ "x-decorator-props": {
140
+ tooltip: string;
141
+ };
142
+ };
143
+ };
144
+ interface IConfigParams {
145
+ /**
146
+ * 类型的名称(非实例名称),所有该类型的实例都一样
147
+ */
148
+ name: string;
149
+ desc?: string;
150
+ /**
151
+ * 公共目录的相对路径,如 /public/images/logo.png
152
+ */
153
+ logoPath?: string;
154
+ /**
155
+ * 实例属性配置的结构
156
+ */
157
+ optionsSchema: IConfigSchema;
158
+ supported?: {
159
+ groupInAndOut?: boolean;
160
+ inTypes?: SourceChatMessageType[];
161
+ outTypes?: SourceChatMessageType[];
162
+ };
163
+ /**
164
+ * 使用文档地址
165
+ */
166
+ readMeUrl?: string;
167
+ }
168
+ declare const config: {
169
+ port: number;
170
+ host: string;
171
+ wsUrl: string;
172
+ httpUrl: string;
173
+ privateHttpUrl: string;
174
+ privateWsUrl: string;
175
+ /**
176
+ * 公共资源路径,在本机的路径
177
+ */
178
+ publicPath: string;
179
+ /**
180
+ * 公共资源访问的路径名
181
+ */
182
+ publicPathName: string;
183
+ tempDir: string;
184
+ redisUrl: string;
185
+ offline: boolean;
186
+ configServerUrl: string;
187
+ configServerEmail: string;
188
+ configServerPassword: string;
189
+ publicToken: string;
190
+ publicForceAuth: boolean;
191
+ secretFile: string;
192
+ traceHttpRequest: boolean;
193
+ version: string;
194
+ npmRegistry: string;
195
+ npmTimeout: number;
196
+ serverCompress: boolean;
197
+ serverCompressMinSize: number;
198
+ serverCompressMime: string[];
199
+ };
200
+
201
+ interface IInstanceCreateOptions {
202
+ /**
203
+ * 用来区分不同实例的全局唯一key
204
+ */
205
+ instanceName?: string;
206
+ }
207
+ interface IInstanceBaseMangerOptions {
208
+ /**
209
+ * 是否缓存实例,默认true。false的时候每次都会创建新的实例,需要自行处理实例名称重复逻辑
210
+ */
211
+ cacheInstance?: boolean;
212
+ }
213
+ interface IInstance {
214
+ get options(): IInstanceCreateOptions;
215
+ get params(): IConfigParams;
216
+ }
217
+ declare abstract class InstanceBaseManager<InstanceType extends IInstance, CreatorType extends (...args: any[]) => any, CreateOptionsType extends IInstanceCreateOptions, TParams extends IConfigParams> {
218
+ protected options?: IInstanceBaseMangerOptions;
219
+ private _instances;
220
+ private _creators;
221
+ private _params;
222
+ constructor(options?: IInstanceBaseMangerOptions);
223
+ /**
224
+ * 消息源创建器注册。一般由插件进行注册。
225
+ * @param name
226
+ * @param creator
227
+ */
228
+ registerInstanceCreator(creator: CreatorType, params: TParams): void;
229
+ /**
230
+ * 根据固有名称获取其相关参数
231
+ * @param name
232
+ */
233
+ getParams(name: string): TParams;
234
+ getAllParams(): {
235
+ [key: string]: TParams;
236
+ };
237
+ getAllParamsArray(): TParams[];
238
+ /**
239
+ * 只有允许缓存实例的管理器才能够获取到创建过的实例
240
+ * @param instanceName
241
+ * @returns
242
+ */
243
+ getInstance(instanceName: string): InstanceType;
244
+ /**
245
+ * 获取某个类型的所有的实例
246
+ * @param typeName 类型名称
247
+ */
248
+ getInstances(typeName?: string): InstanceType[];
249
+ /**
250
+ * 创建实例
251
+ * @param name
252
+ * @param options
253
+ * @returns
254
+ */
255
+ createInstance(name: string, options: CreateOptionsType): InstanceType;
256
+ clearInstances(): Promise<void>;
257
+ }
258
+
259
+ /**
260
+ * 一个source可以有多个实例,比如不同的api地址,由用户配置
261
+ */
262
+ interface ISourceOptions extends IInstanceCreateOptions {
263
+ /**
264
+ * 离线后是否自动重新请求登陆,默认false
265
+ */
266
+ autoReLogin?: boolean;
267
+ }
268
+ /**
269
+ * params应该由source供应商提供
270
+ */
271
+ interface ISourceParamas extends IConfigParams {
272
+ /**
273
+ * @ 相关功能的时候,atList里面是用户信息的哪个字段,默认是userId,不同的source可能会有区别,可以在此配置
274
+ *
275
+ * 可以配置的值有:userName userId nickName
276
+ */
277
+ fieldInAtList?: "userName" | "userId" | "nickName";
278
+ /**
279
+ * 可以被外界监听的消息类型
280
+ * 内置类型可以从SourceEventTypes中选择,也可以加入自定义类型。
281
+ */
282
+ eventNames: string[];
283
+ /**
284
+ * 是否不要在@的时候自动加上@fieldInAtList的值。默认false,即不会自动附加。
285
+ */
286
+ autoAppendAt?: boolean;
287
+ }
288
+ /**
289
+ * 消息源的路由和ws处理器信息
290
+ */
291
+ interface ISourceActionInfo {
292
+ actionName: string;
293
+ type: "api" | "ws";
294
+ action: ISourceApiAction | SourceWSNormalAction | SourceWSCustomAction;
295
+ /**
296
+ * 是否需要
297
+ */
298
+ needAuth?: boolean;
299
+ }
300
+ /**
301
+ * 消息源的实现类
302
+ */
303
+ interface ISource extends IInstance {
304
+ /**
305
+ * 这个Source的固有属性,比如source的平台名称
306
+ */
307
+ get params(): ISourceParamas;
308
+ /**
309
+ * 初始化过程中的动态参数
310
+ */
311
+ get options(): ISourceOptions;
312
+ /**
313
+ * 消息源的路由和ws处理器列表,需要在消息源的构造函数阶段创建
314
+ */
315
+ get actions(): ISourceActionInfo[];
316
+ /**
317
+ * 用户发布订阅事件的对象,事件类型为SourceEventType
318
+ */
319
+ event: Emittery;
320
+ /**
321
+ * 获取当前登录用户的个人信息
322
+ */
323
+ me(force?: boolean): Promise<ISourceUserInfo>;
324
+ /**
325
+ * 执行登录,如果有需要扫码等,应发出全局TODO事件,登录成功后发出LOGIN消息,并携带用户信息
326
+ */
327
+ login(): Promise<void>;
328
+ /**
329
+ * 发送消息,如果返回内容不为空,说明发送失败
330
+ * @param message 要发送的消息
331
+ * @param fromMessage 该条消息如果是对某条消息的响应,可以传入原始消息。某些平台可能只允许被动发送消息,此时可能需要用到原始触发回复的那条消息。
332
+ */
333
+ sendMessage(message: ISourceChatMessage, fromMessage?: ISourceChatMessage): Promise<string>;
334
+ /**
335
+ * 获取用户信息,至少返回nickName
336
+ * @param mode all返回全部,user仅返回个人用户,group仅返回群组
337
+ * @param 是否强刷
338
+ */
339
+ getContacts(mode: "all" | "user" | "group", force?: boolean): Promise<({
340
+ nickName: string;
341
+ } & Partial<ISourceUserInfo>)[]>;
342
+ /**
343
+ * 根据获取联系人列表接口返回的粗略信息
344
+ * @param baseInfo
345
+ */
346
+ getContactDetail(baseInfo: ISourceUserInfo): Promise<ISourceUserInfo>;
347
+ /**
348
+ * 是否是登录状态。仅被用来检查登录状态,未登录不代表出错,也可能是正处于登录中。
349
+ */
350
+ hasLogin(): boolean;
351
+ /**
352
+ * 当agent把内容送给bot回复之前。可以用来做一系列的准备工作,如提前下发卡片stream卡片。
353
+ */
354
+ beforeSend?(sourceMessage: ISourceChatMessage): Promise<void>;
355
+ /**
356
+ * 当agent把内容发送给bot之后,可以用来给source释放相关资源,如结束卡片的写入状态。
357
+ * @param sourceMessage
358
+ */
359
+ afterSend?(sourceMessage: ISourceChatMessage): any;
360
+ }
361
+ type SourceCreator = (options: ISourceOptions) => ISource;
362
+ declare enum SourceEventType {
363
+ CHAT_MESSAGE = "CHAT_MESSAGE",
364
+ LOGIN = "LOGIN",
365
+ LOGOUT = "LOGOUT",
366
+ GROUP_INFO_CHANGED = "GROUP_INFO_CHANGED",
367
+ SYSTEM = "SYSTEM",
368
+ /**
369
+ * 非robot发送的消息
370
+ */
371
+ SELF_SEND = "SELF_SEND",
372
+ /**
373
+ * 第一次展开对话,并非所有消息源都会支持
374
+ */
375
+ FIRST_CHAT = "FIRST_CHAT",
376
+ /**
377
+ * 新用户进群
378
+ */
379
+ GROUP_NEW_USER = "GROUP_NEW_USER",
380
+ /**
381
+ * 每次消息源中激活与机器人的对话
382
+ */
383
+ ENTER_CHAT = "ENTER_CHAT",
384
+ CUSTOM = "CUSTOM"
385
+ }
386
+ /**
387
+ * 消息源发布的事件,通过websocket传到客户端
388
+ */
389
+ interface ISourceEventData {
390
+ id: string;
391
+ type: SourceEventType;
392
+ origin?: any;
393
+ source: ISource;
394
+ me: ISourceUserInfo;
395
+ }
396
+ /**
397
+ * 需要用户交互完成的事项,如扫码,验证码登,前端收集后提交后端进行继续处理
398
+ */
399
+ interface ISourceTodoEventData extends ISourceEventData {
400
+ todo: {
401
+ [key: string]: {
402
+ schema: IConfigSchema;
403
+ data: any;
404
+ };
405
+ };
406
+ }
407
+ /**
408
+ * 聊天消息到达事件,主要分为群聊和单聊
409
+ */
410
+ interface ISourceChatMessageEventData extends ISourceEventData {
411
+ message: ISourceChatMessage;
412
+ /**
413
+ * 当bot开始生成时,该方法被调用,以便source可以执行相关状态变更
414
+ * 请勿在此执行异步逻辑来发送消息
415
+ * @returns
416
+ */
417
+ onGenerating?: () => void;
418
+ }
419
+ /**
420
+ * 用户登录的消息
421
+ */
422
+ interface ISourceLoginEventData extends ISourceEventData {
423
+ user: ISourceUserInfo;
424
+ }
425
+ /**
426
+ * 用户登出消息
427
+ */
428
+ interface ISourceLogoutEventData extends ISourceEventData {
429
+ user: ISourceUserInfo;
430
+ }
431
+ /**
432
+ * 群组信息发生变化的消息
433
+ */
434
+ interface ISourceGroupInfoChangedEventData extends ISourceEventData {
435
+ groupInfo: ISourceUserInfo;
436
+ }
437
+ /**
438
+ * 系统消息,主要指全局系统消息,非聊天中的系统消息
439
+ */
440
+ interface ISourceSystemEventData extends ISourceEventData {
441
+ content: any;
442
+ }
443
+ declare enum SourceChatMessageType {
444
+ /**
445
+ * 文本或者Markdown
446
+ */
447
+ TEXT = "TEXT",
448
+ /**
449
+ * 图文混排,数据结构是数组。
450
+ * 该类型主要适配部分接收的消息源,如钉钉。bot回复的内容如果有图文,建议使用Markdown形式。
451
+ */
452
+ RICH_TEXT = "RICH_TEXT",
453
+ IMAGE = "IMAGE",
454
+ AUDIO = "AUDIO",
455
+ VIDEO = "VIDEO",
456
+ ARTICLE = "ARTICLE",
457
+ MUSIC = "MUSIC",
458
+ FILE = "FILE",
459
+ EMOTION = "EMOTION",
460
+ /**
461
+ * 小程序
462
+ */
463
+ MP = "MP",
464
+ /**
465
+ * 引用消息
466
+ */
467
+ REF = "REF",
468
+ POSITION = "POSITION",
469
+ PHONE = "PHONE",
470
+ FRIEND_REQUEST = "FRIEND_REQUEST",
471
+ /**
472
+ * 名片
473
+ */
474
+ CONTACT_CARD = "CONTACT_CARD",
475
+ /**
476
+ * 应用卡片
477
+ */
478
+ CARD = "CARD",
479
+ RECALL = "RECALL",
480
+ PAT = "PAT",
481
+ SYSTEM = "SYSTEM",
482
+ /**
483
+ * 订阅,主要用于类似公众号的场景
484
+ */
485
+ SUBSCRIBE = "SUBSCRIBE",
486
+ /**
487
+ * 取消订阅,主要用于类似公众号的场景
488
+ */
489
+ UNSUBSCRIBE = "UNSUBSCRIBE",
490
+ CUSTOM = "CUSTOM"
491
+ }
492
+ interface ISourceUserInfo {
493
+ /**
494
+ * 用户名
495
+ */
496
+ userName: string;
497
+ /**
498
+ * 用户昵称(如果有备注就是备注名称)
499
+ */
500
+ nickName?: string;
501
+ /**
502
+ * 头像地址
503
+ */
504
+ avatarUrl?: string;
505
+ /**
506
+ * 大头像地址
507
+ */
508
+ bigAvatarUrl?: string;
509
+ /**
510
+ * 唯一ID
511
+ */
512
+ userId: string;
513
+ /**
514
+ * 用户签名
515
+ */
516
+ signature?: string;
517
+ /**
518
+ * 自定义信息
519
+ */
520
+ origin?: any;
521
+ /**
522
+ * 是否是群组
523
+ */
524
+ isGroup?: boolean;
525
+ }
526
+ type SourceChatImageContent = {
527
+ file: IAsyncFile;
528
+ };
529
+ type SourceChatTextContent = string;
530
+ /**
531
+ * 富文本格式。与Markdown的区别是Markdown以纯文本传输,富文本中的图像是直接嵌入为file的,富文本只支持图文的有序排列。
532
+ */
533
+ type SourceChatRichTextContent = {
534
+ content: {
535
+ type: "text" | "image" | "video" | "custom" | "at" | "file";
536
+ data: SourceChatTextContent | SourceChatImageContent | SourceChatVideoContent | string;
537
+ customData?: any;
538
+ }[];
539
+ title?: string;
540
+ };
541
+ type SourceChatAudioContent = {
542
+ /**
543
+ * 音频需为wav格式。
544
+ */
545
+ file: IAsyncFile;
546
+ /**
547
+ * 语音转成的文本
548
+ */
549
+ text?: string;
550
+ };
551
+ type SourceChatFileContent = {
552
+ file: IAsyncFile;
553
+ sizeInBytes?: number;
554
+ title?: string;
555
+ desc?: string;
556
+ };
557
+ type SourceChatMusicContent = SourceChatFileContent & {
558
+ coverUrl?: string;
559
+ signer?: string;
560
+ album?: string;
561
+ url?: string;
562
+ };
563
+ type SourceChatVideoContent = SourceChatFileContent & {
564
+ previewImage?: IAsyncFile;
565
+ };
566
+ type SourceChatPositionContent = {
567
+ placeName: string;
568
+ lon: number;
569
+ lat: number;
570
+ placeDetail: string;
571
+ mapLevel?: number;
572
+ };
573
+ type SourceChatArticleContent = {
574
+ thumbFile?: IAsyncFile;
575
+ title: string;
576
+ url: string;
577
+ coverFile?: IAsyncFile;
578
+ desc?: string;
579
+ source?: string;
580
+ };
581
+ /**
582
+ * 如果是一张动图,那么previewUrl通常是一个预览的静态图。url是实际动图。
583
+ */
584
+ type SourceChatEmotionContent = {
585
+ url?: string;
586
+ previewUrl: string;
587
+ file: IAsyncFile;
588
+ };
589
+ /**
590
+ * 用户名片
591
+ */
592
+ type SourceChatContactContent = {
593
+ display: string;
594
+ smallImageUrl: string;
595
+ bigImageUrl?: string;
596
+ custom?: any;
597
+ };
598
+ /**
599
+ * 小程序消息
600
+ */
601
+ type SourceChatMPContent = {
602
+ title: string;
603
+ displayName?: string;
604
+ desc?: string;
605
+ openUrl: string;
606
+ openRelativePath?: string;
607
+ cover?: IAsyncFile;
608
+ iconUrl?: string;
609
+ id?: string;
610
+ };
611
+ /**
612
+ * 引用消息,当前仅支持以文本来回复引用消息
613
+ * 引用消息可以套娃,使用的时候要注意识别
614
+ */
615
+ type SourceChatRefContent = {
616
+ text: SourceChatTextContent;
617
+ refMessage?: ISourceChatMessage;
618
+ };
619
+ type SourceChatRecallContent = {
620
+ display: string;
621
+ sourceMessageId: string;
622
+ sourceContent?: SourceChatContent;
623
+ };
624
+ type SourceChatPatContentType = {
625
+ text: string;
626
+ };
627
+ type SourceChatSubscribeContent = {
628
+ isSubscribe: boolean;
629
+ };
630
+ type SourceChatSystemContent = {
631
+ data: any;
632
+ };
633
+ type SourceChatPhoneContent = {
634
+ title: string;
635
+ time: Date;
636
+ };
637
+ type SourceChatCardContent = {
638
+ /**
639
+ * 卡片的类型。
640
+ * - templateId表示使用模板id,这时候template是id的值,content是绑定的变量
641
+ * - template表示使用模板,这时候template提供模板结构,content提供变量对象
642
+ * - content表示直接使用完整的卡片内容,这时候template为空
643
+ */
644
+ type: "template" | "templateId" | "content";
645
+ /**
646
+ * 卡片的模板结构,变量使用{var}的方式进行占位。
647
+ *
648
+ * 如果type类型是template,则表示模板的id
649
+ *
650
+ * type是content时可不设置
651
+ */
652
+ template?: string;
653
+ /**
654
+ * 卡片的完整内容或者绑定的变量体
655
+ */
656
+ content: any;
657
+ /**
658
+ * 卡片交互结果,一般用户交互回调后才有
659
+ */
660
+ result?: any;
661
+ };
662
+ type SourceChatContent = SourceChatTextContent | SourceChatImageContent | SourceChatAudioContent | SourceChatPositionContent | SourceChatFileContent | SourceChatEmotionContent | SourceChatVideoContent | SourceChatMusicContent | SourceChatArticleContent | SourceChatContactContent | SourceChatMPContent | SourceChatRefContent | SourceChatRecallContent | SourceChatSubscribeContent | SourceChatRichTextContent | SourceChatSystemContent | SourceChatPhoneContent | SourceChatCardContent;
663
+ interface ISourceChatMessage {
664
+ type: SourceChatMessageType;
665
+ content: SourceChatContent;
666
+ time?: Date;
667
+ /**
668
+ * 消息来源ID,如果是个人消息,同senderId,如果是群消息,是群Id
669
+ */
670
+ fromId?: string;
671
+ /**
672
+ * 发消息人的ID
673
+ */
674
+ senderId?: string;
675
+ /**
676
+ * 发消息的用户名(一般也是唯一),不管是群消息还是个人消息,都应该是发送者(个人)的名称
677
+ */
678
+ senderName?: string;
679
+ isGroupChat: boolean;
680
+ isSender?: boolean;
681
+ senderInfo?: ISourceUserInfo;
682
+ /**
683
+ * 如果是群消息,则是群信息(具体使用哪个字段发送由source决定)
684
+ */
685
+ toInfo: ISourceUserInfo[];
686
+ origin?: any;
687
+ messageId?: string;
688
+ atList?: string[];
689
+ error?: string;
690
+ /**
691
+ * 自定义类型时的名称
692
+ */
693
+ customType?: string;
694
+ }
695
+ interface ISourceGroupChatMessage extends ISourceChatMessage {
696
+ groupInfo: ISourceUserInfo;
697
+ isAdmin?: boolean;
698
+ isOwner?: boolean;
699
+ }
700
+ declare class SourceApiNotFoundError extends Error {
701
+ }
702
+ declare class SourceApiMissingParamsError extends Error {
703
+ }
704
+ declare class SourceApiUnAuthorizedError extends Error {
705
+ }
706
+ type ISourceApiResponseType = "normal" | "custom";
707
+ interface ISourceApiAction {
708
+ /**
709
+ * 当type为normal时,将不会接收到rep,直接异步返回要响应的json即可
710
+ * 当type为custom时,需要自行处理reply的内容
711
+ */
712
+ type: ISourceApiResponseType;
713
+ /**
714
+ * 当type为normal时,将不会接收到rep,直接异步返回要响应的json即可
715
+ * 当type为custom时,需要自行处理reply的内容
716
+ * @param req
717
+ * @param rep
718
+ * @returns
719
+ */
720
+ handler: (req: FastifyRequest, rep?: FastifyReply) => Promise<any>;
721
+ }
722
+ interface ISourceWSNormalInMessage {
723
+ instanceName: string;
724
+ action: string;
725
+ /**
726
+ * id用来识别此次调用
727
+ */
728
+ id: string;
729
+ data: any;
730
+ }
731
+ interface ISourceWSNormalOutMessage {
732
+ error?: string;
733
+ data?: any;
734
+ id: string;
735
+ }
736
+ /**
737
+ * 收到的是纯JSON数据
738
+ */
739
+ type SourceWSNormalAction = (message: any) => Promise<any>;
740
+ /**
741
+ * 收到的是原始消息
742
+ */
743
+ type SourceWSCustomAction = {
744
+ /**
745
+ *
746
+ * @param message
747
+ * @param req
748
+ * @param socket
749
+ * @returns
750
+ */
751
+ onMessage: (message: any, req: FastifyRequest, socket: WebSocket) => Promise<void>;
752
+ onOpen?: (req: FastifyRequest, socket: WebSocket) => Promise<void>;
753
+ onClose?: (req: FastifyRequest, socket: WebSocket) => Promise<void>;
754
+ };
755
+
756
+ interface IMessageContentRule {
757
+ type: "startsWith" | "contains" | "regex" | "in";
758
+ content: string;
759
+ }
760
+ /**
761
+ * agent的一条匹配规则,agent根据规则优先级找到匹配的第一个规则。
762
+ * 规则可以给bot或者skill使用
763
+ * 各个条件之间是且的关系
764
+ *
765
+ * 用于skill的规则,如果返回的时候删除data中的message对象,则会停止进一步使用bot响应。可以用实现如发送特定指令返回固定内容的功能。
766
+ */
767
+ interface IMessageRule {
768
+ /**
769
+ * 响应的消息源实例的名称,不配置表示响应所有的消息源
770
+ */
771
+ /**
772
+ * 消息源模板过滤。比如一个钉钉消息源模板可能有很多个实例,如果希望全部响应,直接配置消息源的名称即可,而不需要每一个实例都配置
773
+ */
774
+ /**
775
+ * 响应的用户列表,不配置表示响应respond规则下,所有可以对话的用户
776
+ *
777
+ * 用户使用的是userName过滤,因为nickName重名的几率很大
778
+ */
779
+ fromUserNames?: string[];
780
+ /**
781
+ * 群消息时,fromUserName的限制是否生效,默认false,即群里所有人都响应
782
+ */
783
+ checkUserInGroup?: boolean;
784
+ /**
785
+ * 用户群组的过滤规则,不配置表示不根据群组过滤(即都响应),针对nickName??userName??id的规则
786
+ */
787
+ groupNameRule?: IMessageContentRule;
788
+ /**
789
+ * 生效的消息类型,可多选,不配置表示不做类型检查(即检查通过)
790
+ */
791
+ messageTypes?: (SourceChatMessageType | "ALL")[];
792
+ /**
793
+ * 过滤规则,不配置表示不根据内容过滤,仅文本消息内容(TEXT和REF)的该过滤生效。
794
+ *
795
+ * 正向规则,匹配成功才会响应,不适合用来做内容审查
796
+ */
797
+ contentFilter?: IMessageContentRule;
798
+ /**
799
+ * 使用的实例名称。如果是针对skill的规则,就是skill实例的名称,如果是针对bot,就是bot实例的名称
800
+ */
801
+ instanceName: string;
802
+ /**
803
+ * 优先级,order值越小,优先级越高,默认100
804
+ */
805
+ order?: number;
806
+ /**
807
+ * 群组过滤模式,deny表示不响应群组消息。whitelist或者blacklist对应groupNames中的配置应该如何理解。
808
+ * 不配置表示whitelist
809
+ */
810
+ groupMode?: "deny" | "whitelist" | "blacklist";
811
+ /**
812
+ * 用户过滤模式,all表示响应全部用户。whitelist或者blacklist对应fromUserNames中的配置该如何理解。
813
+ * 不配置表示whitelist
814
+ */
815
+ userMode?: "all" | "whitelist" | "blacklist";
816
+ /**
817
+ * 对什么消息生效(仅技能的rule可配置)。all表示来源和响应都生效(前提是skill中也有对应方法),source表示只对来源生效,reply表示只对响应生效。默认all。
818
+ */
819
+ skillApplyOn?: "all" | "source" | "reply";
820
+ /**
821
+ * 技能应用与回复的状态,complete表示只有本次回复都结束后才应用,该情况一般用于需要完整获取回复的文本消息内容,part是每次回复都使用,如语音消息转文本。默认part。
822
+ */
823
+ skillWhenReplyStatus?: "complete" | "part";
824
+ /**
825
+ * 该配置仅对群聊生效
826
+ * 只要有一个配置过的条件满足即可,不配置或者bool类型配置为false的不参与判断。
827
+ *
828
+ * 例如:
829
+ * - 如果希望没有任何限制,留空即可。
830
+ * - 如果希望仅仅被@的时候回复,配置为{at:true}
831
+ * - 如果被@ 或者以某个字符开头的时候都回复,配置为{at:true,names:["允许的字符"]}
832
+ * - 如果配置为{}或者{at:false},{names:[]},{refered:false}都表示不响应任何请求
833
+ *
834
+ * 注意:技能会在找到bot后调用,因此如果bot中配置了这个规则,技能如果也是一样的规则,则直接留空即可
835
+ */
836
+ respondTo?: {
837
+ /**
838
+ * 被@ 且在@ 列表中
839
+ * 只对文本或者图文混排的生效。纯图片,声音等类型的,由bot决定是否响应这些类型。
840
+ *
841
+ * 不配置或者配置为false都表示忽略该配置
842
+ */
843
+ at?: boolean;
844
+ /**
845
+ * 文本以以下列表中的一个开头。不配置或者配置为空则忽略该条件(即只看别的条件)。
846
+ */
847
+ names?: string[];
848
+ /**
849
+ * 内容被引用也可以响应。不配置或者配置为false则忽略该条件(即只看别的条件)。
850
+ */
851
+ refered?: boolean;
852
+ };
853
+ }
854
+
855
+ /**
856
+ * 机器人的固有属性,如名称等,在机器人类型属性中配置
857
+ */
858
+ interface IBotParams extends IConfigParams {
859
+ /**
860
+ * 是否需要框架提供历史消息,默认false。对于原生支持历史消息的后端,如dify,可以不需要平台进行历史消息存储
861
+ * 或者没有实现历史功能的bot,也应该设置为false。
862
+ */
863
+ needHistoryMessage?: boolean;
864
+ /**
865
+ * 在一个用户的当前对话中是否允许有多个活跃的chat,默认false。,一般均不允许,agent会等待bot上一个回复完成再继续下一次对话
866
+ */
867
+ allowMultiActiveChat?: boolean;
868
+ }
869
+ /**
870
+ * 机器人的实例属性,在创建机器人实例的时候配置
871
+ */
872
+ interface IBotOptions extends IInstanceCreateOptions {
873
+ /**
874
+ * 并不是所有bot都支持自定义prompt,比如agent类的,一般都在agent平台上预置好,或者通过自定义变量传入
875
+ */
876
+ systemPrompt?: string;
877
+ }
878
+ interface IMessageContentReceiver {
879
+ /**
880
+ * 将后端的消息返回给前端。当完成时,如果支持历史消息,应该将此次消息的平台版本,即botMessage返回给agent
881
+ * @param content
882
+ * @param messageType
883
+ * @param botMessage 此botMeesage为机器人的消息,类型应该为bot
884
+ * @returns
885
+ */
886
+ onContent: (content: SourceChatContent, messageType: SourceChatMessageType) => void;
887
+ onError: (error: string) => void;
888
+ }
889
+ interface IBotFileInfo {
890
+ file: IAsyncFile;
891
+ messageId: string;
892
+ type: "image" | "file" | "video";
893
+ }
894
+ /**
895
+ * 机器人特定平台最终发送和接收的消息,用于历史消息缓存
896
+ */
897
+ interface IBotHistoryMessage {
898
+ type: "bot" | "user";
899
+ data: any;
900
+ }
901
+ interface IBotReadyMessage {
902
+ forHistory?: IBotHistoryMessage;
903
+ forSend: any;
904
+ chatId: string;
905
+ plainText: string;
906
+ }
907
+ /**
908
+ * 一个被动接收消息并响应的机器人
909
+ */
910
+ interface IBot extends IInstance {
911
+ get options(): IBotOptions;
912
+ get params(): IBotParams;
913
+ /**
914
+ * bot的初始化代码,支持预加载资源
915
+ */
916
+ init(): Promise<void>;
917
+ /**
918
+ * 仅仅对消息实现一个平台化的转换。
919
+ * 如果涉及到图片或者文件的上传,应该在用户提问的时候,识别提问中是否存在引用消息(即针对文件图片的提问,必须使用引用消息实现),如果存在,在获取回复之前执行上传等异步动作,而不是一收到文件消息就上传
920
+ * 该接口返回的IBotMessage的type应该都是user
921
+ */
922
+ prepareMessage(data: IAgentChatEventData): Promise<IBotReadyMessage>;
923
+ /**
924
+ * 单聊时,每次对方发来消息都会调用该方法获取回复
925
+ * 群聊时,只有被@或者以指定名称开头呼叫时,才会被调用
926
+ *
927
+ * 该方法请务必等待回复完成后再异步返回。
928
+ * @param data
929
+ * @param receiver
930
+ * @param forSend 由本bot在getBotMessage中返回的forSend的内容,正常应该直接使用此内容进行发送
931
+ * @param historyBotMessages 当bot支持历史消息,且调用的agent开启了历史消息存储时会传入历史消息
932
+ * @returns 返回本次回答的botMessage信息,以便存入历史消息
933
+ */
934
+ getResponse(data: IAgentChatEventData, receiver: IMessageContentReceiver, readyMessage: IBotReadyMessage, historyBotMessages?: IBotHistoryMessage[]): Promise<IBotHistoryMessage>;
935
+ /**
936
+ * 请求清除当前聊天对象的历史对话
937
+ * @param data
938
+ * @returns 如果有异常,返回异常说明。成功清除无需返回信息。
939
+ */
940
+ clearHistoryRequested(data: IAgentChatEventData): Promise<string>;
941
+ }
942
+ type BotCreator = (options: IBotOptions) => IBot;
943
+ /**
944
+ * 机器人触发的消息的基础结构
945
+ */
946
+ interface IBotEventData {
947
+ sourceMessage: ISourceChatMessage;
948
+ }
949
+ /**
950
+ * 当bot获得回复后,用来记录历史消息的事件。如果bot申明了历史消息,agent会监听该事件,并管理历史消息,在调用getMessage的时候传入历史消息
951
+ */
952
+ interface IBotHistoryRecordEventData {
953
+ userMessage: any;
954
+ botMessage: any;
955
+ }
956
+
957
+ interface IHisotryMessageManagerOptions {
958
+ /**
959
+ * 过期时间。超过该时间的消息将被移除。默认300秒。
960
+ */
961
+ expireInSeconds?: number;
962
+ /**
963
+ * 最大缓存的字数。默认10240。如果一条记录就大于了这个数值,这条记录也不会被缓存。
964
+ *
965
+ * 仅对文字类消息使用
966
+ */
967
+ maxWordsCount?: number;
968
+ /**
969
+ * 最大缓存条数,默认30。
970
+ */
971
+ maxItemsCount?: number;
972
+ }
973
+ interface IBotCacheMessage {
974
+ message: IBotHistoryMessage;
975
+ wordsCount: number;
976
+ expiresAt: number;
977
+ }
978
+ /**
979
+ * 基于内存的历史消息管理
980
+ */
981
+ declare class HistoryMessageManager {
982
+ protected options: IHisotryMessageManagerOptions;
983
+ static DefaultOptions: IHisotryMessageManagerOptions;
984
+ constructor(options: IHisotryMessageManagerOptions);
985
+ protected messages: IBotCacheMessage[];
986
+ protected wordsCount: number;
987
+ /**
988
+ * 增加一条历史消息,如果是文本类型的,需要单独传入文本内容content,以便统计字数
989
+ * @param message
990
+ * @param content
991
+ */
992
+ addMessage(message: IBotHistoryMessage, content?: SourceChatContent): void;
993
+ /**
994
+ * 获取历史消息,获取的是内部的一个浅拷贝
995
+ * @returns
996
+ */
997
+ getHistoryMessages(): IBotHistoryMessage[];
998
+ clearHistory(): void;
999
+ }
1000
+
1001
+ interface IDisposable {
1002
+ dispose(): Promise<string>;
1003
+ }
1004
+
1005
+ /**
1006
+ * agent的技能,可以用来做任何关于消息源或者bot回复的内容的操作,如改变文本回复为语音回复
1007
+ */
1008
+ interface ISkill extends IInstance {
1009
+ get options(): ISkillOptions;
1010
+ get params(): ISkillParams;
1011
+ init(): Promise<void>;
1012
+ /**
1013
+ * 在消息被响应之前调用。无需响应的消息不会被调用
1014
+ * 如果希望拦截bot的后续响应,可以将data中的message设置为空
1015
+ * @param data
1016
+ */
1017
+ applyOnSource?(data: IAgentChatEventData): Promise<void>;
1018
+ /**
1019
+ * 在bot响应的消息被发出之前调用,可以基于bot的内容加工,返回新的内容和消息类型
1020
+ * @param content
1021
+ * @param messageType
1022
+ * @param sourceData
1023
+ * @param allContent 当回复类型是文本且回复全部完成时,会传入该参数,表示完整的回复内容
1024
+ */
1025
+ applyOnReply?(content: SourceChatContent, messageType: SourceChatMessageType, sourceData: IAgentChatEventData, allContent?: string): Promise<{
1026
+ content: SourceChatContent;
1027
+ messageType: SourceChatMessageType;
1028
+ }>;
1029
+ }
1030
+ interface ISkillOptions extends IInstanceCreateOptions {
1031
+ /**
1032
+ * 技能是否被禁用,禁用后将不可用。实例级别
1033
+ */
1034
+ disabled?: boolean;
1035
+ }
1036
+ declare const SkillSchemaBaseProperties: {
1037
+ disabled: {
1038
+ type: string;
1039
+ title: string;
1040
+ "x-decorator": string;
1041
+ "x-component": string;
1042
+ "x-decorator-props": {
1043
+ tooltip: string;
1044
+ };
1045
+ };
1046
+ instanceName: {
1047
+ type: string;
1048
+ title: string;
1049
+ "x-order": number;
1050
+ "x-decorator": string;
1051
+ "x-component": string;
1052
+ "x-component-props": {
1053
+ placeholder: string;
1054
+ };
1055
+ "x-decorator-props": {
1056
+ tooltip: string;
1057
+ };
1058
+ };
1059
+ };
1060
+ interface ISkillParams extends IConfigParams {
1061
+ }
1062
+ type SkillCreator = (options: ISkillOptions) => ISkill;
1063
+
1064
+ interface ITaskTriggerData {
1065
+ data: any;
1066
+ from: string;
1067
+ }
1068
+ /**
1069
+ * 任务触发器构建参数
1070
+ */
1071
+ interface ITaskTriggerOptions extends IInstanceCreateOptions {
1072
+ /**
1073
+ * 任务被触发时的回调
1074
+ * @param data
1075
+ * @returns
1076
+ */
1077
+ onTask: (data: ITaskTriggerData) => void;
1078
+ }
1079
+ /**
1080
+ * 任务触发器的固定属性
1081
+ */
1082
+ interface ITaskTriggerParams extends IConfigParams {
1083
+ }
1084
+ /**
1085
+ * 任务触发器。限定条件可以在触发器的options中配置
1086
+ * 通过实例管理器注册和构建,不缓存实例,每个任务创建新的实例
1087
+ */
1088
+ interface ITaskTrigger extends IInstance, IDisposable {
1089
+ get options(): ITaskTriggerOptions;
1090
+ get params(): ITaskTriggerParams;
1091
+ }
1092
+ /**
1093
+ * 任务执行结果
1094
+ */
1095
+ interface ITaskRunResult {
1096
+ /**
1097
+ * 执行过程中的记录或者结果,编码为字符串,方便存储
1098
+ */
1099
+ detail?: string;
1100
+ /**
1101
+ * 如果没有执行成功,error需要提供错误信息
1102
+ */
1103
+ error?: string;
1104
+ /**
1105
+ * 任务开始时间
1106
+ */
1107
+ startTime?: Date;
1108
+ /**
1109
+ * 任务结束时间
1110
+ */
1111
+ endTime?: Date;
1112
+ }
1113
+ /**
1114
+ * 一个任务执行器。前端基于任务执行器及其约束条件创建任务
1115
+ */
1116
+ interface ITaskRunner extends IInstance {
1117
+ get options(): ITaskRunnerOptions;
1118
+ get params(): ITaskRunnerParams;
1119
+ /**
1120
+ * 任务执行接口。任务执行无需返回任何内容,任务需要异步执行。
1121
+ */
1122
+ run(data?: any): Promise<ITaskRunResult>;
1123
+ }
1124
+ declare const TaskRunnerSchemaBaseProperties: {
1125
+ disabled: {
1126
+ type: string;
1127
+ title: string;
1128
+ "x-decorator": string;
1129
+ "x-component": string;
1130
+ "x-decorator-props": {
1131
+ tooltip: string;
1132
+ };
1133
+ default: boolean;
1134
+ required: boolean;
1135
+ };
1136
+ };
1137
+ /**
1138
+ * 任务执行器的构建参数
1139
+ */
1140
+ interface ITaskRunnerOptions extends IInstanceCreateOptions {
1141
+ disabled?: boolean;
1142
+ }
1143
+ /**
1144
+ * 任务执行器的固定属性
1145
+ */
1146
+ interface ITaskRunnerParams extends IConfigParams {
1147
+ /**
1148
+ * 支持的触发器名称及其限制条件
1149
+ *
1150
+ * 如设置消息触发的时候,可以通过这里设置支持触发的消息类型,主要给前端选择进行约束
1151
+ */
1152
+ triggerConstraints: {
1153
+ [name: string]: ITaskTriggerOptions | null;
1154
+ };
1155
+ }
1156
+ type TaskRunnerCreator = (options: ITaskRunnerOptions) => ITaskRunner;
1157
+ type TaskTriggerCreator = (options: ITaskTriggerOptions) => ITaskTrigger;
1158
+ declare abstract class TaskTrigger implements ITaskTrigger {
1159
+ protected app: PPAgent;
1160
+ protected _options: ITaskTriggerOptions;
1161
+ constructor(app: PPAgent, _options: ITaskTriggerOptions);
1162
+ abstract get options(): ITaskTriggerOptions;
1163
+ abstract get params(): ITaskTriggerParams;
1164
+ abstract dispose(): Promise<string>;
1165
+ }
1166
+ interface ITaskConfig {
1167
+ name: string;
1168
+ triggerName: string;
1169
+ triggerOptions: ITaskTriggerOptions;
1170
+ runnerName: string;
1171
+ runnerOptions: ITaskRunnerOptions;
1172
+ }
1173
+ interface ITaskServiceOptions {
1174
+ tasks?: ITaskConfig[];
1175
+ maxRecords?: number;
1176
+ }
1177
+ declare class TaskService implements IDisposable {
1178
+ private _app;
1179
+ private _options;
1180
+ constructor(_app: PPAgent, _options?: ITaskServiceOptions);
1181
+ private _initialized;
1182
+ private _taskTriggers;
1183
+ private _onlineCount;
1184
+ get onlineCount(): number;
1185
+ init(): Promise<void>;
1186
+ reload(): Promise<void>;
1187
+ private _loadTasks;
1188
+ dispose(): Promise<string>;
1189
+ }
1190
+
1191
+ type Creator<OptionsType, InstanceType> = (options: OptionsType) => InstanceType;
1192
+ interface IInstanceCreator<OptionsType, InstanceType, ParamsType> {
1193
+ creator: Creator<OptionsType, InstanceType>;
1194
+ params: ParamsType;
1195
+ }
1196
+ interface IOnlinePluginInfo extends IModelInfo {
1197
+ version: string;
1198
+ repo?: string;
1199
+ author?: string;
1200
+ homepage?: string;
1201
+ keywords?: string;
1202
+ options?: any;
1203
+ displayName?: string;
1204
+ schecma?: ISchema;
1205
+ }
1206
+ interface IPPAgentPluginHandler extends IDisposable {
1207
+ /**
1208
+ * 所有服务启动之前被调用。适合注册各类构建器,如消息源、技能、机器人。也可以注入自定义的路由,如果需要在实体注册和创建之后,http启动之前可以在beforeStart中实现。
1209
+ * @returns
1210
+ */
1211
+ init: () => Promise<{
1212
+ skills?: IInstanceCreator<ISkillOptions, ISkill, ISkillParams>[];
1213
+ bots?: IInstanceCreator<IBotOptions, IBot, IBotParams>[];
1214
+ sources?: IInstanceCreator<ISourceOptions, ISource, ISourceParamas>[];
1215
+ taskTriggers?: IInstanceCreator<ITaskTriggerOptions, ITaskTrigger, ITaskTriggerParams>[];
1216
+ taskRunners?: IInstanceCreator<ITaskRunnerOptions, ITaskRunner, ITaskRunnerParams>[];
1217
+ }>;
1218
+ /**
1219
+ * HTTP服务启动之前(agent和task创建之后)
1220
+ * @returns
1221
+ */
1222
+ beforeStart?: () => Promise<void>;
1223
+ /**
1224
+ * HTTP服务启动之后
1225
+ * @returns
1226
+ */
1227
+ afterStart?: () => Promise<void>;
1228
+ /**
1229
+ * 在服务被关闭之前被调用
1230
+ * @returns
1231
+ */
1232
+ beforeClose?: () => Promise<void>;
1233
+ /**
1234
+ * 是否必须使用在线配置的相关功能,如进行数据存储。
1235
+ */
1236
+ needOnline: boolean;
1237
+ /**
1238
+ * 插件名称,需要跟package.json中的完全一致
1239
+ */
1240
+ name: string;
1241
+ /**
1242
+ * 插件配置UI定义,如果不设置,则使用JSON编辑器编辑。
1243
+ */
1244
+ schema?: ISchema;
1245
+ }
1246
+ /**
1247
+ * 插件。在函数被调用的时候,如果有需要可以执行初始化操作
1248
+ *
1249
+ * 如果需要注册技能、消息源、机器人,请在beforeStart时
1250
+ */
1251
+ type IPPAgentPlugin = (app: PPAgent, options?: Record<string, any>) => Promise<IPPAgentPluginHandler>;
1252
+
1253
+ interface IAgentModels {
1254
+ /**
1255
+ * agent列表
1256
+ */
1257
+ agents?: IAgentOptions[];
1258
+ /**
1259
+ * skill列表
1260
+ */
1261
+ skills?: {
1262
+ name: string;
1263
+ options: ISkillOptions;
1264
+ }[];
1265
+ /**
1266
+ * bot列表
1267
+ */
1268
+ bots?: {
1269
+ name: string;
1270
+ options: IBotOptions;
1271
+ }[];
1272
+ /**
1273
+ * 消息源列表
1274
+ */
1275
+ sources?: {
1276
+ name: string;
1277
+ options: ISourceOptions;
1278
+ }[];
1279
+ }
1280
+ interface IAgentServiceOptions {
1281
+ /**
1282
+ * 最大请求记录,与用户级别也相关。超过的配置将不被获取到
1283
+ */
1284
+ maxRecords?: number;
1285
+ models?: IAgentModels;
1286
+ }
1287
+ /**
1288
+ * 智能体服务。如果不连接在线配置,可以设置offline为true。
1289
+ */
1290
+ declare class AgentService implements IDisposable {
1291
+ private _app;
1292
+ private _options;
1293
+ constructor(_app: PPAgent, _options?: IAgentServiceOptions);
1294
+ private _initialized;
1295
+ private _agents;
1296
+ private _tableNames;
1297
+ private _resourceCount;
1298
+ get resourceCount(): {
1299
+ agents: number;
1300
+ bots: number;
1301
+ sources: number;
1302
+ skills: number;
1303
+ };
1304
+ get agents(): Agent[];
1305
+ init(): Promise<void>;
1306
+ getAgentByName(name: string): Agent;
1307
+ /**
1308
+ * 停止当前所有的agent、bot、skill、source的活动,重新从数据库加载新的。
1309
+ */
1310
+ reload(): Promise<void>;
1311
+ private _loadConfig;
1312
+ private _loadTableConfig;
1313
+ private _loadInstances;
1314
+ private _loadSources;
1315
+ private _loadBots;
1316
+ private _loadSkills;
1317
+ private _loadAgents;
1318
+ dispose(): Promise<string>;
1319
+ }
1320
+
1321
+ declare class SkillManager extends InstanceBaseManager<ISkill, SkillCreator, ISkillOptions, ISkillParams> {
1322
+ }
1323
+
1324
+ declare class SourceManager extends InstanceBaseManager<ISource, SourceCreator, ISourceOptions, ISourceParamas> {
1325
+ }
1326
+
1327
+ declare class BotManager extends InstanceBaseManager<IBot, BotCreator, IBotOptions, IBotParams> {
1328
+ }
1329
+
1330
+ declare class TaskRunnerManager extends InstanceBaseManager<ITaskRunner, TaskRunnerCreator, ITaskRunnerOptions, ITaskRunnerParams> {
1331
+ protected options?: IInstanceBaseMangerOptions;
1332
+ constructor(options?: IInstanceBaseMangerOptions);
1333
+ }
1334
+ declare class TaskTriggerManager extends InstanceBaseManager<ITaskTrigger, TaskTriggerCreator, ITaskTriggerOptions, ITaskTriggerParams> {
1335
+ protected options?: IInstanceBaseMangerOptions;
1336
+ constructor(options?: IInstanceBaseMangerOptions);
1337
+ }
1338
+
1339
+ interface IGlobalNotifyEventData extends IGlobalEventData {
1340
+ info: {
1341
+ /**
1342
+ * 如果提供了callback url,那么客户端会详细消息操作按钮。当提供了schema和data时,按照可视化方式显示,否则显示一个文本输入框。用户编辑的JSON结果,将被POST到指定的路由下。
1343
+ *
1344
+ * 为http的绝对路径。
1345
+ */
1346
+ callbackUrl?: string;
1347
+ /**
1348
+ * 表单结构
1349
+ */
1350
+ schema?: ISchema;
1351
+ /**
1352
+ * 操作按钮的名称,默认是“详情”
1353
+ */
1354
+ detailActionName?: string;
1355
+ /**
1356
+ * 详情窗口中,确认按钮的名称,默认是“提交”
1357
+ */
1358
+ confirmActionName?: string;
1359
+ /**
1360
+ * 通知等级,important和urgent会高亮显示
1361
+ */
1362
+ level?: "normal" | "important" | "urgent";
1363
+ /**
1364
+ * 消息的有效期,如果不提供,则使用插件的全局有效期,全局有效期默认为1小时
1365
+ */
1366
+ expireInSeconds?: number;
1367
+ };
1368
+ }
1369
+ interface IGlobalEventData {
1370
+ /**
1371
+ * 消息名称
1372
+ */
1373
+ title: string;
1374
+ /**
1375
+ * 消息的描述
1376
+ */
1377
+ desc?: string;
1378
+ /**
1379
+ * 消息的时间
1380
+ */
1381
+ time?: Date;
1382
+ /**
1383
+ * 用来唯一标记一条消息。如果是支持与配置端进行callback的通知,在callback的时候需要根据这个id来识别当前是哪个消息的callback。
1384
+ */
1385
+ id?: string;
1386
+ /**
1387
+ * 消息的详细数据
1388
+ */
1389
+ data?: any;
1390
+ }
1391
+ declare enum GlobalEventNames {
1392
+ APP_STARTED = "APP_STARED",
1393
+ APP_RELOAD = "APP_REALOD",
1394
+ APP_RESTARTED = "APP_RESTARTED",
1395
+ APP_NOTIFY = "APP_NOTIFY"
1396
+ }
1397
+ declare class GlobalEvent extends Emittery<{
1398
+ [eventName: string]: IGlobalEventData;
1399
+ }> {
1400
+ constructor(name: string);
1401
+ private _logger;
1402
+ private _eventNames;
1403
+ get eventNames(): string[];
1404
+ emit(eventName: string, eventData?: IGlobalEventData): Promise<void>;
1405
+ /**
1406
+ * 只有注册过的全局消息类型才会被外部通过接口获取到名称,未注册的也可正常触发消息
1407
+ */
1408
+ registerGlobalEventNames(name: string): void;
1409
+ }
1410
+
1411
+ interface IPPAgentOptions {
1412
+ /**
1413
+ * agent服务的构建参数
1414
+ */
1415
+ agentServiceOptions?: IAgentServiceOptions;
1416
+ taskServiceOptions?: ITaskServiceOptions;
1417
+ /**
1418
+ * 是否是离线模式,离线模式不从网络加载配置
1419
+ */
1420
+ offline?: boolean;
1421
+ /**
1422
+ * 如果配置,那么应用可以在有需要的时候使用默认图
1423
+ */
1424
+ sharedLogoPath?: string;
1425
+ /**
1426
+ * 如果配置,那么应用可以在有需要的时候使用默认图
1427
+ */
1428
+ sharedCoverPath?: string;
1429
+ /**
1430
+ * id,请使用英文
1431
+ */
1432
+ name: string;
1433
+ }
1434
+ declare class PPAgent extends Emittery {
1435
+ private _options;
1436
+ static EventNames: {
1437
+ ERROR: string;
1438
+ };
1439
+ constructor(_options?: IPPAgentOptions);
1440
+ private _server;
1441
+ private _pluginHandlers;
1442
+ private _wsRoutes;
1443
+ private _httpRoutes;
1444
+ private _starting;
1445
+ private _stopping;
1446
+ private _stopped;
1447
+ private _running;
1448
+ private _agentService;
1449
+ private _skillManager;
1450
+ private _sourceManager;
1451
+ private _botManager;
1452
+ private _taskService;
1453
+ private _taskTriggerManager;
1454
+ private _taskRunnerManager;
1455
+ private _xmlParser;
1456
+ private _sharedCover;
1457
+ private _sharedLogo;
1458
+ private _client;
1459
+ private _me;
1460
+ private _globalEvent;
1461
+ private _logger;
1462
+ private _onlinePluginInfos;
1463
+ private _services;
1464
+ get server(): FastifyInstance<fastify.RawServerDefault, http.IncomingMessage, http.ServerResponse<http.IncomingMessage>, fastify.FastifyBaseLogger, fastify.FastifyTypeProviderDefault>;
1465
+ get skillManager(): SkillManager;
1466
+ get sourceManager(): SourceManager;
1467
+ get botManager(): BotManager;
1468
+ get taskTriggerManager(): TaskTriggerManager;
1469
+ get taskRunnerManager(): TaskRunnerManager;
1470
+ get agentService(): AgentService;
1471
+ get offlineMode(): boolean;
1472
+ get sharedCover(): IAsyncFile;
1473
+ get sharedLogo(): IAsyncFile;
1474
+ get client(): AuthenticationClient<any> & RestClient<any>;
1475
+ get options(): IPPAgentOptions;
1476
+ get taskService(): TaskService;
1477
+ get globalEvent(): GlobalEvent;
1478
+ get plugins(): IPPAgentPluginHandler[];
1479
+ get me(): {
1480
+ id: string;
1481
+ first_name: string | null;
1482
+ last_name: string | null;
1483
+ email: string | null;
1484
+ password: string | null;
1485
+ location: string | null;
1486
+ title: string | null;
1487
+ description: string | null;
1488
+ tags: string[] | null;
1489
+ avatar: string | {
1490
+ id: string;
1491
+ storage: string;
1492
+ filename_disk: string | null;
1493
+ filename_download: string;
1494
+ title: string | null;
1495
+ type: string | null;
1496
+ folder: string | {
1497
+ id: string;
1498
+ name: string;
1499
+ parent: string | any;
1500
+ };
1501
+ uploaded_by: string | any;
1502
+ uploaded_on: "datetime";
1503
+ modified_by: string | any;
1504
+ modified_on: "datetime";
1505
+ charset: string | null;
1506
+ filesize: string | null;
1507
+ width: number | null;
1508
+ height: number | null;
1509
+ duration: number | null;
1510
+ embed: unknown | null;
1511
+ description: string | null;
1512
+ location: string | null;
1513
+ tags: string[] | null;
1514
+ metadata: Record<string, any> | null;
1515
+ focal_point_x: number | null;
1516
+ focal_point_y: number | null;
1517
+ };
1518
+ language: string | null;
1519
+ theme: string | null;
1520
+ tfa_secret: string | null;
1521
+ status: string;
1522
+ role: string | {
1523
+ id: string;
1524
+ name: string;
1525
+ icon: string;
1526
+ description: string | null;
1527
+ parent: string | any;
1528
+ children: string[] | any[];
1529
+ policies: string[] | {
1530
+ id: string;
1531
+ name: string;
1532
+ icon: string;
1533
+ description: string | null;
1534
+ ip_access: string | null;
1535
+ enforce_tfa: boolean;
1536
+ admin_access: boolean;
1537
+ app_access: boolean;
1538
+ permissions: number[] | {
1539
+ id: number;
1540
+ policy: string | any;
1541
+ collection: string;
1542
+ action: string;
1543
+ permissions: Record<string, any> | null;
1544
+ validation: Record<string, any> | null;
1545
+ presets: Record<string, any> | null;
1546
+ fields: string[] | null;
1547
+ }[];
1548
+ users: string[] | any[];
1549
+ roles: string[] | any[];
1550
+ }[];
1551
+ users: string[] | any[];
1552
+ };
1553
+ token: string | null;
1554
+ last_access: "datetime" | null;
1555
+ last_page: string | null;
1556
+ provider: string;
1557
+ external_identifier: string | null;
1558
+ auth_data: Record<string, any> | null;
1559
+ email_notifications: boolean | null;
1560
+ appearance: string | null;
1561
+ theme_dark: string | null;
1562
+ theme_light: string | null;
1563
+ theme_light_overrides: Record<string, unknown> | null;
1564
+ theme_dark_overrides: Record<string, unknown> | null;
1565
+ policies: string[] | {
1566
+ id: string;
1567
+ name: string;
1568
+ icon: string;
1569
+ description: string | null;
1570
+ ip_access: string | null;
1571
+ enforce_tfa: boolean;
1572
+ admin_access: boolean;
1573
+ app_access: boolean;
1574
+ permissions: number[] | {
1575
+ id: number;
1576
+ policy: string | any;
1577
+ collection: string;
1578
+ action: string;
1579
+ permissions: Record<string, any> | null;
1580
+ validation: Record<string, any> | null;
1581
+ presets: Record<string, any> | null;
1582
+ fields: string[] | null;
1583
+ }[];
1584
+ users: string[] | any[];
1585
+ roles: string[] | any[];
1586
+ }[];
1587
+ };
1588
+ get onlinePlugins(): MapIterator<IOnlinePluginInfo>;
1589
+ get running(): boolean;
1590
+ get services(): Map<string, any>;
1591
+ private _createServer;
1592
+ private _initServer;
1593
+ private _checkRegister;
1594
+ private _initResources;
1595
+ private _loadOnlinePlugins;
1596
+ /**
1597
+ * 请在start之前调用
1598
+ * @param plugin
1599
+ * @returns
1600
+ */
1601
+ use(plugin: IPPAgentPlugin, info?: IOnlinePluginInfo): Promise<IPPAgentPluginHandler>;
1602
+ start(): Promise<void>;
1603
+ reload(): Promise<void>;
1604
+ stop(signal?: string): Promise<void>;
1605
+ /**
1606
+ * API路由动态注册。由框架统一注册,source类只需要按接口要求返回相应路由信息。
1607
+ * - 如果使用文本进行交互,type可以设置为normal,这样只要handler直接返回相应的文本即可。
1608
+ * - 如果需要完全自己控制返回内容,如二进制等,可以设置为custom,需要自行调用reply中的send方法返回内容。
1609
+ * - 如果遇到异常将在外层被捕获后,根据异常类型进行返回。
1610
+ *
1611
+ * 由于不同的外部请求认证方式不一(如不同来源的回调),因此有需要实现认证的时候,需要action自行实现
1612
+ * @param instanceName 消息源实例的key
1613
+ * @param actionName 处理器名称
1614
+ * @param action 处理器
1615
+ */
1616
+ registerRoutes(instanceName: string, info: ISourceActionInfo): void;
1617
+ /**
1618
+ * WS处理器注册。由框架统一注册,source类只需要按接口要求返回相应处理行器信息。
1619
+ * 如果使用JSON进行交互,建议客户端连接的时候直接连接ws/normal端点,然后使用标准的ISourceWSNormalInMessage格式传入数据,此时handler只要处理好数据返回纯数据即可,框架会包裹为ISourceWSNormalOutMessage返回给客户端。如果不需要返回数据,返回void即可。
1620
+ * 如果希望完全自定义,可以让客户端连接到ws/instanceName/action端点,此时所有消息将原封不动的传给handler进行处理,handler可以返回处理好的内容由框架发送,或者自行调用socket.send进行发送,自行发送时,处理方法返回void即可。
1621
+ *
1622
+ * 由于不同的外部请求认证方式不一(如不同来源的回调),因此有需要实现认证的时候,需要action自行实现
1623
+ * @param instanceName 消息源实例的key
1624
+ * @param actionName 处理器的名称
1625
+ * @param action 处理器
1626
+ */
1627
+ registerWSHandler(instanceName: string, info: ISourceActionInfo): void;
1628
+ }
1629
+
1630
+ type AgentChatMessageReplyType = (content: SourceChatContent, messageType: SourceChatMessageType, custom?: Partial<ISourceChatMessage>, now?: boolean) => Promise<string>;
1631
+ /**
1632
+ * 由agent发布的聊天消息事件,带了快速回复方法
1633
+ */
1634
+ interface IAgentChatEventData extends ISourceChatMessageEventData {
1635
+ /**
1636
+ * 快捷回复。完全自定义的发送可以直接调用agent的发送方法。
1637
+ * 默认文本类型,其他类型传入第二个参数
1638
+ */
1639
+ reply: AgentChatMessageReplyType;
1640
+ }
1641
+ interface IAgentOptions {
1642
+ botResponseRule: IMessageRule;
1643
+ sourceInstanceNames: string[];
1644
+ /**
1645
+ * 是否从文本消息中提取图片单独发送。钉钉这类支持混编的建议使用混编的类型发送,而不是提取后单独发送。
1646
+ */
1647
+ splitImageFromBotText?: boolean;
1648
+ /**
1649
+ * 图片拆出来之后是否需要从原来的文字中移除
1650
+ */
1651
+ removeImageAfterSplit?: boolean;
1652
+ /**
1653
+ * 是否检测音频wav,默认是
1654
+ */
1655
+ checkWavAudio?: boolean;
1656
+ /**
1657
+ * agent实例的名称
1658
+ */
1659
+ instanceName: string;
1660
+ /**
1661
+ * 当不支持流式传输时,系统会尽快把后段返回的内容发送回去。通过设置单词最小数量,可以避免连续发送过多条数据。
1662
+ * 默认70个字符。实际返回数量不一定刚好等于该数。该特性仅对中文生效。
1663
+ *
1664
+ * 如果希望等待后端回答完成后一次性发送,可以设置为负值。
1665
+ *
1666
+ * 建议在支持流式模式的source下,设置较小,比如10-20
1667
+ *
1668
+ * 小于0表示最后全部输出完成一起回复
1669
+ */
1670
+ bufferWordsMinCount?: number;
1671
+ /**
1672
+ * 一次回复最多被拆分成多少条,如果超过了,则最后一次性回复。避免被拆分的太零散,也能符合部分平台对回复数量的要求。
1673
+ *
1674
+ * 默认3。建议在支持流式的source下,设置尽可能的大,避免造成最后一起回复。
1675
+ */
1676
+ maxSplitCount?: number;
1677
+ /**
1678
+ * 用于拆分句子的标记,默认["!","。","?"]
1679
+ *
1680
+ * 如果设置为["none"],则表示只关注字数,不考虑分句,适用于流式回复。非流式回复请务必设置合理值或者不做设置,否则异常的断句可能导致图片无法被识别或者错误识别
1681
+ */
1682
+ splitCharacters?: string[];
1683
+ /**
1684
+ * 是否激活历史消息。需要机器的实现类也支持历史消息,即触发历史消息事件,并在发送到后端时带上历史消息
1685
+ */
1686
+ historyEnabled?: boolean;
1687
+ /**
1688
+ * 历史消息管理的构建参数
1689
+ */
1690
+ historyOptions?: IHisotryMessageManagerOptions;
1691
+ /**
1692
+ * 仅sendMode为queue时生效。最小发送时间间隔,单位是毫秒。防止发送过快被识别为垃圾消息。默认为1000。
1693
+ * source的流式模式下,建议设置的较小
1694
+ */
1695
+ minSendInterval?: number;
1696
+ /**
1697
+ * 发送模式,now是所有消息都默认立即发送,interval是加入发送队列,隔一段时间发送一条,避免认为乱发。发送间隔可以通过minSendInterval配置。
1698
+ * 如果立即发送,有可能造成发送顺序与bot返回的不一致(下载和传输耗时导致)
1699
+ * 默认队列发送。
1700
+ */
1701
+ sendMode?: "now" | "queue";
1702
+ /**
1703
+ * 技能规则列表
1704
+ */
1705
+ skillRules?: IMessageRule[];
1706
+ /**
1707
+ * 兜底回复。当没有匹配到规则,但是bot无法回复的时候触发该回复。如果不设置,则不回复。如果消息被技能取消回复,不会触发该回复。
1708
+ */
1709
+ fallbackAnswer?: string;
1710
+ /**
1711
+ * 表示如果一个用户同时在一个bot还没有回答结束时又提问,且bot不支持一个会话中多个活跃对话时,输出的提示词。
1712
+ *
1713
+ * 当multiActiveChatInConversationMode配置为发送提示时才会生效。
1714
+ */
1715
+ multiActiveChatInConversationTips?: string;
1716
+ /**
1717
+ * 如果一个用户同时在一个bot还没有回答结束时又提问,且bot不支持一个会话中多个活跃对话时,要采取的措施,pool是直接放入等待区,不提示;tips是给出提示,不放入等待区;pool_tips是放入等待区且给出提示。
1718
+ *
1719
+ * 提示内容可以通过multiActiveChatInConversationTips进行配置。
1720
+ *
1721
+ * 默认为pool。
1722
+ */
1723
+ multiActiveChatInConversationMode?: "pool" | "tips" | "pool_tips";
1724
+ /**
1725
+ * 是否发送消息处理异常的日志到客户端,默认false
1726
+ */
1727
+ sendErrorLog?: boolean;
1728
+ /**
1729
+ * 正在执行中的问答,执行的超时时间,默认60秒。超过的任务将不再等待,继续执行一个提问(不会被取消回调,有返回后仍然会发送)。
1730
+ */
1731
+ timeoutInSeconds?: number;
1732
+ }
1733
+ /**
1734
+ * 一个智能体,用于连接source和bot。
1735
+ * 各自职责如下:
1736
+ * - source:负责收消息、发消息、提供外部消息服务的接口能力
1737
+ * - bot:负责判断是否有能力响应某种消息、构建后端工具所需的消息体、发送消息给后端并回调给agent
1738
+ * - agent:负责监听source的消息、判断是否应该响应、找到bot获取响应、调用技能、回传响应结果给source
1739
+ */
1740
+ declare class Agent extends Emittery implements IDisposable {
1741
+ protected app: PPAgent;
1742
+ protected _options: IAgentOptions;
1743
+ static params: IConfigParams;
1744
+ constructor(app: PPAgent, _options: IAgentOptions);
1745
+ private _initialized;
1746
+ private _logger;
1747
+ /**
1748
+ * 一个agent只匹配一个规则,如果需要针对不同的群或者对象设置不同的bot,可以建立多个agent
1749
+ */
1750
+ private _responseRule;
1751
+ private _skillRules;
1752
+ private _textEndId;
1753
+ private _historyManagers;
1754
+ private _sendMessagePool;
1755
+ private _sourceMessagePool;
1756
+ get options(): IAgentOptions;
1757
+ get name(): string;
1758
+ /**
1759
+ * 发送消息到指定的消息源
1760
+ * @param message 要发送的消息
1761
+ * @param to 要发送的消息源
1762
+ * @param now 是否立即发送,如果否,则根据配置确定是否加入发送队列
1763
+ * @param fromMessage 该消息的前置消息。如果source端只能被动回复消息,可能在发送的时候需要提供来源消息。
1764
+ * @returns
1765
+ */
1766
+ sendMessage(message: ISourceChatMessage, to: ISource, now?: boolean, fromMessage?: ISourceChatMessage): Promise<string>;
1767
+ dispose(): Promise<string>;
1768
+ protected processChatMessage: (sourceData: ISourceChatMessageEventData) => Promise<void>;
1769
+ protected onChatMessage: (data: IAgentChatEventData) => Promise<void>;
1770
+ protected onSelfChatMessage: (data: ISourceChatMessageEventData) => void;
1771
+ private _applyAfterSkills;
1772
+ private _applyBeforeSkills;
1773
+ private _nextQuestion;
1774
+ private _findRules;
1775
+ private _getBotMessageManager;
1776
+ private _wrapEventWithChatReply;
1777
+ private _sendFromPool;
1778
+ private _splitWords;
1779
+ private _initAgent;
1780
+ }
1781
+
1782
+ interface ILogger {
1783
+ trace(message: any): void;
1784
+ debug(message: any): void;
1785
+ info(message: any): void;
1786
+ warn(message: any): void;
1787
+ error(message: any): void;
1788
+ fatal(message: any): void;
1789
+ emitter?: LogEmitter;
1790
+ }
1791
+ interface ILoggerEmitContent {
1792
+ level: Level;
1793
+ name: string;
1794
+ message: string;
1795
+ }
1796
+ /**
1797
+ * 日志转发器,仅转发框架内部日志
1798
+ * 默认级别为环境变量的级别
1799
+ */
1800
+ declare class LogEmitter extends Emittery {
1801
+ private _levelMap;
1802
+ private _currentLevelVal;
1803
+ private _currentLevel;
1804
+ get level(): pino.Level;
1805
+ constructor(level?: Level);
1806
+ setLevel(level: Level): void;
1807
+ emitString(level: Level, name: string, message: string): void;
1808
+ emitObject(level: Level, name: string, message: any): void;
1809
+ }
1810
+ declare const getLogger: (name: string, needEmitter?: boolean) => ILogger;
1811
+
1812
+ interface IBasicBotOptions extends IBotOptions {
1813
+ /**
1814
+ * service url
1815
+ */
1816
+ apiBase?: string;
1817
+ /**
1818
+ * service key
1819
+ */
1820
+ apiKey: string;
1821
+ /**
1822
+ * 如果大于0,表示上一次的消息距离现在如果超过了多长时间就清空历史对话重新开始新的对话。默认30分钟。注意dify本身也有会话周期逻辑。这里的逻辑是在dify内增加主动清空逻辑。
1823
+ */
1824
+ historyExipresInSeconds?: number;
1825
+ /**
1826
+ * 附件何时上传,now是立即上传,later是用户下次提问的时候上传。立即上传bot会进行响应(私聊或者群聊agent配置非文本消息reply时),later不会马上响应,等提问后再响应。
1827
+ * later模式下,如果用户提问之前服务重启,那么缓存会丢失。
1828
+ * 默认later
1829
+ */
1830
+ attachSendMode?: "now" | "later";
1831
+ /**
1832
+ * 默认3张,同dify设置
1833
+ */
1834
+ maxAttachCount?: number;
1835
+ /**
1836
+ * 当收到订阅消息时,要对用户说的欢迎词,如果欢迎词以双下划线__开头,表示使用固定词语,如 __欢迎关注!,否则将使用配置的词作为提示词让后端给出欢迎词
1837
+ *
1838
+ * 可以使用该功能提供对模型能力的介绍。
1839
+ *
1840
+ * 默认为 “请对用户的使用表示欢迎,并且简单的介绍你自己,重点是你的能力。”
1841
+ */
1842
+ subscribeWelcome?: string;
1843
+ /**
1844
+ * 是否是纯文本模型,默认false,表示支持多模态。
1845
+ */
1846
+ onlyText?: boolean;
1847
+ }
1848
+ interface ILastBotMessageInfo {
1849
+ timeInSeconds: number;
1850
+ conversationId: string;
1851
+ }
1852
+ declare abstract class BasicBot extends Emittery implements IBot {
1853
+ protected _options: IBasicBotOptions;
1854
+ static params: IBotParams;
1855
+ constructor(_options: IBasicBotOptions);
1856
+ abstract get params(): IBotParams;
1857
+ abstract init(): Promise<void>;
1858
+ /**
1859
+ * 是否支持线上存储会话信息,默认false。dify和fastgpt这类是支持的,需要设置为true
1860
+ *
1861
+ * 即采用本系统再带的历史会话的,设置为false,使用后端线上会话的,设置为true
1862
+ */
1863
+ abstract get supportConversationOnline(): boolean;
1864
+ protected commandText: {
1865
+ attach: string;
1866
+ position: string;
1867
+ article: string;
1868
+ subscribe: string;
1869
+ };
1870
+ /**
1871
+ * 只有后端原生支持会话管理的,才需要缓存会话信息
1872
+ * 使用本系统自带历史信息的时候不需要管理该对象
1873
+ */
1874
+ protected chatIdCache: Keyv<ILastBotMessageInfo>;
1875
+ protected chatAttachCache: {
1876
+ [key: string]: IBotFileInfo[];
1877
+ };
1878
+ protected logger: ILogger;
1879
+ get options(): IBasicBotOptions;
1880
+ /**
1881
+ * 根据文本内容和文件信息生成请求体
1882
+ * @param text
1883
+ * @param files
1884
+ */
1885
+ protected abstract generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[], evt: IAgentChatEventData): Promise<IBotReadyMessage>;
1886
+ /**
1887
+ * 获取当前用户上一次聊天的会话ID
1888
+ */
1889
+ protected abstract getLatestConversationId(chatId: string): Promise<string>;
1890
+ /**
1891
+ * 获取当前用户上一次聊天的时间,单位是秒
1892
+ */
1893
+ protected abstract getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
1894
+ protected abstract deleteConversation(conversationId: string, chatId: string): Promise<any>;
1895
+ protected checkCommand(text: string, chatId: string, data: IAgentChatEventData): boolean;
1896
+ protected getLastInfo(chatId: string): Promise<ILastBotMessageInfo>;
1897
+ protected abstract sendMessageBody(body: any, historyMessages: any[], cb: {
1898
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
1899
+ onError: (error: any) => void;
1900
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
1901
+ }, lastInfo?: ILastBotMessageInfo, evt?: IAgentChatEventData): Promise<IBotHistoryMessage>;
1902
+ clearHistoryRequested(data: IAgentChatEventData): Promise<string>;
1903
+ prepareMessage(data: IAgentChatEventData): Promise<IBotReadyMessage>;
1904
+ getResponse(data: IAgentChatEventData, receiver: IMessageContentReceiver, readyMessage: IBotReadyMessage, historyBotMessages?: IBotHistoryMessage[]): Promise<IBotHistoryMessage>;
1905
+ }
1906
+
1907
+ interface ICozeBotOptions extends IBasicBotOptions {
1908
+ appId: string;
1909
+ privateKey: string;
1910
+ botId: string;
1911
+ customVars?: Record<string, string>;
1912
+ /**
1913
+ * 是否优先使用本地文件,而不是将文件上传到dify服务器,默认false
1914
+ * 如果优先使用本地文件,某些平台可能无法后续进行追问
1915
+ */
1916
+ preferLocalAttach?: boolean;
1917
+ }
1918
+ declare class CozeBot extends BasicBot {
1919
+ protected _options: ICozeBotOptions;
1920
+ static params: IBotParams;
1921
+ constructor(_options: ICozeBotOptions);
1922
+ private _service;
1923
+ init(): Promise<void>;
1924
+ get options(): ICozeBotOptions;
1925
+ get params(): IBotParams;
1926
+ get supportConversationOnline(): boolean;
1927
+ private _loadFileInfo;
1928
+ protected generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[]): Promise<IBotReadyMessage>;
1929
+ protected getLatestChatTime(): Promise<number>;
1930
+ protected getLatestConversationId(): Promise<string>;
1931
+ protected deleteConversation(): Promise<any>;
1932
+ protected sendMessageBody(body: StreamChatReq, historyMessages: any[], cb: {
1933
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
1934
+ onError: (error: any) => void;
1935
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
1936
+ }, lastInfo?: ILastBotMessageInfo): Promise<IBotHistoryMessage>;
1937
+ }
1938
+
1939
+ interface ICozeServiceOptions {
1940
+ privateKeyPath: string;
1941
+ publicKey: string;
1942
+ appId: string;
1943
+ /**
1944
+ * 默认https://api.coze.cn
1945
+ */
1946
+ apiBase?: string;
1947
+ }
1948
+ declare class CozeService {
1949
+ private _options;
1950
+ constructor(_options: ICozeServiceOptions);
1951
+ private _token;
1952
+ private _client;
1953
+ get client(): CozeAPI;
1954
+ private _loadToken;
1955
+ init(): Promise<void>;
1956
+ conversations(botId: string): Promise<unknown>;
1957
+ createConversation(messages?: any, metaData?: Map<string, any>): Promise<unknown>;
1958
+ streamChat(req: StreamChatReq, cb: {
1959
+ onStart?: (data: CreateChatData) => void;
1960
+ onReply: (content: string, data: StreamChatData) => void;
1961
+ onReplyCompleted?: (all: string, data: StreamChatData) => void;
1962
+ onCompleted?: (all: string, data: CreateChatData) => void;
1963
+ others?: (data: StreamChatData) => void;
1964
+ }): Promise<void>;
1965
+ private _post;
1966
+ private _get;
1967
+ }
1968
+
1969
+ interface IDifyFileInfo {
1970
+ type: "image";
1971
+ transfer_method: "remote_url" | "local_file";
1972
+ /**
1973
+ * 传输模式为remote_url时需要传入
1974
+ */
1975
+ url?: string;
1976
+ /**
1977
+ * 传输模式为local_file时,填入返回的id
1978
+ */
1979
+ upload_file_id?: string;
1980
+ }
1981
+ interface IDifyChatMessageBody {
1982
+ query: string;
1983
+ /**
1984
+ * 用户输入变量,如果没有,请传入{}
1985
+ */
1986
+ inputs: {
1987
+ [key: string]: any;
1988
+ };
1989
+ response_mode?: "streaming" | "blocking";
1990
+ /**
1991
+ * 会话id,如果希望有历史消息功能,应该使用合适的规则来生成对话id
1992
+ * 如个人聊天以消息源+对方id,群组以消息源+群组id
1993
+ * 如果传入undefined,则每次对话都是新的对话
1994
+ */
1995
+ conversation_id?: string;
1996
+ parent_message_id?: string;
1997
+ /**
1998
+ * 聊天附件
1999
+ */
2000
+ files?: IDifyFileInfo[];
2001
+ /**
2002
+ * 是否自动生成标题,默认true
2003
+ */
2004
+ auto_generate_name?: boolean;
2005
+ user: string;
2006
+ }
2007
+
2008
+ interface IDifyAgentBotOptions extends IBasicBotOptions {
2009
+ /**
2010
+ * 是否优先使用本地文件,而不是将文件上传到dify服务器,默认false
2011
+ * 如果优先使用本地文件,某些平台可能无法后续进行追问
2012
+ */
2013
+ preferLocalAttach?: boolean;
2014
+ /**
2015
+ * 自定义变量
2016
+ */
2017
+ customVars?: {
2018
+ [key: string]: any;
2019
+ };
2020
+ }
2021
+ declare class DifyAgentBot extends BasicBot {
2022
+ protected _options: IDifyAgentBotOptions;
2023
+ static params: IBotParams;
2024
+ constructor(_options: IDifyAgentBotOptions);
2025
+ private _service;
2026
+ get params(): IBotParams;
2027
+ get options(): IDifyAgentBotOptions;
2028
+ get supportConversationOnline(): boolean;
2029
+ private _uploadImage;
2030
+ private _loadFileInfo;
2031
+ init(): Promise<void>;
2032
+ protected generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[]): Promise<IBotReadyMessage>;
2033
+ protected getLatestConversationId(chatId: string): Promise<string>;
2034
+ protected getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
2035
+ protected deleteConversation(conversationId: string, chatId: string): Promise<any>;
2036
+ protected sendMessageBody(body: IDifyChatMessageBody, historyMessages: any[], cb: {
2037
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
2038
+ onError: (error: any) => void;
2039
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
2040
+ }, lastInfo?: ILastBotMessageInfo): Promise<IBotHistoryMessage>;
2041
+ }
2042
+
2043
+ interface IOpenAIBotOptions extends IBasicBotOptions {
2044
+ clientOptions?: Omit<ClientOptions, "baseURL" | "apiKey">;
2045
+ chatOptions: Omit<OpenAI.ChatCompletionCreateParamsStreaming, "messages" | "stream" | "audio">;
2046
+ }
2047
+ declare class OpenAIBot extends BasicBot {
2048
+ protected _options: IOpenAIBotOptions;
2049
+ static params: IBotParams;
2050
+ constructor(_options: IOpenAIBotOptions);
2051
+ protected client: OpenAI;
2052
+ get options(): IOpenAIBotOptions;
2053
+ get params(): IBotParams;
2054
+ get supportConversationOnline(): boolean;
2055
+ private _loadFileInfo;
2056
+ protected generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[]): Promise<IBotReadyMessage>;
2057
+ protected getLatestConversationId(chatId: string): Promise<string>;
2058
+ protected getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
2059
+ protected deleteConversation(conversationId: string, chatId: string): Promise<any>;
2060
+ protected sendMessageBody(body: OpenAI.ChatCompletionCreateParamsStreaming, historyMessages: any[], cb: {
2061
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
2062
+ onError: (error: any) => void;
2063
+ /**
2064
+ * 支持线上后端会话的才要调用,主要用于更新本次会话对应的时间
2065
+ * @param conversationId
2066
+ * @param timeInSeconds
2067
+ * @returns
2068
+ */
2069
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
2070
+ }): Promise<IBotHistoryMessage>;
2071
+ init(): Promise<void>;
2072
+ }
2073
+
2074
+ interface IFastGPTBotOptions extends IOpenAIBotOptions {
2075
+ /**
2076
+ * 是否使用在线的历史记录功能,关闭后每次都会创建新的会话。默认false,表示开启历史记录。
2077
+ */
2078
+ disableHistory?: boolean;
2079
+ chatOptions: Omit<OpenAI.ChatCompletionCreateParamsStreaming, "messages" | "stream" | "audio"> & {
2080
+ variables?: {
2081
+ [key: string]: any;
2082
+ };
2083
+ };
2084
+ /**
2085
+ * 应用的ID
2086
+ */
2087
+ appId: string;
2088
+ }
2089
+ declare class FastGPTBot extends OpenAIBot {
2090
+ protected _options: IFastGPTBotOptions;
2091
+ static params: IBotParams;
2092
+ constructor(_options: IFastGPTBotOptions);
2093
+ private _commonApiBase;
2094
+ get options(): IFastGPTBotOptions;
2095
+ get supportConversationOnline(): boolean;
2096
+ protected generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[]): Promise<IBotReadyMessage>;
2097
+ protected getLatestConversationId(chatId: string): Promise<string>;
2098
+ protected getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
2099
+ protected deleteConversation(conversationId: string, chatId: string): Promise<any>;
2100
+ }
2101
+
2102
+ interface IOllamaBotOptions extends IBasicBotOptions {
2103
+ /**
2104
+ * 模型名称
2105
+ */
2106
+ model: string;
2107
+ /**
2108
+ * Ollama的可选配置
2109
+ */
2110
+ options?: {
2111
+ [key: string]: any;
2112
+ };
2113
+ /**
2114
+ * 模型在GPU中驻留多久,默认为空
2115
+ */
2116
+ keep_alive?: number;
2117
+ authType: "basic" | "token" | "none";
2118
+ basicOptions?: {
2119
+ name: string;
2120
+ password: string;
2121
+ };
2122
+ tokenOptions?: {
2123
+ key: string;
2124
+ token: string;
2125
+ in: "header" | "query";
2126
+ };
2127
+ }
2128
+ declare class OllamaBot extends BasicBot {
2129
+ protected _options: IOllamaBotOptions;
2130
+ static params: IBotParams;
2131
+ constructor(_options: IOllamaBotOptions);
2132
+ get options(): IOllamaBotOptions;
2133
+ get params(): IBotParams;
2134
+ get supportConversationOnline(): boolean;
2135
+ protected generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[]): Promise<IBotReadyMessage>;
2136
+ protected getLatestConversationId(chatId: string): Promise<string>;
2137
+ protected getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
2138
+ protected deleteConversation(conversationId: string, chatId: string): Promise<any>;
2139
+ protected sendMessageBody(body: any, historyMessages: any[], cb: {
2140
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
2141
+ onError: (error: any) => void;
2142
+ /**
2143
+ * 支持线上后端会话的才要调用,主要用于更新本次会话对应的时间
2144
+ * @param conversationId
2145
+ * @param timeInSeconds
2146
+ * @returns
2147
+ */
2148
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
2149
+ }): Promise<IBotHistoryMessage>;
2150
+ init(): Promise<void>;
2151
+ }
2152
+
2153
+ declare class OpenRouterBot extends OpenAIBot {
2154
+ static params: IBotParams;
2155
+ constructor(options: IOpenAIBotOptions);
2156
+ }
2157
+
2158
+ interface IQAnythingBotOptions extends IBasicBotOptions {
2159
+ botId: string;
2160
+ }
2161
+ declare class QAnythingBot extends BasicBot {
2162
+ protected _options: IQAnythingBotOptions;
2163
+ static params: IBotParams;
2164
+ constructor(_options: IQAnythingBotOptions);
2165
+ get options(): IQAnythingBotOptions;
2166
+ get params(): IBotParams;
2167
+ get supportConversationOnline(): boolean;
2168
+ protected generateReadyMessage(chatId: string, text: string): Promise<IBotReadyMessage>;
2169
+ protected getLatestConversationId(chatId: string): Promise<string>;
2170
+ protected getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
2171
+ protected deleteConversation(conversationId: string, chatId: string): Promise<any>;
2172
+ protected sendMessageBody(body: any, historyMessages: any[], cb: {
2173
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
2174
+ onError: (error: any) => void;
2175
+ /**
2176
+ * 支持线上后端会话的才要调用,主要用于更新本次会话对应的时间
2177
+ * @param conversationId
2178
+ * @param timeInSeconds
2179
+ * @returns
2180
+ */
2181
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
2182
+ }): Promise<IBotHistoryMessage>;
2183
+ init(): Promise<void>;
2184
+ }
2185
+
2186
+ interface IWenxinAgentBotOptions extends IBasicBotOptions {
2187
+ appId: string;
2188
+ }
2189
+ declare class WenxinAgentBot extends BasicBot {
2190
+ protected _options: IWenxinAgentBotOptions;
2191
+ static params: IBotParams;
2192
+ constructor(_options: IWenxinAgentBotOptions);
2193
+ get options(): IWenxinAgentBotOptions;
2194
+ get params(): IBotParams;
2195
+ get supportConversationOnline(): boolean;
2196
+ private _loadFileInfo;
2197
+ protected generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[]): Promise<IBotReadyMessage>;
2198
+ protected getLatestConversationId(chatId: string): Promise<string>;
2199
+ protected getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
2200
+ protected deleteConversation(conversationId: string, chatId: string): Promise<any>;
2201
+ protected sendMessageBody(body: any, historyMessages: any[], cb: {
2202
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
2203
+ onError: (error: any) => void;
2204
+ /**
2205
+ * 支持线上后端会话的才要调用,主要用于更新本次会话对应的时间
2206
+ * @param conversationId
2207
+ * @param timeInSeconds
2208
+ * @returns
2209
+ */
2210
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
2211
+ }, lastInfo?: ILastBotMessageInfo): Promise<IBotHistoryMessage>;
2212
+ init(): Promise<void>;
2213
+ }
2214
+
2215
+ interface IYuanQiBotOptions extends IBasicBotOptions {
2216
+ appId: string;
2217
+ }
2218
+ declare class YuanQiBot extends BasicBot {
2219
+ protected _options: IYuanQiBotOptions;
2220
+ static params: IBotParams;
2221
+ constructor(_options: IYuanQiBotOptions);
2222
+ get options(): IYuanQiBotOptions;
2223
+ get params(): IBotParams;
2224
+ get supportConversationOnline(): boolean;
2225
+ private _loadFileInfo;
2226
+ protected generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[]): Promise<IBotReadyMessage>;
2227
+ protected getLatestConversationId(chatId: string): Promise<string>;
2228
+ protected getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
2229
+ protected deleteConversation(conversationId: string, chatId: string): Promise<any>;
2230
+ protected sendMessageBody(body: any, historyMessages: any[], cb: {
2231
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
2232
+ onError: (error: any) => void;
2233
+ /**
2234
+ * 支持线上后端会话的才要调用,主要用于更新本次会话对应的时间
2235
+ * @param conversationId
2236
+ * @param timeInSeconds
2237
+ * @returns
2238
+ */
2239
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
2240
+ }): Promise<IBotHistoryMessage>;
2241
+ init(): Promise<void>;
2242
+ }
2243
+
2244
+ interface IZhipuQingyanBotOptions extends IBasicBotOptions {
2245
+ assistantId: string;
2246
+ metaData?: {
2247
+ [key: string]: string;
2248
+ };
2249
+ apiSecret: string;
2250
+ }
2251
+ declare class ZhipuQingyanBot extends BasicBot {
2252
+ protected _options: IZhipuQingyanBotOptions;
2253
+ static params: IBotParams;
2254
+ constructor(_options: IZhipuQingyanBotOptions);
2255
+ private _token;
2256
+ get options(): IZhipuQingyanBotOptions;
2257
+ get params(): IBotParams;
2258
+ get supportConversationOnline(): boolean;
2259
+ private _loadToken;
2260
+ private _loadFileInfo;
2261
+ protected generateReadyMessage(chatId: string, text: string, files: IBotFileInfo[]): Promise<IBotReadyMessage>;
2262
+ protected getLatestConversationId(chatId: string): Promise<string>;
2263
+ protected getLatestChatTime(conversationId: string, chatId: string): Promise<number>;
2264
+ protected deleteConversation(conversationId: string, chatId: string): Promise<any>;
2265
+ protected sendMessageBody(body: any, historyMessages: any[], cb: {
2266
+ onContent: (content: any, messageType: SourceChatMessageType) => void;
2267
+ onError: (error: any) => void;
2268
+ /**
2269
+ * 支持线上后端会话的才要调用,主要用于更新本次会话对应的时间
2270
+ * @param conversationId
2271
+ * @param timeInSeconds
2272
+ * @returns
2273
+ */
2274
+ onCompleted: (conversationId: string, timeInSeconds: number) => void;
2275
+ }, lastInfo?: ILastBotMessageInfo): Promise<IBotHistoryMessage>;
2276
+ init(): Promise<void>;
2277
+ }
2278
+
2279
+ declare class SiliconFlowBot extends OpenAIBot {
2280
+ static params: IBotParams;
2281
+ constructor(options: IOpenAIBotOptions);
2282
+ }
2283
+
2284
+ interface IXunfeiBotOptions extends IOpenAIBotOptions {
2285
+ /**
2286
+ * 优先级高于chatOptions中的模型名称
2287
+ */
2288
+ modelName?: string;
2289
+ }
2290
+ declare class XunfeiBot extends OpenAIBot {
2291
+ static params: IBotParams;
2292
+ constructor(options: IXunfeiBotOptions);
2293
+ }
2294
+
2295
+ interface IZhipuBotOptions extends IOpenAIBotOptions {
2296
+ /**
2297
+ * 优先级高于chatOptions中的模型名称
2298
+ */
2299
+ modelName?: string;
2300
+ }
2301
+ declare class ZhipuBot extends OpenAIBot {
2302
+ static params: IBotParams;
2303
+ constructor(options: IZhipuBotOptions);
2304
+ }
2305
+
2306
+ interface IPPAgentPluginOptions {
2307
+ /**
2308
+ * 通知有效期,过期的会被删除,客户端将看不到。
2309
+ *
2310
+ * 默认为1小时,即3600秒。最长不超过7天。
2311
+ *
2312
+ * 如果消息内指定了单独的有效期,以消息内的为准。
2313
+ */
2314
+ expiresInSeconds?: number;
2315
+ /**
2316
+ * 每隔多久检查一次消息的过期情况,默认是20秒。
2317
+ */
2318
+ checkNotifyFequencySeconds?: number;
2319
+ /**
2320
+ * 最大留存通知条数,超过后新的将覆盖旧的,默认100条。最少5条。
2321
+ */
2322
+ maxNotifyCount?: number;
2323
+ }
2324
+ declare const apiPlugin: IPPAgentPlugin;
2325
+
2326
+ declare const defaultPlugin: IPPAgentPlugin;
2327
+
2328
+ interface IBaseSTTSkillOptions extends ISkillOptions {
2329
+ /**
2330
+ * 是否确保音频格式为百度支持的wav格式。默认true,如果已经对接的渠道确保了是16k或者8k单声道音频,则无需检查。
2331
+ */
2332
+ ensureAudioFormat?: boolean;
2333
+ }
2334
+ /**
2335
+ * 对https://github.com/HG-ha/SenseVoice-Api的技能封装
2336
+ */
2337
+ declare abstract class BaseSTTSkill implements ISkill {
2338
+ protected _options: IBaseSTTSkillOptions;
2339
+ static params: ISkillParams;
2340
+ constructor(_options: IBaseSTTSkillOptions);
2341
+ protected _logger: ILogger;
2342
+ protected _targetFormat: string;
2343
+ get options(): IBaseSTTSkillOptions;
2344
+ get params(): ISkillParams;
2345
+ init(): Promise<void>;
2346
+ protected abstract _getText(file: IAsyncFile): Promise<string>;
2347
+ protected _transpileContent(originContent: SourceChatContent): Promise<void>;
2348
+ applyOnSource(data: IAgentChatEventData): Promise<void>;
2349
+ applyOnReply(content: SourceChatContent, messageType: SourceChatMessageType): Promise<{
2350
+ content: SourceChatContent;
2351
+ messageType: SourceChatMessageType;
2352
+ }>;
2353
+ }
2354
+
2355
+ interface ISenseVoiceSTTSkillOptions extends IBaseSTTSkillOptions {
2356
+ /**
2357
+ * 如xxx.com,无需带extract_text
2358
+ */
2359
+ apiHost: string;
2360
+ authType?: "basic" | "jwt" | "none";
2361
+ /**
2362
+ * jwt认证的时候需要提供
2363
+ */
2364
+ jwt?: string;
2365
+ /**
2366
+ * basic认证的时候需要提供
2367
+ */
2368
+ userName?: string;
2369
+ /**
2370
+ * basic认证的时候需要提供
2371
+ */
2372
+ password?: string;
2373
+ }
2374
+ /**
2375
+ * 对https://github.com/HG-ha/SenseVoice-Api的技能封装
2376
+ */
2377
+ declare class SenseVoiceSTTSkill extends BaseSTTSkill {
2378
+ protected _options: ISenseVoiceSTTSkillOptions;
2379
+ static params: ISkillParams;
2380
+ constructor(_options: ISenseVoiceSTTSkillOptions);
2381
+ private _headers;
2382
+ get options(): ISenseVoiceSTTSkillOptions;
2383
+ get params(): ISkillParams;
2384
+ protected _getText(file: IAsyncFile): Promise<string>;
2385
+ }
2386
+
2387
+ interface IBaseTTSSkillOptions extends ISkillOptions {
2388
+ /**
2389
+ * 用语音的概率。默认0.5,即一半。
2390
+ */
2391
+ probability?: number;
2392
+ /**
2393
+ * 当判别使用语音时,如果此值为true,会移除语音可能无法阅读的内容。默认false,即遇到无法阅读的,取消语音转换
2394
+ */
2395
+ deleteUnreadableText?: boolean;
2396
+ }
2397
+ declare abstract class BaseTTSSkill implements ISkill {
2398
+ protected _options: IBaseTTSSkillOptions;
2399
+ static params: ISkillParams;
2400
+ constructor(_options: IBaseTTSSkillOptions);
2401
+ protected _logger: ILogger;
2402
+ protected abstract get _maxToken(): number;
2403
+ get options(): IBaseTTSSkillOptions;
2404
+ get params(): ISkillParams;
2405
+ init(): Promise<void>;
2406
+ applyOnReply(content: SourceChatContent, messageType: SourceChatMessageType, sourceData: IAgentChatEventData, allContent?: string): Promise<{
2407
+ content: SourceChatContent;
2408
+ messageType: SourceChatMessageType;
2409
+ }>;
2410
+ protected abstract getAudioBuffer(text: string, sourceData: IAgentChatEventData): Promise<Buffer>;
2411
+ }
2412
+
2413
+ interface ISoviteRequestOptions {
2414
+ text: string;
2415
+ text_language?: "zh" | "en" | "ja" | "ko" | "yue";
2416
+ refer_wav_path?: string;
2417
+ prompt_text?: string;
2418
+ prompt_language?: "zh" | "en" | "ja" | "ko" | "yue";
2419
+ top_k?: number;
2420
+ top_p?: number;
2421
+ temperature?: number;
2422
+ speed?: number;
2423
+ inp_refs?: string[];
2424
+ }
2425
+ interface ISoviteTTSSkillOptions extends IBaseTTSSkillOptions {
2426
+ apiHost: string;
2427
+ authType?: "basic" | "jwt" | "none";
2428
+ /**
2429
+ * jwt认证的时候需要提供
2430
+ */
2431
+ jwt?: string;
2432
+ /**
2433
+ * basic认证的时候需要提供
2434
+ */
2435
+ userName?: string;
2436
+ /**
2437
+ * basic认证的时候需要提供
2438
+ */
2439
+ password?: string;
2440
+ /**
2441
+ * 是否是流式返回,目前不支持流式,请保持为空或者false
2442
+ */
2443
+ isStreaming?: boolean;
2444
+ /**
2445
+ * 调用接口时额外的参数
2446
+ */
2447
+ customReqOptions?: Omit<ISoviteRequestOptions, "text">;
2448
+ }
2449
+ declare class SoviteTTSSkill extends BaseTTSSkill {
2450
+ protected _options: ISoviteTTSSkillOptions;
2451
+ static params: ISkillParams;
2452
+ constructor(_options: ISoviteTTSSkillOptions);
2453
+ private _headers;
2454
+ protected get _maxToken(): number;
2455
+ get options(): ISoviteTTSSkillOptions;
2456
+ get params(): ISkillParams;
2457
+ init(): Promise<void>;
2458
+ getAudioBuffer(text: string): Promise<Buffer>;
2459
+ }
2460
+
2461
+ interface IBaiduSTTSkillOptions extends IBaseSTTSkillOptions {
2462
+ appId: string;
2463
+ apiKey: string;
2464
+ secretKey: string;
2465
+ }
2466
+ declare class BaiduSTTSkill extends BaseSTTSkill {
2467
+ protected _app: PPAgent;
2468
+ protected _options: IBaiduSTTSkillOptions;
2469
+ static params: ISkillParams;
2470
+ constructor(_app: PPAgent, _options: IBaiduSTTSkillOptions);
2471
+ private _client;
2472
+ get options(): IBaiduSTTSkillOptions;
2473
+ get params(): ISkillParams;
2474
+ protected _getText(file: IAsyncFile): Promise<string>;
2475
+ }
2476
+
2477
+ interface IBaiduTTSSkillOptions extends IBaseTTSSkillOptions {
2478
+ appId: string;
2479
+ apiKey: string;
2480
+ secretKey: string;
2481
+ /**
2482
+ * 语速,0-5
2483
+ */
2484
+ spd: number;
2485
+ /**
2486
+ * 音量大小,精品库0-15,其他0-9
2487
+ */
2488
+ vol: number;
2489
+ /**
2490
+ * 度小宇=1,度小美=0,度逍遥(基础)=3,度丫丫=4
2491
+ * 精品发音人选择:度逍遥(精品)=5003,度小鹿=5118,度博文=106,度小童=110,度小萌=111,度米朵=103,度小娇=5
2492
+ * 臻品度逍遥(臻品)=4003,度博文=4106,度小贤=4115,度小鹿=4119,度灵儿=4105,度小乔=4117,度小雯=4100,度米朵=4103,度姗姗=4144,度小贝=4278,度清风=4143,度小新=4140,度小彦=4129,度星河=4149,度小清=4254,度博文=4206,南方=4226
2493
+ */
2494
+ per: number;
2495
+ /**
2496
+ * 音调,取值0-9,默认为5中语调
2497
+ */
2498
+ pit: number;
2499
+ /**
2500
+ * 3为mp3格式(默认); 4为pcm-16k;5为pcm-8k;6为wav(内容同pcm-16k); 注意aue=4或者6是语音识别要求的格式,但是音频内容不是语音识别要求的自然人发音,所以识别效果会受影响。
2501
+ */
2502
+ aue: number;
2503
+ }
2504
+ declare class BaiduTTSSkill extends BaseTTSSkill {
2505
+ private _app;
2506
+ protected _options: IBaiduTTSSkillOptions;
2507
+ static params: ISkillParams;
2508
+ constructor(_app: PPAgent, _options: IBaiduTTSSkillOptions);
2509
+ private _client;
2510
+ protected get _maxToken(): number;
2511
+ get options(): IBaiduTTSSkillOptions;
2512
+ get params(): ISkillParams;
2513
+ protected getAudioBuffer(text: string, sourceData: IAgentChatEventData): Promise<Buffer>;
2514
+ }
2515
+
2516
+ interface IBaseDrawSkillOptions extends ISkillOptions {
2517
+ /**
2518
+ * 绘图触发词,默认画图,画画,画图
2519
+ */
2520
+ triggerWords?: string;
2521
+ replyFormat?: "TEXT" | "IMAGE" | "URL" | "VIDEO" | "FILE";
2522
+ apiBase: string;
2523
+ apiKey: string;
2524
+ model: string;
2525
+ size: string;
2526
+ /**
2527
+ * 优化器的bot的instanceName
2528
+ */
2529
+ optimizer?: string;
2530
+ /**
2531
+ * 是否使用大模型优化。
2532
+ */
2533
+ useLLM?: boolean;
2534
+ }
2535
+ interface IDrawResult {
2536
+ url: string;
2537
+ text?: string;
2538
+ coverUrl?: string;
2539
+ }
2540
+ declare abstract class BaseDrawSkill implements ISkill {
2541
+ protected _app: PPAgent;
2542
+ protected _options: IBaseDrawSkillOptions;
2543
+ static params: ISkillParams;
2544
+ constructor(_app: PPAgent, _options: IBaseDrawSkillOptions);
2545
+ protected _logger: ILogger;
2546
+ get options(): ISkillOptions;
2547
+ get params(): IConfigParams;
2548
+ init(): Promise<void>;
2549
+ protected abstract _draw(text: string, userId: string, data: IAgentChatEventData): Promise<IDrawResult>;
2550
+ applyOnSource(data: IAgentChatEventData): Promise<void>;
2551
+ }
2552
+
2553
+ interface ICogVideoDrawSkillOptions extends IBaseDrawSkillOptions {
2554
+ /**
2555
+ * 视频生成超时时间,避免永久循环查询结果,默认180秒
2556
+ */
2557
+ timeout?: number;
2558
+ /**
2559
+ * 是否生成音频,默认false
2560
+ */
2561
+ withAudio?: boolean;
2562
+ }
2563
+ declare class CogVideoDrawSkill extends BaseDrawSkill {
2564
+ protected _app: PPAgent;
2565
+ protected _options: ICogVideoDrawSkillOptions;
2566
+ static params: ISkillParams;
2567
+ constructor(_app: PPAgent, _options: ICogVideoDrawSkillOptions);
2568
+ protected _draw(prompt: string, userId: string): Promise<IDrawResult>;
2569
+ }
2570
+
2571
+ interface ICogviewDrawSkillOptions extends IBaseDrawSkillOptions {
2572
+ }
2573
+ declare class CogviewDrawSkill extends BaseDrawSkill {
2574
+ protected _app: PPAgent;
2575
+ protected _options: ICogviewDrawSkillOptions;
2576
+ static params: ISkillParams;
2577
+ constructor(_app: PPAgent, _options: ICogviewDrawSkillOptions);
2578
+ protected _draw(prompt: string, userId: string): Promise<IDrawResult>;
2579
+ }
2580
+
2581
+ interface IFishAudioTTSSkillOptions extends IBaseTTSSkillOptions {
2582
+ apiKey: string;
2583
+ baseUrl?: string;
2584
+ referenceId: string;
2585
+ }
2586
+ declare class FishAudioTTSSkill extends BaseTTSSkill {
2587
+ protected _app: PPAgent;
2588
+ protected _options: IFishAudioTTSSkillOptions;
2589
+ static params: ISkillParams;
2590
+ constructor(_app: PPAgent, _options: IFishAudioTTSSkillOptions);
2591
+ protected get _maxToken(): number;
2592
+ get options(): IFishAudioTTSSkillOptions;
2593
+ get params(): ISkillParams;
2594
+ protected getAudioBuffer(text: string): Promise<Buffer>;
2595
+ }
2596
+
2597
+ interface IOpenAIDrawSkillOptions extends IBaseDrawSkillOptions {
2598
+ quality: "standard" | "hd";
2599
+ }
2600
+ declare class OpenAIDrawSkill extends BaseDrawSkill {
2601
+ protected _app: PPAgent;
2602
+ protected _options: IOpenAIDrawSkillOptions;
2603
+ static params: ISkillParams;
2604
+ constructor(_app: PPAgent, _options: IOpenAIDrawSkillOptions);
2605
+ protected _draw(prompt: string, userId: string): Promise<IDrawResult>;
2606
+ }
2607
+
2608
+ interface IOpenAISTTSkillOptions extends IBaseSTTSkillOptions {
2609
+ apiKey: string;
2610
+ baseUrl?: string;
2611
+ model: string;
2612
+ }
2613
+ declare class OpenAISTTSkill extends BaseSTTSkill {
2614
+ protected _app: PPAgent;
2615
+ protected _options: IOpenAISTTSkillOptions;
2616
+ static params: ISkillParams;
2617
+ constructor(_app: PPAgent, _options: IOpenAISTTSkillOptions);
2618
+ protected _client: OpenAI;
2619
+ init(): Promise<void>;
2620
+ get options(): IOpenAISTTSkillOptions;
2621
+ get params(): ISkillParams;
2622
+ protected _getText(file: IAsyncFile): Promise<string>;
2623
+ }
2624
+
2625
+ interface IOpenAITTSSkillOptions extends IBaseTTSSkillOptions {
2626
+ apiKey: string;
2627
+ baseUrl?: string;
2628
+ model: string;
2629
+ voice: string;
2630
+ /**
2631
+ * 语速 0.25-4,默认1
2632
+ */
2633
+ speed?: number;
2634
+ }
2635
+ declare class OpenAITTSSkill extends BaseTTSSkill {
2636
+ protected _app: PPAgent;
2637
+ protected _options: IOpenAITTSSkillOptions;
2638
+ static params: ISkillParams;
2639
+ constructor(_app: PPAgent, _options: IOpenAITTSSkillOptions);
2640
+ protected _format: string;
2641
+ protected get _maxToken(): number;
2642
+ get options(): IOpenAITTSSkillOptions;
2643
+ get params(): ISkillParams;
2644
+ protected _updateBody(body: any): any;
2645
+ protected getAudioBuffer(text: string): Promise<Buffer>;
2646
+ }
2647
+
2648
+ interface ISiliconFlowDrawSkillOptions extends IBaseDrawSkillOptions {
2649
+ customOptions?: any;
2650
+ }
2651
+ declare class SiliconFlowDrawSkill extends BaseDrawSkill {
2652
+ protected _app: PPAgent;
2653
+ protected _options: ISiliconFlowDrawSkillOptions;
2654
+ static params: ISkillParams;
2655
+ constructor(_app: PPAgent, _options: ISiliconFlowDrawSkillOptions);
2656
+ protected _draw(prompt: string): Promise<IDrawResult>;
2657
+ }
2658
+
2659
+ interface ISiliconFlowSTTSkillOptions extends IBaseSTTSkillOptions {
2660
+ apiKey: string;
2661
+ baseUrl?: string;
2662
+ model: string;
2663
+ }
2664
+ declare class SiliconFlowSTTSkill extends OpenAISTTSkill {
2665
+ protected _app: PPAgent;
2666
+ protected _options: ISiliconFlowSTTSkillOptions;
2667
+ static params: ISkillParams;
2668
+ constructor(_app: PPAgent, _options: ISiliconFlowSTTSkillOptions);
2669
+ get options(): ISiliconFlowSTTSkillOptions;
2670
+ get params(): ISkillParams;
2671
+ }
2672
+
2673
+ interface ISiliconFlowTTSSkillOptions extends IOpenAISTTSkillOptions {
2674
+ apiKey: string;
2675
+ baseUrl?: string;
2676
+ model: string;
2677
+ voice: string;
2678
+ /**
2679
+ * 语速 0.25-4,默认1
2680
+ */
2681
+ speed?: number;
2682
+ }
2683
+ declare class SiliconFlowTTSSkill extends OpenAITTSSkill {
2684
+ protected _app: PPAgent;
2685
+ protected _options: ISiliconFlowTTSSkillOptions;
2686
+ static params: ISkillParams;
2687
+ constructor(_app: PPAgent, _options: ISiliconFlowTTSSkillOptions);
2688
+ protected _format: string;
2689
+ get options(): ISiliconFlowTTSSkillOptions;
2690
+ get params(): ISkillParams;
2691
+ protected _updateBody(body: any): any;
2692
+ protected getAudioBuffer(text: string): Promise<Buffer>;
2693
+ }
2694
+
2695
+ interface ITencentSTTSkillOptions extends IBaseSTTSkillOptions {
2696
+ secretId: string;
2697
+ secretKey: string;
2698
+ }
2699
+ declare class TencentSTTSkill extends BaseSTTSkill {
2700
+ protected _app: PPAgent;
2701
+ protected _options: ITencentSTTSkillOptions;
2702
+ static params: ISkillParams;
2703
+ constructor(_app: PPAgent, _options: ITencentSTTSkillOptions);
2704
+ private _client;
2705
+ init(): Promise<void>;
2706
+ get options(): ITencentSTTSkillOptions;
2707
+ get params(): ISkillParams;
2708
+ protected _getText(file: IAsyncFile): Promise<string>;
2709
+ }
2710
+
2711
+ interface ITencentTTSSkillOptions extends IBaseTTSSkillOptions {
2712
+ secretId: string;
2713
+ secretKey: string;
2714
+ /**
2715
+ * 语速,[-2.6],默认0
2716
+ */
2717
+ spd: number;
2718
+ /**
2719
+ * 音量大小,[-10,10],默认0
2720
+ */
2721
+ vol: number;
2722
+ /**
2723
+ * 详见 https://cloud.tencent.com/document/product/1073/92668 的基础语音合成音色
2724
+ */
2725
+ voice?: number;
2726
+ }
2727
+ declare class TencentTTSSkill extends BaseTTSSkill {
2728
+ private _app;
2729
+ protected _options: ITencentTTSSkillOptions;
2730
+ static params: ISkillParams;
2731
+ constructor(_app: PPAgent, _options: ITencentTTSSkillOptions);
2732
+ private _client;
2733
+ protected get _maxToken(): number;
2734
+ init(): Promise<void>;
2735
+ get options(): ITencentTTSSkillOptions;
2736
+ get params(): ISkillParams;
2737
+ protected getAudioBuffer(text: string): Promise<Buffer>;
2738
+ }
2739
+
2740
+ interface IXunfeiSTTSkillOptions extends IBaseSTTSkillOptions {
2741
+ appId: string;
2742
+ apiKey: string;
2743
+ secretKey: string;
2744
+ }
2745
+ declare class XunfeiSTTSkill extends BaseSTTSkill {
2746
+ protected _app: PPAgent;
2747
+ protected _options: IXunfeiSTTSkillOptions;
2748
+ static params: ISkillParams;
2749
+ constructor(_app: PPAgent, _options: IXunfeiSTTSkillOptions);
2750
+ private _hostUrl;
2751
+ private _host;
2752
+ private _uri;
2753
+ private _frame;
2754
+ get options(): IXunfeiSTTSkillOptions;
2755
+ get params(): ISkillParams;
2756
+ private _getAuthStr;
2757
+ private _getFrame;
2758
+ protected _getText(file: IAsyncFile): Promise<string>;
2759
+ }
2760
+
2761
+ interface IXunfeiTTSSkillOptions extends IBaseTTSSkillOptions {
2762
+ appId: string;
2763
+ apiKey: string;
2764
+ secretKey: string;
2765
+ /**
2766
+ * 语速,0-100
2767
+ */
2768
+ speed: number;
2769
+ /**
2770
+ * 0-100
2771
+ */
2772
+ volume: number;
2773
+ /**
2774
+ * 发音人,如 xiaoyan 请在讯飞控制台查看
2775
+ */
2776
+ vcn: string;
2777
+ /**
2778
+ * 音调(音高),取值0-100
2779
+ */
2780
+ pitch: number;
2781
+ /**
2782
+ * 用语音的概率。默认0.5,即一半。增加随机性。
2783
+ */
2784
+ probability?: number;
2785
+ /**
2786
+ * 当判别使用语音时,如果此值为true,会移除语音可能无法阅读的内容。默认false,即遇到无法阅读的,取消语音转换。
2787
+ */
2788
+ deleteUnreadableText?: boolean;
2789
+ }
2790
+ declare class XunfeiTTSSkill extends BaseTTSSkill {
2791
+ private _app;
2792
+ protected _options: IXunfeiTTSSkillOptions;
2793
+ static params: ISkillParams;
2794
+ constructor(_app: PPAgent, _options: IXunfeiTTSSkillOptions);
2795
+ private _hostUrl;
2796
+ private _host;
2797
+ private _uri;
2798
+ get options(): IXunfeiTTSSkillOptions;
2799
+ get params(): ISkillParams;
2800
+ protected get _maxToken(): number;
2801
+ private _getAuthStr;
2802
+ protected getAudioBuffer(text: string): Promise<Buffer>;
2803
+ }
2804
+
2805
+ interface IDingRobotSourceOptions extends ISourceOptions {
2806
+ clientId: string;
2807
+ clientSecret: string;
2808
+ corpId: string;
2809
+ apiHost?: string;
2810
+ oldApiHost?: string;
2811
+ agentId: number;
2812
+ robotCode: string;
2813
+ /**
2814
+ * 如果不设置,则使用环境变量中的值,设置该值优先
2815
+ */
2816
+ debug?: boolean;
2817
+ /**
2818
+ * 当发送文本类消息的时候,钉钉支持提供一个标题,标题会在列表中展示。默认是AI回复的前16个字。
2819
+ *
2820
+ * 如果配置这个参数,则会固定用这个标题
2821
+ */
2822
+ markdownMsgTitle?: string;
2823
+ /**
2824
+ * 发送音频时的格式,默认amr,可选wav(部分wav可能手机会播放失败),amr文件尺寸小,效率略低于wav。
2825
+ *
2826
+ * 目前测试wav格式支持客户端播放,但是转文字会失败。
2827
+ */
2828
+ sendAudioFormat?: "wav" | "amr";
2829
+ /**
2830
+ * 如果配置为AI卡片,则开启了流式回复,则需要配置streamTemplateId,否则流式回复不会生效
2831
+ * 可以参考着创建:https://open.dingtalk.com/document/orgapp/typewriter-effect-streaming-ai-card
2832
+ *
2833
+ * 此外还需要开放应用的卡片相关权限(后台应用权限搜索卡片全选批量开通即可)
2834
+ *
2835
+ * 使用卡片时候,因只支持markdown类型,即text类型,因此要关闭相关文字转语音技能对该source的使用,否则会出现卡片没有内容更新的情况。
2836
+ */
2837
+ streamTemplateId?: string;
2838
+ /**
2839
+ * 联系人缓存时间,单位是秒,默认24小时
2840
+ */
2841
+ contactsCacheTime?: number;
2842
+ /**
2843
+ * 联系人的列表ID,可以从钉钉api explorer里面相关接口获取(从根路径开始一层层获取)
2844
+ *
2845
+ * 默认1,表示根路径,如果只希望对部分部门的用户可被前端选取,可以这里设置上级部门ID
2846
+ *
2847
+ * 该配置仅影响前端选择联系人的数量,不影响消息监听
2848
+ */
2849
+ contactDepartId?: number;
2850
+ /**
2851
+ * 是否在系统启动的时候就自动获取联系人。默认false。
2852
+ *
2853
+ * 如果员工较多,建议启动的时候获取,避免第一次使用的时候等待时间过长。
2854
+ */
2855
+ contactAutoloadOnStart?: boolean;
2856
+ /**
2857
+ * 由于递归调用获取用户接口可能触发限流,此时可以设置获取间隔,默认是30ms一次。
2858
+ */
2859
+ contactSleepMS?: number;
2860
+ }
2861
+ interface IDingRobotSourceParams extends ISourceParamas {
2862
+ supportedFileExts: string[];
2863
+ }
2864
+ /**
2865
+ * 需要开启机器人发消息相关权限、通讯录和部门管理相关权限、应用管理相关权限、互动卡片相关权限
2866
+ *
2867
+ * 钉钉支持直接引用外部图片显示,因此需要本服务器具备公网访问能力
2868
+ *
2869
+ * 钉钉应用机器人暂不支持@人,webhook机器人支持,因此可以配合使用
2870
+ */
2871
+ declare class DingRobotSource implements ISource, IDisposable {
2872
+ private _app;
2873
+ private _options;
2874
+ static params: IDingRobotSourceParams;
2875
+ constructor(_app: PPAgent, _options: IDingRobotSourceOptions);
2876
+ private _token;
2877
+ private _oldToken;
2878
+ private _talkClient;
2879
+ private _me;
2880
+ private _trackIdCache;
2881
+ private _contacts;
2882
+ private _contactLoadingPromise;
2883
+ private _departIdNameMap;
2884
+ get params(): ISourceParamas;
2885
+ get options(): IDingRobotSourceOptions;
2886
+ get actions(): ISourceActionInfo[];
2887
+ event: Emittery;
2888
+ private _loadToken;
2889
+ private _api;
2890
+ private _oldApi;
2891
+ private _downloadMedia;
2892
+ private _onChatMessage;
2893
+ private _sendByWebhook;
2894
+ private _getPublicUrl;
2895
+ private _uploadMediaFile;
2896
+ private _sendByAPI;
2897
+ private _getDepartList;
2898
+ private _getDepartUsers;
2899
+ me(): Promise<ISourceUserInfo>;
2900
+ hasLogin(): boolean;
2901
+ login(): Promise<void>;
2902
+ beforeSend(sourceMessage: ISourceChatMessage): Promise<void>;
2903
+ afterSend(sourceMessage: ISourceChatMessage): Promise<void>;
2904
+ sendMessage(message: ISourceChatMessage, fromMessage?: ISourceChatMessage): Promise<string>;
2905
+ getContacts(mode: "all" | "user" | "group", forece?: boolean): Promise<({
2906
+ nickName: string;
2907
+ } & Partial<ISourceUserInfo>)[]>;
2908
+ getContactDetail(baseInfo: ISourceUserInfo): Promise<ISourceUserInfo>;
2909
+ dispose(): Promise<string>;
2910
+ }
2911
+
2912
+ interface IFeishuSourceOptions extends ISourceOptions {
2913
+ appId?: string;
2914
+ appSecret?: string;
2915
+ verificationToken?: string;
2916
+ encryptKey?: string;
2917
+ /**
2918
+ * 默认是 https://open.feishu.cn
2919
+ */
2920
+ domain?: string;
2921
+ /**
2922
+ * 联系人缓存时间,单位是秒,默认24小时
2923
+ */
2924
+ contactsCacheTime?: number;
2925
+ /**
2926
+ * 联系人的列表ID,如果以od-开头表示飞书自动生成的开放id,否则认为是自定义的id
2927
+ *
2928
+ * 默认0,表示根路径,如果只希望对部分部门的用户可被前端选取,可以这里设置上级部门ID
2929
+ *
2930
+ * 该配置仅影响前端选择联系人的数量,不影响消息监听
2931
+ *
2932
+ * 注意,系统内部使用的都是自定义的departmentId,在部门创建时可以指定或者自动生成,客户端内可查看或者编辑。
2933
+ */
2934
+ contactDepartId?: string;
2935
+ /**
2936
+ * 是否忽略非用户发送的消息,默认true
2937
+ */
2938
+ ignoreNoneUserMessage?: boolean;
2939
+ /**
2940
+ * 文本消息的回复方式,默认使用text格式。如果设置为stream,将会使用卡片模拟流式输出。
2941
+ *
2942
+ * text模式下,简单的markdown标签可以显示,图片标签会被转为普通的超链
2943
+ *
2944
+ * rich_text下,markdown的图片标签会被提取单独显示,其他内容会以markdown显示(飞书markdown不支持富文本消息中的图片标签)
2945
+ *
2946
+ * stream下,markdown中的图片标签会被提取并上传到飞书,且嵌入在原来位置显示
2947
+ */
2948
+ replayTextMode?: "text" | "rich_text" | "stream";
2949
+ /**
2950
+ * 当配置输出位stream时,需要提供卡片ID,否则将使用默认的卡片模板
2951
+ */
2952
+ cardId?: string;
2953
+ /**
2954
+ * 当使用富文本形式回复时,是否启用标题,默认false
2955
+ */
2956
+ richTextTitle?: boolean;
2957
+ /**
2958
+ * 富文本标题模板,可以使用{title}来占位,内容是用户提问的内容的最多前10个字符(未找到则使用用户昵称),默认是RE:{title},仅开启富文本回复和启用富文本标题后生效
2959
+ */
2960
+ richTextTitleTemplate?: string;
2961
+ /**
2962
+ * 启用流式回复时,正在思考的提示语,默认是"正在思考中..."
2963
+ */
2964
+ thinkingTips?: string;
2965
+ /**
2966
+ * 收到的语音转为wav时的通道数,不设置则采用ffmpeg的默认值。
2967
+ */
2968
+ wavChannel?: number;
2969
+ /**
2970
+ * 收到的语音转为wav时的采样率,不设置则使用ffmpeg的默认值。
2971
+ */
2972
+ wavSampleRate?: number;
2973
+ }
2974
+ /**
2975
+ * 飞书的应用消息源,要注意使用了长连接进行监听,不能启动多个参数相同的消息源,只有其中一个会接收到消息
2976
+ *
2977
+ * 涉及到用户或者群组信息时,userId是对应的用户open_id或者群组的open_id,userName对应的用户userId或者群组自定义id(仅在需要单独调用消息发送接口时会用到)
2978
+ *
2979
+ * 至少需要基本的机器人消息权限、获取用户基本信息、通讯录中获取部门列表及用户列表相关权限、卡片消息相关权限
2980
+ *
2981
+ * 由于飞书的自定义机器人没有权限直接上传图片文件,因此只能发送文本信息、不带图的富文本信息和不带图的卡片消息
2982
+ */
2983
+ declare class FeishuSource implements ISource {
2984
+ private _app;
2985
+ private _options;
2986
+ static params: ISourceParamas;
2987
+ constructor(_app: PPAgent, _options: IFeishuSourceOptions);
2988
+ private _me;
2989
+ private _client;
2990
+ private _wsClient;
2991
+ private _connected;
2992
+ private _departCache;
2993
+ private _userCache;
2994
+ private _trackIdCache;
2995
+ get params(): ISourceParamas;
2996
+ get options(): IFeishuSourceOptions;
2997
+ get actions(): ISourceActionInfo[];
2998
+ event: Emittery;
2999
+ private _getResourceFile;
3000
+ private _getRichTextContent;
3001
+ private _processChatMessage;
3002
+ private _handleChatMessage;
3003
+ private _getDepartList;
3004
+ private _getDepartUsers;
3005
+ private _uploadImage;
3006
+ private _uploadFile;
3007
+ private _getSimpleLinkContent;
3008
+ private _getSendMessageContent;
3009
+ private _sendWebhookMessage;
3010
+ me(force?: boolean): Promise<ISourceUserInfo>;
3011
+ hasLogin(): boolean;
3012
+ login(): Promise<void>;
3013
+ beforeSend(message: ISourceChatMessage): Promise<void>;
3014
+ afterSend(message: ISourceChatMessage): Promise<void>;
3015
+ sendMessage(message: ISourceChatMessage, fromMessage?: ISourceChatMessage): Promise<string>;
3016
+ getContacts(mode: "all" | "user" | "group", force?: boolean): Promise<({
3017
+ nickName: string;
3018
+ } & Partial<ISourceUserInfo>)[]>;
3019
+ getContactDetail(baseInfo: ISourceUserInfo): Promise<ISourceUserInfo>;
3020
+ }
3021
+
3022
+ interface IQQSourceOptions extends ISourceOptions {
3023
+ appId: string;
3024
+ token?: string;
3025
+ appSecret: string;
3026
+ /**
3027
+ * API地址,如果要强行开启沙箱模式,可以配置为沙箱的api地址,否则根据NODE_ENV环境变量是否为development来决定
3028
+ */
3029
+ apiBase?: string;
3030
+ /**
3031
+ * 用于获取token的api域名,默认是 https://bots.qq.com
3032
+ */
3033
+ tokenBase?: string;
3034
+ /**
3035
+ * 机器人的身份,可自行指定
3036
+ */
3037
+ me: ISourceUserInfo;
3038
+ /**
3039
+ * 音频编码的码率,默认32000,可选8000/12000/16000/24000/32000/44100/48000
3040
+ */
3041
+ audioEncodeRate?: number;
3042
+ /**
3043
+ * 音频解码的码率,默认为32000,可选8000/12000/16000/24000/32000/44100/48000
3044
+ */
3045
+ audioDecodeRate?: number;
3046
+ /**
3047
+ * 是否获邀使用markdown功能,如果有权限,可以设置为true,默认为false。
3048
+ */
3049
+ canUseMarkdown?: boolean;
3050
+ /**
3051
+ * 消息ID缓存的有效期,默认是20小时,用于避免重复消息接收,单位是小时
3052
+ */
3053
+ messageIdCacheHourPeriod?: number;
3054
+ }
3055
+ declare class QQSource implements ISource {
3056
+ private _app;
3057
+ private _options;
3058
+ static params: ISourceParamas;
3059
+ constructor(_app: PPAgent, _options: IQQSourceOptions);
3060
+ private _logger;
3061
+ private _accessToken;
3062
+ private _signKeyPair;
3063
+ private _msgIdCache;
3064
+ event: Emittery;
3065
+ get params(): ISourceParamas;
3066
+ get options(): ISourceOptions;
3067
+ get actions(): ISourceActionInfo[];
3068
+ private _checkSignature;
3069
+ private _verifyCallback;
3070
+ private _processChatMessage;
3071
+ private _onMessage;
3072
+ private _initToken;
3073
+ private _uploadFile;
3074
+ private _getArkContent;
3075
+ hasLogin(): boolean;
3076
+ me(): Promise<ISourceUserInfo>;
3077
+ login(): Promise<void>;
3078
+ sendMessage(message: ISourceChatMessage, fromMessage?: ISourceChatMessage): Promise<string>;
3079
+ getContacts(): Promise<({
3080
+ nickName: string;
3081
+ } & Partial<ISourceUserInfo>)[]>;
3082
+ getContactDetail(baseInfo: ISourceUserInfo): Promise<ISourceUserInfo>;
3083
+ }
3084
+
3085
+ interface IWCAISourceOptions extends ISourceOptions {
3086
+ /**
3087
+ * 对话开放平台的appId
3088
+ */
3089
+ appId: string;
3090
+ token: string;
3091
+ aesKey: string;
3092
+ apiBase?: string;
3093
+ /**
3094
+ * 用来识别公众平台消息源(机器人)的信息,可以自定义
3095
+ */
3096
+ me: ISourceUserInfo;
3097
+ }
3098
+ /**
3099
+ * 微信对话开放平台的消息源。支持公众号、企业微信、小程序、微信客服、网页H5
3100
+ */
3101
+ declare class WCAISource implements ISource {
3102
+ private _app;
3103
+ private _options;
3104
+ static params: ISourceParamas;
3105
+ constructor(_app: PPAgent, _options: IWCAISourceOptions);
3106
+ private _logger;
3107
+ get params(): ISourceParamas;
3108
+ get options(): ISourceOptions;
3109
+ get actions(): ISourceActionInfo[];
3110
+ event: Emittery;
3111
+ private _processMessage;
3112
+ private _onChatMessage;
3113
+ me(): Promise<ISourceUserInfo>;
3114
+ hasLogin(): boolean;
3115
+ login(): Promise<void>;
3116
+ sendMessage(message: ISourceChatMessage, fromMessage?: ISourceChatMessage): Promise<string>;
3117
+ getContacts(mode: "all" | "user" | "group", force?: boolean): Promise<({
3118
+ nickName: string;
3119
+ } & Partial<ISourceUserInfo>)[]>;
3120
+ getContactDetail(baseInfo: ISourceUserInfo): Promise<ISourceUserInfo>;
3121
+ }
3122
+
3123
+ interface IWCOASourceOptions extends ISourceOptions {
3124
+ appId: string;
3125
+ appSecret: string;
3126
+ token: string;
3127
+ aesKey: string;
3128
+ apiBase?: string;
3129
+ }
3130
+ /**
3131
+ * 微信公众平台的消息源。
3132
+ */
3133
+ declare class WCOASource implements ISource {
3134
+ private _options;
3135
+ static params: ISourceParamas;
3136
+ constructor(_options: IWCOASourceOptions);
3137
+ private _token;
3138
+ private _sendMessageUrl;
3139
+ private _me;
3140
+ get params(): ISourceParamas;
3141
+ get options(): IWCOASourceOptions;
3142
+ get actions(): ISourceActionInfo[];
3143
+ event: Emittery;
3144
+ private _onCheckSignature;
3145
+ private _loadToken;
3146
+ private _loadMediaFile;
3147
+ private _uploadMediaFile;
3148
+ private _processMessage;
3149
+ private _onChatMessage;
3150
+ private _setTyping;
3151
+ me(): Promise<ISourceUserInfo>;
3152
+ hasLogin(): boolean;
3153
+ login(): Promise<void>;
3154
+ sendMessage(message: ISourceChatMessage, fromMessage?: ISourceChatMessage): Promise<string>;
3155
+ getContacts(mode: "all" | "user" | "group", force?: boolean): Promise<({
3156
+ nickName: string;
3157
+ } & Partial<ISourceUserInfo>)[]>;
3158
+ getContactDetail(baseInfo: ISourceUserInfo): Promise<ISourceUserInfo>;
3159
+ }
3160
+
3161
+ interface IWeWorkSourceOptions extends ISourceOptions {
3162
+ agentId?: string;
3163
+ secret?: string;
3164
+ corpId?: string;
3165
+ token?: string;
3166
+ aesKey?: string;
3167
+ apiHost?: string;
3168
+ /**
3169
+ * 转人工关键词列表,默认为 ["人工"],即只要消息中包含了这个关键词,就会将客服状态转为人工接管。暂未启用。
3170
+ *
3171
+ * 前提是配置了人工接待账号
3172
+ */
3173
+ manualKeyWords?: string[];
3174
+ /**
3175
+ * 接待人员列表。目前策略为随机选择一个接待人员(还是放入接待池?)暂未启用。
3176
+ */
3177
+ manualUsers?: string[];
3178
+ /**
3179
+ * 客服模式下,用户第一次进入时是否发送欢迎语,如果是的话,可以通过设置prompt让bot生成一段欢迎的话。
3180
+ *
3181
+ * 默认false
3182
+ */
3183
+ welcomeInKfMode?: boolean;
3184
+ /**
3185
+ * 欢迎词的提示语,可以使用{nickName}对用户的昵称进行占位,如果提示语以双下划线开头,则会直接发送这段话,注意这时将不经过agent。如:__欢迎{nickName},有任何问题都可以跟我咨询。
3186
+ */
3187
+ welcomePrompt?: string;
3188
+ /**
3189
+ * 需要该应用自动创建的群聊。由于只有应用创建的群聊才能够主动推送群消息,因此需要先创建群聊。
3190
+ *
3191
+ * 注意务必指定群聊的ID,以便后续发消息时进行引用。
3192
+ *
3193
+ * 如果已经存在的群聊会提示重复,不影响。
3194
+ */
3195
+ appChatGroups?: {
3196
+ /**
3197
+ * 第一个人是群主
3198
+ */
3199
+ userlist: string[];
3200
+ /**
3201
+ * 群聊ID
3202
+ */
3203
+ chatid: string;
3204
+ /**
3205
+ * 群名称
3206
+ */
3207
+ name: string;
3208
+ }[];
3209
+ }
3210
+ /**
3211
+ * 企业微信应用的消息源。支持应用单聊,客服聊天以及应用和机器人的单向群推送(应用推送仅支持通过应用接口创建的群,没有机器人方便,且机器人支持Markdown,但是机器人不支持发送视频)
3212
+ * 群消息一次只发送一个群。只有机器人消息支持@
3213
+ *
3214
+ * 如果希望一次性发给一群人,可以使用应用单聊同事发送多个对象,支持发群到部门ID或者标签ID,而不需要通过群
3215
+ *
3216
+ * 注意:当启动后第一次收到客服消息时,仅会处理最新的一条客服消息。后续有新的消息进来时,将会处理最后一次到当前消息之间所有的消息。
3217
+ *
3218
+ * 企微的客服逻辑:创建应用-设置应用可以通过API访问(允许的JS回调需先配置)以及可信IP-设置API接收,勾选接收客服消息;微信客服中创建一个客服,指定一个接待人员,最下方打开通过API管理会话消息的企业内部开发,选中之前创建的应用
3219
+ *
3220
+ * 这样就可以通过这个应用来管理刚创建的客服的对话了,默认是机器人接管状态,有需要转人工可通过调用转人工接口实现转人工或者其他状态的流转。
3221
+ */
3222
+ declare class WeWorkSource implements ISource {
3223
+ private _app;
3224
+ private _options;
3225
+ static params: ISourceParamas;
3226
+ constructor(_app: PPAgent, _options: IWeWorkSourceOptions);
3227
+ private _apiHost;
3228
+ private _token;
3229
+ private _me;
3230
+ private _cacheManager;
3231
+ get params(): ISourceParamas;
3232
+ get options(): ISourceOptions;
3233
+ get actions(): ISourceActionInfo[];
3234
+ event: Emittery;
3235
+ private _loadToken;
3236
+ private _checkSignature;
3237
+ private _loadMediaFile;
3238
+ private _uploadMediaFile;
3239
+ private _uploadAppMediaFile;
3240
+ private _uploadRobotMediaFile;
3241
+ private _processKfMessage;
3242
+ private _processKfUserEventMessage;
3243
+ private _onKfMessage;
3244
+ private _processEventMessage;
3245
+ private _processAppMessage;
3246
+ private _onMessage;
3247
+ private _api;
3248
+ private _sendAppGroupMessage;
3249
+ private _sendRobotMessage;
3250
+ private _sendKfMessage;
3251
+ private _sendAppMessage;
3252
+ me(force?: boolean): Promise<ISourceUserInfo>;
3253
+ hasLogin(): boolean;
3254
+ login(): Promise<void>;
3255
+ sendMessage(message: ISourceChatMessage, fromMessage?: ISourceChatMessage): Promise<string>;
3256
+ getContacts(mode: "all" | "user" | "group", force?: boolean): Promise<({
3257
+ nickName: string;
3258
+ } & Partial<ISourceUserInfo>)[]>;
3259
+ getContactDetail(baseInfo: ISourceUserInfo): Promise<ISourceUserInfo>;
3260
+ createAppGroupChats(info: {
3261
+ userlist: string[];
3262
+ chatid: string;
3263
+ name: string;
3264
+ }[]): Promise<void>;
3265
+ }
3266
+
3267
+ interface ICronTaskTriggerOptions extends ITaskTriggerOptions {
3268
+ cron: string;
3269
+ context?: any;
3270
+ }
3271
+ declare class CronTaskTrigger extends TaskTrigger {
3272
+ protected app: PPAgent;
3273
+ protected _options: ICronTaskTriggerOptions;
3274
+ static params: ITaskTriggerParams;
3275
+ constructor(app: PPAgent, _options: ICronTaskTriggerOptions);
3276
+ private _job;
3277
+ private _logger;
3278
+ get options(): ICronTaskTriggerOptions;
3279
+ get params(): ITaskTriggerParams;
3280
+ dispose(): Promise<string>;
3281
+ }
3282
+
3283
+ declare class EchoTaskRunner implements ITaskRunner {
3284
+ private _app;
3285
+ private _options;
3286
+ static params: ITaskRunnerParams;
3287
+ constructor(_app: PPAgent, _options: ITaskRunnerOptions);
3288
+ get options(): ITaskRunnerOptions;
3289
+ get params(): ITaskRunnerParams;
3290
+ run(data?: ITaskTriggerData): Promise<ITaskRunResult>;
3291
+ }
3292
+
3293
+ /**
3294
+ * 消息触发类任务收到的消息内容
3295
+ */
3296
+ interface ITaskEventTriggerData extends ITaskTriggerData {
3297
+ triggerName: string;
3298
+ eventName: string;
3299
+ }
3300
+ /**
3301
+ * 消息触发类任务属性
3302
+ */
3303
+ interface IEventTaskTriggerOptions extends ITaskTriggerOptions {
3304
+ eventNames: string[];
3305
+ }
3306
+ /**
3307
+ * 数据源消息触发类任务属性
3308
+ */
3309
+ interface ISourceEventTaskTriggerOptions extends IEventTaskTriggerOptions {
3310
+ /**
3311
+ * 使用实例名称来配置,只监听指定的实例上的消息,与sourceNames是或的关系
3312
+ */
3313
+ sourceInstanceNames: string[];
3314
+ /**
3315
+ * 使用消息源类型名称来配置,该类型下的所有源的消息都被监听,与sourceInstanceNames是或的关系
3316
+ */
3317
+ sourceNames: string[] | string;
3318
+ /**
3319
+ * 消息规则,不配置则不过滤
3320
+ */
3321
+ messageRule?: IMessageRule;
3322
+ }
3323
+ /**
3324
+ * 消息类触发任务基础类型。封装了消息注册逻辑,子类只需提供可被监听的实例和名称。
3325
+ */
3326
+ declare abstract class EventTaskTrigger extends TaskTrigger {
3327
+ protected app: PPAgent;
3328
+ protected _options: IEventTaskTriggerOptions;
3329
+ constructor(app: PPAgent, _options: IEventTaskTriggerOptions);
3330
+ private _initialized;
3331
+ private _logger;
3332
+ private _disposers;
3333
+ protected abstract get loggerName(): string;
3334
+ protected get logger(): ILogger;
3335
+ dispose(): Promise<string>;
3336
+ protected init(): void;
3337
+ protected abstract getEventTriggers(): {
3338
+ name: string;
3339
+ trigger: Emittery;
3340
+ }[];
3341
+ }
3342
+ declare class SourceEventTaskTrigger extends EventTaskTrigger {
3343
+ protected app: PPAgent;
3344
+ protected _options: ISourceEventTaskTriggerOptions;
3345
+ static params: ITaskTriggerParams;
3346
+ constructor(app: PPAgent, _options: ISourceEventTaskTriggerOptions);
3347
+ protected get loggerName(): string;
3348
+ get options(): ISourceEventTaskTriggerOptions;
3349
+ get params(): ITaskTriggerParams;
3350
+ protected getEventTriggers(): {
3351
+ name: string;
3352
+ trigger: Emittery;
3353
+ }[];
3354
+ }
3355
+ declare class GlobalEventTaskTrigger extends EventTaskTrigger {
3356
+ protected app: PPAgent;
3357
+ protected _options: IEventTaskTriggerOptions;
3358
+ static params: ITaskTriggerParams;
3359
+ constructor(app: PPAgent, _options: IEventTaskTriggerOptions);
3360
+ protected get loggerName(): string;
3361
+ get options(): IEventTaskTriggerOptions;
3362
+ get params(): ITaskTriggerParams;
3363
+ protected getEventTriggers(): {
3364
+ name: string;
3365
+ trigger: Emittery;
3366
+ }[];
3367
+ }
3368
+
3369
+ declare const addWavHeader: (samples: ArrayBuffer, sampleRateTmp: number, sampleBits: number, channelCount: number) => ArrayBuffer;
3370
+ declare function removeEmoji(text: string): string;
3371
+ declare function removeMarkdown(text: string): string;
3372
+ declare function hasEmoji(text: string): boolean;
3373
+ declare function hasMarkdown(text: string): boolean;
3374
+ declare function extractArticleInfo(articleContent: SourceChatArticleContent): string;
3375
+ declare function extractPositionInfo(positionContent: SourceChatPositionContent): string;
3376
+ declare function betterMarkdown(text: string): string;
3377
+ declare function disposeObjects(objs: IDisposable[]): Promise<void>;
3378
+ declare function arm2wav(buffer: Buffer): Promise<IAsyncFile>;
3379
+ declare function wav2amr(file: IAsyncFile): Promise<{
3380
+ file: IAsyncFile;
3381
+ duration: number;
3382
+ }>;
3383
+ declare function createCacheManager(namespace: string): Keyv;
3384
+ declare function getSecret(key: string): string;
3385
+ declare function isPhoneNumber(text: string): boolean;
3386
+ declare function generateRandomString(length?: number): string;
3387
+ declare function transFormat(inputPath: string, outFilePath: string, toFormat: string, preCommand?: (command: ffmpeg.FfmpegCommand) => ffmpeg.FfmpegCommand): Promise<boolean>;
3388
+ declare function transFileFormat(inputFile: IAsyncFile, toFormat: string, preCommand?: (command: ffmpeg.FfmpegCommand) => ffmpeg.FfmpegCommand): Promise<IAsyncFile>;
3389
+ declare function extractImageUrls(text: string, onlyMarkdonw?: boolean): string[];
3390
+ declare function extractMarkdownImageTags(text: string): string[];
3391
+ /**
3392
+ * 根据文件内容生成文件名,只支持二进制数据
3393
+ * @param buffer
3394
+ * @param name
3395
+ * @returns
3396
+ */
3397
+ declare function detectName(buffer: Buffer | string, name?: string): Promise<string>;
3398
+ declare function stream2buffer(stream: ReadStream$1): Promise<Buffer>;
3399
+ declare function sse(stream: any, onJSONContent: (content: any) => void): Promise<void>;
3400
+ declare function richText2Markdown(content: SourceChatRichTextContent): Promise<string>;
3401
+ declare function getFromMessageSummary(message: ISourceChatMessage, source?: ISource): string;
3402
+ declare function getToMessageSummary(message: ISourceChatMessage, source?: ISource): string;
3403
+ declare function createFormilySchema<Decorator, Component, DecoratorProps, ComponentProps, Pattern, Display, Validator, Message>(properties: SchemaProperties<Decorator, Component, DecoratorProps, ComponentProps, Pattern, Display, Validator, Message>): IConfigSchema;
3404
+ declare function filterContentRule(text: string, r: IMessageContentRule): boolean;
3405
+ declare function sleep(ms: number): Promise<void>;
3406
+ declare function checkMessageRule(r: IMessageRule, data: ISourceChatMessageEventData): boolean;
3407
+ declare function installAndGetPluginInfo(name: string, version?: string, registry?: string): Promise<IOnlinePluginInfo>;
3408
+ declare function uninstallDep(name: string): Promise<IOnlinePluginInfo>;
3409
+ declare function getEnvNumber(key: string): number | undefined;
3410
+ declare function extractMessageContentText(content: SourceChatContent): string;
3411
+
3412
+ /**
3413
+ * 按照进来顺序回调输出
3414
+ */
3415
+ declare class SortedPromise extends Emittery {
3416
+ private _queue;
3417
+ private _logger;
3418
+ add<T>(p: Promise<T>): Promise<T>;
3419
+ }
3420
+
3421
+ export { Agent, type AgentChatMessageReplyType, AgentService, AsyncFile, type AsyncFileLoader, BaiduSTTSkill, BaiduTTSSkill, BaseDrawSkill, BaseSTTSkill, BaseTTSSkill, BasicBot, type BotCreator, BotManager, CogVideoDrawSkill, CogviewDrawSkill, CozeBot, CozeService, CronTaskTrigger, DifyAgentBot, DingRobotSource, EchoTaskRunner, EventTaskTrigger, FastGPTBot, FeishuSource, FishAudioTTSSkill, GlobalEvent, GlobalEventNames, GlobalEventTaskTrigger, HistoryMessageManager, type IAgentChatEventData, type IAgentModels, type IAgentOptions, type IAgentServiceOptions, type IAsyncFile, type IAsyncFileSource, type IBaiduSTTSkillOptions, type IBaiduTTSSkillOptions, type IBaseDrawSkillOptions, type IBaseSTTSkillOptions, type IBaseTTSSkillOptions, type IBasicBotOptions, type IBot, type IBotEventData, type IBotFileInfo, type IBotHistoryMessage, type IBotHistoryRecordEventData, type IBotOptions, type IBotParams, type IBotReadyMessage, type ICogVideoDrawSkillOptions, type ICogviewDrawSkillOptions, type IConfigParams, type IConfigSchema, type ICozeBotOptions, type ICozeServiceOptions, type ICronTaskTriggerOptions, type IDifyAgentBotOptions, type IDingRobotSourceOptions, type IDingRobotSourceParams, type IDisposable, type IDrawResult, type IEventTaskTriggerOptions, type IFastGPTBotOptions, type IFeishuSourceOptions, type IFishAudioTTSSkillOptions, type IGlobalEventData, type IGlobalNotifyEventData, type IHisotryMessageManagerOptions, type IInstance, type IInstanceBaseMangerOptions, type IInstanceCreateOptions, type ILastBotMessageInfo, type ILogger, type ILoggerEmitContent, type IMessageContentReceiver, type IMessageContentRule, type IMessageRule, type IModelInfo, type IOllamaBotOptions, type IOnlinePluginInfo, type IOpenAIBotOptions, type IOpenAIDrawSkillOptions, type IOpenAISTTSkillOptions, type IOpenAITTSSkillOptions, type IPPAgentOptions, type IPPAgentPlugin, type IPPAgentPluginHandler, type IPPAgentPluginOptions, type IQAnythingBotOptions, type IQQSourceOptions, type ISenseVoiceSTTSkillOptions, type ISiliconFlowDrawSkillOptions, type ISiliconFlowSTTSkillOptions, type ISiliconFlowTTSSkillOptions, type ISimpleSchemaItem, type ISkill, type ISkillOptions, type ISkillParams, type ISource, type ISourceActionInfo, type ISourceApiAction, type ISourceApiResponseType, type ISourceChatMessage, type ISourceChatMessageEventData, type ISourceEventData, type ISourceEventTaskTriggerOptions, type ISourceGroupChatMessage, type ISourceGroupInfoChangedEventData, type ISourceLoginEventData, type ISourceLogoutEventData, type ISourceOptions, type ISourceParamas, type ISourceSystemEventData, type ISourceTodoEventData, type ISourceUserInfo, type ISourceWSNormalInMessage, type ISourceWSNormalOutMessage, type ISoviteTTSSkillOptions, type ITaskConfig, type ITaskEventTriggerData, type ITaskRunResult, type ITaskRunner, type ITaskRunnerOptions, type ITaskRunnerParams, type ITaskServiceOptions, type ITaskTrigger, type ITaskTriggerData, type ITaskTriggerOptions, type ITaskTriggerParams, type ITencentSTTSkillOptions, type ITencentTTSSkillOptions, type IWCAISourceOptions, type IWCOASourceOptions, type IWeWorkSourceOptions, type IWenxinAgentBotOptions, type IXunfeiBotOptions, type IXunfeiSTTSkillOptions, type IXunfeiTTSSkillOptions, type IYuanQiBotOptions, type IZhipuBotOptions, type IZhipuQingyanBotOptions, InstanceBaseManager, OllamaBot, OpenAIBot, OpenAIDrawSkill, OpenAISTTSkill, OpenAITTSSkill, OpenRouterBot, PPAgent, QAnythingBot, QQSource, SchemaBaseProperties, SenseVoiceSTTSkill, SiliconFlowBot, SiliconFlowDrawSkill, SiliconFlowSTTSkill, SiliconFlowTTSSkill, SimpleSchemaType, type SkillCreator, SkillManager, SkillSchemaBaseProperties, SortedPromise, SourceApiMissingParamsError, SourceApiNotFoundError, SourceApiUnAuthorizedError, type SourceChatArticleContent, type SourceChatAudioContent, type SourceChatCardContent, type SourceChatContactContent, type SourceChatContent, type SourceChatEmotionContent, type SourceChatFileContent, type SourceChatImageContent, type SourceChatMPContent, SourceChatMessageType, type SourceChatMusicContent, type SourceChatPatContentType, type SourceChatPhoneContent, type SourceChatPositionContent, type SourceChatRecallContent, type SourceChatRefContent, type SourceChatRichTextContent, type SourceChatSubscribeContent, type SourceChatSystemContent, type SourceChatTextContent, type SourceChatVideoContent, type SourceCreator, SourceEventTaskTrigger, SourceEventType, SourceManager, type SourceWSCustomAction, type SourceWSNormalAction, SoviteTTSSkill, type TaskRunnerCreator, TaskRunnerManager, TaskRunnerSchemaBaseProperties, TaskService, TaskTrigger, type TaskTriggerCreator, TaskTriggerManager, TencentSTTSkill, TencentTTSSkill, WCAISource, WCOASource, WeWorkSource, WenxinAgentBot, XunfeiBot, XunfeiSTTSkill, XunfeiTTSSkill, YuanQiBot, ZhipuBot, ZhipuQingyanBot, addWavHeader, apiPlugin, arm2wav, betterMarkdown, checkMessageRule, config, createCacheManager, createFormilySchema, defaultPlugin, detectName, disposeObjects, extractArticleInfo, extractImageUrls, extractMarkdownImageTags, extractMessageContentText, extractPositionInfo, filterContentRule, generateRandomString, getEnvNumber, getFromMessageSummary, getLogger, getSecret, getToMessageSummary, hasEmoji, hasMarkdown, installAndGetPluginInfo, isPhoneNumber, removeEmoji, removeMarkdown, richText2Markdown, sleep, sse, stream2buffer, transFileFormat, transFormat, uninstallDep, wav2amr };