Skip to content

Commit 9cb66f2

Browse files
feat(api): manual updates
1 parent 75563a5 commit 9cb66f2

9 files changed

Lines changed: 61 additions & 191 deletions

File tree

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 7
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-09064f4021f94fb1b1bd86ce496d998318276b61bbc24de4728ecdb5763847ef.yml
3-
openapi_spec_hash: 911d0631010b372890f98545a038cfb5
4-
config_hash: bb7561632c1f66c2b9efca06f438f904
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-6a22863a7da4fa45f904657a4cb8fc1a28e236925f03dc94fca25fd8271ca6db.yml
3+
openapi_spec_hash: d5c6108942ad79f39ea4ff1bee9b7996
4+
config_hash: 2f1ec44e7e07906e07bdc6e075763da9

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ $client = new Client(
5151
apiKey: getenv('STAGEHAND_API_KEY') ?: 'My API Key', environment: 'dev'
5252
);
5353

54-
$response = $client->sessions->start(env: 'LOCAL');
54+
$response = $client->sessions->act(
55+
'182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
56+
input: 'click the first link on the page',
57+
);
5558

56-
var_dump($response->available);
59+
var_dump($response->actions);
5760
```
5861

5962
### Value Objects
@@ -73,7 +76,10 @@ When the library is unable to connect to the API, or if the API returns a non-su
7376
use Stagehand\Core\Exceptions\APIConnectionException;
7477

7578
try {
76-
$response = $client->sessions->start(env: 'LOCAL');
79+
$response = $client->sessions->start(
80+
browserbaseAPIKey: 'BROWSERBASE_API_KEY',
81+
browserbaseProjectID: 'BROWSERBASE_PROJECT_ID',
82+
);
7783
} catch (APIConnectionException $e) {
7884
echo "The server could not be reached", PHP_EOL;
7985
var_dump($e->getPrevious());
@@ -120,7 +126,9 @@ $client = new Client(maxRetries: 0);
120126

121127
// Or, configure per-request:
122128
$result = $client->sessions->start(
123-
env: 'LOCAL', requestOptions: RequestOptions::with(maxRetries: 5)
129+
browserbaseAPIKey: 'BROWSERBASE_API_KEY',
130+
browserbaseProjectID: 'BROWSERBASE_PROJECT_ID',
131+
requestOptions: RequestOptions::with(maxRetries: 5),
124132
);
125133
```
126134

@@ -140,7 +148,8 @@ Note: the `extra*` parameters of the same name overrides the documented paramete
140148
use Stagehand\RequestOptions;
141149

142150
$response = $client->sessions->start(
143-
env: 'LOCAL',
151+
browserbaseAPIKey: 'BROWSERBASE_API_KEY',
152+
browserbaseProjectID: 'BROWSERBASE_PROJECT_ID',
144153
requestOptions: RequestOptions::with(
145154
extraQueryParams: ['my_query_parameter' => 'value'],
146155
extraBodyParams: ['my_body_parameter' => 'value'],

src/ServiceContracts/SessionsContract.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Stagehand\Sessions\SessionExtractResponse\Extraction;
1616
use Stagehand\Sessions\SessionNavigateParams\Options\WaitUntil;
1717
use Stagehand\Sessions\SessionNavigateResponse;
18-
use Stagehand\Sessions\SessionStartParams\Env;
1918
use Stagehand\Sessions\SessionStartResponse;
2019

2120
interface SessionsContract
@@ -188,27 +187,21 @@ public function observe(
188187
/**
189188
* @api
190189
*
191-
* @param 'LOCAL'|'BROWSERBASE'|Env $env Environment to run the browser in
192-
* @param string $apiKey API key for Browserbase (required when env=BROWSERBASE)
190+
* @param string $browserbaseAPIKey API key for Browserbase Cloud
191+
* @param string $browserbaseProjectID Project ID for Browserbase
193192
* @param int $domSettleTimeout Timeout in ms to wait for DOM to settle
194-
* @param array{
195-
* headless?: bool
196-
* } $localBrowserLaunchOptions Options for local browser launch
197-
* @param string $model AI model to use for actions
198-
* @param string $projectID Project ID for Browserbase (required when env=BROWSERBASE)
193+
* @param string $model AI model to use for actions (must be prefixed with provider/)
199194
* @param bool $selfHeal Enable self-healing for failed actions
200195
* @param string $systemPrompt Custom system prompt for AI actions
201196
* @param int $verbose Logging verbosity level
202197
*
203198
* @throws APIException
204199
*/
205200
public function start(
206-
string|Env $env,
207-
?string $apiKey = null,
201+
string $browserbaseAPIKey,
202+
string $browserbaseProjectID,
208203
?int $domSettleTimeout = null,
209-
?array $localBrowserLaunchOptions = null,
210204
?string $model = null,
211-
?string $projectID = null,
212205
?bool $selfHeal = null,
213206
?string $systemPrompt = null,
214207
int $verbose = 0,

src/Services/SessionsRawService.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Stagehand\Sessions\SessionNavigateResponse;
2828
use Stagehand\Sessions\SessionObserveParams;
2929
use Stagehand\Sessions\SessionStartParams;
30-
use Stagehand\Sessions\SessionStartParams\Env;
3130
use Stagehand\Sessions\SessionStartResponse;
3231

3332
final class SessionsRawService implements SessionsRawContract
@@ -346,12 +345,10 @@ public function observe(
346345
* Returns a session ID that must be used for all subsequent requests.
347346
*
348347
* @param array{
349-
* env: 'LOCAL'|'BROWSERBASE'|Env,
350-
* apiKey?: string,
348+
* browserbaseAPIKey: string,
349+
* browserbaseProjectID: string,
351350
* domSettleTimeout?: int,
352-
* localBrowserLaunchOptions?: array{headless?: bool},
353351
* model?: string,
354-
* projectID?: string,
355352
* selfHeal?: bool,
356353
* systemPrompt?: string,
357354
* verbose?: int,

src/Services/SessionsService.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use Stagehand\Sessions\SessionExtractResponse\Extraction;
1919
use Stagehand\Sessions\SessionNavigateParams\Options\WaitUntil;
2020
use Stagehand\Sessions\SessionNavigateResponse;
21-
use Stagehand\Sessions\SessionStartParams\Env;
2221
use Stagehand\Sessions\SessionStartResponse;
2322

2423
final class SessionsService implements SessionsContract
@@ -299,40 +298,32 @@ public function observe(
299298
* Initializes a new Stagehand session with a browser instance.
300299
* Returns a session ID that must be used for all subsequent requests.
301300
*
302-
* @param 'LOCAL'|'BROWSERBASE'|Env $env Environment to run the browser in
303-
* @param string $apiKey API key for Browserbase (required when env=BROWSERBASE)
301+
* @param string $browserbaseAPIKey API key for Browserbase Cloud
302+
* @param string $browserbaseProjectID Project ID for Browserbase
304303
* @param int $domSettleTimeout Timeout in ms to wait for DOM to settle
305-
* @param array{
306-
* headless?: bool
307-
* } $localBrowserLaunchOptions Options for local browser launch
308-
* @param string $model AI model to use for actions
309-
* @param string $projectID Project ID for Browserbase (required when env=BROWSERBASE)
304+
* @param string $model AI model to use for actions (must be prefixed with provider/)
310305
* @param bool $selfHeal Enable self-healing for failed actions
311306
* @param string $systemPrompt Custom system prompt for AI actions
312307
* @param int $verbose Logging verbosity level
313308
*
314309
* @throws APIException
315310
*/
316311
public function start(
317-
string|Env $env,
318-
?string $apiKey = null,
312+
string $browserbaseAPIKey,
313+
string $browserbaseProjectID,
319314
?int $domSettleTimeout = null,
320-
?array $localBrowserLaunchOptions = null,
321315
?string $model = null,
322-
?string $projectID = null,
323316
?bool $selfHeal = null,
324317
?string $systemPrompt = null,
325318
int $verbose = 0,
326319
?RequestOptions $requestOptions = null,
327320
): SessionStartResponse {
328321
$params = Util::removeNulls(
329322
[
330-
'env' => $env,
331-
'apiKey' => $apiKey,
323+
'browserbaseAPIKey' => $browserbaseAPIKey,
324+
'browserbaseProjectID' => $browserbaseProjectID,
332325
'domSettleTimeout' => $domSettleTimeout,
333-
'localBrowserLaunchOptions' => $localBrowserLaunchOptions,
334326
'model' => $model,
335-
'projectID' => $projectID,
336327
'selfHeal' => $selfHeal,
337328
'systemPrompt' => $systemPrompt,
338329
'verbose' => $verbose,

src/Sessions/SessionStartParams.php

Lines changed: 24 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
use Stagehand\Core\Concerns\SdkModel;
1010
use Stagehand\Core\Concerns\SdkParams;
1111
use Stagehand\Core\Contracts\BaseModel;
12-
use Stagehand\Sessions\SessionStartParams\Env;
13-
use Stagehand\Sessions\SessionStartParams\LocalBrowserLaunchOptions;
1412

1513
/**
1614
* Initializes a new Stagehand session with a browser instance.
@@ -19,14 +17,10 @@
1917
* @see Stagehand\Services\SessionsService::start()
2018
*
2119
* @phpstan-type SessionStartParamsShape = array{
22-
* env: Env|value-of<Env>,
23-
* apiKey?: string,
20+
* browserbaseAPIKey: string,
21+
* browserbaseProjectID: string,
2422
* domSettleTimeout?: int,
25-
* localBrowserLaunchOptions?: LocalBrowserLaunchOptions|array{
26-
* headless?: bool|null
27-
* },
2823
* model?: string,
29-
* projectID?: string,
3024
* selfHeal?: bool,
3125
* systemPrompt?: string,
3226
* verbose?: int,
@@ -39,18 +33,16 @@ final class SessionStartParams implements BaseModel
3933
use SdkParams;
4034

4135
/**
42-
* Environment to run the browser in.
43-
*
44-
* @var value-of<Env> $env
36+
* API key for Browserbase Cloud.
4537
*/
46-
#[Required(enum: Env::class)]
47-
public string $env;
38+
#[Required('BROWSERBASE_API_KEY')]
39+
public string $browserbaseAPIKey;
4840

4941
/**
50-
* API key for Browserbase (required when env=BROWSERBASE).
42+
* Project ID for Browserbase.
5143
*/
52-
#[Optional]
53-
public ?string $apiKey;
44+
#[Required('BROWSERBASE_PROJECT_ID')]
45+
public string $browserbaseProjectID;
5446

5547
/**
5648
* Timeout in ms to wait for DOM to settle.
@@ -59,23 +51,11 @@ final class SessionStartParams implements BaseModel
5951
public ?int $domSettleTimeout;
6052

6153
/**
62-
* Options for local browser launch.
63-
*/
64-
#[Optional]
65-
public ?LocalBrowserLaunchOptions $localBrowserLaunchOptions;
66-
67-
/**
68-
* AI model to use for actions.
54+
* AI model to use for actions (must be prefixed with provider/).
6955
*/
7056
#[Optional]
7157
public ?string $model;
7258

73-
/**
74-
* Project ID for Browserbase (required when env=BROWSERBASE).
75-
*/
76-
#[Optional('projectId')]
77-
public ?string $projectID;
78-
7959
/**
8060
* Enable self-healing for failed actions.
8161
*/
@@ -99,13 +79,15 @@ final class SessionStartParams implements BaseModel
9979
*
10080
* To enforce required parameters use
10181
* ```
102-
* SessionStartParams::with(env: ...)
82+
* SessionStartParams::with(browserbaseAPIKey: ..., browserbaseProjectID: ...)
10383
* ```
10484
*
10585
* Otherwise ensure the following setters are called
10686
*
10787
* ```
108-
* (new SessionStartParams)->withEnv(...)
88+
* (new SessionStartParams)
89+
* ->withBrowserbaseAPIKey(...)
90+
* ->withBrowserbaseProjectID(...)
10991
* ```
11092
*/
11193
public function __construct()
@@ -117,32 +99,23 @@ public function __construct()
11799
* Construct an instance from the required parameters.
118100
*
119101
* You must use named parameters to construct any parameters with a default value.
120-
*
121-
* @param Env|value-of<Env> $env
122-
* @param LocalBrowserLaunchOptions|array{
123-
* headless?: bool|null
124-
* } $localBrowserLaunchOptions
125102
*/
126103
public static function with(
127-
Env|string $env,
128-
?string $apiKey = null,
104+
string $browserbaseAPIKey,
105+
string $browserbaseProjectID,
129106
?int $domSettleTimeout = null,
130-
LocalBrowserLaunchOptions|array|null $localBrowserLaunchOptions = null,
131107
?string $model = null,
132-
?string $projectID = null,
133108
?bool $selfHeal = null,
134109
?string $systemPrompt = null,
135110
?int $verbose = null,
136111
): self {
137112
$self = new self;
138113

139-
$self['env'] = $env;
114+
$self['browserbaseAPIKey'] = $browserbaseAPIKey;
115+
$self['browserbaseProjectID'] = $browserbaseProjectID;
140116

141-
null !== $apiKey && $self['apiKey'] = $apiKey;
142117
null !== $domSettleTimeout && $self['domSettleTimeout'] = $domSettleTimeout;
143-
null !== $localBrowserLaunchOptions && $self['localBrowserLaunchOptions'] = $localBrowserLaunchOptions;
144118
null !== $model && $self['model'] = $model;
145-
null !== $projectID && $self['projectID'] = $projectID;
146119
null !== $selfHeal && $self['selfHeal'] = $selfHeal;
147120
null !== $systemPrompt && $self['systemPrompt'] = $systemPrompt;
148121
null !== $verbose && $self['verbose'] = $verbose;
@@ -151,25 +124,23 @@ public static function with(
151124
}
152125

153126
/**
154-
* Environment to run the browser in.
155-
*
156-
* @param Env|value-of<Env> $env
127+
* API key for Browserbase Cloud.
157128
*/
158-
public function withEnv(Env|string $env): self
129+
public function withBrowserbaseAPIKey(string $browserbaseAPIKey): self
159130
{
160131
$self = clone $this;
161-
$self['env'] = $env;
132+
$self['browserbaseAPIKey'] = $browserbaseAPIKey;
162133

163134
return $self;
164135
}
165136

166137
/**
167-
* API key for Browserbase (required when env=BROWSERBASE).
138+
* Project ID for Browserbase.
168139
*/
169-
public function withAPIKey(string $apiKey): self
140+
public function withBrowserbaseProjectID(string $browserbaseProjectID): self
170141
{
171142
$self = clone $this;
172-
$self['apiKey'] = $apiKey;
143+
$self['browserbaseProjectID'] = $browserbaseProjectID;
173144

174145
return $self;
175146
}
@@ -186,23 +157,7 @@ public function withDomSettleTimeout(int $domSettleTimeout): self
186157
}
187158

188159
/**
189-
* Options for local browser launch.
190-
*
191-
* @param LocalBrowserLaunchOptions|array{
192-
* headless?: bool|null
193-
* } $localBrowserLaunchOptions
194-
*/
195-
public function withLocalBrowserLaunchOptions(
196-
LocalBrowserLaunchOptions|array $localBrowserLaunchOptions
197-
): self {
198-
$self = clone $this;
199-
$self['localBrowserLaunchOptions'] = $localBrowserLaunchOptions;
200-
201-
return $self;
202-
}
203-
204-
/**
205-
* AI model to use for actions.
160+
* AI model to use for actions (must be prefixed with provider/).
206161
*/
207162
public function withModel(string $model): self
208163
{
@@ -212,17 +167,6 @@ public function withModel(string $model): self
212167
return $self;
213168
}
214169

215-
/**
216-
* Project ID for Browserbase (required when env=BROWSERBASE).
217-
*/
218-
public function withProjectID(string $projectID): self
219-
{
220-
$self = clone $this;
221-
$self['projectID'] = $projectID;
222-
223-
return $self;
224-
}
225-
226170
/**
227171
* Enable self-healing for failed actions.
228172
*/

src/Sessions/SessionStartParams/Env.php

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)