@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
package/valyu.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { activityMonitor } from "./activity.ts";
|
|
3
|
+
import { normalizeDomain } from "./domain-filter-normalization.ts";
|
|
4
|
+
import type { ExtractedContent } from "./extract.ts";
|
|
5
|
+
import type { SearchOptions, SearchResponse } from "./perplexity.ts";
|
|
6
|
+
import { formatSearchResultsAsAnswer } from "./search-answer-formatting.ts";
|
|
7
|
+
import { normalizeSearchResultCount } from "./search-result-count-normalization.ts";
|
|
8
|
+
import { hasCredentialSource, redactCredential, resolveCredential } from "./credential-source.ts";
|
|
9
|
+
import { getWebSearchConfigPath, resolveProviderApiUrl, fetchWithCredentialRedirects } from "./utils.ts";
|
|
10
|
+
|
|
11
|
+
const VALYU_SEARCH_URL = "https://api.valyu.ai/v1/search";
|
|
12
|
+
const CONFIG_PATH = getWebSearchConfigPath();
|
|
13
|
+
const SEARCH_TIMEOUT_MS = 60_000;
|
|
14
|
+
const MAX_SNIPPET_CHARS = 2_500;
|
|
15
|
+
const MAX_CONTENT_CHARS = 4_000;
|
|
16
|
+
|
|
17
|
+
interface WebSearchConfig {
|
|
18
|
+
valyuBaseUrl?: unknown;
|
|
19
|
+
valyuApiKey?: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ValyuResult {
|
|
23
|
+
title?: unknown;
|
|
24
|
+
url?: unknown;
|
|
25
|
+
description?: unknown;
|
|
26
|
+
content?: unknown;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let cachedConfig: WebSearchConfig | null = null;
|
|
30
|
+
|
|
31
|
+
function loadConfig(): WebSearchConfig {
|
|
32
|
+
if (cachedConfig) return cachedConfig;
|
|
33
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
34
|
+
cachedConfig = {};
|
|
35
|
+
return cachedConfig;
|
|
36
|
+
}
|
|
37
|
+
const raw = readFileSync(CONFIG_PATH, "utf-8");
|
|
38
|
+
let parsed: unknown;
|
|
39
|
+
try {
|
|
40
|
+
parsed = JSON.parse(raw);
|
|
41
|
+
} catch (err) {
|
|
42
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
43
|
+
throw new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);
|
|
44
|
+
}
|
|
45
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
46
|
+
throw new Error(`Invalid config in ${CONFIG_PATH}: expected a JSON object`);
|
|
47
|
+
}
|
|
48
|
+
cachedConfig = parsed as WebSearchConfig;
|
|
49
|
+
return cachedConfig;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function getApiKey(signal?: AbortSignal): Promise<string | null> {
|
|
53
|
+
return resolveCredential({
|
|
54
|
+
provider: "Valyu",
|
|
55
|
+
configuredValue: loadConfig().valyuApiKey,
|
|
56
|
+
environmentValue: process.env.VALYU_API_KEY,
|
|
57
|
+
signal,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function requireApiKey(signal?: AbortSignal): Promise<string> {
|
|
62
|
+
const apiKey = await getApiKey(signal);
|
|
63
|
+
if (!apiKey) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
"Valyu API key not found. Either:\n" +
|
|
66
|
+
` 1. Create ${CONFIG_PATH} with { "valyuApiKey": "your-key" }\n` +
|
|
67
|
+
" 2. Set VALYU_API_KEY environment variable\n" +
|
|
68
|
+
"Get a key at https://platform.valyu.ai",
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
return apiKey;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function mapDomainFilter(domainFilter: string[] | undefined): { included_sources?: string[]; excluded_sources?: string[] } {
|
|
75
|
+
if (!domainFilter?.length) return {};
|
|
76
|
+
const included_sources: string[] = [];
|
|
77
|
+
const excluded_sources: string[] = [];
|
|
78
|
+
for (const raw of domainFilter) {
|
|
79
|
+
const domain = normalizeDomain(raw);
|
|
80
|
+
if (!domain) continue;
|
|
81
|
+
const target = raw.trim().startsWith("-") ? excluded_sources : included_sources;
|
|
82
|
+
if (!target.includes(domain)) target.push(domain);
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
...(included_sources.length > 0 ? { included_sources } : {}),
|
|
86
|
+
...(excluded_sources.length > 0 ? { excluded_sources } : {}),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function recencyToStartDate(filter: SearchOptions["recencyFilter"]): string | undefined {
|
|
91
|
+
if (!filter) return undefined;
|
|
92
|
+
const days = { day: 1, week: 7, month: 30, year: 365 }[filter];
|
|
93
|
+
return days ? new Date(Date.now() - days * 86_400_000).toISOString().slice(0, 10) : undefined;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function text(value: unknown, limit: number): string {
|
|
97
|
+
return typeof value === "string" ? value.replace(/\s+/g, " ").trim().slice(0, limit) : "";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function errorMessage(err: unknown): string {
|
|
101
|
+
return err instanceof Error ? err.message : String(err);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function invalidResponse(message: string): Error {
|
|
105
|
+
return new Error(`Valyu API returned invalid response: ${message}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function parseResponse(value: unknown): ValyuResult[] {
|
|
109
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw invalidResponse("expected an object envelope");
|
|
110
|
+
const envelope = value as Record<string, unknown>;
|
|
111
|
+
if (envelope.success !== true) throw invalidResponse("expected success true");
|
|
112
|
+
if (!Array.isArray(envelope.results)) throw invalidResponse("expected results array");
|
|
113
|
+
return envelope.results as ValyuResult[];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function isValyuAvailable(): boolean {
|
|
117
|
+
return hasCredentialSource({ provider: "Valyu", configuredValue: loadConfig().valyuApiKey, environmentValue: process.env.VALYU_API_KEY });
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export async function searchWithValyu(query: string, options: SearchOptions & { includeContent?: boolean } = {}): Promise<SearchResponse> {
|
|
121
|
+
const apiKey = await requireApiKey(options.signal);
|
|
122
|
+
const numResults = normalizeSearchResultCount(options.numResults);
|
|
123
|
+
const startDate = recencyToStartDate(options.recencyFilter);
|
|
124
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
125
|
+
let response: Response;
|
|
126
|
+
try {
|
|
127
|
+
response = await fetchWithCredentialRedirects(resolveProviderApiUrl("valyu", VALYU_SEARCH_URL, loadConfig().valyuBaseUrl), {
|
|
128
|
+
method: "POST",
|
|
129
|
+
headers: { "x-api-key": apiKey, "Content-Type": "application/json", Accept: "application/json" },
|
|
130
|
+
body: JSON.stringify({ query, max_num_results: numResults, ...mapDomainFilter(options.domainFilter), ...(startDate ? { start_date: startDate } : {}) }),
|
|
131
|
+
signal: options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS),
|
|
132
|
+
}, ["x-api-key"]);
|
|
133
|
+
} catch (err) {
|
|
134
|
+
const message = errorMessage(err);
|
|
135
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
136
|
+
if (redactedMessage.toLowerCase().includes("abort")) activityMonitor.logComplete(activityId, 0);
|
|
137
|
+
else activityMonitor.logError(activityId, redactedMessage);
|
|
138
|
+
if (redactedMessage === message) throw err;
|
|
139
|
+
const redactedError = new Error(redactedMessage);
|
|
140
|
+
if (err instanceof Error) redactedError.name = err.name;
|
|
141
|
+
throw redactedError;
|
|
142
|
+
}
|
|
143
|
+
if (!response.ok) {
|
|
144
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
145
|
+
const errorText = redactCredential(await response.text(), apiKey);
|
|
146
|
+
throw new Error(`Valyu API error ${response.status}: ${errorText.slice(0, 300)}`);
|
|
147
|
+
}
|
|
148
|
+
let rawData: unknown;
|
|
149
|
+
try {
|
|
150
|
+
rawData = await response.json();
|
|
151
|
+
} catch (err) {
|
|
152
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
153
|
+
throw new Error(`Valyu API returned invalid JSON: ${errorMessage(err)}`);
|
|
154
|
+
}
|
|
155
|
+
let entries: ValyuResult[];
|
|
156
|
+
try {
|
|
157
|
+
entries = parseResponse(rawData);
|
|
158
|
+
} catch (err) {
|
|
159
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
163
|
+
const results: SearchResponse["results"] = [];
|
|
164
|
+
const inlineContent: ExtractedContent[] = [];
|
|
165
|
+
for (const entry of entries) {
|
|
166
|
+
if (!entry || typeof entry !== "object") continue;
|
|
167
|
+
const url = text(entry.url, Number.MAX_SAFE_INTEGER);
|
|
168
|
+
if (!url) continue;
|
|
169
|
+
const title = text(entry.title, Number.MAX_SAFE_INTEGER) || `Source ${results.length + 1}`;
|
|
170
|
+
const content = text(entry.content, MAX_CONTENT_CHARS);
|
|
171
|
+
const description = text(entry.description, MAX_SNIPPET_CHARS);
|
|
172
|
+
results.push({ title, url, snippet: (content || description).slice(0, MAX_SNIPPET_CHARS) });
|
|
173
|
+
if (options.includeContent && content) inlineContent.push({ url, title, content, error: null });
|
|
174
|
+
if (results.length >= numResults) break;
|
|
175
|
+
}
|
|
176
|
+
return { answer: formatSearchResultsAsAnswer(results), results, ...(inlineContent.length > 0 ? { inlineContent } : {}) };
|
|
177
|
+
}
|
package/video-extract.ts
ADDED
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
import { resolve, extname, basename, join, dirname } from "node:path";
|
|
5
|
+
import { activityMonitor } from "./activity.ts";
|
|
6
|
+
import { canAttachImages } from "./feature-config.ts";
|
|
7
|
+
import { isGeminiWebAvailable, queryWithCookies, requestBrowserCookieAccess } from "./gemini-web.ts";
|
|
8
|
+
import { queryGeminiApiWithVideo, getApiKey, fetchGeminiApi, getVersionedApiBase, getUploadBase, redactGeminiApiResponse, rewriteUploadUrlOrigin } from "./gemini-api.ts";
|
|
9
|
+
import { extractHeadingTitle, type ExtractedContent, type ExtractOptions, type FrameResult } from "./extract.ts";
|
|
10
|
+
import { readExecError, trimErrorText, mapFfmpegError, getWebSearchConfigPath, FRAME_SCALE_FILTER } from "./utils.ts";
|
|
11
|
+
import { getRetrievalOnlyPolicy, retrievalOnlyError } from "./retrieval-only.ts";
|
|
12
|
+
|
|
13
|
+
const CONFIG_PATH = getWebSearchConfigPath();
|
|
14
|
+
|
|
15
|
+
const DEFAULT_VIDEO_PROMPT = `Extract the complete content of this video. Include:
|
|
16
|
+
1. Video title (infer from content if not explicit), duration
|
|
17
|
+
2. A brief summary (2-3 sentences)
|
|
18
|
+
3. Full transcript with timestamps
|
|
19
|
+
4. Descriptions of any code, terminal commands, diagrams, slides, or UI shown on screen
|
|
20
|
+
|
|
21
|
+
Format as markdown.`;
|
|
22
|
+
|
|
23
|
+
const VIDEO_EXTENSIONS: Record<string, string> = {
|
|
24
|
+
".mp4": "video/mp4",
|
|
25
|
+
".mov": "video/quicktime",
|
|
26
|
+
".webm": "video/webm",
|
|
27
|
+
".avi": "video/x-msvideo",
|
|
28
|
+
".mpeg": "video/mpeg",
|
|
29
|
+
".mpg": "video/mpeg",
|
|
30
|
+
".wmv": "video/x-ms-wmv",
|
|
31
|
+
".flv": "video/x-flv",
|
|
32
|
+
".3gp": "video/3gpp",
|
|
33
|
+
".3gpp": "video/3gpp",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
function shouldRethrow(err: unknown): boolean {
|
|
37
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
38
|
+
return message.startsWith("Failed to parse ");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface VideoFileInfo {
|
|
42
|
+
absolutePath: string;
|
|
43
|
+
mimeType: string;
|
|
44
|
+
sizeBytes: number;
|
|
45
|
+
maxSizeBytes: number;
|
|
46
|
+
withinUploadLimit: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface VideoConfig {
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
preferredModel: string;
|
|
52
|
+
maxSizeMB: number;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function normalizePreferredModel(value: unknown, fallback: string): string {
|
|
56
|
+
if (typeof value !== "string") return fallback;
|
|
57
|
+
const normalized = value.trim();
|
|
58
|
+
return normalized.length > 0 ? normalized : fallback;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function normalizeEnabled(value: unknown, fallback: boolean): boolean {
|
|
62
|
+
return typeof value === "boolean" ? value : fallback;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function normalizeMaxSizeMB(value: unknown, fallback: number): number {
|
|
66
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return fallback;
|
|
67
|
+
return value > 0 ? value : fallback;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const VIDEO_CONFIG_DEFAULTS: VideoConfig = {
|
|
71
|
+
enabled: true,
|
|
72
|
+
preferredModel: "gemini-3.6-flash",
|
|
73
|
+
maxSizeMB: 50,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
let cachedVideoConfig: VideoConfig | null = null;
|
|
77
|
+
|
|
78
|
+
function loadVideoConfig(): VideoConfig {
|
|
79
|
+
if (cachedVideoConfig) return cachedVideoConfig;
|
|
80
|
+
if (!existsSync(CONFIG_PATH)) {
|
|
81
|
+
cachedVideoConfig = { ...VIDEO_CONFIG_DEFAULTS };
|
|
82
|
+
return cachedVideoConfig;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const rawText = readFileSync(CONFIG_PATH, "utf-8");
|
|
86
|
+
let raw: { video?: { enabled?: boolean; preferredModel?: string; maxSizeMB?: number } };
|
|
87
|
+
try {
|
|
88
|
+
raw = JSON.parse(rawText) as { video?: { enabled?: boolean; preferredModel?: string; maxSizeMB?: number } };
|
|
89
|
+
} catch (err) {
|
|
90
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
91
|
+
throw new Error(`Failed to parse ${CONFIG_PATH}: ${message}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const v = raw.video ?? {};
|
|
95
|
+
cachedVideoConfig = {
|
|
96
|
+
enabled: normalizeEnabled(v.enabled, VIDEO_CONFIG_DEFAULTS.enabled),
|
|
97
|
+
preferredModel: normalizePreferredModel(v.preferredModel, VIDEO_CONFIG_DEFAULTS.preferredModel),
|
|
98
|
+
maxSizeMB: normalizeMaxSizeMB(v.maxSizeMB, VIDEO_CONFIG_DEFAULTS.maxSizeMB),
|
|
99
|
+
};
|
|
100
|
+
return cachedVideoConfig;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function isVideoFile(input: string): VideoFileInfo | null {
|
|
104
|
+
const config = loadVideoConfig();
|
|
105
|
+
if (!config.enabled) return null;
|
|
106
|
+
|
|
107
|
+
const isFilePath = input.startsWith("/") || input.startsWith("./") || input.startsWith("../") || input.startsWith("file://");
|
|
108
|
+
if (!isFilePath) return null;
|
|
109
|
+
|
|
110
|
+
let filePath = input;
|
|
111
|
+
if (input.startsWith("file://")) {
|
|
112
|
+
try {
|
|
113
|
+
filePath = decodeURIComponent(new URL(input).pathname);
|
|
114
|
+
} catch {
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const ext = extname(filePath).toLowerCase();
|
|
120
|
+
const mimeType = VIDEO_EXTENSIONS[ext];
|
|
121
|
+
if (!mimeType) return null;
|
|
122
|
+
|
|
123
|
+
const absolutePath = resolveFilePath(filePath);
|
|
124
|
+
if (!absolutePath) return null;
|
|
125
|
+
|
|
126
|
+
let stat: ReturnType<typeof statSync>;
|
|
127
|
+
try {
|
|
128
|
+
stat = statSync(absolutePath);
|
|
129
|
+
} catch {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (!stat.isFile()) return null;
|
|
133
|
+
|
|
134
|
+
const maxBytes = config.maxSizeMB * 1024 * 1024;
|
|
135
|
+
return {
|
|
136
|
+
absolutePath,
|
|
137
|
+
mimeType,
|
|
138
|
+
sizeBytes: stat.size,
|
|
139
|
+
maxSizeBytes: maxBytes,
|
|
140
|
+
withinUploadLimit: stat.size <= maxBytes,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function resolveFilePath(filePath: string): string | null {
|
|
145
|
+
const absolutePath = resolve(filePath);
|
|
146
|
+
if (existsSync(absolutePath)) return absolutePath;
|
|
147
|
+
|
|
148
|
+
const dir = dirname(absolutePath);
|
|
149
|
+
const base = basename(absolutePath);
|
|
150
|
+
if (!existsSync(dir)) return null;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
const normalizedBase = normalizeSpaces(base);
|
|
154
|
+
const match = readdirSync(dir).find(f => normalizeSpaces(f) === normalizedBase);
|
|
155
|
+
return match ? join(dir, match) : null;
|
|
156
|
+
} catch {
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function normalizeSpaces(s: string): string {
|
|
162
|
+
return s.replace(/[\u00A0\u2000-\u200B\u202F\u205F\u3000\uFEFF]/g, " ");
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export async function extractVideo(
|
|
166
|
+
info: VideoFileInfo,
|
|
167
|
+
signal?: AbortSignal,
|
|
168
|
+
options?: ExtractOptions,
|
|
169
|
+
): Promise<ExtractedContent | null> {
|
|
170
|
+
if (getRetrievalOnlyPolicy().enabled) throw retrievalOnlyError("Local video analysis");
|
|
171
|
+
const config = loadVideoConfig();
|
|
172
|
+
const effectivePrompt = options?.prompt ?? DEFAULT_VIDEO_PROMPT;
|
|
173
|
+
const effectiveModel = options?.model ?? config.preferredModel;
|
|
174
|
+
const displayName = basename(info.absolutePath);
|
|
175
|
+
if (!info.withinUploadLimit) {
|
|
176
|
+
const sizeMB = (info.sizeBytes / 1024 / 1024).toFixed(1);
|
|
177
|
+
const maxSizeMB = (info.maxSizeBytes / 1024 / 1024).toFixed(1);
|
|
178
|
+
const error = `Local video ${displayName} is ${sizeMB} MiB, above configured video.maxSizeMB (${maxSizeMB} MiB) for Gemini analysis. Use timestamp/frames for ffmpeg frame extraction, increase video.maxSizeMB, or compress the file.`;
|
|
179
|
+
return { url: info.absolutePath, title: displayName, content: error, error };
|
|
180
|
+
}
|
|
181
|
+
const activityId = activityMonitor.logStart({ type: "fetch", url: `video:${displayName}` });
|
|
182
|
+
|
|
183
|
+
const result = await tryVideoGeminiApi(info, effectivePrompt, effectiveModel, signal)
|
|
184
|
+
?? await tryVideoGeminiWeb(info, effectivePrompt, effectiveModel, signal)
|
|
185
|
+
?? (await requestBrowserCookieAccess(options?.browserCookieConsent, signal) ? await tryVideoGeminiWeb(info, effectivePrompt, effectiveModel, signal) : null);
|
|
186
|
+
|
|
187
|
+
if (result) {
|
|
188
|
+
if (canAttachImages()) {
|
|
189
|
+
const thumbnail = await extractVideoFrame(info.absolutePath);
|
|
190
|
+
if (!("error" in thumbnail)) {
|
|
191
|
+
result.thumbnail = thumbnail;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
activityMonitor.logComplete(activityId, 200);
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (signal?.aborted) {
|
|
199
|
+
activityMonitor.logComplete(activityId, 0);
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
activityMonitor.logError(activityId, "all video extraction paths failed");
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function mapFfprobeError(err: unknown): string {
|
|
208
|
+
const { code, stderr, message } = readExecError(err);
|
|
209
|
+
if (code === "ENOENT") return "ffprobe is not installed. Install ffmpeg which includes ffprobe";
|
|
210
|
+
const snippet = trimErrorText(stderr || message);
|
|
211
|
+
return snippet ? `ffprobe failed: ${snippet}` : "ffprobe failed";
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export async function extractVideoFrame(filePath: string, seconds: number = 1): Promise<FrameResult> {
|
|
215
|
+
try {
|
|
216
|
+
const buffer = execFileSync("ffmpeg", [
|
|
217
|
+
"-ss", String(seconds), "-i", filePath,
|
|
218
|
+
"-frames:v", "1", "-vf", FRAME_SCALE_FILTER, "-f", "image2pipe", "-vcodec", "mjpeg", "pipe:1",
|
|
219
|
+
], { maxBuffer: 5 * 1024 * 1024, timeout: 10000, stdio: ["pipe", "pipe", "pipe"] });
|
|
220
|
+
if (buffer.length === 0) return { error: "ffmpeg failed: empty output" };
|
|
221
|
+
return { data: buffer.toString("base64"), mimeType: "image/jpeg" };
|
|
222
|
+
} catch (err) {
|
|
223
|
+
return { error: mapFfmpegError(err) };
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export async function getLocalVideoDuration(filePath: string): Promise<number | { error: string }> {
|
|
228
|
+
try {
|
|
229
|
+
const output = execFileSync("ffprobe", [
|
|
230
|
+
"-v", "quiet",
|
|
231
|
+
"-show_entries", "format=duration",
|
|
232
|
+
"-of", "csv=p=0",
|
|
233
|
+
filePath,
|
|
234
|
+
], { timeout: 10000, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] }).trim();
|
|
235
|
+
const duration = Number.parseFloat(output);
|
|
236
|
+
if (!Number.isFinite(duration)) return { error: "ffprobe failed: invalid duration output" };
|
|
237
|
+
return duration;
|
|
238
|
+
} catch (err) {
|
|
239
|
+
return { error: mapFfprobeError(err) };
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async function tryVideoGeminiWeb(
|
|
244
|
+
info: VideoFileInfo,
|
|
245
|
+
prompt: string,
|
|
246
|
+
model: string,
|
|
247
|
+
signal?: AbortSignal,
|
|
248
|
+
): Promise<ExtractedContent | null> {
|
|
249
|
+
try {
|
|
250
|
+
const cookies = await isGeminiWebAvailable();
|
|
251
|
+
if (!cookies) return null;
|
|
252
|
+
if (signal?.aborted) return null;
|
|
253
|
+
|
|
254
|
+
const text = await queryWithCookies(prompt, cookies, {
|
|
255
|
+
files: [{ path: info.absolutePath, mimeType: info.mimeType }],
|
|
256
|
+
...(model !== "gemini-3.6-flash" ? { model } : {}),
|
|
257
|
+
signal,
|
|
258
|
+
timeoutMs: 180000,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
return {
|
|
262
|
+
url: info.absolutePath,
|
|
263
|
+
title: extractVideoTitle(text, info.absolutePath),
|
|
264
|
+
content: text,
|
|
265
|
+
error: null,
|
|
266
|
+
};
|
|
267
|
+
} catch (err) {
|
|
268
|
+
if (shouldRethrow(err)) throw err;
|
|
269
|
+
return null;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
async function tryVideoGeminiApi(
|
|
274
|
+
info: VideoFileInfo,
|
|
275
|
+
prompt: string,
|
|
276
|
+
model: string,
|
|
277
|
+
signal?: AbortSignal,
|
|
278
|
+
): Promise<ExtractedContent | null> {
|
|
279
|
+
const apiKey = await getApiKey(signal);
|
|
280
|
+
if (!apiKey) return null;
|
|
281
|
+
if (signal?.aborted) return null;
|
|
282
|
+
|
|
283
|
+
let fileName: string | null = null;
|
|
284
|
+
try {
|
|
285
|
+
const uploaded = await uploadToFilesApi(info, apiKey, signal);
|
|
286
|
+
fileName = uploaded.name;
|
|
287
|
+
|
|
288
|
+
await pollFileState(fileName, apiKey, signal, 120000);
|
|
289
|
+
|
|
290
|
+
const text = await queryGeminiApiWithVideo(prompt, uploaded.uri, {
|
|
291
|
+
apiKey,
|
|
292
|
+
model,
|
|
293
|
+
mimeType: info.mimeType,
|
|
294
|
+
signal,
|
|
295
|
+
timeoutMs: 120000,
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
return {
|
|
299
|
+
url: info.absolutePath,
|
|
300
|
+
title: extractVideoTitle(text, info.absolutePath),
|
|
301
|
+
content: text,
|
|
302
|
+
error: null,
|
|
303
|
+
};
|
|
304
|
+
} catch (err) {
|
|
305
|
+
if (shouldRethrow(err)) throw err;
|
|
306
|
+
return null;
|
|
307
|
+
} finally {
|
|
308
|
+
if (fileName) deleteGeminiFile(fileName, apiKey);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
async function uploadToFilesApi(
|
|
313
|
+
info: VideoFileInfo,
|
|
314
|
+
apiKey: string,
|
|
315
|
+
signal?: AbortSignal,
|
|
316
|
+
): Promise<{ name: string; uri: string }> {
|
|
317
|
+
const displayName = basename(info.absolutePath);
|
|
318
|
+
|
|
319
|
+
const initRes = await fetchGeminiApi(`${getUploadBase()}/files`, {
|
|
320
|
+
method: "POST",
|
|
321
|
+
headers: {
|
|
322
|
+
"X-Goog-Upload-Protocol": "resumable",
|
|
323
|
+
"X-Goog-Upload-Command": "start",
|
|
324
|
+
"X-Goog-Upload-Header-Content-Length": String(info.sizeBytes),
|
|
325
|
+
"X-Goog-Upload-Header-Content-Type": info.mimeType,
|
|
326
|
+
"Content-Type": "application/json",
|
|
327
|
+
},
|
|
328
|
+
body: JSON.stringify({ file: { display_name: displayName } }),
|
|
329
|
+
signal,
|
|
330
|
+
}, apiKey);
|
|
331
|
+
|
|
332
|
+
if (!initRes.ok) {
|
|
333
|
+
const text = redactGeminiApiResponse(initRes, await initRes.text(), apiKey);
|
|
334
|
+
throw new Error(`File upload init failed: ${initRes.status} (${text.slice(0, 200)})`);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const uploadUrl = initRes.headers.get("x-goog-upload-url");
|
|
338
|
+
if (!uploadUrl) throw new Error("No upload URL in response headers");
|
|
339
|
+
// Google returns a DIRECT upload URL, which would bypass the configured gateway
|
|
340
|
+
// (unlogged spend + the gateway VK sent to Google). Re-originate it at getApiHost();
|
|
341
|
+
// no-op when no gateway is configured, since that is already the Google origin.
|
|
342
|
+
const routedUploadUrl = rewriteUploadUrlOrigin(uploadUrl);
|
|
343
|
+
|
|
344
|
+
const fileData = await readFile(info.absolutePath);
|
|
345
|
+
const uploadRes = await fetchGeminiApi(routedUploadUrl, {
|
|
346
|
+
method: "PUT",
|
|
347
|
+
headers: {
|
|
348
|
+
"Content-Length": String(info.sizeBytes),
|
|
349
|
+
"X-Goog-Upload-Offset": "0",
|
|
350
|
+
"X-Goog-Upload-Command": "upload, finalize",
|
|
351
|
+
},
|
|
352
|
+
body: fileData,
|
|
353
|
+
signal,
|
|
354
|
+
}, apiKey);
|
|
355
|
+
|
|
356
|
+
if (!uploadRes.ok) {
|
|
357
|
+
const text = redactGeminiApiResponse(uploadRes, await uploadRes.text(), apiKey);
|
|
358
|
+
throw new Error(`File upload failed: ${uploadRes.status} (${text.slice(0, 200)})`);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const result = await uploadRes.json() as { file: { name: string; uri: string } };
|
|
362
|
+
return result.file;
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
async function pollFileState(
|
|
366
|
+
fileName: string,
|
|
367
|
+
apiKey: string,
|
|
368
|
+
signal?: AbortSignal,
|
|
369
|
+
timeoutMs: number = 120000,
|
|
370
|
+
): Promise<void> {
|
|
371
|
+
const deadline = Date.now() + timeoutMs;
|
|
372
|
+
|
|
373
|
+
while (Date.now() < deadline) {
|
|
374
|
+
if (signal?.aborted) throw new Error("Aborted");
|
|
375
|
+
|
|
376
|
+
const res = await fetchGeminiApi(`${getVersionedApiBase()}/${fileName}`, { signal }, apiKey);
|
|
377
|
+
if (!res.ok) throw new Error(`File state check failed: ${res.status}`);
|
|
378
|
+
|
|
379
|
+
const data = await res.json() as { state: string };
|
|
380
|
+
if (data.state === "ACTIVE") return;
|
|
381
|
+
if (data.state === "FAILED") throw new Error("File processing failed");
|
|
382
|
+
|
|
383
|
+
await new Promise(r => setTimeout(r, 5000));
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
throw new Error("File processing timed out");
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function deleteGeminiFile(fileName: string, apiKey: string): void {
|
|
390
|
+
void fetchGeminiApi(`${getVersionedApiBase()}/${fileName}`, { method: "DELETE" }, apiKey).catch((err) => {
|
|
391
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
392
|
+
console.error(`Failed to delete Gemini file ${fileName}: ${message}`);
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
function extractVideoTitle(text: string, filePath: string): string {
|
|
397
|
+
return extractHeadingTitle(text) ?? basename(filePath, extname(filePath));
|
|
398
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Host-neutral contract for the web tools. The Pi extension (index.ts) and the
|
|
2
|
+
// MCP server (mcp-server.ts) both drive tools through WebToolCore so tool
|
|
3
|
+
// behavior lives in one place; each host keeps its own schemas and transport.
|
|
4
|
+
|
|
5
|
+
import type { Usage } from "@earendil-works/pi-ai/compat";
|
|
6
|
+
import type { FindMode } from "./content-find.ts";
|
|
7
|
+
import type { PageExtraction } from "./field-extract.ts";
|
|
8
|
+
import type { RecencyFilter } from "./source-check.ts";
|
|
9
|
+
|
|
10
|
+
export type WebToolContent =
|
|
11
|
+
| { type: "text"; text: string }
|
|
12
|
+
| { type: "image"; data: string; mimeType: string };
|
|
13
|
+
|
|
14
|
+
export interface WebToolResult {
|
|
15
|
+
content: WebToolContent[];
|
|
16
|
+
details: Record<string, unknown>;
|
|
17
|
+
isError?: boolean;
|
|
18
|
+
/** Data for programmatic callers such as Pi codemode scripts; never sent to the model or over MCP. */
|
|
19
|
+
structuredContent?: WebSearchStructuredContent | FetchContentStructuredContent;
|
|
20
|
+
/** Combined usage of the model calls the tool made, which Pi adds to the session's totals; absent when it made none. */
|
|
21
|
+
usage?: Usage;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type WebSearchStructuredContent = {
|
|
25
|
+
responseId: string;
|
|
26
|
+
fetchId: string | null;
|
|
27
|
+
queries: Array<{
|
|
28
|
+
query: string;
|
|
29
|
+
answer: string;
|
|
30
|
+
error: string | null;
|
|
31
|
+
provider?: string;
|
|
32
|
+
providers?: string[];
|
|
33
|
+
results: Array<{ title: string; url: string; snippet: string }>;
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type FetchContentStructuredContent = {
|
|
38
|
+
responseId: string | null;
|
|
39
|
+
/** In extract mode, each fetched URL also has its `extraction`: typed fields per name, or why extraction failed. */
|
|
40
|
+
urls: Array<{ url: string; title: string; content: string; error: string | null; mimeType?: string; status?: number; duration?: number; extraction?: PageExtraction }>;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export interface WebSearchCallParams {
|
|
44
|
+
model?: string;
|
|
45
|
+
objective?: string;
|
|
46
|
+
query?: string;
|
|
47
|
+
queries?: string[];
|
|
48
|
+
numResults?: number;
|
|
49
|
+
includeContent?: boolean;
|
|
50
|
+
recencyFilter?: RecencyFilter;
|
|
51
|
+
domainFilter?: string[];
|
|
52
|
+
category?: string;
|
|
53
|
+
provider?: string | string[];
|
|
54
|
+
proxy?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface FetchContentCallParams {
|
|
58
|
+
url?: string;
|
|
59
|
+
urls?: string[];
|
|
60
|
+
mode?: string;
|
|
61
|
+
forceClone?: boolean;
|
|
62
|
+
proxy?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface GetSearchContentCallParams {
|
|
66
|
+
responseId: string;
|
|
67
|
+
query?: string;
|
|
68
|
+
queryIndex?: number;
|
|
69
|
+
url?: string;
|
|
70
|
+
urlIndex?: number;
|
|
71
|
+
offset?: number;
|
|
72
|
+
limit?: number;
|
|
73
|
+
findText?: string | string[];
|
|
74
|
+
findMode?: FindMode;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface SourceCheckCallParams {
|
|
78
|
+
claim: string;
|
|
79
|
+
queries?: string[];
|
|
80
|
+
numResults?: number;
|
|
81
|
+
fetchContent?: boolean;
|
|
82
|
+
recencyFilter?: RecencyFilter;
|
|
83
|
+
domainFilter?: string[];
|
|
84
|
+
provider?: string | string[];
|
|
85
|
+
proxy?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export interface WebToolCore {
|
|
89
|
+
webSearch(params: WebSearchCallParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
90
|
+
fetchContent(params: FetchContentCallParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
91
|
+
getSearchContent(params: GetSearchContentCallParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
92
|
+
sourceCheck(params: SourceCheckCallParams, signal?: AbortSignal): Promise<WebToolResult>;
|
|
93
|
+
}
|