import { t as formatCliCommand } from "../command-format-BwDuXB2Y.js";
import { d as normalizeSecretInputString, m as resolveSecretInputRef } from "../types.secrets-DdS3-UHE.js";
import { t as enablePluginInConfig } from "../enable-Bm1BGWp3.js";
import { n as normalizeSecretInput } from "../normalize-secret-input-CsdRhsMj.js";
import { b as readStringParam, g as readPositiveIntegerParam, h as readNumberParam, l as jsonResult, m as readNonNegativeIntegerParam, v as readStringArrayParam } from "../common-DT_6Jmmb.js";
import { a as wrapWebContent } from "../external-content-DjKXXY5B.js";
import { a as truncateText, r as markdownToText } from "../web-fetch-utils-pZDHsjC4.js";
import { a as readResponseText, c as resolveTimeoutSeconds, i as readCache, n as DEFAULT_TIMEOUT_SECONDS, o as resolveCacheTtlMs, r as normalizeCacheKey, s as resolvePositiveTimeoutSeconds, t as DEFAULT_CACHE_TTL_MINUTES, u as writeCache } from "../web-shared-BF36JSqC.js";
import { S as writeCachedSearchPayload, _ as resolveSearchTimeoutSeconds, a as buildUnsupportedSearchFilterResponse, b as withSelfHostedWebSearchEndpoint, c as normalizeToIsoDate, d as postTrustedWebToolsJson, f as readCachedSearchPayload, g as resolveSearchCount, h as resolveSearchCacheTtlMs, i as buildSearchCacheKey, l as parseIsoDateRange, m as readProviderEnvValue, n as FRESHNESS_TO_RECENCY, o as isoToPerplexityDate, p as readConfiguredSecretString, r as MAX_SEARCH_COUNT, s as normalizeFreshness, t as DEFAULT_SEARCH_COUNT, u as parseWebSearchTimeFilters, v as resolveSiteName, x as withTrustedWebSearchEndpoint, y as throwWebSearchApiError } from "../web-search-provider-common-CwLTjwii.js";
import { i as withTrustedWebToolsEndpoint, n as withSelfHostedWebToolsEndpoint, r as withStrictWebToolsEndpoint } from "../web-guarded-fetch-Dn9df4aF.js";
import { a as setProviderWebSearchPluginConfigValue, i as resolveProviderWebSearchPluginConfig, n as getTopLevelCredentialValue, o as setScopedCredentialValue, r as mergeScopedSearchConfig, s as setTopLevelCredentialValue, t as getScopedCredentialValue } from "../web-search-provider-config-BM2hIBV9.js";
//#region src/agents/tools/web-search-citation-redirect.ts
const REDIRECT_TIMEOUT_MS = 5e3;
/**
* Resolve a citation redirect URL to its final destination using a HEAD request.
* Returns the original URL if resolution fails or times out.
*/
async function resolveCitationRedirectUrl(url) {
	try {
		return await withStrictWebToolsEndpoint({
			url,
			init: { method: "HEAD" },
			timeoutMs: REDIRECT_TIMEOUT_MS
		}, async ({ finalUrl }) => finalUrl || url);
	} catch {
		return url;
	}
}
//#endregion
//#region src/agents/tools/web-search-provider-credentials.ts
function resolveWebSearchProviderCredential(params) {
	const fromConfig = normalizeSecretInput(normalizeSecretInputString(params.credentialValue));
	if (fromConfig) return fromConfig;
	const credentialRef = resolveSecretInputRef({ value: params.credentialValue }).ref;
	if (credentialRef) {
		if (credentialRef.source !== "env") return;
		const fromEnvRef = normalizeSecretInput(process.env[credentialRef.id]);
		if (fromEnvRef) return fromEnvRef;
		return;
	}
	for (const envVar of params.envVars) {
		const fromEnv = normalizeSecretInput(process.env[envVar]);
		if (fromEnv) return fromEnv;
	}
}
//#endregion
//#region src/plugin-sdk/provider-web-search.ts
/**
* @deprecated Implement provider-owned `createTool(...)` directly on the
* returned WebSearchProviderPlugin instead of routing through core.
*/
function createPluginBackedWebSearchProvider(provider) {
	return {
		...provider,
		createTool: () => {
			throw new Error(`createPluginBackedWebSearchProvider(${provider.id}) is no longer supported. Define provider-owned createTool(...) directly in the extension's WebSearchProviderPlugin.`);
		}
	};
}
//#endregion
export { DEFAULT_CACHE_TTL_MINUTES, DEFAULT_SEARCH_COUNT, DEFAULT_TIMEOUT_SECONDS, FRESHNESS_TO_RECENCY, MAX_SEARCH_COUNT, buildSearchCacheKey, buildUnsupportedSearchFilterResponse, createPluginBackedWebSearchProvider, enablePluginInConfig, formatCliCommand, getScopedCredentialValue, getTopLevelCredentialValue, isoToPerplexityDate, jsonResult, markdownToText, mergeScopedSearchConfig, normalizeCacheKey, normalizeFreshness, normalizeToIsoDate, parseIsoDateRange, parseWebSearchTimeFilters, postTrustedWebToolsJson, readCache, readCachedSearchPayload, readConfiguredSecretString, readNonNegativeIntegerParam, readNumberParam, readPositiveIntegerParam, readProviderEnvValue, readResponseText, readStringArrayParam, readStringParam, resolveCacheTtlMs, resolveCitationRedirectUrl, resolvePositiveTimeoutSeconds, resolveProviderWebSearchPluginConfig, resolveSearchCacheTtlMs, resolveSearchCount, resolveSearchTimeoutSeconds, resolveSiteName, resolveTimeoutSeconds, resolveWebSearchProviderCredential, setProviderWebSearchPluginConfigValue, setScopedCredentialValue, setTopLevelCredentialValue, throwWebSearchApiError, truncateText, withSelfHostedWebSearchEndpoint, withSelfHostedWebToolsEndpoint, withTrustedWebSearchEndpoint, withTrustedWebToolsEndpoint, wrapWebContent, writeCache, writeCachedSearchPayload };
