mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 11:04:42 -07:00
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:
@@ -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}`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user