Skip to content

uni-flow 公开 API(中文注解)


uni-flow 公开 API(中文注解) / createEngineFromYaml

Function: createEngineFromYaml()

createEngineFromYaml(source, options?): Promise<WorkflowEngine>

Defined in: yaml/loader.ts:251

YAML 路径主入口:从文件路径或 YAML 字符串加载、校验并构造 WorkflowEngine

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']);

MIT Licensed