@pikku/inspector 0.11.1 → 0.12.0
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/CHANGELOG.md +26 -1
- package/OPTIMIZATION-PLAN.md +195 -0
- package/dist/add/add-ai-agent.d.ts +2 -0
- package/dist/add/add-ai-agent.js +314 -0
- package/dist/add/add-channel.js +69 -61
- package/dist/add/add-cli.js +36 -18
- package/dist/add/add-file-with-factory.js +2 -0
- package/dist/add/add-functions.js +327 -59
- package/dist/add/add-http-route.d.ts +19 -10
- package/dist/add/add-http-route.js +153 -44
- package/dist/add/add-http-routes.d.ts +5 -0
- package/dist/add/add-http-routes.js +159 -0
- package/dist/add/add-keyed-wiring.d.ts +12 -0
- package/dist/add/add-keyed-wiring.js +97 -0
- package/dist/add/add-mcp-prompt.js +14 -9
- package/dist/add/add-mcp-resource.js +14 -9
- package/dist/add/add-middleware.d.ts +1 -4
- package/dist/add/add-middleware.js +364 -79
- package/dist/add/add-permission.d.ts +1 -1
- package/dist/add/add-permission.js +152 -40
- package/dist/add/add-queue-worker.js +18 -12
- package/dist/add/add-rpc-invocations.d.ts +3 -0
- package/dist/add/add-rpc-invocations.js +65 -25
- package/dist/add/add-schedule.js +11 -5
- package/dist/add/add-secret.d.ts +3 -0
- package/dist/add/add-secret.js +82 -0
- package/dist/add/add-trigger.d.ts +2 -0
- package/dist/add/add-trigger.js +87 -0
- package/dist/add/add-variable.d.ts +1 -0
- package/dist/add/add-variable.js +8 -0
- package/dist/add/add-workflow-graph.d.ts +7 -0
- package/dist/add/add-workflow-graph.js +396 -0
- package/dist/add/add-workflow.js +124 -26
- package/dist/error-codes.d.ts +16 -1
- package/dist/error-codes.js +21 -1
- package/dist/index.d.ts +9 -5
- package/dist/index.js +5 -2
- package/dist/inspector.d.ts +1 -1
- package/dist/inspector.js +106 -13
- package/dist/schema-generator.d.ts +1 -0
- package/dist/schema-generator.js +1 -0
- package/dist/types-map.js +10 -1
- package/dist/types.d.ts +180 -30
- package/dist/utils/compute-required-schemas.d.ts +4 -0
- package/dist/utils/compute-required-schemas.js +41 -0
- package/dist/utils/contract-hashes.d.ts +35 -0
- package/dist/utils/contract-hashes.js +202 -0
- package/dist/utils/custom-types-generator.d.ts +9 -0
- package/dist/utils/custom-types-generator.js +71 -0
- package/dist/utils/detect-schema-vendor.d.ts +22 -0
- package/dist/utils/detect-schema-vendor.js +76 -0
- package/dist/utils/ensure-function-metadata.d.ts +5 -2
- package/dist/utils/ensure-function-metadata.js +220 -6
- package/dist/utils/extract-function-name.d.ts +5 -16
- package/dist/utils/extract-function-name.js +93 -298
- package/dist/utils/extract-services.d.ts +2 -1
- package/dist/utils/extract-services.js +25 -1
- package/dist/utils/filter-inspector-state.js +107 -23
- package/dist/utils/get-property-value.d.ts +8 -2
- package/dist/utils/get-property-value.js +33 -4
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +23 -0
- package/dist/utils/middleware.d.ts +7 -30
- package/dist/utils/middleware.js +80 -66
- package/dist/utils/permissions.d.ts +2 -2
- package/dist/utils/permissions.js +10 -10
- package/dist/utils/post-process.d.ts +9 -10
- package/dist/utils/post-process.js +231 -24
- package/dist/utils/resolve-external-package.d.ts +12 -0
- package/dist/utils/resolve-external-package.js +34 -0
- package/dist/utils/resolve-function-types.d.ts +6 -0
- package/dist/utils/resolve-function-types.js +29 -0
- package/dist/utils/resolve-identifier.d.ts +10 -0
- package/dist/utils/resolve-identifier.js +36 -0
- package/dist/utils/resolve-versions.d.ts +2 -0
- package/dist/utils/resolve-versions.js +78 -0
- package/dist/utils/schema-generator.d.ts +9 -0
- package/dist/utils/schema-generator.js +209 -0
- package/dist/utils/serialize-inspector-state.d.ts +73 -13
- package/dist/utils/serialize-inspector-state.js +102 -6
- package/dist/utils/serialize-mcp-json.d.ts +2 -0
- package/dist/utils/serialize-mcp-json.js +99 -0
- package/dist/utils/serialize-middleware-groups-meta.d.ts +12 -0
- package/dist/utils/serialize-middleware-groups-meta.js +28 -0
- package/dist/utils/serialize-openapi-json.d.ts +85 -0
- package/dist/utils/serialize-openapi-json.js +151 -0
- package/dist/utils/serialize-permissions-groups-meta.d.ts +6 -0
- package/dist/utils/serialize-permissions-groups-meta.js +31 -0
- package/dist/utils/workflow/dsl/deserialize-dsl-workflow.d.ts +24 -0
- package/dist/utils/workflow/dsl/deserialize-dsl-workflow.js +830 -0
- package/dist/{workflow/extract-simple-workflow.d.ts → utils/workflow/dsl/extract-dsl-workflow.d.ts} +4 -2
- package/dist/{workflow/extract-simple-workflow.js → utils/workflow/dsl/extract-dsl-workflow.js} +572 -72
- package/dist/utils/workflow/dsl/index.d.ts +7 -0
- package/dist/utils/workflow/dsl/index.js +7 -0
- package/dist/{workflow → utils/workflow/dsl}/patterns.d.ts +21 -0
- package/dist/{workflow → utils/workflow/dsl}/patterns.js +90 -10
- package/dist/{workflow → utils/workflow/dsl}/validation.d.ts +2 -0
- package/dist/{workflow → utils/workflow/dsl}/validation.js +25 -7
- package/dist/utils/workflow/graph/convert-dsl-to-graph.d.ts +13 -0
- package/dist/utils/workflow/graph/convert-dsl-to-graph.js +318 -0
- package/dist/utils/workflow/graph/finalize-workflow-wires.d.ts +3 -0
- package/dist/utils/workflow/graph/finalize-workflow-wires.js +276 -0
- package/dist/utils/workflow/graph/finalize-workflows.d.ts +2 -0
- package/dist/utils/workflow/graph/finalize-workflows.js +75 -0
- package/dist/utils/workflow/graph/index.d.ts +8 -0
- package/dist/utils/workflow/graph/index.js +8 -0
- package/dist/utils/workflow/graph/serialize-workflow-graph.d.ts +35 -0
- package/dist/utils/workflow/graph/serialize-workflow-graph.js +150 -0
- package/dist/utils/workflow/graph/workflow-graph.types.d.ts +203 -0
- package/dist/utils/workflow/graph/workflow-graph.types.js +38 -0
- package/dist/visit.js +13 -2
- package/package.json +26 -4
- package/src/add/add-ai-agent.ts +468 -0
- package/src/add/add-channel.ts +82 -79
- package/src/add/add-cli.ts +49 -20
- package/src/add/add-file-with-factory.ts +2 -0
- package/src/add/add-functions.ts +429 -71
- package/src/add/add-http-route.ts +246 -65
- package/src/add/add-http-routes.ts +228 -0
- package/src/add/add-keyed-wiring.ts +151 -0
- package/src/add/add-mcp-prompt.ts +26 -15
- package/src/add/add-mcp-resource.ts +27 -15
- package/src/add/add-middleware.ts +482 -80
- package/src/add/add-permission.ts +199 -40
- package/src/add/add-queue-worker.ts +24 -19
- package/src/add/add-rpc-invocations.ts +78 -31
- package/src/add/add-schedule.ts +16 -11
- package/src/add/add-secret.ts +140 -0
- package/src/add/add-trigger.ts +154 -0
- package/src/add/add-variable.ts +9 -0
- package/src/add/add-workflow-graph.ts +522 -0
- package/src/add/add-workflow.ts +117 -30
- package/src/error-codes.ts +26 -1
- package/src/index.ts +27 -8
- package/src/inspector.ts +145 -17
- package/src/schema-generator.ts +1 -0
- package/src/types-map.ts +12 -1
- package/src/types.ts +192 -51
- package/src/utils/compute-required-schemas.ts +49 -0
- package/src/utils/contract-hashes.test.ts +528 -0
- package/src/utils/contract-hashes.ts +290 -0
- package/src/utils/custom-types-generator.ts +88 -0
- package/src/utils/detect-schema-vendor.ts +90 -0
- package/src/utils/ensure-function-metadata.ts +324 -7
- package/src/utils/extract-function-name.ts +108 -358
- package/src/utils/extract-services.ts +35 -2
- package/src/utils/filter-inspector-state.test.ts +34 -20
- package/src/utils/filter-inspector-state.ts +140 -31
- package/src/utils/get-property-value.ts +50 -5
- package/src/utils/hash.ts +26 -0
- package/src/utils/middleware.test.ts +204 -0
- package/src/utils/middleware.ts +129 -67
- package/src/utils/permissions.test.ts +35 -12
- package/src/utils/permissions.ts +10 -10
- package/src/utils/post-process.ts +283 -43
- package/src/utils/resolve-external-package.ts +42 -0
- package/src/utils/resolve-function-types.ts +42 -0
- package/src/utils/resolve-identifier.ts +46 -0
- package/src/utils/resolve-versions.test.ts +249 -0
- package/src/utils/resolve-versions.ts +105 -0
- package/src/utils/schema-generator.ts +329 -0
- package/src/utils/serialize-inspector-state.ts +181 -20
- package/src/utils/serialize-mcp-json.ts +145 -0
- package/src/utils/serialize-middleware-groups-meta.ts +33 -0
- package/src/utils/serialize-openapi-json.ts +277 -0
- package/src/utils/serialize-permissions-groups-meta.ts +35 -0
- package/src/utils/test-data/inspector-state.json +69 -66
- package/src/utils/workflow/dsl/deserialize-dsl-workflow.ts +1104 -0
- package/src/{workflow/extract-simple-workflow.ts → utils/workflow/dsl/extract-dsl-workflow.ts} +678 -85
- package/src/utils/workflow/dsl/index.ts +11 -0
- package/src/{workflow → utils/workflow/dsl}/patterns.ts +108 -11
- package/src/{workflow → utils/workflow/dsl}/validation.ts +34 -7
- package/src/utils/workflow/graph/convert-dsl-to-graph.ts +422 -0
- package/src/utils/workflow/graph/finalize-workflow-wires.ts +310 -0
- package/src/utils/workflow/graph/finalize-workflows.ts +100 -0
- package/src/utils/workflow/graph/index.ts +11 -0
- package/src/utils/workflow/graph/serialize-workflow-graph.ts +216 -0
- package/src/utils/workflow/graph/workflow-graph.types.ts +231 -0
- package/src/visit.ts +14 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/add/add-mcp-tool.d.ts +0 -2
- package/dist/add/add-mcp-tool.js +0 -81
- package/dist/utils/extract-service-metadata.d.ts +0 -19
- package/dist/utils/extract-service-metadata.js +0 -244
- package/dist/utils/write-service-metadata.d.ts +0 -13
- package/dist/utils/write-service-metadata.js +0 -37
- package/src/add/add-mcp-tool.ts +0 -141
- package/src/utils/extract-service-metadata.ts +0 -353
- package/src/utils/write-service-metadata.ts +0 -51
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSL (Domain Specific Language) workflow extraction exports
|
|
3
|
+
*/
|
|
4
|
+
export { extractDSLWorkflow } from './extract-dsl-workflow.js';
|
|
5
|
+
export { deserializeDslWorkflow, deserializeGraphWorkflow, deserializeAllDslWorkflows, } from './deserialize-dsl-workflow.js';
|
|
6
|
+
export * from './patterns.js';
|
|
7
|
+
export * from './validation.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSL (Domain Specific Language) workflow extraction exports
|
|
3
|
+
*/
|
|
4
|
+
export { extractDSLWorkflow } from './extract-dsl-workflow.js';
|
|
5
|
+
export { deserializeDslWorkflow, deserializeGraphWorkflow, deserializeAllDslWorkflows, } from './deserialize-dsl-workflow.js';
|
|
6
|
+
export * from './patterns.js';
|
|
7
|
+
export * from './validation.js';
|
|
@@ -10,6 +10,27 @@ export declare function isWorkflowDoCall(node: ts.CallExpression, checker: ts.Ty
|
|
|
10
10
|
* Check if a call expression is workflow.sleep()
|
|
11
11
|
*/
|
|
12
12
|
export declare function isWorkflowSleepCall(node: ts.CallExpression, checker: ts.TypeChecker): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check if a throw statement throws WorkflowCancelledException
|
|
15
|
+
* Matches: throw new WorkflowCancelledException(...) or throw WorkflowCancelledException(...)
|
|
16
|
+
*/
|
|
17
|
+
export declare function isThrowCancelException(node: ts.ThrowStatement): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Extract the reason string from a throw WorkflowCancelledException statement
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractCancelReason(node: ts.ThrowStatement, checker: ts.TypeChecker): string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Check if a call expression is array.filter()
|
|
24
|
+
*/
|
|
25
|
+
export declare function isArrayFilter(node: ts.CallExpression): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Check if a call expression is array.some()
|
|
28
|
+
*/
|
|
29
|
+
export declare function isArraySome(node: ts.CallExpression): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a call expression is array.every()
|
|
32
|
+
*/
|
|
33
|
+
export declare function isArrayEvery(node: ts.CallExpression): boolean;
|
|
13
34
|
/**
|
|
14
35
|
* Check if an expression is Promise.all(array.map(...))
|
|
15
36
|
*/
|
|
@@ -26,6 +26,79 @@ export function isWorkflowSleepCall(node, checker) {
|
|
|
26
26
|
ts.isIdentifier(propAccess.expression) &&
|
|
27
27
|
propAccess.expression.text === 'workflow');
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Check if a throw statement throws WorkflowCancelledException
|
|
31
|
+
* Matches: throw new WorkflowCancelledException(...) or throw WorkflowCancelledException(...)
|
|
32
|
+
*/
|
|
33
|
+
export function isThrowCancelException(node) {
|
|
34
|
+
const expr = node.expression;
|
|
35
|
+
if (!expr)
|
|
36
|
+
return false;
|
|
37
|
+
// Check for: throw new WorkflowCancelledException(...)
|
|
38
|
+
if (ts.isNewExpression(expr)) {
|
|
39
|
+
if (ts.isIdentifier(expr.expression)) {
|
|
40
|
+
return expr.expression.text === 'WorkflowCancelledException';
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Check for: throw WorkflowCancelledException(...) - function call style
|
|
44
|
+
if (ts.isCallExpression(expr)) {
|
|
45
|
+
if (ts.isIdentifier(expr.expression)) {
|
|
46
|
+
return expr.expression.text === 'WorkflowCancelledException';
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Extract the reason string from a throw WorkflowCancelledException statement
|
|
53
|
+
*/
|
|
54
|
+
export function extractCancelReason(node, checker) {
|
|
55
|
+
const expr = node.expression;
|
|
56
|
+
if (!expr)
|
|
57
|
+
return undefined;
|
|
58
|
+
let args;
|
|
59
|
+
if (ts.isNewExpression(expr) && expr.arguments) {
|
|
60
|
+
args = expr.arguments;
|
|
61
|
+
}
|
|
62
|
+
else if (ts.isCallExpression(expr)) {
|
|
63
|
+
args = expr.arguments;
|
|
64
|
+
}
|
|
65
|
+
if (args && args.length > 0) {
|
|
66
|
+
const firstArg = args[0];
|
|
67
|
+
if (ts.isStringLiteral(firstArg)) {
|
|
68
|
+
return firstArg.text;
|
|
69
|
+
}
|
|
70
|
+
// For template literals or other expressions, return the source text
|
|
71
|
+
return firstArg.getText();
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check if a call expression is array.filter()
|
|
77
|
+
*/
|
|
78
|
+
export function isArrayFilter(node) {
|
|
79
|
+
if (!ts.isPropertyAccessExpression(node.expression)) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return node.expression.name.text === 'filter';
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Check if a call expression is array.some()
|
|
86
|
+
*/
|
|
87
|
+
export function isArraySome(node) {
|
|
88
|
+
if (!ts.isPropertyAccessExpression(node.expression)) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
return node.expression.name.text === 'some';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Check if a call expression is array.every()
|
|
95
|
+
*/
|
|
96
|
+
export function isArrayEvery(node) {
|
|
97
|
+
if (!ts.isPropertyAccessExpression(node.expression)) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return node.expression.name.text === 'every';
|
|
101
|
+
}
|
|
29
102
|
/**
|
|
30
103
|
* Check if an expression is Promise.all(array.map(...))
|
|
31
104
|
*/
|
|
@@ -86,6 +159,21 @@ export function isSequentialFanout(node) {
|
|
|
86
159
|
}
|
|
87
160
|
return true;
|
|
88
161
|
}
|
|
162
|
+
/**
|
|
163
|
+
* Extract full source path from an expression (e.g., data.memberEmails)
|
|
164
|
+
*/
|
|
165
|
+
function extractSourcePath(expr) {
|
|
166
|
+
if (ts.isIdentifier(expr)) {
|
|
167
|
+
return expr.text;
|
|
168
|
+
}
|
|
169
|
+
if (ts.isPropertyAccessExpression(expr)) {
|
|
170
|
+
const base = extractSourcePath(expr.expression);
|
|
171
|
+
if (base) {
|
|
172
|
+
return `${base}.${expr.name.text}`;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
89
177
|
/**
|
|
90
178
|
* Extract the variable name from a for..of statement
|
|
91
179
|
*/
|
|
@@ -98,16 +186,8 @@ export function extractForOfVariable(node) {
|
|
|
98
186
|
return null;
|
|
99
187
|
}
|
|
100
188
|
const itemVar = decl.name.text;
|
|
101
|
-
// Extract source variable
|
|
102
|
-
|
|
103
|
-
if (ts.isIdentifier(node.expression)) {
|
|
104
|
-
sourceVar = node.expression.text;
|
|
105
|
-
}
|
|
106
|
-
else if (ts.isPropertyAccessExpression(node.expression) &&
|
|
107
|
-
ts.isIdentifier(node.expression.expression)) {
|
|
108
|
-
// Handle data.memberEmails
|
|
109
|
-
sourceVar = node.expression.expression.text;
|
|
110
|
-
}
|
|
189
|
+
// Extract source variable with full path (e.g., data.memberEmails)
|
|
190
|
+
const sourceVar = extractSourcePath(node.expression);
|
|
111
191
|
if (!sourceVar) {
|
|
112
192
|
return null;
|
|
113
193
|
}
|
|
@@ -13,8 +13,10 @@ export interface ValidationError {
|
|
|
13
13
|
* - VariableStatement (const/let declarations)
|
|
14
14
|
* - ExpressionStatement (await workflow.do, await workflow.sleep, await Promise.all)
|
|
15
15
|
* - IfStatement (branches)
|
|
16
|
+
* - SwitchStatement (switch/case)
|
|
16
17
|
* - ForOfStatement (sequential fanout)
|
|
17
18
|
* - ReturnStatement
|
|
19
|
+
* - ThrowStatement (for WorkflowCancelledException)
|
|
18
20
|
* - Block (containers)
|
|
19
21
|
*/
|
|
20
22
|
export declare function validateNoDisallowedPatterns(node: ts.Node): ValidationError[];
|
|
@@ -6,8 +6,10 @@ import * as ts from 'typescript';
|
|
|
6
6
|
* - VariableStatement (const/let declarations)
|
|
7
7
|
* - ExpressionStatement (await workflow.do, await workflow.sleep, await Promise.all)
|
|
8
8
|
* - IfStatement (branches)
|
|
9
|
+
* - SwitchStatement (switch/case)
|
|
9
10
|
* - ForOfStatement (sequential fanout)
|
|
10
11
|
* - ReturnStatement
|
|
12
|
+
* - ThrowStatement (for WorkflowCancelledException)
|
|
11
13
|
* - Block (containers)
|
|
12
14
|
*/
|
|
13
15
|
export function validateNoDisallowedPatterns(node) {
|
|
@@ -17,8 +19,10 @@ export function validateNoDisallowedPatterns(node) {
|
|
|
17
19
|
if (ts.isVariableStatement(statement) ||
|
|
18
20
|
ts.isExpressionStatement(statement) ||
|
|
19
21
|
ts.isIfStatement(statement) ||
|
|
22
|
+
ts.isSwitchStatement(statement) ||
|
|
20
23
|
ts.isForOfStatement(statement) ||
|
|
21
|
-
ts.isReturnStatement(statement)
|
|
24
|
+
ts.isReturnStatement(statement) ||
|
|
25
|
+
ts.isThrowStatement(statement)) {
|
|
22
26
|
// Allowed statement type - recurse into it
|
|
23
27
|
visitNode(statement);
|
|
24
28
|
}
|
|
@@ -26,7 +30,7 @@ export function validateNoDisallowedPatterns(node) {
|
|
|
26
30
|
// Unknown/disallowed statement type
|
|
27
31
|
const nodeType = ts.SyntaxKind[statement.kind];
|
|
28
32
|
errors.push({
|
|
29
|
-
message: `Statement type '${nodeType}' is not allowed in simple workflows. Allowed: const/let, if/else, for..of, return, and workflow calls. If this should be supported, please report the node type: ${nodeType}`,
|
|
33
|
+
message: `Statement type '${nodeType}' is not allowed in simple workflows. Allowed: const/let, if/else, switch/case, for..of, return, throw, and workflow calls. If this should be supported, please report the node type: ${nodeType}`,
|
|
30
34
|
node: statement,
|
|
31
35
|
});
|
|
32
36
|
}
|
|
@@ -85,14 +89,28 @@ export function validateNoDisallowedPatterns(node) {
|
|
|
85
89
|
*/
|
|
86
90
|
export function validateAwaitedCalls(node) {
|
|
87
91
|
const errors = [];
|
|
88
|
-
function visit(node, parentIsAwait = false) {
|
|
92
|
+
function visit(node, parentIsAwait = false, insidePromiseAll = false) {
|
|
93
|
+
// Check if this is Promise.all(...) first, before checking for workflow calls
|
|
94
|
+
if (ts.isCallExpression(node) &&
|
|
95
|
+
ts.isPropertyAccessExpression(node.expression)) {
|
|
96
|
+
const propAccess = node.expression;
|
|
97
|
+
if (propAccess.name.text === 'all' &&
|
|
98
|
+
ts.isIdentifier(propAccess.expression) &&
|
|
99
|
+
propAccess.expression.text === 'Promise') {
|
|
100
|
+
// console.log('[DEBUG] Found Promise.all, setting insidePromiseAll=true')
|
|
101
|
+
// Visit children with insidePromiseAll = true
|
|
102
|
+
ts.forEachChild(node, (child) => visit(child, parentIsAwait, true));
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Now check for workflow calls
|
|
89
107
|
if (ts.isCallExpression(node)) {
|
|
90
108
|
if (ts.isPropertyAccessExpression(node.expression)) {
|
|
91
109
|
const propAccess = node.expression;
|
|
92
110
|
if ((propAccess.name.text === 'do' || propAccess.name.text === 'sleep') &&
|
|
93
111
|
ts.isIdentifier(propAccess.expression) &&
|
|
94
112
|
propAccess.expression.text === 'workflow') {
|
|
95
|
-
if (!parentIsAwait) {
|
|
113
|
+
if (!parentIsAwait && !insidePromiseAll) {
|
|
96
114
|
errors.push({
|
|
97
115
|
message: `workflow.${propAccess.name.text}() must be awaited`,
|
|
98
116
|
node,
|
|
@@ -103,11 +121,11 @@ export function validateAwaitedCalls(node) {
|
|
|
103
121
|
}
|
|
104
122
|
}
|
|
105
123
|
if (ts.isAwaitExpression(node)) {
|
|
106
|
-
//
|
|
107
|
-
|
|
124
|
+
// Visit the expression itself with parentIsAwait=true
|
|
125
|
+
visit(node.expression, true, insidePromiseAll);
|
|
108
126
|
}
|
|
109
127
|
else {
|
|
110
|
-
ts.forEachChild(node, (child) => visit(child, false));
|
|
128
|
+
ts.forEachChild(node, (child) => visit(child, false, insidePromiseAll));
|
|
111
129
|
}
|
|
112
130
|
}
|
|
113
131
|
visit(node);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts DSL (Domain Specific Language) step-based format to graph node format
|
|
3
|
+
*/
|
|
4
|
+
import type { WorkflowsMeta } from '@pikku/core/workflow';
|
|
5
|
+
import type { SerializedWorkflowGraph } from './workflow-graph.types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Convert a DSL workflow to graph format
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertDslToGraph(workflowName: string, meta: WorkflowsMeta[string]): SerializedWorkflowGraph;
|
|
10
|
+
/**
|
|
11
|
+
* Convert all DSL workflows to graph format
|
|
12
|
+
*/
|
|
13
|
+
export declare function convertAllDslToGraphs(workflowsMeta: WorkflowsMeta): Record<string, SerializedWorkflowGraph>;
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
function makeNodeId(step, index, prefix) {
|
|
2
|
+
if ('stepName' in step && step.stepName) {
|
|
3
|
+
return step.stepName;
|
|
4
|
+
}
|
|
5
|
+
return `${prefix}_${index}`;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Check if a node is a terminal flow (no next step should follow)
|
|
9
|
+
*/
|
|
10
|
+
function isTerminalFlow(node) {
|
|
11
|
+
if ('flow' in node) {
|
|
12
|
+
// Cancel and return are terminal flows - they end execution
|
|
13
|
+
return node.flow === 'cancel' || node.flow === 'return';
|
|
14
|
+
}
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Convert InputSource to DataRef
|
|
19
|
+
*/
|
|
20
|
+
function convertInputSource(source) {
|
|
21
|
+
if (source.from === 'literal') {
|
|
22
|
+
return source.value;
|
|
23
|
+
}
|
|
24
|
+
if (source.from === 'input') {
|
|
25
|
+
return { $ref: 'trigger', path: source.path };
|
|
26
|
+
}
|
|
27
|
+
if (source.from === 'outputVar') {
|
|
28
|
+
return { $ref: source.name, path: source.path };
|
|
29
|
+
}
|
|
30
|
+
if (source.from === 'item') {
|
|
31
|
+
return { $ref: '$item', path: source.path };
|
|
32
|
+
}
|
|
33
|
+
if (source.from === 'stateVar') {
|
|
34
|
+
return { $state: source.name, path: source.path };
|
|
35
|
+
}
|
|
36
|
+
if (source.from === 'template') {
|
|
37
|
+
return {
|
|
38
|
+
$template: {
|
|
39
|
+
parts: source.parts,
|
|
40
|
+
expressions: source.expressions?.map((expr) => convertInputSource(expr)),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return source.value;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Convert a single DSL step to graph node(s)
|
|
48
|
+
*/
|
|
49
|
+
function convertStepToNode(step, index, steps, nodeIdPrefix = 'step') {
|
|
50
|
+
const nodeId = makeNodeId(step, index, nodeIdPrefix);
|
|
51
|
+
const nextNodeId = index < steps.length - 1
|
|
52
|
+
? makeNodeId(steps[index + 1], index + 1, nodeIdPrefix)
|
|
53
|
+
: undefined;
|
|
54
|
+
switch (step.type) {
|
|
55
|
+
case 'rpc': {
|
|
56
|
+
const node = {
|
|
57
|
+
nodeId,
|
|
58
|
+
rpcName: step.rpcName,
|
|
59
|
+
next: nextNodeId,
|
|
60
|
+
};
|
|
61
|
+
if (step.inputs) {
|
|
62
|
+
if (step.inputs === 'passthrough') {
|
|
63
|
+
// Entire data is passed through - store as reference to trigger
|
|
64
|
+
node.input = { $passthrough: { $ref: 'trigger' } };
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
node.input = {};
|
|
68
|
+
for (const [key, source] of Object.entries(step.inputs)) {
|
|
69
|
+
node.input[key] = convertInputSource(source);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (step.outputVar) {
|
|
74
|
+
node.outputVar = step.outputVar;
|
|
75
|
+
}
|
|
76
|
+
if (step.options) {
|
|
77
|
+
node.options = {
|
|
78
|
+
retries: step.options.retries,
|
|
79
|
+
retryDelay: step.options.retryDelay?.toString(),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
return [node];
|
|
83
|
+
}
|
|
84
|
+
case 'sleep': {
|
|
85
|
+
const node = {
|
|
86
|
+
nodeId,
|
|
87
|
+
flow: 'sleep',
|
|
88
|
+
duration: step.duration,
|
|
89
|
+
next: nextNodeId,
|
|
90
|
+
};
|
|
91
|
+
return [node];
|
|
92
|
+
}
|
|
93
|
+
case 'inline': {
|
|
94
|
+
const node = {
|
|
95
|
+
nodeId,
|
|
96
|
+
flow: 'inline',
|
|
97
|
+
description: step.description,
|
|
98
|
+
next: nextNodeId,
|
|
99
|
+
};
|
|
100
|
+
return [node];
|
|
101
|
+
}
|
|
102
|
+
case 'branch': {
|
|
103
|
+
// Convert all branch conditions (if/else-if chain)
|
|
104
|
+
const branchNodes = [];
|
|
105
|
+
const branches = [];
|
|
106
|
+
for (let i = 0; i < step.branches.length; i++) {
|
|
107
|
+
const branchSteps = convertStepsToNodes(step.branches[i].steps, `${nodeId}_branch${i}`);
|
|
108
|
+
if (branchSteps.length > 0) {
|
|
109
|
+
branches.push({
|
|
110
|
+
condition: step.branches[i].condition,
|
|
111
|
+
entry: branchSteps[0].nodeId,
|
|
112
|
+
});
|
|
113
|
+
// Link last branch node back to next (unless terminal flow)
|
|
114
|
+
if (nextNodeId) {
|
|
115
|
+
const lastBranch = branchSteps[branchSteps.length - 1];
|
|
116
|
+
if (!lastBranch.next && !isTerminalFlow(lastBranch))
|
|
117
|
+
lastBranch.next = nextNodeId;
|
|
118
|
+
}
|
|
119
|
+
branchNodes.push(...branchSteps);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// Convert else branch
|
|
123
|
+
const elseNodes = step.elseSteps
|
|
124
|
+
? convertStepsToNodes(step.elseSteps, `${nodeId}_else`)
|
|
125
|
+
: [];
|
|
126
|
+
if (elseNodes.length > 0 && nextNodeId) {
|
|
127
|
+
const lastElse = elseNodes[elseNodes.length - 1];
|
|
128
|
+
if (!lastElse.next && !isTerminalFlow(lastElse))
|
|
129
|
+
lastElse.next = nextNodeId;
|
|
130
|
+
}
|
|
131
|
+
const node = {
|
|
132
|
+
nodeId,
|
|
133
|
+
flow: 'branch',
|
|
134
|
+
branches,
|
|
135
|
+
elseEntry: elseNodes.length > 0 ? elseNodes[0].nodeId : undefined,
|
|
136
|
+
next: nextNodeId,
|
|
137
|
+
};
|
|
138
|
+
return [node, ...branchNodes, ...elseNodes];
|
|
139
|
+
}
|
|
140
|
+
case 'switch': {
|
|
141
|
+
const caseNodes = [];
|
|
142
|
+
const cases = [];
|
|
143
|
+
for (let i = 0; i < step.cases.length; i++) {
|
|
144
|
+
const caseSteps = convertStepsToNodes(step.cases[i].steps, `${nodeId}_case${i}`);
|
|
145
|
+
if (caseSteps.length > 0) {
|
|
146
|
+
cases.push({
|
|
147
|
+
value: step.cases[i].value,
|
|
148
|
+
expression: step.cases[i].expression,
|
|
149
|
+
entry: caseSteps[0].nodeId,
|
|
150
|
+
});
|
|
151
|
+
// Link last case node to next (unless terminal flow)
|
|
152
|
+
if (nextNodeId) {
|
|
153
|
+
const lastCase = caseSteps[caseSteps.length - 1];
|
|
154
|
+
if (!lastCase.next && !isTerminalFlow(lastCase))
|
|
155
|
+
lastCase.next = nextNodeId;
|
|
156
|
+
}
|
|
157
|
+
caseNodes.push(...caseSteps);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
let defaultEntry;
|
|
161
|
+
if (step.defaultSteps) {
|
|
162
|
+
const defaultNodes = convertStepsToNodes(step.defaultSteps, `${nodeId}_default`);
|
|
163
|
+
if (defaultNodes.length > 0) {
|
|
164
|
+
defaultEntry = defaultNodes[0].nodeId;
|
|
165
|
+
// Link last default node to next (unless terminal flow)
|
|
166
|
+
if (nextNodeId) {
|
|
167
|
+
const lastDefault = defaultNodes[defaultNodes.length - 1];
|
|
168
|
+
if (!lastDefault.next && !isTerminalFlow(lastDefault))
|
|
169
|
+
lastDefault.next = nextNodeId;
|
|
170
|
+
}
|
|
171
|
+
caseNodes.push(...defaultNodes);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
const node = {
|
|
175
|
+
nodeId,
|
|
176
|
+
flow: 'switch',
|
|
177
|
+
expression: step.expression,
|
|
178
|
+
cases,
|
|
179
|
+
defaultEntry,
|
|
180
|
+
next: nextNodeId,
|
|
181
|
+
};
|
|
182
|
+
return [node, ...caseNodes];
|
|
183
|
+
}
|
|
184
|
+
case 'parallel': {
|
|
185
|
+
// Convert children to nodes
|
|
186
|
+
const childNodes = [];
|
|
187
|
+
const childEntries = [];
|
|
188
|
+
for (let i = 0; i < step.children.length; i++) {
|
|
189
|
+
const childSteps = convertStepToNode(step.children[i], i, step.children, `${nodeId}_child`);
|
|
190
|
+
if (childSteps.length > 0) {
|
|
191
|
+
childEntries.push(childSteps[0].nodeId);
|
|
192
|
+
childNodes.push(...childSteps);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const node = {
|
|
196
|
+
nodeId,
|
|
197
|
+
flow: 'parallel',
|
|
198
|
+
children: childEntries,
|
|
199
|
+
next: nextNodeId,
|
|
200
|
+
};
|
|
201
|
+
return [node, ...childNodes];
|
|
202
|
+
}
|
|
203
|
+
case 'fanout': {
|
|
204
|
+
// Convert child step
|
|
205
|
+
const childNodes = convertStepToNode(step.child, 0, [step.child], `${nodeId}_item`);
|
|
206
|
+
const node = {
|
|
207
|
+
nodeId,
|
|
208
|
+
flow: 'fanout',
|
|
209
|
+
sourceVar: step.sourceVar,
|
|
210
|
+
itemVar: step.itemVar,
|
|
211
|
+
mode: step.mode,
|
|
212
|
+
childEntry: childNodes.length > 0 ? childNodes[0].nodeId : undefined,
|
|
213
|
+
timeBetween: step.timeBetween,
|
|
214
|
+
next: nextNodeId,
|
|
215
|
+
};
|
|
216
|
+
return [node, ...childNodes];
|
|
217
|
+
}
|
|
218
|
+
case 'filter': {
|
|
219
|
+
const node = {
|
|
220
|
+
nodeId,
|
|
221
|
+
flow: 'filter',
|
|
222
|
+
sourceVar: step.sourceVar,
|
|
223
|
+
itemVar: step.itemVar,
|
|
224
|
+
condition: step.condition,
|
|
225
|
+
outputVar: step.outputVar,
|
|
226
|
+
next: nextNodeId,
|
|
227
|
+
};
|
|
228
|
+
return [node];
|
|
229
|
+
}
|
|
230
|
+
case 'arrayPredicate': {
|
|
231
|
+
const node = {
|
|
232
|
+
nodeId,
|
|
233
|
+
flow: 'arrayPredicate',
|
|
234
|
+
mode: step.mode,
|
|
235
|
+
sourceVar: step.sourceVar,
|
|
236
|
+
itemVar: step.itemVar,
|
|
237
|
+
condition: step.condition,
|
|
238
|
+
outputVar: step.outputVar,
|
|
239
|
+
next: nextNodeId,
|
|
240
|
+
};
|
|
241
|
+
return [node];
|
|
242
|
+
}
|
|
243
|
+
case 'return': {
|
|
244
|
+
const node = {
|
|
245
|
+
nodeId,
|
|
246
|
+
flow: 'return',
|
|
247
|
+
outputs: step.outputs,
|
|
248
|
+
};
|
|
249
|
+
return [node];
|
|
250
|
+
}
|
|
251
|
+
case 'cancel': {
|
|
252
|
+
const node = {
|
|
253
|
+
nodeId,
|
|
254
|
+
flow: 'cancel',
|
|
255
|
+
reason: step.reason,
|
|
256
|
+
};
|
|
257
|
+
return [node];
|
|
258
|
+
}
|
|
259
|
+
case 'set': {
|
|
260
|
+
const node = {
|
|
261
|
+
nodeId,
|
|
262
|
+
flow: 'set',
|
|
263
|
+
variable: step.variable,
|
|
264
|
+
value: step.value,
|
|
265
|
+
next: nextNodeId,
|
|
266
|
+
};
|
|
267
|
+
return [node];
|
|
268
|
+
}
|
|
269
|
+
default:
|
|
270
|
+
return [];
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Convert array of steps to graph nodes
|
|
275
|
+
*/
|
|
276
|
+
function convertStepsToNodes(steps, nodeIdPrefix = 'step') {
|
|
277
|
+
const allNodes = [];
|
|
278
|
+
for (let i = 0; i < steps.length; i++) {
|
|
279
|
+
const nodes = convertStepToNode(steps[i], i, steps, nodeIdPrefix);
|
|
280
|
+
allNodes.push(...nodes);
|
|
281
|
+
}
|
|
282
|
+
return allNodes;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Convert a DSL workflow to graph format
|
|
286
|
+
*/
|
|
287
|
+
export function convertDslToGraph(workflowName, meta) {
|
|
288
|
+
const nodes = convertStepsToNodes(meta.steps);
|
|
289
|
+
const nodesRecord = {};
|
|
290
|
+
for (const node of nodes) {
|
|
291
|
+
nodesRecord[node.nodeId] = node;
|
|
292
|
+
}
|
|
293
|
+
const entryNodeIds = nodes.length > 0 ? [nodes[0].nodeId] : [];
|
|
294
|
+
// Determine source type based on dsl flag:
|
|
295
|
+
// - dsl === true: pure DSL workflow, can be serialized
|
|
296
|
+
// - dsl === false: complex workflow with inline steps, not serializable
|
|
297
|
+
const source = meta.dsl === false ? 'complex' : 'dsl';
|
|
298
|
+
return {
|
|
299
|
+
name: workflowName,
|
|
300
|
+
pikkuFuncId: meta.pikkuFuncId,
|
|
301
|
+
source,
|
|
302
|
+
description: meta.description,
|
|
303
|
+
tags: meta.tags,
|
|
304
|
+
context: meta.context,
|
|
305
|
+
nodes: nodesRecord,
|
|
306
|
+
entryNodeIds,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Convert all DSL workflows to graph format
|
|
311
|
+
*/
|
|
312
|
+
export function convertAllDslToGraphs(workflowsMeta) {
|
|
313
|
+
const result = {};
|
|
314
|
+
for (const [name, meta] of Object.entries(workflowsMeta)) {
|
|
315
|
+
result[name] = convertDslToGraph(name, meta);
|
|
316
|
+
}
|
|
317
|
+
return result;
|
|
318
|
+
}
|