@voltagent/core 2.4.2 → 2.4.4
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 +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +35 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -10056,6 +10056,10 @@ interface WorkflowRunOptions {
|
|
|
10056
10056
|
* The user ID, this can be used to track the current user in a workflow
|
|
10057
10057
|
*/
|
|
10058
10058
|
userId?: string;
|
|
10059
|
+
/**
|
|
10060
|
+
* Additional execution metadata persisted with workflow state
|
|
10061
|
+
*/
|
|
10062
|
+
metadata?: Record<string, unknown>;
|
|
10059
10063
|
/**
|
|
10060
10064
|
* The user context, this can be used to track the current user context in a workflow
|
|
10061
10065
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -10056,6 +10056,10 @@ interface WorkflowRunOptions {
|
|
|
10056
10056
|
* The user ID, this can be used to track the current user in a workflow
|
|
10057
10057
|
*/
|
|
10058
10058
|
userId?: string;
|
|
10059
|
+
/**
|
|
10060
|
+
* Additional execution metadata persisted with workflow state
|
|
10061
|
+
*/
|
|
10062
|
+
metadata?: Record<string, unknown>;
|
|
10059
10063
|
/**
|
|
10060
10064
|
* The user context, this can be used to track the current user context in a workflow
|
|
10061
10065
|
*/
|
package/dist/index.js
CHANGED
|
@@ -505,7 +505,7 @@ function convertWorkflowStateToParam(state, executionContext, signal) {
|
|
|
505
505
|
executionId: state.executionId,
|
|
506
506
|
conversationId: state.conversationId,
|
|
507
507
|
userId: state.userId,
|
|
508
|
-
context: state.context,
|
|
508
|
+
context: executionContext?.context ?? state.context,
|
|
509
509
|
workflowState: state.workflowState,
|
|
510
510
|
active: state.active,
|
|
511
511
|
startAt: state.startAt,
|
|
@@ -9701,6 +9701,13 @@ function createWorkflow({
|
|
|
9701
9701
|
} else {
|
|
9702
9702
|
executionId = options?.executionId || randomUUID();
|
|
9703
9703
|
}
|
|
9704
|
+
const mergeExecutionMetadata = /* @__PURE__ */ __name(async (patch) => {
|
|
9705
|
+
const existingState = await executionMemory.getWorkflowState(executionId);
|
|
9706
|
+
return {
|
|
9707
|
+
...existingState?.metadata ?? {},
|
|
9708
|
+
...patch
|
|
9709
|
+
};
|
|
9710
|
+
}, "mergeExecutionMetadata");
|
|
9704
9711
|
const streamController = externalStreamController || null;
|
|
9705
9712
|
const collectedEvents = [];
|
|
9706
9713
|
const emitAndCollectEvent = /* @__PURE__ */ __name((event) => {
|
|
@@ -9725,6 +9732,7 @@ function createWorkflow({
|
|
|
9725
9732
|
}, "emitAndCollectEvent");
|
|
9726
9733
|
const observability = getObservability();
|
|
9727
9734
|
const contextMap = options?.context instanceof Map ? options.context : options?.context ? new Map(Object.entries(options.context)) : /* @__PURE__ */ new Map();
|
|
9735
|
+
const optionMetadata = options?.metadata && typeof options.metadata === "object" && !Array.isArray(options.metadata) ? options.metadata : void 0;
|
|
9728
9736
|
const workflowStateStore = options?.workflowState ?? {};
|
|
9729
9737
|
let resumedFrom;
|
|
9730
9738
|
if (options?.resumeFrom?.executionId) {
|
|
@@ -9813,11 +9821,12 @@ function createWorkflow({
|
|
|
9813
9821
|
workflowName: name,
|
|
9814
9822
|
status: "running",
|
|
9815
9823
|
input: input2,
|
|
9816
|
-
context: options?.context ? Array.from(
|
|
9824
|
+
context: options?.context ? Array.from(contextMap.entries()) : void 0,
|
|
9817
9825
|
workflowState: workflowStateStore,
|
|
9818
9826
|
userId: options?.userId,
|
|
9819
9827
|
conversationId: options?.conversationId,
|
|
9820
9828
|
metadata: {
|
|
9829
|
+
...optionMetadata ?? {},
|
|
9821
9830
|
traceId: rootSpan.spanContext().traceId,
|
|
9822
9831
|
spanId: rootSpan.spanContext().spanId
|
|
9823
9832
|
},
|
|
@@ -9834,7 +9843,7 @@ function createWorkflow({
|
|
|
9834
9843
|
);
|
|
9835
9844
|
}
|
|
9836
9845
|
}
|
|
9837
|
-
const streamWriter = streamController ? new WorkflowStreamWriterImpl(streamController, executionId, id, name, 0,
|
|
9846
|
+
const streamWriter = streamController ? new WorkflowStreamWriterImpl(streamController, executionId, id, name, 0, contextMap) : new NoOpWorkflowStreamWriter();
|
|
9838
9847
|
const executionContext = {
|
|
9839
9848
|
workflowId: id,
|
|
9840
9849
|
executionId,
|
|
@@ -9888,7 +9897,7 @@ function createWorkflow({
|
|
|
9888
9897
|
from: name,
|
|
9889
9898
|
input: input2,
|
|
9890
9899
|
status: "running",
|
|
9891
|
-
context:
|
|
9900
|
+
context: contextMap,
|
|
9892
9901
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
9893
9902
|
});
|
|
9894
9903
|
runLogger.debug(
|
|
@@ -9901,6 +9910,7 @@ function createWorkflow({
|
|
|
9901
9910
|
if (options?.resumeFrom?.executionId) {
|
|
9902
9911
|
stateManager.start(input2, {
|
|
9903
9912
|
...options,
|
|
9913
|
+
context: contextMap,
|
|
9904
9914
|
executionId,
|
|
9905
9915
|
// Use the resumed execution ID
|
|
9906
9916
|
active: options.resumeFrom.resumeStepIndex,
|
|
@@ -9909,6 +9919,7 @@ function createWorkflow({
|
|
|
9909
9919
|
} else {
|
|
9910
9920
|
stateManager.start(input2, {
|
|
9911
9921
|
...options,
|
|
9922
|
+
context: contextMap,
|
|
9912
9923
|
executionId,
|
|
9913
9924
|
// Use the created execution ID
|
|
9914
9925
|
workflowState: workflowStateStore
|
|
@@ -10022,7 +10033,7 @@ function createWorkflow({
|
|
|
10022
10033
|
input: stateManager.state.data,
|
|
10023
10034
|
output: void 0,
|
|
10024
10035
|
status: "cancelled",
|
|
10025
|
-
context:
|
|
10036
|
+
context: contextMap,
|
|
10026
10037
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10027
10038
|
stepIndex: index,
|
|
10028
10039
|
stepType: step.type,
|
|
@@ -10042,10 +10053,10 @@ function createWorkflow({
|
|
|
10042
10053
|
cancelledAt: /* @__PURE__ */ new Date(),
|
|
10043
10054
|
reason
|
|
10044
10055
|
},
|
|
10045
|
-
metadata: {
|
|
10056
|
+
metadata: await mergeExecutionMetadata({
|
|
10046
10057
|
...stateManager.state?.usage ? { usage: stateManager.state.usage } : {},
|
|
10047
10058
|
cancellationReason: reason
|
|
10048
|
-
},
|
|
10059
|
+
}),
|
|
10049
10060
|
updatedAt: /* @__PURE__ */ new Date()
|
|
10050
10061
|
});
|
|
10051
10062
|
} catch (memoryError) {
|
|
@@ -10058,7 +10069,7 @@ function createWorkflow({
|
|
|
10058
10069
|
executionId,
|
|
10059
10070
|
from: name,
|
|
10060
10071
|
status: "cancelled",
|
|
10061
|
-
context:
|
|
10072
|
+
context: contextMap,
|
|
10062
10073
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10063
10074
|
metadata: { reason }
|
|
10064
10075
|
});
|
|
@@ -10190,7 +10201,7 @@ function createWorkflow({
|
|
|
10190
10201
|
step.id,
|
|
10191
10202
|
step.name || step.id,
|
|
10192
10203
|
index,
|
|
10193
|
-
|
|
10204
|
+
contextMap
|
|
10194
10205
|
) : new NoOpWorkflowStreamWriter();
|
|
10195
10206
|
executionContext.streamWriter = stepWriter;
|
|
10196
10207
|
emitAndCollectEvent({
|
|
@@ -10199,7 +10210,7 @@ function createWorkflow({
|
|
|
10199
10210
|
from: step.name || step.id,
|
|
10200
10211
|
input: stateManager.state.data,
|
|
10201
10212
|
status: "running",
|
|
10202
|
-
context:
|
|
10213
|
+
context: contextMap,
|
|
10203
10214
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10204
10215
|
stepIndex: index,
|
|
10205
10216
|
stepType: step.type,
|
|
@@ -10269,7 +10280,7 @@ function createWorkflow({
|
|
|
10269
10280
|
input: stateManager.state.data,
|
|
10270
10281
|
output: void 0,
|
|
10271
10282
|
status: "suspended",
|
|
10272
|
-
context:
|
|
10283
|
+
context: contextMap,
|
|
10273
10284
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10274
10285
|
stepIndex: index,
|
|
10275
10286
|
metadata: {
|
|
@@ -10337,7 +10348,7 @@ function createWorkflow({
|
|
|
10337
10348
|
step.id,
|
|
10338
10349
|
step.name || step.id,
|
|
10339
10350
|
index,
|
|
10340
|
-
|
|
10351
|
+
contextMap
|
|
10341
10352
|
) : new NoOpWorkflowStreamWriter();
|
|
10342
10353
|
const stepExecutionContext = {
|
|
10343
10354
|
...executionContext,
|
|
@@ -10414,7 +10425,7 @@ function createWorkflow({
|
|
|
10414
10425
|
input: stateManager.state.data,
|
|
10415
10426
|
output: result2,
|
|
10416
10427
|
status: isSkipped ? "skipped" : "success",
|
|
10417
|
-
context:
|
|
10428
|
+
context: contextMap,
|
|
10418
10429
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10419
10430
|
stepIndex: index,
|
|
10420
10431
|
stepType: step.type,
|
|
@@ -10539,7 +10550,7 @@ function createWorkflow({
|
|
|
10539
10550
|
from: name,
|
|
10540
10551
|
output: finalState.result,
|
|
10541
10552
|
status: "success",
|
|
10542
|
-
context:
|
|
10553
|
+
context: contextMap,
|
|
10543
10554
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
10544
10555
|
});
|
|
10545
10556
|
streamController?.close();
|
|
@@ -10569,7 +10580,7 @@ function createWorkflow({
|
|
|
10569
10580
|
executionId,
|
|
10570
10581
|
from: name,
|
|
10571
10582
|
status: "cancelled",
|
|
10572
|
-
context:
|
|
10583
|
+
context: contextMap,
|
|
10573
10584
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
10574
10585
|
metadata: cancellationReason ? { reason: cancellationReason } : void 0
|
|
10575
10586
|
});
|
|
@@ -10578,10 +10589,10 @@ function createWorkflow({
|
|
|
10578
10589
|
await executionMemory.updateWorkflowState(executionId, {
|
|
10579
10590
|
status: "cancelled",
|
|
10580
10591
|
workflowState: stateManager.state.workflowState,
|
|
10581
|
-
metadata: {
|
|
10592
|
+
metadata: await mergeExecutionMetadata({
|
|
10582
10593
|
...stateManager.state?.usage ? { usage: stateManager.state.usage } : {},
|
|
10583
10594
|
cancellationReason
|
|
10584
|
-
},
|
|
10595
|
+
}),
|
|
10585
10596
|
updatedAt: /* @__PURE__ */ new Date()
|
|
10586
10597
|
});
|
|
10587
10598
|
} catch (memoryError) {
|
|
@@ -10645,7 +10656,7 @@ function createWorkflow({
|
|
|
10645
10656
|
from: name,
|
|
10646
10657
|
status: "error",
|
|
10647
10658
|
error,
|
|
10648
|
-
context:
|
|
10659
|
+
context: contextMap,
|
|
10649
10660
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
10650
10661
|
});
|
|
10651
10662
|
if (stateManager.state.status !== "completed" && stateManager.state.status !== "failed") {
|
|
@@ -10657,10 +10668,10 @@ function createWorkflow({
|
|
|
10657
10668
|
workflowState: stateManager.state.workflowState,
|
|
10658
10669
|
events: collectedEvents,
|
|
10659
10670
|
// Store a lightweight error summary in metadata for debugging
|
|
10660
|
-
metadata: {
|
|
10671
|
+
metadata: await mergeExecutionMetadata({
|
|
10661
10672
|
...stateManager.state?.usage ? { usage: stateManager.state.usage } : {},
|
|
10662
10673
|
errorMessage: error instanceof Error ? error.message : String(error)
|
|
10663
|
-
},
|
|
10674
|
+
}),
|
|
10664
10675
|
updatedAt: /* @__PURE__ */ new Date()
|
|
10665
10676
|
});
|
|
10666
10677
|
} catch (memoryError) {
|
|
@@ -10784,6 +10795,7 @@ function createWorkflow({
|
|
|
10784
10795
|
resumedReject = reject;
|
|
10785
10796
|
}
|
|
10786
10797
|
);
|
|
10798
|
+
const resumedSuspendController = createSuspendController();
|
|
10787
10799
|
const executeResume = /* @__PURE__ */ __name(async () => {
|
|
10788
10800
|
if (!execResult.suspension) {
|
|
10789
10801
|
throw new Error("No suspension metadata found");
|
|
@@ -10806,7 +10818,7 @@ function createWorkflow({
|
|
|
10806
10818
|
resumeStepIndex,
|
|
10807
10819
|
resumeData: input3
|
|
10808
10820
|
},
|
|
10809
|
-
suspendController
|
|
10821
|
+
suspendController: resumedSuspendController
|
|
10810
10822
|
};
|
|
10811
10823
|
const resumed = await executeInternal(
|
|
10812
10824
|
originalInput,
|
|
@@ -10849,10 +10861,10 @@ function createWorkflow({
|
|
|
10849
10861
|
return streamResult.resume(input22, opts2);
|
|
10850
10862
|
}, "resume"),
|
|
10851
10863
|
suspend: /* @__PURE__ */ __name((reason) => {
|
|
10852
|
-
|
|
10864
|
+
resumedSuspendController.suspend(reason);
|
|
10853
10865
|
}, "suspend"),
|
|
10854
10866
|
cancel: /* @__PURE__ */ __name((reason) => {
|
|
10855
|
-
|
|
10867
|
+
resumedSuspendController.cancel(reason);
|
|
10856
10868
|
}, "cancel"),
|
|
10857
10869
|
abort: /* @__PURE__ */ __name(() => streamController.abort(), "abort"),
|
|
10858
10870
|
toUIMessageStreamResponse: eventToUIMessageStreamResponse(streamController),
|