@escapeaihq/client-core 0.8.0 → 0.42.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 (307) hide show
  1. package/README.md +48 -4
  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 +200 -0
  31. package/dist/admin.d.ts.map +1 -0
  32. package/dist/admin.js +124 -0
  33. package/dist/admin.js.map +1 -0
  34. package/dist/api.d.ts +1299 -3
  35. package/dist/api.d.ts.map +1 -1
  36. package/dist/api.js +683 -95
  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 +62 -0
  47. package/dist/conversation/binding.d.ts.map +1 -0
  48. package/dist/conversation/binding.js +51 -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 +342 -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 +260 -0
  103. package/dist/graphSchema.d.ts.map +1 -0
  104. package/dist/graphSchema.js +354 -0
  105. package/dist/graphSchema.js.map +1 -0
  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 +9 -0
  111. package/dist/index.d.ts.map +1 -1
  112. package/dist/index.js +12 -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/abortUtils.d.ts +16 -0
  119. package/dist/reactor/abortUtils.d.ts.map +1 -0
  120. package/dist/reactor/abortUtils.js +26 -0
  121. package/dist/reactor/abortUtils.js.map +1 -0
  122. package/dist/reactor/applyScenePrompt.d.ts +75 -0
  123. package/dist/reactor/applyScenePrompt.d.ts.map +1 -0
  124. package/dist/reactor/applyScenePrompt.js +60 -0
  125. package/dist/reactor/applyScenePrompt.js.map +1 -0
  126. package/dist/reactor/chunkDistribution.d.ts +43 -0
  127. package/dist/reactor/chunkDistribution.d.ts.map +1 -0
  128. package/dist/reactor/chunkDistribution.js +85 -0
  129. package/dist/reactor/chunkDistribution.js.map +1 -0
  130. package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
  131. package/dist/reactor/heliosCommandDispatcher.js +10 -15
  132. package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
  133. package/dist/reactor/index.d.ts +4 -0
  134. package/dist/reactor/index.d.ts.map +1 -1
  135. package/dist/reactor/index.js +7 -0
  136. package/dist/reactor/index.js.map +1 -1
  137. package/dist/reactor/longLiveCommandDispatcher.d.ts +103 -0
  138. package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -0
  139. package/dist/reactor/longLiveCommandDispatcher.js +87 -0
  140. package/dist/reactor/longLiveCommandDispatcher.js.map +1 -0
  141. package/dist/reactor/sceneEntry.d.ts +40 -6
  142. package/dist/reactor/sceneEntry.d.ts.map +1 -1
  143. package/dist/reactor/sceneEntry.js +63 -24
  144. package/dist/reactor/sceneEntry.js.map +1 -1
  145. package/dist/reactor/scenesFromEnrichment.d.ts.map +1 -1
  146. package/dist/reactor/scenesFromEnrichment.js +2 -66
  147. package/dist/reactor/scenesFromEnrichment.js.map +1 -1
  148. package/dist/reactor/seedImageOrchestrator.d.ts +42 -2
  149. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
  150. package/dist/reactor/seedImageOrchestrator.js +173 -4
  151. package/dist/reactor/seedImageOrchestrator.js.map +1 -1
  152. package/dist/reactor/storyTimeline.d.ts +44 -0
  153. package/dist/reactor/storyTimeline.d.ts.map +1 -0
  154. package/dist/reactor/storyTimeline.js +95 -0
  155. package/dist/reactor/storyTimeline.js.map +1 -0
  156. package/dist/storyGraph.d.ts +70 -0
  157. package/dist/storyGraph.d.ts.map +1 -0
  158. package/dist/storyGraph.js +178 -0
  159. package/dist/storyGraph.js.map +1 -0
  160. package/dist/timeFormat.d.ts +10 -0
  161. package/dist/timeFormat.d.ts.map +1 -1
  162. package/dist/timeFormat.js +12 -0
  163. package/dist/timeFormat.js.map +1 -1
  164. package/dist/toolSchemas.d.ts +370 -0
  165. package/dist/toolSchemas.d.ts.map +1 -0
  166. package/dist/toolSchemas.js +182 -0
  167. package/dist/toolSchemas.js.map +1 -0
  168. package/dist/vision/VisionPublisher.d.ts +115 -0
  169. package/dist/vision/VisionPublisher.d.ts.map +1 -0
  170. package/dist/vision/VisionPublisher.js +475 -0
  171. package/dist/vision/VisionPublisher.js.map +1 -0
  172. package/dist/vision/VisionSourceController.d.ts +127 -0
  173. package/dist/vision/VisionSourceController.d.ts.map +1 -0
  174. package/dist/vision/VisionSourceController.js +284 -0
  175. package/dist/vision/VisionSourceController.js.map +1 -0
  176. package/dist/vision/credentials.d.ts +22 -0
  177. package/dist/vision/credentials.d.ts.map +1 -0
  178. package/dist/vision/credentials.js +34 -0
  179. package/dist/vision/credentials.js.map +1 -0
  180. package/dist/vision/index.d.ts +18 -0
  181. package/dist/vision/index.d.ts.map +1 -0
  182. package/dist/vision/index.js +13 -0
  183. package/dist/vision/index.js.map +1 -0
  184. package/dist/vision/sourceKinds.d.ts +65 -0
  185. package/dist/vision/sourceKinds.d.ts.map +1 -0
  186. package/dist/vision/sourceKinds.js +26 -0
  187. package/dist/vision/sourceKinds.js.map +1 -0
  188. package/dist/vision/startVisionPublisher.d.ts +38 -0
  189. package/dist/vision/startVisionPublisher.d.ts.map +1 -0
  190. package/dist/vision/startVisionPublisher.js +44 -0
  191. package/dist/vision/startVisionPublisher.js.map +1 -0
  192. package/dist/vision/types.d.ts +95 -0
  193. package/dist/vision/types.d.ts.map +1 -0
  194. package/dist/vision/types.js +12 -0
  195. package/dist/vision/types.js.map +1 -0
  196. package/dist/vision/visionScheduler.d.ts +63 -0
  197. package/dist/vision/visionScheduler.d.ts.map +1 -0
  198. package/dist/vision/visionScheduler.js +67 -0
  199. package/dist/vision/visionScheduler.js.map +1 -0
  200. package/dist/websocket.d.ts +195 -0
  201. package/dist/websocket.d.ts.map +1 -1
  202. package/dist/websocket.js +179 -1
  203. package/dist/websocket.js.map +1 -1
  204. package/package.json +11 -1
  205. package/src/__tests__/adapters-capabilities.test.ts +46 -0
  206. package/src/__tests__/adapters-chat.test.ts +172 -0
  207. package/src/__tests__/adapters-director.test.ts +95 -0
  208. package/src/__tests__/adapters-image.test.ts +133 -0
  209. package/src/__tests__/adapters-platform.test.ts +95 -0
  210. package/src/__tests__/adapters-registry.test.ts +189 -0
  211. package/src/__tests__/adapters-world.test.ts +296 -0
  212. package/src/__tests__/admin.test.ts +312 -0
  213. package/src/__tests__/adventures-party.test.ts +219 -0
  214. package/src/__tests__/adventures.test.ts +282 -0
  215. package/src/__tests__/api-pollers.test.ts +104 -0
  216. package/src/__tests__/api.clip-lookup.test.ts +64 -0
  217. package/src/__tests__/api.list-images-filters.test.ts +103 -0
  218. package/src/__tests__/api.test.ts +470 -0
  219. package/src/__tests__/audio.test.ts +65 -0
  220. package/src/__tests__/cast.test.ts +95 -0
  221. package/src/__tests__/castProjection.test.ts +167 -0
  222. package/src/__tests__/chat-auth.test.ts +91 -0
  223. package/src/__tests__/conversation/controller.test.ts +697 -0
  224. package/src/__tests__/conversation/effectiveModel.test.ts +169 -0
  225. package/src/__tests__/conversation/headlessRenderer.ts +46 -0
  226. package/src/__tests__/conversation/presenceBus.test.ts +236 -0
  227. package/src/__tests__/conversation/presenceRegistry.test.ts +73 -0
  228. package/src/__tests__/conversation/roster.test.ts +100 -0
  229. package/src/__tests__/conversation/rosterProjection.test.ts +142 -0
  230. package/src/__tests__/conversation/router.test.ts +81 -0
  231. package/src/__tests__/conversation/runtime.test.ts +206 -0
  232. package/src/__tests__/conversation/voice.test.ts +440 -0
  233. package/src/__tests__/documents.test.ts +360 -0
  234. package/src/__tests__/graphSchema.test.ts +326 -0
  235. package/src/__tests__/longLiveCommandDispatcher.test.ts +185 -0
  236. package/src/__tests__/platformAssistant.test.ts +484 -0
  237. package/src/__tests__/reactor/applyScenePrompt.test.ts +192 -0
  238. package/src/__tests__/reactor/heliosCommandDispatcher.test.ts +4 -3
  239. package/src/__tests__/reactor/sceneEntry.test.ts +134 -10
  240. package/src/__tests__/reactor/seedImageOrchestrator.test.ts +51 -16
  241. package/src/__tests__/reactor/storyTimeline.test.ts +186 -0
  242. package/src/__tests__/regeneration.test.ts +486 -0
  243. package/src/__tests__/stories.test.ts +171 -0
  244. package/src/__tests__/storyGraph.test.ts +134 -0
  245. package/src/__tests__/timeFormat.test.ts +22 -1
  246. package/src/__tests__/toolSchemas.test.ts +57 -0
  247. package/src/__tests__/tools-wrappers.test.ts +272 -0
  248. package/src/__tests__/videoGraph.test.ts +94 -0
  249. package/src/__tests__/websocket-vision.test.ts +265 -0
  250. package/src/__tests__/websocket.test.ts +213 -0
  251. package/src/adapters/capabilities.ts +24 -0
  252. package/src/adapters/chatAdapter.ts +114 -0
  253. package/src/adapters/directorAdapter.ts +126 -0
  254. package/src/adapters/imageAdapter.ts +100 -0
  255. package/src/adapters/index.ts +67 -0
  256. package/src/adapters/registry.ts +159 -0
  257. package/src/adapters/worldAdapter.ts +272 -0
  258. package/src/admin.ts +310 -0
  259. package/src/api.ts +1890 -162
  260. package/src/audio.ts +35 -0
  261. package/src/castProjection.ts +95 -0
  262. package/src/conversation/binding.ts +81 -0
  263. package/src/conversation/controller.ts +439 -0
  264. package/src/conversation/effectiveModel.ts +111 -0
  265. package/src/conversation/index.ts +27 -0
  266. package/src/conversation/participant.ts +71 -0
  267. package/src/conversation/presence.ts +60 -0
  268. package/src/conversation/presenceBus.ts +109 -0
  269. package/src/conversation/presenceRegistry.ts +83 -0
  270. package/src/conversation/roster.ts +111 -0
  271. package/src/conversation/rosterProjection.ts +98 -0
  272. package/src/conversation/router.ts +96 -0
  273. package/src/conversation/runtime.ts +188 -0
  274. package/src/conversation/types.ts +100 -0
  275. package/src/conversation/voice.ts +402 -0
  276. package/src/graphSchema.ts +532 -0
  277. package/src/http.ts +72 -0
  278. package/src/index.ts +12 -0
  279. package/src/platformAssistant.ts +347 -0
  280. package/src/reactor/abortUtils.ts +22 -0
  281. package/src/reactor/applyScenePrompt.ts +136 -0
  282. package/src/reactor/chunkDistribution.ts +98 -0
  283. package/src/reactor/heliosCommandDispatcher.ts +10 -18
  284. package/src/reactor/index.ts +7 -0
  285. package/src/reactor/longLiveCommandDispatcher.ts +156 -0
  286. package/src/reactor/sceneEntry.ts +104 -33
  287. package/src/reactor/scenesFromEnrichment.ts +11 -76
  288. package/src/reactor/seedImageOrchestrator.ts +200 -4
  289. package/src/reactor/storyTimeline.ts +127 -0
  290. package/src/storyGraph.ts +298 -0
  291. package/src/timeFormat.ts +13 -0
  292. package/src/toolSchemas.ts +225 -0
  293. package/src/vision/VisionPublisher.ts +553 -0
  294. package/src/vision/VisionSourceController.ts +354 -0
  295. package/src/vision/__tests__/VisionPublisher.kvs.test.ts +244 -0
  296. package/src/vision/__tests__/VisionPublisher.test.ts +301 -0
  297. package/src/vision/__tests__/VisionSourceController.test.ts +719 -0
  298. package/src/vision/__tests__/startVisionPublisher.test.ts +251 -0
  299. package/src/vision/__tests__/toVisionRtcCredentials.test.ts +113 -0
  300. package/src/vision/__tests__/visionScheduler.test.ts +149 -0
  301. package/src/vision/credentials.ts +39 -0
  302. package/src/vision/index.ts +44 -0
  303. package/src/vision/sourceKinds.ts +75 -0
  304. package/src/vision/startVisionPublisher.ts +64 -0
  305. package/src/vision/types.ts +101 -0
  306. package/src/vision/visionScheduler.ts +102 -0
  307. package/src/websocket.ts +334 -4
@@ -0,0 +1,172 @@
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 { turnChangedSpeakerId, resolvePersonaPill } from './router.js';
24
+ import { shouldRefreshAdventureRail } from './roster.js';
25
+ export class ConversationRuntime {
26
+ state;
27
+ adventureSessionId;
28
+ listeners = new Set();
29
+ constructor(opts = {}) {
30
+ this.adventureSessionId = opts.adventureSessionId;
31
+ this.state = Object.freeze({
32
+ participants: Object.freeze([...(opts.participants ?? [])]),
33
+ activePersonaId: opts.boundPersonaId ?? null,
34
+ previousPersonaId: null,
35
+ busy: false,
36
+ inFlightPersonaId: null,
37
+ lastFinalizedPill: null,
38
+ staleAdventureState: false,
39
+ });
40
+ }
41
+ /** Current immutable snapshot. A new object per actual transition, so hosts
42
+ * can use reference equality for change detection. */
43
+ getState() {
44
+ return this.state;
45
+ }
46
+ /**
47
+ * Subscribe to state transitions. The listener fires only when a transition
48
+ * actually changed the state (never on no-op frames). Returns an
49
+ * unsubscribe function. A throwing listener is isolated (logged via
50
+ * `console.error`) so it cannot break sibling listeners — mirrors the
51
+ * observer discipline of the R2.1 controller's typed callback seam.
52
+ */
53
+ subscribe(listener) {
54
+ this.listeners.add(listener);
55
+ return () => {
56
+ this.listeners.delete(listener);
57
+ };
58
+ }
59
+ /**
60
+ * Reduce one incoming chat frame into the state. Pure per-frame transition —
61
+ * no network, no timers, no DOM. Unknown/irrelevant frame types are no-ops.
62
+ */
63
+ applyFrame(event) {
64
+ switch (event.type) {
65
+ case 'turn_changed': {
66
+ // The ONLY way the speaker moves: the server's turn_changed, gated on
67
+ // an active adventure (the client never self-routes — land-dark).
68
+ const speakerId = turnChangedSpeakerId(event, this.adventureSessionId);
69
+ if (speakerId !== null && speakerId !== this.state.activePersonaId) {
70
+ this.transition({
71
+ previousPersonaId: this.state.activePersonaId,
72
+ activePersonaId: speakerId,
73
+ });
74
+ }
75
+ return;
76
+ }
77
+ case 'token': {
78
+ // Streaming started/continuing; capture the orchestrator's persona
79
+ // stamp (M10 9a) for in-flight message attribution. Ordinary-chat
80
+ // tokens carry no personaId ⇒ attribution stays null (land-dark).
81
+ this.transition({
82
+ busy: true,
83
+ ...(event.personaId ? { inFlightPersonaId: event.personaId } : {}),
84
+ });
85
+ return;
86
+ }
87
+ case 'tool_use': {
88
+ this.transition({ busy: true });
89
+ return;
90
+ }
91
+ case 'done': {
92
+ // Finalize the streamed message: resolve its persona pill against the
93
+ // roster (null when unattributed — every ordinary-chat bubble).
94
+ const pillSource = this.state.inFlightPersonaId ?? event.personaId;
95
+ const pill = resolvePersonaPill(pillSource ?? undefined, this.state.participants.map((p) => ({
96
+ persona_id: p.personaId,
97
+ name: p.displayName,
98
+ })));
99
+ this.transition({
100
+ busy: false,
101
+ inFlightPersonaId: null,
102
+ lastFinalizedPill: pill,
103
+ });
104
+ return;
105
+ }
106
+ case 'error': {
107
+ this.transition({ busy: false, inFlightPersonaId: null });
108
+ return;
109
+ }
110
+ case 'tool_result': {
111
+ // The single land-dark gate on adventure-state refresh: active
112
+ // adventure AND a DM mutation tool. Anything else is a no-op.
113
+ if (shouldRefreshAdventureRail(this.adventureSessionId, event.tool)) {
114
+ this.transition({ staleAdventureState: true });
115
+ }
116
+ return;
117
+ }
118
+ default:
119
+ // citation/image/audio/transcript/heartbeat/… carry no runtime state.
120
+ return;
121
+ }
122
+ }
123
+ /**
124
+ * Host-driven turn release (R7.2, ADDITIVE): the host removed `personaId`
125
+ * from the party while it held the turn, so it loses the floor —
126
+ * `activePersonaId` returns to null until the server's next `turn_changed`.
127
+ * No-op when `personaId` is not the active speaker. This is the ONLY
128
+ * host-driven speaker transition (roster changes are a host concern, see
129
+ * `ConversationRuntimeState.participants`); a server `turn_changed` frame
130
+ * remains the only way the speaker MOVES to a persona (never self-routing).
131
+ */
132
+ releaseTurn(personaId) {
133
+ if (this.state.activePersonaId === personaId) {
134
+ this.transition({
135
+ previousPersonaId: this.state.activePersonaId,
136
+ activePersonaId: null,
137
+ });
138
+ }
139
+ }
140
+ /**
141
+ * The host re-fetched the server-authoritative `AdventureState`; clear the
142
+ * stale flag set by a DM mutation `tool_result`.
143
+ */
144
+ acknowledgeAdventureState() {
145
+ if (this.state.staleAdventureState) {
146
+ this.transition({ staleAdventureState: false });
147
+ }
148
+ }
149
+ /** Apply a partial update; notify listeners only when something changed. */
150
+ transition(patch) {
151
+ let changed = false;
152
+ for (const key of Object.keys(patch)) {
153
+ if (!Object.is(patch[key], this.state[key])) {
154
+ changed = true;
155
+ break;
156
+ }
157
+ }
158
+ if (!changed)
159
+ return;
160
+ this.state = Object.freeze({ ...this.state, ...patch });
161
+ for (const listener of this.listeners) {
162
+ try {
163
+ listener(this.state);
164
+ }
165
+ catch (err) {
166
+ // Isolate listener faults so one bad subscriber can't break siblings.
167
+ console.error('ConversationRuntime listener threw', err);
168
+ }
169
+ }
170
+ }
171
+ }
172
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime.js","sourceRoot":"","sources":["../../src/conversation/runtime.ts"],"names":[],"mappings":"AAAA;;;;;;;;;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C,OAAO,GAAG,IAAI,CAAC;gBACf,MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,CAAC,OAAO;YAAE,OAAO;QAErB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;QACxD,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACtC,IAAI,CAAC;gBACH,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,sEAAsE;gBACtE,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,GAAG,CAAC,CAAC;YAC3D,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Types for the `ConversationRuntime` reducer (R7.1).
3
+ *
4
+ * The presence vocabulary is NOT re-declared here: `PresenceKind` and its
5
+ * `PRESENCE_*` members already live on `conversation/participant.ts` (R2.1)
6
+ * and are imported — re-exporting them from this module would create the
7
+ * documented ESM ambiguous-export collision in the `export *` barrels (see
8
+ * `src/index.ts` collision warning). Likewise the runtime state type is
9
+ * `ConversationRuntimeState` (not `ConversationState`) to keep the name
10
+ * unambiguous next to the R2.1 controller's `ConversationSnapshot`.
11
+ */
12
+ import type { PresenceKind } from './participant';
13
+ /**
14
+ * One persona seat in the conversation roster, as the RUNTIME sees it (R7.1).
15
+ * This is the renderer-facing projection — keyed by `personaId` because every
16
+ * chat frame attributes by persona id (`ChatWsEvent.personaId`,
17
+ * `turn_changed.personaId`). The R2.1 `ConversationParticipant` remains the
18
+ * controller's seat model (keyed by `participantId`, carries model binding);
19
+ * this type carries only what a presence renderer / transcript needs.
20
+ */
21
+ export interface RosterParticipant {
22
+ /** The persona id chat frames attribute to (`personaId` on `ChatWsEvent`). */
23
+ personaId: string;
24
+ /** True for the Dungeon Master seat. */
25
+ isDm: boolean;
26
+ /** Display name for transcript pills and roster chips. */
27
+ displayName: string;
28
+ /** Bound character entity id, when the persona portrays a story character. */
29
+ entityId?: string;
30
+ /** How this participant renders on the presence stage (R2.1 vocabulary). */
31
+ presence: PresenceKind;
32
+ }
33
+ /**
34
+ * The renderer-agnostic state snapshot `ConversationRuntime` produces. A new
35
+ * (frozen-by-convention) object is created per transition; listeners are
36
+ * notified only when a transition actually changed something, so a host can
37
+ * use reference equality for change detection.
38
+ */
39
+ export interface ConversationRuntimeState {
40
+ /** The roster, as constructed. The runtime never mutates membership —
41
+ * roster changes are a host concern (re-construct or future additive API). */
42
+ participants: readonly RosterParticipant[];
43
+ /**
44
+ * The persona currently holding the turn. Starts as the bound/DM persona and
45
+ * ONLY ever moves on a server `turn_changed` frame while an adventure is
46
+ * active (`turnChangedSpeakerId` gate) — the client never self-routes.
47
+ * LAND-DARK: in ordinary chat / single-DM adventures no `turn_changed` ever
48
+ * arrives, so this stays the bound persona forever.
49
+ */
50
+ activePersonaId: string | null;
51
+ /** The persona that held the turn before the last swap (null until a swap). */
52
+ previousPersonaId: string | null;
53
+ /** True while an assistant reply is streaming (token/tool_use → done/error). */
54
+ busy: boolean;
55
+ /**
56
+ * Persona attribution of the in-flight (streaming) assistant message,
57
+ * captured off the first frame carrying a `personaId` (M10 9a orchestrator
58
+ * stamp). Null for ordinary chat — those frames never carry one (land-dark).
59
+ */
60
+ inFlightPersonaId: string | null;
61
+ /**
62
+ * The persona pill of the most recently finalized assistant message
63
+ * (`done` frame), resolved against the roster via `resolvePersonaPill`.
64
+ * Null when the finalized message had no persona attribution (every
65
+ * ordinary-chat bubble — land-dark).
66
+ */
67
+ lastFinalizedPill: {
68
+ personaId: string;
69
+ name: string;
70
+ } | null;
71
+ /**
72
+ * True after a `tool_result` for an `ADVENTURE_MUTATION_TOOLS` member while
73
+ * an adventure is active (`shouldRefreshAdventureRail` gate): the
74
+ * server-authoritative `AdventureState` changed and the host should
75
+ * re-fetch, then call `acknowledgeAdventureState()`.
76
+ */
77
+ staleAdventureState: boolean;
78
+ }
79
+ /** Observer callback for {@link ConversationRuntimeState} transitions. */
80
+ export type ConversationRuntimeListener = (state: ConversationRuntimeState) => void;
81
+ /** Construction options for `ConversationRuntime`. */
82
+ export interface ConversationRuntimeOptions {
83
+ /**
84
+ * The bound/DM persona id — the initial `activePersonaId`. Optional: a
85
+ * persona-less chat starts with `activePersonaId = null` and (land-dark)
86
+ * keeps it there.
87
+ */
88
+ boundPersonaId?: string | null;
89
+ /**
90
+ * The active adventure session id, when in an adventure. Gates BOTH the
91
+ * `turn_changed` speaker swap (`turnChangedSpeakerId`) and the
92
+ * stale-adventure flag (`shouldRefreshAdventureRail`). Undefined for
93
+ * ordinary chat ⇒ neither transition can ever fire (land-dark).
94
+ */
95
+ adventureSessionId?: string;
96
+ /** Initial roster. Defaults to empty; the runtime never mutates it. */
97
+ participants?: readonly RosterParticipant[];
98
+ }
99
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/conversation/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD;;;;;;;GAOG;AACH,MAAM,WAAW,iBAAiB;IAChC,8EAA8E;IAC9E,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,IAAI,EAAE,OAAO,CAAC;IACd,0DAA0D;IAC1D,WAAW,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4EAA4E;IAC5E,QAAQ,EAAE,YAAY,CAAC;CACxB;AAED;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC;mFAC+E;IAC/E,YAAY,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC3C;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B,+EAA+E;IAC/E,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,gFAAgF;IAChF,IAAI,EAAE,OAAO,CAAC;IACd;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC;;;;;OAKG;IACH,iBAAiB,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC9D;;;;;OAKG;IACH,mBAAmB,EAAE,OAAO,CAAC;CAC9B;AAED,0EAA0E;AAC1E,MAAM,MAAM,2BAA2B,GAAG,CAAC,KAAK,EAAE,wBAAwB,KAAK,IAAI,CAAC;AAEpF,sDAAsD;AACtD,MAAM,WAAW,0BAA0B;IACzC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC/B;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,uEAAuE;IACvE,YAAY,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC7C"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Types for the `ConversationRuntime` reducer (R7.1).
3
+ *
4
+ * The presence vocabulary is NOT re-declared here: `PresenceKind` and its
5
+ * `PRESENCE_*` members already live on `conversation/participant.ts` (R2.1)
6
+ * and are imported — re-exporting them from this module would create the
7
+ * documented ESM ambiguous-export collision in the `export *` barrels (see
8
+ * `src/index.ts` collision warning). Likewise the runtime state type is
9
+ * `ConversationRuntimeState` (not `ConversationState`) to keep the name
10
+ * unambiguous next to the R2.1 controller's `ConversationSnapshot`.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/conversation/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * `VoiceSession` (R7.5) — the framework-agnostic voice pipeline for the
3
+ * Conversation overlay.
4
+ *
5
+ * The R2.3/R2.4 Conversation overlay was TEXT-only (the controller's hello is
6
+ * `mode:'text'`; tech-debt #441). R7.5 lifts the FOUR page-owned voice pieces
7
+ * that live inside the 3,000-line `web/app/chat-ws/page.tsx` — the voice-mode
8
+ * `tts_stt` hello, mic capture (STT), audio playback + barge-in (TTS), and
9
+ * viseme scheduling — into ONE module that drives the SAME `ChatWebSocket` the
10
+ * `ConversationController` owns/adopts.
11
+ *
12
+ * DRY: this is a THIN composition, not a re-implementation. The
13
+ * player/viseme/barge-in/sentence-anchoring machinery already lives in
14
+ * `AudioPipeline` (audio.ts) and the hello in the single `buildHelloPayload`.
15
+ * The mic is the existing `MicrophoneRecorder`. `VoiceSession` only owns the
16
+ * lifecycle (the iOS user-gesture priming order, the socket handler wiring, and
17
+ * the dispose contract). There is NO second viseme scheduler, NO second
18
+ * hello-construction site, and NO second sentence-anchoring loop.
19
+ *
20
+ * Viseme delivery: `onViseme` is the SINGLE viseme callback. The React panel
21
+ * routes it into the presence face, which is the React realisation of R7.3's
22
+ * `PresenceAdapter.applyViseme` — visemes reach a face through exactly one path.
23
+ *
24
+ * Socket ownership: `VoiceSession` NEVER closes the socket on `dispose()` — the
25
+ * `ConversationController` (or the surface that owns an adopted socket) manages
26
+ * the transport. This preserves the Watch shared-socket invariant: voice on an
27
+ * adopted socket must not tear down the one `FrameBuffer` vision rides.
28
+ *
29
+ * `/chat-ws` is the parity ORACLE and is NOT rewired by R7.5: its page-owned
30
+ * pipeline stays verbatim, and `buildHello()` here is fixture-diffed against
31
+ * `startVoiceChat()`'s payload so the overlay's `tts_stt` hello is byte-identical.
32
+ */
33
+ import { type HelloPayload } from '../audio';
34
+ import type { AudioFormat } from '../audioProtocol';
35
+ import type { ChatWebSocket } from '../websocket';
36
+ import type { HelloArgs } from './binding';
37
+ import type { VisemeSymbol } from '../visemeScheduler';
38
+ /**
39
+ * The audio knobs `startVoiceChat()` passes into `buildHelloPayload` (page.tsx
40
+ * lines 1829-1858). Context fields (`videoId`/`personaId`/`entityId`/
41
+ * `adventureSessionId`/`partyPersonaIds`/`modelId`) come from `getHelloArgs`,
42
+ * NOT from here — they flow through the single `toHelloArgs` mapper the
43
+ * controller owns. Everything here is a voice-only setting. All optional: an
44
+ * omitted field falls to `buildHelloPayload`'s own default (the one place
45
+ * defaults live), exactly as the page relies on.
46
+ */
47
+ export interface VoiceSessionOptions {
48
+ audioFormat?: AudioFormat;
49
+ enableAudioMarkups?: boolean;
50
+ voiceTemperature?: number;
51
+ speakingRate?: number;
52
+ voiceId?: string;
53
+ ttsModelId?: string;
54
+ systemPrompt?: string;
55
+ systemPromptOverride?: boolean;
56
+ }
57
+ export interface VoiceSessionCallbacks {
58
+ /**
59
+ * The single viseme delivery sink. Receives every scheduled viseme value
60
+ * from the internal `AudioPipeline`'s `VisemeScheduler` and is expected to
61
+ * route it onto a face via R7.3's `PresenceAdapter.applyViseme` (in React,
62
+ * the self-driving panel's presence face). This is the ONLY viseme path.
63
+ */
64
+ onViseme: (viseme: VisemeSymbol) => void;
65
+ /** A final STT transcript of the user's speech (the panel appends a user
66
+ * turn). `final=false` is the interim partial (the live transcript bar). */
67
+ onTranscript?: (text: string, final: boolean) => void;
68
+ /** AI speaking flag transitions (gates the barge-in affordance). */
69
+ onSpeakingChange?: (speaking: boolean) => void;
70
+ /** Human-readable error surfaced to the panel's inline error banner. */
71
+ onError?: (message: string) => void;
72
+ /** Optional human-readable status line (mic priming / streaming / paused). */
73
+ onStatus?: (status: string) => void;
74
+ }
75
+ export interface VoiceSessionConfig extends VoiceSessionCallbacks {
76
+ /**
77
+ * The conversation's `ChatWebSocket` — the SAME one the controller owns or
78
+ * adopted. `VoiceSession` drives hello/audio frames onto it and subscribes
79
+ * to its message/binary streams, but NEVER closes it.
80
+ */
81
+ socket: ChatWebSocket;
82
+ /**
83
+ * Returns the context + active-participant args for the hello (the
84
+ * controller's `toHelloArgs()` spread with the active participant's
85
+ * `personaId`/`modelId`). Called at `start()` time so the hello reflects the
86
+ * live binding. Voice knobs are layered on top from {@link VoiceSessionOptions}.
87
+ */
88
+ getHelloArgs: () => HelloArgs;
89
+ /** The voice-only hello knobs (see {@link VoiceSessionOptions}). */
90
+ voiceOptions?: VoiceSessionOptions;
91
+ }
92
+ /**
93
+ * Drives a full voice round-trip (STT in, TTS + visemes out) over a shared
94
+ * `ChatWebSocket`. Construct one per conversation; dispose it with the
95
+ * conversation. The socket is NOT owned here.
96
+ */
97
+ export declare class VoiceSession {
98
+ private readonly socket;
99
+ private readonly getHelloArgs;
100
+ private readonly voiceOptions;
101
+ private readonly callbacks;
102
+ private pipeline;
103
+ private recorder;
104
+ /** True once `hello_ack` lands — gates outbound mic frames so they are never
105
+ * sent into a server that has not wired up its receive side yet (the page's
106
+ * `audioReadyRef` contract). */
107
+ private audioReady;
108
+ /** True between `start()` and `stop()`/`dispose()`. Gates reconnect re-send. */
109
+ private active;
110
+ private disposed;
111
+ /** The last hello sent, so a reconnect can re-send it (the page's
112
+ * `lastHelloRef`). Exposed via {@link reconnectHello}. */
113
+ private lastHello;
114
+ private readonly messageHandler;
115
+ private readonly binaryHandler;
116
+ constructor(config: VoiceSessionConfig);
117
+ /**
118
+ * Build the voice (`tts_stt`) hello. The SINGLE hello-builder: the context +
119
+ * active-participant args come from `getHelloArgs()` (which itself flows
120
+ * through `toHelloArgs`), the voice knobs from `voiceOptions`, and `mode` is
121
+ * forced to `'tts_stt'` — fed to the one `buildHelloPayload`. NO second
122
+ * construction site. This is the parity oracle target: for identical inputs
123
+ * it is byte-identical to the page's `startVoiceChat()` payload.
124
+ */
125
+ buildHello(): HelloPayload;
126
+ /** True while a voice session is running (between `start()` and stop). */
127
+ get isActive(): boolean;
128
+ /**
129
+ * Start voice. Mirrors `startVoiceChat()` (page.tsx:1770-1873) EXACTLY,
130
+ * including the iOS Safari user-gesture audio-activation order: the
131
+ * `AudioPipeline` (which creates the player's AudioContext) and the
132
+ * `MicrophoneRecorder.prime()` run in the SYNCHRONOUS prefix BEFORE the first
133
+ * await — an async wrapper around these silently breaks Safari mic activation.
134
+ * Callers MUST invoke `start()` from the synchronous prefix of the overlay
135
+ * button's click handler.
136
+ */
137
+ start(): Promise<void>;
138
+ /**
139
+ * Stop voice capture/playback but keep the session reusable. Mirrors the
140
+ * page's `stopVoiceChat()` + `resetAudioState()`. Detaches socket handlers
141
+ * and tears down the audio resources; the socket itself is left OPEN (the
142
+ * owner manages it).
143
+ */
144
+ stop(): void;
145
+ /**
146
+ * Barge-in: interrupt the assistant's current audio. Mirrors the page's
147
+ * `handleInterrupt()` — delegates to the pipeline's `bargeIn()` (which sends
148
+ * the server `barge_in`, clears the player queue + visemes) and flips the
149
+ * speaking flag off. No-op when nothing is playing.
150
+ */
151
+ interrupt(): Promise<void>;
152
+ /**
153
+ * Re-send the voice hello after a socket reconnect, IF a voice session is
154
+ * active. Returns the payload (so a host that owns socket construction can
155
+ * wire this into `ChatWebSocket`'s `onReconnect` option) or `null` when voice
156
+ * is inactive (text reconnect — nothing to re-send). NOTE: it does NOT
157
+ * re-prime the mic/AudioSession (the page does, but that path is iOS-gesture
158
+ * gapped on an event-loop reconnect and requires the host to own socket
159
+ * construction — tracked as a follow-up). The hello re-send alone restores
160
+ * the server-side voice routing for the existing recorder's frames.
161
+ */
162
+ reconnectHello(): HelloPayload | null;
163
+ /**
164
+ * Tear down. Stops audio + detaches handlers, then becomes inert. NEVER
165
+ * closes the socket — the controller / adopting surface owns the transport
166
+ * (the Watch shared-socket invariant). Idempotent.
167
+ */
168
+ dispose(): void;
169
+ /** Tear down audio resources + detach socket handlers, leaving the socket
170
+ * open. Idempotent; mirrors the page's `resetAudioState`. */
171
+ private resetAudio;
172
+ /**
173
+ * Reset per-turn audio state for a new assistant reply. Mirrors the page's
174
+ * new-assistant-turn reset (page.tsx:1244-1251): the pipeline's barge-in /
175
+ * sentence-anchor state (`AudioPipeline.resetTurn`), the player's
176
+ * `playbackOrigin` (so playback positions for the next reply are 0-based), and
177
+ * the viseme scheduler (so a stale tail doesn't bleed into the new turn). The
178
+ * pipeline's `player`/`visemeScheduler` are public readonly handles. No-op
179
+ * before the first `start()` (no pipeline yet).
180
+ */
181
+ private resetTurn;
182
+ private handleMessage;
183
+ private handleBinary;
184
+ }
185
+ //# sourceMappingURL=voice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"voice.d.ts","sourceRoot":"","sources":["../../src/conversation/voice.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAoB,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,WAAW,mBAAmB;IAClC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IACzC;iFAC6E;IAC7E,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACtD,oEAAoE;IACpE,gBAAgB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/C,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