
























@@ -1,17 +1,28 @@
11import { replaceConfigFile } from "../config/config.js";
2+import type { ConfigWriteOptions } from "../config/io.js";
23import type { OpenClawConfig } from "../config/types.openclaw.js";
34import type { PluginInstallRecord } from "../config/types.plugins.js";
45import {
56loadInstalledPluginIndexInstallRecords,
67PLUGIN_INSTALLS_CONFIG_PATH,
8+withoutPluginInstallRecords,
79writePersistedInstalledPluginIndexInstallRecords,
810} from "../plugins/installed-plugin-index-records.js";
91112+function mergeUnsetPaths(
13+left?: ConfigWriteOptions["unsetPaths"],
14+right?: ConfigWriteOptions["unsetPaths"],
15+): ConfigWriteOptions["unsetPaths"] | undefined {
16+const merged = [...(left ?? []), ...(right ?? [])];
17+return merged.length > 0 ? merged : undefined;
18+}
19+1020export async function commitPluginInstallRecordsWithConfig(params: {
1121previousInstallRecords?: Record<string, PluginInstallRecord>;
1222nextInstallRecords: Record<string, PluginInstallRecord>;
1323nextConfig: OpenClawConfig;
1424baseHash?: string;
25+writeOptions?: ConfigWriteOptions;
1526}): Promise<void> {
1627const previousInstallRecords =
1728params.previousInstallRecords ?? (await loadInstalledPluginIndexInstallRecords());
@@ -20,7 +31,12 @@ export async function commitPluginInstallRecordsWithConfig(params: {
2031await replaceConfigFile({
2132nextConfig: params.nextConfig,
2233 ...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
23-writeOptions: { unsetPaths: [Array.from(PLUGIN_INSTALLS_CONFIG_PATH)] },
34+writeOptions: {
35+ ...params.writeOptions,
36+unsetPaths: mergeUnsetPaths(params.writeOptions?.unsetPaths, [
37+Array.from(PLUGIN_INSTALLS_CONFIG_PATH),
38+]),
39+},
2440});
2541} catch (error) {
2642try {
@@ -34,3 +50,46 @@ export async function commitPluginInstallRecordsWithConfig(params: {
3450throw error;
3551}
3652}
53+54+export async function commitConfigWithPendingPluginInstalls(params: {
55+nextConfig: OpenClawConfig;
56+baseHash?: string;
57+writeOptions?: ConfigWriteOptions;
58+}): Promise<{
59+config: OpenClawConfig;
60+installRecords: Record<string, PluginInstallRecord>;
61+movedInstallRecords: boolean;
62+}> {
63+const pendingInstallRecords = params.nextConfig.plugins?.installs ?? {};
64+if (Object.keys(pendingInstallRecords).length === 0) {
65+await replaceConfigFile({
66+nextConfig: params.nextConfig,
67+ ...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
68+ ...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
69+});
70+return {
71+config: params.nextConfig,
72+installRecords: {},
73+movedInstallRecords: false,
74+};
75+}
76+77+const previousInstallRecords = await loadInstalledPluginIndexInstallRecords();
78+const nextInstallRecords = {
79+ ...previousInstallRecords,
80+ ...pendingInstallRecords,
81+};
82+const strippedConfig = withoutPluginInstallRecords(params.nextConfig);
83+await commitPluginInstallRecordsWithConfig({
84+ previousInstallRecords,
85+ nextInstallRecords,
86+nextConfig: strippedConfig,
87+ ...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
88+ ...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
89+});
90+return {
91+config: strippedConfig,
92+installRecords: nextInstallRecords,
93+movedInstallRecords: true,
94+};
95+}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。