Merge pull request #68 from shengsuan/fix_mpm

修复模型选择错误
This commit is contained in:
HybridTalentComputing authored and GitHub committed 2026-01-23 15:57:47 +08:00
commit dc519b7ba5
10 files changed
+142 -30

No files matched your search

+1 -2
View File
@@ -113,8 +113,7 @@
},
"css": {
"parser": {
"cssModules": false,
"tailwindDirectives": true
"cssModules": false
}
},
"files": {
+1 -1
View File
@@ -26,7 +26,7 @@ export class SSYAccountService {
const url = `${this.baseUrl}${endpoint}`
// console.log("SSYAccountService.authenticatedRequest():", url, reqConfig)
const res: any = await axios.get(url, reqConfig)
console.log(url, res.data)
// console.log(url, res.data)
if (!res.data || !res.data.data || res.data.code == 103) {
throw new Error(`Invalid response from ${endpoint} API`)
}
@@ -4,6 +4,7 @@ import {
LiteLLMModelInfo as ProtoLiteLLMModelInfo,
OcaModelInfo as ProtoOcaModelInfo,
OpenAiCompatibleModelInfo as ProtoOpenAiCompatibleModelInfo,
ShengSuanYunModelInfo,
ThinkingConfig,
} from "@shared/proto/cline/models"
@@ -168,3 +169,26 @@ export function toProtobufModels(models: Record<string, ModelInfo>): Record<stri
}
return result
}
export function fromProtobufShengSuanYunModelInfo(protoInfo: ShengSuanYunModelInfo): ModelInfo {
return {
maxTokens: protoInfo.maxTokens,
contextWindow: protoInfo.contextWindow,
supportsImages: protoInfo.supportsImages,
supportsPromptCache: protoInfo.supportsPromptCache,
inputPrice: protoInfo.inputPrice,
outputPrice: protoInfo.outputPrice,
cacheWritesPrice: protoInfo.cacheWritesPrice,
cacheReadsPrice: protoInfo.cacheReadsPrice,
description: protoInfo.description,
thinkingConfig: convertThinkingConfig(protoInfo.thinkingConfig),
}
}
export function fromProtobufShengSuanYunModels(protoModels: Record<string, ShengSuanYunModelInfo>): Record<string, ModelInfo> {
const result: Record<string, ModelInfo> = {}
for (const [key, value] of Object.entries(protoModels)) {
result[key] = fromProtobufShengSuanYunModelInfo(value)
}
return result
}
@@ -139,7 +139,6 @@ export const SSYAccountView = () => {
<p style={{}}>注册帐户访问最新模型,进群联系客服,获得100万Tokens免费额度,以及更多即将推出的功能。</p>
<VSCodeButton
className="w-full mb-4"
disabled={isLoading}
onClick={() => {
setIsLoading(true)
AccountServiceClient.shengSuanYunLoginClicked(EmptyRequest.create())
@@ -27,6 +27,7 @@ const SETTINGS_ONLY_PROVIDERS: ApiProvider[] = [
"oca",
"aihubmix",
"together",
"shengsuanyun",
]
// Helper to get provider-specific configuration info and empty state guidance
@@ -78,6 +79,14 @@ const getProviderInfo = (
baseUrl: apiConfiguration.requestyBaseUrl,
helpText: t("settings.apiConfig.providerHelpText.requesty"),
}
case "shengsuanyun":
return {
modelId:
effectiveMode === "plan"
? apiConfiguration.planModeShengSuanYunModelId
: apiConfiguration.actModeShengSuanYunModelId,
helpText: t("settings.apiConfig.providerHelpText.shengsuanyun"),
}
case "together":
return {
modelId:
@@ -121,9 +130,9 @@ const getProviderInfo = (
const OPENROUTER_MODEL_PROVIDERS: ApiProvider[] = ["cline", "openrouter", "vercel-ai-gateway"]
import { freeModels, recommendedModels } from "@/components/settings/OpenRouterModelPicker"
import { SUPPORTED_ANTHROPIC_THINKING_MODELS } from "@/components/settings/providers/AnthropicProvider"
import { SUPPORTED_BEDROCK_THINKING_MODELS } from "@/components/settings/providers/BedrockProvider"
import { freeModels, recommendedModels } from "@/components/settings/ShengSuanYunModelPicker"
import {
filterOpenRouterModelIds,
getModelsForProvider,
@@ -178,6 +187,7 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
const { t } = useTranslation()
const {
apiConfiguration,
shengSuanYunModels,
openRouterModels,
navigateToSettings,
planActSeparateModelsSetting,
@@ -207,7 +217,6 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
// Get current provider from config - use activeEditMode when in split mode
const effectiveMode = planActSeparateModelsSetting ? activeEditMode : currentMode
const { selectedProvider, selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration, effectiveMode)
// Get both Plan and Act models for split view
const planModel = useMemo(() => normalizeApiConfiguration(apiConfiguration, "plan"), [apiConfiguration])
const actModel = useMemo(() => normalizeApiConfiguration(apiConfiguration, "act"), [apiConfiguration])
@@ -264,14 +273,14 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
// Get models for current provider
const allModels = useMemo((): ModelItem[] => {
if (OPENROUTER_MODEL_PROVIDERS.includes(selectedProvider)) {
const modelIds = Object.keys(openRouterModels || {})
const modelIds = Object.keys(shengSuanYunModels || {})
const filteredIds = filterOpenRouterModelIds(modelIds, selectedProvider)
return filteredIds.map((id) => ({
id,
name: id.split("/").pop() || id,
provider: id.split("/")[0],
info: openRouterModels[id],
info: shengSuanYunModels[id],
}))
}
@@ -287,7 +296,7 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
}
return []
}, [selectedProvider, openRouterModels, apiConfiguration])
}, [selectedProvider, shengSuanYunModels, apiConfiguration])
// Multi-word substring search - all words must match somewhere in id/name/provider
const matchesSearch = useCallback((model: ModelItem, query: string): boolean => {
@@ -299,10 +308,10 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
// Filtered models - for OpenRouter/Vercel show all by default, for Cline only when searching
const filteredModels = useMemo(() => {
const isCline = selectedProvider === "cline"
const isShengsuanyun = selectedProvider === "shengsuanyun"
// For Cline: only show non-featured models when searching
if (isCline && !searchQuery) return []
if (isShengsuanyun && !searchQuery) return []
let models: ModelItem[]
if (searchQuery) {
@@ -316,13 +325,13 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
models = models.filter((m) => m.id !== selectedModelId)
// For Cline when searching, also filter out featured models (they're shown separately)
if (isCline) {
if (isShengsuanyun) {
const featuredIds = new Set([...recommendedModels, ...freeModels].map((m) => m.id))
models = models.filter((m) => !featuredIds.has(m.id))
}
// For openrouter/vercel-ai-gateway (not cline): put favorites first
if (!isCline && (selectedProvider === "openrouter" || selectedProvider === "vercel-ai-gateway")) {
if (!isShengsuanyun && (selectedProvider === "openrouter" || selectedProvider === "vercel-ai-gateway")) {
const favoriteSet = new Set(favoritedModelIds || [])
const favoritedModels = models.filter((m) => favoriteSet.has(m.id))
const nonFavoritedModels = models.filter((m) => !favoriteSet.has(m.id))
@@ -338,7 +347,7 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
// Featured models for Cline provider (recommended + free)
const featuredModels = useMemo(() => {
if (selectedProvider !== "cline") return []
// if (selectedProvider !== "cline") return []
const allFeatured = [...recommendedModels, ...freeModels].map((m) => ({
...m,
@@ -362,7 +371,6 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
const handleSelectModel = useCallback(
(modelId: string, modelInfo?: ModelInfoType) => {
const modeToUse = isSplit ? activeEditMode : currentMode
if (OPENROUTER_MODEL_PROVIDERS.includes(selectedProvider)) {
const modelInfoToUse = modelInfo || openRouterModels[modelId]
handleModeFieldsChange(
@@ -376,10 +384,24 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
},
modeToUse,
)
} else if (selectedProvider == "shengsuanyun") {
const modelInfoToUse = modelInfo || shengSuanYunModels[modelId]
handleModeFieldsChange(
{
shengSuanYunModelId: { plan: "planModeShengSuanYunModelId", act: "actModeShengSuanYunModelId" },
shengSuanYunModelInfo: { plan: "planModeShengSuanYunModelInfo", act: "actModeShengSuanYunModelInfo" },
},
{
shengSuanYunModelId: modelId,
shengSuanYunModelInfo: modelInfoToUse,
},
modeToUse,
)
} else {
// Static model providers use apiModelId
handleModeFieldChange({ plan: "planModeApiModelId", act: "actModeApiModelId" }, modelId, modeToUse)
}
// Only close modal if not in split mode
if (!isSplit) {
onOpenChange(false)
@@ -392,6 +414,7 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
currentMode,
isSplit,
activeEditMode,
shengSuanYunModels,
openRouterModels,
onOpenChange,
],
@@ -456,7 +479,7 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
// Determine which list the index falls into
if (selectedIndex < featuredModels.length) {
const model = featuredModels[selectedIndex]
handleSelectModel(model.id, openRouterModels[model.id])
handleSelectModel(model.id, shengSuanYunModels[model.id])
} else {
const model = filteredModels[selectedIndex - featuredModels.length]
handleSelectModel(model.id, model.info)
@@ -469,7 +492,7 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
break
}
},
[filteredModels, featuredModels, selectedIndex, handleSelectModel, openRouterModels, onOpenChange],
[filteredModels, featuredModels, selectedIndex, handleSelectModel, shengSuanYunModels, onOpenChange],
)
// Reset selectedIndex and clear refs when search/provider changes
@@ -577,7 +600,7 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
onOpenChange(!isOpen)
}, [isOpen, onOpenChange])
const isClineProvider = selectedProvider === "cline"
const isshengsuanyunProvider = selectedProvider === "shengsuanyun"
const isSearching = !!searchQuery
return (
@@ -757,7 +780,7 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
modelBelongsToProvider &&
(() => {
// Check if current model has a featured label (only for Cline provider)
const currentFeaturedModel = isClineProvider
const currentFeaturedModel = isshengsuanyunProvider
? [...recommendedModels, ...freeModels].find((m) => m.id === selectedModelId)
: undefined
const currentLabel = currentFeaturedModel
@@ -787,12 +810,12 @@ const ModelPickerModal: React.FC<ModelPickerModalProps> = ({ isOpen, onOpenChang
)}
{/* For Cline: Show recommended models */}
{isClineProvider &&
{isshengsuanyunProvider &&
featuredModels.map((model, index) => (
<ModelItemContainer
$isSelected={index === selectedIndex}
key={model.id}
onClick={() => handleSelectModel(model.id, openRouterModels[model.id])}
onClick={() => handleSelectModel(model.id, shengSuanYunModels[model.id])}
onMouseEnter={() => setSelectedIndex(index)}
ref={(el) => (itemRefs.current[index] = el)}>
<ModelInfoRow>
@@ -1,5 +1,6 @@
import { Button } from "@components/ui/button"
import { EmptyRequest } from "@shared/proto/cline/common"
import { ShengSuanYunModelInfo } from "@shared/proto/cline/models"
import React, { useCallback, useRef } from "react"
import { useMount } from "react-use"
import { Dialog, DialogContent } from "@/components/ui/dialog"
@@ -15,20 +16,33 @@ interface WhatsNewModalProps {
}
export const WhatsNewModal: React.FC<WhatsNewModalProps> = ({ open, onClose, version }) => {
const { userInfo, openRouterModels, setShowChatModelSelector, refreshOpenRouterModels } = useExtensionState()
const { userInfo, shengSuanYunModels, setShowChatModelSelector, refreshShengSuanYunModels } = useExtensionState()
const { handleFieldsChange } = useApiConfigurationHandlers()
const clickedModelsRef = useRef<Set<string>>(new Set())
// Get latest model list in case user hits shortcut button to set model
useMount(refreshOpenRouterModels)
useMount(refreshShengSuanYunModels)
const setModel = useCallback(
(modelId: string) => {
const modelInfo = shengSuanYunModels[modelId]
if (!modelInfo) {
return
}
const ssyModelInfo: ShengSuanYunModelInfo = {
...modelInfo,
endPoints: [],
thinkingConfig: modelInfo.thinkingConfig
? { ...modelInfo.thinkingConfig, outputPriceTiers: modelInfo.thinkingConfig.outputPriceTiers || [] }
: undefined,
}
handleFieldsChange({
planModeOpenRouterModelId: modelId,
actModeOpenRouterModelId: modelId,
planModeOpenRouterModelInfo: openRouterModels[modelId],
actModeOpenRouterModelInfo: openRouterModels[modelId],
planModeShengSuanYunModelId: modelId,
actModeShengSuanYunModelId: modelId,
planModeShengSuanYunModelInfo: ssyModelInfo,
actModeShengSuanYunModelInfo: ssyModelInfo,
planModeApiProvider: "shengsuanyun",
actModeApiProvider: "shengsuanyun",
})
@@ -36,7 +50,7 @@ export const WhatsNewModal: React.FC<WhatsNewModalProps> = ({ open, onClose, ver
setShowChatModelSelector(true)
onClose()
},
[handleFieldsChange, openRouterModels, setShowChatModelSelector, onClose],
[handleFieldsChange, shengSuanYunModels, setShowChatModelSelector, onClose],
)
const handleShowAccount = useCallback(() => {
@@ -37,6 +37,44 @@ const StarIcon = ({ isFavorite, onClick }: { isFavorite: boolean; onClick: (e: R
</div>
)
}
// Featured models for Cline provider organized by tabs
// Note: These will be translated in the component using useTranslation hook
export const recommendedModels = [
{
id: "anthropic/claude-sonnet-4.5",
descriptionKey: "claudeSonnet45",
labelKey: "best",
},
{
id: "google/gemini-3-flash",
descriptionKey: "gemini3Flash",
labelKey: "new",
},
{
id: "anthropic/claude-opus-4.5",
descriptionKey: "claudeOpus45",
labelKey: "hot",
},
{
id: "openai/gpt-5.2",
descriptionKey: "gpt52",
labelKey: "new",
},
{
id: "google/gemini-3-pro-preview",
descriptionKey: "gemini3Pro",
labelKey: "oneMillionCtx",
},
]
export const freeModels = [
{
id: "xiaomi/mimo-v2-flash",
descriptionKey: "MiMo V2 Flash (Free)",
labelKey: "free",
},
]
const ShengSuanYunModelPicker: React.FC<ShengSuanYunModelPickerProps> = ({ isPopup, currentMode }) => {
const { apiConfiguration, shengSuanYunModels, setShengSuanYunModels } = useExtensionState()
const { handleModeFieldsChange } = useApiConfigurationHandlers()
@@ -7,12 +7,12 @@ import { DEFAULT_FOCUS_CHAIN_SETTINGS } from "@shared/FocusChainSettings"
import { DEFAULT_MCP_DISPLAY_MODE } from "@shared/McpDisplayMode"
import type { UserInfo } from "@shared/proto/cline/account"
import { EmptyRequest } from "@shared/proto/cline/common"
import type { OpenRouterCompatibleModelInfo } from "@shared/proto/cline/models"
import type { OpenRouterCompatibleModelInfo, ShengSuanYunCompatibleModelInfo } from "@shared/proto/cline/models"
import { ShengSuanYunModelInfo } from "@shared/proto/cline/models"
import { OnboardingModelGroup, type TerminalProfile } from "@shared/proto/cline/state"
import { convertProtoToClineMessage } from "@shared/proto-conversions/cline-message"
import { convertProtoMcpServersToMcpServers } from "@shared/proto-conversions/mcp/mcp-server-conversion"
import { fromProtobufModels } from "@shared/proto-conversions/models/typeConversion"
import { fromProtobufModels, fromProtobufShengSuanYunModels } from "@shared/proto-conversions/models/typeConversion"
import type React from "react"
import { createContext, useCallback, useContext, useEffect, useRef, useState } from "react"
import { Environment } from "../../../src/config"
@@ -90,6 +90,7 @@ export interface ExtensionStateContextType extends ExtensionState {
setOnboardingModels: (value: OnboardingModelGroup | undefined) => void
// Refresh functions
refreshShengSuanYunModels: () => void
refreshOpenRouterModels: () => void
refreshHicapModels: () => void
refreshLiteLlmModels: () => void
@@ -683,6 +684,17 @@ export const ExtensionStateContextProvider: React.FC<{
.catch((error: Error) => console.error("Failed to refresh OpenRouter models:", error))
}, [])
const refreshShengSuanYunModels = useCallback(() => {
ModelsServiceClient.refreshShengSuanYunModels(EmptyRequest.create({}))
.then((response: ShengSuanYunCompatibleModelInfo) => {
const models = fromProtobufShengSuanYunModels(response.models)
setOpenRouterModels({
[shengSuanYunDefaultModelId]: shengSuanYunDefaultModelInfo,
})
})
.catch((error: Error) => console.error("Failed to refresh OpenRouter models:", error))
}, [])
const refreshHicapModels = useCallback(() => {
ModelsServiceClient.refreshHicapModels(EmptyRequest.create({}))
.then((response: OpenRouterCompatibleModelInfo) => {
@@ -820,6 +832,7 @@ export const ExtensionStateContextProvider: React.FC<{
setMcpTab,
setTotalTasksSize,
refreshOpenRouterModels,
refreshShengSuanYunModels,
refreshHicapModels,
refreshLiteLlmModels,
onRelinquishControl,
+1
View File
@@ -448,6 +448,7 @@
"hicap": "Add your HiCap API key in settings",
"oca": "Configure your OCA endpoint in settings",
"aihubmix": "Add your AIHubMix API key in settings",
"shengsuanyun": "Add your ShengSuanYun API key in settings",
"default": "Configure this provider in model settings"
},
"vscodeLm": {
+1
View File
@@ -443,6 +443,7 @@
"openai": "在设置中添加您的 OpenAI API 密钥和端点",
"vscode-lm": "在设置中选择 VS Code 语言模型",
"requesty": "在设置中添加您的 Requesty API 密钥",
"shengsuanyun": "在设置中添加您的胜算云 API 密钥",
"together": "在设置中添加您的 Together AI API 密钥",
"dify": "配置您的 Dify 工作流 URL 和 API 密钥",
"hicap": "在设置中添加您的 HiCap API 密钥",