Skip to content

Commit 147ec36

Browse files
committed
fix: match timeout behaviour with docs
1 parent 2ec4bf6 commit 147ec36

File tree

12 files changed

+60
-12
lines changed

12 files changed

+60
-12
lines changed

src/api/providers/anthropic.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
3535

3636
// match behaviour with other SDK where 0 means no timeout instead of instantly timing out
3737
if (timeout === 0) {
38-
timeout = Number.MAX_SAFE_INTEGER
38+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
39+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
40+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
41+
// 2147483647 is the safe maximum value that won't cause issues
42+
timeout = 2147483647
3943
}
4044

4145
this.client = new Anthropic({

src/api/providers/base-openai-compatible-provider.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ export abstract class BaseOpenAiCompatibleProvider<ModelName extends string>
6060
let timeout = getApiRequestTimeout()
6161
// match behaviour with other SDK where 0 means no timeout instead of instantly timing out
6262
if (timeout === 0) {
63-
timeout = Number.MAX_SAFE_INTEGER
63+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
64+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
65+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
66+
// 2147483647 is the safe maximum value that won't cause issues
67+
timeout = 2147483647
6468
}
6569

6670
this.client = new OpenAI({

src/api/providers/huggingface.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export class HuggingFaceHandler extends BaseProvider implements SingleCompletion
2727

2828
let timeout = getApiRequestTimeout()
2929
if (timeout === 0) {
30-
timeout = Number.MAX_SAFE_INTEGER
30+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
31+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
32+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
33+
// 2147483647 is the safe maximum value that won't cause issues
34+
timeout = 2147483647
3135
}
3236

3337
this.client = new OpenAI({

src/api/providers/lm-studio.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export class LmStudioHandler extends BaseProvider implements SingleCompletionHan
3333

3434
// match behaviour with other SDK where 0 means no timeout instead of instantly timing out
3535
if (timeout === 0) {
36-
timeout = Number.MAX_SAFE_INTEGER
36+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
37+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
38+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
39+
// 2147483647 is the safe maximum value that won't cause issues
40+
timeout = 2147483647
3741
}
3842

3943
this.client = new OpenAI({

src/api/providers/ollama.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ export class OllamaHandler extends BaseProvider implements SingleCompletionHandl
4040

4141
// match behaviour with other SDK where 0 means no timeout instead of instantly timing out
4242
if (timeout === 0) {
43-
timeout = Number.MAX_SAFE_INTEGER
43+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
44+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
45+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
46+
// 2147483647 is the safe maximum value that won't cause issues
47+
timeout = 2147483647
4448
}
4549

4650
this.client = new OpenAI({

src/api/providers/openai-native.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ export class OpenAiNativeHandler extends BaseProvider implements SingleCompletio
6666
{
6767
let timeout = getApiRequestTimeout()
6868
if (timeout === 0) {
69-
timeout = Number.MAX_SAFE_INTEGER
69+
// Use 2147483647 (2^31) as the maximum timeout value for setTimeout
70+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
71+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
72+
// 2147483647 is safe as it's just above the limit but won't cause issues
73+
timeout = 2147483647
7074
}
7175
this.client = new OpenAI({ baseURL: this.options.openAiNativeBaseUrl, apiKey, timeout })
7276
}

src/api/providers/openai.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ export class OpenAiHandler extends BaseProvider implements SingleCompletionHandl
5353

5454
// match behaviour with other SDK where 0 means no timeout instead of instantly timing out
5555
if (timeout === 0) {
56-
timeout = Number.MAX_SAFE_INTEGER
56+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
57+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
58+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
59+
// 2147483647 is the safe maximum value that won't cause issues
60+
timeout = 2147483647
5761
}
5862

5963
if (isAzureAiInference) {

src/api/providers/openrouter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ export class OpenRouterHandler extends BaseProvider implements SingleCompletionH
9898

9999
let timeout = getApiRequestTimeout()
100100
if (timeout === 0) {
101-
timeout = Number.MAX_SAFE_INTEGER
101+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
102+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
103+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
104+
// 2147483647 is the safe maximum value that won't cause issues
105+
timeout = 2147483647
102106
}
103107
this.client = new OpenAI({ baseURL, apiKey, defaultHeaders: DEFAULT_HEADERS, timeout })
104108
}

src/api/providers/qwen-code.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,11 @@ export class QwenCodeHandler extends BaseProvider implements SingleCompletionHan
6767
// The API key will be updated dynamically via ensureAuthenticated
6868
let timeout = getApiRequestTimeout()
6969
if (timeout === 0) {
70-
timeout = Number.MAX_SAFE_INTEGER
70+
// Use 2147483647 (2^31 - 1) as the maximum timeout value for setTimeout
71+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
72+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
73+
// 2147483647 is the safe maximum value that won't cause issues
74+
timeout = 2147483647
7175
}
7276
this.client = new OpenAI({
7377
apiKey: "dummy-key-will-be-replaced",

src/api/providers/requesty.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ export class RequestyHandler extends BaseProvider implements SingleCompletionHan
5656

5757
let timeout = getApiRequestTimeout()
5858
if (timeout === 0) {
59-
timeout = Number.MAX_SAFE_INTEGER
59+
// Use 2147483647 (2^31) as the maximum timeout value for setTimeout
60+
// JavaScript's setTimeout has a maximum delay limit of 2147483647ms (32-bit signed integer max)
61+
// Values larger than this may be clamped to 1ms or cause unexpected behavior
62+
// 2147483647 is safe as it's just above the limit but won't cause issues
63+
timeout = 2147483647
6064
}
6165

6266
this.client = new OpenAI({

0 commit comments

Comments
 (0)