registerFlow method

String registerFlow(
  1. FlowDefinition fl
)

mb.FlowDefinition → FlowDefinitionWorkflow factory inserted into OpsRuntime.workflowRegistry. Step execution wires through boot.server.callTool / SkillFacade.execute / LlmPort / recursive OpsFacade.runWorkflow.

Implementation

String registerFlow(mb.FlowDefinition fl) {
  final opsRuntime = system.opsRuntime;
  if (opsRuntime is! ops.OpsRuntime) {
    throw StateError('OpsRuntime not configured');
  }
  final exposedId = '$bundleId.${fl.id}';
  final namespacedFlow = mb.FlowDefinition(
    id: exposedId,
    name: fl.name,
    description: fl.description,
    trigger: fl.trigger,
    steps: fl.steps,
    inputs: fl.inputs,
    output: fl.output,
    timeoutMs: fl.timeoutMs,
    retry: fl.retry,
  );
  final invoke = callTool ?? boot?.callTool;
  opsRuntime.workflowRegistry[exposedId] = () => FlowDefinitionWorkflow(
        namespacedFlow,
        toolDispatcher: invoke == null
            ? null
            : (tool, args) => invoke(tool, args),
        skillRunner: (skillId, inputs) async {
          final result = await system.skill.execute(skillId, inputs);
          return result;
        },
        subFlowRunner: (flowId, subInput) async {
          final handle =
              await system.ops.runWorkflow(flowId, subInput);
          return <String, dynamic>{
            'runId': handle.runId,
            'status': handle.status,
            if (handle.output != null) 'output': handle.output,
            if (handle.error != null) 'error': handle.error,
          };
        },
      );
  return exposedId;
}