@celestoai/sdk 0.1.3 → 0.1.5

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.
Files changed (37) hide show
  1. package/README.md +246 -10
  2. package/dist/agents/index.cjs +1226 -0
  3. package/dist/agents/index.cjs.map +1 -0
  4. package/dist/agents/index.d.cts +2 -0
  5. package/dist/agents/index.d.ts +2 -0
  6. package/dist/agents/index.js +60 -0
  7. package/dist/agents/index.js.map +1 -0
  8. package/dist/{chunk-LPTIN7LO.js → chunk-52TE4RZV.js} +345 -58
  9. package/dist/chunk-52TE4RZV.js.map +1 -0
  10. package/dist/chunk-6Y2YZCPU.js +1007 -0
  11. package/dist/chunk-6Y2YZCPU.js.map +1 -0
  12. package/dist/{chunk-4KVRJSVJ.js → chunk-P7F52CSQ.js} +2 -2
  13. package/dist/{chunk-N3HU6ONW.js → chunk-THPVQCTE.js} +41 -6
  14. package/dist/chunk-THPVQCTE.js.map +1 -0
  15. package/dist/computers/index.cjs +407 -74
  16. package/dist/computers/index.cjs.map +1 -1
  17. package/dist/computers/index.d.cts +96 -15
  18. package/dist/computers/index.d.ts +96 -15
  19. package/dist/computers/index.js +10 -4
  20. package/dist/{config-BTTpuv_b.d.cts → config-dDPvsH-K.d.cts} +18 -1
  21. package/dist/{config-BTTpuv_b.d.ts → config-dDPvsH-K.d.ts} +18 -1
  22. package/dist/gatekeeper/index.cjs +14 -4
  23. package/dist/gatekeeper/index.cjs.map +1 -1
  24. package/dist/gatekeeper/index.d.cts +1 -1
  25. package/dist/gatekeeper/index.d.ts +1 -1
  26. package/dist/gatekeeper/index.js +2 -2
  27. package/dist/index-Cii1_OFg.d.ts +696 -0
  28. package/dist/index-CsEA7qMF.d.cts +696 -0
  29. package/dist/index.cjs +1412 -64
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +3 -21
  32. package/dist/index.d.ts +3 -21
  33. package/dist/index.js +61 -5
  34. package/package.json +11 -3
  35. package/dist/chunk-LPTIN7LO.js.map +0 -1
  36. package/dist/chunk-N3HU6ONW.js.map +0 -1
  37. /package/dist/{chunk-4KVRJSVJ.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
@@ -28,12 +29,21 @@ files or folders your app can use.
28
29
  npm install @celestoai/sdk
29
30
  ```
30
31
 
31
- Set your API key before running SDK examples:
32
+ Sign in once with the Celesto CLI:
32
33
 
33
34
  ```bash
34
- export CELESTO_API_KEY="your-api-key"
35
+ pip install celesto
36
+ celesto auth login
35
37
  ```
36
38
 
39
+ The `Computer` API checks an explicitly passed `token` or `apiKey` first, then `CELESTO_API_KEY` in the shell, the current project's `.env`, and credentials saved by `celesto auth login`. You can use a local `.env` instead of the CLI:
40
+
41
+ ```bash .env
42
+ CELESTO_API_KEY="your-api-key"
43
+ ```
44
+
45
+ Add `.env` to `.gitignore`.
46
+
37
47
  ## Quickstart
38
48
 
39
49
  Create a file named `quickstart.mjs`:
@@ -58,6 +68,143 @@ Run it:
58
68
  node quickstart.mjs
59
69
  ```
60
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
+
61
208
  ## Computers
62
209
 
63
210
  A computer is a disposable cloud machine for your app or agent. By default,
@@ -86,6 +233,39 @@ try {
86
233
  Omit CPU, memory, or disk fields to use the default size. `disk` accepts MB as
87
234
  an integer or strings such as `"2gb"`.
88
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
+
89
269
  ### Templates
90
270
 
91
271
  Use a template when you want a computer that already has extra tools installed.
@@ -138,6 +318,26 @@ try {
138
318
  }
139
319
  ```
140
320
 
321
+ Stream output while the command is running:
322
+
323
+ ```js
324
+ import { Computer } from "@celestoai/sdk";
325
+
326
+ const computer = await Computer.get("curie");
327
+ const controller = new AbortController();
328
+
329
+ for await (const event of computer.runStream("npm test", {
330
+ timeout: 300,
331
+ signal: controller.signal,
332
+ })) {
333
+ if (event.type === "stdout") process.stdout.write(event.data);
334
+ if (event.type === "stderr") process.stderr.write(event.data);
335
+ if (event.type === "exit") console.log(`Exit code: ${event.exitCode}`);
336
+ }
337
+ ```
338
+
339
+ Call `controller.abort()` to stop the stream and the remote command.
340
+
141
341
  ### Manage Computers
142
342
 
143
343
  `computerId` can be `computer.id` from `Computer.create()` or a computer name
@@ -147,6 +347,7 @@ shown by the Celesto command-line tool: `celesto computer list`.
147
347
  | --- | --- |
148
348
  | `Computer.list()` | List computers in your account |
149
349
  | `Computer.get(computerId)` | Get one computer by name or ID |
350
+ | `computer.listCommandHistory()` | List recent commands and their status |
150
351
  | `computer.stop()` | Stop a running computer |
151
352
  | `computer.start()` | Start a stopped computer |
152
353
  | `computer.delete()` | Delete a computer |
@@ -175,13 +376,33 @@ await computer.unpublishPort(8000);
175
376
 
176
377
  ### Terminal Connections
177
378
 
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.
379
+ Use `createTerminalSession()` when you are building an interactive terminal.
380
+ Celesto returns a short-lived URL that connects directly to the fast terminal
381
+ gateway instead of sending terminal traffic through the control plane. Creating
382
+ a terminal session requires write access to the computer.
383
+
384
+ For Node.js, first install a WebSocket client:
385
+
386
+ ```bash
387
+ npm install ws
388
+ ```
389
+
390
+ Then connect with the authenticated URL:
391
+
392
+ ```js
393
+ import { Computer } from "@celestoai/sdk";
394
+ import WebSocket from "ws";
395
+
396
+ const computer = await Computer.get("curie");
397
+ const connection = await computer.createTerminalSession();
398
+ const ws = new WebSocket(connection.url);
399
+
400
+ ws.on("message", (data) => process.stdout.write(data));
401
+ ws.on("open", () => ws.send("pwd\n"));
402
+ ```
182
403
 
183
- The SDK does not install a WebSocket package for you. Use any WebSocket library
184
- that supports custom headers.
404
+ `connection.url` contains a short-lived terminal token. Treat it as a secret and
405
+ create a new terminal session after `connection.expiresAt`.
185
406
 
186
407
  ## Gatekeeper
187
408
 
@@ -224,8 +445,7 @@ Full Gatekeeper docs: https://docs.celesto.ai/celesto-sdk/gatekeeper
224
445
  | `headers` | Extra headers to send with every request |
225
446
 
226
447
  Pass these options as the second argument to `Computer.create()` or
227
- `Computer.get()`. Gatekeeper clients accept the same options in their
228
- constructor.
448
+ `Computer.get()`. An explicit `token` or `apiKey` takes precedence over local credential discovery. Gatekeeper clients accept the same options in their constructor and require an explicit token.
229
449
 
230
450
  JWT is a signed login token. Most users should use a Celesto API key.
231
451
 
@@ -239,6 +459,22 @@ The SDK exports these error classes:
239
459
  | `CelestoNetworkError` | The network request fails |
240
460
  | `CelestoError` | Base class for all SDK errors |
241
461
 
462
+ Managed agents add an error class per reason an operation can be refused, so you
463
+ can react to the specific one. Each extends `ManagedAgentError`, which extends
464
+ `CelestoApiError`.
465
+
466
+ | Error | When it is used |
467
+ | --- | --- |
468
+ | `BudgetExceededError` | This user has spent their budget for the window |
469
+ | `SessionBusyError` | Another run holds the conversation. Retryable; check `retryAfter` |
470
+ | `IdempotencyConflictError` | This key was already used with a different request |
471
+ | `AgentArchivedError` | The agent no longer takes runs |
472
+ | `ProviderNotConnectedError` | No credential is connected for the agent's model |
473
+ | `SessionAgentMismatchError` | That conversation belongs to a different agent |
474
+ | `SessionEndUserMismatchError` | That conversation belongs to a different user |
475
+ | `ModelRequiresOwnKeyError` | This model runs only on your own provider key |
476
+ | `ConfigKeyNotAllowedError` | The agent config carried an unsupported setting. Thrown by `agents.create()`/`agents.update()` before any request is sent, not by a run |
477
+
242
478
  ## Develop Locally
243
479
 
244
480
  If you are contributing and have `npm` installed, run these commands from the