feat: add codex image tool (#650)

This commit is contained in:
Kevin Lin
2026-01-22 18:05:49 -08:00
committed by GitHub
parent e32b10f931
commit e735bb7c66
8 changed files with 77 additions and 3 deletions

View File

@@ -0,0 +1,39 @@
import * as path from "node:path";
import { read, type ToolReturnContent } from "./Read";
import { validateRequiredParams } from "./validation.js";
interface ViewImageArgs {
path: string;
}
const IMAGE_EXTENSIONS = new Set([
".png",
".jpg",
".jpeg",
".gif",
".webp",
".bmp",
]);
function isImageFile(filePath: string): boolean {
const ext = path.extname(filePath).toLowerCase();
return IMAGE_EXTENSIONS.has(ext);
}
export async function view_image(
args: ViewImageArgs,
): Promise<{ content: ToolReturnContent }> {
validateRequiredParams(args, ["path"], "view_image");
const userCwd = process.env.USER_CWD || process.cwd();
const resolvedPath = path.isAbsolute(args.path)
? args.path
: path.resolve(userCwd, args.path);
if (!isImageFile(resolvedPath)) {
throw new Error(`Unsupported image file type: ${resolvedPath}`);
}
const result = await read({ file_path: resolvedPath });
return { content: result.content };
}