@kibotos/sdk 0.0.0-stage → 0.2.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.
@@ -0,0 +1,1025 @@
1
+ /**
2
+ * Configuration options for initializing a {@link Kibotos} client.
3
+ */
4
+ interface KibotosClientOptions {
5
+ /**
6
+ * API key (`kb_...`).
7
+ * Defaults to `process.env.KIBOTOS_API_KEY` when running in a runtime with `process.env`.
8
+ */
9
+ apiKey?: string;
10
+ /**
11
+ * Base API URL. Trailing slashes are trimmed and `/v1` is normalized automatically.
12
+ * Defaults to `process.env.KIBOTOS_API_URL ?? "https://api.kibo.to/v1"`.
13
+ */
14
+ baseUrl?: string;
15
+ /**
16
+ * Maximum number of retry attempts for retryable API errors, HTTP 429/5xx, and network errors.
17
+ * Defaults to `3`. Set to `0` to disable retries.
18
+ */
19
+ maxRetries?: number;
20
+ /**
21
+ * Default per-request timeout in milliseconds.
22
+ * Defaults to `30000` (30 seconds).
23
+ */
24
+ timeoutMs?: number;
25
+ /**
26
+ * Custom `fetch` implementation (useful for testing or custom runtimes).
27
+ * Defaults to `globalThis.fetch`.
28
+ */
29
+ fetch?: typeof globalThis.fetch;
30
+ /**
31
+ * Additional headers merged into every request.
32
+ */
33
+ defaultHeaders?: Record<string, string>;
34
+ }
35
+ /**
36
+ * Per-request options supported by all resource methods.
37
+ */
38
+ interface RequestOptions {
39
+ /**
40
+ * Explicit `Idempotency-Key` header value (1..255 characters).
41
+ * For `POST` mutations, a UUID v4 is automatically generated and reused across retries if omitted.
42
+ */
43
+ idempotencyKey?: string;
44
+ /**
45
+ * Optional `AbortSignal` to cancel the request and any retry backoff delay.
46
+ */
47
+ signal?: AbortSignal;
48
+ /**
49
+ * Per-request timeout override in milliseconds.
50
+ */
51
+ timeoutMs?: number;
52
+ /**
53
+ * Additional per-request HTTP headers.
54
+ */
55
+ headers?: Record<string, string>;
56
+ }
57
+ /**
58
+ * Standard paginated response envelope.
59
+ */
60
+ interface Page<T> {
61
+ data: T[];
62
+ next_page_token: string | null;
63
+ }
64
+ /**
65
+ * Multi-zone paginated response envelope returned by cross-zone list endpoints.
66
+ */
67
+ interface MultiZonePage<T> extends Page<T> {
68
+ unavailable_zones: string[];
69
+ }
70
+ /**
71
+ * Common pagination query parameters.
72
+ */
73
+ interface PaginationParams {
74
+ /** Maximum number of items per page (default 20, max 100). */
75
+ limit?: number;
76
+ /** Opaque pagination cursor returned in `next_page_token`. */
77
+ page_token?: string;
78
+ }
79
+ /**
80
+ * Structured failure metadata on asynchronous resources.
81
+ */
82
+ interface Failure {
83
+ code: string;
84
+ message: string;
85
+ retryable: boolean;
86
+ }
87
+ /**
88
+ * Structured error body inside the v1 API error envelope.
89
+ */
90
+ interface APIErrorBody {
91
+ code: string;
92
+ message: string;
93
+ status: number;
94
+ request_id?: string;
95
+ retryable?: boolean;
96
+ details?: Record<string, unknown>;
97
+ }
98
+ /**
99
+ * Standard v1 API error envelope.
100
+ */
101
+ interface ErrorEnvelope {
102
+ error: APIErrorBody;
103
+ }
104
+ type ZoneStatus = 'available' | 'draining';
105
+ interface Zone {
106
+ id: string;
107
+ display_name: string;
108
+ /** Optional human-readable description (up to 200 characters), or `null` when unspecified. */
109
+ description?: string | null;
110
+ region: string;
111
+ /** ISO 3166-1 alpha-2 uppercase country/region code (e.g. `"JP"`, `"US"`), or `null` when unspecified. */
112
+ country: string | null;
113
+ status: ZoneStatus;
114
+ default: boolean;
115
+ }
116
+ type ListZonesParams = PaginationParams;
117
+ type TemplateOwner = 'platform' | 'organization';
118
+ interface TemplateLatestRevision {
119
+ id: string;
120
+ status: string;
121
+ }
122
+ interface Template {
123
+ id: string;
124
+ owner: TemplateOwner;
125
+ display_name: string;
126
+ description: string;
127
+ default_revision: string;
128
+ latest_revision: TemplateLatestRevision | null;
129
+ zones: string[];
130
+ created_at: string | null;
131
+ updated_at: string | null;
132
+ }
133
+ interface TemplateRevision {
134
+ id: string;
135
+ template_id: string;
136
+ status: string;
137
+ failure: Failure | null;
138
+ source: Record<string, unknown> | null;
139
+ process: Record<string, unknown> | null;
140
+ size_mib: number | null;
141
+ zones: string[];
142
+ created_at: string | null;
143
+ ready_at: string | null;
144
+ }
145
+ interface ListTemplatesParams extends PaginationParams {
146
+ owner?: TemplateOwner;
147
+ zone?: string;
148
+ }
149
+ type ListTemplateRevisionsParams = PaginationParams;
150
+ /**
151
+ * Workspace lifecycle status. Maps 1:1 to native Kibotos WorkspaceState in lowercase.
152
+ */
153
+ type WorkspaceStatus = 'creating' | 'available' | 'stopping' | 'stopped' | 'starting' | 'deleting' | 'failed' | 'unknown';
154
+ type NetworkMode = 'public_internet' | 'deny_all';
155
+ type TimeoutAction = 'stop' | 'delete';
156
+ interface WorkspaceTemplateRef {
157
+ id: string;
158
+ revision: string;
159
+ }
160
+ interface WorkspaceTemplateInput {
161
+ id: string;
162
+ revision?: string;
163
+ }
164
+ interface WorkspaceResources {
165
+ vcpus: number;
166
+ memory_mib: number;
167
+ disk_mib: number;
168
+ }
169
+ interface WorkspaceResourcesInput {
170
+ vcpus?: number;
171
+ memory_mib?: number;
172
+ disk_mib?: number;
173
+ }
174
+ interface NetworkEgressRule {
175
+ egress_id: string;
176
+ destinations: string[];
177
+ }
178
+ type NetworkResolverPath = {
179
+ type: 'direct';
180
+ } | {
181
+ type: 'egress';
182
+ egress_id: string;
183
+ };
184
+ interface NetworkResolverRule {
185
+ resolver_id: string;
186
+ path: NetworkResolverPath;
187
+ }
188
+ interface WorkspaceNetworkInput {
189
+ mode: NetworkMode;
190
+ allow?: string[];
191
+ deny?: string[];
192
+ egresses?: NetworkEgressRule[];
193
+ resolvers?: NetworkResolverRule[];
194
+ }
195
+ interface WorkspaceNetwork extends WorkspaceNetworkInput {
196
+ /** Null while the workspace is stopped. */
197
+ applied: boolean | null;
198
+ }
199
+ interface WorkspaceVolumeAttachment {
200
+ id: string;
201
+ mount_path: string;
202
+ delete_with_workspace: boolean;
203
+ }
204
+ interface WorkspaceVolumeAttachmentInput {
205
+ id: string;
206
+ mount_path?: string;
207
+ delete_with_workspace?: boolean;
208
+ }
209
+ interface WorkspaceTimeout {
210
+ expires_at: string;
211
+ action: TimeoutAction;
212
+ }
213
+ interface WorkspaceTimeoutInput {
214
+ seconds: number;
215
+ action?: TimeoutAction;
216
+ }
217
+ interface WorkspacePack {
218
+ id: string;
219
+ revision: string;
220
+ provided_capabilities: string[];
221
+ }
222
+ interface Workspace {
223
+ id: string;
224
+ name: string | null;
225
+ zone: string;
226
+ template: WorkspaceTemplateRef;
227
+ status: WorkspaceStatus;
228
+ failure: Failure | null;
229
+ resources: WorkspaceResources;
230
+ network: WorkspaceNetwork;
231
+ volume: WorkspaceVolumeAttachment | null;
232
+ volumes?: WorkspaceVolumeAttachment[];
233
+ packs?: WorkspacePack[];
234
+ timeout: WorkspaceTimeout | null;
235
+ labels: Record<string, string>;
236
+ created_at: string;
237
+ updated_at: string;
238
+ }
239
+ interface CreateWorkspaceRequest {
240
+ name?: string;
241
+ zone?: string;
242
+ template: WorkspaceTemplateInput;
243
+ resources?: WorkspaceResourcesInput;
244
+ network?: WorkspaceNetworkInput;
245
+ volume?: WorkspaceVolumeAttachmentInput;
246
+ volumes?: WorkspaceVolumeAttachmentInput[];
247
+ packs?: string[];
248
+ timeout?: WorkspaceTimeoutInput;
249
+ /** Disable automatic expiration (serializes as `timeout: { seconds: 0 }`). Cannot be combined with `timeout`. */
250
+ noTimeout?: boolean;
251
+ labels?: Record<string, string>;
252
+ }
253
+ interface ListWorkspacesParams extends PaginationParams {
254
+ status?: WorkspaceStatus | WorkspaceStatus[];
255
+ zone?: string;
256
+ /** Label filters serialized as `label.<key>=<value>` query parameters. */
257
+ labels?: Record<string, string>;
258
+ }
259
+ interface UpdateWorkspaceRequest {
260
+ name?: string | null;
261
+ /** Set a key to `null` to delete that label. */
262
+ labels?: Record<string, string | null>;
263
+ resources?: WorkspaceResourcesInput;
264
+ }
265
+ interface StartWorkspaceRequest {
266
+ timeout?: WorkspaceTimeoutInput;
267
+ /** Disable automatic expiration on start (serializes as `timeout: { seconds: 0 }`). Cannot be combined with `timeout`. */
268
+ noTimeout?: boolean;
269
+ }
270
+ interface StopWorkspaceRequest {
271
+ force?: boolean;
272
+ }
273
+ interface SetWorkspaceTimeoutRequest {
274
+ seconds: number;
275
+ action?: TimeoutAction;
276
+ }
277
+ interface SetWorkspaceNetworkRequest extends WorkspaceNetworkInput {
278
+ drain_seconds?: number;
279
+ }
280
+ interface SetWorkspaceVolumesRequest {
281
+ volumes: WorkspaceVolumeAttachmentInput[];
282
+ }
283
+ interface SetWorkspacePacksRequest {
284
+ packs: string[];
285
+ }
286
+ interface WorkspaceMetricsParams {
287
+ start?: string | Date;
288
+ end?: string | Date;
289
+ }
290
+ interface WorkspaceGuestMetricsPoint {
291
+ time: string;
292
+ cpu_count: number;
293
+ cpu_used_percent: number;
294
+ disk_total_bytes: number;
295
+ disk_used_bytes: number;
296
+ memory_cache_bytes: number;
297
+ memory_total_bytes: number;
298
+ memory_used_bytes: number;
299
+ }
300
+ interface WorkspaceHostMetricsPoint {
301
+ time: string;
302
+ cpu_cores?: number;
303
+ cpu_pressure_some_ratio?: number;
304
+ io_pressure_full_ratio?: number;
305
+ io_pressure_some_ratio?: number;
306
+ memory_bytes?: number;
307
+ memory_pressure_full_ratio?: number;
308
+ memory_pressure_some_ratio?: number;
309
+ network_receive_bytes_per_second?: number;
310
+ network_receive_dropped_per_second?: number;
311
+ network_receive_packets_per_second?: number;
312
+ network_transmit_bytes_per_second?: number;
313
+ network_transmit_dropped_per_second?: number;
314
+ network_transmit_packets_per_second?: number;
315
+ }
316
+ interface WorkspaceMetrics {
317
+ earliest_time: string | null;
318
+ guest: WorkspaceGuestMetricsPoint[];
319
+ host: WorkspaceHostMetricsPoint[];
320
+ step_seconds: number;
321
+ }
322
+ interface AttachVolumeRequest {
323
+ id: string;
324
+ mount_path?: string;
325
+ delete_with_workspace?: boolean;
326
+ }
327
+ interface WaitWorkspaceParams {
328
+ /** One or more target statuses to wait for. */
329
+ status: WorkspaceStatus | WorkspaceStatus[];
330
+ /**
331
+ * Total wait timeout in seconds. Defaults to `30`.
332
+ * Values greater than `60` automatically loop across `<= 60s` server wait calls.
333
+ */
334
+ timeoutSeconds?: number;
335
+ }
336
+ type ExposureStatus = 'active' | 'revoked';
337
+ interface Exposure {
338
+ id: string;
339
+ workspace_id: string;
340
+ port: number;
341
+ url: string;
342
+ status: ExposureStatus;
343
+ expires_at: string;
344
+ revoked_at: string | null;
345
+ created_at: string;
346
+ }
347
+ interface CreateExposureRequest {
348
+ port: number;
349
+ ttl_seconds?: number;
350
+ }
351
+ interface ListExposuresParams extends PaginationParams {
352
+ include_revoked?: boolean;
353
+ }
354
+ /**
355
+ * Volume lifecycle status. Maps 1:1 to native Kibotos VolumeState in lowercase:
356
+ * `workspace_id` expresses workspace binding; `available` means ready and not
357
+ * mounted to a running workspace; `attached` means mounted to a running workspace;
358
+ * `lost` means the underlying storage pool was lost.
359
+ */
360
+ type VolumeStatus = 'creating' | 'available' | 'attached' | 'resizing' | 'deleting' | 'failed' | 'lost' | 'unknown';
361
+ interface Volume {
362
+ id: string;
363
+ name: string | null;
364
+ zone: string;
365
+ size_gib: number;
366
+ status: VolumeStatus;
367
+ failure: Failure | null;
368
+ workspace_id: string | null;
369
+ labels: Record<string, string>;
370
+ created_at: string;
371
+ updated_at: string;
372
+ }
373
+ interface CreateVolumeRequest {
374
+ name?: string;
375
+ zone?: string;
376
+ size_gib: number;
377
+ labels?: Record<string, string>;
378
+ }
379
+ interface ListVolumesParams extends PaginationParams {
380
+ zone?: string;
381
+ attached?: boolean;
382
+ /** Label filters serialized as `label.<key>=<value>` query parameters. */
383
+ labels?: Record<string, string>;
384
+ }
385
+ interface UpdateVolumeRequest {
386
+ name?: string | null;
387
+ /** Set a key to `null` to delete that label. */
388
+ labels?: Record<string, string | null>;
389
+ }
390
+ interface ResizeVolumeRequest {
391
+ size_gib: number;
392
+ }
393
+ interface WaitVolumeParams {
394
+ /** One or more target statuses to wait for. */
395
+ status: VolumeStatus | VolumeStatus[];
396
+ /**
397
+ * Total wait timeout in seconds. Defaults to `30`.
398
+ * Values greater than `60` automatically loop across `<= 60s` server wait calls.
399
+ */
400
+ timeoutSeconds?: number;
401
+ }
402
+ interface PackRelease {
403
+ id: string;
404
+ architecture: string;
405
+ guest_requirements: string[];
406
+ provided_capabilities: string[];
407
+ published_at: string;
408
+ version: string;
409
+ zones: string[];
410
+ }
411
+ interface Pack extends PackRelease {
412
+ default_revision: string;
413
+ description: string;
414
+ display_name: string;
415
+ }
416
+ interface PackRevision extends PackRelease {
417
+ pack_id: string;
418
+ }
419
+ interface ListPacksParams extends PaginationParams {
420
+ zone?: string;
421
+ }
422
+ interface ListEgressesParams extends ListPacksParams {
423
+ labels?: Record<string, string>;
424
+ }
425
+ type ListResolversParams = ListEgressesParams;
426
+ interface EgressTLS {
427
+ ca_cert?: string | null;
428
+ server_name?: string | null;
429
+ }
430
+ interface EgressSocks5 {
431
+ address: string;
432
+ tls?: EgressTLS | null;
433
+ username?: string | null;
434
+ }
435
+ interface EgressSocks5Input extends EgressSocks5 {
436
+ /** Write-only. Supply again when replacing the configuration. */
437
+ password?: string | null;
438
+ }
439
+ interface ZonedNetworkResource {
440
+ id: string;
441
+ name: string | null;
442
+ zone: string;
443
+ labels: Record<string, string>;
444
+ revision: number;
445
+ created_at: string;
446
+ updated_at: string;
447
+ }
448
+ interface CreateNetworkResourceRequest {
449
+ name?: string;
450
+ zone?: string;
451
+ labels?: Record<string, string>;
452
+ }
453
+ interface Egress extends ZonedNetworkResource {
454
+ protocol: 'socks5';
455
+ socks5: EgressSocks5;
456
+ udp_enabled: boolean;
457
+ }
458
+ interface CreateEgressRequest extends CreateNetworkResourceRequest {
459
+ protocol: 'socks5';
460
+ socks5: EgressSocks5Input;
461
+ udp_enabled?: boolean;
462
+ }
463
+ interface ReplaceEgressRequest {
464
+ protocol: 'socks5';
465
+ socks5: EgressSocks5Input;
466
+ udp_enabled?: boolean;
467
+ drain_seconds?: number;
468
+ }
469
+ interface UpdateEgressRequest {
470
+ name?: string | null;
471
+ labels?: Record<string, string | null>;
472
+ }
473
+ interface ResolverAddress {
474
+ address: string;
475
+ }
476
+ interface ResolverHTTPS {
477
+ url: string;
478
+ }
479
+ interface ResolverConfig {
480
+ protocol: 'udp' | 'tcp' | 'tls' | 'https';
481
+ udp?: ResolverAddress;
482
+ tcp?: ResolverAddress;
483
+ tls?: ResolverAddress;
484
+ https?: ResolverHTTPS;
485
+ }
486
+ interface Resolver extends ZonedNetworkResource, ResolverConfig {
487
+ }
488
+ interface CreateResolverRequest extends CreateNetworkResourceRequest, ResolverConfig {
489
+ }
490
+ type ReplaceResolverRequest = ResolverConfig;
491
+ type UpdateResolverRequest = UpdateEgressRequest;
492
+ interface ExecRequest {
493
+ argv: string[];
494
+ env?: Record<string, string>;
495
+ max_output_bytes?: number;
496
+ stdin?: string | null;
497
+ timeout_seconds?: number;
498
+ user?: string | null;
499
+ working_dir?: string | null;
500
+ }
501
+ interface ExecResponse {
502
+ duration_ms: number;
503
+ exit_code: number | null;
504
+ signal: number | null;
505
+ stdout: string;
506
+ stderr: string;
507
+ termination_reason: 'exited' | 'signaled' | 'timed_out' | 'canceled' | 'failed' | 'memory_saturated' | 'out_of_memory';
508
+ truncated: boolean;
509
+ }
510
+ interface ExecEvent {
511
+ event: 'started' | 'stdout' | 'stderr' | 'heartbeat' | 'exited' | 'error';
512
+ /** The decoded JSON payload, or the original text when the payload is not JSON. */
513
+ data: unknown;
514
+ }
515
+ interface FileEntry {
516
+ path: string;
517
+ name: string;
518
+ type: string;
519
+ mode: string;
520
+ modified_at: string | null;
521
+ size_bytes: number;
522
+ }
523
+ interface FileList {
524
+ path: string;
525
+ entries: FileEntry[];
526
+ }
527
+ interface FileWriteResult {
528
+ path: string;
529
+ size_bytes: number;
530
+ sha256: string;
531
+ }
532
+ interface FileOptions extends RequestOptions {
533
+ user?: string;
534
+ }
535
+ interface ListFilesOptions extends FileOptions {
536
+ depth?: number;
537
+ }
538
+ interface ReadFileOptions extends FileOptions {
539
+ range?: string;
540
+ ifNoneMatch?: string;
541
+ as?: 'response' | 'bytes' | 'stream';
542
+ }
543
+ interface WriteFileOptions extends FileOptions {
544
+ mode?: string;
545
+ createOnly?: boolean;
546
+ }
547
+ type FileContent = Uint8Array | ReadableStream<Uint8Array> | string | Blob;
548
+ interface MakeDirectoryRequest {
549
+ path: string;
550
+ mode?: string;
551
+ user?: string | null;
552
+ }
553
+ interface MoveFileRequest {
554
+ source: string;
555
+ destination: string;
556
+ user?: string | null;
557
+ }
558
+
559
+ declare const DEFAULT_BASE_URL = "https://api.kibo.to/v1";
560
+ declare const DEFAULT_MAX_RETRIES = 3;
561
+ declare const DEFAULT_TIMEOUT_MS = 30000;
562
+ declare const SDK_VERSION = "0.2.0";
563
+ type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
564
+ interface InternalRequestConfig {
565
+ method: HttpMethod;
566
+ path: string;
567
+ query?: URLSearchParams;
568
+ body?: unknown;
569
+ rawBody?: BodyInit;
570
+ duplex?: 'half';
571
+ accept?: string;
572
+ successStatuses?: readonly number[];
573
+ nonReplayable?: boolean;
574
+ disableIdempotency?: boolean;
575
+ opts?: RequestOptions;
576
+ /**
577
+ * When true, HTTP 408 `wait_timeout` responses are NOT retried by the low-level transport
578
+ * so that higher-level `wait()` chunk looping controls the timeout budget directly.
579
+ */
580
+ disableWaitTimeoutRetry?: boolean;
581
+ }
582
+ /**
583
+ * Internal fetch-based HTTP transport powering all resource namespaces.
584
+ */
585
+ declare class HttpClient {
586
+ readonly baseUrl: string;
587
+ readonly maxRetries: number;
588
+ readonly timeoutMs: number;
589
+ private readonly apiKey;
590
+ private readonly fetchImpl;
591
+ private readonly defaultHeaders;
592
+ constructor(options?: KibotosClientOptions);
593
+ buildUrl(path: string, query?: URLSearchParams): string;
594
+ buildHeaders(overrides?: Record<string, string>): Headers;
595
+ request<T>(config: InternalRequestConfig): Promise<T>;
596
+ requestResponse(config: InternalRequestConfig): Promise<Response>;
597
+ private perform;
598
+ private shouldRetryAPIError;
599
+ }
600
+
601
+ declare class ExposuresResource {
602
+ private readonly http;
603
+ constructor(http: HttpClient);
604
+ /**
605
+ * Creates a public HTTPS exposure for a workspace port (`201 Created`).
606
+ * `POST /v1/workspaces/{id}/exposures`
607
+ */
608
+ create(workspaceId: string, body: CreateExposureRequest, opts?: RequestOptions): Promise<Exposure>;
609
+ /**
610
+ * Lists exposures for a workspace.
611
+ * `GET /v1/workspaces/{id}/exposures`
612
+ */
613
+ list(workspaceId: string, params?: ListExposuresParams, opts?: RequestOptions): Promise<Page<Exposure>>;
614
+ /**
615
+ * Auto-paginates across all exposures for a workspace.
616
+ */
617
+ iterate(workspaceId: string, params?: ListExposuresParams, opts?: RequestOptions): AsyncIterable<Exposure>;
618
+ /**
619
+ * Retrieves a specific exposure by ID.
620
+ * `GET /v1/workspaces/{id}/exposures/{exposure_id}`
621
+ */
622
+ get(workspaceId: string, exposureId: string, opts?: RequestOptions): Promise<Exposure>;
623
+ /**
624
+ * Revokes an active exposure.
625
+ * `DELETE /v1/workspaces/{id}/exposures/{exposure_id}`
626
+ */
627
+ revoke(workspaceId: string, exposureId: string, opts?: RequestOptions): Promise<Exposure>;
628
+ }
629
+
630
+ declare class TemplatesResource {
631
+ private readonly http;
632
+ constructor(http: HttpClient);
633
+ /**
634
+ * Lists templates across zones.
635
+ * `GET /v1/templates`
636
+ */
637
+ list(params?: ListTemplatesParams, opts?: RequestOptions): Promise<MultiZonePage<Template>>;
638
+ /**
639
+ * Auto-paginates across all templates matching `params`.
640
+ */
641
+ iterate(params?: ListTemplatesParams, opts?: RequestOptions): AsyncIterable<Template>;
642
+ /**
643
+ * Retrieves a template by ID.
644
+ * `GET /v1/templates/{id}`
645
+ */
646
+ get(id: string, opts?: RequestOptions): Promise<Template>;
647
+ /**
648
+ * Lists revisions for a template.
649
+ * `GET /v1/templates/{id}/revisions`
650
+ */
651
+ listRevisions(id: string, params?: ListTemplateRevisionsParams, opts?: RequestOptions): Promise<Page<TemplateRevision>>;
652
+ /**
653
+ * Retrieves a specific template revision.
654
+ * `GET /v1/templates/{id}/revisions/{revision_id}`
655
+ */
656
+ getRevision(id: string, revisionId: string, opts?: RequestOptions): Promise<TemplateRevision>;
657
+ }
658
+
659
+ declare class VolumesResource {
660
+ private readonly http;
661
+ constructor(http: HttpClient);
662
+ /**
663
+ * Creates a new persistent volume asynchronously (`202 Accepted`).
664
+ * `POST /v1/volumes`
665
+ */
666
+ create(body: CreateVolumeRequest, opts?: RequestOptions): Promise<Volume>;
667
+ /**
668
+ * Lists volumes across zones.
669
+ * `GET /v1/volumes`
670
+ */
671
+ list(params?: ListVolumesParams, opts?: RequestOptions): Promise<MultiZonePage<Volume>>;
672
+ /**
673
+ * Auto-paginates across all volumes matching `params`.
674
+ */
675
+ iterate(params?: ListVolumesParams, opts?: RequestOptions): AsyncIterable<Volume>;
676
+ /**
677
+ * Retrieves a volume by ID.
678
+ * `GET /v1/volumes/{id}`
679
+ */
680
+ get(id: string, opts?: RequestOptions): Promise<Volume>;
681
+ /**
682
+ * Updates volume metadata (`name` and/or `labels`).
683
+ * `PATCH /v1/volumes/{id}`
684
+ */
685
+ update(id: string, body: UpdateVolumeRequest, opts?: RequestOptions): Promise<Volume>;
686
+ /**
687
+ * Resizes a volume asynchronously (`202 Accepted`).
688
+ * `POST /v1/volumes/{id}/resize`
689
+ */
690
+ resize(id: string, body: ResizeVolumeRequest, opts?: RequestOptions): Promise<Volume>;
691
+ /**
692
+ * Deletes a volume asynchronously (`202 Accepted`).
693
+ * `DELETE /v1/volumes/{id}`
694
+ */
695
+ delete(id: string, opts?: RequestOptions): Promise<Volume>;
696
+ /**
697
+ * Waits until the volume reaches one of the target statuses.
698
+ * Automatically chunks calls into `<= 60s` windows when `timeoutSeconds > 60`.
699
+ * `GET /v1/volumes/{id}/wait`
700
+ */
701
+ wait(id: string, params: WaitVolumeParams, opts?: RequestOptions): Promise<Volume>;
702
+ }
703
+
704
+ declare const WorkspaceChannel: {
705
+ readonly stdin: 0;
706
+ readonly stdout: 1;
707
+ readonly stderr: 2;
708
+ readonly pty: 3;
709
+ readonly tunnel: 4;
710
+ };
711
+ type WorkspaceChannel = (typeof WorkspaceChannel)[keyof typeof WorkspaceChannel];
712
+ interface WorkspaceBinaryFrame {
713
+ stream_id: number;
714
+ channel: WorkspaceChannel;
715
+ payload: Uint8Array;
716
+ }
717
+ declare function encodeBinaryFrame(streamId: number, channel: WorkspaceChannel, payload: Uint8Array): Uint8Array<ArrayBuffer>;
718
+ declare function decodeBinaryFrame(input: ArrayBuffer | ArrayBufferView): WorkspaceBinaryFrame;
719
+ type WorkspaceStreamKind = 'process' | 'fs.watch' | 'tunnel';
720
+ type WorkspaceControlType = 'open' | 'opened' | 'resize' | 'signal' | 'close_stdin' | 'close' | 'exited' | 'fs.event' | 'heartbeat' | 'closed' | 'error' | 'ping' | 'pong';
721
+ interface WorkspaceControlFrame {
722
+ type: WorkspaceControlType;
723
+ stream_id?: number;
724
+ kind?: WorkspaceStreamKind;
725
+ [key: string]: unknown;
726
+ }
727
+ type WorkspaceFrame = {
728
+ type: 'control';
729
+ frame: WorkspaceControlFrame;
730
+ } | {
731
+ type: 'binary';
732
+ frame: WorkspaceBinaryFrame;
733
+ };
734
+ declare function decodeWorkspaceFrame(data: string | ArrayBuffer | ArrayBufferView): WorkspaceFrame;
735
+ type TunnelTarget = {
736
+ port: number;
737
+ family?: 'ipv4' | 'ipv6';
738
+ unix_path?: never;
739
+ } | {
740
+ unix_path: string;
741
+ port?: never;
742
+ family?: never;
743
+ };
744
+ interface WebSocketConnectOptions {
745
+ protocols?: string | string[];
746
+ headers?: Record<string, string>;
747
+ /** Factory for runtimes whose global WebSocket cannot set handshake headers. */
748
+ factory?: (url: string, options: WebSocketHandshake) => WebSocket;
749
+ }
750
+ interface WebSocketHandshake {
751
+ protocols?: string | string[];
752
+ headers: Record<string, string>;
753
+ }
754
+ declare class WorkspaceSocket {
755
+ readonly socket: WebSocket;
756
+ constructor(socket: WebSocket);
757
+ /** Subscribe to decoded frames. Returns an unsubscribe function. */
758
+ onFrame(listener: (frame: WorkspaceFrame) => void): () => void;
759
+ sendControl(frame: WorkspaceControlFrame): void;
760
+ open(streamId: number, kind: WorkspaceStreamKind, params?: Record<string, unknown>): void;
761
+ sendBinary(streamId: number, channel: WorkspaceChannel, payload: Uint8Array): void;
762
+ close(code?: number, reason?: string): void;
763
+ }
764
+
765
+ declare class WorkspacesResource {
766
+ private readonly http;
767
+ constructor(http: HttpClient);
768
+ /**
769
+ * Creates a new workspace asynchronously (`202 Accepted`).
770
+ * `POST /v1/workspaces`
771
+ */
772
+ create(body: CreateWorkspaceRequest, opts?: RequestOptions): Promise<Workspace>;
773
+ /**
774
+ * Lists workspaces across zones.
775
+ * `GET /v1/workspaces`
776
+ */
777
+ list(params?: ListWorkspacesParams, opts?: RequestOptions): Promise<MultiZonePage<Workspace>>;
778
+ /**
779
+ * Auto-paginates across all workspaces matching `params`.
780
+ */
781
+ iterate(params?: ListWorkspacesParams, opts?: RequestOptions): AsyncIterable<Workspace>;
782
+ /**
783
+ * Retrieves a workspace by ID.
784
+ * `GET /v1/workspaces/{id}`
785
+ */
786
+ get(id: string, opts?: RequestOptions): Promise<Workspace>;
787
+ /**
788
+ * Updates workspace metadata and resizes eligible stopped or failed workspaces.
789
+ * `PATCH /v1/workspaces/{id}`
790
+ */
791
+ update(id: string, body: UpdateWorkspaceRequest, opts?: RequestOptions): Promise<Workspace>;
792
+ /**
793
+ * Deletes a workspace asynchronously (`202 Accepted`).
794
+ * `DELETE /v1/workspaces/{id}`
795
+ */
796
+ delete(id: string, opts?: RequestOptions): Promise<Workspace>;
797
+ /**
798
+ * Starts a stopped workspace (`202 Accepted`).
799
+ * `POST /v1/workspaces/{id}/start`
800
+ */
801
+ start(id: string, body?: StartWorkspaceRequest, opts?: RequestOptions): Promise<Workspace>;
802
+ /**
803
+ * Stops an available workspace (`202 Accepted`).
804
+ * `POST /v1/workspaces/{id}/stop`
805
+ */
806
+ stop(id: string, body?: StopWorkspaceRequest, opts?: RequestOptions): Promise<Workspace>;
807
+ /**
808
+ * Updates the auto-timeout policy for a workspace.
809
+ * `POST /v1/workspaces/{id}/timeout`
810
+ */
811
+ setTimeout(id: string, body: SetWorkspaceTimeoutRequest, opts?: RequestOptions): Promise<Workspace>;
812
+ /**
813
+ * Removes the auto-timeout policy so the workspace does not expire automatically.
814
+ * `POST /v1/workspaces/{id}/timeout` with `{ seconds: 0 }`.
815
+ */
816
+ clearTimeout(id: string, opts?: RequestOptions): Promise<Workspace>;
817
+ /**
818
+ * Replaces the outbound network policy for a workspace.
819
+ * `PUT /v1/workspaces/{id}/network`
820
+ */
821
+ setNetwork(id: string, body: SetWorkspaceNetworkRequest, opts?: RequestOptions): Promise<Workspace>;
822
+ setVolumes(id: string, body: SetWorkspaceVolumesRequest, opts?: RequestOptions): Promise<Workspace>;
823
+ setPacks(id: string, body: SetWorkspacePacksRequest, opts?: RequestOptions): Promise<Workspace>;
824
+ getMetrics(id: string, params?: WorkspaceMetricsParams, opts?: RequestOptions): Promise<WorkspaceMetrics>;
825
+ exec(id: string, body: ExecRequest, opts?: RequestOptions): Promise<ExecResponse>;
826
+ execStream(id: string, body: ExecRequest, opts?: RequestOptions): AsyncGenerator<ExecEvent>;
827
+ listFiles(id: string, path: string, opts?: ListFilesOptions): Promise<FileList>;
828
+ statFile(id: string, path: string, opts?: FileOptions): Promise<FileEntry>;
829
+ readFile(id: string, path: string, opts?: ReadFileOptions & {
830
+ as?: 'response';
831
+ }): Promise<Response>;
832
+ readFile(id: string, path: string, opts: ReadFileOptions & {
833
+ as: 'bytes';
834
+ }): Promise<Uint8Array>;
835
+ readFile(id: string, path: string, opts: ReadFileOptions & {
836
+ as: 'stream';
837
+ }): Promise<ReadableStream<Uint8Array> | null>;
838
+ readFile(id: string, path: string, opts: ReadFileOptions): Promise<Response | Uint8Array | ReadableStream<Uint8Array> | null>;
839
+ writeFile(id: string, path: string, content: FileContent, opts?: WriteFileOptions): Promise<FileWriteResult>;
840
+ makeDir(id: string, body: MakeDirectoryRequest, opts?: RequestOptions): Promise<FileEntry>;
841
+ moveFile(id: string, body: MoveFileRequest, opts?: RequestOptions): Promise<FileEntry>;
842
+ deleteFile(id: string, path: string, opts?: FileOptions): Promise<void>;
843
+ wsUrl(id: string): string;
844
+ tunnelWSUrl(id: string, target: TunnelTarget): string;
845
+ desktopVNCUrl(id: string): string;
846
+ proxyUrl(id: string, port: number, path?: string, query?: URLSearchParams): string;
847
+ proxyWSUrl(id: string, port: number, path?: string, query?: URLSearchParams): string;
848
+ /** Headers for a WebSocket upgrade or an authenticated proxy request. */
849
+ wsHeaders(overrides?: Record<string, string>): Headers;
850
+ connectWS(id: string, opts?: WebSocketConnectOptions): WorkspaceSocket;
851
+ connectTunnel(id: string, target: TunnelTarget, opts?: WebSocketConnectOptions): WebSocket;
852
+ connectDesktop(id: string, opts?: WebSocketConnectOptions): WebSocket;
853
+ connectProxy(id: string, port: number, opts?: WebSocketConnectOptions & {
854
+ path?: string;
855
+ query?: URLSearchParams;
856
+ }): WebSocket;
857
+ /**
858
+ * Attaches a volume to a workspace.
859
+ * `PUT /v1/workspaces/{id}/volume`
860
+ */
861
+ attachVolume(id: string, body: AttachVolumeRequest, opts?: RequestOptions): Promise<Workspace>;
862
+ /**
863
+ * Detaches the attached volume from a workspace.
864
+ * `DELETE /v1/workspaces/{id}/volume`
865
+ */
866
+ detachVolume(id: string, opts?: RequestOptions): Promise<Workspace>;
867
+ /**
868
+ * Waits until the workspace reaches one of the target statuses.
869
+ * Automatically chunks calls into `<= 60s` windows when `timeoutSeconds > 60`.
870
+ * `GET /v1/workspaces/{id}/wait`
871
+ */
872
+ wait(id: string, params: WaitWorkspaceParams, opts?: RequestOptions): Promise<Workspace>;
873
+ }
874
+
875
+ declare class ZonesResource {
876
+ private readonly http;
877
+ constructor(http: HttpClient);
878
+ /**
879
+ * Lists zones available to the authenticated organization.
880
+ * `GET /v1/zones`
881
+ */
882
+ list(params?: ListZonesParams, opts?: RequestOptions): Promise<Page<Zone>>;
883
+ /**
884
+ * Auto-paginates across all zones matching `params`.
885
+ */
886
+ iterate(params?: ListZonesParams, opts?: RequestOptions): AsyncIterable<Zone>;
887
+ }
888
+
889
+ declare class EgressesResource {
890
+ private readonly http;
891
+ constructor(http: HttpClient);
892
+ create(body: CreateEgressRequest, opts?: RequestOptions): Promise<Egress>;
893
+ list(params?: ListEgressesParams, opts?: RequestOptions): Promise<MultiZonePage<Egress>>;
894
+ get(id: string, opts?: RequestOptions): Promise<Egress>;
895
+ replace(id: string, body: ReplaceEgressRequest, opts?: RequestOptions): Promise<Egress>;
896
+ update(id: string, body: UpdateEgressRequest, opts?: RequestOptions): Promise<Egress>;
897
+ delete(id: string, opts?: RequestOptions): Promise<void>;
898
+ }
899
+
900
+ declare class PacksResource {
901
+ private readonly http;
902
+ constructor(http: HttpClient);
903
+ list(params?: ListPacksParams, opts?: RequestOptions): Promise<MultiZonePage<Pack>>;
904
+ get(id: string, opts?: RequestOptions): Promise<Pack>;
905
+ getRevision(id: string, revisionId: string, opts?: RequestOptions): Promise<PackRevision>;
906
+ }
907
+
908
+ declare class ResolversResource {
909
+ private readonly http;
910
+ constructor(http: HttpClient);
911
+ create(body: CreateResolverRequest, opts?: RequestOptions): Promise<Resolver>;
912
+ list(params?: ListResolversParams, opts?: RequestOptions): Promise<MultiZonePage<Resolver>>;
913
+ get(id: string, opts?: RequestOptions): Promise<Resolver>;
914
+ replace(id: string, body: ReplaceResolverRequest, opts?: RequestOptions): Promise<Resolver>;
915
+ update(id: string, body: UpdateResolverRequest, opts?: RequestOptions): Promise<Resolver>;
916
+ delete(id: string, opts?: RequestOptions): Promise<void>;
917
+ }
918
+
919
+ /**
920
+ * Official Kibotos v1 API client.
921
+ *
922
+ * @example
923
+ * ```ts
924
+ * import { Kibotos } from '@kibotos/sdk';
925
+ *
926
+ * const client = new Kibotos();
927
+ * const ws = await client.workspaces.create({ template: { id: 'python-3.12' } });
928
+ * await client.workspaces.wait(ws.id, { status: ['available', 'failed'] });
929
+ * ```
930
+ */
931
+ declare class Kibotos {
932
+ readonly zones: ZonesResource;
933
+ readonly templates: TemplatesResource;
934
+ readonly workspaces: WorkspacesResource;
935
+ readonly volumes: VolumesResource;
936
+ readonly exposures: ExposuresResource;
937
+ readonly egresses: EgressesResource;
938
+ readonly packs: PacksResource;
939
+ readonly resolvers: ResolversResource;
940
+ private readonly http;
941
+ constructor(options?: KibotosClientOptions);
942
+ /** Normalized base URL (always ending in `/v1`). */
943
+ get baseUrl(): string;
944
+ }
945
+
946
+ interface KibotosAPIErrorInit {
947
+ status: number;
948
+ code: string;
949
+ message: string;
950
+ requestId?: string;
951
+ retryable: boolean;
952
+ details?: Record<string, unknown>;
953
+ headers?: Headers;
954
+ cause?: unknown;
955
+ }
956
+ /**
957
+ * Base error class for all errors thrown by `@kibotos/sdk`.
958
+ */
959
+ declare class KibotosError extends Error {
960
+ constructor(message: string, options?: {
961
+ cause?: unknown;
962
+ });
963
+ }
964
+ /**
965
+ * Thrown when a request fails to reach the Kibotos API due to network errors or timeouts.
966
+ */
967
+ declare class APIConnectionError extends KibotosError {
968
+ constructor(message?: string, options?: {
969
+ cause?: unknown;
970
+ });
971
+ }
972
+ /**
973
+ * Thrown when the Kibotos API returns a non-2xx HTTP response.
974
+ */
975
+ declare class KibotosAPIError extends KibotosError {
976
+ readonly status: number;
977
+ readonly code: string;
978
+ readonly requestId: string | undefined;
979
+ readonly retryable: boolean;
980
+ readonly details: Record<string, unknown> | undefined;
981
+ readonly headers: Headers | undefined;
982
+ constructor(init: KibotosAPIErrorInit);
983
+ }
984
+ /**
985
+ * Thrown on HTTP 401 responses (e.g. `unauthenticated`).
986
+ */
987
+ declare class AuthenticationError extends KibotosAPIError {
988
+ }
989
+ /**
990
+ * Thrown on HTTP 403 responses (e.g. `permission_denied`, `zone_not_permitted`, `quota_exceeded`).
991
+ */
992
+ declare class PermissionDeniedError extends KibotosAPIError {
993
+ }
994
+ /**
995
+ * Thrown on HTTP 404 responses (e.g. `workspace_not_found`, `volume_not_found`).
996
+ */
997
+ declare class NotFoundError extends KibotosAPIError {
998
+ }
999
+ /**
1000
+ * Thrown on HTTP 408 responses (e.g. `wait_timeout`).
1001
+ */
1002
+ declare class WaitTimeoutError extends KibotosAPIError {
1003
+ }
1004
+ /**
1005
+ * Thrown on HTTP 409 responses (e.g. `invalid_state`, `operation_in_progress`, `volume_attached`).
1006
+ */
1007
+ declare class ConflictError extends KibotosAPIError {
1008
+ }
1009
+ /**
1010
+ * Thrown on HTTP 409 responses with error code `unexpected_status` during `wait()` calls.
1011
+ */
1012
+ declare class UnexpectedStatusError extends ConflictError {
1013
+ }
1014
+ /**
1015
+ * Thrown on HTTP 429 responses (`rate_limited`).
1016
+ */
1017
+ declare class RateLimitError extends KibotosAPIError {
1018
+ /** Parsed `Retry-After` delay in milliseconds, if provided by the server. */
1019
+ readonly retryAfterMs: number | undefined;
1020
+ constructor(init: KibotosAPIErrorInit & {
1021
+ retryAfterMs?: number;
1022
+ });
1023
+ }
1024
+
1025
+ export { APIConnectionError, type APIErrorBody, type AttachVolumeRequest, AuthenticationError, ConflictError, type CreateEgressRequest, type CreateExposureRequest, type CreateResolverRequest, type CreateVolumeRequest, type CreateWorkspaceRequest, DEFAULT_BASE_URL, DEFAULT_MAX_RETRIES, DEFAULT_TIMEOUT_MS, type Egress, type EgressSocks5, type EgressSocks5Input, type EgressTLS, EgressesResource, type ErrorEnvelope, type ExecEvent, type ExecRequest, type ExecResponse, type Exposure, type ExposureStatus, ExposuresResource, type Failure, type FileContent, type FileEntry, type FileList, type FileOptions, type FileWriteResult, Kibotos, KibotosAPIError, type KibotosAPIErrorInit, type KibotosClientOptions, KibotosError, type ListEgressesParams, type ListExposuresParams, type ListFilesOptions, type ListPacksParams, type ListResolversParams, type ListTemplateRevisionsParams, type ListTemplatesParams, type ListVolumesParams, type ListWorkspacesParams, type ListZonesParams, type MakeDirectoryRequest, type MoveFileRequest, type MultiZonePage, type NetworkEgressRule, type NetworkMode, type NetworkResolverPath, type NetworkResolverRule, NotFoundError, type Pack, type PackRevision, PacksResource, type Page, type PaginationParams, PermissionDeniedError, RateLimitError, type ReadFileOptions, type ReplaceEgressRequest, type ReplaceResolverRequest, type RequestOptions, type ResizeVolumeRequest, type Resolver, type ResolverAddress, type ResolverHTTPS, ResolversResource, SDK_VERSION, type SetWorkspaceNetworkRequest, type SetWorkspacePacksRequest, type SetWorkspaceTimeoutRequest, type SetWorkspaceVolumesRequest, type StartWorkspaceRequest, type StopWorkspaceRequest, type Template, type TemplateLatestRevision, type TemplateOwner, type TemplateRevision, TemplatesResource, type TimeoutAction, type TunnelTarget, UnexpectedStatusError, type UpdateEgressRequest, type UpdateResolverRequest, type UpdateVolumeRequest, type UpdateWorkspaceRequest, type Volume, type VolumeStatus, VolumesResource, WaitTimeoutError, type WaitVolumeParams, type WaitWorkspaceParams, type WebSocketConnectOptions, type WebSocketHandshake, type Workspace, type WorkspaceBinaryFrame, WorkspaceChannel, type WorkspaceControlFrame, type WorkspaceControlType, type WorkspaceFrame, type WorkspaceGuestMetricsPoint, type WorkspaceHostMetricsPoint, type WorkspaceMetrics, type WorkspaceMetricsParams, type WorkspaceNetwork, type WorkspaceNetworkInput, type WorkspacePack, type WorkspaceResources, type WorkspaceResourcesInput, WorkspaceSocket, type WorkspaceStatus, type WorkspaceStreamKind, type WorkspaceTemplateInput, type WorkspaceTemplateRef, type WorkspaceTimeout, type WorkspaceTimeoutInput, type WorkspaceVolumeAttachment, type WorkspaceVolumeAttachmentInput, WorkspacesResource, type WriteFileOptions, type Zone, type ZoneStatus, ZonesResource, decodeBinaryFrame, decodeWorkspaceFrame, encodeBinaryFrame };