cencori 1.10.0 → 1.11.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.
- package/README.md +33 -0
- package/dist/agents/index.d.mts +65 -1
- package/dist/agents/index.d.ts +65 -1
- package/dist/agents/index.js +539 -15
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/index.mjs +533 -14
- package/dist/agents/index.mjs.map +1 -1
- package/dist/protocol-T2jhccPz.d.mts +321 -0
- package/dist/protocol-T2jhccPz.d.ts +321 -0
- package/dist/react/index.d.mts +202 -2
- package/dist/react/index.d.ts +202 -2
- package/dist/react/index.js +1604 -171
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +1599 -174
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -124,6 +124,39 @@ await run(extractor, 'Trip to Lagos for 3 days', { memory: { userId: 'user_123'
|
|
|
124
124
|
|
|
125
125
|
Tool parameters accept zod 3 or 4, any [Standard Schema](https://standardschema.dev) library, or a plain JSON Schema object.
|
|
126
126
|
|
|
127
|
+
## Agent UI
|
|
128
|
+
|
|
129
|
+
A chat for your agent where it can answer with UI: charts, tables, stats, lists, buttons and forms, generated on the fly. Works with any model in the catalog.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
// app/api/chat/route.ts: your tools run on your server
|
|
133
|
+
import { Agent, createAgentChatHandler, tool } from 'cencori/agents';
|
|
134
|
+
import { z } from 'zod';
|
|
135
|
+
|
|
136
|
+
const getSales = tool({
|
|
137
|
+
name: 'get_sales',
|
|
138
|
+
description: 'Monthly revenue by product',
|
|
139
|
+
parameters: z.object({}),
|
|
140
|
+
execute: async () => db.sales.monthly(),
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
const analyst = new Agent({ name: 'Analyst', instructions: 'Answer with charts and tables when it helps.', tools: [getSales], widgets: true });
|
|
144
|
+
export const POST = createAgentChatHandler(analyst);
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
```tsx
|
|
148
|
+
// In your page
|
|
149
|
+
import { AgentChat } from 'cencori/react';
|
|
150
|
+
|
|
151
|
+
<AgentChat api="/api/chat" greeting="Ask about your sales" prompts={['Revenue by product', 'Top customers']} />
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
- `widgets: true` gives the model the built-in `render_ui` tool. Cencori checks every widget before it's shown.
|
|
155
|
+
- A tool can also return `{ widget }` to show a design you control, filled with real data.
|
|
156
|
+
- Buttons and forms send their action back to the agent (or to `onAction` with `handler: 'client'`).
|
|
157
|
+
- Approvals (`needsApproval`) show an approval card; the paused run is signed so the browser can't change it.
|
|
158
|
+
- Theme with `theme={{ colorScheme, accent, radius }}` or CSS variables. Build your own layout with `useAgentChat()`, `<Transcript>`, `<Composer>` and `<Widget>`.
|
|
159
|
+
|
|
127
160
|
## Embedded Agents
|
|
128
161
|
|
|
129
162
|
```typescript
|
package/dist/agents/index.d.mts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { W as WidgetNode } from '../protocol-T2jhccPz.mjs';
|
|
2
|
+
export { b as AgentChatApprovalItem, c as AgentChatDecision, A as AgentChatEvent, a as AgentChatRequest, B as BadgeNode, r as ButtonNode, C as CardNode, o as ChartNode, n as ChartSeries, w as CheckboxNode, k as ColNode, D as DividerNode, F as FormNode, I as ImageNode, s as InputNode, L as ListViewItem, j as ListViewNode, M as MarkdownNode, y as RenderedWidget, R as RowNode, u as SelectNode, t as SelectOption, S as SpacerNode, m as StatNode, p as TableColumn, q as TableNode, T as TextNode, l as TitleNode, z as WIDGET_LIMITS, d as WIDGET_TYPES, h as WidgetAction, e as WidgetColor, f as WidgetFormat, g as WidgetGap, x as WidgetType, E as WidgetValidation, G as describeWidgetSpec, i as isWidgetResult, v as validateWidget } from '../protocol-T2jhccPz.mjs';
|
|
3
|
+
|
|
1
4
|
/** What tools, guardrails and dynamic instructions receive during a run. */
|
|
2
5
|
interface RunContext<Ctx = unknown> {
|
|
3
6
|
/** Your own value from run(..., { context }): a user, a db handle, anything. Never sent to Cencori. */
|
|
@@ -179,6 +182,12 @@ type RunItem = {
|
|
|
179
182
|
type: 'handoff';
|
|
180
183
|
from: string;
|
|
181
184
|
to: string;
|
|
185
|
+
} | {
|
|
186
|
+
type: 'widget';
|
|
187
|
+
agentName: string;
|
|
188
|
+
callId: string;
|
|
189
|
+
widgetId: string;
|
|
190
|
+
widget: WidgetNode;
|
|
182
191
|
};
|
|
183
192
|
interface Usage {
|
|
184
193
|
inputTokens: number;
|
|
@@ -208,6 +217,14 @@ type RunStreamEvent = {
|
|
|
208
217
|
type: 'handoff';
|
|
209
218
|
from: string;
|
|
210
219
|
to: string;
|
|
220
|
+
}
|
|
221
|
+
/** UI to show: from the model (render_ui) or from a tool that returned { widget }. */
|
|
222
|
+
| {
|
|
223
|
+
type: 'widget';
|
|
224
|
+
callId: string;
|
|
225
|
+
widgetId: string;
|
|
226
|
+
widget: WidgetNode;
|
|
227
|
+
agentName: string;
|
|
211
228
|
} | {
|
|
212
229
|
type: 'interruption';
|
|
213
230
|
interruptions: ToolApprovalItem[];
|
|
@@ -353,6 +370,13 @@ interface AgentOptions<Ctx = unknown, Out = string> {
|
|
|
353
370
|
modelSettings?: ModelSettings;
|
|
354
371
|
inputGuardrails?: InputGuardrail<Ctx>[];
|
|
355
372
|
outputGuardrails?: OutputGuardrail<Ctx>[];
|
|
373
|
+
/**
|
|
374
|
+
* Let the agent answer with UI: it gets the built-in render_ui tool and can
|
|
375
|
+
* show cards, tables, charts, stats, buttons and forms in a chat
|
|
376
|
+
* (cencori/react's <AgentChat> renders them). Tools can also return
|
|
377
|
+
* `{ widget }` whether or not this is on.
|
|
378
|
+
*/
|
|
379
|
+
widgets?: boolean;
|
|
356
380
|
}
|
|
357
381
|
/** The model an agent uses when none is given: GPT OSS 120B on Cerebras, chosen for speed. */
|
|
358
382
|
declare const DEFAULT_MODEL = "gpt-oss-120b";
|
|
@@ -380,6 +404,7 @@ declare class Agent<Ctx = unknown, Out = string> {
|
|
|
380
404
|
readonly modelSettings: ModelSettings;
|
|
381
405
|
readonly inputGuardrails: InputGuardrail<Ctx>[];
|
|
382
406
|
readonly outputGuardrails: OutputGuardrail<Ctx>[];
|
|
407
|
+
readonly widgets: boolean;
|
|
383
408
|
constructor(options: AgentOptions<Ctx, Out>);
|
|
384
409
|
/** A copy with some options changed. */
|
|
385
410
|
clone(overrides: Partial<AgentOptions<Ctx, Out>>): Agent<Ctx, Out>;
|
|
@@ -430,4 +455,43 @@ declare class CencoriRunError extends AgentsError {
|
|
|
430
455
|
});
|
|
431
456
|
}
|
|
432
457
|
|
|
433
|
-
|
|
458
|
+
/**
|
|
459
|
+
* Agent UI on your backend: serve an agent to <AgentChat> from your own route. Your tools run here,
|
|
460
|
+
* with your database and secrets; the browser only sees the conversation.
|
|
461
|
+
*
|
|
462
|
+
* ```ts
|
|
463
|
+
* // app/api/chat/route.ts
|
|
464
|
+
* import { Agent, createAgentChatHandler } from 'cencori/agents';
|
|
465
|
+
*
|
|
466
|
+
* const support = new Agent({ name: 'Support', instructions: '...', tools: [lookupOrder], widgets: true });
|
|
467
|
+
* export const POST = createAgentChatHandler(support, {
|
|
468
|
+
* context: async (req) => ({ userId: await userIdFrom(req) }),
|
|
469
|
+
* });
|
|
470
|
+
*
|
|
471
|
+
* // In the page: <AgentChat api="/api/chat" />
|
|
472
|
+
* ```
|
|
473
|
+
*
|
|
474
|
+
* Approvals: when a tool needs one, the chat gets the paused run's state,
|
|
475
|
+
* signed, and sends it back with the user's decisions. The signature (HMAC
|
|
476
|
+
* with your secret key, or `secret`) means a browser can't alter what runs.
|
|
477
|
+
*/
|
|
478
|
+
interface AgentChatHandlerOptions<Ctx> extends Omit<RunOptions<Ctx>, 'context' | 'sessionId' | 'stream' | 'signal' | 'user'> {
|
|
479
|
+
/** Your context for this request (who the user is, their permissions...). */
|
|
480
|
+
context?: (req: Request) => Ctx | Promise<Ctx>;
|
|
481
|
+
/** A stable id for the end user, for Cencori's per-user analytics and limits. */
|
|
482
|
+
user?: (req: Request) => string | undefined | Promise<string | undefined>;
|
|
483
|
+
/**
|
|
484
|
+
* May this request continue this session? Check it belongs to the user.
|
|
485
|
+
* Without it, any session id the browser sends is continued.
|
|
486
|
+
*/
|
|
487
|
+
authorizeSession?: (sessionId: string, req: Request) => boolean | Promise<boolean>;
|
|
488
|
+
/** Signs paused-run state. Default: CENCORI_AGENT_CHAT_SECRET, then your API key. */
|
|
489
|
+
secret?: string;
|
|
490
|
+
}
|
|
491
|
+
declare function createAgentChatHandler<Ctx>(agent: Agent<Ctx, any>, options?: AgentChatHandlerOptions<Ctx>): (req: Request) => Promise<Response>;
|
|
492
|
+
/** A streamed run as the agent chat event stream (for your own route handler). */
|
|
493
|
+
declare function toAgentChatStream(streamed: StreamedRunResult<unknown>, options: {
|
|
494
|
+
secret: string;
|
|
495
|
+
}): ReadableStream<Uint8Array>;
|
|
496
|
+
|
|
497
|
+
export { Agent, type AgentChatHandlerOptions, 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, WidgetNode, createAgentChatHandler, run, toAgentChatStream, tool };
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { W as WidgetNode } from '../protocol-T2jhccPz.js';
|
|
2
|
+
export { b as AgentChatApprovalItem, c as AgentChatDecision, A as AgentChatEvent, a as AgentChatRequest, B as BadgeNode, r as ButtonNode, C as CardNode, o as ChartNode, n as ChartSeries, w as CheckboxNode, k as ColNode, D as DividerNode, F as FormNode, I as ImageNode, s as InputNode, L as ListViewItem, j as ListViewNode, M as MarkdownNode, y as RenderedWidget, R as RowNode, u as SelectNode, t as SelectOption, S as SpacerNode, m as StatNode, p as TableColumn, q as TableNode, T as TextNode, l as TitleNode, z as WIDGET_LIMITS, d as WIDGET_TYPES, h as WidgetAction, e as WidgetColor, f as WidgetFormat, g as WidgetGap, x as WidgetType, E as WidgetValidation, G as describeWidgetSpec, i as isWidgetResult, v as validateWidget } from '../protocol-T2jhccPz.js';
|
|
3
|
+
|
|
1
4
|
/** What tools, guardrails and dynamic instructions receive during a run. */
|
|
2
5
|
interface RunContext<Ctx = unknown> {
|
|
3
6
|
/** Your own value from run(..., { context }): a user, a db handle, anything. Never sent to Cencori. */
|
|
@@ -179,6 +182,12 @@ type RunItem = {
|
|
|
179
182
|
type: 'handoff';
|
|
180
183
|
from: string;
|
|
181
184
|
to: string;
|
|
185
|
+
} | {
|
|
186
|
+
type: 'widget';
|
|
187
|
+
agentName: string;
|
|
188
|
+
callId: string;
|
|
189
|
+
widgetId: string;
|
|
190
|
+
widget: WidgetNode;
|
|
182
191
|
};
|
|
183
192
|
interface Usage {
|
|
184
193
|
inputTokens: number;
|
|
@@ -208,6 +217,14 @@ type RunStreamEvent = {
|
|
|
208
217
|
type: 'handoff';
|
|
209
218
|
from: string;
|
|
210
219
|
to: string;
|
|
220
|
+
}
|
|
221
|
+
/** UI to show: from the model (render_ui) or from a tool that returned { widget }. */
|
|
222
|
+
| {
|
|
223
|
+
type: 'widget';
|
|
224
|
+
callId: string;
|
|
225
|
+
widgetId: string;
|
|
226
|
+
widget: WidgetNode;
|
|
227
|
+
agentName: string;
|
|
211
228
|
} | {
|
|
212
229
|
type: 'interruption';
|
|
213
230
|
interruptions: ToolApprovalItem[];
|
|
@@ -353,6 +370,13 @@ interface AgentOptions<Ctx = unknown, Out = string> {
|
|
|
353
370
|
modelSettings?: ModelSettings;
|
|
354
371
|
inputGuardrails?: InputGuardrail<Ctx>[];
|
|
355
372
|
outputGuardrails?: OutputGuardrail<Ctx>[];
|
|
373
|
+
/**
|
|
374
|
+
* Let the agent answer with UI: it gets the built-in render_ui tool and can
|
|
375
|
+
* show cards, tables, charts, stats, buttons and forms in a chat
|
|
376
|
+
* (cencori/react's <AgentChat> renders them). Tools can also return
|
|
377
|
+
* `{ widget }` whether or not this is on.
|
|
378
|
+
*/
|
|
379
|
+
widgets?: boolean;
|
|
356
380
|
}
|
|
357
381
|
/** The model an agent uses when none is given: GPT OSS 120B on Cerebras, chosen for speed. */
|
|
358
382
|
declare const DEFAULT_MODEL = "gpt-oss-120b";
|
|
@@ -380,6 +404,7 @@ declare class Agent<Ctx = unknown, Out = string> {
|
|
|
380
404
|
readonly modelSettings: ModelSettings;
|
|
381
405
|
readonly inputGuardrails: InputGuardrail<Ctx>[];
|
|
382
406
|
readonly outputGuardrails: OutputGuardrail<Ctx>[];
|
|
407
|
+
readonly widgets: boolean;
|
|
383
408
|
constructor(options: AgentOptions<Ctx, Out>);
|
|
384
409
|
/** A copy with some options changed. */
|
|
385
410
|
clone(overrides: Partial<AgentOptions<Ctx, Out>>): Agent<Ctx, Out>;
|
|
@@ -430,4 +455,43 @@ declare class CencoriRunError extends AgentsError {
|
|
|
430
455
|
});
|
|
431
456
|
}
|
|
432
457
|
|
|
433
|
-
|
|
458
|
+
/**
|
|
459
|
+
* Agent UI on your backend: serve an agent to <AgentChat> from your own route. Your tools run here,
|
|
460
|
+
* with your database and secrets; the browser only sees the conversation.
|
|
461
|
+
*
|
|
462
|
+
* ```ts
|
|
463
|
+
* // app/api/chat/route.ts
|
|
464
|
+
* import { Agent, createAgentChatHandler } from 'cencori/agents';
|
|
465
|
+
*
|
|
466
|
+
* const support = new Agent({ name: 'Support', instructions: '...', tools: [lookupOrder], widgets: true });
|
|
467
|
+
* export const POST = createAgentChatHandler(support, {
|
|
468
|
+
* context: async (req) => ({ userId: await userIdFrom(req) }),
|
|
469
|
+
* });
|
|
470
|
+
*
|
|
471
|
+
* // In the page: <AgentChat api="/api/chat" />
|
|
472
|
+
* ```
|
|
473
|
+
*
|
|
474
|
+
* Approvals: when a tool needs one, the chat gets the paused run's state,
|
|
475
|
+
* signed, and sends it back with the user's decisions. The signature (HMAC
|
|
476
|
+
* with your secret key, or `secret`) means a browser can't alter what runs.
|
|
477
|
+
*/
|
|
478
|
+
interface AgentChatHandlerOptions<Ctx> extends Omit<RunOptions<Ctx>, 'context' | 'sessionId' | 'stream' | 'signal' | 'user'> {
|
|
479
|
+
/** Your context for this request (who the user is, their permissions...). */
|
|
480
|
+
context?: (req: Request) => Ctx | Promise<Ctx>;
|
|
481
|
+
/** A stable id for the end user, for Cencori's per-user analytics and limits. */
|
|
482
|
+
user?: (req: Request) => string | undefined | Promise<string | undefined>;
|
|
483
|
+
/**
|
|
484
|
+
* May this request continue this session? Check it belongs to the user.
|
|
485
|
+
* Without it, any session id the browser sends is continued.
|
|
486
|
+
*/
|
|
487
|
+
authorizeSession?: (sessionId: string, req: Request) => boolean | Promise<boolean>;
|
|
488
|
+
/** Signs paused-run state. Default: CENCORI_AGENT_CHAT_SECRET, then your API key. */
|
|
489
|
+
secret?: string;
|
|
490
|
+
}
|
|
491
|
+
declare function createAgentChatHandler<Ctx>(agent: Agent<Ctx, any>, options?: AgentChatHandlerOptions<Ctx>): (req: Request) => Promise<Response>;
|
|
492
|
+
/** A streamed run as the agent chat event stream (for your own route handler). */
|
|
493
|
+
declare function toAgentChatStream(streamed: StreamedRunResult<unknown>, options: {
|
|
494
|
+
secret: string;
|
|
495
|
+
}): ReadableStream<Uint8Array>;
|
|
496
|
+
|
|
497
|
+
export { Agent, type AgentChatHandlerOptions, 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, WidgetNode, createAgentChatHandler, run, toAgentChatStream, tool };
|