@animastor/orchestration 0.1.1

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 (36) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +75 -0
  3. package/package.json +51 -0
  4. package/src/host/host-bindings.js +138 -0
  5. package/src/index.js +99 -0
  6. package/src/orchestration/index.js +40 -0
  7. package/src/orchestration/orchestrator.js +630 -0
  8. package/src/orchestration/runtime-result-consumer.js +54 -0
  9. package/src/orchestration/scene-callbacks.js +542 -0
  10. package/src/orchestration/scene-orchestrator.js +601 -0
  11. package/src/orchestration/scene-restoration.js +129 -0
  12. package/src/orchestration/scene-utils.js +36 -0
  13. package/src/runtime/active-scenes-index.js +164 -0
  14. package/src/runtime/audio-fsm-port.js +187 -0
  15. package/src/runtime/circuit-breaker.js +588 -0
  16. package/src/runtime/counter-reconciliation.js +308 -0
  17. package/src/runtime/dispatch-engine.js +1768 -0
  18. package/src/runtime/failure-taxonomy.js +125 -0
  19. package/src/runtime/hub-cancel-port.js +122 -0
  20. package/src/runtime/layer-config-port.js +136 -0
  21. package/src/runtime/lease-manager.js +607 -0
  22. package/src/runtime/persistence-port.js +162 -0
  23. package/src/runtime/placeholder-audio-port.js +117 -0
  24. package/src/runtime/progress-events-port.js +121 -0
  25. package/src/runtime/reconciliation-engine.js +2405 -0
  26. package/src/runtime/retry-budget-manager.js +229 -0
  27. package/src/runtime/runtime-metrics.js +427 -0
  28. package/src/runtime/runtime-result-emitter.js +123 -0
  29. package/src/runtime/runtime-scheduler.js +629 -0
  30. package/src/runtime/scene-data-port.js +114 -0
  31. package/src/runtime/scene-window.js +827 -0
  32. package/src/runtime/video-fsm-port.js +189 -0
  33. package/src/runtime/worker-health.js +270 -0
  34. package/test/counter-reconciliation.test.js +164 -0
  35. package/test/mocks/redis-mock.js +221 -0
  36. package/test/test-bindings.js +60 -0
@@ -0,0 +1,114 @@
1
+ // ======================================================
2
+ // O-3 PORT: SceneDataPort — runtime/orchestration scene-content contract
3
+ // ======================================================
4
+ // The runtime and orchestration tiers must not know the Book Model facade.
5
+ // Every book-module require — backend/src/book → @animastor/vbook-runtime —
6
+ // stays HOST-side; the tiers consume scene content ONLY through this port,
7
+ // wired by the composition root (backend.cjs) at startup.
8
+ //
9
+ // runtime/** + orchestration/** (tier consumers)
10
+ // ↓ consume scene reads through
11
+ // runtime/scene-data-port.js ← THIS PORT (tier-owned contract)
12
+ // ↑ wired by the host
13
+ // storage/scene-data-adapter.js (host VBook adapter)
14
+ //
15
+ // This is the O-2 PersistencePort convention (runtime/persistence-port.js):
16
+ // a zero-require contract module, a fail-fast call-time resolver, one
17
+ // set/wired/reset surface. No Book Model surface, no lazy-book internals,
18
+ // no VBook deep specifiers and no "future reads" cross the boundary — the
19
+ // contract below is EXACTLY the set of scene-data operations the two tiers
20
+ // use today (measured §32.11, O-3 reconnaissance):
21
+ //
22
+ // loadBook — load the canonical book.json bundle by bookId
23
+ // (dispatch fallback ×3 in scene-orchestrator,
24
+ // auto-slide in scene-callbacks, window-complete
25
+ // + trySlideWindowOnComplete in scene-window,
26
+ // scheduler tick cache-miss leg, reconciliation
27
+ // resolveBookBuildId + rebuildWorkList)
28
+ // findSceneRuntimeData — resolve the scene payload inside a loaded book
29
+ // (scene-orchestrator per-stage dispatch legs ×3)
30
+ // collectScenes — enumerate a book's scenes in canonical order
31
+ // (scene-window isWindowComplete + trySlide,
32
+ // reconciliation rebuildWorkList)
33
+ //
34
+ // No SQL, no VBook implementation knowledge. The `loadedBook` argument of
35
+ // findSceneRuntimeData/collectScenes stays the same opaque loaded-book value
36
+ // the tiers already pass around (injected by the caller or produced by
37
+ // loadBook) — the tiers never construct one themselves.
38
+ //
39
+ // Deliberately NOT in the port: the rest of the VBook facade (save/delete/
40
+ // import/sessions), lazy-book deep modules, book-model internals, and CRUD
41
+ // "for later". The host adapter owns the VBook wiring (booksRoot config,
42
+ // structure detector).
43
+ //
44
+ // Docs: docs/architecture/generation-module-extraction-reconnaissance.md §32.11 (O-3 DONE)
45
+ // ======================================================
46
+
47
+ const OPS = [
48
+ 'loadBook',
49
+ 'findSceneRuntimeData',
50
+ 'collectScenes',
51
+ ];
52
+
53
+ let impl = null;
54
+
55
+ /**
56
+ * Wire the host scene-data adapter. Called once by the composition root
57
+ * (backend.cjs) BEFORE any runtime/orchestration scene-data consumer runs.
58
+ * @param {object} adapter — flat map with every op in OPS as a function.
59
+ */
60
+ function setSceneDataPort(adapter) {
61
+ if (!adapter) {
62
+ throw new Error('scene-data-port: adapter is required');
63
+ }
64
+ for (const op of OPS) {
65
+ if (typeof adapter[op] !== 'function') {
66
+ throw new Error(`scene-data-port: adapter must implement ${op}()`);
67
+ }
68
+ }
69
+ impl = adapter;
70
+ }
71
+
72
+ /** Resolve the port at CALL time — fail-fast when unwired. */
73
+ function sceneData() {
74
+ if (!impl) {
75
+ throw new Error(
76
+ 'scene-data-port: not wired — the composition root must call ' +
77
+ 'setSceneDataPort(adapter) (storage/scene-data-adapter) ' +
78
+ 'before runtime/orchestration scene-data consumers run (O-3)'
79
+ );
80
+ }
81
+ return impl;
82
+ }
83
+
84
+ /**
85
+ * Shorthand op resolver: `sceneData('loadBook')(...)`.
86
+ * Fails fast when the port or the single op is missing — a missing read
87
+ * must never degrade into a silent undefined.
88
+ * @param {string} op — op name from OPS
89
+ */
90
+ function sceneDataOp(op) {
91
+ const fn = impl?.[op];
92
+ if (typeof fn !== 'function') {
93
+ throw new Error(`scene-data-port: op '${op}' is not wired (O-3)`);
94
+ }
95
+ return fn;
96
+ }
97
+
98
+ function isSceneDataPortWired() {
99
+ return impl !== null;
100
+ }
101
+
102
+ /** Test hygiene: drop the wiring (mocha hooks). */
103
+ function _resetSceneDataPort() {
104
+ impl = null;
105
+ }
106
+
107
+ module.exports = {
108
+ OPS,
109
+ setSceneDataPort,
110
+ sceneData,
111
+ sceneDataOp,
112
+ isSceneDataPortWired,
113
+ _resetSceneDataPort,
114
+ };