langchain.js
    Preparing search index...

    Interface ApplyPatchOptions

    Options for the Apply Patch tool.

    interface ApplyPatchOptions {
        execute: (operation: ApplyPatchOperation) => string | Promise<string>;
    }
    Index

    Properties

    Properties

    execute: (operation: ApplyPatchOperation) => string | Promise<string>

    Execute function that handles patch operations. This function receives the operation input and should return a string describing the result (success or failure message).

    The operation types are:

    • create_file: Create a new file at the specified path with the diff content
    • update_file: Modify an existing file using V4A diff format
    • delete_file: Remove a file at the specified path
    execute: async (operation) => {
    if (operation.type === "create_file") {
    const content = applyDiff("", operation.diff, "create");
    await fs.writeFile(operation.path, content);
    return `Created ${operation.path}`;
    }
    if (operation.type === "update_file") {
    const current = await fs.readFile(operation.path, "utf-8");
    const newContent = applyDiff(current, operation.diff);
    await fs.writeFile(operation.path, newContent);
    return `Updated ${operation.path}`;
    }
    if (operation.type === "delete_file") {
    await fs.unlink(operation.path);
    return `Deleted ${operation.path}`;
    }
    return "Unknown operation type";
    }