@mrclrchtr/supi-web 1.12.0 → 1.12.1

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/README.md CHANGED
@@ -97,6 +97,6 @@ Skip step 1 if you already know the exact Context7 `library_id`.
97
97
 
98
98
  ## Context7 API key
99
99
 
100
- `web_docs_search` and `web_docs_fetch` use [Context7](https://context7.com/) through `@upstash/context7-sdk`.
100
+ `web_docs_search` and `web_docs_fetch` call the [Context7 REST API](https://context7.com/) directly.
101
101
 
102
- If `CONTEXT7_API_KEY` is set in your environment, the SDK uses it automatically for higher rate limits. Without a key, the tools still work with lower defaults.
102
+ Set `CONTEXT7_API_KEY` in your environment to authenticate with the Context7 API. Without a key, the tools will return an authentication error when called. Get a free API key at https://context7.com/dashboard.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-core",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "SuPi core — shared infrastructure for SuPi extensions (XML context tags, config system)",
5
5
  "license": "MIT",
6
6
  "repository": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mrclrchtr/supi-web",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "SuPi Web extension — fetch web pages as clean Markdown (web_fetch_md) and library docs via Context7 (web_docs_search, web_docs_fetch)",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -20,12 +20,11 @@
20
20
  "README.md"
21
21
  ],
22
22
  "dependencies": {
23
- "@upstash/context7-sdk": "^0.3.0",
24
23
  "jsdom": "^29.0.0",
25
24
  "@mozilla/readability": "^0.6.0",
26
25
  "turndown": "^7.2.0",
27
26
  "turndown-plugin-gfm": "^1.0.2",
28
- "@mrclrchtr/supi-core": "1.12.0"
27
+ "@mrclrchtr/supi-core": "1.12.1"
29
28
  },
30
29
  "bundledDependencies": [
31
30
  "@mrclrchtr/supi-core"
@@ -1,12 +1,19 @@
1
1
  /**
2
- * Context7 API client — thin wrapper around @upstash/context7-sdk.
2
+ * Context7 API client — calls the Context7 REST API directly via fetch(),
3
+ * matching the official Context7 pi extension pattern.
3
4
  *
4
- * API key is read automatically from CONTEXT7_API_KEY env var by the SDK.
5
+ * API key is read from CONTEXT7_API_KEY env var. Without a key, requests are
6
+ * sent without an Authorization header; the API will return 401.
5
7
  */
6
8
 
7
- import { Context7, Context7Error } from "@upstash/context7-sdk";
9
+ const BASE_URL = "https://context7.com/api";
8
10
 
9
- export { Context7Error };
11
+ export class Context7Error extends Error {
12
+ constructor(message: string) {
13
+ super(message);
14
+ this.name = "Context7Error";
15
+ }
16
+ }
10
17
 
11
18
  export interface SearchResult {
12
19
  id: string;
@@ -24,11 +31,74 @@ export interface DocSnippet {
24
31
  source: string;
25
32
  }
26
33
 
27
- const client = new Context7();
34
+ function authHeaders(): Record<string, string> {
35
+ const apiKey = process.env.CONTEXT7_API_KEY;
36
+ return apiKey ? { Authorization: `Bearer ${apiKey}` } : {};
37
+ }
38
+
39
+ async function parseErrorResponse(response: Response): Promise<string> {
40
+ try {
41
+ const json = (await response.json()) as { message?: string };
42
+ if (json.message) return json.message;
43
+ } catch {
44
+ // JSON parsing failed, fall through to status-based message
45
+ }
46
+
47
+ const hasKey = Boolean(process.env.CONTEXT7_API_KEY);
48
+ if (response.status === 429) {
49
+ return hasKey
50
+ ? "Rate limited or quota exceeded. Upgrade your plan at https://context7.com/plans for higher limits."
51
+ : "Rate limited or quota exceeded. Create a free API key at https://context7.com/dashboard for higher limits.";
52
+ }
53
+ if (response.status === 404) {
54
+ return "The library you are trying to access does not exist. Please try with a different library ID.";
55
+ }
56
+ if (response.status === 401) {
57
+ return "Invalid API key. Please check your API key. API keys should start with 'ctx7sk' prefix.";
58
+ }
59
+ return `Request failed with status ${response.status}. Please try again later.`;
60
+ }
61
+
62
+ interface ApiSearchResult {
63
+ id: string;
64
+ title: string;
65
+ description: string;
66
+ totalSnippets: number;
67
+ trustScore: number;
68
+ benchmarkScore: number;
69
+ versions?: string[];
70
+ }
71
+
72
+ interface ApiSearchResponse {
73
+ error?: string;
74
+ results: ApiSearchResult[];
75
+ }
76
+
77
+ function mapSearchResult(r: ApiSearchResult): SearchResult {
78
+ return {
79
+ id: r.id,
80
+ name: r.title,
81
+ description: r.description,
82
+ totalSnippets: r.totalSnippets,
83
+ trustScore: r.trustScore,
84
+ benchmarkScore: r.benchmarkScore,
85
+ versions: r.versions,
86
+ };
87
+ }
28
88
 
29
89
  export async function searchLibrary(query: string, libraryName: string): Promise<SearchResult[]> {
30
- const results = await client.searchLibrary(query, libraryName);
31
- return results as unknown as SearchResult[];
90
+ const url = new URL(`${BASE_URL}/v2/libs/search`);
91
+ url.searchParams.set("query", query);
92
+ url.searchParams.set("libraryName", libraryName);
93
+
94
+ const response = await fetch(url, { headers: authHeaders() });
95
+
96
+ if (!response.ok) {
97
+ throw new Context7Error(await parseErrorResponse(response));
98
+ }
99
+
100
+ const data = (await response.json()) as ApiSearchResponse;
101
+ return (data.results ?? []).map(mapSearchResult);
32
102
  }
33
103
 
34
104
  export async function getContext(
@@ -36,6 +106,20 @@ export async function getContext(
36
106
  libraryId: string,
37
107
  raw?: boolean,
38
108
  ): Promise<string | DocSnippet[]> {
39
- const options = raw ? ({ type: "json" } as const) : ({ type: "txt" } as const);
40
- return client.getContext(query, libraryId, options) as Promise<string | DocSnippet[]>;
109
+ const url = new URL(`${BASE_URL}/v2/context`);
110
+ url.searchParams.set("query", query);
111
+ url.searchParams.set("libraryId", libraryId);
112
+
113
+ const response = await fetch(url, { headers: authHeaders() });
114
+
115
+ if (!response.ok) {
116
+ throw new Context7Error(await parseErrorResponse(response));
117
+ }
118
+
119
+ if (raw) {
120
+ const json = (await response.json()) as DocSnippet[];
121
+ return json;
122
+ }
123
+
124
+ return response.text();
41
125
  }
package/src/fetch.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * HTTP fetching with content negotiation and Markdown sniffing.
3
3
  */
4
4
 
5
- // biome-ignore lint/nursery/noExcessiveLinesPerFile: expanded guessLanguage map pushes past the threshold; nursery rule, not stable
5
+ // biome-ignore lint/style/noExcessiveLinesPerFile: expanded guessLanguage map pushes past the threshold; nursery rule, not stable
6
6
  const USER_AGENT = "Mozilla/5.0 (compatible; supi-web/1.0; +https://github.com/mrclrchtr/supi)";
7
7
  const ACCEPT_SIBLING = "text/markdown,text/plain;q=0.9,*/*;q=0.1";
8
8
  const DEFAULT_TIMEOUT_MS = 30_000;