Skip to content

Commit 93ef310

Browse files
feat: variables for observe
1 parent 5201ec1 commit 93ef310

File tree

4 files changed

+104
-11
lines changed

4 files changed

+104
-11
lines changed

.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/stagehand/types/session_act_params.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"Input",
1515
"Options",
1616
"OptionsModel",
17+
"OptionsVariables",
18+
"OptionsVariablesUnionMember3",
1719
"SessionActParamsNonStreaming",
1820
"SessionActParamsStreaming",
1921
]
@@ -37,15 +39,27 @@ class SessionActParamsBase(TypedDict, total=False):
3739
OptionsModel: TypeAlias = Union[ModelConfigParam, str]
3840

3941

42+
class OptionsVariablesUnionMember3(TypedDict, total=False):
43+
value: Required[Union[str, float, bool]]
44+
45+
description: str
46+
47+
48+
OptionsVariables: TypeAlias = Union[str, float, bool, OptionsVariablesUnionMember3]
49+
50+
4051
class Options(TypedDict, total=False):
4152
model: OptionsModel
4253
"""Model configuration object or model name string (e.g., 'openai/gpt-5-nano')"""
4354

4455
timeout: float
4556
"""Timeout in ms for the action"""
4657

47-
variables: Dict[str, str]
48-
"""Variables to substitute in the action instruction"""
58+
variables: Dict[str, OptionsVariables]
59+
"""Variables to substitute in the action instruction.
60+
61+
Accepts flat primitives or { value, description? } objects.
62+
"""
4963

5064

5165
class SessionActParamsNonStreaming(SessionActParamsBase, total=False):

src/stagehand/types/session_observe_params.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
from __future__ import annotations
44

5-
from typing import Union, Optional
6-
from typing_extensions import Literal, Required, Annotated, TypedDict
5+
from typing import Dict, Union, Optional
6+
from typing_extensions import Literal, Required, Annotated, TypeAlias, TypedDict
77

88
from .._utils import PropertyInfo
99
from .model_config_param import ModelConfigParam
1010

11-
__all__ = ["SessionObserveParamsBase", "Options", "SessionObserveParamsNonStreaming", "SessionObserveParamsStreaming"]
11+
__all__ = [
12+
"SessionObserveParamsBase",
13+
"Options",
14+
"OptionsModel",
15+
"OptionsVariables",
16+
"OptionsVariablesUnionMember3",
17+
"SessionObserveParamsNonStreaming",
18+
"SessionObserveParamsStreaming",
19+
]
1220

1321

1422
class SessionObserveParamsBase(TypedDict, total=False):
@@ -24,6 +32,18 @@ class SessionObserveParamsBase(TypedDict, total=False):
2432
"""Whether to stream the response via SSE"""
2533

2634

35+
OptionsModel: TypeAlias = Union[ModelConfigParam, str]
36+
37+
38+
class OptionsVariablesUnionMember3(TypedDict, total=False):
39+
value: Required[Union[str, float, bool]]
40+
41+
description: str
42+
43+
44+
OptionsVariables: TypeAlias = Union[str, float, bool, OptionsVariablesUnionMember3]
45+
46+
2747
class Options(TypedDict, total=False):
2848
model: ModelConfigParam
2949
"""
@@ -37,6 +57,13 @@ class Options(TypedDict, total=False):
3757
timeout: float
3858
"""Timeout in ms for the observation"""
3959

60+
variables: Dict[str, OptionsVariables]
61+
"""
62+
Variables whose names are exposed to the model so observe() returns
63+
%variableName% placeholders in suggested action arguments instead of literal
64+
values. Accepts flat primitives or { value, description? } objects.
65+
"""
66+
4067

4168
class SessionObserveParamsNonStreaming(SessionObserveParamsBase, total=False):
4269
stream_response: Annotated[Literal[False], PropertyInfo(alias="streamResponse")]

tests/api_resources/test_sessions.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ def test_method_act_with_all_params_overload_1(self, client: Stagehand) -> None:
4545
options={
4646
"model": {"model_name": "openai/gpt-5-nano"},
4747
"timeout": 30000,
48-
"variables": {"username": "john_doe"},
48+
"variables": {
49+
"username": "john_doe",
50+
"password": {
51+
"value": "secret123",
52+
"description": "The login password",
53+
},
54+
},
4955
},
5056
stream_response=False,
5157
x_stream_response="true",
@@ -110,7 +116,13 @@ def test_method_act_with_all_params_overload_2(self, client: Stagehand) -> None:
110116
options={
111117
"model": {"model_name": "openai/gpt-5-nano"},
112118
"timeout": 30000,
113-
"variables": {"username": "john_doe"},
119+
"variables": {
120+
"username": "john_doe",
121+
"password": {
122+
"value": "secret123",
123+
"description": "The login password",
124+
},
125+
},
114126
},
115127
x_stream_response="true",
116128
)
@@ -608,6 +620,13 @@ def test_method_observe_with_all_params_overload_1(self, client: Stagehand) -> N
608620
"model": {"model_name": "openai/gpt-5-nano"},
609621
"selector": "nav",
610622
"timeout": 30000,
623+
"variables": {
624+
"username": {
625+
"value": "john@example.com",
626+
"description": "The login email",
627+
},
628+
"rememberMe": True,
629+
},
611630
},
612631
stream_response=False,
613632
x_stream_response="true",
@@ -669,6 +688,13 @@ def test_method_observe_with_all_params_overload_2(self, client: Stagehand) -> N
669688
"model": {"model_name": "openai/gpt-5-nano"},
670689
"selector": "nav",
671690
"timeout": 30000,
691+
"variables": {
692+
"username": {
693+
"value": "john@example.com",
694+
"description": "The login email",
695+
},
696+
"rememberMe": True,
697+
},
672698
},
673699
x_stream_response="true",
674700
)
@@ -909,7 +935,13 @@ async def test_method_act_with_all_params_overload_1(self, async_client: AsyncSt
909935
options={
910936
"model": {"model_name": "openai/gpt-5-nano"},
911937
"timeout": 30000,
912-
"variables": {"username": "john_doe"},
938+
"variables": {
939+
"username": "john_doe",
940+
"password": {
941+
"value": "secret123",
942+
"description": "The login password",
943+
},
944+
},
913945
},
914946
stream_response=False,
915947
x_stream_response="true",
@@ -974,7 +1006,13 @@ async def test_method_act_with_all_params_overload_2(self, async_client: AsyncSt
9741006
options={
9751007
"model": {"model_name": "openai/gpt-5-nano"},
9761008
"timeout": 30000,
977-
"variables": {"username": "john_doe"},
1009+
"variables": {
1010+
"username": "john_doe",
1011+
"password": {
1012+
"value": "secret123",
1013+
"description": "The login password",
1014+
},
1015+
},
9781016
},
9791017
x_stream_response="true",
9801018
)
@@ -1472,6 +1510,13 @@ async def test_method_observe_with_all_params_overload_1(self, async_client: Asy
14721510
"model": {"model_name": "openai/gpt-5-nano"},
14731511
"selector": "nav",
14741512
"timeout": 30000,
1513+
"variables": {
1514+
"username": {
1515+
"value": "john@example.com",
1516+
"description": "The login email",
1517+
},
1518+
"rememberMe": True,
1519+
},
14751520
},
14761521
stream_response=False,
14771522
x_stream_response="true",
@@ -1533,6 +1578,13 @@ async def test_method_observe_with_all_params_overload_2(self, async_client: Asy
15331578
"model": {"model_name": "openai/gpt-5-nano"},
15341579
"selector": "nav",
15351580
"timeout": 30000,
1581+
"variables": {
1582+
"username": {
1583+
"value": "john@example.com",
1584+
"description": "The login email",
1585+
},
1586+
"rememberMe": True,
1587+
},
15361588
},
15371589
x_stream_response="true",
15381590
)

0 commit comments

Comments
 (0)