@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.
- package/ASTACK.md +23 -0
- package/CHANGELOG.md +1289 -0
- package/LICENSE +21 -0
- package/README.md +1215 -2
- package/SECURITY.md +5 -0
- package/abortable.ts +17 -0
- package/activity.ts +101 -0
- package/anysearch.ts +188 -0
- package/auth-fetch.ts +152 -0
- package/baizhi.ts +124 -0
- package/banner.png +0 -0
- package/bocha.ts +203 -0
- package/brave-rate-limit.ts +176 -0
- package/brave.ts +247 -0
- package/brightdata-unlocker.ts +272 -0
- package/ceramic.ts +220 -0
- package/chrome-cookies.ts +752 -0
- package/cloudflare-search.ts +237 -0
- package/content-find.ts +255 -0
- package/crawl4ai.ts +196 -0
- package/credential-source.ts +242 -0
- package/curator-page.ts +3607 -0
- package/curator-run.ts +45 -0
- package/curator-server.ts +761 -0
- package/custom-search.ts +226 -0
- package/data-uri-sanitize.ts +406 -0
- package/datalab-pdf-extract.ts +568 -0
- package/declared-web-links.ts +173 -0
- package/deepseek.ts +377 -0
- package/degoog.ts +323 -0
- package/dist/index.js +28286 -0
- package/dist/mcp-cli.js +29186 -0
- package/dist/pi-mcp.js +20855 -0
- package/dist/types/abortable.d.ts +2 -0
- package/dist/types/activity.d.ts +33 -0
- package/dist/types/anysearch.d.ts +7 -0
- package/dist/types/auth-fetch.d.ts +14 -0
- package/dist/types/baizhi.d.ts +3 -0
- package/dist/types/bocha.d.ts +3 -0
- package/dist/types/brave-rate-limit.d.ts +35 -0
- package/dist/types/brave.d.ts +3 -0
- package/dist/types/brightdata-unlocker.d.ts +11 -0
- package/dist/types/ceramic.d.ts +3 -0
- package/dist/types/chrome-cookies.d.ts +44 -0
- package/dist/types/cloudflare-search.d.ts +4 -0
- package/dist/types/content-find.d.ts +10 -0
- package/dist/types/crawl4ai.d.ts +8 -0
- package/dist/types/credential-source.d.ts +29 -0
- package/dist/types/curator-page.d.ts +5 -0
- package/dist/types/curator-run.d.ts +10 -0
- package/dist/types/curator-server.d.ts +72 -0
- package/dist/types/custom-search.d.ts +22 -0
- package/dist/types/data-uri-sanitize.d.ts +20 -0
- package/dist/types/datalab-pdf-extract.d.ts +59 -0
- package/dist/types/declared-web-links.d.ts +7 -0
- package/dist/types/deepseek.d.ts +13 -0
- package/dist/types/degoog.d.ts +3 -0
- package/dist/types/domain-filter-normalization.d.ts +9 -0
- package/dist/types/duckduckgo-rate-limit.d.ts +52 -0
- package/dist/types/duckduckgo.d.ts +6 -0
- package/dist/types/endpoint-pdf-extract.d.ts +22 -0
- package/dist/types/exa.d.ts +17 -0
- package/dist/types/extract.d.ts +70 -0
- package/dist/types/feature-config.d.ts +2 -0
- package/dist/types/fetch-params.d.ts +39 -0
- package/dist/types/field-extract.d.ts +37 -0
- package/dist/types/firecrawl.d.ts +18 -0
- package/dist/types/gemini-adc.d.ts +9 -0
- package/dist/types/gemini-api.d.ts +37 -0
- package/dist/types/gemini-pdf-extract.d.ts +8 -0
- package/dist/types/gemini-search.d.ts +76 -0
- package/dist/types/gemini-url-context.d.ts +3 -0
- package/dist/types/gemini-web-config.d.ts +25 -0
- package/dist/types/gemini-web.d.ts +31 -0
- package/dist/types/github-api.d.ts +6 -0
- package/dist/types/github-extract.d.ts +19 -0
- package/dist/types/github-issue-pr.d.ts +28 -0
- package/dist/types/index.d.ts +53 -0
- package/dist/types/jina-search.d.ts +7 -0
- package/dist/types/kagi.d.ts +14 -0
- package/dist/types/keenable.d.ts +3 -0
- package/dist/types/kimi-search.d.ts +4 -0
- package/dist/types/linkup.d.ts +5 -0
- package/dist/types/mcp-cli.d.ts +2 -0
- package/dist/types/mcp-server.d.ts +10 -0
- package/dist/types/mcp-tool-definitions.d.ts +16 -0
- package/dist/types/mistral-search.d.ts +3 -0
- package/dist/types/ninerouter.d.ts +3 -0
- package/dist/types/offtopic-judge.d.ts +26 -0
- package/dist/types/ollama.d.ts +14 -0
- package/dist/types/openai-search.d.ts +23 -0
- package/dist/types/page-query.d.ts +22 -0
- package/dist/types/parallel-mcp.d.ts +10 -0
- package/dist/types/parallel.d.ts +13 -0
- package/dist/types/pdf-extract.d.ts +44 -0
- package/dist/types/perplexity.d.ts +26 -0
- package/dist/types/pi-mcp.d.ts +56 -0
- package/dist/types/pi-session-results.d.ts +8 -0
- package/dist/types/querit.d.ts +9 -0
- package/dist/types/query-rewrite.d.ts +2 -0
- package/dist/types/render-search-error.d.ts +56 -0
- package/dist/types/retrieval-only.d.ts +78 -0
- package/dist/types/rsc-extract.d.ts +11 -0
- package/dist/types/search-answer-formatting.d.ts +7 -0
- package/dist/types/search-result-count-normalization.d.ts +1 -0
- package/dist/types/searchinfinity.d.ts +7 -0
- package/dist/types/searxng.d.ts +3 -0
- package/dist/types/source-check.d.ts +102 -0
- package/dist/types/ssrf-protection.d.ts +66 -0
- package/dist/types/storage.d.ts +69 -0
- package/dist/types/summary-model-scope.d.ts +33 -0
- package/dist/types/summary-review.d.ts +30 -0
- package/dist/types/tabstack.d.ts +5 -0
- package/dist/types/tavily.d.ts +7 -0
- package/dist/types/tinyfish.d.ts +10 -0
- package/dist/types/tool-activation.d.ts +7 -0
- package/dist/types/tool-arguments.d.ts +1 -0
- package/dist/types/upgrade-notice.d.ts +6 -0
- package/dist/types/utils.d.ts +55 -0
- package/dist/types/valyu.d.ts +5 -0
- package/dist/types/video-extract.d.ts +15 -0
- package/dist/types/web-tool-contract.d.ts +98 -0
- package/dist/types/web-tool-core.d.ts +227 -0
- package/dist/types/xai-search.d.ts +12 -0
- package/dist/types/you.d.ts +3 -0
- package/dist/types/youtube-extract.d.ts +29 -0
- package/dist/types/zai.d.ts +3 -0
- package/docs/pi-mcp.md +41 -0
- package/domain-filter-normalization.ts +44 -0
- package/duckduckgo-rate-limit.ts +205 -0
- package/duckduckgo.ts +123 -0
- package/endpoint-pdf-extract.ts +225 -0
- package/exa.ts +620 -0
- package/extract.ts +1721 -0
- package/feature-config.ts +29 -0
- package/fetch-params.ts +147 -0
- package/field-extract.ts +347 -0
- package/firecrawl.ts +476 -0
- package/gemini-adc.ts +345 -0
- package/gemini-api.ts +368 -0
- package/gemini-pdf-extract.ts +108 -0
- package/gemini-search.ts +1162 -0
- package/gemini-url-context.ts +128 -0
- package/gemini-web-config.ts +131 -0
- package/gemini-web.ts +527 -0
- package/github-api.ts +197 -0
- package/github-extract.ts +1064 -0
- package/github-issue-pr.ts +717 -0
- package/index.ts +2819 -0
- package/jina-search.ts +275 -0
- package/kagi.ts +257 -0
- package/keenable.ts +222 -0
- package/kimi-search.ts +209 -0
- package/linkup.ts +170 -0
- package/mcp-cli.ts +40 -0
- package/mcp-server.ts +84 -0
- package/mcp-tool-definitions.ts +143 -0
- package/mistral-search.ts +268 -0
- package/ninerouter.ts +92 -0
- package/offtopic-judge.ts +72 -0
- package/ollama.ts +237 -0
- package/openai-search.ts +855 -0
- package/package.json +108 -4
- package/page-query.ts +185 -0
- package/parallel-mcp.ts +255 -0
- package/parallel.ts +373 -0
- package/pdf-extract.ts +447 -0
- package/perplexity.ts +245 -0
- package/pi-mcp.ts +139 -0
- package/pi-session-results.ts +40 -0
- package/pi-web-fetch-demo.mp4 +0 -0
- package/promise-try.d.ts +7 -0
- package/querit.ts +394 -0
- package/query-rewrite.ts +84 -0
- package/render-search-error.ts +170 -0
- package/retrieval-only.ts +102 -0
- package/rsc-extract.ts +338 -0
- package/search-answer-formatting.ts +11 -0
- package/search-result-count-normalization.ts +4 -0
- package/searchinfinity.ts +246 -0
- package/searxng.ts +236 -0
- package/source-check.ts +269 -0
- package/ssrf-protection.ts +602 -0
- package/storage.ts +547 -0
- package/summary-model-scope.ts +72 -0
- package/summary-review.ts +476 -0
- package/tabstack.ts +289 -0
- package/tavily.ts +257 -0
- package/tinyfish.ts +373 -0
- package/tool-activation.ts +169 -0
- package/tool-arguments.ts +23 -0
- package/upgrade-notice.ts +47 -0
- package/utils.ts +693 -0
- package/valyu.ts +177 -0
- package/video-extract.ts +398 -0
- package/web-tool-contract.ts +93 -0
- package/web-tool-core.ts +1810 -0
- package/xai-search.ts +443 -0
- package/you.ts +165 -0
- package/youtube-extract.ts +336 -0
- package/zai.ts +161 -0
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { exec, execFile } from "node:child_process";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
3
|
+
import { promisify } from "node:util";
|
|
4
|
+
|
|
5
|
+
const execAsync = promisify(exec);
|
|
6
|
+
const execFileAsync = promisify(execFile);
|
|
7
|
+
const COMMAND_TIMEOUT_MS = 5_000;
|
|
8
|
+
const MAX_CREDENTIAL_BYTES = 16_384;
|
|
9
|
+
const ENV_SOURCE = /^\$(?:([A-Za-z_][A-Za-z0-9_]*)|\{([A-Za-z_][A-Za-z0-9_]*)\})$/;
|
|
10
|
+
const OP_SESSION_NAME = /^OP_SESSION_[A-Za-z0-9_]+$/;
|
|
11
|
+
// Pi drives the legacy WSL launcher through stdin; credential commands fall back to cmd.exe instead.
|
|
12
|
+
const LEGACY_WSL_BASH = /^[a-z]:\\windows\\(?:system32|sysnative)\\bash\.exe$/i;
|
|
13
|
+
const COMMAND_ENVIRONMENT_NAMES = [
|
|
14
|
+
"HOME",
|
|
15
|
+
"USER",
|
|
16
|
+
"LOGNAME",
|
|
17
|
+
"OP_SERVICE_ACCOUNT_TOKEN",
|
|
18
|
+
"PATH",
|
|
19
|
+
"LANG",
|
|
20
|
+
"LC_ALL",
|
|
21
|
+
"LC_CTYPE",
|
|
22
|
+
"TERM",
|
|
23
|
+
"TMPDIR",
|
|
24
|
+
"XDG_CONFIG_HOME",
|
|
25
|
+
"XDG_RUNTIME_DIR",
|
|
26
|
+
"DBUS_SESSION_BUS_ADDRESS",
|
|
27
|
+
"SSH_AUTH_SOCK",
|
|
28
|
+
"WSL_DISTRO_NAME",
|
|
29
|
+
"WSL_INTEROP",
|
|
30
|
+
// Git Bash derives $HOME from USERPROFILE, and Windows children need SystemRoot for networking and crypto.
|
|
31
|
+
"SystemRoot",
|
|
32
|
+
"windir",
|
|
33
|
+
"ComSpec",
|
|
34
|
+
"PATHEXT",
|
|
35
|
+
"USERPROFILE",
|
|
36
|
+
"HOMEDRIVE",
|
|
37
|
+
"HOMEPATH",
|
|
38
|
+
"APPDATA",
|
|
39
|
+
"LOCALAPPDATA",
|
|
40
|
+
"TEMP",
|
|
41
|
+
"TMP",
|
|
42
|
+
"ProgramData",
|
|
43
|
+
"ProgramFiles",
|
|
44
|
+
"ProgramFiles(x86)",
|
|
45
|
+
] as const;
|
|
46
|
+
|
|
47
|
+
export type CredentialFailureCategory =
|
|
48
|
+
| "invalid-source"
|
|
49
|
+
| "command-failed"
|
|
50
|
+
| "command-timeout"
|
|
51
|
+
| "command-aborted"
|
|
52
|
+
| "command-empty"
|
|
53
|
+
| "command-invalid-output"
|
|
54
|
+
| "command-output-too-large"
|
|
55
|
+
| "environment-empty"
|
|
56
|
+
| "oauth-credential-rejected";
|
|
57
|
+
|
|
58
|
+
export class CredentialResolutionError extends Error {
|
|
59
|
+
readonly provider: string;
|
|
60
|
+
readonly category: CredentialFailureCategory;
|
|
61
|
+
|
|
62
|
+
constructor(provider: string, category: CredentialFailureCategory) {
|
|
63
|
+
const suffix =
|
|
64
|
+
category === "command-aborted" ? "aborted" :
|
|
65
|
+
category === "oauth-credential-rejected" ? "OAuth token exchange rejected the credentials" :
|
|
66
|
+
category;
|
|
67
|
+
super(`${provider} credential resolution failed: ${suffix}`);
|
|
68
|
+
this.name = "CredentialResolutionError";
|
|
69
|
+
this.provider = provider;
|
|
70
|
+
this.category = category;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export interface CredentialCommandResult {
|
|
75
|
+
stdout: string | Buffer;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface CredentialCommandOptions {
|
|
79
|
+
signal?: AbortSignal;
|
|
80
|
+
timeoutMs: number;
|
|
81
|
+
maxOutputBytes: number;
|
|
82
|
+
environment: Record<string, string>;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export type CredentialCommandRunner = (
|
|
86
|
+
command: string,
|
|
87
|
+
options: CredentialCommandOptions,
|
|
88
|
+
) => Promise<CredentialCommandResult>;
|
|
89
|
+
|
|
90
|
+
export interface CredentialOptions {
|
|
91
|
+
provider: string;
|
|
92
|
+
configuredValue?: unknown;
|
|
93
|
+
environmentValue?: unknown;
|
|
94
|
+
environment?: Record<string, string | undefined>;
|
|
95
|
+
signal?: AbortSignal;
|
|
96
|
+
runCommand?: CredentialCommandRunner;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function redactCredential(text: string, credential: string | null | undefined): string {
|
|
100
|
+
return credential ? text.split(credential).join("[redacted]") : text;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function normalize(value: unknown): string | null {
|
|
104
|
+
if (typeof value !== "string") return null;
|
|
105
|
+
const normalized = value.trim();
|
|
106
|
+
return normalized.length > 0 ? normalized : null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function commandEnvironment(source: Record<string, string | undefined>): Record<string, string> {
|
|
110
|
+
const environment: Record<string, string> = {};
|
|
111
|
+
for (const name of COMMAND_ENVIRONMENT_NAMES) {
|
|
112
|
+
const value = source[name];
|
|
113
|
+
if (value !== undefined) environment[name] = value;
|
|
114
|
+
}
|
|
115
|
+
for (const [name, value] of Object.entries(source)) {
|
|
116
|
+
if (value !== undefined && OP_SESSION_NAME.test(name)) environment[name] = value;
|
|
117
|
+
}
|
|
118
|
+
return environment;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function configuredSource(options: CredentialOptions): string | null {
|
|
122
|
+
return normalize(options.configuredValue);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function explicitEnvironmentName(source: string): string | null {
|
|
126
|
+
const match = source.match(ENV_SOURCE);
|
|
127
|
+
return match ? match[1] ?? match[2] : null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function escapedSource(source: string): string | null {
|
|
131
|
+
if (source.startsWith("$$") || source.startsWith("$!")) return source.slice(1);
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function isMalformedExplicitSource(source: string): boolean {
|
|
136
|
+
return source.startsWith("$") && escapedSource(source) === null && explicitEnvironmentName(source) === null;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function bashOnPath(signal: AbortSignal | undefined, timeoutMs: number): Promise<string | null> {
|
|
140
|
+
try {
|
|
141
|
+
const { stdout } = await execFileAsync("where", ["bash.exe"], { encoding: "utf8", signal, timeout: timeoutMs, windowsHide: true });
|
|
142
|
+
return stdout.trim().split(/\r?\n/)[0] || null;
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Resolves bash on Windows in Pi's own `!command` order: Git Bash install locations, then bash.exe on PATH. */
|
|
149
|
+
export async function findWindowsBash(
|
|
150
|
+
environment: Record<string, string | undefined>,
|
|
151
|
+
exists: (path: string) => boolean,
|
|
152
|
+
findOnPath: () => Promise<string | null>,
|
|
153
|
+
): Promise<string | null> {
|
|
154
|
+
for (const root of [environment.ProgramFiles, environment["ProgramFiles(x86)"]]) {
|
|
155
|
+
const candidate = root ? `${root}\\Git\\bin\\bash.exe` : null;
|
|
156
|
+
if (candidate && exists(candidate)) return candidate;
|
|
157
|
+
}
|
|
158
|
+
const found = await findOnPath();
|
|
159
|
+
return found && exists(found) && !LEGACY_WSL_BASH.test(found.replace(/\//g, "\\")) ? found : null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
async function defaultRunCommand(
|
|
163
|
+
command: string,
|
|
164
|
+
options: CredentialCommandOptions,
|
|
165
|
+
): Promise<CredentialCommandResult> {
|
|
166
|
+
// The bash lookup and the command share one timeout budget and the caller's abort signal.
|
|
167
|
+
const deadline = Date.now() + options.timeoutMs;
|
|
168
|
+
const bash = process.platform === "win32"
|
|
169
|
+
? await findWindowsBash(process.env, existsSync, () => bashOnPath(options.signal, options.timeoutMs))
|
|
170
|
+
: null;
|
|
171
|
+
const execOptions = {
|
|
172
|
+
encoding: "utf8",
|
|
173
|
+
env: options.environment,
|
|
174
|
+
maxBuffer: options.maxOutputBytes + 1,
|
|
175
|
+
signal: options.signal,
|
|
176
|
+
timeout: Math.max(1, deadline - Date.now()),
|
|
177
|
+
windowsHide: true,
|
|
178
|
+
} as const;
|
|
179
|
+
const result = bash
|
|
180
|
+
? await execFileAsync(bash, ["-c", command], execOptions)
|
|
181
|
+
: await execAsync(command, execOptions);
|
|
182
|
+
return { stdout: result.stdout };
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function commandFailureCategory(error: unknown, signal?: AbortSignal): CredentialFailureCategory {
|
|
186
|
+
if (signal?.aborted) return "command-aborted";
|
|
187
|
+
if (error && typeof error === "object") {
|
|
188
|
+
const code = (error as { code?: string }).code;
|
|
189
|
+
if (code === "ERR_CHILD_PROCESS_STDIO_MAXBUFFER") return "command-output-too-large";
|
|
190
|
+
if ((error as { killed?: boolean }).killed || code === "ETIMEDOUT") return "command-timeout";
|
|
191
|
+
}
|
|
192
|
+
return "command-failed";
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export function hasCredentialSource(options: CredentialOptions): boolean {
|
|
196
|
+
const source = configuredSource(options);
|
|
197
|
+
if (source?.startsWith("!")) return true;
|
|
198
|
+
if (source?.startsWith("$")) return true;
|
|
199
|
+
return normalize(options.environmentValue) !== null || source !== null;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export async function resolveCredential(options: CredentialOptions): Promise<string | null> {
|
|
203
|
+
const source = configuredSource(options);
|
|
204
|
+
const escaped = source ? escapedSource(source) : null;
|
|
205
|
+
if (escaped !== null) return escaped;
|
|
206
|
+
if (source?.startsWith("!")) {
|
|
207
|
+
const command = source.slice(1).trim();
|
|
208
|
+
if (!command) throw new CredentialResolutionError(options.provider, "invalid-source");
|
|
209
|
+
let result: CredentialCommandResult;
|
|
210
|
+
try {
|
|
211
|
+
result = await (options.runCommand ?? defaultRunCommand)(command, {
|
|
212
|
+
signal: options.signal,
|
|
213
|
+
timeoutMs: COMMAND_TIMEOUT_MS,
|
|
214
|
+
maxOutputBytes: MAX_CREDENTIAL_BYTES,
|
|
215
|
+
environment: commandEnvironment(options.environment ?? process.env),
|
|
216
|
+
});
|
|
217
|
+
} catch (error) {
|
|
218
|
+
throw new CredentialResolutionError(options.provider, commandFailureCategory(error, options.signal));
|
|
219
|
+
}
|
|
220
|
+
const stdout = Buffer.isBuffer(result.stdout) ? result.stdout.toString("utf8") : result.stdout;
|
|
221
|
+
if (Buffer.byteLength(stdout, "utf8") > MAX_CREDENTIAL_BYTES) {
|
|
222
|
+
throw new CredentialResolutionError(options.provider, "command-output-too-large");
|
|
223
|
+
}
|
|
224
|
+
const value = stdout.trim();
|
|
225
|
+
if (!value) throw new CredentialResolutionError(options.provider, "command-empty");
|
|
226
|
+
if (/[\0-\x1f\x7f]/.test(value)) {
|
|
227
|
+
throw new CredentialResolutionError(options.provider, "command-invalid-output");
|
|
228
|
+
}
|
|
229
|
+
return value;
|
|
230
|
+
}
|
|
231
|
+
if (source && isMalformedExplicitSource(source)) {
|
|
232
|
+
throw new CredentialResolutionError(options.provider, "invalid-source");
|
|
233
|
+
}
|
|
234
|
+
if (source?.startsWith("$")) {
|
|
235
|
+
const name = explicitEnvironmentName(source);
|
|
236
|
+
if (!name) throw new CredentialResolutionError(options.provider, "invalid-source");
|
|
237
|
+
const value = normalize((options.environment ?? process.env)[name]);
|
|
238
|
+
if (!value) throw new CredentialResolutionError(options.provider, "environment-empty");
|
|
239
|
+
return value;
|
|
240
|
+
}
|
|
241
|
+
return normalize(options.environmentValue) ?? source;
|
|
242
|
+
}
|