import type { BaseStepOptions, LlmSpanAllowedInputType, LlmSpanAllowedOutputType, MetricsOptions, RetrieverSpanAllowedOutputType, SerializedStep, StepAllowedInputType, StepAllowedOutputType } from './step.types'; import { BaseStep, Metrics, StepType } from './step.types'; import type { SerializedMetrics } from './step.types'; import type { Message } from '../message.types'; import { MessageRole } from '../message.types'; import type { Document } from '../document.types'; import type { MetricValueType } from '../metrics.types'; import { AgentType } from '../new-api.types'; import type { JsonValue, JsonObject, JsonArray } from '../base.types'; /** * Types of events that can appear in reasoning/multi-turn model outputs. */ export declare enum EventType { message = "message", reasoning = "reasoning", internal_tool_call = "internal_tool_call", image_generation = "image_generation", mcp_call = "mcp_call", mcp_list_tools = "mcp_list_tools", mcp_approval_request = "mcp_approval_request" } /** * Common status values for events. */ export declare enum EventStatus { in_progress = "in_progress", completed = "completed", failed = "failed", cancelled = "cancelled", incomplete = "incomplete" } /** * Base interface for all event types with common fields. */ export interface BaseEvent { type: EventType; id?: string; status?: EventStatus; metadata?: JsonObject; errorMessage?: string; } /** * An output message from the model. */ export interface MessageEvent extends BaseEvent { type: EventType.message; role: MessageRole; content?: string; contentParts?: JsonArray; } /** * Internal reasoning/thinking from the model (e.g., OpenAI o1/o3 reasoning tokens). */ export interface ReasoningEvent extends BaseEvent { type: EventType.reasoning; content?: string; summary?: string; } /** * A tool call executed internally by the model during reasoning. * This represents internal tools like web search, code execution, file search, etc. * that the model invokes (not user-defined functions or MCP tools). */ export interface InternalToolCall extends BaseEvent { type: EventType.internal_tool_call; name: string; input?: JsonObject; output?: JsonObject; } /** * An image generation event from the model. */ export interface ImageGenerationEvent extends BaseEvent { type: EventType.image_generation; prompt?: string; images?: JsonArray; model?: string; } /** * A Model Context Protocol (MCP) tool call. * MCP is a protocol for connecting LLMs to external tools/data sources. * This is distinct from internal tools because it involves external integrations. */ export interface MCPCallEvent extends BaseEvent { type: EventType.mcp_call; toolName?: string; serverName?: string; arguments?: JsonObject; result?: JsonObject; } /** * MCP list tools event - when the model queries available MCP tools. */ export interface MCPListToolsEvent extends BaseEvent { type: EventType.mcp_list_tools; serverName?: string; tools?: JsonArray; } /** * MCP approval request - when human approval is needed for an MCP tool call. */ export interface MCPApprovalRequestEvent extends BaseEvent { type: EventType.mcp_approval_request; toolName?: string; toolInvocation?: JsonObject; approved?: boolean; } /** * Union of all event types. */ export type Event = MessageEvent | ReasoningEvent | InternalToolCall | ImageGenerationEvent | MCPCallEvent | MCPListToolsEvent | MCPApprovalRequestEvent; export interface BaseSpanOptions extends BaseStepOptions { input: StepAllowedInputType; redactedInput?: StepAllowedInputType; } export declare class BaseSpan extends BaseStep { input: StepAllowedInputType; redactedInput?: StepAllowedInputType; constructor(type: StepType, data: BaseSpanOptions); } export interface StepWithChildSpansOptions extends BaseSpanOptions { spans?: Span[]; } export interface SerializedStepWithChildSpans extends SerializedStep { spans?: JsonArray; } export declare class StepWithChildSpans extends BaseSpan { spans: Span[]; constructor(type: StepType, data: StepWithChildSpansOptions); toJSON(): SerializedStepWithChildSpans; addChildSpan(...spans: Span[]): void; } export interface WorkflowSpanOptions extends StepWithChildSpansOptions { input: string; redactedInput?: string; output?: string; redactedOutput?: string; } export declare class WorkflowSpan extends StepWithChildSpans { type: StepType; constructor(data: WorkflowSpanOptions); } export { AgentType }; export interface AgentSpanOptions extends StepWithChildSpansOptions { agentType?: AgentType; } export interface SerializedAgentSpan extends SerializedStepWithChildSpans { agentType: AgentType; } export declare class AgentSpan extends StepWithChildSpans { type: StepType; agentType: AgentType; constructor(data: AgentSpanOptions); toJSON(): SerializedAgentSpan; } export interface LlmMetricsOptions extends MetricsOptions { numInputTokens?: number; numOutputTokens?: number; numTotalTokens?: number; numReasoningTokens?: number; numCachedInputTokens?: number; timeToFirstTokenNs?: number; } export interface SerializedLlmMetrics extends SerializedMetrics { numInputTokens?: number; numOutputTokens?: number; numTotalTokens?: number; numReasoningTokens?: number; numCachedInputTokens?: number; timeToFirstTokenNs?: number; } export declare class LlmMetrics extends Metrics { numInputTokens?: number; numOutputTokens?: number; numTotalTokens?: number; numReasoningTokens?: number; numCachedInputTokens?: number; timeToFirstTokenNs?: number; constructor(options: LlmMetricsOptions); toJSON(): SerializedLlmMetrics; } export interface LlmSpanOptions extends BaseSpanOptions { input: LlmSpanAllowedInputType; redactedInput?: LlmSpanAllowedInputType; output: LlmSpanAllowedOutputType; redactedOutput?: LlmSpanAllowedOutputType; metrics?: LlmMetrics; tools?: JsonObject[]; model?: string; temperature?: number; finishReason?: string; events?: Event[]; } export interface SerializedLlmSpan extends SerializedStep { metrics?: { numInputTokens?: number; numOutputTokens?: number; numTotalTokens?: number; numReasoningTokens?: number; numCachedInputTokens?: number; timeToFirstTokenNs?: number; durationNs?: number; }; [key: string]: MetricValueType | JsonArray | StepAllowedInputType | StepAllowedOutputType | undefined; } export declare class LlmSpan extends BaseSpan { type: StepType; input: Message[]; redactedInput?: Message[]; output: Message; redactedOutput?: Message; metrics: LlmMetrics; tools?: JsonObject[]; model?: string; temperature?: number; finishReason?: string; events?: Event[]; constructor(data: LlmSpanOptions); toJSON(): SerializedLlmSpan; } export interface RetrieverSpanOptions extends BaseSpanOptions { input: string; redactedInput?: string; output?: RetrieverSpanAllowedOutputType; redactedOutput?: RetrieverSpanAllowedOutputType; } export interface SerializedRetrieverSpan extends Omit { output: JsonArray; } export declare class RetrieverSpan extends BaseStep { type: StepType; input: string; redactedInput?: string; output: Document[]; redactedOutput?: Document[]; constructor(data: RetrieverSpanOptions); toJSON(): SerializedRetrieverSpan; } export interface ToolSpanOptions extends Omit { input: JsonValue; redactedInput?: JsonValue; output?: JsonValue; redactedOutput?: JsonValue; toolCallId?: string; } export interface SerializedToolSpan extends SerializedStepWithChildSpans { toolCallId?: string; } export declare class ToolSpan extends StepWithChildSpans { type: StepType; input: string; redactedInput?: string; output: string; redactedOutput?: string; toolCallId?: string; constructor(data: ToolSpanOptions); toJSON(): SerializedToolSpan; } export type Span = WorkflowSpan | AgentSpan | LlmSpan | RetrieverSpan | ToolSpan; /** * Type guard to validate if a value is a valid AgentType */ export declare function isValidAgentType(value: unknown): value is AgentType;