runWorkflow method

Future<AiWorkflowRunResult> runWorkflow(
  1. String workflowName, {
  2. String? userId,
  3. String? tenantId,
  4. String? threadId,
  5. Map<String, dynamic> input = const {},
  6. Context? context,
  7. Map<String, dynamic> metadata = const {},
  8. bool isBackground = false,
})

Executes a registered workflow by name.

Implementation

Future<AiWorkflowRunResult> runWorkflow(
  String workflowName, {
  String? userId,
  String? tenantId,
  String? threadId,
  Map<String, dynamic> input = const {},
  Context? context,
  Map<String, dynamic> metadata = const {},
  bool isBackground = false,
}) async {
  final workflow = workflows.workflow(workflowName);
  if (workflow == null) {
    throw StateError('Unknown AI workflow: $workflowName');
  }

  final output = await workflow.run(
    AiWorkflowContext(
      userId: userId,
      tenantId: tenantId,
      threadId: threadId,
      input: input,
      requestContext: context,
      metadata: {
        'workflow': workflow.name,
        ...metadata,
      },
      runId: generateAiRunId(),
      isBackground: isBackground,
    ),
  );

  return AiWorkflowRunResult(
    workflowName: workflow.name,
    output: output,
  );
}