@celestoai/sdk 0.1.4 → 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 +187 -0
  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-XNTZDOKY.js → chunk-52TE4RZV.js} +17 -2
  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-5VVB6N33.js → chunk-P7F52CSQ.js} +2 -2
  13. package/dist/{chunk-JS6BTDP5.js → chunk-THPVQCTE.js} +12 -4
  14. package/dist/chunk-THPVQCTE.js.map +1 -0
  15. package/dist/computers/index.cjs +26 -3
  16. package/dist/computers/index.cjs.map +1 -1
  17. package/dist/computers/index.d.cts +12 -2
  18. package/dist/computers/index.d.ts +12 -2
  19. package/dist/computers/index.js +2 -2
  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 +9 -2
  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 +1045 -5
  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 +54 -4
  34. package/package.json +7 -2
  35. package/dist/chunk-JS6BTDP5.js.map +0 -1
  36. package/dist/chunk-XNTZDOKY.js.map +0 -1
  37. /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.
@@ -288,6 +459,22 @@ The SDK exports these error classes:
288
459
  | `CelestoNetworkError` | The network request fails |
289
460
  | `CelestoError` | Base class for all SDK errors |
290
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
+
291
478
  ## Develop Locally
292
479
 
293
480
  If you are contributing and have `npm` installed, run these commands from the