refactor(web): trim runtime helper exports

This commit is contained in:
Vincent Koc
2026-06-17 16:53:46 +08:00
parent 4ae94d1d46
commit b962c53e78
3 changed files with 6 additions and 72 deletions
+3 -12
View File
@@ -29,7 +29,7 @@ type WebFetchConfig = NonNullable<OpenClawConfig["tools"]>["web"] extends infer
: undefined
: undefined;
export type ResolveWebFetchDefinitionParams = {
type ResolveWebFetchDefinitionParams = {
config?: OpenClawConfig;
sandboxed?: boolean;
runtimeWebFetch?: RuntimeWebFetchMetadata;
@@ -38,7 +38,7 @@ export type ResolveWebFetchDefinitionParams = {
};
/** Resolves whether web_fetch is enabled for the current config/sandbox. */
export function resolveWebFetchEnabled(params: {
function resolveWebFetchEnabled(params: {
fetch?: WebFetchConfig;
sandboxed?: boolean;
}): boolean {
@@ -102,17 +102,8 @@ export function listWebFetchProviders(params?: {
});
}
/** Lists plugin-configured web_fetch providers. */
export function listConfiguredWebFetchProviders(params?: {
config?: OpenClawConfig;
}): PluginWebFetchProviderEntry[] {
return resolvePluginWebFetchProviders({
config: params?.config,
});
}
/** Resolves the configured or auto-detected web_fetch provider id. */
export function resolveWebFetchProviderId(params: {
function resolveWebFetchProviderId(params: {
fetch?: WebFetchConfig;
config?: OpenClawConfig;
providers?: PluginWebFetchProviderEntry[];
+1 -35
View File
@@ -165,14 +165,13 @@ function createDuckDuckGoSearchProvider(
describe("web search runtime", () => {
let runWebSearch: typeof import("./runtime.js").runWebSearch;
let resolveWebSearchDefinition: typeof import("./runtime.js").resolveWebSearchDefinition;
let activateSecretsRuntimeSnapshot: typeof import("../secrets/runtime.js").activateSecretsRuntimeSnapshot;
let clearSecretsRuntimeSnapshot: typeof import("../secrets/runtime.js").clearSecretsRuntimeSnapshot;
let setRuntimeConfigSnapshot: typeof import("../config/config.js").setRuntimeConfigSnapshot;
const tempDirs: string[] = [];
beforeAll(async () => {
({ resolveWebSearchDefinition, runWebSearch } = await import("./runtime.js"));
({ runWebSearch } = await import("./runtime.js"));
({ activateSecretsRuntimeSnapshot, clearSecretsRuntimeSnapshot } =
await import("../secrets/runtime.js"));
({ setRuntimeConfigSnapshot } = await import("../config/config.js"));
@@ -591,16 +590,6 @@ describe("web search runtime", () => {
).rejects.toThrow("web_search is disabled or no provider is available.");
});
it("does not resolve a keyless provider definition when no provider is configured", () => {
resolvePluginWebSearchProvidersMock.mockReturnValue([createDuckDuckGoSearchProvider()]);
const resolved = resolveWebSearchDefinition({
config: {},
});
expect(resolved).toBeNull();
});
it("uses a keyless provider when the user explicitly selects it", async () => {
resolveRuntimeWebSearchProvidersMock.mockReturnValue([createDuckDuckGoSearchProvider()]);
@@ -774,29 +763,6 @@ describe("web search runtime", () => {
expect(createTool).not.toHaveBeenCalled();
});
it("ignores auto-detected keyless runtime metadata when resolving a provider definition", () => {
resolvePluginWebSearchProvidersMock.mockReturnValue([
createWebSearchTestProvider({
pluginId: "parallel",
id: "parallel-free",
credentialPath: "",
autoDetectOrder: 76,
requiresCredential: false,
}),
]);
const resolved = resolveWebSearchDefinition({
config: {},
runtimeWebSearch: {
providerSource: "auto-detect",
selectedProvider: "parallel-free",
diagnostics: [],
},
});
expect(resolved).toBeNull();
});
it("falls back to another provider when auto-selected search execution fails", async () => {
resolveRuntimeWebSearchProvidersMock.mockReturnValue([
createGoogleSearchProvider({
+2 -25
View File
@@ -39,18 +39,6 @@ import type {
RuntimeWebSearchConfig as WebSearchConfig,
} from "./runtime-types.js";
// Runtime provider selection and execution for web_search. This keeps plugin,
// runtime, and explicit provider selections aligned before a tool executes.
export type {
ListWebSearchProvidersParams,
ResolveWebSearchDefinitionParams,
RunWebSearchParams,
RunWebSearchResult,
RuntimeWebSearchConfig,
RuntimeWebSearchProviderEntry,
RuntimeWebSearchToolDefinition,
} from "./runtime-types.js";
function resolveSearchConfig(cfg?: OpenClawConfig): WebSearchConfig {
return resolveWebProviderConfig(cfg, "search") as NonNullable<WebSearchConfig> | undefined;
}
@@ -70,7 +58,7 @@ function resolveWebSearchRuntimeConfig(params?: {
}
/** Resolves whether web_search is enabled for the current config/sandbox. */
export function resolveWebSearchEnabled(params: {
function resolveWebSearchEnabled(params: {
search?: WebSearchConfig;
sandboxed?: boolean;
}): boolean {
@@ -383,7 +371,7 @@ function loadSortedWebSearchProviders(
}
/** Resolves the executable web_search provider tool definition. */
export function resolveWebSearchDefinition(
function resolveWebSearchDefinition(
options?: ResolveWebSearchDefinitionParams,
): { provider: PluginWebSearchProviderEntry; definition: WebSearchProviderToolDefinition } | null {
const { config, search, runtimeWebSearch } = resolveWebSearchRequestContext(options);
@@ -603,14 +591,3 @@ export async function runWebSearch(params: RunWebSearchParams): Promise<RunWebSe
}
throw lastError instanceof Error ? lastError : new Error(String(lastError));
}
export const testing = {
resolveSearchConfig,
resolveSearchProvider: resolveWebSearchProviderId,
resolveWebSearchProviderId,
resolveWebSearchCandidates,
resolveExplicitWebSearchProviderId,
resolveExplicitWebSearchProviderPluginIds,
hasExplicitWebSearchSelection,
};
export { testing as __testing };