XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEWorkflow

【WinUI】XFE基于windows的工作流

公开
关注 0 Fork 0 Star 0
UTF-8
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;

namespace XFEWorkflow.Plugins.AgentBrowser;

public sealed class AgentOptions
{
    public string Endpoint { get; set; } = "https://api.deepseek.com/";
    public string Model { get; set; } = "deepseek-v4-flash";
    public string Credential { get; set; } = AgentApiSettings.PrivateCredential;
    [JsonIgnore] public string SkillDirectory { get; set; } = BrowserSkill.DefaultDirectory;
    [JsonIgnore] public string NodeExecutable { get; set; } = Path.Combine(BrowserSkill.PackageDirectory, "Runtime", "node.exe");
    public bool Vision { get; set; }
    public bool Thinking { get; set; }
    public int MaximumSteps { get; set; }
    public List<string> MigratedContextKeys { get; set; } = [];
    public string MigrationContextKey { get; set; } = "";
    public Uri CompletionUri()
    {
        if (!Uri.TryCreate(Endpoint.Trim(), UriKind.Absolute, out var uri) || uri.Scheme is not ("http" or "https") || uri.UserInfo.Length > 0 || uri.Query.Length > 0 || uri.Fragment.Length > 0)
            throw new ArgumentException("AI 服务地址必须是 HTTP(S) 地址,不能包含账号、查询或片段");
        if (string.IsNullOrWhiteSpace(Model)) throw new ArgumentException("请先在 Agent 设置中填写模型名称");
        if (MaximumSteps < 0) throw new ArgumentException("最大工具轮数不能为负数;0 表示不限");
        var value = uri.AbsoluteUri.TrimEnd('/');
        return new(value.EndsWith("/chat/completions", StringComparison.Ordinal) ? value : value + "/chat/completions");
    }
}

public sealed record AgentEvent(string Kind, string Id, string Text, string? Name = null, string? ImagePath = null, string? MessageId = null);
public sealed record AgentToolResult(string Text, string? ImagePath = null);

public interface IAgentBrowserRuntime : IAsyncDisposable
{
    Task<JsonObject> StartAsync(BrowserSkill skill, CancellationToken ct);
    Task<AgentToolResult> ExecuteAsync(string tool, JsonObject arguments, CancellationToken ct);
}