Skip to content

Commit 767cd77

Browse files
committed
Only send if data collection is on
1 parent 7f14785 commit 767cd77

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export abstract class VertexAIModel {
7878
apiKey: vertexAI.app.options.apiKey,
7979
project: vertexAI.app.options.projectId,
8080
appId: vertexAI.app.options.appId,
81+
automaticDataCollectionEnabled:
82+
vertexAI.app.automaticDataCollectionEnabled,
8183
location: vertexAI.location
8284
};
8385

packages/vertexai/src/requests/request.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,50 @@ describe('request methods', () => {
126126
const headers = await getHeaders(fakeUrl);
127127
expect(headers.get('x-goog-api-key')).to.equal('key');
128128
});
129+
it('adds app id if automatedDataCollectionEnabled is undefined', async () => {
130+
const headers = await getHeaders(fakeUrl);
131+
expect(headers.get('X-Firebase-AppId')).to.equal('my-appid');
132+
});
133+
it('adds app id if automatedDataCollectionEnabled is true', async () => {
134+
const fakeApiSettings: ApiSettings = {
135+
apiKey: 'key',
136+
project: 'myproject',
137+
appId: 'my-appid',
138+
location: 'moon',
139+
automaticDataCollectionEnabled: true,
140+
getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }),
141+
getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' })
142+
};
143+
const fakeUrl = new RequestUrl(
144+
'models/model-name',
145+
Task.GENERATE_CONTENT,
146+
fakeApiSettings,
147+
true,
148+
{}
149+
);
150+
const headers = await getHeaders(fakeUrl);
151+
expect(headers.get('X-Firebase-AppId')).to.equal('my-appid');
152+
});
153+
it('does not add app id if automatedDataCollectionEnabled is false', async () => {
154+
const fakeApiSettings: ApiSettings = {
155+
apiKey: 'key',
156+
project: 'myproject',
157+
appId: 'my-appid',
158+
location: 'moon',
159+
automaticDataCollectionEnabled: false,
160+
getAuthToken: () => Promise.resolve({ accessToken: 'authtoken' }),
161+
getAppCheckToken: () => Promise.resolve({ token: 'appchecktoken' })
162+
};
163+
const fakeUrl = new RequestUrl(
164+
'models/model-name',
165+
Task.GENERATE_CONTENT,
166+
fakeApiSettings,
167+
true,
168+
{}
169+
);
170+
const headers = await getHeaders(fakeUrl);
171+
expect(headers.get('X-Firebase-AppId')).to.be.null;
172+
});
129173
it('adds app check token if it exists', async () => {
130174
const headers = await getHeaders(fakeUrl);
131175
expect(headers.get('X-Firebase-AppCheck')).to.equal('appchecktoken');

packages/vertexai/src/requests/request.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ export async function getHeaders(url: RequestUrl): Promise<Headers> {
8484
headers.append('Content-Type', 'application/json');
8585
headers.append('x-goog-api-client', getClientHeaders());
8686
headers.append('x-goog-api-key', url.apiSettings.apiKey);
87-
headers.append('X-Firebase-AppId', url.apiSettings.appId); // Will be converted to 'X-Firebase-Appid' before it's sent in the browser.
87+
if (url.apiSettings.automaticDataCollectionEnabled !== false) {
88+
headers.append('X-Firebase-AppId', url.apiSettings.appId);
89+
}
8890
if (url.apiSettings.getAppCheckToken) {
8991
const appCheckToken = await url.apiSettings.getAppCheckToken();
9092
if (appCheckToken) {

packages/vertexai/src/types/internal.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface ApiSettings {
2525
project: string;
2626
appId: string;
2727
location: string;
28+
automaticDataCollectionEnabled?: boolean;
2829
getAuthToken?: () => Promise<FirebaseAuthTokenData | null>;
2930
getAppCheckToken?: () => Promise<AppCheckTokenResult>;
3031
}

0 commit comments

Comments
 (0)