-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionsContract.php
More file actions
312 lines (297 loc) · 14.5 KB
/
SessionsContract.php
File metadata and controls
312 lines (297 loc) · 14.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<?php
declare(strict_types=1);
namespace Stagehand\ServiceContracts;
use Stagehand\Core\Contracts\BaseStream;
use Stagehand\Core\Exceptions\APIException;
use Stagehand\RequestOptions;
use Stagehand\Sessions\Action;
use Stagehand\Sessions\SessionActParams\Options;
use Stagehand\Sessions\SessionActParams\XStreamResponse;
use Stagehand\Sessions\SessionActResponse;
use Stagehand\Sessions\SessionEndResponse;
use Stagehand\Sessions\SessionExecuteParams\AgentConfig;
use Stagehand\Sessions\SessionExecuteParams\ExecuteOptions;
use Stagehand\Sessions\SessionExecuteResponse;
use Stagehand\Sessions\SessionExtractResponse;
use Stagehand\Sessions\SessionNavigateResponse;
use Stagehand\Sessions\SessionObserveResponse;
use Stagehand\Sessions\SessionReplayResponse;
use Stagehand\Sessions\SessionStartParams\Browser;
use Stagehand\Sessions\SessionStartParams\BrowserbaseSessionCreateParams;
use Stagehand\Sessions\SessionStartResponse;
use Stagehand\Sessions\StreamEvent;
/**
* @phpstan-import-type OptionsShape from \Stagehand\Sessions\SessionNavigateParams\Options
* @phpstan-import-type BrowserShape from \Stagehand\Sessions\SessionStartParams\Browser
* @phpstan-import-type BrowserbaseSessionCreateParamsShape from \Stagehand\Sessions\SessionStartParams\BrowserbaseSessionCreateParams
* @phpstan-import-type InputShape from \Stagehand\Sessions\SessionActParams\Input
* @phpstan-import-type OptionsShape from \Stagehand\Sessions\SessionActParams\Options as OptionsShape1
* @phpstan-import-type RequestOpts from \Stagehand\RequestOptions
* @phpstan-import-type AgentConfigShape from \Stagehand\Sessions\SessionExecuteParams\AgentConfig
* @phpstan-import-type ExecuteOptionsShape from \Stagehand\Sessions\SessionExecuteParams\ExecuteOptions
* @phpstan-import-type OptionsShape from \Stagehand\Sessions\SessionExtractParams\Options as OptionsShape2
* @phpstan-import-type OptionsShape from \Stagehand\Sessions\SessionObserveParams\Options as OptionsShape3
*/
interface SessionsContract
{
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param InputShape $input Body param: Natural language instruction or Action object
* @param string|null $frameID Body param: Target frame ID for the action
* @param Options|OptionsShape1 $options Body param
* @param XStreamResponse|value-of<XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function act(
string $id,
string|Action|array $input,
?string $frameID = null,
Options|array|null $options = null,
XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): SessionActResponse;
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param InputShape $input Body param: Natural language instruction or Action object
* @param string|null $frameID Body param: Target frame ID for the action
* @param Options|OptionsShape1 $options Body param
* @param XStreamResponse|value-of<XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @return BaseStream<StreamEvent>
*
* @throws APIException
*/
public function actStream(
string $id,
string|Action|array $input,
?string $frameID = null,
Options|array|null $options = null,
XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): BaseStream;
/**
* @api
*
* @param string $id Unique session identifier
* @param \Stagehand\Sessions\SessionEndParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionEndParams\XStreamResponse> $xStreamResponse Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function end(
string $id,
\Stagehand\Sessions\SessionEndParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): SessionEndResponse;
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param AgentConfig|AgentConfigShape $agentConfig Body param
* @param ExecuteOptions|ExecuteOptionsShape $executeOptions Body param
* @param string|null $frameID Body param: Target frame ID for the agent
* @param bool $shouldCache Body param: If true, the server captures a cache entry and returns it to the client
* @param \Stagehand\Sessions\SessionExecuteParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionExecuteParams\XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function execute(
string $id,
AgentConfig|array $agentConfig,
ExecuteOptions|array $executeOptions,
?string $frameID = null,
?bool $shouldCache = null,
\Stagehand\Sessions\SessionExecuteParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): SessionExecuteResponse;
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param AgentConfig|AgentConfigShape $agentConfig Body param
* @param ExecuteOptions|ExecuteOptionsShape $executeOptions Body param
* @param string|null $frameID Body param: Target frame ID for the agent
* @param bool $shouldCache Body param: If true, the server captures a cache entry and returns it to the client
* @param \Stagehand\Sessions\SessionExecuteParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionExecuteParams\XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @return BaseStream<StreamEvent>
*
* @throws APIException
*/
public function executeStream(
string $id,
AgentConfig|array $agentConfig,
ExecuteOptions|array $executeOptions,
?string $frameID = null,
?bool $shouldCache = null,
\Stagehand\Sessions\SessionExecuteParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): BaseStream;
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param string|null $frameID Body param: Target frame ID for the extraction
* @param string $instruction Body param: Natural language instruction for what to extract
* @param \Stagehand\Sessions\SessionExtractParams\Options|OptionsShape2 $options Body param
* @param array<string,mixed> $schema Body param: JSON Schema defining the structure of data to extract
* @param \Stagehand\Sessions\SessionExtractParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionExtractParams\XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function extract(
string $id,
?string $frameID = null,
?string $instruction = null,
\Stagehand\Sessions\SessionExtractParams\Options|array|null $options = null,
?array $schema = null,
\Stagehand\Sessions\SessionExtractParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): SessionExtractResponse;
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param string|null $frameID Body param: Target frame ID for the extraction
* @param string $instruction Body param: Natural language instruction for what to extract
* @param \Stagehand\Sessions\SessionExtractParams\Options|OptionsShape2 $options Body param
* @param array<string,mixed> $schema Body param: JSON Schema defining the structure of data to extract
* @param \Stagehand\Sessions\SessionExtractParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionExtractParams\XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @return BaseStream<StreamEvent>
*
* @throws APIException
*/
public function extractStream(
string $id,
?string $frameID = null,
?string $instruction = null,
\Stagehand\Sessions\SessionExtractParams\Options|array|null $options = null,
?array $schema = null,
\Stagehand\Sessions\SessionExtractParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): BaseStream;
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param string $url Body param: URL to navigate to
* @param string|null $frameID Body param: Target frame ID for the navigation
* @param \Stagehand\Sessions\SessionNavigateParams\Options|OptionsShape $options Body param
* @param bool $streamResponse Body param: Whether to stream the response via SSE
* @param \Stagehand\Sessions\SessionNavigateParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionNavigateParams\XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function navigate(
string $id,
string $url,
?string $frameID = null,
\Stagehand\Sessions\SessionNavigateParams\Options|array|null $options = null,
?bool $streamResponse = null,
\Stagehand\Sessions\SessionNavigateParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): SessionNavigateResponse;
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param string|null $frameID Body param: Target frame ID for the observation
* @param string $instruction Body param: Natural language instruction for what actions to find
* @param \Stagehand\Sessions\SessionObserveParams\Options|OptionsShape3 $options Body param
* @param \Stagehand\Sessions\SessionObserveParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionObserveParams\XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function observe(
string $id,
?string $frameID = null,
?string $instruction = null,
\Stagehand\Sessions\SessionObserveParams\Options|array|null $options = null,
\Stagehand\Sessions\SessionObserveParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): SessionObserveResponse;
/**
* @api
*
* @param string $id Path param: Unique session identifier
* @param string|null $frameID Body param: Target frame ID for the observation
* @param string $instruction Body param: Natural language instruction for what actions to find
* @param \Stagehand\Sessions\SessionObserveParams\Options|OptionsShape3 $options Body param
* @param \Stagehand\Sessions\SessionObserveParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionObserveParams\XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @return BaseStream<StreamEvent>
*
* @throws APIException
*/
public function observeStream(
string $id,
?string $frameID = null,
?string $instruction = null,
\Stagehand\Sessions\SessionObserveParams\Options|array|null $options = null,
\Stagehand\Sessions\SessionObserveParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): BaseStream;
/**
* @api
*
* @param string $id Unique session identifier
* @param \Stagehand\Sessions\SessionReplayParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionReplayParams\XStreamResponse> $xStreamResponse Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function replay(
string $id,
\Stagehand\Sessions\SessionReplayParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): SessionReplayResponse;
/**
* @api
*
* @param string $modelName Body param: Model name to use for AI operations
* @param float $actTimeoutMs Body param: Timeout in ms for act operations (deprecated, v2 only)
* @param Browser|BrowserShape $browser Body param
* @param BrowserbaseSessionCreateParams|BrowserbaseSessionCreateParamsShape $browserbaseSessionCreateParams Body param
* @param string $browserbaseSessionID Body param: Existing Browserbase session ID to resume
* @param float $domSettleTimeoutMs Body param: Timeout in ms to wait for DOM to settle
* @param bool $experimental Body param
* @param bool $selfHeal Body param: Enable self-healing for failed actions
* @param string $systemPrompt Body param: Custom system prompt for AI operations
* @param float $verbose Body param: Logging verbosity level (0=quiet, 1=normal, 2=debug)
* @param bool $waitForCaptchaSolves Body param: Wait for captcha solves (deprecated, v2 only)
* @param \Stagehand\Sessions\SessionStartParams\XStreamResponse|value-of<\Stagehand\Sessions\SessionStartParams\XStreamResponse> $xStreamResponse Header param: Whether to stream the response via SSE
* @param RequestOpts|null $requestOptions
*
* @throws APIException
*/
public function start(
string $modelName,
?float $actTimeoutMs = null,
Browser|array|null $browser = null,
BrowserbaseSessionCreateParams|array|null $browserbaseSessionCreateParams = null,
?string $browserbaseSessionID = null,
?float $domSettleTimeoutMs = null,
?bool $experimental = null,
?bool $selfHeal = null,
?string $systemPrompt = null,
?float $verbose = null,
?bool $waitForCaptchaSolves = null,
\Stagehand\Sessions\SessionStartParams\XStreamResponse|string|null $xStreamResponse = null,
RequestOptions|array|null $requestOptions = null,
): SessionStartResponse;
}