@voltagent/core 0.1.35 → 0.1.36

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/index.d.ts CHANGED
@@ -858,6 +858,7 @@ interface CommonGenerateOptions {
858
858
  historyEntryId?: string;
859
859
  operationContext?: OperationContext;
860
860
  userContext?: Map<string | symbol, unknown>;
861
+ streamEventForwarder?: (event: any) => Promise<void>;
861
862
  }
862
863
  /**
863
864
  * Public-facing generate options for external users
@@ -957,6 +958,17 @@ type AgentHandoffOptions = {
957
958
  * Optional user-defined context to be passed from the supervisor agent
958
959
  */
959
960
  userContext?: Map<string | symbol, unknown>;
961
+ /**
962
+ * Optional real-time event forwarder function
963
+ * Used to forward SubAgent events to parent stream in real-time
964
+ */
965
+ forwardEvent?: (event: {
966
+ type: string;
967
+ data: any;
968
+ timestamp: string;
969
+ subAgentId: string;
970
+ subAgentName: string;
971
+ }) => Promise<void>;
960
972
  };
961
973
  /**
962
974
  * Result of a handoff to another agent
@@ -982,6 +994,16 @@ interface AgentHandoffResult {
982
994
  * Error information if the handoff failed
983
995
  */
984
996
  error?: Error | string;
997
+ /**
998
+ * Stream events captured from sub-agent for forwarding to parent
999
+ */
1000
+ streamEvents?: Array<{
1001
+ type: string;
1002
+ data: any;
1003
+ timestamp: string;
1004
+ subAgentId: string;
1005
+ subAgentName: string;
1006
+ }>;
985
1007
  }
986
1008
  /**
987
1009
  * Context for a specific agent operation (e.g., one generateText call)
@@ -1195,6 +1217,40 @@ type ProviderTextResponse<TOriginalResponse> = {
1195
1217
  */
1196
1218
  finishReason?: string;
1197
1219
  };
1220
+ type TextDeltaStreamPart = {
1221
+ type: "text-delta";
1222
+ textDelta: string;
1223
+ };
1224
+ type ReasoningStreamPart = {
1225
+ type: "reasoning";
1226
+ reasoning: string;
1227
+ };
1228
+ type SourceStreamPart = {
1229
+ type: "source";
1230
+ source: string;
1231
+ };
1232
+ type ToolCallStreamPart = {
1233
+ type: "tool-call";
1234
+ toolCallId: string;
1235
+ toolName: string;
1236
+ args: Record<string, any>;
1237
+ };
1238
+ type ToolResultStreamPart = {
1239
+ type: "tool-result";
1240
+ toolCallId: string;
1241
+ toolName: string;
1242
+ result: any;
1243
+ };
1244
+ type FinishStreamPart = {
1245
+ type: "finish";
1246
+ finishReason?: string;
1247
+ usage?: UsageInfo;
1248
+ };
1249
+ type ErrorStreamPart = {
1250
+ type: "error";
1251
+ error: Error;
1252
+ };
1253
+ type StreamPart = TextDeltaStreamPart | ReasoningStreamPart | SourceStreamPart | ToolCallStreamPart | ToolResultStreamPart | FinishStreamPart | ErrorStreamPart;
1198
1254
  /**
1199
1255
  * Response type for text streaming operations
1200
1256
  */
@@ -1207,6 +1263,12 @@ type ProviderTextStreamResponse<TOriginalResponse> = {
1207
1263
  * Text stream for consuming the response
1208
1264
  */
1209
1265
  textStream: AsyncIterableStream<string>;
1266
+ /**
1267
+ * Full stream for consuming all events (text, tool calls, reasoning, etc.)
1268
+ * This provides access to the complete stream of events from the provider
1269
+ * Optional - only available in providers that support it
1270
+ */
1271
+ fullStream?: AsyncIterable<StreamPart>;
1210
1272
  };
1211
1273
  /**
1212
1274
  * Response type for object generation operations
@@ -2980,6 +3042,72 @@ declare class CustomEndpointError extends Error {
2980
3042
  constructor(message: string);
2981
3043
  }
2982
3044
 
3045
+ /**
3046
+ * Basic type definitions for VoltAgent Core
3047
+ */
3048
+
3049
+ /**
3050
+ * Server configuration options for VoltAgent
3051
+ */
3052
+ type ServerOptions = {
3053
+ /**
3054
+ * Whether to automatically start the server
3055
+ * @default true
3056
+ */
3057
+ autoStart?: boolean;
3058
+ /**
3059
+ * Port number for the server
3060
+ * @default 3141 (or next available port)
3061
+ */
3062
+ port?: number;
3063
+ /**
3064
+ * Optional flag to enable/disable Swagger UI
3065
+ * By default:
3066
+ * - In development (NODE_ENV !== 'production'): Swagger UI is enabled
3067
+ * - In production (NODE_ENV === 'production'): Swagger UI is disabled
3068
+ */
3069
+ enableSwaggerUI?: boolean;
3070
+ /**
3071
+ * Optional array of custom endpoint definitions to register with the API server
3072
+ */
3073
+ customEndpoints?: CustomEndpointDefinition[];
3074
+ };
3075
+ /**
3076
+ * VoltAgent constructor options
3077
+ */
3078
+ type VoltAgentOptions = {
3079
+ agents: Record<string, Agent<any>>;
3080
+ /**
3081
+ * Server configuration options
3082
+ */
3083
+ server?: ServerOptions;
3084
+ /**
3085
+ * @deprecated Use `server.port` instead
3086
+ */
3087
+ port?: number;
3088
+ /**
3089
+ * @deprecated Use `server.autoStart` instead
3090
+ */
3091
+ autoStart?: boolean;
3092
+ checkDependencies?: boolean;
3093
+ /**
3094
+ * @deprecated Use `server.customEndpoints` instead
3095
+ */
3096
+ customEndpoints?: CustomEndpointDefinition[];
3097
+ /**
3098
+ * @deprecated Use `server.enableSwaggerUI` instead
3099
+ */
3100
+ enableSwaggerUI?: boolean;
3101
+ /**
3102
+ * Optional OpenTelemetry SpanExporter instance or array of instances.
3103
+ * or a VoltAgentExporter instance or array of instances.
3104
+ * If provided, VoltAgent will attempt to initialize and register
3105
+ * a NodeTracerProvider with a BatchSpanProcessor for the given exporter(s).
3106
+ * It's recommended to only provide this in one VoltAgent instance per application process.
3107
+ */
3108
+ telemetryExporter?: (SpanExporter | VoltAgentExporter) | (SpanExporter | VoltAgentExporter)[];
3109
+ };
3110
+
2983
3111
  /**
2984
3112
  * Enum defining the next action to take after a reasoning step.
2985
3113
  */
@@ -3009,8 +3137,8 @@ declare const ReasoningStepSchema: z.ZodObject<{
3009
3137
  id: string;
3010
3138
  historyEntryId: string;
3011
3139
  agentId: string;
3012
- timestamp: string;
3013
3140
  reasoning: string;
3141
+ timestamp: string;
3014
3142
  confidence: number;
3015
3143
  action?: string | undefined;
3016
3144
  result?: string | undefined;
@@ -3021,8 +3149,8 @@ declare const ReasoningStepSchema: z.ZodObject<{
3021
3149
  id: string;
3022
3150
  historyEntryId: string;
3023
3151
  agentId: string;
3024
- timestamp: string;
3025
3152
  reasoning: string;
3153
+ timestamp: string;
3026
3154
  action?: string | undefined;
3027
3155
  result?: string | undefined;
3028
3156
  next_action?: NextAction | undefined;
@@ -3054,44 +3182,6 @@ type CreateReasoningToolsOptions = {
3054
3182
  */
3055
3183
  declare const createReasoningTools: (options?: CreateReasoningToolsOptions) => Toolkit;
3056
3184
 
3057
- /**
3058
- * Basic type definitions for VoltAgent Core
3059
- */
3060
- /**
3061
- * Retry configuration for error handling
3062
- */
3063
- interface RetryConfig {
3064
- /**
3065
- * Maximum number of retry attempts
3066
- * @default 3
3067
- */
3068
- maxRetries?: number;
3069
- /**
3070
- * Initial delay between retries in milliseconds
3071
- * @default 1000
3072
- */
3073
- initialDelay?: number;
3074
- /**
3075
- * Backoff multiplier for exponential backoff
3076
- * @default 2
3077
- */
3078
- backoffMultiplier?: number;
3079
- /**
3080
- * Maximum delay between retries in milliseconds
3081
- * @default 30000
3082
- */
3083
- maxDelay?: number;
3084
- /**
3085
- * Callback function called when an error occurs
3086
- * Return true to retry, false to abort
3087
- * @param error The error that occurred
3088
- * @param attempt Current attempt number (1-based)
3089
- * @param maxRetries Maximum number of retries
3090
- * @returns Boolean indicating whether to retry
3091
- */
3092
- onError?: ((error: Error, attempt: number, maxRetries: number) => boolean | Promise<boolean>) | null;
3093
- }
3094
-
3095
3185
  /**
3096
3186
  * Prompt management utilities for agent prompt tuning
3097
3187
  */
@@ -3325,9 +3415,10 @@ type MCPClientConfig = {
3325
3415
  /**
3326
3416
  * MCP server configuration options
3327
3417
  */
3328
- type MCPServerConfig = HTTPServerConfig | StdioServerConfig;
3418
+ type MCPServerConfig = HTTPServerConfig | SSEServerConfig | StreamableHTTPServerConfig | StdioServerConfig;
3329
3419
  /**
3330
- * HTTP-based MCP server configuration via SSE
3420
+ * HTTP-based MCP server configuration with automatic fallback
3421
+ * Tries streamable HTTP first, falls back to SSE if not supported
3331
3422
  */
3332
3423
  type HTTPServerConfig = {
3333
3424
  /**
@@ -3342,11 +3433,53 @@ type HTTPServerConfig = {
3342
3433
  * Request initialization options
3343
3434
  */
3344
3435
  requestInit?: RequestInit;
3436
+ /**
3437
+ * Event source initialization options (used for SSE fallback)
3438
+ */
3439
+ eventSourceInit?: EventSourceInit;
3440
+ };
3441
+ /**
3442
+ * SSE-based MCP server configuration (explicit SSE transport)
3443
+ */
3444
+ type SSEServerConfig = {
3445
+ /**
3446
+ * Type of server connection
3447
+ */
3448
+ type: "sse";
3449
+ /**
3450
+ * URL of the MCP server
3451
+ */
3452
+ url: string;
3453
+ /**
3454
+ * Request initialization options
3455
+ */
3456
+ requestInit?: RequestInit;
3345
3457
  /**
3346
3458
  * Event source initialization options
3347
3459
  */
3348
3460
  eventSourceInit?: EventSourceInit;
3349
3461
  };
3462
+ /**
3463
+ * Streamable HTTP-based MCP server configuration (no fallback)
3464
+ */
3465
+ type StreamableHTTPServerConfig = {
3466
+ /**
3467
+ * Type of server connection
3468
+ */
3469
+ type: "streamable-http";
3470
+ /**
3471
+ * URL of the MCP server
3472
+ */
3473
+ url: string;
3474
+ /**
3475
+ * Request initialization options
3476
+ */
3477
+ requestInit?: RequestInit;
3478
+ /**
3479
+ * Session ID for the connection
3480
+ */
3481
+ sessionId?: string;
3482
+ };
3350
3483
  /**
3351
3484
  * Stdio-based MCP server configuration
3352
3485
  */
@@ -3459,6 +3592,18 @@ declare class MCPClient extends EventEmitter {
3459
3592
  * Information identifying this client to the server.
3460
3593
  */
3461
3594
  private readonly clientInfo;
3595
+ /**
3596
+ * Server configuration for fallback attempts.
3597
+ */
3598
+ private readonly serverConfig;
3599
+ /**
3600
+ * Whether to attempt SSE fallback if streamable HTTP fails.
3601
+ */
3602
+ private shouldAttemptFallback;
3603
+ /**
3604
+ * Client capabilities for re-initialization.
3605
+ */
3606
+ private readonly capabilities;
3462
3607
  /**
3463
3608
  * Creates a new MCP client instance.
3464
3609
  * @param config Configuration for the client, including server details and client identity.
@@ -3473,6 +3618,11 @@ declare class MCPClient extends EventEmitter {
3473
3618
  * Idempotent: does nothing if already connected.
3474
3619
  */
3475
3620
  connect(): Promise<void>;
3621
+ /**
3622
+ * Attempts to connect using SSE transport as a fallback.
3623
+ * @param originalError The error from the initial connection attempt.
3624
+ */
3625
+ private attemptSSEFallback;
3476
3626
  /**
3477
3627
  * Closes the connection to the MCP server.
3478
3628
  * Idempotent: does nothing if not connected.
@@ -3517,6 +3667,18 @@ declare class MCPClient extends EventEmitter {
3517
3667
  * @returns True if the configuration type is 'http', false otherwise.
3518
3668
  */
3519
3669
  private isHTTPServer;
3670
+ /**
3671
+ * Type guard to check if a server configuration is for an SSE server.
3672
+ * @param server The server configuration object.
3673
+ * @returns True if the configuration type is 'sse', false otherwise.
3674
+ */
3675
+ private isSSEServer;
3676
+ /**
3677
+ * Type guard to check if a server configuration is for a Streamable HTTP server.
3678
+ * @param server The server configuration object.
3679
+ * @returns True if the configuration type is 'streamable-http', false otherwise.
3680
+ */
3681
+ private isStreamableHTTPServer;
3520
3682
  /**
3521
3683
  * Type guard to check if a server configuration is for a Stdio server.
3522
3684
  * @param server The server configuration object.
@@ -3691,24 +3853,6 @@ declare function registerCustomEndpoint(endpoint: CustomEndpointDefinition): voi
3691
3853
  */
3692
3854
  declare function registerCustomEndpoints(endpoints: CustomEndpointDefinition[]): void;
3693
3855
 
3694
- type VoltAgentOptions = {
3695
- agents: Record<string, Agent<any>>;
3696
- port?: number;
3697
- autoStart?: boolean;
3698
- checkDependencies?: boolean;
3699
- /**
3700
- * Optional array of custom endpoint definitions to register with the API server
3701
- */
3702
- customEndpoints?: CustomEndpointDefinition[];
3703
- /**
3704
- * Optional OpenTelemetry SpanExporter instance or array of instances.
3705
- * or a VoltAgentExporter instance or array of instances.
3706
- * If provided, VoltAgent will attempt to initialize and register
3707
- * a NodeTracerProvider with a BatchSpanProcessor for the given exporter(s).
3708
- * It's recommended to only provide this in one VoltAgent instance per application process.
3709
- */
3710
- telemetryExporter?: (SpanExporter | VoltAgentExporter) | (SpanExporter | VoltAgentExporter)[];
3711
- };
3712
3856
  /**
3713
3857
  * Main VoltAgent class for managing agents and server
3714
3858
  */
@@ -3716,6 +3860,8 @@ declare class VoltAgent {
3716
3860
  private registry;
3717
3861
  private serverStarted;
3718
3862
  private customEndpoints;
3863
+ private serverConfig;
3864
+ private serverOptions;
3719
3865
  constructor(options: VoltAgentOptions);
3720
3866
  /**
3721
3867
  * Check for dependency updates
@@ -3761,4 +3907,4 @@ declare class VoltAgent {
3761
3907
  shutdownTelemetry(): Promise<void>;
3762
3908
  }
3763
3909
 
3764
- export { Agent, AgentErrorEvent, AgentHistoryEntry, AgentHookOnEnd, AgentHookOnHandoff, AgentHookOnStart, AgentHookOnToolEnd, AgentHookOnToolStart, AgentHooks, AgentOptions, AgentRegistry, AgentResponse, AgentStartEvent, AgentStartEventMetadata, AgentSuccessEvent, AgentSuccessEventMetadata, AgentTool, AllowedVariableValue, AnyToolConfig, AsyncIterableStream, BaseEventMetadata, BaseLLMOptions, BaseMessage, BaseRetriever, BaseTimelineEvent, BaseTool, BaseToolCall, ClientInfo, Conversation, ConversationQueryOptions, CreateConversationInput, CreateReasoningToolsOptions, CustomEndpointDefinition, CustomEndpointError, CustomEndpointHandler, DEFAULT_INSTRUCTIONS, DataContent, EventStatus, ExtractVariableNames, FEW_SHOT_EXAMPLES, FilePart, GenerateObjectOptions, GenerateTextOptions, HTTPServerConfig, HistoryStatus, HttpMethod, ImagePart, InMemoryStorage, InferGenerateObjectResponse, InferGenerateTextResponse, InferMessage, InferModel, InferProviderParams, InferStreamResponse, InferTool, LLMProvider, LibSQLStorage, MCPClient, MCPClientConfig, MCPClientEvents, MCPConfiguration, MCPOptions, MCPServerConfig, MCPToolCall, MCPToolResult, Memory, MemoryEventMetadata, MemoryManager, MemoryMessage, MemoryOptions, MemoryReadErrorEvent, MemoryReadStartEvent, MemoryReadSuccessEvent, MemoryWriteErrorEvent, MemoryWriteStartEvent, MemoryWriteSuccessEvent, MessageContent, MessageFilterOptions, MessageRole, ModelToolCall, NewTimelineEvent, NextAction, NodeType, OnEndHookArgs, OnHandoffHookArgs, OnStartHookArgs, OnToolEndHookArgs, OnToolStartHookArgs, OperationContext, PackageUpdateInfo, PromptCreator, PromptTemplate, ProviderObjectResponse, ProviderObjectStreamResponse, ProviderParams, ProviderResponse, ProviderTextResponse, ProviderTextStreamResponse, ReadableStreamType, ReasoningStep, ReasoningStepSchema, ReasoningToolExecuteOptions, RetrieveOptions, Retriever, RetrieverErrorEvent, RetrieverOptions, RetrieverStartEvent, RetrieverSuccessEvent, RetryConfig, StandardEventData, StandardTimelineEvent, StdioServerConfig, StepChunkCallback, StepFinishCallback, StepWithContent, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, TemplateVariables, TextPart, TimelineEventCoreLevel, TimelineEventCoreStatus, TimelineEventCoreType, Tool, ToolCall, ToolErrorEvent, ToolErrorInfo, ToolExecuteOptions, ToolExecutionContext, ToolManager, ToolOptions, ToolSchema, ToolStartEvent, ToolStatus, ToolStatusInfo, ToolSuccessEvent, Toolkit, ToolsetMap, ToolsetWithTools, TransportError, Usage, UsageInfo, Voice, VoiceEventData, VoiceEventType, VoiceMetadata, VoiceOptions, VoltAgent, VoltAgentError, VoltAgentExporter, VoltAgentExporterOptions, checkForUpdates, createAsyncIterableStream, createHooks, createNodeId, createPrompt, createReasoningTools, createRetrieverTool, createTool, createToolkit, VoltAgent as default, getNodeTypeFromNodeId, registerCustomEndpoint, registerCustomEndpoints, safeJsonParse, serializeValueForDebug, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };
3910
+ export { Agent, AgentErrorEvent, AgentHistoryEntry, AgentHookOnEnd, AgentHookOnHandoff, AgentHookOnStart, AgentHookOnToolEnd, AgentHookOnToolStart, AgentHooks, AgentOptions, AgentRegistry, AgentResponse, AgentStartEvent, AgentStartEventMetadata, AgentSuccessEvent, AgentSuccessEventMetadata, AgentTool, AllowedVariableValue, AnyToolConfig, AsyncIterableStream, BaseEventMetadata, BaseLLMOptions, BaseMessage, BaseRetriever, BaseTimelineEvent, BaseTool, BaseToolCall, ClientInfo, Conversation, ConversationQueryOptions, CreateConversationInput, CreateReasoningToolsOptions, CustomEndpointDefinition, CustomEndpointError, CustomEndpointHandler, DEFAULT_INSTRUCTIONS, DataContent, ErrorStreamPart, EventStatus, ExtractVariableNames, FEW_SHOT_EXAMPLES, FilePart, FinishStreamPart, GenerateObjectOptions, GenerateTextOptions, HTTPServerConfig, HistoryStatus, HttpMethod, ImagePart, InMemoryStorage, InferGenerateObjectResponse, InferGenerateTextResponse, InferMessage, InferModel, InferProviderParams, InferStreamResponse, InferTool, LLMProvider, LibSQLStorage, MCPClient, MCPClientConfig, MCPClientEvents, MCPConfiguration, MCPOptions, MCPServerConfig, MCPToolCall, MCPToolResult, Memory, MemoryEventMetadata, MemoryManager, MemoryMessage, MemoryOptions, MemoryReadErrorEvent, MemoryReadStartEvent, MemoryReadSuccessEvent, MemoryWriteErrorEvent, MemoryWriteStartEvent, MemoryWriteSuccessEvent, MessageContent, MessageFilterOptions, MessageRole, ModelToolCall, NewTimelineEvent, NextAction, NodeType, OnEndHookArgs, OnHandoffHookArgs, OnStartHookArgs, OnToolEndHookArgs, OnToolStartHookArgs, OperationContext, PackageUpdateInfo, PromptCreator, PromptTemplate, ProviderObjectResponse, ProviderObjectStreamResponse, ProviderParams, ProviderResponse, ProviderTextResponse, ProviderTextStreamResponse, ReadableStreamType, ReasoningStep, ReasoningStepSchema, ReasoningStreamPart, ReasoningToolExecuteOptions, RetrieveOptions, Retriever, RetrieverErrorEvent, RetrieverOptions, RetrieverStartEvent, RetrieverSuccessEvent, SSEServerConfig, ServerOptions, SourceStreamPart, StandardEventData, StandardTimelineEvent, StdioServerConfig, StepChunkCallback, StepFinishCallback, StepWithContent, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamPart, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, StreamableHTTPServerConfig, TemplateVariables, TextDeltaStreamPart, TextPart, TimelineEventCoreLevel, TimelineEventCoreStatus, TimelineEventCoreType, Tool, ToolCall, ToolCallStreamPart, ToolErrorEvent, ToolErrorInfo, ToolExecuteOptions, ToolExecutionContext, ToolManager, ToolOptions, ToolResultStreamPart, ToolSchema, ToolStartEvent, ToolStatus, ToolStatusInfo, ToolSuccessEvent, Toolkit, ToolsetMap, ToolsetWithTools, TransportError, Usage, UsageInfo, Voice, VoiceEventData, VoiceEventType, VoiceMetadata, VoiceOptions, VoltAgent, VoltAgentError, VoltAgentExporter, VoltAgentExporterOptions, VoltAgentOptions, checkForUpdates, createAsyncIterableStream, createHooks, createNodeId, createPrompt, createReasoningTools, createRetrieverTool, createTool, createToolkit, VoltAgent as default, getNodeTypeFromNodeId, registerCustomEndpoint, registerCustomEndpoints, safeJsonParse, serializeValueForDebug, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };