mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-03-17 17:41:24 -07:00
Disallow unsafe type assertions (#18688)
This commit is contained in:
committed by
GitHub
parent
bce1caefd0
commit
fd65416a2f
@@ -208,6 +208,7 @@ function toContent(content: ContentUnion): Content {
|
||||
// it's a Part
|
||||
return {
|
||||
role: 'user',
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
parts: [toPart(content as Part)],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ export async function getExperiments(
|
||||
'Invalid format for experiments file: `flags` and `experimentIds` must be arrays if present.',
|
||||
);
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
return parseExperiments(response as ListExperimentsResponse);
|
||||
} catch (e) {
|
||||
debugLogger.debug('Failed to read experiments from GEMINI_EXP', e);
|
||||
|
||||
@@ -125,6 +125,7 @@ export class OAuthCredentialStorage {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const credentials = JSON.parse(credsJson) as Credentials;
|
||||
|
||||
// Save to new storage
|
||||
|
||||
@@ -115,6 +115,7 @@ async function initOauthClient(
|
||||
|
||||
if (
|
||||
credentials &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
(credentials as { type?: string }).type ===
|
||||
'external_account_authorized_user'
|
||||
) {
|
||||
@@ -602,6 +603,7 @@ export function getAvailablePort(): Promise<number> {
|
||||
}
|
||||
const server = net.createServer();
|
||||
server.listen(0, () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const address = server.address()! as net.AddressInfo;
|
||||
port = address.port;
|
||||
});
|
||||
|
||||
@@ -301,6 +301,7 @@ 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;
|
||||
}
|
||||
|
||||
@@ -318,6 +319,7 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
responseType: 'json',
|
||||
signal,
|
||||
});
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
return res.data as T;
|
||||
}
|
||||
|
||||
@@ -351,6 +353,7 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
|
||||
return (async function* (): AsyncGenerator<T> {
|
||||
const rl = readline.createInterface({
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
input: res.data as NodeJS.ReadableStream,
|
||||
crlfDelay: Infinity, // Recognizes '\r\n' and '\n' as line breaks
|
||||
});
|
||||
@@ -363,6 +366,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;
|
||||
bufferedLines = []; // Reset the buffer after yielding
|
||||
}
|
||||
@@ -390,11 +394,13 @@ 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;
|
||||
};
|
||||
};
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const response = gaxiosError.response?.data as
|
||||
| GoogleRpcResponse
|
||||
| undefined;
|
||||
|
||||
Reference in New Issue
Block a user