mirror of https://github.com/openclaw/openclaw.git
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import type { OpenClawConfig } from "../config/config.js";
|
|
import { writeConfigFile } from "../config/config.js";
|
|
import { type HookInstallUpdate, recordHookInstall } from "../hooks/installs.js";
|
|
import { enablePluginInConfig } from "../plugins/enable.js";
|
|
import { type PluginInstallUpdate, recordPluginInstall } from "../plugins/installs.js";
|
|
import { defaultRuntime } from "../runtime.js";
|
|
import { theme } from "../terminal/theme.js";
|
|
import {
|
|
applySlotSelectionForPlugin,
|
|
enableInternalHookEntries,
|
|
logHookPackRestartHint,
|
|
logSlotWarnings,
|
|
} from "./plugins-command-helpers.js";
|
|
|
|
export async function persistPluginInstall(params: {
|
|
config: OpenClawConfig;
|
|
pluginId: string;
|
|
install: Omit<PluginInstallUpdate, "pluginId">;
|
|
successMessage?: string;
|
|
warningMessage?: string;
|
|
}): Promise<OpenClawConfig> {
|
|
let next = enablePluginInConfig(params.config, params.pluginId).config;
|
|
next = recordPluginInstall(next, {
|
|
pluginId: params.pluginId,
|
|
...params.install,
|
|
});
|
|
const slotResult = applySlotSelectionForPlugin(next, params.pluginId);
|
|
next = slotResult.config;
|
|
await writeConfigFile(next);
|
|
logSlotWarnings(slotResult.warnings);
|
|
if (params.warningMessage) {
|
|
defaultRuntime.log(theme.warn(params.warningMessage));
|
|
}
|
|
defaultRuntime.log(params.successMessage ?? `Installed plugin: ${params.pluginId}`);
|
|
defaultRuntime.log("Restart the gateway to load plugins.");
|
|
return next;
|
|
}
|
|
|
|
export async function persistHookPackInstall(params: {
|
|
config: OpenClawConfig;
|
|
hookPackId: string;
|
|
hooks: string[];
|
|
install: Omit<HookInstallUpdate, "hookId" | "hooks">;
|
|
successMessage?: string;
|
|
}): Promise<OpenClawConfig> {
|
|
let next = enableInternalHookEntries(params.config, params.hooks);
|
|
next = recordHookInstall(next, {
|
|
hookId: params.hookPackId,
|
|
hooks: params.hooks,
|
|
...params.install,
|
|
});
|
|
await writeConfigFile(next);
|
|
defaultRuntime.log(params.successMessage ?? `Installed hook pack: ${params.hookPackId}`);
|
|
logHookPackRestartHint();
|
|
return next;
|
|
}
|