vybekiit 0.7.32 → 0.7.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/bin.js +5 -2
  2. package/dist/global-skills/aws-serverless/SKILL.md +168 -32
  3. package/dist/global-skills/aws-serverless/references/api-gateway.md +17 -0
  4. package/dist/global-skills/aws-serverless/references/architecture.md +9 -13
  5. package/dist/global-skills/aws-serverless/references/lambda.md +3 -3
  6. package/dist/global-skills/aws-serverless/references/orchestration.md +46 -20
  7. package/dist/global-skills/aws-serverless/references/production.md +1 -1
  8. package/dist/global-skills/eas-simulator/SKILL.md +15 -15
  9. package/dist/global-skills/eas-simulator/references/controllers.md +11 -7
  10. package/dist/global-skills/eas-simulator/references/run-your-app.md +8 -8
  11. package/dist/global-skills/eas-simulator/references/troubleshooting.md +10 -6
  12. package/dist/global-skills/email-best-practices/references/sending-reliability.md +17 -22
  13. package/dist/global-skills/extension-to-functions-codebase/SKILL.md +1 -0
  14. package/dist/global-skills/firebase-ai-logic-basics/SKILL.md +161 -76
  15. package/dist/global-skills/firebase-ai-logic-basics/references/flutter_setup.md +37 -0
  16. package/dist/global-skills/firebase-ai-logic-basics/references/ios_setup.md +97 -3
  17. package/dist/global-skills/firebase-ai-logic-basics/references/usage_patterns_android.md +88 -3
  18. package/dist/global-skills/firebase-ai-logic-basics/references/usage_patterns_web.md +91 -3
  19. package/dist/global-skills/firebase-app-hosting-basics/SKILL.md +5 -1
  20. package/dist/global-skills/firebase-auth-basics/SKILL.md +1 -0
  21. package/dist/global-skills/firebase-auth-basics/references/client_sdk_android.md +9 -9
  22. package/dist/global-skills/firebase-auth-basics/references/client_sdk_web.md +3 -3
  23. package/dist/global-skills/firebase-auth-basics/references/flutter_setup.md +22 -19
  24. package/dist/global-skills/firebase-auth-basics/references/security_rules.md +2 -2
  25. package/dist/global-skills/firebase-basics/SKILL.md +6 -2
  26. package/dist/global-skills/firebase-basics/references/android_setup.md +101 -37
  27. package/dist/global-skills/firebase-basics/references/ios_setup.md +57 -0
  28. package/dist/global-skills/firebase-basics/references/web_setup.md +52 -0
  29. package/dist/global-skills/firebase-crashlytics/SKILL.md +1 -0
  30. package/dist/global-skills/firebase-crashlytics/references/android_setup.md +84 -84
  31. package/dist/global-skills/firebase-crashlytics/references/ios_setup.md +1 -0
  32. package/dist/global-skills/firebase-data-connect/SKILL.md +1 -0
  33. package/dist/global-skills/firebase-data-connect/reference/config.md +8 -8
  34. package/dist/global-skills/firebase-data-connect/reference/realtime.md +4 -1
  35. package/dist/global-skills/firebase-data-connect/reference/sdk_android.md +33 -34
  36. package/dist/global-skills/firebase-data-connect/reference/sdk_web.md +8 -3
  37. package/dist/global-skills/firebase-data-connect/reference/security.md +13 -13
  38. package/dist/global-skills/firebase-firestore/SKILL.md +17 -7
  39. package/dist/global-skills/firebase-firestore/references/enterprise/android_sdk_usage.md +32 -32
  40. package/dist/global-skills/firebase-firestore/references/enterprise/indexes.md +2 -1
  41. package/dist/global-skills/firebase-firestore/references/standard/android_sdk_usage.md +14 -14
  42. package/dist/global-skills/firebase-firestore/references/standard/indexes.md +2 -1
  43. package/dist/global-skills/firebase-hosting-basics/SKILL.md +1 -0
  44. package/dist/global-skills/firebase-remote-config-basics/SKILL.md +2 -1
  45. package/dist/global-skills/firebase-remote-config-basics/references/android_setup.md +36 -37
  46. package/dist/global-skills/firebase-security-rules-auditor/SKILL.md +7 -6
  47. package/dist/global-skills/firestore-rules-creation/SKILL.md +22 -10
  48. package/dist/global-skills/neon/SKILL.md +16 -0
  49. package/dist/global-skills/neon-ai-gateway/SKILL.md +43 -14
  50. package/dist/global-skills/neon-postgres/SKILL.md +1 -1
  51. package/dist/global-skills/neon-postgres/references/full-text-search.md +27 -17
  52. package/dist/global-skills/neon-postgres/references/hybrid-search.md +19 -15
  53. package/dist/global-skills/neon-postgres/references/lakebase-search-drizzle.md +99 -14
  54. package/dist/global-skills/neon-postgres/references/vector-search.md +93 -10
  55. package/dist/global-skills/resend/SKILL.md +4 -15
  56. package/dist/global-skills/resend/references/domains.md +1 -1
  57. package/dist/global-skills/resend/references/installation.md +3 -3
  58. package/dist/global-skills/resend/references/sending/best-practices.md +3 -3
  59. package/dist/global-skills/resend/references/sending/single-email-examples.md +3 -3
  60. package/dist/global-skills/stripe-best-practices/SKILL.md +18 -18
  61. package/dist/global-skills/stripe-best-practices/references/tax.md +26 -14
  62. package/dist/global-skills/use-railway/SKILL.md +6 -6
  63. package/dist/global-skills/use-railway/references/iac.md +2 -1
  64. package/dist/global-skills/use-railway/references/tracing.md +13 -5
  65. package/dist/global-skills/workers-best-practices/SKILL.md +1 -1
  66. package/dist/global-skills/wrangler/SKILL.md +3 -3
  67. package/dist/global-skills/xcode-project-setup/SKILL.md +1 -0
  68. package/package.json +8 -8
@@ -1,8 +1,10 @@
1
1
  ---
2
2
  name: firebase-ai-logic-basics
3
- description: Official skill for integrating Firebase AI Logic (Gemini API) into web applications. Covers setup, multimodal inference, structured output, and security.
3
+ description: >-
4
+ Integrates Firebase AI Logic (formerly Vertex AI for Firebase) into mobile and web apps (Android, iOS, Web, and Flutter) to call Gemini models from client code. Use when provisioning or initializing Firebase AI Logic, or adding Gemini features to an app: text generation, multimodal input, chat, streaming, structured output, hybrid on-device inference, App Check protection, or switching models with Remote Config.
4
5
  version: 1.0.1
5
6
  metadata:
7
+ author: Google LLC
6
8
  category: AiAndMachineLearning
7
9
  disable-model-invocation: true
8
10
  ---
@@ -12,57 +14,98 @@ disable-model-invocation: true
12
14
  ## Overview
13
15
 
14
16
  Firebase AI Logic is a product of Firebase that allows developers to add gen AI
15
- to their mobile and web apps using client-side SDKs. You can call Gemini models
16
- directly from your app without managing a dedicated backend. Firebase AI Logic,
17
- which was previously known as "Vertex AI for Firebase", represents the evolution
18
- of Google's AI integration platform for mobile and web developers.
17
+ to their mobile and web apps using client-side SDKs. The app can directly call
18
+ Gemini models via Firebase AI Logic without the developer needing to manage a
19
+ dedicated backend. Firebase AI Logic was previously known as "Vertex AI for
20
+ Firebase".
19
21
 
20
22
  It supports the two Gemini API providers:
21
23
 
22
- - **Gemini Developer API**: It has a free tier ideal for prototyping, and
23
- pay-as-you-go for production
24
- - **Agent Platform Gemini API** (formerly branded Vertex AI): Ideal for scale
25
- with enterprise-grade production readiness, requires Blaze plan
24
+ - **Gemini Developer API**: It has a free tier ideal for prototyping, and
25
+ pay-as-you-go for production
26
+ - **Agent Platform Gemini API** (formerly branded Vertex AI): Ideal for scale
27
+ with enterprise-grade production readiness, requires Blaze pricing plan
26
28
 
27
29
  Use the Gemini Developer API as a default, and only Agent Platform Gemini API
28
30
  (formerly branded Vertex AI) if the application requires it.
29
31
 
30
- ## Setup & Initialization
32
+ ______________________________________________________________________
33
+
34
+ ## Setup & initialization
31
35
 
32
36
  ### Prerequisites
33
37
 
34
- - Before starting, ensure you have **Node.js 16+** and npm installed. Install
35
- them if they aren’t already available.
36
- - Identify the platform the user is interested in building on prior to
37
- starting: Android, iOS, Flutter or Web.
38
- - If their platform is unsupported, Direct the user to Firebase Docs to learn
39
- how to set up AI Logic for their application (share this link with the user
40
- https://firebase.google.com/docs/ai-logic/get-started)
38
+ - Identify the platform the user is interested in building on prior to starting:
39
+ Android, iOS, Web, or Flutter.
40
+ - If their platform is unsupported, Direct the user to Firebase Docs to learn
41
+ how to set up AI Logic for their application (share this link with the user
42
+ https://firebase.google.com/docs/ai-logic/get-started)
43
+ - The Firebase CLI commands below run through `npx` on every platform, so they
44
+ need **Node.js 20+** and npm. Use the `firebase-basics` skill to check for
45
+ them and to log in to the Firebase CLI. If Node.js is missing or older than
46
+ version 20, ask the user to install it as that skill describes. Don't install
47
+ system packages yourself, for example with `sudo apt-get`, because that
48
+ changes the user's machine without their consent.
49
+
50
+ ### 1. Provision Firebase AI Logic (ALL platforms)
51
+
52
+ Use the **Firebase CLI** to provision Firebase AI Logic for the Firebase
53
+ Project:
54
+
55
+ 1. Make sure that you're in a firebase directory (with a `firebase.json`).
41
56
 
42
- ### Installation
57
+ 1. Verify that you're running Firebase CLI commands against the intended
58
+ Firebase Project. When you run this command, the active project is marked
59
+ with "current":
43
60
 
44
- The library is part of the standard Firebase Web SDK.
61
+ ```bash
62
+ npx -y firebase-tools@latest projects:list
63
+ ```
45
64
 
46
- `npm install firebase@latest`
65
+ 1. Make sure there's at least one Firebase App for the target platform
66
+ registered with the current Firebase Project:
47
67
 
48
- If you're in a firebase directory (with a firebase.json) the currently selected
49
- project will be marked with "current" using this command:
68
+ ```bash
69
+ npx -y firebase-tools@latest apps:list
70
+ ```
50
71
 
51
- `npx -y firebase-tools@latest projects:list`
72
+ 1. Provision Firebase AI Logic for the Firebase Project:
52
73
 
53
- Ensure there's at least one app associated with the current project
74
+ ```bash
75
+ npx -y firebase-tools@latest init ailogic
76
+ ```
77
+
78
+ This command will enable the Gemini Developer API in the Firebase project.
79
+
80
+ > [!WARNING] **CRITICAL: Provisioning Firebase AI Logic is Required** For all
81
+ > platforms (Android, iOS, Web, or Flutter), even if the app already uses
82
+ > Firebase, you MUST run `npx -y firebase-tools@latest init ailogic` to
83
+ > provision the service. The configuration files of `GoogleService-Info.plist`,
84
+ > `google-services.json`, and `firebase_options.dart` ONLY handle client
85
+ > configuration and do NOT enable the Firebase AI Logic service, leading to
86
+ > `PERMISSION_DENIED` errors.
54
87
 
55
- `npx -y firebase-tools@latest apps:list`
88
+ If you can't run `init ailogic` yourself (for example because Node.js is missing
89
+ or the Firebase CLI isn't logged in) do NOT skip it. The app's requests to
90
+ Gemini models will fail until the Firebase AI Logic service is provisioned. Tell
91
+ the user to run this command in their project directory, and include it in your
92
+ final summary:
56
93
 
57
- Initialize AI logic SDK with the init command
94
+ ```bash
95
+ npx -y firebase-tools@latest init ailogic
96
+ ```
58
97
 
59
- `npx -y firebase-tools@latest init ailogic`
98
+ ### 2. Add the SDK and initialize the service in the app
60
99
 
61
- This will automatically enable the Gemini Developer API in the Firebase console.
100
+ Adding the SDK dependency and initializing the service are platform-specific.
101
+ Before writing code, read the reference for the target platform listed under
102
+ [Initialization Code References](#initialization-code-references).
62
103
 
63
104
  More info in
64
105
  [Firebase AI Logic Getting Started](https://firebase.google.com/docs/ai-logic/get-started.md.txt)
65
106
 
107
+ ______________________________________________________________________
108
+
66
109
  ## Core Capabilities
67
110
 
68
111
  > [!WARNING] **CRITICAL: Use current model names:** Always check the
@@ -92,16 +135,42 @@ To improve the user experience by showing partial results as they arrive (like a
92
135
  typing effect), use `generateContentStream` instead of `generateContent` for
93
136
  faster display of results.
94
137
 
138
+ ### Text-to-Speech (TTS) Generation
139
+
140
+ Generate spoken audio directly on client devices without a custom speech
141
+ backend. Firebase AI Logic supports speech synthesis using dedicated Gemini TTS
142
+ models:
143
+
144
+ - **Supported Models**: `gemini-3.1-flash-tts-preview`
145
+ - **Capabilities**:
146
+ - Single-speaker voice persona selection (`voiceName`) and multi-speaker
147
+ dialogues (up to 2 distinct speakers) via `SpeechConfig` /
148
+ `MultiSpeakerVoiceConfig`
149
+ - Direct audio responses by setting `responseModalities` to audio
150
+ - Streaming speech responses with `generateContentStream` for low-latency
151
+ playback
152
+ - Audio directives (`[Audio Profile: ...]`, `[Scene: ...]`,
153
+ `[Director's Note: ...]`) and emotional tags (`[whispers]`, `[laughs]`,
154
+ `[slowly]`)
155
+ - Client-side decoding and playback of 24 kHz 16-bit linear PCM (`audio/l16`)
156
+ or WAV container format (`audio/x-wav`)
157
+
158
+ See the [Text-to-Speech (TTS) Generation Guide](references/tts_generation.md)
159
+ for full implementation details, streaming patterns, and copy-paste code
160
+ snippets for iOS (Swift), Android (Kotlin), and Web.
161
+
95
162
  ### Generate Images with Nano Banana
96
163
 
97
164
  > [!WARNING] **Use current Image model names:** Always check the
98
165
  > [Firebase AI Logic Models documentation](https://firebase.google.com/docs/ai-logic/models.md.txt)
99
166
  > for the currently supported image generation (Nano Banana) model names.
100
167
 
101
- - Requires an upgraded Blaze pay-as-you-go billing plan.
168
+ - Requires an upgraded Blaze pay-as-you-go billing plan.
102
169
 
103
170
  ### Search Grounding with the built in googleSearch tool
104
171
 
172
+ ______________________________________________________________________
173
+
105
174
  ## Supported Platforms and Frameworks
106
175
 
107
176
  Supported Platforms and Frameworks include Kotlin and Java for Android, Swift
@@ -115,23 +184,26 @@ Enforce a specific JSON schema for the response.
115
184
 
116
185
  ### On-Device AI (Hybrid)
117
186
 
118
- Hybrid on-device inference for web apps, where the Firebase Javascript SDK
119
- automatically checks for Gemini Nano's availability (after installation) and
120
- switches between on-device or cloud-hosted prompt execution. This requires
121
- specific steps to enable model usage in the Chrome browser, more info in the
122
- [hybrid-on-device-inference documentation](https://firebase.google.com/docs/ai-logic/hybrid-on-device-inference.md.txt).
187
+ Hybrid inference runs prompts with an on-device model when one is available and
188
+ falls back to a cloud-hosted model otherwise (or vice versa). Availability and
189
+ setup steps differ by platform, more info in the
190
+ [hybrid and on-device documentation](https://firebase.google.com/docs/ai-logic/hybrid.md.txt),
191
+ which links to each platform's guide.
192
+
193
+ ______________________________________________________________________
123
194
 
124
195
  ## Security & Production
125
196
 
126
- ### App Check
197
+ ### Firebase App Check
127
198
 
128
199
  > [!WARNING] **Critical Safety Requirement:** In order to use AI Logic safely,
129
200
  > you MUST set up App Check on your app. This prevents unauthorized clients from
130
201
  > using your API quota and accessing your backend resources.
131
202
 
132
203
  See
133
- [App Check with reCAPTCHA Enterprise](https://firebase.google.com/docs/app-check/web/recaptcha-enterprise-provider.md.txt)
134
- for setup instructions.
204
+ [App Check for Firebase AI Logic](https://firebase.google.com/docs/ai-logic/app-check.md.txt)
205
+ for setup instructions. Each platform uses its own attestation provider, so
206
+ follow the instructions for the target platform.
135
207
 
136
208
  #### App Check Debug Tokens for Local Development & CI/CD
137
209
 
@@ -139,57 +211,69 @@ Because App Check attestation providers (like Play Integrity or DeviceCheck)
139
211
  reject emulators, simulators, or CI environments, you must use **App Check Debug
140
212
  Tokens** during development and testing to bypass standard attestation.
141
213
 
214
+ > [!WARNING] **CRITICAL: Never Hardcode or Commit Debug Tokens** App Check debug
215
+ > tokens allow clients to bypass attestation and access backend resources
216
+ > without a genuine device. Treat them as private secrets. **Never commit debug
217
+ > tokens to version control or hardcode raw token strings in client code** (Web,
218
+ > Android, iOS, or Flutter). Always inject them through local environment
219
+ > variables, gitignored local configurations, or CI secrets. If a token is
220
+ > compromised, revoke it immediately in the Firebase Console.
221
+
142
222
  ##### Local Development (Auto-Generated)
143
223
 
144
- 1. Configure your code's App Check provider to use the debug factory:
145
- * **Web**: Set `self.FIREBASE_APPCHECK_DEBUG_TOKEN = true;` before
146
- initializing App Check.
147
- * **Android**: Install `DebugAppCheckProviderFactory.getInstance()`.
148
- * **iOS**: Set provider factory to `AppCheckDebugProviderFactory()`.
149
- 2. Run your app in the emulator/localhost.
150
- 3. Look at your runtime debugger console / Logcat logs for the generated UUID:
151
- * *Example:* `AppCheck debug token:
152
- "123a4567-b89c-12d3-e456-789012345678"`
153
- 4. Register this token in the Firebase Console under **Security > App Check >
154
- Apps > Manage debug tokens**.
224
+ 1. Configure your code's App Check provider to use the debug factory. The API is
225
+ platform-specific; see the App Check section of the platform reference or the
226
+ App Check documentation linked above.
227
+ 1. Run your app in the emulator/localhost.
228
+ 1. Look at your runtime debugger console / Logcat logs for the generated UUID:
229
+ - *Example:* `AppCheck debug token: "123a4567-b89c-12d3-e456-789012345678"`
230
+ 1. Register this token in the Firebase Console under **Security > App Check >
231
+ Apps > Manage debug tokens**.
232
+
233
+ > **💡 Tip (Prevent Debug Token Churn):** Simulator or emulator resets, fresh
234
+ > installs, and clearing browser data can make the SDK generate a new debug
235
+ > token that you must register again. To keep a stable debug token without
236
+ > hardcoding it, see the App Check section of the platform reference.
155
237
 
156
238
  ##### CI/CD Pipelines (Pre-Provisioned)
157
239
 
158
- 1. Generate and register a new debug token in the Firebase Console under
159
- **Security > App Check > Apps > Manage debug tokens**.
160
- 2. Add this token string as an encrypted secret in your CI system (e.g.
161
- `APP_CHECK_DEBUG_TOKEN`).
162
- 3. Configure your build to pass this secret as an environment variable to the
163
- SDK during test execution (e.g. `self.FIREBASE_APPCHECK_DEBUG_TOKEN =
164
- process.env.APP_CHECK_DEBUG_TOKEN`).
240
+ 1. Generate and register a new debug token in the Firebase Console under
241
+ **Security > App Check > Apps > Manage debug tokens**.
242
+ 1. Add this token string as an encrypted secret in your CI system (e.g.
243
+ `APP_CHECK_DEBUG_TOKEN`).
244
+ 1. Configure your build to pass this secret as an environment variable to the
245
+ SDK during test execution.
165
246
 
166
- ### Remote Config
247
+ ### Firebase Remote Config
167
248
 
168
249
  Consider that you do not need to hardcode model names (e.g., a specific model
169
250
  version string). Use Firebase Remote Config to update model versions dynamically
170
251
  without deploying new client code. See
171
252
  [Changing model names remotely](https://firebase.google.com/docs/ai-logic/change-model-name-remotely.md.txt)
172
253
 
173
- > [!WARNING] **CRITICAL: Backend Provisioning Required** For all platforms
174
- > (Flutter, Android, iOS, Web), you MUST run `npx firebase-tools init ailogic`
175
- > to provision the service. `flutterfire configure` ONLY handles client
176
- > configuration and does NOT enable the AI service, leading to
177
- > `PERMISSION_DENIED` errors.
254
+ ______________________________________________________________________
178
255
 
179
256
  ## Initialization Code References
180
257
 
181
- - **Web Modular API**
182
- - Provider: Gemini Developer API
183
- - Reference: [usage_patterns_web.md](references/usage_patterns_web.md)
184
- - **Android (Kotlin)**
185
- - Provider: Gemini Developer API
186
- - Reference: [usage_patterns_android.md](references/usage_patterns_android.md)
187
- - **iOS (Swift)**
188
- - Provider: Gemini Developer API
189
- - Reference: [ios_setup.md](references/ios_setup.md)
190
- - **Flutter (Dart)**
191
- - Provider: Gemini Developer API
192
- - Reference: [flutter_setup.md](references/flutter_setup.md)
258
+ - **Android (Kotlin)**
259
+
260
+ - Gemini API Provider: Gemini Developer API
261
+ - Reference: [usage_patterns_android.md](references/usage_patterns_android.md)
262
+
263
+ - **iOS (Swift)**
264
+
265
+ - Gemini API Provider: Gemini Developer API
266
+ - Reference: [ios_setup.md](references/ios_setup.md)
267
+
268
+ - **Web Modular API**
269
+
270
+ - Gemini API Provider: Gemini Developer API
271
+ - Reference: [usage_patterns_web.md](references/usage_patterns_web.md)
272
+
273
+ - **Flutter (Dart)**
274
+
275
+ - Gemini API Provider: Gemini Developer API
276
+ - Reference: [flutter_setup.md](references/flutter_setup.md)
193
277
 
194
278
  > [!WARNING] **CRITICAL: Use current model names:** Always check the
195
279
  > [Firebase AI Logic Models documentation](https://firebase.google.com/docs/ai-logic/models.md.txt)
@@ -198,8 +282,9 @@ without deploying new client code. See
198
282
 
199
283
  ## References
200
284
 
201
- [Web SDK code examples and usage patterns](references/usage_patterns_web.md)
285
+ [Android (Kotlin) SDK usage patterns](references/usage_patterns_android.md)
202
286
  [iOS SDK code examples and usage patterns](references/ios_setup.md)
203
- [Flutter SDK code examples and usage patterns](references/flutter_setup.md)
287
+ [Web SDK setup, code examples, and usage patterns](references/usage_patterns_web.md)
204
288
 
205
- [Android (Kotlin) SDK usage patterns](references/usage_patterns_android.md)
289
+ [Flutter SDK code examples and usage patterns](references/flutter_setup.md)
290
+ [Client-side Text-to-Speech (TTS) generation](references/tts_generation.md)
@@ -96,3 +96,40 @@ final chat = model.startChat(history: [
96
96
 
97
97
  final response = await chat.sendMessage(Content.text('What is CBT?'));
98
98
  ```
99
+
100
+ ## App Check Debug Provider
101
+
102
+ For App Check debug tokens during local development and CI/CD, add the plugin
103
+ with `flutter pub add firebase_app_check`, then activate the debug providers
104
+ right after `Firebase.initializeApp()`:
105
+
106
+ ```dart
107
+ import 'package:firebase_app_check/firebase_app_check.dart';
108
+ import 'package:flutter/foundation.dart';
109
+
110
+ // In main(), after `await Firebase.initializeApp();`
111
+ if (kDebugMode) {
112
+ await FirebaseAppCheck.instance.activate(
113
+ providerAndroid: const AndroidDebugProvider(),
114
+ providerApple: const AppleDebugProvider(),
115
+ providerWeb: WebDebugProvider(),
116
+ );
117
+ }
118
+ ```
119
+
120
+ - Use `providerAndroid`, `providerApple`, and `providerWeb`. The older
121
+ `androidProvider` and `appleProvider` parameters (`AndroidProvider.debug`,
122
+ `AppleProvider.debug`) still appear in many examples but are deprecated.
123
+ - Only use the debug providers in debug builds, as gated by `kDebugMode` above.
124
+ Release builds must activate the production providers (Play Integrity, App
125
+ Attest or DeviceCheck, and reCAPTCHA Enterprise) instead; see
126
+ [App Check for Firebase AI Logic](https://firebase.google.com/docs/ai-logic/app-check.md.txt).
127
+ - **CI/CD**: Pass the pre-provisioned token to all three debug providers, e.g.
128
+ `debugToken: const String.fromEnvironment('APP_CHECK_DEBUG_TOKEN')`, and build
129
+ with `--dart-define=APP_CHECK_DEBUG_TOKEN=<token>`.
130
+ - **Flutter web**: `providerWeb` is required on web; without it, `activate()`
131
+ throws. `WebDebugProvider` turns on the web debug token itself, so
132
+ `web/index.html` doesn't need `self.FIREBASE_APPCHECK_DEBUG_TOKEN`.
133
+ - If the app uses `firebase_ai` 3.11.0 or lower, also set the `appCheck`
134
+ parameter of `FirebaseAI.googleAI(...)` to `FirebaseAppCheck.instance`. Newer
135
+ versions don't need this.
@@ -3,17 +3,46 @@
3
3
  ## 1. Import and Initialize
4
4
 
5
5
  Ensure you have installed the `FirebaseAILogic` SDK via Swift Package Manager.
6
+ Use the `xcode-project-setup` skill to automate adding the SPM dependency to the
7
+ Xcode project.
6
8
 
7
9
  ```swift
8
10
  import FirebaseAILogic
9
11
 
10
- // Initialize the Firebase AI service and the generative model.
11
- let ai = FirebaseAI.firebaseAI()
12
+ // To enable replay protection for generative or preview models, pass
13
+ // useLimitedUseAppCheckTokens: true with your backend:
14
+ let ai = FirebaseAI.firebaseAI(
15
+ backend: .googleAI(),
16
+ useLimitedUseAppCheckTokens: true
17
+ )
12
18
 
13
19
  // [AGENT] Replace "<latest_supported_model>" with the latest model from https://firebase.google.com/docs/ai-logic/models.md.txt
14
20
  let model = ai.generativeModel(modelName: "<latest_supported_model>")
15
21
  ```
16
22
 
23
+ ### App Check Replay Protection
24
+
25
+ Generative and preview models enforce replay protection with 5-minute
26
+ limited-use App Check tokens. If you call a protected model without enabling
27
+ limited-use tokens, the request fails with:
28
+
29
+ ```text
30
+ HTTP 403: "To access this model, you must enforce Firebase App Check"
31
+ ```
32
+
33
+ To resolve this error, initialize `FirebaseAI` with
34
+ `useLimitedUseAppCheckTokens: true`:
35
+
36
+ ```swift
37
+ let ai = FirebaseAI.firebaseAI(
38
+ backend: .googleAI(),
39
+ useLimitedUseAppCheckTokens: true
40
+ )
41
+ ```
42
+
43
+ This ensures the SDK fetches a fresh, short-lived limited-use token for each
44
+ request rather than reusing a standard cached App Check token.
45
+
17
46
  ## 2. SwiftUI Integration (Best Practices)
18
47
 
19
48
  Use the `@Observable` pattern to manage AI state and provide a smooth UX with
@@ -33,7 +62,10 @@ import FirebaseAILogic
33
62
  @Observable
34
63
  final class AIViewModel {
35
64
  // [AGENT] Replace with the latest model from https://firebase.google.com/docs/ai-logic/models.md.txt
36
- private lazy var model = FirebaseAI.firebaseAI().generativeModel(modelName: "<latest_supported_model>")
65
+ private lazy var model = FirebaseAI.firebaseAI(
66
+ backend: .googleAI(),
67
+ useLimitedUseAppCheckTokens: true
68
+ ).generativeModel(modelName: "<latest_supported_model>")
37
69
 
38
70
  var responseText: String = ""
39
71
  var isFetching: Bool = false
@@ -98,6 +130,68 @@ let model = FirebaseAI.firebaseAI().generativeModel(
98
130
  )
99
131
  ```
100
132
 
133
+ ## 4. App Check Debug Provider
134
+
135
+ For App Check debug tokens during local development and CI/CD, add the
136
+ `FirebaseAppCheck` product to the app target (with the `xcode-project-setup`
137
+ skill), then set the debug provider factory in debug builds *before*
138
+ `FirebaseApp.configure()`. Otherwise the debug provider isn't used.
139
+
140
+ ```swift
141
+ import FirebaseAppCheck
142
+ import FirebaseCore
143
+
144
+ // In your app's init(), before configuring Firebase:
145
+ #if DEBUG
146
+ AppCheck.setAppCheckProviderFactory(AppCheckDebugProviderFactory())
147
+ #endif
148
+ FirebaseApp.configure()
149
+ ```
150
+
151
+ For CI/CD, add an `AppCheckDebugToken` environment variable to the Xcode test
152
+ scheme with a value like `$(APP_CHECK_DEBUG_TOKEN)`, then pass the token from
153
+ the CI test command:
154
+
155
+ ```bash
156
+ xcodebuild test -scheme <scheme> -workspace <project>.xcworkspace \
157
+ APP_CHECK_DEBUG_TOKEN=<token>
158
+ ```
159
+
160
+ ### Debug Token Persistence
161
+
162
+ When running on simulators or during development, the Firebase iOS SDK generates
163
+ a new debug token UUID whenever `NSUserDefaults` is cleared (e.g., simulator
164
+ reset or fresh install). To avoid invalidating tokens registered in the Firebase
165
+ Console and prevent token churn, persist a stable token by setting the
166
+ `AppCheckDebugToken` environment variable, which the SDK reads automatically at
167
+ runtime:
168
+
169
+ > [!WARNING] **CRITICAL: Never Hardcode or Commit Debug Tokens** Debug tokens
170
+ > grant access to backend resources without device attestation. Never commit
171
+ > debug tokens to version control or hardcode token strings in source code.
172
+
173
+ - **In Xcode Scheme (Recommended):** Edit Scheme -> Run -> Arguments ->
174
+ Environment Variables -> Add `AppCheckDebugToken = <YOUR_DEBUG_TOKEN>`. Keep
175
+ user schemes (`xcuserdata/`) unshared and gitignored.
176
+ - **In Code (Safe Dynamic Loading Only):** If setting the environment variable
177
+ in code before configuring `AppCheckDebugProviderFactory`, load the token
178
+ dynamically from a gitignored local file or environment rather than hardcoding
179
+ the token literal:
180
+
181
+ ```swift
182
+ #if DEBUG
183
+ // ✅ SAFE: Load from gitignored local file or process environment
184
+ // Note: loadGitIgnoredDebugToken() is a placeholder for your custom helper (e.g., reading from a gitignored plist)
185
+ if let debugToken = loadGitIgnoredDebugToken() {
186
+ setenv("AppCheckDebugToken", debugToken, 0)
187
+ }
188
+ let providerFactory = AppCheckDebugProviderFactory()
189
+ AppCheck.setAppCheckProviderFactory(providerFactory)
190
+ #endif
191
+
192
+ FirebaseApp.configure() // Configure Firebase AFTER setting the App Check provider factory
193
+ ```
194
+
101
195
  # Advanced Features
102
196
 
103
197
  ### Chat Session (Multi-turn)
@@ -38,9 +38,9 @@ In your Activity or Fragment, initialize the `FirebaseAI` service and generate
38
38
  content using a Gemini model:
39
39
 
40
40
  ```kotlin
41
- import com.google.firebase.ai.FirebaseAI
42
41
  import com.google.firebase.Firebase
43
42
  import com.google.firebase.ai.ai
43
+ import com.google.firebase.ai.type.GenerativeBackend
44
44
 
45
45
  class MainActivity : AppCompatActivity() {
46
46
 
@@ -48,8 +48,11 @@ class MainActivity : AppCompatActivity() {
48
48
  super.onCreate(savedInstanceState)
49
49
  setContentView(R.layout.activity_main)
50
50
 
51
- // Initialize Firebase AI
52
- val ai = Firebase.ai
51
+ // Initialize with replay protection using limited-use App Check tokens:
52
+ val ai = Firebase.ai(
53
+ backend = GenerativeBackend.googleAI(),
54
+ useLimitedUseAppCheckTokens = true
55
+ )
53
56
 
54
57
  // [AGENT] Replace "<latest_supported_model>" with the latest model from https://firebase.google.com/docs/ai-logic/models.md.txt
55
58
  val model = ai.generativeModel("<latest_supported_model>")
@@ -67,6 +70,30 @@ class MainActivity : AppCompatActivity() {
67
70
  }
68
71
  ```
69
72
 
73
+ #### App Check Replay Protection on Android
74
+
75
+ Generative and preview models enforce replay protection using short-lived
76
+ (5-minute) limited-use App Check tokens to prevent replay attacks. If you call a
77
+ model enforcing replay protection without limited-use tokens, the request is
78
+ rejected with:
79
+
80
+ ```text
81
+ HTTP 403: "To access this model, you must enforce Firebase App Check"
82
+ ```
83
+
84
+ To resolve this on Android, pass `useLimitedUseAppCheckTokens = true` when
85
+ calling `Firebase.ai`:
86
+
87
+ ```kotlin
88
+ val ai = Firebase.ai(
89
+ backend = GenerativeBackend.googleAI(),
90
+ useLimitedUseAppCheckTokens = true
91
+ )
92
+ ```
93
+
94
+ This ensures the SDK requests fresh limited-use tokens (via Play Integrity or
95
+ the debug provider) for each request instead of reusing cached tokens.
96
+
70
97
  #### Jetpack Compose (Modern)
71
98
 
72
99
  Initialize inside a `ComponentActivity` and use `setContent`:
@@ -155,3 +182,61 @@ lifecycleScope.launch {
155
182
  }
156
183
  }
157
184
  ```
185
+
186
+ ______________________________________________________________________
187
+
188
+ ### 6. App Check Debug Provider
189
+
190
+ For App Check debug tokens during local development and CI/CD, install
191
+ `DebugAppCheckProviderFactory.getInstance()` as the App Check provider factory
192
+ in debug builds:
193
+
194
+ ```kotlin
195
+ if (BuildConfig.DEBUG) {
196
+ Firebase.appCheck.installAppCheckProviderFactory(
197
+ DebugAppCheckProviderFactory.getInstance()
198
+ )
199
+ }
200
+ ```
201
+
202
+ #### Debug Token Persistence
203
+
204
+ Emulator resets or clearing app storage erase `SharedPreferences`, causing
205
+ `DebugAppCheckProviderFactory` to print a new debug token in Logcat. To persist
206
+ a stable debug token across emulator resets and fresh installs without
207
+ hardcoding secrets:
208
+
209
+ > [!WARNING] **CRITICAL: Never Hardcode or Commit Debug Tokens** Never hardcode
210
+ > debug token strings in `build.gradle.kts` or Kotlin source files. Store the
211
+ > token in gitignored `local.properties` and inject it dynamically.
212
+
213
+ 1. In gitignored `local.properties`:
214
+
215
+ ```properties
216
+ APP_CHECK_DEBUG_TOKEN=<YOUR_DEBUG_TOKEN>
217
+ ```
218
+
219
+ 1. In `app/build.gradle.kts`:
220
+
221
+ ```kotlin
222
+ val localProperties = java.util.Properties().apply {
223
+ val localPropertiesFile = rootProject.file("local.properties")
224
+ if (localPropertiesFile.exists()) {
225
+ load(localPropertiesFile.inputStream())
226
+ }
227
+ }
228
+ val appCheckDebugToken = localProperties.getProperty("APP_CHECK_DEBUG_TOKEN")
229
+ ?: System.getenv("APP_CHECK_DEBUG_TOKEN") ?: ""
230
+
231
+ android {
232
+ defaultConfig {
233
+ // For normal emulator runs (injects into AndroidManifest)
234
+ manifestPlaceholders["firebaseAppCheckDebugSecret"] = appCheckDebugToken
235
+
236
+ // For instrumentation tests
237
+ if (appCheckDebugToken.isNotEmpty()) {
238
+ testInstrumentationRunnerArguments["firebaseAppCheckDebugSecret"] = appCheckDebugToken
239
+ }
240
+ }
241
+ }
242
+ ```