Class: Daytona::ComputerUse::Recording

Inherits:
Object
  • Object
show all
Includes:
Instrumentation
Defined in:
lib/daytona/computer_use.rb

Overview

Recording operations for computer use functionality.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Instrumentation

included

Constructor Details

#initialize(sandbox_id:, toolbox_api:, otel_state: nil) ⇒ Recording

Returns a new instance of Recording.

Parameters:

  • sandbox_id (String)

    The ID of the sandbox

  • toolbox_api (DaytonaToolboxApiClient::ComputerUseApi)

    API client for sandbox operations

  • otel_state (Daytona::OtelState, nil) (defaults to: nil)


610
611
612
613
614
# File 'lib/daytona/computer_use.rb', line 610

def initialize(sandbox_id:, toolbox_api:, otel_state: nil)
  @sandbox_id = sandbox_id
  @toolbox_api = toolbox_api
  @otel_state = otel_state
end

Instance Attribute Details

#sandbox_idString (readonly)

Returns The ID of the sandbox.

Returns:

  • (String)

    The ID of the sandbox



602
603
604
# File 'lib/daytona/computer_use.rb', line 602

def sandbox_id
  @sandbox_id
end

#toolbox_apiDaytonaToolboxApiClient::ComputerUseApi (readonly)

Returns API client for sandbox operations.

Returns:

  • (DaytonaToolboxApiClient::ComputerUseApi)

    API client for sandbox operations



605
606
607
# File 'lib/daytona/computer_use.rb', line 605

def toolbox_api
  @toolbox_api
end

Instance Method Details

#delete(id:) ⇒ void

This method returns an undefined value.

Deletes a recording by ID.

Examples:

sandbox.computer_use.recording.delete(id: recording_id)
puts "Recording deleted"

Parameters:

  • id (String)

    The ID of the recording to delete

Raises:



694
695
696
697
698
# File 'lib/daytona/computer_use.rb', line 694

def delete(id:)
  toolbox_api.delete_recording(id)
rescue StandardError => e
  raise Sdk::Error, "Failed to delete recording: #{e.message}"
end

#download(id:, local_path:) ⇒ void

This method returns an undefined value.

Downloads a recording file and saves it to a local path.

The file is streamed directly to disk without loading the entire content into memory.

Examples:

sandbox.computer_use.recording.download(id: recording_id, local_path: "local_recording.mp4")
puts "Recording downloaded"

Parameters:

  • id (String)

    The ID of the recording to download

  • local_path (String)

    Path to save the recording file locally

Raises:



712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
# File 'lib/daytona/computer_use.rb', line 712

def download(id:, local_path:)
  require 'fileutils'
  require 'typhoeus'

  # Get the API configuration and build the download URL
  api_client = toolbox_api.api_client
  config = api_client.config
  base_url = config.base_url
  download_url = "#{base_url}/computeruse/recordings/#{id}/download"

  # Create parent directory if it doesn't exist
  parent_dir = File.dirname(local_path)
  FileUtils.mkdir_p(parent_dir) unless parent_dir.empty?

  # Stream the download directly to file
  file = File.open(local_path, 'wb')
  request = Typhoeus::Request.new(
    download_url,
    method: :get,
    headers: api_client.default_headers,
    timeout: config.timeout,
    ssl_verifypeer: config.verify_ssl,
    ssl_verifyhost: config.verify_ssl_host ? 2 : 0
  )

  # Stream chunks directly to file
  request.on_body do |chunk|
    file.write(chunk)
  end

  request.on_complete do |response|
    file.close
    unless response.success?
      File.delete(local_path) if File.exist?(local_path)
      raise Sdk::Error, "Failed to download recording: HTTP #{response.code}"
    end
  end

  request.run
rescue StandardError => e
  file&.close
  File.delete(local_path) if File.exist?(local_path)
  raise Sdk::Error, "Failed to download recording: #{e.message}"
end

#get(id:) ⇒ DaytonaToolboxApiClient::Recording

Gets details of a specific recording by ID.

Examples:

recording = sandbox.computer_use.recording.get(id: recording_id)
puts "Recording: #{recording.file_name}"
puts "Status: #{recording.status}"
puts "Duration: #{recording.duration_seconds} seconds"

Parameters:

  • id (String)

    The ID of the recording to retrieve

Returns:

  • (DaytonaToolboxApiClient::Recording)

    Recording details

Raises:



679
680
681
682
683
# File 'lib/daytona/computer_use.rb', line 679

def get(id:)
  toolbox_api.get_recording(id)
rescue StandardError => e
  raise Sdk::Error, "Failed to get recording: #{e.message}"
end

#listDaytonaToolboxApiClient::ListRecordingsResponse

Lists all recordings (active and completed).

Examples:

recordings = sandbox.computer_use.recording.list
puts "Found #{recordings.recordings.length} recordings"
recordings.recordings.each do |rec|
  puts "- #{rec.file_name}: #{rec.status}"
end

Returns:

  • (DaytonaToolboxApiClient::ListRecordingsResponse)

    List of all recordings

Raises:



662
663
664
665
666
# File 'lib/daytona/computer_use.rb', line 662

def list
  toolbox_api.list_recordings
rescue StandardError => e
  raise Sdk::Error, "Failed to list recordings: #{e.message}"
end

#start(label: nil) ⇒ DaytonaToolboxApiClient::Recording

Starts a new screen recording session.

Examples:

# Start a recording with a label
recording = sandbox.computer_use.recording.start(label: "my-test-recording")
puts "Recording started: #{recording.id}"
puts "File: #{recording.file_path}"

Parameters:

  • label (String, nil) (defaults to: nil)

    Optional custom label for the recording

Returns:

  • (DaytonaToolboxApiClient::Recording)

    Started recording details

Raises:



627
628
629
630
631
632
# File 'lib/daytona/computer_use.rb', line 627

def start(label: nil)
  request = DaytonaToolboxApiClient::StartRecordingRequest.new(label:)
  toolbox_api.start_recording(request: request)
rescue StandardError => e
  raise Sdk::Error, "Failed to start recording: #{e.message}"
end

#stop(id:) ⇒ DaytonaToolboxApiClient::Recording

Stops an active screen recording session.

Examples:

result = sandbox.computer_use.recording.stop(id: recording.id)
puts "Recording stopped: #{result.duration_seconds} seconds"
puts "Saved to: #{result.file_path}"

Parameters:

  • id (String)

    The ID of the recording to stop

Returns:

  • (DaytonaToolboxApiClient::Recording)

    Stopped recording details

Raises:



644
645
646
647
648
649
# File 'lib/daytona/computer_use.rb', line 644

def stop(id:)
  request = DaytonaToolboxApiClient::StopRecordingRequest.new(id: id)
  toolbox_api.stop_recording(request)
rescue StandardError => e
  raise Sdk::Error, "Failed to stop recording: #{e.message}"
end