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