mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 07:01:49 +00:00
Tests: share provider registration helpers (#48767)
This commit is contained in:
@@ -32,7 +32,7 @@ import {
|
||||
ZAI_CODING_GLOBAL_BASE_URL,
|
||||
} from "../plugins/provider-model-definitions.js";
|
||||
import type { ProviderPlugin } from "../plugins/types.js";
|
||||
import { createCapturedPluginRegistration } from "../test-utils/plugin-registration.js";
|
||||
import { registerProviderPlugins } from "../test-utils/plugin-registration.js";
|
||||
import type { WizardPrompter } from "../wizard/prompts.js";
|
||||
import { applyAuthChoice, resolvePreferredProviderForAuthChoice } from "./auth-choice.js";
|
||||
import { GOOGLE_GEMINI_DEFAULT_MODEL } from "./google-gemini-model-default.js";
|
||||
@@ -82,8 +82,7 @@ type StoredAuthProfile = {
|
||||
};
|
||||
|
||||
function createDefaultProviderPlugins() {
|
||||
const captured = createCapturedPluginRegistration();
|
||||
for (const plugin of [
|
||||
return registerProviderPlugins(
|
||||
anthropicPlugin,
|
||||
cloudflareAiGatewayPlugin,
|
||||
googlePlugin,
|
||||
@@ -106,10 +105,7 @@ function createDefaultProviderPlugins() {
|
||||
xaiPlugin,
|
||||
xiaomiPlugin,
|
||||
zaiPlugin,
|
||||
]) {
|
||||
plugin.register(captured.api);
|
||||
}
|
||||
return captured.providers;
|
||||
);
|
||||
}
|
||||
|
||||
describe("applyAuthChoice", () => {
|
||||
|
||||
@@ -1,25 +1,7 @@
|
||||
import { createCapturedPluginRegistration } from "../../test-utils/plugin-registration.js";
|
||||
import type { OpenClawPluginApi, ProviderPlugin } from "../types.js";
|
||||
|
||||
type RegistrablePlugin = {
|
||||
register(api: OpenClawPluginApi): void;
|
||||
};
|
||||
|
||||
export function registerProviders(...plugins: RegistrablePlugin[]) {
|
||||
const captured = createCapturedPluginRegistration();
|
||||
for (const plugin of plugins) {
|
||||
plugin.register(captured.api);
|
||||
}
|
||||
return captured.providers;
|
||||
}
|
||||
|
||||
export function requireProvider(providers: ProviderPlugin[], providerId: string) {
|
||||
const provider = providers.find((entry) => entry.id === providerId);
|
||||
if (!provider) {
|
||||
throw new Error(`provider ${providerId} missing`);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
export {
|
||||
registerProviderPlugins as registerProviders,
|
||||
requireRegisteredProvider as requireProvider,
|
||||
} from "../../test-utils/plugin-registration.js";
|
||||
|
||||
export function uniqueSortedStrings(values: readonly string[]) {
|
||||
return [...new Set(values)].toSorted((left, right) => left.localeCompare(right));
|
||||
|
||||
@@ -3,6 +3,10 @@ import type { OpenClawPluginApi, ProviderPlugin } from "../plugins/types.js";
|
||||
|
||||
export { createCapturedPluginRegistration };
|
||||
|
||||
type RegistrablePlugin = {
|
||||
register(api: OpenClawPluginApi): void;
|
||||
};
|
||||
|
||||
export function registerSingleProviderPlugin(params: {
|
||||
register(api: OpenClawPluginApi): void;
|
||||
}): ProviderPlugin {
|
||||
@@ -14,3 +18,19 @@ export function registerSingleProviderPlugin(params: {
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
export function registerProviderPlugins(...plugins: RegistrablePlugin[]): ProviderPlugin[] {
|
||||
const captured = createCapturedPluginRegistration();
|
||||
for (const plugin of plugins) {
|
||||
plugin.register(captured.api);
|
||||
}
|
||||
return captured.providers;
|
||||
}
|
||||
|
||||
export function requireRegisteredProvider(providers: ProviderPlugin[], providerId: string) {
|
||||
const provider = providers.find((entry) => entry.id === providerId);
|
||||
if (!provider) {
|
||||
throw new Error(`provider ${providerId} missing`);
|
||||
}
|
||||
return provider;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user