695
let historyDerivedModel: ISerializableChatModelInputState['selectedModel'] = undefined;
696
if ((modelId || agentUri)) {
697
>
const mode: ISerializableChatModelInputState['mode'] = agentUri ? { kind: ChatModeKind.Agent, id: agentUri.toString() } : { kind: ChatModeKind.Agent, id: ChatMode.Agent.id };
chatServiceImpl.ts
698
>
const modelMetadata = modelId ? this.languageModelsService.lookupLanguageModel(modelId) : undefined;
699
>
// The session request history only tells us which model id was last used, not the
700
>
// user's per-model configuration (e.g. thinking effort, context window). Preserve that
701
>
// configuration from the persisted draft when it refers to the same model, so reopening
702
>
// the session restores the full model config and not just the bare model id. Older drafts
703
>
// stored the configuration as a sibling of `selectedModel` (legacy top-level field) rather
704
>
// than nested within it, so fall back to that for backwards compatibility.
705
>
const storedModelConfiguration = storedInputState?.selectedModel?.modelConfiguration
706
>
?? (storedInputState as { modelConfiguration?: IStringDictionary<unknown> } | undefined)?.modelConfiguration;
707
>
const modelConfiguration = storedInputState?.selectedModel?.identifier === modelId
708
? storedModelConfiguration
710
>
// When the live model list has not loaded yet (cold restore) `lookupLanguageModel`
711
>
// returns undefined. Don't discard the known model: fall back to the session's saved
712
>
// draft model, which carries the full serialized metadata (including
713
>
// `targetChatSessionType`), when it refers to the same id the request history reports
714
>
// as last used. Handing the input part a model-with-metadata lets it wait for the
715
>
// model pool and apply it once it loads, instead of falling back to Auto.
716
>
const storedSelectedModel = storedInputState?.selectedModel;
717
>
const selectedModel: ISerializableChatModelInputState['selectedModel'] = modelId && modelMetadata
718
>
? { identifier: modelId, metadata: modelMetadata, modelConfiguration }
719
: (modelId && storedSelectedModel && storedSelectedModel.identifier === modelId
720
? { ...storedSelectedModel, modelConfiguration }
721
: undefined);
723
>
historyDerivedModel = selectedModel;
724
>
// This is used to initialize the state of the chat input box, with the selected model, mode, etc
725
>
initialData = {
726
>
serializer: new ChatSessionOperationLog(),
727
>
value: {
728
>
creationDate: Date.now(),
729
>
initialLocation: undefined,
730
>
customTitle: undefined,
731
>
requests: [],
732
>
responderUsername: '',
733
>
sessionId: '',
734
>
version: 3,
735
>
inputState: {
736
>
attachments: [],
737
>
contrib: {},
738
>
inputText: '',
739
>
mode,
740
>
selectedModel: selectedModel,
741
>
selections: [],
742
>
permissionLevel: storedPermissionLevel,
743
>
},
744
>
pendingRequests: undefined,
745
>
repoData: undefined
746
>
}
747
>
};
748
>
}
749
750
// Contributed sessions do not use UI tools.