daytona 0.126.0.alpha.6

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.
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'net/http'
4
+
5
+ module Daytona
6
+ module Util
7
+ def self.demux(line) # rubocop:disable Metrics/MethodLength
8
+ stdout = ''.dup
9
+ stderr = ''.dup
10
+
11
+ until line.empty?
12
+ buff = line.start_with?(STDOUT_PREFIX) ? stdout : stderr
13
+ line = line[3..]
14
+
15
+ end_index = [
16
+ line.index(STDOUT_PREFIX),
17
+ line.index(STDERR_PREFIX)
18
+ ].compact.min || line.length
19
+ data = line[...end_index]
20
+ buff << data
21
+
22
+ line = line[end_index..]
23
+ end
24
+
25
+ [stdout, stderr]
26
+ end
27
+
28
+ # @param uri [URI]
29
+ # @param on_chunk [Proc]
30
+ # @param headers [Hash<String, String>]
31
+ # @return [Thread]
32
+ def self.stream_async(uri:, on_chunk:, headers: nil) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
33
+ Sdk.logger.debug("Starting async stream: #{uri}")
34
+ Thread.new do
35
+ Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
36
+ request = Net::HTTP::Get.new(uri, headers)
37
+
38
+ http.request(request) do |response|
39
+ response.read_body do |chunk|
40
+ Sdk.logger.debug("Chunked response received: #{chunk.inspect}")
41
+ on_chunk.call(chunk)
42
+ end
43
+ end
44
+ end
45
+ rescue Net::ReadTimeout => e
46
+ Sdk.logger.debug("Async stream (#{uri}) timeout: #{e.inspect}")
47
+ end
48
+ end
49
+
50
+ STDOUT_PREFIX = "\x01\x01\01"
51
+ private_constant :STDOUT_PREFIX
52
+
53
+ STDERR_PREFIX = "\x02\x02\02"
54
+ private_constant :STDERR_PREFIX
55
+ end
56
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daytona
4
+ class Volume
5
+ # @return [String]
6
+ attr_reader :id
7
+
8
+ # @return [String]
9
+ attr_reader :name
10
+
11
+ # @return [String]
12
+ attr_reader :organization_id
13
+
14
+ # @return [String]
15
+ attr_reader :state
16
+
17
+ # @return [String]
18
+ attr_reader :created_at
19
+
20
+ # @return [String]
21
+ attr_reader :updated_at
22
+
23
+ # @return [String]
24
+ attr_reader :last_used_at
25
+
26
+ # @return [String, nil]
27
+ attr_reader :error_reason
28
+
29
+ # Initialize volume from DTO
30
+ #
31
+ # @param volume_dto [DaytonaApiClient::SandboxVolume]
32
+ def initialize(volume_dto)
33
+ @id = volume_dto.id
34
+ @name = volume_dto.name
35
+ @organization_id = volume_dto.organization_id
36
+ @state = volume_dto.state
37
+ @created_at = volume_dto.created_at
38
+ @updated_at = volume_dto.updated_at
39
+ @last_used_at = volume_dto.last_used_at
40
+ @error_reason = volume_dto.error_reason
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Daytona
4
+ class VolumeService
5
+ # Service for managing Daytona Volumes. Can be used to list, get, create and delete Volumes.
6
+ #
7
+ # @param volumes_api [DaytonaApiClient::VolumesApi]
8
+ def initialize(volumes_api)
9
+ @volumes_api = volumes_api
10
+ end
11
+
12
+ # Create new Volume.
13
+ #
14
+ # @param name [String]
15
+ # @return [Daytona::Volume]
16
+ def create(name) = Volume.new(volumes_api.create_volume(DaytonaApiClient::CreateVolume.new(name:)))
17
+
18
+ # Delete a Volume.
19
+ #
20
+ # @param volume [Daytona::Volume]
21
+ # @return [void]
22
+ def delete(volume) = volumes_api.delete_volume(volume.id)
23
+
24
+ # Get a Volume by name.
25
+ #
26
+ # @param name [String]
27
+ # @param create [Boolean]
28
+ # @return [Daytona::Volume]
29
+ def get(name, create: false)
30
+ Volume.new(volumes_api.get_volume_by_name(name))
31
+ rescue DaytonaApiClient::ApiError => e
32
+ raise unless create && e.code == 404 && e.message.include?("Volume with name #{name} not found")
33
+
34
+ create(name)
35
+ end
36
+
37
+ # List all Volumes.
38
+ #
39
+ # @return [Array<Daytona::Volume>]
40
+ def list
41
+ volumes_api.list_volumes.map { |volume| Volume.new(volume) }
42
+ end
43
+
44
+ private
45
+
46
+ # @return [DaytonaApiClient::VolumesApi]
47
+ attr_reader :volumes_api
48
+ end
49
+ end
data/lib/daytona.rb ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Main entry point for the Daytona Ruby SDK
4
+ # This file provides a convenient way to require the entire SDK with:
5
+ # require 'daytona'
6
+
7
+ require_relative 'daytona/sdk'
8
+
data/project.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "sdk-ruby",
3
+ "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
+ "projectType": "library",
5
+ "sourceRoot": "libs/sdk-ruby",
6
+ "tags": [],
7
+ "targets": {
8
+ "build": {
9
+ "executor": "nx:run-commands",
10
+ "options": {
11
+ "cwd": "{projectRoot}",
12
+ "commands": ["rm -f *.gem", "bundle install", "gem build daytona.gemspec"],
13
+ "parallel": false
14
+ },
15
+ "dependsOn": [
16
+ {
17
+ "target": "build",
18
+ "projects": ["api-client-ruby", "toolbox-api-client-ruby"]
19
+ },
20
+ "set-version"
21
+ ]
22
+ },
23
+ "set-version": {
24
+ "executor": "nx:run-commands",
25
+ "options": {
26
+ "cwd": "{projectRoot}",
27
+ "command": "if [ -n \"$RUBYGEMS_PKG_VERSION\" ] || [ -n \"$DEFAULT_PACKAGE_VERSION\" ]; then VER=${RUBYGEMS_PKG_VERSION:-$DEFAULT_PACKAGE_VERSION}; sed -i \"s/VERSION = '[^']*'/VERSION = '$VER'/\" lib/daytona/sdk/version.rb && echo \"Changed version to $VER\"; else echo \"Using version from version.rb\"; fi"
28
+ }
29
+ },
30
+ "lint": {
31
+ "executor": "nx:run-commands",
32
+ "options": {
33
+ "cwd": "{projectRoot}",
34
+ "command": "bundle exec rubocop"
35
+ }
36
+ },
37
+ "test": {
38
+ "executor": "nx:run-commands",
39
+ "options": {
40
+ "cwd": "{projectRoot}",
41
+ "command": "bundle exec rake spec"
42
+ }
43
+ },
44
+ "format": {
45
+ "executor": "nx:run-commands",
46
+ "options": {
47
+ "cwd": "{projectRoot}",
48
+ "commands": ["bundle exec rubocop -a --fail-level=E"],
49
+ "parallel": false
50
+ }
51
+ },
52
+ "publish": {
53
+ "executor": "nx:run-commands",
54
+ "options": {
55
+ "cwd": "{projectRoot}",
56
+ "command": "gem push daytona-*.gem --key rubygems --host https://rubygems.org"
57
+ },
58
+ "dependsOn": [
59
+ {
60
+ "target": "publish",
61
+ "projects": ["api-client-ruby", "toolbox-api-client-ruby"]
62
+ },
63
+ "build"
64
+ ]
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,6 @@
1
+ module Daytona
2
+ module Sdk
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: daytona
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.126.0.alpha.6
5
+ platform: ruby
6
+ authors:
7
+ - Daytona Platforms Inc.
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: aws-sdk-s3
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: daytona_api_client
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - '='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.126.0.alpha.6
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '='
38
+ - !ruby/object:Gem::Version
39
+ version: 0.126.0.alpha.6
40
+ - !ruby/object:Gem::Dependency
41
+ name: daytona_toolbox_api_client
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 0.126.0.alpha.6
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.126.0.alpha.6
54
+ - !ruby/object:Gem::Dependency
55
+ name: dotenv
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '2.0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.0'
68
+ - !ruby/object:Gem::Dependency
69
+ name: toml
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '0.3'
75
+ type: :runtime
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '0.3'
82
+ - !ruby/object:Gem::Dependency
83
+ name: websocket-client-simple
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.6'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.6'
96
+ description: 'High-level Ruby SDK for Daytona: sandboxes, git, filesystem, LSP, process,
97
+ and object storage.'
98
+ email:
99
+ - support@daytona.io
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".rubocop.yml"
105
+ - ".ruby-version"
106
+ - CODE_OF_CONDUCT.md
107
+ - README.md
108
+ - Rakefile
109
+ - lib/daytona.rb
110
+ - lib/daytona/code_toolbox/sandbox_python_code_toolbox.rb
111
+ - lib/daytona/code_toolbox/sandbox_ts_code_toolbox.rb
112
+ - lib/daytona/common/charts.rb
113
+ - lib/daytona/common/code_language.rb
114
+ - lib/daytona/common/daytona.rb
115
+ - lib/daytona/common/file_system.rb
116
+ - lib/daytona/common/git.rb
117
+ - lib/daytona/common/image.rb
118
+ - lib/daytona/common/process.rb
119
+ - lib/daytona/common/pty.rb
120
+ - lib/daytona/common/resources.rb
121
+ - lib/daytona/common/response.rb
122
+ - lib/daytona/common/snapshot.rb
123
+ - lib/daytona/computer_use.rb
124
+ - lib/daytona/config.rb
125
+ - lib/daytona/daytona.rb
126
+ - lib/daytona/file_system.rb
127
+ - lib/daytona/git.rb
128
+ - lib/daytona/lsp_server.rb
129
+ - lib/daytona/object_storage.rb
130
+ - lib/daytona/process.rb
131
+ - lib/daytona/sandbox.rb
132
+ - lib/daytona/sdk.rb
133
+ - lib/daytona/sdk/version.rb
134
+ - lib/daytona/snapshot_service.rb
135
+ - lib/daytona/util.rb
136
+ - lib/daytona/volume.rb
137
+ - lib/daytona/volume_service.rb
138
+ - project.json
139
+ - sig/daytona/sdk.rbs
140
+ homepage: https://github.com/daytonaio/daytona
141
+ licenses: []
142
+ metadata:
143
+ allowed_push_host: https://rubygems.org
144
+ homepage_uri: https://github.com/daytonaio/daytona
145
+ source_code_uri: https://github.com/daytonaio/daytona
146
+ changelog_uri: https://github.com/daytonaio/daytona/releases
147
+ rubygems_mfa_required: 'true'
148
+ rdoc_options: []
149
+ require_paths:
150
+ - lib
151
+ required_ruby_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: 3.2.0
156
+ required_rubygems_version: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubygems_version: 3.6.9
163
+ specification_version: 4
164
+ summary: Ruby SDK for Daytona
165
+ test_files: []