Repository: microsoft/terminal
File: src/cascadia/TerminalSettingsModel/AIConfig.cpp (C++)

Code before:
static constexpr wil::zwstring_view PasswordVaultResourceName = L"TerminalAI";
static constexpr wil::zwstring_view PasswordVaultAIKey = L"TerminalAIKey";
static constexpr wil::zwstring_view PasswordVaultAIEndpoint = L"TerminalAIEndpoint";
static constexpr wil::zwstring_view PasswordVaultOpenAIKey = L"TerminalOpenAIKey";
static constexpr wil::zwstring_view PasswordVaultGithubCopilotAuthToken = L"TerminalGithubCopilotAuthToken";
static constexpr wil::zwstring_view PasswordVaultGithubCopilotRefreshToken = L"TerminalGithubCopilotRefreshToken";

// When new LM providers are added here, make sure you also update the admx/adml!
static constexpr wil::zwstring_view AzureOpenAIPolicyKey = L"AzureOpenAI";
static constexpr wil::zwstring_view OpenAIPolicyKey = L"OpenAI";
static constexpr wil::zwstring_view GitHubCopilotPolicyKey = L"GitHubCopilot";

winrt::Microsoft::Terminal::Settings::Model::EnabledLMProviders AIConfig::AllowedLMProviders() noexcept
{
    Model::EnabledLMProviders enabledLMProviders{ Model::EnabledLMProviders::All };
    // get our allowed list of LM providers from the registry
    for (const auto key : { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER })
    {
        wchar_t buffer[512]; // "640K ought to be enough for anyone"
        DWORD bufferSize = sizeof(buffer);
        if (RegGetValueW(key, LR"(Software\Policies\Microsoft\Windows Terminal)", L"EnabledLMProviders", RRF_RT_REG_MULTI_SZ, nullptr, buffer, &bufferSize) == 0)
        {
            WI_ClearAllFlags(enabledLMProviders, Model::EnabledLMProviders::All);
            for (auto p = buffer; *p;)
            {
                const auto len = wcslen(p);
                if (wcscmp(p, AzureOpenAIPolicyKey.c_str()) == 0)
                {
                    WI_SetFlag(enabledLMProviders, Model::EnabledLMProviders::AzureOpenAI);
                }
                else if (wcscmp(p, OpenAIPolicyKey.c_str()) == 0)
                {
                    WI_SetFlag(enabledLMProviders, Model::EnabledLMProviders::OpenAI);
                }
                else if (wcscmp(p, GitHubCopilotPolicyKey.c_str()) == 0)
                {
                    WI_SetFlag(enabledLMProviders, Model::EnabledLMProviders::GithubCopilot);
                }
                p += len + 1;
            }
            break;
        }
    }
    return enabledLMProviders;
}

winrt::com_ptr<AIConfig> AIConfig::CopyAIConfig(const AIConfig* source)
{
    auto aiConfig{ winrt::make_self<AIConfig>() };

#define AI_SETTINGS_COPY(type, name, jsonKey, ...) \

Review comment (suggestion):
If you feel like it's more comfortable you can also write this:
```cpp
const std::wstring_view value{ p };

if (value == AzureOpenAIPolicyKey) {
} else if ... {
}

p += value.size();
```

This allows the `==` to take advantage of the known string length to skip the check immediately if the length differs.

Code after:
static constexpr wil::zwstring_view PasswordVaultResourceName = L"TerminalAI";
static constexpr wil::zwstring_view PasswordVaultAIKey = L"TerminalAIKey";
static constexpr wil::zwstring_view PasswordVaultAIEndpoint = L"TerminalAIEndpoint";
static constexpr wil::zwstring_view PasswordVaultOpenAIKey = L"TerminalOpenAIKey";
static constexpr wil::zwstring_view PasswordVaultGithubCopilotAuthValues = L"TerminalGithubCopilotAuthValues";

// When new LM providers are added here, make sure you also update the admx/adml!
static constexpr wil::zwstring_view AzureOpenAIPolicyKey = L"AzureOpenAI";
static constexpr wil::zwstring_view OpenAIPolicyKey = L"OpenAI";
static constexpr wil::zwstring_view GitHubCopilotPolicyKey = L"GitHubCopilot";

winrt::Microsoft::Terminal::Settings::Model::EnabledLMProviders AIConfig::AllowedLMProviders() noexcept
{
    Model::EnabledLMProviders enabledLMProviders{ Model::EnabledLMProviders::All };
    // get our allowed list of LM providers from the registry
    for (const auto key : { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER })
    {
        wchar_t buffer[512]; // "640K ought to be enough for anyone"
        DWORD bufferSize = sizeof(buffer);
        if (RegGetValueW(key, LR"(Software\Policies\Microsoft\Windows Terminal)", L"EnabledLMProviders", RRF_RT_REG_MULTI_SZ, nullptr, buffer, &bufferSize) == 0)
        {
            WI_ClearAllFlags(enabledLMProviders, Model::EnabledLMProviders::All);
            for (auto p = buffer; *p;)
            {
                const std::wstring_view value{ p };
                if (value == AzureOpenAIPolicyKey)
                {
                    WI_SetFlag(enabledLMProviders, Model::EnabledLMProviders::AzureOpenAI);
                }
                else if (value == OpenAIPolicyKey)
                {
                    WI_SetFlag(enabledLMProviders, Model::EnabledLMProviders::OpenAI);
                }
                else if (value == GitHubCopilotPolicyKey)
                {
                    WI_SetFlag(enabledLMProviders, Model::EnabledLMProviders::GithubCopilot);
                }
                p += value.size() + 1;
            }
            break;
        }
    }
    return enabledLMProviders;
}

winrt::com_ptr<AIConfig> AIConfig::CopyAIConfig(const AIConfig* source)
{
    auto aiConfig{ winrt::make_self<AIConfig>() };

#define AI_SETTINGS_COPY(type, name, jsonKey, ...) \
    aiConfig->_##name = source->_##name;