daytona 0.164.0 → 0.167.0.alpha.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce668bd56c2b7767f624eb0bbb347ed6144cc40782d8d27a857783a82448ae60
4
- data.tar.gz: 6587e4186ff8ee24dbf55acb5be580d71c507b8bb1d76acf9badc891778e8630
3
+ metadata.gz: a9b70911a632518aefb458889b450d58d12b024ee796155bb39f980bafb4b576
4
+ data.tar.gz: 24f4791337a7418f2269e1560eaeba72ffec7899dcbf321d2367cc6ec3857886
5
5
  SHA512:
6
- metadata.gz: 8f561638b39e7cf53f5d3488ba592a3ccbd93a395ba85e5622ee7c9b7ba909dd34235ccad5947ed5565d2c116c0c7d8fe78e51f7547936839705a2b9824a2474
7
- data.tar.gz: dbf8ffab3facea88678ad36b8a8af77d8bd73087ed3c1fcf8cbe5aef11a3bd85924467227f7b0c58b90ac3540da82086dbb0cb3345be55b7677797b939cf2f85
6
+ metadata.gz: 596015b011c0efc5d1235e7b5a2a06e721d69d746541344043df8bf6ea049cfd7f584e7df63bc3b14e06e39d2c387b00334fe74c0bf5b2b351c12fe7985ab984
7
+ data.tar.gz: a016a6509ffe4436885290ea6174e8a37af602a53e454f2fe7c589921af8f95ee32de0879f831a509d81dc26c3eedcc38ab88fd283c9cdfd572b9e36fa318478
@@ -1,298 +1,121 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Daytona
4
- module Charts
5
- # @param data [Hash<Symbol, Object>]
6
- # @return [Daytona::Charts::Chart]
7
- def self.parse(data)
8
- case data.fetch(:type, ChartType::UNKNOWN)
9
- when ChartType::LINE then LineChart.new(data)
10
- when ChartType::SCATTER then ScatterChart.new(data)
11
- when ChartType::BAR then BarChart.new(data)
12
- when ChartType::PIE then PieChart.new(data)
13
- when ChartType::BOX_AND_WHISKER then BoxAndWhiskerChart.new(data)
14
- when ChartType::COMPOSITE_CHART then CompositeChart.new(data)
15
- else
16
- Chart.new(data)
17
- end
18
- end
19
-
20
- class Chart
21
- # @return [String, Nil] The type of chart
22
- attr_reader :type
23
-
24
- # @return [String, Nil] The title of the chart
25
- attr_reader :title
26
-
27
- # @return [Array<Object>] The elements of the chart
28
- attr_reader :elements
29
-
30
- # @return [String, Nil] The PNG representation of the chart encoded in base64
31
- attr_reader :png
32
-
33
- # @param data [Hash<Symbol, Object>]
34
- def initialize(data)
35
- @type = data.fetch(:type, nil)
36
- @title = data.fetch(:title, nil)
37
- @elements = data.fetch(:elements, [])
38
- @png = data.fetch(:png, nil)
39
- end
40
-
41
- # @return [Hash<Symbol, Object>] original metadata
42
- def to_h = { type:, title:, elements:, png: }
43
- end
44
-
45
- class Chart2D < Chart
46
- # @return [String, Nil] The label of the x-axis
47
- attr_reader :x_label
48
-
49
- # @return [String, Nil] The label of the y-axis
50
- attr_reader :y_label
51
-
52
- # @param data [Hash<Symbol, Object>]
53
- def initialize(data)
54
- super
55
- @x_label = data.fetch(:x_label, nil)
56
- @y_label = data.fetch(:y_label, nil)
57
- end
58
-
59
- # @return [Hash<Symbol, Object>] original metadata
60
- def to_h = super.merge(x_label:, y_label:)
61
- end
62
-
63
- class PointData
64
- # @return [String] The label of the point series
65
- attr_reader :label
66
-
67
- # @return [Array<Array<Object>>] Array of [x, y] points
68
- attr_reader :points
69
-
70
- # @param data [Hash<Symbol, Object>]
71
- def initialize(data)
72
- @label = data.fetch(:label)
73
- @points = data.fetch(:points)
74
- end
75
-
76
- # @return [Hash<Symbol, Object>] original data representation
77
- def to_h = { label:, points: }
78
- end
79
-
80
- class PointChart < Chart2D
81
- # @return [Array<Object>] The ticks of the x-axis
82
- attr_reader :x_ticks
83
-
84
- # @return [Array<String>] The labels of the x-axis
85
- attr_reader :x_tick_labels
86
-
87
- # @return [String, Nil] The scale of the x-axis
88
- attr_reader :x_scale
89
-
90
- # @return [Array<Object>] The ticks of the y-axis
91
- attr_reader :y_ticks
92
-
93
- # @return [Array<String>] The labels of the y-axis
94
- attr_reader :y_tick_labels
95
-
96
- # @return [String, Nil] The scale of the y-axis
97
- attr_reader :y_scale
98
-
99
- # @return [Array<Daytona::Charts::PointData>] The points of the chart
100
- attr_reader :elements
101
-
102
- # @param data [Hash<Symbol, Object>]
103
- def initialize(data)
104
- super
105
- @x_scale = data.fetch(:x_scale, nil)
106
- @x_ticks = data.fetch(:x_ticks, nil)
107
- @x_tick_labels = data.fetch(:x_tick_labels, nil)
108
-
109
- @y_scale = data.fetch(:y_scale, nil)
110
- @y_ticks = data.fetch(:y_ticks, nil)
111
- @y_tick_labels = data.fetch(:y_tick_labels, nil)
112
-
113
- @elements = data.fetch(:elements, []).map { |e| PointData.new(e) }
114
- end
115
-
116
- # @return [Hash<Symbol, Object>] original metadata
117
- def to_h
118
- super.merge(
119
- x_scale:,
120
- x_ticks:,
121
- x_tick_labels:,
122
- y_scale:,
123
- y_ticks:,
124
- y_tick_labels:,
125
- elements: elements.map(&:to_h)
126
- )
127
- end
128
- end
129
-
130
- class LineChart < PointChart
131
- def initialize(data)
132
- super
133
- @type = ChartType::LINE
134
- end
135
- end
136
-
137
- class ScatterChart < PointChart
138
- def initialize(data)
139
- super
140
- @type = ChartType::SCATTER
141
- end
142
- end
143
-
144
- class BarData
145
- # @return [String] The label of the bar
146
- attr_reader :label
147
-
148
- # @return [String] The value of the bar
149
- attr_reader :value
150
-
151
- # @return [String] The group of the bar
152
- attr_reader :group
153
-
154
- # @param data [Hash<Symbol, Object>]
155
- def initialize(data)
156
- @label = data.fetch(:label)
157
- @value = data.fetch(:value)
158
- @group = data.fetch(:group)
159
- end
160
-
161
- # @return [Hash<Symbol, Object>]
162
- def to_h = { label:, value:, group: }
163
- end
164
-
165
- class BarChart < Chart2D
166
- # @return [Array<Daytona::Charts::BarData>] The bars of the chart
167
- attr_reader :elements
4
+ ChartElement = DaytonaToolboxApiClient::ChartElement
5
+
6
+ module ChartType
7
+ LINE = 'line'
8
+ SCATTER = 'scatter'
9
+ BAR = 'bar'
10
+ PIE = 'pie'
11
+ BOX_AND_WHISKER = 'box_and_whisker'
12
+ COMPOSITE_CHART = 'composite_chart'
13
+ UNKNOWN = 'unknown'
14
+ end
168
15
 
169
- # @param data [Hash<Symbol, Object>]
170
- def initialize(data)
171
- super
172
- @type = ChartType::BAR
173
- @elements = data.fetch(:elements, []).map { |e| BarData.new(e) }
174
- end
16
+ PointData = Struct.new(:label, :points, keyword_init: true)
17
+ BarData = Struct.new(:label, :value, :group, keyword_init: true)
18
+ PieData = Struct.new(:label, :angle, :radius, keyword_init: true)
19
+ BoxAndWhiskerData = Struct.new(:label, :min, :first_quartile, :median, :third_quartile, :max, :outliers,
20
+ keyword_init: true)
175
21
 
176
- # @return [Hash<Symbol, Object>]
177
- def to_h = super.merge(elements: elements.map(&:to_h))
22
+ Chart = Struct.new(:type, :title, :png, :elements, keyword_init: true) do
23
+ def initialize(type: nil, title: nil, png: nil, elements: [])
24
+ super
178
25
  end
26
+ end
179
27
 
180
- class PieData
181
- # @return [String] The label of the pie slice
182
- attr_reader :label
183
-
184
- # @return [Float] The angle of the pie slice
185
- attr_reader :angle
186
-
187
- # @return [Float] The radius of the pie slice
188
- attr_reader :radius
189
-
190
- # @return [Float] The autopct value of the pie slice
191
- attr_reader :autopct
192
-
193
- # @param data [Hash<Symbol, Object>]
194
- def initialize(data)
195
- @label = data.fetch(:label)
196
- @angle = data.fetch(:angle)
197
- @radius = data.fetch(:radius)
198
- @autopct = data.fetch(:autopct)
199
- end
200
-
201
- # @return [Hash<Symbol, Object>]
202
- def to_h = { label:, angle:, radius:, autopct: }
28
+ Chart2D = Struct.new(:type, :title, :png, :elements, :x_label, :y_label, keyword_init: true) do
29
+ def initialize(type: nil, title: nil, png: nil, elements: [], x_label: nil, y_label: nil)
30
+ super
203
31
  end
32
+ end
204
33
 
205
- class PieChart < Chart
206
- # @return [Array<Daytona::Charts::PieData>] The pie slices of the chart
207
- attr_reader :elements
208
-
209
- # @param data [Hash<Symbol, Object>]
210
- def initialize(data)
211
- super
212
- @type = ChartType::PIE
213
- @elements = data.fetch(:elements, []).map { |e| PieData.new(e) }
214
- end
215
-
216
- # @return [Hash<Symbol, Object>]
217
- def to_h = super.merge(elements: elements.map(&:to_h))
34
+ PointChart = Struct.new(:type, :title, :png, :elements, :x_label, :y_label,
35
+ :x_ticks, :y_ticks, :x_tick_labels, :y_tick_labels,
36
+ :x_scale, :y_scale, keyword_init: true) do
37
+ def initialize(type: nil, title: nil, png: nil, elements: [], x_label: nil, y_label: nil,
38
+ x_ticks: nil, y_ticks: nil, x_tick_labels: nil, y_tick_labels: nil,
39
+ x_scale: nil, y_scale: nil)
40
+ super
218
41
  end
42
+ end
219
43
 
220
- class BoxAndWhiskerData
221
- # @return [String] The label of the box and whisker
222
- attr_reader :label
223
-
224
- # @return [Float] The minimum value of the box and whisker
225
- attr_reader :min
226
-
227
- # @return [Float] The first quartile of the box and whisker
228
- attr_reader :first_quartile
229
-
230
- # @return [Float] The median of the box and whisker
231
- attr_reader :median
232
-
233
- # @return [Float] The third quartile of the box and whisker
234
- attr_reader :third_quartile
44
+ class LineChart < PointChart
45
+ end
235
46
 
236
- # @return [Float] The maximum value of the box and whisker
237
- attr_reader :max
47
+ class ScatterChart < PointChart
48
+ end
238
49
 
239
- # @return [Array<Float>] The outliers of the box and whisker
240
- attr_reader :outliers
50
+ class BarChart < Chart2D
51
+ end
241
52
 
242
- # @param data [Hash<Symbol, Object>]
243
- def initialize(data)
244
- @label = data.fetch(:label)
245
- @min = data.fetch(:min)
246
- @first_quartile = data.fetch(:first_quartile)
247
- @median = data.fetch(:median)
248
- @third_quartile = data.fetch(:third_quartile)
249
- @max = data.fetch(:max)
250
- @outliers = data.fetch(:outliers, [])
251
- end
53
+ class PieChart < Chart
54
+ end
252
55
 
253
- # @return [Hash<Symbol, Object>]
254
- def to_h = { label:, min:, first_quartile:, median:, third_quartile:, max:, outliers: }
255
- end
56
+ class BoxAndWhiskerChart < Chart2D
57
+ end
256
58
 
257
- class BoxAndWhiskerChart < Chart2D
258
- # @return [Array<Daytona::Charts::BoxAndWhiskerData>] The box and whiskers of the chart
259
- attr_reader :elements
59
+ class CompositeChart < Chart
60
+ end
260
61
 
261
- # @param data [Hash<Symbol, Object>]
262
- def initialize(data)
263
- super
264
- @type = ChartType::BOX_AND_WHISKER
265
- @elements = data.fetch(:elements, []).map { |e| BoxAndWhiskerData.new(e) }
62
+ module Charts
63
+ Chart = Daytona::Chart
64
+ ChartElement = Daytona::ChartElement
65
+ ChartType = Daytona::ChartType
66
+ LineChart = Daytona::LineChart
67
+ ScatterChart = Daytona::ScatterChart
68
+ BarChart = Daytona::BarChart
69
+ PieChart = Daytona::PieChart
70
+ BoxAndWhiskerChart = Daytona::BoxAndWhiskerChart
71
+ CompositeChart = Daytona::CompositeChart
72
+ PointData = Daytona::PointData
73
+ BarData = Daytona::BarData
74
+ PieData = Daytona::PieData
75
+ BoxAndWhiskerData = Daytona::BoxAndWhiskerData
76
+
77
+ def self.parse_chart(chart)
78
+ type = chart.type || ChartType::UNKNOWN
79
+ elements = (chart.elements || []).map { |el| map_element(el, type) }
80
+ common = { type: chart.type, title: chart.title, png: chart.png, elements: elements }
81
+
82
+ case type
83
+ when ChartType::LINE
84
+ LineChart.new(x_label: chart.x_label, y_label: chart.y_label, x_ticks: chart.x_ticks, y_ticks: chart.y_ticks,
85
+ x_tick_labels: chart.x_tick_labels, y_tick_labels: chart.y_tick_labels,
86
+ x_scale: chart.x_scale, y_scale: chart.y_scale, **common)
87
+ when ChartType::SCATTER
88
+ ScatterChart.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::BAR
92
+ BarChart.new(x_label: chart.x_label, y_label: chart.y_label, **common)
93
+ when ChartType::PIE
94
+ PieChart.new(**common)
95
+ when ChartType::BOX_AND_WHISKER
96
+ BoxAndWhiskerChart.new(x_label: chart.x_label, y_label: chart.y_label, **common)
97
+ when ChartType::COMPOSITE_CHART
98
+ CompositeChart.new(**common)
99
+ else
100
+ Chart.new(**common)
266
101
  end
267
-
268
- # @return [Hash<Symbol, Object>]
269
- def to_h = super.merge(elements: elements.map(&:to_h))
270
102
  end
271
103
 
272
- class CompositeChart < Chart
273
- # @return [Array<Daytona::Charts::Chart>] The charts of the composite chart
274
- attr_reader :elements
275
-
276
- # @param data [Hash<Symbol, Object>]
277
- def initialize(data)
278
- super
279
- @type = ChartType::COMPOSITE_CHART
280
- @elements = data.fetch(:elements, []).map { |e| Charts.parse(e) }
104
+ def self.map_element(el, chart_type)
105
+ case chart_type
106
+ when ChartType::LINE, ChartType::SCATTER
107
+ PointData.new(label: el.label, points: el.points)
108
+ when ChartType::BAR
109
+ BarData.new(label: el.label, value: el.value, group: el.group)
110
+ when ChartType::PIE
111
+ PieData.new(label: el.label, angle: el.angle, radius: el.radius)
112
+ when ChartType::BOX_AND_WHISKER
113
+ BoxAndWhiskerData.new(label: el.label, min: el.min, first_quartile: el.first_quartile,
114
+ median: el.median, third_quartile: el.third_quartile,
115
+ max: el.max, outliers: el.outliers)
116
+ else
117
+ el
281
118
  end
282
-
283
- def to_h = super.merge(elements: elements.map(&:to_h))
284
- end
285
-
286
- module ChartType
287
- ALL = [
288
- LINE = 'line',
289
- SCATTER = 'scatter',
290
- BAR = 'bar',
291
- PIE = 'pie',
292
- BOX_AND_WHISKER = 'box_and_whisker',
293
- COMPOSITE_CHART = 'composite_chart',
294
- UNKNOWN = 'unknown'
295
- ].freeze
296
119
  end
297
120
  end
298
121
  end
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Daytona
4
+ CODE_TOOLBOX_LANGUAGE_LABEL = 'code-toolbox-language'
5
+
4
6
  class CreateSandboxBaseParams
5
7
  # @return [Symbol, nil] Programming language for the Sandbox
6
8
  attr_accessor :language
@@ -66,6 +66,11 @@ module Daytona
66
66
  params.language = CodeLanguage::PYTHON
67
67
  end
68
68
 
69
+ unless CodeLanguage::ALL.include?(params.language.to_s.to_sym)
70
+ raise ArgumentError,
71
+ "Invalid #{CODE_TOOLBOX_LANGUAGE_LABEL}: #{params.language}. Supported languages: #{CodeLanguage::ALL.join(', ')}"
72
+ end
73
+
69
74
  _create(params, on_snapshot_create_logs:)
70
75
  end
71
76
 
@@ -81,7 +86,7 @@ module Daytona
81
86
  # @return [Daytona::Sandbox]
82
87
  def get(id)
83
88
  sandbox_dto = sandbox_api.get_sandbox(id)
84
- to_sandbox(sandbox_dto:, code_toolbox: code_toolbox_from_labels(sandbox_dto.labels))
89
+ to_sandbox(sandbox_dto:)
85
90
  end
86
91
 
87
92
  # Lists Sandboxes filtered by labels.
@@ -102,10 +107,8 @@ module Daytona
102
107
  total: response.total,
103
108
  page: response.page,
104
109
  total_pages: response.total_pages,
105
- items: response
106
- .items
107
- .map do |sandbox_dto|
108
- to_sandbox(sandbox_dto:, code_toolbox: code_toolbox_from_labels(sandbox_dto.labels))
110
+ items: response.items.map do |sandbox_dto|
111
+ to_sandbox(sandbox_dto:)
109
112
  end
110
113
  )
111
114
  end
@@ -150,7 +153,7 @@ module Daytona
150
153
  end
151
154
 
152
155
  labels = params.labels&.dup || {}
153
- labels[LABEL_CODE_TOOLBOX_LANGUAGE] = params.language.to_s if params.language
156
+ labels[CODE_TOOLBOX_LANGUAGE_LABEL] = params.language.to_s if params.language
154
157
 
155
158
  create_sandbox = DaytonaApiClient::CreateSandbox.new(
156
159
  user: params.os_user,
@@ -204,7 +207,7 @@ module Daytona
204
207
  Util.stream_async(uri:, headers:, on_chunk: on_snapshot_create_logs)
205
208
  end
206
209
 
207
- sandbox = to_sandbox(sandbox_dto: response, code_toolbox: code_toolbox_from_labels(response.labels))
210
+ sandbox = to_sandbox(sandbox_dto: response)
208
211
 
209
212
  if sandbox.state != DaytonaApiClient::SandboxState::STARTED
210
213
  sandbox.wait_for_sandbox_start([0.001, timeout - (Time.now - start_time)].max)
@@ -246,42 +249,16 @@ module Daytona
246
249
  end
247
250
 
248
251
  # @param sandbox_dto [DaytonaApiClient::Sandbox]
249
- # @param code_toolbox [Daytona::SandboxPythonCodeToolbox, Daytona::SandboxTsCodeToolbox]
250
252
  # @return [Daytona::Sandbox]
251
- def to_sandbox(sandbox_dto:, code_toolbox:)
253
+ def to_sandbox(sandbox_dto:)
252
254
  Sandbox.new(
253
255
  sandbox_dto:,
254
256
  config:,
255
257
  sandbox_api:,
256
- code_toolbox:,
257
258
  otel_state: @otel_state
258
259
  )
259
260
  end
260
261
 
261
- # Converts a language to a code toolbox
262
- #
263
- # @param language [Symbol]
264
- # @return [Daytona::CodeToolbox]
265
- # @raise [Daytona::Sdk::Error] If the language is not supported
266
- def code_toolbox_from_language(language)
267
- case language
268
- when CodeLanguage::PYTHON, nil
269
- SandboxPythonCodeToolbox.new
270
- when SandboxTsCodeToolbox, CodeLanguage::TYPESCRIPT
271
- SandboxTsCodeToolbox.new
272
- when CodeLanguage::JAVASCRIPT
273
- SandboxJsCodeToolbox.new
274
- else
275
- raise Sdk::Error, "Unsupported language: #{language}"
276
- end
277
- end
278
-
279
- # Get code toolbox from Sandbox labels
280
- #
281
- # @param labels [Hash<String, String>]
282
- # @return [Daytona::CodeToolbox]
283
- def code_toolbox_from_labels(labels) = code_toolbox_from_language(labels[LABEL_CODE_TOOLBOX_LANGUAGE]&.to_sym)
284
-
285
262
  SOURCE_RUBY = 'sdk-ruby'
286
263
  private_constant :SOURCE_RUBY
287
264
 
@@ -293,8 +270,5 @@ module Daytona
293
270
 
294
271
  HEADER_ORGANIZATION_ID = 'X-Daytona-Organization-ID'
295
272
  private_constant :HEADER_ORGANIZATION_ID
296
-
297
- LABEL_CODE_TOOLBOX_LANGUAGE = 'code-toolbox-language'
298
- private_constant :LABEL_CODE_TOOLBOX_LANGUAGE
299
273
  end
300
274
  end