Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Github Copilot to be used with Terminal Chat #18014

Merged
merged 106 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
b44216b
got an idl
PankajBhojwani Jun 6, 2024
e78e4d0
works
PankajBhojwani Jun 7, 2024
ac83d76
allow
PankajBhojwani Jun 7, 2024
4b944e9
conflict
PankajBhojwani Jun 7, 2024
ef406ee
use id here too
PankajBhojwani Jun 7, 2024
4fb4ca4
have terminal page initialize the llmprovider
PankajBhojwani Jun 7, 2024
e5afbae
format
PankajBhojwani Jun 7, 2024
32b3d68
consts
PankajBhojwani Jun 8, 2024
1700a92
works on palette side
PankajBhojwani Jun 11, 2024
08dd951
open ai in settings, llmprovider enum
PankajBhojwani Jun 13, 2024
1934b30
aiconfig struct
PankajBhojwani Jun 20, 2024
96a489a
move more things to ai info
PankajBhojwani Jun 21, 2024
6052a8d
works on palette side
PankajBhojwani Jun 11, 2024
4add2c9
open ai in settings, llmprovider enum
PankajBhojwani Jun 13, 2024
c3885ff
aiconfig struct
PankajBhojwani Jun 20, 2024
646c28b
move more things to ai info
PankajBhojwani Jun 21, 2024
fb7ff3c
github copilot impl works
PankajBhojwani Jun 28, 2024
8bf23bc
handle uri action
PankajBhojwani Jul 2, 2024
65c2587
rough edges, but roundtrip works
PankajBhojwani Jul 4, 2024
73eb2af
mark a couple todos
PankajBhojwani Jul 8, 2024
8e560e2
active provider buttons
PankajBhojwani Jul 9, 2024
f9e9326
rename to lmprovider
PankajBhojwani Jul 9, 2024
4133239
spelling conflict
PankajBhojwani Jul 9, 2024
e545ca2
conflicts
PankajBhojwani Jul 9, 2024
dfad8d9
spell
PankajBhojwani Jul 9, 2024
5139b88
array of accepted models
PankajBhojwani Jul 9, 2024
dfbdc75
cleanup this comment
PankajBhojwani Jul 9, 2024
2819606
placeholder, remove device flow code
PankajBhojwani Jul 11, 2024
19e73db
refresh tokens works
PankajBhojwani Jul 11, 2024
82125f9
error dialog for failed auth
PankajBhojwani Jul 11, 2024
405276e
mark todos
PankajBhojwani Jul 12, 2024
1f305ab
first round of comments
PankajBhojwani Jul 15, 2024
242b964
combine setter/getter
PankajBhojwani Jul 15, 2024
0094db0
Merge branch 'dev/pabhoj/llm_provider_interface' of https://github.co…
PankajBhojwani Jul 15, 2024
3560339
conflicts
PankajBhojwani Jul 15, 2024
86f4966
active button and bool
PankajBhojwani Jul 15, 2024
6479c47
auth related functions
PankajBhojwani Jul 16, 2024
2cfe23d
github auth function implementation, static event on settings side
PankajBhojwani Jul 16, 2024
eb1c805
nope just wrong thread
PankajBhojwani Jul 16, 2024
d392aab
dispatcher
PankajBhojwani Jul 17, 2024
8faf8b4
domain check
PankajBhojwani Jul 17, 2024
dd6b46d
hot reload works now
PankajBhojwani Jul 18, 2024
4f81775
conflict and updates to openAI provider
PankajBhojwani Jul 18, 2024
46ab508
password box
PankajBhojwani Jul 18, 2024
ac1b4a3
logic for updating providers based on settings changes
PankajBhojwani Jul 18, 2024
90642d0
conflict, updates with new interface
PankajBhojwani Jul 19, 2024
fc8e36d
use static strings for strings used more than once
PankajBhojwani Jul 19, 2024
e8fc46d
conflict, updates with new interface
PankajBhojwani Jul 19, 2024
6ef93f4
Merge branch 'dev/pabhoj/featurellm_capi' of https://microsoft.visual…
PankajBhojwani Jul 19, 2024
cddbd75
random state string, manifest for canary
PankajBhojwani Jul 19, 2024
fdee6c2
Merge branch 'feature/llm' of https://github.com/microsoft/terminal i…
PankajBhojwani Jul 19, 2024
fff97a4
merge
PankajBhojwani Jul 20, 2024
4cd6e82
merge
PankajBhojwani Jul 20, 2024
c86dfdd
auth values
PankajBhojwani Jul 22, 2024
45ce94d
don't use &
PankajBhojwani Jul 22, 2024
c89a306
update with base changes
PankajBhojwani Jul 22, 2024
63d6c63
update
PankajBhojwani Jul 22, 2024
de88842
conflict
PankajBhojwani Sep 9, 2024
edf08a9
missed this
PankajBhojwani Sep 9, 2024
830e655
newline...
PankajBhojwani Sep 9, 2024
ef9fb02
conflict
PankajBhojwani Sep 9, 2024
2adbe0e
update settings ui
PankajBhojwani Sep 9, 2024
c094900
use correct links
PankajBhojwani Sep 9, 2024
15f9d8e
checkbox
PankajBhojwani Sep 10, 2024
234ebd0
allow LMProviders to modify parts of the UI, github copilot provider …
PankajBhojwani Sep 11, 2024
1cd7f33
username metadata
PankajBhojwani Sep 11, 2024
ec294e5
GitHub
PankajBhojwani Sep 11, 2024
c1e74c9
sequencing
PankajBhojwani Sep 13, 2024
14949c1
branding data struct
PankajBhojwani Oct 8, 2024
32caeba
github telemetry
PankajBhojwani Oct 8, 2024
c504a08
why was this here
PankajBhojwani Oct 8, 2024
a70339c
launch setting issue
PankajBhojwani Oct 8, 2024
bfb4295
H in github
PankajBhojwani Oct 10, 2024
6fa4cc7
feature flag for capi
PankajBhojwani Oct 11, 2024
93f065f
add feature id
PankajBhojwani Oct 11, 2024
5665097
display error message on failed auth
PankajBhojwani Oct 15, 2024
ad5dba5
comments
PankajBhojwani Oct 15, 2024
5931ecd
better refresh
PankajBhojwani Oct 15, 2024
b376da4
api spell
PankajBhojwani Oct 15, 2024
ba81e16
sku isolation
PankajBhojwani Oct 16, 2024
d0a9e05
deduplicate a bunch
PankajBhojwani Oct 16, 2024
5ea6f62
move secret to its own file
PankajBhojwani Oct 17, 2024
16d3035
conflict
PankajBhojwani Oct 17, 2024
8dc2dfb
conflict
PankajBhojwani Oct 17, 2024
e973ced
open ai desc fixes
PankajBhojwani Oct 17, 2024
ea79fb9
caching logic and other comments
PankajBhojwani Oct 22, 2024
9031427
std move
PankajBhojwani Oct 22, 2024
3ee948d
comment
PankajBhojwani Oct 22, 2024
b2e38af
nits
PankajBhojwani Oct 23, 2024
ce4a1de
zwstring_view
PankajBhojwani Oct 23, 2024
95e721c
conflict
PankajBhojwani Oct 23, 2024
596d17e
store the last response to bubble in case of errors
PankajBhojwani Oct 23, 2024
2fc21ef
rename to attribution, getters only
PankajBhojwani Oct 24, 2024
bcfc1d4
branding too
PankajBhojwani Oct 24, 2024
2bb6d7f
some fixes
PankajBhojwani Oct 24, 2024
6a694ae
auth values as string
PankajBhojwani Oct 24, 2024
3ffaafc
use winrt::hstring
PankajBhojwani Oct 24, 2024
d0847a1
wait these didn't save
PankajBhojwani Oct 24, 2024
7234b9d
strong
PankajBhojwani Oct 24, 2024
b969baf
safer coroutines
PankajBhojwani Oct 24, 2024
e0d7172
turn on feature for new build
PankajBhojwani Oct 25, 2024
bd34e90
iasyncaction instead
PankajBhojwani Oct 25, 2024
df9a233
use a grid because stackpanel is the worst
PankajBhojwani Oct 25, 2024
a6deddf
Merge branch 'feature/llm' of https://github.com/microsoft/terminal i…
PankajBhojwani Oct 28, 2024
0564bc5
conflict
PankajBhojwani Oct 28, 2024
9a30666
unpackaged check
PankajBhojwani Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cascadia/QueryExtension/AzureLLMProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
responseMessageObject.Insert(contentString, WDJ::JsonValue::CreateStringValue(message));
_jsonMessages.Append(responseMessageObject);

co_return winrt::make<AzureResponse>(message, errorType);
co_return winrt::make<AzureResponse>(message, errorType, L"");
}

bool AzureLLMProvider::_verifyModelIsValidHelper(const WDJ::JsonObject jsonResponse)
Expand Down
32 changes: 21 additions & 11 deletions src/cascadia/QueryExtension/AzureLLMProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
{
AzureBranding() = default;

WINRT_PROPERTY(winrt::hstring, Name, L"Azure OpenAI");
WINRT_PROPERTY(winrt::hstring, HeaderIconPath);
WINRT_PROPERTY(winrt::hstring, HeaderText);
WINRT_PROPERTY(winrt::hstring, SubheaderText);
WINRT_PROPERTY(winrt::hstring, BadgeIconPath);
WINRT_PROPERTY(winrt::hstring, ResponseMetaData);
WINRT_PROPERTY(winrt::hstring, QueryMetaData);
winrt::hstring Name() { return _name; };
winrt::hstring HeaderIconPath() { return _headerIconPath; };
winrt::hstring HeaderText() { return _headerText; };
winrt::hstring SubheaderText() { return _subheaderText; };
winrt::hstring BadgeIconPath() { return _badgeIconPath; };
winrt::hstring QueryAttribution() { return _queryAttribution; };

private:
winrt::hstring _name{ L"Azure OpenAI" };
winrt::hstring _headerIconPath;
winrt::hstring _headerText;
winrt::hstring _subheaderText;
winrt::hstring _badgeIconPath;
winrt::hstring _queryAttribution;
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
};

struct AzureLLMProvider : AzureLLMProviderT<AzureLLMProvider>
Expand All @@ -28,17 +35,18 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
void SetSystemPrompt(const winrt::hstring& systemPrompt);
void SetContext(Extension::IContext context);

IBrandingData BrandingData() { return _brandingData; };

winrt::Windows::Foundation::IAsyncOperation<Extension::IResponse> GetResponseAsync(const winrt::hstring& userPrompt);

void SetAuthentication(const Windows::Foundation::Collections::ValueSet& authValues);
TYPED_EVENT(AuthChanged, winrt::Microsoft::Terminal::Query::Extension::ILMProvider, winrt::Microsoft::Terminal::Query::Extension::IAuthenticationResult);

WINRT_PROPERTY(IBrandingData, BrandingData, winrt::make<AzureBranding>());

private:
winrt::hstring _azureEndpoint;
winrt::hstring _azureKey;
winrt::Windows::Web::Http::HttpClient _httpClient{ nullptr };
IBrandingData _brandingData{ winrt::make<AzureBranding>() };

Extension::IContext _context;

Expand All @@ -49,12 +57,14 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation

struct AzureResponse : public winrt::implements<AzureResponse, winrt::Microsoft::Terminal::Query::Extension::IResponse>
{
AzureResponse(const winrt::hstring& message, const winrt::Microsoft::Terminal::Query::Extension::ErrorTypes errorType) :
AzureResponse(const winrt::hstring& message, const winrt::Microsoft::Terminal::Query::Extension::ErrorTypes errorType, const winrt::hstring& responseAttribution) :
Message{ message },
ErrorType{ errorType } {}
ErrorType{ errorType },
ResponseAttribution{ responseAttribution } {}

til::property<winrt::hstring> Message;
til::property<winrt::Microsoft::Terminal::Query::Extension::ErrorTypes> ErrorType;
til::property<winrt::hstring> ResponseAttribution;
};
}

Expand Down
18 changes: 9 additions & 9 deletions src/cascadia/QueryExtension/ExtensionPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
{
const auto userMessage = winrt::make<ChatMessage>(prompt, true, false);
std::vector<IInspectable> userMessageVector{ userMessage };
const auto queryMetaData = _lmProvider ? _lmProvider.BrandingData().QueryMetaData() : L"";
const auto userGroupedMessages = winrt::make<GroupedChatMessages>(currentLocalTime, true, _ProfileName, winrt::single_threaded_vector(std::move(userMessageVector)), queryMetaData);
const auto queryAttribution = _lmProvider ? _lmProvider.BrandingData().QueryAttribution() : L"";
const auto userGroupedMessages = winrt::make<GroupedChatMessages>(currentLocalTime, true, winrt::single_threaded_vector(std::move(userMessageVector)), queryAttribution);
_messages.Append(userGroupedMessages);
_queryBox().Text(L"");

Expand Down Expand Up @@ -152,7 +152,7 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
}
else
{
result = winrt::make<SystemResponse>(RS_(L"CouldNotFindKeyErrorMessage"), ErrorTypes::InvalidAuth);
result = winrt::make<SystemResponse>(RS_(L"CouldNotFindKeyErrorMessage"), ErrorTypes::InvalidAuth, L"");
}

// Switch back to the foreground thread because we are changing the UI now
Expand All @@ -164,7 +164,7 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
IsProgressRingActive(false);

// Append the result to our list, clear the query box
_splitResponseAndAddToChatHelper(result.Message(), result.ErrorType());
_splitResponseAndAddToChatHelper(result);
}

co_return;
Expand All @@ -184,12 +184,12 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
return winrt::to_hstring(time_str);
}

void ExtensionPalette::_splitResponseAndAddToChatHelper(const winrt::hstring& response, const ErrorTypes errorType)
void ExtensionPalette::_splitResponseAndAddToChatHelper(const IResponse response)
{
// this function is dependent on the AI response separating code blocks with
// newlines and "```". OpenAI seems to naturally conform to this, though
// we could probably engineer the prompt to specify this if we need to.
std::wstringstream ss(response.c_str());
std::wstringstream ss(response.Message().c_str());
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
std::wstring line;
std::wstring codeBlock;
bool inCodeBlock = false;
Expand Down Expand Up @@ -230,17 +230,17 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
}

const auto brandingData = _lmProvider.BrandingData();
const auto responseMetaData = _lmProvider ? brandingData.ResponseMetaData() : L"";
const auto responseAttribution = response.ResponseAttribution().empty() ? _ProfileName : response.ResponseAttribution();
const auto badgeUriPath = _lmProvider ? brandingData.BadgeIconPath() : L"";
const auto responseGroupedMessages = winrt::make<GroupedChatMessages>(time, false, _ProfileName, winrt::single_threaded_vector(std::move(messageParts)), responseMetaData, badgeUriPath);
const auto responseGroupedMessages = winrt::make<GroupedChatMessages>(time, false, winrt::single_threaded_vector(std::move(messageParts)), responseAttribution, badgeUriPath);
_messages.Append(responseGroupedMessages);

const auto lmProviderName = _lmProvider ? _lmProvider.BrandingData().Name() : L"";
TraceLoggingWrite(
g_hQueryExtensionProvider,
"AIResponseReceived",
TraceLoggingDescription("Event emitted when the user receives a response to their query"),
TraceLoggingBoolean(errorType == ErrorTypes::None, "ResponseReceivedFromAI", "True if the response came from the AI, false if the response was generated in Terminal or was a server error"),
TraceLoggingBoolean(response.ErrorType() == ErrorTypes::None, "ResponseReceivedFromAI", "True if the response came from the AI, false if the response was generated in Terminal or was a server error"),
TraceLoggingWideString(lmProviderName.c_str(), "LMProviderName", "The name of the connected service provider, if present"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_CRITICAL_DATA),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
Expand Down
16 changes: 8 additions & 8 deletions src/cascadia/QueryExtension/ExtensionPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
winrt::fire_and_forget _getSuggestions(const winrt::hstring& prompt, const winrt::hstring& currentLocalTime);

winrt::hstring _getCurrentLocalTimeHelper();
void _splitResponseAndAddToChatHelper(const winrt::hstring& response, const winrt::Microsoft::Terminal::Query::Extension::ErrorTypes errorType);
void _splitResponseAndAddToChatHelper(const winrt::Microsoft::Terminal::Query::Extension::IResponse response);
void _setFocusAndPlaceholderTextHelper();

void _clearAndInitializeMessages(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);
Expand Down Expand Up @@ -79,16 +79,14 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
{
GroupedChatMessages(winrt::hstring key,
bool isQuery,
winrt::hstring profileName,
const Windows::Foundation::Collections::IVector<Windows::Foundation::IInspectable>& messages,
winrt::hstring metaData = L"",
winrt::hstring attribution = L"",
winrt::hstring badgeImagePath = L"")
{
_Key = key;
_isQuery = isQuery;
_ProfileName = profileName;
_messages = messages;
_MetaData = metaData.empty() ? _ProfileName : metaData;
_Attribution = attribution;

if (!badgeImagePath.empty())
{
Expand Down Expand Up @@ -152,7 +150,7 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
bool IsQuery() const { return _isQuery; };
WINRT_PROPERTY(winrt::hstring, Key);
WINRT_PROPERTY(winrt::hstring, ProfileName);
WINRT_PROPERTY(winrt::hstring, MetaData);
WINRT_PROPERTY(winrt::hstring, Attribution);
WINRT_PROPERTY(winrt::Windows::UI::Xaml::Media::Imaging::BitmapImage, BadgeBitmapImage, nullptr);

private:
Expand All @@ -170,12 +168,14 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation

struct SystemResponse : public winrt::implements<SystemResponse, winrt::Microsoft::Terminal::Query::Extension::IResponse>
{
SystemResponse(const winrt::hstring& message, const winrt::Microsoft::Terminal::Query::Extension::ErrorTypes errorType) :
SystemResponse(const winrt::hstring& message, const winrt::Microsoft::Terminal::Query::Extension::ErrorTypes errorType, const winrt::hstring& responseAttribution) :
Message{ message },
ErrorType{ errorType } {}
ErrorType{ errorType },
ResponseAttribution{ responseAttribution } {}

til::property<winrt::hstring> Message;
til::property<winrt::Microsoft::Terminal::Query::Extension::ErrorTypes> ErrorType;
til::property<winrt::hstring> ResponseAttribution;
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/QueryExtension/ExtensionPalette.idl
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace Microsoft.Terminal.Query.Extension

runtimeclass GroupedChatMessages : Windows.Foundation.Collections.IVector<IInspectable>
{
GroupedChatMessages(String key, Boolean isQuery, String profileName, Windows.Foundation.Collections.IVector<IInspectable> messages, String MetaData, String badgeImagePath);
GroupedChatMessages(String key, Boolean isQuery, Windows.Foundation.Collections.IVector<IInspectable> messages, String Attribution, String badgeImagePath);
String Key;
String MetaData;
String Attribution;
Windows.UI.Xaml.Media.Imaging.BitmapImage BadgeBitmapImage;
Boolean IsQuery { get; };
}
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/QueryExtension/ExtensionPalette.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
Spacing="4">
<TextBlock FontFamily="Segoe UI"
FontSize="12">
<Run Text="{x:Bind MetaData}" />
<Run Text="{x:Bind Attribution}" />
</TextBlock>
<TextBlock FontFamily="Segoe UI"
FontSize="12"
Expand All @@ -189,7 +189,7 @@
<mux:ImageIcon Source="{x:Bind BadgeBitmapImage}"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Highly amazed this worked. It should have failed because WUX and MUX image sources are different (????)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish I had an answer for this haha

<TextBlock FontFamily="Segoe UI"
FontSize="12">
<Run Text="{x:Bind MetaData}" />
<Run Text="{x:Bind Attribution}" />
</TextBlock>
<TextBlock FontFamily="Segoe UI"
FontSize="12"
Expand Down
15 changes: 7 additions & 8 deletions src/cascadia/QueryExtension/GithubCopilotLLMProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
{
GithubCopilotBranding::GithubCopilotBranding()
{
_HeaderIconPath = headerIconPath;
_HeaderText = RS_(L"GithubCopilot_HeaderText");
_SubheaderText = RS_(L"GithubCopilot_SubheaderText");
_BadgeIconPath = badgeIconPath;
_ResponseMetaData = RS_(L"GithubCopilot_ResponseMetaData");
_headerIconPath = headerIconPath;
_headerText = RS_(L"GithubCopilot_HeaderText");
_subheaderText = RS_(L"GithubCopilot_SubheaderText");
_badgeIconPath = badgeIconPath;
}

void GithubCopilotLLMProvider::SetAuthentication(const Windows::Foundation::Collections::ValueSet& authValues)
Expand Down Expand Up @@ -129,8 +128,8 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
const auto copilotEndpoint = viewerObject.GetNamedObject(copilotEndpointsKey).GetNamedString(apiKey);

_endpointUri = copilotEndpoint + chatCompletionSuffix;
const auto brandingData{ get_self<GithubCopilotBranding>(_BrandingData) };
brandingData->QueryMetaData(userName);
const auto brandingData{ get_self<GithubCopilotBranding>(_brandingData) };
brandingData->QueryAttribution(userName);
break;
}
CATCH_LOG();
Expand Down Expand Up @@ -300,7 +299,7 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
responseMessageObject.Insert(contentKey, WDJ::JsonValue::CreateStringValue(message));
_jsonMessages.Append(responseMessageObject);

co_return winrt::make<GithubCopilotResponse>(message, errorType);
co_return winrt::make<GithubCopilotResponse>(message, errorType, RS_(L"GithubCopilot_ResponseMetaData"));
}

void GithubCopilotLLMProvider::_refreshAuthTokens()
Expand Down
31 changes: 20 additions & 11 deletions src/cascadia/QueryExtension/GithubCopilotLLMProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
{
GithubCopilotBranding();

WINRT_PROPERTY(winrt::hstring, Name, L"GitHub Copilot");
WINRT_PROPERTY(winrt::hstring, HeaderIconPath);
WINRT_PROPERTY(winrt::hstring, HeaderText);
WINRT_PROPERTY(winrt::hstring, SubheaderText);
WINRT_PROPERTY(winrt::hstring, BadgeIconPath);
WINRT_PROPERTY(winrt::hstring, ResponseMetaData);
WINRT_PROPERTY(winrt::hstring, QueryMetaData);
winrt::hstring Name() { return _name; };
winrt::hstring HeaderIconPath() { return _headerIconPath; };
winrt::hstring HeaderText() { return _headerText; };
winrt::hstring SubheaderText() { return _subheaderText; };
winrt::hstring BadgeIconPath() { return _badgeIconPath; };
WINRT_PROPERTY(winrt::hstring, QueryAttribution);

private:
winrt::hstring _name{ L"GitHub Copilot" };
winrt::hstring _headerIconPath;
winrt::hstring _headerText;
winrt::hstring _subheaderText;
winrt::hstring _badgeIconPath;
};

struct GithubCopilotAuthenticationResult : public winrt::implements<GithubCopilotAuthenticationResult, winrt::Microsoft::Terminal::Query::Extension::IAuthenticationResult>
Expand All @@ -38,18 +44,19 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
void SetSystemPrompt(const winrt::hstring& systemPrompt);
void SetContext(const Extension::IContext context);

IBrandingData BrandingData() { return _brandingData; };

winrt::Windows::Foundation::IAsyncOperation<Extension::IResponse> GetResponseAsync(const winrt::hstring& userPrompt);

void SetAuthentication(const Windows::Foundation::Collections::ValueSet& authValues);
TYPED_EVENT(AuthChanged, winrt::Microsoft::Terminal::Query::Extension::ILMProvider, winrt::Microsoft::Terminal::Query::Extension::IAuthenticationResult);

WINRT_PROPERTY(IBrandingData, BrandingData, winrt::make<GithubCopilotBranding>());

private:
winrt::hstring _authToken;
winrt::hstring _refreshToken;
winrt::hstring _endpointUri;
winrt::Windows::Web::Http::HttpClient _httpClient{ nullptr };
IBrandingData _brandingData{ winrt::make<GithubCopilotBranding>() };
winrt::hstring _lastResponse;

Extension::IContext _context;
Expand All @@ -64,12 +71,14 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation

struct GithubCopilotResponse : public winrt::implements<GithubCopilotResponse, winrt::Microsoft::Terminal::Query::Extension::IResponse>
{
GithubCopilotResponse(const winrt::hstring& message, const winrt::Microsoft::Terminal::Query::Extension::ErrorTypes errorType) :
GithubCopilotResponse(const winrt::hstring& message, const winrt::Microsoft::Terminal::Query::Extension::ErrorTypes errorType, const winrt::hstring& responseAttribution) :
Message{ message },
ErrorType{ errorType } {}
ErrorType{ errorType },
ResponseAttribution{ responseAttribution } {}

til::property<winrt::hstring> Message;
til::property<winrt::Microsoft::Terminal::Query::Extension::ErrorTypes> ErrorType;
til::property<winrt::hstring> ResponseAttribution;
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/QueryExtension/ILMProvider.idl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ namespace Microsoft.Terminal.Query.Extension
String HeaderText { get; };
String SubheaderText { get; };
String BadgeIconPath { get; };
String ResponseMetaData { get; };
String QueryMetaData { get; };
String QueryAttribution { get; };
};

interface IAuthenticationResult
Expand Down Expand Up @@ -50,6 +49,7 @@ namespace Microsoft.Terminal.Query.Extension
{
String Message { get; };
ErrorTypes ErrorType { get; };
String ResponseAttribution { get; };
};

interface IContext
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/QueryExtension/OpenAILLMProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
responseMessageObject.Insert(L"content", WDJ::JsonValue::CreateStringValue(message));
_jsonMessages.Append(responseMessageObject);

co_return winrt::make<OpenAIResponse>(message, errorType);
co_return winrt::make<OpenAIResponse>(message, errorType, L"");
}
}
Loading
Loading