cencori 1.8.3 → 1.10.0

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 (48) hide show
  1. package/README.md +89 -1
  2. package/dist/agents/index.d.mts +433 -0
  3. package/dist/agents/index.d.ts +433 -0
  4. package/dist/agents/index.js +897 -0
  5. package/dist/agents/index.js.map +1 -0
  6. package/dist/agents/index.mjs +870 -0
  7. package/dist/agents/index.mjs.map +1 -0
  8. package/dist/ai/index.d.mts +14 -1
  9. package/dist/ai/index.d.ts +14 -1
  10. package/dist/ai/index.js +43 -3
  11. package/dist/ai/index.js.map +1 -1
  12. package/dist/ai/index.mjs +43 -3
  13. package/dist/ai/index.mjs.map +1 -1
  14. package/dist/compute/index.d.mts +1 -1
  15. package/dist/compute/index.d.ts +1 -1
  16. package/dist/documents/index.d.mts +1 -1
  17. package/dist/documents/index.d.ts +1 -1
  18. package/dist/index.d.mts +50 -9
  19. package/dist/index.d.ts +50 -9
  20. package/dist/index.js +67 -13
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +67 -13
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/judgment/index.d.mts +1 -1
  25. package/dist/judgment/index.d.ts +1 -1
  26. package/dist/memory/index.d.mts +1 -1
  27. package/dist/memory/index.d.ts +1 -1
  28. package/dist/react/index.d.mts +6 -6
  29. package/dist/react/index.d.ts +6 -6
  30. package/dist/storage/index.d.mts +5 -7
  31. package/dist/storage/index.d.ts +5 -7
  32. package/dist/storage/index.js +6 -8
  33. package/dist/storage/index.js.map +1 -1
  34. package/dist/storage/index.mjs +6 -8
  35. package/dist/storage/index.mjs.map +1 -1
  36. package/dist/telemetry/index.d.mts +1 -1
  37. package/dist/telemetry/index.d.ts +1 -1
  38. package/dist/{types-CAhDuNTz.d.mts → types-D91o22Gb.d.mts} +28 -1
  39. package/dist/{types-CAhDuNTz.d.ts → types-D91o22Gb.d.ts} +28 -1
  40. package/dist/vision/index.d.mts +1 -1
  41. package/dist/vision/index.d.ts +1 -1
  42. package/dist/voice/index.d.mts +1 -1
  43. package/dist/voice/index.d.ts +1 -1
  44. package/dist/web/index.d.mts +1 -1
  45. package/dist/web/index.d.ts +1 -1
  46. package/dist/workflow/index.d.mts +1 -1
  47. package/dist/workflow/index.d.ts +1 -1
  48. package/package.json +11 -3
@@ -0,0 +1,433 @@
1
+ /** What tools, guardrails and dynamic instructions receive during a run. */
2
+ interface RunContext<Ctx = unknown> {
3
+ /** Your own value from run(..., { context }): a user, a db handle, anything. Never sent to Cencori. */
4
+ context: Ctx;
5
+ /**
6
+ * The Cencori session this run lives in. Empty in input guardrails and
7
+ * instructions of a new run: the session is created with its first turn.
8
+ */
9
+ sessionId: string;
10
+ /** Name of the agent currently answering. */
11
+ agentName: string;
12
+ /** Aborts with the run. */
13
+ signal?: AbortSignal;
14
+ }
15
+
16
+ /**
17
+ * Schemas for tool parameters and structured output, without depending on a
18
+ * validation library. Anything implementing Standard Schema works (zod 3.24+,
19
+ * zod 4, valibot, arktype); JSON Schema is read from Standard JSON Schema
20
+ * (zod 4.2+), a schema's own toJSONSchema(), or given directly as an object.
21
+ */
22
+ /** The Standard Schema interface (https://standardschema.dev), inlined. */
23
+ interface StandardSchemaV1<Input = unknown, Output = Input> {
24
+ readonly '~standard': {
25
+ readonly version: 1;
26
+ readonly vendor: string;
27
+ readonly validate: (value: unknown) => StandardResult<Output> | Promise<StandardResult<Output>>;
28
+ readonly types?: {
29
+ readonly input: Input;
30
+ readonly output: Output;
31
+ } | undefined;
32
+ readonly jsonSchema?: {
33
+ readonly input: (options: {
34
+ target: string;
35
+ }) => Record<string, unknown>;
36
+ readonly output: (options: {
37
+ target: string;
38
+ }) => Record<string, unknown>;
39
+ };
40
+ };
41
+ }
42
+ type StandardResult<Output> = {
43
+ readonly value: Output;
44
+ readonly issues?: undefined;
45
+ } | {
46
+ readonly issues: ReadonlyArray<{
47
+ readonly message: string;
48
+ readonly path?: ReadonlyArray<PropertyKey | {
49
+ key: PropertyKey;
50
+ }>;
51
+ }>;
52
+ };
53
+ /** A JSON Schema object, passed through as is. */
54
+ type JsonSchema = Record<string, unknown>;
55
+ /** What tool parameters and outputType accept. */
56
+ type SchemaLike<T = unknown> = StandardSchemaV1<unknown, T> | JsonSchema;
57
+ /** The type a schema validates to; `unknown` for plain JSON Schema. */
58
+ type InferSchema<S> = S extends StandardSchemaV1<unknown, infer O> ? O : unknown;
59
+ declare class SchemaValidationError extends Error {
60
+ readonly issues: ReadonlyArray<{
61
+ message: string;
62
+ path?: string;
63
+ }>;
64
+ constructor(what: string, issues: ReadonlyArray<{
65
+ message: string;
66
+ path?: string;
67
+ }>);
68
+ }
69
+
70
+ /** Whether a call needs a human's approval before it runs. */
71
+ type NeedsApproval<Args, Ctx> = boolean | ((runContext: RunContext<Ctx>, args: Args, callId: string) => boolean | Promise<boolean>);
72
+ interface ToolOptions<S extends SchemaLike, Ctx = unknown, Out = unknown> {
73
+ /** Name the model calls it by: letters, digits, _ and -, at most 64. */
74
+ name: string;
75
+ /** What it does and when to use it. The model reads this. */
76
+ description: string;
77
+ /** Parameters: a zod (or any Standard Schema) object, or a JSON Schema object. */
78
+ parameters?: S;
79
+ /** Runs the tool. Return anything; non-strings are sent to the model as JSON. */
80
+ execute: (args: InferSchema<S>, runContext: RunContext<Ctx>, details: {
81
+ callId: string;
82
+ }) => Out | Promise<Out>;
83
+ /**
84
+ * Ask a human before running it. `true` also records the request and the
85
+ * decision in your project's governance ledger; a function decides per call.
86
+ */
87
+ needsApproval?: NeedsApproval<InferSchema<S>, Ctx>;
88
+ /** What the model sees when execute throws. Default: the error's message. */
89
+ errorFunction?: (error: unknown, runContext: RunContext<Ctx>) => string | Promise<string>;
90
+ }
91
+ interface FunctionTool<Ctx = unknown> {
92
+ readonly type: 'function';
93
+ readonly name: string;
94
+ readonly description: string;
95
+ readonly parameters: JsonSchema;
96
+ readonly needsApproval: NeedsApproval<unknown, Ctx>;
97
+ /** Validate the model's arguments, run the tool, and return what the model sees. */
98
+ invoke(runContext: RunContext<Ctx>, rawArguments: string, callId: string): Promise<string>;
99
+ /** Parse and validate arguments (used to decide on approval before running). */
100
+ parseArguments(rawArguments: string): Promise<unknown>;
101
+ }
102
+ /**
103
+ * Define a tool the agent can call. It runs in your process, with your
104
+ * credentials and data; Cencori only sees its name, arguments and result.
105
+ *
106
+ * ```ts
107
+ * const getOrder = tool({
108
+ * name: 'get_order',
109
+ * description: 'Look up an order by id',
110
+ * parameters: z.object({ id: z.string() }),
111
+ * execute: async ({ id }) => db.orders.find(id),
112
+ * });
113
+ * ```
114
+ */
115
+ declare function tool<S extends SchemaLike, Ctx = unknown, Out = unknown>(options: ToolOptions<S, Ctx, Out>): FunctionTool<Ctx>;
116
+
117
+ interface TransportOptions {
118
+ /** Secret project key (csk_...). Defaults to the CENCORI_API_KEY environment variable. */
119
+ apiKey?: string;
120
+ /** Defaults to CENCORI_BASE_URL, then https://cencori.com. */
121
+ baseUrl?: string;
122
+ /** Custom fetch (tests, proxies, edge runtimes). */
123
+ fetch?: typeof fetch;
124
+ signal?: AbortSignal;
125
+ }
126
+ /** A tool call the turn paused on. */
127
+ interface PausedAction {
128
+ action_id: string;
129
+ tool: string;
130
+ arguments: string;
131
+ needs_approval?: boolean;
132
+ }
133
+
134
+ interface RunOptions<Ctx = unknown> extends TransportOptions {
135
+ /** Your value for tools, guardrails and dynamic instructions. Stays in your process. */
136
+ context?: Ctx;
137
+ /** Continue an earlier conversation: pass the sessionId from a previous result. */
138
+ sessionId?: string;
139
+ /** Most model calls this run may make (each tool round is one). Default 10. */
140
+ maxTurns?: number;
141
+ /** Stream events as they happen; see StreamedRunResult. */
142
+ stream?: boolean;
143
+ /** Turn on Cencori memory for this user: recalled before, written after. */
144
+ memory?: {
145
+ userId: string;
146
+ [key: string]: unknown;
147
+ };
148
+ /** Your end user's id: per-user quotas, billing and memory. */
149
+ user?: string;
150
+ /** Extra metadata on the session (strings). */
151
+ metadata?: Record<string, string>;
152
+ }
153
+ /** A tool call waiting for a human. Approve or reject it on result.state, then run again. */
154
+ interface ToolApprovalItem {
155
+ type: 'tool_approval';
156
+ callId: string;
157
+ toolName: string;
158
+ /** The model's arguments, as JSON text. */
159
+ arguments: string;
160
+ agentName: string;
161
+ }
162
+ type RunItem = {
163
+ type: 'message';
164
+ agentName: string;
165
+ text: string;
166
+ } | {
167
+ type: 'tool_call';
168
+ agentName: string;
169
+ callId: string;
170
+ toolName: string;
171
+ arguments: string;
172
+ } | {
173
+ type: 'tool_output';
174
+ agentName: string;
175
+ callId: string;
176
+ toolName: string;
177
+ output: string;
178
+ } | {
179
+ type: 'handoff';
180
+ from: string;
181
+ to: string;
182
+ };
183
+ interface Usage {
184
+ inputTokens: number;
185
+ outputTokens: number;
186
+ totalTokens: number;
187
+ }
188
+ type RunStreamEvent = {
189
+ type: 'agent_updated';
190
+ agent: Agent<any>;
191
+ } | {
192
+ type: 'text_delta';
193
+ delta: string;
194
+ agentName: string;
195
+ } | {
196
+ type: 'tool_call';
197
+ callId: string;
198
+ toolName: string;
199
+ arguments: string;
200
+ agentName: string;
201
+ } | {
202
+ type: 'tool_output';
203
+ callId: string;
204
+ toolName: string;
205
+ output: string;
206
+ agentName: string;
207
+ } | {
208
+ type: 'handoff';
209
+ from: string;
210
+ to: string;
211
+ } | {
212
+ type: 'interruption';
213
+ interruptions: ToolApprovalItem[];
214
+ };
215
+ interface PendingPause {
216
+ actionId: string;
217
+ actions: PausedAction[];
218
+ text: string;
219
+ }
220
+ interface SerializedRunState {
221
+ v: 1;
222
+ sessionId: string;
223
+ agentName: string;
224
+ turnsUsed: number;
225
+ usage: Usage;
226
+ pending: PendingPause;
227
+ decisions: Record<string, {
228
+ approved: boolean;
229
+ message?: string;
230
+ }>;
231
+ }
232
+ /**
233
+ * A paused run: tool calls are waiting for a human. Approve or reject each,
234
+ * then pass the state back to run(). Serializable with JSON.stringify, so the
235
+ * decision can come minutes or hours later from another process (Cencori
236
+ * keeps a paused session for 24 hours).
237
+ */
238
+ declare class RunState {
239
+ readonly sessionId: string;
240
+ readonly agentName: string;
241
+ readonly turnsUsed: number;
242
+ readonly usage: Usage;
243
+ /** @internal */
244
+ readonly pending: PendingPause;
245
+ private readonly decisions;
246
+ /** @internal */
247
+ constructor(init: Omit<SerializedRunState, 'v' | 'decisions'> & {
248
+ decisions?: SerializedRunState['decisions'];
249
+ });
250
+ approve(item: ToolApprovalItem | string): void;
251
+ /** The model is told the call was rejected, with your message if given. */
252
+ reject(item: ToolApprovalItem | string, options?: {
253
+ message?: string;
254
+ }): void;
255
+ /** @internal */
256
+ decision(callId: string): {
257
+ approved: boolean;
258
+ message?: string;
259
+ } | undefined;
260
+ toJSON(): SerializedRunState;
261
+ static fromJSON(json: string | SerializedRunState): RunState;
262
+ }
263
+ interface RunResult<Output = string> {
264
+ /** The final answer: text, or the parsed outputType. Undefined while interrupted. */
265
+ finalOutput: Output | undefined;
266
+ /** The Cencori session: pass it as sessionId to continue the conversation. */
267
+ sessionId: string;
268
+ /** The agent that gave the final answer (after any handoffs). */
269
+ lastAgent: Agent<any>;
270
+ /** Tool calls waiting for approval; empty when the run finished. */
271
+ interruptions: ToolApprovalItem[];
272
+ /** Set when interrupted: approve or reject, then run(agent, state). */
273
+ state: RunState | undefined;
274
+ /** Messages, tool calls and handoffs in this run, in order. */
275
+ newItems: RunItem[];
276
+ usage: Usage;
277
+ }
278
+ /** run(..., { stream: true }): iterate events as they happen, then await completed. */
279
+ interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEvent> {
280
+ /** Resolves with the result once the run ends (after you finish iterating, or on its own). */
281
+ readonly completed: Promise<RunResult<Output>>;
282
+ /** Only the text deltas. */
283
+ toTextStream(): AsyncIterable<string>;
284
+ }
285
+ /**
286
+ * Run an agent until it answers, pausing tool calls run in your process.
287
+ *
288
+ * ```ts
289
+ * const result = await run(support, 'Where is order 1042?');
290
+ * result.finalOutput; // "It shipped yesterday..."
291
+ * ```
292
+ *
293
+ * Pass `{ stream: true }` for events as they happen, `{ sessionId }` to
294
+ * continue a conversation, or a RunState to resume after approvals.
295
+ */
296
+ declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: string | RunState, options: RunOptions<Ctx> & {
297
+ stream: true;
298
+ }): StreamedRunResult<Out>;
299
+ declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: string | RunState, options?: RunOptions<Ctx> & {
300
+ stream?: false;
301
+ }): Promise<RunResult<Out>>;
302
+
303
+ /** Checks the user's input before the first model call. */
304
+ interface InputGuardrail<Ctx = unknown> {
305
+ name: string;
306
+ execute: (args: {
307
+ input: string;
308
+ agent: Agent<Ctx, any>;
309
+ runContext: RunContext<Ctx>;
310
+ }) => GuardrailResult | Promise<GuardrailResult>;
311
+ }
312
+ /** Checks the final answer before the run returns it. */
313
+ interface OutputGuardrail<Ctx = unknown> {
314
+ name: string;
315
+ execute: (args: {
316
+ output: unknown;
317
+ agent: Agent<Ctx, any>;
318
+ runContext: RunContext<Ctx>;
319
+ }) => GuardrailResult | Promise<GuardrailResult>;
320
+ }
321
+ interface GuardrailResult {
322
+ /** true stops the run with a GuardrailTripwireTriggered error. */
323
+ tripwireTriggered: boolean;
324
+ /** Anything you want back on the error. */
325
+ outputInfo?: unknown;
326
+ }
327
+ interface ModelSettings {
328
+ temperature?: number;
329
+ maxTokens?: number;
330
+ /**
331
+ * How hard a reasoning model thinks before answering. Lower is faster;
332
+ * 'none' skips thinking where the model allows it. Default: the model's own.
333
+ */
334
+ reasoningEffort?: 'none' | 'low' | 'medium' | 'high';
335
+ }
336
+ interface AgentOptions<Ctx = unknown, Out = string> {
337
+ /** Shown in traces, and used for handoff tool names (transfer_to_<name>). */
338
+ name: string;
339
+ /** System prompt. A function gets the run context, for per-user instructions. */
340
+ instructions?: string | ((runContext: RunContext<Ctx>) => string | Promise<string>);
341
+ /**
342
+ * Any model in the Cencori catalog: 'claude-sonnet-4-5', 'gemini-2.5-flash'...
343
+ * Default: DEFAULT_MODEL, GPT OSS 120B on Cerebras (fast, calls tools).
344
+ */
345
+ model?: string;
346
+ tools?: FunctionTool<Ctx>[];
347
+ /** Agents this one can hand the conversation to. */
348
+ handoffs?: Agent<Ctx, any>[];
349
+ /** Tells other agents when to hand off to this one. */
350
+ handoffDescription?: string;
351
+ /** Structured final output: a zod (or Standard Schema) object, or a JSON Schema. */
352
+ outputType?: StandardSchemaV1<unknown, Out> | Record<string, unknown>;
353
+ modelSettings?: ModelSettings;
354
+ inputGuardrails?: InputGuardrail<Ctx>[];
355
+ outputGuardrails?: OutputGuardrail<Ctx>[];
356
+ }
357
+ /** The model an agent uses when none is given: GPT OSS 120B on Cerebras, chosen for speed. */
358
+ declare const DEFAULT_MODEL = "gpt-oss-120b";
359
+ /**
360
+ * An agent: a model, instructions and tools. It holds no state; run() drives
361
+ * it in a Cencori session.
362
+ *
363
+ * ```ts
364
+ * const support = new Agent({
365
+ * name: 'Support',
366
+ * instructions: 'Answer order questions. Be brief.',
367
+ * model: 'claude-sonnet-4-5',
368
+ * tools: [getOrder],
369
+ * });
370
+ * ```
371
+ */
372
+ declare class Agent<Ctx = unknown, Out = string> {
373
+ readonly name: string;
374
+ readonly instructions: AgentOptions<Ctx, Out>['instructions'];
375
+ readonly model: string;
376
+ readonly tools: FunctionTool<Ctx>[];
377
+ readonly handoffs: Agent<Ctx, any>[];
378
+ readonly handoffDescription?: string;
379
+ readonly outputType?: SchemaLike;
380
+ readonly modelSettings: ModelSettings;
381
+ readonly inputGuardrails: InputGuardrail<Ctx>[];
382
+ readonly outputGuardrails: OutputGuardrail<Ctx>[];
383
+ constructor(options: AgentOptions<Ctx, Out>);
384
+ /** A copy with some options changed. */
385
+ clone(overrides: Partial<AgentOptions<Ctx, Out>>): Agent<Ctx, Out>;
386
+ /** The tool name a handoff to this agent goes by. */
387
+ static handoffToolName(agent: Agent<any>): string;
388
+ /** Instructions for this run, resolving a function if given. */
389
+ resolveInstructions(runContext: RunContext<Ctx>): Promise<string | undefined>;
390
+ /**
391
+ * Use this agent as a tool of another: it runs on its own (in its own
392
+ * session) and returns its final answer, while the calling agent keeps the
393
+ * conversation. Compare handoffs, where this agent would take it over.
394
+ */
395
+ asTool(options?: {
396
+ toolName?: string;
397
+ toolDescription?: string;
398
+ runOptions?: Pick<RunOptions<Ctx>, 'maxTurns' | 'apiKey' | 'baseUrl'>;
399
+ }): FunctionTool<Ctx>;
400
+ }
401
+
402
+ /** Base class for errors thrown by cencori/agents. */
403
+ declare class AgentsError extends Error {
404
+ constructor(message: string);
405
+ }
406
+ /** The run used up maxTurns model calls without a final answer. */
407
+ declare class MaxTurnsExceededError extends AgentsError {
408
+ readonly sessionId: string;
409
+ constructor(maxTurns: number, sessionId: string);
410
+ }
411
+ /** A guardrail's tripwire fired; the run stopped. */
412
+ declare class GuardrailTripwireTriggered extends AgentsError {
413
+ readonly guardrail: string;
414
+ readonly kind: 'input' | 'output';
415
+ readonly outputInfo: unknown;
416
+ constructor(kind: 'input' | 'output', guardrail: string, outputInfo: unknown);
417
+ }
418
+ /**
419
+ * Cencori refused or failed a request, or the turn failed (a project policy
420
+ * blocked it, the model provider errored, credits ran out...).
421
+ */
422
+ declare class CencoriRunError extends AgentsError {
423
+ readonly status?: number;
424
+ readonly code?: string;
425
+ readonly sessionId?: string;
426
+ constructor(message: string, details?: {
427
+ status?: number;
428
+ code?: string;
429
+ sessionId?: string;
430
+ });
431
+ }
432
+
433
+ export { Agent, type AgentOptions, AgentsError, CencoriRunError, DEFAULT_MODEL, type FunctionTool, type GuardrailResult, GuardrailTripwireTriggered, type InputGuardrail, type JsonSchema, MaxTurnsExceededError, type ModelSettings, type NeedsApproval, type OutputGuardrail, type RunContext, type RunItem, type RunOptions, type RunResult, RunState, type RunStreamEvent, type SchemaLike, SchemaValidationError, type StandardSchemaV1, type StreamedRunResult, type ToolApprovalItem, type ToolOptions, type Usage, run, tool };