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

XFEWorkflow

【WinUI】XFE基于windows的工作流

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEWorkflow.Desktop.Sdk;

namespace XFEWorkflow.Plugins.AgentBrowser.WinUI;

public sealed partial class AgentBrowserPage
{
    private void UserChanged() => root.DispatcherQueue.TryEnqueue(() =>
    {
        if (disposed) return;
        currentUser = host.User; Post(new { type = "identity", user = currentUser });
        _ = RefreshIdentityAsync();
    });
    private async Task RefreshIdentityAsync()
    {
        var version = Interlocked.Increment(ref identityVersion);
        try
        {
            var user = await host.GetUserAsync(lifetime.Token);
            if (disposed || version != Interlocked.Read(ref identityVersion)) return;
            currentUser = user; Post(new { type = "identity", user });
        }
        catch (OperationCanceledException) { }
    }
    private string GetConfiguredKey(AgentOptions value)
    {
        string key;
        try { key = value.Credential.Length == 0 ? "" : host.GetCredential(value.Credential); }
        catch (KeyNotFoundException) { throw new ArgumentException("尚未配置 API Key,请打开右上角设置,填写 DeepSeek API Key 并保存"); }
        catch (System.Security.Cryptography.CryptographicException) { throw new ArgumentException("已保存的 API Key 无法解密,请在设置中重新填写并保存"); }
        key = AgentApiSettings.NormalizeKey(key);
        if (key.Length == 0 && !value.CompletionUri().IsLoopback) throw new ArgumentException("尚未配置 API Key,请在右上角设置中填写并保存");
        return key;
    }
}