runWorkflow method
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,
);
}