mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-25 20:05:46 -06:00
refactor(web): trim runtime helper exports
This commit is contained in:
@@ -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[];
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user