reactor-effect-client 0.7.0 → 0.8.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 (514) hide show
  1. package/NOTICE +7 -2
  2. package/README.md +103 -141
  3. package/dist/Coordinator.d.ts +382 -0
  4. package/dist/Coordinator.d.ts.map +1 -0
  5. package/dist/Coordinator.js +732 -0
  6. package/dist/Coordinator.js.map +1 -0
  7. package/dist/H3.d.ts +159 -0
  8. package/dist/H3.d.ts.map +1 -0
  9. package/dist/H3.js +21 -0
  10. package/dist/H3.js.map +1 -0
  11. package/dist/H3Source.d.ts +93 -0
  12. package/dist/H3Source.d.ts.map +1 -0
  13. package/dist/H3Source.js +401 -0
  14. package/dist/H3Source.js.map +1 -0
  15. package/dist/LocalSource.d.ts +68 -0
  16. package/dist/LocalSource.d.ts.map +1 -0
  17. package/dist/LocalSource.js +354 -0
  18. package/dist/LocalSource.js.map +1 -0
  19. package/dist/Media.d.ts +106 -0
  20. package/dist/Media.d.ts.map +1 -0
  21. package/dist/Media.js +16 -0
  22. package/dist/Media.js.map +1 -0
  23. package/dist/Peer.d.ts +134 -0
  24. package/dist/Peer.d.ts.map +1 -0
  25. package/dist/Peer.js +57 -0
  26. package/dist/Peer.js.map +1 -0
  27. package/dist/Playout.d.ts +724 -0
  28. package/dist/Playout.d.ts.map +1 -0
  29. package/dist/Playout.js +28 -0
  30. package/dist/Playout.js.map +1 -0
  31. package/dist/Reactor.d.ts +135 -0
  32. package/dist/Reactor.d.ts.map +1 -0
  33. package/dist/Reactor.js +158 -0
  34. package/dist/Reactor.js.map +1 -0
  35. package/dist/ReactorError.d.ts +331 -0
  36. package/dist/ReactorError.d.ts.map +1 -0
  37. package/dist/ReactorError.js +316 -0
  38. package/dist/ReactorError.js.map +1 -0
  39. package/dist/ReactorTest.d.ts +383 -0
  40. package/dist/ReactorTest.d.ts.map +1 -0
  41. package/dist/ReactorTest.js +317 -0
  42. package/dist/ReactorTest.js.map +1 -0
  43. package/dist/Session.d.ts +314 -0
  44. package/dist/Session.d.ts.map +1 -0
  45. package/dist/Session.js +51 -0
  46. package/dist/Session.js.map +1 -0
  47. package/dist/index.d.ts +12 -22
  48. package/dist/index.d.ts.map +1 -1
  49. package/dist/index.js +12 -11
  50. package/dist/index.js.map +1 -1
  51. package/dist/internal/correlator.d.ts +46 -0
  52. package/dist/internal/correlator.d.ts.map +1 -0
  53. package/dist/internal/correlator.js +150 -0
  54. package/dist/internal/correlator.js.map +1 -0
  55. package/dist/internal/deadline.d.ts +24 -0
  56. package/dist/internal/deadline.d.ts.map +1 -0
  57. package/dist/internal/deadline.js +44 -0
  58. package/dist/internal/deadline.js.map +1 -0
  59. package/dist/{h3/_internal/contracts.d.ts → internal/h3/commands.d.ts} +39 -33
  60. package/dist/internal/h3/commands.d.ts.map +1 -0
  61. package/dist/internal/h3/commands.js +128 -0
  62. package/dist/internal/h3/commands.js.map +1 -0
  63. package/dist/{h3 → internal/h3}/messages.d.ts +16 -11
  64. package/dist/internal/h3/messages.d.ts.map +1 -0
  65. package/dist/{h3 → internal/h3}/messages.js +19 -31
  66. package/dist/internal/h3/messages.js.map +1 -0
  67. package/dist/internal/h3/operations.d.ts +145 -0
  68. package/dist/internal/h3/operations.d.ts.map +1 -0
  69. package/dist/internal/h3/operations.js +284 -0
  70. package/dist/internal/h3/operations.js.map +1 -0
  71. package/dist/{h3 → internal/h3}/profile.d.ts +63 -65
  72. package/dist/internal/h3/profile.d.ts.map +1 -0
  73. package/dist/{h3 → internal/h3}/profile.js +39 -39
  74. package/dist/internal/h3/profile.js.map +1 -0
  75. package/dist/internal/h3/provider.d.ts +14 -0
  76. package/dist/internal/h3/provider.d.ts.map +1 -0
  77. package/dist/internal/h3/provider.js +672 -0
  78. package/dist/internal/h3/provider.js.map +1 -0
  79. package/dist/internal/h3/references.d.ts +68 -0
  80. package/dist/internal/h3/references.d.ts.map +1 -0
  81. package/dist/internal/h3/references.js +339 -0
  82. package/dist/internal/h3/references.js.map +1 -0
  83. package/dist/internal/h3/request.d.ts +56 -0
  84. package/dist/internal/h3/request.d.ts.map +1 -0
  85. package/dist/internal/h3/request.js +70 -0
  86. package/dist/internal/h3/request.js.map +1 -0
  87. package/dist/internal/h3/state.d.ts +120 -0
  88. package/dist/internal/h3/state.d.ts.map +1 -0
  89. package/dist/internal/h3/state.js +270 -0
  90. package/dist/internal/h3/state.js.map +1 -0
  91. package/dist/{Submission.d.ts → internal/h3/submission.d.ts} +1 -3
  92. package/dist/internal/h3/submission.d.ts.map +1 -0
  93. package/dist/{Submission.js → internal/h3/submission.js} +1 -9
  94. package/dist/internal/h3/submission.js.map +1 -0
  95. package/dist/internal/hub.d.ts +32 -0
  96. package/dist/internal/hub.d.ts.map +1 -0
  97. package/dist/internal/hub.js +92 -0
  98. package/dist/internal/hub.js.map +1 -0
  99. package/dist/internal/playout/errors.d.ts +51 -0
  100. package/dist/internal/playout/errors.d.ts.map +1 -0
  101. package/dist/internal/playout/errors.js +40 -0
  102. package/dist/internal/playout/errors.js.map +1 -0
  103. package/dist/internal/playout/policy.d.ts +559 -0
  104. package/dist/internal/playout/policy.d.ts.map +1 -0
  105. package/dist/internal/playout/policy.js +2338 -0
  106. package/dist/internal/playout/policy.js.map +1 -0
  107. package/dist/internal/playout/runtime.d.ts +28 -0
  108. package/dist/internal/playout/runtime.d.ts.map +1 -0
  109. package/dist/internal/playout/runtime.js +766 -0
  110. package/dist/internal/playout/runtime.js.map +1 -0
  111. package/dist/internal/playout/tag.d.ts +14 -0
  112. package/dist/internal/playout/tag.d.ts.map +1 -0
  113. package/dist/internal/playout/tag.js +43 -0
  114. package/dist/internal/playout/tag.js.map +1 -0
  115. package/dist/internal/proto/reactor_wire/v1/common_pb.d.ts +55 -0
  116. package/dist/internal/proto/reactor_wire/v1/common_pb.d.ts.map +1 -0
  117. package/dist/internal/proto/reactor_wire/v1/common_pb.js +42 -0
  118. package/dist/internal/proto/reactor_wire/v1/common_pb.js.map +1 -0
  119. package/dist/internal/proto/reactor_wire/v1/control_pb.d.ts +160 -0
  120. package/dist/internal/proto/reactor_wire/v1/control_pb.d.ts.map +1 -0
  121. package/dist/internal/proto/reactor_wire/v1/control_pb.js +21 -0
  122. package/dist/internal/proto/reactor_wire/v1/control_pb.js.map +1 -0
  123. package/dist/internal/proto/reactor_wire/v1/data_pb.d.ts +89 -0
  124. package/dist/internal/proto/reactor_wire/v1/data_pb.d.ts.map +1 -0
  125. package/dist/internal/proto/reactor_wire/v1/data_pb.js +20 -0
  126. package/dist/internal/proto/reactor_wire/v1/data_pb.js.map +1 -0
  127. package/dist/internal/proto/reactor_wire/v1/model_pb.d.ts +85 -0
  128. package/dist/internal/proto/reactor_wire/v1/model_pb.d.ts.map +1 -0
  129. package/dist/internal/proto/reactor_wire/v1/model_pb.js +24 -0
  130. package/dist/internal/proto/reactor_wire/v1/model_pb.js.map +1 -0
  131. package/dist/internal/proto/reactor_wire/v1/platform_pb.d.ts +190 -0
  132. package/dist/internal/proto/reactor_wire/v1/platform_pb.d.ts.map +1 -0
  133. package/dist/internal/proto/reactor_wire/v1/platform_pb.js +54 -0
  134. package/dist/internal/proto/reactor_wire/v1/platform_pb.js.map +1 -0
  135. package/dist/internal/proto/reactor_wire/v1/track_pb.d.ts +88 -0
  136. package/dist/internal/proto/reactor_wire/v1/track_pb.d.ts.map +1 -0
  137. package/dist/internal/proto/reactor_wire/v1/track_pb.js +33 -0
  138. package/dist/internal/proto/reactor_wire/v1/track_pb.js.map +1 -0
  139. package/dist/internal/queue.d.ts +4 -0
  140. package/dist/internal/queue.d.ts.map +1 -0
  141. package/dist/{_internal → internal}/queue.js +0 -9
  142. package/dist/internal/queue.js.map +1 -0
  143. package/dist/internal/reactorTest/coordinator.d.ts +5 -0
  144. package/dist/internal/reactorTest/coordinator.d.ts.map +1 -0
  145. package/dist/internal/reactorTest/coordinator.js +178 -0
  146. package/dist/internal/reactorTest/coordinator.js.map +1 -0
  147. package/dist/internal/reactorTest/faults.d.ts +172 -0
  148. package/dist/internal/reactorTest/faults.d.ts.map +1 -0
  149. package/dist/internal/reactorTest/faults.js +23 -0
  150. package/dist/internal/reactorTest/faults.js.map +1 -0
  151. package/dist/internal/reactorTest/h3.d.ts +431 -0
  152. package/dist/internal/reactorTest/h3.d.ts.map +1 -0
  153. package/dist/internal/reactorTest/h3.js +625 -0
  154. package/dist/internal/reactorTest/h3.js.map +1 -0
  155. package/dist/internal/reactorTest/media.d.ts +22 -0
  156. package/dist/internal/reactorTest/media.d.ts.map +1 -0
  157. package/dist/internal/reactorTest/media.js +34 -0
  158. package/dist/internal/reactorTest/media.js.map +1 -0
  159. package/dist/internal/reactorTest/peer.d.ts +318 -0
  160. package/dist/internal/reactorTest/peer.d.ts.map +1 -0
  161. package/dist/internal/reactorTest/peer.js +206 -0
  162. package/dist/internal/reactorTest/peer.js.map +1 -0
  163. package/dist/internal/reactorTest/playout.d.ts +34 -0
  164. package/dist/internal/reactorTest/playout.d.ts.map +1 -0
  165. package/dist/internal/reactorTest/playout.js +340 -0
  166. package/dist/internal/reactorTest/playout.js.map +1 -0
  167. package/dist/internal/reactorTest/references.d.ts +25 -0
  168. package/dist/internal/reactorTest/references.d.ts.map +1 -0
  169. package/dist/{testing/Png.js → internal/reactorTest/references.js} +50 -12
  170. package/dist/internal/reactorTest/references.js.map +1 -0
  171. package/dist/internal/reactorTest/sessions.d.ts +364 -0
  172. package/dist/internal/reactorTest/sessions.d.ts.map +1 -0
  173. package/dist/internal/reactorTest/sessions.js +592 -0
  174. package/dist/internal/reactorTest/sessions.js.map +1 -0
  175. package/dist/internal/reactorTest/timing.d.ts +13 -0
  176. package/dist/internal/reactorTest/timing.d.ts.map +1 -0
  177. package/dist/internal/reactorTest/timing.js +20 -0
  178. package/dist/internal/reactorTest/timing.js.map +1 -0
  179. package/dist/internal/recording.d.ts +52 -0
  180. package/dist/internal/recording.d.ts.map +1 -0
  181. package/dist/internal/recording.js +141 -0
  182. package/dist/internal/recording.js.map +1 -0
  183. package/dist/internal/session/connect.d.ts +34 -0
  184. package/dist/internal/session/connect.d.ts.map +1 -0
  185. package/dist/internal/session/connect.js +502 -0
  186. package/dist/internal/session/connect.js.map +1 -0
  187. package/dist/internal/session/generation.d.ts +35 -0
  188. package/dist/internal/session/generation.d.ts.map +1 -0
  189. package/dist/internal/session/generation.js +185 -0
  190. package/dist/internal/session/generation.js.map +1 -0
  191. package/dist/internal/session/ice.d.ts +23 -0
  192. package/dist/internal/session/ice.d.ts.map +1 -0
  193. package/dist/internal/session/ice.js +57 -0
  194. package/dist/internal/session/ice.js.map +1 -0
  195. package/dist/internal/session/inbound.d.ts +50 -0
  196. package/dist/internal/session/inbound.d.ts.map +1 -0
  197. package/dist/internal/session/inbound.js +202 -0
  198. package/dist/internal/session/inbound.js.map +1 -0
  199. package/dist/internal/session/model.d.ts +163 -0
  200. package/dist/internal/session/model.d.ts.map +1 -0
  201. package/dist/internal/session/model.js +78 -0
  202. package/dist/internal/session/model.js.map +1 -0
  203. package/dist/internal/session/requests.d.ts +71 -0
  204. package/dist/internal/session/requests.d.ts.map +1 -0
  205. package/dist/internal/session/requests.js +240 -0
  206. package/dist/internal/session/requests.js.map +1 -0
  207. package/dist/internal/session/tracks.d.ts +21 -0
  208. package/dist/internal/session/tracks.d.ts.map +1 -0
  209. package/dist/internal/session/tracks.js +166 -0
  210. package/dist/internal/session/tracks.js.map +1 -0
  211. package/dist/internal/session/upload.d.ts +21 -0
  212. package/dist/internal/session/upload.d.ts.map +1 -0
  213. package/dist/internal/session/upload.js +68 -0
  214. package/dist/internal/session/upload.js.map +1 -0
  215. package/dist/internal/session.d.ts +66 -0
  216. package/dist/internal/session.d.ts.map +1 -0
  217. package/dist/internal/session.js +280 -0
  218. package/dist/internal/session.js.map +1 -0
  219. package/dist/{stats.d.ts → internal/stats.d.ts} +30 -16
  220. package/dist/internal/stats.d.ts.map +1 -0
  221. package/dist/internal/stats.js +201 -0
  222. package/dist/internal/stats.js.map +1 -0
  223. package/dist/internal/token.d.ts +22 -0
  224. package/dist/internal/token.d.ts.map +1 -0
  225. package/dist/internal/token.js +65 -0
  226. package/dist/internal/token.js.map +1 -0
  227. package/dist/internal/wire.d.ts +37 -0
  228. package/dist/internal/wire.d.ts.map +1 -0
  229. package/dist/internal/wire.js +49 -0
  230. package/dist/internal/wire.js.map +1 -0
  231. package/notices/bufbuild-protobuf-LICENSE +201 -0
  232. package/package.json +17 -38
  233. package/dist/FetchHttp.d.ts +0 -9
  234. package/dist/FetchHttp.d.ts.map +0 -1
  235. package/dist/FetchHttp.js +0 -63
  236. package/dist/FetchHttp.js.map +0 -1
  237. package/dist/PeerFactory.d.ts +0 -26
  238. package/dist/PeerFactory.d.ts.map +0 -1
  239. package/dist/PeerFactory.js +0 -4
  240. package/dist/PeerFactory.js.map +0 -1
  241. package/dist/PeerTypes.d.ts +0 -64
  242. package/dist/PeerTypes.d.ts.map +0 -1
  243. package/dist/PeerTypes.js +0 -2
  244. package/dist/PeerTypes.js.map +0 -1
  245. package/dist/Sequence.d.ts +0 -85
  246. package/dist/Sequence.d.ts.map +0 -1
  247. package/dist/Sequence.js +0 -210
  248. package/dist/Sequence.js.map +0 -1
  249. package/dist/SessionTypes.d.ts +0 -312
  250. package/dist/SessionTypes.d.ts.map +0 -1
  251. package/dist/SessionTypes.js +0 -19
  252. package/dist/SessionTypes.js.map +0 -1
  253. package/dist/Submission.d.ts.map +0 -1
  254. package/dist/Submission.js.map +0 -1
  255. package/dist/_internal/queue.d.ts +0 -6
  256. package/dist/_internal/queue.d.ts.map +0 -1
  257. package/dist/_internal/queue.js.map +0 -1
  258. package/dist/bytes.d.ts +0 -6
  259. package/dist/bytes.d.ts.map +0 -1
  260. package/dist/bytes.js +0 -32
  261. package/dist/bytes.js.map +0 -1
  262. package/dist/contract.d.ts +0 -149
  263. package/dist/contract.d.ts.map +0 -1
  264. package/dist/contract.js +0 -119
  265. package/dist/contract.js.map +0 -1
  266. package/dist/coordinator/_internal/client.d.ts +0 -215
  267. package/dist/coordinator/_internal/client.d.ts.map +0 -1
  268. package/dist/coordinator/_internal/client.js +0 -563
  269. package/dist/coordinator/_internal/client.js.map +0 -1
  270. package/dist/coordinator/_internal/recording.d.ts +0 -31
  271. package/dist/coordinator/_internal/recording.d.ts.map +0 -1
  272. package/dist/coordinator/_internal/recording.js +0 -123
  273. package/dist/coordinator/_internal/recording.js.map +0 -1
  274. package/dist/coordinator/_internal/response.d.ts +0 -15
  275. package/dist/coordinator/_internal/response.d.ts.map +0 -1
  276. package/dist/coordinator/_internal/response.js +0 -55
  277. package/dist/coordinator/_internal/response.js.map +0 -1
  278. package/dist/coordinator/_internal/schemas.d.ts +0 -73
  279. package/dist/coordinator/_internal/schemas.d.ts.map +0 -1
  280. package/dist/coordinator/_internal/schemas.js +0 -200
  281. package/dist/coordinator/_internal/schemas.js.map +0 -1
  282. package/dist/coordinator/index.d.ts +0 -40
  283. package/dist/coordinator/index.d.ts.map +0 -1
  284. package/dist/coordinator/index.js +0 -21
  285. package/dist/coordinator/index.js.map +0 -1
  286. package/dist/correlation.d.ts +0 -47
  287. package/dist/correlation.d.ts.map +0 -1
  288. package/dist/correlation.js +0 -131
  289. package/dist/correlation.js.map +0 -1
  290. package/dist/duration.d.ts +0 -27
  291. package/dist/duration.d.ts.map +0 -1
  292. package/dist/duration.js +0 -47
  293. package/dist/duration.js.map +0 -1
  294. package/dist/errors.d.ts +0 -1303
  295. package/dist/errors.d.ts.map +0 -1
  296. package/dist/errors.js +0 -745
  297. package/dist/errors.js.map +0 -1
  298. package/dist/h3/_internal/client.d.ts +0 -9
  299. package/dist/h3/_internal/client.d.ts.map +0 -1
  300. package/dist/h3/_internal/client.js +0 -652
  301. package/dist/h3/_internal/client.js.map +0 -1
  302. package/dist/h3/_internal/contracts.d.ts.map +0 -1
  303. package/dist/h3/_internal/contracts.js +0 -123
  304. package/dist/h3/_internal/contracts.js.map +0 -1
  305. package/dist/h3/_internal/deployment.d.ts +0 -8
  306. package/dist/h3/_internal/deployment.d.ts.map +0 -1
  307. package/dist/h3/_internal/deployment.js +0 -149
  308. package/dist/h3/_internal/deployment.js.map +0 -1
  309. package/dist/h3/_internal/evidence.d.ts +0 -17
  310. package/dist/h3/_internal/evidence.d.ts.map +0 -1
  311. package/dist/h3/_internal/evidence.js +0 -48
  312. package/dist/h3/_internal/evidence.js.map +0 -1
  313. package/dist/h3/_internal/operations.d.ts +0 -58
  314. package/dist/h3/_internal/operations.d.ts.map +0 -1
  315. package/dist/h3/_internal/operations.js +0 -268
  316. package/dist/h3/_internal/operations.js.map +0 -1
  317. package/dist/h3/_internal/references.d.ts +0 -24
  318. package/dist/h3/_internal/references.d.ts.map +0 -1
  319. package/dist/h3/_internal/references.js +0 -309
  320. package/dist/h3/_internal/references.js.map +0 -1
  321. package/dist/h3/_internal/request.d.ts +0 -21
  322. package/dist/h3/_internal/request.d.ts.map +0 -1
  323. package/dist/h3/_internal/request.js +0 -97
  324. package/dist/h3/_internal/request.js.map +0 -1
  325. package/dist/h3/_internal/retained.d.ts +0 -22
  326. package/dist/h3/_internal/retained.d.ts.map +0 -1
  327. package/dist/h3/_internal/retained.js +0 -89
  328. package/dist/h3/_internal/retained.js.map +0 -1
  329. package/dist/h3/_internal/state.d.ts +0 -44
  330. package/dist/h3/_internal/state.d.ts.map +0 -1
  331. package/dist/h3/_internal/state.js +0 -283
  332. package/dist/h3/_internal/state.js.map +0 -1
  333. package/dist/h3/index.d.ts +0 -10
  334. package/dist/h3/index.d.ts.map +0 -1
  335. package/dist/h3/index.js +0 -7
  336. package/dist/h3/index.js.map +0 -1
  337. package/dist/h3/messages.d.ts.map +0 -1
  338. package/dist/h3/messages.js.map +0 -1
  339. package/dist/h3/profile.d.ts.map +0 -1
  340. package/dist/h3/profile.js.map +0 -1
  341. package/dist/h3/types.d.ts +0 -291
  342. package/dist/h3/types.d.ts.map +0 -1
  343. package/dist/h3/types.js +0 -2
  344. package/dist/h3/types.js.map +0 -1
  345. package/dist/host.d.ts +0 -26
  346. package/dist/host.d.ts.map +0 -1
  347. package/dist/host.js +0 -20
  348. package/dist/host.js.map +0 -1
  349. package/dist/json.d.ts +0 -25
  350. package/dist/json.d.ts.map +0 -1
  351. package/dist/json.js +0 -143
  352. package/dist/json.js.map +0 -1
  353. package/dist/media-stream.d.ts +0 -10
  354. package/dist/media-stream.d.ts.map +0 -1
  355. package/dist/media-stream.js +0 -18
  356. package/dist/media-stream.js.map +0 -1
  357. package/dist/observation.d.ts +0 -38
  358. package/dist/observation.d.ts.map +0 -1
  359. package/dist/observation.js +0 -113
  360. package/dist/observation.js.map +0 -1
  361. package/dist/orchestration/elapsed.d.ts +0 -9
  362. package/dist/orchestration/elapsed.d.ts.map +0 -1
  363. package/dist/orchestration/elapsed.js +0 -8
  364. package/dist/orchestration/elapsed.js.map +0 -1
  365. package/dist/orchestration/h3-source.d.ts +0 -58
  366. package/dist/orchestration/h3-source.d.ts.map +0 -1
  367. package/dist/orchestration/h3-source.js +0 -362
  368. package/dist/orchestration/h3-source.js.map +0 -1
  369. package/dist/orchestration/index.d.ts +0 -17
  370. package/dist/orchestration/index.d.ts.map +0 -1
  371. package/dist/orchestration/index.js +0 -12
  372. package/dist/orchestration/index.js.map +0 -1
  373. package/dist/orchestration/media-buffer.d.ts +0 -32
  374. package/dist/orchestration/media-buffer.d.ts.map +0 -1
  375. package/dist/orchestration/media-buffer.js +0 -94
  376. package/dist/orchestration/media-buffer.js.map +0 -1
  377. package/dist/orchestration/open-h3.d.ts +0 -101
  378. package/dist/orchestration/open-h3.d.ts.map +0 -1
  379. package/dist/orchestration/open-h3.js +0 -127
  380. package/dist/orchestration/open-h3.js.map +0 -1
  381. package/dist/orchestration/queries.d.ts +0 -10
  382. package/dist/orchestration/queries.d.ts.map +0 -1
  383. package/dist/orchestration/queries.js +0 -43
  384. package/dist/orchestration/queries.js.map +0 -1
  385. package/dist/orchestration/references.d.ts +0 -18
  386. package/dist/orchestration/references.d.ts.map +0 -1
  387. package/dist/orchestration/references.js +0 -79
  388. package/dist/orchestration/references.js.map +0 -1
  389. package/dist/orchestration/renewal-state.d.ts +0 -84
  390. package/dist/orchestration/renewal-state.d.ts.map +0 -1
  391. package/dist/orchestration/renewal-state.js +0 -95
  392. package/dist/orchestration/renewal-state.js.map +0 -1
  393. package/dist/orchestration/renewal.d.ts +0 -103
  394. package/dist/orchestration/renewal.d.ts.map +0 -1
  395. package/dist/orchestration/renewal.js +0 -1088
  396. package/dist/orchestration/renewal.js.map +0 -1
  397. package/dist/orchestration/request.d.ts +0 -65
  398. package/dist/orchestration/request.d.ts.map +0 -1
  399. package/dist/orchestration/request.js +0 -134
  400. package/dist/orchestration/request.js.map +0 -1
  401. package/dist/orchestration/retention.d.ts +0 -100
  402. package/dist/orchestration/retention.d.ts.map +0 -1
  403. package/dist/orchestration/retention.js +0 -134
  404. package/dist/orchestration/retention.js.map +0 -1
  405. package/dist/orchestration/routing.d.ts +0 -21
  406. package/dist/orchestration/routing.d.ts.map +0 -1
  407. package/dist/orchestration/routing.js +0 -93
  408. package/dist/orchestration/routing.js.map +0 -1
  409. package/dist/orchestration/scheduler-key.d.ts +0 -14
  410. package/dist/orchestration/scheduler-key.d.ts.map +0 -1
  411. package/dist/orchestration/scheduler-key.js +0 -62
  412. package/dist/orchestration/scheduler-key.js.map +0 -1
  413. package/dist/orchestration/scheduler-policy.d.ts +0 -222
  414. package/dist/orchestration/scheduler-policy.d.ts.map +0 -1
  415. package/dist/orchestration/scheduler-policy.js +0 -582
  416. package/dist/orchestration/scheduler-policy.js.map +0 -1
  417. package/dist/orchestration/scheduler.d.ts +0 -383
  418. package/dist/orchestration/scheduler.d.ts.map +0 -1
  419. package/dist/orchestration/scheduler.js +0 -2597
  420. package/dist/orchestration/scheduler.js.map +0 -1
  421. package/dist/orchestration/source-slot.d.ts +0 -124
  422. package/dist/orchestration/source-slot.d.ts.map +0 -1
  423. package/dist/orchestration/source-slot.js +0 -348
  424. package/dist/orchestration/source-slot.js.map +0 -1
  425. package/dist/orchestration/types.d.ts +0 -1462
  426. package/dist/orchestration/types.d.ts.map +0 -1
  427. package/dist/orchestration/types.js +0 -135
  428. package/dist/orchestration/types.js.map +0 -1
  429. package/dist/protobuf.d.ts +0 -63
  430. package/dist/protobuf.d.ts.map +0 -1
  431. package/dist/protobuf.js +0 -252
  432. package/dist/protobuf.js.map +0 -1
  433. package/dist/session/_internal/acquire.d.ts +0 -21
  434. package/dist/session/_internal/acquire.d.ts.map +0 -1
  435. package/dist/session/_internal/acquire.js +0 -168
  436. package/dist/session/_internal/acquire.js.map +0 -1
  437. package/dist/session/_internal/cleanup.d.ts +0 -19
  438. package/dist/session/_internal/cleanup.d.ts.map +0 -1
  439. package/dist/session/_internal/cleanup.js +0 -102
  440. package/dist/session/_internal/cleanup.js.map +0 -1
  441. package/dist/session/_internal/lifecycle.d.ts +0 -67
  442. package/dist/session/_internal/lifecycle.d.ts.map +0 -1
  443. package/dist/session/_internal/lifecycle.js +0 -142
  444. package/dist/session/_internal/lifecycle.js.map +0 -1
  445. package/dist/session/_internal/remote.d.ts +0 -28
  446. package/dist/session/_internal/remote.d.ts.map +0 -1
  447. package/dist/session/_internal/remote.js +0 -71
  448. package/dist/session/_internal/remote.js.map +0 -1
  449. package/dist/session/_internal/uploads.d.ts +0 -7
  450. package/dist/session/_internal/uploads.d.ts.map +0 -1
  451. package/dist/session/_internal/uploads.js +0 -31
  452. package/dist/session/_internal/uploads.js.map +0 -1
  453. package/dist/session/commands.d.ts +0 -2
  454. package/dist/session/commands.d.ts.map +0 -1
  455. package/dist/session/commands.js +0 -2
  456. package/dist/session/commands.js.map +0 -1
  457. package/dist/session/files.d.ts +0 -21
  458. package/dist/session/files.d.ts.map +0 -1
  459. package/dist/session/files.js +0 -49
  460. package/dist/session/files.js.map +0 -1
  461. package/dist/session/index.d.ts +0 -84
  462. package/dist/session/index.d.ts.map +0 -1
  463. package/dist/session/index.js +0 -16
  464. package/dist/session/index.js.map +0 -1
  465. package/dist/session/media.d.ts +0 -114
  466. package/dist/session/media.d.ts.map +0 -1
  467. package/dist/session/media.js +0 -2
  468. package/dist/session/media.js.map +0 -1
  469. package/dist/session/recorder.d.ts +0 -24
  470. package/dist/session/recorder.d.ts.map +0 -1
  471. package/dist/session/recorder.js +0 -19
  472. package/dist/session/recorder.js.map +0 -1
  473. package/dist/session.d.ts +0 -105
  474. package/dist/session.d.ts.map +0 -1
  475. package/dist/session.js +0 -976
  476. package/dist/session.js.map +0 -1
  477. package/dist/simulation/_internal/source.d.ts +0 -12
  478. package/dist/simulation/_internal/source.d.ts.map +0 -1
  479. package/dist/simulation/_internal/source.js +0 -513
  480. package/dist/simulation/_internal/source.js.map +0 -1
  481. package/dist/simulation/index.d.ts +0 -13
  482. package/dist/simulation/index.d.ts.map +0 -1
  483. package/dist/simulation/index.js +0 -12
  484. package/dist/simulation/index.js.map +0 -1
  485. package/dist/simulation/types.d.ts +0 -39
  486. package/dist/simulation/types.d.ts.map +0 -1
  487. package/dist/simulation/types.js +0 -2
  488. package/dist/simulation/types.js.map +0 -1
  489. package/dist/stats.d.ts.map +0 -1
  490. package/dist/stats.js +0 -205
  491. package/dist/stats.js.map +0 -1
  492. package/dist/testing/Faults.d.ts +0 -4
  493. package/dist/testing/Faults.d.ts.map +0 -1
  494. package/dist/testing/Faults.js +0 -7
  495. package/dist/testing/Faults.js.map +0 -1
  496. package/dist/testing/Png.d.ts +0 -3
  497. package/dist/testing/Png.d.ts.map +0 -1
  498. package/dist/testing/Png.js.map +0 -1
  499. package/dist/testing/Wav.d.ts +0 -14
  500. package/dist/testing/Wav.d.ts.map +0 -1
  501. package/dist/testing/Wav.js +0 -37
  502. package/dist/testing/Wav.js.map +0 -1
  503. package/dist/testing/index.d.ts +0 -5
  504. package/dist/testing/index.d.ts.map +0 -1
  505. package/dist/testing/index.js +0 -4
  506. package/dist/testing/index.js.map +0 -1
  507. package/dist/wire.d.ts +0 -7
  508. package/dist/wire.d.ts.map +0 -1
  509. package/dist/wire.generated.d.ts +0 -305
  510. package/dist/wire.generated.d.ts.map +0 -1
  511. package/dist/wire.generated.js +0 -1257
  512. package/dist/wire.generated.js.map +0 -1
  513. package/dist/wire.js +0 -5
  514. package/dist/wire.js.map +0 -1
@@ -0,0 +1,625 @@
1
+ /**
2
+ * The simulated H3 model's queues, builds and playout as a pure state machine:
3
+ * a command, a finished timer or a new connection goes in; the next state
4
+ * comes out with the messages to send and the timers to start.
5
+ *
6
+ * It states H3 as Reactor documents it and paid runs measured it, and takes
7
+ * no rule from the client: a client limit that drifts from the documentation
8
+ * then fails against the simulation instead of passing with it.
9
+ */
10
+ import * as Result from "effect/Result";
11
+ import * as Schema from "effect/Schema";
12
+ import * as Struct from "effect/Struct";
13
+ /** H3 Reference Turbo Realtime's documented facts, and the grid and audio paid runs measured. */
14
+ export const documented = {
15
+ modelName: "reactor/h3-reference-to-video-turbo-realtime",
16
+ version: "0.5.5",
17
+ fps: 24,
18
+ /** Built lengths: 124 frames and each 17 more up to 362, so 5.167 to 15.083 seconds. */
19
+ frames: { min: 124, step: 17, max: 362 },
20
+ /** Requested lengths, before they are aligned up to the grid. */
21
+ seconds: { min: 5, max: 15.084 },
22
+ images: 9,
23
+ audio: 3,
24
+ /** A continued clip spends one audio slot on the soundtrack it continues. */
25
+ continuedAudio: 2,
26
+ /** Images, audio and a continuation together. */
27
+ references: 12,
28
+ metadataChars: 2_000,
29
+ /**
30
+ * The text budget, about 2,000 tokens; past it a clip fails as it would
31
+ * build. H3 does not document its tokenizer: 3.5 characters a token is this
32
+ * simulation's.
33
+ */
34
+ text: { tokens: 2_000, charactersPerToken: 3.5 },
35
+ canvases: {
36
+ "16:9": { width: 1344, height: 768 },
37
+ "1:1": { width: 768, height: 768 },
38
+ "9:16": { width: 768, height: 1344 },
39
+ "4:3": { width: 1024, height: 768 },
40
+ },
41
+ tracks: { video: "main_video", audio: "main_audio" },
42
+ /** The soundtrack hosted H3 sent in paid runs. */
43
+ soundtrack: { sampleRate: 48_000, channels: 1 },
44
+ };
45
+ const isAspect = (aspect) => Object.hasOwn(documented.canvases, aspect);
46
+ /** The frames a request of `seconds` builds: rounded to frames, then aligned up to the grid. */
47
+ export const framesFor = (seconds) => {
48
+ const { min, step, max } = documented.frames;
49
+ const frames = Math.ceil(seconds * documented.fps - 1e-6);
50
+ return Math.min(max, min + Math.ceil(Math.max(0, frames - min) / step) * step);
51
+ };
52
+ const requestable = (seconds) => seconds >= documented.seconds.min && seconds <= documented.seconds.max;
53
+ const Upload = Schema.Struct({
54
+ upload_id: Schema.String,
55
+ name: Schema.String,
56
+ mime_type: Schema.String,
57
+ size: Schema.Int,
58
+ });
59
+ /** A parameter that may be omitted, and null as well where H3 documents it nullable. */
60
+ const omitted = Schema.optionalKey;
61
+ const nullable = (schema) => schema.pipe(Schema.NullOr, Schema.optionalKey);
62
+ const Empty = Schema.Struct({});
63
+ /**
64
+ * Each command's parameters as H3 documents them; one omitted takes its
65
+ * documented default. A value of the wrong type is refused as invalid.
66
+ */
67
+ export const Arguments = {
68
+ enqueue: Schema.Struct({
69
+ prompt: omitted(Schema.String),
70
+ reference_image: nullable(Upload),
71
+ reference_images: nullable(Upload.pipe(Schema.Array)),
72
+ reference_audio: nullable(Upload),
73
+ reference_audios: nullable(Upload.pipe(Schema.Array)),
74
+ seconds: nullable(Schema.Finite),
75
+ seed: nullable(Schema.Int),
76
+ position: nullable(Schema.Int),
77
+ metadata: omitted(Schema.String),
78
+ continue_from_clip_id: omitted(Schema.String),
79
+ }),
80
+ move: Schema.Struct({ clip_id: omitted(Schema.String), position: omitted(Schema.Int) }),
81
+ pop: Schema.Struct({ clip_id: omitted(Schema.String) }),
82
+ play: Schema.Struct({ clip_id: omitted(Schema.String) }),
83
+ stop: Empty,
84
+ set_seed: Schema.Struct({ seed: omitted(Schema.Int) }),
85
+ set_clip_seconds: Schema.Struct({ seconds: omitted(Schema.Finite) }),
86
+ set_canvas: Schema.Struct({ aspect: omitted(Schema.String) }),
87
+ set_autoplay: Schema.Struct({ enabled: omitted(Schema.Boolean) }),
88
+ set_flush_on_clip_end: Schema.Struct({ enabled: omitted(Schema.Boolean) }),
89
+ get_queue: Empty,
90
+ get_state: Empty,
91
+ reset: Empty,
92
+ };
93
+ export const initial = {
94
+ generation: [],
95
+ playout: [],
96
+ building: undefined,
97
+ playing: undefined,
98
+ arming: undefined,
99
+ stopping: undefined,
100
+ deferred: [],
101
+ autoplay: false,
102
+ flush: true,
103
+ seed: 1000,
104
+ clipFrames: framesFor(15),
105
+ aspect: "16:9",
106
+ clipsPlayed: 0,
107
+ secondsSent: 0,
108
+ clips: 0,
109
+ generated: new Set(),
110
+ dropped: new Set(),
111
+ continuations: new Map(),
112
+ tokens: 0,
113
+ };
114
+ const idPrefix = "00000000-0000-4000-8000-";
115
+ /** Clip ids are UUIDs numbered in creation order, so a frame can name its clip. */
116
+ export const clipId = (ordinal) => `${idPrefix}${ordinal.toString(16).padStart(12, "0")}`;
117
+ /** Whether the session created `id` and has not dropped it. */
118
+ const holds = (model, id) => {
119
+ const ordinal = id.startsWith(idPrefix) ? Number.parseInt(id.slice(idPrefix.length), 16) : 0;
120
+ return ordinal >= 1 && ordinal <= model.clips && !model.dropped.has(id);
121
+ };
122
+ const adding = (set, ids) => new Set([...set, ...ids]);
123
+ /** An enqueue's references: images, audio, and whether it continues a clip. */
124
+ const referencesOf = (args) => ({
125
+ images: args.reference_images?.length ?? (args.reference_image == null ? 0 : 1),
126
+ audio: args.reference_audios?.length ?? (args.reference_audio == null ? 0 : 1),
127
+ continued: (args.continue_from_clip_id ?? "") !== "",
128
+ });
129
+ /** Why H3 refuses an enqueue, by its documented rules. */
130
+ const refusal = (args, queued, env) => {
131
+ const { images, audio, continued } = referencesOf(args);
132
+ if (args.reference_image != null && args.reference_images != null)
133
+ return "reference_image and reference_images together";
134
+ if (args.reference_audio != null && args.reference_audios != null)
135
+ return "reference_audio and reference_audios together";
136
+ if ((args.prompt ?? "").trim() === "")
137
+ return "the prompt is empty";
138
+ if (args.seconds != null && !requestable(args.seconds))
139
+ return "seconds out of range";
140
+ if ((args.seed ?? 0) < 0 || (args.position ?? 0) < 0)
141
+ return "seed and position must be natural";
142
+ if (Array.from(args.metadata ?? "").length > documented.metadataChars)
143
+ return "metadata is too long";
144
+ if (images > documented.images)
145
+ return "too many reference images";
146
+ if (audio > documented.audio || (audio > 0 && images === 0 && !continued))
147
+ return "invalid reference audio";
148
+ if (continued && audio > documented.continuedAudio)
149
+ return "a continued clip takes at most two audio references";
150
+ if (images + audio + (continued ? 1 : 0) > documented.references)
151
+ return "too many references";
152
+ if (queued >= env.generationCapacity)
153
+ return "the generation queue is full";
154
+ return undefined;
155
+ };
156
+ export const step = ({ model, input, env, }) => {
157
+ let s = model;
158
+ const out = [];
159
+ const set = (patch) => {
160
+ s = { ...s, ...patch };
161
+ };
162
+ const token = () => {
163
+ set({ tokens: s.tokens + 1 });
164
+ return s.tokens;
165
+ };
166
+ const emit = (output) => {
167
+ out.push(output);
168
+ };
169
+ const broadcast = (message) => emit({ _tag: "Broadcast", message });
170
+ const reply = (requestId, message) => emit({ _tag: "Reply", requestId, message });
171
+ const refuse = (requestId, command, reason) => reply(requestId, { type: "command_error", data: { command, reason } });
172
+ const queue = () => ({ generation: s.generation, playout: s.playout, history: [] });
173
+ const elapsed = () => s.playing && Math.min(s.playing.clip.seconds, (env.now - s.playing.startedAt) / 1000);
174
+ const state = () => {
175
+ const idle = s.playing === undefined && s.arming === undefined;
176
+ const queued = s.generation.length + s.playout.length;
177
+ // Commands the state names valid; any command not listed here always is.
178
+ const valid = {
179
+ enqueue: s.generation.length < env.generationCapacity,
180
+ move: queued > 0,
181
+ pop: queued > 0,
182
+ play: idle && s.playout.length > 0,
183
+ stop: !idle,
184
+ set_canvas: idle && queued === 0,
185
+ };
186
+ return {
187
+ clip_seconds: s.clipFrames / documented.fps,
188
+ clip_seconds_min: documented.seconds.min,
189
+ clip_seconds_max: documented.seconds.max,
190
+ seed: s.seed,
191
+ autoplay: s.autoplay,
192
+ flush_on_clip_end: s.flush,
193
+ aspect: s.aspect,
194
+ ...documented.canvases[s.aspect],
195
+ playing: !idle,
196
+ playing_clip_id: s.playing?.clip.clip_id ?? s.arming?.clipId ?? null,
197
+ generation_queued: s.generation.length,
198
+ generation_capacity: env.generationCapacity,
199
+ playout_queued: s.playout.length,
200
+ playout_capacity: env.playoutCapacity,
201
+ clips_played: s.clipsPlayed,
202
+ seconds_sent: s.secondsSent + (elapsed() ?? 0),
203
+ valid_commands: Object.keys(Arguments).filter((name) => valid[name] ?? true),
204
+ };
205
+ };
206
+ const changed = (withState = true) => {
207
+ broadcast({ type: "queue_update", data: queue() });
208
+ if (withState)
209
+ broadcast({ type: "state_update", data: state() });
210
+ };
211
+ const fail = (clip, reason) => {
212
+ set({
213
+ generation: s.generation.filter((entry) => entry !== clip),
214
+ dropped: adding(s.dropped, [clip.clip_id]),
215
+ });
216
+ broadcast({ type: "clip_failed", data: { clip, reason } });
217
+ changed();
218
+ };
219
+ /**
220
+ * The next clip builds unless a build holds the slot or the ready queue is
221
+ * full. A prompt past the model's text budget fails its clip when it would
222
+ * build.
223
+ */
224
+ const build = () => {
225
+ for (;;) {
226
+ const next = s.generation[0];
227
+ if (s.building !== undefined || next === undefined)
228
+ return;
229
+ if (s.playout.length >= env.playoutCapacity)
230
+ return;
231
+ if (next.prompt.length / documented.text.charactersPerToken > documented.text.tokens) {
232
+ fail(next, "the prompt exceeds the model's text budget");
233
+ continue;
234
+ }
235
+ const from = s.continuations.get(next.clip_id);
236
+ const continued = from !== undefined && s.generated.has(from) && !s.dropped.has(from);
237
+ if (from !== undefined)
238
+ emit({ _tag: "Continuation", clipId: next.clip_id, from, applied: continued });
239
+ const t = token();
240
+ set({ building: { clipId: next.clip_id, token: t, discarded: false } });
241
+ emit({ _tag: "Build", token: t, seconds: next.seconds, continued });
242
+ return;
243
+ }
244
+ };
245
+ const arm = () => {
246
+ if (!s.autoplay || s.playing !== undefined || s.arming !== undefined)
247
+ return;
248
+ const next = s.playout[0];
249
+ if (next === undefined)
250
+ return;
251
+ const t = token();
252
+ set({ arming: { token: t, clipId: next.clip_id } });
253
+ emit({ _tag: "Arm", token: t });
254
+ };
255
+ const start = (clip) => {
256
+ const t = token();
257
+ set({
258
+ arming: undefined,
259
+ playout: s.playout.filter((entry) => entry !== clip),
260
+ playing: { clip, startedAt: env.now, token: t },
261
+ });
262
+ emit({ _tag: "Play", clip, startedAt: env.now, token: t });
263
+ broadcast({ type: "clip_started", data: { clip } });
264
+ changed();
265
+ build();
266
+ if (s.stopping === undefined)
267
+ resume();
268
+ };
269
+ const end = (how) => {
270
+ const playing = s.playing;
271
+ if (playing === undefined)
272
+ return;
273
+ const seconds = how === "clip_finished" ? playing.clip.seconds : (elapsed() ?? 0);
274
+ set({
275
+ playing: undefined,
276
+ secondsSent: s.secondsSent + seconds,
277
+ clipsPlayed: s.clipsPlayed + 1,
278
+ });
279
+ if (how === "clip_stopped")
280
+ emit({ _tag: "Halt", token: playing.token });
281
+ if (s.flush)
282
+ emit({ _tag: "Flush", clip: playing.clip });
283
+ broadcast({ type: how, data: { clip: playing.clip, seconds_sent: s.secondsSent } });
284
+ broadcast({ type: "state_update", data: state() });
285
+ arm();
286
+ };
287
+ /** Stop cuts the armed clip before it starts, as it would cut a playing one. */
288
+ const cutArmed = (clipId) => {
289
+ const armed = s.playout.find((entry) => entry.clip_id === clipId);
290
+ if (armed === undefined)
291
+ return;
292
+ set({
293
+ arming: undefined,
294
+ playout: s.playout.filter((entry) => entry !== armed),
295
+ clipsPlayed: s.clipsPlayed + 1,
296
+ });
297
+ broadcast({ type: "clip_stopped", data: { clip: armed, seconds_sent: s.secondsSent } });
298
+ changed();
299
+ arm();
300
+ };
301
+ /**
302
+ * A stop is acknowledged at once and takes effect after its lag, on the clip
303
+ * that played or was armed when it arrived. One sent while another lands
304
+ * waits for it.
305
+ */
306
+ const stop = (id) => {
307
+ if (s.stopping !== undefined) {
308
+ set({ deferred: [...s.deferred, id] });
309
+ return;
310
+ }
311
+ const clipId = s.playing?.clip.clip_id ?? s.arming?.clipId;
312
+ if (clipId === undefined)
313
+ return refuse(id, "stop", "nothing is playing");
314
+ emit({ _tag: "Ack", requestId: id });
315
+ const t = token();
316
+ set({ stopping: { token: t, clipId } });
317
+ emit({ _tag: "Land", token: t });
318
+ };
319
+ /** The stops that waited on a landing stop, handled now. */
320
+ const resume = () => {
321
+ const waiting = s.deferred;
322
+ set({ deferred: [] });
323
+ for (const id of waiting)
324
+ stop(id);
325
+ };
326
+ const accepted = (id, message) => {
327
+ reply(id, message);
328
+ broadcast({ type: "state_update", data: state() });
329
+ };
330
+ const enqueue = (id, args) => {
331
+ const decoded = Schema.decodeResult(Arguments.enqueue)(args);
332
+ if (Result.isFailure(decoded))
333
+ return refuse(id, "enqueue", "invalid arguments");
334
+ const a = decoded.success;
335
+ const problem = refusal(a, s.generation.length, env);
336
+ if (problem !== undefined)
337
+ return refuse(id, "enqueue", problem);
338
+ const { images, audio } = referencesOf(a);
339
+ // An unknown or dropped continuation falls back to an independent clip,
340
+ // except for a clip whose audio would then have no image to go with.
341
+ const from = a.continue_from_clip_id ?? "";
342
+ if (from !== "" && !holds(s, from) && audio > 0 && images === 0)
343
+ return refuse(id, "enqueue", "continue_from_clip_id names no clip the session holds");
344
+ const frames = a.seconds == null ? s.clipFrames : framesFor(a.seconds);
345
+ const clip = {
346
+ clip_id: clipId(s.clips + 1),
347
+ prompt: a.prompt ?? "",
348
+ metadata: a.metadata ?? "",
349
+ frames,
350
+ seconds: frames / documented.fps,
351
+ seed: a.seed ?? s.seed,
352
+ ready: false,
353
+ has_reference_image: images > 0,
354
+ reference_image_count: images,
355
+ has_reference_audio: audio > 0,
356
+ reference_audio_count: audio,
357
+ };
358
+ // Position 0 goes ahead of every queued clip except the one building, as documented. One
359
+ // hosted read (0.7.0 `scheduler-cut` run) listed it ahead of the running build as well.
360
+ const first = s.building !== undefined && !s.building.discarded ? 1 : 0;
361
+ const at = Math.min(Math.max(a.position ?? s.generation.length, first), s.generation.length);
362
+ set({
363
+ clips: s.clips + 1,
364
+ seed: a.seed == null ? s.seed + 1 : s.seed,
365
+ generation: [...s.generation.slice(0, at), clip, ...s.generation.slice(at)],
366
+ ...(from === "" ? {} : { continuations: new Map(s.continuations).set(clip.clip_id, from) }),
367
+ });
368
+ // Hosted H3 broadcasts the queue that lists the clip before its reply.
369
+ changed();
370
+ reply(id, { type: "clip_queued", data: { clip } });
371
+ build();
372
+ };
373
+ const move = (id, args) => {
374
+ const decoded = Schema.decodeResult(Arguments.move)(args);
375
+ if (Result.isFailure(decoded) || (decoded.success.position ?? 0) < 0)
376
+ return refuse(id, "move", "position must be a natural number");
377
+ const { clip_id: wanted = "", position = 0 } = decoded.success;
378
+ const target = s.generation.some((clip) => clip.clip_id === wanted) ? "generation" : "playout";
379
+ const list = target === "generation" ? s.generation : s.playout;
380
+ const clip = list.find((entry) => entry.clip_id === wanted);
381
+ if (clip === undefined)
382
+ return refuse(id, "move", "no queued clip has that id");
383
+ const rest = list.filter((entry) => entry !== clip);
384
+ // The clip building stays first; nothing moves ahead of it.
385
+ const building = target === "generation" && s.building !== undefined && !s.building.discarded;
386
+ const at = building && s.building?.clipId === wanted
387
+ ? 0
388
+ : Math.min(Math.max(position, building ? 1 : 0), rest.length);
389
+ const moved = [...rest.slice(0, at), clip, ...rest.slice(at)];
390
+ set(target === "generation" ? { generation: moved } : { playout: moved });
391
+ reply(id, { type: "clip_moved", data: { clip, queue: target, position: at } });
392
+ changed(false);
393
+ };
394
+ const pop = (id, args) => {
395
+ const decoded = Schema.decodeResult(Arguments.pop)(args);
396
+ const wanted = Result.isSuccess(decoded) ? decoded.success.clip_id : undefined;
397
+ const clip = [...s.generation, ...s.playout].find((entry) => entry.clip_id === wanted);
398
+ if (clip === undefined)
399
+ return refuse(id, "pop", "no queued clip has that id");
400
+ set({
401
+ generation: s.generation.filter((entry) => entry !== clip),
402
+ playout: s.playout.filter((entry) => entry !== clip),
403
+ dropped: adding(s.dropped, [clip.clip_id]),
404
+ ...(s.building?.clipId === clip.clip_id
405
+ ? { building: { ...s.building, discarded: true } }
406
+ : {}),
407
+ });
408
+ reply(id, { type: "clip_popped", data: { clip } });
409
+ changed();
410
+ build();
411
+ };
412
+ const play = (id, args) => {
413
+ const decoded = Schema.decodeResult(Arguments.play)(args);
414
+ if (Result.isFailure(decoded))
415
+ return refuse(id, "play", "invalid arguments");
416
+ if (s.playing !== undefined || s.arming !== undefined)
417
+ return refuse(id, "play", "a clip is already playing");
418
+ const wanted = decoded.success.clip_id ?? "";
419
+ const clip = wanted === "" ? s.playout[0] : s.playout.find((entry) => entry.clip_id === wanted);
420
+ if (clip === undefined)
421
+ return refuse(id, "play", "no matching ready clip");
422
+ emit({ _tag: "Ack", requestId: id });
423
+ start(clip);
424
+ };
425
+ const reset = (id) => {
426
+ const waiting = s.deferred;
427
+ const armed = s.playout.find((entry) => entry.clip_id === s.arming?.clipId);
428
+ const stopped = s.playing?.clip ?? armed;
429
+ const queued = [...s.generation, ...s.playout].filter((clip) => clip !== armed);
430
+ const halted = s.playing?.token;
431
+ set({
432
+ ...initial,
433
+ clips: s.clips,
434
+ tokens: s.tokens,
435
+ generated: s.generated,
436
+ dropped: adding(s.dropped, [...queued, ...(armed === undefined ? [] : [armed])].map((clip) => clip.clip_id)),
437
+ continuations: s.continuations,
438
+ clipsPlayed: s.clipsPlayed + (stopped === undefined ? 0 : 1),
439
+ secondsSent: s.secondsSent + (elapsed() ?? 0),
440
+ });
441
+ reply(id, {
442
+ type: "session_reset",
443
+ data: { cleared_clips: queued.length, was_playing: stopped !== undefined },
444
+ });
445
+ changed();
446
+ if (stopped === undefined)
447
+ return;
448
+ if (halted !== undefined)
449
+ emit({ _tag: "Halt", token: halted });
450
+ // Reset always clears the tracks.
451
+ emit({ _tag: "Flush", clip: stopped });
452
+ broadcast({ type: "clip_stopped", data: { clip: stopped, seconds_sent: s.secondsSent } });
453
+ // The landing stop went with the reset; the stops waiting on it find nothing playing.
454
+ for (const deferred of waiting)
455
+ stop(deferred);
456
+ };
457
+ const command = (id, name, args) => {
458
+ switch (name) {
459
+ case "enqueue":
460
+ return enqueue(id, args);
461
+ case "move":
462
+ return move(id, args);
463
+ case "pop":
464
+ return pop(id, args);
465
+ case "play":
466
+ return play(id, args);
467
+ case "stop":
468
+ return stop(id);
469
+ case "set_seed": {
470
+ const decoded = Schema.decodeResult(Arguments.set_seed)(args);
471
+ const seed = Result.isSuccess(decoded) ? (decoded.success.seed ?? 1000) : -1;
472
+ if (seed < 0)
473
+ return refuse(id, name, "seed must be a natural number");
474
+ set({ seed });
475
+ return accepted(id, { type: "seed_accepted", data: { seed: s.seed } });
476
+ }
477
+ case "set_clip_seconds": {
478
+ const decoded = Schema.decodeResult(Arguments.set_clip_seconds)(args);
479
+ const seconds = Result.isSuccess(decoded) ? (decoded.success.seconds ?? 15) : 0;
480
+ if (!requestable(seconds))
481
+ return refuse(id, name, "seconds out of range");
482
+ set({ clipFrames: framesFor(seconds) });
483
+ const data = { clip_seconds: s.clipFrames / documented.fps, frames: s.clipFrames };
484
+ return accepted(id, { type: "clip_length_accepted", data });
485
+ }
486
+ case "set_canvas": {
487
+ const decoded = Schema.decodeResult(Arguments.set_canvas)(args);
488
+ const aspect = Result.isSuccess(decoded) ? (decoded.success.aspect ?? "16:9") : "";
489
+ if (!isAspect(aspect))
490
+ return refuse(id, name, "unsupported aspect");
491
+ if (s.playing !== undefined || s.generation.length + s.playout.length > 0)
492
+ return refuse(id, name, "the canvas changes only while idle and empty");
493
+ set({ aspect });
494
+ const data = { aspect, ...documented.canvases[aspect] };
495
+ return accepted(id, { type: "canvas_accepted", data });
496
+ }
497
+ case "set_autoplay":
498
+ case "set_flush_on_clip_end": {
499
+ const decoded = Schema.decodeResult(Arguments[name])(args);
500
+ if (Result.isFailure(decoded))
501
+ return refuse(id, name, "enabled must be boolean");
502
+ // Autoplay is off unless asked for, and flushing on.
503
+ const enabled = decoded.success.enabled ?? name === "set_flush_on_clip_end";
504
+ set(name === "set_autoplay" ? { autoplay: enabled } : { flush: enabled });
505
+ const type = name === "set_autoplay" ? "autoplay_accepted" : "flush_accepted";
506
+ accepted(id, { type, data: { enabled } });
507
+ return arm();
508
+ }
509
+ case "get_queue":
510
+ return reply(id, { type: "queue_update", data: queue() });
511
+ case "get_state":
512
+ return reply(id, { type: "state_update", data: state() });
513
+ case "reset":
514
+ return reset(id);
515
+ default:
516
+ emit({ _tag: "Unknown", requestId: id, command: name });
517
+ }
518
+ };
519
+ switch (input._tag) {
520
+ case "Connected":
521
+ changed();
522
+ break;
523
+ case "Command":
524
+ if (input.refuse !== undefined)
525
+ refuse(input.requestId, input.name, input.refuse);
526
+ else
527
+ command(input.requestId, input.name, input.args);
528
+ break;
529
+ case "Built":
530
+ case "BuildFailed": {
531
+ const building = s.building;
532
+ if (building?.token !== input.token)
533
+ break;
534
+ set({ building: undefined });
535
+ const clip = s.generation.find((entry) => entry.clip_id === building.clipId);
536
+ if (!building.discarded && clip !== undefined) {
537
+ set({ generation: s.generation.filter((entry) => entry !== clip) });
538
+ if (input._tag === "Built") {
539
+ const ready = { ...clip, ready: true };
540
+ set({ playout: [...s.playout, ready], generated: adding(s.generated, [clip.clip_id]) });
541
+ broadcast({ type: "clip_generated", data: { clip: ready } });
542
+ }
543
+ else {
544
+ set({ dropped: adding(s.dropped, [clip.clip_id]) });
545
+ broadcast({ type: "clip_failed", data: { clip, reason: input.reason } });
546
+ }
547
+ changed();
548
+ arm();
549
+ }
550
+ build();
551
+ break;
552
+ }
553
+ case "Start": {
554
+ const armed = s.arming;
555
+ if (armed?.token !== input.token)
556
+ break;
557
+ set({ arming: undefined });
558
+ const next = s.playout.find((entry) => entry.clip_id === armed.clipId) ?? s.playout[0];
559
+ if (next !== undefined && s.autoplay && s.playing === undefined)
560
+ start(next);
561
+ break;
562
+ }
563
+ case "Finish":
564
+ if (s.playing?.token === input.token)
565
+ end("clip_finished");
566
+ break;
567
+ case "Landed": {
568
+ const landing = s.stopping;
569
+ if (landing?.token !== input.token)
570
+ break;
571
+ set({ stopping: undefined });
572
+ if (s.playing?.clip.clip_id === landing.clipId)
573
+ end("clip_stopped");
574
+ else if (s.arming?.clipId === landing.clipId)
575
+ cutArmed(landing.clipId);
576
+ // The stops sent meanwhile wait for the next clip to start, if one is arming.
577
+ if (s.arming === undefined)
578
+ resume();
579
+ break;
580
+ }
581
+ }
582
+ return [s, out];
583
+ };
584
+ /** The message each command replies with, as H3's schema names it. */
585
+ const replies = {
586
+ enqueue: "clip_queued",
587
+ move: "clip_moved",
588
+ pop: "clip_popped",
589
+ play: "accepted; emits clip_started",
590
+ stop: "accepted; emits clip_stopped",
591
+ set_seed: "seed_accepted",
592
+ set_clip_seconds: "clip_length_accepted",
593
+ set_canvas: "canvas_accepted",
594
+ set_autoplay: "autoplay_accepted",
595
+ set_flush_on_clip_end: "flush_accepted",
596
+ get_queue: "queue_update",
597
+ get_state: "state_update",
598
+ reset: "session_reset",
599
+ };
600
+ /**
601
+ * The deployment document `request_schema` answers with: each command and
602
+ * its parameters, from this simulation's own statement of them. A deployment
603
+ * without reference audio declares none.
604
+ */
605
+ export const deployment = (referenceAudio) => ({
606
+ openapi: "3.1.0",
607
+ info: { title: "H3 Reference Turbo Realtime (ReactorTest)", version: documented.version },
608
+ paths: Object.fromEntries(Struct.keys(Arguments).map((name) => {
609
+ const args = name === "enqueue" && !referenceAudio
610
+ ? Arguments.enqueue.mapFields(Struct.omit(["reference_audio", "reference_audios"]))
611
+ : Arguments[name];
612
+ const schema = Schema.toJsonSchemaDocument(args).schema;
613
+ return [
614
+ `/events/${name}`,
615
+ {
616
+ post: {
617
+ operationId: name,
618
+ requestBody: { required: true, content: { "application/json": { schema } } },
619
+ responses: { "200": { description: replies[name] } },
620
+ },
621
+ },
622
+ ];
623
+ })),
624
+ });
625
+ //# sourceMappingURL=h3.js.map