@voltagent/core 0.1.41 → 0.1.43

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
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  import { Span } from '@opentelemetry/api';
3
+ import { Simplify, LiteralUnion } from 'type-fest';
3
4
  import { Context } from 'hono';
4
5
  import { SpanExporter } from '@opentelemetry/sdk-trace-base';
5
6
  import { ClientCapabilities } from '@modelcontextprotocol/sdk/types.js';
@@ -554,6 +555,11 @@ declare class HistoryManager {
554
555
  * Optional VoltAgentExporter for sending telemetry data.
555
556
  */
556
557
  private voltAgentExporter?;
558
+ /**
559
+ * Background queue for non-blocking history operations
560
+ * Uses lower concurrency to preserve operation order when telemetryExporter is enabled
561
+ */
562
+ private historyQueue;
557
563
  /**
558
564
  * Create a new history manager
559
565
  *
@@ -572,11 +578,22 @@ declare class HistoryManager {
572
578
  * This allows the exporter to be set after the HistoryManager is created.
573
579
  */
574
580
  setExporter(exporter: VoltAgentExporter): void;
581
+ /**
582
+ * Get the VoltAgentExporter instance
583
+ * @returns The VoltAgentExporter instance or undefined if not configured
584
+ */
585
+ getExporter(): VoltAgentExporter | undefined;
575
586
  /**
576
587
  * Checks if a VoltAgentExporter is configured for this history manager.
577
588
  * @returns True if an exporter is configured, false otherwise.
578
589
  */
579
590
  isExporterConfigured(): boolean;
591
+ /**
592
+ * Queue a history operation for background processing
593
+ * @param operationId Unique identifier for the operation
594
+ * @param operation The async operation to execute
595
+ */
596
+ private queueHistoryOperation;
580
597
  /**
581
598
  * Add a new history entry
582
599
  *
@@ -591,7 +608,7 @@ declare class HistoryManager {
591
608
  * @param steps - Steps to add
592
609
  * @returns The updated entry or undefined if not found
593
610
  */
594
- addStepsToEntry(entryId: string, steps: StepWithContent[]): Promise<AgentHistoryEntry | undefined>;
611
+ addStepsToEntry(entryId: string, steps: StepWithContent[]): void;
595
612
  /**
596
613
  * Get history entry by ID
597
614
  *
@@ -618,11 +635,12 @@ declare class HistoryManager {
618
635
  */
619
636
  updateEntry(id: string, updates: Partial<Omit<AgentHistoryEntry, "id" | "timestamp"> & {
620
637
  metadata?: Record<string, unknown>;
621
- }>): Promise<AgentHistoryEntry | undefined>;
638
+ }>): void;
622
639
  /**
623
640
  * Persists a timeline event for a history entry.
624
641
  * This is used by the new immutable event system.
625
642
  *
643
+ *
626
644
  * @param historyId - ID of the history entry
627
645
  * @param event - The NewTimelineEvent object to persist
628
646
  * @returns A promise that resolves to the updated entry or undefined if an error occurs
@@ -691,46 +709,104 @@ interface VoltAgentExporterOptions {
691
709
  declare class VoltAgentExporter {
692
710
  private apiClient;
693
711
  readonly publicKey: string;
712
+ /**
713
+ * Internal queue for all telemetry export operations
714
+ * Ensures non-blocking exports that don't interfere with event ordering
715
+ */
716
+ private telemetryQueue;
694
717
  constructor(options: VoltAgentExporterOptions);
695
718
  /**
696
719
  * Exports a single agent history entry.
697
720
  * @param historyEntryData - The agent history data to export.
698
- * This should conform to ExportAgentHistoryPayload.
699
- * @returns A promise that resolves with the response from the telemetry service,
700
- * typically including the ID of the created history entry.
721
+ * @returns A promise that resolves with the response from the telemetry service.
701
722
  */
702
723
  exportHistoryEntry(historyEntryData: ExportAgentHistoryPayload): Promise<{
703
724
  historyEntryId: string;
704
725
  }>;
726
+ /**
727
+ * Exports a single agent history entry asynchronously (non-blocking).
728
+ * Queues the export operation to avoid blocking the calling thread.
729
+ * @param historyEntryData - The agent history data to export.
730
+ */
731
+ exportHistoryEntryAsync(historyEntryData: ExportAgentHistoryPayload): void;
705
732
  /**
706
733
  * Exports a single timeline event.
707
- * (Placeholder for when the 'export-timeline-event' Edge Function is ready)
708
734
  * @param timelineEventData - The timeline event data to export.
709
- * This should conform to ExportTimelineEventPayload.
710
735
  * @returns A promise that resolves with the response from the telemetry service.
711
736
  */
712
737
  exportTimelineEvent(timelineEventData: ExportTimelineEventPayload): Promise<{
713
738
  timelineEventId: string;
714
739
  }>;
740
+ /**
741
+ * Exports a single timeline event asynchronously (non-blocking).
742
+ * Queues the export operation to avoid blocking the calling thread.
743
+ * @param timelineEventData - The timeline event data to export.
744
+ */
745
+ exportTimelineEventAsync(timelineEventData: ExportTimelineEventPayload): void;
715
746
  /**
716
747
  * Exports history steps for a specific agent history entry.
717
- * @param project_id - The project ID associated with the history entry.
718
748
  * @param history_id - The ID of the history entry to export steps for.
719
749
  * @param steps - The steps data to export.
720
- * @returns A promise that resolves with the response from the telemetry service.
750
+ * @returns A promise that resolves when the export is complete.
721
751
  */
722
752
  exportHistorySteps(history_id: string, steps: HistoryStep[]): Promise<void>;
753
+ /**
754
+ * Exports history steps for a specific agent history entry asynchronously (non-blocking).
755
+ * @param history_id - The ID of the history entry to export steps for.
756
+ * @param steps - The steps data to export.
757
+ */
758
+ exportHistoryStepsAsync(history_id: string, steps: HistoryStep[]): void;
723
759
  /**
724
760
  * Updates specific fields of an agent history entry.
725
- * @param project_id - The project ID associated with the history entry.
726
761
  * @param history_id - The ID of the history entry to update.
727
762
  * @param updates - An object containing the fields to update.
728
- * Should conform to Partial<AgentHistoryUpdatableFields>.
729
- * @returns A promise that resolves with the response from the telemetry service.
763
+ * @returns A promise that resolves when the update is complete.
730
764
  */
731
765
  updateHistoryEntry(history_id: string, updates: Partial<AgentHistoryUpdatableFields>): Promise<void>;
766
+ /**
767
+ * Updates specific fields of an agent history entry asynchronously (non-blocking).
768
+ * @param history_id - The ID of the history entry to update.
769
+ * @param updates - An object containing the fields to update.
770
+ */
771
+ updateHistoryEntryAsync(history_id: string, updates: Partial<AgentHistoryUpdatableFields>): void;
732
772
  }
733
773
 
774
+ type StreamEventType = StreamEvent["type"];
775
+ type StreamEvent = StreamEventTextDelta | StreamEventReasoning | StreamEventSource | StreamEventToolCall | StreamEventToolResult | StreamEventFinish | StreamEventError;
776
+ type StreamEventTextDelta = InferStreamEventBase<TextDeltaStreamPart>;
777
+ type StreamEventReasoning = InferStreamEventBase<ReasoningStreamPart>;
778
+ type StreamEventSource = InferStreamEventBase<SourceStreamPart>;
779
+ type StreamEventToolCall = InferStreamEventBase<ToolCallStreamPart>;
780
+ type StreamEventToolResult = InferStreamEventBase<ToolResultStreamPart>;
781
+ type StreamEventFinish = InferStreamEventBase<FinishStreamPart>;
782
+ type StreamEventError = InferStreamEventBase<ErrorStreamPart>;
783
+ type InferStreamEventBase<TStreamPart extends StreamPart> = {
784
+ type: TStreamPart["type"];
785
+ data: InferStreamEventData<TStreamPart> | null;
786
+ timestamp: string;
787
+ subAgentId: string;
788
+ subAgentName: string;
789
+ };
790
+ type InferStreamEventData<TStreamPart extends StreamPart> = Simplify<Omit<TStreamPart, "type" | "subAgentId" | "subAgentName">>;
791
+
792
+ interface StreamEventForwarderOptions {
793
+ forwarder?: (event: StreamEvent) => Promise<void>;
794
+ filterTypes?: LiteralUnion<StreamEventType, string>[];
795
+ addSubAgentPrefix?: boolean;
796
+ }
797
+ /**
798
+ * Forwards SubAgent events to a stream with optional filtering and prefixing
799
+ * @param event - The SubAgent event to forward
800
+ * @param options - Configuration options for forwarding
801
+ */
802
+ declare function streamEventForwarder(event: StreamEvent, options?: StreamEventForwarderOptions): Promise<void>;
803
+ /**
804
+ * Creates a configured streamEventForwarder function
805
+ * @param options - Configuration options
806
+ * @returns A configured forwarder function
807
+ */
808
+ declare function createStreamEventForwarder(options?: StreamEventForwarderOptions): (event: StreamEvent) => Promise<void>;
809
+
734
810
  /**
735
811
  * Options object for dynamic value resolution
736
812
  */
@@ -983,13 +1059,7 @@ type AgentHandoffOptions = {
983
1059
  * Optional real-time event forwarder function
984
1060
  * Used to forward SubAgent events to parent stream in real-time
985
1061
  */
986
- forwardEvent?: (event: {
987
- type: string;
988
- data: any;
989
- timestamp: string;
990
- subAgentId: string;
991
- subAgentName: string;
992
- }) => Promise<void>;
1062
+ forwardEvent?: (event: StreamEvent) => Promise<void>;
993
1063
  };
994
1064
  /**
995
1065
  * Result of a handoff to another agent
@@ -2370,16 +2440,19 @@ declare class MemoryManager {
2370
2440
  * The ID of the resource (agent) that owns this memory manager
2371
2441
  */
2372
2442
  private resourceId;
2443
+ /**
2444
+ * Background queue for memory operations
2445
+ */
2446
+ private backgroundQueue;
2373
2447
  /**
2374
2448
  * Creates a new MemoryManager
2375
2449
  */
2376
2450
  constructor(resourceId: string, memory?: Memory | false, options?: MemoryOptions);
2377
2451
  /**
2378
- * Create and publish a timeline event for memory operations
2452
+ * Create and publish a timeline event for memory operations using the queue
2379
2453
  *
2380
2454
  * @param context - Operation context with history entry info
2381
2455
  * @param event - Timeline event to publish
2382
- * @returns A promise that resolves when the event is published
2383
2456
  */
2384
2457
  private publishTimelineEvent;
2385
2458
  /**
@@ -2391,12 +2464,26 @@ declare class MemoryManager {
2391
2464
  */
2392
2465
  createStepFinishHandler(context: OperationContext, userId?: string, conversationId?: string): (() => void) | ((step: StepWithContent) => Promise<void>);
2393
2466
  /**
2394
- * Prepare conversation context for message generation
2467
+ * Prepare conversation context for message generation (CONTEXT-FIRST OPTIMIZED)
2468
+ * Ensures context is always loaded, optimizes non-critical operations in background
2395
2469
  */
2396
2470
  prepareConversationContext(context: OperationContext, input: string | BaseMessage[], userId?: string, conversationIdParam?: string, contextLimit?: number): Promise<{
2397
2471
  messages: BaseMessage[];
2398
2472
  conversationId: string;
2399
2473
  }>;
2474
+ /**
2475
+ * Handle sequential background operations using the queue
2476
+ * Setup conversation and save input in a single atomic operation
2477
+ */
2478
+ private handleSequentialBackgroundOperations;
2479
+ /**
2480
+ * Ensure conversation exists (background task)
2481
+ */
2482
+ private ensureConversationExists;
2483
+ /**
2484
+ * Save current input (background task)
2485
+ */
2486
+ private saveCurrentInput;
2400
2487
  /**
2401
2488
  * Get the memory instance
2402
2489
  */
@@ -2993,6 +3080,7 @@ declare class Agent<TProvider extends {
2993
3080
  * Helper method to enrich and end an OpenTelemetry span associated with a tool call.
2994
3081
  */
2995
3082
  private _endOtelToolSpan;
3083
+ private publishTimelineEvent;
2996
3084
  /**
2997
3085
  * Create an enhanced fullStream with real-time SubAgent event injection
2998
3086
  */
@@ -3203,23 +3291,23 @@ declare const ReasoningStepSchema: z.ZodObject<{
3203
3291
  title: string;
3204
3292
  id: string;
3205
3293
  historyEntryId: string;
3206
- agentId: string;
3207
3294
  reasoning: string;
3208
3295
  timestamp: string;
3296
+ agentId: string;
3209
3297
  confidence: number;
3210
- action?: string | undefined;
3211
3298
  result?: string | undefined;
3299
+ action?: string | undefined;
3212
3300
  next_action?: NextAction | undefined;
3213
3301
  }, {
3214
3302
  type: "thought" | "analysis";
3215
3303
  title: string;
3216
3304
  id: string;
3217
3305
  historyEntryId: string;
3218
- agentId: string;
3219
3306
  reasoning: string;
3220
3307
  timestamp: string;
3221
- action?: string | undefined;
3308
+ agentId: string;
3222
3309
  result?: string | undefined;
3310
+ action?: string | undefined;
3223
3311
  next_action?: NextAction | undefined;
3224
3312
  confidence?: number | undefined;
3225
3313
  }>;
@@ -3373,31 +3461,6 @@ declare const updateSinglePackage: (packageName: string, packagePath?: string) =
3373
3461
  declare function safeJsonParse(value: string | null | undefined): any;
3374
3462
  declare function serializeValueForDebug(value: unknown): unknown;
3375
3463
 
3376
- interface SubAgentEvent {
3377
- type: string;
3378
- data: any;
3379
- timestamp: string;
3380
- subAgentId: string;
3381
- subAgentName: string;
3382
- }
3383
- interface StreamEventForwarderOptions {
3384
- forwarder?: (event: any) => Promise<void>;
3385
- filterTypes?: string[];
3386
- addSubAgentPrefix?: boolean;
3387
- }
3388
- /**
3389
- * Forwards SubAgent events to a stream with optional filtering and prefixing
3390
- * @param event - The SubAgent event to forward
3391
- * @param options - Configuration options for forwarding
3392
- */
3393
- declare function streamEventForwarder(event: SubAgentEvent, options?: StreamEventForwarderOptions): Promise<void>;
3394
- /**
3395
- * Creates a configured streamEventForwarder function
3396
- * @param options - Configuration options
3397
- * @returns A configured forwarder function
3398
- */
3399
- declare function createStreamEventForwarder(options?: StreamEventForwarderOptions): (event: SubAgentEvent) => Promise<void>;
3400
-
3401
3464
  /**
3402
3465
  * Creates an AgentTool from a retriever, allowing it to be used as a tool in an agent.
3403
3466
  * This is the preferred way to use a retriever as a tool, as it properly maintains the 'this' context.
@@ -3999,4 +4062,4 @@ declare class VoltAgent {
3999
4062
  shutdownTelemetry(): Promise<void>;
4000
4063
  }
4001
4064
 
4002
- 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, DynamicValueOptions, 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, StreamEventForwarderOptions, StreamObjectFinishResult, StreamObjectOnFinishCallback, StreamObjectOptions, StreamPart, StreamTextFinishResult, StreamTextOnFinishCallback, StreamTextOptions, StreamableHTTPServerConfig, SubAgentEvent, 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, createStreamEventForwarder, createTool, createToolkit, VoltAgent as default, getNodeTypeFromNodeId, registerCustomEndpoint, registerCustomEndpoints, safeJsonParse, serializeValueForDebug, streamEventForwarder, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };
4065
+ 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, DynamicValueOptions, 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, StreamEventForwarderOptions, 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, createStreamEventForwarder, createTool, createToolkit, VoltAgent as default, getNodeTypeFromNodeId, registerCustomEndpoint, registerCustomEndpoints, safeJsonParse, serializeValueForDebug, streamEventForwarder, tool, updateAllPackages, updateSinglePackage, zodSchemaToJsonUI };