mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-02 23:50:26 +00:00
31 lines
898 B
TypeScript
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();
|
|
}
|