Support for custom timeout (#3029)

* Support for custom timeout

* Make custom timeout visible only for ollama

* Remove parameters from other providers, only kept for ollama

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

Co-authored-by: nomaven <arafat.da.khan@gmail.com>

---------

Co-authored-by: nomaven <arafat.da.khan@gmail.com>
This commit is contained in:
WingsDrafterworkandnomaven authored and GitHub committed 2025-04-27 15:17:04 -07:00
1 parent 60c210b017
commit df37f29746
6 files changed
+40 -2

No files matched your search

+5
View File
@@ -0,0 +1,5 @@
---
"cline": minor
---
Add support for custom API request timeout. Previously, timeouts were hardcoded to 30 seconds for providers like Ollama or 15 seconds for OpenRouter and Cline. Now users can set a custom timeout value in milliseconds through the settings interface.
+4 -2
View File
@@ -21,8 +21,9 @@ export class OllamaHandler implements ApiHandler {
try {
// Create a promise that rejects after timeout
const timeoutMs = this.options.requestTimeoutMs || 30000
const timeoutPromise = new Promise<never>((_, reject) => {
setTimeout(() => reject(new Error("Ollama request timed out after 120 seconds")), 120000)
setTimeout(() => reject(new Error(`Ollama request timed out after ${timeoutMs / 1000} seconds`)), timeoutMs)
})
// Create the actual API request promise
@@ -63,7 +64,8 @@ export class OllamaHandler implements ApiHandler {
} catch (error: any) {
// Check if it's a timeout error
if (error.message && error.message.includes("timed out")) {
throw new Error("Ollama request timed out after 120 seconds")
const timeoutMs = this.options.requestTimeoutMs || 30000
throw new Error(`Ollama request timed out after ${timeoutMs / 1000} seconds`)
}
// Enhance error reporting
+1
View File
@@ -75,5 +75,6 @@ export type GlobalStateKey =
| "reasoningEffort"
| "planActSeparateModelsSetting"
| "favoritedModelIds"
| "requestTimeoutMs"
export type LocalStateKey = "localClineRulesToggles"
+4
View File
@@ -125,6 +125,7 @@ export async function getAllExtensionState(context: vscode.ExtensionContext) {
planActSeparateModelsSettingRaw,
favoritedModelIds,
globalClineRulesToggles,
requestTimeoutMs,
] = await Promise.all([
getGlobalState(context, "apiProvider") as Promise<ApiProvider | undefined>,
getGlobalState(context, "apiModelId") as Promise<string | undefined>,
@@ -198,6 +199,7 @@ export async function getAllExtensionState(context: vscode.ExtensionContext) {
getGlobalState(context, "planActSeparateModelsSetting") as Promise<boolean | undefined>,
getGlobalState(context, "favoritedModelIds") as Promise<string[] | undefined>,
getGlobalState(context, "globalClineRulesToggles") as Promise<ClineRulesToggles | undefined>,
getGlobalState(context, "requestTimeoutMs") as Promise<number | undefined>,
])
let apiProvider: ApiProvider
@@ -297,6 +299,7 @@ export async function getAllExtensionState(context: vscode.ExtensionContext) {
xaiApiKey,
sambanovaApiKey,
favoritedModelIds,
requestTimeoutMs,
},
lastShownAnnouncementId,
customInstructions,
@@ -434,6 +437,7 @@ export async function updateApiConfiguration(context: vscode.ExtensionContext, a
await storeSecret(context, "clineApiKey", clineApiKey)
await storeSecret(context, "sambanovaApiKey", sambanovaApiKey)
await updateGlobalState(context, "favoritedModelIds", favoritedModelIds)
await updateGlobalState(context, "requestTimeoutMs", apiConfiguration.requestTimeoutMs)
}
export async function resetExtensionState(context: vscode.ExtensionContext) {
+1
View File
@@ -80,6 +80,7 @@ export interface ApiHandlerOptions {
thinkingBudgetTokens?: number
reasoningEffort?: string
sambanovaApiKey?: string
requestTimeoutMs?: number
}
export type ApiConfiguration = ApiHandlerOptions & {
@@ -1574,6 +1574,31 @@ const ApiOptions = ({
</p>
)}
{selectedProvider === "ollama" && showModelOptions && (
<>
<VSCodeTextField
value={apiConfiguration?.requestTimeoutMs ? apiConfiguration.requestTimeoutMs.toString() : "30000"}
style={{ width: "100%" }}
onInput={(e: any) => {
const value = e.target.value
// Convert to number, with validation
const numValue = parseInt(value, 10)
if (!isNaN(numValue) && numValue > 0) {
setApiConfiguration({
...apiConfiguration,
requestTimeoutMs: numValue,
})
}
}}
placeholder="Default: 30000 (30 seconds)">
<span style={{ fontWeight: 500 }}>Request Timeout (ms)</span>
</VSCodeTextField>
<p style={{ fontSize: "12px", marginTop: 3, color: "var(--vscode-descriptionForeground)" }}>
Maximum time in milliseconds to wait for API responses before timing out.
</p>
</>
)}
{(selectedProvider === "openrouter" || selectedProvider === "cline") && showModelOptions && (
<>
<VSCodeCheckbox