cencori 1.13.0 → 1.16.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.
@@ -1,5 +1,5 @@
1
- import { W as WidgetNode } from '../protocol-Dq7rZbRX.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-Dq7rZbRX.mjs';
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> {
@@ -222,6 +222,49 @@ declare class MCPServerStdio implements MCPServer {
222
222
  private request;
223
223
  }
224
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
+
225
268
  interface TransportOptions {
226
269
  /** Secret project key (csk_...). Defaults to the CENCORI_API_KEY environment variable. */
227
270
  apiKey?: string;
@@ -340,6 +383,16 @@ type RunStreamEvent = {
340
383
  } | {
341
384
  type: 'interruption';
342
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';
343
396
  };
344
397
  interface PendingPause {
345
398
  actionId: string;
@@ -403,6 +456,12 @@ interface RunResult<Output = string> {
403
456
  /** Messages, tool calls and handoffs in this run, in order. */
404
457
  newItems: RunItem[];
405
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;
406
465
  }
407
466
  /** run(..., { stream: true }): iterate events as they happen, then await completed. */
408
467
  interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEvent> {
@@ -422,10 +481,10 @@ interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEven
422
481
  * Pass `{ stream: true }` for events as they happen, `{ sessionId }` to
423
482
  * continue a conversation, or a RunState to resume after approvals.
424
483
  */
425
- declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: string | RunState, options: RunOptions<Ctx> & {
484
+ declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: AgentInput | RunState, options: RunOptions<Ctx> & {
426
485
  stream: true;
427
486
  }): StreamedRunResult<Out>;
428
- declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: string | RunState, options?: RunOptions<Ctx> & {
487
+ declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: AgentInput | RunState, options?: RunOptions<Ctx> & {
429
488
  stream?: false;
430
489
  }): Promise<RunResult<Out>>;
431
490
 
@@ -639,4 +698,72 @@ declare function toAgentChatStream(streamed: StreamedRunResult<unknown>, options
639
698
  secret: string;
640
699
  }): ReadableStream<Uint8Array>;
641
700
 
642
- export { Agent, type AgentChatHandlerOptions, type AgentOptions, AgentsError, CencoriRunError, DEFAULT_MODEL, type FunctionTool, type GuardrailResult, GuardrailTripwireTriggered, 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, run, toAgentChatStream, tool };
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
+ interface WebSearchToolOptions {
755
+ /** Results per search (1-20). Default 8. */
756
+ limit?: number;
757
+ /** Only search this site, e.g. 'docs.python.org'. */
758
+ domain?: string;
759
+ description?: string;
760
+ }
761
+ declare function webSearch<Ctx = unknown>(options?: WebSearchToolOptions): FunctionTool<Ctx>;
762
+ interface WebFetchToolOptions {
763
+ /** Longest page text given to the model, in characters. Default 20,000. */
764
+ maxChars?: number;
765
+ description?: string;
766
+ }
767
+ declare function webFetch<Ctx = unknown>(options?: WebFetchToolOptions): FunctionTool<Ctx>;
768
+
769
+ 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, type WebFetchToolOptions, type WebSearchToolOptions, WidgetNode, createAgentChatHandler, file, humanHandoff, humanReply, humanStatus, image, inputText, releaseToAgent, run, toAgentChatStream, tool, webFetch, webSearch };
@@ -1,5 +1,5 @@
1
- import { W as WidgetNode } from '../protocol-Dq7rZbRX.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-Dq7rZbRX.js';
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> {
@@ -222,6 +222,49 @@ declare class MCPServerStdio implements MCPServer {
222
222
  private request;
223
223
  }
224
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
+
225
268
  interface TransportOptions {
226
269
  /** Secret project key (csk_...). Defaults to the CENCORI_API_KEY environment variable. */
227
270
  apiKey?: string;
@@ -340,6 +383,16 @@ type RunStreamEvent = {
340
383
  } | {
341
384
  type: 'interruption';
342
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';
343
396
  };
344
397
  interface PendingPause {
345
398
  actionId: string;
@@ -403,6 +456,12 @@ interface RunResult<Output = string> {
403
456
  /** Messages, tool calls and handoffs in this run, in order. */
404
457
  newItems: RunItem[];
405
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;
406
465
  }
407
466
  /** run(..., { stream: true }): iterate events as they happen, then await completed. */
408
467
  interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEvent> {
@@ -422,10 +481,10 @@ interface StreamedRunResult<Output = string> extends AsyncIterable<RunStreamEven
422
481
  * Pass `{ stream: true }` for events as they happen, `{ sessionId }` to
423
482
  * continue a conversation, or a RunState to resume after approvals.
424
483
  */
425
- declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: string | RunState, options: RunOptions<Ctx> & {
484
+ declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: AgentInput | RunState, options: RunOptions<Ctx> & {
426
485
  stream: true;
427
486
  }): StreamedRunResult<Out>;
428
- declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: string | RunState, options?: RunOptions<Ctx> & {
487
+ declare function run<Ctx, Out>(agent: Agent<Ctx, Out>, input: AgentInput | RunState, options?: RunOptions<Ctx> & {
429
488
  stream?: false;
430
489
  }): Promise<RunResult<Out>>;
431
490
 
@@ -639,4 +698,72 @@ declare function toAgentChatStream(streamed: StreamedRunResult<unknown>, options
639
698
  secret: string;
640
699
  }): ReadableStream<Uint8Array>;
641
700
 
642
- export { Agent, type AgentChatHandlerOptions, type AgentOptions, AgentsError, CencoriRunError, DEFAULT_MODEL, type FunctionTool, type GuardrailResult, GuardrailTripwireTriggered, 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, run, toAgentChatStream, tool };
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
+ interface WebSearchToolOptions {
755
+ /** Results per search (1-20). Default 8. */
756
+ limit?: number;
757
+ /** Only search this site, e.g. 'docs.python.org'. */
758
+ domain?: string;
759
+ description?: string;
760
+ }
761
+ declare function webSearch<Ctx = unknown>(options?: WebSearchToolOptions): FunctionTool<Ctx>;
762
+ interface WebFetchToolOptions {
763
+ /** Longest page text given to the model, in characters. Default 20,000. */
764
+ maxChars?: number;
765
+ description?: string;
766
+ }
767
+ declare function webFetch<Ctx = unknown>(options?: WebFetchToolOptions): FunctionTool<Ctx>;
768
+
769
+ 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, type WebFetchToolOptions, type WebSearchToolOptions, WidgetNode, createAgentChatHandler, file, humanHandoff, humanReply, humanStatus, image, inputText, releaseToAgent, run, toAgentChatStream, tool, webFetch, webSearch };