mirror of https://github.com/openclaw/openclaw.git
refactor: trim image generation runtime imports
This commit is contained in:
parent
768ec2a712
commit
42786afc64
|
|
@ -1,4 +1,8 @@
|
|||
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
generateImage,
|
||||
listRuntimeImageGenerationProviders,
|
||||
} from "../../extensions/image-generation-core/runtime-api.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createEmptyPluginRegistry } from "../plugins/registry.js";
|
||||
import { resetPluginRuntimeStateForTest, setActivePluginRegistry } from "../plugins/runtime.js";
|
||||
|
|
@ -13,9 +17,6 @@ vi.mock("../plugins/loader.js", () => ({
|
|||
resolveRuntimePluginRegistry: resolveRuntimePluginRegistryMock,
|
||||
}));
|
||||
|
||||
let generateImage: typeof import("./runtime.js").generateImage;
|
||||
let listRuntimeImageGenerationProviders: typeof import("./runtime.js").listRuntimeImageGenerationProviders;
|
||||
|
||||
function setCompatibleActiveImageGenerationRegistry(
|
||||
pluginRegistry: ReturnType<typeof createEmptyPluginRegistry>,
|
||||
_cfg: OpenClawConfig,
|
||||
|
|
@ -24,10 +25,6 @@ function setCompatibleActiveImageGenerationRegistry(
|
|||
}
|
||||
|
||||
describe("image-generation runtime helpers", () => {
|
||||
beforeAll(async () => {
|
||||
({ generateImage, listRuntimeImageGenerationProviders } = await import("./runtime.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
resolveRuntimePluginRegistryMock.mockReset();
|
||||
resolveRuntimePluginRegistryMock.mockReturnValue(undefined);
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
export { resolveApiKeyForProvider } from "../agents/model-auth.js";
|
||||
|
|
@ -14,7 +14,6 @@ export type {
|
|||
export type { OpenClawConfig } from "../config/config.js";
|
||||
|
||||
export { describeFailoverError, isFailoverError } from "../agents/failover-error.js";
|
||||
export { resolveApiKeyForProvider } from "../agents/model-auth.js";
|
||||
export {
|
||||
resolveAgentModelFallbackValues,
|
||||
resolveAgentModelPrimaryValue,
|
||||
|
|
@ -27,5 +26,24 @@ export {
|
|||
export { parseImageGenerationModelRef } from "../image-generation/model-ref.js";
|
||||
export { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
export { normalizeGoogleModelId } from "./google.js";
|
||||
export { OPENAI_DEFAULT_IMAGE_MODEL } from "./openai.js";
|
||||
export { getProviderEnvVars } from "../secrets/provider-env-vars.js";
|
||||
export { OPENAI_DEFAULT_IMAGE_MODEL } from "../plugins/provider-model-defaults.js";
|
||||
|
||||
type ImageGenerationCoreAuthRuntimeModule =
|
||||
typeof import("./image-generation-core.auth.runtime.js");
|
||||
|
||||
let imageGenerationCoreAuthRuntimePromise:
|
||||
| Promise<ImageGenerationCoreAuthRuntimeModule>
|
||||
| undefined;
|
||||
|
||||
async function loadImageGenerationCoreAuthRuntime(): Promise<ImageGenerationCoreAuthRuntimeModule> {
|
||||
imageGenerationCoreAuthRuntimePromise ??= import("./image-generation-core.auth.runtime.js");
|
||||
return imageGenerationCoreAuthRuntimePromise;
|
||||
}
|
||||
|
||||
export async function resolveApiKeyForProvider(
|
||||
...args: Parameters<ImageGenerationCoreAuthRuntimeModule["resolveApiKeyForProvider"]>
|
||||
): Promise<Awaited<ReturnType<ImageGenerationCoreAuthRuntimeModule["resolveApiKeyForProvider"]>>> {
|
||||
const runtime = await loadImageGenerationCoreAuthRuntime();
|
||||
return runtime.resolveApiKeyForProvider(...args);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { PluginEntryConfig } from "../config/types.plugins.js";
|
||||
import { hasExplicitPluginConfig } from "./config-state.js";
|
||||
import { hasExplicitPluginConfig } from "./config-policy.js";
|
||||
import type { PluginLoadOptions } from "./loader.js";
|
||||
|
||||
export function withBundledPluginAllowlistCompat(params: {
|
||||
|
|
|
|||
|
|
@ -318,7 +318,30 @@ export function resolvePluginActivationState(params: {
|
|||
source: "default",
|
||||
};
|
||||
}
|
||||
|
||||
export function hasExplicitPluginConfig(plugins?: OpenClawConfig["plugins"]): boolean {
|
||||
if (!plugins) {
|
||||
return false;
|
||||
}
|
||||
if (typeof plugins.enabled === "boolean") {
|
||||
return true;
|
||||
}
|
||||
if (Array.isArray(plugins.allow) && plugins.allow.length > 0) {
|
||||
return true;
|
||||
}
|
||||
if (Array.isArray(plugins.deny) && plugins.deny.length > 0) {
|
||||
return true;
|
||||
}
|
||||
if (plugins.load?.paths && Array.isArray(plugins.load.paths) && plugins.load.paths.length > 0) {
|
||||
return true;
|
||||
}
|
||||
if (plugins.slots && Object.keys(plugins.slots).length > 0) {
|
||||
return true;
|
||||
}
|
||||
if (plugins.entries && Object.keys(plugins.entries).length > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
export function resolveEnableState(
|
||||
id: string,
|
||||
origin: PluginOrigin,
|
||||
|
|
|
|||
Loading…
Reference in New Issue