yt-chat-components 1.2.9 → 1.3.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/package.json
CHANGED
|
@@ -302,12 +302,13 @@ export default function ChatMessage({
|
|
|
302
302
|
|
|
303
303
|
const renderBotTextMessage = () => {
|
|
304
304
|
const items = messageItemList.map((item, index) => {
|
|
305
|
-
const {id, thinkMessage, message, type, name, toolCallInfo, rawInfo} = item;
|
|
305
|
+
const {id, thinkMessage, message, loadingMessage, type, name, toolCallInfo, rawInfo} = item;
|
|
306
|
+
const isLatest = index == messageItemList.length - 1;
|
|
306
307
|
let status = 'success'
|
|
307
308
|
// 只有在接收信息的时候有 pending 状态
|
|
308
309
|
if (receivingMessage && isLatest){
|
|
309
310
|
// 最后的信息才为 pending
|
|
310
|
-
if(
|
|
311
|
+
if(isLatest){
|
|
311
312
|
status = 'pending'
|
|
312
313
|
}
|
|
313
314
|
}
|
|
@@ -325,7 +326,7 @@ export default function ChatMessage({
|
|
|
325
326
|
size="small"
|
|
326
327
|
defaultActiveKey={'1'}
|
|
327
328
|
expandIconPosition={'end'}
|
|
328
|
-
items={[{key: '1', label: renderThinkTitle(isEmpty(message)), children: <Markdown
|
|
329
|
+
items={[{key: '1', label: renderThinkTitle(isEmpty(message) && isLatest), children: <Markdown
|
|
329
330
|
className={'think markdown-body prose flex flex-col word-break-break-word'}
|
|
330
331
|
remarkPlugins={[remarkGfm]}
|
|
331
332
|
rehypePlugins={[rehypeMathjax]}
|
|
@@ -334,6 +335,7 @@ export default function ChatMessage({
|
|
|
334
335
|
</Markdown>}]}
|
|
335
336
|
/>
|
|
336
337
|
}
|
|
338
|
+
{/* 有 thinkMessage 的时候没有占位符,否则赞为符输出*/}
|
|
337
339
|
{
|
|
338
340
|
message ? <Markdown
|
|
339
341
|
key={id}
|
|
@@ -343,7 +345,7 @@ export default function ChatMessage({
|
|
|
343
345
|
components={CustomRender}
|
|
344
346
|
>
|
|
345
347
|
{message}
|
|
346
|
-
</Markdown> : thinkMessage ? "" : <ChatMessagePlaceholderInThought aiStatus={"正在处理数据"} />
|
|
348
|
+
</Markdown> : thinkMessage ? "" : <ChatMessagePlaceholderInThought aiStatus={loadingMessage ? loadingMessage : "正在处理数据"} />
|
|
347
349
|
}
|
|
348
350
|
</div>,
|
|
349
351
|
footer: <div key={id} className="msg_operateBox">
|
|
@@ -150,6 +150,7 @@ export default function ChatWindow({
|
|
|
150
150
|
const [inputContainerHeight, setInputContainerHeight] = useState('50px')
|
|
151
151
|
let content_id: string = null
|
|
152
152
|
let content_ns: string = null
|
|
153
|
+
let event_latest: string = null
|
|
153
154
|
const nowAIContentListRef = useRef(nowAIContentList)
|
|
154
155
|
|
|
155
156
|
let voiceChunks = []; // 临时存储录制的语音片段
|
|
@@ -176,7 +177,7 @@ export default function ChatWindow({
|
|
|
176
177
|
if (delayMessageList.length > 0) {
|
|
177
178
|
const data = delayMessageList.shift();
|
|
178
179
|
const {r_id, form_config} = data;
|
|
179
|
-
updateMessageItem("\n```form\n" + JSON.stringify(form_config) + "\n```\n")
|
|
180
|
+
updateMessageItem({chunk:"\n```form\n" + JSON.stringify(form_config) + "\n```\n"})
|
|
180
181
|
|
|
181
182
|
// ?????? done
|
|
182
183
|
// addMessage({
|
|
@@ -193,8 +194,8 @@ export default function ChatWindow({
|
|
|
193
194
|
}
|
|
194
195
|
}
|
|
195
196
|
|
|
196
|
-
const addMessageItem = (chunk, id, name, status = null, isThinkChunk = false) => {
|
|
197
|
-
// console.log("--- addMessageItem", chunk, status)
|
|
197
|
+
const addMessageItem = ({chunk, id, name, status = null, isThinkChunk = false, loadingMessage = null}) => {
|
|
198
|
+
// console.log("--- addMessageItem", chunk, status, loadingMessage)
|
|
198
199
|
setNowAIContentList((prevState) => {
|
|
199
200
|
const content = {}
|
|
200
201
|
if(isThinkChunk){
|
|
@@ -210,6 +211,7 @@ export default function ChatWindow({
|
|
|
210
211
|
name,
|
|
211
212
|
type: MessageType.text,
|
|
212
213
|
toolCallInfo: status,
|
|
214
|
+
loadingMessage,
|
|
213
215
|
...content
|
|
214
216
|
}
|
|
215
217
|
nowAIContentListRef.current = [...prevState, messageItem]
|
|
@@ -217,7 +219,7 @@ export default function ChatWindow({
|
|
|
217
219
|
})
|
|
218
220
|
}
|
|
219
221
|
|
|
220
|
-
const updateMessageItem = (chunk, status = null, isThinkChunk = false) => {
|
|
222
|
+
const updateMessageItem = ({chunk, status = null, isThinkChunk = false, loadingMessage = null}) => {
|
|
221
223
|
// console.log("--- updateMessageItem", chunk, status)
|
|
222
224
|
setNowAIContentList((prevState) => {
|
|
223
225
|
const latestMessageItem = prevState[prevState.length - 1]
|
|
@@ -235,6 +237,7 @@ export default function ChatWindow({
|
|
|
235
237
|
name: latestMessageItem.name,
|
|
236
238
|
type: latestMessageItem.type,
|
|
237
239
|
toolCallInfo: status,
|
|
240
|
+
loadingMessage,
|
|
238
241
|
...content
|
|
239
242
|
}
|
|
240
243
|
|
|
@@ -248,13 +251,13 @@ export default function ChatWindow({
|
|
|
248
251
|
|
|
249
252
|
// 流式输出消息,实时显示(token为流式输出内容,end为结束输出,整体输出一次)
|
|
250
253
|
const handleMessageContent = (event, data) => {
|
|
251
|
-
|
|
254
|
+
console.log("--- event, data",event, data)
|
|
252
255
|
|
|
253
256
|
if (event == 'add_message' && data['sender'] == 'Machine') {
|
|
254
257
|
getHistoryList();
|
|
255
258
|
}
|
|
256
|
-
else if (event == 'token') {
|
|
257
|
-
let { chunk, id, r_id, ns, name } = data
|
|
259
|
+
else if (event == 'token' || event == 't_full_token') {
|
|
260
|
+
let { chunk, id, r_id, ns, name, loading_message } = data
|
|
258
261
|
if (chunk.includes('```') && !chunk.startsWith('\n')) {
|
|
259
262
|
// 确保 ``` 前有换行
|
|
260
263
|
chunk = '\n' + chunk;
|
|
@@ -266,14 +269,16 @@ export default function ChatWindow({
|
|
|
266
269
|
// 如果刚才在调用工具,则追加信息
|
|
267
270
|
if (content_id === 'WAIT'){
|
|
268
271
|
content_id = id
|
|
269
|
-
updateMessageItem(chunk)
|
|
272
|
+
updateMessageItem({chunk, loadingMessage: loading_message})
|
|
270
273
|
}
|
|
271
274
|
// 新建信息
|
|
272
275
|
else{
|
|
273
276
|
content_id = id
|
|
274
|
-
addMessageItem(chunk, id, name)
|
|
277
|
+
addMessageItem({chunk, id, name, loadingMessage:loading_message})
|
|
275
278
|
}
|
|
276
|
-
}
|
|
279
|
+
}
|
|
280
|
+
// 输出主体没有变化
|
|
281
|
+
else {
|
|
277
282
|
// 如果 content_id === WAIT 表示 token 发出来之前 agent在调用工具
|
|
278
283
|
// 但是调用工具的时候已经创建了信息,所以这里更新一下 content_id。这样就可以追加信息
|
|
279
284
|
if(content_id === 'WAIT'){
|
|
@@ -283,27 +288,35 @@ export default function ChatWindow({
|
|
|
283
288
|
// id切换表示一句话说完了, 新增信息
|
|
284
289
|
if (content_id !== id){
|
|
285
290
|
content_id = id
|
|
286
|
-
|
|
291
|
+
|
|
292
|
+
// 如果 event_latest 是 token,此刻变成了 t_full_token,表示之前都在输出占位符,所以更新信息
|
|
293
|
+
if (event_latest === 'token' && event === 't_full_token'){
|
|
294
|
+
updateMessageItem({chunk, loadingMessage: loading_message})
|
|
295
|
+
} else {
|
|
296
|
+
addMessageItem({chunk, id, name, loadingMessage:loading_message})
|
|
297
|
+
}
|
|
287
298
|
}else{
|
|
288
|
-
updateMessageItem(chunk)
|
|
299
|
+
updateMessageItem({chunk, loadingMessage: loading_message})
|
|
289
300
|
}
|
|
290
301
|
}
|
|
291
302
|
|
|
292
303
|
if (lastMessage.current) {
|
|
293
304
|
lastMessage.current.scrollIntoView({ behavior: 'smooth' });
|
|
294
305
|
}
|
|
306
|
+
|
|
307
|
+
|
|
295
308
|
}
|
|
296
309
|
else if (event == 't_token') {
|
|
297
|
-
let { chunk, id, r_id, ns, name } = data
|
|
310
|
+
let { chunk, id, r_id, ns, name, loading_message } = data
|
|
298
311
|
|
|
299
312
|
// ns切换表示切换了智能体
|
|
300
313
|
if (content_ns !== ns){
|
|
301
314
|
content_ns = ns
|
|
302
315
|
// 新建信息
|
|
303
316
|
content_id = id
|
|
304
|
-
addMessageItem(chunk, id, name, null, true)
|
|
317
|
+
addMessageItem({chunk, id, name, status:null, isThinkChunk:true, loadingMessage: loading_message})
|
|
305
318
|
}else {
|
|
306
|
-
updateMessageItem(chunk, null, true)
|
|
319
|
+
updateMessageItem({chunk, status:null, isThinkChunk:true, loadingMessage: loading_message})
|
|
307
320
|
}
|
|
308
321
|
|
|
309
322
|
if (lastMessage.current) {
|
|
@@ -319,16 +332,16 @@ export default function ChatWindow({
|
|
|
319
332
|
content_ns = ns
|
|
320
333
|
// 表示智能体连续调用工具
|
|
321
334
|
if (content_id === 'WAIT') {
|
|
322
|
-
updateMessageItem("", status)
|
|
335
|
+
updateMessageItem({chunk:"", status, loadingMessage: loading_message})
|
|
323
336
|
}else{
|
|
324
337
|
// 这个时候还没有信息的id,所以 content_id 给特殊值
|
|
325
338
|
content_id = "WAIT"
|
|
326
|
-
addMessageItem("", "WAIT", name, status)
|
|
339
|
+
addMessageItem({chunk:"", id: "WAIT", name, status})
|
|
327
340
|
}
|
|
328
341
|
}
|
|
329
342
|
// 当前智能体在调用工具
|
|
330
343
|
else{
|
|
331
|
-
updateMessageItem("", status)
|
|
344
|
+
updateMessageItem({chunk:"", status, loadingMessage: loading_message})
|
|
332
345
|
}
|
|
333
346
|
|
|
334
347
|
setAiStatus(data.status)
|
|
@@ -410,6 +423,8 @@ export default function ChatWindow({
|
|
|
410
423
|
content_ns = null
|
|
411
424
|
content_id = null
|
|
412
425
|
}
|
|
426
|
+
|
|
427
|
+
event_latest = event
|
|
413
428
|
};
|
|
414
429
|
|
|
415
430
|
const sendMessageNoStream = (res) => {
|