opencode-python-sdk 0.0.1.dev1__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.
Files changed (62) hide show
  1. opencode/.generated.json +39 -0
  2. opencode/__init__.py +221 -0
  3. opencode/_base_client.py +539 -0
  4. opencode/_client.py +255 -0
  5. opencode/_constants.py +27 -0
  6. opencode/_errors.py +547 -0
  7. opencode/_events.py +732 -0
  8. opencode/_exceptions.py +271 -0
  9. opencode/_models.py +54 -0
  10. opencode/_pagination.py +192 -0
  11. opencode/_pty.py +586 -0
  12. opencode/_qs.py +95 -0
  13. opencode/_resource.py +42 -0
  14. opencode/_rpc.py +489 -0
  15. opencode/_server.py +335 -0
  16. opencode/_streaming.py +248 -0
  17. opencode/_types.py +77 -0
  18. opencode/_unions.py +46 -0
  19. opencode/_version.py +8 -0
  20. opencode/lib/__init__.py +5 -0
  21. opencode/lib/_ready.py +91 -0
  22. opencode/lib/_session.py +231 -0
  23. opencode/py.typed +0 -0
  24. opencode/resources/__init__.py +364 -0
  25. opencode/resources/agent.py +179 -0
  26. opencode/resources/command.py +100 -0
  27. opencode/resources/config.py +240 -0
  28. opencode/resources/credential.py +384 -0
  29. opencode/resources/debug.py +178 -0
  30. opencode/resources/event.py +88 -0
  31. opencode/resources/experimental.py +765 -0
  32. opencode/resources/file.py +355 -0
  33. opencode/resources/form.py +100 -0
  34. opencode/resources/generate.py +110 -0
  35. opencode/resources/integration.py +1033 -0
  36. opencode/resources/location.py +162 -0
  37. opencode/resources/mcp.py +492 -0
  38. opencode/resources/message.py +152 -0
  39. opencode/resources/migration.py +118 -0
  40. opencode/resources/model.py +177 -0
  41. opencode/resources/permission.py +704 -0
  42. opencode/resources/plugin.py +250 -0
  43. opencode/resources/project.py +187 -0
  44. opencode/resources/provider.py +183 -0
  45. opencode/resources/pty.py +522 -0
  46. opencode/resources/reference.py +100 -0
  47. opencode/resources/rpc.py +113 -0
  48. opencode/resources/server.py +230 -0
  49. opencode/resources/session.py +3567 -0
  50. opencode/resources/shell.py +412 -0
  51. opencode/resources/skill.py +100 -0
  52. opencode/resources/vcs.py +500 -0
  53. opencode/resources/voice.py +113 -0
  54. opencode/resources/websearch.py +184 -0
  55. opencode/resources/worktree.py +336 -0
  56. opencode/testing.py +508 -0
  57. opencode/types/__init__.py +1462 -0
  58. opencode/types/_generated.py +8540 -0
  59. opencode_python_sdk-0.0.1.dev1.dist-info/METADATA +468 -0
  60. opencode_python_sdk-0.0.1.dev1.dist-info/RECORD +62 -0
  61. opencode_python_sdk-0.0.1.dev1.dist-info/WHEEL +4 -0
  62. opencode_python_sdk-0.0.1.dev1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,355 @@
1
+ # This file is generated by `python -m codegen` from spec/contract.json. Do not edit it by hand.
2
+ # OpenCode 2.1.2
3
+
4
+ """The ``file`` resource."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import TYPE_CHECKING, Literal, cast
9
+
10
+ from .._base_client import RequestOptions
11
+ from .._qs import encode_path
12
+ from .._resource import AsyncAPIResource, SyncAPIResource
13
+ from .._types import NOT_GIVEN, Body, Headers, NotGiven, OpenEnum, Query, Timeout
14
+
15
+ if TYPE_CHECKING:
16
+ from ..types import (
17
+ FileFindResponse,
18
+ FileListResponse,
19
+ FileWriteResponse,
20
+ Location,
21
+ )
22
+
23
+ __all__ = ["FileResource", "AsyncFileResource"]
24
+
25
+
26
+ class FileResource(SyncAPIResource):
27
+ """Operations under ``client.file`` (OpenCode ``file``)."""
28
+
29
+ def read(
30
+ self,
31
+ path: str,
32
+ *,
33
+ location: Location | NotGiven | None = NOT_GIVEN,
34
+ extra_headers: Headers | None = None,
35
+ extra_query: Query | None = None,
36
+ extra_body: Body | None = None,
37
+ timeout: Timeout | NotGiven = NOT_GIVEN,
38
+ ) -> bytes:
39
+ """Read file.
40
+
41
+ Stream one file relative to the requested location with ETag, Last-Modified, and single-range HTTP Range support (206 Partial Content, 416 Range Not Satisfiable, and 304 Not Modified; multi-range and malformed Range headers fall back to 200).
42
+
43
+ Raises:
44
+ InvalidRequestError: The server answered 400.
45
+ UnauthorizedError: The server answered 401.
46
+ RemoteFileNotFoundError: The server answered 404.
47
+ LocationNotFoundError: The server answered 404.
48
+
49
+ ``GET /api/fs/read/*``
50
+ """
51
+ return cast(
52
+ "bytes",
53
+ self._client.request(
54
+ RequestOptions(
55
+ method="GET",
56
+ path=f"/api/fs/read/{encode_path(path)}",
57
+ query={"location": self._location(location)},
58
+ extra_headers=extra_headers,
59
+ extra_query=extra_query,
60
+ extra_body=extra_body,
61
+ timeout=timeout,
62
+ ),
63
+ kind="binary",
64
+ ),
65
+ )
66
+
67
+ def list(
68
+ self,
69
+ *,
70
+ location: Location | NotGiven | None = NOT_GIVEN,
71
+ path: str | NotGiven | None = NOT_GIVEN,
72
+ extra_headers: Headers | None = None,
73
+ extra_query: Query | None = None,
74
+ extra_body: Body | None = None,
75
+ timeout: Timeout | NotGiven = NOT_GIVEN,
76
+ ) -> FileListResponse:
77
+ """List directory.
78
+
79
+ List direct children using an absolute path or a path relative to the requested location, including parents and siblings outside its directory. Entry paths remain relative to the requested location; listing does not switch locations.
80
+
81
+ Args:
82
+ path: An absolute path or a path relative to the requested location. Defaults to the location directory.
83
+
84
+ Raises:
85
+ InvalidRequestError: The server answered 400.
86
+ UnauthorizedError: The server answered 401.
87
+ RemoteFileNotFoundError: The server answered 404.
88
+ LocationNotFoundError: The server answered 404.
89
+
90
+ ``GET /api/fs/list``
91
+ """
92
+ return cast(
93
+ "FileListResponse",
94
+ self._client.request(
95
+ RequestOptions(
96
+ method="GET",
97
+ path="/api/fs/list",
98
+ query={"location": self._location(location), "path": path},
99
+ extra_headers=extra_headers,
100
+ extra_query=extra_query,
101
+ extra_body=extra_body,
102
+ timeout=timeout,
103
+ ),
104
+ response_type="FileListResponse",
105
+ ),
106
+ )
107
+
108
+ def find(
109
+ self,
110
+ *,
111
+ query: str,
112
+ location: Location | NotGiven | None = NOT_GIVEN,
113
+ type: OpenEnum[Literal["file", "directory"]] | NotGiven | None = NOT_GIVEN,
114
+ limit: int | NotGiven | None = NOT_GIVEN,
115
+ extra_headers: Headers | None = None,
116
+ extra_query: Query | None = None,
117
+ extra_body: Body | None = None,
118
+ timeout: Timeout | NotGiven = NOT_GIVEN,
119
+ ) -> FileFindResponse:
120
+ """Find files.
121
+
122
+ Find recursively ranked filesystem entries relative to the requested location.
123
+
124
+ Raises:
125
+ InvalidRequestError: The server answered 400.
126
+ UnauthorizedError: The server answered 401.
127
+ LocationNotFoundError: The server answered 404.
128
+
129
+ ``GET /api/fs/find``
130
+ """
131
+ return cast(
132
+ "FileFindResponse",
133
+ self._client.request(
134
+ RequestOptions(
135
+ method="GET",
136
+ path="/api/fs/find",
137
+ query={"location": self._location(location), "query": query, "type": type, "limit": limit},
138
+ extra_headers=extra_headers,
139
+ extra_query=extra_query,
140
+ extra_body=extra_body,
141
+ timeout=timeout,
142
+ ),
143
+ response_type="FileFindResponse",
144
+ ),
145
+ )
146
+
147
+ def write(
148
+ self,
149
+ *,
150
+ path: str,
151
+ payload: bytes,
152
+ location: Location | NotGiven | None = NOT_GIVEN,
153
+ extra_headers: Headers | None = None,
154
+ extra_query: Query | None = None,
155
+ extra_body: Body | None = None,
156
+ timeout: Timeout | NotGiven = NOT_GIVEN,
157
+ ) -> FileWriteResponse:
158
+ """Write file.
159
+
160
+ Write the raw request body to an absolute path or a path relative to the requested location, creating parent directories, and return the resolved absolute path. Unlike read, the target is not confined to the location. Experimental: may change without compatibility guarantees.
161
+
162
+ This endpoint is experimental in OpenCode and may change without notice.
163
+
164
+ Args:
165
+ path: An absolute path or a path relative to the requested location. Missing parent directories are created.
166
+
167
+ Raises:
168
+ InvalidRequestError: The server answered 400.
169
+ UnauthorizedError: The server answered 401.
170
+ LocationNotFoundError: The server answered 404.
171
+
172
+ ``POST /api/experimental/fs/write``
173
+ """
174
+ return cast(
175
+ "FileWriteResponse",
176
+ self._client.request(
177
+ RequestOptions(
178
+ method="POST",
179
+ path="/api/experimental/fs/write",
180
+ query={"location": self._location(location), "path": path},
181
+ content=bytes(payload),
182
+ extra_headers=extra_headers,
183
+ extra_query=extra_query,
184
+ extra_body=extra_body,
185
+ timeout=timeout,
186
+ ),
187
+ response_type="FileWriteResponse",
188
+ ),
189
+ )
190
+
191
+
192
+ class AsyncFileResource(AsyncAPIResource):
193
+ """Operations under ``client.file`` (OpenCode ``file``)."""
194
+
195
+ async def read(
196
+ self,
197
+ path: str,
198
+ *,
199
+ location: Location | NotGiven | None = NOT_GIVEN,
200
+ extra_headers: Headers | None = None,
201
+ extra_query: Query | None = None,
202
+ extra_body: Body | None = None,
203
+ timeout: Timeout | NotGiven = NOT_GIVEN,
204
+ ) -> bytes:
205
+ """Read file.
206
+
207
+ Stream one file relative to the requested location with ETag, Last-Modified, and single-range HTTP Range support (206 Partial Content, 416 Range Not Satisfiable, and 304 Not Modified; multi-range and malformed Range headers fall back to 200).
208
+
209
+ Raises:
210
+ InvalidRequestError: The server answered 400.
211
+ UnauthorizedError: The server answered 401.
212
+ RemoteFileNotFoundError: The server answered 404.
213
+ LocationNotFoundError: The server answered 404.
214
+
215
+ ``GET /api/fs/read/*``
216
+ """
217
+ return cast(
218
+ "bytes",
219
+ await self._client.request(
220
+ RequestOptions(
221
+ method="GET",
222
+ path=f"/api/fs/read/{encode_path(path)}",
223
+ query={"location": self._location(location)},
224
+ extra_headers=extra_headers,
225
+ extra_query=extra_query,
226
+ extra_body=extra_body,
227
+ timeout=timeout,
228
+ ),
229
+ kind="binary",
230
+ ),
231
+ )
232
+
233
+ async def list(
234
+ self,
235
+ *,
236
+ location: Location | NotGiven | None = NOT_GIVEN,
237
+ path: str | NotGiven | None = NOT_GIVEN,
238
+ extra_headers: Headers | None = None,
239
+ extra_query: Query | None = None,
240
+ extra_body: Body | None = None,
241
+ timeout: Timeout | NotGiven = NOT_GIVEN,
242
+ ) -> FileListResponse:
243
+ """List directory.
244
+
245
+ List direct children using an absolute path or a path relative to the requested location, including parents and siblings outside its directory. Entry paths remain relative to the requested location; listing does not switch locations.
246
+
247
+ Args:
248
+ path: An absolute path or a path relative to the requested location. Defaults to the location directory.
249
+
250
+ Raises:
251
+ InvalidRequestError: The server answered 400.
252
+ UnauthorizedError: The server answered 401.
253
+ RemoteFileNotFoundError: The server answered 404.
254
+ LocationNotFoundError: The server answered 404.
255
+
256
+ ``GET /api/fs/list``
257
+ """
258
+ return cast(
259
+ "FileListResponse",
260
+ await self._client.request(
261
+ RequestOptions(
262
+ method="GET",
263
+ path="/api/fs/list",
264
+ query={"location": self._location(location), "path": path},
265
+ extra_headers=extra_headers,
266
+ extra_query=extra_query,
267
+ extra_body=extra_body,
268
+ timeout=timeout,
269
+ ),
270
+ response_type="FileListResponse",
271
+ ),
272
+ )
273
+
274
+ async def find(
275
+ self,
276
+ *,
277
+ query: str,
278
+ location: Location | NotGiven | None = NOT_GIVEN,
279
+ type: OpenEnum[Literal["file", "directory"]] | NotGiven | None = NOT_GIVEN,
280
+ limit: int | NotGiven | None = NOT_GIVEN,
281
+ extra_headers: Headers | None = None,
282
+ extra_query: Query | None = None,
283
+ extra_body: Body | None = None,
284
+ timeout: Timeout | NotGiven = NOT_GIVEN,
285
+ ) -> FileFindResponse:
286
+ """Find files.
287
+
288
+ Find recursively ranked filesystem entries relative to the requested location.
289
+
290
+ Raises:
291
+ InvalidRequestError: The server answered 400.
292
+ UnauthorizedError: The server answered 401.
293
+ LocationNotFoundError: The server answered 404.
294
+
295
+ ``GET /api/fs/find``
296
+ """
297
+ return cast(
298
+ "FileFindResponse",
299
+ await self._client.request(
300
+ RequestOptions(
301
+ method="GET",
302
+ path="/api/fs/find",
303
+ query={"location": self._location(location), "query": query, "type": type, "limit": limit},
304
+ extra_headers=extra_headers,
305
+ extra_query=extra_query,
306
+ extra_body=extra_body,
307
+ timeout=timeout,
308
+ ),
309
+ response_type="FileFindResponse",
310
+ ),
311
+ )
312
+
313
+ async def write(
314
+ self,
315
+ *,
316
+ path: str,
317
+ payload: bytes,
318
+ location: Location | NotGiven | None = NOT_GIVEN,
319
+ extra_headers: Headers | None = None,
320
+ extra_query: Query | None = None,
321
+ extra_body: Body | None = None,
322
+ timeout: Timeout | NotGiven = NOT_GIVEN,
323
+ ) -> FileWriteResponse:
324
+ """Write file.
325
+
326
+ Write the raw request body to an absolute path or a path relative to the requested location, creating parent directories, and return the resolved absolute path. Unlike read, the target is not confined to the location. Experimental: may change without compatibility guarantees.
327
+
328
+ This endpoint is experimental in OpenCode and may change without notice.
329
+
330
+ Args:
331
+ path: An absolute path or a path relative to the requested location. Missing parent directories are created.
332
+
333
+ Raises:
334
+ InvalidRequestError: The server answered 400.
335
+ UnauthorizedError: The server answered 401.
336
+ LocationNotFoundError: The server answered 404.
337
+
338
+ ``POST /api/experimental/fs/write``
339
+ """
340
+ return cast(
341
+ "FileWriteResponse",
342
+ await self._client.request(
343
+ RequestOptions(
344
+ method="POST",
345
+ path="/api/experimental/fs/write",
346
+ query={"location": self._location(location), "path": path},
347
+ content=bytes(payload),
348
+ extra_headers=extra_headers,
349
+ extra_query=extra_query,
350
+ extra_body=extra_body,
351
+ timeout=timeout,
352
+ ),
353
+ response_type="FileWriteResponse",
354
+ ),
355
+ )
@@ -0,0 +1,100 @@
1
+ # This file is generated by `python -m codegen` from spec/contract.json. Do not edit it by hand.
2
+ # OpenCode 2.1.2
3
+
4
+ """The ``form`` resource."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import TYPE_CHECKING, cast
9
+
10
+ from .._base_client import RequestOptions
11
+ from .._resource import AsyncAPIResource, SyncAPIResource
12
+ from .._types import NOT_GIVEN, Body, Headers, NotGiven, Query, Timeout
13
+
14
+ if TYPE_CHECKING:
15
+ from ..types import (
16
+ FormListResponse,
17
+ Location,
18
+ )
19
+
20
+ __all__ = ["FormResource", "AsyncFormResource"]
21
+
22
+
23
+ class FormResource(SyncAPIResource):
24
+ """Operations under ``client.form`` (OpenCode ``form``)."""
25
+
26
+ def list(
27
+ self,
28
+ *,
29
+ location: Location | NotGiven | None = NOT_GIVEN,
30
+ extra_headers: Headers | None = None,
31
+ extra_query: Query | None = None,
32
+ extra_body: Body | None = None,
33
+ timeout: Timeout | NotGiven = NOT_GIVEN,
34
+ ) -> FormListResponse:
35
+ """List pending forms.
36
+
37
+ Retrieve pending forms for a location.
38
+
39
+ Raises:
40
+ InvalidRequestError: The server answered 400.
41
+ UnauthorizedError: The server answered 401.
42
+ LocationNotFoundError: The server answered 404.
43
+
44
+ ``GET /api/form``
45
+ """
46
+ return cast(
47
+ "FormListResponse",
48
+ self._client.request(
49
+ RequestOptions(
50
+ method="GET",
51
+ path="/api/form",
52
+ query={"location": self._location(location)},
53
+ extra_headers=extra_headers,
54
+ extra_query=extra_query,
55
+ extra_body=extra_body,
56
+ timeout=timeout,
57
+ ),
58
+ response_type="FormListResponse",
59
+ ),
60
+ )
61
+
62
+
63
+ class AsyncFormResource(AsyncAPIResource):
64
+ """Operations under ``client.form`` (OpenCode ``form``)."""
65
+
66
+ async def list(
67
+ self,
68
+ *,
69
+ location: Location | NotGiven | None = NOT_GIVEN,
70
+ extra_headers: Headers | None = None,
71
+ extra_query: Query | None = None,
72
+ extra_body: Body | None = None,
73
+ timeout: Timeout | NotGiven = NOT_GIVEN,
74
+ ) -> FormListResponse:
75
+ """List pending forms.
76
+
77
+ Retrieve pending forms for a location.
78
+
79
+ Raises:
80
+ InvalidRequestError: The server answered 400.
81
+ UnauthorizedError: The server answered 401.
82
+ LocationNotFoundError: The server answered 404.
83
+
84
+ ``GET /api/form``
85
+ """
86
+ return cast(
87
+ "FormListResponse",
88
+ await self._client.request(
89
+ RequestOptions(
90
+ method="GET",
91
+ path="/api/form",
92
+ query={"location": self._location(location)},
93
+ extra_headers=extra_headers,
94
+ extra_query=extra_query,
95
+ extra_body=extra_body,
96
+ timeout=timeout,
97
+ ),
98
+ response_type="FormListResponse",
99
+ ),
100
+ )
@@ -0,0 +1,110 @@
1
+ # This file is generated by `python -m codegen` from spec/contract.json. Do not edit it by hand.
2
+ # OpenCode 2.1.2
3
+
4
+ """The ``generate`` resource."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from typing import TYPE_CHECKING, cast
9
+
10
+ from .._base_client import RequestOptions
11
+ from .._resource import AsyncAPIResource, SyncAPIResource
12
+ from .._types import NOT_GIVEN, Body, Headers, NotGiven, Query, Timeout
13
+
14
+ if TYPE_CHECKING:
15
+ from ..types import (
16
+ GenerateTextResponseData,
17
+ ModelRef,
18
+ )
19
+
20
+ __all__ = ["GenerateResource", "AsyncGenerateResource"]
21
+
22
+
23
+ class GenerateResource(SyncAPIResource):
24
+ """Operations under ``client.generate`` (OpenCode ``generate``)."""
25
+
26
+ def text(
27
+ self,
28
+ *,
29
+ prompt: str,
30
+ model: ModelRef | NotGiven | None = NOT_GIVEN,
31
+ extra_headers: Headers | None = None,
32
+ extra_query: Query | None = None,
33
+ extra_body: Body | None = None,
34
+ timeout: Timeout | NotGiven = NOT_GIVEN,
35
+ ) -> GenerateTextResponseData:
36
+ """Generate text.
37
+
38
+ Run one stateless model generation using the server's base configuration and return the assistant text. Uses the base configuration's default model when none is specified.
39
+
40
+ This endpoint is experimental in OpenCode and may change without notice.
41
+
42
+ Raises:
43
+ InvalidRequestError: The server answered 400.
44
+ UnauthorizedError: The server answered 401.
45
+ LocationNotFoundError: The server answered 404.
46
+ ServiceUnavailableError: The server answered 503.
47
+
48
+ ``POST /api/experimental/generate``
49
+ """
50
+ return cast(
51
+ "GenerateTextResponseData",
52
+ self._client.request(
53
+ RequestOptions(
54
+ method="POST",
55
+ path="/api/experimental/generate",
56
+ body={"prompt": prompt, "model": model},
57
+ extra_headers=extra_headers,
58
+ extra_query=extra_query,
59
+ extra_body=extra_body,
60
+ timeout=timeout,
61
+ ),
62
+ response_type="GenerateTextResponseData",
63
+ unwrap=True,
64
+ ),
65
+ )
66
+
67
+
68
+ class AsyncGenerateResource(AsyncAPIResource):
69
+ """Operations under ``client.generate`` (OpenCode ``generate``)."""
70
+
71
+ async def text(
72
+ self,
73
+ *,
74
+ prompt: str,
75
+ model: ModelRef | NotGiven | None = NOT_GIVEN,
76
+ extra_headers: Headers | None = None,
77
+ extra_query: Query | None = None,
78
+ extra_body: Body | None = None,
79
+ timeout: Timeout | NotGiven = NOT_GIVEN,
80
+ ) -> GenerateTextResponseData:
81
+ """Generate text.
82
+
83
+ Run one stateless model generation using the server's base configuration and return the assistant text. Uses the base configuration's default model when none is specified.
84
+
85
+ This endpoint is experimental in OpenCode and may change without notice.
86
+
87
+ Raises:
88
+ InvalidRequestError: The server answered 400.
89
+ UnauthorizedError: The server answered 401.
90
+ LocationNotFoundError: The server answered 404.
91
+ ServiceUnavailableError: The server answered 503.
92
+
93
+ ``POST /api/experimental/generate``
94
+ """
95
+ return cast(
96
+ "GenerateTextResponseData",
97
+ await self._client.request(
98
+ RequestOptions(
99
+ method="POST",
100
+ path="/api/experimental/generate",
101
+ body={"prompt": prompt, "model": model},
102
+ extra_headers=extra_headers,
103
+ extra_query=extra_query,
104
+ extra_body=extra_body,
105
+ timeout=timeout,
106
+ ),
107
+ response_type="GenerateTextResponseData",
108
+ unwrap=True,
109
+ ),
110
+ )