File tree Expand file tree Collapse file tree
packages/firebase_ai/firebase_ai Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -107,6 +107,7 @@ export 'src/live_api.dart'
107107 LiveServerToolCall,
108108 LiveServerToolCallCancellation,
109109 LiveServerResponse,
110+ GoingAwayNotice,
110111 Transcription;
111112export 'src/live_session.dart' show LiveSession;
112113export 'src/schema.dart' show Schema, SchemaType;
Original file line number Diff line number Diff line change @@ -209,6 +209,19 @@ class LiveServerToolCallCancellation implements LiveServerMessage {
209209 final List <String >? functionIds;
210210}
211211
212+ /// A server message indicating that the server will not be able to service the
213+ /// client soon.
214+ class GoingAwayNotice implements LiveServerMessage {
215+ /// Creates a [GoingAwayNotice] instance.
216+ ///
217+ /// [timeLeft] (optional): The remaining time before the connection will be
218+ /// terminated.
219+ const GoingAwayNotice ({this .timeLeft});
220+
221+ /// The remaining time before the connection will be terminated as ABORTED.
222+ final String ? timeLeft;
223+ }
224+
212225/// A single response chunk received during a live content generation.
213226///
214227/// It can contain generated content, function calls to be executed, or
@@ -435,6 +448,9 @@ LiveServerMessage _parseServerMessage(Object jsonObject) {
435448 return LiveServerToolCallCancellation (functionIds: toolCancelJson['ids' ]);
436449 } else if (json.containsKey ('setupComplete' )) {
437450 return LiveServerSetupComplete ();
451+ } else if (json.containsKey ('goAway' )) {
452+ final goAwayJson = json['goAway' ] as Map ;
453+ return GoingAwayNotice (timeLeft: goAwayJson['timeLeft' ] as String ? );
438454 } else {
439455 throw unhandledFormat ('LiveServerMessage' , json);
440456 }
Original file line number Diff line number Diff line change @@ -228,6 +228,16 @@ void main() {
228228 expect (response.message, isA <LiveServerSetupComplete >());
229229 });
230230
231+ test ('parseServerMessage parses goAway message correctly' , () {
232+ final jsonObject = {
233+ 'goAway' : {'timeLeft' : '50s' }
234+ };
235+ final response = parseServerResponse (jsonObject);
236+ expect (response.message, isA <GoingAwayNotice >());
237+ final goAwayMessage = response.message as GoingAwayNotice ;
238+ expect (goAwayMessage.timeLeft, '50s' );
239+ });
240+
231241 test ('parseServerMessage throws VertexAIException for error message' , () {
232242 final jsonObject = {'error' : {}};
233243 expect (() => parseServerResponse (jsonObject),
You can’t perform that action at this time.
0 commit comments