Files
openclaw/src/agents/models-config-state.ts
2026-04-07 15:28:46 +01:00

31 lines
898 B
TypeScript

const MODELS_JSON_STATE_KEY = Symbol.for("openclaw.modelsJsonState");
type ModelsJsonState = {
writeLocks: Map<string, Promise<void>>;
readyCache: Map<
string,
Promise<{ fingerprint: string; result: { agentDir: string; wrote: boolean } }>
>;
};
export const MODELS_JSON_STATE = (() => {
const globalState = globalThis as typeof globalThis & {
[MODELS_JSON_STATE_KEY]?: ModelsJsonState;
};
if (!globalState[MODELS_JSON_STATE_KEY]) {
globalState[MODELS_JSON_STATE_KEY] = {
writeLocks: new Map<string, Promise<void>>(),
readyCache: new Map<
string,
Promise<{ fingerprint: string; result: { agentDir: string; wrote: boolean } }>
>(),
};
}
return globalState[MODELS_JSON_STATE_KEY];
})();
export function resetModelsJsonReadyCacheForTest(): void {
MODELS_JSON_STATE.writeLocks.clear();
MODELS_JSON_STATE.readyCache.clear();
}