Skip to content

feat(firebase-ai-logic-basics): Web (JavaScript) SDK setup and capability guides - #222

Open
AustinBenoit wants to merge 1 commit into
ai-logic/2c-setup-flutterfrom
ai-logic/2d-setup-web
Open

AustinBenoit wants to merge 1 commit into
ai-logic/2c-setup-flutterfrom
ai-logic/2d-setup-web

Conversation

@AustinBenoit

@AustinBenoit AustinBenoit commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary (PR 5 of 8 — Web / JavaScript SDK Specialist Review)

Consolidates all Web (JavaScript / TypeScript) SDK changes into a single PR for Web JS specialist review:

  • references/sdk/setup/web_setup.md:
    • Updates firebase (^13.0.0 / @firebase/ai 3.0.0), useLimitedUseAppCheckTokens: true, and moves inline capability sections into the dedicated capability guides.
  • ## Web (JavaScript) across all 10 capability guides (references/sdk/capabilities/*.md):
    • text_generation.md, multimodal_input.md (with reader.onerror = reject;), chat.md, streaming.md
    • structured_output.md, function_calling.md, search_grounding.md
    • image_generation.md (with reader.onerror = reject;), on_device_hybrid.md (InferenceMode, initializeDeviceModel, inCloudParams / onDeviceParams)
    • text_to_speech.md (ResponseModality.AUDIO, speechConfig, chunk.inlineDataParts(), Web Audio API AudioContext streaming, and WAV Blob helper)

@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 Firebase AI Logic Web Setup Guide to provide comprehensive instructions on installation, initialization, App Check integration, and various usage patterns. The review feedback highlights three improvement opportunities: guarding initializeAppCheck with a client-side check to prevent errors during server-side rendering (SSR) in Next.js, removing a redundant await from result.response in the text-only generation snippet, and fixing a minor spacing inconsistency in an import statement.

Comment thread skills/firebase-ai-logic-basics/references/sdk/setup/web_setup.md
Comment thread skills/firebase-ai-logic-basics/references/sdk/setup/web_setup.md
Comment thread skills/firebase-ai-logic-basics/references/sdk/setup/web_setup.md Outdated
@AustinBenoit
AustinBenoit added this pull request to stack #223 October 9, 2026 16:53
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch from 14d88ad to c962dbc Compare October 13, 2026 16:37
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch from c962dbc to 8eb6852 Compare October 13, 2026 18:18
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch from 8eb6852 to 717c923 Compare October 13, 2026 20:31
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch from 717c923 to 29efeb6 Compare October 13, 2026 22:28
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch from 29efeb6 to d4cdb70 Compare October 13, 2026 22:33
@AustinBenoit AustinBenoit changed the title feat(firebase-ai-logic-basics): update Web SDK setup and App Check guide feat(firebase-ai-logic-basics): Web (JavaScript) SDK setup and capability guides Oct 13, 2026
@AustinBenoit
AustinBenoit removed this pull request from stack #223 October 13, 2026 22:35
@AustinBenoit
AustinBenoit added this pull request to stack #227 October 13, 2026 22:39
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch from d4cdb70 to 83c07c8 Compare October 13, 2026 23:35
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch from 83c07c8 to 68bb1d8 Compare October 14, 2026 13:19
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch 2 times, most recently from 43b7275 to ca8c0ed Compare October 14, 2026 14:01
@AustinBenoit
AustinBenoit force-pushed the ai-logic/2d-setup-web branch 2 times, most recently from 64ea7d8 to 42b232b Compare October 14, 2026 15:32
@AustinBenoit
AustinBenoit removed this pull request from stack #227 October 14, 2026 15:47
@AustinBenoit
AustinBenoit added this pull request to stack #235 October 14, 2026 15:54
@AustinBenoit

Copy link
Copy Markdown
Contributor 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 adds Web (JavaScript) code examples and documentation for various Firebase AI Logic capabilities, including chat, function calling, image generation, multimodal input, on-device hybrid inference, search grounding, streaming, structured output, and text generation, while updating the setup and text-to-speech guides to reflect the renamed SDK. The review feedback highlights several API mismatches in the proposed examples: the Part object in the JS SDK does not support a top-level type field, the inlineDataParts() helper method is non-existent on response and chunk objects, and Schema is a TypeScript interface rather than a runtime class, requiring schemas to be defined as plain JSON objects instead of using builder methods.

Comment thread skills/firebase-ai-logic-basics/references/sdk/capabilities/chat.md
import { initializeAppCheck, ReCaptchaEnterpriseProvider } from "firebase/app-check";

if (typeof self !== "undefined") {
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I know this PR didn't touch it, but this logic is such that a Vite app can potentially pass this first condition, and not reach the "else if" that's supposed to apply to Vite. Both conditional blocks should probably check for the exact env variable names also.

}
}

const appCheck = initializeAppCheck(app, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This can't be allowed to run in NextJS server rendering as recaptcha won't work there and will error. I'm not sure if the best way is to add additional instructions to the agent to tell it to avoid calling this in server-rendering code and let it handle that itself, or to explicitly add a if (typeof window !== 'undefined') around this ourselves and just force it to never run when window isn't available. Further best practices are to use initializeServerApp when running in the NextJS server environment and to pass it the app check token generated during the client render, but that might be beyond the scope of this.

```JavaScript
async function generateText(prompt) {
const result = await model.generateContent(prompt);
const response = await result.response;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actually gemini-code-assist was right here, we don't need the await. I think it might be wrong in the devsite snippet


Text-Only Generation

```JavaScript

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

does the different casing break this?


## Core Capabilities

Text-Only Generation

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this supposed to be a ### subheading?

const pcmBuffer = Uint8Array.from(atob(pcmBase64), (c) =>
c.charCodeAt(0)
).buffer;
playAudio(pcmBuffer);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So this function doesn't exist. I think it's in the devsite snippet as a "to be implemented by you the developer" placeholder. It looks like there's instructions below in section 3 on how to actually process and play the Uint8Array itself (not the .buffer) so I don't know if there's some way to say "we don't know how to play this yet, wait until section 3"

## Web (JavaScript)

#### 1. Streaming Playback with Web Audio API
### 1. Single-Speaker & Multi-Speaker Generation (`generateContent`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think the multi-speaker is missing


Gemini TTS audio format depends on whether the request is unary or streaming:

- **Unary Requests (`generateContent`)**: Returns complete **WAV (`audio/wav`)**

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Jetski says this contradicts the Android, iOS and Flutter snippets, and line 832 in this same file in terms of what audio format is returned.

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.

2 participants