refactor(agents): dedupe lifecycle send assertions and stable payload stringify

This commit is contained in:
Peter Steinberger
2026-02-18 14:15:14 +00:00
parent 168d24526e
commit 1934eebbf0
4 changed files with 56 additions and 44 deletions

View File

@@ -0,0 +1,12 @@
export function stableStringify(value: unknown): string {
if (value === null || typeof value !== "object") {
return JSON.stringify(value) ?? "null";
}
if (Array.isArray(value)) {
return `[${value.map((entry) => stableStringify(entry)).join(",")}]`;
}
const record = value as Record<string, unknown>;
const keys = Object.keys(record).toSorted();
const entries = keys.map((key) => `${JSON.stringify(key)}:${stableStringify(record[key])}`);
return `{${entries.join(",")}}`;
}