From e7eef9fa28174266b780e150933f1ff776c92467 Mon Sep 17 00:00:00 2001 From: anadoris007 Date: Wed, 22 Apr 2026 14:57:06 +0530 Subject: [PATCH] feat(narrative): add frontend API client for world + god mode --- frontend/src/api/narrative.js | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/frontend/src/api/narrative.js b/frontend/src/api/narrative.js index 70d37fb2..62b71568 100644 --- a/frontend/src/api/narrative.js +++ b/frontend/src/api/narrative.js @@ -40,3 +40,54 @@ export const getCharacters = (simId) => { export const initCharacters = (simId) => { return requestWithRetry(() => service.post(`/api/narrative/characters/${simId}/init`), 3, 1000) } + +// ---- World State ---- + +/** + * Get the full world state (rules, locations, event log). + */ +export const getWorld = (simId) => + service.get(`/api/narrative/world/${simId}`) + +/** + * Replace world rules with the given array of strings. + */ +export const setWorldRules = (simId, rules) => + service.post(`/api/narrative/world/${simId}/rules`, { rules }) + +/** + * Insert or update a location. + * @param {Object} location - { id, name, description } + */ +export const upsertLocation = (simId, location) => + service.post(`/api/narrative/world/${simId}/locations`, location) + +// ---- God Mode ---- + +/** + * Inject a world event. The next translate_round will surface it to the LLM. + * @param {string} description + * @param {number|null} round - optional; defaults to (last beat round + 1) + */ +export const injectEvent = (simId, description, round = null) => + requestWithRetry( + () => service.post(`/api/narrative/godmode/${simId}/inject-event`, { description, round }), + 3, 2000 + ) + +/** + * Overwrite specified emotion values for a character. + * @param {string} characterId + * @param {Object} emotions - { anger: 0.8, joy: 0.1, ... } + */ +export const modifyEmotion = (simId, characterId, emotions) => + service.post(`/api/narrative/godmode/${simId}/modify-emotion`, { + character_id: characterId, + emotions, + }) + +/** + * Mark a character as dead. Auto-appends a death event to the world log. + */ +export const killCharacter = (simId, characterId) => + service.post(`/api/narrative/godmode/${simId}/kill`, { character_id: characterId })