cogbox 0.190.1

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 (43) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +22 -0
  4. data/.ruby-version +1 -0
  5. data/CODE_OF_CONDUCT.md +132 -0
  6. data/LICENSE +190 -0
  7. data/README.md +184 -0
  8. data/Rakefile +12 -0
  9. data/lib/cogbox/code_interpreter.rb +360 -0
  10. data/lib/cogbox/cogbox.rb +337 -0
  11. data/lib/cogbox/common/charts.rb +125 -0
  12. data/lib/cogbox/common/code_interpreter.rb +57 -0
  13. data/lib/cogbox/common/code_language.rb +15 -0
  14. data/lib/cogbox/common/cogbox.rb +231 -0
  15. data/lib/cogbox/common/file_system.rb +27 -0
  16. data/lib/cogbox/common/git.rb +20 -0
  17. data/lib/cogbox/common/image.rb +501 -0
  18. data/lib/cogbox/common/process.rb +150 -0
  19. data/lib/cogbox/common/pty.rb +310 -0
  20. data/lib/cogbox/common/resources.rb +40 -0
  21. data/lib/cogbox/common/response.rb +84 -0
  22. data/lib/cogbox/common/snapshot.rb +125 -0
  23. data/lib/cogbox/computer_use.rb +920 -0
  24. data/lib/cogbox/config.rb +110 -0
  25. data/lib/cogbox/file_system.rb +452 -0
  26. data/lib/cogbox/file_transfer.rb +384 -0
  27. data/lib/cogbox/git.rb +335 -0
  28. data/lib/cogbox/lsp_server.rb +140 -0
  29. data/lib/cogbox/object_storage.rb +173 -0
  30. data/lib/cogbox/otel.rb +184 -0
  31. data/lib/cogbox/process.rb +551 -0
  32. data/lib/cogbox/sandbox.rb +752 -0
  33. data/lib/cogbox/sdk/version.rb +11 -0
  34. data/lib/cogbox/sdk.rb +57 -0
  35. data/lib/cogbox/snapshot_service.rb +239 -0
  36. data/lib/cogbox/util.rb +81 -0
  37. data/lib/cogbox/volume.rb +47 -0
  38. data/lib/cogbox/volume_service.rb +62 -0
  39. data/lib/cogbox.rb +11 -0
  40. data/project.json +100 -0
  41. data/scripts/generate-docs.rb +403 -0
  42. data/sig/cogbox/sdk.rbs +6 -0
  43. metadata +240 -0
@@ -0,0 +1,125 @@
1
+ # Copyright Daytona Platforms Inc.
2
+ # Copyright Cognifyi
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # frozen_string_literal: true
6
+
7
+ module Cogbox
8
+ ChartElement = CogboxToolboxApiClient::ChartElement
9
+
10
+ module ChartType
11
+ LINE = 'line'
12
+ SCATTER = 'scatter'
13
+ BAR = 'bar'
14
+ PIE = 'pie'
15
+ BOX_AND_WHISKER = 'box_and_whisker'
16
+ COMPOSITE_CHART = 'composite_chart'
17
+ UNKNOWN = 'unknown'
18
+ end
19
+
20
+ PointData = Struct.new(:label, :points, keyword_init: true)
21
+ BarData = Struct.new(:label, :value, :group, keyword_init: true)
22
+ PieData = Struct.new(:label, :angle, :radius, keyword_init: true)
23
+ BoxAndWhiskerData = Struct.new(:label, :min, :first_quartile, :median, :third_quartile, :max, :outliers,
24
+ keyword_init: true)
25
+
26
+ Chart = Struct.new(:type, :title, :png, :elements, keyword_init: true) do
27
+ def initialize(type: nil, title: nil, png: nil, elements: [])
28
+ super
29
+ end
30
+ end
31
+
32
+ Chart2D = Struct.new(:type, :title, :png, :elements, :x_label, :y_label, keyword_init: true) do
33
+ def initialize(type: nil, title: nil, png: nil, elements: [], x_label: nil, y_label: nil)
34
+ super
35
+ end
36
+ end
37
+
38
+ PointChart = Struct.new(:type, :title, :png, :elements, :x_label, :y_label,
39
+ :x_ticks, :y_ticks, :x_tick_labels, :y_tick_labels,
40
+ :x_scale, :y_scale, keyword_init: true) do
41
+ def initialize(type: nil, title: nil, png: nil, elements: [], x_label: nil, y_label: nil,
42
+ x_ticks: nil, y_ticks: nil, x_tick_labels: nil, y_tick_labels: nil,
43
+ x_scale: nil, y_scale: nil)
44
+ super
45
+ end
46
+ end
47
+
48
+ class LineChart < PointChart
49
+ end
50
+
51
+ class ScatterChart < PointChart
52
+ end
53
+
54
+ class BarChart < Chart2D
55
+ end
56
+
57
+ class PieChart < Chart
58
+ end
59
+
60
+ class BoxAndWhiskerChart < Chart2D
61
+ end
62
+
63
+ class CompositeChart < Chart
64
+ end
65
+
66
+ module Charts
67
+ Chart = Cogbox::Chart
68
+ ChartElement = Cogbox::ChartElement
69
+ ChartType = Cogbox::ChartType
70
+ LineChart = Cogbox::LineChart
71
+ ScatterChart = Cogbox::ScatterChart
72
+ BarChart = Cogbox::BarChart
73
+ PieChart = Cogbox::PieChart
74
+ BoxAndWhiskerChart = Cogbox::BoxAndWhiskerChart
75
+ CompositeChart = Cogbox::CompositeChart
76
+ PointData = Cogbox::PointData
77
+ BarData = Cogbox::BarData
78
+ PieData = Cogbox::PieData
79
+ BoxAndWhiskerData = Cogbox::BoxAndWhiskerData
80
+
81
+ def self.parse_chart(chart)
82
+ type = chart.type || ChartType::UNKNOWN
83
+ elements = (chart.elements || []).map { |el| map_element(el, type) }
84
+ common = { type: chart.type, title: chart.title, png: chart.png, elements: elements }
85
+
86
+ case type
87
+ when ChartType::LINE
88
+ LineChart.new(x_label: chart.x_label, y_label: chart.y_label, x_ticks: chart.x_ticks, y_ticks: chart.y_ticks,
89
+ x_tick_labels: chart.x_tick_labels, y_tick_labels: chart.y_tick_labels,
90
+ x_scale: chart.x_scale, y_scale: chart.y_scale, **common)
91
+ when ChartType::SCATTER
92
+ ScatterChart.new(x_label: chart.x_label, y_label: chart.y_label, x_ticks: chart.x_ticks, y_ticks: chart.y_ticks,
93
+ x_tick_labels: chart.x_tick_labels, y_tick_labels: chart.y_tick_labels,
94
+ x_scale: chart.x_scale, y_scale: chart.y_scale, **common)
95
+ when ChartType::BAR
96
+ BarChart.new(x_label: chart.x_label, y_label: chart.y_label, **common)
97
+ when ChartType::PIE
98
+ PieChart.new(**common)
99
+ when ChartType::BOX_AND_WHISKER
100
+ BoxAndWhiskerChart.new(x_label: chart.x_label, y_label: chart.y_label, **common)
101
+ when ChartType::COMPOSITE_CHART
102
+ CompositeChart.new(**common)
103
+ else
104
+ Chart.new(**common)
105
+ end
106
+ end
107
+
108
+ def self.map_element(el, chart_type)
109
+ case chart_type
110
+ when ChartType::LINE, ChartType::SCATTER
111
+ PointData.new(label: el.label, points: el.points)
112
+ when ChartType::BAR
113
+ BarData.new(label: el.label, value: el.value, group: el.group)
114
+ when ChartType::PIE
115
+ PieData.new(label: el.label, angle: el.angle, radius: el.radius)
116
+ when ChartType::BOX_AND_WHISKER
117
+ BoxAndWhiskerData.new(label: el.label, min: el.min, first_quartile: el.first_quartile,
118
+ median: el.median, third_quartile: el.third_quartile,
119
+ max: el.max, outliers: el.outliers)
120
+ else
121
+ el
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,57 @@
1
+ # Copyright Daytona Platforms Inc.
2
+ # Copyright Cognifyi
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # frozen_string_literal: true
6
+
7
+ module Cogbox
8
+ # Represents stdout or stderr output from code execution
9
+ class OutputMessage
10
+ # @return [String] The output content
11
+ attr_reader :output
12
+
13
+ # @param output [String]
14
+ def initialize(output:)
15
+ @output = output
16
+ end
17
+ end
18
+
19
+ # Represents an error that occurred during code execution
20
+ class ExecutionError
21
+ # @return [String] The error type/class name (e.g., "ValueError", "SyntaxError")
22
+ attr_reader :name
23
+
24
+ # @return [String] The error value
25
+ attr_reader :value
26
+
27
+ # @return [String] Full traceback of the error
28
+ attr_reader :traceback
29
+
30
+ # @param name [String]
31
+ # @param value [String]
32
+ # @param traceback [String]
33
+ def initialize(name:, value:, traceback: '')
34
+ @name = name
35
+ @value = value
36
+ @traceback = traceback
37
+ end
38
+ end
39
+
40
+ # Result of code execution
41
+ class ExecutionResult
42
+ # @return [String] Standard output from the code execution
43
+ attr_accessor :stdout
44
+
45
+ # @return [String] Standard error output from the code execution
46
+ attr_accessor :stderr
47
+
48
+ # @return [ExecutionError, nil] Error details if execution failed, nil otherwise
49
+ attr_accessor :error
50
+
51
+ def initialize(stdout: '', stderr: '', error: nil)
52
+ @stdout = stdout
53
+ @stderr = stderr
54
+ @error = error
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,15 @@
1
+ # Copyright Daytona Platforms Inc.
2
+ # Copyright Cognifyi
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # frozen_string_literal: true
6
+
7
+ module Cogbox
8
+ module CodeLanguage
9
+ ALL = [
10
+ JAVASCRIPT = :javascript,
11
+ PYTHON = :python,
12
+ TYPESCRIPT = :typescript
13
+ ].freeze
14
+ end
15
+ end
@@ -0,0 +1,231 @@
1
+ # Copyright Daytona Platforms Inc.
2
+ # Copyright Cognifyi
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # frozen_string_literal: true
6
+
7
+ module Cogbox
8
+ CODE_TOOLBOX_LANGUAGE_LABEL = 'code-toolbox-language'
9
+
10
+ class CreateSandboxBaseParams
11
+ # @return [Symbol, nil] Programming language for the Sandbox
12
+ attr_accessor :language
13
+
14
+ # @return [String, nil] OS user for the Sandbox
15
+ attr_accessor :os_user
16
+
17
+ # @return [Hash<String, String>, nil] Environment variables to set in the Sandbox
18
+ attr_accessor :env_vars
19
+
20
+ # @return [Hash<String, String>, nil] Custom labels for the Sandbox
21
+ attr_accessor :labels
22
+
23
+ # @return [Boolean, nil] Whether the Sandbox should be public
24
+ attr_accessor :public
25
+
26
+ # @return [Float, nil] Timeout in seconds for Sandbox to be created and started
27
+ attr_accessor :timeout
28
+
29
+ # @return [Integer, nil] Auto-stop interval in minutes
30
+ attr_accessor :auto_stop_interval
31
+
32
+ # @return [Integer, nil] Auto-archive interval in minutes
33
+ attr_accessor :auto_archive_interval
34
+
35
+ # @return [Integer, nil] Auto-delete interval in minutes
36
+ attr_accessor :auto_delete_interval
37
+
38
+ # @return [Array<CogboxApiClient::SandboxVolume>, nil] List of volumes mounts to attach to the Sandbox
39
+ attr_accessor :volumes
40
+
41
+ # @return [Boolean, nil] Whether to block all network access for the Sandbox
42
+ attr_accessor :network_block_all
43
+
44
+ # @return [String, nil] Comma-separated list of allowed CIDR network addresses for the Sandbox
45
+ attr_accessor :network_allow_list
46
+
47
+ # @return [String, nil] Comma-separated list of allowed domains for the Sandbox
48
+ attr_accessor :domain_allow_list
49
+
50
+ # @return [Boolean, nil] Whether the Sandbox should be ephemeral
51
+ attr_accessor :ephemeral
52
+
53
+ # @return [String, nil] ID or name of an existing Sandbox to link the new Sandbox to. The new
54
+ # Sandbox will be scheduled on the same runner as the linked Sandbox so a local network can be
55
+ # established between them. Linked Sandboxes must be
56
+ # ephemeral (auto_delete_interval=0) and cannot themselves be linked to another Sandbox.
57
+ attr_accessor :linked_sandbox
58
+
59
+ # Initialize CreateSandboxBaseParams
60
+ #
61
+ # @param language [Symbol, nil] Programming language for the Sandbox
62
+ # @param os_user [String, nil] OS user for the Sandbox
63
+ # @param env_vars [Hash<String, String>, nil] Environment variables to set in the Sandbox
64
+ # @param labels [Hash<String, String>, nil] Custom labels for the Sandbox
65
+ # @param public [Boolean, nil] Whether the Sandbox should be public
66
+ # @param timeout [Float, nil] Timeout in seconds for Sandbox to be created and started
67
+ # @param auto_stop_interval [Integer, nil] Auto-stop interval in minutes
68
+ # @param auto_archive_interval [Integer, nil] Auto-archive interval in minutes
69
+ # @param auto_delete_interval [Integer, nil] Auto-delete interval in minutes
70
+ # @param volumes [Array<CogboxApiClient::SandboxVolume>, nil] List of volumes mounts to attach to the Sandbox
71
+ # @param network_block_all [Boolean, nil] Whether to block all network access for the Sandbox
72
+ # @param network_allow_list [String, nil] Comma-separated list of allowed CIDR network addresses for the Sandbox
73
+ # @param domain_allow_list [String, nil] Comma-separated list of allowed domains for the Sandbox
74
+ # @param ephemeral [Boolean, nil] Whether the Sandbox should be ephemeral
75
+ # @param linked_sandbox [String, nil] ID or name of an existing Sandbox to link the new Sandbox to
76
+ def initialize( # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
77
+ language: nil,
78
+ os_user: nil,
79
+ env_vars: nil,
80
+ labels: nil,
81
+ public: nil,
82
+ timeout: nil,
83
+ auto_stop_interval: nil,
84
+ auto_archive_interval: nil,
85
+ auto_delete_interval: nil,
86
+ volumes: nil,
87
+ network_block_all: nil,
88
+ network_allow_list: nil,
89
+ domain_allow_list: nil,
90
+ ephemeral: nil,
91
+ linked_sandbox: nil
92
+ )
93
+ @language = language
94
+ @os_user = os_user
95
+ @env_vars = env_vars
96
+ @labels = labels
97
+ @public = public
98
+ @timeout = timeout
99
+ @auto_stop_interval = auto_stop_interval
100
+ @auto_archive_interval = auto_archive_interval
101
+ @auto_delete_interval = auto_delete_interval
102
+ @volumes = volumes
103
+ @network_block_all = network_block_all
104
+ @network_allow_list = network_allow_list
105
+ @domain_allow_list = domain_allow_list
106
+ @ephemeral = ephemeral
107
+ @linked_sandbox = linked_sandbox
108
+
109
+ # Handle ephemeral and auto_delete_interval conflict
110
+ handle_ephemeral_auto_delete_conflict
111
+ end
112
+
113
+ # Convert to hash representation
114
+ #
115
+ # @return [Hash<Symbol, Object>] Hash representation of the parameters
116
+ def to_h # rubocop:disable Metrics/MethodLength
117
+ {
118
+ language:,
119
+ os_user:,
120
+ env_vars:,
121
+ labels:,
122
+ public:,
123
+ timeout:,
124
+ auto_stop_interval:,
125
+ auto_archive_interval:,
126
+ auto_delete_interval:,
127
+ volumes:,
128
+ network_block_all:,
129
+ network_allow_list:,
130
+ domain_allow_list:,
131
+ ephemeral:,
132
+ linked_sandbox:
133
+ }.compact
134
+ end
135
+
136
+ private
137
+
138
+ # Handle the conflict between ephemeral and auto_delete_interval
139
+ #
140
+ # @return [void]
141
+ def handle_ephemeral_auto_delete_conflict
142
+ return unless ephemeral && auto_delete_interval && !auto_delete_interval.zero?
143
+
144
+ warn(
145
+ "'ephemeral' and 'auto_delete_interval' cannot be used together. " \
146
+ 'If ephemeral is true, auto_delete_interval will be ignored and set to 0.'
147
+ )
148
+ @auto_delete_interval = 0
149
+ end
150
+ end
151
+
152
+ class CreateSandboxFromImageParams < CreateSandboxBaseParams
153
+ # @return [String, Image] Custom Docker image to use for the Sandbox. If an Image object is provided,
154
+ # the image will be dynamically built.
155
+ attr_accessor :image
156
+
157
+ # @return [Cogbox::Resources, nil] Resource configuration for the Sandbox. If not provided, sandbox will
158
+ # have default resources.
159
+ attr_accessor :resources
160
+
161
+ # Initialize CreateSandboxFromImageParams
162
+ #
163
+ # @param image [String, Image] Custom Docker image to use for the Sandbox
164
+ # @param resources [Cogbox::Resources, nil] Resource configuration for the Sandbox
165
+ # @param language [Symbol, nil] Programming language for the Sandbox
166
+ # @param os_user [String, nil] OS user for the Sandbox
167
+ # @param env_vars [Hash<String, String>, nil] Environment variables to set in the Sandbox
168
+ # @param labels [Hash<String, String>, nil] Custom labels for the Sandbox
169
+ # @param public [Boolean, nil] Whether the Sandbox should be public
170
+ # @param timeout [Float, nil] Timeout in seconds for Sandbox to be created and started
171
+ # @param auto_stop_interval [Integer, nil] Auto-stop interval in minutes
172
+ # @param auto_archive_interval [Integer, nil] Auto-archive interval in minutes
173
+ # @param auto_delete_interval [Integer, nil] Auto-delete interval in minutes
174
+ # @param volumes [Array<CogboxApiClient::SandboxVolume>, nil] List of volumes mounts to attach to the Sandbox
175
+ # @param network_block_all [Boolean, nil] Whether to block all network access for the Sandbox
176
+ # @param network_allow_list [String, nil] Comma-separated list of allowed CIDR network addresses for the Sandbox
177
+ # @param domain_allow_list [String, nil] Comma-separated list of allowed domains for the Sandbox
178
+ # @param ephemeral [Boolean, nil] Whether the Sandbox should be ephemeral
179
+ def initialize(image:, resources: nil, **args)
180
+ @image = image
181
+ @resources = resources
182
+
183
+ super(**args)
184
+ end
185
+
186
+ # Convert to hash representation
187
+ #
188
+ # @return [Hash<Symbol, Object>] Hash representation of the parameters
189
+ def to_h
190
+ super.merge(
191
+ image:,
192
+ resources: resources&.to_h
193
+ ).compact
194
+ end
195
+ end
196
+
197
+ class CreateSandboxFromSnapshotParams < CreateSandboxBaseParams
198
+ # @return [String, nil] Name of the snapshot to use for the Sandbox
199
+ attr_accessor :snapshot
200
+
201
+ # Initialize CreateSandboxFromSnapshotParams
202
+ #
203
+ # @param snapshot [String, nil] Name of the snapshot to use for the Sandbox
204
+ # @param language [Symbol, nil] Programming language for the Sandbox
205
+ # @param os_user [String, nil] OS user for the Sandbox
206
+ # @param env_vars [Hash<String, String>, nil] Environment variables to set in the Sandbox
207
+ # @param labels [Hash<String, String>, nil] Custom labels for the Sandbox
208
+ # @param public [Boolean, nil] Whether the Sandbox should be public
209
+ # @param timeout [Float, nil] Timeout in seconds for Sandbox to be created and started
210
+ # @param auto_stop_interval [Integer, nil] Auto-stop interval in minutes
211
+ # @param auto_archive_interval [Integer, nil] Auto-archive interval in minutes
212
+ # @param auto_delete_interval [Integer, nil] Auto-delete interval in minutes
213
+ # @param volumes [Array<CogboxApiClient::SandboxVolume>, nil] List of volumes mounts to attach to the Sandbox
214
+ # @param network_block_all [Boolean, nil] Whether to block all network access for the Sandbox
215
+ # @param network_allow_list [String, nil] Comma-separated list of allowed CIDR network addresses for the Sandbox
216
+ # @param domain_allow_list [String, nil] Comma-separated list of allowed domains for the Sandbox
217
+ # @param ephemeral [Boolean, nil] Whether the Sandbox should be ephemeral
218
+ def initialize(snapshot: nil, **args)
219
+ @snapshot = snapshot
220
+
221
+ super(**args)
222
+ end
223
+
224
+ # Convert to hash representation
225
+ #
226
+ # @return [Hash<Symbol, Object>] Hash representation of the parameters
227
+ def to_h
228
+ super.merge(snapshot:).compact
229
+ end
230
+ end
231
+ end
@@ -0,0 +1,27 @@
1
+ # Copyright Daytona Platforms Inc.
2
+ # Copyright Cognifyi
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # frozen_string_literal: true
6
+
7
+ module Cogbox
8
+ class FileUpload
9
+ # @return [String, IO] File contents as a string/bytes object or a local file path or IO object.
10
+ # If a string path is provided, the file content will be read from disk.
11
+ # If a string content is provided, make sure it fits into memory.
12
+ attr_reader :source
13
+
14
+ # @return [String] Absolute destination path in the Sandbox. Relative paths are resolved based on
15
+ # the sandbox working directory.
16
+ attr_reader :destination
17
+
18
+ # Initializes a new FileUpload instance.
19
+ #
20
+ # @param source [String, IO] File contents as a string/bytes object or a local file path or IO object.
21
+ # @param destination [String] Absolute destination path in the Sandbox.
22
+ def initialize(source, destination)
23
+ @source = source
24
+ @destination = destination
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ # Copyright Daytona Platforms Inc.
2
+ # Copyright Cognifyi
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # frozen_string_literal: true
6
+
7
+ module Cogbox
8
+ # Response from the git commit.
9
+ class GitCommitResponse
10
+ # @return [String] The SHA of the commit
11
+ attr_reader :sha
12
+
13
+ # Initialize a new GitCommitResponse
14
+ #
15
+ # @param sha [String] The SHA of the commit
16
+ def initialize(sha:)
17
+ @sha = sha
18
+ end
19
+ end
20
+ end