Skip to content

Commit cb4cf1f

Browse files
authored
Merge pull request #2 from browserbase/release-please--branches--main--changes--next
release: 0.1.0
2 parents e0b192e + d0a40c2 commit cb4cf1f

28 files changed

Lines changed: 547 additions & 341 deletions

.github/workflows/publish-gem.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow is triggered when a GitHub release is created.
2+
# It can also be run manually to re-publish to rubygems.org in case it failed for some reason.
3+
# You can run this workflow by navigating to https://www.github.com/browserbase/stagehand-ruby/actions/workflows/publish-gem.yml
4+
name: Publish Gem
5+
on:
6+
workflow_dispatch:
7+
8+
release:
9+
types: [published]
10+
11+
jobs:
12+
publish:
13+
name: publish
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Set up Ruby
19+
uses: ruby/setup-ruby@v1
20+
with:
21+
bundler-cache: false
22+
- run: |-
23+
bundle install
24+
25+
- name: Publish to RubyGems.org
26+
run: |
27+
bash ./bin/publish-gem
28+
env:
29+
# `RUBYGEMS_HOST` is only required for private gem repositories, not https://rubygems.org
30+
RUBYGEMS_HOST: ${{ secrets.STAGEHAND_RUBYGEMS_HOST || secrets.RUBYGEMS_HOST }}
31+
GEM_HOST_API_KEY: ${{ secrets.STAGEHAND_GEM_HOST_API_KEY || secrets.GEM_HOST_API_KEY }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Release Doctor
2+
on:
3+
pull_request:
4+
branches:
5+
- main
6+
workflow_dispatch:
7+
8+
jobs:
9+
release_doctor:
10+
name: release doctor
11+
runs-on: ubuntu-latest
12+
if: github.repository == 'browserbase/stagehand-ruby' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Check release environment
18+
run: |
19+
bash ./bin/check-release-environment
20+
env:
21+
RUBYGEMS_HOST: ${{ secrets.STAGEHAND_RUBYGEMS_HOST || secrets.RUBYGEMS_HOST }}
22+
GEM_HOST_API_KEY: ${{ secrets.STAGEHAND_GEM_HOST_API_KEY || secrets.GEM_HOST_API_KEY }}

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "0.1.0"
3+
}

.stats.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 7
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-0c12f985340be2a9287e8e01ff8733f7f2d02e019149d1ae95f1a8f8798c6690.yml
3-
openapi_spec_hash: efb79934e1dc63763dd4e8493b825273
4-
config_hash: 5f3345d1d825e49f896f3b0e493e6938
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/browserbase%2Fstagehand-2c88c6d890406ff8a5f1bca692264fb9af4bc4fe64df0986e06d3386fc6d6fcb.yml
3+
openapi_spec_hash: dc6ea17f8152708dc0a390c7f86b1a5d
4+
config_hash: b01f15c540ab2c92808c2bba96368631

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
## 0.1.0 (2025-12-16)
4+
5+
Full Changelog: [v0.0.1...v0.1.0](https://github.com/browserbase/stagehand-ruby/compare/v0.0.1...v0.1.0)
6+
7+
### Features
8+
9+
* **api:** manual updates ([5deaf8f](https://github.com/browserbase/stagehand-ruby/commit/5deaf8ff2011a2808dcfe66ef14470029bb3590e))
10+
* **api:** manual updates ([87ce5f3](https://github.com/browserbase/stagehand-ruby/commit/87ce5f320056fb34770be2f0c87985960e995e92))
11+
* **api:** manual updates ([2a8b9e7](https://github.com/browserbase/stagehand-ruby/commit/2a8b9e7d219360a5e783c650fc7c9544a9a6fbb5))
12+
* **api:** manual updates ([0bcedba](https://github.com/browserbase/stagehand-ruby/commit/0bcedbaf26918822abdc958e6020f68b263ffee0))
13+
* **api:** manual updates ([8355d5e](https://github.com/browserbase/stagehand-ruby/commit/8355d5e6b83f6c31f6494f771fba51b6e31023e7))
14+
* **api:** manual updates ([655f517](https://github.com/browserbase/stagehand-ruby/commit/655f51718008b4c512eed1ce65660dae80039e49))
15+
* **api:** tweak branding and fix some config fields ([c48f36e](https://github.com/browserbase/stagehand-ruby/commit/c48f36e307aafd9a2d6ac59d9857be789f29eaa1))
16+
17+
18+
### Chores
19+
20+
* configure new SDK language ([3be44a3](https://github.com/browserbase/stagehand-ruby/commit/3be44a344d5bc49e7c2e16129c2b24db175f4eb6))

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ If you’d like to use the repository from source, you can either install from g
4343
To install via git in your `Gemfile`:
4444

4545
```ruby
46-
gem "stagehand", git: "https://www.github.com/stainless-sdks/stagehand-ruby"
46+
gem "stagehand", git: "https://www.github.com/browserbase/stagehand-ruby"
4747
```
4848

4949
Alternatively, reference local copy of the repo:
5050

5151
```bash
52-
$ git clone -- 'https://www.github.com/stainless-sdks/stagehand-ruby' '<path-to-repo>'
52+
$ git clone -- 'https://www.github.com/browserbase/stagehand-ruby' '<path-to-repo>'
5353
```
5454

5555
```ruby

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ GIT
1111
PATH
1212
remote: .
1313
specs:
14-
stagehand (0.0.1)
14+
stagehand (0.1.0)
1515
connection_pool
1616

1717
GEM

README.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
# Stagehand Ruby API library
22

3-
The Stagehand Ruby library provides convenient access to the Stagehand REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/stainless-sdks/stagehand-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
3+
The Stagehand Ruby library provides convenient access to the Stagehand REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/browserbase/stagehand-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
44

55
It is generated with [Stainless](https://www.stainless.com/).
66

77
## Documentation
88

99
Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs.org/gems/stagehand).
1010

11-
The REST API documentation can be found on [browserbase.com](https://browserbase.com).
11+
The REST API documentation can be found on [docs.stagehand.dev](https://docs.stagehand.dev).
1212

1313
## Installation
1414

1515
To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
1616

17+
<!-- x-release-please-start-version -->
18+
1719
```ruby
18-
gem "stagehand", "~> 0.0.1"
20+
gem "stagehand", "~> 0.1.0"
1921
```
2022

23+
<!-- x-release-please-end -->
24+
2125
## Usage
2226

2327
```ruby
2428
require "bundler/setup"
2529
require "stagehand"
2630

2731
stagehand = Stagehand::Client.new(
28-
api_key: ENV["STAGEHAND_API_KEY"], # This is the default and can be omitted
29-
environment: "environment_1" # defaults to "production"
32+
browserbase_api_key: ENV["BROWSERBASE_API_KEY"], # This is the default and can be omitted
33+
browserbase_project_id: ENV["BROWSERBASE_PROJECT_ID"], # This is the default and can be omitted
34+
model_api_key: ENV["MODEL_API_KEY"] # This is the default and can be omitted
3035
)
3136

32-
response = stagehand.sessions.start(env: "LOCAL")
37+
response = stagehand.sessions.act("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", input: "click the first link on the page")
3338

34-
puts(response.available)
39+
puts(response.actions)
3540
```
3641

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

4146
```ruby
4247
begin
43-
session = stagehand.sessions.start(env: "LOCAL")
48+
session = stagehand.sessions.start(
49+
browserbase_api_key: "BROWSERBASE_API_KEY",
50+
browserbase_project_id: "BROWSERBASE_PROJECT_ID"
51+
)
4452
rescue Stagehand::Errors::APIConnectionError => e
4553
puts("The server could not be reached")
4654
puts(e.cause) # an underlying Exception, likely raised within `net/http`
@@ -83,7 +91,11 @@ stagehand = Stagehand::Client.new(
8391
)
8492

8593
# Or, configure per-request:
86-
stagehand.sessions.start(env: "LOCAL", request_options: {max_retries: 5})
94+
stagehand.sessions.start(
95+
browserbase_api_key: "BROWSERBASE_API_KEY",
96+
browserbase_project_id: "BROWSERBASE_PROJECT_ID",
97+
request_options: {max_retries: 5}
98+
)
8799
```
88100

89101
### Timeouts
@@ -97,7 +109,11 @@ stagehand = Stagehand::Client.new(
97109
)
98110

99111
# Or, configure per-request:
100-
stagehand.sessions.start(env: "LOCAL", request_options: {timeout: 5})
112+
stagehand.sessions.start(
113+
browserbase_api_key: "BROWSERBASE_API_KEY",
114+
browserbase_project_id: "BROWSERBASE_PROJECT_ID",
115+
request_options: {timeout: 5}
116+
)
101117
```
102118

103119
On timeout, `Stagehand::Errors::APITimeoutError` is raised.
@@ -129,7 +145,8 @@ Note: the `extra_` parameters of the same name overrides the documented paramete
129145
```ruby
130146
response =
131147
stagehand.sessions.start(
132-
env: "LOCAL",
148+
browserbase_api_key: "BROWSERBASE_API_KEY",
149+
browserbase_project_id: "BROWSERBASE_PROJECT_ID",
133150
request_options: {
134151
extra_query: {my_query_parameter: value},
135152
extra_body: {my_body_parameter: value},
@@ -175,18 +192,18 @@ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitio
175192
You can provide typesafe request parameters like so:
176193

177194
```ruby
178-
stagehand.sessions.start(env: "LOCAL")
195+
stagehand.sessions.act("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", input: "click the first link on the page")
179196
```
180197

181198
Or, equivalently:
182199

183200
```ruby
184201
# Hashes work, but are not typesafe:
185-
stagehand.sessions.start(env: "LOCAL")
202+
stagehand.sessions.act("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", input: "click the first link on the page")
186203

187204
# You can also splat a full Params class:
188-
params = Stagehand::SessionStartParams.new(env: "LOCAL")
189-
stagehand.sessions.start(**params)
205+
params = Stagehand::SessionActParams.new(input: "click the first link on the page")
206+
stagehand.sessions.act("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", **params)
190207
```
191208

192209
### Enums
@@ -229,4 +246,4 @@ Ruby 3.2.0 or higher.
229246

230247
## Contributing
231248

232-
See [the contributing documentation](https://github.com/stainless-sdks/stagehand-ruby/tree/main/CONTRIBUTING.md).
249+
See [the contributing documentation](https://github.com/browserbase/stagehand-ruby/tree/main/CONTRIBUTING.md).

bin/check-release-environment

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
errors=()
4+
5+
if [ -z "${GEM_HOST_API_KEY}" ]; then
6+
errors+=("The GEM_HOST_API_KEY secret has not been set. Please set it in either this repository's secrets or your organization secrets")
7+
fi
8+
9+
lenErrors=${#errors[@]}
10+
11+
if [[ lenErrors -gt 0 ]]; then
12+
echo -e "Found the following errors in the release environment:\n"
13+
14+
for error in "${errors[@]}"; do
15+
echo -e "- $error\n"
16+
done
17+
18+
exit 1
19+
fi
20+
21+
echo "The environment is ready to push releases!"

lib/stagehand/client.rb

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ class Client < Stagehand::Internal::Transport::BaseClient
1515
# Default max retry delay in seconds.
1616
DEFAULT_MAX_RETRY_DELAY = 8.0
1717

18-
# rubocop:disable Style/MutableConstant
19-
# @type [Hash{Symbol=>String}]
20-
ENVIRONMENTS =
21-
{production: "http://localhost:3000/v1", environment_1: "https://api.stagehand.browserbase.com/v1"}
22-
# rubocop:enable Style/MutableConstant
18+
# Your [Browserbase API Key](https://www.browserbase.com/settings)
19+
# @return [String]
20+
attr_reader :browserbase_api_key
2321

24-
# @return [String, nil]
25-
attr_reader :api_key
22+
# Your [Browserbase Project ID](https://www.browserbase.com/settings)
23+
# @return [String]
24+
attr_reader :browserbase_project_id
25+
26+
# Your LLM provider API key (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.)
27+
# @return [String]
28+
attr_reader :model_api_key
2629

2730
# @return [Stagehand::Resources::Sessions]
2831
attr_reader :sessions
@@ -31,21 +34,40 @@ class Client < Stagehand::Internal::Transport::BaseClient
3134
#
3235
# @return [Hash{String=>String}]
3336
private def auth_headers
34-
return {} if @api_key.nil?
37+
{**bb_api_key_auth, **bb_project_id_auth, **llm_model_api_key_auth}
38+
end
3539

36-
{"authorization" => "Bearer #{@api_key}"}
40+
# @api private
41+
#
42+
# @return [Hash{String=>String}]
43+
private def bb_api_key_auth
44+
{"x-bb-api-key" => @browserbase_api_key}
3745
end
3846

39-
# Creates and returns a new client for interacting with the API.
47+
# @api private
4048
#
41-
# @param api_key [String, nil] Defaults to `ENV["STAGEHAND_API_KEY"]`
49+
# @return [Hash{String=>String}]
50+
private def bb_project_id_auth
51+
{"x-bb-project-id" => @browserbase_project_id}
52+
end
53+
54+
# @api private
4255
#
43-
# @param environment [:production, :environment_1, nil] Specifies the environment to use for the API.
56+
# @return [Hash{String=>String}]
57+
private def llm_model_api_key_auth
58+
{"x-model-api-key" => @model_api_key}
59+
end
60+
61+
# Creates and returns a new client for interacting with the API.
4462
#
45-
# Each environment maps to a different base URL:
63+
# @param browserbase_api_key [String, nil] Your [Browserbase API Key](https://www.browserbase.com/settings) Defaults to
64+
# `ENV["BROWSERBASE_API_KEY"]`
4665
#
47-
# - `production` corresponds to `http://localhost:3000/v1`
48-
# - `environment_1` corresponds to `https://api.stagehand.browserbase.com/v1`
66+
# @param browserbase_project_id [String, nil] Your [Browserbase Project ID](https://www.browserbase.com/settings) Defaults to
67+
# `ENV["BROWSERBASE_PROJECT_ID"]`
68+
#
69+
# @param model_api_key [String, nil] Your LLM provider API key (e.g. OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.)
70+
# Defaults to `ENV["MODEL_API_KEY"]`
4971
#
5072
# @param base_url [String, nil] Override the default base URL for the API, e.g.,
5173
# `"https://api.example.com/v2/"`. Defaults to `ENV["STAGEHAND_BASE_URL"]`
@@ -58,20 +80,30 @@ class Client < Stagehand::Internal::Transport::BaseClient
5880
#
5981
# @param max_retry_delay [Float]
6082
def initialize(
61-
api_key: ENV["STAGEHAND_API_KEY"],
62-
environment: nil,
83+
browserbase_api_key: ENV["BROWSERBASE_API_KEY"],
84+
browserbase_project_id: ENV["BROWSERBASE_PROJECT_ID"],
85+
model_api_key: ENV["MODEL_API_KEY"],
6386
base_url: ENV["STAGEHAND_BASE_URL"],
6487
max_retries: self.class::DEFAULT_MAX_RETRIES,
6588
timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
6689
initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
6790
max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
6891
)
69-
base_url ||= Stagehand::Client::ENVIRONMENTS.fetch(environment&.to_sym || :production) do
70-
message = "environment must be one of #{Stagehand::Client::ENVIRONMENTS.keys}, got #{environment}"
71-
raise ArgumentError.new(message)
92+
base_url ||= "https://api.stagehand.browserbase.com/v1"
93+
94+
if browserbase_api_key.nil?
95+
raise ArgumentError.new("browserbase_api_key is required, and can be set via environ: \"BROWSERBASE_API_KEY\"")
96+
end
97+
if browserbase_project_id.nil?
98+
raise ArgumentError.new("browserbase_project_id is required, and can be set via environ: \"BROWSERBASE_PROJECT_ID\"")
99+
end
100+
if model_api_key.nil?
101+
raise ArgumentError.new("model_api_key is required, and can be set via environ: \"MODEL_API_KEY\"")
72102
end
73103

74-
@api_key = api_key&.to_s
104+
@browserbase_api_key = browserbase_api_key.to_s
105+
@browserbase_project_id = browserbase_project_id.to_s
106+
@model_api_key = model_api_key.to_s
75107

76108
super(
77109
base_url: base_url,

0 commit comments

Comments
 (0)