chore: Prettier fix formatting

This commit is contained in:
Saoud Rizwan committed 2025-01-06 12:41:33 -08:00
1 parent 9de7253998
commit 25cd7cc8e2
106 files changed
+1624 -5278

No files matched your search

+104 -279
View File
@@ -7,14 +7,7 @@ import {
VSCodeRadioGroup,
VSCodeTextField,
} from "@vscode/webview-ui-toolkit/react"
import {
Fragment,
memo,
useCallback,
useEffect,
useMemo,
useState,
} from "react"
import { Fragment, memo, useCallback, useEffect, useMemo, useState } from "react"
import { useEvent, useInterval } from "react-use"
import {
ApiConfiguration,
@@ -40,10 +33,7 @@ import { ExtensionMessage } from "../../../../src/shared/ExtensionMessage"
import { useExtensionState } from "../../context/ExtensionStateContext"
import { vscode } from "../../utils/vscode"
import VSCodeButtonLink from "../common/VSCodeButtonLink"
import OpenRouterModelPicker, {
ModelDescriptionMarkdown,
OPENROUTER_MODEL_PICKER_Z_INDEX,
} from "./OpenRouterModelPicker"
import OpenRouterModelPicker, { ModelDescriptionMarkdown, OPENROUTER_MODEL_PICKER_Z_INDEX } from "./OpenRouterModelPicker"
interface ApiOptionsProps {
showModelOptions: boolean
@@ -51,35 +41,24 @@ interface ApiOptionsProps {
modelIdErrorMessage?: string
}
const ApiOptions = ({
showModelOptions,
apiErrorMessage,
modelIdErrorMessage,
}: ApiOptionsProps) => {
const { apiConfiguration, setApiConfiguration, uriScheme } =
useExtensionState()
const ApiOptions = ({ showModelOptions, apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) => {
const { apiConfiguration, setApiConfiguration, uriScheme } = useExtensionState()
const [ollamaModels, setOllamaModels] = useState<string[]>([])
const [lmStudioModels, setLmStudioModels] = useState<string[]>([])
const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(
!!apiConfiguration?.anthropicBaseUrl,
)
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(
!!apiConfiguration?.azureApiVersion,
)
const [anthropicBaseUrlSelected, setAnthropicBaseUrlSelected] = useState(!!apiConfiguration?.anthropicBaseUrl)
const [azureApiVersionSelected, setAzureApiVersionSelected] = useState(!!apiConfiguration?.azureApiVersion)
const [isDescriptionExpanded, setIsDescriptionExpanded] = useState(false)
const handleInputChange =
(field: keyof ApiConfiguration) => (event: any) => {
setApiConfiguration({
...apiConfiguration,
[field]: event.target.value,
})
}
const handleInputChange = (field: keyof ApiConfiguration) => (event: any) => {
setApiConfiguration({
...apiConfiguration,
[field]: event.target.value,
})
}
const { selectedProvider, selectedModelId, selectedModelInfo } =
useMemo(() => {
return normalizeApiConfiguration(apiConfiguration)
}, [apiConfiguration])
const { selectedProvider, selectedModelId, selectedModelInfo } = useMemo(() => {
return normalizeApiConfiguration(apiConfiguration)
}, [apiConfiguration])
// Poll ollama/lmstudio models
const requestLocalModels = useCallback(() => {
@@ -94,31 +73,19 @@ const ApiOptions = ({
text: apiConfiguration?.lmStudioBaseUrl,
})
}
}, [
selectedProvider,
apiConfiguration?.ollamaBaseUrl,
apiConfiguration?.lmStudioBaseUrl,
])
}, [selectedProvider, apiConfiguration?.ollamaBaseUrl, apiConfiguration?.lmStudioBaseUrl])
useEffect(() => {
if (selectedProvider === "ollama" || selectedProvider === "lmstudio") {
requestLocalModels()
}
}, [selectedProvider, requestLocalModels])
useInterval(
requestLocalModels,
selectedProvider === "ollama" || selectedProvider === "lmstudio"
? 2000
: null,
)
useInterval(requestLocalModels, selectedProvider === "ollama" || selectedProvider === "lmstudio" ? 2000 : null)
const handleMessage = useCallback((event: MessageEvent) => {
const message: ExtensionMessage = event.data
if (message.type === "ollamaModels" && message.ollamaModels) {
setOllamaModels(message.ollamaModels)
} else if (
message.type === "lmStudioModels" &&
message.lmStudioModels
) {
} else if (message.type === "lmStudioModels" && message.lmStudioModels) {
setLmStudioModels(message.lmStudioModels)
}
}, [])
@@ -178,9 +145,7 @@ const ApiOptions = ({
<VSCodeOption value="vertex">GCP Vertex AI</VSCodeOption>
<VSCodeOption value="bedrock">AWS Bedrock</VSCodeOption>
<VSCodeOption value="openai-native">OpenAI</VSCodeOption>
<VSCodeOption value="openai">
OpenAI Compatible
</VSCodeOption>
<VSCodeOption value="openai">OpenAI Compatible</VSCodeOption>
<VSCodeOption value="lmstudio">LM Studio</VSCodeOption>
<VSCodeOption value="ollama">Ollama</VSCodeOption>
</VSCodeDropdown>
@@ -194,9 +159,7 @@ const ApiOptions = ({
type="password"
onInput={handleInputChange("apiKey")}
placeholder="Enter API Key...">
<span style={{ fontWeight: 500 }}>
Anthropic API Key
</span>
<span style={{ fontWeight: 500 }}>Anthropic API Key</span>
</VSCodeTextField>
<VSCodeCheckbox
@@ -230,8 +193,7 @@ const ApiOptions = ({
marginTop: 3,
color: "var(--vscode-descriptionForeground)",
}}>
This key is stored locally and only used to make API
requests from this extension.
This key is stored locally and only used to make API requests from this extension.
{!apiConfiguration?.apiKey && (
<VSCodeLink
href="https://console.anthropic.com/settings/keys"
@@ -239,8 +201,7 @@ const ApiOptions = ({
display: "inline",
fontSize: "inherit",
}}>
You can get an Anthropic API key by signing up
here.
You can get an Anthropic API key by signing up here.
</VSCodeLink>
)}
</p>
@@ -263,8 +224,7 @@ const ApiOptions = ({
marginTop: 3,
color: "var(--vscode-descriptionForeground)",
}}>
This key is stored locally and only used to make API
requests from this extension.
This key is stored locally and only used to make API requests from this extension.
{!apiConfiguration?.openAiNativeApiKey && (
<VSCodeLink
href="https://platform.openai.com/api-keys"
@@ -272,8 +232,7 @@ const ApiOptions = ({
display: "inline",
fontSize: "inherit",
}}>
You can get an OpenAI API key by signing up
here.
You can get an OpenAI API key by signing up here.
</VSCodeLink>
)}
</p>
@@ -288,9 +247,7 @@ const ApiOptions = ({
type="password"
onInput={handleInputChange("deepSeekApiKey")}
placeholder="Enter API Key...">
<span style={{ fontWeight: 500 }}>
DeepSeek API Key
</span>
<span style={{ fontWeight: 500 }}>DeepSeek API Key</span>
</VSCodeTextField>
<p
style={{
@@ -298,8 +255,7 @@ const ApiOptions = ({
marginTop: 3,
color: "var(--vscode-descriptionForeground)",
}}>
This key is stored locally and only used to make API
requests from this extension.
This key is stored locally and only used to make API requests from this extension.
{!apiConfiguration?.deepSeekApiKey && (
<VSCodeLink
href="https://www.deepseek.com/"
@@ -307,8 +263,7 @@ const ApiOptions = ({
display: "inline",
fontSize: "inherit",
}}>
You can get a DeepSeek API key by signing up
here.
You can get a DeepSeek API key by signing up here.
</VSCodeLink>
)}
</p>
@@ -323,9 +278,7 @@ const ApiOptions = ({
type="password"
onInput={handleInputChange("openRouterApiKey")}
placeholder="Enter API Key...">
<span style={{ fontWeight: 500 }}>
OpenRouter API Key
</span>
<span style={{ fontWeight: 500 }}>OpenRouter API Key</span>
</VSCodeTextField>
{!apiConfiguration?.openRouterApiKey && (
<VSCodeButtonLink
@@ -341,8 +294,7 @@ const ApiOptions = ({
marginTop: "5px",
color: "var(--vscode-descriptionForeground)",
}}>
This key is stored locally and only used to make API
requests from this extension.{" "}
This key is stored locally and only used to make API requests from this extension.{" "}
{/* {!apiConfiguration?.openRouterApiKey && (
<span style={{ color: "var(--vscode-charts-green)" }}>
(<span style={{ fontWeight: 500 }}>Note:</span> OpenRouter is recommended for high rate
@@ -382,9 +334,7 @@ const ApiOptions = ({
type="password"
onInput={handleInputChange("awsSessionToken")}
placeholder="Enter Session Token...">
<span style={{ fontWeight: 500 }}>
AWS Session Token
</span>
<span style={{ fontWeight: 500 }}>AWS Session Token</span>
</VSCodeTextField>
<div className="dropdown-container">
<label htmlFor="aws-region-dropdown">
@@ -395,75 +345,36 @@ const ApiOptions = ({
value={apiConfiguration?.awsRegion || ""}
style={{ width: "100%" }}
onChange={handleInputChange("awsRegion")}>
<VSCodeOption value="">
Select a region...
</VSCodeOption>
<VSCodeOption value="">Select a region...</VSCodeOption>
{/* The user will have to choose a region that supports the model they use, but this shouldn't be a problem since they'd have to request access for it in that region in the first place. */}
<VSCodeOption value="us-east-1">
us-east-1
</VSCodeOption>
<VSCodeOption value="us-east-2">
us-east-2
</VSCodeOption>
<VSCodeOption value="us-east-1">us-east-1</VSCodeOption>
<VSCodeOption value="us-east-2">us-east-2</VSCodeOption>
{/* <VSCodeOption value="us-west-1">us-west-1</VSCodeOption> */}
<VSCodeOption value="us-west-2">
us-west-2
</VSCodeOption>
<VSCodeOption value="us-west-2">us-west-2</VSCodeOption>
{/* <VSCodeOption value="af-south-1">af-south-1</VSCodeOption> */}
{/* <VSCodeOption value="ap-east-1">ap-east-1</VSCodeOption> */}
<VSCodeOption value="ap-south-1">
ap-south-1
</VSCodeOption>
<VSCodeOption value="ap-northeast-1">
ap-northeast-1
</VSCodeOption>
<VSCodeOption value="ap-northeast-2">
ap-northeast-2
</VSCodeOption>
<VSCodeOption value="ap-south-1">ap-south-1</VSCodeOption>
<VSCodeOption value="ap-northeast-1">ap-northeast-1</VSCodeOption>
<VSCodeOption value="ap-northeast-2">ap-northeast-2</VSCodeOption>
{/* <VSCodeOption value="ap-northeast-3">ap-northeast-3</VSCodeOption> */}
<VSCodeOption value="ap-southeast-1">
ap-southeast-1
</VSCodeOption>
<VSCodeOption value="ap-southeast-2">
ap-southeast-2
</VSCodeOption>
<VSCodeOption value="ca-central-1">
ca-central-1
</VSCodeOption>
<VSCodeOption value="eu-central-1">
eu-central-1
</VSCodeOption>
<VSCodeOption value="eu-central-2">
eu-central-2
</VSCodeOption>
<VSCodeOption value="eu-west-1">
eu-west-1
</VSCodeOption>
<VSCodeOption value="eu-west-2">
eu-west-2
</VSCodeOption>
<VSCodeOption value="eu-west-3">
eu-west-3
</VSCodeOption>
<VSCodeOption value="ap-southeast-1">ap-southeast-1</VSCodeOption>
<VSCodeOption value="ap-southeast-2">ap-southeast-2</VSCodeOption>
<VSCodeOption value="ca-central-1">ca-central-1</VSCodeOption>
<VSCodeOption value="eu-central-1">eu-central-1</VSCodeOption>
<VSCodeOption value="eu-central-2">eu-central-2</VSCodeOption>
<VSCodeOption value="eu-west-1">eu-west-1</VSCodeOption>
<VSCodeOption value="eu-west-2">eu-west-2</VSCodeOption>
<VSCodeOption value="eu-west-3">eu-west-3</VSCodeOption>
{/* <VSCodeOption value="eu-north-1">eu-north-1</VSCodeOption> */}
{/* <VSCodeOption value="me-south-1">me-south-1</VSCodeOption> */}
<VSCodeOption value="sa-east-1">
sa-east-1
</VSCodeOption>
<VSCodeOption value="us-gov-east-1">
us-gov-east-1
</VSCodeOption>
<VSCodeOption value="us-gov-west-1">
us-gov-west-1
</VSCodeOption>
<VSCodeOption value="sa-east-1">sa-east-1</VSCodeOption>
<VSCodeOption value="us-gov-east-1">us-gov-east-1</VSCodeOption>
<VSCodeOption value="us-gov-west-1">us-gov-west-1</VSCodeOption>
{/* <VSCodeOption value="us-gov-east-1">us-gov-east-1</VSCodeOption> */}
</VSCodeDropdown>
</div>
<VSCodeCheckbox
checked={
apiConfiguration?.awsUseCrossRegionInference ||
false
}
checked={apiConfiguration?.awsUseCrossRegionInference || false}
onChange={(e: any) => {
const isChecked = e.target.checked === true
setApiConfiguration({
@@ -479,10 +390,8 @@ const ApiOptions = ({
marginTop: "5px",
color: "var(--vscode-descriptionForeground)",
}}>
Authenticate by either providing the keys above or use
the default AWS credential providers, i.e.
~/.aws/credentials or environment variables. These
credentials are only used locally to make API requests
Authenticate by either providing the keys above or use the default AWS credential providers, i.e.
~/.aws/credentials or environment variables. These credentials are only used locally to make API requests
from this extension.
</p>
</div>
@@ -500,39 +409,23 @@ const ApiOptions = ({
style={{ width: "100%" }}
onInput={handleInputChange("vertexProjectId")}
placeholder="Enter Project ID...">
<span style={{ fontWeight: 500 }}>
Google Cloud Project ID
</span>
<span style={{ fontWeight: 500 }}>Google Cloud Project ID</span>
</VSCodeTextField>
<div className="dropdown-container">
<label htmlFor="vertex-region-dropdown">
<span style={{ fontWeight: 500 }}>
Google Cloud Region
</span>
<span style={{ fontWeight: 500 }}>Google Cloud Region</span>
</label>
<VSCodeDropdown
id="vertex-region-dropdown"
value={apiConfiguration?.vertexRegion || ""}
style={{ width: "100%" }}
onChange={handleInputChange("vertexRegion")}>
<VSCodeOption value="">
Select a region...
</VSCodeOption>
<VSCodeOption value="us-east5">
us-east5
</VSCodeOption>
<VSCodeOption value="us-central1">
us-central1
</VSCodeOption>
<VSCodeOption value="europe-west1">
europe-west1
</VSCodeOption>
<VSCodeOption value="europe-west4">
europe-west4
</VSCodeOption>
<VSCodeOption value="asia-southeast1">
asia-southeast1
</VSCodeOption>
<VSCodeOption value="">Select a region...</VSCodeOption>
<VSCodeOption value="us-east5">us-east5</VSCodeOption>
<VSCodeOption value="us-central1">us-central1</VSCodeOption>
<VSCodeOption value="europe-west1">europe-west1</VSCodeOption>
<VSCodeOption value="europe-west4">europe-west4</VSCodeOption>
<VSCodeOption value="asia-southeast1">asia-southeast1</VSCodeOption>
</VSCodeDropdown>
</div>
<p
@@ -545,16 +438,12 @@ const ApiOptions = ({
<VSCodeLink
href="https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude#before_you_begin"
style={{ display: "inline", fontSize: "inherit" }}>
{
"1) create a Google Cloud account › enable the Vertex AI API › enable the desired Claude models,"
}
{"1) create a Google Cloud account › enable the Vertex AI API › enable the desired Claude models,"}
</VSCodeLink>{" "}
<VSCodeLink
href="https://cloud.google.com/docs/authentication/provide-credentials-adc#google-idp"
style={{ display: "inline", fontSize: "inherit" }}>
{
"2) install the Google Cloud CLI › configure Application Default Credentials."
}
{"2) install the Google Cloud CLI › configure Application Default Credentials."}
</VSCodeLink>
</p>
</div>
@@ -576,8 +465,7 @@ const ApiOptions = ({
marginTop: 3,
color: "var(--vscode-descriptionForeground)",
}}>
This key is stored locally and only used to make API
requests from this extension.
This key is stored locally and only used to make API requests from this extension.
{!apiConfiguration?.geminiApiKey && (
<VSCodeLink
href="https://ai.google.dev/"
@@ -645,12 +533,9 @@ const ApiOptions = ({
marginTop: 3,
color: "var(--vscode-descriptionForeground)",
}}>
<span
style={{ color: "var(--vscode-errorForeground)" }}>
(<span style={{ fontWeight: 500 }}>Note:</span>{" "}
Cline uses complex prompts and works best with
Claude models. Less capable models may not work as
expected.)
<span style={{ color: "var(--vscode-errorForeground)" }}>
(<span style={{ fontWeight: 500 }}>Note:</span> Cline uses complex prompts and works best with Claude
models. Less capable models may not work as expected.)
</span>
</p>
</div>
@@ -664,9 +549,7 @@ const ApiOptions = ({
type="url"
onInput={handleInputChange("lmStudioBaseUrl")}
placeholder={"Default: http://localhost:1234"}>
<span style={{ fontWeight: 500 }}>
Base URL (optional)
</span>
<span style={{ fontWeight: 500 }}>Base URL (optional)</span>
</VSCodeTextField>
<VSCodeTextField
value={apiConfiguration?.lmStudioModelId || ""}
@@ -678,15 +561,12 @@ const ApiOptions = ({
{lmStudioModels.length > 0 && (
<VSCodeRadioGroup
value={
lmStudioModels.includes(
apiConfiguration?.lmStudioModelId || "",
)
lmStudioModels.includes(apiConfiguration?.lmStudioModelId || "")
? apiConfiguration?.lmStudioModelId
: ""
}
onChange={(e) => {
const value = (e.target as HTMLInputElement)
?.value
const value = (e.target as HTMLInputElement)?.value
// need to check value first since radio group returns empty string sometimes
if (value) {
handleInputChange("lmStudioModelId")({
@@ -695,13 +575,7 @@ const ApiOptions = ({
}
}}>
{lmStudioModels.map((model) => (
<VSCodeRadio
key={model}
value={model}
checked={
apiConfiguration?.lmStudioModelId ===
model
}>
<VSCodeRadio key={model} value={model} checked={apiConfiguration?.lmStudioModelId === model}>
{model}
</VSCodeRadio>
))}
@@ -713,12 +587,9 @@ const ApiOptions = ({
marginTop: "5px",
color: "var(--vscode-descriptionForeground)",
}}>
LM Studio allows you to run models locally on your
computer. For instructions on how to get started, see
LM Studio allows you to run models locally on your computer. For instructions on how to get started, see
their
<VSCodeLink
href="https://lmstudio.ai/docs"
style={{ display: "inline", fontSize: "inherit" }}>
<VSCodeLink href="https://lmstudio.ai/docs" style={{ display: "inline", fontSize: "inherit" }}>
quickstart guide.
</VSCodeLink>
You will also need to start LM Studio's{" "}
@@ -728,12 +599,9 @@ const ApiOptions = ({
local server
</VSCodeLink>{" "}
feature to use it with this extension.{" "}
<span
style={{ color: "var(--vscode-errorForeground)" }}>
(<span style={{ fontWeight: 500 }}>Note:</span>{" "}
Cline uses complex prompts and works best with
Claude models. Less capable models may not work as
expected.)
<span style={{ color: "var(--vscode-errorForeground)" }}>
(<span style={{ fontWeight: 500 }}>Note:</span> Cline uses complex prompts and works best with Claude
models. Less capable models may not work as expected.)
</span>
</p>
</div>
@@ -747,9 +615,7 @@ const ApiOptions = ({
type="url"
onInput={handleInputChange("ollamaBaseUrl")}
placeholder={"Default: http://localhost:11434"}>
<span style={{ fontWeight: 500 }}>
Base URL (optional)
</span>
<span style={{ fontWeight: 500 }}>Base URL (optional)</span>
</VSCodeTextField>
<VSCodeTextField
value={apiConfiguration?.ollamaModelId || ""}
@@ -761,15 +627,12 @@ const ApiOptions = ({
{ollamaModels.length > 0 && (
<VSCodeRadioGroup
value={
ollamaModels.includes(
apiConfiguration?.ollamaModelId || "",
)
ollamaModels.includes(apiConfiguration?.ollamaModelId || "")
? apiConfiguration?.ollamaModelId
: ""
}
onChange={(e) => {
const value = (e.target as HTMLInputElement)
?.value
const value = (e.target as HTMLInputElement)?.value
// need to check value first since radio group returns empty string sometimes
if (value) {
handleInputChange("ollamaModelId")({
@@ -778,13 +641,7 @@ const ApiOptions = ({
}
}}>
{ollamaModels.map((model) => (
<VSCodeRadio
key={model}
value={model}
checked={
apiConfiguration?.ollamaModelId ===
model
}>
<VSCodeRadio key={model} value={model} checked={apiConfiguration?.ollamaModelId === model}>
{model}
</VSCodeRadio>
))}
@@ -796,20 +653,16 @@ const ApiOptions = ({
marginTop: "5px",
color: "var(--vscode-descriptionForeground)",
}}>
Ollama allows you to run models locally on your
computer. For instructions on how to get started, see
Ollama allows you to run models locally on your computer. For instructions on how to get started, see
their
<VSCodeLink
href="https://github.com/ollama/ollama/blob/main/README.md"
style={{ display: "inline", fontSize: "inherit" }}>
quickstart guide.
</VSCodeLink>
<span
style={{ color: "var(--vscode-errorForeground)" }}>
(<span style={{ fontWeight: 500 }}>Note:</span>{" "}
Cline uses complex prompts and works best with
Claude models. Less capable models may not work as
expected.)
<span style={{ color: "var(--vscode-errorForeground)" }}>
(<span style={{ fontWeight: 500 }}>Note:</span> Cline uses complex prompts and works best with Claude
models. Less capable models may not work as expected.)
</span>
</p>
</div>
@@ -826,9 +679,7 @@ const ApiOptions = ({
</p>
)}
{selectedProvider === "openrouter" && showModelOptions && (
<OpenRouterModelPicker />
)}
{selectedProvider === "openrouter" && showModelOptions && <OpenRouterModelPicker />}
{selectedProvider !== "openrouter" &&
selectedProvider !== "openai" &&
@@ -840,18 +691,12 @@ const ApiOptions = ({
<label htmlFor="model-id">
<span style={{ fontWeight: 500 }}>Model</span>
</label>
{selectedProvider === "anthropic" &&
createDropdown(anthropicModels)}
{selectedProvider === "bedrock" &&
createDropdown(bedrockModels)}
{selectedProvider === "vertex" &&
createDropdown(vertexModels)}
{selectedProvider === "gemini" &&
createDropdown(geminiModels)}
{selectedProvider === "openai-native" &&
createDropdown(openAiNativeModels)}
{selectedProvider === "deepseek" &&
createDropdown(deepSeekModels)}
{selectedProvider === "anthropic" && createDropdown(anthropicModels)}
{selectedProvider === "bedrock" && createDropdown(bedrockModels)}
{selectedProvider === "vertex" && createDropdown(vertexModels)}
{selectedProvider === "gemini" && createDropdown(geminiModels)}
{selectedProvider === "openai-native" && createDropdown(openAiNativeModels)}
{selectedProvider === "deepseek" && createDropdown(deepSeekModels)}
</div>
<ModelInfoView
@@ -934,44 +779,36 @@ export const ModelInfoView = ({
),
modelInfo.maxTokens !== undefined && modelInfo.maxTokens > 0 && (
<span key="maxTokens">
<span style={{ fontWeight: 500 }}>Max output:</span>{" "}
{modelInfo.maxTokens?.toLocaleString()} tokens
<span style={{ fontWeight: 500 }}>Max output:</span> {modelInfo.maxTokens?.toLocaleString()} tokens
</span>
),
modelInfo.inputPrice !== undefined && modelInfo.inputPrice > 0 && (
<span key="inputPrice">
<span style={{ fontWeight: 500 }}>Input price:</span>{" "}
{formatPrice(modelInfo.inputPrice)}/million tokens
<span style={{ fontWeight: 500 }}>Input price:</span> {formatPrice(modelInfo.inputPrice)}/million tokens
</span>
),
modelInfo.supportsPromptCache && modelInfo.cacheWritesPrice && (
<span key="cacheWritesPrice">
<span style={{ fontWeight: 500 }}>Cache writes price:</span>{" "}
{formatPrice(modelInfo.cacheWritesPrice || 0)}/million tokens
<span style={{ fontWeight: 500 }}>Cache writes price:</span> {formatPrice(modelInfo.cacheWritesPrice || 0)}
/million tokens
</span>
),
modelInfo.supportsPromptCache && modelInfo.cacheReadsPrice && (
<span key="cacheReadsPrice">
<span style={{ fontWeight: 500 }}>Cache reads price:</span>{" "}
{formatPrice(modelInfo.cacheReadsPrice || 0)}/million tokens
<span style={{ fontWeight: 500 }}>Cache reads price:</span> {formatPrice(modelInfo.cacheReadsPrice || 0)}/million
tokens
</span>
),
modelInfo.outputPrice !== undefined && modelInfo.outputPrice > 0 && (
<span key="outputPrice">
<span style={{ fontWeight: 500 }}>Output price:</span>{" "}
{formatPrice(modelInfo.outputPrice)}/million tokens
<span style={{ fontWeight: 500 }}>Output price:</span> {formatPrice(modelInfo.outputPrice)}/million tokens
</span>
),
isGemini && (
<span key="geminiInfo" style={{ fontStyle: "italic" }}>
* Free up to{" "}
{selectedModelId && selectedModelId.includes("flash")
? "15"
: "2"}{" "}
requests per minute. After that, billing depends on prompt size.{" "}
<VSCodeLink
href="https://ai.google.dev/pricing"
style={{ display: "inline", fontSize: "inherit" }}>
* Free up to {selectedModelId && selectedModelId.includes("flash") ? "15" : "2"} requests per minute. After that,
billing depends on prompt size.{" "}
<VSCodeLink href="https://ai.google.dev/pricing" style={{ display: "inline", fontSize: "inherit" }}>
For more info, see pricing details.
</VSCodeLink>
</span>
@@ -1007,9 +844,7 @@ const ModelInfoSupportsItem = ({
<span
style={{
fontWeight: 500,
color: isSupported
? "var(--vscode-charts-green)"
: "var(--vscode-errorForeground)",
color: isSupported ? "var(--vscode-charts-green)" : "var(--vscode-errorForeground)",
}}>
<i
className={`codicon codicon-${isSupported ? "check" : "x"}`}
@@ -1029,10 +864,7 @@ export function normalizeApiConfiguration(apiConfiguration?: ApiConfiguration) {
const provider = apiConfiguration?.apiProvider || "anthropic"
const modelId = apiConfiguration?.apiModelId
const getProviderData = (
models: Record<string, ModelInfo>,
defaultId: string,
) => {
const getProviderData = (models: Record<string, ModelInfo>, defaultId: string) => {
let selectedModelId: string
let selectedModelInfo: ModelInfo
if (modelId && modelId in models) {
@@ -1058,21 +890,14 @@ export function normalizeApiConfiguration(apiConfiguration?: ApiConfiguration) {
case "gemini":
return getProviderData(geminiModels, geminiDefaultModelId)
case "openai-native":
return getProviderData(
openAiNativeModels,
openAiNativeDefaultModelId,
)
return getProviderData(openAiNativeModels, openAiNativeDefaultModelId)
case "deepseek":
return getProviderData(deepSeekModels, deepSeekDefaultModelId)
case "openrouter":
return {
selectedProvider: provider,
selectedModelId:
apiConfiguration?.openRouterModelId ||
openRouterDefaultModelId,
selectedModelInfo:
apiConfiguration?.openRouterModelInfo ||
openRouterDefaultModelInfo,
selectedModelId: apiConfiguration?.openRouterModelId || openRouterDefaultModelId,
selectedModelInfo: apiConfiguration?.openRouterModelInfo || openRouterDefaultModelInfo,
}
case "openai":
return {
@@ -1,13 +1,6 @@
import { VSCodeLink, VSCodeTextField } from "@vscode/webview-ui-toolkit/react"
import Fuse from "fuse.js"
import React, {
KeyboardEvent,
memo,
useEffect,
useMemo,
useRef,
useState,
} from "react"
import React, { KeyboardEvent, memo, useEffect, useMemo, useRef, useState } from "react"
import { useRemark } from "react-remark"
import { useMount } from "react-use"
import styled from "styled-components"
@@ -18,11 +11,8 @@ import { highlight } from "../history/HistoryView"
import { ModelInfoView, normalizeApiConfiguration } from "./ApiOptions"
const OpenRouterModelPicker: React.FC = () => {
const { apiConfiguration, setApiConfiguration, openRouterModels } =
useExtensionState()
const [searchTerm, setSearchTerm] = useState(
apiConfiguration?.openRouterModelId || openRouterDefaultModelId,
)
const { apiConfiguration, setApiConfiguration, openRouterModels } = useExtensionState()
const [searchTerm, setSearchTerm] = useState(apiConfiguration?.openRouterModelId || openRouterDefaultModelId)
const [isDropdownVisible, setIsDropdownVisible] = useState(false)
const [selectedIndex, setSelectedIndex] = useState(-1)
const dropdownRef = useRef<HTMLDivElement>(null)
@@ -50,10 +40,7 @@ const OpenRouterModelPicker: React.FC = () => {
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (
dropdownRef.current &&
!dropdownRef.current.contains(event.target as Node)
) {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
setIsDropdownVisible(false)
}
}
@@ -101,9 +88,7 @@ const OpenRouterModelPicker: React.FC = () => {
switch (event.key) {
case "ArrowDown":
event.preventDefault()
setSelectedIndex((prev) =>
prev < modelSearchResults.length - 1 ? prev + 1 : prev,
)
setSelectedIndex((prev) => (prev < modelSearchResults.length - 1 ? prev + 1 : prev))
break
case "ArrowUp":
event.preventDefault()
@@ -111,10 +96,7 @@ const OpenRouterModelPicker: React.FC = () => {
break
case "Enter":
event.preventDefault()
if (
selectedIndex >= 0 &&
selectedIndex < modelSearchResults.length
) {
if (selectedIndex >= 0 && selectedIndex < modelSearchResults.length) {
handleModelChange(modelSearchResults[selectedIndex].id)
setIsDropdownVisible(false)
}
@@ -127,9 +109,7 @@ const OpenRouterModelPicker: React.FC = () => {
}
const hasInfo = useMemo(() => {
return modelIds.some(
(id) => id.toLowerCase() === searchTerm.toLowerCase(),
)
return modelIds.some((id) => id.toLowerCase() === searchTerm.toLowerCase())
}, [modelIds, searchTerm])
useEffect(() => {
@@ -168,11 +148,7 @@ const OpenRouterModelPicker: React.FC = () => {
placeholder="Search and select a model..."
value={searchTerm}
onInput={(e) => {
handleModelChange(
(
e.target as HTMLInputElement
)?.value?.toLowerCase(),
)
handleModelChange((e.target as HTMLInputElement)?.value?.toLowerCase())
setIsDropdownVisible(true)
}}
onFocus={() => setIsDropdownVisible(true)}
@@ -236,26 +212,17 @@ const OpenRouterModelPicker: React.FC = () => {
marginTop: 0,
color: "var(--vscode-descriptionForeground)",
}}>
The extension automatically fetches the latest list of
models available on{" "}
<VSCodeLink
style={{ display: "inline", fontSize: "inherit" }}
href="https://openrouter.ai/models">
The extension automatically fetches the latest list of models available on{" "}
<VSCodeLink style={{ display: "inline", fontSize: "inherit" }} href="https://openrouter.ai/models">
OpenRouter.
</VSCodeLink>
If you're unsure which model to choose, Cline works best
with{" "}
If you're unsure which model to choose, Cline works best with{" "}
<VSCodeLink
style={{ display: "inline", fontSize: "inherit" }}
onClick={() =>
handleModelChange(
"anthropic/claude-3.5-sonnet:beta",
)
}>
onClick={() => handleModelChange("anthropic/claude-3.5-sonnet:beta")}>
anthropic/claude-3.5-sonnet:beta.
</VSCodeLink>
You can also try searching "free" for no-cost options
currently available.
You can also try searching "free" for no-cost options currently available.
</p>
)}
</>
@@ -293,10 +260,7 @@ const DropdownItem = styled.div<{ isSelected: boolean }>`
word-break: break-all;
white-space: normal;
background-color: ${({ isSelected }) =>
isSelected
? "var(--vscode-list-activeSelectionBackground)"
: "inherit"};
background-color: ${({ isSelected }) => (isSelected ? "var(--vscode-list-activeSelectionBackground)" : "inherit")};
&:hover {
background-color: var(--vscode-list-activeSelectionBackground);
@@ -385,9 +349,7 @@ export const ModelDescriptionMarkdown = memo(
}, [reactContent, setIsExpanded])
return (
<StyledMarkdown
key={key}
style={{ display: "inline-block", marginBottom: 0 }}>
<StyledMarkdown key={key} style={{ display: "inline-block", marginBottom: 0 }}>
<div
ref={textContainerRef}
style={{
@@ -422,8 +384,7 @@ export const ModelDescriptionMarkdown = memo(
style={{
width: 30,
height: "1.2em",
background:
"linear-gradient(to right, transparent, var(--vscode-sideBar-background))",
background: "linear-gradient(to right, transparent, var(--vscode-sideBar-background))",
}}
/>
<VSCodeLink
@@ -433,8 +394,7 @@ export const ModelDescriptionMarkdown = memo(
fontSize: "inherit",
paddingRight: 0,
paddingLeft: 3,
backgroundColor:
"var(--vscode-sideBar-background)",
backgroundColor: "var(--vscode-sideBar-background)",
}}
onClick={() => setIsExpanded(true)}>
See more
@@ -1,8 +1,4 @@
import {
VSCodeButton,
VSCodeLink,
VSCodeTextArea,
} from "@vscode/webview-ui-toolkit/react"
import { VSCodeButton, VSCodeLink, VSCodeTextArea } from "@vscode/webview-ui-toolkit/react"
import { memo, useEffect, useState } from "react"
import { useExtensionState } from "../../context/ExtensionStateContext"
import { validateApiConfiguration, validateModelId } from "../../utils/validate"
@@ -16,25 +12,12 @@ type SettingsViewProps = {
}
const SettingsView = ({ onDone }: SettingsViewProps) => {
const {
apiConfiguration,
version,
customInstructions,
setCustomInstructions,
openRouterModels,
} = useExtensionState()
const [apiErrorMessage, setApiErrorMessage] = useState<string | undefined>(
undefined,
)
const [modelIdErrorMessage, setModelIdErrorMessage] = useState<
string | undefined
>(undefined)
const { apiConfiguration, version, customInstructions, setCustomInstructions, openRouterModels } = useExtensionState()
const [apiErrorMessage, setApiErrorMessage] = useState<string | undefined>(undefined)
const [modelIdErrorMessage, setModelIdErrorMessage] = useState<string | undefined>(undefined)
const handleSubmit = () => {
const apiValidationResult = validateApiConfiguration(apiConfiguration)
const modelIdValidationResult = validateModelId(
apiConfiguration,
openRouterModels,
)
const modelIdValidationResult = validateModelId(apiConfiguration, openRouterModels)
setApiErrorMessage(apiValidationResult)
setModelIdErrorMessage(modelIdValidationResult)
@@ -90,9 +73,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
marginBottom: "17px",
paddingRight: 17,
}}>
<h3 style={{ color: "var(--vscode-foreground)", margin: 0 }}>
Settings
</h3>
<h3 style={{ color: "var(--vscode-foreground)", margin: 0 }}>Settings</h3>
<VSCodeButton onClick={handleSubmit}>Done</VSCodeButton>
</div>
<div
@@ -116,15 +97,9 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
value={customInstructions ?? ""}
style={{ width: "100%" }}
rows={4}
placeholder={
'e.g. "Run unit tests at the end", "Use TypeScript with async/await", "Speak in Spanish"'
}
onInput={(e: any) =>
setCustomInstructions(e.target?.value ?? "")
}>
<span style={{ fontWeight: "500" }}>
Custom Instructions
</span>
placeholder={'e.g. "Run unit tests at the end", "Use TypeScript with async/await", "Speak in Spanish"'}
onInput={(e: any) => setCustomInstructions(e.target?.value ?? "")}>
<span style={{ fontWeight: "500" }}>Custom Instructions</span>
</VSCodeTextArea>
<p
style={{
@@ -132,19 +107,14 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
marginTop: "5px",
color: "var(--vscode-descriptionForeground)",
}}>
These instructions are added to the end of the system
prompt sent with every request.
These instructions are added to the end of the system prompt sent with every request.
</p>
</div>
{IS_DEV && (
<>
<div style={{ marginTop: "10px", marginBottom: "4px" }}>
Debug
</div>
<VSCodeButton
onClick={handleResetState}
style={{ marginTop: "5px", width: "auto" }}>
<div style={{ marginTop: "10px", marginBottom: "4px" }}>Debug</div>
<VSCodeButton onClick={handleResetState} style={{ marginTop: "5px", width: "auto" }}>
Reset State
</VSCodeButton>
<p
@@ -153,8 +123,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
marginTop: "5px",
color: "var(--vscode-descriptionForeground)",
}}>
This will reset all global state and secret storage
in the extension.
This will reset all global state and secret storage in the extension.
</p>
</>
)}
@@ -174,11 +143,8 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
margin: 0,
padding: 0,
}}>
If you have any questions or feedback, feel free to open
an issue at{" "}
<VSCodeLink
href="https://github.com/cline/cline"
style={{ display: "inline" }}>
If you have any questions or feedback, feel free to open an issue at{" "}
<VSCodeLink href="https://github.com/cline/cline" style={{ display: "inline" }}>
https://github.com/cline/cline
</VSCodeLink>
</p>
@@ -18,12 +18,7 @@ type TooltipProps = {
align?: "left" | "center" | "right"
}
const Tooltip: React.FC<TooltipProps> = ({
text,
isVisible,
position,
align = "center",
}) => {
const Tooltip: React.FC<TooltipProps> = ({ text, isVisible, position, align = "center" }) => {
let leftPosition = position.x
let triangleStyle: React.CSSProperties = {
left: "50%",
@@ -54,8 +49,7 @@ const Tooltip: React.FC<TooltipProps> = ({
transform: align === "center" ? "translateX(-50%)" : "none",
opacity: isVisible ? 1 : 0,
visibility: isVisible ? "visible" : "hidden",
transition:
"opacity 0.1s ease-out 0.1s, visibility 0.1s ease-out 0.1s",
transition: "opacity 0.1s ease-out 0.1s, visibility 0.1s ease-out 0.1s",
backgroundColor: "var(--vscode-editorHoverWidget-background)",
color: "var(--vscode-editorHoverWidget-foreground)",
padding: "4px 8px",
@@ -75,8 +69,7 @@ const Tooltip: React.FC<TooltipProps> = ({
...triangleStyle,
borderLeft: "5px solid transparent",
borderRight: "5px solid transparent",
borderBottom:
"5px solid var(--vscode-editorHoverWidget-border)",
borderBottom: "5px solid var(--vscode-editorHoverWidget-border)",
}}
/>
<div
@@ -86,8 +79,7 @@ const Tooltip: React.FC<TooltipProps> = ({
...triangleStyle,
borderLeft: "5px solid transparent",
borderRight: "5px solid transparent",
borderBottom:
"5px solid var(--vscode-editorHoverWidget-background)",
borderBottom: "5px solid var(--vscode-editorHoverWidget-background)",
}}
/>
{text}
@@ -95,11 +87,7 @@ const Tooltip: React.FC<TooltipProps> = ({
)
}
const TabNavbar = ({
onPlusClick,
onHistoryClick,
onSettingsClick,
}: TabNavbarProps) => {
const TabNavbar = ({ onPlusClick, onHistoryClick, onSettingsClick }: TabNavbarProps) => {
const [tooltip, setTooltip] = useState<TooltipProps>({
text: "",
isVisible: false,
@@ -107,11 +95,7 @@ const TabNavbar = ({
align: "center",
})
const showTooltip = (
text: string,
event: React.MouseEvent,
align: "left" | "center" | "right" = "center",
) => {
const showTooltip = (text: string, event: React.MouseEvent, align: "left" | "center" | "right" = "center") => {
const rect = event.currentTarget.getBoundingClientRect()
setTooltip({
text,