@celestoai/sdk 0.1.1 → 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 +202 -45
- package/dist/chunk-LPTIN7LO.js +475 -0
- package/dist/chunk-LPTIN7LO.js.map +1 -0
- package/dist/computers/index.cjs +320 -9
- package/dist/computers/index.cjs.map +1 -1
- package/dist/computers/index.d.cts +103 -52
- package/dist/computers/index.d.ts +103 -52
- package/dist/computers/index.js +3 -3
- package/dist/index.cjs +476 -175
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -13
- package/dist/index.d.ts +4 -13
- package/dist/index.js +3 -12
- package/dist/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-OGMV3NFZ.js +0 -164
- package/dist/chunk-OGMV3NFZ.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
# @celestoai/sdk
|
|
2
2
|
|
|
3
|
-
|
|
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.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
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.
|
|
8
|
+
|
|
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**.
|
|
7
24
|
|
|
8
25
|
## Install
|
|
9
26
|
|
|
@@ -11,67 +28,169 @@ Node-only TypeScript SDK for the [Celesto](https://celesto.ai) platform. Covers:
|
|
|
11
28
|
npm install @celestoai/sdk
|
|
12
29
|
```
|
|
13
30
|
|
|
31
|
+
Set your API key before running SDK examples:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
export CELESTO_API_KEY="your-api-key"
|
|
35
|
+
```
|
|
36
|
+
|
|
14
37
|
## Quickstart
|
|
15
38
|
|
|
16
|
-
|
|
17
|
-
import { Celesto } from "@celestoai/sdk";
|
|
39
|
+
Create a file named `quickstart.mjs`:
|
|
18
40
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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:
|
|
23
56
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const result = await celesto.computers.exec(computer.id, "uname -a");
|
|
27
|
-
console.log(result.stdout);
|
|
28
|
-
await celesto.computers.delete(computer.id);
|
|
57
|
+
```bash
|
|
58
|
+
node quickstart.mjs
|
|
29
59
|
```
|
|
30
60
|
|
|
31
61
|
## Computers
|
|
32
62
|
|
|
33
|
-
|
|
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
|
|
67
|
+
|
|
68
|
+
Create a file named `create-computer.mjs`:
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { Computer } from "@celestoai/sdk";
|
|
34
72
|
|
|
35
|
-
|
|
36
|
-
const computer = await celesto.computers.create({
|
|
73
|
+
const computer = await Computer.create({
|
|
37
74
|
cpus: 2,
|
|
38
75
|
memory: 2048,
|
|
39
|
-
|
|
76
|
+
disk: "15gb",
|
|
40
77
|
});
|
|
41
78
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
79
|
+
try {
|
|
80
|
+
console.log(computer.name, computer["name"]);
|
|
81
|
+
} finally {
|
|
82
|
+
await computer.delete();
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
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.
|
|
93
|
+
|
|
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();
|
|
102
|
+
for (const template of templates) {
|
|
103
|
+
console.log(template.id, template.defaultRamMb);
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Create a computer from a template:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
import { Computer } from "@celestoai/sdk";
|
|
45
111
|
|
|
46
|
-
const
|
|
112
|
+
const computer = await Computer.create({ templateId: "coding-agent" });
|
|
113
|
+
try {
|
|
114
|
+
console.log(computer.name);
|
|
115
|
+
} finally {
|
|
116
|
+
await computer.delete();
|
|
117
|
+
}
|
|
47
118
|
```
|
|
48
119
|
|
|
49
|
-
###
|
|
120
|
+
### Run a Command
|
|
121
|
+
|
|
122
|
+
Create a file named `run-command.mjs`:
|
|
50
123
|
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
|
|
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
|
+
});
|
|
132
|
+
|
|
133
|
+
console.log(result.exitCode);
|
|
134
|
+
console.log(result.stdout);
|
|
135
|
+
console.error(result.stderr);
|
|
136
|
+
} finally {
|
|
137
|
+
await computer.delete();
|
|
138
|
+
}
|
|
54
139
|
```
|
|
55
140
|
|
|
56
|
-
###
|
|
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`.
|
|
57
145
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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 |
|
|
61
153
|
|
|
62
|
-
|
|
63
|
-
const conn = await celesto.computers.getTerminalConnection("my-computer");
|
|
154
|
+
### Publish Ports
|
|
64
155
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
156
|
+
Publish a port when a service inside the computer needs a public URL:
|
|
157
|
+
|
|
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);
|
|
70
164
|
```
|
|
71
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
|
+
|
|
72
186
|
## Gatekeeper
|
|
73
187
|
|
|
74
|
-
|
|
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
|
|
75
194
|
import { GatekeeperClient } from "@celestoai/sdk/gatekeeper";
|
|
76
195
|
|
|
77
196
|
const client = new GatekeeperClient({ token: process.env.CELESTO_API_KEY });
|
|
@@ -83,18 +202,56 @@ const connect = await client.connect({
|
|
|
83
202
|
});
|
|
84
203
|
|
|
85
204
|
if (connect.status === "redirect") {
|
|
86
|
-
console.log(
|
|
205
|
+
console.log(connect.oauthUrl);
|
|
206
|
+
} else {
|
|
207
|
+
console.log(connect.status);
|
|
87
208
|
}
|
|
88
209
|
```
|
|
89
210
|
|
|
90
|
-
|
|
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.
|
|
91
229
|
|
|
92
|
-
|
|
230
|
+
JWT is a signed login token. Most users should use a Celesto API key.
|
|
93
231
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
+
```
|
|
97
253
|
|
|
98
254
|
## License
|
|
99
255
|
|
|
100
|
-
Apache-2.0. The SDK is open source
|
|
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
|