opencode-python-sdk 0.1.0__py3-none-any.whl → 0.1.1__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 (38) hide show
  1. opencode/_exceptions.py +22 -0
  2. opencode/_server.py +8 -0
  3. opencode/resources/agent.py +14 -14
  4. opencode/resources/command.py +6 -6
  5. opencode/resources/config.py +18 -18
  6. opencode/resources/credential.py +22 -22
  7. opencode/resources/debug.py +10 -8
  8. opencode/resources/event.py +4 -4
  9. opencode/resources/experimental.py +74 -72
  10. opencode/resources/file.py +28 -28
  11. opencode/resources/form.py +6 -6
  12. opencode/resources/generate.py +8 -8
  13. opencode/resources/integration.py +102 -94
  14. opencode/resources/location.py +12 -12
  15. opencode/resources/mcp.py +44 -42
  16. opencode/resources/message.py +10 -10
  17. opencode/resources/migration.py +6 -4
  18. opencode/resources/model.py +16 -16
  19. opencode/resources/permission.py +68 -64
  20. opencode/resources/plugin.py +20 -20
  21. opencode/resources/project.py +14 -14
  22. opencode/resources/provider.py +18 -18
  23. opencode/resources/pty.py +48 -46
  24. opencode/resources/reference.py +6 -6
  25. opencode/resources/rpc.py +10 -10
  26. opencode/resources/server.py +12 -12
  27. opencode/resources/session.py +378 -366
  28. opencode/resources/shell.py +34 -34
  29. opencode/resources/skill.py +6 -6
  30. opencode/resources/vcs.py +48 -46
  31. opencode/resources/voice.py +8 -8
  32. opencode/resources/websearch.py +16 -16
  33. opencode/resources/worktree.py +30 -30
  34. {opencode_python_sdk-0.1.0.dist-info → opencode_python_sdk-0.1.1.dist-info}/METADATA +5 -2
  35. opencode_python_sdk-0.1.1.dist-info/RECORD +55 -0
  36. opencode_python_sdk-0.1.0.dist-info/RECORD +0 -55
  37. {opencode_python_sdk-0.1.0.dist-info → opencode_python_sdk-0.1.1.dist-info}/WHEEL +0 -0
  38. {opencode_python_sdk-0.1.0.dist-info → opencode_python_sdk-0.1.1.dist-info}/licenses/LICENSE +0 -0
opencode/_exceptions.py CHANGED
@@ -147,47 +147,69 @@ class APIStatusError(APIError):
147
147
 
148
148
 
149
149
  class BadRequestError(APIStatusError):
150
+ """The server rejected the request as malformed (400)."""
151
+
150
152
  status = 400
151
153
 
152
154
 
153
155
  class AuthenticationError(APIStatusError):
156
+ """The password was missing or wrong (401)."""
157
+
154
158
  status = 401
155
159
 
156
160
 
157
161
  class PermissionDeniedError(APIStatusError):
162
+ """The request is not allowed (403)."""
163
+
158
164
  status = 403
159
165
 
160
166
 
161
167
  class NotFoundError(APIStatusError):
168
+ """The requested resource does not exist (404)."""
169
+
162
170
  status = 404
163
171
 
164
172
 
165
173
  class ConflictError(APIStatusError):
174
+ """The request conflicts with the current state, for example a busy session (409)."""
175
+
166
176
  status = 409
167
177
  tag = "ConflictError"
168
178
 
169
179
 
170
180
  class ContentTooLargeError(APIStatusError):
181
+ """The request body is too large (413)."""
182
+
171
183
  status = 413
172
184
 
173
185
 
174
186
  class UnprocessableEntityError(APIStatusError):
187
+ """The request was well formed but could not be processed (422)."""
188
+
175
189
  status = 422
176
190
 
177
191
 
178
192
  class RateLimitError(APIStatusError):
193
+ """Too many requests (429). Retried automatically, honoring ``Retry-After``."""
194
+
179
195
  status = 429
180
196
 
181
197
 
182
198
  class InternalServerError(APIStatusError):
199
+ """The server failed (500, and the base class for every 5xx)."""
200
+
183
201
  status = 500
184
202
 
185
203
 
186
204
  class NotImplementedServerError(InternalServerError):
205
+ """The server does not implement this endpoint (501)."""
206
+
187
207
  status = 501
188
208
 
189
209
 
190
210
  class ServiceUnavailableError(InternalServerError):
211
+ """The server is temporarily unavailable (503). Retried automatically."""
212
+
191
213
  status = 503
192
214
  tag = "ServiceUnavailableError"
193
215
 
opencode/_server.py CHANGED
@@ -109,10 +109,12 @@ class OpencodeServer:
109
109
 
110
110
  @property
111
111
  def process(self) -> subprocess.Popen[str] | None:
112
+ """The ``opencode serve`` child process, or ``None`` before it starts."""
112
113
  return self._process
113
114
 
114
115
  @property
115
116
  def running(self) -> bool:
117
+ """Whether the server process is alive."""
116
118
  return self._process is not None and self._process.poll() is None
117
119
 
118
120
  def client(self, *, directory: str | os.PathLike[str] | None = None, timeout: Timeout | None = None) -> Opencode:
@@ -291,18 +293,22 @@ class AsyncOpencodeServer:
291
293
 
292
294
  @property
293
295
  def url(self) -> str:
296
+ """The server's base URL. Available once started."""
294
297
  return self._server.url
295
298
 
296
299
  @property
297
300
  def password(self) -> str:
301
+ """The server password clients authenticate with."""
298
302
  return self._server.password
299
303
 
300
304
  @property
301
305
  def running(self) -> bool:
306
+ """Whether the server process is alive."""
302
307
  return self._server.running
303
308
 
304
309
  @property
305
310
  def output(self) -> str:
311
+ """The last lines the server wrote, for diagnostics."""
306
312
  return self._server.output
307
313
 
308
314
  def client(
@@ -312,10 +318,12 @@ class AsyncOpencodeServer:
312
318
  return self._server.async_client(directory=directory, timeout=timeout)
313
319
 
314
320
  async def start(self) -> Self:
321
+ """Starts the server and waits until it reports its address."""
315
322
  await anyio.to_thread.run_sync(self._server.start)
316
323
  return self
317
324
 
318
325
  async def stop(self, timeout: float = 10.0) -> None:
326
+ """Stops the server: closes its stdin, then terminates it if it has not exited within ``timeout``."""
319
327
  await anyio.to_thread.run_sync(lambda: self._server.stop(timeout))
320
328
 
321
329
  async def __aenter__(self) -> Self:
@@ -38,9 +38,9 @@ class AgentResource(SyncAPIResource):
38
38
  Retrieve currently registered agents.
39
39
 
40
40
  Raises:
41
- InvalidRequestError
42
- UnauthorizedError
43
- LocationNotFoundError
41
+ InvalidRequestError: The server answered 400.
42
+ UnauthorizedError: The server answered 401.
43
+ LocationNotFoundError: The server answered 404.
44
44
 
45
45
  ``GET /api/agent``
46
46
  """
@@ -75,10 +75,10 @@ class AgentResource(SyncAPIResource):
75
75
  Retrieve a single currently registered agent.
76
76
 
77
77
  Raises:
78
- InvalidRequestError
79
- UnauthorizedError
80
- AgentNotFoundError
81
- LocationNotFoundError
78
+ InvalidRequestError: The server answered 400.
79
+ UnauthorizedError: The server answered 401.
80
+ AgentNotFoundError: The server answered 404.
81
+ LocationNotFoundError: The server answered 404.
82
82
 
83
83
  ``GET /api/agent/:agentID``
84
84
  """
@@ -116,9 +116,9 @@ class AsyncAgentResource(AsyncAPIResource):
116
116
  Retrieve currently registered agents.
117
117
 
118
118
  Raises:
119
- InvalidRequestError
120
- UnauthorizedError
121
- LocationNotFoundError
119
+ InvalidRequestError: The server answered 400.
120
+ UnauthorizedError: The server answered 401.
121
+ LocationNotFoundError: The server answered 404.
122
122
 
123
123
  ``GET /api/agent``
124
124
  """
@@ -153,10 +153,10 @@ class AsyncAgentResource(AsyncAPIResource):
153
153
  Retrieve a single currently registered agent.
154
154
 
155
155
  Raises:
156
- InvalidRequestError
157
- UnauthorizedError
158
- AgentNotFoundError
159
- LocationNotFoundError
156
+ InvalidRequestError: The server answered 400.
157
+ UnauthorizedError: The server answered 401.
158
+ AgentNotFoundError: The server answered 404.
159
+ LocationNotFoundError: The server answered 404.
160
160
 
161
161
  ``GET /api/agent/:agentID``
162
162
  """
@@ -35,9 +35,9 @@ class CommandResource(SyncAPIResource):
35
35
  Retrieve currently registered commands.
36
36
 
37
37
  Raises:
38
- InvalidRequestError
39
- UnauthorizedError
40
- LocationNotFoundError
38
+ InvalidRequestError: The server answered 400.
39
+ UnauthorizedError: The server answered 401.
40
+ LocationNotFoundError: The server answered 404.
41
41
 
42
42
  ``GET /api/command``
43
43
  """
@@ -75,9 +75,9 @@ class AsyncCommandResource(AsyncAPIResource):
75
75
  Retrieve currently registered commands.
76
76
 
77
77
  Raises:
78
- InvalidRequestError
79
- UnauthorizedError
80
- LocationNotFoundError
78
+ InvalidRequestError: The server answered 400.
79
+ UnauthorizedError: The server answered 401.
80
+ LocationNotFoundError: The server answered 404.
81
81
 
82
82
  ``GET /api/command``
83
83
  """
@@ -37,9 +37,9 @@ class ConfigResource(SyncAPIResource):
37
37
  Return configuration documents and discovery sources for the requested location, from lowest to highest priority.
38
38
 
39
39
  Raises:
40
- InvalidRequestError
41
- UnauthorizedError
42
- LocationNotFoundError
40
+ InvalidRequestError: The server answered 400.
41
+ UnauthorizedError: The server answered 401.
42
+ LocationNotFoundError: The server answered 404.
43
43
 
44
44
  ``GET /api/config``
45
45
  """
@@ -72,9 +72,9 @@ class ConfigResource(SyncAPIResource):
72
72
  Return shells available to terminal and agent execution.
73
73
 
74
74
  Raises:
75
- InvalidRequestError
76
- UnauthorizedError
77
- LocationNotFoundError
75
+ InvalidRequestError: The server answered 400.
76
+ UnauthorizedError: The server answered 401.
77
+ LocationNotFoundError: The server answered 404.
78
78
 
79
79
  ``GET /api/config/shell``
80
80
  """
@@ -109,9 +109,9 @@ class ConfigResource(SyncAPIResource):
109
109
  This endpoint is experimental in OpenCode and may change without notice.
110
110
 
111
111
  Raises:
112
- InvalidRequestError
113
- UnauthorizedError
114
- LocationNotFoundError
112
+ InvalidRequestError: The server answered 400.
113
+ UnauthorizedError: The server answered 401.
114
+ LocationNotFoundError: The server answered 404.
115
115
 
116
116
  ``PATCH /api/experimental/config``
117
117
  """
@@ -146,9 +146,9 @@ class AsyncConfigResource(AsyncAPIResource):
146
146
  Return configuration documents and discovery sources for the requested location, from lowest to highest priority.
147
147
 
148
148
  Raises:
149
- InvalidRequestError
150
- UnauthorizedError
151
- LocationNotFoundError
149
+ InvalidRequestError: The server answered 400.
150
+ UnauthorizedError: The server answered 401.
151
+ LocationNotFoundError: The server answered 404.
152
152
 
153
153
  ``GET /api/config``
154
154
  """
@@ -181,9 +181,9 @@ class AsyncConfigResource(AsyncAPIResource):
181
181
  Return shells available to terminal and agent execution.
182
182
 
183
183
  Raises:
184
- InvalidRequestError
185
- UnauthorizedError
186
- LocationNotFoundError
184
+ InvalidRequestError: The server answered 400.
185
+ UnauthorizedError: The server answered 401.
186
+ LocationNotFoundError: The server answered 404.
187
187
 
188
188
  ``GET /api/config/shell``
189
189
  """
@@ -218,9 +218,9 @@ class AsyncConfigResource(AsyncAPIResource):
218
218
  This endpoint is experimental in OpenCode and may change without notice.
219
219
 
220
220
  Raises:
221
- InvalidRequestError
222
- UnauthorizedError
223
- LocationNotFoundError
221
+ InvalidRequestError: The server answered 400.
222
+ UnauthorizedError: The server answered 401.
223
+ LocationNotFoundError: The server answered 404.
224
224
 
225
225
  ``PATCH /api/experimental/config``
226
226
  """
@@ -38,8 +38,8 @@ class CredentialResource(SyncAPIResource):
38
38
  List every stored integration credential, including its secret value.
39
39
 
40
40
  Raises:
41
- InvalidRequestError
42
- UnauthorizedError
41
+ InvalidRequestError: The server answered 400.
42
+ UnauthorizedError: The server answered 401.
43
43
 
44
44
  ``GET /api/credential``
45
45
  """
@@ -77,9 +77,9 @@ class CredentialResource(SyncAPIResource):
77
77
  Store an integration credential. It becomes the integration's active credential unless activate is false and the integration already has one. Fails with a conflict when the requested ID already exists.
78
78
 
79
79
  Raises:
80
- InvalidRequestError
81
- UnauthorizedError
82
- ConflictError
80
+ InvalidRequestError: The server answered 400.
81
+ UnauthorizedError: The server answered 401.
82
+ ConflictError: The server answered 409.
83
83
 
84
84
  ``POST /api/credential``
85
85
  """
@@ -121,8 +121,8 @@ class CredentialResource(SyncAPIResource):
121
121
  Update a stored credential label.
122
122
 
123
123
  Raises:
124
- InvalidRequestError
125
- UnauthorizedError
124
+ InvalidRequestError: The server answered 400.
125
+ UnauthorizedError: The server answered 401.
126
126
 
127
127
  ``PATCH /api/credential/:credentialID``
128
128
  """
@@ -153,8 +153,8 @@ class CredentialResource(SyncAPIResource):
153
153
  Activate a stored integration credential.
154
154
 
155
155
  Raises:
156
- InvalidRequestError
157
- UnauthorizedError
156
+ InvalidRequestError: The server answered 400.
157
+ UnauthorizedError: The server answered 401.
158
158
 
159
159
  ``POST /api/credential/:credentialID/activate``
160
160
  """
@@ -184,8 +184,8 @@ class CredentialResource(SyncAPIResource):
184
184
  Remove a stored integration credential.
185
185
 
186
186
  Raises:
187
- InvalidRequestError
188
- UnauthorizedError
187
+ InvalidRequestError: The server answered 400.
188
+ UnauthorizedError: The server answered 401.
189
189
 
190
190
  ``DELETE /api/credential/:credentialID``
191
191
  """
@@ -218,8 +218,8 @@ class AsyncCredentialResource(AsyncAPIResource):
218
218
  List every stored integration credential, including its secret value.
219
219
 
220
220
  Raises:
221
- InvalidRequestError
222
- UnauthorizedError
221
+ InvalidRequestError: The server answered 400.
222
+ UnauthorizedError: The server answered 401.
223
223
 
224
224
  ``GET /api/credential``
225
225
  """
@@ -257,9 +257,9 @@ class AsyncCredentialResource(AsyncAPIResource):
257
257
  Store an integration credential. It becomes the integration's active credential unless activate is false and the integration already has one. Fails with a conflict when the requested ID already exists.
258
258
 
259
259
  Raises:
260
- InvalidRequestError
261
- UnauthorizedError
262
- ConflictError
260
+ InvalidRequestError: The server answered 400.
261
+ UnauthorizedError: The server answered 401.
262
+ ConflictError: The server answered 409.
263
263
 
264
264
  ``POST /api/credential``
265
265
  """
@@ -301,8 +301,8 @@ class AsyncCredentialResource(AsyncAPIResource):
301
301
  Update a stored credential label.
302
302
 
303
303
  Raises:
304
- InvalidRequestError
305
- UnauthorizedError
304
+ InvalidRequestError: The server answered 400.
305
+ UnauthorizedError: The server answered 401.
306
306
 
307
307
  ``PATCH /api/credential/:credentialID``
308
308
  """
@@ -333,8 +333,8 @@ class AsyncCredentialResource(AsyncAPIResource):
333
333
  Activate a stored integration credential.
334
334
 
335
335
  Raises:
336
- InvalidRequestError
337
- UnauthorizedError
336
+ InvalidRequestError: The server answered 400.
337
+ UnauthorizedError: The server answered 401.
338
338
 
339
339
  ``POST /api/credential/:credentialID/activate``
340
340
  """
@@ -364,8 +364,8 @@ class AsyncCredentialResource(AsyncAPIResource):
364
364
  Remove a stored integration credential.
365
365
 
366
366
  Raises:
367
- InvalidRequestError
368
- UnauthorizedError
367
+ InvalidRequestError: The server answered 400.
368
+ UnauthorizedError: The server answered 401.
369
369
 
370
370
  ``DELETE /api/credential/:credentialID``
371
371
  """
@@ -36,8 +36,8 @@ class DebugLocationResource(SyncAPIResource):
36
36
  List locations currently loaded by the server.
37
37
 
38
38
  Raises:
39
- InvalidRequestError
40
- UnauthorizedError
39
+ InvalidRequestError: The server answered 400.
40
+ UnauthorizedError: The server answered 401.
41
41
 
42
42
  ``GET /api/debug/location``
43
43
  """
@@ -70,8 +70,8 @@ class DebugLocationResource(SyncAPIResource):
70
70
  Dispose the requested location's cached services so its next use boots them fresh.
71
71
 
72
72
  Raises:
73
- InvalidRequestError
74
- UnauthorizedError
73
+ InvalidRequestError: The server answered 400.
74
+ UnauthorizedError: The server answered 401.
75
75
 
76
76
  ``DELETE /api/debug/location``
77
77
  """
@@ -94,6 +94,7 @@ class DebugResource(SyncAPIResource):
94
94
 
95
95
  @cached_property
96
96
  def location(self) -> DebugLocationResource:
97
+ """Operations under ``client.debug.location``."""
97
98
  return DebugLocationResource(self._client)
98
99
 
99
100
 
@@ -113,8 +114,8 @@ class AsyncDebugLocationResource(AsyncAPIResource):
113
114
  List locations currently loaded by the server.
114
115
 
115
116
  Raises:
116
- InvalidRequestError
117
- UnauthorizedError
117
+ InvalidRequestError: The server answered 400.
118
+ UnauthorizedError: The server answered 401.
118
119
 
119
120
  ``GET /api/debug/location``
120
121
  """
@@ -147,8 +148,8 @@ class AsyncDebugLocationResource(AsyncAPIResource):
147
148
  Dispose the requested location's cached services so its next use boots them fresh.
148
149
 
149
150
  Raises:
150
- InvalidRequestError
151
- UnauthorizedError
151
+ InvalidRequestError: The server answered 400.
152
+ UnauthorizedError: The server answered 401.
152
153
 
153
154
  ``DELETE /api/debug/location``
154
155
  """
@@ -171,4 +172,5 @@ class AsyncDebugResource(AsyncAPIResource):
171
172
 
172
173
  @cached_property
173
174
  def location(self) -> AsyncDebugLocationResource:
175
+ """Operations under ``client.debug.location``."""
174
176
  return AsyncDebugLocationResource(self._client)
@@ -32,8 +32,8 @@ class EventResource(SyncAPIResource):
32
32
  Subscribe to native events and plugin RPC events across all server locations. Volatile by contract: a slow consumer overflows and fails the stream, and events during disconnection are missed.
33
33
 
34
34
  Raises:
35
- InvalidRequestError
36
- UnauthorizedError
35
+ InvalidRequestError: The server answered 400.
36
+ UnauthorizedError: The server answered 401.
37
37
 
38
38
  ``GET /api/event``
39
39
  """
@@ -66,8 +66,8 @@ class AsyncEventResource(AsyncAPIResource):
66
66
  Subscribe to native events and plugin RPC events across all server locations. Volatile by contract: a slow consumer overflows and fails the stream, and events during disconnection are missed.
67
67
 
68
68
  Raises:
69
- InvalidRequestError
70
- UnauthorizedError
69
+ InvalidRequestError: The server answered 400.
70
+ UnauthorizedError: The server answered 401.
71
71
 
72
72
  ``GET /api/event``
73
73
  """