

























@@ -17,26 +17,24 @@ function mergeUnsetPaths(
1717return merged.length > 0 ? merged : undefined;
1818}
191920-export async function commitPluginInstallRecordsWithConfig(params: {
20+type ConfigCommit = (config: OpenClawConfig, writeOptions?: ConfigWriteOptions) => Promise<void>;
21+22+async function commitPluginInstallRecordsWithWriter(params: {
2123previousInstallRecords?: Record<string, PluginInstallRecord>;
2224nextInstallRecords: Record<string, PluginInstallRecord>;
2325nextConfig: OpenClawConfig;
24-baseHash?: string;
2526writeOptions?: ConfigWriteOptions;
27+commit: ConfigCommit;
2628}): Promise<void> {
2729const previousInstallRecords =
2830params.previousInstallRecords ?? (await loadInstalledPluginIndexInstallRecords());
2931await writePersistedInstalledPluginIndexInstallRecords(params.nextInstallRecords);
3032try {
31-await replaceConfigFile({
32-nextConfig: params.nextConfig,
33- ...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
34-writeOptions: {
35- ...params.writeOptions,
36-unsetPaths: mergeUnsetPaths(params.writeOptions?.unsetPaths, [
37-Array.from(PLUGIN_INSTALLS_CONFIG_PATH),
38-]),
39-},
33+await params.commit(params.nextConfig, {
34+ ...params.writeOptions,
35+unsetPaths: mergeUnsetPaths(params.writeOptions?.unsetPaths, [
36+Array.from(PLUGIN_INSTALLS_CONFIG_PATH),
37+]),
4038});
4139} catch (error) {
4240try {
@@ -51,22 +49,41 @@ export async function commitPluginInstallRecordsWithConfig(params: {
5149}
5250}
535154-export async function commitConfigWithPendingPluginInstalls(params: {
52+export async function commitPluginInstallRecordsWithConfig(params: {
53+previousInstallRecords?: Record<string, PluginInstallRecord>;
54+nextInstallRecords: Record<string, PluginInstallRecord>;
5555nextConfig: OpenClawConfig;
5656baseHash?: string;
5757writeOptions?: ConfigWriteOptions;
58+}): Promise<void> {
59+await commitPluginInstallRecordsWithWriter({
60+ ...params,
61+commit: async (nextConfig, writeOptions) => {
62+await replaceConfigFile({
63+ nextConfig,
64+ ...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
65+ ...(writeOptions ? { writeOptions } : {}),
66+});
67+},
68+});
69+}
70+71+export async function commitConfigWriteWithPendingPluginInstalls(params: {
72+nextConfig: OpenClawConfig;
73+writeOptions?: ConfigWriteOptions;
74+commit: ConfigCommit;
5875}): Promise<{
5976config: OpenClawConfig;
6077installRecords: Record<string, PluginInstallRecord>;
6178movedInstallRecords: boolean;
6279}> {
6380const pendingInstallRecords = params.nextConfig.plugins?.installs ?? {};
6481if (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-});
82+if (params.writeOptions) {
83+await params.commit(params.nextConfig, params.writeOptions);
84+} else {
85+await params.commit(params.nextConfig);
86+}
7087return {
7188config: params.nextConfig,
7289installRecords: {},
@@ -80,16 +97,38 @@ export async function commitConfigWithPendingPluginInstalls(params: {
8097 ...pendingInstallRecords,
8198};
8299const strippedConfig = withoutPluginInstallRecords(params.nextConfig);
83-await commitPluginInstallRecordsWithConfig({
100+await commitPluginInstallRecordsWithWriter({
84101 previousInstallRecords,
85102 nextInstallRecords,
86103nextConfig: strippedConfig,
87- ...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
88104 ...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
105+commit: params.commit,
89106});
90107return {
91108config: strippedConfig,
92109installRecords: nextInstallRecords,
93110movedInstallRecords: true,
94111};
95112}
113+114+export async function commitConfigWithPendingPluginInstalls(params: {
115+nextConfig: OpenClawConfig;
116+baseHash?: string;
117+writeOptions?: ConfigWriteOptions;
118+}): Promise<{
119+config: OpenClawConfig;
120+installRecords: Record<string, PluginInstallRecord>;
121+movedInstallRecords: boolean;
122+}> {
123+return await commitConfigWriteWithPendingPluginInstalls({
124+nextConfig: params.nextConfig,
125+ ...(params.writeOptions ? { writeOptions: params.writeOptions } : {}),
126+commit: async (nextConfig, writeOptions) => {
127+await replaceConfigFile({
128+ nextConfig,
129+ ...(params.baseHash !== undefined ? { baseHash: params.baseHash } : {}),
130+ ...(writeOptions ? { writeOptions } : {}),
131+});
132+},
133+});
134+}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。