@celestoai/sdk 0.1.6 → 0.1.7
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/CHANGELOG.md +24 -0
- package/README.md +89 -270
- package/dist/{chunk-B4JRBDUO.js → chunk-3HEUI5UL.js} +278 -304
- package/dist/chunk-3HEUI5UL.js.map +1 -0
- package/dist/computers/index.cjs +148 -345
- package/dist/computers/index.cjs.map +1 -1
- package/dist/computers/index.d.cts +1 -270
- package/dist/computers/index.d.ts +1 -270
- package/dist/computers/index.js +1 -2
- package/dist/index-59d7VJXL.d.cts +303 -0
- package/dist/index-59d7VJXL.d.ts +303 -0
- package/dist/index.cjs +191 -1573
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -4
- package/dist/index.d.ts +22 -4
- package/dist/index.js +5 -61
- package/package.json +25 -22
- package/dist/agents/index.cjs +0 -1226
- package/dist/agents/index.cjs.map +0 -1
- package/dist/agents/index.d.cts +0 -2
- package/dist/agents/index.d.ts +0 -2
- package/dist/agents/index.js +0 -60
- package/dist/agents/index.js.map +0 -1
- package/dist/chunk-6Y2YZCPU.js +0 -1007
- package/dist/chunk-6Y2YZCPU.js.map +0 -1
- package/dist/chunk-B4JRBDUO.js.map +0 -1
- package/dist/chunk-P7F52CSQ.js +0 -177
- package/dist/chunk-P7F52CSQ.js.map +0 -1
- package/dist/chunk-THPVQCTE.js +0 -183
- package/dist/chunk-THPVQCTE.js.map +0 -1
- package/dist/config-dDPvsH-K.d.cts +0 -42
- package/dist/config-dDPvsH-K.d.ts +0 -42
- package/dist/gatekeeper/index.cjs +0 -348
- package/dist/gatekeeper/index.cjs.map +0 -1
- package/dist/gatekeeper/index.d.cts +0 -104
- package/dist/gatekeeper/index.d.ts +0 -104
- package/dist/gatekeeper/index.js +0 -8
- package/dist/gatekeeper/index.js.map +0 -1
- package/dist/index-Cii1_OFg.d.ts +0 -696
- package/dist/index-CsEA7qMF.d.cts +0 -696
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Cloud TypeScript SDK changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.7
|
|
4
|
+
|
|
5
|
+
- Moved the Cloud TypeScript SDK into the Celesto repository. The npm package
|
|
6
|
+
name and the import paths for computers are unchanged. Imported from
|
|
7
|
+
[`CelestoAI/sdk` at `1ab90c7`](https://github.com/CelestoAI/sdk/tree/1ab90c7fa0d845800c5e93a5a43ef163661e3f5b/ts).
|
|
8
|
+
- Removed `GatekeeperClient` and `@celestoai/sdk/gatekeeper`. The Cloud API no
|
|
9
|
+
longer offers Gatekeeper or its delegated Google Drive access.
|
|
10
|
+
- Removed `ManagedAgentsClient` and `@celestoai/sdk/agents`. The Cloud API no
|
|
11
|
+
longer serves managed agents, runs, sessions, or their settings.
|
|
12
|
+
- `Computer.create()` now sends the required `Idempotency-Key`. Pass
|
|
13
|
+
`idempotencyKey` to reuse a key on retry.
|
|
14
|
+
- Use `sizeId` instead of CPU, memory, or disk overrides, which are now
|
|
15
|
+
rejected before the request. The SDK also rejects unknown create options.
|
|
16
|
+
- `runStream()` and `execStream()` yield buffered output and an exit event
|
|
17
|
+
after `/exec` completes. They no longer call the unavailable `/exec/stream`
|
|
18
|
+
endpoint. Aborting stops the HTTP request, not necessarily the remote command.
|
|
19
|
+
- The computer SDK reads logins saved by `celesto auth login` and keeps each
|
|
20
|
+
saved key on its original API URL.
|
|
21
|
+
- Requests honor their configured deadline even when a caller also supplies
|
|
22
|
+
an abort signal.
|
|
23
|
+
- Published separate TypeScript declarations for ESM and CommonJS consumers.
|
|
24
|
+
- Added `lost` to the computer status type and list filter.
|
package/README.md
CHANGED
|
@@ -11,11 +11,9 @@ Use this package when you want to:
|
|
|
11
11
|
- Run an AI agent or harness in a clean computer.
|
|
12
12
|
- Run shell commands from JavaScript or TypeScript.
|
|
13
13
|
- Keep agent work separate from your laptop, server, or production system.
|
|
14
|
-
- Run an agent for each of your own users, with a spending limit per user.
|
|
15
|
-
- Ask a user to approve access to Google Drive through Gatekeeper.
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
This is the Cloud SDK. To run computers on your own machine, use the separate
|
|
16
|
+
[@celestoai/celesto](https://github.com/CelestoAI/celesto/tree/main/ts) package.
|
|
19
17
|
|
|
20
18
|
## Requirements
|
|
21
19
|
|
|
@@ -29,6 +27,8 @@ files or folders your app can use.
|
|
|
29
27
|
npm install @celestoai/sdk
|
|
30
28
|
```
|
|
31
29
|
|
|
30
|
+
The computer examples below require `@celestoai/sdk` 0.1.7 or newer.
|
|
31
|
+
|
|
32
32
|
Sign in once with the Celesto CLI:
|
|
33
33
|
|
|
34
34
|
```bash
|
|
@@ -36,7 +36,10 @@ pip install celesto
|
|
|
36
36
|
celesto auth login
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
The `Computer` API checks an explicitly passed `token` or `apiKey` first, then
|
|
39
|
+
The `Computer` API checks an explicitly passed `token` or `apiKey` first, then
|
|
40
|
+
`CELESTO_API_KEY` in the shell, the current project's `.env`, and credentials
|
|
41
|
+
saved by `celesto auth login`. A saved login is used only with the API URL it
|
|
42
|
+
was saved for. You can use a local `.env` instead of the CLI:
|
|
40
43
|
|
|
41
44
|
```bash .env
|
|
42
45
|
CELESTO_API_KEY="your-api-key"
|
|
@@ -46,225 +49,76 @@ Add `.env` to `.gitignore`.
|
|
|
46
49
|
|
|
47
50
|
## Quickstart
|
|
48
51
|
|
|
49
|
-
Create a file named `quickstart.mjs
|
|
52
|
+
Create a file named `quickstart.mjs`. `Computer.create()` can return before
|
|
53
|
+
the computer is ready, so check its status before running commands.
|
|
50
54
|
|
|
51
55
|
```js
|
|
56
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
52
57
|
import { Computer } from "@celestoai/sdk";
|
|
53
58
|
|
|
54
59
|
const computer = await Computer.create();
|
|
60
|
+
console.log(`Computer ID: ${computer.id}`);
|
|
55
61
|
try {
|
|
56
|
-
|
|
62
|
+
const deadline = Date.now() + 60_000;
|
|
63
|
+
while (computer.status === "creating" && Date.now() < deadline) {
|
|
64
|
+
await delay(500);
|
|
65
|
+
await computer.refresh();
|
|
66
|
+
}
|
|
67
|
+
if (computer.status !== "running") {
|
|
68
|
+
throw new Error(`Computer ${computer.id} is ${computer.status}. Check it in the Cloud dashboard.`);
|
|
69
|
+
}
|
|
57
70
|
|
|
58
71
|
const result = await computer.run("uname -a");
|
|
59
72
|
console.log(result.stdout);
|
|
60
73
|
} finally {
|
|
61
|
-
await computer.delete();
|
|
74
|
+
if (computer.status !== "creating") await computer.delete();
|
|
62
75
|
}
|
|
63
76
|
```
|
|
64
77
|
|
|
78
|
+
If it is still `creating` when the example stops waiting, check the printed
|
|
79
|
+
ID in the dashboard and delete it once creation finishes.
|
|
80
|
+
|
|
65
81
|
Run it:
|
|
66
82
|
|
|
67
83
|
```bash
|
|
68
84
|
node quickstart.mjs
|
|
69
85
|
```
|
|
70
86
|
|
|
71
|
-
## Run Agents for Your Users
|
|
72
|
-
|
|
73
|
-
If you are building a product on top of an AI agent, every run happens for one
|
|
74
|
-
of *your* users. Celesto keeps them apart: each run is recorded against the user
|
|
75
|
-
it acted for, so you can see what that person's agent did and what it cost, and
|
|
76
|
-
stop it from spending more than you allow.
|
|
77
|
-
|
|
78
|
-
You identify each of your users with a string you already have — a database ID,
|
|
79
|
-
an email, anything. Celesto stores it as you send it. There is no Celesto user
|
|
80
|
-
ID to look up and no mapping table to keep.
|
|
81
|
-
|
|
82
|
-
This example creates an agent, runs it for one user, prints the answer as it
|
|
83
|
-
arrives, and then reads that user's spending.
|
|
84
|
-
|
|
85
|
-
```ts
|
|
86
|
-
import { ManagedAgentsClient } from "@celestoai/sdk";
|
|
87
|
-
|
|
88
|
-
const celesto = new ManagedAgentsClient({ apiKey: process.env.CELESTO_API_KEY });
|
|
89
|
-
|
|
90
|
-
const agent = await celesto.agents.create({
|
|
91
|
-
name: "support-bot",
|
|
92
|
-
model: "openai/gpt-5.4-mini",
|
|
93
|
-
instructions: "Answer order questions in one short paragraph.",
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
for await (const event of celesto.runs.stream(agent.id, {
|
|
97
|
-
input: "Where is my order?",
|
|
98
|
-
endUserId: "usr_8837",
|
|
99
|
-
})) {
|
|
100
|
-
if (event.name === "message.delta") process.stdout.write(event.data.text ?? "");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const { budget } = await celesto.endUsers.get("usr_8837");
|
|
104
|
-
console.log(`\nSpent ${budget.spentUsd} of ${budget.capUsd}`);
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
Switching on `event.name` narrows the event, so `event.data` is typed for that
|
|
108
|
-
event and nothing else.
|
|
109
|
-
|
|
110
|
-
### Wait Instead of Streaming
|
|
111
|
-
|
|
112
|
-
`stream()` gives you the answer as it is written. `create()` waits and gives you
|
|
113
|
-
the finished run:
|
|
114
|
-
|
|
115
|
-
```ts
|
|
116
|
-
import { ManagedAgentsClient } from "@celestoai/sdk";
|
|
117
|
-
|
|
118
|
-
const celesto = new ManagedAgentsClient({ apiKey: process.env.CELESTO_API_KEY });
|
|
119
|
-
const agentId = "agt_your_agent_id";
|
|
120
|
-
|
|
121
|
-
const run = await celesto.runs.create(agentId, {
|
|
122
|
-
input: "Where is my order?",
|
|
123
|
-
endUserId: "usr_8837",
|
|
124
|
-
});
|
|
125
|
-
console.log(run.output, run.usage.costUsd);
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### Money Is a String
|
|
129
|
-
|
|
130
|
-
Every amount — `costUsd`, `spentUsd`, `capUsd` — is a decimal string such as
|
|
131
|
-
`"0.000450"`, never a `number`. A single answer can cost a few millionths of a
|
|
132
|
-
dollar, which a JavaScript number cannot hold exactly. Display and compare the
|
|
133
|
-
string; if you need arithmetic, use a decimal library rather than `parseFloat`.
|
|
134
|
-
|
|
135
|
-
Writes are strings too. `budgetCapUsd` is typed `string`, so a number fails to
|
|
136
|
-
compile, and passing one anyway throws rather than sending it — `0.1 + 0.2`
|
|
137
|
-
stringifies to `"0.30000000000000004"`, and the only place that can still be
|
|
138
|
-
fixed is before it leaves your program.
|
|
139
|
-
|
|
140
|
-
### Set a Spending Limit
|
|
141
|
-
|
|
142
|
-
Give one user a cap, or set the default for everyone:
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
import { ManagedAgentsClient } from "@celestoai/sdk";
|
|
146
|
-
|
|
147
|
-
const celesto = new ManagedAgentsClient({ apiKey: process.env.CELESTO_API_KEY });
|
|
148
|
-
|
|
149
|
-
await celesto.endUsers.update("usr_8837", { budgetCapUsd: "5.00" });
|
|
150
|
-
await celesto.settings.update({ defaultEndUserBudgetUsd: "0.50" });
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
The cap covers a 30-day window that starts the first time that user runs
|
|
154
|
-
anything. When it runs out, the next run throws `BudgetExceededError`, and a run
|
|
155
|
-
already in flight stops at its next step with a `run.failed` event.
|
|
156
|
-
|
|
157
|
-
### Retry Safely
|
|
158
|
-
|
|
159
|
-
Pass `idempotencyKey` to make a retry safe: sending the same key again returns
|
|
160
|
-
the run that already happened instead of running the agent — and charging your
|
|
161
|
-
user — twice.
|
|
162
|
-
|
|
163
|
-
```ts
|
|
164
|
-
import { ManagedAgentsClient } from "@celestoai/sdk";
|
|
165
|
-
|
|
166
|
-
const celesto = new ManagedAgentsClient({ apiKey: process.env.CELESTO_API_KEY });
|
|
167
|
-
const agentId = "agt_your_agent_id";
|
|
168
|
-
|
|
169
|
-
const run = await celesto.runs.create(agentId, {
|
|
170
|
-
input: "Where is my order?",
|
|
171
|
-
endUserId: "usr_8837",
|
|
172
|
-
idempotencyKey: "order-status-42",
|
|
173
|
-
});
|
|
174
|
-
```
|
|
175
|
-
|
|
176
|
-
One conversation runs one agent at a time. If a second run arrives while the
|
|
177
|
-
first is still going, Celesto throws `SessionBusyError`. Pass `maxRetries: 2` to
|
|
178
|
-
wait and try again; the SDK creates an idempotency key for you when you do.
|
|
179
|
-
|
|
180
|
-
### Keep the Conversation Going
|
|
181
|
-
|
|
182
|
-
Every run belongs to a session, which is that user's transcript. Leave
|
|
183
|
-
`sessionId` out and Celesto starts one; pass it back to continue:
|
|
184
|
-
|
|
185
|
-
```ts
|
|
186
|
-
import { ManagedAgentsClient } from "@celestoai/sdk";
|
|
187
|
-
|
|
188
|
-
const celesto = new ManagedAgentsClient({ apiKey: process.env.CELESTO_API_KEY });
|
|
189
|
-
const agentId = "agt_your_agent_id";
|
|
190
|
-
|
|
191
|
-
const first = await celesto.runs.create(agentId, {
|
|
192
|
-
input: "Hello",
|
|
193
|
-
endUserId: "usr_8837",
|
|
194
|
-
});
|
|
195
|
-
const followUp = await celesto.runs.create(agentId, {
|
|
196
|
-
input: "And the one before that?",
|
|
197
|
-
endUserId: "usr_8837",
|
|
198
|
-
sessionId: first.sessionId,
|
|
199
|
-
});
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
### Change an Agent
|
|
203
|
-
|
|
204
|
-
Updating an agent saves a new version and leaves the old ones readable. Runs
|
|
205
|
-
remember the version they used, so a change never rewrites what already
|
|
206
|
-
happened. `celesto.agents.activateVersion(agent.id, 1)` goes back.
|
|
207
|
-
|
|
208
87
|
## Computers
|
|
209
88
|
|
|
210
89
|
A computer is a disposable cloud machine for your app or agent. By default,
|
|
211
90
|
Celesto creates a `scratch` computer, which is a minimal Ubuntu computer.
|
|
212
91
|
|
|
213
|
-
###
|
|
214
|
-
|
|
215
|
-
Create a file named `create-computer.mjs`:
|
|
92
|
+
### Choose a Size
|
|
216
93
|
|
|
217
94
|
```js
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
const computer = await Computer.create({
|
|
221
|
-
cpus: 2,
|
|
222
|
-
memory: 2048,
|
|
223
|
-
disk: "15gb",
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
try {
|
|
227
|
-
console.log(computer.name, computer["name"]);
|
|
228
|
-
} finally {
|
|
229
|
-
await computer.delete();
|
|
230
|
-
}
|
|
95
|
+
const computer = await Computer.create({ sizeId: "micro" });
|
|
231
96
|
```
|
|
232
97
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
```js
|
|
240
|
-
import { Computer } from "@celestoai/sdk";
|
|
241
|
-
|
|
242
|
-
const computer = await Computer.create({ persistentHome: true });
|
|
243
|
-
```
|
|
98
|
+
Use the same readiness and cleanup steps as in the quickstart. Omit `sizeId`
|
|
99
|
+
to use your account's default. The SDK sends `sizeId` as `size_id`; the current
|
|
100
|
+
catalog (`GET /v1/billing/sizes`) lists the exact CPU, memory, and disk values.
|
|
101
|
+
Cloud computers do not accept CPU, memory, or disk overrides. The SDK also
|
|
102
|
+
rejects unknown options, including `name`, `labels`, and `size`.
|
|
244
103
|
|
|
245
|
-
|
|
104
|
+
The SDK generates an `Idempotency-Key` for each call. If your app needs to
|
|
105
|
+
retry the same creation request after a lost response, pass an
|
|
106
|
+
`idempotencyKey` you saved before the first attempt, and reuse that key and
|
|
107
|
+
the same options on retry. The SDK does not retry automatically.
|
|
246
108
|
|
|
247
109
|
### Control Internet Access
|
|
248
110
|
|
|
249
|
-
Internet is on by default.
|
|
250
|
-
|
|
111
|
+
Internet is on by default. To disable outbound connections, replace the
|
|
112
|
+
`Computer.create()` line in the [quickstart](#quickstart):
|
|
251
113
|
|
|
252
114
|
```js
|
|
253
|
-
import { Computer } from "@celestoai/sdk";
|
|
254
|
-
|
|
255
115
|
const computer = await Computer.create({ networkPolicy: { mode: "off" } });
|
|
256
|
-
try {
|
|
257
|
-
console.log((await computer.run("uname -a")).stdout);
|
|
258
|
-
} finally {
|
|
259
|
-
await computer.delete();
|
|
260
|
-
}
|
|
261
116
|
```
|
|
262
117
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
creation.
|
|
266
|
-
`
|
|
267
|
-
allowlists are not supported.
|
|
118
|
+
Keep the quickstart's readiness check and cleanup. Commands and terminal
|
|
119
|
+
sessions still work without internet access. The policy cannot be changed
|
|
120
|
+
after creation. Pool computers do not support
|
|
121
|
+
`persistentHome: true`. Domain and IP allowlists are not supported.
|
|
268
122
|
|
|
269
123
|
### Templates
|
|
270
124
|
|
|
@@ -284,41 +138,33 @@ for (const template of templates) {
|
|
|
284
138
|
}
|
|
285
139
|
```
|
|
286
140
|
|
|
287
|
-
|
|
141
|
+
To create a computer from a template, change the create call in the
|
|
142
|
+
[quickstart](#quickstart):
|
|
288
143
|
|
|
289
144
|
```js
|
|
290
|
-
import { Computer } from "@celestoai/sdk";
|
|
291
|
-
|
|
292
145
|
const computer = await Computer.create({ templateId: "coding-agent" });
|
|
293
|
-
try {
|
|
294
|
-
console.log(computer.name);
|
|
295
|
-
} finally {
|
|
296
|
-
await computer.delete();
|
|
297
|
-
}
|
|
298
146
|
```
|
|
299
147
|
|
|
300
148
|
### Run a Command
|
|
301
149
|
|
|
302
|
-
|
|
150
|
+
Use the name or ID of a running computer:
|
|
303
151
|
|
|
304
152
|
```js
|
|
305
153
|
import { Computer } from "@celestoai/sdk";
|
|
306
154
|
|
|
307
|
-
const computer = await Computer.
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
});
|
|
312
|
-
|
|
313
|
-
console.log(result.exitCode);
|
|
314
|
-
console.log(result.stdout);
|
|
315
|
-
console.error(result.stderr);
|
|
316
|
-
} finally {
|
|
317
|
-
await computer.delete();
|
|
318
|
-
}
|
|
155
|
+
const computer = await Computer.get("curie");
|
|
156
|
+
const result = await computer.run("ls -la", { timeout: 60 });
|
|
157
|
+
console.log(result.exitCode, result.stdout);
|
|
158
|
+
console.error(result.stderr);
|
|
319
159
|
```
|
|
320
160
|
|
|
321
|
-
|
|
161
|
+
Commands allow up to 10,000 characters and a timeout of 1–300 seconds. Do not
|
|
162
|
+
put secrets in command text. Encoding them in base64 does not protect them.
|
|
163
|
+
|
|
164
|
+
Use `runStream()` or its alias `execStream()` to consume the result as events.
|
|
165
|
+
Cloud waits for the command to finish before yielding any events. It yields
|
|
166
|
+
non-empty stdout first, then non-empty stderr, then an exit event. It does not
|
|
167
|
+
yield a `started` event or preserve the original order of stdout and stderr.
|
|
322
168
|
|
|
323
169
|
```js
|
|
324
170
|
import { Computer } from "@celestoai/sdk";
|
|
@@ -336,12 +182,14 @@ for await (const event of computer.runStream("npm test", {
|
|
|
336
182
|
}
|
|
337
183
|
```
|
|
338
184
|
|
|
339
|
-
Call `controller.abort()` to stop the
|
|
185
|
+
Call `controller.abort()` to stop waiting for the response. This does not
|
|
186
|
+
guarantee the remote command stopped. For interactive live output, use
|
|
187
|
+
[`createTerminalSession()`](#terminal-connections).
|
|
340
188
|
|
|
341
189
|
### Manage Computers
|
|
342
190
|
|
|
343
191
|
`computerId` can be `computer.id` from `Computer.create()` or a computer name
|
|
344
|
-
shown by the Celesto command-line tool: `celesto computer list`.
|
|
192
|
+
shown by the Celesto command-line tool: `celesto computer list --cloud`.
|
|
345
193
|
|
|
346
194
|
| Method | What it does |
|
|
347
195
|
| --- | --- |
|
|
@@ -355,9 +203,17 @@ shown by the Celesto command-line tool: `celesto computer list`.
|
|
|
355
203
|
| `computer.start()` | Start a stopped computer |
|
|
356
204
|
| `computer.delete()` | Delete a computer |
|
|
357
205
|
|
|
206
|
+
Save `computer.id` with the job that owns it so you can clean it up later.
|
|
207
|
+
If `delete()` returns HTTP 409 while the computer is `creating`, refresh its
|
|
208
|
+
status and retry deletion by the same ID once creation finishes. After
|
|
209
|
+
`stop()` and `start()`, check that your services are running again. Do not
|
|
210
|
+
assume processes survived.
|
|
211
|
+
|
|
358
212
|
### Publish Ports
|
|
359
213
|
|
|
360
|
-
Publish a port when a service inside the computer needs a public URL
|
|
214
|
+
Publish a port when a service inside the computer needs a public URL. Celesto
|
|
215
|
+
does not add authentication to the URL. Add authentication to the service
|
|
216
|
+
before publishing it if access should be restricted.
|
|
361
217
|
|
|
362
218
|
```js
|
|
363
219
|
import { Computer } from "@celestoai/sdk";
|
|
@@ -419,16 +275,18 @@ Install Playwright Core in the application that runs this code:
|
|
|
419
275
|
npm install playwright-core
|
|
420
276
|
```
|
|
421
277
|
|
|
422
|
-
|
|
278
|
+
Create a computer with the `browser-agent` template and wait until it is
|
|
279
|
+
running, as in the [quickstart](#quickstart). Replace `curie` with its name or
|
|
280
|
+
ID to connect without creating another computer:
|
|
423
281
|
|
|
424
282
|
```js
|
|
425
283
|
import { Computer } from "@celestoai/sdk";
|
|
426
284
|
import { chromium } from "playwright-core";
|
|
427
285
|
|
|
428
|
-
const computer = await Computer.
|
|
286
|
+
const computer = await Computer.get("curie");
|
|
287
|
+
const connection = await computer.createBrowserConnection();
|
|
288
|
+
const browser = await chromium.connectOverCDP(connection.url);
|
|
429
289
|
try {
|
|
430
|
-
const connection = await computer.createBrowserConnection();
|
|
431
|
-
const browser = await chromium.connectOverCDP(connection.url);
|
|
432
290
|
const context = browser.contexts()[0];
|
|
433
291
|
if (!context) throw new Error("Celesto browser did not provide a context");
|
|
434
292
|
const pages = context.pages();
|
|
@@ -437,10 +295,12 @@ try {
|
|
|
437
295
|
await page.goto("https://example.com");
|
|
438
296
|
console.log(await page.title());
|
|
439
297
|
} finally {
|
|
440
|
-
await
|
|
298
|
+
await browser.close();
|
|
441
299
|
}
|
|
442
300
|
```
|
|
443
301
|
|
|
302
|
+
Delete the computer separately when you no longer need it.
|
|
303
|
+
|
|
444
304
|
### Display Connections
|
|
445
305
|
|
|
446
306
|
Use `createDisplayConnection()` when a Remote Framebuffer (RFB) client, such as
|
|
@@ -461,35 +321,6 @@ contain short-lived secret tokens, so do not log, persist, or share them. Create
|
|
|
461
321
|
a new connection after a disconnect or expiry. Browser automation and
|
|
462
322
|
read-write display connections require write access to the computer.
|
|
463
323
|
|
|
464
|
-
## Gatekeeper
|
|
465
|
-
|
|
466
|
-
Use Gatekeeper when your app needs user-approved access to an external resource,
|
|
467
|
-
such as Google Drive.
|
|
468
|
-
|
|
469
|
-
Create a file named `gatekeeper-connect.mjs`:
|
|
470
|
-
|
|
471
|
-
```js
|
|
472
|
-
import { GatekeeperClient } from "@celestoai/sdk/gatekeeper";
|
|
473
|
-
|
|
474
|
-
const client = new GatekeeperClient({ token: process.env.CELESTO_API_KEY });
|
|
475
|
-
|
|
476
|
-
const connect = await client.connect({
|
|
477
|
-
subject: "customer_123",
|
|
478
|
-
provider: "google_drive",
|
|
479
|
-
projectName: "Default",
|
|
480
|
-
});
|
|
481
|
-
|
|
482
|
-
if (connect.status === "redirect") {
|
|
483
|
-
console.log(connect.oauthUrl);
|
|
484
|
-
} else {
|
|
485
|
-
console.log(connect.status);
|
|
486
|
-
}
|
|
487
|
-
```
|
|
488
|
-
|
|
489
|
-
If the response prints a URL, open it so the user can approve access.
|
|
490
|
-
|
|
491
|
-
Full Gatekeeper docs: https://docs.celesto.ai/celesto-sdk/gatekeeper
|
|
492
|
-
|
|
493
324
|
## Configuration
|
|
494
325
|
|
|
495
326
|
| Option | What it does |
|
|
@@ -498,11 +329,12 @@ Full Gatekeeper docs: https://docs.celesto.ai/celesto-sdk/gatekeeper
|
|
|
498
329
|
| `apiKey` | Alias for `token` |
|
|
499
330
|
| `baseUrl` | Custom Celesto API URL |
|
|
500
331
|
| `organizationId` | Sends the `X-Current-Organization` header |
|
|
501
|
-
| `timeoutMs` |
|
|
332
|
+
| `timeoutMs` | Deadline in milliseconds for each request, including reading the response body |
|
|
502
333
|
| `headers` | Extra headers to send with every request |
|
|
503
334
|
|
|
504
335
|
Pass these options as the second argument to `Computer.create()` or
|
|
505
|
-
`Computer.get()`. An explicit `token` or `apiKey` takes precedence over local
|
|
336
|
+
`Computer.get()`. An explicit `token` or `apiKey` takes precedence over local
|
|
337
|
+
credential discovery.
|
|
506
338
|
|
|
507
339
|
JWT is a signed login token. Most users should use a Celesto API key.
|
|
508
340
|
|
|
@@ -514,36 +346,23 @@ The SDK exports these error classes:
|
|
|
514
346
|
| --- | --- |
|
|
515
347
|
| `CelestoApiError` | The API returns an error status |
|
|
516
348
|
| `CelestoNetworkError` | The network request fails |
|
|
517
|
-
| `CelestoError` | Base class for
|
|
518
|
-
|
|
519
|
-
Managed agents add an error class per reason an operation can be refused, so you
|
|
520
|
-
can react to the specific one. Each extends `ManagedAgentError`, which extends
|
|
521
|
-
`CelestoApiError`.
|
|
522
|
-
|
|
523
|
-
| Error | When it is used |
|
|
524
|
-
| --- | --- |
|
|
525
|
-
| `BudgetExceededError` | This user has spent their budget for the window |
|
|
526
|
-
| `SessionBusyError` | Another run holds the conversation. Retryable; check `retryAfter` |
|
|
527
|
-
| `IdempotencyConflictError` | This key was already used with a different request |
|
|
528
|
-
| `AgentArchivedError` | The agent no longer takes runs |
|
|
529
|
-
| `ProviderNotConnectedError` | No credential is connected for the agent's model |
|
|
530
|
-
| `SessionAgentMismatchError` | That conversation belongs to a different agent |
|
|
531
|
-
| `SessionEndUserMismatchError` | That conversation belongs to a different user |
|
|
532
|
-
| `ModelRequiresOwnKeyError` | This model runs only on your own provider key |
|
|
533
|
-
| `ConfigKeyNotAllowedError` | The agent config carried an unsupported setting. Thrown by `agents.create()`/`agents.update()` before any request is sent, not by a run |
|
|
349
|
+
| `CelestoError` | Base class for API and network errors |
|
|
350
|
+
| `TypeError` | The SDK rejects unsupported create options or invalid command arguments before sending a request |
|
|
534
351
|
|
|
535
352
|
## Develop Locally
|
|
536
353
|
|
|
537
354
|
If you are contributing and have `npm` installed, run these commands from the
|
|
538
|
-
repository's `ts` directory:
|
|
355
|
+
repository's `ts-cloud` directory:
|
|
539
356
|
|
|
540
357
|
```bash
|
|
541
|
-
npm
|
|
542
|
-
npm
|
|
543
|
-
npm run lint
|
|
544
|
-
npm run build
|
|
358
|
+
npm ci
|
|
359
|
+
npm run check
|
|
545
360
|
```
|
|
546
361
|
|
|
362
|
+
The package test installs the built npm archive and checks it against a local
|
|
363
|
+
HTTP fixture. No Cloud API key is needed. The tested archive and request
|
|
364
|
+
transcript are saved to `artifacts/cloud-sdk/` at the repository root.
|
|
365
|
+
|
|
547
366
|
## License
|
|
548
367
|
|
|
549
368
|
Apache-2.0. The SDK is open source. Use of the Celesto platform is governed by
|