Fix duplicate message on debug drawer
This commit is contained in:
@@ -1166,6 +1166,7 @@ export const DebugDrawer: React.FC<{
|
|||||||
const handleSend = async () => {
|
const handleSend = async () => {
|
||||||
if (!inputText.trim()) return;
|
if (!inputText.trim()) return;
|
||||||
const userMsg = inputText;
|
const userMsg = inputText;
|
||||||
|
assistantDraftIndexRef.current = null;
|
||||||
setMessages(prev => [...prev, { role: 'user', text: userMsg }]);
|
setMessages(prev => [...prev, { role: 'user', text: userMsg }]);
|
||||||
setInputText('');
|
setInputText('');
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@@ -1189,7 +1190,7 @@ export const DebugDrawer: React.FC<{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchRuntimeMetadata = async (): Promise<Record<string, any>> => {
|
const buildLocalResolvedRuntime = () => {
|
||||||
const warnings: string[] = [];
|
const warnings: string[] = [];
|
||||||
const services: Record<string, any> = {};
|
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));
|
setResolvedConfigView(JSON.stringify(localResolved, null, 2));
|
||||||
return localResolved.sessionStartMetadata;
|
return localResolved.sessionStartMetadata;
|
||||||
};
|
};
|
||||||
@@ -1380,6 +1386,10 @@ export const DebugDrawer: React.FC<{
|
|||||||
setMessages((prev) => {
|
setMessages((prev) => {
|
||||||
const idx = assistantDraftIndexRef.current;
|
const idx = assistantDraftIndexRef.current;
|
||||||
if (idx === null || !prev[idx] || prev[idx].role !== 'model') {
|
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 }];
|
const next = [...prev, { role: 'model' as const, text: delta }];
|
||||||
assistantDraftIndexRef.current = next.length - 1;
|
assistantDraftIndexRef.current = next.length - 1;
|
||||||
return next;
|
return next;
|
||||||
@@ -1401,7 +1411,17 @@ export const DebugDrawer: React.FC<{
|
|||||||
next[idx] = { ...next[idx], text: finalText || next[idx].text };
|
next[idx] = { ...next[idx], text: finalText || next[idx].text };
|
||||||
return next;
|
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);
|
setIsLoading(false);
|
||||||
return;
|
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 = () => (
|
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">
|
<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>}
|
{messages.length === 0 && <div className="text-center text-muted-foreground text-xs py-4">暂无转写记录</div>}
|
||||||
|
|||||||
Reference in New Issue
Block a user