feat(firebaseai): live session resumption#18038
Conversation
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the Gemini Live implementation to support session resumption and context window compression. It introduces a BidiMediaManager and BidiSessionController to better separate hardware management, business logic, and UI concerns. Key feedback includes addressing a potential runtime error on Flutter Web when decoding WebSocket messages, restoring echo cancellation to prevent audio feedback loops, and correcting several JSON keys to use snake_case to align with the Gemini Live API. Additionally, a typo in a tool response key was identified that could prevent correct model interaction.
I am having trouble creating individual review comments. Click here to see my feedback.
packages/firebase_ai/firebase_ai/lib/src/live_session.dart (144)
Calling utf8.decode(message) directly will cause a runtime error on Flutter Web because the message emitted by the WebSocketChannel is already a String on that platform. You should check the type of the message before decoding.
final String jsonString = message is String ? message : utf8.decode(message as List<int>);
packages/firebase_ai/firebase_ai/example/lib/utils/audio_input.dart (113-114)
The removal of echoCancel and noiseSuppress from the RecordConfig is concerning for a bidirectional (Bidi) session. Without echo cancellation, the model's audio output played through the speakers will likely be picked up by the microphone and sent back to the model, creating a feedback loop or causing the model to 'hear' itself.
packages/firebase_ai/firebase_ai/lib/src/live_api.dart (558-561)
The keys used to parse the SessionResumptionUpdate message are in camelCase, but the Gemini Live API typically returns snake_case keys (e.g., new_handle, last_consumed_client_message_index). This will likely result in null values being parsed even when the data is present.
newHandle: sessionResumptionUpdateJson['new_handle'] as String?,
resumable: sessionResumptionUpdateJson['resumable'] as bool?,
lastConsumedClientMessageIndex:
sessionResumptionUpdateJson['last_consumed_client_message_index'] as int?,
packages/firebase_ai/firebase_ai/example/lib/pages/bidi_page.dart (511-512)
The key 'colorTemprature' contains a typo. While the comment mentions preserving the original typo, the tool definition at line 545 uses the correct spelling 'colorTemperature'. To ensure the model correctly interprets the tool response, the key must match the definition exactly.
'colorTemperature': color,
packages/firebase_ai/firebase_ai/lib/src/live_api.dart (94)
The JSON key should use snake_case to align with the Gemini Live API naming conventions.
{if (targetTokens case final targetTokens?) 'target_tokens': targetTokens};
packages/firebase_ai/firebase_ai/lib/src/live_api.dart (117-120)
The JSON keys should use snake_case to align with the Gemini Live API naming conventions.
if (triggerTokens case final triggerTokens?)
'trigger_tokens': triggerTokens,
if (slidingWindow case final slidingWindow?)
'sliding_window': slidingWindow.toJson()
packages/firebase_ai/firebase_ai/lib/src/live_session.dart (126)
The JSON key 'contextWindowCompression' should be 'context_window_compression' to maintain consistency with other snake_case keys in the setup message.
'context_window_compression': contextWindowCompression.toJson()
Description
Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change.
Related Issues
Replace this paragraph with a list of issues related to this PR from the issue database. Indicate, which of these issues are resolved or fixed by this PR. Note that you'll have to prefix the issue numbers with flutter/flutter#.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).This will ensure a smooth and quick review process. Updating the
pubspec.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?