# ef-compiler 新增结点说明 --- ## 一、action 下添加结点 在 `nodejs/ef-compiler/actions/` 下新建 `hello-parser.js`: ```js const types = ['hello'] function parse(action, parseContext) { const parsed = { type: 'hello', value: action.value || '' } return Object.assign({}, action, parsed) } async function execute(action, ctx) { const msg = action.value ? String(action.value) : 'hello' if (ctx.logMessage) await ctx.logMessage('[hello] ' + msg, ctx.folderPath) return { success: true } } module.exports = { types, parse, execute } ``` 在 `workflow-json-parser.js` 里:`actionModules` 加 `require('./actions/hello-parser.js')`;要中文名则在 `getActionName` 的 `typeNames` 加 `'hello': '打招呼'`。 工作流 JSON:`{ "type": "hello", "value": "世界" }` --- ## 二、fun 下添加结点 --- ### 1. 新建脚本 在 `actions/fun/` 下新建 `xxx.js`: ```js async function executeTestFun({ num, str, folderPath }) { // 函数名与注册表 execute 一致;入参 key 与注册表 in 对应,folderPath 由框架注入 const n = Number(num ?? 0) // 第 1 个入参,转成 number const s = String(str ?? '') // 第 2 个入参,转成 string return { success: true, value: String(n) + s } // 成功:返回 value,框架会写入出参变量并打日志;失败可返回 { success: false, error: '...' } } module.exports = { executeTestFun } // 导出与注册表 execute 同名的函数 ``` --- ### 2. 注册表一条 在 `nodejs/ef-compiler/actions/fun/fun-node-registry.js` 里添加: ```js { type: 'test-fun', // 工作流里的 type category: 'io', // 与 get() 分类一致:io / img / chat in: ['num', 'str'], // 入参名,与上面 executeTestFun 的 input 的 key 一致;对应 inVars[0]、inVars[1] 或 action.num、action.str out: 'variable', // 出参变量名来自 action.variable 或 action.outVars[0] execute: 'executeTestFun', script: 'test-fun.js', displayName: 'test-fun', // 可选 } ``` 工作流示例:`{ "type": "test-fun", "inVars": ["myNum", "myStr"], "variable": "result" }` --- ### 可选:字段别名 在注册表加 `inAlt`: ```js inAlt: { savePath: 'save-path' } ``` --- ### 可选:完全自定义 注册表配 `customParse`、`customRun`;脚本导出 `parseNode`、`runNode`。