import {
  EDIT_FILE_SYSTEM_PROMPT,
  EDIT_FILE_TOOL_DESCRIPTION
} from "./chunk-63WE2C5R.js";
import {
  executeEditFile
} from "./chunk-SFIMDGVL.js";
import {
  __export
} from "./chunk-PZ5AY32C.js";

// tools/fastapply/openai.ts
var openai_exports = {};
__export(openai_exports, {
  createEditFileTool: () => createEditFileTool,
  default: () => openai_default,
  editFileTool: () => editFileTool,
  execute: () => execute,
  formatResult: () => formatResult,
  getSystemPrompt: () => getSystemPrompt
});
var editFileTool = {
  type: "function",
  function: {
    name: "edit_file",
    description: EDIT_FILE_TOOL_DESCRIPTION,
    parameters: {
      type: "object",
      properties: {
        target_filepath: {
          type: "string",
          description: "The path of the target file to modify"
        },
        instruction: {
          type: "string",
          description: "A single sentence written in the first person describing what the agent is changing. Used to help disambiguate uncertainty in the edit."
        },
        code_edit: {
          type: "string",
          description: "Specify ONLY the precise lines of code that you wish to edit. Use `// ... existing code ...` for unchanged sections."
        }
      },
      required: ["target_filepath", "instruction", "code_edit"]
    }
  }
};
async function execute(input, config) {
  return executeEditFile(input, config);
}
function getSystemPrompt() {
  return EDIT_FILE_SYSTEM_PROMPT;
}
function formatResult(result) {
  if (!result.success) {
    return `Error editing file: ${result.error}`;
  }
  const { changes } = result;
  return `Successfully applied changes to ${result.filepath}. Added ${changes.linesAdded}, removed ${changes.linesRemoved}, modified ${changes.linesModified}.`;
}
function createEditFileTool(config = {}) {
  const toolDef = {
    ...editFileTool,
    ...config.description && {
      function: {
        ...editFileTool.function,
        description: config.description
      }
    }
  };
  return Object.assign({}, toolDef, {
    execute: async (input) => {
      const parsedInput = typeof input === "string" ? JSON.parse(input) : input;
      return execute(parsedInput, config);
    },
    formatResult: (result) => {
      return formatResult(result);
    },
    getSystemPrompt: () => {
      return getSystemPrompt();
    }
  });
}
var openai_default = editFileTool;

export {
  editFileTool,
  execute,
  getSystemPrompt,
  formatResult,
  createEditFileTool,
  openai_default,
  openai_exports
};
//# sourceMappingURL=chunk-7JVW5IHP.js.map