@primero.ai/temporal-graph-tools 1.4.1 → 1.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.
|
@@ -3,6 +3,8 @@ export type MastraWorkflowLike = {
|
|
|
3
3
|
id?: string;
|
|
4
4
|
engineType?: string;
|
|
5
5
|
stepGraph: Array<Record<string, unknown>>;
|
|
6
|
+
steps?: Record<string, unknown>;
|
|
7
|
+
stepById?: Record<string, unknown>;
|
|
6
8
|
};
|
|
7
9
|
export type CompileMastraWorkflowOptions = Omit<TemporalWorkflowBuildOptions, 'workflowName'> & {
|
|
8
10
|
workflowName?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow-compiler.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflow-compiler.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"workflow-compiler.d.ts","sourceRoot":"","sources":["../../../src/mastra/workflow-compiler.ts"],"names":[],"mappings":"AAEA,OAAO,EAIL,KAAK,4BAA4B,EACjC,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAA;AAYpB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,KAAK,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAA;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACnC,CAAA;AAED,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC,4BAA4B,EAAE,cAAc,CAAC,GAAG;IAC9F,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACxC;;;;;OAKG;IACH,8BAA8B,CAAC,EAAE,OAAO,CAAA;CACzC,CAAA;AAED,MAAM,MAAM,8BAA8B,GAAG;IAC3C,QAAQ,EAAE,kBAAkB,CAAA;IAC5B,OAAO,CAAC,EAAE,4BAA4B,CAAA;CACvC,CAAA;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,GAAE,4BAAiC,GACzC,mBAAmB,CAwFrB"}
|
|
@@ -13,8 +13,16 @@ export function compileMastraWorkflow(workflow, options = {}) {
|
|
|
13
13
|
...(options.proxyOptions ? { proxyOptions: options.proxyOptions } : {}),
|
|
14
14
|
});
|
|
15
15
|
workflow.stepGraph.forEach((entry, stageIndex) => {
|
|
16
|
-
if (entry.type === 'step'
|
|
17
|
-
const
|
|
16
|
+
if (entry.type === 'step') {
|
|
17
|
+
const step = resolveMastraStep(entry.step, workflow);
|
|
18
|
+
if (!step) {
|
|
19
|
+
const stepId = getMastraStepId(entry.step);
|
|
20
|
+
throw new Error(stepId
|
|
21
|
+
? `Unable to resolve Mastra step '${stepId}' at stage ${stageIndex}. ` +
|
|
22
|
+
`Ensure workflow.steps/workflow.stepById includes executable steps or pass stepActivities explicitly.`
|
|
23
|
+
: `Unsupported Mastra step entry at stage ${stageIndex}. Expected an executable step or step id.`);
|
|
24
|
+
}
|
|
25
|
+
const reference = resolveStepReference(workflow, step, options.stepActivities, options.allowUnsafeStepExecuteFallback === true);
|
|
18
26
|
builder = builder.then(reference);
|
|
19
27
|
return;
|
|
20
28
|
}
|
|
@@ -22,14 +30,21 @@ export function compileMastraWorkflow(workflow, options = {}) {
|
|
|
22
30
|
const references = entry.steps.map((child, branchIndex) => {
|
|
23
31
|
if (typeof child !== 'object' ||
|
|
24
32
|
child === null ||
|
|
25
|
-
child.type !== 'step'
|
|
26
|
-
!isMastraStepLike(child.step)) {
|
|
33
|
+
child.type !== 'step') {
|
|
27
34
|
const childType = typeof child === 'object' && child !== null
|
|
28
35
|
? String(child.type)
|
|
29
36
|
: typeof child;
|
|
30
37
|
throw new Error(`Unsupported Mastra parallel child type '${childType}' at stage ${stageIndex}, branch ${branchIndex}.`);
|
|
31
38
|
}
|
|
32
|
-
|
|
39
|
+
const step = resolveMastraStep(child.step, workflow);
|
|
40
|
+
if (!step) {
|
|
41
|
+
const stepId = getMastraStepId(child.step);
|
|
42
|
+
throw new Error(stepId
|
|
43
|
+
? `Unable to resolve Mastra parallel step '${stepId}' at stage ${stageIndex}, branch ${branchIndex}. ` +
|
|
44
|
+
`Ensure workflow.steps/workflow.stepById includes executable steps or pass stepActivities explicitly.`
|
|
45
|
+
: `Unsupported Mastra parallel step at stage ${stageIndex}, branch ${branchIndex}.`);
|
|
46
|
+
}
|
|
47
|
+
return resolveStepReference(workflow, step, options.stepActivities, options.allowUnsafeStepExecuteFallback === true);
|
|
33
48
|
});
|
|
34
49
|
builder = builder.parallel(references);
|
|
35
50
|
return;
|
|
@@ -45,6 +60,38 @@ function isMastraStepLike(value) {
|
|
|
45
60
|
const step = value;
|
|
46
61
|
return typeof step.id === 'string' && typeof step.execute === 'function';
|
|
47
62
|
}
|
|
63
|
+
function isMastraStepIdentifier(value) {
|
|
64
|
+
if (typeof value !== 'object' || value === null) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const step = value;
|
|
68
|
+
return typeof step.id === 'string' && step.id.trim().length > 0;
|
|
69
|
+
}
|
|
70
|
+
function resolveMastraStep(stepCandidate, workflow) {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
if (isMastraStepLike(stepCandidate)) {
|
|
73
|
+
return stepCandidate;
|
|
74
|
+
}
|
|
75
|
+
if (!isMastraStepIdentifier(stepCandidate)) {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
const { id } = stepCandidate;
|
|
79
|
+
const fromSteps = (_a = workflow.steps) === null || _a === void 0 ? void 0 : _a[id];
|
|
80
|
+
if (isMastraStepLike(fromSteps)) {
|
|
81
|
+
return fromSteps;
|
|
82
|
+
}
|
|
83
|
+
const fromStepById = (_b = workflow.stepById) === null || _b === void 0 ? void 0 : _b[id];
|
|
84
|
+
if (isMastraStepLike(fromStepById)) {
|
|
85
|
+
return fromStepById;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function getMastraStepId(stepCandidate) {
|
|
90
|
+
if (!isMastraStepIdentifier(stepCandidate)) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return stepCandidate.id;
|
|
94
|
+
}
|
|
48
95
|
function resolveWorkflowName(workflow, explicitName) {
|
|
49
96
|
const explicit = typeof explicitName === 'string' ? explicitName.trim() : '';
|
|
50
97
|
if (explicit.length > 0) {
|
package/package.json
CHANGED