mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:40:42 +00:00
fix: commit pending plugin install records in config flows
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
import { replaceConfigFile } from "../config/config.js";
|
||||
import type { ConfigWriteOptions } from "../config/io.js";
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import type { PluginInstallRecord } from "../config/types.plugins.js";
|
||||
import {
|
||||
loadInstalledPluginIndexInstallRecords,
|
||||
PLUGIN_INSTALLS_CONFIG_PATH,
|
||||
withoutPluginInstallRecords,
|
||||
writePersistedInstalledPluginIndexInstallRecords,
|
||||
} from "../plugins/installed-plugin-index-records.js";
|
||||
|
||||
function mergeUnsetPaths(
|
||||
left?: ConfigWriteOptions["unsetPaths"],
|
||||
right?: ConfigWriteOptions["unsetPaths"],
|
||||
): ConfigWriteOptions["unsetPaths"] | undefined {
|
||||
const merged = [...(left ?? []), ...(right ?? [])];
|
||||
return merged.length > 0 ? merged : undefined;
|
||||
}
|
||||
|
||||
export async function commitPluginInstallRecordsWithConfig(params: {
|
||||
previousInstallRecords?: Record<string, PluginInstallRecord>;
|
||||
nextInstallRecords: Record<string, PluginInstallRecord>;
|
||||
nextConfig: OpenClawConfig;
|
||||
baseHash?: string;
|
||||
writeOptions?: ConfigWriteOptions;
|
||||
}): Promise<void> {
|
||||
const previousInstallRecords =
|
||||
params.previousInstallRecords ?? (await loadInstalledPluginIndexInstallRecords());
|
||||
@@ -20,7 +31,12 @@ export async function commitPluginInstallRecordsWithConfig(params: {
|
||||
await replaceConfigFile({
|
||||
nextConfig: params.nextConfig,
|
||||
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
|
||||
writeOptions: { unsetPaths: [Array.from(PLUGIN_INSTALLS_CONFIG_PATH)] },
|
||||
writeOptions: {
|
||||
...params.writeOptions,
|
||||
unsetPaths: mergeUnsetPaths(params.writeOptions?.unsetPaths, [
|
||||
Array.from(PLUGIN_INSTALLS_CONFIG_PATH),
|
||||
]),
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
try {
|
||||
@@ -34,3 +50,46 @@ export async function commitPluginInstallRecordsWithConfig(params: {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
export async function commitConfigWithPendingPluginInstalls(params: {
|
||||
nextConfig: OpenClawConfig;
|
||||
baseHash?: string;
|
||||
writeOptions?: ConfigWriteOptions;
|
||||
}): Promise<{
|
||||
config: OpenClawConfig;
|
||||
installRecords: Record<string, PluginInstallRecord>;
|
||||
movedInstallRecords: boolean;
|
||||
}> {
|
||||
const pendingInstallRecords = params.nextConfig.plugins?.installs ?? {};
|
||||
if (Object.keys(pendingInstallRecords).length === 0) {
|
||||
await replaceConfigFile({
|
||||
nextConfig: params.nextConfig,
|
||||
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
|
||||
...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
|
||||
});
|
||||
return {
|
||||
config: params.nextConfig,
|
||||
installRecords: {},
|
||||
movedInstallRecords: false,
|
||||
};
|
||||
}
|
||||
|
||||
const previousInstallRecords = await loadInstalledPluginIndexInstallRecords();
|
||||
const nextInstallRecords = {
|
||||
...previousInstallRecords,
|
||||
...pendingInstallRecords,
|
||||
};
|
||||
const strippedConfig = withoutPluginInstallRecords(params.nextConfig);
|
||||
await commitPluginInstallRecordsWithConfig({
|
||||
previousInstallRecords,
|
||||
nextInstallRecords,
|
||||
nextConfig: strippedConfig,
|
||||
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
|
||||
...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
|
||||
});
|
||||
return {
|
||||
config: strippedConfig,
|
||||
installRecords: nextInstallRecords,
|
||||
movedInstallRecords: true,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user