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