mirror of
https://github.com/cline/cline.git
synced 2026-09-01 15:11:04 +08:00
Use the right model info
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { ApiConfiguration, clinePassDefaultModelId, clinePassModels, ModelInfo, QwenApiRegions } from "@shared/api"
|
||||
import { ApiConfiguration, clinePassDefaultModelId, ModelInfo, QwenApiRegions, resolveClinePassModelInfo } from "@shared/api"
|
||||
import { Mode } from "@shared/storage/types"
|
||||
import { featureFlagsService } from "@/services/feature-flags"
|
||||
import { ClineStorageMessage } from "@/shared/messages/content"
|
||||
@@ -292,10 +292,7 @@ function createHandlerForProvider(
|
||||
const clineModelId = configuredClinePassModelId?.startsWith("cline-pass/")
|
||||
? configuredClinePassModelId
|
||||
: clinePassDefaultModelId
|
||||
const clineModelInfo =
|
||||
configuredClinePassModelInfo ||
|
||||
clinePassModels[clineModelId as keyof typeof clinePassModels] ||
|
||||
clinePassModels[clinePassDefaultModelId]
|
||||
const clineModelInfo = configuredClinePassModelInfo || resolveClinePassModelInfo(clineModelId)
|
||||
return new ClineHandler({
|
||||
onRetryAttempt: options.onRetryAttempt,
|
||||
clineAccountId: options.clineAccountId,
|
||||
|
||||
@@ -1026,6 +1026,18 @@ export const clineDevstralModelInfo: ModelInfo = {
|
||||
|
||||
export type ClinePassModelId = keyof typeof clinePassModels
|
||||
export const clinePassDefaultModelId = "cline-pass/glm-5.1"
|
||||
export const clinePassModelInfoSaneDefaults: ModelInfo = {
|
||||
maxTokens: 8_192,
|
||||
contextWindow: 128_000,
|
||||
supportsImages: false,
|
||||
supportsPromptCache: false,
|
||||
supportsReasoning: true,
|
||||
inputPrice: 0,
|
||||
outputPrice: 0,
|
||||
cacheReadsPrice: 0,
|
||||
cacheWritesPrice: 0,
|
||||
description: "",
|
||||
}
|
||||
export const clinePassModels = {
|
||||
"cline-pass/glm-5.1": {
|
||||
name: "cline-pass/glm-5.1",
|
||||
@@ -1042,6 +1054,28 @@ export const clinePassModels = {
|
||||
},
|
||||
} as const satisfies Record<string, ModelInfo>
|
||||
|
||||
export function getModelSlug(modelId: string): string {
|
||||
return modelId.split("/").at(-1) ?? modelId
|
||||
}
|
||||
|
||||
export function buildModelInfoNameMap(models: Record<string, ModelInfo>): Record<string, ModelInfo> {
|
||||
const nameMap: Record<string, ModelInfo> = {}
|
||||
|
||||
for (const [id, info] of Object.entries(models)) {
|
||||
nameMap[getModelSlug(id)] = info
|
||||
}
|
||||
|
||||
return nameMap
|
||||
}
|
||||
|
||||
export function resolveClinePassModelInfo(modelId: string, modelInfoByName?: Record<string, ModelInfo>): ModelInfo {
|
||||
return (
|
||||
clinePassModels[modelId as keyof typeof clinePassModels] ??
|
||||
modelInfoByName?.[getModelSlug(modelId)] ??
|
||||
clinePassModelInfoSaneDefaults
|
||||
)
|
||||
}
|
||||
|
||||
export const OPENROUTER_PROVIDER_PREFERENCES: Record<string, { order: string[]; allow_fallbacks: boolean }> = {
|
||||
// Exacto Providers
|
||||
"moonshotai/kimi-k2:exacto": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { type ApiConfiguration, CLAUDE_SONNET_1M_SUFFIX, type ModelInfo } from "@shared/api"
|
||||
import { type ApiConfiguration, buildModelInfoNameMap, CLAUDE_SONNET_1M_SUFFIX, type ModelInfo } from "@shared/api"
|
||||
import { CLINE_RECOMMENDED_MODELS_FALLBACK } from "@shared/cline/recommended-models"
|
||||
import { EmptyRequest, StringRequest } from "@shared/proto/cline/common"
|
||||
import { type ClineRecommendedModel, ClineRecommendedModelsResponse } from "@shared/proto/cline/models"
|
||||
@@ -111,12 +111,17 @@ const ClineModelPicker: React.FC<ClineModelPickerProps> = ({
|
||||
showFeaturedModels = true,
|
||||
}) => {
|
||||
const { handleModeFieldsChange, handleFieldChange } = useApiConfigurationHandlers()
|
||||
const { apiConfiguration, favoritedModelIds, clineModels, refreshClineModels } = useExtensionState()
|
||||
const { apiConfiguration, favoritedModelIds, clineModels, openRouterModels, refreshClineModels } = useExtensionState()
|
||||
const modeFields = getModeSpecificFields(apiConfiguration, currentMode)
|
||||
const resolvedModels = models ?? clineModels
|
||||
const openRouterModelsByName = useMemo(() => buildModelInfoNameMap(openRouterModels), [openRouterModels])
|
||||
const normalizedSelection = useMemo(
|
||||
() => normalizeApiConfiguration(apiConfiguration, currentMode, { isClinePassEnabled }),
|
||||
[apiConfiguration, currentMode, isClinePassEnabled],
|
||||
() =>
|
||||
normalizeApiConfiguration(apiConfiguration, currentMode, {
|
||||
isClinePassEnabled,
|
||||
clinePassModelInfoByName: openRouterModelsByName,
|
||||
}),
|
||||
[apiConfiguration, currentMode, isClinePassEnabled, openRouterModelsByName],
|
||||
)
|
||||
const configuredModelId = apiConfiguration?.[modelIdFieldPair[currentMode]] as string | undefined
|
||||
const selectedOrDefaultModelId = defaultModelId ?? normalizedSelection.selectedModelId
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
import { clinePassDefaultModelId, clinePassModels, type ModelInfo } from "@shared/api"
|
||||
import {
|
||||
buildModelInfoNameMap,
|
||||
clinePassDefaultModelId,
|
||||
clinePassModels,
|
||||
type ModelInfo,
|
||||
resolveClinePassModelInfo,
|
||||
} from "@shared/api"
|
||||
import { EmptyRequest } from "@shared/proto/cline/common"
|
||||
import { useCallback, useEffect, useMemo, useState } from "react"
|
||||
import { useExtensionState } from "@/context/ExtensionStateContext"
|
||||
import { ModelsServiceClient } from "@/services/grpc-client"
|
||||
import ClineModelPicker from "../ClineModelPicker"
|
||||
import { ClineProvider } from "./ClineProvider"
|
||||
|
||||
export const ClinePassProvider: typeof ClineProvider = (props) => {
|
||||
const { openRouterModels } = useExtensionState()
|
||||
const openRouterModelsByName = useMemo(() => buildModelInfoNameMap(openRouterModels), [openRouterModels])
|
||||
const [clinePassRecommendedModels, setClinePassRecommendedModels] = useState<Record<string, ModelInfo> | undefined>(undefined)
|
||||
|
||||
const refreshClinePassModels = useCallback(async () => {
|
||||
@@ -15,8 +24,11 @@ export const ClinePassProvider: typeof ClineProvider = (props) => {
|
||||
(response.clinePass ?? [])
|
||||
.filter((model) => model.id)
|
||||
.map((model) => {
|
||||
const fallback =
|
||||
clinePassModels[model.id as keyof typeof clinePassModels] ?? clinePassModels[clinePassDefaultModelId]
|
||||
// Cline Pass model IDs omit the upstream lab, so look up capabilities using
|
||||
// the model slug (for example, glm-5.1 instead of cline-pass/glm-5.1).
|
||||
// If the model is not in OpenRouter yet, use conservative generic defaults
|
||||
// instead of copying GLM-5.1-specific context/max-token values.
|
||||
const fallback = resolveClinePassModelInfo(model.id, openRouterModelsByName)
|
||||
return [
|
||||
model.id,
|
||||
{
|
||||
@@ -31,7 +43,7 @@ export const ClinePassProvider: typeof ClineProvider = (props) => {
|
||||
} catch (error) {
|
||||
console.error("Failed to refresh Cline Pass models:", error)
|
||||
}
|
||||
}, [])
|
||||
}, [openRouterModelsByName])
|
||||
|
||||
useEffect(() => {
|
||||
void refreshClinePassModels()
|
||||
|
||||
@@ -61,6 +61,7 @@ import {
|
||||
qwenCodeModels,
|
||||
requestyDefaultModelId,
|
||||
requestyDefaultModelInfo,
|
||||
resolveClinePassModelInfo,
|
||||
sambanovaDefaultModelId,
|
||||
sambanovaModels,
|
||||
sapAiCoreDefaultModelId,
|
||||
@@ -184,7 +185,7 @@ export interface NormalizedApiConfig {
|
||||
export function normalizeApiConfiguration(
|
||||
apiConfiguration: ApiConfiguration | undefined,
|
||||
currentMode: Mode,
|
||||
options: { isClinePassEnabled?: boolean } = {},
|
||||
options: { isClinePassEnabled?: boolean; clinePassModelInfoByName?: Record<string, ModelInfo> } = {},
|
||||
): NormalizedApiConfig {
|
||||
const configuredProvider =
|
||||
(currentMode === "plan" ? apiConfiguration?.planModeApiProvider : apiConfiguration?.actModeApiProvider) || "anthropic"
|
||||
@@ -308,8 +309,7 @@ export function normalizeApiConfiguration(
|
||||
(currentMode === "plan"
|
||||
? apiConfiguration?.planModeClinePassModelInfo
|
||||
: apiConfiguration?.actModeClinePassModelInfo) ||
|
||||
clinePassModels[clinePassModelId as keyof typeof clinePassModels] ||
|
||||
clinePassModels[clinePassDefaultModelId]
|
||||
resolveClinePassModelInfo(clinePassModelId, options.clinePassModelInfoByName)
|
||||
return {
|
||||
selectedProvider: provider,
|
||||
selectedModelId: clinePassModelId,
|
||||
|
||||
Reference in New Issue
Block a user