kloudlite-sdk 0.6.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 +327 -2
- 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
|
@@ -21,11 +21,12 @@ raise LoadError, "kloudlite.rb needs Ruby 3.0 or later, found #{RUBY_VERSION}" i
|
|
|
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
|
|
|
@@ -85,7 +86,8 @@ module Kloudlite
|
|
|
85
86
|
|
|
86
87
|
class Client
|
|
87
88
|
attr_reader :workspaces, :environments, :netgroups, :volumes,
|
|
88
|
-
:secrets, :connectors, :capsules, :pipelines
|
|
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"])
|
|
@@ -109,6 +111,10 @@ module Kloudlite
|
|
|
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.
|
|
@@ -629,6 +635,325 @@ module Kloudlite
|
|
|
629
635
|
end
|
|
630
636
|
end
|
|
631
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 })
|
|
954
|
+
end
|
|
955
|
+
end
|
|
956
|
+
|
|
632
957
|
# An owner's named secrets, over /v1/secrets. A value goes in and never comes back: +list+
|
|
633
958
|
# answers names with who and when. Reference one from a workspace env as "${{ secrets.NAME }}".
|
|
634
959
|
# +scope+ "mine" (default) is your own secret in the team +owner+ (for your own handle, your
|
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:
|