fix: make QMD cache key deterministic
This commit is contained in:
committed by
Vignesh
parent
e332a717a8
commit
d0b98c75e5
@@ -191,5 +191,22 @@ class FallbackMemoryManager implements MemorySearchManager {
|
||||
}
|
||||
|
||||
function buildQmdCacheKey(agentId: string, config: ResolvedQmdConfig): string {
|
||||
return `${agentId}:${JSON.stringify(config)}`;
|
||||
return `${agentId}:${stableSerialize(config)}`;
|
||||
}
|
||||
|
||||
function stableSerialize(value: unknown): string {
|
||||
return JSON.stringify(sortValue(value));
|
||||
}
|
||||
|
||||
function sortValue(value: unknown): unknown {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((entry) => sortValue(entry));
|
||||
}
|
||||
if (value && typeof value === "object") {
|
||||
const sortedEntries = Object.keys(value as Record<string, unknown>)
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
.map((key) => [key, sortValue((value as Record<string, unknown>)[key])]);
|
||||
return Object.fromEntries(sortedEntries);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user