From d1cd69a20d78b4675c7c15d6b1a542760b6fa1c2 Mon Sep 17 00:00:00 2001 From: lottielin <77655652+lottielin@users.noreply.github.com> Date: Fri, 30 Jan 2026 11:12:04 -0800 Subject: [PATCH] feat(core): enable overriding CODE_ASSIST_API_VERSION with env var (#17942) Co-authored-by: Charlotte Lin --- packages/core/src/code_assist/server.test.ts | 16 ++++++++++++++++ packages/core/src/code_assist/server.ts | 4 +++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/core/src/code_assist/server.test.ts b/packages/core/src/code_assist/server.test.ts index 930e7dfdb2..35b91fd1c5 100644 --- a/packages/core/src/code_assist/server.test.ts +++ b/packages/core/src/code_assist/server.test.ts @@ -327,6 +327,22 @@ describe('CodeAssistServer', () => { const url = server.getMethodUrl('testMethod'); expect(url).toBe('https://custom-endpoint.com/v1internal:testMethod'); }); + + it('should use the CODE_ASSIST_API_VERSION environment variable if set', () => { + process.env['CODE_ASSIST_API_VERSION'] = 'v2beta'; + const server = new CodeAssistServer({} as never); + const url = server.getMethodUrl('testMethod'); + expect(url).toBe('https://cloudcode-pa.googleapis.com/v2beta:testMethod'); + }); + + it('should use default value if CODE_ASSIST_API_VERSION env var is empty', () => { + process.env['CODE_ASSIST_API_VERSION'] = ''; + const server = new CodeAssistServer({} as never); + const url = server.getMethodUrl('testMethod'); + expect(url).toBe( + 'https://cloudcode-pa.googleapis.com/v1internal:testMethod', + ); + }); }); it('should call the generateContentStream endpoint and parse SSE', async () => { diff --git a/packages/core/src/code_assist/server.ts b/packages/core/src/code_assist/server.ts index bf57bc55b7..fa34464444 100644 --- a/packages/core/src/code_assist/server.ts +++ b/packages/core/src/code_assist/server.ts @@ -374,7 +374,9 @@ export class CodeAssistServer implements ContentGenerator { private getBaseUrl(): string { const endpoint = process.env['CODE_ASSIST_ENDPOINT'] ?? CODE_ASSIST_ENDPOINT; - return `${endpoint}/${CODE_ASSIST_API_VERSION}`; + const version = + process.env['CODE_ASSIST_API_VERSION'] || CODE_ASSIST_API_VERSION; + return `${endpoint}/${version}`; } getMethodUrl(method: string): string {