mrmd-python 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
mrmd_python/types.py ADDED
@@ -0,0 +1,245 @@
1
+ """
2
+ MRP Type Definitions
3
+
4
+ Matches the MRMD Runtime Protocol specification.
5
+ """
6
+
7
+ from dataclasses import dataclass, field
8
+ from typing import Any, Literal
9
+
10
+
11
+ # =============================================================================
12
+ # Capabilities
13
+ # =============================================================================
14
+
15
+
16
+ @dataclass
17
+ class CapabilityFeatures:
18
+ execute: bool = True
19
+ executeStream: bool = True
20
+ interrupt: bool = True
21
+ complete: bool = True
22
+ inspect: bool = True
23
+ hover: bool = True
24
+ variables: bool = True
25
+ variableExpand: bool = True
26
+ reset: bool = True
27
+ isComplete: bool = True
28
+ format: bool = False
29
+ assets: bool = True
30
+
31
+
32
+ @dataclass
33
+ class Environment:
34
+ cwd: str = ""
35
+ executable: str = ""
36
+ virtualenv: str | None = None
37
+
38
+
39
+ @dataclass
40
+ class Capabilities:
41
+ runtime: str = "mrmd-python"
42
+ version: str = ""
43
+ languages: list[str] = field(default_factory=lambda: ["python", "py", "python3"])
44
+ features: CapabilityFeatures = field(default_factory=CapabilityFeatures)
45
+ defaultSession: str = "default"
46
+ maxSessions: int = 10
47
+ environment: Environment = field(default_factory=Environment)
48
+ lspFallback: str | None = None
49
+
50
+
51
+ # =============================================================================
52
+ # Sessions
53
+ # =============================================================================
54
+
55
+
56
+ @dataclass
57
+ class Session:
58
+ id: str
59
+ language: str = "python"
60
+ created: str = ""
61
+ lastActivity: str = ""
62
+ executionCount: int = 0
63
+ variableCount: int = 0
64
+
65
+
66
+ # =============================================================================
67
+ # Execution
68
+ # =============================================================================
69
+
70
+
71
+ @dataclass
72
+ class ExecuteError:
73
+ type: str
74
+ message: str
75
+ traceback: list[str] = field(default_factory=list)
76
+ line: int | None = None
77
+ column: int | None = None
78
+
79
+
80
+ @dataclass
81
+ class DisplayData:
82
+ data: dict[str, str] = field(default_factory=dict)
83
+ metadata: dict[str, Any] = field(default_factory=dict)
84
+
85
+
86
+ @dataclass
87
+ class Asset:
88
+ path: str
89
+ url: str
90
+ mimeType: str
91
+ assetType: Literal["image", "html", "svg", "data", "file"]
92
+ size: int | None = None
93
+
94
+
95
+ @dataclass
96
+ class ExecuteResult:
97
+ success: bool = True
98
+ stdout: str = ""
99
+ stderr: str = ""
100
+ result: str | None = None
101
+ error: ExecuteError | None = None
102
+ displayData: list[DisplayData] = field(default_factory=list)
103
+ assets: list[Asset] = field(default_factory=list)
104
+ executionCount: int = 0
105
+ duration: int | None = None # milliseconds
106
+ imports: list[str] = field(default_factory=list)
107
+
108
+
109
+ # =============================================================================
110
+ # Completion
111
+ # =============================================================================
112
+
113
+
114
+ @dataclass
115
+ class CompletionItem:
116
+ label: str
117
+ insertText: str | None = None
118
+ kind: Literal[
119
+ "variable",
120
+ "function",
121
+ "method",
122
+ "property",
123
+ "class",
124
+ "module",
125
+ "keyword",
126
+ "constant",
127
+ "field",
128
+ "value",
129
+ ] = "variable"
130
+ detail: str | None = None
131
+ documentation: str | None = None
132
+ valuePreview: str | None = None
133
+ type: str | None = None
134
+
135
+
136
+ @dataclass
137
+ class CompleteResult:
138
+ matches: list[CompletionItem] = field(default_factory=list)
139
+ cursorStart: int = 0
140
+ cursorEnd: int = 0
141
+ source: Literal["runtime", "lsp", "static"] = "runtime"
142
+
143
+
144
+ # =============================================================================
145
+ # Inspection
146
+ # =============================================================================
147
+
148
+
149
+ @dataclass
150
+ class InspectResult:
151
+ found: bool = False
152
+ source: Literal["runtime", "lsp", "static"] = "runtime"
153
+ name: str | None = None
154
+ kind: Literal[
155
+ "variable", "function", "class", "module", "method", "property"
156
+ ] | None = None
157
+ type: str | None = None
158
+ signature: str | None = None
159
+ docstring: str | None = None
160
+ sourceCode: str | None = None
161
+ file: str | None = None
162
+ line: int | None = None
163
+ value: str | None = None
164
+ children: int | None = None
165
+
166
+
167
+ @dataclass
168
+ class HoverResult:
169
+ found: bool = False
170
+ name: str | None = None
171
+ type: str | None = None
172
+ value: str | None = None
173
+ signature: str | None = None
174
+
175
+
176
+ # =============================================================================
177
+ # Variables
178
+ # =============================================================================
179
+
180
+
181
+ @dataclass
182
+ class Variable:
183
+ name: str
184
+ type: str
185
+ value: str
186
+ size: str | None = None
187
+ expandable: bool = False
188
+ shape: list[int] | None = None
189
+ dtype: str | None = None
190
+ length: int | None = None
191
+ keys: list[str] | None = None
192
+
193
+
194
+ @dataclass
195
+ class VariablesResult:
196
+ variables: list[Variable] = field(default_factory=list)
197
+ count: int = 0
198
+ truncated: bool = False
199
+
200
+
201
+ @dataclass
202
+ class VariableDetail(Variable):
203
+ fullValue: str | None = None
204
+ children: list[Variable] | None = None
205
+ methods: list[str] | None = None
206
+ attributes: list[str] | None = None
207
+
208
+
209
+ # =============================================================================
210
+ # Code Analysis
211
+ # =============================================================================
212
+
213
+
214
+ @dataclass
215
+ class IsCompleteResult:
216
+ status: Literal["complete", "incomplete", "invalid", "unknown"] = "unknown"
217
+ indent: str = ""
218
+
219
+
220
+ @dataclass
221
+ class FormatResult:
222
+ formatted: str = ""
223
+ changed: bool = False
224
+
225
+
226
+ # =============================================================================
227
+ # Streaming Events
228
+ # =============================================================================
229
+
230
+
231
+ @dataclass
232
+ class StdinRequest:
233
+ prompt: str = ""
234
+ password: bool = False
235
+ execId: str = ""
236
+
237
+
238
+ # =============================================================================
239
+ # Exceptions
240
+ # =============================================================================
241
+
242
+
243
+ class InputCancelledError(Exception):
244
+ """Raised when user cancels input request."""
245
+ pass