@ldsg/workflow 0.3.31 → 0.3.32
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/__tests__/unit/evaluate-variables.prefixItems.test.js +197 -191
- package/dist/__tests__/unit/resource.js +61 -61
- package/dist/__tests__/unit/resource.portId.test.js +144 -144
- package/dist/constants.d.ts +3 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +10 -10
- package/dist/handler.d.ts +4 -4
- package/dist/index.d.ts +5 -5
- package/dist/instantiate-resource.d.ts +4 -4
- package/dist/instantiate-resource.js +1 -1
- package/dist/resource.d.ts +2 -2
- package/dist/resource.js +12 -12
- package/dist/types/index.d.ts +6 -6
- package/dist/types/json_schema_with_expression_extension.d.ts +6 -6
- package/dist/types/json_schema_with_expression_extension.d.ts.map +1 -1
- package/dist/types/node.d.ts +1 -1
- package/dist/types/specific-resource-settings.d.ts +1 -1
- package/dist/types/specific-resource-settings.d.ts.map +1 -1
- package/dist/types/specific-resource-settings.js +1 -1
- package/dist/types/workflow.d.ts +3 -3
- package/dist/utils/evaluate-variables/constants.js +17 -17
- package/dist/utils/evaluate-variables/index.d.ts +1 -1
- package/dist/utils/evaluate-variables/index.debug.js +79 -79
- package/dist/utils/evaluate-variables/index.js +2 -2
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.d.ts +1 -1
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/index.js +2 -2
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/resolve-json-schema.d.ts +1 -1
- package/dist/utils/evaluate-variables/utils/get-data-with-json-schema-and-input/resolve-json-schema.js +11 -11
- package/dist/utils/evaluate-variables/utils/get-field-path-by-field-type-key.js +3 -3
- package/dist/utils/execute-workflow.d.ts +2 -2
- package/dist/utils/execute-workflow.d.ts.map +1 -1
- package/dist/utils/execute-workflow.js +19 -17
- package/package.json +11 -7
|
@@ -9,7 +9,7 @@ const lodash_1 = __importDefault(require("lodash"));
|
|
|
9
9
|
const resolveJsonSchema = async (params) => {
|
|
10
10
|
var _a;
|
|
11
11
|
const { input, jsonSchema, source } = params;
|
|
12
|
-
const { type: jsonSchemaType,
|
|
12
|
+
const { type: jsonSchemaType, "x-expression": jsonSchemaExpression, const: jsonSchemaConst, prefixItems: jsonSchemaPrefixItems, } = jsonSchema;
|
|
13
13
|
let data;
|
|
14
14
|
/**
|
|
15
15
|
* 若常量值存在,则直接返回
|
|
@@ -27,7 +27,7 @@ const resolveJsonSchema = async (params) => {
|
|
|
27
27
|
data = await expression.evaluate(input);
|
|
28
28
|
}
|
|
29
29
|
switch (jsonSchemaType) {
|
|
30
|
-
case
|
|
30
|
+
case "object": {
|
|
31
31
|
data = data !== null && data !== void 0 ? data : {};
|
|
32
32
|
const jsonSchemaProperties = (_a = jsonSchema.properties) !== null && _a !== void 0 ? _a : {};
|
|
33
33
|
const keys = lodash_1.default.keys(jsonSchemaProperties);
|
|
@@ -36,11 +36,11 @@ const resolveJsonSchema = async (params) => {
|
|
|
36
36
|
const resolveJsonSchemaRes = await (0, exports.resolveJsonSchema)({
|
|
37
37
|
jsonSchema: jsonSchemaProperties[key],
|
|
38
38
|
input,
|
|
39
|
-
source
|
|
39
|
+
source,
|
|
40
40
|
});
|
|
41
41
|
const res = {
|
|
42
42
|
key,
|
|
43
|
-
resolveJsonSchemaRes
|
|
43
|
+
resolveJsonSchemaRes,
|
|
44
44
|
};
|
|
45
45
|
return res;
|
|
46
46
|
});
|
|
@@ -50,7 +50,7 @@ const resolveJsonSchema = async (params) => {
|
|
|
50
50
|
});
|
|
51
51
|
break;
|
|
52
52
|
}
|
|
53
|
-
case
|
|
53
|
+
case "array": {
|
|
54
54
|
/**
|
|
55
55
|
* 如果 prefixItems 存在,则转为数组结果
|
|
56
56
|
*/
|
|
@@ -60,7 +60,7 @@ const resolveJsonSchema = async (params) => {
|
|
|
60
60
|
const resolveJsonSchemaRes = await (0, exports.resolveJsonSchema)({
|
|
61
61
|
jsonSchema: prefixItem,
|
|
62
62
|
input,
|
|
63
|
-
source
|
|
63
|
+
source,
|
|
64
64
|
});
|
|
65
65
|
return resolveJsonSchemaRes.data;
|
|
66
66
|
});
|
|
@@ -76,13 +76,13 @@ const resolveJsonSchema = async (params) => {
|
|
|
76
76
|
}
|
|
77
77
|
break;
|
|
78
78
|
}
|
|
79
|
-
case
|
|
80
|
-
case
|
|
81
|
-
case
|
|
82
|
-
case
|
|
79
|
+
case "boolean":
|
|
80
|
+
case "integer":
|
|
81
|
+
case "number":
|
|
82
|
+
case "string": {
|
|
83
83
|
break;
|
|
84
84
|
}
|
|
85
|
-
case
|
|
85
|
+
case "null": {
|
|
86
86
|
break;
|
|
87
87
|
}
|
|
88
88
|
default: {
|
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getFieldPathByFieldTypeKey = void 0;
|
|
4
4
|
const getFieldPathByFieldTypeKey = (fieldTypeKey) => {
|
|
5
5
|
// 将字符串按点分割成数组
|
|
6
|
-
const splitRes = fieldTypeKey.split(
|
|
6
|
+
const splitRes = fieldTypeKey.split(".");
|
|
7
7
|
// 过滤数组:除了索引为复数且值为 properties ,其他所有元素均保留
|
|
8
8
|
const filterRes = splitRes.filter((value, index) => {
|
|
9
|
-
const res = !(value ===
|
|
9
|
+
const res = !(value === "properties" && index % 2 === 0);
|
|
10
10
|
return res;
|
|
11
11
|
});
|
|
12
12
|
// 将过滤后的数组重新用点连接成字符串
|
|
13
|
-
const res = filterRes.join(
|
|
13
|
+
const res = filterRes.join(".");
|
|
14
14
|
return res;
|
|
15
15
|
};
|
|
16
16
|
exports.getFieldPathByFieldTypeKey = getFieldPathByFieldTypeKey;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { WorkflowData, WorkflowExecuteRes, WorkflowNodeInfo, WorkflowVariables } from
|
|
1
|
+
import { WorkflowData, WorkflowExecuteRes, WorkflowNodeInfo, WorkflowVariables } from "../types";
|
|
2
2
|
export interface ExecuteWorkflowParams {
|
|
3
3
|
context: any;
|
|
4
4
|
endWorkflowNodeResourceId: string;
|
|
5
5
|
nodes: WorkflowNodeInfo[];
|
|
6
|
-
edges: WorkflowData[
|
|
6
|
+
edges: WorkflowData["edges"];
|
|
7
7
|
presetWorkflowVariables?: Record<string, WorkflowVariables>;
|
|
8
8
|
startWorkflowNodeResourceId: string;
|
|
9
9
|
variables: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"execute-workflow.d.ts","sourceRoot":"","sources":["../../src/utils/execute-workflow.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAqBlB,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,GAAG,CAAC;IACb,yBAAyB,EAAE,MAAM,CAAC;IAClC,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC5D,2BAA2B,EAAE,MAAM,CAAC;IACpC,SAAS,EAAE,GAAG,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,GAAG,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;
|
|
1
|
+
{"version":3,"file":"execute-workflow.d.ts","sourceRoot":"","sources":["../../src/utils/execute-workflow.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,iBAAiB,EAElB,MAAM,UAAU,CAAC;AAqBlB,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,GAAG,CAAC;IACb,yBAAyB,EAAE,MAAM,CAAC;IAClC,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,KAAK,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC7B,uBAAuB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;IAC5D,2BAA2B,EAAE,MAAM,CAAC;IACpC,SAAS,EAAE,GAAG,CAAC;IACf,YAAY,EAAE,YAAY,CAAC;IAC3B,YAAY,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,GAAG,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAiLD;;GAEG;AACH,wBAAsB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAsHhG"}
|
|
@@ -7,16 +7,16 @@ exports.executeWorkflow = executeWorkflow;
|
|
|
7
7
|
const api_1 = __importDefault(require("@opentelemetry/api"));
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const evaluate_variables_1 = require("./evaluate-variables");
|
|
10
|
-
const tracer = api_1.default.trace.getTracer(
|
|
10
|
+
const tracer = api_1.default.trace.getTracer("workspace");
|
|
11
11
|
/**
|
|
12
12
|
* 安全的 JSON 序列化,处理循环引用
|
|
13
13
|
*/
|
|
14
14
|
function safeStringify(obj) {
|
|
15
15
|
const seen = new WeakSet();
|
|
16
16
|
return JSON.stringify(obj, (key, value) => {
|
|
17
|
-
if (typeof value ===
|
|
17
|
+
if (typeof value === "object" && value !== null) {
|
|
18
18
|
if (seen.has(value)) {
|
|
19
|
-
return
|
|
19
|
+
return "[Circular Reference]";
|
|
20
20
|
}
|
|
21
21
|
seen.add(value);
|
|
22
22
|
}
|
|
@@ -30,23 +30,25 @@ async function executeNode(node, context, workflowVariablesMap, isFirstLevel, wo
|
|
|
30
30
|
const { id, propertiesSchema, execute: nodeExecute } = node;
|
|
31
31
|
const workflowVariables = Object.fromEntries(workflowVariablesMap);
|
|
32
32
|
// 输入变量从工作流变量中使用表达式获取
|
|
33
|
-
const workflowNodePropertiesInputSchema = lodash_1.default.get(propertiesSchema,
|
|
34
|
-
const workflowNodePropertiesOutputSchema = lodash_1.default.get(propertiesSchema,
|
|
33
|
+
const workflowNodePropertiesInputSchema = lodash_1.default.get(propertiesSchema, "properties.input");
|
|
34
|
+
const workflowNodePropertiesOutputSchema = lodash_1.default.get(propertiesSchema, "properties.output");
|
|
35
35
|
/**
|
|
36
36
|
* 对于开始节点,不忽略 input 表达式,但替换工作流内部变量为工作流输入变量。
|
|
37
37
|
*/
|
|
38
|
-
const workflowNodeInputExpressionEvaluateInput = isFirstLevel
|
|
38
|
+
const workflowNodeInputExpressionEvaluateInput = isFirstLevel
|
|
39
|
+
? workflowInputVariables
|
|
40
|
+
: workflowVariables;
|
|
39
41
|
let workflowNodeInputVariables = {};
|
|
40
42
|
if (workflowNodePropertiesInputSchema) {
|
|
41
43
|
const { variables } = await (0, evaluate_variables_1.evaluateVariables)({
|
|
42
44
|
jsonSchema: workflowNodePropertiesInputSchema,
|
|
43
|
-
variables: workflowNodeInputExpressionEvaluateInput
|
|
45
|
+
variables: workflowNodeInputExpressionEvaluateInput,
|
|
44
46
|
});
|
|
45
47
|
workflowNodeInputVariables = variables;
|
|
46
48
|
}
|
|
47
49
|
const { variables: workflowNodeOutputExpressionEvaluateInput, portId } = await nodeExecute({
|
|
48
50
|
context,
|
|
49
|
-
variables: workflowNodeInputVariables
|
|
51
|
+
variables: workflowNodeInputVariables,
|
|
50
52
|
});
|
|
51
53
|
/**
|
|
52
54
|
* 输出变量从结果中使用表达式获取
|
|
@@ -56,7 +58,7 @@ async function executeNode(node, context, workflowVariablesMap, isFirstLevel, wo
|
|
|
56
58
|
if (workflowNodePropertiesOutputSchema) {
|
|
57
59
|
const { variables } = await (0, evaluate_variables_1.evaluateVariables)({
|
|
58
60
|
jsonSchema: workflowNodePropertiesOutputSchema,
|
|
59
|
-
variables: workflowNodeOutputExpressionEvaluateInput
|
|
61
|
+
variables: workflowNodeOutputExpressionEvaluateInput,
|
|
60
62
|
});
|
|
61
63
|
workflowNodeOutputVariables = variables;
|
|
62
64
|
}
|
|
@@ -65,13 +67,13 @@ async function executeNode(node, context, workflowVariablesMap, isFirstLevel, wo
|
|
|
65
67
|
nodeId: id,
|
|
66
68
|
portId,
|
|
67
69
|
inputVariables: workflowNodeInputVariables,
|
|
68
|
-
outputVariables: workflowNodeOutputVariables
|
|
70
|
+
outputVariables: workflowNodeOutputVariables,
|
|
69
71
|
});
|
|
70
72
|
}
|
|
71
73
|
const res = {
|
|
72
74
|
nodeId: id,
|
|
73
75
|
variables: workflowNodeOutputVariables,
|
|
74
|
-
portId
|
|
76
|
+
portId,
|
|
75
77
|
};
|
|
76
78
|
return res;
|
|
77
79
|
}
|
|
@@ -152,15 +154,15 @@ function findNextNodeIds(levelResults, edges, visitedNodes, completedNodePredece
|
|
|
152
154
|
* 执行工作流
|
|
153
155
|
*/
|
|
154
156
|
async function executeWorkflow(params) {
|
|
155
|
-
const { context, endWorkflowNodeResourceId, nodes, edges, presetWorkflowVariables = {}, startWorkflowNodeResourceId, variables: workflowInputVariables, traceContext } = params;
|
|
157
|
+
const { context, endWorkflowNodeResourceId, nodes, edges, presetWorkflowVariables = {}, startWorkflowNodeResourceId, variables: workflowInputVariables, traceContext, } = params;
|
|
156
158
|
// 使用传入的 traceContext 或当前活跃的 context 来创建 span
|
|
157
159
|
const parentContext = traceContext || api_1.default.context.active();
|
|
158
|
-
const executeWorkflowSpan = tracer.startSpan(
|
|
160
|
+
const executeWorkflowSpan = tracer.startSpan("execute-workflow", undefined, parentContext);
|
|
159
161
|
const workflowVariablesMap = new Map(Object.entries(presetWorkflowVariables));
|
|
160
162
|
const startNode = nodes.find((value) => value.id === startWorkflowNodeResourceId);
|
|
161
163
|
const endNode = nodes.find((value) => value.id === endWorkflowNodeResourceId);
|
|
162
164
|
if (!startNode || !endNode) {
|
|
163
|
-
throw new Error(
|
|
165
|
+
throw new Error("invalid workflow nodes");
|
|
164
166
|
}
|
|
165
167
|
let workflowOutputVariables;
|
|
166
168
|
// 使用动态执行,根据 portId 决定下一步执行哪些节点
|
|
@@ -185,12 +187,12 @@ async function executeWorkflow(params) {
|
|
|
185
187
|
if (!node) {
|
|
186
188
|
throw new Error(`node not found: ${nodeId}`);
|
|
187
189
|
}
|
|
188
|
-
span.addEvent(
|
|
190
|
+
span.addEvent("execution workflow node");
|
|
189
191
|
const res = await executeNode(node, context, workflowVariablesMap, isFirstLevel, workflowInputVariables);
|
|
190
192
|
const { portId: outputPortId } = res;
|
|
191
193
|
span.setAttributes({
|
|
192
194
|
currentNodeId: nodeId,
|
|
193
|
-
outputPortId
|
|
195
|
+
outputPortId,
|
|
194
196
|
});
|
|
195
197
|
span.end();
|
|
196
198
|
return res;
|
|
@@ -214,7 +216,7 @@ async function executeWorkflow(params) {
|
|
|
214
216
|
isFirstLevel = false;
|
|
215
217
|
}
|
|
216
218
|
const res = {
|
|
217
|
-
variables: workflowOutputVariables
|
|
219
|
+
variables: workflowOutputVariables,
|
|
218
220
|
};
|
|
219
221
|
executeWorkflowSpan.end();
|
|
220
222
|
return res;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ldsg/workflow",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.32",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"@opentelemetry/api": "~1.9.0",
|
|
15
15
|
"json-schema": "0.4.0",
|
|
16
16
|
"json-schema-default": "^1.0.2",
|
|
17
|
-
"jsonata": "
|
|
17
|
+
"jsonata": "2.2.2",
|
|
18
18
|
"lodash": "^4.17.21",
|
|
19
19
|
"zod": "^4.1.11",
|
|
20
|
-
"@ldsg/constants": "0.3.
|
|
21
|
-
"@ldsg/
|
|
22
|
-
"@ldsg/
|
|
23
|
-
"@ldsg/resource-definition": "0.3.
|
|
20
|
+
"@ldsg/constants": "0.3.32",
|
|
21
|
+
"@ldsg/resource": "0.3.32",
|
|
22
|
+
"@ldsg/handler": "0.3.32",
|
|
23
|
+
"@ldsg/resource-definition": "0.3.32"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/fs-extra": "^11.0.4",
|
|
@@ -29,11 +29,13 @@
|
|
|
29
29
|
"@types/lodash": "^4.14.202",
|
|
30
30
|
"fs-extra": "^11.3.0",
|
|
31
31
|
"jest": "^29.5.0",
|
|
32
|
+
"oxfmt": "latest",
|
|
33
|
+
"oxlint": "latest",
|
|
32
34
|
"supertest": "^6.3.4",
|
|
33
35
|
"ts-jest": "^29.1.5",
|
|
34
36
|
"ts-node": "^10.9.2",
|
|
35
37
|
"typescript": "^5.8.3",
|
|
36
|
-
"@ldsg/types": "0.3.
|
|
38
|
+
"@ldsg/types": "0.3.32"
|
|
37
39
|
},
|
|
38
40
|
"publishConfig": {
|
|
39
41
|
"access": "public"
|
|
@@ -41,6 +43,8 @@
|
|
|
41
43
|
"scripts": {
|
|
42
44
|
"build": "tsc --project tsconfig.build.json",
|
|
43
45
|
"clean": "rm -rf dist",
|
|
46
|
+
"format": "oxfmt --write src/",
|
|
47
|
+
"lint": "oxlint src/",
|
|
44
48
|
"test": "jest"
|
|
45
49
|
}
|
|
46
50
|
}
|