@voltagent/core 0.1.45 → 0.1.47

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
@@ -790,8 +790,8 @@ type InferStreamEventBase<TStreamPart extends StreamPart> = {
790
790
  type InferStreamEventData<TStreamPart extends StreamPart> = Simplify<Omit<TStreamPart, "type" | "subAgentId" | "subAgentName">>;
791
791
 
792
792
  interface StreamEventForwarderOptions {
793
- forwarder?: (event: StreamEvent) => Promise<void>;
794
- filterTypes?: LiteralUnion<StreamEventType, string>[];
793
+ forwarder: (event: StreamEvent) => Promise<void>;
794
+ types: Array<LiteralUnion<StreamEventType, string>> | ReadonlyArray<LiteralUnion<StreamEventType, string>>;
795
795
  addSubAgentPrefix?: boolean;
796
796
  }
797
797
  /**
@@ -799,13 +799,13 @@ interface StreamEventForwarderOptions {
799
799
  * @param event - The SubAgent event to forward
800
800
  * @param options - Configuration options for forwarding
801
801
  */
802
- declare function streamEventForwarder(event: StreamEvent, options?: StreamEventForwarderOptions): Promise<void>;
802
+ declare function streamEventForwarder(event: StreamEvent, options: StreamEventForwarderOptions): Promise<void>;
803
803
  /**
804
804
  * Creates a configured streamEventForwarder function
805
805
  * @param options - Configuration options
806
806
  * @returns A configured forwarder function
807
807
  */
808
- declare function createStreamEventForwarder(options?: StreamEventForwarderOptions): (event: StreamEvent) => Promise<void>;
808
+ declare function createStreamEventForwarder(options: StreamEventForwarderOptions): (event: StreamEvent) => Promise<void>;
809
809
 
810
810
  /**
811
811
  * Options object for dynamic value resolution
@@ -1515,6 +1515,8 @@ interface StepWithContent {
1515
1515
  arguments?: Record<string, any>;
1516
1516
  result?: any;
1517
1517
  usage?: UsageInfo;
1518
+ subAgentId?: string;
1519
+ subAgentName?: string;
1518
1520
  }
1519
1521
  type StepFinishCallback = (step: StepWithContent) => void | Promise<void>;
1520
1522
  type StepChunkCallback = (chunk: any) => void | Promise<void>;
package/dist/index.js CHANGED
@@ -2477,6 +2477,7 @@ var import_dev19 = require("@voltagent/internal/dev");
2477
2477
 
2478
2478
  // src/agent/index.ts
2479
2479
  var import_dev14 = require("@voltagent/internal/dev");
2480
+ var import_ts_pattern2 = require("ts-pattern");
2480
2481
 
2481
2482
  // src/memory/in-memory/index.ts
2482
2483
  var import_dev4 = require("@voltagent/internal/dev");
@@ -3199,8 +3200,8 @@ __name(serializeValueForDebug, "serializeValueForDebug");
3199
3200
 
3200
3201
  // src/utils/streams/stream-event-forwarder.ts
3201
3202
  var import_dev5 = require("@voltagent/internal/dev");
3202
- async function streamEventForwarder(event, options = {}) {
3203
- const { forwarder, filterTypes = ["text-delta", "reasoning", "source"] } = options;
3203
+ async function streamEventForwarder(event, options) {
3204
+ const { forwarder, types } = options;
3204
3205
  try {
3205
3206
  if (!event || typeof event !== "object") {
3206
3207
  import_dev5.devLogger.warn("[StreamEventForwarder] Invalid event structure:", event);
@@ -3214,7 +3215,7 @@ async function streamEventForwarder(event, options = {}) {
3214
3215
  });
3215
3216
  return;
3216
3217
  }
3217
- if (filterTypes.includes(event.type)) {
3218
+ if (!types.includes(event.type)) {
3218
3219
  import_dev5.devLogger.info(
3219
3220
  "[StreamEventForwarder] Filtered out",
3220
3221
  event.type,
@@ -3223,9 +3224,6 @@ async function streamEventForwarder(event, options = {}) {
3223
3224
  );
3224
3225
  return;
3225
3226
  }
3226
- if (!forwarder) {
3227
- return;
3228
- }
3229
3227
  await forwarder(formatEvent(event, options));
3230
3228
  import_dev5.devLogger.info(
3231
3229
  "[StreamEventForwarder] Forwarded",
@@ -3238,7 +3236,7 @@ async function streamEventForwarder(event, options = {}) {
3238
3236
  }
3239
3237
  }
3240
3238
  __name(streamEventForwarder, "streamEventForwarder");
3241
- function createStreamEventForwarder(options = {}) {
3239
+ function createStreamEventForwarder(options) {
3242
3240
  return (event) => streamEventForwarder(event, options);
3243
3241
  }
3244
3242
  __name(createStreamEventForwarder, "createStreamEventForwarder");
@@ -7322,36 +7320,36 @@ var Agent = class {
7322
7320
  /**
7323
7321
  * Resolve dynamic instructions based on user context
7324
7322
  */
7325
- resolveInstructions = async (options) => {
7323
+ async resolveInstructions(options) {
7326
7324
  if (!this.dynamicInstructions)
7327
7325
  return this.instructions;
7328
7326
  if (typeof this.dynamicInstructions === "function") {
7329
7327
  return await this.dynamicInstructions(options);
7330
7328
  }
7331
7329
  return this.dynamicInstructions;
7332
- };
7330
+ }
7333
7331
  /**
7334
7332
  * Resolve dynamic model based on user context
7335
7333
  */
7336
- resolveModel = async (options) => {
7334
+ async resolveModel(options) {
7337
7335
  if (!this.dynamicModel)
7338
7336
  return this.model;
7339
7337
  if (typeof this.dynamicModel === "function") {
7340
7338
  return await this.dynamicModel(options);
7341
7339
  }
7342
7340
  return this.dynamicModel;
7343
- };
7341
+ }
7344
7342
  /**
7345
7343
  * Resolve dynamic tools based on user context
7346
7344
  */
7347
- resolveTools = async (options) => {
7345
+ async resolveTools(options) {
7348
7346
  if (!this.dynamicTools)
7349
7347
  return [];
7350
7348
  if (typeof this.dynamicTools === "function") {
7351
7349
  return await this.dynamicTools(options);
7352
7350
  }
7353
7351
  return this.dynamicTools;
7354
- };
7352
+ }
7355
7353
  /**
7356
7354
  * Get the system message for the agent
7357
7355
  */
@@ -7602,12 +7600,13 @@ ${context}`;
7602
7600
  import_dev14.devLogger.info(
7603
7601
  `[Agent ${this.id}] Received SubAgent event: ${event.type} from ${event.subAgentName}`
7604
7602
  );
7605
- await streamEventForwarder(event, {
7606
- forwarder: internalStreamForwarder,
7607
- filterTypes: [],
7608
- // Don't filter any events in this context
7609
- addSubAgentPrefix: true
7610
- });
7603
+ if (internalStreamForwarder) {
7604
+ await streamEventForwarder(event, {
7605
+ forwarder: internalStreamForwarder,
7606
+ types: ["tool-call", "tool-result"],
7607
+ addSubAgentPrefix: true
7608
+ });
7609
+ }
7611
7610
  }, "forwardEvent");
7612
7611
  const delegateTool = this.subAgentManager.createDelegateTool({
7613
7612
  sourceAgent: this,
@@ -7723,7 +7722,14 @@ ${context}`;
7723
7722
  if (!context.conversationSteps) {
7724
7723
  context.conversationSteps = [];
7725
7724
  }
7726
- context.conversationSteps.push(step);
7725
+ const finalStep = {
7726
+ ...step,
7727
+ ...(0, import_ts_pattern2.match)(context).with({ parentAgentId: import_ts_pattern2.P.not(import_ts_pattern2.P.nullish) }, () => ({
7728
+ subAgentId: this.id,
7729
+ subAgentName: this.name
7730
+ })).otherwise(() => ({}))
7731
+ };
7732
+ context.conversationSteps.push(finalStep);
7727
7733
  }
7728
7734
  /**
7729
7735
  * Update history entry
@@ -7734,7 +7740,7 @@ ${context}`;
7734
7740
  /**
7735
7741
  * Fix delete operator usage for better performance
7736
7742
  */
7737
- addToolEvent = (context, toolName, status, data = {}) => {
7743
+ addToolEvent(context, toolName, status, data = {}) {
7738
7744
  if (!context.toolSpans) {
7739
7745
  context.toolSpans = /* @__PURE__ */ new Map();
7740
7746
  }
@@ -7754,11 +7760,11 @@ ${context}`;
7754
7760
  context.toolSpans.set(toolCallId, toolSpan);
7755
7761
  }
7756
7762
  }
7757
- };
7763
+ }
7758
7764
  /**
7759
7765
  * Agent event creator (update)
7760
7766
  */
7761
- addAgentEvent = (context, eventName, status, data = {}) => {
7767
+ addAgentEvent(context, eventName, status, data = {}) {
7762
7768
  const otelSpan = context.otelSpan;
7763
7769
  if (otelSpan) {
7764
7770
  endOperationSpan({
@@ -7771,7 +7777,7 @@ ${context}`;
7771
7777
  `OpenTelemetry span not found in OperationContext for agent event ${eventName} (Operation ID: ${context.operationId})`
7772
7778
  );
7773
7779
  }
7774
- };
7780
+ }
7775
7781
  /**
7776
7782
  * Helper method to enrich and end an OpenTelemetry span associated with a tool call.
7777
7783
  */