pi-all-search 1.0.7 → 1.0.8

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-all-search",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "All-in-one web search extension for Pi — exa, tavily, anysearch, firecrawl, context7",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -7,22 +7,38 @@ export class AnysearchProvider implements SearchProvider {
7
7
  constructor(private apiKey: string) {}
8
8
 
9
9
  async search(query: string, maxResults: number): Promise<{ results: SearchResult[] }> {
10
- const resp = await fetch("https://api.anysearch.dev/v1/search", {
10
+ const resp = await fetch("https://api.anysearch.com/mcp", {
11
11
  method: "POST",
12
- headers: { "Content-Type": "application/json", Authorization: `Bearer ${this.apiKey}` },
13
- body: JSON.stringify({ q: query, limit: maxResults }),
12
+ headers: {
13
+ "Content-Type": "application/json",
14
+ Authorization: `Bearer ${this.apiKey}`,
15
+ },
16
+ body: JSON.stringify({
17
+ jsonrpc: "2.0",
18
+ id: 1,
19
+ method: "tools/call",
20
+ params: { name: "search", arguments: { query, max_results: maxResults } },
21
+ }),
14
22
  });
15
23
  const data = await resp.json();
16
- const results: SearchResult[] = (data.results ?? []).map((r: any) => ({
17
- title: r.title ?? "",
18
- url: r.url ?? "",
19
- snippet: r.description ?? r.snippet ?? "",
20
- score: r.score,
21
- }));
22
- return { results };
24
+ const text = data.result?.content?.[0]?.text ?? "";
25
+ return { results: this.parseResults(text) };
23
26
  }
24
27
 
25
- async verticalSearch(domain: string, subDomain: string, query: string, maxResults: number): Promise<{ results: SearchResult[] }> {
26
- return this.search(query, maxResults);
28
+ private parseResults(text: string): SearchResult[] {
29
+ const results: SearchResult[] = [];
30
+ const sections = text.split(/^### \d+\. /m).slice(1);
31
+ for (const section of sections) {
32
+ const lines = section.trim().split("\n");
33
+ const title = lines[0]?.trim() ?? "";
34
+ const urlLine = lines.find((l) => l.startsWith("- **URL**:"));
35
+ const url = urlLine?.replace("- **URL**: ", "").replace(/\*\*/g, "").trim() ?? "";
36
+ const snippet = lines
37
+ .filter((l) => !l.startsWith("- **URL**:") && l.trim() && !l.startsWith("#"))
38
+ .join(" ")
39
+ .slice(0, 300);
40
+ if (title) results.push({ title, url, snippet });
41
+ }
42
+ return results;
27
43
  }
28
44
  }