Skip to content

Commit 7271c1e

Browse files
feat: remove experimental requirement on agent variables (#2079)
1 parent 5ce5e23 commit 7271c1e

6 files changed

Lines changed: 177 additions & 2 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 8
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase/stagehand-f10429ab9f004c9a7f9f362d7fa82915e0dc04b1ba08a7bc9fd442ed5854cc77.yml
3-
openapi_spec_hash: 818f2e6e7eb5eb6f21f346b0b9828dce
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase/stagehand-6f6bfb81d092f30a5e2005328c97d61b9ea36132bb19e9e79e55294b9534ce20.yml
3+
openapi_spec_hash: f3fc1e3688a38dc2c28f7178f7d534e5
44
config_hash: 1fb12ae9b478488bc1e56bfbdc210b01

src/Sessions/SessionExecuteParams/ExecuteOptions.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,19 @@
88
use Stagehand\Core\Attributes\Required;
99
use Stagehand\Core\Concerns\SdkModel;
1010
use Stagehand\Core\Contracts\BaseModel;
11+
use Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable;
1112

1213
/**
14+
* @phpstan-import-type VariableVariants from \Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable
15+
* @phpstan-import-type VariableShape from \Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable
16+
*
1317
* @phpstan-type ExecuteOptionsShape = array{
1418
* instruction: string,
1519
* highlightCursor?: bool|null,
1620
* maxSteps?: float|null,
1721
* toolTimeout?: float|null,
1822
* useSearch?: bool|null,
23+
* variables?: array<string,VariableShape>|null,
1924
* }
2025
*/
2126
final class ExecuteOptions implements BaseModel
@@ -53,6 +58,14 @@ final class ExecuteOptions implements BaseModel
5358
#[Optional]
5459
public ?bool $useSearch;
5560

61+
/**
62+
* Variables available to the agent via %variableName% syntax in supported tools.
63+
*
64+
* @var array<string,VariableVariants>|null $variables
65+
*/
66+
#[Optional(map: Variable::class)]
67+
public ?array $variables;
68+
5669
/**
5770
* `new ExecuteOptions()` is missing required properties by the API.
5871
*
@@ -76,13 +89,16 @@ public function __construct()
7689
* Construct an instance from the required parameters.
7790
*
7891
* You must use named parameters to construct any parameters with a default value.
92+
*
93+
* @param array<string,VariableShape>|null $variables
7994
*/
8095
public static function with(
8196
string $instruction,
8297
?bool $highlightCursor = null,
8398
?float $maxSteps = null,
8499
?float $toolTimeout = null,
85100
?bool $useSearch = null,
101+
?array $variables = null,
86102
): self {
87103
$self = new self;
88104

@@ -92,6 +108,7 @@ public static function with(
92108
null !== $maxSteps && $self['maxSteps'] = $maxSteps;
93109
null !== $toolTimeout && $self['toolTimeout'] = $toolTimeout;
94110
null !== $useSearch && $self['useSearch'] = $useSearch;
111+
null !== $variables && $self['variables'] = $variables;
95112

96113
return $self;
97114
}
@@ -150,4 +167,17 @@ public function withUseSearch(bool $useSearch): self
150167

151168
return $self;
152169
}
170+
171+
/**
172+
* Variables available to the agent via %variableName% syntax in supported tools.
173+
*
174+
* @param array<string,VariableShape> $variables
175+
*/
176+
public function withVariables(array $variables): self
177+
{
178+
$self = clone $this;
179+
$self['variables'] = $variables;
180+
181+
return $self;
182+
}
153183
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stagehand\Sessions\SessionExecuteParams\ExecuteOptions;
6+
7+
use Stagehand\Core\Concerns\SdkUnion;
8+
use Stagehand\Core\Conversion\Contracts\Converter;
9+
use Stagehand\Core\Conversion\Contracts\ConverterSource;
10+
use Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable\UnionMember3;
11+
12+
/**
13+
* @phpstan-import-type UnionMember3Shape from \Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable\UnionMember3
14+
*
15+
* @phpstan-type VariableVariants = string|float|bool|UnionMember3
16+
* @phpstan-type VariableShape = VariableVariants|UnionMember3Shape
17+
*/
18+
final class Variable implements ConverterSource
19+
{
20+
use SdkUnion;
21+
22+
/**
23+
* @return list<string|Converter|ConverterSource>|array<string,string|Converter|ConverterSource>
24+
*/
25+
public static function variants(): array
26+
{
27+
return ['string', 'float', 'bool', UnionMember3::class];
28+
}
29+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable;
6+
7+
use Stagehand\Core\Attributes\Optional;
8+
use Stagehand\Core\Attributes\Required;
9+
use Stagehand\Core\Concerns\SdkModel;
10+
use Stagehand\Core\Contracts\BaseModel;
11+
12+
/**
13+
* @phpstan-import-type ValueVariants from \Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable\UnionMember3\Value
14+
* @phpstan-import-type ValueShape from \Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable\UnionMember3\Value
15+
*
16+
* @phpstan-type UnionMember3Shape = array{
17+
* value: ValueShape, description?: string|null
18+
* }
19+
*/
20+
final class UnionMember3 implements BaseModel
21+
{
22+
/** @use SdkModel<UnionMember3Shape> */
23+
use SdkModel;
24+
25+
/** @var ValueVariants $value */
26+
#[Required]
27+
public string|float|bool $value;
28+
29+
#[Optional]
30+
public ?string $description;
31+
32+
/**
33+
* `new UnionMember3()` is missing required properties by the API.
34+
*
35+
* To enforce required parameters use
36+
* ```
37+
* UnionMember3::with(value: ...)
38+
* ```
39+
*
40+
* Otherwise ensure the following setters are called
41+
*
42+
* ```
43+
* (new UnionMember3)->withValue(...)
44+
* ```
45+
*/
46+
public function __construct()
47+
{
48+
$this->initialize();
49+
}
50+
51+
/**
52+
* Construct an instance from the required parameters.
53+
*
54+
* You must use named parameters to construct any parameters with a default value.
55+
*
56+
* @param ValueShape $value
57+
*/
58+
public static function with(
59+
string|float|bool $value,
60+
?string $description = null
61+
): self {
62+
$self = new self;
63+
64+
$self['value'] = $value;
65+
66+
null !== $description && $self['description'] = $description;
67+
68+
return $self;
69+
}
70+
71+
/**
72+
* @param ValueShape $value
73+
*/
74+
public function withValue(string|float|bool $value): self
75+
{
76+
$self = clone $this;
77+
$self['value'] = $value;
78+
79+
return $self;
80+
}
81+
82+
public function withDescription(string $description): self
83+
{
84+
$self = clone $this;
85+
$self['description'] = $description;
86+
87+
return $self;
88+
}
89+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stagehand\Sessions\SessionExecuteParams\ExecuteOptions\Variable\UnionMember3;
6+
7+
use Stagehand\Core\Concerns\SdkUnion;
8+
use Stagehand\Core\Conversion\Contracts\Converter;
9+
use Stagehand\Core\Conversion\Contracts\ConverterSource;
10+
11+
/**
12+
* @phpstan-type ValueVariants = string|float|bool
13+
* @phpstan-type ValueShape = ValueVariants
14+
*/
15+
final class Value implements ConverterSource
16+
{
17+
use SdkUnion;
18+
19+
/**
20+
* @return list<string|Converter|ConverterSource>|array<string,string|Converter|ConverterSource>
21+
*/
22+
public static function variants(): array
23+
{
24+
return ['string', 'float', 'bool'];
25+
}
26+
}

tests/Services/SessionsTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public function testExecuteWithOptionalParams(): void
159159
'maxSteps' => 20,
160160
'toolTimeout' => 30000,
161161
'useSearch' => true,
162+
'variables' => ['foo' => 'string'],
162163
],
163164
frameID: 'frameId',
164165
shouldCache: true,

0 commit comments

Comments
 (0)