@@ -58,6 +58,7 @@ import {
5858import { ChatHistory , ChatHistoryList } from './features/history'
5959import { pairProgrammingModeOff , pairProgrammingModeOn , programmerModeCard } from './texts/pairProgramming'
6060import { getModelSelectionChatItem } from './texts/modelSelection'
61+ import { paidTierSuccessCard , freeTierLimitReachedCard , upgradeQButton } from './texts/paidTier'
6162
6263export interface InboundChatApi {
6364 addChatResponse ( params : ChatResult , tabId : string , isPartialResult : boolean ) : void
@@ -488,6 +489,14 @@ export const createMynahUi = (
488489 }
489490 messager . onPromptInputOptionChange ( { tabId, optionsValues } )
490491 } ,
492+ onPromptInputButtonClick : ( tabId , buttonId , eventId ) => {
493+ const payload : ButtonClickParams = {
494+ tabId,
495+ messageId : 'not-a-message' ,
496+ buttonId : buttonId ,
497+ }
498+ messager . onPromptInputButtonClick ( payload )
499+ } ,
491500 onMessageDismiss : ( tabId , messageId ) => {
492501 if ( messageId === programmerModeCard . messageId ) {
493502 programmingModeCardActive = false
@@ -836,7 +845,42 @@ export const createMynahUi = (
836845 } )
837846 }
838847
848+ /**
849+ * Adjusts the UI when the user changes to/from free-tier/paid-tier.
850+ * Shows a message if the user reaches free-tier limit.
851+ * Shows a message if the user just upgraded to paid-tier.
852+ */
853+ const onPaidTierModeChange = (
854+ tabId : string ,
855+ mode : 'paidtier' | 'paidtier-success' | 'freetier' | 'freetier-limit'
856+ ) => {
857+ if ( ! [ 'paidtier' , 'paidtier-success' , 'freetier' , 'freetier-limit' ] . includes ( mode ) ) {
858+ return // invalid mode
859+ }
860+
861+ tabId = tabId !== '' ? tabId : getOrCreateTabId ( ) !
862+
863+ // Detect if the tab is already showing the "Upgrade Q" calls-to-action.
864+ const didShowLimitReached = mynahUi . getTabData ( tabId ) ?. getStore ( ) ?. promptInputButtons ?. [ 0 ] === upgradeQButton
865+ if ( mode === 'freetier-limit' && ! didShowLimitReached ) {
866+ mynahUi . addChatItem ( tabId , freeTierLimitReachedCard )
867+ } else if ( mode === 'paidtier-success' ) {
868+ mynahUi . addChatItem ( tabId , paidTierSuccessCard )
869+ }
870+
871+ mynahUi . updateStore ( tabId , {
872+ promptInputButtons : mode === 'freetier-limit' ? [ upgradeQButton ] : [ ] ,
873+ promptInputDisabledState : mode === 'freetier-limit' ,
874+ } )
875+ }
876+
839877 const updateChat = ( params : ChatUpdateParams ) => {
878+ // HACK: Special field sent by `agenticChatController.ts:setPaidTierMode()`.
879+ if ( ( params as any ) . paidTierMode ) {
880+ onPaidTierModeChange ( params . tabId , ( params as any ) . paidTierMode as any )
881+ return
882+ }
883+
840884 const isChatLoading = params . state ?. inProgress
841885 mynahUi . updateStore ( params . tabId , {
842886 loadingChat : isChatLoading ,
0 commit comments