mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
118 lines
3.5 KiB
C#
118 lines
3.5 KiB
C#
// ------------------------------------------------------------------------------
|
|
// <auto-generated>
|
|
// This code was generated by a tool.
|
|
// Runtime Version: 18.0.0.0
|
|
//
|
|
// Changes to this file may cause incorrect behavior and will be lost if
|
|
// the code is regenerated.
|
|
// </auto-generated>
|
|
// ------------------------------------------------------------------------------
|
|
namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen
|
|
{
|
|
using Microsoft.Agents.AI.Workflows.Declarative.Extensions;
|
|
using Microsoft.Agents.ObjectModel;
|
|
using System;
|
|
|
|
/// <summary>
|
|
/// Class to produce the template output
|
|
/// </summary>
|
|
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")]
|
|
internal partial class SetTextVariableTemplate : ActionTemplate
|
|
{
|
|
/// <summary>
|
|
/// Create the template output
|
|
/// </summary>
|
|
public override string TransformText()
|
|
{
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n");
|
|
this.Write("\n/// <summary>\n/// Assigns an evaluated message template to the \"");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Variable));
|
|
this.Write("\" variable.\n/// </summary>\ninternal sealed class ");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(this.Name));
|
|
this.Write("Executor(FormulaSession session) : ActionExecutor(id: \"");
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(this.Id));
|
|
this.Write("\", session)\n{\n protected override async ValueTask<object?> ExecuteAsync(IWorkf" +
|
|
"lowContext context, CancellationToken cancellationToken)\n {");
|
|
|
|
EvaluateMessageTemplate(this.Model.Value, "textValue");
|
|
AssignVariable(this.Variable, "textValue");
|
|
this.Write("\n return default;\n }\n}");
|
|
return this.GenerationEnvironment.ToString();
|
|
}
|
|
|
|
void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false)
|
|
{
|
|
if (targetVariable is not null)
|
|
{
|
|
this.Write("\n await context.QueueStateUpdateAsync(key: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable)));
|
|
|
|
this.Write("\", value: ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable));
|
|
|
|
this.Write(", scopeName: \"");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable)));
|
|
|
|
this.Write("\").ConfigureAwait(false);");
|
|
|
|
|
|
if (!tightFormat)
|
|
{
|
|
this.Write("\n ");
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
void EvaluateMessageTemplate(TemplateLine templateLine, string variableName)
|
|
{
|
|
if (templateLine is not null)
|
|
{
|
|
this.Write("\n string ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
|
|
|
|
this.Write(" =\n await context.FormatTemplateAsync(\n \"\"\"");
|
|
|
|
|
|
FormatMessageTemplate(templateLine);
|
|
this.Write("\n \"\"\");");
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
this.Write("\n string? ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(variableName));
|
|
|
|
this.Write(" = null;");
|
|
|
|
|
|
}
|
|
}
|
|
|
|
void FormatMessageTemplate(TemplateLine line)
|
|
{
|
|
foreach (string text in line.ToTemplateString().ByLine())
|
|
{
|
|
this.Write("\n ");
|
|
|
|
this.Write(this.ToStringHelper.ToStringWithCulture(text));
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|