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 {
15
15
backend: Backend ;
16
16
// @deprecated (undocumented)
17
17
location: string ;
18
+ options? : AIOptions ;
18
19
}
19
20
20
21
// @public
@@ -61,6 +62,7 @@ export abstract class AIModel {
61
62
62
63
// @public
63
64
export interface AIOptions {
65
+ appCheck? : AppCheckOptions ;
64
66
backend: Backend ;
65
67
}
66
68
@@ -75,6 +77,12 @@ export class AnyOfSchema extends Schema {
75
77
toJSON(): SchemaRequest ;
76
78
}
77
79
80
+ // @public
81
+ export interface AppCheckOptions {
82
+ // (undocumented)
83
+ limitedUseTokens? : boolean ;
84
+ }
85
+
78
86
// @public
79
87
export class ArraySchema extends Schema {
80
88
constructor (schemaParams : SchemaParams , items : TypedSchema );
Original file line number Diff line number Diff line change @@ -72,18 +72,24 @@ declare module '@firebase/component' {
72
72
*
73
73
* @public
74
74
*/
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 {
79
76
app = getModularInstance ( app ) ;
80
77
// Dependencies
81
78
const AIProvider : Provider < 'AI' > = _getProvider ( app , AI_TYPE ) ;
82
79
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 ( {
85
87
identifier
86
88
} ) ;
89
+
90
+ aiInstance . options = finalOptions ;
91
+
92
+ return aiInstance ;
87
93
}
88
94
89
95
/**
Original file line number Diff line number Diff line change @@ -90,8 +90,13 @@ export abstract class AIModel {
90
90
return Promise . resolve ( { token } ) ;
91
91
} ;
92
92
} 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
+ }
95
100
}
96
101
97
102
if ( ( ai as AIService ) . auth ) {
Original file line number Diff line number Diff line change @@ -38,6 +38,10 @@ export interface AI {
38
38
* Vertex AI Gemini API (using {@link VertexAIBackend}).
39
39
*/
40
40
backend : Backend ;
41
+ /**
42
+ * Options applied to this {@link AI} instance.
43
+ */
44
+ options ?: AIOptions ;
41
45
/**
42
46
* @deprecated use `AI.backend.location` instead.
43
47
*
@@ -92,4 +96,15 @@ export interface AIOptions {
92
96
* The backend configuration to use for the AI service instance.
93
97
*/
94
98
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 ;
95
110
}
Original file line number Diff line number Diff line change 16
16
*/
17
17
18
18
import { FirebaseApp , _FirebaseService } from '@firebase/app' ;
19
- import { AI } from './public-types' ;
19
+ import { AI , AIOptions } from './public-types' ;
20
20
import {
21
21
AppCheckInternalComponentName ,
22
22
FirebaseAppCheckInternal
@@ -31,6 +31,7 @@ import { Backend, VertexAIBackend } from './backend';
31
31
export class AIService implements AI , _FirebaseService {
32
32
auth : FirebaseAuthInternal | null ;
33
33
appCheck : FirebaseAppCheckInternal | null ;
34
+ _options ?: AIOptions ;
34
35
location : string ; // This is here for backwards-compatibility
35
36
36
37
constructor (
@@ -54,4 +55,12 @@ export class AIService implements AI, _FirebaseService {
54
55
_delete ( ) : Promise < void > {
55
56
return Promise . resolve ( ) ;
56
57
}
58
+
59
+ set options ( optionsToSet : AIOptions ) {
60
+ this . options = optionsToSet ;
61
+ }
62
+
63
+ get options ( ) : AIOptions {
64
+ return this . options ;
65
+ }
57
66
}
You can’t perform that action at this time.
0 commit comments