1- import { type Dict } from '@/api/type/common'
2- import { type Ref } from 'vue'
1+ import { type Dict } from '@/api/type/common'
2+ import { type Ref } from 'vue'
33import bus from '@/bus'
4+
45interface ApplicationFormType {
56 name ?: string
67 desc ?: string
@@ -35,6 +36,7 @@ interface ApplicationFormType {
3536 tool_ids ?: string [ ]
3637 mcp_output_enable ?: boolean
3738}
39+
3840interface Chunk {
3941 real_node_id : string
4042 chat_id : string
@@ -50,6 +52,7 @@ interface Chunk {
5052 runtime_node_id : string
5153 child_node : any
5254}
55+
5356interface chatType {
5457 id : string
5558 problem_text : string
@@ -82,6 +85,7 @@ interface chatType {
8285 document_list : Array < any >
8386 image_list : Array < any >
8487 audio_list : Array < any >
88+ video_list : Array < any >
8589 other_list : Array < any >
8690 }
8791}
@@ -95,13 +99,15 @@ interface Node {
9599 index : number
96100 is_end : boolean
97101}
102+
98103interface WriteNodeInfo {
99104 current_node : any
100105 answer_text_list_index : number
101106 current_up_node ?: any
102107 divider_content ?: Array < string >
103108 divider_reasoning_content ?: Array < string >
104109}
110+
105111export class ChatRecordManage {
106112 id ?: any
107113 ms : number
@@ -112,6 +118,7 @@ export class ChatRecordManage {
112118 loading ?: Ref < boolean >
113119 node_list : Array < any >
114120 write_node_info ?: WriteNodeInfo
121+
115122 constructor ( chat : chatType , ms ?: number , loading ?: Ref < boolean > ) {
116123 this . ms = ms ? ms : 10
117124 this . chat = chat
@@ -121,6 +128,7 @@ export class ChatRecordManage {
121128 this . write_ed = false
122129 this . node_list = [ ]
123130 }
131+
124132 append_answer (
125133 chunk_answer : string ,
126134 reasoning_content : string ,
@@ -157,8 +165,9 @@ export class ChatRecordManage {
157165 }
158166 }
159167 this . chat . answer_text = this . chat . answer_text + chunk_answer
160- bus . emit ( 'change:answer' , { record_id : this . chat . record_id , is_end : false } )
168+ bus . emit ( 'change:answer' , { record_id : this . chat . record_id , is_end : false } )
161169 }
170+
162171 get_current_up_node ( run_node : any ) {
163172 const index = this . node_list . findIndex ( ( item ) => item == run_node )
164173 if ( index > 0 ) {
@@ -167,6 +176,7 @@ export class ChatRecordManage {
167176 }
168177 return undefined
169178 }
179+
170180 get_run_node ( ) {
171181 if (
172182 this . write_node_info &&
@@ -225,6 +235,7 @@ export class ChatRecordManage {
225235 }
226236 return undefined
227237 }
238+
228239 findIndex < T > ( array : Array < T > , find : ( item : T ) => boolean , type : 'last' | 'index' ) {
229240 let set_index = - 1
230241 for ( let index = 0 ; index < array . length ; index ++ ) {
@@ -238,13 +249,14 @@ export class ChatRecordManage {
238249 }
239250 return set_index
240251 }
252+
241253 closeInterval ( ) {
242254 this . chat . write_ed = true
243255 this . write_ed = true
244256 if ( this . loading ) {
245257 this . loading . value = false
246258 }
247- bus . emit ( 'change:answer' , { record_id : this . chat . record_id , is_end : true } )
259+ bus . emit ( 'change:answer' , { record_id : this . chat . record_id , is_end : true } )
248260 if ( this . id ) {
249261 clearInterval ( this . id )
250262 }
@@ -257,6 +269,7 @@ export class ChatRecordManage {
257269 this . chat . answer_text_list . splice ( last_index , 1 )
258270 }
259271 }
272+
260273 write ( ) {
261274 this . chat . is_stop = false
262275 this . is_stop = false
@@ -277,21 +290,21 @@ export class ChatRecordManage {
277290 }
278291 return
279292 }
280- const { current_node, answer_text_list_index } = node_info
293+ const { current_node, answer_text_list_index} = node_info
281294
282295 if ( current_node . buffer . length > 20 ) {
283296 const context = current_node . is_end
284297 ? current_node . buffer . splice ( 0 )
285298 : current_node . buffer . splice (
286- 0 ,
287- current_node . is_end ? undefined : current_node . buffer . length - 20 ,
288- )
299+ 0 ,
300+ current_node . is_end ? undefined : current_node . buffer . length - 20 ,
301+ )
289302 const reasoning_content = current_node . is_end
290303 ? current_node . reasoning_content_buffer . splice ( 0 )
291304 : current_node . reasoning_content_buffer . splice (
292- 0 ,
293- current_node . is_end ? undefined : current_node . reasoning_content_buffer . length - 20 ,
294- )
305+ 0 ,
306+ current_node . is_end ? undefined : current_node . reasoning_content_buffer . length - 20 ,
307+ )
295308 this . append_answer (
296309 context . join ( '' ) ,
297310 reasoning_content . join ( '' ) ,
@@ -354,6 +367,7 @@ export class ChatRecordManage {
354367 }
355368 } , this . ms )
356369 }
370+
357371 stop ( ) {
358372 clearInterval ( this . id )
359373 this . is_stop = true
@@ -362,13 +376,16 @@ export class ChatRecordManage {
362376 this . loading . value = false
363377 }
364378 }
379+
365380 close ( ) {
366381 this . is_close = true
367382 }
383+
368384 open ( ) {
369385 this . is_close = false
370386 this . is_stop = false
371387 }
388+
372389 appendChunk ( chunk : Chunk ) {
373390 let n = this . node_list . find ( ( item ) => item . real_node_id == chunk . real_node_id )
374391 if ( n ) {
@@ -401,6 +418,7 @@ export class ChatRecordManage {
401418 n [ 'is_end' ] = true
402419 }
403420 }
421+
404422 append ( answer_text_block : string , reasoning_content ?: string ) {
405423 let set_index = this . findIndex (
406424 this . chat . answer_text_list ,
@@ -425,24 +443,28 @@ export class ChatManagement {
425443 static addChatRecord ( chat : chatType , ms : number , loading ?: Ref < boolean > ) {
426444 this . chatMessageContainer [ chat . id ] = new ChatRecordManage ( chat , ms , loading )
427445 }
446+
428447 static appendChunk ( chatRecordId : string , chunk : Chunk ) {
429448 const chatRecord = this . chatMessageContainer [ chatRecordId ]
430449 if ( chatRecord ) {
431450 chatRecord . appendChunk ( chunk )
432451 }
433452 }
453+
434454 static append ( chatRecordId : string , content : string , reasoning_content ?: string ) {
435455 const chatRecord = this . chatMessageContainer [ chatRecordId ]
436456 if ( chatRecord ) {
437457 chatRecord . append ( content , reasoning_content )
438458 }
439459 }
460+
440461 static updateStatus ( chatRecordId : string , code : number ) {
441462 const chatRecord = this . chatMessageContainer [ chatRecordId ]
442463 if ( chatRecord ) {
443464 chatRecord . chat . status = code
444465 }
445466 }
467+
446468 /**
447469 * 持续从缓存区 写出数据
448470 * @param chatRecordId 对话记录id
@@ -453,12 +475,14 @@ export class ChatManagement {
453475 chatRecord . write ( )
454476 }
455477 }
478+
456479 static open ( chatRecordId : string ) {
457480 const chatRecord = this . chatMessageContainer [ chatRecordId ]
458481 if ( chatRecord ) {
459482 chatRecord . open ( )
460483 }
461484 }
485+
462486 /**
463487 * 等待所有数据输出完毕后 才会关闭流
464488 * @param chatRecordId 对话记录id
@@ -470,6 +494,7 @@ export class ChatManagement {
470494 chatRecord . close ( )
471495 }
472496 }
497+
473498 /**
474499 * 停止输出 立即关闭定时任务输出
475500 * @param chatRecordId 对话记录id
@@ -481,6 +506,7 @@ export class ChatManagement {
481506 chatRecord . stop ( )
482507 }
483508 }
509+
484510 /**
485511 * 判断是否输出完成
486512 * @param chatRecordId 对话记录id
@@ -490,6 +516,7 @@ export class ChatManagement {
490516 const chatRecord = this . chatMessageContainer [ chatRecordId ]
491517 return chatRecord ? chatRecord . is_close && chatRecord . write_ed : false
492518 }
519+
493520 /**
494521 * 判断是否停止输出
495522 * @param chatRecordId 对话记录id
@@ -499,6 +526,7 @@ export class ChatManagement {
499526 const chatRecord = this . chatMessageContainer [ chatRecordId ]
500527 return chatRecord ? chatRecord . is_stop : false
501528 }
529+
502530 /**
503531 * 清除无用数据 也就是被close掉的和stop的数据
504532 */
@@ -510,4 +538,5 @@ export class ChatManagement {
510538 }
511539 }
512540}
513- export type { ApplicationFormType , chatType }
541+
542+ export type { ApplicationFormType , chatType }
0 commit comments