daytona 0.200.0 → 0.201.0
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 +4 -4
- data/lib/daytona/code_interpreter.rb +6 -6
- data/lib/daytona/common/event_subscription_manager.rb +110 -60
- data/lib/daytona/common/response.rb +2 -0
- data/lib/daytona/computer_use.rb +62 -62
- data/lib/daytona/daytona.rb +9 -0
- data/lib/daytona/file_system.rb +36 -28
- data/lib/daytona/git.rb +21 -31
- data/lib/daytona/lsp_server.rb +20 -2
- data/lib/daytona/object_storage.rb +2 -5
- data/lib/daytona/process.rb +44 -4
- data/lib/daytona/sandbox.rb +93 -9
- data/lib/daytona/sdk/deprecated.rb +18 -0
- data/lib/daytona/sdk/errors.rb +279 -0
- data/lib/daytona/sdk/file_download_patch.rb +131 -0
- data/lib/daytona/sdk/version.rb +1 -1
- data/lib/daytona/sdk.rb +7 -9
- data/lib/daytona/snapshot_service.rb +2 -1
- data/lib/daytona/utils/file_url_signing.rb +56 -0
- metadata +19 -9
data/lib/daytona/file_system.rb
CHANGED
|
@@ -46,8 +46,8 @@ module Daytona
|
|
|
46
46
|
def create_folder(path, mode)
|
|
47
47
|
Sdk.logger.debug("Creating folder #{path} with mode #{mode}")
|
|
48
48
|
toolbox_api.create_folder(path, mode)
|
|
49
|
-
rescue
|
|
50
|
-
raise Sdk
|
|
49
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
50
|
+
raise Sdk.wrap_error(e, 'Failed to create folder')
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
# Deletes a file from the Sandbox.
|
|
@@ -65,8 +65,8 @@ module Daytona
|
|
|
65
65
|
# sandbox.fs.delete_file("workspace/old_dir", recursive: true)
|
|
66
66
|
def delete_file(path, recursive: false)
|
|
67
67
|
toolbox_api.delete_file(path, { recursive: })
|
|
68
|
-
rescue
|
|
69
|
-
raise Sdk
|
|
68
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
69
|
+
raise Sdk.wrap_error(e, 'Failed to delete file')
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
# Gets detailed information about a file or directory, including its
|
|
@@ -89,8 +89,8 @@ module Daytona
|
|
|
89
89
|
# puts "Path is a directory" if info.is_dir
|
|
90
90
|
def get_file_info(path)
|
|
91
91
|
toolbox_api.get_file_info(path)
|
|
92
|
-
rescue
|
|
93
|
-
raise Sdk
|
|
92
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
93
|
+
raise Sdk.wrap_error(e, 'Failed to get file info')
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
# Lists files and directories in a given path and returns their information, similar to the ls -l command.
|
|
@@ -123,8 +123,8 @@ module Daytona
|
|
|
123
123
|
toolbox_api.list_files({ path:, depth: }.compact)
|
|
124
124
|
rescue Sdk::Error
|
|
125
125
|
raise
|
|
126
|
-
rescue
|
|
127
|
-
raise Sdk
|
|
126
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
127
|
+
raise Sdk.wrap_error(e, 'Failed to list files')
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
# Downloads a file from the Sandbox. Returns the file contents as a string.
|
|
@@ -159,7 +159,9 @@ module Daytona
|
|
|
159
159
|
else
|
|
160
160
|
file
|
|
161
161
|
end
|
|
162
|
-
rescue
|
|
162
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
163
|
+
raise Sdk.wrap_error(e, 'Failed to download file')
|
|
164
|
+
rescue IOError, SystemCallError => e
|
|
163
165
|
raise Sdk::Error, "Failed to download file: #{e.message}"
|
|
164
166
|
end
|
|
165
167
|
|
|
@@ -198,7 +200,9 @@ module Daytona
|
|
|
198
200
|
timeout: timeout, on_progress: on_progress,
|
|
199
201
|
cancel_event: cancel_event, &)
|
|
200
202
|
nil
|
|
201
|
-
rescue
|
|
203
|
+
rescue *Sdk::API_ERROR_CLASSES, Sdk::Error => e
|
|
204
|
+
raise Sdk.wrap_error(e, 'Failed to download file')
|
|
205
|
+
rescue IOError, SystemCallError => e
|
|
202
206
|
raise Sdk::Error, "Failed to download file: #{e.message}"
|
|
203
207
|
end
|
|
204
208
|
|
|
@@ -222,13 +226,13 @@ module Daytona
|
|
|
222
226
|
# # Upload binary data
|
|
223
227
|
# data = { key: "value" }.to_json
|
|
224
228
|
# sandbox.fs.upload_file(data, "tmp/config.json")
|
|
225
|
-
def upload_file(source, remote_path)
|
|
229
|
+
def upload_file(source, remote_path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
226
230
|
if source.is_a?(String) && File.exist?(source)
|
|
227
231
|
# Source is a file path
|
|
228
|
-
File.open(source, 'rb') { |file| toolbox_api.upload_file(remote_path, file) }
|
|
232
|
+
File.open(source, 'rb') { |file| toolbox_api.upload_file(remote_path, file: file) }
|
|
229
233
|
elsif source.respond_to?(:read)
|
|
230
234
|
# Source is an IO object
|
|
231
|
-
toolbox_api.upload_file(remote_path, source)
|
|
235
|
+
toolbox_api.upload_file(remote_path, file: source)
|
|
232
236
|
else
|
|
233
237
|
# Tempfile.create yields a ::File (works with Typhoeus) but deletes
|
|
234
238
|
# on block exit — too early if curl reads asynchronously. Write via
|
|
@@ -238,12 +242,14 @@ module Daytona
|
|
|
238
242
|
tmp.binmode
|
|
239
243
|
tmp.write(source.to_s.b)
|
|
240
244
|
tmp.close
|
|
241
|
-
File.open(tmp.path, 'rb') { |file| toolbox_api.upload_file(remote_path, file) }
|
|
245
|
+
File.open(tmp.path, 'rb') { |file| toolbox_api.upload_file(remote_path, file: file) }
|
|
242
246
|
ensure
|
|
243
247
|
tmp.unlink
|
|
244
248
|
end
|
|
245
249
|
end
|
|
246
|
-
rescue
|
|
250
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
251
|
+
raise Sdk.wrap_error(e, 'Failed to upload file')
|
|
252
|
+
rescue IOError, SystemCallError => e
|
|
247
253
|
raise Sdk::Error, "Failed to upload file: #{e.message}"
|
|
248
254
|
end
|
|
249
255
|
|
|
@@ -273,7 +279,9 @@ module Daytona
|
|
|
273
279
|
FileTransfer.stream_upload(api_client: toolbox_api.api_client, remote_path: remote_path,
|
|
274
280
|
source: source, timeout: timeout, on_progress: on_progress,
|
|
275
281
|
cancel_event: cancel_event)
|
|
276
|
-
rescue
|
|
282
|
+
rescue *Sdk::API_ERROR_CLASSES, Sdk::Error => e
|
|
283
|
+
raise Sdk.wrap_error(e, 'Failed to upload file')
|
|
284
|
+
rescue IOError, SystemCallError => e
|
|
277
285
|
raise Sdk::Error, "Failed to upload file: #{e.message}"
|
|
278
286
|
end
|
|
279
287
|
|
|
@@ -294,8 +302,8 @@ module Daytona
|
|
|
294
302
|
# sandbox.fs.upload_files(files)
|
|
295
303
|
def upload_files(files)
|
|
296
304
|
files.each { |file_upload| upload_file(file_upload.source, file_upload.destination) }
|
|
297
|
-
rescue
|
|
298
|
-
raise Sdk
|
|
305
|
+
rescue *Sdk::API_ERROR_CLASSES, Sdk::Error => e
|
|
306
|
+
raise Sdk.wrap_error(e, 'Failed to upload files')
|
|
299
307
|
end
|
|
300
308
|
|
|
301
309
|
# Searches for files containing a pattern, similar to the grep command.
|
|
@@ -315,8 +323,8 @@ module Daytona
|
|
|
315
323
|
# end
|
|
316
324
|
def find_files(path, pattern)
|
|
317
325
|
toolbox_api.find_in_files(path, pattern)
|
|
318
|
-
rescue
|
|
319
|
-
raise Sdk
|
|
326
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
327
|
+
raise Sdk.wrap_error(e, 'Failed to find files')
|
|
320
328
|
end
|
|
321
329
|
|
|
322
330
|
# Searches for files and directories whose names match the specified pattern.
|
|
@@ -339,8 +347,8 @@ module Daytona
|
|
|
339
347
|
# puts "Found #{result.files.length} test files"
|
|
340
348
|
def search_files(path, pattern)
|
|
341
349
|
toolbox_api.search_files(path, pattern)
|
|
342
|
-
rescue
|
|
343
|
-
raise Sdk
|
|
350
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
351
|
+
raise Sdk.wrap_error(e, 'Failed to search files')
|
|
344
352
|
end
|
|
345
353
|
|
|
346
354
|
# Moves or renames a file or directory. The parent directory of the destination must exist.
|
|
@@ -372,8 +380,8 @@ module Daytona
|
|
|
372
380
|
# )
|
|
373
381
|
def move_files(source, destination)
|
|
374
382
|
toolbox_api.move_file(source, destination)
|
|
375
|
-
rescue
|
|
376
|
-
raise Sdk
|
|
383
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
384
|
+
raise Sdk.wrap_error(e, 'Failed to move files')
|
|
377
385
|
end
|
|
378
386
|
|
|
379
387
|
# Performs search and replace operations across multiple files.
|
|
@@ -408,8 +416,8 @@ module Daytona
|
|
|
408
416
|
new_value: new_value
|
|
409
417
|
)
|
|
410
418
|
toolbox_api.replace_in_files(replace_request)
|
|
411
|
-
rescue
|
|
412
|
-
raise Sdk
|
|
419
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
420
|
+
raise Sdk.wrap_error(e, 'Failed to replace in files')
|
|
413
421
|
end
|
|
414
422
|
|
|
415
423
|
# Sets permissions and ownership for a file or directory. Any of the parameters can be nil
|
|
@@ -443,8 +451,8 @@ module Daytona
|
|
|
443
451
|
opts[:group] = group if group
|
|
444
452
|
|
|
445
453
|
toolbox_api.set_file_permissions(path, opts)
|
|
446
|
-
rescue
|
|
447
|
-
raise Sdk
|
|
454
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
455
|
+
raise Sdk.wrap_error(e, 'Failed to set file permissions')
|
|
448
456
|
end
|
|
449
457
|
|
|
450
458
|
instrument :create_folder, :delete_file, :get_file_info, :list_files, :download_file,
|
data/lib/daytona/git.rb
CHANGED
|
@@ -47,8 +47,8 @@ module Daytona
|
|
|
47
47
|
toolbox_api.add_files(DaytonaToolboxApiClient::GitAddRequest.new(path:, files:))
|
|
48
48
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
49
49
|
raise map_api_error(e, 'Failed to add files')
|
|
50
|
-
rescue
|
|
51
|
-
raise Sdk
|
|
50
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
51
|
+
raise Sdk.wrap_error(e, 'Failed to add files')
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
# Lists branches in the repository.
|
|
@@ -65,8 +65,8 @@ module Daytona
|
|
|
65
65
|
toolbox_api.list_branches(path)
|
|
66
66
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
67
67
|
raise map_api_error(e, 'Failed to list branches')
|
|
68
|
-
rescue
|
|
69
|
-
raise Sdk
|
|
68
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
69
|
+
raise Sdk.wrap_error(e, 'Failed to list branches')
|
|
70
70
|
end
|
|
71
71
|
|
|
72
72
|
# Clones a Git repository into the specified path. It supports
|
|
@@ -126,8 +126,8 @@ module Daytona
|
|
|
126
126
|
)
|
|
127
127
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
128
128
|
raise map_api_error(e, 'Failed to clone repository')
|
|
129
|
-
rescue
|
|
130
|
-
raise Sdk
|
|
129
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
130
|
+
raise Sdk.wrap_error(e, 'Failed to clone repository')
|
|
131
131
|
end
|
|
132
132
|
|
|
133
133
|
# Creates a new commit with the staged changes. Make sure to stage
|
|
@@ -160,8 +160,8 @@ module Daytona
|
|
|
160
160
|
GitCommitResponse.new(sha: response._hash)
|
|
161
161
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
162
162
|
raise map_api_error(e, 'Failed to commit changes')
|
|
163
|
-
rescue
|
|
164
|
-
raise Sdk
|
|
163
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
164
|
+
raise Sdk.wrap_error(e, 'Failed to commit changes')
|
|
165
165
|
end
|
|
166
166
|
|
|
167
167
|
# Pushes all local commits on the current branch to the remote
|
|
@@ -197,8 +197,8 @@ module Daytona
|
|
|
197
197
|
)
|
|
198
198
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
199
199
|
raise map_api_error(e, 'Failed to push changes')
|
|
200
|
-
rescue
|
|
201
|
-
raise Sdk
|
|
200
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
201
|
+
raise Sdk.wrap_error(e, 'Failed to push changes')
|
|
202
202
|
end
|
|
203
203
|
|
|
204
204
|
# Pulls changes from the remote repository. If the remote repository requires authentication,
|
|
@@ -232,8 +232,8 @@ module Daytona
|
|
|
232
232
|
)
|
|
233
233
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
234
234
|
raise map_api_error(e, 'Failed to pull changes')
|
|
235
|
-
rescue
|
|
236
|
-
raise Sdk
|
|
235
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
236
|
+
raise Sdk.wrap_error(e, 'Failed to pull changes')
|
|
237
237
|
end
|
|
238
238
|
|
|
239
239
|
# Gets the current Git repository status.
|
|
@@ -252,8 +252,8 @@ module Daytona
|
|
|
252
252
|
toolbox_api.get_status(path)
|
|
253
253
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
254
254
|
raise map_api_error(e, 'Failed to get status')
|
|
255
|
-
rescue
|
|
256
|
-
raise Sdk
|
|
255
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
256
|
+
raise Sdk.wrap_error(e, 'Failed to get status')
|
|
257
257
|
end
|
|
258
258
|
|
|
259
259
|
# Checkout branch in the repository.
|
|
@@ -273,8 +273,8 @@ module Daytona
|
|
|
273
273
|
)
|
|
274
274
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
275
275
|
raise map_api_error(e, 'Failed to checkout branch')
|
|
276
|
-
rescue
|
|
277
|
-
raise Sdk
|
|
276
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
277
|
+
raise Sdk.wrap_error(e, 'Failed to checkout branch')
|
|
278
278
|
end
|
|
279
279
|
|
|
280
280
|
# Create branch in the repository.
|
|
@@ -295,8 +295,8 @@ module Daytona
|
|
|
295
295
|
)
|
|
296
296
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
297
297
|
raise map_api_error(e, 'Failed to create branch')
|
|
298
|
-
rescue
|
|
299
|
-
raise Sdk
|
|
298
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
299
|
+
raise Sdk.wrap_error(e, 'Failed to create branch')
|
|
300
300
|
end
|
|
301
301
|
|
|
302
302
|
# Delete branch in the repository.
|
|
@@ -316,8 +316,8 @@ module Daytona
|
|
|
316
316
|
)
|
|
317
317
|
rescue DaytonaToolboxApiClient::ApiError => e
|
|
318
318
|
raise map_api_error(e, 'Failed to delete branch')
|
|
319
|
-
rescue
|
|
320
|
-
raise Sdk
|
|
319
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
320
|
+
raise Sdk.wrap_error(e, 'Failed to delete branch')
|
|
321
321
|
end
|
|
322
322
|
|
|
323
323
|
# Initializes a new Git repository at the specified path.
|
|
@@ -544,17 +544,7 @@ module Daytona
|
|
|
544
544
|
attr_reader :otel_state
|
|
545
545
|
|
|
546
546
|
def map_api_error(api_error, prefix)
|
|
547
|
-
|
|
548
|
-
case api_error.code
|
|
549
|
-
when 400 then Sdk::ValidationError.new(msg)
|
|
550
|
-
when 401 then Sdk::AuthenticationError.new(msg)
|
|
551
|
-
when 403 then Sdk::ForbiddenError.new(msg)
|
|
552
|
-
when 404 then Sdk::NotFoundError.new(msg)
|
|
553
|
-
when 409 then Sdk::ConflictError.new(msg)
|
|
554
|
-
when 429 then Sdk::RateLimitError.new(msg)
|
|
555
|
-
when 500..599 then Sdk::ServerError.new(msg)
|
|
556
|
-
else Sdk::Error.new(msg)
|
|
557
|
-
end
|
|
547
|
+
Sdk.wrap_error(api_error, prefix)
|
|
558
548
|
end
|
|
559
549
|
end
|
|
560
550
|
end
|
data/lib/daytona/lsp_server.rb
CHANGED
|
@@ -59,6 +59,8 @@ module Daytona
|
|
|
59
59
|
position: DaytonaToolboxApiClient::LspPosition.new(line: position.line, character: position.character)
|
|
60
60
|
)
|
|
61
61
|
)
|
|
62
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
63
|
+
raise Sdk.wrap_error(e, 'Failed to get LSP completions')
|
|
62
64
|
end
|
|
63
65
|
|
|
64
66
|
# Notify the language server that a file has been closed.
|
|
@@ -71,6 +73,8 @@ module Daytona
|
|
|
71
73
|
toolbox_api.did_close(
|
|
72
74
|
DaytonaToolboxApiClient::LspDocumentRequest.new(language_id:, path_to_project:, uri: uri(path))
|
|
73
75
|
)
|
|
76
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
77
|
+
raise Sdk.wrap_error(e, 'Failed to notify LSP server of closed document')
|
|
74
78
|
end
|
|
75
79
|
|
|
76
80
|
# Notifies the language server that a file has been opened.
|
|
@@ -84,20 +88,30 @@ module Daytona
|
|
|
84
88
|
toolbox_api.did_open(
|
|
85
89
|
DaytonaToolboxApiClient::LspDocumentRequest.new(language_id:, path_to_project:, uri: uri(path))
|
|
86
90
|
)
|
|
91
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
92
|
+
raise Sdk.wrap_error(e, 'Failed to notify LSP server of opened document')
|
|
87
93
|
end
|
|
88
94
|
|
|
89
95
|
# Gets symbol information (functions, classes, variables, etc.) from a document.
|
|
90
96
|
#
|
|
91
97
|
# @param path [String]
|
|
92
98
|
# @return [Array<DaytonaToolboxApiClient::LspSymbol]
|
|
93
|
-
def document_symbols(path)
|
|
99
|
+
def document_symbols(path)
|
|
100
|
+
toolbox_api.document_symbols(language_id, path_to_project, uri(path))
|
|
101
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
102
|
+
raise Sdk.wrap_error(e, 'Failed to get LSP document symbols')
|
|
103
|
+
end
|
|
94
104
|
|
|
95
105
|
# Searches for symbols matching the query string across all files
|
|
96
106
|
# in the Sandbox.
|
|
97
107
|
#
|
|
98
108
|
# @param query [String]
|
|
99
109
|
# @return [Array<DaytonaToolboxApiClient::LspSymbol]
|
|
100
|
-
def sandbox_symbols(query)
|
|
110
|
+
def sandbox_symbols(query)
|
|
111
|
+
toolbox_api.workspace_symbols(query, language_id, path_to_project)
|
|
112
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
113
|
+
raise Sdk.wrap_error(e, 'Failed to get LSP workspace symbols')
|
|
114
|
+
end
|
|
101
115
|
|
|
102
116
|
# Starts the language server.
|
|
103
117
|
# This method must be called before using any other LSP functionality.
|
|
@@ -108,6 +122,8 @@ module Daytona
|
|
|
108
122
|
toolbox_api.start(
|
|
109
123
|
DaytonaToolboxApiClient::LspServerRequest.new(language_id:, path_to_project:)
|
|
110
124
|
)
|
|
125
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
126
|
+
raise Sdk.wrap_error(e, 'Failed to start LSP server')
|
|
111
127
|
end
|
|
112
128
|
|
|
113
129
|
# Stops the language server.
|
|
@@ -119,6 +135,8 @@ module Daytona
|
|
|
119
135
|
toolbox_api.stop(
|
|
120
136
|
DaytonaToolboxApiClient::LspServerRequest.new(language_id:, path_to_project:)
|
|
121
137
|
)
|
|
138
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
139
|
+
raise Sdk.wrap_error(e, 'Failed to stop LSP server')
|
|
122
140
|
end
|
|
123
141
|
|
|
124
142
|
instrument :completions, :did_close, :did_open, :document_symbols, :sandbox_symbols,
|
|
@@ -25,9 +25,9 @@ module Daytona
|
|
|
25
25
|
# @param aws_secret_access_key [String] The secret access key for the object storage service
|
|
26
26
|
# @param aws_session_token [String] The session token for the object storage service
|
|
27
27
|
# @param bucket_name [String] The name of the bucket to use (defaults to "daytona-volume-builds")
|
|
28
|
-
# @param region [String]
|
|
28
|
+
# @param region [String] Region of the storage backend
|
|
29
29
|
def initialize(endpoint_url:, aws_access_key_id:, aws_secret_access_key:, aws_session_token:, # rubocop:disable Metrics/ParameterLists
|
|
30
|
-
bucket_name: DEFAULT_BUCKET_NAME
|
|
30
|
+
region:, bucket_name: DEFAULT_BUCKET_NAME)
|
|
31
31
|
@bucket_name = bucket_name
|
|
32
32
|
@s3_client = Aws::S3::Client.new(
|
|
33
33
|
region:,
|
|
@@ -165,8 +165,5 @@ module Daytona
|
|
|
165
165
|
|
|
166
166
|
DEFAULT_BUCKET_NAME = 'daytona-volume-builds'
|
|
167
167
|
private_constant :DEFAULT_BUCKET_NAME
|
|
168
|
-
|
|
169
|
-
DEFAULT_REGION = 'us-east-1'
|
|
170
|
-
private_constant :DEFAULT_REGION
|
|
171
168
|
end
|
|
172
169
|
end
|
data/lib/daytona/process.rb
CHANGED
|
@@ -68,6 +68,8 @@ module Daytona
|
|
|
68
68
|
result:,
|
|
69
69
|
artifacts: ExecutionArtifacts.new(result, [])
|
|
70
70
|
)
|
|
71
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
72
|
+
raise Sdk.wrap_error(e, 'Failed to execute command')
|
|
71
73
|
end
|
|
72
74
|
|
|
73
75
|
# Execute code in the Sandbox using the appropriate language runtime
|
|
@@ -99,6 +101,8 @@ module Daytona
|
|
|
99
101
|
Charts.parse_chart(c)
|
|
100
102
|
end)
|
|
101
103
|
)
|
|
104
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
105
|
+
raise Sdk.wrap_error(e, 'Failed to run code')
|
|
102
106
|
end
|
|
103
107
|
|
|
104
108
|
# Creates a new long-running background session in the Sandbox
|
|
@@ -118,6 +122,8 @@ module Daytona
|
|
|
118
122
|
# sandbox.process.delete_session(session_id)
|
|
119
123
|
def create_session(session_id)
|
|
120
124
|
toolbox_api.create_session(DaytonaToolboxApiClient::CreateSessionRequest.new(session_id:))
|
|
125
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
126
|
+
raise Sdk.wrap_error(e, 'Failed to create session')
|
|
121
127
|
end
|
|
122
128
|
|
|
123
129
|
# Gets a session in the Sandbox
|
|
@@ -130,7 +136,11 @@ module Daytona
|
|
|
130
136
|
# session.commands.each do |cmd|
|
|
131
137
|
# puts "Command: #{cmd.command}"
|
|
132
138
|
# end
|
|
133
|
-
def get_session(session_id)
|
|
139
|
+
def get_session(session_id)
|
|
140
|
+
toolbox_api.get_session(session_id)
|
|
141
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
142
|
+
raise Sdk.wrap_error(e, 'Failed to get session')
|
|
143
|
+
end
|
|
134
144
|
|
|
135
145
|
# Gets the Sandbox entrypoint session
|
|
136
146
|
#
|
|
@@ -141,7 +151,11 @@ module Daytona
|
|
|
141
151
|
# session.commands.each do |cmd|
|
|
142
152
|
# puts "Command: #{cmd.command}"
|
|
143
153
|
# end
|
|
144
|
-
def get_entrypoint_session
|
|
154
|
+
def get_entrypoint_session
|
|
155
|
+
toolbox_api.get_entrypoint_session
|
|
156
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
157
|
+
raise Sdk.wrap_error(e, 'Failed to get entrypoint session')
|
|
158
|
+
end
|
|
145
159
|
|
|
146
160
|
# Gets information about a specific command executed in a session
|
|
147
161
|
#
|
|
@@ -156,6 +170,8 @@ module Daytona
|
|
|
156
170
|
# end
|
|
157
171
|
def get_session_command(session_id:, command_id:)
|
|
158
172
|
toolbox_api.get_session_command(session_id, command_id)
|
|
173
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
174
|
+
raise Sdk.wrap_error(e, 'Failed to get session command')
|
|
159
175
|
end
|
|
160
176
|
|
|
161
177
|
# Executes a command in the session
|
|
@@ -196,6 +212,8 @@ module Daytona
|
|
|
196
212
|
exit_code: response.exit_code,
|
|
197
213
|
additional_properties: {}
|
|
198
214
|
)
|
|
215
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
216
|
+
raise Sdk.wrap_error(e, 'Failed to execute session command')
|
|
199
217
|
end
|
|
200
218
|
|
|
201
219
|
# Get the logs for a command executed in a session
|
|
@@ -211,6 +229,8 @@ module Daytona
|
|
|
211
229
|
def get_session_command_logs(session_id:, command_id:)
|
|
212
230
|
response = toolbox_api.get_session_command_logs(session_id, command_id)
|
|
213
231
|
SessionCommandLogsResponse.new(output: response.output, stdout: response.stdout, stderr: response.stderr)
|
|
232
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
233
|
+
raise Sdk.wrap_error(e, 'Failed to get session command logs')
|
|
214
234
|
end
|
|
215
235
|
|
|
216
236
|
# Asynchronously retrieves and processes the logs for a command executed in a session as they become available
|
|
@@ -282,6 +302,8 @@ module Daytona
|
|
|
282
302
|
def get_entrypoint_logs
|
|
283
303
|
response = toolbox_api.get_entrypoint_logs
|
|
284
304
|
SessionCommandLogsResponse.new(output: response.output, stdout: response.stdout, stderr: response.stderr)
|
|
305
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
306
|
+
raise Sdk.wrap_error(e, 'Failed to get entrypoint logs')
|
|
285
307
|
end
|
|
286
308
|
|
|
287
309
|
# Asynchronously retrieves and processes the sandbox entrypoint logs as they become available
|
|
@@ -353,6 +375,8 @@ module Daytona
|
|
|
353
375
|
command_id,
|
|
354
376
|
DaytonaToolboxApiClient::SessionSendInputRequest.new(data:)
|
|
355
377
|
)
|
|
378
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
379
|
+
raise Sdk.wrap_error(e, 'Failed to send session command input')
|
|
356
380
|
end
|
|
357
381
|
|
|
358
382
|
#
|
|
@@ -364,7 +388,11 @@ module Daytona
|
|
|
364
388
|
# puts "Session #{session.session_id}:"
|
|
365
389
|
# puts " Commands: #{session.commands.length}"
|
|
366
390
|
# end
|
|
367
|
-
def list_sessions
|
|
391
|
+
def list_sessions
|
|
392
|
+
toolbox_api.list_sessions
|
|
393
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
394
|
+
raise Sdk.wrap_error(e, 'Failed to list sessions')
|
|
395
|
+
end
|
|
368
396
|
|
|
369
397
|
# Terminates and removes a session from the Sandbox, cleaning up any resources associated with it
|
|
370
398
|
#
|
|
@@ -377,7 +405,11 @@ module Daytona
|
|
|
377
405
|
#
|
|
378
406
|
# # Clean up when done
|
|
379
407
|
# sandbox.process.delete_session("temp-session")
|
|
380
|
-
def delete_session(session_id)
|
|
408
|
+
def delete_session(session_id)
|
|
409
|
+
toolbox_api.delete_session(session_id)
|
|
410
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
411
|
+
raise Sdk.wrap_error(e, 'Failed to delete session')
|
|
412
|
+
end
|
|
381
413
|
|
|
382
414
|
# Creates a new PTY (pseudo-terminal) session in the Sandbox.
|
|
383
415
|
#
|
|
@@ -499,6 +531,8 @@ module Daytona
|
|
|
499
531
|
rows: pty_size.rows
|
|
500
532
|
)
|
|
501
533
|
)
|
|
534
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
535
|
+
raise Sdk.wrap_error(e, 'Failed to resize PTY session')
|
|
502
536
|
end
|
|
503
537
|
|
|
504
538
|
# Deletes a PTY session, terminating the associated process
|
|
@@ -510,6 +544,8 @@ module Daytona
|
|
|
510
544
|
# sandbox.process.delete_pty_session("my-pty")
|
|
511
545
|
def delete_pty_session(session_id)
|
|
512
546
|
toolbox_api.delete_pty_session(session_id)
|
|
547
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
548
|
+
raise Sdk.wrap_error(e, 'Failed to delete PTY session')
|
|
513
549
|
end
|
|
514
550
|
|
|
515
551
|
# Lists all PTY sessions in the Sandbox
|
|
@@ -526,6 +562,8 @@ module Daytona
|
|
|
526
562
|
return [] if response.nil?
|
|
527
563
|
|
|
528
564
|
response.respond_to?(:sessions) ? (response.sessions || []) : response
|
|
565
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
566
|
+
raise Sdk.wrap_error(e, 'Failed to list PTY sessions')
|
|
529
567
|
end
|
|
530
568
|
|
|
531
569
|
# Gets detailed information about a specific PTY session
|
|
@@ -546,6 +584,8 @@ module Daytona
|
|
|
546
584
|
# puts "Terminal Size: #{session_info.cols}x#{session_info.rows}"
|
|
547
585
|
def get_pty_session_info(session_id)
|
|
548
586
|
toolbox_api.get_pty_session(session_id)
|
|
587
|
+
rescue *Sdk::API_ERROR_CLASSES => e
|
|
588
|
+
raise Sdk.wrap_error(e, 'Failed to get PTY session info')
|
|
549
589
|
end
|
|
550
590
|
|
|
551
591
|
instrument :exec, :code_run, :create_session, :get_session, :get_session_command,
|