Skip to content

Commit c53417d

Browse files
sararobcopybara-github
authored andcommitted
chore: Append language to user-agent header
FUTURE_COPYBARA_INTEGRATE_REVIEW=#596 from googleapis:release-please--branches--main--components--vertexai 489440d PiperOrigin-RevId: 900425828
1 parent 73d18da commit c53417d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/genai/client.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ export class Client {
2626
const uploader = new NodeUploader();
2727
const downloader = new NodeDownloader();
2828

29+
const nodeVersion =
30+
typeof process !== 'undefined' ? process.version : 'unknown';
31+
2932
this.apiClient = new ApiClient({
3033
auth,
3134
uploader,
@@ -35,7 +38,8 @@ export class Client {
3538
vertexai: true,
3639
httpOptions: options.apiEndpoint ? {baseUrl: options.apiEndpoint} :
3740
undefined,
38-
userAgentExtra: `vertex-genai-modules/${SDK_VERSION}`,
41+
userAgentExtra:
42+
`vertex-genai-modules/${SDK_VERSION} gl-node/${nodeVersion}`,
3943
});
4044

4145
this._agentEnginesInternal = new AgentEngines(this.apiClient);

test/genai/_replay_client.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ export class ReplayClient extends Client {
8686
}
8787

8888
const [url, init] = actualArgs;
89+
90+
91+
const actualHeaders = new Headers(init?.headers || {});
92+
const xGoogApiClient = actualHeaders.get('x-goog-api-client') || '';
93+
const userAgent = actualHeaders.get('user-agent') || '';
94+
95+
// Validate that user-agent is set correctly.
96+
expect(xGoogApiClient).toContain('vertex-genai-modules/');
97+
expect(xGoogApiClient).toContain('gl-node/');
98+
expect(userAgent).toContain('vertex-genai-modules/');
99+
expect(userAgent).toContain('gl-node/');
100+
89101
const normalizedActual = normalizeRequest(init || {}, url.toString());
90102
assertMessagesEqual(normalizedActual, expectedRequestCamel);
91103
}

0 commit comments

Comments
 (0)