@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
|
@@ -0,0 +1,696 @@
|
|
|
1
|
+
import { a as RequestContext, b as RequestOptions, C as ClientConfig, R as RequestOverrides } from './config-dDPvsH-K.cjs';
|
|
2
|
+
|
|
3
|
+
declare const request: <T>(ctx: RequestContext, options: RequestOptions) => Promise<T>;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Types for managed agents: agents, runs, sessions, and end users.
|
|
7
|
+
*
|
|
8
|
+
* Money is a `DecimalString`, never a `number`. See the note on that type.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* An amount of money, as a fixed-scale decimal string such as `"0.000450"`.
|
|
12
|
+
*
|
|
13
|
+
* A single generation can cost millionths of a dollar, and a JavaScript
|
|
14
|
+
* `number` cannot hold those exactly — `0.1 + 0.2` is the classic example, and
|
|
15
|
+
* a month of agent runs is that mistake ten thousand times over. The API sends
|
|
16
|
+
* these as strings and this SDK keeps them as strings. Compare and display
|
|
17
|
+
* them as-is, and if you must do arithmetic, use a decimal library
|
|
18
|
+
* (`decimal.js`, `big.js`) rather than `parseFloat`.
|
|
19
|
+
*/
|
|
20
|
+
type DecimalString = string;
|
|
21
|
+
/** Lets a known set autocomplete without closing it to future values. */
|
|
22
|
+
type Open<T extends string> = T | (string & {});
|
|
23
|
+
/** The lifecycle of an agent. */
|
|
24
|
+
type AgentStatus = Open<"active" | "archived">;
|
|
25
|
+
/** Where a run ended up. */
|
|
26
|
+
type RunStatus = Open<"queued" | "running" | "completed" | "failed">;
|
|
27
|
+
type ReasoningEffort = "minimal" | "low" | "medium" | "high";
|
|
28
|
+
type Verbosity = "low" | "medium" | "high";
|
|
29
|
+
/**
|
|
30
|
+
* Generation settings an agent may carry.
|
|
31
|
+
*
|
|
32
|
+
* This is a closed set: anything else is refused by the API with a 422, so
|
|
33
|
+
* these are the only keys TypeScript will accept, and the SDK checks again
|
|
34
|
+
* before sending.
|
|
35
|
+
*/
|
|
36
|
+
interface AgentConfig {
|
|
37
|
+
temperature?: number;
|
|
38
|
+
topP?: number;
|
|
39
|
+
maxTokens?: number;
|
|
40
|
+
maxOutputTokens?: number;
|
|
41
|
+
frequencyPenalty?: number;
|
|
42
|
+
presencePenalty?: number;
|
|
43
|
+
seed?: number;
|
|
44
|
+
stop?: string | string[];
|
|
45
|
+
reasoningEffort?: ReasoningEffort;
|
|
46
|
+
verbosity?: Verbosity;
|
|
47
|
+
maxTurns?: number;
|
|
48
|
+
}
|
|
49
|
+
/** A named, versioned agent definition. */
|
|
50
|
+
interface Agent {
|
|
51
|
+
id: string;
|
|
52
|
+
object: string;
|
|
53
|
+
name: string;
|
|
54
|
+
description: string | null;
|
|
55
|
+
model: string;
|
|
56
|
+
instructions: string | null;
|
|
57
|
+
config: AgentConfig | null;
|
|
58
|
+
version: number;
|
|
59
|
+
currentVersionId: string;
|
|
60
|
+
projectId: string;
|
|
61
|
+
organizationId: string;
|
|
62
|
+
status: AgentStatus;
|
|
63
|
+
createdAt: string;
|
|
64
|
+
updatedAt: string;
|
|
65
|
+
}
|
|
66
|
+
/** One immutable snapshot of an agent definition. */
|
|
67
|
+
interface AgentVersion {
|
|
68
|
+
id: string;
|
|
69
|
+
object: string;
|
|
70
|
+
agentId: string;
|
|
71
|
+
version: number;
|
|
72
|
+
name: string;
|
|
73
|
+
description: string | null;
|
|
74
|
+
model: string;
|
|
75
|
+
instructions: string | null;
|
|
76
|
+
config: AgentConfig | null;
|
|
77
|
+
createdAt: string;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* One page of results.
|
|
81
|
+
*
|
|
82
|
+
* There is no total count anywhere in this API. `hasMore` is how you know
|
|
83
|
+
* whether to ask for another page.
|
|
84
|
+
*/
|
|
85
|
+
interface Page<T> {
|
|
86
|
+
data: T[];
|
|
87
|
+
hasMore: boolean;
|
|
88
|
+
}
|
|
89
|
+
/** What archiving an agent returns. */
|
|
90
|
+
interface ArchivedAgent {
|
|
91
|
+
id: string;
|
|
92
|
+
status: AgentStatus;
|
|
93
|
+
}
|
|
94
|
+
interface CreateAgentParams {
|
|
95
|
+
/** Display name, 1-255 characters. */
|
|
96
|
+
name: string;
|
|
97
|
+
/** Model to run, such as `"openai/gpt-5.4-mini"`. Pinned per version. */
|
|
98
|
+
model: string;
|
|
99
|
+
/** The system prompt. */
|
|
100
|
+
instructions?: string;
|
|
101
|
+
/** Free text for your own dashboard, up to 1000 characters. */
|
|
102
|
+
description?: string;
|
|
103
|
+
/** Generation settings. Only the keys of {@link AgentConfig} are accepted. */
|
|
104
|
+
config?: AgentConfig;
|
|
105
|
+
/** Project to scope the agent to. Defaults to your default project. */
|
|
106
|
+
projectId?: string;
|
|
107
|
+
}
|
|
108
|
+
/** A full replacement of an agent's definition, which cuts a new version. */
|
|
109
|
+
type UpdateAgentParams = Omit<CreateAgentParams, "projectId">;
|
|
110
|
+
interface ListAgentsParams {
|
|
111
|
+
projectId?: string;
|
|
112
|
+
includeArchived?: boolean;
|
|
113
|
+
/** Page size, 1-100. */
|
|
114
|
+
limit?: number;
|
|
115
|
+
offset?: number;
|
|
116
|
+
}
|
|
117
|
+
interface ListAgentVersionsParams {
|
|
118
|
+
/** Page size, 1-100. */
|
|
119
|
+
limit?: number;
|
|
120
|
+
offset?: number;
|
|
121
|
+
}
|
|
122
|
+
/** Tokens and money spent by a run or a single generation. */
|
|
123
|
+
interface RunUsage {
|
|
124
|
+
inputTokens: number;
|
|
125
|
+
outputTokens: number;
|
|
126
|
+
totalTokens: number;
|
|
127
|
+
costUsd: DecimalString;
|
|
128
|
+
}
|
|
129
|
+
/** A run of an agent, on behalf of one end user. */
|
|
130
|
+
interface Run {
|
|
131
|
+
runId: string;
|
|
132
|
+
object: string;
|
|
133
|
+
status: RunStatus;
|
|
134
|
+
errorCode: string | null;
|
|
135
|
+
error: string | null;
|
|
136
|
+
output: string | null;
|
|
137
|
+
usage: RunUsage;
|
|
138
|
+
agentId: string;
|
|
139
|
+
agentVersionId: string;
|
|
140
|
+
sessionId: string;
|
|
141
|
+
endUserId: string;
|
|
142
|
+
turnCount: number | null;
|
|
143
|
+
createdAt: string;
|
|
144
|
+
startedAt: string | null;
|
|
145
|
+
endedAt: string | null;
|
|
146
|
+
}
|
|
147
|
+
interface CreateRunParams {
|
|
148
|
+
/** What the end user said. */
|
|
149
|
+
input: string;
|
|
150
|
+
/**
|
|
151
|
+
* Your own identifier for the person this run acts for, such as
|
|
152
|
+
* `"usr_8837"`. Celesto stores it as you send it and never parses it.
|
|
153
|
+
*/
|
|
154
|
+
endUserId: string;
|
|
155
|
+
/** Continue an existing conversation. Omit to start a new one. */
|
|
156
|
+
sessionId?: string;
|
|
157
|
+
/** Stop the agent after this many turns, 1-100. */
|
|
158
|
+
maxTurns?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Send the same key to retry safely: a replay returns the stored run
|
|
161
|
+
* instead of running the agent again.
|
|
162
|
+
*/
|
|
163
|
+
idempotencyKey?: string;
|
|
164
|
+
/**
|
|
165
|
+
* How many times to retry when the session is busy. Sessions run one at a
|
|
166
|
+
* time, so a second run on the same session is refused until the first
|
|
167
|
+
* settles. An idempotency key is generated for you when you ask for
|
|
168
|
+
* retries, so a retry cannot charge the end user twice.
|
|
169
|
+
*/
|
|
170
|
+
maxRetries?: number;
|
|
171
|
+
}
|
|
172
|
+
/** One stored event, as returned by the events endpoint. */
|
|
173
|
+
interface StoredRunEvent {
|
|
174
|
+
seq: number;
|
|
175
|
+
event: string;
|
|
176
|
+
data: Record<string, unknown>;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* One page of stored run events.
|
|
180
|
+
*
|
|
181
|
+
* This endpoint reports no `hasMore`: page with `afterSeq` set to the last
|
|
182
|
+
* `seq` you saw, and stop when a page comes back short.
|
|
183
|
+
*/
|
|
184
|
+
interface RunEventsPage {
|
|
185
|
+
data: StoredRunEvent[];
|
|
186
|
+
eventsVersion: string;
|
|
187
|
+
}
|
|
188
|
+
interface ListRunEventsParams {
|
|
189
|
+
/** Return events after this sequence number. */
|
|
190
|
+
afterSeq?: number;
|
|
191
|
+
/** Page size, 1-500. */
|
|
192
|
+
limit?: number;
|
|
193
|
+
}
|
|
194
|
+
/** A conversation between one end user and one agent. */
|
|
195
|
+
interface Session {
|
|
196
|
+
id: string;
|
|
197
|
+
object: string;
|
|
198
|
+
agentId: string | null;
|
|
199
|
+
endUserId: string;
|
|
200
|
+
status: string;
|
|
201
|
+
messageCount: number;
|
|
202
|
+
lastMessageAt: string | null;
|
|
203
|
+
createdAt: string;
|
|
204
|
+
}
|
|
205
|
+
/** One entry in a session transcript. */
|
|
206
|
+
interface SessionMessage {
|
|
207
|
+
seq: number;
|
|
208
|
+
role: string | null;
|
|
209
|
+
item: Record<string, unknown>;
|
|
210
|
+
createdAt: string;
|
|
211
|
+
}
|
|
212
|
+
/** A session together with a page of its messages. */
|
|
213
|
+
interface SessionTranscript {
|
|
214
|
+
session: Session;
|
|
215
|
+
messages: SessionMessage[];
|
|
216
|
+
}
|
|
217
|
+
interface ListSessionsParams {
|
|
218
|
+
/** Your own identifier for the end user. */
|
|
219
|
+
endUserId: string;
|
|
220
|
+
/** Page size, 1-100. */
|
|
221
|
+
limit?: number;
|
|
222
|
+
offset?: number;
|
|
223
|
+
}
|
|
224
|
+
interface GetSessionParams {
|
|
225
|
+
/** How many messages to return, 1-200. */
|
|
226
|
+
limit?: number;
|
|
227
|
+
/** Return messages before this sequence number. */
|
|
228
|
+
beforeSeq?: number;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Spend and cap for one end user, in the current 30-day window.
|
|
232
|
+
*
|
|
233
|
+
* The window is anchored to that user's first activity, not the calendar
|
|
234
|
+
* month. A `capUsd` of `null` means no cap.
|
|
235
|
+
*/
|
|
236
|
+
interface EndUserBudget {
|
|
237
|
+
capUsd: DecimalString | null;
|
|
238
|
+
source: string;
|
|
239
|
+
windowStart: string;
|
|
240
|
+
windowResetsAt: string;
|
|
241
|
+
spentUsd: DecimalString;
|
|
242
|
+
remainingUsd: DecimalString | null;
|
|
243
|
+
}
|
|
244
|
+
/** One of your users, addressed by your own identifier for them. */
|
|
245
|
+
interface EndUser {
|
|
246
|
+
endUserId: string;
|
|
247
|
+
object: string;
|
|
248
|
+
firstActivityAt: string;
|
|
249
|
+
budget: EndUserBudget;
|
|
250
|
+
metadata: Record<string, unknown> | null;
|
|
251
|
+
createdAt: string;
|
|
252
|
+
}
|
|
253
|
+
interface UpdateEndUserParams {
|
|
254
|
+
/**
|
|
255
|
+
* Spend cap for the rolling 30-day window. A decimal string, never a
|
|
256
|
+
* `number` — `0.1 + 0.2` would go out as `"0.30000000000000004"`, and the
|
|
257
|
+
* API refuses it. `null` clears the override and falls back to the
|
|
258
|
+
* organization default. Omit the field to leave it alone.
|
|
259
|
+
*/
|
|
260
|
+
budgetCapUsd?: DecimalString | null;
|
|
261
|
+
/** Free-form JSON of your own. `null` clears it. */
|
|
262
|
+
metadata?: Record<string, unknown> | null;
|
|
263
|
+
}
|
|
264
|
+
/** Organization-wide defaults for managed agents. */
|
|
265
|
+
interface RuntimeSettings {
|
|
266
|
+
organizationId: string;
|
|
267
|
+
defaultEndUserBudgetUsd: DecimalString | null;
|
|
268
|
+
}
|
|
269
|
+
interface UpdateRuntimeSettingsParams {
|
|
270
|
+
/**
|
|
271
|
+
* The budget every end user starts with, as a decimal string. `null`
|
|
272
|
+
* removes the default.
|
|
273
|
+
*/
|
|
274
|
+
defaultEndUserBudgetUsd?: DecimalString | null;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* The run event stream.
|
|
279
|
+
*
|
|
280
|
+
* A run is an append-only log, and streaming is tailing it. The wire format is
|
|
281
|
+
* Server-Sent Events and the event names are a versioned, closed set:
|
|
282
|
+
*
|
|
283
|
+
* `run.started`, `message.delta`, `message.completed`, `tool.call`,
|
|
284
|
+
* `tool.result`, `usage`, `run.completed`, `run.failed`.
|
|
285
|
+
*
|
|
286
|
+
* **Unknown event names are ignored.** That is the forward-compatibility
|
|
287
|
+
* contract: the server may add an event tomorrow and today's SDK must not
|
|
288
|
+
* break on it. {@link toRunEvent} returns `undefined` for anything it does not
|
|
289
|
+
* know, and {@link parseRunEvents} drops those frames.
|
|
290
|
+
*
|
|
291
|
+
* Every frame except `message.delta` carries an `id:` — the event's sequence
|
|
292
|
+
* number. Deltas are not stored, so they are not positions you can resume
|
|
293
|
+
* from, and their `seq` is `null`.
|
|
294
|
+
*/
|
|
295
|
+
|
|
296
|
+
/** The event contract this SDK was written against. */
|
|
297
|
+
declare const EVENTS_VERSION = "1";
|
|
298
|
+
/** Response header naming the server's event contract version. */
|
|
299
|
+
declare const EVENTS_VERSION_HEADER = "X-Celesto-Events-Version";
|
|
300
|
+
/** Every event name this SDK understands. */
|
|
301
|
+
declare const KNOWN_EVENTS: readonly ["run.started", "message.delta", "message.completed", "tool.call", "tool.result", "usage", "run.completed", "run.failed"];
|
|
302
|
+
type RunEventName = (typeof KNOWN_EVENTS)[number];
|
|
303
|
+
/** One raw Server-Sent Events frame, before it is understood. */
|
|
304
|
+
interface SseFrame {
|
|
305
|
+
event?: string;
|
|
306
|
+
data: string;
|
|
307
|
+
id?: string;
|
|
308
|
+
}
|
|
309
|
+
interface RunStartedData {
|
|
310
|
+
runId: string;
|
|
311
|
+
agentId: string;
|
|
312
|
+
agentVersionId: string;
|
|
313
|
+
sessionId: string;
|
|
314
|
+
endUserId: string;
|
|
315
|
+
model: string;
|
|
316
|
+
createdAt: string;
|
|
317
|
+
}
|
|
318
|
+
interface MessageData {
|
|
319
|
+
text: string | null;
|
|
320
|
+
turn: number | null;
|
|
321
|
+
}
|
|
322
|
+
interface ToolCallData {
|
|
323
|
+
callId: string | null;
|
|
324
|
+
name: string | null;
|
|
325
|
+
args: unknown;
|
|
326
|
+
turn: number | null;
|
|
327
|
+
}
|
|
328
|
+
interface ToolResultData {
|
|
329
|
+
callId: string | null;
|
|
330
|
+
name: string | null;
|
|
331
|
+
turn: number | null;
|
|
332
|
+
/** Present when the tool succeeded. */
|
|
333
|
+
result?: unknown;
|
|
334
|
+
/** Present instead of `result` when the tool failed. */
|
|
335
|
+
error?: unknown;
|
|
336
|
+
}
|
|
337
|
+
interface UsageData extends RunUsage {
|
|
338
|
+
turn: number | null;
|
|
339
|
+
model: string | null;
|
|
340
|
+
}
|
|
341
|
+
interface RunCompletedData {
|
|
342
|
+
runId: string;
|
|
343
|
+
status: RunStatus;
|
|
344
|
+
output: string | null;
|
|
345
|
+
turnCount: number | null;
|
|
346
|
+
usage: RunUsage;
|
|
347
|
+
}
|
|
348
|
+
interface RunFailedData {
|
|
349
|
+
runId: string;
|
|
350
|
+
status: RunStatus;
|
|
351
|
+
errorCode: string | null;
|
|
352
|
+
error: string | null;
|
|
353
|
+
turnCount: number | null;
|
|
354
|
+
usage: RunUsage;
|
|
355
|
+
}
|
|
356
|
+
interface BaseEvent<Name extends RunEventName, Data> {
|
|
357
|
+
name: Name;
|
|
358
|
+
/** Position in the run's log, or `null` for unstored `message.delta`. */
|
|
359
|
+
seq: number | null;
|
|
360
|
+
data: Data;
|
|
361
|
+
}
|
|
362
|
+
/** One thing that happened during a run. Switch on `name`. */
|
|
363
|
+
type RunEvent = BaseEvent<"run.started", RunStartedData> | BaseEvent<"message.delta", MessageData> | BaseEvent<"message.completed", MessageData> | BaseEvent<"tool.call", ToolCallData> | BaseEvent<"tool.result", ToolResultData> | BaseEvent<"usage", UsageData> | BaseEvent<"run.completed", RunCompletedData> | BaseEvent<"run.failed", RunFailedData>;
|
|
364
|
+
/**
|
|
365
|
+
* Turn one raw frame into a run event, or `undefined` to ignore it.
|
|
366
|
+
*
|
|
367
|
+
* Returns `undefined` for comments, keep-alives, and — deliberately — event
|
|
368
|
+
* names this SDK does not know.
|
|
369
|
+
*/
|
|
370
|
+
declare const toRunEvent: (frame: SseFrame) => RunEvent | undefined;
|
|
371
|
+
/** True for `run.completed` and `run.failed`: the run is settled. */
|
|
372
|
+
declare const isTerminal: (event: RunEvent) => boolean;
|
|
373
|
+
/** The text an event carries, or `""`. */
|
|
374
|
+
declare const eventText: (event: RunEvent) => string;
|
|
375
|
+
/**
|
|
376
|
+
* Feeds SSE text in, gets frames out. Chunk boundaries land anywhere, so the
|
|
377
|
+
* decoder holds a buffer between pushes.
|
|
378
|
+
*/
|
|
379
|
+
declare class SseDecoder {
|
|
380
|
+
private buffer;
|
|
381
|
+
push(chunk: string): SseFrame[];
|
|
382
|
+
/** Anything left in the buffer when the stream ends. */
|
|
383
|
+
flush(): SseFrame[];
|
|
384
|
+
private findBoundary;
|
|
385
|
+
}
|
|
386
|
+
/** Parse a whole SSE body into frames. */
|
|
387
|
+
declare const parseSseFrames: (body: string) => SseFrame[];
|
|
388
|
+
/** Parse a whole SSE body into run events, ignoring unknown event names. */
|
|
389
|
+
declare const parseRunEvents: (body: string) => RunEvent[];
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Managed agents: run your agents for your end users.
|
|
393
|
+
*
|
|
394
|
+
* You define an agent once — a name, a model, instructions — and then run it
|
|
395
|
+
* on behalf of *your* users. Every run names the end user it acts for, using
|
|
396
|
+
* your own identifier for them (`"usr_8837"`, `"alice@acme.com"`). Celesto
|
|
397
|
+
* keeps that user's spend, budget, and transcript together, so "what has this
|
|
398
|
+
* user spent this month?" is one call.
|
|
399
|
+
*/
|
|
400
|
+
|
|
401
|
+
/** The keys an agent `config` may contain. */
|
|
402
|
+
declare const ALLOWED_CONFIG_KEYS: (keyof AgentConfig)[];
|
|
403
|
+
declare abstract class BaseClient {
|
|
404
|
+
protected readonly config: ClientConfig;
|
|
405
|
+
constructor(config: ClientConfig);
|
|
406
|
+
/** Every call goes through here, so refusals arrive already typed. */
|
|
407
|
+
protected call<T>(options: Parameters<typeof request>[1]): Promise<T>;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Create and version the agents your end users run.
|
|
411
|
+
*
|
|
412
|
+
* An agent is a named pointer at an immutable definition. Every update cuts a
|
|
413
|
+
* new version and moves the pointer; runs pin the version they started with,
|
|
414
|
+
* so a change never rewrites history. Rolling back moves the pointer and cuts
|
|
415
|
+
* nothing.
|
|
416
|
+
*/
|
|
417
|
+
declare class AgentsClient extends BaseClient {
|
|
418
|
+
/** Create an agent, at version 1. */
|
|
419
|
+
create(params: CreateAgentParams, options?: RequestOverrides): Promise<Agent>;
|
|
420
|
+
/** List one page of agents. Check `hasMore`; there is no total count. */
|
|
421
|
+
list(params?: ListAgentsParams, options?: RequestOverrides): Promise<Page<Agent>>;
|
|
422
|
+
/** Yield every agent, fetching pages as you go. */
|
|
423
|
+
listAll(params?: Omit<ListAgentsParams, "offset">, options?: RequestOverrides): AsyncGenerator<Agent>;
|
|
424
|
+
/** Get an agent, at its current version. */
|
|
425
|
+
get(agentId: string, options?: RequestOverrides): Promise<Agent>;
|
|
426
|
+
/**
|
|
427
|
+
* Replace an agent's definition, which cuts a new version.
|
|
428
|
+
*
|
|
429
|
+
* This is a full replacement, not a patch: whatever you leave out is
|
|
430
|
+
* cleared. Read the agent first if you only mean to change one field.
|
|
431
|
+
*/
|
|
432
|
+
update(agentId: string, params: UpdateAgentParams, options?: RequestOverrides): Promise<Agent>;
|
|
433
|
+
/**
|
|
434
|
+
* Archive an agent. Archived agents refuse new runs.
|
|
435
|
+
*
|
|
436
|
+
* Past runs, versions, and transcripts stay readable.
|
|
437
|
+
*/
|
|
438
|
+
archive(agentId: string, options?: RequestOverrides): Promise<ArchivedAgent>;
|
|
439
|
+
/** List one page of an agent's versions. */
|
|
440
|
+
listVersions(agentId: string, params?: ListAgentVersionsParams, options?: RequestOverrides): Promise<Page<AgentVersion>>;
|
|
441
|
+
/** Yield every version of an agent, fetching pages as you go. */
|
|
442
|
+
listAllVersions(agentId: string, params?: Omit<ListAgentVersionsParams, "offset">, options?: RequestOverrides): AsyncGenerator<AgentVersion>;
|
|
443
|
+
/** Get one version of an agent by its number. */
|
|
444
|
+
getVersion(agentId: string, versionNumber: number, options?: RequestOverrides): Promise<AgentVersion>;
|
|
445
|
+
/**
|
|
446
|
+
* Roll back to an earlier version.
|
|
447
|
+
*
|
|
448
|
+
* This moves the agent's pointer; it does not cut a new version and nothing
|
|
449
|
+
* is lost.
|
|
450
|
+
*/
|
|
451
|
+
activateVersion(agentId: string, versionNumber: number, options?: RequestOverrides): Promise<Agent>;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Run an agent for one of your end users, and read what happened.
|
|
455
|
+
*
|
|
456
|
+
* Two ways to run, so the return type never depends on an argument:
|
|
457
|
+
* `create()` resolves with the settled run, `stream()` yields events.
|
|
458
|
+
*/
|
|
459
|
+
declare class RunsClient extends BaseClient {
|
|
460
|
+
private runBody;
|
|
461
|
+
/** Retrying without a key can charge twice, so make one when retrying. */
|
|
462
|
+
private idempotencyKey;
|
|
463
|
+
/**
|
|
464
|
+
* Run an agent and wait for the answer.
|
|
465
|
+
*
|
|
466
|
+
* @throws {@link BudgetExceededError} when the end user has spent their budget.
|
|
467
|
+
* @throws {@link SessionBusyError} when another run holds the session.
|
|
468
|
+
*/
|
|
469
|
+
create(agentId: string, params: CreateRunParams, options?: RequestOverrides): Promise<Run>;
|
|
470
|
+
/**
|
|
471
|
+
* Run an agent and watch it work.
|
|
472
|
+
*
|
|
473
|
+
* Yields events as the run happens: text as it is generated, each tool call
|
|
474
|
+
* and its result, what each generation cost, and finally `run.completed` or
|
|
475
|
+
* `run.failed`. Event names this SDK does not know are ignored, so a newer
|
|
476
|
+
* server cannot break an older client.
|
|
477
|
+
*
|
|
478
|
+
* A failed run arrives as a `run.failed` event, not a thrown error —
|
|
479
|
+
* including a run stopped mid-stream because the end user ran out of
|
|
480
|
+
* budget. Errors are thrown for runs that never started.
|
|
481
|
+
*
|
|
482
|
+
* A replay of an idempotency key omits `message.delta`: partial text is
|
|
483
|
+
* never stored, so there is nothing to replay.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* ```ts
|
|
487
|
+
* for await (const event of celesto.runs.stream(agent.id, {
|
|
488
|
+
* input: "Where is my order?",
|
|
489
|
+
* endUserId: "usr_8837",
|
|
490
|
+
* })) {
|
|
491
|
+
* if (event.name === "message.delta") process.stdout.write(event.data.text ?? "");
|
|
492
|
+
* }
|
|
493
|
+
* ```
|
|
494
|
+
*/
|
|
495
|
+
stream(agentId: string, params: CreateRunParams, options?: RequestOverrides): AsyncGenerator<RunEvent>;
|
|
496
|
+
/** Get a run by id, settled or not. */
|
|
497
|
+
get(runId: string, options?: RequestOverrides): Promise<Run>;
|
|
498
|
+
/**
|
|
499
|
+
* Read one page of a run's stored events.
|
|
500
|
+
*
|
|
501
|
+
* The same event contract as {@link stream}, read back after the fact,
|
|
502
|
+
* minus `message.delta` — partial text is never stored.
|
|
503
|
+
*/
|
|
504
|
+
listEvents(runId: string, params?: ListRunEventsParams, options?: RequestOverrides): Promise<RunEventsPage>;
|
|
505
|
+
/** Yield every stored event of a run, in order, fetching pages as you go. */
|
|
506
|
+
listAllEvents(runId: string, params?: ListRunEventsParams, options?: RequestOverrides): AsyncGenerator<StoredRunEvent>;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* The conversations your end users have had.
|
|
510
|
+
*
|
|
511
|
+
* A session holds one end user's transcript with one agent. Runs on the same
|
|
512
|
+
* session share history; runs without a session get a fresh one.
|
|
513
|
+
*/
|
|
514
|
+
declare class SessionsClient extends BaseClient {
|
|
515
|
+
/** List one page of an end user's sessions. */
|
|
516
|
+
list(params: ListSessionsParams, options?: RequestOverrides): Promise<Page<Session>>;
|
|
517
|
+
/** Yield every session for an end user, fetching pages as you go. */
|
|
518
|
+
listAll(params: Omit<ListSessionsParams, "offset">, options?: RequestOverrides): AsyncGenerator<Session>;
|
|
519
|
+
/**
|
|
520
|
+
* Get a session and a page of its transcript.
|
|
521
|
+
*
|
|
522
|
+
* The transcript pages backwards: `beforeSeq` asks for what came before a
|
|
523
|
+
* message you already have.
|
|
524
|
+
*/
|
|
525
|
+
get(sessionId: string, params?: GetSessionParams, options?: RequestOverrides): Promise<SessionTranscript>;
|
|
526
|
+
/** Yield a session's messages newest first, fetching pages as you go. */
|
|
527
|
+
listAllMessages(sessionId: string, params?: GetSessionParams, options?: RequestOverrides): AsyncGenerator<SessionMessage>;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Your users: what they have spent, and what they are allowed to spend.
|
|
531
|
+
*
|
|
532
|
+
* An end user is addressed by *your* identifier for them. You never store a
|
|
533
|
+
* Celesto id, and the record is created the first time you run an agent for
|
|
534
|
+
* them.
|
|
535
|
+
*/
|
|
536
|
+
declare class EndUsersClient extends BaseClient {
|
|
537
|
+
/** Get an end user's budget and activity. */
|
|
538
|
+
get(endUserId: string, options?: RequestOverrides): Promise<EndUser>;
|
|
539
|
+
/**
|
|
540
|
+
* Set an end user's budget override or metadata, creating them if needed.
|
|
541
|
+
*
|
|
542
|
+
* Fields you do not pass are left alone. Passing `null` clears the field:
|
|
543
|
+
* `budgetCapUsd: null` drops back to your organization's default budget.
|
|
544
|
+
*/
|
|
545
|
+
update(endUserId: string, params: UpdateEndUserParams, options?: RequestOverrides): Promise<EndUser>;
|
|
546
|
+
/** Drop an end user's override, back to the organization default. */
|
|
547
|
+
clearBudget(endUserId: string, options?: RequestOverrides): Promise<EndUser>;
|
|
548
|
+
}
|
|
549
|
+
/** Organization-wide defaults for managed agents. */
|
|
550
|
+
declare class RuntimeSettingsClient extends BaseClient {
|
|
551
|
+
/** Read the default budget every end user starts with. */
|
|
552
|
+
get(options?: RequestOverrides): Promise<RuntimeSettings>;
|
|
553
|
+
/**
|
|
554
|
+
* Set the default budget every end user starts with.
|
|
555
|
+
*
|
|
556
|
+
* Pass `null` to remove the default, which leaves end users uncapped unless
|
|
557
|
+
* they have their own override.
|
|
558
|
+
*/
|
|
559
|
+
update(params: UpdateRuntimeSettingsParams, options?: RequestOverrides): Promise<RuntimeSettings>;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Run your agents for your end users.
|
|
563
|
+
*
|
|
564
|
+
* @example
|
|
565
|
+
* ```ts
|
|
566
|
+
* const celesto = new ManagedAgentsClient({ apiKey: process.env.CELESTO_API_KEY });
|
|
567
|
+
* const agent = await celesto.agents.create({ name: "support-bot", model: "openai/gpt-5.4-mini" });
|
|
568
|
+
* const run = await celesto.runs.create(agent.id, {
|
|
569
|
+
* input: "Where is my order?",
|
|
570
|
+
* endUserId: "usr_8837",
|
|
571
|
+
* });
|
|
572
|
+
* console.log(run.output, run.usage.costUsd);
|
|
573
|
+
* ```
|
|
574
|
+
*/
|
|
575
|
+
declare class ManagedAgentsClient {
|
|
576
|
+
readonly agents: AgentsClient;
|
|
577
|
+
readonly runs: RunsClient;
|
|
578
|
+
readonly sessions: SessionsClient;
|
|
579
|
+
readonly endUsers: EndUsersClient;
|
|
580
|
+
readonly settings: RuntimeSettingsClient;
|
|
581
|
+
constructor(config?: ClientConfig);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/** Base error for all Celesto SDK errors. */
|
|
585
|
+
declare class CelestoError extends Error {
|
|
586
|
+
constructor(message: string);
|
|
587
|
+
}
|
|
588
|
+
/** Thrown when an API request returns a non-2xx HTTP status. */
|
|
589
|
+
declare class CelestoApiError extends CelestoError {
|
|
590
|
+
readonly status: number;
|
|
591
|
+
readonly data: unknown;
|
|
592
|
+
readonly requestId?: string;
|
|
593
|
+
/** Response headers, for the ones that carry meaning — such as Retry-After. */
|
|
594
|
+
readonly headers?: Headers;
|
|
595
|
+
constructor(message: string, status: number, data: unknown, requestId?: string, headers?: Headers);
|
|
596
|
+
}
|
|
597
|
+
/** Thrown when fetch() itself fails — DNS, network, timeout, abort. */
|
|
598
|
+
declare class CelestoNetworkError extends CelestoError {
|
|
599
|
+
readonly cause?: Error;
|
|
600
|
+
constructor(message: string, cause?: Error);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
/**
|
|
604
|
+
* Typed errors for managed agents.
|
|
605
|
+
*
|
|
606
|
+
* A refused run comes back with a machine-readable code, so your code can
|
|
607
|
+
* branch on *why* instead of matching message text. Each code gets its own
|
|
608
|
+
* class here; all of them are still `CelestoApiError`, so existing
|
|
609
|
+
* `catch (e) { if (e instanceof CelestoApiError) ... }` keeps working.
|
|
610
|
+
*
|
|
611
|
+
* Two error body shapes exist in the wild:
|
|
612
|
+
*
|
|
613
|
+
* ```json
|
|
614
|
+
* {"detail": "Agent not found"}
|
|
615
|
+
* {"detail": {"code": "budget_exceeded", "message": "..."}}
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
618
|
+
|
|
619
|
+
/** Every reason a managed-agent request can be refused. */
|
|
620
|
+
type RunErrorCode = "budget_exceeded" | "session_busy" | "idempotency_conflict" | "agent_archived" | "provider_not_connected" | "session_agent_mismatch" | "session_end_user_mismatch" | "model_requires_own_key" | "config_key_not_allowed";
|
|
621
|
+
/** A managed-agent request was refused with a known error code. */
|
|
622
|
+
declare class ManagedAgentError extends CelestoApiError {
|
|
623
|
+
/** The API's error code, such as `"budget_exceeded"`. */
|
|
624
|
+
readonly code?: RunErrorCode;
|
|
625
|
+
/** Seconds to wait before retrying, when the API said so. */
|
|
626
|
+
readonly retryAfter?: number;
|
|
627
|
+
/** True when retrying the identical request can succeed. */
|
|
628
|
+
readonly retryable: boolean;
|
|
629
|
+
constructor(message: string, status: number, data: unknown, options?: {
|
|
630
|
+
code?: RunErrorCode;
|
|
631
|
+
retryAfter?: number;
|
|
632
|
+
requestId?: string;
|
|
633
|
+
headers?: Headers;
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
/**
|
|
637
|
+
* 402 — this end user's budget is spent for the current window.
|
|
638
|
+
*
|
|
639
|
+
* Raise the cap with `endUsers.update(id, { budgetCapUsd })`, or wait for
|
|
640
|
+
* `budget.windowResetsAt`.
|
|
641
|
+
*/
|
|
642
|
+
declare class BudgetExceededError extends ManagedAgentError {
|
|
643
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* 409 — another run holds this session. Retryable.
|
|
647
|
+
*
|
|
648
|
+
* `retryAfter` carries the API's hint in seconds. Sessions run one at a time,
|
|
649
|
+
* so the same request succeeds once the in-flight run settles.
|
|
650
|
+
*/
|
|
651
|
+
declare class SessionBusyError extends ManagedAgentError {
|
|
652
|
+
readonly retryable = true;
|
|
653
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
654
|
+
}
|
|
655
|
+
/** 409 — this idempotency key was already used with a different body. */
|
|
656
|
+
declare class IdempotencyConflictError extends ManagedAgentError {
|
|
657
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
658
|
+
}
|
|
659
|
+
/** 409 — the agent is archived and cannot take new runs. */
|
|
660
|
+
declare class AgentArchivedError extends ManagedAgentError {
|
|
661
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
662
|
+
}
|
|
663
|
+
/** 409 — no provider credential is connected for this agent's model. */
|
|
664
|
+
declare class ProviderNotConnectedError extends ManagedAgentError {
|
|
665
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
666
|
+
}
|
|
667
|
+
/** 409 — that session belongs to a different agent. */
|
|
668
|
+
declare class SessionAgentMismatchError extends ManagedAgentError {
|
|
669
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* 422 — that session belongs to a different end user.
|
|
673
|
+
*
|
|
674
|
+
* Sessions are owned by one end user. Pass the session's own `endUserId`, or
|
|
675
|
+
* omit `sessionId` to start a new session.
|
|
676
|
+
*/
|
|
677
|
+
declare class SessionEndUserMismatchError extends ManagedAgentError {
|
|
678
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
679
|
+
}
|
|
680
|
+
/** 422 — this model can only run on your own provider key. */
|
|
681
|
+
declare class ModelRequiresOwnKeyError extends ManagedAgentError {
|
|
682
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
683
|
+
}
|
|
684
|
+
/** 422 — the agent config carried a key outside {@link AgentConfig}. */
|
|
685
|
+
declare class ConfigKeyNotAllowedError extends ManagedAgentError {
|
|
686
|
+
constructor(...args: ConstructorParameters<typeof ManagedAgentError>);
|
|
687
|
+
}
|
|
688
|
+
/**
|
|
689
|
+
* Re-throwable: turn a generic API error into its specific type.
|
|
690
|
+
*
|
|
691
|
+
* Anything that is not a recognized managed-agent refusal is returned
|
|
692
|
+
* unchanged, so network errors and plain 404s keep their existing shape.
|
|
693
|
+
*/
|
|
694
|
+
declare const toManagedAgentError: (error: unknown) => unknown;
|
|
695
|
+
|
|
696
|
+
export { type Verbosity as $, ALLOWED_CONFIG_KEYS as A, BudgetExceededError as B, CelestoApiError as C, type DecimalString as D, EVENTS_VERSION as E, type RunUsage as F, type GetSessionParams as G, RunsClient as H, IdempotencyConflictError as I, type RuntimeSettings as J, KNOWN_EVENTS as K, type ListAgentsParams as L, ManagedAgentError as M, RuntimeSettingsClient as N, SessionAgentMismatchError as O, type Page as P, SessionBusyError as Q, type ReasoningEffort as R, type Session as S, SessionEndUserMismatchError as T, type SessionMessage as U, type SessionTranscript as V, SessionsClient as W, type StoredRunEvent as X, type UpdateAgentParams as Y, type UpdateEndUserParams as Z, type UpdateRuntimeSettingsParams as _, type Agent as a, eventText as a0, isTerminal as a1, parseRunEvents as a2, parseSseFrames as a3, toRunEvent as a4, EVENTS_VERSION_HEADER as a5, type ListAgentVersionsParams as a6, type MessageData as a7, type RunCompletedData as a8, type RunFailedData as a9, type RunStartedData as aa, SseDecoder as ab, type SseFrame as ac, type ToolCallData as ad, type ToolResultData as ae, type UsageData as af, toManagedAgentError as ag, AgentArchivedError as b, type AgentConfig as c, type AgentStatus as d, type AgentVersion as e, AgentsClient as f, type ArchivedAgent as g, CelestoError as h, CelestoNetworkError as i, ConfigKeyNotAllowedError as j, type CreateAgentParams as k, type CreateRunParams as l, type EndUser as m, type EndUserBudget as n, EndUsersClient as o, type ListRunEventsParams as p, type ListSessionsParams as q, ManagedAgentsClient as r, ModelRequiresOwnKeyError as s, ProviderNotConnectedError as t, type Run as u, type RunErrorCode as v, type RunEvent as w, type RunEventName as x, type RunEventsPage as y, type RunStatus as z };
|