mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 03:24:42 -07:00
Fix unsafe assertions in code_assist folder. (#19706)
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
c04602f209
commit
b7555ab1e1
@@ -7,7 +7,6 @@
|
||||
import type { AuthClient } from 'google-auth-library';
|
||||
import type {
|
||||
CodeAssistGlobalUserSettingResponse,
|
||||
GoogleRpcResponse,
|
||||
LoadCodeAssistRequest,
|
||||
LoadCodeAssistResponse,
|
||||
LongRunningOperationResponse,
|
||||
@@ -296,7 +295,7 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
req: object,
|
||||
signal?: AbortSignal,
|
||||
): Promise<T> {
|
||||
const res = await this.client.request({
|
||||
const res = await this.client.request<T>({
|
||||
url: this.getMethodUrl(method),
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -307,15 +306,14 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
body: JSON.stringify(req),
|
||||
signal,
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
return res.data as T;
|
||||
return res.data;
|
||||
}
|
||||
|
||||
private async makeGetRequest<T>(
|
||||
url: string,
|
||||
signal?: AbortSignal,
|
||||
): Promise<T> {
|
||||
const res = await this.client.request({
|
||||
const res = await this.client.request<T>({
|
||||
url,
|
||||
method: 'GET',
|
||||
headers: {
|
||||
@@ -325,8 +323,7 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
responseType: 'json',
|
||||
signal,
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
return res.data as T;
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async requestGet<T>(method: string, signal?: AbortSignal): Promise<T> {
|
||||
@@ -371,8 +368,7 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
if (bufferedLines.length === 0) {
|
||||
continue; // no data to yield
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
yield JSON.parse(bufferedLines.join('\n')) as T;
|
||||
yield JSON.parse(bufferedLines.join('\n'));
|
||||
bufferedLines = []; // Reset the buffer after yielding
|
||||
}
|
||||
// Ignore other lines like comments or id fields
|
||||
@@ -397,23 +393,43 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
function isVpcScAffectedUser(error: unknown): boolean {
|
||||
if (error && typeof error === 'object' && 'response' in error) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const gaxiosError = error as {
|
||||
response?: {
|
||||
data?: unknown;
|
||||
interface VpcScErrorResponse {
|
||||
response: {
|
||||
data: {
|
||||
error: {
|
||||
details: unknown[];
|
||||
};
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const response = gaxiosError.response?.data as
|
||||
| GoogleRpcResponse
|
||||
| undefined;
|
||||
if (Array.isArray(response?.error?.details)) {
|
||||
return response.error.details.some(
|
||||
(detail) => detail.reason === 'SECURITY_POLICY_VIOLATED',
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function isVpcScErrorResponse(error: unknown): error is VpcScErrorResponse {
|
||||
return (
|
||||
!!error &&
|
||||
typeof error === 'object' &&
|
||||
'response' in error &&
|
||||
!!error.response &&
|
||||
typeof error.response === 'object' &&
|
||||
'data' in error.response &&
|
||||
!!error.response.data &&
|
||||
typeof error.response.data === 'object' &&
|
||||
'error' in error.response.data &&
|
||||
!!error.response.data.error &&
|
||||
typeof error.response.data.error === 'object' &&
|
||||
'details' in error.response.data.error &&
|
||||
Array.isArray(error.response.data.error.details)
|
||||
);
|
||||
}
|
||||
|
||||
function isVpcScAffectedUser(error: unknown): boolean {
|
||||
if (isVpcScErrorResponse(error)) {
|
||||
return error.response.data.error.details.some(
|
||||
(detail: unknown) =>
|
||||
detail &&
|
||||
typeof detail === 'object' &&
|
||||
'reason' in detail &&
|
||||
detail.reason === 'SECURITY_POLICY_VIOLATED',
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user