Skip to content

feat(ai): expose recent firebase-js-sdk APIs in react-native-firebase#9028

Open
mikehardy wants to merge 15 commits into
mainfrom
@mikehardy/ai-package-gap-fill-1
Open

feat(ai): expose recent firebase-js-sdk APIs in react-native-firebase#9028
mikehardy wants to merge 15 commits into
mainfrom
@mikehardy/ai-package-gap-fill-1

Conversation

@mikehardy
Copy link
Copy Markdown
Collaborator

Description

This is a "converge towards API parity" PR for the AI package - there have been quite a few API elements added upstream in firebase-js-sdk and this PR should close the gap down a fair bit

Related issues

None logged

Release Summary

A series of feature conventional commits, a semver minor should issue

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
    • Yes
  • My change supports the following platforms;
    • Android
    • iOS
    • Other (macOS, web)
  • My change includes tests;
    • e2e tests added or updated in packages/\*\*/e2e
    • jest tests added or updated in packages/\*\*/__tests__
  • I have updated TypeScript types that are affected by my change.
  • This is a breaking change;
    • Yes
    • No

Test Plan

Mostly compare:types and tests:jest analysis, periodic local runs of tests:macos:test but CI will also confirm


Think react-native-firebase is great? Please consider supporting the project with any of the below:

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves API parity between react-native-firebase and the upstream firebase-js-sdk for the AI package. It introduces support for anyOf schema composition, exposes ThinkingLevel presets for model reasoning, and adds handling for server-side going away notices in live sessions. Additionally, it includes client-side validation for generation configurations to prevent common configuration errors.

Highlights

  • AnyOfSchema Support: Added support for anyOf schema composition, allowing for more flexible data structures in AI model requests.
  • ThinkingLevel Integration: Exposed ThinkingLevel constants and updated ThinkingConfig to allow developers to control model reasoning presets.
  • Live Session Updates: Implemented handling for LiveServerGoingAwayNotice messages, enabling the client to gracefully respond to server-side termination notices.
  • GenerationConfig Validation: Added client-side validation to prevent invalid configurations, specifically ensuring thinkingBudget and thinkingLevel are not set simultaneously.
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.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Comment on lines +115 to +116
export interface ObjectSchemaRequest extends Omit<SchemaRequest, 'type'> {
type: 'object';
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This was a curious one, here's the relevant output while steering an agent:

compare:types rebuilt successfully but found one undocumented shape difference: RN’s new ObjectSchemaRequest.type was emitted as SchemaType.OBJECT while the JS SDK emits the literal 'object'

So we have to use a type of object here if we want 100% fidelity with upstream types (which I believe we do...) but that implies we have to use a more complicated extends type so that we can extend SchemaRequest since that type expects the type to be SchemaType.OBJECT

I think that's okay, but it is worth a callout

Copy link
Copy Markdown
Contributor

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

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 introduces support for anyOf schemas and thinkingLevel configurations within the AI package, aligning the React Native Firebase implementation more closely with the JS SDK. Key changes include the addition of the AnyOfSchema class, the ThinkingLevel enum, and the LiveServerGoingAwayNotice response type for live sessions. The feedback identifies a potential issue where malformed duration strings could result in NaN values and suggests a more robust null check for thinkingLevel during validation to ensure future-proof code.

if (
// != allows for null and undefined. 0 is considered "set" by the model.
generationConfig?.thinkingConfig?.thinkingBudget != null &&
generationConfig.thinkingConfig?.thinkingLevel
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.

low

For consistency with the thinkingBudget check on the previous line and to follow defensive programming practices, it is recommended to use an explicit != null check for thinkingLevel. While the current enum values are truthy strings, this approach is more robust against future changes to the enum or unexpected values.

Suggested change
generationConfig.thinkingConfig?.thinkingLevel
generationConfig.thinkingConfig?.thinkingLevel != null

if (!duration || !duration.endsWith('s')) {
return 0;
}
return Number(duration.slice(0, -1));
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.

low

The Number() function can return NaN if the input string is not a valid number (e.g., if the server sends a malformed duration like "abc s"). It is safer to check for NaN and return a default value of 0 to ensure that timeLeft always contains a valid numeric value.

  const val = Number(duration.slice(0, -1));
  return Number.isNaN(val) ? 0 : val;

@mikehardy
Copy link
Copy Markdown
Collaborator Author

maintainer note: compare-types did not surface the entry points for automatic function calling in the multiple various entry points, though it was detected during agent review - possibly augment compare-types so it surfaces them, red/green test would be to check any change aimed at this at commit point prior to the function-calling PRs after the first one

@russellwheatley
Copy link
Copy Markdown
Member

@mikehardy - presuming one of the the automatic function calling methods is this: 22a741c (this PR)

This isn't surfaced to end consumer (i.e. it's for internal use) so I think this is why it didn't surface in compare scripts?

Copy link
Copy Markdown
Member

@russellwheatley russellwheatley left a comment

Choose a reason for hiding this comment

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

Approved - I'll leave it to your discretion if you want to address the gemini feedback 👍

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants