File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,11 +37,17 @@ public function __construct(
3737 ?string $ baseUrl = null ,
3838 RequestOptions |array |null $ requestOptions = null ,
3939 ) {
40- $ this ->browserbaseAPIKey = (string ) ($ browserbaseAPIKey ?? getenv ('BROWSERBASE_API_KEY ' ));
41- $ this ->browserbaseProjectID = (string ) ($ browserbaseProjectID ?? getenv ('BROWSERBASE_PROJECT_ID ' ));
42- $ this ->modelAPIKey = (string ) ($ modelAPIKey ?? getenv ('MODEL_API_KEY ' ));
43-
44- $ baseUrl ??= getenv (
40+ $ this ->browserbaseAPIKey = (string ) ($ browserbaseAPIKey ?? Util::getenv (
41+ 'BROWSERBASE_API_KEY '
42+ ));
43+ $ this ->browserbaseProjectID = (string ) ($ browserbaseProjectID ?? Util::getenv (
44+ 'BROWSERBASE_PROJECT_ID '
45+ ));
46+ $ this ->modelAPIKey = (string ) ($ modelAPIKey ?? Util::getenv (
47+ 'MODEL_API_KEY '
48+ ));
49+
50+ $ baseUrl ??= Util::getenv (
4551 'STAGEHAND_BASE_URL '
4652 ) ?: 'https://api.stagehand.browserbase.com ' ;
4753
Original file line number Diff line number Diff line change @@ -25,6 +25,23 @@ final class Util
2525
2626 public const JSONL_CONTENT_TYPE = '/^application\/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)/ ' ;
2727
28+ public static function getenv (string $ key ): ?string
29+ {
30+ if (array_key_exists ($ key , array: $ _ENV )) {
31+ if (!is_string ($ value = $ _ENV [$ key ])) {
32+ throw new \InvalidArgumentException ;
33+ }
34+
35+ return $ value ;
36+ }
37+
38+ if (is_string ($ value = getenv ($ key ))) {
39+ return $ value ;
40+ }
41+
42+ return null ;
43+ }
44+
2845 /**
2946 * @return array<string,mixed>
3047 */
Original file line number Diff line number Diff line change 66use PHPUnit \Framework \Attributes \Test ;
77use PHPUnit \Framework \TestCase ;
88use Stagehand \Client ;
9+ use Stagehand \Core \Util ;
910use Stagehand \Sessions \SessionActResponse ;
1011use Stagehand \Sessions \SessionEndResponse ;
1112use Stagehand \Sessions \SessionExecuteResponse ;
@@ -28,7 +29,7 @@ protected function setUp(): void
2829 {
2930 parent ::setUp ();
3031
31- $ testUrl = getenv ('TEST_API_BASE_URL ' ) ?: 'http://127.0.0.1:4010 ' ;
32+ $ testUrl = Util:: getenv ('TEST_API_BASE_URL ' ) ?: 'http://127.0.0.1:4010 ' ;
3233 $ client = new Client (
3334 browserbaseAPIKey: 'My Browserbase API Key ' ,
3435 browserbaseProjectID: 'My Browserbase Project ID ' ,
You can’t perform that action at this time.
0 commit comments