molroo docs
SDK ReferenceTypes

World Types

Entity, Space, Environment, WorldContext, WorldEvent, and world structure types.

World Types

Types representing world structure -- entities, spaces, environment, events, relationships, and spatial connections.

import type {
  Entity,
  EntityType,
  Space,
  SpaceType,
  Environment,
  WorldContext,
  WorldEvent,
  Relationship,
  WorldRelationship,
  SpaceConnection,
  Fact,
  ProgressionTrigger,
} from '@molroo-ai/sdk';

EntityType

type EntityType = 'persona' | 'user' | 'secondary';
TypeDescription
'persona'AI character with full emotion engine (personality, goals, memory, soul stages)
'user'Human player/user. Every world should have at least one user entity
'secondary'Background character without a full persona agent

SpaceType

type SpaceType = 'physical' | 'virtual' | 'abstract';
TypeDescription
'physical'A real-world location (room, building, outdoor area)
'virtual'A digital space (chatroom, virtual world)
'abstract'A conceptual space (dream, memory, thought)

Entity

An entity in the world.

interface Entity {
  id: string;
  name: string;
  type: EntityType;
  spaceId: string;
  profile?: UserProfile;
}
FieldTypeDescription
idstringUnique entity ID (auto-generated)
namestringEntity name (unique within the world)
typeEntityTypeEntity type
spaceIdstringID of the space this entity is currently in
profileUserProfileOptional profile data

Space

A spatial container within the world.

interface Space {
  id: string;
  name: string;
  type: SpaceType;
  capacity: number;
}
FieldTypeDescription
idstringUnique space ID
namestringSpace name
typeSpaceTypeSpace type
capacitynumberMaximum number of entities

Environment

Current world environment state.

interface Environment {
  weather: string;
  location: string;
  ambiance: string;
}
FieldTypeDescription
weatherstringCurrent weather (e.g., 'sunny', 'rainy')
locationstringLocation description
ambiancestringAmbient mood/atmosphere

WorldContext

World context from the perspective of a specific entity. Returned by world.getContext(). Used internally by the SDK to build LLM system prompts.

interface WorldContext {
  whoAmI: string;
  whereAmI: string;
  whoIsHere: string[];
  whatHappened: WorldEvent[];
  adjacentSpaces?: string[];
  worldIdentity?: {
    name: string;
    [key: string]: unknown;
  };
  worldCulture?: {
    coreValues: string[];
    socialProtocol?: {
      greetingStyle?: string;
      addressSystem?: string;
      tabooTopics?: string[];
    };
  };
  knownFacts?: Array<{ id: string; content: string; visibility: string }>;
  currentPhase?: string;
}
FieldTypeDescription
whoAmIstringThe entity's name
whereAmIstringThe entity's current space name
whoIsHerestring[]Names of other entities in the same space
whatHappenedWorldEvent[]Recent events visible to this entity
adjacentSpacesstring[]?Names of connected spaces
worldIdentityobject?World identity data (name, genre, tone, era, lore)
worldCultureobject?World culture data (core values, social protocol)
knownFactsArray<{ id, content, visibility }>?Facts known to this entity
currentPhasestring?Current progression phase

Example:

const ctx = await world.getContext('Sera');
// {
//   whoAmI: 'Sera',
//   whereAmI: 'Main Cafe',
//   whoIsHere: ['user', 'Mika'],
//   whatHappened: [
//     { type: 'chat', sourceEntity: 'user', payload: { message: 'Hello!' }, ... },
//   ],
//   adjacentSpaces: ['Kitchen', 'Patio'],
//   worldIdentity: { name: 'Cafe World', genre: 'slice-of-life', tone: 'warm' },
//   currentPhase: 'morning_rush',
// }

WorldEvent

An event that occurred in the world. Returned in WorldContext.whatHappened and WorldSnapshot.recentEvents.

interface WorldEvent {
  type: string;
  spaceId: string;
  timestamp: number;
  sourceEntity?: string;
  targetEntity?: string;
  payload: Record<string, unknown>;
  appraisal?: AppraisalVector;
}
FieldTypeDescription
typestringEvent type (e.g., 'chat', 'chat_observed', 'earthquake')
spaceIdstringSpace where the event occurred
timestampnumberEpoch milliseconds
sourceEntitystring?Entity that initiated the event
targetEntitystring?Entity targeted by the event
payloadRecord<string, unknown>Event-specific data
appraisalAppraisalVectorOptional appraisal attached to the event

Relationship

Persona-level relationship data. Found in PersonaSnapshot.relationships.

interface Relationship {
  entityId: string;
  trust: number;
  intimacy: number;
  interactionCount: number;
  attachmentStyle?: string;
  lastInteraction?: number;
}
FieldTypeDescription
entityIdstringID of the related entity
trustnumberTrust level (0 to 1)
intimacynumberIntimacy level (0 to 1)
interactionCountnumberTotal number of interactions
attachmentStylestring?Attachment style label
lastInteractionnumber?Timestamp of last interaction

WorldRelationship

World-level relationship data. Found in WorldSnapshot entity relationship arrays.

interface WorldRelationship {
  type: string;
  strength: number;
  trust: number;
}
FieldTypeDescription
typestringRelationship type label (e.g., 'friend', 'rival', 'mentor')
strengthnumberRelationship strength
trustnumberTrust level

SpaceConnection

A spatial connection between two spaces. Used in WorldDefinitionInput.topology.

interface SpaceConnection {
  from: string;
  to: string;
  distance?: number;
  traversalTime?: number;
  accessibility?: string;
  bidirectional?: boolean;
}
FieldTypeDefaultDescription
fromstring--Source space name or ID
tostring--Destination space name or ID
distancenumber?--Distance between spaces
traversalTimenumber?--Time (seconds) to travel between spaces
accessibilitystring?--Access restriction (e.g., 'open', 'locked', 'hidden')
bidirectionalboolean?trueWhether the connection works both ways

Example:

const topology = {
  connections: [
    { from: 'cafe', to: 'kitchen', bidirectional: true },
    { from: 'cafe', to: 'patio', distance: 10, traversalTime: 5 },
    { from: 'kitchen', to: 'storeroom', accessibility: 'staff_only' },
  ],
};

Fact

A piece of knowledge in the world. Facts have visibility levels and can be revealed to or hidden from specific entities.

interface Fact {
  id: string;
  content: string;
  visibility: 'public' | 'secret' | 'rumor';
  knownBy: string[];
}
FieldTypeDescription
idstringUnique fact ID
contentstringThe fact content text
visibility'public' | 'secret' | 'rumor'Visibility level
knownBystring[]Entity names that know this fact

Example:

const facts: Fact[] = [
  { id: 'f1', content: 'The cafe was founded in 1985', visibility: 'public', knownBy: [] },
  { id: 'f2', content: 'Sera is planning a surprise party', visibility: 'secret', knownBy: ['Sera', 'Mika'] },
  { id: 'f3', content: 'Someone saw a ghost in the storeroom', visibility: 'rumor', knownBy: ['Mika'] },
];

ProgressionTrigger

A condition that triggers a phase transition in the world's progression system.

interface ProgressionTrigger {
  id: string;
  condition:
    | { type: 'event_count'; eventType: string; threshold: number }
    | { type: 'time_elapsed'; seconds: number }
    | { type: 'relationship'; entityA: string; entityB: string; field?: 'strength' | 'trust'; above?: number; below?: number }
    | { type: 'persona_emotion'; entity: string; dimension: 'V' | 'A' | 'D'; above?: number; below?: number };
  targetPhase: string;
  oneShot?: boolean;
}
FieldTypeDescription
idstringUnique trigger ID
conditionobjectCondition that must be met (see condition types below)
targetPhasestringPhase to transition to when triggered
oneShotboolean?If true, trigger fires only once

Condition Types

event_count -- fires when a specific event type has occurred N times:

{ type: 'event_count', eventType: 'chat', threshold: 10 }

time_elapsed -- fires after N seconds have passed:

{ type: 'time_elapsed', seconds: 3600 }

relationship -- fires when a relationship field crosses a threshold:

{ type: 'relationship', entityA: 'Sera', entityB: 'user', field: 'trust', above: 0.8 }

persona_emotion -- fires when an entity's emotion dimension crosses a threshold:

{ type: 'persona_emotion', entity: 'Sera', dimension: 'V', below: -0.5 }

Example:

const triggers: ProgressionTrigger[] = [
  {
    id: 'to-chapter2',
    condition: { type: 'event_count', eventType: 'chat', threshold: 20 },
    targetPhase: 'chapter_2',
    oneShot: true,
  },
  {
    id: 'crisis',
    condition: { type: 'persona_emotion', entity: 'Sera', dimension: 'V', below: -0.7 },
    targetPhase: 'crisis',
  },
  {
    id: 'friendship-arc',
    condition: { type: 'relationship', entityA: 'Sera', entityB: 'user', field: 'trust', above: 0.9 },
    targetPhase: 'deep_friendship',
    oneShot: true,
  },
];

On this page