Skip to content

Commit 5b3b6e5

Browse files
committed
Simplify limitedUseToken option
1 parent 9ed8490 commit 5b3b6e5

File tree

10 files changed

+24
-85
lines changed

10 files changed

+24
-85
lines changed

common/api-review/ai.api.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export abstract class AIModel {
7070

7171
// @public
7272
export interface AIOptions {
73-
appCheck?: AppCheckOptions;
7473
backend?: Backend;
74+
useLimitedUseAppCheckTokens?: boolean;
7575
}
7676

7777
// @public
@@ -85,11 +85,6 @@ export class AnyOfSchema extends Schema {
8585
toJSON(): SchemaRequest;
8686
}
8787

88-
// @public
89-
export interface AppCheckOptions {
90-
limitedUseTokens?: boolean;
91-
}
92-
9388
// @public
9489
export class ArraySchema extends Schema {
9590
constructor(schemaParams: SchemaParams, items: TypedSchema);

docs-devsite/_toc.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ toc:
1414
path: /docs/reference/js/ai.aioptions.md
1515
- title: AnyOfSchema
1616
path: /docs/reference/js/ai.anyofschema.md
17-
- title: AppCheckOptions
18-
path: /docs/reference/js/ai.appcheckoptions.md
1917
- title: ArraySchema
2018
path: /docs/reference/js/ai.arrayschema.md
2119
- title: Backend

docs-devsite/ai.aioptions.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ export interface AIOptions
2222

2323
| Property | Type | Description |
2424
| --- | --- | --- |
25-
| [appCheck](./ai.aioptions.md#aioptionsappcheck) | [AppCheckOptions](./ai.appcheckoptions.md#appcheckoptions_interface) | Configures App Check usage for this AI service instance. |
2625
| [backend](./ai.aioptions.md#aioptionsbackend) | [Backend](./ai.backend.md#backend_class) | The backend configuration to use for the AI service instance. Defaults to the Gemini Developer API backend ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->). |
26+
| [useLimitedUseAppCheckTokens](./ai.aioptions.md#aioptionsuselimiteduseappchecktokens) | boolean | Whether to use App Check limited use tokens. Defaults to false. |
2727

28-
## AIOptions.appCheck
28+
## AIOptions.backend
2929

30-
Configures App Check usage for this AI service instance.
30+
The backend configuration to use for the AI service instance. Defaults to the Gemini Developer API backend ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->).
3131

3232
<b>Signature:</b>
3333

3434
```typescript
35-
appCheck?: AppCheckOptions;
35+
backend?: Backend;
3636
```
3737

38-
## AIOptions.backend
38+
## AIOptions.useLimitedUseAppCheckTokens
3939

40-
The backend configuration to use for the AI service instance. Defaults to the Gemini Developer API backend ([GoogleAIBackend](./ai.googleaibackend.md#googleaibackend_class)<!-- -->).
40+
Whether to use App Check limited use tokens. Defaults to false.
4141

4242
<b>Signature:</b>
4343

4444
```typescript
45-
backend?: Backend;
45+
useLimitedUseAppCheckTokens?: boolean;
4646
```

docs-devsite/ai.appcheckoptions.md

Lines changed: 0 additions & 35 deletions
This file was deleted.

docs-devsite/ai.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ The Firebase AI Web SDK.
5252
| --- | --- |
5353
| [AI](./ai.ai.md#ai_interface) | An instance of the Firebase AI SDK.<!-- -->Do not create this instance directly. Instead, use [getAI()](./ai.md#getai_a94a413)<!-- -->. |
5454
| [AIOptions](./ai.aioptions.md#aioptions_interface) | Options for initializing the AI service using [getAI()](./ai.md#getai_a94a413)<!-- -->. This allows specifying which backend to use (Vertex AI Gemini API or Gemini Developer API) and configuring its specific options (like location for Vertex AI). |
55-
| [AppCheckOptions](./ai.appcheckoptions.md#appcheckoptions_interface) | Configures App Check usage for this AI service instance. |
5655
| [BaseParams](./ai.baseparams.md#baseparams_interface) | Base parameters for a number of methods. |
5756
| [ChromeAdapter](./ai.chromeadapter.md#chromeadapter_interface) | <b>(EXPERIMENTAL)</b> Defines an inference "backend" that uses Chrome's on-device model, and encapsulates logic for detecting when on-device inference is possible.<!-- -->These methods should not be called directly by the user. |
5857
| [Citation](./ai.citation.md#citation_interface) | A single citation. |

packages/ai/src/api.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,32 @@ describe('Top level API', () => {
4545
expect(ai.backend).to.be.instanceOf(GoogleAIBackend);
4646
});
4747
it('works with options: no backend, limited use token', () => {
48-
const ai = getAI(getFullApp(), { appCheck: { limitedUseTokens: true } });
48+
const ai = getAI(getFullApp(), { useLimitedUseAppCheckTokens: true });
4949
expect(ai.backend).to.be.instanceOf(GoogleAIBackend);
50-
expect(ai.options?.appCheck?.limitedUseTokens).to.be.true;
50+
expect(ai.options?.useLimitedUseAppCheckTokens).to.be.true;
5151
});
5252
it('works with options: backend specified, limited use token', () => {
5353
const ai = getAI(getFullApp(), {
5454
backend: new VertexAIBackend('us-central1'),
55-
appCheck: { limitedUseTokens: true }
55+
useLimitedUseAppCheckTokens: true
5656
});
5757
expect(ai.backend).to.be.instanceOf(VertexAIBackend);
58-
expect(ai.options?.appCheck?.limitedUseTokens).to.be.true;
58+
expect(ai.options?.useLimitedUseAppCheckTokens).to.be.true;
5959
});
60-
it('works with options: appCheck option is empty', () => {
60+
it('works with options: appCheck option is falsy', () => {
6161
const ai = getAI(getFullApp(), {
6262
backend: new VertexAIBackend('us-central1'),
63-
appCheck: {}
63+
useLimitedUseAppCheckTokens: undefined
6464
});
6565
expect(ai.backend).to.be.instanceOf(VertexAIBackend);
66-
expect(ai.options?.appCheck?.limitedUseTokens).to.be.false;
66+
expect(ai.options?.useLimitedUseAppCheckTokens).to.be.false;
6767
});
6868
it('works with options: backend specified only', () => {
6969
const ai = getAI(getFullApp(), {
7070
backend: new VertexAIBackend('us-central1')
7171
});
7272
expect(ai.backend).to.be.instanceOf(VertexAIBackend);
73-
expect(ai.options?.appCheck?.limitedUseTokens).to.be.false;
73+
expect(ai.options?.useLimitedUseAppCheckTokens).to.be.false;
7474
});
7575
});
7676
it('getGenerativeModel throws if no model is provided', () => {

packages/ai/src/api.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,9 @@ export function getAI(app: FirebaseApp = getApp(), options?: AIOptions): AI {
8282

8383
const backend = options?.backend ?? new GoogleAIBackend();
8484

85-
const finalOptions: Omit<AIOptions, 'backend'> = {};
86-
87-
if (options?.appCheck) {
88-
if (options.appCheck.hasOwnProperty('limitedUseTokens')) {
89-
finalOptions.appCheck = options.appCheck;
90-
} else {
91-
finalOptions.appCheck = { ...options.appCheck, limitedUseTokens: false };
92-
}
93-
} else {
94-
finalOptions.appCheck = { limitedUseTokens: false };
95-
}
85+
const finalOptions: Omit<AIOptions, 'backend'> = {
86+
useLimitedUseAppCheckTokens: options?.useLimitedUseAppCheckTokens ?? false
87+
};
9688

9789
const identifier = encodeInstanceIdentifier(backend);
9890
const aiInstance = AIProvider.getImmediate({

packages/ai/src/models/ai-model.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ describe('AIModel', () => {
7676
//@ts-ignore
7777
{
7878
...fakeAI,
79-
options: { appCheck: { limitedUseTokens: false } },
79+
options: { useLimitedUseAppCheckTokens: false },
8080
appCheck: {
8181
getToken: getTokenStub,
8282
getLimitedUseToken: getLimitedUseTokenStub
@@ -99,7 +99,7 @@ describe('AIModel', () => {
9999
//@ts-ignore
100100
{
101101
...fakeAI,
102-
options: { appCheck: { limitedUseTokens: true } },
102+
options: { useLimitedUseAppCheckTokens: true },
103103
appCheck: {
104104
getToken: getTokenStub,
105105
getLimitedUseToken: getLimitedUseTokenStub

packages/ai/src/models/ai-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export abstract class AIModel {
9090
return Promise.resolve({ token });
9191
};
9292
} else if ((ai as AIService).appCheck) {
93-
if (ai.options?.appCheck?.limitedUseTokens) {
93+
if (ai.options?.useLimitedUseAppCheckTokens) {
9494
this._apiSettings.getAppCheckToken = () =>
9595
(ai as AIService).appCheck!.getLimitedUseToken();
9696
} else {

packages/ai/src/public-types.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,7 @@ export interface AIOptions {
9898
*/
9999
backend?: Backend;
100100
/**
101-
* Configures App Check usage for this AI service instance.
101+
* Whether to use App Check limited use tokens. Defaults to false.
102102
*/
103-
appCheck?: AppCheckOptions;
104-
}
105-
106-
/**
107-
* Configures App Check usage for this AI service instance.
108-
*/
109-
export interface AppCheckOptions {
110-
/**
111-
* Defaults to false.
112-
*/
113-
limitedUseTokens?: boolean;
103+
useLimitedUseAppCheckTokens?: boolean;
114104
}

0 commit comments

Comments
 (0)