2026-08-26 18:06:02 +08:00
|
|
|
using System.Text.Json;
|
|
|
|
|
|
|
|
|
|
namespace MAF1.Agents;
|
|
|
|
|
|
|
|
|
|
public sealed class AgentStepResult
|
|
|
|
|
{
|
|
|
|
|
public string Message { get; init; } = "";
|
|
|
|
|
public Dictionary<string, object?> Inputs { get; init; } = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
public Dictionary<string, object?> Outputs { get; init; } = new(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-28 10:43:57 +08:00
|
|
|
public static class AgentInputs
|
2026-08-26 18:06:02 +08:00
|
|
|
{
|
|
|
|
|
public static string? ReadString(IReadOnlyDictionary<string, object?> inputs, string key)
|
|
|
|
|
{
|
|
|
|
|
if (!inputs.TryGetValue(key, out object? value) || value is null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value is JsonElement el)
|
|
|
|
|
{
|
|
|
|
|
return el.ValueKind == JsonValueKind.String ? el.GetString() : el.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return value.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static List<string> ReadStringList(IReadOnlyDictionary<string, object?> inputs, string key)
|
|
|
|
|
{
|
|
|
|
|
if (!inputs.TryGetValue(key, out object? value) || value is null)
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value is JsonElement el)
|
|
|
|
|
{
|
|
|
|
|
if (el.ValueKind == JsonValueKind.Array)
|
|
|
|
|
{
|
|
|
|
|
return el.EnumerateArray()
|
|
|
|
|
.Select(item => item.ValueKind == JsonValueKind.String ? item.GetString() : item.ToString())
|
|
|
|
|
.Where(s => !string.IsNullOrWhiteSpace(s))
|
|
|
|
|
.Select(s => s!.Trim())
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (el.ValueKind == JsonValueKind.String)
|
|
|
|
|
{
|
|
|
|
|
return Split(el.GetString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value is IEnumerable<string> typed)
|
|
|
|
|
{
|
|
|
|
|
return typed.Where(v => !string.IsNullOrWhiteSpace(v)).Select(v => v.Trim()).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (value is IEnumerable<object> objects)
|
|
|
|
|
{
|
|
|
|
|
return objects.Select(o => o?.ToString())
|
|
|
|
|
.Where(s => !string.IsNullOrWhiteSpace(s))
|
|
|
|
|
.Select(s => s!.Trim())
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Split(value.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static List<string> Split(string? text)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(text))
|
|
|
|
|
{
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text.Split(['、', ',', ';', '\n'], StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries)
|
|
|
|
|
.ToList();
|
|
|
|
|
}
|
|
|
|
|
}
|