kosa8 0.9.0 → 0.10.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/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/lib/kosa8/cloud.rb +40 -3
- data/lib/kosa8/errors.rb +20 -1
- data/lib/kosa8/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '06296eb5f5d03874b2269a72c26196a24162e9e556fa4677f9acf3aaf560dbe1'
|
|
4
|
+
data.tar.gz: 8daefd13df470de92c35272eb6c7526e6c6be865bef3bcde0ca60214234a05f4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78dd5aafcea380b617073fbb229cbeb9f592826de15b6b3e6324ce93f4cb05e81fd76503d7bf250cb90f4448164b9b39e0f610bc8d4cd3f05ec1a6c8b46cf529
|
|
7
|
+
data.tar.gz: af731b7f5bc33c03ba5bc66fddeb6fc944d5e4d4ea15d31dd3cf81f951940387ce9b8def0754573fd67cbed985cec02307839c2ccbaabb778768756212916b20
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.0 - 2026-11-25
|
|
4
|
+
|
|
5
|
+
- `Kosa8::Cloud.new` with no `api_key:` and no `KOSA8_API_KEY` uses the key `kosa8 login` keeps in `~/.kosa8/cloud.json` (and its `api_url` unless `base_url:` or `KOSA8_CLOUD_URL` is set). The no-key error names `kosa8 login`.
|
|
6
|
+
- A plan limit answered with HTTP 429 (`starter_limit`) raises the new `Kosa8::PlanLimitError`, a `PaymentRequiredError`, still caught by `rescue Kosa8::RateLimitError`. Fix: it was retried as a rate limit; `starter_limit`, `payment_failed` and `spend_cap` are now quota codes (not retried), as in the other SDKs.
|
|
7
|
+
|
|
3
8
|
## 0.9.0 - 2026-11-25
|
|
4
9
|
|
|
5
10
|
- Autopilot: `cloud.bots` with `list` (`bots`, `paused_all`, `pending_approvals`), `templates`, `template(id)`,
|
data/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Method for method it matches [`@kosa8/sdk`](https://github.com/kosa8ai/kosa8-js)
|
|
|
9
9
|
|
|
10
10
|
```sh
|
|
11
11
|
gem install kosa8
|
|
12
|
-
# or in a Gemfile: gem "kosa8", "~> 0.
|
|
12
|
+
# or in a Gemfile: gem "kosa8", "~> 0.10"
|
|
13
13
|
export KOSA8_API_KEY=k8c_live_... # made in the cloud dashboard
|
|
14
14
|
```
|
|
15
15
|
|
data/lib/kosa8/cloud.rb
CHANGED
|
@@ -41,7 +41,7 @@ module Kosa8
|
|
|
41
41
|
# kosa8 Cloud: the same sandboxes, run on kosa8's hosts (or your own, with
|
|
42
42
|
# bring-your-own-cloud) instead of the local daemon.
|
|
43
43
|
#
|
|
44
|
-
# cloud = Kosa8::Cloud.new # KOSA8_API_KEY
|
|
44
|
+
# cloud = Kosa8::Cloud.new # KOSA8_API_KEY, else your `kosa8 login`
|
|
45
45
|
# box = cloud.sandboxes.create(template: "python", ttl_s: 3600)
|
|
46
46
|
# box.exec(["python3", "-c", "print(6 * 7)"]).stdout # => "42\n"
|
|
47
47
|
# box.delete
|
|
@@ -101,11 +101,48 @@ module Kosa8
|
|
|
101
101
|
# retry_after / retry_after_s). An answer with retryable: false is never
|
|
102
102
|
# retried. RetryPolicy::NONE turns it off. sleeper: replaces
|
|
103
103
|
# Kernel#sleep for those waits (tests).
|
|
104
|
+
# Where `kosa8 login` keeps the kosa8 Cloud key: ~/.kosa8/cloud.json.
|
|
105
|
+
# With an +env+ other than ENV, its HOME decides (none: no file).
|
|
106
|
+
def self.credentials_path(env = ENV)
|
|
107
|
+
home = env["HOME"] || env["USERPROFILE"]
|
|
108
|
+
if (home.nil? || home.empty?) && env.equal?(ENV)
|
|
109
|
+
home = begin
|
|
110
|
+
Dir.home
|
|
111
|
+
rescue ArgumentError
|
|
112
|
+
nil
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
return nil if home.nil? || home.empty?
|
|
116
|
+
|
|
117
|
+
File.join(home, ".kosa8", "cloud.json")
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# [key, api_url] that `kosa8 login` saved, or ["", nil] when none.
|
|
121
|
+
def self.saved_login(env = ENV)
|
|
122
|
+
path = credentials_path(env)
|
|
123
|
+
return ["", nil] unless path && File.file?(path)
|
|
124
|
+
|
|
125
|
+
data = JSON.parse(File.read(path))
|
|
126
|
+
return ["", nil] unless data.is_a?(Hash)
|
|
127
|
+
|
|
128
|
+
key = (data["key"] || data["api_key"]).to_s.strip
|
|
129
|
+
url = data["api_url"].to_s.strip
|
|
130
|
+
[key, url.empty? ? nil : url]
|
|
131
|
+
rescue StandardError
|
|
132
|
+
["", nil]
|
|
133
|
+
end
|
|
134
|
+
|
|
104
135
|
def initialize(api_key: nil, base_url: nil, env: ENV, timeout: 120, transport: nil, retry_policy: nil,
|
|
105
136
|
sleeper: nil)
|
|
106
137
|
key = (api_key.nil? ? env["KOSA8_API_KEY"].to_s : api_key.to_s).strip
|
|
138
|
+
saved_url = nil
|
|
139
|
+
if key.empty? && api_key.nil?
|
|
140
|
+
# Signed in with `kosa8 login`: the CLI keeps the key in ~/.kosa8/cloud.json.
|
|
141
|
+
key, saved_url = Cloud.saved_login(env)
|
|
142
|
+
end
|
|
107
143
|
if key.empty?
|
|
108
|
-
raise Error, "no kosa8 Cloud API key: set KOSA8_API_KEY or pass api_key:;
|
|
144
|
+
raise Error, "no kosa8 Cloud API key: run `kosa8 login`, set KOSA8_API_KEY or pass api_key:; " \
|
|
145
|
+
"make one at #{KEYS_URL}"
|
|
109
146
|
end
|
|
110
147
|
unless key.start_with?(KEY_PREFIX) || key.start_with?(TOKEN_PREFIX)
|
|
111
148
|
raise Error, "a kosa8 Cloud API key starts with #{KEY_PREFIX} (a capability token with #{TOKEN_PREFIX}); " \
|
|
@@ -113,7 +150,7 @@ module Kosa8
|
|
|
113
150
|
end
|
|
114
151
|
|
|
115
152
|
@key = key
|
|
116
|
-
base = [base_url, env["KOSA8_CLOUD_URL"]].find { |v| v && !v.to_s.empty? } || DEFAULT_URL
|
|
153
|
+
base = [base_url, env["KOSA8_CLOUD_URL"], saved_url].find { |v| v && !v.to_s.empty? } || DEFAULT_URL
|
|
117
154
|
@base_url = Cloud.check_base(base.to_s)
|
|
118
155
|
@timeout = timeout
|
|
119
156
|
@transport = transport || method(:net_http)
|
data/lib/kosa8/errors.rb
CHANGED
|
@@ -190,7 +190,13 @@ module Kosa8
|
|
|
190
190
|
# 429: too many requests, or a quota reached (+code+ quota_exceeded, with
|
|
191
191
|
# #agent_message and #request_url). +retry_after+ is the server's
|
|
192
192
|
# Retry-After in seconds, when it sent one.
|
|
193
|
-
class RateLimitError < ApiError
|
|
193
|
+
class RateLimitError < ApiError
|
|
194
|
+
# A plan limit answered 429 (PlanLimitError) still matches +rescue
|
|
195
|
+
# RateLimitError+, for code written before it existed.
|
|
196
|
+
def self.===(other)
|
|
197
|
+
super || (equal?(RateLimitError) && other.is_a?(PlanLimitError) && other.status == 429)
|
|
198
|
+
end
|
|
199
|
+
end
|
|
194
200
|
|
|
195
201
|
# 423 (+code+ org_frozen): the org is frozen in the Security Center. New
|
|
196
202
|
# sandboxes, commands, wakes and function calls are refused until an owner or
|
|
@@ -249,6 +255,14 @@ module Kosa8
|
|
|
249
255
|
# Raised when a frame stream carries something that is not NDJSON.
|
|
250
256
|
class ProtocolError < Error; end
|
|
251
257
|
|
|
258
|
+
# A plan limit answered with HTTP 429 (Starter's running limit,
|
|
259
|
+
# +starter_limit+): a PaymentRequiredError like every other plan limit
|
|
260
|
+
# (pick a plan or stop a sandbox; retrying does not help).
|
|
261
|
+
class PlanLimitError < PaymentRequiredError; end
|
|
262
|
+
|
|
263
|
+
# Codes that mean "pick or pay for a plan", whatever the HTTP status.
|
|
264
|
+
PLAN_LIMIT_CODES = %w[starter_limit plan_limit plan_feature plan_required].freeze
|
|
265
|
+
|
|
252
266
|
BY_STATUS = {
|
|
253
267
|
400 => BadRequestError, 401 => AuthError, 402 => PaymentRequiredError, 403 => PolicyError,
|
|
254
268
|
404 => NotFoundError, 409 => ConflictError, 423 => OrgFrozenError, 429 => RateLimitError,
|
|
@@ -286,6 +300,10 @@ module Kosa8
|
|
|
286
300
|
code: code }
|
|
287
301
|
return ApprovalRequiredError.new(text, approval: approval, **kw) if approval
|
|
288
302
|
|
|
303
|
+
if !BY_CODE[code] && PLAN_LIMIT_CODES.include?(code)
|
|
304
|
+
return (status == 429 ? PlanLimitError : PaymentRequiredError).new(text, **kw)
|
|
305
|
+
end
|
|
306
|
+
|
|
289
307
|
(BY_CODE[code] || BY_STATUS[status] || ApiError).new(text, **kw)
|
|
290
308
|
end
|
|
291
309
|
|
|
@@ -296,6 +314,7 @@ module Kosa8
|
|
|
296
314
|
insufficient_storage starting database_busy].freeze
|
|
297
315
|
RATE_CODES = %w[rate_limited slow_down too_soon].freeze
|
|
298
316
|
QUOTA_CODES = %w[quota_exceeded running_limit plan_required plan_limit plan_feature payment_required payment_declined
|
|
317
|
+
payment_failed spend_cap starter_limit
|
|
299
318
|
spending_cap_reached snapshot_limit org_frozen org_suspended too_many_runs].freeze
|
|
300
319
|
IDEMPOTENCY_IN_PROGRESS = "idempotency_in_progress"
|
|
301
320
|
|
data/lib/kosa8/version.rb
CHANGED