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,160 @@
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 ``location`` 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
+ Location,
15
+ LocationPublicInfo,
16
+ )
17
+
18
+ __all__ = ["LocationResource", "AsyncLocationResource"]
19
+
20
+
21
+ class LocationResource(SyncAPIResource):
22
+ """Operations under ``client.location`` (OpenCode ``location``)."""
23
+
24
+ def get(
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
+ ) -> LocationPublicInfo:
33
+ """Get location.
34
+
35
+ Resolve the requested location or the server default location.
36
+
37
+ Raises:
38
+ InvalidRequestError
39
+ UnauthorizedError
40
+ LocationNotFoundError
41
+
42
+ ``GET /api/location``
43
+ """
44
+ return cast(
45
+ "LocationPublicInfo",
46
+ self._client.request(
47
+ RequestOptions(
48
+ method="GET",
49
+ path="/api/location",
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=LocationPublicInfo,
57
+ ),
58
+ )
59
+
60
+ def reload(
61
+ self,
62
+ *,
63
+ extra_headers: Headers | None = None,
64
+ extra_query: Query | None = None,
65
+ extra_body: Body | None = None,
66
+ timeout: Timeout | NotGiven = NOT_GIVEN,
67
+ ) -> None:
68
+ """Reload configuration.
69
+
70
+ Shut down and rebuild every loaded location. Pending permissions and forms are cancelled; running sessions continue with fresh services at the next step boundary. Emits location.shutdown for client recovery and responds once all replacement builds settle.
71
+
72
+ Raises:
73
+ InvalidRequestError
74
+ UnauthorizedError
75
+ ServiceUnavailableError
76
+
77
+ ``POST /api/location/reload``
78
+ """
79
+ self._client.request(
80
+ RequestOptions(
81
+ method="POST",
82
+ path="/api/location/reload",
83
+ extra_headers=extra_headers,
84
+ extra_query=extra_query,
85
+ extra_body=extra_body,
86
+ timeout=timeout,
87
+ ),
88
+ kind="void",
89
+ )
90
+
91
+
92
+ class AsyncLocationResource(AsyncAPIResource):
93
+ """Operations under ``client.location`` (OpenCode ``location``)."""
94
+
95
+ async def get(
96
+ self,
97
+ *,
98
+ location: Location | NotGiven | None = NOT_GIVEN,
99
+ extra_headers: Headers | None = None,
100
+ extra_query: Query | None = None,
101
+ extra_body: Body | None = None,
102
+ timeout: Timeout | NotGiven = NOT_GIVEN,
103
+ ) -> LocationPublicInfo:
104
+ """Get location.
105
+
106
+ Resolve the requested location or the server default location.
107
+
108
+ Raises:
109
+ InvalidRequestError
110
+ UnauthorizedError
111
+ LocationNotFoundError
112
+
113
+ ``GET /api/location``
114
+ """
115
+ return cast(
116
+ "LocationPublicInfo",
117
+ await self._client.request(
118
+ RequestOptions(
119
+ method="GET",
120
+ path="/api/location",
121
+ query={"location": self._location(location)},
122
+ extra_headers=extra_headers,
123
+ extra_query=extra_query,
124
+ extra_body=extra_body,
125
+ timeout=timeout,
126
+ ),
127
+ response_type=LocationPublicInfo,
128
+ ),
129
+ )
130
+
131
+ async def reload(
132
+ self,
133
+ *,
134
+ extra_headers: Headers | None = None,
135
+ extra_query: Query | None = None,
136
+ extra_body: Body | None = None,
137
+ timeout: Timeout | NotGiven = NOT_GIVEN,
138
+ ) -> None:
139
+ """Reload configuration.
140
+
141
+ Shut down and rebuild every loaded location. Pending permissions and forms are cancelled; running sessions continue with fresh services at the next step boundary. Emits location.shutdown for client recovery and responds once all replacement builds settle.
142
+
143
+ Raises:
144
+ InvalidRequestError
145
+ UnauthorizedError
146
+ ServiceUnavailableError
147
+
148
+ ``POST /api/location/reload``
149
+ """
150
+ await self._client.request(
151
+ RequestOptions(
152
+ method="POST",
153
+ path="/api/location/reload",
154
+ extra_headers=extra_headers,
155
+ extra_query=extra_query,
156
+ extra_body=extra_body,
157
+ timeout=timeout,
158
+ ),
159
+ kind="void",
160
+ )
@@ -0,0 +1,488 @@
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 ``mcp`` resource."""
5
+
6
+ from __future__ import annotations
7
+
8
+ from functools import cached_property
9
+ from typing import cast
10
+
11
+ from .._base_client import RequestOptions
12
+ from .._qs import encode_path_segment
13
+ from .._resource import AsyncAPIResource, SyncAPIResource
14
+ from .._types import NOT_GIVEN, Body, Headers, NotGiven, Query, Timeout
15
+ from ..types import (
16
+ Location,
17
+ McpAddConfig,
18
+ McpListResponse,
19
+ McpResourceCatalogResponse,
20
+ )
21
+
22
+ __all__ = ["McpResource", "AsyncMcpResource"]
23
+
24
+
25
+ class McpResourceResource(SyncAPIResource):
26
+ """Operations under ``client.mcp.resource`` (OpenCode ``mcp.resource``)."""
27
+
28
+ def catalog(
29
+ self,
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
+ ) -> McpResourceCatalogResponse:
37
+ """List MCP resources.
38
+
39
+ Retrieve resources and resource templates from connected MCP servers.
40
+
41
+ Raises:
42
+ InvalidRequestError
43
+ UnauthorizedError
44
+ LocationNotFoundError
45
+
46
+ ``GET /api/mcp/resource``
47
+ """
48
+ return cast(
49
+ "McpResourceCatalogResponse",
50
+ self._client.request(
51
+ RequestOptions(
52
+ method="GET",
53
+ path="/api/mcp/resource",
54
+ query={"location": self._location(location)},
55
+ extra_headers=extra_headers,
56
+ extra_query=extra_query,
57
+ extra_body=extra_body,
58
+ timeout=timeout,
59
+ ),
60
+ response_type=McpResourceCatalogResponse,
61
+ ),
62
+ )
63
+
64
+
65
+ class McpResource(SyncAPIResource):
66
+ """Operations under ``client.mcp`` (OpenCode ``mcp``)."""
67
+
68
+ @cached_property
69
+ def resource(self) -> McpResourceResource:
70
+ return McpResourceResource(self._client)
71
+
72
+ def list(
73
+ self,
74
+ *,
75
+ location: Location | 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
+ ) -> McpListResponse:
81
+ """List MCP servers.
82
+
83
+ Retrieve configured MCP servers and their connection status.
84
+
85
+ Raises:
86
+ InvalidRequestError
87
+ UnauthorizedError
88
+ LocationNotFoundError
89
+
90
+ ``GET /api/mcp``
91
+ """
92
+ return cast(
93
+ "McpListResponse",
94
+ self._client.request(
95
+ RequestOptions(
96
+ method="GET",
97
+ path="/api/mcp",
98
+ query={"location": self._location(location)},
99
+ extra_headers=extra_headers,
100
+ extra_query=extra_query,
101
+ extra_body=extra_body,
102
+ timeout=timeout,
103
+ ),
104
+ response_type=McpListResponse,
105
+ ),
106
+ )
107
+
108
+ def add(
109
+ self,
110
+ server: str,
111
+ *,
112
+ config: McpAddConfig,
113
+ location: Location | NotGiven | None = NOT_GIVEN,
114
+ extra_headers: Headers | None = None,
115
+ extra_query: Query | None = None,
116
+ extra_body: Body | None = None,
117
+ timeout: Timeout | NotGiven = NOT_GIVEN,
118
+ ) -> None:
119
+ """Add MCP server.
120
+
121
+ Add an MCP server at runtime or replace an existing one, connecting it immediately.
122
+
123
+ This endpoint is experimental in OpenCode and may change without notice.
124
+
125
+ Raises:
126
+ InvalidRequestError
127
+ UnauthorizedError
128
+ LocationNotFoundError
129
+
130
+ ``PUT /api/experimental/mcp/:server``
131
+ """
132
+ self._client.request(
133
+ RequestOptions(
134
+ method="PUT",
135
+ path=f"/api/experimental/mcp/{encode_path_segment(server)}",
136
+ query={"location": self._location(location)},
137
+ body={"config": config},
138
+ extra_headers=extra_headers,
139
+ extra_query=extra_query,
140
+ extra_body=extra_body,
141
+ timeout=timeout,
142
+ ),
143
+ kind="void",
144
+ )
145
+
146
+ def remove(
147
+ self,
148
+ server: str,
149
+ *,
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
+ ) -> None:
156
+ """Remove MCP server.
157
+
158
+ Stop an MCP server and remove it from the runtime set until restart.
159
+
160
+ This endpoint is experimental in OpenCode and may change without notice.
161
+
162
+ Raises:
163
+ InvalidRequestError
164
+ UnauthorizedError
165
+ McpServerNotFoundError
166
+ LocationNotFoundError
167
+
168
+ ``DELETE /api/experimental/mcp/:server``
169
+ """
170
+ self._client.request(
171
+ RequestOptions(
172
+ method="DELETE",
173
+ path=f"/api/experimental/mcp/{encode_path_segment(server)}",
174
+ query={"location": self._location(location)},
175
+ extra_headers=extra_headers,
176
+ extra_query=extra_query,
177
+ extra_body=extra_body,
178
+ timeout=timeout,
179
+ ),
180
+ kind="void",
181
+ )
182
+
183
+ def connect(
184
+ self,
185
+ server: str,
186
+ *,
187
+ location: Location | NotGiven | None = NOT_GIVEN,
188
+ extra_headers: Headers | None = None,
189
+ extra_query: Query | None = None,
190
+ extra_body: Body | None = None,
191
+ timeout: Timeout | NotGiven = NOT_GIVEN,
192
+ ) -> None:
193
+ """Connect MCP server.
194
+
195
+ Connect an MCP server at runtime, overriding a disabled configuration until restart.
196
+
197
+ This endpoint is experimental in OpenCode and may change without notice.
198
+
199
+ Raises:
200
+ InvalidRequestError
201
+ UnauthorizedError
202
+ McpServerNotFoundError
203
+ LocationNotFoundError
204
+
205
+ ``POST /api/experimental/mcp/:server/connect``
206
+ """
207
+ self._client.request(
208
+ RequestOptions(
209
+ method="POST",
210
+ path=f"/api/experimental/mcp/{encode_path_segment(server)}/connect",
211
+ query={"location": self._location(location)},
212
+ extra_headers=extra_headers,
213
+ extra_query=extra_query,
214
+ extra_body=extra_body,
215
+ timeout=timeout,
216
+ ),
217
+ kind="void",
218
+ )
219
+
220
+ def disconnect(
221
+ self,
222
+ server: str,
223
+ *,
224
+ location: Location | NotGiven | None = NOT_GIVEN,
225
+ extra_headers: Headers | None = None,
226
+ extra_query: Query | None = None,
227
+ extra_body: Body | None = None,
228
+ timeout: Timeout | NotGiven = NOT_GIVEN,
229
+ ) -> None:
230
+ """Disconnect MCP server.
231
+
232
+ Disconnect an MCP server at runtime, removing its tools until reconnected.
233
+
234
+ This endpoint is experimental in OpenCode and may change without notice.
235
+
236
+ Raises:
237
+ InvalidRequestError
238
+ UnauthorizedError
239
+ McpServerNotFoundError
240
+ LocationNotFoundError
241
+
242
+ ``POST /api/experimental/mcp/:server/disconnect``
243
+ """
244
+ self._client.request(
245
+ RequestOptions(
246
+ method="POST",
247
+ path=f"/api/experimental/mcp/{encode_path_segment(server)}/disconnect",
248
+ query={"location": self._location(location)},
249
+ extra_headers=extra_headers,
250
+ extra_query=extra_query,
251
+ extra_body=extra_body,
252
+ timeout=timeout,
253
+ ),
254
+ kind="void",
255
+ )
256
+
257
+
258
+ class AsyncMcpResourceResource(AsyncAPIResource):
259
+ """Operations under ``client.mcp.resource`` (OpenCode ``mcp.resource``)."""
260
+
261
+ async def catalog(
262
+ self,
263
+ *,
264
+ location: Location | NotGiven | None = NOT_GIVEN,
265
+ extra_headers: Headers | None = None,
266
+ extra_query: Query | None = None,
267
+ extra_body: Body | None = None,
268
+ timeout: Timeout | NotGiven = NOT_GIVEN,
269
+ ) -> McpResourceCatalogResponse:
270
+ """List MCP resources.
271
+
272
+ Retrieve resources and resource templates from connected MCP servers.
273
+
274
+ Raises:
275
+ InvalidRequestError
276
+ UnauthorizedError
277
+ LocationNotFoundError
278
+
279
+ ``GET /api/mcp/resource``
280
+ """
281
+ return cast(
282
+ "McpResourceCatalogResponse",
283
+ await self._client.request(
284
+ RequestOptions(
285
+ method="GET",
286
+ path="/api/mcp/resource",
287
+ query={"location": self._location(location)},
288
+ extra_headers=extra_headers,
289
+ extra_query=extra_query,
290
+ extra_body=extra_body,
291
+ timeout=timeout,
292
+ ),
293
+ response_type=McpResourceCatalogResponse,
294
+ ),
295
+ )
296
+
297
+
298
+ class AsyncMcpResource(AsyncAPIResource):
299
+ """Operations under ``client.mcp`` (OpenCode ``mcp``)."""
300
+
301
+ @cached_property
302
+ def resource(self) -> AsyncMcpResourceResource:
303
+ return AsyncMcpResourceResource(self._client)
304
+
305
+ async def list(
306
+ self,
307
+ *,
308
+ location: Location | NotGiven | None = NOT_GIVEN,
309
+ extra_headers: Headers | None = None,
310
+ extra_query: Query | None = None,
311
+ extra_body: Body | None = None,
312
+ timeout: Timeout | NotGiven = NOT_GIVEN,
313
+ ) -> McpListResponse:
314
+ """List MCP servers.
315
+
316
+ Retrieve configured MCP servers and their connection status.
317
+
318
+ Raises:
319
+ InvalidRequestError
320
+ UnauthorizedError
321
+ LocationNotFoundError
322
+
323
+ ``GET /api/mcp``
324
+ """
325
+ return cast(
326
+ "McpListResponse",
327
+ await self._client.request(
328
+ RequestOptions(
329
+ method="GET",
330
+ path="/api/mcp",
331
+ query={"location": self._location(location)},
332
+ extra_headers=extra_headers,
333
+ extra_query=extra_query,
334
+ extra_body=extra_body,
335
+ timeout=timeout,
336
+ ),
337
+ response_type=McpListResponse,
338
+ ),
339
+ )
340
+
341
+ async def add(
342
+ self,
343
+ server: str,
344
+ *,
345
+ config: McpAddConfig,
346
+ location: Location | NotGiven | None = NOT_GIVEN,
347
+ extra_headers: Headers | None = None,
348
+ extra_query: Query | None = None,
349
+ extra_body: Body | None = None,
350
+ timeout: Timeout | NotGiven = NOT_GIVEN,
351
+ ) -> None:
352
+ """Add MCP server.
353
+
354
+ Add an MCP server at runtime or replace an existing one, connecting it immediately.
355
+
356
+ This endpoint is experimental in OpenCode and may change without notice.
357
+
358
+ Raises:
359
+ InvalidRequestError
360
+ UnauthorizedError
361
+ LocationNotFoundError
362
+
363
+ ``PUT /api/experimental/mcp/:server``
364
+ """
365
+ await self._client.request(
366
+ RequestOptions(
367
+ method="PUT",
368
+ path=f"/api/experimental/mcp/{encode_path_segment(server)}",
369
+ query={"location": self._location(location)},
370
+ body={"config": config},
371
+ extra_headers=extra_headers,
372
+ extra_query=extra_query,
373
+ extra_body=extra_body,
374
+ timeout=timeout,
375
+ ),
376
+ kind="void",
377
+ )
378
+
379
+ async def remove(
380
+ self,
381
+ server: str,
382
+ *,
383
+ location: Location | NotGiven | None = NOT_GIVEN,
384
+ extra_headers: Headers | None = None,
385
+ extra_query: Query | None = None,
386
+ extra_body: Body | None = None,
387
+ timeout: Timeout | NotGiven = NOT_GIVEN,
388
+ ) -> None:
389
+ """Remove MCP server.
390
+
391
+ Stop an MCP server and remove it from the runtime set until restart.
392
+
393
+ This endpoint is experimental in OpenCode and may change without notice.
394
+
395
+ Raises:
396
+ InvalidRequestError
397
+ UnauthorizedError
398
+ McpServerNotFoundError
399
+ LocationNotFoundError
400
+
401
+ ``DELETE /api/experimental/mcp/:server``
402
+ """
403
+ await self._client.request(
404
+ RequestOptions(
405
+ method="DELETE",
406
+ path=f"/api/experimental/mcp/{encode_path_segment(server)}",
407
+ query={"location": self._location(location)},
408
+ extra_headers=extra_headers,
409
+ extra_query=extra_query,
410
+ extra_body=extra_body,
411
+ timeout=timeout,
412
+ ),
413
+ kind="void",
414
+ )
415
+
416
+ async def connect(
417
+ self,
418
+ server: str,
419
+ *,
420
+ location: Location | NotGiven | None = NOT_GIVEN,
421
+ extra_headers: Headers | None = None,
422
+ extra_query: Query | None = None,
423
+ extra_body: Body | None = None,
424
+ timeout: Timeout | NotGiven = NOT_GIVEN,
425
+ ) -> None:
426
+ """Connect MCP server.
427
+
428
+ Connect an MCP server at runtime, overriding a disabled configuration until restart.
429
+
430
+ This endpoint is experimental in OpenCode and may change without notice.
431
+
432
+ Raises:
433
+ InvalidRequestError
434
+ UnauthorizedError
435
+ McpServerNotFoundError
436
+ LocationNotFoundError
437
+
438
+ ``POST /api/experimental/mcp/:server/connect``
439
+ """
440
+ await self._client.request(
441
+ RequestOptions(
442
+ method="POST",
443
+ path=f"/api/experimental/mcp/{encode_path_segment(server)}/connect",
444
+ query={"location": self._location(location)},
445
+ extra_headers=extra_headers,
446
+ extra_query=extra_query,
447
+ extra_body=extra_body,
448
+ timeout=timeout,
449
+ ),
450
+ kind="void",
451
+ )
452
+
453
+ async def disconnect(
454
+ self,
455
+ server: str,
456
+ *,
457
+ location: Location | NotGiven | None = NOT_GIVEN,
458
+ extra_headers: Headers | None = None,
459
+ extra_query: Query | None = None,
460
+ extra_body: Body | None = None,
461
+ timeout: Timeout | NotGiven = NOT_GIVEN,
462
+ ) -> None:
463
+ """Disconnect MCP server.
464
+
465
+ Disconnect an MCP server at runtime, removing its tools until reconnected.
466
+
467
+ This endpoint is experimental in OpenCode and may change without notice.
468
+
469
+ Raises:
470
+ InvalidRequestError
471
+ UnauthorizedError
472
+ McpServerNotFoundError
473
+ LocationNotFoundError
474
+
475
+ ``POST /api/experimental/mcp/:server/disconnect``
476
+ """
477
+ await self._client.request(
478
+ RequestOptions(
479
+ method="POST",
480
+ path=f"/api/experimental/mcp/{encode_path_segment(server)}/disconnect",
481
+ query={"location": self._location(location)},
482
+ extra_headers=extra_headers,
483
+ extra_query=extra_query,
484
+ extra_body=extra_body,
485
+ timeout=timeout,
486
+ ),
487
+ kind="void",
488
+ )