fix: prevent duplicate brief submissions, add completion logging
All checks were successful
Build & Push / build-and-push (push) Successful in 1m43s
All checks were successful
Build & Push / build-and-push (push) Successful in 1m43s
- briefSubmittedRef prevents multiple complete_brief calls - Added logging throughout completion flow for debugging - Reset ref on new conversation start Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -133,6 +133,7 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
|
|||||||
const [completedFormData, setCompletedFormData] = useState<WizardFormData | null>(null);
|
const [completedFormData, setCompletedFormData] = useState<WizardFormData | null>(null);
|
||||||
|
|
||||||
const turnCompleteRef = useRef(true);
|
const turnCompleteRef = useRef(true);
|
||||||
|
const briefSubmittedRef = useRef(false);
|
||||||
const wsRef = useRef<WebSocket | null>(null);
|
const wsRef = useRef<WebSocket | null>(null);
|
||||||
const mediaStreamRef = useRef<MediaStream | null>(null);
|
const mediaStreamRef = useRef<MediaStream | null>(null);
|
||||||
const audioContextRef = useRef<AudioContext | null>(null);
|
const audioContextRef = useRef<AudioContext | null>(null);
|
||||||
@@ -191,6 +192,10 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (name === 'complete_brief') {
|
if (name === 'complete_brief') {
|
||||||
|
// Prevent duplicate submissions
|
||||||
|
if (briefSubmittedRef.current) return JSON.stringify({ success: true, message: 'Brief already submitted' });
|
||||||
|
briefSubmittedRef.current = true;
|
||||||
|
console.log('[VoiceAgent] complete_brief called, generating...');
|
||||||
try {
|
try {
|
||||||
const formData = { ...DEFAULT_FORM_DATA, ...(args as Partial<WizardFormData>), locale };
|
const formData = { ...DEFAULT_FORM_DATA, ...(args as Partial<WizardFormData>), locale };
|
||||||
const res = await fetch('/api/configure', {
|
const res = await fetch('/api/configure', {
|
||||||
@@ -199,12 +204,16 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
|
|||||||
body: JSON.stringify(formData),
|
body: JSON.stringify(formData),
|
||||||
});
|
});
|
||||||
const data = (await res.json()) as { success: boolean; brief?: string };
|
const data = (await res.json()) as { success: boolean; brief?: string };
|
||||||
|
console.log('[VoiceAgent] Brief API response:', data.success);
|
||||||
if (data.success && data.brief) {
|
if (data.success && data.brief) {
|
||||||
setCompletedBrief(data.brief);
|
setCompletedBrief(data.brief);
|
||||||
setCompletedFormData(formData as WizardFormData);
|
setCompletedFormData(formData as WizardFormData);
|
||||||
|
console.log('[VoiceAgent] completedBrief and completedFormData set');
|
||||||
}
|
}
|
||||||
return JSON.stringify(data);
|
return JSON.stringify({ success: true });
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
console.error('[VoiceAgent] Brief generation failed:', err);
|
||||||
|
briefSubmittedRef.current = false;
|
||||||
return JSON.stringify({ success: false, error: 'Brief generation failed' });
|
return JSON.stringify({ success: false, error: 'Brief generation failed' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,6 +250,7 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
|
|||||||
setSelections({});
|
setSelections({});
|
||||||
setCompletedBrief(null);
|
setCompletedBrief(null);
|
||||||
setCompletedFormData(null);
|
setCompletedFormData(null);
|
||||||
|
briefSubmittedRef.current = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tokenRes = await fetch('/api/gemini-token', {
|
const tokenRes = await fetch('/api/gemini-token', {
|
||||||
|
|||||||
Reference in New Issue
Block a user