@escapeaihq/client-core 0.49.1 → 0.138.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 (788) hide show
  1. package/README.md +445 -153
  2. package/dist/adapters/capabilities.d.ts +20 -3
  3. package/dist/adapters/capabilities.d.ts.map +1 -1
  4. package/dist/adapters/directorAdapter.d.ts +5 -4
  5. package/dist/adapters/directorAdapter.d.ts.map +1 -1
  6. package/dist/adapters/directorAdapter.js +5 -4
  7. package/dist/adapters/directorAdapter.js.map +1 -1
  8. package/dist/adapters/experienceModelCatalog.d.ts +382 -0
  9. package/dist/adapters/experienceModelCatalog.d.ts.map +1 -0
  10. package/dist/adapters/experienceModelCatalog.js +401 -0
  11. package/dist/adapters/experienceModelCatalog.js.map +1 -0
  12. package/dist/adapters/extractionAdapter.d.ts +81 -0
  13. package/dist/adapters/extractionAdapter.d.ts.map +1 -0
  14. package/dist/adapters/extractionAdapter.js +98 -0
  15. package/dist/adapters/extractionAdapter.js.map +1 -0
  16. package/dist/adapters/imageAdapter.d.ts +5 -1
  17. package/dist/adapters/imageAdapter.d.ts.map +1 -1
  18. package/dist/adapters/imageAdapter.js +5 -1
  19. package/dist/adapters/imageAdapter.js.map +1 -1
  20. package/dist/adapters/index.d.ts +54 -16
  21. package/dist/adapters/index.d.ts.map +1 -1
  22. package/dist/adapters/index.js +62 -11
  23. package/dist/adapters/index.js.map +1 -1
  24. package/dist/adapters/momentDirective.d.ts +66 -0
  25. package/dist/adapters/momentDirective.d.ts.map +1 -0
  26. package/dist/adapters/momentDirective.js +78 -0
  27. package/dist/adapters/momentDirective.js.map +1 -0
  28. package/dist/adapters/momentPolicy.d.ts +132 -0
  29. package/dist/adapters/momentPolicy.d.ts.map +1 -0
  30. package/dist/adapters/momentPolicy.js +165 -0
  31. package/dist/adapters/momentPolicy.js.map +1 -0
  32. package/dist/adapters/registry.d.ts +1 -1
  33. package/dist/adapters/registry.d.ts.map +1 -1
  34. package/dist/adapters/videoGenAdapter.d.ts +55 -0
  35. package/dist/adapters/videoGenAdapter.d.ts.map +1 -0
  36. package/dist/adapters/videoGenAdapter.js +78 -0
  37. package/dist/adapters/videoGenAdapter.js.map +1 -0
  38. package/dist/adapters/worldAdapter.d.ts +132 -11
  39. package/dist/adapters/worldAdapter.d.ts.map +1 -1
  40. package/dist/adapters/worldAdapter.js +127 -11
  41. package/dist/adapters/worldAdapter.js.map +1 -1
  42. package/dist/adapters/worldModelPreference.d.ts +173 -0
  43. package/dist/adapters/worldModelPreference.d.ts.map +1 -0
  44. package/dist/adapters/worldModelPreference.js +209 -0
  45. package/dist/adapters/worldModelPreference.js.map +1 -0
  46. package/dist/adapters/worldModelTradeoffs.d.ts +120 -0
  47. package/dist/adapters/worldModelTradeoffs.d.ts.map +1 -0
  48. package/dist/adapters/worldModelTradeoffs.js +154 -0
  49. package/dist/adapters/worldModelTradeoffs.js.map +1 -0
  50. package/dist/admin.d.ts +545 -0
  51. package/dist/admin.d.ts.map +1 -1
  52. package/dist/admin.js +230 -16
  53. package/dist/admin.js.map +1 -1
  54. package/dist/api.d.ts +10281 -2216
  55. package/dist/api.d.ts.map +1 -1
  56. package/dist/api.js +4174 -1240
  57. package/dist/api.js.map +1 -1
  58. package/dist/arcBoardJoin.d.ts +38 -0
  59. package/dist/arcBoardJoin.d.ts.map +1 -0
  60. package/dist/arcBoardJoin.js +37 -0
  61. package/dist/arcBoardJoin.js.map +1 -0
  62. package/dist/arcPreview.d.ts +49 -0
  63. package/dist/arcPreview.d.ts.map +1 -0
  64. package/dist/arcPreview.js +65 -0
  65. package/dist/arcPreview.js.map +1 -0
  66. package/dist/audio.d.ts +259 -16
  67. package/dist/audio.d.ts.map +1 -1
  68. package/dist/audio.js +605 -114
  69. package/dist/audio.js.map +1 -1
  70. package/dist/audioDsp.d.ts +45 -0
  71. package/dist/audioDsp.d.ts.map +1 -0
  72. package/dist/audioDsp.js +108 -0
  73. package/dist/audioDsp.js.map +1 -0
  74. package/dist/audioProtocol.d.ts +160 -0
  75. package/dist/audioProtocol.d.ts.map +1 -1
  76. package/dist/audioProtocol.js +99 -0
  77. package/dist/audioProtocol.js.map +1 -1
  78. package/dist/beatTitles.d.ts +33 -0
  79. package/dist/beatTitles.d.ts.map +1 -0
  80. package/dist/beatTitles.js +39 -0
  81. package/dist/beatTitles.js.map +1 -0
  82. package/dist/castProjection.d.ts +204 -1
  83. package/dist/castProjection.d.ts.map +1 -1
  84. package/dist/castProjection.js +202 -0
  85. package/dist/castProjection.js.map +1 -1
  86. package/dist/characterGrounding.d.ts +369 -0
  87. package/dist/characterGrounding.d.ts.map +1 -0
  88. package/dist/characterGrounding.js +408 -0
  89. package/dist/characterGrounding.js.map +1 -0
  90. package/dist/conversation/binding.d.ts +41 -1
  91. package/dist/conversation/binding.d.ts.map +1 -1
  92. package/dist/conversation/binding.js +12 -0
  93. package/dist/conversation/binding.js.map +1 -1
  94. package/dist/conversation/chatSessionStore.d.ts +178 -0
  95. package/dist/conversation/chatSessionStore.d.ts.map +1 -0
  96. package/dist/conversation/chatSessionStore.js +196 -0
  97. package/dist/conversation/chatSessionStore.js.map +1 -0
  98. package/dist/conversation/controller.d.ts +60 -0
  99. package/dist/conversation/controller.d.ts.map +1 -1
  100. package/dist/conversation/controller.js +104 -3
  101. package/dist/conversation/controller.js.map +1 -1
  102. package/dist/conversation/index.d.ts +2 -0
  103. package/dist/conversation/index.d.ts.map +1 -1
  104. package/dist/conversation/index.js +2 -0
  105. package/dist/conversation/index.js.map +1 -1
  106. package/dist/conversation/participant.d.ts +16 -0
  107. package/dist/conversation/participant.d.ts.map +1 -1
  108. package/dist/conversation/readSequencer.d.ts +38 -0
  109. package/dist/conversation/readSequencer.d.ts.map +1 -0
  110. package/dist/conversation/readSequencer.js +42 -0
  111. package/dist/conversation/readSequencer.js.map +1 -0
  112. package/dist/conversation/roster.d.ts +5 -1
  113. package/dist/conversation/roster.d.ts.map +1 -1
  114. package/dist/conversation/roster.js.map +1 -1
  115. package/dist/conversation/rosterProjection.d.ts +74 -1
  116. package/dist/conversation/rosterProjection.d.ts.map +1 -1
  117. package/dist/conversation/rosterProjection.js +135 -1
  118. package/dist/conversation/rosterProjection.js.map +1 -1
  119. package/dist/conversation/runtime.d.ts +20 -3
  120. package/dist/conversation/runtime.d.ts.map +1 -1
  121. package/dist/conversation/runtime.js +66 -7
  122. package/dist/conversation/runtime.js.map +1 -1
  123. package/dist/conversation/types.d.ts +43 -4
  124. package/dist/conversation/types.d.ts.map +1 -1
  125. package/dist/conversation/voice.d.ts +290 -13
  126. package/dist/conversation/voice.d.ts.map +1 -1
  127. package/dist/conversation/voice.js +565 -42
  128. package/dist/conversation/voice.js.map +1 -1
  129. package/dist/creatorCuration.d.ts +134 -0
  130. package/dist/creatorCuration.d.ts.map +1 -0
  131. package/dist/creatorCuration.js +228 -0
  132. package/dist/creatorCuration.js.map +1 -0
  133. package/dist/creatorDashboard.d.ts +155 -0
  134. package/dist/creatorDashboard.d.ts.map +1 -0
  135. package/dist/creatorDashboard.js +237 -0
  136. package/dist/creatorDashboard.js.map +1 -0
  137. package/dist/creatorUniverse.d.ts +95 -0
  138. package/dist/creatorUniverse.d.ts.map +1 -0
  139. package/dist/creatorUniverse.js +136 -0
  140. package/dist/creatorUniverse.js.map +1 -0
  141. package/dist/curationWrite.d.ts +76 -0
  142. package/dist/curationWrite.d.ts.map +1 -0
  143. package/dist/curationWrite.js +106 -0
  144. package/dist/curationWrite.js.map +1 -0
  145. package/dist/designTokens.d.ts +64 -0
  146. package/dist/designTokens.d.ts.map +1 -0
  147. package/dist/designTokens.js +117 -0
  148. package/dist/designTokens.js.map +1 -0
  149. package/dist/dialogAttribution.d.ts +79 -0
  150. package/dist/dialogAttribution.d.ts.map +1 -0
  151. package/dist/dialogAttribution.js +144 -0
  152. package/dist/dialogAttribution.js.map +1 -0
  153. package/dist/dmRunWorldReadiness.d.ts +605 -0
  154. package/dist/dmRunWorldReadiness.d.ts.map +1 -0
  155. package/dist/dmRunWorldReadiness.js +775 -0
  156. package/dist/dmRunWorldReadiness.js.map +1 -0
  157. package/dist/domains/access.d.ts +32 -0
  158. package/dist/domains/access.d.ts.map +1 -0
  159. package/dist/domains/access.js +43 -0
  160. package/dist/domains/access.js.map +1 -0
  161. package/dist/domains/adventureDefinitions.d.ts +159 -0
  162. package/dist/domains/adventureDefinitions.d.ts.map +1 -0
  163. package/dist/domains/adventureDefinitions.js +168 -0
  164. package/dist/domains/adventureDefinitions.js.map +1 -0
  165. package/dist/domains/adventures.d.ts +329 -0
  166. package/dist/domains/adventures.d.ts.map +1 -0
  167. package/dist/domains/adventures.js +359 -0
  168. package/dist/domains/adventures.js.map +1 -0
  169. package/dist/domains/arcs.d.ts +146 -0
  170. package/dist/domains/arcs.d.ts.map +1 -0
  171. package/dist/domains/arcs.js +202 -0
  172. package/dist/domains/arcs.js.map +1 -0
  173. package/dist/domains/artifacts.d.ts +259 -0
  174. package/dist/domains/artifacts.d.ts.map +1 -0
  175. package/dist/domains/artifacts.js +125 -0
  176. package/dist/domains/artifacts.js.map +1 -0
  177. package/dist/domains/chat.d.ts +158 -0
  178. package/dist/domains/chat.d.ts.map +1 -0
  179. package/dist/domains/chat.js +224 -0
  180. package/dist/domains/chat.js.map +1 -0
  181. package/dist/domains/decisions.d.ts +31 -0
  182. package/dist/domains/decisions.d.ts.map +1 -0
  183. package/dist/domains/decisions.js +42 -0
  184. package/dist/domains/decisions.js.map +1 -0
  185. package/dist/domains/documents.d.ts +218 -0
  186. package/dist/domains/documents.d.ts.map +1 -0
  187. package/dist/domains/documents.js +252 -0
  188. package/dist/domains/documents.js.map +1 -0
  189. package/dist/domains/enhancements.d.ts +106 -0
  190. package/dist/domains/enhancements.d.ts.map +1 -0
  191. package/dist/domains/enhancements.js +160 -0
  192. package/dist/domains/enhancements.js.map +1 -0
  193. package/dist/domains/graph.d.ts +454 -0
  194. package/dist/domains/graph.d.ts.map +1 -0
  195. package/dist/domains/graph.js +648 -0
  196. package/dist/domains/graph.js.map +1 -0
  197. package/dist/domains/images.d.ts +220 -0
  198. package/dist/domains/images.d.ts.map +1 -0
  199. package/dist/domains/images.js +307 -0
  200. package/dist/domains/images.js.map +1 -0
  201. package/dist/domains/ingestion.d.ts +312 -0
  202. package/dist/domains/ingestion.d.ts.map +1 -0
  203. package/dist/domains/ingestion.js +495 -0
  204. package/dist/domains/ingestion.js.map +1 -0
  205. package/dist/domains/me.d.ts +21 -0
  206. package/dist/domains/me.d.ts.map +1 -0
  207. package/dist/domains/me.js +23 -0
  208. package/dist/domains/me.js.map +1 -0
  209. package/dist/domains/orgs.d.ts +47 -0
  210. package/dist/domains/orgs.d.ts.map +1 -0
  211. package/dist/domains/orgs.js +75 -0
  212. package/dist/domains/orgs.js.map +1 -0
  213. package/dist/domains/personas.d.ts +135 -0
  214. package/dist/domains/personas.d.ts.map +1 -0
  215. package/dist/domains/personas.js +316 -0
  216. package/dist/domains/personas.js.map +1 -0
  217. package/dist/domains/projects.d.ts +53 -0
  218. package/dist/domains/projects.d.ts.map +1 -0
  219. package/dist/domains/projects.js +94 -0
  220. package/dist/domains/projects.js.map +1 -0
  221. package/dist/domains/quests.d.ts +431 -0
  222. package/dist/domains/quests.d.ts.map +1 -0
  223. package/dist/domains/quests.js +61 -0
  224. package/dist/domains/quests.js.map +1 -0
  225. package/dist/domains/reactor.d.ts +98 -0
  226. package/dist/domains/reactor.d.ts.map +1 -0
  227. package/dist/domains/reactor.js +131 -0
  228. package/dist/domains/reactor.js.map +1 -0
  229. package/dist/domains/showcase.d.ts +28 -0
  230. package/dist/domains/showcase.d.ts.map +1 -0
  231. package/dist/domains/showcase.js +28 -0
  232. package/dist/domains/showcase.js.map +1 -0
  233. package/dist/domains/storyboards.d.ts +1253 -0
  234. package/dist/domains/storyboards.d.ts.map +1 -0
  235. package/dist/domains/storyboards.js +781 -0
  236. package/dist/domains/storyboards.js.map +1 -0
  237. package/dist/domains/studioSettings.d.ts +39 -0
  238. package/dist/domains/studioSettings.d.ts.map +1 -0
  239. package/dist/domains/studioSettings.js +80 -0
  240. package/dist/domains/studioSettings.js.map +1 -0
  241. package/dist/domains/universes.d.ts +191 -0
  242. package/dist/domains/universes.d.ts.map +1 -0
  243. package/dist/domains/universes.js +276 -0
  244. package/dist/domains/universes.js.map +1 -0
  245. package/dist/domains/userDefaults.d.ts +18 -0
  246. package/dist/domains/userDefaults.d.ts.map +1 -0
  247. package/dist/domains/userDefaults.js +27 -0
  248. package/dist/domains/userDefaults.js.map +1 -0
  249. package/dist/domains/visemeBundles.d.ts +262 -0
  250. package/dist/domains/visemeBundles.d.ts.map +1 -0
  251. package/dist/domains/visemeBundles.js +373 -0
  252. package/dist/domains/visemeBundles.js.map +1 -0
  253. package/dist/domains/workflows.d.ts +142 -0
  254. package/dist/domains/workflows.d.ts.map +1 -0
  255. package/dist/domains/workflows.js +245 -0
  256. package/dist/domains/workflows.js.map +1 -0
  257. package/dist/enhancementDiff.d.ts +56 -0
  258. package/dist/enhancementDiff.d.ts.map +1 -0
  259. package/dist/enhancementDiff.js +110 -0
  260. package/dist/enhancementDiff.js.map +1 -0
  261. package/dist/generated/contract.d.ts +372 -0
  262. package/dist/generated/contract.d.ts.map +1 -0
  263. package/dist/generated/contract.js +390 -0
  264. package/dist/generated/contract.js.map +1 -0
  265. package/dist/graphSchema.d.ts +36 -5
  266. package/dist/graphSchema.d.ts.map +1 -1
  267. package/dist/graphSchema.js +88 -2
  268. package/dist/graphSchema.js.map +1 -1
  269. package/dist/http.d.ts +70 -1
  270. package/dist/http.d.ts.map +1 -1
  271. package/dist/http.js +263 -11
  272. package/dist/http.js.map +1 -1
  273. package/dist/identity.d.ts +81 -0
  274. package/dist/identity.d.ts.map +1 -0
  275. package/dist/identity.js +65 -0
  276. package/dist/identity.js.map +1 -0
  277. package/dist/index.d.ts +35 -0
  278. package/dist/index.d.ts.map +1 -1
  279. package/dist/index.js +118 -0
  280. package/dist/index.js.map +1 -1
  281. package/dist/messageContent.d.ts +174 -0
  282. package/dist/messageContent.d.ts.map +1 -0
  283. package/dist/messageContent.js +405 -0
  284. package/dist/messageContent.js.map +1 -0
  285. package/dist/mutationEpoch.d.ts +83 -0
  286. package/dist/mutationEpoch.d.ts.map +1 -0
  287. package/dist/mutationEpoch.js +109 -0
  288. package/dist/mutationEpoch.js.map +1 -0
  289. package/dist/obo.d.ts +144 -0
  290. package/dist/obo.d.ts.map +1 -0
  291. package/dist/obo.js +135 -0
  292. package/dist/obo.js.map +1 -0
  293. package/dist/opusTransport.d.ts +113 -0
  294. package/dist/opusTransport.d.ts.map +1 -0
  295. package/dist/opusTransport.js +170 -0
  296. package/dist/opusTransport.js.map +1 -0
  297. package/dist/pagination.d.ts +18 -0
  298. package/dist/pagination.d.ts.map +1 -0
  299. package/dist/pagination.js +26 -0
  300. package/dist/pagination.js.map +1 -0
  301. package/dist/platformAssistant.d.ts +55 -1
  302. package/dist/platformAssistant.d.ts.map +1 -1
  303. package/dist/platformAssistant.js +39 -1
  304. package/dist/platformAssistant.js.map +1 -1
  305. package/dist/pollUtils.d.ts +19 -0
  306. package/dist/pollUtils.d.ts.map +1 -0
  307. package/dist/pollUtils.js +35 -0
  308. package/dist/pollUtils.js.map +1 -0
  309. package/dist/questLog.d.ts +232 -0
  310. package/dist/questLog.d.ts.map +1 -0
  311. package/dist/questLog.js +522 -0
  312. package/dist/questLog.js.map +1 -0
  313. package/dist/reactor/dmDirectiveToExperience.d.ts +300 -0
  314. package/dist/reactor/dmDirectiveToExperience.d.ts.map +1 -0
  315. package/dist/reactor/dmDirectiveToExperience.js +401 -0
  316. package/dist/reactor/dmDirectiveToExperience.js.map +1 -0
  317. package/dist/reactor/dmSceneControlPrompt.d.ts +40 -0
  318. package/dist/reactor/dmSceneControlPrompt.d.ts.map +1 -0
  319. package/dist/reactor/dmSceneControlPrompt.js +145 -0
  320. package/dist/reactor/dmSceneControlPrompt.js.map +1 -0
  321. package/dist/reactor/dmWorldEntry.d.ts +1278 -0
  322. package/dist/reactor/dmWorldEntry.d.ts.map +1 -0
  323. package/dist/reactor/dmWorldEntry.js +1396 -0
  324. package/dist/reactor/dmWorldEntry.js.map +1 -0
  325. package/dist/reactor/framePromptCompaction.d.ts +223 -0
  326. package/dist/reactor/framePromptCompaction.d.ts.map +1 -0
  327. package/dist/reactor/framePromptCompaction.js +393 -0
  328. package/dist/reactor/framePromptCompaction.js.map +1 -0
  329. package/dist/reactor/frameWorldBind.d.ts +86 -0
  330. package/dist/reactor/frameWorldBind.d.ts.map +1 -0
  331. package/dist/reactor/frameWorldBind.js +79 -0
  332. package/dist/reactor/frameWorldBind.js.map +1 -0
  333. package/dist/reactor/happyOysterSeed.d.ts +166 -0
  334. package/dist/reactor/happyOysterSeed.d.ts.map +1 -0
  335. package/dist/reactor/happyOysterSeed.js +233 -0
  336. package/dist/reactor/happyOysterSeed.js.map +1 -0
  337. package/dist/reactor/happyOysterWalk.d.ts +274 -0
  338. package/dist/reactor/happyOysterWalk.d.ts.map +1 -0
  339. package/dist/reactor/happyOysterWalk.js +407 -0
  340. package/dist/reactor/happyOysterWalk.js.map +1 -0
  341. package/dist/reactor/happyOysterWorld.d.ts +718 -0
  342. package/dist/reactor/happyOysterWorld.d.ts.map +1 -0
  343. package/dist/reactor/happyOysterWorld.js +826 -0
  344. package/dist/reactor/happyOysterWorld.js.map +1 -0
  345. package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
  346. package/dist/reactor/heliosCommandDispatcher.js +5 -2
  347. package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
  348. package/dist/reactor/hiddenWorldLifecycle.d.ts +101 -0
  349. package/dist/reactor/hiddenWorldLifecycle.d.ts.map +1 -0
  350. package/dist/reactor/hiddenWorldLifecycle.js +119 -0
  351. package/dist/reactor/hiddenWorldLifecycle.js.map +1 -0
  352. package/dist/reactor/imageCanvas.d.ts +15 -0
  353. package/dist/reactor/imageCanvas.d.ts.map +1 -0
  354. package/dist/reactor/imageCanvas.js +33 -0
  355. package/dist/reactor/imageCanvas.js.map +1 -0
  356. package/dist/reactor/index.d.ts +20 -0
  357. package/dist/reactor/index.d.ts.map +1 -1
  358. package/dist/reactor/index.js +81 -0
  359. package/dist/reactor/index.js.map +1 -1
  360. package/dist/reactor/longLiveCommandDispatcher.d.ts +23 -8
  361. package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -1
  362. package/dist/reactor/longLiveCommandDispatcher.js +16 -4
  363. package/dist/reactor/longLiveCommandDispatcher.js.map +1 -1
  364. package/dist/reactor/longLiveSceneEntry.d.ts +203 -0
  365. package/dist/reactor/longLiveSceneEntry.d.ts.map +1 -0
  366. package/dist/reactor/longLiveSceneEntry.js +280 -0
  367. package/dist/reactor/longLiveSceneEntry.js.map +1 -0
  368. package/dist/reactor/momentCut.d.ts +153 -0
  369. package/dist/reactor/momentCut.d.ts.map +1 -0
  370. package/dist/reactor/momentCut.js +142 -0
  371. package/dist/reactor/momentCut.js.map +1 -0
  372. package/dist/reactor/promptAddonRegistry.d.ts +39 -3
  373. package/dist/reactor/promptAddonRegistry.d.ts.map +1 -1
  374. package/dist/reactor/promptAddonRegistry.js +44 -5
  375. package/dist/reactor/promptAddonRegistry.js.map +1 -1
  376. package/dist/reactor/promptTemplatePreview.d.ts +97 -0
  377. package/dist/reactor/promptTemplatePreview.d.ts.map +1 -0
  378. package/dist/reactor/promptTemplatePreview.js +185 -0
  379. package/dist/reactor/promptTemplatePreview.js.map +1 -0
  380. package/dist/reactor/reactorAvailability.d.ts +80 -0
  381. package/dist/reactor/reactorAvailability.d.ts.map +1 -0
  382. package/dist/reactor/reactorAvailability.js +121 -0
  383. package/dist/reactor/reactorAvailability.js.map +1 -0
  384. package/dist/reactor/reactorSessionRefusal.d.ts +125 -0
  385. package/dist/reactor/reactorSessionRefusal.d.ts.map +1 -0
  386. package/dist/reactor/reactorSessionRefusal.js +197 -0
  387. package/dist/reactor/reactorSessionRefusal.js.map +1 -0
  388. package/dist/reactor/reactorTokenScope.d.ts +47 -0
  389. package/dist/reactor/reactorTokenScope.d.ts.map +1 -0
  390. package/dist/reactor/reactorTokenScope.js +64 -0
  391. package/dist/reactor/reactorTokenScope.js.map +1 -0
  392. package/dist/reactor/resolveDirectorBeats.d.ts +65 -0
  393. package/dist/reactor/resolveDirectorBeats.d.ts.map +1 -0
  394. package/dist/reactor/resolveDirectorBeats.js +86 -0
  395. package/dist/reactor/resolveDirectorBeats.js.map +1 -0
  396. package/dist/reactor/sanaLiveEdit.d.ts +117 -0
  397. package/dist/reactor/sanaLiveEdit.d.ts.map +1 -0
  398. package/dist/reactor/sanaLiveEdit.js +105 -0
  399. package/dist/reactor/sanaLiveEdit.js.map +1 -0
  400. package/dist/reactor/sceneEntry.d.ts +66 -9
  401. package/dist/reactor/sceneEntry.d.ts.map +1 -1
  402. package/dist/reactor/sceneEntry.js +59 -66
  403. package/dist/reactor/sceneEntry.js.map +1 -1
  404. package/dist/reactor/sceneSeedImage.d.ts +199 -0
  405. package/dist/reactor/sceneSeedImage.d.ts.map +1 -0
  406. package/dist/reactor/sceneSeedImage.js +239 -0
  407. package/dist/reactor/sceneSeedImage.js.map +1 -0
  408. package/dist/reactor/seedImageOrchestrator.d.ts +70 -3
  409. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
  410. package/dist/reactor/seedImageOrchestrator.js +92 -28
  411. package/dist/reactor/seedImageOrchestrator.js.map +1 -1
  412. package/dist/reactor/toolPromptAddon.d.ts +37 -28
  413. package/dist/reactor/toolPromptAddon.d.ts.map +1 -1
  414. package/dist/reactor/toolPromptAddon.js +63 -101
  415. package/dist/reactor/toolPromptAddon.js.map +1 -1
  416. package/dist/reactor/worldMintLoop.d.ts +286 -0
  417. package/dist/reactor/worldMintLoop.d.ts.map +1 -0
  418. package/dist/reactor/worldMintLoop.js +381 -0
  419. package/dist/reactor/worldMintLoop.js.map +1 -0
  420. package/dist/reactor/worldSteerOutcome.d.ts +98 -0
  421. package/dist/reactor/worldSteerOutcome.d.ts.map +1 -0
  422. package/dist/reactor/worldSteerOutcome.js +81 -0
  423. package/dist/reactor/worldSteerOutcome.js.map +1 -0
  424. package/dist/retryAfter.d.ts +15 -0
  425. package/dist/retryAfter.d.ts.map +1 -0
  426. package/dist/retryAfter.js +75 -0
  427. package/dist/retryAfter.js.map +1 -0
  428. package/dist/seriesKey.d.ts +31 -0
  429. package/dist/seriesKey.d.ts.map +1 -0
  430. package/dist/seriesKey.js +33 -0
  431. package/dist/seriesKey.js.map +1 -0
  432. package/dist/sessionRefresh.d.ts +135 -0
  433. package/dist/sessionRefresh.d.ts.map +1 -0
  434. package/dist/sessionRefresh.js +215 -0
  435. package/dist/sessionRefresh.js.map +1 -0
  436. package/dist/sharedAudioContext.d.ts +39 -0
  437. package/dist/sharedAudioContext.d.ts.map +1 -0
  438. package/dist/sharedAudioContext.js +63 -0
  439. package/dist/sharedAudioContext.js.map +1 -0
  440. package/dist/singleFlight.d.ts +51 -0
  441. package/dist/singleFlight.d.ts.map +1 -0
  442. package/dist/singleFlight.js +87 -0
  443. package/dist/singleFlight.js.map +1 -0
  444. package/dist/storyGraph.d.ts +83 -0
  445. package/dist/storyGraph.d.ts.map +1 -1
  446. package/dist/storyGraph.js +169 -4
  447. package/dist/storyGraph.js.map +1 -1
  448. package/dist/storyboardMask.d.ts +343 -0
  449. package/dist/storyboardMask.d.ts.map +1 -0
  450. package/dist/storyboardMask.js +505 -0
  451. package/dist/storyboardMask.js.map +1 -0
  452. package/dist/storyboardTimeline.d.ts +93 -0
  453. package/dist/storyboardTimeline.d.ts.map +1 -0
  454. package/dist/storyboardTimeline.js +131 -0
  455. package/dist/storyboardTimeline.js.map +1 -0
  456. package/dist/studioAutomation.d.ts +104 -0
  457. package/dist/studioAutomation.d.ts.map +1 -0
  458. package/dist/studioAutomation.js +178 -0
  459. package/dist/studioAutomation.js.map +1 -0
  460. package/dist/tenantClaim.d.ts +86 -0
  461. package/dist/tenantClaim.d.ts.map +1 -0
  462. package/dist/tenantClaim.js +164 -0
  463. package/dist/tenantClaim.js.map +1 -0
  464. package/dist/timeFormat.d.ts +25 -0
  465. package/dist/timeFormat.d.ts.map +1 -1
  466. package/dist/timeFormat.js +56 -0
  467. package/dist/timeFormat.js.map +1 -1
  468. package/dist/toolSchemas.d.ts +53 -10
  469. package/dist/toolSchemas.d.ts.map +1 -1
  470. package/dist/toolSchemas.js +36 -9
  471. package/dist/toolSchemas.js.map +1 -1
  472. package/dist/transport.d.ts +120 -0
  473. package/dist/transport.d.ts.map +1 -0
  474. package/dist/transport.js +282 -0
  475. package/dist/transport.js.map +1 -0
  476. package/dist/videoGenFacade.d.ts +63 -0
  477. package/dist/videoGenFacade.d.ts.map +1 -0
  478. package/dist/videoGenFacade.js +49 -0
  479. package/dist/videoGenFacade.js.map +1 -0
  480. package/dist/visemeScheduler.d.ts +24 -2
  481. package/dist/visemeScheduler.d.ts.map +1 -1
  482. package/dist/visemeScheduler.js +31 -2
  483. package/dist/visemeScheduler.js.map +1 -1
  484. package/dist/vision/VisionPublisher.d.ts +88 -0
  485. package/dist/vision/VisionPublisher.d.ts.map +1 -1
  486. package/dist/vision/VisionPublisher.js +196 -13
  487. package/dist/vision/VisionPublisher.js.map +1 -1
  488. package/dist/vision/VisionSourceController.d.ts +67 -1
  489. package/dist/vision/VisionSourceController.d.ts.map +1 -1
  490. package/dist/vision/VisionSourceController.js +147 -5
  491. package/dist/vision/VisionSourceController.js.map +1 -1
  492. package/dist/vision/index.d.ts +2 -1
  493. package/dist/vision/index.d.ts.map +1 -1
  494. package/dist/vision/index.js +2 -1
  495. package/dist/vision/index.js.map +1 -1
  496. package/dist/vision/sourceKinds.d.ts +18 -5
  497. package/dist/vision/sourceKinds.d.ts.map +1 -1
  498. package/dist/vision/sourceKinds.js +15 -2
  499. package/dist/vision/sourceKinds.js.map +1 -1
  500. package/dist/vision/types.d.ts +7 -4
  501. package/dist/vision/types.d.ts.map +1 -1
  502. package/dist/vision/visionErrors.d.ts +45 -0
  503. package/dist/vision/visionErrors.d.ts.map +1 -0
  504. package/dist/vision/visionErrors.js +66 -0
  505. package/dist/vision/visionErrors.js.map +1 -0
  506. package/dist/voiceCloneCaption.d.ts +33 -0
  507. package/dist/voiceCloneCaption.d.ts.map +1 -0
  508. package/dist/voiceCloneCaption.js +69 -0
  509. package/dist/voiceCloneCaption.js.map +1 -0
  510. package/dist/websocket.d.ts +390 -10
  511. package/dist/websocket.d.ts.map +1 -1
  512. package/dist/websocket.js +152 -0
  513. package/dist/websocket.js.map +1 -1
  514. package/dist/workflowAuthoring.d.ts +139 -0
  515. package/dist/workflowAuthoring.d.ts.map +1 -0
  516. package/dist/workflowAuthoring.js +557 -0
  517. package/dist/workflowAuthoring.js.map +1 -0
  518. package/package.json +15 -5
  519. package/src/__tests__/adapters-director.test.ts +9 -6
  520. package/src/__tests__/adapters-extraction.test.ts +175 -0
  521. package/src/__tests__/adapters-image.test.ts +66 -0
  522. package/src/__tests__/adapters-momentPolicy.test.ts +218 -0
  523. package/src/__tests__/adapters-platform.test.ts +110 -4
  524. package/src/__tests__/adapters-videogen.test.ts +53 -0
  525. package/src/__tests__/adapters-world.test.ts +117 -7
  526. package/src/__tests__/admin.enhancement-defaults.test.ts +115 -0
  527. package/src/__tests__/admin.test.ts +282 -0
  528. package/src/__tests__/adventures-world-state.test.ts +156 -0
  529. package/src/__tests__/adventures.test.ts +111 -1
  530. package/src/__tests__/api-pollers.test.ts +113 -23
  531. package/src/__tests__/api.adventure-definitions.test.ts +312 -0
  532. package/src/__tests__/api.anchor-beat.test.ts +75 -0
  533. package/src/__tests__/api.arc-approval.test.ts +171 -0
  534. package/src/__tests__/api.arc-beats-floor.test.ts +56 -0
  535. package/src/__tests__/api.arc-generation.test.ts +168 -0
  536. package/src/__tests__/api.arc-templates.test.ts +78 -0
  537. package/src/__tests__/api.assignVideoSeries.test.ts +81 -0
  538. package/src/__tests__/api.cast-frame-choices.test.ts +141 -0
  539. package/src/__tests__/api.cutscene-registry.test.ts +148 -0
  540. package/src/__tests__/api.enhancement-addition-actions.test.ts +137 -0
  541. package/src/__tests__/api.enrichVideo-serialization.test.ts +116 -0
  542. package/src/__tests__/api.extraction-base.test.ts +87 -0
  543. package/src/__tests__/api.generateVideo-cutscene.test.ts +148 -0
  544. package/src/__tests__/api.job-pipeline-stages.test.ts +128 -0
  545. package/src/__tests__/api.list-images-filters.test.ts +6 -3
  546. package/src/__tests__/api.quest-curation.test.ts +169 -0
  547. package/src/__tests__/api.reprocessVideo.test.ts +71 -0
  548. package/src/__tests__/api.scene-split-merge.test.ts +129 -0
  549. package/src/__tests__/api.session-quests.test.ts +184 -0
  550. package/src/__tests__/api.test.ts +122 -0
  551. package/src/__tests__/api.transferSeries.test.ts +114 -0
  552. package/src/__tests__/api.unknown-clusters.test.ts +225 -0
  553. package/src/__tests__/api.uploadVideo-options.test.ts +156 -0
  554. package/src/__tests__/arcPreview.test.ts +71 -0
  555. package/src/__tests__/arcStyleProfile.test.ts +204 -0
  556. package/src/__tests__/artifacts-delete.test.ts +109 -0
  557. package/src/__tests__/audio.test.ts +864 -5
  558. package/src/__tests__/audioDsp.test.ts +196 -0
  559. package/src/__tests__/audioUnavailable.test.ts +43 -0
  560. package/src/__tests__/cast.test.ts +10 -1
  561. package/src/__tests__/castCurationProjection.test.ts +84 -0
  562. package/src/__tests__/castFramePipelinePending.test.ts +171 -0
  563. package/src/__tests__/castProjection.test.ts +497 -5
  564. package/src/__tests__/characterGrounding.test.ts +357 -0
  565. package/src/__tests__/contract.test.ts +97 -0
  566. package/src/__tests__/conversation/binding.test.ts +53 -0
  567. package/src/__tests__/conversation/chatSessionStore.test.ts +243 -0
  568. package/src/__tests__/conversation/controller.test.ts +328 -0
  569. package/src/__tests__/conversation/readSequencer.test.ts +52 -0
  570. package/src/__tests__/conversation/rosterProjection.test.ts +204 -3
  571. package/src/__tests__/conversation/runtime.test.ts +118 -1
  572. package/src/__tests__/conversation/voice.test.ts +741 -7
  573. package/src/__tests__/creatorCuration.test.ts +256 -0
  574. package/src/__tests__/creatorDashboard.test.ts +444 -0
  575. package/src/__tests__/creatorUniverse.test.ts +138 -0
  576. package/src/__tests__/curationWrite.test.ts +179 -0
  577. package/src/__tests__/decisions.test.ts +89 -0
  578. package/src/__tests__/designTokens.test.ts +72 -0
  579. package/src/__tests__/dialogAttribution.test.ts +187 -0
  580. package/src/__tests__/dmDirectiveToExperience.test.ts +198 -0
  581. package/src/__tests__/dmWorldEntry.test.ts +2102 -0
  582. package/src/__tests__/enhancementDiff.test.ts +132 -0
  583. package/src/__tests__/experienceModelCatalog.test.ts +292 -0
  584. package/src/__tests__/extractionStageState.test.ts +67 -0
  585. package/src/__tests__/getVideo.test.ts +95 -0
  586. package/src/__tests__/graphReadAfterWrite.test.ts +211 -0
  587. package/src/__tests__/graphSchema.test.ts +55 -4
  588. package/src/__tests__/happyOysterSeed.test.ts +208 -0
  589. package/src/__tests__/happyOysterWorld.test.ts +1241 -0
  590. package/src/__tests__/happyOysterWorldRefusal.test.ts +224 -0
  591. package/src/__tests__/hiddenWorldLifecycle.test.ts +203 -0
  592. package/src/__tests__/http.session-refresh.test.ts +424 -0
  593. package/src/__tests__/http.test.ts +316 -0
  594. package/src/__tests__/identity.test.ts +132 -0
  595. package/src/__tests__/loadBundleManifest.test.ts +192 -22
  596. package/src/__tests__/longLiveSceneEntry.test.ts +371 -0
  597. package/src/__tests__/me.test.ts +74 -0
  598. package/src/__tests__/messageContent.test.ts +395 -0
  599. package/src/__tests__/momentCut.test.ts +229 -0
  600. package/src/__tests__/mutationEpoch.test.ts +218 -0
  601. package/src/__tests__/obo.test.ts +159 -0
  602. package/src/__tests__/opusTransport.test.ts +182 -0
  603. package/src/__tests__/opusTransportLibopus.test.ts +125 -0
  604. package/src/__tests__/orgs.test.ts +229 -0
  605. package/src/__tests__/persona-generation.test.ts +187 -1
  606. package/src/__tests__/platformAssistant.test.ts +140 -0
  607. package/src/__tests__/projects.test.ts +338 -0
  608. package/src/__tests__/promptTemplatePreview.test.ts +160 -0
  609. package/src/__tests__/reactor/__fixtures__/realFramePromptText.ts +23 -0
  610. package/src/__tests__/reactor/api-reactor.test.ts +60 -21
  611. package/src/__tests__/reactor/framePromptCompaction.test.ts +300 -0
  612. package/src/__tests__/reactor/promptAddonRegistry.test.ts +82 -1
  613. package/src/__tests__/reactor/reactorTokenScope.test.ts +50 -0
  614. package/src/__tests__/reactor/resolveDirectorBeats.test.ts +156 -0
  615. package/src/__tests__/reactor/sceneEntry.test.ts +3 -0
  616. package/src/__tests__/reactor/sceneSeedImage.test.ts +361 -0
  617. package/src/__tests__/reactor/seedImageOrchestrator.test.ts +43 -5
  618. package/src/__tests__/reactor/toolPromptAddon.test.ts +34 -42
  619. package/src/__tests__/reactor-happyOysterWalk.test.ts +294 -0
  620. package/src/__tests__/reactorAvailability.test.ts +217 -0
  621. package/src/__tests__/reactorSessionRefusal.test.ts +189 -0
  622. package/src/__tests__/regeneration.test.ts +9 -9
  623. package/src/__tests__/reprocessBlockedReason.test.ts +30 -0
  624. package/src/__tests__/retryAfter.test.ts +65 -0
  625. package/src/__tests__/roleClaim.test.ts +102 -0
  626. package/src/__tests__/sanaLiveEdit.test.ts +84 -0
  627. package/src/__tests__/seriesKey.test.ts +24 -0
  628. package/src/__tests__/settings-set9.test.ts +238 -0
  629. package/src/__tests__/singleFlight.test.ts +348 -0
  630. package/src/__tests__/storyGraph.test.ts +111 -1
  631. package/src/__tests__/storyboardFrameCutscene.test.ts +115 -0
  632. package/src/__tests__/storyboardMask.test.ts +527 -0
  633. package/src/__tests__/storyboardTimeline.test.ts +228 -0
  634. package/src/__tests__/storyboards.test.ts +639 -0
  635. package/src/__tests__/studioAutomation.test.ts +325 -0
  636. package/src/__tests__/toolSchemas.test.ts +11 -18
  637. package/src/__tests__/transport.test.ts +312 -0
  638. package/src/__tests__/videoGenFacade.test.ts +141 -0
  639. package/src/__tests__/videoGraph.test.ts +43 -1
  640. package/src/__tests__/visemeScheduler.test.ts +55 -1
  641. package/src/__tests__/visibility.test.ts +143 -0
  642. package/src/__tests__/voiceCloneCaption.test.ts +80 -0
  643. package/src/__tests__/voiceFallback.test.ts +55 -0
  644. package/src/__tests__/websocket-error-turn-ended.test.ts +49 -0
  645. package/src/__tests__/websocket-session-attach.test.ts +288 -0
  646. package/src/__tests__/websocket-vision.test.ts +141 -0
  647. package/src/__tests__/websocket.test.ts +75 -1
  648. package/src/__tests__/workflowAuthoring.test.ts +187 -0
  649. package/src/__tests__/workflows.test.ts +640 -0
  650. package/src/__tests__/worldMintLoop.test.ts +448 -0
  651. package/src/__tests__/worldModelPreference.test.ts +302 -0
  652. package/src/__tests__/worldModelTradeoffs.test.ts +89 -0
  653. package/src/__tests__/worldSteerOutcome.test.ts +62 -0
  654. package/src/adapters/capabilities.ts +39 -3
  655. package/src/adapters/directorAdapter.ts +5 -4
  656. package/src/adapters/experienceModelCatalog.ts +538 -0
  657. package/src/adapters/extractionAdapter.ts +150 -0
  658. package/src/adapters/imageAdapter.ts +5 -1
  659. package/src/adapters/index.ts +104 -17
  660. package/src/adapters/momentDirective.ts +109 -0
  661. package/src/adapters/momentPolicy.ts +209 -0
  662. package/src/adapters/registry.ts +1 -1
  663. package/src/adapters/videoGenAdapter.ts +124 -0
  664. package/src/adapters/worldAdapter.ts +221 -16
  665. package/src/adapters/worldModelPreference.ts +247 -0
  666. package/src/adapters/worldModelTradeoffs.ts +247 -0
  667. package/src/admin.ts +842 -16
  668. package/src/api.ts +12670 -3446
  669. package/src/arcBoardJoin.ts +46 -0
  670. package/src/arcPreview.ts +103 -0
  671. package/src/audio.ts +691 -130
  672. package/src/audioDsp.ts +132 -0
  673. package/src/audioProtocol.ts +235 -0
  674. package/src/beatTitles.ts +51 -0
  675. package/src/castProjection.ts +311 -0
  676. package/src/characterGrounding.ts +491 -0
  677. package/src/conversation/binding.ts +53 -1
  678. package/src/conversation/chatSessionStore.ts +281 -0
  679. package/src/conversation/controller.ts +135 -3
  680. package/src/conversation/index.ts +2 -0
  681. package/src/conversation/participant.ts +16 -0
  682. package/src/conversation/readSequencer.ts +55 -0
  683. package/src/conversation/roster.ts +5 -1
  684. package/src/conversation/rosterProjection.ts +166 -2
  685. package/src/conversation/runtime.ts +66 -7
  686. package/src/conversation/types.ts +43 -4
  687. package/src/conversation/voice.ts +655 -51
  688. package/src/creatorCuration.ts +316 -0
  689. package/src/creatorDashboard.ts +344 -0
  690. package/src/creatorUniverse.ts +222 -0
  691. package/src/curationWrite.ts +108 -0
  692. package/src/designTokens.ts +157 -0
  693. package/src/dialogAttribution.ts +182 -0
  694. package/src/dmRunWorldReadiness.ts +1168 -0
  695. package/src/domains/access.ts +92 -0
  696. package/src/domains/adventureDefinitions.ts +313 -0
  697. package/src/domains/adventures.ts +557 -0
  698. package/src/domains/arcs.ts +350 -0
  699. package/src/domains/artifacts.ts +349 -0
  700. package/src/domains/chat.ts +338 -0
  701. package/src/domains/decisions.ts +62 -0
  702. package/src/domains/documents.ts +389 -0
  703. package/src/domains/enhancements.ts +259 -0
  704. package/src/domains/graph.ts +959 -0
  705. package/src/domains/images.ts +451 -0
  706. package/src/domains/ingestion.ts +695 -0
  707. package/src/domains/me.ts +27 -0
  708. package/src/domains/orgs.ts +168 -0
  709. package/src/domains/personas.ts +433 -0
  710. package/src/domains/projects.ts +177 -0
  711. package/src/domains/quests.ts +587 -0
  712. package/src/domains/reactor.ts +163 -0
  713. package/src/domains/showcase.ts +35 -0
  714. package/src/domains/storyboards.ts +1698 -0
  715. package/src/domains/studioSettings.ts +149 -0
  716. package/src/domains/universes.ts +433 -0
  717. package/src/domains/userDefaults.ts +37 -0
  718. package/src/domains/visemeBundles.ts +541 -0
  719. package/src/domains/workflows.ts +376 -0
  720. package/src/enhancementDiff.ts +171 -0
  721. package/src/generated/contract.ts +1011 -0
  722. package/src/graphSchema.ts +154 -6
  723. package/src/http.ts +295 -11
  724. package/src/identity.ts +123 -0
  725. package/src/index.ts +131 -0
  726. package/src/messageContent.ts +500 -0
  727. package/src/mutationEpoch.ts +107 -0
  728. package/src/obo.ts +201 -0
  729. package/src/opusTransport.ts +268 -0
  730. package/src/pagination.ts +29 -0
  731. package/src/platformAssistant.ts +97 -1
  732. package/src/pollUtils.ts +35 -0
  733. package/src/questLog.ts +704 -0
  734. package/src/reactor/dmDirectiveToExperience.ts +636 -0
  735. package/src/reactor/dmSceneControlPrompt.ts +152 -0
  736. package/src/reactor/dmWorldEntry.ts +2226 -0
  737. package/src/reactor/framePromptCompaction.ts +544 -0
  738. package/src/reactor/frameWorldBind.ts +133 -0
  739. package/src/reactor/happyOysterSeed.ts +329 -0
  740. package/src/reactor/happyOysterWalk.ts +541 -0
  741. package/src/reactor/happyOysterWorld.ts +1270 -0
  742. package/src/reactor/heliosCommandDispatcher.ts +5 -1
  743. package/src/reactor/hiddenWorldLifecycle.ts +182 -0
  744. package/src/reactor/imageCanvas.ts +38 -0
  745. package/src/reactor/index.ts +81 -0
  746. package/src/reactor/longLiveCommandDispatcher.ts +23 -8
  747. package/src/reactor/longLiveSceneEntry.ts +409 -0
  748. package/src/reactor/momentCut.ts +219 -0
  749. package/src/reactor/promptAddonRegistry.ts +83 -5
  750. package/src/reactor/promptTemplatePreview.ts +240 -0
  751. package/src/reactor/reactorAvailability.ts +155 -0
  752. package/src/reactor/reactorSessionRefusal.ts +260 -0
  753. package/src/reactor/reactorTokenScope.ts +69 -0
  754. package/src/reactor/resolveDirectorBeats.ts +140 -0
  755. package/src/reactor/sanaLiveEdit.ts +158 -0
  756. package/src/reactor/sceneEntry.ts +106 -88
  757. package/src/reactor/sceneSeedImage.ts +338 -0
  758. package/src/reactor/seedImageOrchestrator.ts +116 -34
  759. package/src/reactor/toolPromptAddon.ts +66 -102
  760. package/src/reactor/worldMintLoop.ts +545 -0
  761. package/src/reactor/worldSteerOutcome.ts +132 -0
  762. package/src/retryAfter.ts +71 -0
  763. package/src/seriesKey.ts +42 -0
  764. package/src/sessionRefresh.ts +237 -0
  765. package/src/sharedAudioContext.ts +67 -0
  766. package/src/singleFlight.ts +91 -0
  767. package/src/storyGraph.ts +247 -4
  768. package/src/storyboardMask.ts +756 -0
  769. package/src/storyboardTimeline.ts +220 -0
  770. package/src/studioAutomation.ts +208 -0
  771. package/src/tenantClaim.ts +170 -0
  772. package/src/timeFormat.ts +51 -0
  773. package/src/toolSchemas.ts +39 -10
  774. package/src/transport.ts +327 -0
  775. package/src/videoGenFacade.ts +90 -0
  776. package/src/visemeScheduler.ts +36 -3
  777. package/src/vision/VisionPublisher.ts +204 -14
  778. package/src/vision/VisionSourceController.ts +187 -6
  779. package/src/vision/__tests__/VisionPublisher.kvs.test.ts +50 -0
  780. package/src/vision/__tests__/VisionPublisher.test.ts +291 -0
  781. package/src/vision/__tests__/VisionSourceController.test.ts +376 -6
  782. package/src/vision/index.ts +5 -1
  783. package/src/vision/sourceKinds.ts +19 -5
  784. package/src/vision/types.ts +7 -4
  785. package/src/vision/visionErrors.ts +70 -0
  786. package/src/voiceCloneCaption.ts +77 -0
  787. package/src/websocket.ts +542 -9
  788. package/src/workflowAuthoring.ts +664 -0
package/src/audio.ts CHANGED
@@ -18,40 +18,28 @@ import {
18
18
  type PlaybackPositionMessage,
19
19
  } from './audioProtocol';
20
20
  import { VisemeScheduler } from './visemeScheduler';
21
+ import { resampleToTarget } from './audioDsp';
22
+ import {
23
+ acquireSharedAudioContext,
24
+ releaseSharedAudioContext,
25
+ } from './sharedAudioContext';
21
26
 
22
27
  const FLOAT_DIVISOR = 32768;
23
28
 
24
- const floatTo16BitPCM = (input: Float32Array): Int16Array => {
25
- const output = new Int16Array(input.length);
26
- for (let i = 0; i < input.length; i += 1) {
27
- const s = Math.max(-1, Math.min(1, input[i]));
28
- output[i] = s < 0 ? s * 32768 : s * 32767;
29
- }
30
- return output;
31
- };
32
-
33
- const resampleToTarget = (
34
- input: Float32Array,
35
- sourceRate: number,
36
- targetRate: number = SAMPLE_RATE,
37
- ): Int16Array => {
38
- if (sourceRate === targetRate) {
39
- return floatTo16BitPCM(input);
40
- }
41
-
42
- const ratio = targetRate / sourceRate;
43
- const targetLength = Math.round(input.length * ratio);
44
- const output = new Float32Array(targetLength);
45
-
46
- for (let i = 0; i < targetLength; i += 1) {
47
- const origin = i / ratio;
48
- const index = Math.floor(origin);
49
- const nextIndex = Math.min(index + 1, input.length - 1);
50
- const weight = origin - index;
51
- output[i] = input[index] * (1 - weight) + input[nextIndex] * weight;
52
- }
53
-
54
- return floatTo16BitPCM(output);
29
+ /**
30
+ * The ONE mic-capture constraint set (AU.3). `echoCancellation: true` is
31
+ * LOAD-BEARING for auto barge-in: the server treats any Deepgram
32
+ * `StartOfTurn` during assistant speech as the user interrupting, so the
33
+ * persona's own TTS leaking into the mic would self-trigger barge-ins.
34
+ * Pinned by a unit test — do not weaken without re-testing auto barge-in
35
+ * on speakerphone/laptop-speaker setups.
36
+ */
37
+ export const MIC_AUDIO_CONSTRAINTS: MediaTrackConstraints = {
38
+ echoCancellation: true,
39
+ noiseSuppression: true,
40
+ channelCount: 1,
41
+ sampleRate: SAMPLE_RATE,
42
+ sampleSize: BYTES_PER_SAMPLE * 8,
55
43
  };
56
44
 
57
45
  export class MicrophoneRecorder {
@@ -81,11 +69,12 @@ export class MicrophoneRecorder {
81
69
  * `start()`'s own internal `prime()` runs after the gesture has
82
70
  * unwound and iOS leaves the context in `suspended` state.
83
71
  *
84
- * No I/O, no awaits, no permission prompts — just `new AudioContext`
85
- * and a fire-and-forget `resume()`. */
72
+ * No I/O, no awaits, no permission prompts — just an acquire of the shared
73
+ * page-singleton context (AU.2a: iOS caps a page at 4 live AudioContexts;
74
+ * the recorder and player now SHARE one) and a fire-and-forget `resume()`. */
86
75
  prime(): void {
87
76
  if (this.audioContext) return;
88
- this.audioContext = new AudioContext({ sampleRate: SAMPLE_RATE });
77
+ this.audioContext = acquireSharedAudioContext();
89
78
  void this.audioContext.resume();
90
79
  }
91
80
 
@@ -107,20 +96,14 @@ export class MicrophoneRecorder {
107
96
 
108
97
  try {
109
98
  this.mediaStream = await navigator.mediaDevices.getUserMedia({
110
- audio: {
111
- echoCancellation: true,
112
- noiseSuppression: true,
113
- channelCount: 1,
114
- sampleRate: SAMPLE_RATE,
115
- sampleSize: BYTES_PER_SAMPLE * 8,
116
- },
99
+ audio: MIC_AUDIO_CONSTRAINTS,
117
100
  });
118
101
  } catch (err) {
119
- // Tear down the context we just created (or that was primed) so a
120
- // permission denial doesn't leave a dangling suspended context
121
- // behind, and so a retry from a fresh user gesture starts clean.
102
+ // Release our hold on the shared context so a permission denial
103
+ // doesn't leak a refcount, and a retry from a fresh user gesture
104
+ // starts clean (the singleton itself is retained for reuse — AU.2a).
122
105
  if (this.audioContext) {
123
- void this.audioContext.close();
106
+ releaseSharedAudioContext();
124
107
  this.audioContext = null;
125
108
  }
126
109
  const message = err instanceof Error ? err.message : 'Microphone permission denied';
@@ -149,9 +132,19 @@ export class MicrophoneRecorder {
149
132
 
150
133
  if (useWorklet) {
151
134
  this.workletNode = new AudioWorkletNode(this.audioContext, 'mic-processor');
152
- this.workletNode.port.onmessage = (event: MessageEvent<Float32Array>) => {
135
+ this.workletNode.port.onmessage = (
136
+ event: MessageEvent<Float32Array | Int16Array>,
137
+ ) => {
153
138
  // Guard: worklet message can arrive after stop() has nulled the context
154
139
  if (!this.audioContext) return;
140
+ // AU.2c — an updated worklet processor resamples + anti-alias filters
141
+ // OFF the main thread and posts wire-ready Int16 PCM. A stale cached
142
+ // processor (or a host app serving the old asset) still posts raw
143
+ // Float32 at the context rate; keep the main-thread fallback for it.
144
+ if (event.data instanceof Int16Array) {
145
+ this.enqueueSamples(event.data);
146
+ return;
147
+ }
155
148
  const pcm = resampleToTarget(event.data, this.audioContext.sampleRate);
156
149
  this.enqueueSamples(pcm);
157
150
  };
@@ -198,7 +191,9 @@ export class MicrophoneRecorder {
198
191
  this.source = null;
199
192
  }
200
193
  if (this.audioContext) {
201
- void this.audioContext.close();
194
+ // AU.2a: release the shared singleton (suspended at refcount 0, never
195
+ // closed) instead of closing a per-recorder context.
196
+ releaseSharedAudioContext();
202
197
  this.audioContext = null;
203
198
  }
204
199
  if (this.mediaStream) {
@@ -225,46 +220,229 @@ export class MicrophoneRecorder {
225
220
  }
226
221
  }
227
222
 
223
+ /** Default RMS threshold (normalized 0..1) above which a mic frame counts as
224
+ * voiced. Post-echoCancellation TTS residue and room noise sit well below
225
+ * this; normal speech at conversational distance sits well above. */
226
+ const MIC_VAD_DEFAULT_THRESHOLD = 0.015;
227
+ /** Consecutive voiced frames (20 ms each) required before `speaking` flips
228
+ * true — the AU.3 VAD-assist DEBOUNCE (~100 ms) so clicks/pops don't flash
229
+ * the "listening/interrupting" affordance. */
230
+ const MIC_VAD_DEFAULT_ATTACK_FRAMES = 5;
231
+ /** Consecutive silent frames before `speaking` flips false (~500 ms hangover
232
+ * so natural inter-word gaps don't flicker the affordance). */
233
+ const MIC_VAD_DEFAULT_RELEASE_FRAMES = 25;
234
+
235
+ export interface MicVadOptions {
236
+ threshold?: number;
237
+ attackFrames?: number;
238
+ releaseFrames?: number;
239
+ }
240
+
241
+ /**
242
+ * AU.3 — tiny energy-based voice-activity detector over the outbound mic
243
+ * frames (the same tagged PCM16 frames `MicrophoneRecorder` emits). CLIENT
244
+ * AFFORDANCE ONLY: the authoritative barge-in decision is server-side
245
+ * (Deepgram StartOfTurn); this just debounces a local "the user is speaking"
246
+ * signal so hosts can show a listening/interrupting indicator without a
247
+ * server round-trip. Framework-agnostic, no audio-graph dependency.
248
+ */
249
+ export class MicVad {
250
+ private voicedRun = 0;
251
+
252
+ private silentRun = 0;
253
+
254
+ private isSpeaking = false;
255
+
256
+ private readonly threshold: number;
257
+
258
+ private readonly attackFrames: number;
259
+
260
+ private readonly releaseFrames: number;
261
+
262
+ constructor(
263
+ private readonly onChange: (speaking: boolean) => void,
264
+ options: MicVadOptions = {},
265
+ ) {
266
+ this.threshold = options.threshold ?? MIC_VAD_DEFAULT_THRESHOLD;
267
+ this.attackFrames = options.attackFrames ?? MIC_VAD_DEFAULT_ATTACK_FRAMES;
268
+ this.releaseFrames = options.releaseFrames ?? MIC_VAD_DEFAULT_RELEASE_FRAMES;
269
+ }
270
+
271
+ get speaking(): boolean {
272
+ return this.isSpeaking;
273
+ }
274
+
275
+ /** Feed one outbound mic frame (tag byte + PCM16LE, as produced by
276
+ * `encodeAudioFrame(TAG_MIC, …)`). Fires `onChange` on debounced
277
+ * speech-start/speech-end transitions. */
278
+ push(frame: Uint8Array): void {
279
+ // Skip the 1-byte tag; read aligned PCM16LE samples.
280
+ const byteLength = frame.byteLength - 1;
281
+ const sampleCount = Math.floor(byteLength / 2);
282
+ if (sampleCount <= 0) return;
283
+ const view = new DataView(frame.buffer, frame.byteOffset + 1, sampleCount * 2);
284
+ let sumSquares = 0;
285
+ for (let i = 0; i < sampleCount; i += 1) {
286
+ const s = view.getInt16(i * 2, true) / 32768;
287
+ sumSquares += s * s;
288
+ }
289
+ const rms = Math.sqrt(sumSquares / sampleCount);
290
+ if (rms >= this.threshold) {
291
+ this.voicedRun += 1;
292
+ this.silentRun = 0;
293
+ if (!this.isSpeaking && this.voicedRun >= this.attackFrames) {
294
+ this.isSpeaking = true;
295
+ this.onChange(true);
296
+ }
297
+ } else {
298
+ this.silentRun += 1;
299
+ this.voicedRun = 0;
300
+ if (this.isSpeaking && this.silentRun >= this.releaseFrames) {
301
+ this.isSpeaking = false;
302
+ this.onChange(false);
303
+ }
304
+ }
305
+ }
306
+
307
+ /** Reset all state (session stop/teardown). Fires `onChange(false)` if a
308
+ * speaking run was open so hosts never strand the affordance. */
309
+ reset(): void {
310
+ this.voicedRun = 0;
311
+ this.silentRun = 0;
312
+ if (this.isSpeaking) {
313
+ this.isSpeaking = false;
314
+ this.onChange(false);
315
+ }
316
+ }
317
+ }
318
+
319
+ /**
320
+ * Persona-TTS gain while a visual TAKEOVER owns the surface (§Q DM.1) — a
321
+ * cutscene clip or a HappyOyster world stream. Those play un-muted and carry
322
+ * their own music/SFX mux, so without a duck the DM and the takeover talk over
323
+ * each other at full volume.
324
+ *
325
+ * 0.25 keeps the DM audible under the takeover rather than cutting it: the DM
326
+ * is still narrating the moment, so muting is wrong and full volume is wrong.
327
+ */
328
+ export const AUDIO_TAKEOVER_DUCK_GAIN = 0.25;
329
+
330
+ /**
331
+ * Time constant for the duck ramp, in seconds. A gain step is a click; ~30 ms
332
+ * of `setTargetAtTime` is inaudible as a transition and still fast enough that
333
+ * the duck lands under the takeover's first frame.
334
+ */
335
+ export const AUDIO_DUCK_RAMP_TIME_CONSTANT_S = 0.03;
336
+
228
337
  export class AudioFramePlayer {
229
338
  private context: AudioContext;
230
339
 
231
340
  private gainNode: GainNode;
232
341
 
342
+ /** Current output gain (1 = un-ducked). Tracked as a field because the ramp
343
+ * schedules the value rather than assigning `gain.value`, so the param is
344
+ * not a reliable readback of what was REQUESTED. */
345
+ private duckGain = 1;
346
+
233
347
  private activeSources = new Set<AudioBufferSourceNode>();
234
348
 
235
349
  private queuedTime = 0;
236
350
 
237
- /** Timestamp (AudioContext.currentTime) when the first frame started playing. */
238
- public playbackOrigin = 0;
351
+ /** Internal origin sentinel: `null` = no frame scheduled yet. A `null`
352
+ * sentinel (not `0`) so a legitimate `AudioContext.currentTime` of exactly
353
+ * 0 at first-frame time still counts as initialized (debt internal-#90). */
354
+ private originTime: number | null = null;
239
355
 
240
- /** Start time of the first audio frame in the current chunk.
241
- * Reset each time getChunkStartTime() is called (consumed by viseme scheduler). */
242
- private chunkStartTime = 0;
356
+ /** Timestamp (AudioContext.currentTime) when the first frame started
357
+ * playing; 0 when no frame has played yet.
358
+ *
359
+ * Published-compat accessor pair over the null-sentinel `originTime`:
360
+ * external consumers (e.g. `VoiceSession.resetTurn`) read a plain number
361
+ * and write `0` to mean "reset for the next turn" — the setter maps that
362
+ * reset back onto the internal `null` sentinel. */
363
+ get playbackOrigin(): number {
364
+ return this.originTime ?? 0;
365
+ }
243
366
 
244
- private chunkStartTimeSet = false;
367
+ set playbackOrigin(value: number) {
368
+ this.originTime = value === 0 ? null : value;
369
+ }
370
+
371
+ /** Start time of the first audio frame in the current chunk; `null` = no
372
+ * frame has set it yet (same #90 null-sentinel rationale as `originTime`).
373
+ * Reset each time getChunkStartTime() is called (consumed by viseme scheduler). */
374
+ private chunkStartTime: number | null = null;
375
+
376
+ // ── AU.2b adaptive jitter buffer ──────────────────────────────────────
377
+ // Frames used to be scheduled at `max(currentTime, queuedTime)`: the very
378
+ // first frame of a run started IMMEDIATELY, so any 20–40 ms of network
379
+ // jitter on the next frame produced an audible gap (spec-K Fault B #2).
380
+ // Now every run start (first frame of a turn, or a restart after an
381
+ // underrun) is scheduled `jitterLeadS` in the future, buying that much
382
+ // jitter absorption; steady-state frames still chain at `queuedTime`.
383
+ // Each mid-stream underrun ADAPTIVELY grows the lead (bad network ⇒ more
384
+ // buffer, at the cost of latency), capped at MAX_JITTER_LEAD_S.
385
+ static readonly INITIAL_JITTER_LEAD_S = 0.06;
386
+
387
+ private jitterLeadS = AudioFramePlayer.INITIAL_JITTER_LEAD_S;
388
+
389
+ static readonly JITTER_LEAD_STEP_S = 0.02;
390
+
391
+ static readonly MAX_JITTER_LEAD_S = 0.2;
392
+
393
+ // ── AU.2d AudioBuffer pool ────────────────────────────────────────────
394
+ // TTS frames are fixed-size (SAMPLES_PER_FRAME) at 50 Hz; allocating a
395
+ // fresh AudioBuffer per frame churns ~50 allocations/s through the GC
396
+ // (spec-K Fault B #3). Finished sources return their buffer here for
397
+ // reuse; only exact-size buffers are pooled.
398
+ private bufferPool: AudioBuffer[] = [];
399
+
400
+ private static readonly MAX_POOLED_BUFFERS = 32;
401
+
402
+ /** statechange listener kept as a field so stop() can detach it — the
403
+ * context is the SHARED page singleton (AU.2a), so an orphaned listener
404
+ * from a stopped player must not keep firing. */
405
+ private readonly onStateChange = (): void => {
406
+ if (
407
+ this.context.state === 'running' &&
408
+ this.queuedTime < this.context.currentTime
409
+ ) {
410
+ this.queuedTime = this.context.currentTime;
411
+ }
412
+ };
245
413
 
246
414
  constructor() {
247
- this.context = new AudioContext({ sampleRate: SAMPLE_RATE });
415
+ // AU.2a: acquire the shared page-singleton context (iOS max-4 pool)
416
+ // instead of creating a per-player one.
417
+ this.context = acquireSharedAudioContext();
248
418
  this.gainNode = this.context.createGain();
249
419
  this.gainNode.connect(this.context.destination);
250
420
 
251
421
  // Re-anchor queuedTime on AudioContext resume so post-suspension
252
422
  // frames aren't scheduled in the past (mobile lock screen / tab
253
423
  // background recovery). See docs/features/2026-05-10-audio-pipeline-safety-net.md.
254
- this.context.onstatechange = () => {
255
- if (
256
- this.context.state === 'running' &&
257
- this.queuedTime < this.context.currentTime
258
- ) {
259
- this.queuedTime = this.context.currentTime;
260
- }
261
- };
424
+ // addEventListener (not `onstatechange = …`) because the context is
425
+ // shared — assignment would clobber other listeners on the singleton.
426
+ this.context.addEventListener?.('statechange', this.onStateChange);
262
427
  }
263
428
 
264
- /** Return the playback time elapsed since the first frame was scheduled. */
429
+ /** Return the playback time elapsed since the first frame was scheduled.
430
+ *
431
+ * §Q PLYR.5 — NEVER negative. `originTime` is the *scheduled* start of the
432
+ * turn's first frame, which can sit in the FUTURE, so the raw
433
+ * `currentTime - originTime` can go negative; staging captured a live
434
+ * session streaming `-61.148, -61.052, -60.948…` at ~10 Hz. Until the
435
+ * turn's audio is actually audible, the playhead INTO that turn is 0 —
436
+ * which is what the server's `is_speech_active` / `get_words_spoken_until`
437
+ * arithmetic (`api/chat/ws.py`) needs to stay truthful.
438
+ *
439
+ * §Q PLYR.6 removed the DRIVER of the big negatives (a new turn no longer
440
+ * chains behind the previous turn's backlog — `AudioPipeline.resetTurn`
441
+ * flushes it), leaving only the jitter lead in the future. The clamp stays
442
+ * as the floor: `startTime` is always `>= currentTime` by construction. */
265
443
  getPlaybackTime(): number {
266
- if (this.playbackOrigin === 0) return 0;
267
- return this.context.currentTime - this.playbackOrigin;
444
+ if (this.originTime === null) return 0;
445
+ return Math.max(0, this.context.currentTime - this.originTime);
268
446
  }
269
447
 
270
448
  /**
@@ -272,11 +450,36 @@ export class AudioFramePlayer {
272
450
  * or 0 if no frame has played yet. Used by `AudioPipeline` to convert
273
451
  * absolute chunk start times into the relative coordinate frame the
274
452
  * playback tracker uses for word timestamps.
453
+ *
454
+ * NOTE: a return of 0 is ambiguous (unset vs a legitimate origin of
455
+ * exactly 0). Callers that need to distinguish must use
456
+ * {@link getPlaybackOriginOrNull} — this method stays for the published
457
+ * numeric surface.
275
458
  */
276
459
  getPlaybackOrigin(): number {
277
460
  return this.playbackOrigin;
278
461
  }
279
462
 
463
+ /**
464
+ * Null-aware origin read (debt internal-#90): `null` = no frame has been
465
+ * scheduled yet; a `number` (including a legitimate `0`) = the recorded
466
+ * origin. `AudioPipeline.processAudioMetadata` uses this so an origin of
467
+ * exactly 0 is not conflated with "unset" in the word-timestamp math.
468
+ */
469
+ getPlaybackOriginOrNull(): number | null {
470
+ return this.originTime;
471
+ }
472
+
473
+ /**
474
+ * Explicitly reset the playback origin for a new turn. Preferred over the
475
+ * legacy `playbackOrigin = 0` write (which the setter maps to the same
476
+ * reset) — this name states the intent and cannot collide with a
477
+ * legitimate computed origin of 0.
478
+ */
479
+ resetPlaybackOrigin(): void {
480
+ this.originTime = null;
481
+ }
482
+
280
483
  /** Expose the AudioContext for external time queries. */
281
484
  getContext(): AudioContext {
282
485
  return this.context;
@@ -291,9 +494,8 @@ export class AudioFramePlayer {
291
494
  * Call this from the audio_metadata handler to schedule visemes at the
292
495
  * correct time. Resets after each call so the next chunk gets a fresh start. */
293
496
  getChunkStartTime(): number {
294
- const t = this.chunkStartTime || this.getNextFrameStartTime();
295
- this.chunkStartTime = 0;
296
- this.chunkStartTimeSet = false;
497
+ const t = this.chunkStartTime ?? this.getNextFrameStartTime();
498
+ this.chunkStartTime = null;
297
499
  return t;
298
500
  }
299
501
 
@@ -303,7 +505,7 @@ export class AudioFramePlayer {
303
505
  * without binary, `getChunkStartTime()` falls back to `currentTime`,
304
506
  * which anchors visemes to "now" instead of the actual chunk start. */
305
507
  hasChunkStart(): boolean {
306
- return this.chunkStartTimeSet;
508
+ return this.chunkStartTime !== null;
307
509
  }
308
510
 
309
511
  async resume(): Promise<void> {
@@ -312,6 +514,45 @@ export class AudioFramePlayer {
312
514
  }
313
515
  }
314
516
 
517
+ /**
518
+ * Duck (or restore) persona TTS on the shared output gain — the mix point the
519
+ * player has always owned but never exposed.
520
+ *
521
+ * Hosts call `setDuck(AUDIO_TAKEOVER_DUCK_GAIN)` when a cutscene / world
522
+ * takeover becomes visible and `clearDuck()` when it is dismissed. The duck is
523
+ * a MIX setting, not playback state: it survives `clearQueue()`/`resetTurn()`
524
+ * so a barge-in or a turn boundary mid-takeover cannot silently restore full
525
+ * volume underneath a playing clip.
526
+ *
527
+ * @param gain clamped to `[0, 1]`; a non-finite value is ignored.
528
+ */
529
+ setDuck(gain: number): void {
530
+ if (!Number.isFinite(gain)) return;
531
+ const target = Math.min(1, Math.max(0, gain));
532
+ this.duckGain = target;
533
+ const param = this.gainNode.gain;
534
+ const now = this.context.currentTime;
535
+ // Ramp when the platform offers one; fall back through the schedulers a
536
+ // minimal/mocked AudioParam may implement before assigning outright.
537
+ if (typeof param.setTargetAtTime === 'function') {
538
+ param.setTargetAtTime(target, now, AUDIO_DUCK_RAMP_TIME_CONSTANT_S);
539
+ } else if (typeof param.setValueAtTime === 'function') {
540
+ param.setValueAtTime(target, now);
541
+ } else {
542
+ param.value = target;
543
+ }
544
+ }
545
+
546
+ /** Restore full persona-TTS volume — the takeover was dismissed. */
547
+ clearDuck(): void {
548
+ this.setDuck(1);
549
+ }
550
+
551
+ /** The gain last requested via {@link setDuck} (1 = un-ducked). */
552
+ getDuck(): number {
553
+ return this.duckGain;
554
+ }
555
+
315
556
  /** Immediately silence and stop all scheduled/playing audio. */
316
557
  clearQueue(): void {
317
558
  // Stopping each source is sufficient to silence playback — the
@@ -325,17 +566,37 @@ export class AudioFramePlayer {
325
566
  }
326
567
  this.activeSources.clear();
327
568
  this.queuedTime = this.context.currentTime;
328
- this.playbackOrigin = 0;
329
- this.chunkStartTime = 0;
330
- this.chunkStartTimeSet = false;
569
+ this.originTime = null;
570
+ this.chunkStartTime = null;
331
571
  }
332
572
 
333
573
  async stop(): Promise<void> {
334
574
  // Reuse clearQueue so the source-stop loop only lives in one place,
335
- // then zero out the queuedTime watermark and close the context.
575
+ // then zero out the queuedTime watermark and RELEASE the shared context
576
+ // (AU.2a — suspended at refcount 0, kept for reuse; closing a shared
577
+ // singleton would kill the mic and burn an iOS context slot).
336
578
  this.clearQueue();
337
579
  this.queuedTime = 0;
338
- await this.context.close();
580
+ this.bufferPool = [];
581
+ this.context.removeEventListener?.('statechange', this.onStateChange);
582
+ releaseSharedAudioContext();
583
+ }
584
+
585
+ /** Pop a pooled AudioBuffer of exactly `length` frames, or allocate one. */
586
+ private acquireBuffer(length: number): AudioBuffer {
587
+ const pooled = this.bufferPool.pop();
588
+ if (pooled && pooled.length === length) {
589
+ return pooled;
590
+ }
591
+ // Wrong-size pooled buffer (shouldn't happen — frames are fixed-size):
592
+ // discard it and allocate fresh.
593
+ return this.context.createBuffer(1, length, SAMPLE_RATE);
594
+ }
595
+
596
+ private recycleBuffer(buffer: AudioBuffer): void {
597
+ if (this.bufferPool.length < AudioFramePlayer.MAX_POOLED_BUFFERS) {
598
+ this.bufferPool.push(buffer);
599
+ }
339
600
  }
340
601
 
341
602
  playFrame(data: ArrayBuffer): void {
@@ -344,35 +605,59 @@ export class AudioFramePlayer {
344
605
  return;
345
606
  }
346
607
 
608
+ const buffer = this.acquireBuffer(audio.length);
609
+ // Reuse a scratch Float32Array per frame is not worth it — copyToChannel
610
+ // needs a Float32Array view anyway; the POOLED allocation is the
611
+ // AudioBuffer itself (the expensive audio-graph object, AU.2d).
347
612
  const floatData = new Float32Array(audio.length);
348
613
  for (let i = 0; i < audio.length; i += 1) {
349
614
  floatData[i] = audio[i] / FLOAT_DIVISOR;
350
615
  }
351
-
352
- const buffer = this.context.createBuffer(1, floatData.length, SAMPLE_RATE);
353
616
  buffer.copyToChannel(floatData, 0);
354
617
 
355
618
  const source = this.context.createBufferSource();
356
619
  source.buffer = buffer;
357
620
  source.connect(this.gainNode);
358
621
 
359
- // Track source so barge-in can stop it cleanly
622
+ // Track source so barge-in can stop it cleanly; recycle the buffer once
623
+ // the source finishes (or is stopped by clearQueue — onended fires for
624
+ // both), so steady-state playback allocates zero new AudioBuffers.
360
625
  this.activeSources.add(source);
361
- source.onended = () => this.activeSources.delete(source);
626
+ source.onended = () => {
627
+ this.activeSources.delete(source);
628
+ this.recycleBuffer(buffer);
629
+ };
362
630
 
363
- const startTime = Math.max(this.context.currentTime, this.queuedTime);
631
+ // AU.2b — adaptive jitter buffer. Steady state chains at queuedTime; a
632
+ // run (re)start schedules jitterLeadS ahead so network jitter on the
633
+ // following frames is absorbed instead of gapping. A RESTART of an
634
+ // in-progress turn (originTime already set ⇒ audio had started, but the
635
+ // queue drained before this frame arrived) is an underrun: grow the lead.
636
+ let startTime: number;
637
+ if (this.queuedTime > this.context.currentTime) {
638
+ startTime = this.queuedTime;
639
+ } else {
640
+ if (this.originTime !== null) {
641
+ this.jitterLeadS = Math.min(
642
+ AudioFramePlayer.MAX_JITTER_LEAD_S,
643
+ this.jitterLeadS + AudioFramePlayer.JITTER_LEAD_STEP_S,
644
+ );
645
+ }
646
+ startTime = this.context.currentTime + this.jitterLeadS;
647
+ }
364
648
 
365
- // Record the origin time when the very first frame is scheduled
366
- if (this.playbackOrigin === 0) {
367
- this.playbackOrigin = startTime;
649
+ // Record the origin time when the very first frame is scheduled.
650
+ // Written to the internal field directly (not the setter) so a
651
+ // legitimate startTime of exactly 0 still counts as initialized (#90).
652
+ if (this.originTime === null) {
653
+ this.originTime = startTime;
368
654
  }
369
655
 
370
656
  // Track the start time of the first frame in this chunk.
371
657
  // audio_metadata arrives AFTER the binary frames for the same chunk,
372
658
  // so this captures the correct base time for viseme scheduling.
373
- if (!this.chunkStartTimeSet) {
659
+ if (this.chunkStartTime === null) {
374
660
  this.chunkStartTime = startTime;
375
- this.chunkStartTimeSet = true;
376
661
  }
377
662
 
378
663
  source.start(startTime);
@@ -397,6 +682,7 @@ export const buildHelloPayload = ({
397
682
  entityId,
398
683
  adventureSessionId,
399
684
  partyPersonaIds,
685
+ audioCodecs,
400
686
  }: {
401
687
  videoId?: string;
402
688
  personaId?: string;
@@ -439,6 +725,17 @@ export const buildHelloPayload = ({
439
725
  * Matches `HelloMessage.partyPersonaIds` in `shared/audio_protocol.py`.
440
726
  */
441
727
  partyPersonaIds?: string[];
728
+ /**
729
+ * AU.4 — codecs this client can speak, in preference order (e.g.
730
+ * `['opus', 'pcm16']`). Omit (undefined) to leave the field OFF the hello
731
+ * frame entirely — required against servers that predate the
732
+ * `HelloMessage.audioCodecs` widening (their `extra='forbid'` validation
733
+ * rejects unknown fields), and the land-dark default. Only pass this once
734
+ * the client actually ships an Opus encode/decode path; the negotiated
735
+ * result comes back on `hello_ack.negotiatedCodec`. Matches
736
+ * `HelloMessage.audioCodecs` in `shared/audio_protocol.py`.
737
+ */
738
+ audioCodecs?: string[];
442
739
  }) => ({
443
740
  action: 'hello' as const,
444
741
  version: HELLO_VERSION,
@@ -456,6 +753,7 @@ export const buildHelloPayload = ({
456
753
  ...(entityId ? { entityId } : {}),
457
754
  ...(adventureSessionId ? { adventureSessionId } : {}),
458
755
  ...(partyPersonaIds && partyPersonaIds.length > 0 ? { partyPersonaIds } : {}),
756
+ ...(audioCodecs && audioCodecs.length > 0 ? { audioCodecs } : {}),
459
757
  });
460
758
 
461
759
  export type HelloPayload = ReturnType<typeof buildHelloPayload>;
@@ -694,6 +992,16 @@ export class AudioSessionClient {
694
992
  */
695
993
  const SENTENCE_OVERLAP_EPSILON_S = 0.01;
696
994
 
995
+ /**
996
+ * Cap on the suspended-context frame queue (debt #88 follow-up). Frames are
997
+ * 20 ms each, so 150 ≈ 3 s of audio. While the AudioContext stays suspended
998
+ * (iOS/Chrome pre-gesture — `resume()` can stay pending indefinitely), a
999
+ * streaming reply would otherwise queue UNBOUNDED PCM in memory and then
1000
+ * burst-play the entire stale backlog on a late gesture. Drop-oldest: a very
1001
+ * late resume plays at most the freshest ~3 s instead of minutes-old audio.
1002
+ */
1003
+ const MAX_PENDING_FRAMES = 150;
1004
+
697
1005
  /** Walk a phoneme message from the back, return the last phoneme with
698
1006
  * non-empty `phones`. Returns null only when every word is empty. */
699
1007
  function findLastPhone(words: WordPhonemeInfo[]): PhonemeInfo | null {
@@ -744,16 +1052,101 @@ export class AudioPipeline {
744
1052
  // 20–100 ms forward drift of visemes vs audio.
745
1053
  private pendingMetadata: AudioMetadataMessage[] = [];
746
1054
 
747
- constructor(onVisemeChange: (viseme: string) => void) {
1055
+ // Post-barge inbound-frame latch (AU.1a). `bargeIn()` only silences frames
1056
+ // that were ALREADY scheduled (`clearQueue()` stops active sources) — TTS
1057
+ // frames still in flight from the server arrive AFTER the flush and would
1058
+ // be scheduled and PLAY ("audio buffers still play back on barge-in").
1059
+ // While latched, inbound binary frames + audio_metadata are dropped. The
1060
+ // latch clears on the next turn boundary (`resetTurn()`, driven by the
1061
+ // next final transcript) or on `destroy()`.
1062
+ private barged = false;
1063
+
1064
+ // In-arrival-order event queue for the suspended-context burst (debt #88 +
1065
+ // the AU.2 fold of debt 20260710-suspended-burst-drain…). When the context
1066
+ // is suspended, frames AND audio_metadata are queued TOGETHER in arrival
1067
+ // order and replayed in that order once a SINGLE resume() resolves. The
1068
+ // earlier frames-only queue lost the frame↔metadata interleaving: a burst
1069
+ // spanning multiple chunks drained one metadata per frame landing, so a
1070
+ // later chunk's metadata could anchor to a mid-previous-chunk frame time.
1071
+ // Replaying in arrival order preserves the live-path per-chunk anchoring
1072
+ // (frames re-arm chunkStartTime, the chunk's own metadata consumes it).
1073
+ private pendingEvents: Array<
1074
+ | { kind: 'frame'; data: ArrayBuffer }
1075
+ | { kind: 'metadata'; msg: AudioMetadataMessage }
1076
+ > = [];
1077
+
1078
+ private pendingFrameCount = 0;
1079
+
1080
+ private resumeDrainInFlight = false;
1081
+
1082
+ /** AU.2a — last suspended-state value reported to `onPlaybackSuspended`,
1083
+ * so the callback fires only on transitions. */
1084
+ private suspendedNotified = false;
1085
+
1086
+ private readonly onPlaybackSuspended?: (suspended: boolean) => void;
1087
+
1088
+ constructor(
1089
+ onVisemeChange: (viseme: string) => void,
1090
+ options?: {
1091
+ /**
1092
+ * AU.2a — fired with `true` when TTS frames are piling up behind a
1093
+ * suspended AudioContext (the iOS "mic looks live, audio is silent"
1094
+ * state: reconnect re-armed audio outside a user gesture, so
1095
+ * `resume()` hangs until the next gesture), and with `false` once
1096
+ * playback drains. Hosts use it to show a tap-to-restore overlay whose
1097
+ * tap handler calls {@link resume} synchronously in the gesture.
1098
+ */
1099
+ onPlaybackSuspended?: (suspended: boolean) => void;
1100
+ },
1101
+ ) {
748
1102
  this.player = new AudioFramePlayer();
749
1103
  this.visemeScheduler = new VisemeScheduler(
750
1104
  this.player.getContext(),
751
1105
  onVisemeChange,
752
1106
  );
1107
+ this.onPlaybackSuspended = options?.onPlaybackSuspended;
1108
+ }
1109
+
1110
+ private notifySuspended(suspended: boolean): void {
1111
+ if (this.suspendedNotified === suspended) return;
1112
+ this.suspendedNotified = suspended;
1113
+ this.onPlaybackSuspended?.(suspended);
1114
+ }
1115
+
1116
+ /**
1117
+ * AU.2a — probe the (shared) AudioContext and fire `onPlaybackSuspended`
1118
+ * per its live state. Hosts call this after a reconnect re-arm: on iOS the
1119
+ * gesture-less `resume()` can stay pending forever, so the awaited arm
1120
+ * never returns and only an external probe can surface the tap-to-restore
1121
+ * overlay. Transition-guarded — safe to call repeatedly.
1122
+ */
1123
+ notifyIfSuspended(): void {
1124
+ this.notifySuspended(this.player.getContext().state === 'suspended');
753
1125
  }
754
1126
 
1127
+ /**
1128
+ * Resume the player's (shared) AudioContext and drain any queued
1129
+ * suspended-burst events. Callers restoring audio from a user gesture
1130
+ * (the AU.2a tap-to-restore overlay) MUST call this synchronously inside
1131
+ * the gesture handler — the underlying `resume()` is what iOS gates.
1132
+ */
755
1133
  async resume(): Promise<void> {
756
1134
  await this.player.resume();
1135
+ this.drainPendingEvents();
1136
+ }
1137
+
1138
+ /**
1139
+ * §Q DM.1 — duck persona TTS under a visual takeover (cutscene clip / world
1140
+ * stream). Delegates to {@link AudioFramePlayer.setDuck}; hosts drive the
1141
+ * pipeline, not the player, so this is the surface they reach for.
1142
+ */
1143
+ setDuck(gain: number): void {
1144
+ this.player.setDuck(gain);
1145
+ }
1146
+
1147
+ /** Restore full persona-TTS volume after a takeover is dismissed. */
1148
+ clearDuck(): void {
1149
+ this.player.clearDuck();
757
1150
  }
758
1151
 
759
1152
  /**
@@ -776,52 +1169,147 @@ export class AudioPipeline {
776
1169
  this._sessionClient.setAudioPlayer(this.player);
777
1170
  }
778
1171
 
779
- /** Handle an incoming binary TTS audio frame. */
780
- handleBinaryFrame(data: ArrayBuffer): void {
1172
+ /**
1173
+ * Handle an incoming binary TTS audio frame.
1174
+ *
1175
+ * Returns `true` when the frame was accepted (played or queued for the
1176
+ * resume drain), `false` when it was DROPPED (post-barge latch or closed
1177
+ * context). Consumers use the return to avoid asserting UI state (e.g.
1178
+ * "speaking") for audio that will never play. Additive — existing callers
1179
+ * that ignore the return are unchanged.
1180
+ */
1181
+ handleBinaryFrame(data: ArrayBuffer): boolean {
781
1182
  try {
1183
+ // Post-barge latch: drop in-flight frames for the interrupted reply.
1184
+ // Re-armed by `resetTurn()` at the next turn boundary.
1185
+ if (this.barged) {
1186
+ return false;
1187
+ }
782
1188
  const state = this.player.getContext().state;
783
1189
  // 'closed' shouldn't normally happen here because callers go
784
1190
  // through `destroy()` before letting the context close, but a
785
1191
  // stray frame after a teardown race would crash `playFrame` with
786
1192
  // an InvalidStateError. Drop it explicitly.
787
1193
  if (state === 'closed') {
788
- return;
1194
+ return false;
789
1195
  }
790
- if (state === 'running') {
791
- this.player.playFrame(data);
792
- this.updateTrackerPosition();
793
- this.drainPendingMetadata();
794
- } else {
795
- // Suspended-context path (typical: first frame before any user
796
- // gesture). `playFrame` runs after `resume()` resolves, so a
797
- // synchronous follow-up frame can land first and write
798
- // `chunkStartTimeSet` before this one. This is acceptable
799
- // because the chunk-start anchor is only used for viseme
800
- // scheduling, which receives metadata in the same chunk as
801
- // these frames — the frames within a chunk all share an audio
802
- // source, so a one-frame misattribution at the very start
803
- // produces a viseme drift well under one phoneme. If this ever
804
- // shows up as audible drift, switch to a small in-memory queue
805
- // here that drains in arrival order on resume.
806
- this.player
807
- .resume()
808
- .then(() => {
809
- this.player.playFrame(data);
810
- // Update tracker INSIDE then() so the position read is taken
811
- // after playFrame schedules — outside, we'd write a stale
812
- // position before the frame even reaches the audio graph.
813
- this.updateTrackerPosition();
814
- this.drainPendingMetadata();
815
- })
816
- .catch((err) =>
817
- console.error('[AudioPipeline] Failed to resume audio:', err),
818
- );
1196
+ if (state === 'running' && this.pendingEvents.length === 0) {
1197
+ this.playFrameNow(data);
1198
+ return true;
1199
+ }
1200
+ // Suspended-context path (typical: first frame before any user
1201
+ // gesture) — or a running context whose resume-drain hasn't emptied
1202
+ // the queue yet (ordering: a frame must never jump ahead of queued
1203
+ // predecessors). Queue in arrival order; a single resume() drains
1204
+ // the queue in order when it resolves (debt #88 — the previous
1205
+ // per-frame `.then()` chains raced and could reorder frames).
1206
+ // Bounded drop-oldest so a never-resuming context can't accumulate
1207
+ // unbounded PCM (see MAX_PENDING_FRAMES).
1208
+ this.pendingEvents.push({ kind: 'frame', data });
1209
+ this.pendingFrameCount += 1;
1210
+ this.trimPendingEvents();
1211
+ // AU.2a — a frame stuck behind a suspended context is exactly the
1212
+ // "mic live, audio silent" state; let the host show tap-to-restore.
1213
+ if (state === 'suspended') {
1214
+ this.notifySuspended(true);
1215
+ }
1216
+ if (this.resumeDrainInFlight) {
1217
+ return true;
819
1218
  }
1219
+ this.resumeDrainInFlight = true;
1220
+ this.player
1221
+ .resume()
1222
+ .then(() => {
1223
+ this.resumeDrainInFlight = false;
1224
+ // Drain INSIDE then() so position reads are taken after each
1225
+ // playFrame schedules — outside, we'd write stale positions
1226
+ // before the frames even reach the audio graph.
1227
+ this.drainPendingEvents();
1228
+ })
1229
+ .catch((err) => {
1230
+ this.resumeDrainInFlight = false;
1231
+ // Drop the queued events — parity with the previous per-frame
1232
+ // behavior (a rejected resume() lost that frame). Retaining them
1233
+ // would burst-play a STALE backlog whenever a much-later frame or
1234
+ // gesture finally drains the queue — the very symptom AU.1 fixes.
1235
+ this.clearPendingEvents();
1236
+ console.error('[AudioPipeline] Failed to resume audio:', err);
1237
+ });
1238
+ return true;
820
1239
  } catch (err) {
821
1240
  console.error('[AudioPipeline] Failed to play audio frame:', err);
1241
+ // `false` strictly means "deliberately dropped" (latch/closed). An
1242
+ // unexpected play error is still an ACCEPTED frame — consumers keep
1243
+ // their pre-AU.1 behavior (e.g. asserting "speaking") for it.
1244
+ return true;
822
1245
  }
823
1246
  }
824
1247
 
1248
+ /** Schedule one frame and run the per-frame bookkeeping (tracker + metadata). */
1249
+ private playFrameNow(data: ArrayBuffer): void {
1250
+ this.player.playFrame(data);
1251
+ this.updateTrackerPosition();
1252
+ this.drainPendingMetadata();
1253
+ }
1254
+
1255
+ /** Reset the burst queue + its frame counter (single reset site). */
1256
+ private clearPendingEvents(): void {
1257
+ this.pendingEvents = [];
1258
+ this.pendingFrameCount = 0;
1259
+ }
1260
+
1261
+ /** Drop-oldest cap on queued burst FRAMES (metadata rides along: when a
1262
+ * frame is dropped, any metadata queued BEFORE the next surviving frame
1263
+ * belongs to a dropped chunk and is dropped with it — otherwise the
1264
+ * drain would anchor that stale metadata to the next SURVIVING chunk's
1265
+ * first frame, corrupting visemes/word timestamps; codex P2 on #727). */
1266
+ private trimPendingEvents(): void {
1267
+ if (this.pendingFrameCount <= MAX_PENDING_FRAMES) return;
1268
+ while (this.pendingFrameCount > MAX_PENDING_FRAMES) {
1269
+ const dropped = this.pendingEvents.shift();
1270
+ if (dropped === undefined) {
1271
+ this.pendingFrameCount = 0;
1272
+ break;
1273
+ }
1274
+ if (dropped.kind === 'frame') {
1275
+ this.pendingFrameCount -= 1;
1276
+ }
1277
+ }
1278
+ // Strip metadata now stranded at the front: it followed a dropped frame,
1279
+ // so it describes a dropped chunk. (An ASYNC metadata-first message for
1280
+ // the next surviving chunk is indistinguishable without frame chunk-ids;
1281
+ // in this pathological >3 s-flood path, dropping is the safe choice —
1282
+ // missing visemes beat wrongly-anchored ones.)
1283
+ while (this.pendingEvents[0]?.kind === 'metadata') {
1284
+ this.pendingEvents.shift();
1285
+ }
1286
+ }
1287
+
1288
+ /** Drain queued suspended-burst events in arrival order (debt #88; AU.2
1289
+ * extends the queue to carry metadata too, preserving frame↔metadata
1290
+ * interleaving so multi-chunk bursts anchor each chunk's visemes/word
1291
+ * timestamps at that chunk's own first frame). */
1292
+ private drainPendingEvents(): void {
1293
+ while (this.pendingEvents.length > 0) {
1294
+ // A barge-in may have landed while resume() was in flight — the
1295
+ // queued events belong to the interrupted reply, drop them all.
1296
+ if (this.barged) {
1297
+ this.clearPendingEvents();
1298
+ return;
1299
+ }
1300
+ const event = this.pendingEvents.shift();
1301
+ if (event === undefined) continue;
1302
+ if (event.kind === 'frame') {
1303
+ this.pendingFrameCount -= 1;
1304
+ this.playFrameNow(event.data);
1305
+ } else {
1306
+ this.routeAudioMetadata(event.msg);
1307
+ }
1308
+ }
1309
+ // Queue fully replayed — playback is live again (AU.2a).
1310
+ this.notifySuspended(false);
1311
+ }
1312
+
825
1313
  /**
826
1314
  * Push the current playhead into the session's playback tracker in the
827
1315
  * same coordinate frame everything else uses (relative — elapsed since
@@ -843,7 +1331,29 @@ export class AudioPipeline {
843
1331
  * would fall back to `AudioContext.currentTime`, anchoring visemes ~20–
844
1332
  * 100 ms ahead of the audio. Buffer until a binary frame lands and the
845
1333
  * real chunk start is known. */
846
- handleAudioMetadata(msg: AudioMetadataMessage): void {
1334
+ handleAudioMetadata(msg: AudioMetadataMessage): boolean {
1335
+ // Post-barge latch: metadata for the interrupted reply's audio must not
1336
+ // schedule visemes (its frames are dropped too — see handleBinaryFrame).
1337
+ // Returns false when dropped (same contract as handleBinaryFrame).
1338
+ if (this.barged) {
1339
+ return false;
1340
+ }
1341
+ // Suspended-burst path (AU.2 fold of the multi-chunk anchoring debt):
1342
+ // while frames are queued behind a suspended context, metadata must NOT
1343
+ // bypass them into pendingMetadata — it queues INLINE so the drain
1344
+ // replays the exact arrival interleaving and each chunk's metadata
1345
+ // anchors at that chunk's own first frame.
1346
+ if (this.pendingEvents.length > 0) {
1347
+ this.pendingEvents.push({ kind: 'metadata', msg });
1348
+ return true;
1349
+ }
1350
+ this.routeAudioMetadata(msg);
1351
+ return true;
1352
+ }
1353
+
1354
+ /** Live-path metadata routing: buffer until the chunk's first binary frame
1355
+ * has landed (Inworld ASYNC mode), else process immediately. */
1356
+ private routeAudioMetadata(msg: AudioMetadataMessage): void {
847
1357
  if (!this.player.hasChunkStart()) {
848
1358
  this.pendingMetadata.push(msg);
849
1359
  return;
@@ -879,7 +1389,11 @@ export class AudioPipeline {
879
1389
  // frames), fall back to chunkStartTime so the very-first-chunk math
880
1390
  // still produces a 0-based offset.
881
1391
  if (msg.wordTimestamps?.length && this.sessionClient) {
882
- const origin = this.player.getPlaybackOrigin() || chunkStartTime;
1392
+ // Null-aware read (debt #90): `??` — NOT `||` — so a legitimate
1393
+ // origin of exactly 0 anchors correctly instead of falling back to
1394
+ // this chunk's own start (which would zero out chunkRelativeStart
1395
+ // for every later chunk and mis-anchor all word timestamps).
1396
+ const origin = this.player.getPlaybackOriginOrNull() ?? chunkStartTime;
883
1397
  const chunkRelativeStart = chunkStartTime - origin;
884
1398
  this.sessionClient.addWordTimestamps(
885
1399
  msg.wordTimestamps.map((ts) => ({
@@ -929,11 +1443,36 @@ export class AudioPipeline {
929
1443
  }
930
1444
  }
931
1445
 
932
- /** Reset state for a new conversational turn. */
933
- resetTurn(): void {
1446
+ /**
1447
+ * Clear the turn-scoped buffers/anchors shared by `resetTurn()`,
1448
+ * `bargeIn()`, and `destroy()` — the SINGLE reset site so a future
1449
+ * turn-scoped field can't be cleared in one place and leak in another.
1450
+ * The `barged` latch is deliberately NOT touched here: bargeIn() keeps it
1451
+ * set, resetTurn()/destroy() clear it explicitly.
1452
+ */
1453
+ private clearTurnBuffers(): void {
934
1454
  this.sentenceStartTime = null;
935
1455
  this.lastPhonemeEnd = 0;
936
1456
  this.pendingMetadata = [];
1457
+ this.clearPendingEvents();
1458
+ }
1459
+
1460
+ /** Reset state for a new conversational turn.
1461
+ *
1462
+ * Deliberately does NOT touch the player's queue (§Q PLYR.6, codex P1 on
1463
+ * #1514). Each consumer drives this from its OWN view of the turn boundary
1464
+ * and they disagree about when that is: the Vue surfaces call it on the
1465
+ * `done` frame (`../Web-App` `ai-integration-seer.vue:69`) and on the first
1466
+ * token of a new assistant message (`seer-ai-chat.vue:835`) — `done` lands
1467
+ * while most of that reply's audio is still scheduled, so flushing here
1468
+ * would truncate every reply on those surfaces. The PLYR.6 flush belongs to
1469
+ * the SERVER-authoritative boundary only, and lives in
1470
+ * `VoiceSession.resetTurn()` (driven by `turn_start`), which is the one
1471
+ * caller that knows the queued audio is stale. */
1472
+ resetTurn(): void {
1473
+ this.clearTurnBuffers();
1474
+ // Re-arm playback: the new turn's audio is legitimate.
1475
+ this.barged = false;
937
1476
  this.sessionClient?.resetForNewTurn();
938
1477
  }
939
1478
 
@@ -943,14 +1482,19 @@ export class AudioPipeline {
943
1482
  * When a session is attached, delegates to `AudioSessionClient.bargeIn()`
944
1483
  * which sends the `barge_in` WebSocket action to the server, clears the
945
1484
  * player queue, stops position tracking, and resets the playback tracker.
946
- * Without a session we still clear local audio/visemes so the UI is sane,
947
- * but the server has no way to know — the next chunk it streams will
948
- * resume playback.
1485
+ * Without a session we still clear local audio/visemes AND latch (the
1486
+ * server has no way to know, but any further chunks it streams for this
1487
+ * turn are DROPPED by the latch until `resetTurn()` re-arms playback —
1488
+ * AU.1a changed the old "the next chunk resumes playback" behavior).
949
1489
  *
950
1490
  * Returns the `InterruptResult` describing what was spoken when a session
951
1491
  * is attached; returns null when there is no session.
952
1492
  */
953
1493
  async bargeIn(): Promise<InterruptResult | null> {
1494
+ // Latch FIRST so a frame racing in while the (async) session barge-in
1495
+ // runs is dropped rather than scheduled (AU.1a). Cleared by resetTurn().
1496
+ this.barged = true;
1497
+ this.clearPendingEvents();
954
1498
  let result: InterruptResult | null = null;
955
1499
  if (this.sessionClient) {
956
1500
  result = await this.sessionClient.bargeIn();
@@ -958,21 +1502,38 @@ export class AudioPipeline {
958
1502
  this.player.clearQueue();
959
1503
  }
960
1504
  this.visemeScheduler.clear();
961
- this.sentenceStartTime = null;
962
- this.lastPhonemeEnd = 0;
963
- this.pendingMetadata = [];
1505
+ this.clearTurnBuffers();
964
1506
  return result;
965
1507
  }
966
1508
 
1509
+ /**
1510
+ * AU.3 — server-initiated flush (`{type:'tts_flush'}`): the server already
1511
+ * arbitrated a barge-in (auto barge-in via Deepgram StartOfTurn, or the
1512
+ * server echoing a button barge), so drop local audio/visemes and LATCH —
1513
+ * exactly `bargeIn()` minus the client→server `barge_in` send (sending it
1514
+ * back would double-cancel the NEXT turn's TTS context). Idempotent: a
1515
+ * second flush (e.g. button + server echo) is a no-op on empty queues.
1516
+ * The latch clears on the next server `turn_start` (`resetTurn()`).
1517
+ */
1518
+ serverFlush(): void {
1519
+ this.barged = true;
1520
+ this.clearPendingEvents();
1521
+ this.player.clearQueue();
1522
+ // Mirror `AudioSessionClient.bargeIn()`'s local half: stop position
1523
+ // tracking + reset the word tracker for the next turn.
1524
+ this.sessionClient?.resetForNewTurn();
1525
+ this.visemeScheduler.clear();
1526
+ this.clearTurnBuffers();
1527
+ }
1528
+
967
1529
  /** Clean up all resources. */
968
1530
  async destroy(): Promise<void> {
969
1531
  this._sessionClient?.cleanup();
970
1532
  this._sessionClient = null;
971
1533
  this.visemeScheduler.destroy();
972
1534
  await this.player.stop();
973
- this.sentenceStartTime = null;
974
- this.lastPhonemeEnd = 0;
975
- this.pendingMetadata = [];
1535
+ this.clearTurnBuffers();
1536
+ this.barged = false;
976
1537
  }
977
1538
  }
978
1539