99use Stagehand \Core \Concerns \SdkModel ;
1010use Stagehand \Core \Concerns \SdkParams ;
1111use 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.
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 */
0 commit comments