uni-flow 公开 API(中文注解) / createEngineFromYaml
Function: createEngineFromYaml()
createEngineFromYaml(
source,options?):Promise<WorkflowEngine>
Defined in: yaml/loader.ts:251
YAML 路径主入口:从文件路径或 YAML 字符串加载、校验并构造 WorkflowEngine。
source若为可读文件路径则读文件;否则当作 YAML 文本- 校验走 validateWorkflowYamlSource;
uses经 builtin +registry/bindings解析 - 生产编排优先本函数;代码拼拓扑请用 createWorkflowEngine
Parameters
source
string
Workflow YAML 文件路径,或完整 YAML 字符串
options?
CreateEngineFromYamlOptions = {}
插件表、HTTP bindings、额外引擎选项
Returns
Promise<WorkflowEngine>
可调用 run() / resume() 的引擎
Example
ts
import { createEngineFromYaml, createMockAdapter } from 'uni-flow';
const engine = await createEngineFromYaml(
`apiVersion: uniflow/v1
kind: Workflow
metadata:
id: demo
spec:
units:
- id: echo
uses: demo.echo
flow:
type: sequential
order: [echo]
`,
{
registry: {
'demo.echo': () => createMockAdapter({
responseFn: (input) => ({
content: `echo:${input.task}`,
toolCalls: [],
stopReason: 'stop',
metadata: {},
}),
}),
},
},
);
const result = await engine.run({ task: 'hello' });
console.log(result.state['output.echo']);