// Copyright (c) Microsoft. All rights reserved.
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.Agents.AI.Workflows.Declarative.Kit;
///
/// Signature for a delegate that can be used with .
///
/// The type of message being handled
/// The workflow execution context providing messaging and state services.
/// The the message handled by this executor.
/// A token that can be used to observe cancellation.
/// A representing the asynchronous execution operation.
public delegate ValueTask DelegateAction(IWorkflowContext context, TMessage message, CancellationToken cancellationToken) where TMessage : notnull;
///
/// Base class for an action executor that receives the initial trigger message.
///
public sealed class DelegateExecutor(string id, FormulaSession session, DelegateAction? action = null)
: DelegateExecutor(id, session, action);
///
/// Base class for an action executor that receives the initial trigger message.
///
/// The type of message being handled
public class DelegateExecutor : ActionExecutor where TMessage : notnull
{
private readonly DelegateAction? _action;
///
/// Initializes a new instance of the class.
///
/// The executor id
/// Session to support formula expressions.
/// An optional delegate to execute.
public DelegateExecutor(string id, FormulaSession session, DelegateAction? action = null)
: base(id, session)
{
this._action = action;
}
///
protected override async ValueTask