import type { ExtensionContext } from "@earendil-works/pi-coding-agent"; import type { KeyId } from "@earendil-works/pi-tui"; import type { ExtractedContent, ExtractOptions } from "./extract.ts"; import { type FetchContentParams, type FetchMode, type FetchModeConfig } from "./fetch-params.ts"; import { type SearchProvider, type SearchProviderSelection } from "./gemini-search.ts"; import { type RecencyFilter } from "./source-check.ts"; import { type QueryResultData, type StoredSearchData } from "./storage.ts"; import type { SummaryMeta } from "./summary-review.ts"; import type { FetchContentCallParams, FetchContentStructuredContent, GetSearchContentCallParams, SourceCheckCallParams, WebSearchCallParams, WebToolCore, WebToolResult } from "./web-tool-contract.ts"; export declare const WEB_SEARCH_CONFIG_PATH: string; export interface WebSearchConfig { anysearchApiKey?: unknown; xcrawlApiKey?: unknown; brightdataApiKey?: unknown; brightdataSerpZone?: unknown; kagiApiKey?: unknown; ollamaApiKey?: unknown; serpbaseApiKey?: unknown; serpapiApiKey?: unknown; serperApiKey?: unknown; serplyApiKey?: unknown; youApiKey?: unknown; baizhiApiKey?: unknown; zaiApiKey?: unknown; tinyfishApiKey?: unknown; valyuApiKey?: unknown; keenableApiKey?: unknown; ceramicApiKey?: unknown; linkupApiKey?: unknown; linkupDepth?: unknown; deepseekApiKey?: unknown; degoogBaseUrl?: unknown; degoogApiKey?: unknown; degoogEngines?: unknown; degoogHeaders?: unknown; xaiApiKey?: unknown; provider?: unknown; searchProvider?: unknown; workflow?: string; curatorTimeoutSeconds?: unknown; autoOpenBrowser?: unknown; curatorRemote?: unknown; summaryModel?: string; summaryGenerationDeadlineMs?: unknown; summaryInstructions?: unknown; maxInlineContentChars?: unknown; fetch?: { defaultMode?: unknown; allowedModes?: unknown; /** Provider for `mode: "answer"`; must be configured together with `answerModel`. */ answerProvider?: unknown; /** Model id for `mode: "answer"`; must be configured together with `answerProvider`. */ answerModel?: unknown; }; webSearch?: { enabled?: boolean; allowedProviders?: unknown; }; tools?: Partial>; toolActivation?: unknown; toolExposure?: unknown; enableWebLoader?: unknown; commands?: Partial>; toolNames?: Partial; shortcuts?: { curate?: KeyId; activity?: KeyId; }; ssrf?: { /** CIDR ranges exempted from the SSRF guard (e.g. fake-IP proxy ranges). */ allowRanges?: string[]; /** Skip local hostname DNS preflight when an HTTP(S)_PROXY env var applies. */ trustEnvProxy?: boolean; }; } export declare function loadConfig(): WebSearchConfig; export type ToolNames = { webSearch: string; sourceCheck: string; fetchContent: string; getSearchContent: string; }; export declare const DEFAULT_TOOL_NAMES: ToolNames; export declare function resolveFetchModeConfig(config: WebSearchConfig): FetchModeConfig; export declare function runSearchQueries(queries: string[], run: (query: string, index: number) => Promise): Promise; export declare function isToolEnabled(config: WebSearchConfig, key: keyof ToolNames): boolean; export declare function normalizeProviderInput(value: unknown, label?: string): SearchProviderSelection | undefined; export declare function resolveRequestedProvider(requested: unknown): SearchProviderSelection; export declare function toCuratorProvider(provider: SearchProviderSelection): SearchProvider | undefined; export declare function normalizeRecencyFilter(value: unknown): RecencyFilter | undefined; export declare function normalizeQueryList(queryList: unknown[]): string[]; export declare function expandQueryString(query: unknown): string[]; export declare function fetchAllContent(urls: string[], signal?: AbortSignal, options?: ExtractOptions): Promise; /** Returns content for every URL in order: the provider's content where it supplied some, * and a page fetch only for the URLs it did not cover. */ export declare function fetchUncoveredContent(urls: string[], provided: ExtractedContent[] | undefined, fetchPages: (urls: string[]) => Promise): Promise; export declare function withRegisteredFetchOptions(options: ExtractOptions | undefined, toolNames: ExtractOptions["toolNames"], proxy?: string): ExtractOptions; export declare function getMaxInlineContentChars(config?: WebSearchConfig): number; export declare function stripThumbnails(results: ExtractedContent[]): ExtractedContent[]; type GetSearchContentParams = GetSearchContentCallParams; export type RawGetSearchContentParams = Omit & { findMode?: unknown; }; export type SummaryWorkflow = "summary-review" | "auto-summary"; export type FetchedContentData = StoredSearchData & { type: "fetch"; urls: ExtractedContent[]; }; export interface SearchReturnOptions { queryList: string[]; results: QueryResultData[]; urls: string[]; includeContent: boolean; inlineContent?: ExtractedContent[] | undefined; curated?: boolean | undefined; curatedFrom?: number | undefined; workflow?: SummaryWorkflow | undefined; approvedSummary?: string | undefined; summaryMeta?: SummaryMeta | undefined; proxy?: string | undefined; } /** Tool names and limits a host resolved once at startup. */ export interface WebToolCoreSettings { toolNames: ToolNames; enabledTools: Record; /** Output ceiling for search results and stored-content pages. fetch_content rereads config per call. */ maxInlineContentChars: number; fetchModes: FetchModeConfig; } export interface PageAnswerRequest { question: string; pageText: string; sourceUrl: string; model?: string; } /** Everything that differs between hosts. Pi supplies session persistence, background * notifications, and page answers; the standalone host keeps results in memory only. */ export interface WebToolCoreHost { settings: WebToolCoreSettings; /** Store fetched page content under id so the retrieval tool can page through it. */ storeFetchedContent(id: string, data: FetchedContentData): void; /** Called after search or research results are stored in memory. */ publishResult?(data: StoredSearchData): void; /** Fetch includeContent pages the provider did not cover in the background and return * their responseId. When omitted, web_search awaits the same fetch before returning. */ startBackgroundFetch?(urls: string[], proxy?: string, provided?: ExtractedContent[]): string | null; /** Answers fetch_content mode "answer"; requires the host's model access. */ answerFromPage?(request: PageAnswerRequest, extensionContext: ExtensionContext | undefined, signal?: AbortSignal): Promise<{ text: string; }>; /** Extraction options every fetch in this host adds (for example direct-image policy). */ extractOptions?: Pick; } export type WebToolUpdate = (update: { content: Array<{ type: "text"; text: string; }>; details: Record; }) => void; /** Per-call inputs only Pi has: its live ExtensionContext and partial-result callback. */ export interface WebToolCallOptions { extensionContext?: ExtensionContext | undefined; onUpdate?: WebToolUpdate | undefined; } export interface WebSearchCallOptions extends WebToolCallOptions { /** Generates an auto-summary after searches complete; returning a tool result ends the call. */ summarize?: ((results: QueryResultData[]) => Promise) | undefined; /** Wait for includeContent pages and store them with the result instead of fetching in the background. */ awaitContent?: boolean | undefined; } export type WebSearchParams = Omit & { recencyFilter?: string | undefined; workflow?: string | undefined; }; export type FetchContentToolParams = FetchContentCallParams & FetchContentParams; export type SourceCheckParams = Omit & { recencyFilter?: string | undefined; }; export interface WebToolCoreInstance extends WebToolCore { webSearch(params: WebSearchParams, signal?: AbortSignal, call?: WebSearchCallOptions): Promise; fetchContent(params: FetchContentToolParams, signal?: AbortSignal, call?: WebToolCallOptions): Promise; getSearchContent(params: RawGetSearchContentParams, signal?: AbortSignal): Promise; sourceCheck(params: SourceCheckParams, signal?: AbortSignal, call?: WebToolCallOptions): Promise; /** Formats and stores search results; the Pi curator reuses it for curated returns. */ buildSearchReturn(opts: SearchReturnOptions): WebToolResult; } /** Names fetch guidance may point at: only tools registered this session. */ export declare function registeredFetchToolNames(settings: WebToolCoreSettings): NonNullable; export declare function storedContentSourceNames(settings: WebToolCoreSettings): string; /** Everything presenting a fetch result needs. Answers are shown; the original pages are stored. */ export interface FetchPresentation { mode: FetchMode; /** Retrieval tool to point at, or null when get_search_content is not registered. */ getSearchContentTool: string | null; /** responseId of the stored original content, or null when it was not stored. */ responseId: string | null; maxChars: number; /** URLs the call asked for, in request order. */ urlList: string[]; structuredContent: FetchContentStructuredContent; } export declare function presentSingleFetch(presentation: FetchPresentation, result: ExtractedContent | undefined, params: FetchContentToolParams): WebToolResult; export declare function presentFetchedUrls(presentation: FetchPresentation, results: ExtractedContent[]): WebToolResult; export declare function createWebToolCore(host: WebToolCoreHost): WebToolCoreInstance; export declare function markToolError>(result: T): T; export {};