Skip to content

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


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

Class: RouterFlow

Defined in: core/control-flow/parallel-router.ts:108

路由 ControlFlow:先跑 router Unit,再根据路由键调度对应 handler。

路由键由 routeExtractor 从 router 的 AgentOutput 取出,并写入 router.selectedKey。 也可由 Workflow YAML 的 flow.type: router 映射而来。

Implements

Constructors

Constructor

new RouterFlow(router, handlers, routeExtractor): RouterFlow

Defined in: core/control-flow/parallel-router.ts:116

Parameters

router

WorkflowUnit

负责产出路由决策的 Unit

handlers

Map<string, WorkflowUnit>

路由键 → handler Unit 的映射

routeExtractor

(output) => string

从 router 输出提取路由键(字符串)

Returns

RouterFlow

Properties

type

readonly type: "router" = 'router'

Defined in: core/control-flow/parallel-router.ts:109

Flow 类型名。

Implementation of

ControlFlow.type

Methods

isComplete()

isComplete(state): boolean

Defined in: core/control-flow/parallel-router.ts:184

Parameters

state

SharedState

当前 SharedState

Returns

boolean

已选路由键且对应 handler.<key>.done 为真

Implementation of

ControlFlow.isComplete


isHandlerUnit()

isHandlerUnit(unitId): boolean

Defined in: core/control-flow/parallel-router.ts:176

Parameters

unitId

string

待判定的 Unit id

Returns

boolean

是否为任一 handler Unit


isRouterUnit()

isRouterUnit(unitId): boolean

Defined in: core/control-flow/parallel-router.ts:168

Parameters

unitId

string

待判定的 Unit id

Returns

boolean

是否为 router Unit


next()

next(state, completedUnits?): WorkflowUnit[]

Defined in: core/control-flow/parallel-router.ts:132

未路由时返回 router;已选键后返回对应 handler(若尚未完成)。

Parameters

state

SharedState

当前 SharedState(可读 router.selectedKeyhandler.<key>.done

completedUnits?

Set<string>

引擎侧已完成 Unit id 集合

Returns

WorkflowUnit[]

下一轮要执行的 Unit 列表(0 或 1 个)

Implementation of

ControlFlow.next


onRouterComplete()

onRouterComplete(output, state): void

Defined in: core/control-flow/parallel-router.ts:158

由引擎在 router Unit 完成后调用:提取路由键并写入 SharedState。

Parameters

output

AgentOutput

router 的 AgentOutput

state

SharedState

当前 SharedState(写入 router.selectedKey

Returns

void


restore()

restore(cursor): void

Defined in: core/control-flow/parallel-router.ts:202

Parameters

cursor

ControlFlowCursor

先前 serialize() 的结果

Returns

void

Implementation of

ControlFlow.restore


serialize()

serialize(): ControlFlowCursor

Defined in: core/control-flow/parallel-router.ts:192

Returns

ControlFlowCursor

可写入检查点的游标(含 routed / selectedKey

Implementation of

ControlFlow.serialize

MIT Licensed