fix: persist pending onboarding plugin installs

This commit is contained in:
Shakker
2026-04-26 02:33:07 +01:00
parent 2495585a32
commit 29463b9c47
6 changed files with 224 additions and 44 deletions

View File

@@ -17,26 +17,24 @@ function mergeUnsetPaths(
return merged.length > 0 ? merged : undefined;
}
export async function commitPluginInstallRecordsWithConfig(params: {
type ConfigCommit = (config: OpenClawConfig, writeOptions?: ConfigWriteOptions) => Promise<void>;
async function commitPluginInstallRecordsWithWriter(params: {
previousInstallRecords?: Record<string, PluginInstallRecord>;
nextInstallRecords: Record<string, PluginInstallRecord>;
nextConfig: OpenClawConfig;
baseHash?: string;
writeOptions?: ConfigWriteOptions;
commit: ConfigCommit;
}): Promise<void> {
const previousInstallRecords =
params.previousInstallRecords ?? (await loadInstalledPluginIndexInstallRecords());
await writePersistedInstalledPluginIndexInstallRecords(params.nextInstallRecords);
try {
await replaceConfigFile({
nextConfig: params.nextConfig,
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
writeOptions: {
...params.writeOptions,
unsetPaths: mergeUnsetPaths(params.writeOptions?.unsetPaths, [
Array.from(PLUGIN_INSTALLS_CONFIG_PATH),
]),
},
await params.commit(params.nextConfig, {
...params.writeOptions,
unsetPaths: mergeUnsetPaths(params.writeOptions?.unsetPaths, [
Array.from(PLUGIN_INSTALLS_CONFIG_PATH),
]),
});
} catch (error) {
try {
@@ -51,10 +49,29 @@ export async function commitPluginInstallRecordsWithConfig(params: {
}
}
export async function commitConfigWithPendingPluginInstalls(params: {
export async function commitPluginInstallRecordsWithConfig(params: {
previousInstallRecords?: Record<string, PluginInstallRecord>;
nextInstallRecords: Record<string, PluginInstallRecord>;
nextConfig: OpenClawConfig;
baseHash?: string;
writeOptions?: ConfigWriteOptions;
}): Promise<void> {
await commitPluginInstallRecordsWithWriter({
...params,
commit: async (nextConfig, writeOptions) => {
await replaceConfigFile({
nextConfig,
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
...(writeOptions ? { writeOptions } : {}),
});
},
});
}
export async function commitConfigWriteWithPendingPluginInstalls(params: {
nextConfig: OpenClawConfig;
writeOptions?: ConfigWriteOptions;
commit: ConfigCommit;
}): Promise<{
config: OpenClawConfig;
installRecords: Record<string, PluginInstallRecord>;
@@ -62,11 +79,11 @@ export async function commitConfigWithPendingPluginInstalls(params: {
}> {
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 } : {}),
});
if (params.writeOptions) {
await params.commit(params.nextConfig, params.writeOptions);
} else {
await params.commit(params.nextConfig);
}
return {
config: params.nextConfig,
installRecords: {},
@@ -80,12 +97,12 @@ export async function commitConfigWithPendingPluginInstalls(params: {
...pendingInstallRecords,
};
const strippedConfig = withoutPluginInstallRecords(params.nextConfig);
await commitPluginInstallRecordsWithConfig({
await commitPluginInstallRecordsWithWriter({
previousInstallRecords,
nextInstallRecords,
nextConfig: strippedConfig,
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
commit: params.commit,
});
return {
config: strippedConfig,
@@ -93,3 +110,25 @@ export async function commitConfigWithPendingPluginInstalls(params: {
movedInstallRecords: true,
};
}
export async function commitConfigWithPendingPluginInstalls(params: {
nextConfig: OpenClawConfig;
baseHash?: string;
writeOptions?: ConfigWriteOptions;
}): Promise<{
config: OpenClawConfig;
installRecords: Record<string, PluginInstallRecord>;
movedInstallRecords: boolean;
}> {
return await commitConfigWriteWithPendingPluginInstalls({
nextConfig: params.nextConfig,
...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
commit: async (nextConfig, writeOptions) => {
await replaceConfigFile({
nextConfig,
...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
...(writeOptions ? { writeOptions } : {}),
});
},
});
}