




























@@ -314,6 +314,7 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {
314314private sessionReadyFired = false;
315315private consecutiveSilenceMs = 0;
316316private audioStreamEnded = false;
317+private pendingFunctionNames = new Map<string, string>();
317318318319constructor(private readonly config: GoogleRealtimeVoiceBridgeConfig) {}
319320@@ -323,6 +324,7 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {
323324this.sessionReadyFired = false;
324325this.consecutiveSilenceMs = 0;
325326this.audioStreamEnded = false;
327+this.pendingFunctionNames.clear();
326328327329const ai = createGoogleGenAI({
328330apiKey: this.config.apiKey,
@@ -375,6 +377,7 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {
375377onclose: () => {
376378this.connected = false;
377379this.sessionConfigured = false;
380+this.pendingFunctionNames.clear();
378381const reason = this.intentionallyClosed ? "completed" : "error";
379382this.session = null;
380383this.config.onClose?.(reason);
@@ -449,10 +452,21 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {
449452if (!this.session) {
450453return;
451454}
455+const name = this.pendingFunctionNames.get(callId);
456+if (!name) {
457+this.config.onError?.(
458+new Error(
459+`Google Live function response is missing a matching function call for ${callId}`,
460+),
461+);
462+return;
463+}
464+this.pendingFunctionNames.delete(callId);
452465this.session.sendToolResponse({
453466functionResponses: [
454467{
455468id: callId,
469+ name,
456470response:
457471result && typeof result === "object"
458472 ? (result as Record<string, unknown>)
@@ -471,6 +485,7 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {
471485this.pendingAudio = [];
472486this.consecutiveSilenceMs = 0;
473487this.audioStreamEnded = false;
488+this.pendingFunctionNames.clear();
474489const session = this.session;
475490this.session = null;
476491session?.close();
@@ -557,6 +572,7 @@ class GoogleRealtimeVoiceBridge implements RealtimeVoiceBridge {
557572continue;
558573}
559574const callId = call.id?.trim() || `google-live-${randomUUID()}`;
575+this.pendingFunctionNames.set(callId, name);
560576this.config.onToolCall?.({
561577itemId: callId,
562578 callId,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。