Fix duplicate message on debug drawer
This commit is contained in:
@@ -1166,6 +1166,7 @@ export const DebugDrawer: React.FC<{
|
||||
const handleSend = async () => {
|
||||
if (!inputText.trim()) return;
|
||||
const userMsg = inputText;
|
||||
assistantDraftIndexRef.current = null;
|
||||
setMessages(prev => [...prev, { role: 'user', text: userMsg }]);
|
||||
setInputText('');
|
||||
setIsLoading(true);
|
||||
@@ -1189,7 +1190,7 @@ export const DebugDrawer: React.FC<{
|
||||
}
|
||||
};
|
||||
|
||||
const fetchRuntimeMetadata = async (): Promise<Record<string, any>> => {
|
||||
const buildLocalResolvedRuntime = () => {
|
||||
const warnings: string[] = [];
|
||||
const services: Record<string, any> = {};
|
||||
|
||||
@@ -1256,6 +1257,11 @@ export const DebugDrawer: React.FC<{
|
||||
},
|
||||
};
|
||||
|
||||
return localResolved;
|
||||
};
|
||||
|
||||
const fetchRuntimeMetadata = async (): Promise<Record<string, any>> => {
|
||||
const localResolved = buildLocalResolvedRuntime();
|
||||
setResolvedConfigView(JSON.stringify(localResolved, null, 2));
|
||||
return localResolved.sessionStartMetadata;
|
||||
};
|
||||
@@ -1380,6 +1386,10 @@ export const DebugDrawer: React.FC<{
|
||||
setMessages((prev) => {
|
||||
const idx = assistantDraftIndexRef.current;
|
||||
if (idx === null || !prev[idx] || prev[idx].role !== 'model') {
|
||||
const last = prev[prev.length - 1];
|
||||
if (last?.role === 'model' && last.text === delta) {
|
||||
return prev;
|
||||
}
|
||||
const next = [...prev, { role: 'model' as const, text: delta }];
|
||||
assistantDraftIndexRef.current = next.length - 1;
|
||||
return next;
|
||||
@@ -1401,7 +1411,17 @@ export const DebugDrawer: React.FC<{
|
||||
next[idx] = { ...next[idx], text: finalText || next[idx].text };
|
||||
return next;
|
||||
}
|
||||
return finalText ? [...prev, { role: 'model', text: finalText }] : prev;
|
||||
if (!finalText) return prev;
|
||||
const last = prev[prev.length - 1];
|
||||
if (last?.role === 'model') {
|
||||
if (last.text === finalText) return prev;
|
||||
if (finalText.startsWith(last.text) || last.text.startsWith(finalText)) {
|
||||
const next = [...prev];
|
||||
next[next.length - 1] = { ...last, text: finalText };
|
||||
return next;
|
||||
}
|
||||
}
|
||||
return [...prev, { role: 'model', text: finalText }];
|
||||
});
|
||||
setIsLoading(false);
|
||||
return;
|
||||
@@ -1436,6 +1456,12 @@ export const DebugDrawer: React.FC<{
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isOpen) return;
|
||||
const localResolved = buildLocalResolvedRuntime();
|
||||
setResolvedConfigView(JSON.stringify(localResolved, null, 2));
|
||||
}, [isOpen, assistant, voices, llmModels, asrModels]);
|
||||
|
||||
const TranscriptionLog = () => (
|
||||
<div ref={scrollRef} className="flex-1 overflow-y-auto space-y-4 p-2 border border-white/5 rounded-md bg-black/20 min-h-0">
|
||||
{messages.length === 0 && <div className="text-center text-muted-foreground text-xs py-4">暂无转写记录</div>}
|
||||
|
||||
Reference in New Issue
Block a user