ava-langgraph-narrative-intelligence 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +268 -0
- package/dist/graphs/index.cjs +1511 -0
- package/dist/graphs/index.cjs.map +1 -0
- package/dist/graphs/index.d.cts +2 -0
- package/dist/graphs/index.d.ts +2 -0
- package/dist/graphs/index.js +1468 -0
- package/dist/graphs/index.js.map +1 -0
- package/dist/index-Btxk3nQm.d.cts +430 -0
- package/dist/index-CgXXxuIH.d.ts +430 -0
- package/dist/index-CweT-D3c.d.cts +122 -0
- package/dist/index-D-zWH42e.d.cts +66 -0
- package/dist/index-D71kh3nE.d.cts +213 -0
- package/dist/index-DApls3w2.d.ts +66 -0
- package/dist/index-UamXITgg.d.ts +122 -0
- package/dist/index-v9AlRC0M.d.ts +213 -0
- package/dist/index.cjs +2753 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +2654 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/index.cjs +654 -0
- package/dist/integrations/index.cjs.map +1 -0
- package/dist/integrations/index.d.cts +2 -0
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/index.js +614 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/ncp-tXS9Jr9e.d.cts +132 -0
- package/dist/ncp-tXS9Jr9e.d.ts +132 -0
- package/dist/nodes/index.cjs +226 -0
- package/dist/nodes/index.cjs.map +1 -0
- package/dist/nodes/index.d.cts +2 -0
- package/dist/nodes/index.d.ts +2 -0
- package/dist/nodes/index.js +196 -0
- package/dist/nodes/index.js.map +1 -0
- package/dist/schemas/index.cjs +550 -0
- package/dist/schemas/index.cjs.map +1 -0
- package/dist/schemas/index.d.cts +2 -0
- package/dist/schemas/index.d.ts +2 -0
- package/dist/schemas/index.js +484 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/unified_state_bridge-CIDm1kuf.d.cts +266 -0
- package/dist/unified_state_bridge-CIDm1kuf.d.ts +266 -0
- package/package.json +91 -0
- package/src/graphs/coherence_engine.ts +1027 -0
- package/src/graphs/index.ts +47 -0
- package/src/graphs/three_universe_processor.ts +1136 -0
- package/src/index.ts +181 -0
- package/src/integrations/index.ts +17 -0
- package/src/integrations/redis_state.ts +691 -0
- package/src/nodes/emotional_classifier.ts +289 -0
- package/src/nodes/index.ts +17 -0
- package/src/schemas/index.ts +75 -0
- package/src/schemas/ncp.ts +312 -0
- package/src/schemas/unified_state_bridge.ts +681 -0
- package/src/tests/coherence_engine.test.ts +273 -0
- package/src/tests/three_universe_processor.test.ts +309 -0
- package/src/tests/unified_state_bridge.test.ts +360 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Narrative State Bridge
|
|
3
|
+
*
|
|
4
|
+
* The shared contract between all six systems in the Narrative Intelligence Stack:
|
|
5
|
+
* 1. LangGraph Narrative Intelligence Toolkit
|
|
6
|
+
* 2. ava-langflow Universal Router
|
|
7
|
+
* 3. ava-Flowise Agent Coordination
|
|
8
|
+
* 4. LangChain/Langfuse Tracing
|
|
9
|
+
* 5. Storytelling System
|
|
10
|
+
* 6. Miadi-46 Event-Driven Platform
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The three interpretive universes from multiverse_3act
|
|
14
|
+
*/
|
|
15
|
+
declare enum Universe {
|
|
16
|
+
ENGINEER = "engineer",// Mia - The Builder
|
|
17
|
+
CEREMONY = "ceremony",// Ava8 - The Keeper
|
|
18
|
+
STORY_ENGINE = "story_engine"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Single universe's interpretation of an event
|
|
22
|
+
*/
|
|
23
|
+
interface UniversePerspective {
|
|
24
|
+
universe: Universe;
|
|
25
|
+
intent: string;
|
|
26
|
+
confidence: number;
|
|
27
|
+
suggestedFlows: string[];
|
|
28
|
+
context: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a UniversePerspective
|
|
32
|
+
*/
|
|
33
|
+
declare function createUniversePerspective(universe: Universe, intent: string, confidence: number, options?: Partial<UniversePerspective>): UniversePerspective;
|
|
34
|
+
/**
|
|
35
|
+
* Complete three-universe analysis of an event
|
|
36
|
+
*/
|
|
37
|
+
interface ThreeUniverseAnalysis {
|
|
38
|
+
engineer: UniversePerspective;
|
|
39
|
+
ceremony: UniversePerspective;
|
|
40
|
+
storyEngine: UniversePerspective;
|
|
41
|
+
leadUniverse: Universe;
|
|
42
|
+
coherenceScore: number;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a ThreeUniverseAnalysis
|
|
47
|
+
*/
|
|
48
|
+
declare function createThreeUniverseAnalysis(engineer: UniversePerspective, ceremony: UniversePerspective, storyEngine: UniversePerspective, leadUniverse: Universe, coherenceScore: number): ThreeUniverseAnalysis;
|
|
49
|
+
/**
|
|
50
|
+
* Get perspective for a specific universe
|
|
51
|
+
*/
|
|
52
|
+
declare function getPerspective(analysis: ThreeUniverseAnalysis, universe: Universe): UniversePerspective;
|
|
53
|
+
/**
|
|
54
|
+
* Phases in the three-act structure
|
|
55
|
+
*/
|
|
56
|
+
declare enum NarrativePhase {
|
|
57
|
+
SETUP = "setup",// Act 1
|
|
58
|
+
CONFRONTATION = "confrontation",// Act 2
|
|
59
|
+
RESOLUTION = "resolution"
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Narrative functions for story beats
|
|
63
|
+
*/
|
|
64
|
+
declare enum NarrativeFunction {
|
|
65
|
+
INCITING_INCIDENT = "inciting_incident",
|
|
66
|
+
RISING_ACTION = "rising_action",
|
|
67
|
+
TURNING_POINT = "turning_point",
|
|
68
|
+
COMPLICATION = "complication",
|
|
69
|
+
CRISIS = "crisis",
|
|
70
|
+
CLIMAX = "climax",
|
|
71
|
+
RESOLUTION = "resolution",
|
|
72
|
+
DENOUEMENT = "denouement",
|
|
73
|
+
BEAT = "beat"
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Current position in the narrative journey
|
|
77
|
+
*/
|
|
78
|
+
interface NarrativePosition {
|
|
79
|
+
act: number;
|
|
80
|
+
phase: NarrativePhase;
|
|
81
|
+
currentBeatId?: string;
|
|
82
|
+
beatCount: number;
|
|
83
|
+
characterArcStrength: number;
|
|
84
|
+
thematicResonance: number;
|
|
85
|
+
emotionalTone: string;
|
|
86
|
+
leadUniverse: Universe;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a NarrativePosition with defaults
|
|
90
|
+
*/
|
|
91
|
+
declare function createNarrativePosition(options?: Partial<NarrativePosition>): NarrativePosition;
|
|
92
|
+
/**
|
|
93
|
+
* A single story beat with three-universe perspectives
|
|
94
|
+
*/
|
|
95
|
+
interface StoryBeat {
|
|
96
|
+
id: string;
|
|
97
|
+
sequence: number;
|
|
98
|
+
content: string;
|
|
99
|
+
narrativeFunction: NarrativeFunction;
|
|
100
|
+
act: number;
|
|
101
|
+
universeAnalysis?: ThreeUniverseAnalysis;
|
|
102
|
+
leadUniverse: Universe;
|
|
103
|
+
emotionalTone: string;
|
|
104
|
+
thematicTags: string[];
|
|
105
|
+
characterId?: string;
|
|
106
|
+
characterArcImpact: number;
|
|
107
|
+
source: string;
|
|
108
|
+
sourceEventId?: string;
|
|
109
|
+
timestamp: string;
|
|
110
|
+
enrichmentsApplied: string[];
|
|
111
|
+
qualityScore: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create a StoryBeat with defaults
|
|
115
|
+
*/
|
|
116
|
+
declare function createStoryBeat(id: string, sequence: number, content: string, narrativeFunction: NarrativeFunction, act: number, options?: Partial<StoryBeat>): StoryBeat;
|
|
117
|
+
/**
|
|
118
|
+
* Character state tracking for arc continuity
|
|
119
|
+
*/
|
|
120
|
+
interface CharacterState {
|
|
121
|
+
id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
archetype: string;
|
|
124
|
+
universe: Universe;
|
|
125
|
+
arcPosition: number;
|
|
126
|
+
initialState: string;
|
|
127
|
+
currentState: string;
|
|
128
|
+
growthPoints: Array<{
|
|
129
|
+
timestamp: string;
|
|
130
|
+
impact: number;
|
|
131
|
+
description: string;
|
|
132
|
+
}>;
|
|
133
|
+
relationships: string[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create a CharacterState with defaults
|
|
137
|
+
*/
|
|
138
|
+
declare function createCharacterState(id: string, name: string, archetype: string, universe: Universe, options?: Partial<CharacterState>): CharacterState;
|
|
139
|
+
/**
|
|
140
|
+
* A thematic thread being tracked across the narrative
|
|
141
|
+
*/
|
|
142
|
+
interface ThematicThread {
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
description: string;
|
|
146
|
+
strength: number;
|
|
147
|
+
tensionLevel: number;
|
|
148
|
+
resolutionProgress: number;
|
|
149
|
+
beatIds: string[];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a ThematicThread with defaults
|
|
153
|
+
*/
|
|
154
|
+
declare function createThematicThread(id: string, name: string, description: string, options?: Partial<ThematicThread>): ThematicThread;
|
|
155
|
+
/**
|
|
156
|
+
* Record of a routing decision for tracing
|
|
157
|
+
*/
|
|
158
|
+
interface RoutingDecision {
|
|
159
|
+
id: string;
|
|
160
|
+
backend: string;
|
|
161
|
+
flow: string;
|
|
162
|
+
universeAnalysis: ThreeUniverseAnalysis;
|
|
163
|
+
narrativePosition: NarrativePosition;
|
|
164
|
+
score: number;
|
|
165
|
+
method: string;
|
|
166
|
+
success: boolean;
|
|
167
|
+
resultSummary: string;
|
|
168
|
+
latencyMs: number;
|
|
169
|
+
timestamp: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a RoutingDecision
|
|
173
|
+
*/
|
|
174
|
+
declare function createRoutingDecision(id: string, backend: string, flow: string, universeAnalysis: ThreeUniverseAnalysis, narrativePosition: NarrativePosition, score: number, options?: Partial<RoutingDecision>): RoutingDecision;
|
|
175
|
+
/**
|
|
176
|
+
* The complete unified state shared across all systems.
|
|
177
|
+
* This is THE contract that all six systems use to communicate.
|
|
178
|
+
*/
|
|
179
|
+
interface UnifiedNarrativeState {
|
|
180
|
+
storyId: string;
|
|
181
|
+
sessionId: string;
|
|
182
|
+
position: NarrativePosition;
|
|
183
|
+
beats: StoryBeat[];
|
|
184
|
+
characters: Record<string, CharacterState>;
|
|
185
|
+
themes: Record<string, ThematicThread>;
|
|
186
|
+
routingDecisions: RoutingDecision[];
|
|
187
|
+
currentEpisodeId?: string;
|
|
188
|
+
episodeBeatsCount: number;
|
|
189
|
+
createdAt: string;
|
|
190
|
+
updatedAt: string;
|
|
191
|
+
overallCoherence: number;
|
|
192
|
+
emotionalArcStrength: number;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Create a new UnifiedNarrativeState
|
|
196
|
+
*/
|
|
197
|
+
declare function createUnifiedNarrativeState(storyId: string, sessionId: string, options?: {
|
|
198
|
+
includeDefaultCharacters?: boolean;
|
|
199
|
+
includeDefaultThemes?: boolean;
|
|
200
|
+
}): UnifiedNarrativeState;
|
|
201
|
+
/**
|
|
202
|
+
* Add a beat to the state
|
|
203
|
+
*/
|
|
204
|
+
declare function addBeat(state: UnifiedNarrativeState, beat: StoryBeat): void;
|
|
205
|
+
/**
|
|
206
|
+
* Add a routing decision to the state
|
|
207
|
+
*/
|
|
208
|
+
declare function addRoutingDecision(state: UnifiedNarrativeState, decision: RoutingDecision): void;
|
|
209
|
+
/**
|
|
210
|
+
* Update character arc position
|
|
211
|
+
*/
|
|
212
|
+
declare function updateCharacterArc(state: UnifiedNarrativeState, characterId: string, impact: number, description: string): void;
|
|
213
|
+
/**
|
|
214
|
+
* Update theme strength
|
|
215
|
+
*/
|
|
216
|
+
declare function updateThemeStrength(state: UnifiedNarrativeState, themeId: string, strengthDelta: number): void;
|
|
217
|
+
/**
|
|
218
|
+
* Get the last n beats for context
|
|
219
|
+
*/
|
|
220
|
+
declare function getLastNBeats(state: UnifiedNarrativeState, n?: number): StoryBeat[];
|
|
221
|
+
/**
|
|
222
|
+
* Calculate overall narrative coherence
|
|
223
|
+
*/
|
|
224
|
+
declare function calculateCoherence(state: UnifiedNarrativeState): number;
|
|
225
|
+
/**
|
|
226
|
+
* Check if we should create a new episode
|
|
227
|
+
*/
|
|
228
|
+
declare function shouldCreateNewEpisode(state: UnifiedNarrativeState): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Start a new episode
|
|
231
|
+
*/
|
|
232
|
+
declare function startNewEpisode(state: UnifiedNarrativeState, episodeId: string): void;
|
|
233
|
+
/**
|
|
234
|
+
* Get the three main archetypes from multiverse_3act
|
|
235
|
+
*/
|
|
236
|
+
declare function getDefaultCharacters(): Record<string, CharacterState>;
|
|
237
|
+
/**
|
|
238
|
+
* Get default thematic threads from multiverse_3act
|
|
239
|
+
*/
|
|
240
|
+
declare function getDefaultThemes(): Record<string, ThematicThread>;
|
|
241
|
+
/**
|
|
242
|
+
* Create a story beat from a webhook event
|
|
243
|
+
*/
|
|
244
|
+
declare function createBeatFromWebhook(eventId: string, content: string, universeAnalysis: ThreeUniverseAnalysis, sequence: number): StoryBeat;
|
|
245
|
+
/**
|
|
246
|
+
* Standard Redis key patterns for state storage
|
|
247
|
+
*/
|
|
248
|
+
declare const RedisKeys: {
|
|
249
|
+
state: (sessionId: string) => string;
|
|
250
|
+
currentState: () => string;
|
|
251
|
+
beats: (sessionId: string) => string;
|
|
252
|
+
beat: (beatId: string) => string;
|
|
253
|
+
eventAnalysis: (eventId: string) => string;
|
|
254
|
+
routingHistory: (sessionId: string) => string;
|
|
255
|
+
episode: (episodeId: string) => string;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Serialize state to JSON
|
|
259
|
+
*/
|
|
260
|
+
declare function serializeState(state: UnifiedNarrativeState): string;
|
|
261
|
+
/**
|
|
262
|
+
* Deserialize state from JSON
|
|
263
|
+
*/
|
|
264
|
+
declare function deserializeState(json: string): UnifiedNarrativeState;
|
|
265
|
+
|
|
266
|
+
export { updateCharacterArc as A, updateThemeStrength as B, type CharacterState as C, NarrativeFunction as N, RedisKeys as R, type StoryBeat as S, type ThematicThread as T, type UnifiedNarrativeState as U, NarrativePhase as a, type NarrativePosition as b, type RoutingDecision as c, type ThreeUniverseAnalysis as d, Universe as e, type UniversePerspective as f, addBeat as g, addRoutingDecision as h, calculateCoherence as i, createBeatFromWebhook as j, createCharacterState as k, createNarrativePosition as l, createRoutingDecision as m, createStoryBeat as n, createThematicThread as o, createThreeUniverseAnalysis as p, createUnifiedNarrativeState as q, createUniversePerspective as r, deserializeState as s, getDefaultCharacters as t, getDefaultThemes as u, getLastNBeats as v, getPerspective as w, serializeState as x, shouldCreateNewEpisode as y, startNewEpisode as z };
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified Narrative State Bridge
|
|
3
|
+
*
|
|
4
|
+
* The shared contract between all six systems in the Narrative Intelligence Stack:
|
|
5
|
+
* 1. LangGraph Narrative Intelligence Toolkit
|
|
6
|
+
* 2. ava-langflow Universal Router
|
|
7
|
+
* 3. ava-Flowise Agent Coordination
|
|
8
|
+
* 4. LangChain/Langfuse Tracing
|
|
9
|
+
* 5. Storytelling System
|
|
10
|
+
* 6. Miadi-46 Event-Driven Platform
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* The three interpretive universes from multiverse_3act
|
|
14
|
+
*/
|
|
15
|
+
declare enum Universe {
|
|
16
|
+
ENGINEER = "engineer",// Mia - The Builder
|
|
17
|
+
CEREMONY = "ceremony",// Ava8 - The Keeper
|
|
18
|
+
STORY_ENGINE = "story_engine"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Single universe's interpretation of an event
|
|
22
|
+
*/
|
|
23
|
+
interface UniversePerspective {
|
|
24
|
+
universe: Universe;
|
|
25
|
+
intent: string;
|
|
26
|
+
confidence: number;
|
|
27
|
+
suggestedFlows: string[];
|
|
28
|
+
context: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Create a UniversePerspective
|
|
32
|
+
*/
|
|
33
|
+
declare function createUniversePerspective(universe: Universe, intent: string, confidence: number, options?: Partial<UniversePerspective>): UniversePerspective;
|
|
34
|
+
/**
|
|
35
|
+
* Complete three-universe analysis of an event
|
|
36
|
+
*/
|
|
37
|
+
interface ThreeUniverseAnalysis {
|
|
38
|
+
engineer: UniversePerspective;
|
|
39
|
+
ceremony: UniversePerspective;
|
|
40
|
+
storyEngine: UniversePerspective;
|
|
41
|
+
leadUniverse: Universe;
|
|
42
|
+
coherenceScore: number;
|
|
43
|
+
timestamp: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a ThreeUniverseAnalysis
|
|
47
|
+
*/
|
|
48
|
+
declare function createThreeUniverseAnalysis(engineer: UniversePerspective, ceremony: UniversePerspective, storyEngine: UniversePerspective, leadUniverse: Universe, coherenceScore: number): ThreeUniverseAnalysis;
|
|
49
|
+
/**
|
|
50
|
+
* Get perspective for a specific universe
|
|
51
|
+
*/
|
|
52
|
+
declare function getPerspective(analysis: ThreeUniverseAnalysis, universe: Universe): UniversePerspective;
|
|
53
|
+
/**
|
|
54
|
+
* Phases in the three-act structure
|
|
55
|
+
*/
|
|
56
|
+
declare enum NarrativePhase {
|
|
57
|
+
SETUP = "setup",// Act 1
|
|
58
|
+
CONFRONTATION = "confrontation",// Act 2
|
|
59
|
+
RESOLUTION = "resolution"
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Narrative functions for story beats
|
|
63
|
+
*/
|
|
64
|
+
declare enum NarrativeFunction {
|
|
65
|
+
INCITING_INCIDENT = "inciting_incident",
|
|
66
|
+
RISING_ACTION = "rising_action",
|
|
67
|
+
TURNING_POINT = "turning_point",
|
|
68
|
+
COMPLICATION = "complication",
|
|
69
|
+
CRISIS = "crisis",
|
|
70
|
+
CLIMAX = "climax",
|
|
71
|
+
RESOLUTION = "resolution",
|
|
72
|
+
DENOUEMENT = "denouement",
|
|
73
|
+
BEAT = "beat"
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Current position in the narrative journey
|
|
77
|
+
*/
|
|
78
|
+
interface NarrativePosition {
|
|
79
|
+
act: number;
|
|
80
|
+
phase: NarrativePhase;
|
|
81
|
+
currentBeatId?: string;
|
|
82
|
+
beatCount: number;
|
|
83
|
+
characterArcStrength: number;
|
|
84
|
+
thematicResonance: number;
|
|
85
|
+
emotionalTone: string;
|
|
86
|
+
leadUniverse: Universe;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Create a NarrativePosition with defaults
|
|
90
|
+
*/
|
|
91
|
+
declare function createNarrativePosition(options?: Partial<NarrativePosition>): NarrativePosition;
|
|
92
|
+
/**
|
|
93
|
+
* A single story beat with three-universe perspectives
|
|
94
|
+
*/
|
|
95
|
+
interface StoryBeat {
|
|
96
|
+
id: string;
|
|
97
|
+
sequence: number;
|
|
98
|
+
content: string;
|
|
99
|
+
narrativeFunction: NarrativeFunction;
|
|
100
|
+
act: number;
|
|
101
|
+
universeAnalysis?: ThreeUniverseAnalysis;
|
|
102
|
+
leadUniverse: Universe;
|
|
103
|
+
emotionalTone: string;
|
|
104
|
+
thematicTags: string[];
|
|
105
|
+
characterId?: string;
|
|
106
|
+
characterArcImpact: number;
|
|
107
|
+
source: string;
|
|
108
|
+
sourceEventId?: string;
|
|
109
|
+
timestamp: string;
|
|
110
|
+
enrichmentsApplied: string[];
|
|
111
|
+
qualityScore: number;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Create a StoryBeat with defaults
|
|
115
|
+
*/
|
|
116
|
+
declare function createStoryBeat(id: string, sequence: number, content: string, narrativeFunction: NarrativeFunction, act: number, options?: Partial<StoryBeat>): StoryBeat;
|
|
117
|
+
/**
|
|
118
|
+
* Character state tracking for arc continuity
|
|
119
|
+
*/
|
|
120
|
+
interface CharacterState {
|
|
121
|
+
id: string;
|
|
122
|
+
name: string;
|
|
123
|
+
archetype: string;
|
|
124
|
+
universe: Universe;
|
|
125
|
+
arcPosition: number;
|
|
126
|
+
initialState: string;
|
|
127
|
+
currentState: string;
|
|
128
|
+
growthPoints: Array<{
|
|
129
|
+
timestamp: string;
|
|
130
|
+
impact: number;
|
|
131
|
+
description: string;
|
|
132
|
+
}>;
|
|
133
|
+
relationships: string[];
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Create a CharacterState with defaults
|
|
137
|
+
*/
|
|
138
|
+
declare function createCharacterState(id: string, name: string, archetype: string, universe: Universe, options?: Partial<CharacterState>): CharacterState;
|
|
139
|
+
/**
|
|
140
|
+
* A thematic thread being tracked across the narrative
|
|
141
|
+
*/
|
|
142
|
+
interface ThematicThread {
|
|
143
|
+
id: string;
|
|
144
|
+
name: string;
|
|
145
|
+
description: string;
|
|
146
|
+
strength: number;
|
|
147
|
+
tensionLevel: number;
|
|
148
|
+
resolutionProgress: number;
|
|
149
|
+
beatIds: string[];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Create a ThematicThread with defaults
|
|
153
|
+
*/
|
|
154
|
+
declare function createThematicThread(id: string, name: string, description: string, options?: Partial<ThematicThread>): ThematicThread;
|
|
155
|
+
/**
|
|
156
|
+
* Record of a routing decision for tracing
|
|
157
|
+
*/
|
|
158
|
+
interface RoutingDecision {
|
|
159
|
+
id: string;
|
|
160
|
+
backend: string;
|
|
161
|
+
flow: string;
|
|
162
|
+
universeAnalysis: ThreeUniverseAnalysis;
|
|
163
|
+
narrativePosition: NarrativePosition;
|
|
164
|
+
score: number;
|
|
165
|
+
method: string;
|
|
166
|
+
success: boolean;
|
|
167
|
+
resultSummary: string;
|
|
168
|
+
latencyMs: number;
|
|
169
|
+
timestamp: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a RoutingDecision
|
|
173
|
+
*/
|
|
174
|
+
declare function createRoutingDecision(id: string, backend: string, flow: string, universeAnalysis: ThreeUniverseAnalysis, narrativePosition: NarrativePosition, score: number, options?: Partial<RoutingDecision>): RoutingDecision;
|
|
175
|
+
/**
|
|
176
|
+
* The complete unified state shared across all systems.
|
|
177
|
+
* This is THE contract that all six systems use to communicate.
|
|
178
|
+
*/
|
|
179
|
+
interface UnifiedNarrativeState {
|
|
180
|
+
storyId: string;
|
|
181
|
+
sessionId: string;
|
|
182
|
+
position: NarrativePosition;
|
|
183
|
+
beats: StoryBeat[];
|
|
184
|
+
characters: Record<string, CharacterState>;
|
|
185
|
+
themes: Record<string, ThematicThread>;
|
|
186
|
+
routingDecisions: RoutingDecision[];
|
|
187
|
+
currentEpisodeId?: string;
|
|
188
|
+
episodeBeatsCount: number;
|
|
189
|
+
createdAt: string;
|
|
190
|
+
updatedAt: string;
|
|
191
|
+
overallCoherence: number;
|
|
192
|
+
emotionalArcStrength: number;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Create a new UnifiedNarrativeState
|
|
196
|
+
*/
|
|
197
|
+
declare function createUnifiedNarrativeState(storyId: string, sessionId: string, options?: {
|
|
198
|
+
includeDefaultCharacters?: boolean;
|
|
199
|
+
includeDefaultThemes?: boolean;
|
|
200
|
+
}): UnifiedNarrativeState;
|
|
201
|
+
/**
|
|
202
|
+
* Add a beat to the state
|
|
203
|
+
*/
|
|
204
|
+
declare function addBeat(state: UnifiedNarrativeState, beat: StoryBeat): void;
|
|
205
|
+
/**
|
|
206
|
+
* Add a routing decision to the state
|
|
207
|
+
*/
|
|
208
|
+
declare function addRoutingDecision(state: UnifiedNarrativeState, decision: RoutingDecision): void;
|
|
209
|
+
/**
|
|
210
|
+
* Update character arc position
|
|
211
|
+
*/
|
|
212
|
+
declare function updateCharacterArc(state: UnifiedNarrativeState, characterId: string, impact: number, description: string): void;
|
|
213
|
+
/**
|
|
214
|
+
* Update theme strength
|
|
215
|
+
*/
|
|
216
|
+
declare function updateThemeStrength(state: UnifiedNarrativeState, themeId: string, strengthDelta: number): void;
|
|
217
|
+
/**
|
|
218
|
+
* Get the last n beats for context
|
|
219
|
+
*/
|
|
220
|
+
declare function getLastNBeats(state: UnifiedNarrativeState, n?: number): StoryBeat[];
|
|
221
|
+
/**
|
|
222
|
+
* Calculate overall narrative coherence
|
|
223
|
+
*/
|
|
224
|
+
declare function calculateCoherence(state: UnifiedNarrativeState): number;
|
|
225
|
+
/**
|
|
226
|
+
* Check if we should create a new episode
|
|
227
|
+
*/
|
|
228
|
+
declare function shouldCreateNewEpisode(state: UnifiedNarrativeState): boolean;
|
|
229
|
+
/**
|
|
230
|
+
* Start a new episode
|
|
231
|
+
*/
|
|
232
|
+
declare function startNewEpisode(state: UnifiedNarrativeState, episodeId: string): void;
|
|
233
|
+
/**
|
|
234
|
+
* Get the three main archetypes from multiverse_3act
|
|
235
|
+
*/
|
|
236
|
+
declare function getDefaultCharacters(): Record<string, CharacterState>;
|
|
237
|
+
/**
|
|
238
|
+
* Get default thematic threads from multiverse_3act
|
|
239
|
+
*/
|
|
240
|
+
declare function getDefaultThemes(): Record<string, ThematicThread>;
|
|
241
|
+
/**
|
|
242
|
+
* Create a story beat from a webhook event
|
|
243
|
+
*/
|
|
244
|
+
declare function createBeatFromWebhook(eventId: string, content: string, universeAnalysis: ThreeUniverseAnalysis, sequence: number): StoryBeat;
|
|
245
|
+
/**
|
|
246
|
+
* Standard Redis key patterns for state storage
|
|
247
|
+
*/
|
|
248
|
+
declare const RedisKeys: {
|
|
249
|
+
state: (sessionId: string) => string;
|
|
250
|
+
currentState: () => string;
|
|
251
|
+
beats: (sessionId: string) => string;
|
|
252
|
+
beat: (beatId: string) => string;
|
|
253
|
+
eventAnalysis: (eventId: string) => string;
|
|
254
|
+
routingHistory: (sessionId: string) => string;
|
|
255
|
+
episode: (episodeId: string) => string;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Serialize state to JSON
|
|
259
|
+
*/
|
|
260
|
+
declare function serializeState(state: UnifiedNarrativeState): string;
|
|
261
|
+
/**
|
|
262
|
+
* Deserialize state from JSON
|
|
263
|
+
*/
|
|
264
|
+
declare function deserializeState(json: string): UnifiedNarrativeState;
|
|
265
|
+
|
|
266
|
+
export { updateCharacterArc as A, updateThemeStrength as B, type CharacterState as C, NarrativeFunction as N, RedisKeys as R, type StoryBeat as S, type ThematicThread as T, type UnifiedNarrativeState as U, NarrativePhase as a, type NarrativePosition as b, type RoutingDecision as c, type ThreeUniverseAnalysis as d, Universe as e, type UniversePerspective as f, addBeat as g, addRoutingDecision as h, calculateCoherence as i, createBeatFromWebhook as j, createCharacterState as k, createNarrativePosition as l, createRoutingDecision as m, createStoryBeat as n, createThematicThread as o, createThreeUniverseAnalysis as p, createUnifiedNarrativeState as q, createUniversePerspective as r, deserializeState as s, getDefaultCharacters as t, getDefaultThemes as u, getLastNBeats as v, getPerspective as w, serializeState as x, shouldCreateNewEpisode as y, startNewEpisode as z };
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ava-langgraph-narrative-intelligence",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Narrative Intelligence Toolkit for LangGraph.js - Three-universe processing and NCP analysis",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=18"
|
|
8
|
+
},
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"./schemas": {
|
|
18
|
+
"types": "./dist/schemas/index.d.ts",
|
|
19
|
+
"import": "./dist/schemas/index.js",
|
|
20
|
+
"require": "./dist/schemas/index.cjs"
|
|
21
|
+
},
|
|
22
|
+
"./graphs": {
|
|
23
|
+
"types": "./dist/graphs/index.d.ts",
|
|
24
|
+
"import": "./dist/graphs/index.js",
|
|
25
|
+
"require": "./dist/graphs/index.cjs"
|
|
26
|
+
},
|
|
27
|
+
"./nodes": {
|
|
28
|
+
"types": "./dist/nodes/index.d.ts",
|
|
29
|
+
"import": "./dist/nodes/index.js",
|
|
30
|
+
"require": "./dist/nodes/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./integrations": {
|
|
33
|
+
"types": "./dist/integrations/index.d.ts",
|
|
34
|
+
"import": "./dist/integrations/index.js",
|
|
35
|
+
"require": "./dist/integrations/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"src"
|
|
41
|
+
],
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsup",
|
|
44
|
+
"dev": "tsup --watch",
|
|
45
|
+
"lint": "eslint src",
|
|
46
|
+
"lint:fix": "eslint src --fix",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"test:watch": "vitest",
|
|
49
|
+
"clean": "rm -rf dist"
|
|
50
|
+
},
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/avadisabelle/ava-langgraphjs.git",
|
|
54
|
+
"directory": "libs/narrative-intelligence"
|
|
55
|
+
},
|
|
56
|
+
"keywords": [
|
|
57
|
+
"langgraph",
|
|
58
|
+
"narrative",
|
|
59
|
+
"intelligence",
|
|
60
|
+
"three-universe",
|
|
61
|
+
"ncp",
|
|
62
|
+
"storytelling"
|
|
63
|
+
],
|
|
64
|
+
"author": "ava",
|
|
65
|
+
"license": "MIT",
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"uuid": "^9.0.0"
|
|
68
|
+
},
|
|
69
|
+
"peerDependencies": {
|
|
70
|
+
"@langchain/langgraph": ">=0.2.0",
|
|
71
|
+
"ioredis": ">=5.0.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependenciesMeta": {
|
|
74
|
+
"@langchain/langgraph": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"ioredis": {
|
|
78
|
+
"optional": true
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@langchain/langgraph": "^0.2.0",
|
|
83
|
+
"@types/node": "^20.0.0",
|
|
84
|
+
"@types/uuid": "^9.0.0",
|
|
85
|
+
"eslint": "^8.0.0",
|
|
86
|
+
"ioredis": "^5.0.0",
|
|
87
|
+
"tsup": "^8.0.0",
|
|
88
|
+
"typescript": "^5.0.0",
|
|
89
|
+
"vitest": "^1.0.0"
|
|
90
|
+
}
|
|
91
|
+
}
|