(self, args: Dict[str, Any])
| 96 | ) |
| 97 | |
| 98 | def _create_file(self, args: Dict[str, Any]) -> ToolExecutionResult: |
| 99 | path = ensure_str(args.get("path") or self.file_state.path or "index.html") |
| 100 | content = ensure_str(args.get("content")) |
| 101 | if not content: |
| 102 | return ToolExecutionResult( |
| 103 | ok=False, |
| 104 | result={"error": "create_file requires non-empty content"}, |
| 105 | summary={"error": "Missing content"}, |
| 106 | ) |
| 107 | |
| 108 | extracted = extract_html_content(content) |
| 109 | self.file_state.path = path |
| 110 | self.file_state.content = extracted or content |
| 111 | |
| 112 | summary = { |
| 113 | "path": self.file_state.path, |
| 114 | "contentLength": len(self.file_state.content), |
| 115 | "preview": summarize_text(self.file_state.content, 320), |
| 116 | } |
| 117 | result = { |
| 118 | "content": f"Successfully created file at {self.file_state.path}.", |
| 119 | "details": { |
| 120 | "path": self.file_state.path, |
| 121 | "contentLength": len(self.file_state.content), |
| 122 | }, |
| 123 | } |
| 124 | return ToolExecutionResult( |
| 125 | ok=True, |
| 126 | result=result, |
| 127 | summary=summary, |
| 128 | updated_content=self.file_state.content, |
| 129 | ) |
| 130 | |
| 131 | @staticmethod |
| 132 | def _generate_diff(old_content: str, new_content: str, path: str) -> Dict[str, Any]: |
no test coverage detected