kloudlite-sdk 0.5.0 → 0.7.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/kloudlite.rb +437 -95
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c89a44a4437048efb7402aa11479f465469f257b2443badcf0de8adc656920d
|
|
4
|
+
data.tar.gz: ef577fc7b737598224da17a4697c8855f61276ebfc0c73521ab8c7b5257ee881
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 392d389bacbb307bb1f69a9bbd97d0e9e1f10bb29f4c5b9bdd7dc3587b21886fc657cae9b8722ab8b157c2d371f9eab1fa8b2123dade0395e41d3fe65b3b95fd
|
|
7
|
+
data.tar.gz: a07341f5fe3e3c200016ca578044bd3ace5715fd8e89a94e8f2e34f78eab06523be19cd6665f99702ae201ebd43a4e86dd1b487893978312c56c746c0707fb23
|
data/kloudlite.rb
CHANGED
|
@@ -14,18 +14,19 @@
|
|
|
14
14
|
# "no Kloudlite login: pass token=, set KLOUDLITE_TOKEN, or run kloudlite login".
|
|
15
15
|
#
|
|
16
16
|
# Every public method takes KEYWORD arguments, so no caller has to remember an order; a
|
|
17
|
-
# resource is always the keyword named after it (workspace:, environment:,
|
|
17
|
+
# resource is always the keyword named after it (workspace:, environment:, netgroup:,
|
|
18
18
|
# volume:, snapshot:, capsule:, run:), and a new object made from an existing one is to:.
|
|
19
19
|
|
|
20
20
|
raise LoadError, "kloudlite.rb needs Ruby 3.0 or later, found #{RUBY_VERSION}" if RUBY_VERSION < "3.0"
|
|
21
21
|
|
|
22
22
|
require "json"
|
|
23
23
|
require "net/http"
|
|
24
|
+
require "securerandom"
|
|
24
25
|
require "timeout"
|
|
25
26
|
require "uri"
|
|
26
27
|
|
|
27
28
|
module Kloudlite
|
|
28
|
-
VERSION = "0.
|
|
29
|
+
VERSION = "0.7.0"
|
|
29
30
|
USER_AGENT = "kloudlite-sdk-ruby/#{VERSION}".freeze
|
|
30
31
|
NO_LOGIN = "no Kloudlite login: pass token=, set KLOUDLITE_TOKEN, or run kloudlite login"
|
|
31
32
|
|
|
@@ -60,7 +61,7 @@ module Kloudlite
|
|
|
60
61
|
module Names
|
|
61
62
|
private
|
|
62
63
|
|
|
63
|
-
# "name" → [nil, name]; "team/name" → [team, name]. Workspaces, environments and
|
|
64
|
+
# "name" → [nil, name]; "team/name" → [team, name]. Workspaces, environments and netgroups
|
|
64
65
|
# send the pair as path segment +name+ plus ?owner=team, which the server folds back.
|
|
65
66
|
def owned(s)
|
|
66
67
|
s = s.to_s
|
|
@@ -77,15 +78,16 @@ module Kloudlite
|
|
|
77
78
|
end
|
|
78
79
|
|
|
79
80
|
# The body of a workspace or environment push, shared so the two never drift apart.
|
|
80
|
-
def snapshot_body(message, volume, description, labels,
|
|
81
|
+
def snapshot_body(message, volume, description, labels, tag, ttl_secs, never)
|
|
81
82
|
{ message: message, volume: volume, description: description, labels: labels,
|
|
82
|
-
|
|
83
|
+
tag: tag, ttl_secs: ttl_secs, never: never }.compact
|
|
83
84
|
end
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
class Client
|
|
87
|
-
attr_reader :workspaces, :environments, :
|
|
88
|
-
:secrets, :connectors, :capsules, :pipelines
|
|
88
|
+
attr_reader :workspaces, :environments, :netgroups, :volumes,
|
|
89
|
+
:secrets, :connectors, :capsules, :pipelines,
|
|
90
|
+
:static_sandboxes, :code_boxes, :mcp_servers, :browser_sandboxes
|
|
89
91
|
|
|
90
92
|
def initialize(base_url: nil, token: nil, timeout: 30)
|
|
91
93
|
base_url = presence(base_url) || presence(ENV["KLOUDLITE_URL"])
|
|
@@ -103,12 +105,16 @@ module Kloudlite
|
|
|
103
105
|
@timeout = timeout
|
|
104
106
|
@workspaces = Workspaces.new(self)
|
|
105
107
|
@environments = Environments.new(self)
|
|
106
|
-
@
|
|
108
|
+
@netgroups = Netgroups.new(self)
|
|
107
109
|
@volumes = Volumes.new(self)
|
|
108
110
|
@secrets = Secrets.new(self)
|
|
109
111
|
@connectors = Connectors.new(self)
|
|
110
112
|
@capsules = Capsules.new(self)
|
|
111
113
|
@pipelines = Pipelines.new(self)
|
|
114
|
+
@static_sandboxes = StaticSandboxes.new(self)
|
|
115
|
+
@code_boxes = CodeBoxes.new(self)
|
|
116
|
+
@mcp_servers = McpServers.new(self)
|
|
117
|
+
@browser_sandboxes = BrowserSandboxes.new(self)
|
|
112
118
|
end
|
|
113
119
|
|
|
114
120
|
# The ceiling and what is against it; +owner+ defaults to the caller's own.
|
|
@@ -224,14 +230,13 @@ module Kloudlite
|
|
|
224
230
|
# names the volume and is required on its first push; +ttl_secs+ (3600..=31536000) or
|
|
225
231
|
# never: true set its expiry. +push+ is the old name.
|
|
226
232
|
# The push is a storage commit of the volume. +description+ and +labels+ describe the volume
|
|
227
|
-
# (a given one replaces the stored one). +
|
|
228
|
-
#
|
|
229
|
-
#
|
|
230
|
-
# +detached+.
|
|
233
|
+
# (a given one replaces the stored one). +tag+ puts that tag on the new snapshot, moving it
|
|
234
|
+
# from wherever it was; without it the snapshot is untagged (a volume's first is tagged
|
|
235
|
+
# "base"). The answer carries +tag+.
|
|
231
236
|
def take_snapshot(workspace:, message: nil, volume: nil, description: nil, labels: nil,
|
|
232
|
-
|
|
237
|
+
tag: nil, ttl_secs: nil, never: nil)
|
|
233
238
|
at("POST", workspace, "/snapshots",
|
|
234
|
-
body: snapshot_body(message, volume, description, labels,
|
|
239
|
+
body: snapshot_body(message, volume, description, labels, tag, ttl_secs, never))
|
|
235
240
|
end
|
|
236
241
|
alias_method :push, :take_snapshot
|
|
237
242
|
|
|
@@ -241,8 +246,8 @@ module Kloudlite
|
|
|
241
246
|
at("POST", workspace, "/clone", body: { name: to, task: task })
|
|
242
247
|
end
|
|
243
248
|
|
|
244
|
-
# A new workspace +to+ grafted onto a PUSHED +snapshot+ (a volume name — its
|
|
245
|
-
# else its newest
|
|
249
|
+
# A new workspace +to+ grafted onto a PUSHED +snapshot+ (a volume name — its snapshot tagged
|
|
250
|
+
# "base", else its newest — "name@N", "name@<tag>" or a snapshot id) — also one
|
|
246
251
|
# whose workspace is long gone. +team+ (or to: "team/name") is required for a
|
|
247
252
|
# team's volume. Absent overrides mean "whatever the snapshot froze".
|
|
248
253
|
def restore(snapshot:, to:, team: nil, image: nil, packages: nil, quota_gb: nil)
|
|
@@ -345,10 +350,10 @@ module Kloudlite
|
|
|
345
350
|
context: context, ignore_case: ignore_case, max: max)
|
|
346
351
|
end
|
|
347
352
|
|
|
348
|
-
# commands and processes —
|
|
349
|
-
def exec(cmd:, cwd: nil, env: nil, timeout_ms: nil, head: nil, tail: nil, quiet: nil, detach: nil)
|
|
353
|
+
# commands and processes — background: true (formerly detach:, still read) answers {id}, passed back as +process+
|
|
354
|
+
def exec(cmd:, cwd: nil, env: nil, timeout_ms: nil, head: nil, tail: nil, quiet: nil, background: nil, detach: nil)
|
|
350
355
|
call(tool: "exec", cmd: cmd, cwd: cwd, env: env, timeout_ms: timeout_ms,
|
|
351
|
-
head: head, tail: tail, quiet: quiet, detach:
|
|
356
|
+
head: head, tail: tail, quiet: quiet, background: background.nil? ? detach : background)
|
|
352
357
|
end
|
|
353
358
|
|
|
354
359
|
def process_list
|
|
@@ -476,11 +481,11 @@ module Kloudlite
|
|
|
476
481
|
|
|
477
482
|
# Push a SNAPSHOT of every service's data and the service list, a storage commit (202).
|
|
478
483
|
# +volume+ names the volume and is required on its first push; +description+, +labels+ and
|
|
479
|
-
# +
|
|
484
|
+
# +tag+ are as in Workspaces#take_snapshot. +push+ is the old name.
|
|
480
485
|
def take_snapshot(environment:, message: nil, volume: nil, description: nil, labels: nil,
|
|
481
|
-
|
|
486
|
+
tag: nil, ttl_secs: nil, never: nil)
|
|
482
487
|
at("POST", environment, "/snapshots",
|
|
483
|
-
body: snapshot_body(message, volume, description, labels,
|
|
488
|
+
body: snapshot_body(message, volume, description, labels, tag, ttl_secs, never))
|
|
484
489
|
end
|
|
485
490
|
alias_method :push, :take_snapshot
|
|
486
491
|
|
|
@@ -515,96 +520,437 @@ module Kloudlite
|
|
|
515
520
|
end
|
|
516
521
|
end
|
|
517
522
|
|
|
518
|
-
#
|
|
519
|
-
# environment. Many people's
|
|
520
|
-
# it; an intercept a
|
|
521
|
-
# release it, and
|
|
523
|
+
# Netgroups, over /v1/netgroups: some of YOUR workspaces in one team, joined to one
|
|
524
|
+
# environment, with one idle clock. Many people's netgroups connect to the same environment
|
|
525
|
+
# and collaborate through it; an intercept a netgroup takes is environment-wide, and the
|
|
526
|
+
# netgroup owns it — only it can release it, and a member leaving or the netgroup ending
|
|
527
|
+
# releases it.
|
|
522
528
|
#
|
|
523
|
-
# A
|
|
524
|
-
#
|
|
525
|
-
class
|
|
529
|
+
# A netgroup is named like an environment — "name" (personal) or "team/name" — or by its id;
|
|
530
|
+
# a workspace by its id, name or "team/name", sent verbatim.
|
|
531
|
+
class Netgroups
|
|
526
532
|
include Names
|
|
527
533
|
|
|
528
534
|
def initialize(client)
|
|
529
535
|
@c = client
|
|
530
536
|
end
|
|
531
537
|
|
|
532
|
-
# +environment+, when given, must be the
|
|
533
|
-
# without one
|
|
534
|
-
#
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
+
# +environment+, when given, must be the netgroup's team's: an id, a name or "team/name";
|
|
539
|
+
# without one it connects to nothing until +connect+. +ttl_secs+ (600..=2592000) deletes it
|
|
540
|
+
# after that long unused; +idle_secs+ (60..=1800) idle-stops its members after that long
|
|
541
|
+
# unused, in place of the region's window.
|
|
542
|
+
def create(netgroup:, environment: nil, ttl_secs: nil, idle_secs: nil)
|
|
543
|
+
team, name = owned(netgroup)
|
|
544
|
+
@c.request("POST", "/v1/netgroups",
|
|
545
|
+
body: { name: name, team: team, environment: environment, ttl_secs: ttl_secs,
|
|
546
|
+
idle_secs: idle_secs }.compact)
|
|
538
547
|
end
|
|
539
548
|
|
|
540
|
-
# Seconds unused before
|
|
541
|
-
def
|
|
542
|
-
at("PUT",
|
|
549
|
+
# Seconds unused before its members idle-stop (60..=1800); nil follows the region's window again.
|
|
550
|
+
def set_idle(netgroup:, secs:)
|
|
551
|
+
at("PUT", netgroup, "/idle", body: { idle_secs: secs })
|
|
552
|
+
end
|
|
553
|
+
|
|
554
|
+
# Seconds unused before the netgroup is deleted (600..=2592000); nil clears it.
|
|
555
|
+
def set_ttl(netgroup:, ttl_secs:)
|
|
556
|
+
at("PUT", netgroup, "/ttl", body: { ttl_secs: ttl_secs })
|
|
543
557
|
end
|
|
544
558
|
|
|
545
559
|
def list(team: nil)
|
|
546
|
-
@c.request("GET", "/v1/
|
|
560
|
+
@c.request("GET", "/v1/netgroups", query: { team: team })
|
|
561
|
+
end
|
|
562
|
+
|
|
563
|
+
# The netgroup with its +workspaces+ and the +intercepts+ it holds.
|
|
564
|
+
def get(netgroup:)
|
|
565
|
+
at("GET", netgroup)
|
|
566
|
+
end
|
|
567
|
+
|
|
568
|
+
# Releases its intercepts, deletes the workspaces made in it and lets the joined ones go.
|
|
569
|
+
def delete(netgroup:)
|
|
570
|
+
at("DELETE", netgroup)
|
|
547
571
|
end
|
|
548
572
|
|
|
549
|
-
#
|
|
550
|
-
|
|
551
|
-
|
|
573
|
+
# Sets, switches or (nil) clears the netgroup's environment. Its intercepts in the old
|
|
574
|
+
# environment are released first.
|
|
575
|
+
def connect(netgroup:, environment:)
|
|
576
|
+
at("PUT", netgroup, "/environment", body: { environment: environment })
|
|
552
577
|
end
|
|
553
578
|
|
|
554
|
-
#
|
|
555
|
-
def
|
|
556
|
-
at("
|
|
579
|
+
# Stop every workspace in the netgroup (202, {"stopped" => [ids]}).
|
|
580
|
+
def stop(netgroup:)
|
|
581
|
+
at("POST", netgroup, "/stop")
|
|
557
582
|
end
|
|
558
583
|
|
|
559
|
-
#
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
at("PUT", desk, "/environment", body: { environment: environment })
|
|
584
|
+
# Start the netgroup's environment and every workspace in it.
|
|
585
|
+
def start(netgroup:)
|
|
586
|
+
at("POST", netgroup, "/start")
|
|
563
587
|
end
|
|
564
588
|
|
|
565
|
-
#
|
|
566
|
-
#
|
|
567
|
-
def
|
|
568
|
-
at("POST",
|
|
589
|
+
# Create a workspace +workspace+ (a bare name) in the netgroup, in its team (201); it is
|
|
590
|
+
# deleted with the netgroup. +cpu+ (1..=8) and +memory_gb+ (1..=32) size it.
|
|
591
|
+
def create_workspace(netgroup:, workspace:, image: nil, packages: nil, ttl_secs: nil, env: nil, cpu: nil, memory_gb: nil)
|
|
592
|
+
at("POST", netgroup, "/workspaces",
|
|
593
|
+
body: { name: workspace, image: image, packages: packages, ttl_secs: ttl_secs, env: env,
|
|
594
|
+
cpu: cpu, memory_gb: memory_gb }.compact)
|
|
569
595
|
end
|
|
570
596
|
|
|
571
|
-
#
|
|
572
|
-
#
|
|
573
|
-
def
|
|
574
|
-
at("POST",
|
|
575
|
-
body: { name: workspace, quota_gb: quota_gb, image: image, packages: packages,
|
|
576
|
-
ttl_secs: ttl_secs, env: env }.compact)
|
|
597
|
+
# A standalone workspace of yours (a device one too) joins: it follows the netgroup's idle
|
|
598
|
+
# clock and reaches its environment.
|
|
599
|
+
def join(netgroup:, workspace:)
|
|
600
|
+
at("POST", netgroup, "/workspaces", body: { workspace: workspace })
|
|
577
601
|
end
|
|
578
602
|
|
|
579
|
-
#
|
|
580
|
-
|
|
581
|
-
|
|
603
|
+
# The workspace leaves and is standalone again, its intercepts released; +delete+ deletes it
|
|
604
|
+
# instead (a capsule, or a workspace made in the netgroup).
|
|
605
|
+
def leave(netgroup:, workspace:, delete: false)
|
|
606
|
+
owner, name = owned(netgroup)
|
|
607
|
+
@c.request("DELETE", "/v1/netgroups/#{seg(name)}/workspaces/#{seg(workspace)}",
|
|
608
|
+
query: { owner: owner, delete: delete ? "true" : nil })
|
|
582
609
|
end
|
|
583
610
|
|
|
584
|
-
# Create a capsule
|
|
585
|
-
# Same inputs as Capsules#create (+team+ must be the
|
|
586
|
-
def create_capsule(
|
|
587
|
-
Capsule.new(@c, at("POST",
|
|
611
|
+
# Create a capsule in the netgroup (202), in its team and reaching its environment.
|
|
612
|
+
# Same inputs as Capsules#create (+team+ must be the netgroup's).
|
|
613
|
+
def create_capsule(netgroup:, cmd:, **options)
|
|
614
|
+
Capsule.new(@c, at("POST", netgroup, "/capsules", body: Capsules.body(cmd: cmd, **options)))
|
|
588
615
|
end
|
|
589
616
|
|
|
590
617
|
# Send everything that calls +service+ in the environment to +workspace+ (a member), +ports+
|
|
591
618
|
# mapping each service port to the workspace port that answers it ({ 8080 => 3000 }); an
|
|
592
619
|
# unmapped port answers on the same number.
|
|
593
|
-
def intercept(
|
|
594
|
-
at("POST",
|
|
620
|
+
def intercept(netgroup:, service:, workspace:, ports: nil)
|
|
621
|
+
at("POST", netgroup, "/intercepts",
|
|
595
622
|
body: { service: service, workspace: workspace,
|
|
596
623
|
ports: (ports || {}).map { |s, w| { service: Integer(s), workspace: Integer(w) } } })
|
|
597
624
|
end
|
|
598
625
|
|
|
599
|
-
def release(
|
|
600
|
-
at("DELETE",
|
|
626
|
+
def release(netgroup:, service:)
|
|
627
|
+
at("DELETE", netgroup, "/intercepts/#{seg(service)}")
|
|
601
628
|
end
|
|
602
629
|
|
|
603
630
|
private
|
|
604
631
|
|
|
605
|
-
def at(method,
|
|
606
|
-
owner, name = owned(
|
|
607
|
-
@c.request(method, "/v1/
|
|
632
|
+
def at(method, netgroup, tail = "", body: nil)
|
|
633
|
+
owner, name = owned(netgroup)
|
|
634
|
+
@c.request(method, "/v1/netgroups/#{seg(name)}#{tail}", body: body, query: { owner: owner })
|
|
635
|
+
end
|
|
636
|
+
end
|
|
637
|
+
|
|
638
|
+
# Storage-only sandboxes of files, over /v1/static-sandboxes. A sandbox is named "name" (your
|
|
639
|
+
# own), "team/name" (a team's) or by its id.
|
|
640
|
+
class StaticSandboxes
|
|
641
|
+
include Names
|
|
642
|
+
|
|
643
|
+
def initialize(client)
|
|
644
|
+
@c = client
|
|
645
|
+
end
|
|
646
|
+
|
|
647
|
+
# 201 with the sandbox (its +id+); +from_sandbox+ ("[owner/]name[@ref]") makes it a clone of
|
|
648
|
+
# that snapshot (202).
|
|
649
|
+
def create(sandbox:, size_gb:, description: nil, labels: nil, from_sandbox: nil)
|
|
650
|
+
team, name = owned(sandbox)
|
|
651
|
+
@c.request("POST", "/v1/static-sandboxes",
|
|
652
|
+
body: { name: name, team: team, size_gb: size_gb, description: description,
|
|
653
|
+
labels: labels, from: from_sandbox }.compact)
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
# Your sandboxes (or +team+'s); +shared+ adds those shared with you.
|
|
657
|
+
def list(team: nil, shared: false)
|
|
658
|
+
@c.request("GET", "/v1/static-sandboxes", query: { team: team, shared: shared ? "1" : nil })
|
|
659
|
+
end
|
|
660
|
+
|
|
661
|
+
def get(sandbox:)
|
|
662
|
+
at("GET", sandbox)
|
|
663
|
+
end
|
|
664
|
+
|
|
665
|
+
# 202; its files and snapshots go with it.
|
|
666
|
+
def delete(sandbox:)
|
|
667
|
+
at("DELETE", sandbox)
|
|
668
|
+
end
|
|
669
|
+
|
|
670
|
+
# Grow while the quota has room; a shrink below the bytes it holds is a 409.
|
|
671
|
+
def resize(sandbox:, size_gb:)
|
|
672
|
+
at("PUT", sandbox, "/size", body: { size_gb: size_gb })
|
|
673
|
+
end
|
|
674
|
+
|
|
675
|
+
# Share it with +team+, +mode+ "read" or "write"; again changes the mode.
|
|
676
|
+
def share(sandbox:, team:, mode: "read")
|
|
677
|
+
at("PUT", sandbox, "/shares", body: { team: team, mode: mode })
|
|
678
|
+
end
|
|
679
|
+
|
|
680
|
+
def unshare(sandbox:, team:)
|
|
681
|
+
at("DELETE", sandbox, "/shares", body: { team: team })
|
|
682
|
+
end
|
|
683
|
+
|
|
684
|
+
# Its snapshots, newest first.
|
|
685
|
+
def snapshots(sandbox:)
|
|
686
|
+
at("GET", sandbox, "/snapshots")
|
|
687
|
+
end
|
|
688
|
+
|
|
689
|
+
def take_snapshot(sandbox:, message: nil, tag: nil)
|
|
690
|
+
at("POST", sandbox, "/snapshots", body: { message: message, tag: tag }.compact)
|
|
691
|
+
end
|
|
692
|
+
|
|
693
|
+
# Put +snapshot+ (a version, a tag or a snapshot id) back in place (202).
|
|
694
|
+
def restore(sandbox:, snapshot:)
|
|
695
|
+
at("POST", sandbox, "/restore", body: { from: snapshot })
|
|
696
|
+
end
|
|
697
|
+
|
|
698
|
+
# A new sandbox +to+ ("team/name" for a team's) from +snapshot+, else the newest (202).
|
|
699
|
+
def clone(sandbox:, to:, snapshot: nil, size_gb: nil)
|
|
700
|
+
team, name = owned(to)
|
|
701
|
+
at("POST", sandbox, "/clone", body: { to: name, team: team, from: snapshot, size_gb: size_gb }.compact)
|
|
702
|
+
end
|
|
703
|
+
|
|
704
|
+
private
|
|
705
|
+
|
|
706
|
+
def at(method, sandbox, tail = "", body: nil)
|
|
707
|
+
owner, name = owned(sandbox)
|
|
708
|
+
@c.request(method, "/v1/static-sandboxes/#{seg(name)}#{tail}", body: body, query: { owner: owner })
|
|
709
|
+
end
|
|
710
|
+
end
|
|
711
|
+
|
|
712
|
+
# JavaScript runtimes whose saved names and files outlive each cell, over /v1/code-boxes. A box
|
|
713
|
+
# is named "name", "team/name" or by its id ("cb-…"). An MCP attachment is
|
|
714
|
+
# { server: id, as: alias, vars: {…}, tools: […] }, all but +server+ optional.
|
|
715
|
+
class CodeBoxes
|
|
716
|
+
include Names
|
|
717
|
+
|
|
718
|
+
def initialize(client)
|
|
719
|
+
@c = client
|
|
720
|
+
end
|
|
721
|
+
|
|
722
|
+
# 201 with the box. +from_box+ (with +from_snapshot+, else its newest) makes a clone;
|
|
723
|
+
# +attach_kode+ (server default true) attaches Kode's own tools as "kode".
|
|
724
|
+
def create(box:, size_gb: nil, memory_mb: nil, cell_timeout_ms: nil, from_box: nil,
|
|
725
|
+
from_snapshot: nil, mcp: nil, attach_kode: nil)
|
|
726
|
+
team, name = owned(box)
|
|
727
|
+
limits = { memoryMb: memory_mb, cellTimeoutMs: cell_timeout_ms }.compact
|
|
728
|
+
@c.request("POST", "/v1/code-boxes",
|
|
729
|
+
body: { name: name, team: team, sizeGb: size_gb, limits: limits.empty? ? nil : limits,
|
|
730
|
+
from: from_box && { box: from_box, snapshot: from_snapshot }.compact,
|
|
731
|
+
mcp: mcp, attachKode: attach_kode }.compact)
|
|
732
|
+
end
|
|
733
|
+
|
|
734
|
+
def list(team: nil)
|
|
735
|
+
@c.request("GET", "/v1/code-boxes", query: { team: team })
|
|
736
|
+
end
|
|
737
|
+
|
|
738
|
+
def get(box:)
|
|
739
|
+
at("GET", box)
|
|
740
|
+
end
|
|
741
|
+
|
|
742
|
+
# 202; its saved state and snapshots go with it.
|
|
743
|
+
def delete(box:)
|
|
744
|
+
at("DELETE", box)
|
|
745
|
+
end
|
|
746
|
+
|
|
747
|
+
def resize(box:, size_gb:)
|
|
748
|
+
at("PUT", box, "/size", body: { sizeGb: size_gb })
|
|
749
|
+
end
|
|
750
|
+
|
|
751
|
+
# Run one cell: a door from POST /door, then POST {url}/cells. A retry with the same
|
|
752
|
+
# +request_id+ (a fresh one by default) answers the first run's answer.
|
|
753
|
+
def run(box:, code:, timeout_ms: nil, request_id: nil)
|
|
754
|
+
door = at("POST", box, "/door")
|
|
755
|
+
Ide.new(url: door["url"], token: door["token"]).__send__(
|
|
756
|
+
:http, "POST", "/cells",
|
|
757
|
+
{ code: code, timeoutMs: timeout_ms, requestId: request_id || SecureRandom.uuid }.compact
|
|
758
|
+
)
|
|
759
|
+
end
|
|
760
|
+
|
|
761
|
+
# Replace the box's MCP attachments.
|
|
762
|
+
def set_mcp(box:, attachments:)
|
|
763
|
+
at("PUT", box, "/mcp", body: attachments)
|
|
764
|
+
end
|
|
765
|
+
|
|
766
|
+
# Change one attachment's var overrides or tools; each given replaces.
|
|
767
|
+
def update_mcp(box:, alias_name:, vars: nil, tools: nil)
|
|
768
|
+
at("PATCH", box, "/mcp/#{seg(alias_name)}", body: { vars: vars, tools: tools }.compact)
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
def detach_mcp(box:, alias_name:)
|
|
772
|
+
at("DELETE", box, "/mcp/#{seg(alias_name)}")
|
|
773
|
+
end
|
|
774
|
+
|
|
775
|
+
# Check one attachment with its effective vars.
|
|
776
|
+
def check_mcp(box:, alias_name:)
|
|
777
|
+
at("POST", box, "/mcp/#{seg(alias_name)}/check")
|
|
778
|
+
end
|
|
779
|
+
|
|
780
|
+
# The saved names with kind and size; with +name+, that one's value.
|
|
781
|
+
def state(box:, name: nil)
|
|
782
|
+
at("GET", box, "/state", query: { name: name })
|
|
783
|
+
end
|
|
784
|
+
|
|
785
|
+
# The ledger entries after cell +since+ (default 0).
|
|
786
|
+
def ledger(box:, since: nil)
|
|
787
|
+
at("GET", box, "/ledger", query: { since: since })
|
|
788
|
+
end
|
|
789
|
+
|
|
790
|
+
def checkpoint(box:)
|
|
791
|
+
at("POST", box, "/checkpoint")
|
|
792
|
+
end
|
|
793
|
+
|
|
794
|
+
def snapshots(box:)
|
|
795
|
+
at("GET", box, "/snapshots")
|
|
796
|
+
end
|
|
797
|
+
|
|
798
|
+
def take_snapshot(box:, message: nil, tag: nil)
|
|
799
|
+
at("POST", box, "/snapshots", body: { message: message, tag: tag }.compact)
|
|
800
|
+
end
|
|
801
|
+
|
|
802
|
+
# +snapshot+ is a version, a tag or a snapshot id.
|
|
803
|
+
def restore(box:, snapshot:)
|
|
804
|
+
at("POST", box, "/restore", body: { from: snapshot })
|
|
805
|
+
end
|
|
806
|
+
|
|
807
|
+
private
|
|
808
|
+
|
|
809
|
+
def at(method, box, tail = "", body: nil, query: {})
|
|
810
|
+
owner, name = owned(box)
|
|
811
|
+
@c.request(method, "/v1/code-boxes/#{seg(name)}#{tail}", body: body, query: { owner: owner, **query })
|
|
812
|
+
end
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
# MCP servers that code boxes attach, over /v1/mcp-servers. A server is named "name",
|
|
816
|
+
# "team/name" or by its id. A var is { name:, default:, secret:, description: }; ${NAME} in
|
|
817
|
+
# +url+ or +headers+ is filled from it.
|
|
818
|
+
class McpServers
|
|
819
|
+
include Names
|
|
820
|
+
|
|
821
|
+
def initialize(client)
|
|
822
|
+
@c = client
|
|
823
|
+
end
|
|
824
|
+
|
|
825
|
+
# 201 { id, status }; the first check runs before the answer.
|
|
826
|
+
def create(server:, url:, description: nil, headers: nil, vars: nil, tools: nil, protocol_version: nil)
|
|
827
|
+
team, name = owned(server)
|
|
828
|
+
@c.request("POST", "/v1/mcp-servers",
|
|
829
|
+
body: { name: name, team: team, url: url, description: description, headers: headers,
|
|
830
|
+
vars: vars, tools: tools, protocolVersion: protocol_version }.compact)
|
|
831
|
+
end
|
|
832
|
+
|
|
833
|
+
# Your servers (or +team+'s) and the built-in "kode".
|
|
834
|
+
def list(team: nil)
|
|
835
|
+
@c.request("GET", "/v1/mcp-servers", query: { team: team })
|
|
836
|
+
end
|
|
837
|
+
|
|
838
|
+
def get(server:)
|
|
839
|
+
at("GET", server)
|
|
840
|
+
end
|
|
841
|
+
|
|
842
|
+
# Change the given fields, then re-check.
|
|
843
|
+
def update(server:, url: nil, description: nil, headers: nil, vars: nil, tools: nil, protocol_version: nil)
|
|
844
|
+
at("PATCH", server, body: { url: url, description: description, headers: headers, vars: vars,
|
|
845
|
+
tools: tools, protocolVersion: protocol_version }.compact)
|
|
846
|
+
end
|
|
847
|
+
|
|
848
|
+
# 204, or 409 IN_USE naming the boxes that attach it.
|
|
849
|
+
def delete(server:)
|
|
850
|
+
at("DELETE", server)
|
|
851
|
+
end
|
|
852
|
+
|
|
853
|
+
# Check it now with the defaults.
|
|
854
|
+
def check(server:)
|
|
855
|
+
at("POST", server, "/check")
|
|
856
|
+
end
|
|
857
|
+
|
|
858
|
+
# Its tools with input schemas, fetched live; +via+ ("box/alias") uses that attachment's vars.
|
|
859
|
+
def tools(server:, via: nil)
|
|
860
|
+
at("GET", server, "/tools", query: { via: via })
|
|
861
|
+
end
|
|
862
|
+
|
|
863
|
+
private
|
|
864
|
+
|
|
865
|
+
def at(method, server, tail = "", body: nil, query: {})
|
|
866
|
+
owner, name = owned(server)
|
|
867
|
+
@c.request(method, "/v1/mcp-servers/#{seg(name)}#{tail}", body: body, query: { owner: owner, **query })
|
|
868
|
+
end
|
|
869
|
+
end
|
|
870
|
+
|
|
871
|
+
# Cloud Chromium browsers that keep cookies, storage, tabs and downloads, over
|
|
872
|
+
# /v1/browser-sandboxes. A sandbox is named "name", "team/name" or by its id.
|
|
873
|
+
class BrowserSandboxes
|
|
874
|
+
include Names
|
|
875
|
+
|
|
876
|
+
def initialize(client)
|
|
877
|
+
@c = client
|
|
878
|
+
end
|
|
879
|
+
|
|
880
|
+
# 201; it starts running unless +running+ is false. +viewport+ is { width:, height: };
|
|
881
|
+
# +from_box+ (a sandbox, with +from_snapshot+) starts it as a copy of a snapshot.
|
|
882
|
+
def create(sandbox:, size_gb:, locale: nil, timezone: nil, viewport: nil, tabs: nil, memory_mb: nil,
|
|
883
|
+
running: nil, idle_stop_minutes: nil, from_box: nil, from_snapshot: nil)
|
|
884
|
+
team, name = owned(sandbox)
|
|
885
|
+
limits = { tabs: tabs, memoryMb: memory_mb }.compact
|
|
886
|
+
@c.request("POST", "/v1/browser-sandboxes",
|
|
887
|
+
body: { name: name, team: team, sizeGb: size_gb, locale: locale, timezone: timezone,
|
|
888
|
+
viewport: viewport, limits: limits.empty? ? nil : limits, running: running,
|
|
889
|
+
idleStopMinutes: idle_stop_minutes,
|
|
890
|
+
from: from_box && { box: from_box, snapshot: from_snapshot }.compact }.compact)
|
|
891
|
+
end
|
|
892
|
+
|
|
893
|
+
def list(team: nil)
|
|
894
|
+
@c.request("GET", "/v1/browser-sandboxes", query: { team: team })
|
|
895
|
+
end
|
|
896
|
+
|
|
897
|
+
def get(sandbox:)
|
|
898
|
+
at("GET", sandbox)
|
|
899
|
+
end
|
|
900
|
+
|
|
901
|
+
# 202; its state, downloads and snapshots go with it.
|
|
902
|
+
def delete(sandbox:)
|
|
903
|
+
at("DELETE", sandbox)
|
|
904
|
+
end
|
|
905
|
+
|
|
906
|
+
def resize(sandbox:, size_gb:)
|
|
907
|
+
at("PUT", sandbox, "/size", body: { sizeGb: size_gb })
|
|
908
|
+
end
|
|
909
|
+
|
|
910
|
+
# Minutes unused before a running browser stops itself (0..=1440, 0 never); from the next start.
|
|
911
|
+
def set_idle(sandbox:, minutes:)
|
|
912
|
+
at("PATCH", sandbox, body: { idleStopMinutes: minutes })
|
|
913
|
+
end
|
|
914
|
+
|
|
915
|
+
# 409 RUNNING_LIMIT past 3 running; 503 NO_CAPACITY means try again.
|
|
916
|
+
def start(sandbox:)
|
|
917
|
+
at("POST", sandbox, "/start")
|
|
918
|
+
end
|
|
919
|
+
|
|
920
|
+
# Saves the state and closes the browser.
|
|
921
|
+
def stop(sandbox:)
|
|
922
|
+
at("POST", sandbox, "/stop")
|
|
923
|
+
end
|
|
924
|
+
|
|
925
|
+
# One action of the browser tool, e.g. act(sandbox: s, action: "navigate", url: u); every
|
|
926
|
+
# other keyword is that action's own argument.
|
|
927
|
+
def act(sandbox:, action:, **args)
|
|
928
|
+
at("POST", sandbox, "/actions", body: { **args, action: action }.compact)
|
|
929
|
+
end
|
|
930
|
+
|
|
931
|
+
# "take": a person takes control from the agent; "release" hands it back.
|
|
932
|
+
def control(sandbox:, action:)
|
|
933
|
+
at("POST", sandbox, "/control", body: { action: action })
|
|
934
|
+
end
|
|
935
|
+
|
|
936
|
+
def snapshots(sandbox:)
|
|
937
|
+
at("GET", sandbox, "/snapshots")
|
|
938
|
+
end
|
|
939
|
+
|
|
940
|
+
def take_snapshot(sandbox:, message: nil, tag: nil)
|
|
941
|
+
at("POST", sandbox, "/snapshots", body: { message: message, tag: tag }.compact)
|
|
942
|
+
end
|
|
943
|
+
|
|
944
|
+
# +snapshot+ is a version, a tag or a snapshot id.
|
|
945
|
+
def restore(sandbox:, snapshot:)
|
|
946
|
+
at("POST", sandbox, "/restore", body: { from: snapshot })
|
|
947
|
+
end
|
|
948
|
+
|
|
949
|
+
private
|
|
950
|
+
|
|
951
|
+
def at(method, sandbox, tail = "", body: nil)
|
|
952
|
+
owner, name = owned(sandbox)
|
|
953
|
+
@c.request(method, "/v1/browser-sandboxes/#{seg(name)}#{tail}", body: body, query: { owner: owner })
|
|
608
954
|
end
|
|
609
955
|
end
|
|
610
956
|
|
|
@@ -663,7 +1009,7 @@ module Kloudlite
|
|
|
663
1009
|
end
|
|
664
1010
|
end
|
|
665
1011
|
|
|
666
|
-
# The btrfs volumes behind workspaces and environments:
|
|
1012
|
+
# The btrfs volumes behind workspaces and environments: their snapshots, restore targets, and
|
|
667
1013
|
# the deletes — over /v1/volumes.
|
|
668
1014
|
class Volumes
|
|
669
1015
|
include Names
|
|
@@ -678,13 +1024,9 @@ module Kloudlite
|
|
|
678
1024
|
@c.request("GET", "/v1/volumes", query: { kind: kind, owner: owner, label: label })
|
|
679
1025
|
end
|
|
680
1026
|
|
|
681
|
-
#
|
|
682
|
-
def
|
|
683
|
-
@c.request("GET", "/v1/volumes/#{seg(volume)}
|
|
684
|
-
end
|
|
685
|
-
|
|
686
|
-
def refs(volume:)
|
|
687
|
-
@c.request("GET", "/v1/volumes/#{seg(volume)}/refs")
|
|
1027
|
+
# A volume by its id, named or not: its disks and its snapshots, newest first.
|
|
1028
|
+
def get_by_id(volume:)
|
|
1029
|
+
@c.request("GET", "/v1/volumes/#{seg(volume)}")
|
|
688
1030
|
end
|
|
689
1031
|
|
|
690
1032
|
# Refused (409) for a sync point or a running worktree's base; deleting a detached volume's
|
|
@@ -699,7 +1041,7 @@ module Kloudlite
|
|
|
699
1041
|
end
|
|
700
1042
|
|
|
701
1043
|
# One named volume; +owner+ is your handle or a team slug. It carries +description+,
|
|
702
|
-
# +labels+ and +
|
|
1044
|
+
# +labels+ and +tags+ (each tag with the number of the snapshot it is on).
|
|
703
1045
|
def get(owner:, name:)
|
|
704
1046
|
@c.request("GET", named(owner, name))
|
|
705
1047
|
end
|
|
@@ -711,19 +1053,19 @@ module Kloudlite
|
|
|
711
1053
|
body: { description: description, labels: labels }.compact)
|
|
712
1054
|
end
|
|
713
1055
|
|
|
714
|
-
#
|
|
715
|
-
#
|
|
716
|
-
def
|
|
717
|
-
@c.request("PUT", named(owner, name, "/
|
|
1056
|
+
# Put +tag+ on a snapshot, or move it there: give +version+ (the snapshot number) or
|
|
1057
|
+
# +snapshot+ (a snapshot id), not both. Answers the volume.
|
|
1058
|
+
def set_tag(owner:, name:, tag:, version: nil, snapshot: nil)
|
|
1059
|
+
@c.request("PUT", named(owner, name, "/tags/#{seg(tag)}"),
|
|
718
1060
|
body: { version: version, snapshot: snapshot }.compact)
|
|
719
1061
|
end
|
|
720
1062
|
|
|
721
|
-
# Remove a
|
|
722
|
-
def
|
|
723
|
-
@c.request("DELETE", named(owner, name, "/
|
|
1063
|
+
# Remove a tag (204); its snapshot stays.
|
|
1064
|
+
def delete_tag(owner:, name:, tag:)
|
|
1065
|
+
@c.request("DELETE", named(owner, name, "/tags/#{seg(tag)}"))
|
|
724
1066
|
end
|
|
725
1067
|
|
|
726
|
-
# The storage commits of a named volume, newest first; each row carries the +
|
|
1068
|
+
# The storage commits of a named volume, newest first; each row carries the +tags+ on it.
|
|
727
1069
|
def versions(owner:, name:)
|
|
728
1070
|
@c.request("GET", named(owner, name, "/versions"))
|
|
729
1071
|
end
|
|
@@ -733,8 +1075,8 @@ module Kloudlite
|
|
|
733
1075
|
@c.request("DELETE", named(owner, name))
|
|
734
1076
|
end
|
|
735
1077
|
|
|
736
|
-
# Delete storage commit +n+ (204); deleting the last one deletes the volume. A
|
|
737
|
-
#
|
|
1078
|
+
# Delete storage commit +n+ (204); deleting the last one deletes the volume. A tagged
|
|
1079
|
+
# snapshot is refused (409).
|
|
738
1080
|
def delete_version(owner:, name:, n:)
|
|
739
1081
|
@c.request("DELETE", named(owner, name, "/versions/#{Integer(n)}"))
|
|
740
1082
|
end
|
|
@@ -758,7 +1100,7 @@ module Kloudlite
|
|
|
758
1100
|
include Names
|
|
759
1101
|
|
|
760
1102
|
# The POST /v1/capsules body; refuses a missing +cmd+ before anything is sent. Shared with
|
|
761
|
-
#
|
|
1103
|
+
# Netgroups#create_capsule — not public surface.
|
|
762
1104
|
def self.body(cmd:, image: nil, packages: nil, from_workspace: nil, from_snapshot: nil, team: nil,
|
|
763
1105
|
tty: nil, stdin: nil, timeout_s: nil, network: nil, env: nil, cpu: nil,
|
|
764
1106
|
memory_gb: nil, disk_gb: nil)
|
|
@@ -779,8 +1121,8 @@ module Kloudlite
|
|
|
779
1121
|
# is the program then its arguments. +tty+ runs it on a pty; +stdin+ keeps input open for
|
|
780
1122
|
# attach. +timeout_s+ is 10..=86400. +from_workspace+ is an id, "name" or "team/name";
|
|
781
1123
|
# +from_snapshot+ a volume name, "name@N" or snapshot id (exclusive with it). +network+ is
|
|
782
|
-
# "internet" or "none"; +cpu+ 1..=8, +memory_gb+ 1..=32. A
|
|
783
|
-
#
|
|
1124
|
+
# "internet" or "none"; +cpu+ 1..=8, +memory_gb+ 1..=32. A netgroup's capsule is made with
|
|
1125
|
+
# Netgroups#create_capsule. Unset keywords are omitted, so the server's defaults apply.
|
|
784
1126
|
def create(cmd:, **options)
|
|
785
1127
|
Capsule.new(@c, @c.request("POST", "/v1/capsules", body: Capsules.body(cmd: cmd, **options)))
|
|
786
1128
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kloudlite-sdk
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kloudlite
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-12-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description:
|
|
14
14
|
email:
|