fix(core): unsafe type assertions in Core File System #19712 (#19739)

Co-authored-by: Dev Randalpura <devrandalpura@google.com>
This commit is contained in:
Saurav Sharma
2026-04-03 02:14:22 +05:30
committed by GitHub
parent 6fb58bd31f
commit e5adeaca80
2 changed files with 13 additions and 13 deletions

View File

@@ -10,6 +10,7 @@ import * as path from 'node:path';
import type { FileDiscoveryService } from '../services/fileDiscoveryService.js';
import type { FileFilteringOptions } from '../config/constants.js';
import { debugLogger } from './debugLogger.js';
import { getErrorMessage } from './errors.js';
// Simple console logger for now.
// TODO: Integrate with a more robust server-side logger.
const logger = {
@@ -80,10 +81,8 @@ export async function bfsFileSearch(
return { currentDir, entries };
} catch (error) {
// Warn user that a directory could not be read, as this affects search results.
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const message = (error as Error)?.message ?? 'Unknown error';
debugLogger.warn(
`[WARN] Skipping unreadable directory: ${currentDir} (${message})`,
`[WARN] Skipping unreadable directory: ${currentDir} (${getErrorMessage(error)})`,
);
if (debug) {
logger.debug(`Full error for ${currentDir}:`, error);
@@ -154,10 +153,8 @@ export function bfsFileSearchSync(
foundFiles,
);
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const message = (error as Error)?.message ?? 'Unknown error';
debugLogger.warn(
`[WARN] Skipping unreadable directory: ${currentDir} (${message})`,
`[WARN] Skipping unreadable directory: ${currentDir} (${getErrorMessage(error)})`,
);
}
}

View File

@@ -49,12 +49,12 @@ export function generateCheckpointFileName(
toolCall: ToolCallRequestInfo,
): string | null {
const toolArgs = toolCall.args;
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const toolFilePath = toolArgs['file_path'] as string;
const rawFilePath = toolArgs['file_path'];
if (!toolFilePath) {
if (typeof rawFilePath !== 'string' || !rawFilePath) {
return null;
}
const toolFilePath = rawFilePath;
const timestamp = new Date()
.toISOString()
@@ -168,11 +168,14 @@ export function getCheckpointInfoList(
for (const [file, content] of checkpointFiles) {
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const toolCallData = JSON.parse(content) as ToolCallData;
if (toolCallData.messageId) {
const parsed: unknown = JSON.parse(content);
const result = z
.object({ messageId: z.string() })
.passthrough()
.safeParse(parsed);
if (result.success) {
checkpointInfoList.push({
messageId: toolCallData.messageId,
messageId: result.data.messageId,
checkpoint: file.replace('.json', ''),
});
}