mm_workflow 1.0.1

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/README.en.md ADDED
@@ -0,0 +1,36 @@
1
+ # 超级美眉工作流
2
+
3
+ #### Description
4
+ 这是一个workflow JSON模块,它能够用JSON表示编程逻辑,可通过可视化的工作流编程、积木编程或者直接手写json的方式实现,最终可转成python、nodeJS的代码,或实现代码之间的互转。是AI的逻辑编程,从而节省对tokens的消耗。
5
+
6
+ #### Software Architecture
7
+ Software architecture description
8
+
9
+ #### Installation
10
+
11
+ 1. xxxx
12
+ 2. xxxx
13
+ 3. xxxx
14
+
15
+ #### Instructions
16
+
17
+ 1. xxxx
18
+ 2. xxxx
19
+ 3. xxxx
20
+
21
+ #### Contribution
22
+
23
+ 1. Fork the repository
24
+ 2. Create Feat_xxx branch
25
+ 3. Commit your code
26
+ 4. Create Pull Request
27
+
28
+
29
+ #### Gitee Feature
30
+
31
+ 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md
32
+ 2. Gitee blog [blog.gitee.com](https://blog.gitee.com)
33
+ 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore)
34
+ 4. The most valuable open source project [GVP](https://gitee.com/gvp)
35
+ 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help)
36
+ 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # 超级美眉工作流
2
+
3
+ #### 介绍
4
+ 这是一个workflow JSON模块,它能够用JSON表示编程逻辑,可通过可视化的工作流编程、积木编程或者直接手写json的方式实现,最终可转成python、nodeJS的代码,或实现代码之间的互转。是AI的逻辑编程,从而节省对tokens的消耗。
5
+
6
+ #### 软件架构
7
+ 软件架构说明
8
+
9
+
10
+ #### 安装教程
11
+
12
+ 1. xxxx
13
+ 2. xxxx
14
+ 3. xxxx
15
+
16
+ #### 使用说明
17
+
18
+ 1. xxxx
19
+ 2. xxxx
20
+ 3. xxxx
21
+
22
+ #### 参与贡献
23
+
24
+ 1. Fork 本仓库
25
+ 2. 新建 Feat_xxx 分支
26
+ 3. 提交代码
27
+ 4. 新建 Pull Request
28
+
29
+
30
+ #### 特技
31
+
32
+ 1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md
33
+ 2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com)
34
+ 3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目
35
+ 4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
36
+ 5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help)
37
+ 6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)
package/demo/index.js ADDED
@@ -0,0 +1,38 @@
1
+ const { Editor, Engine } = require('../index.js');
2
+
3
+ class Demo {
4
+ constructor() {
5
+ super();
6
+ }
7
+ /**
8
+ * 测试编辑器
9
+ */
10
+ testEditor() {
11
+ let editor = new Editor();
12
+ let node = editor.toNode();
13
+ return node;
14
+ }
15
+ /**
16
+ * 测试引擎
17
+ */
18
+ testEngine(node) {
19
+ let engine = new Engine();
20
+ let code = engine.jsonToJavaScript(node);
21
+ return code;
22
+ }
23
+ }
24
+
25
+ async function test() {
26
+ console.log(" ====== 开始测试 ====== ");
27
+ let demo = new Demo();
28
+
29
+ console.log("测试编辑器 =>");
30
+ let node = await demo.testEditor();
31
+ console.log("编辑结果", node);
32
+
33
+ console.log("测试引擎 =>");
34
+ let code = await demo.testEngine(node);
35
+ console.log("转换结果", code);
36
+ }
37
+
38
+ test();
@@ -0,0 +1,32 @@
1
+ {
2
+ "user_list": [
3
+ {
4
+ "id": 1,
5
+ "name": "张三",
6
+ "age": 25,
7
+ "user_type": "normal"
8
+ },
9
+ {
10
+ "id": 2,
11
+ "name": "李四",
12
+ "age": 35,
13
+ "user_type": "vip"
14
+ },
15
+ {
16
+ "id": 3,
17
+ "name": "王五",
18
+ "age": 28,
19
+ "user_type": "admin"
20
+ },
21
+ {
22
+ "id": 4,
23
+ "name": "赵六",
24
+ "age": 22,
25
+ "user_type": "test"
26
+ }
27
+ ],
28
+ "age_threshold": 18,
29
+ "max_iterations": 10,
30
+ "concurrency_limit": 3,
31
+ "retry_count": 2
32
+ }
package/index.js ADDED
@@ -0,0 +1,7 @@
1
+ const { Editor } = require('./lib/editor');
2
+ const { Engine } = require('./lib/engine');
3
+
4
+ module.exports = {
5
+ Editor,
6
+ Engine
7
+ };
@@ -0,0 +1,259 @@
1
+ /**
2
+ * 编译器
3
+ */
4
+ class Compiler {
5
+ /**
6
+ * 构造函数
7
+ * @param {object} 配置参数
8
+ */
9
+ constructor(config = {}) {
10
+ this.config = { ...config };
11
+ }
12
+ }
13
+
14
+ /**
15
+ * 转成JS代码
16
+ * @param {array} nodes 节点
17
+ * @returns {string} 返回代码
18
+ */
19
+ Compiler.prototype.toCode = function (nodes) {
20
+ let code = '';
21
+ for (let i = 0; i < nodes.length; i++) {
22
+ let node = nodes[i];
23
+ code += this.toCodeByFunction(node) + '\n';
24
+ }
25
+ return code;
26
+ };
27
+
28
+ /**
29
+ * 将body节点转为代码
30
+ * @param {array} nodes 节点
31
+ * @returns {string} 返回代码
32
+ */
33
+ Compiler.prototype.toCodeByBody = function (nodes) {
34
+ let code = '';
35
+ for (let i = 0; i < nodes.length; i++) {
36
+ let node = nodes[i];
37
+ code += this.toCodeByBodyLine(node) + "\n";
38
+ }
39
+ return code;
40
+ };
41
+
42
+ /**
43
+ * 将body成员节点转为代码
44
+ * @param {array} node 节点
45
+ * @returns {string} 返回代码
46
+ */
47
+ Compiler.prototype.toCodeByBodyLine = function (node) {
48
+ let code = '';
49
+ if (node.function_call) {
50
+ code = this.toCodeByFunctionCall(node);
51
+ }
52
+ else if (node.if) {
53
+ code = this.toCodeByIf(node);
54
+ }
55
+ else if (node.for) {
56
+ code = this.toCodeByFor(node);
57
+ }
58
+ else if (node.switch) {
59
+ code = this.toCodeBySwitch(node);
60
+ }
61
+ else if (node.return !== undefined) {
62
+ code = this.toCodeByReturn(node);
63
+ }
64
+ else if (node.value !== undefined) {
65
+ code = this.toCodeByValue(node);
66
+ }
67
+ return code;
68
+ };
69
+
70
+ /**
71
+ * 将if节点转为代码
72
+ * @param {object} node 节点
73
+ * @returns {string} 返回代码
74
+ */
75
+ Compiler.prototype.toCodeByIf = function (node) {
76
+ let code = '';
77
+
78
+ return code;
79
+ };
80
+
81
+ /**
82
+ * 将for节点转为代码
83
+ * @param {object} node 节点
84
+ * @returns {string} 返回代码
85
+ */
86
+ Compiler.prototype.toCodeByFor = function (node) {
87
+ let code = '';
88
+
89
+ return code;
90
+ };
91
+
92
+ /**
93
+ * 将for节点转为代码
94
+ * @param {object} node 节点
95
+ * @returns {string} 返回代码
96
+ */
97
+ Compiler.prototype.toCodeBySwitch = function (node) {
98
+ let code = '';
99
+
100
+ return code;
101
+ };
102
+
103
+ /**
104
+ * 将function节点转为代码
105
+ * @param {object} node 节点
106
+ * @returns {string} 返回代码
107
+ */
108
+ Compiler.prototype.toCodeByFunction = function (node) {
109
+ let code = '';
110
+
111
+ return code;
112
+ };
113
+
114
+ /**
115
+ * 将function call节点转为代码
116
+ * @param {object} node 节点
117
+ * @returns {string} 返回代码
118
+ */
119
+ Compiler.prototype.toCodeByFunctionCall = function (node) {
120
+ let code = '';
121
+
122
+ if (node.source && node.function_call) {
123
+ let functionName = node.function_call;
124
+ let source = node.source;
125
+
126
+ code += `await ${source}.${functionName}(`;
127
+
128
+ if (node.inputs && node.inputs.length > 0) {
129
+ let params = [];
130
+ for (let i = 0; i < node.inputs.length; i++) {
131
+ let input = node.inputs[i];
132
+ if (this.isVar(input)) {
133
+ let varName = this.getVarName(input);
134
+ params.push(varName);
135
+ } else {
136
+ params.push(`'${input}'`);
137
+ }
138
+ }
139
+ code += params.join(', ');
140
+ }
141
+
142
+ code += ');\n';
143
+ }
144
+
145
+ return code;
146
+ };
147
+
148
+ /**
149
+ * 将function节点转为代码
150
+ * @param {object} node 节点
151
+ * @returns {string} 返回代码
152
+ */
153
+ Compiler.prototype.toCodeByWhile = function (node) {
154
+ let code = '';
155
+ let cases = node.cases;
156
+ for (let i = 0; i < cases.length; i++) {
157
+ let o = cases[i];
158
+
159
+ }
160
+ code += this.toCodeByBody(node) + '\n';
161
+ return code;
162
+ };
163
+
164
+ /**
165
+ * 将case节点转为代码
166
+ * @param {Array} node 字符串数组
167
+ * @returns {string} 返回代码
168
+ */
169
+ Compiler.prototype.toCodeByCase = function (node) {
170
+ let code = '';
171
+ let arr = node.is;
172
+ for (let i = 0; i < arr.length; i++) {
173
+ let value = arr[i];
174
+ if (typeof value === 'string') {
175
+ code += `case '${value}':\n`;
176
+ } else {
177
+ code += `case ${value}:\n`
178
+ }
179
+ }
180
+ code += this.toCodeByBody(node.body) + "\n";
181
+ return code;
182
+ };
183
+
184
+ /**
185
+ * 将value节点转为代码
186
+ * @param {object} node 节点
187
+ * @returns {string} 返回代码
188
+ */
189
+ Compiler.prototype.toCodeByValue = function (node) {
190
+ let code = '';
191
+ let value = node.value;
192
+ if (value) {
193
+ if (typeof value === 'string') {
194
+ let val_name = this.getVarName(value);
195
+ if (val_name) {
196
+ code += ` ${val_name};`
197
+ }
198
+ else {
199
+ code += ` '${val_name}';`
200
+ }
201
+ }
202
+ else {
203
+ code += ` ${value};`
204
+ }
205
+ }
206
+ return code;
207
+ };
208
+
209
+ /**
210
+ * 将return节点转为代码
211
+ * @param {object} node 节点
212
+ * @returns {string} 返回代码
213
+ */
214
+ Compiler.prototype.toCodeByReturn = function (node) {
215
+ let code = 'return';
216
+ let value = node.return;
217
+ if (value) {
218
+ if (typeof value === 'string') {
219
+ let val_name = this.getVarName(value);
220
+ if (val_name) {
221
+ code += ` ${val_name};`
222
+ }
223
+ else {
224
+ code += ` '${val_name}';`
225
+ }
226
+ }
227
+ else {
228
+ code += ` ${value};`
229
+ }
230
+ }
231
+ return code;
232
+ };
233
+
234
+ /**
235
+ * 判断文本是否为变量
236
+ * @param {string} text 被判断的文本
237
+ * @returns {boolean} 是返回true,否则返回false
238
+ */
239
+ Compiler.prototype.isVar = function (text) {
240
+ if (/\$\{[$a-zA-Z0-9_]\}/.test(text)) {
241
+ return true;
242
+ }
243
+ else {
244
+ return false;
245
+ }
246
+ };
247
+
248
+ /**
249
+ * 获取变量名
250
+ * @param {string} text 被截取的文本
251
+ * @returns {string} 返回变量名
252
+ */
253
+ Compiler.prototype.getVarName = function (text) {
254
+ return text.between("${", "}");
255
+ };
256
+
257
+ module.exports = {
258
+ Compiler
259
+ };
package/lib/editor.js ADDED
@@ -0,0 +1,66 @@
1
+ const { Base } = require('mm_expand');
2
+
3
+ /**
4
+ * 编辑器类
5
+ */
6
+ class Editor extends Base {
7
+ /**
8
+ * 构造函数
9
+ * @param {object} config 配置项
10
+ * @param {object} parent 父类
11
+ */
12
+ constructor(config, parent) {
13
+ super(config, parent);
14
+ this.node = {};
15
+ }
16
+ }
17
+
18
+ /**
19
+ * 添加节点
20
+ * @param {string} target_node_id 目标节点ID
21
+ * @param {object} node 节点对象
22
+ * @returns {string} 添加成功返回添加的节点ID,失败返回null
23
+ */
24
+ Editor.prototype.addNode = function (target_node_id, node) {
25
+ return node.id;
26
+ };
27
+
28
+ /**
29
+ * 修改节点
30
+ * @param {string} target_node_id 目标节点ID
31
+ * @param {object} node 节点对象
32
+ * @returns {string} 修改成功返回修改的节点ID,失败返回null
33
+ */
34
+ Editor.prototype.setNode = function (target_node_id, node) {
35
+ return node.id;
36
+ };
37
+
38
+ /**
39
+ * 删除节点
40
+ * @param {string} target_node_id 目标节点ID
41
+ * @returns {string} 删除成功返回删除的节点ID,失败返回null
42
+ */
43
+ Editor.prototype.delNode = function (target_node_id) {
44
+ return target_node_id;
45
+ };
46
+
47
+ /**
48
+ * 获取节点
49
+ * @param {string} target_node_id 目标节点ID
50
+ * @returns {object} 节点对象
51
+ */
52
+ Editor.prototype.getNode = function (target_node_id) {
53
+
54
+ };
55
+
56
+ /**
57
+ * 将节点对象转换为workflow JSON
58
+ * @returns {string} workflow JSON
59
+ */
60
+ Editor.prototype.toNode = function () {
61
+ return this.node;
62
+ };
63
+
64
+ module.exports = {
65
+ Editor
66
+ };
package/lib/engine.js ADDED
@@ -0,0 +1,217 @@
1
+ const { Base } = require('mm_expand');
2
+ const { JavaScript } = require('./javascript');
3
+ const { Python } = require('./python');
4
+
5
+ /**
6
+ * 引擎类
7
+ */
8
+ class Engine extends Base {
9
+ /**
10
+ * 构造函数
11
+ * @param {object} config 配置项
12
+ * @param {object} parent 父类
13
+ */
14
+ constructor(config, parent) {
15
+ super(config, parent);
16
+ this.javaScript = new JavaScript();
17
+ this.python = new Python();
18
+ }
19
+ }
20
+
21
+ /**
22
+ * 转换为JS代码
23
+ * @param {object} node 节点对象
24
+ * @returns {string} 代码字符串
25
+ */
26
+ Engine.prototype.jsonToJavaScript = function (node) {
27
+ if (!node) {
28
+ throw new TypeError('节点对象(node)不能为空');
29
+ }
30
+ return this.javaScript.toCode(node);
31
+ };
32
+
33
+ /**
34
+ * 转换为Python代码
35
+ * @param {object} node 节点对象
36
+ * @returns {string} 代码字符串
37
+ */
38
+ Engine.prototype.jsonToPython = function (node) {
39
+ if (!node) {
40
+ throw new TypeError('节点对象(node)不能为空');
41
+ }
42
+ return this.python.toCode(node);
43
+ };
44
+
45
+
46
+ /**
47
+ * 转换为指定语言代码
48
+ * @param {string} lang 代码语言 可选值:js/javascript; py/python
49
+ * @param {object} node 节点对象
50
+ * @returns {string} 代码字符串
51
+ */
52
+ Engine.prototype.toCode = function (lang, node) {
53
+ if (!lang) {
54
+ throw new TypeError('代码语言(lang)不能为空');
55
+ }
56
+ switch (lang) {
57
+ case 'js':
58
+ case 'javascript':
59
+ return this.jsonToJavaScript(node);
60
+ case 'py':
61
+ case 'python':
62
+ return this.jsonToPython(node);
63
+ default:
64
+ return '';
65
+ }
66
+ };
67
+
68
+ /**
69
+ * 将代码转换为workflow JSON
70
+ * @param {string} lang 代码语言 可选值:js/javascript; py/python
71
+ * @param {string} code 代码
72
+ * @returns {string} workflow JSON
73
+ */
74
+ Engine.prototype.toJson = function (lang, code) {
75
+ if (!lang) {
76
+ throw new TypeError('代码语言(lang)不能为空');
77
+ }
78
+ switch (lang) {
79
+ case 'js':
80
+ case 'javascript':
81
+ return this.javaScriptToJson(code);
82
+ case 'py':
83
+ case 'python':
84
+ return this.pythonToJson(code);
85
+ default:
86
+ return '';
87
+ }
88
+ };
89
+
90
+ /**
91
+ * 将Python代码转换为workflow JSON
92
+ * @param {string} code 代码
93
+ * @returns {string} workflow JSON
94
+ */
95
+ Engine.prototype.pythonToJson = function (code) {
96
+ if (!code) {
97
+ throw new TypeError('代码(code)不能为空');
98
+ }
99
+ let json = this.python.toJson(code);
100
+ return json;
101
+ };
102
+
103
+ /**
104
+ * 将JS代码转换为workflow JSON
105
+ * @param {string} code 代码
106
+ * @returns {string} workflow JSON
107
+ */
108
+ Engine.prototype.javaScriptToJson = function (code) {
109
+ if (!code) {
110
+ throw new TypeError('代码(code)不能为空');
111
+ }
112
+ let json = this.javaScript.toJson(code);
113
+ return json;
114
+ };
115
+
116
+ /**
117
+ * 生成智能体工具信息
118
+ * @param {object} node 节点对象
119
+ * @returns {string} 信息字符串
120
+ */
121
+ Engine.prototype.generateToolInfo = function (node) {
122
+ if (!node) {
123
+ throw new TypeError('节点对象(node)不能为空');
124
+ }
125
+ return
126
+ };
127
+
128
+ /**
129
+ * 生成智能体工具代码
130
+ * @param {string} lang 代码语言 可选值:js/javascript; py/python
131
+ * @param {object} node 节点对象
132
+ * @returns {string} 代码字符串
133
+ */
134
+ Engine.prototype.generateToolCode = function (lang, node) {
135
+ if (!lang) {
136
+ throw new TypeError('代码语言(lang)不能为空');
137
+ }
138
+ if (!node) {
139
+ throw new TypeError('节点对象(node)不能为空');
140
+ }
141
+ switch (lang) {
142
+ case 'js':
143
+ case 'javascript':
144
+ return this.jsonToJavaScript(node);
145
+ case 'py':
146
+ case 'python':
147
+ return this.jsonToPython(node);
148
+ default:
149
+ return '';
150
+ }
151
+ };
152
+
153
+ /**
154
+ * 生成智能体工具
155
+ * @param {string} file 文件路径
156
+ * @param {object} node 节点对象
157
+ * @returns {string} 成功返回文件路径,失败返回null
158
+ */
159
+ Engine.prototype.generateTool = function (file, node) {
160
+ if (!file) {
161
+ throw new TypeError('文件路径(file)不能为空');
162
+ }
163
+ let info = this.generateToolInfo(node);
164
+ if (!info) {
165
+ throw new TypeError('生成智能体工具失败');
166
+ }
167
+ let lang = file.extname().substring(1);
168
+ let code = this.generateToolCode(lang, node);
169
+ if (!code) {
170
+ throw new TypeError('生成智能体工具代码失败');
171
+ }
172
+ let dir = file.fullname();
173
+ let json_file = file.basename() + '.json';
174
+ let code_file = file.basename() + '.' + lang + '.json';
175
+
176
+ let ret = {
177
+ info: info,
178
+ code: code,
179
+ lang: lang,
180
+ dir: dir,
181
+ json_file: json_file.fullname(dir),
182
+ code_file: code_file.fullname(dir)
183
+ };
184
+
185
+ return ret;
186
+ };
187
+
188
+ /**
189
+ * 运行节点
190
+ * @param {object} node 节点对象
191
+ * @param {object} mod 变量值对象 变量名:变量值对
192
+ * @returns {object} 运行结果对象 包含result和mod属性
193
+ */
194
+ Engine.prototype.run = function (node, mod) {
195
+ if (!node) {
196
+ throw new TypeError('节点对象(node)不能为空');
197
+ }
198
+ code = this.javaScript.toCode(node);
199
+ if (!code) {
200
+ throw new Error('转换为JS代码失败');
201
+ }
202
+ // 前置代码
203
+ let code_header = '';
204
+ for (let key in mod) {
205
+ code_header += 'let ' + key + ' = ' + mod[key] + ';\n';
206
+ }
207
+ eval(code_header + code);
208
+ let result = eval(code);
209
+ return {
210
+ result: result,
211
+ mod: mod
212
+ }
213
+ };
214
+
215
+ module.exports = {
216
+ Engine
217
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * JavaScript类
3
+ */
4
+ class JavaScript {
5
+ constructor() {
6
+ }
7
+ }
8
+
9
+ /**
10
+ * 将JavaScript代码转换为workflow JSON
11
+ * @param {string} code 代码
12
+ * @returns {string} workflow JSON
13
+ */
14
+ JavaScript.prototype.toJson = function (code) {
15
+ return code;
16
+ };
17
+
18
+ /**
19
+ * 将workflow JSON转换为JavaScript代码
20
+ * @param {array} node workflow JSON
21
+ * @returns {string} JavaScript代码
22
+ */
23
+ JavaScript.prototype.toCode = function (node) {
24
+ return node;
25
+ };
26
+
27
+ module.exports = {
28
+ JavaScript
29
+ };
package/lib/python.js ADDED
@@ -0,0 +1,30 @@
1
+
2
+ /**
3
+ * Python类
4
+ */
5
+ class Python {
6
+ constructor() {
7
+ }
8
+ }
9
+
10
+ /**
11
+ * 将Python代码转换为workflow JSON
12
+ * @param {string} code 代码
13
+ * @returns {string} workflow JSON
14
+ */
15
+ Python.prototype.toJson = function (code) {
16
+ return code;
17
+ };
18
+
19
+ /**
20
+ * 将workflow JSON转换为Python代码
21
+ * @param {array} node workflow JSON
22
+ * @returns {string} Python代码
23
+ */
24
+ Python.prototype.toCode = function (node) {
25
+ return node;
26
+ };
27
+
28
+ module.exports = {
29
+ Python
30
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 工作流模型
3
+ */
4
+ class Workflow {
5
+ constructor() {
6
+ super();
7
+
8
+ }
9
+ }
@@ -0,0 +1,421 @@
1
+ {
2
+ "name": "demo",
3
+ "title": "多参数异步工作流示例",
4
+ "description": "每个函数接收多个独立参数的工作流设计,包含完整的异步支持和输入输出属性描述",
5
+ "version": "7.0.0",
6
+ "author": "mm_modules_ok",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "workflow",
10
+ "多参数",
11
+ "异步",
12
+ "JSDoc",
13
+ "类型安全",
14
+ "输入输出",
15
+ "完整结构"
16
+ ],
17
+ "workflow": [
18
+ {
19
+ "name": "main",
20
+ "type": "function",
21
+ "title": "工作流入口函数",
22
+ "description": "负责整个用户数据处理流程的协调执行",
23
+ "async": true,
24
+ "timeout": 60000,
25
+ "retry": 2,
26
+ "params": [
27
+ {
28
+ "name": "user_list",
29
+ "type": "array",
30
+ "description": "用户列表",
31
+ "default": [],
32
+ "required": true,
33
+ "min": 0,
34
+ "max": 1000,
35
+ "items": {
36
+ "type": "object",
37
+ "props": [
38
+ {
39
+ "name": "id",
40
+ "type": "number",
41
+ "description": "用户ID",
42
+ "required": true,
43
+ "min": 1,
44
+ "max": 1000000
45
+ },
46
+ {
47
+ "name": "name",
48
+ "type": "string",
49
+ "description": "用户名",
50
+ "required": true,
51
+ "minLength": 1,
52
+ "maxLength": 50
53
+ },
54
+ {
55
+ "name": "age",
56
+ "type": "number",
57
+ "description": "年龄",
58
+ "required": false,
59
+ "default": 0,
60
+ "min": 0,
61
+ "max": 150
62
+ },
63
+ {
64
+ "name": "user_type",
65
+ "type": "string",
66
+ "description": "用户类型",
67
+ "required": false,
68
+ "default": "normal",
69
+ "enum": [
70
+ "normal",
71
+ "vip",
72
+ "admin",
73
+ "test"
74
+ ]
75
+ }
76
+ ]
77
+ }
78
+ },
79
+ {
80
+ "name": "user_type",
81
+ "type": "string",
82
+ "description": "用户类型",
83
+ "required": false,
84
+ "default": "normal",
85
+ "enum": [
86
+ "normal",
87
+ "vip",
88
+ "admin",
89
+ "test"
90
+ ]
91
+ }
92
+ ],
93
+ "return": {
94
+ "name": "summary_report",
95
+ "type": "object",
96
+ "description": "处理完成的汇总报告,包含详细的统计信息和处理结果",
97
+ "required": true,
98
+ "props": [
99
+ {
100
+ "name": "total_processed",
101
+ "type": "number",
102
+ "description": "成功处理的用户数量",
103
+ "required": true,
104
+ "min": 0,
105
+ "max": 1000000
106
+ },
107
+ {
108
+ "name": "total_users",
109
+ "type": "number",
110
+ "description": "总用户数量",
111
+ "required": true,
112
+ "min": 0,
113
+ "max": 1000000
114
+ },
115
+ {
116
+ "name": "processed_users",
117
+ "type": "array",
118
+ "description": "处理完成的用户列表",
119
+ "required": true,
120
+ "min": 0,
121
+ "max": 1000,
122
+ "items": {
123
+ "type": "object",
124
+ "props": [
125
+ {
126
+ "name": "id",
127
+ "type": "number",
128
+ "description": "用户ID",
129
+ "required": true
130
+ },
131
+ {
132
+ "name": "name",
133
+ "type": "string",
134
+ "description": "用户名",
135
+ "required": true
136
+ },
137
+ {
138
+ "name": "user_type",
139
+ "type": "string",
140
+ "description": "处理后的用户类型",
141
+ "required": true,
142
+ "enum": [
143
+ "normal",
144
+ "vip",
145
+ "admin",
146
+ "test"
147
+ ]
148
+ },
149
+ {
150
+ "name": "processed_by",
151
+ "type": "string",
152
+ "description": "处理者标识",
153
+ "required": true
154
+ },
155
+ {
156
+ "name": "processed_at",
157
+ "type": "string",
158
+ "description": "处理时间戳",
159
+ "required": true
160
+ }
161
+ ]
162
+ }
163
+ },
164
+ {
165
+ "name": "generated_at",
166
+ "type": "string",
167
+ "description": "报告生成时间",
168
+ "required": true
169
+ },
170
+ {
171
+ "name": "success_rate",
172
+ "type": "number",
173
+ "description": "处理成功率",
174
+ "required": false,
175
+ "min": 0,
176
+ "max": 1
177
+ }
178
+ ]
179
+ },
180
+ "body": [
181
+ {
182
+ "name": "users",
183
+ "type": "array",
184
+ "function_call": "handle_users",
185
+ "inputs": [
186
+ "${user_list}"
187
+ ],
188
+ "default": []
189
+ }
190
+ ]
191
+ },
192
+ {
193
+ "name": "handle_users",
194
+ "type": "function",
195
+ "title": "处理用户",
196
+ "description": "负责处理指定用户",
197
+ "async": true,
198
+ "timeout": 60000,
199
+ "retry": 2,
200
+ "params": [
201
+ {
202
+ "name": "user_list",
203
+ "type": "array",
204
+ "description": "待处理的用户列表",
205
+ "default": [],
206
+ "required": true,
207
+ "min": 0,
208
+ "max": 1000
209
+ },
210
+ {
211
+ "name": "user_type",
212
+ "type": "string",
213
+ "description": "用户类型",
214
+ "default": "",
215
+ "required": false,
216
+ "min": 0,
217
+ "max": 100
218
+ }
219
+ ],
220
+ "return": {
221
+ "name": "summary_report",
222
+ "type": "object",
223
+ "description": "处理完成的汇总报告,包含详细的统计信息和处理结果",
224
+ "required": true,
225
+ "props": [
226
+ {
227
+ "name": "total_processed",
228
+ "type": "number",
229
+ "description": "成功处理的用户数量",
230
+ "required": true,
231
+ "min": 0,
232
+ "max": 1000000
233
+ },
234
+ {
235
+ "name": "total_users",
236
+ "type": "number",
237
+ "description": "总用户数量",
238
+ "required": true,
239
+ "min": 0,
240
+ "max": 1000000
241
+ },
242
+ {
243
+ "name": "processed_users",
244
+ "type": "array",
245
+ "description": "处理完成的用户列表",
246
+ "required": true,
247
+ "min": 0,
248
+ "max": 1000,
249
+ "items": {
250
+ "type": "object",
251
+ "props": [
252
+ {
253
+ "name": "id",
254
+ "type": "number",
255
+ "description": "用户ID",
256
+ "required": true
257
+ },
258
+ {
259
+ "name": "name",
260
+ "type": "string",
261
+ "description": "用户名",
262
+ "required": true
263
+ },
264
+ {
265
+ "name": "user_type",
266
+ "type": "string",
267
+ "description": "处理后的用户类型",
268
+ "required": true,
269
+ "enum": [
270
+ "normal",
271
+ "vip",
272
+ "admin",
273
+ "test"
274
+ ]
275
+ },
276
+ {
277
+ "name": "processed_by",
278
+ "type": "string",
279
+ "description": "处理者标识",
280
+ "required": true
281
+ },
282
+ {
283
+ "name": "processed_at",
284
+ "type": "string",
285
+ "description": "处理时间戳",
286
+ "required": true
287
+ }
288
+ ]
289
+ }
290
+ },
291
+ {
292
+ "name": "generated_at",
293
+ "type": "string",
294
+ "description": "报告生成时间",
295
+ "required": true
296
+ },
297
+ {
298
+ "name": "success_rate",
299
+ "type": "number",
300
+ "description": "处理成功率",
301
+ "required": false,
302
+ "min": 0,
303
+ "max": 1
304
+ }
305
+ ]
306
+ },
307
+ "body": [
308
+ {
309
+ "name": "user_types",
310
+ "type": "array",
311
+ "value": [
312
+ {
313
+ "name": "普通用户",
314
+ "value": "user"
315
+ },
316
+ {
317
+ "name": "会员",
318
+ "value": "vip"
319
+ },
320
+ {
321
+ "name": "管理员",
322
+ "value": "admin"
323
+ },
324
+ {
325
+ "name": "测试员",
326
+ "value": "test"
327
+ }
328
+ ]
329
+ },
330
+ {
331
+ "name": "has",
332
+ "type": "boolean",
333
+ "default": false,
334
+ "if": {
335
+ "way": "and",
336
+ "condition": [
337
+ {
338
+ "left": {
339
+ "function_call": "hasUser",
340
+ "inputs": [
341
+ "${user_list}",
342
+ "${user_type}"
343
+ ]
344
+ },
345
+ "compare": ">",
346
+ "right": {
347
+ "type": "number",
348
+ "value": -1
349
+ }
350
+ }
351
+ ],
352
+ "body": [
353
+ {
354
+ "source": "has",
355
+ "value": true
356
+ }
357
+ ]
358
+ },
359
+ "else": {
360
+ "body": [
361
+ {
362
+ "source": "has",
363
+ "value": false
364
+ }
365
+ ]
366
+ }
367
+ },
368
+ {
369
+ "name": "users",
370
+ "type": "array",
371
+ "switch": {
372
+ "on": "${user_type}",
373
+ "cases": [
374
+ {
375
+ "is": [
376
+ "admin"
377
+ ],
378
+ "body": [
379
+ {
380
+ "function_call": "process_admin_user",
381
+ "inputs": [
382
+ "${user_list}"
383
+ ]
384
+ }
385
+ ]
386
+ },
387
+ {
388
+ "is": [
389
+ "vip"
390
+ ],
391
+ "body": [
392
+ {
393
+ "source": "users",
394
+ "function_call": "process_admin_vip",
395
+ "inputs": [
396
+ "${user_list}"
397
+ ]
398
+ }
399
+ ]
400
+ },
401
+ {
402
+ "is": [
403
+ "normal"
404
+ ],
405
+ "body": [
406
+ {
407
+ "source": "users",
408
+ "inputs": [
409
+ "${user_list}"
410
+ ]
411
+ }
412
+ ]
413
+ }
414
+ ],
415
+ "default": []
416
+ }
417
+ }
418
+ ]
419
+ }
420
+ ]
421
+ }
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "mm_workflow",
3
+ "version": "1.0.1",
4
+ "description": "这是一个workflow JSON模块,它能够用JSON表示编程逻辑,可通过可视化的工作流编程、积木编程或者直接手写json的方式实现,最终可转成python、nodeJS的代码,或实现代码之间的互转。是AI的逻辑编程,从而节省对tokens的消耗。",
5
+ "keywords": [
6
+ "工作流编程、积木编程、AI编程、json编程、workflow",
7
+ "JSON"
8
+ ],
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://gitee.com/qiuwenwu91/mm_workflow.git"
12
+ },
13
+ "license": "ISC",
14
+ "author": "qww",
15
+ "type": "commonjs",
16
+ "main": "index.js",
17
+ "scripts": {
18
+ "test": "node demo/index.js",
19
+ "dev": "nodemon demo/index.js --watch"
20
+ },
21
+ "dependencies": {
22
+ "mm_expand": "^2.5.1"
23
+ }
24
+ }
@@ -0,0 +1,40 @@
1
+ const { Compiler } = require('./lib/compiler');
2
+
3
+ // 创建编译器实例
4
+ const compiler = new Compiler();
5
+
6
+ // 测试 function_call 节点
7
+ const functionCallNode = {
8
+ source: "users",
9
+ function_call: "process_admin_vip",
10
+ inputs: ["${user_list}"]
11
+ };
12
+
13
+ console.log("测试 function_call 节点编译:");
14
+ console.log("节点结构:", JSON.stringify(functionCallNode, null, 2));
15
+ console.log("编译结果:");
16
+ console.log(compiler.toCodeByFunctionCall(functionCallNode));
17
+
18
+ // 测试没有参数的 function_call
19
+ const functionCallNodeNoParams = {
20
+ source: "users",
21
+ function_call: "get_all_users",
22
+ inputs: []
23
+ };
24
+
25
+ console.log("\n测试无参数 function_call 节点编译:");
26
+ console.log("节点结构:", JSON.stringify(functionCallNodeNoParams, null, 2));
27
+ console.log("编译结果:");
28
+ console.log(compiler.toCodeByFunctionCall(functionCallNodeNoParams));
29
+
30
+ // 测试字符串参数
31
+ const functionCallNodeStringParam = {
32
+ source: "users",
33
+ function_call: "find_by_name",
34
+ inputs: ["admin"]
35
+ };
36
+
37
+ console.log("\n测试字符串参数 function_call 节点编译:");
38
+ console.log("节点结构:", JSON.stringify(functionCallNodeStringParam, null, 2));
39
+ console.log("编译结果:");
40
+ console.log(compiler.toCodeByFunctionCall(functionCallNodeStringParam));
@@ -0,0 +1,11 @@
1
+ const { Compiler } = require('./lib/compiler');
2
+
3
+ // 创建编译器实例
4
+ const compiler = new Compiler();
5
+
6
+ // 测试变量提取
7
+ console.log("测试变量提取功能:");
8
+ console.log("isVar('${user_list}'):", compiler.isVar('${user_list}'));
9
+ console.log("getVarName('${user_list}'):", compiler.getVarName('${user_list}'));
10
+ console.log("isVar('admin'):", compiler.isVar('admin'));
11
+ console.log("getVarName('admin'):", compiler.getVarName('admin'));