From c498d76a11ec95ed86dfef431182955a08c007c1 Mon Sep 17 00:00:00 2001 From: Jude Kwashie Date: Tue, 4 Nov 2025 15:51:53 +0000 Subject: [PATCH 1/3] 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); } From 9cce6cb8bedc5d64b18485ca77b01dbe472ac725 Mon Sep 17 00:00:00 2001 From: Jude Kwashie Date: Tue, 2 Dec 2025 12:10:55 +0000 Subject: [PATCH 2/3] feat(firebase_ai): add test for parsing goAway message in LiveServer response --- packages/firebase_ai/firebase_ai/test/live_test.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/firebase_ai/firebase_ai/test/live_test.dart b/packages/firebase_ai/firebase_ai/test/live_test.dart index ea1ebb382b80..03f440f3aba2 100644 --- a/packages/firebase_ai/firebase_ai/test/live_test.dart +++ b/packages/firebase_ai/firebase_ai/test/live_test.dart @@ -228,6 +228,16 @@ void main() { expect(response.message, isA()); }); + test('parseServerMessage parses goAway message correctly', () { + final jsonObject = { + 'goAway': {'timeLeft': '50s'} + }; + final response = parseServerResponse(jsonObject); + expect(response.message, isA()); + final goAwayMessage = response.message as LiveServerGoAway; + expect(goAwayMessage.timeLeft, '50s'); + }); + test('parseServerMessage throws VertexAIException for error message', () { final jsonObject = {'error': {}}; expect(() => parseServerResponse(jsonObject), From 042d9b1982198e372d585b0b6f65f8a1fa7c6d20 Mon Sep 17 00:00:00 2001 From: Jude Kwashie Date: Fri, 16 Jan 2026 09:25:04 +0000 Subject: [PATCH 3/3] chore: rename LiveServerGoAway to GoingAwayNotice and update related tests --- .../firebase_ai/firebase_ai/lib/firebase_ai.dart | 1 + .../firebase_ai/lib/src/live_api.dart | 16 ++++++++++------ .../firebase_ai/firebase_ai/test/live_test.dart | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/firebase_ai/firebase_ai/lib/firebase_ai.dart b/packages/firebase_ai/firebase_ai/lib/firebase_ai.dart index 4be52604e600..a976658b40cd 100644 --- a/packages/firebase_ai/firebase_ai/lib/firebase_ai.dart +++ b/packages/firebase_ai/firebase_ai/lib/firebase_ai.dart @@ -104,6 +104,7 @@ export 'src/live_api.dart' LiveServerToolCall, LiveServerToolCallCancellation, LiveServerResponse, + GoingAwayNotice, Transcription; export 'src/live_session.dart' show LiveSession; export 'src/schema.dart' show Schema, SchemaType; 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 86817d61a593..9db6bd845476 100644 --- a/packages/firebase_ai/firebase_ai/lib/src/live_api.dart +++ b/packages/firebase_ai/firebase_ai/lib/src/live_api.dart @@ -209,12 +209,16 @@ 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}); +/// A server message indicating that the server will not be able to service the +/// client soon. +class GoingAwayNotice implements LiveServerMessage { + /// Creates a [GoingAwayNotice] instance. + /// + /// [timeLeft] (optional): The remaining time before the connection will be + /// terminated. + const GoingAwayNotice({this.timeLeft}); - /// The time left in seconds for the live session to be terminated. + /// The remaining time before the connection will be terminated as ABORTED. final String? timeLeft; } @@ -446,7 +450,7 @@ LiveServerMessage _parseServerMessage(Object jsonObject) { return LiveServerSetupComplete(); } else if (json.containsKey('goAway')) { final goAwayJson = json['goAway'] as Map; - return LiveServerGoAway(timeLeft: goAwayJson['timeLeft'] as String?); + return GoingAwayNotice(timeLeft: goAwayJson['timeLeft'] as String?); } else { throw unhandledFormat('LiveServerMessage', json); } diff --git a/packages/firebase_ai/firebase_ai/test/live_test.dart b/packages/firebase_ai/firebase_ai/test/live_test.dart index 03f440f3aba2..8eb09d308476 100644 --- a/packages/firebase_ai/firebase_ai/test/live_test.dart +++ b/packages/firebase_ai/firebase_ai/test/live_test.dart @@ -233,8 +233,8 @@ void main() { 'goAway': {'timeLeft': '50s'} }; final response = parseServerResponse(jsonObject); - expect(response.message, isA()); - final goAwayMessage = response.message as LiveServerGoAway; + expect(response.message, isA()); + final goAwayMessage = response.message as GoingAwayNotice; expect(goAwayMessage.timeLeft, '50s'); });