From a2a46c7c6700edc6840faa2675d92695d2d3104d Mon Sep 17 00:00:00 2001 From: Tommaso Sciortino Date: Fri, 27 Jun 2025 12:07:38 -0700 Subject: Add privacy notice slash command (#2059) --- packages/core/src/code_assist/server.ts | 47 +++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'packages/core/src/code_assist/server.ts') diff --git a/packages/core/src/code_assist/server.ts b/packages/core/src/code_assist/server.ts index 5798289a..1eaf9217 100644 --- a/packages/core/src/code_assist/server.ts +++ b/packages/core/src/code_assist/server.ts @@ -6,28 +6,30 @@ import { AuthClient } from 'google-auth-library'; import { - LoadCodeAssistResponse, + CodeAssistGlobalUserSettingResponse, LoadCodeAssistRequest, - OnboardUserRequest, + LoadCodeAssistResponse, LongrunningOperationResponse, + OnboardUserRequest, + SetCodeAssistGlobalUserSettingRequest, } from './types.js'; import { - GenerateContentResponse, - GenerateContentParameters, CountTokensParameters, - EmbedContentResponse, CountTokensResponse, EmbedContentParameters, + EmbedContentResponse, + GenerateContentParameters, + GenerateContentResponse, } from '@google/genai'; import * as readline from 'readline'; import { ContentGenerator } from '../core/contentGenerator.js'; import { + CaCountTokenResponse, CaGenerateContentResponse, - toGenerateContentRequest, + fromCountTokenResponse, fromGenerateContentResponse, toCountTokenRequest, - fromCountTokenResponse, - CaCountTokenResponse, + toGenerateContentRequest, } from './converter.js'; import { PassThrough } from 'node:stream'; @@ -93,6 +95,21 @@ export class CodeAssistServer implements ContentGenerator { ); } + async getCodeAssistGlobalUserSetting(): Promise { + return await this.getEndpoint( + 'getCodeAssistGlobalUserSetting', + ); + } + + async setCodeAssistGlobalUserSetting( + req: SetCodeAssistGlobalUserSettingRequest, + ): Promise { + return await this.callEndpoint( + 'setCodeAssistGlobalUserSetting', + req, + ); + } + async countTokens(req: CountTokensParameters): Promise { const resp = await this.callEndpoint( 'countTokens', @@ -126,6 +143,20 @@ export class CodeAssistServer implements ContentGenerator { return res.data as T; } + async getEndpoint(method: string, signal?: AbortSignal): Promise { + const res = await this.auth.request({ + url: `${CODE_ASSIST_ENDPOINT}/${CODE_ASSIST_API_VERSION}:${method}`, + method: 'GET', + headers: { + 'Content-Type': 'application/json', + ...this.httpOptions.headers, + }, + responseType: 'json', + signal, + }); + return res.data as T; + } + async streamEndpoint( method: string, req: object, -- cgit v1.2.3