diff --git a/packages/types/src/global-settings.ts b/packages/types/src/global-settings.ts index f4d728d4ff3..5ea5d9e367a 100644 --- a/packages/types/src/global-settings.ts +++ b/packages/types/src/global-settings.ts @@ -146,6 +146,7 @@ export const globalSettingsSchema = z.object({ // kilocode_change start: Morph fast apply morphApiKey: z.string().optional(), fastApplyModel: fastApplyModelSchema.optional(), + fastApplyApiProvider: z.string().optional(), // kilocode_change end codebaseIndexModels: codebaseIndexModelsSchema.optional(), diff --git a/src/core/tools/editFileTool.ts b/src/core/tools/editFileTool.ts index cf0a3ea0986..86e64b286f7 100644 --- a/src/core/tools/editFileTool.ts +++ b/src/core/tools/editFileTool.ts @@ -342,9 +342,22 @@ function getFastApplyConfiguration(state: ClineProviderState): FastApplyConfigur // Read the selected model from state const selectedModel = state.fastApplyModel || "auto" + // Read fastApplyApiProvider from state when use current Api Configuration + let fastApplyApiProvider: string | undefined = state.apiConfiguration?.apiProvider + + const useCurrentApiConfiguration = state.fastApplyApiProvider === "-" + + if (!useCurrentApiConfiguration) { + // Read fastApplyApiProvider provider from fast apply setting + fastApplyApiProvider = state.fastApplyApiProvider + } + // Priority 1: Use direct Morph API key if available // Allow human-relay for debugging - if (state.morphApiKey || state.apiConfiguration?.apiProvider === "human-relay") { + if ( + (fastApplyApiProvider === "morph" && state.morphApiKey) || + state.apiConfiguration?.apiProvider === "human-relay" + ) { const [org, model] = selectedModel.split("/") return { available: true, @@ -355,8 +368,8 @@ function getFastApplyConfiguration(state: ClineProviderState): FastApplyConfigur } // Priority 2: Use KiloCode provider - if (state.apiConfiguration?.apiProvider === "kilocode") { - const token = state.apiConfiguration.kilocodeToken + if (fastApplyApiProvider === "kilocode") { + const token = useCurrentApiConfiguration ? state.apiConfiguration.kilocodeToken : state.morphApiKey if (!token) { return { available: false, error: "No KiloCode token available to use Fast Apply" } } @@ -372,15 +385,17 @@ function getFastApplyConfiguration(state: ClineProviderState): FastApplyConfigur } // Priority 3: Use OpenRouter provider - if (state.apiConfiguration?.apiProvider === "openrouter") { - const token = state.apiConfiguration.openRouterApiKey + if (fastApplyApiProvider === "openrouter") { + const token = useCurrentApiConfiguration ? state.apiConfiguration.openRouterApiKey : state.morphApiKey if (!token) { return { available: false, error: "No OpenRouter API token available to use Fast Apply" } } return { available: true, apiKey: token, - baseUrl: state.apiConfiguration.openRouterBaseUrl || "https://openrouter.ai/api/v1", + baseUrl: useCurrentApiConfiguration + ? state.apiConfiguration.openRouterBaseUrl + : "https://openrouter.ai/api/v1", model: selectedModel === "auto" ? "morph/morph-v3-large" : selectedModel, // Use selected model } } diff --git a/src/core/webview/ClineProvider.ts b/src/core/webview/ClineProvider.ts index 077c7ccc685..253f06df2d6 100644 --- a/src/core/webview/ClineProvider.ts +++ b/src/core/webview/ClineProvider.ts @@ -1945,6 +1945,7 @@ ${prompt} dismissedNotificationIds, // kilocode_change morphApiKey, // kilocode_change fastApplyModel, // kilocode_change: Fast Apply model selection + fastApplyApiProvider, // kilocode_change: Fast Apply model api base url alwaysAllowFollowupQuestions, followupAutoApproveTimeoutMs, includeDiagnosticMessages, @@ -2126,6 +2127,7 @@ ${prompt} dismissedNotificationIds: dismissedNotificationIds ?? [], // kilocode_change morphApiKey, // kilocode_change fastApplyModel: fastApplyModel ?? "auto", // kilocode_change: Fast Apply model selection + fastApplyApiProvider: fastApplyApiProvider ?? "-", // kilocode_change: Fast Apply model api base url alwaysAllowFollowupQuestions: alwaysAllowFollowupQuestions ?? false, followupAutoApproveTimeoutMs: followupAutoApproveTimeoutMs ?? 60000, includeDiagnosticMessages: includeDiagnosticMessages ?? true, @@ -2341,6 +2343,7 @@ ${prompt} dismissedNotificationIds: stateValues.dismissedNotificationIds ?? [], // kilocode_change morphApiKey: stateValues.morphApiKey, // kilocode_change fastApplyModel: stateValues.fastApplyModel ?? "auto", // kilocode_change: Fast Apply model selection + fastApplyApiProvider: stateValues.fastApplyApiProvider ?? "-", // kilocode_change: Fast Apply model api config id historyPreviewCollapsed: stateValues.historyPreviewCollapsed ?? false, reasoningBlockCollapsed: stateValues.reasoningBlockCollapsed ?? true, cloudUserInfo, @@ -3062,6 +3065,7 @@ ${prompt} morphFastApply: Boolean(experiments.morphFastApply), morphApiKey: Boolean(this.contextProxy.getValue("morphApiKey")), selectedModel: this.contextProxy.getValue("fastApplyModel") || "auto", + fastApplyApiProvider: this.contextProxy.getValue("fastApplyApiProvider") || "-", }, } } catch (error) { diff --git a/src/core/webview/webviewMessageHandler.ts b/src/core/webview/webviewMessageHandler.ts index 48199607afe..4bcb87ae972 100644 --- a/src/core/webview/webviewMessageHandler.ts +++ b/src/core/webview/webviewMessageHandler.ts @@ -1471,6 +1471,11 @@ export const webviewMessageHandler = async ( await provider.postStateToWebview() break } + case "fastApplyApiProvider": { + await updateGlobalState("fastApplyApiProvider", message.text ?? "-") + await provider.postStateToWebview() + break + } // kilocode_change end case "updateVSCodeSetting": { const { setting, value } = message diff --git a/src/shared/ExtensionMessage.ts b/src/shared/ExtensionMessage.ts index 7c20c4b9149..df67d472ee8 100644 --- a/src/shared/ExtensionMessage.ts +++ b/src/shared/ExtensionMessage.ts @@ -336,6 +336,7 @@ export type ExtensionState = Pick< | "fuzzyMatchThreshold" | "morphApiKey" // kilocode_change: Morph fast apply - global setting | "fastApplyModel" // kilocode_change: Fast Apply model selection + | "fastApplyApiProvider" // kilocode_change: Fast Apply model api base url // | "experiments" // Optional in GlobalSettings, required here. | "language" // | "telemetrySetting" // Optional in GlobalSettings, required here. diff --git a/src/shared/WebviewMessage.ts b/src/shared/WebviewMessage.ts index 5287a8db938..843ac95457b 100644 --- a/src/shared/WebviewMessage.ts +++ b/src/shared/WebviewMessage.ts @@ -138,6 +138,7 @@ export interface WebviewMessage { | "fuzzyMatchThreshold" | "morphApiKey" // kilocode_change: Morph fast apply - global setting | "fastApplyModel" // kilocode_change: Fast Apply model selection + | "fastApplyApiProvider" // kilocode_change: Fast Apply model api base url | "writeDelayMs" | "diagnosticsEnabled" | "enhancePrompt" diff --git a/webview-ui/src/components/settings/ExperimentalSettings.tsx b/webview-ui/src/components/settings/ExperimentalSettings.tsx index b98fb03e5ec..c6556ee326a 100644 --- a/webview-ui/src/components/settings/ExperimentalSettings.tsx +++ b/webview-ui/src/components/settings/ExperimentalSettings.tsx @@ -24,7 +24,8 @@ type ExperimentalSettingsProps = HTMLAttributes & { // kilocode_change start morphApiKey?: string fastApplyModel?: string - setCachedStateField: SetCachedStateField<"morphApiKey" | "fastApplyModel"> + fastApplyApiProvider?: string + setCachedStateField: SetCachedStateField<"morphApiKey" | "fastApplyModel" | "fastApplyApiProvider"> kiloCodeImageApiKey?: string setKiloCodeImageApiKey?: (apiKey: string) => void currentProfileKilocodeToken?: string @@ -50,6 +51,7 @@ export const ExperimentalSettings = ({ // kilocode_change start morphApiKey, fastApplyModel, // kilocode_change: Fast Apply model selection + fastApplyApiProvider, // kilocode_change: Fast Apply model api base url setCachedStateField, setKiloCodeImageApiKey, kiloCodeImageApiKey, @@ -107,6 +109,7 @@ export const ExperimentalSettings = ({ setCachedStateField={setCachedStateField} morphApiKey={morphApiKey} fastApplyModel={fastApplyModel} + fastApplyApiProvider={fastApplyApiProvider} /> )} diff --git a/webview-ui/src/components/settings/FastApplySettings.tsx b/webview-ui/src/components/settings/FastApplySettings.tsx index 4743d6e10fb..e40e510a74d 100644 --- a/webview-ui/src/components/settings/FastApplySettings.tsx +++ b/webview-ui/src/components/settings/FastApplySettings.tsx @@ -6,15 +6,39 @@ import { SetCachedStateField } from "./types" export const FastApplySettings = ({ morphApiKey, fastApplyModel, + fastApplyApiProvider, setCachedStateField, }: { morphApiKey?: string fastApplyModel?: string - setCachedStateField: SetCachedStateField<"morphApiKey" | "fastApplyModel"> + fastApplyApiProvider?: string + setCachedStateField: SetCachedStateField<"morphApiKey" | "fastApplyModel" | "fastApplyApiProvider"> }) => { const { t } = useAppTranslation() return (
+
+ + setCachedStateField("fastApplyApiProvider", (e.target as any)?.value || "-")} + className="w-full"> + + Kilo Code + + + OpenRouter + + + Morph + + + Use Current Configuration + + +
- setCachedStateField("morphApiKey", (e.target as any)?.value || "")} - className="w-full"> - {t("settings:experimental.MORPH_FAST_APPLY.apiKey")} - + {fastApplyApiProvider !== "-" && ( + setCachedStateField("morphApiKey", (e.target as any)?.value || "")} + className="w-full"> + {t("settings:experimental.MORPH_FAST_APPLY.apiKey")} + + )}
) } diff --git a/webview-ui/src/components/settings/SettingsView.tsx b/webview-ui/src/components/settings/SettingsView.tsx index e9d7e39231e..b90a47a80a7 100644 --- a/webview-ui/src/components/settings/SettingsView.tsx +++ b/webview-ui/src/components/settings/SettingsView.tsx @@ -183,6 +183,7 @@ const SettingsView = forwardRef(({ onDone, t experiments, morphApiKey, // kilocode_change fastApplyModel, // kilocode_change: Fast Apply model selection + fastApplyApiProvider, // kilocode_change: Fast Apply model api base url fuzzyMatchThreshold, maxOpenTabsContext, maxWorkspaceFiles, @@ -478,6 +479,7 @@ const SettingsView = forwardRef(({ onDone, t vscode.postMessage({ type: "ghostServiceSettings", values: ghostServiceSettings }) // kilocode_change vscode.postMessage({ type: "morphApiKey", text: morphApiKey }) // kilocode_change vscode.postMessage({ type: "fastApplyModel", text: fastApplyModel }) // kilocode_change: Fast Apply model selection + vscode.postMessage({ type: "fastApplyApiProvider", text: fastApplyApiProvider }) // kilocode_change: Fast Apply model api base url vscode.postMessage({ type: "openRouterImageApiKey", text: openRouterImageApiKey }) vscode.postMessage({ type: "kiloCodeImageApiKey", text: kiloCodeImageApiKey }) vscode.postMessage({ @@ -950,6 +952,7 @@ const SettingsView = forwardRef(({ onDone, t setCachedStateField={setCachedStateField} morphApiKey={morphApiKey} fastApplyModel={fastApplyModel} + fastApplyApiProvider={fastApplyApiProvider} // kilocode_change end apiConfiguration={apiConfiguration} setApiConfigurationField={setApiConfigurationField}