基于WebView2实现的Win11桌面框架,利用插件自定义
chunhualin1
2026-08-14 09d4e2f1a1bc206c80d8d3287d070c70ec7fd63d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
namespace Moli.Desktop.Llm;
 
public static class LlmOpenAiUrls
{
    public const string ChatCompletionsPath = "/chat/completions";
    public const string ModelsPath = "/models";
 
    public static string? ResolveBaseUrl(string? baseUrl, string? endpoint)
    {
        var raw = FirstNonEmpty(baseUrl, endpoint);
        if (raw is null)
        {
            return null;
        }
 
        raw = raw.Trim().TrimEnd('/');
        if (raw.EndsWith(ChatCompletionsPath, StringComparison.OrdinalIgnoreCase))
        {
            raw = raw[..^ChatCompletionsPath.Length].TrimEnd('/');
        }
 
        return string.IsNullOrWhiteSpace(raw) ? null : raw;
    }
 
    public static string? ToChatCompletionsUrl(string? baseUrl, string? endpoint)
    {
        var resolved = ResolveBaseUrl(baseUrl, endpoint);
        return resolved is null ? null : resolved + ChatCompletionsPath;
    }
 
    public static string? ToModelsUrl(string? baseUrl, string? endpoint = null)
    {
        var resolved = ResolveBaseUrl(baseUrl, endpoint);
        return resolved is null ? null : resolved + ModelsPath;
    }
 
    public static bool IsAbsoluteHttpUrl(string? url)
        => Uri.TryCreate(url, UriKind.Absolute, out var uri) &&
           uri.Scheme is "http" or "https";
 
    public static string Host(string? url)
        => Uri.TryCreate(url, UriKind.Absolute, out var uri) ? uri.Host : "";
 
    private static string? FirstNonEmpty(string? primary, string? fallback)
    {
        if (!string.IsNullOrWhiteSpace(primary))
        {
            return primary;
        }
 
        return string.IsNullOrWhiteSpace(fallback) ? null : fallback;
    }
}
 
public static class LlmProviderModelIds
{
    public const string Prefix = "provider:";
 
    public static string Create(string providerId, string apiModel)
        => $"{Prefix}{providerId}:{apiModel}";
 
    public static bool TryParse(string? modelId, out string providerId, out string apiModel)
    {
        providerId = "";
        apiModel = "";
        if (string.IsNullOrWhiteSpace(modelId) ||
            !modelId.StartsWith(Prefix, StringComparison.OrdinalIgnoreCase))
        {
            return false;
        }
 
        var rest = modelId[Prefix.Length..];
        var separator = rest.IndexOf(':');
        if (separator <= 0 || separator >= rest.Length - 1)
        {
            return false;
        }
 
        providerId = rest[..separator];
        apiModel = rest[(separator + 1)..];
        return !string.IsNullOrWhiteSpace(providerId) && !string.IsNullOrWhiteSpace(apiModel);
    }
}
 
public static class AiChatProjectStatuses
{
    public const string NotConfigured = "not-configured";
    public const string NotConnected = "not-connected";
    public const string Ready = "ready";
}