@firebase/ai 2.1.0-20250806231852 → 2.1.0-canary.02280d747

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.
@@ -4,7 +4,7 @@ import { FirebaseError, getModularInstance } from '@firebase/util';
4
4
  import { Logger } from '@firebase/logger';
5
5
 
6
6
  var name = "@firebase/ai";
7
- var version = "2.1.0-20250806231852";
7
+ var version = "2.1.0-canary.02280d747";
8
8
 
9
9
  /**
10
10
  * @license
@@ -653,6 +653,12 @@ class AIService {
653
653
  _delete() {
654
654
  return Promise.resolve();
655
655
  }
656
+ set options(optionsToSet) {
657
+ this._options = optionsToSet;
658
+ }
659
+ get options() {
660
+ return this._options;
661
+ }
656
662
  }
657
663
 
658
664
  /**
@@ -837,7 +843,12 @@ class AIModel {
837
843
  };
838
844
  }
839
845
  else if (ai.appCheck) {
840
- this._apiSettings.getAppCheckToken = () => ai.appCheck.getToken();
846
+ if (ai.options?.useLimitedUseAppCheckTokens) {
847
+ this._apiSettings.getAppCheckToken = () => ai.appCheck.getLimitedUseToken();
848
+ }
849
+ else {
850
+ this._apiSettings.getAppCheckToken = () => ai.appCheck.getToken();
851
+ }
841
852
  }
842
853
  if (ai.auth) {
843
854
  this._apiSettings.getAuthToken = () => ai.auth.getToken();
@@ -2369,17 +2380,17 @@ class ChromeAdapterImpl {
2369
2380
  /**
2370
2381
  * Checks if a given request can be made on-device.
2371
2382
  *
2372
- * <ol>Encapsulates a few concerns:
2373
- * <li>the mode</li>
2374
- * <li>API existence</li>
2375
- * <li>prompt formatting</li>
2376
- * <li>model availability, including triggering download if necessary</li>
2377
- * </ol>
2383
+ * Encapsulates a few concerns:
2384
+ * the mode
2385
+ * API existence
2386
+ * prompt formatting
2387
+ * model availability, including triggering download if necessary
2378
2388
  *
2379
- * <p>Pros: callers needn't be concerned with details of on-device availability.</p>
2380
- * <p>Cons: this method spans a few concerns and splits request validation from usage.
2389
+ *
2390
+ * Pros: callers needn't be concerned with details of on-device availability.</p>
2391
+ * Cons: this method spans a few concerns and splits request validation from usage.
2381
2392
  * If instance variables weren't already part of the API, we could consider a better
2382
- * separation of concerns.</p>
2393
+ * separation of concerns.
2383
2394
  */
2384
2395
  async isAvailable(request) {
2385
2396
  if (!this.mode) {
@@ -2420,8 +2431,9 @@ class ChromeAdapterImpl {
2420
2431
  /**
2421
2432
  * Generates content on device.
2422
2433
  *
2423
- * <p>This is comparable to {@link GenerativeModel.generateContent} for generating content in
2424
- * Cloud.</p>
2434
+ * @remarks
2435
+ * This is comparable to {@link GenerativeModel.generateContent} for generating content in
2436
+ * Cloud.
2425
2437
  * @param request - a standard Firebase AI {@link GenerateContentRequest}
2426
2438
  * @returns {@link Response}, so we can reuse common response formatting.
2427
2439
  */
@@ -2434,8 +2446,9 @@ class ChromeAdapterImpl {
2434
2446
  /**
2435
2447
  * Generates content stream on device.
2436
2448
  *
2437
- * <p>This is comparable to {@link GenerativeModel.generateContentStream} for generating content in
2438
- * Cloud.</p>
2449
+ * @remarks
2450
+ * This is comparable to {@link GenerativeModel.generateContentStream} for generating content in
2451
+ * Cloud.
2439
2452
  * @param request - a standard Firebase AI {@link GenerateContentRequest}
2440
2453
  * @returns {@link Response}, so we can reuse common response formatting.
2441
2454
  */
@@ -2486,11 +2499,11 @@ class ChromeAdapterImpl {
2486
2499
  /**
2487
2500
  * Triggers out-of-band download of an on-device model.
2488
2501
  *
2489
- * <p>Chrome only downloads models as needed. Chrome knows a model is needed when code calls
2490
- * LanguageModel.create.</p>
2502
+ * Chrome only downloads models as needed. Chrome knows a model is needed when code calls
2503
+ * LanguageModel.create.
2491
2504
  *
2492
- * <p>Since Chrome manages the download, the SDK can only avoid redundant download requests by
2493
- * tracking if a download has previously been requested.</p>
2505
+ * Since Chrome manages the download, the SDK can only avoid redundant download requests by
2506
+ * tracking if a download has previously been requested.
2494
2507
  */
2495
2508
  download() {
2496
2509
  if (this.isDownloading) {
@@ -2544,12 +2557,12 @@ class ChromeAdapterImpl {
2544
2557
  /**
2545
2558
  * Abstracts Chrome session creation.
2546
2559
  *
2547
- * <p>Chrome uses a multi-turn session for all inference. Firebase AI uses single-turn for all
2560
+ * Chrome uses a multi-turn session for all inference. Firebase AI uses single-turn for all
2548
2561
  * inference. To map the Firebase AI API to Chrome's API, the SDK creates a new session for all
2549
- * inference.</p>
2562
+ * inference.
2550
2563
  *
2551
- * <p>Chrome will remove a model from memory if it's no longer in use, so this method ensures a
2552
- * new session is created before an old session is destroyed.</p>
2564
+ * Chrome will remove a model from memory if it's no longer in use, so this method ensures a
2565
+ * new session is created before an old session is destroyed.
2553
2566
  */
2554
2567
  async createSession() {
2555
2568
  if (!this.languageModelProvider) {
@@ -2957,14 +2970,20 @@ class ImagenImageFormat {
2957
2970
  *
2958
2971
  * @public
2959
2972
  */
2960
- function getAI(app = getApp(), options = { backend: new GoogleAIBackend() }) {
2973
+ function getAI(app = getApp(), options) {
2961
2974
  app = getModularInstance(app);
2962
2975
  // Dependencies
2963
2976
  const AIProvider = _getProvider(app, AI_TYPE);
2964
- const identifier = encodeInstanceIdentifier(options.backend);
2965
- return AIProvider.getImmediate({
2977
+ const backend = options?.backend ?? new GoogleAIBackend();
2978
+ const finalOptions = {
2979
+ useLimitedUseAppCheckTokens: options?.useLimitedUseAppCheckTokens ?? false
2980
+ };
2981
+ const identifier = encodeInstanceIdentifier(backend);
2982
+ const aiInstance = AIProvider.getImmediate({
2966
2983
  identifier
2967
2984
  });
2985
+ aiInstance.options = finalOptions;
2986
+ return aiInstance;
2968
2987
  }
2969
2988
  /**
2970
2989
  * Returns a {@link GenerativeModel} class with methods for inference