Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/shared/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface ApiHandlerOptions {
glamaModelId?: string
glamaModelInfo?: ModelInfo
glamaApiKey?: string
rateLimitSeconds?: number // Added for per-profile rate limiting
openRouterApiKey?: string
openRouterModelId?: string
openRouterModelInfo?: ModelInfo
Expand Down Expand Up @@ -134,6 +135,7 @@ export const API_CONFIG_KEYS: GlobalStateKey[] = [
"modelTemperature",
"modelMaxTokens",
"modelMaxThinkingTokens",
"rateLimitSeconds", // Added for per-profile rate limiting
]

// Models
Expand Down
27 changes: 1 addition & 26 deletions webview-ui/src/components/settings/AdvancedSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,14 @@ import { SectionHeader } from "./SectionHeader"
import { Section } from "./Section"

type AdvancedSettingsProps = HTMLAttributes<HTMLDivElement> & {
rateLimitSeconds: number
terminalShellIntegrationTimeout: number | undefined
diffEnabled?: boolean
fuzzyMatchThreshold?: number
setCachedStateField: SetCachedStateField<
"rateLimitSeconds" | "diffEnabled" | "fuzzyMatchThreshold" | "terminalShellIntegrationTimeout"
>
setCachedStateField: SetCachedStateField<"diffEnabled" | "fuzzyMatchThreshold" | "terminalShellIntegrationTimeout">
experiments: Record<ExperimentId, boolean>
setExperimentEnabled: SetExperimentEnabled
}
export const AdvancedSettings = ({
rateLimitSeconds,
terminalShellIntegrationTimeout,
diffEnabled,
fuzzyMatchThreshold,
Expand All @@ -45,27 +41,6 @@ export const AdvancedSettings = ({
</SectionHeader>

<Section>
<div>
<div className="flex flex-col gap-2">
<span className="font-medium">{t("settings:advanced.rateLimit.label")}</span>
<div className="flex items-center gap-2">
<input
type="range"
min="0"
max="60"
step="1"
value={rateLimitSeconds}
onChange={(e) => setCachedStateField("rateLimitSeconds", parseInt(e.target.value))}
className="h-2 focus:outline-0 w-4/5 accent-vscode-button-background"
/>
<span style={{ ...sliderLabelStyle }}>{rateLimitSeconds}s</span>
</div>
</div>
<p className="text-vscode-descriptionForeground text-sm mt-0">
{t("settings:advanced.rateLimit.description")}
</p>
</div>

<div>
<div className="flex flex-col gap-2">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this just an empty section now? Can we get rid of it?

<span className="font-medium">Terminal shell integration timeout</span>
Expand Down
20 changes: 15 additions & 5 deletions webview-ui/src/components/settings/ApiOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { VSCodeButtonLink } from "../common/VSCodeButtonLink"
import { ModelInfoView } from "./ModelInfoView"
import { ModelPicker } from "./ModelPicker"
import { TemperatureControl } from "./TemperatureControl"
import { RateLimitControl } from "./RateLimitControl"
import { validateApiConfiguration, validateModelId, validateBedrockArn } from "@/utils/validate"
import { ApiErrorMessage } from "./ApiErrorMessage"
import { ThinkingBudget } from "./ThinkingBudget"
Expand Down Expand Up @@ -1526,11 +1527,20 @@ const ApiOptions = ({
)}

{!fromWelcomeView && (
<TemperatureControl
value={apiConfiguration?.modelTemperature}
onChange={handleInputChange("modelTemperature", noTransform)}
maxValue={2}
/>
<>
<TemperatureControl
value={apiConfiguration?.modelTemperature}
onChange={handleInputChange("modelTemperature", noTransform)}
maxValue={2}
/>
<RateLimitControl
value={apiConfiguration?.rateLimitSeconds}
onChange={(value) =>
setApiConfigurationField("rateLimitSeconds", value === null ? undefined : value)
}
maxValue={60}
/>
</>
)}
</div>
)
Expand Down
71 changes: 71 additions & 0 deletions webview-ui/src/components/settings/RateLimitControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
import { useEffect, useState } from "react"
import { useAppTranslation } from "@/i18n/TranslationContext"
import { useDebounce } from "react-use"

interface RateLimitControlProps {
value: number | undefined | null
onChange: (value: number | undefined | null) => void
maxValue?: number
}

export const RateLimitControl = ({ value, onChange, maxValue = 60 }: RateLimitControlProps) => {
const { t } = useAppTranslation()
const [isCustomRateLimit, setIsCustomRateLimit] = useState(value !== undefined)
const [inputValue, setInputValue] = useState(value)
useDebounce(() => onChange(inputValue), 50, [onChange, inputValue])
// Sync internal state with prop changes when switching profiles
useEffect(() => {
const hasCustomRateLimit = value !== undefined && value !== null
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checkbox doesn't seem to be serializing correctly

Screen.Recording.2025-03-24.at.3.10.38.PM.mov

setIsCustomRateLimit(hasCustomRateLimit)
setInputValue(value)
}, [value])

return (
<>
<div>
<VSCodeCheckbox
checked={isCustomRateLimit}
onChange={(e: any) => {
const isChecked = e.target.checked
setIsCustomRateLimit(isChecked)
if (!isChecked) {
setInputValue(null) // Unset the rate limit, note that undefined is unserializable
} else {
setInputValue(value ?? 0) // Use the value from apiConfiguration, if set
}
}}>
<span className="font-medium">{t("settings:rateLimit.useCustom")}</span>
</VSCodeCheckbox>
<div className="text-sm text-vscode-descriptionForeground">
{t("settings:advanced.rateLimit.description")}
</div>
</div>

{isCustomRateLimit && (
<div
style={{
marginLeft: 0,
paddingLeft: 10,
borderLeft: "2px solid var(--vscode-button-background)",
}}>
<div style={{ display: "flex", alignItems: "center", gap: "5px" }}>
<input
type="range"
min="0"
max={maxValue}
step="1"
value={inputValue ?? 0}
className="h-2 focus:outline-0 w-4/5 accent-vscode-button-background"
onChange={(e) => setInputValue(parseInt(e.target.value))}
/>
<span>{inputValue}s</span>
</div>
<p className="text-vscode-descriptionForeground text-sm mt-1">
{t("settings:advanced.rateLimit.description")}
</p>
</div>
)}
</>
)
}
1 change: 0 additions & 1 deletion webview-ui/src/components/settings/SettingsView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,6 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },

<div ref={advancedRef}>
<AdvancedSettings
rateLimitSeconds={rateLimitSeconds}
terminalShellIntegrationTimeout={terminalShellIntegrationTimeout}
diffEnabled={diffEnabled}
fuzzyMatchThreshold={fuzzyMatchThreshold}
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/ca/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Temps màxim d'espera per a la inicialització de la integració de shell abans d'executar comandes. Per a usuaris amb temps d'inici de shell llargs, aquest valor pot necessitar ser augmentat si veieu errors \"Shell Integration Unavailable\" al terminal."
}
},
"rateLimit": {
"useCustom": "Utilitzar límit de freqüència personalitzat"
},
"advanced": {
"rateLimit": {
"label": "Límit de freqüència",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/de/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Maximale Wartezeit für die Shell-Integration, bevor Befehle ausgeführt werden. Für Benutzer mit langen Shell-Startzeiten muss dieser Wert möglicherweise erhöht werden, wenn Sie Fehler vom Typ \"Shell Integration Unavailable\" im Terminal sehen."
}
},
"rateLimit": {
"useCustom": "Benutzerdefinierte Ratenbegrenzung verwenden"
},
"advanced": {
"rateLimit": {
"label": "Ratenbegrenzung",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Maximum time to wait for shell integration to initialize before executing commands. For users with long shell startup times, this value may need to be increased if you see \"Shell Integration Unavailable\" errors in the terminal."
}
},
"rateLimit": {
"useCustom": "Use custom rate limit"
},
"advanced": {
"rateLimit": {
"label": "Rate limit",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/es/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Tiempo máximo de espera para la inicialización de la integración del shell antes de ejecutar comandos. Para usuarios con tiempos de inicio de shell largos, este valor puede necesitar ser aumentado si ve errores \"Shell Integration Unavailable\" en el terminal."
}
},
"rateLimit": {
"useCustom": "Usar límite de tasa personalizado"
},
"advanced": {
"rateLimit": {
"label": "Límite de tasa",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/fr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Temps maximum d'attente pour l'initialisation de l'intégration du shell avant d'exécuter des commandes. Pour les utilisateurs avec des temps de démarrage de shell longs, cette valeur peut nécessiter d'être augmentée si vous voyez des erreurs \"Shell Integration Unavailable\" dans le terminal."
}
},
"rateLimit": {
"useCustom": "Utiliser une limite de débit personnalisée"
},
"advanced": {
"rateLimit": {
"label": "Limite de débit",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/hi/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "कमांड निष्पादित करने से पहले शेल एकीकरण के आरंभ होने के लिए प्रतीक्षा का अधिकतम समय। लंबे शेल स्टार्टअप समय वाले उपयोगकर्ताओं के लिए, यदि आप टर्मिनल में \"Shell Integration Unavailable\" त्रुटियाँ देखते हैं तो इस मान को बढ़ाने की आवश्यकता हो सकती है।"
}
},
"rateLimit": {
"useCustom": "कस्टम दर सीमा का उपयोग करें"
},
"advanced": {
"rateLimit": {
"label": "दर सीमा",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/it/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Tempo massimo di attesa per l'inizializzazione dell'integrazione della shell prima di eseguire i comandi. Per gli utenti con tempi di avvio della shell lunghi, questo valore potrebbe dover essere aumentato se si vedono errori \"Shell Integration Unavailable\" nel terminale."
}
},
"rateLimit": {
"useCustom": "Usa limite di frequenza personalizzato"
},
"advanced": {
"rateLimit": {
"label": "Limite di frequenza",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/ja/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "コマンドを実行する前にシェル統合の初期化を待つ最大時間。シェルの起動時間が長いユーザーの場合、ターミナルで「Shell Integration Unavailable」エラーが表示される場合は、この値を増やす必要があるかもしれません。"
}
},
"rateLimit": {
"useCustom": "カスタムレート制限を使用"
},
"advanced": {
"rateLimit": {
"label": "レート制限",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/ko/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "명령을 실행하기 전에 쉘 통합이 초기화될 때까지 기다리는 최대 시간. 쉘 시작 시간이 긴 사용자의 경우, 터미널에서 \"Shell Integration Unavailable\" 오류가 표시되면 이 값을 늘려야 할 수 있습니다."
}
},
"rateLimit": {
"useCustom": "사용자 정의 속도 제한 사용"
},
"advanced": {
"rateLimit": {
"label": "속도 제한",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/pl/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Maksymalny czas oczekiwania na inicjalizację integracji powłoki przed wykonaniem poleceń. Dla użytkowników z długim czasem uruchamiania powłoki, ta wartość może wymagać zwiększenia, jeśli widzisz błędy \"Shell Integration Unavailable\" w terminalu."
}
},
"rateLimit": {
"useCustom": "Użyj niestandardowego limitu szybkości"
},
"advanced": {
"rateLimit": {
"label": "Limit szybkości",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/pt-BR/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Tempo máximo de espera para a inicialização da integração do shell antes de executar comandos. Para usuários com tempos de inicialização de shell longos, este valor pode precisar ser aumentado se você vir erros \"Shell Integration Unavailable\" no terminal."
}
},
"rateLimit": {
"useCustom": "Usar limite de taxa personalizado"
},
"advanced": {
"rateLimit": {
"label": "Limite de taxa",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/tr/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Komutları yürütmeden önce kabuk entegrasyonunun başlatılması için beklenecek maksimum süre. Kabuk başlatma süresi uzun olan kullanıcılar için, terminalde \"Shell Integration Unavailable\" hatalarını görürseniz bu değerin artırılması gerekebilir."
}
},
"rateLimit": {
"useCustom": "Özel hız sınırı kullan"
},
"advanced": {
"rateLimit": {
"label": "Hız sınırı",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/vi/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "Thời gian tối đa để chờ tích hợp shell khởi tạo trước khi thực hiện lệnh. Đối với người dùng có thời gian khởi động shell dài, giá trị này có thể cần được tăng lên nếu bạn thấy lỗi \"Shell Integration Unavailable\" trong terminal."
}
},
"rateLimit": {
"useCustom": "Sử dụng giới hạn tốc độ tùy chỉnh"
},
"advanced": {
"rateLimit": {
"label": "Giới hạn tốc độ",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/zh-CN/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "执行命令前等待 Shell 集成初始化的最长时间。对于 Shell 启动时间较长的用户,如果在终端中看到\"Shell Integration Unavailable\"错误,可能需要增加此值。"
}
},
"rateLimit": {
"useCustom": "使用自定义速率限制"
},
"advanced": {
"rateLimit": {
"label": "速率限制",
Expand Down
3 changes: 3 additions & 0 deletions webview-ui/src/i18n/locales/zh-TW/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@
"description": "執行命令前等待 Shell 整合初始化的最長時間。對於 Shell 啟動時間較長的使用者,如果在終端機中看到\"Shell Integration Unavailable\"錯誤,可能需要增加此值。"
}
},
"rateLimit": {
"useCustom": "使用自訂速率限制"
},
"advanced": {
"rateLimit": {
"label": "速率限制",
Expand Down
Loading