export const searchEngineRuntimePort = "BaseToolExecutorPort.network.search";
export const searchEngineDependencyDeclarations = [
    {
        dependencyId: "runtime.executor.network.search",
        kind: "runtime",
        required: true,
        description: "Runtime-provided generic search exposed through BaseToolExecutorPort.network.search.",
    },
    {
        dependencyId: "runtime.governancePlane.searchEngineGuard",
        kind: "permission",
        required: true,
        description: "Runtime search governance, provider policy, and affirmative real-execution guard",
    },
];
export function createRuntimeSearchEngineProvider(dependencies = {}) {
    if (dependencies.provider !== undefined)
        return dependencies.provider;
    const search = dependencies.executor?.network?.search;
    if (search === undefined)
        return undefined;
    return async (request) => {
        const result = await search({
            provider: request.provider,
            query: request.query,
            maxResults: request.maxResults,
            recencyDays: request.recencyDays,
            safeSearch: request.safeSearch,
            locale: request.locale,
            context: request.context,
        });
        if (!result.ok) {
            throw new Error(result.error.message);
        }
        return {
            results: result.output.results.map((item) => ({ title: item.title, url: item.url, snippet: item.snippet, ...(item.raw !== undefined ? { raw: item.raw } : {}) })),
            providerMetadata: {
                runtimeEntry: searchEngineRuntimePort,
                provider: request.provider,
                safeSearch: request.safeSearch,
                ...(result.output.providerMetadata ?? {}),
            },
            ...(result.output.raw !== undefined ? { raw: result.output.raw } : {}),
        };
    };
}
export function createHostExecutorSearchEngineProvider(executor) {
    return createRuntimeSearchEngineProvider({ executor });
}
