@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,1698 @@
1
+ /**
2
+ * Visual-storyboard domain module (§Q SB-U.1, spec slice S1 —
3
+ * `specs/2026-07-24-storyboard-generator.md` §4.1/§4.5).
4
+ *
5
+ * Wire-type MIRROR of `shared/storyboard_models.py` (frozen by §Q SB.1,
6
+ * PR #1464) plus the §4.5 request surface. The BACKEND module is the single
7
+ * source of truth for this vocabulary: every union here is mirrored, never
8
+ * re-derived, and no consumer hard-codes a raw status/mode string. Additive-
9
+ * only, framework-agnostic (no React/Vue imports) — the `quests.ts`/
10
+ * `artifacts.ts` posture.
11
+ *
12
+ * Three shape decisions SB.1 PINNED, honoured here rather than re-litigated:
13
+ *
14
+ * 1. **Ordering lives ONLY in {@link Storyboard.frameIds}.** There is no
15
+ * per-frame `order` field and this module does not add one — a reorder is
16
+ * the single idempotent list patch
17
+ * {@link StoryboardsApi.reorderStoryboardFrames}, and
18
+ * {@link orderStoryboardFrames} is the ONE resolver that turns the id list
19
+ * into a rendered sequence.
20
+ * 2. **Frame status is DERIVED, never stored.** The backend computes it
21
+ * (`StoryboardFrame.status`, a pydantic `computed_field`) so it DOES ride
22
+ * the wire read-only; {@link deriveFrameStatus} mirrors the same rule for
23
+ * optimistic UI. Nothing client-side ever SENDS a frame status.
24
+ * 3. **Master frame is `1664×936` at exactly `16:9`**
25
+ * ({@link STORYBOARD_MASTER_FRAME_WIDTH}/{@link STORYBOARD_MASTER_FRAME_HEIGHT}/
26
+ * {@link STORYBOARD_MASTER_ASPECT_RATIO}). The old contradictory 1664×960
27
+ * appears nowhere — `StyleProfile` is REJECTED server-side when the declared
28
+ * ratio and the declared pixels disagree.
29
+ *
30
+ * `txnVer` is the store-owned optimistic-lock value. Clients never mint it:
31
+ * they read it off a frame and echo it back on the version-guarded writes
32
+ * ({@link StoryboardsApi.patchStoryboardFrame} /
33
+ * {@link StoryboardsApi.selectStoryboardFrameVariant}). Omitting it makes those
34
+ * calls last-writer-wins.
35
+ *
36
+ * Land-dark: the whole backend surface 404s until `SEER_STORYBOARD_ENABLED` is
37
+ * set server-side (SB.4 ships the routes; SB.15 flips staging). As of this
38
+ * slice NO storyboard route exists yet — this module is the contract every
39
+ * SB-U row builds against.
40
+ */
41
+
42
+ import type { Transport } from '../transport';
43
+ import type { CameraPose } from '../storyboardMask';
44
+ import type { GateExpr } from './quests';
45
+ import type { HappyOysterMode } from '../reactor/happyOysterWorld';
46
+
47
+ // ------------------------------------------------------------------- enums
48
+
49
+ /** Board lifecycle (mirrors backend `StoryboardStatus`). */
50
+ export type StoryboardStatus = 'queued' | 'running' | 'succeeded' | 'failed' | 'cancelled';
51
+
52
+ /** Statuses no transition may leave (mirrors `STORYBOARD_TERMINAL_STATUSES`). */
53
+ export const STORYBOARD_TERMINAL_STATUSES: readonly StoryboardStatus[] = [
54
+ 'succeeded',
55
+ 'failed',
56
+ 'cancelled',
57
+ ];
58
+
59
+ /** Poll predicate for the 202-create flow — prefer this over raw comparisons. */
60
+ export function isStoryboardTerminal(status: StoryboardStatus): boolean {
61
+ return STORYBOARD_TERMINAL_STATUSES.includes(status);
62
+ }
63
+
64
+ /** Whether the board matches the source film or restyles it (`StyleMode`). */
65
+ export type StoryboardStyleMode = 'original_similar' | 'restyled';
66
+
67
+ /** How a frame enters — compiles to LongLive `set_shot` vs `scene_cut`. */
68
+ export type ShotTransition = 'soft_shot' | 'hard_cut';
69
+
70
+ /** One generation attempt's outcome (`VariantStatus`). */
71
+ export type FrameVariantStatus = 'pending' | 'succeeded' | 'failed';
72
+
73
+ /** Which surface produced a variant (`VariantOrigin`). */
74
+ export type FrameVariantOrigin = 'generate' | 'regenerate' | 'region_edit';
75
+
76
+ /**
77
+ * DERIVED frame state (`FrameStatus`) — computed from the variant list by
78
+ * {@link deriveFrameStatus}, never authored by a client.
79
+ */
80
+ export type StoryboardFrameStatus = 'pending' | 'running' | 'succeeded' | 'failed';
81
+
82
+ // --------------------------------------------------------------- constants
83
+
84
+ /** Canonical master-frame width in pixels (`MASTER_FRAME_WIDTH`). */
85
+ export const STORYBOARD_MASTER_FRAME_WIDTH = 1664;
86
+ /** Canonical master-frame height — 1664 × 9/16, exactly 16:9 (`MASTER_FRAME_HEIGHT`). */
87
+ export const STORYBOARD_MASTER_FRAME_HEIGHT = 936;
88
+ /** The ONE aspect ratio v1 boards render at, `"W:H"` (`MASTER_ASPECT_RATIO`). */
89
+ export const STORYBOARD_MASTER_ASPECT_RATIO = '16:9';
90
+
91
+ /** Max frames one board may hold (`MAX_FRAMES_PER_BOARD`). */
92
+ export const MAX_FRAMES_PER_BOARD = 24;
93
+ /** Variant history kept per frame (`VARIANT_HISTORY_CAP`); overflow evicts the
94
+ * oldest NON-SELECTED variant server-side. */
95
+ export const FRAME_VARIANT_HISTORY_CAP = 8;
96
+ /** Marble multi-view degrees cap — ≤8 in reconstruction mode
97
+ * (`MULTI_VIEW_AZIMUTH_CAP`). */
98
+ export const MULTI_VIEW_AZIMUTH_CAP = 8;
99
+
100
+ /** Per-frame clip length; Veo 3.1's documented set is the binding constraint. */
101
+ export type FrameDurationSeconds = 4 | 6 | 8;
102
+ /** The same set as data, for pickers and validation messages
103
+ * (`FRAME_DURATION_CHOICES`). */
104
+ export const FRAME_DURATION_CHOICES: readonly FrameDurationSeconds[] = [4, 6, 8];
105
+ /** Our default when the composer does not choose (`DEFAULT_FRAME_DURATION_SECONDS`). */
106
+ export const DEFAULT_FRAME_DURATION_SECONDS: FrameDurationSeconds = 6;
107
+
108
+ /** Per-tag length cap (`STYLE_TAG_MAX_LEN`) — the editor's own bound. */
109
+ export const STORYBOARD_STYLE_TAG_MAX_LEN = 64;
110
+ /** Style-tag count cap (`STYLE_TAGS_MAX`). */
111
+ export const STORYBOARD_STYLE_TAGS_MAX = 12;
112
+ /** Free-text prompt-field cap (`PROMPT_TEXT_MAX_LEN`). */
113
+ export const STORYBOARD_PROMPT_TEXT_MAX_LEN = 2000;
114
+ /** Dialogue-line count cap (`DIALOG_LINES_MAX`). */
115
+ export const STORYBOARD_DIALOG_LINES_MAX = 12;
116
+ /** Per-list reference cap for `characterRefs`/`settingRefs` (`FRAME_REFS_MAX`). */
117
+ export const STORYBOARD_FRAME_REFS_MAX = 12;
118
+
119
+ // ------------------------------------------------------------- spend preview
120
+
121
+ /**
122
+ * What generating a board from one arc variant will actually SPEND, in the only
123
+ * unit this product can state honestly: images.
124
+ *
125
+ * §Q `SB.22` — generation is PAID and irreversible, so no surface may fire it
126
+ * without first telling the creator how much work it commits. There is no
127
+ * per-image price anywhere in the catalogue (`shared/image_model_registry.py`
128
+ * carries capabilities, not dollars) and `Storyboard.costUsd` is written by the
129
+ * worker AFTER the fact, so a dollar figure here would be invented. The FRAME
130
+ * COUNT is not invented: it is exactly what the planner will draw.
131
+ */
132
+ export interface StoryboardFrameBudget {
133
+ /** Beats + endings the plan will walk — one candidate frame each. */
134
+ nodeCount: number;
135
+ /** Images that will actually be generated (`nodeCount` under the cap). */
136
+ frameCount: number;
137
+ /** True when {@link MAX_FRAMES_PER_BOARD} truncated the plan. */
138
+ capped: boolean;
139
+ }
140
+
141
+ /**
142
+ * The frame budget an arc variant would generate — mirror of the backend's
143
+ * frame planner (`services/storyboard/worker.py` `_plan_frames`), which walks
144
+ * `topological_node_order(variant)` (beats then endings — EVERY beat and EVERY
145
+ * ending, in a stable order) and stops at {@link MAX_FRAMES_PER_BOARD}.
146
+ *
147
+ * Only the COUNT is mirrored, never the ordering: the count is order-invariant,
148
+ * so this cannot drift from the planner the way a re-implemented topological
149
+ * sort would. Structurally typed rather than taking `ArcVariant` so the
150
+ * storyboard module keeps its one-way dependency (arcs types live in `api.ts`,
151
+ * which imports this module).
152
+ */
153
+ export function storyboardFrameBudget(variant: {
154
+ beats: readonly unknown[];
155
+ endings: readonly unknown[];
156
+ }): StoryboardFrameBudget {
157
+ const nodeCount = variant.beats.length + variant.endings.length;
158
+ return {
159
+ nodeCount,
160
+ frameCount: Math.min(nodeCount, MAX_FRAMES_PER_BOARD),
161
+ capped: nodeCount > MAX_FRAMES_PER_BOARD,
162
+ };
163
+ }
164
+
165
+ // ------------------------------------------------------------------ shapes
166
+
167
+ /**
168
+ * Board-wide look + the master geometry every frame is generated at (mirrors
169
+ * backend `StyleProfile`). The backend REJECTS a profile whose
170
+ * {@link StyleProfile.aspectRatio} disagrees with the master pixels, so a UI
171
+ * that offers a custom master must keep the two in step.
172
+ */
173
+ export interface StyleProfile {
174
+ mode: StoryboardStyleMode;
175
+ /** Short look descriptors folded into every frame prompt. */
176
+ styleTags: string[];
177
+ /** Free-text art direction applied board-wide. */
178
+ styleDirection?: string | null;
179
+ /** Frame aspect as `"W:H"` — must agree with the master pixels. */
180
+ aspectRatio: string;
181
+ masterWidth: number;
182
+ masterHeight: number;
183
+ /** Board-wide generation seed — the consistency-v1 anchor. */
184
+ boardSeed?: number | null;
185
+ }
186
+
187
+ // --------------------------------------------------------- board-style pick
188
+
189
+ /**
190
+ * What a creator picked on an arc-generate surface (§Q `BOARD.5`).
191
+ *
192
+ * The UI holds tags and direction across a mode flip so a mis-click does not
193
+ * erase typing; {@link buildArcStyleProfile} is what decides they are only
194
+ * SENT on the restyled arm.
195
+ */
196
+ export interface ArcStyleSelection {
197
+ mode: StoryboardStyleMode;
198
+ /** Look descriptors, as typed — unnormalized. */
199
+ styleTags?: readonly string[];
200
+ /** Free-text art direction, as typed. */
201
+ styleDirection?: string | null;
202
+ }
203
+
204
+ /** The default a surface starts on — identical to what the backend assumes. */
205
+ export const DEFAULT_ARC_STYLE_SELECTION: ArcStyleSelection = {
206
+ mode: 'original_similar',
207
+ styleTags: [],
208
+ styleDirection: '',
209
+ };
210
+
211
+ /**
212
+ * Trim, drop blanks, and de-duplicate style tags, preserving typed order.
213
+ *
214
+ * De-duplication is case-SENSITIVE on purpose: the backend folds tags into
215
+ * frame prompts verbatim, so `"Noir"` and `"noir"` are two different words to
216
+ * the image model and collapsing them would silently edit the creator's look.
217
+ * It only removes an exact repeat, which is always a typo.
218
+ */
219
+ export function normalizeArcStyleTags(tags: readonly string[] | undefined): string[] {
220
+ const seen = new Set<string>();
221
+ const out: string[] = [];
222
+ for (const raw of tags ?? []) {
223
+ const tag = String(raw ?? '').trim();
224
+ if (tag === '' || seen.has(tag)) continue;
225
+ seen.add(tag);
226
+ out.push(tag);
227
+ }
228
+ return out;
229
+ }
230
+
231
+ /**
232
+ * Length in CODE POINTS, which is what the backend counts.
233
+ *
234
+ * `String.length` counts UTF-16 code units, so a 64-emoji tag measures 128 here
235
+ * and 64 in pydantic — the client would reject a value the server accepts. The
236
+ * error direction is safe (a false block, not a false send) and it is still a
237
+ * false gate on a creator's own text (codex, this PR).
238
+ */
239
+ function codePointLength(text: string): number {
240
+ return [...text].length;
241
+ }
242
+
243
+ /**
244
+ * Why this selection would 422, or `null` when it is sendable.
245
+ *
246
+ * The caps are the backend's (`STYLE_TAGS_MAX`, `STYLE_TAG_MAX_LEN`,
247
+ * `PROMPT_TEXT_MAX_LEN`) and they are checked HERE rather than left to the
248
+ * server because `StyleProfile` validation happens at ARC GENERATION — a 422
249
+ * there loses the whole request, not just the style.
250
+ *
251
+ * The `original_similar` arm never fails: {@link buildArcStyleProfile} sends
252
+ * nothing on it, so an over-cap tag the creator typed and then abandoned
253
+ * cannot block a generate.
254
+ */
255
+ export function arcStyleSelectionError(selection: ArcStyleSelection): string | null {
256
+ if (selection.mode === 'original_similar') return null;
257
+ const tags = normalizeArcStyleTags(selection.styleTags);
258
+ if (tags.length > STORYBOARD_STYLE_TAGS_MAX) {
259
+ return `Use at most ${STORYBOARD_STYLE_TAGS_MAX} style tags (you have ${tags.length}).`;
260
+ }
261
+ const tooLong = tags.find((tag) => codePointLength(tag) > STORYBOARD_STYLE_TAG_MAX_LEN);
262
+ if (tooLong !== undefined) {
263
+ return `Each style tag must be ${STORYBOARD_STYLE_TAG_MAX_LEN} characters or fewer — "${tooLong.slice(0, 24)}…" is ${codePointLength(tooLong)}.`;
264
+ }
265
+ const direction = (selection.styleDirection ?? '').trim();
266
+ if (codePointLength(direction) > STORYBOARD_PROMPT_TEXT_MAX_LEN) {
267
+ return `Art direction must be ${STORYBOARD_PROMPT_TEXT_MAX_LEN} characters or fewer (you have ${codePointLength(direction)}).`;
268
+ }
269
+ return null;
270
+ }
271
+
272
+ /**
273
+ * The `styleProfile` partial to put on a `GenerateArcRequest`, or `undefined`
274
+ * to OMIT the key entirely (§Q `BOARD.5`).
275
+ *
276
+ * ⛔ **THE DEFAULT ARM RETURNS `undefined`, NOT A NEUTRAL PROFILE.** Every
277
+ * arc-generate surface omitted the key before this row, and the backend's
278
+ * `StyleProfile()` defaults ARE `original_similar` with no tags — so omitting
279
+ * keeps an unstyled generate byte-identical to what shipped, which is the
280
+ * only way to be sure this row changed nothing for a creator who ignores it.
281
+ * ⚠ The reason is NOT that a sent key would 422: `styleProfile` is a declared
282
+ * optional field and `{}` validates straight through to those same defaults
283
+ * (codex corrected an earlier claim here that blamed `extra="forbid"`; that
284
+ * setting rejects UNDECLARED keys, which this is not). The reason is that a
285
+ * proposal recording an explicit profile and one recording "the creator did
286
+ * not choose" are different facts, and only the second is true here.
287
+ *
288
+ * ⛔ **THE `original_similar` ARM DROPS TAGS AND DIRECTION.** The backend's
289
+ * `sheet_style_recipe` treats a profile as STYLIZED when it carries tags or
290
+ * direction *regardless of mode*, so forwarding text a creator typed and then
291
+ * switched away from would quietly buy a stylized board they de-selected.
292
+ *
293
+ * ⛔ **GEOMETRY IS NEVER SENT.** `aspectRatio`/`masterWidth`/`masterHeight`
294
+ * must agree with each other or the backend 422s the ARC REQUEST (not the
295
+ * board), and this surface offers no master control — so the server's own
296
+ * defaults are the only correct source. `boardSeed` is likewise not a
297
+ * creator-facing choice here.
298
+ *
299
+ * A restyled pick with neither tags nor direction still sends `{mode}`: mode
300
+ * alone is meaningful to `sheet_style_recipe`, not a no-op.
301
+ */
302
+ export function buildArcStyleProfile(
303
+ selection: ArcStyleSelection,
304
+ ): Partial<StyleProfile> | undefined {
305
+ if (selection.mode !== 'restyled') return undefined;
306
+ const styleTags = normalizeArcStyleTags(selection.styleTags);
307
+ const styleDirection = (selection.styleDirection ?? '').trim();
308
+ return {
309
+ mode: 'restyled',
310
+ ...(styleTags.length > 0 ? { styleTags } : {}),
311
+ ...(styleDirection !== '' ? { styleDirection } : {}),
312
+ };
313
+ }
314
+
315
+ /**
316
+ * The `styleProfile` key spread straight into a `GenerateArcRequest` literal —
317
+ * `{}` on the default arm, so the request object is byte-identical to the
318
+ * pre-`BOARD.5` payload. One helper so no surface re-derives the omit rule.
319
+ */
320
+ export function arcStyleProfileField(
321
+ selection: ArcStyleSelection,
322
+ ): { styleProfile?: Partial<StyleProfile> } {
323
+ const profile = buildArcStyleProfile(selection);
324
+ return profile === undefined ? {} : { styleProfile: profile };
325
+ }
326
+
327
+ /**
328
+ * The structured prompt (mirrors backend `FramePrompt`) — self-sufficient
329
+ * because LongLive takes TEXT ONLY. The flattener `compiled_text()` stays
330
+ * SERVER-SIDE by design (it is the single source of the string every adapter
331
+ * and export target sends); the compiled result reaches the client as
332
+ * {@link StoryboardFrameVariant.promptText} provenance.
333
+ */
334
+ export interface FramePrompt {
335
+ sceneDescription: string;
336
+ /** Cast described IN WORDS (identity survives text-only targets). */
337
+ charactersInWords: string[];
338
+ action: string;
339
+ /** The camera leg every live target actually reads (SB-U.2's prose). */
340
+ cameraProse: string;
341
+ styleTags: string[];
342
+ dialogLines: string[];
343
+ negative?: string | null;
344
+ }
345
+
346
+ /** One reference image fed to a multi-reference adapter (`FrameRef`). */
347
+ export interface StoryboardFrameRef {
348
+ /** Cast member or setting name. */
349
+ entity: string;
350
+ imageId: string;
351
+ /** Stylized companion — Seedance rejects photoreal-face references. */
352
+ stylizedImageId?: string | null;
353
+ /** 1-based `@ImageN` address; null ⇒ the ref is unaddressed. */
354
+ imageSlot?: number | null;
355
+ }
356
+
357
+ /** One generation ATTEMPT and its provenance (`FrameVariant`, history cap 8). */
358
+ export interface StoryboardFrameVariant {
359
+ variantId: string;
360
+ status: FrameVariantStatus;
361
+ origin: FrameVariantOrigin;
362
+ /** S3 key (`shared.s3_keys.storyboard_frame_key`) — not directly fetchable. */
363
+ imageKey?: string | null;
364
+ /** S3 key of the region-edit mask, when `origin` is `region_edit`. */
365
+ maskKey?: string | null;
366
+ modelId?: string | null;
367
+ seed?: number | null;
368
+ /** The compiled prompt actually sent — regeneration provenance. */
369
+ promptText?: string | null;
370
+ error?: string | null;
371
+ /** ISO-8601. */
372
+ createdAt: string;
373
+ completedAt?: string | null;
374
+ /**
375
+ * Presigned URL for {@link StoryboardFrameVariant.imageKey}, attached by the
376
+ * DETAIL read only (spec §4.5 "detail + presigned frame URLs"); it is not a
377
+ * stored field and never rides a write. Absent until SB.4 ships the route.
378
+ */
379
+ imageUrl?: string | null;
380
+ }
381
+
382
+ /** Per-target extras the lowest-common-denominator frame cannot carry (§5). */
383
+ export interface FrameExtensions {
384
+ lastFrameImageKey?: string | null;
385
+ /** Helios seed adherence, `[0, 1]`. */
386
+ imageStrength?: number | null;
387
+ /** Marble multi-view degrees (≤{@link MULTI_VIEW_AZIMUTH_CAP}). */
388
+ multiViewAzimuths: number[];
389
+ /** SAM-3D per-object lift requested. Wire key is `lift3D` (backend
390
+ * `lift_3d` through pydantic `to_camel`) — note the capital D. */
391
+ lift3D: boolean;
392
+ }
393
+
394
+ /**
395
+ * One board frame (mirrors backend `StoryboardFrame`). Carries NO `videoId`/
396
+ * `historyScopeId` — those live on the board. There is deliberately **no
397
+ * `order` field**: position is this frame's index in
398
+ * {@link Storyboard.frameIds} (use {@link orderStoryboardFrames}).
399
+ */
400
+ export interface StoryboardFrame {
401
+ storyboardId: string;
402
+ frameId: string;
403
+ /**
404
+ * Join key → the PlotBeat node id, which is also the quests'
405
+ * `sourceBeatId` — this is what makes the quest view a JOIN rather than a
406
+ * second projection (spec §4.5).
407
+ */
408
+ beatId?: string | null;
409
+ /**
410
+ * The `PlotBeat` id this frame's beat carries IN THE GRAPH (§Q SB.92 /
411
+ * DM.105) — the id a cutscene for this frame posts as `beatId`, with the
412
+ * detail read's {@link StoryboardDetailResponse.graphStoryId} as `storyId`.
413
+ *
414
+ * ⛔ NOT {@link StoryboardFrame.beatId}: that id is hashed in the BOARD's
415
+ * scope (the video), which on a fork-approved arc is not where the arc's
416
+ * nodes live — every cutscene posted with it 404'd "PlotBeat not found"
417
+ * (measured 2026-10-19, 0 of 42 frames on three stories). Served only by a
418
+ * detail read whose {@link StoryboardDetailResponse.graphResolution} is
419
+ * `resolved`; `null`/absent otherwise.
420
+ */
421
+ graphBeatId?: string | null;
422
+ anchorSceneId?: string | null;
423
+ /** Scene grouping — a change implies a cut. */
424
+ sequenceId?: string | null;
425
+ shotTransition: ShotTransition;
426
+ durationSeconds: FrameDurationSeconds;
427
+ prompt: FramePrompt;
428
+ /**
429
+ * The parametric camera leg — the SAME shape as client-core's
430
+ * {@link CameraPose} (`storyboardMask.ts`), reused rather than redefined.
431
+ * Authoring intent only: no live target consumes a 6-DoF pose today, it
432
+ * compiles to {@link FramePrompt.cameraProse}.
433
+ */
434
+ cameraPose?: CameraPose | null;
435
+ characterRefs: StoryboardFrameRef[];
436
+ settingRefs: StoryboardFrameRef[];
437
+ /**
438
+ * The cast names this frame ASKED for, in roster order (§Q SB.41).
439
+ *
440
+ * With {@link StoryboardFrame.characterRefs} and
441
+ * {@link StoryboardFrame.unresolvedCast} it makes cast coverage answerable —
442
+ * "3 of 4 cast resolved, and here is the one that is missing".
443
+ */
444
+ requestedCast?: string[];
445
+ /**
446
+ * Requested cast members that resolved to NO reference image (§Q SB.41).
447
+ *
448
+ * A missing FIRST-BILLED character used to be invisible: on the `star-wars`
449
+ * board every beat named "Jedi Orin", every frame shipped without him, and
450
+ * the board reported success. Surface this — a frame that silently omits the
451
+ * character its beat is about is the defect, not the reporting.
452
+ *
453
+ * Absent on frames written before SB.41; treat that as UNKNOWN coverage
454
+ * rather than "nothing was missing".
455
+ */
456
+ unresolvedCast?: string[];
457
+ variants: StoryboardFrameVariant[];
458
+ selectedVariantId?: string | null;
459
+ extensions: FrameExtensions;
460
+ seed?: number | null;
461
+ audioEnabled: boolean;
462
+ /** Persisted HappyOyster `encrypted_world_id` once a world exists (SB-W.*). */
463
+ worldId?: string | null;
464
+ /**
465
+ * The mode-fixed HappyOyster model that OWNS {@link StoryboardFrame.worldId}
466
+ * (§Q DM.30). Required to reopen the world — `attachWorld` rejects the other
467
+ * mode's worlds with `MODE_MISMATCH`, so a bare id is not a usable handle.
468
+ *
469
+ * `null`/absent on frames bound before DM.30, and a reader must treat that as
470
+ * UNKNOWN rather than assume its own mode: assuming is exactly how the
471
+ * pre-flight in `launchHappyOysterWorld` was made unreachable.
472
+ */
473
+ worldMode?: HappyOysterMode | null;
474
+ /**
475
+ * §Q MOMENT.8 — permanent worlds this frame USED to open into, oldest first.
476
+ *
477
+ * A HappyOyster world cannot be reseeded and cannot be deleted, so
478
+ * "regenerate this world" means REPLACEMENT: the new id becomes
479
+ * {@link StoryboardFrame.worldId} and the old one moves here. Every id in the
480
+ * list is still billed and still reachable via `attachWorld` — the ledger is
481
+ * what keeps it so, which is why nothing drops one.
482
+ *
483
+ * Absent on frames written before MOMENT.8; treat that as "never superseded".
484
+ */
485
+ supersededWorldIds?: string[];
486
+ createdAt: string;
487
+ updatedAt?: string | null;
488
+ editedAt?: string | null;
489
+ editedBy?: string | null;
490
+ /**
491
+ * SERVER-DERIVED from {@link StoryboardFrame.variants} — never stored and
492
+ * never sent by a client. {@link deriveFrameStatus} is the same rule for
493
+ * optimistic rendering between a write and its refetch.
494
+ */
495
+ readonly status: StoryboardFrameStatus;
496
+ /**
497
+ * Store-owned optimistic-lock value. Echo it back on
498
+ * {@link StoryboardsApi.patchStoryboardFrame} /
499
+ * {@link StoryboardsApi.selectStoryboardFrameVariant}; never mint it.
500
+ */
501
+ txnVer?: number | null;
502
+ }
503
+
504
+ /**
505
+ * One board — the `META` item (mirrors backend `Storyboard`). List reads
506
+ * return exactly this (no frames); {@link Storyboard.frameIds} is the ordering
507
+ * source of truth AND the frame count.
508
+ */
509
+ export interface Storyboard {
510
+ storyboardId: string;
511
+ /** Owning story — `storyId` IS `videoId`. */
512
+ videoId: string;
513
+ /** Source arc proposal. */
514
+ proposalId?: string | null;
515
+ /** Source arc variant. */
516
+ variantId?: string | null;
517
+ status: StoryboardStatus;
518
+ styleProfile: StyleProfile;
519
+ /** ORDERING SOURCE OF TRUTH — a reorder is a list patch here (≤24). */
520
+ frameIds: string[];
521
+ modelId?: string | null;
522
+ /**
523
+ * EVERY composition model the board generates against, in the order the
524
+ * creator asked for (§Q SB.54). `modelId` is the PRIMARY — `modelIds[0]`.
525
+ *
526
+ * Absent or empty on every board created before SB.54, which is exactly the
527
+ * single-model case: read it as `modelIds?.length ? modelIds : [modelId]`.
528
+ */
529
+ modelIds?: string[] | null;
530
+ fallbackModelId?: string | null;
531
+ costUsd: number;
532
+ error?: string | null;
533
+ createdAt: string;
534
+ updatedAt?: string | null;
535
+ completedAt?: string | null;
536
+ createdBy?: string | null;
537
+ tenantId?: string | null;
538
+ historyScopeId?: string | null;
539
+ /** Store-owned optimistic-lock value. */
540
+ txnVer?: number | null;
541
+ }
542
+
543
+ // -------------------------------------------------------------- projections
544
+
545
+ /**
546
+ * The ONE place the ordering SSOT is applied: resolve
547
+ * {@link Storyboard.frameIds} against a detail read's frames, in board order.
548
+ *
549
+ * Ids with no loaded frame are skipped, and frames the board no longer lists
550
+ * are dropped — so a mid-reorder read renders a coherent (possibly short)
551
+ * board instead of a duplicated or mis-ordered one. Every SB-U board surface
552
+ * calls this rather than sorting frames itself.
553
+ */
554
+ export function orderStoryboardFrames(
555
+ frameIds: readonly string[],
556
+ frames: readonly StoryboardFrame[],
557
+ ): StoryboardFrame[] {
558
+ const byId = new Map(frames.map(frame => [frame.frameId, frame]));
559
+ const ordered: StoryboardFrame[] = [];
560
+ for (const frameId of frameIds) {
561
+ const frame = byId.get(frameId);
562
+ if (frame) ordered.push(frame);
563
+ }
564
+ return ordered;
565
+ }
566
+
567
+ /**
568
+ * Mirror of the backend's derived `StoryboardFrame.status` — in-flight wins
569
+ * (a regenerate on a succeeded frame reads `running`, so the board shows work
570
+ * happening), then any success, then all-failed, then empty ⇒ `pending`.
571
+ *
572
+ * The server value on {@link StoryboardFrame.status} is authoritative; this is
573
+ * for the optimistic window between appending a pending variant locally and
574
+ * the next poll.
575
+ */
576
+ export function deriveFrameStatus(
577
+ variants: readonly StoryboardFrameVariant[],
578
+ ): StoryboardFrameStatus {
579
+ if (variants.some(variant => variant.status === 'pending')) return 'running';
580
+ if (variants.some(variant => variant.status === 'succeeded')) return 'succeeded';
581
+ if (variants.length > 0) return 'failed';
582
+ return 'pending';
583
+ }
584
+
585
+ /**
586
+ * The variant {@link StoryboardFrame.selectedVariantId} names, if it is still
587
+ * held in the capped history (mirrors the backend's `selected_variant()`).
588
+ */
589
+ export function selectedFrameVariant(
590
+ frame: StoryboardFrame,
591
+ ): StoryboardFrameVariant | undefined {
592
+ if (!frame.selectedVariantId) return undefined;
593
+ return frame.variants.find(variant => variant.variantId === frame.selectedVariantId);
594
+ }
595
+
596
+ /**
597
+ * Does this variant actually carry IMAGE BYTES a surface could render?
598
+ *
599
+ * ⛔ **"Has bytes" is `imageKey` OR `imageUrl`, and the `imageKey` half is the
600
+ * load-bearing one** — that is the durable field, and the one the
601
+ * select-variant route tests. `imageUrl` is only the detail read's presigned
602
+ * VIEW of it, so keying on the URL alone would call a genuinely rendered
603
+ * variant empty the moment presigning fails or the frame arrives from a read
604
+ * that does not presign.
605
+ *
606
+ * THE single definition, because two rules in this file disagreed about it and
607
+ * the disagreement was the §Q SB.71 defect (see {@link displayFrameVariant}).
608
+ */
609
+ export function variantHasBytes(variant: StoryboardFrameVariant): boolean {
610
+ return (variant.imageKey ?? '') !== '' || (variant.imageUrl ?? '') !== '';
611
+ }
612
+
613
+ /**
614
+ * The variant a surface should SHOW for a frame (§Q SB-U.4): the explicitly
615
+ * selected one when it is present, succeeded AND carries bytes, otherwise the
616
+ * newest such variant, otherwise nothing.
617
+ *
618
+ * Distinct from {@link selectedFrameVariant}, which answers only "what does
619
+ * `selectedVariantId` point at" and is deliberately undefined before a
620
+ * selection exists. A freshly generated frame has no `selectedVariantId` yet,
621
+ * so a board keyed on that alone would render a rendered frame as blank; and a
622
+ * selection pointing at a `pending`/`failed` variant must not blank out the
623
+ * image the creator can already see. Variants are appended in generation
624
+ * order, so "newest succeeded" is the last succeeded entry.
625
+ *
626
+ * **§Q SB.71 — the bytes clause is new, and its absence BLANKED THE BOARD.**
627
+ * The rule was succeeded-only, so a variant marked `succeeded` while carrying
628
+ * no `imageKey` was honoured as the display variant: {@link frameImageUrl} then
629
+ * returned `null` and every surface rendered NOTHING while the frame claimed an
630
+ * image. Silent by construction — the frame looks healthy, and the older
631
+ * variant that DOES have bytes is sitting right there in the same history,
632
+ * never reached because the walk stopped at the keyless one.
633
+ *
634
+ * Two things make this the right shape rather than a patch. The server mirror
635
+ * (`shared/storyboard_store._display_variant`) has ALWAYS required an
636
+ * `image_key` and says so; the client was the half that drifted, on a docstring
637
+ * claiming the client "needs no such clause" because it reads `imageUrl`. And
638
+ * {@link buildFrameVariantStrip} in this same file already refused to promote a
639
+ * keyless variant (`no-image`) — so one file held both rules and they
640
+ * contradicted each other. They now share {@link variantHasBytes}.
641
+ */
642
+ export function displayFrameVariant(
643
+ frame: StoryboardFrame,
644
+ ): StoryboardFrameVariant | undefined {
645
+ const renderable = (variant: StoryboardFrameVariant | undefined): boolean =>
646
+ variant?.status === 'succeeded' && variantHasBytes(variant);
647
+ const selected = selectedFrameVariant(frame);
648
+ if (renderable(selected)) return selected;
649
+ for (let i = frame.variants.length - 1; i >= 0; i -= 1) {
650
+ if (renderable(frame.variants[i])) return frame.variants[i];
651
+ }
652
+ return undefined;
653
+ }
654
+
655
+ /**
656
+ * The presigned image URL a surface should render for a frame, or `null`.
657
+ *
658
+ * One line over {@link displayFrameVariant}, but kept here so every surface that
659
+ * only wants the URL (the timeline clip, the large preview, a future thumbnail)
660
+ * reads it from one place rather than repeating the `?.imageUrl ?? null` tail.
661
+ * `imageUrl` rides the DETAIL read only, so a list-shaped frame yields `null`.
662
+ */
663
+ export function frameImageUrl(frame: StoryboardFrame): string | null {
664
+ return displayFrameVariant(frame)?.imageUrl ?? null;
665
+ }
666
+
667
+ /**
668
+ * §Q `SB.34` — the variant a surface should read a frame's PROMPT from, which is
669
+ * deliberately NOT {@link displayFrameVariant}.
670
+ *
671
+ * `displayFrameVariant` is succeeded-only and must stay that way: it answers
672
+ * "which IMAGE do I show", and its rule defends a real invariant — a selection
673
+ * pointing at a `pending`/`failed` variant must not blank out the image the
674
+ * creator can already see. Reading the prompt through it, though, made a FAILED
675
+ * frame indistinguishable from a frame that does not exist: the DM world-entry
676
+ * path got `undefined` and reported "no world for this beat" on a beat that was
677
+ * fully storyboarded and merely refused by the image model.
678
+ *
679
+ * The prompt is a different kind of fact from the image. It is COMPOSED BEFORE
680
+ * the image call and is not itself what failed, and §Q `SB.38` (#1575) made the
681
+ * backend persist it on all four failure arms — so a failed variant carries the
682
+ * text of the beat it meant to draw. This accessor is what lets that text be
683
+ * read without touching the image rule.
684
+ *
685
+ * Order: the displayed (succeeded) variant when it carries prompt text — a
686
+ * rendered frame's own provenance always wins — then the newest variant of ANY
687
+ * status that carries some. Variants are appended in generation order, so
688
+ * "newest" is the last entry. `undefined` when no variant carries prompt text at
689
+ * all (including boards generated before `SB.38`, whose failed variants were
690
+ * written with an empty string).
691
+ */
692
+ export function promptFrameVariant(
693
+ frame: StoryboardFrame,
694
+ ): StoryboardFrameVariant | undefined {
695
+ const displayed = displayFrameVariant(frame);
696
+ if (hasPromptText(displayed)) return displayed;
697
+ for (let i = frame.variants.length - 1; i >= 0; i -= 1) {
698
+ if (hasPromptText(frame.variants[i])) return frame.variants[i];
699
+ }
700
+ return undefined;
701
+ }
702
+
703
+ function hasPromptText(variant: StoryboardFrameVariant | undefined): boolean {
704
+ return (variant?.promptText?.trim() ?? '') !== '';
705
+ }
706
+
707
+ /**
708
+ * §Q `SB.34` — why a frame's render FAILED, or `null` when it did not fail.
709
+ *
710
+ * A frame with no image can be in two completely different situations: still
711
+ * generating, or refused/errored and never coming back on its own. Both used to
712
+ * read as "not rendered yet", which told the owner to wait for something that
713
+ * was never going to happen. This is the ONE place that tells them apart, so no
714
+ * surface re-derives the distinction from raw variant statuses.
715
+ *
716
+ * Derived from the variants via {@link deriveFrameStatus} rather than the
717
+ * server's {@link StoryboardFrame.status} so it stays correct in the optimistic
718
+ * window between a regenerate and its refetch — the same reason
719
+ * `deriveFrameStatus` exists.
720
+ *
721
+ * Returns the newest failed variant's `error` — for a content-policy refusal
722
+ * that is `SB.36`'s classified message, which is the actionable half. Falls back
723
+ * to `null` text only if the backend recorded none; callers pair this with their
724
+ * own copy, so an empty reason still reads as "failed", never as "pending".
725
+ */
726
+ export function frameRenderFailure(frame: StoryboardFrame): string | null {
727
+ if (deriveFrameStatus(frame.variants) !== 'failed') return null;
728
+ for (let i = frame.variants.length - 1; i >= 0; i -= 1) {
729
+ const variant = frame.variants[i];
730
+ if (variant.status !== 'failed') continue;
731
+ const error = variant.error?.trim() ?? '';
732
+ if (error !== '') return error;
733
+ }
734
+ return null;
735
+ }
736
+
737
+ /**
738
+ * Whether a frame's render failed at all — {@link frameRenderFailure} answers
739
+ * "why", this answers "did it", and a failure the backend recorded no message
740
+ * for is still a failure. Kept beside it so the two can never disagree.
741
+ */
742
+ export function frameRenderFailed(frame: StoryboardFrame): boolean {
743
+ return deriveFrameStatus(frame.variants) === 'failed';
744
+ }
745
+
746
+ /** Why a variant cannot be promoted to be the frame's image ({@link FrameVariantChip}). */
747
+ export type VariantPromoteBlock = 'pending' | 'failed' | 'no-image' | 'already-current';
748
+
749
+ /**
750
+ * One attempt as the compare strip renders it (§Q SB-U.6) — every fact the chip
751
+ * shows and every decision the chip makes, decided HERE so `web/` and
752
+ * `../Web-App` cannot disagree about which attempt is current or which one may
753
+ * be promoted.
754
+ */
755
+ export interface FrameVariantChip {
756
+ variantId: string;
757
+ status: FrameVariantStatus;
758
+ origin: FrameVariantOrigin;
759
+ /** Which model produced this attempt — the compare axis of §Q SB.53. */
760
+ modelId: string | null;
761
+ seed: number | null;
762
+ imageUrl: string | null;
763
+ createdAt: string;
764
+ /** This attempt's failure message, when it failed. */
765
+ error: string | null;
766
+ /** {@link StoryboardFrame.selectedVariantId} points HERE. */
767
+ selected: boolean;
768
+ /** This is the attempt {@link displayFrameVariant} actually renders. */
769
+ displayed: boolean;
770
+ /** A version-guarded select-variant on this id would be accepted. */
771
+ promotable: boolean;
772
+ /** Why not, when {@link FrameVariantChip.promotable} is false. */
773
+ promoteBlock: VariantPromoteBlock | null;
774
+ }
775
+
776
+ /** The compare strip for one frame ({@link buildFrameVariantStrip}). */
777
+ export interface FrameVariantStrip {
778
+ chips: FrameVariantChip[];
779
+ /**
780
+ * TRUE when {@link StoryboardFrame.selectedVariantId} names something that is
781
+ * NOT A RENDERABLE ATTEMPT — so what the frame CLAIMS is its image and what
782
+ * the board actually shows cannot agree.
783
+ *
784
+ * Two reachable states, both of which the server permits on a frame the WORKER
785
+ * wrote, and they do DIFFERENT harm:
786
+ *
787
+ * - **the selection was EVICTED from the capped history** — nothing addresses
788
+ * it any more (select-variant 404s), and the board silently renders a
789
+ * DIFFERENT attempt than the one the creator chose;
790
+ * - **the selection is `succeeded` with NO rendered bytes** — the codex P2
791
+ * §Q SB.56 closed on the WRITE path only. {@link displayFrameVariant}
792
+ * honours it (it is succeeded), so the board renders NOTHING AT ALL while
793
+ * the frame still claims a selection, and the export 422s on the same
794
+ * frame. That is the state this flag exists to stop being invisible.
795
+ */
796
+ selectionAdrift: boolean;
797
+ /** How many attempts the history still has room for before it evicts. */
798
+ remainingSlots: number;
799
+ /**
800
+ * TRUE when the next attempt will EVICT the oldest one. Surfaced honestly per
801
+ * the row rather than discovered when a chip disappears: `append_variant`
802
+ * drops the oldest non-selected entry at
803
+ * {@link FRAME_VARIANT_HISTORY_CAP}, and an evicted variant can never be
804
+ * promoted again (select-variant 404s on it).
805
+ */
806
+ evictionImminent: boolean;
807
+ }
808
+
809
+ /**
810
+ * §Q SB-U.6 — the variant compare strip for one frame, as pure data.
811
+ *
812
+ * Chips are in GENERATION ORDER (oldest first), which is the order
813
+ * `append_variant` writes them and therefore the order eviction removes them —
814
+ * so left-to-right is also "closest to being evicted" first.
815
+ *
816
+ * `promotable` encodes the SERVER's rule rather than a looser client guess: the
817
+ * select-variant route accepts a variant only when it is `succeeded` AND carries
818
+ * rendered bytes, and 422s otherwise — so those chips are disabled with a reason
819
+ * instead of offering a click that fails.
820
+ *
821
+ * ⚠ **`already-current` is the one block that is NOT a server rejection.**
822
+ * Re-selecting the variant a frame already holds is accepted (200, idempotent);
823
+ * the chip hides the control because the click would be a no-op, not because it
824
+ * would fail. Do not read the four blocks as "the server would 422".
825
+ *
826
+ * ⛔ **"Has bytes" is {@link variantHasBytes}** — `imageKey` OR `imageUrl`, with
827
+ * the `imageKey` half load-bearing. §Q SB.71: this rule and
828
+ * {@link displayFrameVariant} used to disagree inside this one file, which is
829
+ * how a keyless variant could be refused promotion here and still be chosen as
830
+ * the thing to render.
831
+ */
832
+ export function buildFrameVariantStrip(frame: StoryboardFrame): FrameVariantStrip {
833
+ const displayed = displayFrameVariant(frame);
834
+ const chips: FrameVariantChip[] = frame.variants.map(variant => {
835
+ const selected = frame.selectedVariantId === variant.variantId;
836
+ const isDisplayed = displayed?.variantId === variant.variantId;
837
+ const hasBytes = variantHasBytes(variant);
838
+ let promoteBlock: VariantPromoteBlock | null = null;
839
+ if (variant.status === 'pending') promoteBlock = 'pending';
840
+ else if (variant.status === 'failed') promoteBlock = 'failed';
841
+ else if (!hasBytes) promoteBlock = 'no-image';
842
+ else if (selected) promoteBlock = 'already-current';
843
+ return {
844
+ variantId: variant.variantId,
845
+ status: variant.status,
846
+ origin: variant.origin,
847
+ modelId: variant.modelId ?? null,
848
+ seed: variant.seed ?? null,
849
+ imageUrl: variant.imageUrl ?? null,
850
+ createdAt: variant.createdAt,
851
+ error: variant.error ?? null,
852
+ selected,
853
+ displayed: isDisplayed,
854
+ promotable: promoteBlock === null,
855
+ promoteBlock,
856
+ };
857
+ });
858
+ // A selection is adrift unless it names a chip that is itself PROMOTABLE-shaped
859
+ // (succeeded with bytes) — the same rule the select-variant route enforces on
860
+ // the write, applied to what is already stored. Deliberately NOT
861
+ // `displayed?.variantId !== selectedVariantId`: `displayFrameVariant` honours a
862
+ // succeeded-but-keyless selection, so that comparison reads "in agreement" on
863
+ // the exact frame whose board renders nothing.
864
+ const selectedChip = chips.find(chip => chip.variantId === frame.selectedVariantId);
865
+ const selectionAdrift =
866
+ (frame.selectedVariantId ?? '') !== '' &&
867
+ (selectedChip === undefined ||
868
+ selectedChip.promoteBlock === 'pending' ||
869
+ selectedChip.promoteBlock === 'failed' ||
870
+ selectedChip.promoteBlock === 'no-image');
871
+ const remainingSlots = Math.max(0, FRAME_VARIANT_HISTORY_CAP - frame.variants.length);
872
+ return {
873
+ chips,
874
+ selectionAdrift,
875
+ remainingSlots,
876
+ evictionImminent: remainingSlots === 0,
877
+ };
878
+ }
879
+
880
+ // --------------------------------------------------------------- wire: read
881
+
882
+ /** Which projection a detail read returns (spec §4.5 `?view=`). */
883
+ export type StoryboardView = 'arc' | 'quests';
884
+
885
+ /** Runtime enumeration of {@link StoryboardView} for view pickers. */
886
+ export const STORYBOARD_VIEWS: readonly StoryboardView[] = ['arc', 'quests'];
887
+
888
+ /**
889
+ * The quest-view join, COMPUTED per request and never stored (spec §4.5):
890
+ * quest definitions indexed by `sourceBeatId`, joined on
891
+ * {@link StoryboardFrame.beatId}. The client RENDERS {@link GateExpr}; it never
892
+ * evaluates one.
893
+ */
894
+ export interface StoryboardFrameQuestAnnotation {
895
+ frameId: string;
896
+ questId: string;
897
+ /** Serialized `GATED_BY` expression, or null for an ungated quest. */
898
+ gate?: GateExpr | null;
899
+ prereqQuestIds: string[];
900
+ }
901
+
902
+ /** `GET …/storyboards` — board summaries (META items only, no frames). */
903
+ export interface ListStoryboardsResponse {
904
+ traceId: string;
905
+ storyboards: Storyboard[];
906
+ }
907
+
908
+ /**
909
+ * `GET …/storyboards/{id}?view=arc|quests` — board + its frames, with
910
+ * presigned URLs on each variant. `questAnnotations` is populated only for
911
+ * `view=quests`.
912
+ */
913
+ export interface StoryboardDetailResponse {
914
+ traceId: string;
915
+ storyboard: Storyboard;
916
+ frames: StoryboardFrame[];
917
+ questAnnotations?: StoryboardFrameQuestAnnotation[] | null;
918
+ /**
919
+ * §Q DM.105 — the story scope the board's PlotBeats live in (the fork story
920
+ * on a fork-approved arc, the video otherwise). A cutscene for a frame posts
921
+ * this as `storyId`. `null` when the arc is not approved.
922
+ */
923
+ graphStoryId?: string | null;
924
+ /** §Q DM.105 — whether the frames' graph beat ids were checked. Absent on
925
+ * reads from before DM.105: read that as not resolved. */
926
+ graphResolution?: BoardGraphResolution;
927
+ /** §Q DM.105 — frames of a `resolved` board whose beat is no PlotBeat in the
928
+ * graph; a cutscene cannot be grounded on them. */
929
+ unresolvedGraphFrameIds?: string[];
930
+ }
931
+
932
+ /**
933
+ * §Q DM.105 — whether a board's frames resolved to graph `PlotBeat` ids
934
+ * (mirrors backend `services/storyboard/beat_scope.py::BoardGraphResolution`).
935
+ * Compare against these, never a raw literal.
936
+ */
937
+ export const BOARD_GRAPH_RESOLUTION = {
938
+ /** Every frame was checked; the unresolved ones are named. */
939
+ RESOLVED: 'resolved',
940
+ /** The board's arc variant is not the approved one — no PlotBeat of it exists. */
941
+ ARC_NOT_APPROVED: 'arc_not_approved',
942
+ /** The graph holds no node of the arc yet, could not be read, or the board is still generating. */
943
+ UNVERIFIED: 'unverified',
944
+ /** §Q SB.93 — the board's source arc is gone (deleted, another video's, or
945
+ * re-generated without the board's variant). PERMANENT: no later read resolves it. */
946
+ ARC_GONE: 'arc_gone',
947
+ } as const;
948
+
949
+ /**
950
+ * {@link BOARD_GRAPH_RESOLUTION}'s values, OPEN for forward compatibility: the
951
+ * backend may add one (e.g. an arc that is gone), and a reader must treat any
952
+ * value it does not know as NOT resolved rather than fail.
953
+ */
954
+ export type BoardGraphResolution =
955
+ | (typeof BOARD_GRAPH_RESOLUTION)[keyof typeof BOARD_GRAPH_RESOLUTION]
956
+ | (string & {});
957
+
958
+ /** Why a frame cannot ground a cutscene (§Q UX.38). */
959
+ export const FRAME_CUTSCENE_BLOCK = {
960
+ /** The board's arc is not approved, so none of its beats is in the graph. */
961
+ ARC_NOT_APPROVED: 'arc_not_approved',
962
+ /** The graph has not (yet) confirmed this board's beats — or answered a resolution this client does not know. */
963
+ GRAPH_UNVERIFIED: 'graph_unverified',
964
+ /** This frame's beat is no PlotBeat in the graph. */
965
+ FRAME_UNRESOLVED: 'frame_unresolved',
966
+ /** The board's source arc is gone — permanent, unlike {@link FRAME_CUTSCENE_BLOCK.GRAPH_UNVERIFIED}. */
967
+ ARC_GONE: 'arc_gone',
968
+ } as const;
969
+ export type FrameCutsceneBlock = (typeof FRAME_CUTSCENE_BLOCK)[keyof typeof FRAME_CUTSCENE_BLOCK];
970
+
971
+ /** What a cutscene for one frame posts, or why it cannot (§Q UX.38). */
972
+ export type FrameCutsceneTarget =
973
+ | { status: 'ready'; storyId: string; beatId: string }
974
+ | { status: 'blocked'; reason: FrameCutsceneBlock };
975
+
976
+ /**
977
+ * §Q UX.38 — the `{storyId, beatId}` a "cutscene from this frame" posts to
978
+ * `POST /api/v1/videos/generate`, from the board detail read's DM.105 overlay.
979
+ *
980
+ * The ONE place the rule lives: the GRAPH ids (`graphStoryId` +
981
+ * `graphBeatId`), never the frame's board-scoped `beatId` (the measured 404
982
+ * class); and only on a `resolved` board for a frame it did not name as
983
+ * unresolved. Every other state is `blocked` with its reason — including a
984
+ * resolution value this client does not know.
985
+ */
986
+ export function storyboardFrameCutsceneTarget(
987
+ detail: Pick<StoryboardDetailResponse, 'graphStoryId' | 'graphResolution' | 'unresolvedGraphFrameIds'>,
988
+ frame: Pick<StoryboardFrame, 'frameId' | 'graphBeatId'>,
989
+ ): FrameCutsceneTarget {
990
+ if (detail.graphResolution === BOARD_GRAPH_RESOLUTION.ARC_NOT_APPROVED) {
991
+ return { status: 'blocked', reason: FRAME_CUTSCENE_BLOCK.ARC_NOT_APPROVED };
992
+ }
993
+ if (detail.graphResolution === BOARD_GRAPH_RESOLUTION.ARC_GONE) {
994
+ return { status: 'blocked', reason: FRAME_CUTSCENE_BLOCK.ARC_GONE };
995
+ }
996
+ const storyId = detail.graphStoryId?.trim() ?? '';
997
+ if (detail.graphResolution !== BOARD_GRAPH_RESOLUTION.RESOLVED || storyId === '') {
998
+ return { status: 'blocked', reason: FRAME_CUTSCENE_BLOCK.GRAPH_UNVERIFIED };
999
+ }
1000
+ const beatId = frame.graphBeatId?.trim() ?? '';
1001
+ if (beatId === '' || (detail.unresolvedGraphFrameIds ?? []).includes(frame.frameId)) {
1002
+ return { status: 'blocked', reason: FRAME_CUTSCENE_BLOCK.FRAME_UNRESOLVED };
1003
+ }
1004
+ return { status: 'ready', storyId, beatId };
1005
+ }
1006
+
1007
+ // -------------------------------------------------------------- wire: write
1008
+
1009
+ /**
1010
+ * `POST …/storyboards` body. `styleProfile` is a PARTIAL — every field the
1011
+ * backend `StyleProfile` declares has a default, so omitted fields take the
1012
+ * pinned master geometry.
1013
+ */
1014
+ export interface CreateStoryboardRequest {
1015
+ proposalId: string;
1016
+ variantId: string;
1017
+ styleProfile?: Partial<StyleProfile>;
1018
+ modelId?: string;
1019
+ /**
1020
+ * Generate one variant per model per frame, in this order (§Q SB.54) — the
1021
+ * general form of which `modelId` is the singleton case.
1022
+ *
1023
+ * Send ONE of the two, never both: naming both is a 422 rather than a
1024
+ * precedence rule, because silently preferring one would let a creator pay
1025
+ * for a board generated against a model they did not pick. Every id must
1026
+ * declare `multi_reference` and there is a hard cap of TWO (a wall-clock
1027
+ * bound — a maxed 24-frame board already runs 10–15 min at two arms).
1028
+ */
1029
+ modelIds?: string[];
1030
+ }
1031
+
1032
+ /**
1033
+ * `POST …/storyboards/{storyboardId}/frames/{frameId}/retry` body — OPTIONAL
1034
+ * (§Q SB.55). The route has accepted a body-less POST since §Q SB.35 and still
1035
+ * does; this exists to carry ONE thing.
1036
+ */
1037
+ export interface RetryStoryboardFrameRequest {
1038
+ /**
1039
+ * Re-compose this attempt with a DIFFERENT model than the board's. Omitted ⇒
1040
+ * the board's primary model.
1041
+ *
1042
+ * This is the one untried lever for a content-blocked frame: every Gemini
1043
+ * tier shares a single safety stack (§Q SB.32 measured `gemini-3-pro-image`
1044
+ * returning the identical block at twice the price), so a genuine second
1045
+ * opinion needs a second VENDOR. Capability-gated exactly as create is — an
1046
+ * incapable id is a 422 before anything is billed.
1047
+ */
1048
+ modelId?: string;
1049
+ }
1050
+
1051
+ /** 202 envelope from `POST …/storyboards` — poll the detail read until
1052
+ * {@link isStoryboardTerminal}. */
1053
+ export interface CreateStoryboardResponse {
1054
+ traceId: string;
1055
+ storyboard: Storyboard;
1056
+ }
1057
+
1058
+ /**
1059
+ * `PATCH …/frames/{frameId}` body — every field optional, absent = unchanged.
1060
+ * `prompt`/`extensions` merge per-field. `cameraPose: null` clears the pose.
1061
+ * There is no `status` and no `order` here by design.
1062
+ */
1063
+ export interface PatchStoryboardFrameRequest {
1064
+ prompt?: Partial<FramePrompt>;
1065
+ durationSeconds?: FrameDurationSeconds;
1066
+ shotTransition?: ShotTransition;
1067
+ sequenceId?: string | null;
1068
+ cameraPose?: CameraPose | null;
1069
+ characterRefs?: StoryboardFrameRef[];
1070
+ settingRefs?: StoryboardFrameRef[];
1071
+ extensions?: Partial<FrameExtensions>;
1072
+ seed?: number | null;
1073
+ audioEnabled?: boolean;
1074
+ /** Version guard — the {@link StoryboardFrame.txnVer} the edit was based on. */
1075
+ txnVer?: number;
1076
+ }
1077
+
1078
+ /**
1079
+ * `POST …/frames/{frameId}/region-edit` body. A mask routes to a
1080
+ * `mask_inpaint`-capable adapter; no mask routes to `semantic_edit`.
1081
+ */
1082
+ export interface RegionEditFrameRequest {
1083
+ instruction: string;
1084
+ /**
1085
+ * Base64 PNG mask, white = edit / black = keep — exactly what client-core's
1086
+ * `renderMaskToCanvas` (`storyboardMask.ts`, SB-U.2) produces.
1087
+ */
1088
+ maskImageBase64?: string;
1089
+ /** Prefer an identity-preserving adapter for this edit. */
1090
+ keepIdentity?: boolean;
1091
+ }
1092
+
1093
+ /**
1094
+ * `PUT …/frames/{frameId}/world` body — bind the HappyOyster world this frame
1095
+ * opens into (§Q DM.1; owner ruling Q2: ONE permanent world per frame).
1096
+ *
1097
+ * NOT version-guarded, deliberately. A HappyOyster world is paid, permanent and
1098
+ * unlistable, and `worldId` is the only handle that can ever reach it again —
1099
+ * so the persist must not be able to fail because an unrelated regenerate moved
1100
+ * the frame's `txnVer` since it was read. The server write is a first-writer-
1101
+ * wins claim instead: re-sending the SAME id succeeds (retry the persist freely
1102
+ * after a dropped response), a DIFFERENT id **409s** and the error carries the
1103
+ * id the frame already owns so the caller reopens that world rather than
1104
+ * stranding it.
1105
+ *
1106
+ * §Q DM.30 — the MODE is part of this contract, and this doc used to say the
1107
+ * opposite ("the client knows the mode it launched with; `attachWorld`
1108
+ * pre-flights a mismatch on reopen"). A reopen rebuilds the handle from the
1109
+ * STORED frame, so that pre-flight was comparing the session's mode with itself
1110
+ * and could never fire; a World-Explorer (`directing`) world reattached from the
1111
+ * adventure-mode DM reached the vendor and returned `[MODE_MISMATCH]` — after
1112
+ * the world was paid for.
1113
+ *
1114
+ * `worldMode` is optional only so a bind that follows a PAID `createWorld` can
1115
+ * never be rejected outright (losing a billed, unlistable world is worse than
1116
+ * recording an under-described one). Always send it.
1117
+ */
1118
+ export interface SetFrameWorldRequest {
1119
+ /** The `encryptedWorldId` returned by `createWorld`. */
1120
+ worldId: string;
1121
+ /** The mode-fixed model that owns the world — required to reopen it. */
1122
+ worldMode?: HappyOysterMode;
1123
+ /**
1124
+ * §Q `WORLD.11` — the {@link PreparedWorldBeatEntry.leaseToken} this beat's
1125
+ * `pending` entry came back with. It is what CONSUMES the reservation: the
1126
+ * ledger append and the lease delete ride one transaction fenced on this exact
1127
+ * token, so a mint against a lapsed authorisation can no longer consume a
1128
+ * NEWER caller's lease for the same frame — which left that caller holding a
1129
+ * phantom authorisation while the one-beat race re-opened underneath it.
1130
+ *
1131
+ * Omit it for a bind with no prepared authorisation (the DM's own world entry,
1132
+ * a legacy client): the world is still recorded and still counted against the
1133
+ * cap, and no lease is touched.
1134
+ */
1135
+ leaseToken?: string;
1136
+ /**
1137
+ * §Q MOMENT.8 — REQUIRED with `?supersede=true`, rejected without it (422
1138
+ * either way). The world id you READ off the frame: the replacement write is
1139
+ * fenced on it, so a frame that has meanwhile moved to some other world 409s
1140
+ * instead of being overwritten. The superseded id lands in
1141
+ * {@link StoryboardFrame.supersededWorldIds} and stays reachable.
1142
+ */
1143
+ supersedesWorldId?: string;
1144
+ }
1145
+
1146
+ /** One beat's outcome from `POST …/worlds/prepare` (§Q MOMENT.6a). */
1147
+ export type PreparedWorldDisposition =
1148
+ /** The beat's anchor frame already owns a world — skipped, nothing to pay. */
1149
+ | 'bound'
1150
+ /** AUTHORISED to mint. Mint it, then bind it with `setStoryboardFrameWorld`. */
1151
+ | 'pending'
1152
+ /** Refused — the story is at its permanent-world cap. */
1153
+ | 'capped'
1154
+ /** Unseedable: the anchor frame has no rendered image. */
1155
+ | 'blocked'
1156
+ /**
1157
+ * §Q MOMENT.13 — a DIFFERENT authorisation for this beat is outstanding and
1158
+ * has not been minted or lapsed yet. NOT `capped`: the story has slots free,
1159
+ * and two live authorisations for one anchor frame would mean two permanent
1160
+ * worlds billed and one of them refused by the bind. Mint the outstanding
1161
+ * one, or re-run after `leaseExpiresAt`.
1162
+ */
1163
+ | 'held';
1164
+
1165
+ export interface PreparedWorldBeatEntry {
1166
+ beatId: string;
1167
+ frameId: string;
1168
+ disposition: PreparedWorldDisposition;
1169
+ /** The world the frame already owns (`bound`), or — under `supersede` — the
1170
+ * one this beat's new mint replaces, to echo back as `supersedesWorldId`. */
1171
+ worldId?: string | null;
1172
+ worldMode?: HappyOysterMode | null;
1173
+ /** Why, for the `capped`/`blocked`/`held` arms. */
1174
+ reason?: string | null;
1175
+ /**
1176
+ * §Q MOMENT.13 — the authorisation LEASE this mint is covered by, on
1177
+ * `pending` only. A permanent-world slot is RESERVED against the story the
1178
+ * moment it is issued, and binding the world consumes it.
1179
+ */
1180
+ leaseToken?: string | null;
1181
+ /**
1182
+ * Unix epoch seconds the lease lapses at. On `pending` it is the deadline for
1183
+ * minting; on `held` it is when the beat frees up.
1184
+ */
1185
+ leaseExpiresAt?: number | null;
1186
+ }
1187
+
1188
+ /**
1189
+ * One permanent world a story has paid for (§Q WORLD.9).
1190
+ *
1191
+ * HappyOyster worlds are billed once, exist forever, and **cannot be listed
1192
+ * vendor-side** — the id is the only path back to one. Recording it on the
1193
+ * frame alone meant deleting the frame or the board destroyed the sole copy, so
1194
+ * these rows live in a story-level ledger no board delete touches.
1195
+ * `storyboardId`/`frameId` are PROVENANCE and may name rows that no longer
1196
+ * exist; that is the point of the ledger, not a stale reference.
1197
+ */
1198
+ export interface StoryWorldHandle {
1199
+ worldId: string;
1200
+ worldMode?: HappyOysterMode | null;
1201
+ storyboardId?: string | null;
1202
+ frameId?: string | null;
1203
+ recordedAt?: string | null;
1204
+ }
1205
+
1206
+ /**
1207
+ * `POST …/storyboards/{storyboardId}/worlds/prepare` (§Q MOMENT.6a).
1208
+ *
1209
+ * ⚠ **The route AUTHORISES spend; it does not spend.** There is no server-side
1210
+ * `createWorld` — the browser mints. So `pendingCount` is the number of
1211
+ * PERMANENT, BILLED, undeletable worlds this caller is being cleared to create,
1212
+ * and it is the number to show a human before anything happens.
1213
+ */
1214
+ export interface PrepareStoryboardWorldsResponse {
1215
+ traceId: string;
1216
+ beats: PreparedWorldBeatEntry[];
1217
+ /** The per-STORY ceiling in force. */
1218
+ cap: number;
1219
+ /**
1220
+ * Distinct permanent worlds the story already owns, superseded ones included.
1221
+ * Read from the DURABLE story ledger (§Q MOMENT.14), so deleting a board no
1222
+ * longer makes the worlds it paid for vanish from the accounting.
1223
+ */
1224
+ storyWorldCount: number;
1225
+ /** Mints AUTHORISED by this call. THE SPEND NUMBER. */
1226
+ pendingCount: number;
1227
+ skippedCount: number;
1228
+ cappedCount: number;
1229
+ blockedCount: number;
1230
+ /** §Q MOMENT.13 — beats another live authorisation already covers. */
1231
+ heldCount?: number;
1232
+ /**
1233
+ * Slots reserved by authorisations nobody has minted yet. Without it, a
1234
+ * refusal on a story owning 8 of 10 reads as a bug rather than as two
1235
+ * authorisations still outstanding.
1236
+ */
1237
+ outstandingAuthorizations?: number;
1238
+ /**
1239
+ * §Q WORLD.9 — every permanent world this story has paid for. HappyOyster
1240
+ * exposes no listing, so this is the only enumeration that exists anywhere.
1241
+ */
1242
+ permanentWorlds?: StoryWorldHandle[];
1243
+ /**
1244
+ * §Q `WORLD.14a` — permanent worlds this story PAID for that no surviving shot
1245
+ * of any of its boards opens. Always a subset of {@link permanentWorlds}, and
1246
+ * they still count against {@link cap}: the vendor has no delete, so nothing
1247
+ * reclaims them and surfacing them IS the remedy. A non-empty list is the
1248
+ * reading behind "my cap is consumed and I cannot see by what".
1249
+ */
1250
+ unopenedWorldIds?: string[];
1251
+ supersede: boolean;
1252
+ /** The mode every authorised mint must be created in — always `adventure`. */
1253
+ worldMode: HappyOysterMode;
1254
+ /**
1255
+ * §Q WORLD.29 — `true` on the spend PREVIEW (`GET`): nothing was reserved,
1256
+ * `pending` entries carry no `leaseToken`, and `pendingCount` is what a
1257
+ * confirm WOULD authorise. `false`/absent on the leasing confirm (`POST`).
1258
+ */
1259
+ preview?: boolean;
1260
+ /**
1261
+ * §Q WORLD.29 — `true` only on a PREVIEW of a story whose pre-ledger worlds
1262
+ * span more boards than one migration window: `storyWorldCount` (and
1263
+ * `permanentWorlds`) is then a LOWER BOUND, and the confirm refuses until its
1264
+ * migration has walked the rest. Always `false` on the leasing confirm.
1265
+ */
1266
+ storyWorldCountIsFloor?: boolean;
1267
+ }
1268
+
1269
+ /** One authorisation a client is handing back (§Q WORLD.44). */
1270
+ export interface WorldLeaseHandle {
1271
+ frameId: string;
1272
+ /** The `leaseToken` the confirm returned on this frame's `pending` entry.
1273
+ * The release is fenced on it: a lease re-issued to another caller is never
1274
+ * released by this one. */
1275
+ leaseToken: string;
1276
+ }
1277
+
1278
+ /** `POST …/storyboards/{storyboardId}/worlds/release` body (§Q WORLD.44). */
1279
+ export interface ReleaseStoryboardWorldsRequest {
1280
+ leases: WorldLeaseHandle[];
1281
+ }
1282
+
1283
+ /**
1284
+ * What the release door actually released (§Q WORLD.44). `notReleased` is not
1285
+ * an error: the lease was already consumed by a bind, already lapsed and swept,
1286
+ * or carries another token.
1287
+ */
1288
+ export interface ReleaseStoryboardWorldsResponse {
1289
+ traceId: string;
1290
+ released: string[];
1291
+ notReleased: string[];
1292
+ }
1293
+
1294
+ /**
1295
+ * The leases a CONFIRM issued — every `pending` entry carrying a `leaseToken`
1296
+ * (§Q WORLD.44). What a client hands back through
1297
+ * {@link StoryboardsApi.releaseStoryboardWorlds} when it will not spend them. A
1298
+ * preview's entries carry no token, so this is empty for a preview.
1299
+ */
1300
+ export function worldLeasesOf(
1301
+ beats: readonly Pick<PreparedWorldBeatEntry, 'frameId' | 'disposition' | 'leaseToken'>[],
1302
+ ): WorldLeaseHandle[] {
1303
+ return beats.flatMap(beat =>
1304
+ beat.disposition === 'pending' && typeof beat.leaseToken === 'string' && beat.leaseToken !== ''
1305
+ ? [{ frameId: beat.frameId, leaseToken: beat.leaseToken }]
1306
+ : [],
1307
+ );
1308
+ }
1309
+
1310
+ /** `POST …/frames/{frameId}/select-variant` body — version-guarded. */
1311
+ export interface SelectFrameVariantRequest {
1312
+ variantId: string;
1313
+ /** Version guard — the {@link StoryboardFrame.txnVer} the choice was based on. */
1314
+ txnVer?: number;
1315
+ }
1316
+
1317
+ /** Every frame-scoped write returns the refreshed frame. */
1318
+ export interface StoryboardFrameResponse {
1319
+ traceId: string;
1320
+ frame: StoryboardFrame;
1321
+ }
1322
+
1323
+ /**
1324
+ * `PATCH …/storyboards/{id}/order` body — FULL-LIST replace, idempotent. The
1325
+ * list must be a permutation of the board's current `frameIds`.
1326
+ */
1327
+ export interface ReorderStoryboardFramesRequest {
1328
+ frameIds: string[];
1329
+ }
1330
+
1331
+ /** Board-scoped writes return the refreshed META item. */
1332
+ export interface StoryboardResponse {
1333
+ traceId: string;
1334
+ storyboard: Storyboard;
1335
+ }
1336
+
1337
+ /** Export v1 targets (spec §4.6). */
1338
+ export type StoryboardExportTarget = 'longlive' | 'seedance' | 'bundle';
1339
+
1340
+ /** Runtime enumeration of {@link StoryboardExportTarget}. */
1341
+ export const STORYBOARD_EXPORT_TARGETS: readonly StoryboardExportTarget[] = [
1342
+ 'longlive',
1343
+ 'seedance',
1344
+ 'bundle',
1345
+ ];
1346
+
1347
+ /**
1348
+ * `GET …/storyboards/{id}/export/{target}`. `payload` is the target-shaped
1349
+ * document (a LongLive shot script, a Seedance request payload, or the JSON
1350
+ * bundle) — deliberately untyped here because SB.8 owns those three shapes;
1351
+ * the export UI (SB-U.9) narrows it per target.
1352
+ */
1353
+ export interface ExportStoryboardResponse {
1354
+ traceId: string;
1355
+ target: StoryboardExportTarget;
1356
+ filename: string;
1357
+ payload: Record<string, unknown>;
1358
+ }
1359
+
1360
+ // -------------------------------------------------------------------- api
1361
+
1362
+ /**
1363
+ * The visual-storyboard surface (spec §4.5), mounted on the STORIES app
1364
+ * alongside arcs — so every call goes to `transport.baseUrl`. Land-dark: 404s
1365
+ * until `SEER_STORYBOARD_ENABLED` is set server-side.
1366
+ *
1367
+ * Board creation is async (the arcs envelope): create returns **202** with a
1368
+ * QUEUED board, then poll {@link StoryboardsApi.getStoryboard} until
1369
+ * {@link isStoryboardTerminal}. `regenerate` and `region-edit` are likewise
1370
+ * 202 — they append a PENDING variant, which makes the frame read `running`.
1371
+ */
1372
+ export class StoryboardsApi {
1373
+ constructor(private readonly transport: Transport) {}
1374
+
1375
+ private boardsPath(storyId: string): string {
1376
+ return `/api/v1/stories/${encodeURIComponent(storyId)}/storyboards`;
1377
+ }
1378
+
1379
+ private framePath(storyId: string, storyboardId: string, frameId: string): string {
1380
+ return `${this.boardsPath(storyId)}/${encodeURIComponent(storyboardId)}/frames/${encodeURIComponent(frameId)}`;
1381
+ }
1382
+
1383
+ /**
1384
+ * Generate a board from an approved arc variant. `POST
1385
+ * /api/v1/stories/{storyId}/storyboards` → **202** + `Location` + the QUEUED
1386
+ * board; frames fill in as the worker completes them.
1387
+ */
1388
+ async createStoryboard(
1389
+ storyId: string,
1390
+ req: CreateStoryboardRequest,
1391
+ ): Promise<CreateStoryboardResponse> {
1392
+ return this.transport.requestJson<CreateStoryboardResponse>(
1393
+ this.transport.baseUrl,
1394
+ this.boardsPath(storyId),
1395
+ { method: 'POST', body: JSON.stringify(req) },
1396
+ );
1397
+ }
1398
+
1399
+ /**
1400
+ * List a story's boards newest-first (summaries — no frames). `GET
1401
+ * /api/v1/stories/{storyId}/storyboards`.
1402
+ */
1403
+ async listStoryboards(storyId: string): Promise<ListStoryboardsResponse> {
1404
+ return this.transport.requestJson<ListStoryboardsResponse>(
1405
+ this.transport.baseUrl,
1406
+ this.boardsPath(storyId),
1407
+ );
1408
+ }
1409
+
1410
+ /**
1411
+ * Read one board in full — frames + presigned variant URLs, and (with
1412
+ * `view: 'quests'`) the computed quest join. `GET
1413
+ * /api/v1/stories/{storyId}/storyboards/{storyboardId}?view=…&sessionId=…`.
1414
+ * This is also the 202-create poll target.
1415
+ *
1416
+ * `sessionId` (§Q SEC.44, additive): the caller's OWN play session. The
1417
+ * storyboard reads take the fork-material grade, so a definition's player who
1418
+ * is not a member of the story's owner reads the board their run plays only
1419
+ * by naming that session — and only at the default `arc` view. A caller the
1420
+ * grade already admits is unaffected by it.
1421
+ */
1422
+ async getStoryboard(
1423
+ storyId: string,
1424
+ storyboardId: string,
1425
+ params?: { view?: StoryboardView; sessionId?: string },
1426
+ ): Promise<StoryboardDetailResponse> {
1427
+ const search = new URLSearchParams();
1428
+ if (params?.view) search.set('view', params.view);
1429
+ if (params?.sessionId) search.set('sessionId', params.sessionId);
1430
+ const encoded = search.toString();
1431
+ const query = encoded ? `?${encoded}` : '';
1432
+ return this.transport.requestJson<StoryboardDetailResponse>(
1433
+ this.transport.baseUrl,
1434
+ `${this.boardsPath(storyId)}/${encodeURIComponent(storyboardId)}${query}`,
1435
+ );
1436
+ }
1437
+
1438
+ /**
1439
+ * Partial edit of ONE frame — prompt fields, duration, transition, camera,
1440
+ * refs, extensions. Absent fields are unchanged; pass the frame's `txnVer`
1441
+ * to make the write version-guarded (409 on a stale base). `PATCH
1442
+ * /api/v1/stories/{storyId}/storyboards/{storyboardId}/frames/{frameId}`.
1443
+ */
1444
+ async patchStoryboardFrame(
1445
+ storyId: string,
1446
+ storyboardId: string,
1447
+ frameId: string,
1448
+ body: PatchStoryboardFrameRequest,
1449
+ ): Promise<StoryboardFrameResponse> {
1450
+ return this.transport.requestJson<StoryboardFrameResponse>(
1451
+ this.transport.baseUrl,
1452
+ this.framePath(storyId, storyboardId, frameId),
1453
+ { method: 'PATCH', body: JSON.stringify(body) },
1454
+ );
1455
+ }
1456
+
1457
+ /**
1458
+ * @deprecated Use {@link StoryboardsApi.retryStoryboardFrame} — it is the same
1459
+ * operation under the name the server actually implements, and it accepts the
1460
+ * `{modelId}` body this signature cannot express (§Q SB.55).
1461
+ *
1462
+ * Re-run generation for ONE frame with its CURRENT prompt (patch it first with
1463
+ * {@link StoryboardsApi.patchStoryboardFrame} to change it) → **202** + the
1464
+ * frame as it stands; poll the detail read for the appended variant.
1465
+ *
1466
+ * **§Q SB.70 — this used to POST `…/frames/{frameId}/regenerate`, a route that
1467
+ * never existed, so every call 404'd.** It was published by SB-U.1 (#1472)
1468
+ * against a planned endpoint and shipped ahead of it; `SB-U.6`'s row was
1469
+ * written against this method, hit the 404, and had to be rebuilt on `/retry`.
1470
+ * It now targets `/retry`, which has done exactly this job since §Q SB.35.
1471
+ *
1472
+ * Retargeting rather than removing is deliberate: client-core is a contract
1473
+ * with two consumers, one of them a pinned app outside this repo, so the
1474
+ * method must keep existing. Two behaviours you inherit from the real route
1475
+ * and should know about — it **409s a board that is not terminal** (a running
1476
+ * generation already owns the frame), and a retry of an ALREADY-SUCCEEDED
1477
+ * frame is allowed and is a PAID re-roll.
1478
+ */
1479
+ async regenerateStoryboardFrame(
1480
+ storyId: string,
1481
+ storyboardId: string,
1482
+ frameId: string,
1483
+ ): Promise<StoryboardFrameResponse> {
1484
+ return this.retryStoryboardFrame(storyId, storyboardId, frameId);
1485
+ }
1486
+
1487
+ /**
1488
+ * Edit a REGION of one frame — with a mask (inpaint) or without (semantic
1489
+ * edit). `POST …/frames/{frameId}/region-edit` → **202** + the frame with a
1490
+ * PENDING `region_edit` variant appended.
1491
+ */
1492
+ async regionEditStoryboardFrame(
1493
+ storyId: string,
1494
+ storyboardId: string,
1495
+ frameId: string,
1496
+ body: RegionEditFrameRequest,
1497
+ ): Promise<StoryboardFrameResponse> {
1498
+ return this.transport.requestJson<StoryboardFrameResponse>(
1499
+ this.transport.baseUrl,
1500
+ `${this.framePath(storyId, storyboardId, frameId)}/region-edit`,
1501
+ { method: 'POST', body: JSON.stringify(body) },
1502
+ );
1503
+ }
1504
+
1505
+ /**
1506
+ * Choose which variant is the frame's image — SYNCHRONOUS and
1507
+ * version-guarded (echo the frame's `txnVer`; a stale value 409s rather than
1508
+ * clobbering a concurrent edit). `POST …/frames/{frameId}/select-variant`.
1509
+ */
1510
+ async selectStoryboardFrameVariant(
1511
+ storyId: string,
1512
+ storyboardId: string,
1513
+ frameId: string,
1514
+ body: SelectFrameVariantRequest,
1515
+ ): Promise<StoryboardFrameResponse> {
1516
+ return this.transport.requestJson<StoryboardFrameResponse>(
1517
+ this.transport.baseUrl,
1518
+ `${this.framePath(storyId, storyboardId, frameId)}/select-variant`,
1519
+ { method: 'POST', body: JSON.stringify(body) },
1520
+ );
1521
+ }
1522
+
1523
+ /**
1524
+ * Regenerate ONE frame of a terminal board — 202, the board stays terminal
1525
+ * (§Q SB.35, `POST
1526
+ * /api/v1/stories/{storyId}/storyboards/{storyboardId}/frames/{frameId}/retry`).
1527
+ *
1528
+ * The recovery action for a PARTIALLY failed board: without it the only way
1529
+ * to repair one blocked frame is regenerating the whole storyboard, which
1530
+ * re-pays for every frame that already rendered. Pass
1531
+ * {@link RetryStoryboardFrameRequest.modelId} to re-compose with a different
1532
+ * model (§Q SB.55); omit the body entirely to use the board's own.
1533
+ *
1534
+ * **It is asynchronous and PAID.** The response carries the frame as it
1535
+ * stands NOW — poll {@link StoryboardsApi.getStoryboard} for the appended
1536
+ * variant. Two dispatches for the same frame are refused: the second gets a
1537
+ * **409** rather than composing a second billed image (§Q SB.44), so a UI
1538
+ * should disable the control while one is outstanding and treat a 409 as
1539
+ * "already running", not as an error to surface.
1540
+ *
1541
+ * ⚠ **The 202 returns the frame UNCHANGED — no pending variant is appended**
1542
+ * (the worker appends it asynchronously). So the response is a receipt, not
1543
+ * new state: a caller cannot tell from it that the retry is in flight, and
1544
+ * must keep its own outstanding flag and watch the detail read for a variant
1545
+ * id it did not already hold. Watching the variant COUNT does not work at
1546
+ * {@link FRAME_VARIANT_HISTORY_CAP} — `append_variant` evicts one to add one,
1547
+ * so the length does not change (§Q SB-U.6).
1548
+ */
1549
+ async retryStoryboardFrame(
1550
+ storyId: string,
1551
+ storyboardId: string,
1552
+ frameId: string,
1553
+ body: RetryStoryboardFrameRequest = {},
1554
+ ): Promise<StoryboardFrameResponse> {
1555
+ return this.transport.requestJson<StoryboardFrameResponse>(
1556
+ this.transport.baseUrl,
1557
+ `${this.framePath(storyId, storyboardId, frameId)}/retry`,
1558
+ { method: 'POST', body: JSON.stringify(body) },
1559
+ );
1560
+ }
1561
+
1562
+ /**
1563
+ * Persist the HappyOyster world this frame opens into — the DM world-entry
1564
+ * write (§Q DM.1). `PUT
1565
+ * /api/v1/stories/{storyId}/storyboards/{storyboardId}/frames/{frameId}/world`.
1566
+ *
1567
+ * Call it IMMEDIATELY after `createWorld` resolves, and also from
1568
+ * `HappyOysterLaunchError.handle` when `startTravel` failed on a world that
1569
+ * was nonetheless created — that world is already billed, and this call is the
1570
+ * only thing that keeps it findable. Idempotent: safe to retry with the same
1571
+ * id. See {@link SetFrameWorldRequest} for the 409 semantics.
1572
+ */
1573
+ async setStoryboardFrameWorld(
1574
+ storyId: string,
1575
+ storyboardId: string,
1576
+ frameId: string,
1577
+ body: SetFrameWorldRequest,
1578
+ options: { supersede?: boolean } = {},
1579
+ ): Promise<StoryboardFrameResponse> {
1580
+ // §Q MOMENT.8 — the flag and `body.supersedesWorldId` are ONE decision and
1581
+ // the server 422s on either half alone. Sending the flag only when a fence
1582
+ // is present is what keeps a plain DM-side bind on the first-writer-wins
1583
+ // path: a supersede is creator-only and must never be reachable by default.
1584
+ const supersede = options.supersede === true ? '?supersede=true' : '';
1585
+ return this.transport.requestJson<StoryboardFrameResponse>(
1586
+ this.transport.baseUrl,
1587
+ `${this.framePath(storyId, storyboardId, frameId)}/world${supersede}`,
1588
+ { method: 'PUT', body: JSON.stringify(body) },
1589
+ );
1590
+ }
1591
+
1592
+ /**
1593
+ * Plan pre-minting one adventure world per BEAT (§Q MOMENT.6a) —
1594
+ * `/api/v1/stories/{storyId}/storyboards/{storyboardId}/worlds/prepare`.
1595
+ *
1596
+ * **§Q WORLD.29 — two arms, and the DEFAULT reserves nothing.** Without
1597
+ * `confirm` this is the spend PREVIEW (`GET`): the same plan with
1598
+ * `preview: true`, no lease taken, no cap slot consumed — so a preview a
1599
+ * creator abandons blocks no board/video delete. With `confirm: true` it is
1600
+ * the creator's CONFIRM (`POST`): every `pending` entry is LEASED (a story
1601
+ * cap slot reserved for an hour) and carries the `leaseToken` the bind must
1602
+ * echo. Only an explicit "mint" click may pass `confirm` — the owner ruled
1603
+ * leases are taken only on confirm. The confirm answers a 409
1604
+ * `reactor_disabled` while the admin Reactor switch is off (§Q WORLD.30).
1605
+ *
1606
+ * ⚠ **CREATOR-INVOKED ONLY, and the confirm authorises SPEND.** `pendingCount`
1607
+ * is a count of permanent, billed, undeletable worlds — show it before
1608
+ * minting. Then, for each `pending` entry of the CONFIRM, `createWorld` from
1609
+ * that frame's image + compiled prompt and persist the result with
1610
+ * {@link StoryboardsApi.setStoryboardFrameWorld}. Nothing is minted server-side.
1611
+ *
1612
+ * `supersede` (§Q MOMENT.8) re-opens already-bound beats for replacement
1613
+ * instead of skipping them; each authorised entry carries the `worldId` to
1614
+ * echo back as `supersedesWorldId`.
1615
+ *
1616
+ * **§Q WORLD.44 — `frameIds` SCOPES the confirm.** Pass the anchor frames the
1617
+ * run will actually mint (the `frameId` of each confirmed target): only those
1618
+ * beats are leased, and the response reports only them. A confirm without it
1619
+ * leases EVERY pending beat for an hour, holding board and video DELETE at 409
1620
+ * over beats nobody mints. Ignored on the preview. Leases the run then will
1621
+ * not spend go back through {@link StoryboardsApi.releaseStoryboardWorlds}.
1622
+ */
1623
+ async prepareStoryboardWorlds(
1624
+ storyId: string,
1625
+ storyboardId: string,
1626
+ options: {
1627
+ supersede?: boolean;
1628
+ confirm?: boolean;
1629
+ frameIds?: readonly string[];
1630
+ } = {},
1631
+ ): Promise<PrepareStoryboardWorldsResponse> {
1632
+ const supersede = options.supersede === true ? '?supersede=true' : '';
1633
+ const confirm = options.confirm === true;
1634
+ return this.transport.requestJson<PrepareStoryboardWorldsResponse>(
1635
+ this.transport.baseUrl,
1636
+ `${this.boardsPath(storyId)}/${encodeURIComponent(storyboardId)}/worlds/prepare${supersede}`,
1637
+ confirm && options.frameIds !== undefined
1638
+ ? { method: 'POST', body: JSON.stringify({ frameIds: [...options.frameIds] }) }
1639
+ : { method: confirm ? 'POST' : 'GET' },
1640
+ );
1641
+ }
1642
+
1643
+ /**
1644
+ * Hand back world-mint authorisations this client will not spend (§Q
1645
+ * WORLD.44) — `POST
1646
+ * /api/v1/stories/{storyId}/storyboards/{storyboardId}/worlds/release`.
1647
+ *
1648
+ * Call it for a confirm the drift check refused, and for targets a run never
1649
+ * reached or skipped before `createWorld`. ⛔ NEVER for a target whose mint may
1650
+ * have been billed — a release frees the slot for another prepare while that
1651
+ * world is still unrecorded. Token-fenced and idempotent; not Reactor-gated.
1652
+ */
1653
+ async releaseStoryboardWorlds(
1654
+ storyId: string,
1655
+ storyboardId: string,
1656
+ body: ReleaseStoryboardWorldsRequest,
1657
+ ): Promise<ReleaseStoryboardWorldsResponse> {
1658
+ return this.transport.requestJson<ReleaseStoryboardWorldsResponse>(
1659
+ this.transport.baseUrl,
1660
+ `${this.boardsPath(storyId)}/${encodeURIComponent(storyboardId)}/worlds/release`,
1661
+ { method: 'POST', body: JSON.stringify(body) },
1662
+ );
1663
+ }
1664
+
1665
+ /**
1666
+ * Reorder the board — a FULL-LIST replace of {@link Storyboard.frameIds},
1667
+ * which is the ONE ordering source of truth, so this is idempotent and
1668
+ * cannot diverge from a per-frame order. `PATCH
1669
+ * /api/v1/stories/{storyId}/storyboards/{storyboardId}/order`.
1670
+ */
1671
+ async reorderStoryboardFrames(
1672
+ storyId: string,
1673
+ storyboardId: string,
1674
+ body: ReorderStoryboardFramesRequest,
1675
+ ): Promise<StoryboardResponse> {
1676
+ return this.transport.requestJson<StoryboardResponse>(
1677
+ this.transport.baseUrl,
1678
+ `${this.boardsPath(storyId)}/${encodeURIComponent(storyboardId)}/order`,
1679
+ { method: 'PATCH', body: JSON.stringify(body) },
1680
+ );
1681
+ }
1682
+
1683
+ /**
1684
+ * Export the board to one of the v1 targets (`longlive` / `seedance` /
1685
+ * `bundle`). `GET
1686
+ * /api/v1/stories/{storyId}/storyboards/{storyboardId}/export/{target}`.
1687
+ */
1688
+ async exportStoryboard(
1689
+ storyId: string,
1690
+ storyboardId: string,
1691
+ target: StoryboardExportTarget,
1692
+ ): Promise<ExportStoryboardResponse> {
1693
+ return this.transport.requestJson<ExportStoryboardResponse>(
1694
+ this.transport.baseUrl,
1695
+ `${this.boardsPath(storyId)}/${encodeURIComponent(storyboardId)}/export/${encodeURIComponent(target)}`,
1696
+ );
1697
+ }
1698
+ }