@celestoai/sdk 0.1.2 → 0.1.3

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 CHANGED
@@ -1,12 +1,26 @@
1
1
  # @celestoai/sdk
2
2
 
3
- Use this package to create Celesto computers from Node.js apps. Your code can
4
- start a computer, run commands in it, and delete it when the work is done.
3
+ Use this package to run work in Celesto from a Node.js app. Your code can create
4
+ a cloud computer, run commands in it, and delete it when the work is done.
5
5
 
6
- It includes:
6
+ An AI agent is software that can plan and run tasks. A harness is the code that
7
+ starts, tests, or supervises an agent.
7
8
 
8
- - **Computers** (`/v1/computers`) — create, manage, and interact with sandboxed virtual machines
9
- - **Gatekeeper** (`/v1/gatekeeper`) — delegated access to user resources
9
+ Use this package when you want to:
10
+
11
+ - Run an AI agent or harness in a clean computer.
12
+ - Run shell commands from JavaScript or TypeScript.
13
+ - Keep agent work separate from your laptop, server, or production system.
14
+ - Ask a user to approve access to Google Drive through Gatekeeper.
15
+
16
+ Gatekeeper is Celesto's access helper. It lets a user approve which external
17
+ files or folders your app can use.
18
+
19
+ ## Requirements
20
+
21
+ - Node.js 18 or newer.
22
+ - A Celesto API key from [Celesto Settings](https://celesto.ai) under
23
+ **Settings > Security**.
10
24
 
11
25
  ## Install
12
26
 
@@ -14,80 +28,169 @@ It includes:
14
28
  npm install @celestoai/sdk
15
29
  ```
16
30
 
31
+ Set your API key before running SDK examples:
32
+
33
+ ```bash
34
+ export CELESTO_API_KEY="your-api-key"
35
+ ```
36
+
17
37
  ## Quickstart
18
38
 
19
- ```ts
20
- import { Celesto } from "@celestoai/sdk";
39
+ Create a file named `quickstart.mjs`:
21
40
 
22
- const celesto = new Celesto({
23
- token: process.env.CELESTO_API_KEY,
24
- // organizationId: "org_123", // optional, for JWTs with multiple orgs
25
- });
41
+ ```js
42
+ import { Computer } from "@celestoai/sdk";
43
+
44
+ const computer = await Computer.create();
45
+ try {
46
+ console.log(`Computer ready: ${computer.name}`);
47
+
48
+ const result = await computer.run("uname -a");
49
+ console.log(result.stdout);
50
+ } finally {
51
+ await computer.delete();
52
+ }
53
+ ```
54
+
55
+ Run it:
26
56
 
27
- // Computers
28
- const computer = await celesto.computers.create({ templateId: "coding-agent" });
29
- const result = await celesto.computers.exec(computer.id, "uname -a");
30
- console.log(result.stdout);
31
- await celesto.computers.delete(computer.id);
57
+ ```bash
58
+ node quickstart.mjs
32
59
  ```
33
60
 
34
61
  ## Computers
35
62
 
36
- Templates are ready-made computer setups. Choose one when you want a computer
37
- that already has the tools your agent needs.
63
+ A computer is a disposable cloud machine for your app or agent. By default,
64
+ Celesto creates a `scratch` computer, which is a minimal Ubuntu computer.
65
+
66
+ ### Create with Custom Resources
38
67
 
39
- ### Lifecycle
68
+ Create a file named `create-computer.mjs`:
40
69
 
41
- ```ts
42
- const computer = await celesto.computers.create({
43
- templateId: "coding-agent",
70
+ ```js
71
+ import { Computer } from "@celestoai/sdk";
72
+
73
+ const computer = await Computer.create({
44
74
  cpus: 2,
45
75
  memory: 2048,
46
- diskSizeMb: 15360,
76
+ disk: "15gb",
47
77
  });
48
78
 
49
- await celesto.computers.stop(computer.id);
50
- await celesto.computers.start(computer.id);
51
- await celesto.computers.delete(computer.id);
52
-
53
- const { computers, count } = await celesto.computers.list();
79
+ try {
80
+ console.log(computer.name, computer["name"]);
81
+ } finally {
82
+ await computer.delete();
83
+ }
54
84
  ```
55
85
 
56
- Omit CPU, memory, or disk fields to use the selected template defaults.
86
+ Omit CPU, memory, or disk fields to use the default size. `disk` accepts MB as
87
+ an integer or strings such as `"2gb"`.
88
+
89
+ ### Templates
90
+
91
+ Use a template when you want a computer that already has extra tools installed.
92
+ For example, `coding-agent` includes common tools for coding tasks.
57
93
 
58
- ```ts
59
- const templates = await celesto.computers.listTemplates();
94
+ List available templates:
95
+
96
+ Create a file named `list-templates.mjs`:
97
+
98
+ ```js
99
+ import { Computer } from "@celestoai/sdk";
100
+
101
+ const templates = await Computer.listTemplates();
60
102
  for (const template of templates) {
61
103
  console.log(template.id, template.defaultRamMb);
62
104
  }
63
105
  ```
64
106
 
65
- ### Running commands
107
+ Create a computer from a template:
108
+
109
+ ```js
110
+ import { Computer } from "@celestoai/sdk";
111
+
112
+ const computer = await Computer.create({ templateId: "coding-agent" });
113
+ try {
114
+ console.log(computer.name);
115
+ } finally {
116
+ await computer.delete();
117
+ }
118
+ ```
119
+
120
+ ### Run a Command
121
+
122
+ Create a file named `run-command.mjs`:
123
+
124
+ ```js
125
+ import { Computer } from "@celestoai/sdk";
126
+
127
+ const computer = await Computer.create();
128
+ try {
129
+ const result = await computer.run("ls -la", {
130
+ timeout: 60,
131
+ });
66
132
 
67
- ```ts
68
- const result = await celesto.computers.exec(computer.id, "ls -la", { timeout: 60 });
69
- console.log(result.exitCode, result.stdout, result.stderr);
133
+ console.log(result.exitCode);
134
+ console.log(result.stdout);
135
+ console.error(result.stderr);
136
+ } finally {
137
+ await computer.delete();
138
+ }
70
139
  ```
71
140
 
72
- ### Terminal connection
141
+ ### Manage Computers
142
+
143
+ `computerId` can be `computer.id` from `Computer.create()` or a computer name
144
+ shown by the Celesto command-line tool: `celesto computer list`.
145
+
146
+ | Method | What it does |
147
+ | --- | --- |
148
+ | `Computer.list()` | List computers in your account |
149
+ | `Computer.get(computerId)` | Get one computer by name or ID |
150
+ | `computer.stop()` | Stop a running computer |
151
+ | `computer.start()` | Start a stopped computer |
152
+ | `computer.delete()` | Delete a computer |
73
153
 
74
- `getTerminalConnection()` resolves a computer name or ID and returns everything you need
75
- to open a WebSocket terminal with any library of your choice. No built-in WebSocket
76
- dependency — bring your own.
154
+ ### Publish Ports
77
155
 
78
- ```ts
79
- const conn = await celesto.computers.getTerminalConnection("my-computer");
156
+ Publish a port when a service inside the computer needs a public URL:
80
157
 
81
- // Use any WebSocket library (ws, Node 22+ built-in, etc.)
82
- import WebSocket from "ws";
83
- const ws = new WebSocket(conn.url, { headers: conn.headers });
84
- ws.on("open", () => ws.send(conn.firstMessage));
85
- ws.on("message", (data) => process.stdout.write(data));
158
+ ```js
159
+ import { Computer } from "@celestoai/sdk";
160
+
161
+ const computer = await Computer.get("curie");
162
+ const url = await computer.publishPort(8000);
163
+ console.log(url);
86
164
  ```
87
165
 
166
+ List and remove published ports:
167
+
168
+ ```js
169
+ import { Computer } from "@celestoai/sdk";
170
+
171
+ const computer = await Computer.get("curie");
172
+ console.log(await computer.listPublishedPorts());
173
+ await computer.unpublishPort(8000);
174
+ ```
175
+
176
+ ### Terminal Connections
177
+
178
+ Use `getTerminalConnection()` when you are building your own interactive
179
+ terminal. It returns the WebSocket URL, headers, and first message needed to
180
+ connect. A WebSocket is a long-running connection for sending terminal input and
181
+ receiving terminal output.
182
+
183
+ The SDK does not install a WebSocket package for you. Use any WebSocket library
184
+ that supports custom headers.
185
+
88
186
  ## Gatekeeper
89
187
 
90
- ```ts
188
+ Use Gatekeeper when your app needs user-approved access to an external resource,
189
+ such as Google Drive.
190
+
191
+ Create a file named `gatekeeper-connect.mjs`:
192
+
193
+ ```js
91
194
  import { GatekeeperClient } from "@celestoai/sdk/gatekeeper";
92
195
 
93
196
  const client = new GatekeeperClient({ token: process.env.CELESTO_API_KEY });
@@ -99,18 +202,56 @@ const connect = await client.connect({
99
202
  });
100
203
 
101
204
  if (connect.status === "redirect") {
102
- console.log("OAuth URL:", connect.oauthUrl);
205
+ console.log(connect.oauthUrl);
206
+ } else {
207
+ console.log(connect.status);
103
208
  }
104
209
  ```
105
210
 
106
- Full docs: https://docs.celesto.ai/celesto-sdk/gatekeeper
211
+ If the response prints a URL, open it so the user can approve access.
212
+
213
+ Full Gatekeeper docs: https://docs.celesto.ai/celesto-sdk/gatekeeper
214
+
215
+ ## Configuration
216
+
217
+ | Option | What it does |
218
+ | --- | --- |
219
+ | `token` | Celesto API key or JWT |
220
+ | `apiKey` | Alias for `token` |
221
+ | `baseUrl` | Custom Celesto API URL |
222
+ | `organizationId` | Sends the `X-Current-Organization` header |
223
+ | `timeoutMs` | Request timeout in milliseconds |
224
+ | `headers` | Extra headers to send with every request |
225
+
226
+ Pass these options as the second argument to `Computer.create()` or
227
+ `Computer.get()`. Gatekeeper clients accept the same options in their
228
+ constructor.
107
229
 
108
- ## Notes
230
+ JWT is a signed login token. Most users should use a Celesto API key.
109
231
 
110
- - `token` accepts either a Celesto API key or a JWT.
111
- - `organizationId` adds the `X-Current-Organization` header.
112
- - Requires Node 18+ for built-in `fetch`. Zero runtime dependencies.
232
+ ## Errors
233
+
234
+ The SDK exports these error classes:
235
+
236
+ | Error | When it is used |
237
+ | --- | --- |
238
+ | `CelestoApiError` | The API returns an error status |
239
+ | `CelestoNetworkError` | The network request fails |
240
+ | `CelestoError` | Base class for all SDK errors |
241
+
242
+ ## Develop Locally
243
+
244
+ If you are contributing and have `npm` installed, run these commands from the
245
+ repository's `ts` directory:
246
+
247
+ ```bash
248
+ npm install
249
+ npm test
250
+ npm run lint
251
+ npm run build
252
+ ```
113
253
 
114
254
  ## License
115
255
 
116
- Apache-2.0. The SDK is open source; use of the Celesto platform is governed by the Celesto Terms of Service: https://celesto.ai/legal/terms
256
+ Apache-2.0. The SDK is open source. Use of the Celesto platform is governed by
257
+ the Celesto Terms of Service: https://celesto.ai/legal/terms