Skip to content

Commit

Permalink
don't need these anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed Nov 19, 2024
1 parent ef9e69e commit 146d027
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 52 deletions.
58 changes: 13 additions & 45 deletions src/cascadia/QueryExtension/ExtensionPalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation

winrt::fire_and_forget ExtensionPalette::_getSuggestions(const winrt::hstring& prompt, const winrt::hstring& currentLocalTime)
{
const auto userMessage = winrt::make<ChatMessage>(prompt, true, false);
const auto userMessage = winrt::make<ChatMessage>(prompt, true);
std::vector<IInspectable> userMessageVector{ userMessage };
const auto queryAttribution = _lmProvider ? _lmProvider.BrandingData().QueryAttribution() : winrt::hstring{};
const auto userGroupedMessages = winrt::make<GroupedChatMessages>(currentLocalTime, true, winrt::single_threaded_vector(std::move(userMessageVector)), queryAttribution);
Expand Down Expand Up @@ -200,10 +200,19 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
const auto time = _getCurrentLocalTimeHelper();
std::vector<IInspectable> messageParts;

const auto chatMsg = winrt::make<ChatMessage>(winrt::to_hstring(response.Message()), false, false);
const auto chatMsg = winrt::make<ChatMessage>(winrt::to_hstring(response.Message()), false);
chatMsg.RunCommandClicked([this](auto&&, const auto commandlines) {
_InputSuggestionRequestedHandlers(*this, commandlines);
_close();

const auto lmProviderName = _lmProvider ? _lmProvider.BrandingData().Name() : winrt::hstring{};
TraceLoggingWrite(
g_hQueryExtensionProvider,
"AICodeResponseInputted",
TraceLoggingDescription("Event emitted when the user clicks on a suggestion to have it be input into their active shell"),
TraceLoggingWideString(lmProviderName.c_str(), "LMProviderName", "The name of the connected service provider, if present"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_CRITICAL_DATA),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
});
messageParts.push_back(chatMsg);

Expand Down Expand Up @@ -280,46 +289,6 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
}
}

// Method Description:
// - This event is called when the user clicks on a Chat Message. We will
// dispatch the contents of the message to the app to input into the active control.
// Arguments:
// - e: an ItemClickEventArgs who's ClickedItem() will be the message that was clicked on.
// Return Value:
// - <none>
void ExtensionPalette::_listItemClicked(const Windows::Foundation::IInspectable& /*sender*/,
const Windows::UI::Xaml::Controls::ItemClickEventArgs& e)
{
const auto selectedSuggestionItem = e.ClickedItem();
const auto selectedItemAsChatMessage = selectedSuggestionItem.as<winrt::Microsoft::Terminal::Query::Extension::ChatMessage>();
if (selectedItemAsChatMessage.IsCode())
{
auto suggestion = winrt::to_string(selectedItemAsChatMessage.MessageContent());

// the AI sometimes sends multiline code blocks
// we don't want to run any of those commands when the chat item is clicked,
// so we replace newlines with the appropriate delimiter
size_t pos = 0;
while ((pos = suggestion.find("\n", pos)) != std::string::npos)
{
const auto delimiter = (_ActiveCommandline == cmdExe || _ActiveCommandline == cmd) ? cmdCommandDelimiter : commandDelimiter;
suggestion.at(pos) = delimiter;
pos += 1; // Move past the replaced character
}
_InputSuggestionRequestedHandlers(*this, winrt::to_hstring(suggestion));
_close();

const auto lmProviderName = _lmProvider ? _lmProvider.BrandingData().Name() : winrt::hstring{};
TraceLoggingWrite(
g_hQueryExtensionProvider,
"AICodeResponseInputted",
TraceLoggingDescription("Event emitted when the user clicks on a suggestion to have it be input into their active shell"),
TraceLoggingWideString(lmProviderName.c_str(), "LMProviderName", "The name of the connected service provider, if present"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_CRITICAL_DATA),
TelemetryPrivacyDataTag(PDT_ProductAndServiceUsage));
}
}

// Method Description:
// - This event is triggered when someone clicks anywhere in the bounds of
// the window that's _not_ the query palette UI. When that happens,
Expand Down Expand Up @@ -457,10 +426,9 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation
_queryBox().Text(winrt::hstring{});
}

ChatMessage::ChatMessage(winrt::hstring content, bool isQuery, bool isCode) :
ChatMessage::ChatMessage(winrt::hstring content, bool isQuery) :
_messageContent{ content },
_isQuery{ isQuery },
_isCode{ isCode }
_isQuery{ isQuery }
{
_richBlock = Microsoft::Terminal::UI::Markdown::Builder::Convert(_messageContent, L"");
const auto resources = Application::Current().Resources();
Expand Down
5 changes: 1 addition & 4 deletions src/cascadia/QueryExtension/ExtensionPalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation

void _clearAndInitializeMessages(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);
void _exportMessagesToFile(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);
void _listItemClicked(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Controls::ItemClickEventArgs& e);
void _rootPointerPressed(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& e);
void _backdropPointerPressed(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& e);
void _lostFocusHandler(const Windows::Foundation::IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& args);
Expand All @@ -63,18 +62,16 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation

struct ChatMessage : ChatMessageT<ChatMessage>
{
ChatMessage(winrt::hstring content, bool isQuery, bool isCode);
ChatMessage(winrt::hstring content, bool isQuery);

bool IsQuery() const { return _isQuery; };
bool IsCode() const { return _isCode; };
winrt::hstring MessageContent() const { return _messageContent; };
winrt::Windows::UI::Xaml::Controls::RichTextBlock RichBlock() const { return _richBlock; };

TYPED_EVENT(RunCommandClicked, winrt::Microsoft::Terminal::Query::Extension::ChatMessage, winrt::hstring);

private:
bool _isQuery;
bool _isCode;
winrt::hstring _messageContent;
Windows::UI::Xaml::Controls::RichTextBlock _richBlock;
};
Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/QueryExtension/ExtensionPalette.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ namespace Microsoft.Terminal.Query.Extension
{
[default_interface] runtimeclass ChatMessage
{
ChatMessage(String content, Boolean isQuery, Boolean isCode);
ChatMessage(String content, Boolean isQuery);
String MessageContent { get; };
Boolean IsQuery { get; };
Boolean IsCode { get; };
Windows.UI.Xaml.Controls.RichTextBlock RichBlock { get; };
event Windows.Foundation.TypedEventHandler<ChatMessage, String> RunCommandClicked;
}
Expand Down
1 change: 0 additions & 1 deletion src/cascadia/QueryExtension/ExtensionPalette.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@
VerticalAlignment="Bottom"
HorizontalContentAlignment="Stretch"
IsItemClickEnabled="True"
ItemClick="_listItemClicked"
ItemTemplateSelector="{StaticResource ChatMessageTemplateSelector}"
ItemsSource="{Binding Source={StaticResource MessagesCollectionViewSource}}"
SelectionMode="None">
Expand Down

0 comments on commit 146d027

Please sign in to comment.