pi-all-search 1.0.4 → 1.0.6
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/package.json +3 -3
- package/src/providers/context7.ts +20 -13
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-all-search",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "All-in-one search extension for Pi — exa, tavily, anysearch, firecrawl,
|
|
3
|
+
"version": "1.0.6",
|
|
4
|
+
"description": "All-in-one web search extension for Pi — exa, tavily, anysearch, firecrawl, context7",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": "github:RealAlexandreAI/pi-all-search",
|
|
@@ -20,6 +20,6 @@
|
|
|
20
20
|
"@earendil-works/pi-ai": "^0.80.0",
|
|
21
21
|
"@earendil-works/pi-coding-agent": "^0.80.0",
|
|
22
22
|
"@earendil-works/pi-tui": "^0.80.0",
|
|
23
|
-
"typebox": "^
|
|
23
|
+
"typebox": "^1.3.1"
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -6,21 +6,28 @@ export class Context7Provider implements SearchProvider {
|
|
|
6
6
|
name = "context7";
|
|
7
7
|
constructor(private apiKey: string) {}
|
|
8
8
|
|
|
9
|
+
private async searchLibrary(query: string): Promise<{ id: string; title: string } | null> {
|
|
10
|
+
const resp = await fetch(
|
|
11
|
+
`https://context7.com/api/v2/libs/search?libraryName=${encodeURIComponent(query)}&query=${encodeURIComponent(query)}`,
|
|
12
|
+
{ headers: { Authorization: `Bearer ${this.apiKey}` } }
|
|
13
|
+
);
|
|
14
|
+
const data = await resp.json();
|
|
15
|
+
return data.results?.[0] ?? null;
|
|
16
|
+
}
|
|
17
|
+
|
|
9
18
|
async search(query: string, maxResults: number): Promise<{ results: SearchResult[] }> {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
});
|
|
19
|
+
const lib = await this.searchLibrary(query);
|
|
20
|
+
if (!lib) return { results: [] };
|
|
21
|
+
|
|
22
|
+
const resp = await fetch(
|
|
23
|
+
`https://context7.com/api/v2/context?libraryId=${encodeURIComponent(lib.id)}&query=${encodeURIComponent(query)}`,
|
|
24
|
+
{ headers: { Authorization: `Bearer ${this.apiKey}` } }
|
|
25
|
+
);
|
|
18
26
|
const data = await resp.json();
|
|
19
|
-
const results: SearchResult[] = (data.results ?? []).map((r: any) => ({
|
|
20
|
-
title: r.title ?? r.name ??
|
|
21
|
-
url: r.url ?? r.
|
|
22
|
-
snippet: r.
|
|
23
|
-
score: r.score,
|
|
27
|
+
const results: SearchResult[] = (data.context ?? data.results ?? []).slice(0, maxResults).map((r: any) => ({
|
|
28
|
+
title: r.title ?? r.name ?? lib.title,
|
|
29
|
+
url: r.url ?? r.source ?? `https://context7.com${lib.id}`,
|
|
30
|
+
snippet: r.content ?? r.snippet ?? r.description ?? "",
|
|
24
31
|
}));
|
|
25
32
|
return { results };
|
|
26
33
|
}
|