Skip to content

fix(firebase_ai): parse camelCase fileData response parts - #18754

Open
cabljac wants to merge 1 commit into
mainfrom
fix/firebase-ai-filedata-camelcase
Open

cabljac wants to merge 1 commit into
mainfrom
fix/firebase-ai-filedata-camelcase

Conversation

@cabljac

@cabljac cabljac commented Oct 5, 2026

Copy link
Copy Markdown

Description

parsePart in packages/firebase_ai/firebase_ai/lib/src/content.dart matches every part type by its lowerCamelCase JSON key (functionCall, executableCode, codeExecutionResult, inlineData, text) except file data, which it matched only by the snake_case proto names (file_data / file_uri / mime_type). The Gemini API serialises Part.fileData in responses as fileData / fileUri / mimeType, so a file data part in a model response never matched and fell through to UnknownPart. Callers switching on FileData never saw one.

This PR adds the lowerCamelCase form as a second arm of the same switch case, sharing the existing FileData._ construction so thought, thoughtSignature and mediaResolution are carried the same way. The snake_case arm is kept, so anything that previously parsed still does. The change is additive; no existing behaviour is modified.

Tests in test/content_test.dart cover: camelCase fileData parses to FileData with the right fileUri / mimeType; camelCase with thought: true and a thoughtSignature keeps both; camelCase with mediaResolution keeps it. The existing snake_case test is unchanged and still passes. Before the fix the three new tests fail with Actual: <Instance of 'UnknownPart'>.

Follow-up question for maintainers: FileData.toJson() still emits snake_case ('file_data': {'file_uri': ..., 'mime_type': ...}). Requests work because the API accepts both spellings on input, so I left it alone here. Switching it to fileData for consistency with the other parts is a separate decision and I am happy to do it in another PR if wanted.

Verification: flutter test in packages/firebase_ai/firebase_ai passes (355 tests, 9 skipped). dart analyze lib test reports no issues. flutter analyze for the package reports 4 pre-existing errors in example/integration_test/* from the gitignored firebase_options.dart, identical on main. dart format --set-exit-if-changed on the two touched files reports 0 changed. Not run: melos bootstrap or the e2e suite.

Related Issues

Fixes #18753

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

The Gemini API serialises Part.fileData in responses as fileData with
fileUri and mimeType. parsePart matched file data only by the snake_case
proto names (file_data, file_uri, mime_type), so every fileData part in a
model response fell through to UnknownPart. Add the lowerCamelCase form as
a second arm of the same match and keep the snake_case arm.
@gemini-code-assist

Copy link
Copy Markdown
Contributor
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the 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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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.

@cabljac

cabljac commented Oct 5, 2026

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the parsePart function in content.dart to support parsing camelCase fileData (containing fileUri and mimeType) alongside the existing snake_case file_data structure. It also adds comprehensive unit tests in content_test.dart to verify correct parsing of camelCase fileData under various conditions, including with thought signatures and media resolutions. There are no review comments, and I have no additional feedback to provide.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[firebase_ai] parsePart only recognises snake_case file_data; camelCase fileData response parts become UnknownPart

2 participants