From c49b17418f262f26ff222a932c7266812a7f7697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8C=97=E6=9E=B3?= <7854742+wang_rumeng@user.noreply.gitee.com> Date: Sun, 24 Aug 2025 15:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dchatbox=20=E8=BD=AE=E8=AF=A2?= =?UTF-8?q?=E6=9C=80=E6=96=B0=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SmartChatBox/api.ts | 24 ++++++++++++++---------- components/SmartChatBox/types.ts | 4 +++- components/SmartChatBox/useMessages.ts | 13 +++++++++++++ components/pages/work-flow.tsx | 2 +- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/components/SmartChatBox/api.ts b/components/SmartChatBox/api.ts index fd08fe4..6653007 100644 --- a/components/SmartChatBox/api.ts +++ b/components/SmartChatBox/api.ts @@ -204,7 +204,9 @@ const MOCK_MESSAGES: RealApiMessage[] = [ created_at: '2024-03-20T10:10:00Z', function_name: 'generate_video', custom_data: { - core_atmosphere: '欢欣、胜利', + prompt_json: { + core_atmosphere: '欢欣、胜利', + }, urls: ['https://cdn.qikongjian.com/faces/1755798635_facefusion_output_1755798635.mp4'], completed_count: 1, total_count: 1 @@ -266,7 +268,7 @@ function isShotSketchGeneration(data: any): data is ShotSketchGeneration { } function isShotVideoGeneration(data: any): data is ShotVideoGeneration { - return data && 'core_atmosphere' in data && 'urls' in data && 'completed_count' in data && 'total_count' in data; + return data && 'prompt_json' in data && 'urls' in data && 'completed_count' in data && 'total_count' in data; } /** @@ -362,7 +364,7 @@ function transformSystemMessage( if (isShotVideoGeneration(customData)) { blocks = [{ type: 'text', - text: `🎬 分镜视频生成 \n核心氛围:${customData.core_atmosphere}` + text: `🎬 分镜视频生成 \n核心氛围:${customData.prompt_json.core_atmosphere}` }, { type: 'video', url: customData.urls[0] || '' @@ -414,6 +416,8 @@ function transformMessage(apiMessage: RealApiMessage): ChatMessage { } else if (role === 'system' && function_name && custom_data) { // 处理系统消息 message.blocks = transformSystemMessage(function_name, content, custom_data); + } else { + message.blocks.push({ type: "text", text: content }); } // 如果没有有效的 blocks,至少添加一个文本块 @@ -470,13 +474,13 @@ export async function fetchMessages( } // 转换消息并按时间排序 - if (response.data.messages.length === 0) { - return { - messages: MOCK_MESSAGES.map(transformMessage), - hasMore: false, - totalCount: 0 - }; - } + // if (response.data.messages.length === 0) { + // return { + // messages: MOCK_MESSAGES.map(transformMessage), + // hasMore: false, + // totalCount: 0 + // }; + // } return { messages: response.data.messages .map(transformMessage) diff --git a/components/SmartChatBox/types.ts b/components/SmartChatBox/types.ts index 70132c3..a71dad0 100644 --- a/components/SmartChatBox/types.ts +++ b/components/SmartChatBox/types.ts @@ -114,7 +114,9 @@ export interface ShotSketchGeneration { } // 分镜视频生成 export interface ShotVideoGeneration { - core_atmosphere: string; // 核心氛围 + prompt_json: { + core_atmosphere: string; // 核心氛围 + }; urls: string[]; // 分镜视频 completed_count: number; // 生成数量 total_count: number; // 总数量 diff --git a/components/SmartChatBox/useMessages.ts b/components/SmartChatBox/useMessages.ts index f0e8afa..50319fd 100644 --- a/components/SmartChatBox/useMessages.ts +++ b/components/SmartChatBox/useMessages.ts @@ -139,6 +139,11 @@ export function useMessages({ config, onMessagesUpdate }: UseMessagesProps): [Me setIsLoading(true); setError(null); + // 暂停轮询 + if (timeoutIdRef.current) { + clearTimeout(timeoutIdRef.current); + } + try { // 立即添加用户消息(临时显示) const userMessage: ChatMessage = { @@ -164,6 +169,14 @@ export function useMessages({ config, onMessagesUpdate }: UseMessagesProps): [Me setError(err instanceof Error ? err : new Error("发送消息失败")); } finally { setIsLoading(false); + + // 恢复轮询 + if (systemPush) { + timeoutIdRef.current = setTimeout(() => { + isPollingRef.current = false; + updateMessages(false); + }, POLLING_INTERVAL); + } } }, [updateMessages, mergeMessages]); diff --git a/components/pages/work-flow.tsx b/components/pages/work-flow.tsx index 8f79222..d47a977 100644 --- a/components/pages/work-flow.tsx +++ b/components/pages/work-flow.tsx @@ -226,7 +226,7 @@ const WorkFlow = React.memo(function WorkFlow() { isSmartChatBoxOpen={isSmartChatBoxOpen} setIsSmartChatBoxOpen={setIsSmartChatBoxOpen} projectId={episodeId} - userId={userId} + userId={51} />