@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,7 @@
|
|
|
1
|
+
import { type ExtensionAPI } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
export type WebCapability = "search" | "source-check" | "fetch" | "stored-content";
|
|
3
|
+
export interface WebActivationTool {
|
|
4
|
+
name: string;
|
|
5
|
+
capability: WebCapability;
|
|
6
|
+
}
|
|
7
|
+
export declare function registerWebToolActivation(pi: ExtensionAPI, tools: ReadonlyArray<WebActivationTool>, mode: "auto" | "dynamic"): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseStringifiedArrays(args: unknown, keys: readonly string[]): unknown;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export declare function getWebSearchConfigDir(): string;
|
|
2
|
+
export declare function getWebSearchConfigPath(): string;
|
|
3
|
+
interface ApiBaseUrlOptions {
|
|
4
|
+
configKey: string;
|
|
5
|
+
configuredValue: unknown;
|
|
6
|
+
defaultValue: string;
|
|
7
|
+
environmentKey: string;
|
|
8
|
+
environmentValue: string | undefined;
|
|
9
|
+
}
|
|
10
|
+
export declare function isLoopbackHostname(hostnameValue: string): boolean;
|
|
11
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
12
|
+
export declare function resolveApiBaseUrl(options: ApiBaseUrlOptions): string;
|
|
13
|
+
/** Resolve a provider's API root without dropping its endpoint path or a gateway prefix. */
|
|
14
|
+
export declare function resolveProviderApiUrl(configStem: string, defaultUrl: string, configuredValue: unknown): string;
|
|
15
|
+
export declare function fetchWithCredentialRedirects(url: string, init: RequestInit, credentialHeaders: readonly string[], credentialQueryParams?: readonly string[]): Promise<Response>;
|
|
16
|
+
export interface CuratorNetworkConfig {
|
|
17
|
+
/** Whether remote access was opted into via curatorRemote. */
|
|
18
|
+
enabled: boolean;
|
|
19
|
+
host: string;
|
|
20
|
+
bind: string;
|
|
21
|
+
}
|
|
22
|
+
/** Resolves the curator server bind address and URL host from `curatorRemote`. */
|
|
23
|
+
export declare function resolveCuratorNetworkConfig(): CuratorNetworkConfig;
|
|
24
|
+
export declare function formatSeconds(s: number): string;
|
|
25
|
+
export declare function readExecError(err: unknown): {
|
|
26
|
+
code?: string;
|
|
27
|
+
stderr: string;
|
|
28
|
+
message: string;
|
|
29
|
+
};
|
|
30
|
+
export declare function isTimeoutError(err: unknown): boolean;
|
|
31
|
+
export declare function trimErrorText(text: string): string;
|
|
32
|
+
export declare const FRAME_SCALE_FILTER = "scale=w='min(2000,iw)':h='min(2000,ih)':force_original_aspect_ratio=decrease";
|
|
33
|
+
export declare function mapFfmpegError(err: unknown): string;
|
|
34
|
+
export declare function normalizeProxyUrl(value: unknown, source: string): string | null;
|
|
35
|
+
export declare function loadConfiguredProxy(): string | null;
|
|
36
|
+
export declare function runWithProxy<T>(proxy: string | undefined, fn: () => T): T;
|
|
37
|
+
export declare function getActiveProxy(): string | null;
|
|
38
|
+
export declare function hasScopedProxyDecision(): boolean;
|
|
39
|
+
/** True when a URL must NOT be sent through the active proxy. */
|
|
40
|
+
export declare function isProxyBypassedUrl(url: URL): boolean;
|
|
41
|
+
export interface ProxiedRequestInit extends RequestInit {
|
|
42
|
+
/** Caller-supplied proxy; bypasses AsyncLocalStorage for pLimit-safe contexts. */
|
|
43
|
+
__proxy?: string;
|
|
44
|
+
}
|
|
45
|
+
/** Wraps globalThis.fetch so every http(s) call routes through curl while a proxy is active. Idempotent. */
|
|
46
|
+
export declare function installGlobalProxyFetch(): void;
|
|
47
|
+
/** A fetch for the extension's own page requests that runs the `fetchContent.curl` command instead of
|
|
48
|
+
* Node's fetch. It uses a proxy the way the proxy transport does: a per-call `__proxy` wins, `""`
|
|
49
|
+
* connects directly, and loopback and NO_PROXY hosts are never proxied. With no proxy decision,
|
|
50
|
+
* `envProxy` names the env proxy the SSRF check trusted for the URL. Callers pass a URL. */
|
|
51
|
+
export declare function createCurlFetch(command: readonly string[], { maxBytes, envProxy }: {
|
|
52
|
+
maxBytes: number;
|
|
53
|
+
envProxy: (url: URL) => string | null;
|
|
54
|
+
}): typeof fetch;
|
|
55
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ExtractedContent, type ExtractOptions, type FrameResult } from "./extract.ts";
|
|
2
|
+
interface VideoFileInfo {
|
|
3
|
+
absolutePath: string;
|
|
4
|
+
mimeType: string;
|
|
5
|
+
sizeBytes: number;
|
|
6
|
+
maxSizeBytes: number;
|
|
7
|
+
withinUploadLimit: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function isVideoFile(input: string): VideoFileInfo | null;
|
|
10
|
+
export declare function extractVideo(info: VideoFileInfo, signal?: AbortSignal, options?: ExtractOptions): Promise<ExtractedContent | null>;
|
|
11
|
+
export declare function extractVideoFrame(filePath: string, seconds?: number): Promise<FrameResult>;
|
|
12
|
+
export declare function getLocalVideoDuration(filePath: string): Promise<number | {
|
|
13
|
+
error: string;
|
|
14
|
+
}>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { Usage } from "@earendil-works/pi-ai/compat";
|
|
2
|
+
import type { FindMode } from "./content-find.ts";
|
|
3
|
+
import type { PageExtraction } from "./field-extract.ts";
|
|
4
|
+
import type { RecencyFilter } from "./source-check.ts";
|
|
5
|
+
export type WebToolContent = {
|
|
6
|
+
type: "text";
|
|
7
|
+
text: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: "image";
|
|
10
|
+
data: string;
|
|
11
|
+
mimeType: string;
|
|
12
|
+
};
|
|
13
|
+
export interface WebToolResult {
|
|
14
|
+
content: WebToolContent[];
|
|
15
|
+
details: Record<string, unknown>;
|
|
16
|
+
isError?: boolean;
|
|
17
|
+
/** Data for programmatic callers such as Pi codemode scripts; never sent to the model or over MCP. */
|
|
18
|
+
structuredContent?: WebSearchStructuredContent | FetchContentStructuredContent;
|
|
19
|
+
/** Combined usage of the model calls the tool made, which Pi adds to the session's totals; absent when it made none. */
|
|
20
|
+
usage?: Usage;
|
|
21
|
+
}
|
|
22
|
+
export type WebSearchStructuredContent = {
|
|
23
|
+
responseId: string;
|
|
24
|
+
fetchId: string | null;
|
|
25
|
+
queries: Array<{
|
|
26
|
+
query: string;
|
|
27
|
+
answer: string;
|
|
28
|
+
error: string | null;
|
|
29
|
+
provider?: string;
|
|
30
|
+
providers?: string[];
|
|
31
|
+
results: Array<{
|
|
32
|
+
title: string;
|
|
33
|
+
url: string;
|
|
34
|
+
snippet: string;
|
|
35
|
+
}>;
|
|
36
|
+
}>;
|
|
37
|
+
};
|
|
38
|
+
export type FetchContentStructuredContent = {
|
|
39
|
+
responseId: string | null;
|
|
40
|
+
/** In extract mode, each fetched URL also has its `extraction`: typed fields per name, or why extraction failed. */
|
|
41
|
+
urls: Array<{
|
|
42
|
+
url: string;
|
|
43
|
+
title: string;
|
|
44
|
+
content: string;
|
|
45
|
+
error: string | null;
|
|
46
|
+
mimeType?: string;
|
|
47
|
+
status?: number;
|
|
48
|
+
duration?: number;
|
|
49
|
+
extraction?: PageExtraction;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
export interface WebSearchCallParams {
|
|
53
|
+
model?: string;
|
|
54
|
+
objective?: string;
|
|
55
|
+
query?: string;
|
|
56
|
+
queries?: string[];
|
|
57
|
+
numResults?: number;
|
|
58
|
+
includeContent?: boolean;
|
|
59
|
+
recencyFilter?: RecencyFilter;
|
|
60
|
+
domainFilter?: string[];
|
|
61
|
+
category?: string;
|
|
62
|
+
provider?: string | string[];
|
|
63
|
+
proxy?: string;
|
|
64
|
+
}
|
|
65
|
+
export interface FetchContentCallParams {
|
|
66
|
+
url?: string;
|
|
67
|
+
urls?: string[];
|
|
68
|
+
mode?: string;
|
|
69
|
+
forceClone?: boolean;
|
|
70
|
+
proxy?: string;
|
|
71
|
+
}
|
|
72
|
+
export interface GetSearchContentCallParams {
|
|
73
|
+
responseId: string;
|
|
74
|
+
query?: string;
|
|
75
|
+
queryIndex?: number;
|
|
76
|
+
url?: string;
|
|
77
|
+
urlIndex?: number;
|
|
78
|
+
offset?: number;
|
|
79
|
+
limit?: number;
|
|
80
|
+
findText?: string | string[];
|
|
81
|
+
findMode?: FindMode;
|
|
82
|
+
}
|
|
83
|
+
export interface SourceCheckCallParams {
|
|
84
|
+
claim: string;
|
|
85
|
+
queries?: string[];
|
|
86
|
+
numResults?: number;
|
|
87
|
+
fetchContent?: boolean;
|
|
88
|
+
recencyFilter?: RecencyFilter;
|
|
89
|
+
domainFilter?: string[];
|
|
90
|
+
provider?: string | string[];
|
|
91
|
+
proxy?: string;
|
|
92
|
+
}
|
|
93
|
+
export interface WebToolCore {
|
|
94
|
+
webSearch(params: WebSearchCallParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
95
|
+
fetchContent(params: FetchContentCallParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
96
|
+
getSearchContent(params: GetSearchContentCallParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
97
|
+
sourceCheck(params: SourceCheckCallParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
98
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import type { Usage } from "@earendil-works/pi-ai/compat";
|
|
2
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import type { BrowserCookieConsent } from "./gemini-web-config.ts";
|
|
4
|
+
import type { KeyId } from "@earendil-works/pi-tui";
|
|
5
|
+
import type { ExtractedContent, ExtractOptions } from "./extract.ts";
|
|
6
|
+
import { type FetchContentParams } from "./fetch-params.ts";
|
|
7
|
+
import { type SearchProvider, type SearchProviderSelection } from "./gemini-search.ts";
|
|
8
|
+
import { type QueryResultData, type StoredSearchData } from "./storage.ts";
|
|
9
|
+
import { type RecencyFilter } from "./source-check.ts";
|
|
10
|
+
import type { SummaryMeta } from "./summary-review.ts";
|
|
11
|
+
import type { FetchContentCallParams, GetSearchContentCallParams, SourceCheckCallParams, WebSearchCallParams, WebToolCore, WebToolResult } from "./web-tool-contract.ts";
|
|
12
|
+
export declare const WEB_SEARCH_CONFIG_PATH: string;
|
|
13
|
+
export interface WebSearchConfig {
|
|
14
|
+
anysearchApiKey?: unknown;
|
|
15
|
+
brightdataApiKey?: unknown;
|
|
16
|
+
kagiApiKey?: unknown;
|
|
17
|
+
ollamaApiKey?: unknown;
|
|
18
|
+
youApiKey?: unknown;
|
|
19
|
+
baizhiApiKey?: unknown;
|
|
20
|
+
zaiApiKey?: unknown;
|
|
21
|
+
tinyfishApiKey?: unknown;
|
|
22
|
+
valyuApiKey?: unknown;
|
|
23
|
+
keenableApiKey?: unknown;
|
|
24
|
+
ceramicApiKey?: unknown;
|
|
25
|
+
linkupApiKey?: unknown;
|
|
26
|
+
linkupDepth?: unknown;
|
|
27
|
+
ninerouterBaseUrl?: unknown;
|
|
28
|
+
ninerouterApiKey?: unknown;
|
|
29
|
+
ninerouterProvider?: unknown;
|
|
30
|
+
cloudflareAccountId?: unknown;
|
|
31
|
+
cloudflareGatewayId?: unknown;
|
|
32
|
+
cloudflareSearchProvider?: unknown;
|
|
33
|
+
tabstackBaseUrl?: unknown;
|
|
34
|
+
tabstackApiKey?: unknown;
|
|
35
|
+
tabstackResearchMode?: unknown;
|
|
36
|
+
deepseekApiKey?: unknown;
|
|
37
|
+
degoogBaseUrl?: unknown;
|
|
38
|
+
degoogApiKey?: unknown;
|
|
39
|
+
degoogEngines?: unknown;
|
|
40
|
+
degoogHeaders?: unknown;
|
|
41
|
+
xaiApiKey?: unknown;
|
|
42
|
+
provider?: unknown;
|
|
43
|
+
searchProvider?: unknown;
|
|
44
|
+
workflow?: string;
|
|
45
|
+
curatorTimeoutSeconds?: unknown;
|
|
46
|
+
autoOpenBrowser?: unknown;
|
|
47
|
+
curatorRemote?: unknown;
|
|
48
|
+
summaryModel?: string;
|
|
49
|
+
queryRewriteModel?: string;
|
|
50
|
+
summaryGenerationDeadlineMs?: unknown;
|
|
51
|
+
summaryInstructions?: unknown;
|
|
52
|
+
maxInlineContentChars?: unknown;
|
|
53
|
+
retrievalOnly?: unknown;
|
|
54
|
+
fetch?: {
|
|
55
|
+
defaultMode?: unknown;
|
|
56
|
+
allowedModes?: unknown;
|
|
57
|
+
};
|
|
58
|
+
webSearch?: {
|
|
59
|
+
enabled?: boolean;
|
|
60
|
+
allowedProviders?: unknown;
|
|
61
|
+
};
|
|
62
|
+
tools?: Partial<Record<keyof ToolNames, {
|
|
63
|
+
enabled?: boolean;
|
|
64
|
+
}>>;
|
|
65
|
+
toolActivation?: unknown;
|
|
66
|
+
toolExposure?: unknown;
|
|
67
|
+
commands?: Partial<Record<"websearch" | "curator" | "search" | "google-account", {
|
|
68
|
+
enabled?: boolean;
|
|
69
|
+
}>>;
|
|
70
|
+
toolNames?: Partial<ToolNames>;
|
|
71
|
+
shortcuts?: {
|
|
72
|
+
curate?: KeyId;
|
|
73
|
+
activity?: KeyId;
|
|
74
|
+
};
|
|
75
|
+
ssrf?: {
|
|
76
|
+
/** CIDR ranges exempted from the SSRF guard (e.g. fake-IP proxy ranges). */
|
|
77
|
+
allowRanges?: string[];
|
|
78
|
+
/** Skip local hostname DNS preflight when an HTTP(S)_PROXY env var applies. */
|
|
79
|
+
trustEnvProxy?: boolean;
|
|
80
|
+
};
|
|
81
|
+
allowBrowserCookies?: unknown;
|
|
82
|
+
browserCookies?: unknown;
|
|
83
|
+
}
|
|
84
|
+
export declare function parseConfigRoot(raw: string): Record<string, unknown>;
|
|
85
|
+
export declare function loadConfig(): WebSearchConfig;
|
|
86
|
+
export type ToolNames = {
|
|
87
|
+
webSearch: string;
|
|
88
|
+
sourceCheck: string;
|
|
89
|
+
fetchContent: string;
|
|
90
|
+
getSearchContent: string;
|
|
91
|
+
};
|
|
92
|
+
export declare const DEFAULT_TOOL_NAMES: ToolNames;
|
|
93
|
+
declare const FETCH_MODES: readonly ["readable", "raw", "answer", "extract"];
|
|
94
|
+
export type FetchMode = typeof FETCH_MODES[number];
|
|
95
|
+
export type FetchModeConfig = {
|
|
96
|
+
defaultMode: FetchMode;
|
|
97
|
+
allowedModes: FetchMode[];
|
|
98
|
+
};
|
|
99
|
+
export declare function resolveFetchModeConfig(config: WebSearchConfig): FetchModeConfig;
|
|
100
|
+
export declare function runSearchQueries<T>(queries: string[], run: (query: string, index: number) => Promise<T>): Promise<T[]>;
|
|
101
|
+
export declare function isToolEnabled(config: WebSearchConfig, key: keyof ToolNames): boolean;
|
|
102
|
+
export declare function normalizeProviderInput(value: unknown, label?: string): SearchProviderSelection | undefined;
|
|
103
|
+
export declare function resolveRequestedProvider(requested: unknown): SearchProviderSelection;
|
|
104
|
+
export declare function toCuratorProvider(provider: SearchProviderSelection): SearchProvider | undefined;
|
|
105
|
+
export declare function normalizeRecencyFilter(value: unknown): RecencyFilter | undefined;
|
|
106
|
+
export declare function normalizeQueryList(queryList: unknown[]): string[];
|
|
107
|
+
export declare function expandQueryString(query: unknown): string[];
|
|
108
|
+
export declare function fetchAllContent(urls: string[], signal?: AbortSignal, options?: ExtractOptions): Promise<ExtractedContent[]>;
|
|
109
|
+
/** Returns content for every URL in order: the provider's content where it supplied some,
|
|
110
|
+
* and a page fetch only for the URLs it did not cover. */
|
|
111
|
+
export declare function fetchUncoveredContent(urls: string[], provided: ExtractedContent[] | undefined, fetchPages: (urls: string[]) => Promise<ExtractedContent[]>): Promise<ExtractedContent[]>;
|
|
112
|
+
export declare function withRegisteredFetchOptions(options: ExtractOptions | undefined, toolNames: ExtractOptions["toolNames"], proxy?: string): ExtractOptions;
|
|
113
|
+
export declare function getMaxInlineContentChars(config?: WebSearchConfig): number;
|
|
114
|
+
export declare function stripThumbnails(results: ExtractedContent[]): ExtractedContent[];
|
|
115
|
+
type GetSearchContentParams = GetSearchContentCallParams;
|
|
116
|
+
export type RawGetSearchContentParams = Omit<GetSearchContentParams, "findMode"> & {
|
|
117
|
+
findMode?: unknown;
|
|
118
|
+
};
|
|
119
|
+
export type SummaryWorkflow = "summary-review" | "auto-summary";
|
|
120
|
+
export type FetchedContentData = StoredSearchData & {
|
|
121
|
+
type: "fetch";
|
|
122
|
+
urls: ExtractedContent[];
|
|
123
|
+
};
|
|
124
|
+
export interface SearchReturnOptions {
|
|
125
|
+
queryList: string[];
|
|
126
|
+
results: QueryResultData[];
|
|
127
|
+
urls: string[];
|
|
128
|
+
includeContent: boolean;
|
|
129
|
+
inlineContent?: ExtractedContent[];
|
|
130
|
+
curated?: boolean;
|
|
131
|
+
curatedFrom?: number;
|
|
132
|
+
workflow?: SummaryWorkflow;
|
|
133
|
+
approvedSummary?: string;
|
|
134
|
+
summaryMeta?: SummaryMeta;
|
|
135
|
+
proxy?: string;
|
|
136
|
+
}
|
|
137
|
+
/** Tool names and limits a host resolved once at startup. */
|
|
138
|
+
export interface WebToolCoreSettings {
|
|
139
|
+
toolNames: ToolNames;
|
|
140
|
+
enabledTools: Record<keyof ToolNames, boolean>;
|
|
141
|
+
/** Output ceiling for search results and stored-content pages. fetch_content rereads config per call. */
|
|
142
|
+
maxInlineContentChars: number;
|
|
143
|
+
fetchModes: FetchModeConfig;
|
|
144
|
+
}
|
|
145
|
+
export interface PageAnswerRequest {
|
|
146
|
+
question: string;
|
|
147
|
+
pageText: string;
|
|
148
|
+
sourceUrl: string;
|
|
149
|
+
model?: string;
|
|
150
|
+
/** Video frames or a fetched image, sent to the answer model as image input. */
|
|
151
|
+
images?: Array<{
|
|
152
|
+
data: string;
|
|
153
|
+
mimeType: string;
|
|
154
|
+
label?: string;
|
|
155
|
+
}>;
|
|
156
|
+
}
|
|
157
|
+
/** Everything that differs between hosts. Pi supplies session persistence, background
|
|
158
|
+
* notifications, and page answers; the standalone host keeps results in memory only. */
|
|
159
|
+
export interface WebToolCoreHost {
|
|
160
|
+
settings: WebToolCoreSettings;
|
|
161
|
+
/** Store fetched page content under id so the retrieval tool can page through it. */
|
|
162
|
+
storeFetchedContent(id: string, data: FetchedContentData): void;
|
|
163
|
+
/** Called after search or research results are stored in memory. */
|
|
164
|
+
publishResult?(data: StoredSearchData): void;
|
|
165
|
+
/** Fetch includeContent pages the provider did not cover in the background and return
|
|
166
|
+
* their responseId. When omitted, web_search awaits the same fetch before returning. */
|
|
167
|
+
startBackgroundFetch?(urls: string[], proxy?: string, provided?: ExtractedContent[]): string | null;
|
|
168
|
+
/** Answers fetch_content mode "answer"; requires the host's model access. */
|
|
169
|
+
answerFromPage?(request: PageAnswerRequest, extensionContext: ExtensionContext | undefined, signal?: AbortSignal): Promise<{
|
|
170
|
+
text: string;
|
|
171
|
+
usage?: Usage;
|
|
172
|
+
}>;
|
|
173
|
+
/** Extraction options every fetch in this host adds (for example direct-image policy). */
|
|
174
|
+
extractOptions?: Pick<ExtractOptions, "rejectDirectImages">;
|
|
175
|
+
}
|
|
176
|
+
export type WebToolUpdate = (update: {
|
|
177
|
+
content: Array<{
|
|
178
|
+
type: "text";
|
|
179
|
+
text: string;
|
|
180
|
+
}>;
|
|
181
|
+
details: Record<string, unknown>;
|
|
182
|
+
}) => void;
|
|
183
|
+
/** Per-call inputs only Pi has: its live ExtensionContext and partial-result callback. */
|
|
184
|
+
export interface WebToolCallOptions {
|
|
185
|
+
extensionContext?: ExtensionContext;
|
|
186
|
+
onUpdate?: WebToolUpdate;
|
|
187
|
+
/** Lets Gemini-only routes ask the user to turn on browser cookie access. */
|
|
188
|
+
browserCookieConsent?: BrowserCookieConsent;
|
|
189
|
+
}
|
|
190
|
+
export interface WebSearchCallOptions extends WebToolCallOptions {
|
|
191
|
+
/** Generates an auto-summary after searches complete; returning a tool result ends the call. */
|
|
192
|
+
summarize?(results: QueryResultData[]): Promise<WebToolResult | {
|
|
193
|
+
approvedSummary: string;
|
|
194
|
+
summaryMeta: SummaryMeta;
|
|
195
|
+
}>;
|
|
196
|
+
/** Wait for includeContent pages and store them with the result instead of fetching in the background. */
|
|
197
|
+
awaitContent?: boolean;
|
|
198
|
+
}
|
|
199
|
+
export type WebSearchParams = Omit<WebSearchCallParams, "recencyFilter"> & {
|
|
200
|
+
recencyFilter?: string;
|
|
201
|
+
workflow?: string;
|
|
202
|
+
};
|
|
203
|
+
export type FetchContentToolParams = FetchContentCallParams & FetchContentParams;
|
|
204
|
+
export type SourceCheckParams = Omit<SourceCheckCallParams, "recencyFilter"> & {
|
|
205
|
+
recencyFilter?: string;
|
|
206
|
+
};
|
|
207
|
+
export interface WebToolCoreInstance extends WebToolCore {
|
|
208
|
+
webSearch(params: WebSearchParams, signal?: AbortSignal, call?: WebSearchCallOptions): Promise<WebToolResult>;
|
|
209
|
+
fetchContent(params: FetchContentToolParams, signal?: AbortSignal, call?: WebToolCallOptions): Promise<WebToolResult>;
|
|
210
|
+
getSearchContent(params: RawGetSearchContentParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
211
|
+
sourceCheck(params: SourceCheckParams, signal?: AbortSignal, call?: WebToolCallOptions): Promise<WebToolResult>;
|
|
212
|
+
/** Formats and stores search results; the Pi curator reuses it for curated returns. */
|
|
213
|
+
buildSearchReturn(opts: SearchReturnOptions): WebToolResult;
|
|
214
|
+
}
|
|
215
|
+
/** Names fetch guidance may point at: only tools registered this session. */
|
|
216
|
+
export declare function registeredFetchToolNames(settings: WebToolCoreSettings): NonNullable<ExtractOptions["toolNames"]>;
|
|
217
|
+
export declare function storedContentSourceNames(settings: WebToolCoreSettings): string;
|
|
218
|
+
export declare function createWebToolCore(host: WebToolCoreHost): WebToolCoreInstance;
|
|
219
|
+
export interface StandaloneWebToolCore extends WebToolCore {
|
|
220
|
+
/** Default names of the tools web-search.json enables; hosts list only these. */
|
|
221
|
+
enabledToolNames: string[];
|
|
222
|
+
}
|
|
223
|
+
export declare function markToolError<T extends Omit<WebToolResult, "structuredContent">>(result: T): T;
|
|
224
|
+
/** Core for hosts without Pi: no extension context, curator, or summaries; results
|
|
225
|
+
* live in a bounded in-memory store; includeContent waits for the page fetch. */
|
|
226
|
+
export declare function createStandaloneWebToolCore(): StandaloneWebToolCore;
|
|
227
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
import type { SearchOptions, SearchResponse } from "./perplexity.ts";
|
|
3
|
+
type ProviderHeaders = Record<string, string | null>;
|
|
4
|
+
interface XaiAuth {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
model: string;
|
|
7
|
+
headers: ProviderHeaders;
|
|
8
|
+
}
|
|
9
|
+
export declare function resolveXaiAuth(ctx?: ExtensionContext, signal?: AbortSignal, model?: string): Promise<XaiAuth | undefined>;
|
|
10
|
+
export declare function isXaiSearchAvailable(ctx?: ExtensionContext): Promise<boolean>;
|
|
11
|
+
export declare function searchWithXai(query: string, options?: SearchOptions, ctx?: ExtensionContext): Promise<SearchResponse>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type BrowserCookieConsent } from "./gemini-web-config.ts";
|
|
2
|
+
import { type ExtractedContent, type FrameResult, type VideoFrame } from "./extract.ts";
|
|
3
|
+
export declare function isYouTubeURL(url: string): {
|
|
4
|
+
isYouTube: boolean;
|
|
5
|
+
videoId: string | null;
|
|
6
|
+
};
|
|
7
|
+
export declare function isYouTubeEnabled(): boolean;
|
|
8
|
+
/** The error when no route could read a YouTube video and none said why. */
|
|
9
|
+
export declare function youTubeAccessError(browserCookieConsent?: BrowserCookieConsent): string;
|
|
10
|
+
export declare function extractYouTube(url: string, signal?: AbortSignal, prompt?: string, model?: string, browserCookieConsent?: BrowserCookieConsent): Promise<ExtractedContent | null>;
|
|
11
|
+
type StreamInfo = {
|
|
12
|
+
streamUrl: string;
|
|
13
|
+
duration: number | null;
|
|
14
|
+
};
|
|
15
|
+
type StreamResult = StreamInfo | {
|
|
16
|
+
error: string;
|
|
17
|
+
};
|
|
18
|
+
export declare function getYouTubeStreamInfo(videoId: string): Promise<StreamResult>;
|
|
19
|
+
export declare function extractYouTubeFrame(videoId: string, seconds: number, streamInfo?: StreamInfo): Promise<FrameResult>;
|
|
20
|
+
export declare function extractYouTubeFrames(videoId: string, timestamps: number[], streamInfo?: StreamInfo): Promise<{
|
|
21
|
+
frames: VideoFrame[];
|
|
22
|
+
duration: number | null;
|
|
23
|
+
error: string | null;
|
|
24
|
+
}>;
|
|
25
|
+
export declare function fetchYouTubeThumbnail(videoId: string): Promise<{
|
|
26
|
+
data: string;
|
|
27
|
+
mimeType: string;
|
|
28
|
+
} | null>;
|
|
29
|
+
export {};
|
package/docs/pi-mcp.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Embedded MCP with a live Pi session
|
|
2
|
+
|
|
3
|
+
`pi-web-access/pi-mcp` is an opt-in compiled library entry for an application that already owns a Pi session in the same process. It exports `createPiWebToolCore` and a Pi-aware wrapper of the transport-neutral `createMcpServer`. The ordinary `pi-web-access-mcp` command stays standalone: it has no Pi context and still rejects Pi-only authentication and page-answer mode.
|
|
4
|
+
|
|
5
|
+
Bind the core from the real session's `session_start` callback. Do not manufacture an ExtensionContext, spread it into a snapshot, or open another model/auth runtime for web tools. Pi contexts have live getters and become invalid when their runtime is disposed. New/resumed/forked runtimes need a new core.
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
9
|
+
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
10
|
+
import { createMcpServer, createPiWebToolCore } from 'pi-web-access/pi-mcp';
|
|
11
|
+
|
|
12
|
+
// The owning application supplies a transport connected to its intended client.
|
|
13
|
+
export function installWebMcp(pi: ExtensionAPI, openTransport: () => Promise<Transport>) {
|
|
14
|
+
let core: ReturnType<typeof createPiWebToolCore> | undefined;
|
|
15
|
+
let server: ReturnType<typeof createMcpServer> | undefined;
|
|
16
|
+
pi.on('session_start', async (_event, context) => {
|
|
17
|
+
core = createPiWebToolCore({ pi, context });
|
|
18
|
+
server = createMcpServer(core, { name: 'session-web', version: '1.0.0' }, core.enabledToolNames);
|
|
19
|
+
await server.connect(await openTransport());
|
|
20
|
+
});
|
|
21
|
+
pi.on('session_shutdown', async () => {
|
|
22
|
+
await core?.close();
|
|
23
|
+
await server?.close();
|
|
24
|
+
core = undefined;
|
|
25
|
+
server = undefined;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This is not a new server command or a remote-auth delegation protocol. A stdio child does not inherit its parent's actual Pi context. For an in-process Pi MCP client, use its public `createMcpExtension({ createTransport })` hook. The official SDK's `InMemoryTransport.createLinkedPair()` can connect the server, but its callback-property interface is not Pi's subscription-based `McpTransport`: the host must adapt and validate parsed JSON-RPC messages, forward errors/close/cancellation, start the server asynchronously in `start()`, and supply a fresh transport/server for reconnects. Reuse the same session core across those reconnects. Do not install a second MCP extension or replace unrelated configured server transports.
|
|
31
|
+
|
|
32
|
+
## Contract
|
|
33
|
+
|
|
34
|
+
- The core lists only the four tools enabled by the operator's existing web configuration. It adds no provider, credential source, network listener or login/refresh owner.
|
|
35
|
+
- Existing search/fetch execution receives the actual context and therefore its model registry and provider authentication. The query goes to the configured search provider; the conversation transcript is not replayed or uploaded. A virtual model remains the actual selection; existing independent search-provider configuration may choose a physical model from that registry.
|
|
36
|
+
- Curator, summary workflows, UI commands, background agent turns and page-answer calls are not installed. `includeContent` waits for content. Existing browser-cookie consent and retrieval-only policy remain in force.
|
|
37
|
+
- Results use the same Pi journal/restore/release code as the native extension. Retrieval requires ownership on the active branch, not possession of a response ID. Tree changes cancel outstanding calls and restore that branch. Closing one core does not clear other live cores' results.
|
|
38
|
+
- Request, current Pi-turn and lifetime cancellation are combined. `close()` is idempotent, aborts and settles outstanding calls, and releases results. Await it before disposing the context and settling the owning ModelRuntime's native credential writes.
|
|
39
|
+
- Tool arguments still cross the existing MCP schema boundary. The `createMcpServer` exported by this entry admits explicit `provider: "kimi"` (including provider lists) for `web_search` and `source_check`, using the bound Pi registry for authentication. The standalone server still rejects explicit Kimi; neither entry accepts model/auth overrides or page-answer mode. The application owns any additional tenant policy, endpoint authentication, provider-override restrictions, per-call accounting and session lifecycle. A live context does not authorize hosted resale, cross-tenant use or unrestricted file access.
|
|
40
|
+
|
|
41
|
+
The compiled entry and declarations are included by `npm run build`. Pi packages remain host-provided optional peers; the standalone CLI does not import this entry or acquire Pi authentication.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export function normalizeDomain(value: string): string | null {
|
|
2
|
+
let input = value.trim().toLowerCase();
|
|
3
|
+
if (!input) return null;
|
|
4
|
+
if (input.startsWith("-")) input = input.slice(1).trim();
|
|
5
|
+
if (!input) return null;
|
|
6
|
+
try {
|
|
7
|
+
const parsed = input.includes("://") ? new URL(input) : new URL(`https://${input}`);
|
|
8
|
+
input = parsed.hostname;
|
|
9
|
+
} catch {
|
|
10
|
+
input = input.split("/")[0]?.split(":")[0] ?? "";
|
|
11
|
+
}
|
|
12
|
+
input = input.replace(/^\.+|\.+$/g, "");
|
|
13
|
+
return /^[a-z0-9][a-z0-9.-]*\.[a-z]{2,}$/i.test(input) ? input : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Applies the shared include/exclude `domainFilter` to results from a provider
|
|
18
|
+
* that has no server-side equivalent, so a filter never returns off-domain
|
|
19
|
+
* results silently. Unparseable result URLs are dropped.
|
|
20
|
+
*/
|
|
21
|
+
export function applyDomainFilter<T extends { url: string }>(results: T[], domainFilter: readonly string[] | undefined): T[] {
|
|
22
|
+
if (!domainFilter?.length) return results;
|
|
23
|
+
const includes: string[] = [];
|
|
24
|
+
const excludes: string[] = [];
|
|
25
|
+
for (const raw of domainFilter) {
|
|
26
|
+
const normalized = normalizeDomain(raw);
|
|
27
|
+
if (!normalized) continue;
|
|
28
|
+
if (raw.trim().startsWith("-")) excludes.push(normalized);
|
|
29
|
+
else includes.push(normalized);
|
|
30
|
+
}
|
|
31
|
+
if (!includes.length && !excludes.length) return results;
|
|
32
|
+
return results.filter((result) => {
|
|
33
|
+
let host: string;
|
|
34
|
+
try {
|
|
35
|
+
host = new URL(result.url).hostname.toLowerCase();
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
const matches = (domain: string) => host === domain || host.endsWith(`.${domain}`);
|
|
40
|
+
if (excludes.some(matches)) return false;
|
|
41
|
+
if (includes.length && !includes.some(matches)) return false;
|
|
42
|
+
return true;
|
|
43
|
+
});
|
|
44
|
+
}
|