Compare commits

...
11 changed files with 44 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"claude-dev": patch
---
Add ability to choose chinese endpoint for Moonshot provider
+1
View File
@@ -239,4 +239,5 @@ message ModelsApiConfiguration {
optional string aws_authentication = 74;
optional string aws_bedrock_api_key = 75;
optional string moonshot_api_key = 76;
optional string moonshot_api_line = 77;
}
+1
View File
@@ -239,4 +239,5 @@ message ApiConfiguration {
// Moonshot
optional string moonshot_api_key = 80;
optional string moonshot_api_line = 81;
}
+1
View File
@@ -191,6 +191,7 @@ function createHandlerForProvider(apiProvider: string | undefined, options: Omit
case "moonshot":
return new MoonshotHandler({
moonshotApiKey: options.moonshotApiKey,
moonshotApiLine: options.moonshotApiLine,
apiModelId: options.apiModelId,
})
case "nebius":
+3 -1
View File
@@ -8,6 +8,7 @@ import { ModelInfo, MoonshotModelId, moonshotModels, moonshotDefaultModelId } fr
interface MoonshotHandlerOptions {
moonshotApiKey?: string
moonshotApiLine?: string
apiModelId?: string
}
@@ -23,7 +24,8 @@ export class MoonshotHandler implements ApiHandler {
}
try {
this.client = new OpenAI({
baseURL: "https://api.moonshot.ai/v1",
baseURL:
this.options.moonshotApiLine === "china" ? "https://api.moonshot.cn/v1" : "https://api.moonshot.ai/v1",
apiKey: this.options.moonshotApiKey,
})
} catch (error) {
+1
View File
@@ -62,6 +62,7 @@ export type GlobalStateKey =
| "fireworksModelMaxCompletionTokens"
| "fireworksModelMaxTokens"
| "qwenApiLine"
| "moonshotApiLine"
| "mcpMarketplaceCatalog"
| "telemetrySetting"
| "asksageApiUrl"
+5
View File
@@ -159,6 +159,7 @@ export async function getAllExtensionState(context: vscode.ExtensionContext) {
fireworksModelMaxTokens,
userInfo,
qwenApiLine,
moonshotApiLine,
liteLlmApiKey,
telemetrySetting,
asksageApiKey,
@@ -235,6 +236,7 @@ export async function getAllExtensionState(context: vscode.ExtensionContext) {
getGlobalState(context, "fireworksModelMaxTokens") as Promise<number | undefined>,
getGlobalState(context, "userInfo") as Promise<UserInfo | undefined>,
getGlobalState(context, "qwenApiLine") as Promise<string | undefined>,
getGlobalState(context, "moonshotApiLine") as Promise<string | undefined>,
getSecret(context, "liteLlmApiKey") as Promise<string | undefined>,
getGlobalState(context, "telemetrySetting") as Promise<TelemetrySetting | undefined>,
getSecret(context, "asksageApiKey") as Promise<string | undefined>,
@@ -416,6 +418,7 @@ export async function getAllExtensionState(context: vscode.ExtensionContext) {
togetherModelId,
qwenApiKey,
qwenApiLine,
moonshotApiLine,
doubaoApiKey,
mistralApiKey,
azureApiVersion,
@@ -542,6 +545,7 @@ export async function updateApiConfiguration(context: vscode.ExtensionContext, a
liteLlmApiKey,
liteLlmUsePromptCache,
qwenApiLine,
moonshotApiLine,
asksageApiKey,
asksageApiUrl,
xaiApiKey,
@@ -612,6 +616,7 @@ export async function updateApiConfiguration(context: vscode.ExtensionContext, a
liteLlmBaseUrl,
liteLlmUsePromptCache,
qwenApiLine,
moonshotApiLine,
asksageApiUrl,
favoritedModelIds,
requestTimeoutMs: apiConfiguration.requestTimeoutMs,
+1
View File
@@ -89,6 +89,7 @@ export interface ApiHandlerOptions {
azureApiVersion?: string
vsCodeLmModelSelector?: LanguageModelChatSelector
qwenApiLine?: string
moonshotApiLine?: string
moonshotApiKey?: string
nebiusApiKey?: string
asksageApiUrl?: string
@@ -368,6 +368,7 @@ export function convertApiConfigurationToProto(config: ApiConfiguration): ProtoA
azureApiVersion: config.azureApiVersion,
vsCodeLmModelSelector: config.vsCodeLmModelSelector,
qwenApiLine: config.qwenApiLine,
moonshotApiLine: config.moonshotApiLine,
moonshotApiKey: config.moonshotApiKey,
nebiusApiKey: config.nebiusApiKey,
asksageApiUrl: config.asksageApiUrl,
@@ -450,6 +451,7 @@ export function convertProtoToApiConfiguration(protoConfig: ProtoApiConfiguratio
azureApiVersion: protoConfig.azureApiVersion,
vsCodeLmModelSelector: protoConfig.vsCodeLmModelSelector,
qwenApiLine: protoConfig.qwenApiLine,
moonshotApiLine: protoConfig.moonshotApiLine,
moonshotApiKey: protoConfig.moonshotApiKey,
nebiusApiKey: protoConfig.nebiusApiKey,
asksageApiUrl: protoConfig.asksageApiUrl,
@@ -102,6 +102,9 @@ export function convertApiConfigurationToProtoApiConfiguration(config: ApiConfig
// Qwen specific
qwenApiLine: config.qwenApiLine,
// Moonshot specific
moonshotApiLine: config.moonshotApiLine,
// OpenRouter specific
openrouterProviderSorting: config.openRouterProviderSorting,
@@ -221,6 +224,9 @@ export function convertProtoApiConfigurationToApiConfiguration(protoConfig: Prot
// Qwen specific
qwenApiLine: protoConfig.qwenApiLine,
// Moonshot specific
moonshotApiLine: protoConfig.moonshotApiLine,
// OpenRouter specific
openRouterProviderSorting: protoConfig.openrouterProviderSorting,
@@ -5,6 +5,8 @@ import { ModelInfoView } from "../common/ModelInfoView"
import { normalizeApiConfiguration } from "../utils/providerUtils"
import { useApiConfigurationHandlers } from "../utils/useApiConfigurationHandlers"
import { useExtensionState } from "@/context/ExtensionStateContext"
import { useState } from "react"
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
/**
* Props for the MoonshotProvider component
@@ -21,9 +23,18 @@ export const MoonshotProvider = ({ showModelOptions, isPopup }: MoonshotProvider
const { apiConfiguration } = useExtensionState()
const { handleFieldChange } = useApiConfigurationHandlers()
// Local state for Chinese API endpoint checkbox
const [isChineseEndpoint, setIsChineseEndpoint] = useState(!!apiConfiguration?.moonshotApiLine)
// Get the normalized configuration
const { selectedModelId, selectedModelInfo } = normalizeApiConfiguration(apiConfiguration)
const handleChineseEndpointToggle = (e: any) => {
const checked = e.target.checked === true
setIsChineseEndpoint(checked)
handleFieldChange("moonshotApiLine", checked ? "china" : "")
}
return (
<div>
<ApiKeyField
@@ -34,6 +45,13 @@ export const MoonshotProvider = ({ showModelOptions, isPopup }: MoonshotProvider
helpText="This key is stored locally and only used to make API requests from this extension."
/>
<VSCodeCheckbox
checked={isChineseEndpoint}
onChange={handleChineseEndpointToggle}
style={{ marginTop: -3, marginBottom: 10 }}>
Use Chinese API endpoint
</VSCodeCheckbox>
{showModelOptions && (
<>
<ModelSelector