cencori 1.12.1 → 1.14.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/dist/agents/index.d.mts +235 -5
- package/dist/agents/index.d.ts +235 -5
- package/dist/agents/index.js +664 -201
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/index.mjs +644 -201
- package/dist/agents/index.mjs.map +1 -1
- package/dist/{protocol-Dq7rZbRX.d.mts → protocol-CQy4ZF8f.d.mts} +25 -2
- package/dist/{protocol-Dq7rZbRX.d.ts → protocol-CQy4ZF8f.d.ts} +25 -2
- package/dist/react/index.d.mts +26 -7
- package/dist/react/index.d.ts +26 -7
- package/dist/react/index.js +437 -165
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +438 -166
- package/dist/react/index.mjs.map +1 -1
- package/package.json +1 -6
package/dist/agents/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WidgetNode } from '../protocol-
|
|
2
|
-
export {
|
|
1
|
+
import { W as WidgetNode } from '../protocol-CQy4ZF8f.mjs';
|
|
2
|
+
export { A as AgentChatApprovalItem, a as AgentChatDecision, c as AgentChatEvent, d 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, e as WIDGET_TYPES, b as WidgetAction, f as WidgetColor, g as WidgetFormat, h as WidgetGap, x as WidgetType, E as WidgetValidation, G as describeWidgetSpec, i as isWidgetResult, v as validateWidget } from '../protocol-CQy4ZF8f.mjs';
|
|
3
3
|
|
|
4
4
|
/** What tools, guardrails and dynamic instructions receive during a run. */
|
|
5
5
|
interface RunContext<Ctx = unknown> {
|
|
@@ -117,6 +117,154 @@ interface FunctionTool<Ctx = unknown> {
|
|
|
117
117
|
*/
|
|
118
118
|
declare function tool<S extends SchemaLike, Ctx = unknown, Out = unknown>(options: ToolOptions<S, Ctx, Out>): FunctionTool<Ctx>;
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* MCP servers as agent tools.
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* const linear = new MCPServerStreamableHttp({ url: 'https://mcp.linear.app/mcp', headers: { Authorization: `Bearer ${token}` } });
|
|
125
|
+
* const files = new MCPServerStdio({ command: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', './docs'] });
|
|
126
|
+
* const agent = new Agent({ name: 'Ops', mcpServers: [linear, files] });
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* Servers connect from your process, like your other tools: their
|
|
130
|
+
* credentials never reach Cencori. Their tools join the agent's own, with the
|
|
131
|
+
* same argument checks, approvals and traces.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
interface MCPTool {
|
|
135
|
+
name: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
inputSchema?: JsonSchema;
|
|
138
|
+
annotations?: {
|
|
139
|
+
readOnlyHint?: boolean;
|
|
140
|
+
destructiveHint?: boolean;
|
|
141
|
+
idempotentHint?: boolean;
|
|
142
|
+
openWorldHint?: boolean;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
interface MCPServerOptions {
|
|
146
|
+
/** A name for traces and to keep tool names apart between servers. Default from the URL or command. */
|
|
147
|
+
name?: string;
|
|
148
|
+
/** Only these tools (by their MCP name). Default: all. */
|
|
149
|
+
allowedTools?: string[];
|
|
150
|
+
/**
|
|
151
|
+
* Ask a person before calling: true for every tool, a list of tool names,
|
|
152
|
+
* or a function. Tools marked destructive by the server always ask unless
|
|
153
|
+
* this is false.
|
|
154
|
+
*/
|
|
155
|
+
requireApproval?: boolean | string[] | ((tool: MCPTool) => boolean);
|
|
156
|
+
/** Keep the tools list after the first fetch (default true). */
|
|
157
|
+
cacheToolsList?: boolean;
|
|
158
|
+
/** Per request, in ms. Default 30000. */
|
|
159
|
+
timeoutMs?: number;
|
|
160
|
+
}
|
|
161
|
+
/** What an agent needs from an MCP server. */
|
|
162
|
+
interface MCPServer {
|
|
163
|
+
readonly name: string;
|
|
164
|
+
readonly options: MCPServerOptions;
|
|
165
|
+
connect(): Promise<void>;
|
|
166
|
+
listTools(): Promise<MCPTool[]>;
|
|
167
|
+
callTool(name: string, args: Record<string, unknown>): Promise<MCPCallResult>;
|
|
168
|
+
close(): Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
interface MCPCallResult {
|
|
171
|
+
content?: Array<{
|
|
172
|
+
type: string;
|
|
173
|
+
text?: string;
|
|
174
|
+
[key: string]: unknown;
|
|
175
|
+
}>;
|
|
176
|
+
structuredContent?: unknown;
|
|
177
|
+
isError?: boolean;
|
|
178
|
+
}
|
|
179
|
+
interface MCPServerStreamableHttpOptions extends MCPServerOptions {
|
|
180
|
+
url: string;
|
|
181
|
+
/** Sent on every request: auth goes here. */
|
|
182
|
+
headers?: Record<string, string>;
|
|
183
|
+
fetch?: typeof fetch;
|
|
184
|
+
}
|
|
185
|
+
/** A remote MCP server over Streamable HTTP. Speaks stateless MCP, and falls back to the session handshake for older servers. */
|
|
186
|
+
declare class MCPServerStreamableHttp implements MCPServer {
|
|
187
|
+
readonly name: string;
|
|
188
|
+
readonly options: MCPServerStreamableHttpOptions;
|
|
189
|
+
private mode;
|
|
190
|
+
private sessionHeaders;
|
|
191
|
+
private tools;
|
|
192
|
+
constructor(options: MCPServerStreamableHttpOptions);
|
|
193
|
+
connect(): Promise<void>;
|
|
194
|
+
listTools(): Promise<MCPTool[]>;
|
|
195
|
+
callTool(name: string, args: Record<string, unknown>): Promise<MCPCallResult>;
|
|
196
|
+
close(): Promise<void>;
|
|
197
|
+
private request;
|
|
198
|
+
private handshake;
|
|
199
|
+
private post;
|
|
200
|
+
}
|
|
201
|
+
interface MCPServerStdioOptions extends MCPServerOptions {
|
|
202
|
+
command: string;
|
|
203
|
+
args?: string[];
|
|
204
|
+
env?: Record<string, string>;
|
|
205
|
+
cwd?: string;
|
|
206
|
+
}
|
|
207
|
+
/** A local MCP server started as a process (Node only). */
|
|
208
|
+
declare class MCPServerStdio implements MCPServer {
|
|
209
|
+
readonly name: string;
|
|
210
|
+
readonly options: MCPServerStdioOptions;
|
|
211
|
+
private child;
|
|
212
|
+
private starting;
|
|
213
|
+
private pending;
|
|
214
|
+
private tools;
|
|
215
|
+
private stderr;
|
|
216
|
+
constructor(options: MCPServerStdioOptions);
|
|
217
|
+
connect(): Promise<void>;
|
|
218
|
+
listTools(): Promise<MCPTool[]>;
|
|
219
|
+
callTool(name: string, args: Record<string, unknown>): Promise<MCPCallResult>;
|
|
220
|
+
close(): Promise<void>;
|
|
221
|
+
private start;
|
|
222
|
+
private request;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* What run() can take besides text: messages with images and files.
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* await run(agent, [
|
|
230
|
+
* { role: 'user', content: [
|
|
231
|
+
* { type: 'input_text', text: 'What does this invoice owe?' },
|
|
232
|
+
* { type: 'input_file', filename: 'invoice.pdf', file_data: 'data:application/pdf;base64,...' },
|
|
233
|
+
* { type: 'input_image', image_url: 'https://example.com/receipt.jpg' },
|
|
234
|
+
* ] },
|
|
235
|
+
* ]);
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* Same shape as OpenAI's Responses input. Images reach models that can see
|
|
239
|
+
* them (a text-only model is swapped for one that can, for that turn); PDFs
|
|
240
|
+
* and text files are read on Cencori and given to the model as text.
|
|
241
|
+
*/
|
|
242
|
+
type InputContentPart = {
|
|
243
|
+
type: 'input_text';
|
|
244
|
+
text: string;
|
|
245
|
+
} | {
|
|
246
|
+
type: 'input_image';
|
|
247
|
+
image_url: string;
|
|
248
|
+
detail?: 'auto' | 'low' | 'high';
|
|
249
|
+
} | {
|
|
250
|
+
type: 'input_file';
|
|
251
|
+
filename: string;
|
|
252
|
+
file_data: string;
|
|
253
|
+
};
|
|
254
|
+
interface AgentInputItem {
|
|
255
|
+
/** Optional, as in OpenAI's shorthand; Cencori treats { role, content } as a message. */
|
|
256
|
+
type?: 'message';
|
|
257
|
+
role: 'user';
|
|
258
|
+
content: string | InputContentPart[];
|
|
259
|
+
}
|
|
260
|
+
type AgentInput = string | AgentInputItem[];
|
|
261
|
+
/** The text in an input, for guardrails and anything else that reads words. */
|
|
262
|
+
declare function inputText(input: AgentInput): string;
|
|
263
|
+
/** An image part from a URL or a data URL. */
|
|
264
|
+
declare function image(url: string, detail?: 'auto' | 'low' | 'high'): InputContentPart;
|
|
265
|
+
/** A file part from bytes (Node Buffer / Uint8Array) or a data URL. */
|
|
266
|
+
declare function file(filename: string, data: string | Uint8Array, mimeType?: string): InputContentPart;
|
|
267
|
+
|
|
120
268
|
interface TransportOptions {
|
|
121
269
|
/** Secret project key (csk_...). Defaults to the CENCORI_API_KEY environment variable. */
|
|
122
270
|
apiKey?: string;
|
|
@@ -235,6 +383,16 @@ type RunStreamEvent = {
|
|
|
235
383
|
} | {
|
|
236
384
|
type: 'interruption';
|
|
237
385
|
interruptions: ToolApprovalItem[];
|
|
386
|
+
}
|
|
387
|
+
/** The agent handed the conversation to a person (humanHandoff). */
|
|
388
|
+
| {
|
|
389
|
+
type: 'human_handoff';
|
|
390
|
+
reason: string;
|
|
391
|
+
agentName: string;
|
|
392
|
+
}
|
|
393
|
+
/** A person is handling the conversation: the message was kept for them, no answer from the agent. */
|
|
394
|
+
| {
|
|
395
|
+
type: 'with_human';
|
|
238
396
|
};
|
|
239
397
|
interface PendingPause {
|
|
240
398
|
actionId: string;
|
|
@@ -298,6 +456,12 @@ interface RunResult<Output = string> {
|
|
|
298
456
|
/** Messages, tool calls and handoffs in this run, in order. */
|
|
299
457
|
newItems: RunItem[];
|
|
300
458
|
usage: Usage;
|
|
459
|
+
/**
|
|
460
|
+
* A person is handling this conversation (the agent handed it over with
|
|
461
|
+
* humanHandoff, or someone stepped in): the message was kept for them and
|
|
462
|
+
* the agent didn't answer. See humanReply / releaseToAgent.
|
|
463
|
+
*/
|
|
464
|
+
withHuman: boolean;
|
|
301
465
|
}
|
|
302
466
|
/** run(..., { stream: true }): iterate events as they happen, then await completed. */
|
|
303
467
|
interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEvent> {
|
|
@@ -317,10 +481,10 @@ interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEven
|
|
|
317
481
|
* Pass `{ stream: true }` for events as they happen, `{ sessionId }` to
|
|
318
482
|
* continue a conversation, or a RunState to resume after approvals.
|
|
319
483
|
*/
|
|
320
|
-
declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input:
|
|
484
|
+
declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: AgentInput | RunState, options: RunOptions<Ctx> & {
|
|
321
485
|
stream: true;
|
|
322
486
|
}): StreamedRunResult<Out>;
|
|
323
|
-
declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input:
|
|
487
|
+
declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: AgentInput | RunState, options?: RunOptions<Ctx> & {
|
|
324
488
|
stream?: false;
|
|
325
489
|
}): Promise<RunResult<Out>>;
|
|
326
490
|
|
|
@@ -390,6 +554,12 @@ interface AgentOptions<Ctx = unknown, Out = string> {
|
|
|
390
554
|
* add here run in your process on top. Usually set with Agent.fromCencori().
|
|
391
555
|
*/
|
|
392
556
|
cencoriAgentId?: string;
|
|
557
|
+
/**
|
|
558
|
+
* MCP servers whose tools this agent can use, next to its own. They connect
|
|
559
|
+
* from your process (MCPServerStreamableHttp for remote servers,
|
|
560
|
+
* MCPServerStdio for local ones).
|
|
561
|
+
*/
|
|
562
|
+
mcpServers?: MCPServer[];
|
|
393
563
|
}
|
|
394
564
|
/** The model an agent uses when none is given: GPT OSS 120B on Cerebras, chosen for speed. */
|
|
395
565
|
declare const DEFAULT_MODEL = "gpt-oss-120b";
|
|
@@ -419,6 +589,7 @@ declare class Agent<Ctx = unknown, Out = string> {
|
|
|
419
589
|
readonly outputGuardrails: OutputGuardrail<Ctx>[];
|
|
420
590
|
readonly widgets: boolean;
|
|
421
591
|
readonly cencoriAgentId?: string;
|
|
592
|
+
readonly mcpServers: MCPServer[];
|
|
422
593
|
constructor(options: AgentOptions<Ctx, Out>);
|
|
423
594
|
/** A copy with some options changed. */
|
|
424
595
|
clone(overrides: Partial<AgentOptions<Ctx, Out>>): Agent<Ctx, Out>;
|
|
@@ -435,6 +606,12 @@ declare class Agent<Ctx = unknown, Out = string> {
|
|
|
435
606
|
static fromCencori<Ctx = unknown>(agentId: string, options?: Omit<AgentOptions<Ctx, string>, 'cencoriAgentId' | 'name'> & {
|
|
436
607
|
name?: string;
|
|
437
608
|
}): Agent<Ctx, string>;
|
|
609
|
+
/**
|
|
610
|
+
* Every tool this agent can call: its own, then its MCP servers' (fetched
|
|
611
|
+
* from each server, once per server unless it says otherwise). An MCP tool
|
|
612
|
+
* whose name is taken gets its server's name in front.
|
|
613
|
+
*/
|
|
614
|
+
resolveTools(): Promise<FunctionTool<Ctx>[]>;
|
|
438
615
|
/** The tool name a handoff to this agent goes by. */
|
|
439
616
|
static handoffToolName(agent: Agent<any>): string;
|
|
440
617
|
/** Instructions for this run, resolving a function if given. */
|
|
@@ -521,4 +698,57 @@ declare function toAgentChatStream(streamed: StreamedRunResult<unknown>, options
|
|
|
521
698
|
secret: string;
|
|
522
699
|
}): ReadableStream<Uint8Array>;
|
|
523
700
|
|
|
524
|
-
|
|
701
|
+
/**
|
|
702
|
+
* Handing a conversation to a person.
|
|
703
|
+
*
|
|
704
|
+
* Give an agent the humanHandoff() tool and it can pass the conversation to
|
|
705
|
+
* your team: it says so, then goes quiet. While a person handles it, the
|
|
706
|
+
* user's messages are kept for them (run() returns `withHuman: true` instead
|
|
707
|
+
* of an answer). Your team replies with humanReply() and hands it back with
|
|
708
|
+
* releaseToAgent(); it also goes back on its own after 30 quiet minutes. The
|
|
709
|
+
* agent is then told what was said, and carries on.
|
|
710
|
+
*
|
|
711
|
+
* ```ts
|
|
712
|
+
* const support = new Agent({
|
|
713
|
+
* name: 'Support',
|
|
714
|
+
* tools: [lookupOrder, humanHandoff({ onHandoff: ({ sessionId, reason }) => slack.post(`#support: ${reason} ${sessionId}`) })],
|
|
715
|
+
* });
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
declare const HUMAN_HANDOFF_TOOL = "handoff_to_human";
|
|
719
|
+
interface HumanHandoffOptions<Ctx = unknown> {
|
|
720
|
+
/** When the model should use it. */
|
|
721
|
+
description?: string;
|
|
722
|
+
/** Tell your team: post to Slack, open a ticket, page someone. */
|
|
723
|
+
onHandoff?: (event: {
|
|
724
|
+
sessionId: string;
|
|
725
|
+
reason: string;
|
|
726
|
+
runContext: RunContext<Ctx>;
|
|
727
|
+
}) => void | Promise<void>;
|
|
728
|
+
}
|
|
729
|
+
declare function humanHandoff<Ctx = unknown>(options?: HumanHandoffOptions<Ctx>): FunctionTool<Ctx>;
|
|
730
|
+
interface HumanMessage {
|
|
731
|
+
id: string;
|
|
732
|
+
/** 'user' (your end user), 'human' (your team), 'agent'. */
|
|
733
|
+
from: 'user' | 'human' | 'agent';
|
|
734
|
+
text: string;
|
|
735
|
+
at: string;
|
|
736
|
+
}
|
|
737
|
+
interface HumanStatus {
|
|
738
|
+
handledBy: 'human' | 'agent';
|
|
739
|
+
handoff: {
|
|
740
|
+
reason: string;
|
|
741
|
+
at: string;
|
|
742
|
+
} | null;
|
|
743
|
+
messages: HumanMessage[];
|
|
744
|
+
}
|
|
745
|
+
/** A person on your team replies in the conversation (and keeps it with them). */
|
|
746
|
+
declare function humanReply(sessionId: string, text: string, options?: TransportOptions): Promise<HumanMessage>;
|
|
747
|
+
/** Hand the conversation back to the agent. */
|
|
748
|
+
declare function releaseToAgent(sessionId: string, options?: TransportOptions): Promise<void>;
|
|
749
|
+
/** Who's handling the conversation, and what was said while a person was (optionally only after a time). */
|
|
750
|
+
declare function humanStatus(sessionId: string, options?: TransportOptions & {
|
|
751
|
+
after?: string;
|
|
752
|
+
}): Promise<HumanStatus>;
|
|
753
|
+
|
|
754
|
+
export { Agent, type AgentChatHandlerOptions, type AgentInput, type AgentInputItem, type AgentOptions, AgentsError, CencoriRunError, DEFAULT_MODEL, type FunctionTool, type GuardrailResult, GuardrailTripwireTriggered, HUMAN_HANDOFF_TOOL, type HumanHandoffOptions, type HumanMessage, type HumanStatus, type InputContentPart, type InputGuardrail, type JsonSchema, type MCPCallResult, type MCPServer, type MCPServerOptions, MCPServerStdio, type MCPServerStdioOptions, MCPServerStreamableHttp, type MCPServerStreamableHttpOptions, type MCPTool, 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, file, humanHandoff, humanReply, humanStatus, image, inputText, releaseToAgent, run, toAgentChatStream, tool };
|
package/dist/agents/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { W as WidgetNode } from '../protocol-
|
|
2
|
-
export {
|
|
1
|
+
import { W as WidgetNode } from '../protocol-CQy4ZF8f.js';
|
|
2
|
+
export { A as AgentChatApprovalItem, a as AgentChatDecision, c as AgentChatEvent, d 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, e as WIDGET_TYPES, b as WidgetAction, f as WidgetColor, g as WidgetFormat, h as WidgetGap, x as WidgetType, E as WidgetValidation, G as describeWidgetSpec, i as isWidgetResult, v as validateWidget } from '../protocol-CQy4ZF8f.js';
|
|
3
3
|
|
|
4
4
|
/** What tools, guardrails and dynamic instructions receive during a run. */
|
|
5
5
|
interface RunContext<Ctx = unknown> {
|
|
@@ -117,6 +117,154 @@ interface FunctionTool<Ctx = unknown> {
|
|
|
117
117
|
*/
|
|
118
118
|
declare function tool<S extends SchemaLike, Ctx = unknown, Out = unknown>(options: ToolOptions<S, Ctx, Out>): FunctionTool<Ctx>;
|
|
119
119
|
|
|
120
|
+
/**
|
|
121
|
+
* MCP servers as agent tools.
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* const linear = new MCPServerStreamableHttp({ url: 'https://mcp.linear.app/mcp', headers: { Authorization: `Bearer ${token}` } });
|
|
125
|
+
* const files = new MCPServerStdio({ command: 'npx', args: ['-y', '@modelcontextprotocol/server-filesystem', './docs'] });
|
|
126
|
+
* const agent = new Agent({ name: 'Ops', mcpServers: [linear, files] });
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* Servers connect from your process, like your other tools: their
|
|
130
|
+
* credentials never reach Cencori. Their tools join the agent's own, with the
|
|
131
|
+
* same argument checks, approvals and traces.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
interface MCPTool {
|
|
135
|
+
name: string;
|
|
136
|
+
description?: string;
|
|
137
|
+
inputSchema?: JsonSchema;
|
|
138
|
+
annotations?: {
|
|
139
|
+
readOnlyHint?: boolean;
|
|
140
|
+
destructiveHint?: boolean;
|
|
141
|
+
idempotentHint?: boolean;
|
|
142
|
+
openWorldHint?: boolean;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
interface MCPServerOptions {
|
|
146
|
+
/** A name for traces and to keep tool names apart between servers. Default from the URL or command. */
|
|
147
|
+
name?: string;
|
|
148
|
+
/** Only these tools (by their MCP name). Default: all. */
|
|
149
|
+
allowedTools?: string[];
|
|
150
|
+
/**
|
|
151
|
+
* Ask a person before calling: true for every tool, a list of tool names,
|
|
152
|
+
* or a function. Tools marked destructive by the server always ask unless
|
|
153
|
+
* this is false.
|
|
154
|
+
*/
|
|
155
|
+
requireApproval?: boolean | string[] | ((tool: MCPTool) => boolean);
|
|
156
|
+
/** Keep the tools list after the first fetch (default true). */
|
|
157
|
+
cacheToolsList?: boolean;
|
|
158
|
+
/** Per request, in ms. Default 30000. */
|
|
159
|
+
timeoutMs?: number;
|
|
160
|
+
}
|
|
161
|
+
/** What an agent needs from an MCP server. */
|
|
162
|
+
interface MCPServer {
|
|
163
|
+
readonly name: string;
|
|
164
|
+
readonly options: MCPServerOptions;
|
|
165
|
+
connect(): Promise<void>;
|
|
166
|
+
listTools(): Promise<MCPTool[]>;
|
|
167
|
+
callTool(name: string, args: Record<string, unknown>): Promise<MCPCallResult>;
|
|
168
|
+
close(): Promise<void>;
|
|
169
|
+
}
|
|
170
|
+
interface MCPCallResult {
|
|
171
|
+
content?: Array<{
|
|
172
|
+
type: string;
|
|
173
|
+
text?: string;
|
|
174
|
+
[key: string]: unknown;
|
|
175
|
+
}>;
|
|
176
|
+
structuredContent?: unknown;
|
|
177
|
+
isError?: boolean;
|
|
178
|
+
}
|
|
179
|
+
interface MCPServerStreamableHttpOptions extends MCPServerOptions {
|
|
180
|
+
url: string;
|
|
181
|
+
/** Sent on every request: auth goes here. */
|
|
182
|
+
headers?: Record<string, string>;
|
|
183
|
+
fetch?: typeof fetch;
|
|
184
|
+
}
|
|
185
|
+
/** A remote MCP server over Streamable HTTP. Speaks stateless MCP, and falls back to the session handshake for older servers. */
|
|
186
|
+
declare class MCPServerStreamableHttp implements MCPServer {
|
|
187
|
+
readonly name: string;
|
|
188
|
+
readonly options: MCPServerStreamableHttpOptions;
|
|
189
|
+
private mode;
|
|
190
|
+
private sessionHeaders;
|
|
191
|
+
private tools;
|
|
192
|
+
constructor(options: MCPServerStreamableHttpOptions);
|
|
193
|
+
connect(): Promise<void>;
|
|
194
|
+
listTools(): Promise<MCPTool[]>;
|
|
195
|
+
callTool(name: string, args: Record<string, unknown>): Promise<MCPCallResult>;
|
|
196
|
+
close(): Promise<void>;
|
|
197
|
+
private request;
|
|
198
|
+
private handshake;
|
|
199
|
+
private post;
|
|
200
|
+
}
|
|
201
|
+
interface MCPServerStdioOptions extends MCPServerOptions {
|
|
202
|
+
command: string;
|
|
203
|
+
args?: string[];
|
|
204
|
+
env?: Record<string, string>;
|
|
205
|
+
cwd?: string;
|
|
206
|
+
}
|
|
207
|
+
/** A local MCP server started as a process (Node only). */
|
|
208
|
+
declare class MCPServerStdio implements MCPServer {
|
|
209
|
+
readonly name: string;
|
|
210
|
+
readonly options: MCPServerStdioOptions;
|
|
211
|
+
private child;
|
|
212
|
+
private starting;
|
|
213
|
+
private pending;
|
|
214
|
+
private tools;
|
|
215
|
+
private stderr;
|
|
216
|
+
constructor(options: MCPServerStdioOptions);
|
|
217
|
+
connect(): Promise<void>;
|
|
218
|
+
listTools(): Promise<MCPTool[]>;
|
|
219
|
+
callTool(name: string, args: Record<string, unknown>): Promise<MCPCallResult>;
|
|
220
|
+
close(): Promise<void>;
|
|
221
|
+
private start;
|
|
222
|
+
private request;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* What run() can take besides text: messages with images and files.
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* await run(agent, [
|
|
230
|
+
* { role: 'user', content: [
|
|
231
|
+
* { type: 'input_text', text: 'What does this invoice owe?' },
|
|
232
|
+
* { type: 'input_file', filename: 'invoice.pdf', file_data: 'data:application/pdf;base64,...' },
|
|
233
|
+
* { type: 'input_image', image_url: 'https://example.com/receipt.jpg' },
|
|
234
|
+
* ] },
|
|
235
|
+
* ]);
|
|
236
|
+
* ```
|
|
237
|
+
*
|
|
238
|
+
* Same shape as OpenAI's Responses input. Images reach models that can see
|
|
239
|
+
* them (a text-only model is swapped for one that can, for that turn); PDFs
|
|
240
|
+
* and text files are read on Cencori and given to the model as text.
|
|
241
|
+
*/
|
|
242
|
+
type InputContentPart = {
|
|
243
|
+
type: 'input_text';
|
|
244
|
+
text: string;
|
|
245
|
+
} | {
|
|
246
|
+
type: 'input_image';
|
|
247
|
+
image_url: string;
|
|
248
|
+
detail?: 'auto' | 'low' | 'high';
|
|
249
|
+
} | {
|
|
250
|
+
type: 'input_file';
|
|
251
|
+
filename: string;
|
|
252
|
+
file_data: string;
|
|
253
|
+
};
|
|
254
|
+
interface AgentInputItem {
|
|
255
|
+
/** Optional, as in OpenAI's shorthand; Cencori treats { role, content } as a message. */
|
|
256
|
+
type?: 'message';
|
|
257
|
+
role: 'user';
|
|
258
|
+
content: string | InputContentPart[];
|
|
259
|
+
}
|
|
260
|
+
type AgentInput = string | AgentInputItem[];
|
|
261
|
+
/** The text in an input, for guardrails and anything else that reads words. */
|
|
262
|
+
declare function inputText(input: AgentInput): string;
|
|
263
|
+
/** An image part from a URL or a data URL. */
|
|
264
|
+
declare function image(url: string, detail?: 'auto' | 'low' | 'high'): InputContentPart;
|
|
265
|
+
/** A file part from bytes (Node Buffer / Uint8Array) or a data URL. */
|
|
266
|
+
declare function file(filename: string, data: string | Uint8Array, mimeType?: string): InputContentPart;
|
|
267
|
+
|
|
120
268
|
interface TransportOptions {
|
|
121
269
|
/** Secret project key (csk_...). Defaults to the CENCORI_API_KEY environment variable. */
|
|
122
270
|
apiKey?: string;
|
|
@@ -235,6 +383,16 @@ type RunStreamEvent = {
|
|
|
235
383
|
} | {
|
|
236
384
|
type: 'interruption';
|
|
237
385
|
interruptions: ToolApprovalItem[];
|
|
386
|
+
}
|
|
387
|
+
/** The agent handed the conversation to a person (humanHandoff). */
|
|
388
|
+
| {
|
|
389
|
+
type: 'human_handoff';
|
|
390
|
+
reason: string;
|
|
391
|
+
agentName: string;
|
|
392
|
+
}
|
|
393
|
+
/** A person is handling the conversation: the message was kept for them, no answer from the agent. */
|
|
394
|
+
| {
|
|
395
|
+
type: 'with_human';
|
|
238
396
|
};
|
|
239
397
|
interface PendingPause {
|
|
240
398
|
actionId: string;
|
|
@@ -298,6 +456,12 @@ interface RunResult<Output = string> {
|
|
|
298
456
|
/** Messages, tool calls and handoffs in this run, in order. */
|
|
299
457
|
newItems: RunItem[];
|
|
300
458
|
usage: Usage;
|
|
459
|
+
/**
|
|
460
|
+
* A person is handling this conversation (the agent handed it over with
|
|
461
|
+
* humanHandoff, or someone stepped in): the message was kept for them and
|
|
462
|
+
* the agent didn't answer. See humanReply / releaseToAgent.
|
|
463
|
+
*/
|
|
464
|
+
withHuman: boolean;
|
|
301
465
|
}
|
|
302
466
|
/** run(..., { stream: true }): iterate events as they happen, then await completed. */
|
|
303
467
|
interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEvent> {
|
|
@@ -317,10 +481,10 @@ interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEven
|
|
|
317
481
|
* Pass `{ stream: true }` for events as they happen, `{ sessionId }` to
|
|
318
482
|
* continue a conversation, or a RunState to resume after approvals.
|
|
319
483
|
*/
|
|
320
|
-
declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input:
|
|
484
|
+
declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: AgentInput | RunState, options: RunOptions<Ctx> & {
|
|
321
485
|
stream: true;
|
|
322
486
|
}): StreamedRunResult<Out>;
|
|
323
|
-
declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input:
|
|
487
|
+
declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: AgentInput | RunState, options?: RunOptions<Ctx> & {
|
|
324
488
|
stream?: false;
|
|
325
489
|
}): Promise<RunResult<Out>>;
|
|
326
490
|
|
|
@@ -390,6 +554,12 @@ interface AgentOptions<Ctx = unknown, Out = string> {
|
|
|
390
554
|
* add here run in your process on top. Usually set with Agent.fromCencori().
|
|
391
555
|
*/
|
|
392
556
|
cencoriAgentId?: string;
|
|
557
|
+
/**
|
|
558
|
+
* MCP servers whose tools this agent can use, next to its own. They connect
|
|
559
|
+
* from your process (MCPServerStreamableHttp for remote servers,
|
|
560
|
+
* MCPServerStdio for local ones).
|
|
561
|
+
*/
|
|
562
|
+
mcpServers?: MCPServer[];
|
|
393
563
|
}
|
|
394
564
|
/** The model an agent uses when none is given: GPT OSS 120B on Cerebras, chosen for speed. */
|
|
395
565
|
declare const DEFAULT_MODEL = "gpt-oss-120b";
|
|
@@ -419,6 +589,7 @@ declare class Agent<Ctx = unknown, Out = string> {
|
|
|
419
589
|
readonly outputGuardrails: OutputGuardrail<Ctx>[];
|
|
420
590
|
readonly widgets: boolean;
|
|
421
591
|
readonly cencoriAgentId?: string;
|
|
592
|
+
readonly mcpServers: MCPServer[];
|
|
422
593
|
constructor(options: AgentOptions<Ctx, Out>);
|
|
423
594
|
/** A copy with some options changed. */
|
|
424
595
|
clone(overrides: Partial<AgentOptions<Ctx, Out>>): Agent<Ctx, Out>;
|
|
@@ -435,6 +606,12 @@ declare class Agent<Ctx = unknown, Out = string> {
|
|
|
435
606
|
static fromCencori<Ctx = unknown>(agentId: string, options?: Omit<AgentOptions<Ctx, string>, 'cencoriAgentId' | 'name'> & {
|
|
436
607
|
name?: string;
|
|
437
608
|
}): Agent<Ctx, string>;
|
|
609
|
+
/**
|
|
610
|
+
* Every tool this agent can call: its own, then its MCP servers' (fetched
|
|
611
|
+
* from each server, once per server unless it says otherwise). An MCP tool
|
|
612
|
+
* whose name is taken gets its server's name in front.
|
|
613
|
+
*/
|
|
614
|
+
resolveTools(): Promise<FunctionTool<Ctx>[]>;
|
|
438
615
|
/** The tool name a handoff to this agent goes by. */
|
|
439
616
|
static handoffToolName(agent: Agent<any>): string;
|
|
440
617
|
/** Instructions for this run, resolving a function if given. */
|
|
@@ -521,4 +698,57 @@ declare function toAgentChatStream(streamed: StreamedRunResult<unknown>, options
|
|
|
521
698
|
secret: string;
|
|
522
699
|
}): ReadableStream<Uint8Array>;
|
|
523
700
|
|
|
524
|
-
|
|
701
|
+
/**
|
|
702
|
+
* Handing a conversation to a person.
|
|
703
|
+
*
|
|
704
|
+
* Give an agent the humanHandoff() tool and it can pass the conversation to
|
|
705
|
+
* your team: it says so, then goes quiet. While a person handles it, the
|
|
706
|
+
* user's messages are kept for them (run() returns `withHuman: true` instead
|
|
707
|
+
* of an answer). Your team replies with humanReply() and hands it back with
|
|
708
|
+
* releaseToAgent(); it also goes back on its own after 30 quiet minutes. The
|
|
709
|
+
* agent is then told what was said, and carries on.
|
|
710
|
+
*
|
|
711
|
+
* ```ts
|
|
712
|
+
* const support = new Agent({
|
|
713
|
+
* name: 'Support',
|
|
714
|
+
* tools: [lookupOrder, humanHandoff({ onHandoff: ({ sessionId, reason }) => slack.post(`#support: ${reason} ${sessionId}`) })],
|
|
715
|
+
* });
|
|
716
|
+
* ```
|
|
717
|
+
*/
|
|
718
|
+
declare const HUMAN_HANDOFF_TOOL = "handoff_to_human";
|
|
719
|
+
interface HumanHandoffOptions<Ctx = unknown> {
|
|
720
|
+
/** When the model should use it. */
|
|
721
|
+
description?: string;
|
|
722
|
+
/** Tell your team: post to Slack, open a ticket, page someone. */
|
|
723
|
+
onHandoff?: (event: {
|
|
724
|
+
sessionId: string;
|
|
725
|
+
reason: string;
|
|
726
|
+
runContext: RunContext<Ctx>;
|
|
727
|
+
}) => void | Promise<void>;
|
|
728
|
+
}
|
|
729
|
+
declare function humanHandoff<Ctx = unknown>(options?: HumanHandoffOptions<Ctx>): FunctionTool<Ctx>;
|
|
730
|
+
interface HumanMessage {
|
|
731
|
+
id: string;
|
|
732
|
+
/** 'user' (your end user), 'human' (your team), 'agent'. */
|
|
733
|
+
from: 'user' | 'human' | 'agent';
|
|
734
|
+
text: string;
|
|
735
|
+
at: string;
|
|
736
|
+
}
|
|
737
|
+
interface HumanStatus {
|
|
738
|
+
handledBy: 'human' | 'agent';
|
|
739
|
+
handoff: {
|
|
740
|
+
reason: string;
|
|
741
|
+
at: string;
|
|
742
|
+
} | null;
|
|
743
|
+
messages: HumanMessage[];
|
|
744
|
+
}
|
|
745
|
+
/** A person on your team replies in the conversation (and keeps it with them). */
|
|
746
|
+
declare function humanReply(sessionId: string, text: string, options?: TransportOptions): Promise<HumanMessage>;
|
|
747
|
+
/** Hand the conversation back to the agent. */
|
|
748
|
+
declare function releaseToAgent(sessionId: string, options?: TransportOptions): Promise<void>;
|
|
749
|
+
/** Who's handling the conversation, and what was said while a person was (optionally only after a time). */
|
|
750
|
+
declare function humanStatus(sessionId: string, options?: TransportOptions & {
|
|
751
|
+
after?: string;
|
|
752
|
+
}): Promise<HumanStatus>;
|
|
753
|
+
|
|
754
|
+
export { Agent, type AgentChatHandlerOptions, type AgentInput, type AgentInputItem, type AgentOptions, AgentsError, CencoriRunError, DEFAULT_MODEL, type FunctionTool, type GuardrailResult, GuardrailTripwireTriggered, HUMAN_HANDOFF_TOOL, type HumanHandoffOptions, type HumanMessage, type HumanStatus, type InputContentPart, type InputGuardrail, type JsonSchema, type MCPCallResult, type MCPServer, type MCPServerOptions, MCPServerStdio, type MCPServerStdioOptions, MCPServerStreamableHttp, type MCPServerStreamableHttpOptions, type MCPTool, 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, file, humanHandoff, humanReply, humanStatus, image, inputText, releaseToAgent, run, toAgentChatStream, tool };
|