Implementation:AIScientists Dev WorldSeed frontend types
| Knowledge Sources | |
|---|---|
| Domains | Frontend, Types |
| Last Updated | 2026-10-26 18:00 GMT |
Overview
Concrete shared TypeScript interfaces and the `enrichEntities` data transformation API matching server API responses, provided by the WorldSeed frontend.
Description
The types module defines the core interfaces used across stores and lib modules: `Entity` (with `properties` map), `WorldEvent`, `Character`, `DmEffect`, `StreamRecord` (SSE records with all optional fields), and `AgentPerception`. The `enrichEntities(raw)` function transforms raw API entity objects by moving all non-`id`/non-`type` fields into a `properties` map, producing the `Entity` shape used throughout the frontend. This is the canonical entity shape consumed by stores, layout, and rendering components.
Usage
Import types and `enrichEntities` from any module that handles API entity data — stores call `enrichEntities` on every state fetch, and components consume the typed interfaces.
Code Reference
Source Location
- Repository: WorldSeed
- File: frontend/src/lib/types.ts
Signature
export interface Entity {
id: string;
type: string;
properties: Record<string, unknown>;
relationships?: { type: string; target: string; value?: unknown }[];
[key: string]: unknown;
}
export function enrichEntities(raw: any[]): Entity[];
export interface StreamRecord { kind: string; tick?: number; agent_id?: string; /* ... */ }
export interface AgentPerception { self_state: Record<string, unknown> | null; /* ... */ }
Import
import { enrichEntities, type Entity, type StreamRecord } from '@/lib/types';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| raw | any[] | Yes │ Raw entity objects from API (fields spread at top level) |
Outputs
| Name | Type | Description |
|---|---|---|
| enrichEntities returns | Entity[] │ Entities with `properties` map containing all non-id/type fields |
Usage Examples
import { enrichEntities, type Entity } from '@/lib/types';
// Enrich raw API entities
const raw = [
{ id: 'old_chen', type: 'agent', location: 'town', gold: 100 },
{ id: 'sword', type: 'item', owner: 'old_chen' },
];
const entities: Entity[] = enrichEntities(raw);
// entities[0].properties = { location: 'town', gold: 100 }
// entities[0].id = 'old_chen'