Prune retired Face state entries
This commit is contained in:
parent
6850554c13
commit
058477a82a
3 changed files with 19 additions and 0 deletions
|
|
@ -206,6 +206,8 @@ function normalizeTypedStateForWrite(
|
|||
state: VoidSelfStateTypedProjection,
|
||||
observedAt = new Date().toISOString(),
|
||||
): void {
|
||||
pruneRetiredTypedState(state);
|
||||
|
||||
let thoughtMemoryChanged = false;
|
||||
for (const memory of state.thoughtMemory.shortTerm) {
|
||||
thoughtMemoryChanged = clampFutureTimestampFields(memory, observedAt, [
|
||||
|
|
@ -242,6 +244,21 @@ function normalizeTypedStateForWrite(
|
|||
}
|
||||
}
|
||||
|
||||
function pruneRetiredTypedState(state: VoidSelfStateTypedProjection): void {
|
||||
state.thoughtMemory.shortTerm = state.thoughtMemory.shortTerm.filter(isNotRetiredEntry);
|
||||
state.thoughtMemory.memories = state.thoughtMemory.memories.filter(isNotRetiredEntry);
|
||||
state.thoughtMemory.incubation = state.thoughtMemory.incubation.filter(isNotRetiredEntry);
|
||||
state.agencyPressure.pressures = state.agencyPressure.pressures.filter(isNotRetiredEntry);
|
||||
state.candidateInterventions.interventions = state.candidateInterventions.interventions.filter(isNotRetiredEntry);
|
||||
state.faceAffect.needs = state.faceAffect.needs.filter(isNotRetiredEntry);
|
||||
state.faceAffect.socialBonds = state.faceAffect.socialBonds.filter(isNotRetiredEntry);
|
||||
state.faceAffect.statusReads = state.faceAffect.statusReads.filter(isNotRetiredEntry);
|
||||
}
|
||||
|
||||
function isNotRetiredEntry(entry: { status?: string; retiredAt?: string }): boolean {
|
||||
return entry.status !== "retired" && !entry.retiredAt;
|
||||
}
|
||||
|
||||
function clampFutureTimestampFields<T extends Record<string, unknown>>(
|
||||
value: T,
|
||||
observedAt: string,
|
||||
|
|
|
|||
Loading…
Reference in a new issue