Spaces:
Running
Running
Nicolas Rabault Claude Sonnet 4.6 commited on
Commit Β·
ba2cfd8
1
Parent(s): c0910ea
feat(engine): define core types for story data and game state
Browse filesCo-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
packages/story-engine/src/types.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// βββ Loaded data (immutable after load) ββββββββββββββββββββββββββββββββββ
|
| 2 |
+
|
| 3 |
+
export interface Narrator {
|
| 4 |
+
id: "narrator"; // sentinel id for the global narrator
|
| 5 |
+
name: string;
|
| 6 |
+
description: string;
|
| 7 |
+
introduction: string;
|
| 8 |
+
background: string;
|
| 9 |
+
goal: string;
|
| 10 |
+
voice: string; // OpenAI Realtime voice preset name
|
| 11 |
+
voiceTone: string;
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
export interface Character {
|
| 15 |
+
id: string; // derived from filename stem (e.g. "sparrow")
|
| 16 |
+
name: string;
|
| 17 |
+
description: string;
|
| 18 |
+
introduction: string;
|
| 19 |
+
background: string;
|
| 20 |
+
goal: string;
|
| 21 |
+
voice: string; // OpenAI Realtime voice preset name
|
| 22 |
+
voiceTone: string;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
export interface SceneAction {
|
| 26 |
+
id: string;
|
| 27 |
+
description: string;
|
| 28 |
+
effects: string; // narrative description, no flag effects
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
export interface Scene {
|
| 32 |
+
id: string; // derived from filename stem
|
| 33 |
+
name: string;
|
| 34 |
+
description: string;
|
| 35 |
+
actions: SceneAction[]; // atmospheric actions
|
| 36 |
+
charactersPresent: string[]; // character ids
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
export interface StorylineActionEffects {
|
| 40 |
+
setFlags?: Record<string, boolean>;
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
export interface StorylineAction {
|
| 44 |
+
id: string;
|
| 45 |
+
description: string;
|
| 46 |
+
next?: string; // next storyline node id
|
| 47 |
+
effects?: StorylineActionEffects;
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
export type StorylineType = "dialogue" | "narration" | "character_interaction";
|
| 51 |
+
|
| 52 |
+
export interface StorylineNode {
|
| 53 |
+
id: string;
|
| 54 |
+
scene: string; // scene id
|
| 55 |
+
type: StorylineType;
|
| 56 |
+
speaker: string; // character id, "narrator", or empty string
|
| 57 |
+
text: string;
|
| 58 |
+
actions: StorylineAction[];
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
export interface FlagCondition {
|
| 62 |
+
type: "requires_flag";
|
| 63 |
+
flag: string;
|
| 64 |
+
conditionFailed: string; // explanation if blocked
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
export interface MapEdge {
|
| 68 |
+
from: string; // scene id
|
| 69 |
+
to: string; // scene id
|
| 70 |
+
description: string;
|
| 71 |
+
conditions?: FlagCondition[];
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
export interface Story {
|
| 75 |
+
id: string;
|
| 76 |
+
title: string;
|
| 77 |
+
description: string;
|
| 78 |
+
languages: string[];
|
| 79 |
+
entryPoint: string; // path relative to story root, e.g. "storylines/chapter1/meet_sparrow.json"
|
| 80 |
+
narrator: Character | Narrator; // story-specific or global
|
| 81 |
+
characters: Record<string, Character>;
|
| 82 |
+
scenes: Record<string, Scene>;
|
| 83 |
+
storylines: Record<string, StorylineNode>;
|
| 84 |
+
map: MapEdge[];
|
| 85 |
+
flags: string[]; // declared flag names (flat array)
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
export interface LoadedContent {
|
| 89 |
+
narrator: Narrator; // global menu narrator
|
| 90 |
+
stories: Record<string, Story>;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// βββ Mutable state ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 94 |
+
|
| 95 |
+
export type AppMode = "menu" | "story";
|
| 96 |
+
|
| 97 |
+
export interface GameState {
|
| 98 |
+
mode: AppMode;
|
| 99 |
+
storyId?: string;
|
| 100 |
+
currentSceneId?: string;
|
| 101 |
+
currentNodeId?: string;
|
| 102 |
+
currentSpeaker?: string; // character id, or "narrator"
|
| 103 |
+
flags: Record<string, boolean>;
|
| 104 |
+
discoveredScenes: string[];
|
| 105 |
+
metCharacters: string[];
|
| 106 |
+
recentTransitions: TransitionEvent[]; // bounded log for summary builder
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
// βββ Transition events ββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 110 |
+
|
| 111 |
+
export type TransitionEvent =
|
| 112 |
+
| { type: "speakerChanged"; from?: string; to: string;
|
| 113 |
+
newCharacter: Character | Narrator }
|
| 114 |
+
| { type: "sceneChanged"; from?: string; to: string }
|
| 115 |
+
| { type: "storyEntered"; storyId: string }
|
| 116 |
+
| { type: "storyExited" }
|
| 117 |
+
| { type: "flagSet"; name: string; value: boolean }
|
| 118 |
+
| { type: "blocked"; reason: string };
|
| 119 |
+
|
| 120 |
+
export interface TransitionResult {
|
| 121 |
+
state: Readonly<GameState>;
|
| 122 |
+
events: TransitionEvent[];
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
// βββ Tool definitions for OpenAI Realtime βββββββββββββββββββββββββββββββββ
|
| 126 |
+
|
| 127 |
+
export interface ToolDef {
|
| 128 |
+
name: string;
|
| 129 |
+
description: string;
|
| 130 |
+
parameters: {
|
| 131 |
+
type: "object";
|
| 132 |
+
properties: Record<string, unknown>;
|
| 133 |
+
required: string[];
|
| 134 |
+
};
|
| 135 |
+
}
|