kosa8 0.3.1 → 0.4.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.
data/lib/kosa8/errors.rb CHANGED
@@ -28,8 +28,39 @@ module Kosa8
28
28
  class NotFoundError < ApiError; end # 404
29
29
  class ConflictError < ApiError; end # 409
30
30
  class UnsupportedError < ApiError; end # 501
31
- class PaymentRequiredError < ApiError; end # 402: kosa8 Cloud wants a payment method first
32
- class RateLimitError < ApiError; end # 429: too many requests, or a quota reached
31
+
32
+ # 402: kosa8 Cloud wants a payment method, credit or an accepted price first
33
+ # (+code+ payment_required, spending_cap_reached, price_not_accepted, ...).
34
+ class PaymentRequiredError < ApiError
35
+ # Where the person adds a payment method or credit; nil when the answer has none.
36
+ def upgrade_url
37
+ Kosa8.body_str(body, "upgrade_url")
38
+ end
39
+
40
+ # A sentence an AI agent should relay to its person word for word; nil when absent.
41
+ def agent_message
42
+ Kosa8.body_str(body, "agent_message")
43
+ end
44
+ end
45
+
46
+ # 429: too many requests, or a quota reached (+code+ quota_exceeded).
47
+ # +retry_after+ is the server's Retry-After in seconds, when it sent one.
48
+ class RateLimitError < ApiError
49
+ attr_accessor :retry_after
50
+ end
51
+
52
+ # 423 (+code+ org_frozen): the org is frozen in the Security Center. New
53
+ # sandboxes, commands, wakes and function calls are refused until an owner or
54
+ # admin unfreezes it; retrying does not help.
55
+ class OrgFrozenError < ApiError; end
56
+
57
+ # A kosa8 Cloud exec ran past the API's limit for a buffered command. Today a
58
+ # buffered exec is cut off after about 30 s (HTTP 502 host_failed "timed out";
59
+ # later servers answer 504 exec_timeout). Run long work in the background,
60
+ # writing to /workspace, and poll it:
61
+ #
62
+ # box.exec("nohup sh -c 'make test > /workspace/test.log 2>&1' &")
63
+ class ExecTimeoutError < ApiError; end
33
64
 
34
65
  # 403 that a signed approval would lift; +approval+ is the daemon's refusal.
35
66
  class ApprovalRequiredError < PolicyError
@@ -60,9 +91,16 @@ module Kosa8
60
91
 
61
92
  BY_STATUS = {
62
93
  400 => BadRequestError, 401 => AuthError, 402 => PaymentRequiredError, 403 => PolicyError,
63
- 404 => NotFoundError, 409 => ConflictError, 429 => RateLimitError, 501 => UnsupportedError
94
+ 404 => NotFoundError, 409 => ConflictError, 423 => OrgFrozenError, 429 => RateLimitError,
95
+ 501 => UnsupportedError
64
96
  }.freeze
65
97
 
98
+ # body[key] when it is a non-empty String, else nil.
99
+ def self.body_str(body, key)
100
+ v = body.is_a?(Hash) ? body[key] : nil
101
+ v.is_a?(String) && !v.empty? ? v : nil
102
+ end
103
+
66
104
  # The typed error for an HTTP error answer: the daemon's message with its
67
105
  # remediation in parentheses, as the CLI and MCP server print it.
68
106
  def self.error_from_response(status, body, method:, path:, code: nil)
data/lib/kosa8/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kosa8
4
- VERSION = "0.3.1"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/kosa8.rb CHANGED
@@ -9,3 +9,4 @@ require_relative "kosa8/checkpoints"
9
9
  require_relative "kosa8/toolbox"
10
10
  require_relative "kosa8/client"
11
11
  require_relative "kosa8/cloud"
12
+ require_relative "kosa8/cloud_features"
metadata CHANGED
@@ -1,17 +1,18 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kosa8
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kosa8
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-04 00:00:00.000000000 Z
11
+ date: 2026-11-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Typed client for the kosa8 daemon: sandboxes, run/exec streams, snapshots,
14
- fork, best-of-N explore and checkpoints shared with the kosa8 CLI. No dependencies.'
14
+ fork, best-of-N explore and checkpoints shared with the kosa8 CLI, plus the kosa8
15
+ Cloud API. No dependencies.'
15
16
  email:
16
17
  executables: []
17
18
  extensions: []
@@ -23,6 +24,7 @@ files:
23
24
  - lib/kosa8/checkpoints.rb
24
25
  - lib/kosa8/client.rb
25
26
  - lib/kosa8/cloud.rb
27
+ - lib/kosa8/cloud_features.rb
26
28
  - lib/kosa8/errors.rb
27
29
  - lib/kosa8/toolbox.rb
28
30
  - lib/kosa8/transport.rb