refactor(ui): use asEntityId helper at piece-id boundaries

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
Joey Yakimowich-Payne 2026-04-19 13:53:45 -06:00
commit 9960ea96cf
No known key found for this signature in database
6 changed files with 79 additions and 7 deletions

View file

@ -6,7 +6,7 @@ export type {
SchemaKind,
DefineSchemaOptions,
} from "./schema.js";
export { defineSchema, fact } from "./schema.js";
export { asEntityId, defineSchema, fact } from "./schema.js";
export type { AttrKey, FactValue } from "./wm.js";
export { WorkingMemory } from "./wm.js";

View file

@ -24,6 +24,16 @@
*/
export type EntityId = number & { readonly __brand: "EntityId" };
/**
* Coerce a raw number to the branded EntityId type. Use ONLY at trust
* boundaries where you've already established that `n` came from
* `Session.nextId()` or a fact's `id` field (e.g. UI code that carries
* a piece's id as `number` because React prop serialization doesn't
* preserve branding). Prefer passing `EntityId` through end-to-end when
* possible; this helper is the single legitimate cast site.
*/
export const asEntityId = (n: number): EntityId => n as EntityId;
/**
* Shape of a schema type parameter.
*