Skip to content

Commit c054e45

Browse files
committed
fix: test relace artifacts
1 parent 495893b commit c054e45

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

src/codegen/extensions/langchain/tools.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,9 +1054,9 @@ class RelaceEditTool(BaseTool):
10541054
def __init__(self, codebase: Codebase) -> None:
10551055
super().__init__(codebase=codebase)
10561056

1057-
def _run(self, filepath: str, edit_snippet: str) -> str:
1057+
def _run(self, filepath: str, edit_snippet: str, tool_call_id: str) -> ToolMessage:
10581058
result = relace_edit(self.codebase, filepath, edit_snippet)
1059-
return result.render()
1059+
return result.render(tool_call_id=tool_call_id)
10601060

10611061

10621062
class ReflectionInput(BaseModel):

src/codegen/extensions/tools/relace_edit.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
import requests
88
from pydantic import Field
99

10+
from codegen.extensions.tools.tool_output_types import RelaceEditArtifacts
1011
from codegen.sdk.core.codebase import Codebase
1112

1213
from .observation import Observation
1314
from .view_file import add_line_numbers
15+
from langchain_core.messages import ToolMessage
1416

1517

1618
class RelaceEditObservation(Observation):
@@ -35,6 +37,34 @@ class RelaceEditObservation(Observation):
3537
str_template: ClassVar[str] = "Edited file {filepath} using Relace Instant Apply"
3638

3739

40+
def render(self, tool_call_id: str) -> ToolMessage:
41+
"""Render the relace edit observation as a ToolMessage."""
42+
43+
artifacts: RelaceEditArtifacts = {
44+
"filepath": self.filepath,
45+
"diff": self.diff,
46+
"new_content": self.new_content,
47+
"line_count": self.line_count,
48+
"error": self.error,
49+
}
50+
51+
if self.status == "error":
52+
return ToolMessage(
53+
content=f"[ERROR EDITING FILE]: {self.filepath}: {self.error}",
54+
status=self.status,
55+
name="relace_edit",
56+
artifact=artifacts,
57+
tool_call_id=tool_call_id,
58+
)
59+
60+
return ToolMessage(
61+
content=self.render_as_string(),
62+
status=self.status,
63+
tool_call_id=tool_call_id,
64+
artifact=artifacts,
65+
)
66+
67+
3868
def generate_diff(original: str, modified: str) -> str:
3969
"""Generate a unified diff between two strings.
4070

src/codegen/extensions/tools/tool_output_types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,17 @@ class SemanticEditArtifacts(TypedDict, total=False):
8989
new_content: Optional[str] # New content of the file after edits
9090
line_count: Optional[int] # Total number of lines in the edited file
9191
error: Optional[str] # Error message (only present on error)
92+
93+
94+
class RelaceEditArtifacts(TypedDict, total=False):
95+
"""Artifacts for relace edit operations.
96+
97+
All fields are optional to support both success and error cases.
98+
Includes metadata useful for UI diff view and file content.
99+
"""
100+
101+
filepath: str # Path to the edited file
102+
diff: Optional[str] # Unified diff of changes made to the file
103+
new_content: Optional[str] # New content of the file after edits
104+
line_count: Optional[int] # Total number of lines in the edited file
105+
error: Optional[str] # Error message (only present on error)

0 commit comments

Comments
 (0)