Skip to content

Commit f5bf2bf

Browse files
committed
cp dines
1 parent 1676b0a commit f5bf2bf

7 files changed

Lines changed: 286 additions & 255 deletions

File tree

README.md

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ await devbox.shutdown();
5151

5252
## Core Concepts
5353

54-
### RunloopSDK
54+
### [RunloopSDK](https://runloopai.github.io/api-client-ts/stable/classes/RunloopSDK.html)
5555

5656
The main SDK class that provides access to all Runloop functionality:
5757

@@ -68,26 +68,11 @@ const sdk = new RunloopSDK({
6868

6969
The SDK provides object-oriented interfaces for all major Runloop resources:
7070

71-
- **`sdk.devbox`** - Devbox management (create, list, execute commands, file operations)
72-
- **`sdk.blueprint`** - Blueprint management (create, list, build blueprints)
73-
- **`sdk.snapshot`** - Snapshot management (list disk snapshots)
74-
- **`sdk.storageObject`** - Storage object management (upload, download, list objects)
75-
- **`sdk.api`** - Direct access to the legacy REST API client
76-
77-
78-
79-
80-
81-
82-
83-
84-
85-
86-
87-
88-
89-
90-
71+
- **[`sdk.devbox`](https://runloopai.github.io/api-client-ts/stable/classes/RunloopSDK.Devbox.html)** - Devbox management (create, list, execute commands, file operations)
72+
- **[`sdk.blueprint`](https://runloopai.github.io/api-client-ts/stable/classes/RunloopSDK.Blueprint.html)** - Blueprint management (create, list, build blueprints)
73+
- **[`sdk.snapshot`](https://runloopai.github.io/api-client-ts/stable/classes/RunloopSDK.Snapshot.html)** - Snapshot management (list disk snapshots)
74+
- **[`sdk.storageObject`](https://runloopai.github.io/api-client-ts/stable/classes/RunloopSDK.StorageObject.html)** - Storage object management (upload, download, list objects)
75+
- **[`sdk.api`](https://runloopai.github.io/api-client-ts/stable/classes/Runloop.html)** - Direct access to the legacy REST API client
9176

9277
## Installation
9378

src/sdk/blueprint.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,43 @@ import { Devbox } from './devbox';
1111

1212
/**
1313
* Object-oriented interface for working with Blueprints.
14+
*
15+
* ## Overview
16+
*
17+
* The `Blueprint` class provides a high-level, object-oriented API for managing blueprints.
18+
* Blueprints are ways to create customized starting points for Devboxes.
19+
* They allow you to define custom starting points for Devboxes such that environment set up can be cached to improve Devbox boot times.
20+
*
21+
* ## Quickstart
22+
*
23+
* ### Basic Creation
24+
* ```typescript
25+
* import { RunloopSDK } from '@runloop/api-client-ts';
26+
*
27+
* const runloop = new RunloopSDK();
28+
* const blueprint = await runloop.blueprint.create({
29+
* name: 'my-blueprint',
30+
* dockerfile: 'FROM ubuntu:22.04
31+
* RUN apt-get update',
32+
* });
33+
* console.log(`Created blueprint: ${blueprint.id}`);
34+
*
35+
* // Create a devbox from the blueprint
36+
* const devbox = await blueprint.createDevbox({ name: 'my-devbox' });
1437
* ```
38+
*
1539
*/
1640
export class Blueprint {
1741
private client: Runloop;
1842
private _id: string;
1943

44+
/**
45+
* Creates a new Blueprint instance.
46+
*
47+
* @private
48+
* @param {Runloop} client - The Runloop client instance
49+
* @param {string} id - The blueprint ID
50+
*/
2051
private constructor(client: Runloop, id: string) {
2152
this.client = client;
2253
this._id = id;

src/sdk/devbox.ts

Lines changed: 151 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ export class DevboxNetOps {
5151

5252
/**
5353
* Create an SSH key for remote access to the devbox.
54+
*
55+
* @example
56+
* ```typescript
57+
* const sshKey = await devbox.net.createSSHKey();
58+
* ```
59+
*
5460
* @param {Core.RequestOptions} [options] - Request options
5561
* @returns {Promise<unknown>} SSH key creation result
5662
*/
@@ -60,6 +66,12 @@ export class DevboxNetOps {
6066

6167
/**
6268
* Create a tunnel to a port on the devbox.
69+
*
70+
* @example
71+
* ```typescript
72+
* const tunnel = await devbox.net.createTunnel({ port: 8080 });
73+
* ```
74+
*
6375
* @param {DevboxCreateTunnelParams} params - Tunnel creation parameters
6476
* @param {Core.RequestOptions} [options] - Request options
6577
* @returns {Promise<unknown>} Tunnel creation result
@@ -70,6 +82,12 @@ export class DevboxNetOps {
7082

7183
/**
7284
* Remove a tunnel from the devbox.
85+
*
86+
* @example
87+
* ```typescript
88+
* await devbox.net.removeTunnel({ port: 8080 });
89+
* ```
90+
*
7391
* @param {DevboxRemoveTunnelParams} params - Tunnel removal parameters
7492
* @param {Core.RequestOptions} [options] - Request options
7593
* @returns {Promise<unknown>} Tunnel removal result
@@ -258,6 +276,13 @@ export class DevboxFileOps {
258276
/**
259277
* Download file contents (supports binary files).
260278
*
279+
* @example
280+
* ```typescript
281+
* const response = await devbox.file.download({ path: '/app/data.bin' });
282+
* const blob = await response.blob();
283+
* // Process binary data...
284+
* ```
285+
*
261286
* @param {DevboxDownloadFileParams} params - Parameters containing the file path
262287
* @param {Core.RequestOptions} [options] - Request options
263288
* @returns {Promise<Response>} Response with file contents
@@ -269,6 +294,15 @@ export class DevboxFileOps {
269294
/**
270295
* Upload a file to the devbox.
271296
*
297+
* @example
298+
* ```typescript
299+
* const file = new File(['content'], 'data.txt');
300+
* await devbox.file.upload({
301+
* path: '/app/data.txt',
302+
* file: file,
303+
* });
304+
* ```
305+
*
272306
* @param {DevboxUploadFileParams} params - Parameters containing the file path and file to upload
273307
* @param {Core.RequestOptions} [options] - Request options
274308
* @returns {Promise<unknown>} Upload result
@@ -284,11 +318,13 @@ export class DevboxFileOps {
284318
* ## Overview
285319
*
286320
* The `Devbox` class provides a high-level, object-oriented API for managing devboxes.
287-
* It wraps the low-level API client and provides convenient methods for common operations.
321+
* Devboxes are containers that run your code in a consistent environment. They have the the following operations:
322+
* - {@link DevboxNetOps net} - Network operations
323+
* - {@link DevboxCmdOps cmd} - Command execution operations
324+
* - {@link DevboxFileOps file} - File operations
288325
*
289-
* ## Creating Devboxes
326+
* ## Quickstart
290327
*
291-
* ### Basic Creation
292328
* ```typescript
293329
* import { RunloopSDK } from '@runloop/api-client-ts';
294330
*
@@ -334,7 +370,9 @@ export class Devbox {
334370
* ```typescript
335371
* const runloop = new RunloopSDK();
336372
* const devbox = await runloop.devbox.create({ name: 'my-devbox' });
337-
* console.log(`Devbox ${devbox.id} is ready!`);
373+
*
374+
* devbox.cmd.exec({ command: 'echo "Hello, World!"' });
375+
* ...
338376
* ```
339377
*
340378
* @param {Runloop} client - The Runloop client instance
@@ -354,6 +392,15 @@ export class Devbox {
354392
/**
355393
* Create a new Devbox from a Blueprint and wait for it to reach the running state.
356394
*
395+
* @example
396+
* ```typescript
397+
* const devbox = await Devbox.createFromBlueprintId(
398+
* runloop,
399+
* blueprint.id,
400+
* { name: 'my-devbox' }
401+
* );
402+
* ```
403+
*
357404
* @param {Runloop} client - The Runloop client instance
358405
* @param {string} blueprintId - The blueprint ID to create from
359406
* @param {Omit<DevboxCreateParams, 'blueprint_id' | 'snapshot_id' | 'blueprint_name'>} [params] - Additional devbox creation parameters
@@ -400,6 +447,15 @@ export class Devbox {
400447
/**
401448
* Create a new Devbox from a Snapshot and wait for it to reach the running state.
402449
*
450+
* @example
451+
* ```typescript
452+
* const devbox = await Devbox.createFromSnapshot(
453+
* runloop,
454+
* snapshot.id,
455+
* { name: 'restored-devbox' }
456+
* );
457+
* ```
458+
*
403459
* @param {Runloop} client - The Runloop client instance
404460
* @param {string} snapshotId - The snapshot ID to create from
405461
* @param {Omit<DevboxCreateParams, 'snapshot_id' | 'blueprint_id' | 'blueprint_name'>} [params] - Additional devbox creation parameters
@@ -424,6 +480,12 @@ export class Devbox {
424480
* Create a Devbox instance by ID without retrieving from API.
425481
* Use getInfo() to fetch the actual data when needed.
426482
*
483+
* @example
484+
* ```typescript
485+
* const devbox = Devbox.fromId(runloop, 'devbox-123');
486+
* const info = await devbox.getInfo();
487+
* ```
488+
*
427489
* @param {Runloop} client - The Runloop client instance
428490
* @param {string} id - The devbox ID
429491
* @returns {Devbox} A {@link Devbox} instance
@@ -434,6 +496,7 @@ export class Devbox {
434496

435497
/**
436498
* Get the devbox ID.
499+
* @returns {string} The devbox ID
437500
*/
438501
get id(): string {
439502
return this._id;
@@ -443,6 +506,13 @@ export class Devbox {
443506
* Start streaming logs with callbacks.
444507
* Returns a promise that resolves when all streams complete.
445508
* Uses SSE streams from the old SDK with auto-reconnect.
509+
*
510+
* @private
511+
* @param {string} executionId - The execution ID to stream logs for
512+
* @param {(line: string) => void} [stdout] - Callback for stdout log lines
513+
* @param {(line: string) => void} [stderr] - Callback for stderr log lines
514+
* @param {(line: string) => void} [output] - Callback for all log lines (both stdout and stderr)
515+
* @returns {Promise<void>} Promise that resolves when all streams complete
446516
*/
447517
private startStreamingWithCallbacks(
448518
executionId: string,
@@ -492,6 +562,14 @@ export class Devbox {
492562

493563
/**
494564
* Get the complete devbox data from the API.
565+
*
566+
* @example
567+
* ```typescript
568+
* const devbox = Devbox.fromId(runloop, 'devbox-123');
569+
* const info = await devbox.getInfo();
570+
* console.log(`Devbox name: ${info.name}, status: ${info.status}`);
571+
* ```
572+
*
495573
* @param {Core.RequestOptions} [options] - Request options
496574
* @returns {Promise<DevboxView>} The devbox data
497575
*/
@@ -503,6 +581,13 @@ export class Devbox {
503581
* Wait for the devbox to reach the running state.
504582
* Uses optimized server-side polling for better performance.
505583
*
584+
* @example
585+
* ```typescript
586+
* const devbox = Devbox.fromId(runloop, 'devbox-123');
587+
* await devbox.awaitRunning();
588+
* console.log('Devbox is now running');
589+
* ```
590+
*
506591
* @param {Core.RequestOptions & { polling?: Partial<PollingOptions<DevboxView>> }} [options] - Request options with optional polling configuration
507592
* @returns {Promise<DevboxView>} The devbox data when running state is reached
508593
*/
@@ -516,6 +601,13 @@ export class Devbox {
516601
* Wait for the devbox to reach the suspended state.
517602
* Uses optimized server-side polling for better performance.
518603
*
604+
* @example
605+
* ```typescript
606+
* await devbox.suspend();
607+
* await devbox.awaitSuspended();
608+
* console.log('Devbox is now suspended');
609+
* ```
610+
*
519611
* @param {Core.RequestOptions & { polling?: Partial<PollingOptions<DevboxView>> }} [options] - Request options with optional polling configuration
520612
* @returns {Promise<DevboxView>} The devbox data when suspended state is reached
521613
*/
@@ -570,6 +662,12 @@ export class Devbox {
570662

571663
/**
572664
* Shutdown the devbox.
665+
*
666+
* @example
667+
* ```typescript
668+
* await devbox.shutdown();
669+
* ```
670+
*
573671
* @param {Core.RequestOptions} [options] - Request options
574672
* @returns {Promise<unknown>} Shutdown result
575673
*/
@@ -579,6 +677,13 @@ export class Devbox {
579677

580678
/**
581679
* Suspend the devbox and create a disk snapshot.
680+
*
681+
* @example
682+
* ```typescript
683+
* await devbox.suspend();
684+
* await devbox.awaitSuspended();
685+
* ```
686+
*
582687
* @param {Core.RequestOptions} [options] - Request options
583688
* @returns {Promise<unknown>} Suspend result
584689
*/
@@ -588,6 +693,13 @@ export class Devbox {
588693

589694
/**
590695
* Resume a suspended devbox.
696+
*
697+
* @example
698+
* ```typescript
699+
* await devbox.resume();
700+
* await devbox.awaitRunning();
701+
* ```
702+
*
591703
* @param {Core.RequestOptions} [options] - Request options
592704
* @returns {Promise<unknown>} Resume result
593705
*/
@@ -597,6 +709,13 @@ export class Devbox {
597709

598710
/**
599711
* Send a keep-alive signal to prevent idle shutdown.
712+
*
713+
* @example
714+
* ```typescript
715+
* // Send keep-alive periodically
716+
* setInterval(() => devbox.keepAlive(), 60000);
717+
* ```
718+
*
600719
* @param {Core.RequestOptions} [options] - Request options
601720
* @returns {Promise<unknown>} Keep-alive result
602721
*/
@@ -605,13 +724,41 @@ export class Devbox {
605724
}
606725
}
607726

727+
/**
728+
* Namespace for Devbox-related types and classes.
729+
* Provides convenient access to operation classes and types.
730+
*/
608731
export declare namespace Devbox {
732+
/**
733+
* Network operations class for devboxes.
734+
* @see {@link DevboxNetOps}
735+
*/
609736
export {
610737
DevboxNetOps as NetOps,
738+
/**
739+
* Command execution operations class for devboxes.
740+
* @see {@link DevboxCmdOps}
741+
*/
611742
DevboxCmdOps as CmdOps,
743+
/**
744+
* File operations class for devboxes.
745+
* @see {@link DevboxFileOps}
746+
*/
612747
DevboxFileOps as FileOps,
748+
/**
749+
* Execution class for tracking async command execution.
750+
* @see {@link Execution}
751+
*/
613752
Execution as Execution,
753+
/**
754+
* ExecutionResult class for accessing command execution results.
755+
* @see {@link ExecutionResult}
756+
*/
614757
ExecutionResult as ExecutionResult,
758+
/**
759+
* Streaming callbacks interface for real-time log processing.
760+
* @see {@link ExecuteStreamingCallbacks}
761+
*/
615762
type ExecuteStreamingCallbacks as ExecuteStreamingCallbacks,
616763
};
617764
}

0 commit comments

Comments
 (0)