-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslide_patch.py
More file actions
826 lines (683 loc) · 26.3 KB
/
slide_patch.py
File metadata and controls
826 lines (683 loc) · 26.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
"""Slide patching tool for applying patches to slide presentations."""
from pathlib import Path
from enum import Enum
import textwrap
from typing import Optional, Any
from pydantic import BaseModel, Field
from datetime import datetime
from backend.src.tool_server.core.workspace import FileSystemValidationError
from backend.src.tool_server.tools.base import (
ToolResult,
ToolConfirmationDetails,
)
from .base import SlideToolBase
# Name
NAME = "slide_apply_patch"
DISPLAY_NAME = "Apply Slide Patch"
DEFINITION = textwrap.dedent(
r"""
start: begin_patch hunk+ end_patch
begin_patch: "*** Begin Slide Patch" LF
end_patch: "*** End Slide Patch" LF?
hunk: add_hunk | update_hunk
add_hunk: "*** Add Slide: " presentation_name "/" slide_number LF slide_metadata? add_line+
update_hunk: "*** Update Slide: " presentation_name "/" slide_number LF slide_metadata? change?
presentation_name: /([^/]+)/
slide_number: /(\d+)/
slide_metadata: "*** Metadata: " title_line description_line type_line?
title_line: "Title: " /(.*)/ LF
description_line: "Description: " /(.*)/ LF
type_line: "Type: " /(.*)/ LF
add_line: "+" /(.*)/ LF -> line
change: (change_context | change_line)+ eof_line?
change_context: ("@@" | "@@ " /(.+)/) LF
change_line: ("+" | "-" | " ") /(.*)/ LF
eof_line: "*** End of Slide" LF
%import common.LF
"""
)
FORMAT = {"type": "custom", "syntax": "lark", "definition": DEFINITION}
# Tool description
DESCRIPTION = """Use the `slide_apply_patch` tool to create or edit slides in presentations.
Your patch language follows this format:
*** Begin Slide Patch
[ one or more slide operations ]
*** End Slide Patch
Within that envelope, you can perform three types of operations:
*** Add Slide: <presentation_name>/<slide_number> - create a new slide
*** Update Slide: <presentation_name>/<slide_number> - patch an existing slide
For Add and Update operations, you can optionally include metadata:
*** Metadata:
Title: <slide title>
Description: <slide description>
Type: <slide type (cover, content, chart, conclusion, etc.)>
Examples:
1. Creating a new slide:
*** Begin Slide Patch
*** Add Slide: my_presentation/1
*** Metadata:
Title: Introduction
Description: Opening slide with title and agenda
Type: cover
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Introduction</title>
+</head>
+<body>
+ <h1>Welcome</h1>
+</body>
+</html>
*** End Slide Patch
2. Updating an existing slide:
*** Begin Slide Patch
*** Update Slide: my_presentation/2
*** Metadata:
Title: Updated Title
Description: Modified slide content
@@ <h1 class="title">
- Old Title
+ New Title
*** End Slide Patch
3. Multiple operations:
*** Begin Slide Patch
*** Update Slide: workshop/1
@@ <title>
-Workshop Introduction
+Advanced Workshop Introduction
*** Add Slide: workshop/5
*** Metadata:
Title: Conclusion
Description: Final slide with summary
Type: conclusion
+<!DOCTYPE html>
+<html>
+<body>
+ <h1>Thank You!</h1>
+</body>
+</html>
*** End Slide Patch
Important notes:
- Presentation names and slide numbers are specified as: presentation_name/slide_number
- Slide numbers are 1-based (slide 1, not slide 0)
- When updating slides, use context lines (with spaces) to uniquely identify the location
- For HTML content, ensure proper formatting and structure
- All local file paths in HTML must be absolute paths accessible by the agent
- The tool automatically updates metadata.json timestamps
"""
SHORT_DESCRIPTION = DESCRIPTION
# Input schema
INPUT_SCHEMA = {
"type": "object",
"properties": {
"input": {
"type": "string",
"description": "The slide_apply_patch command that you wish to execute.",
}
},
"required": ["input"],
}
# Core classes
class ActionType(str, Enum):
ADD = "add"
UPDATE = "update"
class SlideMetadata(BaseModel):
title: Optional[str] = None
description: Optional[str] = None
type: Optional[str] = None
class SlideChange(BaseModel):
type: ActionType
presentation_name: str
slide_number: int
old_content: Optional[str] = None
new_content: Optional[str] = None
metadata: Optional[SlideMetadata] = None
class SlideCommit(BaseModel):
changes: list[SlideChange] = Field(default_factory=list)
class Chunk(BaseModel):
orig_index: int = -1
del_lines: list[str] = Field(default_factory=list)
ins_lines: list[str] = Field(default_factory=list)
class SlidePatchAction(BaseModel):
type: ActionType
presentation_name: str
slide_number: int
new_content: Optional[str] = None
chunks: list[Chunk] = Field(default_factory=list)
metadata: Optional[SlideMetadata] = None
class SlidePatch(BaseModel):
actions: list[SlidePatchAction] = Field(default_factory=list)
class SlideParser(BaseModel):
lines: list[str] = Field(default_factory=list)
index: int = 0
patch: SlidePatch = Field(default_factory=SlidePatch)
fuzz: int = 0
current_slides: dict[tuple[str, int], str] = Field(default_factory=dict)
def is_done(self, prefixes: Optional[tuple[str, ...]] = None) -> bool:
if self.index >= len(self.lines):
return True
if prefixes and self.lines[self.index].startswith(prefixes):
return True
return False
def startswith(self, prefix: str) -> bool:
if self.index >= len(self.lines):
return False
return self.lines[self.index].startswith(prefix)
def read_str(self, prefix: str = "", return_everything: bool = False) -> str:
if self.index >= len(self.lines):
return ""
if self.lines[self.index].startswith(prefix):
if return_everything:
text = self.lines[self.index]
else:
text = self.lines[self.index][len(prefix) :]
self.index += 1
return text
return ""
def parse_metadata(self) -> Optional[SlideMetadata]:
"""Parse slide metadata if present."""
if not self.startswith("*** Metadata:"):
return None
self.index += 1 # Skip metadata header
metadata = SlideMetadata()
# Parse Title
title_line = self.read_str("Title: ")
if title_line:
metadata.title = title_line.strip()
# Parse Description
desc_line = self.read_str("Description: ")
if desc_line:
metadata.description = desc_line.strip()
# Parse Type (optional)
type_line = self.read_str("Type: ")
if type_line:
metadata.type = type_line.strip()
return metadata
def parse(self):
while not self.is_done(("*** End Slide Patch",)):
# Skip empty lines
if self.index < len(self.lines) and self.lines[self.index].strip() == "":
self.index += 1
continue
# Parse Update Slide
line = self.read_str("*** Update Slide: ")
if line:
presentation_name, slide_number = self._parse_slide_path(line)
metadata = self.parse_metadata()
key = (presentation_name, slide_number)
if key not in self.current_slides:
raise DiffError(
f"Update Slide Error: Slide {presentation_name}/{slide_number} not found"
)
text = self.current_slides[key]
action = self.parse_update_slide(text)
action.presentation_name = presentation_name
action.slide_number = slide_number
action.metadata = metadata
self.patch.actions.append(action)
continue
# Parse Add Slide
line = self.read_str("*** Add Slide: ")
if line:
presentation_name, slide_number = self._parse_slide_path(line)
metadata = self.parse_metadata()
action = self.parse_add_slide()
action.presentation_name = presentation_name
action.slide_number = slide_number
action.metadata = metadata
self.patch.actions.append(action)
continue
raise DiffError(f"Unknown Line: {self.lines[self.index]}")
if not self.startswith("*** End Slide Patch"):
raise DiffError("Missing End Slide Patch")
self.index += 1
def _parse_slide_path(self, path_str: str) -> tuple[str, int]:
"""Parse presentation_name/slide_number format."""
parts = path_str.strip().split("/")
if len(parts) != 2:
raise DiffError(f"Invalid slide path format: {path_str}")
try:
return parts[0], int(parts[1])
except ValueError:
raise DiffError(f"Invalid slide number: {parts[1]}")
def parse_update_slide(self, text: str) -> SlidePatchAction:
"""Parse update slide action similar to parse_update_file."""
action = SlidePatchAction(
type=ActionType.UPDATE, presentation_name="", slide_number=0
)
lines = text.split("\n")
index = 0
while not self.is_done(
(
"*** End Slide Patch",
"*** Update Slide:",
"*** Add Slide:",
"*** End of Slide",
)
):
def_str = self.read_str("@@ ")
section_str = ""
if not def_str:
if self.index < len(self.lines) and self.lines[self.index] == "@@":
section_str = self.lines[self.index]
self.index += 1
if not (def_str or section_str or index == 0):
raise DiffError(f"Invalid Line:\n{self.lines[self.index]}")
if def_str.strip():
# Try to find the context line
for i, s in enumerate(lines[index:], index):
if s == def_str or s.strip() == def_str.strip():
index = i + 1
if s.strip() == def_str.strip() and s != def_str:
self.fuzz += 1
break
next_chunk_context, chunks, end_patch_index, eof = self.peek_next_section()
next_chunk_text = "\n".join(next_chunk_context)
new_index, fuzz = find_context(lines, next_chunk_context, index, eof)
if new_index == -1:
if eof:
raise DiffError(f"Invalid EOF Context {index}:\n{next_chunk_text}")
else:
raise DiffError(f"Invalid Context {index}:\n{next_chunk_text}")
self.fuzz += fuzz
for ch in chunks:
ch.orig_index += new_index
action.chunks.append(ch)
index = new_index + len(next_chunk_context)
self.index = end_patch_index
return action
def parse_add_slide(self) -> SlidePatchAction:
"""Parse add slide action."""
lines = []
while not self.is_done(
(
"*** End Slide Patch",
"*** Update Slide:",
"*** Add Slide:",
)
):
s = self.read_str()
# Skip empty lines between sections
if s.strip() == "":
continue
if not s.startswith("+"):
raise DiffError(f"Invalid Add Slide Line: {s}")
s = s[1:]
lines.append(s)
return SlidePatchAction(
type=ActionType.ADD,
presentation_name="", # Will be set by parse()
slide_number=0, # Will be set by parse()
new_content="\n".join(lines),
)
def peek_next_section(self) -> tuple[list[str], list[Chunk], int, bool]:
"""Peek at the next section for context matching."""
old: list[str] = []
del_lines: list[str] = []
ins_lines: list[str] = []
chunks: list[Chunk] = []
mode = "keep"
orig_index = self.index
while self.index < len(self.lines):
s = self.lines[self.index]
if s.startswith(
(
"@@",
"*** End Slide Patch",
"*** Update Slide:",
"*** Add Slide:",
"*** End of Slide",
)
):
break
if s == "***":
break
elif s.startswith("***"):
raise DiffError(f"Invalid Line: {s}")
self.index += 1
last_mode = mode
if s == "":
s = " "
if s[0] == "+":
mode = "add"
elif s[0] == "-":
mode = "delete"
elif s[0] == " ":
mode = "keep"
else:
raise DiffError(f"Invalid Line: {s}")
s = s[1:]
if mode == "keep" and last_mode != mode:
if ins_lines or del_lines:
chunks.append(
Chunk(
orig_index=len(old) - len(del_lines),
del_lines=del_lines,
ins_lines=ins_lines,
)
)
del_lines = []
ins_lines = []
if mode == "delete":
del_lines.append(s)
old.append(s)
elif mode == "add":
ins_lines.append(s)
elif mode == "keep":
old.append(s)
if ins_lines or del_lines:
chunks.append(
Chunk(
orig_index=len(old) - len(del_lines),
del_lines=del_lines,
ins_lines=ins_lines,
)
)
eof = False
if (
self.index < len(self.lines)
and self.lines[self.index] == "*** End of Slide"
):
self.index += 1
eof = True
if self.index == orig_index:
raise DiffError(
f"Nothing in this section - {self.index=} {self.lines[self.index]}"
)
return old, chunks, self.index, eof
class DiffError(ValueError):
pass
# Utility functions
def find_context_core(
lines: list[str], context: list[str], start: int
) -> tuple[int, int]:
if not context:
return start, 0
# Prefer identical match
for i in range(start, len(lines)):
if lines[i : i + len(context)] == context:
return i, 0
# RStrip is ok
for i in range(start, len(lines)):
if [s.rstrip() for s in lines[i : i + len(context)]] == [
s.rstrip() for s in context
]:
return i, 1
# Strip is ok too
for i in range(start, len(lines)):
if [s.strip() for s in lines[i : i + len(context)]] == [
s.strip() for s in context
]:
return i, 100
return -1, 0
def find_context(
lines: list[str], context: list[str], start: int, eof: bool
) -> tuple[int, int]:
if eof:
new_index, fuzz = find_context_core(lines, context, len(lines) - len(context))
if new_index != -1:
return new_index, fuzz
new_index, fuzz = find_context_core(lines, context, start)
return new_index, fuzz + 10000
return find_context_core(lines, context, start)
def _get_updated_content(text: str, action: SlidePatchAction) -> str:
"""Apply patches to slide content."""
assert action.type == ActionType.UPDATE
orig_lines = text.split("\n")
dest_lines = []
orig_index = 0
for chunk in action.chunks:
# Process unchanged lines before the chunk
if chunk.orig_index > len(orig_lines):
raise DiffError(
f"_get_updated_content: chunk.orig_index {chunk.orig_index} > len(lines) {len(orig_lines)}"
)
if orig_index > chunk.orig_index:
raise DiffError(
f"_get_updated_content: orig_index {orig_index} > chunk.orig_index {chunk.orig_index}"
)
dest_lines.extend(orig_lines[orig_index : chunk.orig_index])
orig_index = chunk.orig_index
# Process inserted lines
if chunk.ins_lines:
dest_lines.extend(chunk.ins_lines)
orig_index += len(chunk.del_lines)
# Add remaining lines
dest_lines.extend(orig_lines[orig_index:])
return "\n".join(dest_lines)
def text_to_slide_patch(
text: str, current_slides: dict[tuple[str, int], str]
) -> tuple[SlidePatch, int]:
"""Parse patch text into SlidePatch object."""
lines = text.strip().split("\n")
if (
len(lines) < 2
or not lines[0].startswith("*** Begin Slide Patch")
or lines[-1] != "*** End Slide Patch"
):
raise DiffError("Invalid patch text")
parser = SlideParser(
current_slides=current_slides,
lines=lines,
index=1,
)
parser.parse()
return parser.patch, parser.fuzz
def identify_slides_needed(text: str) -> list[tuple[str, int]]:
"""Identify which slides need to be loaded for the patch."""
lines = text.strip().split("\n")
result = set()
for line in lines:
if line.startswith("*** Update Slide: "):
path_str = line.split(": ", 1)[1]
parts = path_str.strip().split("/")
if len(parts) == 2:
try:
result.add((parts[0], int(parts[1])))
except ValueError:
pass
return list(result)
def patch_to_commit(patch: SlidePatch, orig: dict[tuple[str, int], str]) -> SlideCommit:
"""Convert patch to commit."""
commit = SlideCommit()
for action in patch.actions:
key = (action.presentation_name, action.slide_number)
if action.type == ActionType.ADD:
commit.changes.append(
SlideChange(
type=ActionType.ADD,
presentation_name=action.presentation_name,
slide_number=action.slide_number,
new_content=action.new_content,
metadata=action.metadata,
)
)
elif action.type == ActionType.UPDATE:
new_content = _get_updated_content(orig[key], action)
commit.changes.append(
SlideChange(
type=ActionType.UPDATE,
presentation_name=action.presentation_name,
slide_number=action.slide_number,
old_content=orig[key],
new_content=new_content,
metadata=action.metadata,
)
)
return commit
class SlideEditToolResultContent(BaseModel):
"""Content structure for slide edit results."""
old_content: str
new_content: str
filepath: str
class SlideApplyPatchTool(SlideToolBase):
"""Tool for applying patches to slides using a unified diff format."""
name = NAME
display_name = DISPLAY_NAME
description = DESCRIPTION
input_schema = INPUT_SCHEMA
metadata = {"format": FORMAT}
read_only = False
def should_confirm_execute(
self, tool_input: dict[str, Any]
) -> ToolConfirmationDetails | bool:
"""Determine if patch execution should be confirmed."""
patch_input = tool_input.get("input", "")
return ToolConfirmationDetails(
type="edit", message=f"Apply the following slide patch:\n{patch_input}"
)
def _load_slide(self, presentation_name: str, slide_number: int) -> str:
"""Load slide content."""
presentation_path = self._get_presentation_path(presentation_name)
slide_filename = self._get_slide_filename(slide_number)
# Get the workspace root and build the full path properly
workspace_root = Path(self.workspace_manager.workspace_path)
full_presentation_path = workspace_root / presentation_path
slide_path = full_presentation_path / slide_filename
if not slide_path.exists():
raise DiffError(f"Slide does not exist: {presentation_name}/{slide_number}")
try:
return slide_path.read_text(encoding="utf-8")
except Exception as e:
raise DiffError(
f"Failed to read slide {presentation_name}/{slide_number}: {str(e)}"
)
def _write_slide(
self,
presentation_name: str,
slide_number: int,
content: str,
metadata: Optional[SlideMetadata] = None,
) -> None:
"""Write slide content and update metadata."""
presentation_path = self._get_presentation_path(presentation_name)
# Get the workspace root and build the full path properly
workspace_root = Path(self.workspace_manager.workspace_path)
full_presentation_path = workspace_root / presentation_path
self.workspace_manager.validate_path(str(full_presentation_path))
# Create presentation directory if needed
full_presentation_path.mkdir(parents=True, exist_ok=True)
# Write slide file
slide_filename = self._get_slide_filename(slide_number)
slide_path = full_presentation_path / slide_filename
slide_path.write_text(content, encoding="utf-8")
# Update metadata
meta = self._load_metadata(full_presentation_path)
# Update presentation name if empty
if not meta["presentation"]["name"]:
meta["presentation"]["name"] = presentation_name
meta["presentation"]["title"] = presentation_name
# Update slide metadata
if metadata:
meta = self._update_slide_in_metadata(
metadata=meta,
slide_number=slide_number,
title=metadata.title or f"Slide {slide_number}",
description=metadata.description or "",
slide_type=metadata.type or "content",
)
else:
# Just update timestamp for existing slide
slide_meta = self._find_slide_in_metadata(meta, slide_number)
if slide_meta:
slide_meta["updated_at"] = datetime.now().isoformat()
self._save_metadata(full_presentation_path, meta)
async def execute(self, tool_input: dict[str, Any]) -> ToolResult:
"""Execute the slide_apply_patch command."""
patch_input = tool_input.get("input")
if not patch_input:
return ToolResult(
llm_content="ERROR: 'input' parameter is required", is_error=True
)
try:
# Identify slides needed for the patch
slides_needed = identify_slides_needed(patch_input)
# Load current slide contents
current_slides = {}
for presentation_name, slide_number in slides_needed:
try:
content = self._load_slide(presentation_name, slide_number)
current_slides[(presentation_name, slide_number)] = content
except DiffError:
# Slide doesn't exist, skip it for updates
pass
# Parse the patch
patch, fuzz = text_to_slide_patch(patch_input, current_slides)
# Convert to commit
commit = patch_to_commit(patch, current_slides)
# Apply the commit
user_display_content = []
messages = []
for change in commit.changes:
key = f"{change.presentation_name}/{change.slide_number}"
if change.type == ActionType.ADD:
self._write_slide(
change.presentation_name,
change.slide_number,
change.new_content,
change.metadata,
)
messages.append(f"Added slide {key}")
# Add to display content
presentation_path = self._get_presentation_path(
change.presentation_name
)
slide_filename = self._get_slide_filename(change.slide_number)
slide_path = presentation_path / slide_filename
workspace_filepath = f"/workspace/{slide_path}"
user_display_content.append(
SlideEditToolResultContent(
old_content="",
new_content=change.new_content or "",
filepath=workspace_filepath,
).model_dump()
)
elif change.type == ActionType.UPDATE:
self._write_slide(
change.presentation_name,
change.slide_number,
change.new_content,
change.metadata,
)
messages.append(f"Updated slide {key}")
# Add to display content
presentation_path = self._get_presentation_path(
change.presentation_name
)
slide_filename = self._get_slide_filename(change.slide_number)
slide_path = presentation_path / slide_filename
workspace_filepath = f"/workspace/{slide_path}"
user_display_content.append(
SlideEditToolResultContent(
old_content=change.old_content or "",
new_content=change.new_content or "",
filepath=workspace_filepath,
).model_dump()
)
result_msg = f"Slide patch applied successfully! (fuzz: {fuzz})\n"
result_msg += "\n".join(messages)
return ToolResult(
llm_content=result_msg,
user_display_content=(
user_display_content if user_display_content else None
),
is_error=False,
)
except DiffError as e:
return ToolResult(llm_content=f"ERROR: {str(e)}", is_error=True)
except FileSystemValidationError as e:
return ToolResult(llm_content=f"ERROR: {str(e)}", is_error=True)
except Exception as e:
return ToolResult(
llm_content=f"ERROR: Unexpected error: {str(e)}", is_error=True
)
async def execute_mcp_wrapper(
self,
input: str,
):
"""MCP wrapper for the slide_apply_patch tool."""
tool_input = {
"input": input,
}
return await self._mcp_wrapper(tool_input=tool_input)