2
2
3
3
import difflib
4
4
import os
5
- from typing import TYPE_CHECKING , ClassVar , Optional
5
+ from typing import TYPE_CHECKING , ClassVar
6
6
7
7
import requests
8
8
from langchain_core .messages import ToolMessage
@@ -23,15 +23,15 @@ class RelaceEditObservation(Observation):
23
23
filepath : str = Field (
24
24
description = "Path to the edited file" ,
25
25
)
26
- diff : Optional [ str ] = Field (
26
+ diff : str | None = Field (
27
27
default = None ,
28
28
description = "Unified diff showing the changes made" ,
29
29
)
30
- new_content : Optional [ str ] = Field (
30
+ new_content : str | None = Field (
31
31
default = None ,
32
32
description = "New content with line numbers" ,
33
33
)
34
- line_count : Optional [ int ] = Field (
34
+ line_count : int | None = Field (
35
35
default = None ,
36
36
description = "Total number of lines in file" ,
37
37
)
@@ -135,7 +135,7 @@ def apply_relace_edit(api_key: str, initial_code: str, edit_snippet: str, stream
135
135
raise Exception (msg )
136
136
137
137
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 :
139
139
"""Edit a file using the Relace Instant Apply API.
140
140
141
141
Args:
@@ -176,6 +176,8 @@ def relace_edit(codebase: Codebase, filepath: str, edit_snippet: str, api_key: O
176
176
# Apply the edit using Relace API
177
177
try :
178
178
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 "
179
181
except Exception as e :
180
182
return RelaceEditObservation (
181
183
status = "error" ,
0 commit comments