@celestoai/sdk 0.1.4 → 0.1.6
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 +244 -0
- package/dist/agents/index.cjs +1226 -0
- package/dist/agents/index.cjs.map +1 -0
- package/dist/agents/index.d.cts +2 -0
- package/dist/agents/index.d.ts +2 -0
- package/dist/agents/index.js +60 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/chunk-6Y2YZCPU.js +1007 -0
- package/dist/chunk-6Y2YZCPU.js.map +1 -0
- package/dist/{chunk-XNTZDOKY.js → chunk-B4JRBDUO.js} +80 -4
- package/dist/chunk-B4JRBDUO.js.map +1 -0
- package/dist/{chunk-5VVB6N33.js → chunk-P7F52CSQ.js} +2 -2
- package/dist/{chunk-JS6BTDP5.js → chunk-THPVQCTE.js} +12 -4
- package/dist/chunk-THPVQCTE.js.map +1 -0
- package/dist/computers/index.cjs +89 -5
- package/dist/computers/index.cjs.map +1 -1
- package/dist/computers/index.d.cts +43 -2
- package/dist/computers/index.d.ts +43 -2
- package/dist/computers/index.js +2 -2
- package/dist/{config-BTTpuv_b.d.cts → config-dDPvsH-K.d.cts} +18 -1
- package/dist/{config-BTTpuv_b.d.ts → config-dDPvsH-K.d.ts} +18 -1
- package/dist/gatekeeper/index.cjs +9 -2
- package/dist/gatekeeper/index.cjs.map +1 -1
- package/dist/gatekeeper/index.d.cts +1 -1
- package/dist/gatekeeper/index.d.ts +1 -1
- package/dist/gatekeeper/index.js +2 -2
- package/dist/index-Cii1_OFg.d.ts +696 -0
- package/dist/index-CsEA7qMF.d.cts +696 -0
- package/dist/index.cjs +1108 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -21
- package/dist/index.d.ts +3 -21
- package/dist/index.js +54 -4
- package/package.json +7 -2
- package/dist/chunk-JS6BTDP5.js.map +0 -1
- package/dist/chunk-XNTZDOKY.js.map +0 -1
- /package/dist/{chunk-5VVB6N33.js.map → chunk-P7F52CSQ.js.map} +0 -0
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ 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.
|
|
14
15
|
- Ask a user to approve access to Google Drive through Gatekeeper.
|
|
15
16
|
|
|
16
17
|
Gatekeeper is Celesto's access helper. It lets a user approve which external
|
|
@@ -67,6 +68,143 @@ Run it:
|
|
|
67
68
|
node quickstart.mjs
|
|
68
69
|
```
|
|
69
70
|
|
|
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
|
+
|
|
70
208
|
## Computers
|
|
71
209
|
|
|
72
210
|
A computer is a disposable cloud machine for your app or agent. By default,
|
|
@@ -95,6 +233,39 @@ try {
|
|
|
95
233
|
Omit CPU, memory, or disk fields to use the default size. `disk` accepts MB as
|
|
96
234
|
an integer or strings such as `"2gb"`.
|
|
97
235
|
|
|
236
|
+
Computers are ephemeral by default. To keep `/home/ohm` across stop and restore,
|
|
237
|
+
enable a persistent home when you create the computer:
|
|
238
|
+
|
|
239
|
+
```js
|
|
240
|
+
import { Computer } from "@celestoai/sdk";
|
|
241
|
+
|
|
242
|
+
const computer = await Computer.create({ persistentHome: true });
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
This setting cannot be changed later.
|
|
246
|
+
|
|
247
|
+
### Control Internet Access
|
|
248
|
+
|
|
249
|
+
Internet is on by default. Disable outbound connections when you create a
|
|
250
|
+
computer:
|
|
251
|
+
|
|
252
|
+
```js
|
|
253
|
+
import { Computer } from "@celestoai/sdk";
|
|
254
|
+
|
|
255
|
+
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
|
+
```
|
|
262
|
+
|
|
263
|
+
Commands and terminal sessions still work without internet access. The policy
|
|
264
|
+
survives stop/start and snapshot restore, and it cannot be changed after
|
|
265
|
+
creation. A persistent home uses an external volume, so do not combine
|
|
266
|
+
`networkPolicy: { mode: "off" }` with `persistentHome: true`. Domain and IP
|
|
267
|
+
allowlists are not supported.
|
|
268
|
+
|
|
98
269
|
### Templates
|
|
99
270
|
|
|
100
271
|
Use a template when you want a computer that already has extra tools installed.
|
|
@@ -177,6 +348,9 @@ shown by the Celesto command-line tool: `celesto computer list`.
|
|
|
177
348
|
| `Computer.list()` | List computers in your account |
|
|
178
349
|
| `Computer.get(computerId)` | Get one computer by name or ID |
|
|
179
350
|
| `computer.listCommandHistory()` | List recent commands and their status |
|
|
351
|
+
| `computer.createTerminalSession()` | Create a short-lived fast terminal connection |
|
|
352
|
+
| `computer.createBrowserConnection()` | Create a short-lived CDP connection to browser-agent Chromium |
|
|
353
|
+
| `computer.createDisplayConnection({ mode: "read_only" })` | Create a short-lived RFB display connection |
|
|
180
354
|
| `computer.stop()` | Stop a running computer |
|
|
181
355
|
| `computer.start()` | Start a stopped computer |
|
|
182
356
|
| `computer.delete()` | Delete a computer |
|
|
@@ -233,6 +407,60 @@ ws.on("open", () => ws.send("pwd\n"));
|
|
|
233
407
|
`connection.url` contains a short-lived terminal token. Treat it as a secret and
|
|
234
408
|
create a new terminal session after `connection.expiresAt`.
|
|
235
409
|
|
|
410
|
+
### Browser Automation Connections
|
|
411
|
+
|
|
412
|
+
Use the `browser-agent` template when your application needs an existing
|
|
413
|
+
Chromium browser. `createBrowserConnection()` returns a short-lived Chrome
|
|
414
|
+
DevTools Protocol (CDP) WebSocket URL that Playwright can attach to.
|
|
415
|
+
|
|
416
|
+
Install Playwright Core in the application that runs this code:
|
|
417
|
+
|
|
418
|
+
```bash
|
|
419
|
+
npm install playwright-core
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
Then connect to the browser already running in the Celesto computer:
|
|
423
|
+
|
|
424
|
+
```js
|
|
425
|
+
import { Computer } from "@celestoai/sdk";
|
|
426
|
+
import { chromium } from "playwright-core";
|
|
427
|
+
|
|
428
|
+
const computer = await Computer.create({ templateId: "browser-agent" });
|
|
429
|
+
try {
|
|
430
|
+
const connection = await computer.createBrowserConnection();
|
|
431
|
+
const browser = await chromium.connectOverCDP(connection.url);
|
|
432
|
+
const context = browser.contexts()[0];
|
|
433
|
+
if (!context) throw new Error("Celesto browser did not provide a context");
|
|
434
|
+
const pages = context.pages();
|
|
435
|
+
const page = pages[0] ?? await context.newPage();
|
|
436
|
+
|
|
437
|
+
await page.goto("https://example.com");
|
|
438
|
+
console.log(await page.title());
|
|
439
|
+
} finally {
|
|
440
|
+
await computer.delete();
|
|
441
|
+
}
|
|
442
|
+
```
|
|
443
|
+
|
|
444
|
+
### Display Connections
|
|
445
|
+
|
|
446
|
+
Use `createDisplayConnection()` when a Remote Framebuffer (RFB) client, such as
|
|
447
|
+
the browser-based noVNC viewer, needs to watch the graphical desktop.
|
|
448
|
+
Connections are read-only by default. Pass
|
|
449
|
+
`{ mode: "read_write" }` when the viewer also needs pointer and keyboard control:
|
|
450
|
+
|
|
451
|
+
```js
|
|
452
|
+
import { Computer } from "@celestoai/sdk";
|
|
453
|
+
|
|
454
|
+
const computer = await Computer.get("curie");
|
|
455
|
+
const display = await computer.createDisplayConnection({ mode: "read_only" });
|
|
456
|
+
console.log(display.mode, display.expiresAt);
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
Pass `display.url` to the RFB client before it expires. Browser and display URLs
|
|
460
|
+
contain short-lived secret tokens, so do not log, persist, or share them. Create
|
|
461
|
+
a new connection after a disconnect or expiry. Browser automation and
|
|
462
|
+
read-write display connections require write access to the computer.
|
|
463
|
+
|
|
236
464
|
## Gatekeeper
|
|
237
465
|
|
|
238
466
|
Use Gatekeeper when your app needs user-approved access to an external resource,
|
|
@@ -288,6 +516,22 @@ The SDK exports these error classes:
|
|
|
288
516
|
| `CelestoNetworkError` | The network request fails |
|
|
289
517
|
| `CelestoError` | Base class for all SDK errors |
|
|
290
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 |
|
|
534
|
+
|
|
291
535
|
## Develop Locally
|
|
292
536
|
|
|
293
537
|
If you are contributing and have `npm` installed, run these commands from the
|