ideacode 1.1.6 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.js CHANGED
@@ -9,6 +9,11 @@ export async function fetchModels(apiKey) {
9
9
  const json = (await res.json());
10
10
  return json.data ?? [];
11
11
  }
12
+ const MAX_RETRIES = 3;
13
+ const INITIAL_BACKOFF_MS = 1000;
14
+ function sleep(ms) {
15
+ return new Promise((resolve) => setTimeout(resolve, ms));
16
+ }
12
17
  export async function callApi(apiKey, messages, systemPrompt, model) {
13
18
  const body = {
14
19
  model,
@@ -17,17 +22,31 @@ export async function callApi(apiKey, messages, systemPrompt, model) {
17
22
  messages,
18
23
  tools: makeSchema(),
19
24
  };
20
- const res = await fetch(config.apiUrl, {
21
- method: "POST",
22
- headers: {
23
- "Content-Type": "application/json",
24
- Authorization: `Bearer ${apiKey}`,
25
- },
26
- body: JSON.stringify(body),
27
- });
28
- if (!res.ok)
29
- throw new Error(`API ${res.status}: ${await res.text()}`);
30
- return res.json();
25
+ let lastError = null;
26
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
27
+ const res = await fetch(config.apiUrl, {
28
+ method: "POST",
29
+ headers: {
30
+ "Content-Type": "application/json",
31
+ Authorization: `Bearer ${apiKey}`,
32
+ },
33
+ body: JSON.stringify(body),
34
+ });
35
+ if (res.ok)
36
+ return res.json();
37
+ const text = await res.text();
38
+ lastError = new Error(`API ${res.status}: ${text}`);
39
+ if ((res.status === 429 || res.status === 503) && attempt < MAX_RETRIES) {
40
+ const retryAfter = res.headers.get("retry-after");
41
+ const waitMs = retryAfter
42
+ ? Math.max(1000, parseInt(retryAfter, 10) * 1000)
43
+ : INITIAL_BACKOFF_MS * Math.pow(2, attempt);
44
+ await sleep(waitMs);
45
+ continue;
46
+ }
47
+ throw lastError;
48
+ }
49
+ throw lastError;
31
50
  }
32
51
  function parseStreamChunk(line) {
33
52
  if (line.startsWith("data: ")) {
@@ -176,18 +195,33 @@ export async function callSummarize(apiKey, messages, model) {
176
195
  system: SUMMARIZE_SYSTEM,
177
196
  messages,
178
197
  };
179
- const res = await fetch(config.apiUrl, {
180
- method: "POST",
181
- headers: {
182
- "Content-Type": "application/json",
183
- Authorization: `Bearer ${apiKey}`,
184
- },
185
- body: JSON.stringify(body),
186
- });
187
- if (!res.ok)
188
- throw new Error(`Summarize API ${res.status}: ${await res.text()}`);
189
- const data = (await res.json());
190
- const blocks = data.content ?? [];
191
- const textBlock = blocks.find((b) => b.type === "text" && b.text);
192
- return (textBlock?.text ?? "").trim();
198
+ let lastError = null;
199
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
200
+ const res = await fetch(config.apiUrl, {
201
+ method: "POST",
202
+ headers: {
203
+ "Content-Type": "application/json",
204
+ Authorization: `Bearer ${apiKey}`,
205
+ },
206
+ body: JSON.stringify(body),
207
+ });
208
+ if (res.ok) {
209
+ const data = (await res.json());
210
+ const blocks = data.content ?? [];
211
+ const textBlock = blocks.find((b) => b.type === "text" && b.text);
212
+ return (textBlock?.text ?? "").trim();
213
+ }
214
+ const text = await res.text();
215
+ lastError = new Error(`Summarize API ${res.status}: ${text}`);
216
+ if ((res.status === 429 || res.status === 503) && attempt < MAX_RETRIES) {
217
+ const retryAfter = res.headers.get("retry-after");
218
+ const waitMs = retryAfter
219
+ ? Math.max(1000, parseInt(retryAfter, 10) * 1000)
220
+ : INITIAL_BACKOFF_MS * Math.pow(2, attempt);
221
+ await sleep(waitMs);
222
+ continue;
223
+ }
224
+ throw lastError;
225
+ }
226
+ throw lastError;
193
227
  }
package/dist/repl.js CHANGED
@@ -528,6 +528,7 @@ export function Repl({ apiKey, cwd, onQuit }) {
528
528
  }
529
529
  }
530
530
  catch (err) {
531
+ setLoading(false);
531
532
  appendLog(colors.error(`${icons.error} ${err instanceof Error ? err.message : String(err)}`));
532
533
  appendLog("");
533
534
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ideacode",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "CLI TUI for AI agents via OpenRouter — agentic loop, tools, markdown",
5
5
  "type": "module",
6
6
  "repository": {