mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:10:45 +00:00
fix(plugins): break metadata snapshot cycle
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
||||
import {
|
||||
clearCurrentPluginMetadataSnapshotState,
|
||||
getCurrentPluginMetadataSnapshotState,
|
||||
setCurrentPluginMetadataSnapshotState,
|
||||
} from "./current-plugin-metadata-state.js";
|
||||
import { resolveInstalledPluginIndexPolicyHash } from "./installed-plugin-index-policy.js";
|
||||
import type { PluginMetadataSnapshot } from "./plugin-metadata-snapshot.types.js";
|
||||
|
||||
let currentPluginMetadataSnapshot: PluginMetadataSnapshot | undefined;
|
||||
let currentPluginMetadataSnapshotConfigFingerprint: string | undefined;
|
||||
|
||||
function normalizeLoadPaths(config: OpenClawConfig | undefined): readonly string[] {
|
||||
const paths = config?.plugins?.load?.paths;
|
||||
if (!Array.isArray(paths)) {
|
||||
@@ -28,15 +30,14 @@ export function setCurrentPluginMetadataSnapshot(
|
||||
snapshot: PluginMetadataSnapshot | undefined,
|
||||
options: { config?: OpenClawConfig } = {},
|
||||
): void {
|
||||
currentPluginMetadataSnapshot = snapshot;
|
||||
currentPluginMetadataSnapshotConfigFingerprint = snapshot
|
||||
? resolvePluginMetadataSnapshotConfigFingerprint(options.config)
|
||||
: undefined;
|
||||
setCurrentPluginMetadataSnapshotState(
|
||||
snapshot,
|
||||
snapshot ? resolvePluginMetadataSnapshotConfigFingerprint(options.config) : undefined,
|
||||
);
|
||||
}
|
||||
|
||||
export function clearCurrentPluginMetadataSnapshot(): void {
|
||||
currentPluginMetadataSnapshot = undefined;
|
||||
currentPluginMetadataSnapshotConfigFingerprint = undefined;
|
||||
clearCurrentPluginMetadataSnapshotState();
|
||||
}
|
||||
|
||||
export function getCurrentPluginMetadataSnapshot(
|
||||
@@ -45,7 +46,8 @@ export function getCurrentPluginMetadataSnapshot(
|
||||
workspaceDir?: string;
|
||||
} = {},
|
||||
): PluginMetadataSnapshot | undefined {
|
||||
const snapshot = currentPluginMetadataSnapshot;
|
||||
const { snapshot: rawSnapshot, configFingerprint } = getCurrentPluginMetadataSnapshotState();
|
||||
const snapshot = rawSnapshot as PluginMetadataSnapshot | undefined;
|
||||
if (!snapshot) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -57,9 +59,8 @@ export function getCurrentPluginMetadataSnapshot(
|
||||
}
|
||||
if (
|
||||
params.config &&
|
||||
currentPluginMetadataSnapshotConfigFingerprint &&
|
||||
currentPluginMetadataSnapshotConfigFingerprint !==
|
||||
resolvePluginMetadataSnapshotConfigFingerprint(params.config)
|
||||
configFingerprint &&
|
||||
configFingerprint !== resolvePluginMetadataSnapshotConfigFingerprint(params.config)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
25
src/plugins/current-plugin-metadata-state.ts
Normal file
25
src/plugins/current-plugin-metadata-state.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
let currentPluginMetadataSnapshot: unknown;
|
||||
let currentPluginMetadataSnapshotConfigFingerprint: string | undefined;
|
||||
|
||||
export function setCurrentPluginMetadataSnapshotState(
|
||||
snapshot: unknown,
|
||||
configFingerprint: string | undefined,
|
||||
): void {
|
||||
currentPluginMetadataSnapshot = snapshot;
|
||||
currentPluginMetadataSnapshotConfigFingerprint = snapshot ? configFingerprint : undefined;
|
||||
}
|
||||
|
||||
export function clearCurrentPluginMetadataSnapshotState(): void {
|
||||
currentPluginMetadataSnapshot = undefined;
|
||||
currentPluginMetadataSnapshotConfigFingerprint = undefined;
|
||||
}
|
||||
|
||||
export function getCurrentPluginMetadataSnapshotState(): {
|
||||
snapshot: unknown;
|
||||
configFingerprint: string | undefined;
|
||||
} {
|
||||
return {
|
||||
snapshot: currentPluginMetadataSnapshot,
|
||||
configFingerprint: currentPluginMetadataSnapshotConfigFingerprint,
|
||||
};
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import { saveJsonFile } from "../infra/json-file.js";
|
||||
import { readJsonFile, readJsonFileSync, writeJsonAtomic } from "../infra/json-files.js";
|
||||
import { isBlockedObjectKey } from "../infra/prototype-keys.js";
|
||||
import { safeParseWithSchema } from "../utils/zod-parse.js";
|
||||
import { clearCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot.js";
|
||||
import { clearCurrentPluginMetadataSnapshotState } from "./current-plugin-metadata-state.js";
|
||||
import {
|
||||
resolveInstalledPluginIndexStorePath,
|
||||
type InstalledPluginIndexStoreOptions,
|
||||
@@ -172,7 +172,7 @@ export async function writePersistedInstalledPluginIndex(
|
||||
mode: 0o600,
|
||||
},
|
||||
);
|
||||
clearCurrentPluginMetadataSnapshot();
|
||||
clearCurrentPluginMetadataSnapshotState();
|
||||
return filePath;
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ export function writePersistedInstalledPluginIndexSync(
|
||||
): string {
|
||||
const filePath = resolveInstalledPluginIndexStorePath(options);
|
||||
saveJsonFile(filePath, { ...index, warning: INSTALLED_PLUGIN_INDEX_WARNING });
|
||||
clearCurrentPluginMetadataSnapshot();
|
||||
clearCurrentPluginMetadataSnapshotState();
|
||||
return filePath;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user