Add abort signal handling to read, write, and edit tools

All tools now check the abort signal before executing and throw
"Operation aborted" error if the signal is already aborted.
This ensures consistent abort behavior across all tools.
This commit is contained in:
Mario Zechner 2025-11-11 23:28:39 +01:00
parent 001beff394
commit e6b47799a4
4 changed files with 84 additions and 2 deletions

View file

@ -26,7 +26,12 @@ export const readTool: AgentTool<typeof readSchema> = {
label: "read",
description: "Read the contents of a file. Returns the full file content as text.",
parameters: readSchema,
execute: async (_toolCallId: string, { path }: { path: string }) => {
execute: async (_toolCallId: string, { path }: { path: string }, signal?: AbortSignal) => {
// Check if already aborted
if (signal?.aborted) {
throw new Error("Operation aborted");
}
const absolutePath = resolve(expandPath(path));
if (!existsSync(absolutePath)) {