@@ -220,7 +220,7 @@ import {
220220 Message as DbMessage ,
221221 messageToStreamingMessage ,
222222} from './tools/chatDb/util'
223- import { FALLBACK_MODEL_OPTIONS , MODEL_RECORD } from './constants/modelSelection'
223+ import { FALLBACK_MODEL_OPTIONS , FALLBACK_MODEL_RECORD } from './constants/modelSelection'
224224import { DEFAULT_IMAGE_VERIFICATION_OPTIONS , verifyServerImage } from '../../shared/imageVerification'
225225import { sanitize } from '@aws/lsp-core/out/util/path'
226226import { ActiveUserTracker } from '../../shared/activeUserTracker'
@@ -755,7 +755,7 @@ export class AgenticChatController implements ChatHandlers {
755755
756756 // Get the first fallback model option as default
757757 const defaultModelOption = FALLBACK_MODEL_OPTIONS [ 1 ]
758- const DEFAULT_MODEL_ID = defaultModelOption ?. id || Object . keys ( MODEL_RECORD ) [ 1 ]
758+ const DEFAULT_MODEL_ID = defaultModelOption ?. id || Object . keys ( FALLBACK_MODEL_RECORD ) [ 1 ]
759759
760760 const sessionResult = this . #chatSessionManagementService. getSession ( params . tabId )
761761 const { data : session , success } = sessionResult
@@ -773,22 +773,27 @@ export class AgenticChatController implements ChatHandlers {
773773 let selectedModelId : string
774774 let modelId = this . #chatHistoryDb. getModelId ( )
775775
776+ // Helper function to get model label from FALLBACK_MODEL_RECORD
777+ const getModelLabel = ( modelKey : string ) =>
778+ FALLBACK_MODEL_RECORD [ modelKey as keyof typeof FALLBACK_MODEL_RECORD ] ?. label || modelKey
779+
780+ // Determine selected model ID based on priority
776781 if ( modelId ) {
777- // Case 1: User has previously selected a model - use that model or its mapped version
778- // Check if modelId is a key in MODEL_RECORD
779- if ( modelId in MODEL_RECORD ) {
780- // If it's a valid model key, use its mapped label
781- selectedModelId = MODEL_RECORD [ modelId as keyof typeof MODEL_RECORD ] ?. label || modelId
782- } else {
783- // Otherwise use as is (might be a direct model ID from the API)
782+ // Priority 1: Use modelId if it exists in available models from backend
783+ if ( models . some ( model => model . id === modelId ) ) {
784784 selectedModelId = modelId
785785 }
786- } else if ( defaultModelId ) {
787- // Case 2: No user selection, but API provided a default model - use server recommendation
788- selectedModelId = defaultModelId
786+ // Priority 2: Use mapped version if modelId exists in FALLBACK_MODEL_RECORD
787+ else if ( modelId in FALLBACK_MODEL_RECORD ) {
788+ selectedModelId = getModelLabel ( modelId )
789+ }
790+ // Priority 3: Fall back to default or system default
791+ else {
792+ selectedModelId = defaultModelId || getModelLabel ( DEFAULT_MODEL_ID )
793+ }
789794 } else {
790- // Case 3: Last resort - use default model's label
791- selectedModelId = MODEL_RECORD [ DEFAULT_MODEL_ID as keyof typeof MODEL_RECORD ] ?. label || DEFAULT_MODEL_ID
795+ // No user-selected model - use API default or system default
796+ selectedModelId = defaultModelId || getModelLabel ( DEFAULT_MODEL_ID )
792797 }
793798
794799 // Store the selected model in the session
0 commit comments