@kosa8/sdk 0.1.0 → 0.3.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.
- package/README.md +82 -4
- package/dist/index.cjs +748 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +546 -1
- package/dist/index.d.ts +546 -1
- package/dist/index.js +737 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -89,6 +89,24 @@ interface Sandbox {
|
|
|
89
89
|
ip?: string;
|
|
90
90
|
labels?: Record<string, string>;
|
|
91
91
|
broker?: BrokerInfo;
|
|
92
|
+
/** When it stops or is deleted by itself (pkg/sandbox Lifecycle). */
|
|
93
|
+
lifecycle?: Lifecycle;
|
|
94
|
+
/** When it last stopped (RFC 3339). */
|
|
95
|
+
stopped_at?: string;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* When a sandbox stops or goes away by itself (pkg/sandbox Lifecycle).
|
|
99
|
+
* A field left out (or 0) is off.
|
|
100
|
+
*/
|
|
101
|
+
interface Lifecycle {
|
|
102
|
+
/** Stop after this many minutes without use. */
|
|
103
|
+
auto_stop_min?: number;
|
|
104
|
+
/** Delete once it has been stopped this many minutes. */
|
|
105
|
+
auto_delete_min?: number;
|
|
106
|
+
/** Stop this many minutes after it was created, in use or not. */
|
|
107
|
+
ttl_min?: number;
|
|
108
|
+
/** Delete instead of stopping, disk and all. */
|
|
109
|
+
ephemeral?: boolean;
|
|
92
110
|
}
|
|
93
111
|
/** A saved sandbox state (pkg/sandbox Snapshot). */
|
|
94
112
|
interface Snapshot {
|
|
@@ -257,6 +275,124 @@ interface ExploreResult {
|
|
|
257
275
|
winner: string;
|
|
258
276
|
removed: number;
|
|
259
277
|
}
|
|
278
|
+
/** A file a code run produced: today, a chart as a PNG. */
|
|
279
|
+
interface CodeArtifact {
|
|
280
|
+
/** Media type, e.g. `image/png`. */
|
|
281
|
+
type: string;
|
|
282
|
+
name: string;
|
|
283
|
+
data: Buffer;
|
|
284
|
+
}
|
|
285
|
+
/** The outcome of `runCode`. A non-zero `exitCode` is a result, not an error. */
|
|
286
|
+
interface CodeResult {
|
|
287
|
+
/** `exitCode === 0` and not timed out. */
|
|
288
|
+
ok: boolean;
|
|
289
|
+
exitCode: number;
|
|
290
|
+
stdout: string;
|
|
291
|
+
stderr: string;
|
|
292
|
+
language: string;
|
|
293
|
+
image: string;
|
|
294
|
+
artifacts: CodeArtifact[];
|
|
295
|
+
durationMs: number;
|
|
296
|
+
timedOut: boolean;
|
|
297
|
+
/** Output was cut at the daemon's limit. */
|
|
298
|
+
truncated: boolean;
|
|
299
|
+
}
|
|
300
|
+
/** The outcome of one command in a shell session. `cwd` is where the shell is now. */
|
|
301
|
+
interface ShellResult {
|
|
302
|
+
ok: boolean;
|
|
303
|
+
exitCode: number;
|
|
304
|
+
stdout: string;
|
|
305
|
+
stderr: string;
|
|
306
|
+
cwd: string;
|
|
307
|
+
durationMs: number;
|
|
308
|
+
timedOut: boolean;
|
|
309
|
+
truncated: boolean;
|
|
310
|
+
}
|
|
311
|
+
/** A file or folder in the sandbox workspace (pkg/engine FileInfo). */
|
|
312
|
+
interface FileInfo {
|
|
313
|
+
name: string;
|
|
314
|
+
path: string;
|
|
315
|
+
/** file | dir | symlink | other */
|
|
316
|
+
type: string;
|
|
317
|
+
size: number;
|
|
318
|
+
/** Permission bits. */
|
|
319
|
+
mode: number;
|
|
320
|
+
mod_time: string;
|
|
321
|
+
/** A symlink's target. */
|
|
322
|
+
link?: string;
|
|
323
|
+
}
|
|
324
|
+
/** One changed path in `git status`. */
|
|
325
|
+
interface GitFileStatus {
|
|
326
|
+
path: string;
|
|
327
|
+
/** A rename's old path. */
|
|
328
|
+
from?: string;
|
|
329
|
+
index: string;
|
|
330
|
+
worktree: string;
|
|
331
|
+
}
|
|
332
|
+
interface GitStatus {
|
|
333
|
+
branch: string;
|
|
334
|
+
upstream?: string;
|
|
335
|
+
ahead: number;
|
|
336
|
+
behind: number;
|
|
337
|
+
clean: boolean;
|
|
338
|
+
files: GitFileStatus[];
|
|
339
|
+
}
|
|
340
|
+
interface GitCommit {
|
|
341
|
+
hash: string;
|
|
342
|
+
author_name: string;
|
|
343
|
+
author_email: string;
|
|
344
|
+
date: string;
|
|
345
|
+
subject: string;
|
|
346
|
+
}
|
|
347
|
+
interface GitBranch {
|
|
348
|
+
name: string;
|
|
349
|
+
current: boolean;
|
|
350
|
+
}
|
|
351
|
+
/** The git operations the daemon runs (POST …/git). */
|
|
352
|
+
type GitOp = 'clone' | 'status' | 'add' | 'commit' | 'push' | 'pull' | 'checkout' | 'branches' | 'log' | 'diff';
|
|
353
|
+
/**
|
|
354
|
+
* The outcome of a git operation. A git failure is `ok: false`, not an error;
|
|
355
|
+
* `status`, `log` or `branches` are filled for those ops.
|
|
356
|
+
*/
|
|
357
|
+
interface GitResult {
|
|
358
|
+
op: string;
|
|
359
|
+
ok: boolean;
|
|
360
|
+
exitCode: number;
|
|
361
|
+
stdout: string;
|
|
362
|
+
stderr: string;
|
|
363
|
+
/** The repository, in the workspace. */
|
|
364
|
+
path: string;
|
|
365
|
+
status?: GitStatus;
|
|
366
|
+
log?: GitCommit[];
|
|
367
|
+
branches?: GitBranch[];
|
|
368
|
+
}
|
|
369
|
+
/** A shell session (POST/GET …/sessions). */
|
|
370
|
+
interface SessionInfo {
|
|
371
|
+
name: string;
|
|
372
|
+
/** The session's container id. */
|
|
373
|
+
id: string;
|
|
374
|
+
image: string;
|
|
375
|
+
status: string;
|
|
376
|
+
}
|
|
377
|
+
/** POST …/previews answer: a signed link to a port in the sandbox. */
|
|
378
|
+
interface Preview {
|
|
379
|
+
url: string;
|
|
380
|
+
token: string;
|
|
381
|
+
/** RFC 3339. */
|
|
382
|
+
expires_at: string;
|
|
383
|
+
container: string;
|
|
384
|
+
port: number;
|
|
385
|
+
/** Where the daemon's preview listener is. */
|
|
386
|
+
listen: string;
|
|
387
|
+
}
|
|
388
|
+
/** A sandbox template (GET /kosa8/v1/templates). */
|
|
389
|
+
interface Template {
|
|
390
|
+
name: string;
|
|
391
|
+
image: string;
|
|
392
|
+
size_bytes: number;
|
|
393
|
+
created: string;
|
|
394
|
+
dockerfile?: string;
|
|
395
|
+
}
|
|
260
396
|
|
|
261
397
|
/**
|
|
262
398
|
* Checkpoints are client-side bookkeeping over daemon snapshots, exactly as
|
|
@@ -356,6 +492,13 @@ interface TransportOptions {
|
|
|
356
492
|
headers?: Record<string, string>;
|
|
357
493
|
/** Environment to read KOSA8_* variables from. Default `process.env`. */
|
|
358
494
|
env?: Record<string, string | undefined>;
|
|
495
|
+
/**
|
|
496
|
+
* The CLI's saved worker connection, used when neither `host` nor KOSA8_HOST
|
|
497
|
+
* is set (and no `socketPath` is given): what `kosa8 wsl setup` writes on
|
|
498
|
+
* Windows, and `kosa8 worker join` anywhere. Default
|
|
499
|
+
* `$HOME/.kosa8/worker.json`; `null` reads none.
|
|
500
|
+
*/
|
|
501
|
+
workerFile?: string | null;
|
|
359
502
|
}
|
|
360
503
|
interface RequestOptions {
|
|
361
504
|
query?: Record<string, string | number | boolean | undefined>;
|
|
@@ -380,6 +523,8 @@ declare const ACTOR_HEADER = "X-Kosa8-Actor";
|
|
|
380
523
|
declare const AGENT_TOKEN_HEADER = "X-Kosa8-Agent-Token";
|
|
381
524
|
/** The daemon's default socket: $HOME/.kosa8/run/kosa8.sock (pkg/paths). */
|
|
382
525
|
declare function defaultSocketPath(): string;
|
|
526
|
+
/** The CLI's saved worker connection: $HOME/.kosa8/worker.json (internal/cli/worker.go). */
|
|
527
|
+
declare function defaultWorkerFile(): string;
|
|
383
528
|
/** Resolve where to connect, following the CLI's KOSA8_HOST rules. */
|
|
384
529
|
declare function resolveEndpoint(opts: TransportOptions): Endpoint;
|
|
385
530
|
interface RawResponse {
|
|
@@ -447,6 +592,106 @@ interface CreateSandboxOptions extends CallOptions {
|
|
|
447
592
|
labels?: Record<string, string>;
|
|
448
593
|
/** Put the sandbox behind an egress broker that adds credentials it never holds. */
|
|
449
594
|
broker?: BrokerSpec;
|
|
595
|
+
/** Stop it after this many idle minutes. */
|
|
596
|
+
autoStopMin?: number;
|
|
597
|
+
/** Stop it this many minutes after creation, in use or not. */
|
|
598
|
+
ttlMin?: number;
|
|
599
|
+
/** Delete it once it has been stopped this many minutes. */
|
|
600
|
+
autoDeleteMin?: number;
|
|
601
|
+
/** Delete it (disk and all) whenever it stops. */
|
|
602
|
+
ephemeral?: boolean;
|
|
603
|
+
/** Start it with a template's image (see `buildTemplate`). */
|
|
604
|
+
template?: string;
|
|
605
|
+
}
|
|
606
|
+
interface RunCodeOptions extends CallOptions {
|
|
607
|
+
/** `python` (default), `javascript` or `typescript`. */
|
|
608
|
+
language?: string;
|
|
609
|
+
/** Image to run in; the daemon picks one per language (or the sandbox template's). */
|
|
610
|
+
image?: string;
|
|
611
|
+
env?: Record<string, string>;
|
|
612
|
+
/** Time limit in seconds; past it the run is killed and `timedOut` set. */
|
|
613
|
+
timeoutS?: number;
|
|
614
|
+
}
|
|
615
|
+
interface WriteFileOptions extends CallOptions {
|
|
616
|
+
/** Permission bits as octal text, e.g. `0755`. */
|
|
617
|
+
mode?: string;
|
|
618
|
+
}
|
|
619
|
+
/** The fields of a git op; which ones matter depends on the op. */
|
|
620
|
+
interface GitOptions extends CallOptions {
|
|
621
|
+
/** The repository, in the workspace. */
|
|
622
|
+
path?: string;
|
|
623
|
+
/** clone */
|
|
624
|
+
url?: string;
|
|
625
|
+
branch?: string;
|
|
626
|
+
/** clone --depth */
|
|
627
|
+
depth?: number;
|
|
628
|
+
/** push | pull; default origin */
|
|
629
|
+
remote?: string;
|
|
630
|
+
/** checkout -b */
|
|
631
|
+
create?: boolean;
|
|
632
|
+
/** add: these paths (default everything) */
|
|
633
|
+
files?: string[];
|
|
634
|
+
/** commit */
|
|
635
|
+
message?: string;
|
|
636
|
+
authorName?: string;
|
|
637
|
+
authorEmail?: string;
|
|
638
|
+
/** log: how many (default 20) */
|
|
639
|
+
n?: number;
|
|
640
|
+
/** diff --cached */
|
|
641
|
+
staged?: boolean;
|
|
642
|
+
/** For an https remote that needs credentials. */
|
|
643
|
+
username?: string;
|
|
644
|
+
token?: string;
|
|
645
|
+
/** Image git runs in. */
|
|
646
|
+
image?: string;
|
|
647
|
+
}
|
|
648
|
+
interface GitCommitOptions extends Omit<GitOptions, 'path' | 'message'> {
|
|
649
|
+
/** Stage everything first (default true). */
|
|
650
|
+
addAll?: boolean;
|
|
651
|
+
}
|
|
652
|
+
interface CreateSessionOptions extends CallOptions {
|
|
653
|
+
image?: string;
|
|
654
|
+
env?: Record<string, string>;
|
|
655
|
+
}
|
|
656
|
+
interface SessionExecOptions extends CallOptions {
|
|
657
|
+
/** Time limit in seconds for this command. */
|
|
658
|
+
timeoutS?: number;
|
|
659
|
+
}
|
|
660
|
+
interface ShellOptions extends SessionExecOptions {
|
|
661
|
+
/** Session to run in; made on first use. Default `main`. */
|
|
662
|
+
session?: string;
|
|
663
|
+
}
|
|
664
|
+
interface StartPtyOptions extends CallOptions {
|
|
665
|
+
image?: string;
|
|
666
|
+
command?: string[];
|
|
667
|
+
cols?: number;
|
|
668
|
+
rows?: number;
|
|
669
|
+
env?: Record<string, string>;
|
|
670
|
+
}
|
|
671
|
+
interface CreatePreviewOptions extends CallOptions {
|
|
672
|
+
/** Which session's container serves the port. */
|
|
673
|
+
session?: string;
|
|
674
|
+
/** Or which container. */
|
|
675
|
+
container?: string;
|
|
676
|
+
/** How long the link lives, in seconds. */
|
|
677
|
+
expiresInS?: number;
|
|
678
|
+
}
|
|
679
|
+
interface SetLifecycleOptions extends CallOptions {
|
|
680
|
+
autoStopMin?: number;
|
|
681
|
+
autoDeleteMin?: number;
|
|
682
|
+
ttlMin?: number;
|
|
683
|
+
ephemeral?: boolean;
|
|
684
|
+
}
|
|
685
|
+
interface BuildTemplateOptions extends CallOptions {
|
|
686
|
+
/** Dockerfile name inside the context (default `Dockerfile`). */
|
|
687
|
+
dockerfile?: string;
|
|
688
|
+
buildArgs?: Record<string, string>;
|
|
689
|
+
/** Network the build sandbox gets (daemon default `any`). */
|
|
690
|
+
egress?: EgressPolicy;
|
|
691
|
+
/** Build again over an existing template of the same name. */
|
|
692
|
+
replace?: boolean;
|
|
693
|
+
/** Build output as it arrives. */
|
|
694
|
+
onOutput?: (chunk: Buffer, stream: string) => void;
|
|
450
695
|
}
|
|
451
696
|
interface RunOptions extends CallOptions {
|
|
452
697
|
env?: Record<string, string> | string[];
|
|
@@ -629,6 +874,92 @@ declare class Kosa8Client {
|
|
|
629
874
|
* checkpoints taken after the target are discarded. Current state is lost.
|
|
630
875
|
*/
|
|
631
876
|
rewind(sandbox: string, opts?: RewindOptions): Promise<RewindResult>;
|
|
877
|
+
/**
|
|
878
|
+
* POST /kosa8/v1/sandboxes/{id}/code: run a Python, JavaScript or
|
|
879
|
+
* TypeScript snippet. It starts in `/workspace`. Charts a Python snippet
|
|
880
|
+
* draws with matplotlib come back in `artifacts` as PNG bytes.
|
|
881
|
+
*/
|
|
882
|
+
runCode(id: string, code: string, opts?: RunCodeOptions): Promise<CodeResult>;
|
|
883
|
+
/** GET …/files: a folder in the workspace (default `/workspace`), or one entry. */
|
|
884
|
+
listFiles(id: string, path?: string, opts?: CallOptions): Promise<FileInfo[]>;
|
|
885
|
+
/** GET …/files/stat: one entry, not following a symlink. */
|
|
886
|
+
statFile(id: string, path: string, opts?: CallOptions): Promise<FileInfo>;
|
|
887
|
+
/** GET …/files/content: a file's bytes. A body cut short is a Kosa8StreamError. */
|
|
888
|
+
readFile(id: string, path: string, opts?: CallOptions): Promise<Buffer>;
|
|
889
|
+
/** A file's contents as text (UTF-8 by default). */
|
|
890
|
+
readText(id: string, path: string, opts?: CallOptions & {
|
|
891
|
+
encoding?: BufferEncoding;
|
|
892
|
+
}): Promise<string>;
|
|
893
|
+
/** PUT …/files/content: replace a file, making its folders. Answers the new entry. */
|
|
894
|
+
writeFile(id: string, path: string, data: Uint8Array | string | AsyncIterable<Uint8Array | string>, opts?: WriteFileOptions): Promise<FileInfo>;
|
|
895
|
+
/** DELETE …/files: a file, or with `recursive` a folder and everything in it. */
|
|
896
|
+
deleteFile(id: string, path: string, opts?: CallOptions & {
|
|
897
|
+
recursive?: boolean;
|
|
898
|
+
}): Promise<{
|
|
899
|
+
removed: string;
|
|
900
|
+
}>;
|
|
901
|
+
/** POST …/files/mkdir: a folder, with its parents. */
|
|
902
|
+
makeDir(id: string, path: string, opts?: CallOptions): Promise<FileInfo>;
|
|
903
|
+
/** POST …/files/move: rename or move a file or folder. Answers the entry at `to`. */
|
|
904
|
+
moveFile(id: string, from: string, to: string, opts?: CallOptions): Promise<FileInfo>;
|
|
905
|
+
/**
|
|
906
|
+
* POST …/git: one git operation in the workspace. A git failure resolves
|
|
907
|
+
* with `ok: false`; only a refusal (bad op, no sandbox, policy) throws.
|
|
908
|
+
*/
|
|
909
|
+
git(id: string, op: GitOp | (string & {}), opts?: GitOptions): Promise<GitResult>;
|
|
910
|
+
/** Clone `url` into the workspace (into `path`, else a folder named after the repo). */
|
|
911
|
+
gitClone(id: string, url: string, opts?: GitOptions): Promise<GitResult>;
|
|
912
|
+
/** `git status` of the repository at `path`, parsed into `status`. */
|
|
913
|
+
gitStatus(id: string, path: string, opts?: GitOptions): Promise<GitResult>;
|
|
914
|
+
/** Stage everything (unless `addAll: false`) and commit. A failed add is returned as is. */
|
|
915
|
+
gitCommit(id: string, path: string, message: string, opts?: GitCommitOptions): Promise<GitResult>;
|
|
916
|
+
/** POST …/sessions: a shell that keeps `cd` and `export` between commands. */
|
|
917
|
+
createSession(id: string, name?: string, opts?: CreateSessionOptions): Promise<SessionInfo>;
|
|
918
|
+
/** GET …/sessions */
|
|
919
|
+
listSessions(id: string, opts?: CallOptions): Promise<SessionInfo[]>;
|
|
920
|
+
/** POST …/sessions/{name}/exec: run one command line in the session. */
|
|
921
|
+
sessionExec(id: string, session: string, command: string, opts?: SessionExecOptions): Promise<ShellResult>;
|
|
922
|
+
/** Run a command in a session (default `main`), making the session on first use. */
|
|
923
|
+
shell(id: string, command: string, opts?: ShellOptions): Promise<ShellResult>;
|
|
924
|
+
/** DELETE …/sessions/{name} */
|
|
925
|
+
deleteSession(id: string, session: string, opts?: CallOptions): Promise<{
|
|
926
|
+
deleted: string;
|
|
927
|
+
}>;
|
|
928
|
+
/**
|
|
929
|
+
* POST …/pty: a container with a terminal; resolves with its id. Connect
|
|
930
|
+
* to `/kosa8/v1/sandboxes/{id}/containers/{cid}/tty` with any WebSocket
|
|
931
|
+
* client: binary messages are the terminal, text messages JSON control.
|
|
932
|
+
*/
|
|
933
|
+
startPty(id: string, opts?: StartPtyOptions): Promise<string>;
|
|
934
|
+
/** POST …/containers/{cid}/resize: set a terminal's size. */
|
|
935
|
+
resizePty(id: string, container: string, cols: number, rows: number, opts?: CallOptions): Promise<{
|
|
936
|
+
ok: boolean;
|
|
937
|
+
}>;
|
|
938
|
+
/** POST …/previews: a signed link, which expires, to a web server in the sandbox. */
|
|
939
|
+
createPreview(id: string, port: number, opts?: CreatePreviewOptions): Promise<Preview>;
|
|
940
|
+
/** POST /kosa8/v1/previews/rotate: end every preview link at once. */
|
|
941
|
+
revokePreviews(opts?: CallOptions): Promise<{
|
|
942
|
+
ok: boolean;
|
|
943
|
+
revoked: string;
|
|
944
|
+
}>;
|
|
945
|
+
/**
|
|
946
|
+
* POST …/lifecycle: change auto-stop, auto-delete, TTL or ephemeral.
|
|
947
|
+
* Options left out keep their value; 0 (or `false`) turns one off.
|
|
948
|
+
*/
|
|
949
|
+
setLifecycle(id: string, opts?: SetLifecycleOptions): Promise<Sandbox>;
|
|
950
|
+
/** GET /kosa8/v1/templates */
|
|
951
|
+
listTemplates(opts?: CallOptions): Promise<Template[]>;
|
|
952
|
+
/** DELETE /kosa8/v1/templates/{name}. Sandboxes made from it keep their copy. */
|
|
953
|
+
deleteTemplate(name: string, opts?: CallOptions): Promise<{
|
|
954
|
+
deleted: string;
|
|
955
|
+
}>;
|
|
956
|
+
/**
|
|
957
|
+
* POST /kosa8/v1/templates: build `contextDir`'s Dockerfile in a throwaway
|
|
958
|
+
* sandbox and keep the image as a template, for `createSandbox({ template })`.
|
|
959
|
+
* The context is packed honouring `.dockerignore`. Resolves with the final
|
|
960
|
+
* frame (`{ done, ok, image }`); a failed build throws Kosa8StreamError.
|
|
961
|
+
*/
|
|
962
|
+
buildTemplate(name: string, contextDir?: string, opts?: BuildTemplateOptions): Promise<Frame>;
|
|
632
963
|
/** A handle bound to one sandbox. */
|
|
633
964
|
sandbox(id: string): SandboxHandle;
|
|
634
965
|
private collect;
|
|
@@ -666,8 +997,46 @@ declare class SandboxHandle {
|
|
|
666
997
|
checkpoint(opts?: CheckpointOptions): Promise<CheckpointResult>;
|
|
667
998
|
checkpoints(): Promise<Checkpoint[]>;
|
|
668
999
|
rewind(opts?: RewindOptions): Promise<RewindResult>;
|
|
1000
|
+
runCode(code: string, opts?: RunCodeOptions): Promise<CodeResult>;
|
|
1001
|
+
listFiles(path?: string, opts?: CallOptions): Promise<FileInfo[]>;
|
|
1002
|
+
statFile(path: string, opts?: CallOptions): Promise<FileInfo>;
|
|
1003
|
+
readFile(path: string, opts?: CallOptions): Promise<Buffer<ArrayBufferLike>>;
|
|
1004
|
+
readText(path: string, opts?: CallOptions & {
|
|
1005
|
+
encoding?: BufferEncoding;
|
|
1006
|
+
}): Promise<string>;
|
|
1007
|
+
writeFile(path: string, data: Uint8Array | string | AsyncIterable<Uint8Array | string>, opts?: WriteFileOptions): Promise<FileInfo>;
|
|
1008
|
+
deleteFile(path: string, opts?: CallOptions & {
|
|
1009
|
+
recursive?: boolean;
|
|
1010
|
+
}): Promise<{
|
|
1011
|
+
removed: string;
|
|
1012
|
+
}>;
|
|
1013
|
+
makeDir(path: string, opts?: CallOptions): Promise<FileInfo>;
|
|
1014
|
+
moveFile(from: string, to: string, opts?: CallOptions): Promise<FileInfo>;
|
|
1015
|
+
git(op: GitOp | (string & {}), opts?: GitOptions): Promise<GitResult>;
|
|
1016
|
+
gitClone(url: string, opts?: GitOptions): Promise<GitResult>;
|
|
1017
|
+
gitStatus(path: string, opts?: GitOptions): Promise<GitResult>;
|
|
1018
|
+
gitCommit(path: string, message: string, opts?: GitCommitOptions): Promise<GitResult>;
|
|
1019
|
+
createSession(name?: string, opts?: CreateSessionOptions): Promise<SessionInfo>;
|
|
1020
|
+
sessions(opts?: CallOptions): Promise<SessionInfo[]>;
|
|
1021
|
+
sessionExec(session: string, command: string, opts?: SessionExecOptions): Promise<ShellResult>;
|
|
1022
|
+
shell(command: string, opts?: ShellOptions): Promise<ShellResult>;
|
|
1023
|
+
deleteSession(session: string, opts?: CallOptions): Promise<{
|
|
1024
|
+
deleted: string;
|
|
1025
|
+
}>;
|
|
1026
|
+
startPty(opts?: StartPtyOptions): Promise<string>;
|
|
1027
|
+
resizePty(container: string, cols: number, rows: number, opts?: CallOptions): Promise<{
|
|
1028
|
+
ok: boolean;
|
|
1029
|
+
}>;
|
|
1030
|
+
createPreview(port: number, opts?: CreatePreviewOptions): Promise<Preview>;
|
|
1031
|
+
setLifecycle(opts: SetLifecycleOptions): Promise<Sandbox>;
|
|
669
1032
|
}
|
|
670
1033
|
|
|
1034
|
+
/**
|
|
1035
|
+
* Pack `dir` as a tar archive for POST /kosa8/v1/templates. Throws when the
|
|
1036
|
+
* Dockerfile is missing, so a bad path fails before anything is sent.
|
|
1037
|
+
*/
|
|
1038
|
+
declare function tarContext(dir: string, dockerfile?: string): Promise<Buffer>;
|
|
1039
|
+
|
|
671
1040
|
/**
|
|
672
1041
|
* Typed errors. Every error the daemon answers with carries its own words:
|
|
673
1042
|
* `daemonMessage` is the daemon's `error` field verbatim, and `remediation`
|
|
@@ -722,6 +1091,8 @@ interface Kosa8ErrorOptions {
|
|
|
722
1091
|
path?: string;
|
|
723
1092
|
body?: unknown;
|
|
724
1093
|
cause?: unknown;
|
|
1094
|
+
/** kosa8 Cloud's stable error code, such as payment_required. */
|
|
1095
|
+
code?: string;
|
|
725
1096
|
}
|
|
726
1097
|
/** Base class of every error this SDK throws. */
|
|
727
1098
|
declare class Kosa8Error extends Error {
|
|
@@ -735,11 +1106,19 @@ declare class Kosa8Error extends Error {
|
|
|
735
1106
|
readonly path?: string;
|
|
736
1107
|
/** The decoded response body, when there was one. */
|
|
737
1108
|
readonly body?: unknown;
|
|
1109
|
+
/** kosa8 Cloud's stable error code (payment_required, quota_exceeded, ...). */
|
|
1110
|
+
readonly code?: string;
|
|
738
1111
|
constructor(message: string, options?: Kosa8ErrorOptions);
|
|
739
1112
|
}
|
|
740
1113
|
/** The daemon could not be reached (no socket, connection refused, ...). */
|
|
741
1114
|
declare class Kosa8ConnectionError extends Kosa8Error {
|
|
742
1115
|
}
|
|
1116
|
+
/**
|
|
1117
|
+
* A call took longer than its timeout. A connection error too, so code that
|
|
1118
|
+
* catches Kosa8ConnectionError keeps catching it.
|
|
1119
|
+
*/
|
|
1120
|
+
declare class Kosa8TimeoutError extends Kosa8ConnectionError {
|
|
1121
|
+
}
|
|
743
1122
|
/** The daemon answered with an HTTP error. */
|
|
744
1123
|
declare class Kosa8ApiError extends Kosa8Error {
|
|
745
1124
|
}
|
|
@@ -782,6 +1161,12 @@ declare class Kosa8StreamError extends Kosa8Error {
|
|
|
782
1161
|
stderr: string;
|
|
783
1162
|
}, options?: Kosa8ErrorOptions);
|
|
784
1163
|
}
|
|
1164
|
+
/** kosa8 Cloud refused new work until a payment method is on file (402). */
|
|
1165
|
+
declare class Kosa8PaymentRequiredError extends Kosa8ApiError {
|
|
1166
|
+
}
|
|
1167
|
+
/** Too many requests or a quota reached (429). */
|
|
1168
|
+
declare class Kosa8RateLimitError extends Kosa8ApiError {
|
|
1169
|
+
}
|
|
785
1170
|
/** A client-side checkpoint operation failed (no checkpoint, bad name, ...). */
|
|
786
1171
|
declare class Kosa8CheckpointError extends Kosa8Error {
|
|
787
1172
|
}
|
|
@@ -793,6 +1178,166 @@ declare class Kosa8CheckpointError extends Kosa8Error {
|
|
|
793
1178
|
declare function errorFromResponse(status: number, body: unknown, ctx?: {
|
|
794
1179
|
method?: string;
|
|
795
1180
|
path?: string;
|
|
1181
|
+
code?: string;
|
|
796
1182
|
}): Kosa8ApiError;
|
|
797
1183
|
|
|
798
|
-
|
|
1184
|
+
declare const DEFAULT_CLOUD_URL = "https://api.kosa8.cloud";
|
|
1185
|
+
declare const CLOUD_KEY_PREFIX = "k8c_live_";
|
|
1186
|
+
interface Kosa8CloudOptions {
|
|
1187
|
+
/** API key. Defaults to the KOSA8_API_KEY environment variable. */
|
|
1188
|
+
apiKey?: string;
|
|
1189
|
+
/** Control-plane address. Defaults to KOSA8_CLOUD_URL, then https://api.kosa8.cloud. */
|
|
1190
|
+
baseUrl?: string;
|
|
1191
|
+
/** Where to read KOSA8_API_KEY and KOSA8_CLOUD_URL from. Defaults to process.env. */
|
|
1192
|
+
env?: Record<string, string | undefined>;
|
|
1193
|
+
/** A fetch to use instead of the global one (tests, proxies). */
|
|
1194
|
+
fetch?: typeof fetch;
|
|
1195
|
+
/** Per-request timeout. Default 120 s. */
|
|
1196
|
+
timeoutMs?: number;
|
|
1197
|
+
}
|
|
1198
|
+
interface CloudSandboxInfo {
|
|
1199
|
+
id: string;
|
|
1200
|
+
state: 'creating' | 'running' | 'sleeping' | 'stopped' | 'deleted' | 'error' | string;
|
|
1201
|
+
template: string;
|
|
1202
|
+
cpus: number;
|
|
1203
|
+
mem_mb: number;
|
|
1204
|
+
source: 'pool' | 'restore' | 'cold' | null;
|
|
1205
|
+
region: string | null;
|
|
1206
|
+
own_host: boolean;
|
|
1207
|
+
created_at: number;
|
|
1208
|
+
started_at: number | null;
|
|
1209
|
+
stopped_at: number | null;
|
|
1210
|
+
deleted_at: number | null;
|
|
1211
|
+
last_error: string | null;
|
|
1212
|
+
running_s: number;
|
|
1213
|
+
asleep_s: number;
|
|
1214
|
+
sleep_bytes: number;
|
|
1215
|
+
cost_usd: number;
|
|
1216
|
+
}
|
|
1217
|
+
interface CloudCreateOptions {
|
|
1218
|
+
/** Template key, such as base, python or node. Defaults to the org's setting. */
|
|
1219
|
+
template?: string;
|
|
1220
|
+
/** Region id, such as eu-hel1. Defaults to the org's setting (any region). */
|
|
1221
|
+
region?: string;
|
|
1222
|
+
/** Idle seconds before the sandbox sleeps; 0 never. Defaults to the org's setting. */
|
|
1223
|
+
sleepAfterS?: number;
|
|
1224
|
+
}
|
|
1225
|
+
interface CloudExecOptions {
|
|
1226
|
+
/** Image to run the command in. Defaults to the template's own image. */
|
|
1227
|
+
image?: string;
|
|
1228
|
+
/** Environment variables for the command. */
|
|
1229
|
+
env?: Record<string, string>;
|
|
1230
|
+
}
|
|
1231
|
+
interface CloudExecResult {
|
|
1232
|
+
exitCode: number | null;
|
|
1233
|
+
stdout: string;
|
|
1234
|
+
stderr: string;
|
|
1235
|
+
/** Set when the sandbox was asleep and woke for this command. */
|
|
1236
|
+
wokeMs?: number;
|
|
1237
|
+
}
|
|
1238
|
+
interface CloudInvocation {
|
|
1239
|
+
id: string;
|
|
1240
|
+
function: string;
|
|
1241
|
+
function_id: string;
|
|
1242
|
+
version: number;
|
|
1243
|
+
trigger: 'api' | 'web' | 'map' | 'cron' | string;
|
|
1244
|
+
}
|
|
1245
|
+
interface CloudInvokeResult<T = unknown> {
|
|
1246
|
+
invocation: CloudInvocation | null;
|
|
1247
|
+
/** False when the handler raised; `error` then says what. */
|
|
1248
|
+
ok: boolean;
|
|
1249
|
+
result?: T;
|
|
1250
|
+
error?: {
|
|
1251
|
+
type: string;
|
|
1252
|
+
message: string;
|
|
1253
|
+
};
|
|
1254
|
+
logs?: string;
|
|
1255
|
+
source?: 'pool' | 'restore' | null;
|
|
1256
|
+
timings_ms?: {
|
|
1257
|
+
start: number | null;
|
|
1258
|
+
run: number | null;
|
|
1259
|
+
host_total: number | null;
|
|
1260
|
+
total: number;
|
|
1261
|
+
};
|
|
1262
|
+
}
|
|
1263
|
+
interface CloudFunctionSpec {
|
|
1264
|
+
runtime: 'python3.12' | 'node22' | string;
|
|
1265
|
+
code: string;
|
|
1266
|
+
env?: Record<string, string>;
|
|
1267
|
+
timeout_s?: number;
|
|
1268
|
+
web?: 'off' | 'public' | 'key' | string;
|
|
1269
|
+
schedule?: string | null;
|
|
1270
|
+
[k: string]: unknown;
|
|
1271
|
+
}
|
|
1272
|
+
type Json = Record<string, unknown>;
|
|
1273
|
+
/** A client for the kosa8 Cloud control plane. */
|
|
1274
|
+
declare class Kosa8Cloud {
|
|
1275
|
+
readonly baseUrl: string;
|
|
1276
|
+
readonly sandboxes: CloudSandboxes;
|
|
1277
|
+
readonly functions: CloudFunctions;
|
|
1278
|
+
private readonly apiKey;
|
|
1279
|
+
private readonly fetchImpl;
|
|
1280
|
+
private readonly timeoutMs;
|
|
1281
|
+
constructor(options?: Kosa8CloudOptions);
|
|
1282
|
+
/** The org, the key in use and, for a member's key, the member. */
|
|
1283
|
+
me(): Promise<Json>;
|
|
1284
|
+
/** This month's usage, bill estimate and whether work is paused for payment. */
|
|
1285
|
+
usage(): Promise<Json>;
|
|
1286
|
+
/** @internal */
|
|
1287
|
+
request<T = Json>(method: string, path: string, body?: unknown): Promise<T>;
|
|
1288
|
+
}
|
|
1289
|
+
declare class CloudSandboxes {
|
|
1290
|
+
private readonly cloud;
|
|
1291
|
+
constructor(cloud: Kosa8Cloud);
|
|
1292
|
+
/** Start a sandbox; resolves once it is running. */
|
|
1293
|
+
create(opts?: CloudCreateOptions): Promise<CloudSandbox>;
|
|
1294
|
+
/** The org's sandboxes; with all, deleted ones too. */
|
|
1295
|
+
list(opts?: {
|
|
1296
|
+
all?: boolean;
|
|
1297
|
+
}): Promise<CloudSandbox[]>;
|
|
1298
|
+
get(id: string): Promise<CloudSandbox>;
|
|
1299
|
+
}
|
|
1300
|
+
/** One cloud sandbox. `info` is its state as of the last call. */
|
|
1301
|
+
declare class CloudSandbox {
|
|
1302
|
+
private readonly cloud;
|
|
1303
|
+
info: CloudSandboxInfo;
|
|
1304
|
+
constructor(cloud: Kosa8Cloud, info: CloudSandboxInfo);
|
|
1305
|
+
get id(): string;
|
|
1306
|
+
private path;
|
|
1307
|
+
/**
|
|
1308
|
+
* Run a command and wait for it. A string runs through `sh -c`. A
|
|
1309
|
+
* sleeping sandbox wakes for it.
|
|
1310
|
+
*/
|
|
1311
|
+
exec(cmd: string | string[], opts?: CloudExecOptions): Promise<CloudExecResult>;
|
|
1312
|
+
/** Snapshot it and free its VM; it then costs only snapshot storage. */
|
|
1313
|
+
sleep(): Promise<this>;
|
|
1314
|
+
/** Restore a sleeping sandbox, files and all. */
|
|
1315
|
+
wake(): Promise<this>;
|
|
1316
|
+
refresh(): Promise<this>;
|
|
1317
|
+
delete(): Promise<void>;
|
|
1318
|
+
}
|
|
1319
|
+
declare class CloudFunctions {
|
|
1320
|
+
private readonly cloud;
|
|
1321
|
+
constructor(cloud: Kosa8Cloud);
|
|
1322
|
+
/** Deploy (create or replace) a function; every deploy bumps its version. */
|
|
1323
|
+
deploy(name: string, spec: CloudFunctionSpec): Promise<Json>;
|
|
1324
|
+
list(): Promise<Json[]>;
|
|
1325
|
+
get(name: string): Promise<Json>;
|
|
1326
|
+
delete(name: string): Promise<void>;
|
|
1327
|
+
/** Call it once. A handler that raises resolves with ok: false, not a throw. */
|
|
1328
|
+
invoke<T = unknown>(name: string, event?: unknown): Promise<CloudInvokeResult<T>>;
|
|
1329
|
+
/** One call per event, results in input order. */
|
|
1330
|
+
map<T = unknown>(name: string, events: unknown[], opts?: {
|
|
1331
|
+
concurrency?: number;
|
|
1332
|
+
}): Promise<{
|
|
1333
|
+
function: string;
|
|
1334
|
+
version: number;
|
|
1335
|
+
count: number;
|
|
1336
|
+
succeeded: number;
|
|
1337
|
+
failed: number;
|
|
1338
|
+
total_ms: number;
|
|
1339
|
+
results: CloudInvokeResult<T>[];
|
|
1340
|
+
}>;
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
export { ACTOR_HEADER, AGENT_TOKEN_HEADER, APPROVAL_HEADER, type Actor, type ApprovalAction, type ApprovalRefusal, type ApprovalRequirement, type ApprovalRule, type BrokerHostRule, type BrokerInfo, type BrokerRoute, type BrokerSpec, type BuildTemplateOptions, CLOUD_KEY_PREFIX, type CallOptions, type CaptureSpec, type Checkpoint, CheckpointBook, type CheckpointOptions, type CheckpointResult, type CheckpointStore, type CloudCreateOptions, type CloudExecOptions, type CloudExecResult, type CloudFunctionSpec, CloudFunctions, type CloudInvocation, type CloudInvokeResult, CloudSandbox, type CloudSandboxInfo, CloudSandboxes, type CodeArtifact, type CodeResult, type Container, type CreatePreviewOptions, type CreateSandboxOptions, type CreateSandboxResult, type CreateSessionOptions, DEFAULT_CLOUD_URL, type DeleteSandboxResult, type DeleteSnapshotResult, type EgressPolicy, type EgressPolicyString, type EgressStatus, type ExecOptions, type ExecResult, type ExploreBranch, type ExploreOptions, type ExploreResult, FileCheckpointStore, type FileInfo, type ForkOptions, type ForkResult, type Frame, type GitBranch, type GitCommit, type GitCommitOptions, type GitFileStatus, type GitOp, type GitOptions, type GitResult, type GitStatus, type Health, Kosa8ApiError, Kosa8ApprovalRequiredError, Kosa8AuthError, Kosa8BadRequestError, Kosa8CheckpointError, Kosa8Client, type Kosa8ClientOptions, Kosa8Cloud, type Kosa8CloudOptions, Kosa8ConflictError, Kosa8ConnectionError, Kosa8Error, Kosa8NotFoundError, Kosa8PaymentRequiredError, Kosa8PolicyError, Kosa8RateLimitError, Kosa8StreamError, Kosa8TimeoutError, Kosa8UnsupportedError, type Lifecycle, MAX_CHECKPOINTS_PER_SANDBOX, MemoryCheckpointStore, type Mount, type Preview, type RequestOptions, type RestoreOptions, type RestoreResult, type RewindOptions, type RewindResult, type RunCodeOptions, type RunOptions, type Sandbox, SandboxHandle, type SessionExecOptions, type SessionInfo, type SetLifecycleOptions, type ShellOptions, type ShellResult, type Snapshot, type SnapshotSandboxResult, type StartPtyOptions, type StartSandboxResult, type StopSandboxResult, type Template, Transport, type TransportOptions, type WriteFileOptions, defaultSocketPath, defaultWorkerFile, errorFromResponse, resolveEndpoint, tarContext, validateSandboxName };
|