|
4 | 4 | chatPath, |
5 | 5 | requestJson, |
6 | 6 | normalizeModelBaseUrl, |
7 | | - applyChatEnableThinking, |
8 | | - resolveChatEnableThinking, |
9 | | - withEnableThinkingRetry, |
10 | 7 | type AuthPersistPatch, |
11 | 8 | type AuthStore, |
12 | 9 | type Identity, |
@@ -61,48 +58,31 @@ export async function validateAndPersistApiKey( |
61 | 58 | ? normalizeModelBaseUrl(profile.persistBaseUrl) |
62 | 59 | : undefined; |
63 | 60 | const validationModel = profile.defaultTextModel || "qwen3.7-max"; |
64 | | - const body: { |
65 | | - model: string; |
66 | | - messages: Array<{ role: string; content: string }>; |
67 | | - max_tokens: number; |
68 | | - stream: boolean; |
69 | | - enable_thinking?: boolean; |
70 | | - } = { |
71 | | - model: validationModel, |
72 | | - messages: [{ role: "user", content: "hi" }], |
73 | | - max_tokens: 1, |
74 | | - stream: false, |
75 | | - }; |
76 | | - |
77 | 61 | const requestOpts = { |
78 | 62 | url: baseUrl + chatPath(), |
79 | 63 | method: "POST", |
80 | 64 | headers: { Authorization: `Bearer ${key}` }, |
81 | 65 | timeout: Math.min(deps.settings.timeout, 30), |
82 | | - body, |
| 66 | + body: { |
| 67 | + model: validationModel, |
| 68 | + messages: [{ role: "user", content: "hi" }], |
| 69 | + max_tokens: 1, |
| 70 | + stream: false, |
| 71 | + }, |
83 | 72 | }; |
84 | 73 |
|
85 | | - try { |
86 | | - await withEnableThinkingRetry({ |
87 | | - // Validation requests are always non-streaming. |
88 | | - initial: resolveChatEnableThinking({ stream: false }), |
89 | | - apply: (value) => applyChatEnableThinking(body, value), |
90 | | - run: async () => { |
91 | | - for (let attempt = 1; attempt <= 3; attempt++) { |
92 | | - try { |
93 | | - await requestJson<unknown>(httpDeps, requestOpts); |
94 | | - return; |
95 | | - } catch (error) { |
96 | | - if (attempt >= 3 || !canRetry(error)) throw error; |
97 | | - const delayMs = RETRY_DELAY_BASE_MS * 2 ** (attempt - 1); |
98 | | - await new Promise((resolve) => setTimeout(resolve, delayMs)); |
99 | | - } |
100 | | - } |
101 | | - }, |
102 | | - }); |
103 | | - } catch (error) { |
104 | | - process.stderr.write("Failed\n"); |
105 | | - throw error; |
| 74 | + for (let attempt = 1; attempt <= 3; attempt++) { |
| 75 | + try { |
| 76 | + await requestJson<unknown>(httpDeps, requestOpts); |
| 77 | + break; |
| 78 | + } catch (error) { |
| 79 | + if (attempt >= 3 || !canRetry(error)) { |
| 80 | + process.stderr.write("Failed\n"); |
| 81 | + throw error; |
| 82 | + } |
| 83 | + const delayMs = RETRY_DELAY_BASE_MS * 2 ** (attempt - 1); |
| 84 | + await new Promise((resolve) => setTimeout(resolve, delayMs)); |
| 85 | + } |
106 | 86 | } |
107 | 87 |
|
108 | 88 | process.stderr.write("Valid\n"); |
|
0 commit comments