mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
75a8335af5
* Builds locally and tests pass * Fix typo * Reverted nuget config change to remove internal feed and map to new public object model package with renames. * Renaming Bot object model in additional sample. --------- Co-authored-by: Peter Ibekwe <peibekwe@microsoft.com>
44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.Interpreter;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.Kit;
|
|
using Microsoft.Agents.AI.Workflows.Declarative.PowerFx;
|
|
using Microsoft.Agents.ObjectModel;
|
|
using Microsoft.Agents.ObjectModel.Abstractions;
|
|
using Microsoft.PowerFx.Types;
|
|
using Microsoft.Shared.Diagnostics;
|
|
|
|
namespace Microsoft.Agents.AI.Workflows.Declarative.ObjectModel;
|
|
|
|
internal sealed class ParseValueExecutor(ParseValue model, WorkflowFormulaState state) :
|
|
DeclarativeActionExecutor<ParseValue>(model, state)
|
|
{
|
|
protected override async ValueTask<object?> ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken = default)
|
|
{
|
|
PropertyPath variablePath = Throw.IfNull(this.Model.Variable?.Path, $"{nameof(this.Model)}.{nameof(model.Variable)}");
|
|
ValueExpression valueExpression = Throw.IfNull(this.Model.Value, $"{nameof(this.Model)}.{nameof(this.Model.Value)}");
|
|
|
|
EvaluationResult<DataValue> expressionResult = this.Evaluator.GetValue(valueExpression);
|
|
|
|
FormulaValue parsedValue;
|
|
if (this.Model.ValueType is not null)
|
|
{
|
|
VariableType targetType = new(this.Model.ValueType);
|
|
object? parsedResult = expressionResult.Value.ToObject().ConvertType(targetType);
|
|
parsedValue = parsedResult.ToFormula();
|
|
}
|
|
else
|
|
{
|
|
parsedValue = expressionResult.Value.ToFormula();
|
|
}
|
|
|
|
await this.AssignAsync(variablePath, parsedValue, context).ConfigureAwait(false);
|
|
|
|
return default;
|
|
}
|
|
}
|