fix: correct WebSocket setup format and handle Blob messages
Some checks failed
Build & Push / build-and-push (push) Has been cancelled
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:
@@ -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}`,
|
||||||
responseModalities: config.responseModalities,
|
generationConfig: {
|
||||||
speechConfig: config.speechConfig,
|
responseModalities: config.responseModalities,
|
||||||
|
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
|
||||||
|
|||||||
Reference in New Issue
Block a user