Skip to content

Commit 72c370b

Browse files
committed
add a case and test
1 parent a9d69bc commit 72c370b

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

packages/ai/src/api.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ describe('Top level API', () => {
5757
expect(ai.backend).to.be.instanceOf(VertexAIBackend);
5858
expect(ai.options?.appCheck?.limitedUseTokens).to.be.true;
5959
});
60+
it('works with options: appCheck option is empty', () => {
61+
const ai = getAI(getFullApp(), {
62+
backend: new VertexAIBackend('us-central1'),
63+
appCheck: {}
64+
});
65+
expect(ai.backend).to.be.instanceOf(VertexAIBackend);
66+
expect(ai.options?.appCheck?.limitedUseTokens).to.be.false;
67+
});
6068
it('works with options: backend specified only', () => {
6169
const ai = getAI(getFullApp(), {
6270
backend: new VertexAIBackend('us-central1')

packages/ai/src/api.ts

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

8080
const backend = options?.backend ?? new GoogleAIBackend();
8181

82-
const finalOptions = {
83-
appCheck: options?.appCheck ?? { limitedUseTokens: false }
84-
};
82+
const finalOptions: Omit<AIOptions, 'backend'> = {};
83+
84+
if (options?.appCheck) {
85+
if (options.appCheck.hasOwnProperty('limitedUseTokens')) {
86+
finalOptions.appCheck = options.appCheck;
87+
} else {
88+
finalOptions.appCheck = { ...options.appCheck, limitedUseTokens: false };
89+
}
90+
} else {
91+
finalOptions.appCheck = { limitedUseTokens: false };
92+
}
8593

8694
const identifier = encodeInstanceIdentifier(backend);
8795
const aiInstance = AIProvider.getImmediate({

packages/ai/test-utils/get-fake-firebase-services.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ export function getFullApp(fakeAppParams?: {
3838
appId?: string;
3939
apiKey?: string;
4040
}): FirebaseApp {
41-
_registerComponent(
42-
new Component(
43-
AI_TYPE,
44-
factory,
45-
ComponentType.PUBLIC
46-
)
47-
);
41+
_registerComponent(new Component(AI_TYPE, factory, ComponentType.PUBLIC));
4842
_registerComponent(
4943
new Component(
5044
'app-check-internal',

0 commit comments

Comments
 (0)