Project Files
src / tools / readPythonFile.ts
import { tool } from "@lmstudio/sdk";
import { z } from "zod";
import { readPythonFile } from "../utils/pythonFileEditor";
import { getToolDefinition } from "../utils/toolRegistry";
const TOOL_DEFINITION = getToolDefinition("read_python_file");
export const readPythonFileTool = tool({
name: TOOL_DEFINITION.name,
description: TOOL_DEFINITION.description,
parameters: {
filePath: z.string().min(1).max(500).describe("Python file path relative to workspace or absolute inside workspace."),
startLine: z.number().int().min(1).optional().describe("Optional 1-based start line."),
endLine: z.number().int().min(1).optional().describe("Optional 1-based end line."),
includeLineNumbers: z.boolean().optional().describe("Whether to prefix each returned line with its line number."),
},
implementation: async ({ filePath, startLine, endLine, includeLineNumbers }) => {
return await readPythonFile({
filePath,
...(startLine !== undefined ? { startLine } : {}),
...(endLine !== undefined ? { endLine } : {}),
includeLineNumbers: includeLineNumbers ?? false,
});
},
});