@escapeaihq/client-core 0.52.0 → 0.139.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (782) hide show
  1. package/README.md +445 -153
  2. package/dist/adapters/capabilities.d.ts +20 -3
  3. package/dist/adapters/capabilities.d.ts.map +1 -1
  4. package/dist/adapters/directorAdapter.d.ts +5 -4
  5. package/dist/adapters/directorAdapter.d.ts.map +1 -1
  6. package/dist/adapters/directorAdapter.js +5 -4
  7. package/dist/adapters/directorAdapter.js.map +1 -1
  8. package/dist/adapters/experienceModelCatalog.d.ts +382 -0
  9. package/dist/adapters/experienceModelCatalog.d.ts.map +1 -0
  10. package/dist/adapters/experienceModelCatalog.js +401 -0
  11. package/dist/adapters/experienceModelCatalog.js.map +1 -0
  12. package/dist/adapters/extractionAdapter.d.ts +81 -0
  13. package/dist/adapters/extractionAdapter.d.ts.map +1 -0
  14. package/dist/adapters/extractionAdapter.js +98 -0
  15. package/dist/adapters/extractionAdapter.js.map +1 -0
  16. package/dist/adapters/imageAdapter.d.ts +5 -1
  17. package/dist/adapters/imageAdapter.d.ts.map +1 -1
  18. package/dist/adapters/imageAdapter.js +5 -1
  19. package/dist/adapters/imageAdapter.js.map +1 -1
  20. package/dist/adapters/index.d.ts +54 -16
  21. package/dist/adapters/index.d.ts.map +1 -1
  22. package/dist/adapters/index.js +62 -11
  23. package/dist/adapters/index.js.map +1 -1
  24. package/dist/adapters/momentDirective.d.ts +66 -0
  25. package/dist/adapters/momentDirective.d.ts.map +1 -0
  26. package/dist/adapters/momentDirective.js +78 -0
  27. package/dist/adapters/momentDirective.js.map +1 -0
  28. package/dist/adapters/momentPolicy.d.ts +132 -0
  29. package/dist/adapters/momentPolicy.d.ts.map +1 -0
  30. package/dist/adapters/momentPolicy.js +165 -0
  31. package/dist/adapters/momentPolicy.js.map +1 -0
  32. package/dist/adapters/registry.d.ts +1 -1
  33. package/dist/adapters/registry.d.ts.map +1 -1
  34. package/dist/adapters/videoGenAdapter.d.ts +55 -0
  35. package/dist/adapters/videoGenAdapter.d.ts.map +1 -0
  36. package/dist/adapters/videoGenAdapter.js +78 -0
  37. package/dist/adapters/videoGenAdapter.js.map +1 -0
  38. package/dist/adapters/worldAdapter.d.ts +132 -11
  39. package/dist/adapters/worldAdapter.d.ts.map +1 -1
  40. package/dist/adapters/worldAdapter.js +127 -11
  41. package/dist/adapters/worldAdapter.js.map +1 -1
  42. package/dist/adapters/worldModelPreference.d.ts +173 -0
  43. package/dist/adapters/worldModelPreference.d.ts.map +1 -0
  44. package/dist/adapters/worldModelPreference.js +209 -0
  45. package/dist/adapters/worldModelPreference.js.map +1 -0
  46. package/dist/adapters/worldModelTradeoffs.d.ts +120 -0
  47. package/dist/adapters/worldModelTradeoffs.d.ts.map +1 -0
  48. package/dist/adapters/worldModelTradeoffs.js +154 -0
  49. package/dist/adapters/worldModelTradeoffs.js.map +1 -0
  50. package/dist/admin.d.ts +545 -0
  51. package/dist/admin.d.ts.map +1 -1
  52. package/dist/admin.js +230 -16
  53. package/dist/admin.js.map +1 -1
  54. package/dist/api.d.ts +10295 -2216
  55. package/dist/api.d.ts.map +1 -1
  56. package/dist/api.js +4187 -1240
  57. package/dist/api.js.map +1 -1
  58. package/dist/arcBoardJoin.d.ts +38 -0
  59. package/dist/arcBoardJoin.d.ts.map +1 -0
  60. package/dist/arcBoardJoin.js +37 -0
  61. package/dist/arcBoardJoin.js.map +1 -0
  62. package/dist/arcPreview.d.ts +49 -0
  63. package/dist/arcPreview.d.ts.map +1 -0
  64. package/dist/arcPreview.js +65 -0
  65. package/dist/arcPreview.js.map +1 -0
  66. package/dist/audio.d.ts +259 -16
  67. package/dist/audio.d.ts.map +1 -1
  68. package/dist/audio.js +605 -114
  69. package/dist/audio.js.map +1 -1
  70. package/dist/audioDsp.d.ts +45 -0
  71. package/dist/audioDsp.d.ts.map +1 -0
  72. package/dist/audioDsp.js +108 -0
  73. package/dist/audioDsp.js.map +1 -0
  74. package/dist/audioProtocol.d.ts +160 -0
  75. package/dist/audioProtocol.d.ts.map +1 -1
  76. package/dist/audioProtocol.js +99 -0
  77. package/dist/audioProtocol.js.map +1 -1
  78. package/dist/beatTitles.d.ts +33 -0
  79. package/dist/beatTitles.d.ts.map +1 -0
  80. package/dist/beatTitles.js +39 -0
  81. package/dist/beatTitles.js.map +1 -0
  82. package/dist/castProjection.d.ts +204 -1
  83. package/dist/castProjection.d.ts.map +1 -1
  84. package/dist/castProjection.js +202 -0
  85. package/dist/castProjection.js.map +1 -1
  86. package/dist/characterGrounding.d.ts +369 -0
  87. package/dist/characterGrounding.d.ts.map +1 -0
  88. package/dist/characterGrounding.js +408 -0
  89. package/dist/characterGrounding.js.map +1 -0
  90. package/dist/conversation/binding.d.ts +13 -0
  91. package/dist/conversation/binding.d.ts.map +1 -1
  92. package/dist/conversation/binding.js.map +1 -1
  93. package/dist/conversation/chatSessionStore.d.ts +178 -0
  94. package/dist/conversation/chatSessionStore.d.ts.map +1 -0
  95. package/dist/conversation/chatSessionStore.js +196 -0
  96. package/dist/conversation/chatSessionStore.js.map +1 -0
  97. package/dist/conversation/controller.d.ts +44 -0
  98. package/dist/conversation/controller.d.ts.map +1 -1
  99. package/dist/conversation/controller.js +82 -3
  100. package/dist/conversation/controller.js.map +1 -1
  101. package/dist/conversation/index.d.ts +2 -0
  102. package/dist/conversation/index.d.ts.map +1 -1
  103. package/dist/conversation/index.js +2 -0
  104. package/dist/conversation/index.js.map +1 -1
  105. package/dist/conversation/participant.d.ts +16 -0
  106. package/dist/conversation/participant.d.ts.map +1 -1
  107. package/dist/conversation/readSequencer.d.ts +38 -0
  108. package/dist/conversation/readSequencer.d.ts.map +1 -0
  109. package/dist/conversation/readSequencer.js +42 -0
  110. package/dist/conversation/readSequencer.js.map +1 -0
  111. package/dist/conversation/roster.d.ts +5 -1
  112. package/dist/conversation/roster.d.ts.map +1 -1
  113. package/dist/conversation/roster.js.map +1 -1
  114. package/dist/conversation/rosterProjection.d.ts +74 -1
  115. package/dist/conversation/rosterProjection.d.ts.map +1 -1
  116. package/dist/conversation/rosterProjection.js +135 -1
  117. package/dist/conversation/rosterProjection.js.map +1 -1
  118. package/dist/conversation/runtime.d.ts +20 -3
  119. package/dist/conversation/runtime.d.ts.map +1 -1
  120. package/dist/conversation/runtime.js +66 -7
  121. package/dist/conversation/runtime.js.map +1 -1
  122. package/dist/conversation/types.d.ts +43 -4
  123. package/dist/conversation/types.d.ts.map +1 -1
  124. package/dist/conversation/voice.d.ts +290 -13
  125. package/dist/conversation/voice.d.ts.map +1 -1
  126. package/dist/conversation/voice.js +565 -42
  127. package/dist/conversation/voice.js.map +1 -1
  128. package/dist/creatorCuration.d.ts +134 -0
  129. package/dist/creatorCuration.d.ts.map +1 -0
  130. package/dist/creatorCuration.js +228 -0
  131. package/dist/creatorCuration.js.map +1 -0
  132. package/dist/creatorDashboard.d.ts +155 -0
  133. package/dist/creatorDashboard.d.ts.map +1 -0
  134. package/dist/creatorDashboard.js +237 -0
  135. package/dist/creatorDashboard.js.map +1 -0
  136. package/dist/creatorUniverse.d.ts +95 -0
  137. package/dist/creatorUniverse.d.ts.map +1 -0
  138. package/dist/creatorUniverse.js +136 -0
  139. package/dist/creatorUniverse.js.map +1 -0
  140. package/dist/curationWrite.d.ts +76 -0
  141. package/dist/curationWrite.d.ts.map +1 -0
  142. package/dist/curationWrite.js +106 -0
  143. package/dist/curationWrite.js.map +1 -0
  144. package/dist/designTokens.d.ts +64 -0
  145. package/dist/designTokens.d.ts.map +1 -0
  146. package/dist/designTokens.js +117 -0
  147. package/dist/designTokens.js.map +1 -0
  148. package/dist/dialogAttribution.d.ts +79 -0
  149. package/dist/dialogAttribution.d.ts.map +1 -0
  150. package/dist/dialogAttribution.js +144 -0
  151. package/dist/dialogAttribution.js.map +1 -0
  152. package/dist/dmRunWorldReadiness.d.ts +605 -0
  153. package/dist/dmRunWorldReadiness.d.ts.map +1 -0
  154. package/dist/dmRunWorldReadiness.js +775 -0
  155. package/dist/dmRunWorldReadiness.js.map +1 -0
  156. package/dist/domains/access.d.ts +32 -0
  157. package/dist/domains/access.d.ts.map +1 -0
  158. package/dist/domains/access.js +43 -0
  159. package/dist/domains/access.js.map +1 -0
  160. package/dist/domains/adventureDefinitions.d.ts +159 -0
  161. package/dist/domains/adventureDefinitions.d.ts.map +1 -0
  162. package/dist/domains/adventureDefinitions.js +168 -0
  163. package/dist/domains/adventureDefinitions.js.map +1 -0
  164. package/dist/domains/adventures.d.ts +329 -0
  165. package/dist/domains/adventures.d.ts.map +1 -0
  166. package/dist/domains/adventures.js +359 -0
  167. package/dist/domains/adventures.js.map +1 -0
  168. package/dist/domains/arcs.d.ts +146 -0
  169. package/dist/domains/arcs.d.ts.map +1 -0
  170. package/dist/domains/arcs.js +202 -0
  171. package/dist/domains/arcs.js.map +1 -0
  172. package/dist/domains/artifacts.d.ts +259 -0
  173. package/dist/domains/artifacts.d.ts.map +1 -0
  174. package/dist/domains/artifacts.js +125 -0
  175. package/dist/domains/artifacts.js.map +1 -0
  176. package/dist/domains/chat.d.ts +158 -0
  177. package/dist/domains/chat.d.ts.map +1 -0
  178. package/dist/domains/chat.js +224 -0
  179. package/dist/domains/chat.js.map +1 -0
  180. package/dist/domains/decisions.d.ts +31 -0
  181. package/dist/domains/decisions.d.ts.map +1 -0
  182. package/dist/domains/decisions.js +42 -0
  183. package/dist/domains/decisions.js.map +1 -0
  184. package/dist/domains/documents.d.ts +218 -0
  185. package/dist/domains/documents.d.ts.map +1 -0
  186. package/dist/domains/documents.js +252 -0
  187. package/dist/domains/documents.js.map +1 -0
  188. package/dist/domains/enhancements.d.ts +106 -0
  189. package/dist/domains/enhancements.d.ts.map +1 -0
  190. package/dist/domains/enhancements.js +160 -0
  191. package/dist/domains/enhancements.js.map +1 -0
  192. package/dist/domains/graph.d.ts +454 -0
  193. package/dist/domains/graph.d.ts.map +1 -0
  194. package/dist/domains/graph.js +648 -0
  195. package/dist/domains/graph.js.map +1 -0
  196. package/dist/domains/images.d.ts +220 -0
  197. package/dist/domains/images.d.ts.map +1 -0
  198. package/dist/domains/images.js +307 -0
  199. package/dist/domains/images.js.map +1 -0
  200. package/dist/domains/ingestion.d.ts +312 -0
  201. package/dist/domains/ingestion.d.ts.map +1 -0
  202. package/dist/domains/ingestion.js +495 -0
  203. package/dist/domains/ingestion.js.map +1 -0
  204. package/dist/domains/me.d.ts +21 -0
  205. package/dist/domains/me.d.ts.map +1 -0
  206. package/dist/domains/me.js +23 -0
  207. package/dist/domains/me.js.map +1 -0
  208. package/dist/domains/orgs.d.ts +47 -0
  209. package/dist/domains/orgs.d.ts.map +1 -0
  210. package/dist/domains/orgs.js +75 -0
  211. package/dist/domains/orgs.js.map +1 -0
  212. package/dist/domains/personas.d.ts +138 -0
  213. package/dist/domains/personas.d.ts.map +1 -0
  214. package/dist/domains/personas.js +322 -0
  215. package/dist/domains/personas.js.map +1 -0
  216. package/dist/domains/projects.d.ts +53 -0
  217. package/dist/domains/projects.d.ts.map +1 -0
  218. package/dist/domains/projects.js +94 -0
  219. package/dist/domains/projects.js.map +1 -0
  220. package/dist/domains/quests.d.ts +431 -0
  221. package/dist/domains/quests.d.ts.map +1 -0
  222. package/dist/domains/quests.js +61 -0
  223. package/dist/domains/quests.js.map +1 -0
  224. package/dist/domains/reactor.d.ts +98 -0
  225. package/dist/domains/reactor.d.ts.map +1 -0
  226. package/dist/domains/reactor.js +131 -0
  227. package/dist/domains/reactor.js.map +1 -0
  228. package/dist/domains/showcase.d.ts +28 -0
  229. package/dist/domains/showcase.d.ts.map +1 -0
  230. package/dist/domains/showcase.js +28 -0
  231. package/dist/domains/showcase.js.map +1 -0
  232. package/dist/domains/storyboards.d.ts +1253 -0
  233. package/dist/domains/storyboards.d.ts.map +1 -0
  234. package/dist/domains/storyboards.js +781 -0
  235. package/dist/domains/storyboards.js.map +1 -0
  236. package/dist/domains/studioSettings.d.ts +39 -0
  237. package/dist/domains/studioSettings.d.ts.map +1 -0
  238. package/dist/domains/studioSettings.js +80 -0
  239. package/dist/domains/studioSettings.js.map +1 -0
  240. package/dist/domains/universes.d.ts +191 -0
  241. package/dist/domains/universes.d.ts.map +1 -0
  242. package/dist/domains/universes.js +276 -0
  243. package/dist/domains/universes.js.map +1 -0
  244. package/dist/domains/userDefaults.d.ts +18 -0
  245. package/dist/domains/userDefaults.d.ts.map +1 -0
  246. package/dist/domains/userDefaults.js +27 -0
  247. package/dist/domains/userDefaults.js.map +1 -0
  248. package/dist/domains/visemeBundles.d.ts +262 -0
  249. package/dist/domains/visemeBundles.d.ts.map +1 -0
  250. package/dist/domains/visemeBundles.js +373 -0
  251. package/dist/domains/visemeBundles.js.map +1 -0
  252. package/dist/domains/workflows.d.ts +142 -0
  253. package/dist/domains/workflows.d.ts.map +1 -0
  254. package/dist/domains/workflows.js +245 -0
  255. package/dist/domains/workflows.js.map +1 -0
  256. package/dist/enhancementDiff.d.ts +56 -0
  257. package/dist/enhancementDiff.d.ts.map +1 -0
  258. package/dist/enhancementDiff.js +110 -0
  259. package/dist/enhancementDiff.js.map +1 -0
  260. package/dist/generated/contract.d.ts +372 -0
  261. package/dist/generated/contract.d.ts.map +1 -0
  262. package/dist/generated/contract.js +395 -0
  263. package/dist/generated/contract.js.map +1 -0
  264. package/dist/graphSchema.d.ts +36 -5
  265. package/dist/graphSchema.d.ts.map +1 -1
  266. package/dist/graphSchema.js +88 -2
  267. package/dist/graphSchema.js.map +1 -1
  268. package/dist/http.d.ts +70 -1
  269. package/dist/http.d.ts.map +1 -1
  270. package/dist/http.js +263 -11
  271. package/dist/http.js.map +1 -1
  272. package/dist/identity.d.ts +81 -0
  273. package/dist/identity.d.ts.map +1 -0
  274. package/dist/identity.js +65 -0
  275. package/dist/identity.js.map +1 -0
  276. package/dist/index.d.ts +35 -0
  277. package/dist/index.d.ts.map +1 -1
  278. package/dist/index.js +118 -0
  279. package/dist/index.js.map +1 -1
  280. package/dist/messageContent.d.ts +174 -0
  281. package/dist/messageContent.d.ts.map +1 -0
  282. package/dist/messageContent.js +405 -0
  283. package/dist/messageContent.js.map +1 -0
  284. package/dist/mutationEpoch.d.ts +83 -0
  285. package/dist/mutationEpoch.d.ts.map +1 -0
  286. package/dist/mutationEpoch.js +109 -0
  287. package/dist/mutationEpoch.js.map +1 -0
  288. package/dist/obo.d.ts +144 -0
  289. package/dist/obo.d.ts.map +1 -0
  290. package/dist/obo.js +135 -0
  291. package/dist/obo.js.map +1 -0
  292. package/dist/opusTransport.d.ts +113 -0
  293. package/dist/opusTransport.d.ts.map +1 -0
  294. package/dist/opusTransport.js +170 -0
  295. package/dist/opusTransport.js.map +1 -0
  296. package/dist/pagination.d.ts +18 -0
  297. package/dist/pagination.d.ts.map +1 -0
  298. package/dist/pagination.js +26 -0
  299. package/dist/pagination.js.map +1 -0
  300. package/dist/platformAssistant.d.ts +55 -1
  301. package/dist/platformAssistant.d.ts.map +1 -1
  302. package/dist/platformAssistant.js +39 -1
  303. package/dist/platformAssistant.js.map +1 -1
  304. package/dist/pollUtils.d.ts +19 -0
  305. package/dist/pollUtils.d.ts.map +1 -0
  306. package/dist/pollUtils.js +35 -0
  307. package/dist/pollUtils.js.map +1 -0
  308. package/dist/questLog.d.ts +232 -0
  309. package/dist/questLog.d.ts.map +1 -0
  310. package/dist/questLog.js +522 -0
  311. package/dist/questLog.js.map +1 -0
  312. package/dist/reactor/dmDirectiveToExperience.d.ts +300 -0
  313. package/dist/reactor/dmDirectiveToExperience.d.ts.map +1 -0
  314. package/dist/reactor/dmDirectiveToExperience.js +401 -0
  315. package/dist/reactor/dmDirectiveToExperience.js.map +1 -0
  316. package/dist/reactor/dmSceneControlPrompt.d.ts.map +1 -1
  317. package/dist/reactor/dmSceneControlPrompt.js +64 -2
  318. package/dist/reactor/dmSceneControlPrompt.js.map +1 -1
  319. package/dist/reactor/dmWorldEntry.d.ts +1278 -0
  320. package/dist/reactor/dmWorldEntry.d.ts.map +1 -0
  321. package/dist/reactor/dmWorldEntry.js +1396 -0
  322. package/dist/reactor/dmWorldEntry.js.map +1 -0
  323. package/dist/reactor/framePromptCompaction.d.ts +223 -0
  324. package/dist/reactor/framePromptCompaction.d.ts.map +1 -0
  325. package/dist/reactor/framePromptCompaction.js +393 -0
  326. package/dist/reactor/framePromptCompaction.js.map +1 -0
  327. package/dist/reactor/frameWorldBind.d.ts +86 -0
  328. package/dist/reactor/frameWorldBind.d.ts.map +1 -0
  329. package/dist/reactor/frameWorldBind.js +79 -0
  330. package/dist/reactor/frameWorldBind.js.map +1 -0
  331. package/dist/reactor/happyOysterSeed.d.ts +166 -0
  332. package/dist/reactor/happyOysterSeed.d.ts.map +1 -0
  333. package/dist/reactor/happyOysterSeed.js +233 -0
  334. package/dist/reactor/happyOysterSeed.js.map +1 -0
  335. package/dist/reactor/happyOysterWalk.d.ts +274 -0
  336. package/dist/reactor/happyOysterWalk.d.ts.map +1 -0
  337. package/dist/reactor/happyOysterWalk.js +407 -0
  338. package/dist/reactor/happyOysterWalk.js.map +1 -0
  339. package/dist/reactor/happyOysterWorld.d.ts +718 -0
  340. package/dist/reactor/happyOysterWorld.d.ts.map +1 -0
  341. package/dist/reactor/happyOysterWorld.js +826 -0
  342. package/dist/reactor/happyOysterWorld.js.map +1 -0
  343. package/dist/reactor/heliosCommandDispatcher.d.ts.map +1 -1
  344. package/dist/reactor/heliosCommandDispatcher.js +5 -2
  345. package/dist/reactor/heliosCommandDispatcher.js.map +1 -1
  346. package/dist/reactor/hiddenWorldLifecycle.d.ts +101 -0
  347. package/dist/reactor/hiddenWorldLifecycle.d.ts.map +1 -0
  348. package/dist/reactor/hiddenWorldLifecycle.js +119 -0
  349. package/dist/reactor/hiddenWorldLifecycle.js.map +1 -0
  350. package/dist/reactor/imageCanvas.d.ts +15 -0
  351. package/dist/reactor/imageCanvas.d.ts.map +1 -0
  352. package/dist/reactor/imageCanvas.js +33 -0
  353. package/dist/reactor/imageCanvas.js.map +1 -0
  354. package/dist/reactor/index.d.ts +19 -0
  355. package/dist/reactor/index.d.ts.map +1 -1
  356. package/dist/reactor/index.js +78 -0
  357. package/dist/reactor/index.js.map +1 -1
  358. package/dist/reactor/longLiveCommandDispatcher.d.ts +23 -8
  359. package/dist/reactor/longLiveCommandDispatcher.d.ts.map +1 -1
  360. package/dist/reactor/longLiveCommandDispatcher.js +16 -4
  361. package/dist/reactor/longLiveCommandDispatcher.js.map +1 -1
  362. package/dist/reactor/longLiveSceneEntry.d.ts +203 -0
  363. package/dist/reactor/longLiveSceneEntry.d.ts.map +1 -0
  364. package/dist/reactor/longLiveSceneEntry.js +280 -0
  365. package/dist/reactor/longLiveSceneEntry.js.map +1 -0
  366. package/dist/reactor/momentCut.d.ts +153 -0
  367. package/dist/reactor/momentCut.d.ts.map +1 -0
  368. package/dist/reactor/momentCut.js +142 -0
  369. package/dist/reactor/momentCut.js.map +1 -0
  370. package/dist/reactor/promptAddonRegistry.d.ts +39 -3
  371. package/dist/reactor/promptAddonRegistry.d.ts.map +1 -1
  372. package/dist/reactor/promptAddonRegistry.js +42 -3
  373. package/dist/reactor/promptAddonRegistry.js.map +1 -1
  374. package/dist/reactor/promptTemplatePreview.d.ts +97 -0
  375. package/dist/reactor/promptTemplatePreview.d.ts.map +1 -0
  376. package/dist/reactor/promptTemplatePreview.js +185 -0
  377. package/dist/reactor/promptTemplatePreview.js.map +1 -0
  378. package/dist/reactor/reactorAvailability.d.ts +80 -0
  379. package/dist/reactor/reactorAvailability.d.ts.map +1 -0
  380. package/dist/reactor/reactorAvailability.js +121 -0
  381. package/dist/reactor/reactorAvailability.js.map +1 -0
  382. package/dist/reactor/reactorSessionRefusal.d.ts +125 -0
  383. package/dist/reactor/reactorSessionRefusal.d.ts.map +1 -0
  384. package/dist/reactor/reactorSessionRefusal.js +197 -0
  385. package/dist/reactor/reactorSessionRefusal.js.map +1 -0
  386. package/dist/reactor/reactorTokenScope.d.ts +47 -0
  387. package/dist/reactor/reactorTokenScope.d.ts.map +1 -0
  388. package/dist/reactor/reactorTokenScope.js +64 -0
  389. package/dist/reactor/reactorTokenScope.js.map +1 -0
  390. package/dist/reactor/resolveDirectorBeats.d.ts +65 -0
  391. package/dist/reactor/resolveDirectorBeats.d.ts.map +1 -0
  392. package/dist/reactor/resolveDirectorBeats.js +86 -0
  393. package/dist/reactor/resolveDirectorBeats.js.map +1 -0
  394. package/dist/reactor/sanaLiveEdit.d.ts +117 -0
  395. package/dist/reactor/sanaLiveEdit.d.ts.map +1 -0
  396. package/dist/reactor/sanaLiveEdit.js +105 -0
  397. package/dist/reactor/sanaLiveEdit.js.map +1 -0
  398. package/dist/reactor/sceneEntry.d.ts +66 -9
  399. package/dist/reactor/sceneEntry.d.ts.map +1 -1
  400. package/dist/reactor/sceneEntry.js +59 -66
  401. package/dist/reactor/sceneEntry.js.map +1 -1
  402. package/dist/reactor/sceneSeedImage.d.ts +199 -0
  403. package/dist/reactor/sceneSeedImage.d.ts.map +1 -0
  404. package/dist/reactor/sceneSeedImage.js +239 -0
  405. package/dist/reactor/sceneSeedImage.js.map +1 -0
  406. package/dist/reactor/seedImageOrchestrator.d.ts +70 -3
  407. package/dist/reactor/seedImageOrchestrator.d.ts.map +1 -1
  408. package/dist/reactor/seedImageOrchestrator.js +92 -28
  409. package/dist/reactor/seedImageOrchestrator.js.map +1 -1
  410. package/dist/reactor/toolPromptAddon.d.ts.map +1 -1
  411. package/dist/reactor/toolPromptAddon.js +16 -2
  412. package/dist/reactor/toolPromptAddon.js.map +1 -1
  413. package/dist/reactor/worldMintLoop.d.ts +286 -0
  414. package/dist/reactor/worldMintLoop.d.ts.map +1 -0
  415. package/dist/reactor/worldMintLoop.js +381 -0
  416. package/dist/reactor/worldMintLoop.js.map +1 -0
  417. package/dist/reactor/worldSteerOutcome.d.ts +98 -0
  418. package/dist/reactor/worldSteerOutcome.d.ts.map +1 -0
  419. package/dist/reactor/worldSteerOutcome.js +81 -0
  420. package/dist/reactor/worldSteerOutcome.js.map +1 -0
  421. package/dist/retryAfter.d.ts +15 -0
  422. package/dist/retryAfter.d.ts.map +1 -0
  423. package/dist/retryAfter.js +75 -0
  424. package/dist/retryAfter.js.map +1 -0
  425. package/dist/seriesKey.d.ts +31 -0
  426. package/dist/seriesKey.d.ts.map +1 -0
  427. package/dist/seriesKey.js +33 -0
  428. package/dist/seriesKey.js.map +1 -0
  429. package/dist/sessionRefresh.d.ts +135 -0
  430. package/dist/sessionRefresh.d.ts.map +1 -0
  431. package/dist/sessionRefresh.js +215 -0
  432. package/dist/sessionRefresh.js.map +1 -0
  433. package/dist/sharedAudioContext.d.ts +39 -0
  434. package/dist/sharedAudioContext.d.ts.map +1 -0
  435. package/dist/sharedAudioContext.js +63 -0
  436. package/dist/sharedAudioContext.js.map +1 -0
  437. package/dist/singleFlight.d.ts +51 -0
  438. package/dist/singleFlight.d.ts.map +1 -0
  439. package/dist/singleFlight.js +87 -0
  440. package/dist/singleFlight.js.map +1 -0
  441. package/dist/storyGraph.d.ts +83 -0
  442. package/dist/storyGraph.d.ts.map +1 -1
  443. package/dist/storyGraph.js +169 -4
  444. package/dist/storyGraph.js.map +1 -1
  445. package/dist/storyboardMask.d.ts +343 -0
  446. package/dist/storyboardMask.d.ts.map +1 -0
  447. package/dist/storyboardMask.js +505 -0
  448. package/dist/storyboardMask.js.map +1 -0
  449. package/dist/storyboardTimeline.d.ts +93 -0
  450. package/dist/storyboardTimeline.d.ts.map +1 -0
  451. package/dist/storyboardTimeline.js +131 -0
  452. package/dist/storyboardTimeline.js.map +1 -0
  453. package/dist/studioAutomation.d.ts +104 -0
  454. package/dist/studioAutomation.d.ts.map +1 -0
  455. package/dist/studioAutomation.js +178 -0
  456. package/dist/studioAutomation.js.map +1 -0
  457. package/dist/tenantClaim.d.ts +86 -0
  458. package/dist/tenantClaim.d.ts.map +1 -0
  459. package/dist/tenantClaim.js +164 -0
  460. package/dist/tenantClaim.js.map +1 -0
  461. package/dist/timeFormat.d.ts +25 -0
  462. package/dist/timeFormat.d.ts.map +1 -1
  463. package/dist/timeFormat.js +56 -0
  464. package/dist/timeFormat.js.map +1 -1
  465. package/dist/toolSchemas.d.ts +58 -10
  466. package/dist/toolSchemas.d.ts.map +1 -1
  467. package/dist/toolSchemas.js +37 -9
  468. package/dist/toolSchemas.js.map +1 -1
  469. package/dist/transport.d.ts +120 -0
  470. package/dist/transport.d.ts.map +1 -0
  471. package/dist/transport.js +282 -0
  472. package/dist/transport.js.map +1 -0
  473. package/dist/videoGenFacade.d.ts +63 -0
  474. package/dist/videoGenFacade.d.ts.map +1 -0
  475. package/dist/videoGenFacade.js +49 -0
  476. package/dist/videoGenFacade.js.map +1 -0
  477. package/dist/visemeScheduler.d.ts +24 -2
  478. package/dist/visemeScheduler.d.ts.map +1 -1
  479. package/dist/visemeScheduler.js +31 -2
  480. package/dist/visemeScheduler.js.map +1 -1
  481. package/dist/vision/VisionPublisher.d.ts +88 -0
  482. package/dist/vision/VisionPublisher.d.ts.map +1 -1
  483. package/dist/vision/VisionPublisher.js +196 -13
  484. package/dist/vision/VisionPublisher.js.map +1 -1
  485. package/dist/vision/VisionSourceController.d.ts +67 -1
  486. package/dist/vision/VisionSourceController.d.ts.map +1 -1
  487. package/dist/vision/VisionSourceController.js +147 -5
  488. package/dist/vision/VisionSourceController.js.map +1 -1
  489. package/dist/vision/index.d.ts +2 -1
  490. package/dist/vision/index.d.ts.map +1 -1
  491. package/dist/vision/index.js +2 -1
  492. package/dist/vision/index.js.map +1 -1
  493. package/dist/vision/sourceKinds.d.ts +18 -5
  494. package/dist/vision/sourceKinds.d.ts.map +1 -1
  495. package/dist/vision/sourceKinds.js +15 -2
  496. package/dist/vision/sourceKinds.js.map +1 -1
  497. package/dist/vision/types.d.ts +7 -4
  498. package/dist/vision/types.d.ts.map +1 -1
  499. package/dist/vision/visionErrors.d.ts +45 -0
  500. package/dist/vision/visionErrors.d.ts.map +1 -0
  501. package/dist/vision/visionErrors.js +66 -0
  502. package/dist/vision/visionErrors.js.map +1 -0
  503. package/dist/voiceCloneCaption.d.ts +33 -0
  504. package/dist/voiceCloneCaption.d.ts.map +1 -0
  505. package/dist/voiceCloneCaption.js +69 -0
  506. package/dist/voiceCloneCaption.js.map +1 -0
  507. package/dist/websocket.d.ts +273 -10
  508. package/dist/websocket.d.ts.map +1 -1
  509. package/dist/websocket.js +79 -0
  510. package/dist/websocket.js.map +1 -1
  511. package/dist/workflowAuthoring.d.ts +139 -0
  512. package/dist/workflowAuthoring.d.ts.map +1 -0
  513. package/dist/workflowAuthoring.js +557 -0
  514. package/dist/workflowAuthoring.js.map +1 -0
  515. package/package.json +15 -5
  516. package/src/__tests__/adapters-director.test.ts +9 -6
  517. package/src/__tests__/adapters-extraction.test.ts +175 -0
  518. package/src/__tests__/adapters-image.test.ts +66 -0
  519. package/src/__tests__/adapters-momentPolicy.test.ts +218 -0
  520. package/src/__tests__/adapters-platform.test.ts +110 -4
  521. package/src/__tests__/adapters-videogen.test.ts +53 -0
  522. package/src/__tests__/adapters-world.test.ts +117 -7
  523. package/src/__tests__/admin.enhancement-defaults.test.ts +115 -0
  524. package/src/__tests__/admin.test.ts +282 -0
  525. package/src/__tests__/adventures-world-state.test.ts +156 -0
  526. package/src/__tests__/adventures.test.ts +111 -1
  527. package/src/__tests__/api-pollers.test.ts +113 -23
  528. package/src/__tests__/api.adventure-definitions.test.ts +312 -0
  529. package/src/__tests__/api.anchor-beat.test.ts +75 -0
  530. package/src/__tests__/api.arc-approval.test.ts +171 -0
  531. package/src/__tests__/api.arc-beats-floor.test.ts +56 -0
  532. package/src/__tests__/api.arc-generation.test.ts +168 -0
  533. package/src/__tests__/api.arc-templates.test.ts +78 -0
  534. package/src/__tests__/api.assignVideoSeries.test.ts +81 -0
  535. package/src/__tests__/api.cast-frame-choices.test.ts +141 -0
  536. package/src/__tests__/api.cutscene-registry.test.ts +148 -0
  537. package/src/__tests__/api.enhancement-addition-actions.test.ts +137 -0
  538. package/src/__tests__/api.enrichVideo-serialization.test.ts +116 -0
  539. package/src/__tests__/api.extraction-base.test.ts +87 -0
  540. package/src/__tests__/api.generateVideo-cutscene.test.ts +148 -0
  541. package/src/__tests__/api.job-pipeline-stages.test.ts +128 -0
  542. package/src/__tests__/api.list-images-filters.test.ts +6 -3
  543. package/src/__tests__/api.quest-curation.test.ts +169 -0
  544. package/src/__tests__/api.reprocessVideo.test.ts +71 -0
  545. package/src/__tests__/api.scene-split-merge.test.ts +129 -0
  546. package/src/__tests__/api.session-quests.test.ts +184 -0
  547. package/src/__tests__/api.test.ts +122 -0
  548. package/src/__tests__/api.transferSeries.test.ts +114 -0
  549. package/src/__tests__/api.unknown-clusters.test.ts +225 -0
  550. package/src/__tests__/api.uploadVideo-options.test.ts +156 -0
  551. package/src/__tests__/arcPreview.test.ts +71 -0
  552. package/src/__tests__/arcStyleProfile.test.ts +204 -0
  553. package/src/__tests__/artifacts-delete.test.ts +109 -0
  554. package/src/__tests__/audio.test.ts +864 -5
  555. package/src/__tests__/audioDsp.test.ts +196 -0
  556. package/src/__tests__/audioUnavailable.test.ts +43 -0
  557. package/src/__tests__/cast.test.ts +10 -1
  558. package/src/__tests__/castCurationProjection.test.ts +84 -0
  559. package/src/__tests__/castFramePipelinePending.test.ts +171 -0
  560. package/src/__tests__/castProjection.test.ts +497 -5
  561. package/src/__tests__/characterGrounding.test.ts +357 -0
  562. package/src/__tests__/contract.test.ts +97 -0
  563. package/src/__tests__/conversation/chatSessionStore.test.ts +243 -0
  564. package/src/__tests__/conversation/controller.test.ts +211 -0
  565. package/src/__tests__/conversation/readSequencer.test.ts +52 -0
  566. package/src/__tests__/conversation/rosterProjection.test.ts +204 -3
  567. package/src/__tests__/conversation/runtime.test.ts +118 -1
  568. package/src/__tests__/conversation/voice.test.ts +741 -7
  569. package/src/__tests__/creatorCuration.test.ts +256 -0
  570. package/src/__tests__/creatorDashboard.test.ts +444 -0
  571. package/src/__tests__/creatorUniverse.test.ts +138 -0
  572. package/src/__tests__/curationWrite.test.ts +179 -0
  573. package/src/__tests__/decisions.test.ts +89 -0
  574. package/src/__tests__/designTokens.test.ts +72 -0
  575. package/src/__tests__/dialogAttribution.test.ts +187 -0
  576. package/src/__tests__/dmDirectiveToExperience.test.ts +198 -0
  577. package/src/__tests__/dmWorldEntry.test.ts +2102 -0
  578. package/src/__tests__/enhancementDiff.test.ts +132 -0
  579. package/src/__tests__/experienceModelCatalog.test.ts +292 -0
  580. package/src/__tests__/extractionStageState.test.ts +67 -0
  581. package/src/__tests__/getVideo.test.ts +95 -0
  582. package/src/__tests__/graphReadAfterWrite.test.ts +211 -0
  583. package/src/__tests__/graphSchema.test.ts +55 -4
  584. package/src/__tests__/happyOysterSeed.test.ts +208 -0
  585. package/src/__tests__/happyOysterWorld.test.ts +1241 -0
  586. package/src/__tests__/happyOysterWorldRefusal.test.ts +224 -0
  587. package/src/__tests__/hiddenWorldLifecycle.test.ts +203 -0
  588. package/src/__tests__/http.session-refresh.test.ts +424 -0
  589. package/src/__tests__/http.test.ts +316 -0
  590. package/src/__tests__/identity.test.ts +132 -0
  591. package/src/__tests__/loadBundleManifest.test.ts +192 -22
  592. package/src/__tests__/longLiveSceneEntry.test.ts +371 -0
  593. package/src/__tests__/me.test.ts +74 -0
  594. package/src/__tests__/messageContent.test.ts +395 -0
  595. package/src/__tests__/momentCut.test.ts +229 -0
  596. package/src/__tests__/mutationEpoch.test.ts +218 -0
  597. package/src/__tests__/obo.test.ts +159 -0
  598. package/src/__tests__/opusTransport.test.ts +182 -0
  599. package/src/__tests__/opusTransportLibopus.test.ts +125 -0
  600. package/src/__tests__/orgs.test.ts +229 -0
  601. package/src/__tests__/persona-generation.test.ts +208 -1
  602. package/src/__tests__/platformAssistant.test.ts +140 -0
  603. package/src/__tests__/projects.test.ts +338 -0
  604. package/src/__tests__/promptTemplatePreview.test.ts +160 -0
  605. package/src/__tests__/reactor/__fixtures__/realFramePromptText.ts +23 -0
  606. package/src/__tests__/reactor/api-reactor.test.ts +60 -21
  607. package/src/__tests__/reactor/framePromptCompaction.test.ts +300 -0
  608. package/src/__tests__/reactor/promptAddonRegistry.test.ts +79 -0
  609. package/src/__tests__/reactor/reactorTokenScope.test.ts +50 -0
  610. package/src/__tests__/reactor/resolveDirectorBeats.test.ts +156 -0
  611. package/src/__tests__/reactor/sceneEntry.test.ts +3 -0
  612. package/src/__tests__/reactor/sceneSeedImage.test.ts +361 -0
  613. package/src/__tests__/reactor/seedImageOrchestrator.test.ts +43 -5
  614. package/src/__tests__/reactor-happyOysterWalk.test.ts +294 -0
  615. package/src/__tests__/reactorAvailability.test.ts +217 -0
  616. package/src/__tests__/reactorSessionRefusal.test.ts +189 -0
  617. package/src/__tests__/regeneration.test.ts +9 -9
  618. package/src/__tests__/reprocessBlockedReason.test.ts +30 -0
  619. package/src/__tests__/retryAfter.test.ts +65 -0
  620. package/src/__tests__/roleClaim.test.ts +102 -0
  621. package/src/__tests__/sanaLiveEdit.test.ts +84 -0
  622. package/src/__tests__/seriesKey.test.ts +24 -0
  623. package/src/__tests__/settings-set9.test.ts +238 -0
  624. package/src/__tests__/singleFlight.test.ts +348 -0
  625. package/src/__tests__/storyGraph.test.ts +111 -1
  626. package/src/__tests__/storyboardFrameCutscene.test.ts +115 -0
  627. package/src/__tests__/storyboardMask.test.ts +527 -0
  628. package/src/__tests__/storyboardTimeline.test.ts +228 -0
  629. package/src/__tests__/storyboards.test.ts +639 -0
  630. package/src/__tests__/studioAutomation.test.ts +325 -0
  631. package/src/__tests__/toolSchemas.test.ts +11 -18
  632. package/src/__tests__/transport.test.ts +312 -0
  633. package/src/__tests__/videoGenFacade.test.ts +141 -0
  634. package/src/__tests__/videoGraph.test.ts +43 -1
  635. package/src/__tests__/visemeScheduler.test.ts +55 -1
  636. package/src/__tests__/visibility.test.ts +143 -0
  637. package/src/__tests__/voiceCloneCaption.test.ts +80 -0
  638. package/src/__tests__/voiceFallback.test.ts +55 -0
  639. package/src/__tests__/websocket-error-turn-ended.test.ts +49 -0
  640. package/src/__tests__/websocket-vision.test.ts +141 -0
  641. package/src/__tests__/websocket.test.ts +75 -1
  642. package/src/__tests__/workflowAuthoring.test.ts +187 -0
  643. package/src/__tests__/workflows.test.ts +640 -0
  644. package/src/__tests__/worldMintLoop.test.ts +448 -0
  645. package/src/__tests__/worldModelPreference.test.ts +302 -0
  646. package/src/__tests__/worldModelTradeoffs.test.ts +89 -0
  647. package/src/__tests__/worldSteerOutcome.test.ts +62 -0
  648. package/src/adapters/capabilities.ts +39 -3
  649. package/src/adapters/directorAdapter.ts +5 -4
  650. package/src/adapters/experienceModelCatalog.ts +538 -0
  651. package/src/adapters/extractionAdapter.ts +150 -0
  652. package/src/adapters/imageAdapter.ts +5 -1
  653. package/src/adapters/index.ts +104 -17
  654. package/src/adapters/momentDirective.ts +109 -0
  655. package/src/adapters/momentPolicy.ts +209 -0
  656. package/src/adapters/registry.ts +1 -1
  657. package/src/adapters/videoGenAdapter.ts +124 -0
  658. package/src/adapters/worldAdapter.ts +221 -16
  659. package/src/adapters/worldModelPreference.ts +247 -0
  660. package/src/adapters/worldModelTradeoffs.ts +247 -0
  661. package/src/admin.ts +842 -16
  662. package/src/api.ts +12687 -3446
  663. package/src/arcBoardJoin.ts +46 -0
  664. package/src/arcPreview.ts +103 -0
  665. package/src/audio.ts +691 -130
  666. package/src/audioDsp.ts +132 -0
  667. package/src/audioProtocol.ts +235 -0
  668. package/src/beatTitles.ts +51 -0
  669. package/src/castProjection.ts +311 -0
  670. package/src/characterGrounding.ts +491 -0
  671. package/src/conversation/binding.ts +13 -0
  672. package/src/conversation/chatSessionStore.ts +281 -0
  673. package/src/conversation/controller.ts +96 -3
  674. package/src/conversation/index.ts +2 -0
  675. package/src/conversation/participant.ts +16 -0
  676. package/src/conversation/readSequencer.ts +55 -0
  677. package/src/conversation/roster.ts +5 -1
  678. package/src/conversation/rosterProjection.ts +166 -2
  679. package/src/conversation/runtime.ts +66 -7
  680. package/src/conversation/types.ts +43 -4
  681. package/src/conversation/voice.ts +655 -51
  682. package/src/creatorCuration.ts +316 -0
  683. package/src/creatorDashboard.ts +344 -0
  684. package/src/creatorUniverse.ts +222 -0
  685. package/src/curationWrite.ts +108 -0
  686. package/src/designTokens.ts +157 -0
  687. package/src/dialogAttribution.ts +182 -0
  688. package/src/dmRunWorldReadiness.ts +1168 -0
  689. package/src/domains/access.ts +92 -0
  690. package/src/domains/adventureDefinitions.ts +313 -0
  691. package/src/domains/adventures.ts +557 -0
  692. package/src/domains/arcs.ts +350 -0
  693. package/src/domains/artifacts.ts +349 -0
  694. package/src/domains/chat.ts +338 -0
  695. package/src/domains/decisions.ts +62 -0
  696. package/src/domains/documents.ts +389 -0
  697. package/src/domains/enhancements.ts +259 -0
  698. package/src/domains/graph.ts +959 -0
  699. package/src/domains/images.ts +451 -0
  700. package/src/domains/ingestion.ts +695 -0
  701. package/src/domains/me.ts +27 -0
  702. package/src/domains/orgs.ts +168 -0
  703. package/src/domains/personas.ts +440 -0
  704. package/src/domains/projects.ts +177 -0
  705. package/src/domains/quests.ts +587 -0
  706. package/src/domains/reactor.ts +163 -0
  707. package/src/domains/showcase.ts +35 -0
  708. package/src/domains/storyboards.ts +1698 -0
  709. package/src/domains/studioSettings.ts +149 -0
  710. package/src/domains/universes.ts +433 -0
  711. package/src/domains/userDefaults.ts +37 -0
  712. package/src/domains/visemeBundles.ts +541 -0
  713. package/src/domains/workflows.ts +376 -0
  714. package/src/enhancementDiff.ts +171 -0
  715. package/src/generated/contract.ts +1016 -0
  716. package/src/graphSchema.ts +154 -6
  717. package/src/http.ts +295 -11
  718. package/src/identity.ts +123 -0
  719. package/src/index.ts +131 -0
  720. package/src/messageContent.ts +500 -0
  721. package/src/mutationEpoch.ts +107 -0
  722. package/src/obo.ts +201 -0
  723. package/src/opusTransport.ts +268 -0
  724. package/src/pagination.ts +29 -0
  725. package/src/platformAssistant.ts +97 -1
  726. package/src/pollUtils.ts +35 -0
  727. package/src/questLog.ts +704 -0
  728. package/src/reactor/dmDirectiveToExperience.ts +636 -0
  729. package/src/reactor/dmSceneControlPrompt.ts +69 -2
  730. package/src/reactor/dmWorldEntry.ts +2226 -0
  731. package/src/reactor/framePromptCompaction.ts +544 -0
  732. package/src/reactor/frameWorldBind.ts +133 -0
  733. package/src/reactor/happyOysterSeed.ts +329 -0
  734. package/src/reactor/happyOysterWalk.ts +541 -0
  735. package/src/reactor/happyOysterWorld.ts +1270 -0
  736. package/src/reactor/heliosCommandDispatcher.ts +5 -1
  737. package/src/reactor/hiddenWorldLifecycle.ts +182 -0
  738. package/src/reactor/imageCanvas.ts +38 -0
  739. package/src/reactor/index.ts +78 -0
  740. package/src/reactor/longLiveCommandDispatcher.ts +23 -8
  741. package/src/reactor/longLiveSceneEntry.ts +409 -0
  742. package/src/reactor/momentCut.ts +219 -0
  743. package/src/reactor/promptAddonRegistry.ts +81 -3
  744. package/src/reactor/promptTemplatePreview.ts +240 -0
  745. package/src/reactor/reactorAvailability.ts +155 -0
  746. package/src/reactor/reactorSessionRefusal.ts +260 -0
  747. package/src/reactor/reactorTokenScope.ts +69 -0
  748. package/src/reactor/resolveDirectorBeats.ts +140 -0
  749. package/src/reactor/sanaLiveEdit.ts +158 -0
  750. package/src/reactor/sceneEntry.ts +106 -88
  751. package/src/reactor/sceneSeedImage.ts +338 -0
  752. package/src/reactor/seedImageOrchestrator.ts +116 -34
  753. package/src/reactor/toolPromptAddon.ts +16 -2
  754. package/src/reactor/worldMintLoop.ts +545 -0
  755. package/src/reactor/worldSteerOutcome.ts +132 -0
  756. package/src/retryAfter.ts +71 -0
  757. package/src/seriesKey.ts +42 -0
  758. package/src/sessionRefresh.ts +237 -0
  759. package/src/sharedAudioContext.ts +67 -0
  760. package/src/singleFlight.ts +91 -0
  761. package/src/storyGraph.ts +247 -4
  762. package/src/storyboardMask.ts +756 -0
  763. package/src/storyboardTimeline.ts +220 -0
  764. package/src/studioAutomation.ts +208 -0
  765. package/src/tenantClaim.ts +170 -0
  766. package/src/timeFormat.ts +51 -0
  767. package/src/toolSchemas.ts +40 -10
  768. package/src/transport.ts +327 -0
  769. package/src/videoGenFacade.ts +90 -0
  770. package/src/visemeScheduler.ts +36 -3
  771. package/src/vision/VisionPublisher.ts +204 -14
  772. package/src/vision/VisionSourceController.ts +187 -6
  773. package/src/vision/__tests__/VisionPublisher.kvs.test.ts +50 -0
  774. package/src/vision/__tests__/VisionPublisher.test.ts +291 -0
  775. package/src/vision/__tests__/VisionSourceController.test.ts +376 -6
  776. package/src/vision/index.ts +5 -1
  777. package/src/vision/sourceKinds.ts +19 -5
  778. package/src/vision/types.ts +7 -4
  779. package/src/vision/visionErrors.ts +70 -0
  780. package/src/voiceCloneCaption.ts +77 -0
  781. package/src/websocket.ts +361 -12
  782. package/src/workflowAuthoring.ts +664 -0
@@ -0,0 +1,1396 @@
1
+ /**
2
+ * DM world entry — the client half of §Q `DM.1`: a DM `[SCENE:enter_world]`
3
+ * directive opens a HappyOyster world SEEDED FROM THE RATIFIED STORYBOARD
4
+ * FRAME for the beat the party is standing on.
5
+ *
6
+ * Nothing here is a new mechanism. `happyOysterWorld.ts` already owns the
7
+ * lifecycle, the permanent `{encryptedWorldId, mode}` handle and the error
8
+ * taxonomy; `happyOysterSeed.ts` already owns crop-then-encode; the directive
9
+ * pipeline already parses the tag. This module owns only the decisions that
10
+ * stand between an LLM-emitted tag and a PERMANENT, BILLED, UNLISTABLE asset,
11
+ * and it owns them in ONE place so no surface can re-derive them differently.
12
+ *
13
+ * ## The owner's ruling: OPT-IN AUTO-FIRE WITH RAILS, not a blanket gate
14
+ *
15
+ * (Owner, 2026-07-28: *"user should be able to allow dm to auto-fire (as long
16
+ * as there aren't any hidden sessions or lost sessions and they can easily be
17
+ * stopped. And they timeout after an interval … default to 30 seconds)"*.) The
18
+ * four rails, and where each one lives:
19
+ *
20
+ * 1. **Opt-in.** {@link DmWorldEntryPlanInput.autoFireEnabled} defaults to
21
+ * `false` ({@link DM_WORLD_AUTO_FIRE_DEFAULT}). With it off, every create
22
+ * is `confirm_required` and {@link launchDmWorldEntry} REFUSES to run one
23
+ * without an explicit operator confirmation.
24
+ * 2. **No hidden or lost sessions.** Every handle a launch produces goes to
25
+ * `onWorldHandle`, at THREE points (§Q `DM.43`): at MINT time, the instant
26
+ * the vendor returns a world id and BEFORE `startTravel`; on success; and
27
+ * from `HappyOysterLaunchError.handle`, i.e. including a world that was
28
+ * created and billed but whose `startTravel` failed. The mint-time offer
29
+ * is the load-bearing one — `startTravel` can occupy minutes, and the two
30
+ * settle-time offers only fire once it is over.
31
+ * {@link rememberDmWorldEntry} keeps the session's
32
+ * list so a surface can show what it opened and reattach to it, and
33
+ * {@link collectDmWorldRecords} (§Q `DM.24`) is the DURABLE-FIRST read of
34
+ * it: the board's `StoryboardFrame.worldId` bindings, which survive a
35
+ * reload, plus whatever the session knows that the board does not yet.
36
+ * 3. **Easily stopped.** Auto-fired plans carry
37
+ * {@link DmWorldEntryPlan.autoStopAfterMs}; the pane arms that deadline and
38
+ * the existing "Back to the party" exit is the manual stop.
39
+ * 4. **Timeout, default 30 s** — {@link DM_WORLD_AUTO_STOP_MS_DEFAULT},
40
+ * overridable per call by the studio setting once that store exists.
41
+ *
42
+ * **What actually bounds vendor cost is CREATION FREQUENCY, not run time.** A
43
+ * timeout stops a world streaming; it cannot un-bill a world already created.
44
+ * So auto-fire rides the owner's `DM.12` ruling — *"regenerate the world at
45
+ * scene changes, have the DM issue instruct commands based on the storyboard
46
+ * and user choices otherwise"*: a live world whose scene has not changed is
47
+ * STEERED (`'steer'` ⇒ `instruct`, free), a frame that already owns a world is
48
+ * REOPENED (`'reopen'` ⇒ `attachWorld`, free), and `createWorld` fires only on
49
+ * a genuine scene change. That caps creation at one per scene rather than one
50
+ * per LLM emission, which was the real hazard.
51
+ *
52
+ * ## Two things that are NOT relaxed by any of the above
53
+ *
54
+ * - **The seed is BYTES, never a URL.** `createWorld({firstFrameImageUrl})` is
55
+ * forwarded verbatim with no client guard, frames are stored PNG with no
56
+ * byte guarantee, and the presigned frame URL expires — each of those fails
57
+ * AFTER the world is billed. `prepareHappyOysterSeedFromUrl` converts all
58
+ * three into PRE-billing throws for the cost of one client-side fetch, and
59
+ * the launcher refuses to create without prepared bytes in hand.
60
+ * - **The frame is resolved DETERMINISTICALLY, never from the tag.**
61
+ * {@link resolveDmWorldEntryFrame} joins the ACTIVE BEAT to a board frame
62
+ * through `StoryboardFrame.beatId` (the documented join to quests'
63
+ * `sourceBeatId`). The tag's free text is ATMOSPHERE ONLY, appended to the
64
+ * frame's server-compiled prompt. A hallucinated id can never select,
65
+ * replace or mis-address the seed — a risk that goes UP, not down, with
66
+ * auto-fire on.
67
+ *
68
+ * Framework- and SDK-agnostic, like the rest of `reactor/`: pure data plus the
69
+ * structural {@link HappyOysterBridge}.
70
+ *
71
+ * PARKED, deliberately not decided here: §Q `DM.1` Q3 (are DM worlds always
72
+ * `adventure`?) stays open on `SB-W.4`, so `mode` is a REQUIRED input the host
73
+ * supplies rather than a default this module picks.
74
+ */
75
+ import { frameImageUrl, frameRenderFailed, frameRenderFailure, orderStoryboardFrames, promptFrameVariant, } from '../domains/storyboards.js';
76
+ import { beatHeadline } from '../beatTitles.js';
77
+ import { compactFramePromptText } from './framePromptCompaction.js';
78
+ import { HAPPY_OYSTER_BUILD_FAST_MS, HAPPY_OYSTER_BUILD_OBSERVED_MAX_MS, HAPPY_OYSTER_PROMPT_MAX_CHARS, HAPPY_OYSTER_STREAM_START_TIMEOUT_MS, HappyOysterLaunchError, happyOysterPromptIssue, launchHappyOysterWorld, } from './happyOysterWorld.js';
79
+ import { reactorSessionRefusalDetail, reactorSessionRefusalTitle, } from './reactorSessionRefusal.js';
80
+ /**
81
+ * Whether the DM may open a world WITHOUT asking, when the host supplies no
82
+ * setting. `false` — the rail is opt-IN (owner 2026-07-28), so an unconfigured
83
+ * host never lets an LLM-emitted tag mint a permanent, billed asset on its own.
84
+ */
85
+ export const DM_WORLD_AUTO_FIRE_DEFAULT = false;
86
+ /**
87
+ * §Q `WORLD.1-A` — THE MODE EVERY PLAYER SURFACE OPENS A WORLD ON.
88
+ *
89
+ * `DM.23` decided this for the DM play episode and held the constant in that
90
+ * file: **on a player surface a world is always `adventure`** — the party steps
91
+ * into it while the DM narrates, and `directing` is the authoring experience
92
+ * (the World Explorer demo and, later, `SB-W.4`'s storyboard director keep
93
+ * their own picker). `DM.1` Q3 stays PARKED at the client-core level: this is a
94
+ * shared HOST default, not a decision `planDmWorldEntry` makes — `mode` is
95
+ * still a REQUIRED input there.
96
+ *
97
+ * It moved here the moment a SECOND player surface needed it. The viewer
98
+ * (`WatchShell`) reopens the very worlds the episode created, and the vendor
99
+ * fails a cross-mode reattach with `MODE_MISMATCH` — so two surfaces holding
100
+ * their own literal is a world that is permanently unreachable from one of
101
+ * them, and `planDmWorldEntry`'s `world_mode_mismatch` refusal would be the
102
+ * only warning.
103
+ */
104
+ export const DM_WORLD_MODE = 'adventure';
105
+ /**
106
+ * How long an AUTO-FIRED world runs before the surface stops it, in ms. Owner
107
+ * default: 30 s. Studio-configurable once that setting store exists — the value
108
+ * rides {@link DmWorldEntryPlanInput.autoStopAfterMs} so the host passes the
109
+ * configured number and nothing here needs to change.
110
+ *
111
+ * This bounds RUN TIME, not spend: the world is already billed by the time it
112
+ * streams. The spend rail is the scene-change condition on `'create'`.
113
+ */
114
+ export const DM_WORLD_AUTO_STOP_MS_DEFAULT = 30_000;
115
+ /**
116
+ * Separator between the frame's server-compiled prompt and the DM tag's
117
+ * atmosphere text. The label is part of the contract: it keeps the atmosphere
118
+ * legible as a modifier of the frame rather than as a second scene description.
119
+ */
120
+ export const DM_WORLD_ATMOSPHERE_PREFIX = '\n\nAtmosphere: ';
121
+ /**
122
+ * Shortest atmosphere worth appending. If the frame's own prompt leaves less
123
+ * room than this under {@link HAPPY_OYSTER_PROMPT_MAX_CHARS}, the atmosphere is
124
+ * dropped entirely rather than shipped as a truncated fragment — the frame is
125
+ * the authority, so it is never the thing that gets cut.
126
+ */
127
+ export const DM_WORLD_ATMOSPHERE_MIN_CHARS = 24;
128
+ /**
129
+ * §Q `DM.17` — WHAT A REOPEN ACTUALLY RETURNS, in the one place every surface
130
+ * reads it from.
131
+ *
132
+ * Measured live 2026-07-28 on world `dHpmaEU0…EihKgVEbA1ghvbKh20QDdU4`: after an
133
+ * `instruct` visibly moved the world, TWO separate reattaches minutes apart both
134
+ * came back to the world as CREATED. `attachWorld` restores the seeded scene;
135
+ * the vendor persists no steered state and exposes no checkpoint API.
136
+ *
137
+ * The `DM.17` ruling is to SAY SO, not to replay. Replay cannot serve the
138
+ * affordance this notice guards —
139
+ * `↻ relive` mints a NEW session (`reliveFromSavePoint`), so a client-held steer
140
+ * log dies with the session it was kept in, and the quest ledger has no steer
141
+ * event to rebuild one from (`QUEST_EVENT_TYPES` carries none). Replaying only
142
+ * where a log happens to survive would make continuity INTERMITTENT, which is a
143
+ * worse lie than a uniform, stated limit. Durable replay is a backend row.
144
+ */
145
+ export const DM_WORLD_REOPEN_NOTICE = 'Reopening returns this world to the scene it was created from. Steering issued while it ran is not carried over — the vendor stores no steered state.';
146
+ /**
147
+ * The continuity notice a surface must show for `action`, or `null` when the
148
+ * action carries no continuity claim to correct.
149
+ *
150
+ * Only `'reopen'` re-enters an existing world, so only `'reopen'` can silently
151
+ * imply a continuity that does not exist. `'create'`/`'confirm_required'` mint
152
+ * the scene they show, and `'steer'` re-aims the world that is already running —
153
+ * neither loses anything. Derived here so no surface re-decides it.
154
+ */
155
+ export function dmWorldReopenNotice(action) {
156
+ return action === 'reopen' ? DM_WORLD_REOPEN_NOTICE : null;
157
+ }
158
+ /**
159
+ * The SDK client phase that means "the world is done; we are opening the
160
+ * stream". `HappyOysterModel.doStartTravel` sets it on the line immediately
161
+ * before `startTravel`, so it is the exact boundary — not an inference from
162
+ * elapsed time, which is what a host would otherwise have to guess with.
163
+ */
164
+ export const HAPPY_OYSTER_PHASE_STARTING_STREAM = 'starting_stream';
165
+ /** Resolve the stage from the SDK's own phase. `preparingSeed` wins because it
166
+ * runs before any session state exists to read. */
167
+ export function dmWorldLaunchStage(input) {
168
+ if (input.preparingSeed)
169
+ return 'preparing';
170
+ return input.clientPhase === HAPPY_OYSTER_PHASE_STARTING_STREAM
171
+ ? 'entering'
172
+ : 'building';
173
+ }
174
+ const seconds = (ms) => Math.round(ms / 1000);
175
+ /**
176
+ * The progress copy for a stage — the ONLY place a surface gets it, so the
177
+ * build's 105–240 s expectation can never be shown over the stream-start wait
178
+ * again.
179
+ */
180
+ export function dmWorldLaunchProgress(stage, action) {
181
+ if (stage === 'preparing') {
182
+ return { title: 'Preparing the starting frame…', detail: null };
183
+ }
184
+ if (stage === 'entering') {
185
+ return {
186
+ title: 'Opening the live stream…',
187
+ detail: `The world is built. Video has ${seconds(HAPPY_OYSTER_STREAM_START_TIMEOUT_MS)} seconds to arrive before the ` +
188
+ 'vendor ends the travel — waiting longer does not help.',
189
+ };
190
+ }
191
+ return action === 'reopen'
192
+ ? { title: 'Reopening this world…', detail: null }
193
+ : {
194
+ title: 'Building the world…',
195
+ detail: `World builds have taken ${seconds(HAPPY_OYSTER_BUILD_FAST_MS)}–${seconds(HAPPY_OYSTER_BUILD_OBSERVED_MAX_MS)} seconds. ` +
196
+ 'Leaving abandons a world that is already being billed.',
197
+ };
198
+ }
199
+ /**
200
+ * §Q `DM.42` — what to SAY when a launch dies after the world was already
201
+ * built and the stream never came.
202
+ *
203
+ * Measured on staging 2026-08-01, on the free reopen path and independently in
204
+ * the World Explorer host, which shares no episode code: the vendor's
205
+ * `travels/status` reports `rtcStatus: STREAMING`, the AliRTC peer reaches ICE
206
+ * `connected` with both transceivers delivered — and `getStats()` records ZERO
207
+ * `inbound-rtp` for the whole window, so the world publisher never sends a
208
+ * packet. The client then hits the vendor's stream-start bound and the SDK ends
209
+ * the travel.
210
+ *
211
+ * Why this text exists rather than the vendor's own error: the SDK retries a
212
+ * stream-start timeout (its transient-error regex matches the word "timeout"),
213
+ * so the error that finally surfaces is the RETRY's — on a reopen that is
214
+ * `[TRAVELING] a travel is live`, which describes the wreckage of the first
215
+ * attempt and not the failure. Reporting it verbatim sends the reader after
216
+ * the wrong cause.
217
+ */
218
+ export const DM_WORLD_STREAM_STALL_TITLE = 'The world never started streaming';
219
+ export const DM_WORLD_STREAM_STALL_MESSAGE = 'The world is built and the vendor reports it as streaming, but no video ever reached this browser, ' +
220
+ `so the vendor ended the travel after ${seconds(HAPPY_OYSTER_STREAM_START_TIMEOUT_MS)} seconds. ` +
221
+ 'This is a fault on the world-model side, not something retrying from here fixes.';
222
+ /**
223
+ * Build a {@link DmWorldLaunchFailure}. `streamStalled` takes precedence over
224
+ * the vendor's reason for the reason in {@link DM_WORLD_STREAM_STALL_MESSAGE};
225
+ * the vendor's own text is kept as the detail's tail so nothing is hidden.
226
+ */
227
+ export function dmWorldLaunchFailure(input) {
228
+ const worldId = input.worldId ?? null;
229
+ if (input.vendorRefusal != null) {
230
+ return {
231
+ title: reactorSessionRefusalTitle(input.vendorRefusal),
232
+ detail: reactorSessionRefusalDetail(input.vendorRefusal),
233
+ worldId,
234
+ streamStalled: false,
235
+ vendorRefusal: input.vendorRefusal,
236
+ };
237
+ }
238
+ if (input.streamStalled === true) {
239
+ return {
240
+ title: DM_WORLD_STREAM_STALL_TITLE,
241
+ detail: `${DM_WORLD_STREAM_STALL_MESSAGE} (The SDK reported: ${input.message})`,
242
+ worldId,
243
+ streamStalled: true,
244
+ };
245
+ }
246
+ return { title: input.reason, detail: input.message, worldId, streamStalled: false };
247
+ }
248
+ /**
249
+ * §Q `SB.34` — the HEADLINE a surface shows for each block reason.
250
+ *
251
+ * The messages below already differed per reason; the headline did not, so
252
+ * every block read as the same dead end — *"No world for this beat"* on a beat
253
+ * whose frame merely failed looks exactly like a beat nobody storyboarded, and
254
+ * the owner's `star-wars` board (1 rendered frame, 5 refused) presented as
255
+ * having no board at all. The headline is the line that gets read first, so it
256
+ * is the line that has to carry the difference.
257
+ *
258
+ * A `Record` rather than a `switch` so a new {@link DmWorldEntryBlockReason}
259
+ * member fails to compile here instead of silently falling back to generic copy.
260
+ * It lives beside the reasons — the messages already do — so no surface invents
261
+ * its own vocabulary for a state the planner owns.
262
+ */
263
+ export const DM_WORLD_ENTRY_BLOCK_TITLES = {
264
+ // §Q DM.61(a) — "No beat is active yet" describes the DATA and reads as a
265
+ // fault. On the happy path it is not one: a definition spawn starts with
266
+ // `current_beat_id=None` (25 of 88 live sessions on 2026-08-02), so a player
267
+ // who launches and immediately asks for the world hits this BY DESIGN. The
268
+ // headline now names the situation the player is in, and the recourse below
269
+ // names the one move that leaves it.
270
+ no_active_beat: 'The story has not started yet',
271
+ no_frame_for_beat: 'This beat has no storyboard frame',
272
+ frame_not_rendered: "This beat's frame is still rendering",
273
+ frame_render_failed: "This beat's frame failed to render",
274
+ prompt_unavailable: "This beat's frame has no prompt to build from",
275
+ prompt_invalid: "This beat's prompt cannot open a world",
276
+ world_mode_mismatch: "This beat's world belongs to another experience",
277
+ // §Q DM.73 — neither of these says anything about whether a board EXISTS,
278
+ // because neither host state knows. That is the whole point of the row.
279
+ board_read_pending: "Loading this story's storyboard…",
280
+ board_read_failed: "This story's storyboard could not be loaded",
281
+ // §Q WORLD.1-A — nothing is wrong; the surface is waiting on a choice only
282
+ // the player can make. The headline says so rather than borrowing an absence.
283
+ world_not_chosen: 'Pick a world to step into',
284
+ };
285
+ /**
286
+ * The headline for a block, or the generic one when the planner was never
287
+ * reached at all (no board on the story, so there is no reason object).
288
+ */
289
+ export const DM_WORLD_ENTRY_NO_BOARD_TITLE = 'No world for this beat';
290
+ /**
291
+ * §Q `DM.61(a)` — THE ONE MOVE THAT LEAVES THE BLOCK, when one exists.
292
+ *
293
+ * A refusal that states only what is missing is a dead end even when the way
294
+ * out is one click away. `no_active_beat` is the case that made this worth a
295
+ * field: it is reachable on the HAPPY path (a definition spawn starts with no
296
+ * beat until the DM's first `advance_story`), it resolves ENTIRELY by playing
297
+ * the first turn, and nothing on the block said so.
298
+ *
299
+ * The value is the action LABEL a surface puts on the way back, so the copy
300
+ * lives beside the reason it belongs to rather than in whichever pane renders
301
+ * it. `null` means there is genuinely nothing the player can do from here — do
302
+ * NOT invent one to fill the field:
303
+ *
304
+ * · `no_frame_for_beat` / `frame_not_rendered` / `frame_render_failed` /
305
+ * `prompt_unavailable` / `prompt_invalid` resolve on the STORYBOARD, which
306
+ * is a different surface and a different person's job.
307
+ * · `world_mode_mismatch` has no client recourse at all. The frame holds ONE
308
+ * world slot and the bound world lives on the other mode-fixed model, so
309
+ * nothing the player clicks here can rebind it — per-mode slots (or an
310
+ * unbind) is a server change. Faking a button would be worse than the
311
+ * honest dead end.
312
+ */
313
+ export const DM_WORLD_ENTRY_BLOCK_RECOURSE = {
314
+ // codex P3 on #1663 — the label names what the CONTROL does and what it is
315
+ // for, in that order. "Take your first turn" alone would overstate it: the
316
+ // control returns to the chat, it does not send a turn.
317
+ no_active_beat: 'Back to chat to take your first turn',
318
+ no_frame_for_beat: null,
319
+ frame_not_rendered: null,
320
+ frame_render_failed: null,
321
+ prompt_unavailable: null,
322
+ prompt_invalid: null,
323
+ world_mode_mismatch: null,
324
+ // §Q DM.73 — nothing to offer while the read is still in flight; the surface
325
+ // is already doing the only thing that resolves it.
326
+ board_read_pending: null,
327
+ // The one host block with a real move: the read is retryable BY DEFINITION
328
+ // (the host exhausted its automatic attempts to get here), so asking again is
329
+ // not a guess. `dmWorldEntryBlockIsRetryable` is what a surface branches on —
330
+ // this label must NOT be hung on an exit control.
331
+ board_read_failed: 'Try loading the storyboard again',
332
+ // §Q WORLD.1-A — the list of this story's worlds is on the surface BEHIND
333
+ // this pane, so leaving the pane IS the move. Named for the viewer, which is
334
+ // the only surface that can produce this reason.
335
+ world_not_chosen: 'Back to the video',
336
+ };
337
+ /**
338
+ * §Q `DM.73` — whether this block's recourse is a RETRY of the thing that
339
+ * failed, rather than a way out of the surface.
340
+ *
341
+ * `HappyOysterWorldPane` renders `DmWorldEntryBlock.recourse` as the label of
342
+ * its EXIT control, which is right for `no_active_beat` ("Back to chat to take
343
+ * your first turn" genuinely leaves the pane) and would be a lie for
344
+ * `board_read_failed` — a button reading *"Try loading the storyboard again"*
345
+ * that instead closes the world pane. Derived here so no surface re-decides
346
+ * which recourses are exits and which are actions.
347
+ */
348
+ export function dmWorldEntryBlockIsRetryable(reason) {
349
+ return reason === 'board_read_failed';
350
+ }
351
+ /** {@link DM_WORLD_ENTRY_BLOCK_RECOURSE} with the no-reason case folded in. */
352
+ export function dmWorldEntryBlockRecourse(reason) {
353
+ return reason === null ? null : DM_WORLD_ENTRY_BLOCK_RECOURSE[reason];
354
+ }
355
+ /** {@link DM_WORLD_ENTRY_BLOCK_TITLES} with the no-reason case folded in, so a
356
+ * surface never repeats the `?? generic` tail. */
357
+ export function dmWorldEntryBlockTitle(reason) {
358
+ return reason === null
359
+ ? DM_WORLD_ENTRY_NO_BOARD_TITLE
360
+ : DM_WORLD_ENTRY_BLOCK_TITLES[reason];
361
+ }
362
+ /** Build a {@link DmWorldEntryBlock}; the ONLY way a surface should mint one. */
363
+ export function dmWorldEntryBlock(reason, message) {
364
+ return {
365
+ reason,
366
+ title: dmWorldEntryBlockTitle(reason),
367
+ message,
368
+ recourse: dmWorldEntryBlockRecourse(reason),
369
+ };
370
+ }
371
+ /**
372
+ * Add a world to the session's list, de-duplicated by `encryptedWorldId`.
373
+ *
374
+ * Pure and returning a new array so a host can hold it in ordinary state. It is
375
+ * NOT the world-explorer demo's `worldHandleStore.saveStoredWorld` — that one
376
+ * PERSISTS a capped, newest-first list to `localStorage` for a dev host; this is
377
+ * the DM session's in-order record of what THIS session opened, and the durable
378
+ * home for a DM world is `StoryboardFrame.world_id`. Only the
379
+ * dedupe-on-encrypted-id rule is shared, and it is three lines.
380
+ *
381
+ * This is rail 2's data half: a world that is billed and permanent must be VISIBLE
382
+ * (the list is what a surface renders) and REACHABLE afterwards (the handle
383
+ * reopens it via `attachWorld`), including one whose `startTravel` failed.
384
+ *
385
+ * §Q `DM.24` — this list ALONE is not that rail: it is React state, so it is
386
+ * gone on reload while the worlds stay billed. A surface renders
387
+ * {@link collectDmWorldRecords}, which reads the durable frame bindings first
388
+ * and folds this list in; an entry that appears ONLY here is flagged with
389
+ * {@link DM_WORLD_UNRECORDED_NOTICE}.
390
+ */
391
+ export function rememberDmWorldEntry(entries, entry) {
392
+ const existing = entries.findIndex(e => e.handle.encryptedWorldId === entry.handle.encryptedWorldId);
393
+ if (existing === -1)
394
+ return [...entries, entry];
395
+ const next = [...entries];
396
+ next[existing] = entry;
397
+ return next;
398
+ }
399
+ /**
400
+ * What a surface must say about a `'session'`-source record.
401
+ *
402
+ * HappyOyster worlds are permanent, billed and UNLISTABLE — there is no
403
+ * vendor-side list to recover an id from. So a world whose frame binding never
404
+ * landed is reachable ONLY through the string on screen, and only until the page
405
+ * reloads. That is not a warning about a future risk; it is the current state.
406
+ */
407
+ export const DM_WORLD_UNRECORDED_NOTICE = 'This world exists and is billed, but no storyboard frame records it — copy the id now. HappyOyster worlds cannot be listed, so once this page reloads nothing can reach it again.';
408
+ /**
409
+ * Every world this story owns, DURABLE-FIRST — the data half of §Q `DM.24`.
410
+ *
411
+ * The problem it solves: `DmWorldSessionEntry[]` lives in React state, so a
412
+ * surface built on it alone shows nothing after a reload while the worlds it
413
+ * listed are still permanent and still billed. `StoryboardFrame.worldId` is the
414
+ * durable home (written by `DM.27`, mode-stamped by `DM.30`), so the board — not
415
+ * the session — is the primary source here and the session list only ADDS what
416
+ * the board does not yet know.
417
+ *
418
+ * Order: board order (`orderStoryboardFrames`) for durable records, then
419
+ * session-only records in the order they were opened. Durable first because
420
+ * that is the list that is still true tomorrow.
421
+ *
422
+ * A session entry whose world IS on the board enriches that durable record with
423
+ * `trigger`/`openedAt` rather than appearing twice — one world, one row, and the
424
+ * row still says it is safely recorded.
425
+ */
426
+ export function collectDmWorldRecords(input) {
427
+ const entries = input.entries ?? [];
428
+ const records = [];
429
+ const byWorldId = new Map();
430
+ for (const frame of orderStoryboardFrames(input.frameIds, input.frames)) {
431
+ const worldId = frame.worldId?.trim() ?? '';
432
+ if (worldId === '' || byWorldId.has(worldId))
433
+ continue;
434
+ const record = {
435
+ worldId,
436
+ mode: frame.worldMode ?? null,
437
+ frameId: frame.frameId,
438
+ beatId: frame.beatId ?? null,
439
+ source: 'frame',
440
+ trigger: null,
441
+ openedAt: null,
442
+ };
443
+ records.push(record);
444
+ byWorldId.set(worldId, record);
445
+ }
446
+ // §Q MOMENT.8 — the supersede ledger, AFTER the current bindings so a world
447
+ // that is current on one frame is never demoted to "superseded" by another
448
+ // frame's history. Listed at all because these are still permanent and still
449
+ // billed; the row is what keeps them reachable.
450
+ for (const frame of orderStoryboardFrames(input.frameIds, input.frames)) {
451
+ for (const supersededId of frame.supersededWorldIds ?? []) {
452
+ const worldId = supersededId.trim();
453
+ if (worldId === '' || byWorldId.has(worldId))
454
+ continue;
455
+ const record = {
456
+ worldId,
457
+ // The mode is UNKNOWN for a superseded id and is never substituted: the
458
+ // frame's `worldMode` describes the world that REPLACED it, and
459
+ // assuming it here re-creates the `[MODE_MISMATCH]` bug DM.30 fixed.
460
+ mode: null,
461
+ frameId: frame.frameId,
462
+ beatId: frame.beatId ?? null,
463
+ source: 'superseded',
464
+ trigger: null,
465
+ openedAt: null,
466
+ };
467
+ records.push(record);
468
+ byWorldId.set(worldId, record);
469
+ }
470
+ }
471
+ for (const entry of entries) {
472
+ const worldId = entry.handle.encryptedWorldId;
473
+ const durable = byWorldId.get(worldId);
474
+ if (durable !== undefined) {
475
+ // The board already owns it; the session only knows HOW and WHEN.
476
+ durable.trigger = entry.trigger;
477
+ durable.openedAt = entry.openedAt;
478
+ continue;
479
+ }
480
+ const record = {
481
+ worldId,
482
+ // The handle's mode is what the session launched against, i.e. the mode
483
+ // the world was created on — a recorded fact, not a substitution.
484
+ mode: entry.handle.mode,
485
+ frameId: entry.frameId,
486
+ beatId: entry.beatId,
487
+ source: 'session',
488
+ trigger: entry.trigger,
489
+ openedAt: entry.openedAt,
490
+ };
491
+ records.push(record);
492
+ byWorldId.set(worldId, record);
493
+ }
494
+ return records;
495
+ }
496
+ export function summarizeDmWorldPreparation(input) {
497
+ const ordered = orderStoryboardFrames(input.frameIds, input.frames);
498
+ const beatIds = [];
499
+ for (const frame of ordered) {
500
+ const beatId = frame.beatId?.trim() ?? '';
501
+ if (beatId !== '' && !beatIds.includes(beatId))
502
+ beatIds.push(beatId);
503
+ }
504
+ const preparedBeats = beatIds.filter(beatId => {
505
+ // The SAME anchor rule play-time entry uses — a beat counts as prepared
506
+ // only when the frame entry will actually resolve to owns a world. A plain
507
+ // "any frame on this beat has a worldId" would report a beat prepared whose
508
+ // entry then cold-builds, which is precisely the promise this label makes.
509
+ const anchor = resolveDmWorldEntryFrame({
510
+ frameIds: input.frameIds,
511
+ frames: input.frames,
512
+ activeBeatId: beatId,
513
+ });
514
+ return (anchor?.worldId?.trim() ?? '') !== '';
515
+ }).length;
516
+ return {
517
+ preparedBeats,
518
+ totalBeats: beatIds.length,
519
+ label: `${preparedBeats} of ${beatIds.length} prepared`,
520
+ };
521
+ }
522
+ /**
523
+ * §Q `DM.24` — the reopen affordance's own refusal.
524
+ *
525
+ * The row's reopen button plans through {@link planDmWorldEntry} rather than
526
+ * building a handle by hand, so the plan is checked to be a `'reopen'` OF THE
527
+ * CLICKED WORLD before it runs. It can legitimately not be: several frames may
528
+ * carry the same `beatId` and {@link resolveDmWorldEntryFrame} prefers a
529
+ * RENDERED one, so the beat can resolve to a frame that owns a DIFFERENT world
530
+ * (or none). Opening the resolver's choice anyway would mean opening the wrong
531
+ * PAID asset, so this says so instead.
532
+ */
533
+ export const DM_WORLD_REOPEN_UNRESOLVED_MESSAGE = "This world's beat now resolves to a different storyboard frame, so reopening from here could open the wrong world. Open it from that frame on the board instead.";
534
+ /**
535
+ * §Q `WORLD.1-A` — what a surface tells a player who reached the world pane
536
+ * without naming a world. Paired with the `world_not_chosen` block reason.
537
+ */
538
+ export const DM_WORLD_NOT_CHOSEN_MESSAGE = 'HappyOyster worlds belong to a storyboard frame, so this surface opens one you pick rather than guessing. Choose a world from the list beside the video.';
539
+ /**
540
+ * §Q `WORLD.1-A` — THE ONE DECISION BEHIND A "REOPEN THIS WORLD" CLICK.
541
+ *
542
+ * Pure, and shared by every surface that lists {@link collectDmWorldRecords}:
543
+ * the DM play episode and the viewer both offer the same button and both must
544
+ * refuse the same way. It was written once in `DmExperienceLayout` and copied
545
+ * nowhere — this exists so it stays that way now the viewer has the affordance
546
+ * too.
547
+ *
548
+ * The guard is two conditions, and dropping either one turns a free reattach
549
+ * into a paid mistake: the plan must be a `'reopen'` (a `'create'` would mint a
550
+ * SECOND permanent world for a button labelled "reopen"), and its handle must be
551
+ * THE CLICKED WORLD (the beat can resolve to a frame owning a different one).
552
+ *
553
+ * `planned === null` means the host could not reach the planner at all — no
554
+ * board in hand — which is a refusal like any other here, not a licence to open.
555
+ */
556
+ export function dmWorldReopenDecision(record, planned) {
557
+ if (planned !== null &&
558
+ planned.ok &&
559
+ planned.plan.action === 'reopen' &&
560
+ planned.plan.handle?.encryptedWorldId === record.worldId) {
561
+ return { plan: planned.plan, blocked: null };
562
+ }
563
+ return {
564
+ plan: null,
565
+ blocked: planned !== null && !planned.ok
566
+ ? dmWorldEntryBlock(planned.reason, planned.message)
567
+ : dmWorldEntryBlock(null, DM_WORLD_REOPEN_UNRESOLVED_MESSAGE),
568
+ };
569
+ }
570
+ /* ==========================================================================
571
+ * §Q `DM.67` — A CONTENT-REFUSED BEAT IS NOT A DEAD END
572
+ * ========================================================================== */
573
+ /**
574
+ * WHAT WAS MEASURED. CHECKPOINT-3 (2026-08-02,
575
+ * `~/.seer-e2e/checkpoint3-0802-verdicts.md` §B3-residual): beat 1's world was
576
+ * refused `content_rejected [403004]` by HappyOyster moderation and the pane
577
+ * rendered the vendor's *"Please try something else"* with NO control on it.
578
+ * Beat 2 then opened and played — so the refusal is PER BEAT, the recourse
579
+ * existed, and nothing on screen said so.
580
+ *
581
+ * The route out is the story's OTHER beats whose entry the planner would
582
+ * authorise. Each route is decided by {@link planDmWorldEntry} itself, never by
583
+ * a second reading of the frame here, so a route can never promise an entry the
584
+ * click then refuses.
585
+ */
586
+ const HAPPY_OYSTER_FAILURE_CONTENT_REJECTED = 'content_rejected';
587
+ /**
588
+ * Whether a failed launch was the vendor's CONTENT refusal of this beat's scene
589
+ * (403004 moderation / 403005 copyright — `classifyHappyOysterError` collapses
590
+ * both). That refusal is about the seed and prompt, so a different beat's world
591
+ * can still open, which is what makes {@link dmWorldContentRefusalRoutes} the
592
+ * recourse. No other launch failure gets those routes: a transport fault or a
593
+ * credits refusal fails the next beat exactly the same way.
594
+ */
595
+ export function dmWorldLaunchIsContentRefusal(reason) {
596
+ return reason === HAPPY_OYSTER_FAILURE_CONTENT_REJECTED;
597
+ }
598
+ export const DM_WORLD_REFUSAL_ROUTE_REOPEN_HINT = 'reopens the world this beat already owns';
599
+ export const DM_WORLD_REFUSAL_ROUTE_BUILD_HINT = 'builds this beat’s world — asks you first';
600
+ /** The sentence above the routes. */
601
+ export const DM_WORLD_CONTENT_REFUSAL_ROUTES_LEAD = 'The world model refused this beat’s scene on content grounds. That refusal is about this beat only — another beat’s world can still open:';
602
+ /**
603
+ * What the card says when no other beat can be entered. Said in words, because
604
+ * an empty list under a refusal is the same dead end this row removes.
605
+ */
606
+ export const DM_WORLD_CONTENT_REFUSAL_NO_ROUTE = 'The world model refused this beat’s scene on content grounds, and no other beat on this story’s board has a world or a drawn frame to open one from yet. Carry on in the chat — the refusal is about this beat, not the story.';
607
+ /**
608
+ * The control under {@link DM_WORLD_CONTENT_REFUSAL_NO_ROUTE}. The routes are
609
+ * planned from the board the episode read when it opened, and a session board
610
+ * is still drawing frames for minutes after launch — so "nothing else can open
611
+ * yet" from that read is exactly when re-reading the board is the way out.
612
+ */
613
+ export const DM_WORLD_CONTENT_REFUSAL_RECHECK_LABEL = 'Check the board again';
614
+ /**
615
+ * §Q `DM.67` — the beats a content-refused entry can go to instead.
616
+ *
617
+ * Every beat on the board other than the refused ones, in board order, kept
618
+ * only when {@link planDmWorldEntry} authorises an entry for it. Reopens come
619
+ * first: they are free, and attaching an existing world submits nothing new to
620
+ * the moderation that just refused. Planned WITHOUT auto-fire, so a route that
621
+ * would mint a world arrives as `'confirm_required'` and the pane still parks
622
+ * it on the consent card.
623
+ */
624
+ export function dmWorldContentRefusalRoutes(input) {
625
+ const refused = new Set(input.refusedBeatIds.map(id => id.trim()));
626
+ const beatById = input.beatById ?? new Map();
627
+ const seen = new Set();
628
+ const routes = [];
629
+ for (const frame of orderStoryboardFrames(input.frameIds, input.frames)) {
630
+ const beatId = frame.beatId?.trim() ?? '';
631
+ if (beatId === '' || refused.has(beatId) || seen.has(beatId))
632
+ continue;
633
+ seen.add(beatId);
634
+ const planned = planDmWorldEntry({
635
+ frameIds: input.frameIds,
636
+ frames: input.frames,
637
+ activeBeatId: beatId,
638
+ mode: input.mode,
639
+ });
640
+ if (!planned.ok)
641
+ continue;
642
+ const { action } = planned.plan;
643
+ routes.push({
644
+ beatId,
645
+ frameId: planned.plan.frame.frameId,
646
+ action,
647
+ label: beatHeadline(beatId, beatById),
648
+ hint: action === 'reopen'
649
+ ? DM_WORLD_REFUSAL_ROUTE_REOPEN_HINT
650
+ : DM_WORLD_REFUSAL_ROUTE_BUILD_HINT,
651
+ });
652
+ }
653
+ // Stable: board order within each group.
654
+ return [
655
+ ...routes.filter(route => route.action === 'reopen'),
656
+ ...routes.filter(route => route.action !== 'reopen'),
657
+ ];
658
+ }
659
+ /**
660
+ * Whether an action would MINT a new permanent, billed world (`'create'` now,
661
+ * `'confirm_required'` once an operator confirms). Derived from the action
662
+ * rather than stored on the plan, so no plan can carry a stale flag.
663
+ */
664
+ export function dmWorldEntryWouldCreateWorld(action) {
665
+ return action === 'create' || action === 'confirm_required';
666
+ }
667
+ /**
668
+ * Resolve the ACTIVE BEAT to its board frame, deterministically.
669
+ *
670
+ * Board order (`frameIds`) is the tie-break, so the same beat always resolves
671
+ * to the same frame for every player of the story. A beat with several frames
672
+ * prefers the first that has actually RENDERED — an unrendered frame has no
673
+ * seed, and silently seeding from a later beat would be worse than reporting
674
+ * nothing.
675
+ *
676
+ * Returns `null` when the beat is absent or no frame carries it.
677
+ */
678
+ export function resolveDmWorldEntryFrame(input) {
679
+ const beatId = input.activeBeatId?.trim() ?? '';
680
+ if (beatId === '')
681
+ return null;
682
+ const matches = orderStoryboardFrames(input.frameIds, input.frames).filter(frame => frame.beatId === beatId);
683
+ return matches.find(frame => frameImageUrl(frame) !== null) ?? matches[0] ?? null;
684
+ }
685
+ /**
686
+ * How many characters {@link composeDmWorldPrompt} holds back from the frame's
687
+ * compacted prompt so the DM tag's atmosphere survives (§Q `DM.21`).
688
+ *
689
+ * The prefix plus enough of the atmosphere to be worth appending —
690
+ * {@link DM_WORLD_ATMOSPHERE_MIN_CHARS}, the floor the module already used to
691
+ * decide a stub was not worth shipping — or the WHOLE atmosphere when it is
692
+ * shorter than that floor, because reserving more ceremony than the text needs
693
+ * would shed board context for nothing.
694
+ *
695
+ * `0` for an empty atmosphere: nothing to seat, so the frame gets the full cap.
696
+ */
697
+ export function dmWorldAtmosphereReservation(atmosphere) {
698
+ if (atmosphere === '')
699
+ return 0;
700
+ return (DM_WORLD_ATMOSPHERE_PREFIX.length +
701
+ Math.min(atmosphere.length, DM_WORLD_ATMOSPHERE_MIN_CHARS));
702
+ }
703
+ /**
704
+ * Compose the prompt: the frame's SERVER-COMPILED prompt text, COMPACTED to
705
+ * the vendor cap, plus the DM tag's atmosphere.
706
+ *
707
+ * The base is `FrameVariant.promptText` — the exact string the storyboard
708
+ * worker sent for this frame — deliberately NOT a client-side re-flattening of
709
+ * `FramePrompt`. `compiled_text()` is server-side by design (`FramePrompt`'s
710
+ * docblock) and a second flattener here would be a second source of truth for
711
+ * what a frame looks like.
712
+ *
713
+ * §Q `SB.34` — read through `promptFrameVariant`, NOT `displayFrameVariant`.
714
+ * The latter is succeeded-only (correctly, for images), which meant a frame
715
+ * whose render was refused reported no prompt at all and blocked the beat as if
716
+ * it had never been storyboarded. The prompt is composed BEFORE the image call
717
+ * and is not what failed, so a failed variant's text is a real answer here even
718
+ * though its (absent) image is not. This is the accessor split the row calls
719
+ * for: image display keeps the succeeded-only rule untouched.
720
+ *
721
+ * §Q `DM.18` — `compiled_text` is budgeted against `PROMPT_TEXT_MAX_LEN * 4`
722
+ * and a real frame compiles past {@link HAPPY_OYSTER_PROMPT_MAX_CHARS}, so the
723
+ * base runs through {@link compactFramePromptText} first. That sheds whole
724
+ * semantic units (reference addressing, arc stakes, themes) in a fixed
725
+ * ceremony-first order and NEVER touches the `Action` line — see that module
726
+ * for why truncation is not an option here. A base already inside the cap comes
727
+ * back byte-identical.
728
+ *
729
+ * A frame whose `Action` alone exceeds the cap stays over it: this returns the
730
+ * fully-shed text and `planDmWorldEntry`'s `happyOysterPromptIssue` check
731
+ * reports `prompt_invalid` with the real overflow, rather than launching a
732
+ * world built from half a beat.
733
+ *
734
+ * §Q `DM.21` — DM.18 left the real frame at 1999 of 2000, so the DM tag's own
735
+ * text no longer fit and was dropped. `DM.19` established that the world tracks
736
+ * the storyboard's PROSE, which makes that drop the loss of the INTERACTIVE
737
+ * half of the entry: the world gets built from the board alone and the DM's
738
+ * live scene intent is silently discarded. So the atmosphere's room is now
739
+ * RESERVED before compaction — and taken from CEREMONY only
740
+ * (`shedTiers: ['ceremony']`), never from the cast, the setting or the action.
741
+ * That honours the ratified "the frame is never the thing that gets cut"
742
+ * precedence rather than inverting it: ceremony is not the frame's substance.
743
+ * When ceremony alone cannot free the reservation, the reservation is abandoned
744
+ * and the full-cap compaction stands — the frame still wins.
745
+ *
746
+ * Returns `null` when the frame carries no compiled prompt.
747
+ */
748
+ export function composeDmWorldPrompt(frame, atmosphere) {
749
+ const compiled = promptFrameVariant(frame)?.promptText?.trim() ?? '';
750
+ if (compiled === '')
751
+ return null;
752
+ // The frame's STRUCTURED cast, so the cast rung keeps every name exactly
753
+ // instead of re-deriving the roster from the flattened `Characters:` line.
754
+ const castInWords = frame.prompt?.charactersInWords;
755
+ const extra = atmosphere?.trim() ?? '';
756
+ // §Q DM.21 — reserve the atmosphere's room out of CEREMONY before compacting.
757
+ // A ceremony-only pass that cannot reach the reduced target comes back over
758
+ // it; the full-cap compaction below is then the answer and the atmosphere
759
+ // takes whatever is left, exactly as before.
760
+ const reservation = dmWorldAtmosphereReservation(extra);
761
+ if (reservation > 0) {
762
+ const target = HAPPY_OYSTER_PROMPT_MAX_CHARS - reservation;
763
+ const reserved = compactFramePromptText(compiled, target, {
764
+ castInWords,
765
+ shedTiers: ['ceremony'],
766
+ });
767
+ if (reserved.text.length <= target) {
768
+ return appendDmWorldAtmosphere(reserved.text, extra);
769
+ }
770
+ }
771
+ const base = compactFramePromptText(compiled, HAPPY_OYSTER_PROMPT_MAX_CHARS, {
772
+ castInWords,
773
+ }).text;
774
+ return extra === '' ? base : appendDmWorldAtmosphere(base, extra);
775
+ }
776
+ /**
777
+ * Append the atmosphere to an already-compacted base, inside the vendor cap.
778
+ *
779
+ * The frame text is never cut here — the base arrives compacted and this only
780
+ * decides how much of the ATMOSPHERE fits. Three outcomes, in order: the whole
781
+ * atmosphere when it fits; a trimmed one when at least
782
+ * {@link DM_WORLD_ATMOSPHERE_MIN_CHARS} of it does; nothing when even that
783
+ * would be a stub.
784
+ */
785
+ function appendDmWorldAtmosphere(base, extra) {
786
+ const room = HAPPY_OYSTER_PROMPT_MAX_CHARS -
787
+ base.length -
788
+ DM_WORLD_ATMOSPHERE_PREFIX.length;
789
+ if (extra.length <= room) {
790
+ return `${base}${DM_WORLD_ATMOSPHERE_PREFIX}${extra}`;
791
+ }
792
+ if (room < DM_WORLD_ATMOSPHERE_MIN_CHARS)
793
+ return base;
794
+ return `${base}${DM_WORLD_ATMOSPHERE_PREFIX}${extra.slice(0, room).trimEnd()}`;
795
+ }
796
+ export function dmWorldEntrySceneRelation(liveWorld, frame) {
797
+ const liveFrameId = liveWorld.frameId?.trim() ?? '';
798
+ if (liveFrameId !== '' && liveFrameId === frame.frameId)
799
+ return 'same';
800
+ // Deliberately NOT `return liveFrameId === frame.frameId` above: a DIFFERENT
801
+ // frame of the SAME sequence is still one scene, and short-circuiting on the
802
+ // frame id would have turned DM.12's steer into a create for every anchored
803
+ // pan across a scene — a spend regression dressed up as a correctness fix.
804
+ const liveSequenceId = liveWorld.sequenceId?.trim() ?? '';
805
+ const frameSequenceId = frame.sequenceId?.trim() ?? '';
806
+ if (liveSequenceId !== '' && frameSequenceId !== '') {
807
+ return liveSequenceId === frameSequenceId ? 'same' : 'changed';
808
+ }
809
+ // Unanchored, and the frame ids are known to differ: a change.
810
+ if (liveFrameId !== '')
811
+ return 'changed';
812
+ const liveBeatId = liveWorld.beatId?.trim() ?? '';
813
+ const frameBeatId = frame.beatId?.trim() ?? '';
814
+ if (liveBeatId !== '' && frameBeatId !== '') {
815
+ return liveBeatId === frameBeatId ? 'same' : 'changed';
816
+ }
817
+ return 'unknown';
818
+ }
819
+ /**
820
+ * Decide what a DM world entry may do, from deterministic state only.
821
+ *
822
+ * Every failure path lands here — BEFORE `connect`, before `createWorld`, so
823
+ * before anything is billed. Exactly one branch mints a billed world
824
+ * (`'create'`), and it requires BOTH the player's auto-fire setting AND a
825
+ * genuine scene change; everything else steers, reopens, or asks.
826
+ */
827
+ export function planDmWorldEntry(input) {
828
+ const frame = resolveDmWorldEntryFrame(input);
829
+ if (frame === null) {
830
+ const beatId = input.activeBeatId?.trim() ?? '';
831
+ return beatId === ''
832
+ ? {
833
+ ok: false,
834
+ reason: 'no_active_beat',
835
+ // §Q DM.61(a) — this is the PRE-FIRST-TURN state, not a fault, and
836
+ // the old copy ("No beat is active in this session yet — the world is
837
+ // seeded from the storyboard frame for the current beat.") described
838
+ // the join key instead of the situation. A definition spawn starts
839
+ // with no beat until the DM's first `advance_story`, so a player who
840
+ // launches and immediately asks for the world lands here on the happy
841
+ // path. Say what has to happen, and let the block carry the action.
842
+ message: 'The DM has not opened the scene yet, so the party is not standing on a beat — and a ' +
843
+ "world is seeded from the storyboard frame for the beat you're on. Take your first turn " +
844
+ 'in the chat; the world opens on the beat the DM moves you to.',
845
+ }
846
+ : {
847
+ ok: false,
848
+ reason: 'no_frame_for_beat',
849
+ // §Q ARC.6k — the old copy read "storyboard this beat before
850
+ // entering its world", and for a FORK-approved arc that instruction
851
+ // is impossible to follow: a board is only ever minted in the
852
+ // canonical story's id space, so no amount of re-storyboarding can
853
+ // ever produce a frame carrying a fork-scoped beat id. The owner
854
+ // followed it on 2026-08-02 and it could not have worked. The
855
+ // caller-side scope translation (`storyboardJoinBeatId`) fixes the
856
+ // JOIN; this fixes the advice for the residual cases where the join
857
+ // still finds nothing, without prescribing an action that cannot
858
+ // succeed.
859
+ message: `No storyboard frame is anchored to beat "${beatId}" — a world is seeded from a ratified ` +
860
+ "board frame and this story's board has none for it. Storyboard the beat to give it one; if " +
861
+ 'this adventure came from a FORK-approved arc, storyboarding cannot reach it (boards are ' +
862
+ 'minted only in the canonical story\'s id space) — re-approve the arc as a merge instead.',
863
+ };
864
+ }
865
+ const liveWorld = input.liveWorld ?? null;
866
+ // Owner DM.12 — a live world whose scene has NOT changed is steered, never
867
+ // rebuilt. This is the rail that actually bounds spend: it caps `createWorld`
868
+ // at one per scene instead of one per LLM emission.
869
+ const sceneRelation = liveWorld === null ? null : dmWorldEntrySceneRelation(liveWorld, frame);
870
+ if (liveWorld !== null && sceneRelation === 'same') {
871
+ const steerPrompt = composeDmWorldPrompt(frame, input.atmosphere);
872
+ if (steerPrompt === null) {
873
+ return {
874
+ ok: false,
875
+ reason: 'prompt_unavailable',
876
+ message: 'The storyboard frame carries no compiled prompt, so there is nothing to re-aim the world with.',
877
+ };
878
+ }
879
+ return {
880
+ ok: true,
881
+ plan: {
882
+ action: 'steer',
883
+ frame,
884
+ mode: input.mode,
885
+ handle: liveWorld.handle,
886
+ prompt: steerPrompt,
887
+ seedImageUrl: null,
888
+ autoStopAfterMs: null,
889
+ },
890
+ };
891
+ }
892
+ // Owner ruling Q2 — world ownership is PER FRAME: a frame that already owns a
893
+ // world reopens it. Free, instant, and it is preferred over any create.
894
+ const worldId = frame.worldId?.trim() ?? '';
895
+ if (worldId !== '') {
896
+ // §Q DM.30 — the STORED mode, never the session's. This line used to read
897
+ // `mode: input.mode`, which fabricated the handle's mode from whichever
898
+ // session happened to be open: `launchHappyOysterWorld`'s pre-flight then
899
+ // compared the session mode with itself and could never fire, so a world
900
+ // belonging to the OTHER mode reached the vendor and came back
901
+ // `[MODE_MISMATCH]` — with the world already paid for.
902
+ const storedMode = frame.worldMode ?? null;
903
+ if (storedMode !== null && storedMode !== input.mode) {
904
+ return {
905
+ ok: false,
906
+ reason: 'world_mode_mismatch',
907
+ message: `This beat's world belongs to the "${storedMode}" experience, but this session is "${input.mode}" — ` +
908
+ 'HappyOyster worlds live on the mode-fixed model that created them and cannot be opened from the other one. ' +
909
+ `Reopen it from the ${storedMode} surface.`,
910
+ };
911
+ }
912
+ return {
913
+ ok: true,
914
+ plan: {
915
+ action: 'reopen',
916
+ frame,
917
+ // A frame bound before DM.30 carries no mode. Falling back to the
918
+ // session's keeps those (DM-created, therefore adventure) worlds
919
+ // reopenable — the milestone run's `9b838d88…` frame among them —
920
+ // rather than dead-ending every pre-DM.30 binding.
921
+ handle: { encryptedWorldId: worldId, mode: storedMode ?? input.mode },
922
+ mode: input.mode,
923
+ prompt: '',
924
+ seedImageUrl: null,
925
+ autoStopAfterMs: null,
926
+ },
927
+ };
928
+ }
929
+ const seedImageUrl = frameImageUrl(frame);
930
+ if (seedImageUrl === null) {
931
+ // §Q SB.34 — a REFUSED frame and a still-generating one are both "no image",
932
+ // and telling the player to wait for one that will never arrive is the
933
+ // failure the row is about. A world still cannot be created either way (the
934
+ // seed is bytes), so this changes what the player is TOLD, not what is spent.
935
+ if (frameRenderFailed(frame)) {
936
+ const why = frameRenderFailure(frame);
937
+ return {
938
+ ok: false,
939
+ reason: 'frame_render_failed',
940
+ message: 'This beat IS storyboarded — its frame is written and waiting — but the image model refused or failed to draw it, so there is no starting image to seed the world with.' +
941
+ (why === null ? '' : ` The model reported: ${why}`),
942
+ };
943
+ }
944
+ return {
945
+ ok: false,
946
+ reason: 'frame_not_rendered',
947
+ message: 'The storyboard frame for this beat has not rendered yet, so there is no starting image to seed the world with.',
948
+ };
949
+ }
950
+ const prompt = composeDmWorldPrompt(frame, input.atmosphere);
951
+ if (prompt === null) {
952
+ return {
953
+ ok: false,
954
+ reason: 'prompt_unavailable',
955
+ message: 'The storyboard frame carries no compiled prompt, so the world has nothing to build from.',
956
+ };
957
+ }
958
+ const promptIssue = happyOysterPromptIssue(prompt);
959
+ if (promptIssue !== null) {
960
+ return { ok: false, reason: 'prompt_invalid', message: promptIssue };
961
+ }
962
+ // Rail 1 — auto-fire is the player's setting, and reaching here means the
963
+ // scene DID change (the steer branch above returns for an unchanged scene).
964
+ //
965
+ // §Q DM.62 / codex P1 on #1663 — EXCEPT when a world IS streaming and its
966
+ // identity is unrecorded. That is not a scene change, it is an unanswered
967
+ // question, and auto-firing it bills a second permanent world for a scene
968
+ // that may already be on screen. Auto-fire is consent to skip the prompt on a
969
+ // KNOWN cut, not consent to guess. An operator confirmation is the honest
970
+ // resolution, and it is exactly one click.
971
+ const autoFire = (input.autoFireEnabled ?? DM_WORLD_AUTO_FIRE_DEFAULT) && sceneRelation !== 'unknown';
972
+ return {
973
+ ok: true,
974
+ plan: {
975
+ action: autoFire ? 'create' : 'confirm_required',
976
+ frame,
977
+ mode: input.mode,
978
+ handle: null,
979
+ prompt,
980
+ seedImageUrl,
981
+ autoStopAfterMs: autoFire
982
+ ? (input.autoStopAfterMs ?? DM_WORLD_AUTO_STOP_MS_DEFAULT)
983
+ : null,
984
+ },
985
+ };
986
+ }
987
+ /**
988
+ * Execute a {@link planDmWorldEntry} plan. This is the ONLY place a DM world
989
+ * entry reaches `createWorld`, and it refuses three things outright:
990
+ *
991
+ * - a `confirm_required` plan without `operatorConfirmed: true` (i.e. auto-fire
992
+ * off and nobody confirmed);
993
+ * - a create with no prepared seed bytes;
994
+ * - anything the underlying launcher already refuses (prompt cap, mode
995
+ * mismatch, …).
996
+ *
997
+ * All three throw a {@link HappyOysterLaunchError} before a session is opened.
998
+ * A `'steer'` plan is NOT launched here, and no second executor is owed: the
999
+ * adapter-agnostic steer path already shipped as §Q DM.14 — the pane registers
1000
+ * a steer closure (`useExperienceSource.registerWorldSteer`) and client-core's
1001
+ * `resolveWorldSteerCommand(adapterId)` maps it to the live model's verb
1002
+ * (HappyOyster → `instruct`). A steer plan feeds that, not this launcher.
1003
+ */
1004
+ export async function launchDmWorldEntry(plan, bridge, options = {}) {
1005
+ if (plan.action === 'steer') {
1006
+ throw new HappyOysterLaunchError({
1007
+ reason: 'invalid_request',
1008
+ message: 'A steer plan re-aims the live world through the pane, it does not launch one.',
1009
+ retryable: false,
1010
+ });
1011
+ }
1012
+ if (plan.action === 'confirm_required' && options.operatorConfirmed !== true) {
1013
+ throw new HappyOysterLaunchError({
1014
+ reason: 'invalid_request',
1015
+ message: 'Creating this world needs an explicit confirmation — a HappyOyster world is paid and permanent, so with auto-fire off a DM directive alone never creates one.',
1016
+ retryable: false,
1017
+ });
1018
+ }
1019
+ // Exhaustive by construction: a new `DmWorldEntryAction` member fails to
1020
+ // compile here rather than falling through a ternary into 'confirmed'.
1021
+ const TRIGGERS = { reopen: 'reopen', create: 'auto', confirm_required: 'confirmed' };
1022
+ const trigger = TRIGGERS[plan.action];
1023
+ const launchOptions = { jwt: options.jwt };
1024
+ /**
1025
+ * §Q `DM.43` — worlds already recorded by THIS launch. The handle is now
1026
+ * offered at three points (created, succeeded, failed-but-created), and they
1027
+ * describe ONE world, so the frame is written once. Recorded only AFTER the
1028
+ * write resolves, so a failed create-time write is retried by the later
1029
+ * offers rather than being swallowed by its own bookkeeping.
1030
+ */
1031
+ const persisted = new Set();
1032
+ const persist = async (handle) => {
1033
+ if (persisted.has(handle.encryptedWorldId))
1034
+ return;
1035
+ const recorded = await options.onWorldHandle?.(handle, {
1036
+ handle,
1037
+ frameId: plan.frame.frameId,
1038
+ beatId: plan.frame.beatId ?? null,
1039
+ trigger,
1040
+ openedAt: Date.now(),
1041
+ });
1042
+ // `false` is the host telling us the write did not land — see
1043
+ // {@link DmWorldHandleRecorded}. A throw is handled the same way, by never
1044
+ // reaching this line. Anything else (including `undefined`) is recorded.
1045
+ if (recorded !== false)
1046
+ persisted.add(handle.encryptedWorldId);
1047
+ };
1048
+ if (plan.action === 'reopen') {
1049
+ // Non-null by construction — `planDmWorldEntry` sets `handle` on a reopen.
1050
+ const handle = plan.handle;
1051
+ const result = await launchHappyOysterWorld({ kind: 'reopen', handle }, bridge, plan.mode, launchOptions);
1052
+ // Recorded like a create: rail 2 is about what the SESSION opened, and a
1053
+ // reopened world is just as visible and just as reachable.
1054
+ await persist(result.handle);
1055
+ return result;
1056
+ }
1057
+ if (options.seed === undefined) {
1058
+ throw new HappyOysterLaunchError({
1059
+ reason: 'invalid_request',
1060
+ message: 'The starting frame has not been prepared — a DM world is always seeded from prepared image bytes, never from a frame URL.',
1061
+ retryable: false,
1062
+ });
1063
+ }
1064
+ try {
1065
+ const result = await launchHappyOysterWorld({
1066
+ kind: 'create',
1067
+ prompt: plan.prompt,
1068
+ firstFrameImage: options.seed.blob,
1069
+ }, bridge, plan.mode,
1070
+ // §Q DM.43 — the handle goes to the frame the moment the vendor mints it,
1071
+ // BEFORE `startTravel`. Persisting only on success (or only from the
1072
+ // error's `handle`) leaves the whole 60 s stream-start window — and the
1073
+ // vendor's 3-attempt ladder behind it, up to ~3 minutes — as a period in
1074
+ // which a reload orphans a permanent, billed, unlistable world.
1075
+ { ...launchOptions, onWorldCreated: persist });
1076
+ await persist(result.handle);
1077
+ return result;
1078
+ }
1079
+ catch (error) {
1080
+ if (error instanceof HappyOysterLaunchError && error.handle !== null) {
1081
+ // A world EXISTS and is already billed even though the launch failed.
1082
+ // Persist it before rethrowing, and never let a persistence failure
1083
+ // replace the error the caller needs to see.
1084
+ try {
1085
+ await persist(error.handle);
1086
+ }
1087
+ catch {
1088
+ /* the launch error below is the one that matters */
1089
+ }
1090
+ }
1091
+ throw error;
1092
+ }
1093
+ }
1094
+ /** Every reason, for runtime validation by a probe or a coherence check. */
1095
+ export const DM_WORLD_STREAM_END_REASONS = [
1096
+ 'travel_completed',
1097
+ 'session_ended',
1098
+ 'video_gone',
1099
+ 'video_silent',
1100
+ ];
1101
+ /**
1102
+ * `HTMLMediaElement.HAVE_NOTHING`. Named because the whole `video_gone` verdict
1103
+ * turns on it and a bare `0` at a comparison site reads as a placeholder.
1104
+ */
1105
+ export const HTML_MEDIA_HAVE_NOTHING = 0;
1106
+ /**
1107
+ * How long the render may go without a new frame before the stream is called
1108
+ * dead, in ms.
1109
+ *
1110
+ * DELIBERATELY LONGER THAN THE SDK'S OWN CONFIRM DELAY. The SDK's runtime
1111
+ * monitor debounces a `waiting`/`stalled`/`suspend` by
1112
+ * `DEFAULT_VIDEO_ISSUE_CONFIRM_DELAY_MS = 3000` and then re-checks whether the
1113
+ * element became playable again — i.e. the vendor treats sub-3 s silence as
1114
+ * ordinary rebuffering. A host bound at or below that would paint "the stream
1115
+ * ended" over a stream the SDK is about to recover, which is the same
1116
+ * dishonest surface this row exists to remove, pointing the other way. 15 s is
1117
+ * five times the vendor's own tolerance and still well inside the 10 s
1118
+ * sampling interval that caught the real failure.
1119
+ */
1120
+ export const DM_WORLD_STREAM_SILENCE_MS = 15_000;
1121
+ /**
1122
+ * How long an INFERRED end must persist before a surface may state it, in ms.
1123
+ *
1124
+ * Longer than the SDK's own `DEFAULT_VIDEO_ISSUE_CONFIRM_DELAY_MS = 3000`
1125
+ * rebuffer-confirm delay, for the same reason the silence bound is: a single
1126
+ * sample at `HAVE_NOTHING` — a source swap, a reload, a brief rebuffer — is not
1127
+ * yet a dead stream, and painting the ended notice on it is the mirror of the
1128
+ * defect this row removes.
1129
+ */
1130
+ export const DM_WORLD_STREAM_DEAD_CONFIRM_MS = 4_000;
1131
+ /**
1132
+ * Whether a reason may be stated the moment it is first seen.
1133
+ *
1134
+ * Only the vendor-reported end is authoritative enough: `travel_completed` is
1135
+ * the SDK folding a server-side status into its own facade, so there is nothing
1136
+ * to confirm and nothing to recover from. Everything else is INFERRED from the
1137
+ * client's own view and must persist for {@link DM_WORLD_STREAM_DEAD_CONFIRM_MS}
1138
+ * before a surface says it out loud.
1139
+ */
1140
+ export function dmWorldStreamEndIsImmediate(reason) {
1141
+ return reason === 'travel_completed';
1142
+ }
1143
+ /** The SDK client phase that means the live stream is up. */
1144
+ export const HAPPY_OYSTER_PHASE_STREAMING = 'streaming';
1145
+ /**
1146
+ * The `onTravelStatusChanged` value the SDK folds into its own facade state —
1147
+ * it is the one status on which `HappyOysterModel.handleTravelCompleted` runs.
1148
+ * Named here so a host compares against vendor vocabulary in one place instead
1149
+ * of spelling the literal at each call site.
1150
+ */
1151
+ export const HAPPY_OYSTER_TRAVEL_STATUS_COMPLETED = 'completed';
1152
+ /**
1153
+ * Why the claimed-live world is not streaming, or `null` while it is fine.
1154
+ *
1155
+ * Pure, so a host can call it on a timer and a check can call it on a fixture.
1156
+ * Order is authority: a vendor-reported end outranks the client phase, which
1157
+ * outranks anything inferred from the element. Reversible BY CONSTRUCTION —
1158
+ * it reads only the current observation, so an element that starts advancing
1159
+ * again returns `null` and the surface goes back to claiming the world.
1160
+ */
1161
+ export function dmWorldStreamEndReason(input) {
1162
+ if (input.travelCompleted)
1163
+ return 'travel_completed';
1164
+ if (typeof input.clientPhase === 'string' &&
1165
+ input.clientPhase !== HAPPY_OYSTER_PHASE_STREAMING) {
1166
+ return 'session_ended';
1167
+ }
1168
+ // A held world is not a dead one. The player's own Pause stops `currentTime`
1169
+ // and sets the element's `paused`, so every element-derived reason below
1170
+ // would otherwise fire on it.
1171
+ if (input.userPaused)
1172
+ return null;
1173
+ if (input.sample === null)
1174
+ return null;
1175
+ if (input.sample.readyState === HTML_MEDIA_HAVE_NOTHING)
1176
+ return 'video_gone';
1177
+ if (input.msSinceAdvance !== null &&
1178
+ input.msSinceAdvance >= DM_WORLD_STREAM_SILENCE_MS) {
1179
+ return 'video_silent';
1180
+ }
1181
+ return null;
1182
+ }
1183
+ export const DM_WORLD_STREAM_ENDED_TITLE = 'The world stopped streaming';
1184
+ export const DM_WORLD_REENTER_ACTION = 'Re-enter the world';
1185
+ const DM_WORLD_STREAM_END_DETAIL = {
1186
+ travel_completed: 'The world model ended this run, so no more video is coming.',
1187
+ session_ended: 'The session carrying this world closed, so the video stopped.',
1188
+ video_gone: 'No video is reaching this browser any more — the stream is gone rather than buffering.',
1189
+ video_silent: `No new frames have arrived for ${seconds(DM_WORLD_STREAM_SILENCE_MS)} seconds, so this run has stopped.`,
1190
+ };
1191
+ /**
1192
+ * The permanence claim, appended ONLY when a handle exists to reopen.
1193
+ *
1194
+ * It used to be on every reason unconditionally, which overclaims: on a launch
1195
+ * whose world id never reached this surface, "the world is still recorded" is
1196
+ * exactly the thing that is not known (codex on #1669).
1197
+ */
1198
+ const DM_WORLD_STREAM_END_PERMANENCE = 'The world itself is permanent and is still recorded.';
1199
+ /**
1200
+ * The copy for a dead stream — one place, so no surface can keep claiming a
1201
+ * live world.
1202
+ *
1203
+ * The re-entry half is NOT decoration: a stream that stopped with no way back
1204
+ * leaves a black pane, which is the state this row was filed against. When a
1205
+ * handle exists the detail carries {@link DM_WORLD_REOPEN_NOTICE} verbatim,
1206
+ * because re-entering IS a reopen and `DM.17` already measured what a reopen
1207
+ * does — it returns to the opening scene. Restating that in different words
1208
+ * here would be a second source of truth for it.
1209
+ */
1210
+ export function dmWorldStreamEndedNotice(reason, options) {
1211
+ const base = DM_WORLD_STREAM_END_DETAIL[reason];
1212
+ return {
1213
+ title: DM_WORLD_STREAM_ENDED_TITLE,
1214
+ detail: options.canReenter
1215
+ ? `${base} ${DM_WORLD_STREAM_END_PERMANENCE} ${DM_WORLD_REOPEN_NOTICE}`
1216
+ : base,
1217
+ action: options.canReenter ? DM_WORLD_REENTER_ACTION : null,
1218
+ };
1219
+ }
1220
+ /**
1221
+ * The plan a re-entry runs — ALWAYS a `'reopen'`, never a mint.
1222
+ *
1223
+ * ⛔ THE SPEND RAIL LIVES HERE, NOT IN THE SURFACE. The obvious re-entry is
1224
+ * "run the plan again", and on a `'create'` / `'confirm_required'` plan that
1225
+ * CREATES A SECOND PERMANENT BILLED WORLD every time the vendor stops the
1226
+ * stream — a charge for a fault the player did not cause. This builder is
1227
+ * structurally incapable of returning a minting action:
1228
+ * {@link dmWorldEntryWouldCreateWorld} is `false` for every plan it can return,
1229
+ * and it returns `null` (⇒ the surface offers only the exit) when no permanent
1230
+ * handle exists to reopen.
1231
+ *
1232
+ * `prompt` and `seedImageUrl` are cleared because a reopen sends neither, and
1233
+ * `autoStopAfterMs` is cleared because a re-entry is an explicit player action
1234
+ * — the auto-stop rail exists for worlds the player did not ask for.
1235
+ */
1236
+ export function dmWorldReentryPlan(plan, handle) {
1237
+ if (plan === null || handle === null)
1238
+ return null;
1239
+ return {
1240
+ ...plan,
1241
+ action: 'reopen',
1242
+ handle,
1243
+ prompt: '',
1244
+ seedImageUrl: null,
1245
+ autoStopAfterMs: null,
1246
+ };
1247
+ }
1248
+ /** Every status, for runtime validation by a probe or a coherence check. */
1249
+ export const DM_WORLD_BOARD_READ_STATUSES = [
1250
+ 'loading',
1251
+ 'retrying',
1252
+ 'loaded',
1253
+ 'absent',
1254
+ 'failed',
1255
+ ];
1256
+ /** `429 Too Many Requests` — the status this row was filed against. Named
1257
+ * because a bare `429` at a comparison site reads as a placeholder. */
1258
+ export const HTTP_STATUS_TOO_MANY_REQUESTS = 429;
1259
+ /** The floor of the 5xx range: everything at or above it is a server-side
1260
+ * fault, i.e. not something this client asked for wrongly. */
1261
+ export const HTTP_STATUS_SERVER_ERROR_FLOOR = 500;
1262
+ /**
1263
+ * How many times the board read may be attempted in total, including the first.
1264
+ *
1265
+ * Three, not more: the read sits on the episode's own mount, so every extra
1266
+ * attempt is latency a player waits through before the DM can ground anything —
1267
+ * and the burst that produced the 429 is itself the thing more attempts would
1268
+ * feed. Exhausting these leaves a RETRYABLE block, so the ceiling costs the
1269
+ * player a click rather than the answer.
1270
+ */
1271
+ export const DM_WORLD_BOARD_READ_MAX_ATTEMPTS = 3;
1272
+ /**
1273
+ * The wait before attempt N+1, in ms — one entry per retry, so its length is
1274
+ * {@link DM_WORLD_BOARD_READ_MAX_ATTEMPTS} minus the first attempt.
1275
+ *
1276
+ * Backed off rather than flat because the failure mode being retried is a rate
1277
+ * limit produced by a burst this read is part of; retrying immediately re-enters
1278
+ * the burst. Short in absolute terms because the whole schedule runs BEFORE the
1279
+ * player can be told anything true about the board.
1280
+ */
1281
+ export const DM_WORLD_BOARD_READ_RETRY_DELAYS_MS = [
1282
+ 600, 1_800,
1283
+ ];
1284
+ /**
1285
+ * Whether an HTTP status is worth another attempt.
1286
+ *
1287
+ * `null`/`undefined` — a transport failure with no response at all — IS
1288
+ * retryable: that is the offline blip and the aborted connection, neither of
1289
+ * which says anything about the board.
1290
+ *
1291
+ * A `404`/`403` is deliberately NOT retryable. Those are answers: retrying them
1292
+ * would spin a story that legitimately has no board (or that this viewer may not
1293
+ * read) through the full schedule before settling, which is latency bought for
1294
+ * nothing.
1295
+ */
1296
+ export function isRetryableBoardReadStatus(status) {
1297
+ if (status === null || status === undefined)
1298
+ return true;
1299
+ return (status === HTTP_STATUS_TOO_MANY_REQUESTS ||
1300
+ status >= HTTP_STATUS_SERVER_ERROR_FLOOR);
1301
+ }
1302
+ /**
1303
+ * {@link isRetryableBoardReadStatus} against a thrown error.
1304
+ *
1305
+ * `http.ts` enriches every thrown request error with `.status` (§Q `AA.5c`), so
1306
+ * this branches on the status rather than pattern-matching a message — an error
1307
+ * carrying no status at all is a transport failure and retryable.
1308
+ */
1309
+ export function dmWorldBoardReadIsRetryable(err) {
1310
+ if (typeof err !== 'object' || err === null)
1311
+ return true;
1312
+ const status = err.status;
1313
+ return isRetryableBoardReadStatus(typeof status === 'number' ? status : undefined);
1314
+ }
1315
+ /**
1316
+ * How long to wait before the attempt that follows `attemptsMade`, or `null`
1317
+ * when no attempt is left.
1318
+ *
1319
+ * Takes the number of attempts ALREADY made, so a caller counting from 1 asks
1320
+ * the same question the schedule answers and there is no off-by-one to get
1321
+ * wrong at the call site.
1322
+ */
1323
+ export function dmWorldBoardReadRetryDelayMs(attemptsMade) {
1324
+ if (attemptsMade < 1)
1325
+ return null;
1326
+ if (attemptsMade >= DM_WORLD_BOARD_READ_MAX_ATTEMPTS)
1327
+ return null;
1328
+ return (DM_WORLD_BOARD_READ_RETRY_DELAYS_MS[attemptsMade - 1] ??
1329
+ DM_WORLD_BOARD_READ_RETRY_DELAYS_MS[DM_WORLD_BOARD_READ_RETRY_DELAYS_MS.length - 1] ??
1330
+ null);
1331
+ }
1332
+ /** The message for a board read that has not settled yet. It states the state
1333
+ * and claims nothing about whether a board exists. */
1334
+ export const DM_WORLD_BOARD_READ_PENDING_MESSAGE = "The storyboard this world would be seeded from is still loading. Whether this story has a ratified board is not known yet — nothing has been decided against it.";
1335
+ /**
1336
+ * The message for a board read this session has stopped attempting — the
1337
+ * schedule was exhausted, or the failure was one retrying cannot resolve.
1338
+ *
1339
+ * It must say UNKNOWN, not absent: the whole row exists because a 429 was
1340
+ * rendered as *"this story has no ratified storyboard yet"* over a board that
1341
+ * was succeeded and 14/14. Deliberately claims no ATTEMPT COUNT — a
1342
+ * non-retryable failure settles here on the first one, and a message asserting
1343
+ * three would be its own small lie.
1344
+ */
1345
+ export const DM_WORLD_BOARD_READ_FAILED_MESSAGE = 'The storyboard could not be read, so it is unknown whether this story has one. This is a failed read, not a missing board — the story may well have a ratified storyboard that this session could not fetch.';
1346
+ /**
1347
+ * The host block for a board-read status, or `null` when the status carries no
1348
+ * block at all.
1349
+ *
1350
+ * `'loaded'` has a board, so the PLANNER decides and this must not speak over
1351
+ * it. `'absent'` is the one status that genuinely means no board — it keeps the
1352
+ * `reason: null` / {@link DM_WORLD_ENTRY_NO_BOARD_TITLE} rendering, which is now
1353
+ * true wherever it appears, because the two states that used to borrow it have
1354
+ * their own.
1355
+ */
1356
+ /**
1357
+ * Whether a block came from the BOARD READ rather than from the planner.
1358
+ *
1359
+ * A host holds a block in state, so a block minted while the read was in flight
1360
+ * outlives the read unless something re-decides it. This is the predicate that
1361
+ * says which blocks are worth re-deciding when the read's status moves: a
1362
+ * planner refusal is a decision about the beat and does not become stale when a
1363
+ * board arrives, but a board-read block is nothing BUT a statement about the
1364
+ * read.
1365
+ */
1366
+ export function dmWorldEntryBlockIsBoardRead(reason) {
1367
+ return reason === 'board_read_pending' || reason === 'board_read_failed';
1368
+ }
1369
+ /**
1370
+ * §Q `DM.76` — whether this block is still IN FLIGHT rather than settled.
1371
+ *
1372
+ * Every other block reason is an ANSWER: the planner refused, the read failed,
1373
+ * the story has no board. `board_read_pending` is the one that says only *"ask
1374
+ * again in a moment"* — the read has not decided anything yet and the surface is
1375
+ * already doing the one thing that resolves it.
1376
+ *
1377
+ * That difference has to be readable by a surface, because a surface that
1378
+ * renders pending under the same handle as the settled blocks teaches every
1379
+ * reader — human and probe — that the entry is over. `golden-path.mjs` races
1380
+ * three TERMINAL selectors after a world directive, `dm-world-blocked` among
1381
+ * them, so a directive landing mid-read resolved that race on a state that was
1382
+ * about to become a live world and recorded the attempt as blocked. The
1383
+ * predicate lives here, beside the reasons, so no surface re-derives "is this
1384
+ * one still in flight" from a string literal of its own.
1385
+ */
1386
+ export function dmWorldEntryBlockIsPending(reason) {
1387
+ return reason === 'board_read_pending';
1388
+ }
1389
+ export function dmWorldBoardBlock(status) {
1390
+ if (status === 'loaded' || status === 'absent')
1391
+ return null;
1392
+ return dmWorldEntryBlock(status === 'failed' ? 'board_read_failed' : 'board_read_pending', status === 'failed'
1393
+ ? DM_WORLD_BOARD_READ_FAILED_MESSAGE
1394
+ : DM_WORLD_BOARD_READ_PENDING_MESSAGE);
1395
+ }
1396
+ //# sourceMappingURL=dmWorldEntry.js.map