@escapeaihq/client-core 0.12.0 → 0.49.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.
Files changed (242) hide show
  1. package/README.md +32 -7
  2. package/dist/adapters/capabilities.d.ts +10 -0
  3. package/dist/adapters/capabilities.d.ts.map +1 -0
  4. package/dist/adapters/capabilities.js +2 -0
  5. package/dist/adapters/capabilities.js.map +1 -0
  6. package/dist/adapters/chatAdapter.d.ts +38 -0
  7. package/dist/adapters/chatAdapter.d.ts.map +1 -0
  8. package/dist/adapters/chatAdapter.js +88 -0
  9. package/dist/adapters/chatAdapter.js.map +1 -0
  10. package/dist/adapters/directorAdapter.d.ts +62 -0
  11. package/dist/adapters/directorAdapter.d.ts.map +1 -0
  12. package/dist/adapters/directorAdapter.js +71 -0
  13. package/dist/adapters/directorAdapter.js.map +1 -0
  14. package/dist/adapters/imageAdapter.d.ts +44 -0
  15. package/dist/adapters/imageAdapter.d.ts.map +1 -0
  16. package/dist/adapters/imageAdapter.js +73 -0
  17. package/dist/adapters/imageAdapter.js.map +1 -0
  18. package/dist/adapters/index.d.ts +47 -0
  19. package/dist/adapters/index.d.ts.map +1 -0
  20. package/dist/adapters/index.js +41 -0
  21. package/dist/adapters/index.js.map +1 -0
  22. package/dist/adapters/registry.d.ts +98 -0
  23. package/dist/adapters/registry.d.ts.map +1 -0
  24. package/dist/adapters/registry.js +106 -0
  25. package/dist/adapters/registry.js.map +1 -0
  26. package/dist/adapters/worldAdapter.d.ts +142 -0
  27. package/dist/adapters/worldAdapter.d.ts.map +1 -0
  28. package/dist/adapters/worldAdapter.js +164 -0
  29. package/dist/adapters/worldAdapter.js.map +1 -0
  30. package/dist/admin.d.ts +323 -0
  31. package/dist/admin.d.ts.map +1 -0
  32. package/dist/admin.js +198 -0
  33. package/dist/admin.js.map +1 -0
  34. package/dist/api.d.ts +1512 -4
  35. package/dist/api.d.ts.map +1 -1
  36. package/dist/api.js +820 -52
  37. package/dist/api.js.map +1 -1
  38. package/dist/audio.d.ts +33 -1
  39. package/dist/audio.d.ts.map +1 -1
  40. package/dist/audio.js +4 -1
  41. package/dist/audio.js.map +1 -1
  42. package/dist/castProjection.d.ts +35 -0
  43. package/dist/castProjection.d.ts.map +1 -0
  44. package/dist/castProjection.js +80 -0
  45. package/dist/castProjection.js.map +1 -0
  46. package/dist/conversation/binding.d.ts +77 -0
  47. package/dist/conversation/binding.d.ts.map +1 -0
  48. package/dist/conversation/binding.js +57 -0
  49. package/dist/conversation/binding.js.map +1 -0
  50. package/dist/conversation/controller.d.ts +209 -0
  51. package/dist/conversation/controller.d.ts.map +1 -0
  52. package/dist/conversation/controller.js +350 -0
  53. package/dist/conversation/controller.js.map +1 -0
  54. package/dist/conversation/effectiveModel.d.ts +62 -0
  55. package/dist/conversation/effectiveModel.d.ts.map +1 -0
  56. package/dist/conversation/effectiveModel.js +73 -0
  57. package/dist/conversation/effectiveModel.js.map +1 -0
  58. package/dist/conversation/index.d.ts +27 -0
  59. package/dist/conversation/index.d.ts.map +1 -0
  60. package/dist/conversation/index.js +27 -0
  61. package/dist/conversation/index.js.map +1 -0
  62. package/dist/conversation/participant.d.ts +66 -0
  63. package/dist/conversation/participant.d.ts.map +1 -0
  64. package/dist/conversation/participant.js +36 -0
  65. package/dist/conversation/participant.js.map +1 -0
  66. package/dist/conversation/presence.d.ts +56 -0
  67. package/dist/conversation/presence.d.ts.map +1 -0
  68. package/dist/conversation/presence.js +34 -0
  69. package/dist/conversation/presence.js.map +1 -0
  70. package/dist/conversation/presenceBus.d.ts +42 -0
  71. package/dist/conversation/presenceBus.d.ts.map +1 -0
  72. package/dist/conversation/presenceBus.js +81 -0
  73. package/dist/conversation/presenceBus.js.map +1 -0
  74. package/dist/conversation/presenceRegistry.d.ts +49 -0
  75. package/dist/conversation/presenceRegistry.d.ts.map +1 -0
  76. package/dist/conversation/presenceRegistry.js +59 -0
  77. package/dist/conversation/presenceRegistry.js.map +1 -0
  78. package/dist/conversation/roster.d.ts +72 -0
  79. package/dist/conversation/roster.d.ts.map +1 -0
  80. package/dist/conversation/roster.js +69 -0
  81. package/dist/conversation/roster.js.map +1 -0
  82. package/dist/conversation/rosterProjection.d.ts +52 -0
  83. package/dist/conversation/rosterProjection.d.ts.map +1 -0
  84. package/dist/conversation/rosterProjection.js +74 -0
  85. package/dist/conversation/rosterProjection.js.map +1 -0
  86. package/dist/conversation/router.d.ts +74 -0
  87. package/dist/conversation/router.d.ts.map +1 -0
  88. package/dist/conversation/router.js +58 -0
  89. package/dist/conversation/router.js.map +1 -0
  90. package/dist/conversation/runtime.d.ts +64 -0
  91. package/dist/conversation/runtime.d.ts.map +1 -0
  92. package/dist/conversation/runtime.js +172 -0
  93. package/dist/conversation/runtime.js.map +1 -0
  94. package/dist/conversation/types.d.ts +99 -0
  95. package/dist/conversation/types.d.ts.map +1 -0
  96. package/dist/conversation/types.js +13 -0
  97. package/dist/conversation/types.js.map +1 -0
  98. package/dist/conversation/voice.d.ts +185 -0
  99. package/dist/conversation/voice.d.ts.map +1 -0
  100. package/dist/conversation/voice.js +307 -0
  101. package/dist/conversation/voice.js.map +1 -0
  102. package/dist/graphSchema.d.ts +201 -13
  103. package/dist/graphSchema.d.ts.map +1 -1
  104. package/dist/graphSchema.js +258 -9
  105. package/dist/graphSchema.js.map +1 -1
  106. package/dist/http.d.ts +20 -0
  107. package/dist/http.d.ts.map +1 -0
  108. package/dist/http.js +57 -0
  109. package/dist/http.js.map +1 -0
  110. package/dist/index.d.ts +6 -0
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +9 -0
  113. package/dist/index.js.map +1 -1
  114. package/dist/platformAssistant.d.ts +155 -0
  115. package/dist/platformAssistant.d.ts.map +1 -0
  116. package/dist/platformAssistant.js +256 -0
  117. package/dist/platformAssistant.js.map +1 -0
  118. package/dist/reactor/chunkDistribution.d.ts +43 -0
  119. package/dist/reactor/chunkDistribution.d.ts.map +1 -0
  120. package/dist/reactor/chunkDistribution.js +85 -0
  121. package/dist/reactor/chunkDistribution.js.map +1 -0
  122. package/dist/reactor/index.d.ts +2 -0
  123. package/dist/reactor/index.d.ts.map +1 -1
  124. package/dist/reactor/index.js +5 -0
  125. package/dist/reactor/index.js.map +1 -1
  126. package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
  127. package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
  128. package/dist/reactor/longLiveCommandDispatcher.js +87 -0
  129. package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
  130. package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
  131. package/dist/reactor/scenesFromEnrichment.js +2 -66
  132. package/dist/reactor/scenesFromEnrichment.js.map +1 -1
  133. package/dist/reactor/seedImageOrchestrator.d.ts +6 -9
  134. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
  135. package/dist/reactor/seedImageOrchestrator.js +12 -13
  136. package/dist/reactor/seedImageOrchestrator.js.map +1 -1
  137. package/dist/reactor/storyTimeline.d.ts +44 -0
  138. package/dist/reactor/storyTimeline.d.ts.map +1 -0
  139. package/dist/reactor/storyTimeline.js +95 -0
  140. package/dist/reactor/storyTimeline.js.map +1 -0
  141. package/dist/storyGraph.d.ts +70 -0
  142. package/dist/storyGraph.d.ts.map +1 -0
  143. package/dist/storyGraph.js +178 -0
  144. package/dist/storyGraph.js.map +1 -0
  145. package/dist/vision/VisionSourceController.d.ts +127 -0
  146. package/dist/vision/VisionSourceController.d.ts.map +1 -0
  147. package/dist/vision/VisionSourceController.js +284 -0
  148. package/dist/vision/VisionSourceController.js.map +1 -0
  149. package/dist/vision/index.d.ts +4 -0
  150. package/dist/vision/index.d.ts.map +1 -1
  151. package/dist/vision/index.js +2 -0
  152. package/dist/vision/index.js.map +1 -1
  153. package/dist/vision/sourceKinds.d.ts +65 -0
  154. package/dist/vision/sourceKinds.d.ts.map +1 -0
  155. package/dist/vision/sourceKinds.js +26 -0
  156. package/dist/vision/sourceKinds.js.map +1 -0
  157. package/dist/websocket.d.ts +92 -0
  158. package/dist/websocket.d.ts.map +1 -1
  159. package/dist/websocket.js.map +1 -1
  160. package/package.json +1 -1
  161. package/src/__tests__/adapters-capabilities.test.ts +46 -0
  162. package/src/__tests__/adapters-chat.test.ts +172 -0
  163. package/src/__tests__/adapters-director.test.ts +95 -0
  164. package/src/__tests__/adapters-image.test.ts +133 -0
  165. package/src/__tests__/adapters-platform.test.ts +95 -0
  166. package/src/__tests__/adapters-registry.test.ts +189 -0
  167. package/src/__tests__/adapters-world.test.ts +296 -0
  168. package/src/__tests__/admin.test.ts +312 -0
  169. package/src/__tests__/adventures-party.test.ts +219 -0
  170. package/src/__tests__/adventures.test.ts +282 -0
  171. package/src/__tests__/api-pollers.test.ts +4 -0
  172. package/src/__tests__/api.clip-lookup.test.ts +64 -0
  173. package/src/__tests__/api.list-images-filters.test.ts +103 -0
  174. package/src/__tests__/api.test.ts +553 -0
  175. package/src/__tests__/audio.test.ts +65 -0
  176. package/src/__tests__/cast.test.ts +95 -0
  177. package/src/__tests__/castProjection.test.ts +167 -0
  178. package/src/__tests__/conversation/binding.test.ts +62 -0
  179. package/src/__tests__/conversation/controller.test.ts +732 -0
  180. package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
  181. package/src/__tests__/conversation/headlessRenderer.ts +46 -0
  182. package/src/__tests__/conversation/presenceBus.test.ts +236 -0
  183. package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
  184. package/src/__tests__/conversation/roster.test.ts +100 -0
  185. package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
  186. package/src/__tests__/conversation/router.test.ts +81 -0
  187. package/src/__tests__/conversation/runtime.test.ts +206 -0
  188. package/src/__tests__/conversation/voice.test.ts +440 -0
  189. package/src/__tests__/documents.test.ts +360 -0
  190. package/src/__tests__/graphSchema.test.ts +218 -9
  191. package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
  192. package/src/__tests__/monitoring.test.ts +162 -0
  193. package/src/__tests__/persona-generation.test.ts +352 -0
  194. package/src/__tests__/platformAssistant.test.ts +484 -0
  195. package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
  196. package/src/__tests__/regeneration.test.ts +486 -0
  197. package/src/__tests__/stories.test.ts +171 -0
  198. package/src/__tests__/storyGraph.test.ts +134 -0
  199. package/src/__tests__/tools-wrappers.test.ts +272 -0
  200. package/src/__tests__/videoGraph.test.ts +94 -0
  201. package/src/__tests__/websocket.test.ts +263 -0
  202. package/src/adapters/capabilities.ts +24 -0
  203. package/src/adapters/chatAdapter.ts +114 -0
  204. package/src/adapters/directorAdapter.ts +126 -0
  205. package/src/adapters/imageAdapter.ts +100 -0
  206. package/src/adapters/index.ts +67 -0
  207. package/src/adapters/registry.ts +159 -0
  208. package/src/adapters/worldAdapter.ts +272 -0
  209. package/src/admin.ts +517 -0
  210. package/src/api.ts +2215 -95
  211. package/src/audio.ts +35 -0
  212. package/src/castProjection.ts +95 -0
  213. package/src/conversation/binding.ts +100 -0
  214. package/src/conversation/controller.ts +447 -0
  215. package/src/conversation/effectiveModel.ts +111 -0
  216. package/src/conversation/index.ts +27 -0
  217. package/src/conversation/participant.ts +71 -0
  218. package/src/conversation/presence.ts +60 -0
  219. package/src/conversation/presenceBus.ts +109 -0
  220. package/src/conversation/presenceRegistry.ts +83 -0
  221. package/src/conversation/roster.ts +111 -0
  222. package/src/conversation/rosterProjection.ts +98 -0
  223. package/src/conversation/router.ts +96 -0
  224. package/src/conversation/runtime.ts +188 -0
  225. package/src/conversation/types.ts +100 -0
  226. package/src/conversation/voice.ts +402 -0
  227. package/src/graphSchema.ts +396 -13
  228. package/src/http.ts +72 -0
  229. package/src/index.ts +9 -0
  230. package/src/platformAssistant.ts +347 -0
  231. package/src/reactor/chunkDistribution.ts +98 -0
  232. package/src/reactor/index.ts +5 -0
  233. package/src/reactor/longLiveCommandDispatcher.ts +156 -0
  234. package/src/reactor/scenesFromEnrichment.ts +11 -76
  235. package/src/reactor/seedImageOrchestrator.ts +12 -13
  236. package/src/reactor/storyTimeline.ts +127 -0
  237. package/src/storyGraph.ts +298 -0
  238. package/src/vision/VisionSourceController.ts +354 -0
  239. package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
  240. package/src/vision/index.ts +13 -0
  241. package/src/vision/sourceKinds.ts +75 -0
  242. package/src/websocket.ts +99 -3
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Party / roster helpers (R7.1), lifted VERBATIM (logic-preserving) from
3
+ * `web/app/chat-ws/adventureMode.ts` (M9 Story Engine Phase 8b Component F +
4
+ * M10 Phase 9b) — they were always I/O-free and misplaced in `web/`.
5
+ *
6
+ * Single source of truth for the Dungeon-Master tool names that MUTATE the
7
+ * server-authoritative `AdventureState` (`shared/tool_schemas.py`'s
8
+ * `_ADVENTURE_TOOL_SCHEMAS`). When the chat stream reports a `tool_result` for
9
+ * one of these, the host re-fetches `getAdventure(...)` to mirror the new
10
+ * state. `_ADVENTURE_TOOL_SCHEMAS` defines 7 DM tools; this is the 4 that
11
+ * mutate. The 3 read-only DM tools (`describe_current_scene`, `get_flag`,
12
+ * `get_party_status`) and ordinary chat tools must NOT be in this set, so they
13
+ * never trigger a re-fetch and an inactive adventure stays land-dark.
14
+ */
15
+ /**
16
+ * The four DM tools that mutate `AdventureState`. Mirrors the Python
17
+ * `_ADVENTURE_TOOL_SCHEMAS` names in `shared/tool_schemas.py`. `readonly` so the
18
+ * set can't be mutated by a caller. After R7.2 this is the ONLY copy — the
19
+ * `web/` `adventureMode.ts` re-exports it from here.
20
+ */
21
+ export declare const ADVENTURE_MUTATION_TOOLS: readonly ["advance_story", "set_flag", "clear_flag", "update_inventory"];
22
+ export type AdventureMutationTool = (typeof ADVENTURE_MUTATION_TOOLS)[number];
23
+ /**
24
+ * True when `tool` is one of the DM tools that mutate adventure state, so the
25
+ * host should re-fetch. Tolerates `undefined` (a `tool_result` frame may
26
+ * omit `tool`) and any non-mutation tool by returning false — the load-bearing
27
+ * land-dark guarantee is that this is the ONLY gate on a rail re-fetch.
28
+ */
29
+ export declare function isAdventureMutationTool(tool: string | undefined): tool is AdventureMutationTool;
30
+ /**
31
+ * The single land-dark gate for re-fetching adventure state after a
32
+ * `tool_result` frame: refresh ONLY when an adventure is active AND a DM
33
+ * mutation tool ran. The `/chat-ws` message handler and
34
+ * `ConversationRuntime.applyFrame` call exactly this — so it is the one place
35
+ * that decides whether adventure mode does anything, and asserting it here
36
+ * proves the land-dark contract (no adventureSessionId ⇒ never true ⇒ no new
37
+ * network call, for ANY tool).
38
+ */
39
+ export declare function shouldRefreshAdventureRail(adventureSessionId: string | undefined, tool: string | undefined): boolean;
40
+ /**
41
+ * Pure candidate filter for party-member pickers (M10 Story Engine Phase 9b),
42
+ * extracted — like {@link shouldRefreshAdventureRail} — so the rule is
43
+ * unit-testable without a DOM render of the modal or the API client.
44
+ *
45
+ * A persona is a valid party candidate when it is:
46
+ * 1. NOT a Dungeon Master (`is_dungeon_master !== true`),
47
+ * 2. `status === 'approved'`,
48
+ * 3. bound to a character entity (`entity_id` non-null/non-empty),
49
+ * 4. bound to a character that exists in THIS story (its `entity_id` is in
50
+ * `storyCharacterEntityIds`), and
51
+ * 5. NOT already in the party / the DM (`persona_id` ∉ `excludePersonaIds`).
52
+ *
53
+ * Rule (4) is relaxed when `storyCharacterEntityIds` is `null` — the caller
54
+ * passes `null` only when `listVideoCharacters` was unavailable or errored, so
55
+ * the picker degrades to the looser "any character-bound persona" set rather
56
+ * than offering nothing (the caller logs a console warning). The character set
57
+ * being empty (not null) means the story genuinely has no characters ⇒ no
58
+ * candidates, which is correct.
59
+ *
60
+ * Typed loosely on the persona shape so this module takes no dependency on the
61
+ * full `PersonaConfig`. Pure: no side effects.
62
+ */
63
+ export interface PartyCandidatePersona {
64
+ persona_id: string;
65
+ status: 'pending' | 'approved';
66
+ entity_id?: string | null;
67
+ is_dungeon_master?: boolean;
68
+ }
69
+ export declare function filterPartyCandidates<T extends PartyCandidatePersona>(personas: readonly T[], excludePersonaIds: readonly string[],
70
+ /** Character entity ids in this story, or `null` to relax the story-binding check. */
71
+ storyCharacterEntityIds: ReadonlySet<string> | null): T[];
72
+ //# sourceMappingURL=roster.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roster.d.ts","sourceRoot":"","sources":["../../src/conversation/roster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,0EAK3B,CAAC;AAEX,MAAM,MAAM,qBAAqB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAC;AAM9E;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,IAAI,qBAAqB,CAE/B;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CACxC,kBAAkB,EAAE,MAAM,GAAG,SAAS,EACtC,IAAI,EAAE,MAAM,GAAG,SAAS,GACvB,OAAO,CAET;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,SAAS,GAAG,UAAU,CAAC;IAC/B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,qBAAqB,EACnE,QAAQ,EAAE,SAAS,CAAC,EAAE,EACtB,iBAAiB,EAAE,SAAS,MAAM,EAAE;AACpC,sFAAsF;AACtF,uBAAuB,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,GAClD,CAAC,EAAE,CAaL"}
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Party / roster helpers (R7.1), lifted VERBATIM (logic-preserving) from
3
+ * `web/app/chat-ws/adventureMode.ts` (M9 Story Engine Phase 8b Component F +
4
+ * M10 Phase 9b) — they were always I/O-free and misplaced in `web/`.
5
+ *
6
+ * Single source of truth for the Dungeon-Master tool names that MUTATE the
7
+ * server-authoritative `AdventureState` (`shared/tool_schemas.py`'s
8
+ * `_ADVENTURE_TOOL_SCHEMAS`). When the chat stream reports a `tool_result` for
9
+ * one of these, the host re-fetches `getAdventure(...)` to mirror the new
10
+ * state. `_ADVENTURE_TOOL_SCHEMAS` defines 7 DM tools; this is the 4 that
11
+ * mutate. The 3 read-only DM tools (`describe_current_scene`, `get_flag`,
12
+ * `get_party_status`) and ordinary chat tools must NOT be in this set, so they
13
+ * never trigger a re-fetch and an inactive adventure stays land-dark.
14
+ */
15
+ /**
16
+ * The four DM tools that mutate `AdventureState`. Mirrors the Python
17
+ * `_ADVENTURE_TOOL_SCHEMAS` names in `shared/tool_schemas.py`. `readonly` so the
18
+ * set can't be mutated by a caller. After R7.2 this is the ONLY copy — the
19
+ * `web/` `adventureMode.ts` re-exports it from here.
20
+ */
21
+ export const ADVENTURE_MUTATION_TOOLS = [
22
+ 'advance_story',
23
+ 'set_flag',
24
+ 'clear_flag',
25
+ 'update_inventory',
26
+ ];
27
+ const ADVENTURE_MUTATION_TOOL_SET = new Set(ADVENTURE_MUTATION_TOOLS);
28
+ /**
29
+ * True when `tool` is one of the DM tools that mutate adventure state, so the
30
+ * host should re-fetch. Tolerates `undefined` (a `tool_result` frame may
31
+ * omit `tool`) and any non-mutation tool by returning false — the load-bearing
32
+ * land-dark guarantee is that this is the ONLY gate on a rail re-fetch.
33
+ */
34
+ export function isAdventureMutationTool(tool) {
35
+ return tool !== undefined && ADVENTURE_MUTATION_TOOL_SET.has(tool);
36
+ }
37
+ /**
38
+ * The single land-dark gate for re-fetching adventure state after a
39
+ * `tool_result` frame: refresh ONLY when an adventure is active AND a DM
40
+ * mutation tool ran. The `/chat-ws` message handler and
41
+ * `ConversationRuntime.applyFrame` call exactly this — so it is the one place
42
+ * that decides whether adventure mode does anything, and asserting it here
43
+ * proves the land-dark contract (no adventureSessionId ⇒ never true ⇒ no new
44
+ * network call, for ANY tool).
45
+ */
46
+ export function shouldRefreshAdventureRail(adventureSessionId, tool) {
47
+ return Boolean(adventureSessionId) && isAdventureMutationTool(tool);
48
+ }
49
+ export function filterPartyCandidates(personas, excludePersonaIds,
50
+ /** Character entity ids in this story, or `null` to relax the story-binding check. */
51
+ storyCharacterEntityIds) {
52
+ const excluded = new Set(excludePersonaIds);
53
+ return personas.filter((p) => {
54
+ if (p.is_dungeon_master === true)
55
+ return false;
56
+ if (p.status !== 'approved')
57
+ return false;
58
+ if (!p.entity_id)
59
+ return false;
60
+ if (excluded.has(p.persona_id))
61
+ return false;
62
+ // Story-binding check, relaxed (fallback) when the character set is null.
63
+ if (storyCharacterEntityIds !== null && !storyCharacterEntityIds.has(p.entity_id)) {
64
+ return false;
65
+ }
66
+ return true;
67
+ });
68
+ }
69
+ //# sourceMappingURL=roster.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roster.js","sourceRoot":"","sources":["../../src/conversation/roster.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,eAAe;IACf,UAAU;IACV,YAAY;IACZ,kBAAkB;CACV,CAAC;AAIX,MAAM,2BAA2B,GAAwB,IAAI,GAAG,CAC9D,wBAAwB,CACzB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,IAAwB;IAExB,OAAO,IAAI,KAAK,SAAS,IAAI,2BAA2B,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,0BAA0B,CACxC,kBAAsC,EACtC,IAAwB;IAExB,OAAO,OAAO,CAAC,kBAAkB,CAAC,IAAI,uBAAuB,CAAC,IAAI,CAAC,CAAC;AACtE,CAAC;AAgCD,MAAM,UAAU,qBAAqB,CACnC,QAAsB,EACtB,iBAAoC;AACpC,sFAAsF;AACtF,uBAAmD;IAEnD,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,iBAAiB,CAAC,CAAC;IAC5C,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;QAC3B,IAAI,CAAC,CAAC,iBAAiB,KAAK,IAAI;YAAE,OAAO,KAAK,CAAC;QAC/C,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU;YAAE,OAAO,KAAK,CAAC;QAC1C,IAAI,CAAC,CAAC,CAAC,SAAS;YAAE,OAAO,KAAK,CAAC;QAC/B,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC;QAC7C,0EAA0E;QAC1E,IAAI,uBAAuB,KAAK,IAAI,IAAI,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC;YAClF,OAAO,KAAK,CAAC;QACf,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * `castToRoster` (R7.4) — the single DRY projection turning R5's one-call
3
+ * cast-with-persona response (`getCast` → `CastEntry[]`) plus the active
4
+ * `AdventureState` (DM persona + `partyPersonaIds`) into the
5
+ * {@link RosterParticipant}[] the framework-agnostic `ConversationRuntime` and
6
+ * `presenceBus` consume.
7
+ *
8
+ * WHY this exists: pre-R7.4 the Studio surface derived its party roster by a
9
+ * CLIENT-SIDE `entity_id ∈ storyCharacterEntityIds` join across two stores
10
+ * (`listVideoCharacters` + `listPersonas`), which depends on
11
+ * `generate_entity_id` vs `generate_document_entity_id` string matching
12
+ * (`shared/neo4j_queries.py`). R5 moved that join SERVER-SIDE
13
+ * (`GET /api/v1/tools/videos/{videoId}/cast`, the PORTRAYS edge +
14
+ * authoritative `PersonaConfig.entity_id`). This function is the one place that
15
+ * reshapes that authoritative projection into the renderer-facing roster — so
16
+ * the roster never re-derives the binding client-side again.
17
+ *
18
+ * Ordering is server-party-authoritative: the DM seat leads (it always holds
19
+ * the floor first — the runtime's initial `activePersonaId`), then each party
20
+ * member in `partyPersonaIds` order. Every server-party member gets a seat even
21
+ * when absent from the cast projection (a removed/foreign id), so the runtime
22
+ * can always stage a `turn_changed` speaker; the display name falls back to the
23
+ * persona id in that defensive case.
24
+ *
25
+ * Pure: no I/O, no DOM, no React — framework-agnostic, like every other
26
+ * `conversation/` module. The presence kind is `PRESENCE_FACE_2D` for every
27
+ * seat (the current renderer); a future host can re-map per participant.
28
+ */
29
+ import type { RosterParticipant } from './types';
30
+ import type { CastEntry } from '../api';
31
+ /** The DM persona's identity fields the roster needs (a thin slice of the
32
+ * bound `PersonaConfig`). */
33
+ export interface RosterDmPersona {
34
+ personaId: string;
35
+ /** Display name for the DM's transcript pill / roster chip. */
36
+ name: string;
37
+ }
38
+ export interface CastToRosterInput {
39
+ /** R5's one-call cast-with-persona projection (`getCast(...).cast`). */
40
+ cast: readonly CastEntry[];
41
+ /** The Dungeon-Master persona running this adventure. */
42
+ dmPersona: RosterDmPersona;
43
+ /** The server-authoritative party member persona ids, in party order
44
+ * (`AdventureState.partyPersonaIds`). */
45
+ partyPersonaIds: readonly string[];
46
+ }
47
+ /**
48
+ * Project the cast + active adventure into the renderer-facing roster (DM seat
49
+ * first, then party members in party order, de-duplicated, DM never doubled).
50
+ */
51
+ export declare function castToRoster(input: CastToRosterInput): RosterParticipant[];
52
+ //# sourceMappingURL=rosterProjection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rosterProjection.d.ts","sourceRoot":"","sources":["../../src/conversation/rosterProjection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAGH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC;8BAC8B;AAC9B,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,iBAAiB;IAChC,wEAAwE;IACxE,IAAI,EAAE,SAAS,SAAS,EAAE,CAAC;IAC3B,yDAAyD;IACzD,SAAS,EAAE,eAAe,CAAC;IAC3B;8CAC0C;IAC1C,eAAe,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,CA0C1E"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * `castToRoster` (R7.4) — the single DRY projection turning R5's one-call
3
+ * cast-with-persona response (`getCast` → `CastEntry[]`) plus the active
4
+ * `AdventureState` (DM persona + `partyPersonaIds`) into the
5
+ * {@link RosterParticipant}[] the framework-agnostic `ConversationRuntime` and
6
+ * `presenceBus` consume.
7
+ *
8
+ * WHY this exists: pre-R7.4 the Studio surface derived its party roster by a
9
+ * CLIENT-SIDE `entity_id ∈ storyCharacterEntityIds` join across two stores
10
+ * (`listVideoCharacters` + `listPersonas`), which depends on
11
+ * `generate_entity_id` vs `generate_document_entity_id` string matching
12
+ * (`shared/neo4j_queries.py`). R5 moved that join SERVER-SIDE
13
+ * (`GET /api/v1/tools/videos/{videoId}/cast`, the PORTRAYS edge +
14
+ * authoritative `PersonaConfig.entity_id`). This function is the one place that
15
+ * reshapes that authoritative projection into the renderer-facing roster — so
16
+ * the roster never re-derives the binding client-side again.
17
+ *
18
+ * Ordering is server-party-authoritative: the DM seat leads (it always holds
19
+ * the floor first — the runtime's initial `activePersonaId`), then each party
20
+ * member in `partyPersonaIds` order. Every server-party member gets a seat even
21
+ * when absent from the cast projection (a removed/foreign id), so the runtime
22
+ * can always stage a `turn_changed` speaker; the display name falls back to the
23
+ * persona id in that defensive case.
24
+ *
25
+ * Pure: no I/O, no DOM, no React — framework-agnostic, like every other
26
+ * `conversation/` module. The presence kind is `PRESENCE_FACE_2D` for every
27
+ * seat (the current renderer); a future host can re-map per participant.
28
+ */
29
+ import { PresenceKind } from './participant.js';
30
+ /**
31
+ * Project the cast + active adventure into the renderer-facing roster (DM seat
32
+ * first, then party members in party order, de-duplicated, DM never doubled).
33
+ */
34
+ export function castToRoster(input) {
35
+ const { cast, dmPersona, partyPersonaIds } = input;
36
+ // Index the cast's bound personas by persona id so a party member resolves its
37
+ // display name (the persona's, not the character's) + bound entity id in O(1).
38
+ const castByPersonaId = new Map();
39
+ for (const entry of cast) {
40
+ if (entry.persona)
41
+ castByPersonaId.set(entry.persona.personaId, entry);
42
+ }
43
+ const roster = [
44
+ {
45
+ personaId: dmPersona.personaId,
46
+ isDm: true,
47
+ displayName: dmPersona.name,
48
+ presence: PresenceKind.PRESENCE_FACE_2D,
49
+ },
50
+ ];
51
+ // The DM is already seated; never seat it twice, and de-duplicate repeated
52
+ // party ids (first occurrence wins — mirrors the server party set semantics).
53
+ const seen = new Set([dmPersona.personaId]);
54
+ for (const personaId of partyPersonaIds) {
55
+ if (seen.has(personaId))
56
+ continue;
57
+ seen.add(personaId);
58
+ const entry = castByPersonaId.get(personaId);
59
+ roster.push({
60
+ personaId,
61
+ isDm: false,
62
+ // The persona's display name wins (the transcript pill the user sees);
63
+ // fall back to the character name, then the raw id (defensive — a removed
64
+ // or foreign party member still needs a seat so the runtime can stage it).
65
+ displayName: entry?.persona?.name ?? entry?.character.name ?? personaId,
66
+ ...(entry?.character.entityId
67
+ ? { entityId: entry.character.entityId }
68
+ : {}),
69
+ presence: PresenceKind.PRESENCE_FACE_2D,
70
+ });
71
+ }
72
+ return roster;
73
+ }
74
+ //# sourceMappingURL=rosterProjection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rosterProjection.js","sourceRoot":"","sources":["../../src/conversation/rosterProjection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAsB7C;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IAEnD,+EAA+E;IAC/E,+EAA+E;IAC/E,MAAM,eAAe,GAAG,IAAI,GAAG,EAAqB,CAAC;IACrD,KAAK,MAAM,KAAK,IAAI,IAAI,EAAE,CAAC;QACzB,IAAI,KAAK,CAAC,OAAO;YAAE,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,MAAM,GAAwB;QAClC;YACE,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,IAAI,EAAE,IAAI;YACV,WAAW,EAAE,SAAS,CAAC,IAAI;YAC3B,QAAQ,EAAE,YAAY,CAAC,gBAAgB;SACxC;KACF,CAAC;IAEF,2EAA2E;IAC3E,8EAA8E;IAC9E,MAAM,IAAI,GAAG,IAAI,GAAG,CAAS,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;IACpD,KAAK,MAAM,SAAS,IAAI,eAAe,EAAE,CAAC;QACxC,IAAI,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC;YAAE,SAAS;QAClC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAEpB,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC;YACV,SAAS;YACT,IAAI,EAAE,KAAK;YACX,uEAAuE;YACvE,0EAA0E;YAC1E,2EAA2E;YAC3E,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,IAAI,KAAK,EAAE,SAAS,CAAC,IAAI,IAAI,SAAS;YACvE,GAAG,CAAC,KAAK,EAAE,SAAS,CAAC,QAAQ;gBAC3B,CAAC,CAAC,EAAE,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE;gBACxC,CAAC,CAAC,EAAE,CAAC;YACP,QAAQ,EAAE,YAAY,CAAC,gBAAgB;SACxC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Advisory client-side routing helpers (R7.1), lifted VERBATIM
3
+ * (logic-preserving) from `web/app/chat-ws/adventureMode.ts` — they were
4
+ * always I/O-free and misplaced in `web/`.
5
+ *
6
+ * **ADVISORY ONLY.** The server `agents/orchestrator/persona_router.py`
7
+ * `resolve_addressed_persona` is the AUTHORITATIVE router: it alone decides
8
+ * which persona takes a turn. The client NEVER routes a turn — these helpers
9
+ * only read the server's `turn_changed` frames and per-frame `personaId`
10
+ * stamps so a renderer can display who is speaking. Any client-side
11
+ * address-resolution mirror must stay presentation-only and must never be
12
+ * promoted to a routing decision.
13
+ */
14
+ /**
15
+ * The additive multi-persona fields the M10 Story Engine Phase 9a server stamps
16
+ * on chat frames. This is the single, narrowly-typed structural seam for
17
+ * reading `type: 'turn_changed'` and the per-frame `personaId` off an incoming
18
+ * message without an unsafe inline cast at each call site — every member of
19
+ * the precise `ChatWsEvent` union (websocket.ts) is assignable to it. Both
20
+ * fields are optional: a non-adventure frame carries neither, so every reader
21
+ * degrades to the land-dark path.
22
+ */
23
+ export interface MultiPersonaFrameFields {
24
+ type: string;
25
+ personaId?: string;
26
+ }
27
+ /**
28
+ * Pull the active speaking persona id off a `turn_changed` event — the M10 9a
29
+ * scene orchestrator's signal that the turn passed to a different persona.
30
+ * Funnelling the read through one helper keeps the contract in one place
31
+ * (the `/chat-ws` handler and `ConversationRuntime.applyFrame` both route
32
+ * through it).
33
+ *
34
+ * LAND-DARK: returns `null` unless the frame is genuinely a `turn_changed`
35
+ * carrying a non-empty `personaId` AND an adventure is active
36
+ * (`adventureSessionId` set). `turn_changed` is only ever emitted in a
37
+ * non-empty-party adventure, but gating on the session id too means an
38
+ * ordinary-chat frame can never move the speaker, even defensively.
39
+ */
40
+ export declare function turnChangedSpeakerId(message: MultiPersonaFrameFields, adventureSessionId: string | undefined): string | null;
41
+ /**
42
+ * Resolve the per-message persona "pill" for an assistant transcript bubble
43
+ * (M10 Phase 9b). Given the `personaId` captured off the assistant's chat
44
+ * frames and the backend persona list, returns the id + display name to render,
45
+ * or `null` when there's nothing to show. Pure so the transcript pill is
46
+ * unit-testable without a DOM render.
47
+ *
48
+ * LAND-DARK: returns `null` for a `personaId` of `undefined` (every
49
+ * non-adventure assistant message — those frames never carry one), so a normal
50
+ * chat bubble renders byte-identically. When the id is present but unresolvable
51
+ * in `personas` (e.g. a since-deleted persona), falls back to the raw id as the
52
+ * name so the speaker is still attributed rather than silently dropped.
53
+ */
54
+ export interface PillPersona {
55
+ persona_id: string;
56
+ name: string;
57
+ }
58
+ export declare function resolvePersonaPill(personaId: string | undefined, personas: readonly PillPersona[]): {
59
+ personaId: string;
60
+ name: string;
61
+ } | null;
62
+ /**
63
+ * Advisory `partyPersonaIds` for the `send(...)` / `buildHelloPayload(...)`
64
+ * options when in a multi-persona adventure (M10 Phase 9b). The server's
65
+ * `AdventureState.party_persona_ids` is authoritative for scene routing — this
66
+ * is forward-compat/advisory only.
67
+ *
68
+ * LAND-DARK: returns `undefined` when there's no active adventure session OR the
69
+ * party is empty/absent, so both option builders drop the key entirely (they
70
+ * already omit `undefined`) and the wire stays byte-identical for ordinary chat
71
+ * and M9 single-DM adventures.
72
+ */
73
+ export declare function advisoryPartyPersonaIds(adventureSessionId: string | undefined, partyPersonaIds: readonly string[] | undefined): string[] | undefined;
74
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/conversation/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;;;;;;GAQG;AACH,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,uBAAuB,EAChC,kBAAkB,EAAE,MAAM,GAAG,SAAS,GACrC,MAAM,GAAG,IAAI,CAIf;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,QAAQ,EAAE,SAAS,WAAW,EAAE,GAC/B;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAI5C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CACrC,kBAAkB,EAAE,MAAM,GAAG,SAAS,EACtC,eAAe,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,GAC7C,MAAM,EAAE,GAAG,SAAS,CAItB"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Advisory client-side routing helpers (R7.1), lifted VERBATIM
3
+ * (logic-preserving) from `web/app/chat-ws/adventureMode.ts` — they were
4
+ * always I/O-free and misplaced in `web/`.
5
+ *
6
+ * **ADVISORY ONLY.** The server `agents/orchestrator/persona_router.py`
7
+ * `resolve_addressed_persona` is the AUTHORITATIVE router: it alone decides
8
+ * which persona takes a turn. The client NEVER routes a turn — these helpers
9
+ * only read the server's `turn_changed` frames and per-frame `personaId`
10
+ * stamps so a renderer can display who is speaking. Any client-side
11
+ * address-resolution mirror must stay presentation-only and must never be
12
+ * promoted to a routing decision.
13
+ */
14
+ /**
15
+ * Pull the active speaking persona id off a `turn_changed` event — the M10 9a
16
+ * scene orchestrator's signal that the turn passed to a different persona.
17
+ * Funnelling the read through one helper keeps the contract in one place
18
+ * (the `/chat-ws` handler and `ConversationRuntime.applyFrame` both route
19
+ * through it).
20
+ *
21
+ * LAND-DARK: returns `null` unless the frame is genuinely a `turn_changed`
22
+ * carrying a non-empty `personaId` AND an adventure is active
23
+ * (`adventureSessionId` set). `turn_changed` is only ever emitted in a
24
+ * non-empty-party adventure, but gating on the session id too means an
25
+ * ordinary-chat frame can never move the speaker, even defensively.
26
+ */
27
+ export function turnChangedSpeakerId(message, adventureSessionId) {
28
+ if (!adventureSessionId)
29
+ return null;
30
+ if (message.type !== 'turn_changed')
31
+ return null;
32
+ return message.personaId && message.personaId.length > 0 ? message.personaId : null;
33
+ }
34
+ export function resolvePersonaPill(personaId, personas) {
35
+ if (!personaId)
36
+ return null;
37
+ const match = personas.find((p) => p.persona_id === personaId);
38
+ return { personaId, name: match?.name ?? personaId };
39
+ }
40
+ /**
41
+ * Advisory `partyPersonaIds` for the `send(...)` / `buildHelloPayload(...)`
42
+ * options when in a multi-persona adventure (M10 Phase 9b). The server's
43
+ * `AdventureState.party_persona_ids` is authoritative for scene routing — this
44
+ * is forward-compat/advisory only.
45
+ *
46
+ * LAND-DARK: returns `undefined` when there's no active adventure session OR the
47
+ * party is empty/absent, so both option builders drop the key entirely (they
48
+ * already omit `undefined`) and the wire stays byte-identical for ordinary chat
49
+ * and M9 single-DM adventures.
50
+ */
51
+ export function advisoryPartyPersonaIds(adventureSessionId, partyPersonaIds) {
52
+ if (!adventureSessionId)
53
+ return undefined;
54
+ if (!partyPersonaIds || partyPersonaIds.length === 0)
55
+ return undefined;
56
+ return [...partyPersonaIds];
57
+ }
58
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/conversation/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAgBH;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAAgC,EAChC,kBAAsC;IAEtC,IAAI,CAAC,kBAAkB;QAAE,OAAO,IAAI,CAAC;IACrC,IAAI,OAAO,CAAC,IAAI,KAAK,cAAc;QAAE,OAAO,IAAI,CAAC;IACjD,OAAO,OAAO,CAAC,SAAS,IAAI,OAAO,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC;AACtF,CAAC;AAoBD,MAAM,UAAU,kBAAkB,CAChC,SAA6B,EAC7B,QAAgC;IAEhC,IAAI,CAAC,SAAS;QAAE,OAAO,IAAI,CAAC;IAC5B,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC;IAC/D,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,IAAI,SAAS,EAAE,CAAC;AACvD,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,uBAAuB,CACrC,kBAAsC,EACtC,eAA8C;IAE9C,IAAI,CAAC,kBAAkB;QAAE,OAAO,SAAS,CAAC;IAC1C,IAAI,CAAC,eAAe,IAAI,eAAe,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACvE,OAAO,CAAC,GAAG,eAAe,CAAC,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * `ConversationRuntime` (R7.1) — a pure, framework-agnostic reducer/observer
3
+ * that consumes the EXISTING additive WS frames (`ChatWsEvent`,
4
+ * websocket.ts) and produces a renderer-agnostic
5
+ * {@link ConversationRuntimeState} (who is in the roster, who is speaking,
6
+ * per-message persona attribution, busy flag, stale-adventure flag).
7
+ *
8
+ * This is the CLIENT MIRROR of the server `SceneOrchestrator`'s observable
9
+ * state: it makes NO tool/Bedrock/model decisions (the server owns routing —
10
+ * `agents/orchestrator/persona_router.py` is authoritative; model selection
11
+ * belongs to R1's registry + R2's `resolveEffectiveModel`). It only derives
12
+ * presentation state from frames the server already emits, through the same
13
+ * single gates the `/chat-ws` page uses today (`turnChangedSpeakerId`,
14
+ * `shouldRefreshAdventureRail`) — so React (R7.2) and a PlayCanvas host (R7.3+)
15
+ * render identical state with zero React/DOM imports here.
16
+ *
17
+ * LAND-DARK: for ordinary chat and M9 single-DM (empty-party) adventures no
18
+ * `turn_changed` ever arrives and no frame carries a `personaId`, so
19
+ * `activePersonaId` stays the bound persona, the roster stays as constructed,
20
+ * and the only transitions are busy/message-attribution — byte-identical
21
+ * "lone speaker" behavior.
22
+ */
23
+ import type { ChatWsEvent } from '../websocket';
24
+ import type { ConversationRuntimeListener, ConversationRuntimeOptions, ConversationRuntimeState } from './types';
25
+ export declare class ConversationRuntime {
26
+ private state;
27
+ private readonly adventureSessionId;
28
+ private readonly listeners;
29
+ constructor(opts?: ConversationRuntimeOptions);
30
+ /** Current immutable snapshot. A new object per actual transition, so hosts
31
+ * can use reference equality for change detection. */
32
+ getState(): ConversationRuntimeState;
33
+ /**
34
+ * Subscribe to state transitions. The listener fires only when a transition
35
+ * actually changed the state (never on no-op frames). Returns an
36
+ * unsubscribe function. A throwing listener is isolated (logged via
37
+ * `console.error`) so it cannot break sibling listeners — mirrors the
38
+ * observer discipline of the R2.1 controller's typed callback seam.
39
+ */
40
+ subscribe(listener: ConversationRuntimeListener): () => void;
41
+ /**
42
+ * Reduce one incoming chat frame into the state. Pure per-frame transition —
43
+ * no network, no timers, no DOM. Unknown/irrelevant frame types are no-ops.
44
+ */
45
+ applyFrame(event: ChatWsEvent): void;
46
+ /**
47
+ * Host-driven turn release (R7.2, ADDITIVE): the host removed `personaId`
48
+ * from the party while it held the turn, so it loses the floor —
49
+ * `activePersonaId` returns to null until the server's next `turn_changed`.
50
+ * No-op when `personaId` is not the active speaker. This is the ONLY
51
+ * host-driven speaker transition (roster changes are a host concern, see
52
+ * `ConversationRuntimeState.participants`); a server `turn_changed` frame
53
+ * remains the only way the speaker MOVES to a persona (never self-routing).
54
+ */
55
+ releaseTurn(personaId: string): void;
56
+ /**
57
+ * The host re-fetched the server-authoritative `AdventureState`; clear the
58
+ * stale flag set by a DM mutation `tool_result`.
59
+ */
60
+ acknowledgeAdventureState(): void;
61
+ /** Apply a partial update; notify listeners only when something changed. */
62
+ private transition;
63
+ }
64
+ //# sourceMappingURL=runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../../src/conversation/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAGhD,OAAO,KAAK,EACV,2BAA2B,EAC3B,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,SAAS,CAAC;AAEjB,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,KAAK,CAA2B;IACxC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAqB;IACxD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0C;gBAExD,IAAI,GAAE,0BAA+B;IAajD;2DACuD;IACvD,QAAQ,IAAI,wBAAwB;IAIpC;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,EAAE,2BAA2B,GAAG,MAAM,IAAI;IAO5D;;;OAGG;IACH,UAAU,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI;IAgEpC;;;;;;;;OAQG;IACH,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI;IASpC;;;OAGG;IACH,yBAAyB,IAAI,IAAI;IAMjC,4EAA4E;IAC5E,OAAO,CAAC,UAAU;CAoBnB"}