refactor(migrate): consolidate migrations into version 172 (#11194)

* refactor(migrate): consolidate migrations into version 172

Consolidates migrations 162-166 into a single migration 172 to fix data
inconsistencies between release/v1.6.x and v1.7.0-x versions. This
ensures a single, consistent migration path and corrects data deviations
that occurred during version upgrades.

Changes:
- Remove separate migrations 162-166
- Add consolidated migration 172 that includes:
  - Mini app additions (ling, huggingchat)
  - OCR provider updates (ovocr)
  - Agent to preset migration
  - Sidebar icon updates (agents -> store)
  - LLM provider Anthropic API host configurations
  - Assistant preset settings initialization

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor(store): update persist version to 172

Update the redux-persist version number from 171 to 172 to match the
consolidated migration version.

Co-Authored-By: Claude <noreply@anthropic.com>

* fix(migrate): add missing break statement in switch case

Add missing break statement after 'grok' case to prevent fall-through
to 'cherryin' case. Also add break statement for 'longcat' case.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
亢奋猫 2025-11-09 00:31:35 +08:00 committed by GitHub
parent 58afbe8a79
commit 57d9a31c0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 93 additions and 127 deletions

View File

@ -67,7 +67,7 @@ const persistedReducer = persistReducer(
{
key: 'cherry-studio',
storage,
version: 171,
version: 172,
blacklist: ['runtime', 'messages', 'messageBlocks', 'tabs', 'toolPermissions'],
migrate
},

View File

@ -2623,132 +2623,6 @@ const migrateConfig = {
return state
}
},
'162': (state: RootState) => {
try {
// @ts-ignore
if (state?.agents?.agents) {
// @ts-ignore
state.assistants.presets = [...state.agents.agents]
// @ts-ignore
delete state.agents.agents
}
if (state.settings.sidebarIcons) {
state.settings.sidebarIcons.visible = state.settings.sidebarIcons.visible.map((icon) => {
// @ts-ignore
return icon === 'agents' ? 'store' : icon
})
state.settings.sidebarIcons.disabled = state.settings.sidebarIcons.disabled.map((icon) => {
// @ts-ignore
return icon === 'agents' ? 'store' : icon
})
}
state.llm.providers.forEach((provider) => {
if (provider.anthropicApiHost) {
return
}
switch (provider.id) {
case 'deepseek':
provider.anthropicApiHost = 'https://api.deepseek.com/anthropic'
break
case 'moonshot':
provider.anthropicApiHost = 'https://api.moonshot.cn/anthropic'
break
case 'zhipu':
provider.anthropicApiHost = 'https://open.bigmodel.cn/api/anthropic'
break
case 'dashscope':
provider.anthropicApiHost = 'https://dashscope.aliyuncs.com/api/v2/apps/claude-code-proxy'
break
case 'modelscope':
provider.anthropicApiHost = 'https://api-inference.modelscope.cn'
break
case 'aihubmix':
provider.anthropicApiHost = 'https://aihubmix.com'
break
case 'new-api':
provider.anthropicApiHost = 'http://localhost:3000'
break
case 'grok':
provider.anthropicApiHost = 'https://api.x.ai'
}
})
return state
} catch (error) {
logger.error('migrate 162 error', error as Error)
return state
}
},
'163': (state: RootState) => {
try {
addOcrProvider(state, BUILTIN_OCR_PROVIDERS_MAP.ovocr)
state.llm.providers.forEach((provider) => {
if (provider.id === 'cherryin') {
provider.anthropicApiHost = 'https://open.cherryin.net'
}
})
state.paintings.ovms_paintings = []
return state
} catch (error) {
logger.error('migrate 163 error', error as Error)
return state
}
},
'164': (state: RootState) => {
try {
addMiniApp(state, 'ling')
return state
} catch (error) {
logger.error('migrate 164 error', error as Error)
return state
}
},
'165': (state: RootState) => {
try {
addMiniApp(state, 'huggingchat')
return state
} catch (error) {
logger.error('migrate 165 error', error as Error)
return state
}
},
'166': (state: RootState) => {
try {
if (state.assistants.presets === undefined) {
state.assistants.presets = []
}
state.assistants.presets.forEach((preset) => {
if (!preset.settings) {
preset.settings = DEFAULT_ASSISTANT_SETTINGS
} else if (!preset.settings.toolUseMode) {
preset.settings.toolUseMode = DEFAULT_ASSISTANT_SETTINGS.toolUseMode
}
})
// 更新阿里云百炼的 Anthropic API 地址
const dashscopeProvider = state.llm.providers.find((provider) => provider.id === 'dashscope')
if (dashscopeProvider) {
dashscopeProvider.anthropicApiHost = 'https://dashscope.aliyuncs.com/apps/anthropic'
}
state.llm.providers.forEach((provider) => {
if (provider.id === SystemProviderIds['new-api'] && provider.type !== 'new-api') {
provider.type = 'new-api'
}
if (provider.id === SystemProviderIds.longcat) {
// https://longcat.chat/platform/docs/zh/#anthropic-api-%E6%A0%BC%E5%BC%8F
if (!provider.anthropicApiHost) {
provider.anthropicApiHost = 'https://api.longcat.chat/anthropic'
}
}
})
return state
} catch (error) {
logger.error('migrate 166 error', error as Error)
return state
}
},
'167': (state: RootState) => {
try {
addProvider(state, 'huggingface')
@ -2817,6 +2691,98 @@ const migrateConfig = {
logger.error('migrate 171 error', error as Error)
return state
}
},
'172': (state: RootState) => {
try {
// Add ling and huggingchat mini apps
addMiniApp(state, 'ling')
addMiniApp(state, 'huggingchat')
// Add ovocr provider and clear ovms paintings
addOcrProvider(state, BUILTIN_OCR_PROVIDERS_MAP.ovocr)
if (isEmpty(state.paintings.ovms_paintings)) {
state.paintings.ovms_paintings = []
}
// Migrate agents to assistants presets
// @ts-ignore
if (state?.agents?.agents) {
// @ts-ignore
state.assistants.presets = [...state.agents.agents]
// @ts-ignore
delete state.agents.agents
}
// Initialize assistants presets
if (state.assistants.presets === undefined) {
state.assistants.presets = []
}
// Migrate assistants presets
state.assistants.presets.forEach((preset) => {
if (!preset.settings) {
preset.settings = DEFAULT_ASSISTANT_SETTINGS
} else if (!preset.settings.toolUseMode) {
preset.settings.toolUseMode = DEFAULT_ASSISTANT_SETTINGS.toolUseMode
}
})
// Migrate sidebar icons
if (state.settings.sidebarIcons) {
state.settings.sidebarIcons.visible = state.settings.sidebarIcons.visible.map((icon) => {
// @ts-ignore
return icon === 'agents' ? 'store' : icon
})
state.settings.sidebarIcons.disabled = state.settings.sidebarIcons.disabled.map((icon) => {
// @ts-ignore
return icon === 'agents' ? 'store' : icon
})
}
// Migrate llm providers
state.llm.providers.forEach((provider) => {
if (provider.id === SystemProviderIds['new-api'] && provider.type !== 'new-api') {
provider.type = 'new-api'
}
switch (provider.id) {
case 'deepseek':
provider.anthropicApiHost = 'https://api.deepseek.com/anthropic'
break
case 'moonshot':
provider.anthropicApiHost = 'https://api.moonshot.cn/anthropic'
break
case 'zhipu':
provider.anthropicApiHost = 'https://open.bigmodel.cn/api/anthropic'
break
case 'dashscope':
provider.anthropicApiHost = 'https://dashscope.aliyuncs.com/apps/anthropic'
break
case 'modelscope':
provider.anthropicApiHost = 'https://api-inference.modelscope.cn'
break
case 'aihubmix':
provider.anthropicApiHost = 'https://aihubmix.com'
break
case 'new-api':
provider.anthropicApiHost = 'http://localhost:3000'
break
case 'grok':
provider.anthropicApiHost = 'https://api.x.ai'
break
case 'cherryin':
provider.anthropicApiHost = 'https://open.cherryin.net'
break
case 'longcat':
provider.anthropicApiHost = 'https://api.longcat.chat/anthropic'
break
}
})
return state
} catch (error) {
logger.error('migrate 172 error', error as Error)
return state
}
}
}