diff --git a/src/cascadia/QueryExtension/ExtensionPalette.cpp b/src/cascadia/QueryExtension/ExtensionPalette.cpp index ef303ff232c..3d49bf0a7c1 100644 --- a/src/cascadia/QueryExtension/ExtensionPalette.cpp +++ b/src/cascadia/QueryExtension/ExtensionPalette.cpp @@ -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(prompt, true, false); + const auto userMessage = winrt::make(prompt, true); std::vector userMessageVector{ userMessage }; const auto queryAttribution = _lmProvider ? _lmProvider.BrandingData().QueryAttribution() : winrt::hstring{}; const auto userGroupedMessages = winrt::make(currentLocalTime, true, winrt::single_threaded_vector(std::move(userMessageVector)), queryAttribution); @@ -200,10 +200,19 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation const auto time = _getCurrentLocalTimeHelper(); std::vector messageParts; - const auto chatMsg = winrt::make(winrt::to_hstring(response.Message()), false, false); + const auto chatMsg = winrt::make(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); @@ -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: - // - - 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(); - 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, @@ -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(); diff --git a/src/cascadia/QueryExtension/ExtensionPalette.h b/src/cascadia/QueryExtension/ExtensionPalette.h index aedc0a8179b..0b4abee122f 100644 --- a/src/cascadia/QueryExtension/ExtensionPalette.h +++ b/src/cascadia/QueryExtension/ExtensionPalette.h @@ -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); @@ -63,10 +62,9 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation struct ChatMessage : ChatMessageT { - 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; }; @@ -74,7 +72,6 @@ namespace winrt::Microsoft::Terminal::Query::Extension::implementation private: bool _isQuery; - bool _isCode; winrt::hstring _messageContent; Windows::UI::Xaml::Controls::RichTextBlock _richBlock; }; diff --git a/src/cascadia/QueryExtension/ExtensionPalette.idl b/src/cascadia/QueryExtension/ExtensionPalette.idl index d0f25f10742..61eda5f1131 100644 --- a/src/cascadia/QueryExtension/ExtensionPalette.idl +++ b/src/cascadia/QueryExtension/ExtensionPalette.idl @@ -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 RunCommandClicked; } diff --git a/src/cascadia/QueryExtension/ExtensionPalette.xaml b/src/cascadia/QueryExtension/ExtensionPalette.xaml index d256ff6336a..1cf33725200 100644 --- a/src/cascadia/QueryExtension/ExtensionPalette.xaml +++ b/src/cascadia/QueryExtension/ExtensionPalette.xaml @@ -240,7 +240,6 @@ VerticalAlignment="Bottom" HorizontalContentAlignment="Stretch" IsItemClickEnabled="True" - ItemClick="_listItemClicked" ItemTemplateSelector="{StaticResource ChatMessageTemplateSelector}" ItemsSource="{Binding Source={StaticResource MessagesCollectionViewSource}}" SelectionMode="None">