11import { hbs } from "ember-cli-htmlbars" ;
2- import { withSilencedDeprecations } from "discourse/lib/deprecated" ;
32import { withPluginApi } from "discourse/lib/plugin-api" ;
43import { registerWidgetShim } from "discourse/widgets/render-glimmer" ;
54import AiBotHeaderIcon from "../discourse/components/ai-bot-header-icon" ;
65import AiCancelStreamingButton from "../discourse/components/post-menu/ai-cancel-streaming-button" ;
76import AiDebugButton from "../discourse/components/post-menu/ai-debug-button" ;
87import AiShareButton from "../discourse/components/post-menu/ai-share-button" ;
9- import {
10- isPostFromAiBot ,
11- showShareConversationModal ,
12- } from "../discourse/lib/ai-bot-helper" ;
8+ import { showShareConversationModal } from "../discourse/lib/ai-bot-helper" ;
139import { streamPostText } from "../discourse/lib/ai-streamer/progress-handlers" ;
1410
1511let enabledChatBotIds = [ ] ;
@@ -83,7 +79,7 @@ function initializePersonaDecorator(api) {
8379}
8480
8581function initializePauseButton ( api ) {
86- const transformerRegistered = api . registerValueTransformer (
82+ api . registerValueTransformer (
8783 "post-menu-buttons" ,
8884 ( { value : dag , context : { post, firstButtonKey } } ) => {
8985 if ( isGPTBot ( post . user ) ) {
@@ -94,29 +90,6 @@ function initializePauseButton(api) {
9490 }
9591 }
9692 ) ;
97-
98- const silencedKey =
99- transformerRegistered && "discourse.post-menu-widget-overrides" ;
100-
101- withSilencedDeprecations ( silencedKey , ( ) => initializePauseWidgetButton ( api ) ) ;
102- }
103-
104- function initializePauseWidgetButton ( api ) {
105- api . addPostMenuButton ( "cancel-gpt" , ( post ) => {
106- if ( isGPTBot ( post . user ) ) {
107- return {
108- icon : "pause" ,
109- action : "cancelStreaming" ,
110- title : "discourse_ai.ai_bot.cancel_streaming" ,
111- className : "btn btn-default cancel-streaming" ,
112- position : "first" ,
113- } ;
114- }
115- } ) ;
116-
117- api . attachWidgetAction ( "post" , "cancelStreaming" , function ( ) {
118- AiCancelStreamingButton . cancelStreaming ( this . model ) ;
119- } ) ;
12093}
12194
12295function initializeDebugButton ( api ) {
@@ -125,7 +98,7 @@ function initializeDebugButton(api) {
12598 return ;
12699 }
127100
128- const transformerRegistered = api . registerValueTransformer (
101+ api . registerValueTransformer (
129102 "post-menu-buttons" ,
130103 ( { value : dag , context : { post, firstButtonKey } } ) => {
131104 if ( post . topic ?. archetype === "private_message" ) {
@@ -136,38 +109,6 @@ function initializeDebugButton(api) {
136109 }
137110 }
138111 ) ;
139-
140- const silencedKey =
141- transformerRegistered && "discourse.post-menu-widget-overrides" ;
142-
143- withSilencedDeprecations ( silencedKey , ( ) => initializeDebugWidgetButton ( api ) ) ;
144- }
145-
146- function initializeDebugWidgetButton ( api ) {
147- const currentUser = api . getCurrentUser ( ) ;
148-
149- let debugAiResponse = async function ( { post } ) {
150- const modal = api . container . lookup ( "service:modal" ) ;
151- AiDebugButton . debugAiResponse ( post , modal ) ;
152- } ;
153-
154- api . addPostMenuButton ( "debugAi" , ( post ) => {
155- if ( post . topic ?. archetype !== "private_message" ) {
156- return ;
157- }
158-
159- if ( ! isPostFromAiBot ( post , currentUser ) ) {
160- return ;
161- }
162-
163- return {
164- action : debugAiResponse ,
165- icon : "info" ,
166- className : "post-action-menu__debug-ai" ,
167- title : "discourse_ai.ai_bot.debug_ai" ,
168- position : "first" ,
169- } ;
170- } ) ;
171112}
172113
173114function initializeShareButton ( api ) {
@@ -176,7 +117,7 @@ function initializeShareButton(api) {
176117 return ;
177118 }
178119
179- const transformerRegistered = api . registerValueTransformer (
120+ api . registerValueTransformer (
180121 "post-menu-buttons" ,
181122 ( { value : dag , context : { post, firstButtonKey } } ) => {
182123 if ( post . topic ?. archetype === "private_message" ) {
@@ -186,39 +127,6 @@ function initializeShareButton(api) {
186127 }
187128 }
188129 ) ;
189-
190- const silencedKey =
191- transformerRegistered && "discourse.post-menu-widget-overrides" ;
192-
193- withSilencedDeprecations ( silencedKey , ( ) => initializeShareWidgetButton ( api ) ) ;
194- }
195-
196- function initializeShareWidgetButton ( api ) {
197- const currentUser = api . getCurrentUser ( ) ;
198-
199- let shareAiResponse = async function ( { post, showFeedback } ) {
200- const modal = api . container . lookup ( "service:modal" ) ;
201- AiShareButton . shareAiResponse ( post , modal , showFeedback ) ;
202- } ;
203-
204- api . addPostMenuButton ( "share" , ( post ) => {
205- // for backwards compat so we don't break if topic is undefined
206- if ( post . topic ?. archetype !== "private_message" ) {
207- return ;
208- }
209-
210- if ( ! isPostFromAiBot ( post , currentUser ) ) {
211- return ;
212- }
213-
214- return {
215- action : shareAiResponse ,
216- icon : "far-copy" ,
217- className : "post-action-menu__share-ai" ,
218- title : "discourse_ai.ai_bot.share" ,
219- position : "first" ,
220- } ;
221- } ) ;
222130}
223131
224132function initializeShareTopicButton ( api ) {
0 commit comments