Skip to content

Commit 804b83d

Browse files
feat: [STG-2090] Add Azure Entra model auth support
1 parent a76dda8 commit 804b83d

53 files changed

Lines changed: 5630 additions & 35 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.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-c7910965e66e73ad8b65b6cc391d431094b2a6c6577c3e9d82feaa8138e74cff.yml
3-
openapi_spec_hash: 37748bb69c22a9ce721d9b5a5861f964
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase/stagehand-4d0d50b4f18fd74f58aca0b84d6968d1228499f2fa4e5714516f13ff6f820c9d.yml
3+
openapi_spec_hash: f7b1a869f3e412aea4d4bd42467791bb
44
config_hash: 1fb12ae9b478488bc1e56bfbdc210b01

src/Sessions/ModelConfig.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
use Stagehand\Core\Concerns\SdkUnion;
88
use Stagehand\Core\Conversion\Contracts\Converter;
99
use Stagehand\Core\Conversion\Contracts\ConverterSource;
10+
use Stagehand\Sessions\ModelConfig\AzureAPIKeyModelConfigObject;
11+
use Stagehand\Sessions\ModelConfig\AzureEntraModelConfigObject;
1012
use Stagehand\Sessions\ModelConfig\GenericModelConfigObject;
1113
use Stagehand\Sessions\ModelConfig\VertexModelConfigObject;
1214

1315
/**
1416
* @phpstan-import-type VertexModelConfigObjectShape from \Stagehand\Sessions\ModelConfig\VertexModelConfigObject
17+
* @phpstan-import-type AzureEntraModelConfigObjectShape from \Stagehand\Sessions\ModelConfig\AzureEntraModelConfigObject
18+
* @phpstan-import-type AzureAPIKeyModelConfigObjectShape from \Stagehand\Sessions\ModelConfig\AzureAPIKeyModelConfigObject
1519
* @phpstan-import-type GenericModelConfigObjectShape from \Stagehand\Sessions\ModelConfig\GenericModelConfigObject
1620
*
17-
* @phpstan-type ModelConfigVariants = VertexModelConfigObject|GenericModelConfigObject
18-
* @phpstan-type ModelConfigShape = ModelConfigVariants|VertexModelConfigObjectShape|GenericModelConfigObjectShape
21+
* @phpstan-type ModelConfigVariants = VertexModelConfigObject|AzureEntraModelConfigObject|AzureAPIKeyModelConfigObject|GenericModelConfigObject
22+
* @phpstan-type ModelConfigShape = ModelConfigVariants|VertexModelConfigObjectShape|AzureEntraModelConfigObjectShape|AzureAPIKeyModelConfigObjectShape|GenericModelConfigObjectShape
1923
*/
2024
final class ModelConfig implements ConverterSource
2125
{
@@ -26,6 +30,11 @@ final class ModelConfig implements ConverterSource
2630
*/
2731
public static function variants(): array
2832
{
29-
return [VertexModelConfigObject::class, GenericModelConfigObject::class];
33+
return [
34+
VertexModelConfigObject::class,
35+
AzureEntraModelConfigObject::class,
36+
AzureAPIKeyModelConfigObject::class,
37+
GenericModelConfigObject::class,
38+
];
3039
}
3140
}
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stagehand\Sessions\ModelConfig;
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+
use Stagehand\Sessions\ModelConfig\AzureAPIKeyModelConfigObject\ProviderOptions;
12+
13+
/**
14+
* @phpstan-import-type ProviderOptionsShape from \Stagehand\Sessions\ModelConfig\AzureAPIKeyModelConfigObject\ProviderOptions
15+
*
16+
* @phpstan-type AzureAPIKeyModelConfigObjectShape = array{
17+
* modelName: string,
18+
* provider: 'azure',
19+
* providerOptions: ProviderOptions|ProviderOptionsShape,
20+
* apiKey?: string|null,
21+
* baseURL?: string|null,
22+
* headers?: array<string,string>|null,
23+
* }
24+
*/
25+
final class AzureAPIKeyModelConfigObject implements BaseModel
26+
{
27+
/** @use SdkModel<AzureAPIKeyModelConfigObjectShape> */
28+
use SdkModel;
29+
30+
/**
31+
* Azure OpenAI model provider.
32+
*
33+
* @var 'azure' $provider
34+
*/
35+
#[Required]
36+
public string $provider = 'azure';
37+
38+
/**
39+
* Model name string with provider prefix (e.g., 'openai/gpt-5-nano').
40+
*/
41+
#[Required]
42+
public string $modelName;
43+
44+
/**
45+
* Azure provider-specific model configuration.
46+
*/
47+
#[Required]
48+
public ProviderOptions $providerOptions;
49+
50+
/**
51+
* API key for the model provider.
52+
*/
53+
#[Optional]
54+
public ?string $apiKey;
55+
56+
/**
57+
* Base URL for the model provider.
58+
*/
59+
#[Optional]
60+
public ?string $baseURL;
61+
62+
/**
63+
* Custom headers sent with every request to the model provider.
64+
*
65+
* @var array<string,string>|null $headers
66+
*/
67+
#[Optional(map: 'string')]
68+
public ?array $headers;
69+
70+
/**
71+
* `new AzureAPIKeyModelConfigObject()` is missing required properties by the API.
72+
*
73+
* To enforce required parameters use
74+
* ```
75+
* AzureAPIKeyModelConfigObject::with(modelName: ..., providerOptions: ...)
76+
* ```
77+
*
78+
* Otherwise ensure the following setters are called
79+
*
80+
* ```
81+
* (new AzureAPIKeyModelConfigObject)->withModelName(...)->withProviderOptions(...)
82+
* ```
83+
*/
84+
public function __construct()
85+
{
86+
$this->initialize();
87+
}
88+
89+
/**
90+
* Construct an instance from the required parameters.
91+
*
92+
* You must use named parameters to construct any parameters with a default value.
93+
*
94+
* @param ProviderOptions|ProviderOptionsShape $providerOptions
95+
* @param array<string,string>|null $headers
96+
*/
97+
public static function with(
98+
string $modelName,
99+
ProviderOptions|array $providerOptions,
100+
?string $apiKey = null,
101+
?string $baseURL = null,
102+
?array $headers = null,
103+
): self {
104+
$self = new self;
105+
106+
$self['modelName'] = $modelName;
107+
$self['providerOptions'] = $providerOptions;
108+
109+
null !== $apiKey && $self['apiKey'] = $apiKey;
110+
null !== $baseURL && $self['baseURL'] = $baseURL;
111+
null !== $headers && $self['headers'] = $headers;
112+
113+
return $self;
114+
}
115+
116+
/**
117+
* Model name string with provider prefix (e.g., 'openai/gpt-5-nano').
118+
*/
119+
public function withModelName(string $modelName): self
120+
{
121+
$self = clone $this;
122+
$self['modelName'] = $modelName;
123+
124+
return $self;
125+
}
126+
127+
/**
128+
* Azure OpenAI model provider.
129+
*
130+
* @param 'azure' $provider
131+
*/
132+
public function withProvider(string $provider): self
133+
{
134+
$self = clone $this;
135+
$self['provider'] = $provider;
136+
137+
return $self;
138+
}
139+
140+
/**
141+
* Azure provider-specific model configuration.
142+
*
143+
* @param ProviderOptions|ProviderOptionsShape $providerOptions
144+
*/
145+
public function withProviderOptions(
146+
ProviderOptions|array $providerOptions
147+
): self {
148+
$self = clone $this;
149+
$self['providerOptions'] = $providerOptions;
150+
151+
return $self;
152+
}
153+
154+
/**
155+
* API key for the model provider.
156+
*/
157+
public function withAPIKey(string $apiKey): self
158+
{
159+
$self = clone $this;
160+
$self['apiKey'] = $apiKey;
161+
162+
return $self;
163+
}
164+
165+
/**
166+
* Base URL for the model provider.
167+
*/
168+
public function withBaseURL(string $baseURL): self
169+
{
170+
$self = clone $this;
171+
$self['baseURL'] = $baseURL;
172+
173+
return $self;
174+
}
175+
176+
/**
177+
* Custom headers sent with every request to the model provider.
178+
*
179+
* @param array<string,string> $headers
180+
*/
181+
public function withHeaders(array $headers): self
182+
{
183+
$self = clone $this;
184+
$self['headers'] = $headers;
185+
186+
return $self;
187+
}
188+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stagehand\Sessions\ModelConfig\AzureAPIKeyModelConfigObject;
6+
7+
use Stagehand\Core\Attributes\Required;
8+
use Stagehand\Core\Concerns\SdkModel;
9+
use Stagehand\Core\Contracts\BaseModel;
10+
use Stagehand\Sessions\ModelConfig\AzureAPIKeyModelConfigObject\ProviderOptions\Azure;
11+
12+
/**
13+
* Azure provider-specific model configuration.
14+
*
15+
* @phpstan-import-type AzureShape from \Stagehand\Sessions\ModelConfig\AzureAPIKeyModelConfigObject\ProviderOptions\Azure
16+
*
17+
* @phpstan-type ProviderOptionsShape = array{azure: Azure|AzureShape}
18+
*/
19+
final class ProviderOptions implements BaseModel
20+
{
21+
/** @use SdkModel<ProviderOptionsShape> */
22+
use SdkModel;
23+
24+
/**
25+
* Azure OpenAI provider-specific settings.
26+
*/
27+
#[Required]
28+
public Azure $azure;
29+
30+
/**
31+
* `new ProviderOptions()` is missing required properties by the API.
32+
*
33+
* To enforce required parameters use
34+
* ```
35+
* ProviderOptions::with(azure: ...)
36+
* ```
37+
*
38+
* Otherwise ensure the following setters are called
39+
*
40+
* ```
41+
* (new ProviderOptions)->withAzure(...)
42+
* ```
43+
*/
44+
public function __construct()
45+
{
46+
$this->initialize();
47+
}
48+
49+
/**
50+
* Construct an instance from the required parameters.
51+
*
52+
* You must use named parameters to construct any parameters with a default value.
53+
*
54+
* @param Azure|AzureShape $azure
55+
*/
56+
public static function with(Azure|array $azure): self
57+
{
58+
$self = new self;
59+
60+
$self['azure'] = $azure;
61+
62+
return $self;
63+
}
64+
65+
/**
66+
* Azure OpenAI provider-specific settings.
67+
*
68+
* @param Azure|AzureShape $azure
69+
*/
70+
public function withAzure(Azure|array $azure): self
71+
{
72+
$self = clone $this;
73+
$self['azure'] = $azure;
74+
75+
return $self;
76+
}
77+
}

0 commit comments

Comments
 (0)