From dc11cd6d77a0bdcfd44d16b69d64278dc00d7703 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Thu, 17 Sep 2026 18:43:57 +0800 Subject: [PATCH] feat: UI Tool Debugging --- .../shared/use-stream-manager.ts | 16 +++---- ui/src/conversation-panel/stream.ts | 45 +++++++++---------- .../workflow/tool/debug/ResultDrawer.vue | 30 ++++++------- 3 files changed, 41 insertions(+), 50 deletions(-) diff --git a/ui/src/conversation-panel/common/use-chat-store/shared/use-stream-manager.ts b/ui/src/conversation-panel/common/use-chat-store/shared/use-stream-manager.ts index f30091754c1..ddb726e6530 100644 --- a/ui/src/conversation-panel/common/use-chat-store/shared/use-stream-manager.ts +++ b/ui/src/conversation-panel/common/use-chat-store/shared/use-stream-manager.ts @@ -43,13 +43,10 @@ export function useStreamManager() { currentStream = new ConversationStream( response, onStream, - () => { - currentStream = null - onFinish?.() - }, (e) => { currentStream = null - onFailure?.(e) + if (e) onFailure?.(e) + else onFinish?.() }, ) currentStream.start() @@ -92,13 +89,10 @@ export function useStreamManager() { currentStream = new ConversationStream( response, onStream, - () => { - currentStream = null - onFinish?.() - }, - () => { + (e) => { currentStream = null - onFailure?.() + if (e) onFailure?.() + else onFinish?.() }, ) currentStream.start() diff --git a/ui/src/conversation-panel/stream.ts b/ui/src/conversation-panel/stream.ts index 09887594f96..a62acb52684 100644 --- a/ui/src/conversation-panel/stream.ts +++ b/ui/src/conversation-panel/stream.ts @@ -1,35 +1,32 @@ export class ConversationStream { private response: any - private onChunk: (chunk: any) => void - private onFinish: () => void - private onError: (e: any) => void + private onNext: (chunk: any) => void + private onComplete: (e?: any) => void private cancelled = false - private finished = false + private completed = false private reader: ReadableStreamDefaultReader | null = null constructor( response: any, - onChunk: (chunk: any) => void, - onFinish: () => void, - onError: (e: any) => void, + onNext: (chunk: any) => void, + onComplete: (e?: any) => void, ) { this.response = response - this.onChunk = onChunk - this.onFinish = onFinish - this.onError = onError + this.onComplete = onComplete + this.onNext = onNext } - private finish() { - if (this.finished || this.cancelled) return - this.finished = true - this.onFinish() + private complete(e?:any) { + if (this.completed || this.cancelled) return + this.completed = true + this.onComplete(e) } async start() { try { this.reader = this.response.body?.getReader() if (!this.reader) { - this.finish() + this.complete() return } @@ -37,7 +34,7 @@ export class ConversationStream { let buffer = '' while (true) { - if (this.cancelled || this.finished) break + if (this.cancelled || this.completed) break const { done, value } = await this.reader.read() @@ -50,7 +47,7 @@ export class ConversationStream { buffer = lines.pop() || '' for (const line of lines) { - if (this.cancelled || this.finished) break + if (this.cancelled || this.completed) break const trimmed = line.trim() if (!trimmed) continue @@ -58,13 +55,13 @@ export class ConversationStream { if (trimmed.startsWith('data:')) { const data = trimmed.slice(5).trim() if (data === '[DONE]') { - this.finish() + this.complete() return } try { const chunk = JSON.parse(data) - this.onChunk(chunk) + this.onNext(chunk) } catch (e) { // Skip invalid JSON } @@ -73,14 +70,14 @@ export class ConversationStream { } // 处理 buffer 中剩余的数据 - if (!this.cancelled && !this.finished && buffer.trim()) { + if (!this.cancelled && !this.completed && buffer.trim()) { const trimmed = buffer.trim() if (trimmed.startsWith('data:')) { const data = trimmed.slice(5).trim() if (data !== '[DONE]') { try { const chunk = JSON.parse(data) - this.onChunk(chunk) + this.onNext(chunk) } catch (e) { // Skip invalid JSON } @@ -89,11 +86,11 @@ export class ConversationStream { } if (!this.cancelled) { - this.finish() + this.complete() } } catch (e) { - if (!this.cancelled && !this.finished) { - this.onError(e) + if (!this.cancelled && !this.completed) { + this.complete(e) } } finally { this.reader = null diff --git a/ui/src/views/workflow/tool/debug/ResultDrawer.vue b/ui/src/views/workflow/tool/debug/ResultDrawer.vue index 338732af0f6..eeac3e7cfc5 100644 --- a/ui/src/views/workflow/tool/debug/ResultDrawer.vue +++ b/ui/src/views/workflow/tool/debug/ResultDrawer.vue @@ -6,7 +6,7 @@ import type { ToolWorkflowRecord } from '@/api/types' import { MsgError } from '@/utils/message' import { ConversationStream } from '@/conversation-panel/stream' import { aggregators } from '@/conversation-panel' -import ContentItem from '@/conversation-panel/content/index.vue' +import ContentList from '@/conversation-panel/content-list/index.vue' import ExecutionDetailContent from '@/workflow-canvas/details/index.vue' import { WorkflowMode } from '@/workflow-canvas/types' @@ -25,6 +25,8 @@ interface ResumeParameters { formData?: Record position?: unknown chunkId?: string + chatRecordId?:string + } const props = defineProps<{ toolId: string }>() const running = defineModel('running', { default: false }) @@ -71,9 +73,9 @@ async function execute(extra: Record = {}) { stream = new ConversationStream( response, receiveChunk, - () => {}, - (error: unknown) => { - streamError = error + (error?: unknown) => { + if (error) streamError = error + running.value = false }, ) await stream.start() @@ -88,16 +90,14 @@ async function execute(extra: Record = {}) { } } finally { stream = undefined - running.value = false + } } // 表单节点沿用同一条执行记录续跑,复用现有回复组件的 sendMessage 协议。 provide('sendMessage', (options: ResumeParameters) => { if (running.value || !visible.value) return - const block = blocks.value.find((entry) => entry.id === options.chunkId) - if (block) Object.assign(block, { is_submit: true, form_data: options.formData }) - return execute({ ...options.formData, position: options.position }) + return execute({ 'form_data':options.formData,'chat_record_id':options.chatRecordId, 'chunk_id':options.chunkId,position: options.position }) }) function open(parameters: Record) { @@ -136,21 +136,21 @@ defineExpose({ open, close })

回复内容

+ + +
回答中...
+
+