Skip to content

Commit bd33c5a

Browse files
feat: Add executionModel serialization to api client
1 parent f583566 commit bd33c5a

7 files changed

Lines changed: 83 additions & 24 deletions

File tree

.github/workflows/publish-packagist.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

.stats.yml

Lines changed: 3 additions & 3 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-43e6dd4ce19381de488d296e9036fea15bfea9a6f946cf8ccf4e02aecc8fb765.yml
3-
openapi_spec_hash: f736e7a8acea0d73e1031c86ea803246
4-
config_hash: b375728ccf7d33287335852f4f59c293
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-8fbb3fa8f3a37c1c7408de427fe125aadec49f705e8e30d191601a9b69c4cc41.yml
3+
openapi_spec_hash: 48b4dfac35a842d7fb0d228caf87544e
4+
config_hash: 242651c4871c2869ba3c2e3d337505b9

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,22 @@ The REST API documentation can be found on [docs.stagehand.dev](https://docs.sta
7777

7878
## Installation
7979

80+
To use this package, install via Composer by adding the following to your application's `composer.json`:
81+
8082
<!-- x-release-please-start-version -->
8183

82-
```
83-
composer require "browserbase/stagehand 3.10.0"
84+
```json
85+
{
86+
"repositories": [
87+
{
88+
"type": "vcs",
89+
"url": "git@github.com:browserbase/stagehand-php.git"
90+
}
91+
],
92+
"require": {
93+
"browserbase/stagehand": "dev-main"
94+
}
95+
}
8496
```
8597

8698
<!-- x-release-please-end -->

src/SSEStream.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private function parsedGenerator(): \Generator
4949
}
5050

5151
if ($data = $row['data'] ?? '') {
52-
if (str_starts_with($data, needle: '{"data":{"status":"finished"')) {
52+
if (str_starts_with($data, needle: 'finished')) {
5353
$done = true;
5454

5555
continue;

src/Sessions/SessionExecuteParams/AgentConfig.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
use Stagehand\Sessions\SessionExecuteParams\AgentConfig\Provider;
1313

1414
/**
15+
* @phpstan-import-type ExecutionModelVariants from \Stagehand\Sessions\SessionExecuteParams\AgentConfig\ExecutionModel
1516
* @phpstan-import-type ModelVariants from \Stagehand\Sessions\SessionExecuteParams\AgentConfig\Model
17+
* @phpstan-import-type ExecutionModelShape from \Stagehand\Sessions\SessionExecuteParams\AgentConfig\ExecutionModel
1618
* @phpstan-import-type ModelShape from \Stagehand\Sessions\SessionExecuteParams\AgentConfig\Model
1719
*
1820
* @phpstan-type AgentConfigShape = array{
1921
* cua?: bool|null,
22+
* executionModel?: ExecutionModelShape|null,
2023
* mode?: null|Mode|value-of<Mode>,
2124
* model?: ModelShape|null,
2225
* provider?: null|Provider|value-of<Provider>,
@@ -34,6 +37,14 @@ final class AgentConfig implements BaseModel
3437
#[Optional]
3538
public ?bool $cua;
3639

40+
/**
41+
* Model configuration object or model name string (e.g., 'openai/gpt-5-nano') for tool execution (observe/act calls within agent tools). If not specified, inherits from the main model configuration.
42+
*
43+
* @var ExecutionModelVariants|null $executionModel
44+
*/
45+
#[Optional]
46+
public string|ModelConfig|null $executionModel;
47+
3748
/**
3849
* Tool mode for the agent (dom, hybrid, cua). If set, overrides cua.
3950
*
@@ -74,12 +85,14 @@ public function __construct()
7485
*
7586
* You must use named parameters to construct any parameters with a default value.
7687
*
88+
* @param ExecutionModelShape|null $executionModel
7789
* @param Mode|value-of<Mode>|null $mode
7890
* @param ModelShape|null $model
7991
* @param Provider|value-of<Provider>|null $provider
8092
*/
8193
public static function with(
8294
?bool $cua = null,
95+
string|ModelConfig|array|null $executionModel = null,
8396
Mode|string|null $mode = null,
8497
string|ModelConfig|array|null $model = null,
8598
Provider|string|null $provider = null,
@@ -88,6 +101,7 @@ public static function with(
88101
$self = new self;
89102

90103
null !== $cua && $self['cua'] = $cua;
104+
null !== $executionModel && $self['executionModel'] = $executionModel;
91105
null !== $mode && $self['mode'] = $mode;
92106
null !== $model && $self['model'] = $model;
93107
null !== $provider && $self['provider'] = $provider;
@@ -107,6 +121,20 @@ public function withCua(bool $cua): self
107121
return $self;
108122
}
109123

124+
/**
125+
* Model configuration object or model name string (e.g., 'openai/gpt-5-nano') for tool execution (observe/act calls within agent tools). If not specified, inherits from the main model configuration.
126+
*
127+
* @param ExecutionModelShape $executionModel
128+
*/
129+
public function withExecutionModel(
130+
string|ModelConfig|array $executionModel
131+
): self {
132+
$self = clone $this;
133+
$self['executionModel'] = $executionModel;
134+
135+
return $self;
136+
}
137+
110138
/**
111139
* Tool mode for the agent (dom, hybrid, cua). If set, overrides cua.
112140
*
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Stagehand\Sessions\SessionExecuteParams\AgentConfig;
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\ModelConfig;
11+
12+
/**
13+
* Model configuration object or model name string (e.g., 'openai/gpt-5-nano') for tool execution (observe/act calls within agent tools). If not specified, inherits from the main model configuration.
14+
*
15+
* @phpstan-import-type ModelConfigShape from \Stagehand\Sessions\ModelConfig
16+
*
17+
* @phpstan-type ExecutionModelVariants = string|ModelConfig
18+
* @phpstan-type ExecutionModelShape = ExecutionModelVariants|ModelConfigShape
19+
*/
20+
final class ExecutionModel implements ConverterSource
21+
{
22+
use SdkUnion;
23+
24+
/**
25+
* @return list<string|Converter|ConverterSource>|array<string,string|Converter|ConverterSource>
26+
*/
27+
public static function variants(): array
28+
{
29+
return [ModelConfig::class, 'string'];
30+
}
31+
}

tests/Services/SessionsTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ public function testExecuteWithOptionalParams(): void
128128
'c4dbf3a9-9a58-4b22-8a1c-9f20f9f9e123',
129129
agentConfig: [
130130
'cua' => true,
131+
'executionModel' => [
132+
'modelName' => 'openai/gpt-5-nano',
133+
'apiKey' => 'sk-some-openai-api-key',
134+
'baseURL' => 'https://api.openai.com/v1',
135+
'provider' => 'openai',
136+
],
131137
'mode' => 'cua',
132138
'model' => [
133139
'modelName' => 'openai/gpt-5-nano',

0 commit comments

Comments
 (0)