opencode-py 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.
- opencode/__init__.py +45 -0
- opencode/__main__.py +20 -0
- opencode/_async_client.py +538 -0
- opencode/_async_opencode.py +255 -0
- opencode/_async_session.py +155 -0
- opencode/_binary.py +135 -0
- opencode/_client.py +532 -0
- opencode/_errors.py +20 -0
- opencode/_models.py +110 -0
- opencode/_opencode.py +290 -0
- opencode/_process.py +24 -0
- opencode/_server.py +97 -0
- opencode/_session.py +160 -0
- opencode/_tools.py +156 -0
- opencode_py-0.1.0.dist-info/METADATA +201 -0
- opencode_py-0.1.0.dist-info/RECORD +17 -0
- opencode_py-0.1.0.dist-info/WHEEL +4 -0
opencode/__init__.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from opencode._async_client import AsyncOpendcodeClient
|
|
2
|
+
from opencode._async_opencode import AsyncOpendcode, async_opencode
|
|
3
|
+
from opencode._async_session import AsyncSession
|
|
4
|
+
from opencode._client import OpencodeClient
|
|
5
|
+
from opencode._errors import ApiError, BinaryNotFound, OpencodeError, ServerStartupTimeout
|
|
6
|
+
from opencode._models import (
|
|
7
|
+
AssistantMessage,
|
|
8
|
+
AssistantMessageReasoning,
|
|
9
|
+
AssistantMessageText,
|
|
10
|
+
AssistantMessageTool,
|
|
11
|
+
SessionMessage,
|
|
12
|
+
SessionInfo,
|
|
13
|
+
UserMessage,
|
|
14
|
+
)
|
|
15
|
+
from opencode._opencode import Opencode, opencode
|
|
16
|
+
from opencode._server import OpencodeServer, create_opencode_server
|
|
17
|
+
from opencode._session import Session
|
|
18
|
+
from opencode._tools import ToolExecutor
|
|
19
|
+
|
|
20
|
+
__version__ = "0.1.0"
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"ApiError",
|
|
24
|
+
"AssistantMessage",
|
|
25
|
+
"AssistantMessageReasoning",
|
|
26
|
+
"AssistantMessageText",
|
|
27
|
+
"AssistantMessageTool",
|
|
28
|
+
"AsyncOpendcode",
|
|
29
|
+
"AsyncOpendcodeClient",
|
|
30
|
+
"AsyncSession",
|
|
31
|
+
"async_opencode",
|
|
32
|
+
"BinaryNotFound",
|
|
33
|
+
"Opencode",
|
|
34
|
+
"OpendcodeClient",
|
|
35
|
+
"OpendcodeError",
|
|
36
|
+
"OpencodeServer",
|
|
37
|
+
"ServerStartupTimeout",
|
|
38
|
+
"Session",
|
|
39
|
+
"ToolExecutor",
|
|
40
|
+
"SessionInfo",
|
|
41
|
+
"SessionMessage",
|
|
42
|
+
"UserMessage",
|
|
43
|
+
"create_opencode_server",
|
|
44
|
+
"opencode",
|
|
45
|
+
]
|
opencode/__main__.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from opencode import opencode
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main() -> None:
|
|
9
|
+
args = sys.argv[1:]
|
|
10
|
+
if not args:
|
|
11
|
+
print("Usage: python -m opencode <prompt>")
|
|
12
|
+
print(" or: echo 'question' | python -m opencode")
|
|
13
|
+
sys.exit(1)
|
|
14
|
+
prompt = " ".join(args)
|
|
15
|
+
result = opencode(prompt)
|
|
16
|
+
print(result)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if __name__ == "__main__":
|
|
20
|
+
main()
|
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any, Dict, List, Optional, Sequence
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from opencode._errors import ApiError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AsyncOpendcodeClient:
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
*,
|
|
14
|
+
base_url: str = "http://127.0.0.1:4096",
|
|
15
|
+
directory: Optional[str] = None,
|
|
16
|
+
workspace: Optional[str] = None,
|
|
17
|
+
timeout: float = 300.0,
|
|
18
|
+
httpx_client: Optional[httpx.AsyncClient] = None,
|
|
19
|
+
):
|
|
20
|
+
self.base_url = base_url.rstrip("/")
|
|
21
|
+
self.directory = directory
|
|
22
|
+
self.workspace = workspace
|
|
23
|
+
self._client = httpx_client or httpx.AsyncClient(timeout=httpx.Timeout(timeout))
|
|
24
|
+
|
|
25
|
+
# ------------------------------------------------------------------
|
|
26
|
+
# Internal helpers
|
|
27
|
+
# ------------------------------------------------------------------
|
|
28
|
+
|
|
29
|
+
def _build_url(self, path: str) -> str:
|
|
30
|
+
return f"{self.base_url}{path}"
|
|
31
|
+
|
|
32
|
+
def _merge_params(
|
|
33
|
+
self,
|
|
34
|
+
params: Optional[Dict[str, Any]] = None,
|
|
35
|
+
) -> Dict[str, Any]:
|
|
36
|
+
params = dict(params or {})
|
|
37
|
+
if self.directory and "directory" not in params:
|
|
38
|
+
params["directory"] = self.directory
|
|
39
|
+
if self.workspace and "workspace" not in params:
|
|
40
|
+
params["workspace"] = self.workspace
|
|
41
|
+
return params
|
|
42
|
+
|
|
43
|
+
def _handle(self, response: httpx.Response) -> Any:
|
|
44
|
+
if response.is_success:
|
|
45
|
+
if response.status_code == 204:
|
|
46
|
+
return None
|
|
47
|
+
ct = response.headers.get("content-type", "")
|
|
48
|
+
if "text/event-stream" in ct:
|
|
49
|
+
return response
|
|
50
|
+
if "text/" in ct:
|
|
51
|
+
return response.text
|
|
52
|
+
return response.json()
|
|
53
|
+
body = None
|
|
54
|
+
try:
|
|
55
|
+
body = response.json()
|
|
56
|
+
except Exception:
|
|
57
|
+
body = response.text
|
|
58
|
+
message = None
|
|
59
|
+
if isinstance(body, dict):
|
|
60
|
+
message = body.get("message") or body.get("error") or str(body)
|
|
61
|
+
elif isinstance(body, str):
|
|
62
|
+
message = body
|
|
63
|
+
raise ApiError(
|
|
64
|
+
message or f"HTTP {response.status_code}: {response.reason_phrase}",
|
|
65
|
+
status=response.status_code,
|
|
66
|
+
body=body,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
async def _request(
|
|
70
|
+
self,
|
|
71
|
+
method: str,
|
|
72
|
+
path: str,
|
|
73
|
+
*,
|
|
74
|
+
params: Optional[Dict[str, Any]] = None,
|
|
75
|
+
json_body: Any = None,
|
|
76
|
+
headers: Optional[Dict[str, str]] = None,
|
|
77
|
+
) -> Any:
|
|
78
|
+
url = self._build_url(path)
|
|
79
|
+
params = self._merge_params(params)
|
|
80
|
+
hdrs = {"Content-Type": "application/json", **(headers or {})}
|
|
81
|
+
response = await self._client.request(method, url, params=params, json=json_body, headers=hdrs)
|
|
82
|
+
return self._handle(response)
|
|
83
|
+
|
|
84
|
+
async def _request_stream(
|
|
85
|
+
self,
|
|
86
|
+
method: str,
|
|
87
|
+
path: str,
|
|
88
|
+
*,
|
|
89
|
+
params: Optional[Dict[str, Any]] = None,
|
|
90
|
+
json_body: Any = None,
|
|
91
|
+
headers: Optional[Dict[str, str]] = None,
|
|
92
|
+
) -> httpx.Response:
|
|
93
|
+
url = self._build_url(path)
|
|
94
|
+
params = self._merge_params(params)
|
|
95
|
+
hdrs = {"Content-Type": "application/json", **(headers or {})}
|
|
96
|
+
request = self._client.build_request(method, url, params=params, json=json_body, headers=hdrs)
|
|
97
|
+
return await self._client.send(request, stream=True)
|
|
98
|
+
|
|
99
|
+
# ------------------------------------------------------------------
|
|
100
|
+
# Global
|
|
101
|
+
# ------------------------------------------------------------------
|
|
102
|
+
|
|
103
|
+
async def health(self) -> Any:
|
|
104
|
+
return await self._request("GET", "/global/health")
|
|
105
|
+
|
|
106
|
+
async def global_event(self) -> httpx.Response:
|
|
107
|
+
return await self._request_stream("GET", "/global/event")
|
|
108
|
+
|
|
109
|
+
async def global_dispose(self) -> Any:
|
|
110
|
+
return await self._request("POST", "/global/dispose")
|
|
111
|
+
|
|
112
|
+
async def global_upgrade(self, target: Optional[str] = None) -> Any:
|
|
113
|
+
return await self._request("POST", "/global/upgrade", json_body={"target": target})
|
|
114
|
+
|
|
115
|
+
async def global_config_get(self) -> Any:
|
|
116
|
+
return await self._request("GET", "/global/config")
|
|
117
|
+
|
|
118
|
+
async def global_config_update(self, config: Any) -> Any:
|
|
119
|
+
return await self._request("PATCH", "/global/config", json_body={"config": config})
|
|
120
|
+
|
|
121
|
+
# ------------------------------------------------------------------
|
|
122
|
+
# Config
|
|
123
|
+
# ------------------------------------------------------------------
|
|
124
|
+
|
|
125
|
+
async def config_get(self, **kwargs) -> Any:
|
|
126
|
+
return await self._request("GET", "/config", params=kwargs)
|
|
127
|
+
|
|
128
|
+
async def config_update(self, config: Any, **kwargs) -> Any:
|
|
129
|
+
return await self._request("PATCH", "/config", json_body={"config": config}, params=kwargs)
|
|
130
|
+
|
|
131
|
+
async def config_providers(self, **kwargs) -> Any:
|
|
132
|
+
return await self._request("GET", "/config/providers", params=kwargs)
|
|
133
|
+
|
|
134
|
+
# ------------------------------------------------------------------
|
|
135
|
+
# Session
|
|
136
|
+
# ------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
async def session_create(self, **kwargs) -> Any:
|
|
139
|
+
return await self._request("POST", "/session", json_body=kwargs or None)
|
|
140
|
+
|
|
141
|
+
async def session_get(self, session_id: str) -> Any:
|
|
142
|
+
return await self._request("GET", f"/session/{session_id}")
|
|
143
|
+
|
|
144
|
+
async def session_list(self, **kwargs) -> Any:
|
|
145
|
+
return await self._request("GET", "/session", params=kwargs)
|
|
146
|
+
|
|
147
|
+
async def session_delete(self, session_id: str) -> Any:
|
|
148
|
+
return await self._request("DELETE", f"/session/{session_id}")
|
|
149
|
+
|
|
150
|
+
async def session_update(self, session_id: str, **kwargs) -> Any:
|
|
151
|
+
return await self._request("PUT", f"/session/{session_id}", json_body=kwargs or None)
|
|
152
|
+
|
|
153
|
+
async def session_messages(self, session_id: str, **kwargs) -> Any:
|
|
154
|
+
return await self._request("GET", f"/session/{session_id}/message", params=kwargs)
|
|
155
|
+
|
|
156
|
+
async def session_message(self, session_id: str, message_id: str) -> Any:
|
|
157
|
+
return await self._request("GET", f"/session/{session_id}/message/{message_id}")
|
|
158
|
+
|
|
159
|
+
async def session_fork(self, session_id: str, **kwargs) -> Any:
|
|
160
|
+
return await self._request("POST", f"/session/{session_id}/fork", json_body=kwargs or None)
|
|
161
|
+
|
|
162
|
+
async def session_abort(self, session_id: str) -> Any:
|
|
163
|
+
return await self._request("POST", f"/session/{session_id}/abort")
|
|
164
|
+
|
|
165
|
+
async def session_init(self, session_id: str, **kwargs) -> Any:
|
|
166
|
+
return await self._request("POST", f"/session/{session_id}/init", json_body=kwargs or None)
|
|
167
|
+
|
|
168
|
+
async def session_summarize(self, session_id: str) -> Any:
|
|
169
|
+
return await self._request("POST", f"/session/{session_id}/summarize")
|
|
170
|
+
|
|
171
|
+
async def session_todo(self, session_id: str) -> Any:
|
|
172
|
+
return await self._request("GET", f"/session/{session_id}/todo")
|
|
173
|
+
|
|
174
|
+
async def session_children(self, session_id: str) -> Any:
|
|
175
|
+
return await self._request("GET", f"/session/{session_id}/child")
|
|
176
|
+
|
|
177
|
+
async def session_diff(self, session_id: str) -> Any:
|
|
178
|
+
return await self._request("GET", f"/session/{session_id}/diff")
|
|
179
|
+
|
|
180
|
+
async def session_share(self, session_id: str) -> Any:
|
|
181
|
+
return await self._request("POST", f"/session/{session_id}/share")
|
|
182
|
+
|
|
183
|
+
async def session_unshare(self, session_id: str) -> Any:
|
|
184
|
+
return await self._request("DELETE", f"/session/{session_id}/share")
|
|
185
|
+
|
|
186
|
+
async def session_revert(self, session_id: str) -> Any:
|
|
187
|
+
return await self._request("POST", f"/session/{session_id}/revert")
|
|
188
|
+
|
|
189
|
+
async def session_unrevert(self, session_id: str) -> Any:
|
|
190
|
+
return await self._request("POST", f"/session/{session_id}/unrevert")
|
|
191
|
+
|
|
192
|
+
async def session_command(self, session_id: str, command: str, **kwargs) -> Any:
|
|
193
|
+
return await self._request("POST", f"/session/{session_id}/command", json_body={"command": command, **kwargs})
|
|
194
|
+
|
|
195
|
+
async def session_shell(self, session_id: str, command: str) -> Any:
|
|
196
|
+
return await self._request("POST", f"/session/{session_id}/shell", json_body={"command": command})
|
|
197
|
+
|
|
198
|
+
# ------------------------------------------------------------------
|
|
199
|
+
# V2 Session
|
|
200
|
+
# ------------------------------------------------------------------
|
|
201
|
+
|
|
202
|
+
async def v2_session_list(self, **kwargs) -> Any:
|
|
203
|
+
return await self._request("GET", "/api/session", params=kwargs)
|
|
204
|
+
|
|
205
|
+
async def session_send(self, session_id: str, body: Any) -> Any:
|
|
206
|
+
return await self._request("POST", f"/session/{session_id}/message", json_body=body)
|
|
207
|
+
|
|
208
|
+
async def v2_session_prompt(self, session_id: str, prompt: Any, *, delivery: str = "queue", **kwargs) -> Any:
|
|
209
|
+
body: Dict[str, Any] = {"prompt": prompt, "delivery": delivery, **kwargs}
|
|
210
|
+
return await self._request("POST", f"/api/session/{session_id}/prompt", json_body=body)
|
|
211
|
+
|
|
212
|
+
async def v2_session_wait(self, session_id: str) -> Any:
|
|
213
|
+
return await self._request("POST", f"/api/session/{session_id}/wait")
|
|
214
|
+
|
|
215
|
+
async def v2_session_context(self, session_id: str, **kwargs) -> Any:
|
|
216
|
+
return await self._request("GET", f"/api/session/{session_id}/context", params=kwargs)
|
|
217
|
+
|
|
218
|
+
async def v2_session_messages(self, session_id: str, **kwargs) -> Any:
|
|
219
|
+
return await self._request("GET", f"/api/session/{session_id}/message", params=kwargs)
|
|
220
|
+
|
|
221
|
+
async def v2_session_compact(self, session_id: str) -> Any:
|
|
222
|
+
return await self._request("POST", f"/api/session/{session_id}/compact")
|
|
223
|
+
|
|
224
|
+
async def v2_model_list(self, **kwargs) -> Any:
|
|
225
|
+
return await self._request("GET", "/api/model", params=kwargs)
|
|
226
|
+
|
|
227
|
+
async def v2_provider_list(self, **kwargs) -> Any:
|
|
228
|
+
return await self._request("GET", "/api/provider", params=kwargs)
|
|
229
|
+
|
|
230
|
+
async def v2_provider_get(self, provider_id: str) -> Any:
|
|
231
|
+
return await self._request("GET", f"/api/provider/{provider_id}")
|
|
232
|
+
|
|
233
|
+
# ------------------------------------------------------------------
|
|
234
|
+
# Auth
|
|
235
|
+
# ------------------------------------------------------------------
|
|
236
|
+
|
|
237
|
+
async def auth_set(self, provider_id: str, auth: Any) -> Any:
|
|
238
|
+
return await self._request("PUT", f"/auth/{provider_id}", json_body={"auth": auth})
|
|
239
|
+
|
|
240
|
+
async def auth_remove(self, provider_id: str) -> Any:
|
|
241
|
+
return await self._request("DELETE", f"/auth/{provider_id}")
|
|
242
|
+
|
|
243
|
+
# ------------------------------------------------------------------
|
|
244
|
+
# App
|
|
245
|
+
# ------------------------------------------------------------------
|
|
246
|
+
|
|
247
|
+
async def app_log(self, **kwargs) -> Any:
|
|
248
|
+
return await self._request("POST", "/log", json_body=kwargs or None)
|
|
249
|
+
|
|
250
|
+
async def app_agents(self, **kwargs) -> Any:
|
|
251
|
+
return await self._request("GET", "/agent", params=kwargs)
|
|
252
|
+
|
|
253
|
+
# ------------------------------------------------------------------
|
|
254
|
+
# File
|
|
255
|
+
# ------------------------------------------------------------------
|
|
256
|
+
|
|
257
|
+
async def file_read(self, path: str, **kwargs) -> Any:
|
|
258
|
+
return await self._request("GET", "/file/content", params={"path": path, **kwargs})
|
|
259
|
+
|
|
260
|
+
async def file_list(self, path: str, **kwargs) -> Any:
|
|
261
|
+
return await self._request("GET", "/file", params={"path": path, **kwargs})
|
|
262
|
+
|
|
263
|
+
async def file_status(self, **kwargs) -> Any:
|
|
264
|
+
return await self._request("GET", "/file/status", params=kwargs)
|
|
265
|
+
|
|
266
|
+
# ------------------------------------------------------------------
|
|
267
|
+
# Find
|
|
268
|
+
# ------------------------------------------------------------------
|
|
269
|
+
|
|
270
|
+
async def find_text(self, pattern: str, **kwargs) -> Any:
|
|
271
|
+
return await self._request("GET", "/find", params={"pattern": pattern, **kwargs})
|
|
272
|
+
|
|
273
|
+
async def find_files(self, query: str, **kwargs) -> Any:
|
|
274
|
+
return await self._request("GET", "/find/file", params={"query": query, **kwargs})
|
|
275
|
+
|
|
276
|
+
async def find_symbols(self, query: str, **kwargs) -> Any:
|
|
277
|
+
return await self._request("GET", "/find/symbol", params={"query": query, **kwargs})
|
|
278
|
+
|
|
279
|
+
# ------------------------------------------------------------------
|
|
280
|
+
# VCS
|
|
281
|
+
# ------------------------------------------------------------------
|
|
282
|
+
|
|
283
|
+
async def vcs_get(self, **kwargs) -> Any:
|
|
284
|
+
return await self._request("GET", "/vcs", params=kwargs)
|
|
285
|
+
|
|
286
|
+
async def vcs_status(self, **kwargs) -> Any:
|
|
287
|
+
return await self._request("GET", "/vcs/status", params=kwargs)
|
|
288
|
+
|
|
289
|
+
async def vcs_diff(self, mode: str = "git", **kwargs) -> Any:
|
|
290
|
+
return await self._request("GET", "/vcs/diff", params={"mode": mode, **kwargs})
|
|
291
|
+
|
|
292
|
+
async def vcs_diff_raw(self, **kwargs) -> Any:
|
|
293
|
+
return await self._request("GET", "/vcs/diff/raw", params=kwargs)
|
|
294
|
+
|
|
295
|
+
async def vcs_apply(self, patch: str, **kwargs) -> Any:
|
|
296
|
+
return await self._request("POST", "/vcs/apply", json_body={"patch": patch, **kwargs})
|
|
297
|
+
|
|
298
|
+
# ------------------------------------------------------------------
|
|
299
|
+
# LSP / Formatter
|
|
300
|
+
# ------------------------------------------------------------------
|
|
301
|
+
|
|
302
|
+
async def lsp_status(self, **kwargs) -> Any:
|
|
303
|
+
return await self._request("GET", "/lsp", params=kwargs)
|
|
304
|
+
|
|
305
|
+
async def formatter_status(self, **kwargs) -> Any:
|
|
306
|
+
return await self._request("GET", "/formatter", params=kwargs)
|
|
307
|
+
|
|
308
|
+
# ------------------------------------------------------------------
|
|
309
|
+
# Provider
|
|
310
|
+
# ------------------------------------------------------------------
|
|
311
|
+
|
|
312
|
+
async def provider_list(self, **kwargs) -> Any:
|
|
313
|
+
return await self._request("GET", "/provider", params=kwargs)
|
|
314
|
+
|
|
315
|
+
async def provider_auth(self, provider_id: str, **kwargs) -> Any:
|
|
316
|
+
return await self._request("GET", f"/provider/{provider_id}/auth", params=kwargs)
|
|
317
|
+
|
|
318
|
+
# ------------------------------------------------------------------
|
|
319
|
+
# MCP
|
|
320
|
+
# ------------------------------------------------------------------
|
|
321
|
+
|
|
322
|
+
async def mcp_list(self, **kwargs) -> Any:
|
|
323
|
+
return await self._request("GET", "/mcp", params=kwargs)
|
|
324
|
+
|
|
325
|
+
async def mcp_status(self, **kwargs) -> Any:
|
|
326
|
+
return await self._request("GET", "/mcp/status", params=kwargs)
|
|
327
|
+
|
|
328
|
+
async def mcp_add(self, config: Any) -> Any:
|
|
329
|
+
return await self._request("PUT", "/mcp", json_body={"config": config})
|
|
330
|
+
|
|
331
|
+
async def mcp_connect(self, name: str, **kwargs) -> Any:
|
|
332
|
+
return await self._request("POST", f"/mcp/{name}/connect", json_body=kwargs or None)
|
|
333
|
+
|
|
334
|
+
async def mcp_disconnect(self, name: str) -> Any:
|
|
335
|
+
return await self._request("DELETE", f"/mcp/{name}/connect")
|
|
336
|
+
|
|
337
|
+
# ------------------------------------------------------------------
|
|
338
|
+
# Tool
|
|
339
|
+
# ------------------------------------------------------------------
|
|
340
|
+
|
|
341
|
+
async def tool_list(self, **kwargs) -> Any:
|
|
342
|
+
return await self._request("GET", "/experimental/tool", params=kwargs)
|
|
343
|
+
|
|
344
|
+
async def tool_ids(self, **kwargs) -> Any:
|
|
345
|
+
return await self._request("GET", "/experimental/tool/ids", params=kwargs)
|
|
346
|
+
|
|
347
|
+
# ------------------------------------------------------------------
|
|
348
|
+
# Permission
|
|
349
|
+
# ------------------------------------------------------------------
|
|
350
|
+
|
|
351
|
+
async def permission_list(self, **kwargs) -> Any:
|
|
352
|
+
return await self._request("GET", "/permission", params=kwargs)
|
|
353
|
+
|
|
354
|
+
async def permission_reply(self, permission_id: str, **kwargs) -> Any:
|
|
355
|
+
return await self._request("POST", f"/permission/{permission_id}", json_body=kwargs or None)
|
|
356
|
+
|
|
357
|
+
# ------------------------------------------------------------------
|
|
358
|
+
# Question
|
|
359
|
+
# ------------------------------------------------------------------
|
|
360
|
+
|
|
361
|
+
async def question_list(self, **kwargs) -> Any:
|
|
362
|
+
return await self._request("GET", "/question", params=kwargs)
|
|
363
|
+
|
|
364
|
+
async def question_reply(self, question_id: str, answer: Any) -> Any:
|
|
365
|
+
return await self._request("POST", f"/question/{question_id}", json_body={"answer": answer})
|
|
366
|
+
|
|
367
|
+
async def question_reject(self, question_id: str) -> Any:
|
|
368
|
+
return await self._request("DELETE", f"/question/{question_id}")
|
|
369
|
+
|
|
370
|
+
# ------------------------------------------------------------------
|
|
371
|
+
# Event (SSE)
|
|
372
|
+
# ------------------------------------------------------------------
|
|
373
|
+
|
|
374
|
+
async def event_subscribe(self, **kwargs) -> httpx.Response:
|
|
375
|
+
return await self._request_stream("GET", "/event", params=kwargs)
|
|
376
|
+
|
|
377
|
+
# ------------------------------------------------------------------
|
|
378
|
+
# PTY
|
|
379
|
+
# ------------------------------------------------------------------
|
|
380
|
+
|
|
381
|
+
async def pty_list(self, **kwargs) -> Any:
|
|
382
|
+
return await self._request("GET", "/pty", params=kwargs)
|
|
383
|
+
|
|
384
|
+
async def pty_create(self, **kwargs) -> Any:
|
|
385
|
+
return await self._request("POST", "/pty", json_body=kwargs or None)
|
|
386
|
+
|
|
387
|
+
async def pty_get(self, pty_id: str) -> Any:
|
|
388
|
+
return await self._request("GET", f"/pty/{pty_id}")
|
|
389
|
+
|
|
390
|
+
async def pty_remove(self, pty_id: str) -> Any:
|
|
391
|
+
return await self._request("DELETE", f"/pty/{pty_id}")
|
|
392
|
+
|
|
393
|
+
async def pty_update(self, pty_id: str, **kwargs) -> Any:
|
|
394
|
+
return await self._request("PATCH", f"/pty/{pty_id}", json_body=kwargs or None)
|
|
395
|
+
|
|
396
|
+
async def pty_shells(self, **kwargs) -> Any:
|
|
397
|
+
return await self._request("GET", "/pty/shells", params=kwargs)
|
|
398
|
+
|
|
399
|
+
# ------------------------------------------------------------------
|
|
400
|
+
# Path
|
|
401
|
+
# ------------------------------------------------------------------
|
|
402
|
+
|
|
403
|
+
async def path_get(self, **kwargs) -> Any:
|
|
404
|
+
return await self._request("GET", "/path", params=kwargs)
|
|
405
|
+
|
|
406
|
+
# ------------------------------------------------------------------
|
|
407
|
+
# Instance
|
|
408
|
+
# ------------------------------------------------------------------
|
|
409
|
+
|
|
410
|
+
async def instance_dispose(self, **kwargs) -> Any:
|
|
411
|
+
return await self._request("POST", "/instance/dispose", params=kwargs)
|
|
412
|
+
|
|
413
|
+
# ------------------------------------------------------------------
|
|
414
|
+
# Command
|
|
415
|
+
# ------------------------------------------------------------------
|
|
416
|
+
|
|
417
|
+
async def command_list(self, **kwargs) -> Any:
|
|
418
|
+
return await self._request("GET", "/command", params=kwargs)
|
|
419
|
+
|
|
420
|
+
# ------------------------------------------------------------------
|
|
421
|
+
# Project
|
|
422
|
+
# ------------------------------------------------------------------
|
|
423
|
+
|
|
424
|
+
async def project_current(self, **kwargs) -> Any:
|
|
425
|
+
return await self._request("GET", "/project/current", params=kwargs)
|
|
426
|
+
|
|
427
|
+
async def project_list(self, **kwargs) -> Any:
|
|
428
|
+
return await self._request("GET", "/project", params=kwargs)
|
|
429
|
+
|
|
430
|
+
async def project_update(self, **kwargs) -> Any:
|
|
431
|
+
return await self._request("PATCH", "/project", json_body=kwargs or None)
|
|
432
|
+
|
|
433
|
+
async def project_init_git(self, **kwargs) -> Any:
|
|
434
|
+
return await self._request("POST", "/project/init-git", json_body=kwargs or None)
|
|
435
|
+
|
|
436
|
+
# ------------------------------------------------------------------
|
|
437
|
+
# Worktree (experimental)
|
|
438
|
+
# ------------------------------------------------------------------
|
|
439
|
+
|
|
440
|
+
async def worktree_list(self, **kwargs) -> Any:
|
|
441
|
+
return await self._request("GET", "/experimental/worktree", params=kwargs)
|
|
442
|
+
|
|
443
|
+
async def worktree_create(self, **kwargs) -> Any:
|
|
444
|
+
return await self._request("POST", "/experimental/worktree", json_body=kwargs or None)
|
|
445
|
+
|
|
446
|
+
async def worktree_remove(self, **kwargs) -> Any:
|
|
447
|
+
return await self._request("DELETE", "/experimental/worktree", params=kwargs)
|
|
448
|
+
|
|
449
|
+
async def worktree_reset(self, **kwargs) -> Any:
|
|
450
|
+
return await self._request("POST", "/experimental/worktree/reset", json_body=kwargs or None)
|
|
451
|
+
|
|
452
|
+
# ------------------------------------------------------------------
|
|
453
|
+
# Workspace (experimental)
|
|
454
|
+
# ------------------------------------------------------------------
|
|
455
|
+
|
|
456
|
+
async def workspace_list(self, **kwargs) -> Any:
|
|
457
|
+
return await self._request("GET", "/experimental/workspace", params=kwargs)
|
|
458
|
+
|
|
459
|
+
async def workspace_create(self, **kwargs) -> Any:
|
|
460
|
+
return await self._request("POST", "/experimental/workspace", json_body=kwargs or None)
|
|
461
|
+
|
|
462
|
+
async def workspace_status(self, **kwargs) -> Any:
|
|
463
|
+
return await self._request("GET", "/experimental/workspace/status", params=kwargs)
|
|
464
|
+
|
|
465
|
+
async def workspace_remove(self, workspace_id: str) -> Any:
|
|
466
|
+
return await self._request("DELETE", f"/experimental/workspace/{workspace_id}")
|
|
467
|
+
|
|
468
|
+
async def workspace_warp(self, **kwargs) -> Any:
|
|
469
|
+
return await self._request("POST", "/experimental/workspace/warp", json_body=kwargs or None)
|
|
470
|
+
|
|
471
|
+
# ------------------------------------------------------------------
|
|
472
|
+
# Sync (experimental)
|
|
473
|
+
# ------------------------------------------------------------------
|
|
474
|
+
|
|
475
|
+
async def sync_start(self, **kwargs) -> Any:
|
|
476
|
+
return await self._request("POST", "/experimental/sync/start", json_body=kwargs or None)
|
|
477
|
+
|
|
478
|
+
async def sync_steal(self, **kwargs) -> Any:
|
|
479
|
+
return await self._request("POST", "/experimental/sync/steal", json_body=kwargs or None)
|
|
480
|
+
|
|
481
|
+
async def sync_replay(self, session_id: str) -> Any:
|
|
482
|
+
return await self._request("POST", f"/experimental/sync/replay/{session_id}")
|
|
483
|
+
|
|
484
|
+
async def sync_history(self, session_id: str) -> Any:
|
|
485
|
+
return await self._request("GET", f"/experimental/sync/history/{session_id}")
|
|
486
|
+
|
|
487
|
+
# ------------------------------------------------------------------
|
|
488
|
+
# TUI
|
|
489
|
+
# ------------------------------------------------------------------
|
|
490
|
+
|
|
491
|
+
async def tui_submit_prompt(self, **kwargs) -> Any:
|
|
492
|
+
return await self._request("POST", "/tui/submit", json_body=kwargs or None)
|
|
493
|
+
|
|
494
|
+
async def tui_append_prompt(self, **kwargs) -> Any:
|
|
495
|
+
return await self._request("POST", "/tui/append", json_body=kwargs or None)
|
|
496
|
+
|
|
497
|
+
async def tui_clear_prompt(self) -> Any:
|
|
498
|
+
return await self._request("POST", "/tui/clear")
|
|
499
|
+
|
|
500
|
+
async def tui_execute_command(self, **kwargs) -> Any:
|
|
501
|
+
return await self._request("POST", "/tui/command", json_body=kwargs or None)
|
|
502
|
+
|
|
503
|
+
async def tui_show_toast(self, **kwargs) -> Any:
|
|
504
|
+
return await self._request("POST", "/tui/toast", json_body=kwargs or None)
|
|
505
|
+
|
|
506
|
+
async def tui_open_sessions(self) -> Any:
|
|
507
|
+
return await self._request("POST", "/tui/sessions")
|
|
508
|
+
|
|
509
|
+
async def tui_open_models(self) -> Any:
|
|
510
|
+
return await self._request("POST", "/tui/models")
|
|
511
|
+
|
|
512
|
+
async def tui_open_themes(self) -> Any:
|
|
513
|
+
return await self._request("POST", "/tui/themes")
|
|
514
|
+
|
|
515
|
+
async def tui_open_help(self) -> Any:
|
|
516
|
+
return await self._request("POST", "/tui/help")
|
|
517
|
+
|
|
518
|
+
async def tui_publish(self, **kwargs) -> Any:
|
|
519
|
+
return await self._request("POST", "/tui/publish", json_body=kwargs or None)
|
|
520
|
+
|
|
521
|
+
async def tui_control_response(self, **kwargs) -> Any:
|
|
522
|
+
return await self._request("POST", "/tui/control/response", json_body=kwargs or None)
|
|
523
|
+
|
|
524
|
+
async def tui_control_next(self, session_id: str) -> Any:
|
|
525
|
+
return await self._request("POST", f"/tui/control/next/{session_id}")
|
|
526
|
+
|
|
527
|
+
# ------------------------------------------------------------------
|
|
528
|
+
# Async context manager
|
|
529
|
+
# ------------------------------------------------------------------
|
|
530
|
+
|
|
531
|
+
async def close(self) -> None:
|
|
532
|
+
await self._client.aclose()
|
|
533
|
+
|
|
534
|
+
async def __aenter__(self) -> AsyncOpendcodeClient:
|
|
535
|
+
return self
|
|
536
|
+
|
|
537
|
+
async def __aexit__(self, *args: Any) -> None:
|
|
538
|
+
await self.close()
|