@kweaver-ai/chatkit 0.1.17 → 0.1.19
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/chatkit.cjs.js +80 -80
- package/dist/chatkit.es.js +11729 -11457
- package/dist/components/base/ChatKitBase.d.ts +123 -115
- package/dist/components/base/assistant/blocks/index.d.ts +1 -0
- package/dist/components/base/copilot/blocks/index.d.ts +1 -0
- package/dist/components/base/shared/blocks/WebProcessorBlock/WebProcessorContentView.d.ts +9 -0
- package/dist/components/base/shared/blocks/WebProcessorBlock/WebProcessorIframe.d.ts +8 -0
- package/dist/components/base/shared/blocks/WebProcessorBlock/WebProcessorModal.d.ts +10 -0
- package/dist/components/base/shared/blocks/WebProcessorBlock/index.d.ts +9 -0
- package/dist/components/base/shared/blocks/WebProcessorBlock/utils.d.ts +6 -0
- package/dist/components/base/shared/blocks/WebProcessorBlock.d.ts +7 -0
- package/dist/components/dip/DIPBase.d.ts +128 -125
- package/dist/types/index.d.ts +107 -89
- package/package.json +1 -1
|
@@ -1,84 +1,84 @@
|
|
|
1
1
|
import { Component } from 'react';
|
|
2
|
-
import { ChatMessage, ApplicationContext, ChatKitInterface, OnboardingInfo, WebSearchQuery, ExecuteCodeResult, Text2SqlResult, Text2MetricResult, AfSailorResult, DatasourceFilterResult, DatasourceRerankResult, ChartDataSchema, DefaultToolResult, MessageContext } from '../../types';
|
|
2
|
+
import { ChatMessage, ApplicationContext, ChatKitInterface, OnboardingInfo, WebSearchQuery, ExecuteCodeResult, Text2SqlResult, Text2MetricResult, AfSailorResult, DatasourceFilterResult, DatasourceRerankResult, ChartDataSchema, DefaultToolResult, MessageContext, WebProcessorDataSchema } from '../../types';
|
|
3
3
|
/**
|
|
4
|
-
* ChatKitBase
|
|
4
|
+
* ChatKitBase 组件的属性接�?
|
|
5
5
|
*/
|
|
6
6
|
export interface ChatKitBaseProps {
|
|
7
7
|
/** 会话 ID,每次新建会话时由后端返回新的会话唯一标识 */
|
|
8
8
|
conversationID?: string;
|
|
9
|
-
/** 当没有指定的 inputContext
|
|
9
|
+
/** 当没有指定的 inputContext 时的默认输入上下�?*/
|
|
10
10
|
defaultApplicationContext?: ApplicationContext;
|
|
11
11
|
/** 组件标题 */
|
|
12
12
|
title?: string;
|
|
13
13
|
/** 是否显示组件 */
|
|
14
14
|
visible?: boolean;
|
|
15
|
-
/**
|
|
15
|
+
/** 关闭组件的回调函�?*/
|
|
16
16
|
onClose?: () => void;
|
|
17
17
|
/** 调用接口时携带的令牌,放置到请求头:Authorization:Bearer {token} */
|
|
18
18
|
token?: string;
|
|
19
19
|
/** 刷新 token 的方法,由集成方传入 */
|
|
20
20
|
refreshToken?: () => Promise<string>;
|
|
21
21
|
/**
|
|
22
|
-
*
|
|
22
|
+
* 初始用户问题�?
|
|
23
23
|
*
|
|
24
|
-
* -
|
|
25
|
-
* -
|
|
24
|
+
* - 外层在挂�?Assistant / Copilot 等组件时传入
|
|
25
|
+
* - 当组件首次可见且当前没有任何消息时,会自动发送该问题并触发问�?
|
|
26
26
|
*/
|
|
27
27
|
initialQuestion?: string;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* ChatKitBase
|
|
30
|
+
* ChatKitBase 组件的状态接�?
|
|
31
31
|
*/
|
|
32
32
|
export interface ChatKitBaseState {
|
|
33
33
|
/** 会话 ID,每次新建会话时由后端返回新的会话唯一标识 */
|
|
34
34
|
conversationID: string;
|
|
35
|
-
/**
|
|
35
|
+
/** 消息列表,这里仅记录渲染到界面上的对话消�?*/
|
|
36
36
|
messages: ChatMessage[];
|
|
37
|
-
/**
|
|
37
|
+
/** 用户输入的文�?*/
|
|
38
38
|
textInput: string;
|
|
39
|
-
/**
|
|
39
|
+
/** 和用户输入文本相关的上下�?*/
|
|
40
40
|
applicationContext?: ApplicationContext;
|
|
41
|
-
/**
|
|
41
|
+
/** 是否正在发送消�?*/
|
|
42
42
|
isSending: boolean;
|
|
43
|
-
/**
|
|
43
|
+
/** 当前正在流式更新的消�?ID */
|
|
44
44
|
streamingMessageId: string | null;
|
|
45
|
-
/**
|
|
45
|
+
/** 开场白信息,包含开场白文案和预置问�?*/
|
|
46
46
|
onboardingInfo?: OnboardingInfo;
|
|
47
47
|
/** 是否正在加载开场白信息 */
|
|
48
48
|
isLoadingOnboarding: boolean;
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
51
|
* ChatKitBase 基础组件
|
|
52
|
-
* AI
|
|
52
|
+
* AI 对话组件的核心类。该类是一�?React 组件,包含标准的交互界面和交互逻辑�?
|
|
53
53
|
*
|
|
54
|
-
* 注意:开发者不能够直接挂载 ChatKitBase
|
|
55
|
-
* ChatKitBase
|
|
54
|
+
* 注意:开发者不能够直接挂载 ChatKitBase �?Web 应用,而是需要创建一个子类继�?
|
|
55
|
+
* ChatKitBase �?ChatKitInterface,并实现 ChatKitInterface 中定义的方法�?
|
|
56
56
|
*
|
|
57
|
-
*
|
|
57
|
+
* 该类实现�?ChatKitInterface 接口,子类需要实�?sendMessage �?reduceEventStreamMessage 方法
|
|
58
58
|
*/
|
|
59
59
|
export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBaseProps> extends Component<P, ChatKitBaseState> implements ChatKitInterface {
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* 标记是否正在初始化或已经初始�?
|
|
62
62
|
* 用于防止重复初始化(特别是在 React.StrictMode 下)
|
|
63
63
|
*/
|
|
64
64
|
private isInitializing;
|
|
65
65
|
private hasInitialized;
|
|
66
66
|
/**
|
|
67
|
-
*
|
|
68
|
-
*
|
|
67
|
+
* 会话代数:用于区分「旧会话的流式更新」和「新会话�?
|
|
68
|
+
* 每次清空/新建会话时自增,流式处理只在代数未变化时才继续写�?state
|
|
69
69
|
*/
|
|
70
70
|
private conversationSeq;
|
|
71
71
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
72
|
+
* 当前流式请求�?AbortController
|
|
73
|
+
* 子类在发起流�?fetch 时应设置该字段,便于�?handleStop / 新建会话时主动中断连�?
|
|
74
74
|
*/
|
|
75
75
|
protected currentStreamController?: AbortController;
|
|
76
76
|
/**
|
|
77
|
-
* 是否已经根据 initialQuestion
|
|
77
|
+
* 是否已经根据 initialQuestion 触发过一次自动发�?
|
|
78
78
|
*/
|
|
79
79
|
private hasSentInitialQuestion;
|
|
80
80
|
/**
|
|
81
|
-
* 流式响应时是否处于「按 chunk 批处理」中,避免同一 chunk
|
|
81
|
+
* 流式响应时是否处于「按 chunk 批处理」中,避免同一 chunk 内多行事件触发多�?setState 导致 Maximum update depth exceeded
|
|
82
82
|
*/
|
|
83
83
|
private _streamingBatch;
|
|
84
84
|
private _pendingStreamingUpdates;
|
|
@@ -92,119 +92,119 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
92
92
|
protected refreshToken?: () => Promise<string>;
|
|
93
93
|
constructor(props: P);
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
95
|
+
* 组件挂载后自动创建会�?
|
|
96
96
|
* 根据设计文档要求:组件被初始化的时候会自动新建会话
|
|
97
97
|
*/
|
|
98
98
|
componentDidMount(): Promise<void>;
|
|
99
99
|
/**
|
|
100
100
|
* 组件更新时检查是否需要初始化会话
|
|
101
|
-
*
|
|
101
|
+
* �?visible �?false 变为 true 时,如果还未初始化,则初始化会话
|
|
102
102
|
*/
|
|
103
103
|
componentDidUpdate(prevProps: P): Promise<void>;
|
|
104
104
|
/**
|
|
105
105
|
* 初始化会话的内部方法
|
|
106
|
-
*
|
|
106
|
+
* 仅在组件首次可见时调用,防止重复初始�?
|
|
107
107
|
*/
|
|
108
108
|
private initializeConversation;
|
|
109
109
|
/**
|
|
110
|
-
* 根据 props.initialQuestion
|
|
110
|
+
* 根据 props.initialQuestion 在合适的时机自动触发一次问�?
|
|
111
111
|
*
|
|
112
|
-
*
|
|
113
|
-
* - 组件当前处于可见状态(visible !== false
|
|
112
|
+
* 触发条件�?
|
|
113
|
+
* - 组件当前处于可见状态(visible !== false�?
|
|
114
114
|
* - props.initialQuestion 为非空字符串
|
|
115
|
-
* - 当前还没有任何对话消息(messages.length === 0
|
|
116
|
-
* - 仅触发一次(hasSentInitialQuestion
|
|
115
|
+
* - 当前还没有任何对话消息(messages.length === 0�?
|
|
116
|
+
* - 仅触发一次(hasSentInitialQuestion �?false�?
|
|
117
117
|
*/
|
|
118
118
|
private trySendInitialQuestion;
|
|
119
119
|
/**
|
|
120
|
-
*
|
|
121
|
-
* 该方法需要由子类继承并重写,以适配扣子、Dify
|
|
122
|
-
*
|
|
120
|
+
* 获取开场白和预置问�?(抽象方法,由子类实现)
|
|
121
|
+
* 该方法需要由子类继承并重写,以适配扣子、Dify �?LLMOps 平台的接�?
|
|
122
|
+
* 返回开场白信息结构�?
|
|
123
123
|
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state
|
|
124
|
-
* @returns
|
|
124
|
+
* @returns 返回开场白信息,包含开场白文案和预置问�?
|
|
125
125
|
*/
|
|
126
126
|
abstract getOnboardingInfo(): Promise<OnboardingInfo>;
|
|
127
127
|
/**
|
|
128
128
|
* 新建会话 (抽象方法,由子类实现)
|
|
129
|
-
* 该方法需要由开发者实现,以适配扣子、Dify
|
|
129
|
+
* 该方法需要由开发者实现,以适配扣子、Dify �?LLMOps 平台的接�?
|
|
130
130
|
* 成功返回会话 ID
|
|
131
131
|
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state
|
|
132
|
-
* @param title
|
|
132
|
+
* @param title 会话标题,通常是用户发送的第一条消息内�?
|
|
133
133
|
* @returns 返回新创建的会话 ID
|
|
134
134
|
*/
|
|
135
135
|
abstract generateConversation(title?: string): Promise<string>;
|
|
136
136
|
/**
|
|
137
|
-
*
|
|
138
|
-
* 该方法需要由开发者实现,以适配扣子、Dify
|
|
137
|
+
* 向后端发送消�?(抽象方法,由子类实现)
|
|
138
|
+
* 该方法需要由开发者实现,以适配扣子、Dify�?LLMOps 平台的接�?
|
|
139
139
|
* 发送成功后,返回发送的消息结构
|
|
140
140
|
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state
|
|
141
141
|
* @param text 发送给后端的用户输入的文本
|
|
142
|
-
* @param ctx
|
|
142
|
+
* @param ctx 随用户输入文本一起发送的应用上下�?
|
|
143
143
|
* @param conversationID 发送的对话消息所属的会话 ID
|
|
144
144
|
* @returns 返回发送的消息结构
|
|
145
145
|
*/
|
|
146
146
|
abstract sendMessage(text: string, ctx: ApplicationContext, conversationID?: string, regenerateMessageId?: string): Promise<ChatMessage>;
|
|
147
147
|
/**
|
|
148
|
-
*
|
|
148
|
+
* �?API 接口返回�?EventStream 增量解析成完整的 AssistantMessage 对象 (抽象方法,由子类实现)
|
|
149
149
|
* 当接收到 SSE 消息时触发,该方法需要由子类实现
|
|
150
|
-
*
|
|
151
|
-
* - appendMarkdownBlock(): 添加 Markdown
|
|
152
|
-
* - appendWebSearchBlock(): 添加 Web
|
|
153
|
-
* - appendExecuteCodeBlock():
|
|
154
|
-
* 注意:该方法应该只处理数据解析逻辑,通过调用 append*Block
|
|
155
|
-
* @param eventMessage
|
|
156
|
-
* @param prev
|
|
157
|
-
* @param messageId
|
|
150
|
+
* 子类在该方法中应该调用以下方法来更新消息内容�?
|
|
151
|
+
* - appendMarkdownBlock(): 添加 Markdown 文本�?
|
|
152
|
+
* - appendWebSearchBlock(): 添加 Web 搜索结果�?
|
|
153
|
+
* - appendExecuteCodeBlock(): 添加代码执行结果�?
|
|
154
|
+
* 注意:该方法应该只处理数据解析逻辑,通过调用 append*Block 方法来更新界�?
|
|
155
|
+
* @param eventMessage 接收到的一�?Event Message
|
|
156
|
+
* @param prev 上一次增量更新后�?AssistantMessage 对象
|
|
157
|
+
* @param messageId 当前正在更新的消�?ID,用于调�?append*Block 方法
|
|
158
158
|
* @returns 返回更新后的 AssistantMessage 对象
|
|
159
159
|
*/
|
|
160
160
|
abstract reduceAssistantMessage<T = any, K = any>(eventMessage: T, prev: K, messageId: string): K;
|
|
161
161
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* 该方法需要由子类继承并重写,以适配扣子、Dify
|
|
165
|
-
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state
|
|
162
|
+
* 检查是否需要刷�?token (抽象方法,由子类实现)
|
|
163
|
+
* 当发生异常时检查是否需要刷�?token。返�?true 表示需要刷�?token,返�?false 表示无需刷新 token�?
|
|
164
|
+
* 该方法需要由子类继承并重写,以适配扣子、Dify �?LLMOps 平台的接口�?
|
|
165
|
+
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state�?
|
|
166
166
|
* @param status HTTP 状态码
|
|
167
|
-
* @param error
|
|
168
|
-
* @returns
|
|
167
|
+
* @param error 错误响应�?
|
|
168
|
+
* @returns 返回是否需要刷�?token
|
|
169
169
|
*/
|
|
170
170
|
abstract shouldRefreshToken(status: number, error: any): boolean;
|
|
171
171
|
/**
|
|
172
172
|
* 终止会话 (抽象方法,由子类实现)
|
|
173
|
-
* 该方法需要由子类继承并重写,以适配扣子、Dify
|
|
174
|
-
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state
|
|
173
|
+
* 该方法需要由子类继承并重写,以适配扣子、Dify �?LLMOps 平台的接口�?
|
|
174
|
+
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state�?
|
|
175
175
|
* @param conversationId 要终止的会话 ID
|
|
176
176
|
* @returns 返回 Promise,成功时 resolve,失败时 reject
|
|
177
177
|
*/
|
|
178
178
|
abstract terminateConversation(conversationId: string): Promise<void>;
|
|
179
179
|
/**
|
|
180
180
|
* 获取历史会话列表 (抽象方法,由子类实现)
|
|
181
|
-
* 该方法需要由子类继承并重写,以适配扣子、Dify
|
|
182
|
-
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state
|
|
181
|
+
* 该方法需要由子类继承并重写,以适配扣子、Dify �?LLMOps 平台的接口�?
|
|
182
|
+
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state�?
|
|
183
183
|
* @param page 分页页码,默认为 1
|
|
184
184
|
* @param size 每页返回条数,默认为 10
|
|
185
185
|
* @returns 返回历史会话列表
|
|
186
186
|
*/
|
|
187
187
|
abstract getConversations(page?: number, size?: number): Promise<import('../../types').ConversationHistory[]>;
|
|
188
188
|
/**
|
|
189
|
-
* 获取指定会话 ID
|
|
190
|
-
* 该方法需要由子类继承并重写,以适配扣子、Dify
|
|
191
|
-
*
|
|
192
|
-
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state
|
|
189
|
+
* 获取指定会话 ID 的对话消息列�?(抽象方法,由子类实现)
|
|
190
|
+
* 该方法需要由子类继承并重写,以适配扣子、Dify �?LLMOps 平台的接口�?
|
|
191
|
+
* 如果对话消息�?AI 助手消息,则需要调�?reduceAssistantMessage() 解析消息�?
|
|
192
|
+
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state�?
|
|
193
193
|
* @param conversationId 会话 ID
|
|
194
194
|
* @returns 返回对话消息列表
|
|
195
195
|
*/
|
|
196
196
|
abstract getConversationMessages(conversationId: string): Promise<ChatMessage[]>;
|
|
197
197
|
/**
|
|
198
|
-
* 删除指定 ID
|
|
199
|
-
* 该方法需要由子类继承并重写,以适配扣子、Dify
|
|
200
|
-
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state
|
|
198
|
+
* 删除指定 ID 的会�?(抽象方法,由子类实现)
|
|
199
|
+
* 该方法需要由子类继承并重写,以适配扣子、Dify �?LLMOps 平台的接口�?
|
|
200
|
+
* 注意:该方法是一个无状态无副作用的函数,不允许修改 state�?
|
|
201
201
|
* @param conversationID 会话 ID
|
|
202
202
|
* @returns 返回 Promise,成功时 resolve,失败时 reject
|
|
203
203
|
*/
|
|
204
204
|
abstract deleteConversation(conversationID: string): Promise<void>;
|
|
205
205
|
/**
|
|
206
|
-
*
|
|
207
|
-
* @param ctx
|
|
206
|
+
* �?ChatKit 注入应用上下�?
|
|
207
|
+
* @param ctx 要注入的应用上下�?
|
|
208
208
|
*/
|
|
209
209
|
injectApplicationContext: (ctx: ApplicationContext) => void;
|
|
210
210
|
/**
|
|
@@ -212,124 +212,132 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
212
212
|
*/
|
|
213
213
|
removeApplicationContext: () => void;
|
|
214
214
|
/**
|
|
215
|
-
*
|
|
216
|
-
* 该方法由子类调用,用于在消息中添加或更新 Markdown
|
|
217
|
-
*
|
|
215
|
+
* 添加或更�?Markdown 类型的消息块
|
|
216
|
+
* 该方法由子类调用,用于在消息中添加或更新 Markdown 内容�?
|
|
217
|
+
* 如果最后一个块�?Markdown 块且内容为空或是 text 的前缀,则更新它(流式更新场景�?
|
|
218
218
|
* 否则添加新的 Markdown 块(新阶段场景)
|
|
219
219
|
* @param messageId 消息 ID
|
|
220
|
-
* @param text
|
|
220
|
+
* @param text 要添加或更新�?Markdown 文本,每次都传完整的文本
|
|
221
221
|
*/
|
|
222
222
|
protected appendMarkdownBlock(messageId: string, text: string): void;
|
|
223
223
|
/**
|
|
224
224
|
* 添加 Web 搜索类型的消息块
|
|
225
|
-
*
|
|
225
|
+
* 该方法由子类调用,用于在消息中添�?Web 搜索结果
|
|
226
226
|
* @param messageId 消息 ID
|
|
227
|
-
* @param query Web
|
|
227
|
+
* @param query Web 搜索的执行详�?
|
|
228
228
|
*/
|
|
229
229
|
protected appendWebSearchBlock(messageId: string, query: WebSearchQuery): void;
|
|
230
230
|
/**
|
|
231
231
|
* 添加代码执行工具类型的消息块
|
|
232
|
-
*
|
|
232
|
+
* 该方法由子类调用,用于在消息中添加代码执行结�?
|
|
233
233
|
* @param messageId 消息 ID
|
|
234
234
|
* @param result 代码执行的输入和输出结果
|
|
235
235
|
*/
|
|
236
236
|
protected appendExecuteCodeBlock(messageId: string, result: ExecuteCodeResult, consumeTime?: number): void;
|
|
237
237
|
/**
|
|
238
238
|
* 添加 Text2SQL 工具类型的消息块
|
|
239
|
-
*
|
|
239
|
+
* 该方法由子类调用,用于在消息中添�?Text2SQL 查询结果
|
|
240
240
|
* @param messageId 消息 ID
|
|
241
241
|
* @param result Text2SQL 的输入和输出结果
|
|
242
|
-
* @param consumeTime
|
|
242
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
243
243
|
*/
|
|
244
244
|
protected appendText2SqlBlock(messageId: string, result: Text2SqlResult, consumeTime?: number): void;
|
|
245
245
|
/**
|
|
246
246
|
* 添加 Text2Metric 工具类型的消息块
|
|
247
|
-
*
|
|
247
|
+
* 该方法由子类调用,用于在消息中添�?Text2Metric 查询结果
|
|
248
248
|
* @param messageId 消息 ID
|
|
249
249
|
* @param result Text2Metric 的输入和输出结果
|
|
250
|
-
* @param consumeTime
|
|
250
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
251
251
|
*/
|
|
252
252
|
protected appendText2MetricBlock(messageId: string, result: Text2MetricResult, consumeTime?: number): void;
|
|
253
253
|
/**
|
|
254
254
|
* 添加 JSON2Plot 图表类型的消息块
|
|
255
|
-
*
|
|
255
|
+
* 该方法由子类调用,用于在消息中添�?JSON2Plot 图表数据
|
|
256
256
|
* @param messageId 消息 ID
|
|
257
257
|
* @param chartData 图表数据 Schema
|
|
258
|
-
* @param consumeTime
|
|
258
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
259
259
|
*/
|
|
260
260
|
protected appendJson2PlotBlock(messageId: string, chartData: ChartDataSchema, consumeTime?: number): void;
|
|
261
261
|
/**
|
|
262
|
-
*
|
|
263
|
-
*
|
|
262
|
+
* 更新指定消息中最后一�?JSON2Plot 图表块的内容(用于流式工�?json2plot 的组装)
|
|
263
|
+
* 如果不存�?JSON2Plot 块,则在流式更新时创建一个新的图表块
|
|
264
264
|
* @param messageId 消息 ID
|
|
265
265
|
* @param chartData 最新的图表数据 Schema
|
|
266
|
-
* @param consumeTime
|
|
266
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
267
267
|
*/
|
|
268
268
|
protected updateJson2PlotBlock(messageId: string, chartData: ChartDataSchema, consumeTime?: number): void;
|
|
269
|
+
/**
|
|
270
|
+
* 添加 WebProcessor 页面预览类型的消息块
|
|
271
|
+
*/
|
|
272
|
+
protected appendWebProcessorBlock(messageId: string, data: WebProcessorDataSchema, consumeTime?: number): void;
|
|
273
|
+
/**
|
|
274
|
+
* 更新指定消息中最后一�?WebProcessor �?
|
|
275
|
+
*/
|
|
276
|
+
protected updateWebProcessorBlock(messageId: string, data: WebProcessorDataSchema, consumeTime?: number): void;
|
|
269
277
|
/**
|
|
270
278
|
* 添加 AfSailor 工具类型的消息块
|
|
271
|
-
*
|
|
279
|
+
* 该方法由子类调用,用于在消息中添�?AfSailor 查询结果
|
|
272
280
|
* @param messageId 消息 ID
|
|
273
281
|
* @param result AfSailor 的输入和输出结果
|
|
274
|
-
* @param consumeTime
|
|
282
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
275
283
|
*/
|
|
276
284
|
protected appendAfSailorBlock(messageId: string, result: AfSailorResult, consumeTime?: number): void;
|
|
277
285
|
/**
|
|
278
286
|
* 添加 DatasourceFilter 工具类型的消息块
|
|
279
|
-
*
|
|
287
|
+
* 该方法由子类调用,用于在消息中添�?DatasourceFilter 查询结果
|
|
280
288
|
* @param messageId 消息 ID
|
|
281
289
|
* @param result DatasourceFilter 的输入和输出结果
|
|
282
|
-
* @param consumeTime
|
|
290
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
283
291
|
*/
|
|
284
292
|
protected appendDatasourceFilterBlock(messageId: string, result: DatasourceFilterResult, consumeTime?: number): void;
|
|
285
293
|
/**
|
|
286
|
-
*
|
|
287
|
-
*
|
|
294
|
+
* 更新指定消息中最后一�?DatasourceFilter 工具块的内容(用于流式工�?datasource_filter 的组装)
|
|
295
|
+
* 如果不存�?DatasourceFilter 块,则在流式更新时创建一个新的工具块
|
|
288
296
|
* @param messageId 消息 ID
|
|
289
297
|
* @param result 最新的 DatasourceFilterResult
|
|
290
|
-
* @param consumeTime
|
|
298
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
291
299
|
*/
|
|
292
300
|
protected updateDatasourceFilterBlock(messageId: string, result: DatasourceFilterResult, consumeTime?: number): void;
|
|
293
301
|
/**
|
|
294
302
|
* 添加 DatasourceRerank 工具类型的消息块
|
|
295
|
-
*
|
|
303
|
+
* 该方法由子类调用,用于在消息中添�?DatasourceRerank 查询结果,与 datasource_filter 处理方式一�?
|
|
296
304
|
* @param messageId 消息 ID
|
|
297
305
|
* @param result DatasourceRerank 的输入和输出结果
|
|
298
|
-
* @param consumeTime
|
|
306
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
299
307
|
*/
|
|
300
308
|
protected appendDatasourceRerankBlock(messageId: string, result: DatasourceRerankResult, consumeTime?: number): void;
|
|
301
309
|
/**
|
|
302
|
-
*
|
|
303
|
-
*
|
|
310
|
+
* 更新指定消息中最后一�?DatasourceRerank 工具块的内容(用于流式工�?datasource_rerank 的组装)
|
|
311
|
+
* 如果不存�?DatasourceRerank 块,则在流式更新时创建一个新的工具块
|
|
304
312
|
* @param messageId 消息 ID
|
|
305
313
|
* @param result 最新的 DatasourceRerankResult
|
|
306
|
-
* @param consumeTime
|
|
314
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
307
315
|
*/
|
|
308
316
|
protected updateDatasourceRerankBlock(messageId: string, result: DatasourceRerankResult, consumeTime?: number): void;
|
|
309
317
|
/**
|
|
310
318
|
* 添加默认工具类型的消息块
|
|
311
319
|
* 用于那些没有单独渲染逻辑的通用工具
|
|
312
320
|
* @param messageId 消息 ID
|
|
313
|
-
* @param toolName 工具名称(skill_name
|
|
314
|
-
* @param result
|
|
315
|
-
* @param consumeTime
|
|
321
|
+
* @param toolName 工具名称(skill_name�?
|
|
322
|
+
* @param result 默认工具的输入输出结�?
|
|
323
|
+
* @param consumeTime 耗时(毫秒),可�?
|
|
316
324
|
*/
|
|
317
325
|
protected appendDefaultToolBlock(messageId: string, toolName: string, result: DefaultToolResult, consumeTime?: number): void;
|
|
318
326
|
/**
|
|
319
|
-
*
|
|
320
|
-
* 用于在流式过程中或流结束时写入相关问题、耗时、Token
|
|
327
|
+
* 更新指定消息�?messageContext(合并更新)
|
|
328
|
+
* 用于在流式过程中或流结束时写入相关问题、耗时、Token 等辅助信�?
|
|
321
329
|
*/
|
|
322
330
|
protected updateMessageContext(messageId: string, patch: Partial<MessageContext>): void;
|
|
323
331
|
/**
|
|
324
|
-
*
|
|
332
|
+
* 流式期间将状态更新入队,�?handleStreamResponse �?chunk 结束时统一 flush,避免同一 chunk 内多行事件导致多�?setState 触发 Maximum update depth exceeded
|
|
325
333
|
*/
|
|
326
334
|
protected applyStreamingUpdate(updater: (prev: ChatKitBaseState) => Partial<ChatKitBaseState>): void;
|
|
327
335
|
/**
|
|
328
|
-
*
|
|
336
|
+
* 将当前批内的所有流式更新合并为一�?setState 执行
|
|
329
337
|
*/
|
|
330
338
|
protected flushStreamingUpdates(): void;
|
|
331
339
|
/**
|
|
332
|
-
*
|
|
340
|
+
* 更新指定工具名称对应的最后一个工具块的结果(用于流式工具�?contextloader_data_enhanced 的组装)
|
|
333
341
|
* @param messageId 消息 ID
|
|
334
342
|
* @param toolName 工具名称
|
|
335
343
|
* @param result 更新后的默认工具结果
|
|
@@ -337,7 +345,7 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
337
345
|
protected updateDefaultToolBlockResult(messageId: string, toolName: string, result: DefaultToolResult): void;
|
|
338
346
|
/**
|
|
339
347
|
* 创建新的会话
|
|
340
|
-
* 内部会调用子类实现的 generateConversation()
|
|
348
|
+
* 内部会调用子类实现的 generateConversation() �?getOnboardingInfo() 方法
|
|
341
349
|
*/
|
|
342
350
|
createConversation: () => Promise<void>;
|
|
343
351
|
/**
|
|
@@ -347,38 +355,38 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
347
355
|
*/
|
|
348
356
|
loadConversation: (conversationId: string) => Promise<void>;
|
|
349
357
|
/**
|
|
350
|
-
*
|
|
358
|
+
* 清除会话中的对话消息及会�?ID
|
|
351
359
|
*/
|
|
352
360
|
private clearConversation;
|
|
353
361
|
/**
|
|
354
362
|
* 发送消息的核心方法
|
|
355
363
|
* 该方法是暴露给集成方进行调用的接口,内部会调用子类实现的 sendMessage() 方法
|
|
356
|
-
* @param text
|
|
357
|
-
* @param ctx
|
|
364
|
+
* @param text 用户输入的文�?
|
|
365
|
+
* @param ctx 应用上下�?
|
|
358
366
|
* @param conversationID 发送的对话消息所属的会话 ID(可选)
|
|
359
367
|
* @returns 返回发送的消息结构
|
|
360
368
|
*/
|
|
361
369
|
send: (text: string, ctx?: ApplicationContext, conversationID?: string, regenerateMessageId?: string) => Promise<ChatMessage>;
|
|
362
370
|
/**
|
|
363
371
|
* 处理流式响应
|
|
364
|
-
* 在闭包中处理 EventStream
|
|
372
|
+
* 在闭包中处理 EventStream,并在处理完成后丢弃闭�?
|
|
365
373
|
* @param reader ReadableStreamDefaultReader
|
|
366
374
|
* @param assistantMessageId 助手消息 ID
|
|
367
375
|
*/
|
|
368
376
|
protected handleStreamResponse<T = any>(reader: ReadableStreamDefaultReader<Uint8Array>, assistantMessageId: string): Promise<T>;
|
|
369
377
|
/**
|
|
370
|
-
* 执行 API 调用,并在需要时自动刷新 token
|
|
378
|
+
* 执行 API 调用,并在需要时自动刷新 token 并重试一�?
|
|
371
379
|
* @param apiCall API 调用函数
|
|
372
380
|
* @returns API 调用结果
|
|
373
381
|
*/
|
|
374
382
|
protected executeWithTokenRefresh<T>(apiCall: () => Promise<T>): Promise<T>;
|
|
375
383
|
/**
|
|
376
|
-
*
|
|
384
|
+
* 处理发送按钮点�?
|
|
377
385
|
*/
|
|
378
386
|
protected handleSend: () => Promise<void>;
|
|
379
387
|
/**
|
|
380
388
|
* 处理停止流式响应
|
|
381
|
-
*
|
|
389
|
+
* 调用子类实现�?terminateConversation 方法终止当前会话
|
|
382
390
|
*/
|
|
383
391
|
protected handleStop: () => Promise<void>;
|
|
384
392
|
/**
|
|
@@ -392,7 +400,7 @@ export declare abstract class ChatKitBase<P extends ChatKitBaseProps = ChatKitBa
|
|
|
392
400
|
/**
|
|
393
401
|
* 渲染组件 (抽象方法,由子类实现)
|
|
394
402
|
* 子类需要实现该方法以渲染不同的界面
|
|
395
|
-
* CopilotBase
|
|
403
|
+
* CopilotBase �?AssistantBase 会分别实现各自的渲染逻辑
|
|
396
404
|
*/
|
|
397
405
|
abstract render(): React.ReactNode;
|
|
398
406
|
}
|
|
@@ -8,5 +8,6 @@ export { default as WebSearchBlock } from './WebSearchBlock';
|
|
|
8
8
|
export { default as ToolBlock } from './ToolBlock';
|
|
9
9
|
export { default as ToolDrawer } from './ToolDrawer';
|
|
10
10
|
export { default as Json2PlotBlock } from './Json2PlotBlock';
|
|
11
|
+
export { default as WebProcessorBlock } from '../../shared/blocks/WebProcessorBlock';
|
|
11
12
|
export { CodeViewTool } from './CodeViewTool';
|
|
12
13
|
export type { CodeViewToolProps } from './CodeViewTool';
|
|
@@ -7,3 +7,4 @@ export { default as MarkdownBlock } from './MarkdownBlock';
|
|
|
7
7
|
export { default as WebSearchBlock } from './WebSearchBlock';
|
|
8
8
|
export { default as ToolBlock } from './ToolBlock';
|
|
9
9
|
export { default as ToolDrawer } from './ToolDrawer';
|
|
10
|
+
export { default as WebProcessorBlock } from '../../shared/blocks/WebProcessorBlock';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WebProcessorDataSchema } from '../../../../../types';
|
|
3
|
+
export interface WebProcessorContentViewProps {
|
|
4
|
+
data: WebProcessorDataSchema;
|
|
5
|
+
onZoom: () => void;
|
|
6
|
+
onOpenNewWindow: () => void;
|
|
7
|
+
}
|
|
8
|
+
declare const WebProcessorContentView: React.FC<WebProcessorContentViewProps>;
|
|
9
|
+
export default WebProcessorContentView;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WebProcessorDataSchema } from '../../../../../types';
|
|
3
|
+
export interface WebProcessorIframeProps {
|
|
4
|
+
data: WebProcessorDataSchema;
|
|
5
|
+
mode?: 'chat' | 'modal';
|
|
6
|
+
}
|
|
7
|
+
declare const WebProcessorIframe: React.FC<WebProcessorIframeProps>;
|
|
8
|
+
export default WebProcessorIframe;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WebProcessorDataSchema } from '../../../../../types';
|
|
3
|
+
export interface WebProcessorModalProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
data: WebProcessorDataSchema;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
onOpenNewWindow: () => void;
|
|
8
|
+
}
|
|
9
|
+
declare const WebProcessorModal: React.FC<WebProcessorModalProps>;
|
|
10
|
+
export default WebProcessorModal;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { default } from '../WebProcessorBlock';
|
|
2
|
+
export type { WebProcessorBlockProps } from '../WebProcessorBlock';
|
|
3
|
+
export { default as WebProcessorContentView } from './WebProcessorContentView';
|
|
4
|
+
export type { WebProcessorContentViewProps } from './WebProcessorContentView';
|
|
5
|
+
export { default as WebProcessorModal } from './WebProcessorModal';
|
|
6
|
+
export type { WebProcessorModalProps } from './WebProcessorModal';
|
|
7
|
+
export { default as WebProcessorIframe } from './WebProcessorIframe';
|
|
8
|
+
export type { WebProcessorIframeProps } from './WebProcessorIframe';
|
|
9
|
+
export { buildEmbedUrl, getSafeWebProcessorUrl } from './utils';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { WebProcessorDataSchema } from '../../../../../types';
|
|
2
|
+
export declare function getSafeWebProcessorUrl(url?: string): URL | null;
|
|
3
|
+
export declare function buildEmbedUrl(url?: string): string | null;
|
|
4
|
+
export declare function getWebProcessorTitle(data: WebProcessorDataSchema): string;
|
|
5
|
+
export declare function getWebProcessorDisplayUrl(url?: string): string;
|
|
6
|
+
export declare function getWebProcessorHeight(data: WebProcessorDataSchema, mode: 'chat' | 'modal'): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { WebProcessorBlock as WebProcessorBlockType } from '../../../../types';
|
|
3
|
+
export interface WebProcessorBlockProps {
|
|
4
|
+
block: WebProcessorBlockType;
|
|
5
|
+
}
|
|
6
|
+
declare const WebProcessorBlock: React.FC<WebProcessorBlockProps>;
|
|
7
|
+
export default WebProcessorBlock;
|