@@ -3,22 +3,19 @@ import { withSilencedDeprecations } from "discourse/lib/deprecated";
33import { withPluginApi } from "discourse/lib/plugin-api" ;
44import { registerWidgetShim } from "discourse/widgets/render-glimmer" ;
55import AiBotHeaderIcon from "../discourse/components/ai-bot-header-icon" ;
6+ import AiPersonaFlair from "../discourse/components/post/ai-persona-flair" ;
67import AiCancelStreamingButton from "../discourse/components/post-menu/ai-cancel-streaming-button" ;
78import AiDebugButton from "../discourse/components/post-menu/ai-debug-button" ;
89import AiShareButton from "../discourse/components/post-menu/ai-share-button" ;
910import {
11+ isGPTBot ,
1012 isPostFromAiBot ,
1113 showShareConversationModal ,
1214} from "../discourse/lib/ai-bot-helper" ;
1315import { streamPostText } from "../discourse/lib/ai-streamer/progress-handlers" ;
1416
15- let enabledChatBotIds = [ ] ;
1617let allowDebug = false ;
1718
18- function isGPTBot ( user ) {
19- return user && enabledChatBotIds . includes ( user . id ) ;
20- }
21-
2219function attachHeaderIcon ( api ) {
2320 api . headerIcons . add ( "ai" , AiBotHeaderIcon ) ;
2421}
@@ -57,6 +54,14 @@ function initializeAIBotReplies(api) {
5754}
5855
5956function initializePersonaDecorator ( api ) {
57+ api . renderAfterWrapperOutlet ( "post-meta-data-poster-name" , AiPersonaFlair ) ;
58+
59+ withSilencedDeprecations ( "discourse.post-stream-widget-overrides" , ( ) =>
60+ initializeWidgetPersonaDecorator ( api )
61+ ) ;
62+ }
63+
64+ function initializeWidgetPersonaDecorator ( api ) {
6065 let topicController = null ;
6166 api . decorateWidget ( `poster-name:after` , ( dec ) => {
6267 if ( ! isGPTBot ( dec . attrs . user ) ) {
@@ -98,7 +103,11 @@ function initializePauseButton(api) {
98103 const silencedKey =
99104 transformerRegistered && "discourse.post-menu-widget-overrides" ;
100105
101- withSilencedDeprecations ( silencedKey , ( ) => initializePauseWidgetButton ( api ) ) ;
106+ withSilencedDeprecations ( "discourse.post-stream-widget-overrides" , ( ) => {
107+ withSilencedDeprecations ( silencedKey , ( ) =>
108+ initializePauseWidgetButton ( api )
109+ ) ;
110+ } ) ;
102111}
103112
104113function initializePauseWidgetButton ( api ) {
@@ -251,16 +260,16 @@ export default {
251260 const user = container . lookup ( "service:current-user" ) ;
252261
253262 if ( user ?. ai_enabled_chat_bots ) {
254- enabledChatBotIds = user . ai_enabled_chat_bots . map ( ( bot ) => bot . id ) ;
255263 allowDebug = user . can_debug_ai_bot_conversations ;
256- withPluginApi ( "1.6.0" , attachHeaderIcon ) ;
257- withPluginApi ( "1.34.0" , initializeAIBotReplies ) ;
258- withPluginApi ( "1.6.0" , initializePersonaDecorator ) ;
259- withPluginApi ( "1.34.0" , ( api ) => initializeDebugButton ( api , container ) ) ;
260- withPluginApi ( "1.34.0" , ( api ) => initializeShareButton ( api , container ) ) ;
261- withPluginApi ( "1.22.0" , ( api ) =>
262- initializeShareTopicButton ( api , container )
263- ) ;
264+
265+ withPluginApi ( ( api ) => {
266+ attachHeaderIcon ( api ) ;
267+ initializeAIBotReplies ( api ) ;
268+ initializePersonaDecorator ( api ) ;
269+ initializeDebugButton ( api , container ) ;
270+ initializeShareButton ( api , container ) ;
271+ initializeShareTopicButton ( api , container ) ;
272+ } ) ;
264273 }
265274 } ,
266275} ;
0 commit comments