uni-flow 公开 API(中文注解) / createWorkflowEngine
Function: createWorkflowEngine()
createWorkflowEngine(
config,options?):WorkflowEngine
Defined in: core/workflow-engine.ts:513
代码路径入口:用已组装的 WorkflowConfig 创建 WorkflowEngine。 适合测试、Composite 等 YAML v1 难以表达的拓扑;生产编排优先 createEngineFromYaml。
Parameters
config
含 workflowId、units、controlFlow 的配置
options?
可选 Layer4 依赖与策略
Returns
可调用 run() / resume() 的引擎实例
Example
ts
import {
createWorkflowEngine,
createSharedState,
SequentialFlow,
createMockAdapter,
} from 'uni-flow';
const echo = {
id: 'echo',
runtime: createMockAdapter({ content: 'hi' }),
terminationPolicy: { type: 'stop-reason', reasons: ['stop'] },
inputAdapter: (s) => ({ task: String(s.get('task') ?? '') }),
outputAdapter: (out, s) => s.set('output.echo', out.content),
};
const units = new Map([[echo.id, echo]]);
const engine = createWorkflowEngine({
workflowId: 'demo',
units,
controlFlow: new SequentialFlow([echo]),
sharedState: createSharedState(),
});
await engine.run({ task: 'ping' });