e2b 0.3.3 → 0.3.4

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: 0fa9c1779eddd80d88939182c59ed84697bbcd75af38bacc61ea2272dee24b45
4
- data.tar.gz: 547824e29330fb45199e9cd4b3ccb4ebc388edb92a39ebabd32a229a4db49300
3
+ metadata.gz: dfc3dc31658813cd8fb30e3ad23464287d65a0c44fe604092b88af9943e6cc95
4
+ data.tar.gz: 944847469b79e7da14d8f347c21cbc564bc44d76ae426c4f338c020f1497ff45
5
5
  SHA512:
6
- metadata.gz: f05cba4db6cf6273d4ae2caf5e9f47755adea8059af6617cdb87b316d7b0a29fef87c8cfc32db9ed04d657f16d3876e6c4da274a26f05026fcb4187d5cd4632c
7
- data.tar.gz: 2f010ab757dec6053bf033e472f817b3fddfa5e22f2fc6e8180e2bca6eb70241f2a22dc520662e947c941d3634c76b3dc893f20caa6f58d9f36a6e8aa54fccf0
6
+ metadata.gz: 479f9080d1a96b9ae2e7508f79d2ee3fdd17d82519a7a395bbcd2bc7c4864d3b99b43c29a66812ba4156c43f87751d49ccec267eb36a808118bf5bffd9cf98ce
7
+ data.tar.gz: ab09177f228a09b7c4c350324ab352de99d2c86ad8a8d8c25849923c3ad6b35ccb524ddbcd58f98dae7ce3a4c2920bccca57bf33cf4b91e27ec2ebfa53b0ca32
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "../services/envd_base64"
4
+
3
5
  module E2B
4
6
  module Models
5
7
  # Result of a process execution
@@ -76,11 +78,7 @@ module E2B
76
78
  end
77
79
 
78
80
  def self.decode_base64_safe(data)
79
- return "" if data.nil? || data.empty?
80
-
81
- Base64.decode64(data)
82
- rescue
83
- data.to_s
81
+ E2B::Services::EnvdBase64.decode_process_output(data)
84
82
  end
85
83
 
86
84
  # Parse exit code from various formats
@@ -4,6 +4,7 @@ require "base64"
4
4
  require "net/http"
5
5
  require "openssl"
6
6
  require "rubygems/version"
7
+ require_relative "envd_base64"
7
8
 
8
9
  module E2B
9
10
  module Services
@@ -315,8 +316,8 @@ module E2B
315
316
 
316
317
  data_event = event["Data"] || event["data"]
317
318
  if data_event
318
- stdout_data = decode_base64(data_event["stdout"]) if data_event["stdout"]
319
- stderr_data = decode_base64(data_event["stderr"]) if data_event["stderr"]
319
+ stdout_data = EnvdBase64.decode_process_output(data_event["stdout"]) if data_event["stdout"]
320
+ stderr_data = EnvdBase64.decode_process_output(data_event["stderr"]) if data_event["stderr"]
320
321
  result[:stdout] += stdout_data if stdout_data
321
322
  result[:stderr] += stderr_data if stderr_data
322
323
  end
@@ -328,11 +329,11 @@ module E2B
328
329
  end
329
330
 
330
331
  if msg["stdout"]
331
- stdout_data = decode_base64(msg["stdout"])
332
+ stdout_data = EnvdBase64.decode_process_output(msg["stdout"])
332
333
  result[:stdout] += stdout_data
333
334
  end
334
335
  if msg["stderr"]
335
- stderr_data = decode_base64(msg["stderr"])
336
+ stderr_data = EnvdBase64.decode_process_output(msg["stderr"])
336
337
  result[:stderr] += stderr_data
337
338
  end
338
339
  if msg["exitCode"] || msg["exit_code"]
@@ -495,8 +496,8 @@ module E2B
495
496
 
496
497
  data_event = event["Data"] || event["data"]
497
498
  if data_event
498
- result[:stdout] += decode_base64(data_event["stdout"]) if data_event["stdout"]
499
- result[:stderr] += decode_base64(data_event["stderr"]) if data_event["stderr"]
499
+ result[:stdout] += EnvdBase64.decode_process_output(data_event["stdout"]) if data_event["stdout"]
500
+ result[:stderr] += EnvdBase64.decode_process_output(data_event["stderr"]) if data_event["stderr"]
500
501
  end
501
502
 
502
503
  end_event = event["End"] || event["end"]
@@ -506,8 +507,8 @@ module E2B
506
507
  end
507
508
  end
508
509
 
509
- result[:stdout] += decode_base64(msg["stdout"]) if msg["stdout"]
510
- result[:stderr] += decode_base64(msg["stderr"]) if msg["stderr"]
510
+ result[:stdout] += EnvdBase64.decode_process_output(msg["stdout"]) if msg["stdout"]
511
+ result[:stderr] += EnvdBase64.decode_process_output(msg["stderr"]) if msg["stderr"]
511
512
  if msg["exitCode"] || msg["exit_code"]
512
513
  result[:exit_code] = parse_exit_code(msg["exitCode"] || msg["exit_code"])
513
514
  end
@@ -576,14 +577,6 @@ module E2B
576
577
  end
577
578
  end
578
579
 
579
- def decode_base64(data)
580
- return "" if data.nil? || data.empty?
581
-
582
- Base64.decode64(data)
583
- rescue StandardError
584
- data.to_s
585
- end
586
-
587
580
  def handle_error(response)
588
581
  message = extract_error_message(response)
589
582
  status = response.status
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "base64"
3
+ require_relative "envd_base64"
4
4
 
5
5
  module E2B
6
6
  module Services
@@ -360,8 +360,8 @@ module E2B
360
360
  process_event(event) { |stdout_chunk, stderr_chunk, pty_chunk| yield stdout_chunk, stderr_chunk, pty_chunk } if event.is_a?(Hash)
361
361
 
362
362
  if event.nil?
363
- stdout_chunk = decode_base64(message["stdout"])
364
- stderr_chunk = decode_base64(message["stderr"])
363
+ stdout_chunk = EnvdBase64.decode_process_output(message["stdout"])
364
+ stderr_chunk = EnvdBase64.decode_process_output(message["stderr"])
365
365
 
366
366
  if stdout_chunk && !stdout_chunk.empty?
367
367
  append_stdout(stdout_chunk)
@@ -387,9 +387,9 @@ module E2B
387
387
  # Handle Data event
388
388
  data_event = event["Data"] || event["data"]
389
389
  if data_event
390
- stdout_chunk = decode_base64(data_event["stdout"])
391
- stderr_chunk = decode_base64(data_event["stderr"])
392
- pty_chunk = decode_base64(data_event["pty"])
390
+ stdout_chunk = EnvdBase64.decode_process_output(data_event["stdout"])
391
+ stderr_chunk = EnvdBase64.decode_process_output(data_event["stderr"])
392
+ pty_chunk = EnvdBase64.decode_process_output(data_event["pty"])
393
393
 
394
394
  if stdout_chunk && !stdout_chunk.empty?
395
395
  append_stdout(stdout_chunk)
@@ -467,18 +467,6 @@ module E2B
467
467
  nil
468
468
  end
469
469
 
470
- # Decode a base64-encoded string.
471
- #
472
- # @param data [String, nil] Base64-encoded data
473
- # @return [String, nil] Decoded string, or nil if input is nil/empty
474
- def decode_base64(data)
475
- return nil if data.nil? || data.empty?
476
-
477
- Base64.decode64(data).force_encoding("UTF-8")
478
- rescue StandardError
479
- data.to_s
480
- end
481
-
482
470
  # Parse an exit code from various envd response formats.
483
471
  #
484
472
  # Handles integer values, string integers, and "exit status N" strings.
@@ -36,11 +36,15 @@ module E2B
36
36
  # @param on_stderr [Proc, nil] Callback for stderr data
37
37
  # @param timeout [Integer] Command timeout in seconds (default: 60)
38
38
  # @param request_timeout [Integer, nil] HTTP request timeout in seconds
39
+ # @param stdin [Boolean] Allocate a stdin pipe for the process. Required
40
+ # when the caller plans to use {#send_stdin} or {CommandHandle#send_stdin}
41
+ # on a background handle. Defaults to +false+ to mirror TS/Python SDKs.
39
42
  # @return [CommandResult, CommandHandle] Result or handle for background commands
40
43
  #
41
44
  # @raise [CommandExitError] If exit code is non-zero (foreground only)
42
45
  def run(cmd, background: false, envs: nil, user: nil, cwd: nil,
43
- on_stdout: nil, on_stderr: nil, timeout: 60, request_timeout: nil, &block)
46
+ on_stdout: nil, on_stderr: nil, timeout: 60, request_timeout: nil,
47
+ stdin: false, &block)
44
48
  # Build the process spec - official SDK always uses /bin/bash -l -c
45
49
  process_spec = {
46
50
  cmd: "/bin/bash",
@@ -55,7 +59,7 @@ module E2B
55
59
 
56
60
  process_spec[:cwd] = cwd if cwd
57
61
 
58
- body = { process: process_spec }
62
+ body = { process: process_spec, stdin: stdin }
59
63
  headers = user_auth_headers(user)
60
64
 
61
65
  # Set up streaming callback
@@ -150,7 +154,11 @@ module E2B
150
154
  false
151
155
  end
152
156
 
153
- # Send stdin data to a running process
157
+ # Send stdin data to a running process.
158
+ #
159
+ # The target process must have been started with +stdin: true+ (see {#run})
160
+ # — otherwise envd silently drops the input and the call is a no-op on the
161
+ # process side.
154
162
  #
155
163
  # @param pid [Integer] Process ID
156
164
  # @param data [String] Data to send to stdin
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "base64"
4
+
5
+ module E2B
6
+ module Services
7
+ # Base64 payloads from envd wrap raw subprocess / PTY bytes.
8
+ module EnvdBase64
9
+ module_function
10
+
11
+ # @param data [String, nil] base64-encoded chunk from envd
12
+ # @return [String] UTF-8 string with invalid byte sequences scrubbed; "" if +data+ is nil or empty
13
+ def decode_process_output(data)
14
+ return "" if data.nil? || data.empty?
15
+
16
+ Base64.decode64(data).force_encoding(Encoding::UTF_8).scrub
17
+ rescue StandardError
18
+ data.to_s
19
+ end
20
+ end
21
+ end
22
+ end
@@ -98,7 +98,8 @@ module E2B
98
98
  process: process_spec,
99
99
  pty: {
100
100
  size: size.to_h
101
- }
101
+ },
102
+ stdin: false
102
103
  }
103
104
 
104
105
  build_live_handle(
data/lib/e2b/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module E2B
4
- VERSION = "0.3.3"
4
+ VERSION = "0.3.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: e2b
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tao Luo
@@ -134,6 +134,7 @@ files:
134
134
  - lib/e2b/services/base_service.rb
135
135
  - lib/e2b/services/command_handle.rb
136
136
  - lib/e2b/services/commands.rb
137
+ - lib/e2b/services/envd_base64.rb
137
138
  - lib/e2b/services/filesystem.rb
138
139
  - lib/e2b/services/git.rb
139
140
  - lib/e2b/services/live_streamable.rb