forked from 77media/video-flow
修复chatbox 轮询最新消息
This commit is contained in:
parent
628ff70a0c
commit
c49b17418f
@ -204,7 +204,9 @@ const MOCK_MESSAGES: RealApiMessage[] = [
|
|||||||
created_at: '2024-03-20T10:10:00Z',
|
created_at: '2024-03-20T10:10:00Z',
|
||||||
function_name: 'generate_video',
|
function_name: 'generate_video',
|
||||||
custom_data: {
|
custom_data: {
|
||||||
|
prompt_json: {
|
||||||
core_atmosphere: '欢欣、胜利',
|
core_atmosphere: '欢欣、胜利',
|
||||||
|
},
|
||||||
urls: ['https://cdn.qikongjian.com/faces/1755798635_facefusion_output_1755798635.mp4'],
|
urls: ['https://cdn.qikongjian.com/faces/1755798635_facefusion_output_1755798635.mp4'],
|
||||||
completed_count: 1,
|
completed_count: 1,
|
||||||
total_count: 1
|
total_count: 1
|
||||||
@ -266,7 +268,7 @@ function isShotSketchGeneration(data: any): data is ShotSketchGeneration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isShotVideoGeneration(data: any): data is ShotVideoGeneration {
|
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)) {
|
if (isShotVideoGeneration(customData)) {
|
||||||
blocks = [{
|
blocks = [{
|
||||||
type: 'text',
|
type: 'text',
|
||||||
text: `🎬 分镜视频生成 \n核心氛围:${customData.core_atmosphere}`
|
text: `🎬 分镜视频生成 \n核心氛围:${customData.prompt_json.core_atmosphere}`
|
||||||
}, {
|
}, {
|
||||||
type: 'video',
|
type: 'video',
|
||||||
url: customData.urls[0] || ''
|
url: customData.urls[0] || ''
|
||||||
@ -414,6 +416,8 @@ function transformMessage(apiMessage: RealApiMessage): ChatMessage {
|
|||||||
} else if (role === 'system' && function_name && custom_data) {
|
} else if (role === 'system' && function_name && custom_data) {
|
||||||
// 处理系统消息
|
// 处理系统消息
|
||||||
message.blocks = transformSystemMessage(function_name, content, custom_data);
|
message.blocks = transformSystemMessage(function_name, content, custom_data);
|
||||||
|
} else {
|
||||||
|
message.blocks.push({ type: "text", text: content });
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果没有有效的 blocks,至少添加一个文本块
|
// 如果没有有效的 blocks,至少添加一个文本块
|
||||||
@ -470,13 +474,13 @@ export async function fetchMessages(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 转换消息并按时间排序
|
// 转换消息并按时间排序
|
||||||
if (response.data.messages.length === 0) {
|
// if (response.data.messages.length === 0) {
|
||||||
return {
|
// return {
|
||||||
messages: MOCK_MESSAGES.map(transformMessage),
|
// messages: MOCK_MESSAGES.map(transformMessage),
|
||||||
hasMore: false,
|
// hasMore: false,
|
||||||
totalCount: 0
|
// totalCount: 0
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
return {
|
return {
|
||||||
messages: response.data.messages
|
messages: response.data.messages
|
||||||
.map(transformMessage)
|
.map(transformMessage)
|
||||||
|
|||||||
@ -114,7 +114,9 @@ export interface ShotSketchGeneration {
|
|||||||
}
|
}
|
||||||
// 分镜视频生成
|
// 分镜视频生成
|
||||||
export interface ShotVideoGeneration {
|
export interface ShotVideoGeneration {
|
||||||
|
prompt_json: {
|
||||||
core_atmosphere: string; // 核心氛围
|
core_atmosphere: string; // 核心氛围
|
||||||
|
};
|
||||||
urls: string[]; // 分镜视频
|
urls: string[]; // 分镜视频
|
||||||
completed_count: number; // 生成数量
|
completed_count: number; // 生成数量
|
||||||
total_count: number; // 总数量
|
total_count: number; // 总数量
|
||||||
|
|||||||
@ -139,6 +139,11 @@ export function useMessages({ config, onMessagesUpdate }: UseMessagesProps): [Me
|
|||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
setError(null);
|
setError(null);
|
||||||
|
|
||||||
|
// 暂停轮询
|
||||||
|
if (timeoutIdRef.current) {
|
||||||
|
clearTimeout(timeoutIdRef.current);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 立即添加用户消息(临时显示)
|
// 立即添加用户消息(临时显示)
|
||||||
const userMessage: ChatMessage = {
|
const userMessage: ChatMessage = {
|
||||||
@ -164,6 +169,14 @@ export function useMessages({ config, onMessagesUpdate }: UseMessagesProps): [Me
|
|||||||
setError(err instanceof Error ? err : new Error("发送消息失败"));
|
setError(err instanceof Error ? err : new Error("发送消息失败"));
|
||||||
} finally {
|
} finally {
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
|
|
||||||
|
// 恢复轮询
|
||||||
|
if (systemPush) {
|
||||||
|
timeoutIdRef.current = setTimeout(() => {
|
||||||
|
isPollingRef.current = false;
|
||||||
|
updateMessages(false);
|
||||||
|
}, POLLING_INTERVAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, [updateMessages, mergeMessages]);
|
}, [updateMessages, mergeMessages]);
|
||||||
|
|
||||||
|
|||||||
@ -226,7 +226,7 @@ const WorkFlow = React.memo(function WorkFlow() {
|
|||||||
isSmartChatBoxOpen={isSmartChatBoxOpen}
|
isSmartChatBoxOpen={isSmartChatBoxOpen}
|
||||||
setIsSmartChatBoxOpen={setIsSmartChatBoxOpen}
|
setIsSmartChatBoxOpen={setIsSmartChatBoxOpen}
|
||||||
projectId={episodeId}
|
projectId={episodeId}
|
||||||
userId={userId}
|
userId={51}
|
||||||
/>
|
/>
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user