codeset 0.4.4__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.
- codeset/__init__.py +92 -0
- codeset/_base_client.py +2001 -0
- codeset/_client.py +572 -0
- codeset/_compat.py +219 -0
- codeset/_constants.py +14 -0
- codeset/_exceptions.py +108 -0
- codeset/_files.py +123 -0
- codeset/_models.py +857 -0
- codeset/_qs.py +150 -0
- codeset/_resource.py +43 -0
- codeset/_response.py +830 -0
- codeset/_streaming.py +333 -0
- codeset/_types.py +261 -0
- codeset/_utils/__init__.py +66 -0
- codeset/_utils/_compat.py +45 -0
- codeset/_utils/_datetime_parse.py +136 -0
- codeset/_utils/_logs.py +25 -0
- codeset/_utils/_proxy.py +65 -0
- codeset/_utils/_reflection.py +42 -0
- codeset/_utils/_resources_proxy.py +24 -0
- codeset/_utils/_streams.py +12 -0
- codeset/_utils/_sync.py +58 -0
- codeset/_utils/_transform.py +457 -0
- codeset/_utils/_typing.py +156 -0
- codeset/_utils/_utils.py +474 -0
- codeset/_version.py +4 -0
- codeset/lib/.keep +4 -0
- codeset/py.typed +0 -0
- codeset/resources/__init__.py +61 -0
- codeset/resources/datasets.py +135 -0
- codeset/resources/health.py +135 -0
- codeset/resources/samples.py +303 -0
- codeset/resources/sessions/__init__.py +33 -0
- codeset/resources/sessions/sessions.py +891 -0
- codeset/resources/sessions/verify.py +335 -0
- codeset/types/__init__.py +22 -0
- codeset/types/container_info.py +32 -0
- codeset/types/dataset_list_response.py +28 -0
- codeset/types/error_info.py +15 -0
- codeset/types/health_check_response.py +21 -0
- codeset/types/interaction.py +37 -0
- codeset/types/interaction_status.py +7 -0
- codeset/types/sample_download_params.py +14 -0
- codeset/types/sample_list_params.py +22 -0
- codeset/types/sample_list_response.py +95 -0
- codeset/types/session.py +48 -0
- codeset/types/session_close_response.py +15 -0
- codeset/types/session_create_params.py +18 -0
- codeset/types/session_create_response.py +21 -0
- codeset/types/session_execute_command_params.py +15 -0
- codeset/types/session_execute_command_response.py +15 -0
- codeset/types/session_list_response.py +20 -0
- codeset/types/session_status.py +7 -0
- codeset/types/session_str_replace_params.py +18 -0
- codeset/types/session_str_replace_response.py +15 -0
- codeset/types/sessions/__init__.py +7 -0
- codeset/types/sessions/job_status.py +7 -0
- codeset/types/sessions/verify_start_response.py +21 -0
- codeset/types/sessions/verify_status_response.py +79 -0
- codeset-0.4.4.dist-info/METADATA +399 -0
- codeset-0.4.4.dist-info/RECORD +63 -0
- codeset-0.4.4.dist-info/WHEEL +4 -0
- codeset-0.4.4.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,891 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
from .verify import (
|
|
10
|
+
VerifyResource,
|
|
11
|
+
AsyncVerifyResource,
|
|
12
|
+
VerifyResourceWithRawResponse,
|
|
13
|
+
AsyncVerifyResourceWithRawResponse,
|
|
14
|
+
VerifyResourceWithStreamingResponse,
|
|
15
|
+
AsyncVerifyResourceWithStreamingResponse,
|
|
16
|
+
)
|
|
17
|
+
from ...types import session_create_params, session_str_replace_params, session_execute_command_params
|
|
18
|
+
from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given
|
|
19
|
+
from ..._utils import check_timeout, maybe_transform, async_maybe_transform, get_remaining_timeout
|
|
20
|
+
from ..._compat import cached_property
|
|
21
|
+
from ..._resource import SyncAPIResource, AsyncAPIResource
|
|
22
|
+
from ..._response import (
|
|
23
|
+
to_raw_response_wrapper,
|
|
24
|
+
to_streamed_response_wrapper,
|
|
25
|
+
async_to_raw_response_wrapper,
|
|
26
|
+
async_to_streamed_response_wrapper,
|
|
27
|
+
)
|
|
28
|
+
from ..._base_client import make_request_options
|
|
29
|
+
from ...types.session import Session
|
|
30
|
+
from ...types.interaction import Interaction
|
|
31
|
+
from ...types.session_list_response import SessionListResponse
|
|
32
|
+
from ...types.session_close_response import SessionCloseResponse
|
|
33
|
+
from ...types.session_create_response import SessionCreateResponse
|
|
34
|
+
from ...types.session_str_replace_response import SessionStrReplaceResponse
|
|
35
|
+
from ...types.session_execute_command_response import SessionExecuteCommandResponse
|
|
36
|
+
|
|
37
|
+
__all__ = ["SessionsResource", "AsyncSessionsResource"]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class SessionsResource(SyncAPIResource):
|
|
41
|
+
@cached_property
|
|
42
|
+
def verify(self) -> VerifyResource:
|
|
43
|
+
return VerifyResource(self._client)
|
|
44
|
+
|
|
45
|
+
@cached_property
|
|
46
|
+
def with_raw_response(self) -> SessionsResourceWithRawResponse:
|
|
47
|
+
"""
|
|
48
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
49
|
+
the raw response object instead of the parsed content.
|
|
50
|
+
|
|
51
|
+
For more information, see https://www.github.com/codeset-ai/codeset-sdk#accessing-raw-response-data-eg-headers
|
|
52
|
+
"""
|
|
53
|
+
return SessionsResourceWithRawResponse(self)
|
|
54
|
+
|
|
55
|
+
@cached_property
|
|
56
|
+
def with_streaming_response(self) -> SessionsResourceWithStreamingResponse:
|
|
57
|
+
"""
|
|
58
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
59
|
+
|
|
60
|
+
For more information, see https://www.github.com/codeset-ai/codeset-sdk#with_streaming_response
|
|
61
|
+
"""
|
|
62
|
+
return SessionsResourceWithStreamingResponse(self)
|
|
63
|
+
|
|
64
|
+
def create(
|
|
65
|
+
self,
|
|
66
|
+
*,
|
|
67
|
+
dataset: str,
|
|
68
|
+
sample_id: str,
|
|
69
|
+
ttl_minutes: int | Omit = omit,
|
|
70
|
+
poll_interval: float = 3.0,
|
|
71
|
+
wait_for_ready: bool = True,
|
|
72
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
73
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
74
|
+
extra_headers: Headers | None = None,
|
|
75
|
+
extra_query: Query | None = None,
|
|
76
|
+
extra_body: Body | None = None,
|
|
77
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
78
|
+
) -> Session:
|
|
79
|
+
"""
|
|
80
|
+
Create a new session
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
dataset: Dataset name for the sample.
|
|
84
|
+
|
|
85
|
+
sample_id: Identifier of the sample to use for this session.
|
|
86
|
+
|
|
87
|
+
ttl_minutes: Time to live for the session in minutes (default: 30).
|
|
88
|
+
|
|
89
|
+
poll_interval: Interval in seconds between polling attempts while waiting for session to be ready (default: 3.0).
|
|
90
|
+
|
|
91
|
+
wait_for_ready: Whether to poll until the session is ready (default: True). If False, returns the session immediately after creation.
|
|
92
|
+
|
|
93
|
+
extra_headers: Send extra headers
|
|
94
|
+
|
|
95
|
+
extra_query: Add additional query parameters to the request
|
|
96
|
+
|
|
97
|
+
extra_body: Add additional JSON properties to the request
|
|
98
|
+
|
|
99
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
100
|
+
"""
|
|
101
|
+
start_time = time.time()
|
|
102
|
+
|
|
103
|
+
check_timeout(timeout, start_time)
|
|
104
|
+
response = self._post(
|
|
105
|
+
"/sessions",
|
|
106
|
+
body=maybe_transform(
|
|
107
|
+
{
|
|
108
|
+
"dataset": dataset,
|
|
109
|
+
"sample_id": sample_id,
|
|
110
|
+
"ttl_minutes": ttl_minutes,
|
|
111
|
+
},
|
|
112
|
+
session_create_params.SessionCreateParams,
|
|
113
|
+
),
|
|
114
|
+
options=make_request_options(
|
|
115
|
+
extra_headers=extra_headers,
|
|
116
|
+
extra_query=extra_query,
|
|
117
|
+
extra_body=extra_body,
|
|
118
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
119
|
+
),
|
|
120
|
+
cast_to=SessionCreateResponse,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
check_timeout(timeout, start_time)
|
|
124
|
+
session = self.retrieve(
|
|
125
|
+
response.session_id,
|
|
126
|
+
extra_headers=extra_headers,
|
|
127
|
+
extra_query=extra_query,
|
|
128
|
+
extra_body=extra_body,
|
|
129
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
if not wait_for_ready:
|
|
133
|
+
return session
|
|
134
|
+
|
|
135
|
+
while session.status != "ready":
|
|
136
|
+
if session.status in ("error", "closed"):
|
|
137
|
+
return session
|
|
138
|
+
check_timeout(timeout, start_time)
|
|
139
|
+
self._sleep(poll_interval)
|
|
140
|
+
check_timeout(timeout, start_time)
|
|
141
|
+
session = self.retrieve(
|
|
142
|
+
response.session_id,
|
|
143
|
+
extra_headers=extra_headers,
|
|
144
|
+
extra_query=extra_query,
|
|
145
|
+
extra_body=extra_body,
|
|
146
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
return session
|
|
150
|
+
|
|
151
|
+
def retrieve(
|
|
152
|
+
self,
|
|
153
|
+
session_id: str,
|
|
154
|
+
*,
|
|
155
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
156
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
157
|
+
extra_headers: Headers | None = None,
|
|
158
|
+
extra_query: Query | None = None,
|
|
159
|
+
extra_body: Body | None = None,
|
|
160
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
161
|
+
) -> Session:
|
|
162
|
+
"""
|
|
163
|
+
Get session details
|
|
164
|
+
|
|
165
|
+
Args:
|
|
166
|
+
extra_headers: Send extra headers
|
|
167
|
+
|
|
168
|
+
extra_query: Add additional query parameters to the request
|
|
169
|
+
|
|
170
|
+
extra_body: Add additional JSON properties to the request
|
|
171
|
+
|
|
172
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
173
|
+
"""
|
|
174
|
+
if not session_id:
|
|
175
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
176
|
+
return self._get(
|
|
177
|
+
f"/sessions/{session_id}",
|
|
178
|
+
options=make_request_options(
|
|
179
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
180
|
+
),
|
|
181
|
+
cast_to=Session,
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
def list(
|
|
185
|
+
self,
|
|
186
|
+
*,
|
|
187
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
188
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
189
|
+
extra_headers: Headers | None = None,
|
|
190
|
+
extra_query: Query | None = None,
|
|
191
|
+
extra_body: Body | None = None,
|
|
192
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
193
|
+
) -> SessionListResponse:
|
|
194
|
+
"""List environment sessions"""
|
|
195
|
+
return self._get(
|
|
196
|
+
"/sessions",
|
|
197
|
+
options=make_request_options(
|
|
198
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
199
|
+
),
|
|
200
|
+
cast_to=SessionListResponse,
|
|
201
|
+
)
|
|
202
|
+
|
|
203
|
+
def close(
|
|
204
|
+
self,
|
|
205
|
+
session_id: str,
|
|
206
|
+
*,
|
|
207
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
208
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
209
|
+
extra_headers: Headers | None = None,
|
|
210
|
+
extra_query: Query | None = None,
|
|
211
|
+
extra_body: Body | None = None,
|
|
212
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
213
|
+
) -> SessionCloseResponse:
|
|
214
|
+
"""
|
|
215
|
+
Close/delete an environment session
|
|
216
|
+
|
|
217
|
+
Args:
|
|
218
|
+
extra_headers: Send extra headers
|
|
219
|
+
|
|
220
|
+
extra_query: Add additional query parameters to the request
|
|
221
|
+
|
|
222
|
+
extra_body: Add additional JSON properties to the request
|
|
223
|
+
|
|
224
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
225
|
+
"""
|
|
226
|
+
if not session_id:
|
|
227
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
228
|
+
return self._delete(
|
|
229
|
+
f"/sessions/{session_id}",
|
|
230
|
+
options=make_request_options(
|
|
231
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
232
|
+
),
|
|
233
|
+
cast_to=SessionCloseResponse,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
def execute_command(
|
|
237
|
+
self,
|
|
238
|
+
session_id: str,
|
|
239
|
+
*,
|
|
240
|
+
command: str,
|
|
241
|
+
command_timeout: int | Omit = omit,
|
|
242
|
+
poll_interval: float = 3.0,
|
|
243
|
+
wait_for_completion: bool = True,
|
|
244
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
245
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
246
|
+
extra_headers: Headers | None = None,
|
|
247
|
+
extra_query: Query | None = None,
|
|
248
|
+
extra_body: Body | None = None,
|
|
249
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
250
|
+
) -> Interaction:
|
|
251
|
+
"""
|
|
252
|
+
Start command execution in an environment (async)
|
|
253
|
+
|
|
254
|
+
Args:
|
|
255
|
+
command: The bash command to execute.
|
|
256
|
+
|
|
257
|
+
command_timeout: Timeout for command execution in seconds (default: 300).
|
|
258
|
+
|
|
259
|
+
poll_interval: Interval in seconds between polling attempts while waiting for command to complete (default: 3.0).
|
|
260
|
+
|
|
261
|
+
wait_for_completion: Whether to poll until the command is completed (default: True). If False, returns the interaction immediately after creation.
|
|
262
|
+
|
|
263
|
+
extra_headers: Send extra headers
|
|
264
|
+
|
|
265
|
+
extra_query: Add additional query parameters to the request
|
|
266
|
+
|
|
267
|
+
extra_body: Add additional JSON properties to the request
|
|
268
|
+
|
|
269
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
270
|
+
"""
|
|
271
|
+
if not session_id:
|
|
272
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
273
|
+
start_time = time.time()
|
|
274
|
+
|
|
275
|
+
check_timeout(timeout, start_time)
|
|
276
|
+
response = self._post(
|
|
277
|
+
f"/sessions/{session_id}/exec",
|
|
278
|
+
body=maybe_transform(
|
|
279
|
+
{
|
|
280
|
+
"command": command,
|
|
281
|
+
"command_timeout": command_timeout,
|
|
282
|
+
},
|
|
283
|
+
session_execute_command_params.SessionExecuteCommandParams,
|
|
284
|
+
),
|
|
285
|
+
options=make_request_options(
|
|
286
|
+
extra_headers=extra_headers,
|
|
287
|
+
extra_query=extra_query,
|
|
288
|
+
extra_body=extra_body,
|
|
289
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
290
|
+
),
|
|
291
|
+
cast_to=SessionExecuteCommandResponse,
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
interaction_id = response.interaction_id
|
|
295
|
+
|
|
296
|
+
check_timeout(timeout, start_time)
|
|
297
|
+
interaction = self.get_interaction(
|
|
298
|
+
session_id,
|
|
299
|
+
interaction_id,
|
|
300
|
+
extra_headers=extra_headers,
|
|
301
|
+
extra_query=extra_query,
|
|
302
|
+
extra_body=extra_body,
|
|
303
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
if not wait_for_completion:
|
|
307
|
+
return interaction
|
|
308
|
+
|
|
309
|
+
while interaction.exit_code is None:
|
|
310
|
+
check_timeout(timeout, start_time)
|
|
311
|
+
self._sleep(poll_interval)
|
|
312
|
+
check_timeout(timeout, start_time)
|
|
313
|
+
interaction = self.get_interaction(
|
|
314
|
+
session_id,
|
|
315
|
+
interaction_id,
|
|
316
|
+
extra_headers=extra_headers,
|
|
317
|
+
extra_query=extra_query,
|
|
318
|
+
extra_body=extra_body,
|
|
319
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
return interaction
|
|
323
|
+
|
|
324
|
+
def get_interaction(
|
|
325
|
+
self,
|
|
326
|
+
session_id: str,
|
|
327
|
+
interaction_id: str,
|
|
328
|
+
*,
|
|
329
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
330
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
331
|
+
extra_headers: Headers | None = None,
|
|
332
|
+
extra_query: Query | None = None,
|
|
333
|
+
extra_body: Body | None = None,
|
|
334
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
335
|
+
) -> Interaction:
|
|
336
|
+
"""
|
|
337
|
+
Get interaction details by ID
|
|
338
|
+
|
|
339
|
+
Args:
|
|
340
|
+
extra_headers: Send extra headers
|
|
341
|
+
|
|
342
|
+
extra_query: Add additional query parameters to the request
|
|
343
|
+
|
|
344
|
+
extra_body: Add additional JSON properties to the request
|
|
345
|
+
|
|
346
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
347
|
+
"""
|
|
348
|
+
if not session_id:
|
|
349
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
350
|
+
if not interaction_id:
|
|
351
|
+
raise ValueError(f"Expected a non-empty value for `interaction_id` but received {interaction_id!r}")
|
|
352
|
+
return self._get(
|
|
353
|
+
f"/sessions/{session_id}/interactions/{interaction_id}",
|
|
354
|
+
options=make_request_options(
|
|
355
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
356
|
+
),
|
|
357
|
+
cast_to=Interaction,
|
|
358
|
+
)
|
|
359
|
+
|
|
360
|
+
def str_replace(
|
|
361
|
+
self,
|
|
362
|
+
session_id: str,
|
|
363
|
+
*,
|
|
364
|
+
file_path: str,
|
|
365
|
+
str_to_insert: str,
|
|
366
|
+
str_to_replace: str,
|
|
367
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
368
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
369
|
+
extra_headers: Headers | None = None,
|
|
370
|
+
extra_query: Query | None = None,
|
|
371
|
+
extra_body: Body | None = None,
|
|
372
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
373
|
+
) -> SessionStrReplaceResponse:
|
|
374
|
+
"""
|
|
375
|
+
Replace a string in a file within the session environment
|
|
376
|
+
|
|
377
|
+
Args:
|
|
378
|
+
file_path: Path to the file where replacement should be performed.
|
|
379
|
+
|
|
380
|
+
str_to_insert: String to insert as replacement.
|
|
381
|
+
|
|
382
|
+
str_to_replace: String to be replaced.
|
|
383
|
+
|
|
384
|
+
extra_headers: Send extra headers
|
|
385
|
+
|
|
386
|
+
extra_query: Add additional query parameters to the request
|
|
387
|
+
|
|
388
|
+
extra_body: Add additional JSON properties to the request
|
|
389
|
+
|
|
390
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
391
|
+
"""
|
|
392
|
+
if not session_id:
|
|
393
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
394
|
+
return self._post(
|
|
395
|
+
f"/sessions/{session_id}/str_replace",
|
|
396
|
+
body=maybe_transform(
|
|
397
|
+
{
|
|
398
|
+
"file_path": file_path,
|
|
399
|
+
"str_to_insert": str_to_insert,
|
|
400
|
+
"str_to_replace": str_to_replace,
|
|
401
|
+
},
|
|
402
|
+
session_str_replace_params.SessionStrReplaceParams,
|
|
403
|
+
),
|
|
404
|
+
options=make_request_options(
|
|
405
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
406
|
+
),
|
|
407
|
+
cast_to=SessionStrReplaceResponse,
|
|
408
|
+
)
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
class AsyncSessionsResource(AsyncAPIResource):
|
|
412
|
+
@cached_property
|
|
413
|
+
def verify(self) -> AsyncVerifyResource:
|
|
414
|
+
return AsyncVerifyResource(self._client)
|
|
415
|
+
|
|
416
|
+
@cached_property
|
|
417
|
+
def with_raw_response(self) -> AsyncSessionsResourceWithRawResponse:
|
|
418
|
+
"""
|
|
419
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
420
|
+
the raw response object instead of the parsed content.
|
|
421
|
+
|
|
422
|
+
For more information, see https://www.github.com/codeset-ai/codeset-sdk#accessing-raw-response-data-eg-headers
|
|
423
|
+
"""
|
|
424
|
+
return AsyncSessionsResourceWithRawResponse(self)
|
|
425
|
+
|
|
426
|
+
@cached_property
|
|
427
|
+
def with_streaming_response(self) -> AsyncSessionsResourceWithStreamingResponse:
|
|
428
|
+
"""
|
|
429
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
430
|
+
|
|
431
|
+
For more information, see https://www.github.com/codeset-ai/codeset-sdk#with_streaming_response
|
|
432
|
+
"""
|
|
433
|
+
return AsyncSessionsResourceWithStreamingResponse(self)
|
|
434
|
+
|
|
435
|
+
async def create(
|
|
436
|
+
self,
|
|
437
|
+
*,
|
|
438
|
+
dataset: str,
|
|
439
|
+
sample_id: str,
|
|
440
|
+
ttl_minutes: int | Omit = omit,
|
|
441
|
+
poll_interval: float = 3.0,
|
|
442
|
+
wait_for_ready: bool = True,
|
|
443
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
444
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
445
|
+
extra_headers: Headers | None = None,
|
|
446
|
+
extra_query: Query | None = None,
|
|
447
|
+
extra_body: Body | None = None,
|
|
448
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
449
|
+
) -> Session:
|
|
450
|
+
"""
|
|
451
|
+
Create a new session
|
|
452
|
+
|
|
453
|
+
Args:
|
|
454
|
+
dataset: Dataset name for the sample.
|
|
455
|
+
|
|
456
|
+
sample_id: Identifier of the sample to use for this session.
|
|
457
|
+
|
|
458
|
+
ttl_minutes: Time to live for the session in minutes (default: 30).
|
|
459
|
+
|
|
460
|
+
poll_interval: Interval in seconds between polling attempts while waiting for session to be ready (default: 3.0).
|
|
461
|
+
|
|
462
|
+
wait_for_ready: Whether to poll until the session is ready (default: True). If False, returns the session immediately after creation.
|
|
463
|
+
|
|
464
|
+
extra_headers: Send extra headers
|
|
465
|
+
|
|
466
|
+
extra_query: Add additional query parameters to the request
|
|
467
|
+
|
|
468
|
+
extra_body: Add additional JSON properties to the request
|
|
469
|
+
|
|
470
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
471
|
+
"""
|
|
472
|
+
start_time = time.time()
|
|
473
|
+
|
|
474
|
+
check_timeout(timeout, start_time)
|
|
475
|
+
response = await self._post(
|
|
476
|
+
"/sessions",
|
|
477
|
+
body=await async_maybe_transform(
|
|
478
|
+
{
|
|
479
|
+
"dataset": dataset,
|
|
480
|
+
"sample_id": sample_id,
|
|
481
|
+
"ttl_minutes": ttl_minutes,
|
|
482
|
+
},
|
|
483
|
+
session_create_params.SessionCreateParams,
|
|
484
|
+
),
|
|
485
|
+
options=make_request_options(
|
|
486
|
+
extra_headers=extra_headers,
|
|
487
|
+
extra_query=extra_query,
|
|
488
|
+
extra_body=extra_body,
|
|
489
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
490
|
+
),
|
|
491
|
+
cast_to=SessionCreateResponse,
|
|
492
|
+
)
|
|
493
|
+
|
|
494
|
+
check_timeout(timeout, start_time)
|
|
495
|
+
session = await self.retrieve(
|
|
496
|
+
response.session_id,
|
|
497
|
+
extra_headers=extra_headers,
|
|
498
|
+
extra_query=extra_query,
|
|
499
|
+
extra_body=extra_body,
|
|
500
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
if not wait_for_ready:
|
|
504
|
+
return session
|
|
505
|
+
|
|
506
|
+
while session.status != "ready":
|
|
507
|
+
if session.status in ("error", "closed"):
|
|
508
|
+
return session
|
|
509
|
+
check_timeout(timeout, start_time)
|
|
510
|
+
await self._sleep(poll_interval)
|
|
511
|
+
check_timeout(timeout, start_time)
|
|
512
|
+
session = await self.retrieve(
|
|
513
|
+
response.session_id,
|
|
514
|
+
extra_headers=extra_headers,
|
|
515
|
+
extra_query=extra_query,
|
|
516
|
+
extra_body=extra_body,
|
|
517
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
518
|
+
)
|
|
519
|
+
|
|
520
|
+
return session
|
|
521
|
+
|
|
522
|
+
async def retrieve(
|
|
523
|
+
self,
|
|
524
|
+
session_id: str,
|
|
525
|
+
*,
|
|
526
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
527
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
528
|
+
extra_headers: Headers | None = None,
|
|
529
|
+
extra_query: Query | None = None,
|
|
530
|
+
extra_body: Body | None = None,
|
|
531
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
532
|
+
) -> Session:
|
|
533
|
+
"""
|
|
534
|
+
Get session details
|
|
535
|
+
|
|
536
|
+
Args:
|
|
537
|
+
extra_headers: Send extra headers
|
|
538
|
+
|
|
539
|
+
extra_query: Add additional query parameters to the request
|
|
540
|
+
|
|
541
|
+
extra_body: Add additional JSON properties to the request
|
|
542
|
+
|
|
543
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
544
|
+
"""
|
|
545
|
+
if not session_id:
|
|
546
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
547
|
+
return await self._get(
|
|
548
|
+
f"/sessions/{session_id}",
|
|
549
|
+
options=make_request_options(
|
|
550
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
551
|
+
),
|
|
552
|
+
cast_to=Session,
|
|
553
|
+
)
|
|
554
|
+
|
|
555
|
+
async def list(
|
|
556
|
+
self,
|
|
557
|
+
*,
|
|
558
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
559
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
560
|
+
extra_headers: Headers | None = None,
|
|
561
|
+
extra_query: Query | None = None,
|
|
562
|
+
extra_body: Body | None = None,
|
|
563
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
564
|
+
) -> SessionListResponse:
|
|
565
|
+
"""List environment sessions"""
|
|
566
|
+
return await self._get(
|
|
567
|
+
"/sessions",
|
|
568
|
+
options=make_request_options(
|
|
569
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
570
|
+
),
|
|
571
|
+
cast_to=SessionListResponse,
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
async def close(
|
|
575
|
+
self,
|
|
576
|
+
session_id: str,
|
|
577
|
+
*,
|
|
578
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
579
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
580
|
+
extra_headers: Headers | None = None,
|
|
581
|
+
extra_query: Query | None = None,
|
|
582
|
+
extra_body: Body | None = None,
|
|
583
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
584
|
+
) -> SessionCloseResponse:
|
|
585
|
+
"""
|
|
586
|
+
Close/delete an environment session
|
|
587
|
+
|
|
588
|
+
Args:
|
|
589
|
+
extra_headers: Send extra headers
|
|
590
|
+
|
|
591
|
+
extra_query: Add additional query parameters to the request
|
|
592
|
+
|
|
593
|
+
extra_body: Add additional JSON properties to the request
|
|
594
|
+
|
|
595
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
596
|
+
"""
|
|
597
|
+
if not session_id:
|
|
598
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
599
|
+
return await self._delete(
|
|
600
|
+
f"/sessions/{session_id}",
|
|
601
|
+
options=make_request_options(
|
|
602
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
603
|
+
),
|
|
604
|
+
cast_to=SessionCloseResponse,
|
|
605
|
+
)
|
|
606
|
+
|
|
607
|
+
async def execute_command(
|
|
608
|
+
self,
|
|
609
|
+
session_id: str,
|
|
610
|
+
*,
|
|
611
|
+
command: str,
|
|
612
|
+
command_timeout: int | Omit = omit,
|
|
613
|
+
poll_interval: float = 3.0,
|
|
614
|
+
wait_for_completion: bool = True,
|
|
615
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
616
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
617
|
+
extra_headers: Headers | None = None,
|
|
618
|
+
extra_query: Query | None = None,
|
|
619
|
+
extra_body: Body | None = None,
|
|
620
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
621
|
+
) -> Interaction:
|
|
622
|
+
"""
|
|
623
|
+
Start command execution in an environment (async)
|
|
624
|
+
|
|
625
|
+
Args:
|
|
626
|
+
command: The bash command to execute.
|
|
627
|
+
|
|
628
|
+
command_timeout: Timeout for command execution in seconds (default: 300).
|
|
629
|
+
|
|
630
|
+
poll_interval: Interval in seconds between polling attempts while waiting for command to complete (default: 3.0).
|
|
631
|
+
|
|
632
|
+
wait_for_completion: Whether to poll until the command is completed (default: True). If False, returns the interaction immediately after creation.
|
|
633
|
+
|
|
634
|
+
extra_headers: Send extra headers
|
|
635
|
+
|
|
636
|
+
extra_query: Add additional query parameters to the request
|
|
637
|
+
|
|
638
|
+
extra_body: Add additional JSON properties to the request
|
|
639
|
+
|
|
640
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
641
|
+
"""
|
|
642
|
+
if not session_id:
|
|
643
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
644
|
+
start_time = time.time()
|
|
645
|
+
|
|
646
|
+
check_timeout(timeout, start_time)
|
|
647
|
+
response = await self._post(
|
|
648
|
+
f"/sessions/{session_id}/exec",
|
|
649
|
+
body=await async_maybe_transform(
|
|
650
|
+
{
|
|
651
|
+
"command": command,
|
|
652
|
+
"command_timeout": command_timeout,
|
|
653
|
+
},
|
|
654
|
+
session_execute_command_params.SessionExecuteCommandParams,
|
|
655
|
+
),
|
|
656
|
+
options=make_request_options(
|
|
657
|
+
extra_headers=extra_headers,
|
|
658
|
+
extra_query=extra_query,
|
|
659
|
+
extra_body=extra_body,
|
|
660
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
661
|
+
),
|
|
662
|
+
cast_to=SessionExecuteCommandResponse,
|
|
663
|
+
)
|
|
664
|
+
|
|
665
|
+
interaction_id = response.interaction_id
|
|
666
|
+
|
|
667
|
+
check_timeout(timeout, start_time)
|
|
668
|
+
interaction = await self.get_interaction(
|
|
669
|
+
session_id,
|
|
670
|
+
interaction_id,
|
|
671
|
+
extra_headers=extra_headers,
|
|
672
|
+
extra_query=extra_query,
|
|
673
|
+
extra_body=extra_body,
|
|
674
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
675
|
+
)
|
|
676
|
+
|
|
677
|
+
if not wait_for_completion:
|
|
678
|
+
return interaction
|
|
679
|
+
|
|
680
|
+
while interaction.exit_code is None:
|
|
681
|
+
check_timeout(timeout, start_time)
|
|
682
|
+
await self._sleep(poll_interval)
|
|
683
|
+
check_timeout(timeout, start_time)
|
|
684
|
+
interaction = await self.get_interaction(
|
|
685
|
+
session_id,
|
|
686
|
+
interaction_id,
|
|
687
|
+
extra_headers=extra_headers,
|
|
688
|
+
extra_query=extra_query,
|
|
689
|
+
extra_body=extra_body,
|
|
690
|
+
timeout=get_remaining_timeout(timeout, start_time),
|
|
691
|
+
)
|
|
692
|
+
|
|
693
|
+
return interaction
|
|
694
|
+
|
|
695
|
+
async def get_interaction(
|
|
696
|
+
self,
|
|
697
|
+
session_id: str,
|
|
698
|
+
interaction_id: str,
|
|
699
|
+
*,
|
|
700
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
701
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
702
|
+
extra_headers: Headers | None = None,
|
|
703
|
+
extra_query: Query | None = None,
|
|
704
|
+
extra_body: Body | None = None,
|
|
705
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
706
|
+
) -> Interaction:
|
|
707
|
+
"""
|
|
708
|
+
Get interaction details by ID
|
|
709
|
+
|
|
710
|
+
Args:
|
|
711
|
+
extra_headers: Send extra headers
|
|
712
|
+
|
|
713
|
+
extra_query: Add additional query parameters to the request
|
|
714
|
+
|
|
715
|
+
extra_body: Add additional JSON properties to the request
|
|
716
|
+
|
|
717
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
718
|
+
"""
|
|
719
|
+
if not session_id:
|
|
720
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
721
|
+
if not interaction_id:
|
|
722
|
+
raise ValueError(f"Expected a non-empty value for `interaction_id` but received {interaction_id!r}")
|
|
723
|
+
return await self._get(
|
|
724
|
+
f"/sessions/{session_id}/interactions/{interaction_id}",
|
|
725
|
+
options=make_request_options(
|
|
726
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
727
|
+
),
|
|
728
|
+
cast_to=Interaction,
|
|
729
|
+
)
|
|
730
|
+
|
|
731
|
+
async def str_replace(
|
|
732
|
+
self,
|
|
733
|
+
session_id: str,
|
|
734
|
+
*,
|
|
735
|
+
file_path: str,
|
|
736
|
+
str_to_insert: str,
|
|
737
|
+
str_to_replace: str,
|
|
738
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
739
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
740
|
+
extra_headers: Headers | None = None,
|
|
741
|
+
extra_query: Query | None = None,
|
|
742
|
+
extra_body: Body | None = None,
|
|
743
|
+
timeout: float | httpx.Timeout | None | NotGiven = not_given,
|
|
744
|
+
) -> SessionStrReplaceResponse:
|
|
745
|
+
"""
|
|
746
|
+
Replace a string in a file within the session environment
|
|
747
|
+
|
|
748
|
+
Args:
|
|
749
|
+
file_path: Path to the file where replacement should be performed.
|
|
750
|
+
|
|
751
|
+
str_to_insert: String to insert as replacement.
|
|
752
|
+
|
|
753
|
+
str_to_replace: String to be replaced.
|
|
754
|
+
|
|
755
|
+
extra_headers: Send extra headers
|
|
756
|
+
|
|
757
|
+
extra_query: Add additional query parameters to the request
|
|
758
|
+
|
|
759
|
+
extra_body: Add additional JSON properties to the request
|
|
760
|
+
|
|
761
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
762
|
+
"""
|
|
763
|
+
if not session_id:
|
|
764
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
765
|
+
return await self._post(
|
|
766
|
+
f"/sessions/{session_id}/str_replace",
|
|
767
|
+
body=await async_maybe_transform(
|
|
768
|
+
{
|
|
769
|
+
"file_path": file_path,
|
|
770
|
+
"str_to_insert": str_to_insert,
|
|
771
|
+
"str_to_replace": str_to_replace,
|
|
772
|
+
},
|
|
773
|
+
session_str_replace_params.SessionStrReplaceParams,
|
|
774
|
+
),
|
|
775
|
+
options=make_request_options(
|
|
776
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
777
|
+
),
|
|
778
|
+
cast_to=SessionStrReplaceResponse,
|
|
779
|
+
)
|
|
780
|
+
|
|
781
|
+
|
|
782
|
+
class SessionsResourceWithRawResponse:
|
|
783
|
+
def __init__(self, sessions: SessionsResource) -> None:
|
|
784
|
+
self._sessions = sessions
|
|
785
|
+
|
|
786
|
+
self.create = to_raw_response_wrapper(
|
|
787
|
+
sessions.create,
|
|
788
|
+
)
|
|
789
|
+
self.retrieve = to_raw_response_wrapper(
|
|
790
|
+
sessions.retrieve,
|
|
791
|
+
)
|
|
792
|
+
self.list = to_raw_response_wrapper(
|
|
793
|
+
sessions.list,
|
|
794
|
+
)
|
|
795
|
+
self.close = to_raw_response_wrapper(
|
|
796
|
+
sessions.close,
|
|
797
|
+
)
|
|
798
|
+
self.execute_command = to_raw_response_wrapper(
|
|
799
|
+
sessions.execute_command,
|
|
800
|
+
)
|
|
801
|
+
self.str_replace = to_raw_response_wrapper(
|
|
802
|
+
sessions.str_replace,
|
|
803
|
+
)
|
|
804
|
+
|
|
805
|
+
@cached_property
|
|
806
|
+
def verify(self) -> VerifyResourceWithRawResponse:
|
|
807
|
+
return VerifyResourceWithRawResponse(self._sessions.verify)
|
|
808
|
+
|
|
809
|
+
|
|
810
|
+
class AsyncSessionsResourceWithRawResponse:
|
|
811
|
+
def __init__(self, sessions: AsyncSessionsResource) -> None:
|
|
812
|
+
self._sessions = sessions
|
|
813
|
+
|
|
814
|
+
self.create = async_to_raw_response_wrapper(
|
|
815
|
+
sessions.create,
|
|
816
|
+
)
|
|
817
|
+
self.retrieve = async_to_raw_response_wrapper(
|
|
818
|
+
sessions.retrieve,
|
|
819
|
+
)
|
|
820
|
+
self.list = async_to_raw_response_wrapper(
|
|
821
|
+
sessions.list,
|
|
822
|
+
)
|
|
823
|
+
self.close = async_to_raw_response_wrapper(
|
|
824
|
+
sessions.close,
|
|
825
|
+
)
|
|
826
|
+
self.execute_command = async_to_raw_response_wrapper(
|
|
827
|
+
sessions.execute_command,
|
|
828
|
+
)
|
|
829
|
+
self.str_replace = async_to_raw_response_wrapper(
|
|
830
|
+
sessions.str_replace,
|
|
831
|
+
)
|
|
832
|
+
|
|
833
|
+
@cached_property
|
|
834
|
+
def verify(self) -> AsyncVerifyResourceWithRawResponse:
|
|
835
|
+
return AsyncVerifyResourceWithRawResponse(self._sessions.verify)
|
|
836
|
+
|
|
837
|
+
|
|
838
|
+
class SessionsResourceWithStreamingResponse:
|
|
839
|
+
def __init__(self, sessions: SessionsResource) -> None:
|
|
840
|
+
self._sessions = sessions
|
|
841
|
+
|
|
842
|
+
self.create = to_streamed_response_wrapper(
|
|
843
|
+
sessions.create,
|
|
844
|
+
)
|
|
845
|
+
self.retrieve = to_streamed_response_wrapper(
|
|
846
|
+
sessions.retrieve,
|
|
847
|
+
)
|
|
848
|
+
self.list = to_streamed_response_wrapper(
|
|
849
|
+
sessions.list,
|
|
850
|
+
)
|
|
851
|
+
self.close = to_streamed_response_wrapper(
|
|
852
|
+
sessions.close,
|
|
853
|
+
)
|
|
854
|
+
self.execute_command = to_streamed_response_wrapper(
|
|
855
|
+
sessions.execute_command,
|
|
856
|
+
)
|
|
857
|
+
self.str_replace = to_streamed_response_wrapper(
|
|
858
|
+
sessions.str_replace,
|
|
859
|
+
)
|
|
860
|
+
|
|
861
|
+
@cached_property
|
|
862
|
+
def verify(self) -> VerifyResourceWithStreamingResponse:
|
|
863
|
+
return VerifyResourceWithStreamingResponse(self._sessions.verify)
|
|
864
|
+
|
|
865
|
+
|
|
866
|
+
class AsyncSessionsResourceWithStreamingResponse:
|
|
867
|
+
def __init__(self, sessions: AsyncSessionsResource) -> None:
|
|
868
|
+
self._sessions = sessions
|
|
869
|
+
|
|
870
|
+
self.create = async_to_streamed_response_wrapper(
|
|
871
|
+
sessions.create,
|
|
872
|
+
)
|
|
873
|
+
self.retrieve = async_to_streamed_response_wrapper(
|
|
874
|
+
sessions.retrieve,
|
|
875
|
+
)
|
|
876
|
+
self.list = async_to_streamed_response_wrapper(
|
|
877
|
+
sessions.list,
|
|
878
|
+
)
|
|
879
|
+
self.close = async_to_streamed_response_wrapper(
|
|
880
|
+
sessions.close,
|
|
881
|
+
)
|
|
882
|
+
self.execute_command = async_to_streamed_response_wrapper(
|
|
883
|
+
sessions.execute_command,
|
|
884
|
+
)
|
|
885
|
+
self.str_replace = async_to_streamed_response_wrapper(
|
|
886
|
+
sessions.str_replace,
|
|
887
|
+
)
|
|
888
|
+
|
|
889
|
+
@cached_property
|
|
890
|
+
def verify(self) -> AsyncVerifyResourceWithStreamingResponse:
|
|
891
|
+
return AsyncVerifyResourceWithStreamingResponse(self._sessions.verify)
|