@zero-library/chat-agent 2.0.9 → 2.1.0

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