| 42 | } |
| 43 | |
| 44 | function formatApplyChangeResult( |
| 45 | result: ApplyChangeResult, |
| 46 | fileChange: FileChange, |
| 47 | ): CodebuffToolOutput<'str_replace'>[0]['value'] { |
| 48 | if (result.status === 'created' || result.status === 'modified') { |
| 49 | return { |
| 50 | file: result.file, |
| 51 | message: |
| 52 | fileChange.type === 'patch' |
| 53 | ? 'String replace applied successfully.' |
| 54 | : result.status === 'created' |
| 55 | ? 'Created file successfully.' |
| 56 | : 'Overwrote file successfully.', |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | if (result.status === 'patchFailed') { |
| 61 | return { |
| 62 | file: result.file, |
| 63 | errorMessage: `Failed to apply patch.`, |
| 64 | patch: result.patch, |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | return { |
| 69 | file: result.file, |
| 70 | errorMessage: |
| 71 | 'Failed to write to file: file path caused an error or file could not be written', |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | async function applyChange(params: { |
| 76 | change: FileChange |