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

XFEWorkflow

【WinUI】XFE基于windows的工作流

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

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; } = "agent-browser.deepseek";
    public string SkillDirectory { get; set; } = BrowserSkill.DefaultDirectory;
    public string NodeExecutable { get; set; } = "node";
    public bool Vision { get; set; }
    public bool Thinking { get; set; }
    public int MaximumSteps { get; set; } = 32;
    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 is < 1 or > 100) throw new ArgumentException("最大工具轮数应为 1–100");
        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);
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);
}