Skip to content

Commit 36f0681

Browse files
feat(api): manual updates
1 parent b90a630 commit 36f0681

61 files changed

Lines changed: 305 additions & 3789 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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 7
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-705638ac8966569986bd9ebb7c9761bf0016909e9f2753e77ceabb12c8049511.yml
3-
openapi_spec_hash: a8fbbcaa38e91c7f97313620b42d8d62
1+
configured_endpoints: 1
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-516862e7e90968bc55ac44ce7ffe2d5c1f738c11757471c2b9e0e4cff9384f2c.yml
3+
openapi_spec_hash: 19bbe52a6ae0eec7fc3f6698e831ee55
44
config_hash: a35b56eb05306a0f02e83c11d57f975f

README.md

Lines changed: 9 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ stagehand = Stagehand::Client.new(
3434
model_api_key: ENV["MODEL_API_KEY"] # This is the default and can be omitted
3535
)
3636

37-
response = stagehand.sessions.act("00000000-your-session-id-000000000000", input: "click the first link on the page")
37+
response = stagehand.sessions.start
3838

39-
puts(response.actions)
39+
puts(response)
4040
```
4141

4242
### Handling errors
@@ -45,10 +45,7 @@ When the library is unable to connect to the API, or if the API returns a non-su
4545

4646
```ruby
4747
begin
48-
session = stagehand.sessions.start(
49-
browserbase_api_key: "your Browserbase API key",
50-
browserbase_project_id: "your Browserbase Project ID"
51-
)
48+
session = stagehand.sessions.start
5249
rescue Stagehand::Errors::APIConnectionError => e
5350
puts("The server could not be reached")
5451
puts(e.cause) # an underlying Exception, likely raised within `net/http`
@@ -91,11 +88,7 @@ stagehand = Stagehand::Client.new(
9188
)
9289

9390
# Or, configure per-request:
94-
stagehand.sessions.start(
95-
browserbase_api_key: "your Browserbase API key",
96-
browserbase_project_id: "your Browserbase Project ID",
97-
request_options: {max_retries: 5}
98-
)
91+
stagehand.sessions.start(request_options: {max_retries: 5})
9992
```
10093

10194
### Timeouts
@@ -109,11 +102,7 @@ stagehand = Stagehand::Client.new(
109102
)
110103

111104
# Or, configure per-request:
112-
stagehand.sessions.start(
113-
browserbase_api_key: "your Browserbase API key",
114-
browserbase_project_id: "your Browserbase Project ID",
115-
request_options: {timeout: 5}
116-
)
105+
stagehand.sessions.start(request_options: {timeout: 5})
117106
```
118107

119108
On timeout, `Stagehand::Errors::APITimeoutError` is raised.
@@ -145,8 +134,6 @@ Note: the `extra_` parameters of the same name overrides the documented paramete
145134
```ruby
146135
response =
147136
stagehand.sessions.start(
148-
browserbase_api_key: "your Browserbase API key",
149-
browserbase_project_id: "your Browserbase Project ID",
150137
request_options: {
151138
extra_query: {my_query_parameter: value},
152139
extra_body: {my_body_parameter: value},
@@ -192,46 +179,18 @@ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitio
192179
You can provide typesafe request parameters like so:
193180

194181
```ruby
195-
stagehand.sessions.act("00000000-your-session-id-000000000000", input: "click the first link on the page")
182+
stagehand.sessions.start
196183
```
197184

198185
Or, equivalently:
199186

200187
```ruby
201188
# Hashes work, but are not typesafe:
202-
stagehand.sessions.act("00000000-your-session-id-000000000000", input: "click the first link on the page")
189+
stagehand.sessions.start
203190

204191
# You can also splat a full Params class:
205-
params = Stagehand::SessionActParams.new(input: "click the first link on the page")
206-
stagehand.sessions.act("00000000-your-session-id-000000000000", **params)
207-
```
208-
209-
### Enums
210-
211-
Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
212-
213-
```ruby
214-
# :true
215-
puts(Stagehand::SessionActParams::XStreamResponse::TRUE)
216-
217-
# Revealed type: `T.all(Stagehand::SessionActParams::XStreamResponse, Symbol)`
218-
T.reveal_type(Stagehand::SessionActParams::XStreamResponse::TRUE)
219-
```
220-
221-
Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
222-
223-
```ruby
224-
# Using the enum constants preserves the tagged type information:
225-
stagehand.sessions.act(
226-
x_stream_response: Stagehand::SessionActParams::XStreamResponse::TRUE,
227-
#
228-
)
229-
230-
# Literal values are also permissible:
231-
stagehand.sessions.act(
232-
x_stream_response: :true,
233-
#
234-
)
192+
params = Stagehand::SessionStartParams.new
193+
stagehand.sessions.start(**params)
235194
```
236195

237196
## Versioning

lib/stagehand.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,6 @@
5454
require_relative "stagehand/client"
5555
require_relative "stagehand/models/action"
5656
require_relative "stagehand/models/model_config"
57-
require_relative "stagehand/models/session_act_params"
58-
require_relative "stagehand/models/session_act_response"
59-
require_relative "stagehand/models/session_end_params"
60-
require_relative "stagehand/models/session_end_response"
61-
require_relative "stagehand/models/session_execute_agent_params"
62-
require_relative "stagehand/models/session_execute_agent_response"
63-
require_relative "stagehand/models/session_extract_params"
64-
require_relative "stagehand/models/session_extract_response"
65-
require_relative "stagehand/models/session_navigate_params"
66-
require_relative "stagehand/models/session_navigate_response"
67-
require_relative "stagehand/models/session_observe_params"
68-
require_relative "stagehand/models/session_observe_response"
6957
require_relative "stagehand/models/session_start_params"
7058
require_relative "stagehand/models/session_start_response"
7159
require_relative "stagehand/models"

lib/stagehand/internal/type/base_model.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,9 +440,9 @@ def deep_to_h = self.class.recursively_to_h(@data, convert: false)
440440
# @example
441441
# # `action` is a `Stagehand::Action`
442442
# action => {
443-
# arguments: arguments,
444443
# description: description,
445-
# method_: method_
444+
# selector: selector,
445+
# arguments: arguments
446446
# }
447447
def deconstruct_keys(keys)
448448
(keys || self.class.known_fields.keys)

lib/stagehand/internal/type/union.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ module Type
66
# @api private
77
#
88
# @example
9-
# # `session_extract_response` is a `Stagehand::Models::SessionExtractResponse`
10-
# case session_extract_response
11-
# when Stagehand::Models::SessionExtractResponse::Extraction
12-
# puts(session_extract_response.extraction)
13-
# when Stagehand::Models::SessionExtractResponse::CustomMap
9+
# # `model_config` is a `Stagehand::ModelConfig`
10+
# case model_config
11+
# when String
1412
# # ...
13+
# when Stagehand::ModelConfig::UnionMember1
14+
# puts(model_config.model_name)
1515
# else
16-
# puts(session_extract_response)
16+
# puts(model_config)
1717
# end
1818
module Union
1919
include Stagehand::Internal::Type::Converter

lib/stagehand/models.rb

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,5 @@ module Stagehand
4343

4444
ModelConfig = Stagehand::Models::ModelConfig
4545

46-
SessionActParams = Stagehand::Models::SessionActParams
47-
48-
SessionEndParams = Stagehand::Models::SessionEndParams
49-
50-
SessionExecuteAgentParams = Stagehand::Models::SessionExecuteAgentParams
51-
52-
SessionExtractParams = Stagehand::Models::SessionExtractParams
53-
54-
SessionNavigateParams = Stagehand::Models::SessionNavigateParams
55-
56-
SessionObserveParams = Stagehand::Models::SessionObserveParams
57-
5846
SessionStartParams = Stagehand::Models::SessionStartParams
5947
end

lib/stagehand/models/action.rb

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,40 @@
33
module Stagehand
44
module Models
55
class Action < Stagehand::Internal::Type::BaseModel
6-
# @!attribute arguments
7-
# Arguments for the method
8-
#
9-
# @return [Array<String>]
10-
required :arguments, Stagehand::Internal::Type::ArrayOf[String]
11-
126
# @!attribute description
137
# Human-readable description of the action
148
#
159
# @return [String]
1610
required :description, String
1711

18-
# @!attribute method_
19-
# Method to execute (e.g., "click", "fill")
20-
#
21-
# @return [String]
22-
required :method_, String, api_name: :method
23-
2412
# @!attribute selector
25-
# CSS or XPath selector for the element
13+
# CSS selector or XPath for the element
2614
#
2715
# @return [String]
2816
required :selector, String
2917

30-
# @!attribute backend_node_id
31-
# CDP backend node ID
18+
# @!attribute arguments
19+
# Arguments to pass to the method
20+
#
21+
# @return [Array<String>, nil]
22+
optional :arguments, Stagehand::Internal::Type::ArrayOf[String]
23+
24+
# @!attribute method_
25+
# The method to execute (click, fill, etc.)
3226
#
33-
# @return [Integer, nil]
34-
optional :backend_node_id, Integer, api_name: :backendNodeId
27+
# @return [String, nil]
28+
optional :method_, String, api_name: :method
3529

36-
# @!method initialize(arguments:, description:, method_:, selector:, backend_node_id: nil)
37-
# @param arguments [Array<String>] Arguments for the method
30+
# @!method initialize(description:, selector:, arguments: nil, method_: nil)
31+
# Action object returned by observe and used by act
3832
#
3933
# @param description [String] Human-readable description of the action
4034
#
41-
# @param method_ [String] Method to execute (e.g., "click", "fill")
35+
# @param selector [String] CSS selector or XPath for the element
4236
#
43-
# @param selector [String] CSS or XPath selector for the element
37+
# @param arguments [Array<String>] Arguments to pass to the method
4438
#
45-
# @param backend_node_id [Integer] CDP backend node ID
39+
# @param method_ [String] The method to execute (click, fill, etc.)
4640
end
4741
end
4842
end

lib/stagehand/models/model_config.rb

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,37 @@
22

33
module Stagehand
44
module Models
5-
class ModelConfig < Stagehand::Internal::Type::BaseModel
6-
# @!attribute api_key
7-
# API key for the model provider
8-
#
9-
# @return [String, nil]
10-
optional :api_key, String, api_name: :apiKey
11-
12-
# @!attribute base_url
13-
# Custom base URL for API
14-
#
15-
# @return [String, nil]
16-
optional :base_url, String, api_name: :baseURL
17-
18-
# @!attribute model
19-
# Model name
20-
#
21-
# @return [String, nil]
22-
optional :model, String
23-
24-
# @!attribute provider
25-
#
26-
# @return [Symbol, Stagehand::Models::ModelConfig::Provider, nil]
27-
optional :provider, enum: -> { Stagehand::ModelConfig::Provider }
28-
29-
# @!method initialize(api_key: nil, base_url: nil, model: nil, provider: nil)
30-
# @param api_key [String] API key for the model provider
31-
#
32-
# @param base_url [String] Custom base URL for API
33-
#
34-
# @param model [String] Model name
35-
#
36-
# @param provider [Symbol, Stagehand::Models::ModelConfig::Provider]
37-
38-
# @see Stagehand::Models::ModelConfig#provider
39-
module Provider
40-
extend Stagehand::Internal::Type::Enum
41-
42-
OPENAI = :openai
43-
ANTHROPIC = :anthropic
44-
GOOGLE = :google
45-
46-
# @!method self.values
47-
# @return [Array<Symbol>]
5+
module ModelConfig
6+
extend Stagehand::Internal::Type::Union
7+
8+
variant String
9+
10+
variant -> { Stagehand::ModelConfig::UnionMember1 }
11+
12+
class UnionMember1 < Stagehand::Internal::Type::BaseModel
13+
# @!attribute model_name
14+
#
15+
# @return [String]
16+
required :model_name, String, api_name: :modelName
17+
18+
# @!attribute api_key
19+
#
20+
# @return [String, nil]
21+
optional :api_key, String, api_name: :apiKey
22+
23+
# @!attribute base_url
24+
#
25+
# @return [String, nil]
26+
optional :base_url, String, api_name: :baseURL
27+
28+
# @!method initialize(model_name:, api_key: nil, base_url: nil)
29+
# @param model_name [String]
30+
# @param api_key [String]
31+
# @param base_url [String]
4832
end
33+
34+
# @!method self.variants
35+
# @return [Array(String, Stagehand::Models::ModelConfig::UnionMember1)]
4936
end
5037
end
5138
end

0 commit comments

Comments
 (0)