@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
@@ -0,0 +1,1270 @@
1
+ /**
2
+ * HappyOyster world adapter — the client-core half of the Reactor HappyOyster
3
+ * launch path (§Q SB-W.1, spec `specs/2026-07-24-storyboard-generator.md` §6).
4
+ *
5
+ * WHAT THE SDK OWNS vs WHAT LIVES HERE. HappyOyster ships a dedicated typed SDK
6
+ * (`@reactor-models/happy-oyster`, v0.2.1 / model v2.0.0) — NOT the generic
7
+ * `@reactor-team/js-sdk` command session the Helios/LongLive/Sana adapters
8
+ * drive. Its `HappyOysterModel` facade owns the transport, the world lifecycle
9
+ * (`connect` → `createWorld`/`attachWorld` → `startTravel`), the seed-image
10
+ * validation (`firstFrameImageIssue`: the 2 MB cap + the 1.5–2.0 landscape
11
+ * aspect-ratio bound), and the `<video>` attachment. This module owns the parts
12
+ * the SDK does NOT provide and that BOTH the React `web/` app and the Vue
13
+ * `../Web-App` need identically:
14
+ *
15
+ * 1. **Prompt validation.** The 2000-character cap is documented but the SDK
16
+ * does NOT enforce it client-side (verified against the published
17
+ * `createWorldPayload` — it forwards `params.prompt` verbatim). An
18
+ * over-long prompt fails server-side after a session is already open, so
19
+ * {@link happyOysterPromptIssue} fails fast instead.
20
+ * 2. **The world handle.** Worlds are PERMANENT and there is no listing API —
21
+ * the `encrypted_world_id` is the only way back. It is NOT sufficient on
22
+ * its own: the two experiences are separate mode-fixed Reactor models
23
+ * (`reactor/happy-oyster-adventure` / `reactor/happy-oyster-director`) and
24
+ * `attachWorld` rejects a world belonging to the other mode with
25
+ * `MODE_MISMATCH`. So the persisted handle is `{encryptedWorldId, mode}` —
26
+ * see {@link HappyOysterWorldHandle}.
27
+ * 3. **Error classification.** The SDK throws `HappyOysterActionError` with a
28
+ * raw gate code and surfaces upstream numeric codes untranslated;
29
+ * {@link classifyHappyOysterError} maps both onto the one reason vocabulary
30
+ * every surface renders.
31
+ * 4. **The launch sequence** — {@link launchHappyOysterWorld}, the
32
+ * create-or-reopen orchestrator (the HappyOyster analogue of
33
+ * `bootstrapSceneInReactor` / `bootstrapSanaLiveEdit`).
34
+ *
35
+ * FRAMEWORK- AND SDK-AGNOSTIC: pure data + functions, NO React/Vue/DOM/SDK
36
+ * imports (the discipline of the rest of `reactor/`). The launcher drives the
37
+ * structural {@link HappyOysterBridge}, which `HappyOysterModel` satisfies
38
+ * as-is; `web/` owns the one `@reactor-models/happy-oyster` import.
39
+ */
40
+
41
+ import { HAPPY_OYSTER_MODEL_ID } from '../adapters/experienceModelCatalog';
42
+ import {
43
+ REACTOR_CONNECTION_FAILED_CODE,
44
+ reactorConnectionRefusal,
45
+ type ReactorSessionRefusal,
46
+ } from './reactorSessionRefusal';
47
+ import type { WorldCapability } from '../adapters/capabilities';
48
+
49
+ /**
50
+ * The two HappyOyster experiences. The mode is fixed at client construction —
51
+ * it selects WHICH Reactor model the session connects to, so it cannot change
52
+ * for the life of a session or of a world.
53
+ *
54
+ * Deliberately the SDK's CANONICAL spellings only. SDK 0.2.1 still accepts the
55
+ * legacy `'director'` alias for source compatibility but marks it
56
+ * `@deprecated`; admitting it here would let two spellings of one mode reach
57
+ * persisted world handles.
58
+ */
59
+ export type HappyOysterMode = 'adventure' | 'directing';
60
+
61
+ /** Every valid {@link HappyOysterMode}, for runtime validation of a persisted
62
+ * or user-supplied mode (a stored handle is untrusted input). */
63
+ export const HAPPY_OYSTER_MODES: readonly HappyOysterMode[] = [
64
+ 'adventure',
65
+ 'directing',
66
+ ];
67
+
68
+ /**
69
+ * Maximum `createWorld` prompt length. Documented by the vendor and enforced
70
+ * upstream; **the SDK does not check it client-side**, so this module does.
71
+ */
72
+ export const HAPPY_OYSTER_PROMPT_MAX_CHARS = 2000;
73
+
74
+ /**
75
+ * Why a prompt is unusable, or `null` when it is fine. Returns a
76
+ * human-readable sentence (the `firstFrameImageIssue` convention the SDK uses
77
+ * for seed images) so a surface can render it verbatim.
78
+ */
79
+ export function happyOysterPromptIssue(prompt: string): string | null {
80
+ const trimmed = prompt.trim();
81
+ if (trimmed.length === 0) {
82
+ return 'A world prompt is required — describe the world in natural language.';
83
+ }
84
+ if (prompt.length > HAPPY_OYSTER_PROMPT_MAX_CHARS) {
85
+ return `The world prompt is ${prompt.length} characters; the limit is ${HAPPY_OYSTER_PROMPT_MAX_CHARS} — shorten it before launching.`;
86
+ }
87
+ return null;
88
+ }
89
+
90
+ /**
91
+ * How long `createWorld` takes before the world is enterable — MEASURED, not
92
+ * documented. SB-W.1 timed ~105 s on one live staging run and still `building`
93
+ * past 240 s on another, and the vendor publishes no figure. A host must
94
+ * therefore render a long-running progress affordance (elapsed time + the
95
+ * phase) rather than a spinner that implies seconds, and must not impose a
96
+ * short client-side timeout.
97
+ */
98
+ export const HAPPY_OYSTER_BUILD_FAST_MS = 105_000;
99
+ export const HAPPY_OYSTER_BUILD_OBSERVED_MAX_MS = 240_000;
100
+
101
+ /**
102
+ * §Q `DM.42` — how long the vendor gives the LIVE STREAM to arrive after the
103
+ * world is already built, before it ends the travel itself. **60 s, and it is
104
+ * NOT tunable from this codebase.**
105
+ *
106
+ * Read out of the shipped SDK, not guessed: `HappyOysterModel.doStartTravel`
107
+ * calls `startTravel({credentials, videoElement})` with no `streamReadyTimeout`,
108
+ * and `travel.ts` then constructs the engine with
109
+ * `streamReadyTimeout: options.streamReadyTimeout ?? 6e4`. There is no seam
110
+ * between those two lines, so no host can lengthen this.
111
+ *
112
+ * Why a host must know the number anyway: this bound is the ONLY thing
113
+ * separating "the world is still building" (105–240 s, and fine) from "the
114
+ * world is built and no video ever came" (a dead travel). A surface that shows
115
+ * one progress message across both windows tells the player the build is slow
116
+ * when the build finished minutes ago — measured 2026-08-01, where the pane
117
+ * held *"Reopening this world…"* for the full 60 s on a world whose own phase
118
+ * had already reached `traveling`.
119
+ *
120
+ * What happens at the deadline, measured on staging the same day: the SDK POSTs
121
+ * `travels/end`, rejects `startTravel()` with a message containing the word
122
+ * "timeout", and `doStartTravel`'s `isTransientGatewayError` regex matches that
123
+ * word — so it re-requests credentials and tries again, up to 3 attempts. The
124
+ * repeated `enter-travel`/`end` pairs a host sees are that ladder, not a host
125
+ * bug and not something a host can interrupt.
126
+ */
127
+ export const HAPPY_OYSTER_STREAM_START_TIMEOUT_MS = 60_000;
128
+
129
+ /**
130
+ * How many times the SDK's `doStartTravel` tries to open the stream before it
131
+ * gives up — the ladder described on {@link HAPPY_OYSTER_STREAM_START_TIMEOUT_MS}
132
+ * (read out of the shipped SDK, not tunable from here).
133
+ */
134
+ export const HAPPY_OYSTER_STREAM_START_ATTEMPTS = 3;
135
+
136
+ /**
137
+ * §Q `WORLD.24` — THE LONGEST A HEALTHY LAUNCH IS ALLOWED TO GO UNSETTLED.
138
+ *
139
+ * A host keys its session management on the launch SETTLING, so that a build
140
+ * is never interrupted mid-`createWorld` (an abort there can lose the id of a
141
+ * world the vendor already minted). That rule has a hole: a vendor call that
142
+ * hangs after the session connected never settles, and a session nobody
143
+ * manages bills for the rest of the page. Past this bound the host stops
144
+ * waiting for the launch and manages the session it can SEE.
145
+ *
146
+ * Derived, not guessed, and deliberately LONG — the note on
147
+ * {@link HAPPY_OYSTER_BUILD_OBSERVED_MAX_MS} forbids a short client-side
148
+ * timeout. Twice the longest build ever observed (that 240 s run was still
149
+ * `building`, so it is a floor, not a ceiling) plus the whole stream-start
150
+ * ladder: 11 minutes. It never aborts anything; it only ends the wait.
151
+ */
152
+ export const HAPPY_OYSTER_LAUNCH_SETTLE_BOUND_MS =
153
+ 2 * HAPPY_OYSTER_BUILD_OBSERVED_MAX_MS +
154
+ HAPPY_OYSTER_STREAM_START_ATTEMPTS * HAPPY_OYSTER_STREAM_START_TIMEOUT_MS;
155
+
156
+ /**
157
+ * How long the media track takes to come back after `resume()` — MEASURED.
158
+ * `pause()` does not freeze the stream, it TEARS THE TRACK DOWN: the video
159
+ * element drops to `readyState 0` with `videoWidth`/`videoHeight` 0 and
160
+ * `currentTime` reset, so the pane is BLACK (not a held frame) until the
161
+ * track is re-established ~5–10 s later on a RESET timeline.
162
+ *
163
+ * Two consequences every HappyOyster host inherits: it owes a "resuming…"
164
+ * state for that window (SB-W.2), and a playhead must never be derived from
165
+ * `video.currentTime` across a pause (SB-W.4).
166
+ */
167
+ export const HAPPY_OYSTER_RESUME_MEDIA_MIN_MS = 5_000;
168
+ export const HAPPY_OYSTER_RESUME_MEDIA_MAX_MS = 10_000;
169
+
170
+ /**
171
+ * What a `<video>` element reports about the live HappyOyster track. Declared
172
+ * structurally so this module stays DOM-free and a host can feed it a sampled
173
+ * snapshot (or a test a literal).
174
+ */
175
+ export interface HappyOysterVideoSample {
176
+ /** `HTMLMediaElement.readyState`. */
177
+ readyState: number;
178
+ videoWidth: number;
179
+ videoHeight: number;
180
+ }
181
+
182
+ /**
183
+ * `HAVE_CURRENT_DATA` — the lowest `readyState` at which the element has a
184
+ * frame to paint. Below it the pane is black.
185
+ */
186
+ export const HAPPY_OYSTER_VIDEO_READY_STATE_MIN = 2;
187
+
188
+ /**
189
+ * Whether the pane is actually showing live video. This is the ONE test for
190
+ * "the track is back", used to clear a resuming state and (SB-W.4) to
191
+ * re-baseline a playhead. The element is the only trustworthy witness: a
192
+ * paused HappyOyster stream reports `readyState 0` with zero dimensions long
193
+ * after the pause/resume call has returned, so a host that waits on the
194
+ * facade's own flags uncovers a black stage.
195
+ */
196
+ export function happyOysterVideoIsLive(sample: HappyOysterVideoSample): boolean {
197
+ return (
198
+ sample.readyState >= HAPPY_OYSTER_VIDEO_READY_STATE_MIN &&
199
+ sample.videoWidth > 0 &&
200
+ sample.videoHeight > 0
201
+ );
202
+ }
203
+
204
+ /**
205
+ * The permanent handle to a HappyOyster world — what a frame / Library artifact
206
+ * stores so the world can be REOPENED later.
207
+ *
208
+ * `mode` is part of the handle, not incidental metadata: worlds live on the
209
+ * mode-fixed model that created them and `attachWorld` rejects the other mode's
210
+ * worlds with `MODE_MISMATCH`, so reopening requires knowing which model to
211
+ * connect to BEFORE connecting.
212
+ */
213
+ export interface HappyOysterWorldHandle {
214
+ /** The vendor's opaque, permanent world id (`encrypted_world_id`). */
215
+ encryptedWorldId: string;
216
+ /** The mode-fixed model that owns the world — required to reopen it. */
217
+ mode: HappyOysterMode;
218
+ }
219
+
220
+ /** Whether an unknown value (a persisted record, an API payload) is a usable
221
+ * {@link HappyOysterWorldHandle}. Rejects an unknown/legacy mode spelling
222
+ * rather than letting it reach `attachWorld` and fail with MODE_MISMATCH. */
223
+ export function isHappyOysterWorldHandle(
224
+ value: unknown,
225
+ ): value is HappyOysterWorldHandle {
226
+ if (typeof value !== 'object' || value === null) return false;
227
+ const candidate = value as Partial<HappyOysterWorldHandle>;
228
+ return (
229
+ typeof candidate.encryptedWorldId === 'string' &&
230
+ candidate.encryptedWorldId.length > 0 &&
231
+ typeof candidate.mode === 'string' &&
232
+ (HAPPY_OYSTER_MODES as readonly string[]).includes(candidate.mode)
233
+ );
234
+ }
235
+
236
+ /**
237
+ * Build a handle from a raw `world_state` snapshot. Returns `null` when the
238
+ * snapshot carries no world id yet (the `no_world` / `creating` / `building`
239
+ * phases all report `encrypted_world_id: null`).
240
+ */
241
+ export function happyOysterWorldHandle(
242
+ snapshot: { encrypted_world_id: string | null },
243
+ mode: HappyOysterMode,
244
+ ): HappyOysterWorldHandle | null {
245
+ const id = snapshot.encrypted_world_id;
246
+ return id === null || id.length === 0
247
+ ? null
248
+ : { encryptedWorldId: id, mode };
249
+ }
250
+
251
+ /**
252
+ * Upstream (HappyOyster gateway) numeric error codes, as shipped in the SDK's
253
+ * bundled `BackendErrorCode` table. Recorded here because the surfaces need to
254
+ * tell a retryable failure from a permanent rejection, and because the SPEC's
255
+ * §13.2 risk note is WRONG about one of them: it calls 403005 the
256
+ * "image/prompt-mismatch rejection". Per the shipped table 403005 is a
257
+ * COPYRIGHT violation and 403004 is the content-moderation rejection; there is
258
+ * no distinct "image does not match the prompt" code at all. A seed image the
259
+ * model refuses surfaces as one of the two content codes, and a seed image with
260
+ * the wrong shape surfaces as {@link HAPPY_OYSTER_ERROR_PARAM_INVALID}.
261
+ */
262
+ export const HAPPY_OYSTER_ERROR_PARAM_INVALID = 400000;
263
+ export const HAPPY_OYSTER_ERROR_WORLD_NOT_OWNED = 403001;
264
+ export const HAPPY_OYSTER_ERROR_WORLD_NOT_READY = 403002;
265
+ export const HAPPY_OYSTER_ERROR_MAIN_API_KEY_REQUIRED = 403003;
266
+ export const HAPPY_OYSTER_ERROR_CONTENT_MODERATION = 403004;
267
+ export const HAPPY_OYSTER_ERROR_CONTENT_COPYRIGHT = 403005;
268
+
269
+ /**
270
+ * The single reason vocabulary every HappyOyster surface renders. Collapses the
271
+ * SDK's string gate codes (`TRAVELING` / `BUSY` / `NO_WORLD` /
272
+ * `WORLD_NOT_READY` / `MODE_MISMATCH`) and the upstream numeric codes above
273
+ * into the distinctions a UI actually acts on.
274
+ */
275
+ export type HappyOysterFailureReason =
276
+ /** The world/prompt/seed was rejected on content grounds (403004 / 403005). */
277
+ | 'content_rejected'
278
+ /** The request itself was malformed — e.g. a seed image outside the 2 MB /
279
+ * 1.5–2.0 landscape bounds, or an over-long prompt that reached upstream. */
280
+ | 'invalid_request'
281
+ /** The saved world id is unknown or belongs to another account (403001). */
282
+ | 'world_not_found'
283
+ /** The stored handle's mode does not match the connected model. */
284
+ | 'mode_mismatch'
285
+ /** A travel is live, so the world API is locked — end the travel first. */
286
+ | 'traveling'
287
+ /** The world exists but is not ready to enter yet; retry. */
288
+ | 'not_ready'
289
+ /** Anything else (transport, gateway, unclassified). */
290
+ | 'unknown';
291
+
292
+ /** A classified HappyOyster failure, ready to render. */
293
+ export interface HappyOysterFailure {
294
+ reason: HappyOysterFailureReason;
295
+ /** The underlying message, for the detail line / console. */
296
+ message: string;
297
+ /** Whether retrying the SAME call can plausibly succeed. */
298
+ retryable: boolean;
299
+ }
300
+
301
+ /** Reasons a plain retry can resolve. */
302
+ const RETRYABLE_REASONS: readonly HappyOysterFailureReason[] = [
303
+ 'not_ready',
304
+ 'traveling',
305
+ ];
306
+
307
+ /**
308
+ * Classify a thrown SDK error into the {@link HappyOysterFailureReason}
309
+ * vocabulary. Reads the `code` carried by `HappyOysterActionError` (a string
310
+ * gate code) and, failing that, looks for an upstream numeric code in the
311
+ * message — the SDK surfaces gateway rejections as message text, so the numeric
312
+ * codes are matched there rather than assumed to be structured.
313
+ */
314
+ export function classifyHappyOysterError(error: unknown): HappyOysterFailure {
315
+ const message =
316
+ error instanceof Error
317
+ ? error.message
318
+ : typeof error === 'string'
319
+ ? error
320
+ : 'HappyOyster request failed';
321
+ const gateCode =
322
+ typeof error === 'object' &&
323
+ error !== null &&
324
+ typeof (error as { code?: unknown }).code === 'string'
325
+ ? (error as { code: string }).code
326
+ : null;
327
+
328
+ const reason = ((): HappyOysterFailureReason => {
329
+ switch (gateCode) {
330
+ case 'MODE_MISMATCH':
331
+ return 'mode_mismatch';
332
+ case 'TRAVELING':
333
+ case 'BUSY':
334
+ return 'traveling';
335
+ case 'NO_WORLD':
336
+ case 'WORLD_NOT_READY':
337
+ return 'not_ready';
338
+ default:
339
+ break;
340
+ }
341
+ if (
342
+ message.includes(String(HAPPY_OYSTER_ERROR_CONTENT_MODERATION)) ||
343
+ message.includes(String(HAPPY_OYSTER_ERROR_CONTENT_COPYRIGHT))
344
+ ) {
345
+ return 'content_rejected';
346
+ }
347
+ if (message.includes(String(HAPPY_OYSTER_ERROR_WORLD_NOT_OWNED))) {
348
+ return 'world_not_found';
349
+ }
350
+ if (message.includes(String(HAPPY_OYSTER_ERROR_WORLD_NOT_READY))) {
351
+ return 'not_ready';
352
+ }
353
+ if (message.includes(String(HAPPY_OYSTER_ERROR_PARAM_INVALID))) {
354
+ return 'invalid_request';
355
+ }
356
+ return 'unknown';
357
+ })();
358
+
359
+ return { reason, message, retryable: RETRYABLE_REASONS.includes(reason) };
360
+ }
361
+
362
+ /**
363
+ * The HappyOyster adapter descriptor. STRUCTURALLY mirrors
364
+ * `WorldAdapterDescriptor` but is a STANDALONE record (not registered in
365
+ * `createWorldRegistry()`) for the same reason the Sana descriptor is: the
366
+ * registry's `dispatchWorldCommand` speaks the generic `@reactor-team/js-sdk`
367
+ * command grammar, and HappyOyster is driven through its own typed SDK facade
368
+ * instead. Its catalog row is appended from {@link HAPPY_OYSTER_MODEL_ID}.
369
+ *
370
+ * `capabilities` reuses the EXISTING {@link WorldCapability} members only — no
371
+ * union widening (adding a member breaks `web/`'s exhaustive consumers).
372
+ * `set_scene` is the abstract scene-steering axis, which HappyOyster fulfills
373
+ * via `instruct` the way LongLive fulfills it via `set_shot`.
374
+ */
375
+ export interface HappyOysterAdapterDescriptor {
376
+ readonly id: string;
377
+ readonly displayName: string;
378
+ readonly provider: string;
379
+ readonly capabilities: readonly WorldCapability[];
380
+ readonly supportedCommands: readonly string[];
381
+ /** The ADVENTURE session's held-input verbs (§Q MOMENT.3) — see the field
382
+ * comment on {@link happyOysterWorldAdapter}. */
383
+ readonly adventureCommands: readonly string[];
384
+ }
385
+
386
+ export const happyOysterWorldAdapter = {
387
+ id: HAPPY_OYSTER_MODEL_ID,
388
+ displayName: 'HappyOyster',
389
+ provider: 'reactor',
390
+ capabilities: ['world_stream', 'set_scene', 'swap_seed', 'pause_resume'],
391
+ // The typed SDK's own method vocabulary (not generic Reactor wire commands):
392
+ // the world lifecycle plus the directing-mode steering verbs.
393
+ supportedCommands: [
394
+ 'createWorld',
395
+ 'attachWorld',
396
+ 'startTravel',
397
+ 'instruct',
398
+ 'pause',
399
+ 'resume',
400
+ 'rewind',
401
+ ],
402
+ // §Q MOMENT.3 — the ADVENTURE session's held-input verbs, from the typed
403
+ // SDK's own surface (`@reactor-models/happy-oyster`: hold a direction until
404
+ // `release(axes)`/`stop()`; `interact` takes the verbs the live world
405
+ // advertises in `travelState.character_actions`/`environment_actions`).
406
+ // This model IS the DM's walkable model (owner ruling 2026-08-19,
407
+ // `momentPolicy.ts`), and the walkable model must ADVERTISE movement — the
408
+ // prior descriptor listed only lifecycle + directing verbs, which is exactly
409
+ // why its worlds played like cutscenes. `instruct` is deliberately NOT here:
410
+ // it is a DIRECTING verb the vendor rejects on an adventure travel
411
+ // (§Q MOMENT.0, measured live 2026-08-19). Kept apart from
412
+ // `supportedCommands` so no existing consumer's vocabulary widens.
413
+ adventureCommands: ['move', 'look', 'interact', 'hold', 'release', 'stop'],
414
+ } as const satisfies HappyOysterAdapterDescriptor;
415
+
416
+ /**
417
+ * The minimum `world_state` snapshot shape the launcher reads. Structural
418
+ * subset of the SDK's `WorldStateMessage` so this module imports no SDK types.
419
+ */
420
+ export interface HappyOysterWorldSnapshot {
421
+ phase: string;
422
+ encrypted_world_id: string | null;
423
+ first_frame: string | null;
424
+ prompt: string | null;
425
+ }
426
+
427
+ /**
428
+ * §Q `DM.77` — THE ONE SESSION STATUS `connect()` WILL ACCEPT.
429
+ *
430
+ * `Reactor.connect` opens with `if (this.status !== 'disconnected') throw new
431
+ * Error('Already connected or connecting')`
432
+ * (`@reactor-team/js-sdk/dist/index.mjs:3319`). HappyOyster's own override only
433
+ * de-dupes an IN-FLIGHT connect (it memoises `connectPromise` and clears it in
434
+ * `finally`), so a connect issued after the first one SETTLED goes straight
435
+ * through to that throw.
436
+ */
437
+ export const HAPPY_OYSTER_SESSION_DISCONNECTED = 'disconnected';
438
+
439
+ /** The session status that means an open, usable session — the state a second
440
+ * world entry re-uses instead of re-connecting. */
441
+ export const HAPPY_OYSTER_SESSION_READY = 'ready';
442
+
443
+ /**
444
+ * The SDK's own connect-guard message, verbatim. It is the ONLY signal that
445
+ * separates a connect attempt that has SETTLED and left the status stuck from
446
+ * one that is still IN FLIGHT — the four-value status cannot tell them apart
447
+ * (codex on #1690).
448
+ */
449
+ export const HAPPY_OYSTER_CONNECT_GUARD_MESSAGE =
450
+ 'Already connected or connecting';
451
+
452
+ /** Whether a thrown value is the SDK's connect guard. */
453
+ export function isHappyOysterConnectGuardError(error: unknown): boolean {
454
+ return (
455
+ error instanceof Error &&
456
+ error.message.includes(HAPPY_OYSTER_CONNECT_GUARD_MESSAGE)
457
+ );
458
+ }
459
+
460
+ /**
461
+ * What a launch must do about the session before it touches the world API.
462
+ *
463
+ * - `'connect'` — no session yet (or the host does not report one): open it.
464
+ * - `'reuse'` — a READY session is already open; `connect()` would throw.
465
+ * - `'reset'` — a session is half-open (`connecting`/`waiting`). AMBIGUOUS by
466
+ * construction: that is BOTH what a connect still in flight looks like and
467
+ * what the SDK leaves behind after a FAILED one (only the session-loss
468
+ * retry path calls `setStatus('disconnected')`). The status cannot separate
469
+ * them, so the launcher connects FIRST and only tears down when the connect
470
+ * comes back with the guard — see {@link launchHappyOysterWorld}.
471
+ */
472
+ export type HappyOysterConnectStep = 'connect' | 'reuse' | 'reset';
473
+
474
+ /**
475
+ * §Q `DM.77` — DECIDE THE CONNECT STEP FROM THE SESSION STATUS.
476
+ *
477
+ * Measured live on staging AND on a PR preview, 3/3 runs (DM.71 #1687): ANY
478
+ * second world entry in one page load died on `data-launch-kind="error"`,
479
+ * `unknown / "Already connected or connecting"`. The vendor's own natural stop
480
+ * at ~t+70 s leaves the SDK's `HappyOysterModel` at phase `'connected'` with
481
+ * its Reactor status still `'ready'` — the session is deliberately KEPT so the
482
+ * permanent world stays attachable — and the launcher unconditionally called
483
+ * `connect()` again. So the recovery affordance `DM.66` shipped for exactly
484
+ * that moment threw on every click.
485
+ *
486
+ * Why a REUSE and not a disconnect-then-reconnect: `HappyOysterModel.disconnect`
487
+ * does not clear `worldState`, and `doConnect`'s `waitForFirstSnapshot`
488
+ * short-circuits while `worldState` is non-null — so a reset carries the same
489
+ * snapshot staleness a reuse does, plus a session teardown. Re-using a ready
490
+ * session is what the vendor's own `attachWorld` contract expects.
491
+ *
492
+ * An UNREPORTED status (`null`/`undefined` — a bridge that predates this, e.g.
493
+ * the Vue app's) keeps the old unconditional connect. This is additive: no
494
+ * existing caller changes behaviour until it supplies `sessionStatus`.
495
+ */
496
+ export function happyOysterConnectStep(
497
+ status: string | null | undefined,
498
+ ): HappyOysterConnectStep {
499
+ if (status === undefined || status === null) return 'connect';
500
+ if (status === HAPPY_OYSTER_SESSION_DISCONNECTED) return 'connect';
501
+ return status === HAPPY_OYSTER_SESSION_READY ? 'reuse' : 'reset';
502
+ }
503
+
504
+ /** §Q `WORLD.17` — the slice of the SDK's `ReactorError` the launcher reads. */
505
+ export interface HappyOysterConnectionError {
506
+ code: string;
507
+ message: string;
508
+ }
509
+
510
+ /**
511
+ * The structural bridge the launcher drives — satisfied as-is by the SDK's
512
+ * `HappyOysterModel`. Structural so client-core takes NO
513
+ * `@reactor-models/happy-oyster` dependency (mirrors `SanaReactorBridge`).
514
+ */
515
+ export interface HappyOysterBridge {
516
+ /** Open the Reactor session (does NOT create a world). */
517
+ connect: (jwt?: string) => Promise<void>;
518
+ /**
519
+ * §Q `DM.77` — the SDK session status (`Reactor.getStatus()`), read by
520
+ * {@link happyOysterConnectStep} so a SECOND entry in one page load does not
521
+ * re-`connect()` an already-open session and throw.
522
+ *
523
+ * OPTIONAL, and its absence is the pre-DM.77 behaviour, because
524
+ * `HappyOysterBridge` is published and `../Web-App` is pinned. A host that
525
+ * can report it SHOULD: without it, re-entry is broken.
526
+ */
527
+ sessionStatus?: () => string | null | undefined;
528
+ /**
529
+ * §Q `DM.77` — tear a half-open session down so a fresh `connect()` is legal.
530
+ * Only reached on {@link HappyOysterConnectStep} `'reset'`; a bridge that
531
+ * cannot do it falls back to connecting (and to the vendor's throw), which is
532
+ * exactly what it did before.
533
+ */
534
+ disconnect?: () => Promise<void>;
535
+ /**
536
+ * §Q `DM.78` — the identity of the vendor SESSION this bridge drives (hosts
537
+ * pass the SDK model). Launches whose bridges share it share ONE launch lock
538
+ * (see {@link HAPPY_OYSTER_CREATE_IN_FLIGHT_MESSAGE} and §Q `DM.97`'s
539
+ * {@link HAPPY_OYSTER_REOPEN_IN_FLIGHT_MESSAGE}).
540
+ *
541
+ * It exists because a bridge object is not a session: a React host that
542
+ * builds its bridge in a `useMemo` over unmemoised facade members gets a NEW
543
+ * bridge every render, so a lock keyed on the bridge would never see the
544
+ * second launch. OPTIONAL — the bridge is published and `../Web-App` is
545
+ * pinned — and absent it the bridge object itself is the key, which still
546
+ * covers a host that hands the same bridge (or the model itself) to every
547
+ * launch.
548
+ */
549
+ sessionKey?: object;
550
+ /**
551
+ * §Q `WORLD.17` — the SDK's last connection error (`Reactor.getLastError()`).
552
+ *
553
+ * Read because a REFUSED connect never settles on this SDK: `Reactor.connect`
554
+ * reports the failure (`createError('CONNECTION_FAILED', …)`) and then awaits
555
+ * `this.disconnect(false)` before rethrowing, and `HappyOysterModel`
556
+ * overrides `disconnect()` to await its own in-flight `connectPromise` —
557
+ * which is the connect doing the awaiting. The promise hangs forever, the
558
+ * status stays `connecting`, and on the 2026-10-09 staging walk a 402
559
+ * `credits_depleted` left the pane on "Building the world…" for the whole
560
+ * run. The error is the only part of that failure that ever surfaces.
561
+ *
562
+ * OPTIONAL for the same reason as {@link sessionStatus}: the bridge is
563
+ * published and `../Web-App` is pinned. Without it a refused connect hangs
564
+ * exactly as it did before.
565
+ */
566
+ connectionError?: () => HappyOysterConnectionError | null | undefined;
567
+ /**
568
+ * §Q `WORLD.17` — subscribe to the SDK's `error` event; returns the
569
+ * unsubscribe. Lets the launcher reject the moment a connect is refused
570
+ * instead of awaiting the promise the SDK never settles (see
571
+ * {@link connectionError}).
572
+ */
573
+ onConnectionError?: (
574
+ handler: (error: HappyOysterConnectionError) => void,
575
+ ) => () => void;
576
+ /** Create a new world of the bridge's fixed mode and wait for it to be ready. */
577
+ createWorld: (params: {
578
+ prompt: string;
579
+ firstFrameImage?: File | Blob;
580
+ firstFrameImageUrl?: string;
581
+ }) => Promise<HappyOysterWorldSnapshot>;
582
+ /** Reopen a permanent world by its encrypted id. */
583
+ attachWorld: (encryptedWorldId: string) => Promise<HappyOysterWorldSnapshot>;
584
+ /** Open the live video stream for the bound world. */
585
+ startTravel: () => Promise<{ streaming: boolean }>;
586
+ }
587
+
588
+ /** What to launch: a brand-new world, or a reopen of a permanent one. */
589
+ export type HappyOysterLaunchInput =
590
+ | {
591
+ kind: 'create';
592
+ /** The composed world prompt (≤ {@link HAPPY_OYSTER_PROMPT_MAX_CHARS}). */
593
+ prompt: string;
594
+ /** A local seed image. The SDK validates its size + aspect ratio and
595
+ * uploads it; mutually exclusive with `firstFrameImageUrl`. */
596
+ firstFrameImage?: File | Blob;
597
+ /** A publicly-fetchable seed image URL (HappyOyster fetches it itself). */
598
+ firstFrameImageUrl?: string;
599
+ }
600
+ | { kind: 'reopen'; handle: HappyOysterWorldHandle };
601
+
602
+ /** The outcome of a successful launch. */
603
+ export interface HappyOysterLaunchResult {
604
+ /** The permanent handle — persist it to reopen this world later. */
605
+ handle: HappyOysterWorldHandle;
606
+ /** The world snapshot the model reported ready. */
607
+ snapshot: HappyOysterWorldSnapshot;
608
+ /** False when the session ran against the vendor's mock backend (nothing
609
+ * streams) — the SDK reports this rather than throwing — and false whenever
610
+ * the launch was asked not to travel at all (§Q `MOMENT.15`
611
+ * {@link HappyOysterLaunchOptions.skipTravel}). Read
612
+ * {@link HappyOysterLaunchResult.traveled} to tell those apart: `streaming`
613
+ * answers "is video flowing", not "was a travel attempted". */
614
+ streaming: boolean;
615
+ /**
616
+ * §Q `MOMENT.15` — whether {@link HappyOysterBridge.startTravel} was CALLED.
617
+ *
618
+ * A mint-loop launch skips travel: it exists to create the world and bind its
619
+ * handle, and opening a live stream per world would add the vendor's 60 s
620
+ * stream-start bound (plus its 3-attempt ladder) to every beat and stream
621
+ * video nobody is watching. Without this field a caller cannot distinguish
622
+ * "no travel was attempted" from "a travel ran against the mock backend".
623
+ */
624
+ traveled: boolean;
625
+ }
626
+
627
+ /**
628
+ * Thrown by {@link launchHappyOysterWorld}; carries the classified reason so a
629
+ * surface renders one message path for every failure mode.
630
+ */
631
+ export class HappyOysterLaunchError extends Error {
632
+ readonly reason: HappyOysterFailureReason;
633
+ readonly retryable: boolean;
634
+ /**
635
+ * The world that ALREADY EXISTS despite this failure, or `null` when the
636
+ * launch failed before any world was created.
637
+ *
638
+ * This is not a convenience — it is the only thing standing between a
639
+ * failed `startTravel()` and an orphaned asset. Worlds are permanent, the
640
+ * vendor has no listing API, and `createWorld` bills whether or not the
641
+ * stream then opens. A caller MUST persist this handle in its failure path
642
+ * exactly as it persists a successful launch's.
643
+ */
644
+ readonly handle: HappyOysterWorldHandle | null;
645
+ /**
646
+ * §Q `WORLD.17` — the vendor's refusal of the SESSION itself (HTTP 402
647
+ * `credits_depleted`, capacity, any refused session create), or `null` when
648
+ * the launch failed for any other reason. Carried beside `reason` rather
649
+ * than as a new {@link HappyOysterFailureReason} member because that union is
650
+ * published and consumers switch on it exhaustively. OPTIONAL so a
651
+ * structural mock of this class written before WORLD.17 still type-checks;
652
+ * read it as `err.vendorRefusal ?? null`.
653
+ */
654
+ readonly vendorRefusal?: ReactorSessionRefusal | null;
655
+
656
+ constructor(
657
+ failure: HappyOysterFailure,
658
+ options?: {
659
+ cause?: unknown;
660
+ handle?: HappyOysterWorldHandle | null;
661
+ vendorRefusal?: ReactorSessionRefusal | null;
662
+ },
663
+ ) {
664
+ super(failure.message, options);
665
+ this.name = 'HappyOysterLaunchError';
666
+ this.reason = failure.reason;
667
+ this.retryable = failure.retryable;
668
+ this.handle = options?.handle ?? null;
669
+ this.vendorRefusal = options?.vendorRefusal ?? null;
670
+ }
671
+ }
672
+
673
+ /**
674
+ * Build the launch error for a FAILED connect (no world exists yet). Every
675
+ * `CONNECTION_FAILED` has to end the launch — the SDK never settles any of
676
+ * them — but only a failure the vendor itself answered (a refused session
677
+ * create or poll, or a capacity/credits condition) is a VENDOR REFUSAL; an
678
+ * ICE, DNS or transport failure carries `vendorRefusal: null` and renders as
679
+ * the plain failure it is (codex on this PR).
680
+ */
681
+ function connectFailedLaunchError(error: HappyOysterConnectionError): HappyOysterLaunchError {
682
+ return new HappyOysterLaunchError(
683
+ { reason: 'unknown', message: error.message, retryable: false },
684
+ { vendorRefusal: reactorConnectionRefusal(error.message) },
685
+ );
686
+ }
687
+
688
+ /**
689
+ * §Q `WORLD.17` — the refusal a session is WEDGED on, or `null`.
690
+ *
691
+ * After a refused connect the SDK leaves the status `connecting` and memoises
692
+ * the connect promise it never settles (see
693
+ * {@link HappyOysterBridge.connectionError}), so a later entry's `connect()`
694
+ * joins that hung promise and its `error` event has already fired — nothing
695
+ * would ever answer it. A half-open status beside a `CONNECTION_FAILED` error
696
+ * is exactly that state on this SDK: it records `CONNECTION_FAILED` only on the
697
+ * way out of `connect()`, and on `HappyOysterModel` that exit never completes,
698
+ * so the status cannot leave `connecting` again. (`lastError` is never cleared,
699
+ * so an SDK that one day DOES recover would leave this error stale; the status
700
+ * would then read `disconnected` after the failure and this returns `null`.)
701
+ */
702
+ export function happyOysterWedgedRefusal(
703
+ bridge: Pick<HappyOysterBridge, 'sessionStatus' | 'connectionError'>,
704
+ ): HappyOysterConnectionError | null {
705
+ if (happyOysterConnectStep(bridge.sessionStatus?.()) !== 'reset') return null;
706
+ const error = bridge.connectionError?.() ?? null;
707
+ return error !== null && error.code === REACTOR_CONNECTION_FAILED_CODE ? error : null;
708
+ }
709
+
710
+ /**
711
+ * `bridge.connect`, raced against the SDK's own report that the connect was
712
+ * refused (§Q `WORLD.17`). A bridge that cannot report errors connects exactly
713
+ * as before.
714
+ */
715
+ async function connectOrRefusal(
716
+ bridge: HappyOysterBridge,
717
+ jwt: string | undefined,
718
+ ): Promise<void> {
719
+ const subscribe = bridge.onConnectionError;
720
+ if (subscribe === undefined) {
721
+ await bridge.connect(jwt);
722
+ return;
723
+ }
724
+ let unsubscribe: () => void = () => {};
725
+ const refused = new Promise<never>((_, reject) => {
726
+ unsubscribe = subscribe((error) => {
727
+ if (error.code === REACTOR_CONNECTION_FAILED_CODE) {
728
+ reject(connectFailedLaunchError(error));
729
+ }
730
+ });
731
+ });
732
+ try {
733
+ await Promise.race([bridge.connect(jwt), refused]);
734
+ } finally {
735
+ unsubscribe();
736
+ }
737
+ }
738
+
739
+ /**
740
+ * §Q `DM.78` — the refusal a launch gets while a `create` is still in flight on
741
+ * the same session: a second create would mint a second paid, permanent world,
742
+ * and a reopen would re-point the session's current world under the create.
743
+ * Exported so a surface or a probe can name the refusal without matching
744
+ * rendered copy.
745
+ */
746
+ export const HAPPY_OYSTER_CREATE_IN_FLIGHT_MESSAGE =
747
+ 'A world is still being created on this session — wait for it to finish. A second create now would mint a second paid, permanent world.';
748
+
749
+ /**
750
+ * §Q `DM.78` — the refusal a create gets when its session was taken over while
751
+ * it was in flight (its holder's lock was voided and a later launch reopened the
752
+ * session). The world it minted is real and is handed back on the error; the
753
+ * stream is NOT opened, because the session it would open on is no longer the
754
+ * one this launch connected. Exported for the same reason as
755
+ * {@link HAPPY_OYSTER_CREATE_IN_FLIGHT_MESSAGE}: this is the refusal that
756
+ * carries a minted handle, and a host grading it should not match prose.
757
+ */
758
+ export const HAPPY_OYSTER_CREATE_SESSION_REPLACED_MESSAGE =
759
+ 'The session this world was created on was closed and reopened by a later launch before the world could be entered — the world is saved; enter it again.';
760
+
761
+ /**
762
+ * §Q `DM.97` — the refusal a launch gets while a `reopen` is still in flight on
763
+ * the same session. `attachWorld` mints nothing, but it re-points the session's
764
+ * current world until the reopen's own `startTravel` engages the vendor's
765
+ * travel lock, so a create or a second reopen started inside that window would
766
+ * have one of the two launches enter the other's world. Exported for the same
767
+ * reason as {@link HAPPY_OYSTER_CREATE_IN_FLIGHT_MESSAGE}.
768
+ */
769
+ export const HAPPY_OYSTER_REOPEN_IN_FLIGHT_MESSAGE =
770
+ 'A world is still being opened on this session — wait for it to finish before launching another.';
771
+
772
+ /**
773
+ * §Q `DM.97` — the reopen counterpart of
774
+ * {@link HAPPY_OYSTER_CREATE_SESSION_REPLACED_MESSAGE}: the reopen's session was
775
+ * closed and taken over by a later launch while it was attaching, so it does
776
+ * NOT open the stream on the session that later launch owns. The handle it
777
+ * reopened is handed back on the error.
778
+ */
779
+ export const HAPPY_OYSTER_REOPEN_SESSION_REPLACED_MESSAGE =
780
+ 'The session this world was being opened on was closed and reopened by a later launch before the world could be entered — enter it again.';
781
+
782
+ /**
783
+ * One in-flight launch (§Q `DM.78` create, §Q `DM.97` reopen). `connected`
784
+ * flips once the launch has an open session (connected, or re-used a ready
785
+ * one), which is what lets a LATER launch tell "the holder's session is gone"
786
+ * apart from "the holder has not connected yet" — both read `disconnected`.
787
+ */
788
+ interface HappyOysterLaunchLockEntry {
789
+ kind: HappyOysterLaunchInput['kind'];
790
+ connected: boolean;
791
+ }
792
+
793
+ /** Keyed on {@link HappyOysterBridge.sessionKey} (or the bridge itself). A
794
+ * WeakMap so a discarded session never pins its lock in memory. */
795
+ const happyOysterLaunchLocks = new WeakMap<object, HappyOysterLaunchLockEntry>();
796
+
797
+ /**
798
+ * §Q `DM.78` / `DM.97` — TAKE THE SESSION'S LAUNCH LOCK, OR REFUSE.
799
+ *
800
+ * Before §Q `DM.77` a second concurrent `create` on a READY session died on the
801
+ * vendor's connect guard — by accident, not by design. DM.77 made a ready
802
+ * session re-usable, so two concurrent creates now BOTH reach `createWorld` and
803
+ * mint two permanent, billed worlds. Every shipped caller serialises its own
804
+ * launches today (the DM pane on `launchingRef`, World Explorer on `busy`), so
805
+ * nothing is exposed — but that is the invariant depending on each caller's
806
+ * discipline, and this is the launcher refusing on its own.
807
+ *
808
+ * The lock covers the WHOLE launch, `startTravel` included: the vendor
809
+ * re-points a session's current world freely until its own travel lock engages
810
+ * (`starting_stream` is set only after the credential request inside
811
+ * `startTravel`), so releasing it once `createWorld` returned would reopen the
812
+ * double-mint window rather than close it.
813
+ *
814
+ * §Q `DM.97` — BOTH KINDS take it. DM.78 locked only creates, so a reopen's
815
+ * in-flight `attachWorld`/`startTravel` could have a create (or a second
816
+ * reopen) re-point the session under it. The refusal names the holder's kind.
817
+ *
818
+ * A held lock is VOID — and the new launch takes it — only when the holder had
819
+ * connected and the session now reads `disconnected`: the holder's session is
820
+ * gone (§Q `WORLD.24`'s hidden-world lifecycle disconnects a launch that never
821
+ * settled), so nothing it does can mint on the session the new launch opens.
822
+ * Every other held state refuses, including a holder still connecting.
823
+ */
824
+ function refuseWhileLaunchInFlight(bridge: HappyOysterBridge): void {
825
+ const key = bridge.sessionKey ?? bridge;
826
+ const held = happyOysterLaunchLocks.get(key);
827
+ if (held === undefined) return;
828
+ if (held.connected && bridge.sessionStatus?.() === HAPPY_OYSTER_SESSION_DISCONNECTED) {
829
+ // VOID: the holder's session is gone. The new launch replaces the entry
830
+ // with its own, so the dead holder's `held()` reads false from here on and
831
+ // its late settle neither drives the new session nor frees its lock.
832
+ happyOysterLaunchLocks.delete(key);
833
+ return;
834
+ }
835
+ throw new HappyOysterLaunchError({
836
+ reason: 'invalid_request',
837
+ message:
838
+ held.kind === 'create'
839
+ ? HAPPY_OYSTER_CREATE_IN_FLIGHT_MESSAGE
840
+ : HAPPY_OYSTER_REOPEN_IN_FLIGHT_MESSAGE,
841
+ retryable: false,
842
+ });
843
+ }
844
+
845
+ function acquireHappyOysterLaunchLock(
846
+ bridge: HappyOysterBridge,
847
+ kind: HappyOysterLaunchInput['kind'],
848
+ ): {
849
+ entry: HappyOysterLaunchLockEntry;
850
+ /** Whether this launch STILL holds the lock — false once it was voided and
851
+ * a later launch took the session over. */
852
+ held: () => boolean;
853
+ release: () => void;
854
+ } {
855
+ refuseWhileLaunchInFlight(bridge);
856
+ const key = bridge.sessionKey ?? bridge;
857
+ const entry: HappyOysterLaunchLockEntry = { kind, connected: false };
858
+ happyOysterLaunchLocks.set(key, entry);
859
+ const held = () => happyOysterLaunchLocks.get(key) === entry;
860
+ return {
861
+ entry,
862
+ held,
863
+ // Only the holder's OWN entry is released: a holder whose lock was voided
864
+ // must not, when it finally settles, free the lock a later launch holds.
865
+ release: () => {
866
+ if (held()) happyOysterLaunchLocks.delete(key);
867
+ },
868
+ };
869
+ }
870
+
871
+ /**
872
+ * Create-or-reopen a HappyOyster world and start streaming it. The ONE launch
873
+ * sequence both the React and Vue surfaces run:
874
+ *
875
+ * 1. validate the prompt (the SDK does not) — fails BEFORE a session opens;
876
+ * 2. open the mode-fixed session — `connect()`, or REUSE an already-ready one
877
+ * (§Q `DM.77`: a second `connect()` throws);
878
+ * 3. `createWorld(...)` or `attachWorld(handle.encryptedWorldId)`;
879
+ * 4. `startTravel()` to open the live stream.
880
+ *
881
+ * `bridge` must already be constructed for `mode` — the SDK fixes the mode at
882
+ * construction, so a reopen whose handle carries the other mode is rejected
883
+ * HERE (before the round-trip) rather than upstream with `MODE_MISMATCH`.
884
+ *
885
+ * Every failure surfaces as a {@link HappyOysterLaunchError} carrying a
886
+ * classified {@link HappyOysterFailureReason}.
887
+ */
888
+ export async function launchHappyOysterWorld(
889
+ input: HappyOysterLaunchInput,
890
+ bridge: HappyOysterBridge,
891
+ mode: HappyOysterMode,
892
+ options: {
893
+ jwt?: string;
894
+ /**
895
+ * §Q `DM.43` — THE WORLD EXISTS FROM HERE ON, so record it from here on.
896
+ *
897
+ * Called the instant `createWorld`/`attachWorld` yields a world id and
898
+ * BEFORE {@link HappyOysterBridge.startTravel}, which is the call that can
899
+ * hang for minutes. Everything after this point — the vendor's 60 s
900
+ * stream-start bound (see
901
+ * {@link HAPPY_OYSTER_STREAM_START_TIMEOUT_MS}), its 3-attempt retry
902
+ * ladder, a reload, a tab close, a component unmount — happens to a world
903
+ * that is ALREADY PERMANENT AND ALREADY BILLED.
904
+ *
905
+ * The pre-existing `HappyOysterLaunchError.handle` rail is not a
906
+ * substitute: it only surrenders the id once the launch has finished
907
+ * failing, which is up to ~3 minutes later on a create. Anything that ends
908
+ * the page inside that window destroys the only reference to a paid asset,
909
+ * because HappyOyster worlds cannot be listed.
910
+ *
911
+ * A throw here is swallowed deliberately: recording is best-effort at this
912
+ * point and the success/failure paths persist again, so a transient
913
+ * write failure must not abort a launch that is otherwise fine.
914
+ */
915
+ onWorldCreated?: (handle: HappyOysterWorldHandle) => void | Promise<void>;
916
+ /**
917
+ * §Q `MOMENT.15` — CREATE (or attach) and STOP, without opening a stream.
918
+ *
919
+ * The mint loop pre-mints one world per beat at BOARD time so that play-time
920
+ * entry becomes an `attachWorld`. It needs step 3 and nothing after it: a
921
+ * `startTravel` per world would add the vendor's 60 s stream-start bound and
922
+ * its 3-attempt retry ladder to every beat — up to ~3 minutes each — and
923
+ * stream video to nobody.
924
+ *
925
+ * It is an option on THIS function rather than a second create path on
926
+ * purpose. The sequence's hard-won part is the §Q `DM.77` connect ladder
927
+ * (a second `connect()` throws `Already connected or connecting`, which is
928
+ * exactly what a loop does on its second iteration), and a separate
929
+ * mint-only function would re-derive it and get that wrong.
930
+ *
931
+ * The world is just as permanent and just as billed either way, so the §Q
932
+ * `DM.43` `onWorldCreated` rail still fires before this option can change
933
+ * anything.
934
+ */
935
+ skipTravel?: boolean;
936
+ } = {},
937
+ ): Promise<HappyOysterLaunchResult> {
938
+ if (input.kind === 'create') {
939
+ const issue = happyOysterPromptIssue(input.prompt);
940
+ if (issue !== null) {
941
+ throw new HappyOysterLaunchError({
942
+ reason: 'invalid_request',
943
+ message: issue,
944
+ retryable: false,
945
+ });
946
+ }
947
+ if (
948
+ input.firstFrameImage !== undefined &&
949
+ input.firstFrameImageUrl !== undefined
950
+ ) {
951
+ throw new HappyOysterLaunchError({
952
+ reason: 'invalid_request',
953
+ message:
954
+ 'Provide a seed image or a seed image URL, not both — HappyOyster accepts exactly one.',
955
+ retryable: false,
956
+ });
957
+ }
958
+ } else if (input.handle.mode !== mode) {
959
+ throw new HappyOysterLaunchError({
960
+ reason: 'mode_mismatch',
961
+ message: `This world belongs to the "${input.handle.mode}" experience; the open session is "${mode}". Reopen it from the ${input.handle.mode} surface.`,
962
+ retryable: false,
963
+ });
964
+ }
965
+
966
+ // §Q WORLD.17 — a session an earlier connect left wedged on a refusal can
967
+ // only be named, never joined: `connect()` would hand back the promise the
968
+ // SDK never settles, and `disconnect()` awaits that same promise. Checked
969
+ // BEFORE the DM.78 lock (Fable review on #2141): a create hung on that very
970
+ // connect still holds the lock, and refusing on the lock first would hide
971
+ // the vendor's named refusal behind "a world is still being created".
972
+ const wedged = happyOysterWedgedRefusal(bridge);
973
+ if (wedged !== null) throw connectFailedLaunchError(wedged);
974
+ // §Q DM.78 / DM.97 — one launch per session at a time, refused BEFORE
975
+ // anything is opened or billed. Both kinds lock: a create would mint a second
976
+ // paid world, and any launch's `attachWorld`/`createWorld` re-points the
977
+ // session's current world under the holder, whose `startTravel` would then
978
+ // open the wrong world.
979
+ const launchLock = acquireHappyOysterLaunchLock(bridge, input.kind);
980
+ // Tracked OUTSIDE the try so the catch can hand a created-but-unstreamed
981
+ // world back to the caller instead of orphaning it (permanent worlds, no
982
+ // listing API — `startTravel` failing must not lose the id).
983
+ let created: HappyOysterWorldHandle | null = null;
984
+ try {
985
+ // §Q DM.77 — connect ONLY when there is no usable session. The vendor
986
+ // throws "Already connected or connecting" on a second connect, which is
987
+ // what made every re-entry after the vendor's own stop fail.
988
+ const step = happyOysterConnectStep(bridge.sessionStatus?.());
989
+ if (step !== 'reuse') {
990
+ try {
991
+ await connectOrRefusal(bridge, options.jwt);
992
+ } catch (error) {
993
+ // ⛔ NEVER disconnect FIRST on a `'reset'` status. `connecting` and
994
+ // `waiting` are ALSO what a perfectly healthy connect looks like while
995
+ // it is still in flight, and tearing that down would kill a launch the
996
+ // SDK's own `connectPromise` had already de-duplicated for us — closing
997
+ // the RTC connection under a mounted video (codex on #1690).
998
+ //
999
+ // Calling `connect()` first tells the two apart with no guess: an
1000
+ // IN-FLIGHT connect is JOINED (the facade returns the memoised promise
1001
+ // and never reaches the guard), so anything that reaches this catch
1002
+ // either is that connect's real outcome or is the guard itself — and
1003
+ // only the guard means "settled, and the SDK left the status stuck".
1004
+ if (
1005
+ step !== 'reset' ||
1006
+ bridge.disconnect === undefined ||
1007
+ !isHappyOysterConnectGuardError(error)
1008
+ ) {
1009
+ throw error;
1010
+ }
1011
+ await bridge.disconnect();
1012
+ await connectOrRefusal(bridge, options.jwt);
1013
+ }
1014
+ }
1015
+ launchLock.entry.connected = true;
1016
+ const snapshot =
1017
+ input.kind === 'create'
1018
+ ? await bridge.createWorld({
1019
+ prompt: input.prompt,
1020
+ ...(input.firstFrameImage !== undefined
1021
+ ? { firstFrameImage: input.firstFrameImage }
1022
+ : {}),
1023
+ ...(input.firstFrameImageUrl !== undefined
1024
+ ? { firstFrameImageUrl: input.firstFrameImageUrl }
1025
+ : {}),
1026
+ })
1027
+ : await bridge.attachWorld(input.handle.encryptedWorldId);
1028
+
1029
+ const handle = happyOysterWorldHandle(snapshot, mode);
1030
+ if (handle === null) {
1031
+ throw new HappyOysterLaunchError({
1032
+ reason: 'not_ready',
1033
+ message: `HappyOyster reported phase "${snapshot.phase}" with no world id — the world is not ready to enter.`,
1034
+ retryable: true,
1035
+ });
1036
+ }
1037
+ created = handle;
1038
+ // §Q DM.43 — before `startTravel`, not after. See `onWorldCreated`.
1039
+ if (options.onWorldCreated !== undefined) {
1040
+ try {
1041
+ await options.onWorldCreated(handle);
1042
+ } catch {
1043
+ /* best-effort; the success/failure paths persist again */
1044
+ }
1045
+ }
1046
+
1047
+ // §Q DM.78 / DM.97 — a launch whose lock was VOIDED while it was in
1048
+ // flight (its session went away and a later launch reconnected it) must
1049
+ // not drive the session that later launch now owns. The world is real, so
1050
+ // it is handed back on the error exactly like any created-then-failed
1051
+ // launch.
1052
+ if (!launchLock.held()) {
1053
+ throw new HappyOysterLaunchError(
1054
+ {
1055
+ reason: 'unknown',
1056
+ message:
1057
+ input.kind === 'create'
1058
+ ? HAPPY_OYSTER_CREATE_SESSION_REPLACED_MESSAGE
1059
+ : HAPPY_OYSTER_REOPEN_SESSION_REPLACED_MESSAGE,
1060
+ retryable: false,
1061
+ },
1062
+ { handle },
1063
+ );
1064
+ }
1065
+
1066
+ // §Q MOMENT.15 — the mint loop stops here, with the world created, the
1067
+ // handle surrendered to `onWorldCreated`, and no stream opened.
1068
+ if (options.skipTravel === true) {
1069
+ return { handle, snapshot, streaming: false, traveled: false };
1070
+ }
1071
+
1072
+ const { streaming } = await bridge.startTravel();
1073
+ return { handle, snapshot, streaming, traveled: true };
1074
+ } catch (error) {
1075
+ if (error instanceof HappyOysterLaunchError) throw error;
1076
+ throw new HappyOysterLaunchError(classifyHappyOysterError(error), {
1077
+ cause: error,
1078
+ handle: created,
1079
+ });
1080
+ } finally {
1081
+ launchLock.release();
1082
+ }
1083
+ }
1084
+
1085
+ /* ==========================================================================
1086
+ * §Q WORLD.10 — THE TRAVEL LOCK, AND WHY IT WAS PERMANENT
1087
+ * ========================================================================== */
1088
+
1089
+ /**
1090
+ * The world phase during which the vendor LOCKS `createWorld` and `attachWorld`
1091
+ * (`WorldPhase` in `@reactor-models/happy-oyster` — *"A travel is live: the
1092
+ * world API (create/attach/credentials) is locked"*).
1093
+ */
1094
+ export const HAPPY_OYSTER_WORLD_PHASE_TRAVELING = 'traveling';
1095
+
1096
+ /** Client phases during which the vendor locks the world API. */
1097
+ export const HAPPY_OYSTER_LOCKED_CLIENT_PHASES: readonly string[] = [
1098
+ 'streaming',
1099
+ 'starting_stream',
1100
+ ];
1101
+
1102
+ /**
1103
+ * The vendor's own refusal, quoted. `assertWorldApiUnlocked` throws
1104
+ * `<method>() is locked while a travel is live — end the travel first`, and
1105
+ * this fragment is what a surface (or a harness verdict) matches to say the
1106
+ * refusal was the travel lock rather than any other launch failure.
1107
+ */
1108
+ export const HAPPY_OYSTER_TRAVEL_LOCK_MESSAGE = 'locked while a travel is live';
1109
+
1110
+ /** Whether an error is the vendor's travel-lock refusal. */
1111
+ export function isHappyOysterTravelLockError(error: unknown): boolean {
1112
+ const message =
1113
+ error instanceof Error
1114
+ ? error.message
1115
+ : typeof error === 'string'
1116
+ ? error
1117
+ : '';
1118
+ return message.includes(HAPPY_OYSTER_TRAVEL_LOCK_MESSAGE);
1119
+ }
1120
+
1121
+ /**
1122
+ * §Q WORLD.10 — IS THE WORLD API LOCKED RIGHT NOW? The vendor's condition,
1123
+ * mirrored, because the surface has to answer it BEFORE it calls create/attach.
1124
+ *
1125
+ * ⛔ **THREE ARMS, AND THE SHIPPED GUARD TESTED ONE.** The SDK's
1126
+ * `assertWorldApiUnlocked` refuses when the CLIENT phase is `streaming` **or**
1127
+ * `starting_stream`, **or** when the model's last `world_state` snapshot says
1128
+ * `traveling`. Both panes guarded on `facade.streaming` alone — which is
1129
+ * exactly `phase === 'streaming'` — so a lock held by either of the other two
1130
+ * arms was invisible to the very code whose job was to clear it.
1131
+ *
1132
+ * The world phase is the arm that made the failure PERMANENT (measured on the
1133
+ * §Q GROUND.82 connected run: world entries #2 and #3 both died on
1134
+ * `createWorld() is locked while a travel is live`). See
1135
+ * {@link ensureHappyOysterWorldApiUnlocked} for why ending the travel is not by
1136
+ * itself enough to clear it.
1137
+ */
1138
+ export function happyOysterWorldApiIsLocked(input: {
1139
+ clientPhase?: string | null;
1140
+ worldPhase?: string | null;
1141
+ }): boolean {
1142
+ const clientPhase = input.clientPhase ?? null;
1143
+ const worldPhase = input.worldPhase ?? null;
1144
+ return (
1145
+ (clientPhase !== null && HAPPY_OYSTER_LOCKED_CLIENT_PHASES.includes(clientPhase)) ||
1146
+ worldPhase === HAPPY_OYSTER_WORLD_PHASE_TRAVELING
1147
+ );
1148
+ }
1149
+
1150
+ /**
1151
+ * What a host must expose for {@link ensureHappyOysterWorldApiUnlocked} to
1152
+ * clear a travel lock. Every member is read from the vendor MODEL rather than
1153
+ * from React state on purpose: the model mirrors each message synchronously, so
1154
+ * a getter cannot hand back a value a re-render had not committed yet.
1155
+ */
1156
+ export interface HappyOysterTravelLockGate {
1157
+ /** `model.phase` — the client lifecycle phase. */
1158
+ clientPhase: () => string | null | undefined;
1159
+ /** `model.worldState?.phase` — the model's own world lifecycle phase. */
1160
+ worldPhase: () => string | null | undefined;
1161
+ /** `model.endTravelSession()` — end the live stream, keep the world. */
1162
+ endTravelSession: () => Promise<void>;
1163
+ /**
1164
+ * `model.requestState()` — ask the model for a fresh `world_state`.
1165
+ *
1166
+ * OPTIONAL because this package is published and `../Web-App` is pinned; a
1167
+ * host that cannot refresh keeps the pre-WORLD.10 behaviour (end the travel,
1168
+ * and hope the snapshot was current).
1169
+ */
1170
+ refreshWorldState?: () => Promise<void>;
1171
+ }
1172
+
1173
+ /** What clearing the lock actually took — reported, never swallowed. */
1174
+ export type HappyOysterUnlockOutcome =
1175
+ | 'unlocked'
1176
+ | 'travel_ended'
1177
+ | 'state_refreshed'
1178
+ | 'still_locked';
1179
+
1180
+ /** How long to wait for the refreshed `world_state` snapshot to arrive. */
1181
+ export const HAPPY_OYSTER_WORLD_STATE_REFRESH_MS = 5_000;
1182
+ /** How often to re-read the model's snapshot while waiting for that refresh. */
1183
+ export const HAPPY_OYSTER_WORLD_STATE_POLL_MS = 250;
1184
+
1185
+ /**
1186
+ * §Q WORLD.10 — MAKE THE WORLD API LEGAL AGAIN BEFORE OPENING THE NEXT WORLD.
1187
+ *
1188
+ * ⛔ **`endTravelSession()` CANNOT CLEAR THE LOCK ON ITS OWN, AND THAT IS THE
1189
+ * WHOLE ROW.** Read the vendor in order:
1190
+ *
1191
+ * 1. `travel_state` messages are mirrored onto `model.travelState` — and
1192
+ * **nulled** the moment the status is `completed` or `failed`
1193
+ * (`HappyOysterBase`'s constructor subscription).
1194
+ * 2. `endTravelSession()` reads `travelState?.encrypted_travel_id` and sends
1195
+ * the model's `end_travel` **and** `requestState()` ONLY when that id is
1196
+ * non-null. After a completion it is null, so the call collapses to
1197
+ * "clear the hold, drop the session, reset the client phase".
1198
+ * 3. `handleTravelCompleted()` — the SDK's own completion handler — likewise
1199
+ * never asks for a fresh snapshot.
1200
+ *
1201
+ * So once a travel COMPLETES, `model.worldState.phase` keeps saying `traveling`
1202
+ * with nothing in the session that will ever say otherwise, and every later
1203
+ * `createWorld`/`attachWorld` is refused. That is why the GROUND.82 run's world
1204
+ * entries #2 and #3 failed for the rest of the session while entry #1 had
1205
+ * painted: not a vendor bug, and not the missing exit hook the row guessed at,
1206
+ * but a snapshot nobody re-read.
1207
+ *
1208
+ * The sequence is therefore: end the travel (which clears the client-phase
1209
+ * arms, and the world-phase arm too whenever the SDK still knows the travel
1210
+ * id), then — if the world phase is STILL `traveling` — ask for a fresh
1211
+ * snapshot and wait for it, because `requestState()` only sends the request;
1212
+ * the answer arrives as a message.
1213
+ *
1214
+ * Returns what it took. A `'still_locked'` result is deliberately not a throw:
1215
+ * the caller proceeds and the vendor's own refusal stays the report, rather
1216
+ * than this function inventing a second failure vocabulary for the same fact.
1217
+ */
1218
+ export async function ensureHappyOysterWorldApiUnlocked(
1219
+ gate: HappyOysterTravelLockGate,
1220
+ options: {
1221
+ waitMs?: number;
1222
+ pollMs?: number;
1223
+ sleep?: (ms: number) => Promise<void>;
1224
+ now?: () => number;
1225
+ } = {},
1226
+ ): Promise<HappyOysterUnlockOutcome> {
1227
+ const locked = () =>
1228
+ happyOysterWorldApiIsLocked({
1229
+ clientPhase: gate.clientPhase() ?? null,
1230
+ worldPhase: gate.worldPhase() ?? null,
1231
+ });
1232
+ if (!locked()) return 'unlocked';
1233
+
1234
+ // ⛔ NEITHER VENDOR CALL MAY TAKE THE ENTRY DOWN WITH IT (own diff read).
1235
+ // `endTravelSession` swallows its own transport failures, but `requestState`
1236
+ // is a bare `sendCommand` that rejects on a session that has gone away — and
1237
+ // a launch that died on THAT would report an unclassified transport error in
1238
+ // place of the vendor's own refusal, which is the one message that says what
1239
+ // is actually wrong. A failed attempt to clear the lock leaves the lock, and
1240
+ // the lock is what gets reported.
1241
+ try {
1242
+ await gate.endTravelSession();
1243
+ } catch {
1244
+ /* the lock stands; the vendor's refusal below is the report */
1245
+ }
1246
+ if (!locked()) return 'travel_ended';
1247
+
1248
+ if (gate.refreshWorldState === undefined) return 'still_locked';
1249
+ const waitMs = options.waitMs ?? HAPPY_OYSTER_WORLD_STATE_REFRESH_MS;
1250
+ const pollMs = options.pollMs ?? HAPPY_OYSTER_WORLD_STATE_POLL_MS;
1251
+ const now = options.now ?? (() => Date.now());
1252
+ const sleep =
1253
+ options.sleep
1254
+ ?? ((ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)));
1255
+ try {
1256
+ await gate.refreshWorldState();
1257
+ } catch {
1258
+ // ⛔ RE-READ BEFORE REPORTING (codex on this PR). The request can clear the
1259
+ // lock and STILL reject — an acknowledgement or transport failure after the
1260
+ // snapshot landed — and returning a flat `still_locked` there would publish
1261
+ // a lock over an entry that then succeeds.
1262
+ return locked() ? 'still_locked' : 'state_refreshed';
1263
+ }
1264
+ const deadline = now() + waitMs;
1265
+ while (now() < deadline) {
1266
+ if (!locked()) return 'state_refreshed';
1267
+ await sleep(pollMs);
1268
+ }
1269
+ return locked() ? 'still_locked' : 'state_refreshed';
1270
+ }