fix: correct WebSocket setup format and handle Blob messages
Some checks failed
Build & Push / build-and-push (push) Has been cancelled

- Setup uses "generationConfig" field (not "config") inside "setup" object
- Handle Blob data from WebSocket (Gemini sends binary, not text)
- Voice agent now successfully connects and receives setupComplete

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-28 14:27:11 +01:00
parent bbf534cf4f
commit 0a20d1e243

View File

@@ -27,6 +27,7 @@ interface VoiceAgentContextValue {
endConversation: () => void; endConversation: () => void;
completedBrief: string | null; completedBrief: string | null;
completedFormData: WizardFormData | null; completedFormData: WizardFormData | null;
debugLog: string[];
} }
// ─── Context ───────────────────────────────────────────────────────────────── // ─── Context ─────────────────────────────────────────────────────────────────
@@ -289,13 +290,14 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
}, 10_000); }, 10_000);
ws.onopen = () => { ws.onopen = () => {
console.log('[VoiceAgent] WebSocket opened, sending config...'); console.log('[VoiceAgent] WebSocket opened, sending setup...');
// Send setup message — must use "config" key per Gemini Live API spec
ws.send(JSON.stringify({ ws.send(JSON.stringify({
config: { setup: {
model: `models/${model}`, model: `models/${model}`,
generationConfig: {
responseModalities: config.responseModalities, responseModalities: config.responseModalities,
speechConfig: config.speechConfig, speechConfig: config.speechConfig,
},
systemInstruction: { systemInstruction: {
parts: [{ text: config.systemInstruction }], parts: [{ text: config.systemInstruction }],
}, },
@@ -320,7 +322,13 @@ export default function VoiceAgentProvider({ locale, children }: VoiceAgentProvi
}; };
ws.onmessage = async (event) => { ws.onmessage = async (event) => {
const msg = JSON.parse(event.data as string); let raw: string;
if (event.data instanceof Blob) {
raw = await event.data.text();
} else {
raw = event.data as string;
}
const msg = JSON.parse(raw);
console.log('[VoiceAgent] Message:', JSON.stringify(msg).slice(0, 200)); console.log('[VoiceAgent] Message:', JSON.stringify(msg).slice(0, 200));
// Setup complete — Gemini sends back a setupComplete message // Setup complete — Gemini sends back a setupComplete message