fix: repair node24 ci type drift

This commit is contained in:
Peter Steinberger 2026-03-16 01:15:31 +00:00
parent b8dbc12560
commit d56559bad7
13 changed files with 58 additions and 19 deletions

View File

@ -44,6 +44,7 @@ function fakeApi(overrides: Partial<OpenClawPluginApi> = {}): OpenClawPluginApi
registerCli() {},
registerService() {},
registerProvider() {},
registerWebSearchProvider() {},
registerInteractiveHandler() {},
registerHook() {},
registerHttpRoute() {},

View File

@ -15,6 +15,7 @@ export function createTestPluginApi(api: TestPluginApiInput): OpenClawPluginApi
registerCli() {},
registerService() {},
registerProvider() {},
registerWebSearchProvider() {},
registerInteractiveHandler() {},
registerCommand() {},
registerContextEngine() {},

View File

@ -58,12 +58,12 @@ const whatsappSetupWizardProxy = {
cfg,
}),
resolveStatusLines: async ({ cfg, configured }) =>
await (
(await (
await loadWhatsAppChannelRuntime()
).whatsappSetupWizard.status.resolveStatusLines?.({
cfg,
configured,
}),
})) ?? [],
},
resolveShouldPromptAccountIds: (params) =>
(params.shouldPromptAccountIds || params.options?.promptWhatsAppAccountId) ?? false,

View File

@ -2,6 +2,10 @@ import type { OpenClawConfig } from "../../config/config.js";
import type { WebSearchProviderPlugin } from "../../plugins/types.js";
import { createWebSearchTool as createLegacyWebSearchTool } from "./web-search-core.js";
type ConfiguredWebSearchProvider = NonNullable<
NonNullable<NonNullable<OpenClawConfig["tools"]>["web"]>["search"]
>["provider"];
function cloneWithDescriptors<T extends object>(value: T | undefined): T {
const next = Object.create(Object.getPrototypeOf(value ?? {})) as T;
if (value) {
@ -10,7 +14,10 @@ function cloneWithDescriptors<T extends object>(value: T | undefined): T {
return next;
}
function withForcedProvider(config: OpenClawConfig | undefined, provider: string): OpenClawConfig {
function withForcedProvider(
config: OpenClawConfig | undefined,
provider: ConfiguredWebSearchProvider,
): OpenClawConfig {
const next = cloneWithDescriptors(config ?? {});
const tools = cloneWithDescriptors(next.tools ?? {});
const web = cloneWithDescriptors(tools.web ?? {});
@ -25,7 +32,9 @@ function withForcedProvider(config: OpenClawConfig | undefined, provider: string
}
export function createPluginBackedWebSearchProvider(
provider: Omit<WebSearchProviderPlugin, "createTool">,
provider: Omit<WebSearchProviderPlugin, "createTool"> & {
id: ConfiguredWebSearchProvider;
},
): WebSearchProviderPlugin {
return {
...provider,

View File

@ -88,6 +88,7 @@ const createRegistry = (channels: PluginRegistry["channels"]): PluginRegistry =>
enabled: true,
})),
providers: [],
webSearchProviders: [],
gatewayHandlers: {},
httpRoutes: [],
cliRegistrars: [],

View File

@ -174,6 +174,10 @@ async function promptWebToolsConfig(
hasKeyInEnv,
} = await import("./onboard-search.js");
type SP = (typeof SEARCH_PROVIDER_OPTIONS)[number]["value"];
const defaultProvider = SEARCH_PROVIDER_OPTIONS[0]?.value;
if (!defaultProvider) {
throw new Error("No web search providers are registered.");
}
const hasKeyForProvider = (provider: string): boolean => {
const entry = SEARCH_PROVIDER_OPTIONS.find((e) => e.value === provider);
@ -183,14 +187,13 @@ async function promptWebToolsConfig(
return hasExistingKey(nextConfig, provider as SP) || hasKeyInEnv(entry);
};
const existingProvider: string = (() => {
const existingProvider: SP = (() => {
const stored = existingSearch?.provider;
if (stored && SEARCH_PROVIDER_OPTIONS.some((e) => e.value === stored)) {
return stored;
return stored as SP;
}
return (
SEARCH_PROVIDER_OPTIONS.find((e) => hasKeyForProvider(e.value))?.value ??
SEARCH_PROVIDER_OPTIONS[0].value
SEARCH_PROVIDER_OPTIONS.find((e) => hasKeyForProvider(e.value))?.value ?? defaultProvider
);
})();

View File

@ -11,7 +11,21 @@ import type { RuntimeEnv } from "../runtime.js";
import type { WizardPrompter } from "../wizard/prompts.js";
import type { SecretInputMode } from "./onboard-types.js";
export type SearchProvider = string;
export type SearchProvider = NonNullable<
NonNullable<NonNullable<NonNullable<OpenClawConfig["tools"]>["web"]>["search"]>["provider"]
>;
const SEARCH_PROVIDER_IDS = ["brave", "gemini", "grok", "kimi", "perplexity"] as const;
function isSearchProvider(value: string): value is SearchProvider {
return (SEARCH_PROVIDER_IDS as readonly string[]).includes(value);
}
function hasSearchProviderId<T extends { id: string }>(
provider: T,
): provider is T & { id: SearchProvider } {
return isSearchProvider(provider.id);
}
type SearchProviderEntry = {
value: SearchProvider;
@ -25,14 +39,16 @@ type SearchProviderEntry = {
export const SEARCH_PROVIDER_OPTIONS: readonly SearchProviderEntry[] =
resolvePluginWebSearchProviders({
bundledAllowlistCompat: true,
}).map((provider) => ({
value: provider.id,
label: provider.label,
hint: provider.hint,
envKeys: provider.envVars,
placeholder: provider.placeholder,
signupUrl: provider.signupUrl,
}));
})
.filter(hasSearchProviderId)
.map((provider) => ({
value: provider.id,
label: provider.label,
hint: provider.hint,
envKeys: provider.envVars,
placeholder: provider.placeholder,
signupUrl: provider.signupUrl,
}));
export function hasKeyInEnv(entry: SearchProviderEntry): boolean {
return entry.envKeys.some((k) => Boolean(process.env[k]?.trim()));
@ -178,7 +194,7 @@ export async function setupSearch(
return SEARCH_PROVIDER_OPTIONS[0].value;
})();
type PickerValue = string;
type PickerValue = SearchProvider | "__skip__";
const choice = await prompter.select<PickerValue>({
message: "Search provider",
options: [

View File

@ -335,6 +335,7 @@ describe("ensureOnboardingPluginInstalled", () => {
hookNames: [],
channelIds: [],
providerIds: [],
webSearchProviderIds: [],
gatewayMethods: [],
cliCommands: [],
services: [],

View File

@ -1,6 +1,7 @@
import fs from "node:fs/promises";
import path from "node:path";
import { withTempHome as withTempHomeBase } from "../../test/helpers/temp-home.js";
import type { OpenClawConfig } from "./config.js";
export async function withTempHome<T>(fn: (home: string) => Promise<T>): Promise<T> {
return withTempHomeBase(fn, { prefix: "openclaw-config-" });
@ -53,7 +54,9 @@ export async function withEnvOverride<T>(
}
export function buildWebSearchProviderConfig(params: {
provider: string;
provider: NonNullable<
NonNullable<NonNullable<NonNullable<OpenClawConfig["tools"]>["web"]>["search"]>["provider"]
>;
enabled?: boolean;
providerConfig?: Record<string, unknown>;
}): Record<string, unknown> {

View File

@ -29,6 +29,7 @@ const createRegistry = (diagnostics: PluginDiagnostic[]): PluginRegistry => ({
channelSetups: [],
commands: [],
providers: [],
webSearchProviders: [],
gatewayHandlers: {},
httpRoutes: [],
cliRegistrars: [],

View File

@ -11,6 +11,7 @@ export const registryState: { registry: PluginRegistry } = {
channels: [],
channelSetups: [],
providers: [],
webSearchProviders: [],
gatewayHandlers: {},
httpHandlers: [],
httpRoutes: [],

View File

@ -146,6 +146,7 @@ const createStubPluginRegistry = (): PluginRegistry => ({
],
channelSetups: [],
providers: [],
webSearchProviders: [],
gatewayHandlers: {},
httpRoutes: [],
cliRegistrars: [],

View File

@ -25,6 +25,7 @@ export const createTestRegistry = (channels: TestChannelRegistration[] = []): Pl
enabled: true,
})),
providers: [],
webSearchProviders: [],
gatewayHandlers: {},
httpRoutes: [],
cliRegistrars: [],