Skip to main content

entity_register

Function entity_register 

Source
pub fn entity_register(
    conn: &Connection,
    canonical_name: &str,
    namespace: &str,
    aliases: &[String],
    extra_metadata: &Value,
    agent_id: Option<&str>,
) -> Result<EntityRegistration>
Expand description

Register an entity (canonical name + aliases) under a namespace (Pillar 2 / Stream B).

An entity is stored as a long-tier memory:

  • title = canonical_name
  • namespace = namespace
  • tags includes [ENTITY_TAG]
  • metadata.kind = "entity" (so the resolver can never confuse an entity with a regular memory that happens to share a title)

Aliases live in the entity_aliases side table keyed by (entity_id, alias).

Idempotency: if an entity with this (canonical_name, namespace) already exists, its ID is reused and aliases are merged with INSERT OR IGNORE. The returned [EntityRegistration::created] is false in that case.

Collision detection: if a non-entity memory already occupies (title=canonical_name, namespace=namespace), the call errors rather than silently upgrading it (the upsert path on insert would otherwise overwrite the existing row’s content/tags). Callers must rename the entity or its colliding memory.

extra_metadata is merged into the entity memory’s metadata; any caller-supplied kind field is overwritten with "entity" and agent_id is stamped from the caller (NHI provenance) when extra_metadata does not already specify one.