Narrative Protocol

Events

Create and manage events

Events API

Event routes are world-scoped.

Endpoints

List Events

GET /api/worlds/:worldAddress/events?page=1&limit=20

Create Event

POST /api/worlds/:worldAddress/events
Request Body
{
  "name": "race_result",
  "description": "Resolves a race and updates horse stats",
  "firstVersion": {
    "inputSchema": { "raceId": "string" },
    "outputSchema": { "winner": "string", "time": "string" },
    "readEntities": [{ "schema": "horse" }],
    "stateChanges": { "horse": "partial" },
    "behaviorPrompt": "Determine the race winner based on horse speed ratings.",
    "mutationSettings": { "mode": "ai" },
    "executionSettings": { "visibility": "admin" }
  }
}
FieldTypeRequiredDescription
namestringYesEvent name, unique within world.
descriptionstringNoEvent description.
firstVersionobjectYesInitial event-version definition.
firstVersion.inputSchemaobjectNoExecution input contract.
firstVersion.outputSchemaobjectNoPublic result contract.
firstVersion.readEntitiesobject[]NoRead access config.
firstVersion.readEntities[].schemastringYesEntity schema name to read.
firstVersion.readEntities[].filterstring[]NoFilter expressions (see below).
firstVersion.stateChangesobjectNoPer-schema mode map.
firstVersion.behaviorPromptstringNoPrompt for AI mode.
firstVersion.mutationSettings.modeenumNoai or direct.
firstVersion.mutationSettings.templateobjectConditionallyRequired when mode is direct.
firstVersion.executionSettings.visibilityenumNoadmin, public, or cron.
firstVersion.executionSettings.priceUsdnumberNoPrice for public execution.
firstVersion.executionSettings.cron.schedulestringConditionallyRequired for cron visibility; must be valid cron.
firstVersion.executionSettings.cron.inputobjectNoCron input template.

Get Event

GET /api/worlds/:worldAddress/events/:eventName

Update Event

PUT /api/worlds/:worldAddress/events/:eventName
Request Body
{
  "name": "race_result",
  "description": "Updated event description"
}
FieldTypeRequiredDescription
namestringNoEvent name.
descriptionstringNoEvent description.

Delete Event

DELETE /api/worlds/:worldAddress/events/:eventName

List Event Versions

GET /api/worlds/:worldAddress/events/:eventName/event-versions?page=1&limit=20

Create Event Version

POST /api/worlds/:worldAddress/events/:eventName/event-versions
Request Body
{
  "inputSchema": { "raceId": "string", "weather": "string" },
  "outputSchema": { "winner": "string", "time": "string", "weather": "string" },
  "readEntities": [{ "schema": "horse", "filter": ["eq:instanceId:HORSE_1"] }],
  "stateChanges": { "horse": "partial" },
  "behaviorPrompt": "Consider weather conditions.",
  "mutationSettings": {
    "mode": "direct",
    "template": { "result": { "winner": "{{input.winner}}" } }
  },
  "executionSettings": {
    "visibility": "cron",
    "cron": { "schedule": "*/5 * * * *", "input": { "tick": "{{counter}}" } }
  }
}
FieldTypeRequiredDescription
inputSchemaobjectNoExecution input contract.
outputSchemaobjectNoPublic result contract.
readEntitiesobject[]NoRead access config.
readEntities[].schemastringYesEntity schema name to read.
readEntities[].filterstring[]NoFilter expressions.
stateChangesobjectNoPer-schema mode map (partial, full, append).
behaviorPromptstringNoPrompt for AI mode.
mutationSettings.modeenumNoai or direct.
mutationSettings.templateobjectConditionallyRequired when mode is direct.
executionSettings.visibilityenumNoadmin, public, or cron.
executionSettings.priceUsdnumberNoPrice for public execution.
executionSettings.cron.schedulestringConditionallyRequired for cron visibility; must be valid cron.
executionSettings.cron.inputobjectNoCron input template.

readEntities Filter

The filter field in readEntities specifies which entity instance IDs to load from the event input.

Filter Syntax

filter is an array of input paths that tells the system which specific entity instance IDs to load from the event input (e.g., ["raceId"] looks up eventInput.raceId to find the target instance).

Examples

1. Simple input key

Event input: { "raceId": "RACE_001" }

[{ "schema": "horse", "filter": ["raceId"] }]

Loads instances where instanceId === "RACE_001"


2. Nested input key

Event input: { "data": { "raceId": "RACE_001" } }

[{ "schema": "horse", "filter": ["data.raceId"] }]

Uses dot notation to access nested values


3. Multiple filters (OR logic)

Event input: { "horse1": "HORSE_1", "horse2": "HORSE_2" }

[{ "schema": "horse", "filter": ["horse1", "horse2"] }]

Loads both HORSE_1 and HORSE_2 instances


4. Schema-prefixed instance IDs

If instance IDs are prefixed with schema name (e.g., "horse:HORSE_1"):

Event input: { "winnerId": "horse:HORSE_1" }

[{ "schema": "horse", "filter": ["winnerId"] }]

Matches instanceId === "horse:HORSE_1" exactly


5. Multiple schemas with different filters

Event input: { "raceId": "RACE_001", "betId": "BET_001" }

[
  { "schema": "race", "filter": ["raceId"] },
  { "schema": "bet", "filter": ["betId"] }
]

6. No filter (load all instances)

[{ "schema": "horse" }]

Loads all instances of schema (useful for listing queries)

Lock Event Version

POST /api/worlds/:worldAddress/events/:eventName/event-versions/:version/lock

Get Event Version

GET /api/worlds/:worldAddress/events/:eventName/event-versions/:version

Update Event Version

PUT /api/worlds/:worldAddress/events/:eventName/event-versions/:version
Request Body
{
  "inputSchema": { "raceId": "string", "weather": "string" },
  "outputSchema": { "winner": "string", "time": "string" },
  "readEntities": [{ "schema": "horse", "filter": ["raceId"] }],
  "stateChangeSchema": { "horse": "partial" },
  "behaviorPrompt": "Updated behavior prompt.",
  "mutationSettings": {
    "mode": "ai",
    "behaviorPrompt": "New prompt"
  },
  "executionSettings": {
    "visibility": "admin"
  }
}
FieldTypeRequiredDescription
inputSchemaobjectNoExecution input contract.
outputSchemaobjectNoPublic result contract.
readEntitiesobject[]NoRead access config.
readEntities[].schemastringYesEntity schema name to read.
readEntities[].filterstring[]NoFilter expressions.
stateChangeSchemaobjectNoPer-schema mode map (partial, full, append).
behaviorPromptstringNoPrompt for AI mode.
mutationSettingsobjectNoMutation configuration. Set to null to remove.
mutationSettings.modeenumNoai or direct.
mutationSettings.templateobjectConditionallyRequired when mode is direct.
mutationSettings.behaviorPromptstringNoPrompt for AI mode.
executionSettingsobjectNoExecution settings. Set to null to remove.
executionSettings.visibilityenumNoadmin, public, or cron.
executionSettings.priceUsdnumberNoPrice for public execution.
executionSettings.cron.schedulestringConditionallyRequired for cron visibility.
executionSettings.cron.inputobjectNoCron input template.

Delete Event Version

DELETE /api/worlds/:worldAddress/events/:eventName/event-versions/:version