@ridit/lens 0.2.8 → 0.2.9

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.mjs CHANGED
@@ -265835,7 +265835,7 @@ var PHRASES = {
265835
265835
  "it's the tokens for me... ✨",
265836
265836
  "vibing with the prompt... \uD83C\uDFB5",
265837
265837
  "main character moment incoming... \uD83C\uDFAC",
265838
- "we move... \uD83D\uDEB6",
265838
+ "we move... \uD83E\uDEE1\uD83E\uDEE1",
265839
265839
  "rizzing up an answer... \uD83D\uDDE3️",
265840
265840
  "rizzing up a baddie answer... \uD83D\uDE0F"
265841
265841
  ],
@@ -271748,7 +271748,7 @@ Please continue your response based on this output.`
271748
271748
  return { role: m.role, content: m.content };
271749
271749
  });
271750
271750
  }
271751
- async function callChat(provider, systemPrompt, messages, abortSignal) {
271751
+ async function callChat(provider, systemPrompt, messages, abortSignal, retries = 2) {
271752
271752
  const apiMessages = [
271753
271753
  ...buildFewShotMessages(),
271754
271754
  ...buildApiMessages(messages)
@@ -271785,22 +271785,39 @@ async function callChat(provider, systemPrompt, messages, abortSignal) {
271785
271785
  const controller = new AbortController;
271786
271786
  const timer = setTimeout(() => controller.abort(), 60000);
271787
271787
  abortSignal?.addEventListener("abort", () => controller.abort());
271788
- const res = await fetch(url, {
271789
- method: "POST",
271790
- headers,
271791
- body: JSON.stringify(body),
271792
- signal: controller.signal
271793
- });
271794
- clearTimeout(timer);
271795
- if (!res.ok)
271796
- throw new Error(`API error ${res.status}: ${await res.text()}`);
271797
- const data = await res.json();
271798
- if (provider.type === "anthropic") {
271799
- const content = data.content;
271800
- return content.filter((b) => b.type === "text").map((b) => b.text).join("");
271801
- } else {
271802
- const choices = data.choices;
271803
- return choices[0]?.message.content ?? "";
271788
+ try {
271789
+ const res = await fetch(url, {
271790
+ method: "POST",
271791
+ headers,
271792
+ body: JSON.stringify(body),
271793
+ signal: controller.signal
271794
+ });
271795
+ clearTimeout(timer);
271796
+ if (!res.ok) {
271797
+ const errText = await res.text();
271798
+ if (res.status >= 500 && retries > 0) {
271799
+ await new Promise((r) => setTimeout(r, 1500));
271800
+ return callChat(provider, systemPrompt, messages, abortSignal, retries - 1);
271801
+ }
271802
+ throw new Error(`API error ${res.status}: ${errText}`);
271803
+ }
271804
+ const data = await res.json();
271805
+ if (provider.type === "anthropic") {
271806
+ const content = data.content;
271807
+ return content.filter((b) => b.type === "text").map((b) => b.text).join("");
271808
+ } else {
271809
+ const choices = data.choices;
271810
+ return choices[0]?.message.content ?? "";
271811
+ }
271812
+ } catch (err) {
271813
+ clearTimeout(timer);
271814
+ if (err instanceof Error && err.name === "AbortError")
271815
+ throw err;
271816
+ if (retries > 0) {
271817
+ await new Promise((r) => setTimeout(r, 1500));
271818
+ return callChat(provider, systemPrompt, messages, abortSignal, retries - 1);
271819
+ }
271820
+ throw err;
271804
271821
  }
271805
271822
  }
271806
271823
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ridit/lens",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Know Your Codebase.",
5
5
  "author": "Ridit Jangra <riditjangra09@gmail.com> (https://ridit.space)",
6
6
  "license": "MIT",
package/src/utils/chat.ts CHANGED
@@ -218,6 +218,7 @@ export async function callChat(
218
218
  systemPrompt: string,
219
219
  messages: Message[],
220
220
  abortSignal?: AbortSignal,
221
+ retries = 2,
221
222
  ): Promise<string> {
222
223
  const apiMessages = [
223
224
  ...buildFewShotMessages(),
@@ -259,24 +260,55 @@ export async function callChat(
259
260
  const timer = setTimeout(() => controller.abort(), 60_000);
260
261
  abortSignal?.addEventListener("abort", () => controller.abort());
261
262
 
262
- const res = await fetch(url, {
263
- method: "POST",
264
- headers,
265
- body: JSON.stringify(body),
266
- signal: controller.signal,
267
- });
268
- clearTimeout(timer);
269
- if (!res.ok) throw new Error(`API error ${res.status}: ${await res.text()}`);
270
- const data = (await res.json()) as Record<string, unknown>;
263
+ try {
264
+ const res = await fetch(url, {
265
+ method: "POST",
266
+ headers,
267
+ body: JSON.stringify(body),
268
+ signal: controller.signal,
269
+ });
270
+ clearTimeout(timer);
271
271
 
272
- if (provider.type === "anthropic") {
273
- const content = data.content as { type: string; text: string }[];
274
- return content
275
- .filter((b) => b.type === "text")
276
- .map((b) => b.text)
277
- .join("");
278
- } else {
279
- const choices = data.choices as { message: { content: string } }[];
280
- return choices[0]?.message.content ?? "";
272
+ if (!res.ok) {
273
+ const errText = await res.text();
274
+ if (res.status >= 500 && retries > 0) {
275
+ await new Promise((r) => setTimeout(r, 1500));
276
+ return callChat(
277
+ provider,
278
+ systemPrompt,
279
+ messages,
280
+ abortSignal,
281
+ retries - 1,
282
+ );
283
+ }
284
+ throw new Error(`API error ${res.status}: ${errText}`);
285
+ }
286
+
287
+ const data = (await res.json()) as Record<string, unknown>;
288
+
289
+ if (provider.type === "anthropic") {
290
+ const content = data.content as { type: string; text: string }[];
291
+ return content
292
+ .filter((b) => b.type === "text")
293
+ .map((b) => b.text)
294
+ .join("");
295
+ } else {
296
+ const choices = data.choices as { message: { content: string } }[];
297
+ return choices[0]?.message.content ?? "";
298
+ }
299
+ } catch (err) {
300
+ clearTimeout(timer);
301
+ if (err instanceof Error && err.name === "AbortError") throw err;
302
+ if (retries > 0) {
303
+ await new Promise((r) => setTimeout(r, 1500));
304
+ return callChat(
305
+ provider,
306
+ systemPrompt,
307
+ messages,
308
+ abortSignal,
309
+ retries - 1,
310
+ );
311
+ }
312
+ throw err;
281
313
  }
282
314
  }
@@ -46,7 +46,7 @@ const PHRASES: Record<string, string[]> = {
46
46
  "it's the tokens for me... ✨",
47
47
  "vibing with the prompt... 🎵",
48
48
  "main character moment incoming... 🎬",
49
- "we move... 🚶",
49
+ "we move... 🫡🫡",
50
50
  "rizzing up an answer... 🗣️",
51
51
  "rizzing up a baddie answer... 😏",
52
52
  ],
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import Header from '../Header';
4
-
5
- describe('Header', () => {
6
- it('renders without crashing', () => {
7
- render(<Header />);
8
- });
9
- });