Use GetOperation to poll for OnboardUser completion (#15827)

Co-authored-by: Vedant Mahajan <vedant.04.mahajan@gmail.com>
Co-authored-by: Tommaso Sciortino <sciortino@gmail.com>
This commit is contained in:
Ishaan Gupta
2026-01-07 00:38:59 +05:30
committed by GitHub
parent 9172e28315
commit cce4574143
4 changed files with 133 additions and 9 deletions
+27 -5
View File
@@ -51,7 +51,6 @@ import {
recordConversationOffered,
} from './telemetry.js';
import { getClientMetadata } from './experiments/client_metadata.js';
/** HTTP options to be used in each of the requests. */
export interface HttpOptions {
/** Additional HTTP headers to be sent with the request. */
@@ -160,6 +159,10 @@ export class CodeAssistServer implements ContentGenerator {
return this.requestPost<LongRunningOperationResponse>('onboardUser', req);
}
async getOperation(name: string): Promise<LongRunningOperationResponse> {
return this.requestGetOperation<LongRunningOperationResponse>(name);
}
async loadCodeAssist(
req: LoadCodeAssistRequest,
): Promise<LoadCodeAssistResponse> {
@@ -289,9 +292,12 @@ export class CodeAssistServer implements ContentGenerator {
return res.data as T;
}
async requestGet<T>(method: string, signal?: AbortSignal): Promise<T> {
private async makeGetRequest<T>(
url: string,
signal?: AbortSignal,
): Promise<T> {
const res = await this.client.request({
url: this.getMethodUrl(method),
url,
method: 'GET',
headers: {
'Content-Type': 'application/json',
@@ -303,6 +309,14 @@ export class CodeAssistServer implements ContentGenerator {
return res.data as T;
}
async requestGet<T>(method: string, signal?: AbortSignal): Promise<T> {
return this.makeGetRequest<T>(this.getMethodUrl(method), signal);
}
async requestGetOperation<T>(name: string, signal?: AbortSignal): Promise<T> {
return this.makeGetRequest<T>(this.getOperationUrl(name), signal);
}
async requestStreamingPost<T>(
method: string,
req: object,
@@ -345,10 +359,18 @@ export class CodeAssistServer implements ContentGenerator {
})();
}
getMethodUrl(method: string): string {
private getBaseUrl(): string {
const endpoint =
process.env['CODE_ASSIST_ENDPOINT'] ?? CODE_ASSIST_ENDPOINT;
return `${endpoint}/${CODE_ASSIST_API_VERSION}:${method}`;
return `${endpoint}/${CODE_ASSIST_API_VERSION}`;
}
getMethodUrl(method: string): string {
return `${this.getBaseUrl()}:${method}`;
}
getOperationUrl(name: string): string {
return `${this.getBaseUrl()}/${name}`;
}
}