@@ -153,6 +153,15 @@ const isModelSelection = (value: unknown): value is ModelSelection => {
153153 return typeof record . providerId === 'string' && typeof record . modelId === 'string'
154154}
155155
156+ const normalizeKnownModelId = ( modelId : string ) : string => {
157+ const normalizedModelId = modelId . trim ( ) . toLowerCase ( )
158+ return normalizedModelId . replace ( / ^ m o d e l s \/ / , '' )
159+ }
160+
161+ const normalizeKnownProviderId = ( providerId : string ) : string =>
162+ modelCapabilities . resolveProviderId ( providerId . trim ( ) . toLowerCase ( ) ) ||
163+ providerId . trim ( ) . toLowerCase ( )
164+
156165export const getAnthropicModelSelectionKeysToClear = (
157166 settings : Partial <
158167 Record <
@@ -398,16 +407,20 @@ export class ConfigPresenter implements IConfigPresenter {
398407 }
399408
400409 private migrateLegacyDefaultVisionModelToBuiltinAgent ( ) : void {
401- const legacySelection = this . store . get ( 'defaultVisionModel' ) as ModelSelection | undefined
402- if ( ! legacySelection ) {
410+ const legacySelection = this . store . get ( 'defaultVisionModel' ) as unknown
411+ if ( legacySelection === undefined ) {
403412 return
404413 }
405414
406- const providerId = legacySelection . providerId ?. trim ( )
407- const modelId = legacySelection . modelId ?. trim ( )
408415 const builtinVisionModel = this . getBuiltinDeepChatConfig ( ) . visionModel
409416
410- if ( ! builtinVisionModel ?. providerId || ! builtinVisionModel ?. modelId ) {
417+ if (
418+ isModelSelection ( legacySelection ) &&
419+ ( ! builtinVisionModel ?. providerId || ! builtinVisionModel ?. modelId )
420+ ) {
421+ const providerId = legacySelection . providerId . trim ( )
422+ const modelId = legacySelection . modelId . trim ( )
423+
411424 if ( providerId && modelId ) {
412425 this . updateBuiltinDeepChatConfig ( {
413426 visionModel : {
@@ -1036,6 +1049,26 @@ export class ConfigPresenter implements IConfigPresenter {
10361049 return this . providerModelHelper . getCustomModels ( providerId )
10371050 }
10381051
1052+ isKnownModel ( providerId : string , modelId : string ) : boolean {
1053+ const normalizedProviderId = normalizeKnownProviderId ( providerId )
1054+ const normalizedModelId = normalizeKnownModelId ( modelId )
1055+
1056+ if ( ! normalizedProviderId || ! normalizedModelId ) {
1057+ return false
1058+ }
1059+
1060+ const hasKnownModel = ( models : Array < { id : string } > | undefined ) : boolean =>
1061+ Array . isArray ( models ) &&
1062+ models . some ( ( model ) => normalizeKnownModelId ( model . id ) === normalizedModelId )
1063+
1064+ return (
1065+ this . hasUserModelConfig ( normalizedModelId , normalizedProviderId ) ||
1066+ hasKnownModel ( this . getProviderModels ( normalizedProviderId ) ) ||
1067+ hasKnownModel ( this . getCustomModels ( normalizedProviderId ) ) ||
1068+ hasKnownModel ( this . getDbProviderModels ( normalizedProviderId ) )
1069+ )
1070+ }
1071+
10391072 setCustomModels ( providerId : string , models : MODEL_META [ ] ) : void {
10401073 this . providerModelHelper . setCustomModels ( providerId , models )
10411074 }
@@ -1709,6 +1742,18 @@ export class ConfigPresenter implements IConfigPresenter {
17091742 )
17101743 }
17111744
1745+ async agentSupportsCapability ( agentId : string , capability : 'vision' ) : Promise < boolean > {
1746+ if ( capability !== 'vision' ) {
1747+ return false
1748+ }
1749+
1750+ const agentConfig = await this . resolveDeepChatAgentConfig ( agentId )
1751+ const providerId = agentConfig . visionModel ?. providerId ?. trim ( )
1752+ const modelId = agentConfig . visionModel ?. modelId ?. trim ( )
1753+
1754+ return Boolean ( providerId && modelId && this . getModelConfig ( modelId , providerId ) ?. vision )
1755+ }
1756+
17121757 async createDeepChatAgent ( input : CreateDeepChatAgentInput ) : Promise < Agent > {
17131758 const created = this . getAgentRepositoryOrThrow ( ) . createDeepChatAgent ( input )
17141759 this . notifyAcpAgentsChanged ( )
0 commit comments