Class: Stagehand::Resources::Sessions
- Inherits:
-
Object
- Object
- Stagehand::Resources::Sessions
- Includes:
- Local::SessionsPatch
- Defined in:
- lib/stagehand/resources/sessions.rb
Instance Method Summary collapse
-
#act(id, input:, frame_id: nil, options: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionActResponse
See #act_streaming for streaming counterpart.
-
#act_streaming(id, input:, frame_id: nil, options: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Internal::Stream<Stagehand::Models::StreamEvent>
See #act for non-streaming counterpart.
-
#end_(id, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionEndResponse
Terminates the browser session and releases all associated resources.
-
#execute(id, agent_config:, execute_options:, frame_id: nil, should_cache: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionExecuteResponse
See #execute_streaming for streaming counterpart.
-
#execute_streaming(id, agent_config:, execute_options:, frame_id: nil, should_cache: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Internal::Stream<Stagehand::Models::StreamEvent>
See #execute for non-streaming counterpart.
-
#extract(id, frame_id: nil, instruction: nil, options: nil, schema: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionExtractResponse
See #extract_streaming for streaming counterpart.
-
#extract_streaming(id, frame_id: nil, instruction: nil, options: nil, schema: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Internal::Stream<Stagehand::Models::StreamEvent>
See #extract for non-streaming counterpart.
-
#initialize(client:) ⇒ Sessions
constructor
private
A new instance of Sessions.
-
#navigate(id, url:, frame_id: nil, options: nil, stream_response: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionNavigateResponse
Navigates the browser to the specified URL.
-
#observe(id, frame_id: nil, instruction: nil, options: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionObserveResponse
See #observe_streaming for streaming counterpart.
-
#observe_streaming(id, frame_id: nil, instruction: nil, options: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Internal::Stream<Stagehand::Models::StreamEvent>
See #observe for non-streaming counterpart.
-
#replay(id, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionReplayResponse
Retrieves replay metrics for a session.
-
#start(model_name:, act_timeout_ms: nil, browser: nil, browserbase_session_create_params: nil, browserbase_session_id: nil, dom_settle_timeout_ms: nil, experimental: nil, self_heal: nil, system_prompt: nil, verbose: nil, wait_for_captcha_solves: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionStartResponse
Creates a new browser session with the specified configuration.
Constructor Details
#initialize(client:) ⇒ Sessions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Sessions.
495 496 497 |
# File 'lib/stagehand/resources/sessions.rb', line 495 def initialize(client:) @client = client end |
Instance Method Details
#act(id, input:, frame_id: nil, options: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionActResponse
See #act_streaming for streaming counterpart.
Executes a browser action using natural language instructions or a predefined Action object.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/stagehand/resources/sessions.rb', line 28 def act(id, params) parsed, = Stagehand::SessionActParams.dump_request(params) if parsed[:streamResponse] = "Please use `#act_streaming` for the streaming use case." raise ArgumentError.new() end header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/act", id], headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Stagehand::Models::SessionActResponse, options: ) end |
#act_streaming(id, input:, frame_id: nil, options: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Internal::Stream<Stagehand::Models::StreamEvent>
See #act for non-streaming counterpart.
Executes a browser action using natural language instructions or a predefined Action object.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/stagehand/resources/sessions.rb', line 67 def act_streaming(id, params) parsed, = Stagehand::SessionActParams.dump_request(params) unless parsed.fetch(:streamResponse, true) = "Please use `#act` for the non-streaming use case." raise ArgumentError.new() end parsed.store(:streamResponse, true) header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/act", id], headers: { "accept" => "text/event-stream", "accept-encoding" => "identity", **parsed.slice(*header_params.keys) }.transform_keys( header_params ), body: parsed.except(*header_params.keys), stream: Stagehand::Internal::Stream, model: Stagehand::StreamEvent, options: ) end |
#end_(id, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionEndResponse
Terminates the browser session and releases all associated resources.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/stagehand/resources/sessions.rb', line 105 def end_(id, params = {}) parsed, = Stagehand::SessionEndParams.dump_request(params) @client.request( method: :post, path: ["v1/sessions/%1$s/end", id], headers: parsed.transform_keys(x_stream_response: "x-stream-response"), model: Stagehand::Models::SessionEndResponse, options: ) end |
#execute(id, agent_config:, execute_options:, frame_id: nil, should_cache: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionExecuteResponse
See #execute_streaming for streaming counterpart.
Some parameter documentations has been truncated, see Models::SessionExecuteParams for more details.
Runs an autonomous AI agent that can perform complex multi-step browser tasks.
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/stagehand/resources/sessions.rb', line 143 def execute(id, params) parsed, = Stagehand::SessionExecuteParams.dump_request(params) if parsed[:streamResponse] = "Please use `#execute_streaming` for the streaming use case." raise ArgumentError.new() end header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/agentExecute", id], headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Stagehand::Models::SessionExecuteResponse, options: ) end |
#execute_streaming(id, agent_config:, execute_options:, frame_id: nil, should_cache: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Internal::Stream<Stagehand::Models::StreamEvent>
See #execute for non-streaming counterpart.
Some parameter documentations has been truncated, see Models::SessionExecuteParams for more details.
Runs an autonomous AI agent that can perform complex multi-step browser tasks.
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/stagehand/resources/sessions.rb', line 186 def execute_streaming(id, params) parsed, = Stagehand::SessionExecuteParams.dump_request(params) unless parsed.fetch(:streamResponse, true) = "Please use `#execute` for the non-streaming use case." raise ArgumentError.new() end parsed.store(:streamResponse, true) header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/agentExecute", id], headers: { "accept" => "text/event-stream", "accept-encoding" => "identity", **parsed.slice(*header_params.keys) }.transform_keys( header_params ), body: parsed.except(*header_params.keys), stream: Stagehand::Internal::Stream, model: Stagehand::StreamEvent, options: ) end |
#extract(id, frame_id: nil, instruction: nil, options: nil, schema: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionExtractResponse
See #extract_streaming for streaming counterpart.
Extracts structured data from the current page using AI-powered analysis.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/stagehand/resources/sessions.rb', line 235 def extract(id, params = {}) parsed, = Stagehand::SessionExtractParams.dump_request(params) if parsed[:streamResponse] = "Please use `#extract_streaming` for the streaming use case." raise ArgumentError.new() end header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/extract", id], headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Stagehand::Models::SessionExtractResponse, options: ) end |
#extract_streaming(id, frame_id: nil, instruction: nil, options: nil, schema: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Internal::Stream<Stagehand::Models::StreamEvent>
See #extract for non-streaming counterpart.
Extracts structured data from the current page using AI-powered analysis.
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/stagehand/resources/sessions.rb', line 275 def extract_streaming(id, params = {}) parsed, = Stagehand::SessionExtractParams.dump_request(params) unless parsed.fetch(:streamResponse, true) = "Please use `#extract` for the non-streaming use case." raise ArgumentError.new() end parsed.store(:streamResponse, true) header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/extract", id], headers: { "accept" => "text/event-stream", "accept-encoding" => "identity", **parsed.slice(*header_params.keys) }.transform_keys( header_params ), body: parsed.except(*header_params.keys), stream: Stagehand::Internal::Stream, model: Stagehand::StreamEvent, options: ) end |
#navigate(id, url:, frame_id: nil, options: nil, stream_response: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionNavigateResponse
Navigates the browser to the specified URL.
321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/stagehand/resources/sessions.rb', line 321 def navigate(id, params) parsed, = Stagehand::SessionNavigateParams.dump_request(params) header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/navigate", id], headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Stagehand::Models::SessionNavigateResponse, options: ) end |
#observe(id, frame_id: nil, instruction: nil, options: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionObserveResponse
See #observe_streaming for streaming counterpart.
Identifies and returns available actions on the current page that match the given instruction.
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/stagehand/resources/sessions.rb', line 357 def observe(id, params = {}) parsed, = Stagehand::SessionObserveParams.dump_request(params) if parsed[:streamResponse] = "Please use `#observe_streaming` for the streaming use case." raise ArgumentError.new() end header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/observe", id], headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Stagehand::Models::SessionObserveResponse, options: ) end |
#observe_streaming(id, frame_id: nil, instruction: nil, options: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Internal::Stream<Stagehand::Models::StreamEvent>
See #observe for non-streaming counterpart.
Identifies and returns available actions on the current page that match the given instruction.
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 |
# File 'lib/stagehand/resources/sessions.rb', line 396 def observe_streaming(id, params = {}) parsed, = Stagehand::SessionObserveParams.dump_request(params) unless parsed.fetch(:streamResponse, true) = "Please use `#observe` for the non-streaming use case." raise ArgumentError.new() end parsed.store(:streamResponse, true) header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: ["v1/sessions/%1$s/observe", id], headers: { "accept" => "text/event-stream", "accept-encoding" => "identity", **parsed.slice(*header_params.keys) }.transform_keys( header_params ), body: parsed.except(*header_params.keys), stream: Stagehand::Internal::Stream, model: Stagehand::StreamEvent, options: ) end |
#replay(id, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionReplayResponse
Retrieves replay metrics for a session.
434 435 436 437 438 439 440 441 442 443 |
# File 'lib/stagehand/resources/sessions.rb', line 434 def replay(id, params = {}) parsed, = Stagehand::SessionReplayParams.dump_request(params) @client.request( method: :get, path: ["v1/sessions/%1$s/replay", id], headers: parsed.transform_keys(x_stream_response: "x-stream-response"), model: Stagehand::Models::SessionReplayResponse, options: ) end |
#start(model_name:, act_timeout_ms: nil, browser: nil, browserbase_session_create_params: nil, browserbase_session_id: nil, dom_settle_timeout_ms: nil, experimental: nil, self_heal: nil, system_prompt: nil, verbose: nil, wait_for_captcha_solves: nil, x_stream_response: nil, request_options: {}) ⇒ Stagehand::Models::SessionStartResponse
Creates a new browser session with the specified configuration. Returns a session ID used for all subsequent operations.
479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'lib/stagehand/resources/sessions.rb', line 479 def start(params) parsed, = Stagehand::SessionStartParams.dump_request(params) header_params = {x_stream_response: "x-stream-response"} @client.request( method: :post, path: "v1/sessions/start", headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Stagehand::Models::SessionStartResponse, options: ) end |