koztv-blog-tools 1.2.1 → 1.2.2

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/index.js CHANGED
@@ -329,24 +329,36 @@ Do not add any explanations or notes.`
329
329
  }
330
330
  ];
331
331
  const endpoint = apiUrl.endsWith("/") ? `${apiUrl}chat/completions` : `${apiUrl}/chat/completions`;
332
- const response = await fetch(endpoint, {
333
- method: "POST",
334
- headers: {
335
- "Content-Type": "application/json",
336
- "Authorization": `Bearer ${apiKey}`
337
- },
338
- body: JSON.stringify({
339
- model,
340
- messages,
341
- temperature: 0.3
342
- })
343
- });
344
- if (!response.ok) {
332
+ const maxRetries = 3;
333
+ let lastError = null;
334
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
335
+ if (attempt > 0) {
336
+ const delay = 3e3 * Math.pow(2, attempt - 1);
337
+ await new Promise((r) => setTimeout(r, delay));
338
+ }
339
+ const response = await fetch(endpoint, {
340
+ method: "POST",
341
+ headers: {
342
+ "Content-Type": "application/json",
343
+ "Authorization": `Bearer ${apiKey}`
344
+ },
345
+ body: JSON.stringify({
346
+ model,
347
+ messages,
348
+ temperature: 0.3
349
+ })
350
+ });
351
+ if (response.ok) {
352
+ const data = await response.json();
353
+ return data.choices[0]?.message?.content || "";
354
+ }
345
355
  const error = await response.text();
346
- throw new Error(`API error: ${response.status} - ${error}`);
356
+ lastError = new Error(`API error: ${response.status} - ${error}`);
357
+ if (response.status !== 429 && response.status < 500) {
358
+ throw lastError;
359
+ }
347
360
  }
348
- const data = await response.json();
349
- return data.choices[0]?.message?.content || "";
361
+ throw lastError;
350
362
  }
351
363
  async function translateTitle(title, options) {
352
364
  const translated = await translateContent(title, options);
@@ -685,7 +697,7 @@ async function processPost(post, options, exportDir) {
685
697
  } catch (error) {
686
698
  onProgress?.(` Error translating to ${targetLang}: ${error.message}`);
687
699
  }
688
- await new Promise((r) => setTimeout(r, 300));
700
+ await new Promise((r) => setTimeout(r, 2e3));
689
701
  }
690
702
  } else {
691
703
  languages.push({
package/dist/index.mjs CHANGED
@@ -272,24 +272,36 @@ Do not add any explanations or notes.`
272
272
  }
273
273
  ];
274
274
  const endpoint = apiUrl.endsWith("/") ? `${apiUrl}chat/completions` : `${apiUrl}/chat/completions`;
275
- const response = await fetch(endpoint, {
276
- method: "POST",
277
- headers: {
278
- "Content-Type": "application/json",
279
- "Authorization": `Bearer ${apiKey}`
280
- },
281
- body: JSON.stringify({
282
- model,
283
- messages,
284
- temperature: 0.3
285
- })
286
- });
287
- if (!response.ok) {
275
+ const maxRetries = 3;
276
+ let lastError = null;
277
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
278
+ if (attempt > 0) {
279
+ const delay = 3e3 * Math.pow(2, attempt - 1);
280
+ await new Promise((r) => setTimeout(r, delay));
281
+ }
282
+ const response = await fetch(endpoint, {
283
+ method: "POST",
284
+ headers: {
285
+ "Content-Type": "application/json",
286
+ "Authorization": `Bearer ${apiKey}`
287
+ },
288
+ body: JSON.stringify({
289
+ model,
290
+ messages,
291
+ temperature: 0.3
292
+ })
293
+ });
294
+ if (response.ok) {
295
+ const data = await response.json();
296
+ return data.choices[0]?.message?.content || "";
297
+ }
288
298
  const error = await response.text();
289
- throw new Error(`API error: ${response.status} - ${error}`);
299
+ lastError = new Error(`API error: ${response.status} - ${error}`);
300
+ if (response.status !== 429 && response.status < 500) {
301
+ throw lastError;
302
+ }
290
303
  }
291
- const data = await response.json();
292
- return data.choices[0]?.message?.content || "";
304
+ throw lastError;
293
305
  }
294
306
  async function translateTitle(title, options) {
295
307
  const translated = await translateContent(title, options);
@@ -628,7 +640,7 @@ async function processPost(post, options, exportDir) {
628
640
  } catch (error) {
629
641
  onProgress?.(` Error translating to ${targetLang}: ${error.message}`);
630
642
  }
631
- await new Promise((r) => setTimeout(r, 300));
643
+ await new Promise((r) => setTimeout(r, 2e3));
632
644
  }
633
645
  } else {
634
646
  languages.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koztv-blog-tools",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "Shared utilities for Telegram-based blog sites",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",