File tree Expand file tree Collapse file tree 5 files changed +52
-9
lines changed
Expand file tree Collapse file tree 5 files changed +52
-9
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ export interface AI {
1515 backend: Backend ;
1616 // @deprecated (undocumented)
1717 location: string ;
18+ options? : AIOptions ;
1819}
1920
2021// @public
@@ -61,6 +62,7 @@ export abstract class AIModel {
6162
6263// @public
6364export interface AIOptions {
65+ appCheck? : AppCheckOptions ;
6466 backend: Backend ;
6567}
6668
@@ -75,6 +77,12 @@ export class AnyOfSchema extends Schema {
7577 toJSON(): SchemaRequest ;
7678}
7779
80+ // @public
81+ export interface AppCheckOptions {
82+ // (undocumented)
83+ limitedUseTokens? : boolean ;
84+ }
85+
7886// @public
7987export class ArraySchema extends Schema {
8088 constructor (schemaParams : SchemaParams , items : TypedSchema );
Original file line number Diff line number Diff line change @@ -72,18 +72,24 @@ declare module '@firebase/component' {
7272 *
7373 * @public
7474 */
75- export function getAI (
76- app : FirebaseApp = getApp ( ) ,
77- options : AIOptions = { backend : new GoogleAIBackend ( ) }
78- ) : AI {
75+ export function getAI ( app : FirebaseApp = getApp ( ) , options ?: AIOptions ) : AI {
7976 app = getModularInstance ( app ) ;
8077 // Dependencies
8178 const AIProvider : Provider < 'AI' > = _getProvider ( app , AI_TYPE ) ;
8279
83- const identifier = encodeInstanceIdentifier ( options . backend ) ;
84- return AIProvider . getImmediate ( {
80+ const finalOptions = {
81+ backend : options ?. backend ?? new GoogleAIBackend ( ) ,
82+ appCheck : options ?. appCheck ?? { limitedUseTokens : false }
83+ } ;
84+
85+ const identifier = encodeInstanceIdentifier ( finalOptions . backend ) ;
86+ const aiInstance = AIProvider . getImmediate ( {
8587 identifier
8688 } ) ;
89+
90+ aiInstance . options = finalOptions ;
91+
92+ return aiInstance ;
8793}
8894
8995/**
Original file line number Diff line number Diff line change @@ -90,8 +90,13 @@ export abstract class AIModel {
9090 return Promise . resolve ( { token } ) ;
9191 } ;
9292 } else if ( ( ai as AIService ) . appCheck ) {
93- this . _apiSettings . getAppCheckToken = ( ) =>
94- ( ai as AIService ) . appCheck ! . getToken ( ) ;
93+ if ( ai . options ?. appCheck ?. limitedUseTokens ) {
94+ this . _apiSettings . getAppCheckToken = ( ) =>
95+ ( ai as AIService ) . appCheck ! . getLimitedUseToken ( ) ;
96+ } else {
97+ this . _apiSettings . getAppCheckToken = ( ) =>
98+ ( ai as AIService ) . appCheck ! . getToken ( ) ;
99+ }
95100 }
96101
97102 if ( ( ai as AIService ) . auth ) {
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ export interface AI {
3838 * Vertex AI Gemini API (using {@link VertexAIBackend}).
3939 */
4040 backend : Backend ;
41+ /**
42+ * Options applied to this {@link AI} instance.
43+ */
44+ options ?: AIOptions ;
4145 /**
4246 * @deprecated use `AI.backend.location` instead.
4347 *
@@ -92,4 +96,15 @@ export interface AIOptions {
9296 * The backend configuration to use for the AI service instance.
9397 */
9498 backend : Backend ;
99+ /**
100+ * Configures App Check usage for this AI service instance.
101+ */
102+ appCheck ?: AppCheckOptions ;
103+ }
104+
105+ /**
106+ * Configures App Check usage for this AI service instance.
107+ */
108+ export interface AppCheckOptions {
109+ limitedUseTokens ?: boolean ;
95110}
Original file line number Diff line number Diff line change 1616 */
1717
1818import { FirebaseApp , _FirebaseService } from '@firebase/app' ;
19- import { AI } from './public-types' ;
19+ import { AI , AIOptions } from './public-types' ;
2020import {
2121 AppCheckInternalComponentName ,
2222 FirebaseAppCheckInternal
@@ -31,6 +31,7 @@ import { Backend, VertexAIBackend } from './backend';
3131export class AIService implements AI , _FirebaseService {
3232 auth : FirebaseAuthInternal | null ;
3333 appCheck : FirebaseAppCheckInternal | null ;
34+ _options ?: AIOptions ;
3435 location : string ; // This is here for backwards-compatibility
3536
3637 constructor (
@@ -54,4 +55,12 @@ export class AIService implements AI, _FirebaseService {
5455 _delete ( ) : Promise < void > {
5556 return Promise . resolve ( ) ;
5657 }
58+
59+ set options ( optionsToSet : AIOptions ) {
60+ this . options = optionsToSet ;
61+ }
62+
63+ get options ( ) : AIOptions {
64+ return this . options ;
65+ }
5766}
You can’t perform that action at this time.
0 commit comments