fix: make QMD cache key deterministic
parent
e332a717a8
commit
d0b98c75e5
|
|
@ -191,5 +191,22 @@ class FallbackMemoryManager implements MemorySearchManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildQmdCacheKey(agentId: string, config: ResolvedQmdConfig): string {
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue