@zero-library/chat-agent 2.0.10 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.cjs.js +889 -753
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.css +78 -62
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +267 -44
- package/dist/index.d.ts +267 -44
- package/dist/index.esm.js +891 -755
- package/dist/index.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,64 +1,286 @@
|
|
|
1
|
-
import { RenderControl } from '@zero-library/common';
|
|
1
|
+
import { RenderControl, UserInfo } from '@zero-library/common';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { Conversation } from '@ant-design/x';
|
|
4
4
|
import { ThemeConfig } from 'antd';
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
type ConversationMemberEnum = 'agent' | 'user' | 'other';
|
|
7
|
+
|
|
7
8
|
interface InputFile {
|
|
9
|
+
/**
|
|
10
|
+
* Content,文件内容
|
|
11
|
+
*/
|
|
12
|
+
content: string;
|
|
13
|
+
/**
|
|
14
|
+
* 文件模式 remote_url local_file
|
|
15
|
+
*/
|
|
16
|
+
mode: string;
|
|
17
|
+
/**
|
|
18
|
+
* Type,文件类型
|
|
19
|
+
*/
|
|
8
20
|
type: string;
|
|
9
|
-
|
|
21
|
+
/**
|
|
22
|
+
* 文件扩展名
|
|
23
|
+
*/
|
|
24
|
+
extension: string;
|
|
25
|
+
/**
|
|
26
|
+
* 文件名
|
|
27
|
+
*/
|
|
10
28
|
name: string;
|
|
29
|
+
}
|
|
30
|
+
interface MessageQuoteMsg {
|
|
31
|
+
/**
|
|
32
|
+
* Id,消息ID
|
|
33
|
+
*/
|
|
34
|
+
id?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Msgcontent,消息内容
|
|
37
|
+
*/
|
|
38
|
+
msgContent?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Msgfiles,附件文件列表
|
|
41
|
+
*/
|
|
42
|
+
msgFiles?: InputFile;
|
|
43
|
+
}
|
|
44
|
+
interface MessageSender {
|
|
45
|
+
/**
|
|
46
|
+
* Curruser,是否为当前用户
|
|
47
|
+
*/
|
|
48
|
+
currUser?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Id,发送者ID
|
|
51
|
+
*/
|
|
11
52
|
id: string;
|
|
12
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Type,1-用户 2-专家 3-Agent 4-税协
|
|
55
|
+
*/
|
|
56
|
+
type: number;
|
|
13
57
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
58
|
+
interface ConversationMessage {
|
|
59
|
+
/**
|
|
60
|
+
* Conversationid,会话ID
|
|
61
|
+
*/
|
|
17
62
|
conversationId: string;
|
|
18
|
-
|
|
63
|
+
conversationTitle?: string;
|
|
64
|
+
type?: 'TEXT_MESSAGE_START' | 'STEP_STARTED' | 'TEXT_MESSAGE_CONTENT' | 'TEXT_MESSAGE_END';
|
|
65
|
+
/**
|
|
66
|
+
* Id,消息ID
|
|
67
|
+
*/
|
|
68
|
+
id: string;
|
|
69
|
+
/**
|
|
70
|
+
* Msgcontent,消息内容
|
|
71
|
+
*/
|
|
72
|
+
msgContent: string;
|
|
73
|
+
/**
|
|
74
|
+
* Msgfeedback,消息反馈
|
|
75
|
+
*/
|
|
76
|
+
msgFeedback?: number;
|
|
77
|
+
/**
|
|
78
|
+
* Msgfiles,附件文件列表
|
|
79
|
+
*/
|
|
80
|
+
msgFiles?: InputFile[];
|
|
81
|
+
/**
|
|
82
|
+
* 引消息
|
|
83
|
+
*/
|
|
84
|
+
quoteMsg?: MessageQuoteMsg;
|
|
85
|
+
/**
|
|
86
|
+
* 发送者信息
|
|
87
|
+
*/
|
|
88
|
+
sender?: MessageSender;
|
|
89
|
+
/**
|
|
90
|
+
* Sendtime,发送时间
|
|
91
|
+
*/
|
|
92
|
+
sendTime: number;
|
|
93
|
+
/**
|
|
94
|
+
* Stopflag,是否打断
|
|
95
|
+
*/
|
|
96
|
+
stopFlag?: boolean;
|
|
19
97
|
}
|
|
20
|
-
interface
|
|
21
|
-
|
|
98
|
+
interface ConversationMessageSend {
|
|
99
|
+
/**
|
|
100
|
+
* Conversationid,会话 ID
|
|
101
|
+
*/
|
|
22
102
|
conversationId: string;
|
|
23
|
-
|
|
103
|
+
/**
|
|
104
|
+
* Msgcontent,消息内容
|
|
105
|
+
*/
|
|
106
|
+
msgContent: string;
|
|
107
|
+
/**
|
|
108
|
+
* Msgfiles,附件文件列表
|
|
109
|
+
*/
|
|
110
|
+
msgFiles?: InputFile[];
|
|
111
|
+
/**
|
|
112
|
+
* Params,业务参数,透传到智能体
|
|
113
|
+
*/
|
|
114
|
+
params?: string;
|
|
115
|
+
/**
|
|
116
|
+
* Quotemsgid,引用的消息 ID,大于 0 的整数
|
|
117
|
+
*/
|
|
118
|
+
quoteMsgId?: number;
|
|
119
|
+
/**
|
|
120
|
+
* Receiverid,接收者 ID。当 receiverType ≠ 3(非 agent)时,后端需填充此字段
|
|
121
|
+
*/
|
|
122
|
+
receiverId: string;
|
|
123
|
+
/**
|
|
124
|
+
* Receivertype,接收者身份,必填:1-用户;2-专家;3-agent 4-税协
|
|
125
|
+
*/
|
|
126
|
+
receiverType: number;
|
|
127
|
+
/**
|
|
128
|
+
* Returntype,返回方式:1-http;2-ws(WebSocket)
|
|
129
|
+
*/
|
|
130
|
+
returnType: number;
|
|
131
|
+
/**
|
|
132
|
+
* Senderid,发送者 ID
|
|
133
|
+
*/
|
|
134
|
+
senderId: string;
|
|
135
|
+
/**
|
|
136
|
+
* Sendertype,发送者身份,必填:1-用户;2-专家;3-agent 4-税协
|
|
137
|
+
*/
|
|
138
|
+
senderType: number;
|
|
139
|
+
/**
|
|
140
|
+
* Source,会话来源: 1-罗拉-APP; 2-罗拉-pc端; 3-合作伙伴端 4-税协 5-罗拉-cube 6-api
|
|
141
|
+
*/
|
|
142
|
+
source: number;
|
|
143
|
+
/**
|
|
144
|
+
* Stream,是否启用流式返回响应结果
|
|
145
|
+
*/
|
|
146
|
+
stream: boolean;
|
|
24
147
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
148
|
+
/**
|
|
149
|
+
* FileUploadConfig,文件上传配置
|
|
150
|
+
*/
|
|
151
|
+
interface FileUploadConfig {
|
|
152
|
+
/**
|
|
153
|
+
* Allowedfiletypes,允许的文件类型
|
|
154
|
+
*/
|
|
155
|
+
allowedFileTypes: string[];
|
|
156
|
+
/**
|
|
157
|
+
* Enabled,是否启用文件上传
|
|
158
|
+
*/
|
|
159
|
+
enabled: boolean;
|
|
160
|
+
/**
|
|
161
|
+
* Maxfilecount,最大文件数量
|
|
162
|
+
*/
|
|
163
|
+
maxFileCount: number;
|
|
164
|
+
/**
|
|
165
|
+
* Maxfilesize,最大文件大小
|
|
166
|
+
*/
|
|
167
|
+
maxFileSize?: number;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* QuestionBO,推荐问题或热门问题项
|
|
171
|
+
*/
|
|
172
|
+
interface RecommendQuestion {
|
|
173
|
+
/**
|
|
174
|
+
* Id,问题 ID
|
|
175
|
+
*/
|
|
176
|
+
id: number;
|
|
177
|
+
/**
|
|
178
|
+
* Question,问题内容
|
|
179
|
+
*/
|
|
180
|
+
question: string;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* LabelBO,热门问题标签
|
|
184
|
+
*/
|
|
185
|
+
interface HotQuestionList {
|
|
186
|
+
/**
|
|
187
|
+
* Id,标签 ID
|
|
188
|
+
*/
|
|
189
|
+
id: number;
|
|
190
|
+
/**
|
|
191
|
+
* Items,标签下的问题列表
|
|
192
|
+
*/
|
|
193
|
+
items: RecommendQuestion[];
|
|
194
|
+
/**
|
|
195
|
+
* Name,标签名称
|
|
196
|
+
*/
|
|
197
|
+
name: string;
|
|
198
|
+
}
|
|
199
|
+
interface AgentConfig {
|
|
200
|
+
/**
|
|
201
|
+
* 文件上传配置
|
|
202
|
+
*/
|
|
203
|
+
fileUpload?: FileUploadConfig[];
|
|
204
|
+
/**
|
|
205
|
+
* Labels,热门问题标签列表
|
|
206
|
+
*/
|
|
207
|
+
labels?: HotQuestionList[];
|
|
208
|
+
/**
|
|
209
|
+
* Recommendquestions,推荐问题列表
|
|
210
|
+
*/
|
|
211
|
+
recommendQuestions?: RecommendQuestion[];
|
|
212
|
+
}
|
|
213
|
+
interface AgentInfo {
|
|
214
|
+
/**
|
|
215
|
+
* Agentname,名称
|
|
216
|
+
*/
|
|
217
|
+
agentName: string;
|
|
218
|
+
/**
|
|
219
|
+
* Agenttype,智能体类型
|
|
220
|
+
*/
|
|
221
|
+
agentType: number;
|
|
222
|
+
/**
|
|
223
|
+
* 智能体的附带信息
|
|
224
|
+
*/
|
|
225
|
+
config: AgentConfig;
|
|
226
|
+
/**
|
|
227
|
+
* Description,描述
|
|
228
|
+
*/
|
|
229
|
+
description?: string;
|
|
230
|
+
/**
|
|
231
|
+
* Id,主键
|
|
232
|
+
*/
|
|
233
|
+
id: string;
|
|
234
|
+
/**
|
|
235
|
+
* Isavailable,是否可用
|
|
236
|
+
*/
|
|
237
|
+
isAvailable?: boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Logo,logo
|
|
240
|
+
*/
|
|
241
|
+
logo: string;
|
|
242
|
+
feature?: string;
|
|
33
243
|
}
|
|
34
244
|
|
|
245
|
+
type ConversationStrategy = 1 | 2;
|
|
246
|
+
interface ReferencesContent extends MessageQuoteMsg {
|
|
247
|
+
name?: string;
|
|
248
|
+
markdown?: string;
|
|
249
|
+
[key: string]: any;
|
|
250
|
+
}
|
|
35
251
|
interface ReferencesType {
|
|
36
252
|
type: number;
|
|
37
|
-
content:
|
|
38
|
-
name?: string;
|
|
39
|
-
markdown?: string;
|
|
40
|
-
[key: string]: any;
|
|
41
|
-
};
|
|
253
|
+
content: ReferencesContent;
|
|
42
254
|
params?: ObjectType<any>;
|
|
43
255
|
}
|
|
44
256
|
interface ChatHooks {
|
|
257
|
+
onBeforeInit?: () => void;
|
|
258
|
+
onAfterInit?: () => void;
|
|
45
259
|
onSenderFocus?: () => void;
|
|
46
260
|
onHeaderClose?: () => void;
|
|
47
|
-
onBeforeSend?: (message:
|
|
261
|
+
onBeforeSend?: (message: ConversationMessageSend['msgContent'], files: InputFile[]) => boolean | Promise<boolean> | void;
|
|
48
262
|
onAfterSend?: () => void;
|
|
49
263
|
onBeforeSwitchAgent?: (agentId: string) => boolean | Promise<boolean> | void;
|
|
50
264
|
onAfterSwitchAgent?: (agentId: string) => void;
|
|
51
|
-
onBeforeSwitchConversation?: (conversationId: string
|
|
52
|
-
onAfterSwitchConversation?: (conversationId: string
|
|
265
|
+
onBeforeSwitchConversation?: (conversationId: string) => boolean | Promise<boolean> | void;
|
|
266
|
+
onAfterSwitchConversation?: (conversationId: string) => void;
|
|
267
|
+
onBeforeInitMessages?: (conversationId: string) => boolean | Promise<boolean> | void;
|
|
268
|
+
onAfterInitMessages?: (messages: ConversationMessage[]) => void;
|
|
269
|
+
onBeforeDelConversation?: (conversationId: string) => boolean | Promise<boolean> | void;
|
|
270
|
+
onAfterDelConversation?: (conversationId: string, isCurrentConversation: boolean) => void;
|
|
53
271
|
}
|
|
54
272
|
interface ChatParams {
|
|
55
|
-
|
|
273
|
+
source?: number;
|
|
274
|
+
businessData?: string;
|
|
275
|
+
businessId?: string;
|
|
276
|
+
businessType?: number;
|
|
56
277
|
params?: ObjectType<any>;
|
|
57
278
|
}
|
|
58
279
|
interface ChatLayoutHeader {
|
|
59
280
|
title?: RenderControl<void, void>;
|
|
60
281
|
closeBtn?: boolean;
|
|
61
282
|
newConversationBtn?: RenderControl<void, void>;
|
|
283
|
+
agentCharacter?: boolean;
|
|
62
284
|
conversationListBtn?: boolean;
|
|
63
285
|
}
|
|
64
286
|
interface ChatLayoutConversationList {
|
|
@@ -69,11 +291,15 @@ interface ChatLayoutSender {
|
|
|
69
291
|
extraBtn?: RenderControl<void, void>;
|
|
70
292
|
referencesBtn?: RenderControl<void, void>;
|
|
71
293
|
}
|
|
294
|
+
interface ChatLayoutMessageList {
|
|
295
|
+
avatar?: boolean | Partial<Record<ConversationMemberEnum, boolean>>;
|
|
296
|
+
firstMessage?: RenderControl<void, void>;
|
|
297
|
+
}
|
|
72
298
|
interface ChatLayout {
|
|
73
299
|
leftPanel?: RenderControl<void, void>;
|
|
74
300
|
conversationList?: RenderControl<void, ChatLayoutConversationList>;
|
|
75
301
|
preview?: boolean;
|
|
76
|
-
messageList?:
|
|
302
|
+
messageList?: RenderControl<void, ChatLayoutMessageList>;
|
|
77
303
|
senderHeader?: RenderControl<void, void>;
|
|
78
304
|
sender?: RenderControl<void, ChatLayoutSender>;
|
|
79
305
|
senderPrompts?: boolean;
|
|
@@ -83,31 +309,28 @@ interface ChatLayout {
|
|
|
83
309
|
disclaimerNotice?: RenderControl<void, void>;
|
|
84
310
|
}
|
|
85
311
|
|
|
312
|
+
interface ChatConfig {
|
|
313
|
+
receiverType?: number;
|
|
314
|
+
receiverId?: string;
|
|
315
|
+
conversationId?: string;
|
|
316
|
+
conversationStrategy?: ConversationStrategy;
|
|
317
|
+
}
|
|
86
318
|
interface Props {
|
|
87
319
|
theme?: ThemeConfig;
|
|
88
|
-
|
|
89
|
-
appKey?: string;
|
|
90
|
-
agentKey?: string;
|
|
91
|
-
conversationId?: string;
|
|
92
|
-
};
|
|
320
|
+
config?: ChatConfig;
|
|
93
321
|
params?: ChatParams;
|
|
94
322
|
hooks?: ChatHooks;
|
|
95
323
|
layout?: ChatLayout;
|
|
324
|
+
userInfo?: UserInfo;
|
|
96
325
|
}
|
|
97
326
|
interface ChatHandle {
|
|
98
|
-
sendMessage: (message?: string, files?: InputFile[]) =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
agentKey: string;
|
|
102
|
-
isVerify: boolean;
|
|
103
|
-
}, conversationId?: Conversation['key']) => Promise<void>;
|
|
104
|
-
switchConversation: (conversation?: Conversation) => Promise<void>;
|
|
327
|
+
sendMessage: (message?: string, files?: InputFile[]) => void;
|
|
328
|
+
switchAgentConversation: (agentId: AgentInfo['id'], strategy?: ConversationStrategy) => void;
|
|
329
|
+
switchConversation: (id?: Conversation['id']) => void;
|
|
105
330
|
setReferences: (references?: ReferencesType) => void;
|
|
106
331
|
setMessage: (message?: string) => void;
|
|
107
332
|
setFiles: (files?: InputFile[]) => void;
|
|
108
|
-
setParams: (params: Props['params']) => void;
|
|
109
|
-
setLayout: (layout: Props['layout']) => void;
|
|
110
333
|
}
|
|
111
334
|
declare const _default: react.ForwardRefExoticComponent<Props & react.RefAttributes<ChatHandle>>;
|
|
112
335
|
|
|
113
|
-
export { _default as
|
|
336
|
+
export { type ChatConfig, _default as ChatCopilot, type ChatHandle, type ChatLayout };
|