feat(core): enable overriding CODE_ASSIST_API_VERSION with env var (#17942)

Co-authored-by: Charlotte Lin <charlotteclin@google.com>
This commit is contained in:
lottielin
2026-01-30 11:12:04 -08:00
committed by GitHub
parent 62346875e4
commit d1cd69a20d
2 changed files with 19 additions and 1 deletions

View File

@@ -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 () => {

View File

@@ -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 {