Skip to content

Commit 7ee1f2a

Browse files
authored
feat(amazonq): model throttling message as card instead of chat message (#1657)
* feat(amazonq): model throttling message as card instead of chat message * fix empty message bug for VS
1 parent bbdb4b4 commit 7ee1f2a

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

chat-client/src/client/mynahUi.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import {
6060
} from './utils'
6161
import { ChatHistory, ChatHistoryList } from './features/history'
6262
import { pairProgrammingModeOff, pairProgrammingModeOn, programmerModeCard } from './texts/pairProgramming'
63-
import { getModelSelectionChatItem } from './texts/modelSelection'
63+
import { getModelSelectionChatItem, modelUnavailableBanner } from './texts/modelSelection'
6464
import {
6565
freeTierLimitSticky,
6666
upgradeSuccessSticky,
@@ -877,7 +877,7 @@ export const createMynahUi = (
877877
return false // invalid mode
878878
}
879879

880-
tabId = !!tabId ? tabId : getOrCreateTabId()!
880+
tabId = tabId ? tabId : getOrCreateTabId()!
881881
const store = mynahUi.getTabData(tabId).getStore() || {}
882882

883883
// Detect if the tab is already showing the "Upgrade Q" UI.
@@ -979,6 +979,13 @@ export const createMynahUi = (
979979
return
980980
}
981981

982+
if (updatedMessage.messageId === 'modelUnavailable') {
983+
mynahUi.updateStore(tabId, {
984+
promptInputStickyCard: modelUnavailableBanner,
985+
})
986+
return
987+
}
988+
982989
const oldMessage = chatItems.find(ci => ci.messageId === updatedMessage.messageId)
983990
if (!oldMessage) return
984991

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,14 @@ export const getModelSelectionChatItem = (modelId: string): ChatItem => ({
3535
fullWidth: true,
3636
body: `Switched model to ${modelRecord[modelId as BedrockModel].label}`,
3737
})
38+
39+
export const modelUnavailableBanner: Partial<ChatItem> = {
40+
messageId: 'model-unavailable-banner',
41+
header: {
42+
icon: 'warning',
43+
iconStatus: 'warning',
44+
body: '### Model Unavailable',
45+
},
46+
body: `The model you selected is temporarily unavailable. Please switch to a different model and try again.`,
47+
canBeDismissed: true,
48+
}

server/aws-lsp-codewhisperer/src/language-server/agenticChat/agenticChatController.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,23 @@ export class AgenticChatController implements ChatHandlers {
22032203
buttons: [],
22042204
}
22052205
if (err.code === 'QModelResponse') {
2206+
// special case for throttling where we show error card instead of chat message
2207+
if (
2208+
err.message ===
2209+
`The model you selected is temporarily unavailable. Please switch to a different model and try again.`
2210+
) {
2211+
this.#features.chat.sendChatUpdate({
2212+
tabId: tabId,
2213+
data: { messages: [{ messageId: 'modelUnavailable' }] },
2214+
})
2215+
const emptyChatResult: ChatResult = {
2216+
type: 'answer',
2217+
body: '',
2218+
messageId: errorMessageId,
2219+
buttons: [],
2220+
}
2221+
return emptyChatResult
2222+
}
22062223
return responseData
22072224
}
22082225
return new ResponseError<ChatResult>(LSPErrorCodes.RequestFailed, err.message, responseData)

0 commit comments

Comments
 (0)