stagehand 3.7.1 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -0
  3. data/lib/stagehand/internal/stream.rb +2 -11
  4. data/lib/stagehand/internal/util.rb +31 -0
  5. data/lib/stagehand/local.rb +5 -5
  6. data/lib/stagehand/models/model_config.rb +9 -1
  7. data/lib/stagehand/models/session_act_params.rb +63 -5
  8. data/lib/stagehand/models/session_end_params.rb +9 -1
  9. data/lib/stagehand/models/session_execute_params.rb +26 -2
  10. data/lib/stagehand/models/session_extract_params.rb +9 -1
  11. data/lib/stagehand/models/session_navigate_params.rb +9 -1
  12. data/lib/stagehand/models/session_observe_params.rb +69 -2
  13. data/lib/stagehand/models/session_replay_params.rb +9 -1
  14. data/lib/stagehand/models/session_start_params.rb +7 -1
  15. data/lib/stagehand/models/stream_event.rb +2 -1
  16. data/lib/stagehand/version.rb +1 -1
  17. data/rbi/stagehand/internal/util.rbi +20 -0
  18. data/rbi/stagehand/models/model_config.rbi +11 -0
  19. data/rbi/stagehand/models/session_act_params.rbi +144 -6
  20. data/rbi/stagehand/models/session_end_params.rbi +8 -0
  21. data/rbi/stagehand/models/session_execute_params.rbi +33 -3
  22. data/rbi/stagehand/models/session_extract_params.rbi +8 -0
  23. data/rbi/stagehand/models/session_navigate_params.rbi +8 -0
  24. data/rbi/stagehand/models/session_observe_params.rbi +156 -3
  25. data/rbi/stagehand/models/session_replay_params.rbi +8 -0
  26. data/rbi/stagehand/models/session_start_params.rbi +9 -0
  27. data/rbi/stagehand/models/stream_event.rbi +2 -1
  28. data/sig/stagehand/internal/util.rbs +10 -0
  29. data/sig/stagehand/models/model_config.rbs +7 -0
  30. data/sig/stagehand/models/session_act_params.rbs +56 -5
  31. data/sig/stagehand/models/session_end_params.rbs +5 -0
  32. data/sig/stagehand/models/session_execute_params.rbs +26 -3
  33. data/sig/stagehand/models/session_extract_params.rbs +5 -0
  34. data/sig/stagehand/models/session_navigate_params.rbs +5 -0
  35. data/sig/stagehand/models/session_observe_params.rbs +61 -3
  36. data/sig/stagehand/models/session_replay_params.rbs +5 -0
  37. data/sig/stagehand/models/session_start_params.rbs +7 -0
  38. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 87ccf4bfcfc723469ff68db45b650d9f2702c6692905a8f6a42e7456d6d37b63
4
- data.tar.gz: dbcfc350b71c0a0d89cad72696fcde9fc3f506d425fedd56e2e611b176070a73
3
+ metadata.gz: 74284602dc9bdaf010605da5b97177bfa1335a28e7e2048f924a0025298f5a8d
4
+ data.tar.gz: 45de340a9ce93503b5cd851e87ebc862311fd7c59e5940c5b2b507b8d67ab56a
5
5
  SHA512:
6
- metadata.gz: 1bafc8973dd2a0844797e67c0ecb04fdf0a3b8245ff0639af4f9334da95cdfbc6701f00ab8519ae07a998478383b14c633c8e3bd823c991caa4623ac5b9ace0d
7
- data.tar.gz: 2e35f3d9adace66379d78c8631d271932d040ccc2aa190a793f074e37e1ea737c766424f21ebd2e6bfbd49687d9073e223615db052b624ff7488c641e3dedf81
6
+ metadata.gz: f50f38f6542f249eb99c63399f8d963f37b447e78d40d641c9f535076f671a04c70a9850d31c9f7533dd105d0fa20bf6305b5fdb3928fc38f839f9524285cd00
7
+ data.tar.gz: cc10728334054f28603904751f0a4b69a773ea6b4445dfd3b336e9a4eae0a029a8b819208b925cb317a1499bbf298f97233355e0c07d59b9a82f6ea3d2facc72
data/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.18.0 (2026-03-25)
4
+
5
+ Full Changelog: [v3.7.1...v3.18.0](https://github.com/browserbase/stagehand-ruby/compare/v3.7.1...v3.18.0)
6
+
7
+ ### Features
8
+
9
+ * [fix]: add `useSearch` & `toolTimeout` to stainless types ([e5bedb8](https://github.com/browserbase/stagehand-ruby/commit/e5bedb88ac67d34a6db440e470e3eb964205e558))
10
+ * [STG-1607] Yield finished SSE event instead of silently dropping it ([d5ffd2d](https://github.com/browserbase/stagehand-ruby/commit/d5ffd2d0ed6495673ef80ba0e1649bd1c1afa815))
11
+ * Add explicit SSE event names for local v3 streaming ([5be6d12](https://github.com/browserbase/stagehand-ruby/commit/5be6d1293763ecb7f0268884784475986de2915c))
12
+ * Add missing cdpHeaders field to v3 server openapi spec ([de6457f](https://github.com/browserbase/stagehand-ruby/commit/de6457f121764ffbadac51ec2a6103c27dbde338))
13
+ * Include LLM headers in ModelConfig ([23cb4ea](https://github.com/browserbase/stagehand-ruby/commit/23cb4ea1319287992f1174c2b8fa2eff5fdfc5c4))
14
+ * Revert broken finished SSE yield config ([1de4c00](https://github.com/browserbase/stagehand-ruby/commit/1de4c00c0b72936813fcd3e0499b51b1f135f33d))
15
+ * variables for observe ([a9d6970](https://github.com/browserbase/stagehand-ruby/commit/a9d6970e7f43f1d69eddb42a14f09fb7f9158b29))
16
+
17
+
18
+ ### Chores
19
+
20
+ * **ci:** add build step ([ed6573f](https://github.com/browserbase/stagehand-ruby/commit/ed6573f2ddab4f5f51d1262480cb663da5e003d0))
21
+ * **ci:** skip lint on metadata-only changes ([079a802](https://github.com/browserbase/stagehand-ruby/commit/079a8028edf4e9dd09517363b0c1a3b16ed86865))
22
+ * **ci:** skip uploading artifacts on stainless-internal branches ([3a7e90b](https://github.com/browserbase/stagehand-ruby/commit/3a7e90bc8dd9f983dbbc7be16f997dd2dc02c3c0))
23
+ * **internal:** codegen related update ([f714af2](https://github.com/browserbase/stagehand-ruby/commit/f714af2d7d5b9b822362aa10f6f6facab3332eaf))
24
+ * **internal:** codegen related update ([ed9fab1](https://github.com/browserbase/stagehand-ruby/commit/ed9fab1f726c05ef48d4a55507b09212d7ced713))
25
+ * **internal:** tweak CI branches ([85b5b46](https://github.com/browserbase/stagehand-ruby/commit/85b5b4656c921f0784d05b27a3c4773b05b51cc6))
26
+ * **internal:** update gitignore ([b4bc8a8](https://github.com/browserbase/stagehand-ruby/commit/b4bc8a8ae60ff252080d4bfcd0fc6af26dc95e74))
27
+
3
28
  ## 3.7.1 (2026-02-27)
4
29
 
5
30
  Full Changelog: [v3.7.0...v3.7.1](https://github.com/browserbase/stagehand-ruby/compare/v3.7.0...v3.7.1)
@@ -15,18 +15,10 @@ module Stagehand
15
15
  #
16
16
  # @return [Enumerable<generic<Elem>>]
17
17
  private def iterator
18
- # rubocop:disable Metrics/BlockLength
19
18
  @iterator ||= Stagehand::Internal::Util.chain_fused(@stream) do |y|
20
- consume = false
21
-
22
19
  @stream.each do |msg|
23
- next if consume
24
-
25
20
  case msg
26
- in {data: String => data} if data.start_with?("{\"data\":{\"status\":\"finished\"")
27
- consume = true
28
- next
29
- in {data: String => data} if data.start_with?("error")
21
+ in {event: "error", data: String => data}
30
22
  decoded = Kernel.then do
31
23
  JSON.parse(data, symbolize_names: true)
32
24
  rescue JSON::ParserError
@@ -41,7 +33,7 @@ module Stagehand
41
33
  response: @response
42
34
  )
43
35
  raise err
44
- in {event: nil, data: String => data}
36
+ in {event: "starting" | "connected" | "running" | "finished", data: String => data}
45
37
  decoded = JSON.parse(data, symbolize_names: true)
46
38
  unwrapped = Stagehand::Internal::Util.dig(decoded, @unwrap)
47
39
  y << Stagehand::Internal::Type::Converter.coerce(@model, unwrapped)
@@ -49,7 +41,6 @@ module Stagehand
49
41
  end
50
42
  end
51
43
  end
52
- # rubocop:enable Metrics/BlockLength
53
44
  end
54
45
  end
55
46
  end
@@ -490,6 +490,37 @@ module Stagehand
490
490
  JSONL_CONTENT = %r{^application/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)}
491
491
 
492
492
  class << self
493
+ # @api private
494
+ #
495
+ # @param query [Hash{Symbol=>Object}]
496
+ #
497
+ # @return [Hash{Symbol=>Object}]
498
+ def encode_query_params(query)
499
+ out = {}
500
+ query.each { write_query_param_element!(out, _1, _2) }
501
+ out
502
+ end
503
+
504
+ # @api private
505
+ #
506
+ # @param collection [Hash{Symbol=>Object}]
507
+ # @param key [String]
508
+ # @param element [Object]
509
+ #
510
+ # @return [nil]
511
+ private def write_query_param_element!(collection, key, element)
512
+ case element
513
+ in Hash
514
+ element.each do |name, value|
515
+ write_query_param_element!(collection, "#{key}[#{name}]", value)
516
+ end
517
+ in Array
518
+ collection[key] = element.map(&:to_s).join(",")
519
+ else
520
+ collection[key] = element.to_s
521
+ end
522
+ end
523
+
493
524
  # @api private
494
525
  #
495
526
  # @param y [Enumerator::Yielder]
@@ -85,7 +85,7 @@ module Stagehand
85
85
 
86
86
  def binary_filename
87
87
  platform, arch = platform_tag
88
- name = "stagehand-server-#{platform}-#{arch}"
88
+ name = "stagehand-server-v3-#{platform}-#{arch}"
89
89
  name += ".exe" if platform == "win32"
90
90
  name
91
91
  end
@@ -131,9 +131,9 @@ module Stagehand
131
131
 
132
132
  def resolve_version(version)
133
133
  return fetch_latest_tag if version.empty? || version == "latest"
134
- return version if version.start_with?("stagehand-server/")
134
+ return version if version.start_with?("stagehand-server-v3/")
135
135
 
136
- "stagehand-server/#{version}"
136
+ "stagehand-server-v3/#{version}"
137
137
  end
138
138
 
139
139
  def fetch_latest_tag
@@ -148,9 +148,9 @@ module Stagehand
148
148
  releases = JSON.parse(response.body.to_s)
149
149
  releases.each do |release|
150
150
  tag = release["tag_name"]
151
- return tag if tag.is_a?(String) && tag.start_with?("stagehand-server/")
151
+ return tag if tag.is_a?(String) && tag.start_with?("stagehand-server-v3/")
152
152
  end
153
- raise "Failed to find stagehand-server release tag"
153
+ raise "Failed to find stagehand-server-v3 release tag"
154
154
  end
155
155
 
156
156
  def download_binary(tag, dest_path)
@@ -21,19 +21,27 @@ module Stagehand
21
21
  # @return [String, nil]
22
22
  optional :base_url, String, api_name: :baseURL
23
23
 
24
+ # @!attribute headers
25
+ # Custom headers sent with every request to the model provider
26
+ #
27
+ # @return [Hash{Symbol=>String}, nil]
28
+ optional :headers, Stagehand::Internal::Type::HashOf[String]
29
+
24
30
  # @!attribute provider
25
31
  # AI provider for the model (or provide a baseURL endpoint instead)
26
32
  #
27
33
  # @return [Symbol, Stagehand::Models::ModelConfig::Provider, nil]
28
34
  optional :provider, enum: -> { Stagehand::ModelConfig::Provider }
29
35
 
30
- # @!method initialize(model_name:, api_key: nil, base_url: nil, provider: nil)
36
+ # @!method initialize(model_name:, api_key: nil, base_url: nil, headers: nil, provider: nil)
31
37
  # @param model_name [String] Model name string with provider prefix (e.g., 'openai/gpt-5-nano')
32
38
  #
33
39
  # @param api_key [String] API key for the model provider
34
40
  #
35
41
  # @param base_url [String] Base URL for the model provider
36
42
  #
43
+ # @param headers [Hash{Symbol=>String}] Custom headers sent with every request to the model provider
44
+ #
37
45
  # @param provider [Symbol, Stagehand::Models::ModelConfig::Provider] AI provider for the model (or provide a baseURL endpoint instead)
38
46
 
39
47
  # AI provider for the model (or provide a baseURL endpoint instead)
@@ -9,6 +9,12 @@ module Stagehand
9
9
  extend Stagehand::Internal::Type::RequestParameters::Converter
10
10
  include Stagehand::Internal::Type::RequestParameters
11
11
 
12
+ # @!attribute id
13
+ # Unique session identifier
14
+ #
15
+ # @return [String]
16
+ required :id, String
17
+
12
18
  # @!attribute input
13
19
  # Natural language instruction or Action object
14
20
  #
@@ -32,7 +38,9 @@ module Stagehand
32
38
  # @return [Symbol, Stagehand::Models::SessionActParams::XStreamResponse, nil]
33
39
  optional :x_stream_response, enum: -> { Stagehand::SessionActParams::XStreamResponse }
34
40
 
35
- # @!method initialize(input:, frame_id: nil, options: nil, x_stream_response: nil, request_options: {})
41
+ # @!method initialize(id:, input:, frame_id: nil, options: nil, x_stream_response: nil, request_options: {})
42
+ # @param id [String] Unique session identifier
43
+ #
36
44
  # @param input [String, Stagehand::Models::Action] Natural language instruction or Action object
37
45
  #
38
46
  # @param frame_id [String, nil] Target frame ID for the action
@@ -70,17 +78,22 @@ module Stagehand
70
78
  optional :timeout, Float
71
79
 
72
80
  # @!attribute variables
73
- # Variables to substitute in the action instruction
81
+ # Variables to substitute in the action instruction. Accepts flat primitives or {
82
+ # value, description? } objects.
74
83
  #
75
- # @return [Hash{Symbol=>String}, nil]
76
- optional :variables, Stagehand::Internal::Type::HashOf[String]
84
+ # @return [Hash{Symbol=>String, Float, Boolean, Stagehand::Models::SessionActParams::Options::Variable::UnionMember3}, nil]
85
+ optional :variables,
86
+ -> { Stagehand::Internal::Type::HashOf[union: Stagehand::SessionActParams::Options::Variable] }
77
87
 
78
88
  # @!method initialize(model: nil, timeout: nil, variables: nil)
89
+ # Some parameter documentations has been truncated, see
90
+ # {Stagehand::Models::SessionActParams::Options} for more details.
91
+ #
79
92
  # @param model [Stagehand::Models::ModelConfig, String] Model configuration object or model name string (e.g., 'openai/gpt-5-nano')
80
93
  #
81
94
  # @param timeout [Float] Timeout in ms for the action
82
95
  #
83
- # @param variables [Hash{Symbol=>String}] Variables to substitute in the action instruction
96
+ # @param variables [Hash{Symbol=>String, Float, Boolean, Stagehand::Models::SessionActParams::Options::Variable::UnionMember3}] Variables to substitute in the action instruction. Accepts flat primitives or {
84
97
 
85
98
  # Model configuration object or model name string (e.g., 'openai/gpt-5-nano')
86
99
  #
@@ -95,6 +108,51 @@ module Stagehand
95
108
  # @!method self.variants
96
109
  # @return [Array(Stagehand::Models::ModelConfig, String)]
97
110
  end
111
+
112
+ module Variable
113
+ extend Stagehand::Internal::Type::Union
114
+
115
+ variant String
116
+
117
+ variant Float
118
+
119
+ variant Stagehand::Internal::Type::Boolean
120
+
121
+ variant -> { Stagehand::SessionActParams::Options::Variable::UnionMember3 }
122
+
123
+ class UnionMember3 < Stagehand::Internal::Type::BaseModel
124
+ # @!attribute value
125
+ #
126
+ # @return [String, Float, Boolean]
127
+ required :value, union: -> { Stagehand::SessionActParams::Options::Variable::UnionMember3::Value }
128
+
129
+ # @!attribute description
130
+ #
131
+ # @return [String, nil]
132
+ optional :description, String
133
+
134
+ # @!method initialize(value:, description: nil)
135
+ # @param value [String, Float, Boolean]
136
+ # @param description [String]
137
+
138
+ # @see Stagehand::Models::SessionActParams::Options::Variable::UnionMember3#value
139
+ module Value
140
+ extend Stagehand::Internal::Type::Union
141
+
142
+ variant String
143
+
144
+ variant Float
145
+
146
+ variant Stagehand::Internal::Type::Boolean
147
+
148
+ # @!method self.variants
149
+ # @return [Array(String, Float, Boolean)]
150
+ end
151
+ end
152
+
153
+ # @!method self.variants
154
+ # @return [Array(String, Float, Boolean, Stagehand::Models::SessionActParams::Options::Variable::UnionMember3)]
155
+ end
98
156
  end
99
157
 
100
158
  # Whether to stream the response via SSE
@@ -7,13 +7,21 @@ module Stagehand
7
7
  extend Stagehand::Internal::Type::RequestParameters::Converter
8
8
  include Stagehand::Internal::Type::RequestParameters
9
9
 
10
+ # @!attribute id
11
+ # Unique session identifier
12
+ #
13
+ # @return [String]
14
+ required :id, String
15
+
10
16
  # @!attribute x_stream_response
11
17
  # Whether to stream the response via SSE
12
18
  #
13
19
  # @return [Symbol, Stagehand::Models::SessionEndParams::XStreamResponse, nil]
14
20
  optional :x_stream_response, enum: -> { Stagehand::SessionEndParams::XStreamResponse }
15
21
 
16
- # @!method initialize(x_stream_response: nil, request_options: {})
22
+ # @!method initialize(id:, x_stream_response: nil, request_options: {})
23
+ # @param id [String] Unique session identifier
24
+ #
17
25
  # @param x_stream_response [Symbol, Stagehand::Models::SessionEndParams::XStreamResponse] Whether to stream the response via SSE
18
26
  #
19
27
  # @param request_options [Stagehand::RequestOptions, Hash{Symbol=>Object}]
@@ -9,6 +9,12 @@ module Stagehand
9
9
  extend Stagehand::Internal::Type::RequestParameters::Converter
10
10
  include Stagehand::Internal::Type::RequestParameters
11
11
 
12
+ # @!attribute id
13
+ # Unique session identifier
14
+ #
15
+ # @return [String]
16
+ required :id, String
17
+
12
18
  # @!attribute agent_config
13
19
  #
14
20
  # @return [Stagehand::Models::SessionExecuteParams::AgentConfig]
@@ -39,7 +45,9 @@ module Stagehand
39
45
  # @return [Symbol, Stagehand::Models::SessionExecuteParams::XStreamResponse, nil]
40
46
  optional :x_stream_response, enum: -> { Stagehand::SessionExecuteParams::XStreamResponse }
41
47
 
42
- # @!method initialize(agent_config:, execute_options:, frame_id: nil, should_cache: nil, x_stream_response: nil, request_options: {})
48
+ # @!method initialize(id:, agent_config:, execute_options:, frame_id: nil, should_cache: nil, x_stream_response: nil, request_options: {})
49
+ # @param id [String] Unique session identifier
50
+ #
43
51
  # @param agent_config [Stagehand::Models::SessionExecuteParams::AgentConfig]
44
52
  #
45
53
  # @param execute_options [Stagehand::Models::SessionExecuteParams::ExecuteOptions]
@@ -190,12 +198,28 @@ module Stagehand
190
198
  # @return [Float, nil]
191
199
  optional :max_steps, Float, api_name: :maxSteps
192
200
 
193
- # @!method initialize(instruction:, highlight_cursor: nil, max_steps: nil)
201
+ # @!attribute tool_timeout
202
+ # Timeout in milliseconds for each agent tool call
203
+ #
204
+ # @return [Float, nil]
205
+ optional :tool_timeout, Float, api_name: :toolTimeout
206
+
207
+ # @!attribute use_search
208
+ # Whether to enable the web search tool powered by Browserbase Search API
209
+ #
210
+ # @return [Boolean, nil]
211
+ optional :use_search, Stagehand::Internal::Type::Boolean, api_name: :useSearch
212
+
213
+ # @!method initialize(instruction:, highlight_cursor: nil, max_steps: nil, tool_timeout: nil, use_search: nil)
194
214
  # @param instruction [String] Natural language instruction for the agent
195
215
  #
196
216
  # @param highlight_cursor [Boolean] Whether to visually highlight the cursor during execution
197
217
  #
198
218
  # @param max_steps [Float] Maximum number of steps the agent can take
219
+ #
220
+ # @param tool_timeout [Float] Timeout in milliseconds for each agent tool call
221
+ #
222
+ # @param use_search [Boolean] Whether to enable the web search tool powered by Browserbase Search API
199
223
  end
200
224
 
201
225
  # Whether to stream the response via SSE
@@ -9,6 +9,12 @@ module Stagehand
9
9
  extend Stagehand::Internal::Type::RequestParameters::Converter
10
10
  include Stagehand::Internal::Type::RequestParameters
11
11
 
12
+ # @!attribute id
13
+ # Unique session identifier
14
+ #
15
+ # @return [String]
16
+ required :id, String
17
+
12
18
  # @!attribute frame_id
13
19
  # Target frame ID for the extraction
14
20
  #
@@ -38,7 +44,9 @@ module Stagehand
38
44
  # @return [Symbol, Stagehand::Models::SessionExtractParams::XStreamResponse, nil]
39
45
  optional :x_stream_response, enum: -> { Stagehand::SessionExtractParams::XStreamResponse }
40
46
 
41
- # @!method initialize(frame_id: nil, instruction: nil, options: nil, schema: nil, x_stream_response: nil, request_options: {})
47
+ # @!method initialize(id:, frame_id: nil, instruction: nil, options: nil, schema: nil, x_stream_response: nil, request_options: {})
48
+ # @param id [String] Unique session identifier
49
+ #
42
50
  # @param frame_id [String, nil] Target frame ID for the extraction
43
51
  #
44
52
  # @param instruction [String] Natural language instruction for what to extract
@@ -7,6 +7,12 @@ module Stagehand
7
7
  extend Stagehand::Internal::Type::RequestParameters::Converter
8
8
  include Stagehand::Internal::Type::RequestParameters
9
9
 
10
+ # @!attribute id
11
+ # Unique session identifier
12
+ #
13
+ # @return [String]
14
+ required :id, String
15
+
10
16
  # @!attribute url
11
17
  # URL to navigate to
12
18
  #
@@ -36,7 +42,9 @@ module Stagehand
36
42
  # @return [Symbol, Stagehand::Models::SessionNavigateParams::XStreamResponse, nil]
37
43
  optional :x_stream_response, enum: -> { Stagehand::SessionNavigateParams::XStreamResponse }
38
44
 
39
- # @!method initialize(url:, frame_id: nil, options: nil, stream_response: nil, x_stream_response: nil, request_options: {})
45
+ # @!method initialize(id:, url:, frame_id: nil, options: nil, stream_response: nil, x_stream_response: nil, request_options: {})
46
+ # @param id [String] Unique session identifier
47
+ #
40
48
  # @param url [String] URL to navigate to
41
49
  #
42
50
  # @param frame_id [String, nil] Target frame ID for the navigation
@@ -9,6 +9,12 @@ module Stagehand
9
9
  extend Stagehand::Internal::Type::RequestParameters::Converter
10
10
  include Stagehand::Internal::Type::RequestParameters
11
11
 
12
+ # @!attribute id
13
+ # Unique session identifier
14
+ #
15
+ # @return [String]
16
+ required :id, String
17
+
12
18
  # @!attribute frame_id
13
19
  # Target frame ID for the observation
14
20
  #
@@ -32,7 +38,9 @@ module Stagehand
32
38
  # @return [Symbol, Stagehand::Models::SessionObserveParams::XStreamResponse, nil]
33
39
  optional :x_stream_response, enum: -> { Stagehand::SessionObserveParams::XStreamResponse }
34
40
 
35
- # @!method initialize(frame_id: nil, instruction: nil, options: nil, x_stream_response: nil, request_options: {})
41
+ # @!method initialize(id:, frame_id: nil, instruction: nil, options: nil, x_stream_response: nil, request_options: {})
42
+ # @param id [String] Unique session identifier
43
+ #
36
44
  # @param frame_id [String, nil] Target frame ID for the observation
37
45
  #
38
46
  # @param instruction [String] Natural language instruction for what actions to find
@@ -62,12 +70,26 @@ module Stagehand
62
70
  # @return [Float, nil]
63
71
  optional :timeout, Float
64
72
 
65
- # @!method initialize(model: nil, selector: nil, timeout: nil)
73
+ # @!attribute variables
74
+ # Variables whose names are exposed to the model so observe() returns
75
+ # %variableName% placeholders in suggested action arguments instead of literal
76
+ # values. Accepts flat primitives or { value, description? } objects.
77
+ #
78
+ # @return [Hash{Symbol=>String, Float, Boolean, Stagehand::Models::SessionObserveParams::Options::Variable::UnionMember3}, nil]
79
+ optional :variables,
80
+ -> { Stagehand::Internal::Type::HashOf[union: Stagehand::SessionObserveParams::Options::Variable] }
81
+
82
+ # @!method initialize(model: nil, selector: nil, timeout: nil, variables: nil)
83
+ # Some parameter documentations has been truncated, see
84
+ # {Stagehand::Models::SessionObserveParams::Options} for more details.
85
+ #
66
86
  # @param model [Stagehand::Models::ModelConfig, String] Model configuration object or model name string (e.g., 'openai/gpt-5-nano')
67
87
  #
68
88
  # @param selector [String] CSS selector to scope observation to a specific element
69
89
  #
70
90
  # @param timeout [Float] Timeout in ms for the observation
91
+ #
92
+ # @param variables [Hash{Symbol=>String, Float, Boolean, Stagehand::Models::SessionObserveParams::Options::Variable::UnionMember3}] Variables whose names are exposed to the model so observe() returns %variableNam
71
93
 
72
94
  # Model configuration object or model name string (e.g., 'openai/gpt-5-nano')
73
95
  #
@@ -82,6 +104,51 @@ module Stagehand
82
104
  # @!method self.variants
83
105
  # @return [Array(Stagehand::Models::ModelConfig, String)]
84
106
  end
107
+
108
+ module Variable
109
+ extend Stagehand::Internal::Type::Union
110
+
111
+ variant String
112
+
113
+ variant Float
114
+
115
+ variant Stagehand::Internal::Type::Boolean
116
+
117
+ variant -> { Stagehand::SessionObserveParams::Options::Variable::UnionMember3 }
118
+
119
+ class UnionMember3 < Stagehand::Internal::Type::BaseModel
120
+ # @!attribute value
121
+ #
122
+ # @return [String, Float, Boolean]
123
+ required :value, union: -> { Stagehand::SessionObserveParams::Options::Variable::UnionMember3::Value }
124
+
125
+ # @!attribute description
126
+ #
127
+ # @return [String, nil]
128
+ optional :description, String
129
+
130
+ # @!method initialize(value:, description: nil)
131
+ # @param value [String, Float, Boolean]
132
+ # @param description [String]
133
+
134
+ # @see Stagehand::Models::SessionObserveParams::Options::Variable::UnionMember3#value
135
+ module Value
136
+ extend Stagehand::Internal::Type::Union
137
+
138
+ variant String
139
+
140
+ variant Float
141
+
142
+ variant Stagehand::Internal::Type::Boolean
143
+
144
+ # @!method self.variants
145
+ # @return [Array(String, Float, Boolean)]
146
+ end
147
+ end
148
+
149
+ # @!method self.variants
150
+ # @return [Array(String, Float, Boolean, Stagehand::Models::SessionObserveParams::Options::Variable::UnionMember3)]
151
+ end
85
152
  end
86
153
 
87
154
  # Whether to stream the response via SSE
@@ -7,13 +7,21 @@ module Stagehand
7
7
  extend Stagehand::Internal::Type::RequestParameters::Converter
8
8
  include Stagehand::Internal::Type::RequestParameters
9
9
 
10
+ # @!attribute id
11
+ # Unique session identifier
12
+ #
13
+ # @return [String]
14
+ required :id, String
15
+
10
16
  # @!attribute x_stream_response
11
17
  # Whether to stream the response via SSE
12
18
  #
13
19
  # @return [Symbol, Stagehand::Models::SessionReplayParams::XStreamResponse, nil]
14
20
  optional :x_stream_response, enum: -> { Stagehand::SessionReplayParams::XStreamResponse }
15
21
 
16
- # @!method initialize(x_stream_response: nil, request_options: {})
22
+ # @!method initialize(id:, x_stream_response: nil, request_options: {})
23
+ # @param id [String] Unique session identifier
24
+ #
17
25
  # @param x_stream_response [Symbol, Stagehand::Models::SessionReplayParams::XStreamResponse] Whether to stream the response via SSE
18
26
  #
19
27
  # @param request_options [Stagehand::RequestOptions, Hash{Symbol=>Object}]
@@ -144,6 +144,11 @@ module Stagehand
144
144
  # @return [Array<String>, nil]
145
145
  optional :args, Stagehand::Internal::Type::ArrayOf[String]
146
146
 
147
+ # @!attribute cdp_headers
148
+ #
149
+ # @return [Hash{Symbol=>String}, nil]
150
+ optional :cdp_headers, Stagehand::Internal::Type::HashOf[String], api_name: :cdpHeaders
151
+
147
152
  # @!attribute cdp_url
148
153
  #
149
154
  # @return [String, nil]
@@ -231,9 +236,10 @@ module Stagehand
231
236
  # @return [Stagehand::Models::SessionStartParams::Browser::LaunchOptions::Viewport, nil]
232
237
  optional :viewport, -> { Stagehand::SessionStartParams::Browser::LaunchOptions::Viewport }
233
238
 
234
- # @!method initialize(accept_downloads: nil, args: nil, cdp_url: nil, chromium_sandbox: nil, connect_timeout_ms: nil, device_scale_factor: nil, devtools: nil, downloads_path: nil, executable_path: nil, has_touch: nil, headless: nil, ignore_default_args: nil, ignore_https_errors: nil, locale: nil, port: nil, preserve_user_data_dir: nil, proxy: nil, user_data_dir: nil, viewport: nil)
239
+ # @!method initialize(accept_downloads: nil, args: nil, cdp_headers: nil, cdp_url: nil, chromium_sandbox: nil, connect_timeout_ms: nil, device_scale_factor: nil, devtools: nil, downloads_path: nil, executable_path: nil, has_touch: nil, headless: nil, ignore_default_args: nil, ignore_https_errors: nil, locale: nil, port: nil, preserve_user_data_dir: nil, proxy: nil, user_data_dir: nil, viewport: nil)
235
240
  # @param accept_downloads [Boolean]
236
241
  # @param args [Array<String>]
242
+ # @param cdp_headers [Hash{Symbol=>String}]
237
243
  # @param cdp_url [String]
238
244
  # @param chromium_sandbox [Boolean]
239
245
  # @param connect_timeout_ms [Float]
@@ -22,7 +22,8 @@ module Stagehand
22
22
 
23
23
  # @!method initialize(id:, data:, type:)
24
24
  # Server-Sent Event emitted during streaming responses. Events are sent as
25
- # `data: <JSON>\n\n`. Key order: data (with status first), type, id.
25
+ # `event: <status>\ndata: <JSON>\n\n`, where the JSON payload has the shape
26
+ # `{ data, type, id }`.
26
27
  #
27
28
  # @param id [String] Unique identifier for this event
28
29
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Stagehand
4
- VERSION = "3.7.1"
4
+ VERSION = "3.18.0"
5
5
  end
@@ -301,6 +301,26 @@ module Stagehand
301
301
  T.let(%r{^application/(:?x-(?:n|l)djson)|(:?(?:x-)?jsonl)}, Regexp)
302
302
 
303
303
  class << self
304
+ # @api private
305
+ sig do
306
+ params(query: Stagehand::Internal::AnyHash).returns(
307
+ Stagehand::Internal::AnyHash
308
+ )
309
+ end
310
+ def encode_query_params(query)
311
+ end
312
+
313
+ # @api private
314
+ sig do
315
+ params(
316
+ collection: Stagehand::Internal::AnyHash,
317
+ key: String,
318
+ element: T.anything
319
+ ).void
320
+ end
321
+ private def write_query_param_element!(collection, key, element)
322
+ end
323
+
304
324
  # @api private
305
325
  sig do
306
326
  params(
@@ -26,6 +26,13 @@ module Stagehand
26
26
  sig { params(base_url: String).void }
27
27
  attr_writer :base_url
28
28
 
29
+ # Custom headers sent with every request to the model provider
30
+ sig { returns(T.nilable(T::Hash[Symbol, String])) }
31
+ attr_reader :headers
32
+
33
+ sig { params(headers: T::Hash[Symbol, String]).void }
34
+ attr_writer :headers
35
+
29
36
  # AI provider for the model (or provide a baseURL endpoint instead)
30
37
  sig { returns(T.nilable(Stagehand::ModelConfig::Provider::OrSymbol)) }
31
38
  attr_reader :provider
@@ -38,6 +45,7 @@ module Stagehand
38
45
  model_name: String,
39
46
  api_key: String,
40
47
  base_url: String,
48
+ headers: T::Hash[Symbol, String],
41
49
  provider: Stagehand::ModelConfig::Provider::OrSymbol
42
50
  ).returns(T.attached_class)
43
51
  end
@@ -48,6 +56,8 @@ module Stagehand
48
56
  api_key: nil,
49
57
  # Base URL for the model provider
50
58
  base_url: nil,
59
+ # Custom headers sent with every request to the model provider
60
+ headers: nil,
51
61
  # AI provider for the model (or provide a baseURL endpoint instead)
52
62
  provider: nil
53
63
  )
@@ -59,6 +69,7 @@ module Stagehand
59
69
  model_name: String,
60
70
  api_key: String,
61
71
  base_url: String,
72
+ headers: T::Hash[Symbol, String],
62
73
  provider: Stagehand::ModelConfig::Provider::OrSymbol
63
74
  }
64
75
  )