mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
refactor(plugins): reuse plugin loader logger adapter
This commit is contained in:
@@ -8,6 +8,7 @@ import { enablePluginInConfig } from "../../plugins/enable.js";
|
||||
import { installPluginFromNpmSpec } from "../../plugins/install.js";
|
||||
import { recordPluginInstall } from "../../plugins/installs.js";
|
||||
import { loadOpenClawPlugins } from "../../plugins/loader.js";
|
||||
import { createPluginLoaderLogger } from "../../plugins/logger.js";
|
||||
import type { RuntimeEnv } from "../../runtime.js";
|
||||
import type { WizardPrompter } from "../../wizard/prompts.js";
|
||||
|
||||
@@ -211,11 +212,6 @@ export function reloadOnboardingPluginRegistry(params: {
|
||||
config: params.cfg,
|
||||
workspaceDir,
|
||||
cache: false,
|
||||
logger: {
|
||||
info: (msg) => log.info(msg),
|
||||
warn: (msg) => log.warn(msg),
|
||||
error: (msg) => log.error(msg),
|
||||
debug: (msg) => log.debug(msg),
|
||||
},
|
||||
logger: createPluginLoaderLogger(log),
|
||||
});
|
||||
}
|
||||
|
||||
22
src/plugins/logger.test.ts
Normal file
22
src/plugins/logger.test.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { createPluginLoaderLogger } from "./logger.js";
|
||||
|
||||
describe("plugins/logger", () => {
|
||||
it("forwards logger methods", () => {
|
||||
const info = vi.fn();
|
||||
const warn = vi.fn();
|
||||
const error = vi.fn();
|
||||
const debug = vi.fn();
|
||||
const logger = createPluginLoaderLogger({ info, warn, error, debug });
|
||||
|
||||
logger.info("i");
|
||||
logger.warn("w");
|
||||
logger.error("e");
|
||||
logger.debug?.("d");
|
||||
|
||||
expect(info).toHaveBeenCalledWith("i");
|
||||
expect(warn).toHaveBeenCalledWith("w");
|
||||
expect(error).toHaveBeenCalledWith("e");
|
||||
expect(debug).toHaveBeenCalledWith("d");
|
||||
});
|
||||
});
|
||||
17
src/plugins/logger.ts
Normal file
17
src/plugins/logger.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import type { PluginLogger } from "./types.js";
|
||||
|
||||
type LoggerLike = {
|
||||
info: (message: string) => void;
|
||||
warn: (message: string) => void;
|
||||
error: (message: string) => void;
|
||||
debug?: (message: string) => void;
|
||||
};
|
||||
|
||||
export function createPluginLoaderLogger(logger: LoggerLike): PluginLogger {
|
||||
return {
|
||||
info: (msg) => logger.info(msg),
|
||||
warn: (msg) => logger.warn(msg),
|
||||
error: (msg) => logger.error(msg),
|
||||
debug: (msg) => logger.debug?.(msg),
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { loadOpenClawPlugins, type PluginLoadOptions } from "./loader.js";
|
||||
import { createPluginLoaderLogger } from "./logger.js";
|
||||
import type { ProviderPlugin } from "./types.js";
|
||||
|
||||
const log = createSubsystemLogger("plugins");
|
||||
@@ -11,12 +12,7 @@ export function resolvePluginProviders(params: {
|
||||
const registry = loadOpenClawPlugins({
|
||||
config: params.config,
|
||||
workspaceDir: params.workspaceDir,
|
||||
logger: {
|
||||
info: (msg) => log.info(msg),
|
||||
warn: (msg) => log.warn(msg),
|
||||
error: (msg) => log.error(msg),
|
||||
debug: (msg) => log.debug(msg),
|
||||
},
|
||||
logger: createPluginLoaderLogger(log),
|
||||
});
|
||||
|
||||
return registry.providers.map((entry) => entry.provider);
|
||||
|
||||
@@ -3,6 +3,7 @@ import { resolveDefaultAgentWorkspaceDir } from "../agents/workspace.js";
|
||||
import { loadConfig } from "../config/config.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { loadOpenClawPlugins } from "./loader.js";
|
||||
import { createPluginLoaderLogger } from "./logger.js";
|
||||
import type { PluginRegistry } from "./registry.js";
|
||||
|
||||
export type PluginStatusReport = PluginRegistry & {
|
||||
@@ -24,12 +25,7 @@ export function buildPluginStatusReport(params?: {
|
||||
const registry = loadOpenClawPlugins({
|
||||
config,
|
||||
workspaceDir,
|
||||
logger: {
|
||||
info: (msg) => log.info(msg),
|
||||
warn: (msg) => log.warn(msg),
|
||||
error: (msg) => log.error(msg),
|
||||
debug: (msg) => log.debug(msg),
|
||||
},
|
||||
logger: createPluginLoaderLogger(log),
|
||||
});
|
||||
|
||||
return {
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { AnyAgentTool } from "../agents/tools/common.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { applyTestPluginDefaults, normalizePluginsConfig } from "./config-state.js";
|
||||
import { loadOpenClawPlugins } from "./loader.js";
|
||||
import { createPluginLoaderLogger } from "./logger.js";
|
||||
import type { OpenClawPluginToolContext } from "./types.js";
|
||||
|
||||
const log = createSubsystemLogger("plugins");
|
||||
@@ -57,12 +58,7 @@ export function resolvePluginTools(params: {
|
||||
const registry = loadOpenClawPlugins({
|
||||
config: effectiveConfig,
|
||||
workspaceDir: params.context.workspaceDir,
|
||||
logger: {
|
||||
info: (msg) => log.info(msg),
|
||||
warn: (msg) => log.warn(msg),
|
||||
error: (msg) => log.error(msg),
|
||||
debug: (msg) => log.debug(msg),
|
||||
},
|
||||
logger: createPluginLoaderLogger(log),
|
||||
});
|
||||
|
||||
const tools: AnyAgentTool[] = [];
|
||||
|
||||
Reference in New Issue
Block a user