anchorbrowser 0.1.1__py3-none-any.whl → 0.3.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.
- anchorbrowser/_client.py +17 -1
- anchorbrowser/_models.py +3 -0
- anchorbrowser/_version.py +1 -1
- anchorbrowser/resources/__init__.py +28 -0
- anchorbrowser/resources/batch_sessions.py +288 -0
- anchorbrowser/resources/profiles.py +1 -115
- anchorbrowser/resources/sessions/__init__.py +14 -0
- anchorbrowser/resources/sessions/agent/__init__.py +33 -0
- anchorbrowser/resources/sessions/agent/agent.py +273 -0
- anchorbrowser/resources/sessions/agent/files.py +280 -0
- anchorbrowser/resources/sessions/mouse.py +1 -233
- anchorbrowser/resources/sessions/sessions.py +39 -1
- anchorbrowser/resources/task.py +465 -0
- anchorbrowser/types/__init__.py +7 -1
- anchorbrowser/types/batch_session_create_params.py +487 -0
- anchorbrowser/types/batch_session_create_response.py +27 -0
- anchorbrowser/types/batch_session_retrieve_response.py +90 -0
- anchorbrowser/types/session_create_params.py +52 -9
- anchorbrowser/types/sessions/__init__.py +0 -4
- anchorbrowser/types/sessions/agent/__init__.py +7 -0
- anchorbrowser/types/sessions/agent/file_list_response.py +32 -0
- anchorbrowser/types/sessions/agent/file_upload_params.py +14 -0
- anchorbrowser/types/sessions/agent/file_upload_response.py +17 -0
- anchorbrowser/types/task/__init__.py +6 -0
- anchorbrowser/types/task/run_execute_params.py +324 -0
- anchorbrowser/types/task/run_execute_response.py +33 -0
- anchorbrowser/types/task_create_params.py +317 -0
- anchorbrowser/types/task_create_response.py +345 -0
- anchorbrowser/types/task_list_params.py +15 -0
- anchorbrowser/types/task_list_response.py +361 -0
- {anchorbrowser-0.1.1.dist-info → anchorbrowser-0.3.0.dist-info}/METADATA +6 -6
- {anchorbrowser-0.1.1.dist-info → anchorbrowser-0.3.0.dist-info}/RECORD +34 -20
- anchorbrowser/types/profile_update_params.py +0 -21
- anchorbrowser/types/sessions/mouse_down_params.py +0 -18
- anchorbrowser/types/sessions/mouse_down_response.py +0 -11
- anchorbrowser/types/sessions/mouse_up_params.py +0 -18
- anchorbrowser/types/sessions/mouse_up_response.py +0 -11
- {anchorbrowser-0.1.1.dist-info → anchorbrowser-0.3.0.dist-info}/WHEEL +0 -0
- {anchorbrowser-0.1.1.dist-info → anchorbrowser-0.3.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from .files import (
|
|
8
|
+
FilesResource,
|
|
9
|
+
AsyncFilesResource,
|
|
10
|
+
FilesResourceWithRawResponse,
|
|
11
|
+
AsyncFilesResourceWithRawResponse,
|
|
12
|
+
FilesResourceWithStreamingResponse,
|
|
13
|
+
AsyncFilesResourceWithStreamingResponse,
|
|
14
|
+
)
|
|
15
|
+
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
|
16
|
+
from ...._compat import cached_property
|
|
17
|
+
from ...._resource import SyncAPIResource, AsyncAPIResource
|
|
18
|
+
from ...._response import (
|
|
19
|
+
to_raw_response_wrapper,
|
|
20
|
+
to_streamed_response_wrapper,
|
|
21
|
+
async_to_raw_response_wrapper,
|
|
22
|
+
async_to_streamed_response_wrapper,
|
|
23
|
+
)
|
|
24
|
+
from ...._base_client import make_request_options
|
|
25
|
+
from ....types.shared.success_response import SuccessResponse
|
|
26
|
+
|
|
27
|
+
__all__ = ["AgentResource", "AsyncAgentResource"]
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class AgentResource(SyncAPIResource):
|
|
31
|
+
@cached_property
|
|
32
|
+
def files(self) -> FilesResource:
|
|
33
|
+
return FilesResource(self._client)
|
|
34
|
+
|
|
35
|
+
@cached_property
|
|
36
|
+
def with_raw_response(self) -> AgentResourceWithRawResponse:
|
|
37
|
+
"""
|
|
38
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
39
|
+
the raw response object instead of the parsed content.
|
|
40
|
+
|
|
41
|
+
For more information, see https://www.github.com/anchorbrowser/AnchorBrowser-SDK-Python#accessing-raw-response-data-eg-headers
|
|
42
|
+
"""
|
|
43
|
+
return AgentResourceWithRawResponse(self)
|
|
44
|
+
|
|
45
|
+
@cached_property
|
|
46
|
+
def with_streaming_response(self) -> AgentResourceWithStreamingResponse:
|
|
47
|
+
"""
|
|
48
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
49
|
+
|
|
50
|
+
For more information, see https://www.github.com/anchorbrowser/AnchorBrowser-SDK-Python#with_streaming_response
|
|
51
|
+
"""
|
|
52
|
+
return AgentResourceWithStreamingResponse(self)
|
|
53
|
+
|
|
54
|
+
def pause(
|
|
55
|
+
self,
|
|
56
|
+
session_id: str,
|
|
57
|
+
*,
|
|
58
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
59
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
60
|
+
extra_headers: Headers | None = None,
|
|
61
|
+
extra_query: Query | None = None,
|
|
62
|
+
extra_body: Body | None = None,
|
|
63
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
64
|
+
) -> SuccessResponse:
|
|
65
|
+
"""
|
|
66
|
+
Pauses the AI agent for the specified browser session.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
extra_headers: Send extra headers
|
|
70
|
+
|
|
71
|
+
extra_query: Add additional query parameters to the request
|
|
72
|
+
|
|
73
|
+
extra_body: Add additional JSON properties to the request
|
|
74
|
+
|
|
75
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
76
|
+
"""
|
|
77
|
+
if not session_id:
|
|
78
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
79
|
+
return self._post(
|
|
80
|
+
f"/v1/sessions/{session_id}/agent/pause",
|
|
81
|
+
options=make_request_options(
|
|
82
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
83
|
+
),
|
|
84
|
+
cast_to=SuccessResponse,
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def resume(
|
|
88
|
+
self,
|
|
89
|
+
session_id: str,
|
|
90
|
+
*,
|
|
91
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
92
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
93
|
+
extra_headers: Headers | None = None,
|
|
94
|
+
extra_query: Query | None = None,
|
|
95
|
+
extra_body: Body | None = None,
|
|
96
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
97
|
+
) -> SuccessResponse:
|
|
98
|
+
"""
|
|
99
|
+
Resumes the AI agent for the specified browser session.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
extra_headers: Send extra headers
|
|
103
|
+
|
|
104
|
+
extra_query: Add additional query parameters to the request
|
|
105
|
+
|
|
106
|
+
extra_body: Add additional JSON properties to the request
|
|
107
|
+
|
|
108
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
109
|
+
"""
|
|
110
|
+
if not session_id:
|
|
111
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
112
|
+
return self._post(
|
|
113
|
+
f"/v1/sessions/{session_id}/agent/resume",
|
|
114
|
+
options=make_request_options(
|
|
115
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
116
|
+
),
|
|
117
|
+
cast_to=SuccessResponse,
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
class AsyncAgentResource(AsyncAPIResource):
|
|
122
|
+
@cached_property
|
|
123
|
+
def files(self) -> AsyncFilesResource:
|
|
124
|
+
return AsyncFilesResource(self._client)
|
|
125
|
+
|
|
126
|
+
@cached_property
|
|
127
|
+
def with_raw_response(self) -> AsyncAgentResourceWithRawResponse:
|
|
128
|
+
"""
|
|
129
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
130
|
+
the raw response object instead of the parsed content.
|
|
131
|
+
|
|
132
|
+
For more information, see https://www.github.com/anchorbrowser/AnchorBrowser-SDK-Python#accessing-raw-response-data-eg-headers
|
|
133
|
+
"""
|
|
134
|
+
return AsyncAgentResourceWithRawResponse(self)
|
|
135
|
+
|
|
136
|
+
@cached_property
|
|
137
|
+
def with_streaming_response(self) -> AsyncAgentResourceWithStreamingResponse:
|
|
138
|
+
"""
|
|
139
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
140
|
+
|
|
141
|
+
For more information, see https://www.github.com/anchorbrowser/AnchorBrowser-SDK-Python#with_streaming_response
|
|
142
|
+
"""
|
|
143
|
+
return AsyncAgentResourceWithStreamingResponse(self)
|
|
144
|
+
|
|
145
|
+
async def pause(
|
|
146
|
+
self,
|
|
147
|
+
session_id: str,
|
|
148
|
+
*,
|
|
149
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
150
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
151
|
+
extra_headers: Headers | None = None,
|
|
152
|
+
extra_query: Query | None = None,
|
|
153
|
+
extra_body: Body | None = None,
|
|
154
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
155
|
+
) -> SuccessResponse:
|
|
156
|
+
"""
|
|
157
|
+
Pauses the AI agent for the specified browser session.
|
|
158
|
+
|
|
159
|
+
Args:
|
|
160
|
+
extra_headers: Send extra headers
|
|
161
|
+
|
|
162
|
+
extra_query: Add additional query parameters to the request
|
|
163
|
+
|
|
164
|
+
extra_body: Add additional JSON properties to the request
|
|
165
|
+
|
|
166
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
167
|
+
"""
|
|
168
|
+
if not session_id:
|
|
169
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
170
|
+
return await self._post(
|
|
171
|
+
f"/v1/sessions/{session_id}/agent/pause",
|
|
172
|
+
options=make_request_options(
|
|
173
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
174
|
+
),
|
|
175
|
+
cast_to=SuccessResponse,
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
async def resume(
|
|
179
|
+
self,
|
|
180
|
+
session_id: str,
|
|
181
|
+
*,
|
|
182
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
183
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
184
|
+
extra_headers: Headers | None = None,
|
|
185
|
+
extra_query: Query | None = None,
|
|
186
|
+
extra_body: Body | None = None,
|
|
187
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
188
|
+
) -> SuccessResponse:
|
|
189
|
+
"""
|
|
190
|
+
Resumes the AI agent for the specified browser session.
|
|
191
|
+
|
|
192
|
+
Args:
|
|
193
|
+
extra_headers: Send extra headers
|
|
194
|
+
|
|
195
|
+
extra_query: Add additional query parameters to the request
|
|
196
|
+
|
|
197
|
+
extra_body: Add additional JSON properties to the request
|
|
198
|
+
|
|
199
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
200
|
+
"""
|
|
201
|
+
if not session_id:
|
|
202
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
203
|
+
return await self._post(
|
|
204
|
+
f"/v1/sessions/{session_id}/agent/resume",
|
|
205
|
+
options=make_request_options(
|
|
206
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
207
|
+
),
|
|
208
|
+
cast_to=SuccessResponse,
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class AgentResourceWithRawResponse:
|
|
213
|
+
def __init__(self, agent: AgentResource) -> None:
|
|
214
|
+
self._agent = agent
|
|
215
|
+
|
|
216
|
+
self.pause = to_raw_response_wrapper(
|
|
217
|
+
agent.pause,
|
|
218
|
+
)
|
|
219
|
+
self.resume = to_raw_response_wrapper(
|
|
220
|
+
agent.resume,
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
@cached_property
|
|
224
|
+
def files(self) -> FilesResourceWithRawResponse:
|
|
225
|
+
return FilesResourceWithRawResponse(self._agent.files)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
class AsyncAgentResourceWithRawResponse:
|
|
229
|
+
def __init__(self, agent: AsyncAgentResource) -> None:
|
|
230
|
+
self._agent = agent
|
|
231
|
+
|
|
232
|
+
self.pause = async_to_raw_response_wrapper(
|
|
233
|
+
agent.pause,
|
|
234
|
+
)
|
|
235
|
+
self.resume = async_to_raw_response_wrapper(
|
|
236
|
+
agent.resume,
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
@cached_property
|
|
240
|
+
def files(self) -> AsyncFilesResourceWithRawResponse:
|
|
241
|
+
return AsyncFilesResourceWithRawResponse(self._agent.files)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
class AgentResourceWithStreamingResponse:
|
|
245
|
+
def __init__(self, agent: AgentResource) -> None:
|
|
246
|
+
self._agent = agent
|
|
247
|
+
|
|
248
|
+
self.pause = to_streamed_response_wrapper(
|
|
249
|
+
agent.pause,
|
|
250
|
+
)
|
|
251
|
+
self.resume = to_streamed_response_wrapper(
|
|
252
|
+
agent.resume,
|
|
253
|
+
)
|
|
254
|
+
|
|
255
|
+
@cached_property
|
|
256
|
+
def files(self) -> FilesResourceWithStreamingResponse:
|
|
257
|
+
return FilesResourceWithStreamingResponse(self._agent.files)
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
class AsyncAgentResourceWithStreamingResponse:
|
|
261
|
+
def __init__(self, agent: AsyncAgentResource) -> None:
|
|
262
|
+
self._agent = agent
|
|
263
|
+
|
|
264
|
+
self.pause = async_to_streamed_response_wrapper(
|
|
265
|
+
agent.pause,
|
|
266
|
+
)
|
|
267
|
+
self.resume = async_to_streamed_response_wrapper(
|
|
268
|
+
agent.resume,
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
@cached_property
|
|
272
|
+
def files(self) -> AsyncFilesResourceWithStreamingResponse:
|
|
273
|
+
return AsyncFilesResourceWithStreamingResponse(self._agent.files)
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Mapping, cast
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
|
|
9
|
+
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
|
|
10
|
+
from ...._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
|
|
11
|
+
from ...._compat import cached_property
|
|
12
|
+
from ...._resource import SyncAPIResource, AsyncAPIResource
|
|
13
|
+
from ...._response import (
|
|
14
|
+
to_raw_response_wrapper,
|
|
15
|
+
to_streamed_response_wrapper,
|
|
16
|
+
async_to_raw_response_wrapper,
|
|
17
|
+
async_to_streamed_response_wrapper,
|
|
18
|
+
)
|
|
19
|
+
from ...._base_client import make_request_options
|
|
20
|
+
from ....types.sessions.agent import file_upload_params
|
|
21
|
+
from ....types.sessions.agent.file_list_response import FileListResponse
|
|
22
|
+
from ....types.sessions.agent.file_upload_response import FileUploadResponse
|
|
23
|
+
|
|
24
|
+
__all__ = ["FilesResource", "AsyncFilesResource"]
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class FilesResource(SyncAPIResource):
|
|
28
|
+
@cached_property
|
|
29
|
+
def with_raw_response(self) -> FilesResourceWithRawResponse:
|
|
30
|
+
"""
|
|
31
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
32
|
+
the raw response object instead of the parsed content.
|
|
33
|
+
|
|
34
|
+
For more information, see https://www.github.com/anchorbrowser/AnchorBrowser-SDK-Python#accessing-raw-response-data-eg-headers
|
|
35
|
+
"""
|
|
36
|
+
return FilesResourceWithRawResponse(self)
|
|
37
|
+
|
|
38
|
+
@cached_property
|
|
39
|
+
def with_streaming_response(self) -> FilesResourceWithStreamingResponse:
|
|
40
|
+
"""
|
|
41
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
42
|
+
|
|
43
|
+
For more information, see https://www.github.com/anchorbrowser/AnchorBrowser-SDK-Python#with_streaming_response
|
|
44
|
+
"""
|
|
45
|
+
return FilesResourceWithStreamingResponse(self)
|
|
46
|
+
|
|
47
|
+
def list(
|
|
48
|
+
self,
|
|
49
|
+
session_id: str,
|
|
50
|
+
*,
|
|
51
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
52
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
53
|
+
extra_headers: Headers | None = None,
|
|
54
|
+
extra_query: Query | None = None,
|
|
55
|
+
extra_body: Body | None = None,
|
|
56
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
57
|
+
) -> FileListResponse:
|
|
58
|
+
"""
|
|
59
|
+
List all resources that have been uploaded to the browser session for agent use.
|
|
60
|
+
Returns resource metadata including name, size, type, and last modified
|
|
61
|
+
timestamp.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
extra_headers: Send extra headers
|
|
65
|
+
|
|
66
|
+
extra_query: Add additional query parameters to the request
|
|
67
|
+
|
|
68
|
+
extra_body: Add additional JSON properties to the request
|
|
69
|
+
|
|
70
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
71
|
+
"""
|
|
72
|
+
if not session_id:
|
|
73
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
74
|
+
return self._get(
|
|
75
|
+
f"/v1/sessions/{session_id}/agent/files",
|
|
76
|
+
options=make_request_options(
|
|
77
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
78
|
+
),
|
|
79
|
+
cast_to=FileListResponse,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
def upload(
|
|
83
|
+
self,
|
|
84
|
+
session_id: str,
|
|
85
|
+
*,
|
|
86
|
+
file: FileTypes,
|
|
87
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
88
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
89
|
+
extra_headers: Headers | None = None,
|
|
90
|
+
extra_query: Query | None = None,
|
|
91
|
+
extra_body: Body | None = None,
|
|
92
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
93
|
+
) -> FileUploadResponse:
|
|
94
|
+
"""
|
|
95
|
+
Upload files as agent resources to a browser session using multipart/form-data.
|
|
96
|
+
If you upload a ZIP file, it will be automatically extracted and the files will
|
|
97
|
+
be made available as agent resources. If you upload a single file, it will be
|
|
98
|
+
saved directly as an agent resource. Resources are then accessible to AI agents
|
|
99
|
+
for task completion and automation.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
file: File to upload as agent resource (ZIP files will be extracted automatically)
|
|
103
|
+
|
|
104
|
+
extra_headers: Send extra headers
|
|
105
|
+
|
|
106
|
+
extra_query: Add additional query parameters to the request
|
|
107
|
+
|
|
108
|
+
extra_body: Add additional JSON properties to the request
|
|
109
|
+
|
|
110
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
111
|
+
"""
|
|
112
|
+
if not session_id:
|
|
113
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
114
|
+
body = deepcopy_minimal({"file": file})
|
|
115
|
+
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
|
|
116
|
+
# It should be noted that the actual Content-Type header that will be
|
|
117
|
+
# sent to the server will contain a `boundary` parameter, e.g.
|
|
118
|
+
# multipart/form-data; boundary=---abc--
|
|
119
|
+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
|
120
|
+
return self._post(
|
|
121
|
+
f"/v1/sessions/{session_id}/agent/files",
|
|
122
|
+
body=maybe_transform(body, file_upload_params.FileUploadParams),
|
|
123
|
+
files=files,
|
|
124
|
+
options=make_request_options(
|
|
125
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
126
|
+
),
|
|
127
|
+
cast_to=FileUploadResponse,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
class AsyncFilesResource(AsyncAPIResource):
|
|
132
|
+
@cached_property
|
|
133
|
+
def with_raw_response(self) -> AsyncFilesResourceWithRawResponse:
|
|
134
|
+
"""
|
|
135
|
+
This property can be used as a prefix for any HTTP method call to return
|
|
136
|
+
the raw response object instead of the parsed content.
|
|
137
|
+
|
|
138
|
+
For more information, see https://www.github.com/anchorbrowser/AnchorBrowser-SDK-Python#accessing-raw-response-data-eg-headers
|
|
139
|
+
"""
|
|
140
|
+
return AsyncFilesResourceWithRawResponse(self)
|
|
141
|
+
|
|
142
|
+
@cached_property
|
|
143
|
+
def with_streaming_response(self) -> AsyncFilesResourceWithStreamingResponse:
|
|
144
|
+
"""
|
|
145
|
+
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
|
146
|
+
|
|
147
|
+
For more information, see https://www.github.com/anchorbrowser/AnchorBrowser-SDK-Python#with_streaming_response
|
|
148
|
+
"""
|
|
149
|
+
return AsyncFilesResourceWithStreamingResponse(self)
|
|
150
|
+
|
|
151
|
+
async def list(
|
|
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
|
+
) -> FileListResponse:
|
|
162
|
+
"""
|
|
163
|
+
List all resources that have been uploaded to the browser session for agent use.
|
|
164
|
+
Returns resource metadata including name, size, type, and last modified
|
|
165
|
+
timestamp.
|
|
166
|
+
|
|
167
|
+
Args:
|
|
168
|
+
extra_headers: Send extra headers
|
|
169
|
+
|
|
170
|
+
extra_query: Add additional query parameters to the request
|
|
171
|
+
|
|
172
|
+
extra_body: Add additional JSON properties to the request
|
|
173
|
+
|
|
174
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
175
|
+
"""
|
|
176
|
+
if not session_id:
|
|
177
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
178
|
+
return await self._get(
|
|
179
|
+
f"/v1/sessions/{session_id}/agent/files",
|
|
180
|
+
options=make_request_options(
|
|
181
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
182
|
+
),
|
|
183
|
+
cast_to=FileListResponse,
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
async def upload(
|
|
187
|
+
self,
|
|
188
|
+
session_id: str,
|
|
189
|
+
*,
|
|
190
|
+
file: FileTypes,
|
|
191
|
+
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
|
192
|
+
# The extra values given here take precedence over values defined on the client or passed to this method.
|
|
193
|
+
extra_headers: Headers | None = None,
|
|
194
|
+
extra_query: Query | None = None,
|
|
195
|
+
extra_body: Body | None = None,
|
|
196
|
+
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
|
197
|
+
) -> FileUploadResponse:
|
|
198
|
+
"""
|
|
199
|
+
Upload files as agent resources to a browser session using multipart/form-data.
|
|
200
|
+
If you upload a ZIP file, it will be automatically extracted and the files will
|
|
201
|
+
be made available as agent resources. If you upload a single file, it will be
|
|
202
|
+
saved directly as an agent resource. Resources are then accessible to AI agents
|
|
203
|
+
for task completion and automation.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
file: File to upload as agent resource (ZIP files will be extracted automatically)
|
|
207
|
+
|
|
208
|
+
extra_headers: Send extra headers
|
|
209
|
+
|
|
210
|
+
extra_query: Add additional query parameters to the request
|
|
211
|
+
|
|
212
|
+
extra_body: Add additional JSON properties to the request
|
|
213
|
+
|
|
214
|
+
timeout: Override the client-level default timeout for this request, in seconds
|
|
215
|
+
"""
|
|
216
|
+
if not session_id:
|
|
217
|
+
raise ValueError(f"Expected a non-empty value for `session_id` but received {session_id!r}")
|
|
218
|
+
body = deepcopy_minimal({"file": file})
|
|
219
|
+
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
|
|
220
|
+
# It should be noted that the actual Content-Type header that will be
|
|
221
|
+
# sent to the server will contain a `boundary` parameter, e.g.
|
|
222
|
+
# multipart/form-data; boundary=---abc--
|
|
223
|
+
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
|
|
224
|
+
return await self._post(
|
|
225
|
+
f"/v1/sessions/{session_id}/agent/files",
|
|
226
|
+
body=await async_maybe_transform(body, file_upload_params.FileUploadParams),
|
|
227
|
+
files=files,
|
|
228
|
+
options=make_request_options(
|
|
229
|
+
extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout
|
|
230
|
+
),
|
|
231
|
+
cast_to=FileUploadResponse,
|
|
232
|
+
)
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
class FilesResourceWithRawResponse:
|
|
236
|
+
def __init__(self, files: FilesResource) -> None:
|
|
237
|
+
self._files = files
|
|
238
|
+
|
|
239
|
+
self.list = to_raw_response_wrapper(
|
|
240
|
+
files.list,
|
|
241
|
+
)
|
|
242
|
+
self.upload = to_raw_response_wrapper(
|
|
243
|
+
files.upload,
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class AsyncFilesResourceWithRawResponse:
|
|
248
|
+
def __init__(self, files: AsyncFilesResource) -> None:
|
|
249
|
+
self._files = files
|
|
250
|
+
|
|
251
|
+
self.list = async_to_raw_response_wrapper(
|
|
252
|
+
files.list,
|
|
253
|
+
)
|
|
254
|
+
self.upload = async_to_raw_response_wrapper(
|
|
255
|
+
files.upload,
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
class FilesResourceWithStreamingResponse:
|
|
260
|
+
def __init__(self, files: FilesResource) -> None:
|
|
261
|
+
self._files = files
|
|
262
|
+
|
|
263
|
+
self.list = to_streamed_response_wrapper(
|
|
264
|
+
files.list,
|
|
265
|
+
)
|
|
266
|
+
self.upload = to_streamed_response_wrapper(
|
|
267
|
+
files.upload,
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
class AsyncFilesResourceWithStreamingResponse:
|
|
272
|
+
def __init__(self, files: AsyncFilesResource) -> None:
|
|
273
|
+
self._files = files
|
|
274
|
+
|
|
275
|
+
self.list = async_to_streamed_response_wrapper(
|
|
276
|
+
files.list,
|
|
277
|
+
)
|
|
278
|
+
self.upload = async_to_streamed_response_wrapper(
|
|
279
|
+
files.upload,
|
|
280
|
+
)
|