@abhishek944/pi-web-access 0.0.0-stage → 0.1.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.
Files changed (201) hide show
  1. package/ASTACK.md +23 -0
  2. package/CHANGELOG.md +1289 -0
  3. package/LICENSE +21 -0
  4. package/README.md +1215 -2
  5. package/SECURITY.md +5 -0
  6. package/abortable.ts +17 -0
  7. package/activity.ts +101 -0
  8. package/anysearch.ts +188 -0
  9. package/auth-fetch.ts +152 -0
  10. package/baizhi.ts +124 -0
  11. package/banner.png +0 -0
  12. package/bocha.ts +203 -0
  13. package/brave-rate-limit.ts +176 -0
  14. package/brave.ts +247 -0
  15. package/brightdata-unlocker.ts +272 -0
  16. package/ceramic.ts +220 -0
  17. package/chrome-cookies.ts +752 -0
  18. package/cloudflare-search.ts +237 -0
  19. package/content-find.ts +255 -0
  20. package/crawl4ai.ts +196 -0
  21. package/credential-source.ts +242 -0
  22. package/curator-page.ts +3607 -0
  23. package/curator-run.ts +45 -0
  24. package/curator-server.ts +761 -0
  25. package/custom-search.ts +226 -0
  26. package/data-uri-sanitize.ts +406 -0
  27. package/datalab-pdf-extract.ts +568 -0
  28. package/declared-web-links.ts +173 -0
  29. package/deepseek.ts +377 -0
  30. package/degoog.ts +323 -0
  31. package/dist/index.js +28286 -0
  32. package/dist/mcp-cli.js +29186 -0
  33. package/dist/pi-mcp.js +20855 -0
  34. package/dist/types/abortable.d.ts +2 -0
  35. package/dist/types/activity.d.ts +33 -0
  36. package/dist/types/anysearch.d.ts +7 -0
  37. package/dist/types/auth-fetch.d.ts +14 -0
  38. package/dist/types/baizhi.d.ts +3 -0
  39. package/dist/types/bocha.d.ts +3 -0
  40. package/dist/types/brave-rate-limit.d.ts +35 -0
  41. package/dist/types/brave.d.ts +3 -0
  42. package/dist/types/brightdata-unlocker.d.ts +11 -0
  43. package/dist/types/ceramic.d.ts +3 -0
  44. package/dist/types/chrome-cookies.d.ts +44 -0
  45. package/dist/types/cloudflare-search.d.ts +4 -0
  46. package/dist/types/content-find.d.ts +10 -0
  47. package/dist/types/crawl4ai.d.ts +8 -0
  48. package/dist/types/credential-source.d.ts +29 -0
  49. package/dist/types/curator-page.d.ts +5 -0
  50. package/dist/types/curator-run.d.ts +10 -0
  51. package/dist/types/curator-server.d.ts +72 -0
  52. package/dist/types/custom-search.d.ts +22 -0
  53. package/dist/types/data-uri-sanitize.d.ts +20 -0
  54. package/dist/types/datalab-pdf-extract.d.ts +59 -0
  55. package/dist/types/declared-web-links.d.ts +7 -0
  56. package/dist/types/deepseek.d.ts +13 -0
  57. package/dist/types/degoog.d.ts +3 -0
  58. package/dist/types/domain-filter-normalization.d.ts +9 -0
  59. package/dist/types/duckduckgo-rate-limit.d.ts +52 -0
  60. package/dist/types/duckduckgo.d.ts +6 -0
  61. package/dist/types/endpoint-pdf-extract.d.ts +22 -0
  62. package/dist/types/exa.d.ts +17 -0
  63. package/dist/types/extract.d.ts +70 -0
  64. package/dist/types/feature-config.d.ts +2 -0
  65. package/dist/types/fetch-params.d.ts +39 -0
  66. package/dist/types/field-extract.d.ts +37 -0
  67. package/dist/types/firecrawl.d.ts +18 -0
  68. package/dist/types/gemini-adc.d.ts +9 -0
  69. package/dist/types/gemini-api.d.ts +37 -0
  70. package/dist/types/gemini-pdf-extract.d.ts +8 -0
  71. package/dist/types/gemini-search.d.ts +76 -0
  72. package/dist/types/gemini-url-context.d.ts +3 -0
  73. package/dist/types/gemini-web-config.d.ts +25 -0
  74. package/dist/types/gemini-web.d.ts +31 -0
  75. package/dist/types/github-api.d.ts +6 -0
  76. package/dist/types/github-extract.d.ts +19 -0
  77. package/dist/types/github-issue-pr.d.ts +28 -0
  78. package/dist/types/index.d.ts +53 -0
  79. package/dist/types/jina-search.d.ts +7 -0
  80. package/dist/types/kagi.d.ts +14 -0
  81. package/dist/types/keenable.d.ts +3 -0
  82. package/dist/types/kimi-search.d.ts +4 -0
  83. package/dist/types/linkup.d.ts +5 -0
  84. package/dist/types/mcp-cli.d.ts +2 -0
  85. package/dist/types/mcp-server.d.ts +10 -0
  86. package/dist/types/mcp-tool-definitions.d.ts +16 -0
  87. package/dist/types/mistral-search.d.ts +3 -0
  88. package/dist/types/ninerouter.d.ts +3 -0
  89. package/dist/types/offtopic-judge.d.ts +26 -0
  90. package/dist/types/ollama.d.ts +14 -0
  91. package/dist/types/openai-search.d.ts +23 -0
  92. package/dist/types/page-query.d.ts +22 -0
  93. package/dist/types/parallel-mcp.d.ts +10 -0
  94. package/dist/types/parallel.d.ts +13 -0
  95. package/dist/types/pdf-extract.d.ts +44 -0
  96. package/dist/types/perplexity.d.ts +26 -0
  97. package/dist/types/pi-mcp.d.ts +56 -0
  98. package/dist/types/pi-session-results.d.ts +8 -0
  99. package/dist/types/querit.d.ts +9 -0
  100. package/dist/types/query-rewrite.d.ts +2 -0
  101. package/dist/types/render-search-error.d.ts +56 -0
  102. package/dist/types/retrieval-only.d.ts +78 -0
  103. package/dist/types/rsc-extract.d.ts +11 -0
  104. package/dist/types/search-answer-formatting.d.ts +7 -0
  105. package/dist/types/search-result-count-normalization.d.ts +1 -0
  106. package/dist/types/searchinfinity.d.ts +7 -0
  107. package/dist/types/searxng.d.ts +3 -0
  108. package/dist/types/source-check.d.ts +102 -0
  109. package/dist/types/ssrf-protection.d.ts +66 -0
  110. package/dist/types/storage.d.ts +69 -0
  111. package/dist/types/summary-model-scope.d.ts +33 -0
  112. package/dist/types/summary-review.d.ts +30 -0
  113. package/dist/types/tabstack.d.ts +5 -0
  114. package/dist/types/tavily.d.ts +7 -0
  115. package/dist/types/tinyfish.d.ts +10 -0
  116. package/dist/types/tool-activation.d.ts +7 -0
  117. package/dist/types/tool-arguments.d.ts +1 -0
  118. package/dist/types/upgrade-notice.d.ts +6 -0
  119. package/dist/types/utils.d.ts +55 -0
  120. package/dist/types/valyu.d.ts +5 -0
  121. package/dist/types/video-extract.d.ts +15 -0
  122. package/dist/types/web-tool-contract.d.ts +98 -0
  123. package/dist/types/web-tool-core.d.ts +227 -0
  124. package/dist/types/xai-search.d.ts +12 -0
  125. package/dist/types/you.d.ts +3 -0
  126. package/dist/types/youtube-extract.d.ts +29 -0
  127. package/dist/types/zai.d.ts +3 -0
  128. package/docs/pi-mcp.md +41 -0
  129. package/domain-filter-normalization.ts +44 -0
  130. package/duckduckgo-rate-limit.ts +205 -0
  131. package/duckduckgo.ts +123 -0
  132. package/endpoint-pdf-extract.ts +225 -0
  133. package/exa.ts +620 -0
  134. package/extract.ts +1721 -0
  135. package/feature-config.ts +29 -0
  136. package/fetch-params.ts +147 -0
  137. package/field-extract.ts +347 -0
  138. package/firecrawl.ts +476 -0
  139. package/gemini-adc.ts +345 -0
  140. package/gemini-api.ts +368 -0
  141. package/gemini-pdf-extract.ts +108 -0
  142. package/gemini-search.ts +1162 -0
  143. package/gemini-url-context.ts +128 -0
  144. package/gemini-web-config.ts +131 -0
  145. package/gemini-web.ts +527 -0
  146. package/github-api.ts +197 -0
  147. package/github-extract.ts +1064 -0
  148. package/github-issue-pr.ts +717 -0
  149. package/index.ts +2819 -0
  150. package/jina-search.ts +275 -0
  151. package/kagi.ts +257 -0
  152. package/keenable.ts +222 -0
  153. package/kimi-search.ts +209 -0
  154. package/linkup.ts +170 -0
  155. package/mcp-cli.ts +40 -0
  156. package/mcp-server.ts +84 -0
  157. package/mcp-tool-definitions.ts +143 -0
  158. package/mistral-search.ts +268 -0
  159. package/ninerouter.ts +92 -0
  160. package/offtopic-judge.ts +72 -0
  161. package/ollama.ts +237 -0
  162. package/openai-search.ts +855 -0
  163. package/package.json +108 -4
  164. package/page-query.ts +185 -0
  165. package/parallel-mcp.ts +255 -0
  166. package/parallel.ts +373 -0
  167. package/pdf-extract.ts +447 -0
  168. package/perplexity.ts +245 -0
  169. package/pi-mcp.ts +139 -0
  170. package/pi-session-results.ts +40 -0
  171. package/pi-web-fetch-demo.mp4 +0 -0
  172. package/promise-try.d.ts +7 -0
  173. package/querit.ts +394 -0
  174. package/query-rewrite.ts +84 -0
  175. package/render-search-error.ts +170 -0
  176. package/retrieval-only.ts +102 -0
  177. package/rsc-extract.ts +338 -0
  178. package/search-answer-formatting.ts +11 -0
  179. package/search-result-count-normalization.ts +4 -0
  180. package/searchinfinity.ts +246 -0
  181. package/searxng.ts +236 -0
  182. package/source-check.ts +269 -0
  183. package/ssrf-protection.ts +602 -0
  184. package/storage.ts +547 -0
  185. package/summary-model-scope.ts +72 -0
  186. package/summary-review.ts +476 -0
  187. package/tabstack.ts +289 -0
  188. package/tavily.ts +257 -0
  189. package/tinyfish.ts +373 -0
  190. package/tool-activation.ts +169 -0
  191. package/tool-arguments.ts +23 -0
  192. package/upgrade-notice.ts +47 -0
  193. package/utils.ts +693 -0
  194. package/valyu.ts +177 -0
  195. package/video-extract.ts +398 -0
  196. package/web-tool-contract.ts +93 -0
  197. package/web-tool-core.ts +1810 -0
  198. package/xai-search.ts +443 -0
  199. package/you.ts +165 -0
  200. package/youtube-extract.ts +336 -0
  201. package/zai.ts +161 -0
package/github-api.ts ADDED
@@ -0,0 +1,197 @@
1
+ import { execFile } from "node:child_process";
2
+ import type { ExtractedContent } from "./extract.ts";
3
+ import type { GitHubUrlInfo } from "./github-extract.ts";
4
+
5
+ const MAX_TREE_ENTRIES = 200;
6
+ const MAX_INLINE_FILE_CHARS = 100_000;
7
+
8
+ let ghAvailable: boolean | null = null;
9
+ let ghHintShown = false;
10
+
11
+ export async function checkGhAvailable(signal?: AbortSignal): Promise<boolean> {
12
+ if (ghAvailable !== null) return ghAvailable;
13
+
14
+ return new Promise((resolve) => {
15
+ execFile("gh", ["--version"], { timeout: 5000, ...(signal ? { signal } : {}) }, (err) => {
16
+ const available = !err;
17
+ if (!signal?.aborted) ghAvailable = available;
18
+ resolve(available);
19
+ });
20
+ });
21
+ }
22
+
23
+ export function showGhHint(): void {
24
+ if (!ghHintShown) {
25
+ ghHintShown = true;
26
+ console.error("[pi-web-access] Install `gh` CLI for better GitHub repo access including private repos.");
27
+ }
28
+ }
29
+
30
+ export async function checkRepoSize(owner: string, repo: string): Promise<number | null> {
31
+ if (!(await checkGhAvailable())) return null;
32
+
33
+ return new Promise((resolve) => {
34
+ execFile("gh", ["api", `repos/${owner}/${repo}`, "--jq", ".size"], { timeout: 10000 }, (err, stdout) => {
35
+ if (err) {
36
+ resolve(null);
37
+ return;
38
+ }
39
+ const kb = parseInt(stdout.trim(), 10);
40
+ resolve(Number.isNaN(kb) ? null : kb);
41
+ });
42
+ });
43
+ }
44
+
45
+ async function getDefaultBranch(owner: string, repo: string): Promise<string | null> {
46
+ if (!(await checkGhAvailable())) return null;
47
+
48
+ return new Promise((resolve) => {
49
+ execFile("gh", ["api", `repos/${owner}/${repo}`, "--jq", ".default_branch"], { timeout: 10000 }, (err, stdout) => {
50
+ if (err) {
51
+ resolve(null);
52
+ return;
53
+ }
54
+ const branch = stdout.trim();
55
+ resolve(branch || null);
56
+ });
57
+ });
58
+ }
59
+
60
+ async function fetchTreeViaApi(owner: string, repo: string, ref: string): Promise<string | null> {
61
+ if (!(await checkGhAvailable())) return null;
62
+
63
+ return new Promise((resolve) => {
64
+ execFile(
65
+ "gh",
66
+ ["api", `repos/${owner}/${repo}/git/trees/${ref}?recursive=1`, "--jq", ".tree[].path"],
67
+ { timeout: 15000, maxBuffer: 5 * 1024 * 1024 },
68
+ (err, stdout) => {
69
+ if (err) {
70
+ resolve(null);
71
+ return;
72
+ }
73
+ const paths = stdout.trim().split("\n").filter(Boolean);
74
+ if (paths.length === 0) {
75
+ resolve(null);
76
+ return;
77
+ }
78
+ const truncated = paths.length > MAX_TREE_ENTRIES;
79
+ const display = paths.slice(0, MAX_TREE_ENTRIES).join("\n");
80
+ resolve(truncated ? display + `\n... (${paths.length} total entries)` : display);
81
+ },
82
+ );
83
+ });
84
+ }
85
+
86
+ async function fetchReadmeViaApi(owner: string, repo: string, ref: string): Promise<string | null> {
87
+ if (!(await checkGhAvailable())) return null;
88
+
89
+ return new Promise((resolve) => {
90
+ execFile(
91
+ "gh",
92
+ ["api", `repos/${owner}/${repo}/readme?ref=${ref}`, "--jq", ".content"],
93
+ { timeout: 10000 },
94
+ (err, stdout) => {
95
+ if (err) {
96
+ resolve(null);
97
+ return;
98
+ }
99
+ try {
100
+ const decoded = Buffer.from(stdout.trim(), "base64").toString("utf-8");
101
+ resolve(decoded.length > MAX_INLINE_FILE_CHARS ? `${decoded.slice(0, MAX_INLINE_FILE_CHARS)}\n\n[README truncated at 100K chars]` : decoded);
102
+ } catch {
103
+ resolve(null);
104
+ }
105
+ },
106
+ );
107
+ });
108
+ }
109
+
110
+ async function fetchFileViaApi(owner: string, repo: string, path: string, ref: string): Promise<string | null> {
111
+ if (!(await checkGhAvailable())) return null;
112
+
113
+ return new Promise((resolve) => {
114
+ execFile(
115
+ "gh",
116
+ ["api", `repos/${owner}/${repo}/contents/${path}?ref=${ref}`, "--jq", ".content"],
117
+ { timeout: 10000, maxBuffer: 2 * 1024 * 1024 },
118
+ (err, stdout) => {
119
+ if (err) {
120
+ resolve(null);
121
+ return;
122
+ }
123
+ try {
124
+ resolve(Buffer.from(stdout.trim(), "base64").toString("utf-8"));
125
+ } catch {
126
+ resolve(null);
127
+ }
128
+ },
129
+ );
130
+ });
131
+ }
132
+
133
+ export async function fetchViaApi(
134
+ url: string,
135
+ owner: string,
136
+ repo: string,
137
+ info: GitHubUrlInfo,
138
+ sizeNote?: string,
139
+ ): Promise<ExtractedContent | null> {
140
+ const ref = info.ref || (await getDefaultBranch(owner, repo));
141
+ if (!ref) return null;
142
+
143
+ const lines: string[] = [];
144
+ if (sizeNote) {
145
+ lines.push(sizeNote);
146
+ lines.push("");
147
+ }
148
+
149
+ if (info.type === "blob" && info.path) {
150
+ const content = await fetchFileViaApi(owner, repo, info.path, ref);
151
+ if (!content) return null;
152
+
153
+ lines.push(`## ${info.path}`);
154
+ if (content.length > MAX_INLINE_FILE_CHARS) {
155
+ lines.push(content.slice(0, MAX_INLINE_FILE_CHARS));
156
+ lines.push(`\n[File truncated at 100K chars]`);
157
+ } else {
158
+ lines.push(content);
159
+ }
160
+
161
+ return {
162
+ url,
163
+ title: `${owner}/${repo} - ${info.path}`,
164
+ content: lines.join("\n"),
165
+ error: null,
166
+ };
167
+ }
168
+
169
+ const [tree, readme] = await Promise.all([
170
+ fetchTreeViaApi(owner, repo, ref),
171
+ fetchReadmeViaApi(owner, repo, ref),
172
+ ]);
173
+
174
+ if (!tree && !readme) return null;
175
+
176
+ if (tree) {
177
+ lines.push("## Structure");
178
+ lines.push(tree);
179
+ lines.push("");
180
+ }
181
+
182
+ if (readme) {
183
+ lines.push("## README.md");
184
+ lines.push(readme);
185
+ lines.push("");
186
+ }
187
+
188
+ lines.push("This is an API-only view. Clone the repo or use `read`/`bash` for deeper exploration.");
189
+
190
+ const title = info.path ? `${owner}/${repo} - ${info.path}` : `${owner}/${repo}`;
191
+ return {
192
+ url,
193
+ title,
194
+ content: lines.join("\n"),
195
+ error: null,
196
+ };
197
+ }