Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a4848b4

Browse files
fix(ai): Fix test script broken by #9232 (#9235)
1 parent 4d834de commit a4848b4

File tree

5 files changed

+68
-41
lines changed

5 files changed

+68
-41
lines changed

‎.changeset/heavy-teachers-enjoy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@firebase/ai': patch
3+
---
4+
5+
Refactor component registration.

‎packages/ai/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"dev": "rollup -c -w",
3636
"update-responses": "../../scripts/update_vertexai_responses.sh",
3737
"testsetup": "yarn update-responses && yarn ts-node ./test-utils/convert-mocks.ts",
38-
"test": "run-p --npm-path npm lint test:browser",
38+
"test": "run-p --npm-path npm lint type-check test:browser",
3939
"test:ci": "yarn testsetup && node ../../scripts/run_tests_in_ci.js -s test",
4040
"test:skip-clone": "karma start",
4141
"test:browser": "yarn testsetup && karma start",
@@ -44,6 +44,7 @@
4444
"test:integration:node": "TS_NODE_COMPILER_OPTIONS='{\"module\":\"commonjs\"}' mocha integration/**/*.test.ts --config ../../config/mocharc.node.js",
4545
"api-report": "api-extractor run --local --verbose",
4646
"typings:public": "node ../../scripts/build/use_typings.js ./dist/ai-public.d.ts",
47+
"type-check": "yarn tsc --noEmit",
4748
"trusted-type-check": "tsec -p tsconfig.json --noEmit"
4849
},
4950
"peerDependencies": {

‎packages/ai/src/factory-browser.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import {
19+
ComponentContainer,
20+
InstanceFactoryOptions
21+
} from '@firebase/component';
22+
import { AIError } from './errors';
23+
import { decodeInstanceIdentifier } from './helpers';
24+
import { chromeAdapterFactory } from './methods/chrome-adapter';
25+
import { AIService } from './service';
26+
import { AIErrorCode } from './types';
27+
28+
export function factory(
29+
container: ComponentContainer,
30+
{ instanceIdentifier }: InstanceFactoryOptions
31+
): AIService {
32+
if (!instanceIdentifier) {
33+
throw new AIError(
34+
AIErrorCode.ERROR,
35+
'AIService instance identifier is undefined.'
36+
);
37+
}
38+
39+
const backend = decodeInstanceIdentifier(instanceIdentifier);
40+
41+
// getImmediate for FirebaseApp will always succeed
42+
const app = container.getProvider('app').getImmediate();
43+
const auth = container.getProvider('auth-internal');
44+
const appCheckProvider = container.getProvider('app-check-internal');
45+
46+
return new AIService(
47+
app,
48+
backend,
49+
auth,
50+
appCheckProvider,
51+
chromeAdapterFactory
52+
);
53+
}

‎packages/ai/src/index.ts

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,18 @@
2222
*/
2323

2424
import { registerVersion, _registerComponent } from '@firebase/app';
25-
import { AIService } from './service';
2625
import { AI_TYPE } from './constants';
27-
import {
28-
Component,
29-
ComponentContainer,
30-
ComponentType,
31-
InstanceFactoryOptions
32-
} from '@firebase/component';
26+
import { Component, ComponentType } from '@firebase/component';
3327
import { name, version } from '../package.json';
34-
import { decodeInstanceIdentifier } from './helpers';
35-
import { AIError } from './api';
36-
import { AIErrorCode } from './types';
37-
import { chromeAdapterFactory } from './methods/chrome-adapter';
3828
import { LanguageModel } from './types/language-model';
29+
import { factory } from './factory-browser';
3930

4031
declare global {
4132
interface Window {
4233
LanguageModel: LanguageModel;
4334
}
4435
}
4536

46-
function factory(
47-
container: ComponentContainer,
48-
{ instanceIdentifier }: InstanceFactoryOptions
49-
): AIService {
50-
if (!instanceIdentifier) {
51-
throw new AIError(
52-
AIErrorCode.ERROR,
53-
'AIService instance identifier is undefined.'
54-
);
55-
}
56-
57-
const backend = decodeInstanceIdentifier(instanceIdentifier);
58-
59-
// getImmediate for FirebaseApp will always succeed
60-
const app = container.getProvider('app').getImmediate();
61-
const auth = container.getProvider('auth-internal');
62-
const appCheckProvider = container.getProvider('app-check-internal');
63-
64-
return new AIService(
65-
app,
66-
backend,
67-
auth,
68-
appCheckProvider,
69-
chromeAdapterFactory
70-
);
71-
}
72-
7337
function registerAI(): void {
7438
_registerComponent(
7539
new Component(AI_TYPE, factory, ComponentType.PUBLIC).setMultipleInstances(

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import { Component, ComponentType } from '@firebase/component';
2525
import { FirebaseAppCheckInternal } from '@firebase/app-check-interop-types';
2626
import { AI_TYPE } from '../src/constants';
27-
import { factory } from '../src';
27+
import { factory } from '../src/factory-browser';
2828

2929
const fakeConfig = {
3030
projectId: 'projectId',
@@ -38,7 +38,11 @@ export function getFullApp(fakeAppParams?: {
3838
appId?: string;
3939
apiKey?: string;
4040
}): FirebaseApp {
41-
_registerComponent(new Component(AI_TYPE, factory, ComponentType.PUBLIC));
41+
_registerComponent(
42+
new Component(AI_TYPE, factory, ComponentType.PUBLIC).setMultipleInstances(
43+
true
44+
)
45+
);
4246
_registerComponent(
4347
new Component(
4448
'app-check-internal',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /