@voltagent/core 2.4.1 → 2.4.2

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.mts CHANGED
@@ -10755,14 +10755,28 @@ interface WorkflowStepForEach<INPUT, DATA, ITEM, RESULT, MAP_DATA = ITEM> extend
10755
10755
  items?: WorkflowStepForEachItemsFunc<INPUT, DATA, ITEM>;
10756
10756
  map?: WorkflowStepForEachMapFunc<INPUT, DATA, ITEM, MAP_DATA>;
10757
10757
  }
10758
- type WorkflowStepLoopConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
10759
- step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
10758
+ type WorkflowStepLoopSteps<INPUT, DATA, RESULT> = readonly [InternalAnyWorkflowStep<INPUT, DATA, RESULT>] | readonly [
10759
+ InternalAnyWorkflowStep<INPUT, DATA, DangerouslyAllowAny>,
10760
+ ...InternalAnyWorkflowStep<INPUT, DangerouslyAllowAny, DangerouslyAllowAny>[],
10761
+ InternalAnyWorkflowStep<INPUT, DangerouslyAllowAny, RESULT>
10762
+ ];
10763
+ type WorkflowStepLoopBaseConfig<INPUT, RESULT> = InternalWorkflowStepConfig<{
10760
10764
  condition: InternalWorkflowFunc<INPUT, RESULT, boolean, any, any>;
10761
10765
  }>;
10766
+ type WorkflowStepLoopSingleStepConfig<INPUT, DATA, RESULT> = WorkflowStepLoopBaseConfig<INPUT, RESULT> & {
10767
+ step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
10768
+ steps?: never;
10769
+ };
10770
+ type WorkflowStepLoopMultiStepConfig<INPUT, DATA, RESULT> = WorkflowStepLoopBaseConfig<INPUT, RESULT> & {
10771
+ steps: WorkflowStepLoopSteps<INPUT, DATA, RESULT>;
10772
+ step?: never;
10773
+ };
10774
+ type WorkflowStepLoopConfig<INPUT, DATA, RESULT> = WorkflowStepLoopSingleStepConfig<INPUT, DATA, RESULT> | WorkflowStepLoopMultiStepConfig<INPUT, DATA, RESULT>;
10762
10775
  interface WorkflowStepLoop<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT, any, any> {
10763
10776
  type: "loop";
10764
10777
  loopType: "dowhile" | "dountil";
10765
- step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
10778
+ step: InternalAnyWorkflowStep<INPUT, DATA, DangerouslyAllowAny>;
10779
+ steps: WorkflowStepLoopSteps<INPUT, DATA, RESULT>;
10766
10780
  condition: InternalWorkflowFunc<INPUT, RESULT, boolean, any, any>;
10767
10781
  }
10768
10782
  type WorkflowStepBranchConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
@@ -11137,7 +11151,8 @@ type LoopType = "dowhile" | "dountil";
11137
11151
  declare function andDoWhile<INPUT, DATA, RESULT>(config: WorkflowStepLoopConfig<INPUT, DATA, RESULT>): {
11138
11152
  type: "loop";
11139
11153
  loopType: LoopType;
11140
- step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
11154
+ step: InternalAnyWorkflowStep<INPUT, DATA, RESULT> | InternalAnyWorkflowStep<INPUT, DATA, any>;
11155
+ steps: WorkflowStepLoopSteps<INPUT, DATA, RESULT>;
11141
11156
  condition: InternalWorkflowFunc<INPUT, RESULT, boolean, any, any>;
11142
11157
  execute: (context: WorkflowExecuteContext<INPUT, DATA, any, any>) => Promise<RESULT>;
11143
11158
  id: string;
@@ -11151,7 +11166,8 @@ declare function andDoWhile<INPUT, DATA, RESULT>(config: WorkflowStepLoopConfig<
11151
11166
  declare function andDoUntil<INPUT, DATA, RESULT>(config: WorkflowStepLoopConfig<INPUT, DATA, RESULT>): {
11152
11167
  type: "loop";
11153
11168
  loopType: LoopType;
11154
- step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
11169
+ step: InternalAnyWorkflowStep<INPUT, DATA, RESULT> | InternalAnyWorkflowStep<INPUT, DATA, any>;
11170
+ steps: WorkflowStepLoopSteps<INPUT, DATA, RESULT>;
11155
11171
  condition: InternalWorkflowFunc<INPUT, RESULT, boolean, any, any>;
11156
11172
  execute: (context: WorkflowExecuteContext<INPUT, DATA, any, any>) => Promise<RESULT>;
11157
11173
  id: string;
package/dist/index.d.ts CHANGED
@@ -10755,14 +10755,28 @@ interface WorkflowStepForEach<INPUT, DATA, ITEM, RESULT, MAP_DATA = ITEM> extend
10755
10755
  items?: WorkflowStepForEachItemsFunc<INPUT, DATA, ITEM>;
10756
10756
  map?: WorkflowStepForEachMapFunc<INPUT, DATA, ITEM, MAP_DATA>;
10757
10757
  }
10758
- type WorkflowStepLoopConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
10759
- step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
10758
+ type WorkflowStepLoopSteps<INPUT, DATA, RESULT> = readonly [InternalAnyWorkflowStep<INPUT, DATA, RESULT>] | readonly [
10759
+ InternalAnyWorkflowStep<INPUT, DATA, DangerouslyAllowAny>,
10760
+ ...InternalAnyWorkflowStep<INPUT, DangerouslyAllowAny, DangerouslyAllowAny>[],
10761
+ InternalAnyWorkflowStep<INPUT, DangerouslyAllowAny, RESULT>
10762
+ ];
10763
+ type WorkflowStepLoopBaseConfig<INPUT, RESULT> = InternalWorkflowStepConfig<{
10760
10764
  condition: InternalWorkflowFunc<INPUT, RESULT, boolean, any, any>;
10761
10765
  }>;
10766
+ type WorkflowStepLoopSingleStepConfig<INPUT, DATA, RESULT> = WorkflowStepLoopBaseConfig<INPUT, RESULT> & {
10767
+ step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
10768
+ steps?: never;
10769
+ };
10770
+ type WorkflowStepLoopMultiStepConfig<INPUT, DATA, RESULT> = WorkflowStepLoopBaseConfig<INPUT, RESULT> & {
10771
+ steps: WorkflowStepLoopSteps<INPUT, DATA, RESULT>;
10772
+ step?: never;
10773
+ };
10774
+ type WorkflowStepLoopConfig<INPUT, DATA, RESULT> = WorkflowStepLoopSingleStepConfig<INPUT, DATA, RESULT> | WorkflowStepLoopMultiStepConfig<INPUT, DATA, RESULT>;
10762
10775
  interface WorkflowStepLoop<INPUT, DATA, RESULT> extends InternalBaseWorkflowStep<INPUT, DATA, RESULT, any, any> {
10763
10776
  type: "loop";
10764
10777
  loopType: "dowhile" | "dountil";
10765
- step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
10778
+ step: InternalAnyWorkflowStep<INPUT, DATA, DangerouslyAllowAny>;
10779
+ steps: WorkflowStepLoopSteps<INPUT, DATA, RESULT>;
10766
10780
  condition: InternalWorkflowFunc<INPUT, RESULT, boolean, any, any>;
10767
10781
  }
10768
10782
  type WorkflowStepBranchConfig<INPUT, DATA, RESULT> = InternalWorkflowStepConfig<{
@@ -11137,7 +11151,8 @@ type LoopType = "dowhile" | "dountil";
11137
11151
  declare function andDoWhile<INPUT, DATA, RESULT>(config: WorkflowStepLoopConfig<INPUT, DATA, RESULT>): {
11138
11152
  type: "loop";
11139
11153
  loopType: LoopType;
11140
- step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
11154
+ step: InternalAnyWorkflowStep<INPUT, DATA, RESULT> | InternalAnyWorkflowStep<INPUT, DATA, any>;
11155
+ steps: WorkflowStepLoopSteps<INPUT, DATA, RESULT>;
11141
11156
  condition: InternalWorkflowFunc<INPUT, RESULT, boolean, any, any>;
11142
11157
  execute: (context: WorkflowExecuteContext<INPUT, DATA, any, any>) => Promise<RESULT>;
11143
11158
  id: string;
@@ -11151,7 +11166,8 @@ declare function andDoWhile<INPUT, DATA, RESULT>(config: WorkflowStepLoopConfig<
11151
11166
  declare function andDoUntil<INPUT, DATA, RESULT>(config: WorkflowStepLoopConfig<INPUT, DATA, RESULT>): {
11152
11167
  type: "loop";
11153
11168
  loopType: LoopType;
11154
- step: InternalAnyWorkflowStep<INPUT, DATA, RESULT>;
11169
+ step: InternalAnyWorkflowStep<INPUT, DATA, RESULT> | InternalAnyWorkflowStep<INPUT, DATA, any>;
11170
+ steps: WorkflowStepLoopSteps<INPUT, DATA, RESULT>;
11155
11171
  condition: InternalWorkflowFunc<INPUT, RESULT, boolean, any, any>;
11156
11172
  execute: (context: WorkflowExecuteContext<INPUT, DATA, any, any>) => Promise<RESULT>;
11157
11173
  id: string;
package/dist/index.js CHANGED
@@ -3166,47 +3166,78 @@ function andBranch({
3166
3166
  __name(andBranch, "andBranch");
3167
3167
 
3168
3168
  // src/workflow/steps/and-loop.ts
3169
- var createLoopStep = /* @__PURE__ */ __name((loopType, { step, condition, ...config }) => {
3170
- const finalStep = matchStep(step);
3169
+ function splitLoopConfig(config) {
3170
+ if ("step" in config) {
3171
+ const { step: _step, condition: condition2, ...stepConfig2 } = config;
3172
+ return { condition: condition2, stepConfig: stepConfig2 };
3173
+ }
3174
+ const { steps: _steps, condition, ...stepConfig } = config;
3175
+ return { condition, stepConfig };
3176
+ }
3177
+ __name(splitLoopConfig, "splitLoopConfig");
3178
+ function getLoopSteps(config) {
3179
+ if ("steps" in config && config.steps) {
3180
+ if (config.steps.length === 0) {
3181
+ throw new Error("andDoWhile/andDoUntil requires at least one step");
3182
+ }
3183
+ return config.steps;
3184
+ }
3185
+ return [config.step];
3186
+ }
3187
+ __name(getLoopSteps, "getLoopSteps");
3188
+ var createLoopStep = /* @__PURE__ */ __name((loopType, config) => {
3189
+ const { condition, stepConfig } = splitLoopConfig(config);
3190
+ const loopSteps = getLoopSteps(config);
3191
+ const resolvedSteps = loopSteps.map((loopStep) => matchStep(loopStep));
3192
+ const firstStep = loopSteps[0];
3193
+ if (!firstStep) {
3194
+ throw new Error("andDoWhile/andDoUntil requires at least one step");
3195
+ }
3171
3196
  return {
3172
- ...defaultStepConfig(config),
3197
+ ...defaultStepConfig(stepConfig),
3173
3198
  type: "loop",
3174
3199
  loopType,
3175
- step,
3200
+ step: firstStep,
3201
+ steps: loopSteps,
3176
3202
  condition,
3177
3203
  execute: /* @__PURE__ */ __name(async (context8) => {
3178
3204
  const { state } = context8;
3179
3205
  const traceContext = state.workflowContext?.traceContext;
3180
3206
  let currentData = context8.data;
3181
3207
  let iteration = 0;
3182
- while (true) {
3183
- throwIfAborted(state.signal);
3208
+ const runResolvedStep = /* @__PURE__ */ __name(async (stepIndex) => {
3209
+ const resolvedStep = resolvedSteps[stepIndex];
3210
+ if (!resolvedStep) {
3211
+ return;
3212
+ }
3184
3213
  let childSpan;
3185
3214
  if (traceContext) {
3215
+ const isSingleLoopStep = resolvedSteps.length === 1;
3186
3216
  childSpan = traceContext.createStepSpan(
3187
- iteration,
3188
- finalStep.type,
3189
- finalStep.name || finalStep.id || `Loop ${iteration + 1}`,
3217
+ iteration * resolvedSteps.length + stepIndex,
3218
+ resolvedStep.type,
3219
+ resolvedStep.name || resolvedStep.id || (isSingleLoopStep ? `Loop ${iteration + 1}` : `Loop ${iteration + 1}.${stepIndex + 1}`),
3190
3220
  {
3191
- parentStepId: config.id,
3192
- parallelIndex: iteration,
3221
+ parentStepId: stepConfig.id,
3222
+ parallelIndex: isSingleLoopStep ? iteration : stepIndex,
3193
3223
  input: currentData,
3194
3224
  attributes: {
3195
3225
  "workflow.step.loop": true,
3196
3226
  "workflow.step.parent_type": "loop",
3197
- "workflow.step.loop_type": loopType
3227
+ "workflow.step.loop_type": loopType,
3228
+ "workflow.step.loop_iteration": iteration,
3229
+ "workflow.step.loop_step_index": stepIndex
3198
3230
  }
3199
3231
  }
3200
3232
  );
3201
3233
  }
3202
- const subState = {
3203
- ...state,
3204
- workflowContext: void 0
3205
- };
3206
- const executeStep = /* @__PURE__ */ __name(() => finalStep.execute({
3234
+ const executeStep = /* @__PURE__ */ __name(() => resolvedStep.execute({
3207
3235
  ...context8,
3208
3236
  data: currentData,
3209
- state: subState
3237
+ state: {
3238
+ ...state,
3239
+ workflowContext: void 0
3240
+ }
3210
3241
  }), "executeStep");
3211
3242
  try {
3212
3243
  currentData = childSpan && traceContext ? await traceContext.withSpan(childSpan, executeStep) : await executeStep();
@@ -3219,6 +3250,13 @@ var createLoopStep = /* @__PURE__ */ __name((loopType, { step, condition, ...con
3219
3250
  }
3220
3251
  throw error;
3221
3252
  }
3253
+ }, "runResolvedStep");
3254
+ while (true) {
3255
+ throwIfAborted(state.signal);
3256
+ for (let stepIndex = 0; stepIndex < resolvedSteps.length; stepIndex += 1) {
3257
+ throwIfAborted(state.signal);
3258
+ await runResolvedStep(stepIndex);
3259
+ }
3222
3260
  iteration += 1;
3223
3261
  throwIfAborted(state.signal);
3224
3262
  const shouldContinue = await condition({
@@ -11043,6 +11081,7 @@ function serializeWorkflowStep(step, index) {
11043
11081
  }
11044
11082
  case "loop": {
11045
11083
  const loopStep = step;
11084
+ const serializedSteps = loopStep.steps && Array.isArray(loopStep.steps) ? loopStep.steps.map((subStep, subIndex) => serializeWorkflowStep(subStep, subIndex)) : loopStep.step ? [serializeWorkflowStep(loopStep.step, 0)] : [];
11046
11085
  return {
11047
11086
  ...baseStep,
11048
11087
  ...loopStep.condition && {
@@ -11051,8 +11090,12 @@ function serializeWorkflowStep(step, index) {
11051
11090
  ...loopStep.loopType && {
11052
11091
  loopType: loopStep.loopType
11053
11092
  },
11054
- ...loopStep.step && {
11055
- nestedStep: serializeWorkflowStep(loopStep.step, 0)
11093
+ ...serializedSteps.length === 1 && {
11094
+ nestedStep: serializedSteps[0]
11095
+ },
11096
+ ...serializedSteps.length > 1 && {
11097
+ subSteps: serializedSteps,
11098
+ subStepsCount: serializedSteps.length
11056
11099
  }
11057
11100
  };
11058
11101
  }
@@ -29057,6 +29100,9 @@ var Agent = class {
29057
29100
  },
29058
29101
  options.logger
29059
29102
  );
29103
+ if (this.voltOpsClient && !AgentRegistry.getInstance().getGlobalVoltOpsClient()) {
29104
+ AgentRegistry.getInstance().setGlobalVoltOpsClient(this.voltOpsClient);
29105
+ }
29060
29106
  this.logger.debug(`Agent created: ${this.name}`, {
29061
29107
  event: LogEvents.AGENT_CREATED,
29062
29108
  agentId: this.id,