pinesandbox 0.3.19 → 0.3.21
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/README.md +154 -33
- data/lib/pinesandbox/adapters/connect_aware_net_http.rb +32 -0
- data/lib/pinesandbox/adapters/coordinator_adapter.rb +153 -135
- data/lib/pinesandbox/agent_mode.rb +32 -18
- data/lib/pinesandbox/agent_turn.rb +2 -1
- data/lib/pinesandbox/artifacts.rb +785 -0
- data/lib/pinesandbox/attach_credentials_source.rb +100 -15
- data/lib/pinesandbox/author_terminal_translator.rb +12 -11
- data/lib/pinesandbox/client.rb +83 -30
- data/lib/pinesandbox/computer.rb +181 -81
- data/lib/pinesandbox/connection.rb +7 -3
- data/lib/pinesandbox/control_plane.rb +29 -15
- data/lib/pinesandbox/control_token_source.rb +3 -1
- data/lib/pinesandbox/diagnostics.rb +4 -3
- data/lib/pinesandbox/error_taxonomy.rb +6 -0
- data/lib/pinesandbox/errors.rb +168 -12
- data/lib/pinesandbox/models/artifact_file.rb +40 -0
- data/lib/pinesandbox/models/computer_session.rb +7 -3
- data/lib/pinesandbox/operations.rb +2 -0
- data/lib/pinesandbox/response_handler.rb +4 -1
- data/lib/pinesandbox/runtime_admission.rb +112 -0
- data/lib/pinesandbox/sandbox_handle.rb +71 -39
- data/lib/pinesandbox/session.rb +22 -3
- data/lib/pinesandbox/streamed_read.rb +80 -0
- data/lib/pinesandbox/terminal_reason.rb +31 -0
- data/lib/pinesandbox/timeouts.rb +22 -0
- data/lib/pinesandbox/version.rb +3 -1
- data/lib/pinesandbox/zone.rb +3 -0
- data/lib/pinesandbox.rb +4 -0
- metadata +8 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "securerandom"
|
|
2
2
|
require_relative "errors"
|
|
3
3
|
require_relative "clock"
|
|
4
|
+
require_relative "runtime_admission"
|
|
4
5
|
|
|
5
6
|
module PineSandbox
|
|
6
7
|
# Lifecycle handle for a Computer sandbox, backed by the project-scoped
|
|
@@ -9,8 +10,6 @@ module PineSandbox
|
|
|
9
10
|
# the coordinator host is derived separately from the Zone.
|
|
10
11
|
# @api private
|
|
11
12
|
class SandboxHandle
|
|
12
|
-
READY = :running
|
|
13
|
-
WAIT_FAILURE_STATES = %i[failed terminated unavailable].freeze
|
|
14
13
|
LIVE = %i[running pending stopping].freeze
|
|
15
14
|
DEFAULT_POLL_INTERVAL = 2
|
|
16
15
|
|
|
@@ -19,7 +18,8 @@ module PineSandbox
|
|
|
19
18
|
|
|
20
19
|
# `clock` returns monotonic seconds and `sleeper` waits; both default to
|
|
21
20
|
# the control plane's clock.
|
|
22
|
-
|
|
21
|
+
# status and reason: the create response's observation, when there is one.
|
|
22
|
+
def initialize(control_plane:, sandbox_id: nil, status: nil, reason: nil, clock: nil, sleeper: nil)
|
|
23
23
|
id = sandbox_id
|
|
24
24
|
raise ArgumentError, "sandbox_id required" if id.to_s.empty?
|
|
25
25
|
|
|
@@ -27,16 +27,18 @@ module PineSandbox
|
|
|
27
27
|
@control_plane = control_plane
|
|
28
28
|
@id = id.to_s
|
|
29
29
|
@status = status
|
|
30
|
+
@reason = reason
|
|
30
31
|
@clock = clock || -> { source.monotonic }
|
|
31
32
|
@sleeper = sleeper || ->(seconds) { source.sleep(seconds) }
|
|
32
33
|
end
|
|
33
34
|
|
|
34
35
|
# Allocation may reuse Running from its create response. Memory resume must
|
|
35
36
|
# discard that observation and wait for the controller's new completion.
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
# started: when the caller's ready_timeout began (errors report time waited since).
|
|
38
|
+
def wait_until_running(timeout:, interval: DEFAULT_POLL_INTERVAL, started: nil)
|
|
39
|
+
return self if RuntimeAdmission.decide_new_runtime(@status) == :done
|
|
38
40
|
|
|
39
|
-
wait_until_state(:running, timeout: timeout, interval: interval)
|
|
41
|
+
wait_until_state(:running, timeout: timeout, interval: interval, started: started, new_runtime: true)
|
|
40
42
|
end
|
|
41
43
|
|
|
42
44
|
def pause(timeout: 360, interval: DEFAULT_POLL_INTERVAL)
|
|
@@ -64,25 +66,26 @@ module PineSandbox
|
|
|
64
66
|
|
|
65
67
|
# Observe existing intent before admitting a new operation. No SDK memory
|
|
66
68
|
# or saved operation cursor is needed to continue Stop from another backend.
|
|
69
|
+
# The wait bounds only the polling: false means the Stop was submitted (or
|
|
70
|
+
# the runtime was already shutting down), and a submit failure raises.
|
|
67
71
|
def stop(wait_timeout: 390, interval: DEFAULT_POLL_INTERVAL)
|
|
68
|
-
return false if wait_timeout <= 0
|
|
69
|
-
|
|
70
72
|
deadline = @clock.call + wait_timeout
|
|
71
|
-
info = @control_plane.get(@id, request_timeout:
|
|
73
|
+
info = @control_plane.get(@id, request_timeout: submit_timeout(deadline))
|
|
72
74
|
return true if released?(info)
|
|
73
75
|
if info.status == :save_failed && !info.retryable
|
|
74
76
|
raise StopSaveError.new(Error.new(info.message), retryable: false)
|
|
75
77
|
end
|
|
76
78
|
unless %i[saving stopping].include?(info.status)
|
|
77
79
|
begin
|
|
78
|
-
@control_plane.stop(@id, operation_id: SecureRandom.uuid, request_timeout:
|
|
80
|
+
@control_plane.stop(@id, operation_id: SecureRandom.uuid, request_timeout: submit_timeout(deadline))
|
|
79
81
|
rescue PineSandbox::ConflictError
|
|
80
82
|
# A concurrent caller may have admitted Stop first. Join only that
|
|
81
83
|
# actual operation; a memory-transition conflict is still an error.
|
|
82
|
-
info = @control_plane.get(@id, request_timeout:
|
|
84
|
+
info = @control_plane.get(@id, request_timeout: submit_timeout(deadline))
|
|
83
85
|
raise unless %i[saving stopping].include?(info.status)
|
|
84
86
|
end
|
|
85
87
|
end
|
|
88
|
+
submitted = true
|
|
86
89
|
loop do
|
|
87
90
|
info = next_observation(info, deadline, interval)
|
|
88
91
|
return true if released?(info)
|
|
@@ -93,26 +96,47 @@ module PineSandbox
|
|
|
93
96
|
rescue PineSandbox::NotFoundError
|
|
94
97
|
true
|
|
95
98
|
rescue PineSandbox::TimeoutError
|
|
96
|
-
raise
|
|
99
|
+
raise unless submitted && @clock.call >= deadline
|
|
97
100
|
|
|
98
101
|
false
|
|
99
102
|
end
|
|
100
103
|
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
# Applies the admission table's column (:start or :recover) to the current
|
|
105
|
+
# runtime `info` (nil: none) and to each new observation while it says wait,
|
|
106
|
+
# until `deadline` (monotonic seconds). A release is a DELETE fenced by the
|
|
107
|
+
# observed ETag, which discards retained memory.
|
|
108
|
+
def admit(column, info, started:, deadline:, interval: DEFAULT_POLL_INTERVAL)
|
|
109
|
+
released = nil
|
|
110
|
+
loop do
|
|
111
|
+
decision = RuntimeAdmission.decide(column, info&.status, info&.reason)
|
|
112
|
+
case decision.action
|
|
113
|
+
when :proceed then return self
|
|
114
|
+
when :refuse
|
|
115
|
+
refusal = decision.refusal == :already_started ? ComputerAlreadyStartedError : SandboxRetainedError
|
|
116
|
+
raise refusal.new(sandbox_id: @id, state: info.status, reason: info.reason,
|
|
117
|
+
message: PineSandbox.runtime_message(decision.message, sandbox_id: @id))
|
|
118
|
+
when :release
|
|
119
|
+
# Release each observed version once; the wait below sees it go.
|
|
120
|
+
unless released && info.etag == released
|
|
121
|
+
raise Error, PineSandbox.runtime_message(:no_version, sandbox_id: @id) if info.etag.to_s.empty?
|
|
122
|
+
@control_plane.destroy(@id, if_match: info.etag, request_timeout: remaining(deadline))
|
|
123
|
+
released = info.etag
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
info = begin
|
|
127
|
+
next_observation(info, deadline, interval)
|
|
128
|
+
rescue PineSandbox::NotFoundError
|
|
129
|
+
nil
|
|
108
130
|
end
|
|
109
|
-
raise PineSandbox::Error, "Server did not supply a conditional release version" if info.etag.to_s.empty?
|
|
110
|
-
@control_plane.destroy(@id, if_match: info.etag, request_timeout: remaining(deadline))
|
|
111
131
|
end
|
|
112
|
-
wait_until_released(info, deadline, interval)
|
|
113
132
|
rescue PineSandbox::TimeoutError
|
|
114
133
|
raise if @clock.call < deadline
|
|
115
|
-
|
|
134
|
+
|
|
135
|
+
waited = @clock.call - started
|
|
136
|
+
text = PineSandbox.runtime_message(RuntimeAdmission.decide(column, info.status, info.reason).message,
|
|
137
|
+
sandbox_id: @id, waited: waited)
|
|
138
|
+
raise ReadyTimeoutError.new(text, sandbox_id: @id, last_state: info.status, last_reason: info.reason,
|
|
139
|
+
waited: waited)
|
|
116
140
|
end
|
|
117
141
|
|
|
118
142
|
# Delete, then wait for the sandbox record to disappear. This confirms
|
|
@@ -189,52 +213,60 @@ module PineSandbox
|
|
|
189
213
|
timeout
|
|
190
214
|
end
|
|
191
215
|
|
|
216
|
+
def submit_timeout(deadline)
|
|
217
|
+
[deadline - @clock.call, @control_plane.request_timeout].max
|
|
218
|
+
end
|
|
219
|
+
|
|
192
220
|
def released?(info)
|
|
193
|
-
info.status
|
|
221
|
+
!info.status.nil? && RuntimeAdmission.decide(:start, info.status, info.reason).action == :proceed
|
|
194
222
|
end
|
|
195
223
|
|
|
196
224
|
def transition_memory(operation, target, timeout:, interval:)
|
|
197
225
|
raise ArgumentError, "timeout must be positive" unless timeout.positive?
|
|
198
226
|
|
|
199
|
-
|
|
227
|
+
started = @clock.call
|
|
228
|
+
deadline = started + timeout
|
|
200
229
|
accepted = @control_plane.public_send(operation, @id, request_timeout: timeout)
|
|
201
|
-
@status = nil
|
|
230
|
+
@status = @reason = nil
|
|
202
231
|
unless accepted
|
|
203
232
|
# Older Docker servers answer 409 for an already completed transition.
|
|
204
233
|
remaining = deadline - @clock.call
|
|
205
|
-
raise
|
|
234
|
+
raise ready_timeout(target, started, new_runtime: false) if remaining <= 0
|
|
206
235
|
return self if refresh_status(request_timeout: remaining) == target
|
|
207
236
|
|
|
208
237
|
raise PineSandbox::ConflictError.new(status: 409, error_message: "Computer #{@id} cannot #{operation} in its current state")
|
|
209
238
|
end
|
|
210
|
-
wait_until_state(target, timeout: deadline - @clock.call, interval: interval)
|
|
239
|
+
wait_until_state(target, timeout: deadline - @clock.call, interval: interval, started: started, new_runtime: false)
|
|
211
240
|
end
|
|
212
241
|
|
|
213
|
-
def wait_until_state(target, timeout:, interval:)
|
|
242
|
+
def wait_until_state(target, timeout:, interval:, started:, new_runtime:)
|
|
243
|
+
started ||= @clock.call
|
|
214
244
|
deadline = @clock.call + timeout
|
|
215
245
|
info = nil
|
|
216
246
|
loop do
|
|
217
|
-
|
|
218
|
-
if remaining <= 0
|
|
219
|
-
raise PineSandbox::ReadyTimeoutError, "Computer #{@id} did not reach #{target} before the deadline (last state #{@status.inspect})"
|
|
220
|
-
end
|
|
247
|
+
raise ready_timeout(target, started, new_runtime: new_runtime) if deadline - @clock.call <= 0
|
|
221
248
|
begin
|
|
222
249
|
info = next_observation(info, deadline, interval)
|
|
223
250
|
state = @status = info.status
|
|
251
|
+
@reason = info.reason
|
|
224
252
|
rescue PineSandbox::TimeoutError => error
|
|
225
253
|
raise error if @clock.call < deadline
|
|
226
254
|
|
|
227
|
-
raise
|
|
255
|
+
raise ready_timeout(target, started, new_runtime: new_runtime)
|
|
228
256
|
end
|
|
229
|
-
return self if state == target
|
|
230
|
-
if
|
|
231
|
-
raise PineSandbox::SandboxFailedError.new(
|
|
232
|
-
|
|
233
|
-
)
|
|
257
|
+
return self if new_runtime ? RuntimeAdmission.decide_new_runtime(state) == :done : state == target
|
|
258
|
+
if RuntimeAdmission.decide_new_runtime(state) == :fail
|
|
259
|
+
raise PineSandbox::SandboxFailedError.new(sandbox_id: @id, state: state, reason: @reason,
|
|
260
|
+
target: target, new_runtime: new_runtime)
|
|
234
261
|
end
|
|
235
262
|
end
|
|
236
263
|
end
|
|
237
264
|
|
|
265
|
+
def ready_timeout(target, started, new_runtime:)
|
|
266
|
+
ReadyTimeoutError.new(sandbox_id: @id, last_state: @status, last_reason: @reason,
|
|
267
|
+
waited: @clock.call - started, target: target, new_runtime: new_runtime)
|
|
268
|
+
end
|
|
269
|
+
|
|
238
270
|
def refresh_status(request_timeout: nil)
|
|
239
271
|
@status = if request_timeout
|
|
240
272
|
@control_plane.get(@id, request_timeout: request_timeout).status
|
data/lib/pinesandbox/session.rb
CHANGED
|
@@ -19,11 +19,17 @@ module PineSandbox
|
|
|
19
19
|
# tabs, focus, epoch, drive actions, passkey intent and decisions) need the
|
|
20
20
|
# session token.
|
|
21
21
|
class Session
|
|
22
|
+
# What a session's agent may do with the Computer's artifacts
|
|
23
|
+
# (Computer#create_session `artifact_access:`).
|
|
24
|
+
ARTIFACT_ACCESS = %w[none read_only read_write].freeze
|
|
25
|
+
|
|
22
26
|
attr_reader :info, :parent
|
|
23
27
|
|
|
24
|
-
|
|
28
|
+
# `artifact_access_known` is false when only the Computer knows the
|
|
29
|
+
# session's artifact access (Computer#adopt_session).
|
|
30
|
+
def initialize(parent:, payload:, artifact_access_known: true)
|
|
25
31
|
@parent = parent
|
|
26
|
-
@info = Models::Session.from_payload(payload)
|
|
32
|
+
@info = Models::Session.from_payload(payload, artifact_access_known: artifact_access_known)
|
|
27
33
|
raise PineSandbox::ApiError.new(status: 0, error_message: "empty session payload") if @info.nil?
|
|
28
34
|
end
|
|
29
35
|
|
|
@@ -52,6 +58,15 @@ module PineSandbox
|
|
|
52
58
|
info.session_dir
|
|
53
59
|
end
|
|
54
60
|
|
|
61
|
+
# What this session's agent may do with the Computer's artifacts, as set
|
|
62
|
+
# at create: "none", "read_only" or "read_write". "none" when the Computer
|
|
63
|
+
# doesn't say (an older one). nil for a session from
|
|
64
|
+
# Computer#adopt_session, whose access isn't known: read it with
|
|
65
|
+
# Computer#session(name).
|
|
66
|
+
def artifact_access
|
|
67
|
+
info.artifact_access
|
|
68
|
+
end
|
|
69
|
+
|
|
55
70
|
# session.agent.* — hand-off-the-loop driving (run/steer/answer/cancel/reset/
|
|
56
71
|
# status/result/events). The agent drives; you delegate goals. See {AgentMode}.
|
|
57
72
|
def agent
|
|
@@ -439,8 +454,12 @@ module PineSandbox
|
|
|
439
454
|
#
|
|
440
455
|
# `actor_type:` is REQUIRED; the Computer returns 400
|
|
441
456
|
# /errors/actor-type-required when missing.
|
|
457
|
+
#
|
|
458
|
+
# `idle_paused:` is deprecated: to give the person more time, pass a later
|
|
459
|
+
# `idle_deadline:`. A paused hold doesn't keep the Computer running.
|
|
442
460
|
def update_control(controller: nil, idle_paused: nil, idle_deadline: nil,
|
|
443
461
|
actor_type:, if_match:, force: false, idempotency_key: nil)
|
|
462
|
+
PineSandbox.deprecated_name("Session#update_control(idle_paused:)", "idle_deadline:") unless idle_paused.nil?
|
|
444
463
|
body = { actor_type: actor_type }
|
|
445
464
|
body[:controller] = controller unless controller.nil?
|
|
446
465
|
body[:idle_paused] = idle_paused unless idle_paused.nil?
|
|
@@ -499,7 +518,7 @@ module PineSandbox
|
|
|
499
518
|
# reach the browser. Driving needs control of the session, not this
|
|
500
519
|
# token, so the same token serves a viewer and a driver. Re-mint before
|
|
501
520
|
# each (re)connect. Returns { token:, expires_at: }. 409
|
|
502
|
-
# (NoDesktopStream)
|
|
521
|
+
# (NoDesktopStream) for a session an older SDK created as blind; 503
|
|
503
522
|
# (DesktopUnavailable) when streaming is off.
|
|
504
523
|
def desktop_token
|
|
505
524
|
ct_call { coordinator.mint_desktop_token(token: parent.computer_token, name: name) }
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require "tempfile"
|
|
2
|
+
|
|
3
|
+
module PineSandbox
|
|
4
|
+
# @api private — what the SDK's streamed reads of a body share: a file read
|
|
5
|
+
# from a Computer (Adapters::CoordinatorAdapter) and an artifact read from
|
|
6
|
+
# storage (Artifacts). Only a 2xx body reaches the caller, chunk by chunk as
|
|
7
|
+
# it arrives; an error answer's body is kept, bounded, for its error.
|
|
8
|
+
module StreamedRead
|
|
9
|
+
# A failed answer keeps this much of its body for the error.
|
|
10
|
+
ERROR_BODY_CAP = 64 * 1024
|
|
11
|
+
# Chunk size for passing on a body that was spooled to a temp file.
|
|
12
|
+
SPOOL_READ_SIZE = 64 * 1024
|
|
13
|
+
|
|
14
|
+
# Raised through Faraday's read loop in place of an exception from the
|
|
15
|
+
# caller's block, so the block's own error is never mistaken for a
|
|
16
|
+
# dropped connection. The streaming method raises #error again as it was.
|
|
17
|
+
class BlockError < StandardError
|
|
18
|
+
attr_reader :error
|
|
19
|
+
|
|
20
|
+
def initialize(error)
|
|
21
|
+
@error = error
|
|
22
|
+
super(error.message)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
module_function
|
|
27
|
+
|
|
28
|
+
# Calls the caller's block with `args` from inside Faraday's read loop,
|
|
29
|
+
# which would turn an IOError or EPIPE from the block into a dropped
|
|
30
|
+
# connection; the block's own error comes out as a BlockError.
|
|
31
|
+
def pass(block, *args)
|
|
32
|
+
block.call(*args)
|
|
33
|
+
rescue StandardError => e
|
|
34
|
+
raise BlockError.new(e)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Adds as much of `chunk` to `buffer` as keeps it within ERROR_BODY_CAP.
|
|
38
|
+
def keep_error_body(buffer, chunk)
|
|
39
|
+
remaining = ERROR_BODY_CAP - buffer.bytesize
|
|
40
|
+
buffer << chunk.byteslice(0, remaining) if remaining.positive?
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Reads one streamed GET. Yields the proc to set as the request's
|
|
44
|
+
# on_data; the block sends the request and returns its response. Each
|
|
45
|
+
# chunk of a 2xx body goes to `deliver` with its answer (the Faraday env,
|
|
46
|
+
# or the response) as it arrives. faraday-net_http before 3.0 passes no
|
|
47
|
+
# env and learns the status only after the body, so its chunks go to a
|
|
48
|
+
# temp file, not memory, and on to `deliver` once the status is known. An
|
|
49
|
+
# error answer's body, kept up to ERROR_BODY_CAP, becomes the response's
|
|
50
|
+
# body. Returns the response.
|
|
51
|
+
def read(deliver)
|
|
52
|
+
error_body = +""
|
|
53
|
+
spool = nil
|
|
54
|
+
on_data = proc do |chunk, _received, env|
|
|
55
|
+
if env.nil?
|
|
56
|
+
(spool ||= Tempfile.new("pinesandbox-read", binmode: true)).write(chunk)
|
|
57
|
+
elsif env.status.to_i.between?(200, 299)
|
|
58
|
+
deliver.call(chunk.b, env) unless chunk.empty?
|
|
59
|
+
else
|
|
60
|
+
keep_error_body(error_body, chunk)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
response = yield on_data
|
|
64
|
+
if spool
|
|
65
|
+
spool.rewind
|
|
66
|
+
if response.success?
|
|
67
|
+
while (chunk = spool.read(SPOOL_READ_SIZE))
|
|
68
|
+
deliver.call(chunk, response)
|
|
69
|
+
end
|
|
70
|
+
else
|
|
71
|
+
keep_error_body(error_body, spool.read(ERROR_BODY_CAP).to_s)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
response.env.body = error_body if !response.success? && response.body.to_s.empty?
|
|
75
|
+
response
|
|
76
|
+
ensure
|
|
77
|
+
spool&.close!
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Generated by specs/gen-signal-actions.py from sdks/pine-computer/contract/signal-actions.json. Do not edit; run `python3 specs/gen-signal-actions.py`.
|
|
2
|
+
# signal-actions source-sha256=63709f95953341c1d1db139bd8ff3b46837f30ed1ec978f7bf8b885d4e09ca18 body-sha256=5ced47750cea6b0dec02ebfd88cc5c8b3ff17b912ab01054b1782c9162cdb6a0
|
|
3
|
+
|
|
4
|
+
module PineSandbox
|
|
5
|
+
# @api private — the terminal_reason values of a turn's result: how a turn or a
|
|
6
|
+
# skill-author run ended.
|
|
7
|
+
module TerminalReason
|
|
8
|
+
COMPLETED = "completed".freeze
|
|
9
|
+
NEEDS_INPUT = "needs_input".freeze
|
|
10
|
+
BUDGET = "budget".freeze
|
|
11
|
+
CANCELED = "canceled".freeze
|
|
12
|
+
TIMEOUT = "timeout".freeze
|
|
13
|
+
INCOMPLETE = "incomplete".freeze
|
|
14
|
+
ERROR = "error".freeze
|
|
15
|
+
EXECUTOR_PANIC = "executor_panic".freeze
|
|
16
|
+
COORDINATOR_RESTARTED = "coordinator_restarted".freeze
|
|
17
|
+
STORAGE_EXHAUSTED = "storage_exhausted".freeze
|
|
18
|
+
OUTPUT_INVALID = "output_invalid".freeze
|
|
19
|
+
DRAFT_REGISTERED = "draft_registered".freeze
|
|
20
|
+
CLARIFICATION_REQUESTED = "clarification_requested".freeze
|
|
21
|
+
NOT_REUSABLE = "not_reusable".freeze
|
|
22
|
+
REGISTRATION_FAILED = "registration_failed".freeze
|
|
23
|
+
FAILED = "failed".freeze
|
|
24
|
+
TERMINAL_MISSING = "terminal_missing".freeze
|
|
25
|
+
|
|
26
|
+
# The skill-author run values the blocking learn and teach calls report as a failed run.
|
|
27
|
+
AUTHOR_FAILED = [ CANCELED, STORAGE_EXHAUSTED, REGISTRATION_FAILED, FAILED ].freeze
|
|
28
|
+
# The skill-author run values that mean the Computer's services restarted during the run.
|
|
29
|
+
AUTHOR_INTERRUPTED = [ COORDINATOR_RESTARTED ].freeze
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module PineSandbox
|
|
2
|
+
# The client's network timeouts, in seconds. `connect` bounds opening one
|
|
3
|
+
# connection: the TCP connect, then the TLS handshake. `request` bounds one request that
|
|
4
|
+
# has no budget of its own; a read the Computer holds open, such as a turn
|
|
5
|
+
# wait, gets its hold on top. A connection that could not be opened sent
|
|
6
|
+
# nothing, so the request is tried again within the retry policy.
|
|
7
|
+
Timeouts = Struct.new(:connect, :request) do
|
|
8
|
+
def initialize(connect: Timeouts::DEFAULT_CONNECT, request: Timeouts::DEFAULT_REQUEST)
|
|
9
|
+
{ connect: connect, request: request }.each do |name, value|
|
|
10
|
+
next if value.is_a?(Numeric) && value.positive? && value.finite?
|
|
11
|
+
|
|
12
|
+
raise ArgumentError, "#{name}_timeout must be a positive number of seconds, got #{value.inspect}"
|
|
13
|
+
end
|
|
14
|
+
super(connect, request)
|
|
15
|
+
freeze
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Timeouts::DEFAULT_CONNECT = 10
|
|
20
|
+
Timeouts::DEFAULT_REQUEST = 30
|
|
21
|
+
Timeouts::DEFAULT = Timeouts.new
|
|
22
|
+
end
|
data/lib/pinesandbox/version.rb
CHANGED
data/lib/pinesandbox/zone.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
require "faraday"
|
|
2
2
|
require "uri"
|
|
3
3
|
|
|
4
|
+
require_relative "adapters/connect_aware_net_http"
|
|
5
|
+
|
|
4
6
|
module PineSandbox
|
|
5
7
|
# Resolves the per-deployment hosts from a single zone (e.g. "pinesandbox.io"):
|
|
6
8
|
#
|
|
@@ -54,6 +56,7 @@ module PineSandbox
|
|
|
54
56
|
url, host_header = dial(scheme: scheme, host: host, gateway_url: gateway_url)
|
|
55
57
|
Faraday.new(url: url) do |conn|
|
|
56
58
|
conn.headers["Host"] = host_header if host_header
|
|
59
|
+
conn.adapter Adapters::ConnectAwareNetHttp
|
|
57
60
|
yield conn if block_given?
|
|
58
61
|
end
|
|
59
62
|
end
|
data/lib/pinesandbox.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require_relative "pinesandbox/version"
|
|
2
2
|
require_relative "pinesandbox/clock"
|
|
3
|
+
require_relative "pinesandbox/timeouts"
|
|
3
4
|
require_relative "pinesandbox/errors"
|
|
4
5
|
require_relative "pinesandbox/operations"
|
|
5
6
|
require_relative "pinesandbox/response_handler"
|
|
@@ -8,8 +9,10 @@ require_relative "pinesandbox/models/computer_session"
|
|
|
8
9
|
require_relative "pinesandbox/models/computer_tab"
|
|
9
10
|
require_relative "pinesandbox/models/file_entry"
|
|
10
11
|
require_relative "pinesandbox/models/artifact"
|
|
12
|
+
require_relative "pinesandbox/models/artifact_file"
|
|
11
13
|
require_relative "pinesandbox/sse_frame_parser"
|
|
12
14
|
require_relative "pinesandbox/control_events"
|
|
15
|
+
require_relative "pinesandbox/terminal_reason"
|
|
13
16
|
require_relative "pinesandbox/agent_events"
|
|
14
17
|
require_relative "pinesandbox/agent_turn"
|
|
15
18
|
require_relative "pinesandbox/control_state"
|
|
@@ -20,6 +23,7 @@ require_relative "pinesandbox/capture_keypair"
|
|
|
20
23
|
require_relative "pinesandbox/adapters/coordinator_adapter"
|
|
21
24
|
require_relative "pinesandbox/adapters/snapshot_adapter"
|
|
22
25
|
require_relative "pinesandbox/skills"
|
|
26
|
+
require_relative "pinesandbox/artifacts"
|
|
23
27
|
require_relative "pinesandbox/author_terminal_translator"
|
|
24
28
|
require_relative "pinesandbox/session"
|
|
25
29
|
require_relative "pinesandbox/control_token_source"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pinesandbox
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.21
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Pine AI
|
|
@@ -121,11 +121,13 @@ files:
|
|
|
121
121
|
- README.md
|
|
122
122
|
- Rakefile
|
|
123
123
|
- lib/pinesandbox.rb
|
|
124
|
+
- lib/pinesandbox/adapters/connect_aware_net_http.rb
|
|
124
125
|
- lib/pinesandbox/adapters/coordinator_adapter.rb
|
|
125
126
|
- lib/pinesandbox/adapters/snapshot_adapter.rb
|
|
126
127
|
- lib/pinesandbox/agent_events.rb
|
|
127
128
|
- lib/pinesandbox/agent_mode.rb
|
|
128
129
|
- lib/pinesandbox/agent_turn.rb
|
|
130
|
+
- lib/pinesandbox/artifacts.rb
|
|
129
131
|
- lib/pinesandbox/attach_credentials_source.rb
|
|
130
132
|
- lib/pinesandbox/author_terminal_translator.rb
|
|
131
133
|
- lib/pinesandbox/bind_hpke.rb
|
|
@@ -147,11 +149,13 @@ files:
|
|
|
147
149
|
- lib/pinesandbox/errors.rb
|
|
148
150
|
- lib/pinesandbox/exec_stream_parser.rb
|
|
149
151
|
- lib/pinesandbox/models/artifact.rb
|
|
152
|
+
- lib/pinesandbox/models/artifact_file.rb
|
|
150
153
|
- lib/pinesandbox/models/computer_session.rb
|
|
151
154
|
- lib/pinesandbox/models/computer_tab.rb
|
|
152
155
|
- lib/pinesandbox/models/file_entry.rb
|
|
153
156
|
- lib/pinesandbox/operations.rb
|
|
154
157
|
- lib/pinesandbox/response_handler.rb
|
|
158
|
+
- lib/pinesandbox/runtime_admission.rb
|
|
155
159
|
- lib/pinesandbox/sandbox_details.rb
|
|
156
160
|
- lib/pinesandbox/sandbox_handle.rb
|
|
157
161
|
- lib/pinesandbox/session.rb
|
|
@@ -159,6 +163,9 @@ files:
|
|
|
159
163
|
- lib/pinesandbox/spec_version_middleware.rb
|
|
160
164
|
- lib/pinesandbox/sse_frame_parser.rb
|
|
161
165
|
- lib/pinesandbox/state_hpke.rb
|
|
166
|
+
- lib/pinesandbox/streamed_read.rb
|
|
167
|
+
- lib/pinesandbox/terminal_reason.rb
|
|
168
|
+
- lib/pinesandbox/timeouts.rb
|
|
162
169
|
- lib/pinesandbox/version.rb
|
|
163
170
|
- lib/pinesandbox/zone.rb
|
|
164
171
|
- pinesandbox.gemspec
|