Skip to content

Commit 0990290

Browse files
committed
Persist anthropicThinking
1 parent 849f8bf commit 0990290

File tree

5 files changed

+55
-35
lines changed

5 files changed

+55
-35
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type GlobalStateKey =
8989
| "lmStudioModelId"
9090
| "lmStudioBaseUrl"
9191
| "anthropicBaseUrl"
92+
| "anthropicThinking"
9293
| "azureApiVersion"
9394
| "openAiStreamingEnabled"
9495
| "openRouterModelId"
@@ -1654,6 +1655,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
16541655
lmStudioModelId,
16551656
lmStudioBaseUrl,
16561657
anthropicBaseUrl,
1658+
anthropicThinking,
16571659
geminiApiKey,
16581660
openAiNativeApiKey,
16591661
deepSeekApiKey,
@@ -1701,6 +1703,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
17011703
this.updateGlobalState("lmStudioModelId", lmStudioModelId),
17021704
this.updateGlobalState("lmStudioBaseUrl", lmStudioBaseUrl),
17031705
this.updateGlobalState("anthropicBaseUrl", anthropicBaseUrl),
1706+
this.updateGlobalState("anthropicThinking", anthropicThinking),
17041707
this.storeSecret("geminiApiKey", geminiApiKey),
17051708
this.storeSecret("openAiNativeApiKey", openAiNativeApiKey),
17061709
this.storeSecret("deepSeekApiKey", deepSeekApiKey),
@@ -2510,6 +2513,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
25102513
lmStudioModelId,
25112514
lmStudioBaseUrl,
25122515
anthropicBaseUrl,
2516+
anthropicThinking,
25132517
geminiApiKey,
25142518
openAiNativeApiKey,
25152519
deepSeekApiKey,
@@ -2592,6 +2596,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
25922596
this.getGlobalState("lmStudioModelId") as Promise<string | undefined>,
25932597
this.getGlobalState("lmStudioBaseUrl") as Promise<string | undefined>,
25942598
this.getGlobalState("anthropicBaseUrl") as Promise<string | undefined>,
2599+
this.getGlobalState("anthropicThinking") as Promise<number | undefined>,
25952600
this.getSecret("geminiApiKey") as Promise<string | undefined>,
25962601
this.getSecret("openAiNativeApiKey") as Promise<string | undefined>,
25972602
this.getSecret("deepSeekApiKey") as Promise<string | undefined>,
@@ -2691,6 +2696,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
26912696
lmStudioModelId,
26922697
lmStudioBaseUrl,
26932698
anthropicBaseUrl,
2699+
anthropicThinking,
26942700
geminiApiKey,
26952701
openAiNativeApiKey,
26962702
deepSeekApiKey,

src/shared/__tests__/checkExistApiConfig.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe("checkExistKey", () => {
3232
apiKey: "test-key",
3333
apiProvider: undefined,
3434
anthropicBaseUrl: undefined,
35+
anthropicThinking: undefined,
3536
}
3637
expect(checkExistKey(config)).toBe(true)
3738
})

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import { memo, useCallback, useMemo, useState } from "react"
22
import { useDebounce, useEvent } from "react-use"
33
import { Checkbox, Dropdown, Pane, type DropdownOption } from "vscrui"
44
import { VSCodeLink, VSCodeRadio, VSCodeRadioGroup, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
5-
import { TemperatureControl } from "./TemperatureControl"
65
import * as vscodemodels from "vscode"
76

7+
import { Slider } from "@/components/ui"
8+
89
import {
910
ApiConfiguration,
1011
ModelInfo,
@@ -34,6 +35,7 @@ import {
3435
requestyDefaultModelInfo,
3536
} from "../../../../src/shared/api"
3637
import { ExtensionMessage } from "../../../../src/shared/ExtensionMessage"
38+
3739
import { vscode } from "../../utils/vscode"
3840
import VSCodeButtonLink from "../common/VSCodeButtonLink"
3941
import { OpenRouterModelPicker } from "./OpenRouterModelPicker"
@@ -43,7 +45,7 @@ import { UnboundModelPicker } from "./UnboundModelPicker"
4345
import { ModelInfoView } from "./ModelInfoView"
4446
import { DROPDOWN_Z_INDEX } from "./styles"
4547
import { RequestyModelPicker } from "./RequestyModelPicker"
46-
import { Slider } from "../ui"
48+
import { TemperatureControl } from "./TemperatureControl"
4749

4850
interface ApiOptionsProps {
4951
uriScheme: string | undefined
@@ -66,8 +68,7 @@ const ApiOptions = ({
6668
const [lmStudioModels, setLmStudioModels] = useState<string[]>([])
6769
const [vsCodeLmModels, setVsCodeLmModels] = useState<vscodemodels.LanguageModelChatSelector[]>([])
6870
const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(!!apiConfiguration?.anthropicBaseUrl)
69-
const [anthropicThinkingEnabled, setAnthropicThinkingEnabled] = useState(!!apiConfiguration?.anthropicThinking)
70-
const [anthropicThinkingBudget, setAnthropicThinkingBudget] = useState(apiConfiguration?.anthropicThinking ?? 1024)
71+
const [anthropicThinkingBudget, setAnthropicThinkingBudget] = useState(apiConfiguration?.anthropicThinking)
7172
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion)
7273
const [openRouterBaseUrlSelected, setOpenRouterBaseUrlSelected] = useState(!!apiConfiguration?.openRouterBaseUrl)
7374
const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false)
@@ -188,6 +189,7 @@ const ApiOptions = ({
188189
checked={anthropicBaseUrlSelected}
189190
onChange={(checked: boolean) => {
190191
setAnthropicBaseUrlSelected(checked)
192+
191193
if (!checked) {
192194
setApiConfigurationField("anthropicBaseUrl", "")
193195
}
@@ -387,6 +389,7 @@ const ApiOptions = ({
387389
checked={openRouterBaseUrlSelected}
388390
onChange={(checked: boolean) => {
389391
setOpenRouterBaseUrlSelected(checked)
392+
390393
if (!checked) {
391394
setApiConfigurationField("openRouterBaseUrl", "")
392395
}
@@ -510,7 +513,7 @@ const ApiOptions = ({
510513
</div>
511514
)}
512515

513-
{apiConfiguration?.apiProvider === "vertex" && (
516+
{selectedProvider === "vertex" && (
514517
<div style={{ display: "flex", flexDirection: "column", gap: 5 }}>
515518
<VSCodeTextField
516519
value={apiConfiguration?.vertexProjectId || ""}
@@ -624,6 +627,7 @@ const ApiOptions = ({
624627
checked={azureApiVersionSelected}
625628
onChange={(checked: boolean) => {
626629
setAzureApiVersionSelected(checked)
630+
627631
if (!checked) {
628632
setApiConfigurationField("azureApiVersion", "")
629633
}
@@ -1260,23 +1264,33 @@ const ApiOptions = ({
12601264
</>
12611265
)}
12621266

1263-
{selectedProvider === "anthropic" && (
1267+
{selectedProvider === "anthropic" && selectedModelId === "claude-3-7-sonnet-20250219" && (
12641268
<div className="flex flex-col gap-2 mt-2">
1265-
<Checkbox checked={anthropicThinkingEnabled} onChange={setAnthropicThinkingEnabled}>
1269+
<Checkbox
1270+
checked={!!anthropicThinkingBudget}
1271+
onChange={(checked) => {
1272+
const budget = checked ? 16_384 : undefined
1273+
setAnthropicThinkingBudget(budget)
1274+
setApiConfigurationField("anthropicThinking", budget)
1275+
}}>
12661276
Thinking?
12671277
</Checkbox>
1268-
{anthropicThinkingEnabled && (
1278+
{anthropicThinkingBudget && (
12691279
<>
12701280
<div className="text-muted-foreground text-sm">
1271-
Number of tokens Claude is allowed use for its internal reasoning process
1281+
Number of tokens Claude is allowed use for its internal reasoning process.
12721282
</div>
12731283
<div className="flex items-center gap-2">
12741284
<Slider
12751285
min={1024}
1276-
max={6399}
1277-
step={100}
1286+
max={anthropicModels["claude-3-7-sonnet-20250219"].maxTokens - 1}
1287+
step={1024}
12781288
value={[anthropicThinkingBudget]}
1279-
onValueChange={(value) => setAnthropicThinkingBudget(value[0])}
1289+
onValueChange={(value) => {
1290+
const budget = value[0]
1291+
setAnthropicThinkingBudget(budget)
1292+
setApiConfigurationField("anthropicThinking", budget)
1293+
}}
12801294
/>
12811295
<div className="w-10">{anthropicThinkingBudget}</div>
12821296
</div>

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
1-
import { VSCodeButton, VSCodeCheckbox, VSCodeLink, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
21
import { forwardRef, memo, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react"
3-
import { ExtensionStateContextType, useExtensionState } from "../../context/ExtensionStateContext"
4-
import { validateApiConfiguration, validateModelId } from "../../utils/validate"
5-
import { vscode } from "../../utils/vscode"
6-
import ApiOptions from "./ApiOptions"
7-
import ExperimentalFeature from "./ExperimentalFeature"
8-
import { EXPERIMENT_IDS, experimentConfigsMap, ExperimentId } from "../../../../src/shared/experiments"
9-
import ApiConfigManager from "./ApiConfigManager"
10-
import { Dropdown } from "vscrui"
11-
import type { DropdownOption } from "vscrui"
12-
import { ApiConfiguration } from "../../../../src/shared/api"
2+
import { VSCodeButton, VSCodeCheckbox, VSCodeLink, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
3+
import { Dropdown, type DropdownOption } from "vscrui"
4+
135
import {
146
AlertDialog,
157
AlertDialogContent,
@@ -19,7 +11,17 @@ import {
1911
AlertDialogAction,
2012
AlertDialogHeader,
2113
AlertDialogFooter,
22-
} from "../ui/alert-dialog"
14+
} from "@/components/ui"
15+
16+
import { vscode } from "../../utils/vscode"
17+
import { validateApiConfiguration, validateModelId } from "../../utils/validate"
18+
import { ExtensionStateContextType, useExtensionState } from "../../context/ExtensionStateContext"
19+
import { EXPERIMENT_IDS, experimentConfigsMap, ExperimentId } from "../../../../src/shared/experiments"
20+
import { ApiConfiguration } from "../../../../src/shared/api"
21+
22+
import ExperimentalFeature from "./ExperimentalFeature"
23+
import ApiConfigManager from "./ApiConfigManager"
24+
import ApiOptions from "./ApiOptions"
2325

2426
type SettingsViewProps = {
2527
onDone: () => void
@@ -104,7 +106,9 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },
104106
if (prevState.apiConfiguration?.[field] === value) {
105107
return prevState
106108
}
109+
107110
setChangeDetected(true)
111+
108112
return {
109113
...prevState,
110114
apiConfiguration: {
@@ -131,7 +135,9 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },
131135
}, [])
132136

133137
const handleSubmit = () => {
138+
console.log("handleSubmit", apiConfiguration)
134139
const apiValidationResult = validateApiConfiguration(apiConfiguration)
140+
135141
const modelIdValidationResult = validateModelId(
136142
apiConfiguration,
137143
extensionState.glamaModels,
@@ -140,6 +146,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },
140146

141147
setApiErrorMessage(apiValidationResult)
142148
setModelIdErrorMessage(modelIdValidationResult)
149+
143150
if (!apiValidationResult && !modelIdValidationResult) {
144151
vscode.postMessage({ type: "alwaysAllowReadOnly", bool: alwaysAllowReadOnly })
145152
vscode.postMessage({ type: "alwaysAllowWrite", bool: alwaysAllowWrite })
@@ -162,18 +169,9 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },
162169
vscode.postMessage({ type: "rateLimitSeconds", value: rateLimitSeconds })
163170
vscode.postMessage({ type: "maxOpenTabsContext", value: maxOpenTabsContext })
164171
vscode.postMessage({ type: "currentApiConfigName", text: currentApiConfigName })
165-
vscode.postMessage({
166-
type: "updateExperimental",
167-
values: experiments,
168-
})
172+
vscode.postMessage({ type: "updateExperimental", values: experiments })
169173
vscode.postMessage({ type: "alwaysAllowModeSwitch", bool: alwaysAllowModeSwitch })
170-
171-
vscode.postMessage({
172-
type: "upsertApiConfiguration",
173-
text: currentApiConfigName,
174-
apiConfiguration,
175-
})
176-
// onDone()
174+
vscode.postMessage({ type: "upsertApiConfiguration", text: currentApiConfigName, apiConfiguration })
177175
setChangeDetected(false)
178176
}
179177
}

webview-ui/src/components/ui/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from "./alert-dialog"
12
export * from "./autosize-textarea"
23
export * from "./badge"
34
export * from "./button"

0 commit comments

Comments
 (0)