mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-29 02:41:07 +00:00
refactor: share plugin setup helpers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { PluginEntryConfig } from "../config/types.plugins.js";
|
||||
import { hasExplicitPluginConfig } from "./config-state.js";
|
||||
import type { PluginLoadOptions } from "./loader.js";
|
||||
|
||||
export function withBundledPluginAllowlistCompat(params: {
|
||||
@@ -63,3 +64,32 @@ export function withBundledPluginEnablementCompat(params: {
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function withBundledPluginVitestCompat(params: {
|
||||
config: PluginLoadOptions["config"];
|
||||
pluginIds: readonly string[];
|
||||
env?: PluginLoadOptions["env"];
|
||||
}): PluginLoadOptions["config"] {
|
||||
const env = params.env ?? process.env;
|
||||
const isVitest = Boolean(env.VITEST || process.env.VITEST);
|
||||
if (
|
||||
!isVitest ||
|
||||
hasExplicitPluginConfig(params.config?.plugins) ||
|
||||
params.pluginIds.length === 0
|
||||
) {
|
||||
return params.config;
|
||||
}
|
||||
|
||||
return {
|
||||
...params.config,
|
||||
plugins: {
|
||||
...params.config?.plugins,
|
||||
enabled: true,
|
||||
allow: [...params.pluginIds],
|
||||
slots: {
|
||||
...params.config?.plugins?.slots,
|
||||
memory: "none",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { normalizeProviderId } from "../agents/provider-id.js";
|
||||
import { hasExplicitPluginConfig } from "./config-state.js";
|
||||
import { withBundledPluginVitestCompat } from "./bundled-compat.js";
|
||||
import { normalizePluginsConfig, resolveEffectiveEnableState } from "./config-state.js";
|
||||
import type { PluginLoadOptions } from "./loader.js";
|
||||
import { loadPluginManifestRegistry } from "./manifest-registry.js";
|
||||
@@ -9,27 +9,7 @@ export function withBundledProviderVitestCompat(params: {
|
||||
pluginIds: readonly string[];
|
||||
env?: PluginLoadOptions["env"];
|
||||
}): PluginLoadOptions["config"] {
|
||||
const env = params.env ?? process.env;
|
||||
if (
|
||||
!env.VITEST ||
|
||||
hasExplicitPluginConfig(params.config?.plugins) ||
|
||||
params.pluginIds.length === 0
|
||||
) {
|
||||
return params.config;
|
||||
}
|
||||
|
||||
return {
|
||||
...params.config,
|
||||
plugins: {
|
||||
...params.config?.plugins,
|
||||
enabled: true,
|
||||
allow: [...params.pluginIds],
|
||||
slots: {
|
||||
...params.config?.plugins?.slots,
|
||||
memory: "none",
|
||||
},
|
||||
},
|
||||
};
|
||||
return withBundledPluginVitestCompat(params);
|
||||
}
|
||||
|
||||
export function resolveBundledProviderCompatPluginIds(params: {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { isWSL, isWSLEnv } from "../infra/wsl.js";
|
||||
import { isRemoteEnvironment } from "../infra/remote-env.js";
|
||||
import { isWSL } from "../infra/wsl.js";
|
||||
import { runCommandWithTimeout } from "../process/exec.js";
|
||||
import { detectBinary } from "./setup-binary.js";
|
||||
|
||||
export { isRemoteEnvironment } from "../infra/remote-env.js";
|
||||
|
||||
function shouldSkipBrowserOpenInTests(): boolean {
|
||||
if (process.env.VITEST) {
|
||||
return true;
|
||||
@@ -61,27 +64,6 @@ async function resolveBrowserOpenCommand(): Promise<BrowserOpenCommand> {
|
||||
return { argv: null };
|
||||
}
|
||||
|
||||
export function isRemoteEnvironment(): boolean {
|
||||
if (process.env.SSH_CLIENT || process.env.SSH_TTY || process.env.SSH_CONNECTION) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (process.env.REMOTE_CONTAINERS || process.env.CODESPACES) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
process.platform === "linux" &&
|
||||
!process.env.DISPLAY &&
|
||||
!process.env.WAYLAND_DISPLAY &&
|
||||
!isWSLEnv()
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function openUrl(url: string): Promise<boolean> {
|
||||
if (shouldSkipBrowserOpenInTests()) {
|
||||
return false;
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import {
|
||||
withBundledPluginAllowlistCompat,
|
||||
withBundledPluginEnablementCompat,
|
||||
withBundledPluginVitestCompat,
|
||||
} from "./bundled-compat.js";
|
||||
import { resolveBundledWebSearchPluginIds } from "./bundled-web-search.js";
|
||||
import {
|
||||
hasExplicitPluginConfig,
|
||||
normalizePluginsConfig,
|
||||
type NormalizedPluginsConfig,
|
||||
} from "./config-state.js";
|
||||
import { normalizePluginsConfig, type NormalizedPluginsConfig } from "./config-state.js";
|
||||
import type { PluginLoadOptions } from "./loader.js";
|
||||
import type { PluginWebSearchProviderEntry } from "./types.js";
|
||||
|
||||
@@ -23,35 +20,6 @@ function resolveBundledWebSearchCompatPluginIds(params: {
|
||||
});
|
||||
}
|
||||
|
||||
function withBundledWebSearchVitestCompat(params: {
|
||||
config: PluginLoadOptions["config"];
|
||||
pluginIds: readonly string[];
|
||||
env?: PluginLoadOptions["env"];
|
||||
}): PluginLoadOptions["config"] {
|
||||
const env = params.env ?? process.env;
|
||||
const isVitest = Boolean(env.VITEST || process.env.VITEST);
|
||||
if (
|
||||
!isVitest ||
|
||||
hasExplicitPluginConfig(params.config?.plugins) ||
|
||||
params.pluginIds.length === 0
|
||||
) {
|
||||
return params.config;
|
||||
}
|
||||
|
||||
return {
|
||||
...params.config,
|
||||
plugins: {
|
||||
...params.config?.plugins,
|
||||
enabled: true,
|
||||
allow: [...params.pluginIds],
|
||||
slots: {
|
||||
...params.config?.plugins?.slots,
|
||||
memory: "none",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function compareWebSearchProvidersAlphabetically(
|
||||
left: Pick<PluginWebSearchProviderEntry, "id" | "pluginId">,
|
||||
right: Pick<PluginWebSearchProviderEntry, "id" | "pluginId">,
|
||||
@@ -102,7 +70,7 @@ export function resolveBundledWebSearchResolutionConfig(params: {
|
||||
config: allowlistCompat,
|
||||
pluginIds: bundledCompatPluginIds,
|
||||
});
|
||||
const config = withBundledWebSearchVitestCompat({
|
||||
const config = withBundledPluginVitestCompat({
|
||||
config: enablementCompat,
|
||||
pluginIds: bundledCompatPluginIds,
|
||||
env: params.env,
|
||||
|
||||
Reference in New Issue
Block a user