mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-10-03 19:03:21 +00:00
fix: Include apply patch err message in tool result (#54)
This commit is contained in:
parent
ff23ea49a8
commit
01cfde7077
1 changed files with 6 additions and 1 deletions
|
|
@ -57,10 +57,12 @@ export const applyPatchTool = tool(
|
||||||
|
|
||||||
let patchedContent: string | false;
|
let patchedContent: string | false;
|
||||||
let fixedDiff: string | false = false;
|
let fixedDiff: string | false = false;
|
||||||
|
let errorApplyingPatchMessage: string | undefined;
|
||||||
try {
|
try {
|
||||||
logger.info(`Applying patch to file ${file_path}`);
|
logger.info(`Applying patch to file ${file_path}`);
|
||||||
patchedContent = applyPatch(readFileOutput, diff);
|
patchedContent = applyPatch(readFileOutput, diff);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
errorApplyingPatchMessage = e instanceof Error ? e.message : undefined;
|
||||||
try {
|
try {
|
||||||
logger.warn("Failed to apply patch, trying to fix diff", {
|
logger.warn("Failed to apply patch, trying to fix diff", {
|
||||||
error: e,
|
error: e,
|
||||||
|
|
@ -116,7 +118,10 @@ export const applyPatchTool = tool(
|
||||||
let resultMessage = `Successfully applied diff to \`${file_path}\` and saved changes.`;
|
let resultMessage = `Successfully applied diff to \`${file_path}\` and saved changes.`;
|
||||||
logger.info(resultMessage);
|
logger.info(resultMessage);
|
||||||
if (fixedDiff) {
|
if (fixedDiff) {
|
||||||
resultMessage += `\n\nNOTE: The generated diff was NOT formatted properly, and had to be fixed. The diff which was applied is:\n<fixed-diff>\n${fixedDiff}\n</fixed-diff>`;
|
resultMessage +=
|
||||||
|
"\n\nNOTE: The generated diff was NOT formatted properly, and had to be fixed." +
|
||||||
|
`\nHere is the error that was thrown when your generated diff was applied:\n<apply-diff-error>\n${errorApplyingPatchMessage}\n</apply-diff-error>` +
|
||||||
|
`\nThe diff which was applied is:\n<fixed-diff>\n${fixedDiff}\n</fixed-diff>`;
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
result: resultMessage,
|
result: resultMessage,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue