22
33import difflib
44import os
5- from typing import TYPE_CHECKING , ClassVar , Optional
5+ from typing import TYPE_CHECKING , ClassVar
66
77import requests
88from langchain_core .messages import ToolMessage
@@ -23,15 +23,15 @@ class RelaceEditObservation(Observation):
2323 filepath : str = Field (
2424 description = "Path to the edited file" ,
2525 )
26- diff : Optional [ str ] = Field (
26+ diff : str | None = Field (
2727 default = None ,
2828 description = "Unified diff showing the changes made" ,
2929 )
30- new_content : Optional [ str ] = Field (
30+ new_content : str | None = Field (
3131 default = None ,
3232 description = "New content with line numbers" ,
3333 )
34- line_count : Optional [ int ] = Field (
34+ line_count : int | None = Field (
3535 default = None ,
3636 description = "Total number of lines in file" ,
3737 )
@@ -135,7 +135,7 @@ def apply_relace_edit(api_key: str, initial_code: str, edit_snippet: str, stream
135135 raise Exception (msg )
136136
137137
138- def relace_edit (codebase : Codebase , filepath : str , edit_snippet : str , api_key : Optional [ str ] = None ) -> RelaceEditObservation :
138+ def relace_edit (codebase : Codebase , filepath : str , edit_snippet : str , api_key : str | None = None ) -> RelaceEditObservation :
139139 """Edit a file using the Relace Instant Apply API.
140140
141141 Args:
@@ -176,6 +176,8 @@ def relace_edit(codebase: Codebase, filepath: str, edit_snippet: str, api_key: O
176176 # Apply the edit using Relace API
177177 try :
178178 merged_code = apply_relace_edit (api_key , original_content , edit_snippet )
179+ if original_content .endswith ("\n " ) and not merged_code .endswith ("\n " ):
180+ merged_code += "\n "
179181 except Exception as e :
180182 return RelaceEditObservation (
181183 status = "error" ,
0 commit comments