From c498d76a11ec95ed86dfef431182955a08c007c1 Mon Sep 17 00:00:00 2001 From: Jude Kwashie Date: Tue, 4 Nov 2025 15:51:53 +0000 Subject: [PATCH] feat(firebase_ai): add LiveServerGoAway message for session termination --- .../firebase_ai/firebase_ai/lib/src/live_api.dart | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/firebase_ai/firebase_ai/lib/src/live_api.dart b/packages/firebase_ai/firebase_ai/lib/src/live_api.dart index 83c105b708f2..86817d61a593 100644 --- a/packages/firebase_ai/firebase_ai/lib/src/live_api.dart +++ b/packages/firebase_ai/firebase_ai/lib/src/live_api.dart @@ -209,6 +209,15 @@ class LiveServerToolCallCancellation implements LiveServerMessage { final List? functionIds; } +/// A message indicating that the live server is going away. +class LiveServerGoAway implements LiveServerMessage { + /// Creates a [LiveServerGoAway] instance. + const LiveServerGoAway({this.timeLeft}); + + /// The time left in seconds for the live session to be terminated. + final String? timeLeft; +} + /// A single response chunk received during a live content generation. /// /// It can contain generated content, function calls to be executed, or @@ -435,6 +444,9 @@ LiveServerMessage _parseServerMessage(Object jsonObject) { return LiveServerToolCallCancellation(functionIds: toolCancelJson['ids']); } else if (json.containsKey('setupComplete')) { return LiveServerSetupComplete(); + } else if (json.containsKey('goAway')) { + final goAwayJson = json['goAway'] as Map; + return LiveServerGoAway(timeLeft: goAwayJson['timeLeft'] as String?); } else { throw unhandledFormat('LiveServerMessage', json); }