Skip to content

Commit 9187d2e

Browse files
feat: variables for observe
1 parent b192d02 commit 9187d2e

10 files changed

Lines changed: 337 additions & 11 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%2Fstagehand-4112eba8679ed34cc7c0e4b28ee3f1569cf47d6e4a8252c28b5ef2ee02a82b8c.yml
3-
openapi_spec_hash: b46202361a71845a51d26e880a444d0b
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-975ca868b31b1e45fb00b31a53d9df1ceec8663f6c2851bf40fdaa84171afadc.yml
3+
openapi_spec_hash: 37891379e0f47e5c69769fbaa1064dab
44
config_hash: 0209737a4ab2a71afececb0ff7459998

src/Sessions/SessionActParams/Options.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,18 @@
88
use Stagehand\Core\Concerns\SdkModel;
99
use Stagehand\Core\Contracts\BaseModel;
1010
use Stagehand\Sessions\ModelConfig;
11+
use Stagehand\Sessions\SessionActParams\Options\Variable;
1112

1213
/**
1314
* @phpstan-import-type ModelVariants from \Stagehand\Sessions\SessionActParams\Options\Model
15+
* @phpstan-import-type VariableVariants from \Stagehand\Sessions\SessionActParams\Options\Variable
1416
* @phpstan-import-type ModelShape from \Stagehand\Sessions\SessionActParams\Options\Model
17+
* @phpstan-import-type VariableShape from \Stagehand\Sessions\SessionActParams\Options\Variable
1518
*
1619
* @phpstan-type OptionsShape = array{
1720
* model?: ModelShape|null,
1821
* timeout?: float|null,
19-
* variables?: array<string,string>|null,
22+
* variables?: array<string,VariableShape>|null,
2023
* }
2124
*/
2225
final class Options implements BaseModel
@@ -39,11 +42,11 @@ final class Options implements BaseModel
3942
public ?float $timeout;
4043

4144
/**
42-
* Variables to substitute in the action instruction.
45+
* Variables to substitute in the action instruction. Accepts flat primitives or { value, description? } objects.
4346
*
44-
* @var array<string,string>|null $variables
47+
* @var array<string,VariableVariants>|null $variables
4548
*/
46-
#[Optional(map: 'string')]
49+
#[Optional(map: Variable::class)]
4750
public ?array $variables;
4851

4952
public function __construct()
@@ -57,7 +60,7 @@ public function __construct()
5760
* You must use named parameters to construct any parameters with a default value.
5861
*
5962
* @param ModelShape|null $model
60-
* @param array<string,string>|null $variables
63+
* @param array<string,VariableShape>|null $variables
6164
*/
6265
public static function with(
6366
string|ModelConfig|array|null $model = null,
@@ -98,9 +101,9 @@ public function withTimeout(float $timeout): self
98101
}
99102

100103
/**
101-
* Variables to substitute in the action instruction.
104+
* Variables to substitute in the action instruction. Accepts flat primitives or { value, description? } objects.
102105
*
103-
* @param array<string,string> $variables
106+
* @param array<string,VariableShape> $variables
104107
*/
105108
public function withVariables(array $variables): self
106109
{
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\SessionActParams\Options;
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\SessionActParams\Options\Variable\UnionMember3;
11+
12+
/**
13+
* @phpstan-import-type UnionMember3Shape from \Stagehand\Sessions\SessionActParams\Options\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\SessionActParams\Options\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\SessionActParams\Options\Variable\UnionMember3\Value
14+
* @phpstan-import-type ValueShape from \Stagehand\Sessions\SessionActParams\Options\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\SessionActParams\Options\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+
}

src/Sessions/SessionObserveParams/Options.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
use Stagehand\Core\Concerns\SdkModel;
99
use Stagehand\Core\Contracts\BaseModel;
1010
use Stagehand\Sessions\ModelConfig;
11+
use Stagehand\Sessions\SessionObserveParams\Options\Variable;
1112

1213
/**
1314
* @phpstan-import-type ModelVariants from \Stagehand\Sessions\SessionObserveParams\Options\Model
15+
* @phpstan-import-type VariableVariants from \Stagehand\Sessions\SessionObserveParams\Options\Variable
1416
* @phpstan-import-type ModelShape from \Stagehand\Sessions\SessionObserveParams\Options\Model
17+
* @phpstan-import-type VariableShape from \Stagehand\Sessions\SessionObserveParams\Options\Variable
1518
*
1619
* @phpstan-type OptionsShape = array{
17-
* model?: ModelShape|null, selector?: string|null, timeout?: float|null
20+
* model?: ModelShape|null,
21+
* selector?: string|null,
22+
* timeout?: float|null,
23+
* variables?: array<string,VariableShape>|null,
1824
* }
1925
*/
2026
final class Options implements BaseModel
@@ -42,6 +48,14 @@ final class Options implements BaseModel
4248
#[Optional]
4349
public ?float $timeout;
4450

51+
/**
52+
* Variables whose names are exposed to the model so observe() returns %variableName% placeholders in suggested action arguments instead of literal values. Accepts flat primitives or { value, description? } objects.
53+
*
54+
* @var array<string,VariableVariants>|null $variables
55+
*/
56+
#[Optional(map: Variable::class)]
57+
public ?array $variables;
58+
4559
public function __construct()
4660
{
4761
$this->initialize();
@@ -53,17 +67,20 @@ public function __construct()
5367
* You must use named parameters to construct any parameters with a default value.
5468
*
5569
* @param ModelShape|null $model
70+
* @param array<string,VariableShape>|null $variables
5671
*/
5772
public static function with(
5873
string|ModelConfig|array|null $model = null,
5974
?string $selector = null,
6075
?float $timeout = null,
76+
?array $variables = null,
6177
): self {
6278
$self = new self;
6379

6480
null !== $model && $self['model'] = $model;
6581
null !== $selector && $self['selector'] = $selector;
6682
null !== $timeout && $self['timeout'] = $timeout;
83+
null !== $variables && $self['variables'] = $variables;
6784

6885
return $self;
6986
}
@@ -102,4 +119,17 @@ public function withTimeout(float $timeout): self
102119

103120
return $self;
104121
}
122+
123+
/**
124+
* Variables whose names are exposed to the model so observe() returns %variableName% placeholders in suggested action arguments instead of literal values. Accepts flat primitives or { value, description? } objects.
125+
*
126+
* @param array<string,VariableShape> $variables
127+
*/
128+
public function withVariables(array $variables): self
129+
{
130+
$self = clone $this;
131+
$self['variables'] = $variables;
132+
133+
return $self;
134+
}
105135
}
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\SessionObserveParams\Options;
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\SessionObserveParams\Options\Variable\UnionMember3;
11+
12+
/**
13+
* @phpstan-import-type UnionMember3Shape from \Stagehand\Sessions\SessionObserveParams\Options\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+
}

0 commit comments

Comments
 (0)