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,551 @@
1
+ # Copyright Daytona Platforms Inc.
2
+ # Copyright Cognifyi
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+ # frozen_string_literal: true
6
+
7
+ require 'uri'
8
+
9
+ module Cogbox
10
+ class Process # rubocop:disable Metrics/ClassLength
11
+ include Instrumentation
12
+
13
+ # @return [String] The ID of the Sandbox
14
+ attr_reader :sandbox_id
15
+
16
+ # @return [CogboxToolboxApiClient::ProcessApi] API client for Sandbox operations
17
+ attr_reader :toolbox_api
18
+
19
+ # @return [Proc] Function to get preview link for a port
20
+ attr_reader :get_preview_link
21
+
22
+ # @return [String] The language for code execution (e.g. 'python', 'typescript', 'javascript')
23
+ attr_reader :language
24
+
25
+ # Initialize a new Process instance
26
+ #
27
+ # @param sandbox_id [String] The ID of the Sandbox
28
+ # @param toolbox_api [CogboxToolboxApiClient::ProcessApi] API client for Sandbox operations
29
+ # @param get_preview_link [Proc] Function to get preview link for a port
30
+ # @param language [String] The language for code execution
31
+ # @param otel_state [Cogbox::OtelState, nil]
32
+ def initialize(sandbox_id:, toolbox_api:, get_preview_link:, language: 'python', otel_state: nil)
33
+ @sandbox_id = sandbox_id
34
+ @toolbox_api = toolbox_api
35
+ @get_preview_link = get_preview_link
36
+ @language = language
37
+ @otel_state = otel_state
38
+ end
39
+
40
+ # Execute a shell command in the Sandbox
41
+ #
42
+ # @param command [String] Shell command to execute
43
+ # @param cwd [String, nil] Working directory for command execution. If not specified, uses the sandbox working directory
44
+ # @param env [Hash<String, String>, nil] Environment variables to set for the command
45
+ # @param timeout [Integer, nil] Maximum time in seconds to wait for the command to complete.
46
+ # @return [ExecuteResponse] Command execution results containing exit_code, result, and artifacts
47
+ #
48
+ # @example
49
+ # # Simple command
50
+ # response = sandbox.process.exec("echo 'Hello'")
51
+ # puts response.artifacts.stdout
52
+ # => "Hello\n"
53
+ #
54
+ # # Command with working directory
55
+ # result = sandbox.process.exec("ls", cwd: "workspace/src")
56
+ #
57
+ # # Command with timeout
58
+ # result = sandbox.process.exec("sleep 10", timeout: 5)
59
+ def exec(command:, cwd: nil, env: nil, timeout: nil)
60
+ envs = env&.empty? ? nil : env
61
+
62
+ response = toolbox_api.execute_command(CogboxToolboxApiClient::ExecuteRequest.new(command:, cwd:, envs:,
63
+ timeout:))
64
+ result = response.result || ''
65
+ ExecuteResponse.new(
66
+ exit_code: response.exit_code,
67
+ result:,
68
+ artifacts: ExecutionArtifacts.new(result, [])
69
+ )
70
+ end
71
+
72
+ # Execute code in the Sandbox using the appropriate language runtime
73
+ #
74
+ # @param code [String] Code to execute
75
+ # @param params [CodeRunParams, nil] Parameters for code execution
76
+ # @param timeout [Integer, nil] Maximum time in seconds to wait for the code to complete. 0 means wait indefinitely
77
+ # @return [ExecuteResponse] Code execution result containing exit_code, result, and artifacts
78
+ #
79
+ # @example
80
+ # # Run Python code
81
+ # response = sandbox.process.code_run(<<~CODE)
82
+ # x = 10
83
+ # y = 20
84
+ # print(f"Sum: {x + y}")
85
+ # CODE
86
+ # puts response.artifacts.stdout # Prints: Sum: 30
87
+ def code_run(code:, params: nil, timeout: nil)
88
+ response = toolbox_api.code_run(
89
+ CogboxToolboxApiClient::CodeRunRequest.new(
90
+ code:, language:, argv: params&.argv, envs: params&.env, timeout:
91
+ )
92
+ )
93
+
94
+ ExecuteResponse.new(
95
+ exit_code: response.exit_code,
96
+ result: response.result,
97
+ artifacts: ExecutionArtifacts.new(response.result, (response.artifacts&.charts || []).map do |c|
98
+ Charts.parse_chart(c)
99
+ end)
100
+ )
101
+ end
102
+
103
+ # Creates a new long-running background session in the Sandbox
104
+ #
105
+ # Sessions are background processes that maintain state between commands, making them ideal for
106
+ # scenarios requiring multiple related commands or persistent environment setup.
107
+ #
108
+ # @param session_id [String] Unique identifier for the new session
109
+ # @return [void]
110
+ #
111
+ # @example
112
+ # # Create a new session
113
+ # session_id = "my-session"
114
+ # sandbox.process.create_session(session_id)
115
+ # session = sandbox.process.get_session(session_id)
116
+ # # Do work...
117
+ # sandbox.process.delete_session(session_id)
118
+ def create_session(session_id)
119
+ toolbox_api.create_session(CogboxToolboxApiClient::CreateSessionRequest.new(session_id:))
120
+ end
121
+
122
+ # Gets a session in the Sandbox
123
+ #
124
+ # @param session_id [String] Unique identifier of the session to retrieve
125
+ # @return [CogboxApiClient::Session] Session information including session_id and commands
126
+ #
127
+ # @example
128
+ # session = sandbox.process.get_session("my-session")
129
+ # session.commands.each do |cmd|
130
+ # puts "Command: #{cmd.command}"
131
+ # end
132
+ def get_session(session_id) = toolbox_api.get_session(session_id)
133
+
134
+ # Gets the Sandbox entrypoint session
135
+ #
136
+ # @return [CogboxApiClient::Session] Entrypoint session information including session_id and commands
137
+ #
138
+ # @example
139
+ # session = sandbox.process.get_entrypoint_session()
140
+ # session.commands.each do |cmd|
141
+ # puts "Command: #{cmd.command}"
142
+ # end
143
+ def get_entrypoint_session = toolbox_api.get_entrypoint_session
144
+
145
+ # Gets information about a specific command executed in a session
146
+ #
147
+ # @param session_id [String] Unique identifier of the session
148
+ # @param command_id [String] Unique identifier of the command
149
+ # @return [CogboxApiClient::Command] Command information including id, command, and exit_code
150
+ #
151
+ # @example
152
+ # cmd = sandbox.process.get_session_command(session_id: "my-session", command_id: "cmd-123")
153
+ # if cmd.exit_code == 0
154
+ # puts "Command #{cmd.command} completed successfully"
155
+ # end
156
+ def get_session_command(session_id:, command_id:)
157
+ toolbox_api.get_session_command(session_id, command_id)
158
+ end
159
+
160
+ # Executes a command in the session
161
+ #
162
+ # @param session_id [String] Unique identifier of the session to use
163
+ # @param req [Cogbox::SessionExecuteRequest] Command execution request containing command and run_async
164
+ # @return [Cogbox::SessionExecuteResponse] Command execution results containing cmd_id, output, stdout, stderr, and exit_code
165
+ #
166
+ # @example
167
+ # # Execute commands in sequence, maintaining state
168
+ # session_id = "my-session"
169
+ #
170
+ # # Change directory
171
+ # req = Cogbox::SessionExecuteRequest.new(command: "cd /workspace")
172
+ # sandbox.process.execute_session_command(session_id:, req:)
173
+ #
174
+ # # Create a file
175
+ # req = Cogbox::SessionExecuteRequest.new(command: "echo 'Hello' > test.txt")
176
+ # sandbox.process.execute_session_command(session_id:, req:)
177
+ #
178
+ # # Read the file
179
+ # req = Cogbox::SessionExecuteRequest.new(command: "cat test.txt")
180
+ # result = sandbox.process.execute_session_command(session_id:, req:)
181
+ # puts "Command stdout: #{result.stdout}"
182
+ # puts "Command stderr: #{result.stderr}"
183
+ def execute_session_command(session_id:, req:) # rubocop:disable Metrics/MethodLength
184
+ response = toolbox_api.session_execute_command(
185
+ session_id,
186
+ CogboxToolboxApiClient::SessionExecuteRequest.new(command: req.command, run_async: req.run_async,
187
+ suppress_input_echo: req.suppress_input_echo)
188
+ )
189
+
190
+ SessionExecuteResponse.new(
191
+ cmd_id: response.cmd_id,
192
+ output: response.output,
193
+ stdout: response.stdout || '',
194
+ stderr: response.stderr || '',
195
+ exit_code: response.exit_code,
196
+ additional_properties: {}
197
+ )
198
+ end
199
+
200
+ # Get the logs for a command executed in a session
201
+ #
202
+ # @param session_id [String] Unique identifier of the session
203
+ # @param command_id [String] Unique identifier of the command
204
+ # @return [Cogbox::SessionCommandLogsResponse] Command logs including output, stdout, and stderr
205
+ #
206
+ # @example
207
+ # logs = sandbox.process.get_session_command_logs(session_id: "my-session", command_id: "cmd-123")
208
+ # puts "Command stdout: #{logs.stdout}"
209
+ # puts "Command stderr: #{logs.stderr}"
210
+ def get_session_command_logs(session_id:, command_id:)
211
+ response = toolbox_api.get_session_command_logs(session_id, command_id)
212
+ SessionCommandLogsResponse.new(output: response.output, stdout: response.stdout, stderr: response.stderr)
213
+ end
214
+
215
+ # Asynchronously retrieves and processes the logs for a command executed in a session as they become available
216
+ #
217
+ # @param session_id [String] Unique identifier of the session
218
+ # @param command_id [String] Unique identifier of the command
219
+ # @param on_stdout [Proc] Callback function to handle stdout log chunks as they arrive
220
+ # @param on_stderr [Proc] Callback function to handle stderr log chunks as they arrive
221
+ # @return [WebSocket::Client::Simple::Client]
222
+ #
223
+ # @example
224
+ # sandbox.process.get_session_command_logs_async(
225
+ # session_id: "my-session",
226
+ # command_id: "cmd-123",
227
+ # on_stdout: ->(log) { puts "[STDOUT]: #{log}" },
228
+ # on_stderr: ->(log) { puts "[STDERR]: #{log}" }
229
+ # )
230
+ def get_session_command_logs_async(session_id:, command_id:, on_stdout:, on_stderr:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
231
+ preview_link = get_preview_link.call(WS_PORT)
232
+ url = URI.parse(preview_link.url)
233
+ url.scheme = url.scheme == 'https' ? 'wss' : 'ws'
234
+ url.path = "/process/session/#{session_id}/command/#{command_id}/logs"
235
+ url.query = 'follow=true'
236
+
237
+ completion_queue = Queue.new
238
+
239
+ WebSocket::Client::Simple.connect(
240
+ url.to_s,
241
+ headers: toolbox_api.api_client.default_headers.dup.merge(
242
+ 'X-Cogbox-Preview-Token' => preview_link.token,
243
+ 'Content-Type' => 'text/plain',
244
+ 'Accept' => 'text/plain'
245
+ )
246
+ ) do |client|
247
+ client.on(:message) do |message|
248
+ if message.type == :close
249
+ client.close
250
+ completion_queue.push(:close)
251
+ else
252
+ stdout, stderr = Util.demux(message.data.to_s)
253
+
254
+ on_stdout.call(stdout) unless stdout.empty?
255
+ on_stderr.call(stderr) unless stderr.empty?
256
+ end
257
+ end
258
+
259
+ client.on(:close) do
260
+ completion_queue.push(:close)
261
+ end
262
+
263
+ client.on(:error) do |e|
264
+ completion_queue.push(:error)
265
+ raise Sdk::Error, "WebSocket error: #{e.message}"
266
+ end
267
+ end
268
+
269
+ # Wait for completion
270
+ completion_queue.pop
271
+ end
272
+
273
+ # Get the sandbox entrypoint logs
274
+ #
275
+ # @return [Cogbox::SessionCommandLogsResponse] Entrypoint logs including output, stdout, and stderr
276
+ #
277
+ # @example
278
+ # logs = sandbox.process.get_entrypoint_logs()
279
+ # puts "Command stdout: #{logs.stdout}"
280
+ # puts "Command stderr: #{logs.stderr}"
281
+ def get_entrypoint_logs
282
+ response = toolbox_api.get_entrypoint_logs
283
+ SessionCommandLogsResponse.new(output: response.output, stdout: response.stdout, stderr: response.stderr)
284
+ end
285
+
286
+ # Asynchronously retrieves and processes the sandbox entrypoint logs as they become available
287
+ #
288
+ # @param on_stdout [Proc] Callback function to handle stdout log chunks as they arrive
289
+ # @param on_stderr [Proc] Callback function to handle stderr log chunks as they arrive
290
+ # @return [WebSocket::Client::Simple::Client]
291
+ #
292
+ # @example
293
+ # sandbox.process.get_entrypoint_logs_async(
294
+ # on_stdout: ->(log) { puts "[STDOUT]: #{log}" },
295
+ # on_stderr: ->(log) { puts "[STDERR]: #{log}" }
296
+ # )
297
+ def get_entrypoint_logs_async(on_stdout:, on_stderr:) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
298
+ preview_link = get_preview_link.call(WS_PORT)
299
+ url = URI.parse(preview_link.url)
300
+ url.scheme = url.scheme == 'https' ? 'wss' : 'ws'
301
+ url.path = '/process/session/entrypoint/logs'
302
+ url.query = 'follow=true'
303
+
304
+ completion_queue = Queue.new
305
+
306
+ WebSocket::Client::Simple.connect(
307
+ url.to_s,
308
+ headers: toolbox_api.api_client.default_headers.dup.merge(
309
+ 'X-Cogbox-Preview-Token' => preview_link.token,
310
+ 'Content-Type' => 'text/plain',
311
+ 'Accept' => 'text/plain'
312
+ )
313
+ ) do |client|
314
+ client.on(:message) do |message|
315
+ if message.type == :close
316
+ client.close
317
+ completion_queue.push(:close)
318
+ else
319
+ stdout, stderr = Util.demux(message.data.to_s)
320
+
321
+ on_stdout.call(stdout) unless stdout.empty?
322
+ on_stderr.call(stderr) unless stderr.empty?
323
+ end
324
+ end
325
+
326
+ client.on(:close) do
327
+ completion_queue.push(:close)
328
+ end
329
+
330
+ client.on(:error) do |e|
331
+ completion_queue.push(:error)
332
+ raise Sdk::Error, "WebSocket error: #{e.message}"
333
+ end
334
+ end
335
+
336
+ # Wait for completion
337
+ completion_queue.pop
338
+ end
339
+
340
+ # Sends input data to a command executed in a session
341
+ #
342
+ # This method allows you to send input to an interactive command running in a session,
343
+ # such as responding to prompts or providing data to stdin.
344
+ #
345
+ # @param session_id [String] Unique identifier of the session
346
+ # @param command_id [String] Unique identifier of the command
347
+ # @param data [String] Input data to send to the command
348
+ # @return [void]
349
+ def send_session_command_input(session_id:, command_id:, data:)
350
+ toolbox_api.send_input(
351
+ session_id,
352
+ command_id,
353
+ CogboxToolboxApiClient::SessionSendInputRequest.new(data:)
354
+ )
355
+ end
356
+
357
+ #
358
+ # @return [Array<CogboxApiClient::Session>] List of all sessions in the Sandbox
359
+ #
360
+ # @example
361
+ # sessions = sandbox.process.list_sessions
362
+ # sessions.each do |session|
363
+ # puts "Session #{session.session_id}:"
364
+ # puts " Commands: #{session.commands.length}"
365
+ # end
366
+ def list_sessions = toolbox_api.list_sessions
367
+
368
+ # Terminates and removes a session from the Sandbox, cleaning up any resources associated with it
369
+ #
370
+ # @param session_id [String] Unique identifier of the session to delete
371
+ #
372
+ # @example
373
+ # # Create and use a session
374
+ # sandbox.process.create_session("temp-session")
375
+ # # ... use the session ...
376
+ #
377
+ # # Clean up when done
378
+ # sandbox.process.delete_session("temp-session")
379
+ def delete_session(session_id) = toolbox_api.delete_session(session_id)
380
+
381
+ # Creates a new PTY (pseudo-terminal) session in the Sandbox.
382
+ #
383
+ # Creates an interactive terminal session that can execute commands and handle user input.
384
+ # The PTY session behaves like a real terminal, supporting features like command history.
385
+ #
386
+ # @param id [String] Unique identifier for the PTY session. Must be unique within the Sandbox.
387
+ # @param cwd [String, nil] Working directory for the PTY session. Defaults to the sandbox's working directory.
388
+ # @param envs [Hash<String, String>, nil] Environment variables to set in the PTY session. These will be merged with
389
+ # the Sandbox's default environment variables.
390
+ # @param pty_size [PtySize, nil] Terminal size configuration. Defaults to 80x24 if not specified.
391
+ # @return [PtyHandle] Handle for managing the created PTY session. Use this to send input,
392
+ # receive output, resize the terminal, and manage the session lifecycle.
393
+ #
394
+ # @example
395
+ # # Create a basic PTY session
396
+ # pty_handle = sandbox.process.create_pty_session(id: "my-pty")
397
+ #
398
+ # # Create a PTY session with specific size and environment
399
+ # pty_size = Cogbox::PtySize.new(rows: 30, cols: 120)
400
+ # pty_handle = sandbox.process.create_pty_session(
401
+ # id: "my-pty",
402
+ # cwd: "/workspace",
403
+ # envs: {"NODE_ENV" => "development"},
404
+ # pty_size: pty_size
405
+ # )
406
+ #
407
+ # # Use the PTY session
408
+ # pty_handle.wait_for_connection
409
+ # pty_handle.send_input("ls -la\n")
410
+ # result = pty_handle.wait
411
+ # pty_handle.disconnect
412
+ #
413
+ # @raise [Cogbox::Sdk::Error] If the PTY session creation fails or the session ID is already in use.
414
+ def create_pty_session(id:, cwd: nil, envs: nil, pty_size: nil) # rubocop:disable Metrics/MethodLength
415
+ response = toolbox_api.create_pty_session(
416
+ CogboxToolboxApiClient::PtyCreateRequest.new(
417
+ id:,
418
+ cwd:,
419
+ envs:,
420
+ cols: pty_size&.cols,
421
+ rows: pty_size&.rows,
422
+ lazy_start: true
423
+ )
424
+ )
425
+
426
+ connect_pty_session(response.session_id)
427
+ end
428
+
429
+ # Connects to an existing PTY session in the Sandbox.
430
+ #
431
+ # Establishes a WebSocket connection to an existing PTY session, allowing you to
432
+ # interact with a previously created terminal session.
433
+ #
434
+ # @param session_id [String] Unique identifier of the PTY session to connect to.
435
+ # @return [PtyHandle] Handle for managing the connected PTY session.
436
+ #
437
+ # @example
438
+ # # Connect to an existing PTY session
439
+ # pty_handle = sandbox.process.connect_pty_session("my-pty-session")
440
+ # pty_handle.wait_for_connection
441
+ # pty_handle.send_input("echo 'Hello World'\n")
442
+ # result = pty_handle.wait
443
+ # pty_handle.disconnect
444
+ #
445
+ # @raise [Cogbox::Sdk::Error] If the PTY session doesn't exist or connection fails.
446
+ def connect_pty_session(session_id) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
447
+ preview_link = get_preview_link.call(WS_PORT)
448
+ url = URI.parse(preview_link.url)
449
+ url.scheme = url.scheme == 'https' ? 'wss' : 'ws'
450
+ url.path = "/process/pty/#{session_id}/connect"
451
+
452
+ handle = nil
453
+ WebSocket::Client::Simple.connect(
454
+ url.to_s,
455
+ headers: toolbox_api.api_client.default_headers.dup.merge(
456
+ 'X-Cogbox-Preview-Token' => preview_link.token
457
+ )
458
+ ) do |client|
459
+ handle = PtyHandle.new(
460
+ client,
461
+ session_id:,
462
+ handle_resize: ->(pty_size) { resize_pty_session(session_id, pty_size) },
463
+ handle_kill: -> { delete_pty_session(session_id) }
464
+ )
465
+ end
466
+ handle.tap(&:wait_for_connection)
467
+ end
468
+
469
+ # Resizes a PTY session to the specified dimensions
470
+ #
471
+ # @param session_id [String] Unique identifier of the PTY session
472
+ # @param pty_size [PtySize] New terminal size
473
+ # @return [CogboxApiClient::PtySessionInfo] Updated PTY session information
474
+ #
475
+ # @example
476
+ # pty_size = Cogbox::PtySize.new(rows: 30, cols: 120)
477
+ # session_info = sandbox.process.resize_pty_session("my-pty", pty_size)
478
+ # puts "PTY resized to #{session_info.cols}x#{session_info.rows}"
479
+ def resize_pty_session(session_id, pty_size)
480
+ toolbox_api.resize_pty_session(
481
+ session_id,
482
+ CogboxToolboxApiClient::PtyResizeRequest.new(
483
+ cols: pty_size.cols,
484
+ rows: pty_size.rows
485
+ )
486
+ )
487
+ end
488
+
489
+ # Deletes a PTY session, terminating the associated process
490
+ #
491
+ # @param session_id [String] Unique identifier of the PTY session to delete
492
+ # @return [void]
493
+ #
494
+ # @example
495
+ # sandbox.process.delete_pty_session("my-pty")
496
+ def delete_pty_session(session_id)
497
+ toolbox_api.delete_pty_session(session_id)
498
+ end
499
+
500
+ # Lists all PTY sessions in the Sandbox
501
+ #
502
+ # @return [Array<CogboxApiClient::PtySessionInfo>] List of PTY session information
503
+ #
504
+ # @example
505
+ # sessions = sandbox.process.list_pty_sessions
506
+ # sessions.each do |session|
507
+ # puts "PTY Session #{session.id}: #{session.cols}x#{session.rows}"
508
+ # end
509
+ def list_pty_sessions
510
+ response = toolbox_api.list_pty_sessions
511
+ return [] if response.nil?
512
+
513
+ response.respond_to?(:sessions) ? (response.sessions || []) : response
514
+ end
515
+
516
+ # Gets detailed information about a specific PTY session
517
+ #
518
+ # Retrieves comprehensive information about a PTY session including its current state,
519
+ # configuration, and metadata.
520
+ #
521
+ # @param session_id [String] Unique identifier of the PTY session to retrieve information for
522
+ # @return [CogboxApiClient::PtySessionInfo] Detailed information about the PTY session including ID, state,
523
+ # creation time, working directory, environment variables, and more
524
+ #
525
+ # @example
526
+ # # Get details about a specific PTY session
527
+ # session_info = sandbox.process.get_pty_session_info("my-session")
528
+ # puts "Session ID: #{session_info.id}"
529
+ # puts "Active: #{session_info.active}"
530
+ # puts "Working Directory: #{session_info.cwd}"
531
+ # puts "Terminal Size: #{session_info.cols}x#{session_info.rows}"
532
+ def get_pty_session_info(session_id)
533
+ toolbox_api.get_pty_session(session_id)
534
+ end
535
+
536
+ instrument :exec, :code_run, :create_session, :get_session, :get_session_command,
537
+ :execute_session_command, :get_session_command_logs, :get_session_command_logs_async,
538
+ :send_session_command_input, :list_sessions, :delete_session,
539
+ :create_pty_session, :connect_pty_session, :resize_pty_session,
540
+ :delete_pty_session, :list_pty_sessions, :get_pty_session_info,
541
+ component: 'Process'
542
+
543
+ private
544
+
545
+ # @return [Cogbox::OtelState, nil]
546
+ attr_reader :otel_state
547
+
548
+ WS_PORT = 2280
549
+ private_constant :WS_PORT
550
+ end
551
+ end