refactor(assistant): the empty call and the unknown origin a helper falls back to are named once

This commit is contained in:
Maurice
2026-10-23 04:21:01 +00:00
parent 6d841f98e0
commit 49dd591f8f
2 changed files with 8 additions and 2 deletions
@@ -72,6 +72,9 @@ const CHECKS: Readonly<Partial<Record<string, Check>>> = {
),
};
/** The call a check reads when its caller has none: no arguments, no held card. */
const NO_CALL: UndoCall = { args: {}, preview: null };
/**
* True when the change `toolName` made (its stored `result`) is still as it
* left it. `call` is what the answer may not name (the day a vacation toggle
@@ -81,7 +84,7 @@ export function unchangedSinceApplied(
toolName: string,
result: unknown,
snapshot: TripSnapshot,
call: UndoCall = { args: {}, preview: null },
call: UndoCall = NO_CALL,
): boolean {
const check = CHECKS[toolName];
return !!check && check(recordOf(result), { ...snapshot, reads: snapshot.reads ?? new Map() }, call);
@@ -379,6 +379,9 @@ function bookedDay(result: unknown): number | null {
return reservation && typeof reservation === 'object' ? id(reservation as Args, 'day_id') : null;
}
/** Where a change came from when its caller does not say: no held card, no trip. */
const NOT_FROM: AppliedFrom = { preview: null, tripId: null };
/**
* The receipt of an applied change: what it touched (the created row from its
* answer, the changed one from its arguments), the day "Show on map" goes to
@@ -393,7 +396,7 @@ export function appliedChange(
result: unknown,
dayId: number | null,
undoUntil: string | null,
from: AppliedFrom = { preview: null, tripId: null },
from: AppliedFrom = NOT_FROM,
): AssistantApplied | null {
// A tool without a card of its own touched something the client has no view for.
const runs = writeToolOf(toolName, args);