@ridit/lens 0.2.8 → 0.3.0
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 +35 -18
- package/package.json +3 -3
- package/src/utils/chat.ts +50 -18
- package/src/utils/thinking.tsx +1 -1
- package/src/components/__tests__/Header.test.tsx +0 -9
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... \
|
|
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
|
-
|
|
271789
|
-
|
|
271790
|
-
|
|
271791
|
-
|
|
271792
|
-
|
|
271793
|
-
|
|
271794
|
-
|
|
271795
|
-
|
|
271796
|
-
|
|
271797
|
-
|
|
271798
|
-
|
|
271799
|
-
|
|
271800
|
-
|
|
271801
|
-
|
|
271802
|
-
|
|
271803
|
-
|
|
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.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Know Your Codebase.",
|
|
5
5
|
"author": "Ridit Jangra <riditjangra09@gmail.com> (https://ridit.space)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "bun build src/index.tsx --target node --outfile dist/index.mjs",
|
|
17
17
|
"postbuild": "node -e \"const fs=require('fs');const f='dist/index.mjs';fs.writeFileSync(f,'#!/usr/bin/env node\\n'+fs.readFileSync(f,'utf8'))\"",
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"tag": "node -e \"const v=require('./package.json').version;require('child_process').execSync('git tag v'+v+' && git push origin v'+v,{stdio:'inherit'})\"",
|
|
19
|
+
"prepublishOnly": "npm run build && npm run tag"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@ridit/lens-sdk": "0.1.6",
|
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
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
}
|
package/src/utils/thinking.tsx
CHANGED
|
@@ -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
|
],
|