@escapeaihq/client-core 0.52.0 → 0.139.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 (782) 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 +10295 -2216
  55. package/dist/api.d.ts.map +1 -1
  56. package/dist/api.js +4187 -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 +13 -0
  91. package/dist/conversation/binding.d.ts.map +1 -1
  92. package/dist/conversation/binding.js.map +1 -1
  93. package/dist/conversation/chatSessionStore.d.ts +178 -0
  94. package/dist/conversation/chatSessionStore.d.ts.map +1 -0
  95. package/dist/conversation/chatSessionStore.js +196 -0
  96. package/dist/conversation/chatSessionStore.js.map +1 -0
  97. package/dist/conversation/controller.d.ts +44 -0
  98. package/dist/conversation/controller.d.ts.map +1 -1
  99. package/dist/conversation/controller.js +82 -3
  100. package/dist/conversation/controller.js.map +1 -1
  101. package/dist/conversation/index.d.ts +2 -0
  102. package/dist/conversation/index.d.ts.map +1 -1
  103. package/dist/conversation/index.js +2 -0
  104. package/dist/conversation/index.js.map +1 -1
  105. package/dist/conversation/participant.d.ts +16 -0
  106. package/dist/conversation/participant.d.ts.map +1 -1
  107. package/dist/conversation/readSequencer.d.ts +38 -0
  108. package/dist/conversation/readSequencer.d.ts.map +1 -0
  109. package/dist/conversation/readSequencer.js +42 -0
  110. package/dist/conversation/readSequencer.js.map +1 -0
  111. package/dist/conversation/roster.d.ts +5 -1
  112. package/dist/conversation/roster.d.ts.map +1 -1
  113. package/dist/conversation/roster.js.map +1 -1
  114. package/dist/conversation/rosterProjection.d.ts +74 -1
  115. package/dist/conversation/rosterProjection.d.ts.map +1 -1
  116. package/dist/conversation/rosterProjection.js +135 -1
  117. package/dist/conversation/rosterProjection.js.map +1 -1
  118. package/dist/conversation/runtime.d.ts +20 -3
  119. package/dist/conversation/runtime.d.ts.map +1 -1
  120. package/dist/conversation/runtime.js +66 -7
  121. package/dist/conversation/runtime.js.map +1 -1
  122. package/dist/conversation/types.d.ts +43 -4
  123. package/dist/conversation/types.d.ts.map +1 -1
  124. package/dist/conversation/voice.d.ts +290 -13
  125. package/dist/conversation/voice.d.ts.map +1 -1
  126. package/dist/conversation/voice.js +565 -42
  127. package/dist/conversation/voice.js.map +1 -1
  128. package/dist/creatorCuration.d.ts +134 -0
  129. package/dist/creatorCuration.d.ts.map +1 -0
  130. package/dist/creatorCuration.js +228 -0
  131. package/dist/creatorCuration.js.map +1 -0
  132. package/dist/creatorDashboard.d.ts +155 -0
  133. package/dist/creatorDashboard.d.ts.map +1 -0
  134. package/dist/creatorDashboard.js +237 -0
  135. package/dist/creatorDashboard.js.map +1 -0
  136. package/dist/creatorUniverse.d.ts +95 -0
  137. package/dist/creatorUniverse.d.ts.map +1 -0
  138. package/dist/creatorUniverse.js +136 -0
  139. package/dist/creatorUniverse.js.map +1 -0
  140. package/dist/curationWrite.d.ts +76 -0
  141. package/dist/curationWrite.d.ts.map +1 -0
  142. package/dist/curationWrite.js +106 -0
  143. package/dist/curationWrite.js.map +1 -0
  144. package/dist/designTokens.d.ts +64 -0
  145. package/dist/designTokens.d.ts.map +1 -0
  146. package/dist/designTokens.js +117 -0
  147. package/dist/designTokens.js.map +1 -0
  148. package/dist/dialogAttribution.d.ts +79 -0
  149. package/dist/dialogAttribution.d.ts.map +1 -0
  150. package/dist/dialogAttribution.js +144 -0
  151. package/dist/dialogAttribution.js.map +1 -0
  152. package/dist/dmRunWorldReadiness.d.ts +605 -0
  153. package/dist/dmRunWorldReadiness.d.ts.map +1 -0
  154. package/dist/dmRunWorldReadiness.js +775 -0
  155. package/dist/dmRunWorldReadiness.js.map +1 -0
  156. package/dist/domains/access.d.ts +32 -0
  157. package/dist/domains/access.d.ts.map +1 -0
  158. package/dist/domains/access.js +43 -0
  159. package/dist/domains/access.js.map +1 -0
  160. package/dist/domains/adventureDefinitions.d.ts +159 -0
  161. package/dist/domains/adventureDefinitions.d.ts.map +1 -0
  162. package/dist/domains/adventureDefinitions.js +168 -0
  163. package/dist/domains/adventureDefinitions.js.map +1 -0
  164. package/dist/domains/adventures.d.ts +329 -0
  165. package/dist/domains/adventures.d.ts.map +1 -0
  166. package/dist/domains/adventures.js +359 -0
  167. package/dist/domains/adventures.js.map +1 -0
  168. package/dist/domains/arcs.d.ts +146 -0
  169. package/dist/domains/arcs.d.ts.map +1 -0
  170. package/dist/domains/arcs.js +202 -0
  171. package/dist/domains/arcs.js.map +1 -0
  172. package/dist/domains/artifacts.d.ts +259 -0
  173. package/dist/domains/artifacts.d.ts.map +1 -0
  174. package/dist/domains/artifacts.js +125 -0
  175. package/dist/domains/artifacts.js.map +1 -0
  176. package/dist/domains/chat.d.ts +158 -0
  177. package/dist/domains/chat.d.ts.map +1 -0
  178. package/dist/domains/chat.js +224 -0
  179. package/dist/domains/chat.js.map +1 -0
  180. package/dist/domains/decisions.d.ts +31 -0
  181. package/dist/domains/decisions.d.ts.map +1 -0
  182. package/dist/domains/decisions.js +42 -0
  183. package/dist/domains/decisions.js.map +1 -0
  184. package/dist/domains/documents.d.ts +218 -0
  185. package/dist/domains/documents.d.ts.map +1 -0
  186. package/dist/domains/documents.js +252 -0
  187. package/dist/domains/documents.js.map +1 -0
  188. package/dist/domains/enhancements.d.ts +106 -0
  189. package/dist/domains/enhancements.d.ts.map +1 -0
  190. package/dist/domains/enhancements.js +160 -0
  191. package/dist/domains/enhancements.js.map +1 -0
  192. package/dist/domains/graph.d.ts +454 -0
  193. package/dist/domains/graph.d.ts.map +1 -0
  194. package/dist/domains/graph.js +648 -0
  195. package/dist/domains/graph.js.map +1 -0
  196. package/dist/domains/images.d.ts +220 -0
  197. package/dist/domains/images.d.ts.map +1 -0
  198. package/dist/domains/images.js +307 -0
  199. package/dist/domains/images.js.map +1 -0
  200. package/dist/domains/ingestion.d.ts +312 -0
  201. package/dist/domains/ingestion.d.ts.map +1 -0
  202. package/dist/domains/ingestion.js +495 -0
  203. package/dist/domains/ingestion.js.map +1 -0
  204. package/dist/domains/me.d.ts +21 -0
  205. package/dist/domains/me.d.ts.map +1 -0
  206. package/dist/domains/me.js +23 -0
  207. package/dist/domains/me.js.map +1 -0
  208. package/dist/domains/orgs.d.ts +47 -0
  209. package/dist/domains/orgs.d.ts.map +1 -0
  210. package/dist/domains/orgs.js +75 -0
  211. package/dist/domains/orgs.js.map +1 -0
  212. package/dist/domains/personas.d.ts +138 -0
  213. package/dist/domains/personas.d.ts.map +1 -0
  214. package/dist/domains/personas.js +322 -0
  215. package/dist/domains/personas.js.map +1 -0
  216. package/dist/domains/projects.d.ts +53 -0
  217. package/dist/domains/projects.d.ts.map +1 -0
  218. package/dist/domains/projects.js +94 -0
  219. package/dist/domains/projects.js.map +1 -0
  220. package/dist/domains/quests.d.ts +431 -0
  221. package/dist/domains/quests.d.ts.map +1 -0
  222. package/dist/domains/quests.js +61 -0
  223. package/dist/domains/quests.js.map +1 -0
  224. package/dist/domains/reactor.d.ts +98 -0
  225. package/dist/domains/reactor.d.ts.map +1 -0
  226. package/dist/domains/reactor.js +131 -0
  227. package/dist/domains/reactor.js.map +1 -0
  228. package/dist/domains/showcase.d.ts +28 -0
  229. package/dist/domains/showcase.d.ts.map +1 -0
  230. package/dist/domains/showcase.js +28 -0
  231. package/dist/domains/showcase.js.map +1 -0
  232. package/dist/domains/storyboards.d.ts +1253 -0
  233. package/dist/domains/storyboards.d.ts.map +1 -0
  234. package/dist/domains/storyboards.js +781 -0
  235. package/dist/domains/storyboards.js.map +1 -0
  236. package/dist/domains/studioSettings.d.ts +39 -0
  237. package/dist/domains/studioSettings.d.ts.map +1 -0
  238. package/dist/domains/studioSettings.js +80 -0
  239. package/dist/domains/studioSettings.js.map +1 -0
  240. package/dist/domains/universes.d.ts +191 -0
  241. package/dist/domains/universes.d.ts.map +1 -0
  242. package/dist/domains/universes.js +276 -0
  243. package/dist/domains/universes.js.map +1 -0
  244. package/dist/domains/userDefaults.d.ts +18 -0
  245. package/dist/domains/userDefaults.d.ts.map +1 -0
  246. package/dist/domains/userDefaults.js +27 -0
  247. package/dist/domains/userDefaults.js.map +1 -0
  248. package/dist/domains/visemeBundles.d.ts +262 -0
  249. package/dist/domains/visemeBundles.d.ts.map +1 -0
  250. package/dist/domains/visemeBundles.js +373 -0
  251. package/dist/domains/visemeBundles.js.map +1 -0
  252. package/dist/domains/workflows.d.ts +142 -0
  253. package/dist/domains/workflows.d.ts.map +1 -0
  254. package/dist/domains/workflows.js +245 -0
  255. package/dist/domains/workflows.js.map +1 -0
  256. package/dist/enhancementDiff.d.ts +56 -0
  257. package/dist/enhancementDiff.d.ts.map +1 -0
  258. package/dist/enhancementDiff.js +110 -0
  259. package/dist/enhancementDiff.js.map +1 -0
  260. package/dist/generated/contract.d.ts +372 -0
  261. package/dist/generated/contract.d.ts.map +1 -0
  262. package/dist/generated/contract.js +395 -0
  263. package/dist/generated/contract.js.map +1 -0
  264. package/dist/graphSchema.d.ts +36 -5
  265. package/dist/graphSchema.d.ts.map +1 -1
  266. package/dist/graphSchema.js +88 -2
  267. package/dist/graphSchema.js.map +1 -1
  268. package/dist/http.d.ts +70 -1
  269. package/dist/http.d.ts.map +1 -1
  270. package/dist/http.js +263 -11
  271. package/dist/http.js.map +1 -1
  272. package/dist/identity.d.ts +81 -0
  273. package/dist/identity.d.ts.map +1 -0
  274. package/dist/identity.js +65 -0
  275. package/dist/identity.js.map +1 -0
  276. package/dist/index.d.ts +35 -0
  277. package/dist/index.d.ts.map +1 -1
  278. package/dist/index.js +118 -0
  279. package/dist/index.js.map +1 -1
  280. package/dist/messageContent.d.ts +174 -0
  281. package/dist/messageContent.d.ts.map +1 -0
  282. package/dist/messageContent.js +405 -0
  283. package/dist/messageContent.js.map +1 -0
  284. package/dist/mutationEpoch.d.ts +83 -0
  285. package/dist/mutationEpoch.d.ts.map +1 -0
  286. package/dist/mutationEpoch.js +109 -0
  287. package/dist/mutationEpoch.js.map +1 -0
  288. package/dist/obo.d.ts +144 -0
  289. package/dist/obo.d.ts.map +1 -0
  290. package/dist/obo.js +135 -0
  291. package/dist/obo.js.map +1 -0
  292. package/dist/opusTransport.d.ts +113 -0
  293. package/dist/opusTransport.d.ts.map +1 -0
  294. package/dist/opusTransport.js +170 -0
  295. package/dist/opusTransport.js.map +1 -0
  296. package/dist/pagination.d.ts +18 -0
  297. package/dist/pagination.d.ts.map +1 -0
  298. package/dist/pagination.js +26 -0
  299. package/dist/pagination.js.map +1 -0
  300. package/dist/platformAssistant.d.ts +55 -1
  301. package/dist/platformAssistant.d.ts.map +1 -1
  302. package/dist/platformAssistant.js +39 -1
  303. package/dist/platformAssistant.js.map +1 -1
  304. package/dist/pollUtils.d.ts +19 -0
  305. package/dist/pollUtils.d.ts.map +1 -0
  306. package/dist/pollUtils.js +35 -0
  307. package/dist/pollUtils.js.map +1 -0
  308. package/dist/questLog.d.ts +232 -0
  309. package/dist/questLog.d.ts.map +1 -0
  310. package/dist/questLog.js +522 -0
  311. package/dist/questLog.js.map +1 -0
  312. package/dist/reactor/dmDirectiveToExperience.d.ts +300 -0
  313. package/dist/reactor/dmDirectiveToExperience.d.ts.map +1 -0
  314. package/dist/reactor/dmDirectiveToExperience.js +401 -0
  315. package/dist/reactor/dmDirectiveToExperience.js.map +1 -0
  316. package/dist/reactor/dmSceneControlPrompt.d.ts.map +1 -1
  317. package/dist/reactor/dmSceneControlPrompt.js +64 -2
  318. package/dist/reactor/dmSceneControlPrompt.js.map +1 -1
  319. package/dist/reactor/dmWorldEntry.d.ts +1278 -0
  320. package/dist/reactor/dmWorldEntry.d.ts.map +1 -0
  321. package/dist/reactor/dmWorldEntry.js +1396 -0
  322. package/dist/reactor/dmWorldEntry.js.map +1 -0
  323. package/dist/reactor/framePromptCompaction.d.ts +223 -0
  324. package/dist/reactor/framePromptCompaction.d.ts.map +1 -0
  325. package/dist/reactor/framePromptCompaction.js +393 -0
  326. package/dist/reactor/framePromptCompaction.js.map +1 -0
  327. package/dist/reactor/frameWorldBind.d.ts +86 -0
  328. package/dist/reactor/frameWorldBind.d.ts.map +1 -0
  329. package/dist/reactor/frameWorldBind.js +79 -0
  330. package/dist/reactor/frameWorldBind.js.map +1 -0
  331. package/dist/reactor/happyOysterSeed.d.ts +166 -0
  332. package/dist/reactor/happyOysterSeed.d.ts.map +1 -0
  333. package/dist/reactor/happyOysterSeed.js +233 -0
  334. package/dist/reactor/happyOysterSeed.js.map +1 -0
  335. package/dist/reactor/happyOysterWalk.d.ts +274 -0
  336. package/dist/reactor/happyOysterWalk.d.ts.map +1 -0
  337. package/dist/reactor/happyOysterWalk.js +407 -0
  338. package/dist/reactor/happyOysterWalk.js.map +1 -0
  339. package/dist/reactor/happyOysterWorld.d.ts +718 -0
  340. package/dist/reactor/happyOysterWorld.d.ts.map +1 -0
  341. package/dist/reactor/happyOysterWorld.js +826 -0
  342. package/dist/reactor/happyOysterWorld.js.map +1 -0
  343. package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
  344. package/dist/reactor/heliosCommandDispatcher.js +5 -2
  345. package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
  346. package/dist/reactor/hiddenWorldLifecycle.d.ts +101 -0
  347. package/dist/reactor/hiddenWorldLifecycle.d.ts.map +1 -0
  348. package/dist/reactor/hiddenWorldLifecycle.js +119 -0
  349. package/dist/reactor/hiddenWorldLifecycle.js.map +1 -0
  350. package/dist/reactor/imageCanvas.d.ts +15 -0
  351. package/dist/reactor/imageCanvas.d.ts.map +1 -0
  352. package/dist/reactor/imageCanvas.js +33 -0
  353. package/dist/reactor/imageCanvas.js.map +1 -0
  354. package/dist/reactor/index.d.ts +19 -0
  355. package/dist/reactor/index.d.ts.map +1 -1
  356. package/dist/reactor/index.js +78 -0
  357. package/dist/reactor/index.js.map +1 -1
  358. package/dist/reactor/longLiveCommandDispatcher.d.ts +23 -8
  359. package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -1
  360. package/dist/reactor/longLiveCommandDispatcher.js +16 -4
  361. package/dist/reactor/longLiveCommandDispatcher.js.map +1 -1
  362. package/dist/reactor/longLiveSceneEntry.d.ts +203 -0
  363. package/dist/reactor/longLiveSceneEntry.d.ts.map +1 -0
  364. package/dist/reactor/longLiveSceneEntry.js +280 -0
  365. package/dist/reactor/longLiveSceneEntry.js.map +1 -0
  366. package/dist/reactor/momentCut.d.ts +153 -0
  367. package/dist/reactor/momentCut.d.ts.map +1 -0
  368. package/dist/reactor/momentCut.js +142 -0
  369. package/dist/reactor/momentCut.js.map +1 -0
  370. package/dist/reactor/promptAddonRegistry.d.ts +39 -3
  371. package/dist/reactor/promptAddonRegistry.d.ts.map +1 -1
  372. package/dist/reactor/promptAddonRegistry.js +42 -3
  373. package/dist/reactor/promptAddonRegistry.js.map +1 -1
  374. package/dist/reactor/promptTemplatePreview.d.ts +97 -0
  375. package/dist/reactor/promptTemplatePreview.d.ts.map +1 -0
  376. package/dist/reactor/promptTemplatePreview.js +185 -0
  377. package/dist/reactor/promptTemplatePreview.js.map +1 -0
  378. package/dist/reactor/reactorAvailability.d.ts +80 -0
  379. package/dist/reactor/reactorAvailability.d.ts.map +1 -0
  380. package/dist/reactor/reactorAvailability.js +121 -0
  381. package/dist/reactor/reactorAvailability.js.map +1 -0
  382. package/dist/reactor/reactorSessionRefusal.d.ts +125 -0
  383. package/dist/reactor/reactorSessionRefusal.d.ts.map +1 -0
  384. package/dist/reactor/reactorSessionRefusal.js +197 -0
  385. package/dist/reactor/reactorSessionRefusal.js.map +1 -0
  386. package/dist/reactor/reactorTokenScope.d.ts +47 -0
  387. package/dist/reactor/reactorTokenScope.d.ts.map +1 -0
  388. package/dist/reactor/reactorTokenScope.js +64 -0
  389. package/dist/reactor/reactorTokenScope.js.map +1 -0
  390. package/dist/reactor/resolveDirectorBeats.d.ts +65 -0
  391. package/dist/reactor/resolveDirectorBeats.d.ts.map +1 -0
  392. package/dist/reactor/resolveDirectorBeats.js +86 -0
  393. package/dist/reactor/resolveDirectorBeats.js.map +1 -0
  394. package/dist/reactor/sanaLiveEdit.d.ts +117 -0
  395. package/dist/reactor/sanaLiveEdit.d.ts.map +1 -0
  396. package/dist/reactor/sanaLiveEdit.js +105 -0
  397. package/dist/reactor/sanaLiveEdit.js.map +1 -0
  398. package/dist/reactor/sceneEntry.d.ts +66 -9
  399. package/dist/reactor/sceneEntry.d.ts.map +1 -1
  400. package/dist/reactor/sceneEntry.js +59 -66
  401. package/dist/reactor/sceneEntry.js.map +1 -1
  402. package/dist/reactor/sceneSeedImage.d.ts +199 -0
  403. package/dist/reactor/sceneSeedImage.d.ts.map +1 -0
  404. package/dist/reactor/sceneSeedImage.js +239 -0
  405. package/dist/reactor/sceneSeedImage.js.map +1 -0
  406. package/dist/reactor/seedImageOrchestrator.d.ts +70 -3
  407. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
  408. package/dist/reactor/seedImageOrchestrator.js +92 -28
  409. package/dist/reactor/seedImageOrchestrator.js.map +1 -1
  410. package/dist/reactor/toolPromptAddon.d.ts.map +1 -1
  411. package/dist/reactor/toolPromptAddon.js +16 -2
  412. package/dist/reactor/toolPromptAddon.js.map +1 -1
  413. package/dist/reactor/worldMintLoop.d.ts +286 -0
  414. package/dist/reactor/worldMintLoop.d.ts.map +1 -0
  415. package/dist/reactor/worldMintLoop.js +381 -0
  416. package/dist/reactor/worldMintLoop.js.map +1 -0
  417. package/dist/reactor/worldSteerOutcome.d.ts +98 -0
  418. package/dist/reactor/worldSteerOutcome.d.ts.map +1 -0
  419. package/dist/reactor/worldSteerOutcome.js +81 -0
  420. package/dist/reactor/worldSteerOutcome.js.map +1 -0
  421. package/dist/retryAfter.d.ts +15 -0
  422. package/dist/retryAfter.d.ts.map +1 -0
  423. package/dist/retryAfter.js +75 -0
  424. package/dist/retryAfter.js.map +1 -0
  425. package/dist/seriesKey.d.ts +31 -0
  426. package/dist/seriesKey.d.ts.map +1 -0
  427. package/dist/seriesKey.js +33 -0
  428. package/dist/seriesKey.js.map +1 -0
  429. package/dist/sessionRefresh.d.ts +135 -0
  430. package/dist/sessionRefresh.d.ts.map +1 -0
  431. package/dist/sessionRefresh.js +215 -0
  432. package/dist/sessionRefresh.js.map +1 -0
  433. package/dist/sharedAudioContext.d.ts +39 -0
  434. package/dist/sharedAudioContext.d.ts.map +1 -0
  435. package/dist/sharedAudioContext.js +63 -0
  436. package/dist/sharedAudioContext.js.map +1 -0
  437. package/dist/singleFlight.d.ts +51 -0
  438. package/dist/singleFlight.d.ts.map +1 -0
  439. package/dist/singleFlight.js +87 -0
  440. package/dist/singleFlight.js.map +1 -0
  441. package/dist/storyGraph.d.ts +83 -0
  442. package/dist/storyGraph.d.ts.map +1 -1
  443. package/dist/storyGraph.js +169 -4
  444. package/dist/storyGraph.js.map +1 -1
  445. package/dist/storyboardMask.d.ts +343 -0
  446. package/dist/storyboardMask.d.ts.map +1 -0
  447. package/dist/storyboardMask.js +505 -0
  448. package/dist/storyboardMask.js.map +1 -0
  449. package/dist/storyboardTimeline.d.ts +93 -0
  450. package/dist/storyboardTimeline.d.ts.map +1 -0
  451. package/dist/storyboardTimeline.js +131 -0
  452. package/dist/storyboardTimeline.js.map +1 -0
  453. package/dist/studioAutomation.d.ts +104 -0
  454. package/dist/studioAutomation.d.ts.map +1 -0
  455. package/dist/studioAutomation.js +178 -0
  456. package/dist/studioAutomation.js.map +1 -0
  457. package/dist/tenantClaim.d.ts +86 -0
  458. package/dist/tenantClaim.d.ts.map +1 -0
  459. package/dist/tenantClaim.js +164 -0
  460. package/dist/tenantClaim.js.map +1 -0
  461. package/dist/timeFormat.d.ts +25 -0
  462. package/dist/timeFormat.d.ts.map +1 -1
  463. package/dist/timeFormat.js +56 -0
  464. package/dist/timeFormat.js.map +1 -1
  465. package/dist/toolSchemas.d.ts +58 -10
  466. package/dist/toolSchemas.d.ts.map +1 -1
  467. package/dist/toolSchemas.js +37 -9
  468. package/dist/toolSchemas.js.map +1 -1
  469. package/dist/transport.d.ts +120 -0
  470. package/dist/transport.d.ts.map +1 -0
  471. package/dist/transport.js +282 -0
  472. package/dist/transport.js.map +1 -0
  473. package/dist/videoGenFacade.d.ts +63 -0
  474. package/dist/videoGenFacade.d.ts.map +1 -0
  475. package/dist/videoGenFacade.js +49 -0
  476. package/dist/videoGenFacade.js.map +1 -0
  477. package/dist/visemeScheduler.d.ts +24 -2
  478. package/dist/visemeScheduler.d.ts.map +1 -1
  479. package/dist/visemeScheduler.js +31 -2
  480. package/dist/visemeScheduler.js.map +1 -1
  481. package/dist/vision/VisionPublisher.d.ts +88 -0
  482. package/dist/vision/VisionPublisher.d.ts.map +1 -1
  483. package/dist/vision/VisionPublisher.js +196 -13
  484. package/dist/vision/VisionPublisher.js.map +1 -1
  485. package/dist/vision/VisionSourceController.d.ts +67 -1
  486. package/dist/vision/VisionSourceController.d.ts.map +1 -1
  487. package/dist/vision/VisionSourceController.js +147 -5
  488. package/dist/vision/VisionSourceController.js.map +1 -1
  489. package/dist/vision/index.d.ts +2 -1
  490. package/dist/vision/index.d.ts.map +1 -1
  491. package/dist/vision/index.js +2 -1
  492. package/dist/vision/index.js.map +1 -1
  493. package/dist/vision/sourceKinds.d.ts +18 -5
  494. package/dist/vision/sourceKinds.d.ts.map +1 -1
  495. package/dist/vision/sourceKinds.js +15 -2
  496. package/dist/vision/sourceKinds.js.map +1 -1
  497. package/dist/vision/types.d.ts +7 -4
  498. package/dist/vision/types.d.ts.map +1 -1
  499. package/dist/vision/visionErrors.d.ts +45 -0
  500. package/dist/vision/visionErrors.d.ts.map +1 -0
  501. package/dist/vision/visionErrors.js +66 -0
  502. package/dist/vision/visionErrors.js.map +1 -0
  503. package/dist/voiceCloneCaption.d.ts +33 -0
  504. package/dist/voiceCloneCaption.d.ts.map +1 -0
  505. package/dist/voiceCloneCaption.js +69 -0
  506. package/dist/voiceCloneCaption.js.map +1 -0
  507. package/dist/websocket.d.ts +273 -10
  508. package/dist/websocket.d.ts.map +1 -1
  509. package/dist/websocket.js +79 -0
  510. package/dist/websocket.js.map +1 -1
  511. package/dist/workflowAuthoring.d.ts +139 -0
  512. package/dist/workflowAuthoring.d.ts.map +1 -0
  513. package/dist/workflowAuthoring.js +557 -0
  514. package/dist/workflowAuthoring.js.map +1 -0
  515. package/package.json +15 -5
  516. package/src/__tests__/adapters-director.test.ts +9 -6
  517. package/src/__tests__/adapters-extraction.test.ts +175 -0
  518. package/src/__tests__/adapters-image.test.ts +66 -0
  519. package/src/__tests__/adapters-momentPolicy.test.ts +218 -0
  520. package/src/__tests__/adapters-platform.test.ts +110 -4
  521. package/src/__tests__/adapters-videogen.test.ts +53 -0
  522. package/src/__tests__/adapters-world.test.ts +117 -7
  523. package/src/__tests__/admin.enhancement-defaults.test.ts +115 -0
  524. package/src/__tests__/admin.test.ts +282 -0
  525. package/src/__tests__/adventures-world-state.test.ts +156 -0
  526. package/src/__tests__/adventures.test.ts +111 -1
  527. package/src/__tests__/api-pollers.test.ts +113 -23
  528. package/src/__tests__/api.adventure-definitions.test.ts +312 -0
  529. package/src/__tests__/api.anchor-beat.test.ts +75 -0
  530. package/src/__tests__/api.arc-approval.test.ts +171 -0
  531. package/src/__tests__/api.arc-beats-floor.test.ts +56 -0
  532. package/src/__tests__/api.arc-generation.test.ts +168 -0
  533. package/src/__tests__/api.arc-templates.test.ts +78 -0
  534. package/src/__tests__/api.assignVideoSeries.test.ts +81 -0
  535. package/src/__tests__/api.cast-frame-choices.test.ts +141 -0
  536. package/src/__tests__/api.cutscene-registry.test.ts +148 -0
  537. package/src/__tests__/api.enhancement-addition-actions.test.ts +137 -0
  538. package/src/__tests__/api.enrichVideo-serialization.test.ts +116 -0
  539. package/src/__tests__/api.extraction-base.test.ts +87 -0
  540. package/src/__tests__/api.generateVideo-cutscene.test.ts +148 -0
  541. package/src/__tests__/api.job-pipeline-stages.test.ts +128 -0
  542. package/src/__tests__/api.list-images-filters.test.ts +6 -3
  543. package/src/__tests__/api.quest-curation.test.ts +169 -0
  544. package/src/__tests__/api.reprocessVideo.test.ts +71 -0
  545. package/src/__tests__/api.scene-split-merge.test.ts +129 -0
  546. package/src/__tests__/api.session-quests.test.ts +184 -0
  547. package/src/__tests__/api.test.ts +122 -0
  548. package/src/__tests__/api.transferSeries.test.ts +114 -0
  549. package/src/__tests__/api.unknown-clusters.test.ts +225 -0
  550. package/src/__tests__/api.uploadVideo-options.test.ts +156 -0
  551. package/src/__tests__/arcPreview.test.ts +71 -0
  552. package/src/__tests__/arcStyleProfile.test.ts +204 -0
  553. package/src/__tests__/artifacts-delete.test.ts +109 -0
  554. package/src/__tests__/audio.test.ts +864 -5
  555. package/src/__tests__/audioDsp.test.ts +196 -0
  556. package/src/__tests__/audioUnavailable.test.ts +43 -0
  557. package/src/__tests__/cast.test.ts +10 -1
  558. package/src/__tests__/castCurationProjection.test.ts +84 -0
  559. package/src/__tests__/castFramePipelinePending.test.ts +171 -0
  560. package/src/__tests__/castProjection.test.ts +497 -5
  561. package/src/__tests__/characterGrounding.test.ts +357 -0
  562. package/src/__tests__/contract.test.ts +97 -0
  563. package/src/__tests__/conversation/chatSessionStore.test.ts +243 -0
  564. package/src/__tests__/conversation/controller.test.ts +211 -0
  565. package/src/__tests__/conversation/readSequencer.test.ts +52 -0
  566. package/src/__tests__/conversation/rosterProjection.test.ts +204 -3
  567. package/src/__tests__/conversation/runtime.test.ts +118 -1
  568. package/src/__tests__/conversation/voice.test.ts +741 -7
  569. package/src/__tests__/creatorCuration.test.ts +256 -0
  570. package/src/__tests__/creatorDashboard.test.ts +444 -0
  571. package/src/__tests__/creatorUniverse.test.ts +138 -0
  572. package/src/__tests__/curationWrite.test.ts +179 -0
  573. package/src/__tests__/decisions.test.ts +89 -0
  574. package/src/__tests__/designTokens.test.ts +72 -0
  575. package/src/__tests__/dialogAttribution.test.ts +187 -0
  576. package/src/__tests__/dmDirectiveToExperience.test.ts +198 -0
  577. package/src/__tests__/dmWorldEntry.test.ts +2102 -0
  578. package/src/__tests__/enhancementDiff.test.ts +132 -0
  579. package/src/__tests__/experienceModelCatalog.test.ts +292 -0
  580. package/src/__tests__/extractionStageState.test.ts +67 -0
  581. package/src/__tests__/getVideo.test.ts +95 -0
  582. package/src/__tests__/graphReadAfterWrite.test.ts +211 -0
  583. package/src/__tests__/graphSchema.test.ts +55 -4
  584. package/src/__tests__/happyOysterSeed.test.ts +208 -0
  585. package/src/__tests__/happyOysterWorld.test.ts +1241 -0
  586. package/src/__tests__/happyOysterWorldRefusal.test.ts +224 -0
  587. package/src/__tests__/hiddenWorldLifecycle.test.ts +203 -0
  588. package/src/__tests__/http.session-refresh.test.ts +424 -0
  589. package/src/__tests__/http.test.ts +316 -0
  590. package/src/__tests__/identity.test.ts +132 -0
  591. package/src/__tests__/loadBundleManifest.test.ts +192 -22
  592. package/src/__tests__/longLiveSceneEntry.test.ts +371 -0
  593. package/src/__tests__/me.test.ts +74 -0
  594. package/src/__tests__/messageContent.test.ts +395 -0
  595. package/src/__tests__/momentCut.test.ts +229 -0
  596. package/src/__tests__/mutationEpoch.test.ts +218 -0
  597. package/src/__tests__/obo.test.ts +159 -0
  598. package/src/__tests__/opusTransport.test.ts +182 -0
  599. package/src/__tests__/opusTransportLibopus.test.ts +125 -0
  600. package/src/__tests__/orgs.test.ts +229 -0
  601. package/src/__tests__/persona-generation.test.ts +208 -1
  602. package/src/__tests__/platformAssistant.test.ts +140 -0
  603. package/src/__tests__/projects.test.ts +338 -0
  604. package/src/__tests__/promptTemplatePreview.test.ts +160 -0
  605. package/src/__tests__/reactor/__fixtures__/realFramePromptText.ts +23 -0
  606. package/src/__tests__/reactor/api-reactor.test.ts +60 -21
  607. package/src/__tests__/reactor/framePromptCompaction.test.ts +300 -0
  608. package/src/__tests__/reactor/promptAddonRegistry.test.ts +79 -0
  609. package/src/__tests__/reactor/reactorTokenScope.test.ts +50 -0
  610. package/src/__tests__/reactor/resolveDirectorBeats.test.ts +156 -0
  611. package/src/__tests__/reactor/sceneEntry.test.ts +3 -0
  612. package/src/__tests__/reactor/sceneSeedImage.test.ts +361 -0
  613. package/src/__tests__/reactor/seedImageOrchestrator.test.ts +43 -5
  614. package/src/__tests__/reactor-happyOysterWalk.test.ts +294 -0
  615. package/src/__tests__/reactorAvailability.test.ts +217 -0
  616. package/src/__tests__/reactorSessionRefusal.test.ts +189 -0
  617. package/src/__tests__/regeneration.test.ts +9 -9
  618. package/src/__tests__/reprocessBlockedReason.test.ts +30 -0
  619. package/src/__tests__/retryAfter.test.ts +65 -0
  620. package/src/__tests__/roleClaim.test.ts +102 -0
  621. package/src/__tests__/sanaLiveEdit.test.ts +84 -0
  622. package/src/__tests__/seriesKey.test.ts +24 -0
  623. package/src/__tests__/settings-set9.test.ts +238 -0
  624. package/src/__tests__/singleFlight.test.ts +348 -0
  625. package/src/__tests__/storyGraph.test.ts +111 -1
  626. package/src/__tests__/storyboardFrameCutscene.test.ts +115 -0
  627. package/src/__tests__/storyboardMask.test.ts +527 -0
  628. package/src/__tests__/storyboardTimeline.test.ts +228 -0
  629. package/src/__tests__/storyboards.test.ts +639 -0
  630. package/src/__tests__/studioAutomation.test.ts +325 -0
  631. package/src/__tests__/toolSchemas.test.ts +11 -18
  632. package/src/__tests__/transport.test.ts +312 -0
  633. package/src/__tests__/videoGenFacade.test.ts +141 -0
  634. package/src/__tests__/videoGraph.test.ts +43 -1
  635. package/src/__tests__/visemeScheduler.test.ts +55 -1
  636. package/src/__tests__/visibility.test.ts +143 -0
  637. package/src/__tests__/voiceCloneCaption.test.ts +80 -0
  638. package/src/__tests__/voiceFallback.test.ts +55 -0
  639. package/src/__tests__/websocket-error-turn-ended.test.ts +49 -0
  640. package/src/__tests__/websocket-vision.test.ts +141 -0
  641. package/src/__tests__/websocket.test.ts +75 -1
  642. package/src/__tests__/workflowAuthoring.test.ts +187 -0
  643. package/src/__tests__/workflows.test.ts +640 -0
  644. package/src/__tests__/worldMintLoop.test.ts +448 -0
  645. package/src/__tests__/worldModelPreference.test.ts +302 -0
  646. package/src/__tests__/worldModelTradeoffs.test.ts +89 -0
  647. package/src/__tests__/worldSteerOutcome.test.ts +62 -0
  648. package/src/adapters/capabilities.ts +39 -3
  649. package/src/adapters/directorAdapter.ts +5 -4
  650. package/src/adapters/experienceModelCatalog.ts +538 -0
  651. package/src/adapters/extractionAdapter.ts +150 -0
  652. package/src/adapters/imageAdapter.ts +5 -1
  653. package/src/adapters/index.ts +104 -17
  654. package/src/adapters/momentDirective.ts +109 -0
  655. package/src/adapters/momentPolicy.ts +209 -0
  656. package/src/adapters/registry.ts +1 -1
  657. package/src/adapters/videoGenAdapter.ts +124 -0
  658. package/src/adapters/worldAdapter.ts +221 -16
  659. package/src/adapters/worldModelPreference.ts +247 -0
  660. package/src/adapters/worldModelTradeoffs.ts +247 -0
  661. package/src/admin.ts +842 -16
  662. package/src/api.ts +12687 -3446
  663. package/src/arcBoardJoin.ts +46 -0
  664. package/src/arcPreview.ts +103 -0
  665. package/src/audio.ts +691 -130
  666. package/src/audioDsp.ts +132 -0
  667. package/src/audioProtocol.ts +235 -0
  668. package/src/beatTitles.ts +51 -0
  669. package/src/castProjection.ts +311 -0
  670. package/src/characterGrounding.ts +491 -0
  671. package/src/conversation/binding.ts +13 -0
  672. package/src/conversation/chatSessionStore.ts +281 -0
  673. package/src/conversation/controller.ts +96 -3
  674. package/src/conversation/index.ts +2 -0
  675. package/src/conversation/participant.ts +16 -0
  676. package/src/conversation/readSequencer.ts +55 -0
  677. package/src/conversation/roster.ts +5 -1
  678. package/src/conversation/rosterProjection.ts +166 -2
  679. package/src/conversation/runtime.ts +66 -7
  680. package/src/conversation/types.ts +43 -4
  681. package/src/conversation/voice.ts +655 -51
  682. package/src/creatorCuration.ts +316 -0
  683. package/src/creatorDashboard.ts +344 -0
  684. package/src/creatorUniverse.ts +222 -0
  685. package/src/curationWrite.ts +108 -0
  686. package/src/designTokens.ts +157 -0
  687. package/src/dialogAttribution.ts +182 -0
  688. package/src/dmRunWorldReadiness.ts +1168 -0
  689. package/src/domains/access.ts +92 -0
  690. package/src/domains/adventureDefinitions.ts +313 -0
  691. package/src/domains/adventures.ts +557 -0
  692. package/src/domains/arcs.ts +350 -0
  693. package/src/domains/artifacts.ts +349 -0
  694. package/src/domains/chat.ts +338 -0
  695. package/src/domains/decisions.ts +62 -0
  696. package/src/domains/documents.ts +389 -0
  697. package/src/domains/enhancements.ts +259 -0
  698. package/src/domains/graph.ts +959 -0
  699. package/src/domains/images.ts +451 -0
  700. package/src/domains/ingestion.ts +695 -0
  701. package/src/domains/me.ts +27 -0
  702. package/src/domains/orgs.ts +168 -0
  703. package/src/domains/personas.ts +440 -0
  704. package/src/domains/projects.ts +177 -0
  705. package/src/domains/quests.ts +587 -0
  706. package/src/domains/reactor.ts +163 -0
  707. package/src/domains/showcase.ts +35 -0
  708. package/src/domains/storyboards.ts +1698 -0
  709. package/src/domains/studioSettings.ts +149 -0
  710. package/src/domains/universes.ts +433 -0
  711. package/src/domains/userDefaults.ts +37 -0
  712. package/src/domains/visemeBundles.ts +541 -0
  713. package/src/domains/workflows.ts +376 -0
  714. package/src/enhancementDiff.ts +171 -0
  715. package/src/generated/contract.ts +1016 -0
  716. package/src/graphSchema.ts +154 -6
  717. package/src/http.ts +295 -11
  718. package/src/identity.ts +123 -0
  719. package/src/index.ts +131 -0
  720. package/src/messageContent.ts +500 -0
  721. package/src/mutationEpoch.ts +107 -0
  722. package/src/obo.ts +201 -0
  723. package/src/opusTransport.ts +268 -0
  724. package/src/pagination.ts +29 -0
  725. package/src/platformAssistant.ts +97 -1
  726. package/src/pollUtils.ts +35 -0
  727. package/src/questLog.ts +704 -0
  728. package/src/reactor/dmDirectiveToExperience.ts +636 -0
  729. package/src/reactor/dmSceneControlPrompt.ts +69 -2
  730. package/src/reactor/dmWorldEntry.ts +2226 -0
  731. package/src/reactor/framePromptCompaction.ts +544 -0
  732. package/src/reactor/frameWorldBind.ts +133 -0
  733. package/src/reactor/happyOysterSeed.ts +329 -0
  734. package/src/reactor/happyOysterWalk.ts +541 -0
  735. package/src/reactor/happyOysterWorld.ts +1270 -0
  736. package/src/reactor/heliosCommandDispatcher.ts +5 -1
  737. package/src/reactor/hiddenWorldLifecycle.ts +182 -0
  738. package/src/reactor/imageCanvas.ts +38 -0
  739. package/src/reactor/index.ts +78 -0
  740. package/src/reactor/longLiveCommandDispatcher.ts +23 -8
  741. package/src/reactor/longLiveSceneEntry.ts +409 -0
  742. package/src/reactor/momentCut.ts +219 -0
  743. package/src/reactor/promptAddonRegistry.ts +81 -3
  744. package/src/reactor/promptTemplatePreview.ts +240 -0
  745. package/src/reactor/reactorAvailability.ts +155 -0
  746. package/src/reactor/reactorSessionRefusal.ts +260 -0
  747. package/src/reactor/reactorTokenScope.ts +69 -0
  748. package/src/reactor/resolveDirectorBeats.ts +140 -0
  749. package/src/reactor/sanaLiveEdit.ts +158 -0
  750. package/src/reactor/sceneEntry.ts +106 -88
  751. package/src/reactor/sceneSeedImage.ts +338 -0
  752. package/src/reactor/seedImageOrchestrator.ts +116 -34
  753. package/src/reactor/toolPromptAddon.ts +16 -2
  754. package/src/reactor/worldMintLoop.ts +545 -0
  755. package/src/reactor/worldSteerOutcome.ts +132 -0
  756. package/src/retryAfter.ts +71 -0
  757. package/src/seriesKey.ts +42 -0
  758. package/src/sessionRefresh.ts +237 -0
  759. package/src/sharedAudioContext.ts +67 -0
  760. package/src/singleFlight.ts +91 -0
  761. package/src/storyGraph.ts +247 -4
  762. package/src/storyboardMask.ts +756 -0
  763. package/src/storyboardTimeline.ts +220 -0
  764. package/src/studioAutomation.ts +208 -0
  765. package/src/tenantClaim.ts +170 -0
  766. package/src/timeFormat.ts +51 -0
  767. package/src/toolSchemas.ts +40 -10
  768. package/src/transport.ts +327 -0
  769. package/src/videoGenFacade.ts +90 -0
  770. package/src/visemeScheduler.ts +36 -3
  771. package/src/vision/VisionPublisher.ts +204 -14
  772. package/src/vision/VisionSourceController.ts +187 -6
  773. package/src/vision/__tests__/VisionPublisher.kvs.test.ts +50 -0
  774. package/src/vision/__tests__/VisionPublisher.test.ts +291 -0
  775. package/src/vision/__tests__/VisionSourceController.test.ts +376 -6
  776. package/src/vision/index.ts +5 -1
  777. package/src/vision/sourceKinds.ts +19 -5
  778. package/src/vision/types.ts +7 -4
  779. package/src/vision/visionErrors.ts +70 -0
  780. package/src/voiceCloneCaption.ts +77 -0
  781. package/src/websocket.ts +361 -12
  782. package/src/workflowAuthoring.ts +664 -0
@@ -33,11 +33,18 @@
33
33
 
34
34
  import {
35
35
  AudioPipeline,
36
+ MicVad,
36
37
  MicrophoneRecorder,
37
38
  buildHelloPayload,
38
39
  type HelloPayload,
40
+ type InterruptResult,
39
41
  } from '../audio';
42
+ import { CODEC_OPUS, CODEC_PCM16, isAiOpusFrame } from '../audioProtocol';
40
43
  import type { AudioFormat } from '../audioProtocol';
44
+ import {
45
+ createOpusTransportCodecs,
46
+ type OpusTransportCodecs,
47
+ } from '../opusTransport';
41
48
  import type { ChatWebSocket, WebSocketMessage } from '../websocket';
42
49
  import type { HelloArgs } from './binding';
43
50
  import type { VisemeSymbol } from '../visemeScheduler';
@@ -79,6 +86,42 @@ export interface VoiceSessionCallbacks {
79
86
  onError?: (message: string) => void;
80
87
  /** Optional human-readable status line (mic priming / streaming / paused). */
81
88
  onStatus?: (status: string) => void;
89
+ /**
90
+ * Fired once the audio session is confirmed live — on `hello_ack` and on any
91
+ * `transcript` frame (the two signals that the server's STT/TTS pipeline is up
92
+ * and consuming frames). The `/chat-ws` host lights its "Audio Ready" chip from
93
+ * this (its old `setIsAudioReady(true)` on those frames). The self-driving panel
94
+ * does not use it. ADDITIVE — an absent callback is a no-op.
95
+ */
96
+ onAudioReady?: () => void;
97
+ /**
98
+ * AU.2a — playback-suspension transitions. Fired with `true` when TTS
99
+ * frames are queuing behind a suspended AudioContext (the iOS "mic looks
100
+ * live, audio is silent" state — typically after a reconnect re-armed audio
101
+ * outside a user gesture), and with `false` once playback drains. Hosts
102
+ * show a tap-to-restore overlay whose tap handler calls
103
+ * {@link VoiceSession.restoreAudio} synchronously in the gesture. ADDITIVE
104
+ * — an absent callback is a no-op.
105
+ */
106
+ onPlaybackSuspended?: (suspended: boolean) => void;
107
+ /**
108
+ * AU.3 — the server interrupted TTS playback (`{type:'tts_flush'}`):
109
+ * `reason` is `'auto_barge_in'` (Deepgram StartOfTurn auto barge-in) or
110
+ * `'barge_in'` (the server echoing a button barge). Hosts show the
111
+ * "interrupting" affordance from the auto reason. The audio flush itself
112
+ * is handled internally (`AudioPipeline.serverFlush`). ADDITIVE — an
113
+ * absent callback is a no-op.
114
+ */
115
+ onInterrupted?: (reason: string) => void;
116
+ /**
117
+ * AU.3 — debounced local voice-activity transitions on the OUTBOUND mic
118
+ * (energy VAD over the same frames streamed to STT). `true` when the user
119
+ * starts speaking, `false` after the release hangover. Client affordance
120
+ * only ("listening…" indicator; combined with `onSpeakingChange` it yields
121
+ * the "interrupting" state) — the authoritative barge decision is
122
+ * server-side. ADDITIVE — an absent callback skips the VAD entirely.
123
+ */
124
+ onUserSpeechChange?: (speaking: boolean) => void;
82
125
  }
83
126
 
84
127
  export interface VoiceSessionConfig extends VoiceSessionCallbacks {
@@ -95,8 +138,30 @@ export interface VoiceSessionConfig extends VoiceSessionCallbacks {
95
138
  * live binding. Voice knobs are layered on top from {@link VoiceSessionOptions}.
96
139
  */
97
140
  getHelloArgs: () => HelloArgs;
98
- /** The voice-only hello knobs (see {@link VoiceSessionOptions}). */
99
- voiceOptions?: VoiceSessionOptions;
141
+ /**
142
+ * The voice-only hello knobs (see {@link VoiceSessionOptions}). Either a fixed
143
+ * object (read once — the persona-fixed floater/overlay case) OR a function
144
+ * resolved AT `buildHello()` time. Use the function form when the knobs change
145
+ * over the session's life (the `/chat-ws` case: the voiceId/rate/markups change
146
+ * when the user switches persona, then re-`start()`s the SAME session). Both are
147
+ * merged identically; a function takes priority when provided.
148
+ */
149
+ voiceOptions?: VoiceSessionOptions | (() => VoiceSessionOptions);
150
+ /**
151
+ * AU.4 slice 4 — opt IN to offering the Opus codec on the voice hello.
152
+ * When `true`, `armAudioOutput()` preloads the libopus-wasm codec legs
153
+ * (an optional peer dependency, dynamically imported) and — ONLY when the
154
+ * preload succeeds — the hello advertises `audioCodecs: ['opus','pcm16']`.
155
+ * The wire actually switches to Opus only when the server acks
156
+ * `negotiatedCodec: 'opus'` (its `OPUS_TRANSPORT_ENABLED` flag is ON);
157
+ * otherwise the session stays on the legacy PCM16 wire.
158
+ *
159
+ * DEFAULT OFF (undefined): the hello is byte-identical to pre-AU.4 —
160
+ * REQUIRED against servers that predate `HelloMessage.audioCodecs` (their
161
+ * `extra='forbid'` validation rejects unknown fields; the production
162
+ * Web-App consumer pins such a server). ADDITIVE.
163
+ */
164
+ offerOpus?: boolean;
100
165
  }
101
166
 
102
167
  /**
@@ -107,10 +172,45 @@ export interface VoiceSessionConfig extends VoiceSessionCallbacks {
107
172
  export class VoiceSession {
108
173
  private readonly socket: ChatWebSocket;
109
174
  private readonly getHelloArgs: () => HelloArgs;
110
- private readonly voiceOptions: VoiceSessionOptions;
175
+ private readonly voiceOptions: VoiceSessionOptions | (() => VoiceSessionOptions);
111
176
  private readonly callbacks: VoiceSessionCallbacks;
177
+ /** AU.4 — offer the Opus codec on the hello (see {@link VoiceSessionConfig.offerOpus}). */
178
+ private readonly offerOpus: boolean;
179
+
180
+ /**
181
+ * AU.4 — the libopus-wasm codec legs, loaded by `armAudioOutput()` when
182
+ * {@link offerOpus} is set and the optional peer dep is installed; `null`
183
+ * otherwise (PCM16-only session — zero wasm loaded). Freed by `resetAudio()`.
184
+ */
185
+ private opusCodecs: OpusTransportCodecs | null = null;
186
+
187
+ /**
188
+ * AU.4 — the codec the server negotiated on `hello_ack` (`'opus'` only when
189
+ * we offered AND the server's flag is ON AND the codecs actually loaded);
190
+ * `'pcm16'` in every other case, matching the legacy wire.
191
+ */
192
+ private activeCodec: string = CODEC_PCM16;
193
+
194
+ /**
195
+ * AU.4 (claude[bot] review on #795) — teardown generation counter. Bumped
196
+ * by every `resetAudio()`; `armAudioOutput()` snapshots it before its slow
197
+ * awaits (the libopus-wasm preload is a real dynamic-import + wasm-compile
198
+ * gap) and bails out — freeing anything it just allocated — when a
199
+ * stop()/dispose() landed mid-await. Without this, the pending preload
200
+ * would overwrite the torn-down state with a live, never-freed codec pair
201
+ * and half-revive a disposed session (re-subscribed handlers + a hello on
202
+ * the socket).
203
+ */
204
+ private teardownGeneration = 0;
205
+
206
+ /** Delay before the post-reconnect suspension probe (AU.2a). */
207
+ private static readonly SUSPEND_PROBE_DELAY_MS = 350;
112
208
 
113
209
  private pipeline: AudioPipeline | null = null;
210
+
211
+ /** §Q DM.1 — the takeover duck requested by the host, remembered across a
212
+ * pipeline that has not been created yet (see {@link setDuck}). */
213
+ private duckGain = 1;
114
214
  private recorder: MicrophoneRecorder | null = null;
115
215
 
116
216
  /** True once `hello_ack` lands — gates outbound mic frames so they are never
@@ -119,12 +219,54 @@ export class VoiceSession {
119
219
  private audioReady = false;
120
220
  /** True between `start()` and `stop()`/`dispose()`. Gates reconnect re-send. */
121
221
  private active = false;
222
+ /**
223
+ * True once the OUTPUT half of the pipeline is armed (SP1, TTS-on-typed-input):
224
+ * the `AudioPipeline` exists, the socket message/binary handlers are attached,
225
+ * barge-in is wired, and the `tts_stt` hello has been sent. Both `start()` (the
226
+ * full mic+output voice path) and `synthesizeReply()` (the typed-turn output-only
227
+ * path) go through the SAME `armAudioOutput()` and set this — it is idempotent so
228
+ * a typed turn after a voice `start()` (or vice-versa) re-uses the one pipeline +
229
+ * the one hello. Distinct from `active`: `active` means a MIC session is running
230
+ * (gates outbound mic frames + the panel's Stop/Interrupt UI), whereas a
231
+ * typed-turn synthesis arms output WITHOUT the mic and must NOT flip `active`.
232
+ */
233
+ private audioOutputArmed = false;
122
234
  private disposed = false;
123
235
 
124
236
  /** The last hello sent, so a reconnect can re-send it (the page's
125
237
  * `lastHelloRef`). Exposed via {@link reconnectHello}. */
126
238
  private lastHello: HelloPayload | null = null;
127
239
 
240
+ /**
241
+ * UX-05 — the just-TYPED turn's text (trimmed), awaiting its server echo.
242
+ *
243
+ * The `tts_stt` session echoes a typed prompt back as a FINAL `transcript`
244
+ * frame (the same frame a SPOKEN mic turn produces from STT). For a typed turn
245
+ * the panel ALREADY rendered the user bubble in `handleSend`, so re-emitting
246
+ * `onTranscript` for the echo double-appends it. `synthesizeReply` records the
247
+ * trimmed text here; `handleMessage` consumes it on the matching final
248
+ * transcript and suppresses that ONE echo. `null` ⇒ no pending typed turn, so
249
+ * a SPOKEN mic turn (never goes through `synthesizeReply`) is untouched and its
250
+ * transcript still appends. Single-shot per typed turn — consumed on first
251
+ * match, so a later identical transcript (a re-typed/spoken duplicate) appends.
252
+ */
253
+ private pendingTypedEcho: string | null = null;
254
+
255
+ /**
256
+ * AU.3 — flips true on the first server `turn_start` frame. From then on
257
+ * the post-barge latch re-arms ONLY on the server's turn markers: the
258
+ * transcript-driven `resetTurn()` heuristic is skipped, closing the AU.1
259
+ * early-clear race (a fast next-utterance transcript could unlatch before
260
+ * the interrupted reply's stale tail frames landed, letting them play).
261
+ * Old servers never send `turn_start`, so the transcript path is kept
262
+ * verbatim for them.
263
+ */
264
+ private serverTurnMarkers = false;
265
+
266
+ /** AU.3 — local mic VAD (created per `start()` only when the host passed
267
+ * `onUserSpeechChange`; `null` otherwise so the per-frame cost is zero). */
268
+ private micVad: MicVad | null = null;
269
+
128
270
  private readonly messageHandler = (message: WebSocketMessage): void =>
129
271
  this.handleMessage(message);
130
272
 
@@ -141,7 +283,21 @@ export class VoiceSession {
141
283
  onSpeakingChange: config.onSpeakingChange,
142
284
  onError: config.onError,
143
285
  onStatus: config.onStatus,
286
+ onAudioReady: config.onAudioReady,
287
+ onPlaybackSuspended: config.onPlaybackSuspended,
288
+ onInterrupted: config.onInterrupted,
289
+ onUserSpeechChange: config.onUserSpeechChange,
144
290
  };
291
+ this.offerOpus = config.offerOpus ?? false;
292
+ }
293
+
294
+ /**
295
+ * AU.4 — the audio codec active on the wire: `'opus'` after the server acks
296
+ * an offered Opus session, else `'pcm16'` (the legacy wire). Read-only;
297
+ * settles on `hello_ack`. ADDITIVE.
298
+ */
299
+ get audioCodec(): string {
300
+ return this.activeCodec;
145
301
  }
146
302
 
147
303
  /**
@@ -153,10 +309,24 @@ export class VoiceSession {
153
309
  * it is byte-identical to the page's `startVoiceChat()` payload.
154
310
  */
155
311
  buildHello(): HelloPayload {
312
+ // Resolve the voice knobs FRESH each build: a function form (chat-ws —
313
+ // persona-switch changes voiceId/rate/markups before a re-`start()`) is
314
+ // called now; an object form (floater/overlay — persona-fixed) is read
315
+ // as-is. Either way the result is merged identically — one hello site.
316
+ const voiceOptions =
317
+ typeof this.voiceOptions === 'function'
318
+ ? this.voiceOptions()
319
+ : this.voiceOptions;
156
320
  return buildHelloPayload({
157
321
  ...this.getHelloArgs(),
158
322
  mode: 'tts_stt',
159
- ...this.voiceOptions,
323
+ ...voiceOptions,
324
+ // AU.4 — advertise Opus ONLY when the codec legs actually loaded
325
+ // (offer-after-capability: an offer the client can't honour would
326
+ // break the session the moment the server acks it). Omitted entirely
327
+ // otherwise, keeping the hello byte-identical to pre-AU.4 (old
328
+ // servers' extra='forbid' + the parity oracle both depend on that).
329
+ ...(this.opusCodecs ? { audioCodecs: [CODEC_OPUS, CODEC_PCM16] } : {}),
160
330
  });
161
331
  }
162
332
 
@@ -187,17 +357,35 @@ export class VoiceSession {
187
357
  // ─── iOS Safari user-gesture audio activation (synchronous prefix) ───
188
358
  // Both AudioContexts (player + recorder) MUST be created and resume()'d
189
359
  // inside the synchronous prefix of the click handler — see page.tsx:1776.
190
- if (!this.pipeline) {
191
- this.pipeline = new AudioPipeline((viseme) =>
192
- this.callbacks.onViseme(viseme as VisemeSymbol),
193
- );
194
- }
195
- void this.pipeline.resume();
360
+ // `armAudioOutput()` creates+resumes the PLAYER AudioContext (the output
361
+ // half); the recorder (the mic/input half) is owned only by `start()`.
362
+ this.ensurePipelineSync();
363
+ // AU.3 — arm the local VAD only when the host wants the affordance.
364
+ const userSpeechChange = this.callbacks.onUserSpeechChange;
365
+ this.micVad = userSpeechChange
366
+ ? new MicVad((speaking) => userSpeechChange(speaking))
367
+ : null;
196
368
  const recorder = new MicrophoneRecorder(
197
369
  (frame) => {
198
370
  if (!this.audioReady) return;
371
+ // The VAD always reads the raw PCM frame — energy detection runs
372
+ // BEFORE any codec leg, so it is wire-codec-agnostic (AU.4).
373
+ this.micVad?.push(frame);
374
+ let wireFrame = frame;
375
+ if (this.activeCodec === CODEC_OPUS && this.opusCodecs) {
376
+ // AU.4 mic leg: re-encode the 20 ms PCM16 frame as a TAG_MIC_OPUS
377
+ // wire frame. An encode failure drops THIS frame only (a 20 ms
378
+ // gap) — never the session, mirroring the backend's corrupt-packet
379
+ // posture on the decode side.
380
+ try {
381
+ wireFrame = this.opusCodecs.micEncoder.encodePcmFrame(frame);
382
+ } catch (err) {
383
+ console.error('Failed to Opus-encode mic frame', err);
384
+ return;
385
+ }
386
+ }
199
387
  try {
200
- this.socket.sendAudioFrame(frame);
388
+ this.socket.sendAudioFrame(wireFrame);
201
389
  } catch (err) {
202
390
  console.error('Failed to send audio frame', err);
203
391
  this.callbacks.onError?.('Unable to stream audio frame to server.');
@@ -208,30 +396,20 @@ export class VoiceSession {
208
396
  recorder.prime();
209
397
  this.recorder = recorder;
210
398
 
211
- // Subscribe to the socket BEFORE the hello so no early frame is missed.
212
- this.socket.onMessage(this.messageHandler);
213
- this.socket.onBinary(this.binaryHandler);
214
-
215
399
  try {
216
400
  this.callbacks.onStatus?.('Requesting microphone permission...');
217
- this.audioReady = false;
218
-
219
- // Safety-net await for non-iOS browsers (page.tsx:1809-1811).
220
- await this.pipeline.resume();
221
-
222
- // Barge-in: attach the session against the raw socket + start the
223
- // playback-position tracker (page.tsx:1813-1827). `attachSession`
224
- // wires the player; tracking makes the server's barge-in arbitration
225
- // work against the real playhead.
226
- const rawWs = this.socket.getRawSocket();
227
- if (rawWs) {
228
- this.pipeline.attachSession(rawWs);
229
- this.pipeline.sessionClient?.startPlaybackTracking();
230
- }
231
401
 
232
- const hello = this.buildHello();
233
- this.lastHello = hello;
234
- this.socket.sendHello(hello);
402
+ // Arm the OUTPUT half (player resume + handler subscription + barge-in +
403
+ // the single `tts_stt` hello). Shared with `synthesizeReply()` so there is
404
+ // exactly one place that opens the audio session — NO second hello site.
405
+ // `false` = a stop()/dispose() landed while the arm's awaits were in
406
+ // flight (codex P2 on #795): abandon the start WITHOUT flipping
407
+ // `active` or starting the mic — the teardown already ran.
408
+ if (!(await this.armAudioOutput())) {
409
+ // The interleaved stop()/dispose() already ran resetAudio(), which
410
+ // stopped + nulled this.recorder (assigned above); nothing to clean.
411
+ return;
412
+ }
235
413
 
236
414
  await recorder.start();
237
415
  this.active = true;
@@ -254,6 +432,171 @@ export class VoiceSession {
254
432
  }
255
433
  }
256
434
 
435
+ /**
436
+ * SP1 — TTS-on-typed-input. Synthesize the reply for a TYPED turn so the
437
+ * persona SPEAKS it (audio + lip-sync), reusing the EXISTING audio pipeline —
438
+ * this is a new TRIGGER into the voice path, NOT a second pipeline.
439
+ *
440
+ * The backend only synthesizes a reply when the session opened in `tts_stt`
441
+ * mode (`api/chat/ws.py`: the text-mode `send` path emits text-only frames;
442
+ * the audio session's `_handle_control_message` routes a typed `{action:'send'}`
443
+ * through the SAME `_process_turn` → LLM → Inworld-TTS path as a voice
444
+ * transcript, emitting binary `TAG_AI` audio + `audio_metadata` visemes). So
445
+ * this method arms the audio OUTPUT half — `armAudioOutput()` sends the single
446
+ * `tts_stt` hello (which, on a socket the controller already opened in `text`
447
+ * mode, is the honoured text→tts_stt upgrade: the server's hello branch re-runs
448
+ * and hands the socket to the audio session) — WITHOUT the mic, then sends the
449
+ * typed `send`. The reply's audio + visemes flow back through the existing
450
+ * `handleBinary`/`audio_metadata` → `onViseme` sinks. Mic capture stays
451
+ * exclusive to `start()`; `active` is NOT flipped (no Stop/Interrupt mic UI).
452
+ *
453
+ * iOS Safari: the player AudioContext is created+resumed in the SYNCHRONOUS
454
+ * prefix (`ensurePipelineSync()`) before the first await — so callers MUST
455
+ * invoke this from the synchronous prefix of the user gesture that sent the
456
+ * turn (the Send click / Enter keydown), exactly like `start()`.
457
+ *
458
+ * `opts` mirrors `ChatWebSocket.send`'s per-turn options (the renderer-owned
459
+ * `messages` history rides every turn; persona scope/prompt come from the
460
+ * hello). No-op (resolves) when the socket is not connected or the session is
461
+ * disposed — the caller's text path is unaffected.
462
+ */
463
+ async synthesizeReply(
464
+ text: string,
465
+ opts?: Parameters<ChatWebSocket['send']>[1],
466
+ ): Promise<void> {
467
+ if (this.disposed) {
468
+ throw new Error('VoiceSession: synthesizeReply() after dispose().');
469
+ }
470
+ if (!this.socket.isConnected) {
471
+ // Surface nothing here: the panel still rendered the user turn and the
472
+ // text reply path is the caller's responsibility — a closed socket is its
473
+ // own error elsewhere. Resolve so the typed turn is never blocked.
474
+ return;
475
+ }
476
+ // ─── iOS Safari user-gesture audio activation (synchronous prefix) ───
477
+ // Create + resume the player AudioContext NOW, inside the click/keydown
478
+ // gesture, before any await — otherwise iOS leaves the context suspended.
479
+ this.ensurePipelineSync();
480
+ // Arm the OUTPUT half (idempotent): on the FIRST synthesized turn this sends
481
+ // the `tts_stt` hello (the text→tts_stt upgrade) + subscribes handlers +
482
+ // wires barge-in; subsequent turns reuse the one armed pipeline + hello.
483
+ // `false` = torn down mid-arm (codex P2 on #795): do NOT send the typed
484
+ // turn on a session that was just stopped/disposed.
485
+ if (!(await this.armAudioOutput())) return;
486
+ // UX-05 — mark the trimmed typed text so its server echo (a final
487
+ // `transcript` frame) is NOT re-emitted to `onTranscript`: the panel already
488
+ // rendered this user turn in `handleSend`. Stored trimmed because the echo is
489
+ // compared trimmed (the transcript handler trims before delivery). A SPOKEN
490
+ // mic turn never reaches here, so its transcript still appends. Set BEFORE
491
+ // the send so a fast echo can't race ahead of the marker.
492
+ this.pendingTypedEcho = text.trim();
493
+ // Send the typed turn — the audio session synthesizes the reply.
494
+ this.socket.send(text, opts);
495
+ }
496
+
497
+ /**
498
+ * Create the `AudioPipeline` and kick the player AudioContext's `resume()` in
499
+ * the SYNCHRONOUS prefix of a user gesture (iOS Safari unlock). Idempotent. No
500
+ * awaits — the awaited safety-net `resume()` runs later in `armAudioOutput()`.
501
+ */
502
+ private ensurePipelineSync(): void {
503
+ if (!this.pipeline) {
504
+ this.pipeline = new AudioPipeline(
505
+ (viseme) => this.callbacks.onViseme(viseme as VisemeSymbol),
506
+ {
507
+ onPlaybackSuspended: (suspended) =>
508
+ this.callbacks.onPlaybackSuspended?.(suspended),
509
+ },
510
+ );
511
+ // §Q DM.1 — a takeover can be on screen before the session arms, so a
512
+ // duck requested against no pipeline is applied to the new one.
513
+ if (this.duckGain !== 1) this.pipeline.setDuck(this.duckGain);
514
+ }
515
+ void this.pipeline.resume();
516
+ }
517
+
518
+ /**
519
+ * Arm the audio OUTPUT half over the shared socket: resume the player, attach
520
+ * the socket message/binary handlers, wire barge-in against the raw socket,
521
+ * and send the single `tts_stt` hello (recording it for reconnect). IDEMPOTENT
522
+ * — a second call (e.g. a typed turn after a voice `start()`, or turn-after-turn
523
+ * synthesis) is a no-op, so there is exactly ONE hello and ONE handler
524
+ * subscription. The SINGLE hello site shared by `start()` (mic + output) and
525
+ * `synthesizeReply()` (output only). Assumes `ensurePipelineSync()` already ran
526
+ * (the pipeline exists); callers invoke it from their synchronous gesture prefix.
527
+ */
528
+ private async armAudioOutput(): Promise<boolean> {
529
+ if (this.audioOutputArmed) return true;
530
+ if (!this.pipeline) {
531
+ // Defensive: every caller runs ensurePipelineSync() first. Create it here
532
+ // too so armAudioOutput() is self-contained (no synchronous-gesture unlock
533
+ // benefit, but never a null deref).
534
+ this.ensurePipelineSync();
535
+ }
536
+ const pipeline = this.pipeline!;
537
+ this.audioReady = false;
538
+ // Snapshot the teardown generation BEFORE the async gaps below; a
539
+ // stop()/dispose() during either await bumps it via resetAudio() and the
540
+ // checks after each await abandon the arm instead of re-arming a
541
+ // torn-down session.
542
+ const generation = this.teardownGeneration;
543
+
544
+ // Safety-net await for non-iOS browsers (page.tsx:1809-1811).
545
+ await pipeline.resume();
546
+
547
+ // AU.4 — preload the Opus codec legs BEFORE the hello so the offer is
548
+ // only made when the client can actually honour it. A failed load
549
+ // (optional peer dep not installed / wasm compile failure) downgrades
550
+ // silently to the PCM16-only hello — never an error, never a broken
551
+ // session. Idempotent across re-arms (reconnect re-preloads only after
552
+ // resetAudio() freed the previous legs).
553
+ if (this.offerOpus && !this.opusCodecs) {
554
+ let loaded: OpusTransportCodecs | null = null;
555
+ try {
556
+ loaded = await createOpusTransportCodecs();
557
+ } catch (err) {
558
+ console.warn(
559
+ 'VoiceSession: Opus transport unavailable (libopus-wasm failed to load); staying on PCM16.',
560
+ err,
561
+ );
562
+ }
563
+ if (generation !== this.teardownGeneration || this.disposed) {
564
+ // Torn down mid-preload (claude[bot] P2 on #795): free what we just
565
+ // allocated and abandon the arm — resetAudio() already detached the
566
+ // handlers and destroyed the pipeline this method captured. Returns
567
+ // false so callers do NOT proceed as if armed (codex P2 on #795).
568
+ loaded?.free();
569
+ return false;
570
+ }
571
+ this.opusCodecs = loaded;
572
+ }
573
+ if (generation !== this.teardownGeneration || this.disposed) {
574
+ // Torn down while resume() was in flight — same abandonment, nothing
575
+ // allocated here to free (the codecs branch above returns on its own).
576
+ return false;
577
+ }
578
+
579
+ // Subscribe to the socket BEFORE the hello so no early frame is missed.
580
+ this.socket.onMessage(this.messageHandler);
581
+ this.socket.onBinary(this.binaryHandler);
582
+
583
+ // Barge-in: attach the session against the raw socket + start the
584
+ // playback-position tracker (page.tsx:1813-1827). `attachSession` wires the
585
+ // player; tracking makes the server's barge-in arbitration work against the
586
+ // real playhead.
587
+ const rawWs = this.socket.getRawSocket();
588
+ if (rawWs) {
589
+ pipeline.attachSession(rawWs);
590
+ pipeline.sessionClient?.startPlaybackTracking();
591
+ }
592
+
593
+ const hello = this.buildHello();
594
+ this.lastHello = hello;
595
+ this.socket.sendHello(hello);
596
+ this.audioOutputArmed = true;
597
+ return true;
598
+ }
599
+
257
600
  /**
258
601
  * Stop voice capture/playback but keep the session reusable. Mirrors the
259
602
  * page's `stopVoiceChat()` + `resetAudioState()`. Detaches socket handlers
@@ -272,32 +615,138 @@ export class VoiceSession {
272
615
  * `handleInterrupt()` — delegates to the pipeline's `bargeIn()` (which sends
273
616
  * the server `barge_in`, clears the player queue + visemes) and flips the
274
617
  * speaking flag off. No-op when nothing is playing.
618
+ *
619
+ * Returns the {@link InterruptResult} (what the server reports was spoken)
620
+ * when an attached audio session arbitrated the barge-in, or `null` when
621
+ * nothing was playing / no session is attached. The self-driving panel ignores
622
+ * the return value; the `/chat-ws` host reads `spokenText` to trim the
623
+ * interrupted assistant bubble (its page-owned `handleInterrupt` behavior) —
624
+ * surfacing it here is ADDITIVE (existing callers are unaffected).
275
625
  */
276
- async interrupt(): Promise<void> {
277
- if (!this.pipeline) return;
626
+ async interrupt(): Promise<InterruptResult | null> {
627
+ if (!this.pipeline) return null;
278
628
  try {
279
- await this.pipeline.bargeIn();
629
+ const result = await this.pipeline.bargeIn();
280
630
  this.callbacks.onSpeakingChange?.(false);
631
+ return result;
281
632
  } catch (err) {
282
633
  console.error('Failed to interrupt playback', err);
634
+ return null;
283
635
  }
284
636
  }
285
637
 
638
+ /**
639
+ * The word currently being spoken (the active TTS word at the live playhead),
640
+ * or `null` when nothing is playing or no word matches. A passthrough to the
641
+ * internal `AudioPipeline`'s playback tracker — the SAME position-anchored word
642
+ * the barge-in arbitration uses. The `/chat-ws` host polls this in a
643
+ * requestAnimationFrame loop (gated on `isAiSpeaking`) to drive its live
644
+ * word-display chip; the self-driving panel does not use it. ADDITIVE read-only.
645
+ */
646
+ getCurrentWord(): string | null {
647
+ return (
648
+ this.pipeline?.sessionClient?.getPlaybackTracker().getCurrentWord() ?? null
649
+ );
650
+ }
651
+
652
+ /**
653
+ * AU.2a — restore audio from a USER GESTURE after playback got stuck behind
654
+ * a suspended AudioContext (the state reported by `onPlaybackSuspended`).
655
+ * Resumes the SHARED player/mic AudioContext (one context since AU.2a, so a
656
+ * single resume unblocks BOTH halves) and drains the queued TTS burst in
657
+ * arrival order. MUST be called from the synchronous prefix of the tap/click
658
+ * handler — the `resume()` inside is exactly what iOS gates on the gesture.
659
+ * No-op when no pipeline exists. ADDITIVE.
660
+ */
661
+ async restoreAudio(): Promise<void> {
662
+ if (!this.pipeline) return;
663
+ await this.pipeline.resume();
664
+ }
665
+
286
666
  /**
287
667
  * Re-send the voice hello after a socket reconnect, IF a voice session is
288
668
  * active. Returns the payload (so a host that owns socket construction can
289
669
  * wire this into `ChatWebSocket`'s `onReconnect` option) or `null` when voice
290
670
  * is inactive (text reconnect — nothing to re-send). NOTE: it does NOT
291
- * re-prime the mic/AudioSession (the page does, but that path is iOS-gesture
292
- * gapped on an event-loop reconnect and requires the host to own socket
293
- * construction — tracked as a follow-up). The hello re-send alone restores
294
- * the server-side voice routing for the existing recorder's frames.
671
+ * re-prime the mic/AudioSession — use {@link handleReconnect} for the full
672
+ * re-prime (the hello re-send alone restores the server-side voice routing for
673
+ * an EXISTING recorder's frames, but a reconnect tears down the prior raw
674
+ * socket's audio session, so the mic/AudioSession must be re-armed against the
675
+ * new one).
295
676
  */
296
677
  reconnectHello(): HelloPayload | null {
297
- if (!this.active || !this.lastHello) return null;
678
+ // Re-send whenever the audio OUTPUT is armed — a typed-only synthesis
679
+ // session (SP1, `active === false`) still needs its `tts_stt` hello replayed
680
+ // after a reconnect, or the server falls back to the text loop and the next
681
+ // synthesized turn comes back silent.
682
+ if (!this.audioOutputArmed || !this.lastHello) return null;
298
683
  return this.lastHello;
299
684
  }
300
685
 
686
+ /**
687
+ * Re-prime the WHOLE voice path after a socket reconnect (#471): re-send the
688
+ * `tts_stt` hello AND re-arm the mic capture + AudioSession against the now-live
689
+ * socket. This is the SINGLE re-prime path the shared session owns — both the
690
+ * `/chat-ws` host (`useVoiceSession.reprimeAfterReconnect`) and the Conversation
691
+ * overlay/floater drive it, so there is NO forked re-prime/audio logic.
692
+ *
693
+ * A reconnect creates a NEW underlying raw socket: the prior audio session,
694
+ * barge-in tracker, and `MicrophoneRecorder` were wired to the dead one, so a
695
+ * lone hello re-send (`reconnectHello`) would leave the mic streaming into a
696
+ * detached pipeline. So:
697
+ * - A MIC session (`active`): `stop()` tears down the stale audio + handlers,
698
+ * then `start()` re-arms the recorder + output + re-sends the hello over the
699
+ * live socket — the behavior-preserving analogue of the page's manual
700
+ * recorder/AudioSession recreation. (Returns a promise that resolves once the
701
+ * recorder restarts, or rejects if the mic can't re-prime — iOS may decline
702
+ * without a fresh user gesture, the documented #471 caveat.)
703
+ * - An output-only typed-synthesis session (`audioOutputArmed && !active`):
704
+ * re-arm the output half (resume player + re-subscribe handlers + re-send the
705
+ * hello) WITHOUT the mic, mirroring `synthesizeReply`'s arm.
706
+ * - Inactive (no armed output): a no-op (text reconnect — nothing to re-prime).
707
+ *
708
+ * No-op (resolves) when the socket isn't connected yet or the session is
709
+ * disposed — the reconnect's own loop drives the next attempt.
710
+ */
711
+ async handleReconnect(): Promise<void> {
712
+ if (this.disposed) return;
713
+ if (!this.audioOutputArmed) return; // text-only / never started — nothing to re-prime.
714
+ if (!this.socket.isConnected) return;
715
+ if (this.active) {
716
+ // Mic session: tear down the dead-socket audio + recorder, then re-arm the
717
+ // full path (recorder + output + hello) against the live socket.
718
+ this.stop();
719
+ const started = this.start();
720
+ // AU.2a — the re-arm runs OUTSIDE a user gesture, so on iOS the awaited
721
+ // `resume()` inside start() can stay pending forever ("mic looks live,
722
+ // audio is silent"). Probe the context shortly after so the host's
723
+ // tap-to-restore overlay surfaces even while start() is still hanging;
724
+ // probe again after a successful start to clear it.
725
+ this.scheduleSuspendProbe();
726
+ await started;
727
+ this.pipeline?.notifyIfSuspended();
728
+ return;
729
+ }
730
+ // Output-only (typed synthesis, SP1): re-arm the output half over the live
731
+ // socket. `resetAudio()` cleared `audioOutputArmed` only if we tore down — we
732
+ // didn't (no stop()), so force a fresh arm by clearing the latch + handlers
733
+ // first so the hello is re-sent on the new raw socket.
734
+ this.resetAudio();
735
+ const armed = this.armAudioOutput();
736
+ this.scheduleSuspendProbe();
737
+ if (!(await armed)) return; // torn down mid-arm (codex P2 on #795)
738
+ this.pipeline?.notifyIfSuspended();
739
+ }
740
+
741
+ /** AU.2a — one-shot delayed suspension probe (see {@link handleReconnect}).
742
+ * Delayed so a fast, successful gesture-less resume (desktop browsers)
743
+ * never flashes the overlay. */
744
+ private scheduleSuspendProbe(): void {
745
+ setTimeout(() => {
746
+ if (!this.disposed) this.pipeline?.notifyIfSuspended();
747
+ }, VoiceSession.SUSPEND_PROBE_DELAY_MS);
748
+ }
749
+
301
750
  /**
302
751
  * Tear down. Stops audio + detaches handlers, then becomes inert. NEVER
303
752
  * closes the socket — the controller / adopting surface owns the transport
@@ -316,38 +765,119 @@ export class VoiceSession {
316
765
  /** Tear down audio resources + detach socket handlers, leaving the socket
317
766
  * open. Idempotent; mirrors the page's `resetAudioState`. */
318
767
  private resetAudio(): void {
768
+ // Invalidate any armAudioOutput() paused at an await (AU.4 — see
769
+ // `teardownGeneration`).
770
+ this.teardownGeneration += 1;
319
771
  this.socket.offMessage(this.messageHandler);
320
772
  this.socket.offBinary(this.binaryHandler);
321
773
  this.recorder?.stop();
322
774
  this.recorder = null;
775
+ // AU.3 — clear the local VAD so a stranded "user speaking" affordance
776
+ // never survives a stop/teardown, and drop the server-marker preference
777
+ // (a re-start may land on a different server generation).
778
+ this.micVad?.reset();
779
+ this.micVad = null;
780
+ this.serverTurnMarkers = false;
323
781
  if (this.pipeline) {
324
782
  void this.pipeline.destroy();
325
783
  this.pipeline = null;
326
784
  }
327
785
  this.audioReady = false;
786
+ // AU.4 — free the wasm codec legs + drop back to the PCM16 wire. A
787
+ // future arm re-preloads (and the next hello_ack re-negotiates), so a
788
+ // reconnect can land on either codec cleanly.
789
+ this.opusCodecs?.free();
790
+ this.opusCodecs = null;
791
+ this.activeCodec = CODEC_PCM16;
792
+ // The output half is torn down with the pipeline + handlers — a future arm
793
+ // (a re-`start()` or a typed `synthesizeReply()`) must re-send the hello +
794
+ // re-subscribe, so clear the latch here (SP1).
795
+ this.audioOutputArmed = false;
796
+ // UX-05 — drop any unmatched typed-turn echo marker on teardown so a
797
+ // never-echoed prompt (e.g. the socket dropped before the echo arrived)
798
+ // can't later suppress an unrelated identical transcript.
799
+ this.pendingTypedEcho = null;
328
800
  this.callbacks.onSpeakingChange?.(false);
329
801
  }
330
802
 
803
+ /**
804
+ * §Q DM.1 — duck persona TTS while a VISUAL TAKEOVER owns the surface (a
805
+ * cutscene clip, a world stream). Those play un-muted with their own music/SFX
806
+ * mux, so without this the DM and the takeover talk over each other at full
807
+ * volume.
808
+ *
809
+ * Hosts hold a `VoiceSession`, not the pipeline, so the control surfaces here.
810
+ * The requested gain is REMEMBERED across a pipeline that does not exist yet
811
+ * and re-applied on `start()`, because a takeover can be on screen before the
812
+ * session arms (the DM's own turn opens it).
813
+ *
814
+ * @param gain `AUDIO_TAKEOVER_DUCK_GAIN` while a takeover is up, `1` after.
815
+ */
816
+ setDuck(gain: number): void {
817
+ this.duckGain = gain;
818
+ this.pipeline?.setDuck(gain);
819
+ }
820
+
821
+ /** Restore full persona-TTS volume — the takeover was dismissed. */
822
+ clearDuck(): void {
823
+ this.setDuck(1);
824
+ }
825
+
331
826
  /**
332
827
  * Reset per-turn audio state for a new assistant reply. Mirrors the page's
333
828
  * new-assistant-turn reset (page.tsx:1244-1251): the pipeline's barge-in /
334
- * sentence-anchor state (`AudioPipeline.resetTurn`), the player's
335
- * `playbackOrigin` (so playback positions for the next reply are 0-based), and
336
- * the viseme scheduler (so a stale tail doesn't bleed into the new turn). The
337
- * pipeline's `player`/`visemeScheduler` are public readonly handles. No-op
338
- * before the first `start()` (no pipeline yet).
829
+ * sentence-anchor state (`AudioPipeline.resetTurn`) and the viseme scheduler
830
+ * (so a stale tail doesn't bleed into the new turn). The pipeline's
831
+ * `player`/`visemeScheduler` are public readonly handles. No-op before the
832
+ * first `start()` (no pipeline yet).
833
+ *
834
+ * **§Q PLYR.6 — `player.clearQueue()` drops the PREVIOUS turn's still-queued
835
+ * audio.** TTS is delivered ~6x faster than realtime (staging: 100 s of
836
+ * speech delivered in 15 s), so at this boundary the prior turn's tail is
837
+ * still scheduled minutes ahead; without the flush the new turn's first frame
838
+ * chained at that watermark and its voice trailed its own on-screen text by
839
+ * the whole residue — 71 s / 131 s / 201 s over three human-paced staging
840
+ * turns, compounding every turn. It lives HERE and not in
841
+ * `AudioPipeline.resetTurn()` because this is the only caller driven by the
842
+ * SERVER-authoritative boundary: `turn_start` is sent once per assistant turn
843
+ * and BEFORE any of its TTS frames (`api/chat/ws.py::send_turn_start`; a
844
+ * multi-speaker DM ensemble rides `turn_changed` inside ONE turn), so the
845
+ * queue here holds nothing but stale narration — the same thing
846
+ * `serverFlush()`/`bargeIn()` already drop. Other consumers call
847
+ * `AudioPipeline.resetTurn()` on their OWN, earlier boundaries and must not
848
+ * inherit the flush (codex P1 on #1514). `clearQueue()` also 0-bases the
849
+ * origin, so no separate `resetPlaybackOrigin()` is needed.
850
+ *
851
+ * Fires `onSpeakingChange(false)` for the same reason `serverFlush` does
852
+ * (codex P2 on #1514): the flush means nothing is audible between this
853
+ * boundary and the new turn's first frame (~6 s of LLM+TTS latency on
854
+ * staging), and `visemeScheduler.clear()` alone does NOT cover it — it only
855
+ * emits a `rest` transition when the viseme wasn't already at rest, so audio
856
+ * that carried no phoneme metadata would leave the host's `isAiSpeaking`
857
+ * (and its Interrupt affordance, which sends `barge_in`) stuck on across the
858
+ * generation gap. The new turn's first frame re-asserts `true`.
339
859
  */
340
860
  private resetTurn(): void {
341
861
  if (!this.pipeline) return;
862
+ this.pipeline.player.clearQueue();
342
863
  this.pipeline.resetTurn();
343
- this.pipeline.player.playbackOrigin = 0;
344
864
  this.pipeline.visemeScheduler.clear();
865
+ this.callbacks.onSpeakingChange?.(false);
345
866
  }
346
867
 
347
868
  private handleMessage(message: WebSocketMessage): void {
348
869
  switch (message.type) {
349
870
  case 'hello_ack': {
871
+ // AU.4 — settle the wire codec. `'opus'` only when the server acked
872
+ // it AND our codec legs are loaded (they are — the offer is only
873
+ // made after a successful preload; the guard is a hard invariant so
874
+ // a pathological ack can never select a codec we can't run).
875
+ this.activeCodec =
876
+ message.negotiatedCodec === CODEC_OPUS && this.opusCodecs
877
+ ? CODEC_OPUS
878
+ : CODEC_PCM16;
350
879
  this.audioReady = true;
880
+ this.callbacks.onAudioReady?.();
351
881
  this.callbacks.onStatus?.(
352
882
  'Audio handshake acknowledged. Streaming microphone frames.',
353
883
  );
@@ -356,6 +886,7 @@ export class VoiceSession {
356
886
  }
357
887
  case 'transcript': {
358
888
  this.audioReady = true;
889
+ this.callbacks.onAudioReady?.();
359
890
  const text = message.text?.trim() ?? '';
360
891
  if (message.final) {
361
892
  // A final transcript begins a NEW assistant turn. Reset the
@@ -365,7 +896,27 @@ export class VoiceSession {
365
896
  // playback positions relative to the FIRST audio frame of the whole
366
897
  // session and a later-turn Interrupt makes the server think the reply
367
898
  // was already fully spoken (codex P2; mirrors page.tsx:1244-1251).
368
- this.resetTurn();
899
+ // AU.3 — once the server has shown it emits `turn_start` markers,
900
+ // THEY own the turn boundary: skipping this consumer-timed reset
901
+ // closes the AU.1 early-clear race (stale tail frames of a barged
902
+ // reply must stay latched until the server's marker).
903
+ if (!this.serverTurnMarkers) this.resetTurn();
904
+ // UX-05 — suppress the typed-turn echo. When this final transcript is
905
+ // the server echoing the just-typed prompt (matches the pending
906
+ // marker), consume the marker and DON'T re-emit `onTranscript`: the
907
+ // panel already rendered this user bubble in `handleSend` (a typed
908
+ // turn). The `resetTurn()` above still ran (the reply's audio is
909
+ // tracked identically). A SPOKEN mic turn never sets the marker, so its
910
+ // transcript falls through and appends as before. Single-shot: the
911
+ // marker is cleared on match, so a later identical transcript (a
912
+ // re-typed/spoken duplicate) appends normally.
913
+ if (
914
+ this.pendingTypedEcho !== null &&
915
+ text === this.pendingTypedEcho
916
+ ) {
917
+ this.pendingTypedEcho = null;
918
+ return;
919
+ }
369
920
  if (text) this.callbacks.onTranscript?.(text, true);
370
921
  } else {
371
922
  this.callbacks.onTranscript?.(text, false);
@@ -376,16 +927,43 @@ export class VoiceSession {
376
927
  // Visemes + word timestamps. The pipeline buffers metadata that races
377
928
  // ahead of binary frames (Inworld ASYNC mode) and schedules visemes
378
929
  // through the SINGLE scheduler → `onViseme`.
379
- this.pipeline?.handleAudioMetadata(
930
+ // Only assert "speaking" when the pipeline ACCEPTED the metadata —
931
+ // post-barge latched drops (AU.1a) must not flip the UI back to
932
+ // speaking for visemes that will never render.
933
+ const accepted = this.pipeline?.handleAudioMetadata(
380
934
  message as unknown as Parameters<AudioPipeline['handleAudioMetadata']>[0],
381
935
  );
382
- this.callbacks.onSpeakingChange?.(true);
936
+ if (accepted) this.callbacks.onSpeakingChange?.(true);
383
937
  return;
384
938
  }
385
939
  case 'barge_in_ack': {
386
940
  this.callbacks.onSpeakingChange?.(false);
387
941
  return;
388
942
  }
943
+ case 'turn_start': {
944
+ // AU.3 — server-authoritative turn boundary: re-arm the post-barge
945
+ // latch + per-turn playback state exactly when the server starts a
946
+ // new assistant turn. First sighting flips the session to
947
+ // server-marker mode (the transcript-driven reset is skipped from
948
+ // then on — see the `transcript` case).
949
+ this.serverTurnMarkers = true;
950
+ this.resetTurn();
951
+ // Restart position updates for the new turn: `resetForNewTurn()`
952
+ // stopped the tracking interval, and the server's barge arbitration
953
+ // (spokenText trimming) depends on fresh `playback_position` frames.
954
+ this.pipeline?.sessionClient?.startPlaybackTracking();
955
+ return;
956
+ }
957
+ case 'tts_flush': {
958
+ // AU.3 — the server arbitrated a barge-in (auto or button echo):
959
+ // drop in-flight audio/visemes and latch until the next turn_start.
960
+ // NO client→server `barge_in` send here (the server already ran the
961
+ // cancel path — `serverFlush` is the local half only).
962
+ this.pipeline?.serverFlush();
963
+ this.callbacks.onSpeakingChange?.(false);
964
+ this.callbacks.onInterrupted?.(message.reason ?? 'barge_in');
965
+ return;
966
+ }
389
967
  default:
390
968
  // token/citation/image/done/error/turn_changed/tool_result/metrics —
391
969
  // the panel's text consumer owns those; VoiceSession only handles the
@@ -396,7 +974,33 @@ export class VoiceSession {
396
974
 
397
975
  private handleBinary(data: ArrayBuffer): void {
398
976
  if (!this.pipeline) return;
399
- this.pipeline.handleBinaryFrame(data);
400
- this.callbacks.onSpeakingChange?.(true);
977
+ // AU.4 TTS leg: on a negotiated-Opus session, TAG_AI_OPUS frames are
978
+ // decoded back to 16 kHz PCM16 and re-framed as legacy TAG_AI frames —
979
+ // the pipeline (player, jitter buffer, viseme anchoring, tracker) stays
980
+ // codec-agnostic. A corrupt packet drops THAT packet only (one 20 ms
981
+ // gap), never the session — the backend's mic-leg posture, mirrored.
982
+ if (this.activeCodec === CODEC_OPUS && this.opusCodecs && isAiOpusFrame(data)) {
983
+ let pcmFrames: ArrayBuffer[];
984
+ try {
985
+ pcmFrames = this.opusCodecs.ttsDecoder.decodeWireFrame(data);
986
+ } catch (err) {
987
+ console.error('Failed to Opus-decode TTS frame', err);
988
+ return;
989
+ }
990
+ let accepted = false;
991
+ for (const pcmFrame of pcmFrames) {
992
+ accepted = this.pipeline.handleBinaryFrame(pcmFrame) || accepted;
993
+ }
994
+ if (accepted) this.callbacks.onSpeakingChange?.(true);
995
+ return;
996
+ }
997
+ // Only assert "speaking" for frames the pipeline ACCEPTED — frames the
998
+ // post-barge latch DROPS (AU.1a) produce no audio and no visemes, so
999
+ // flipping isAiSpeaking true for them would strand the UI in "speaking"
1000
+ // (barge_in_ack already set it false; the viseme-rest transition that
1001
+ // normally clears it never fires for dropped frames).
1002
+ if (this.pipeline.handleBinaryFrame(data)) {
1003
+ this.callbacks.onSpeakingChange?.(true);
1004
+ }
401
1005
  }
402
1006
  }