Skip to content

Commit 70f0c41

Browse files
committed
wip
1 parent 7c0d9cc commit 70f0c41

File tree

10 files changed

+292
-115
lines changed

10 files changed

+292
-115
lines changed

chat-client/src/client/mynahUi.ts

Lines changed: 47 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import {
5757
} from './utils'
5858
import { ChatHistory, ChatHistoryList } from './features/history'
5959
import { pairProgrammingModeOff, pairProgrammingModeOn, programmerModeCard } from './texts/pairProgramming'
60-
import { paidTierSuccessCard, freeTierLimitReachedCard, upgradeQButton } from './texts/paidTier'
60+
import { paidTierSuccessCard, freeTierLimitCard, freeTierLimitStickyCard } from './texts/paidTier'
6161

6262
export interface InboundChatApi {
6363
addChatResponse(params: ChatResult, tabId: string, isPartialResult: boolean): void
@@ -827,34 +827,65 @@ export const createMynahUi = (
827827
* Shows a message if the user reaches free-tier limit.
828828
* Shows a message if the user just upgraded to paid-tier.
829829
*/
830-
const onPaidTierModeChange = (
831-
tabId: string,
832-
mode: 'paidtier' | 'paidtier-success' | 'freetier' | 'freetier-limit'
833-
) => {
834-
if (!['paidtier', 'paidtier-success', 'freetier', 'freetier-limit'].includes(mode)) {
835-
return // invalid mode
830+
const onPaidTierModeChange = (tabId: string, mode: string | undefined) => {
831+
if (!mode || !['freetier', 'freetier-limit', 'freetier-upgrade-pending', 'paidtier'].includes(mode)) {
832+
return false // invalid mode
836833
}
837834

838835
tabId = tabId !== '' ? tabId : getOrCreateTabId()!
839836

840-
// Detect if the tab is already showing the "Upgrade Q" calls-to-action.
841-
const didShowLimitReached = mynahUi.getTabData(tabId)?.getStore()?.promptInputButtons?.[0] === upgradeQButton
842-
if (mode === 'freetier-limit' && !didShowLimitReached) {
843-
mynahUi.addChatItem(tabId, freeTierLimitReachedCard)
844-
} else if (mode === 'paidtier-success') {
845-
mynahUi.addChatItem(tabId, paidTierSuccessCard)
837+
// Detect if the tab is already showing the "Upgrade Q" UI.
838+
const isFreeTierLimitUi =
839+
mynahUi.getTabData(tabId)?.getStore()?.promptInputStickyCard?.messageId ===
840+
freeTierLimitStickyCard.messageId
841+
842+
if (mode === 'freetier-limit') {
843+
mynahUi.updateStore(tabId, {
844+
promptInputStickyCard: freeTierLimitStickyCard,
845+
})
846+
847+
if (!isFreeTierLimitUi) {
848+
// Avoid duplicate "limit reached" cards.
849+
mynahUi.addChatItem(tabId, freeTierLimitCard)
850+
}
851+
} else if (mode === 'freetier-upgrade-pending') {
852+
// Change the sticky banner to show a progress spinner.
853+
const card: typeof freeTierLimitStickyCard = {
854+
...freeTierLimitStickyCard,
855+
icon: 'progress',
856+
}
857+
mynahUi.updateStore(tabId, {
858+
// Show a progress ribbon.
859+
promptInputProgress: {
860+
status: 'default',
861+
text: 'Waiting for subscription status...',
862+
value: -1, // infinite
863+
// valueText: 'Waiting 2...',
864+
},
865+
promptInputStickyCard: card,
866+
})
867+
} else if (mode === 'paidtier') {
868+
mynahUi.updateStore(tabId, {
869+
promptInputStickyCard: null,
870+
promptInputProgress: null,
871+
})
872+
if (isFreeTierLimitUi) {
873+
// Avoid duplicate "success" cards.
874+
mynahUi.addChatItem(tabId, paidTierSuccessCard)
875+
}
846876
}
847877

848878
mynahUi.updateStore(tabId, {
849-
promptInputButtons: mode === 'freetier-limit' ? [upgradeQButton] : [],
879+
// promptInputButtons: mode === 'freetier-limit' ? [upgradeQButton] : [],
850880
promptInputDisabledState: mode === 'freetier-limit',
851881
})
882+
883+
return true
852884
}
853885

854886
const updateChat = (params: ChatUpdateParams) => {
855887
// HACK: Special field sent by `agenticChatController.ts:setPaidTierMode()`.
856-
if ((params as any).paidTierMode) {
857-
onPaidTierModeChange(params.tabId, (params as any).paidTierMode as any)
888+
if (onPaidTierModeChange(params.tabId, (params as any).paidTierMode as string)) {
858889
return
859890
}
860891

chat-client/src/client/texts/paidTier.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
import { ChatItem, ChatItemButton, ChatItemFormItem, ChatItemType, TextBasedFormItem } from '@aws/mynah-ui'
22

3-
export const freeTierLimitReachedCard: ChatItem = {
3+
export const upgradeQButton: ChatItemButton = {
4+
flash: 'once',
5+
fillState: 'hover',
6+
position: 'outside',
7+
id: 'paidtier-upgrade-q',
8+
// https://github.com/aws/mynah-ui/blob/main/src/components/icon/icons/q.svg
9+
// https://github.com/aws/mynah-ui/blob/main/src/components/icon/icons/rocket.svg
10+
// icon: MynahIcons.Q,
11+
description: 'Upgrade to Amazon Q Pro',
12+
text: 'Upgrade Q',
13+
status: 'info',
14+
}
15+
16+
export const freeTierLimitCard: ChatItem = {
417
type: ChatItemType.ANSWER,
518
title: 'FREE TIER LIMIT REACHED',
619
header: {
@@ -14,6 +27,13 @@ export const freeTierLimitReachedCard: ChatItem = {
1427
body: 'You have reached the free tier limit. Upgrade to Amazon Q Pro.\n\n[Learn More...](https://aws.amazon.com/q/pricing/)',
1528
}
1629

30+
/** "Banner" (sticky card) shown above the chat prompt. */
31+
export const freeTierLimitStickyCard: Partial<ChatItem> = {
32+
messageId: 'freetier-limit-banner',
33+
body: 'You have reached the free tier limit. Upgrade to Amazon Q Pro. [Learn More...](https://aws.amazon.com/q/pricing/)',
34+
buttons: [upgradeQButton],
35+
}
36+
1737
export const paidTierSuccessCard: ChatItem = {
1838
type: ChatItemType.ANSWER,
1939
title: 'UPGRADED TO AMAZON Q PRO',
@@ -51,16 +71,3 @@ export const paidTierStep1: ChatItem = {
5171
type: ChatItemType.DIRECTIVE,
5272
body: 'You have upgraded to Amazon Q Pro',
5373
}
54-
55-
export const upgradeQButton: ChatItemButton = {
56-
flash: 'once',
57-
fillState: 'hover',
58-
position: 'outside',
59-
id: 'upgrade-q',
60-
// https://github.com/aws/mynah-ui/blob/main/src/components/icon/icons/q.svg
61-
// https://github.com/aws/mynah-ui/blob/main/src/components/icon/icons/rocket.svg
62-
// icon: MynahIcons.Q,
63-
description: 'Upgrade to Amazon Q Pro',
64-
text: 'Upgrade Q',
65-
status: 'info',
66-
}

0 commit comments

Comments
 (0)