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
|
from abc import ABC, abstractmethod
from typing import Any, Callable, Dict, List, Optional, Union
from fastapi import WebSocket
from ..models.filesystem import RangeInFile, RangeInFileWithContents
from ..models.filesystem_edit import EditDiff, FileEdit, FileSystemEdit
class AbstractIdeProtocolServer(ABC):
websocket: WebSocket
session_id: Union[str, None]
ide_info: Optional[Dict] = None
@abstractmethod
async def handle_json(self, data: Any):
"""Handle a json message"""
@abstractmethod
def showSuggestion(self, file_edit: FileEdit):
"""Show a suggestion to the user"""
@abstractmethod
async def setFileOpen(self, filepath: str, open: bool = True):
"""Set whether a file is open"""
@abstractmethod
async def showMessage(self, message: str):
"""Show a message to the user"""
@abstractmethod
async def showVirtualFile(self, name: str, contents: str):
"""Show a virtual file"""
@abstractmethod
async def setSuggestionsLocked(self, filepath: str, locked: bool = True):
"""Set whether suggestions are locked"""
@abstractmethod
async def getSessionId(self):
"""Get a new session ID"""
@abstractmethod
async def showSuggestionsAndWait(self, suggestions: List[FileEdit]) -> bool:
"""Show suggestions to the user and wait for a response"""
@abstractmethod
def onAcceptRejectSuggestion(self, accepted: bool):
"""Called when the user accepts or rejects a suggestion"""
@abstractmethod
def onFileSystemUpdate(self, update: FileSystemEdit):
"""Called when a file system update is received"""
@abstractmethod
def onCloseGUI(self, session_id: str):
"""Called when a GUI is closed"""
@abstractmethod
def onOpenGUIRequest(self):
"""Called when a GUI is requested to be opened"""
@abstractmethod
async def getOpenFiles(self) -> List[str]:
"""Get a list of open files"""
@abstractmethod
async def getVisibleFiles(self) -> List[str]:
"""Get a list of visible files"""
@abstractmethod
async def getHighlightedCode(self) -> List[RangeInFile]:
"""Get a list of highlighted code"""
@abstractmethod
async def readFile(self, filepath: str) -> str:
"""Read a file"""
@abstractmethod
async def readRangeInFile(self, range_in_file: RangeInFile) -> str:
"""Read a range in a file"""
@abstractmethod
async def editFile(self, edit: FileEdit):
"""Edit a file"""
@abstractmethod
async def applyFileSystemEdit(self, edit: FileSystemEdit) -> EditDiff:
"""Apply a file edit"""
@abstractmethod
async def saveFile(self, filepath: str):
"""Save a file"""
@abstractmethod
async def getUserSecret(self, key: str):
"""Get a user secret"""
@abstractmethod
async def highlightCode(self, range_in_file: RangeInFile, color: str):
"""Highlight code"""
@abstractmethod
async def runCommand(self, command: str) -> str:
"""Run a command"""
@abstractmethod
def onHighlightedCodeUpdate(
self,
range_in_files: List[RangeInFileWithContents],
edit: Optional[bool] = False,
):
"""Called when highlighted code is updated"""
@abstractmethod
def onDeleteAtIndex(self, index: int):
"""Called when a step is deleted at a given index"""
@abstractmethod
async def showDiff(self, filepath: str, replacement: str, step_index: int):
"""Show a diff"""
@abstractmethod
def subscribeToFilesCreated(self, callback: Callable[[List[str]], None]):
"""Subscribe to files created event"""
@abstractmethod
def subscribeToFilesDeleted(self, callback: Callable[[List[str]], None]):
"""Subscribe to files deleted event"""
@abstractmethod
def subscribeToFilesRenamed(self, callback: Callable[[List[str], List[str]], None]):
"""Subscribe to files renamed event"""
@abstractmethod
def subscribeToFileSaved(self, callback: Callable[[str, str], None]):
"""Subscribe to file saved event"""
@abstractmethod
def onFilesCreated(self, filepaths: List[str]):
"""Called when files are created"""
@abstractmethod
def onFilesDeleted(self, filepaths: List[str]):
"""Called when files are deleted"""
@abstractmethod
def onFilesRenamed(self, old_filepaths: List[str], new_filepaths: List[str]):
"""Called when files are renamed"""
@abstractmethod
def onFileSaved(self, filepath: str, contents: str):
"""Called when a file is saved"""
@abstractmethod
async def listDirectoryContents(
self, directory: str, recursive: bool = False
) -> List[str]:
"""List directory contents"""
@abstractmethod
async def fileExists(self, filepath: str) -> str:
"""Check if a file exists"""
@abstractmethod
async def getTerminalContents(self, commands: int = -1) -> str:
"""Get the terminal contents"""
workspace_directory: str
unique_id: str
|